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 (
31 Locate the first instance of a protocol. If the protocol requested is an
32 FV protocol, then it will return the first FV that contains the ACPI table
35 @param Instance Return pointer to the first instance of the protocol
37 @return EFI_SUCCESS The function completed successfully.
38 @return EFI_NOT_FOUND The protocol could not be located.
39 @return EFI_OUT_OF_RESOURCES There are not enough resources to find the protocol.
43 LocateFvInstanceWithTables (
44 OUT EFI_FIRMWARE_VOLUME2_PROTOCOL
**Instance
48 EFI_HANDLE
*HandleBuffer
;
49 UINTN NumberOfHandles
;
50 EFI_FV_FILETYPE FileType
;
52 EFI_FV_FILE_ATTRIBUTES Attributes
;
55 EFI_FIRMWARE_VOLUME2_PROTOCOL
*FvInstance
;
62 Status
= gBS
->LocateHandleBuffer (
64 &gEfiFirmwareVolume2ProtocolGuid
,
69 if (EFI_ERROR (Status
)) {
71 // Defined errors at this time are not found and out of resources.
77 // Looking for FV with ACPI storage file
79 for (Index
= 0; Index
< NumberOfHandles
; Index
++) {
81 // Get the protocol on this handle
82 // This should not fail because of LocateHandleBuffer
84 Status
= gBS
->HandleProtocol (
86 &gEfiFirmwareVolume2ProtocolGuid
,
89 ASSERT_EFI_ERROR (Status
);
92 // See if it has the ACPI storage file
94 Status
= FvInstance
->ReadFile (
96 (EFI_GUID
*)PcdGetPtr (PcdAcpiTableStorageFile
),
105 // If we found it, then we are done
107 if (Status
== EFI_SUCCESS
) {
108 *Instance
= FvInstance
;
114 // Our exit status is determined by the success of the previous operations
115 // If the protocol was found, Instance already points to it.
119 // Free any allocated buffers
121 gBS
->FreePool (HandleBuffer
);
127 Find ACPI tables in an FV and install them.
129 This is now a fall-back path. Normally, we will search for tables provided
132 If that fails, we use this function to load the ACPI tables from an FV. The
133 sources for the FV based tables is located under OvmfPkg/Bhyve/AcpiTables.
135 @param AcpiTable Protocol instance pointer
140 InstallOvmfFvTables (
141 IN EFI_ACPI_TABLE_PROTOCOL
*AcpiTable
145 EFI_FIRMWARE_VOLUME2_PROTOCOL
*FwVol
;
147 EFI_ACPI_COMMON_HEADER
*CurrentTable
;
152 EFI_ACPI_TABLE_INSTALL_ACPI_TABLE TableInstallFunction
;
158 TableInstallFunction
= BhyveInstallAcpiTable
;
161 // set FwVol (and use an ASSERT() below) to suppress incorrect
162 // compiler/analyzer warnings
166 // Locate the firmware volume protocol
168 Status
= LocateFvInstanceWithTables (&FwVol
);
169 if (EFI_ERROR (Status
)) {
173 ASSERT (FwVol
!= NULL
);
176 // Read tables from the storage file.
178 while (Status
== EFI_SUCCESS
) {
179 Status
= FwVol
->ReadSection (
181 (EFI_GUID
*)PcdGetPtr (PcdAcpiTableStorageFile
),
184 (VOID
**)&CurrentTable
,
188 if (!EFI_ERROR (Status
)) {
194 TableSize
= ((EFI_ACPI_DESCRIPTION_HEADER
*)CurrentTable
)->Length
;
195 ASSERT (Size
>= TableSize
);
198 // Install ACPI table
200 Status
= TableInstallFunction (
208 // Free memory allocated by ReadSection
210 gBS
->FreePool (CurrentTable
);
212 if (EFI_ERROR (Status
)) {
217 // Increment the instance
228 Effective entrypoint of Acpi Platform driver.
234 @return EFI_LOAD_ERROR
235 @return EFI_OUT_OF_RESOURCES
241 IN EFI_ACPI_TABLE_PROTOCOL
*AcpiTable
246 Status
= InstallOvmfFvTables (AcpiTable
);