2 Sample ACPI Platform Driver
4 Copyright (c) 2008 - 2011, Intel Corporation. All rights reserved.<BR>
5 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
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.
17 #include <Protocol/AcpiTable.h>
18 #include <Protocol/FirmwareVolume2.h>
20 #include <Library/BaseLib.h>
21 #include <Library/UefiBootServicesTableLib.h>
22 #include <Library/DebugLib.h>
23 #include <Library/PcdLib.h>
25 #include <IndustryStandard/Acpi.h>
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
32 @param Instance Return pointer to the first instance of the protocol
34 @return EFI_SUCCESS The function completed successfully.
35 @return EFI_NOT_FOUND The protocol could not be located.
36 @return EFI_OUT_OF_RESOURCES There are not enough resources to find the protocol.
40 LocateFvInstanceWithTables (
41 OUT EFI_FIRMWARE_VOLUME2_PROTOCOL
**Instance
45 EFI_HANDLE
*HandleBuffer
;
46 UINTN NumberOfHandles
;
47 EFI_FV_FILETYPE FileType
;
49 EFI_FV_FILE_ATTRIBUTES Attributes
;
52 EFI_FIRMWARE_VOLUME2_PROTOCOL
*FvInstance
;
59 Status
= gBS
->LocateHandleBuffer (
61 &gEfiFirmwareVolume2ProtocolGuid
,
66 if (EFI_ERROR (Status
)) {
68 // Defined errors at this time are not found and out of resources.
76 // Looking for FV with ACPI storage file
79 for (Index
= 0; Index
< NumberOfHandles
; Index
++) {
81 // Get the protocol on this handle
82 // This should not fail because of LocateHandleBuffer
84 Status
= gBS
->HandleProtocol (
86 &gEfiFirmwareVolume2ProtocolGuid
,
89 ASSERT_EFI_ERROR (Status
);
92 // See if it has the ACPI storage file
94 Status
= FvInstance
->ReadFile (
96 (EFI_GUID
*)PcdGetPtr (PcdAcpiTableStorageFile
),
105 // If we found it, then we are done
107 if (Status
== EFI_SUCCESS
) {
108 *Instance
= FvInstance
;
114 // Our exit status is determined by the success of the previous operations
115 // If the protocol was found, Instance already points to it.
119 // Free any allocated buffers
121 gBS
->FreePool (HandleBuffer
);
128 This function calculates and updates an UINT8 checksum.
130 @param Buffer Pointer to buffer to checksum
131 @param Size Number of bytes to checksum
135 AcpiPlatformChecksum (
140 UINTN ChecksumOffset
;
142 ChecksumOffset
= OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
, Checksum
);
145 // Set checksum to 0 first
147 Buffer
[ChecksumOffset
] = 0;
150 // Update checksum value
152 Buffer
[ChecksumOffset
] = CalculateCheckSum8(Buffer
, Size
);
157 Entrypoint of Acpi Platform driver.
163 @return EFI_LOAD_ERROR
164 @return EFI_OUT_OF_RESOURCES
169 AcpiPlatformEntryPoint (
170 IN EFI_HANDLE ImageHandle
,
171 IN EFI_SYSTEM_TABLE
*SystemTable
175 EFI_ACPI_TABLE_PROTOCOL
*AcpiTable
;
176 EFI_FIRMWARE_VOLUME2_PROTOCOL
*FwVol
;
178 EFI_ACPI_COMMON_HEADER
*CurrentTable
;
189 // Find the AcpiTable protocol
191 Status
= gBS
->LocateProtocol (&gEfiAcpiTableProtocolGuid
, NULL
, (VOID
**)&AcpiTable
);
192 if (EFI_ERROR (Status
)) {
197 // Locate the firmware volume protocol
199 Status
= LocateFvInstanceWithTables (&FwVol
);
200 if (EFI_ERROR (Status
)) {
204 // Read tables from the storage file.
206 while (Status
== EFI_SUCCESS
) {
208 Status
= FwVol
->ReadSection (
210 (EFI_GUID
*)PcdGetPtr (PcdAcpiTableStorageFile
),
213 (VOID
**) &CurrentTable
,
217 if (!EFI_ERROR(Status
)) {
223 TableSize
= ((EFI_ACPI_DESCRIPTION_HEADER
*) CurrentTable
)->Length
;
224 ASSERT (Size
>= TableSize
);
227 // Checksum ACPI table
229 AcpiPlatformChecksum ((UINT8
*)CurrentTable
, TableSize
);
232 // Install ACPI table
234 Status
= AcpiTable
->InstallAcpiTable (
242 // Free memory allocated by ReadSection
244 gBS
->FreePool (CurrentTable
);
246 if (EFI_ERROR(Status
)) {
251 // Increment the instance