3 * Copyright (c) 2014-2015, ARM Limited. All rights reserved.
5 * SPDX-License-Identifier: BSD-2-Clause-Patent
11 #include <Library/AcpiLib.h>
12 #include <Library/DebugLib.h>
13 #include <Library/UefiBootServicesTableLib.h>
15 #include <Protocol/AcpiTable.h>
16 #include <Protocol/FirmwareVolume2.h>
18 #include <IndustryStandard/Acpi.h>
21 Locate and Install the ACPI tables from the Firmware Volume if it verifies
22 the function condition.
24 @param AcpiFile Guid of the ACPI file into the Firmware Volume
25 @param CheckAcpiTableFunction Function that checks if the ACPI table should be installed
27 @return EFI_SUCCESS The function completed successfully.
28 @return EFI_NOT_FOUND The protocol could not be located.
29 @return EFI_OUT_OF_RESOURCES There are not enough resources to find the protocol.
33 LocateAndInstallAcpiFromFvConditional (
34 IN CONST EFI_GUID
* AcpiFile
,
35 IN EFI_LOCATE_ACPI_CHECK CheckAcpiTableFunction
39 EFI_ACPI_TABLE_PROTOCOL
*AcpiProtocol
;
40 EFI_HANDLE
*HandleBuffer
;
41 UINTN NumberOfHandles
;
44 EFI_FIRMWARE_VOLUME2_PROTOCOL
*FvInstance
;
47 EFI_ACPI_COMMON_HEADER
*AcpiTable
;
52 // Ensure the ACPI Table is present
53 Status
= gBS
->LocateProtocol (
54 &gEfiAcpiTableProtocolGuid
,
58 if (EFI_ERROR (Status
)) {
65 // Locate all the Firmware Volume protocols.
66 Status
= gBS
->LocateHandleBuffer (
68 &gEfiFirmwareVolume2ProtocolGuid
,
73 if (EFI_ERROR (Status
)) {
77 // Looking for FV with ACPI storage file
78 for (Index
= 0; Index
< NumberOfHandles
; Index
++) {
80 // Get the protocol on this handle
81 // This should not fail because of LocateHandleBuffer
83 Status
= gBS
->HandleProtocol (
85 &gEfiFirmwareVolume2ProtocolGuid
,
88 if (EFI_ERROR (Status
)) {
89 goto FREE_HANDLE_BUFFER
;
92 while (Status
== EFI_SUCCESS
) {
93 // AcpiTable must be allocated by ReadSection (ie: AcpiTable == NULL)
96 // See if it has the ACPI storage file
97 Status
= FvInstance
->ReadSection (
106 if (!EFI_ERROR (Status
)) {
108 AcpiTableSize
= ((EFI_ACPI_DESCRIPTION_HEADER
*) AcpiTable
)->Length
;
109 ASSERT (SectionSize
>= AcpiTableSize
);
111 DEBUG ((EFI_D_ERROR
, "- Found '%c%c%c%c' ACPI Table\n",
112 (((EFI_ACPI_DESCRIPTION_HEADER
*) AcpiTable
)->Signature
& 0xFF),
113 ((((EFI_ACPI_DESCRIPTION_HEADER
*) AcpiTable
)->Signature
>> 8) & 0xFF),
114 ((((EFI_ACPI_DESCRIPTION_HEADER
*) AcpiTable
)->Signature
>> 16) & 0xFF),
115 ((((EFI_ACPI_DESCRIPTION_HEADER
*) AcpiTable
)->Signature
>> 24) & 0xFF)));
117 // Is the ACPI table valid?
118 if (CheckAcpiTableFunction
) {
119 Valid
= CheckAcpiTableFunction ((EFI_ACPI_DESCRIPTION_HEADER
*)AcpiTable
);
124 // Install the ACPI Table
126 Status
= AcpiProtocol
->InstallAcpiTable (
134 // Free memory allocated by ReadSection
135 gBS
->FreePool (AcpiTable
);
137 if (EFI_ERROR (Status
)) {
141 // Increment the section instance
149 // Free any allocated buffers
151 gBS
->FreePool (HandleBuffer
);
157 Locate and Install the ACPI tables from the Firmware Volume
159 @param AcpiFile Guid of the ACPI file into the Firmware Volume
161 @return EFI_SUCCESS The function completed successfully.
162 @return EFI_NOT_FOUND The protocol could not be located.
163 @return EFI_OUT_OF_RESOURCES There are not enough resources to find the protocol.
167 LocateAndInstallAcpiFromFv (
168 IN CONST EFI_GUID
* AcpiFile
171 return LocateAndInstallAcpiFromFvConditional (AcpiFile
, NULL
);