diff options
Diffstat (limited to 'drivers/pci/pci.c')
-rw-r--r-- | drivers/pci/pci.c | 71 |
1 files changed, 52 insertions, 19 deletions
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 68e3b2b0da93..b0002daa50f3 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c | |||
@@ -52,6 +52,7 @@ static void pci_pme_list_scan(struct work_struct *work); | |||
52 | static LIST_HEAD(pci_pme_list); | 52 | static LIST_HEAD(pci_pme_list); |
53 | static DEFINE_MUTEX(pci_pme_list_mutex); | 53 | static DEFINE_MUTEX(pci_pme_list_mutex); |
54 | static DECLARE_DELAYED_WORK(pci_pme_work, pci_pme_list_scan); | 54 | static DECLARE_DELAYED_WORK(pci_pme_work, pci_pme_list_scan); |
55 | static DEFINE_MUTEX(pci_bridge_mutex); | ||
55 | 56 | ||
56 | struct pci_pme_device { | 57 | struct pci_pme_device { |
57 | struct list_head list; | 58 | struct list_head list; |
@@ -892,7 +893,9 @@ EXPORT_SYMBOL_GPL(__pci_complete_power_transition); | |||
892 | * -EINVAL if the requested state is invalid. | 893 | * -EINVAL if the requested state is invalid. |
893 | * -EIO if device does not support PCI PM or its PM capabilities register has a | 894 | * -EIO if device does not support PCI PM or its PM capabilities register has a |
894 | * wrong version, or device doesn't support the requested state. | 895 | * wrong version, or device doesn't support the requested state. |
896 | * 0 if the transition is to D1 or D2 but D1 and D2 are not supported. | ||
895 | * 0 if device already is in the requested state. | 897 | * 0 if device already is in the requested state. |
898 | * 0 if the transition is to D3 but D3 is not supported. | ||
896 | * 0 if device's power state has been successfully changed. | 899 | * 0 if device's power state has been successfully changed. |
897 | */ | 900 | */ |
898 | int pci_set_power_state(struct pci_dev *dev, pci_power_t state) | 901 | int pci_set_power_state(struct pci_dev *dev, pci_power_t state) |
@@ -1348,10 +1351,16 @@ static void pci_enable_bridge(struct pci_dev *dev) | |||
1348 | if (bridge) | 1351 | if (bridge) |
1349 | pci_enable_bridge(bridge); | 1352 | pci_enable_bridge(bridge); |
1350 | 1353 | ||
1354 | /* | ||
1355 | * Hold pci_bridge_mutex to prevent a race when enabling two | ||
1356 | * devices below the bridge simultaneously. The race may cause a | ||
1357 | * PCI_COMMAND_MEMORY update to be lost (see changelog). | ||
1358 | */ | ||
1359 | mutex_lock(&pci_bridge_mutex); | ||
1351 | if (pci_is_enabled(dev)) { | 1360 | if (pci_is_enabled(dev)) { |
1352 | if (!dev->is_busmaster) | 1361 | if (!dev->is_busmaster) |
1353 | pci_set_master(dev); | 1362 | pci_set_master(dev); |
1354 | return; | 1363 | goto end; |
1355 | } | 1364 | } |
1356 | 1365 | ||
1357 | retval = pci_enable_device(dev); | 1366 | retval = pci_enable_device(dev); |
@@ -1359,6 +1368,8 @@ static void pci_enable_bridge(struct pci_dev *dev) | |||
1359 | dev_err(&dev->dev, "Error enabling bridge (%d), continuing\n", | 1368 | dev_err(&dev->dev, "Error enabling bridge (%d), continuing\n", |
1360 | retval); | 1369 | retval); |
1361 | pci_set_master(dev); | 1370 | pci_set_master(dev); |
1371 | end: | ||
1372 | mutex_unlock(&pci_bridge_mutex); | ||
1362 | } | 1373 | } |
1363 | 1374 | ||
1364 | static int pci_enable_device_flags(struct pci_dev *dev, unsigned long flags) | 1375 | static int pci_enable_device_flags(struct pci_dev *dev, unsigned long flags) |
@@ -1383,7 +1394,7 @@ static int pci_enable_device_flags(struct pci_dev *dev, unsigned long flags) | |||
1383 | return 0; /* already enabled */ | 1394 | return 0; /* already enabled */ |
1384 | 1395 | ||
1385 | bridge = pci_upstream_bridge(dev); | 1396 | bridge = pci_upstream_bridge(dev); |
1386 | if (bridge) | 1397 | if (bridge && !pci_is_enabled(bridge)) |
1387 | pci_enable_bridge(bridge); | 1398 | pci_enable_bridge(bridge); |
1388 | 1399 | ||
1389 | /* only skip sriov related */ | 1400 | /* only skip sriov related */ |
@@ -3818,27 +3829,49 @@ int pci_wait_for_pending_transaction(struct pci_dev *dev) | |||
3818 | } | 3829 | } |
3819 | EXPORT_SYMBOL(pci_wait_for_pending_transaction); | 3830 | EXPORT_SYMBOL(pci_wait_for_pending_transaction); |
3820 | 3831 | ||
3821 | /* | ||
3822 | * We should only need to wait 100ms after FLR, but some devices take longer. | ||
3823 | * Wait for up to 1000ms for config space to return something other than -1. | ||
3824 | * Intel IGD requires this when an LCD panel is attached. We read the 2nd | ||
3825 | * dword because VFs don't implement the 1st dword. | ||
3826 | */ | ||
3827 | static void pci_flr_wait(struct pci_dev *dev) | 3832 | static void pci_flr_wait(struct pci_dev *dev) |
3828 | { | 3833 | { |
3829 | int i = 0; | 3834 | int delay = 1, timeout = 60000; |
3830 | u32 id; | 3835 | u32 id; |
3831 | 3836 | ||
3832 | do { | 3837 | /* |
3833 | msleep(100); | 3838 | * Per PCIe r3.1, sec 6.6.2, a device must complete an FLR within |
3839 | * 100ms, but may silently discard requests while the FLR is in | ||
3840 | * progress. Wait 100ms before trying to access the device. | ||
3841 | */ | ||
3842 | msleep(100); | ||
3843 | |||
3844 | /* | ||
3845 | * After 100ms, the device should not silently discard config | ||
3846 | * requests, but it may still indicate that it needs more time by | ||
3847 | * responding to them with CRS completions. The Root Port will | ||
3848 | * generally synthesize ~0 data to complete the read (except when | ||
3849 | * CRS SV is enabled and the read was for the Vendor ID; in that | ||
3850 | * case it synthesizes 0x0001 data). | ||
3851 | * | ||
3852 | * Wait for the device to return a non-CRS completion. Read the | ||
3853 | * Command register instead of Vendor ID so we don't have to | ||
3854 | * contend with the CRS SV value. | ||
3855 | */ | ||
3856 | pci_read_config_dword(dev, PCI_COMMAND, &id); | ||
3857 | while (id == ~0) { | ||
3858 | if (delay > timeout) { | ||
3859 | dev_warn(&dev->dev, "not ready %dms after FLR; giving up\n", | ||
3860 | 100 + delay - 1); | ||
3861 | return; | ||
3862 | } | ||
3863 | |||
3864 | if (delay > 1000) | ||
3865 | dev_info(&dev->dev, "not ready %dms after FLR; waiting\n", | ||
3866 | 100 + delay - 1); | ||
3867 | |||
3868 | msleep(delay); | ||
3869 | delay *= 2; | ||
3834 | pci_read_config_dword(dev, PCI_COMMAND, &id); | 3870 | pci_read_config_dword(dev, PCI_COMMAND, &id); |
3835 | } while (i++ < 10 && id == ~0); | 3871 | } |
3836 | 3872 | ||
3837 | if (id == ~0) | 3873 | if (delay > 1000) |
3838 | dev_warn(&dev->dev, "Failed to return from FLR\n"); | 3874 | dev_info(&dev->dev, "ready %dms after FLR\n", 100 + delay - 1); |
3839 | else if (i > 1) | ||
3840 | dev_info(&dev->dev, "Required additional %dms to return from FLR\n", | ||
3841 | (i - 1) * 100); | ||
3842 | } | 3875 | } |
3843 | 3876 | ||
3844 | /** | 3877 | /** |
@@ -5405,8 +5438,8 @@ static int of_pci_bus_find_domain_nr(struct device *parent) | |||
5405 | use_dt_domains = 0; | 5438 | use_dt_domains = 0; |
5406 | domain = pci_get_new_domain_nr(); | 5439 | domain = pci_get_new_domain_nr(); |
5407 | } else { | 5440 | } else { |
5408 | dev_err(parent, "Node %s has inconsistent \"linux,pci-domain\" property in DT\n", | 5441 | dev_err(parent, "Node %pOF has inconsistent \"linux,pci-domain\" property in DT\n", |
5409 | parent->of_node->full_name); | 5442 | parent->of_node); |
5410 | domain = -1; | 5443 | domain = -1; |
5411 | } | 5444 | } |
5412 | 5445 | ||