Blame SOURCES/0005-pci-let-firmware-reserve-IO-for-pcie-pci-bridge.patch

aef0c9
From 153f5ec6899055276eaef20eae7b6d9fd090a05a Mon Sep 17 00:00:00 2001
aef0c9
From: Igor Mammedov <imammedo@redhat.com>
aef0c9
Date: Mon, 29 Nov 2021 06:48:12 -0500
aef0c9
Subject: pci: let firmware reserve IO for pcie-pci-bridge
aef0c9
aef0c9
RH-Bugzilla: 2001921
aef0c9
aef0c9
With [1] patch hotplug of rtl8139 succeeds, with caveat that it
aef0c9
fails to initialize IO bar, which is caused by [2] that makes
aef0c9
firmware skip IO reservation for any PCIe device, which isn't
aef0c9
correct in case of pcie-pci-bridge.
aef0c9
Fix it by exposing hotplug type and making IO resource optional
aef0c9
only if PCIe hotplug is in use.
aef0c9
aef0c9
[1]
aef0c9
 "pci: reserve resources for pcie-pci-bridge to fix regressed hotplug on q35"
aef0c9
[2]
aef0c9
aef0c9
Fixes: 76327b9f32a ("fw/pci: do not automatically allocate IO region for PCIe bridges")
aef0c9
Signed-off-by: Igor Mammedov imammedo@redhat.com
aef0c9
CC: mapfelba@redhat.com
aef0c9
CC: kraxel@redhat.com
aef0c9
CC: mst@redhat.com
aef0c9
CC: lvivier@redhat.com
aef0c9
CC: jusual@redhat.com
aef0c9
Tested-by: Laurent Vivier <lvivier@redhat.com>
aef0c9
Acked-by: Michael S. Tsirkin <mst@redhat.com>
aef0c9
Message-Id: <20211129114812.231849-3-imammedo@redhat.com>
aef0c9
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
aef0c9
---
aef0c9
 src/fw/pciinit.c | 19 ++++++++++++++-----
aef0c9
 1 file changed, 14 insertions(+), 5 deletions(-)
aef0c9
aef0c9
diff --git a/src/fw/pciinit.c b/src/fw/pciinit.c
aef0c9
index d25931b..3c99d51 100644
aef0c9
--- a/src/fw/pciinit.c
aef0c9
+++ b/src/fw/pciinit.c
aef0c9
@@ -793,7 +793,13 @@ pci_region_create_entry(struct pci_bus *bus, struct pci_device *dev,
aef0c9
     return entry;
aef0c9
 }
aef0c9
 
aef0c9
-static int pci_bus_hotplug_support(struct pci_bus *bus, u8 pcie_cap)
aef0c9
+typedef enum hotplug_type_t {
aef0c9
+    HOTPLUG_NO_SUPPORTED = 0,
aef0c9
+    HOTPLUG_PCIE,
aef0c9
+    HOTPLUG_SHPC
aef0c9
+} hotplug_type_t;
aef0c9
+
aef0c9
+static hotplug_type_t pci_bus_hotplug_support(struct pci_bus *bus, u8 pcie_cap)
aef0c9
 {
aef0c9
     u8 shpc_cap;
aef0c9
 
aef0c9
@@ -815,11 +821,12 @@ static int pci_bus_hotplug_support(struct pci_bus *bus, u8 pcie_cap)
aef0c9
          */
aef0c9
         u16 slot_implemented = pcie_flags & PCI_EXP_FLAGS_SLOT;
aef0c9
 
aef0c9
-        return downstream_port && slot_implemented;
aef0c9
+        return downstream_port && slot_implemented ?
aef0c9
+            HOTPLUG_PCIE : HOTPLUG_NO_SUPPORTED;
aef0c9
     }
aef0c9
 
aef0c9
     shpc_cap = pci_find_capability(bus->bus_dev->bdf, PCI_CAP_ID_SHPC, 0);
aef0c9
-    return !!shpc_cap;
aef0c9
+    return !!shpc_cap ? HOTPLUG_SHPC : HOTPLUG_NO_SUPPORTED;
aef0c9
 }
aef0c9
 
aef0c9
 /* Test whether bridge support forwarding of transactions
aef0c9
@@ -904,7 +911,7 @@ static int pci_bios_check_devices(struct pci_bus *busses)
aef0c9
         u8 pcie_cap = pci_find_capability(bdf, PCI_CAP_ID_EXP, 0);
aef0c9
         u8 qemu_cap = pci_find_resource_reserve_capability(bdf);
aef0c9
 
aef0c9
-        int hotplug_support = pci_bus_hotplug_support(s, pcie_cap);
aef0c9
+        hotplug_type_t hotplug_support = pci_bus_hotplug_support(s, pcie_cap);
aef0c9
         for (type = 0; type < PCI_REGION_TYPE_COUNT; type++) {
aef0c9
             u64 align = (type == PCI_REGION_TYPE_IO) ?
aef0c9
                 PCI_BRIDGE_IO_MIN : PCI_BRIDGE_MEM_MIN;
aef0c9
@@ -948,7 +955,9 @@ static int pci_bios_check_devices(struct pci_bus *busses)
aef0c9
             if (pci_region_align(&s->r[type]) > align)
aef0c9
                  align = pci_region_align(&s->r[type]);
aef0c9
             u64 sum = pci_region_sum(&s->r[type]);
aef0c9
-            int resource_optional = pcie_cap && (type == PCI_REGION_TYPE_IO);
aef0c9
+            int resource_optional = 0;
aef0c9
+            if (hotplug_support == HOTPLUG_PCIE)
aef0c9
+                resource_optional = pcie_cap && (type == PCI_REGION_TYPE_IO);
aef0c9
             if (!sum && hotplug_support && !resource_optional)
aef0c9
                 sum = align; /* reserve min size for hot-plug */
aef0c9
             if (size > sum) {
aef0c9
-- 
aef0c9
2.27.0
aef0c9