]> git.proxmox.com Git - mirror_edk2.git/commitdiff
OvmfPkg/PciHostBridgeUtilityLib: Extend GetRootBridges() with BusMin/BusMax
authorJiahui Cen via groups.io <cenjiahui=huawei.com@groups.io>
Tue, 19 Jan 2021 01:13:00 +0000 (09:13 +0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Wed, 20 Jan 2021 16:14:20 +0000 (16:14 +0000)
Extend parameter list of PciHostBridgeUtilityGetRootBridges() with BusMin/
BusMax, so that the utility function could be compatible with ArmVirtPkg
who uses mutable bus range [BusMin, BusMax] insteand of [0, PCI_MAX_BUS].

BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3059

Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>
Signed-off-by: Jiahui Cen <cenjiahui@huawei.com>
Message-Id: <20210119011302.10908-10-cenjiahui@huawei.com>
[lersek@redhat.com: fix logging of UINTN values BusMin, BusMax]
[lersek@redhat.com: keep zeroing of (*Count) centralized]
[lersek@redhat.com: fix typos in ExtraRootBridges comment]
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h
OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c
OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c

index a0ea44d96a6744d229259cc21e12b5660b32148a..d2dc18a1afad6c4fbac7edd3ca4aca80e3149aee 100644 (file)
@@ -112,6 +112,10 @@ PciHostBridgeUtilityUninitRootBridge (
 \r
   @param[in]  NoExtendedConfigSpace  No Extended Config Space.\r
 \r
+  @param[in]  BusMin                 Minimum Bus number, inclusive.\r
+\r
+  @param[in]  BusMax                 Maximum Bus number, inclusive.\r
+\r
   @param[in]  Io                     IO aperture.\r
 \r
   @param[in]  Mem                    MMIO aperture.\r
@@ -132,6 +136,8 @@ PciHostBridgeUtilityGetRootBridges (
   IN  UINT64                   AllocationAttributes,\r
   IN  BOOLEAN                  DmaAbove4G,\r
   IN  BOOLEAN                  NoExtendedConfigSpace,\r
+  IN  UINTN                    BusMin,\r
+  IN  UINTN                    BusMax,\r
   IN  PCI_ROOT_BRIDGE_APERTURE *Io,\r
   IN  PCI_ROOT_BRIDGE_APERTURE *Mem,\r
   IN  PCI_ROOT_BRIDGE_APERTURE *MemAbove4G,\r
index 91b9e6baa1e8d9e12189fa20b932df4bdc66e6fa..7d9fb0fb293a72917c67aeb15fb642d1bd809212 100644 (file)
@@ -85,6 +85,8 @@ PciHostBridgeGetRootBridges (
     AllocationAttributes,\r
     FALSE,\r
     PcdGet16 (PcdOvmfHostBridgePciDevId) != INTEL_Q35_MCH_DEVICE_ID,\r
+    0,\r
+    PCI_MAX_BUS,\r
     &Io,\r
     &Mem,\r
     &MemAbove4G,\r
index b59da787007d0e3882a542c06228096e65b9ca76..d2296f33085ee178d3a1f5c75f0c65d4ab6b298d 100644 (file)
@@ -200,6 +200,10 @@ PciHostBridgeUtilityUninitRootBridge (
 \r
   @param[in]  NoExtendedConfigSpace  No Extended Config Space.\r
 \r
+  @param[in]  BusMin                 Minimum Bus number, inclusive.\r
+\r
+  @param[in]  BusMax                 Maximum Bus number, inclusive.\r
+\r
   @param[in]  Io                     IO aperture.\r
 \r
   @param[in]  Mem                    MMIO aperture.\r
@@ -220,6 +224,8 @@ PciHostBridgeUtilityGetRootBridges (
   IN  UINT64                   AllocationAttributes,\r
   IN  BOOLEAN                  DmaAbove4G,\r
   IN  BOOLEAN                  NoExtendedConfigSpace,\r
+  IN  UINTN                    BusMin,\r
+  IN  UINTN                    BusMax,\r
   IN  PCI_ROOT_BRIDGE_APERTURE *Io,\r
   IN  PCI_ROOT_BRIDGE_APERTURE *Mem,\r
   IN  PCI_ROOT_BRIDGE_APERTURE *MemAbove4G,\r
@@ -238,6 +244,12 @@ PciHostBridgeUtilityGetRootBridges (
 \r
   *Count = 0;\r
 \r
+  if (BusMin > BusMax || BusMax > PCI_MAX_BUS) {\r
+    DEBUG ((DEBUG_ERROR, "%a: invalid bus range with BusMin %Lu and BusMax "\r
+      "%Lu\n", __FUNCTION__, (UINT64)BusMin, (UINT64)BusMax));\r
+    return NULL;\r
+  }\r
+\r
   //\r
   // QEMU provides the number of extra root buses, shortening the exhaustive\r
   // search below. If there is no hint, the feature is missing.\r
@@ -249,7 +261,14 @@ PciHostBridgeUtilityGetRootBridges (
     QemuFwCfgSelectItem (FwCfgItem);\r
     QemuFwCfgReadBytes (FwCfgSize, &ExtraRootBridges);\r
 \r
-    if (ExtraRootBridges > PCI_MAX_BUS) {\r
+    //\r
+    // Validate the number of extra root bridges. As BusMax is inclusive, the\r
+    // max bus count is (BusMax - BusMin + 1). From that, the "main" root bus\r
+    // is always a given, so the max count for the "extra" root bridges is one\r
+    // less, i.e. (BusMax - BusMin). If the QEMU hint exceeds that, we have\r
+    // invalid behavior.\r
+    //\r
+    if (ExtraRootBridges > BusMax - BusMin) {\r
       DEBUG ((DEBUG_ERROR, "%a: invalid count of extra root buses (%Lu) "\r
         "reported by QEMU\n", __FUNCTION__, ExtraRootBridges));\r
       return NULL;\r
@@ -271,15 +290,15 @@ PciHostBridgeUtilityGetRootBridges (
   //\r
   // The "main" root bus is always there.\r
   //\r
-  LastRootBridgeNumber = 0;\r
+  LastRootBridgeNumber = BusMin;\r
 \r
   //\r
   // Scan all other root buses. If function 0 of any device on a bus returns a\r
   // VendorId register value different from all-bits-one, then that bus is\r
   // alive.\r
   //\r
-  for (RootBridgeNumber = 1;\r
-       RootBridgeNumber <= PCI_MAX_BUS && Initialized < ExtraRootBridges;\r
+  for (RootBridgeNumber = BusMin + 1;\r
+       RootBridgeNumber <= BusMax && Initialized < ExtraRootBridges;\r
        ++RootBridgeNumber) {\r
     UINTN Device;\r
 \r
@@ -329,7 +348,7 @@ PciHostBridgeUtilityGetRootBridges (
     DmaAbove4G,\r
     NoExtendedConfigSpace,\r
     (UINT8) LastRootBridgeNumber,\r
-    PCI_MAX_BUS,\r
+    (UINT8) BusMax,\r
     Io,\r
     Mem,\r
     MemAbove4G,\r