1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef DRIVERS_PCI_H
3 #define DRIVERS_PCI_H
4
5 #include <linux/pci.h>
6 #include <linux/android_kabi.h>
7
8 /* Number of possible devfns: 0.0 to 1f.7 inclusive */
9 #define MAX_NR_DEVFNS 256
10
11 #define PCI_FIND_CAP_TTL 48
12
13 #define PCI_VSEC_ID_INTEL_TBT 0x1234 /* Thunderbolt */
14
15 extern const unsigned char pcie_link_speed[];
16 extern bool pci_early_dump;
17
18 bool pcie_cap_has_lnkctl(const struct pci_dev *dev);
19 bool pcie_cap_has_rtctl(const struct pci_dev *dev);
20
21 /* Functions internal to the PCI core code */
22
23 int pci_create_sysfs_dev_files(struct pci_dev *pdev);
24 void pci_remove_sysfs_dev_files(struct pci_dev *pdev);
25 void pci_cleanup_rom(struct pci_dev *dev);
26 #ifdef CONFIG_DMI
27 extern const struct attribute_group pci_dev_smbios_attr_group;
28 #endif
29
30 enum pci_mmap_api {
31 PCI_MMAP_SYSFS, /* mmap on /sys/bus/pci/devices/<BDF>/resource<N> */
32 PCI_MMAP_PROCFS /* mmap on /proc/bus/pci/<BDF> */
33 };
34 int pci_mmap_fits(struct pci_dev *pdev, int resno, struct vm_area_struct *vmai,
35 enum pci_mmap_api mmap_api);
36
37 bool pci_reset_supported(struct pci_dev *dev);
38 void pci_init_reset_methods(struct pci_dev *dev);
39 int pci_bridge_secondary_bus_reset(struct pci_dev *dev);
40 int pci_bus_error_reset(struct pci_dev *dev);
41
42 struct pci_cap_saved_data {
43 u16 cap_nr;
44 bool cap_extended;
45 unsigned int size;
46 u32 data[];
47 };
48
49 struct pci_cap_saved_state {
50 struct hlist_node next;
51 struct pci_cap_saved_data cap;
52 };
53
54 void pci_allocate_cap_save_buffers(struct pci_dev *dev);
55 void pci_free_cap_save_buffers(struct pci_dev *dev);
56 int pci_add_cap_save_buffer(struct pci_dev *dev, char cap, unsigned int size);
57 int pci_add_ext_cap_save_buffer(struct pci_dev *dev,
58 u16 cap, unsigned int size);
59 struct pci_cap_saved_state *pci_find_saved_cap(struct pci_dev *dev, char cap);
60 struct pci_cap_saved_state *pci_find_saved_ext_cap(struct pci_dev *dev,
61 u16 cap);
62
63 #define PCI_PM_D2_DELAY 200 /* usec; see PCIe r4.0, sec 5.9.1 */
64 #define PCI_PM_D3HOT_WAIT 10 /* msec */
65 #define PCI_PM_D3COLD_WAIT 100 /* msec */
66
67 /*
68 * Following exit from Conventional Reset, devices must be ready within 1 sec
69 * (PCIe r6.0 sec 6.6.1). A D3cold to D0 transition implies a Conventional
70 * Reset (PCIe r6.0 sec 5.8).
71 */
72 #define PCI_RESET_WAIT 1000 /* msec */
73 /*
74 * Devices may extend the 1 sec period through Request Retry Status completions
75 * (PCIe r6.0 sec 2.3.1). The spec does not provide an upper limit, but 60 sec
76 * ought to be enough for any device to become responsive.
77 */
78 #define PCIE_RESET_READY_POLL_MS 60000 /* msec */
79
80 /**
81 * struct pci_platform_pm_ops - Firmware PM callbacks
82 *
83 * @bridge_d3: Does the bridge allow entering into D3
84 *
85 * @is_manageable: returns 'true' if given device is power manageable by the
86 * platform firmware
87 *
88 * @set_state: invokes the platform firmware to set the device's power state
89 *
90 * @get_state: queries the platform firmware for a device's current power state
91 *
92 * @refresh_state: asks the platform to refresh the device's power state data
93 *
94 * @choose_state: returns PCI power state of given device preferred by the
95 * platform; to be used during system-wide transitions from a
96 * sleeping state to the working state and vice versa
97 *
98 * @set_wakeup: enables/disables wakeup capability for the device
99 *
100 * @need_resume: returns 'true' if the given device (which is currently
101 * suspended) needs to be resumed to be configured for system
102 * wakeup.
103 *
104 * If given platform is generally capable of power managing PCI devices, all of
105 * these callbacks are mandatory.
106 */
107 struct pci_platform_pm_ops {
108 bool (*bridge_d3)(struct pci_dev *dev);
109 bool (*is_manageable)(struct pci_dev *dev);
110 int (*set_state)(struct pci_dev *dev, pci_power_t state);
111 pci_power_t (*get_state)(struct pci_dev *dev);
112 void (*refresh_state)(struct pci_dev *dev);
113 pci_power_t (*choose_state)(struct pci_dev *dev);
114 int (*set_wakeup)(struct pci_dev *dev, bool enable);
115 bool (*need_resume)(struct pci_dev *dev);
116 };
117
118 int pci_set_platform_pm(const struct pci_platform_pm_ops *ops);
119 void pci_update_current_state(struct pci_dev *dev, pci_power_t state);
120 void pci_refresh_power_state(struct pci_dev *dev);
121 int pci_power_up(struct pci_dev *dev);
122 void pci_disable_enabled_device(struct pci_dev *dev);
123 int pci_finish_runtime_suspend(struct pci_dev *dev);
124 void pcie_clear_device_status(struct pci_dev *dev);
125 void pcie_clear_root_pme_status(struct pci_dev *dev);
126 bool pci_check_pme_status(struct pci_dev *dev);
127 void pci_pme_wakeup_bus(struct pci_bus *bus);
128 int __pci_pme_wakeup(struct pci_dev *dev, void *ign);
129 void pci_pme_restore(struct pci_dev *dev);
130 bool pci_dev_need_resume(struct pci_dev *dev);
131 void pci_dev_adjust_pme(struct pci_dev *dev);
132 void pci_dev_complete_resume(struct pci_dev *pci_dev);
133 void pci_config_pm_runtime_get(struct pci_dev *dev);
134 void pci_config_pm_runtime_put(struct pci_dev *dev);
135 void pci_pm_init(struct pci_dev *dev);
136 void pci_ea_init(struct pci_dev *dev);
137 void pci_msi_init(struct pci_dev *dev);
138 void pci_msix_init(struct pci_dev *dev);
139 bool pci_bridge_d3_possible(struct pci_dev *dev);
140 void pci_bridge_d3_update(struct pci_dev *dev);
141 int pci_bridge_wait_for_secondary_bus(struct pci_dev *dev, char *reset_type,
142 int timeout);
143
pci_wakeup_event(struct pci_dev * dev)144 static inline void pci_wakeup_event(struct pci_dev *dev)
145 {
146 /* Wait 100 ms before the system can be put into a sleep state. */
147 pm_wakeup_event(&dev->dev, 100);
148 }
149
pci_has_subordinate(struct pci_dev * pci_dev)150 static inline bool pci_has_subordinate(struct pci_dev *pci_dev)
151 {
152 return !!(pci_dev->subordinate);
153 }
154
pci_power_manageable(struct pci_dev * pci_dev)155 static inline bool pci_power_manageable(struct pci_dev *pci_dev)
156 {
157 /*
158 * Currently we allow normal PCI devices and PCI bridges transition
159 * into D3 if their bridge_d3 is set.
160 */
161 return !pci_has_subordinate(pci_dev) || pci_dev->bridge_d3;
162 }
163
pcie_downstream_port(const struct pci_dev * dev)164 static inline bool pcie_downstream_port(const struct pci_dev *dev)
165 {
166 int type = pci_pcie_type(dev);
167
168 return type == PCI_EXP_TYPE_ROOT_PORT ||
169 type == PCI_EXP_TYPE_DOWNSTREAM ||
170 type == PCI_EXP_TYPE_PCIE_BRIDGE;
171 }
172
173 void pci_vpd_init(struct pci_dev *dev);
174 void pci_vpd_release(struct pci_dev *dev);
175 extern const struct attribute_group pci_dev_vpd_attr_group;
176
177 /* PCI Virtual Channel */
178 int pci_save_vc_state(struct pci_dev *dev);
179 void pci_restore_vc_state(struct pci_dev *dev);
180 void pci_allocate_vc_save_buffers(struct pci_dev *dev);
181
182 /* PCI /proc functions */
183 #ifdef CONFIG_PROC_FS
184 int pci_proc_attach_device(struct pci_dev *dev);
185 int pci_proc_detach_device(struct pci_dev *dev);
186 int pci_proc_detach_bus(struct pci_bus *bus);
187 #else
pci_proc_attach_device(struct pci_dev * dev)188 static inline int pci_proc_attach_device(struct pci_dev *dev) { return 0; }
pci_proc_detach_device(struct pci_dev * dev)189 static inline int pci_proc_detach_device(struct pci_dev *dev) { return 0; }
pci_proc_detach_bus(struct pci_bus * bus)190 static inline int pci_proc_detach_bus(struct pci_bus *bus) { return 0; }
191 #endif
192
193 /* Functions for PCI Hotplug drivers to use */
194 int pci_hp_add_bridge(struct pci_dev *dev);
195
196 #ifdef HAVE_PCI_LEGACY
197 void pci_create_legacy_files(struct pci_bus *bus);
198 void pci_remove_legacy_files(struct pci_bus *bus);
199 #else
pci_create_legacy_files(struct pci_bus * bus)200 static inline void pci_create_legacy_files(struct pci_bus *bus) { return; }
pci_remove_legacy_files(struct pci_bus * bus)201 static inline void pci_remove_legacy_files(struct pci_bus *bus) { return; }
202 #endif
203
204 /* Lock for read/write access to pci device and bus lists */
205 extern struct rw_semaphore pci_bus_sem;
206 extern struct mutex pci_slot_mutex;
207
208 extern raw_spinlock_t pci_lock;
209
210 extern unsigned int pci_pm_d3hot_delay;
211
212 #ifdef CONFIG_PCI_MSI
213 void pci_no_msi(void);
214 #else
pci_no_msi(void)215 static inline void pci_no_msi(void) { }
216 #endif
217
218 void pci_realloc_get_opt(char *);
219
pci_no_d1d2(struct pci_dev * dev)220 static inline int pci_no_d1d2(struct pci_dev *dev)
221 {
222 unsigned int parent_dstates = 0;
223
224 if (dev->bus->self)
225 parent_dstates = dev->bus->self->no_d1d2;
226 return (dev->no_d1d2 || parent_dstates);
227
228 }
229 extern const struct attribute_group *pci_dev_groups[];
230 extern const struct attribute_group *pcibus_groups[];
231 extern const struct device_type pci_dev_type;
232 extern const struct attribute_group *pci_bus_groups[];
233
234 extern unsigned long pci_hotplug_io_size;
235 extern unsigned long pci_hotplug_mmio_size;
236 extern unsigned long pci_hotplug_mmio_pref_size;
237 extern unsigned long pci_hotplug_bus_size;
238
239 /**
240 * pci_match_one_device - Tell if a PCI device structure has a matching
241 * PCI device id structure
242 * @id: single PCI device id structure to match
243 * @dev: the PCI device structure to match against
244 *
245 * Returns the matching pci_device_id structure or %NULL if there is no match.
246 */
247 static inline const struct pci_device_id *
pci_match_one_device(const struct pci_device_id * id,const struct pci_dev * dev)248 pci_match_one_device(const struct pci_device_id *id, const struct pci_dev *dev)
249 {
250 if ((id->vendor == PCI_ANY_ID || id->vendor == dev->vendor) &&
251 (id->device == PCI_ANY_ID || id->device == dev->device) &&
252 (id->subvendor == PCI_ANY_ID || id->subvendor == dev->subsystem_vendor) &&
253 (id->subdevice == PCI_ANY_ID || id->subdevice == dev->subsystem_device) &&
254 !((id->class ^ dev->class) & id->class_mask))
255 return id;
256 return NULL;
257 }
258
259 /* PCI slot sysfs helper code */
260 #define to_pci_slot(s) container_of(s, struct pci_slot, kobj)
261
262 extern struct kset *pci_slots_kset;
263
264 struct pci_slot_attribute {
265 struct attribute attr;
266 ssize_t (*show)(struct pci_slot *, char *);
267 ssize_t (*store)(struct pci_slot *, const char *, size_t);
268 };
269 #define to_pci_slot_attr(s) container_of(s, struct pci_slot_attribute, attr)
270
271 enum pci_bar_type {
272 pci_bar_unknown, /* Standard PCI BAR probe */
273 pci_bar_io, /* An I/O port BAR */
274 pci_bar_mem32, /* A 32-bit memory BAR */
275 pci_bar_mem64, /* A 64-bit memory BAR */
276 };
277
278 struct device *pci_get_host_bridge_device(struct pci_dev *dev);
279 void pci_put_host_bridge_device(struct device *dev);
280
281 int pci_configure_extended_tags(struct pci_dev *dev, void *ign);
282 bool pci_bus_read_dev_vendor_id(struct pci_bus *bus, int devfn, u32 *pl,
283 int crs_timeout);
284 bool pci_bus_generic_read_dev_vendor_id(struct pci_bus *bus, int devfn, u32 *pl,
285 int crs_timeout);
286 int pci_idt_bus_quirk(struct pci_bus *bus, int devfn, u32 *pl, int crs_timeout);
287
288 int pci_setup_device(struct pci_dev *dev);
289 int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
290 struct resource *res, unsigned int reg);
291 void pci_configure_ari(struct pci_dev *dev);
292 void __pci_bus_size_bridges(struct pci_bus *bus,
293 struct list_head *realloc_head);
294 void __pci_bus_assign_resources(const struct pci_bus *bus,
295 struct list_head *realloc_head,
296 struct list_head *fail_head);
297 bool pci_bus_clip_resource(struct pci_dev *dev, int idx);
298
299 void pci_reassigndev_resource_alignment(struct pci_dev *dev);
300 void pci_disable_bridge_window(struct pci_dev *dev);
301 struct pci_bus *pci_bus_get(struct pci_bus *bus);
302 void pci_bus_put(struct pci_bus *bus);
303
304 /* PCIe link information from Link Capabilities 2 */
305 #define PCIE_LNKCAP2_SLS2SPEED(lnkcap2) \
306 ((lnkcap2) & PCI_EXP_LNKCAP2_SLS_64_0GB ? PCIE_SPEED_64_0GT : \
307 (lnkcap2) & PCI_EXP_LNKCAP2_SLS_32_0GB ? PCIE_SPEED_32_0GT : \
308 (lnkcap2) & PCI_EXP_LNKCAP2_SLS_16_0GB ? PCIE_SPEED_16_0GT : \
309 (lnkcap2) & PCI_EXP_LNKCAP2_SLS_8_0GB ? PCIE_SPEED_8_0GT : \
310 (lnkcap2) & PCI_EXP_LNKCAP2_SLS_5_0GB ? PCIE_SPEED_5_0GT : \
311 (lnkcap2) & PCI_EXP_LNKCAP2_SLS_2_5GB ? PCIE_SPEED_2_5GT : \
312 PCI_SPEED_UNKNOWN)
313
314 /* PCIe speed to Mb/s reduced by encoding overhead */
315 #define PCIE_SPEED2MBS_ENC(speed) \
316 ((speed) == PCIE_SPEED_64_0GT ? 64000*1/1 : \
317 (speed) == PCIE_SPEED_32_0GT ? 32000*128/130 : \
318 (speed) == PCIE_SPEED_16_0GT ? 16000*128/130 : \
319 (speed) == PCIE_SPEED_8_0GT ? 8000*128/130 : \
320 (speed) == PCIE_SPEED_5_0GT ? 5000*8/10 : \
321 (speed) == PCIE_SPEED_2_5GT ? 2500*8/10 : \
322 0)
323
324 const char *pci_speed_string(enum pci_bus_speed speed);
325 enum pci_bus_speed pcie_get_speed_cap(struct pci_dev *dev);
326 enum pcie_link_width pcie_get_width_cap(struct pci_dev *dev);
327 u32 pcie_bandwidth_capable(struct pci_dev *dev, enum pci_bus_speed *speed,
328 enum pcie_link_width *width);
329 void __pcie_print_link_status(struct pci_dev *dev, bool verbose);
330 void pcie_report_downtraining(struct pci_dev *dev);
331 void pcie_update_link_speed(struct pci_bus *bus, u16 link_status);
332
333 /* Single Root I/O Virtualization */
334 struct pci_sriov {
335 int pos; /* Capability position */
336 int nres; /* Number of resources */
337 u32 cap; /* SR-IOV Capabilities */
338 u16 ctrl; /* SR-IOV Control */
339 u16 total_VFs; /* Total VFs associated with the PF */
340 u16 initial_VFs; /* Initial VFs associated with the PF */
341 u16 num_VFs; /* Number of VFs available */
342 u16 offset; /* First VF Routing ID offset */
343 u16 stride; /* Following VF stride */
344 u16 vf_device; /* VF device ID */
345 u32 pgsz; /* Page size for BAR alignment */
346 u8 link; /* Function Dependency Link */
347 u8 max_VF_buses; /* Max buses consumed by VFs */
348 u16 driver_max_VFs; /* Max num VFs driver supports */
349 struct pci_dev *dev; /* Lowest numbered PF */
350 struct pci_dev *self; /* This PF */
351 u32 class; /* VF device */
352 u8 hdr_type; /* VF header type */
353 u16 subsystem_vendor; /* VF subsystem vendor */
354 u16 subsystem_device; /* VF subsystem device */
355 resource_size_t barsz[PCI_SRIOV_NUM_BARS]; /* VF BAR size */
356 bool drivers_autoprobe; /* Auto probing of VFs by driver */
357
358 ANDROID_KABI_RESERVE(1);
359 ANDROID_KABI_RESERVE(2);
360 ANDROID_KABI_RESERVE(3);
361 ANDROID_KABI_RESERVE(4);
362 };
363
364 /**
365 * pci_dev_set_io_state - Set the new error state if possible.
366 *
367 * @dev: PCI device to set new error_state
368 * @new: the state we want dev to be in
369 *
370 * If the device is experiencing perm_failure, it has to remain in that state.
371 * Any other transition is allowed.
372 *
373 * Returns true if state has been changed to the requested state.
374 */
pci_dev_set_io_state(struct pci_dev * dev,pci_channel_state_t new)375 static inline bool pci_dev_set_io_state(struct pci_dev *dev,
376 pci_channel_state_t new)
377 {
378 pci_channel_state_t old;
379
380 switch (new) {
381 case pci_channel_io_perm_failure:
382 xchg(&dev->error_state, pci_channel_io_perm_failure);
383 return true;
384 case pci_channel_io_frozen:
385 old = cmpxchg(&dev->error_state, pci_channel_io_normal,
386 pci_channel_io_frozen);
387 return old != pci_channel_io_perm_failure;
388 case pci_channel_io_normal:
389 old = cmpxchg(&dev->error_state, pci_channel_io_frozen,
390 pci_channel_io_normal);
391 return old != pci_channel_io_perm_failure;
392 default:
393 return false;
394 }
395 }
396
pci_dev_set_disconnected(struct pci_dev * dev,void * unused)397 static inline int pci_dev_set_disconnected(struct pci_dev *dev, void *unused)
398 {
399 pci_dev_set_io_state(dev, pci_channel_io_perm_failure);
400
401 return 0;
402 }
403
pci_dev_is_disconnected(const struct pci_dev * dev)404 static inline bool pci_dev_is_disconnected(const struct pci_dev *dev)
405 {
406 return dev->error_state == pci_channel_io_perm_failure;
407 }
408
409 /* pci_dev priv_flags */
410 #define PCI_DEV_ADDED 0
411 #define PCI_DPC_RECOVERED 1
412 #define PCI_DPC_RECOVERING 2
413
pci_dev_assign_added(struct pci_dev * dev,bool added)414 static inline void pci_dev_assign_added(struct pci_dev *dev, bool added)
415 {
416 assign_bit(PCI_DEV_ADDED, &dev->priv_flags, added);
417 }
418
pci_dev_is_added(const struct pci_dev * dev)419 static inline bool pci_dev_is_added(const struct pci_dev *dev)
420 {
421 return test_bit(PCI_DEV_ADDED, &dev->priv_flags);
422 }
423
424 #ifdef CONFIG_PCIEAER
425 #include <linux/aer.h>
426
427 #define AER_MAX_MULTI_ERR_DEVICES 5 /* Not likely to have more */
428
429 struct aer_err_info {
430 struct pci_dev *dev[AER_MAX_MULTI_ERR_DEVICES];
431 int error_dev_num;
432
433 unsigned int id:16;
434
435 unsigned int severity:2; /* 0:NONFATAL | 1:FATAL | 2:COR */
436 unsigned int __pad1:5;
437 unsigned int multi_error_valid:1;
438
439 unsigned int first_error:5;
440 unsigned int __pad2:2;
441 unsigned int tlp_header_valid:1;
442
443 unsigned int status; /* COR/UNCOR Error Status */
444 unsigned int mask; /* COR/UNCOR Error Mask */
445 struct aer_header_log_regs tlp; /* TLP Header */
446 };
447
448 int aer_get_device_error_info(struct pci_dev *dev, struct aer_err_info *info);
449 void aer_print_error(struct pci_dev *dev, struct aer_err_info *info);
450 #endif /* CONFIG_PCIEAER */
451
452 #ifdef CONFIG_PCIEPORTBUS
453 /* Cached RCEC Endpoint Association */
454 struct rcec_ea {
455 u8 nextbusn;
456 u8 lastbusn;
457 u32 bitmap;
458 };
459 #endif
460
461 #ifdef CONFIG_PCIE_DPC
462 void pci_save_dpc_state(struct pci_dev *dev);
463 void pci_restore_dpc_state(struct pci_dev *dev);
464 void pci_dpc_init(struct pci_dev *pdev);
465 void dpc_process_error(struct pci_dev *pdev);
466 pci_ers_result_t dpc_reset_link(struct pci_dev *pdev);
467 bool pci_dpc_recovered(struct pci_dev *pdev);
468 #else
pci_save_dpc_state(struct pci_dev * dev)469 static inline void pci_save_dpc_state(struct pci_dev *dev) {}
pci_restore_dpc_state(struct pci_dev * dev)470 static inline void pci_restore_dpc_state(struct pci_dev *dev) {}
pci_dpc_init(struct pci_dev * pdev)471 static inline void pci_dpc_init(struct pci_dev *pdev) {}
pci_dpc_recovered(struct pci_dev * pdev)472 static inline bool pci_dpc_recovered(struct pci_dev *pdev) { return false; }
473 #endif
474
475 #ifdef CONFIG_PCIEPORTBUS
476 void pci_rcec_init(struct pci_dev *dev);
477 void pci_rcec_exit(struct pci_dev *dev);
478 void pcie_link_rcec(struct pci_dev *rcec);
479 void pcie_walk_rcec(struct pci_dev *rcec,
480 int (*cb)(struct pci_dev *, void *),
481 void *userdata);
482 #else
pci_rcec_init(struct pci_dev * dev)483 static inline void pci_rcec_init(struct pci_dev *dev) {}
pci_rcec_exit(struct pci_dev * dev)484 static inline void pci_rcec_exit(struct pci_dev *dev) {}
pcie_link_rcec(struct pci_dev * rcec)485 static inline void pcie_link_rcec(struct pci_dev *rcec) {}
pcie_walk_rcec(struct pci_dev * rcec,int (* cb)(struct pci_dev *,void *),void * userdata)486 static inline void pcie_walk_rcec(struct pci_dev *rcec,
487 int (*cb)(struct pci_dev *, void *),
488 void *userdata) {}
489 #endif
490
491 #ifdef CONFIG_PCI_ATS
492 /* Address Translation Service */
493 void pci_ats_init(struct pci_dev *dev);
494 void pci_restore_ats_state(struct pci_dev *dev);
495 #else
pci_ats_init(struct pci_dev * d)496 static inline void pci_ats_init(struct pci_dev *d) { }
pci_restore_ats_state(struct pci_dev * dev)497 static inline void pci_restore_ats_state(struct pci_dev *dev) { }
498 #endif /* CONFIG_PCI_ATS */
499
500 #ifdef CONFIG_PCI_PRI
501 void pci_pri_init(struct pci_dev *dev);
502 void pci_restore_pri_state(struct pci_dev *pdev);
503 #else
pci_pri_init(struct pci_dev * dev)504 static inline void pci_pri_init(struct pci_dev *dev) { }
pci_restore_pri_state(struct pci_dev * pdev)505 static inline void pci_restore_pri_state(struct pci_dev *pdev) { }
506 #endif
507
508 #ifdef CONFIG_PCI_PASID
509 void pci_pasid_init(struct pci_dev *dev);
510 void pci_restore_pasid_state(struct pci_dev *pdev);
511 #else
pci_pasid_init(struct pci_dev * dev)512 static inline void pci_pasid_init(struct pci_dev *dev) { }
pci_restore_pasid_state(struct pci_dev * pdev)513 static inline void pci_restore_pasid_state(struct pci_dev *pdev) { }
514 #endif
515
516 #ifdef CONFIG_PCI_IOV
517 int pci_iov_init(struct pci_dev *dev);
518 void pci_iov_release(struct pci_dev *dev);
519 void pci_iov_remove(struct pci_dev *dev);
520 void pci_iov_update_resource(struct pci_dev *dev, int resno);
521 resource_size_t pci_sriov_resource_alignment(struct pci_dev *dev, int resno);
522 void pci_restore_iov_state(struct pci_dev *dev);
523 int pci_iov_bus_range(struct pci_bus *bus);
524 extern const struct attribute_group sriov_pf_dev_attr_group;
525 extern const struct attribute_group sriov_vf_dev_attr_group;
526 #else
pci_iov_init(struct pci_dev * dev)527 static inline int pci_iov_init(struct pci_dev *dev)
528 {
529 return -ENODEV;
530 }
pci_iov_release(struct pci_dev * dev)531 static inline void pci_iov_release(struct pci_dev *dev)
532
533 {
534 }
pci_iov_remove(struct pci_dev * dev)535 static inline void pci_iov_remove(struct pci_dev *dev)
536 {
537 }
pci_restore_iov_state(struct pci_dev * dev)538 static inline void pci_restore_iov_state(struct pci_dev *dev)
539 {
540 }
pci_iov_bus_range(struct pci_bus * bus)541 static inline int pci_iov_bus_range(struct pci_bus *bus)
542 {
543 return 0;
544 }
545
546 #endif /* CONFIG_PCI_IOV */
547
548 #ifdef CONFIG_PCIE_PTM
549 void pci_save_ptm_state(struct pci_dev *dev);
550 void pci_restore_ptm_state(struct pci_dev *dev);
551 void pci_disable_ptm(struct pci_dev *dev);
552 #else
pci_save_ptm_state(struct pci_dev * dev)553 static inline void pci_save_ptm_state(struct pci_dev *dev) { }
pci_restore_ptm_state(struct pci_dev * dev)554 static inline void pci_restore_ptm_state(struct pci_dev *dev) { }
pci_disable_ptm(struct pci_dev * dev)555 static inline void pci_disable_ptm(struct pci_dev *dev) { }
556 #endif
557
558 unsigned long pci_cardbus_resource_alignment(struct resource *);
559
pci_resource_alignment(struct pci_dev * dev,struct resource * res)560 static inline resource_size_t pci_resource_alignment(struct pci_dev *dev,
561 struct resource *res)
562 {
563 #ifdef CONFIG_PCI_IOV
564 int resno = res - dev->resource;
565
566 if (resno >= PCI_IOV_RESOURCES && resno <= PCI_IOV_RESOURCE_END)
567 return pci_sriov_resource_alignment(dev, resno);
568 #endif
569 if (dev->class >> 8 == PCI_CLASS_BRIDGE_CARDBUS)
570 return pci_cardbus_resource_alignment(res);
571 return resource_alignment(res);
572 }
573
574 void pci_acs_init(struct pci_dev *dev);
575 #ifdef CONFIG_PCI_QUIRKS
576 int pci_dev_specific_acs_enabled(struct pci_dev *dev, u16 acs_flags);
577 int pci_dev_specific_enable_acs(struct pci_dev *dev);
578 int pci_dev_specific_disable_acs_redir(struct pci_dev *dev);
579 #else
pci_dev_specific_acs_enabled(struct pci_dev * dev,u16 acs_flags)580 static inline int pci_dev_specific_acs_enabled(struct pci_dev *dev,
581 u16 acs_flags)
582 {
583 return -ENOTTY;
584 }
pci_dev_specific_enable_acs(struct pci_dev * dev)585 static inline int pci_dev_specific_enable_acs(struct pci_dev *dev)
586 {
587 return -ENOTTY;
588 }
pci_dev_specific_disable_acs_redir(struct pci_dev * dev)589 static inline int pci_dev_specific_disable_acs_redir(struct pci_dev *dev)
590 {
591 return -ENOTTY;
592 }
593 #endif
594
595 /* PCI error reporting and recovery */
596 pci_ers_result_t pcie_do_recovery(struct pci_dev *dev,
597 pci_channel_state_t state,
598 pci_ers_result_t (*reset_subordinates)(struct pci_dev *pdev));
599
600 bool pcie_wait_for_link(struct pci_dev *pdev, bool active);
601 #ifdef CONFIG_PCIEASPM
602 void pcie_aspm_init_link_state(struct pci_dev *pdev);
603 void pcie_aspm_exit_link_state(struct pci_dev *pdev);
604 void pcie_aspm_pm_state_change(struct pci_dev *pdev);
605 void pcie_aspm_powersave_config_link(struct pci_dev *pdev);
606 #else
pcie_aspm_init_link_state(struct pci_dev * pdev)607 static inline void pcie_aspm_init_link_state(struct pci_dev *pdev) { }
pcie_aspm_exit_link_state(struct pci_dev * pdev)608 static inline void pcie_aspm_exit_link_state(struct pci_dev *pdev) { }
pcie_aspm_pm_state_change(struct pci_dev * pdev)609 static inline void pcie_aspm_pm_state_change(struct pci_dev *pdev) { }
pcie_aspm_powersave_config_link(struct pci_dev * pdev)610 static inline void pcie_aspm_powersave_config_link(struct pci_dev *pdev) { }
611 #endif
612
613 #ifdef CONFIG_PCIE_ECRC
614 void pcie_set_ecrc_checking(struct pci_dev *dev);
615 void pcie_ecrc_get_policy(char *str);
616 #else
pcie_set_ecrc_checking(struct pci_dev * dev)617 static inline void pcie_set_ecrc_checking(struct pci_dev *dev) { }
pcie_ecrc_get_policy(char * str)618 static inline void pcie_ecrc_get_policy(char *str) { }
619 #endif
620
621 #ifdef CONFIG_PCIE_PTM
622 void pci_ptm_init(struct pci_dev *dev);
623 #else
pci_ptm_init(struct pci_dev * dev)624 static inline void pci_ptm_init(struct pci_dev *dev) { }
625 #endif
626
627 struct pci_dev_reset_methods {
628 u16 vendor;
629 u16 device;
630 int (*reset)(struct pci_dev *dev, bool probe);
631 };
632
633 struct pci_reset_fn_method {
634 int (*reset_fn)(struct pci_dev *pdev, bool probe);
635 char *name;
636 };
637
638 #ifdef CONFIG_PCI_QUIRKS
639 int pci_dev_specific_reset(struct pci_dev *dev, bool probe);
640 #else
pci_dev_specific_reset(struct pci_dev * dev,bool probe)641 static inline int pci_dev_specific_reset(struct pci_dev *dev, bool probe)
642 {
643 return -ENOTTY;
644 }
645 #endif
646
647 #if defined(CONFIG_PCI_QUIRKS) && defined(CONFIG_ARM64)
648 int acpi_get_rc_resources(struct device *dev, const char *hid, u16 segment,
649 struct resource *res);
650 #else
acpi_get_rc_resources(struct device * dev,const char * hid,u16 segment,struct resource * res)651 static inline int acpi_get_rc_resources(struct device *dev, const char *hid,
652 u16 segment, struct resource *res)
653 {
654 return -ENODEV;
655 }
656 #endif
657
658 int pci_rebar_get_current_size(struct pci_dev *pdev, int bar);
659 int pci_rebar_set_size(struct pci_dev *pdev, int bar, int size);
pci_rebar_size_to_bytes(int size)660 static inline u64 pci_rebar_size_to_bytes(int size)
661 {
662 return 1ULL << (size + 20);
663 }
664
665 struct device_node;
666
667 #ifdef CONFIG_OF
668 int of_pci_parse_bus_range(struct device_node *node, struct resource *res);
669 int of_get_pci_domain_nr(struct device_node *node);
670 int of_pci_get_max_link_speed(struct device_node *node);
671 void pci_set_of_node(struct pci_dev *dev);
672 void pci_release_of_node(struct pci_dev *dev);
673 void pci_set_bus_of_node(struct pci_bus *bus);
674 void pci_release_bus_of_node(struct pci_bus *bus);
675
676 int devm_of_pci_bridge_init(struct device *dev, struct pci_host_bridge *bridge);
677
678 #else
679 static inline int
of_pci_parse_bus_range(struct device_node * node,struct resource * res)680 of_pci_parse_bus_range(struct device_node *node, struct resource *res)
681 {
682 return -EINVAL;
683 }
684
685 static inline int
of_get_pci_domain_nr(struct device_node * node)686 of_get_pci_domain_nr(struct device_node *node)
687 {
688 return -1;
689 }
690
691 static inline int
of_pci_get_max_link_speed(struct device_node * node)692 of_pci_get_max_link_speed(struct device_node *node)
693 {
694 return -EINVAL;
695 }
696
pci_set_of_node(struct pci_dev * dev)697 static inline void pci_set_of_node(struct pci_dev *dev) { }
pci_release_of_node(struct pci_dev * dev)698 static inline void pci_release_of_node(struct pci_dev *dev) { }
pci_set_bus_of_node(struct pci_bus * bus)699 static inline void pci_set_bus_of_node(struct pci_bus *bus) { }
pci_release_bus_of_node(struct pci_bus * bus)700 static inline void pci_release_bus_of_node(struct pci_bus *bus) { }
701
devm_of_pci_bridge_init(struct device * dev,struct pci_host_bridge * bridge)702 static inline int devm_of_pci_bridge_init(struct device *dev, struct pci_host_bridge *bridge)
703 {
704 return 0;
705 }
706
707 #endif /* CONFIG_OF */
708
709 #ifdef CONFIG_PCIEAER
710 void pci_no_aer(void);
711 void pci_aer_init(struct pci_dev *dev);
712 void pci_aer_exit(struct pci_dev *dev);
713 extern const struct attribute_group aer_stats_attr_group;
714 void pci_aer_clear_fatal_status(struct pci_dev *dev);
715 int pci_aer_clear_status(struct pci_dev *dev);
716 int pci_aer_raw_clear_status(struct pci_dev *dev);
717 #else
pci_no_aer(void)718 static inline void pci_no_aer(void) { }
pci_aer_init(struct pci_dev * d)719 static inline void pci_aer_init(struct pci_dev *d) { }
pci_aer_exit(struct pci_dev * d)720 static inline void pci_aer_exit(struct pci_dev *d) { }
pci_aer_clear_fatal_status(struct pci_dev * dev)721 static inline void pci_aer_clear_fatal_status(struct pci_dev *dev) { }
pci_aer_clear_status(struct pci_dev * dev)722 static inline int pci_aer_clear_status(struct pci_dev *dev) { return -EINVAL; }
pci_aer_raw_clear_status(struct pci_dev * dev)723 static inline int pci_aer_raw_clear_status(struct pci_dev *dev) { return -EINVAL; }
724 #endif
725
726 #ifdef CONFIG_ACPI
727 int pci_acpi_program_hp_params(struct pci_dev *dev);
728 extern const struct attribute_group pci_dev_acpi_attr_group;
729 void pci_set_acpi_fwnode(struct pci_dev *dev);
730 int pci_dev_acpi_reset(struct pci_dev *dev, bool probe);
731 #else
pci_dev_acpi_reset(struct pci_dev * dev,bool probe)732 static inline int pci_dev_acpi_reset(struct pci_dev *dev, bool probe)
733 {
734 return -ENOTTY;
735 }
736
pci_set_acpi_fwnode(struct pci_dev * dev)737 static inline void pci_set_acpi_fwnode(struct pci_dev *dev) {}
pci_acpi_program_hp_params(struct pci_dev * dev)738 static inline int pci_acpi_program_hp_params(struct pci_dev *dev)
739 {
740 return -ENODEV;
741 }
742 #endif
743
744 #ifdef CONFIG_PCIEASPM
745 extern const struct attribute_group aspm_ctrl_attr_group;
746 #endif
747
748 extern const struct attribute_group pci_dev_reset_method_attr_group;
749
750 #endif /* DRIVERS_PCI_H */
751