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