diff mbox series

[1/3] PCI: Create helper to release/restore bridge resources

Message ID 20200928010609.5375-2-jonathan.derrick@intel.com
State New
Headers show
Series PCI: Minimizing resource assignment algorithm | expand

Commit Message

Jon Derrick Sept. 28, 2020, 1:06 a.m. UTC
Moves bridge release and restore code into a common helper. No
functional changes.

Signed-off-by: Jon Derrick <jonathan.derrick@intel.com>
---
 drivers/pci/setup-bus.c | 49 +++++++++++++++++++++++------------------
 1 file changed, 28 insertions(+), 21 deletions(-)
diff mbox series

Patch

diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index 3951e02b7ded..f22502e8e6e6 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -2047,6 +2047,33 @@  static void pci_bridge_distribute_available_resources(struct pci_dev *bridge,
 					       available_mmio_pref);
 }
 
+static void release_and_restore_resources(struct list_head *head)
+{
+	struct pci_dev_resource *dev_res;
+
+	list_for_each_entry(dev_res, head, list)
+		pci_bus_release_bridge_resources(dev_res->dev->bus,
+						 dev_res->flags & PCI_RES_TYPE_MASK,
+						 whole_subtree);
+
+	/* Restore size and flags */
+	list_for_each_entry(dev_res, head, list) {
+		struct resource *res = dev_res->res;
+		int idx;
+
+		res->start = dev_res->start;
+		res->end = dev_res->end;
+		res->flags = dev_res->flags;
+
+		if (pci_is_bridge(dev_res->dev)) {
+			idx = res - &dev_res->dev->resource[0];
+			if (idx >= PCI_BRIDGE_RESOURCES &&
+			    idx <= PCI_BRIDGE_RESOURCE_END)
+				res->flags = 0;
+		}
+	}
+}
+
 void pci_assign_unassigned_bridge_resources(struct pci_dev *bridge)
 {
 	struct pci_bus *parent = bridge->subordinate;
@@ -2088,27 +2115,7 @@  void pci_assign_unassigned_bridge_resources(struct pci_dev *bridge)
 	 * Try to release leaf bridge's resources that aren't big enough
 	 * to contain child device resources.
 	 */
-	list_for_each_entry(fail_res, &fail_head, list)
-		pci_bus_release_bridge_resources(fail_res->dev->bus,
-						 fail_res->flags & PCI_RES_TYPE_MASK,
-						 whole_subtree);
-
-	/* Restore size and flags */
-	list_for_each_entry(fail_res, &fail_head, list) {
-		struct resource *res = fail_res->res;
-		int idx;
-
-		res->start = fail_res->start;
-		res->end = fail_res->end;
-		res->flags = fail_res->flags;
-
-		if (pci_is_bridge(fail_res->dev)) {
-			idx = res - &fail_res->dev->resource[0];
-			if (idx >= PCI_BRIDGE_RESOURCES &&
-			    idx <= PCI_BRIDGE_RESOURCE_END)
-				res->flags = 0;
-		}
-	}
+	release_and_restore_resources(&fail_head);
 	free_list(&fail_head);
 
 	goto again;