]>
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 | ||
f8bf2aeb JS |
7 | /* Number of possible devfns: 0.0 to 1f.7 inclusive */ |
8 | #define MAX_NR_DEVFNS 256 | |
9 | ||
fff905f3 WY |
10 | #define PCI_FIND_CAP_TTL 48 |
11 | ||
8531e283 LW |
12 | #define PCI_VSEC_ID_INTEL_TBT 0x1234 /* Thunderbolt */ |
13 | ||
343e51ae | 14 | extern const unsigned char pcie_link_speed[]; |
11eb0e0e | 15 | extern bool pci_early_dump; |
343e51ae | 16 | |
7a1562d4 | 17 | bool pcie_cap_has_lnkctl(const struct pci_dev *dev); |
af65d1ad | 18 | bool pcie_cap_has_rtctl(const struct pci_dev *dev); |
7a1562d4 | 19 | |
1da177e4 LT |
20 | /* Functions internal to the PCI core code */ |
21 | ||
f39d5b72 BH |
22 | int pci_create_sysfs_dev_files(struct pci_dev *pdev); |
23 | void pci_remove_sysfs_dev_files(struct pci_dev *pdev); | |
6058989b | 24 | #if !defined(CONFIG_DMI) && !defined(CONFIG_ACPI) |
911e1c9b | 25 | static inline void pci_create_firmware_label_files(struct pci_dev *pdev) |
b879743f | 26 | { return; } |
911e1c9b | 27 | static inline void pci_remove_firmware_label_files(struct pci_dev *pdev) |
b879743f | 28 | { return; } |
911e1c9b | 29 | #else |
f39d5b72 BH |
30 | void pci_create_firmware_label_files(struct pci_dev *pdev); |
31 | void pci_remove_firmware_label_files(struct pci_dev *pdev); | |
911e1c9b | 32 | #endif |
f39d5b72 | 33 | void pci_cleanup_rom(struct pci_dev *dev); |
f7195824 | 34 | |
3b519e4e MW |
35 | enum pci_mmap_api { |
36 | PCI_MMAP_SYSFS, /* mmap on /sys/bus/pci/devices/<BDF>/resource<N> */ | |
37 | PCI_MMAP_PROCFS /* mmap on /proc/bus/pci/<BDF> */ | |
38 | }; | |
f39d5b72 BH |
39 | int pci_mmap_fits(struct pci_dev *pdev, int resno, struct vm_area_struct *vmai, |
40 | enum pci_mmap_api mmap_api); | |
f7195824 | 41 | |
711d5779 | 42 | int pci_probe_reset_function(struct pci_dev *dev); |
381634ca | 43 | int pci_bridge_secondary_bus_reset(struct pci_dev *dev); |
c4eed62a | 44 | int pci_bus_error_reset(struct pci_dev *dev); |
ce5ccdef | 45 | |
638c133e BH |
46 | #define PCI_PM_D2_DELAY 200 /* usec; see PCIe r4.0, sec 5.9.1 */ |
47 | #define PCI_PM_D3HOT_WAIT 10 /* msec */ | |
48 | #define PCI_PM_D3COLD_WAIT 100 /* msec */ | |
c776dd50 | 49 | |
961d9120 | 50 | /** |
b33bfdef | 51 | * struct pci_platform_pm_ops - Firmware PM callbacks |
961d9120 | 52 | * |
26ad34d5 MW |
53 | * @bridge_d3: Does the bridge allow entering into D3 |
54 | * | |
b33bfdef | 55 | * @is_manageable: returns 'true' if given device is power manageable by the |
0aa0f5d1 | 56 | * platform firmware |
961d9120 | 57 | * |
b33bfdef | 58 | * @set_state: invokes the platform firmware to set the device's power state |
961d9120 | 59 | * |
cc7cc02b LW |
60 | * @get_state: queries the platform firmware for a device's current power state |
61 | * | |
b51033e0 RW |
62 | * @refresh_state: asks the platform to refresh the device's power state data |
63 | * | |
b33bfdef | 64 | * @choose_state: returns PCI power state of given device preferred by the |
0aa0f5d1 BH |
65 | * platform; to be used during system-wide transitions from a |
66 | * sleeping state to the working state and vice versa | |
961d9120 | 67 | * |
0847684c | 68 | * @set_wakeup: enables/disables wakeup capability for the device |
b67ea761 | 69 | * |
bac2a909 | 70 | * @need_resume: returns 'true' if the given device (which is currently |
0aa0f5d1 BH |
71 | * suspended) needs to be resumed to be configured for system |
72 | * wakeup. | |
bac2a909 | 73 | * |
961d9120 RW |
74 | * If given platform is generally capable of power managing PCI devices, all of |
75 | * these callbacks are mandatory. | |
76 | */ | |
77 | struct pci_platform_pm_ops { | |
26ad34d5 | 78 | bool (*bridge_d3)(struct pci_dev *dev); |
961d9120 RW |
79 | bool (*is_manageable)(struct pci_dev *dev); |
80 | int (*set_state)(struct pci_dev *dev, pci_power_t state); | |
cc7cc02b | 81 | pci_power_t (*get_state)(struct pci_dev *dev); |
b51033e0 | 82 | void (*refresh_state)(struct pci_dev *dev); |
961d9120 | 83 | pci_power_t (*choose_state)(struct pci_dev *dev); |
0847684c | 84 | int (*set_wakeup)(struct pci_dev *dev, bool enable); |
bac2a909 | 85 | bool (*need_resume)(struct pci_dev *dev); |
961d9120 RW |
86 | }; |
87 | ||
299f2ffe | 88 | int pci_set_platform_pm(const struct pci_platform_pm_ops *ops); |
f39d5b72 | 89 | void pci_update_current_state(struct pci_dev *dev, pci_power_t state); |
b51033e0 | 90 | void pci_refresh_power_state(struct pci_dev *dev); |
adfac8f6 | 91 | int pci_power_up(struct pci_dev *dev); |
f39d5b72 BH |
92 | void pci_disable_enabled_device(struct pci_dev *dev); |
93 | int pci_finish_runtime_suspend(struct pci_dev *dev); | |
600a5b4f | 94 | void pcie_clear_device_status(struct pci_dev *dev); |
dcb0453d | 95 | void pcie_clear_root_pme_status(struct pci_dev *dev); |
669696eb KS |
96 | bool pci_check_pme_status(struct pci_dev *dev); |
97 | void pci_pme_wakeup_bus(struct pci_bus *bus); | |
f39d5b72 | 98 | int __pci_pme_wakeup(struct pci_dev *dev, void *ign); |
0ce3fcaf | 99 | void pci_pme_restore(struct pci_dev *dev); |
0c7376ad RW |
100 | bool pci_dev_need_resume(struct pci_dev *dev); |
101 | void pci_dev_adjust_pme(struct pci_dev *dev); | |
2cef548a | 102 | void pci_dev_complete_resume(struct pci_dev *pci_dev); |
f39d5b72 BH |
103 | void pci_config_pm_runtime_get(struct pci_dev *dev); |
104 | void pci_config_pm_runtime_put(struct pci_dev *dev); | |
105 | void pci_pm_init(struct pci_dev *dev); | |
938174e5 | 106 | void pci_ea_init(struct pci_dev *dev); |
cbc40d5c BH |
107 | void pci_msi_init(struct pci_dev *dev); |
108 | void pci_msix_init(struct pci_dev *dev); | |
f39d5b72 | 109 | void pci_allocate_cap_save_buffers(struct pci_dev *dev); |
f796841e | 110 | void pci_free_cap_save_buffers(struct pci_dev *dev); |
c6a63307 | 111 | bool pci_bridge_d3_possible(struct pci_dev *dev); |
1ed276a7 | 112 | void pci_bridge_d3_update(struct pci_dev *dev); |
ad9001f2 | 113 | void pci_bridge_wait_for_secondary_bus(struct pci_dev *dev); |
aa8c6c93 | 114 | |
b6e335ae RW |
115 | static inline void pci_wakeup_event(struct pci_dev *dev) |
116 | { | |
117 | /* Wait 100 ms before the system can be put into a sleep state. */ | |
118 | pm_wakeup_event(&dev->dev, 100); | |
119 | } | |
120 | ||
326c1cda | 121 | static inline bool pci_has_subordinate(struct pci_dev *pci_dev) |
aa8c6c93 RW |
122 | { |
123 | return !!(pci_dev->subordinate); | |
124 | } | |
0f64474b | 125 | |
9d26d3a8 MW |
126 | static inline bool pci_power_manageable(struct pci_dev *pci_dev) |
127 | { | |
128 | /* | |
129 | * Currently we allow normal PCI devices and PCI bridges transition | |
130 | * into D3 if their bridge_d3 is set. | |
131 | */ | |
132 | return !pci_has_subordinate(pci_dev) || pci_dev->bridge_d3; | |
133 | } | |
134 | ||
984998e3 MW |
135 | static inline bool pcie_downstream_port(const struct pci_dev *dev) |
136 | { | |
137 | int type = pci_pcie_type(dev); | |
138 | ||
139 | return type == PCI_EXP_TYPE_ROOT_PORT || | |
140 | type == PCI_EXP_TYPE_DOWNSTREAM || | |
141 | type == PCI_EXP_TYPE_PCIE_BRIDGE; | |
142 | } | |
143 | ||
f1cd93f9 | 144 | int pci_vpd_init(struct pci_dev *dev); |
64379079 | 145 | void pci_vpd_release(struct pci_dev *dev); |
b1c615c4 BH |
146 | void pcie_vpd_create_sysfs_dev_files(struct pci_dev *dev); |
147 | void pcie_vpd_remove_sysfs_dev_files(struct pci_dev *dev); | |
94e61088 | 148 | |
440589dd KS |
149 | /* PCI Virtual Channel */ |
150 | int pci_save_vc_state(struct pci_dev *dev); | |
151 | void pci_restore_vc_state(struct pci_dev *dev); | |
152 | void pci_allocate_vc_save_buffers(struct pci_dev *dev); | |
153 | ||
1da177e4 LT |
154 | /* PCI /proc functions */ |
155 | #ifdef CONFIG_PROC_FS | |
f39d5b72 BH |
156 | int pci_proc_attach_device(struct pci_dev *dev); |
157 | int pci_proc_detach_device(struct pci_dev *dev); | |
158 | int pci_proc_detach_bus(struct pci_bus *bus); | |
1da177e4 LT |
159 | #else |
160 | static inline int pci_proc_attach_device(struct pci_dev *dev) { return 0; } | |
161 | static inline int pci_proc_detach_device(struct pci_dev *dev) { return 0; } | |
1da177e4 LT |
162 | static inline int pci_proc_detach_bus(struct pci_bus *bus) { return 0; } |
163 | #endif | |
164 | ||
165 | /* Functions for PCI Hotplug drivers to use */ | |
a8e4b9c1 | 166 | int pci_hp_add_bridge(struct pci_dev *dev); |
1da177e4 | 167 | |
f19aeb1f | 168 | #ifdef HAVE_PCI_LEGACY |
f39d5b72 BH |
169 | void pci_create_legacy_files(struct pci_bus *bus); |
170 | void pci_remove_legacy_files(struct pci_bus *bus); | |
f19aeb1f BH |
171 | #else |
172 | static inline void pci_create_legacy_files(struct pci_bus *bus) { return; } | |
173 | static inline void pci_remove_legacy_files(struct pci_bus *bus) { return; } | |
174 | #endif | |
1da177e4 LT |
175 | |
176 | /* Lock for read/write access to pci device and bus lists */ | |
d71374da | 177 | extern struct rw_semaphore pci_bus_sem; |
c4eed62a | 178 | extern struct mutex pci_slot_mutex; |
1da177e4 | 179 | |
a2e27787 JK |
180 | extern raw_spinlock_t pci_lock; |
181 | ||
3789af9a | 182 | extern unsigned int pci_pm_d3hot_delay; |
88187dfa | 183 | |
4b47b0ee | 184 | #ifdef CONFIG_PCI_MSI |
309e57df | 185 | void pci_no_msi(void); |
4b47b0ee | 186 | #else |
309e57df | 187 | static inline void pci_no_msi(void) { } |
4b47b0ee | 188 | #endif |
8fed4b65 | 189 | |
b55438fd | 190 | void pci_realloc_get_opt(char *); |
f483d392 | 191 | |
ffadcc2f KCA |
192 | static inline int pci_no_d1d2(struct pci_dev *dev) |
193 | { | |
194 | unsigned int parent_dstates = 0; | |
4b47b0ee | 195 | |
ffadcc2f KCA |
196 | if (dev->bus->self) |
197 | parent_dstates = dev->bus->self->no_d1d2; | |
198 | return (dev->no_d1d2 || parent_dstates); | |
199 | ||
200 | } | |
5136b2da | 201 | extern const struct attribute_group *pci_dev_groups[]; |
56039e65 | 202 | extern const struct attribute_group *pcibus_groups[]; |
69f2dc24 | 203 | extern const struct device_type pci_dev_type; |
0f49ba55 | 204 | extern const struct attribute_group *pci_bus_groups[]; |
705b1aaa | 205 | |
003d3b2c | 206 | extern unsigned long pci_hotplug_io_size; |
d7b8a217 NJ |
207 | extern unsigned long pci_hotplug_mmio_size; |
208 | extern unsigned long pci_hotplug_mmio_pref_size; | |
003d3b2c | 209 | extern unsigned long pci_hotplug_bus_size; |
1da177e4 LT |
210 | |
211 | /** | |
212 | * pci_match_one_device - Tell if a PCI device structure has a matching | |
0aa0f5d1 | 213 | * PCI device id structure |
1da177e4 LT |
214 | * @id: single PCI device id structure to match |
215 | * @dev: the PCI device structure to match against | |
367b09fe | 216 | * |
1da177e4 LT |
217 | * Returns the matching pci_device_id structure or %NULL if there is no match. |
218 | */ | |
219 | static inline const struct pci_device_id * | |
220 | pci_match_one_device(const struct pci_device_id *id, const struct pci_dev *dev) | |
221 | { | |
222 | if ((id->vendor == PCI_ANY_ID || id->vendor == dev->vendor) && | |
223 | (id->device == PCI_ANY_ID || id->device == dev->device) && | |
224 | (id->subvendor == PCI_ANY_ID || id->subvendor == dev->subsystem_vendor) && | |
225 | (id->subdevice == PCI_ANY_ID || id->subdevice == dev->subsystem_device) && | |
226 | !((id->class ^ dev->class) & id->class_mask)) | |
227 | return id; | |
228 | return NULL; | |
229 | } | |
230 | ||
f46753c5 AC |
231 | /* PCI slot sysfs helper code */ |
232 | #define to_pci_slot(s) container_of(s, struct pci_slot, kobj) | |
233 | ||
234 | extern struct kset *pci_slots_kset; | |
235 | ||
236 | struct pci_slot_attribute { | |
237 | struct attribute attr; | |
238 | ssize_t (*show)(struct pci_slot *, char *); | |
239 | ssize_t (*store)(struct pci_slot *, const char *, size_t); | |
240 | }; | |
241 | #define to_pci_slot_attr(s) container_of(s, struct pci_slot_attribute, attr) | |
242 | ||
0b400c7e YZ |
243 | enum pci_bar_type { |
244 | pci_bar_unknown, /* Standard PCI BAR probe */ | |
0aa0f5d1 | 245 | pci_bar_io, /* An I/O port BAR */ |
0b400c7e YZ |
246 | pci_bar_mem32, /* A 32-bit memory BAR */ |
247 | pci_bar_mem64, /* A 64-bit memory BAR */ | |
248 | }; | |
249 | ||
975e1ac1 KS |
250 | struct device *pci_get_host_bridge_device(struct pci_dev *dev); |
251 | void pci_put_host_bridge_device(struct device *dev); | |
252 | ||
62ce94a7 | 253 | int pci_configure_extended_tags(struct pci_dev *dev, void *ign); |
efdc87da YL |
254 | bool pci_bus_read_dev_vendor_id(struct pci_bus *bus, int devfn, u32 *pl, |
255 | int crs_timeout); | |
aa667c64 JP |
256 | bool pci_bus_generic_read_dev_vendor_id(struct pci_bus *bus, int devfn, u32 *pl, |
257 | int crs_timeout); | |
258 | int pci_idt_bus_quirk(struct pci_bus *bus, int devfn, u32 *pl, int crs_timeout); | |
259 | ||
f39d5b72 BH |
260 | int pci_setup_device(struct pci_dev *dev); |
261 | int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type, | |
262 | struct resource *res, unsigned int reg); | |
f39d5b72 | 263 | void pci_configure_ari(struct pci_dev *dev); |
10874f5a | 264 | void __pci_bus_size_bridges(struct pci_bus *bus, |
d66ecb72 | 265 | struct list_head *realloc_head); |
10874f5a BH |
266 | void __pci_bus_assign_resources(const struct pci_bus *bus, |
267 | struct list_head *realloc_head, | |
268 | struct list_head *fail_head); | |
0f7e7aee | 269 | bool pci_bus_clip_resource(struct pci_dev *dev, int idx); |
939de1d6 | 270 | |
2069ecfb | 271 | void pci_reassigndev_resource_alignment(struct pci_dev *dev); |
f39d5b72 | 272 | void pci_disable_bridge_window(struct pci_dev *dev); |
ecd29c1a KS |
273 | struct pci_bus *pci_bus_get(struct pci_bus *bus); |
274 | void pci_bus_put(struct pci_bus *bus); | |
32a9a682 | 275 | |
757bfaa2 YY |
276 | /* PCIe link information from Link Capabilities 2 */ |
277 | #define PCIE_LNKCAP2_SLS2SPEED(lnkcap2) \ | |
34191749 GP |
278 | ((lnkcap2) & PCI_EXP_LNKCAP2_SLS_64_0GB ? PCIE_SPEED_64_0GT : \ |
279 | (lnkcap2) & PCI_EXP_LNKCAP2_SLS_32_0GB ? PCIE_SPEED_32_0GT : \ | |
757bfaa2 YY |
280 | (lnkcap2) & PCI_EXP_LNKCAP2_SLS_16_0GB ? PCIE_SPEED_16_0GT : \ |
281 | (lnkcap2) & PCI_EXP_LNKCAP2_SLS_8_0GB ? PCIE_SPEED_8_0GT : \ | |
282 | (lnkcap2) & PCI_EXP_LNKCAP2_SLS_5_0GB ? PCIE_SPEED_5_0GT : \ | |
283 | (lnkcap2) & PCI_EXP_LNKCAP2_SLS_2_5GB ? PCIE_SPEED_2_5GT : \ | |
284 | PCI_SPEED_UNKNOWN) | |
6cf57be0 | 285 | |
b852f63a TG |
286 | /* PCIe speed to Mb/s reduced by encoding overhead */ |
287 | #define PCIE_SPEED2MBS_ENC(speed) \ | |
34191749 GP |
288 | ((speed) == PCIE_SPEED_64_0GT ? 64000*128/130 : \ |
289 | (speed) == PCIE_SPEED_32_0GT ? 32000*128/130 : \ | |
9cb3985a | 290 | (speed) == PCIE_SPEED_16_0GT ? 16000*128/130 : \ |
b852f63a TG |
291 | (speed) == PCIE_SPEED_8_0GT ? 8000*128/130 : \ |
292 | (speed) == PCIE_SPEED_5_0GT ? 5000*8/10 : \ | |
293 | (speed) == PCIE_SPEED_2_5GT ? 2500*8/10 : \ | |
294 | 0) | |
295 | ||
e56faff5 | 296 | const char *pci_speed_string(enum pci_bus_speed speed); |
6cf57be0 | 297 | enum pci_bus_speed pcie_get_speed_cap(struct pci_dev *dev); |
c70b65fb | 298 | enum pcie_link_width pcie_get_width_cap(struct pci_dev *dev); |
b852f63a TG |
299 | u32 pcie_bandwidth_capable(struct pci_dev *dev, enum pci_bus_speed *speed, |
300 | enum pcie_link_width *width); | |
2d1ce5ec | 301 | void __pcie_print_link_status(struct pci_dev *dev, bool verbose); |
0fa635ae | 302 | void pcie_report_downtraining(struct pci_dev *dev); |
5da78d95 | 303 | void pcie_update_link_speed(struct pci_bus *bus, u16 link_status); |
6cf57be0 | 304 | |
d1b054da YZ |
305 | /* Single Root I/O Virtualization */ |
306 | struct pci_sriov { | |
0aa0f5d1 BH |
307 | int pos; /* Capability position */ |
308 | int nres; /* Number of resources */ | |
309 | u32 cap; /* SR-IOV Capabilities */ | |
310 | u16 ctrl; /* SR-IOV Control */ | |
311 | u16 total_VFs; /* Total VFs associated with the PF */ | |
312 | u16 initial_VFs; /* Initial VFs associated with the PF */ | |
313 | u16 num_VFs; /* Number of VFs available */ | |
314 | u16 offset; /* First VF Routing ID offset */ | |
315 | u16 stride; /* Following VF stride */ | |
316 | u16 vf_device; /* VF device ID */ | |
317 | u32 pgsz; /* Page size for BAR alignment */ | |
318 | u8 link; /* Function Dependency Link */ | |
319 | u8 max_VF_buses; /* Max buses consumed by VFs */ | |
320 | u16 driver_max_VFs; /* Max num VFs driver supports */ | |
321 | struct pci_dev *dev; /* Lowest numbered PF */ | |
322 | struct pci_dev *self; /* This PF */ | |
cf0921be KA |
323 | u32 class; /* VF device */ |
324 | u8 hdr_type; /* VF header type */ | |
325 | u16 subsystem_vendor; /* VF subsystem vendor */ | |
326 | u16 subsystem_device; /* VF subsystem device */ | |
0aa0f5d1 BH |
327 | resource_size_t barsz[PCI_SRIOV_NUM_BARS]; /* VF BAR size */ |
328 | bool drivers_autoprobe; /* Auto probing of VFs by driver */ | |
d1b054da YZ |
329 | }; |
330 | ||
a6bd101b KB |
331 | /** |
332 | * pci_dev_set_io_state - Set the new error state if possible. | |
333 | * | |
334 | * @dev - pci device to set new error_state | |
335 | * @new - the state we want dev to be in | |
336 | * | |
337 | * Must be called with device_lock held. | |
338 | * | |
339 | * Returns true if state has been changed to the requested state. | |
340 | */ | |
341 | static inline bool pci_dev_set_io_state(struct pci_dev *dev, | |
342 | pci_channel_state_t new) | |
343 | { | |
344 | bool changed = false; | |
345 | ||
346 | device_lock_assert(&dev->dev); | |
347 | switch (new) { | |
348 | case pci_channel_io_perm_failure: | |
349 | switch (dev->error_state) { | |
350 | case pci_channel_io_frozen: | |
351 | case pci_channel_io_normal: | |
352 | case pci_channel_io_perm_failure: | |
353 | changed = true; | |
354 | break; | |
355 | } | |
356 | break; | |
357 | case pci_channel_io_frozen: | |
358 | switch (dev->error_state) { | |
359 | case pci_channel_io_frozen: | |
360 | case pci_channel_io_normal: | |
361 | changed = true; | |
362 | break; | |
363 | } | |
364 | break; | |
365 | case pci_channel_io_normal: | |
366 | switch (dev->error_state) { | |
367 | case pci_channel_io_frozen: | |
368 | case pci_channel_io_normal: | |
369 | changed = true; | |
370 | break; | |
371 | } | |
372 | break; | |
373 | } | |
374 | if (changed) | |
375 | dev->error_state = new; | |
376 | return changed; | |
377 | } | |
89ee9f76 KB |
378 | |
379 | static inline int pci_dev_set_disconnected(struct pci_dev *dev, void *unused) | |
380 | { | |
a6bd101b KB |
381 | device_lock(&dev->dev); |
382 | pci_dev_set_io_state(dev, pci_channel_io_perm_failure); | |
383 | device_unlock(&dev->dev); | |
384 | ||
89ee9f76 KB |
385 | return 0; |
386 | } | |
387 | ||
388 | static inline bool pci_dev_is_disconnected(const struct pci_dev *dev) | |
389 | { | |
a6bd101b | 390 | return dev->error_state == pci_channel_io_perm_failure; |
89ee9f76 KB |
391 | } |
392 | ||
a6bd101b KB |
393 | /* pci_dev priv_flags */ |
394 | #define PCI_DEV_ADDED 0 | |
395 | ||
44bda4b7 HV |
396 | static inline void pci_dev_assign_added(struct pci_dev *dev, bool added) |
397 | { | |
398 | assign_bit(PCI_DEV_ADDED, &dev->priv_flags, added); | |
399 | } | |
400 | ||
401 | static inline bool pci_dev_is_added(const struct pci_dev *dev) | |
402 | { | |
403 | return test_bit(PCI_DEV_ADDED, &dev->priv_flags); | |
404 | } | |
405 | ||
1e451160 KB |
406 | #ifdef CONFIG_PCIEAER |
407 | #include <linux/aer.h> | |
408 | ||
409 | #define AER_MAX_MULTI_ERR_DEVICES 5 /* Not likely to have more */ | |
410 | ||
411 | struct aer_err_info { | |
412 | struct pci_dev *dev[AER_MAX_MULTI_ERR_DEVICES]; | |
413 | int error_dev_num; | |
414 | ||
415 | unsigned int id:16; | |
416 | ||
417 | unsigned int severity:2; /* 0:NONFATAL | 1:FATAL | 2:COR */ | |
418 | unsigned int __pad1:5; | |
419 | unsigned int multi_error_valid:1; | |
420 | ||
421 | unsigned int first_error:5; | |
422 | unsigned int __pad2:2; | |
423 | unsigned int tlp_header_valid:1; | |
424 | ||
425 | unsigned int status; /* COR/UNCOR Error Status */ | |
426 | unsigned int mask; /* COR/UNCOR Error Mask */ | |
427 | struct aer_header_log_regs tlp; /* TLP Header */ | |
428 | }; | |
429 | ||
430 | int aer_get_device_error_info(struct pci_dev *dev, struct aer_err_info *info); | |
431 | void aer_print_error(struct pci_dev *dev, struct aer_err_info *info); | |
432 | #endif /* CONFIG_PCIEAER */ | |
433 | ||
90655631 SK |
434 | #ifdef CONFIG_PCIEPORTBUS |
435 | /* Cached RCEC Endpoint Association */ | |
436 | struct rcec_ea { | |
437 | u8 nextbusn; | |
438 | u8 lastbusn; | |
439 | u32 bitmap; | |
440 | }; | |
441 | #endif | |
442 | ||
4f802170 KB |
443 | #ifdef CONFIG_PCIE_DPC |
444 | void pci_save_dpc_state(struct pci_dev *dev); | |
445 | void pci_restore_dpc_state(struct pci_dev *dev); | |
27005618 | 446 | void pci_dpc_init(struct pci_dev *pdev); |
aea47413 KS |
447 | void dpc_process_error(struct pci_dev *pdev); |
448 | pci_ers_result_t dpc_reset_link(struct pci_dev *pdev); | |
4f802170 KB |
449 | #else |
450 | static inline void pci_save_dpc_state(struct pci_dev *dev) {} | |
451 | static inline void pci_restore_dpc_state(struct pci_dev *dev) {} | |
27005618 | 452 | static inline void pci_dpc_init(struct pci_dev *pdev) {} |
4f802170 KB |
453 | #endif |
454 | ||
90655631 SK |
455 | #ifdef CONFIG_PCIEPORTBUS |
456 | void pci_rcec_init(struct pci_dev *dev); | |
457 | void pci_rcec_exit(struct pci_dev *dev); | |
507b460f | 458 | void pcie_link_rcec(struct pci_dev *rcec); |
af113553 SK |
459 | void pcie_walk_rcec(struct pci_dev *rcec, |
460 | int (*cb)(struct pci_dev *, void *), | |
461 | void *userdata); | |
90655631 SK |
462 | #else |
463 | static inline void pci_rcec_init(struct pci_dev *dev) {} | |
464 | static inline void pci_rcec_exit(struct pci_dev *dev) {} | |
507b460f | 465 | static inline void pcie_link_rcec(struct pci_dev *rcec) {} |
af113553 SK |
466 | static inline void pcie_walk_rcec(struct pci_dev *rcec, |
467 | int (*cb)(struct pci_dev *, void *), | |
468 | void *userdata) {} | |
90655631 SK |
469 | #endif |
470 | ||
1900ca13 | 471 | #ifdef CONFIG_PCI_ATS |
b92b512a KS |
472 | /* Address Translation Service */ |
473 | void pci_ats_init(struct pci_dev *dev); | |
f39d5b72 | 474 | void pci_restore_ats_state(struct pci_dev *dev); |
1900ca13 | 475 | #else |
b92b512a KS |
476 | static inline void pci_ats_init(struct pci_dev *d) { } |
477 | static inline void pci_restore_ats_state(struct pci_dev *dev) { } | |
1900ca13 HX |
478 | #endif /* CONFIG_PCI_ATS */ |
479 | ||
c065190b KS |
480 | #ifdef CONFIG_PCI_PRI |
481 | void pci_pri_init(struct pci_dev *dev); | |
fef2dd8b | 482 | void pci_restore_pri_state(struct pci_dev *pdev); |
c065190b KS |
483 | #else |
484 | static inline void pci_pri_init(struct pci_dev *dev) { } | |
fef2dd8b | 485 | static inline void pci_restore_pri_state(struct pci_dev *pdev) { } |
c065190b KS |
486 | #endif |
487 | ||
751035b8 KS |
488 | #ifdef CONFIG_PCI_PASID |
489 | void pci_pasid_init(struct pci_dev *dev); | |
fef2dd8b | 490 | void pci_restore_pasid_state(struct pci_dev *pdev); |
751035b8 KS |
491 | #else |
492 | static inline void pci_pasid_init(struct pci_dev *dev) { } | |
fef2dd8b | 493 | static inline void pci_restore_pasid_state(struct pci_dev *pdev) { } |
751035b8 KS |
494 | #endif |
495 | ||
d1b054da | 496 | #ifdef CONFIG_PCI_IOV |
f39d5b72 BH |
497 | int pci_iov_init(struct pci_dev *dev); |
498 | void pci_iov_release(struct pci_dev *dev); | |
38972375 | 499 | void pci_iov_remove(struct pci_dev *dev); |
6ffa2489 | 500 | void pci_iov_update_resource(struct pci_dev *dev, int resno); |
f39d5b72 BH |
501 | resource_size_t pci_sriov_resource_alignment(struct pci_dev *dev, int resno); |
502 | void pci_restore_iov_state(struct pci_dev *dev); | |
503 | int pci_iov_bus_range(struct pci_bus *bus); | |
aaee0c1f | 504 | extern const struct attribute_group sriov_dev_attr_group; |
d1b054da YZ |
505 | #else |
506 | static inline int pci_iov_init(struct pci_dev *dev) | |
507 | { | |
508 | return -ENODEV; | |
509 | } | |
510 | static inline void pci_iov_release(struct pci_dev *dev) | |
511 | ||
38972375 JK |
512 | { |
513 | } | |
514 | static inline void pci_iov_remove(struct pci_dev *dev) | |
d1b054da YZ |
515 | { |
516 | } | |
8c5cdb6a YZ |
517 | static inline void pci_restore_iov_state(struct pci_dev *dev) |
518 | { | |
519 | } | |
a28724b0 YZ |
520 | static inline int pci_iov_bus_range(struct pci_bus *bus) |
521 | { | |
522 | return 0; | |
523 | } | |
302b4215 | 524 | |
d1b054da YZ |
525 | #endif /* CONFIG_PCI_IOV */ |
526 | ||
39850ed5 DB |
527 | #ifdef CONFIG_PCIE_PTM |
528 | void pci_save_ptm_state(struct pci_dev *dev); | |
529 | void pci_restore_ptm_state(struct pci_dev *dev); | |
a697f072 | 530 | void pci_disable_ptm(struct pci_dev *dev); |
39850ed5 DB |
531 | #else |
532 | static inline void pci_save_ptm_state(struct pci_dev *dev) { } | |
533 | static inline void pci_restore_ptm_state(struct pci_dev *dev) { } | |
a697f072 | 534 | static inline void pci_disable_ptm(struct pci_dev *dev) { } |
39850ed5 DB |
535 | #endif |
536 | ||
f39d5b72 | 537 | unsigned long pci_cardbus_resource_alignment(struct resource *); |
0a2daa1c | 538 | |
0e52247a | 539 | static inline resource_size_t pci_resource_alignment(struct pci_dev *dev, |
f39d5b72 | 540 | struct resource *res) |
6faf17f6 CW |
541 | { |
542 | #ifdef CONFIG_PCI_IOV | |
543 | int resno = res - dev->resource; | |
544 | ||
545 | if (resno >= PCI_IOV_RESOURCES && resno <= PCI_IOV_RESOURCE_END) | |
546 | return pci_sriov_resource_alignment(dev, resno); | |
547 | #endif | |
0aa0f5d1 | 548 | if (dev->class >> 8 == PCI_CLASS_BRIDGE_CARDBUS) |
0a2daa1c | 549 | return pci_cardbus_resource_alignment(res); |
6faf17f6 CW |
550 | return resource_alignment(res); |
551 | } | |
552 | ||
52fbf5bd | 553 | void pci_acs_init(struct pci_dev *dev); |
bd2e9567 BH |
554 | #ifdef CONFIG_PCI_QUIRKS |
555 | int pci_dev_specific_acs_enabled(struct pci_dev *dev, u16 acs_flags); | |
556 | int pci_dev_specific_enable_acs(struct pci_dev *dev); | |
73c47dde | 557 | int pci_dev_specific_disable_acs_redir(struct pci_dev *dev); |
bd2e9567 BH |
558 | #else |
559 | static inline int pci_dev_specific_acs_enabled(struct pci_dev *dev, | |
560 | u16 acs_flags) | |
561 | { | |
562 | return -ENOTTY; | |
563 | } | |
564 | static inline int pci_dev_specific_enable_acs(struct pci_dev *dev) | |
565 | { | |
566 | return -ENOTTY; | |
567 | } | |
73c47dde LG |
568 | static inline int pci_dev_specific_disable_acs_redir(struct pci_dev *dev) |
569 | { | |
570 | return -ENOTTY; | |
571 | } | |
bd2e9567 | 572 | #endif |
ae21ee65 | 573 | |
2e28bc84 | 574 | /* PCI error reporting and recovery */ |
e8e5ff2a | 575 | pci_ers_result_t pcie_do_recovery(struct pci_dev *dev, |
8f1bbfbc SK |
576 | pci_channel_state_t state, |
577 | pci_ers_result_t (*reset_subordinates)(struct pci_dev *pdev)); | |
2e28bc84 | 578 | |
9f5a70f1 | 579 | bool pcie_wait_for_link(struct pci_dev *pdev, bool active); |
7d8e7d19 BH |
580 | #ifdef CONFIG_PCIEASPM |
581 | void pcie_aspm_init_link_state(struct pci_dev *pdev); | |
582 | void pcie_aspm_exit_link_state(struct pci_dev *pdev); | |
583 | void pcie_aspm_pm_state_change(struct pci_dev *pdev); | |
584 | void pcie_aspm_powersave_config_link(struct pci_dev *pdev); | |
585 | #else | |
586 | static inline void pcie_aspm_init_link_state(struct pci_dev *pdev) { } | |
587 | static inline void pcie_aspm_exit_link_state(struct pci_dev *pdev) { } | |
588 | static inline void pcie_aspm_pm_state_change(struct pci_dev *pdev) { } | |
589 | static inline void pcie_aspm_powersave_config_link(struct pci_dev *pdev) { } | |
590 | #endif | |
591 | ||
72bde9ce KS |
592 | #ifdef CONFIG_PCIE_ECRC |
593 | void pcie_set_ecrc_checking(struct pci_dev *dev); | |
594 | void pcie_ecrc_get_policy(char *str); | |
595 | #else | |
596 | static inline void pcie_set_ecrc_checking(struct pci_dev *dev) { } | |
597 | static inline void pcie_ecrc_get_policy(char *str) { } | |
598 | #endif | |
599 | ||
9bb04a0c JY |
600 | #ifdef CONFIG_PCIE_PTM |
601 | void pci_ptm_init(struct pci_dev *dev); | |
ac6c26da | 602 | int pci_enable_ptm(struct pci_dev *dev, u8 *granularity); |
9bb04a0c JY |
603 | #else |
604 | static inline void pci_ptm_init(struct pci_dev *dev) { } | |
ac6c26da KS |
605 | static inline int pci_enable_ptm(struct pci_dev *dev, u8 *granularity) |
606 | { return -EINVAL; } | |
9bb04a0c JY |
607 | #endif |
608 | ||
b9c3b266 DC |
609 | struct pci_dev_reset_methods { |
610 | u16 vendor; | |
611 | u16 device; | |
612 | int (*reset)(struct pci_dev *dev, int probe); | |
613 | }; | |
614 | ||
93177a74 | 615 | #ifdef CONFIG_PCI_QUIRKS |
f39d5b72 | 616 | int pci_dev_specific_reset(struct pci_dev *dev, int probe); |
93177a74 RW |
617 | #else |
618 | static inline int pci_dev_specific_reset(struct pci_dev *dev, int probe) | |
619 | { | |
620 | return -ENOTTY; | |
621 | } | |
622 | #endif | |
b9c3b266 | 623 | |
169de969 DL |
624 | #if defined(CONFIG_PCI_QUIRKS) && defined(CONFIG_ARM64) |
625 | int acpi_get_rc_resources(struct device *dev, const char *hid, u16 segment, | |
626 | struct resource *res); | |
627 | #endif | |
628 | ||
276b738d CK |
629 | int pci_rebar_get_current_size(struct pci_dev *pdev, int bar); |
630 | int pci_rebar_set_size(struct pci_dev *pdev, int bar, int size); | |
631 | static inline u64 pci_rebar_size_to_bytes(int size) | |
632 | { | |
633 | return 1ULL << (size + 20); | |
634 | } | |
635 | ||
9e2aee80 RH |
636 | struct device_node; |
637 | ||
638 | #ifdef CONFIG_OF | |
639 | int of_pci_parse_bus_range(struct device_node *node, struct resource *res); | |
640 | int of_get_pci_domain_nr(struct device_node *node); | |
641 | int of_pci_get_max_link_speed(struct device_node *node); | |
621f7e35 KS |
642 | void pci_set_of_node(struct pci_dev *dev); |
643 | void pci_release_of_node(struct pci_dev *dev); | |
644 | void pci_set_bus_of_node(struct pci_bus *bus); | |
645 | void pci_release_bus_of_node(struct pci_bus *bus); | |
9e2aee80 | 646 | |
669cbc70 RH |
647 | int devm_of_pci_bridge_init(struct device *dev, struct pci_host_bridge *bridge); |
648 | ||
9e2aee80 RH |
649 | #else |
650 | static inline int | |
651 | of_pci_parse_bus_range(struct device_node *node, struct resource *res) | |
652 | { | |
653 | return -EINVAL; | |
654 | } | |
655 | ||
656 | static inline int | |
657 | of_get_pci_domain_nr(struct device_node *node) | |
658 | { | |
659 | return -1; | |
660 | } | |
661 | ||
662 | static inline int | |
663 | of_pci_get_max_link_speed(struct device_node *node) | |
664 | { | |
665 | return -EINVAL; | |
666 | } | |
621f7e35 KS |
667 | |
668 | static inline void pci_set_of_node(struct pci_dev *dev) { } | |
669 | static inline void pci_release_of_node(struct pci_dev *dev) { } | |
670 | static inline void pci_set_bus_of_node(struct pci_bus *bus) { } | |
671 | static inline void pci_release_bus_of_node(struct pci_bus *bus) { } | |
669cbc70 RH |
672 | |
673 | static inline int devm_of_pci_bridge_init(struct device *dev, struct pci_host_bridge *bridge) | |
674 | { | |
675 | return 0; | |
676 | } | |
677 | ||
9e2aee80 RH |
678 | #endif /* CONFIG_OF */ |
679 | ||
60ed982a RJ |
680 | #ifdef CONFIG_PCIEAER |
681 | void pci_no_aer(void); | |
682 | void pci_aer_init(struct pci_dev *dev); | |
db89ccbe | 683 | void pci_aer_exit(struct pci_dev *dev); |
81aa5206 | 684 | extern const struct attribute_group aer_stats_attr_group; |
7ab92e89 | 685 | void pci_aer_clear_fatal_status(struct pci_dev *dev); |
894020fd | 686 | int pci_aer_clear_status(struct pci_dev *dev); |
20e15e67 | 687 | int pci_aer_raw_clear_status(struct pci_dev *dev); |
60ed982a RJ |
688 | #else |
689 | static inline void pci_no_aer(void) { } | |
31f996ef | 690 | static inline void pci_aer_init(struct pci_dev *d) { } |
db89ccbe | 691 | static inline void pci_aer_exit(struct pci_dev *d) { } |
7ab92e89 | 692 | static inline void pci_aer_clear_fatal_status(struct pci_dev *dev) { } |
894020fd | 693 | static inline int pci_aer_clear_status(struct pci_dev *dev) { return -EINVAL; } |
20e15e67 | 694 | static inline int pci_aer_raw_clear_status(struct pci_dev *dev) { return -EINVAL; } |
60ed982a RJ |
695 | #endif |
696 | ||
8c3aac6e | 697 | #ifdef CONFIG_ACPI |
4a2dbedd | 698 | int pci_acpi_program_hp_params(struct pci_dev *dev); |
8c3aac6e | 699 | #else |
4a2dbedd | 700 | static inline int pci_acpi_program_hp_params(struct pci_dev *dev) |
8c3aac6e KW |
701 | { |
702 | return -ENODEV; | |
703 | } | |
704 | #endif | |
705 | ||
72ea91af HK |
706 | #ifdef CONFIG_PCIEASPM |
707 | extern const struct attribute_group aspm_ctrl_attr_group; | |
708 | #endif | |
709 | ||
557848c3 | 710 | #endif /* DRIVERS_PCI_H */ |