If release the bridge resources with standard release_child_resources(), it
drops the .start field of children's BARs to zero, but with the STARTALIGN
flag remaining set, which makes the resource invalid for reassignment.

Some resources must preserve their offset and size: those marked with the
PCI_FIXED and the immovable ones - which are bound by drivers without
support of the movable BARs feature.

Add the pci_release_child_resources() to replace release_child_resources()
in handling the described PCI-specific cases.

Signed-off-by: Sergey Miroshnichenko <s.miroshniche...@yadro.com>
---
 drivers/pci/setup-bus.c | 54 ++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 53 insertions(+), 1 deletion(-)

diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index 79b1fa6519be..6cb8b293c576 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -1482,6 +1482,55 @@ static void __pci_bridge_assign_resources(const struct 
pci_dev *bridge,
        (IORESOURCE_IO | IORESOURCE_MEM | IORESOURCE_PREFETCH |\
         IORESOURCE_MEM_64)
 
+/*
+ * Similar to generic release_child_resources(), but aware of immovable BARs 
and
+ * PCI_FIXED and STARTALIGN flags
+ */
+static void pci_release_child_resources(struct pci_bus *bus, struct resource 
*r)
+{
+       struct pci_dev *dev;
+
+       if (!bus || !r)
+               return;
+
+       if (r->flags & IORESOURCE_PCI_FIXED)
+               return;
+
+       r->child = NULL;
+
+       list_for_each_entry(dev, &bus->devices, bus_list) {
+               int i;
+
+               for (i = 0; i < PCI_NUM_RESOURCES; i++) {
+                       struct resource *tmp = &dev->resource[i];
+                       resource_size_t size = resource_size(tmp);
+
+                       if (!tmp->flags || tmp->parent != r)
+                               continue;
+
+                       tmp->parent = NULL;
+                       tmp->sibling = NULL;
+
+                       pci_release_child_resources(dev->subordinate, tmp);
+
+                       if ((tmp->flags & IORESOURCE_PCI_FIXED) ||
+                           !pci_dev_movable_bars_supported(dev)) {
+                               pci_dbg(dev, "release immovable %pR (%s), keep 
its flags, base and size\n",
+                                       tmp, tmp->name);
+                               continue;
+                       }
+
+                       pci_dbg(dev, "release %pR (%s)\n", tmp, tmp->name);
+
+                       tmp->start = 0;
+                       tmp->end = size - 1;
+
+                       tmp->flags &= ~IORESOURCE_STARTALIGN;
+                       tmp->flags |= IORESOURCE_SIZEALIGN;
+               }
+       }
+}
+
 static void pci_bridge_release_resources(struct pci_bus *bus,
                                         unsigned long type)
 {
@@ -1522,7 +1571,10 @@ static void pci_bridge_release_resources(struct pci_bus 
*bus,
                return;
 
        /* If there are children, release them all */
-       release_child_resources(r);
+       if (pci_movable_bars_enabled())
+               pci_release_child_resources(bus, r);
+       else
+               release_child_resources(r);
        if (!release_resource(r)) {
                type = old_flags = r->flags & PCI_RES_TYPE_MASK;
                pci_info(dev, "resource %d %pR released\n",
-- 
2.21.0

Reply via email to