]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Universal/Acpi/AcpiPlatformDxe/AcpiPlatform.c
Fix various 'EFIAPI' inconsistencies found while building MdeModulePkg.
[mirror_edk2.git] / MdeModulePkg / Universal / Acpi / AcpiPlatformDxe / AcpiPlatform.c
CommitLineData
5f55c700 1/** @file\r
2 Sample ACPI Platform Driver\r
3\r
4 Copyright (c) 2008 - 2009, Intel Corporation<BR>\r
5 All rights reserved. This program and the accompanying materials\r
6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution. The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php\r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/ \r
14\r
15#include <PiDxe.h>\r
16\r
17#include <Protocol/AcpiTable.h>\r
18#include <Protocol/FirmwareVolume2.h>\r
19\r
20#include <Library/BaseLib.h>\r
21#include <Library/UefiBootServicesTableLib.h>\r
22#include <Library/DebugLib.h>\r
23#include <Library/PcdLib.h>\r
24\r
25#include <IndustryStandard/Acpi.h>\r
26\r
27/**\r
28 Locate the first instance of a protocol. If the protocol requested is an\r
29 FV protocol, then it will return the first FV that contains the ACPI table\r
30 storage file.\r
31\r
32 @param Protocol The protocol to find.\r
33 @param Instance Return pointer to the first instance of the protocol\r
34\r
35 @return EFI_SUCCESS The function completed successfully.\r
36 @return EFI_NOT_FOUND The protocol could not be located.\r
37 @return EFI_OUT_OF_RESOURCES There are not enough resources to find the protocol.\r
38\r
39**/\r
40EFI_STATUS\r
41LocateFvInstanceWithTables (\r
42 OUT EFI_FIRMWARE_VOLUME2_PROTOCOL **Instance\r
43 )\r
44{\r
45 EFI_STATUS Status;\r
46 EFI_HANDLE *HandleBuffer;\r
47 UINTN NumberOfHandles;\r
48 EFI_FV_FILETYPE FileType;\r
49 UINT32 FvStatus;\r
50 EFI_FV_FILE_ATTRIBUTES Attributes;\r
51 UINTN Size;\r
52 UINTN Index;\r
53 EFI_FIRMWARE_VOLUME2_PROTOCOL *FvInstance;\r
54\r
55 FvStatus = 0;\r
56\r
57 //\r
58 // Locate protocol.\r
59 //\r
60 Status = gBS->LocateHandleBuffer (\r
61 ByProtocol,\r
62 &gEfiFirmwareVolume2ProtocolGuid,\r
63 NULL,\r
64 &NumberOfHandles,\r
65 &HandleBuffer\r
66 );\r
67 if (EFI_ERROR (Status)) {\r
68 //\r
69 // Defined errors at this time are not found and out of resources.\r
70 //\r
71 return Status;\r
72 }\r
73\r
74\r
75\r
76 //\r
77 // Looking for FV with ACPI storage file\r
78 //\r
79\r
80 for (Index = 0; Index < NumberOfHandles; Index++) {\r
81 //\r
82 // Get the protocol on this handle\r
83 // This should not fail because of LocateHandleBuffer\r
84 //\r
85 Status = gBS->HandleProtocol (\r
86 HandleBuffer[Index],\r
87 &gEfiFirmwareVolume2ProtocolGuid,\r
88 (VOID**) &FvInstance\r
89 );\r
90 ASSERT_EFI_ERROR (Status);\r
91\r
92 //\r
93 // See if it has the ACPI storage file\r
94 //\r
95 Status = FvInstance->ReadFile (\r
96 FvInstance,\r
97 FixedPcdGetPtr (PcdAcpiTableStorageFile),\r
98 NULL,\r
99 &Size,\r
100 &FileType,\r
101 &Attributes,\r
102 &FvStatus\r
103 );\r
104\r
105 //\r
106 // If we found it, then we are done\r
107 //\r
108 if (Status == EFI_SUCCESS) {\r
109 *Instance = FvInstance;\r
110 break;\r
111 }\r
112 }\r
113\r
114 //\r
115 // Our exit status is determined by the success of the previous operations\r
116 // If the protocol was found, Instance already points to it.\r
117 //\r
118\r
119 //\r
120 // Free any allocated buffers\r
121 //\r
122 gBS->FreePool (HandleBuffer);\r
123\r
124 return Status;\r
125}\r
126\r
127\r
128/**\r
129 This function calculates and updates an UINT8 checksum.\r
130\r
131 @param Buffer Pointer to buffer to checksum\r
132 @param Size Number of bytes to checksum\r
133\r
134**/\r
135VOID\r
136AcpiPlatformChecksum (\r
137 IN UINT8 *Buffer,\r
138 IN UINTN Size\r
139 )\r
140{\r
141 UINTN ChecksumOffset;\r
142\r
143 ChecksumOffset = OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER, Checksum);\r
144\r
145 //\r
146 // Set checksum to 0 first\r
147 //\r
148 Buffer[ChecksumOffset] = 0;\r
149\r
150 //\r
151 // Update checksum value\r
152 //\r
153 Buffer[ChecksumOffset] = CalculateCheckSum8(Buffer, Size);\r
154}\r
155\r
156\r
157/**\r
158 Entrypoint of Acpi Platform driver.\r
159\r
160 @param ImageHandle\r
161 @param SystemTable\r
162\r
163 @return EFI_SUCCESS\r
164 @return EFI_LOAD_ERROR\r
165 @return EFI_OUT_OF_RESOURCES\r
166\r
167**/\r
168EFI_STATUS\r
6d3ea23f 169EFIAPI\r
5f55c700 170AcpiPlatformEntryPoint (\r
171 IN EFI_HANDLE ImageHandle,\r
172 IN EFI_SYSTEM_TABLE *SystemTable\r
173 )\r
174{\r
175 EFI_STATUS Status;\r
176 EFI_ACPI_TABLE_PROTOCOL *AcpiTable;\r
177 EFI_FIRMWARE_VOLUME2_PROTOCOL *FwVol;\r
178 INTN Instance;\r
179 EFI_ACPI_COMMON_HEADER *CurrentTable;\r
180 UINTN TableHandle;\r
181 UINT32 FvStatus;\r
182 UINTN TableSize;\r
183 UINTN Size;\r
184\r
185 Instance = 0;\r
186 CurrentTable = NULL;\r
187 TableHandle = 0;\r
188\r
189 //\r
190 // Find the AcpiTable protocol\r
191 //\r
192 Status = gBS->LocateProtocol (&gEfiAcpiTableProtocolGuid, NULL, (VOID**)&AcpiTable);\r
193 if (EFI_ERROR (Status)) {\r
194 return EFI_ABORTED;\r
195 }\r
196\r
197 //\r
198 // Locate the firmware volume protocol\r
199 //\r
200 Status = LocateFvInstanceWithTables (&FwVol);\r
201 if (EFI_ERROR (Status)) {\r
202 return EFI_ABORTED;\r
203 }\r
204 //\r
205 // Read tables from the storage file.\r
206 //\r
207 while (Status == EFI_SUCCESS) {\r
208\r
209 Status = FwVol->ReadSection (\r
210 FwVol,\r
211 FixedPcdGetPtr (PcdAcpiTableStorageFile),\r
212 EFI_SECTION_RAW,\r
213 Instance,\r
214 (VOID**) &CurrentTable,\r
215 &Size,\r
216 &FvStatus\r
217 );\r
218 if (!EFI_ERROR(Status)) {\r
219 //\r
220 // Add the table\r
221 //\r
222 TableHandle = 0;\r
223\r
224 TableSize = ((EFI_ACPI_DESCRIPTION_HEADER *) CurrentTable)->Length;\r
225 ASSERT (Size >= TableSize);\r
226\r
227 //\r
228 // Checksum ACPI table\r
229 //\r
230 AcpiPlatformChecksum ((UINT8*)CurrentTable, TableSize);\r
231\r
232 //\r
233 // Install ACPI table\r
234 //\r
235 Status = AcpiTable->InstallAcpiTable (\r
236 AcpiTable,\r
237 CurrentTable,\r
238 TableSize,\r
239 &TableHandle\r
240 );\r
241 if (EFI_ERROR(Status)) {\r
242 return EFI_ABORTED;\r
243 }\r
244\r
245 //\r
246 // Increment the instance\r
247 //\r
248 Instance++;\r
249 CurrentTable = NULL;\r
250 }\r
251 }\r
252\r
253 return EFI_SUCCESS;\r
254}\r
255\r