diff options
Diffstat (limited to 'drivers/pci/pci.c')
-rw-r--r-- | drivers/pci/pci.c | 568 |
1 files changed, 529 insertions, 39 deletions
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 7fa3cbd742c5..692671b11667 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c | |||
@@ -38,6 +38,19 @@ EXPORT_SYMBOL(pci_pci_problems); | |||
38 | 38 | ||
39 | unsigned int pci_pm_d3_delay; | 39 | unsigned int pci_pm_d3_delay; |
40 | 40 | ||
41 | static void pci_pme_list_scan(struct work_struct *work); | ||
42 | |||
43 | static LIST_HEAD(pci_pme_list); | ||
44 | static DEFINE_MUTEX(pci_pme_list_mutex); | ||
45 | static DECLARE_DELAYED_WORK(pci_pme_work, pci_pme_list_scan); | ||
46 | |||
47 | struct pci_pme_device { | ||
48 | struct list_head list; | ||
49 | struct pci_dev *dev; | ||
50 | }; | ||
51 | |||
52 | #define PME_TIMEOUT 1000 /* How long between PME checks */ | ||
53 | |||
41 | static void pci_dev_d3_sleep(struct pci_dev *dev) | 54 | static void pci_dev_d3_sleep(struct pci_dev *dev) |
42 | { | 55 | { |
43 | unsigned int delay = dev->d3_delay; | 56 | unsigned int delay = dev->d3_delay; |
@@ -727,6 +740,12 @@ int pci_set_power_state(struct pci_dev *dev, pci_power_t state) | |||
727 | 740 | ||
728 | if (!__pci_complete_power_transition(dev, state)) | 741 | if (!__pci_complete_power_transition(dev, state)) |
729 | error = 0; | 742 | error = 0; |
743 | /* | ||
744 | * When aspm_policy is "powersave" this call ensures | ||
745 | * that ASPM is configured. | ||
746 | */ | ||
747 | if (!error && dev->bus->self) | ||
748 | pcie_aspm_powersave_config_link(dev->bus->self); | ||
730 | 749 | ||
731 | return error; | 750 | return error; |
732 | } | 751 | } |
@@ -811,7 +830,7 @@ static int pci_save_pcie_state(struct pci_dev *dev) | |||
811 | dev_err(&dev->dev, "buffer not found in %s\n", __func__); | 830 | dev_err(&dev->dev, "buffer not found in %s\n", __func__); |
812 | return -ENOMEM; | 831 | return -ENOMEM; |
813 | } | 832 | } |
814 | cap = (u16 *)&save_state->data[0]; | 833 | cap = (u16 *)&save_state->cap.data[0]; |
815 | 834 | ||
816 | pci_read_config_word(dev, pos + PCI_EXP_FLAGS, &flags); | 835 | pci_read_config_word(dev, pos + PCI_EXP_FLAGS, &flags); |
817 | 836 | ||
@@ -844,7 +863,7 @@ static void pci_restore_pcie_state(struct pci_dev *dev) | |||
844 | pos = pci_find_capability(dev, PCI_CAP_ID_EXP); | 863 | pos = pci_find_capability(dev, PCI_CAP_ID_EXP); |
845 | if (!save_state || pos <= 0) | 864 | if (!save_state || pos <= 0) |
846 | return; | 865 | return; |
847 | cap = (u16 *)&save_state->data[0]; | 866 | cap = (u16 *)&save_state->cap.data[0]; |
848 | 867 | ||
849 | pci_read_config_word(dev, pos + PCI_EXP_FLAGS, &flags); | 868 | pci_read_config_word(dev, pos + PCI_EXP_FLAGS, &flags); |
850 | 869 | ||
@@ -880,7 +899,8 @@ static int pci_save_pcix_state(struct pci_dev *dev) | |||
880 | return -ENOMEM; | 899 | return -ENOMEM; |
881 | } | 900 | } |
882 | 901 | ||
883 | pci_read_config_word(dev, pos + PCI_X_CMD, (u16 *)save_state->data); | 902 | pci_read_config_word(dev, pos + PCI_X_CMD, |
903 | (u16 *)save_state->cap.data); | ||
884 | 904 | ||
885 | return 0; | 905 | return 0; |
886 | } | 906 | } |
@@ -895,7 +915,7 @@ static void pci_restore_pcix_state(struct pci_dev *dev) | |||
895 | pos = pci_find_capability(dev, PCI_CAP_ID_PCIX); | 915 | pos = pci_find_capability(dev, PCI_CAP_ID_PCIX); |
896 | if (!save_state || pos <= 0) | 916 | if (!save_state || pos <= 0) |
897 | return; | 917 | return; |
898 | cap = (u16 *)&save_state->data[0]; | 918 | cap = (u16 *)&save_state->cap.data[0]; |
899 | 919 | ||
900 | pci_write_config_word(dev, pos + PCI_X_CMD, cap[i++]); | 920 | pci_write_config_word(dev, pos + PCI_X_CMD, cap[i++]); |
901 | } | 921 | } |
@@ -924,14 +944,13 @@ pci_save_state(struct pci_dev *dev) | |||
924 | * pci_restore_state - Restore the saved state of a PCI device | 944 | * pci_restore_state - Restore the saved state of a PCI device |
925 | * @dev: - PCI device that we're dealing with | 945 | * @dev: - PCI device that we're dealing with |
926 | */ | 946 | */ |
927 | int | 947 | void pci_restore_state(struct pci_dev *dev) |
928 | pci_restore_state(struct pci_dev *dev) | ||
929 | { | 948 | { |
930 | int i; | 949 | int i; |
931 | u32 val; | 950 | u32 val; |
932 | 951 | ||
933 | if (!dev->state_saved) | 952 | if (!dev->state_saved) |
934 | return 0; | 953 | return; |
935 | 954 | ||
936 | /* PCI Express register must be restored first */ | 955 | /* PCI Express register must be restored first */ |
937 | pci_restore_pcie_state(dev); | 956 | pci_restore_pcie_state(dev); |
@@ -955,9 +974,105 @@ pci_restore_state(struct pci_dev *dev) | |||
955 | pci_restore_iov_state(dev); | 974 | pci_restore_iov_state(dev); |
956 | 975 | ||
957 | dev->state_saved = false; | 976 | dev->state_saved = false; |
977 | } | ||
978 | |||
979 | struct pci_saved_state { | ||
980 | u32 config_space[16]; | ||
981 | struct pci_cap_saved_data cap[0]; | ||
982 | }; | ||
983 | |||
984 | /** | ||
985 | * pci_store_saved_state - Allocate and return an opaque struct containing | ||
986 | * the device saved state. | ||
987 | * @dev: PCI device that we're dealing with | ||
988 | * | ||
989 | * Rerturn NULL if no state or error. | ||
990 | */ | ||
991 | struct pci_saved_state *pci_store_saved_state(struct pci_dev *dev) | ||
992 | { | ||
993 | struct pci_saved_state *state; | ||
994 | struct pci_cap_saved_state *tmp; | ||
995 | struct pci_cap_saved_data *cap; | ||
996 | struct hlist_node *pos; | ||
997 | size_t size; | ||
998 | |||
999 | if (!dev->state_saved) | ||
1000 | return NULL; | ||
1001 | |||
1002 | size = sizeof(*state) + sizeof(struct pci_cap_saved_data); | ||
1003 | |||
1004 | hlist_for_each_entry(tmp, pos, &dev->saved_cap_space, next) | ||
1005 | size += sizeof(struct pci_cap_saved_data) + tmp->cap.size; | ||
1006 | |||
1007 | state = kzalloc(size, GFP_KERNEL); | ||
1008 | if (!state) | ||
1009 | return NULL; | ||
1010 | |||
1011 | memcpy(state->config_space, dev->saved_config_space, | ||
1012 | sizeof(state->config_space)); | ||
1013 | |||
1014 | cap = state->cap; | ||
1015 | hlist_for_each_entry(tmp, pos, &dev->saved_cap_space, next) { | ||
1016 | size_t len = sizeof(struct pci_cap_saved_data) + tmp->cap.size; | ||
1017 | memcpy(cap, &tmp->cap, len); | ||
1018 | cap = (struct pci_cap_saved_data *)((u8 *)cap + len); | ||
1019 | } | ||
1020 | /* Empty cap_save terminates list */ | ||
1021 | |||
1022 | return state; | ||
1023 | } | ||
1024 | EXPORT_SYMBOL_GPL(pci_store_saved_state); | ||
1025 | |||
1026 | /** | ||
1027 | * pci_load_saved_state - Reload the provided save state into struct pci_dev. | ||
1028 | * @dev: PCI device that we're dealing with | ||
1029 | * @state: Saved state returned from pci_store_saved_state() | ||
1030 | */ | ||
1031 | int pci_load_saved_state(struct pci_dev *dev, struct pci_saved_state *state) | ||
1032 | { | ||
1033 | struct pci_cap_saved_data *cap; | ||
1034 | |||
1035 | dev->state_saved = false; | ||
1036 | |||
1037 | if (!state) | ||
1038 | return 0; | ||
1039 | |||
1040 | memcpy(dev->saved_config_space, state->config_space, | ||
1041 | sizeof(state->config_space)); | ||
1042 | |||
1043 | cap = state->cap; | ||
1044 | while (cap->size) { | ||
1045 | struct pci_cap_saved_state *tmp; | ||
1046 | |||
1047 | tmp = pci_find_saved_cap(dev, cap->cap_nr); | ||
1048 | if (!tmp || tmp->cap.size != cap->size) | ||
1049 | return -EINVAL; | ||
958 | 1050 | ||
1051 | memcpy(tmp->cap.data, cap->data, tmp->cap.size); | ||
1052 | cap = (struct pci_cap_saved_data *)((u8 *)cap + | ||
1053 | sizeof(struct pci_cap_saved_data) + cap->size); | ||
1054 | } | ||
1055 | |||
1056 | dev->state_saved = true; | ||
959 | return 0; | 1057 | return 0; |
960 | } | 1058 | } |
1059 | EXPORT_SYMBOL_GPL(pci_load_saved_state); | ||
1060 | |||
1061 | /** | ||
1062 | * pci_load_and_free_saved_state - Reload the save state pointed to by state, | ||
1063 | * and free the memory allocated for it. | ||
1064 | * @dev: PCI device that we're dealing with | ||
1065 | * @state: Pointer to saved state returned from pci_store_saved_state() | ||
1066 | */ | ||
1067 | int pci_load_and_free_saved_state(struct pci_dev *dev, | ||
1068 | struct pci_saved_state **state) | ||
1069 | { | ||
1070 | int ret = pci_load_saved_state(dev, *state); | ||
1071 | kfree(*state); | ||
1072 | *state = NULL; | ||
1073 | return ret; | ||
1074 | } | ||
1075 | EXPORT_SYMBOL_GPL(pci_load_and_free_saved_state); | ||
961 | 1076 | ||
962 | static int do_pci_enable_device(struct pci_dev *dev, int bars) | 1077 | static int do_pci_enable_device(struct pci_dev *dev, int bars) |
963 | { | 1078 | { |
@@ -994,6 +1109,18 @@ static int __pci_enable_device_flags(struct pci_dev *dev, | |||
994 | int err; | 1109 | int err; |
995 | int i, bars = 0; | 1110 | int i, bars = 0; |
996 | 1111 | ||
1112 | /* | ||
1113 | * Power state could be unknown at this point, either due to a fresh | ||
1114 | * boot or a device removal call. So get the current power state | ||
1115 | * so that things like MSI message writing will behave as expected | ||
1116 | * (e.g. if the device really is in D0 at enable time). | ||
1117 | */ | ||
1118 | if (dev->pm_cap) { | ||
1119 | u16 pmcsr; | ||
1120 | pci_read_config_word(dev, dev->pm_cap + PCI_PM_CTRL, &pmcsr); | ||
1121 | dev->current_state = (pmcsr & PCI_PM_CTRL_STATE_MASK); | ||
1122 | } | ||
1123 | |||
997 | if (atomic_add_return(1, &dev->enable_cnt) > 1) | 1124 | if (atomic_add_return(1, &dev->enable_cnt) > 1) |
998 | return 0; /* already enabled */ | 1125 | return 0; /* already enabled */ |
999 | 1126 | ||
@@ -1275,22 +1402,6 @@ bool pci_check_pme_status(struct pci_dev *dev) | |||
1275 | return ret; | 1402 | return ret; |
1276 | } | 1403 | } |
1277 | 1404 | ||
1278 | /* | ||
1279 | * Time to wait before the system can be put into a sleep state after reporting | ||
1280 | * a wakeup event signaled by a PCI device. | ||
1281 | */ | ||
1282 | #define PCI_WAKEUP_COOLDOWN 100 | ||
1283 | |||
1284 | /** | ||
1285 | * pci_wakeup_event - Report a wakeup event related to a given PCI device. | ||
1286 | * @dev: Device to report the wakeup event for. | ||
1287 | */ | ||
1288 | void pci_wakeup_event(struct pci_dev *dev) | ||
1289 | { | ||
1290 | if (device_may_wakeup(&dev->dev)) | ||
1291 | pm_wakeup_event(&dev->dev, PCI_WAKEUP_COOLDOWN); | ||
1292 | } | ||
1293 | |||
1294 | /** | 1405 | /** |
1295 | * pci_pme_wakeup - Wake up a PCI device if its PME Status bit is set. | 1406 | * pci_pme_wakeup - Wake up a PCI device if its PME Status bit is set. |
1296 | * @dev: Device to handle. | 1407 | * @dev: Device to handle. |
@@ -1302,8 +1413,8 @@ void pci_wakeup_event(struct pci_dev *dev) | |||
1302 | static int pci_pme_wakeup(struct pci_dev *dev, void *ign) | 1413 | static int pci_pme_wakeup(struct pci_dev *dev, void *ign) |
1303 | { | 1414 | { |
1304 | if (pci_check_pme_status(dev)) { | 1415 | if (pci_check_pme_status(dev)) { |
1305 | pm_request_resume(&dev->dev); | ||
1306 | pci_wakeup_event(dev); | 1416 | pci_wakeup_event(dev); |
1417 | pm_request_resume(&dev->dev); | ||
1307 | } | 1418 | } |
1308 | return 0; | 1419 | return 0; |
1309 | } | 1420 | } |
@@ -1331,6 +1442,32 @@ bool pci_pme_capable(struct pci_dev *dev, pci_power_t state) | |||
1331 | return !!(dev->pme_support & (1 << state)); | 1442 | return !!(dev->pme_support & (1 << state)); |
1332 | } | 1443 | } |
1333 | 1444 | ||
1445 | static void pci_pme_list_scan(struct work_struct *work) | ||
1446 | { | ||
1447 | struct pci_pme_device *pme_dev; | ||
1448 | |||
1449 | mutex_lock(&pci_pme_list_mutex); | ||
1450 | if (!list_empty(&pci_pme_list)) { | ||
1451 | list_for_each_entry(pme_dev, &pci_pme_list, list) | ||
1452 | pci_pme_wakeup(pme_dev->dev, NULL); | ||
1453 | schedule_delayed_work(&pci_pme_work, msecs_to_jiffies(PME_TIMEOUT)); | ||
1454 | } | ||
1455 | mutex_unlock(&pci_pme_list_mutex); | ||
1456 | } | ||
1457 | |||
1458 | /** | ||
1459 | * pci_external_pme - is a device an external PCI PME source? | ||
1460 | * @dev: PCI device to check | ||
1461 | * | ||
1462 | */ | ||
1463 | |||
1464 | static bool pci_external_pme(struct pci_dev *dev) | ||
1465 | { | ||
1466 | if (pci_is_pcie(dev) || dev->bus->number == 0) | ||
1467 | return false; | ||
1468 | return true; | ||
1469 | } | ||
1470 | |||
1334 | /** | 1471 | /** |
1335 | * pci_pme_active - enable or disable PCI device's PME# function | 1472 | * pci_pme_active - enable or disable PCI device's PME# function |
1336 | * @dev: PCI device to handle. | 1473 | * @dev: PCI device to handle. |
@@ -1354,6 +1491,44 @@ void pci_pme_active(struct pci_dev *dev, bool enable) | |||
1354 | 1491 | ||
1355 | pci_write_config_word(dev, dev->pm_cap + PCI_PM_CTRL, pmcsr); | 1492 | pci_write_config_word(dev, dev->pm_cap + PCI_PM_CTRL, pmcsr); |
1356 | 1493 | ||
1494 | /* PCI (as opposed to PCIe) PME requires that the device have | ||
1495 | its PME# line hooked up correctly. Not all hardware vendors | ||
1496 | do this, so the PME never gets delivered and the device | ||
1497 | remains asleep. The easiest way around this is to | ||
1498 | periodically walk the list of suspended devices and check | ||
1499 | whether any have their PME flag set. The assumption is that | ||
1500 | we'll wake up often enough anyway that this won't be a huge | ||
1501 | hit, and the power savings from the devices will still be a | ||
1502 | win. */ | ||
1503 | |||
1504 | if (pci_external_pme(dev)) { | ||
1505 | struct pci_pme_device *pme_dev; | ||
1506 | if (enable) { | ||
1507 | pme_dev = kmalloc(sizeof(struct pci_pme_device), | ||
1508 | GFP_KERNEL); | ||
1509 | if (!pme_dev) | ||
1510 | goto out; | ||
1511 | pme_dev->dev = dev; | ||
1512 | mutex_lock(&pci_pme_list_mutex); | ||
1513 | list_add(&pme_dev->list, &pci_pme_list); | ||
1514 | if (list_is_singular(&pci_pme_list)) | ||
1515 | schedule_delayed_work(&pci_pme_work, | ||
1516 | msecs_to_jiffies(PME_TIMEOUT)); | ||
1517 | mutex_unlock(&pci_pme_list_mutex); | ||
1518 | } else { | ||
1519 | mutex_lock(&pci_pme_list_mutex); | ||
1520 | list_for_each_entry(pme_dev, &pci_pme_list, list) { | ||
1521 | if (pme_dev->dev == dev) { | ||
1522 | list_del(&pme_dev->list); | ||
1523 | kfree(pme_dev); | ||
1524 | break; | ||
1525 | } | ||
1526 | } | ||
1527 | mutex_unlock(&pci_pme_list_mutex); | ||
1528 | } | ||
1529 | } | ||
1530 | |||
1531 | out: | ||
1357 | dev_printk(KERN_DEBUG, &dev->dev, "PME# %s\n", | 1532 | dev_printk(KERN_DEBUG, &dev->dev, "PME# %s\n", |
1358 | enable ? "enabled" : "disabled"); | 1533 | enable ? "enabled" : "disabled"); |
1359 | } | 1534 | } |
@@ -1695,7 +1870,8 @@ static int pci_add_cap_save_buffer( | |||
1695 | if (!save_state) | 1870 | if (!save_state) |
1696 | return -ENOMEM; | 1871 | return -ENOMEM; |
1697 | 1872 | ||
1698 | save_state->cap_nr = cap; | 1873 | save_state->cap.cap_nr = cap; |
1874 | save_state->cap.size = size; | ||
1699 | pci_add_saved_cap(dev, save_state); | 1875 | pci_add_saved_cap(dev, save_state); |
1700 | 1876 | ||
1701 | return 0; | 1877 | return 0; |
@@ -1758,6 +1934,300 @@ void pci_enable_ari(struct pci_dev *dev) | |||
1758 | bridge->ari_enabled = 1; | 1934 | bridge->ari_enabled = 1; |
1759 | } | 1935 | } |
1760 | 1936 | ||
1937 | /** | ||
1938 | * pci_enable_ido - enable ID-based ordering on a device | ||
1939 | * @dev: the PCI device | ||
1940 | * @type: which types of IDO to enable | ||
1941 | * | ||
1942 | * Enable ID-based ordering on @dev. @type can contain the bits | ||
1943 | * %PCI_EXP_IDO_REQUEST and/or %PCI_EXP_IDO_COMPLETION to indicate | ||
1944 | * which types of transactions are allowed to be re-ordered. | ||
1945 | */ | ||
1946 | void pci_enable_ido(struct pci_dev *dev, unsigned long type) | ||
1947 | { | ||
1948 | int pos; | ||
1949 | u16 ctrl; | ||
1950 | |||
1951 | pos = pci_pcie_cap(dev); | ||
1952 | if (!pos) | ||
1953 | return; | ||
1954 | |||
1955 | pci_read_config_word(dev, pos + PCI_EXP_DEVCTL2, &ctrl); | ||
1956 | if (type & PCI_EXP_IDO_REQUEST) | ||
1957 | ctrl |= PCI_EXP_IDO_REQ_EN; | ||
1958 | if (type & PCI_EXP_IDO_COMPLETION) | ||
1959 | ctrl |= PCI_EXP_IDO_CMP_EN; | ||
1960 | pci_write_config_word(dev, pos + PCI_EXP_DEVCTL2, ctrl); | ||
1961 | } | ||
1962 | EXPORT_SYMBOL(pci_enable_ido); | ||
1963 | |||
1964 | /** | ||
1965 | * pci_disable_ido - disable ID-based ordering on a device | ||
1966 | * @dev: the PCI device | ||
1967 | * @type: which types of IDO to disable | ||
1968 | */ | ||
1969 | void pci_disable_ido(struct pci_dev *dev, unsigned long type) | ||
1970 | { | ||
1971 | int pos; | ||
1972 | u16 ctrl; | ||
1973 | |||
1974 | if (!pci_is_pcie(dev)) | ||
1975 | return; | ||
1976 | |||
1977 | pos = pci_pcie_cap(dev); | ||
1978 | if (!pos) | ||
1979 | return; | ||
1980 | |||
1981 | pci_read_config_word(dev, pos + PCI_EXP_DEVCTL2, &ctrl); | ||
1982 | if (type & PCI_EXP_IDO_REQUEST) | ||
1983 | ctrl &= ~PCI_EXP_IDO_REQ_EN; | ||
1984 | if (type & PCI_EXP_IDO_COMPLETION) | ||
1985 | ctrl &= ~PCI_EXP_IDO_CMP_EN; | ||
1986 | pci_write_config_word(dev, pos + PCI_EXP_DEVCTL2, ctrl); | ||
1987 | } | ||
1988 | EXPORT_SYMBOL(pci_disable_ido); | ||
1989 | |||
1990 | /** | ||
1991 | * pci_enable_obff - enable optimized buffer flush/fill | ||
1992 | * @dev: PCI device | ||
1993 | * @type: type of signaling to use | ||
1994 | * | ||
1995 | * Try to enable @type OBFF signaling on @dev. It will try using WAKE# | ||
1996 | * signaling if possible, falling back to message signaling only if | ||
1997 | * WAKE# isn't supported. @type should indicate whether the PCIe link | ||
1998 | * be brought out of L0s or L1 to send the message. It should be either | ||
1999 | * %PCI_EXP_OBFF_SIGNAL_ALWAYS or %PCI_OBFF_SIGNAL_L0. | ||
2000 | * | ||
2001 | * If your device can benefit from receiving all messages, even at the | ||
2002 | * power cost of bringing the link back up from a low power state, use | ||
2003 | * %PCI_EXP_OBFF_SIGNAL_ALWAYS. Otherwise, use %PCI_OBFF_SIGNAL_L0 (the | ||
2004 | * preferred type). | ||
2005 | * | ||
2006 | * RETURNS: | ||
2007 | * Zero on success, appropriate error number on failure. | ||
2008 | */ | ||
2009 | int pci_enable_obff(struct pci_dev *dev, enum pci_obff_signal_type type) | ||
2010 | { | ||
2011 | int pos; | ||
2012 | u32 cap; | ||
2013 | u16 ctrl; | ||
2014 | int ret; | ||
2015 | |||
2016 | if (!pci_is_pcie(dev)) | ||
2017 | return -ENOTSUPP; | ||
2018 | |||
2019 | pos = pci_pcie_cap(dev); | ||
2020 | if (!pos) | ||
2021 | return -ENOTSUPP; | ||
2022 | |||
2023 | pci_read_config_dword(dev, pos + PCI_EXP_DEVCAP2, &cap); | ||
2024 | if (!(cap & PCI_EXP_OBFF_MASK)) | ||
2025 | return -ENOTSUPP; /* no OBFF support at all */ | ||
2026 | |||
2027 | /* Make sure the topology supports OBFF as well */ | ||
2028 | if (dev->bus) { | ||
2029 | ret = pci_enable_obff(dev->bus->self, type); | ||
2030 | if (ret) | ||
2031 | return ret; | ||
2032 | } | ||
2033 | |||
2034 | pci_read_config_word(dev, pos + PCI_EXP_DEVCTL2, &ctrl); | ||
2035 | if (cap & PCI_EXP_OBFF_WAKE) | ||
2036 | ctrl |= PCI_EXP_OBFF_WAKE_EN; | ||
2037 | else { | ||
2038 | switch (type) { | ||
2039 | case PCI_EXP_OBFF_SIGNAL_L0: | ||
2040 | if (!(ctrl & PCI_EXP_OBFF_WAKE_EN)) | ||
2041 | ctrl |= PCI_EXP_OBFF_MSGA_EN; | ||
2042 | break; | ||
2043 | case PCI_EXP_OBFF_SIGNAL_ALWAYS: | ||
2044 | ctrl &= ~PCI_EXP_OBFF_WAKE_EN; | ||
2045 | ctrl |= PCI_EXP_OBFF_MSGB_EN; | ||
2046 | break; | ||
2047 | default: | ||
2048 | WARN(1, "bad OBFF signal type\n"); | ||
2049 | return -ENOTSUPP; | ||
2050 | } | ||
2051 | } | ||
2052 | pci_write_config_word(dev, pos + PCI_EXP_DEVCTL2, ctrl); | ||
2053 | |||
2054 | return 0; | ||
2055 | } | ||
2056 | EXPORT_SYMBOL(pci_enable_obff); | ||
2057 | |||
2058 | /** | ||
2059 | * pci_disable_obff - disable optimized buffer flush/fill | ||
2060 | * @dev: PCI device | ||
2061 | * | ||
2062 | * Disable OBFF on @dev. | ||
2063 | */ | ||
2064 | void pci_disable_obff(struct pci_dev *dev) | ||
2065 | { | ||
2066 | int pos; | ||
2067 | u16 ctrl; | ||
2068 | |||
2069 | if (!pci_is_pcie(dev)) | ||
2070 | return; | ||
2071 | |||
2072 | pos = pci_pcie_cap(dev); | ||
2073 | if (!pos) | ||
2074 | return; | ||
2075 | |||
2076 | pci_read_config_word(dev, pos + PCI_EXP_DEVCTL2, &ctrl); | ||
2077 | ctrl &= ~PCI_EXP_OBFF_WAKE_EN; | ||
2078 | pci_write_config_word(dev, pos + PCI_EXP_DEVCTL2, ctrl); | ||
2079 | } | ||
2080 | EXPORT_SYMBOL(pci_disable_obff); | ||
2081 | |||
2082 | /** | ||
2083 | * pci_ltr_supported - check whether a device supports LTR | ||
2084 | * @dev: PCI device | ||
2085 | * | ||
2086 | * RETURNS: | ||
2087 | * True if @dev supports latency tolerance reporting, false otherwise. | ||
2088 | */ | ||
2089 | bool pci_ltr_supported(struct pci_dev *dev) | ||
2090 | { | ||
2091 | int pos; | ||
2092 | u32 cap; | ||
2093 | |||
2094 | if (!pci_is_pcie(dev)) | ||
2095 | return false; | ||
2096 | |||
2097 | pos = pci_pcie_cap(dev); | ||
2098 | if (!pos) | ||
2099 | return false; | ||
2100 | |||
2101 | pci_read_config_dword(dev, pos + PCI_EXP_DEVCAP2, &cap); | ||
2102 | |||
2103 | return cap & PCI_EXP_DEVCAP2_LTR; | ||
2104 | } | ||
2105 | EXPORT_SYMBOL(pci_ltr_supported); | ||
2106 | |||
2107 | /** | ||
2108 | * pci_enable_ltr - enable latency tolerance reporting | ||
2109 | * @dev: PCI device | ||
2110 | * | ||
2111 | * Enable LTR on @dev if possible, which means enabling it first on | ||
2112 | * upstream ports. | ||
2113 | * | ||
2114 | * RETURNS: | ||
2115 | * Zero on success, errno on failure. | ||
2116 | */ | ||
2117 | int pci_enable_ltr(struct pci_dev *dev) | ||
2118 | { | ||
2119 | int pos; | ||
2120 | u16 ctrl; | ||
2121 | int ret; | ||
2122 | |||
2123 | if (!pci_ltr_supported(dev)) | ||
2124 | return -ENOTSUPP; | ||
2125 | |||
2126 | pos = pci_pcie_cap(dev); | ||
2127 | if (!pos) | ||
2128 | return -ENOTSUPP; | ||
2129 | |||
2130 | /* Only primary function can enable/disable LTR */ | ||
2131 | if (PCI_FUNC(dev->devfn) != 0) | ||
2132 | return -EINVAL; | ||
2133 | |||
2134 | /* Enable upstream ports first */ | ||
2135 | if (dev->bus) { | ||
2136 | ret = pci_enable_ltr(dev->bus->self); | ||
2137 | if (ret) | ||
2138 | return ret; | ||
2139 | } | ||
2140 | |||
2141 | pci_read_config_word(dev, pos + PCI_EXP_DEVCTL2, &ctrl); | ||
2142 | ctrl |= PCI_EXP_LTR_EN; | ||
2143 | pci_write_config_word(dev, pos + PCI_EXP_DEVCTL2, ctrl); | ||
2144 | |||
2145 | return 0; | ||
2146 | } | ||
2147 | EXPORT_SYMBOL(pci_enable_ltr); | ||
2148 | |||
2149 | /** | ||
2150 | * pci_disable_ltr - disable latency tolerance reporting | ||
2151 | * @dev: PCI device | ||
2152 | */ | ||
2153 | void pci_disable_ltr(struct pci_dev *dev) | ||
2154 | { | ||
2155 | int pos; | ||
2156 | u16 ctrl; | ||
2157 | |||
2158 | if (!pci_ltr_supported(dev)) | ||
2159 | return; | ||
2160 | |||
2161 | pos = pci_pcie_cap(dev); | ||
2162 | if (!pos) | ||
2163 | return; | ||
2164 | |||
2165 | /* Only primary function can enable/disable LTR */ | ||
2166 | if (PCI_FUNC(dev->devfn) != 0) | ||
2167 | return; | ||
2168 | |||
2169 | pci_read_config_word(dev, pos + PCI_EXP_DEVCTL2, &ctrl); | ||
2170 | ctrl &= ~PCI_EXP_LTR_EN; | ||
2171 | pci_write_config_word(dev, pos + PCI_EXP_DEVCTL2, ctrl); | ||
2172 | } | ||
2173 | EXPORT_SYMBOL(pci_disable_ltr); | ||
2174 | |||
2175 | static int __pci_ltr_scale(int *val) | ||
2176 | { | ||
2177 | int scale = 0; | ||
2178 | |||
2179 | while (*val > 1023) { | ||
2180 | *val = (*val + 31) / 32; | ||
2181 | scale++; | ||
2182 | } | ||
2183 | return scale; | ||
2184 | } | ||
2185 | |||
2186 | /** | ||
2187 | * pci_set_ltr - set LTR latency values | ||
2188 | * @dev: PCI device | ||
2189 | * @snoop_lat_ns: snoop latency in nanoseconds | ||
2190 | * @nosnoop_lat_ns: nosnoop latency in nanoseconds | ||
2191 | * | ||
2192 | * Figure out the scale and set the LTR values accordingly. | ||
2193 | */ | ||
2194 | int pci_set_ltr(struct pci_dev *dev, int snoop_lat_ns, int nosnoop_lat_ns) | ||
2195 | { | ||
2196 | int pos, ret, snoop_scale, nosnoop_scale; | ||
2197 | u16 val; | ||
2198 | |||
2199 | if (!pci_ltr_supported(dev)) | ||
2200 | return -ENOTSUPP; | ||
2201 | |||
2202 | snoop_scale = __pci_ltr_scale(&snoop_lat_ns); | ||
2203 | nosnoop_scale = __pci_ltr_scale(&nosnoop_lat_ns); | ||
2204 | |||
2205 | if (snoop_lat_ns > PCI_LTR_VALUE_MASK || | ||
2206 | nosnoop_lat_ns > PCI_LTR_VALUE_MASK) | ||
2207 | return -EINVAL; | ||
2208 | |||
2209 | if ((snoop_scale > (PCI_LTR_SCALE_MASK >> PCI_LTR_SCALE_SHIFT)) || | ||
2210 | (nosnoop_scale > (PCI_LTR_SCALE_MASK >> PCI_LTR_SCALE_SHIFT))) | ||
2211 | return -EINVAL; | ||
2212 | |||
2213 | pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_LTR); | ||
2214 | if (!pos) | ||
2215 | return -ENOTSUPP; | ||
2216 | |||
2217 | val = (snoop_scale << PCI_LTR_SCALE_SHIFT) | snoop_lat_ns; | ||
2218 | ret = pci_write_config_word(dev, pos + PCI_LTR_MAX_SNOOP_LAT, val); | ||
2219 | if (ret != 4) | ||
2220 | return -EIO; | ||
2221 | |||
2222 | val = (nosnoop_scale << PCI_LTR_SCALE_SHIFT) | nosnoop_lat_ns; | ||
2223 | ret = pci_write_config_word(dev, pos + PCI_LTR_MAX_NOSNOOP_LAT, val); | ||
2224 | if (ret != 4) | ||
2225 | return -EIO; | ||
2226 | |||
2227 | return 0; | ||
2228 | } | ||
2229 | EXPORT_SYMBOL(pci_set_ltr); | ||
2230 | |||
1761 | static int pci_acs_enable; | 2231 | static int pci_acs_enable; |
1762 | 2232 | ||
1763 | /** | 2233 | /** |
@@ -2403,6 +2873,21 @@ clear: | |||
2403 | return 0; | 2873 | return 0; |
2404 | } | 2874 | } |
2405 | 2875 | ||
2876 | /** | ||
2877 | * pci_pm_reset - Put device into PCI_D3 and back into PCI_D0. | ||
2878 | * @dev: Device to reset. | ||
2879 | * @probe: If set, only check if the device can be reset this way. | ||
2880 | * | ||
2881 | * If @dev supports native PCI PM and its PCI_PM_CTRL_NO_SOFT_RESET flag is | ||
2882 | * unset, it will be reinitialized internally when going from PCI_D3hot to | ||
2883 | * PCI_D0. If that's the case and the device is not in a low-power state | ||
2884 | * already, force it into PCI_D3hot and back to PCI_D0, causing it to be reset. | ||
2885 | * | ||
2886 | * NOTE: This causes the caller to sleep for twice the device power transition | ||
2887 | * cooldown period, which for the D0->D3hot and D3hot->D0 transitions is 10 ms | ||
2888 | * by devault (i.e. unless the @dev's d3_delay field has a different value). | ||
2889 | * Moreover, only devices in D0 can be reset by this function. | ||
2890 | */ | ||
2406 | static int pci_pm_reset(struct pci_dev *dev, int probe) | 2891 | static int pci_pm_reset(struct pci_dev *dev, int probe) |
2407 | { | 2892 | { |
2408 | u16 csr; | 2893 | u16 csr; |
@@ -2689,7 +3174,7 @@ int pcie_get_readrq(struct pci_dev *dev) | |||
2689 | 3174 | ||
2690 | ret = pci_read_config_word(dev, cap + PCI_EXP_DEVCTL, &ctl); | 3175 | ret = pci_read_config_word(dev, cap + PCI_EXP_DEVCTL, &ctl); |
2691 | if (!ret) | 3176 | if (!ret) |
2692 | ret = 128 << ((ctl & PCI_EXP_DEVCTL_READRQ) >> 12); | 3177 | ret = 128 << ((ctl & PCI_EXP_DEVCTL_READRQ) >> 12); |
2693 | 3178 | ||
2694 | return ret; | 3179 | return ret; |
2695 | } | 3180 | } |
@@ -2786,11 +3271,11 @@ void __init pci_register_set_vga_state(arch_set_vga_state_t func) | |||
2786 | } | 3271 | } |
2787 | 3272 | ||
2788 | static int pci_set_vga_state_arch(struct pci_dev *dev, bool decode, | 3273 | static int pci_set_vga_state_arch(struct pci_dev *dev, bool decode, |
2789 | unsigned int command_bits, bool change_bridge) | 3274 | unsigned int command_bits, u32 flags) |
2790 | { | 3275 | { |
2791 | if (arch_set_vga_state) | 3276 | if (arch_set_vga_state) |
2792 | return arch_set_vga_state(dev, decode, command_bits, | 3277 | return arch_set_vga_state(dev, decode, command_bits, |
2793 | change_bridge); | 3278 | flags); |
2794 | return 0; | 3279 | return 0; |
2795 | } | 3280 | } |
2796 | 3281 | ||
@@ -2799,31 +3284,34 @@ static int pci_set_vga_state_arch(struct pci_dev *dev, bool decode, | |||
2799 | * @dev: the PCI device | 3284 | * @dev: the PCI device |
2800 | * @decode: true = enable decoding, false = disable decoding | 3285 | * @decode: true = enable decoding, false = disable decoding |
2801 | * @command_bits: PCI_COMMAND_IO and/or PCI_COMMAND_MEMORY | 3286 | * @command_bits: PCI_COMMAND_IO and/or PCI_COMMAND_MEMORY |
2802 | * @change_bridge: traverse ancestors and change bridges | 3287 | * @flags: traverse ancestors and change bridges |
3288 | * CHANGE_BRIDGE_ONLY / CHANGE_BRIDGE | ||
2803 | */ | 3289 | */ |
2804 | int pci_set_vga_state(struct pci_dev *dev, bool decode, | 3290 | int pci_set_vga_state(struct pci_dev *dev, bool decode, |
2805 | unsigned int command_bits, bool change_bridge) | 3291 | unsigned int command_bits, u32 flags) |
2806 | { | 3292 | { |
2807 | struct pci_bus *bus; | 3293 | struct pci_bus *bus; |
2808 | struct pci_dev *bridge; | 3294 | struct pci_dev *bridge; |
2809 | u16 cmd; | 3295 | u16 cmd; |
2810 | int rc; | 3296 | int rc; |
2811 | 3297 | ||
2812 | WARN_ON(command_bits & ~(PCI_COMMAND_IO|PCI_COMMAND_MEMORY)); | 3298 | WARN_ON((flags & PCI_VGA_STATE_CHANGE_DECODES) & (command_bits & ~(PCI_COMMAND_IO|PCI_COMMAND_MEMORY))); |
2813 | 3299 | ||
2814 | /* ARCH specific VGA enables */ | 3300 | /* ARCH specific VGA enables */ |
2815 | rc = pci_set_vga_state_arch(dev, decode, command_bits, change_bridge); | 3301 | rc = pci_set_vga_state_arch(dev, decode, command_bits, flags); |
2816 | if (rc) | 3302 | if (rc) |
2817 | return rc; | 3303 | return rc; |
2818 | 3304 | ||
2819 | pci_read_config_word(dev, PCI_COMMAND, &cmd); | 3305 | if (flags & PCI_VGA_STATE_CHANGE_DECODES) { |
2820 | if (decode == true) | 3306 | pci_read_config_word(dev, PCI_COMMAND, &cmd); |
2821 | cmd |= command_bits; | 3307 | if (decode == true) |
2822 | else | 3308 | cmd |= command_bits; |
2823 | cmd &= ~command_bits; | 3309 | else |
2824 | pci_write_config_word(dev, PCI_COMMAND, cmd); | 3310 | cmd &= ~command_bits; |
3311 | pci_write_config_word(dev, PCI_COMMAND, cmd); | ||
3312 | } | ||
2825 | 3313 | ||
2826 | if (change_bridge == false) | 3314 | if (!(flags & PCI_VGA_STATE_CHANGE_BRIDGE)) |
2827 | return 0; | 3315 | return 0; |
2828 | 3316 | ||
2829 | bus = dev->bus; | 3317 | bus = dev->bus; |
@@ -2995,6 +3483,8 @@ static int __init pci_setup(char *str) | |||
2995 | pci_no_msi(); | 3483 | pci_no_msi(); |
2996 | } else if (!strcmp(str, "noaer")) { | 3484 | } else if (!strcmp(str, "noaer")) { |
2997 | pci_no_aer(); | 3485 | pci_no_aer(); |
3486 | } else if (!strncmp(str, "realloc", 7)) { | ||
3487 | pci_realloc(); | ||
2998 | } else if (!strcmp(str, "nodomains")) { | 3488 | } else if (!strcmp(str, "nodomains")) { |
2999 | pci_no_domains(); | 3489 | pci_no_domains(); |
3000 | } else if (!strncmp(str, "cbiosize=", 9)) { | 3490 | } else if (!strncmp(str, "cbiosize=", 9)) { |