]>
Commit | Line | Data |
---|---|---|
5f55c700 | 1 | /** @file\r |
2 | Sample ACPI Platform Driver\r | |
3 | \r | |
993b8cdd | 4 | Copyright (c) 2008 - 2011, Intel Corporation. All rights reserved.<BR>\r |
e5eed7d3 | 5 | This program and the accompanying materials\r |
5f55c700 | 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 | |
5f55c700 | 32 | @param Instance Return pointer to the first instance of the protocol\r |
33 | \r | |
34 | @return EFI_SUCCESS The function completed successfully.\r | |
35 | @return EFI_NOT_FOUND The protocol could not be located.\r | |
36 | @return EFI_OUT_OF_RESOURCES There are not enough resources to find the protocol.\r | |
37 | \r | |
38 | **/\r | |
39 | EFI_STATUS\r | |
40 | LocateFvInstanceWithTables (\r | |
41 | OUT EFI_FIRMWARE_VOLUME2_PROTOCOL **Instance\r | |
42 | )\r | |
43 | {\r | |
44 | EFI_STATUS Status;\r | |
45 | EFI_HANDLE *HandleBuffer;\r | |
46 | UINTN NumberOfHandles;\r | |
47 | EFI_FV_FILETYPE FileType;\r | |
48 | UINT32 FvStatus;\r | |
49 | EFI_FV_FILE_ATTRIBUTES Attributes;\r | |
50 | UINTN Size;\r | |
51 | UINTN Index;\r | |
52 | EFI_FIRMWARE_VOLUME2_PROTOCOL *FvInstance;\r | |
53 | \r | |
54 | FvStatus = 0;\r | |
55 | \r | |
56 | //\r | |
57 | // Locate protocol.\r | |
58 | //\r | |
59 | Status = gBS->LocateHandleBuffer (\r | |
60 | ByProtocol,\r | |
61 | &gEfiFirmwareVolume2ProtocolGuid,\r | |
62 | NULL,\r | |
63 | &NumberOfHandles,\r | |
64 | &HandleBuffer\r | |
65 | );\r | |
66 | if (EFI_ERROR (Status)) {\r | |
67 | //\r | |
68 | // Defined errors at this time are not found and out of resources.\r | |
69 | //\r | |
70 | return Status;\r | |
71 | }\r | |
72 | \r | |
73 | \r | |
74 | \r | |
75 | //\r | |
76 | // Looking for FV with ACPI storage file\r | |
77 | //\r | |
78 | \r | |
79 | for (Index = 0; Index < NumberOfHandles; Index++) {\r | |
80 | //\r | |
81 | // Get the protocol on this handle\r | |
82 | // This should not fail because of LocateHandleBuffer\r | |
83 | //\r | |
84 | Status = gBS->HandleProtocol (\r | |
85 | HandleBuffer[Index],\r | |
86 | &gEfiFirmwareVolume2ProtocolGuid,\r | |
87 | (VOID**) &FvInstance\r | |
88 | );\r | |
89 | ASSERT_EFI_ERROR (Status);\r | |
90 | \r | |
91 | //\r | |
92 | // See if it has the ACPI storage file\r | |
93 | //\r | |
94 | Status = FvInstance->ReadFile (\r | |
95 | FvInstance,\r | |
188e4e84 | 96 | (EFI_GUID*)PcdGetPtr (PcdAcpiTableStorageFile),\r |
5f55c700 | 97 | NULL,\r |
98 | &Size,\r | |
99 | &FileType,\r | |
100 | &Attributes,\r | |
101 | &FvStatus\r | |
102 | );\r | |
103 | \r | |
104 | //\r | |
105 | // If we found it, then we are done\r | |
106 | //\r | |
107 | if (Status == EFI_SUCCESS) {\r | |
108 | *Instance = FvInstance;\r | |
109 | break;\r | |
110 | }\r | |
111 | }\r | |
112 | \r | |
113 | //\r | |
114 | // Our exit status is determined by the success of the previous operations\r | |
115 | // If the protocol was found, Instance already points to it.\r | |
116 | //\r | |
117 | \r | |
118 | //\r | |
119 | // Free any allocated buffers\r | |
120 | //\r | |
121 | gBS->FreePool (HandleBuffer);\r | |
122 | \r | |
123 | return Status;\r | |
124 | }\r | |
125 | \r | |
126 | \r | |
127 | /**\r | |
128 | This function calculates and updates an UINT8 checksum.\r | |
129 | \r | |
130 | @param Buffer Pointer to buffer to checksum\r | |
131 | @param Size Number of bytes to checksum\r | |
132 | \r | |
133 | **/\r | |
134 | VOID\r | |
135 | AcpiPlatformChecksum (\r | |
136 | IN UINT8 *Buffer,\r | |
137 | IN UINTN Size\r | |
138 | )\r | |
139 | {\r | |
140 | UINTN ChecksumOffset;\r | |
141 | \r | |
142 | ChecksumOffset = OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER, Checksum);\r | |
143 | \r | |
144 | //\r | |
145 | // Set checksum to 0 first\r | |
146 | //\r | |
147 | Buffer[ChecksumOffset] = 0;\r | |
148 | \r | |
149 | //\r | |
150 | // Update checksum value\r | |
151 | //\r | |
152 | Buffer[ChecksumOffset] = CalculateCheckSum8(Buffer, Size);\r | |
153 | }\r | |
154 | \r | |
155 | \r | |
156 | /**\r | |
157 | Entrypoint of Acpi Platform driver.\r | |
158 | \r | |
159 | @param ImageHandle\r | |
160 | @param SystemTable\r | |
161 | \r | |
162 | @return EFI_SUCCESS\r | |
163 | @return EFI_LOAD_ERROR\r | |
164 | @return EFI_OUT_OF_RESOURCES\r | |
165 | \r | |
166 | **/\r | |
167 | EFI_STATUS\r | |
6d3ea23f | 168 | EFIAPI\r |
5f55c700 | 169 | AcpiPlatformEntryPoint (\r |
170 | IN EFI_HANDLE ImageHandle,\r | |
171 | IN EFI_SYSTEM_TABLE *SystemTable\r | |
172 | )\r | |
173 | {\r | |
174 | EFI_STATUS Status;\r | |
175 | EFI_ACPI_TABLE_PROTOCOL *AcpiTable;\r | |
176 | EFI_FIRMWARE_VOLUME2_PROTOCOL *FwVol;\r | |
177 | INTN Instance;\r | |
178 | EFI_ACPI_COMMON_HEADER *CurrentTable;\r | |
179 | UINTN TableHandle;\r | |
180 | UINT32 FvStatus;\r | |
181 | UINTN TableSize;\r | |
182 | UINTN Size;\r | |
183 | \r | |
184 | Instance = 0;\r | |
185 | CurrentTable = NULL;\r | |
186 | TableHandle = 0;\r | |
187 | \r | |
188 | //\r | |
189 | // Find the AcpiTable protocol\r | |
190 | //\r | |
191 | Status = gBS->LocateProtocol (&gEfiAcpiTableProtocolGuid, NULL, (VOID**)&AcpiTable);\r | |
192 | if (EFI_ERROR (Status)) {\r | |
193 | return EFI_ABORTED;\r | |
194 | }\r | |
195 | \r | |
196 | //\r | |
197 | // Locate the firmware volume protocol\r | |
198 | //\r | |
199 | Status = LocateFvInstanceWithTables (&FwVol);\r | |
200 | if (EFI_ERROR (Status)) {\r | |
201 | return EFI_ABORTED;\r | |
202 | }\r | |
203 | //\r | |
204 | // Read tables from the storage file.\r | |
205 | //\r | |
206 | while (Status == EFI_SUCCESS) {\r | |
207 | \r | |
208 | Status = FwVol->ReadSection (\r | |
209 | FwVol,\r | |
188e4e84 | 210 | (EFI_GUID*)PcdGetPtr (PcdAcpiTableStorageFile),\r |
5f55c700 | 211 | EFI_SECTION_RAW,\r |
212 | Instance,\r | |
213 | (VOID**) &CurrentTable,\r | |
214 | &Size,\r | |
215 | &FvStatus\r | |
216 | );\r | |
217 | if (!EFI_ERROR(Status)) {\r | |
218 | //\r | |
219 | // Add the table\r | |
220 | //\r | |
221 | TableHandle = 0;\r | |
222 | \r | |
223 | TableSize = ((EFI_ACPI_DESCRIPTION_HEADER *) CurrentTable)->Length;\r | |
224 | ASSERT (Size >= TableSize);\r | |
225 | \r | |
226 | //\r | |
227 | // Checksum ACPI table\r | |
228 | //\r | |
229 | AcpiPlatformChecksum ((UINT8*)CurrentTable, TableSize);\r | |
230 | \r | |
231 | //\r | |
232 | // Install ACPI table\r | |
233 | //\r | |
234 | Status = AcpiTable->InstallAcpiTable (\r | |
235 | AcpiTable,\r | |
236 | CurrentTable,\r | |
237 | TableSize,\r | |
238 | &TableHandle\r | |
239 | );\r | |
993b8cdd SZ |
240 | \r |
241 | //\r | |
242 | // Free memory allocated by ReadSection\r | |
243 | //\r | |
244 | gBS->FreePool (CurrentTable);\r | |
245 | \r | |
5f55c700 | 246 | if (EFI_ERROR(Status)) {\r |
247 | return EFI_ABORTED;\r | |
248 | }\r | |
249 | \r | |
250 | //\r | |
251 | // Increment the instance\r | |
252 | //\r | |
253 | Instance++;\r | |
254 | CurrentTable = NULL;\r | |
255 | }\r | |
256 | }\r | |
257 | \r | |
258 | return EFI_SUCCESS;\r | |
259 | }\r | |
260 | \r |