diff options
Diffstat (limited to 'drivers/pci/pci.c')
-rw-r--r-- | drivers/pci/pci.c | 200 |
1 files changed, 189 insertions, 11 deletions
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index fd47ac0c4730..03fd59e80fef 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c | |||
@@ -406,6 +406,13 @@ pci_set_power_state(struct pci_dev *dev, pci_power_t state) | |||
406 | if ((state == PCI_D1 || state == PCI_D2) && pci_no_d1d2(dev)) | 406 | if ((state == PCI_D1 || state == PCI_D2) && pci_no_d1d2(dev)) |
407 | return 0; | 407 | return 0; |
408 | 408 | ||
409 | /* find PCI PM capability in list */ | ||
410 | pm = pci_find_capability(dev, PCI_CAP_ID_PM); | ||
411 | |||
412 | /* abort if the device doesn't support PM capabilities */ | ||
413 | if (!pm) | ||
414 | return -EIO; | ||
415 | |||
409 | /* Validate current state: | 416 | /* Validate current state: |
410 | * Can enter D0 from any state, but if we can only go deeper | 417 | * Can enter D0 from any state, but if we can only go deeper |
411 | * to sleep if we're already in a low power state | 418 | * to sleep if we're already in a low power state |
@@ -418,13 +425,6 @@ pci_set_power_state(struct pci_dev *dev, pci_power_t state) | |||
418 | return 0; /* we're already there */ | 425 | return 0; /* we're already there */ |
419 | 426 | ||
420 | 427 | ||
421 | /* find PCI PM capability in list */ | ||
422 | pm = pci_find_capability(dev, PCI_CAP_ID_PM); | ||
423 | |||
424 | /* abort if the device doesn't support PM capabilities */ | ||
425 | if (!pm) | ||
426 | return -EIO; | ||
427 | |||
428 | pci_read_config_word(dev,pm + PCI_PM_PMC,&pmc); | 428 | pci_read_config_word(dev,pm + PCI_PM_PMC,&pmc); |
429 | if ((pmc & PCI_PM_CAP_VER_MASK) > 3) { | 429 | if ((pmc & PCI_PM_CAP_VER_MASK) > 3) { |
430 | printk(KERN_DEBUG | 430 | printk(KERN_DEBUG |
@@ -1186,6 +1186,11 @@ int pci_set_mwi(struct pci_dev *dev) | |||
1186 | return 0; | 1186 | return 0; |
1187 | } | 1187 | } |
1188 | 1188 | ||
1189 | int pci_try_set_mwi(struct pci_dev *dev) | ||
1190 | { | ||
1191 | return 0; | ||
1192 | } | ||
1193 | |||
1189 | void pci_clear_mwi(struct pci_dev *dev) | 1194 | void pci_clear_mwi(struct pci_dev *dev) |
1190 | { | 1195 | { |
1191 | } | 1196 | } |
@@ -1242,9 +1247,7 @@ pci_set_cacheline_size(struct pci_dev *dev) | |||
1242 | * pci_set_mwi - enables memory-write-invalidate PCI transaction | 1247 | * pci_set_mwi - enables memory-write-invalidate PCI transaction |
1243 | * @dev: the PCI device for which MWI is enabled | 1248 | * @dev: the PCI device for which MWI is enabled |
1244 | * | 1249 | * |
1245 | * Enables the Memory-Write-Invalidate transaction in %PCI_COMMAND, | 1250 | * Enables the Memory-Write-Invalidate transaction in %PCI_COMMAND. |
1246 | * and then calls @pcibios_set_mwi to do the needed arch specific | ||
1247 | * operations or a generic mwi-prep function. | ||
1248 | * | 1251 | * |
1249 | * RETURNS: An appropriate -ERRNO error value on error, or zero for success. | 1252 | * RETURNS: An appropriate -ERRNO error value on error, or zero for success. |
1250 | */ | 1253 | */ |
@@ -1260,7 +1263,8 @@ pci_set_mwi(struct pci_dev *dev) | |||
1260 | 1263 | ||
1261 | pci_read_config_word(dev, PCI_COMMAND, &cmd); | 1264 | pci_read_config_word(dev, PCI_COMMAND, &cmd); |
1262 | if (! (cmd & PCI_COMMAND_INVALIDATE)) { | 1265 | if (! (cmd & PCI_COMMAND_INVALIDATE)) { |
1263 | pr_debug("PCI: Enabling Mem-Wr-Inval for device %s\n", pci_name(dev)); | 1266 | pr_debug("PCI: Enabling Mem-Wr-Inval for device %s\n", |
1267 | pci_name(dev)); | ||
1264 | cmd |= PCI_COMMAND_INVALIDATE; | 1268 | cmd |= PCI_COMMAND_INVALIDATE; |
1265 | pci_write_config_word(dev, PCI_COMMAND, cmd); | 1269 | pci_write_config_word(dev, PCI_COMMAND, cmd); |
1266 | } | 1270 | } |
@@ -1269,6 +1273,21 @@ pci_set_mwi(struct pci_dev *dev) | |||
1269 | } | 1273 | } |
1270 | 1274 | ||
1271 | /** | 1275 | /** |
1276 | * pci_try_set_mwi - enables memory-write-invalidate PCI transaction | ||
1277 | * @dev: the PCI device for which MWI is enabled | ||
1278 | * | ||
1279 | * Enables the Memory-Write-Invalidate transaction in %PCI_COMMAND. | ||
1280 | * Callers are not required to check the return value. | ||
1281 | * | ||
1282 | * RETURNS: An appropriate -ERRNO error value on error, or zero for success. | ||
1283 | */ | ||
1284 | int pci_try_set_mwi(struct pci_dev *dev) | ||
1285 | { | ||
1286 | int rc = pci_set_mwi(dev); | ||
1287 | return rc; | ||
1288 | } | ||
1289 | |||
1290 | /** | ||
1272 | * pci_clear_mwi - disables Memory-Write-Invalidate for device dev | 1291 | * pci_clear_mwi - disables Memory-Write-Invalidate for device dev |
1273 | * @dev: the PCI device to disable | 1292 | * @dev: the PCI device to disable |
1274 | * | 1293 | * |
@@ -1375,6 +1394,164 @@ pci_set_consistent_dma_mask(struct pci_dev *dev, u64 mask) | |||
1375 | #endif | 1394 | #endif |
1376 | 1395 | ||
1377 | /** | 1396 | /** |
1397 | * pcix_get_max_mmrbc - get PCI-X maximum designed memory read byte count | ||
1398 | * @dev: PCI device to query | ||
1399 | * | ||
1400 | * Returns mmrbc: maximum designed memory read count in bytes | ||
1401 | * or appropriate error value. | ||
1402 | */ | ||
1403 | int pcix_get_max_mmrbc(struct pci_dev *dev) | ||
1404 | { | ||
1405 | int err, cap; | ||
1406 | u32 stat; | ||
1407 | |||
1408 | cap = pci_find_capability(dev, PCI_CAP_ID_PCIX); | ||
1409 | if (!cap) | ||
1410 | return -EINVAL; | ||
1411 | |||
1412 | err = pci_read_config_dword(dev, cap + PCI_X_STATUS, &stat); | ||
1413 | if (err) | ||
1414 | return -EINVAL; | ||
1415 | |||
1416 | return (stat & PCI_X_STATUS_MAX_READ) >> 12; | ||
1417 | } | ||
1418 | EXPORT_SYMBOL(pcix_get_max_mmrbc); | ||
1419 | |||
1420 | /** | ||
1421 | * pcix_get_mmrbc - get PCI-X maximum memory read byte count | ||
1422 | * @dev: PCI device to query | ||
1423 | * | ||
1424 | * Returns mmrbc: maximum memory read count in bytes | ||
1425 | * or appropriate error value. | ||
1426 | */ | ||
1427 | int pcix_get_mmrbc(struct pci_dev *dev) | ||
1428 | { | ||
1429 | int ret, cap; | ||
1430 | u32 cmd; | ||
1431 | |||
1432 | cap = pci_find_capability(dev, PCI_CAP_ID_PCIX); | ||
1433 | if (!cap) | ||
1434 | return -EINVAL; | ||
1435 | |||
1436 | ret = pci_read_config_dword(dev, cap + PCI_X_CMD, &cmd); | ||
1437 | if (!ret) | ||
1438 | ret = 512 << ((cmd & PCI_X_CMD_MAX_READ) >> 2); | ||
1439 | |||
1440 | return ret; | ||
1441 | } | ||
1442 | EXPORT_SYMBOL(pcix_get_mmrbc); | ||
1443 | |||
1444 | /** | ||
1445 | * pcix_set_mmrbc - set PCI-X maximum memory read byte count | ||
1446 | * @dev: PCI device to query | ||
1447 | * @mmrbc: maximum memory read count in bytes | ||
1448 | * valid values are 512, 1024, 2048, 4096 | ||
1449 | * | ||
1450 | * If possible sets maximum memory read byte count, some bridges have erratas | ||
1451 | * that prevent this. | ||
1452 | */ | ||
1453 | int pcix_set_mmrbc(struct pci_dev *dev, int mmrbc) | ||
1454 | { | ||
1455 | int cap, err = -EINVAL; | ||
1456 | u32 stat, cmd, v, o; | ||
1457 | |||
1458 | if (mmrbc < 512 || mmrbc > 4096 || (mmrbc & (mmrbc-1))) | ||
1459 | goto out; | ||
1460 | |||
1461 | v = ffs(mmrbc) - 10; | ||
1462 | |||
1463 | cap = pci_find_capability(dev, PCI_CAP_ID_PCIX); | ||
1464 | if (!cap) | ||
1465 | goto out; | ||
1466 | |||
1467 | err = pci_read_config_dword(dev, cap + PCI_X_STATUS, &stat); | ||
1468 | if (err) | ||
1469 | goto out; | ||
1470 | |||
1471 | if (v > (stat & PCI_X_STATUS_MAX_READ) >> 21) | ||
1472 | return -E2BIG; | ||
1473 | |||
1474 | err = pci_read_config_dword(dev, cap + PCI_X_CMD, &cmd); | ||
1475 | if (err) | ||
1476 | goto out; | ||
1477 | |||
1478 | o = (cmd & PCI_X_CMD_MAX_READ) >> 2; | ||
1479 | if (o != v) { | ||
1480 | if (v > o && dev->bus && | ||
1481 | (dev->bus->bus_flags & PCI_BUS_FLAGS_NO_MMRBC)) | ||
1482 | return -EIO; | ||
1483 | |||
1484 | cmd &= ~PCI_X_CMD_MAX_READ; | ||
1485 | cmd |= v << 2; | ||
1486 | err = pci_write_config_dword(dev, cap + PCI_X_CMD, cmd); | ||
1487 | } | ||
1488 | out: | ||
1489 | return err; | ||
1490 | } | ||
1491 | EXPORT_SYMBOL(pcix_set_mmrbc); | ||
1492 | |||
1493 | /** | ||
1494 | * pcie_get_readrq - get PCI Express read request size | ||
1495 | * @dev: PCI device to query | ||
1496 | * | ||
1497 | * Returns maximum memory read request in bytes | ||
1498 | * or appropriate error value. | ||
1499 | */ | ||
1500 | int pcie_get_readrq(struct pci_dev *dev) | ||
1501 | { | ||
1502 | int ret, cap; | ||
1503 | u16 ctl; | ||
1504 | |||
1505 | cap = pci_find_capability(dev, PCI_CAP_ID_EXP); | ||
1506 | if (!cap) | ||
1507 | return -EINVAL; | ||
1508 | |||
1509 | ret = pci_read_config_word(dev, cap + PCI_EXP_DEVCTL, &ctl); | ||
1510 | if (!ret) | ||
1511 | ret = 128 << ((ctl & PCI_EXP_DEVCTL_READRQ) >> 12); | ||
1512 | |||
1513 | return ret; | ||
1514 | } | ||
1515 | EXPORT_SYMBOL(pcie_get_readrq); | ||
1516 | |||
1517 | /** | ||
1518 | * pcie_set_readrq - set PCI Express maximum memory read request | ||
1519 | * @dev: PCI device to query | ||
1520 | * @count: maximum memory read count in bytes | ||
1521 | * valid values are 128, 256, 512, 1024, 2048, 4096 | ||
1522 | * | ||
1523 | * If possible sets maximum read byte count | ||
1524 | */ | ||
1525 | int pcie_set_readrq(struct pci_dev *dev, int rq) | ||
1526 | { | ||
1527 | int cap, err = -EINVAL; | ||
1528 | u16 ctl, v; | ||
1529 | |||
1530 | if (rq < 128 || rq > 4096 || (rq & (rq-1))) | ||
1531 | goto out; | ||
1532 | |||
1533 | v = (ffs(rq) - 8) << 12; | ||
1534 | |||
1535 | cap = pci_find_capability(dev, PCI_CAP_ID_EXP); | ||
1536 | if (!cap) | ||
1537 | goto out; | ||
1538 | |||
1539 | err = pci_read_config_word(dev, cap + PCI_EXP_DEVCTL, &ctl); | ||
1540 | if (err) | ||
1541 | goto out; | ||
1542 | |||
1543 | if ((ctl & PCI_EXP_DEVCTL_READRQ) != v) { | ||
1544 | ctl &= ~PCI_EXP_DEVCTL_READRQ; | ||
1545 | ctl |= v; | ||
1546 | err = pci_write_config_dword(dev, cap + PCI_EXP_DEVCTL, ctl); | ||
1547 | } | ||
1548 | |||
1549 | out: | ||
1550 | return err; | ||
1551 | } | ||
1552 | EXPORT_SYMBOL(pcie_set_readrq); | ||
1553 | |||
1554 | /** | ||
1378 | * pci_select_bars - Make BAR mask from the type of resource | 1555 | * pci_select_bars - Make BAR mask from the type of resource |
1379 | * @dev: the PCI device for which BAR mask is made | 1556 | * @dev: the PCI device for which BAR mask is made |
1380 | * @flags: resource type mask to be selected | 1557 | * @flags: resource type mask to be selected |
@@ -1442,6 +1619,7 @@ EXPORT_SYMBOL(pci_release_selected_regions); | |||
1442 | EXPORT_SYMBOL(pci_request_selected_regions); | 1619 | EXPORT_SYMBOL(pci_request_selected_regions); |
1443 | EXPORT_SYMBOL(pci_set_master); | 1620 | EXPORT_SYMBOL(pci_set_master); |
1444 | EXPORT_SYMBOL(pci_set_mwi); | 1621 | EXPORT_SYMBOL(pci_set_mwi); |
1622 | EXPORT_SYMBOL(pci_try_set_mwi); | ||
1445 | EXPORT_SYMBOL(pci_clear_mwi); | 1623 | EXPORT_SYMBOL(pci_clear_mwi); |
1446 | EXPORT_SYMBOL_GPL(pci_intx); | 1624 | EXPORT_SYMBOL_GPL(pci_intx); |
1447 | EXPORT_SYMBOL(pci_set_dma_mask); | 1625 | EXPORT_SYMBOL(pci_set_dma_mask); |