2 Sample ACPI Platform Driver
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
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 Protocol The protocol to find.
33 @param Instance Return pointer to the first instance of the protocol
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.
41 LocateFvInstanceWithTables (
42 OUT EFI_FIRMWARE_VOLUME2_PROTOCOL
**Instance
46 EFI_HANDLE
*HandleBuffer
;
47 UINTN NumberOfHandles
;
48 EFI_FV_FILETYPE FileType
;
50 EFI_FV_FILE_ATTRIBUTES Attributes
;
53 EFI_FIRMWARE_VOLUME2_PROTOCOL
*FvInstance
;
60 Status
= gBS
->LocateHandleBuffer (
62 &gEfiFirmwareVolume2ProtocolGuid
,
67 if (EFI_ERROR (Status
)) {
69 // Defined errors at this time are not found and out of resources.
77 // Looking for FV with ACPI storage file
80 for (Index
= 0; Index
< NumberOfHandles
; Index
++) {
82 // Get the protocol on this handle
83 // This should not fail because of LocateHandleBuffer
85 Status
= gBS
->HandleProtocol (
87 &gEfiFirmwareVolume2ProtocolGuid
,
90 ASSERT_EFI_ERROR (Status
);
93 // See if it has the ACPI storage file
95 Status
= FvInstance
->ReadFile (
97 FixedPcdGetPtr (PcdAcpiTableStorageFile
),
106 // If we found it, then we are done
108 if (Status
== EFI_SUCCESS
) {
109 *Instance
= FvInstance
;
115 // Our exit status is determined by the success of the previous operations
116 // If the protocol was found, Instance already points to it.
120 // Free any allocated buffers
122 gBS
->FreePool (HandleBuffer
);
129 This function calculates and updates an UINT8 checksum.
131 @param Buffer Pointer to buffer to checksum
132 @param Size Number of bytes to checksum
136 AcpiPlatformChecksum (
141 UINTN ChecksumOffset
;
143 ChecksumOffset
= OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
, Checksum
);
146 // Set checksum to 0 first
148 Buffer
[ChecksumOffset
] = 0;
151 // Update checksum value
153 Buffer
[ChecksumOffset
] = CalculateCheckSum8(Buffer
, Size
);
158 Entrypoint of Acpi Platform driver.
164 @return EFI_LOAD_ERROR
165 @return EFI_OUT_OF_RESOURCES
170 AcpiPlatformEntryPoint (
171 IN EFI_HANDLE ImageHandle
,
172 IN EFI_SYSTEM_TABLE
*SystemTable
176 EFI_ACPI_TABLE_PROTOCOL
*AcpiTable
;
177 EFI_FIRMWARE_VOLUME2_PROTOCOL
*FwVol
;
179 EFI_ACPI_COMMON_HEADER
*CurrentTable
;
190 // Find the AcpiTable protocol
192 Status
= gBS
->LocateProtocol (&gEfiAcpiTableProtocolGuid
, NULL
, (VOID
**)&AcpiTable
);
193 if (EFI_ERROR (Status
)) {
198 // Locate the firmware volume protocol
200 Status
= LocateFvInstanceWithTables (&FwVol
);
201 if (EFI_ERROR (Status
)) {
205 // Read tables from the storage file.
207 while (Status
== EFI_SUCCESS
) {
209 Status
= FwVol
->ReadSection (
211 FixedPcdGetPtr (PcdAcpiTableStorageFile
),
214 (VOID
**) &CurrentTable
,
218 if (!EFI_ERROR(Status
)) {
224 TableSize
= ((EFI_ACPI_DESCRIPTION_HEADER
*) CurrentTable
)->Length
;
225 ASSERT (Size
>= TableSize
);
228 // Checksum ACPI table
230 AcpiPlatformChecksum ((UINT8
*)CurrentTable
, TableSize
);
233 // Install ACPI table
235 Status
= AcpiTable
->InstallAcpiTable (
241 if (EFI_ERROR(Status
)) {
246 // Increment the instance