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