2 bhyve ACPI Platform Driver
4 Copyright (c) 2020, Rebecca Cran <rebecca@bsdio.com>
5 Copyright (c) 2008 - 2012, Intel Corporation. All rights reserved.<BR>
7 SPDX-License-Identifier: BSD-2-Clause-Patent
11 #include "AcpiPlatform.h"
16 IN EFI_ACPI_TABLE_PROTOCOL
*AcpiProtocol
,
17 IN VOID
*AcpiTableBuffer
,
18 IN UINTN AcpiTableBufferSize
,
22 return AcpiProtocol
->InstallAcpiTable (
32 Locate the first instance of a protocol. If the protocol requested is an
33 FV protocol, then it will return the first FV that contains the ACPI table
36 @param Instance Return pointer to the first instance of the protocol
38 @return EFI_SUCCESS The function completed successfully.
39 @return EFI_NOT_FOUND The protocol could not be located.
40 @return EFI_OUT_OF_RESOURCES There are not enough resources to find the protocol.
44 LocateFvInstanceWithTables (
45 OUT EFI_FIRMWARE_VOLUME2_PROTOCOL
**Instance
49 EFI_HANDLE
*HandleBuffer
;
50 UINTN NumberOfHandles
;
51 EFI_FV_FILETYPE FileType
;
53 EFI_FV_FILE_ATTRIBUTES Attributes
;
56 EFI_FIRMWARE_VOLUME2_PROTOCOL
*FvInstance
;
63 Status
= gBS
->LocateHandleBuffer (
65 &gEfiFirmwareVolume2ProtocolGuid
,
70 if (EFI_ERROR (Status
)) {
72 // Defined errors at this time are not found and out of resources.
78 // 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 (EFI_GUID
*)PcdGetPtr (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 Find ACPI tables in an FV and install them.
131 This is now a fall-back path. Normally, we will search for tables provided
134 If that fails, we use this function to load the ACPI tables from an FV. The
135 sources for the FV based tables is located under OvmfPkg/Bhyve/AcpiTables.
137 @param AcpiTable Protocol instance pointer
142 InstallOvmfFvTables (
143 IN EFI_ACPI_TABLE_PROTOCOL
*AcpiTable
147 EFI_FIRMWARE_VOLUME2_PROTOCOL
*FwVol
;
149 EFI_ACPI_COMMON_HEADER
*CurrentTable
;
154 EFI_ACPI_TABLE_INSTALL_ACPI_TABLE TableInstallFunction
;
160 TableInstallFunction
= BhyveInstallAcpiTable
;
163 // set FwVol (and use an ASSERT() below) to suppress incorrect
164 // compiler/analyzer warnings
168 // Locate the firmware volume protocol
170 Status
= LocateFvInstanceWithTables (&FwVol
);
171 if (EFI_ERROR (Status
)) {
174 ASSERT (FwVol
!= NULL
);
177 // Read tables from the storage file.
179 while (Status
== EFI_SUCCESS
) {
181 Status
= FwVol
->ReadSection (
183 (EFI_GUID
*)PcdGetPtr (PcdAcpiTableStorageFile
),
186 (VOID
**) &CurrentTable
,
190 if (!EFI_ERROR (Status
)) {
196 TableSize
= ((EFI_ACPI_DESCRIPTION_HEADER
*) CurrentTable
)->Length
;
197 ASSERT (Size
>= TableSize
);
200 // Install ACPI table
202 Status
= TableInstallFunction (
210 // Free memory allocated by ReadSection
212 gBS
->FreePool (CurrentTable
);
214 if (EFI_ERROR (Status
)) {
219 // Increment the instance
230 Effective entrypoint of Acpi Platform driver.
236 @return EFI_LOAD_ERROR
237 @return EFI_OUT_OF_RESOURCES
243 IN EFI_ACPI_TABLE_PROTOCOL
*AcpiTable
248 Status
= InstallOvmfFvTables (AcpiTable
);