From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smic.int.bsdio.com (smic.int.bsdio.com [65.103.231.193]) by mx.groups.io with SMTP id smtpd.web11.846.1586992429039933429 for ; Wed, 15 Apr 2020 16:13:49 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=none, err=permanent DNS error (domain: smic.int.bsdio.com, ip: 65.103.231.193, mailfrom: bcran@smic.int.bsdio.com) Received: from smic.int.bsdio.com (localhost [127.0.0.1]) by smic.int.bsdio.com (8.15.2/8.15.2) with ESMTPS id 03FNAAgD071922 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Wed, 15 Apr 2020 17:10:10 -0600 (MDT) (envelope-from bcran@smic.int.bsdio.com) Received: (from bcran@localhost) by smic.int.bsdio.com (8.15.2/8.15.2/Submit) id 03FNAA2w071128; Wed, 15 Apr 2020 17:10:10 -0600 (MDT) (envelope-from bcran) From: "Rebecca Cran" To: devel@edk2.groups.io Cc: Jordan Justen , Laszlo Ersek , Ard Biesheuvel , Rebecca Cran Subject: [PATCH 10/13] OvmfPkg: Add bhyve support to AcpiPlatformDxe Date: Wed, 15 Apr 2020 17:09:36 -0600 Message-Id: <883772c5ab95df8397781f4ab7c790b396043c5c.1586991816.git.rebecca@bsdio.com> X-Mailer: git-send-email 2.26.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Add bhyve support to AcpiPlatformDxe. bhyve doesn't use QemuFwCfg and installs its own ACPI tables, so introduce a new AcpiPlatformDxeBhyve.inf that's customized for it. Signed-off-by: Rebecca Cran --- OvmfPkg/AcpiPlatformDxe/AcpiPlatform.c | 8 +- OvmfPkg/AcpiPlatformDxe/AcpiPlatform.h | 9 ++ OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf | 3 + .../AcpiPlatformDxe/AcpiPlatformDxeBhyve.inf | 81 ++++++++++ OvmfPkg/AcpiPlatformDxe/Bhyve.c | 138 ++++++++++++++++++ OvmfPkg/OvmfPkgIa32.dsc | 1 + OvmfPkg/OvmfPkgIa32X64.dsc | 1 + OvmfPkg/OvmfPkgX64.dsc | 1 + OvmfPkg/OvmfXen.dsc | 1 + 9 files changed, 240 insertions(+), 3 deletions(-) create mode 100644 OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxeBhyve.inf create mode 100644 OvmfPkg/AcpiPlatformDxe/Bhyve.c diff --git a/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.c b/OvmfPkg/AcpiPlatformD= xe/AcpiPlatform.c index f872d91aea..5f501c38bf 100644 --- a/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.c +++ b/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.c @@ -157,8 +157,10 @@ InstallOvmfFvTables ( =0D if (QemuDetected ()) {=0D TableInstallFunction =3D QemuInstallAcpiTable;=0D - } else {=0D + } else if (XenDetected()) {=0D TableInstallFunction =3D InstallAcpiTable;=0D + } else {=0D + TableInstallFunction =3D BhyveInstallAcpiTable;=0D }=0D =0D //=0D @@ -245,11 +247,11 @@ InstallAcpiTables ( IN EFI_ACPI_TABLE_PROTOCOL *AcpiTable=0D )=0D {=0D - EFI_STATUS Status;=0D + EFI_STATUS Status =3D EFI_UNSUPPORTED;=0D =0D if (XenDetected ()) {=0D Status =3D InstallXenTables (AcpiTable);=0D - } else {=0D + } else if (QemuDetected()) {=0D Status =3D InstallQemuFwCfgTables (AcpiTable);=0D }=0D =0D diff --git a/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.h b/OvmfPkg/AcpiPlatformD= xe/AcpiPlatform.h index 9597e028e4..160a541aee 100644 --- a/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.h +++ b/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.h @@ -53,6 +53,15 @@ QemuInstallAcpiTable ( OUT UINTN *TableKey=0D );=0D =0D +EFI_STATUS=0D +EFIAPI=0D +BhyveInstallAcpiTable(=0D + IN EFI_ACPI_TABLE_PROTOCOL *AcpiProtocol,=0D + IN VOID *AcpiTableBuffer,=0D + IN UINTN AcpiTableBufferSize,=0D + OUT UINTN *TableKey=0D + );=0D +=0D EFI_STATUS=0D EFIAPI=0D InstallXenTables (=0D diff --git a/OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf b/OvmfPkg/AcpiPlat= formDxe/AcpiPlatformDxe.inf index e486b8afa5..f3b5ab413b 100644 --- a/OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf +++ b/OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf @@ -30,11 +30,13 @@ QemuFwCfgAcpi.c=0D QemuLoader.h=0D Xen.c=0D + Bhyve.c=0D =0D [Packages]=0D MdePkg/MdePkg.dec=0D MdeModulePkg/MdeModulePkg.dec=0D OvmfPkg/OvmfPkg.dec=0D + BhyvePkg/BhyvePkg.dec=0D UefiCpuPkg/UefiCpuPkg.dec=0D =0D [LibraryClasses]=0D @@ -46,6 +48,7 @@ UefiDriverEntryPoint=0D QemuFwCfgLib=0D QemuFwCfgS3Lib=0D + BhyveFwCtlLib=0D MemoryAllocationLib=0D BaseLib=0D DxeServicesTableLib=0D diff --git a/OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxeBhyve.inf b/OvmfPkg/Acp= iPlatformDxe/AcpiPlatformDxeBhyve.inf new file mode 100644 index 0000000000..b8bd8ad20e --- /dev/null +++ b/OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxeBhyve.inf @@ -0,0 +1,81 @@ +## @file=0D +# OVMF ACPI Platform Driver=0D +#=0D +# Copyright (c) 2008 - 2018, Intel Corporation. All rights reserved.
= =0D +# This program and the accompanying materials=0D +# are licensed and made available under the terms and conditions of the B= SD License=0D +# which accompanies this distribution. The full text of the license may = be found at=0D +# http://opensource.org/licenses/bsd-license.php=0D +#=0D +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,=0D +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IM= PLIED.=0D +#=0D +##=0D +=0D +[Defines]=0D + INF_VERSION =3D 0x00010005=0D + BASE_NAME =3D AcpiPlatformBhyve=0D + FILE_GUID =3D D5F92408-BAB5-44CA-8A60-C212F01D7E9D= =0D + MODULE_TYPE =3D DXE_DRIVER=0D + VERSION_STRING =3D 1.0=0D + ENTRY_POINT =3D AcpiPlatformEntryPoint=0D +=0D +#=0D +# The following information is for reference only and not required by the = build tools.=0D +#=0D +# VALID_ARCHITECTURES =3D IA32 X64 EBC=0D +#=0D +=0D +[Sources]=0D + AcpiPlatform.c=0D + AcpiPlatform.h=0D + BootScript.c=0D + EntryPoint.c=0D + PciDecoding.c=0D + Qemu.c=0D + QemuFwCfgAcpi.c=0D + QemuLoader.h=0D + Xen.c=0D + Bhyve.c=0D +=0D +[Packages]=0D + MdePkg/MdePkg.dec=0D + MdeModulePkg/MdeModulePkg.dec=0D + BhyvePkg/BhyvePkg.dec=0D + UefiCpuPkg/UefiCpuPkg.dec=0D + PcAtChipsetPkg/PcAtChipsetPkg.dec=0D +=0D +[LibraryClasses]=0D + UefiLib=0D + PcdLib=0D + BaseMemoryLib=0D + DebugLib=0D + UefiBootServicesTableLib=0D + UefiDriverEntryPoint=0D + HobLib=0D + BhyveFwCtlLib=0D + QemuFwCfgLib=0D + QemuFwCfgS3Lib=0D + MemoryAllocationLib=0D + BaseLib=0D + DxeServicesTableLib=0D + OrderedCollectionLib=0D + XenPlatformLib=0D +=0D +[Protocols]=0D + gEfiAcpiTableProtocolGuid # PROTOCOL ALWAYS_CONSUMED= =0D + gEfiFirmwareVolume2ProtocolGuid # PROTOCOL SOMETIMES_CONSU= MED=0D + gEfiPciIoProtocolGuid # PROTOCOL SOMETIMES_CONSU= MED=0D +=0D +[Guids]=0D + gRootBridgesConnectedEventGroupGuid=0D +=0D +[Pcd]=0D + gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiTableStorageFile=0D + gEfiMdeModulePkgTokenSpaceGuid.PcdPciDisableBusEnumeration=0D + gUefiCpuPkgTokenSpaceGuid.PcdCpuLocalApicBaseAddress=0D + gUefiOvmfPkgTokenSpaceGuid.Pcd8259LegacyModeEdgeLevel=0D + gUefiOvmfPkgTokenSpaceGuid.PcdOvmfFdBaseAddress=0D +=0D +[Depex]=0D + gEfiAcpiTableProtocolGuid=0D diff --git a/OvmfPkg/AcpiPlatformDxe/Bhyve.c b/OvmfPkg/AcpiPlatformDxe/Bhyv= e.c new file mode 100644 index 0000000000..7f1a5fd664 --- /dev/null +++ b/OvmfPkg/AcpiPlatformDxe/Bhyve.c @@ -0,0 +1,138 @@ +/*=0D + * Copyright (c) 2008 - 2012, Intel Corporation. All rights reserved.
= =0D + * Copyright (C) 2012, Red Hat, Inc.=0D + * Copyright (c) 2014, Pluribus Networks, Inc.=0D + *=0D + * This program and the accompanying materials are licensed and made=0D + * available under the terms and conditions of the BSD License which=0D + * accompanies this distribution. The full text of the license may be=0D + * found at http://opensource.org/licenses/bsd-license.php=0D + *=0D + * THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS"=0D + * BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER=0D + * EXPRESS OR IMPLIED.=0D + */=0D +#include "AcpiPlatform.h"=0D +=0D +#include =0D +#include =0D +#include =0D +=0D +STATIC=0D +EFI_STATUS=0D +EFIAPI=0D +BhyveInstallAcpiMadtTable (=0D + IN EFI_ACPI_TABLE_PROTOCOL *AcpiProtocol,=0D + IN VOID *AcpiTableBuffer,=0D + IN UINTN AcpiTableBufferSize,=0D + OUT UINTN *TableKey=0D + )=0D +{=0D + UINT32 CpuCount;=0D + UINTN cSize;=0D + UINTN NewBufferSize;=0D + EFI_ACPI_1_0_MULTIPLE_APIC_DESCRIPTION_TABLE_HEADER *Madt;=0D + EFI_ACPI_1_0_PROCESSOR_LOCAL_APIC_STRUCTURE *LocalApic;=0D + EFI_ACPI_1_0_IO_APIC_STRUCTURE *IoApic;=0D + EFI_ACPI_1_0_INTERRUPT_SOURCE_OVERRIDE_STRUCTURE *Iso;=0D + VOID *Ptr;=0D + UINTN Loop;=0D + EFI_STATUS Status;=0D +=0D + ASSERT (AcpiTableBufferSize >=3D sizeof (EFI_ACPI_DESCRIPTION_HEADER));= =0D +=0D + // Query the host for the number of vCPUs=0D + CpuCount =3D 0;=0D + cSize =3D sizeof(CpuCount);=0D + if (BhyveFwCtlGet ("hw.ncpu", &CpuCount, &cSize) =3D=3D RETURN_SUCCESS) = {=0D + DEBUG ((DEBUG_INFO, "Retrieved CpuCount %d\n", CpuCount));=0D + ASSERT (CpuCount >=3D 1);=0D + } else {=0D + DEBUG ((DEBUG_INFO, "CpuCount retrieval error\n"));=0D + CpuCount =3D 1;=0D + }=0D +=0D + NewBufferSize =3D 1 * sizeof (*Madt) +=0D + CpuCount * sizeof (*LocalApic) +=0D + 1 * sizeof (*IoApic) +=0D + 1 * sizeof (*Iso);=0D +=0D + Madt =3D AllocatePool (NewBufferSize);=0D + if (Madt =3D=3D NULL) {=0D + return EFI_OUT_OF_RESOURCES;=0D + }=0D +=0D + CopyMem (&(Madt->Header), AcpiTableBuffer, sizeof (EFI_ACPI_DESCRIPTION_= HEADER));=0D + Madt->Header.Length =3D (UINT32) NewBufferSize;=0D + Madt->LocalApicAddress =3D 0xFEE00000;=0D + Madt->Flags =3D EFI_ACPI_1_0_PCAT_COMPAT;=0D + Ptr =3D Madt + 1;=0D +=0D + LocalApic =3D Ptr;=0D + for (Loop =3D 0; Loop < CpuCount; ++Loop) {=0D + LocalApic->Type =3D EFI_ACPI_1_0_PROCESSOR_LOCAL_APIC;=0D + LocalApic->Length =3D sizeof (*LocalApic);=0D + LocalApic->AcpiProcessorId =3D (UINT8) Loop;=0D + LocalApic->ApicId =3D (UINT8) Loop;=0D + LocalApic->Flags =3D 1; // enabled=0D + ++LocalApic;=0D + }=0D + Ptr =3D LocalApic;=0D +=0D + IoApic =3D Ptr;=0D + IoApic->Type =3D EFI_ACPI_1_0_IO_APIC;=0D + IoApic->Length =3D sizeof (*IoApic);=0D + IoApic->IoApicId =3D (UINT8) CpuCount;=0D + IoApic->Reserved =3D EFI_ACPI_RESERVED_BYTE;=0D + IoApic->IoApicAddress =3D 0xFEC00000;=0D + IoApic->SystemVectorBase =3D 0x00000000;=0D + Ptr =3D IoApic + 1;=0D +=0D + //=0D + // IRQ0 (8254 Timer) =3D> IRQ2 (PIC) Interrupt Source Override Structure= =0D + //=0D + Iso =3D Ptr;=0D + Iso->Type =3D EFI_ACPI_1_0_INTERRUPT_SOURCE_OVERR= IDE;=0D + Iso->Length =3D sizeof (*Iso);=0D + Iso->Bus =3D 0x00; // ISA=0D + Iso->Source =3D 0x00; // IRQ0=0D + Iso->GlobalSystemInterruptVector =3D 0x00000002;=0D + Iso->Flags =3D 0x0000; // Conforms to specs of the= bus=0D + Ptr =3D Iso + 1;=0D +=0D + ASSERT ((UINTN) ((UINT8 *)Ptr - (UINT8 *)Madt) =3D=3D NewBufferSize);=0D + Status =3D InstallAcpiTable (AcpiProtocol, Madt, NewBufferSize, TableKey= );=0D +=0D + FreePool (Madt);=0D +=0D + return Status;=0D +}=0D +=0D +EFI_STATUS=0D +EFIAPI=0D +BhyveInstallAcpiTable (=0D + IN EFI_ACPI_TABLE_PROTOCOL *AcpiProtocol,=0D + IN VOID *AcpiTableBuffer,=0D + IN UINTN AcpiTableBufferSize,=0D + OUT UINTN *TableKey=0D + )=0D +{=0D + EFI_ACPI_DESCRIPTION_HEADER *Hdr;=0D + EFI_ACPI_TABLE_INSTALL_ACPI_TABLE TableInstallFunction;=0D +=0D + Hdr =3D (EFI_ACPI_DESCRIPTION_HEADER*) AcpiTableBuffer;=0D + switch (Hdr->Signature) {=0D + case EFI_ACPI_1_0_APIC_SIGNATURE:=0D + TableInstallFunction =3D BhyveInstallAcpiMadtTable;=0D + break;=0D + default:=0D + TableInstallFunction =3D InstallAcpiTable;=0D + }=0D +=0D + return TableInstallFunction (=0D + AcpiProtocol,=0D + AcpiTableBuffer,=0D + AcpiTableBufferSize,=0D + TableKey=0D + );=0D +}=0D diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc index cbc5f0e583..3dd41e4f1c 100644 --- a/OvmfPkg/OvmfPkgIa32.dsc +++ b/OvmfPkg/OvmfPkgIa32.dsc @@ -159,6 +159,7 @@ UefiUsbLib|MdePkg/Library/UefiUsbLib/UefiUsbLib.inf=0D SerializeVariablesLib|OvmfPkg/Library/SerializeVariablesLib/SerializeVar= iablesLib.inf=0D QemuFwCfgLib|OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgDxeLib.inf=0D + BhyveFwCtlLib|BhyvePkg/Library/BhyveFwCtlLibNull/BhyveFwCtlLibNull.inf=0D VirtioLib|OvmfPkg/Library/VirtioLib/VirtioLib.inf=0D LoadLinuxLib|OvmfPkg/Library/LoadLinuxLib/LoadLinuxLib.inf=0D MemEncryptSevLib|OvmfPkg/Library/BaseMemEncryptSevLib/BaseMemEncryptSevL= ib.inf=0D diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc index 6d69cc6cb5..d246a96a1b 100644 --- a/OvmfPkg/OvmfPkgIa32X64.dsc +++ b/OvmfPkg/OvmfPkgIa32X64.dsc @@ -163,6 +163,7 @@ UefiUsbLib|MdePkg/Library/UefiUsbLib/UefiUsbLib.inf=0D SerializeVariablesLib|OvmfPkg/Library/SerializeVariablesLib/SerializeVar= iablesLib.inf=0D QemuFwCfgLib|OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgDxeLib.inf=0D + BhyveFwCtlLib|BhyvePkg/Library/BhyveFwCtlLibNull/BhyveFwCtlLibNull.inf=0D VirtioLib|OvmfPkg/Library/VirtioLib/VirtioLib.inf=0D LoadLinuxLib|OvmfPkg/Library/LoadLinuxLib/LoadLinuxLib.inf=0D MemEncryptSevLib|OvmfPkg/Library/BaseMemEncryptSevLib/BaseMemEncryptSevL= ib.inf=0D diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc index 5ad4f461ce..ff030ee502 100644 --- a/OvmfPkg/OvmfPkgX64.dsc +++ b/OvmfPkg/OvmfPkgX64.dsc @@ -163,6 +163,7 @@ UefiUsbLib|MdePkg/Library/UefiUsbLib/UefiUsbLib.inf=0D SerializeVariablesLib|OvmfPkg/Library/SerializeVariablesLib/SerializeVar= iablesLib.inf=0D QemuFwCfgLib|OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgDxeLib.inf=0D + BhyveFwCtlLib|BhyvePkg/Library/BhyveFwCtlLibNull/BhyveFwCtlLibNull.inf=0D VirtioLib|OvmfPkg/Library/VirtioLib/VirtioLib.inf=0D LoadLinuxLib|OvmfPkg/Library/LoadLinuxLib/LoadLinuxLib.inf=0D MemEncryptSevLib|OvmfPkg/Library/BaseMemEncryptSevLib/BaseMemEncryptSevL= ib.inf=0D diff --git a/OvmfPkg/OvmfXen.dsc b/OvmfPkg/OvmfXen.dsc index 47ee8db8b8..b12abaeb0d 100644 --- a/OvmfPkg/OvmfXen.dsc +++ b/OvmfPkg/OvmfXen.dsc @@ -155,6 +155,7 @@ UefiUsbLib|MdePkg/Library/UefiUsbLib/UefiUsbLib.inf=0D SerializeVariablesLib|OvmfPkg/Library/SerializeVariablesLib/SerializeVar= iablesLib.inf=0D QemuFwCfgLib|OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgDxeLib.inf=0D + BhyveFwCtlLib|BhyvePkg/Library/BhyveFwCtlLibNull/BhyveFwCtlLibNull.inf=0D QemuLoadImageLib|OvmfPkg/Library/GenericQemuLoadImageLib/GenericQemuLoad= ImageLib.inf=0D MemEncryptSevLib|OvmfPkg/Library/BaseMemEncryptSevLib/BaseMemEncryptSevL= ib.inf=0D LockBoxLib|OvmfPkg/Library/LockBoxLib/LockBoxBaseLib.inf=0D --=20 2.26.1