diff options
Diffstat (limited to 'drivers/pci/pci.c')
-rw-r--r-- | drivers/pci/pci.c | 123 |
1 files changed, 75 insertions, 48 deletions
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index fdbc294821e6..759475ef6ff3 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c | |||
@@ -108,12 +108,12 @@ static bool pcie_ari_disabled; | |||
108 | */ | 108 | */ |
109 | unsigned char pci_bus_max_busnr(struct pci_bus* bus) | 109 | unsigned char pci_bus_max_busnr(struct pci_bus* bus) |
110 | { | 110 | { |
111 | struct list_head *tmp; | 111 | struct pci_bus *tmp; |
112 | unsigned char max, n; | 112 | unsigned char max, n; |
113 | 113 | ||
114 | max = bus->busn_res.end; | 114 | max = bus->busn_res.end; |
115 | list_for_each(tmp, &bus->children) { | 115 | list_for_each_entry(tmp, &bus->children, node) { |
116 | n = pci_bus_max_busnr(pci_bus_b(tmp)); | 116 | n = pci_bus_max_busnr(tmp); |
117 | if(n > max) | 117 | if(n > max) |
118 | max = n; | 118 | max = n; |
119 | } | 119 | } |
@@ -401,33 +401,40 @@ EXPORT_SYMBOL_GPL(pci_find_ht_capability); | |||
401 | * @res: child resource record for which parent is sought | 401 | * @res: child resource record for which parent is sought |
402 | * | 402 | * |
403 | * For given resource region of given device, return the resource | 403 | * For given resource region of given device, return the resource |
404 | * region of parent bus the given region is contained in or where | 404 | * region of parent bus the given region is contained in. |
405 | * it should be allocated from. | ||
406 | */ | 405 | */ |
407 | struct resource * | 406 | struct resource * |
408 | pci_find_parent_resource(const struct pci_dev *dev, struct resource *res) | 407 | pci_find_parent_resource(const struct pci_dev *dev, struct resource *res) |
409 | { | 408 | { |
410 | const struct pci_bus *bus = dev->bus; | 409 | const struct pci_bus *bus = dev->bus; |
410 | struct resource *r; | ||
411 | int i; | 411 | int i; |
412 | struct resource *best = NULL, *r; | ||
413 | 412 | ||
414 | pci_bus_for_each_resource(bus, r, i) { | 413 | pci_bus_for_each_resource(bus, r, i) { |
415 | if (!r) | 414 | if (!r) |
416 | continue; | 415 | continue; |
417 | if (res->start && !(res->start >= r->start && res->end <= r->end)) | 416 | if (res->start && resource_contains(r, res)) { |
418 | continue; /* Not contained */ | 417 | |
419 | if ((res->flags ^ r->flags) & (IORESOURCE_IO | IORESOURCE_MEM)) | 418 | /* |
420 | continue; /* Wrong type */ | 419 | * If the window is prefetchable but the BAR is |
421 | if (!((res->flags ^ r->flags) & IORESOURCE_PREFETCH)) | 420 | * not, the allocator made a mistake. |
422 | return r; /* Exact match */ | 421 | */ |
423 | /* We can't insert a non-prefetch resource inside a prefetchable parent .. */ | 422 | if (r->flags & IORESOURCE_PREFETCH && |
424 | if (r->flags & IORESOURCE_PREFETCH) | 423 | !(res->flags & IORESOURCE_PREFETCH)) |
425 | continue; | 424 | return NULL; |
426 | /* .. but we can put a prefetchable resource inside a non-prefetchable one */ | 425 | |
427 | if (!best) | 426 | /* |
428 | best = r; | 427 | * If we're below a transparent bridge, there may |
428 | * be both a positively-decoded aperture and a | ||
429 | * subtractively-decoded region that contain the BAR. | ||
430 | * We want the positively-decoded one, so this depends | ||
431 | * on pci_bus_for_each_resource() giving us those | ||
432 | * first. | ||
433 | */ | ||
434 | return r; | ||
435 | } | ||
429 | } | 436 | } |
430 | return best; | 437 | return NULL; |
431 | } | 438 | } |
432 | 439 | ||
433 | /** | 440 | /** |
@@ -1178,6 +1185,11 @@ int pci_load_and_free_saved_state(struct pci_dev *dev, | |||
1178 | } | 1185 | } |
1179 | EXPORT_SYMBOL_GPL(pci_load_and_free_saved_state); | 1186 | EXPORT_SYMBOL_GPL(pci_load_and_free_saved_state); |
1180 | 1187 | ||
1188 | int __weak pcibios_enable_device(struct pci_dev *dev, int bars) | ||
1189 | { | ||
1190 | return pci_enable_resources(dev, bars); | ||
1191 | } | ||
1192 | |||
1181 | static int do_pci_enable_device(struct pci_dev *dev, int bars) | 1193 | static int do_pci_enable_device(struct pci_dev *dev, int bars) |
1182 | { | 1194 | { |
1183 | int err; | 1195 | int err; |
@@ -1624,29 +1636,27 @@ static void pci_pme_list_scan(struct work_struct *work) | |||
1624 | struct pci_pme_device *pme_dev, *n; | 1636 | struct pci_pme_device *pme_dev, *n; |
1625 | 1637 | ||
1626 | mutex_lock(&pci_pme_list_mutex); | 1638 | mutex_lock(&pci_pme_list_mutex); |
1627 | if (!list_empty(&pci_pme_list)) { | 1639 | list_for_each_entry_safe(pme_dev, n, &pci_pme_list, list) { |
1628 | list_for_each_entry_safe(pme_dev, n, &pci_pme_list, list) { | 1640 | if (pme_dev->dev->pme_poll) { |
1629 | if (pme_dev->dev->pme_poll) { | 1641 | struct pci_dev *bridge; |
1630 | struct pci_dev *bridge; | 1642 | |
1631 | 1643 | bridge = pme_dev->dev->bus->self; | |
1632 | bridge = pme_dev->dev->bus->self; | 1644 | /* |
1633 | /* | 1645 | * If bridge is in low power state, the |
1634 | * If bridge is in low power state, the | 1646 | * configuration space of subordinate devices |
1635 | * configuration space of subordinate devices | 1647 | * may be not accessible |
1636 | * may be not accessible | 1648 | */ |
1637 | */ | 1649 | if (bridge && bridge->current_state != PCI_D0) |
1638 | if (bridge && bridge->current_state != PCI_D0) | 1650 | continue; |
1639 | continue; | 1651 | pci_pme_wakeup(pme_dev->dev, NULL); |
1640 | pci_pme_wakeup(pme_dev->dev, NULL); | 1652 | } else { |
1641 | } else { | 1653 | list_del(&pme_dev->list); |
1642 | list_del(&pme_dev->list); | 1654 | kfree(pme_dev); |
1643 | kfree(pme_dev); | ||
1644 | } | ||
1645 | } | 1655 | } |
1646 | if (!list_empty(&pci_pme_list)) | ||
1647 | schedule_delayed_work(&pci_pme_work, | ||
1648 | msecs_to_jiffies(PME_TIMEOUT)); | ||
1649 | } | 1656 | } |
1657 | if (!list_empty(&pci_pme_list)) | ||
1658 | schedule_delayed_work(&pci_pme_work, | ||
1659 | msecs_to_jiffies(PME_TIMEOUT)); | ||
1650 | mutex_unlock(&pci_pme_list_mutex); | 1660 | mutex_unlock(&pci_pme_list_mutex); |
1651 | } | 1661 | } |
1652 | 1662 | ||
@@ -2193,21 +2203,18 @@ void pci_request_acs(void) | |||
2193 | } | 2203 | } |
2194 | 2204 | ||
2195 | /** | 2205 | /** |
2196 | * pci_enable_acs - enable ACS if hardware support it | 2206 | * pci_std_enable_acs - enable ACS on devices using standard ACS capabilites |
2197 | * @dev: the PCI device | 2207 | * @dev: the PCI device |
2198 | */ | 2208 | */ |
2199 | void pci_enable_acs(struct pci_dev *dev) | 2209 | static int pci_std_enable_acs(struct pci_dev *dev) |
2200 | { | 2210 | { |
2201 | int pos; | 2211 | int pos; |
2202 | u16 cap; | 2212 | u16 cap; |
2203 | u16 ctrl; | 2213 | u16 ctrl; |
2204 | 2214 | ||
2205 | if (!pci_acs_enable) | ||
2206 | return; | ||
2207 | |||
2208 | pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ACS); | 2215 | pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ACS); |
2209 | if (!pos) | 2216 | if (!pos) |
2210 | return; | 2217 | return -ENODEV; |
2211 | 2218 | ||
2212 | pci_read_config_word(dev, pos + PCI_ACS_CAP, &cap); | 2219 | pci_read_config_word(dev, pos + PCI_ACS_CAP, &cap); |
2213 | pci_read_config_word(dev, pos + PCI_ACS_CTRL, &ctrl); | 2220 | pci_read_config_word(dev, pos + PCI_ACS_CTRL, &ctrl); |
@@ -2225,6 +2232,23 @@ void pci_enable_acs(struct pci_dev *dev) | |||
2225 | ctrl |= (cap & PCI_ACS_UF); | 2232 | ctrl |= (cap & PCI_ACS_UF); |
2226 | 2233 | ||
2227 | pci_write_config_word(dev, pos + PCI_ACS_CTRL, ctrl); | 2234 | pci_write_config_word(dev, pos + PCI_ACS_CTRL, ctrl); |
2235 | |||
2236 | return 0; | ||
2237 | } | ||
2238 | |||
2239 | /** | ||
2240 | * pci_enable_acs - enable ACS if hardware support it | ||
2241 | * @dev: the PCI device | ||
2242 | */ | ||
2243 | void pci_enable_acs(struct pci_dev *dev) | ||
2244 | { | ||
2245 | if (!pci_acs_enable) | ||
2246 | return; | ||
2247 | |||
2248 | if (!pci_std_enable_acs(dev)) | ||
2249 | return; | ||
2250 | |||
2251 | pci_dev_specific_enable_acs(dev); | ||
2228 | } | 2252 | } |
2229 | 2253 | ||
2230 | static bool pci_acs_flags_enabled(struct pci_dev *pdev, u16 acs_flags) | 2254 | static bool pci_acs_flags_enabled(struct pci_dev *pdev, u16 acs_flags) |
@@ -3043,7 +3067,8 @@ int pci_wait_for_pending_transaction(struct pci_dev *dev) | |||
3043 | if (!pci_is_pcie(dev)) | 3067 | if (!pci_is_pcie(dev)) |
3044 | return 1; | 3068 | return 1; |
3045 | 3069 | ||
3046 | return pci_wait_for_pending(dev, PCI_EXP_DEVSTA, PCI_EXP_DEVSTA_TRPND); | 3070 | return pci_wait_for_pending(dev, pci_pcie_cap(dev) + PCI_EXP_DEVSTA, |
3071 | PCI_EXP_DEVSTA_TRPND); | ||
3047 | } | 3072 | } |
3048 | EXPORT_SYMBOL(pci_wait_for_pending_transaction); | 3073 | EXPORT_SYMBOL(pci_wait_for_pending_transaction); |
3049 | 3074 | ||
@@ -3085,7 +3110,7 @@ static int pci_af_flr(struct pci_dev *dev, int probe) | |||
3085 | return 0; | 3110 | return 0; |
3086 | 3111 | ||
3087 | /* Wait for Transaction Pending bit clean */ | 3112 | /* Wait for Transaction Pending bit clean */ |
3088 | if (pci_wait_for_pending(dev, PCI_AF_STATUS, PCI_AF_STATUS_TP)) | 3113 | if (pci_wait_for_pending(dev, pos + PCI_AF_STATUS, PCI_AF_STATUS_TP)) |
3089 | goto clear; | 3114 | goto clear; |
3090 | 3115 | ||
3091 | dev_err(&dev->dev, "transaction is not cleared; " | 3116 | dev_err(&dev->dev, "transaction is not cleared; " |
@@ -4250,6 +4275,7 @@ void pci_reassigndev_resource_alignment(struct pci_dev *dev) | |||
4250 | "Rounding up size of resource #%d to %#llx.\n", | 4275 | "Rounding up size of resource #%d to %#llx.\n", |
4251 | i, (unsigned long long)size); | 4276 | i, (unsigned long long)size); |
4252 | } | 4277 | } |
4278 | r->flags |= IORESOURCE_UNSET; | ||
4253 | r->end = size - 1; | 4279 | r->end = size - 1; |
4254 | r->start = 0; | 4280 | r->start = 0; |
4255 | } | 4281 | } |
@@ -4263,6 +4289,7 @@ void pci_reassigndev_resource_alignment(struct pci_dev *dev) | |||
4263 | r = &dev->resource[i]; | 4289 | r = &dev->resource[i]; |
4264 | if (!(r->flags & IORESOURCE_MEM)) | 4290 | if (!(r->flags & IORESOURCE_MEM)) |
4265 | continue; | 4291 | continue; |
4292 | r->flags |= IORESOURCE_UNSET; | ||
4266 | r->end = resource_size(r) - 1; | 4293 | r->end = resource_size(r) - 1; |
4267 | r->start = 0; | 4294 | r->start = 0; |
4268 | } | 4295 | } |