aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pci/setup-bus.c
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/pci/setup-bus.c
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/pci/setup-bus.c')
-rw-r--r--drivers/pci/setup-bus.c151
1 files changed, 77 insertions, 74 deletions
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