]>
Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
557848c3 ZY |
2 | #ifndef DRIVERS_PCI_H |
3 | #define DRIVERS_PCI_H | |
4 | ||
2209e06f AG |
5 | #include <linux/pci.h> |
6 | ||
01352558 IJ |
7 | struct pcie_tlp_log; |
8 | ||
f8bf2aeb JS |
9 | /* Number of possible devfns: 0.0 to 1f.7 inclusive */ |
10 | #define MAX_NR_DEVFNS 256 | |
11 | ||
fff905f3 WY |
12 | #define PCI_FIND_CAP_TTL 48 |
13 | ||
8531e283 LW |
14 | #define PCI_VSEC_ID_INTEL_TBT 0x1234 /* Thunderbolt */ |
15 | ||
33a176ab MR |
16 | #define PCIE_LINK_RETRAIN_TIMEOUT_MS 1000 |
17 | ||
6aa9c09f TR |
18 | /* |
19 | * Power stable to PERST# inactive. | |
20 | * | |
21 | * See the "Power Sequencing and Reset Signal Timings" table of the PCI Express | |
22 | * Card Electromechanical Specification, Revision 5.1, Section 2.9.2, Symbol | |
23 | * "T_PVPERL". | |
24 | */ | |
164f66be YS |
25 | #define PCIE_T_PVPERL_MS 100 |
26 | ||
6aa9c09f TR |
27 | /* |
28 | * REFCLK stable before PERST# inactive. | |
29 | * | |
30 | * See the "Power Sequencing and Reset Signal Timings" table of the PCI Express | |
31 | * Card Electromechanical Specification, Revision 5.1, Section 2.9.2, Symbol | |
32 | * "T_PERST-CLK". | |
33 | */ | |
34 | #define PCIE_T_PERST_CLK_US 100 | |
35 | ||
70a7bfb1 DLM |
36 | /* |
37 | * End of conventional reset (PERST# de-asserted) to first configuration | |
38 | * request (device able to respond with a "Request Retry Status" completion), | |
39 | * from PCIe r6.0, sec 6.6.1. | |
40 | */ | |
41 | #define PCIE_T_RRS_READY_MS 100 | |
42 | ||
e78bd50b FL |
43 | /* |
44 | * PCIe r6.0, sec 5.3.3.2.1 <PME Synchronization> | |
45 | * Recommends 1ms to 10ms timeout to check L2 ready. | |
46 | */ | |
47 | #define PCIE_PME_TO_L2_TIMEOUT_US 10000 | |
48 | ||
d5ceb949 KX |
49 | /* |
50 | * PCIe r6.0, sec 6.6.1 <Conventional Reset> | |
51 | * | |
52 | * - "With a Downstream Port that does not support Link speeds greater | |
53 | * than 5.0 GT/s, software must wait a minimum of 100 ms following exit | |
54 | * from a Conventional Reset before sending a Configuration Request to | |
55 | * the device immediately below that Port." | |
56 | * | |
57 | * - "With a Downstream Port that supports Link speeds greater than | |
58 | * 5.0 GT/s, software must wait a minimum of 100 ms after Link training | |
59 | * completes before sending a Configuration Request to the device | |
60 | * immediately below that Port." | |
61 | */ | |
62 | #define PCIE_RESET_CONFIG_DEVICE_WAIT_MS 100 | |
63 | ||
95cb8ff6 YS |
64 | /* Message Routing (r[2:0]); PCIe r6.0, sec 2.2.8 */ |
65 | #define PCIE_MSG_TYPE_R_RC 0 | |
66 | #define PCIE_MSG_TYPE_R_ADDR 1 | |
67 | #define PCIE_MSG_TYPE_R_ID 2 | |
68 | #define PCIE_MSG_TYPE_R_BC 3 | |
69 | #define PCIE_MSG_TYPE_R_LOCAL 4 | |
70 | #define PCIE_MSG_TYPE_R_GATHER 5 | |
71 | ||
9972b177 FL |
72 | /* Power Management Messages; PCIe r6.0, sec 2.2.8.2 */ |
73 | #define PCIE_MSG_CODE_PME_TURN_OFF 0x19 | |
74 | ||
95cb8ff6 YS |
75 | /* INTx Mechanism Messages; PCIe r6.0, sec 2.2.8.1 */ |
76 | #define PCIE_MSG_CODE_ASSERT_INTA 0x20 | |
77 | #define PCIE_MSG_CODE_ASSERT_INTB 0x21 | |
78 | #define PCIE_MSG_CODE_ASSERT_INTC 0x22 | |
79 | #define PCIE_MSG_CODE_ASSERT_INTD 0x23 | |
80 | #define PCIE_MSG_CODE_DEASSERT_INTA 0x24 | |
81 | #define PCIE_MSG_CODE_DEASSERT_INTB 0x25 | |
82 | #define PCIE_MSG_CODE_DEASSERT_INTC 0x26 | |
83 | #define PCIE_MSG_CODE_DEASSERT_INTD 0x27 | |
84 | ||
343e51ae | 85 | extern const unsigned char pcie_link_speed[]; |
11eb0e0e | 86 | extern bool pci_early_dump; |
343e51ae | 87 | |
7a1562d4 | 88 | bool pcie_cap_has_lnkctl(const struct pci_dev *dev); |
503fa236 | 89 | bool pcie_cap_has_lnkctl2(const struct pci_dev *dev); |
af65d1ad | 90 | bool pcie_cap_has_rtctl(const struct pci_dev *dev); |
7a1562d4 | 91 | |
1da177e4 LT |
92 | /* Functions internal to the PCI core code */ |
93 | ||
506140f9 KW |
94 | #ifdef CONFIG_DMI |
95 | extern const struct attribute_group pci_dev_smbios_attr_group; | |
96 | #endif | |
f7195824 | 97 | |
3b519e4e MW |
98 | enum pci_mmap_api { |
99 | PCI_MMAP_SYSFS, /* mmap on /sys/bus/pci/devices/<BDF>/resource<N> */ | |
100 | PCI_MMAP_PROCFS /* mmap on /proc/bus/pci/<BDF> */ | |
101 | }; | |
f39d5b72 BH |
102 | int pci_mmap_fits(struct pci_dev *pdev, int resno, struct vm_area_struct *vmai, |
103 | enum pci_mmap_api mmap_api); | |
f7195824 | 104 | |
e20afa06 AN |
105 | bool pci_reset_supported(struct pci_dev *dev); |
106 | void pci_init_reset_methods(struct pci_dev *dev); | |
381634ca | 107 | int pci_bridge_secondary_bus_reset(struct pci_dev *dev); |
c4eed62a | 108 | int pci_bus_error_reset(struct pci_dev *dev); |
2fa04644 | 109 | int __pci_reset_bus(struct pci_bus *bus); |
ce5ccdef | 110 | |
f0ab0017 BH |
111 | struct pci_cap_saved_data { |
112 | u16 cap_nr; | |
113 | bool cap_extended; | |
114 | unsigned int size; | |
115 | u32 data[]; | |
116 | }; | |
117 | ||
118 | struct pci_cap_saved_state { | |
119 | struct hlist_node next; | |
120 | struct pci_cap_saved_data cap; | |
121 | }; | |
122 | ||
123 | void pci_allocate_cap_save_buffers(struct pci_dev *dev); | |
124 | void pci_free_cap_save_buffers(struct pci_dev *dev); | |
125 | int pci_add_cap_save_buffer(struct pci_dev *dev, char cap, unsigned int size); | |
126 | int pci_add_ext_cap_save_buffer(struct pci_dev *dev, | |
127 | u16 cap, unsigned int size); | |
128 | struct pci_cap_saved_state *pci_find_saved_cap(struct pci_dev *dev, char cap); | |
129 | struct pci_cap_saved_state *pci_find_saved_ext_cap(struct pci_dev *dev, | |
130 | u16 cap); | |
131 | ||
638c133e BH |
132 | #define PCI_PM_D2_DELAY 200 /* usec; see PCIe r4.0, sec 5.9.1 */ |
133 | #define PCI_PM_D3HOT_WAIT 10 /* msec */ | |
134 | #define PCI_PM_D3COLD_WAIT 100 /* msec */ | |
c776dd50 | 135 | |
f39d5b72 | 136 | void pci_update_current_state(struct pci_dev *dev, pci_power_t state); |
b51033e0 | 137 | void pci_refresh_power_state(struct pci_dev *dev); |
adfac8f6 | 138 | int pci_power_up(struct pci_dev *dev); |
f39d5b72 BH |
139 | void pci_disable_enabled_device(struct pci_dev *dev); |
140 | int pci_finish_runtime_suspend(struct pci_dev *dev); | |
600a5b4f | 141 | void pcie_clear_device_status(struct pci_dev *dev); |
dcb0453d | 142 | void pcie_clear_root_pme_status(struct pci_dev *dev); |
669696eb KS |
143 | bool pci_check_pme_status(struct pci_dev *dev); |
144 | void pci_pme_wakeup_bus(struct pci_bus *bus); | |
0ce3fcaf | 145 | void pci_pme_restore(struct pci_dev *dev); |
0c7376ad RW |
146 | bool pci_dev_need_resume(struct pci_dev *dev); |
147 | void pci_dev_adjust_pme(struct pci_dev *dev); | |
2cef548a | 148 | void pci_dev_complete_resume(struct pci_dev *pci_dev); |
f39d5b72 BH |
149 | void pci_config_pm_runtime_get(struct pci_dev *dev); |
150 | void pci_config_pm_runtime_put(struct pci_dev *dev); | |
151 | void pci_pm_init(struct pci_dev *dev); | |
938174e5 | 152 | void pci_ea_init(struct pci_dev *dev); |
cbc40d5c BH |
153 | void pci_msi_init(struct pci_dev *dev); |
154 | void pci_msix_init(struct pci_dev *dev); | |
c6a63307 | 155 | bool pci_bridge_d3_possible(struct pci_dev *dev); |
1ed276a7 | 156 | void pci_bridge_d3_update(struct pci_dev *dev); |
e74b2b58 | 157 | int pci_bridge_wait_for_secondary_bus(struct pci_dev *dev, char *reset_type); |
aa8c6c93 | 158 | |
87f10faf | 159 | static inline bool pci_bus_rrs_vendor_id(u32 l) |
d591f680 BH |
160 | { |
161 | return (l & 0xffff) == PCI_VENDOR_ID_PCI_SIG; | |
162 | } | |
163 | ||
b6e335ae RW |
164 | static inline void pci_wakeup_event(struct pci_dev *dev) |
165 | { | |
166 | /* Wait 100 ms before the system can be put into a sleep state. */ | |
167 | pm_wakeup_event(&dev->dev, 100); | |
168 | } | |
169 | ||
326c1cda | 170 | static inline bool pci_has_subordinate(struct pci_dev *pci_dev) |
aa8c6c93 RW |
171 | { |
172 | return !!(pci_dev->subordinate); | |
173 | } | |
0f64474b | 174 | |
9d26d3a8 MW |
175 | static inline bool pci_power_manageable(struct pci_dev *pci_dev) |
176 | { | |
177 | /* | |
178 | * Currently we allow normal PCI devices and PCI bridges transition | |
179 | * into D3 if their bridge_d3 is set. | |
180 | */ | |
181 | return !pci_has_subordinate(pci_dev) || pci_dev->bridge_d3; | |
182 | } | |
183 | ||
984998e3 MW |
184 | static inline bool pcie_downstream_port(const struct pci_dev *dev) |
185 | { | |
186 | int type = pci_pcie_type(dev); | |
187 | ||
188 | return type == PCI_EXP_TYPE_ROOT_PORT || | |
189 | type == PCI_EXP_TYPE_DOWNSTREAM || | |
190 | type == PCI_EXP_TYPE_PCIE_BRIDGE; | |
191 | } | |
192 | ||
e947e7b1 | 193 | void pci_vpd_init(struct pci_dev *dev); |
d93f8399 | 194 | extern const struct attribute_group pci_dev_vpd_attr_group; |
94e61088 | 195 | |
440589dd KS |
196 | /* PCI Virtual Channel */ |
197 | int pci_save_vc_state(struct pci_dev *dev); | |
198 | void pci_restore_vc_state(struct pci_dev *dev); | |
199 | void pci_allocate_vc_save_buffers(struct pci_dev *dev); | |
200 | ||
1da177e4 LT |
201 | /* PCI /proc functions */ |
202 | #ifdef CONFIG_PROC_FS | |
f39d5b72 BH |
203 | int pci_proc_attach_device(struct pci_dev *dev); |
204 | int pci_proc_detach_device(struct pci_dev *dev); | |
205 | int pci_proc_detach_bus(struct pci_bus *bus); | |
1da177e4 LT |
206 | #else |
207 | static inline int pci_proc_attach_device(struct pci_dev *dev) { return 0; } | |
208 | static inline int pci_proc_detach_device(struct pci_dev *dev) { return 0; } | |
1da177e4 LT |
209 | static inline int pci_proc_detach_bus(struct pci_bus *bus) { return 0; } |
210 | #endif | |
211 | ||
212 | /* Functions for PCI Hotplug drivers to use */ | |
a8e4b9c1 | 213 | int pci_hp_add_bridge(struct pci_dev *dev); |
1da177e4 | 214 | |
be9c3a4c | 215 | #if defined(CONFIG_SYSFS) && defined(HAVE_PCI_LEGACY) |
f39d5b72 BH |
216 | void pci_create_legacy_files(struct pci_bus *bus); |
217 | void pci_remove_legacy_files(struct pci_bus *bus); | |
f19aeb1f | 218 | #else |
eb6723b4 BH |
219 | static inline void pci_create_legacy_files(struct pci_bus *bus) { } |
220 | static inline void pci_remove_legacy_files(struct pci_bus *bus) { } | |
f19aeb1f | 221 | #endif |
1da177e4 LT |
222 | |
223 | /* Lock for read/write access to pci device and bus lists */ | |
d71374da | 224 | extern struct rw_semaphore pci_bus_sem; |
c4eed62a | 225 | extern struct mutex pci_slot_mutex; |
1da177e4 | 226 | |
a2e27787 JK |
227 | extern raw_spinlock_t pci_lock; |
228 | ||
3789af9a | 229 | extern unsigned int pci_pm_d3hot_delay; |
88187dfa | 230 | |
4b47b0ee | 231 | #ifdef CONFIG_PCI_MSI |
309e57df | 232 | void pci_no_msi(void); |
4b47b0ee | 233 | #else |
309e57df | 234 | static inline void pci_no_msi(void) { } |
4b47b0ee | 235 | #endif |
8fed4b65 | 236 | |
b55438fd | 237 | void pci_realloc_get_opt(char *); |
f483d392 | 238 | |
ffadcc2f KCA |
239 | static inline int pci_no_d1d2(struct pci_dev *dev) |
240 | { | |
241 | unsigned int parent_dstates = 0; | |
4b47b0ee | 242 | |
ffadcc2f KCA |
243 | if (dev->bus->self) |
244 | parent_dstates = dev->bus->self->no_d1d2; | |
245 | return (dev->no_d1d2 || parent_dstates); | |
246 | ||
247 | } | |
be9c3a4c LW |
248 | |
249 | #ifdef CONFIG_SYSFS | |
250 | int pci_create_sysfs_dev_files(struct pci_dev *pdev); | |
251 | void pci_remove_sysfs_dev_files(struct pci_dev *pdev); | |
5136b2da | 252 | extern const struct attribute_group *pci_dev_groups[]; |
be9c3a4c | 253 | extern const struct attribute_group *pci_dev_attr_groups[]; |
56039e65 | 254 | extern const struct attribute_group *pcibus_groups[]; |
0f49ba55 | 255 | extern const struct attribute_group *pci_bus_groups[]; |
be9c3a4c LW |
256 | #else |
257 | static inline int pci_create_sysfs_dev_files(struct pci_dev *pdev) { return 0; } | |
258 | static inline void pci_remove_sysfs_dev_files(struct pci_dev *pdev) { } | |
259 | #define pci_dev_groups NULL | |
260 | #define pci_dev_attr_groups NULL | |
261 | #define pcibus_groups NULL | |
262 | #define pci_bus_groups NULL | |
263 | #endif | |
705b1aaa | 264 | |
003d3b2c | 265 | extern unsigned long pci_hotplug_io_size; |
d7b8a217 NJ |
266 | extern unsigned long pci_hotplug_mmio_size; |
267 | extern unsigned long pci_hotplug_mmio_pref_size; | |
003d3b2c | 268 | extern unsigned long pci_hotplug_bus_size; |
1da177e4 LT |
269 | |
270 | /** | |
271 | * pci_match_one_device - Tell if a PCI device structure has a matching | |
0aa0f5d1 | 272 | * PCI device id structure |
1da177e4 LT |
273 | * @id: single PCI device id structure to match |
274 | * @dev: the PCI device structure to match against | |
367b09fe | 275 | * |
1da177e4 LT |
276 | * Returns the matching pci_device_id structure or %NULL if there is no match. |
277 | */ | |
278 | static inline const struct pci_device_id * | |
279 | pci_match_one_device(const struct pci_device_id *id, const struct pci_dev *dev) | |
280 | { | |
281 | if ((id->vendor == PCI_ANY_ID || id->vendor == dev->vendor) && | |
282 | (id->device == PCI_ANY_ID || id->device == dev->device) && | |
283 | (id->subvendor == PCI_ANY_ID || id->subvendor == dev->subsystem_vendor) && | |
284 | (id->subdevice == PCI_ANY_ID || id->subdevice == dev->subsystem_device) && | |
285 | !((id->class ^ dev->class) & id->class_mask)) | |
286 | return id; | |
287 | return NULL; | |
288 | } | |
289 | ||
f46753c5 AC |
290 | /* PCI slot sysfs helper code */ |
291 | #define to_pci_slot(s) container_of(s, struct pci_slot, kobj) | |
292 | ||
293 | extern struct kset *pci_slots_kset; | |
294 | ||
295 | struct pci_slot_attribute { | |
296 | struct attribute attr; | |
297 | ssize_t (*show)(struct pci_slot *, char *); | |
298 | ssize_t (*store)(struct pci_slot *, const char *, size_t); | |
299 | }; | |
300 | #define to_pci_slot_attr(s) container_of(s, struct pci_slot_attribute, attr) | |
301 | ||
0b400c7e YZ |
302 | enum pci_bar_type { |
303 | pci_bar_unknown, /* Standard PCI BAR probe */ | |
0aa0f5d1 | 304 | pci_bar_io, /* An I/O port BAR */ |
0b400c7e YZ |
305 | pci_bar_mem32, /* A 32-bit memory BAR */ |
306 | pci_bar_mem64, /* A 64-bit memory BAR */ | |
307 | }; | |
308 | ||
975e1ac1 KS |
309 | struct device *pci_get_host_bridge_device(struct pci_dev *dev); |
310 | void pci_put_host_bridge_device(struct device *dev); | |
311 | ||
62ce94a7 | 312 | int pci_configure_extended_tags(struct pci_dev *dev, void *ign); |
efdc87da | 313 | bool pci_bus_read_dev_vendor_id(struct pci_bus *bus, int devfn, u32 *pl, |
87f10faf | 314 | int rrs_timeout); |
aa667c64 | 315 | bool pci_bus_generic_read_dev_vendor_id(struct pci_bus *bus, int devfn, u32 *pl, |
87f10faf BH |
316 | int rrs_timeout); |
317 | int pci_idt_bus_quirk(struct pci_bus *bus, int devfn, u32 *pl, int rrs_timeout); | |
aa667c64 | 318 | |
f39d5b72 BH |
319 | int pci_setup_device(struct pci_dev *dev); |
320 | int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type, | |
321 | struct resource *res, unsigned int reg); | |
f39d5b72 | 322 | void pci_configure_ari(struct pci_dev *dev); |
10874f5a | 323 | void __pci_bus_size_bridges(struct pci_bus *bus, |
d66ecb72 | 324 | struct list_head *realloc_head); |
10874f5a BH |
325 | void __pci_bus_assign_resources(const struct pci_bus *bus, |
326 | struct list_head *realloc_head, | |
327 | struct list_head *fail_head); | |
0f7e7aee | 328 | bool pci_bus_clip_resource(struct pci_dev *dev, int idx); |
38a18dfe KB |
329 | void pci_walk_bus_locked(struct pci_bus *top, |
330 | int (*cb)(struct pci_dev *, void *), | |
331 | void *userdata); | |
939de1d6 | 332 | |
65f8e0be PM |
333 | const char *pci_resource_name(struct pci_dev *dev, unsigned int i); |
334 | ||
2069ecfb | 335 | void pci_reassigndev_resource_alignment(struct pci_dev *dev); |
f39d5b72 | 336 | void pci_disable_bridge_window(struct pci_dev *dev); |
ecd29c1a KS |
337 | struct pci_bus *pci_bus_get(struct pci_bus *bus); |
338 | void pci_bus_put(struct pci_bus *bus); | |
32a9a682 | 339 | |
de9a6c8d IJ |
340 | #define PCIE_LNKCAP_SLS2SPEED(lnkcap) \ |
341 | ({ \ | |
342 | ((lnkcap) == PCI_EXP_LNKCAP_SLS_64_0GB ? PCIE_SPEED_64_0GT : \ | |
343 | (lnkcap) == PCI_EXP_LNKCAP_SLS_32_0GB ? PCIE_SPEED_32_0GT : \ | |
344 | (lnkcap) == PCI_EXP_LNKCAP_SLS_16_0GB ? PCIE_SPEED_16_0GT : \ | |
345 | (lnkcap) == PCI_EXP_LNKCAP_SLS_8_0GB ? PCIE_SPEED_8_0GT : \ | |
346 | (lnkcap) == PCI_EXP_LNKCAP_SLS_5_0GB ? PCIE_SPEED_5_0GT : \ | |
347 | (lnkcap) == PCI_EXP_LNKCAP_SLS_2_5GB ? PCIE_SPEED_2_5GT : \ | |
348 | PCI_SPEED_UNKNOWN); \ | |
349 | }) | |
350 | ||
757bfaa2 YY |
351 | /* PCIe link information from Link Capabilities 2 */ |
352 | #define PCIE_LNKCAP2_SLS2SPEED(lnkcap2) \ | |
34191749 GP |
353 | ((lnkcap2) & PCI_EXP_LNKCAP2_SLS_64_0GB ? PCIE_SPEED_64_0GT : \ |
354 | (lnkcap2) & PCI_EXP_LNKCAP2_SLS_32_0GB ? PCIE_SPEED_32_0GT : \ | |
757bfaa2 YY |
355 | (lnkcap2) & PCI_EXP_LNKCAP2_SLS_16_0GB ? PCIE_SPEED_16_0GT : \ |
356 | (lnkcap2) & PCI_EXP_LNKCAP2_SLS_8_0GB ? PCIE_SPEED_8_0GT : \ | |
357 | (lnkcap2) & PCI_EXP_LNKCAP2_SLS_5_0GB ? PCIE_SPEED_5_0GT : \ | |
358 | (lnkcap2) & PCI_EXP_LNKCAP2_SLS_2_5GB ? PCIE_SPEED_2_5GT : \ | |
359 | PCI_SPEED_UNKNOWN) | |
6cf57be0 | 360 | |
de9a6c8d IJ |
361 | #define PCIE_LNKCTL2_TLS2SPEED(lnkctl2) \ |
362 | ((lnkctl2) == PCI_EXP_LNKCTL2_TLS_64_0GT ? PCIE_SPEED_64_0GT : \ | |
363 | (lnkctl2) == PCI_EXP_LNKCTL2_TLS_32_0GT ? PCIE_SPEED_32_0GT : \ | |
364 | (lnkctl2) == PCI_EXP_LNKCTL2_TLS_16_0GT ? PCIE_SPEED_16_0GT : \ | |
365 | (lnkctl2) == PCI_EXP_LNKCTL2_TLS_8_0GT ? PCIE_SPEED_8_0GT : \ | |
366 | (lnkctl2) == PCI_EXP_LNKCTL2_TLS_5_0GT ? PCIE_SPEED_5_0GT : \ | |
367 | (lnkctl2) == PCI_EXP_LNKCTL2_TLS_2_5GT ? PCIE_SPEED_2_5GT : \ | |
368 | PCI_SPEED_UNKNOWN) | |
369 | ||
b852f63a TG |
370 | /* PCIe speed to Mb/s reduced by encoding overhead */ |
371 | #define PCIE_SPEED2MBS_ENC(speed) \ | |
ac4f1897 | 372 | ((speed) == PCIE_SPEED_64_0GT ? 64000*1/1 : \ |
34191749 | 373 | (speed) == PCIE_SPEED_32_0GT ? 32000*128/130 : \ |
9cb3985a | 374 | (speed) == PCIE_SPEED_16_0GT ? 16000*128/130 : \ |
b852f63a TG |
375 | (speed) == PCIE_SPEED_8_0GT ? 8000*128/130 : \ |
376 | (speed) == PCIE_SPEED_5_0GT ? 5000*8/10 : \ | |
377 | (speed) == PCIE_SPEED_2_5GT ? 2500*8/10 : \ | |
378 | 0) | |
379 | ||
100ae5d7 K |
380 | static inline int pcie_dev_speed_mbps(enum pci_bus_speed speed) |
381 | { | |
382 | switch (speed) { | |
383 | case PCIE_SPEED_2_5GT: | |
384 | return 2500; | |
385 | case PCIE_SPEED_5_0GT: | |
386 | return 5000; | |
387 | case PCIE_SPEED_8_0GT: | |
388 | return 8000; | |
389 | case PCIE_SPEED_16_0GT: | |
390 | return 16000; | |
391 | case PCIE_SPEED_32_0GT: | |
392 | return 32000; | |
393 | case PCIE_SPEED_64_0GT: | |
394 | return 64000; | |
395 | default: | |
396 | break; | |
397 | } | |
398 | ||
399 | return -EINVAL; | |
400 | } | |
401 | ||
d2bd39c0 | 402 | u8 pcie_get_supported_speeds(struct pci_dev *dev); |
e56faff5 | 403 | const char *pci_speed_string(enum pci_bus_speed speed); |
2d1ce5ec | 404 | void __pcie_print_link_status(struct pci_dev *dev, bool verbose); |
0fa635ae | 405 | void pcie_report_downtraining(struct pci_dev *dev); |
e93d9fcf IJ |
406 | |
407 | static inline void __pcie_update_link_speed(struct pci_bus *bus, u16 linksta) | |
408 | { | |
409 | bus->cur_bus_speed = pcie_link_speed[linksta & PCI_EXP_LNKSTA_CLS]; | |
410 | } | |
411 | void pcie_update_link_speed(struct pci_bus *bus); | |
6cf57be0 | 412 | |
d1b054da YZ |
413 | /* Single Root I/O Virtualization */ |
414 | struct pci_sriov { | |
0aa0f5d1 BH |
415 | int pos; /* Capability position */ |
416 | int nres; /* Number of resources */ | |
417 | u32 cap; /* SR-IOV Capabilities */ | |
418 | u16 ctrl; /* SR-IOV Control */ | |
419 | u16 total_VFs; /* Total VFs associated with the PF */ | |
420 | u16 initial_VFs; /* Initial VFs associated with the PF */ | |
421 | u16 num_VFs; /* Number of VFs available */ | |
422 | u16 offset; /* First VF Routing ID offset */ | |
423 | u16 stride; /* Following VF stride */ | |
424 | u16 vf_device; /* VF device ID */ | |
425 | u32 pgsz; /* Page size for BAR alignment */ | |
426 | u8 link; /* Function Dependency Link */ | |
427 | u8 max_VF_buses; /* Max buses consumed by VFs */ | |
428 | u16 driver_max_VFs; /* Max num VFs driver supports */ | |
429 | struct pci_dev *dev; /* Lowest numbered PF */ | |
430 | struct pci_dev *self; /* This PF */ | |
cf0921be KA |
431 | u32 class; /* VF device */ |
432 | u8 hdr_type; /* VF header type */ | |
433 | u16 subsystem_vendor; /* VF subsystem vendor */ | |
434 | u16 subsystem_device; /* VF subsystem device */ | |
0aa0f5d1 BH |
435 | resource_size_t barsz[PCI_SRIOV_NUM_BARS]; /* VF BAR size */ |
436 | bool drivers_autoprobe; /* Auto probing of VFs by driver */ | |
d1b054da YZ |
437 | }; |
438 | ||
ac048403 LW |
439 | #ifdef CONFIG_PCI_DOE |
440 | void pci_doe_init(struct pci_dev *pdev); | |
441 | void pci_doe_destroy(struct pci_dev *pdev); | |
442 | void pci_doe_disconnected(struct pci_dev *pdev); | |
443 | #else | |
444 | static inline void pci_doe_init(struct pci_dev *pdev) { } | |
445 | static inline void pci_doe_destroy(struct pci_dev *pdev) { } | |
446 | static inline void pci_doe_disconnected(struct pci_dev *pdev) { } | |
447 | #endif | |
448 | ||
4e893545 MT |
449 | #ifdef CONFIG_PCI_NPEM |
450 | void pci_npem_create(struct pci_dev *dev); | |
451 | void pci_npem_remove(struct pci_dev *dev); | |
452 | #else | |
453 | static inline void pci_npem_create(struct pci_dev *dev) { } | |
454 | static inline void pci_npem_remove(struct pci_dev *dev) { } | |
455 | #endif | |
456 | ||
a6bd101b KB |
457 | /** |
458 | * pci_dev_set_io_state - Set the new error state if possible. | |
459 | * | |
347269c1 KW |
460 | * @dev: PCI device to set new error_state |
461 | * @new: the state we want dev to be in | |
a6bd101b | 462 | * |
74ff8864 LW |
463 | * If the device is experiencing perm_failure, it has to remain in that state. |
464 | * Any other transition is allowed. | |
a6bd101b KB |
465 | * |
466 | * Returns true if state has been changed to the requested state. | |
467 | */ | |
468 | static inline bool pci_dev_set_io_state(struct pci_dev *dev, | |
469 | pci_channel_state_t new) | |
470 | { | |
74ff8864 | 471 | pci_channel_state_t old; |
a6bd101b | 472 | |
a6bd101b KB |
473 | switch (new) { |
474 | case pci_channel_io_perm_failure: | |
74ff8864 LW |
475 | xchg(&dev->error_state, pci_channel_io_perm_failure); |
476 | return true; | |
a6bd101b | 477 | case pci_channel_io_frozen: |
74ff8864 LW |
478 | old = cmpxchg(&dev->error_state, pci_channel_io_normal, |
479 | pci_channel_io_frozen); | |
480 | return old != pci_channel_io_perm_failure; | |
a6bd101b | 481 | case pci_channel_io_normal: |
74ff8864 LW |
482 | old = cmpxchg(&dev->error_state, pci_channel_io_frozen, |
483 | pci_channel_io_normal); | |
484 | return old != pci_channel_io_perm_failure; | |
485 | default: | |
486 | return false; | |
a6bd101b | 487 | } |
a6bd101b | 488 | } |
89ee9f76 KB |
489 | |
490 | static inline int pci_dev_set_disconnected(struct pci_dev *dev, void *unused) | |
491 | { | |
a6bd101b | 492 | pci_dev_set_io_state(dev, pci_channel_io_perm_failure); |
ac048403 | 493 | pci_doe_disconnected(dev); |
a6bd101b | 494 | |
89ee9f76 KB |
495 | return 0; |
496 | } | |
497 | ||
a6bd101b KB |
498 | /* pci_dev priv_flags */ |
499 | #define PCI_DEV_ADDED 0 | |
a97396c6 LW |
500 | #define PCI_DPC_RECOVERED 1 |
501 | #define PCI_DPC_RECOVERING 2 | |
e3f30d56 | 502 | #define PCI_DEV_REMOVED 3 |
a6bd101b | 503 | |
93093ea1 | 504 | static inline void pci_dev_assign_added(struct pci_dev *dev) |
44bda4b7 | 505 | { |
93093ea1 KB |
506 | smp_mb__before_atomic(); |
507 | set_bit(PCI_DEV_ADDED, &dev->priv_flags); | |
508 | smp_mb__after_atomic(); | |
509 | } | |
510 | ||
511 | static inline bool pci_dev_test_and_clear_added(struct pci_dev *dev) | |
512 | { | |
513 | return test_and_clear_bit(PCI_DEV_ADDED, &dev->priv_flags); | |
44bda4b7 HV |
514 | } |
515 | ||
516 | static inline bool pci_dev_is_added(const struct pci_dev *dev) | |
517 | { | |
518 | return test_bit(PCI_DEV_ADDED, &dev->priv_flags); | |
519 | } | |
520 | ||
e3f30d56 KB |
521 | static inline bool pci_dev_test_and_set_removed(struct pci_dev *dev) |
522 | { | |
523 | return test_and_set_bit(PCI_DEV_REMOVED, &dev->priv_flags); | |
524 | } | |
525 | ||
1e451160 KB |
526 | #ifdef CONFIG_PCIEAER |
527 | #include <linux/aer.h> | |
528 | ||
529 | #define AER_MAX_MULTI_ERR_DEVICES 5 /* Not likely to have more */ | |
530 | ||
531 | struct aer_err_info { | |
532 | struct pci_dev *dev[AER_MAX_MULTI_ERR_DEVICES]; | |
533 | int error_dev_num; | |
534 | ||
535 | unsigned int id:16; | |
536 | ||
537 | unsigned int severity:2; /* 0:NONFATAL | 1:FATAL | 2:COR */ | |
538 | unsigned int __pad1:5; | |
539 | unsigned int multi_error_valid:1; | |
540 | ||
541 | unsigned int first_error:5; | |
542 | unsigned int __pad2:2; | |
543 | unsigned int tlp_header_valid:1; | |
544 | ||
545 | unsigned int status; /* COR/UNCOR Error Status */ | |
546 | unsigned int mask; /* COR/UNCOR Error Mask */ | |
0a5a46a6 | 547 | struct pcie_tlp_log tlp; /* TLP Header */ |
1e451160 KB |
548 | }; |
549 | ||
550 | int aer_get_device_error_info(struct pci_dev *dev, struct aer_err_info *info); | |
551 | void aer_print_error(struct pci_dev *dev, struct aer_err_info *info); | |
1e451160 | 552 | |
ad41ddee IJ |
553 | int pcie_read_tlp_log(struct pci_dev *dev, int where, int where2, |
554 | unsigned int tlp_len, struct pcie_tlp_log *log); | |
555 | unsigned int aer_tlp_log_len(struct pci_dev *dev, u32 aercc); | |
a71c5926 | 556 | #endif /* CONFIG_PCIEAER */ |
01352558 | 557 | |
90655631 SK |
558 | #ifdef CONFIG_PCIEPORTBUS |
559 | /* Cached RCEC Endpoint Association */ | |
560 | struct rcec_ea { | |
561 | u8 nextbusn; | |
562 | u8 lastbusn; | |
563 | u32 bitmap; | |
564 | }; | |
565 | #endif | |
566 | ||
4f802170 KB |
567 | #ifdef CONFIG_PCIE_DPC |
568 | void pci_save_dpc_state(struct pci_dev *dev); | |
569 | void pci_restore_dpc_state(struct pci_dev *dev); | |
27005618 | 570 | void pci_dpc_init(struct pci_dev *pdev); |
aea47413 KS |
571 | void dpc_process_error(struct pci_dev *pdev); |
572 | pci_ers_result_t dpc_reset_link(struct pci_dev *pdev); | |
a97396c6 | 573 | bool pci_dpc_recovered(struct pci_dev *pdev); |
ad41ddee | 574 | unsigned int dpc_tlp_log_len(struct pci_dev *dev); |
4f802170 | 575 | #else |
eb6723b4 BH |
576 | static inline void pci_save_dpc_state(struct pci_dev *dev) { } |
577 | static inline void pci_restore_dpc_state(struct pci_dev *dev) { } | |
578 | static inline void pci_dpc_init(struct pci_dev *pdev) { } | |
a97396c6 | 579 | static inline bool pci_dpc_recovered(struct pci_dev *pdev) { return false; } |
4f802170 KB |
580 | #endif |
581 | ||
90655631 SK |
582 | #ifdef CONFIG_PCIEPORTBUS |
583 | void pci_rcec_init(struct pci_dev *dev); | |
584 | void pci_rcec_exit(struct pci_dev *dev); | |
507b460f | 585 | void pcie_link_rcec(struct pci_dev *rcec); |
af113553 SK |
586 | void pcie_walk_rcec(struct pci_dev *rcec, |
587 | int (*cb)(struct pci_dev *, void *), | |
588 | void *userdata); | |
90655631 | 589 | #else |
eb6723b4 BH |
590 | static inline void pci_rcec_init(struct pci_dev *dev) { } |
591 | static inline void pci_rcec_exit(struct pci_dev *dev) { } | |
592 | static inline void pcie_link_rcec(struct pci_dev *rcec) { } | |
af113553 SK |
593 | static inline void pcie_walk_rcec(struct pci_dev *rcec, |
594 | int (*cb)(struct pci_dev *, void *), | |
eb6723b4 | 595 | void *userdata) { } |
90655631 SK |
596 | #endif |
597 | ||
1900ca13 | 598 | #ifdef CONFIG_PCI_ATS |
b92b512a KS |
599 | /* Address Translation Service */ |
600 | void pci_ats_init(struct pci_dev *dev); | |
f39d5b72 | 601 | void pci_restore_ats_state(struct pci_dev *dev); |
1900ca13 | 602 | #else |
b92b512a KS |
603 | static inline void pci_ats_init(struct pci_dev *d) { } |
604 | static inline void pci_restore_ats_state(struct pci_dev *dev) { } | |
1900ca13 HX |
605 | #endif /* CONFIG_PCI_ATS */ |
606 | ||
c065190b KS |
607 | #ifdef CONFIG_PCI_PRI |
608 | void pci_pri_init(struct pci_dev *dev); | |
fef2dd8b | 609 | void pci_restore_pri_state(struct pci_dev *pdev); |
c065190b KS |
610 | #else |
611 | static inline void pci_pri_init(struct pci_dev *dev) { } | |
fef2dd8b | 612 | static inline void pci_restore_pri_state(struct pci_dev *pdev) { } |
c065190b KS |
613 | #endif |
614 | ||
751035b8 KS |
615 | #ifdef CONFIG_PCI_PASID |
616 | void pci_pasid_init(struct pci_dev *dev); | |
fef2dd8b | 617 | void pci_restore_pasid_state(struct pci_dev *pdev); |
751035b8 KS |
618 | #else |
619 | static inline void pci_pasid_init(struct pci_dev *dev) { } | |
fef2dd8b | 620 | static inline void pci_restore_pasid_state(struct pci_dev *pdev) { } |
751035b8 KS |
621 | #endif |
622 | ||
d1b054da | 623 | #ifdef CONFIG_PCI_IOV |
f39d5b72 BH |
624 | int pci_iov_init(struct pci_dev *dev); |
625 | void pci_iov_release(struct pci_dev *dev); | |
38972375 | 626 | void pci_iov_remove(struct pci_dev *dev); |
6ffa2489 | 627 | void pci_iov_update_resource(struct pci_dev *dev, int resno); |
f39d5b72 BH |
628 | resource_size_t pci_sriov_resource_alignment(struct pci_dev *dev, int resno); |
629 | void pci_restore_iov_state(struct pci_dev *dev); | |
630 | int pci_iov_bus_range(struct pci_bus *bus); | |
c3d5c2d9 LR |
631 | extern const struct attribute_group sriov_pf_dev_attr_group; |
632 | extern const struct attribute_group sriov_vf_dev_attr_group; | |
d1b054da YZ |
633 | #else |
634 | static inline int pci_iov_init(struct pci_dev *dev) | |
635 | { | |
636 | return -ENODEV; | |
637 | } | |
eb6723b4 BH |
638 | static inline void pci_iov_release(struct pci_dev *dev) { } |
639 | static inline void pci_iov_remove(struct pci_dev *dev) { } | |
640 | static inline void pci_restore_iov_state(struct pci_dev *dev) { } | |
a28724b0 YZ |
641 | static inline int pci_iov_bus_range(struct pci_bus *bus) |
642 | { | |
643 | return 0; | |
644 | } | |
302b4215 | 645 | |
d1b054da YZ |
646 | #endif /* CONFIG_PCI_IOV */ |
647 | ||
f69767a1 WH |
648 | #ifdef CONFIG_PCIE_TPH |
649 | void pci_restore_tph_state(struct pci_dev *dev); | |
650 | void pci_save_tph_state(struct pci_dev *dev); | |
651 | void pci_no_tph(void); | |
652 | void pci_tph_init(struct pci_dev *dev); | |
653 | #else | |
654 | static inline void pci_restore_tph_state(struct pci_dev *dev) { } | |
655 | static inline void pci_save_tph_state(struct pci_dev *dev) { } | |
656 | static inline void pci_no_tph(void) { } | |
657 | static inline void pci_tph_init(struct pci_dev *dev) { } | |
658 | #endif | |
659 | ||
39850ed5 | 660 | #ifdef CONFIG_PCIE_PTM |
d736d292 | 661 | void pci_ptm_init(struct pci_dev *dev); |
39850ed5 DB |
662 | void pci_save_ptm_state(struct pci_dev *dev); |
663 | void pci_restore_ptm_state(struct pci_dev *dev); | |
e8bdc5ea BH |
664 | void pci_suspend_ptm(struct pci_dev *dev); |
665 | void pci_resume_ptm(struct pci_dev *dev); | |
39850ed5 | 666 | #else |
d736d292 | 667 | static inline void pci_ptm_init(struct pci_dev *dev) { } |
39850ed5 DB |
668 | static inline void pci_save_ptm_state(struct pci_dev *dev) { } |
669 | static inline void pci_restore_ptm_state(struct pci_dev *dev) { } | |
e8bdc5ea BH |
670 | static inline void pci_suspend_ptm(struct pci_dev *dev) { } |
671 | static inline void pci_resume_ptm(struct pci_dev *dev) { } | |
39850ed5 DB |
672 | #endif |
673 | ||
f39d5b72 | 674 | unsigned long pci_cardbus_resource_alignment(struct resource *); |
0a2daa1c | 675 | |
0e52247a | 676 | static inline resource_size_t pci_resource_alignment(struct pci_dev *dev, |
f39d5b72 | 677 | struct resource *res) |
6faf17f6 CW |
678 | { |
679 | #ifdef CONFIG_PCI_IOV | |
680 | int resno = res - dev->resource; | |
681 | ||
682 | if (resno >= PCI_IOV_RESOURCES && resno <= PCI_IOV_RESOURCE_END) | |
683 | return pci_sriov_resource_alignment(dev, resno); | |
684 | #endif | |
0aa0f5d1 | 685 | if (dev->class >> 8 == PCI_CLASS_BRIDGE_CARDBUS) |
0a2daa1c | 686 | return pci_cardbus_resource_alignment(res); |
6faf17f6 CW |
687 | return resource_alignment(res); |
688 | } | |
689 | ||
52fbf5bd | 690 | void pci_acs_init(struct pci_dev *dev); |
bd2e9567 BH |
691 | #ifdef CONFIG_PCI_QUIRKS |
692 | int pci_dev_specific_acs_enabled(struct pci_dev *dev, u16 acs_flags); | |
693 | int pci_dev_specific_enable_acs(struct pci_dev *dev); | |
73c47dde | 694 | int pci_dev_specific_disable_acs_redir(struct pci_dev *dev); |
59100eb2 | 695 | int pcie_failed_link_retrain(struct pci_dev *dev); |
bd2e9567 BH |
696 | #else |
697 | static inline int pci_dev_specific_acs_enabled(struct pci_dev *dev, | |
698 | u16 acs_flags) | |
699 | { | |
700 | return -ENOTTY; | |
701 | } | |
702 | static inline int pci_dev_specific_enable_acs(struct pci_dev *dev) | |
703 | { | |
704 | return -ENOTTY; | |
705 | } | |
73c47dde LG |
706 | static inline int pci_dev_specific_disable_acs_redir(struct pci_dev *dev) |
707 | { | |
708 | return -ENOTTY; | |
709 | } | |
59100eb2 | 710 | static inline int pcie_failed_link_retrain(struct pci_dev *dev) |
a89c8224 | 711 | { |
59100eb2 | 712 | return -ENOTTY; |
a89c8224 | 713 | } |
bd2e9567 | 714 | #endif |
ae21ee65 | 715 | |
2e28bc84 | 716 | /* PCI error reporting and recovery */ |
e8e5ff2a | 717 | pci_ers_result_t pcie_do_recovery(struct pci_dev *dev, |
8f1bbfbc SK |
718 | pci_channel_state_t state, |
719 | pci_ers_result_t (*reset_subordinates)(struct pci_dev *pdev)); | |
2e28bc84 | 720 | |
9f5a70f1 | 721 | bool pcie_wait_for_link(struct pci_dev *pdev, bool active); |
1abb4739 | 722 | int pcie_retrain_link(struct pci_dev *pdev, bool use_lt); |
1e11b549 DB |
723 | |
724 | /* ASPM-related functionality we need even without CONFIG_PCIEASPM */ | |
725 | void pci_save_ltr_state(struct pci_dev *dev); | |
726 | void pci_restore_ltr_state(struct pci_dev *dev); | |
17423360 DB |
727 | void pci_configure_aspm_l1ss(struct pci_dev *dev); |
728 | void pci_save_aspm_l1ss_state(struct pci_dev *dev); | |
729 | void pci_restore_aspm_l1ss_state(struct pci_dev *dev); | |
1e11b549 | 730 | |
7d8e7d19 BH |
731 | #ifdef CONFIG_PCIEASPM |
732 | void pcie_aspm_init_link_state(struct pci_dev *pdev); | |
733 | void pcie_aspm_exit_link_state(struct pci_dev *pdev); | |
1e560864 | 734 | void pcie_aspm_pm_state_change(struct pci_dev *pdev, bool locked); |
7d8e7d19 | 735 | void pcie_aspm_powersave_config_link(struct pci_dev *pdev); |
fa84f443 DB |
736 | void pci_configure_ltr(struct pci_dev *pdev); |
737 | void pci_bridge_reconfigure_ltr(struct pci_dev *pdev); | |
7d8e7d19 BH |
738 | #else |
739 | static inline void pcie_aspm_init_link_state(struct pci_dev *pdev) { } | |
740 | static inline void pcie_aspm_exit_link_state(struct pci_dev *pdev) { } | |
1e560864 | 741 | static inline void pcie_aspm_pm_state_change(struct pci_dev *pdev, bool locked) { } |
7d8e7d19 | 742 | static inline void pcie_aspm_powersave_config_link(struct pci_dev *pdev) { } |
fa84f443 DB |
743 | static inline void pci_configure_ltr(struct pci_dev *pdev) { } |
744 | static inline void pci_bridge_reconfigure_ltr(struct pci_dev *pdev) { } | |
7d8e7d19 BH |
745 | #endif |
746 | ||
72bde9ce KS |
747 | #ifdef CONFIG_PCIE_ECRC |
748 | void pcie_set_ecrc_checking(struct pci_dev *dev); | |
749 | void pcie_ecrc_get_policy(char *str); | |
750 | #else | |
751 | static inline void pcie_set_ecrc_checking(struct pci_dev *dev) { } | |
752 | static inline void pcie_ecrc_get_policy(char *str) { } | |
753 | #endif | |
754 | ||
665745f2 IJ |
755 | #ifdef CONFIG_PCIEPORTBUS |
756 | void pcie_reset_lbms_count(struct pci_dev *port); | |
757 | int pcie_lbms_count(struct pci_dev *port, unsigned long *val); | |
758 | #else | |
759 | static inline void pcie_reset_lbms_count(struct pci_dev *port) {} | |
760 | static inline int pcie_lbms_count(struct pci_dev *port, unsigned long *val) | |
761 | { | |
762 | return -EOPNOTSUPP; | |
763 | } | |
764 | #endif | |
765 | ||
b9c3b266 DC |
766 | struct pci_dev_reset_methods { |
767 | u16 vendor; | |
768 | u16 device; | |
9bdc81ce | 769 | int (*reset)(struct pci_dev *dev, bool probe); |
b9c3b266 DC |
770 | }; |
771 | ||
e20afa06 | 772 | struct pci_reset_fn_method { |
9bdc81ce | 773 | int (*reset_fn)(struct pci_dev *pdev, bool probe); |
e20afa06 | 774 | char *name; |
b9c3b266 DC |
775 | }; |
776 | ||
93177a74 | 777 | #ifdef CONFIG_PCI_QUIRKS |
9bdc81ce | 778 | int pci_dev_specific_reset(struct pci_dev *dev, bool probe); |
93177a74 | 779 | #else |
9bdc81ce | 780 | static inline int pci_dev_specific_reset(struct pci_dev *dev, bool probe) |
93177a74 RW |
781 | { |
782 | return -ENOTTY; | |
783 | } | |
784 | #endif | |
b9c3b266 | 785 | |
169de969 DL |
786 | #if defined(CONFIG_PCI_QUIRKS) && defined(CONFIG_ARM64) |
787 | int acpi_get_rc_resources(struct device *dev, const char *hid, u16 segment, | |
788 | struct resource *res); | |
16f7ae59 AB |
789 | #else |
790 | static inline int acpi_get_rc_resources(struct device *dev, const char *hid, | |
791 | u16 segment, struct resource *res) | |
792 | { | |
793 | return -ENODEV; | |
794 | } | |
169de969 DL |
795 | #endif |
796 | ||
276b738d CK |
797 | int pci_rebar_get_current_size(struct pci_dev *pdev, int bar); |
798 | int pci_rebar_set_size(struct pci_dev *pdev, int bar, int size); | |
799 | static inline u64 pci_rebar_size_to_bytes(int size) | |
800 | { | |
801 | return 1ULL << (size + 20); | |
802 | } | |
803 | ||
9e2aee80 RH |
804 | struct device_node; |
805 | ||
806 | #ifdef CONFIG_OF | |
807 | int of_pci_parse_bus_range(struct device_node *node, struct resource *res); | |
808 | int of_get_pci_domain_nr(struct device_node *node); | |
809 | int of_pci_get_max_link_speed(struct device_node *node); | |
35662423 PR |
810 | u32 of_pci_get_slot_power_limit(struct device_node *node, |
811 | u8 *slot_power_limit_value, | |
812 | u8 *slot_power_limit_scale); | |
407abde9 | 813 | bool of_pci_preserve_config(struct device_node *node); |
0d21e71a | 814 | int pci_set_of_node(struct pci_dev *dev); |
621f7e35 KS |
815 | void pci_release_of_node(struct pci_dev *dev); |
816 | void pci_set_bus_of_node(struct pci_bus *bus); | |
817 | void pci_release_bus_of_node(struct pci_bus *bus); | |
9e2aee80 | 818 | |
669cbc70 | 819 | int devm_of_pci_bridge_init(struct device *dev, struct pci_host_bridge *bridge); |
278dd091 | 820 | bool of_pci_supply_present(struct device_node *np); |
669cbc70 | 821 | |
9e2aee80 RH |
822 | #else |
823 | static inline int | |
824 | of_pci_parse_bus_range(struct device_node *node, struct resource *res) | |
825 | { | |
826 | return -EINVAL; | |
827 | } | |
828 | ||
829 | static inline int | |
830 | of_get_pci_domain_nr(struct device_node *node) | |
831 | { | |
832 | return -1; | |
833 | } | |
834 | ||
835 | static inline int | |
836 | of_pci_get_max_link_speed(struct device_node *node) | |
837 | { | |
838 | return -EINVAL; | |
839 | } | |
621f7e35 | 840 | |
35662423 PR |
841 | static inline u32 |
842 | of_pci_get_slot_power_limit(struct device_node *node, | |
843 | u8 *slot_power_limit_value, | |
844 | u8 *slot_power_limit_scale) | |
845 | { | |
846 | if (slot_power_limit_value) | |
847 | *slot_power_limit_value = 0; | |
848 | if (slot_power_limit_scale) | |
849 | *slot_power_limit_scale = 0; | |
850 | return 0; | |
851 | } | |
852 | ||
407abde9 VS |
853 | static inline bool of_pci_preserve_config(struct device_node *node) |
854 | { | |
855 | return false; | |
856 | } | |
857 | ||
0d21e71a | 858 | static inline int pci_set_of_node(struct pci_dev *dev) { return 0; } |
621f7e35 KS |
859 | static inline void pci_release_of_node(struct pci_dev *dev) { } |
860 | static inline void pci_set_bus_of_node(struct pci_bus *bus) { } | |
861 | static inline void pci_release_bus_of_node(struct pci_bus *bus) { } | |
669cbc70 RH |
862 | |
863 | static inline int devm_of_pci_bridge_init(struct device *dev, struct pci_host_bridge *bridge) | |
864 | { | |
865 | return 0; | |
866 | } | |
867 | ||
278dd091 MS |
868 | static inline bool of_pci_supply_present(struct device_node *np) |
869 | { | |
870 | return false; | |
871 | } | |
9e2aee80 RH |
872 | #endif /* CONFIG_OF */ |
873 | ||
407d1a51 LH |
874 | struct of_changeset; |
875 | ||
876 | #ifdef CONFIG_PCI_DYNAMIC_OF_NODES | |
877 | void of_pci_make_dev_node(struct pci_dev *pdev); | |
878 | void of_pci_remove_node(struct pci_dev *pdev); | |
879 | int of_pci_add_properties(struct pci_dev *pdev, struct of_changeset *ocs, | |
880 | struct device_node *np); | |
881 | #else | |
882 | static inline void of_pci_make_dev_node(struct pci_dev *pdev) { } | |
883 | static inline void of_pci_remove_node(struct pci_dev *pdev) { } | |
884 | #endif | |
885 | ||
60ed982a RJ |
886 | #ifdef CONFIG_PCIEAER |
887 | void pci_no_aer(void); | |
888 | void pci_aer_init(struct pci_dev *dev); | |
db89ccbe | 889 | void pci_aer_exit(struct pci_dev *dev); |
81aa5206 | 890 | extern const struct attribute_group aer_stats_attr_group; |
7ab92e89 | 891 | void pci_aer_clear_fatal_status(struct pci_dev *dev); |
894020fd | 892 | int pci_aer_clear_status(struct pci_dev *dev); |
20e15e67 | 893 | int pci_aer_raw_clear_status(struct pci_dev *dev); |
ba3da667 BH |
894 | void pci_save_aer_state(struct pci_dev *dev); |
895 | void pci_restore_aer_state(struct pci_dev *dev); | |
60ed982a RJ |
896 | #else |
897 | static inline void pci_no_aer(void) { } | |
31f996ef | 898 | static inline void pci_aer_init(struct pci_dev *d) { } |
db89ccbe | 899 | static inline void pci_aer_exit(struct pci_dev *d) { } |
7ab92e89 | 900 | static inline void pci_aer_clear_fatal_status(struct pci_dev *dev) { } |
894020fd | 901 | static inline int pci_aer_clear_status(struct pci_dev *dev) { return -EINVAL; } |
20e15e67 | 902 | static inline int pci_aer_raw_clear_status(struct pci_dev *dev) { return -EINVAL; } |
ba3da667 BH |
903 | static inline void pci_save_aer_state(struct pci_dev *dev) { } |
904 | static inline void pci_restore_aer_state(struct pci_dev *dev) { } | |
60ed982a RJ |
905 | #endif |
906 | ||
8c3aac6e | 907 | #ifdef CONFIG_ACPI |
9d7d5db8 | 908 | bool pci_acpi_preserve_config(struct pci_host_bridge *bridge); |
4a2dbedd | 909 | int pci_acpi_program_hp_params(struct pci_dev *dev); |
506140f9 | 910 | extern const struct attribute_group pci_dev_acpi_attr_group; |
3a15955d | 911 | void pci_set_acpi_fwnode(struct pci_dev *dev); |
9bdc81ce | 912 | int pci_dev_acpi_reset(struct pci_dev *dev, bool probe); |
d97c5d4c RW |
913 | bool acpi_pci_power_manageable(struct pci_dev *dev); |
914 | bool acpi_pci_bridge_d3(struct pci_dev *dev); | |
915 | int acpi_pci_set_power_state(struct pci_dev *dev, pci_power_t state); | |
916 | pci_power_t acpi_pci_get_power_state(struct pci_dev *dev); | |
917 | void acpi_pci_refresh_power_state(struct pci_dev *dev); | |
918 | int acpi_pci_wakeup(struct pci_dev *dev, bool enable); | |
919 | bool acpi_pci_need_resume(struct pci_dev *dev); | |
920 | pci_power_t acpi_pci_choose_state(struct pci_dev *pdev); | |
8c3aac6e | 921 | #else |
9d7d5db8 VS |
922 | static inline bool pci_acpi_preserve_config(struct pci_host_bridge *bridge) |
923 | { | |
924 | return false; | |
925 | } | |
9bdc81ce | 926 | static inline int pci_dev_acpi_reset(struct pci_dev *dev, bool probe) |
6937b7dd SD |
927 | { |
928 | return -ENOTTY; | |
929 | } | |
eb6723b4 | 930 | static inline void pci_set_acpi_fwnode(struct pci_dev *dev) { } |
4a2dbedd | 931 | static inline int pci_acpi_program_hp_params(struct pci_dev *dev) |
8c3aac6e KW |
932 | { |
933 | return -ENODEV; | |
934 | } | |
d97c5d4c RW |
935 | static inline bool acpi_pci_power_manageable(struct pci_dev *dev) |
936 | { | |
937 | return false; | |
938 | } | |
939 | static inline bool acpi_pci_bridge_d3(struct pci_dev *dev) | |
940 | { | |
941 | return false; | |
942 | } | |
943 | static inline int acpi_pci_set_power_state(struct pci_dev *dev, pci_power_t state) | |
944 | { | |
945 | return -ENODEV; | |
946 | } | |
947 | static inline pci_power_t acpi_pci_get_power_state(struct pci_dev *dev) | |
948 | { | |
949 | return PCI_UNKNOWN; | |
950 | } | |
eb6723b4 | 951 | static inline void acpi_pci_refresh_power_state(struct pci_dev *dev) { } |
d97c5d4c RW |
952 | static inline int acpi_pci_wakeup(struct pci_dev *dev, bool enable) |
953 | { | |
954 | return -ENODEV; | |
955 | } | |
956 | static inline bool acpi_pci_need_resume(struct pci_dev *dev) | |
957 | { | |
958 | return false; | |
959 | } | |
960 | static inline pci_power_t acpi_pci_choose_state(struct pci_dev *pdev) | |
961 | { | |
962 | return PCI_POWER_ERROR; | |
963 | } | |
8c3aac6e KW |
964 | #endif |
965 | ||
72ea91af HK |
966 | #ifdef CONFIG_PCIEASPM |
967 | extern const struct attribute_group aspm_ctrl_attr_group; | |
968 | #endif | |
969 | ||
d88f521d AN |
970 | extern const struct attribute_group pci_dev_reset_method_attr_group; |
971 | ||
d5b0d883 RW |
972 | #ifdef CONFIG_X86_INTEL_MID |
973 | bool pci_use_mid_pm(void); | |
974 | int mid_pci_set_power_state(struct pci_dev *pdev, pci_power_t state); | |
975 | pci_power_t mid_pci_get_power_state(struct pci_dev *pdev); | |
976 | #else | |
977 | static inline bool pci_use_mid_pm(void) | |
978 | { | |
979 | return false; | |
980 | } | |
981 | static inline int mid_pci_set_power_state(struct pci_dev *pdev, pci_power_t state) | |
982 | { | |
983 | return -ENODEV; | |
984 | } | |
985 | static inline pci_power_t mid_pci_get_power_state(struct pci_dev *pdev) | |
986 | { | |
987 | return PCI_UNKNOWN; | |
988 | } | |
989 | #endif | |
990 | ||
25216afc | 991 | int pcim_intx(struct pci_dev *dev, int enable); |
d47bde70 PS |
992 | int pcim_request_region_exclusive(struct pci_dev *pdev, int bar, |
993 | const char *name); | |
994 | void pcim_release_region(struct pci_dev *pdev, int bar); | |
995 | ||
8a9b7ef7 PR |
996 | /* |
997 | * Config Address for PCI Configuration Mechanism #1 | |
998 | * | |
999 | * See PCI Local Bus Specification, Revision 3.0, | |
1000 | * Section 3.2.2.3.2, Figure 3-2, p. 50. | |
1001 | */ | |
1002 | ||
1003 | #define PCI_CONF1_BUS_SHIFT 16 /* Bus number */ | |
1004 | #define PCI_CONF1_DEV_SHIFT 11 /* Device number */ | |
1005 | #define PCI_CONF1_FUNC_SHIFT 8 /* Function number */ | |
1006 | ||
1007 | #define PCI_CONF1_BUS_MASK 0xff | |
1008 | #define PCI_CONF1_DEV_MASK 0x1f | |
1009 | #define PCI_CONF1_FUNC_MASK 0x7 | |
1010 | #define PCI_CONF1_REG_MASK 0xfc /* Limit aligned offset to a maximum of 256B */ | |
1011 | ||
1012 | #define PCI_CONF1_ENABLE BIT(31) | |
1013 | #define PCI_CONF1_BUS(x) (((x) & PCI_CONF1_BUS_MASK) << PCI_CONF1_BUS_SHIFT) | |
1014 | #define PCI_CONF1_DEV(x) (((x) & PCI_CONF1_DEV_MASK) << PCI_CONF1_DEV_SHIFT) | |
1015 | #define PCI_CONF1_FUNC(x) (((x) & PCI_CONF1_FUNC_MASK) << PCI_CONF1_FUNC_SHIFT) | |
1016 | #define PCI_CONF1_REG(x) ((x) & PCI_CONF1_REG_MASK) | |
1017 | ||
1018 | #define PCI_CONF1_ADDRESS(bus, dev, func, reg) \ | |
1019 | (PCI_CONF1_ENABLE | \ | |
1020 | PCI_CONF1_BUS(bus) | \ | |
1021 | PCI_CONF1_DEV(dev) | \ | |
1022 | PCI_CONF1_FUNC(func) | \ | |
1023 | PCI_CONF1_REG(reg)) | |
1024 | ||
1025 | /* | |
1026 | * Extension of PCI Config Address for accessing extended PCIe registers | |
1027 | * | |
1028 | * No standardized specification, but used on lot of non-ECAM-compliant ARM SoCs | |
1029 | * or on AMD Barcelona and new CPUs. Reserved bits [27:24] of PCI Config Address | |
1030 | * are used for specifying additional 4 high bits of PCI Express register. | |
1031 | */ | |
1032 | ||
1033 | #define PCI_CONF1_EXT_REG_SHIFT 16 | |
1034 | #define PCI_CONF1_EXT_REG_MASK 0xf00 | |
1035 | #define PCI_CONF1_EXT_REG(x) (((x) & PCI_CONF1_EXT_REG_MASK) << PCI_CONF1_EXT_REG_SHIFT) | |
1036 | ||
1037 | #define PCI_CONF1_EXT_ADDRESS(bus, dev, func, reg) \ | |
1038 | (PCI_CONF1_ADDRESS(bus, dev, func, reg) | \ | |
1039 | PCI_CONF1_EXT_REG(reg)) | |
1040 | ||
557848c3 | 1041 | #endif /* DRIVERS_PCI_H */ |