3 * Copyright (c) 2014, ARM Limited. All rights reserved.
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 <Library/AcpiLib.h>
18 #include <Library/DebugLib.h>
19 #include <Library/UefiBootServicesTableLib.h>
21 #include <Protocol/AcpiTable.h>
22 #include <Protocol/FirmwareVolume2.h>
24 #include <IndustryStandard/Acpi.h>
27 Locate and Install the ACPI tables from the Firmware Volume
29 @param AcpiFile Guid of the ACPI file into the Firmware Volume
31 @return EFI_SUCCESS The function completed successfully.
32 @return EFI_NOT_FOUND The protocol could not be located.
33 @return EFI_OUT_OF_RESOURCES There are not enough resources to find the protocol.
37 LocateAndInstallAcpiFromFv (
38 IN CONST EFI_GUID
* AcpiFile
42 EFI_ACPI_TABLE_PROTOCOL
*AcpiProtocol
;
43 EFI_HANDLE
*HandleBuffer
;
44 UINTN NumberOfHandles
;
47 EFI_FIRMWARE_VOLUME2_PROTOCOL
*FvInstance
;
50 EFI_ACPI_COMMON_HEADER
*AcpiTable
;
54 // Ensure the ACPI Table is present
55 Status
= gBS
->LocateProtocol (
56 &gEfiAcpiTableProtocolGuid
,
60 if (EFI_ERROR (Status
)) {
67 // Locate all the Firmware Volume protocols.
68 Status
= gBS
->LocateHandleBuffer (
70 &gEfiFirmwareVolume2ProtocolGuid
,
75 if (EFI_ERROR (Status
)) {
79 // 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 if (EFI_ERROR (Status
)) {
91 goto FREE_HANDLE_BUFFER
;
94 while (Status
== EFI_SUCCESS
) {
95 // AcpiTable must be allocated by ReadSection (ie: AcpiTable == NULL)
98 // See if it has the ACPI storage file
99 Status
= FvInstance
->ReadSection (
108 if (!EFI_ERROR (Status
)) {
110 AcpiTableSize
= ((EFI_ACPI_DESCRIPTION_HEADER
*) AcpiTable
)->Length
;
111 ASSERT (SectionSize
>= AcpiTableSize
);
113 DEBUG ((EFI_D_ERROR
, "- Found '%c%c%c%c' ACPI Table\n",
114 (((EFI_ACPI_DESCRIPTION_HEADER
*) AcpiTable
)->Signature
& 0xFF),
115 ((((EFI_ACPI_DESCRIPTION_HEADER
*) AcpiTable
)->Signature
>> 8) & 0xFF),
116 ((((EFI_ACPI_DESCRIPTION_HEADER
*) AcpiTable
)->Signature
>> 16) & 0xFF),
117 ((((EFI_ACPI_DESCRIPTION_HEADER
*) AcpiTable
)->Signature
>> 24) & 0xFF)));
119 // Install the ACPI Table
120 Status
= AcpiProtocol
->InstallAcpiTable (
126 // Free memory allocated by ReadSection
127 gBS
->FreePool (AcpiTable
);
129 if (EFI_ERROR (Status
)) {
133 // Increment the section instance
141 // Free any allocated buffers
143 gBS
->FreePool (HandleBuffer
);