aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorBjorn Helgaas <bhelgaas@google.com>2013-08-26 17:40:03 -0400
committerBjorn Helgaas <bhelgaas@google.com>2013-08-26 17:40:03 -0400
commit1193725f543c92a77c73769bc2fbe48c53275f53 (patch)
tree71ef007260a1584f4f48d7a7118a3157d01eb5f7 /drivers
parent7d8c4a2c5ae6d76f1142fb052d698b3c40ce518c (diff)
parent39772038ea93e85ea4f1307ec9c1f48a063d89a0 (diff)
Merge branch 'pci/yinghai-assign-unassigned-v6' into next
* pci/yinghai-assign-unassigned-v6: PCI: Assign resources for hot-added host bridge more aggressively PCI: Move resource reallocation code to non-__init PCI: Delay enabling bridges until they're needed PCI: Assign resources on a per-bus basis PCI: Enable unassigned resource reallocation on per-bus basis PCI: Turn on reallocation for unassigned resources with host bridge offset PCI: Look for unassigned resources on per-bus basis PCI: Drop temporary variable in pci_assign_unassigned_resources()
Diffstat (limited to 'drivers')
-rw-r--r--drivers/acpi/pci_root.c5
-rw-r--r--drivers/parisc/lba_pci.c1
-rw-r--r--drivers/pci/bus.c19
-rw-r--r--drivers/pci/hotplug/acpiphp_glue.c1
-rw-r--r--drivers/pci/pci.c20
-rw-r--r--drivers/pci/probe.c1
-rw-r--r--drivers/pci/setup-bus.c151
-rw-r--r--drivers/pcmcia/cardbus.c1
8 files changed, 98 insertions, 101 deletions
diff --git a/drivers/acpi/pci_root.c b/drivers/acpi/pci_root.c
index 5917839321b8..ce04eb28e029 100644
--- a/drivers/acpi/pci_root.c
+++ b/drivers/acpi/pci_root.c
@@ -526,10 +526,7 @@ static int acpi_pci_root_add(struct acpi_device *device,
526 526
527 if (system_state != SYSTEM_BOOTING) { 527 if (system_state != SYSTEM_BOOTING) {
528 pcibios_resource_survey_bus(root->bus); 528 pcibios_resource_survey_bus(root->bus);
529 pci_assign_unassigned_bus_resources(root->bus); 529 pci_assign_unassigned_root_bus_resources(root->bus);
530
531 /* need to after hot-added ioapic is registered */
532 pci_enable_bridges(root->bus);
533 } 530 }
534 531
535 pci_bus_add_devices(root->bus); 532 pci_bus_add_devices(root->bus);
diff --git a/drivers/parisc/lba_pci.c b/drivers/parisc/lba_pci.c
index 19f6f70c67d3..37e71ff6408d 100644
--- a/drivers/parisc/lba_pci.c
+++ b/drivers/parisc/lba_pci.c
@@ -1590,7 +1590,6 @@ lba_driver_probe(struct parisc_device *dev)
1590 lba_dump_res(&lba_dev->hba.lmmio_space, 2); 1590 lba_dump_res(&lba_dev->hba.lmmio_space, 2);
1591#endif 1591#endif
1592 } 1592 }
1593 pci_enable_bridges(lba_bus);
1594 1593
1595 /* 1594 /*
1596 ** Once PCI register ops has walked the bus, access to config 1595 ** Once PCI register ops has walked the bus, access to config
diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c
index b1ff02ab4f13..fc1b74013743 100644
--- a/drivers/pci/bus.c
+++ b/drivers/pci/bus.c
@@ -216,24 +216,6 @@ void pci_bus_add_devices(const struct pci_bus *bus)
216 } 216 }
217} 217}
218 218
219void pci_enable_bridges(struct pci_bus *bus)
220{
221 struct pci_dev *dev;
222 int retval;
223
224 list_for_each_entry(dev, &bus->devices, bus_list) {
225 if (dev->subordinate) {
226 if (!pci_is_enabled(dev)) {
227 retval = pci_enable_device(dev);
228 if (retval)
229 dev_err(&dev->dev, "Error enabling bridge (%d), continuing\n", retval);
230 pci_set_master(dev);
231 }
232 pci_enable_bridges(dev->subordinate);
233 }
234 }
235}
236
237/** pci_walk_bus - walk devices on/under bus, calling callback. 219/** pci_walk_bus - walk devices on/under bus, calling callback.
238 * @top bus whose devices should be walked 220 * @top bus whose devices should be walked
239 * @cb callback to be called for each device found 221 * @cb callback to be called for each device found
@@ -301,4 +283,3 @@ EXPORT_SYMBOL(pci_bus_put);
301EXPORT_SYMBOL(pci_bus_alloc_resource); 283EXPORT_SYMBOL(pci_bus_alloc_resource);
302EXPORT_SYMBOL_GPL(pci_bus_add_device); 284EXPORT_SYMBOL_GPL(pci_bus_add_device);
303EXPORT_SYMBOL(pci_bus_add_devices); 285EXPORT_SYMBOL(pci_bus_add_devices);
304EXPORT_SYMBOL(pci_enable_bridges);
diff --git a/drivers/pci/hotplug/acpiphp_glue.c b/drivers/pci/hotplug/acpiphp_glue.c
index 59df8575a48c..52dee9d31e1c 100644
--- a/drivers/pci/hotplug/acpiphp_glue.c
+++ b/drivers/pci/hotplug/acpiphp_glue.c
@@ -723,7 +723,6 @@ static int __ref enable_device(struct acpiphp_slot *slot)
723 acpiphp_sanitize_bus(bus); 723 acpiphp_sanitize_bus(bus);
724 acpiphp_set_hpp_values(bus); 724 acpiphp_set_hpp_values(bus);
725 acpiphp_set_acpi_region(slot); 725 acpiphp_set_acpi_region(slot);
726 pci_enable_bridges(bus);
727 726
728 list_for_each_entry(dev, &bus->devices, bus_list) { 727 list_for_each_entry(dev, &bus->devices, bus_list) {
729 /* Assume that newly added devices are powered on already. */ 728 /* Assume that newly added devices are powered on already. */
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 10e3c4e15178..d3fdce8f3d65 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -1146,6 +1146,24 @@ int pci_reenable_device(struct pci_dev *dev)
1146 return 0; 1146 return 0;
1147} 1147}
1148 1148
1149static void pci_enable_bridge(struct pci_dev *dev)
1150{
1151 int retval;
1152
1153 if (!dev)
1154 return;
1155
1156 pci_enable_bridge(dev->bus->self);
1157
1158 if (pci_is_enabled(dev))
1159 return;
1160 retval = pci_enable_device(dev);
1161 if (retval)
1162 dev_err(&dev->dev, "Error enabling bridge (%d), continuing\n",
1163 retval);
1164 pci_set_master(dev);
1165}
1166
1149static int pci_enable_device_flags(struct pci_dev *dev, unsigned long flags) 1167static int pci_enable_device_flags(struct pci_dev *dev, unsigned long flags)
1150{ 1168{
1151 int err; 1169 int err;
@@ -1166,6 +1184,8 @@ static int pci_enable_device_flags(struct pci_dev *dev, unsigned long flags)
1166 if (atomic_inc_return(&dev->enable_cnt) > 1) 1184 if (atomic_inc_return(&dev->enable_cnt) > 1)
1167 return 0; /* already enabled */ 1185 return 0; /* already enabled */
1168 1186
1187 pci_enable_bridge(dev->bus->self);
1188
1169 /* only skip sriov related */ 1189 /* only skip sriov related */
1170 for (i = 0; i <= PCI_ROM_RESOURCE; i++) 1190 for (i = 0; i <= PCI_ROM_RESOURCE; i++)
1171 if (dev->resource[i].flags & flags) 1191 if (dev->resource[i].flags & flags)
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index cf57fe79450a..4ab388a6cc26 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -1979,7 +1979,6 @@ unsigned int __ref pci_rescan_bus(struct pci_bus *bus)
1979 1979
1980 max = pci_scan_child_bus(bus); 1980 max = pci_scan_child_bus(bus);
1981 pci_assign_unassigned_bus_resources(bus); 1981 pci_assign_unassigned_bus_resources(bus);
1982 pci_enable_bridges(bus);
1983 pci_bus_add_devices(bus); 1982 pci_bus_add_devices(bus);
1984 1983
1985 return max; 1984 return max;
diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index 8333c92c2027..9be359594b05 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -1297,7 +1297,7 @@ static void pci_bus_dump_resources(struct pci_bus *bus)
1297 } 1297 }
1298} 1298}
1299 1299
1300static int __init pci_bus_get_depth(struct pci_bus *bus) 1300static int pci_bus_get_depth(struct pci_bus *bus)
1301{ 1301{
1302 int depth = 0; 1302 int depth = 0;
1303 struct pci_bus *child_bus; 1303 struct pci_bus *child_bus;
@@ -1312,21 +1312,6 @@ static int __init pci_bus_get_depth(struct pci_bus *bus)
1312 1312
1313 return depth; 1313 return depth;
1314} 1314}
1315static int __init pci_get_max_depth(void)
1316{
1317 int depth = 0;
1318 struct pci_bus *bus;
1319
1320 list_for_each_entry(bus, &pci_root_buses, node) {
1321 int ret;
1322
1323 ret = pci_bus_get_depth(bus);
1324 if (ret > depth)
1325 depth = ret;
1326 }
1327
1328 return depth;
1329}
1330 1315
1331/* 1316/*
1332 * -1: undefined, will auto detect later 1317 * -1: undefined, will auto detect later
@@ -1343,7 +1328,7 @@ enum enable_type {
1343 auto_enabled, 1328 auto_enabled,
1344}; 1329};
1345 1330
1346static enum enable_type pci_realloc_enable __initdata = undefined; 1331static enum enable_type pci_realloc_enable = undefined;
1347void __init pci_realloc_get_opt(char *str) 1332void __init pci_realloc_get_opt(char *str)
1348{ 1333{
1349 if (!strncmp(str, "off", 3)) 1334 if (!strncmp(str, "off", 3))
@@ -1351,45 +1336,64 @@ void __init pci_realloc_get_opt(char *str)
1351 else if (!strncmp(str, "on", 2)) 1336 else if (!strncmp(str, "on", 2))
1352 pci_realloc_enable = user_enabled; 1337 pci_realloc_enable = user_enabled;
1353} 1338}
1354static bool __init pci_realloc_enabled(void) 1339static bool pci_realloc_enabled(enum enable_type enable)
1355{ 1340{
1356 return pci_realloc_enable >= user_enabled; 1341 return enable >= user_enabled;
1357} 1342}
1358 1343
1359static void __init pci_realloc_detect(void)
1360{
1361#if defined(CONFIG_PCI_IOV) && defined(CONFIG_PCI_REALLOC_ENABLE_AUTO) 1344#if defined(CONFIG_PCI_IOV) && defined(CONFIG_PCI_REALLOC_ENABLE_AUTO)
1362 struct pci_dev *dev = NULL; 1345static int iov_resources_unassigned(struct pci_dev *dev, void *data)
1363 1346{
1364 if (pci_realloc_enable != undefined) 1347 int i;
1365 return; 1348 bool *unassigned = data;
1366
1367 for_each_pci_dev(dev) {
1368 int i;
1369 1349
1370 for (i = PCI_IOV_RESOURCES; i <= PCI_IOV_RESOURCE_END; i++) { 1350 for (i = PCI_IOV_RESOURCES; i <= PCI_IOV_RESOURCE_END; i++) {
1371 struct resource *r = &dev->resource[i]; 1351 struct resource *r = &dev->resource[i];
1352 struct pci_bus_region region;
1372 1353
1373 /* Not assigned, or rejected by kernel ? */ 1354 /* Not assigned or rejected by kernel? */
1374 if (r->flags && !r->start) { 1355 if (!r->flags)
1375 pci_realloc_enable = auto_enabled; 1356 continue;
1376 1357
1377 return; 1358 pcibios_resource_to_bus(dev, &region, r);
1378 } 1359 if (!region.start) {
1360 *unassigned = true;
1361 return 1; /* return early from pci_walk_bus() */
1379 } 1362 }
1380 } 1363 }
1381#endif 1364
1365 return 0;
1366}
1367
1368static enum enable_type pci_realloc_detect(struct pci_bus *bus,
1369 enum enable_type enable_local)
1370{
1371 bool unassigned = false;
1372
1373 if (enable_local != undefined)
1374 return enable_local;
1375
1376 pci_walk_bus(bus, iov_resources_unassigned, &unassigned);
1377 if (unassigned)
1378 return auto_enabled;
1379
1380 return enable_local;
1381}
1382#else
1383static enum enable_type pci_realloc_detect(struct pci_bus *bus,
1384 enum enable_type enable_local)
1385{
1386 return enable_local;
1382} 1387}
1388#endif
1383 1389
1384/* 1390/*
1385 * first try will not touch pci bridge res 1391 * first try will not touch pci bridge res
1386 * second and later try will clear small leaf bridge res 1392 * second and later try will clear small leaf bridge res
1387 * will stop till to the max deepth if can not find good one 1393 * will stop till to the max deepth if can not find good one
1388 */ 1394 */
1389void __init 1395void pci_assign_unassigned_root_bus_resources(struct pci_bus *bus)
1390pci_assign_unassigned_resources(void)
1391{ 1396{
1392 struct pci_bus *bus;
1393 LIST_HEAD(realloc_head); /* list of resources that 1397 LIST_HEAD(realloc_head); /* list of resources that
1394 want additional resources */ 1398 want additional resources */
1395 struct list_head *add_list = NULL; 1399 struct list_head *add_list = NULL;
@@ -1400,15 +1404,17 @@ pci_assign_unassigned_resources(void)
1400 unsigned long type_mask = IORESOURCE_IO | IORESOURCE_MEM | 1404 unsigned long type_mask = IORESOURCE_IO | IORESOURCE_MEM |
1401 IORESOURCE_PREFETCH; 1405 IORESOURCE_PREFETCH;
1402 int pci_try_num = 1; 1406 int pci_try_num = 1;
1407 enum enable_type enable_local;
1403 1408
1404 /* don't realloc if asked to do so */ 1409 /* don't realloc if asked to do so */
1405 pci_realloc_detect(); 1410 enable_local = pci_realloc_detect(bus, pci_realloc_enable);
1406 if (pci_realloc_enabled()) { 1411 if (pci_realloc_enabled(enable_local)) {
1407 int max_depth = pci_get_max_depth(); 1412 int max_depth = pci_bus_get_depth(bus);
1408 1413
1409 pci_try_num = max_depth + 1; 1414 pci_try_num = max_depth + 1;
1410 printk(KERN_DEBUG "PCI: max bus depth: %d pci_try_num: %d\n", 1415 dev_printk(KERN_DEBUG, &bus->dev,
1411 max_depth, pci_try_num); 1416 "max bus depth: %d pci_try_num: %d\n",
1417 max_depth, pci_try_num);
1412 } 1418 }
1413 1419
1414again: 1420again:
@@ -1420,32 +1426,30 @@ again:
1420 add_list = &realloc_head; 1426 add_list = &realloc_head;
1421 /* Depth first, calculate sizes and alignments of all 1427 /* Depth first, calculate sizes and alignments of all
1422 subordinate buses. */ 1428 subordinate buses. */
1423 list_for_each_entry(bus, &pci_root_buses, node) 1429 __pci_bus_size_bridges(bus, add_list);
1424 __pci_bus_size_bridges(bus, add_list);
1425 1430
1426 /* Depth last, allocate resources and update the hardware. */ 1431 /* Depth last, allocate resources and update the hardware. */
1427 list_for_each_entry(bus, &pci_root_buses, node) 1432 __pci_bus_assign_resources(bus, add_list, &fail_head);
1428 __pci_bus_assign_resources(bus, add_list, &fail_head);
1429 if (add_list) 1433 if (add_list)
1430 BUG_ON(!list_empty(add_list)); 1434 BUG_ON(!list_empty(add_list));
1431 tried_times++; 1435 tried_times++;
1432 1436
1433 /* any device complain? */ 1437 /* any device complain? */
1434 if (list_empty(&fail_head)) 1438 if (list_empty(&fail_head))
1435 goto enable_and_dump; 1439 goto dump;
1436 1440
1437 if (tried_times >= pci_try_num) { 1441 if (tried_times >= pci_try_num) {
1438 if (pci_realloc_enable == undefined) 1442 if (enable_local == undefined)
1439 printk(KERN_INFO "Some PCI device resources are unassigned, try booting with pci=realloc\n"); 1443 dev_info(&bus->dev, "Some PCI device resources are unassigned, try booting with pci=realloc\n");
1440 else if (pci_realloc_enable == auto_enabled) 1444 else if (enable_local == auto_enabled)
1441 printk(KERN_INFO "Automatically enabled pci realloc, if you have problem, try booting with pci=realloc=off\n"); 1445 dev_info(&bus->dev, "Automatically enabled pci realloc, if you have problem, try booting with pci=realloc=off\n");
1442 1446
1443 free_list(&fail_head); 1447 free_list(&fail_head);
1444 goto enable_and_dump; 1448 goto dump;
1445 } 1449 }
1446 1450
1447 printk(KERN_DEBUG "PCI: No. %d try to assign unassigned res\n", 1451 dev_printk(KERN_DEBUG, &bus->dev,
1448 tried_times + 1); 1452 "No. %d try to assign unassigned res\n", tried_times + 1);
1449 1453
1450 /* third times and later will not check if it is leaf */ 1454 /* third times and later will not check if it is leaf */
1451 if ((tried_times + 1) > 2) 1455 if ((tried_times + 1) > 2)
@@ -1455,12 +1459,11 @@ again:
1455 * Try to release leaf bridge's resources that doesn't fit resource of 1459 * Try to release leaf bridge's resources that doesn't fit resource of
1456 * child device under that bridge 1460 * child device under that bridge
1457 */ 1461 */
1458 list_for_each_entry(fail_res, &fail_head, list) { 1462 list_for_each_entry(fail_res, &fail_head, list)
1459 bus = fail_res->dev->bus; 1463 pci_bus_release_bridge_resources(fail_res->dev->bus,
1460 pci_bus_release_bridge_resources(bus,
1461 fail_res->flags & type_mask, 1464 fail_res->flags & type_mask,
1462 rel_type); 1465 rel_type);
1463 } 1466
1464 /* restore size and flags */ 1467 /* restore size and flags */
1465 list_for_each_entry(fail_res, &fail_head, list) { 1468 list_for_each_entry(fail_res, &fail_head, list) {
1466 struct resource *res = fail_res->res; 1469 struct resource *res = fail_res->res;
@@ -1475,14 +1478,17 @@ again:
1475 1478
1476 goto again; 1479 goto again;
1477 1480
1478enable_and_dump: 1481dump:
1479 /* Depth last, update the hardware. */
1480 list_for_each_entry(bus, &pci_root_buses, node)
1481 pci_enable_bridges(bus);
1482
1483 /* dump the resource on buses */ 1482 /* dump the resource on buses */
1484 list_for_each_entry(bus, &pci_root_buses, node) 1483 pci_bus_dump_resources(bus);
1485 pci_bus_dump_resources(bus); 1484}
1485
1486void __init pci_assign_unassigned_resources(void)
1487{
1488 struct pci_bus *root_bus;
1489
1490 list_for_each_entry(root_bus, &pci_root_buses, node)
1491 pci_assign_unassigned_root_bus_resources(root_bus);
1486} 1492}
1487 1493
1488void pci_assign_unassigned_bridge_resources(struct pci_dev *bridge) 1494void pci_assign_unassigned_bridge_resources(struct pci_dev *bridge)
@@ -1519,13 +1525,11 @@ again:
1519 * Try to release leaf bridge's resources that doesn't fit resource of 1525 * Try to release leaf bridge's resources that doesn't fit resource of
1520 * child device under that bridge 1526 * child device under that bridge
1521 */ 1527 */
1522 list_for_each_entry(fail_res, &fail_head, list) { 1528 list_for_each_entry(fail_res, &fail_head, list)
1523 struct pci_bus *bus = fail_res->dev->bus; 1529 pci_bus_release_bridge_resources(fail_res->dev->bus,
1524 unsigned long flags = fail_res->flags; 1530 fail_res->flags & type_mask,
1525
1526 pci_bus_release_bridge_resources(bus, flags & type_mask,
1527 whole_subtree); 1531 whole_subtree);
1528 } 1532
1529 /* restore size and flags */ 1533 /* restore size and flags */
1530 list_for_each_entry(fail_res, &fail_head, list) { 1534 list_for_each_entry(fail_res, &fail_head, list) {
1531 struct resource *res = fail_res->res; 1535 struct resource *res = fail_res->res;
@@ -1545,7 +1549,6 @@ enable_all:
1545 if (retval) 1549 if (retval)
1546 dev_err(&bridge->dev, "Error reenabling bridge (%d)\n", retval); 1550 dev_err(&bridge->dev, "Error reenabling bridge (%d)\n", retval);
1547 pci_set_master(bridge); 1551 pci_set_master(bridge);
1548 pci_enable_bridges(parent);
1549} 1552}
1550EXPORT_SYMBOL_GPL(pci_assign_unassigned_bridge_resources); 1553EXPORT_SYMBOL_GPL(pci_assign_unassigned_bridge_resources);
1551 1554
diff --git a/drivers/pcmcia/cardbus.c b/drivers/pcmcia/cardbus.c
index 9d3ac998fc1f..b2a98cdbd0d2 100644
--- a/drivers/pcmcia/cardbus.c
+++ b/drivers/pcmcia/cardbus.c
@@ -91,7 +91,6 @@ int __ref cb_alloc(struct pcmcia_socket *s)
91 if (s->tune_bridge) 91 if (s->tune_bridge)
92 s->tune_bridge(s, bus); 92 s->tune_bridge(s, bus);
93 93
94 pci_enable_bridges(bus);
95 pci_bus_add_devices(bus); 94 pci_bus_add_devices(bus);
96 95
97 return 0; 96 return 0;