aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYijing Wang <wangyijing@huawei.com>2015-03-08 22:33:58 -0400
committerBjorn Helgaas <bhelgaas@google.com>2015-03-12 16:04:01 -0400
commitc90570d9511d42421c85709b46bffd366185d835 (patch)
tree63febf1d38c816fa7c540a8238f7436a9a483813
parentc517d838eb7d07bbe9507871fab3931deccff539 (diff)
PCI: Assign resources before drivers claim devices (pci_scan_bus())
Previously, pci_scan_bus() created a root PCI bus, enumerated the devices on it, and called pci_bus_add_devices(), which made the devices available for drivers to claim them. Most callers assigned resources to devices after pci_scan_bus() returns, which may be after drivers have claimed the devices. This is incorrect; the PCI core should not change device resources while a driver is managing the device. Remove pci_bus_add_devices() from pci_scan_bus() and do it after any resource assignment in the callers. [bhelgaas: changelog, check for failure in mcf_pci_init()] Signed-off-by: Yijing Wang <wangyijing@huawei.com> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com> CC: "David S. Miller" <davem@davemloft.net> CC: Geert Uytterhoeven <geert@linux-m68k.org> CC: Guan Xuetao <gxt@mprc.pku.edu.cn> CC: Richard Henderson <rth@twiddle.net> CC: Ivan Kokshaysky <ink@jurassic.park.msu.ru> CC: Matt Turner <mattst88@gmail.com>
-rw-r--r--arch/alpha/kernel/sys_nautilus.c4
-rw-r--r--arch/m68k/coldfire/pci.c4
-rw-r--r--arch/sparc/kernel/pcic.c4
-rw-r--r--arch/unicore32/kernel/pci.c9
-rw-r--r--drivers/pci/hotplug/ibmphp_core.c8
-rw-r--r--drivers/pci/probe.c1
6 files changed, 19 insertions, 11 deletions
diff --git a/arch/alpha/kernel/sys_nautilus.c b/arch/alpha/kernel/sys_nautilus.c
index 837c0fa58317..700686d04869 100644
--- a/arch/alpha/kernel/sys_nautilus.c
+++ b/arch/alpha/kernel/sys_nautilus.c
@@ -207,6 +207,9 @@ nautilus_init_pci(void)
207 207
208 /* Scan our single hose. */ 208 /* Scan our single hose. */
209 bus = pci_scan_bus(0, alpha_mv.pci_ops, hose); 209 bus = pci_scan_bus(0, alpha_mv.pci_ops, hose);
210 if (!bus)
211 return;
212
210 hose->bus = bus; 213 hose->bus = bus;
211 pcibios_claim_one_bus(bus); 214 pcibios_claim_one_bus(bus);
212 215
@@ -253,6 +256,7 @@ nautilus_init_pci(void)
253 for the root bus, so just clear it. */ 256 for the root bus, so just clear it. */
254 bus->self = NULL; 257 bus->self = NULL;
255 pci_fixup_irqs(alpha_mv.pci_swizzle, alpha_mv.pci_map_irq); 258 pci_fixup_irqs(alpha_mv.pci_swizzle, alpha_mv.pci_map_irq);
259 pci_bus_add_devices(bus);
256} 260}
257 261
258/* 262/*
diff --git a/arch/m68k/coldfire/pci.c b/arch/m68k/coldfire/pci.c
index df9679238b6d..821de928dc3f 100644
--- a/arch/m68k/coldfire/pci.c
+++ b/arch/m68k/coldfire/pci.c
@@ -313,12 +313,16 @@ static int __init mcf_pci_init(void)
313 schedule_timeout(msecs_to_jiffies(200)); 313 schedule_timeout(msecs_to_jiffies(200));
314 314
315 rootbus = pci_scan_bus(0, &mcf_pci_ops, NULL); 315 rootbus = pci_scan_bus(0, &mcf_pci_ops, NULL);
316 if (!rootbus)
317 return -ENODEV;
318
316 rootbus->resource[0] = &mcf_pci_io; 319 rootbus->resource[0] = &mcf_pci_io;
317 rootbus->resource[1] = &mcf_pci_mem; 320 rootbus->resource[1] = &mcf_pci_mem;
318 321
319 pci_fixup_irqs(pci_common_swizzle, mcf_pci_map_irq); 322 pci_fixup_irqs(pci_common_swizzle, mcf_pci_map_irq);
320 pci_bus_size_bridges(rootbus); 323 pci_bus_size_bridges(rootbus);
321 pci_bus_assign_resources(rootbus); 324 pci_bus_assign_resources(rootbus);
325 pci_bus_add_devices(rootbus);
322 return 0; 326 return 0;
323} 327}
324 328
diff --git a/arch/sparc/kernel/pcic.c b/arch/sparc/kernel/pcic.c
index 6cc78c213c01..24384e1dc33d 100644
--- a/arch/sparc/kernel/pcic.c
+++ b/arch/sparc/kernel/pcic.c
@@ -391,12 +391,16 @@ static void __init pcic_pbm_scan_bus(struct linux_pcic *pcic)
391 struct linux_pbm_info *pbm = &pcic->pbm; 391 struct linux_pbm_info *pbm = &pcic->pbm;
392 392
393 pbm->pci_bus = pci_scan_bus(pbm->pci_first_busno, &pcic_ops, pbm); 393 pbm->pci_bus = pci_scan_bus(pbm->pci_first_busno, &pcic_ops, pbm);
394 if (!pbm->pci_bus)
395 return;
396
394#if 0 /* deadwood transplanted from sparc64 */ 397#if 0 /* deadwood transplanted from sparc64 */
395 pci_fill_in_pbm_cookies(pbm->pci_bus, pbm, pbm->prom_node); 398 pci_fill_in_pbm_cookies(pbm->pci_bus, pbm, pbm->prom_node);
396 pci_record_assignments(pbm, pbm->pci_bus); 399 pci_record_assignments(pbm, pbm->pci_bus);
397 pci_assign_unassigned(pbm, pbm->pci_bus); 400 pci_assign_unassigned(pbm, pbm->pci_bus);
398 pci_fixup_irq(pbm, pbm->pci_bus); 401 pci_fixup_irq(pbm, pbm->pci_bus);
399#endif 402#endif
403 pci_bus_add_devices(pbm->pci_bus);
400} 404}
401 405
402/* 406/*
diff --git a/arch/unicore32/kernel/pci.c b/arch/unicore32/kernel/pci.c
index 374a055a8e6b..d45fa5f3e9c4 100644
--- a/arch/unicore32/kernel/pci.c
+++ b/arch/unicore32/kernel/pci.c
@@ -266,17 +266,10 @@ static int __init pci_common_init(void)
266 pci_fixup_irqs(pci_common_swizzle, pci_puv3_map_irq); 266 pci_fixup_irqs(pci_common_swizzle, pci_puv3_map_irq);
267 267
268 if (!pci_has_flag(PCI_PROBE_ONLY)) { 268 if (!pci_has_flag(PCI_PROBE_ONLY)) {
269 /*
270 * Size the bridge windows.
271 */
272 pci_bus_size_bridges(puv3_bus); 269 pci_bus_size_bridges(puv3_bus);
273
274 /*
275 * Assign resources.
276 */
277 pci_bus_assign_resources(puv3_bus); 270 pci_bus_assign_resources(puv3_bus);
278 } 271 }
279 272 pci_bus_add_devices(puv3_bus);
280 return 0; 273 return 0;
281} 274}
282subsys_initcall(pci_common_init); 275subsys_initcall(pci_common_init);
diff --git a/drivers/pci/hotplug/ibmphp_core.c b/drivers/pci/hotplug/ibmphp_core.c
index 96c5c729cdbc..15302475f5b7 100644
--- a/drivers/pci/hotplug/ibmphp_core.c
+++ b/drivers/pci/hotplug/ibmphp_core.c
@@ -738,7 +738,7 @@ static void ibm_unconfigure_device(struct pci_func *func)
738 */ 738 */
739static u8 bus_structure_fixup(u8 busno) 739static u8 bus_structure_fixup(u8 busno)
740{ 740{
741 struct pci_bus *bus; 741 struct pci_bus *bus, *b;
742 struct pci_dev *dev; 742 struct pci_dev *dev;
743 u16 l; 743 u16 l;
744 744
@@ -765,7 +765,11 @@ static u8 bus_structure_fixup(u8 busno)
765 (l != 0x0000) && (l != 0xffff)) { 765 (l != 0x0000) && (l != 0xffff)) {
766 debug("%s - Inside bus_structure_fixup()\n", 766 debug("%s - Inside bus_structure_fixup()\n",
767 __func__); 767 __func__);
768 pci_scan_bus(busno, ibmphp_pci_bus->ops, NULL); 768 b = pci_scan_bus(busno, ibmphp_pci_bus->ops, NULL);
769 if (!b)
770 continue;
771
772 pci_bus_add_devices(b);
769 break; 773 break;
770 } 774 }
771 } 775 }
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index 8d2f400e96cb..88604f29d140 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -2123,7 +2123,6 @@ struct pci_bus *pci_scan_bus(int bus, struct pci_ops *ops,
2123 b = pci_create_root_bus(NULL, bus, ops, sysdata, &resources); 2123 b = pci_create_root_bus(NULL, bus, ops, sysdata, &resources);
2124 if (b) { 2124 if (b) {
2125 pci_scan_child_bus(b); 2125 pci_scan_child_bus(b);
2126 pci_bus_add_devices(b);
2127 } else { 2126 } else {
2128 pci_free_resource_list(&resources); 2127 pci_free_resource_list(&resources);
2129 } 2128 }