3 * Copyright (c) 2014-2015, 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 if it verifies
28 the function condition.
30 @param AcpiFile Guid of the ACPI file into the Firmware Volume
31 @param CheckAcpiTableFunction Function that checks if the ACPI table should be installed
33 @return EFI_SUCCESS The function completed successfully.
34 @return EFI_NOT_FOUND The protocol could not be located.
35 @return EFI_OUT_OF_RESOURCES There are not enough resources to find the protocol.
39 LocateAndInstallAcpiFromFvConditional (
40 IN CONST EFI_GUID
* AcpiFile
,
41 IN EFI_LOCATE_ACPI_CHECK CheckAcpiTableFunction
45 EFI_ACPI_TABLE_PROTOCOL
*AcpiProtocol
;
46 EFI_HANDLE
*HandleBuffer
;
47 UINTN NumberOfHandles
;
50 EFI_FIRMWARE_VOLUME2_PROTOCOL
*FvInstance
;
53 EFI_ACPI_COMMON_HEADER
*AcpiTable
;
58 // Ensure the ACPI Table is present
59 Status
= gBS
->LocateProtocol (
60 &gEfiAcpiTableProtocolGuid
,
64 if (EFI_ERROR (Status
)) {
71 // Locate all the Firmware Volume protocols.
72 Status
= gBS
->LocateHandleBuffer (
74 &gEfiFirmwareVolume2ProtocolGuid
,
79 if (EFI_ERROR (Status
)) {
83 // Looking for FV with ACPI storage file
84 for (Index
= 0; Index
< NumberOfHandles
; Index
++) {
86 // Get the protocol on this handle
87 // This should not fail because of LocateHandleBuffer
89 Status
= gBS
->HandleProtocol (
91 &gEfiFirmwareVolume2ProtocolGuid
,
94 if (EFI_ERROR (Status
)) {
95 goto FREE_HANDLE_BUFFER
;
98 while (Status
== EFI_SUCCESS
) {
99 // AcpiTable must be allocated by ReadSection (ie: AcpiTable == NULL)
102 // See if it has the ACPI storage file
103 Status
= FvInstance
->ReadSection (
112 if (!EFI_ERROR (Status
)) {
114 AcpiTableSize
= ((EFI_ACPI_DESCRIPTION_HEADER
*) AcpiTable
)->Length
;
115 ASSERT (SectionSize
>= AcpiTableSize
);
117 DEBUG ((EFI_D_ERROR
, "- Found '%c%c%c%c' ACPI Table\n",
118 (((EFI_ACPI_DESCRIPTION_HEADER
*) AcpiTable
)->Signature
& 0xFF),
119 ((((EFI_ACPI_DESCRIPTION_HEADER
*) AcpiTable
)->Signature
>> 8) & 0xFF),
120 ((((EFI_ACPI_DESCRIPTION_HEADER
*) AcpiTable
)->Signature
>> 16) & 0xFF),
121 ((((EFI_ACPI_DESCRIPTION_HEADER
*) AcpiTable
)->Signature
>> 24) & 0xFF)));
123 // Is the ACPI table valid?
124 if (CheckAcpiTableFunction
) {
125 Valid
= CheckAcpiTableFunction ((EFI_ACPI_DESCRIPTION_HEADER
*)AcpiTable
);
130 // Install the ACPI Table
132 Status
= AcpiProtocol
->InstallAcpiTable (
140 // Free memory allocated by ReadSection
141 gBS
->FreePool (AcpiTable
);
143 if (EFI_ERROR (Status
)) {
147 // Increment the section instance
155 // Free any allocated buffers
157 gBS
->FreePool (HandleBuffer
);
163 Locate and Install the ACPI tables from the Firmware Volume
165 @param AcpiFile Guid of the ACPI file into the Firmware Volume
167 @return EFI_SUCCESS The function completed successfully.
168 @return EFI_NOT_FOUND The protocol could not be located.
169 @return EFI_OUT_OF_RESOURCES There are not enough resources to find the protocol.
173 LocateAndInstallAcpiFromFv (
174 IN CONST EFI_GUID
* AcpiFile
177 return LocateAndInstallAcpiFromFvConditional (AcpiFile
, NULL
);