Linux Audio

Check our new training course

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