hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/pci/pci.c
....@@ -13,8 +13,8 @@
1313 #include <linux/delay.h>
1414 #include <linux/dmi.h>
1515 #include <linux/init.h>
16
+#include <linux/msi.h>
1617 #include <linux/of.h>
17
-#include <linux/of_pci.h>
1818 #include <linux/pci.h>
1919 #include <linux/pm.h>
2020 #include <linux/slab.h>
....@@ -29,10 +29,11 @@
2929 #include <linux/pm_runtime.h>
3030 #include <linux/pci_hotplug.h>
3131 #include <linux/vmalloc.h>
32
-#include <linux/pci-ats.h>
33
-#include <asm/setup.h>
3432 #include <asm/dma.h>
3533 #include <linux/aer.h>
34
+#ifndef __GENKSYMS__
35
+#include <trace/hooks/pci.h>
36
+#endif
3637 #include "pci.h"
3738
3839 DEFINE_MUTEX(pci_slot_mutex);
....@@ -48,7 +49,7 @@
4849 int pci_pci_problems;
4950 EXPORT_SYMBOL(pci_pci_problems);
5051
51
-unsigned int pci_pm_d3_delay;
52
+unsigned int pci_pm_d3hot_delay;
5253
5354 static void pci_pme_list_scan(struct work_struct *work);
5455
....@@ -65,13 +66,17 @@
6566
6667 static void pci_dev_d3_sleep(struct pci_dev *dev)
6768 {
68
- unsigned int delay = dev->d3_delay;
69
+ unsigned int delay = dev->d3hot_delay;
70
+ int err = -EOPNOTSUPP;
6971
70
- if (delay < pci_pm_d3_delay)
71
- delay = pci_pm_d3_delay;
72
+ if (delay < pci_pm_d3hot_delay)
73
+ delay = pci_pm_d3hot_delay;
7274
73
- if (delay)
74
- msleep(delay);
75
+ if (delay) {
76
+ trace_android_rvh_pci_d3_sleep(dev, delay, &err);
77
+ if (err == -EOPNOTSUPP)
78
+ msleep(delay);
79
+ }
7580 }
7681
7782 #ifdef CONFIG_PCI_DOMAINS
....@@ -85,15 +90,34 @@
8590 unsigned long pci_cardbus_mem_size = DEFAULT_CARDBUS_MEM_SIZE;
8691
8792 #define DEFAULT_HOTPLUG_IO_SIZE (256)
88
-#define DEFAULT_HOTPLUG_MEM_SIZE (2*1024*1024)
89
-/* pci=hpmemsize=nnM,hpiosize=nn can override this */
93
+#define DEFAULT_HOTPLUG_MMIO_SIZE (2*1024*1024)
94
+#define DEFAULT_HOTPLUG_MMIO_PREF_SIZE (2*1024*1024)
95
+/* hpiosize=nn can override this */
9096 unsigned long pci_hotplug_io_size = DEFAULT_HOTPLUG_IO_SIZE;
91
-unsigned long pci_hotplug_mem_size = DEFAULT_HOTPLUG_MEM_SIZE;
97
+/*
98
+ * pci=hpmmiosize=nnM overrides non-prefetchable MMIO size,
99
+ * pci=hpmmioprefsize=nnM overrides prefetchable MMIO size;
100
+ * pci=hpmemsize=nnM overrides both
101
+ */
102
+unsigned long pci_hotplug_mmio_size = DEFAULT_HOTPLUG_MMIO_SIZE;
103
+unsigned long pci_hotplug_mmio_pref_size = DEFAULT_HOTPLUG_MMIO_PREF_SIZE;
92104
93105 #define DEFAULT_HOTPLUG_BUS_SIZE 1
94106 unsigned long pci_hotplug_bus_size = DEFAULT_HOTPLUG_BUS_SIZE;
95107
108
+
109
+/* PCIe MPS/MRRS strategy; can be overridden by kernel command-line param */
110
+#ifdef CONFIG_PCIE_BUS_TUNE_OFF
111
+enum pcie_bus_config_types pcie_bus_config = PCIE_BUS_TUNE_OFF;
112
+#elif defined CONFIG_PCIE_BUS_SAFE
113
+enum pcie_bus_config_types pcie_bus_config = PCIE_BUS_SAFE;
114
+#elif defined CONFIG_PCIE_BUS_PERFORMANCE
115
+enum pcie_bus_config_types pcie_bus_config = PCIE_BUS_PERFORMANCE;
116
+#elif defined CONFIG_PCIE_BUS_PEER2PEER
117
+enum pcie_bus_config_types pcie_bus_config = PCIE_BUS_PEER2PEER;
118
+#else
96119 enum pcie_bus_config_types pcie_bus_config = PCIE_BUS_DEFAULT;
120
+#endif
97121
98122 /*
99123 * The default CLS is used if arch didn't set CLS explicitly and not
....@@ -123,6 +147,7 @@
123147 {
124148 return pcie_ats_disabled;
125149 }
150
+EXPORT_SYMBOL_GPL(pci_ats_disabled);
126151
127152 /* Disable bridge_d3 for all PCIe ports */
128153 static bool pci_bridge_d3_disable;
....@@ -138,9 +163,6 @@
138163 return 1;
139164 }
140165 __setup("pcie_port_pm=", pcie_port_pm_setup);
141
-
142
-/* Time to wait after a reset for device to become responsive */
143
-#define PCIE_RESET_READY_POLL_MS 60000
144166
145167 /**
146168 * pci_bus_max_busnr - returns maximum PCI bus number of given bus' children
....@@ -164,6 +186,29 @@
164186 }
165187 EXPORT_SYMBOL_GPL(pci_bus_max_busnr);
166188
189
+/**
190
+ * pci_status_get_and_clear_errors - return and clear error bits in PCI_STATUS
191
+ * @pdev: the PCI device
192
+ *
193
+ * Returns error bits set in PCI_STATUS and clears them.
194
+ */
195
+int pci_status_get_and_clear_errors(struct pci_dev *pdev)
196
+{
197
+ u16 status;
198
+ int ret;
199
+
200
+ ret = pci_read_config_word(pdev, PCI_STATUS, &status);
201
+ if (ret != PCIBIOS_SUCCESSFUL)
202
+ return -EIO;
203
+
204
+ status &= PCI_STATUS_ERROR_BITS;
205
+ if (status)
206
+ pci_write_config_word(pdev, PCI_STATUS, status);
207
+
208
+ return status;
209
+}
210
+EXPORT_SYMBOL_GPL(pci_status_get_and_clear_errors);
211
+
167212 #ifdef CONFIG_HAS_IOMEM
168213 void __iomem *pci_ioremap_bar(struct pci_dev *pdev, int bar)
169214 {
....@@ -176,7 +221,7 @@
176221 pci_warn(pdev, "can't ioremap BAR %d: %pR\n", bar, res);
177222 return NULL;
178223 }
179
- return ioremap_nocache(res->start, resource_size(res));
224
+ return ioremap(res->start, resource_size(res));
180225 }
181226 EXPORT_SYMBOL_GPL(pci_ioremap_bar);
182227
....@@ -197,8 +242,8 @@
197242
198243 /**
199244 * pci_dev_str_match_path - test if a path string matches a device
200
- * @dev: the PCI device to test
201
- * @p: string to match the device against
245
+ * @dev: the PCI device to test
246
+ * @path: string to match the device against
202247 * @endptr: pointer to the string after the match
203248 *
204249 * Test if a string (typically from a kernel parameter) formatted as a
....@@ -280,8 +325,8 @@
280325
281326 /**
282327 * pci_dev_str_match - test if a string matches a device
283
- * @dev: the PCI device to test
284
- * @p: string to match the device against
328
+ * @dev: the PCI device to test
329
+ * @p: string to match the device against
285330 * @endptr: pointer to the string after the match
286331 *
287332 * Test if a string (typically from a kernel parameter) matches a specified
....@@ -341,7 +386,7 @@
341386 } else {
342387 /*
343388 * PCI Bus, Device, Function IDs are specified
344
- * (optionally, may include a path of devfns following it)
389
+ * (optionally, may include a path of devfns following it)
345390 */
346391 ret = pci_dev_str_match_path(dev, p, &p);
347392 if (ret < 0)
....@@ -425,7 +470,7 @@
425470 * Tell if a device supports a given PCI capability.
426471 * Returns the address of the requested capability structure within the
427472 * device's PCI configuration space or 0 in case the device does not
428
- * support it. Possible values for @cap:
473
+ * support it. Possible values for @cap include:
429474 *
430475 * %PCI_CAP_ID_PM Power Management
431476 * %PCI_CAP_ID_AGP Accelerated Graphics Port
....@@ -450,11 +495,11 @@
450495
451496 /**
452497 * pci_bus_find_capability - query for devices' capabilities
453
- * @bus: the PCI bus to query
498
+ * @bus: the PCI bus to query
454499 * @devfn: PCI device to query
455
- * @cap: capability code
500
+ * @cap: capability code
456501 *
457
- * Like pci_find_capability() but works for pci devices that do not have a
502
+ * Like pci_find_capability() but works for PCI devices that do not have a
458503 * pci_dev structure set up yet.
459504 *
460505 * Returns the address of the requested capability structure within the
....@@ -535,7 +580,7 @@
535580 *
536581 * Returns the address of the requested extended capability structure
537582 * within the device's PCI configuration space or 0 if the device does
538
- * not support it. Possible values for @cap:
583
+ * not support it. Possible values for @cap include:
539584 *
540585 * %PCI_EXT_CAP_ID_ERR Advanced Error Reporting
541586 * %PCI_EXT_CAP_ID_VC Virtual Channel
....@@ -547,6 +592,40 @@
547592 return pci_find_next_ext_capability(dev, 0, cap);
548593 }
549594 EXPORT_SYMBOL_GPL(pci_find_ext_capability);
595
+
596
+/**
597
+ * pci_get_dsn - Read and return the 8-byte Device Serial Number
598
+ * @dev: PCI device to query
599
+ *
600
+ * Looks up the PCI_EXT_CAP_ID_DSN and reads the 8 bytes of the Device Serial
601
+ * Number.
602
+ *
603
+ * Returns the DSN, or zero if the capability does not exist.
604
+ */
605
+u64 pci_get_dsn(struct pci_dev *dev)
606
+{
607
+ u32 dword;
608
+ u64 dsn;
609
+ int pos;
610
+
611
+ pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_DSN);
612
+ if (!pos)
613
+ return 0;
614
+
615
+ /*
616
+ * The Device Serial Number is two dwords offset 4 bytes from the
617
+ * capability position. The specification says that the first dword is
618
+ * the lower half, and the second dword is the upper half.
619
+ */
620
+ pos += 4;
621
+ pci_read_config_dword(dev, pos, &dword);
622
+ dsn = (u64)dword;
623
+ pci_read_config_dword(dev, pos + 4, &dword);
624
+ dsn |= ((u64)dword) << 32;
625
+
626
+ return dsn;
627
+}
628
+EXPORT_SYMBOL_GPL(pci_get_dsn);
550629
551630 static int __pci_find_next_ht_cap(struct pci_dev *dev, int pos, int ht_cap)
552631 {
....@@ -618,12 +697,13 @@
618697 EXPORT_SYMBOL_GPL(pci_find_ht_capability);
619698
620699 /**
621
- * pci_find_parent_resource - return resource region of parent bus of given region
700
+ * pci_find_parent_resource - return resource region of parent bus of given
701
+ * region
622702 * @dev: PCI device structure contains resources to be searched
623703 * @res: child resource record for which parent is sought
624704 *
625
- * For given resource region of given device, return the resource
626
- * region of parent bus the given region is contained in.
705
+ * For given resource region of given device, return the resource region of
706
+ * parent bus the given region is contained in.
627707 */
628708 struct resource *pci_find_parent_resource(const struct pci_dev *dev,
629709 struct resource *res)
....@@ -673,7 +753,7 @@
673753 {
674754 int i;
675755
676
- for (i = 0; i < PCI_ROM_RESOURCE; i++) {
756
+ for (i = 0; i < PCI_STD_NUM_BARS; i++) {
677757 struct resource *r = &dev->resource[i];
678758
679759 if (r->start && resource_contains(r, res))
....@@ -683,30 +763,6 @@
683763 return NULL;
684764 }
685765 EXPORT_SYMBOL(pci_find_resource);
686
-
687
-/**
688
- * pci_find_pcie_root_port - return PCIe Root Port
689
- * @dev: PCI device to query
690
- *
691
- * Traverse up the parent chain and return the PCIe Root Port PCI Device
692
- * for a given PCI Device.
693
- */
694
-struct pci_dev *pci_find_pcie_root_port(struct pci_dev *dev)
695
-{
696
- struct pci_dev *bridge, *highest_pcie_bridge = dev;
697
-
698
- bridge = pci_upstream_bridge(dev);
699
- while (bridge && pci_is_pcie(bridge)) {
700
- highest_pcie_bridge = bridge;
701
- bridge = pci_upstream_bridge(bridge);
702
- }
703
-
704
- if (pci_pcie_type(highest_pcie_bridge) != PCI_EXP_TYPE_ROOT_PORT)
705
- return NULL;
706
-
707
- return highest_pcie_bridge;
708
-}
709
-EXPORT_SYMBOL(pci_find_pcie_root_port);
710766
711767 /**
712768 * pci_wait_for_pending - wait for @mask bit(s) to clear in status word @pos
....@@ -732,6 +788,137 @@
732788 }
733789
734790 return 0;
791
+}
792
+
793
+static int pci_acs_enable;
794
+
795
+/**
796
+ * pci_request_acs - ask for ACS to be enabled if supported
797
+ */
798
+void pci_request_acs(void)
799
+{
800
+ pci_acs_enable = 1;
801
+}
802
+
803
+static const char *disable_acs_redir_param;
804
+
805
+/**
806
+ * pci_disable_acs_redir - disable ACS redirect capabilities
807
+ * @dev: the PCI device
808
+ *
809
+ * For only devices specified in the disable_acs_redir parameter.
810
+ */
811
+static void pci_disable_acs_redir(struct pci_dev *dev)
812
+{
813
+ int ret = 0;
814
+ const char *p;
815
+ int pos;
816
+ u16 ctrl;
817
+
818
+ if (!disable_acs_redir_param)
819
+ return;
820
+
821
+ p = disable_acs_redir_param;
822
+ while (*p) {
823
+ ret = pci_dev_str_match(dev, p, &p);
824
+ if (ret < 0) {
825
+ pr_info_once("PCI: Can't parse disable_acs_redir parameter: %s\n",
826
+ disable_acs_redir_param);
827
+
828
+ break;
829
+ } else if (ret == 1) {
830
+ /* Found a match */
831
+ break;
832
+ }
833
+
834
+ if (*p != ';' && *p != ',') {
835
+ /* End of param or invalid format */
836
+ break;
837
+ }
838
+ p++;
839
+ }
840
+
841
+ if (ret != 1)
842
+ return;
843
+
844
+ if (!pci_dev_specific_disable_acs_redir(dev))
845
+ return;
846
+
847
+ pos = dev->acs_cap;
848
+ if (!pos) {
849
+ pci_warn(dev, "cannot disable ACS redirect for this hardware as it does not have ACS capabilities\n");
850
+ return;
851
+ }
852
+
853
+ pci_read_config_word(dev, pos + PCI_ACS_CTRL, &ctrl);
854
+
855
+ /* P2P Request & Completion Redirect */
856
+ ctrl &= ~(PCI_ACS_RR | PCI_ACS_CR | PCI_ACS_EC);
857
+
858
+ pci_write_config_word(dev, pos + PCI_ACS_CTRL, ctrl);
859
+
860
+ pci_info(dev, "disabled ACS redirect\n");
861
+}
862
+
863
+/**
864
+ * pci_std_enable_acs - enable ACS on devices using standard ACS capabilities
865
+ * @dev: the PCI device
866
+ */
867
+static void pci_std_enable_acs(struct pci_dev *dev)
868
+{
869
+ int pos;
870
+ u16 cap;
871
+ u16 ctrl;
872
+
873
+ pos = dev->acs_cap;
874
+ if (!pos)
875
+ return;
876
+
877
+ pci_read_config_word(dev, pos + PCI_ACS_CAP, &cap);
878
+ pci_read_config_word(dev, pos + PCI_ACS_CTRL, &ctrl);
879
+
880
+ /* Source Validation */
881
+ ctrl |= (cap & PCI_ACS_SV);
882
+
883
+ /* P2P Request Redirect */
884
+ ctrl |= (cap & PCI_ACS_RR);
885
+
886
+ /* P2P Completion Redirect */
887
+ ctrl |= (cap & PCI_ACS_CR);
888
+
889
+ /* Upstream Forwarding */
890
+ ctrl |= (cap & PCI_ACS_UF);
891
+
892
+ /* Enable Translation Blocking for external devices */
893
+ if (dev->external_facing || dev->untrusted)
894
+ ctrl |= (cap & PCI_ACS_TB);
895
+
896
+ pci_write_config_word(dev, pos + PCI_ACS_CTRL, ctrl);
897
+}
898
+
899
+/**
900
+ * pci_enable_acs - enable ACS if hardware support it
901
+ * @dev: the PCI device
902
+ */
903
+static void pci_enable_acs(struct pci_dev *dev)
904
+{
905
+ if (!pci_acs_enable)
906
+ goto disable_acs_redir;
907
+
908
+ if (!pci_dev_specific_enable_acs(dev))
909
+ goto disable_acs_redir;
910
+
911
+ pci_std_enable_acs(dev);
912
+
913
+disable_acs_redir:
914
+ /*
915
+ * Note: pci_disable_acs_redir() must be called even if ACS was not
916
+ * enabled by the kernel because it may have been enabled by
917
+ * platform firmware. So if we are told to disable it, we should
918
+ * always disable it after setting the kernel's default
919
+ * preferences.
920
+ */
921
+ pci_disable_acs_redir(dev);
735922 }
736923
737924 /**
....@@ -776,6 +963,12 @@
776963 return pci_platform_pm ? pci_platform_pm->get_state(dev) : PCI_UNKNOWN;
777964 }
778965
966
+static inline void platform_pci_refresh_power_state(struct pci_dev *dev)
967
+{
968
+ if (pci_platform_pm && pci_platform_pm->refresh_state)
969
+ pci_platform_pm->refresh_state(dev);
970
+}
971
+
779972 static inline pci_power_t platform_pci_choose_state(struct pci_dev *dev)
780973 {
781974 return pci_platform_pm ?
....@@ -793,9 +986,16 @@
793986 return pci_platform_pm ? pci_platform_pm->need_resume(dev) : false;
794987 }
795988
989
+static inline bool platform_pci_bridge_d3(struct pci_dev *dev)
990
+{
991
+ if (pci_platform_pm && pci_platform_pm->bridge_d3)
992
+ return pci_platform_pm->bridge_d3(dev);
993
+ return false;
994
+}
995
+
796996 /**
797997 * pci_raw_set_power_state - Use PCI PM registers to set the power state of
798
- * given PCI device
998
+ * given PCI device
799999 * @dev: PCI device to handle.
8001000 * @state: PCI power state (D0, D1, D2, D3hot) to put the device into.
8011001 *
....@@ -821,25 +1021,35 @@
8211021 if (state < PCI_D0 || state > PCI_D3hot)
8221022 return -EINVAL;
8231023
824
- /* Validate current state:
825
- * Can enter D0 from any state, but if we can only go deeper
826
- * to sleep if we're already in a low power state
1024
+ /*
1025
+ * Validate transition: We can enter D0 from any state, but if
1026
+ * we're already in a low-power state, we can only go deeper. E.g.,
1027
+ * we can go from D1 to D3, but we can't go directly from D3 to D1;
1028
+ * we'd have to go from D3 to D0, then to D1.
8271029 */
8281030 if (state != PCI_D0 && dev->current_state <= PCI_D3cold
8291031 && dev->current_state > state) {
830
- pci_err(dev, "invalid power transition (from state %d to %d)\n",
831
- dev->current_state, state);
1032
+ pci_err(dev, "invalid power transition (from %s to %s)\n",
1033
+ pci_power_name(dev->current_state),
1034
+ pci_power_name(state));
8321035 return -EINVAL;
8331036 }
8341037
835
- /* check if this device supports the desired state */
1038
+ /* Check if this device supports the desired state */
8361039 if ((state == PCI_D1 && !dev->d1_support)
8371040 || (state == PCI_D2 && !dev->d2_support))
8381041 return -EIO;
8391042
8401043 pci_read_config_word(dev, dev->pm_cap + PCI_PM_CTRL, &pmcsr);
1044
+ if (pmcsr == (u16) ~0) {
1045
+ pci_err(dev, "can't change power state from %s to %s (config space inaccessible)\n",
1046
+ pci_power_name(dev->current_state),
1047
+ pci_power_name(state));
1048
+ return -EIO;
1049
+ }
8411050
842
- /* If we're (effectively) in D3, force entire word to 0.
1051
+ /*
1052
+ * If we're (effectively) in D3, force entire word to 0.
8431053 * This doesn't affect PME_Status, disables PME_En, and
8441054 * sets PowerState to 0.
8451055 */
....@@ -856,17 +1066,19 @@
8561066 if ((pmcsr & PCI_PM_CTRL_STATE_MASK) == PCI_D3hot
8571067 && !(pmcsr & PCI_PM_CTRL_NO_SOFT_RESET))
8581068 need_restore = true;
859
- /* Fall-through: force to D0 */
1069
+ fallthrough; /* force to D0 */
8601070 default:
8611071 pmcsr = 0;
8621072 break;
8631073 }
8641074
865
- /* enter specified state */
1075
+ /* Enter specified state */
8661076 pci_write_config_word(dev, dev->pm_cap + PCI_PM_CTRL, pmcsr);
8671077
868
- /* Mandatory power management transition delays */
869
- /* see PCI PM 1.1 5.6.1 table 18 */
1078
+ /*
1079
+ * Mandatory power management transition delays; see PCI PM 1.1
1080
+ * 5.6.1 table 18
1081
+ */
8701082 if (state == PCI_D3hot || dev->current_state == PCI_D3hot)
8711083 pci_dev_d3_sleep(dev);
8721084 else if (state == PCI_D2 || dev->current_state == PCI_D2)
....@@ -874,9 +1086,10 @@
8741086
8751087 pci_read_config_word(dev, dev->pm_cap + PCI_PM_CTRL, &pmcsr);
8761088 dev->current_state = (pmcsr & PCI_PM_CTRL_STATE_MASK);
877
- if (dev->current_state != state && printk_ratelimit())
878
- pci_info(dev, "Refused to change power state, currently in D%d\n",
879
- dev->current_state);
1089
+ if (dev->current_state != state)
1090
+ pci_info_ratelimited(dev, "refused to change power state from %s to %s\n",
1091
+ pci_power_name(dev->current_state),
1092
+ pci_power_name(state));
8801093
8811094 /*
8821095 * According to section 5.4.1 of the "PCI BUS POWER MANAGEMENT
....@@ -928,11 +1141,26 @@
9281141 }
9291142
9301143 /**
1144
+ * pci_refresh_power_state - Refresh the given device's power state data
1145
+ * @dev: Target PCI device.
1146
+ *
1147
+ * Ask the platform to refresh the devices power state information and invoke
1148
+ * pci_update_current_state() to update its current PCI power state.
1149
+ */
1150
+void pci_refresh_power_state(struct pci_dev *dev)
1151
+{
1152
+ if (platform_pci_power_manageable(dev))
1153
+ platform_pci_refresh_power_state(dev);
1154
+
1155
+ pci_update_current_state(dev, dev->current_state);
1156
+}
1157
+
1158
+/**
9311159 * pci_platform_power_transition - Use platform to change device power state
9321160 * @dev: PCI device to handle.
9331161 * @state: State to put the device into.
9341162 */
935
-static int pci_platform_power_transition(struct pci_dev *dev, pci_power_t state)
1163
+int pci_platform_power_transition(struct pci_dev *dev, pci_power_t state)
9361164 {
9371165 int error;
9381166
....@@ -948,6 +1176,7 @@
9481176
9491177 return error;
9501178 }
1179
+EXPORT_SYMBOL_GPL(pci_platform_power_transition);
9511180
9521181 /**
9531182 * pci_wakeup - Wake up a PCI device
....@@ -971,34 +1200,70 @@
9711200 pci_walk_bus(bus, pci_wakeup, NULL);
9721201 }
9731202
974
-/**
975
- * __pci_start_power_transition - Start power transition of a PCI device
976
- * @dev: PCI device to handle.
977
- * @state: State to put the device into.
978
- */
979
-static void __pci_start_power_transition(struct pci_dev *dev, pci_power_t state)
1203
+static int pci_dev_wait(struct pci_dev *dev, char *reset_type, int timeout)
9801204 {
981
- if (state == PCI_D0) {
982
- pci_platform_power_transition(dev, PCI_D0);
983
- /*
984
- * Mandatory power management transition delays, see
985
- * PCI Express Base Specification Revision 2.0 Section
986
- * 6.6.1: Conventional Reset. Do not delay for
987
- * devices powered on/off by corresponding bridge,
988
- * because have already delayed for the bridge.
989
- */
990
- if (dev->runtime_d3cold) {
991
- if (dev->d3cold_delay)
992
- msleep(dev->d3cold_delay);
993
- /*
994
- * When powering on a bridge from D3cold, the
995
- * whole hierarchy may be powered on into
996
- * D0uninitialized state, resume them to give
997
- * them a chance to suspend again
998
- */
999
- pci_wakeup_bus(dev->subordinate);
1205
+ int delay = 1;
1206
+ u32 id;
1207
+
1208
+ /*
1209
+ * After reset, the device should not silently discard config
1210
+ * requests, but it may still indicate that it needs more time by
1211
+ * responding to them with CRS completions. The Root Port will
1212
+ * generally synthesize ~0 data to complete the read (except when
1213
+ * CRS SV is enabled and the read was for the Vendor ID; in that
1214
+ * case it synthesizes 0x0001 data).
1215
+ *
1216
+ * Wait for the device to return a non-CRS completion. Read the
1217
+ * Command register instead of Vendor ID so we don't have to
1218
+ * contend with the CRS SV value.
1219
+ */
1220
+ pci_read_config_dword(dev, PCI_COMMAND, &id);
1221
+ while (id == ~0) {
1222
+ if (delay > timeout) {
1223
+ pci_warn(dev, "not ready %dms after %s; giving up\n",
1224
+ delay - 1, reset_type);
1225
+ return -ENOTTY;
10001226 }
1227
+
1228
+ if (delay > PCI_RESET_WAIT)
1229
+ pci_info(dev, "not ready %dms after %s; waiting\n",
1230
+ delay - 1, reset_type);
1231
+
1232
+ msleep(delay);
1233
+ delay *= 2;
1234
+ pci_read_config_dword(dev, PCI_COMMAND, &id);
10011235 }
1236
+
1237
+ if (delay > PCI_RESET_WAIT)
1238
+ pci_info(dev, "ready %dms after %s\n", delay - 1,
1239
+ reset_type);
1240
+
1241
+ return 0;
1242
+}
1243
+
1244
+/**
1245
+ * pci_power_up - Put the given device into D0
1246
+ * @dev: PCI device to power up
1247
+ */
1248
+int pci_power_up(struct pci_dev *dev)
1249
+{
1250
+ pci_platform_power_transition(dev, PCI_D0);
1251
+
1252
+ /*
1253
+ * Mandatory power management transition delays are handled in
1254
+ * pci_pm_resume_noirq() and pci_pm_runtime_resume() of the
1255
+ * corresponding bridge.
1256
+ */
1257
+ if (dev->runtime_d3cold) {
1258
+ /*
1259
+ * When powering on a bridge from D3cold, the whole hierarchy
1260
+ * may be powered on into D0uninitialized state, resume them to
1261
+ * give them a chance to suspend again
1262
+ */
1263
+ pci_wakeup_bus(dev->subordinate);
1264
+ }
1265
+
1266
+ return pci_raw_set_power_state(dev, PCI_D0);
10021267 }
10031268
10041269 /**
....@@ -1026,27 +1291,6 @@
10261291 }
10271292
10281293 /**
1029
- * __pci_complete_power_transition - Complete power transition of a PCI device
1030
- * @dev: PCI device to handle.
1031
- * @state: State to put the device into.
1032
- *
1033
- * This function should not be called directly by device drivers.
1034
- */
1035
-int __pci_complete_power_transition(struct pci_dev *dev, pci_power_t state)
1036
-{
1037
- int ret;
1038
-
1039
- if (state <= PCI_D0)
1040
- return -EINVAL;
1041
- ret = pci_platform_power_transition(dev, state);
1042
- /* Power off the bridge may power off the whole hierarchy */
1043
- if (!ret && state == PCI_D3cold)
1044
- pci_bus_set_current_state(dev->subordinate, PCI_D3cold);
1045
- return ret;
1046
-}
1047
-EXPORT_SYMBOL_GPL(__pci_complete_power_transition);
1048
-
1049
-/**
10501294 * pci_set_power_state - Set the power state of a PCI device
10511295 * @dev: PCI device to handle.
10521296 * @state: PCI power state (D0, D1, D2, D3hot) to put the device into.
....@@ -1067,16 +1311,18 @@
10671311 {
10681312 int error;
10691313
1070
- /* bound the state we're entering */
1314
+ /* Bound the state we're entering */
10711315 if (state > PCI_D3cold)
10721316 state = PCI_D3cold;
10731317 else if (state < PCI_D0)
10741318 state = PCI_D0;
10751319 else if ((state == PCI_D1 || state == PCI_D2) && pci_no_d1d2(dev))
1320
+
10761321 /*
1077
- * If the device or the parent bridge do not support PCI PM,
1078
- * ignore the request if we're doing anything other than putting
1079
- * it into D0 (which would only happen on boot).
1322
+ * If the device or the parent bridge do not support PCI
1323
+ * PM, ignore the request if we're doing anything other
1324
+ * than putting it into D0 (which would only happen on
1325
+ * boot).
10801326 */
10811327 return 0;
10821328
....@@ -1084,10 +1330,13 @@
10841330 if (dev->current_state == state)
10851331 return 0;
10861332
1087
- __pci_start_power_transition(dev, state);
1333
+ if (state == PCI_D0)
1334
+ return pci_power_up(dev);
10881335
1089
- /* This device is quirked not to be put into D3, so
1090
- don't put it in D3 */
1336
+ /*
1337
+ * This device is quirked not to be put into D3, so don't put it in
1338
+ * D3
1339
+ */
10911340 if (state >= PCI_D3hot && (dev->dev_flags & PCI_DEV_FLAGS_NO_D3))
10921341 return 0;
10931342
....@@ -1098,34 +1347,26 @@
10981347 error = pci_raw_set_power_state(dev, state > PCI_D3hot ?
10991348 PCI_D3hot : state);
11001349
1101
- if (!__pci_complete_power_transition(dev, state))
1102
- error = 0;
1350
+ if (pci_platform_power_transition(dev, state))
1351
+ return error;
11031352
1104
- return error;
1353
+ /* Powering off a bridge may power off the whole hierarchy */
1354
+ if (state == PCI_D3cold)
1355
+ pci_bus_set_current_state(dev->subordinate, PCI_D3cold);
1356
+
1357
+ return 0;
11051358 }
11061359 EXPORT_SYMBOL(pci_set_power_state);
1107
-
1108
-/**
1109
- * pci_power_up - Put the given device into D0 forcibly
1110
- * @dev: PCI device to power up
1111
- */
1112
-void pci_power_up(struct pci_dev *dev)
1113
-{
1114
- __pci_start_power_transition(dev, PCI_D0);
1115
- pci_raw_set_power_state(dev, PCI_D0);
1116
- pci_update_current_state(dev, PCI_D0);
1117
-}
11181360
11191361 /**
11201362 * pci_choose_state - Choose the power state of a PCI device
11211363 * @dev: PCI device to be suspended
11221364 * @state: target sleep state for the whole system. This is the value
1123
- * that is passed to suspend() function.
1365
+ * that is passed to suspend() function.
11241366 *
11251367 * Returns PCI power state suitable for given device and given system
11261368 * message.
11271369 */
1128
-
11291370 pci_power_t pci_choose_state(struct pci_dev *dev, pm_message_t state)
11301371 {
11311372 pci_power_t ret;
....@@ -1226,7 +1467,6 @@
12261467 pcie_capability_write_word(dev, PCI_EXP_SLTCTL2, cap[i++]);
12271468 }
12281469
1229
-
12301470 static int pci_save_pcix_state(struct pci_dev *dev)
12311471 {
12321472 int pos;
....@@ -1263,17 +1503,60 @@
12631503 pci_write_config_word(dev, pos + PCI_X_CMD, cap[i++]);
12641504 }
12651505
1506
+static void pci_save_ltr_state(struct pci_dev *dev)
1507
+{
1508
+ int ltr;
1509
+ struct pci_cap_saved_state *save_state;
1510
+ u16 *cap;
1511
+
1512
+ if (!pci_is_pcie(dev))
1513
+ return;
1514
+
1515
+ ltr = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_LTR);
1516
+ if (!ltr)
1517
+ return;
1518
+
1519
+ save_state = pci_find_saved_ext_cap(dev, PCI_EXT_CAP_ID_LTR);
1520
+ if (!save_state) {
1521
+ pci_err(dev, "no suspend buffer for LTR; ASPM issues possible after resume\n");
1522
+ return;
1523
+ }
1524
+
1525
+ cap = (u16 *)&save_state->cap.data[0];
1526
+ pci_read_config_word(dev, ltr + PCI_LTR_MAX_SNOOP_LAT, cap++);
1527
+ pci_read_config_word(dev, ltr + PCI_LTR_MAX_NOSNOOP_LAT, cap++);
1528
+}
1529
+
1530
+static void pci_restore_ltr_state(struct pci_dev *dev)
1531
+{
1532
+ struct pci_cap_saved_state *save_state;
1533
+ int ltr;
1534
+ u16 *cap;
1535
+
1536
+ save_state = pci_find_saved_ext_cap(dev, PCI_EXT_CAP_ID_LTR);
1537
+ ltr = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_LTR);
1538
+ if (!save_state || !ltr)
1539
+ return;
1540
+
1541
+ cap = (u16 *)&save_state->cap.data[0];
1542
+ pci_write_config_word(dev, ltr + PCI_LTR_MAX_SNOOP_LAT, *cap++);
1543
+ pci_write_config_word(dev, ltr + PCI_LTR_MAX_NOSNOOP_LAT, *cap++);
1544
+}
12661545
12671546 /**
1268
- * pci_save_state - save the PCI configuration space of a device before suspending
1269
- * @dev: - PCI device that we're dealing with
1547
+ * pci_save_state - save the PCI configuration space of a device before
1548
+ * suspending
1549
+ * @dev: PCI device that we're dealing with
12701550 */
12711551 int pci_save_state(struct pci_dev *dev)
12721552 {
12731553 int i;
12741554 /* XXX: 100% dword access ok here? */
1275
- for (i = 0; i < 16; i++)
1555
+ for (i = 0; i < 16; i++) {
12761556 pci_read_config_dword(dev, i * 4, &dev->saved_config_space[i]);
1557
+ pci_dbg(dev, "saving config space at offset %#x (reading %#x)\n",
1558
+ i * 4, dev->saved_config_space[i]);
1559
+ }
12771560 dev->state_saved = true;
12781561
12791562 i = pci_save_pcie_state(dev);
....@@ -1284,6 +1567,9 @@
12841567 if (i != 0)
12851568 return i;
12861569
1570
+ pci_save_ltr_state(dev);
1571
+ pci_save_dpc_state(dev);
1572
+ pci_save_aer_state(dev);
12871573 return pci_save_vc_state(dev);
12881574 }
12891575 EXPORT_SYMBOL(pci_save_state);
....@@ -1375,22 +1661,29 @@
13751661
13761662 /**
13771663 * pci_restore_state - Restore the saved state of a PCI device
1378
- * @dev: - PCI device that we're dealing with
1664
+ * @dev: PCI device that we're dealing with
13791665 */
13801666 void pci_restore_state(struct pci_dev *dev)
13811667 {
13821668 if (!dev->state_saved)
13831669 return;
13841670
1385
- /* PCI Express register must be restored first */
1671
+ /*
1672
+ * Restore max latencies (in the LTR capability) before enabling
1673
+ * LTR itself (in the PCIe capability).
1674
+ */
1675
+ pci_restore_ltr_state(dev);
1676
+
13861677 pci_restore_pcie_state(dev);
13871678 pci_restore_pasid_state(dev);
13881679 pci_restore_pri_state(dev);
13891680 pci_restore_ats_state(dev);
13901681 pci_restore_vc_state(dev);
13911682 pci_restore_rebar_state(dev);
1683
+ pci_restore_dpc_state(dev);
13921684
1393
- pci_cleanup_aer_error_status_regs(dev);
1685
+ pci_aer_clear_status(dev);
1686
+ pci_restore_aer_state(dev);
13941687
13951688 pci_restore_config_space(dev);
13961689
....@@ -1407,7 +1700,7 @@
14071700
14081701 struct pci_saved_state {
14091702 u32 config_space[16];
1410
- struct pci_cap_saved_data cap[0];
1703
+ struct pci_cap_saved_data cap[];
14111704 };
14121705
14131706 /**
....@@ -1546,8 +1839,8 @@
15461839 * pci_reenable_device - Resume abandoned device
15471840 * @dev: PCI device to be resumed
15481841 *
1549
- * Note this function is a backend of pci_default_resume and is not supposed
1550
- * to be called by normal code, write proper resume handler and use it instead.
1842
+ * NOTE: This function is a backend of pci_default_resume() and is not supposed
1843
+ * to be called by normal code, write proper resume handler and use it instead.
15511844 */
15521845 int pci_reenable_device(struct pci_dev *dev)
15531846 {
....@@ -1618,9 +1911,9 @@
16181911 * pci_enable_device_io - Initialize a device for use with IO space
16191912 * @dev: PCI device to be initialized
16201913 *
1621
- * Initialize device before it's used by a driver. Ask low-level code
1622
- * to enable I/O resources. Wake up the device if it was suspended.
1623
- * Beware, this function can fail.
1914
+ * Initialize device before it's used by a driver. Ask low-level code
1915
+ * to enable I/O resources. Wake up the device if it was suspended.
1916
+ * Beware, this function can fail.
16241917 */
16251918 int pci_enable_device_io(struct pci_dev *dev)
16261919 {
....@@ -1632,9 +1925,9 @@
16321925 * pci_enable_device_mem - Initialize a device for use with Memory space
16331926 * @dev: PCI device to be initialized
16341927 *
1635
- * Initialize device before it's used by a driver. Ask low-level code
1636
- * to enable Memory resources. Wake up the device if it was suspended.
1637
- * Beware, this function can fail.
1928
+ * Initialize device before it's used by a driver. Ask low-level code
1929
+ * to enable Memory resources. Wake up the device if it was suspended.
1930
+ * Beware, this function can fail.
16381931 */
16391932 int pci_enable_device_mem(struct pci_dev *dev)
16401933 {
....@@ -1646,12 +1939,12 @@
16461939 * pci_enable_device - Initialize device before it's used by a driver.
16471940 * @dev: PCI device to be initialized
16481941 *
1649
- * Initialize device before it's used by a driver. Ask low-level code
1650
- * to enable I/O and memory. Wake up the device if it was suspended.
1651
- * Beware, this function can fail.
1942
+ * Initialize device before it's used by a driver. Ask low-level code
1943
+ * to enable I/O and memory. Wake up the device if it was suspended.
1944
+ * Beware, this function can fail.
16521945 *
1653
- * Note we don't actually enable the device many times if we call
1654
- * this function repeatedly (we just increment the count).
1946
+ * Note we don't actually enable the device many times if we call
1947
+ * this function repeatedly (we just increment the count).
16551948 */
16561949 int pci_enable_device(struct pci_dev *dev)
16571950 {
....@@ -1660,8 +1953,8 @@
16601953 EXPORT_SYMBOL(pci_enable_device);
16611954
16621955 /*
1663
- * Managed PCI resources. This manages device on/off, intx/msi/msix
1664
- * on/off and BAR regions. pci_dev itself records msi/msix status, so
1956
+ * Managed PCI resources. This manages device on/off, INTx/MSI/MSI-X
1957
+ * on/off and BAR regions. pci_dev itself records MSI/MSI-X status, so
16651958 * there's no need to track it separately. pci_devres is initialized
16661959 * when a device is enabled using managed PCI device enable interface.
16671960 */
....@@ -1779,7 +2072,8 @@
17792072 }
17802073
17812074 /**
1782
- * pcibios_release_device - provide arch specific hooks when releasing device dev
2075
+ * pcibios_release_device - provide arch specific hooks when releasing
2076
+ * device dev
17832077 * @dev: the PCI device being released
17842078 *
17852079 * Permits the platform to provide architecture specific functionality when
....@@ -1870,8 +2164,7 @@
18702164 * @dev: the PCIe device reset
18712165 * @state: Reset state to enter into
18722166 *
1873
- *
1874
- * Sets the PCIe reset state for the device. This is the default
2167
+ * Set the PCIe reset state for the device. This is the default
18752168 * implementation. Architecture implementations can override this.
18762169 */
18772170 int __weak pcibios_set_pcie_reset_state(struct pci_dev *dev,
....@@ -1885,7 +2178,6 @@
18852178 * @dev: the PCIe device reset
18862179 * @state: Reset state to enter into
18872180 *
1888
- *
18892181 * Sets the PCI reset state for the device.
18902182 */
18912183 int pci_set_pcie_reset_state(struct pci_dev *dev, enum pcie_reset_state state)
....@@ -1893,6 +2185,14 @@
18932185 return pcibios_set_pcie_reset_state(dev, state);
18942186 }
18952187 EXPORT_SYMBOL_GPL(pci_set_pcie_reset_state);
2188
+
2189
+void pcie_clear_device_status(struct pci_dev *dev)
2190
+{
2191
+ u16 sta;
2192
+
2193
+ pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &sta);
2194
+ pcie_capability_write_word(dev, PCI_EXP_DEVSTA, sta);
2195
+}
18962196
18972197 /**
18982198 * pcie_clear_root_pme_status - Clear root port PME interrupt status.
....@@ -2147,10 +2447,13 @@
21472447 int ret = 0;
21482448
21492449 /*
2150
- * Bridges can only signal wakeup on behalf of subordinate devices,
2151
- * but that is set up elsewhere, so skip them.
2450
+ * Bridges that are not power-manageable directly only signal
2451
+ * wakeup on behalf of subordinate devices which is set up
2452
+ * elsewhere, so skip them. However, bridges that are
2453
+ * power-manageable may signal wakeup for themselves (for example,
2454
+ * on a hotplug event) and they need to be covered here.
21522455 */
2153
- if (pci_has_subordinate(dev))
2456
+ if (!pci_power_manageable(dev))
21542457 return 0;
21552458
21562459 /* Don't do the same thing twice in a row for one device. */
....@@ -2258,7 +2561,7 @@
22582561 case PCI_D2:
22592562 if (pci_no_d1d2(dev))
22602563 break;
2261
- /* else: fall through */
2564
+ fallthrough;
22622565 default:
22632566 target_state = state;
22642567 }
....@@ -2297,7 +2600,8 @@
22972600 }
22982601
22992602 /**
2300
- * pci_prepare_to_sleep - prepare PCI device for system-wide transition into a sleep state
2603
+ * pci_prepare_to_sleep - prepare PCI device for system-wide transition
2604
+ * into a sleep state
23012605 * @dev: Device to handle.
23022606 *
23032607 * Choose the power state appropriate for the device depending on whether
....@@ -2325,7 +2629,8 @@
23252629 EXPORT_SYMBOL(pci_prepare_to_sleep);
23262630
23272631 /**
2328
- * pci_back_from_sleep - turn PCI device on during system-wide transition into working state
2632
+ * pci_back_from_sleep - turn PCI device on during system-wide transition
2633
+ * into working state
23292634 * @dev: Device to handle.
23302635 *
23312636 * Disable device's system wake-up capability and put it into D0.
....@@ -2407,45 +2712,56 @@
24072712 EXPORT_SYMBOL_GPL(pci_dev_run_wake);
24082713
24092714 /**
2410
- * pci_dev_keep_suspended - Check if the device can stay in the suspended state.
2715
+ * pci_dev_need_resume - Check if it is necessary to resume the device.
24112716 * @pci_dev: Device to check.
24122717 *
2413
- * Return 'true' if the device is runtime-suspended, it doesn't have to be
2718
+ * Return 'true' if the device is not runtime-suspended or it has to be
24142719 * reconfigured due to wakeup settings difference between system and runtime
2415
- * suspend and the current power state of it is suitable for the upcoming
2416
- * (system) transition.
2417
- *
2418
- * If the device is not configured for system wakeup, disable PME for it before
2419
- * returning 'true' to prevent it from waking up the system unnecessarily.
2720
+ * suspend, or the current power state of it is not suitable for the upcoming
2721
+ * (system-wide) transition.
24202722 */
2421
-bool pci_dev_keep_suspended(struct pci_dev *pci_dev)
2723
+bool pci_dev_need_resume(struct pci_dev *pci_dev)
24222724 {
24232725 struct device *dev = &pci_dev->dev;
2424
- bool wakeup = device_may_wakeup(dev);
2726
+ pci_power_t target_state;
24252727
2426
- if (!pm_runtime_suspended(dev)
2427
- || pci_target_state(pci_dev, wakeup) != pci_dev->current_state
2428
- || platform_pci_need_resume(pci_dev))
2429
- return false;
2728
+ if (!pm_runtime_suspended(dev) || platform_pci_need_resume(pci_dev))
2729
+ return true;
2730
+
2731
+ target_state = pci_target_state(pci_dev, device_may_wakeup(dev));
24302732
24312733 /*
2432
- * At this point the device is good to go unless it's been configured
2433
- * to generate PME at the runtime suspend time, but it is not supposed
2434
- * to wake up the system. In that case, simply disable PME for it
2435
- * (it will have to be re-enabled on exit from system resume).
2436
- *
2437
- * If the device's power state is D3cold and the platform check above
2438
- * hasn't triggered, the device's configuration is suitable and we don't
2439
- * need to manipulate it at all.
2734
+ * If the earlier platform check has not triggered, D3cold is just power
2735
+ * removal on top of D3hot, so no need to resume the device in that
2736
+ * case.
24402737 */
2738
+ return target_state != pci_dev->current_state &&
2739
+ target_state != PCI_D3cold &&
2740
+ pci_dev->current_state != PCI_D3hot;
2741
+}
2742
+
2743
+/**
2744
+ * pci_dev_adjust_pme - Adjust PME setting for a suspended device.
2745
+ * @pci_dev: Device to check.
2746
+ *
2747
+ * If the device is suspended and it is not configured for system wakeup,
2748
+ * disable PME for it to prevent it from waking up the system unnecessarily.
2749
+ *
2750
+ * Note that if the device's power state is D3cold and the platform check in
2751
+ * pci_dev_need_resume() has not triggered, the device's configuration need not
2752
+ * be changed.
2753
+ */
2754
+void pci_dev_adjust_pme(struct pci_dev *pci_dev)
2755
+{
2756
+ struct device *dev = &pci_dev->dev;
2757
+
24412758 spin_lock_irq(&dev->power.lock);
24422759
2443
- if (pm_runtime_suspended(dev) && pci_dev->current_state < PCI_D3cold &&
2444
- !wakeup)
2760
+ if (pm_runtime_suspended(dev) && !device_may_wakeup(dev) &&
2761
+ pci_dev->current_state < PCI_D3cold)
24452762 __pci_pme_active(pci_dev, false);
24462763
24472764 spin_unlock_irq(&dev->power.lock);
2448
- return true;
24492765 }
24502766
24512767 /**
....@@ -2518,6 +2834,18 @@
25182834 DMI_MATCH(DMI_BOARD_NAME, "X299 DESIGNARE EX-CF"),
25192835 },
25202836 },
2837
+ {
2838
+ /*
2839
+ * Downstream device is not accessible after putting a root port
2840
+ * into D3cold and back into D0 on Elo Continental Z2 board
2841
+ */
2842
+ .ident = "Elo Continental Z2",
2843
+ .matches = {
2844
+ DMI_MATCH(DMI_BOARD_VENDOR, "Elo Touch Solutions"),
2845
+ DMI_MATCH(DMI_BOARD_NAME, "Geminilake"),
2846
+ DMI_MATCH(DMI_BOARD_VERSION, "Continental Z2"),
2847
+ },
2848
+ },
25212849 #endif
25222850 { }
25232851 };
....@@ -2553,6 +2881,10 @@
25532881
25542882 /* Even the oldest 2010 Thunderbolt controller supports D3. */
25552883 if (bridge->is_thunderbolt)
2884
+ return true;
2885
+
2886
+ /* Platform might know better if the bridge supports D3 */
2887
+ if (platform_pci_bridge_d3(bridge))
25562888 return true;
25572889
25582890 /*
....@@ -2691,6 +3023,7 @@
26913023 void pci_pm_init(struct pci_dev *dev)
26923024 {
26933025 int pm;
3026
+ u16 status;
26943027 u16 pmc;
26953028
26963029 pm_runtime_forbid(&dev->dev);
....@@ -2716,7 +3049,7 @@
27163049 }
27173050
27183051 dev->pm_cap = pm;
2719
- dev->d3_delay = PCI_PM_D3_WAIT;
3052
+ dev->d3hot_delay = PCI_PM_D3HOT_WAIT;
27203053 dev->d3cold_delay = PCI_PM_D3COLD_WAIT;
27213054 dev->bridge_d3 = pci_bridge_d3_possible(dev);
27223055 dev->d3cold_allowed = true;
....@@ -2730,18 +3063,18 @@
27303063 dev->d2_support = true;
27313064
27323065 if (dev->d1_support || dev->d2_support)
2733
- pci_printk(KERN_DEBUG, dev, "supports%s%s\n",
3066
+ pci_info(dev, "supports%s%s\n",
27343067 dev->d1_support ? " D1" : "",
27353068 dev->d2_support ? " D2" : "");
27363069 }
27373070
27383071 pmc &= PCI_PM_CAP_PME_MASK;
27393072 if (pmc) {
2740
- pci_printk(KERN_DEBUG, dev, "PME# supported from%s%s%s%s%s\n",
3073
+ pci_info(dev, "PME# supported from%s%s%s%s%s\n",
27413074 (pmc & PCI_PM_CAP_PME_D0) ? " D0" : "",
27423075 (pmc & PCI_PM_CAP_PME_D1) ? " D1" : "",
27433076 (pmc & PCI_PM_CAP_PME_D2) ? " D2" : "",
2744
- (pmc & PCI_PM_CAP_PME_D3) ? " D3hot" : "",
3077
+ (pmc & PCI_PM_CAP_PME_D3hot) ? " D3hot" : "",
27453078 (pmc & PCI_PM_CAP_PME_D3cold) ? " D3cold" : "");
27463079 dev->pme_support = pmc >> PCI_PM_CAP_PME_SHIFT;
27473080 dev->pme_poll = true;
....@@ -2753,6 +3086,10 @@
27533086 /* Disable the PME# generation functionality */
27543087 pci_pme_active(dev, false);
27553088 }
3089
+
3090
+ pci_read_config_word(dev, PCI_STATUS, &status);
3091
+ if (status & PCI_STATUS_IMM_READY)
3092
+ dev->imm_ready = 1;
27563093 }
27573094
27583095 static unsigned long pci_ea_flags(struct pci_dev *dev, u8 prop)
....@@ -2901,16 +3238,16 @@
29013238 res->flags = flags;
29023239
29033240 if (bei <= PCI_EA_BEI_BAR5)
2904
- pci_printk(KERN_DEBUG, dev, "BAR %d: %pR (from Enhanced Allocation, properties %#02x)\n",
3241
+ pci_info(dev, "BAR %d: %pR (from Enhanced Allocation, properties %#02x)\n",
29053242 bei, res, prop);
29063243 else if (bei == PCI_EA_BEI_ROM)
2907
- pci_printk(KERN_DEBUG, dev, "ROM: %pR (from Enhanced Allocation, properties %#02x)\n",
3244
+ pci_info(dev, "ROM: %pR (from Enhanced Allocation, properties %#02x)\n",
29083245 res, prop);
29093246 else if (bei >= PCI_EA_BEI_VF_BAR0 && bei <= PCI_EA_BEI_VF_BAR5)
2910
- pci_printk(KERN_DEBUG, dev, "VF BAR %d: %pR (from Enhanced Allocation, properties %#02x)\n",
3247
+ pci_info(dev, "VF BAR %d: %pR (from Enhanced Allocation, properties %#02x)\n",
29113248 bei - PCI_EA_BEI_VF_BAR0, res, prop);
29123249 else
2913
- pci_printk(KERN_DEBUG, dev, "BEI %d res: %pR (from Enhanced Allocation, properties %#02x)\n",
3250
+ pci_info(dev, "BEI %d res: %pR (from Enhanced Allocation, properties %#02x)\n",
29143251 bei, res, prop);
29153252
29163253 out:
....@@ -2954,7 +3291,7 @@
29543291
29553292 /**
29563293 * _pci_add_cap_save_buffer - allocate buffer for saving given
2957
- * capability registers
3294
+ * capability registers
29583295 * @dev: the PCI device
29593296 * @cap: the capability to allocate the buffer for
29603297 * @extended: Standard or Extended capability ID
....@@ -3013,6 +3350,11 @@
30133350 if (error)
30143351 pci_err(dev, "unable to preallocate PCI-X save buffer\n");
30153352
3353
+ error = pci_add_ext_cap_save_buffer(dev, PCI_EXT_CAP_ID_LTR,
3354
+ 2 * sizeof(u16));
3355
+ if (error)
3356
+ pci_err(dev, "unable to allocate suspend buffer for LTR\n");
3357
+
30163358 pci_allocate_vc_save_buffers(dev);
30173359 }
30183360
....@@ -3059,140 +3401,12 @@
30593401 }
30603402 }
30613403
3062
-static int pci_acs_enable;
3063
-
3064
-/**
3065
- * pci_request_acs - ask for ACS to be enabled if supported
3066
- */
3067
-void pci_request_acs(void)
3068
-{
3069
- pci_acs_enable = 1;
3070
-}
3071
-EXPORT_SYMBOL_GPL(pci_request_acs);
3072
-
3073
-static const char *disable_acs_redir_param;
3074
-
3075
-/**
3076
- * pci_disable_acs_redir - disable ACS redirect capabilities
3077
- * @dev: the PCI device
3078
- *
3079
- * For only devices specified in the disable_acs_redir parameter.
3080
- */
3081
-static void pci_disable_acs_redir(struct pci_dev *dev)
3082
-{
3083
- int ret = 0;
3084
- const char *p;
3085
- int pos;
3086
- u16 ctrl;
3087
-
3088
- if (!disable_acs_redir_param)
3089
- return;
3090
-
3091
- p = disable_acs_redir_param;
3092
- while (*p) {
3093
- ret = pci_dev_str_match(dev, p, &p);
3094
- if (ret < 0) {
3095
- pr_info_once("PCI: Can't parse disable_acs_redir parameter: %s\n",
3096
- disable_acs_redir_param);
3097
-
3098
- break;
3099
- } else if (ret == 1) {
3100
- /* Found a match */
3101
- break;
3102
- }
3103
-
3104
- if (*p != ';' && *p != ',') {
3105
- /* End of param or invalid format */
3106
- break;
3107
- }
3108
- p++;
3109
- }
3110
-
3111
- if (ret != 1)
3112
- return;
3113
-
3114
- if (!pci_dev_specific_disable_acs_redir(dev))
3115
- return;
3116
-
3117
- pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ACS);
3118
- if (!pos) {
3119
- pci_warn(dev, "cannot disable ACS redirect for this hardware as it does not have ACS capabilities\n");
3120
- return;
3121
- }
3122
-
3123
- pci_read_config_word(dev, pos + PCI_ACS_CTRL, &ctrl);
3124
-
3125
- /* P2P Request & Completion Redirect */
3126
- ctrl &= ~(PCI_ACS_RR | PCI_ACS_CR | PCI_ACS_EC);
3127
-
3128
- pci_write_config_word(dev, pos + PCI_ACS_CTRL, ctrl);
3129
-
3130
- pci_info(dev, "disabled ACS redirect\n");
3131
-}
3132
-
3133
-/**
3134
- * pci_std_enable_acs - enable ACS on devices using standard ACS capabilites
3135
- * @dev: the PCI device
3136
- */
3137
-static void pci_std_enable_acs(struct pci_dev *dev)
3138
-{
3139
- int pos;
3140
- u16 cap;
3141
- u16 ctrl;
3142
-
3143
- pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ACS);
3144
- if (!pos)
3145
- return;
3146
-
3147
- pci_read_config_word(dev, pos + PCI_ACS_CAP, &cap);
3148
- pci_read_config_word(dev, pos + PCI_ACS_CTRL, &ctrl);
3149
-
3150
- /* Source Validation */
3151
- ctrl |= (cap & PCI_ACS_SV);
3152
-
3153
- /* P2P Request Redirect */
3154
- ctrl |= (cap & PCI_ACS_RR);
3155
-
3156
- /* P2P Completion Redirect */
3157
- ctrl |= (cap & PCI_ACS_CR);
3158
-
3159
- /* Upstream Forwarding */
3160
- ctrl |= (cap & PCI_ACS_UF);
3161
-
3162
- pci_write_config_word(dev, pos + PCI_ACS_CTRL, ctrl);
3163
-}
3164
-
3165
-/**
3166
- * pci_enable_acs - enable ACS if hardware support it
3167
- * @dev: the PCI device
3168
- */
3169
-void pci_enable_acs(struct pci_dev *dev)
3170
-{
3171
- if (!pci_acs_enable)
3172
- goto disable_acs_redir;
3173
-
3174
- if (!pci_dev_specific_enable_acs(dev))
3175
- goto disable_acs_redir;
3176
-
3177
- pci_std_enable_acs(dev);
3178
-
3179
-disable_acs_redir:
3180
- /*
3181
- * Note: pci_disable_acs_redir() must be called even if ACS was not
3182
- * enabled by the kernel because it may have been enabled by
3183
- * platform firmware. So if we are told to disable it, we should
3184
- * always disable it after setting the kernel's default
3185
- * preferences.
3186
- */
3187
- pci_disable_acs_redir(dev);
3188
-}
3189
-
31903404 static bool pci_acs_flags_enabled(struct pci_dev *pdev, u16 acs_flags)
31913405 {
31923406 int pos;
31933407 u16 cap, ctrl;
31943408
3195
- pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_ACS);
3409
+ pos = pdev->acs_cap;
31963410 if (!pos)
31973411 return false;
31983412
....@@ -3315,6 +3529,23 @@
33153529 } while (pdev != end);
33163530
33173531 return true;
3532
+}
3533
+
3534
+/**
3535
+ * pci_acs_init - Initialize ACS if hardware supports it
3536
+ * @dev: the PCI device
3537
+ */
3538
+void pci_acs_init(struct pci_dev *dev)
3539
+{
3540
+ dev->acs_cap = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ACS);
3541
+
3542
+ /*
3543
+ * Attempt to enable ACS regardless of capability because some Root
3544
+ * Ports (e.g. those quirked with *_intel_pch_acs_*) do not have
3545
+ * the standard ACS capability but still support ACS via those
3546
+ * quirks.
3547
+ */
3548
+ pci_enable_acs(dev);
33183549 }
33193550
33203551 /**
....@@ -3484,7 +3715,7 @@
34843715 }
34853716
34863717 /* Ensure upstream ports don't block AtomicOps on egress */
3487
- if (!bridge->has_secondary_link) {
3718
+ if (pci_pcie_type(bridge) == PCI_EXP_TYPE_UPSTREAM) {
34883719 pcie_capability_read_dword(bridge, PCI_EXP_DEVCTL2,
34893720 &ctl2);
34903721 if (ctl2 & PCI_EXP_DEVCTL2_ATOMIC_EGRESS_BLOCK)
....@@ -3561,13 +3792,14 @@
35613792 EXPORT_SYMBOL_GPL(pci_common_swizzle);
35623793
35633794 /**
3564
- * pci_release_region - Release a PCI bar
3565
- * @pdev: PCI device whose resources were previously reserved by pci_request_region
3566
- * @bar: BAR to release
3795
+ * pci_release_region - Release a PCI bar
3796
+ * @pdev: PCI device whose resources were previously reserved by
3797
+ * pci_request_region()
3798
+ * @bar: BAR to release
35673799 *
3568
- * Releases the PCI I/O and memory resources previously reserved by a
3569
- * successful call to pci_request_region. Call this function only
3570
- * after all use of the PCI regions has ceased.
3800
+ * Releases the PCI I/O and memory resources previously reserved by a
3801
+ * successful call to pci_request_region(). Call this function only
3802
+ * after all use of the PCI regions has ceased.
35713803 */
35723804 void pci_release_region(struct pci_dev *pdev, int bar)
35733805 {
....@@ -3589,23 +3821,23 @@
35893821 EXPORT_SYMBOL(pci_release_region);
35903822
35913823 /**
3592
- * __pci_request_region - Reserved PCI I/O and memory resource
3593
- * @pdev: PCI device whose resources are to be reserved
3594
- * @bar: BAR to be reserved
3595
- * @res_name: Name to be associated with resource.
3596
- * @exclusive: whether the region access is exclusive or not
3824
+ * __pci_request_region - Reserved PCI I/O and memory resource
3825
+ * @pdev: PCI device whose resources are to be reserved
3826
+ * @bar: BAR to be reserved
3827
+ * @res_name: Name to be associated with resource.
3828
+ * @exclusive: whether the region access is exclusive or not
35973829 *
3598
- * Mark the PCI region associated with PCI device @pdev BR @bar as
3599
- * being reserved by owner @res_name. Do not access any
3600
- * address inside the PCI regions unless this call returns
3601
- * successfully.
3830
+ * Mark the PCI region associated with PCI device @pdev BAR @bar as
3831
+ * being reserved by owner @res_name. Do not access any
3832
+ * address inside the PCI regions unless this call returns
3833
+ * successfully.
36023834 *
3603
- * If @exclusive is set, then the region is marked so that userspace
3604
- * is explicitly not allowed to map the resource via /dev/mem or
3605
- * sysfs MMIO access.
3835
+ * If @exclusive is set, then the region is marked so that userspace
3836
+ * is explicitly not allowed to map the resource via /dev/mem or
3837
+ * sysfs MMIO access.
36063838 *
3607
- * Returns 0 on success, or %EBUSY on error. A warning
3608
- * message is also printed on failure.
3839
+ * Returns 0 on success, or %EBUSY on error. A warning
3840
+ * message is also printed on failure.
36093841 */
36103842 static int __pci_request_region(struct pci_dev *pdev, int bar,
36113843 const char *res_name, int exclusive)
....@@ -3639,49 +3871,24 @@
36393871 }
36403872
36413873 /**
3642
- * pci_request_region - Reserve PCI I/O and memory resource
3643
- * @pdev: PCI device whose resources are to be reserved
3644
- * @bar: BAR to be reserved
3645
- * @res_name: Name to be associated with resource
3874
+ * pci_request_region - Reserve PCI I/O and memory resource
3875
+ * @pdev: PCI device whose resources are to be reserved
3876
+ * @bar: BAR to be reserved
3877
+ * @res_name: Name to be associated with resource
36463878 *
3647
- * Mark the PCI region associated with PCI device @pdev BAR @bar as
3648
- * being reserved by owner @res_name. Do not access any
3649
- * address inside the PCI regions unless this call returns
3650
- * successfully.
3879
+ * Mark the PCI region associated with PCI device @pdev BAR @bar as
3880
+ * being reserved by owner @res_name. Do not access any
3881
+ * address inside the PCI regions unless this call returns
3882
+ * successfully.
36513883 *
3652
- * Returns 0 on success, or %EBUSY on error. A warning
3653
- * message is also printed on failure.
3884
+ * Returns 0 on success, or %EBUSY on error. A warning
3885
+ * message is also printed on failure.
36543886 */
36553887 int pci_request_region(struct pci_dev *pdev, int bar, const char *res_name)
36563888 {
36573889 return __pci_request_region(pdev, bar, res_name, 0);
36583890 }
36593891 EXPORT_SYMBOL(pci_request_region);
3660
-
3661
-/**
3662
- * pci_request_region_exclusive - Reserved PCI I/O and memory resource
3663
- * @pdev: PCI device whose resources are to be reserved
3664
- * @bar: BAR to be reserved
3665
- * @res_name: Name to be associated with resource.
3666
- *
3667
- * Mark the PCI region associated with PCI device @pdev BR @bar as
3668
- * being reserved by owner @res_name. Do not access any
3669
- * address inside the PCI regions unless this call returns
3670
- * successfully.
3671
- *
3672
- * Returns 0 on success, or %EBUSY on error. A warning
3673
- * message is also printed on failure.
3674
- *
3675
- * The key difference that _exclusive makes it that userspace is
3676
- * explicitly not allowed to map the resource via /dev/mem or
3677
- * sysfs.
3678
- */
3679
-int pci_request_region_exclusive(struct pci_dev *pdev, int bar,
3680
- const char *res_name)
3681
-{
3682
- return __pci_request_region(pdev, bar, res_name, IORESOURCE_EXCLUSIVE);
3683
-}
3684
-EXPORT_SYMBOL(pci_request_region_exclusive);
36853892
36863893 /**
36873894 * pci_release_selected_regions - Release selected PCI I/O and memory resources
....@@ -3695,7 +3902,7 @@
36953902 {
36963903 int i;
36973904
3698
- for (i = 0; i < 6; i++)
3905
+ for (i = 0; i < PCI_STD_NUM_BARS; i++)
36993906 if (bars & (1 << i))
37003907 pci_release_region(pdev, i);
37013908 }
....@@ -3706,7 +3913,7 @@
37063913 {
37073914 int i;
37083915
3709
- for (i = 0; i < 6; i++)
3916
+ for (i = 0; i < PCI_STD_NUM_BARS; i++)
37103917 if (bars & (1 << i))
37113918 if (__pci_request_region(pdev, i, res_name, excl))
37123919 goto err_out;
....@@ -3743,65 +3950,66 @@
37433950 EXPORT_SYMBOL(pci_request_selected_regions_exclusive);
37443951
37453952 /**
3746
- * pci_release_regions - Release reserved PCI I/O and memory resources
3747
- * @pdev: PCI device whose resources were previously reserved by pci_request_regions
3953
+ * pci_release_regions - Release reserved PCI I/O and memory resources
3954
+ * @pdev: PCI device whose resources were previously reserved by
3955
+ * pci_request_regions()
37483956 *
3749
- * Releases all PCI I/O and memory resources previously reserved by a
3750
- * successful call to pci_request_regions. Call this function only
3751
- * after all use of the PCI regions has ceased.
3957
+ * Releases all PCI I/O and memory resources previously reserved by a
3958
+ * successful call to pci_request_regions(). Call this function only
3959
+ * after all use of the PCI regions has ceased.
37523960 */
37533961
37543962 void pci_release_regions(struct pci_dev *pdev)
37553963 {
3756
- pci_release_selected_regions(pdev, (1 << 6) - 1);
3964
+ pci_release_selected_regions(pdev, (1 << PCI_STD_NUM_BARS) - 1);
37573965 }
37583966 EXPORT_SYMBOL(pci_release_regions);
37593967
37603968 /**
3761
- * pci_request_regions - Reserved PCI I/O and memory resources
3762
- * @pdev: PCI device whose resources are to be reserved
3763
- * @res_name: Name to be associated with resource.
3969
+ * pci_request_regions - Reserve PCI I/O and memory resources
3970
+ * @pdev: PCI device whose resources are to be reserved
3971
+ * @res_name: Name to be associated with resource.
37643972 *
3765
- * Mark all PCI regions associated with PCI device @pdev as
3766
- * being reserved by owner @res_name. Do not access any
3767
- * address inside the PCI regions unless this call returns
3768
- * successfully.
3973
+ * Mark all PCI regions associated with PCI device @pdev as
3974
+ * being reserved by owner @res_name. Do not access any
3975
+ * address inside the PCI regions unless this call returns
3976
+ * successfully.
37693977 *
3770
- * Returns 0 on success, or %EBUSY on error. A warning
3771
- * message is also printed on failure.
3978
+ * Returns 0 on success, or %EBUSY on error. A warning
3979
+ * message is also printed on failure.
37723980 */
37733981 int pci_request_regions(struct pci_dev *pdev, const char *res_name)
37743982 {
3775
- return pci_request_selected_regions(pdev, ((1 << 6) - 1), res_name);
3983
+ return pci_request_selected_regions(pdev,
3984
+ ((1 << PCI_STD_NUM_BARS) - 1), res_name);
37763985 }
37773986 EXPORT_SYMBOL(pci_request_regions);
37783987
37793988 /**
3780
- * pci_request_regions_exclusive - Reserved PCI I/O and memory resources
3781
- * @pdev: PCI device whose resources are to be reserved
3782
- * @res_name: Name to be associated with resource.
3989
+ * pci_request_regions_exclusive - Reserve PCI I/O and memory resources
3990
+ * @pdev: PCI device whose resources are to be reserved
3991
+ * @res_name: Name to be associated with resource.
37833992 *
3784
- * Mark all PCI regions associated with PCI device @pdev as
3785
- * being reserved by owner @res_name. Do not access any
3786
- * address inside the PCI regions unless this call returns
3787
- * successfully.
3993
+ * Mark all PCI regions associated with PCI device @pdev as being reserved
3994
+ * by owner @res_name. Do not access any address inside the PCI regions
3995
+ * unless this call returns successfully.
37883996 *
3789
- * pci_request_regions_exclusive() will mark the region so that
3790
- * /dev/mem and the sysfs MMIO access will not be allowed.
3997
+ * pci_request_regions_exclusive() will mark the region so that /dev/mem
3998
+ * and the sysfs MMIO access will not be allowed.
37913999 *
3792
- * Returns 0 on success, or %EBUSY on error. A warning
3793
- * message is also printed on failure.
4000
+ * Returns 0 on success, or %EBUSY on error. A warning message is also
4001
+ * printed on failure.
37944002 */
37954003 int pci_request_regions_exclusive(struct pci_dev *pdev, const char *res_name)
37964004 {
37974005 return pci_request_selected_regions_exclusive(pdev,
3798
- ((1 << 6) - 1), res_name);
4006
+ ((1 << PCI_STD_NUM_BARS) - 1), res_name);
37994007 }
38004008 EXPORT_SYMBOL(pci_request_regions_exclusive);
38014009
38024010 /*
38034011 * Record the PCI IO range (expressed as CPU physical address + size).
3804
- * Return a negative value if an error has occured, zero otherwise
4012
+ * Return a negative value if an error has occurred, zero otherwise
38054013 */
38064014 int pci_register_io_range(struct fwnode_handle *fwnode, phys_addr_t addr,
38074015 resource_size_t size)
....@@ -3847,6 +4055,7 @@
38474055
38484056 return address;
38494057 }
4058
+EXPORT_SYMBOL_GPL(pci_pio_to_address);
38504059
38514060 unsigned long __weak pci_address_to_pio(phys_addr_t address)
38524061 {
....@@ -3861,14 +4070,14 @@
38614070 }
38624071
38634072 /**
3864
- * pci_remap_iospace - Remap the memory mapped I/O space
3865
- * @res: Resource describing the I/O space
3866
- * @phys_addr: physical address of range to be mapped
4073
+ * pci_remap_iospace - Remap the memory mapped I/O space
4074
+ * @res: Resource describing the I/O space
4075
+ * @phys_addr: physical address of range to be mapped
38674076 *
3868
- * Remap the memory mapped I/O space described by the @res
3869
- * and the CPU physical address @phys_addr into virtual address space.
3870
- * Only architectures that have memory mapped IO functions defined
3871
- * (and the PCI_IOBASE value defined) should call this function.
4077
+ * Remap the memory mapped I/O space described by the @res and the CPU
4078
+ * physical address @phys_addr into virtual address space. Only
4079
+ * architectures that have memory mapped IO functions defined (and the
4080
+ * PCI_IOBASE value defined) should call this function.
38724081 */
38734082 int pci_remap_iospace(const struct resource *res, phys_addr_t phys_addr)
38744083 {
....@@ -3884,8 +4093,10 @@
38844093 return ioremap_page_range(vaddr, vaddr + resource_size(res), phys_addr,
38854094 pgprot_device(PAGE_KERNEL));
38864095 #else
3887
- /* this architecture does not have memory mapped I/O space,
3888
- so this function should never be called */
4096
+ /*
4097
+ * This architecture does not have memory mapped I/O space,
4098
+ * so this function should never be called
4099
+ */
38894100 WARN_ONCE(1, "This architecture does not support memory mapped I/O\n");
38904101 return -ENODEV;
38914102 #endif
....@@ -3893,12 +4104,12 @@
38934104 EXPORT_SYMBOL(pci_remap_iospace);
38944105
38954106 /**
3896
- * pci_unmap_iospace - Unmap the memory mapped I/O space
3897
- * @res: resource to be unmapped
4107
+ * pci_unmap_iospace - Unmap the memory mapped I/O space
4108
+ * @res: resource to be unmapped
38984109 *
3899
- * Unmap the CPU virtual address @res from virtual address space.
3900
- * Only architectures that have memory mapped IO functions defined
3901
- * (and the PCI_IOBASE value defined) should call this function.
4110
+ * Unmap the CPU virtual address @res from virtual address space. Only
4111
+ * architectures that have memory mapped IO functions defined (and the
4112
+ * PCI_IOBASE value defined) should call this function.
39024113 */
39034114 void pci_unmap_iospace(struct resource *res)
39044115 {
....@@ -4141,7 +4352,7 @@
41414352 if (cacheline_size == pci_cache_line_size)
41424353 return 0;
41434354
4144
- pci_printk(KERN_DEBUG, dev, "cache line size of %d is not supported\n",
4355
+ pci_info(dev, "cache line size of %d is not supported\n",
41454356 pci_cache_line_size << 2);
41464357
41474358 return -EINVAL;
....@@ -4244,7 +4455,7 @@
42444455 * @pdev: the PCI device to operate on
42454456 * @enable: boolean: whether to enable or disable PCI INTx
42464457 *
4247
- * Enables/disables PCI INTx for device dev
4458
+ * Enables/disables PCI INTx for device @pdev
42484459 */
42494460 void pci_intx(struct pci_dev *pdev, int enable)
42504461 {
....@@ -4320,9 +4531,8 @@
43204531 * pci_check_and_mask_intx - mask INTx on pending interrupt
43214532 * @dev: the PCI device to operate on
43224533 *
4323
- * Check if the device dev has its INTx line asserted, mask it and
4324
- * return true in that case. False is returned if no interrupt was
4325
- * pending.
4534
+ * Check if the device dev has its INTx line asserted, mask it and return
4535
+ * true in that case. False is returned if no interrupt was pending.
43264536 */
43274537 bool pci_check_and_mask_intx(struct pci_dev *dev)
43284538 {
....@@ -4334,9 +4544,9 @@
43344544 * pci_check_and_unmask_intx - unmask INTx if no interrupt is pending
43354545 * @dev: the PCI device to operate on
43364546 *
4337
- * Check if the device dev has its INTx line asserted, unmask it if not
4338
- * and return true. False is returned and the mask remains active if
4339
- * there was still an interrupt pending.
4547
+ * Check if the device dev has its INTx line asserted, unmask it if not and
4548
+ * return true. False is returned and the mask remains active if there was
4549
+ * still an interrupt pending.
43404550 */
43414551 bool pci_check_and_unmask_intx(struct pci_dev *dev)
43424552 {
....@@ -4345,7 +4555,7 @@
43454555 EXPORT_SYMBOL_GPL(pci_check_and_unmask_intx);
43464556
43474557 /**
4348
- * pci_wait_for_pending_transaction - waits for pending transaction
4558
+ * pci_wait_for_pending_transaction - wait for pending transaction
43494559 * @dev: the PCI device to operate on
43504560 *
43514561 * Return 0 if transaction is pending 1 otherwise.
....@@ -4360,50 +4570,9 @@
43604570 }
43614571 EXPORT_SYMBOL(pci_wait_for_pending_transaction);
43624572
4363
-static int pci_dev_wait(struct pci_dev *dev, char *reset_type, int timeout)
4364
-{
4365
- int delay = 1;
4366
- u32 id;
4367
-
4368
- /*
4369
- * After reset, the device should not silently discard config
4370
- * requests, but it may still indicate that it needs more time by
4371
- * responding to them with CRS completions. The Root Port will
4372
- * generally synthesize ~0 data to complete the read (except when
4373
- * CRS SV is enabled and the read was for the Vendor ID; in that
4374
- * case it synthesizes 0x0001 data).
4375
- *
4376
- * Wait for the device to return a non-CRS completion. Read the
4377
- * Command register instead of Vendor ID so we don't have to
4378
- * contend with the CRS SV value.
4379
- */
4380
- pci_read_config_dword(dev, PCI_COMMAND, &id);
4381
- while (id == ~0) {
4382
- if (delay > timeout) {
4383
- pci_warn(dev, "not ready %dms after %s; giving up\n",
4384
- delay - 1, reset_type);
4385
- return -ENOTTY;
4386
- }
4387
-
4388
- if (delay > 1000)
4389
- pci_info(dev, "not ready %dms after %s; waiting\n",
4390
- delay - 1, reset_type);
4391
-
4392
- msleep(delay);
4393
- delay *= 2;
4394
- pci_read_config_dword(dev, PCI_COMMAND, &id);
4395
- }
4396
-
4397
- if (delay > 1000)
4398
- pci_info(dev, "ready %dms after %s\n", delay - 1,
4399
- reset_type);
4400
-
4401
- return 0;
4402
-}
4403
-
44044573 /**
44054574 * pcie_has_flr - check if a device supports function level resets
4406
- * @dev: device to check
4575
+ * @dev: device to check
44074576 *
44084577 * Returns true if the device advertises support for PCIe function level
44094578 * resets.
....@@ -4422,7 +4591,7 @@
44224591
44234592 /**
44244593 * pcie_flr - initiate a PCIe function level reset
4425
- * @dev: device to reset
4594
+ * @dev: device to reset
44264595 *
44274596 * Initiate a function level reset on @dev. The caller should ensure the
44284597 * device supports FLR before calling this function, e.g. by using the
....@@ -4434,6 +4603,9 @@
44344603 pci_err(dev, "timed out waiting for pending transaction; performing function level reset anyway\n");
44354604
44364605 pcie_capability_set_word(dev, PCI_EXP_DEVCTL, PCI_EXP_DEVCTL_BCR_FLR);
4606
+
4607
+ if (dev->imm_ready)
4608
+ return 0;
44374609
44384610 /*
44394611 * Per PCIe r4.0, sec 6.6.2, a device must complete an FLR within
....@@ -4467,7 +4639,7 @@
44674639
44684640 /*
44694641 * Wait for Transaction Pending bit to clear. A word-aligned test
4470
- * is used, so we use the conrol offset rather than status and shift
4642
+ * is used, so we use the control offset rather than status and shift
44714643 * the test bit to match.
44724644 */
44734645 if (!pci_wait_for_pending(dev, pos + PCI_AF_CTRL,
....@@ -4475,6 +4647,9 @@
44754647 pci_err(dev, "timed out waiting for pending transaction; performing AF function level reset anyway\n");
44764648
44774649 pci_write_config_byte(dev, pos + PCI_AF_CTRL, PCI_AF_CTRL_FLR);
4650
+
4651
+ if (dev->imm_ready)
4652
+ return 0;
44784653
44794654 /*
44804655 * Per Advanced Capabilities for Conventional PCI ECN, 13 April 2006,
....@@ -4499,7 +4674,7 @@
44994674 *
45004675 * NOTE: This causes the caller to sleep for twice the device power transition
45014676 * cooldown period, which for the D0->D3hot and D3hot->D0 transitions is 10 ms
4502
- * by default (i.e. unless the @dev's d3_delay field has a different value).
4677
+ * by default (i.e. unless the @dev's d3hot_delay field has a different value).
45034678 * Moreover, only devices in D0 can be reset by this function.
45044679 */
45054680 static int pci_pm_reset(struct pci_dev *dev, int probe)
....@@ -4529,8 +4704,60 @@
45294704 pci_write_config_word(dev, dev->pm_cap + PCI_PM_CTRL, csr);
45304705 pci_dev_d3_sleep(dev);
45314706
4532
- return pci_dev_wait(dev, "PM D3->D0", PCIE_RESET_READY_POLL_MS);
4707
+ return pci_dev_wait(dev, "PM D3hot->D0", PCIE_RESET_READY_POLL_MS);
45334708 }
4709
+
4710
+/**
4711
+ * pcie_wait_for_link_delay - Wait until link is active or inactive
4712
+ * @pdev: Bridge device
4713
+ * @active: waiting for active or inactive?
4714
+ * @delay: Delay to wait after link has become active (in ms)
4715
+ *
4716
+ * Use this to wait till link becomes active or inactive.
4717
+ */
4718
+static bool pcie_wait_for_link_delay(struct pci_dev *pdev, bool active,
4719
+ int delay)
4720
+{
4721
+ int timeout = 1000;
4722
+ bool ret;
4723
+ u16 lnk_status;
4724
+
4725
+ /*
4726
+ * Some controllers might not implement link active reporting. In this
4727
+ * case, we wait for 1000 ms + any delay requested by the caller.
4728
+ */
4729
+ if (!pdev->link_active_reporting) {
4730
+ msleep(timeout + delay);
4731
+ return true;
4732
+ }
4733
+
4734
+ /*
4735
+ * PCIe r4.0 sec 6.6.1, a component must enter LTSSM Detect within 20ms,
4736
+ * after which we should expect an link active if the reset was
4737
+ * successful. If so, software must wait a minimum 100ms before sending
4738
+ * configuration requests to devices downstream this port.
4739
+ *
4740
+ * If the link fails to activate, either the device was physically
4741
+ * removed or the link is permanently failed.
4742
+ */
4743
+ if (active)
4744
+ msleep(20);
4745
+ for (;;) {
4746
+ pcie_capability_read_word(pdev, PCI_EXP_LNKSTA, &lnk_status);
4747
+ ret = !!(lnk_status & PCI_EXP_LNKSTA_DLLLA);
4748
+ if (ret == active)
4749
+ break;
4750
+ if (timeout <= 0)
4751
+ break;
4752
+ msleep(10);
4753
+ timeout -= 10;
4754
+ }
4755
+ if (active && ret)
4756
+ msleep(delay);
4757
+
4758
+ return ret == active;
4759
+}
4760
+
45344761 /**
45354762 * pcie_wait_for_link - Wait until link is active or inactive
45364763 * @pdev: Bridge device
....@@ -4540,25 +4767,129 @@
45404767 */
45414768 bool pcie_wait_for_link(struct pci_dev *pdev, bool active)
45424769 {
4543
- int timeout = 1000;
4544
- bool ret;
4545
- u16 lnk_status;
4770
+ return pcie_wait_for_link_delay(pdev, active, 100);
4771
+}
45464772
4547
- for (;;) {
4548
- pcie_capability_read_word(pdev, PCI_EXP_LNKSTA, &lnk_status);
4549
- ret = !!(lnk_status & PCI_EXP_LNKSTA_DLLLA);
4550
- if (ret == active)
4551
- return true;
4552
- if (timeout <= 0)
4553
- break;
4554
- msleep(10);
4555
- timeout -= 10;
4773
+/*
4774
+ * Find maximum D3cold delay required by all the devices on the bus. The
4775
+ * spec says 100 ms, but firmware can lower it and we allow drivers to
4776
+ * increase it as well.
4777
+ *
4778
+ * Called with @pci_bus_sem locked for reading.
4779
+ */
4780
+static int pci_bus_max_d3cold_delay(const struct pci_bus *bus)
4781
+{
4782
+ const struct pci_dev *pdev;
4783
+ int min_delay = 100;
4784
+ int max_delay = 0;
4785
+
4786
+ list_for_each_entry(pdev, &bus->devices, bus_list) {
4787
+ if (pdev->d3cold_delay < min_delay)
4788
+ min_delay = pdev->d3cold_delay;
4789
+ if (pdev->d3cold_delay > max_delay)
4790
+ max_delay = pdev->d3cold_delay;
45564791 }
45574792
4558
- pci_info(pdev, "Data Link Layer Link Active not %s in 1000 msec\n",
4559
- active ? "set" : "cleared");
4793
+ return max(min_delay, max_delay);
4794
+}
45604795
4561
- return false;
4796
+/**
4797
+ * pci_bridge_wait_for_secondary_bus - Wait for secondary bus to be accessible
4798
+ * @dev: PCI bridge
4799
+ * @reset_type: reset type in human-readable form
4800
+ * @timeout: maximum time to wait for devices on secondary bus (milliseconds)
4801
+ *
4802
+ * Handle necessary delays before access to the devices on the secondary
4803
+ * side of the bridge are permitted after D3cold to D0 transition
4804
+ * or Conventional Reset.
4805
+ *
4806
+ * For PCIe this means the delays in PCIe 5.0 section 6.6.1. For
4807
+ * conventional PCI it means Tpvrh + Trhfa specified in PCI 3.0 section
4808
+ * 4.3.2.
4809
+ *
4810
+ * Return 0 on success or -ENOTTY if the first device on the secondary bus
4811
+ * failed to become accessible.
4812
+ */
4813
+int pci_bridge_wait_for_secondary_bus(struct pci_dev *dev, char *reset_type,
4814
+ int timeout)
4815
+{
4816
+ struct pci_dev *child;
4817
+ int delay;
4818
+
4819
+ if (pci_dev_is_disconnected(dev))
4820
+ return 0;
4821
+
4822
+ if (!pci_is_bridge(dev))
4823
+ return 0;
4824
+
4825
+ down_read(&pci_bus_sem);
4826
+
4827
+ /*
4828
+ * We only deal with devices that are present currently on the bus.
4829
+ * For any hot-added devices the access delay is handled in pciehp
4830
+ * board_added(). In case of ACPI hotplug the firmware is expected
4831
+ * to configure the devices before OS is notified.
4832
+ */
4833
+ if (!dev->subordinate || list_empty(&dev->subordinate->devices)) {
4834
+ up_read(&pci_bus_sem);
4835
+ return 0;
4836
+ }
4837
+
4838
+ /* Take d3cold_delay requirements into account */
4839
+ delay = pci_bus_max_d3cold_delay(dev->subordinate);
4840
+ if (!delay) {
4841
+ up_read(&pci_bus_sem);
4842
+ return 0;
4843
+ }
4844
+
4845
+ child = list_first_entry(&dev->subordinate->devices, struct pci_dev,
4846
+ bus_list);
4847
+ up_read(&pci_bus_sem);
4848
+
4849
+ /*
4850
+ * Conventional PCI and PCI-X we need to wait Tpvrh + Trhfa before
4851
+ * accessing the device after reset (that is 1000 ms + 100 ms).
4852
+ */
4853
+ if (!pci_is_pcie(dev)) {
4854
+ pci_dbg(dev, "waiting %d ms for secondary bus\n", 1000 + delay);
4855
+ msleep(1000 + delay);
4856
+ return 0;
4857
+ }
4858
+
4859
+ /*
4860
+ * For PCIe downstream and root ports that do not support speeds
4861
+ * greater than 5 GT/s need to wait minimum 100 ms. For higher
4862
+ * speeds (gen3) we need to wait first for the data link layer to
4863
+ * become active.
4864
+ *
4865
+ * However, 100 ms is the minimum and the PCIe spec says the
4866
+ * software must allow at least 1s before it can determine that the
4867
+ * device that did not respond is a broken device. There is
4868
+ * evidence that 100 ms is not always enough, for example certain
4869
+ * Titan Ridge xHCI controller does not always respond to
4870
+ * configuration requests if we only wait for 100 ms (see
4871
+ * https://bugzilla.kernel.org/show_bug.cgi?id=203885).
4872
+ *
4873
+ * Therefore we wait for 100 ms and check for the device presence
4874
+ * until the timeout expires.
4875
+ */
4876
+ if (!pcie_downstream_port(dev))
4877
+ return 0;
4878
+
4879
+ if (pcie_get_speed_cap(dev) <= PCIE_SPEED_5_0GT) {
4880
+ pci_dbg(dev, "waiting %d ms for downstream link\n", delay);
4881
+ msleep(delay);
4882
+ } else {
4883
+ pci_dbg(dev, "waiting %d ms for downstream link, after activation\n",
4884
+ delay);
4885
+ if (!pcie_wait_for_link_delay(dev, true, delay)) {
4886
+ /* Did not train, no need to wait any further */
4887
+ pci_info(dev, "Data Link Layer Link Active not set in 1000 msec\n");
4888
+ return -ENOTTY;
4889
+ }
4890
+ }
4891
+
4892
+ return pci_dev_wait(child, reset_type, timeout - delay);
45624893 }
45634894
45644895 void pci_reset_secondary_bus(struct pci_dev *dev)
....@@ -4577,15 +4908,6 @@
45774908
45784909 ctrl &= ~PCI_BRIDGE_CTL_BUS_RESET;
45794910 pci_write_config_word(dev, PCI_BRIDGE_CONTROL, ctrl);
4580
-
4581
- /*
4582
- * Trhfa for conventional PCI is 2^25 clock cycles.
4583
- * Assuming a minimum 33MHz clock this results in a 1s
4584
- * delay before we can consider subordinate devices to
4585
- * be re-initialized. PCIe has some ways to shorten this,
4586
- * but we don't make use of them yet.
4587
- */
4588
- ssleep(1);
45894911 }
45904912
45914913 void __weak pcibios_reset_secondary_bus(struct pci_dev *dev)
....@@ -4604,7 +4926,8 @@
46044926 {
46054927 pcibios_reset_secondary_bus(dev);
46064928
4607
- return pci_dev_wait(dev, "bus reset", PCIE_RESET_READY_POLL_MS);
4929
+ return pci_bridge_wait_for_secondary_bus(dev, "bus reset",
4930
+ PCIE_RESET_READY_POLL_MS);
46084931 }
46094932 EXPORT_SYMBOL_GPL(pci_bridge_secondary_bus_reset);
46104933
....@@ -4630,46 +4953,40 @@
46304953 {
46314954 int rc = -ENOTTY;
46324955
4633
- if (!hotplug || !try_module_get(hotplug->ops->owner))
4956
+ if (!hotplug || !try_module_get(hotplug->owner))
46344957 return rc;
46354958
46364959 if (hotplug->ops->reset_slot)
46374960 rc = hotplug->ops->reset_slot(hotplug, probe);
46384961
4639
- module_put(hotplug->ops->owner);
4962
+ module_put(hotplug->owner);
46404963
46414964 return rc;
46424965 }
46434966
46444967 static int pci_dev_reset_slot_function(struct pci_dev *dev, int probe)
46454968 {
4646
- struct pci_dev *pdev;
4647
-
4648
- if (dev->subordinate || !dev->slot ||
4969
+ if (dev->multifunction || dev->subordinate || !dev->slot ||
46494970 dev->dev_flags & PCI_DEV_FLAGS_NO_BUS_RESET)
46504971 return -ENOTTY;
4651
-
4652
- list_for_each_entry(pdev, &dev->bus->devices, bus_list)
4653
- if (pdev != dev && pdev->slot == dev->slot)
4654
- return -ENOTTY;
46554972
46564973 return pci_reset_hotplug_slot(dev->slot->hotplug, probe);
46574974 }
46584975
46594976 static void pci_dev_lock(struct pci_dev *dev)
46604977 {
4661
- pci_cfg_access_lock(dev);
46624978 /* block PM suspend, driver probe, etc. */
46634979 device_lock(&dev->dev);
4980
+ pci_cfg_access_lock(dev);
46644981 }
46654982
46664983 /* Return 1 on successful lock, 0 on contention */
46674984 static int pci_dev_trylock(struct pci_dev *dev)
46684985 {
4669
- if (pci_cfg_access_trylock(dev)) {
4670
- if (device_trylock(&dev->dev))
4986
+ if (device_trylock(&dev->dev)) {
4987
+ if (pci_cfg_access_trylock(dev))
46714988 return 1;
4672
- pci_cfg_access_unlock(dev);
4989
+ device_unlock(&dev->dev);
46734990 }
46744991
46754992 return 0;
....@@ -4677,8 +4994,8 @@
46774994
46784995 static void pci_dev_unlock(struct pci_dev *dev)
46794996 {
4680
- device_unlock(&dev->dev);
46814997 pci_cfg_access_unlock(dev);
4998
+ device_unlock(&dev->dev);
46824999 }
46835000
46845001 static void pci_dev_save_and_disable(struct pci_dev *dev)
....@@ -4739,6 +5056,7 @@
47395056 *
47405057 * The device function is presumed to be unused and the caller is holding
47415058 * the device mutex lock when this function is called.
5059
+ *
47425060 * Resetting the device will make the contents of PCI configuration space
47435061 * random, so any caller of this must be prepared to reinitialise the
47445062 * device including MSI, bus mastering, BARs, decoding IO and memory spaces,
....@@ -5302,8 +5620,8 @@
53025620 * pcix_get_max_mmrbc - get PCI-X maximum designed memory read byte count
53035621 * @dev: PCI device to query
53045622 *
5305
- * Returns mmrbc: maximum designed memory read count in bytes
5306
- * or appropriate error value.
5623
+ * Returns mmrbc: maximum designed memory read count in bytes or
5624
+ * appropriate error value.
53075625 */
53085626 int pcix_get_max_mmrbc(struct pci_dev *dev)
53095627 {
....@@ -5325,8 +5643,8 @@
53255643 * pcix_get_mmrbc - get PCI-X maximum memory read byte count
53265644 * @dev: PCI device to query
53275645 *
5328
- * Returns mmrbc: maximum memory read count in bytes
5329
- * or appropriate error value.
5646
+ * Returns mmrbc: maximum memory read count in bytes or appropriate error
5647
+ * value.
53305648 */
53315649 int pcix_get_mmrbc(struct pci_dev *dev)
53325650 {
....@@ -5350,7 +5668,7 @@
53505668 * @mmrbc: maximum memory read count in bytes
53515669 * valid values are 512, 1024, 2048, 4096
53525670 *
5353
- * If possible sets maximum memory read byte count, some bridges have erratas
5671
+ * If possible sets maximum memory read byte count, some bridges have errata
53545672 * that prevent this.
53555673 */
53565674 int pcix_set_mmrbc(struct pci_dev *dev, int mmrbc)
....@@ -5395,8 +5713,7 @@
53955713 * pcie_get_readrq - get PCI Express read request size
53965714 * @dev: PCI device to query
53975715 *
5398
- * Returns maximum memory read request in bytes
5399
- * or appropriate error value.
5716
+ * Returns maximum memory read request in bytes or appropriate error value.
54005717 */
54015718 int pcie_get_readrq(struct pci_dev *dev)
54025719 {
....@@ -5419,15 +5736,15 @@
54195736 int pcie_set_readrq(struct pci_dev *dev, int rq)
54205737 {
54215738 u16 v;
5739
+ int ret;
54225740
54235741 if (rq < 128 || rq > 4096 || !is_power_of_2(rq))
54245742 return -EINVAL;
54255743
54265744 /*
5427
- * If using the "performance" PCIe config, we clamp the
5428
- * read rq size to the max packet size to prevent the
5429
- * host bridge generating requests larger than we can
5430
- * cope with
5745
+ * If using the "performance" PCIe config, we clamp the read rq
5746
+ * size to the max packet size to keep the host bridge from
5747
+ * generating requests larger than we can cope with.
54315748 */
54325749 if (pcie_bus_config == PCIE_BUS_PERFORMANCE) {
54335750 int mps = pcie_get_mps(dev);
....@@ -5438,8 +5755,10 @@
54385755
54395756 v = (ffs(rq) - 8) << 12;
54405757
5441
- return pcie_capability_clear_and_set_word(dev, PCI_EXP_DEVCTL,
5758
+ ret = pcie_capability_clear_and_set_word(dev, PCI_EXP_DEVCTL,
54425759 PCI_EXP_DEVCTL_READRQ, v);
5760
+
5761
+ return pcibios_err_to_errno(ret);
54435762 }
54445763 EXPORT_SYMBOL(pcie_set_readrq);
54455764
....@@ -5470,6 +5789,7 @@
54705789 int pcie_set_mps(struct pci_dev *dev, int mps)
54715790 {
54725791 u16 v;
5792
+ int ret;
54735793
54745794 if (mps < 128 || mps > 4096 || !is_power_of_2(mps))
54755795 return -EINVAL;
....@@ -5479,8 +5799,10 @@
54795799 return -EINVAL;
54805800 v <<= 5;
54815801
5482
- return pcie_capability_clear_and_set_word(dev, PCI_EXP_DEVCTL,
5802
+ ret = pcie_capability_clear_and_set_word(dev, PCI_EXP_DEVCTL,
54835803 PCI_EXP_DEVCTL_PAYLOAD, v);
5804
+
5805
+ return pcibios_err_to_errno(ret);
54845806 }
54855807 EXPORT_SYMBOL(pcie_set_mps);
54865808
....@@ -5563,17 +5885,10 @@
55635885 * where only 2.5 GT/s and 5.0 GT/s speeds were defined.
55645886 */
55655887 pcie_capability_read_dword(dev, PCI_EXP_LNKCAP2, &lnkcap2);
5566
- if (lnkcap2) { /* PCIe r3.0-compliant */
5567
- if (lnkcap2 & PCI_EXP_LNKCAP2_SLS_16_0GB)
5568
- return PCIE_SPEED_16_0GT;
5569
- else if (lnkcap2 & PCI_EXP_LNKCAP2_SLS_8_0GB)
5570
- return PCIE_SPEED_8_0GT;
5571
- else if (lnkcap2 & PCI_EXP_LNKCAP2_SLS_5_0GB)
5572
- return PCIE_SPEED_5_0GT;
5573
- else if (lnkcap2 & PCI_EXP_LNKCAP2_SLS_2_5GB)
5574
- return PCIE_SPEED_2_5GT;
5575
- return PCI_SPEED_UNKNOWN;
5576
- }
5888
+
5889
+ /* PCIe r3.0-compliant */
5890
+ if (lnkcap2)
5891
+ return PCIE_LNKCAP2_SLS2SPEED(lnkcap2);
55775892
55785893 pcie_capability_read_dword(dev, PCI_EXP_LNKCAP, &lnkcap);
55795894 if ((lnkcap & PCI_EXP_LNKCAP_SLS) == PCI_EXP_LNKCAP_SLS_5_0GB)
....@@ -5649,14 +5964,14 @@
56495964 if (bw_avail >= bw_cap && verbose)
56505965 pci_info(dev, "%u.%03u Gb/s available PCIe bandwidth (%s x%d link)\n",
56515966 bw_cap / 1000, bw_cap % 1000,
5652
- PCIE_SPEED2STR(speed_cap), width_cap);
5967
+ pci_speed_string(speed_cap), width_cap);
56535968 else if (bw_avail < bw_cap)
56545969 pci_info(dev, "%u.%03u Gb/s available PCIe bandwidth, limited by %s x%d link at %s (capable of %u.%03u Gb/s with %s x%d link)\n",
56555970 bw_avail / 1000, bw_avail % 1000,
5656
- PCIE_SPEED2STR(speed), width,
5971
+ pci_speed_string(speed), width,
56575972 limiting_dev ? pci_name(limiting_dev) : "<unknown>",
56585973 bw_cap / 1000, bw_cap % 1000,
5659
- PCIE_SPEED2STR(speed_cap), width_cap);
5974
+ pci_speed_string(speed_cap), width_cap);
56605975 }
56615976
56625977 /**
....@@ -5730,7 +6045,7 @@
57306045
57316046 if (flags & PCI_VGA_STATE_CHANGE_DECODES) {
57326047 pci_read_config_word(dev, PCI_COMMAND, &cmd);
5733
- if (decode == true)
6048
+ if (decode)
57346049 cmd |= command_bits;
57356050 else
57366051 cmd &= ~command_bits;
....@@ -5746,7 +6061,7 @@
57466061 if (bridge) {
57476062 pci_read_config_word(bridge, PCI_BRIDGE_CONTROL,
57486063 &cmd);
5749
- if (decode == true)
6064
+ if (decode)
57506065 cmd |= PCI_BRIDGE_CTL_VGA;
57516066 else
57526067 cmd &= ~PCI_BRIDGE_CTL_VGA;
....@@ -5758,10 +6073,29 @@
57586073 return 0;
57596074 }
57606075
6076
+#ifdef CONFIG_ACPI
6077
+bool pci_pr3_present(struct pci_dev *pdev)
6078
+{
6079
+ struct acpi_device *adev;
6080
+
6081
+ if (acpi_disabled)
6082
+ return false;
6083
+
6084
+ adev = ACPI_COMPANION(&pdev->dev);
6085
+ if (!adev)
6086
+ return false;
6087
+
6088
+ return adev->power.flags.power_resources &&
6089
+ acpi_has_method(adev->handle, "_PR3");
6090
+}
6091
+EXPORT_SYMBOL_GPL(pci_pr3_present);
6092
+#endif
6093
+
57616094 /**
57626095 * pci_add_dma_alias - Add a DMA devfn alias for a device
57636096 * @dev: the PCI device for which alias is added
5764
- * @devfn: alias slot and function
6097
+ * @devfn_from: alias slot and function
6098
+ * @nr_devfns: number of subsequent devfns to alias
57656099 *
57666100 * This helper encodes an 8-bit devfn as a bit number in dma_alias_mask
57676101 * which is used to program permissible bus-devfn source addresses for DMA
....@@ -5777,19 +6111,29 @@
57776111 * cannot be left as a userspace activity). DMA aliases should therefore
57786112 * be configured via quirks, such as the PCI fixup header quirk.
57796113 */
5780
-void pci_add_dma_alias(struct pci_dev *dev, u8 devfn)
6114
+void pci_add_dma_alias(struct pci_dev *dev, u8 devfn_from, unsigned nr_devfns)
57816115 {
6116
+ int devfn_to;
6117
+
6118
+ nr_devfns = min(nr_devfns, (unsigned) MAX_NR_DEVFNS - devfn_from);
6119
+ devfn_to = devfn_from + nr_devfns - 1;
6120
+
57826121 if (!dev->dma_alias_mask)
5783
- dev->dma_alias_mask = kcalloc(BITS_TO_LONGS(U8_MAX),
5784
- sizeof(long), GFP_KERNEL);
6122
+ dev->dma_alias_mask = bitmap_zalloc(MAX_NR_DEVFNS, GFP_KERNEL);
57856123 if (!dev->dma_alias_mask) {
57866124 pci_warn(dev, "Unable to allocate DMA alias mask\n");
57876125 return;
57886126 }
57896127
5790
- set_bit(devfn, dev->dma_alias_mask);
5791
- pci_info(dev, "Enabling fixed DMA alias to %02x.%d\n",
5792
- PCI_SLOT(devfn), PCI_FUNC(devfn));
6128
+ bitmap_set(dev->dma_alias_mask, devfn_from, nr_devfns);
6129
+
6130
+ if (nr_devfns == 1)
6131
+ pci_info(dev, "Enabling fixed DMA alias to %02x.%d\n",
6132
+ PCI_SLOT(devfn_from), PCI_FUNC(devfn_from));
6133
+ else if (nr_devfns > 1)
6134
+ pci_info(dev, "Enabling fixed DMA alias for devfn range from %02x.%d to %02x.%d\n",
6135
+ PCI_SLOT(devfn_from), PCI_FUNC(devfn_from),
6136
+ PCI_SLOT(devfn_to), PCI_FUNC(devfn_to));
57936137 }
57946138
57956139 bool pci_devs_are_dma_aliases(struct pci_dev *dev1, struct pci_dev *dev2)
....@@ -5797,13 +6141,17 @@
57976141 return (dev1->dma_alias_mask &&
57986142 test_bit(dev2->devfn, dev1->dma_alias_mask)) ||
57996143 (dev2->dma_alias_mask &&
5800
- test_bit(dev1->devfn, dev2->dma_alias_mask));
6144
+ test_bit(dev1->devfn, dev2->dma_alias_mask)) ||
6145
+ pci_real_dma_dev(dev1) == dev2 ||
6146
+ pci_real_dma_dev(dev2) == dev1;
58016147 }
58026148
58036149 bool pci_device_is_present(struct pci_dev *pdev)
58046150 {
58056151 u32 v;
58066152
6153
+ /* Check PF if pdev is a VF, since VF Vendor/Device IDs are 0xffff */
6154
+ pdev = pci_physfn(pdev);
58076155 if (pci_dev_is_disconnected(pdev))
58086156 return false;
58096157 return pci_bus_read_dev_vendor_id(pdev->bus, pdev->devfn, &v, 0);
....@@ -5821,13 +6169,39 @@
58216169 }
58226170 EXPORT_SYMBOL_GPL(pci_ignore_hotplug);
58236171
6172
+/**
6173
+ * pci_real_dma_dev - Get PCI DMA device for PCI device
6174
+ * @dev: the PCI device that may have a PCI DMA alias
6175
+ *
6176
+ * Permits the platform to provide architecture-specific functionality to
6177
+ * devices needing to alias DMA to another PCI device on another PCI bus. If
6178
+ * the PCI device is on the same bus, it is recommended to use
6179
+ * pci_add_dma_alias(). This is the default implementation. Architecture
6180
+ * implementations can override this.
6181
+ */
6182
+struct pci_dev __weak *pci_real_dma_dev(struct pci_dev *dev)
6183
+{
6184
+ return dev;
6185
+}
6186
+
58246187 resource_size_t __weak pcibios_default_alignment(void)
58256188 {
58266189 return 0;
58276190 }
58286191
5829
-#define RESOURCE_ALIGNMENT_PARAM_SIZE COMMAND_LINE_SIZE
5830
-static char resource_alignment_param[RESOURCE_ALIGNMENT_PARAM_SIZE] = {0};
6192
+/*
6193
+ * Arches that don't want to expose struct resource to userland as-is in
6194
+ * sysfs and /proc can implement their own pci_resource_to_user().
6195
+ */
6196
+void __weak pci_resource_to_user(const struct pci_dev *dev, int bar,
6197
+ const struct resource *rsrc,
6198
+ resource_size_t *start, resource_size_t *end)
6199
+{
6200
+ *start = rsrc->start;
6201
+ *end = rsrc->end;
6202
+}
6203
+
6204
+static char *resource_alignment_param;
58316205 static DEFINE_SPINLOCK(resource_alignment_lock);
58326206
58336207 /**
....@@ -5848,7 +6222,7 @@
58486222
58496223 spin_lock(&resource_alignment_lock);
58506224 p = resource_alignment_param;
5851
- if (!*p && !align)
6225
+ if (!p || !*p)
58526226 goto out;
58536227 if (pci_has_flag(PCI_PROBE_ONLY)) {
58546228 align = 0;
....@@ -6001,8 +6375,7 @@
60016375 * to enable the kernel to reassign new resource
60026376 * window later on.
60036377 */
6004
- if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE &&
6005
- (dev->class >> 8) == PCI_CLASS_BRIDGE_PCI) {
6378
+ if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE) {
60066379 for (i = PCI_BRIDGE_RESOURCES; i < PCI_NUM_RESOURCES; i++) {
60076380 r = &dev->resource[i];
60086381 if (!(r->flags & IORESOURCE_MEM))
....@@ -6015,39 +6388,44 @@
60156388 }
60166389 }
60176390
6018
-static ssize_t pci_set_resource_alignment_param(const char *buf, size_t count)
6391
+static ssize_t resource_alignment_show(struct bus_type *bus, char *buf)
60196392 {
6020
- if (count > RESOURCE_ALIGNMENT_PARAM_SIZE - 1)
6021
- count = RESOURCE_ALIGNMENT_PARAM_SIZE - 1;
6393
+ size_t count = 0;
6394
+
60226395 spin_lock(&resource_alignment_lock);
6023
- strncpy(resource_alignment_param, buf, count);
6024
- resource_alignment_param[count] = '\0';
6396
+ if (resource_alignment_param)
6397
+ count = scnprintf(buf, PAGE_SIZE, "%s", resource_alignment_param);
60256398 spin_unlock(&resource_alignment_lock);
6399
+
6400
+ /*
6401
+ * When set by the command line, resource_alignment_param will not
6402
+ * have a trailing line feed, which is ugly. So conditionally add
6403
+ * it here.
6404
+ */
6405
+ if (count >= 2 && buf[count - 2] != '\n' && count < PAGE_SIZE - 1) {
6406
+ buf[count - 1] = '\n';
6407
+ buf[count++] = 0;
6408
+ }
6409
+
60266410 return count;
60276411 }
60286412
6029
-static ssize_t pci_get_resource_alignment_param(char *buf, size_t size)
6030
-{
6031
- size_t count;
6032
- spin_lock(&resource_alignment_lock);
6033
- count = snprintf(buf, size, "%s", resource_alignment_param);
6034
- spin_unlock(&resource_alignment_lock);
6035
- return count;
6036
-}
6037
-
6038
-static ssize_t pci_resource_alignment_show(struct bus_type *bus, char *buf)
6039
-{
6040
- return pci_get_resource_alignment_param(buf, PAGE_SIZE);
6041
-}
6042
-
6043
-static ssize_t pci_resource_alignment_store(struct bus_type *bus,
6413
+static ssize_t resource_alignment_store(struct bus_type *bus,
60446414 const char *buf, size_t count)
60456415 {
6046
- return pci_set_resource_alignment_param(buf, count);
6416
+ char *param = kstrndup(buf, count, GFP_KERNEL);
6417
+
6418
+ if (!param)
6419
+ return -ENOMEM;
6420
+
6421
+ spin_lock(&resource_alignment_lock);
6422
+ kfree(resource_alignment_param);
6423
+ resource_alignment_param = param;
6424
+ spin_unlock(&resource_alignment_lock);
6425
+ return count;
60476426 }
60486427
6049
-static BUS_ATTR(resource_alignment, 0644, pci_resource_alignment_show,
6050
- pci_resource_alignment_store);
6428
+static BUS_ATTR_RW(resource_alignment);
60516429
60526430 static int __init pci_resource_alignment_sysfs_init(void)
60536431 {
....@@ -6078,6 +6456,7 @@
60786456
60796457 if (parent)
60806458 domain = of_get_pci_domain_nr(parent->of_node);
6459
+
60816460 /*
60826461 * Check DT domain and use_dt_domains values.
60836462 *
....@@ -6172,14 +6551,18 @@
61726551 } else if (!strncmp(str, "cbmemsize=", 10)) {
61736552 pci_cardbus_mem_size = memparse(str + 10, &str);
61746553 } else if (!strncmp(str, "resource_alignment=", 19)) {
6175
- pci_set_resource_alignment_param(str + 19,
6176
- strlen(str + 19));
6554
+ resource_alignment_param = str + 19;
61776555 } else if (!strncmp(str, "ecrc=", 5)) {
61786556 pcie_ecrc_get_policy(str + 5);
61796557 } else if (!strncmp(str, "hpiosize=", 9)) {
61806558 pci_hotplug_io_size = memparse(str + 9, &str);
6559
+ } else if (!strncmp(str, "hpmmiosize=", 11)) {
6560
+ pci_hotplug_mmio_size = memparse(str + 11, &str);
6561
+ } else if (!strncmp(str, "hpmmioprefsize=", 15)) {
6562
+ pci_hotplug_mmio_pref_size = memparse(str + 15, &str);
61816563 } else if (!strncmp(str, "hpmemsize=", 10)) {
6182
- pci_hotplug_mem_size = memparse(str + 10, &str);
6564
+ pci_hotplug_mmio_size = memparse(str + 10, &str);
6565
+ pci_hotplug_mmio_pref_size = pci_hotplug_mmio_size;
61836566 } else if (!strncmp(str, "hpbussize=", 10)) {
61846567 pci_hotplug_bus_size =
61856568 simple_strtoul(str + 10, &str, 0);
....@@ -6198,8 +6581,7 @@
61986581 } else if (!strncmp(str, "disable_acs_redir=", 18)) {
61996582 disable_acs_redir_param = str + 18;
62006583 } else {
6201
- printk(KERN_ERR "PCI: Unknown option `%s'\n",
6202
- str);
6584
+ pr_err("PCI: Unknown option `%s'\n", str);
62036585 }
62046586 }
62056587 str = k;
....@@ -6209,15 +6591,18 @@
62096591 early_param("pci", pci_setup);
62106592
62116593 /*
6212
- * 'disable_acs_redir_param' is initialized in pci_setup(), above, to point
6213
- * to data in the __initdata section which will be freed after the init
6214
- * sequence is complete. We can't allocate memory in pci_setup() because some
6215
- * architectures do not have any memory allocation service available during
6216
- * an early_param() call. So we allocate memory and copy the variable here
6217
- * before the init section is freed.
6594
+ * 'resource_alignment_param' and 'disable_acs_redir_param' are initialized
6595
+ * in pci_setup(), above, to point to data in the __initdata section which
6596
+ * will be freed after the init sequence is complete. We can't allocate memory
6597
+ * in pci_setup() because some architectures do not have any memory allocation
6598
+ * service available during an early_param() call. So we allocate memory and
6599
+ * copy the variable here before the init section is freed.
6600
+ *
62186601 */
62196602 static int __init pci_realloc_setup_params(void)
62206603 {
6604
+ resource_alignment_param = kstrdup(resource_alignment_param,
6605
+ GFP_KERNEL);
62216606 disable_acs_redir_param = kstrdup(disable_acs_redir_param, GFP_KERNEL);
62226607
62236608 return 0;