mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
To: "Bjorn Helgaas" <bhelgaas@google.com>,
	linux-pci@vger.kernel.org,
	"Michał Winiarski" <michal.winiarski@intel.com>,
	"Igor Mammedov" <imammedo@redhat.com>,
	linux-kernel@vger.kernel.org
Cc: "Mika Westerberg" <mika.westerberg@linux.intel.com>,
	"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
Subject: [PATCH 16/25] PCI: Consolidate assignment loop next round preparation
Date: Mon, 16 Dec 2024 19:56:23 +0200	[thread overview]
Message-ID: <20241216175632.4175-17-ilpo.jarvinen@linux.intel.com> (raw)
In-Reply-To: <20241216175632.4175-1-ilpo.jarvinen@linux.intel.com>

pci_assign_unassigned_root_bus_resources() and
pci_assign_unassigned_bridge_resources() have a loop that performs a
number rounds to assign resources. The code to prepare for the next
round is identical.

Consolidate the code that prepares for the next assignment round
into pci_prepare_next_assign_round().

Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
---
 drivers/pci/setup-bus.c | 104 ++++++++++++++++------------------------
 1 file changed, 42 insertions(+), 62 deletions(-)

diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index 38dbe8b99910..7e5985543734 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -2135,6 +2135,45 @@ pci_root_bus_distribute_available_resources(struct pci_bus *bus,
 	}
 }
 
+static void pci_prepare_next_assign_round(struct list_head *fail_head,
+					  int tried_times,
+					  enum release_type rel_type)
+{
+	struct pci_dev_resource *fail_res;
+
+	pr_info("PCI: No. %d try to assign unassigned res\n", tried_times + 1);
+
+	/*
+	 * 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,
+						 rel_type);
+	}
+
+	/* Restore size and flags */
+	list_for_each_entry(fail_res, fail_head, list) {
+		struct resource *res = fail_res->res;
+		struct pci_dev *dev = fail_res->dev;
+		int idx = pci_resource_num(dev, res);
+
+		res->start = fail_res->start;
+		res->end = fail_res->end;
+		res->flags = fail_res->flags;
+
+		if (!pci_is_bridge(dev))
+			continue;
+
+		if (idx >= PCI_BRIDGE_RESOURCES &&
+		    idx <= PCI_BRIDGE_RESOURCE_END)
+			res->flags = 0;
+	}
+
+	free_list(fail_head);
+}
+
 /*
  * First try will not touch PCI bridge res.
  * Second and later try will clear small leaf bridge res.
@@ -2148,7 +2187,6 @@ void pci_assign_unassigned_root_bus_resources(struct pci_bus *bus)
 	int tried_times = 0;
 	enum release_type rel_type = leaf_only;
 	LIST_HEAD(fail_head);
-	struct pci_dev_resource *fail_res;
 	int pci_try_num = 1;
 	enum enable_type enable_local;
 
@@ -2199,40 +2237,11 @@ void pci_assign_unassigned_root_bus_resources(struct pci_bus *bus)
 			break;
 		}
 
-		dev_info(&bus->dev, "No. %d try to assign unassigned res\n",
-			 tried_times + 1);
-
 		/* Third times and later will not check if it is leaf */
 		if (tried_times + 1 > 2)
 			rel_type = whole_subtree;
 
-		/*
-		 * Try to release leaf bridge's resources that doesn't fit
-		 * resource of child device under that bridge.
-		 */
-		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,
-							 rel_type);
-		}
-
-		/* 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 = pci_resource_num(fail_res->dev, res);
-				if (idx >= PCI_BRIDGE_RESOURCES &&
-				    idx <= PCI_BRIDGE_RESOURCE_END)
-					res->flags = 0;
-			}
-		}
-		free_list(&fail_head);
+		pci_prepare_next_assign_round(&fail_head, tried_times, rel_type);
 	}
 
 	pci_bus_dump_resources(bus);
@@ -2258,7 +2267,6 @@ void pci_assign_unassigned_bridge_resources(struct pci_dev *bridge)
 	LIST_HEAD(add_list);
 	int tried_times = 0;
 	LIST_HEAD(fail_head);
-	struct pci_dev_resource *fail_res;
 	int ret;
 
 	while (1) {
@@ -2284,36 +2292,8 @@ void pci_assign_unassigned_bridge_resources(struct pci_dev *bridge)
 			break;
 		}
 
-		printk(KERN_DEBUG "PCI: No. %d try to assign unassigned res\n",
-				 tried_times + 1);
-
-		/*
-		 * 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 = pci_resource_num(fail_res->dev, res);
-				if (idx >= PCI_BRIDGE_RESOURCES &&
-				    idx <= PCI_BRIDGE_RESOURCE_END)
-					res->flags = 0;
-			}
-		}
-		free_list(&fail_head);
+		pci_prepare_next_assign_round(&fail_head, tried_times,
+					      whole_subtree);
 	}
 
 	ret = pci_reenable_device(bridge);
-- 
2.39.5


  parent reply	other threads:[~2024-12-16 17:58 UTC|newest]

Thread overview: 71+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-16 17:56 [PATCH 00/25] PCI: Resource fitting/assignment fixes and cleanups Ilpo Järvinen
2024-12-16 17:56 ` [PATCH 01/25] PCI: Remove add_align overwrite unrelated to size0 Ilpo Järvinen
2024-12-16 17:56 ` [PATCH 02/25] PCI: size0 is unrelated to add_align Ilpo Järvinen
2024-12-16 17:56 ` [PATCH 03/25] PCI: Simplify size1 assignment logic Ilpo Järvinen
2024-12-16 17:56 ` [PATCH 04/25] PCI: Optional bridge window size too may need relaxing Ilpo Järvinen
2024-12-16 17:56 ` [PATCH 05/25] PCI: Fix old_size lower bound in calculate_iosize() too Ilpo Järvinen
2024-12-16 17:56 ` [PATCH 06/25] PCI: Use SZ_* instead of literals in setup-bus.c Ilpo Järvinen
2024-12-16 17:56 ` [PATCH 07/25] PCI: resource_set_range/size() conversions Ilpo Järvinen
2024-12-16 17:56 ` [PATCH 08/25] PCI: Add a helper to identify IOV resources Ilpo Järvinen
2024-12-16 17:56 ` [PATCH 09/25] PCI: Check resource_size() separately Ilpo Järvinen
2024-12-16 17:56 ` [PATCH 10/25] PCI: Add pci_resource_num() helper Ilpo Järvinen
2024-12-16 17:56 ` [PATCH 11/25] PCI: Add dev & res local variables to resource assignment funcs Ilpo Järvinen
2024-12-16 17:56 ` [PATCH 12/25] PCI: Converge return paths in __assign_resources_sorted() Ilpo Järvinen
2024-12-16 17:56 ` [PATCH 13/25] PCI: Refactor pdev_sort_resources() & __dev_sort_resources() Ilpo Järvinen
2024-12-16 17:56 ` [PATCH 14/25] PCI: Use while loop and break instead of gotos Ilpo Järvinen
2024-12-16 17:56 ` [PATCH 15/25] PCI: Rename retval to ret Ilpo Järvinen
2024-12-16 17:56 ` Ilpo Järvinen [this message]
2024-12-16 17:56 ` [PATCH 17/25] PCI: Remove wrong comment from pci_reassign_resource() Ilpo Järvinen
2024-12-16 17:56 ` [PATCH 18/25] PCI: Add restore_dev_resource() Ilpo Järvinen
2024-12-16 17:56 ` [PATCH 19/25] PCI: Extend enable to check for any optional resource Ilpo Järvinen
2024-12-16 17:56 ` [PATCH 20/25] PCI: Always have realloc_head in __assign_resources_sorted() Ilpo Järvinen
2024-12-16 17:56 ` [PATCH 21/25] PCI: Indicate optional resource assignment failures Ilpo Järvinen
2024-12-16 17:56 ` [PATCH 22/25] PCI: Add debug print when releasing resources before retry Ilpo Järvinen
2024-12-16 17:56 ` [PATCH 23/25] PCI: Use res->parent to check is resource is assigned Ilpo Järvinen
2024-12-16 17:56 ` [PATCH 24/25] PCI: Perform reset_resource() and build fail list in sync Ilpo Järvinen
2025-04-01  2:35   ` Guenter Roeck
2025-04-01 10:18     ` Ilpo Järvinen
2025-04-01 12:07       ` Ilpo Järvinen
2025-04-01 14:15         ` Guenter Roeck
2025-04-01 17:38           ` Ilpo Järvinen
2025-04-11 19:37             ` Ondřej Jirman
2025-04-14  9:52               ` Ilpo Järvinen
2025-04-14 12:19                 ` Ondřej Jirman
2025-04-14 13:15                   ` Ilpo Järvinen
2025-04-14 13:43                     ` Ondřej Jirman
2025-04-14 13:52                       ` Ilpo Järvinen
2025-04-01 13:28       ` Guenter Roeck
2025-05-06 15:03   ` Tudor Ambarus
2025-05-06 15:53     ` Ilpo Järvinen
2025-05-28 11:22       ` Tudor Ambarus
2025-05-28 11:39         ` Tudor Ambarus
2025-05-28 13:09           ` Tudor Ambarus
2025-05-30  6:55             ` Ilpo Järvinen
2025-05-30  6:38         ` Ilpo Järvinen
2025-05-30 14:48           ` Ilpo Järvinen
2025-06-02 14:40             ` Tudor Ambarus
2025-06-02 15:08               ` Ilpo Järvinen
2025-06-02 18:42                 ` Tudor Ambarus
2025-06-03  8:13                   ` Ilpo Järvinen
2025-06-03 10:36                     ` Tudor Ambarus
2025-06-03 10:48                       ` Tudor Ambarus
2025-06-03 11:43                         ` Tudor Ambarus
2025-06-03 14:23                           ` Ilpo Järvinen
2025-06-03 14:43                             ` Ilpo Järvinen
2025-06-03 14:13                       ` Ilpo Järvinen
2025-06-03 15:25                         ` Tudor Ambarus
2025-06-03 17:03                           ` Ilpo Järvinen
2025-06-03 17:09                             ` Ilpo Järvinen
2025-06-02 12:32           ` Tudor Ambarus
2025-06-19  0:30   ` D Scott Phillips
2025-06-24 12:48     ` Ilpo Järvinen
2025-06-25 17:45     ` Ilpo Järvinen
2025-06-25 20:33       ` D Scott Phillips
2025-06-26  9:22         ` Ilpo Järvinen
2025-06-26 14:53           ` D Scott Phillips
2024-12-16 17:56 ` [PATCH 25/25] PCI: Rework optional resource handling Ilpo Järvinen
2025-02-13 21:46 ` [PATCH 00/25] PCI: Resource fitting/assignment fixes and cleanups Bjorn Helgaas
2025-02-14  8:18 ` Xiaochun XC17 Li | 李小春 Xavier
2025-02-14 11:53   ` Ilpo Järvinen
2025-02-14 21:28     ` Bjorn Helgaas
2025-02-14  9:59 ` Xiaochun Lee

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241216175632.4175-17-ilpo.jarvinen@linux.intel.com \
    --to=ilpo.jarvinen@linux.intel.com \
    --cc=bhelgaas@google.com \
    --cc=imammedo@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=michal.winiarski@intel.com \
    --cc=mika.westerberg@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®