]> Git Repo - linux.git/blame - drivers/pci/pci.h
net/mlx5: Use order-0 allocations for EQs
[linux.git] / drivers / pci / pci.h
CommitLineData
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 14extern const unsigned char pcie_link_speed[];
11eb0e0e 15extern bool pci_early_dump;
343e51ae 16
7a1562d4 17bool pcie_cap_has_lnkctl(const struct pci_dev *dev);
af65d1ad 18bool pcie_cap_has_rtctl(const struct pci_dev *dev);
7a1562d4 19
1da177e4
LT
20/* Functions internal to the PCI core code */
21
f39d5b72
BH
22int pci_create_sysfs_dev_files(struct pci_dev *pdev);
23void pci_remove_sysfs_dev_files(struct pci_dev *pdev);
6058989b 24#if !defined(CONFIG_DMI) && !defined(CONFIG_ACPI)
911e1c9b 25static inline void pci_create_firmware_label_files(struct pci_dev *pdev)
b879743f 26{ return; }
911e1c9b 27static inline void pci_remove_firmware_label_files(struct pci_dev *pdev)
b879743f 28{ return; }
911e1c9b 29#else
f39d5b72
BH
30void pci_create_firmware_label_files(struct pci_dev *pdev);
31void pci_remove_firmware_label_files(struct pci_dev *pdev);
911e1c9b 32#endif
f39d5b72 33void pci_cleanup_rom(struct pci_dev *dev);
f7195824 34
3b519e4e
MW
35enum 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
39int pci_mmap_fits(struct pci_dev *pdev, int resno, struct vm_area_struct *vmai,
40 enum pci_mmap_api mmap_api);
f7195824 41
711d5779 42int pci_probe_reset_function(struct pci_dev *dev);
381634ca 43int pci_bridge_secondary_bus_reset(struct pci_dev *dev);
c4eed62a 44int 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 */
77struct 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 88int pci_set_platform_pm(const struct pci_platform_pm_ops *ops);
f39d5b72 89void pci_update_current_state(struct pci_dev *dev, pci_power_t state);
b51033e0 90void pci_refresh_power_state(struct pci_dev *dev);
adfac8f6 91int pci_power_up(struct pci_dev *dev);
f39d5b72
BH
92void pci_disable_enabled_device(struct pci_dev *dev);
93int pci_finish_runtime_suspend(struct pci_dev *dev);
600a5b4f 94void pcie_clear_device_status(struct pci_dev *dev);
dcb0453d 95void pcie_clear_root_pme_status(struct pci_dev *dev);
669696eb
KS
96bool pci_check_pme_status(struct pci_dev *dev);
97void pci_pme_wakeup_bus(struct pci_bus *bus);
f39d5b72 98int __pci_pme_wakeup(struct pci_dev *dev, void *ign);
0ce3fcaf 99void pci_pme_restore(struct pci_dev *dev);
0c7376ad
RW
100bool pci_dev_need_resume(struct pci_dev *dev);
101void pci_dev_adjust_pme(struct pci_dev *dev);
2cef548a 102void pci_dev_complete_resume(struct pci_dev *pci_dev);
f39d5b72
BH
103void pci_config_pm_runtime_get(struct pci_dev *dev);
104void pci_config_pm_runtime_put(struct pci_dev *dev);
105void pci_pm_init(struct pci_dev *dev);
938174e5 106void pci_ea_init(struct pci_dev *dev);
cbc40d5c
BH
107void pci_msi_init(struct pci_dev *dev);
108void pci_msix_init(struct pci_dev *dev);
f39d5b72 109void pci_allocate_cap_save_buffers(struct pci_dev *dev);
f796841e 110void pci_free_cap_save_buffers(struct pci_dev *dev);
c6a63307 111bool pci_bridge_d3_possible(struct pci_dev *dev);
1ed276a7 112void pci_bridge_d3_update(struct pci_dev *dev);
ad9001f2 113void pci_bridge_wait_for_secondary_bus(struct pci_dev *dev);
aa8c6c93 114
b6e335ae
RW
115static 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 121static inline bool pci_has_subordinate(struct pci_dev *pci_dev)
aa8c6c93
RW
122{
123 return !!(pci_dev->subordinate);
124}
0f64474b 125
9d26d3a8
MW
126static 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
135static 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 144int pci_vpd_init(struct pci_dev *dev);
64379079 145void pci_vpd_release(struct pci_dev *dev);
b1c615c4
BH
146void pcie_vpd_create_sysfs_dev_files(struct pci_dev *dev);
147void pcie_vpd_remove_sysfs_dev_files(struct pci_dev *dev);
94e61088 148
440589dd
KS
149/* PCI Virtual Channel */
150int pci_save_vc_state(struct pci_dev *dev);
151void pci_restore_vc_state(struct pci_dev *dev);
152void pci_allocate_vc_save_buffers(struct pci_dev *dev);
153
1da177e4
LT
154/* PCI /proc functions */
155#ifdef CONFIG_PROC_FS
f39d5b72
BH
156int pci_proc_attach_device(struct pci_dev *dev);
157int pci_proc_detach_device(struct pci_dev *dev);
158int pci_proc_detach_bus(struct pci_bus *bus);
1da177e4
LT
159#else
160static inline int pci_proc_attach_device(struct pci_dev *dev) { return 0; }
161static inline int pci_proc_detach_device(struct pci_dev *dev) { return 0; }
1da177e4
LT
162static inline int pci_proc_detach_bus(struct pci_bus *bus) { return 0; }
163#endif
164
165/* Functions for PCI Hotplug drivers to use */
a8e4b9c1 166int pci_hp_add_bridge(struct pci_dev *dev);
1da177e4 167
f19aeb1f 168#ifdef HAVE_PCI_LEGACY
f39d5b72
BH
169void pci_create_legacy_files(struct pci_bus *bus);
170void pci_remove_legacy_files(struct pci_bus *bus);
f19aeb1f
BH
171#else
172static inline void pci_create_legacy_files(struct pci_bus *bus) { return; }
173static 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 177extern struct rw_semaphore pci_bus_sem;
c4eed62a 178extern struct mutex pci_slot_mutex;
1da177e4 179
a2e27787
JK
180extern raw_spinlock_t pci_lock;
181
3789af9a 182extern unsigned int pci_pm_d3hot_delay;
88187dfa 183
4b47b0ee 184#ifdef CONFIG_PCI_MSI
309e57df 185void pci_no_msi(void);
4b47b0ee 186#else
309e57df 187static inline void pci_no_msi(void) { }
4b47b0ee 188#endif
8fed4b65 189
b55438fd 190void pci_realloc_get_opt(char *);
f483d392 191
ffadcc2f
KCA
192static 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 201extern const struct attribute_group *pci_dev_groups[];
56039e65 202extern const struct attribute_group *pcibus_groups[];
69f2dc24 203extern const struct device_type pci_dev_type;
0f49ba55 204extern const struct attribute_group *pci_bus_groups[];
705b1aaa 205
003d3b2c 206extern unsigned long pci_hotplug_io_size;
d7b8a217
NJ
207extern unsigned long pci_hotplug_mmio_size;
208extern unsigned long pci_hotplug_mmio_pref_size;
003d3b2c 209extern 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 */
219static inline const struct pci_device_id *
220pci_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
234extern struct kset *pci_slots_kset;
235
236struct 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
243enum 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
250struct device *pci_get_host_bridge_device(struct pci_dev *dev);
251void pci_put_host_bridge_device(struct device *dev);
252
62ce94a7 253int pci_configure_extended_tags(struct pci_dev *dev, void *ign);
efdc87da
YL
254bool pci_bus_read_dev_vendor_id(struct pci_bus *bus, int devfn, u32 *pl,
255 int crs_timeout);
aa667c64
JP
256bool pci_bus_generic_read_dev_vendor_id(struct pci_bus *bus, int devfn, u32 *pl,
257 int crs_timeout);
258int pci_idt_bus_quirk(struct pci_bus *bus, int devfn, u32 *pl, int crs_timeout);
259
f39d5b72
BH
260int pci_setup_device(struct pci_dev *dev);
261int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
262 struct resource *res, unsigned int reg);
f39d5b72 263void pci_configure_ari(struct pci_dev *dev);
10874f5a 264void __pci_bus_size_bridges(struct pci_bus *bus,
d66ecb72 265 struct list_head *realloc_head);
10874f5a
BH
266void __pci_bus_assign_resources(const struct pci_bus *bus,
267 struct list_head *realloc_head,
268 struct list_head *fail_head);
0f7e7aee 269bool pci_bus_clip_resource(struct pci_dev *dev, int idx);
939de1d6 270
2069ecfb 271void pci_reassigndev_resource_alignment(struct pci_dev *dev);
f39d5b72 272void pci_disable_bridge_window(struct pci_dev *dev);
ecd29c1a
KS
273struct pci_bus *pci_bus_get(struct pci_bus *bus);
274void 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 296const char *pci_speed_string(enum pci_bus_speed speed);
6cf57be0 297enum pci_bus_speed pcie_get_speed_cap(struct pci_dev *dev);
c70b65fb 298enum pcie_link_width pcie_get_width_cap(struct pci_dev *dev);
b852f63a
TG
299u32 pcie_bandwidth_capable(struct pci_dev *dev, enum pci_bus_speed *speed,
300 enum pcie_link_width *width);
2d1ce5ec 301void __pcie_print_link_status(struct pci_dev *dev, bool verbose);
0fa635ae 302void pcie_report_downtraining(struct pci_dev *dev);
5da78d95 303void pcie_update_link_speed(struct pci_bus *bus, u16 link_status);
6cf57be0 304
d1b054da
YZ
305/* Single Root I/O Virtualization */
306struct 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 */
341static 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
379static 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
388static 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
396static 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
401static 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
411struct 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
430int aer_get_device_error_info(struct pci_dev *dev, struct aer_err_info *info);
431void 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 */
436struct rcec_ea {
437 u8 nextbusn;
438 u8 lastbusn;
439 u32 bitmap;
440};
441#endif
442
4f802170
KB
443#ifdef CONFIG_PCIE_DPC
444void pci_save_dpc_state(struct pci_dev *dev);
445void pci_restore_dpc_state(struct pci_dev *dev);
27005618 446void pci_dpc_init(struct pci_dev *pdev);
aea47413
KS
447void dpc_process_error(struct pci_dev *pdev);
448pci_ers_result_t dpc_reset_link(struct pci_dev *pdev);
4f802170
KB
449#else
450static inline void pci_save_dpc_state(struct pci_dev *dev) {}
451static inline void pci_restore_dpc_state(struct pci_dev *dev) {}
27005618 452static inline void pci_dpc_init(struct pci_dev *pdev) {}
4f802170
KB
453#endif
454
90655631
SK
455#ifdef CONFIG_PCIEPORTBUS
456void pci_rcec_init(struct pci_dev *dev);
457void pci_rcec_exit(struct pci_dev *dev);
507b460f 458void pcie_link_rcec(struct pci_dev *rcec);
af113553
SK
459void pcie_walk_rcec(struct pci_dev *rcec,
460 int (*cb)(struct pci_dev *, void *),
461 void *userdata);
90655631
SK
462#else
463static inline void pci_rcec_init(struct pci_dev *dev) {}
464static inline void pci_rcec_exit(struct pci_dev *dev) {}
507b460f 465static inline void pcie_link_rcec(struct pci_dev *rcec) {}
af113553
SK
466static 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 */
473void pci_ats_init(struct pci_dev *dev);
f39d5b72 474void pci_restore_ats_state(struct pci_dev *dev);
1900ca13 475#else
b92b512a
KS
476static inline void pci_ats_init(struct pci_dev *d) { }
477static 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
481void pci_pri_init(struct pci_dev *dev);
fef2dd8b 482void pci_restore_pri_state(struct pci_dev *pdev);
c065190b
KS
483#else
484static inline void pci_pri_init(struct pci_dev *dev) { }
fef2dd8b 485static inline void pci_restore_pri_state(struct pci_dev *pdev) { }
c065190b
KS
486#endif
487
751035b8
KS
488#ifdef CONFIG_PCI_PASID
489void pci_pasid_init(struct pci_dev *dev);
fef2dd8b 490void pci_restore_pasid_state(struct pci_dev *pdev);
751035b8
KS
491#else
492static inline void pci_pasid_init(struct pci_dev *dev) { }
fef2dd8b 493static inline void pci_restore_pasid_state(struct pci_dev *pdev) { }
751035b8
KS
494#endif
495
d1b054da 496#ifdef CONFIG_PCI_IOV
f39d5b72
BH
497int pci_iov_init(struct pci_dev *dev);
498void pci_iov_release(struct pci_dev *dev);
38972375 499void pci_iov_remove(struct pci_dev *dev);
6ffa2489 500void pci_iov_update_resource(struct pci_dev *dev, int resno);
f39d5b72
BH
501resource_size_t pci_sriov_resource_alignment(struct pci_dev *dev, int resno);
502void pci_restore_iov_state(struct pci_dev *dev);
503int pci_iov_bus_range(struct pci_bus *bus);
aaee0c1f 504extern const struct attribute_group sriov_dev_attr_group;
d1b054da
YZ
505#else
506static inline int pci_iov_init(struct pci_dev *dev)
507{
508 return -ENODEV;
509}
510static inline void pci_iov_release(struct pci_dev *dev)
511
38972375
JK
512{
513}
514static inline void pci_iov_remove(struct pci_dev *dev)
d1b054da
YZ
515{
516}
8c5cdb6a
YZ
517static inline void pci_restore_iov_state(struct pci_dev *dev)
518{
519}
a28724b0
YZ
520static 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
528void pci_save_ptm_state(struct pci_dev *dev);
529void pci_restore_ptm_state(struct pci_dev *dev);
a697f072 530void pci_disable_ptm(struct pci_dev *dev);
39850ed5
DB
531#else
532static inline void pci_save_ptm_state(struct pci_dev *dev) { }
533static inline void pci_restore_ptm_state(struct pci_dev *dev) { }
a697f072 534static inline void pci_disable_ptm(struct pci_dev *dev) { }
39850ed5
DB
535#endif
536
f39d5b72 537unsigned long pci_cardbus_resource_alignment(struct resource *);
0a2daa1c 538
0e52247a 539static 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 553void pci_acs_init(struct pci_dev *dev);
bd2e9567
BH
554#ifdef CONFIG_PCI_QUIRKS
555int pci_dev_specific_acs_enabled(struct pci_dev *dev, u16 acs_flags);
556int pci_dev_specific_enable_acs(struct pci_dev *dev);
73c47dde 557int pci_dev_specific_disable_acs_redir(struct pci_dev *dev);
bd2e9567
BH
558#else
559static inline int pci_dev_specific_acs_enabled(struct pci_dev *dev,
560 u16 acs_flags)
561{
562 return -ENOTTY;
563}
564static inline int pci_dev_specific_enable_acs(struct pci_dev *dev)
565{
566 return -ENOTTY;
567}
73c47dde
LG
568static 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 575pci_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 579bool pcie_wait_for_link(struct pci_dev *pdev, bool active);
7d8e7d19
BH
580#ifdef CONFIG_PCIEASPM
581void pcie_aspm_init_link_state(struct pci_dev *pdev);
582void pcie_aspm_exit_link_state(struct pci_dev *pdev);
583void pcie_aspm_pm_state_change(struct pci_dev *pdev);
584void pcie_aspm_powersave_config_link(struct pci_dev *pdev);
585#else
586static inline void pcie_aspm_init_link_state(struct pci_dev *pdev) { }
587static inline void pcie_aspm_exit_link_state(struct pci_dev *pdev) { }
588static inline void pcie_aspm_pm_state_change(struct pci_dev *pdev) { }
589static inline void pcie_aspm_powersave_config_link(struct pci_dev *pdev) { }
590#endif
591
72bde9ce
KS
592#ifdef CONFIG_PCIE_ECRC
593void pcie_set_ecrc_checking(struct pci_dev *dev);
594void pcie_ecrc_get_policy(char *str);
595#else
596static inline void pcie_set_ecrc_checking(struct pci_dev *dev) { }
597static inline void pcie_ecrc_get_policy(char *str) { }
598#endif
599
9bb04a0c
JY
600#ifdef CONFIG_PCIE_PTM
601void pci_ptm_init(struct pci_dev *dev);
ac6c26da 602int pci_enable_ptm(struct pci_dev *dev, u8 *granularity);
9bb04a0c
JY
603#else
604static inline void pci_ptm_init(struct pci_dev *dev) { }
ac6c26da
KS
605static inline int pci_enable_ptm(struct pci_dev *dev, u8 *granularity)
606{ return -EINVAL; }
9bb04a0c
JY
607#endif
608
b9c3b266
DC
609struct 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 616int pci_dev_specific_reset(struct pci_dev *dev, int probe);
93177a74
RW
617#else
618static 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)
625int acpi_get_rc_resources(struct device *dev, const char *hid, u16 segment,
626 struct resource *res);
627#endif
628
276b738d
CK
629int pci_rebar_get_current_size(struct pci_dev *pdev, int bar);
630int pci_rebar_set_size(struct pci_dev *pdev, int bar, int size);
631static inline u64 pci_rebar_size_to_bytes(int size)
632{
633 return 1ULL << (size + 20);
634}
635
9e2aee80
RH
636struct device_node;
637
638#ifdef CONFIG_OF
639int of_pci_parse_bus_range(struct device_node *node, struct resource *res);
640int of_get_pci_domain_nr(struct device_node *node);
641int of_pci_get_max_link_speed(struct device_node *node);
621f7e35
KS
642void pci_set_of_node(struct pci_dev *dev);
643void pci_release_of_node(struct pci_dev *dev);
644void pci_set_bus_of_node(struct pci_bus *bus);
645void pci_release_bus_of_node(struct pci_bus *bus);
9e2aee80 646
669cbc70
RH
647int devm_of_pci_bridge_init(struct device *dev, struct pci_host_bridge *bridge);
648
9e2aee80
RH
649#else
650static inline int
651of_pci_parse_bus_range(struct device_node *node, struct resource *res)
652{
653 return -EINVAL;
654}
655
656static inline int
657of_get_pci_domain_nr(struct device_node *node)
658{
659 return -1;
660}
661
662static inline int
663of_pci_get_max_link_speed(struct device_node *node)
664{
665 return -EINVAL;
666}
621f7e35
KS
667
668static inline void pci_set_of_node(struct pci_dev *dev) { }
669static inline void pci_release_of_node(struct pci_dev *dev) { }
670static inline void pci_set_bus_of_node(struct pci_bus *bus) { }
671static inline void pci_release_bus_of_node(struct pci_bus *bus) { }
669cbc70
RH
672
673static 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
681void pci_no_aer(void);
682void pci_aer_init(struct pci_dev *dev);
db89ccbe 683void pci_aer_exit(struct pci_dev *dev);
81aa5206 684extern const struct attribute_group aer_stats_attr_group;
7ab92e89 685void pci_aer_clear_fatal_status(struct pci_dev *dev);
894020fd 686int pci_aer_clear_status(struct pci_dev *dev);
20e15e67 687int pci_aer_raw_clear_status(struct pci_dev *dev);
60ed982a
RJ
688#else
689static inline void pci_no_aer(void) { }
31f996ef 690static inline void pci_aer_init(struct pci_dev *d) { }
db89ccbe 691static inline void pci_aer_exit(struct pci_dev *d) { }
7ab92e89 692static inline void pci_aer_clear_fatal_status(struct pci_dev *dev) { }
894020fd 693static inline int pci_aer_clear_status(struct pci_dev *dev) { return -EINVAL; }
20e15e67 694static inline int pci_aer_raw_clear_status(struct pci_dev *dev) { return -EINVAL; }
60ed982a
RJ
695#endif
696
8c3aac6e 697#ifdef CONFIG_ACPI
4a2dbedd 698int pci_acpi_program_hp_params(struct pci_dev *dev);
8c3aac6e 699#else
4a2dbedd 700static 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
707extern const struct attribute_group aspm_ctrl_attr_group;
708#endif
709
557848c3 710#endif /* DRIVERS_PCI_H */
This page took 1.257535 seconds and 4 git commands to generate.