2 OVMF ACPI Platform Driver for Xen guests
4 Copyright (C) 2021, Red Hat, Inc.
5 Copyright (c) 2008 - 2012, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #include <Library/DebugLib.h> // ASSERT_EFI_ERROR()
11 #include <Library/UefiBootServicesTableLib.h> // gBS
12 #include <Library/XenPlatformLib.h> // XenDetected()
13 #include <Protocol/FirmwareVolume2.h> // gEfiFirmwareVolume2Protocol...
15 #include "AcpiPlatform.h"
20 IN EFI_ACPI_TABLE_PROTOCOL
*AcpiProtocol
,
21 IN VOID
*AcpiTableBuffer
,
22 IN UINTN AcpiTableBufferSize
,
26 return AcpiProtocol
->InstallAcpiTable (
36 Locate the first instance of a protocol. If the protocol requested is an
37 FV protocol, then it will return the first FV that contains the ACPI table
40 @param Instance Return pointer to the first instance of the protocol
42 @return EFI_SUCCESS The function completed successfully.
43 @return EFI_NOT_FOUND The protocol could not be located.
44 @return EFI_OUT_OF_RESOURCES There are not enough resources to find the protocol.
48 LocateFvInstanceWithTables (
49 OUT EFI_FIRMWARE_VOLUME2_PROTOCOL
**Instance
53 EFI_HANDLE
*HandleBuffer
;
54 UINTN NumberOfHandles
;
55 EFI_FV_FILETYPE FileType
;
57 EFI_FV_FILE_ATTRIBUTES Attributes
;
60 EFI_FIRMWARE_VOLUME2_PROTOCOL
*FvInstance
;
67 Status
= gBS
->LocateHandleBuffer (
69 &gEfiFirmwareVolume2ProtocolGuid
,
74 if (EFI_ERROR (Status
)) {
76 // Defined errors at this time are not found and out of resources.
82 // 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 ASSERT_EFI_ERROR (Status
);
97 // See if it has the ACPI storage file
99 Status
= FvInstance
->ReadFile (
101 (EFI_GUID
*)PcdGetPtr (PcdAcpiTableStorageFile
),
110 // If we found it, then we are done
112 if (Status
== EFI_SUCCESS
) {
113 *Instance
= FvInstance
;
119 // Our exit status is determined by the success of the previous operations
120 // If the protocol was found, Instance already points to it.
124 // Free any allocated buffers
126 gBS
->FreePool (HandleBuffer
);
133 Find ACPI tables in an FV and install them.
135 This is now a fall-back path. Normally, we will search for tables provided
138 If that fails, we use this function to load the ACPI tables from an FV. The
139 sources for the FV based tables is located under OvmfPkg/AcpiTables.
141 @param AcpiTable Protocol instance pointer
146 InstallOvmfFvTables (
147 IN EFI_ACPI_TABLE_PROTOCOL
*AcpiTable
151 EFI_FIRMWARE_VOLUME2_PROTOCOL
*FwVol
;
153 EFI_ACPI_COMMON_HEADER
*CurrentTable
;
158 EFI_ACPI_TABLE_INSTALL_ACPI_TABLE TableInstallFunction
;
164 if (QemuDetected ()) {
165 TableInstallFunction
= QemuInstallAcpiTable
;
167 TableInstallFunction
= InstallAcpiTable
;
171 // set FwVol (and use an ASSERT() below) to suppress incorrect
172 // compiler/analyzer warnings
176 // Locate the firmware volume protocol
178 Status
= LocateFvInstanceWithTables (&FwVol
);
179 if (EFI_ERROR (Status
)) {
182 ASSERT (FwVol
!= NULL
);
185 // Read tables from the storage file.
187 while (Status
== EFI_SUCCESS
) {
189 Status
= FwVol
->ReadSection (
191 (EFI_GUID
*)PcdGetPtr (PcdAcpiTableStorageFile
),
194 (VOID
**) &CurrentTable
,
198 if (!EFI_ERROR (Status
)) {
204 TableSize
= ((EFI_ACPI_DESCRIPTION_HEADER
*) CurrentTable
)->Length
;
205 ASSERT (Size
>= TableSize
);
208 // Install ACPI table
210 Status
= TableInstallFunction (
218 // Free memory allocated by ReadSection
220 gBS
->FreePool (CurrentTable
);
222 if (EFI_ERROR (Status
)) {
227 // Increment the instance
238 Effective entrypoint of Acpi Platform driver.
244 @return EFI_LOAD_ERROR
245 @return EFI_OUT_OF_RESOURCES
251 IN EFI_ACPI_TABLE_PROTOCOL
*AcpiTable
256 if (XenDetected ()) {
257 Status
= InstallXenTables (AcpiTable
);
259 Status
= EFI_UNSUPPORTED
;
262 if (EFI_ERROR (Status
)) {
263 Status
= InstallOvmfFvTables (AcpiTable
);