From nobody Tue May 14 07:06:35 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+81874+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+81874+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1634116654; cv=none; d=zohomail.com; s=zohoarc; b=MYGIZyrjT3zNKV1vPI58q3XE+cVxUDSvTJJckTuQdA2+MhTEDzDhVUskBTANI+sGGP3rbDoVREa8xiCSj/5rpXIpkwCQr0ZjBUik+AHcL+DB+vvUiethsdjP8zuYrjKcXI6feZ1kbMEzyjghvFM40VmUsxixa6mVkZFFpPfJXFI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1634116654; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Sender:Subject; bh=TnB/wVxrR8BzyF6ZAzXbXnXAqNMMbe1g7TZjb6m7DZU=; b=jpWVz9Ht/paR7fyV8b33BUrb9dE7iKP83qzvtnI+Q4RPTCkdK8Az0f3KHzLXOdvifyDkx7XP5cBWrgXIB0QdEQXLd/C0+Ff4lxNnKPeycJmsBmE2P/2Ui7mdqfy0ykXaW3wZXXDY/cal2KFBiQtUv1vBvfym6Rlqcaf6An2LbWU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+81874+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1634116654564689.4059857155024; Wed, 13 Oct 2021 02:17:34 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id dGMAYY1788612xnppxLhanC4; Wed, 13 Oct 2021 02:17:34 -0700 X-Received: from netsrv01.beckhoff.com (netsrv01.beckhoff.com [62.159.14.10]) by mx.groups.io with SMTP id smtpd.web09.5712.1634116653020652479 for ; Wed, 13 Oct 2021 02:17:33 -0700 X-Received: from 172.17.5.170 by netsrv01.beckhoff.com (Tls12, Aes256, Sha384, DiffieHellmanEllipticKey256); Wed, 13 Oct 2021 09:17:31 GMT X-Received: from CorvinK-NB03.beckhoff.com (172.17.62.127) by ex04.beckhoff.com (172.17.5.170) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2375.7; Wed, 13 Oct 2021 11:17:28 +0200 From: =?UTF-8?B?Q29ydmluIEvDtmhuZQ==?= To: CC: =?UTF-8?q?Corvin=20K=C3=B6hne?= , Ard Biesheuvel , Jiewen Yao , Jordan Justen , Gerd Hoffmann , Rebecca Cran , Peter Grehan , , Michael D Kinney , Liming Gao , Zhiguang Liu Subject: [edk2-devel] [PATCH] OvmfPkg/BhyveBhfPkg: install bhyve's ACPI tables Date: Wed, 13 Oct 2021 11:16:57 +0200 Message-ID: <20211013091657.202-1-c.koehne@beckhoff.com> MIME-Version: 1.0 X-Originating-IP: [172.17.62.127] X-ClientProxiedBy: ex01.beckhoff.com (172.17.2.168) To ex04.beckhoff.com (172.17.5.170) X-OLX-Disclaimer: EX04.BECKHOFF.COM Precedence: Bulk List-Unsubscribe: List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,c.koehne@beckhoff.com X-Gm-Message-State: Ytpk2Amr5Kd9jdKoMwNkuzp7x1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1634116654; bh=1Xxa/QGgnVIo0Sbm1aqKgDF7lQcrbH1tbwK7qRUqC2k=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=vt1ieJqwSnBowC1XKXm9qmAz7+FoVUGGOYRTQhR8C6cGsydSzoU/Cj+LE3vN5UqhY8f 4SBuRITz+Ncqo2wFT32f0kpvbSqpdABIyMU8sGivlnZAbm8skPN6hpQFtEl35jpgSJVWD NC4QmHRynO3W2iU+IXGhZFS4/59kyNM7P5I= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1634116655091100001 Content-Type: text/plain; charset="utf-8" =EF=BB=BFIt's much easier to create configuration dependend ACPI tables for bhyve than for OVMF. For this reason, don't use the statically created ACPI tables provided by OVMF. Instead use the dynamically created ACPI tables of bhyve. If bhyve provides no ACPI tables or we are unable to detect those, fall back to OVMF tables. Implementation is similar to . Signed-off-by: Corvin K=C3=B6hne CC: Ard Biesheuvel CC: Jiewen Yao CC: Jordan Justen CC: Gerd Hoffmann CC: Rebecca Cran CC: Peter Grehan CC: devel@edk2.groups.io CC: Michael D Kinney CC: Liming Gao CC: Zhiguang Liu Acked-by: Gerd Hoffmann Acked-by: Jiewen Yao Acked-by: Peter Grehan --- MdePkg/Include/Uefi/UefiBaseType.h | 2 + OvmfPkg/Bhyve/AcpiPlatformDxe/AcpiPlatform.c | 10 ++ OvmfPkg/Bhyve/AcpiPlatformDxe/AcpiPlatform.h | 6 + OvmfPkg/Bhyve/AcpiPlatformDxe/Bhyve.c | 241 +++++++++++++++++++++++= ++++ 4 files changed, 259 insertions(+) diff --git a/MdePkg/Include/Uefi/UefiBaseType.h b/MdePkg/Include/Uefi/UefiB= aseType.h index 45e2aa63bb..084c52cd0f 100644 --- a/MdePkg/Include/Uefi/UefiBaseType.h +++ b/MdePkg/Include/Uefi/UefiBaseType.h @@ -53,6 +53,8 @@ typedef UINT64 EFI_PHYSICAL_ADDRESS; /// typedef UINT64 EFI_VIRTUAL_ADDRESS; =20 +#define NUMERIC_VALUE_AS_POINTER(Type, Value) ((Type *) ((UINTN)(Value))) + /// /// EFI Time Abstraction: /// Year: 1900 - 9999 diff --git a/OvmfPkg/Bhyve/AcpiPlatformDxe/AcpiPlatform.c b/OvmfPkg/Bhyve/A= cpiPlatformDxe/AcpiPlatform.c index 9ccdb4d91c..e7de6937da 100644 --- a/OvmfPkg/Bhyve/AcpiPlatformDxe/AcpiPlatform.c +++ b/OvmfPkg/Bhyve/AcpiPlatformDxe/AcpiPlatform.c @@ -245,6 +245,16 @@ InstallAcpiTables ( { EFI_STATUS Status; =20 + Status =3D InstallBhyveTables (AcpiTable); + if (!EFI_ERROR (Status)) { + return EFI_SUCCESS; + } + if (Status !=3D EFI_NOT_FOUND) { + DEBUG ((DEBUG_INFO, "%a: unable to install bhyve's ACPI tables (%r)\n", + __FUNCTION__, Status)); + return Status; + } + Status =3D InstallOvmfFvTables (AcpiTable); =20 return Status; diff --git a/OvmfPkg/Bhyve/AcpiPlatformDxe/AcpiPlatform.h b/OvmfPkg/Bhyve/A= cpiPlatformDxe/AcpiPlatform.h index 994ee2c7cd..1a99838e8e 100644 --- a/OvmfPkg/Bhyve/AcpiPlatformDxe/AcpiPlatform.h +++ b/OvmfPkg/Bhyve/AcpiPlatformDxe/AcpiPlatform.h @@ -48,6 +48,12 @@ BhyveInstallAcpiTable( =20 EFI_STATUS EFIAPI +InstallBhyveTables ( + IN EFI_ACPI_TABLE_PROTOCOL *AcpiProtocol + ); + +EFI_STATUS +EFIAPI InstallXenTables ( IN EFI_ACPI_TABLE_PROTOCOL *AcpiProtocol ); diff --git a/OvmfPkg/Bhyve/AcpiPlatformDxe/Bhyve.c b/OvmfPkg/Bhyve/AcpiPlat= formDxe/Bhyve.c index 01ee894746..2f5dd87995 100644 --- a/OvmfPkg/Bhyve/AcpiPlatformDxe/Bhyve.c +++ b/OvmfPkg/Bhyve/AcpiPlatformDxe/Bhyve.c @@ -12,6 +12,19 @@ #include #include =20 +#define BHYVE_ACPI_PHYSICAL_ADDRESS ((UINTN)0x000F2400) +#define BHYVE_BIOS_PHYSICAL_END ((UINTN)0x00100000) + +#pragma pack (1) + +typedef struct +{ + EFI_ACPI_DESCRIPTION_HEADER Header; + UINT64 Tables[0]; +} EFI_ACPI_2_0_EXTENDED_SYSTEM_DESCRIPTION_TABLE; + +#pragma pack () + STATIC EFI_STATUS EFIAPI @@ -130,3 +143,231 @@ BhyveInstallAcpiTable ( TableKey ); } + +/** + Get the address of bhyve's ACPI Root System Description Pointer (RSDP). + + @param RsdpPtr Return pointer to RSDP. + + @return EFI_SUCCESS Bhyve's RSDP successfully found. + @return EFI_NOT_FOUND Couldn't find bhyve's RSDP. + @return EFI_UNSUPPORTED Revision is lower than 2. + @return EFI_PROTOCOL_ERROR Invalid RSDP found. + +**/ +EFI_STATUS +EFIAPI +BhyveGetAcpiRsdp ( + OUT EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER **RsdpPtr + ) +{ + UINTN RsdpAddress; + EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER *Rsdp; + + if (RsdpPtr =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + // + // Detect the RSDP + // + for (RsdpAddress =3D BHYVE_ACPI_PHYSICAL_ADDRESS; + RsdpAddress < BHYVE_BIOS_PHYSICAL_END; + RsdpAddress +=3D 0x10) { + Rsdp =3D NUMERIC_VALUE_AS_POINTER ( + EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER, + RsdpAddress + ); + if (Rsdp->Signature !=3D EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER_= SIGNATURE) { + continue; + } + if (Rsdp->Revision < 2) { + DEBUG ((DEBUG_INFO, "%a: unsupported RSDP found\n", __FUNCTION__)); + return EFI_UNSUPPORTED; + } + + // + // For ACPI 1.0/2.0/3.0 the checksum of first 20 bytes should be 0. + // For ACPI 2.0/3.0 the checksum of the entire table should be 0. + // + UINT8 Sum =3D CalculateCheckSum8 ( + (CONST UINT8 *)Rsdp, + sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER) + ); + if (Sum !=3D 0) { + DEBUG ((DEBUG_INFO, "%a: RSDP header checksum not valid: 0x%02x\n", + __FUNCTION__, Sum)); + return EFI_PROTOCOL_ERROR; + } + Sum =3D CalculateCheckSum8 ( + (CONST UINT8 *)Rsdp, + sizeof (EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER) + ); + if (Sum !=3D 0) { + DEBUG ((DEBUG_INFO, "%a: RSDP table checksum not valid: 0x%02x\n", + __FUNCTION__, Sum)); + return EFI_PROTOCOL_ERROR; + } + + // + // RSDP was found and is valid + // + *RsdpPtr =3D Rsdp; + + return EFI_SUCCESS; + } + + DEBUG ((DEBUG_INFO, "%a: RSDP not found\n", __FUNCTION__)); + return EFI_NOT_FOUND; +} + +/** + Get bhyve's ACPI tables from the RSDP. And install bhyve's ACPI tables + into the RSDT/XSDT using InstallAcpiTable. + + @param AcpiProtocol Protocol instance pointer. + + @return EFI_SUCCESS All tables were successfully inserted. + @return EFI_UNSUPPORTED Bhyve's ACPI tables doesn't include a XSDT. + @return EFI_PROTOCOL_ERROR Invalid XSDT found. + + @return Error codes propagated from underlying funct= ions. +**/ +EFI_STATUS +EFIAPI +InstallBhyveTables ( + IN EFI_ACPI_TABLE_PROTOCOL *AcpiProtocol + ) +{ + EFI_STATUS Status; + UINTN TableHandle; + EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER *Rsdp; + EFI_ACPI_2_0_FIRMWARE_ACPI_CONTROL_STRUCTURE *Facs; + EFI_ACPI_DESCRIPTION_HEADER *Dsdt; + + Rsdp =3D NULL; + Facs =3D NULL; + Dsdt =3D NULL; + + // + // Try to find bhyve ACPI tables + // + Status =3D BhyveGetAcpiRsdp (&Rsdp); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_INFO, "%a: can't get RSDP (%r)\n", __FUNCTION__, Status)= ); + return Status; + } + + // + // Bhyve should always provide a XSDT + // + EFI_ACPI_2_0_EXTENDED_SYSTEM_DESCRIPTION_TABLE * CONST Xsdt =3D + NUMERIC_VALUE_AS_POINTER ( + EFI_ACPI_2_0_EXTENDED_SYSTEM_DESCRIPTION_TABLE, + Rsdp->XsdtAddress + ); + if (Xsdt =3D=3D NULL) { + DEBUG ((DEBUG_INFO, "%a: XSDT not found\n", __FUNCTION__)); + return EFI_UNSUPPORTED; + } + if (Xsdt->Header.Length < sizeof (EFI_ACPI_DESCRIPTION_HEADER)) { + DEBUG ((DEBUG_INFO, "%a: invalid XSDT length\n", __FUNCTION__)); + return EFI_PROTOCOL_ERROR; + } + + // + // Install ACPI tables + // + CONST UINTN NumberOfTableEntries =3D + (Xsdt->Header.Length - sizeof (Xsdt->Header)) / sizeof (UINT64); + for (UINTN Index =3D 0; Index < NumberOfTableEntries; Index++) { + EFI_ACPI_DESCRIPTION_HEADER * CONST CurrentTable =3D + NUMERIC_VALUE_AS_POINTER ( + EFI_ACPI_DESCRIPTION_HEADER, + Xsdt->Tables[Index] + ); + Status =3D AcpiProtocol->InstallAcpiTable ( + AcpiProtocol, + CurrentTable, + CurrentTable->Length, + &TableHandle + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_INFO, "%a: failed to install ACPI table %c%c%c%c (%r)\= n", + __FUNCTION__, + NUMERIC_VALUE_AS_POINTER (UINT8, CurrentTable->Signature)[0], + NUMERIC_VALUE_AS_POINTER (UINT8, CurrentTable->Signature)[1], + NUMERIC_VALUE_AS_POINTER (UINT8, CurrentTable->Signature)[2], + NUMERIC_VALUE_AS_POINTER (UINT8, CurrentTable->Signature)[3], + Status)); + return Status; + } + + if (CurrentTable->Signature =3D=3D EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION= _TABLE_SIGNATURE) { + EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE * CONST Fadt =3D + (EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE * CONST)CurrentTable; + if (Fadt->XFirmwareCtrl) { + Facs =3D NUMERIC_VALUE_AS_POINTER ( + EFI_ACPI_2_0_FIRMWARE_ACPI_CONTROL_STRUCTURE, + Fadt->XFirmwareCtrl + ); + } else { + Facs =3D NUMERIC_VALUE_AS_POINTER ( + EFI_ACPI_2_0_FIRMWARE_ACPI_CONTROL_STRUCTURE, + Fadt->FirmwareCtrl + ); + } + if (Fadt->XDsdt) { + Dsdt =3D NUMERIC_VALUE_AS_POINTER ( + EFI_ACPI_DESCRIPTION_HEADER, + Fadt->XDsdt + ); + } else { + Dsdt =3D NUMERIC_VALUE_AS_POINTER ( + EFI_ACPI_DESCRIPTION_HEADER, + Fadt->Dsdt + ); + } + } + } + + // + // Install FACS + // + if (Facs !=3D NULL) { + Status =3D AcpiProtocol->InstallAcpiTable ( + AcpiProtocol, + Facs, + Facs->Length, + &TableHandle + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_INFO, "%a: failed to install FACS (%r)\n", __FUNCTION_= _, + Status)); + return Status; + } + } + + // + // Install DSDT + // If it's not found, something bad happened. Don't continue execution. + // + if (Dsdt =3D=3D NULL) { + DEBUG ((DEBUG_ERROR, "%a: failed to find DSDT\n", __FUNCTION__)); + CpuDeadLoop (); + } + + Status =3D AcpiProtocol->InstallAcpiTable ( + AcpiProtocol, + Dsdt, + Dsdt->Length, + &TableHandle + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_INFO, "%a: failed to install DSDT (%r)\n", __FUNCTION__, + Status)); + return Status; + } + + return EFI_SUCCESS; +} --=20 2.11.0 Beckhoff Automation GmbH & Co. KG | Managing Director: Dipl. Phys. Hans Bec= khoff Registered office: Verl, Germany | Register court: Guetersloh HRA 7075 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#81874): https://edk2.groups.io/g/devel/message/81874 Mute This Topic: https://groups.io/mt/86283809/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-