]> git.proxmox.com Git - mirror_edk2.git/blame - EmbeddedPkg/Library/AcpiLib/AcpiLib.c
EmbeddedPkg: Change use of EFI_D_* to DEBUG_*
[mirror_edk2.git] / EmbeddedPkg / Library / AcpiLib / AcpiLib.c
CommitLineData
3356211b
OM
1/** @file\r
2*\r
da7dd714 3* Copyright (c) 2014-2015, ARM Limited. All rights reserved.\r
3356211b 4*\r
878b807a 5* SPDX-License-Identifier: BSD-2-Clause-Patent\r
3356211b
OM
6*\r
7**/\r
8\r
9#include <Uefi.h>\r
10\r
11#include <Library/AcpiLib.h>\r
12#include <Library/DebugLib.h>\r
13#include <Library/UefiBootServicesTableLib.h>\r
14\r
15#include <Protocol/AcpiTable.h>\r
16#include <Protocol/FirmwareVolume2.h>\r
17\r
18#include <IndustryStandard/Acpi.h>\r
19\r
20/**\r
da7dd714
OM
21 Locate and Install the ACPI tables from the Firmware Volume if it verifies\r
22 the function condition.\r
3356211b 23\r
da7dd714
OM
24 @param AcpiFile Guid of the ACPI file into the Firmware Volume\r
25 @param CheckAcpiTableFunction Function that checks if the ACPI table should be installed\r
3356211b 26\r
da7dd714
OM
27 @return EFI_SUCCESS The function completed successfully.\r
28 @return EFI_NOT_FOUND The protocol could not be located.\r
29 @return EFI_OUT_OF_RESOURCES There are not enough resources to find the protocol.\r
3356211b
OM
30\r
31**/\r
32EFI_STATUS\r
da7dd714
OM
33LocateAndInstallAcpiFromFvConditional (\r
34 IN CONST EFI_GUID* AcpiFile,\r
35 IN EFI_LOCATE_ACPI_CHECK CheckAcpiTableFunction\r
3356211b
OM
36 )\r
37{\r
38 EFI_STATUS Status;\r
39 EFI_ACPI_TABLE_PROTOCOL *AcpiProtocol;\r
40 EFI_HANDLE *HandleBuffer;\r
41 UINTN NumberOfHandles;\r
42 UINT32 FvStatus;\r
43 UINTN Index;\r
44 EFI_FIRMWARE_VOLUME2_PROTOCOL *FvInstance;\r
45 INTN SectionInstance;\r
46 UINTN SectionSize;\r
47 EFI_ACPI_COMMON_HEADER *AcpiTable;\r
48 UINTN AcpiTableSize;\r
49 UINTN AcpiTableKey;\r
da7dd714 50 BOOLEAN Valid;\r
3356211b
OM
51\r
52 // Ensure the ACPI Table is present\r
53 Status = gBS->LocateProtocol (\r
54 &gEfiAcpiTableProtocolGuid,\r
55 NULL,\r
56 (VOID**)&AcpiProtocol\r
57 );\r
58 if (EFI_ERROR (Status)) {\r
59 return Status;\r
60 }\r
61\r
62 FvStatus = 0;\r
63 SectionInstance = 0;\r
64\r
65 // Locate all the Firmware Volume protocols.\r
66 Status = gBS->LocateHandleBuffer (\r
67 ByProtocol,\r
68 &gEfiFirmwareVolume2ProtocolGuid,\r
69 NULL,\r
70 &NumberOfHandles,\r
71 &HandleBuffer\r
72 );\r
73 if (EFI_ERROR (Status)) {\r
74 return Status;\r
75 }\r
76\r
77 // Looking for FV with ACPI storage file\r
78 for (Index = 0; Index < NumberOfHandles; Index++) {\r
79 //\r
80 // Get the protocol on this handle\r
81 // This should not fail because of LocateHandleBuffer\r
82 //\r
83 Status = gBS->HandleProtocol (\r
84 HandleBuffer[Index],\r
85 &gEfiFirmwareVolume2ProtocolGuid,\r
86 (VOID**) &FvInstance\r
87 );\r
88 if (EFI_ERROR (Status)) {\r
89 goto FREE_HANDLE_BUFFER;\r
90 }\r
91\r
92 while (Status == EFI_SUCCESS) {\r
93 // AcpiTable must be allocated by ReadSection (ie: AcpiTable == NULL)\r
94 AcpiTable = NULL;\r
95\r
96 // See if it has the ACPI storage file\r
97 Status = FvInstance->ReadSection (\r
98 FvInstance,\r
99 AcpiFile,\r
100 EFI_SECTION_RAW,\r
101 SectionInstance,\r
102 (VOID**) &AcpiTable,\r
103 &SectionSize,\r
104 &FvStatus\r
105 );\r
106 if (!EFI_ERROR (Status)) {\r
107 AcpiTableKey = 0;\r
108 AcpiTableSize = ((EFI_ACPI_DESCRIPTION_HEADER *) AcpiTable)->Length;\r
109 ASSERT (SectionSize >= AcpiTableSize);\r
110\r
a1878955 111 DEBUG ((DEBUG_ERROR, "- Found '%c%c%c%c' ACPI Table\n",\r
3356211b
OM
112 (((EFI_ACPI_DESCRIPTION_HEADER *) AcpiTable)->Signature & 0xFF),\r
113 ((((EFI_ACPI_DESCRIPTION_HEADER *) AcpiTable)->Signature >> 8) & 0xFF),\r
114 ((((EFI_ACPI_DESCRIPTION_HEADER *) AcpiTable)->Signature >> 16) & 0xFF),\r
115 ((((EFI_ACPI_DESCRIPTION_HEADER *) AcpiTable)->Signature >> 24) & 0xFF)));\r
116\r
da7dd714
OM
117 // Is the ACPI table valid?\r
118 if (CheckAcpiTableFunction) {\r
119 Valid = CheckAcpiTableFunction ((EFI_ACPI_DESCRIPTION_HEADER *)AcpiTable);\r
120 } else {\r
121 Valid = TRUE;\r
122 }\r
123\r
3356211b 124 // Install the ACPI Table\r
da7dd714
OM
125 if (Valid) {\r
126 Status = AcpiProtocol->InstallAcpiTable (\r
127 AcpiProtocol,\r
128 AcpiTable,\r
129 AcpiTableSize,\r
130 &AcpiTableKey\r
131 );\r
132 }\r
133\r
3356211b
OM
134 // Free memory allocated by ReadSection\r
135 gBS->FreePool (AcpiTable);\r
136\r
137 if (EFI_ERROR (Status)) {\r
138 break;\r
139 }\r
140\r
141 // Increment the section instance\r
142 SectionInstance++;\r
143 }\r
144 }\r
145 }\r
146\r
147FREE_HANDLE_BUFFER:\r
148 //\r
149 // Free any allocated buffers\r
150 //\r
151 gBS->FreePool (HandleBuffer);\r
152\r
153 return EFI_SUCCESS;\r
154}\r
da7dd714
OM
155\r
156/**\r
157 Locate and Install the ACPI tables from the Firmware Volume\r
158\r
159 @param AcpiFile Guid of the ACPI file into the Firmware Volume\r
160\r
161 @return EFI_SUCCESS The function completed successfully.\r
162 @return EFI_NOT_FOUND The protocol could not be located.\r
163 @return EFI_OUT_OF_RESOURCES There are not enough resources to find the protocol.\r
164\r
165**/\r
166EFI_STATUS\r
167LocateAndInstallAcpiFromFv (\r
168 IN CONST EFI_GUID* AcpiFile\r
169 )\r
170{\r
171 return LocateAndInstallAcpiFromFvConditional (AcpiFile, NULL);\r
172}\r