aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pci/pci.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/pci/pci.c')
-rw-r--r--drivers/pci/pci.c74
1 files changed, 39 insertions, 35 deletions
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index bdd64b1b4817..33120d156668 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -198,7 +198,7 @@ static int __pci_bus_find_cap_start(struct pci_bus *bus,
198} 198}
199 199
200/** 200/**
201 * pci_find_capability - query for devices' capabilities 201 * pci_find_capability - query for devices' capabilities
202 * @dev: PCI device to query 202 * @dev: PCI device to query
203 * @cap: capability code 203 * @cap: capability code
204 * 204 *
@@ -207,12 +207,12 @@ static int __pci_bus_find_cap_start(struct pci_bus *bus,
207 * device's PCI configuration space or 0 in case the device does not 207 * device's PCI configuration space or 0 in case the device does not
208 * support it. Possible values for @cap: 208 * support it. Possible values for @cap:
209 * 209 *
210 * %PCI_CAP_ID_PM Power Management 210 * %PCI_CAP_ID_PM Power Management
211 * %PCI_CAP_ID_AGP Accelerated Graphics Port 211 * %PCI_CAP_ID_AGP Accelerated Graphics Port
212 * %PCI_CAP_ID_VPD Vital Product Data 212 * %PCI_CAP_ID_VPD Vital Product Data
213 * %PCI_CAP_ID_SLOTID Slot Identification 213 * %PCI_CAP_ID_SLOTID Slot Identification
214 * %PCI_CAP_ID_MSI Message Signalled Interrupts 214 * %PCI_CAP_ID_MSI Message Signalled Interrupts
215 * %PCI_CAP_ID_CHSWP CompactPCI HotSwap 215 * %PCI_CAP_ID_CHSWP CompactPCI HotSwap
216 * %PCI_CAP_ID_PCIX PCI-X 216 * %PCI_CAP_ID_PCIX PCI-X
217 * %PCI_CAP_ID_EXP PCI Express 217 * %PCI_CAP_ID_EXP PCI Express
218 */ 218 */
@@ -228,13 +228,13 @@ int pci_find_capability(struct pci_dev *dev, int cap)
228} 228}
229 229
230/** 230/**
231 * pci_bus_find_capability - query for devices' capabilities 231 * pci_bus_find_capability - query for devices' capabilities
232 * @bus: the PCI bus to query 232 * @bus: the PCI bus to query
233 * @devfn: PCI device to query 233 * @devfn: PCI device to query
234 * @cap: capability code 234 * @cap: capability code
235 * 235 *
236 * Like pci_find_capability() but works for pci devices that do not have a 236 * Like pci_find_capability() but works for pci devices that do not have a
237 * pci_dev structure set up yet. 237 * pci_dev structure set up yet.
238 * 238 *
239 * Returns the address of the requested capability structure within the 239 * Returns the address of the requested capability structure within the
240 * device's PCI configuration space or 0 in case the device does not 240 * device's PCI configuration space or 0 in case the device does not
@@ -515,7 +515,7 @@ static int pci_raw_set_power_state(struct pci_dev *dev, pci_power_t state)
515 return -EINVAL; 515 return -EINVAL;
516 516
517 /* Validate current state: 517 /* Validate current state:
518 * Can enter D0 from any state, but if we can only go deeper 518 * Can enter D0 from any state, but if we can only go deeper
519 * to sleep if we're already in a low power state 519 * to sleep if we're already in a low power state
520 */ 520 */
521 if (state != PCI_D0 && dev->current_state <= PCI_D3cold 521 if (state != PCI_D0 && dev->current_state <= PCI_D3cold
@@ -998,7 +998,7 @@ static void pci_restore_config_space(struct pci_dev *pdev)
998 } 998 }
999} 999}
1000 1000
1001/** 1001/**
1002 * pci_restore_state - Restore the saved state of a PCI device 1002 * pci_restore_state - Restore the saved state of a PCI device
1003 * @dev: - PCI device that we're dealing with 1003 * @dev: - PCI device that we're dealing with
1004 */ 1004 */
@@ -1030,7 +1030,7 @@ struct pci_saved_state {
1030 * the device saved state. 1030 * the device saved state.
1031 * @dev: PCI device that we're dealing with 1031 * @dev: PCI device that we're dealing with
1032 * 1032 *
1033 * Rerturn NULL if no state or error. 1033 * Return NULL if no state or error.
1034 */ 1034 */
1035struct pci_saved_state *pci_store_saved_state(struct pci_dev *dev) 1035struct pci_saved_state *pci_store_saved_state(struct pci_dev *dev)
1036{ 1036{
@@ -1148,18 +1148,16 @@ int pci_reenable_device(struct pci_dev *dev)
1148 1148
1149static void pci_enable_bridge(struct pci_dev *dev) 1149static void pci_enable_bridge(struct pci_dev *dev)
1150{ 1150{
1151 struct pci_dev *bridge;
1151 int retval; 1152 int retval;
1152 1153
1153 if (!dev) 1154 bridge = pci_upstream_bridge(dev);
1154 return; 1155 if (bridge)
1155 1156 pci_enable_bridge(bridge);
1156 pci_enable_bridge(dev->bus->self);
1157 1157
1158 if (pci_is_enabled(dev)) { 1158 if (pci_is_enabled(dev)) {
1159 if (!dev->is_busmaster) { 1159 if (!dev->is_busmaster)
1160 dev_warn(&dev->dev, "driver skip pci_set_master, fix it!\n");
1161 pci_set_master(dev); 1160 pci_set_master(dev);
1162 }
1163 return; 1161 return;
1164 } 1162 }
1165 1163
@@ -1172,6 +1170,7 @@ static void pci_enable_bridge(struct pci_dev *dev)
1172 1170
1173static int pci_enable_device_flags(struct pci_dev *dev, unsigned long flags) 1171static int pci_enable_device_flags(struct pci_dev *dev, unsigned long flags)
1174{ 1172{
1173 struct pci_dev *bridge;
1175 int err; 1174 int err;
1176 int i, bars = 0; 1175 int i, bars = 0;
1177 1176
@@ -1190,7 +1189,9 @@ static int pci_enable_device_flags(struct pci_dev *dev, unsigned long flags)
1190 if (atomic_inc_return(&dev->enable_cnt) > 1) 1189 if (atomic_inc_return(&dev->enable_cnt) > 1)
1191 return 0; /* already enabled */ 1190 return 0; /* already enabled */
1192 1191
1193 pci_enable_bridge(dev->bus->self); 1192 bridge = pci_upstream_bridge(dev);
1193 if (bridge)
1194 pci_enable_bridge(bridge);
1194 1195
1195 /* only skip sriov related */ 1196 /* only skip sriov related */
1196 for (i = 0; i <= PCI_ROM_RESOURCE; i++) 1197 for (i = 0; i <= PCI_ROM_RESOURCE; i++)
@@ -1644,8 +1645,10 @@ void pci_pme_active(struct pci_dev *dev, bool enable)
1644 if (enable) { 1645 if (enable) {
1645 pme_dev = kmalloc(sizeof(struct pci_pme_device), 1646 pme_dev = kmalloc(sizeof(struct pci_pme_device),
1646 GFP_KERNEL); 1647 GFP_KERNEL);
1647 if (!pme_dev) 1648 if (!pme_dev) {
1648 goto out; 1649 dev_warn(&dev->dev, "can't enable PME#\n");
1650 return;
1651 }
1649 pme_dev->dev = dev; 1652 pme_dev->dev = dev;
1650 mutex_lock(&pci_pme_list_mutex); 1653 mutex_lock(&pci_pme_list_mutex);
1651 list_add(&pme_dev->list, &pci_pme_list); 1654 list_add(&pme_dev->list, &pci_pme_list);
@@ -1666,7 +1669,6 @@ void pci_pme_active(struct pci_dev *dev, bool enable)
1666 } 1669 }
1667 } 1670 }
1668 1671
1669out:
1670 dev_dbg(&dev->dev, "PME# %s\n", enable ? "enabled" : "disabled"); 1672 dev_dbg(&dev->dev, "PME# %s\n", enable ? "enabled" : "disabled");
1671} 1673}
1672 1674
@@ -1878,7 +1880,7 @@ int pci_finish_runtime_suspend(struct pci_dev *dev)
1878 * pci_dev_run_wake - Check if device can generate run-time wake-up events. 1880 * pci_dev_run_wake - Check if device can generate run-time wake-up events.
1879 * @dev: Device to check. 1881 * @dev: Device to check.
1880 * 1882 *
1881 * Return true if the device itself is cabable of generating wake-up events 1883 * Return true if the device itself is capable of generating wake-up events
1882 * (through the platform or using the native PCIe PME) or if the device supports 1884 * (through the platform or using the native PCIe PME) or if the device supports
1883 * PME and one of its upstream bridges can generate wake-up events. 1885 * PME and one of its upstream bridges can generate wake-up events.
1884 */ 1886 */
@@ -2445,7 +2447,7 @@ bool pci_acs_enabled(struct pci_dev *pdev, u16 acs_flags)
2445 switch (pci_pcie_type(pdev)) { 2447 switch (pci_pcie_type(pdev)) {
2446 /* 2448 /*
2447 * PCI/X-to-PCIe bridges are not specifically mentioned by the spec, 2449 * PCI/X-to-PCIe bridges are not specifically mentioned by the spec,
2448 * but since their primary inteface is PCI/X, we conservatively 2450 * but since their primary interface is PCI/X, we conservatively
2449 * handle them as we would a non-PCIe device. 2451 * handle them as we would a non-PCIe device.
2450 */ 2452 */
2451 case PCI_EXP_TYPE_PCIE_BRIDGE: 2453 case PCI_EXP_TYPE_PCIE_BRIDGE:
@@ -2469,7 +2471,7 @@ bool pci_acs_enabled(struct pci_dev *pdev, u16 acs_flags)
2469 /* 2471 /*
2470 * PCIe 3.0, 6.12.1.2 specifies ACS capabilities that should be 2472 * PCIe 3.0, 6.12.1.2 specifies ACS capabilities that should be
2471 * implemented by the remaining PCIe types to indicate peer-to-peer 2473 * implemented by the remaining PCIe types to indicate peer-to-peer
2472 * capabilities, but only when they are part of a multifunciton 2474 * capabilities, but only when they are part of a multifunction
2473 * device. The footnote for section 6.12 indicates the specific 2475 * device. The footnote for section 6.12 indicates the specific
2474 * PCIe types included here. 2476 * PCIe types included here.
2475 */ 2477 */
@@ -2484,7 +2486,7 @@ bool pci_acs_enabled(struct pci_dev *pdev, u16 acs_flags)
2484 } 2486 }
2485 2487
2486 /* 2488 /*
2487 * PCIe 3.0, 6.12.1.3 specifies no ACS capabilties are applicable 2489 * PCIe 3.0, 6.12.1.3 specifies no ACS capabilities are applicable
2488 * to single function devices with the exception of downstream ports. 2490 * to single function devices with the exception of downstream ports.
2489 */ 2491 */
2490 return true; 2492 return true;
@@ -2620,7 +2622,7 @@ void pci_release_region(struct pci_dev *pdev, int bar)
2620 * 2622 *
2621 * If @exclusive is set, then the region is marked so that userspace 2623 * If @exclusive is set, then the region is marked so that userspace
2622 * is explicitly not allowed to map the resource via /dev/mem or 2624 * is explicitly not allowed to map the resource via /dev/mem or
2623 * sysfs MMIO access. 2625 * sysfs MMIO access.
2624 * 2626 *
2625 * Returns 0 on success, or %EBUSY on error. A warning 2627 * Returns 0 on success, or %EBUSY on error. A warning
2626 * message is also printed on failure. 2628 * message is also printed on failure.
@@ -2632,7 +2634,7 @@ static int __pci_request_region(struct pci_dev *pdev, int bar, const char *res_n
2632 2634
2633 if (pci_resource_len(pdev, bar) == 0) 2635 if (pci_resource_len(pdev, bar) == 0)
2634 return 0; 2636 return 0;
2635 2637
2636 if (pci_resource_flags(pdev, bar) & IORESOURCE_IO) { 2638 if (pci_resource_flags(pdev, bar) & IORESOURCE_IO) {
2637 if (!request_region(pci_resource_start(pdev, bar), 2639 if (!request_region(pci_resource_start(pdev, bar),
2638 pci_resource_len(pdev, bar), res_name)) 2640 pci_resource_len(pdev, bar), res_name))
@@ -2692,7 +2694,7 @@ int pci_request_region(struct pci_dev *pdev, int bar, const char *res_name)
2692 * 2694 *
2693 * The key difference that _exclusive makes it that userspace is 2695 * The key difference that _exclusive makes it that userspace is
2694 * explicitly not allowed to map the resource via /dev/mem or 2696 * explicitly not allowed to map the resource via /dev/mem or
2695 * sysfs. 2697 * sysfs.
2696 */ 2698 */
2697int pci_request_region_exclusive(struct pci_dev *pdev, int bar, const char *res_name) 2699int pci_request_region_exclusive(struct pci_dev *pdev, int bar, const char *res_name)
2698{ 2700{
@@ -2797,7 +2799,7 @@ int pci_request_regions(struct pci_dev *pdev, const char *res_name)
2797 * successfully. 2799 * successfully.
2798 * 2800 *
2799 * pci_request_regions_exclusive() will mark the region so that 2801 * pci_request_regions_exclusive() will mark the region so that
2800 * /dev/mem and the sysfs MMIO access will not be allowed. 2802 * /dev/mem and the sysfs MMIO access will not be allowed.
2801 * 2803 *
2802 * Returns 0 on success, or %EBUSY on error. A warning 2804 * Returns 0 on success, or %EBUSY on error. A warning
2803 * message is also printed on failure. 2805 * message is also printed on failure.
@@ -2860,7 +2862,7 @@ void __weak pcibios_set_master(struct pci_dev *dev)
2860 lat = pcibios_max_latency; 2862 lat = pcibios_max_latency;
2861 else 2863 else
2862 return; 2864 return;
2863 dev_printk(KERN_DEBUG, &dev->dev, "setting latency timer to %d\n", lat); 2865
2864 pci_write_config_byte(dev, PCI_LATENCY_TIMER, lat); 2866 pci_write_config_byte(dev, PCI_LATENCY_TIMER, lat);
2865} 2867}
2866 2868
@@ -2965,7 +2967,7 @@ pci_set_mwi(struct pci_dev *dev)
2965 cmd |= PCI_COMMAND_INVALIDATE; 2967 cmd |= PCI_COMMAND_INVALIDATE;
2966 pci_write_config_word(dev, PCI_COMMAND, cmd); 2968 pci_write_config_word(dev, PCI_COMMAND, cmd);
2967 } 2969 }
2968 2970
2969 return 0; 2971 return 0;
2970} 2972}
2971 2973
@@ -3290,7 +3292,7 @@ clear:
3290 * 3292 *
3291 * NOTE: This causes the caller to sleep for twice the device power transition 3293 * NOTE: This causes the caller to sleep for twice the device power transition
3292 * cooldown period, which for the D0->D3hot and D3hot->D0 transitions is 10 ms 3294 * cooldown period, which for the D0->D3hot and D3hot->D0 transitions is 10 ms
3293 * by devault (i.e. unless the @dev's d3_delay field has a different value). 3295 * by default (i.e. unless the @dev's d3_delay field has a different value).
3294 * Moreover, only devices in D0 can be reset by this function. 3296 * Moreover, only devices in D0 can be reset by this function.
3295 */ 3297 */
3296static int pci_pm_reset(struct pci_dev *dev, int probe) 3298static int pci_pm_reset(struct pci_dev *dev, int probe)
@@ -3339,7 +3341,7 @@ void pci_reset_bridge_secondary_bus(struct pci_dev *dev)
3339 pci_write_config_word(dev, PCI_BRIDGE_CONTROL, ctrl); 3341 pci_write_config_word(dev, PCI_BRIDGE_CONTROL, ctrl);
3340 /* 3342 /*
3341 * PCI spec v3.0 7.6.4.2 requires minimum Trst of 1ms. Double 3343 * PCI spec v3.0 7.6.4.2 requires minimum Trst of 1ms. Double
3342 * this to 2ms to ensure that we meet the minium requirement. 3344 * this to 2ms to ensure that we meet the minimum requirement.
3343 */ 3345 */
3344 msleep(2); 3346 msleep(2);
3345 3347
@@ -3978,6 +3980,7 @@ int pcie_get_mps(struct pci_dev *dev)
3978 3980
3979 return 128 << ((ctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5); 3981 return 128 << ((ctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5);
3980} 3982}
3983EXPORT_SYMBOL(pcie_get_mps);
3981 3984
3982/** 3985/**
3983 * pcie_set_mps - set PCI Express maximum payload size 3986 * pcie_set_mps - set PCI Express maximum payload size
@@ -3995,13 +3998,14 @@ int pcie_set_mps(struct pci_dev *dev, int mps)
3995 return -EINVAL; 3998 return -EINVAL;
3996 3999
3997 v = ffs(mps) - 8; 4000 v = ffs(mps) - 8;
3998 if (v > dev->pcie_mpss) 4001 if (v > dev->pcie_mpss)
3999 return -EINVAL; 4002 return -EINVAL;
4000 v <<= 5; 4003 v <<= 5;
4001 4004
4002 return pcie_capability_clear_and_set_word(dev, PCI_EXP_DEVCTL, 4005 return pcie_capability_clear_and_set_word(dev, PCI_EXP_DEVCTL,
4003 PCI_EXP_DEVCTL_PAYLOAD, v); 4006 PCI_EXP_DEVCTL_PAYLOAD, v);
4004} 4007}
4008EXPORT_SYMBOL(pcie_set_mps);
4005 4009
4006/** 4010/**
4007 * pcie_get_minimum_link - determine minimum link settings of a PCI device 4011 * pcie_get_minimum_link - determine minimum link settings of a PCI device