2 Sample ACPI Platform Driver
4 Copyright (c) 2008 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
11 #include <Protocol/AcpiTable.h>
12 #include <Protocol/FirmwareVolume2.h>
14 #include <Library/BaseLib.h>
15 #include <Library/UefiBootServicesTableLib.h>
16 #include <Library/DebugLib.h>
17 #include <Library/PcdLib.h>
19 #include <IndustryStandard/Acpi.h>
22 Locate the first instance of a protocol. If the protocol requested is an
23 FV protocol, then it will return the first FV that contains the ACPI table
26 @param Instance Return pointer to the first instance of the protocol
28 @return EFI_SUCCESS The function completed successfully.
29 @return EFI_NOT_FOUND The protocol could not be located.
30 @return EFI_OUT_OF_RESOURCES There are not enough resources to find the protocol.
34 LocateFvInstanceWithTables (
35 OUT EFI_FIRMWARE_VOLUME2_PROTOCOL
**Instance
39 EFI_HANDLE
*HandleBuffer
;
40 UINTN NumberOfHandles
;
41 EFI_FV_FILETYPE FileType
;
43 EFI_FV_FILE_ATTRIBUTES Attributes
;
46 EFI_FIRMWARE_VOLUME2_PROTOCOL
*FvInstance
;
53 Status
= gBS
->LocateHandleBuffer (
55 &gEfiFirmwareVolume2ProtocolGuid
,
60 if (EFI_ERROR (Status
)) {
62 // Defined errors at this time are not found and out of resources.
68 // Looking for FV with ACPI storage file
71 for (Index
= 0; Index
< NumberOfHandles
; Index
++) {
73 // Get the protocol on this handle
74 // This should not fail because of LocateHandleBuffer
76 Status
= gBS
->HandleProtocol (
78 &gEfiFirmwareVolume2ProtocolGuid
,
81 ASSERT_EFI_ERROR (Status
);
84 // See if it has the ACPI storage file
86 Status
= FvInstance
->ReadFile (
88 (EFI_GUID
*)PcdGetPtr (PcdAcpiTableStorageFile
),
97 // If we found it, then we are done
99 if (Status
== EFI_SUCCESS
) {
100 *Instance
= FvInstance
;
106 // Our exit status is determined by the success of the previous operations
107 // If the protocol was found, Instance already points to it.
111 // Free any allocated buffers
113 gBS
->FreePool (HandleBuffer
);
119 This function calculates and updates an UINT8 checksum.
121 @param Buffer Pointer to buffer to checksum
122 @param Size Number of bytes to checksum
126 AcpiPlatformChecksum (
131 UINTN ChecksumOffset
;
133 ChecksumOffset
= OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
, Checksum
);
136 // Set checksum to 0 first
138 Buffer
[ChecksumOffset
] = 0;
141 // Update checksum value
143 Buffer
[ChecksumOffset
] = CalculateCheckSum8 (Buffer
, Size
);
147 Entrypoint of Acpi Platform driver.
153 @return EFI_LOAD_ERROR
154 @return EFI_OUT_OF_RESOURCES
159 AcpiPlatformEntryPoint (
160 IN EFI_HANDLE ImageHandle
,
161 IN EFI_SYSTEM_TABLE
*SystemTable
165 EFI_ACPI_TABLE_PROTOCOL
*AcpiTable
;
166 EFI_FIRMWARE_VOLUME2_PROTOCOL
*FwVol
;
168 EFI_ACPI_COMMON_HEADER
*CurrentTable
;
179 // Find the AcpiTable protocol
181 Status
= gBS
->LocateProtocol (&gEfiAcpiTableProtocolGuid
, NULL
, (VOID
**)&AcpiTable
);
182 if (EFI_ERROR (Status
)) {
187 // Locate the firmware volume protocol
189 Status
= LocateFvInstanceWithTables (&FwVol
);
190 if (EFI_ERROR (Status
)) {
195 // Read tables from the storage file.
197 while (Status
== EFI_SUCCESS
) {
198 Status
= FwVol
->ReadSection (
200 (EFI_GUID
*)PcdGetPtr (PcdAcpiTableStorageFile
),
203 (VOID
**)&CurrentTable
,
207 if (!EFI_ERROR (Status
)) {
213 TableSize
= ((EFI_ACPI_DESCRIPTION_HEADER
*)CurrentTable
)->Length
;
214 ASSERT (Size
>= TableSize
);
217 // Checksum ACPI table
219 AcpiPlatformChecksum ((UINT8
*)CurrentTable
, TableSize
);
222 // Install ACPI table
224 Status
= AcpiTable
->InstallAcpiTable (
232 // Free memory allocated by ReadSection
234 gBS
->FreePool (CurrentTable
);
236 if (EFI_ERROR (Status
)) {
241 // Increment the instance
249 // The driver does not require to be kept loaded.
251 return EFI_REQUEST_UNLOAD_IMAGE
;