public inbox for linux-pci@vger.kernel.org
 help / color / mirror / Atom feed
From: Bjorn Helgaas <helgaas@kernel.org>
To: Mika Westerberg <mika.westerberg@linux.intel.com>,
	Nicholas Johnson <nicholas.johnson-opensource@outlook.com.au>
Cc: Logan Gunthorpe <logang@deltatee.com>,
	Benjamin Herrenschmidt <benh@kernel.crashing.org>,
	linux-pci@vger.kernel.org, Bjorn Helgaas <bhelgaas@google.com>
Subject: [PATCH 1/2] PCI: Simplify pci_bus_distribute_available_resources()
Date: Sat, 22 Jun 2019 16:03:10 -0500	[thread overview]
Message-ID: <20190622210310.180905-2-helgaas@kernel.org> (raw)
In-Reply-To: <20190622210310.180905-1-helgaas@kernel.org>

From: Bjorn Helgaas <bhelgaas@google.com>

Reorder pci_bus_distribute_available_resources() to group related code
together.  No functional change intended.

Link: https://lore.kernel.org/r/PS2P216MB0642C7A485649D2D787A1C6F80000@PS2P216MB0642.KORP216.PROD.OUTLOOK.COM
Based-on-patch-by: Nicholas Johnson <nicholas.johnson-opensource@outlook.com.au>
[bhelgaas: extracted from larger patch]
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>

---

The original order was:

  1) remaining_io = available_io

  2) for_each_pci_bridge(dev, bus)
       # count hotplug_bridges, normal_bridges

  3) for_each_pci_bridge(dev, bus)
       if (!dev->is_hotplug_bridge)
	 # reduce remaining_io by dev window

  4) if (hotplug_bridges + normal_bridges == 1)
       # distribute available_io to the single bridge
       # return

  5) for_each_pci_bridge(dev, bus)
       # distribute remaining_io to hotplug bridges

Blocks 2 and 4 don't require remaining_io, so do them first.  Blocks 1, 3,
5 deal with remaining_io, so group them together.
---
 drivers/pci/setup-bus.c | 50 ++++++++++++++++++++---------------------
 1 file changed, 25 insertions(+), 25 deletions(-)

diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index 0cdd5ff389de..af28af898e42 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -1860,16 +1860,6 @@ static void pci_bus_distribute_available_resources(struct pci_bus *bus,
 	extend_bridge_window(bridge, mmio_pref_res, add_list,
 			     available_mmio_pref);
 
-	/*
-	 * Calculate the total amount of extra resource space we can
-	 * pass to bridges below this one.  This is basically the
-	 * extra space reduced by the minimal required space for the
-	 * non-hotplug bridges.
-	 */
-	remaining_io = available_io;
-	remaining_mmio = available_mmio;
-	remaining_mmio_pref = available_mmio_pref;
-
 	/*
 	 * Calculate how many hotplug bridges and normal bridges there
 	 * are on this bus.  We will distribute the additional available
@@ -1882,6 +1872,31 @@ static void pci_bus_distribute_available_resources(struct pci_bus *bus,
 			normal_bridges++;
 	}
 
+	/*
+	 * There is only one bridge on the bus so it gets all available
+	 * resources which it can then distribute to the possible hotplug
+	 * bridges below.
+	 */
+	if (hotplug_bridges + normal_bridges == 1) {
+		dev = list_first_entry(&bus->devices, struct pci_dev, bus_list);
+		if (dev->subordinate) {
+			pci_bus_distribute_available_resources(dev->subordinate,
+				add_list, available_io, available_mmio,
+				available_mmio_pref);
+		}
+		return;
+	}
+
+	/*
+	 * Calculate the total amount of extra resource space we can
+	 * pass to bridges below this one.  This is basically the
+	 * extra space reduced by the minimal required space for the
+	 * non-hotplug bridges.
+	 */
+	remaining_io = available_io;
+	remaining_mmio = available_mmio;
+	remaining_mmio_pref = available_mmio_pref;
+
 	for_each_pci_bridge(dev, bus) {
 		const struct resource *res;
 
@@ -1905,21 +1920,6 @@ static void pci_bus_distribute_available_resources(struct pci_bus *bus,
 			remaining_mmio_pref -= resource_size(res);
 	}
 
-	/*
-	 * There is only one bridge on the bus so it gets all available
-	 * resources which it can then distribute to the possible hotplug
-	 * bridges below.
-	 */
-	if (hotplug_bridges + normal_bridges == 1) {
-		dev = list_first_entry(&bus->devices, struct pci_dev, bus_list);
-		if (dev->subordinate) {
-			pci_bus_distribute_available_resources(dev->subordinate,
-				add_list, available_io, available_mmio,
-				available_mmio_pref);
-		}
-		return;
-	}
-
 	/*
 	 * Go over devices on this bus and distribute the remaining
 	 * resource space between hotplug bridges.
-- 
2.22.0.410.gd8fdbe21b5-goog


  reply	other threads:[~2019-06-22 21:03 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-22 21:03 [PATCH 0/2] PCI: Simplify pci_bus_distribute_available_resources() Bjorn Helgaas
2019-06-22 21:03 ` Bjorn Helgaas [this message]
2019-06-24 11:09   ` [PATCH 1/2] " Mika Westerberg
2019-06-24 16:21   ` Logan Gunthorpe
2019-06-22 21:03 ` [PATCH 2/2] PCI: Skip resource distribution when no hotplug bridges Bjorn Helgaas
2019-06-24 11:24   ` Mika Westerberg
2019-06-24 23:45     ` Benjamin Herrenschmidt
2019-06-25 10:05       ` Mika Westerberg
2019-06-25 11:48         ` Benjamin Herrenschmidt
2019-06-25 12:04           ` Mika Westerberg
2019-06-25 12:23             ` Benjamin Herrenschmidt
2019-06-25 12:43               ` Mika Westerberg
2019-06-25 23:22             ` Benjamin Herrenschmidt
2019-06-26 17:35       ` Bjorn Helgaas
2019-06-26 22:35         ` Benjamin Herrenschmidt
2019-06-24 16:26   ` Logan Gunthorpe

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=20190622210310.180905-2-helgaas@kernel.org \
    --to=helgaas@kernel.org \
    --cc=benh@kernel.crashing.org \
    --cc=bhelgaas@google.com \
    --cc=linux-pci@vger.kernel.org \
    --cc=logang@deltatee.com \
    --cc=mika.westerberg@linux.intel.com \
    --cc=nicholas.johnson-opensource@outlook.com.au \
    /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