Skip to contentSkip to conversation

MdeModulePkg, OvmfPkg: fixed PCI BAR placement

RFC PATCH New Tushar Dave 2 participants 3 messages Aug 27

lore
Share & tools
lore
#1 lore raw

RFC PATCH v2 1/2 MdeModulePkg/PciBusDxe: honor fixed BAR addresses from IncompatiblePci

In reply to Tushar Dave

EFI_INCOMPATIBLE_PCI_DEVICE_SUPPORT_PROTOCOL returns ACPI address descriptors describing PCI resource requirements. When both _MIF (BIT2) and _MAF (BIT3) are set in the descriptor's GenFlag, the descriptor represents a fixed address range.

Extend PCI_BAR with FixedBaseAddress and update the PCI bus driver to preserve and use this information:

* UpdatePciInfo() detects _MIF|_MAF, records AddrRangeMin as FixedBaseAddress, and marks the BAR as fixed.

* ProgramBar() programs FixedBaseAddress into the BAR register instead of the resource allocator selected address for fixed BARs.

No functional change occurs unless a platform driver supplies fixed BAR descriptors through EFI_INCOMPATIBLE_PCI_DEVICE_SUPPORT_PROTOCOL.

---
 MdeModulePkg/Bus/Pci/PciBusDxe/PciBus.h             |  1 +
 .../Bus/Pci/PciBusDxe/PciEnumeratorSupport.c        | 12 ++++++++++++
 MdeModulePkg/Bus/Pci/PciBusDxe/PciResourceSupport.c | 13 +++++++++++++
 3 files changed, 26 insertions(+)
MdeModulePkg/Bus/Pci/PciBusDxe/PciBus.h +1 -0
index 01bce28b1b..4edf45119f 100644
@@ -96,6 +96,7 @@ struct _PCI_BAR {
   UINT64          Alignment;
   PCI_BAR_TYPE    BarType;
   BOOLEAN         BarTypeFixed;
+  UINT64          FixedBaseAddress;
   UINT16          Offset;
 };
 
MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.c +12 -0
index ae94462f60..da16355d9f 100644
@@ -1638,6 +1638,18 @@ UpdatePciInfo (
         if (Ptr->AddrLen != 0) {
           PciIoDevice->PciBar[BarIndex].Length = Ptr->AddrLen;
         }
+
+        //
+        // When both _MIF (BIT2) and _MAF (BIT3) are set in GenFlag the
+        // descriptor carries a fixed base address in AddrRangeMin.
+        //
+        if ((Ptr->GenFlag & (BIT2 | BIT3)) == (BIT2 | BIT3)) {
+          PciIoDevice->PciBar[BarIndex].BarTypeFixed     = TRUE;
+          PciIoDevice->PciBar[BarIndex].FixedBaseAddress = Ptr->AddrRangeMin;
+          DEBUG ((DEBUG_INFO,
+                  "PciBus: UpdatePciInfo BAR[%u] fixed address=0x%016Lx\n",
+                  (UINT32)BarIndex, Ptr->AddrRangeMin));
+        }
       }
     }
 
MdeModulePkg/Bus/Pci/PciBusDxe/PciResourceSupport.c +13 -0
index 8f3cff3eaa..5cc3ae797d 100644
@@ -1276,6 +1276,19 @@ ProgramBar (
 
   Address = Base + Node->Offset;
 
+  //
+  // If EFI_INCOMPATIBLE_PCI_DEVICE_SUPPORT_PROTOCOL supplied a fixed
+  // base address (_MIF|_MAF in the ACPI descriptor), use it directly.
+  //
+  if (Node->PciDev->PciBar[Node->Bar].BarTypeFixed &&
+      (Node->PciDev->PciBar[Node->Bar].FixedBaseAddress != 0))
+  {
+    Address = Node->PciDev->PciBar[Node->Bar].FixedBaseAddress;
+    DEBUG ((DEBUG_INFO,
+            "PciBus: BAR[%d] fixed address 0x%016Lx (GCD 0x%016Lx)\n",
+            Node->Bar, Address, Base + Node->Offset));
+  }
+
   //
   // Indicate pci bus driver has allocated
   // resource for this device
Signature · 1 line
2.34.1
#0 lore raw

v2 cover MdeModulePkg, OvmfPkg: fixed PCI BAR placement

This is the EDK2 companion to the QEMU RFC v2 series [1].

This series implements the firmware side of fixed PCI BAR placement. QEMU exports validated fixed BAR addresses through the etc/fixed-bars fw_cfg file. This series consumes that information in two steps.

Patch 1 adds minimal changes to PciBusDxe to honor fixed BAR addresses supplied through EFI_INCOMPATIBLE_PCI_DEVICE_SUPPORT_PROTOCOL. When both _MIF and _MAF flags are set in an ACPI address descriptor returned by CheckDevice(), the described address is treated as a fixed requirement. UpdatePciInfo() records the fixed address on the BAR and ProgramBar() uses it in place of the GCD-allocated address.

Patch 2 introduces QemuFixedBarsDxe, a new OvmfPkg driver that installs EFI_INCOMPATIBLE_PCI_DEVICE_SUPPORT_PROTOCOL before PciBusDxe starts. It reads the etc/fixed-bars fw_cfg blob, reserves the required address ranges in the GCD, and returns fixed BAR addresses through CheckDevice(). After PciEnumerationComplete, it reprograms bridge memory windows along each fixed root-port hierarchy to cover the fixed BAR placements.

Testing:

The series was tested together with the QEMU companion patches on the AArch64 virt machine using multiple PCI topologies, including emulated devices, VFIO passthrough devices, PCIe switches, and PCIe root ports configured for fixed BAR placement.

A git branch with this series applied is available at:
https://github.com/tdavenvidia/edk2/tree/RFC-v2-fixed-bar-upstream

[1] companion QEMU RFC v2
https://github.com/tdavenvidia/upstream-qemu/tree/RFC-v2-fixed-bar-upstream

Tushar Dave (2):
MdeModulePkg/PciBusDxe: honor fixed BAR addresses from IncompatiblePci ArmVirtPkg,OvmfPkg: add QemuFixedBarsDxe for fixed PCI BAR placement

 ArmVirtPkg/ArmVirtQemu.dsc                    |   1 +
 ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc          |   1 +
 MdeModulePkg/Bus/Pci/PciBusDxe/PciBus.h       |   1 +
 .../Bus/Pci/PciBusDxe/PciEnumeratorSupport.c  |  12 +
 .../Bus/Pci/PciBusDxe/PciResourceSupport.c    |  13 +
 OvmfPkg/QemuFixedBarsDxe/QemuFixedBarsDxe.c   | 772 ++++++++++++++++++
 OvmfPkg/QemuFixedBarsDxe/QemuFixedBarsDxe.inf |  43 +
 7 files changed, 843 insertions(+)
 create mode 100644 OvmfPkg/QemuFixedBarsDxe/QemuFixedBarsDxe.c
 create mode 100644 OvmfPkg/QemuFixedBarsDxe/QemuFixedBarsDxe.inf
Signature · 1 line
2.34.1
#2 lore raw

RFC PATCH v2 2/2 ArmVirtPkg, OvmfPkg: add QemuFixedBarsDxe for fixed PCI BAR placement

Add QemuFixedBarsDxe, a DXE driver that enables fixed PCI BAR placement using metadata provided by QEMU through the "etc/fixed-bars" fw_cfg file.

The driver installs EFI_INCOMPATIBLE_PCI_DEVICE_SUPPORT_PROTOCOL before PciBusDxe starts so fixed BAR addresses can be returned during CheckDevice(). PciBusDxe then programs those addresses directly when assigning BAR resources.

The driver also reserves the fixed BAR address ranges in GCD before PCI enumeration and, after enumeration completes, updates PCI bridge memory windows to cover the programmed BAR ranges.

---
 ArmVirtPkg/ArmVirtQemu.dsc                    |   1 +
 ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc          |   1 +
 OvmfPkg/QemuFixedBarsDxe/QemuFixedBarsDxe.c   | 772 ++++++++++++++++++
 OvmfPkg/QemuFixedBarsDxe/QemuFixedBarsDxe.inf |  43 +
 4 files changed, 817 insertions(+)
 create mode 100644 OvmfPkg/QemuFixedBarsDxe/QemuFixedBarsDxe.c
 create mode 100644 OvmfPkg/QemuFixedBarsDxe/QemuFixedBarsDxe.inf
ArmVirtPkg/ArmVirtQemu.dsc +1 -0
index 0212be4a33..58164d5418 100644
@@ -469,6 +469,7 @@
   #
   # PCI support
   #
+  OvmfPkg/QemuFixedBarsDxe/QemuFixedBarsDxe.inf
   MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridgeDxe.inf
 
   #
ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc +1 -0
index ad158f57f1..879165de3f 100644
@@ -157,6 +157,7 @@ READ_LOCK_STATUS   = TRUE
   # PCI support
   #
   INF UefiCpuPkg/CpuMmio2Dxe/CpuMmio2Dxe.inf
+  INF OvmfPkg/QemuFixedBarsDxe/QemuFixedBarsDxe.inf
   INF MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridgeDxe.inf
   INF MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf
   INF OvmfPkg/PciHotPlugInitDxe/PciHotPlugInit.inf
OvmfPkg/QemuFixedBarsDxe/QemuFixedBarsDxe.c new file +772 -0

772 lines not on this page · raw message

OvmfPkg/QemuFixedBarsDxe/QemuFixedBarsDxe.inf new file +43 -0

43 lines not on this page · raw message

Signature · 1 line
2.34.1