]>
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 | 319 | int pci_setup_device(struct pci_dev *dev); |
4453f360 AW |
320 | void __pci_size_stdbars(struct pci_dev *dev, int count, |
321 | unsigned int pos, u32 *sizes); | |
f39d5b72 | 322 | int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type, |
4453f360 | 323 | struct resource *res, unsigned int reg, u32 *sizes); |
f39d5b72 | 324 | void pci_configure_ari(struct pci_dev *dev); |
10874f5a | 325 | void __pci_bus_size_bridges(struct pci_bus *bus, |
d66ecb72 | 326 | struct list_head *realloc_head); |
10874f5a BH |
327 | void __pci_bus_assign_resources(const struct pci_bus *bus, |
328 | struct list_head *realloc_head, | |
329 | struct list_head *fail_head); | |
0f7e7aee | 330 | bool pci_bus_clip_resource(struct pci_dev *dev, int idx); |
38a18dfe KB |
331 | void pci_walk_bus_locked(struct pci_bus *top, |
332 | int (*cb)(struct pci_dev *, void *), | |
333 | void *userdata); | |
939de1d6 | 334 | |
65f8e0be PM |
335 | const char *pci_resource_name(struct pci_dev *dev, unsigned int i); |
336 | ||
2069ecfb | 337 | void pci_reassigndev_resource_alignment(struct pci_dev *dev); |
f39d5b72 | 338 | void pci_disable_bridge_window(struct pci_dev *dev); |
ecd29c1a KS |
339 | struct pci_bus *pci_bus_get(struct pci_bus *bus); |
340 | void pci_bus_put(struct pci_bus *bus); | |
32a9a682 | 341 | |
de9a6c8d IJ |
342 | #define PCIE_LNKCAP_SLS2SPEED(lnkcap) \ |
343 | ({ \ | |
344 | ((lnkcap) == PCI_EXP_LNKCAP_SLS_64_0GB ? PCIE_SPEED_64_0GT : \ | |
345 | (lnkcap) == PCI_EXP_LNKCAP_SLS_32_0GB ? PCIE_SPEED_32_0GT : \ | |
346 | (lnkcap) == PCI_EXP_LNKCAP_SLS_16_0GB ? PCIE_SPEED_16_0GT : \ | |
347 | (lnkcap) == PCI_EXP_LNKCAP_SLS_8_0GB ? PCIE_SPEED_8_0GT : \ | |
348 | (lnkcap) == PCI_EXP_LNKCAP_SLS_5_0GB ? PCIE_SPEED_5_0GT : \ | |
349 | (lnkcap) == PCI_EXP_LNKCAP_SLS_2_5GB ? PCIE_SPEED_2_5GT : \ | |
350 | PCI_SPEED_UNKNOWN); \ | |
351 | }) | |
352 | ||
757bfaa2 YY |
353 | /* PCIe link information from Link Capabilities 2 */ |
354 | #define PCIE_LNKCAP2_SLS2SPEED(lnkcap2) \ | |
34191749 GP |
355 | ((lnkcap2) & PCI_EXP_LNKCAP2_SLS_64_0GB ? PCIE_SPEED_64_0GT : \ |
356 | (lnkcap2) & PCI_EXP_LNKCAP2_SLS_32_0GB ? PCIE_SPEED_32_0GT : \ | |
757bfaa2 YY |
357 | (lnkcap2) & PCI_EXP_LNKCAP2_SLS_16_0GB ? PCIE_SPEED_16_0GT : \ |
358 | (lnkcap2) & PCI_EXP_LNKCAP2_SLS_8_0GB ? PCIE_SPEED_8_0GT : \ | |
359 | (lnkcap2) & PCI_EXP_LNKCAP2_SLS_5_0GB ? PCIE_SPEED_5_0GT : \ | |
360 | (lnkcap2) & PCI_EXP_LNKCAP2_SLS_2_5GB ? PCIE_SPEED_2_5GT : \ | |
361 | PCI_SPEED_UNKNOWN) | |
6cf57be0 | 362 | |
de9a6c8d IJ |
363 | #define PCIE_LNKCTL2_TLS2SPEED(lnkctl2) \ |
364 | ((lnkctl2) == PCI_EXP_LNKCTL2_TLS_64_0GT ? PCIE_SPEED_64_0GT : \ | |
365 | (lnkctl2) == PCI_EXP_LNKCTL2_TLS_32_0GT ? PCIE_SPEED_32_0GT : \ | |
366 | (lnkctl2) == PCI_EXP_LNKCTL2_TLS_16_0GT ? PCIE_SPEED_16_0GT : \ | |
367 | (lnkctl2) == PCI_EXP_LNKCTL2_TLS_8_0GT ? PCIE_SPEED_8_0GT : \ | |
368 | (lnkctl2) == PCI_EXP_LNKCTL2_TLS_5_0GT ? PCIE_SPEED_5_0GT : \ | |
369 | (lnkctl2) == PCI_EXP_LNKCTL2_TLS_2_5GT ? PCIE_SPEED_2_5GT : \ | |
370 | PCI_SPEED_UNKNOWN) | |
371 | ||
b852f63a TG |
372 | /* PCIe speed to Mb/s reduced by encoding overhead */ |
373 | #define PCIE_SPEED2MBS_ENC(speed) \ | |
ac4f1897 | 374 | ((speed) == PCIE_SPEED_64_0GT ? 64000*1/1 : \ |
34191749 | 375 | (speed) == PCIE_SPEED_32_0GT ? 32000*128/130 : \ |
9cb3985a | 376 | (speed) == PCIE_SPEED_16_0GT ? 16000*128/130 : \ |
b852f63a TG |
377 | (speed) == PCIE_SPEED_8_0GT ? 8000*128/130 : \ |
378 | (speed) == PCIE_SPEED_5_0GT ? 5000*8/10 : \ | |
379 | (speed) == PCIE_SPEED_2_5GT ? 2500*8/10 : \ | |
380 | 0) | |
381 | ||
100ae5d7 K |
382 | static inline int pcie_dev_speed_mbps(enum pci_bus_speed speed) |
383 | { | |
384 | switch (speed) { | |
385 | case PCIE_SPEED_2_5GT: | |
386 | return 2500; | |
387 | case PCIE_SPEED_5_0GT: | |
388 | return 5000; | |
389 | case PCIE_SPEED_8_0GT: | |
390 | return 8000; | |
391 | case PCIE_SPEED_16_0GT: | |
392 | return 16000; | |
393 | case PCIE_SPEED_32_0GT: | |
394 | return 32000; | |
395 | case PCIE_SPEED_64_0GT: | |
396 | return 64000; | |
397 | default: | |
398 | break; | |
399 | } | |
400 | ||
401 | return -EINVAL; | |
402 | } | |
403 | ||
d2bd39c0 | 404 | u8 pcie_get_supported_speeds(struct pci_dev *dev); |
e56faff5 | 405 | const char *pci_speed_string(enum pci_bus_speed speed); |
2d1ce5ec | 406 | void __pcie_print_link_status(struct pci_dev *dev, bool verbose); |
0fa635ae | 407 | void pcie_report_downtraining(struct pci_dev *dev); |
e93d9fcf IJ |
408 | |
409 | static inline void __pcie_update_link_speed(struct pci_bus *bus, u16 linksta) | |
410 | { | |
411 | bus->cur_bus_speed = pcie_link_speed[linksta & PCI_EXP_LNKSTA_CLS]; | |
412 | } | |
413 | void pcie_update_link_speed(struct pci_bus *bus); | |
6cf57be0 | 414 | |
d1b054da YZ |
415 | /* Single Root I/O Virtualization */ |
416 | struct pci_sriov { | |
0aa0f5d1 BH |
417 | int pos; /* Capability position */ |
418 | int nres; /* Number of resources */ | |
419 | u32 cap; /* SR-IOV Capabilities */ | |
420 | u16 ctrl; /* SR-IOV Control */ | |
421 | u16 total_VFs; /* Total VFs associated with the PF */ | |
422 | u16 initial_VFs; /* Initial VFs associated with the PF */ | |
423 | u16 num_VFs; /* Number of VFs available */ | |
424 | u16 offset; /* First VF Routing ID offset */ | |
425 | u16 stride; /* Following VF stride */ | |
426 | u16 vf_device; /* VF device ID */ | |
427 | u32 pgsz; /* Page size for BAR alignment */ | |
428 | u8 link; /* Function Dependency Link */ | |
429 | u8 max_VF_buses; /* Max buses consumed by VFs */ | |
430 | u16 driver_max_VFs; /* Max num VFs driver supports */ | |
431 | struct pci_dev *dev; /* Lowest numbered PF */ | |
432 | struct pci_dev *self; /* This PF */ | |
cf0921be KA |
433 | u32 class; /* VF device */ |
434 | u8 hdr_type; /* VF header type */ | |
435 | u16 subsystem_vendor; /* VF subsystem vendor */ | |
436 | u16 subsystem_device; /* VF subsystem device */ | |
0aa0f5d1 BH |
437 | resource_size_t barsz[PCI_SRIOV_NUM_BARS]; /* VF BAR size */ |
438 | bool drivers_autoprobe; /* Auto probing of VFs by driver */ | |
d1b054da YZ |
439 | }; |
440 | ||
ac048403 LW |
441 | #ifdef CONFIG_PCI_DOE |
442 | void pci_doe_init(struct pci_dev *pdev); | |
443 | void pci_doe_destroy(struct pci_dev *pdev); | |
444 | void pci_doe_disconnected(struct pci_dev *pdev); | |
445 | #else | |
446 | static inline void pci_doe_init(struct pci_dev *pdev) { } | |
447 | static inline void pci_doe_destroy(struct pci_dev *pdev) { } | |
448 | static inline void pci_doe_disconnected(struct pci_dev *pdev) { } | |
449 | #endif | |
450 | ||
4e893545 MT |
451 | #ifdef CONFIG_PCI_NPEM |
452 | void pci_npem_create(struct pci_dev *dev); | |
453 | void pci_npem_remove(struct pci_dev *dev); | |
454 | #else | |
455 | static inline void pci_npem_create(struct pci_dev *dev) { } | |
456 | static inline void pci_npem_remove(struct pci_dev *dev) { } | |
457 | #endif | |
458 | ||
a6bd101b KB |
459 | /** |
460 | * pci_dev_set_io_state - Set the new error state if possible. | |
461 | * | |
347269c1 KW |
462 | * @dev: PCI device to set new error_state |
463 | * @new: the state we want dev to be in | |
a6bd101b | 464 | * |
74ff8864 LW |
465 | * If the device is experiencing perm_failure, it has to remain in that state. |
466 | * Any other transition is allowed. | |
a6bd101b KB |
467 | * |
468 | * Returns true if state has been changed to the requested state. | |
469 | */ | |
470 | static inline bool pci_dev_set_io_state(struct pci_dev *dev, | |
471 | pci_channel_state_t new) | |
472 | { | |
74ff8864 | 473 | pci_channel_state_t old; |
a6bd101b | 474 | |
a6bd101b KB |
475 | switch (new) { |
476 | case pci_channel_io_perm_failure: | |
74ff8864 LW |
477 | xchg(&dev->error_state, pci_channel_io_perm_failure); |
478 | return true; | |
a6bd101b | 479 | case pci_channel_io_frozen: |
74ff8864 LW |
480 | old = cmpxchg(&dev->error_state, pci_channel_io_normal, |
481 | pci_channel_io_frozen); | |
482 | return old != pci_channel_io_perm_failure; | |
a6bd101b | 483 | case pci_channel_io_normal: |
74ff8864 LW |
484 | old = cmpxchg(&dev->error_state, pci_channel_io_frozen, |
485 | pci_channel_io_normal); | |
486 | return old != pci_channel_io_perm_failure; | |
487 | default: | |
488 | return false; | |
a6bd101b | 489 | } |
a6bd101b | 490 | } |
89ee9f76 KB |
491 | |
492 | static inline int pci_dev_set_disconnected(struct pci_dev *dev, void *unused) | |
493 | { | |
a6bd101b | 494 | pci_dev_set_io_state(dev, pci_channel_io_perm_failure); |
ac048403 | 495 | pci_doe_disconnected(dev); |
a6bd101b | 496 | |
89ee9f76 KB |
497 | return 0; |
498 | } | |
499 | ||
a6bd101b KB |
500 | /* pci_dev priv_flags */ |
501 | #define PCI_DEV_ADDED 0 | |
a97396c6 LW |
502 | #define PCI_DPC_RECOVERED 1 |
503 | #define PCI_DPC_RECOVERING 2 | |
e3f30d56 | 504 | #define PCI_DEV_REMOVED 3 |
a6bd101b | 505 | |
93093ea1 | 506 | static inline void pci_dev_assign_added(struct pci_dev *dev) |
44bda4b7 | 507 | { |
93093ea1 KB |
508 | smp_mb__before_atomic(); |
509 | set_bit(PCI_DEV_ADDED, &dev->priv_flags); | |
510 | smp_mb__after_atomic(); | |
511 | } | |
512 | ||
513 | static inline bool pci_dev_test_and_clear_added(struct pci_dev *dev) | |
514 | { | |
515 | return test_and_clear_bit(PCI_DEV_ADDED, &dev->priv_flags); | |
44bda4b7 HV |
516 | } |
517 | ||
518 | static inline bool pci_dev_is_added(const struct pci_dev *dev) | |
519 | { | |
520 | return test_bit(PCI_DEV_ADDED, &dev->priv_flags); | |
521 | } | |
522 | ||
e3f30d56 KB |
523 | static inline bool pci_dev_test_and_set_removed(struct pci_dev *dev) |
524 | { | |
525 | return test_and_set_bit(PCI_DEV_REMOVED, &dev->priv_flags); | |
526 | } | |
527 | ||
1e451160 KB |
528 | #ifdef CONFIG_PCIEAER |
529 | #include <linux/aer.h> | |
530 | ||
531 | #define AER_MAX_MULTI_ERR_DEVICES 5 /* Not likely to have more */ | |
532 | ||
533 | struct aer_err_info { | |
534 | struct pci_dev *dev[AER_MAX_MULTI_ERR_DEVICES]; | |
535 | int error_dev_num; | |
536 | ||
537 | unsigned int id:16; | |
538 | ||
539 | unsigned int severity:2; /* 0:NONFATAL | 1:FATAL | 2:COR */ | |
540 | unsigned int __pad1:5; | |
541 | unsigned int multi_error_valid:1; | |
542 | ||
543 | unsigned int first_error:5; | |
544 | unsigned int __pad2:2; | |
545 | unsigned int tlp_header_valid:1; | |
546 | ||
547 | unsigned int status; /* COR/UNCOR Error Status */ | |
548 | unsigned int mask; /* COR/UNCOR Error Mask */ | |
0a5a46a6 | 549 | struct pcie_tlp_log tlp; /* TLP Header */ |
1e451160 KB |
550 | }; |
551 | ||
552 | int aer_get_device_error_info(struct pci_dev *dev, struct aer_err_info *info); | |
553 | void aer_print_error(struct pci_dev *dev, struct aer_err_info *info); | |
1e451160 | 554 | |
ad41ddee IJ |
555 | int pcie_read_tlp_log(struct pci_dev *dev, int where, int where2, |
556 | unsigned int tlp_len, struct pcie_tlp_log *log); | |
557 | unsigned int aer_tlp_log_len(struct pci_dev *dev, u32 aercc); | |
f68ea779 IJ |
558 | void pcie_print_tlp_log(const struct pci_dev *dev, |
559 | const struct pcie_tlp_log *log, const char *pfx); | |
1e451160 KB |
560 | #endif /* CONFIG_PCIEAER */ |
561 | ||
90655631 SK |
562 | #ifdef CONFIG_PCIEPORTBUS |
563 | /* Cached RCEC Endpoint Association */ | |
564 | struct rcec_ea { | |
565 | u8 nextbusn; | |
566 | u8 lastbusn; | |
567 | u32 bitmap; | |
568 | }; | |
569 | #endif | |
570 | ||
4f802170 KB |
571 | #ifdef CONFIG_PCIE_DPC |
572 | void pci_save_dpc_state(struct pci_dev *dev); | |
573 | void pci_restore_dpc_state(struct pci_dev *dev); | |
27005618 | 574 | void pci_dpc_init(struct pci_dev *pdev); |
aea47413 KS |
575 | void dpc_process_error(struct pci_dev *pdev); |
576 | pci_ers_result_t dpc_reset_link(struct pci_dev *pdev); | |
a97396c6 | 577 | bool pci_dpc_recovered(struct pci_dev *pdev); |
ad41ddee | 578 | unsigned int dpc_tlp_log_len(struct pci_dev *dev); |
4f802170 | 579 | #else |
eb6723b4 BH |
580 | static inline void pci_save_dpc_state(struct pci_dev *dev) { } |
581 | static inline void pci_restore_dpc_state(struct pci_dev *dev) { } | |
582 | static inline void pci_dpc_init(struct pci_dev *pdev) { } | |
a97396c6 | 583 | static inline bool pci_dpc_recovered(struct pci_dev *pdev) { return false; } |
4f802170 KB |
584 | #endif |
585 | ||
90655631 SK |
586 | #ifdef CONFIG_PCIEPORTBUS |
587 | void pci_rcec_init(struct pci_dev *dev); | |
588 | void pci_rcec_exit(struct pci_dev *dev); | |
507b460f | 589 | void pcie_link_rcec(struct pci_dev *rcec); |
af113553 SK |
590 | void pcie_walk_rcec(struct pci_dev *rcec, |
591 | int (*cb)(struct pci_dev *, void *), | |
592 | void *userdata); | |
90655631 | 593 | #else |
eb6723b4 BH |
594 | static inline void pci_rcec_init(struct pci_dev *dev) { } |
595 | static inline void pci_rcec_exit(struct pci_dev *dev) { } | |
596 | static inline void pcie_link_rcec(struct pci_dev *rcec) { } | |
af113553 SK |
597 | static inline void pcie_walk_rcec(struct pci_dev *rcec, |
598 | int (*cb)(struct pci_dev *, void *), | |
eb6723b4 | 599 | void *userdata) { } |
90655631 SK |
600 | #endif |
601 | ||
1900ca13 | 602 | #ifdef CONFIG_PCI_ATS |
b92b512a KS |
603 | /* Address Translation Service */ |
604 | void pci_ats_init(struct pci_dev *dev); | |
f39d5b72 | 605 | void pci_restore_ats_state(struct pci_dev *dev); |
1900ca13 | 606 | #else |
b92b512a KS |
607 | static inline void pci_ats_init(struct pci_dev *d) { } |
608 | static inline void pci_restore_ats_state(struct pci_dev *dev) { } | |
1900ca13 HX |
609 | #endif /* CONFIG_PCI_ATS */ |
610 | ||
c065190b KS |
611 | #ifdef CONFIG_PCI_PRI |
612 | void pci_pri_init(struct pci_dev *dev); | |
fef2dd8b | 613 | void pci_restore_pri_state(struct pci_dev *pdev); |
c065190b KS |
614 | #else |
615 | static inline void pci_pri_init(struct pci_dev *dev) { } | |
fef2dd8b | 616 | static inline void pci_restore_pri_state(struct pci_dev *pdev) { } |
c065190b KS |
617 | #endif |
618 | ||
751035b8 KS |
619 | #ifdef CONFIG_PCI_PASID |
620 | void pci_pasid_init(struct pci_dev *dev); | |
fef2dd8b | 621 | void pci_restore_pasid_state(struct pci_dev *pdev); |
751035b8 KS |
622 | #else |
623 | static inline void pci_pasid_init(struct pci_dev *dev) { } | |
fef2dd8b | 624 | static inline void pci_restore_pasid_state(struct pci_dev *pdev) { } |
751035b8 KS |
625 | #endif |
626 | ||
d1b054da | 627 | #ifdef CONFIG_PCI_IOV |
f39d5b72 BH |
628 | int pci_iov_init(struct pci_dev *dev); |
629 | void pci_iov_release(struct pci_dev *dev); | |
38972375 | 630 | void pci_iov_remove(struct pci_dev *dev); |
6ffa2489 | 631 | void pci_iov_update_resource(struct pci_dev *dev, int resno); |
f39d5b72 BH |
632 | resource_size_t pci_sriov_resource_alignment(struct pci_dev *dev, int resno); |
633 | void pci_restore_iov_state(struct pci_dev *dev); | |
634 | int pci_iov_bus_range(struct pci_bus *bus); | |
c3d5c2d9 LR |
635 | extern const struct attribute_group sriov_pf_dev_attr_group; |
636 | extern const struct attribute_group sriov_vf_dev_attr_group; | |
d1b054da YZ |
637 | #else |
638 | static inline int pci_iov_init(struct pci_dev *dev) | |
639 | { | |
640 | return -ENODEV; | |
641 | } | |
eb6723b4 BH |
642 | static inline void pci_iov_release(struct pci_dev *dev) { } |
643 | static inline void pci_iov_remove(struct pci_dev *dev) { } | |
644 | static inline void pci_restore_iov_state(struct pci_dev *dev) { } | |
a28724b0 YZ |
645 | static inline int pci_iov_bus_range(struct pci_bus *bus) |
646 | { | |
647 | return 0; | |
648 | } | |
302b4215 | 649 | |
d1b054da YZ |
650 | #endif /* CONFIG_PCI_IOV */ |
651 | ||
f69767a1 WH |
652 | #ifdef CONFIG_PCIE_TPH |
653 | void pci_restore_tph_state(struct pci_dev *dev); | |
654 | void pci_save_tph_state(struct pci_dev *dev); | |
655 | void pci_no_tph(void); | |
656 | void pci_tph_init(struct pci_dev *dev); | |
657 | #else | |
658 | static inline void pci_restore_tph_state(struct pci_dev *dev) { } | |
659 | static inline void pci_save_tph_state(struct pci_dev *dev) { } | |
660 | static inline void pci_no_tph(void) { } | |
661 | static inline void pci_tph_init(struct pci_dev *dev) { } | |
662 | #endif | |
663 | ||
39850ed5 | 664 | #ifdef CONFIG_PCIE_PTM |
d736d292 | 665 | void pci_ptm_init(struct pci_dev *dev); |
39850ed5 DB |
666 | void pci_save_ptm_state(struct pci_dev *dev); |
667 | void pci_restore_ptm_state(struct pci_dev *dev); | |
e8bdc5ea BH |
668 | void pci_suspend_ptm(struct pci_dev *dev); |
669 | void pci_resume_ptm(struct pci_dev *dev); | |
39850ed5 | 670 | #else |
d736d292 | 671 | static inline void pci_ptm_init(struct pci_dev *dev) { } |
39850ed5 DB |
672 | static inline void pci_save_ptm_state(struct pci_dev *dev) { } |
673 | static inline void pci_restore_ptm_state(struct pci_dev *dev) { } | |
e8bdc5ea BH |
674 | static inline void pci_suspend_ptm(struct pci_dev *dev) { } |
675 | static inline void pci_resume_ptm(struct pci_dev *dev) { } | |
39850ed5 DB |
676 | #endif |
677 | ||
f39d5b72 | 678 | unsigned long pci_cardbus_resource_alignment(struct resource *); |
0a2daa1c | 679 | |
0e52247a | 680 | static inline resource_size_t pci_resource_alignment(struct pci_dev *dev, |
f39d5b72 | 681 | struct resource *res) |
6faf17f6 CW |
682 | { |
683 | #ifdef CONFIG_PCI_IOV | |
684 | int resno = res - dev->resource; | |
685 | ||
686 | if (resno >= PCI_IOV_RESOURCES && resno <= PCI_IOV_RESOURCE_END) | |
687 | return pci_sriov_resource_alignment(dev, resno); | |
688 | #endif | |
0aa0f5d1 | 689 | if (dev->class >> 8 == PCI_CLASS_BRIDGE_CARDBUS) |
0a2daa1c | 690 | return pci_cardbus_resource_alignment(res); |
6faf17f6 CW |
691 | return resource_alignment(res); |
692 | } | |
693 | ||
52fbf5bd | 694 | void pci_acs_init(struct pci_dev *dev); |
bd2e9567 BH |
695 | #ifdef CONFIG_PCI_QUIRKS |
696 | int pci_dev_specific_acs_enabled(struct pci_dev *dev, u16 acs_flags); | |
697 | int pci_dev_specific_enable_acs(struct pci_dev *dev); | |
73c47dde | 698 | int pci_dev_specific_disable_acs_redir(struct pci_dev *dev); |
59100eb2 | 699 | int pcie_failed_link_retrain(struct pci_dev *dev); |
bd2e9567 BH |
700 | #else |
701 | static inline int pci_dev_specific_acs_enabled(struct pci_dev *dev, | |
702 | u16 acs_flags) | |
703 | { | |
704 | return -ENOTTY; | |
705 | } | |
706 | static inline int pci_dev_specific_enable_acs(struct pci_dev *dev) | |
707 | { | |
708 | return -ENOTTY; | |
709 | } | |
73c47dde LG |
710 | static inline int pci_dev_specific_disable_acs_redir(struct pci_dev *dev) |
711 | { | |
712 | return -ENOTTY; | |
713 | } | |
59100eb2 | 714 | static inline int pcie_failed_link_retrain(struct pci_dev *dev) |
a89c8224 | 715 | { |
59100eb2 | 716 | return -ENOTTY; |
a89c8224 | 717 | } |
bd2e9567 | 718 | #endif |
ae21ee65 | 719 | |
2e28bc84 | 720 | /* PCI error reporting and recovery */ |
e8e5ff2a | 721 | pci_ers_result_t pcie_do_recovery(struct pci_dev *dev, |
8f1bbfbc SK |
722 | pci_channel_state_t state, |
723 | pci_ers_result_t (*reset_subordinates)(struct pci_dev *pdev)); | |
2e28bc84 | 724 | |
9f5a70f1 | 725 | bool pcie_wait_for_link(struct pci_dev *pdev, bool active); |
1abb4739 | 726 | int pcie_retrain_link(struct pci_dev *pdev, bool use_lt); |
1e11b549 DB |
727 | |
728 | /* ASPM-related functionality we need even without CONFIG_PCIEASPM */ | |
729 | void pci_save_ltr_state(struct pci_dev *dev); | |
730 | void pci_restore_ltr_state(struct pci_dev *dev); | |
17423360 DB |
731 | void pci_configure_aspm_l1ss(struct pci_dev *dev); |
732 | void pci_save_aspm_l1ss_state(struct pci_dev *dev); | |
733 | void pci_restore_aspm_l1ss_state(struct pci_dev *dev); | |
1e11b549 | 734 | |
7d8e7d19 BH |
735 | #ifdef CONFIG_PCIEASPM |
736 | void pcie_aspm_init_link_state(struct pci_dev *pdev); | |
737 | void pcie_aspm_exit_link_state(struct pci_dev *pdev); | |
1e560864 | 738 | void pcie_aspm_pm_state_change(struct pci_dev *pdev, bool locked); |
7d8e7d19 | 739 | void pcie_aspm_powersave_config_link(struct pci_dev *pdev); |
fa84f443 DB |
740 | void pci_configure_ltr(struct pci_dev *pdev); |
741 | void pci_bridge_reconfigure_ltr(struct pci_dev *pdev); | |
7d8e7d19 BH |
742 | #else |
743 | static inline void pcie_aspm_init_link_state(struct pci_dev *pdev) { } | |
744 | static inline void pcie_aspm_exit_link_state(struct pci_dev *pdev) { } | |
1e560864 | 745 | static inline void pcie_aspm_pm_state_change(struct pci_dev *pdev, bool locked) { } |
7d8e7d19 | 746 | static inline void pcie_aspm_powersave_config_link(struct pci_dev *pdev) { } |
fa84f443 DB |
747 | static inline void pci_configure_ltr(struct pci_dev *pdev) { } |
748 | static inline void pci_bridge_reconfigure_ltr(struct pci_dev *pdev) { } | |
7d8e7d19 BH |
749 | #endif |
750 | ||
72bde9ce KS |
751 | #ifdef CONFIG_PCIE_ECRC |
752 | void pcie_set_ecrc_checking(struct pci_dev *dev); | |
753 | void pcie_ecrc_get_policy(char *str); | |
754 | #else | |
755 | static inline void pcie_set_ecrc_checking(struct pci_dev *dev) { } | |
756 | static inline void pcie_ecrc_get_policy(char *str) { } | |
757 | #endif | |
758 | ||
665745f2 IJ |
759 | #ifdef CONFIG_PCIEPORTBUS |
760 | void pcie_reset_lbms_count(struct pci_dev *port); | |
761 | int pcie_lbms_count(struct pci_dev *port, unsigned long *val); | |
762 | #else | |
763 | static inline void pcie_reset_lbms_count(struct pci_dev *port) {} | |
764 | static inline int pcie_lbms_count(struct pci_dev *port, unsigned long *val) | |
765 | { | |
766 | return -EOPNOTSUPP; | |
767 | } | |
768 | #endif | |
769 | ||
b9c3b266 DC |
770 | struct pci_dev_reset_methods { |
771 | u16 vendor; | |
772 | u16 device; | |
9bdc81ce | 773 | int (*reset)(struct pci_dev *dev, bool probe); |
b9c3b266 DC |
774 | }; |
775 | ||
e20afa06 | 776 | struct pci_reset_fn_method { |
9bdc81ce | 777 | int (*reset_fn)(struct pci_dev *pdev, bool probe); |
e20afa06 | 778 | char *name; |
b9c3b266 | 779 | }; |
10269d57 | 780 | extern const struct pci_reset_fn_method pci_reset_fn_methods[]; |
b9c3b266 | 781 | |
93177a74 | 782 | #ifdef CONFIG_PCI_QUIRKS |
9bdc81ce | 783 | int pci_dev_specific_reset(struct pci_dev *dev, bool probe); |
93177a74 | 784 | #else |
9bdc81ce | 785 | static inline int pci_dev_specific_reset(struct pci_dev *dev, bool probe) |
93177a74 RW |
786 | { |
787 | return -ENOTTY; | |
788 | } | |
789 | #endif | |
b9c3b266 | 790 | |
169de969 DL |
791 | #if defined(CONFIG_PCI_QUIRKS) && defined(CONFIG_ARM64) |
792 | int acpi_get_rc_resources(struct device *dev, const char *hid, u16 segment, | |
793 | struct resource *res); | |
16f7ae59 AB |
794 | #else |
795 | static inline int acpi_get_rc_resources(struct device *dev, const char *hid, | |
796 | u16 segment, struct resource *res) | |
797 | { | |
798 | return -ENODEV; | |
799 | } | |
169de969 DL |
800 | #endif |
801 | ||
276b738d CK |
802 | int pci_rebar_get_current_size(struct pci_dev *pdev, int bar); |
803 | int pci_rebar_set_size(struct pci_dev *pdev, int bar, int size); | |
804 | static inline u64 pci_rebar_size_to_bytes(int size) | |
805 | { | |
806 | return 1ULL << (size + 20); | |
807 | } | |
808 | ||
9e2aee80 RH |
809 | struct device_node; |
810 | ||
811 | #ifdef CONFIG_OF | |
9e2aee80 RH |
812 | int of_get_pci_domain_nr(struct device_node *node); |
813 | int of_pci_get_max_link_speed(struct device_node *node); | |
35662423 PR |
814 | u32 of_pci_get_slot_power_limit(struct device_node *node, |
815 | u8 *slot_power_limit_value, | |
816 | u8 *slot_power_limit_scale); | |
407abde9 | 817 | bool of_pci_preserve_config(struct device_node *node); |
0d21e71a | 818 | int pci_set_of_node(struct pci_dev *dev); |
621f7e35 KS |
819 | void pci_release_of_node(struct pci_dev *dev); |
820 | void pci_set_bus_of_node(struct pci_bus *bus); | |
821 | void pci_release_bus_of_node(struct pci_bus *bus); | |
9e2aee80 | 822 | |
669cbc70 | 823 | int devm_of_pci_bridge_init(struct device *dev, struct pci_host_bridge *bridge); |
278dd091 | 824 | bool of_pci_supply_present(struct device_node *np); |
669cbc70 | 825 | |
9e2aee80 | 826 | #else |
9e2aee80 RH |
827 | static inline int |
828 | of_get_pci_domain_nr(struct device_node *node) | |
829 | { | |
830 | return -1; | |
831 | } | |
832 | ||
833 | static inline int | |
834 | of_pci_get_max_link_speed(struct device_node *node) | |
835 | { | |
836 | return -EINVAL; | |
837 | } | |
621f7e35 | 838 | |
35662423 PR |
839 | static inline u32 |
840 | of_pci_get_slot_power_limit(struct device_node *node, | |
841 | u8 *slot_power_limit_value, | |
842 | u8 *slot_power_limit_scale) | |
843 | { | |
844 | if (slot_power_limit_value) | |
845 | *slot_power_limit_value = 0; | |
846 | if (slot_power_limit_scale) | |
847 | *slot_power_limit_scale = 0; | |
848 | return 0; | |
849 | } | |
850 | ||
407abde9 VS |
851 | static inline bool of_pci_preserve_config(struct device_node *node) |
852 | { | |
853 | return false; | |
854 | } | |
855 | ||
0d21e71a | 856 | static inline int pci_set_of_node(struct pci_dev *dev) { return 0; } |
621f7e35 KS |
857 | static inline void pci_release_of_node(struct pci_dev *dev) { } |
858 | static inline void pci_set_bus_of_node(struct pci_bus *bus) { } | |
859 | static inline void pci_release_bus_of_node(struct pci_bus *bus) { } | |
669cbc70 RH |
860 | |
861 | static inline int devm_of_pci_bridge_init(struct device *dev, struct pci_host_bridge *bridge) | |
862 | { | |
863 | return 0; | |
864 | } | |
865 | ||
278dd091 MS |
866 | static inline bool of_pci_supply_present(struct device_node *np) |
867 | { | |
868 | return false; | |
869 | } | |
9e2aee80 RH |
870 | #endif /* CONFIG_OF */ |
871 | ||
407d1a51 LH |
872 | struct of_changeset; |
873 | ||
874 | #ifdef CONFIG_PCI_DYNAMIC_OF_NODES | |
875 | void of_pci_make_dev_node(struct pci_dev *pdev); | |
876 | void of_pci_remove_node(struct pci_dev *pdev); | |
877 | int of_pci_add_properties(struct pci_dev *pdev, struct of_changeset *ocs, | |
878 | struct device_node *np); | |
879 | #else | |
880 | static inline void of_pci_make_dev_node(struct pci_dev *pdev) { } | |
881 | static inline void of_pci_remove_node(struct pci_dev *pdev) { } | |
882 | #endif | |
883 | ||
60ed982a RJ |
884 | #ifdef CONFIG_PCIEAER |
885 | void pci_no_aer(void); | |
886 | void pci_aer_init(struct pci_dev *dev); | |
db89ccbe | 887 | void pci_aer_exit(struct pci_dev *dev); |
81aa5206 | 888 | extern const struct attribute_group aer_stats_attr_group; |
7ab92e89 | 889 | void pci_aer_clear_fatal_status(struct pci_dev *dev); |
894020fd | 890 | int pci_aer_clear_status(struct pci_dev *dev); |
20e15e67 | 891 | int pci_aer_raw_clear_status(struct pci_dev *dev); |
ba3da667 BH |
892 | void pci_save_aer_state(struct pci_dev *dev); |
893 | void pci_restore_aer_state(struct pci_dev *dev); | |
60ed982a RJ |
894 | #else |
895 | static inline void pci_no_aer(void) { } | |
31f996ef | 896 | static inline void pci_aer_init(struct pci_dev *d) { } |
db89ccbe | 897 | static inline void pci_aer_exit(struct pci_dev *d) { } |
7ab92e89 | 898 | static inline void pci_aer_clear_fatal_status(struct pci_dev *dev) { } |
894020fd | 899 | static inline int pci_aer_clear_status(struct pci_dev *dev) { return -EINVAL; } |
20e15e67 | 900 | static inline int pci_aer_raw_clear_status(struct pci_dev *dev) { return -EINVAL; } |
ba3da667 BH |
901 | static inline void pci_save_aer_state(struct pci_dev *dev) { } |
902 | static inline void pci_restore_aer_state(struct pci_dev *dev) { } | |
60ed982a RJ |
903 | #endif |
904 | ||
8c3aac6e | 905 | #ifdef CONFIG_ACPI |
9d7d5db8 | 906 | bool pci_acpi_preserve_config(struct pci_host_bridge *bridge); |
4a2dbedd | 907 | int pci_acpi_program_hp_params(struct pci_dev *dev); |
506140f9 | 908 | extern const struct attribute_group pci_dev_acpi_attr_group; |
3a15955d | 909 | void pci_set_acpi_fwnode(struct pci_dev *dev); |
9bdc81ce | 910 | int pci_dev_acpi_reset(struct pci_dev *dev, bool probe); |
d97c5d4c RW |
911 | bool acpi_pci_power_manageable(struct pci_dev *dev); |
912 | bool acpi_pci_bridge_d3(struct pci_dev *dev); | |
913 | int acpi_pci_set_power_state(struct pci_dev *dev, pci_power_t state); | |
914 | pci_power_t acpi_pci_get_power_state(struct pci_dev *dev); | |
915 | void acpi_pci_refresh_power_state(struct pci_dev *dev); | |
916 | int acpi_pci_wakeup(struct pci_dev *dev, bool enable); | |
917 | bool acpi_pci_need_resume(struct pci_dev *dev); | |
918 | pci_power_t acpi_pci_choose_state(struct pci_dev *pdev); | |
8c3aac6e | 919 | #else |
9d7d5db8 VS |
920 | static inline bool pci_acpi_preserve_config(struct pci_host_bridge *bridge) |
921 | { | |
922 | return false; | |
923 | } | |
9bdc81ce | 924 | static inline int pci_dev_acpi_reset(struct pci_dev *dev, bool probe) |
6937b7dd SD |
925 | { |
926 | return -ENOTTY; | |
927 | } | |
eb6723b4 | 928 | static inline void pci_set_acpi_fwnode(struct pci_dev *dev) { } |
4a2dbedd | 929 | static inline int pci_acpi_program_hp_params(struct pci_dev *dev) |
8c3aac6e KW |
930 | { |
931 | return -ENODEV; | |
932 | } | |
d97c5d4c RW |
933 | static inline bool acpi_pci_power_manageable(struct pci_dev *dev) |
934 | { | |
935 | return false; | |
936 | } | |
937 | static inline bool acpi_pci_bridge_d3(struct pci_dev *dev) | |
938 | { | |
939 | return false; | |
940 | } | |
941 | static inline int acpi_pci_set_power_state(struct pci_dev *dev, pci_power_t state) | |
942 | { | |
943 | return -ENODEV; | |
944 | } | |
945 | static inline pci_power_t acpi_pci_get_power_state(struct pci_dev *dev) | |
946 | { | |
947 | return PCI_UNKNOWN; | |
948 | } | |
eb6723b4 | 949 | static inline void acpi_pci_refresh_power_state(struct pci_dev *dev) { } |
d97c5d4c RW |
950 | static inline int acpi_pci_wakeup(struct pci_dev *dev, bool enable) |
951 | { | |
952 | return -ENODEV; | |
953 | } | |
954 | static inline bool acpi_pci_need_resume(struct pci_dev *dev) | |
955 | { | |
956 | return false; | |
957 | } | |
958 | static inline pci_power_t acpi_pci_choose_state(struct pci_dev *pdev) | |
959 | { | |
960 | return PCI_POWER_ERROR; | |
961 | } | |
8c3aac6e KW |
962 | #endif |
963 | ||
72ea91af HK |
964 | #ifdef CONFIG_PCIEASPM |
965 | extern const struct attribute_group aspm_ctrl_attr_group; | |
966 | #endif | |
967 | ||
d5b0d883 RW |
968 | #ifdef CONFIG_X86_INTEL_MID |
969 | bool pci_use_mid_pm(void); | |
970 | int mid_pci_set_power_state(struct pci_dev *pdev, pci_power_t state); | |
971 | pci_power_t mid_pci_get_power_state(struct pci_dev *pdev); | |
972 | #else | |
973 | static inline bool pci_use_mid_pm(void) | |
974 | { | |
975 | return false; | |
976 | } | |
977 | static inline int mid_pci_set_power_state(struct pci_dev *pdev, pci_power_t state) | |
978 | { | |
979 | return -ENODEV; | |
980 | } | |
981 | static inline pci_power_t mid_pci_get_power_state(struct pci_dev *pdev) | |
982 | { | |
983 | return PCI_UNKNOWN; | |
984 | } | |
985 | #endif | |
986 | ||
25216afc | 987 | int pcim_intx(struct pci_dev *dev, int enable); |
d47bde70 PS |
988 | int pcim_request_region_exclusive(struct pci_dev *pdev, int bar, |
989 | const char *name); | |
990 | void pcim_release_region(struct pci_dev *pdev, int bar); | |
991 | ||
8a9b7ef7 PR |
992 | /* |
993 | * Config Address for PCI Configuration Mechanism #1 | |
994 | * | |
995 | * See PCI Local Bus Specification, Revision 3.0, | |
996 | * Section 3.2.2.3.2, Figure 3-2, p. 50. | |
997 | */ | |
998 | ||
999 | #define PCI_CONF1_BUS_SHIFT 16 /* Bus number */ | |
1000 | #define PCI_CONF1_DEV_SHIFT 11 /* Device number */ | |
1001 | #define PCI_CONF1_FUNC_SHIFT 8 /* Function number */ | |
1002 | ||
1003 | #define PCI_CONF1_BUS_MASK 0xff | |
1004 | #define PCI_CONF1_DEV_MASK 0x1f | |
1005 | #define PCI_CONF1_FUNC_MASK 0x7 | |
1006 | #define PCI_CONF1_REG_MASK 0xfc /* Limit aligned offset to a maximum of 256B */ | |
1007 | ||
1008 | #define PCI_CONF1_ENABLE BIT(31) | |
1009 | #define PCI_CONF1_BUS(x) (((x) & PCI_CONF1_BUS_MASK) << PCI_CONF1_BUS_SHIFT) | |
1010 | #define PCI_CONF1_DEV(x) (((x) & PCI_CONF1_DEV_MASK) << PCI_CONF1_DEV_SHIFT) | |
1011 | #define PCI_CONF1_FUNC(x) (((x) & PCI_CONF1_FUNC_MASK) << PCI_CONF1_FUNC_SHIFT) | |
1012 | #define PCI_CONF1_REG(x) ((x) & PCI_CONF1_REG_MASK) | |
1013 | ||
1014 | #define PCI_CONF1_ADDRESS(bus, dev, func, reg) \ | |
1015 | (PCI_CONF1_ENABLE | \ | |
1016 | PCI_CONF1_BUS(bus) | \ | |
1017 | PCI_CONF1_DEV(dev) | \ | |
1018 | PCI_CONF1_FUNC(func) | \ | |
1019 | PCI_CONF1_REG(reg)) | |
1020 | ||
1021 | /* | |
1022 | * Extension of PCI Config Address for accessing extended PCIe registers | |
1023 | * | |
1024 | * No standardized specification, but used on lot of non-ECAM-compliant ARM SoCs | |
1025 | * or on AMD Barcelona and new CPUs. Reserved bits [27:24] of PCI Config Address | |
1026 | * are used for specifying additional 4 high bits of PCI Express register. | |
1027 | */ | |
1028 | ||
1029 | #define PCI_CONF1_EXT_REG_SHIFT 16 | |
1030 | #define PCI_CONF1_EXT_REG_MASK 0xf00 | |
1031 | #define PCI_CONF1_EXT_REG(x) (((x) & PCI_CONF1_EXT_REG_MASK) << PCI_CONF1_EXT_REG_SHIFT) | |
1032 | ||
1033 | #define PCI_CONF1_EXT_ADDRESS(bus, dev, func, reg) \ | |
1034 | (PCI_CONF1_ADDRESS(bus, dev, func, reg) | \ | |
1035 | PCI_CONF1_EXT_REG(reg)) | |
1036 | ||
557848c3 | 1037 | #endif /* DRIVERS_PCI_H */ |