forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-08 01573e231f18eb2d99162747186f59511f56b64d
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;
....@@ -164,6 +189,29 @@
164189 }
165190 EXPORT_SYMBOL_GPL(pci_bus_max_busnr);
166191
192
+/**
193
+ * pci_status_get_and_clear_errors - return and clear error bits in PCI_STATUS
194
+ * @pdev: the PCI device
195
+ *
196
+ * Returns error bits set in PCI_STATUS and clears them.
197
+ */
198
+int pci_status_get_and_clear_errors(struct pci_dev *pdev)
199
+{
200
+ u16 status;
201
+ int ret;
202
+
203
+ ret = pci_read_config_word(pdev, PCI_STATUS, &status);
204
+ if (ret != PCIBIOS_SUCCESSFUL)
205
+ return -EIO;
206
+
207
+ status &= PCI_STATUS_ERROR_BITS;
208
+ if (status)
209
+ pci_write_config_word(pdev, PCI_STATUS, status);
210
+
211
+ return status;
212
+}
213
+EXPORT_SYMBOL_GPL(pci_status_get_and_clear_errors);
214
+
167215 #ifdef CONFIG_HAS_IOMEM
168216 void __iomem *pci_ioremap_bar(struct pci_dev *pdev, int bar)
169217 {
....@@ -176,7 +224,7 @@
176224 pci_warn(pdev, "can't ioremap BAR %d: %pR\n", bar, res);
177225 return NULL;
178226 }
179
- return ioremap_nocache(res->start, resource_size(res));
227
+ return ioremap(res->start, resource_size(res));
180228 }
181229 EXPORT_SYMBOL_GPL(pci_ioremap_bar);
182230
....@@ -197,8 +245,8 @@
197245
198246 /**
199247 * 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
248
+ * @dev: the PCI device to test
249
+ * @path: string to match the device against
202250 * @endptr: pointer to the string after the match
203251 *
204252 * Test if a string (typically from a kernel parameter) formatted as a
....@@ -280,8 +328,8 @@
280328
281329 /**
282330 * 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
331
+ * @dev: the PCI device to test
332
+ * @p: string to match the device against
285333 * @endptr: pointer to the string after the match
286334 *
287335 * Test if a string (typically from a kernel parameter) matches a specified
....@@ -341,7 +389,7 @@
341389 } else {
342390 /*
343391 * PCI Bus, Device, Function IDs are specified
344
- * (optionally, may include a path of devfns following it)
392
+ * (optionally, may include a path of devfns following it)
345393 */
346394 ret = pci_dev_str_match_path(dev, p, &p);
347395 if (ret < 0)
....@@ -425,7 +473,7 @@
425473 * Tell if a device supports a given PCI capability.
426474 * Returns the address of the requested capability structure within the
427475 * device's PCI configuration space or 0 in case the device does not
428
- * support it. Possible values for @cap:
476
+ * support it. Possible values for @cap include:
429477 *
430478 * %PCI_CAP_ID_PM Power Management
431479 * %PCI_CAP_ID_AGP Accelerated Graphics Port
....@@ -450,11 +498,11 @@
450498
451499 /**
452500 * pci_bus_find_capability - query for devices' capabilities
453
- * @bus: the PCI bus to query
501
+ * @bus: the PCI bus to query
454502 * @devfn: PCI device to query
455
- * @cap: capability code
503
+ * @cap: capability code
456504 *
457
- * Like pci_find_capability() but works for pci devices that do not have a
505
+ * Like pci_find_capability() but works for PCI devices that do not have a
458506 * pci_dev structure set up yet.
459507 *
460508 * Returns the address of the requested capability structure within the
....@@ -535,7 +583,7 @@
535583 *
536584 * Returns the address of the requested extended capability structure
537585 * within the device's PCI configuration space or 0 if the device does
538
- * not support it. Possible values for @cap:
586
+ * not support it. Possible values for @cap include:
539587 *
540588 * %PCI_EXT_CAP_ID_ERR Advanced Error Reporting
541589 * %PCI_EXT_CAP_ID_VC Virtual Channel
....@@ -547,6 +595,40 @@
547595 return pci_find_next_ext_capability(dev, 0, cap);
548596 }
549597 EXPORT_SYMBOL_GPL(pci_find_ext_capability);
598
+
599
+/**
600
+ * pci_get_dsn - Read and return the 8-byte Device Serial Number
601
+ * @dev: PCI device to query
602
+ *
603
+ * Looks up the PCI_EXT_CAP_ID_DSN and reads the 8 bytes of the Device Serial
604
+ * Number.
605
+ *
606
+ * Returns the DSN, or zero if the capability does not exist.
607
+ */
608
+u64 pci_get_dsn(struct pci_dev *dev)
609
+{
610
+ u32 dword;
611
+ u64 dsn;
612
+ int pos;
613
+
614
+ pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_DSN);
615
+ if (!pos)
616
+ return 0;
617
+
618
+ /*
619
+ * The Device Serial Number is two dwords offset 4 bytes from the
620
+ * capability position. The specification says that the first dword is
621
+ * the lower half, and the second dword is the upper half.
622
+ */
623
+ pos += 4;
624
+ pci_read_config_dword(dev, pos, &dword);
625
+ dsn = (u64)dword;
626
+ pci_read_config_dword(dev, pos + 4, &dword);
627
+ dsn |= ((u64)dword) << 32;
628
+
629
+ return dsn;
630
+}
631
+EXPORT_SYMBOL_GPL(pci_get_dsn);
550632
551633 static int __pci_find_next_ht_cap(struct pci_dev *dev, int pos, int ht_cap)
552634 {
....@@ -618,12 +700,13 @@
618700 EXPORT_SYMBOL_GPL(pci_find_ht_capability);
619701
620702 /**
621
- * pci_find_parent_resource - return resource region of parent bus of given region
703
+ * pci_find_parent_resource - return resource region of parent bus of given
704
+ * region
622705 * @dev: PCI device structure contains resources to be searched
623706 * @res: child resource record for which parent is sought
624707 *
625
- * For given resource region of given device, return the resource
626
- * region of parent bus the given region is contained in.
708
+ * For given resource region of given device, return the resource region of
709
+ * parent bus the given region is contained in.
627710 */
628711 struct resource *pci_find_parent_resource(const struct pci_dev *dev,
629712 struct resource *res)
....@@ -673,7 +756,7 @@
673756 {
674757 int i;
675758
676
- for (i = 0; i < PCI_ROM_RESOURCE; i++) {
759
+ for (i = 0; i < PCI_STD_NUM_BARS; i++) {
677760 struct resource *r = &dev->resource[i];
678761
679762 if (r->start && resource_contains(r, res))
....@@ -683,30 +766,6 @@
683766 return NULL;
684767 }
685768 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);
710769
711770 /**
712771 * pci_wait_for_pending - wait for @mask bit(s) to clear in status word @pos
....@@ -732,6 +791,137 @@
732791 }
733792
734793 return 0;
794
+}
795
+
796
+static int pci_acs_enable;
797
+
798
+/**
799
+ * pci_request_acs - ask for ACS to be enabled if supported
800
+ */
801
+void pci_request_acs(void)
802
+{
803
+ pci_acs_enable = 1;
804
+}
805
+
806
+static const char *disable_acs_redir_param;
807
+
808
+/**
809
+ * pci_disable_acs_redir - disable ACS redirect capabilities
810
+ * @dev: the PCI device
811
+ *
812
+ * For only devices specified in the disable_acs_redir parameter.
813
+ */
814
+static void pci_disable_acs_redir(struct pci_dev *dev)
815
+{
816
+ int ret = 0;
817
+ const char *p;
818
+ int pos;
819
+ u16 ctrl;
820
+
821
+ if (!disable_acs_redir_param)
822
+ return;
823
+
824
+ p = disable_acs_redir_param;
825
+ while (*p) {
826
+ ret = pci_dev_str_match(dev, p, &p);
827
+ if (ret < 0) {
828
+ pr_info_once("PCI: Can't parse disable_acs_redir parameter: %s\n",
829
+ disable_acs_redir_param);
830
+
831
+ break;
832
+ } else if (ret == 1) {
833
+ /* Found a match */
834
+ break;
835
+ }
836
+
837
+ if (*p != ';' && *p != ',') {
838
+ /* End of param or invalid format */
839
+ break;
840
+ }
841
+ p++;
842
+ }
843
+
844
+ if (ret != 1)
845
+ return;
846
+
847
+ if (!pci_dev_specific_disable_acs_redir(dev))
848
+ return;
849
+
850
+ pos = dev->acs_cap;
851
+ if (!pos) {
852
+ pci_warn(dev, "cannot disable ACS redirect for this hardware as it does not have ACS capabilities\n");
853
+ return;
854
+ }
855
+
856
+ pci_read_config_word(dev, pos + PCI_ACS_CTRL, &ctrl);
857
+
858
+ /* P2P Request & Completion Redirect */
859
+ ctrl &= ~(PCI_ACS_RR | PCI_ACS_CR | PCI_ACS_EC);
860
+
861
+ pci_write_config_word(dev, pos + PCI_ACS_CTRL, ctrl);
862
+
863
+ pci_info(dev, "disabled ACS redirect\n");
864
+}
865
+
866
+/**
867
+ * pci_std_enable_acs - enable ACS on devices using standard ACS capabilities
868
+ * @dev: the PCI device
869
+ */
870
+static void pci_std_enable_acs(struct pci_dev *dev)
871
+{
872
+ int pos;
873
+ u16 cap;
874
+ u16 ctrl;
875
+
876
+ pos = dev->acs_cap;
877
+ if (!pos)
878
+ return;
879
+
880
+ pci_read_config_word(dev, pos + PCI_ACS_CAP, &cap);
881
+ pci_read_config_word(dev, pos + PCI_ACS_CTRL, &ctrl);
882
+
883
+ /* Source Validation */
884
+ ctrl |= (cap & PCI_ACS_SV);
885
+
886
+ /* P2P Request Redirect */
887
+ ctrl |= (cap & PCI_ACS_RR);
888
+
889
+ /* P2P Completion Redirect */
890
+ ctrl |= (cap & PCI_ACS_CR);
891
+
892
+ /* Upstream Forwarding */
893
+ ctrl |= (cap & PCI_ACS_UF);
894
+
895
+ /* Enable Translation Blocking for external devices */
896
+ if (dev->external_facing || dev->untrusted)
897
+ ctrl |= (cap & PCI_ACS_TB);
898
+
899
+ pci_write_config_word(dev, pos + PCI_ACS_CTRL, ctrl);
900
+}
901
+
902
+/**
903
+ * pci_enable_acs - enable ACS if hardware support it
904
+ * @dev: the PCI device
905
+ */
906
+static void pci_enable_acs(struct pci_dev *dev)
907
+{
908
+ if (!pci_acs_enable)
909
+ goto disable_acs_redir;
910
+
911
+ if (!pci_dev_specific_enable_acs(dev))
912
+ goto disable_acs_redir;
913
+
914
+ pci_std_enable_acs(dev);
915
+
916
+disable_acs_redir:
917
+ /*
918
+ * Note: pci_disable_acs_redir() must be called even if ACS was not
919
+ * enabled by the kernel because it may have been enabled by
920
+ * platform firmware. So if we are told to disable it, we should
921
+ * always disable it after setting the kernel's default
922
+ * preferences.
923
+ */
924
+ pci_disable_acs_redir(dev);
735925 }
736926
737927 /**
....@@ -776,6 +966,12 @@
776966 return pci_platform_pm ? pci_platform_pm->get_state(dev) : PCI_UNKNOWN;
777967 }
778968
969
+static inline void platform_pci_refresh_power_state(struct pci_dev *dev)
970
+{
971
+ if (pci_platform_pm && pci_platform_pm->refresh_state)
972
+ pci_platform_pm->refresh_state(dev);
973
+}
974
+
779975 static inline pci_power_t platform_pci_choose_state(struct pci_dev *dev)
780976 {
781977 return pci_platform_pm ?
....@@ -793,9 +989,16 @@
793989 return pci_platform_pm ? pci_platform_pm->need_resume(dev) : false;
794990 }
795991
992
+static inline bool platform_pci_bridge_d3(struct pci_dev *dev)
993
+{
994
+ if (pci_platform_pm && pci_platform_pm->bridge_d3)
995
+ return pci_platform_pm->bridge_d3(dev);
996
+ return false;
997
+}
998
+
796999 /**
7971000 * pci_raw_set_power_state - Use PCI PM registers to set the power state of
798
- * given PCI device
1001
+ * given PCI device
7991002 * @dev: PCI device to handle.
8001003 * @state: PCI power state (D0, D1, D2, D3hot) to put the device into.
8011004 *
....@@ -821,25 +1024,35 @@
8211024 if (state < PCI_D0 || state > PCI_D3hot)
8221025 return -EINVAL;
8231026
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
1027
+ /*
1028
+ * Validate transition: We can enter D0 from any state, but if
1029
+ * we're already in a low-power state, we can only go deeper. E.g.,
1030
+ * we can go from D1 to D3, but we can't go directly from D3 to D1;
1031
+ * we'd have to go from D3 to D0, then to D1.
8271032 */
8281033 if (state != PCI_D0 && dev->current_state <= PCI_D3cold
8291034 && dev->current_state > state) {
830
- pci_err(dev, "invalid power transition (from state %d to %d)\n",
831
- dev->current_state, state);
1035
+ pci_err(dev, "invalid power transition (from %s to %s)\n",
1036
+ pci_power_name(dev->current_state),
1037
+ pci_power_name(state));
8321038 return -EINVAL;
8331039 }
8341040
835
- /* check if this device supports the desired state */
1041
+ /* Check if this device supports the desired state */
8361042 if ((state == PCI_D1 && !dev->d1_support)
8371043 || (state == PCI_D2 && !dev->d2_support))
8381044 return -EIO;
8391045
8401046 pci_read_config_word(dev, dev->pm_cap + PCI_PM_CTRL, &pmcsr);
1047
+ if (pmcsr == (u16) ~0) {
1048
+ pci_err(dev, "can't change power state from %s to %s (config space inaccessible)\n",
1049
+ pci_power_name(dev->current_state),
1050
+ pci_power_name(state));
1051
+ return -EIO;
1052
+ }
8411053
842
- /* If we're (effectively) in D3, force entire word to 0.
1054
+ /*
1055
+ * If we're (effectively) in D3, force entire word to 0.
8431056 * This doesn't affect PME_Status, disables PME_En, and
8441057 * sets PowerState to 0.
8451058 */
....@@ -856,17 +1069,19 @@
8561069 if ((pmcsr & PCI_PM_CTRL_STATE_MASK) == PCI_D3hot
8571070 && !(pmcsr & PCI_PM_CTRL_NO_SOFT_RESET))
8581071 need_restore = true;
859
- /* Fall-through: force to D0 */
1072
+ fallthrough; /* force to D0 */
8601073 default:
8611074 pmcsr = 0;
8621075 break;
8631076 }
8641077
865
- /* enter specified state */
1078
+ /* Enter specified state */
8661079 pci_write_config_word(dev, dev->pm_cap + PCI_PM_CTRL, pmcsr);
8671080
868
- /* Mandatory power management transition delays */
869
- /* see PCI PM 1.1 5.6.1 table 18 */
1081
+ /*
1082
+ * Mandatory power management transition delays; see PCI PM 1.1
1083
+ * 5.6.1 table 18
1084
+ */
8701085 if (state == PCI_D3hot || dev->current_state == PCI_D3hot)
8711086 pci_dev_d3_sleep(dev);
8721087 else if (state == PCI_D2 || dev->current_state == PCI_D2)
....@@ -874,9 +1089,10 @@
8741089
8751090 pci_read_config_word(dev, dev->pm_cap + PCI_PM_CTRL, &pmcsr);
8761091 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);
1092
+ if (dev->current_state != state)
1093
+ pci_info_ratelimited(dev, "refused to change power state from %s to %s\n",
1094
+ pci_power_name(dev->current_state),
1095
+ pci_power_name(state));
8801096
8811097 /*
8821098 * According to section 5.4.1 of the "PCI BUS POWER MANAGEMENT
....@@ -928,11 +1144,26 @@
9281144 }
9291145
9301146 /**
1147
+ * pci_refresh_power_state - Refresh the given device's power state data
1148
+ * @dev: Target PCI device.
1149
+ *
1150
+ * Ask the platform to refresh the devices power state information and invoke
1151
+ * pci_update_current_state() to update its current PCI power state.
1152
+ */
1153
+void pci_refresh_power_state(struct pci_dev *dev)
1154
+{
1155
+ if (platform_pci_power_manageable(dev))
1156
+ platform_pci_refresh_power_state(dev);
1157
+
1158
+ pci_update_current_state(dev, dev->current_state);
1159
+}
1160
+
1161
+/**
9311162 * pci_platform_power_transition - Use platform to change device power state
9321163 * @dev: PCI device to handle.
9331164 * @state: State to put the device into.
9341165 */
935
-static int pci_platform_power_transition(struct pci_dev *dev, pci_power_t state)
1166
+int pci_platform_power_transition(struct pci_dev *dev, pci_power_t state)
9361167 {
9371168 int error;
9381169
....@@ -948,6 +1179,7 @@
9481179
9491180 return error;
9501181 }
1182
+EXPORT_SYMBOL_GPL(pci_platform_power_transition);
9511183
9521184 /**
9531185 * pci_wakeup - Wake up a PCI device
....@@ -971,34 +1203,70 @@
9711203 pci_walk_bus(bus, pci_wakeup, NULL);
9721204 }
9731205
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)
1206
+static int pci_dev_wait(struct pci_dev *dev, char *reset_type, int timeout)
9801207 {
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);
1208
+ int delay = 1;
1209
+ u32 id;
1210
+
1211
+ /*
1212
+ * After reset, the device should not silently discard config
1213
+ * requests, but it may still indicate that it needs more time by
1214
+ * responding to them with CRS completions. The Root Port will
1215
+ * generally synthesize ~0 data to complete the read (except when
1216
+ * CRS SV is enabled and the read was for the Vendor ID; in that
1217
+ * case it synthesizes 0x0001 data).
1218
+ *
1219
+ * Wait for the device to return a non-CRS completion. Read the
1220
+ * Command register instead of Vendor ID so we don't have to
1221
+ * contend with the CRS SV value.
1222
+ */
1223
+ pci_read_config_dword(dev, PCI_COMMAND, &id);
1224
+ while (id == ~0) {
1225
+ if (delay > timeout) {
1226
+ pci_warn(dev, "not ready %dms after %s; giving up\n",
1227
+ delay - 1, reset_type);
1228
+ return -ENOTTY;
10001229 }
1230
+
1231
+ if (delay > 1000)
1232
+ pci_info(dev, "not ready %dms after %s; waiting\n",
1233
+ delay - 1, reset_type);
1234
+
1235
+ msleep(delay);
1236
+ delay *= 2;
1237
+ pci_read_config_dword(dev, PCI_COMMAND, &id);
10011238 }
1239
+
1240
+ if (delay > 1000)
1241
+ pci_info(dev, "ready %dms after %s\n", delay - 1,
1242
+ reset_type);
1243
+
1244
+ return 0;
1245
+}
1246
+
1247
+/**
1248
+ * pci_power_up - Put the given device into D0
1249
+ * @dev: PCI device to power up
1250
+ */
1251
+int pci_power_up(struct pci_dev *dev)
1252
+{
1253
+ pci_platform_power_transition(dev, PCI_D0);
1254
+
1255
+ /*
1256
+ * Mandatory power management transition delays are handled in
1257
+ * pci_pm_resume_noirq() and pci_pm_runtime_resume() of the
1258
+ * corresponding bridge.
1259
+ */
1260
+ if (dev->runtime_d3cold) {
1261
+ /*
1262
+ * When powering on a bridge from D3cold, the whole hierarchy
1263
+ * may be powered on into D0uninitialized state, resume them to
1264
+ * give them a chance to suspend again
1265
+ */
1266
+ pci_wakeup_bus(dev->subordinate);
1267
+ }
1268
+
1269
+ return pci_raw_set_power_state(dev, PCI_D0);
10021270 }
10031271
10041272 /**
....@@ -1026,27 +1294,6 @@
10261294 }
10271295
10281296 /**
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
-/**
10501297 * pci_set_power_state - Set the power state of a PCI device
10511298 * @dev: PCI device to handle.
10521299 * @state: PCI power state (D0, D1, D2, D3hot) to put the device into.
....@@ -1067,16 +1314,18 @@
10671314 {
10681315 int error;
10691316
1070
- /* bound the state we're entering */
1317
+ /* Bound the state we're entering */
10711318 if (state > PCI_D3cold)
10721319 state = PCI_D3cold;
10731320 else if (state < PCI_D0)
10741321 state = PCI_D0;
10751322 else if ((state == PCI_D1 || state == PCI_D2) && pci_no_d1d2(dev))
1323
+
10761324 /*
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).
1325
+ * If the device or the parent bridge do not support PCI
1326
+ * PM, ignore the request if we're doing anything other
1327
+ * than putting it into D0 (which would only happen on
1328
+ * boot).
10801329 */
10811330 return 0;
10821331
....@@ -1084,10 +1333,13 @@
10841333 if (dev->current_state == state)
10851334 return 0;
10861335
1087
- __pci_start_power_transition(dev, state);
1336
+ if (state == PCI_D0)
1337
+ return pci_power_up(dev);
10881338
1089
- /* This device is quirked not to be put into D3, so
1090
- don't put it in D3 */
1339
+ /*
1340
+ * This device is quirked not to be put into D3, so don't put it in
1341
+ * D3
1342
+ */
10911343 if (state >= PCI_D3hot && (dev->dev_flags & PCI_DEV_FLAGS_NO_D3))
10921344 return 0;
10931345
....@@ -1098,34 +1350,26 @@
10981350 error = pci_raw_set_power_state(dev, state > PCI_D3hot ?
10991351 PCI_D3hot : state);
11001352
1101
- if (!__pci_complete_power_transition(dev, state))
1102
- error = 0;
1353
+ if (pci_platform_power_transition(dev, state))
1354
+ return error;
11031355
1104
- return error;
1356
+ /* Powering off a bridge may power off the whole hierarchy */
1357
+ if (state == PCI_D3cold)
1358
+ pci_bus_set_current_state(dev->subordinate, PCI_D3cold);
1359
+
1360
+ return 0;
11051361 }
11061362 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
-}
11181363
11191364 /**
11201365 * pci_choose_state - Choose the power state of a PCI device
11211366 * @dev: PCI device to be suspended
11221367 * @state: target sleep state for the whole system. This is the value
1123
- * that is passed to suspend() function.
1368
+ * that is passed to suspend() function.
11241369 *
11251370 * Returns PCI power state suitable for given device and given system
11261371 * message.
11271372 */
1128
-
11291373 pci_power_t pci_choose_state(struct pci_dev *dev, pm_message_t state)
11301374 {
11311375 pci_power_t ret;
....@@ -1226,7 +1470,6 @@
12261470 pcie_capability_write_word(dev, PCI_EXP_SLTCTL2, cap[i++]);
12271471 }
12281472
1229
-
12301473 static int pci_save_pcix_state(struct pci_dev *dev)
12311474 {
12321475 int pos;
....@@ -1263,17 +1506,60 @@
12631506 pci_write_config_word(dev, pos + PCI_X_CMD, cap[i++]);
12641507 }
12651508
1509
+static void pci_save_ltr_state(struct pci_dev *dev)
1510
+{
1511
+ int ltr;
1512
+ struct pci_cap_saved_state *save_state;
1513
+ u16 *cap;
1514
+
1515
+ if (!pci_is_pcie(dev))
1516
+ return;
1517
+
1518
+ ltr = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_LTR);
1519
+ if (!ltr)
1520
+ return;
1521
+
1522
+ save_state = pci_find_saved_ext_cap(dev, PCI_EXT_CAP_ID_LTR);
1523
+ if (!save_state) {
1524
+ pci_err(dev, "no suspend buffer for LTR; ASPM issues possible after resume\n");
1525
+ return;
1526
+ }
1527
+
1528
+ cap = (u16 *)&save_state->cap.data[0];
1529
+ pci_read_config_word(dev, ltr + PCI_LTR_MAX_SNOOP_LAT, cap++);
1530
+ pci_read_config_word(dev, ltr + PCI_LTR_MAX_NOSNOOP_LAT, cap++);
1531
+}
1532
+
1533
+static void pci_restore_ltr_state(struct pci_dev *dev)
1534
+{
1535
+ struct pci_cap_saved_state *save_state;
1536
+ int ltr;
1537
+ u16 *cap;
1538
+
1539
+ save_state = pci_find_saved_ext_cap(dev, PCI_EXT_CAP_ID_LTR);
1540
+ ltr = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_LTR);
1541
+ if (!save_state || !ltr)
1542
+ return;
1543
+
1544
+ cap = (u16 *)&save_state->cap.data[0];
1545
+ pci_write_config_word(dev, ltr + PCI_LTR_MAX_SNOOP_LAT, *cap++);
1546
+ pci_write_config_word(dev, ltr + PCI_LTR_MAX_NOSNOOP_LAT, *cap++);
1547
+}
12661548
12671549 /**
1268
- * pci_save_state - save the PCI configuration space of a device before suspending
1269
- * @dev: - PCI device that we're dealing with
1550
+ * pci_save_state - save the PCI configuration space of a device before
1551
+ * suspending
1552
+ * @dev: PCI device that we're dealing with
12701553 */
12711554 int pci_save_state(struct pci_dev *dev)
12721555 {
12731556 int i;
12741557 /* XXX: 100% dword access ok here? */
1275
- for (i = 0; i < 16; i++)
1558
+ for (i = 0; i < 16; i++) {
12761559 pci_read_config_dword(dev, i * 4, &dev->saved_config_space[i]);
1560
+ pci_dbg(dev, "saving config space at offset %#x (reading %#x)\n",
1561
+ i * 4, dev->saved_config_space[i]);
1562
+ }
12771563 dev->state_saved = true;
12781564
12791565 i = pci_save_pcie_state(dev);
....@@ -1284,6 +1570,9 @@
12841570 if (i != 0)
12851571 return i;
12861572
1573
+ pci_save_ltr_state(dev);
1574
+ pci_save_dpc_state(dev);
1575
+ pci_save_aer_state(dev);
12871576 return pci_save_vc_state(dev);
12881577 }
12891578 EXPORT_SYMBOL(pci_save_state);
....@@ -1375,22 +1664,29 @@
13751664
13761665 /**
13771666 * pci_restore_state - Restore the saved state of a PCI device
1378
- * @dev: - PCI device that we're dealing with
1667
+ * @dev: PCI device that we're dealing with
13791668 */
13801669 void pci_restore_state(struct pci_dev *dev)
13811670 {
13821671 if (!dev->state_saved)
13831672 return;
13841673
1385
- /* PCI Express register must be restored first */
1674
+ /*
1675
+ * Restore max latencies (in the LTR capability) before enabling
1676
+ * LTR itself (in the PCIe capability).
1677
+ */
1678
+ pci_restore_ltr_state(dev);
1679
+
13861680 pci_restore_pcie_state(dev);
13871681 pci_restore_pasid_state(dev);
13881682 pci_restore_pri_state(dev);
13891683 pci_restore_ats_state(dev);
13901684 pci_restore_vc_state(dev);
13911685 pci_restore_rebar_state(dev);
1686
+ pci_restore_dpc_state(dev);
13921687
1393
- pci_cleanup_aer_error_status_regs(dev);
1688
+ pci_aer_clear_status(dev);
1689
+ pci_restore_aer_state(dev);
13941690
13951691 pci_restore_config_space(dev);
13961692
....@@ -1407,7 +1703,7 @@
14071703
14081704 struct pci_saved_state {
14091705 u32 config_space[16];
1410
- struct pci_cap_saved_data cap[0];
1706
+ struct pci_cap_saved_data cap[];
14111707 };
14121708
14131709 /**
....@@ -1546,8 +1842,8 @@
15461842 * pci_reenable_device - Resume abandoned device
15471843 * @dev: PCI device to be resumed
15481844 *
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.
1845
+ * NOTE: This function is a backend of pci_default_resume() and is not supposed
1846
+ * to be called by normal code, write proper resume handler and use it instead.
15511847 */
15521848 int pci_reenable_device(struct pci_dev *dev)
15531849 {
....@@ -1618,9 +1914,9 @@
16181914 * pci_enable_device_io - Initialize a device for use with IO space
16191915 * @dev: PCI device to be initialized
16201916 *
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.
1917
+ * Initialize device before it's used by a driver. Ask low-level code
1918
+ * to enable I/O resources. Wake up the device if it was suspended.
1919
+ * Beware, this function can fail.
16241920 */
16251921 int pci_enable_device_io(struct pci_dev *dev)
16261922 {
....@@ -1632,9 +1928,9 @@
16321928 * pci_enable_device_mem - Initialize a device for use with Memory space
16331929 * @dev: PCI device to be initialized
16341930 *
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.
1931
+ * Initialize device before it's used by a driver. Ask low-level code
1932
+ * to enable Memory resources. Wake up the device if it was suspended.
1933
+ * Beware, this function can fail.
16381934 */
16391935 int pci_enable_device_mem(struct pci_dev *dev)
16401936 {
....@@ -1646,12 +1942,12 @@
16461942 * pci_enable_device - Initialize device before it's used by a driver.
16471943 * @dev: PCI device to be initialized
16481944 *
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.
1945
+ * Initialize device before it's used by a driver. Ask low-level code
1946
+ * to enable I/O and memory. Wake up the device if it was suspended.
1947
+ * Beware, this function can fail.
16521948 *
1653
- * Note we don't actually enable the device many times if we call
1654
- * this function repeatedly (we just increment the count).
1949
+ * Note we don't actually enable the device many times if we call
1950
+ * this function repeatedly (we just increment the count).
16551951 */
16561952 int pci_enable_device(struct pci_dev *dev)
16571953 {
....@@ -1660,8 +1956,8 @@
16601956 EXPORT_SYMBOL(pci_enable_device);
16611957
16621958 /*
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
1959
+ * Managed PCI resources. This manages device on/off, INTx/MSI/MSI-X
1960
+ * on/off and BAR regions. pci_dev itself records MSI/MSI-X status, so
16651961 * there's no need to track it separately. pci_devres is initialized
16661962 * when a device is enabled using managed PCI device enable interface.
16671963 */
....@@ -1779,7 +2075,8 @@
17792075 }
17802076
17812077 /**
1782
- * pcibios_release_device - provide arch specific hooks when releasing device dev
2078
+ * pcibios_release_device - provide arch specific hooks when releasing
2079
+ * device dev
17832080 * @dev: the PCI device being released
17842081 *
17852082 * Permits the platform to provide architecture specific functionality when
....@@ -1870,8 +2167,7 @@
18702167 * @dev: the PCIe device reset
18712168 * @state: Reset state to enter into
18722169 *
1873
- *
1874
- * Sets the PCIe reset state for the device. This is the default
2170
+ * Set the PCIe reset state for the device. This is the default
18752171 * implementation. Architecture implementations can override this.
18762172 */
18772173 int __weak pcibios_set_pcie_reset_state(struct pci_dev *dev,
....@@ -1885,7 +2181,6 @@
18852181 * @dev: the PCIe device reset
18862182 * @state: Reset state to enter into
18872183 *
1888
- *
18892184 * Sets the PCI reset state for the device.
18902185 */
18912186 int pci_set_pcie_reset_state(struct pci_dev *dev, enum pcie_reset_state state)
....@@ -1893,6 +2188,14 @@
18932188 return pcibios_set_pcie_reset_state(dev, state);
18942189 }
18952190 EXPORT_SYMBOL_GPL(pci_set_pcie_reset_state);
2191
+
2192
+void pcie_clear_device_status(struct pci_dev *dev)
2193
+{
2194
+ u16 sta;
2195
+
2196
+ pcie_capability_read_word(dev, PCI_EXP_DEVSTA, &sta);
2197
+ pcie_capability_write_word(dev, PCI_EXP_DEVSTA, sta);
2198
+}
18962199
18972200 /**
18982201 * pcie_clear_root_pme_status - Clear root port PME interrupt status.
....@@ -2147,10 +2450,13 @@
21472450 int ret = 0;
21482451
21492452 /*
2150
- * Bridges can only signal wakeup on behalf of subordinate devices,
2151
- * but that is set up elsewhere, so skip them.
2453
+ * Bridges that are not power-manageable directly only signal
2454
+ * wakeup on behalf of subordinate devices which is set up
2455
+ * elsewhere, so skip them. However, bridges that are
2456
+ * power-manageable may signal wakeup for themselves (for example,
2457
+ * on a hotplug event) and they need to be covered here.
21522458 */
2153
- if (pci_has_subordinate(dev))
2459
+ if (!pci_power_manageable(dev))
21542460 return 0;
21552461
21562462 /* Don't do the same thing twice in a row for one device. */
....@@ -2258,7 +2564,7 @@
22582564 case PCI_D2:
22592565 if (pci_no_d1d2(dev))
22602566 break;
2261
- /* else: fall through */
2567
+ fallthrough;
22622568 default:
22632569 target_state = state;
22642570 }
....@@ -2297,7 +2603,8 @@
22972603 }
22982604
22992605 /**
2300
- * pci_prepare_to_sleep - prepare PCI device for system-wide transition into a sleep state
2606
+ * pci_prepare_to_sleep - prepare PCI device for system-wide transition
2607
+ * into a sleep state
23012608 * @dev: Device to handle.
23022609 *
23032610 * Choose the power state appropriate for the device depending on whether
....@@ -2325,7 +2632,8 @@
23252632 EXPORT_SYMBOL(pci_prepare_to_sleep);
23262633
23272634 /**
2328
- * pci_back_from_sleep - turn PCI device on during system-wide transition into working state
2635
+ * pci_back_from_sleep - turn PCI device on during system-wide transition
2636
+ * into working state
23292637 * @dev: Device to handle.
23302638 *
23312639 * Disable device's system wake-up capability and put it into D0.
....@@ -2407,45 +2715,56 @@
24072715 EXPORT_SYMBOL_GPL(pci_dev_run_wake);
24082716
24092717 /**
2410
- * pci_dev_keep_suspended - Check if the device can stay in the suspended state.
2718
+ * pci_dev_need_resume - Check if it is necessary to resume the device.
24112719 * @pci_dev: Device to check.
24122720 *
2413
- * Return 'true' if the device is runtime-suspended, it doesn't have to be
2721
+ * Return 'true' if the device is not runtime-suspended or it has to be
24142722 * 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.
2723
+ * suspend, or the current power state of it is not suitable for the upcoming
2724
+ * (system-wide) transition.
24202725 */
2421
-bool pci_dev_keep_suspended(struct pci_dev *pci_dev)
2726
+bool pci_dev_need_resume(struct pci_dev *pci_dev)
24222727 {
24232728 struct device *dev = &pci_dev->dev;
2424
- bool wakeup = device_may_wakeup(dev);
2729
+ pci_power_t target_state;
24252730
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;
2731
+ if (!pm_runtime_suspended(dev) || platform_pci_need_resume(pci_dev))
2732
+ return true;
2733
+
2734
+ target_state = pci_target_state(pci_dev, device_may_wakeup(dev));
24302735
24312736 /*
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.
2737
+ * If the earlier platform check has not triggered, D3cold is just power
2738
+ * removal on top of D3hot, so no need to resume the device in that
2739
+ * case.
24402740 */
2741
+ return target_state != pci_dev->current_state &&
2742
+ target_state != PCI_D3cold &&
2743
+ pci_dev->current_state != PCI_D3hot;
2744
+}
2745
+
2746
+/**
2747
+ * pci_dev_adjust_pme - Adjust PME setting for a suspended device.
2748
+ * @pci_dev: Device to check.
2749
+ *
2750
+ * If the device is suspended and it is not configured for system wakeup,
2751
+ * disable PME for it to prevent it from waking up the system unnecessarily.
2752
+ *
2753
+ * Note that if the device's power state is D3cold and the platform check in
2754
+ * pci_dev_need_resume() has not triggered, the device's configuration need not
2755
+ * be changed.
2756
+ */
2757
+void pci_dev_adjust_pme(struct pci_dev *pci_dev)
2758
+{
2759
+ struct device *dev = &pci_dev->dev;
2760
+
24412761 spin_lock_irq(&dev->power.lock);
24422762
2443
- if (pm_runtime_suspended(dev) && pci_dev->current_state < PCI_D3cold &&
2444
- !wakeup)
2763
+ if (pm_runtime_suspended(dev) && !device_may_wakeup(dev) &&
2764
+ pci_dev->current_state < PCI_D3cold)
24452765 __pci_pme_active(pci_dev, false);
24462766
24472767 spin_unlock_irq(&dev->power.lock);
2448
- return true;
24492768 }
24502769
24512770 /**
....@@ -2518,6 +2837,18 @@
25182837 DMI_MATCH(DMI_BOARD_NAME, "X299 DESIGNARE EX-CF"),
25192838 },
25202839 },
2840
+ {
2841
+ /*
2842
+ * Downstream device is not accessible after putting a root port
2843
+ * into D3cold and back into D0 on Elo i2.
2844
+ */
2845
+ .ident = "Elo i2",
2846
+ .matches = {
2847
+ DMI_MATCH(DMI_SYS_VENDOR, "Elo Touch Solutions"),
2848
+ DMI_MATCH(DMI_PRODUCT_NAME, "Elo i2"),
2849
+ DMI_MATCH(DMI_PRODUCT_VERSION, "RevB"),
2850
+ },
2851
+ },
25212852 #endif
25222853 { }
25232854 };
....@@ -2553,6 +2884,10 @@
25532884
25542885 /* Even the oldest 2010 Thunderbolt controller supports D3. */
25552886 if (bridge->is_thunderbolt)
2887
+ return true;
2888
+
2889
+ /* Platform might know better if the bridge supports D3 */
2890
+ if (platform_pci_bridge_d3(bridge))
25562891 return true;
25572892
25582893 /*
....@@ -2691,6 +3026,7 @@
26913026 void pci_pm_init(struct pci_dev *dev)
26923027 {
26933028 int pm;
3029
+ u16 status;
26943030 u16 pmc;
26953031
26963032 pm_runtime_forbid(&dev->dev);
....@@ -2716,7 +3052,7 @@
27163052 }
27173053
27183054 dev->pm_cap = pm;
2719
- dev->d3_delay = PCI_PM_D3_WAIT;
3055
+ dev->d3hot_delay = PCI_PM_D3HOT_WAIT;
27203056 dev->d3cold_delay = PCI_PM_D3COLD_WAIT;
27213057 dev->bridge_d3 = pci_bridge_d3_possible(dev);
27223058 dev->d3cold_allowed = true;
....@@ -2730,18 +3066,18 @@
27303066 dev->d2_support = true;
27313067
27323068 if (dev->d1_support || dev->d2_support)
2733
- pci_printk(KERN_DEBUG, dev, "supports%s%s\n",
3069
+ pci_info(dev, "supports%s%s\n",
27343070 dev->d1_support ? " D1" : "",
27353071 dev->d2_support ? " D2" : "");
27363072 }
27373073
27383074 pmc &= PCI_PM_CAP_PME_MASK;
27393075 if (pmc) {
2740
- pci_printk(KERN_DEBUG, dev, "PME# supported from%s%s%s%s%s\n",
3076
+ pci_info(dev, "PME# supported from%s%s%s%s%s\n",
27413077 (pmc & PCI_PM_CAP_PME_D0) ? " D0" : "",
27423078 (pmc & PCI_PM_CAP_PME_D1) ? " D1" : "",
27433079 (pmc & PCI_PM_CAP_PME_D2) ? " D2" : "",
2744
- (pmc & PCI_PM_CAP_PME_D3) ? " D3hot" : "",
3080
+ (pmc & PCI_PM_CAP_PME_D3hot) ? " D3hot" : "",
27453081 (pmc & PCI_PM_CAP_PME_D3cold) ? " D3cold" : "");
27463082 dev->pme_support = pmc >> PCI_PM_CAP_PME_SHIFT;
27473083 dev->pme_poll = true;
....@@ -2753,6 +3089,10 @@
27533089 /* Disable the PME# generation functionality */
27543090 pci_pme_active(dev, false);
27553091 }
3092
+
3093
+ pci_read_config_word(dev, PCI_STATUS, &status);
3094
+ if (status & PCI_STATUS_IMM_READY)
3095
+ dev->imm_ready = 1;
27563096 }
27573097
27583098 static unsigned long pci_ea_flags(struct pci_dev *dev, u8 prop)
....@@ -2901,16 +3241,16 @@
29013241 res->flags = flags;
29023242
29033243 if (bei <= PCI_EA_BEI_BAR5)
2904
- pci_printk(KERN_DEBUG, dev, "BAR %d: %pR (from Enhanced Allocation, properties %#02x)\n",
3244
+ pci_info(dev, "BAR %d: %pR (from Enhanced Allocation, properties %#02x)\n",
29053245 bei, res, prop);
29063246 else if (bei == PCI_EA_BEI_ROM)
2907
- pci_printk(KERN_DEBUG, dev, "ROM: %pR (from Enhanced Allocation, properties %#02x)\n",
3247
+ pci_info(dev, "ROM: %pR (from Enhanced Allocation, properties %#02x)\n",
29083248 res, prop);
29093249 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",
3250
+ pci_info(dev, "VF BAR %d: %pR (from Enhanced Allocation, properties %#02x)\n",
29113251 bei - PCI_EA_BEI_VF_BAR0, res, prop);
29123252 else
2913
- pci_printk(KERN_DEBUG, dev, "BEI %d res: %pR (from Enhanced Allocation, properties %#02x)\n",
3253
+ pci_info(dev, "BEI %d res: %pR (from Enhanced Allocation, properties %#02x)\n",
29143254 bei, res, prop);
29153255
29163256 out:
....@@ -2954,7 +3294,7 @@
29543294
29553295 /**
29563296 * _pci_add_cap_save_buffer - allocate buffer for saving given
2957
- * capability registers
3297
+ * capability registers
29583298 * @dev: the PCI device
29593299 * @cap: the capability to allocate the buffer for
29603300 * @extended: Standard or Extended capability ID
....@@ -3013,6 +3353,11 @@
30133353 if (error)
30143354 pci_err(dev, "unable to preallocate PCI-X save buffer\n");
30153355
3356
+ error = pci_add_ext_cap_save_buffer(dev, PCI_EXT_CAP_ID_LTR,
3357
+ 2 * sizeof(u16));
3358
+ if (error)
3359
+ pci_err(dev, "unable to allocate suspend buffer for LTR\n");
3360
+
30163361 pci_allocate_vc_save_buffers(dev);
30173362 }
30183363
....@@ -3059,140 +3404,12 @@
30593404 }
30603405 }
30613406
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
-
31903407 static bool pci_acs_flags_enabled(struct pci_dev *pdev, u16 acs_flags)
31913408 {
31923409 int pos;
31933410 u16 cap, ctrl;
31943411
3195
- pos = pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_ACS);
3412
+ pos = pdev->acs_cap;
31963413 if (!pos)
31973414 return false;
31983415
....@@ -3315,6 +3532,23 @@
33153532 } while (pdev != end);
33163533
33173534 return true;
3535
+}
3536
+
3537
+/**
3538
+ * pci_acs_init - Initialize ACS if hardware supports it
3539
+ * @dev: the PCI device
3540
+ */
3541
+void pci_acs_init(struct pci_dev *dev)
3542
+{
3543
+ dev->acs_cap = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_ACS);
3544
+
3545
+ /*
3546
+ * Attempt to enable ACS regardless of capability because some Root
3547
+ * Ports (e.g. those quirked with *_intel_pch_acs_*) do not have
3548
+ * the standard ACS capability but still support ACS via those
3549
+ * quirks.
3550
+ */
3551
+ pci_enable_acs(dev);
33183552 }
33193553
33203554 /**
....@@ -3484,7 +3718,7 @@
34843718 }
34853719
34863720 /* Ensure upstream ports don't block AtomicOps on egress */
3487
- if (!bridge->has_secondary_link) {
3721
+ if (pci_pcie_type(bridge) == PCI_EXP_TYPE_UPSTREAM) {
34883722 pcie_capability_read_dword(bridge, PCI_EXP_DEVCTL2,
34893723 &ctl2);
34903724 if (ctl2 & PCI_EXP_DEVCTL2_ATOMIC_EGRESS_BLOCK)
....@@ -3561,13 +3795,14 @@
35613795 EXPORT_SYMBOL_GPL(pci_common_swizzle);
35623796
35633797 /**
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
3798
+ * pci_release_region - Release a PCI bar
3799
+ * @pdev: PCI device whose resources were previously reserved by
3800
+ * pci_request_region()
3801
+ * @bar: BAR to release
35673802 *
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.
3803
+ * Releases the PCI I/O and memory resources previously reserved by a
3804
+ * successful call to pci_request_region(). Call this function only
3805
+ * after all use of the PCI regions has ceased.
35713806 */
35723807 void pci_release_region(struct pci_dev *pdev, int bar)
35733808 {
....@@ -3589,23 +3824,23 @@
35893824 EXPORT_SYMBOL(pci_release_region);
35903825
35913826 /**
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
3827
+ * __pci_request_region - Reserved PCI I/O and memory resource
3828
+ * @pdev: PCI device whose resources are to be reserved
3829
+ * @bar: BAR to be reserved
3830
+ * @res_name: Name to be associated with resource.
3831
+ * @exclusive: whether the region access is exclusive or not
35973832 *
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.
3833
+ * Mark the PCI region associated with PCI device @pdev BAR @bar as
3834
+ * being reserved by owner @res_name. Do not access any
3835
+ * address inside the PCI regions unless this call returns
3836
+ * successfully.
36023837 *
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.
3838
+ * If @exclusive is set, then the region is marked so that userspace
3839
+ * is explicitly not allowed to map the resource via /dev/mem or
3840
+ * sysfs MMIO access.
36063841 *
3607
- * Returns 0 on success, or %EBUSY on error. A warning
3608
- * message is also printed on failure.
3842
+ * Returns 0 on success, or %EBUSY on error. A warning
3843
+ * message is also printed on failure.
36093844 */
36103845 static int __pci_request_region(struct pci_dev *pdev, int bar,
36113846 const char *res_name, int exclusive)
....@@ -3639,49 +3874,24 @@
36393874 }
36403875
36413876 /**
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
3877
+ * pci_request_region - Reserve PCI I/O and memory resource
3878
+ * @pdev: PCI device whose resources are to be reserved
3879
+ * @bar: BAR to be reserved
3880
+ * @res_name: Name to be associated with resource
36463881 *
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.
3882
+ * Mark the PCI region associated with PCI device @pdev BAR @bar as
3883
+ * being reserved by owner @res_name. Do not access any
3884
+ * address inside the PCI regions unless this call returns
3885
+ * successfully.
36513886 *
3652
- * Returns 0 on success, or %EBUSY on error. A warning
3653
- * message is also printed on failure.
3887
+ * Returns 0 on success, or %EBUSY on error. A warning
3888
+ * message is also printed on failure.
36543889 */
36553890 int pci_request_region(struct pci_dev *pdev, int bar, const char *res_name)
36563891 {
36573892 return __pci_request_region(pdev, bar, res_name, 0);
36583893 }
36593894 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);
36853895
36863896 /**
36873897 * pci_release_selected_regions - Release selected PCI I/O and memory resources
....@@ -3695,7 +3905,7 @@
36953905 {
36963906 int i;
36973907
3698
- for (i = 0; i < 6; i++)
3908
+ for (i = 0; i < PCI_STD_NUM_BARS; i++)
36993909 if (bars & (1 << i))
37003910 pci_release_region(pdev, i);
37013911 }
....@@ -3706,7 +3916,7 @@
37063916 {
37073917 int i;
37083918
3709
- for (i = 0; i < 6; i++)
3919
+ for (i = 0; i < PCI_STD_NUM_BARS; i++)
37103920 if (bars & (1 << i))
37113921 if (__pci_request_region(pdev, i, res_name, excl))
37123922 goto err_out;
....@@ -3743,65 +3953,66 @@
37433953 EXPORT_SYMBOL(pci_request_selected_regions_exclusive);
37443954
37453955 /**
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
3956
+ * pci_release_regions - Release reserved PCI I/O and memory resources
3957
+ * @pdev: PCI device whose resources were previously reserved by
3958
+ * pci_request_regions()
37483959 *
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.
3960
+ * Releases all PCI I/O and memory resources previously reserved by a
3961
+ * successful call to pci_request_regions(). Call this function only
3962
+ * after all use of the PCI regions has ceased.
37523963 */
37533964
37543965 void pci_release_regions(struct pci_dev *pdev)
37553966 {
3756
- pci_release_selected_regions(pdev, (1 << 6) - 1);
3967
+ pci_release_selected_regions(pdev, (1 << PCI_STD_NUM_BARS) - 1);
37573968 }
37583969 EXPORT_SYMBOL(pci_release_regions);
37593970
37603971 /**
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.
3972
+ * pci_request_regions - Reserve PCI I/O and memory resources
3973
+ * @pdev: PCI device whose resources are to be reserved
3974
+ * @res_name: Name to be associated with resource.
37643975 *
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.
3976
+ * Mark all PCI regions associated with PCI device @pdev as
3977
+ * being reserved by owner @res_name. Do not access any
3978
+ * address inside the PCI regions unless this call returns
3979
+ * successfully.
37693980 *
3770
- * Returns 0 on success, or %EBUSY on error. A warning
3771
- * message is also printed on failure.
3981
+ * Returns 0 on success, or %EBUSY on error. A warning
3982
+ * message is also printed on failure.
37723983 */
37733984 int pci_request_regions(struct pci_dev *pdev, const char *res_name)
37743985 {
3775
- return pci_request_selected_regions(pdev, ((1 << 6) - 1), res_name);
3986
+ return pci_request_selected_regions(pdev,
3987
+ ((1 << PCI_STD_NUM_BARS) - 1), res_name);
37763988 }
37773989 EXPORT_SYMBOL(pci_request_regions);
37783990
37793991 /**
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.
3992
+ * pci_request_regions_exclusive - Reserve PCI I/O and memory resources
3993
+ * @pdev: PCI device whose resources are to be reserved
3994
+ * @res_name: Name to be associated with resource.
37833995 *
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.
3996
+ * Mark all PCI regions associated with PCI device @pdev as being reserved
3997
+ * by owner @res_name. Do not access any address inside the PCI regions
3998
+ * unless this call returns successfully.
37883999 *
3789
- * pci_request_regions_exclusive() will mark the region so that
3790
- * /dev/mem and the sysfs MMIO access will not be allowed.
4000
+ * pci_request_regions_exclusive() will mark the region so that /dev/mem
4001
+ * and the sysfs MMIO access will not be allowed.
37914002 *
3792
- * Returns 0 on success, or %EBUSY on error. A warning
3793
- * message is also printed on failure.
4003
+ * Returns 0 on success, or %EBUSY on error. A warning message is also
4004
+ * printed on failure.
37944005 */
37954006 int pci_request_regions_exclusive(struct pci_dev *pdev, const char *res_name)
37964007 {
37974008 return pci_request_selected_regions_exclusive(pdev,
3798
- ((1 << 6) - 1), res_name);
4009
+ ((1 << PCI_STD_NUM_BARS) - 1), res_name);
37994010 }
38004011 EXPORT_SYMBOL(pci_request_regions_exclusive);
38014012
38024013 /*
38034014 * Record the PCI IO range (expressed as CPU physical address + size).
3804
- * Return a negative value if an error has occured, zero otherwise
4015
+ * Return a negative value if an error has occurred, zero otherwise
38054016 */
38064017 int pci_register_io_range(struct fwnode_handle *fwnode, phys_addr_t addr,
38074018 resource_size_t size)
....@@ -3847,6 +4058,7 @@
38474058
38484059 return address;
38494060 }
4061
+EXPORT_SYMBOL_GPL(pci_pio_to_address);
38504062
38514063 unsigned long __weak pci_address_to_pio(phys_addr_t address)
38524064 {
....@@ -3861,14 +4073,14 @@
38614073 }
38624074
38634075 /**
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
4076
+ * pci_remap_iospace - Remap the memory mapped I/O space
4077
+ * @res: Resource describing the I/O space
4078
+ * @phys_addr: physical address of range to be mapped
38674079 *
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.
4080
+ * Remap the memory mapped I/O space described by the @res and the CPU
4081
+ * physical address @phys_addr into virtual address space. Only
4082
+ * architectures that have memory mapped IO functions defined (and the
4083
+ * PCI_IOBASE value defined) should call this function.
38724084 */
38734085 int pci_remap_iospace(const struct resource *res, phys_addr_t phys_addr)
38744086 {
....@@ -3884,8 +4096,10 @@
38844096 return ioremap_page_range(vaddr, vaddr + resource_size(res), phys_addr,
38854097 pgprot_device(PAGE_KERNEL));
38864098 #else
3887
- /* this architecture does not have memory mapped I/O space,
3888
- so this function should never be called */
4099
+ /*
4100
+ * This architecture does not have memory mapped I/O space,
4101
+ * so this function should never be called
4102
+ */
38894103 WARN_ONCE(1, "This architecture does not support memory mapped I/O\n");
38904104 return -ENODEV;
38914105 #endif
....@@ -3893,12 +4107,12 @@
38934107 EXPORT_SYMBOL(pci_remap_iospace);
38944108
38954109 /**
3896
- * pci_unmap_iospace - Unmap the memory mapped I/O space
3897
- * @res: resource to be unmapped
4110
+ * pci_unmap_iospace - Unmap the memory mapped I/O space
4111
+ * @res: resource to be unmapped
38984112 *
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.
4113
+ * Unmap the CPU virtual address @res from virtual address space. Only
4114
+ * architectures that have memory mapped IO functions defined (and the
4115
+ * PCI_IOBASE value defined) should call this function.
39024116 */
39034117 void pci_unmap_iospace(struct resource *res)
39044118 {
....@@ -4141,7 +4355,7 @@
41414355 if (cacheline_size == pci_cache_line_size)
41424356 return 0;
41434357
4144
- pci_printk(KERN_DEBUG, dev, "cache line size of %d is not supported\n",
4358
+ pci_info(dev, "cache line size of %d is not supported\n",
41454359 pci_cache_line_size << 2);
41464360
41474361 return -EINVAL;
....@@ -4244,7 +4458,7 @@
42444458 * @pdev: the PCI device to operate on
42454459 * @enable: boolean: whether to enable or disable PCI INTx
42464460 *
4247
- * Enables/disables PCI INTx for device dev
4461
+ * Enables/disables PCI INTx for device @pdev
42484462 */
42494463 void pci_intx(struct pci_dev *pdev, int enable)
42504464 {
....@@ -4320,9 +4534,8 @@
43204534 * pci_check_and_mask_intx - mask INTx on pending interrupt
43214535 * @dev: the PCI device to operate on
43224536 *
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.
4537
+ * Check if the device dev has its INTx line asserted, mask it and return
4538
+ * true in that case. False is returned if no interrupt was pending.
43264539 */
43274540 bool pci_check_and_mask_intx(struct pci_dev *dev)
43284541 {
....@@ -4334,9 +4547,9 @@
43344547 * pci_check_and_unmask_intx - unmask INTx if no interrupt is pending
43354548 * @dev: the PCI device to operate on
43364549 *
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.
4550
+ * Check if the device dev has its INTx line asserted, unmask it if not and
4551
+ * return true. False is returned and the mask remains active if there was
4552
+ * still an interrupt pending.
43404553 */
43414554 bool pci_check_and_unmask_intx(struct pci_dev *dev)
43424555 {
....@@ -4345,7 +4558,7 @@
43454558 EXPORT_SYMBOL_GPL(pci_check_and_unmask_intx);
43464559
43474560 /**
4348
- * pci_wait_for_pending_transaction - waits for pending transaction
4561
+ * pci_wait_for_pending_transaction - wait for pending transaction
43494562 * @dev: the PCI device to operate on
43504563 *
43514564 * Return 0 if transaction is pending 1 otherwise.
....@@ -4360,50 +4573,9 @@
43604573 }
43614574 EXPORT_SYMBOL(pci_wait_for_pending_transaction);
43624575
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
-
44044576 /**
44054577 * pcie_has_flr - check if a device supports function level resets
4406
- * @dev: device to check
4578
+ * @dev: device to check
44074579 *
44084580 * Returns true if the device advertises support for PCIe function level
44094581 * resets.
....@@ -4422,7 +4594,7 @@
44224594
44234595 /**
44244596 * pcie_flr - initiate a PCIe function level reset
4425
- * @dev: device to reset
4597
+ * @dev: device to reset
44264598 *
44274599 * Initiate a function level reset on @dev. The caller should ensure the
44284600 * device supports FLR before calling this function, e.g. by using the
....@@ -4434,6 +4606,9 @@
44344606 pci_err(dev, "timed out waiting for pending transaction; performing function level reset anyway\n");
44354607
44364608 pcie_capability_set_word(dev, PCI_EXP_DEVCTL, PCI_EXP_DEVCTL_BCR_FLR);
4609
+
4610
+ if (dev->imm_ready)
4611
+ return 0;
44374612
44384613 /*
44394614 * Per PCIe r4.0, sec 6.6.2, a device must complete an FLR within
....@@ -4467,7 +4642,7 @@
44674642
44684643 /*
44694644 * 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
4645
+ * is used, so we use the control offset rather than status and shift
44714646 * the test bit to match.
44724647 */
44734648 if (!pci_wait_for_pending(dev, pos + PCI_AF_CTRL,
....@@ -4475,6 +4650,9 @@
44754650 pci_err(dev, "timed out waiting for pending transaction; performing AF function level reset anyway\n");
44764651
44774652 pci_write_config_byte(dev, pos + PCI_AF_CTRL, PCI_AF_CTRL_FLR);
4653
+
4654
+ if (dev->imm_ready)
4655
+ return 0;
44784656
44794657 /*
44804658 * Per Advanced Capabilities for Conventional PCI ECN, 13 April 2006,
....@@ -4499,7 +4677,7 @@
44994677 *
45004678 * NOTE: This causes the caller to sleep for twice the device power transition
45014679 * 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).
4680
+ * by default (i.e. unless the @dev's d3hot_delay field has a different value).
45034681 * Moreover, only devices in D0 can be reset by this function.
45044682 */
45054683 static int pci_pm_reset(struct pci_dev *dev, int probe)
....@@ -4529,8 +4707,60 @@
45294707 pci_write_config_word(dev, dev->pm_cap + PCI_PM_CTRL, csr);
45304708 pci_dev_d3_sleep(dev);
45314709
4532
- return pci_dev_wait(dev, "PM D3->D0", PCIE_RESET_READY_POLL_MS);
4710
+ return pci_dev_wait(dev, "PM D3hot->D0", PCIE_RESET_READY_POLL_MS);
45334711 }
4712
+
4713
+/**
4714
+ * pcie_wait_for_link_delay - Wait until link is active or inactive
4715
+ * @pdev: Bridge device
4716
+ * @active: waiting for active or inactive?
4717
+ * @delay: Delay to wait after link has become active (in ms)
4718
+ *
4719
+ * Use this to wait till link becomes active or inactive.
4720
+ */
4721
+static bool pcie_wait_for_link_delay(struct pci_dev *pdev, bool active,
4722
+ int delay)
4723
+{
4724
+ int timeout = 1000;
4725
+ bool ret;
4726
+ u16 lnk_status;
4727
+
4728
+ /*
4729
+ * Some controllers might not implement link active reporting. In this
4730
+ * case, we wait for 1000 ms + any delay requested by the caller.
4731
+ */
4732
+ if (!pdev->link_active_reporting) {
4733
+ msleep(timeout + delay);
4734
+ return true;
4735
+ }
4736
+
4737
+ /*
4738
+ * PCIe r4.0 sec 6.6.1, a component must enter LTSSM Detect within 20ms,
4739
+ * after which we should expect an link active if the reset was
4740
+ * successful. If so, software must wait a minimum 100ms before sending
4741
+ * configuration requests to devices downstream this port.
4742
+ *
4743
+ * If the link fails to activate, either the device was physically
4744
+ * removed or the link is permanently failed.
4745
+ */
4746
+ if (active)
4747
+ msleep(20);
4748
+ for (;;) {
4749
+ pcie_capability_read_word(pdev, PCI_EXP_LNKSTA, &lnk_status);
4750
+ ret = !!(lnk_status & PCI_EXP_LNKSTA_DLLLA);
4751
+ if (ret == active)
4752
+ break;
4753
+ if (timeout <= 0)
4754
+ break;
4755
+ msleep(10);
4756
+ timeout -= 10;
4757
+ }
4758
+ if (active && ret)
4759
+ msleep(delay);
4760
+
4761
+ return ret == active;
4762
+}
4763
+
45344764 /**
45354765 * pcie_wait_for_link - Wait until link is active or inactive
45364766 * @pdev: Bridge device
....@@ -4540,25 +4770,127 @@
45404770 */
45414771 bool pcie_wait_for_link(struct pci_dev *pdev, bool active)
45424772 {
4543
- int timeout = 1000;
4544
- bool ret;
4545
- u16 lnk_status;
4773
+ return pcie_wait_for_link_delay(pdev, active, 100);
4774
+}
45464775
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;
4776
+/*
4777
+ * Find maximum D3cold delay required by all the devices on the bus. The
4778
+ * spec says 100 ms, but firmware can lower it and we allow drivers to
4779
+ * increase it as well.
4780
+ *
4781
+ * Called with @pci_bus_sem locked for reading.
4782
+ */
4783
+static int pci_bus_max_d3cold_delay(const struct pci_bus *bus)
4784
+{
4785
+ const struct pci_dev *pdev;
4786
+ int min_delay = 100;
4787
+ int max_delay = 0;
4788
+
4789
+ list_for_each_entry(pdev, &bus->devices, bus_list) {
4790
+ if (pdev->d3cold_delay < min_delay)
4791
+ min_delay = pdev->d3cold_delay;
4792
+ if (pdev->d3cold_delay > max_delay)
4793
+ max_delay = pdev->d3cold_delay;
45564794 }
45574795
4558
- pci_info(pdev, "Data Link Layer Link Active not %s in 1000 msec\n",
4559
- active ? "set" : "cleared");
4796
+ return max(min_delay, max_delay);
4797
+}
45604798
4561
- return false;
4799
+/**
4800
+ * pci_bridge_wait_for_secondary_bus - Wait for secondary bus to be accessible
4801
+ * @dev: PCI bridge
4802
+ *
4803
+ * Handle necessary delays before access to the devices on the secondary
4804
+ * side of the bridge are permitted after D3cold to D0 transition.
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
+void pci_bridge_wait_for_secondary_bus(struct pci_dev *dev)
4811
+{
4812
+ struct pci_dev *child;
4813
+ int delay;
4814
+
4815
+ if (pci_dev_is_disconnected(dev))
4816
+ return;
4817
+
4818
+ if (!pci_is_bridge(dev) || !dev->bridge_d3)
4819
+ return;
4820
+
4821
+ down_read(&pci_bus_sem);
4822
+
4823
+ /*
4824
+ * We only deal with devices that are present currently on the bus.
4825
+ * For any hot-added devices the access delay is handled in pciehp
4826
+ * board_added(). In case of ACPI hotplug the firmware is expected
4827
+ * to configure the devices before OS is notified.
4828
+ */
4829
+ if (!dev->subordinate || list_empty(&dev->subordinate->devices)) {
4830
+ up_read(&pci_bus_sem);
4831
+ return;
4832
+ }
4833
+
4834
+ /* Take d3cold_delay requirements into account */
4835
+ delay = pci_bus_max_d3cold_delay(dev->subordinate);
4836
+ if (!delay) {
4837
+ up_read(&pci_bus_sem);
4838
+ return;
4839
+ }
4840
+
4841
+ child = list_first_entry(&dev->subordinate->devices, struct pci_dev,
4842
+ bus_list);
4843
+ up_read(&pci_bus_sem);
4844
+
4845
+ /*
4846
+ * Conventional PCI and PCI-X we need to wait Tpvrh + Trhfa before
4847
+ * accessing the device after reset (that is 1000 ms + 100 ms). In
4848
+ * practice this should not be needed because we don't do power
4849
+ * management for them (see pci_bridge_d3_possible()).
4850
+ */
4851
+ if (!pci_is_pcie(dev)) {
4852
+ pci_dbg(dev, "waiting %d ms for secondary bus\n", 1000 + delay);
4853
+ msleep(1000 + delay);
4854
+ return;
4855
+ }
4856
+
4857
+ /*
4858
+ * For PCIe downstream and root ports that do not support speeds
4859
+ * greater than 5 GT/s need to wait minimum 100 ms. For higher
4860
+ * speeds (gen3) we need to wait first for the data link layer to
4861
+ * become active.
4862
+ *
4863
+ * However, 100 ms is the minimum and the PCIe spec says the
4864
+ * software must allow at least 1s before it can determine that the
4865
+ * device that did not respond is a broken device. There is
4866
+ * evidence that 100 ms is not always enough, for example certain
4867
+ * Titan Ridge xHCI controller does not always respond to
4868
+ * configuration requests if we only wait for 100 ms (see
4869
+ * https://bugzilla.kernel.org/show_bug.cgi?id=203885).
4870
+ *
4871
+ * Therefore we wait for 100 ms and check for the device presence.
4872
+ * If it is still not present give it an additional 100 ms.
4873
+ */
4874
+ if (!pcie_downstream_port(dev))
4875
+ return;
4876
+
4877
+ if (pcie_get_speed_cap(dev) <= PCIE_SPEED_5_0GT) {
4878
+ pci_dbg(dev, "waiting %d ms for downstream link\n", delay);
4879
+ msleep(delay);
4880
+ } else {
4881
+ pci_dbg(dev, "waiting %d ms for downstream link, after activation\n",
4882
+ delay);
4883
+ if (!pcie_wait_for_link_delay(dev, true, delay)) {
4884
+ /* Did not train, no need to wait any further */
4885
+ pci_info(dev, "Data Link Layer Link Active not set in 1000 msec\n");
4886
+ return;
4887
+ }
4888
+ }
4889
+
4890
+ if (!pci_device_is_present(child)) {
4891
+ pci_dbg(child, "waiting additional %d ms to become accessible\n", delay);
4892
+ msleep(delay);
4893
+ }
45624894 }
45634895
45644896 void pci_reset_secondary_bus(struct pci_dev *dev)
....@@ -4630,46 +4962,40 @@
46304962 {
46314963 int rc = -ENOTTY;
46324964
4633
- if (!hotplug || !try_module_get(hotplug->ops->owner))
4965
+ if (!hotplug || !try_module_get(hotplug->owner))
46344966 return rc;
46354967
46364968 if (hotplug->ops->reset_slot)
46374969 rc = hotplug->ops->reset_slot(hotplug, probe);
46384970
4639
- module_put(hotplug->ops->owner);
4971
+ module_put(hotplug->owner);
46404972
46414973 return rc;
46424974 }
46434975
46444976 static int pci_dev_reset_slot_function(struct pci_dev *dev, int probe)
46454977 {
4646
- struct pci_dev *pdev;
4647
-
4648
- if (dev->subordinate || !dev->slot ||
4978
+ if (dev->multifunction || dev->subordinate || !dev->slot ||
46494979 dev->dev_flags & PCI_DEV_FLAGS_NO_BUS_RESET)
46504980 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;
46554981
46564982 return pci_reset_hotplug_slot(dev->slot->hotplug, probe);
46574983 }
46584984
46594985 static void pci_dev_lock(struct pci_dev *dev)
46604986 {
4661
- pci_cfg_access_lock(dev);
46624987 /* block PM suspend, driver probe, etc. */
46634988 device_lock(&dev->dev);
4989
+ pci_cfg_access_lock(dev);
46644990 }
46654991
46664992 /* Return 1 on successful lock, 0 on contention */
46674993 static int pci_dev_trylock(struct pci_dev *dev)
46684994 {
4669
- if (pci_cfg_access_trylock(dev)) {
4670
- if (device_trylock(&dev->dev))
4995
+ if (device_trylock(&dev->dev)) {
4996
+ if (pci_cfg_access_trylock(dev))
46714997 return 1;
4672
- pci_cfg_access_unlock(dev);
4998
+ device_unlock(&dev->dev);
46734999 }
46745000
46755001 return 0;
....@@ -4677,8 +5003,8 @@
46775003
46785004 static void pci_dev_unlock(struct pci_dev *dev)
46795005 {
4680
- device_unlock(&dev->dev);
46815006 pci_cfg_access_unlock(dev);
5007
+ device_unlock(&dev->dev);
46825008 }
46835009
46845010 static void pci_dev_save_and_disable(struct pci_dev *dev)
....@@ -4739,6 +5065,7 @@
47395065 *
47405066 * The device function is presumed to be unused and the caller is holding
47415067 * the device mutex lock when this function is called.
5068
+ *
47425069 * Resetting the device will make the contents of PCI configuration space
47435070 * random, so any caller of this must be prepared to reinitialise the
47445071 * device including MSI, bus mastering, BARs, decoding IO and memory spaces,
....@@ -5302,8 +5629,8 @@
53025629 * pcix_get_max_mmrbc - get PCI-X maximum designed memory read byte count
53035630 * @dev: PCI device to query
53045631 *
5305
- * Returns mmrbc: maximum designed memory read count in bytes
5306
- * or appropriate error value.
5632
+ * Returns mmrbc: maximum designed memory read count in bytes or
5633
+ * appropriate error value.
53075634 */
53085635 int pcix_get_max_mmrbc(struct pci_dev *dev)
53095636 {
....@@ -5325,8 +5652,8 @@
53255652 * pcix_get_mmrbc - get PCI-X maximum memory read byte count
53265653 * @dev: PCI device to query
53275654 *
5328
- * Returns mmrbc: maximum memory read count in bytes
5329
- * or appropriate error value.
5655
+ * Returns mmrbc: maximum memory read count in bytes or appropriate error
5656
+ * value.
53305657 */
53315658 int pcix_get_mmrbc(struct pci_dev *dev)
53325659 {
....@@ -5350,7 +5677,7 @@
53505677 * @mmrbc: maximum memory read count in bytes
53515678 * valid values are 512, 1024, 2048, 4096
53525679 *
5353
- * If possible sets maximum memory read byte count, some bridges have erratas
5680
+ * If possible sets maximum memory read byte count, some bridges have errata
53545681 * that prevent this.
53555682 */
53565683 int pcix_set_mmrbc(struct pci_dev *dev, int mmrbc)
....@@ -5395,8 +5722,7 @@
53955722 * pcie_get_readrq - get PCI Express read request size
53965723 * @dev: PCI device to query
53975724 *
5398
- * Returns maximum memory read request in bytes
5399
- * or appropriate error value.
5725
+ * Returns maximum memory read request in bytes or appropriate error value.
54005726 */
54015727 int pcie_get_readrq(struct pci_dev *dev)
54025728 {
....@@ -5419,15 +5745,15 @@
54195745 int pcie_set_readrq(struct pci_dev *dev, int rq)
54205746 {
54215747 u16 v;
5748
+ int ret;
54225749
54235750 if (rq < 128 || rq > 4096 || !is_power_of_2(rq))
54245751 return -EINVAL;
54255752
54265753 /*
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
5754
+ * If using the "performance" PCIe config, we clamp the read rq
5755
+ * size to the max packet size to keep the host bridge from
5756
+ * generating requests larger than we can cope with.
54315757 */
54325758 if (pcie_bus_config == PCIE_BUS_PERFORMANCE) {
54335759 int mps = pcie_get_mps(dev);
....@@ -5438,8 +5764,10 @@
54385764
54395765 v = (ffs(rq) - 8) << 12;
54405766
5441
- return pcie_capability_clear_and_set_word(dev, PCI_EXP_DEVCTL,
5767
+ ret = pcie_capability_clear_and_set_word(dev, PCI_EXP_DEVCTL,
54425768 PCI_EXP_DEVCTL_READRQ, v);
5769
+
5770
+ return pcibios_err_to_errno(ret);
54435771 }
54445772 EXPORT_SYMBOL(pcie_set_readrq);
54455773
....@@ -5470,6 +5798,7 @@
54705798 int pcie_set_mps(struct pci_dev *dev, int mps)
54715799 {
54725800 u16 v;
5801
+ int ret;
54735802
54745803 if (mps < 128 || mps > 4096 || !is_power_of_2(mps))
54755804 return -EINVAL;
....@@ -5479,8 +5808,10 @@
54795808 return -EINVAL;
54805809 v <<= 5;
54815810
5482
- return pcie_capability_clear_and_set_word(dev, PCI_EXP_DEVCTL,
5811
+ ret = pcie_capability_clear_and_set_word(dev, PCI_EXP_DEVCTL,
54835812 PCI_EXP_DEVCTL_PAYLOAD, v);
5813
+
5814
+ return pcibios_err_to_errno(ret);
54845815 }
54855816 EXPORT_SYMBOL(pcie_set_mps);
54865817
....@@ -5563,17 +5894,10 @@
55635894 * where only 2.5 GT/s and 5.0 GT/s speeds were defined.
55645895 */
55655896 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
- }
5897
+
5898
+ /* PCIe r3.0-compliant */
5899
+ if (lnkcap2)
5900
+ return PCIE_LNKCAP2_SLS2SPEED(lnkcap2);
55775901
55785902 pcie_capability_read_dword(dev, PCI_EXP_LNKCAP, &lnkcap);
55795903 if ((lnkcap & PCI_EXP_LNKCAP_SLS) == PCI_EXP_LNKCAP_SLS_5_0GB)
....@@ -5649,14 +5973,14 @@
56495973 if (bw_avail >= bw_cap && verbose)
56505974 pci_info(dev, "%u.%03u Gb/s available PCIe bandwidth (%s x%d link)\n",
56515975 bw_cap / 1000, bw_cap % 1000,
5652
- PCIE_SPEED2STR(speed_cap), width_cap);
5976
+ pci_speed_string(speed_cap), width_cap);
56535977 else if (bw_avail < bw_cap)
56545978 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",
56555979 bw_avail / 1000, bw_avail % 1000,
5656
- PCIE_SPEED2STR(speed), width,
5980
+ pci_speed_string(speed), width,
56575981 limiting_dev ? pci_name(limiting_dev) : "<unknown>",
56585982 bw_cap / 1000, bw_cap % 1000,
5659
- PCIE_SPEED2STR(speed_cap), width_cap);
5983
+ pci_speed_string(speed_cap), width_cap);
56605984 }
56615985
56625986 /**
....@@ -5730,7 +6054,7 @@
57306054
57316055 if (flags & PCI_VGA_STATE_CHANGE_DECODES) {
57326056 pci_read_config_word(dev, PCI_COMMAND, &cmd);
5733
- if (decode == true)
6057
+ if (decode)
57346058 cmd |= command_bits;
57356059 else
57366060 cmd &= ~command_bits;
....@@ -5746,7 +6070,7 @@
57466070 if (bridge) {
57476071 pci_read_config_word(bridge, PCI_BRIDGE_CONTROL,
57486072 &cmd);
5749
- if (decode == true)
6073
+ if (decode)
57506074 cmd |= PCI_BRIDGE_CTL_VGA;
57516075 else
57526076 cmd &= ~PCI_BRIDGE_CTL_VGA;
....@@ -5758,10 +6082,29 @@
57586082 return 0;
57596083 }
57606084
6085
+#ifdef CONFIG_ACPI
6086
+bool pci_pr3_present(struct pci_dev *pdev)
6087
+{
6088
+ struct acpi_device *adev;
6089
+
6090
+ if (acpi_disabled)
6091
+ return false;
6092
+
6093
+ adev = ACPI_COMPANION(&pdev->dev);
6094
+ if (!adev)
6095
+ return false;
6096
+
6097
+ return adev->power.flags.power_resources &&
6098
+ acpi_has_method(adev->handle, "_PR3");
6099
+}
6100
+EXPORT_SYMBOL_GPL(pci_pr3_present);
6101
+#endif
6102
+
57616103 /**
57626104 * pci_add_dma_alias - Add a DMA devfn alias for a device
57636105 * @dev: the PCI device for which alias is added
5764
- * @devfn: alias slot and function
6106
+ * @devfn_from: alias slot and function
6107
+ * @nr_devfns: number of subsequent devfns to alias
57656108 *
57666109 * This helper encodes an 8-bit devfn as a bit number in dma_alias_mask
57676110 * which is used to program permissible bus-devfn source addresses for DMA
....@@ -5777,19 +6120,29 @@
57776120 * cannot be left as a userspace activity). DMA aliases should therefore
57786121 * be configured via quirks, such as the PCI fixup header quirk.
57796122 */
5780
-void pci_add_dma_alias(struct pci_dev *dev, u8 devfn)
6123
+void pci_add_dma_alias(struct pci_dev *dev, u8 devfn_from, unsigned nr_devfns)
57816124 {
6125
+ int devfn_to;
6126
+
6127
+ nr_devfns = min(nr_devfns, (unsigned) MAX_NR_DEVFNS - devfn_from);
6128
+ devfn_to = devfn_from + nr_devfns - 1;
6129
+
57826130 if (!dev->dma_alias_mask)
5783
- dev->dma_alias_mask = kcalloc(BITS_TO_LONGS(U8_MAX),
5784
- sizeof(long), GFP_KERNEL);
6131
+ dev->dma_alias_mask = bitmap_zalloc(MAX_NR_DEVFNS, GFP_KERNEL);
57856132 if (!dev->dma_alias_mask) {
57866133 pci_warn(dev, "Unable to allocate DMA alias mask\n");
57876134 return;
57886135 }
57896136
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));
6137
+ bitmap_set(dev->dma_alias_mask, devfn_from, nr_devfns);
6138
+
6139
+ if (nr_devfns == 1)
6140
+ pci_info(dev, "Enabling fixed DMA alias to %02x.%d\n",
6141
+ PCI_SLOT(devfn_from), PCI_FUNC(devfn_from));
6142
+ else if (nr_devfns > 1)
6143
+ pci_info(dev, "Enabling fixed DMA alias for devfn range from %02x.%d to %02x.%d\n",
6144
+ PCI_SLOT(devfn_from), PCI_FUNC(devfn_from),
6145
+ PCI_SLOT(devfn_to), PCI_FUNC(devfn_to));
57936146 }
57946147
57956148 bool pci_devs_are_dma_aliases(struct pci_dev *dev1, struct pci_dev *dev2)
....@@ -5797,7 +6150,9 @@
57976150 return (dev1->dma_alias_mask &&
57986151 test_bit(dev2->devfn, dev1->dma_alias_mask)) ||
57996152 (dev2->dma_alias_mask &&
5800
- test_bit(dev1->devfn, dev2->dma_alias_mask));
6153
+ test_bit(dev1->devfn, dev2->dma_alias_mask)) ||
6154
+ pci_real_dma_dev(dev1) == dev2 ||
6155
+ pci_real_dma_dev(dev2) == dev1;
58016156 }
58026157
58036158 bool pci_device_is_present(struct pci_dev *pdev)
....@@ -5821,13 +6176,39 @@
58216176 }
58226177 EXPORT_SYMBOL_GPL(pci_ignore_hotplug);
58236178
6179
+/**
6180
+ * pci_real_dma_dev - Get PCI DMA device for PCI device
6181
+ * @dev: the PCI device that may have a PCI DMA alias
6182
+ *
6183
+ * Permits the platform to provide architecture-specific functionality to
6184
+ * devices needing to alias DMA to another PCI device on another PCI bus. If
6185
+ * the PCI device is on the same bus, it is recommended to use
6186
+ * pci_add_dma_alias(). This is the default implementation. Architecture
6187
+ * implementations can override this.
6188
+ */
6189
+struct pci_dev __weak *pci_real_dma_dev(struct pci_dev *dev)
6190
+{
6191
+ return dev;
6192
+}
6193
+
58246194 resource_size_t __weak pcibios_default_alignment(void)
58256195 {
58266196 return 0;
58276197 }
58286198
5829
-#define RESOURCE_ALIGNMENT_PARAM_SIZE COMMAND_LINE_SIZE
5830
-static char resource_alignment_param[RESOURCE_ALIGNMENT_PARAM_SIZE] = {0};
6199
+/*
6200
+ * Arches that don't want to expose struct resource to userland as-is in
6201
+ * sysfs and /proc can implement their own pci_resource_to_user().
6202
+ */
6203
+void __weak pci_resource_to_user(const struct pci_dev *dev, int bar,
6204
+ const struct resource *rsrc,
6205
+ resource_size_t *start, resource_size_t *end)
6206
+{
6207
+ *start = rsrc->start;
6208
+ *end = rsrc->end;
6209
+}
6210
+
6211
+static char *resource_alignment_param;
58316212 static DEFINE_SPINLOCK(resource_alignment_lock);
58326213
58336214 /**
....@@ -5848,7 +6229,7 @@
58486229
58496230 spin_lock(&resource_alignment_lock);
58506231 p = resource_alignment_param;
5851
- if (!*p && !align)
6232
+ if (!p || !*p)
58526233 goto out;
58536234 if (pci_has_flag(PCI_PROBE_ONLY)) {
58546235 align = 0;
....@@ -6001,8 +6382,7 @@
60016382 * to enable the kernel to reassign new resource
60026383 * window later on.
60036384 */
6004
- if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE &&
6005
- (dev->class >> 8) == PCI_CLASS_BRIDGE_PCI) {
6385
+ if (dev->hdr_type == PCI_HEADER_TYPE_BRIDGE) {
60066386 for (i = PCI_BRIDGE_RESOURCES; i < PCI_NUM_RESOURCES; i++) {
60076387 r = &dev->resource[i];
60086388 if (!(r->flags & IORESOURCE_MEM))
....@@ -6015,39 +6395,44 @@
60156395 }
60166396 }
60176397
6018
-static ssize_t pci_set_resource_alignment_param(const char *buf, size_t count)
6398
+static ssize_t resource_alignment_show(struct bus_type *bus, char *buf)
60196399 {
6020
- if (count > RESOURCE_ALIGNMENT_PARAM_SIZE - 1)
6021
- count = RESOURCE_ALIGNMENT_PARAM_SIZE - 1;
6400
+ size_t count = 0;
6401
+
60226402 spin_lock(&resource_alignment_lock);
6023
- strncpy(resource_alignment_param, buf, count);
6024
- resource_alignment_param[count] = '\0';
6403
+ if (resource_alignment_param)
6404
+ count = scnprintf(buf, PAGE_SIZE, "%s", resource_alignment_param);
60256405 spin_unlock(&resource_alignment_lock);
6406
+
6407
+ /*
6408
+ * When set by the command line, resource_alignment_param will not
6409
+ * have a trailing line feed, which is ugly. So conditionally add
6410
+ * it here.
6411
+ */
6412
+ if (count >= 2 && buf[count - 2] != '\n' && count < PAGE_SIZE - 1) {
6413
+ buf[count - 1] = '\n';
6414
+ buf[count++] = 0;
6415
+ }
6416
+
60266417 return count;
60276418 }
60286419
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,
6420
+static ssize_t resource_alignment_store(struct bus_type *bus,
60446421 const char *buf, size_t count)
60456422 {
6046
- return pci_set_resource_alignment_param(buf, count);
6423
+ char *param = kstrndup(buf, count, GFP_KERNEL);
6424
+
6425
+ if (!param)
6426
+ return -ENOMEM;
6427
+
6428
+ spin_lock(&resource_alignment_lock);
6429
+ kfree(resource_alignment_param);
6430
+ resource_alignment_param = param;
6431
+ spin_unlock(&resource_alignment_lock);
6432
+ return count;
60476433 }
60486434
6049
-static BUS_ATTR(resource_alignment, 0644, pci_resource_alignment_show,
6050
- pci_resource_alignment_store);
6435
+static BUS_ATTR_RW(resource_alignment);
60516436
60526437 static int __init pci_resource_alignment_sysfs_init(void)
60536438 {
....@@ -6078,6 +6463,7 @@
60786463
60796464 if (parent)
60806465 domain = of_get_pci_domain_nr(parent->of_node);
6466
+
60816467 /*
60826468 * Check DT domain and use_dt_domains values.
60836469 *
....@@ -6172,14 +6558,18 @@
61726558 } else if (!strncmp(str, "cbmemsize=", 10)) {
61736559 pci_cardbus_mem_size = memparse(str + 10, &str);
61746560 } else if (!strncmp(str, "resource_alignment=", 19)) {
6175
- pci_set_resource_alignment_param(str + 19,
6176
- strlen(str + 19));
6561
+ resource_alignment_param = str + 19;
61776562 } else if (!strncmp(str, "ecrc=", 5)) {
61786563 pcie_ecrc_get_policy(str + 5);
61796564 } else if (!strncmp(str, "hpiosize=", 9)) {
61806565 pci_hotplug_io_size = memparse(str + 9, &str);
6566
+ } else if (!strncmp(str, "hpmmiosize=", 11)) {
6567
+ pci_hotplug_mmio_size = memparse(str + 11, &str);
6568
+ } else if (!strncmp(str, "hpmmioprefsize=", 15)) {
6569
+ pci_hotplug_mmio_pref_size = memparse(str + 15, &str);
61816570 } else if (!strncmp(str, "hpmemsize=", 10)) {
6182
- pci_hotplug_mem_size = memparse(str + 10, &str);
6571
+ pci_hotplug_mmio_size = memparse(str + 10, &str);
6572
+ pci_hotplug_mmio_pref_size = pci_hotplug_mmio_size;
61836573 } else if (!strncmp(str, "hpbussize=", 10)) {
61846574 pci_hotplug_bus_size =
61856575 simple_strtoul(str + 10, &str, 0);
....@@ -6198,8 +6588,7 @@
61986588 } else if (!strncmp(str, "disable_acs_redir=", 18)) {
61996589 disable_acs_redir_param = str + 18;
62006590 } else {
6201
- printk(KERN_ERR "PCI: Unknown option `%s'\n",
6202
- str);
6591
+ pr_err("PCI: Unknown option `%s'\n", str);
62036592 }
62046593 }
62056594 str = k;
....@@ -6209,15 +6598,18 @@
62096598 early_param("pci", pci_setup);
62106599
62116600 /*
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.
6601
+ * 'resource_alignment_param' and 'disable_acs_redir_param' are initialized
6602
+ * in pci_setup(), above, to point to data in the __initdata section which
6603
+ * will be freed after the init sequence is complete. We can't allocate memory
6604
+ * in pci_setup() because some architectures do not have any memory allocation
6605
+ * service available during an early_param() call. So we allocate memory and
6606
+ * copy the variable here before the init section is freed.
6607
+ *
62186608 */
62196609 static int __init pci_realloc_setup_params(void)
62206610 {
6611
+ resource_alignment_param = kstrdup(resource_alignment_param,
6612
+ GFP_KERNEL);
62216613 disable_acs_redir_param = kstrdup(disable_acs_redir_param, GFP_KERNEL);
62226614
62236615 return 0;