aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pci
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
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')
-rw-r--r--drivers/pci/bus.c78
-rw-r--r--drivers/pci/iov.c9
-rw-r--r--drivers/pci/pci.h1
-rw-r--r--drivers/pci/probe.c35
4 files changed, 41 insertions, 82 deletions
diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c
index c8709c6fdb7c..8647dc6f52d0 100644
--- a/drivers/pci/bus.c
+++ b/drivers/pci/bus.c
@@ -161,73 +161,35 @@ pci_bus_alloc_resource(struct pci_bus *bus, struct resource *res,
161void __weak pcibios_resource_survey_bus(struct pci_bus *bus) { } 161void __weak pcibios_resource_survey_bus(struct pci_bus *bus) { }
162 162
163/** 163/**
164 * pci_bus_add_device - add a single device 164 * pci_bus_add_device - start driver for a single device
165 * @dev: device to add 165 * @dev: device to add
166 * 166 *
167 * This adds a single pci device to the global 167 * This adds add sysfs entries and start device drivers
168 * device list and adds sysfs and procfs entries
169 */ 168 */
170int pci_bus_add_device(struct pci_dev *dev) 169int pci_bus_add_device(struct pci_dev *dev)
171{ 170{
172 int retval; 171 int retval;
173 172
174 pci_fixup_device(pci_fixup_final, dev); 173 /*
175 174 * Can not put in pci_device_add yet because resources
176 retval = pcibios_add_device(dev); 175 * are not assigned yet for some devices.
177 if (retval) 176 */
178 return retval; 177 pci_create_sysfs_dev_files(dev);
179
180 dev->match_driver = false;
181 retval = device_add(&dev->dev);
182 if (retval)
183 return retval;
184 178
185 dev->match_driver = true; 179 dev->match_driver = true;
186 retval = device_attach(&dev->dev); 180 retval = device_attach(&dev->dev);
187 WARN_ON(retval < 0); 181 WARN_ON(retval < 0);
188 182
189 dev->is_added = 1; 183 dev->is_added = 1;
190 pci_proc_attach_device(dev);
191 pci_create_sysfs_dev_files(dev);
192 return 0;
193}
194
195/**
196 * pci_bus_add_child - add a child bus
197 * @bus: bus to add
198 *
199 * This adds sysfs entries for a single bus
200 */
201int pci_bus_add_child(struct pci_bus *bus)
202{
203 int retval;
204
205 if (bus->bridge)
206 bus->dev.parent = bus->bridge;
207
208 retval = device_register(&bus->dev);
209 if (retval)
210 return retval;
211 184
212 bus->is_added = 1; 185 return 0;
213
214 /* Create legacy_io and legacy_mem files for this bus */
215 pci_create_legacy_files(bus);
216
217 return retval;
218} 186}
219 187
220/** 188/**
221 * pci_bus_add_devices - insert newly discovered PCI devices 189 * pci_bus_add_devices - start driver for PCI devices
222 * @bus: bus to check for new devices 190 * @bus: bus to check for new devices
223 * 191 *
224 * Add newly discovered PCI devices (which are on the bus->devices 192 * Start driver for PCI devices and add some sysfs entries.
225 * list) to the global PCI device list, add the sysfs and procfs
226 * entries. Where a bridge is found, add the discovered bus to
227 * the parents list of child buses, and recurse (breadth-first
228 * to be compatible with 2.4)
229 *
230 * Call hotplug for each new devices.
231 */ 193 */
232void pci_bus_add_devices(const struct pci_bus *bus) 194void pci_bus_add_devices(const struct pci_bus *bus)
233{ 195{
@@ -240,36 +202,20 @@ void pci_bus_add_devices(const struct pci_bus *bus)
240 if (dev->is_added) 202 if (dev->is_added)
241 continue; 203 continue;
242 retval = pci_bus_add_device(dev); 204 retval = pci_bus_add_device(dev);
243 if (retval)
244 dev_err(&dev->dev, "Error adding device, continuing\n");
245 } 205 }
246 206
247 list_for_each_entry(dev, &bus->devices, bus_list) { 207 list_for_each_entry(dev, &bus->devices, bus_list) {
248 BUG_ON(!dev->is_added); 208 BUG_ON(!dev->is_added);
249 209
250 child = dev->subordinate; 210 child = dev->subordinate;
251 /* 211
252 * If there is an unattached subordinate bus, attach
253 * it and then scan for unattached PCI devices.
254 */
255 if (!child) 212 if (!child)
256 continue; 213 continue;
257 if (list_empty(&child->node)) {
258 down_write(&pci_bus_sem);
259 list_add_tail(&child->node, &dev->bus->children);
260 up_write(&pci_bus_sem);
261 }
262 pci_bus_add_devices(child); 214 pci_bus_add_devices(child);
263 215
264 /*
265 * register the bus with sysfs as the parent is now
266 * properly registered.
267 */
268 if (child->is_added) 216 if (child->is_added)
269 continue; 217 continue;
270 retval = pci_bus_add_child(child); 218 child->is_added = 1;
271 if (retval)
272 dev_err(&dev->dev, "Error adding bus, continuing\n");
273 } 219 }
274} 220}
275 221
diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c
index bafd2bbcaf65..f8720afe0537 100644
--- a/drivers/pci/iov.c
+++ b/drivers/pci/iov.c
@@ -48,12 +48,7 @@ static struct pci_bus *virtfn_add_bus(struct pci_bus *bus, int busnr)
48 return NULL; 48 return NULL;
49 49
50 pci_bus_insert_busn_res(child, busnr, busnr); 50 pci_bus_insert_busn_res(child, busnr, busnr);
51 child->dev.parent = bus->bridge; 51 bus->is_added = 1;
52 rc = pci_bus_add_child(child);
53 if (rc) {
54 pci_remove_bus(child);
55 return NULL;
56 }
57 52
58 return child; 53 return child;
59} 54}
@@ -123,8 +118,6 @@ static int virtfn_add(struct pci_dev *dev, int id, int reset)
123 virtfn->is_virtfn = 1; 118 virtfn->is_virtfn = 1;
124 119
125 rc = pci_bus_add_device(virtfn); 120 rc = pci_bus_add_device(virtfn);
126 if (rc)
127 goto failed1;
128 sprintf(buf, "virtfn%u", id); 121 sprintf(buf, "virtfn%u", id);
129 rc = sysfs_create_link(&dev->dev.kobj, &virtfn->dev.kobj, buf); 122 rc = sysfs_create_link(&dev->dev.kobj, &virtfn->dev.kobj, buf);
130 if (rc) 123 if (rc)
diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index adfd172c5b9b..d295e7b0e64f 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -203,7 +203,6 @@ extern int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
203 struct resource *res, unsigned int reg); 203 struct resource *res, unsigned int reg);
204extern int pci_resource_bar(struct pci_dev *dev, int resno, 204extern int pci_resource_bar(struct pci_dev *dev, int resno,
205 enum pci_bar_type *type); 205 enum pci_bar_type *type);
206extern int pci_bus_add_child(struct pci_bus *bus);
207extern void pci_enable_ari(struct pci_dev *dev); 206extern void pci_enable_ari(struct pci_dev *dev);
208/** 207/**
209 * pci_ari_enabled - query ARI forwarding status 208 * pci_ari_enabled - query ARI forwarding status
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