From: Lucas Stach <l.stach@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 5/5] PCI: split PCI hierarchy enumeration and config from device registration
Date: Tue, 1 Nov 2016 09:58:55 +0100 [thread overview]
Message-ID: <20161101085855.953-5-l.stach@pengutronix.de> (raw)
In-Reply-To: <20161101085855.953-1-l.stach@pengutronix.de>
This gets rid of some of the special cases in the bus scanning function
by splitting hierarchy enumeration and configuration and the actual
device registration into 2 passes.
This ensures that the PCI hierarchy below a root port is completely
set up before any device driver is probed.
This simplifies the code and makes it less error prone, while moving
the PCI address space layout closer to the one used by Linux.
Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
---
drivers/pci/pci.c | 31 ++++++++++++++++---------------
1 file changed, 16 insertions(+), 15 deletions(-)
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 12aafccde578..b2570eb15181 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -28,6 +28,20 @@ static struct pci_bus *pci_alloc_bus(void)
return b;
}
+static void pci_bus_register_devices(struct pci_bus *bus)
+{
+ struct pci_dev *dev;
+ struct pci_bus *child_bus;
+
+ /* activate all devices on this bus */
+ list_for_each_entry(dev, &bus->devices, bus_list)
+ pci_register_device(dev);
+
+ /* walk down the hierarchy */
+ list_for_each_entry(child_bus, &bus->children, node)
+ pci_bus_register_devices(child_bus);
+}
+
void register_pci_controller(struct pci_controller *hose)
{
struct pci_bus *bus;
@@ -64,6 +78,7 @@ void register_pci_controller(struct pci_controller *hose)
last_io = 0;
pci_scan_bus(bus);
+ pci_bus_register_devices(bus);
list_add_tail(&bus->node, &pci_root_buses);
@@ -384,16 +399,8 @@ unsigned int pci_scan_bus(struct pci_bus *bus)
dev->rom_address = (l == 0xffffffff) ? 0 : l;
setup_device(dev, 6);
- /*
- * If this device is on the root bus, there is no bridge
- * to configure, so we can activate it right away.
- */
- if (!bus->parent_bus)
- pci_register_device(dev);
break;
case PCI_HEADER_TYPE_BRIDGE:
- setup_device(dev, 2);
-
child_bus = pci_alloc_bus();
/* inherit parent properties */
child_bus->host = bus->host;
@@ -412,18 +419,12 @@ unsigned int pci_scan_bus(struct pci_bus *bus)
list_add_tail(&child_bus->node, &bus->children);
dev->subordinate = child_bus;
- /* activate bridge device */
- pci_register_device(dev);
-
/* scan pci hierarchy behind bridge */
prescan_setup_bridge(dev);
pci_scan_bus(child_bus);
postscan_setup_bridge(dev);
- /* finally active all devices behind the bridge */
- list_for_each_entry(dev, &child_bus->devices, bus_list)
- if (!dev->subordinate)
- pci_register_device(dev);
+ setup_device(dev, 2);
break;
default:
bad:
--
2.10.1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2016-11-01 8:59 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-01 8:58 [PATCH 1/5] PCI: add some useful debug output Lucas Stach
2016-11-01 8:58 ` [PATCH 2/5] PCI: only check specific flag for 64bit BAR Lucas Stach
2016-11-01 8:58 ` [PATCH 3/5] PCI: align address range before scanning bridge Lucas Stach
2016-11-01 8:58 ` [PATCH 4/5] PCI: align BAR address to BAR size Lucas Stach
2016-11-01 8:58 ` Lucas Stach [this message]
2016-11-03 6:12 ` [PATCH 1/5] PCI: add some useful debug output Sascha Hauer
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=20161101085855.953-5-l.stach@pengutronix.de \
--to=l.stach@pengutronix.de \
--cc=barebox@lists.infradead.org \
/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