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