From nobody Mon Jun 12 13:18:45 2023 X-Original-To: virtualization@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Qfss04fHkz4cBhk for ; Mon, 12 Jun 2023 13:26:12 +0000 (UTC) (envelope-from corvink@FreeBSD.org) Received: from smtp.freebsd.org (smtp.freebsd.org [IPv6:2610:1c1:1:606c::24b:4]) (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 4Qfss03vCBz43WZ; Mon, 12 Jun 2023 13:26:12 +0000 (UTC) (envelope-from corvink@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1686576372; 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: in-reply-to:in-reply-to:references:references; bh=y4/ReiOKLwsaJngnpP5SodwYgdM2o/jmdJm13HHgTRk=; b=jFMZwSsFp67iYFjGmueS9FYIEN6UibxmppqEVNvkSNwo6ijBa5MZoTt9auYpRMW/Sso+10 xxzjtu2QYTm0vg6Qn2DUJvcWThISOimUnMdVucBY38VOt1HOcsuoHfIl4PAoaWWIZF16bI l3rAD25nKxknNRFhRpuwHMgLuozHbCSFy9LzJY6Z5XdGGL4yxdbagYid/y+2LJ/o2S44CH NEAjjMwR2s5afsuBjNWoo33qmHw6rrE2KUmfUpD8vAdCou1b/sHLtaL4JyT2v4mW/VcDKA /cGk4mJCJueNbPBL22G8vML8C+OBsupqMMRUpQsMn9eDSCdM6WemsbQF7vvWWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1686576372; 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: in-reply-to:in-reply-to:references:references; bh=y4/ReiOKLwsaJngnpP5SodwYgdM2o/jmdJm13HHgTRk=; b=XhsuxRoWwHRRs6Y/wO/F++CdfrNarm1979sDLobknlv5tno9XL+J/ELzzFCW6WNcDAiNOD wbfUBigfkArab2aoOJAQCpQvrp9qH01Bjd6PZKnSSYXSFp4LVj+NiJmqDln7ql7h1cDzuv LnOuz9sIEklsiwh3QmhghvLi4tDGYffRtTaNs4QaUh1JsWOEfQJNSgV+lCobOm10utH32K WF3M9KVcL34iwxDpqSkiWI6QCCSFK/W9mVdCJ/f2EHqYhCHnfijAXO6esICFjHRjL74rnl vYYjKRvpJGaIKd3+o1cVibPAa6J8MNNDlOoH6WCpnisN/TA/69z+KiLImTu/Og== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1686576372; a=rsa-sha256; cv=none; b=wN1Bs9dk7DxzIODGnzV6yWrHOyejp8lCGdb8lpDIZXGaJh+bXIdsrTSYPADkoj8j7t9847 hVqt3JBQ6WmO5SZ+jPQrx/kuVlDg748vPuo/NUJIvUWFaCcoumCzn/SZt9teUBRpjFYsqh nqWu1UMQrjenJwWjotorSmZ+NAhTcaON0K0kycx/xrhcNd+hXyGULaMecB4cderTywvtQX WiStP8laDpjYM+FaGqdTAG9sbJWQnBomgJoo7xij+VGh16wtWBlYywZYPUhqEdJFOZHCvW 0lLkZa3VRJ/LLktYWo2XPMOKhO9J13q+aciNOpjoHuyAkVgRflR9bn416xEaBQ== Received: from corvink-nb.beckhoff.com (unknown [195.226.174.194]) (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 4Qfsrz704VzPPd; Mon, 12 Jun 2023 13:26:11 +0000 (UTC) (envelope-from corvink@FreeBSD.org) From: =?UTF-8?q?Corvin=20K=C3=B6hne?= To: virtualization@freebsd.org Cc: =?UTF-8?q?Corvin=20K=C3=B6hne?= Subject: [PATCH 1/5] OvmfPkg: move PciEncoding into AcpiPlatformLib Date: Mon, 12 Jun 2023 15:18:45 +0200 Message-ID: <20230612132558.349152-2-corvink@FreeBSD.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230612132558.349152-1-corvink@FreeBSD.org> References: <20230612132558.349152-1-corvink@FreeBSD.org> List-Id: Discussion List-Archive: https://lists.freebsd.org/archives/freebsd-virtualization List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-virtualization@freebsd.org X-BeenThere: freebsd-virtualization@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-ThisMailContainsUnwantedMimeParts: N Bhyve supports providing ACPI tables by FwCfg. Therefore, InstallQemuFwCfgTables should be moved to AcpiPlatformLib to reuse the code. As first step, move PciEncoding into AcpiPlatformLib. Signed-off-by: Corvin Köhne --- OvmfPkg/OvmfPkgX64.dsc | 1 + OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf | 5 +- .../Bhyve/AcpiPlatformDxe/AcpiPlatformDxe.inf | 1 - .../AcpiPlatformLib/DxeAcpiPlatformLib.inf | 7 + OvmfPkg/AcpiPlatformDxe/AcpiPlatform.h | 18 -- OvmfPkg/Bhyve/AcpiPlatformDxe/AcpiPlatform.h | 17 -- OvmfPkg/Include/Library/AcpiPlatformLib.h | 18 ++ OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpi.c | 1 + OvmfPkg/Bhyve/AcpiPlatformDxe/PciDecoding.c | 232 ------------------ .../AcpiPlatformLib}/PciDecoding.c | 3 +- 10 files changed, 29 insertions(+), 274 deletions(-) delete mode 100644 OvmfPkg/Bhyve/AcpiPlatformDxe/PciDecoding.c rename OvmfPkg/{AcpiPlatformDxe => Library/AcpiPlatformLib}/PciDecoding.c (96%) diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc index e1c0a6fe9ff7..24ac834e0631 100644 --- a/OvmfPkg/OvmfPkgX64.dsc +++ b/OvmfPkg/OvmfPkgX64.dsc @@ -399,6 +399,7 @@ [LibraryClasses.common.UEFI_DRIVER] PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf [LibraryClasses.common.DXE_DRIVER] + AcpiPlatformLib|OvmfPkg/Library/AcpiPlatformLib/DxeAcpiPlatformLib.inf PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf TimerLib|OvmfPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.inf ResetSystemLib|OvmfPkg/Library/ResetSystemLib/DxeResetSystemLib.inf diff --git a/OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf b/OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf index 3fd0483b50eb..b22aad95e081 100644 --- a/OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf +++ b/OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf @@ -26,7 +26,6 @@ [Sources] BootScript.c CloudHvAcpi.c EntryPoint.c - PciDecoding.c QemuFwCfgAcpi.c [Packages] @@ -35,15 +34,13 @@ [Packages] OvmfPkg/OvmfPkg.dec [LibraryClasses] + AcpiPlatformLib BaseLib BaseMemoryLib - DebugLib MemoryAllocationLib OrderedCollectionLib - PcdLib QemuFwCfgLib QemuFwCfgS3Lib - UefiBootServicesTableLib UefiDriverEntryPoint HobLib TpmMeasurementLib diff --git a/OvmfPkg/Bhyve/AcpiPlatformDxe/AcpiPlatformDxe.inf b/OvmfPkg/Bhyve/AcpiPlatformDxe/AcpiPlatformDxe.inf index 75ed8e4a7deb..2e228d815b87 100644 --- a/OvmfPkg/Bhyve/AcpiPlatformDxe/AcpiPlatformDxe.inf +++ b/OvmfPkg/Bhyve/AcpiPlatformDxe/AcpiPlatformDxe.inf @@ -26,7 +26,6 @@ [Sources] AcpiPlatform.h Bhyve.c EntryPoint.c - PciDecoding.c [Packages] MdePkg/MdePkg.dec diff --git a/OvmfPkg/Library/AcpiPlatformLib/DxeAcpiPlatformLib.inf b/OvmfPkg/Library/AcpiPlatformLib/DxeAcpiPlatformLib.inf index dfe0e5623d32..4be501bb2c58 100644 --- a/OvmfPkg/Library/AcpiPlatformLib/DxeAcpiPlatformLib.inf +++ b/OvmfPkg/Library/AcpiPlatformLib/DxeAcpiPlatformLib.inf @@ -16,11 +16,18 @@ [Defines] [Sources] DxeAcpiPlatformLib.c + PciDecoding.c [Packages] + MdeModulePkg/MdeModulePkg.dec MdePkg/MdePkg.dec OvmfPkg/OvmfPkg.dec [LibraryClasses] BaseLib DebugLib + PcdLib + UefiBootServicesTableLib + +[Pcd] + gEfiMdeModulePkgTokenSpaceGuid.PcdPciDisableBusEnumeration diff --git a/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.h b/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.h index 3ec509865863..1328f6d1cba6 100644 --- a/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.h +++ b/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.h @@ -10,12 +10,6 @@ #define ACPI_PLATFORM_H_ #include // EFI_ACPI_TABLE_PROTOCOL -#include // EFI_PCI_IO_PROTOCOL - -typedef struct { - EFI_PCI_IO_PROTOCOL *PciIo; - UINT64 PciAttributes; -} ORIGINAL_ATTRIBUTES; typedef struct S3_CONTEXT S3_CONTEXT; @@ -43,18 +37,6 @@ InstallAcpiTables ( IN EFI_ACPI_TABLE_PROTOCOL *AcpiTable ); -VOID -EnablePciDecoding ( - OUT ORIGINAL_ATTRIBUTES **OriginalAttributes, - OUT UINTN *Count - ); - -VOID -RestorePciDecoding ( - IN ORIGINAL_ATTRIBUTES *OriginalAttributes, - IN UINTN Count - ); - EFI_STATUS AllocateS3Context ( OUT S3_CONTEXT **S3Context, diff --git a/OvmfPkg/Bhyve/AcpiPlatformDxe/AcpiPlatform.h b/OvmfPkg/Bhyve/AcpiPlatformDxe/AcpiPlatform.h index 54d1af073eab..b75292b73546 100644 --- a/OvmfPkg/Bhyve/AcpiPlatformDxe/AcpiPlatform.h +++ b/OvmfPkg/Bhyve/AcpiPlatformDxe/AcpiPlatform.h @@ -21,11 +21,6 @@ #include #include -typedef struct { - EFI_PCI_IO_PROTOCOL *PciIo; - UINT64 PciAttributes; -} ORIGINAL_ATTRIBUTES; - typedef struct S3_CONTEXT S3_CONTEXT; EFI_STATUS @@ -58,16 +53,4 @@ InstallAcpiTables ( IN EFI_ACPI_TABLE_PROTOCOL *AcpiTable ); -VOID -EnablePciDecoding ( - OUT ORIGINAL_ATTRIBUTES **OriginalAttributes, - OUT UINTN *Count - ); - -VOID -RestorePciDecoding ( - IN ORIGINAL_ATTRIBUTES *OriginalAttributes, - IN UINTN Count - ); - #endif /* _ACPI_PLATFORM_H_INCLUDED_ */ diff --git a/OvmfPkg/Include/Library/AcpiPlatformLib.h b/OvmfPkg/Include/Library/AcpiPlatformLib.h index 73a170636032..a1198da296a5 100644 --- a/OvmfPkg/Include/Library/AcpiPlatformLib.h +++ b/OvmfPkg/Include/Library/AcpiPlatformLib.h @@ -5,6 +5,12 @@ **/ #include +#include + +typedef struct { + EFI_PCI_IO_PROTOCOL *PciIo; + UINT64 PciAttributes; +} ORIGINAL_ATTRIBUTES; /** Searches and returns the address of the ACPI Root System Description Pointer (RSDP) in system memory. @@ -47,3 +53,15 @@ InstallAcpiTablesFromRsdp ( IN EFI_ACPI_TABLE_PROTOCOL *AcpiProtocol, IN EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER *Rsdp ); + +VOID +EnablePciDecoding ( + OUT ORIGINAL_ATTRIBUTES **OriginalAttributes, + OUT UINTN *Count + ); + +VOID +RestorePciDecoding ( + IN ORIGINAL_ATTRIBUTES *OriginalAttributes, + IN UINTN Count + ); diff --git a/OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpi.c b/OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpi.c index a073b292b743..3de039d57414 100644 --- a/OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpi.c +++ b/OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpi.c @@ -11,6 +11,7 @@ #include // EFI_ACPI_DESCRIPTION_HEADER #include // QEMU_LOADER_FNAME_SIZE #include +#include #include // AsciiStrCmp() #include // CopyMem() #include // DEBUG() diff --git a/OvmfPkg/Bhyve/AcpiPlatformDxe/PciDecoding.c b/OvmfPkg/Bhyve/AcpiPlatformDxe/PciDecoding.c deleted file mode 100644 index 0dcf3517f1e7..000000000000 --- a/OvmfPkg/Bhyve/AcpiPlatformDxe/PciDecoding.c +++ /dev/null @@ -1,232 +0,0 @@ -/** @file - Temporarily enable IO and MMIO decoding for all PCI devices while QEMU - regenerates the ACPI tables. - - Copyright (C) 2016, Red Hat, Inc. - - SPDX-License-Identifier: BSD-2-Clause-Patent -**/ - -#include - -#include "AcpiPlatform.h" - -/** - Collect all PciIo protocol instances in the system. Save their original - attributes, and enable IO and MMIO decoding for each. - - This is a best effort function; it doesn't return status codes. Its - caller is supposed to proceed even if this function fails. - - @param[out] OriginalAttributes On output, a dynamically allocated array of - ORIGINAL_ATTRIBUTES elements. The array lists - the PciIo protocol instances found in the - system at the time of the call, plus the - original PCI attributes for each. - - Before returning, the function enables IO and - MMIO decoding for each PciIo instance it - finds. - - On error, or when no such instances are - found, OriginalAttributes is set to NULL. - - @param[out] Count On output, the number of elements in - OriginalAttributes. On error it is set to - zero. -**/ -VOID -EnablePciDecoding ( - OUT ORIGINAL_ATTRIBUTES **OriginalAttributes, - OUT UINTN *Count - ) -{ - EFI_STATUS Status; - UINTN NoHandles; - EFI_HANDLE *Handles; - ORIGINAL_ATTRIBUTES *OrigAttrs; - UINTN Idx; - - *OriginalAttributes = NULL; - *Count = 0; - - if (PcdGetBool (PcdPciDisableBusEnumeration)) { - // - // The platform downloads ACPI tables from QEMU in general, but there are - // no root bridges in this execution. We're done. - // - return; - } - - Status = gBS->LocateHandleBuffer ( - ByProtocol, - &gEfiPciIoProtocolGuid, - NULL /* SearchKey */, - &NoHandles, - &Handles - ); - if (Status == EFI_NOT_FOUND) { - // - // No PCI devices were found on either of the root bridges. We're done. - // - return; - } - - if (EFI_ERROR (Status)) { - DEBUG (( - DEBUG_WARN, - "%a: LocateHandleBuffer(): %r\n", - __func__, - Status - )); - return; - } - - OrigAttrs = AllocatePool (NoHandles * sizeof *OrigAttrs); - if (OrigAttrs == NULL) { - DEBUG (( - DEBUG_WARN, - "%a: AllocatePool(): out of resources\n", - __func__ - )); - goto FreeHandles; - } - - for (Idx = 0; Idx < NoHandles; ++Idx) { - EFI_PCI_IO_PROTOCOL *PciIo; - UINT64 Attributes; - - // - // Look up PciIo on the handle and stash it - // - Status = gBS->HandleProtocol ( - Handles[Idx], - &gEfiPciIoProtocolGuid, - (VOID **)&PciIo - ); - ASSERT_EFI_ERROR (Status); - OrigAttrs[Idx].PciIo = PciIo; - - // - // Stash the current attributes - // - Status = PciIo->Attributes ( - PciIo, - EfiPciIoAttributeOperationGet, - 0, - &OrigAttrs[Idx].PciAttributes - ); - if (EFI_ERROR (Status)) { - DEBUG (( - DEBUG_WARN, - "%a: EfiPciIoAttributeOperationGet: %r\n", - __func__, - Status - )); - goto RestoreAttributes; - } - - // - // Retrieve supported attributes - // - Status = PciIo->Attributes ( - PciIo, - EfiPciIoAttributeOperationSupported, - 0, - &Attributes - ); - if (EFI_ERROR (Status)) { - DEBUG (( - DEBUG_WARN, - "%a: EfiPciIoAttributeOperationSupported: %r\n", - __func__, - Status - )); - goto RestoreAttributes; - } - - // - // Enable IO and MMIO decoding - // - Attributes &= EFI_PCI_IO_ATTRIBUTE_IO | EFI_PCI_IO_ATTRIBUTE_MEMORY; - Status = PciIo->Attributes ( - PciIo, - EfiPciIoAttributeOperationEnable, - Attributes, - NULL - ); - if (EFI_ERROR (Status)) { - DEBUG (( - DEBUG_WARN, - "%a: EfiPciIoAttributeOperationEnable: %r\n", - __func__, - Status - )); - goto RestoreAttributes; - } - } - - // - // Success - // - FreePool (Handles); - *OriginalAttributes = OrigAttrs; - *Count = NoHandles; - return; - -RestoreAttributes: - while (Idx > 0) { - --Idx; - OrigAttrs[Idx].PciIo->Attributes ( - OrigAttrs[Idx].PciIo, - EfiPciIoAttributeOperationSet, - OrigAttrs[Idx].PciAttributes, - NULL - ); - } - - FreePool (OrigAttrs); - -FreeHandles: - FreePool (Handles); -} - -/** - Restore the original PCI attributes saved with EnablePciDecoding(). - - @param[in] OriginalAttributes The array allocated and populated by - EnablePciDecoding(). This parameter may be - NULL. If OriginalAttributes is NULL, then the - function is a no-op; otherwise the PciIo - attributes will be restored, and the - OriginalAttributes array will be freed. - - @param[in] Count The Count value stored by EnablePciDecoding(), - the number of elements in OriginalAttributes. - Count may be zero if and only if - OriginalAttributes is NULL. -**/ -VOID -RestorePciDecoding ( - IN ORIGINAL_ATTRIBUTES *OriginalAttributes, - IN UINTN Count - ) -{ - UINTN Idx; - - ASSERT ((OriginalAttributes == NULL) == (Count == 0)); - if (OriginalAttributes == NULL) { - return; - } - - for (Idx = 0; Idx < Count; ++Idx) { - OriginalAttributes[Idx].PciIo->Attributes ( - OriginalAttributes[Idx].PciIo, - EfiPciIoAttributeOperationSet, - OriginalAttributes[Idx].PciAttributes, - NULL - ); - } - - FreePool (OriginalAttributes); -} diff --git a/OvmfPkg/AcpiPlatformDxe/PciDecoding.c b/OvmfPkg/Library/AcpiPlatformLib/PciDecoding.c similarity index 96% rename from OvmfPkg/AcpiPlatformDxe/PciDecoding.c rename to OvmfPkg/Library/AcpiPlatformLib/PciDecoding.c index c7dbfb1baaea..58fbfeefda36 100644 --- a/OvmfPkg/AcpiPlatformDxe/PciDecoding.c +++ b/OvmfPkg/Library/AcpiPlatformLib/PciDecoding.c @@ -7,12 +7,11 @@ SPDX-License-Identifier: BSD-2-Clause-Patent **/ +#include #include // DEBUG() #include // AllocatePool() #include // gBS -#include "AcpiPlatform.h" - /** Collect all PciIo protocol instances in the system. Save their original attributes, and enable IO and MMIO decoding for each. -- 2.41.0