From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp-fw-9103.amazon.com (smtp-fw-9103.amazon.com [207.171.188.200]) by mx.groups.io with SMTP id smtpd.web09.204.1643922074525184561 for ; Thu, 03 Feb 2022 13:01:14 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@amazon.com header.s=amazon201209 header.b=upCzY/4t; spf=pass (domain: amazon.de, ip: 207.171.188.200, mailfrom: prvs=026b83387=ncoleon@amazon.de) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amazon.com; i=@amazon.com; q=dns/txt; s=amazon201209; t=1643922074; x=1675458074; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=ALSI4CjJ2wkkWHUI9QuRIIvj2WBtl+kUuct/JOgPCUk=; b=upCzY/4tc9aiP433yzXS5NOJ7Z0/pyCyXsPCILUyY4fAFimo8KzTFWB+ 4/GKuw2C8LI+zvaE2HKD1/tfBPn4ISUKMyFiTKF727nK35gmbqrzffTda HAg6xvPxSx4t20JRjzbHBBmk1TQwG0iicOm1eBvKhLq5lY2WirOZ1mCOv k=; X-IronPort-AV: E=Sophos;i="5.88,340,1635206400"; d="scan'208";a="989485279" Received: from pdx4-co-svc-p1-lb2-vlan2.amazon.com (HELO email-inbound-relay-iad-1box-d-74e80b3c.us-east-1.amazon.com) ([10.25.36.210]) by smtp-border-fw-9103.sea19.amazon.com with ESMTP; 03 Feb 2022 21:01:13 +0000 Received: from EX13D49EUC003.ant.amazon.com (iad12-ws-svc-p26-lb9-vlan3.iad.amazon.com [10.40.163.38]) by email-inbound-relay-iad-1box-d-74e80b3c.us-east-1.amazon.com (Postfix) with ESMTPS id B767D85C59; Thu, 3 Feb 2022 21:01:12 +0000 (UTC) Received: from ub4014a598e6c52.ant.amazon.com (10.43.160.114) by EX13D49EUC003.ant.amazon.com (10.43.164.91) with Microsoft SMTP Server (TLS) id 15.0.1497.28; Thu, 3 Feb 2022 21:01:09 +0000 From: "Ojeda Leon, Nicolas" To: CC: , Nicolas Ojeda Leon , Alexander Graf , Gerd Hoffmann Subject: [PATCH v4 6/8] MdeModulePkg, OvmfPkg: Add Pcd token for PCI pre-populated BARs Date: Thu, 3 Feb 2022 21:56:26 +0100 Message-ID: <260fc07686b09a0eaa336c966cfe6fca65e41a62.1643919691.git.ncoleon@amazon.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: MIME-Version: 1.0 X-Originating-IP: [10.43.160.114] X-ClientProxiedBy: EX13D27UWB004.ant.amazon.com (10.43.161.101) To EX13D49EUC003.ant.amazon.com (10.43.164.91) Content-Type: text/plain Create a new PCD boolean token in MdeModulePkg for global use. We use this token to indicate if the configuration, parsed from fw-cfg, requires pre-populated BARs to be preserved. During creation of root bridges configurations, the flag is set according to the "pre-populated-bars" item in fw-cfg. The Pcd token is created as a dynamic item so it can be modified at runtime and it is consumed in both Pei and Dxe PCI modules. In virtualized environments, the hypervisor provides a layer of isolation between the VMs and the hardware. This isolation may include address translations and shadowing of configurations that prevent guests directly modifying hardware registers. The hypervisor then takes care of emulating the hardware accesses requested by the guest. In some cases, the host may want the guest to use a specific value for some or all PCI BARs so that transactions in GPA level (particularly DMA) can make use of the controlled set of addresses. The host then indicates the guest to preserve those BARs that are pre-populated, that is, BARs that already report a value even before guest's firmware BAR placement. The token provides a globally accessible configuration flag to determine, during PCI BAR allocation, if pre-populated BARs must be respected. The pre-allocated PCI BARs are used in platforms in which MMIO resources are configured with the same host physical addresses in the guest so that DMA transactions can happen between PCI devices without packets going through the IOMMU. Performance is improved due to PCI packets travelling shorter distances and avoiding links reaching the Root Complex, which can get busy during I/O intensive periods. Cc: Alexander Graf Cc: Gerd Hoffmann Signed-off-by: Nicolas Ojeda Leon --- Notes: v4: - Move the code reading the pre-populated-bars fw-cfg file and setting the PcdPciPreservePopulatedMappings token to the new function that gets root bridge information from host-provided data. It only makes sense to have fixed BARs if the root bridge resources are also controlled and thus, both things match. MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf | 1 + MdeModulePkg/MdeModulePkg.dec | 6 ++++++ .../PciHostBridgeUtilityLib.c | 17 +++++++++++++++++ .../PciHostBridgeUtilityLib.inf | 4 ++++ OvmfPkg/OvmfPkgX64.dsc | 1 + OvmfPkg/PlatformPei/PlatformPei.inf | 1 + 6 files changed, 30 insertions(+) diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf b/MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf index e317169d9c..046876bb3b 100644 --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf @@ -107,6 +107,7 @@ gEfiMdeModulePkgTokenSpaceGuid.PcdMrIovSupport ## CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdPciDisableBusEnumeration ## SOMETIMES_CONSUMES gEfiMdeModulePkgTokenSpaceGuid.PcdPcieResizableBarSupport ## CONSUMES + gEfiMdeModulePkgTokenSpaceGuid.PcdPciPreservePopulatedMappings## CONSUMES [UserExtensions.TianoCore."ExtraFiles"] PciBusDxeExtra.uni diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec index 463e889e9a..078877ba7f 100644 --- a/MdeModulePkg/MdeModulePkg.dec +++ b/MdeModulePkg/MdeModulePkg.dec @@ -1902,6 +1902,12 @@ # @Prompt Disable full PCI enumeration. gEfiMdeModulePkgTokenSpaceGuid.PcdPciDisableBusEnumeration|FALSE|BOOLEAN|0x10000048 + ## The flag to control preservation of pre-populated PCI BARs + # TRUE - Respect pre-populated PCI BARs + # FALSE - No pre-populated BARs, place all BARs + # @Prompt Enable preservsation of pre-populated PCI BARs + gEfiMdeModulePkgTokenSpaceGuid.PcdPciPreservePopulatedMappings|FALSE|BOOLEAN|0x10000050 + ## Disk I/O - Number of Data Buffer block. # Define the size in block of the pre-allocated buffer. It provide better # performance for large Disk I/O requests. diff --git a/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c index 4bd4671f10..bb666aef62 100644 --- a/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c +++ b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -443,6 +444,22 @@ PciHostBridgeUtilityGetRootBridgesHostProvided ( PCI_ROOT_BRIDGE_APERTURE MemAbove4G; PCI_ROOT_BRIDGE_APERTURE PMem; PCI_ROOT_BRIDGE_APERTURE PMemAbove4G; + UINT64 PrePopulatedBars; + + // + // Find file for pre-populated bars and set Pcd token if enabled + // + Status = QemuFwCfgFindFile ("etc/pre-populated-bars", &FwCfgItem, &FwCfgSize); + PrePopulatedBars = 0; + if (!EFI_ERROR (Status) && (FwCfgSize == sizeof (PrePopulatedBars))) { + QemuFwCfgSelectItem (FwCfgItem); + QemuFwCfgReadBytes (FwCfgSize, &PrePopulatedBars); + + if (PrePopulatedBars) { + PcdSetBoolS (PcdPciPreservePopulatedMappings, TRUE); + DEBUG ((DEBUG_INFO, "%a: Pre-populated BARs present\n", __FUNCTION__)); + } + } // // Initialize the Hardware Info list head to start with an empty but valid diff --git a/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf index e4fc903121..570bf7e97c 100644 --- a/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf +++ b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf @@ -40,5 +40,9 @@ DevicePathLib DxeHardwareInfoLib MemoryAllocationLib + PcdLib PciLib QemuFwCfgLib + +[Pcd] + gEfiMdeModulePkgTokenSpaceGuid.PcdPciPreservePopulatedMappings diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc index b376387b7c..1656509f03 100644 --- a/OvmfPkg/OvmfPkgX64.dsc +++ b/OvmfPkg/OvmfPkgX64.dsc @@ -594,6 +594,7 @@ gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwWorkingBase|0 gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareBase|0 !endif + gEfiMdeModulePkgTokenSpaceGuid.PcdPciPreservePopulatedMappings|FALSE gEfiMdeModulePkgTokenSpaceGuid.PcdVideoHorizontalResolution|800 gEfiMdeModulePkgTokenSpaceGuid.PcdVideoVerticalResolution|600 gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiS3Enable|FALSE diff --git a/OvmfPkg/PlatformPei/PlatformPei.inf b/OvmfPkg/PlatformPei/PlatformPei.inf index e840f960d3..b58f79c6e3 100644 --- a/OvmfPkg/PlatformPei/PlatformPei.inf +++ b/OvmfPkg/PlatformPei/PlatformPei.inf @@ -96,6 +96,7 @@ gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageFtwSpareSize gEfiMdeModulePkgTokenSpaceGuid.PcdFlashNvStorageVariableSize gEfiMdeModulePkgTokenSpaceGuid.PcdEmuVariableNvStoreReserved + gEfiMdeModulePkgTokenSpaceGuid.PcdPciPreservePopulatedMappings gEfiMdeModulePkgTokenSpaceGuid.PcdDxeIplSwitchToLongMode gEfiMdeModulePkgTokenSpaceGuid.PcdUse1GPageTable gEfiMdeModulePkgTokenSpaceGuid.PcdSetNxForStack -- 2.17.1 Amazon Development Center Germany GmbH Krausenstr. 38 10117 Berlin Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B Sitz: Berlin Ust-ID: DE 289 237 879