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