aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pci/probe.c
diff options
context:
space:
mode:
authorYinghai Lu <yinghai@kernel.org>2013-01-21 16:20:52 -0500
committerBjorn Helgaas <bhelgaas@google.com>2013-01-25 18:22:37 -0500
commit4f535093cf8f6da8cfda7c36c2c1ecd2e9586ee4 (patch)
tree62bf63646dc1c6870c5520b15d0f17aa09e05db5 /drivers/pci/probe.c
parent58d9a38f6facb28e935ec2747f6d9e9bf4684118 (diff)
PCI: Put pci_dev in device tree as early as possible
We want to put pci_dev structs in the device tree as soon as possible so for_each_pci_dev() iteration will not miss them, but driver attachment needs to be delayed until after pci_assign_unassigned_resources() to make sure all devices have resources assigned first. This patch moves device registering from pci_bus_add_devices() to pci_device_add(), which happens earlier, leaving driver attachment in pci_bus_add_devices(). It also removes unattached child bus handling in pci_bus_add_devices(). That's not needed because child bus via pci_add_new_bus() is already in parent bus children list. [bhelgaas: changelog] Signed-off-by: Yinghai Lu <yinghai@kernel.org> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Diffstat (limited to 'drivers/pci/probe.c')
-rw-r--r--drivers/pci/probe.c35
1 files changed, 28 insertions, 7 deletions
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index 48b35e15374d..281d90f19c7a 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -623,6 +623,7 @@ static struct pci_bus *pci_alloc_child_bus(struct pci_bus *parent,
623{ 623{
624 struct pci_bus *child; 624 struct pci_bus *child;
625 int i; 625 int i;
626 int ret;
626 627
627 /* 628 /*
628 * Allocate a new bus, and inherit stuff from the parent.. 629 * Allocate a new bus, and inherit stuff from the parent..
@@ -637,8 +638,7 @@ static struct pci_bus *pci_alloc_child_bus(struct pci_bus *parent,
637 child->bus_flags = parent->bus_flags; 638 child->bus_flags = parent->bus_flags;
638 639
639 /* initialize some portions of the bus device, but don't register it 640 /* initialize some portions of the bus device, but don't register it
640 * now as the parent is not properly set up yet. This device will get 641 * now as the parent is not properly set up yet.
641 * registered later in pci_bus_add_devices()
642 */ 642 */
643 child->dev.class = &pcibus_class; 643 child->dev.class = &pcibus_class;
644 dev_set_name(&child->dev, "%04x:%02x", pci_domain_nr(child), busnr); 644 dev_set_name(&child->dev, "%04x:%02x", pci_domain_nr(child), busnr);
@@ -651,11 +651,14 @@ static struct pci_bus *pci_alloc_child_bus(struct pci_bus *parent,
651 child->primary = parent->busn_res.start; 651 child->primary = parent->busn_res.start;
652 child->busn_res.end = 0xff; 652 child->busn_res.end = 0xff;
653 653
654 if (!bridge) 654 if (!bridge) {
655 return child; 655 child->dev.parent = parent->bridge;
656 goto add_dev;
657 }
656 658
657 child->self = bridge; 659 child->self = bridge;
658 child->bridge = get_device(&bridge->dev); 660 child->bridge = get_device(&bridge->dev);
661 child->dev.parent = child->bridge;
659 pci_set_bus_of_node(child); 662 pci_set_bus_of_node(child);
660 pci_set_bus_speed(child); 663 pci_set_bus_speed(child);
661 664
@@ -666,6 +669,13 @@ static struct pci_bus *pci_alloc_child_bus(struct pci_bus *parent,
666 } 669 }
667 bridge->subordinate = child; 670 bridge->subordinate = child;
668 671
672add_dev:
673 ret = device_register(&child->dev);
674 WARN_ON(ret < 0);
675
676 /* Create legacy_io and legacy_mem files for this bus */
677 pci_create_legacy_files(child);
678
669 return child; 679 return child;
670} 680}
671 681
@@ -1296,6 +1306,8 @@ static void pci_init_capabilities(struct pci_dev *dev)
1296 1306
1297void pci_device_add(struct pci_dev *dev, struct pci_bus *bus) 1307void pci_device_add(struct pci_dev *dev, struct pci_bus *bus)
1298{ 1308{
1309 int ret;
1310
1299 device_initialize(&dev->dev); 1311 device_initialize(&dev->dev);
1300 dev->dev.release = pci_release_dev; 1312 dev->dev.release = pci_release_dev;
1301 1313
@@ -1326,6 +1338,17 @@ void pci_device_add(struct pci_dev *dev, struct pci_bus *bus)
1326 down_write(&pci_bus_sem); 1338 down_write(&pci_bus_sem);
1327 list_add_tail(&dev->bus_list, &bus->devices); 1339 list_add_tail(&dev->bus_list, &bus->devices);
1328 up_write(&pci_bus_sem); 1340 up_write(&pci_bus_sem);
1341
1342 pci_fixup_device(pci_fixup_final, dev);
1343 ret = pcibios_add_device(dev);
1344 WARN_ON(ret < 0);
1345
1346 /* Notifier could use PCI capabilities */
1347 dev->match_driver = false;
1348 ret = device_add(&dev->dev);
1349 WARN_ON(ret < 0);
1350
1351 pci_proc_attach_device(dev);
1329} 1352}
1330 1353
1331struct pci_dev *__ref pci_scan_single_device(struct pci_bus *bus, int devfn) 1354struct pci_dev *__ref pci_scan_single_device(struct pci_bus *bus, int devfn)
@@ -1644,13 +1667,13 @@ struct pci_bus *pci_create_root_bus(struct device *parent, int bus,
1644 char bus_addr[64]; 1667 char bus_addr[64];
1645 char *fmt; 1668 char *fmt;
1646 1669
1647
1648 b = pci_alloc_bus(); 1670 b = pci_alloc_bus();
1649 if (!b) 1671 if (!b)
1650 return NULL; 1672 return NULL;
1651 1673
1652 b->sysdata = sysdata; 1674 b->sysdata = sysdata;
1653 b->ops = ops; 1675 b->ops = ops;
1676 b->number = b->busn_res.start = bus;
1654 b2 = pci_find_bus(pci_domain_nr(b), bus); 1677 b2 = pci_find_bus(pci_domain_nr(b), bus);
1655 if (b2) { 1678 if (b2) {
1656 /* If we already got to this bus through a different bridge, ignore it */ 1679 /* If we already got to this bus through a different bridge, ignore it */
@@ -1685,8 +1708,6 @@ struct pci_bus *pci_create_root_bus(struct device *parent, int bus,
1685 /* Create legacy_io and legacy_mem files for this bus */ 1708 /* Create legacy_io and legacy_mem files for this bus */
1686 pci_create_legacy_files(b); 1709 pci_create_legacy_files(b);
1687 1710
1688 b->number = b->busn_res.start = bus;
1689
1690 if (parent) 1711 if (parent)
1691 dev_info(parent, "PCI host bridge to bus %s\n", dev_name(&b->dev)); 1712 dev_info(parent, "PCI host bridge to bus %s\n", dev_name(&b->dev));
1692 else 1713 else