OvmfPkg/Bhyve: add support for QemuFwCfg

QemuFwCfg is much more powerful than BhyveFwCtl. Sadly, BhyveFwCtl
decided to use the same IO ports as QemuFwCfg. It's not possible to use
both interfaces simultaneously. So, prefer QemuFwCfg over BhyveFwCtl.

Signed-off-by: Corvin Köhne <c.koehne@beckhoff.com>
Reviewed-by: Rebecca Cran <rebecca@bsdio.com>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
Acked-by: Peter Grehan <grehan@freebsd.org>
Acked-by: Jiewen Yao <jiewen.yao@intel.com>
This commit is contained in:
Corvin Köhne
2021-10-13 11:19:36 +02:00
committed by mergify[bot]
parent cabd96ad03
commit 4092f1d397
3 changed files with 40 additions and 6 deletions

View File

@ -43,6 +43,7 @@
MemoryAllocationLib MemoryAllocationLib
OrderedCollectionLib OrderedCollectionLib
PcdLib PcdLib
QemuFwCfgLib
UefiBootServicesTableLib UefiBootServicesTableLib
UefiDriverEntryPoint UefiDriverEntryPoint
UefiLib UefiLib

View File

@ -11,6 +11,41 @@
#include <Library/BaseMemoryLib.h> #include <Library/BaseMemoryLib.h>
#include <Library/BhyveFwCtlLib.h> #include <Library/BhyveFwCtlLib.h>
#include <Library/MemoryAllocationLib.h> #include <Library/MemoryAllocationLib.h>
#include <Library/QemuFwCfgLib.h> // QemuFwCfgFindFile()
STATIC
EFI_STATUS
EFIAPI
BhyveGetCpuCount (
OUT UINT32 *CpuCount
)
{
FIRMWARE_CONFIG_ITEM Item;
UINTN Size;
if (QemuFwCfgIsAvailable ()) {
if (EFI_ERROR (QemuFwCfgFindFile ("opt/bhyve/hw.ncpu", &Item, &Size))) {
return EFI_NOT_FOUND;
} else if (Size != sizeof (*CpuCount)) {
return EFI_BAD_BUFFER_SIZE;
}
QemuFwCfgSelectItem (Item);
QemuFwCfgReadBytes (Size, CpuCount);
return EFI_SUCCESS;
}
//
// QemuFwCfg not available, try BhyveFwCtl.
//
Size = sizeof (*CpuCount);
if (BhyveFwCtlGet ("hw.ncpu", CpuCount, &Size) == RETURN_SUCCESS) {
return EFI_SUCCESS;
}
return EFI_UNSUPPORTED;
}
STATIC STATIC
EFI_STATUS EFI_STATUS
@ -23,7 +58,6 @@ BhyveInstallAcpiMadtTable (
) )
{ {
UINT32 CpuCount; UINT32 CpuCount;
UINTN cSize;
UINTN NewBufferSize; UINTN NewBufferSize;
EFI_ACPI_1_0_MULTIPLE_APIC_DESCRIPTION_TABLE_HEADER *Madt; EFI_ACPI_1_0_MULTIPLE_APIC_DESCRIPTION_TABLE_HEADER *Madt;
EFI_ACPI_1_0_PROCESSOR_LOCAL_APIC_STRUCTURE *LocalApic; EFI_ACPI_1_0_PROCESSOR_LOCAL_APIC_STRUCTURE *LocalApic;
@ -36,9 +70,8 @@ BhyveInstallAcpiMadtTable (
ASSERT (AcpiTableBufferSize >= sizeof (EFI_ACPI_DESCRIPTION_HEADER)); ASSERT (AcpiTableBufferSize >= sizeof (EFI_ACPI_DESCRIPTION_HEADER));
// Query the host for the number of vCPUs // Query the host for the number of vCPUs
CpuCount = 0; Status = BhyveGetCpuCount (&CpuCount);
cSize = sizeof (CpuCount); if (!EFI_ERROR (Status)) {
if (BhyveFwCtlGet ("hw.ncpu", &CpuCount, &cSize) == RETURN_SUCCESS) {
DEBUG ((DEBUG_INFO, "Retrieved CpuCount %d\n", CpuCount)); DEBUG ((DEBUG_INFO, "Retrieved CpuCount %d\n", CpuCount));
ASSERT (CpuCount >= 1); ASSERT (CpuCount >= 1);
} else { } else {

View File

@ -164,8 +164,7 @@
SecurityManagementLib|MdeModulePkg/Library/DxeSecurityManagementLib/DxeSecurityManagementLib.inf SecurityManagementLib|MdeModulePkg/Library/DxeSecurityManagementLib/DxeSecurityManagementLib.inf
UefiUsbLib|MdePkg/Library/UefiUsbLib/UefiUsbLib.inf UefiUsbLib|MdePkg/Library/UefiUsbLib/UefiUsbLib.inf
SerializeVariablesLib|OvmfPkg/Library/SerializeVariablesLib/SerializeVariablesLib.inf SerializeVariablesLib|OvmfPkg/Library/SerializeVariablesLib/SerializeVariablesLib.inf
QemuFwCfgLib|OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLibNull.inf QemuFwCfgLib|OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgDxeLib.inf
QemuFwCfgS3Lib|OvmfPkg/Library/QemuFwCfgS3Lib/BaseQemuFwCfgS3LibNull.inf
BhyveFwCtlLib|OvmfPkg/Library/BhyveFwCtlLib/BhyveFwCtlLib.inf BhyveFwCtlLib|OvmfPkg/Library/BhyveFwCtlLib/BhyveFwCtlLib.inf
VirtioLib|OvmfPkg/Library/VirtioLib/VirtioLib.inf VirtioLib|OvmfPkg/Library/VirtioLib/VirtioLib.inf
MemEncryptSevLib|OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLib.inf MemEncryptSevLib|OvmfPkg/Library/BaseMemEncryptSevLib/DxeMemEncryptSevLib.inf
@ -358,6 +357,7 @@
!endif !endif
PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf
MpInitLib|UefiCpuPkg/Library/MpInitLibUp/MpInitLibUp.inf MpInitLib|UefiCpuPkg/Library/MpInitLibUp/MpInitLibUp.inf
QemuFwCfgS3Lib|OvmfPkg/Library/QemuFwCfgS3Lib/DxeQemuFwCfgS3LibFwCfg.inf
[LibraryClasses.common.UEFI_APPLICATION] [LibraryClasses.common.UEFI_APPLICATION]
PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf