diff options
Diffstat (limited to 'drivers/pci/pci.c')
-rw-r--r-- | drivers/pci/pci.c | 154 |
1 files changed, 105 insertions, 49 deletions
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 4e4c295a049f..0bc27e059019 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c | |||
@@ -47,6 +47,15 @@ unsigned long pci_cardbus_mem_size = DEFAULT_CARDBUS_MEM_SIZE; | |||
47 | unsigned long pci_hotplug_io_size = DEFAULT_HOTPLUG_IO_SIZE; | 47 | unsigned long pci_hotplug_io_size = DEFAULT_HOTPLUG_IO_SIZE; |
48 | unsigned long pci_hotplug_mem_size = DEFAULT_HOTPLUG_MEM_SIZE; | 48 | unsigned long pci_hotplug_mem_size = DEFAULT_HOTPLUG_MEM_SIZE; |
49 | 49 | ||
50 | /* | ||
51 | * The default CLS is used if arch didn't set CLS explicitly and not | ||
52 | * all pci devices agree on the same value. Arch can override either | ||
53 | * the dfl or actual value as it sees fit. Don't forget this is | ||
54 | * measured in 32-bit words, not bytes. | ||
55 | */ | ||
56 | u8 pci_dfl_cache_line_size __devinitdata = L1_CACHE_BYTES >> 2; | ||
57 | u8 pci_cache_line_size; | ||
58 | |||
50 | /** | 59 | /** |
51 | * pci_bus_max_busnr - returns maximum PCI bus number of given bus' children | 60 | * pci_bus_max_busnr - returns maximum PCI bus number of given bus' children |
52 | * @bus: pointer to PCI bus structure to search | 61 | * @bus: pointer to PCI bus structure to search |
@@ -373,8 +382,12 @@ pci_find_parent_resource(const struct pci_dev *dev, struct resource *res) | |||
373 | continue; /* Wrong type */ | 382 | continue; /* Wrong type */ |
374 | if (!((res->flags ^ r->flags) & IORESOURCE_PREFETCH)) | 383 | if (!((res->flags ^ r->flags) & IORESOURCE_PREFETCH)) |
375 | return r; /* Exact match */ | 384 | return r; /* Exact match */ |
376 | if ((res->flags & IORESOURCE_PREFETCH) && !(r->flags & IORESOURCE_PREFETCH)) | 385 | /* We can't insert a non-prefetch resource inside a prefetchable parent .. */ |
377 | best = r; /* Approximating prefetchable by non-prefetchable */ | 386 | if (r->flags & IORESOURCE_PREFETCH) |
387 | continue; | ||
388 | /* .. but we can put a prefetchable resource inside a non-prefetchable one */ | ||
389 | if (!best) | ||
390 | best = r; | ||
378 | } | 391 | } |
379 | return best; | 392 | return best; |
380 | } | 393 | } |
@@ -728,8 +741,8 @@ static int pci_save_pcie_state(struct pci_dev *dev) | |||
728 | u16 *cap; | 741 | u16 *cap; |
729 | u16 flags; | 742 | u16 flags; |
730 | 743 | ||
731 | pos = pci_find_capability(dev, PCI_CAP_ID_EXP); | 744 | pos = pci_pcie_cap(dev); |
732 | if (pos <= 0) | 745 | if (!pos) |
733 | return 0; | 746 | return 0; |
734 | 747 | ||
735 | save_state = pci_find_saved_cap(dev, PCI_CAP_ID_EXP); | 748 | save_state = pci_find_saved_cap(dev, PCI_CAP_ID_EXP); |
@@ -837,7 +850,7 @@ pci_save_state(struct pci_dev *dev) | |||
837 | int i; | 850 | int i; |
838 | /* XXX: 100% dword access ok here? */ | 851 | /* XXX: 100% dword access ok here? */ |
839 | for (i = 0; i < 16; i++) | 852 | for (i = 0; i < 16; i++) |
840 | pci_read_config_dword(dev, i * 4,&dev->saved_config_space[i]); | 853 | pci_read_config_dword(dev, i * 4, &dev->saved_config_space[i]); |
841 | dev->state_saved = true; | 854 | dev->state_saved = true; |
842 | if ((i = pci_save_pcie_state(dev)) != 0) | 855 | if ((i = pci_save_pcie_state(dev)) != 0) |
843 | return i; | 856 | return i; |
@@ -1202,7 +1215,7 @@ void pci_pme_active(struct pci_dev *dev, bool enable) | |||
1202 | 1215 | ||
1203 | pci_write_config_word(dev, dev->pm_cap + PCI_PM_CTRL, pmcsr); | 1216 | pci_write_config_word(dev, dev->pm_cap + PCI_PM_CTRL, pmcsr); |
1204 | 1217 | ||
1205 | dev_printk(KERN_INFO, &dev->dev, "PME# %s\n", | 1218 | dev_printk(KERN_DEBUG, &dev->dev, "PME# %s\n", |
1206 | enable ? "enabled" : "disabled"); | 1219 | enable ? "enabled" : "disabled"); |
1207 | } | 1220 | } |
1208 | 1221 | ||
@@ -1413,7 +1426,8 @@ void pci_pm_init(struct pci_dev *dev) | |||
1413 | 1426 | ||
1414 | pmc &= PCI_PM_CAP_PME_MASK; | 1427 | pmc &= PCI_PM_CAP_PME_MASK; |
1415 | if (pmc) { | 1428 | if (pmc) { |
1416 | dev_info(&dev->dev, "PME# supported from%s%s%s%s%s\n", | 1429 | dev_printk(KERN_DEBUG, &dev->dev, |
1430 | "PME# supported from%s%s%s%s%s\n", | ||
1417 | (pmc & PCI_PM_CAP_PME_D0) ? " D0" : "", | 1431 | (pmc & PCI_PM_CAP_PME_D0) ? " D0" : "", |
1418 | (pmc & PCI_PM_CAP_PME_D1) ? " D1" : "", | 1432 | (pmc & PCI_PM_CAP_PME_D1) ? " D1" : "", |
1419 | (pmc & PCI_PM_CAP_PME_D2) ? " D2" : "", | 1433 | (pmc & PCI_PM_CAP_PME_D2) ? " D2" : "", |
@@ -1510,7 +1524,7 @@ void pci_enable_ari(struct pci_dev *dev) | |||
1510 | u16 ctrl; | 1524 | u16 ctrl; |
1511 | struct pci_dev *bridge; | 1525 | struct pci_dev *bridge; |
1512 | 1526 | ||
1513 | if (!dev->is_pcie || dev->devfn) | 1527 | if (!pci_is_pcie(dev) || dev->devfn) |
1514 | return; | 1528 | return; |
1515 | 1529 | ||
1516 | pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ARI); | 1530 | pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ARI); |
@@ -1518,10 +1532,10 @@ void pci_enable_ari(struct pci_dev *dev) | |||
1518 | return; | 1532 | return; |
1519 | 1533 | ||
1520 | bridge = dev->bus->self; | 1534 | bridge = dev->bus->self; |
1521 | if (!bridge || !bridge->is_pcie) | 1535 | if (!bridge || !pci_is_pcie(bridge)) |
1522 | return; | 1536 | return; |
1523 | 1537 | ||
1524 | pos = pci_find_capability(bridge, PCI_CAP_ID_EXP); | 1538 | pos = pci_pcie_cap(bridge); |
1525 | if (!pos) | 1539 | if (!pos) |
1526 | return; | 1540 | return; |
1527 | 1541 | ||
@@ -1536,6 +1550,54 @@ void pci_enable_ari(struct pci_dev *dev) | |||
1536 | bridge->ari_enabled = 1; | 1550 | bridge->ari_enabled = 1; |
1537 | } | 1551 | } |
1538 | 1552 | ||
1553 | static int pci_acs_enable; | ||
1554 | |||
1555 | /** | ||
1556 | * pci_request_acs - ask for ACS to be enabled if supported | ||
1557 | */ | ||
1558 | void pci_request_acs(void) | ||
1559 | { | ||
1560 | pci_acs_enable = 1; | ||
1561 | } | ||
1562 | |||
1563 | /** | ||
1564 | * pci_enable_acs - enable ACS if hardware support it | ||
1565 | * @dev: the PCI device | ||
1566 | */ | ||
1567 | void pci_enable_acs(struct pci_dev *dev) | ||
1568 | { | ||
1569 | int pos; | ||
1570 | u16 cap; | ||
1571 | u16 ctrl; | ||
1572 | |||
1573 | if (!pci_acs_enable) | ||
1574 | return; | ||
1575 | |||
1576 | if (!pci_is_pcie(dev)) | ||
1577 | return; | ||
1578 | |||
1579 | pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ACS); | ||
1580 | if (!pos) | ||
1581 | return; | ||
1582 | |||
1583 | pci_read_config_word(dev, pos + PCI_ACS_CAP, &cap); | ||
1584 | pci_read_config_word(dev, pos + PCI_ACS_CTRL, &ctrl); | ||
1585 | |||
1586 | /* Source Validation */ | ||
1587 | ctrl |= (cap & PCI_ACS_SV); | ||
1588 | |||
1589 | /* P2P Request Redirect */ | ||
1590 | ctrl |= (cap & PCI_ACS_RR); | ||
1591 | |||
1592 | /* P2P Completion Redirect */ | ||
1593 | ctrl |= (cap & PCI_ACS_CR); | ||
1594 | |||
1595 | /* Upstream Forwarding */ | ||
1596 | ctrl |= (cap & PCI_ACS_UF); | ||
1597 | |||
1598 | pci_write_config_word(dev, pos + PCI_ACS_CTRL, ctrl); | ||
1599 | } | ||
1600 | |||
1539 | /** | 1601 | /** |
1540 | * pci_swizzle_interrupt_pin - swizzle INTx for device behind bridge | 1602 | * pci_swizzle_interrupt_pin - swizzle INTx for device behind bridge |
1541 | * @dev: the PCI device | 1603 | * @dev: the PCI device |
@@ -1669,9 +1731,7 @@ static int __pci_request_region(struct pci_dev *pdev, int bar, const char *res_n | |||
1669 | return 0; | 1731 | return 0; |
1670 | 1732 | ||
1671 | err_out: | 1733 | err_out: |
1672 | dev_warn(&pdev->dev, "BAR %d: can't reserve %s region %pR\n", | 1734 | dev_warn(&pdev->dev, "BAR %d: can't reserve %pR\n", bar, |
1673 | bar, | ||
1674 | pci_resource_flags(pdev, bar) & IORESOURCE_IO ? "I/O" : "mem", | ||
1675 | &pdev->resource[bar]); | 1735 | &pdev->resource[bar]); |
1676 | return -EBUSY; | 1736 | return -EBUSY; |
1677 | } | 1737 | } |
@@ -1866,31 +1926,6 @@ void pci_clear_master(struct pci_dev *dev) | |||
1866 | __pci_set_master(dev, false); | 1926 | __pci_set_master(dev, false); |
1867 | } | 1927 | } |
1868 | 1928 | ||
1869 | #ifdef PCI_DISABLE_MWI | ||
1870 | int pci_set_mwi(struct pci_dev *dev) | ||
1871 | { | ||
1872 | return 0; | ||
1873 | } | ||
1874 | |||
1875 | int pci_try_set_mwi(struct pci_dev *dev) | ||
1876 | { | ||
1877 | return 0; | ||
1878 | } | ||
1879 | |||
1880 | void pci_clear_mwi(struct pci_dev *dev) | ||
1881 | { | ||
1882 | } | ||
1883 | |||
1884 | #else | ||
1885 | |||
1886 | #ifndef PCI_CACHE_LINE_BYTES | ||
1887 | #define PCI_CACHE_LINE_BYTES L1_CACHE_BYTES | ||
1888 | #endif | ||
1889 | |||
1890 | /* This can be overridden by arch code. */ | ||
1891 | /* Don't forget this is measured in 32-bit words, not bytes */ | ||
1892 | u8 pci_cache_line_size = PCI_CACHE_LINE_BYTES / 4; | ||
1893 | |||
1894 | /** | 1929 | /** |
1895 | * pci_set_cacheline_size - ensure the CACHE_LINE_SIZE register is programmed | 1930 | * pci_set_cacheline_size - ensure the CACHE_LINE_SIZE register is programmed |
1896 | * @dev: the PCI device for which MWI is to be enabled | 1931 | * @dev: the PCI device for which MWI is to be enabled |
@@ -1901,13 +1936,12 @@ u8 pci_cache_line_size = PCI_CACHE_LINE_BYTES / 4; | |||
1901 | * | 1936 | * |
1902 | * RETURNS: An appropriate -ERRNO error value on error, or zero for success. | 1937 | * RETURNS: An appropriate -ERRNO error value on error, or zero for success. |
1903 | */ | 1938 | */ |
1904 | static int | 1939 | int pci_set_cacheline_size(struct pci_dev *dev) |
1905 | pci_set_cacheline_size(struct pci_dev *dev) | ||
1906 | { | 1940 | { |
1907 | u8 cacheline_size; | 1941 | u8 cacheline_size; |
1908 | 1942 | ||
1909 | if (!pci_cache_line_size) | 1943 | if (!pci_cache_line_size) |
1910 | return -EINVAL; /* The system doesn't support MWI. */ | 1944 | return -EINVAL; |
1911 | 1945 | ||
1912 | /* Validate current setting: the PCI_CACHE_LINE_SIZE must be | 1946 | /* Validate current setting: the PCI_CACHE_LINE_SIZE must be |
1913 | equal to or multiple of the right value. */ | 1947 | equal to or multiple of the right value. */ |
@@ -1928,6 +1962,24 @@ pci_set_cacheline_size(struct pci_dev *dev) | |||
1928 | 1962 | ||
1929 | return -EINVAL; | 1963 | return -EINVAL; |
1930 | } | 1964 | } |
1965 | EXPORT_SYMBOL_GPL(pci_set_cacheline_size); | ||
1966 | |||
1967 | #ifdef PCI_DISABLE_MWI | ||
1968 | int pci_set_mwi(struct pci_dev *dev) | ||
1969 | { | ||
1970 | return 0; | ||
1971 | } | ||
1972 | |||
1973 | int pci_try_set_mwi(struct pci_dev *dev) | ||
1974 | { | ||
1975 | return 0; | ||
1976 | } | ||
1977 | |||
1978 | void pci_clear_mwi(struct pci_dev *dev) | ||
1979 | { | ||
1980 | } | ||
1981 | |||
1982 | #else | ||
1931 | 1983 | ||
1932 | /** | 1984 | /** |
1933 | * pci_set_mwi - enables memory-write-invalidate PCI transaction | 1985 | * pci_set_mwi - enables memory-write-invalidate PCI transaction |
@@ -2062,6 +2114,7 @@ pci_set_dma_mask(struct pci_dev *dev, u64 mask) | |||
2062 | return -EIO; | 2114 | return -EIO; |
2063 | 2115 | ||
2064 | dev->dma_mask = mask; | 2116 | dev->dma_mask = mask; |
2117 | dev_dbg(&dev->dev, "using %dbit DMA mask\n", fls64(mask)); | ||
2065 | 2118 | ||
2066 | return 0; | 2119 | return 0; |
2067 | } | 2120 | } |
@@ -2073,6 +2126,7 @@ pci_set_consistent_dma_mask(struct pci_dev *dev, u64 mask) | |||
2073 | return -EIO; | 2126 | return -EIO; |
2074 | 2127 | ||
2075 | dev->dev.coherent_dma_mask = mask; | 2128 | dev->dev.coherent_dma_mask = mask; |
2129 | dev_dbg(&dev->dev, "using %dbit consistent DMA mask\n", fls64(mask)); | ||
2076 | 2130 | ||
2077 | return 0; | 2131 | return 0; |
2078 | } | 2132 | } |
@@ -2099,9 +2153,9 @@ static int pcie_flr(struct pci_dev *dev, int probe) | |||
2099 | int i; | 2153 | int i; |
2100 | int pos; | 2154 | int pos; |
2101 | u32 cap; | 2155 | u32 cap; |
2102 | u16 status; | 2156 | u16 status, control; |
2103 | 2157 | ||
2104 | pos = pci_find_capability(dev, PCI_CAP_ID_EXP); | 2158 | pos = pci_pcie_cap(dev); |
2105 | if (!pos) | 2159 | if (!pos) |
2106 | return -ENOTTY; | 2160 | return -ENOTTY; |
2107 | 2161 | ||
@@ -2126,8 +2180,10 @@ static int pcie_flr(struct pci_dev *dev, int probe) | |||
2126 | "proceeding with reset anyway\n"); | 2180 | "proceeding with reset anyway\n"); |
2127 | 2181 | ||
2128 | clear: | 2182 | clear: |
2129 | pci_write_config_word(dev, pos + PCI_EXP_DEVCTL, | 2183 | pci_read_config_word(dev, pos + PCI_EXP_DEVCTL, &control); |
2130 | PCI_EXP_DEVCTL_BCR_FLR); | 2184 | control |= PCI_EXP_DEVCTL_BCR_FLR; |
2185 | pci_write_config_word(dev, pos + PCI_EXP_DEVCTL, control); | ||
2186 | |||
2131 | msleep(100); | 2187 | msleep(100); |
2132 | 2188 | ||
2133 | return 0; | 2189 | return 0; |
@@ -2450,7 +2506,7 @@ int pcie_get_readrq(struct pci_dev *dev) | |||
2450 | int ret, cap; | 2506 | int ret, cap; |
2451 | u16 ctl; | 2507 | u16 ctl; |
2452 | 2508 | ||
2453 | cap = pci_find_capability(dev, PCI_CAP_ID_EXP); | 2509 | cap = pci_pcie_cap(dev); |
2454 | if (!cap) | 2510 | if (!cap) |
2455 | return -EINVAL; | 2511 | return -EINVAL; |
2456 | 2512 | ||
@@ -2480,7 +2536,7 @@ int pcie_set_readrq(struct pci_dev *dev, int rq) | |||
2480 | 2536 | ||
2481 | v = (ffs(rq) - 8) << 12; | 2537 | v = (ffs(rq) - 8) << 12; |
2482 | 2538 | ||
2483 | cap = pci_find_capability(dev, PCI_CAP_ID_EXP); | 2539 | cap = pci_pcie_cap(dev); |
2484 | if (!cap) | 2540 | if (!cap) |
2485 | goto out; | 2541 | goto out; |
2486 | 2542 | ||
@@ -2540,7 +2596,7 @@ int pci_resource_bar(struct pci_dev *dev, int resno, enum pci_bar_type *type) | |||
2540 | return reg; | 2596 | return reg; |
2541 | } | 2597 | } |
2542 | 2598 | ||
2543 | dev_err(&dev->dev, "BAR: invalid resource #%d\n", resno); | 2599 | dev_err(&dev->dev, "BAR %d: invalid resource\n", resno); |
2544 | return 0; | 2600 | return 0; |
2545 | } | 2601 | } |
2546 | 2602 | ||
@@ -2590,7 +2646,7 @@ int pci_set_vga_state(struct pci_dev *dev, bool decode, | |||
2590 | 2646 | ||
2591 | #define RESOURCE_ALIGNMENT_PARAM_SIZE COMMAND_LINE_SIZE | 2647 | #define RESOURCE_ALIGNMENT_PARAM_SIZE COMMAND_LINE_SIZE |
2592 | static char resource_alignment_param[RESOURCE_ALIGNMENT_PARAM_SIZE] = {0}; | 2648 | static char resource_alignment_param[RESOURCE_ALIGNMENT_PARAM_SIZE] = {0}; |
2593 | spinlock_t resource_alignment_lock = SPIN_LOCK_UNLOCKED; | 2649 | static DEFINE_SPINLOCK(resource_alignment_lock); |
2594 | 2650 | ||
2595 | /** | 2651 | /** |
2596 | * pci_specified_resource_alignment - get resource alignment specified by user. | 2652 | * pci_specified_resource_alignment - get resource alignment specified by user. |