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.c138
1 files changed, 52 insertions, 86 deletions
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index ba34907538f6..a881c0d3d2e8 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -564,10 +564,6 @@ static void pci_restore_bars(struct pci_dev *dev)
564{ 564{
565 int i; 565 int i;
566 566
567 /* Per SR-IOV spec 3.4.1.11, VF BARs are RO zero */
568 if (dev->is_virtfn)
569 return;
570
571 for (i = 0; i < PCI_BRIDGE_RESOURCES; i++) 567 for (i = 0; i < PCI_BRIDGE_RESOURCES; i++)
572 pci_update_resource(dev, i); 568 pci_update_resource(dev, i);
573} 569}
@@ -2106,6 +2102,10 @@ bool pci_dev_run_wake(struct pci_dev *dev)
2106 if (!dev->pme_support) 2102 if (!dev->pme_support)
2107 return false; 2103 return false;
2108 2104
2105 /* PME-capable in principle, but not from the intended sleep state */
2106 if (!pci_pme_capable(dev, pci_target_state(dev)))
2107 return false;
2108
2109 while (bus->parent) { 2109 while (bus->parent) {
2110 struct pci_dev *bridge = bus->self; 2110 struct pci_dev *bridge = bus->self;
2111 2111
@@ -2226,7 +2226,7 @@ void pci_config_pm_runtime_put(struct pci_dev *pdev)
2226 * This function checks if it is possible to move the bridge to D3. 2226 * This function checks if it is possible to move the bridge to D3.
2227 * Currently we only allow D3 for recent enough PCIe ports. 2227 * Currently we only allow D3 for recent enough PCIe ports.
2228 */ 2228 */
2229static bool pci_bridge_d3_possible(struct pci_dev *bridge) 2229bool pci_bridge_d3_possible(struct pci_dev *bridge)
2230{ 2230{
2231 unsigned int year; 2231 unsigned int year;
2232 2232
@@ -2239,6 +2239,14 @@ static bool pci_bridge_d3_possible(struct pci_dev *bridge)
2239 case PCI_EXP_TYPE_DOWNSTREAM: 2239 case PCI_EXP_TYPE_DOWNSTREAM:
2240 if (pci_bridge_d3_disable) 2240 if (pci_bridge_d3_disable)
2241 return false; 2241 return false;
2242
2243 /*
2244 * Hotplug ports handled by firmware in System Management Mode
2245 * may not be put into D3 by the OS (Thunderbolt on non-Macs).
2246 */
2247 if (bridge->is_hotplug_bridge && !pciehp_is_native(bridge))
2248 return false;
2249
2242 if (pci_bridge_d3_force) 2250 if (pci_bridge_d3_force)
2243 return true; 2251 return true;
2244 2252
@@ -2259,32 +2267,36 @@ static bool pci_bridge_d3_possible(struct pci_dev *bridge)
2259static int pci_dev_check_d3cold(struct pci_dev *dev, void *data) 2267static int pci_dev_check_d3cold(struct pci_dev *dev, void *data)
2260{ 2268{
2261 bool *d3cold_ok = data; 2269 bool *d3cold_ok = data;
2262 bool no_d3cold;
2263 2270
2264 /* 2271 if (/* The device needs to be allowed to go D3cold ... */
2265 * The device needs to be allowed to go D3cold and if it is wake 2272 dev->no_d3cold || !dev->d3cold_allowed ||
2266 * capable to do so from D3cold.
2267 */
2268 no_d3cold = dev->no_d3cold || !dev->d3cold_allowed ||
2269 (device_may_wakeup(&dev->dev) && !pci_pme_capable(dev, PCI_D3cold)) ||
2270 !pci_power_manageable(dev);
2271 2273
2272 *d3cold_ok = !no_d3cold; 2274 /* ... and if it is wakeup capable to do so from D3cold. */
2275 (device_may_wakeup(&dev->dev) &&
2276 !pci_pme_capable(dev, PCI_D3cold)) ||
2273 2277
2274 return no_d3cold; 2278 /* If it is a bridge it must be allowed to go to D3. */
2279 !pci_power_manageable(dev) ||
2280
2281 /* Hotplug interrupts cannot be delivered if the link is down. */
2282 dev->is_hotplug_bridge)
2283
2284 *d3cold_ok = false;
2285
2286 return !*d3cold_ok;
2275} 2287}
2276 2288
2277/* 2289/*
2278 * pci_bridge_d3_update - Update bridge D3 capabilities 2290 * pci_bridge_d3_update - Update bridge D3 capabilities
2279 * @dev: PCI device which is changed 2291 * @dev: PCI device which is changed
2280 * @remove: Is the device being removed
2281 * 2292 *
2282 * Update upstream bridge PM capabilities accordingly depending on if the 2293 * Update upstream bridge PM capabilities accordingly depending on if the
2283 * device PM configuration was changed or the device is being removed. The 2294 * device PM configuration was changed or the device is being removed. The
2284 * change is also propagated upstream. 2295 * change is also propagated upstream.
2285 */ 2296 */
2286static void pci_bridge_d3_update(struct pci_dev *dev, bool remove) 2297void pci_bridge_d3_update(struct pci_dev *dev)
2287{ 2298{
2299 bool remove = !device_is_registered(&dev->dev);
2288 struct pci_dev *bridge; 2300 struct pci_dev *bridge;
2289 bool d3cold_ok = true; 2301 bool d3cold_ok = true;
2290 2302
@@ -2292,55 +2304,39 @@ static void pci_bridge_d3_update(struct pci_dev *dev, bool remove)
2292 if (!bridge || !pci_bridge_d3_possible(bridge)) 2304 if (!bridge || !pci_bridge_d3_possible(bridge))
2293 return; 2305 return;
2294 2306
2295 pci_dev_get(bridge);
2296 /* 2307 /*
2297 * If the device is removed we do not care about its D3cold 2308 * If D3 is currently allowed for the bridge, removing one of its
2298 * capabilities. 2309 * children won't change that.
2310 */
2311 if (remove && bridge->bridge_d3)
2312 return;
2313
2314 /*
2315 * If D3 is currently allowed for the bridge and a child is added or
2316 * changed, disallowance of D3 can only be caused by that child, so
2317 * we only need to check that single device, not any of its siblings.
2318 *
2319 * If D3 is currently not allowed for the bridge, checking the device
2320 * first may allow us to skip checking its siblings.
2299 */ 2321 */
2300 if (!remove) 2322 if (!remove)
2301 pci_dev_check_d3cold(dev, &d3cold_ok); 2323 pci_dev_check_d3cold(dev, &d3cold_ok);
2302 2324
2303 if (d3cold_ok) { 2325 /*
2304 /* 2326 * If D3 is currently not allowed for the bridge, this may be caused
2305 * We need to go through all children to find out if all of 2327 * either by the device being changed/removed or any of its siblings,
2306 * them can still go to D3cold. 2328 * so we need to go through all children to find out if one of them
2307 */ 2329 * continues to block D3.
2330 */
2331 if (d3cold_ok && !bridge->bridge_d3)
2308 pci_walk_bus(bridge->subordinate, pci_dev_check_d3cold, 2332 pci_walk_bus(bridge->subordinate, pci_dev_check_d3cold,
2309 &d3cold_ok); 2333 &d3cold_ok);
2310 }
2311 2334
2312 if (bridge->bridge_d3 != d3cold_ok) { 2335 if (bridge->bridge_d3 != d3cold_ok) {
2313 bridge->bridge_d3 = d3cold_ok; 2336 bridge->bridge_d3 = d3cold_ok;
2314 /* Propagate change to upstream bridges */ 2337 /* Propagate change to upstream bridges */
2315 pci_bridge_d3_update(bridge, false); 2338 pci_bridge_d3_update(bridge);
2316 } 2339 }
2317
2318 pci_dev_put(bridge);
2319}
2320
2321/**
2322 * pci_bridge_d3_device_changed - Update bridge D3 capabilities on change
2323 * @dev: PCI device that was changed
2324 *
2325 * If a device is added or its PM configuration, such as is it allowed to
2326 * enter D3cold, is changed this function updates upstream bridge PM
2327 * capabilities accordingly.
2328 */
2329void pci_bridge_d3_device_changed(struct pci_dev *dev)
2330{
2331 pci_bridge_d3_update(dev, false);
2332}
2333
2334/**
2335 * pci_bridge_d3_device_removed - Update bridge D3 capabilities on remove
2336 * @dev: PCI device being removed
2337 *
2338 * Function updates upstream bridge PM capabilities based on other devices
2339 * still left on the bus.
2340 */
2341void pci_bridge_d3_device_removed(struct pci_dev *dev)
2342{
2343 pci_bridge_d3_update(dev, true);
2344} 2340}
2345 2341
2346/** 2342/**
@@ -2355,7 +2351,7 @@ void pci_d3cold_enable(struct pci_dev *dev)
2355{ 2351{
2356 if (dev->no_d3cold) { 2352 if (dev->no_d3cold) {
2357 dev->no_d3cold = false; 2353 dev->no_d3cold = false;
2358 pci_bridge_d3_device_changed(dev); 2354 pci_bridge_d3_update(dev);
2359 } 2355 }
2360} 2356}
2361EXPORT_SYMBOL_GPL(pci_d3cold_enable); 2357EXPORT_SYMBOL_GPL(pci_d3cold_enable);
@@ -2372,7 +2368,7 @@ void pci_d3cold_disable(struct pci_dev *dev)
2372{ 2368{
2373 if (!dev->no_d3cold) { 2369 if (!dev->no_d3cold) {
2374 dev->no_d3cold = true; 2370 dev->no_d3cold = true;
2375 pci_bridge_d3_device_changed(dev); 2371 pci_bridge_d3_update(dev);
2376 } 2372 }
2377} 2373}
2378EXPORT_SYMBOL_GPL(pci_d3cold_disable); 2374EXPORT_SYMBOL_GPL(pci_d3cold_disable);
@@ -4831,36 +4827,6 @@ int pci_select_bars(struct pci_dev *dev, unsigned long flags)
4831} 4827}
4832EXPORT_SYMBOL(pci_select_bars); 4828EXPORT_SYMBOL(pci_select_bars);
4833 4829
4834/**
4835 * pci_resource_bar - get position of the BAR associated with a resource
4836 * @dev: the PCI device
4837 * @resno: the resource number
4838 * @type: the BAR type to be filled in
4839 *
4840 * Returns BAR position in config space, or 0 if the BAR is invalid.
4841 */
4842int pci_resource_bar(struct pci_dev *dev, int resno, enum pci_bar_type *type)
4843{
4844 int reg;
4845
4846 if (resno < PCI_ROM_RESOURCE) {
4847 *type = pci_bar_unknown;
4848 return PCI_BASE_ADDRESS_0 + 4 * resno;
4849 } else if (resno == PCI_ROM_RESOURCE) {
4850 *type = pci_bar_mem32;
4851 return dev->rom_base_reg;
4852 } else if (resno < PCI_BRIDGE_RESOURCES) {
4853 /* device specific resource */
4854 *type = pci_bar_unknown;
4855 reg = pci_iov_resource_bar(dev, resno);
4856 if (reg)
4857 return reg;
4858 }
4859
4860 dev_err(&dev->dev, "BAR %d: invalid resource\n", resno);
4861 return 0;
4862}
4863
4864/* Some architectures require additional programming to enable VGA */ 4830/* Some architectures require additional programming to enable VGA */
4865static arch_set_vga_state_t arch_set_vga_state; 4831static arch_set_vga_state_t arch_set_vga_state;
4866 4832