From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx2.freebsd.org (mx2.freebsd.org [96.47.72.81]) by mx.groups.io with SMTP id smtpd.web10.13332.1683099158133476840 for ; Wed, 03 May 2023 00:32:38 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@freebsd.org header.s=dkim header.b=oSRiJWo/; spf=pass (domain: freebsd.org, ip: 96.47.72.81, mailfrom: corvink@freebsd.org) Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits)) (Client CN "mx1.freebsd.org", Issuer "R3" (verified OK)) by mx2.freebsd.org (Postfix) with ESMTPS id 4QB7vT03qwz45lt; Wed, 3 May 2023 07:32:37 +0000 (UTC) (envelope-from corvink@FreeBSD.org) Received: from smtp.freebsd.org (smtp.freebsd.org [96.47.72.83]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "smtp.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4QB7vS65PBz4XC1; Wed, 3 May 2023 07:32:36 +0000 (UTC) (envelope-from corvink@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1683099156; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=GM4h/oG8Oa+XZN+6A/La7kMALVmsldorcGYjg0y2Z2c=; b=oSRiJWo/+KQY7lACrmFv4JEL3tc0xB9U3vHILEtPMq99IHg5xTUOH6+yByNhTZp5yZlT4z L5JSWREUThPgPwvjrkP2xttmELWqoDs7zlVyWHcR7E+aYhmB9URDnJT8MrkgscB2T/kaiI /tvTGikfhD6qwlA3vxH6HA2llPphmU2GzSJ3xueW/qerIlrqOl8jPL60rIuYYpt+T9eq3a OiP4ulZqvc36rEX8quD6B8+b8KnEOvw4WCQgswZK7k72KLLBiJ9+vB/4LXjPjCl5khWm05 LcmLG8ASkUo9TxzaOH+bdrJjxkF83RXT8XyjjAtuNLha4m1fDKSJeEGH/RYBUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1683099156; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=GM4h/oG8Oa+XZN+6A/La7kMALVmsldorcGYjg0y2Z2c=; b=KuyU8LYiKuj/ZatEcS4AhVRRqpMxIXhGQja/jyO2csghhGWbMjdppr+5QnqAqltngbyKme +dCuDgRrKuALzZkiR6fWfr/U+FNg0UjlLB6KhL8bqaSuEqvQosgfPQQLpUQivi9qt3qYAV 6yYG9CG6kTVOiNZgZhtPJNWUI5e+H7+VecbakhKJNm0qhiZFbNUcBvr5uPcGm2pzD2hacO fuwXH/U+qRe+Z6ZDbDp1NhxWQjROia/9rZjCx9LzFHmUC6sSNWhi3Ir1CosKgPBqCMLKke WQsP+iLEe+L3pyBmxl8YbYM6tHqeTA1EkuEvOaaTSXoZL71SQltD29B4dyLZwA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1683099156; a=rsa-sha256; cv=none; b=Sdu1Y08RYgeYgNsJXq7feHiprUq5N5ieY3H+InWgKxvVhb8ktHwY1yfaPlv2oobS8Ruxan 7k+kSBfR1V0L6907h/zx7wuSVavpDfVpwlYdjLEPWEMoUyjMMx1G+F05c1yrHvXRcG4kPK 8/nCsmhmIwIsKs/uiXSLCJGr7hNICFvKw3r97zwk5P6lR+2UuvR3FxlOnpSk5wYsjJBTY7 27bx8iGxvt+vD7lmIYqthETp3zi2VGwlt0BvHyz21k8tuV8QProYU4BvmMCmshnm8GblaU u7l7Meb2Y40gV8D670T6bndupQYZETkEt8NtehFH4Qw8zF0X5hmV/KDEnk/BiQ== Received: from corvink-nb.beckhoff.com (unknown [IPv6:2001:9e8:da7b:3000:a559:ee9a:32a4:e1d9]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) (Authenticated sender: corvink) by smtp.freebsd.org (Postfix) with ESMTPSA id 4QB7vR5SclzYJV; Wed, 3 May 2023 07:32:35 +0000 (UTC) (envelope-from corvink@FreeBSD.org) From: =?UTF-8?B?Q29ydmluIEvDtmhuZQ==?= To: devel@edk2.groups.io Cc: =?UTF-8?q?Corvin=20K=C3=B6hne?= , Ard Biesheuvel , Jiewen Yao , Jordan Justen , Gerd Hoffmann , Anthony Perard , Julien Grall Subject: [PATCH v3 1/3] OvmfPkg/Xen: export search of RSDP into a library function Date: Wed, 3 May 2023 09:32:03 +0200 Message-Id: <20230503073205.306090-1-corvink@FreeBSD.org> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Xen and bhyve are placing ACPI tables into system memory. So, they can share the same code. Therefore, create a new library which searches and installs ACPI tables from system memory. Signed-off-by: Corvin K=C3=B6hne Cc: Ard Biesheuvel Cc: Jiewen Yao Cc: Jordan Justen Cc: Gerd Hoffmann Cc: Anthony Perard Cc: Julien Grall --- OvmfPkg/OvmfPkg.dec | 4 + OvmfPkg/OvmfXen.dsc | 1 + .../AcpiPlatformLib/DxeAcpiPlatformLib.inf | 26 ++++++ .../XenAcpiPlatformDxe/XenAcpiPlatformDxe.inf | 1 + OvmfPkg/Include/Library/AcpiPlatformLib.h | 25 +++++ .../AcpiPlatformLib/DxeAcpiPlatformLib.c | 90 ++++++++++++++++++ OvmfPkg/XenAcpiPlatformDxe/Xen.c | 93 ++----------------- 7 files changed, 153 insertions(+), 87 deletions(-) create mode 100644 OvmfPkg/Library/AcpiPlatformLib/DxeAcpiPlatformLib.in= f create mode 100644 OvmfPkg/Include/Library/AcpiPlatformLib.h create mode 100644 OvmfPkg/Library/AcpiPlatformLib/DxeAcpiPlatformLib.c diff --git a/OvmfPkg/OvmfPkg.dec b/OvmfPkg/OvmfPkg.dec index 749fbd3b6bf4..8a71b4aaa266 100644 --- a/OvmfPkg/OvmfPkg.dec +++ b/OvmfPkg/OvmfPkg.dec @@ -20,6 +20,10 @@ [Includes] Csm/Include =20 [LibraryClasses] + ## @libraryclass Search and install ACPI tables. + # + AcpiPlatformLib|Include/Library/AcpiPlatformLib.h + ## @libraryclass Access bhyve's firmware control interface. BhyveFwCtlLib|Include/Library/BhyveFwCtlLib.h =20 diff --git a/OvmfPkg/OvmfXen.dsc b/OvmfPkg/OvmfXen.dsc index 8bfc16c2d3d6..0d91e04e4116 100644 --- a/OvmfPkg/OvmfXen.dsc +++ b/OvmfPkg/OvmfXen.dsc @@ -319,6 +319,7 @@ [LibraryClasses.common.UEFI_DRIVER] PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf =20 [LibraryClasses.common.DXE_DRIVER] + AcpiPlatformLib|OvmfPkg/Library/AcpiPlatformLib/DxeAcpiPlatformLib.inf PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf diff --git a/OvmfPkg/Library/AcpiPlatformLib/DxeAcpiPlatformLib.inf b/Ovm= fPkg/Library/AcpiPlatformLib/DxeAcpiPlatformLib.inf new file mode 100644 index 000000000000..dfe0e5623d32 --- /dev/null +++ b/OvmfPkg/Library/AcpiPlatformLib/DxeAcpiPlatformLib.inf @@ -0,0 +1,26 @@ +## @file +# ACPI Platform Library Instance. +# +# Copyright (C) 2023, Corvin K=C3=B6hne +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D DxeAcpiPlatformLib + FILE_GUID =3D 578F441A-4A4C-4D24-B9BE-F783152B46F6 + MODULE_TYPE =3D DXE_DRIVER + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D AcpiPlatformLib + +[Sources] + DxeAcpiPlatformLib.c + +[Packages] + MdePkg/MdePkg.dec + OvmfPkg/OvmfPkg.dec + +[LibraryClasses] + BaseLib + DebugLib diff --git a/OvmfPkg/XenAcpiPlatformDxe/XenAcpiPlatformDxe.inf b/OvmfPkg/= XenAcpiPlatformDxe/XenAcpiPlatformDxe.inf index d3a6353a50a6..65374569ddc2 100644 --- a/OvmfPkg/XenAcpiPlatformDxe/XenAcpiPlatformDxe.inf +++ b/OvmfPkg/XenAcpiPlatformDxe/XenAcpiPlatformDxe.inf @@ -32,6 +32,7 @@ [Packages] OvmfPkg/OvmfPkg.dec =20 [LibraryClasses] + AcpiPlatformLib BaseLib DebugLib UefiBootServicesTableLib diff --git a/OvmfPkg/Include/Library/AcpiPlatformLib.h b/OvmfPkg/Include/= Library/AcpiPlatformLib.h new file mode 100644 index 000000000000..431ab1c54f5b --- /dev/null +++ b/OvmfPkg/Include/Library/AcpiPlatformLib.h @@ -0,0 +1,25 @@ +/** @file + Copyright (c) 2023, Corvin K=C3=B6hne + + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +/** + Searches and returns the address of the ACPI Root System Description P= ointer (RSDP) in system memory. + + @param StartAddress Start address of search range. + @param EndAddress End address of search range. + @param RsdpPtr Return pointer to RSDP. + + @retval EFI_SUCCESS Bhyve's RSDP successfully found. + @retval EFI_NOT_FOUND Couldn't find bhyve's RSDP. + @retval EFI_UNSUPPORTED Revision is lower than 2. + @retval EFI_PROTOCOL_ERROR Invalid RSDP found. +**/ +EFI_STATUS +EFIAPI +GetAcpiRsdpFromMemory ( + IN UINT64 StartAddress, + IN UINT64 EndAddress, + OUT EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER **RsdpPtr + ); diff --git a/OvmfPkg/Library/AcpiPlatformLib/DxeAcpiPlatformLib.c b/OvmfP= kg/Library/AcpiPlatformLib/DxeAcpiPlatformLib.c new file mode 100644 index 000000000000..80f9b5367b6d --- /dev/null +++ b/OvmfPkg/Library/AcpiPlatformLib/DxeAcpiPlatformLib.c @@ -0,0 +1,90 @@ +/** @file + Copyright (c) 2023, Corvin K=C3=B6hne + + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#include +#include +#include + +EFI_STATUS +EFIAPI +GetAcpiRsdpFromMemory ( + IN UINT64 StartAddress, + IN UINT64 EndAddress, + OUT EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER **RsdpPtr + ) +{ + UINTN RsdpAddress; + EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER *Rsdp; + UINT8 Sum; + + if (RsdpPtr =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + // + // Detect the RSDP + // + for (RsdpAddress =3D StartAddress; RsdpAddress < EndAddress; + 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_WARN, "%a: unsupported RSDP found\n", __func__)); + 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. + // + Sum =3D CalculateCheckSum8 ( + (CONST UINT8 *)Rsdp, + sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER) + ); + if (Sum !=3D 0) { + DEBUG (( + DEBUG_ERROR, + "%a: RSDP header checksum not valid: 0x%02x\n", + __func__, + 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_ERROR, + "%a: RSDP table checksum not valid: 0x%02x\n", + __func__, + Sum + )); + return EFI_PROTOCOL_ERROR; + } + + // + // RSDP was found and is valid + // + *RsdpPtr =3D Rsdp; + + return EFI_SUCCESS; + } + + DEBUG ((DEBUG_WARN, "%a: RSDP not found\n", __func__)); + return EFI_NOT_FOUND; +} diff --git a/OvmfPkg/XenAcpiPlatformDxe/Xen.c b/OvmfPkg/XenAcpiPlatformDx= e/Xen.c index a80a24628c08..28fa1d1e0e03 100644 --- a/OvmfPkg/XenAcpiPlatformDxe/Xen.c +++ b/OvmfPkg/XenAcpiPlatformDxe/Xen.c @@ -9,6 +9,7 @@ =20 **/ =20 +#include #include // CpuDeadLoop() #include // DEBUG() #include // XenGetInfoHOB() @@ -20,92 +21,6 @@ =20 EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER *XenAcpiRsdpStructurePtr =3D= NULL; =20 -/** - Get the address of Xen ACPI Root System Description Pointer (RSDP) - structure. - - @param RsdpStructurePtr Return pointer to RSDP structure - - @return EFI_SUCCESS Find Xen RSDP structure successfully. - @return EFI_NOT_FOUND Don't find Xen RSDP structure. - @return EFI_ABORTED Find Xen RSDP structure, but it's not integ= rated. - -**/ -EFI_STATUS -EFIAPI -GetXenAcpiRsdp ( - OUT EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER **RsdpPtr - ) -{ - EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER *RsdpStructurePtr; - UINT8 *XenAcpiPtr; - UINT8 Sum; - EFI_XEN_INFO *XenInfo; - - // - // Detect the RSDP structure - // - - // - // First look for PVH one - // - XenInfo =3D XenGetInfoHOB (); - ASSERT (XenInfo !=3D NULL); - if (XenInfo->RsdpPvh !=3D NULL) { - DEBUG (( - DEBUG_INFO, - "%a: Use ACPI RSDP table at 0x%p\n", - gEfiCallerBaseName, - XenInfo->RsdpPvh - )); - *RsdpPtr =3D XenInfo->RsdpPvh; - return EFI_SUCCESS; - } - - // - // Otherwise, look for the HVM one - // - for (XenAcpiPtr =3D (UINT8 *)(UINTN)XEN_ACPI_PHYSICAL_ADDRESS; - XenAcpiPtr < (UINT8 *)(UINTN)XEN_BIOS_PHYSICAL_END; - XenAcpiPtr +=3D 0x10) - { - RsdpStructurePtr =3D (EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER *= ) - (UINTN)XenAcpiPtr; - - if (!AsciiStrnCmp ((CHAR8 *)&RsdpStructurePtr->Signature, "RSD PTR "= , 8)) { - // - // RSDP ACPI 1.0 checksum for 1.0/2.0/3.0 table. - // This is only the first 20 bytes of the structure - // - Sum =3D CalculateSum8 ( - (CONST UINT8 *)RsdpStructurePtr, - sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER) - ); - if (Sum !=3D 0) { - return EFI_ABORTED; - } - - if (RsdpStructurePtr->Revision >=3D 2) { - // - // RSDP ACPI 2.0/3.0 checksum, this is the entire table - // - Sum =3D CalculateSum8 ( - (CONST UINT8 *)RsdpStructurePtr, - sizeof (EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER) - ); - if (Sum !=3D 0) { - return EFI_ABORTED; - } - } - - *RsdpPtr =3D RsdpStructurePtr; - return EFI_SUCCESS; - } - } - - return EFI_NOT_FOUND; -} - /** Get Xen Acpi tables from the RSDP structure. And installs Xen ACPI tab= les into the RSDT/XSDT using InstallAcpiTable. Some signature of the insta= lled @@ -154,7 +69,11 @@ InstallXenTables ( // // Try to find Xen ACPI tables // - Status =3D GetXenAcpiRsdp (&XenAcpiRsdpStructurePtr); + Status =3D GetAcpiRsdpFromMemory ( + XEN_ACPI_PHYSICAL_ADDRESS, + XEN_BIOS_PHYSICAL_END, + &XenAcpiRsdpStructurePtr + ); if (EFI_ERROR (Status)) { return Status; } --=20 2.40.1