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 #define PCIE_LINK_RETRAIN_TIMEOUT_MS	1000
16 
17 /*
18  * Power stable to PERST# inactive.
19  *
20  * See the "Power Sequencing and Reset Signal Timings" table of the PCI Express
21  * Card Electromechanical Specification, Revision 5.1, Section 2.9.2, Symbol
22  * "T_PVPERL".
23  */
24 #define PCIE_T_PVPERL_MS		100
25 
26 /*
27  * REFCLK stable before PERST# inactive.
28  *
29  * See the "Power Sequencing and Reset Signal Timings" table of the PCI Express
30  * Card Electromechanical Specification, Revision 5.1, Section 2.9.2, Symbol
31  * "T_PERST-CLK".
32  */
33 #define PCIE_T_PERST_CLK_US		100
34 
35 /*
36  * End of conventional reset (PERST# de-asserted) to first configuration
37  * request (device able to respond with a "Request Retry Status" completion),
38  * from PCIe r6.0, sec 6.6.1.
39  */
40 #define PCIE_T_RRS_READY_MS	100
41 
42 /*
43  * PCIe r6.0, sec 5.3.3.2.1 <PME Synchronization>
44  * Recommends 1ms to 10ms timeout to check L2 ready.
45  */
46 #define PCIE_PME_TO_L2_TIMEOUT_US	10000
47 
48 /*
49  * PCIe r6.0, sec 6.6.1 <Conventional Reset>
50  *
51  * - "With a Downstream Port that does not support Link speeds greater
52  *    than 5.0 GT/s, software must wait a minimum of 100 ms following exit
53  *    from a Conventional Reset before sending a Configuration Request to
54  *    the device immediately below that Port."
55  *
56  * - "With a Downstream Port that supports Link speeds greater than
57  *    5.0 GT/s, software must wait a minimum of 100 ms after Link training
58  *    completes before sending a Configuration Request to the device
59  *    immediately below that Port."
60  */
61 #define PCIE_RESET_CONFIG_WAIT_MS	100
62 
63 /* Message Routing (r[2:0]); PCIe r6.0, sec 2.2.8 */
64 #define PCIE_MSG_TYPE_R_RC	0
65 #define PCIE_MSG_TYPE_R_ADDR	1
66 #define PCIE_MSG_TYPE_R_ID	2
67 #define PCIE_MSG_TYPE_R_BC	3
68 #define PCIE_MSG_TYPE_R_LOCAL	4
69 #define PCIE_MSG_TYPE_R_GATHER	5
70 
71 /* Power Management Messages; PCIe r6.0, sec 2.2.8.2 */
72 #define PCIE_MSG_CODE_PME_TURN_OFF	0x19
73 
74 /* INTx Mechanism Messages; PCIe r6.0, sec 2.2.8.1 */
75 #define PCIE_MSG_CODE_ASSERT_INTA	0x20
76 #define PCIE_MSG_CODE_ASSERT_INTB	0x21
77 #define PCIE_MSG_CODE_ASSERT_INTC	0x22
78 #define PCIE_MSG_CODE_ASSERT_INTD	0x23
79 #define PCIE_MSG_CODE_DEASSERT_INTA	0x24
80 #define PCIE_MSG_CODE_DEASSERT_INTB	0x25
81 #define PCIE_MSG_CODE_DEASSERT_INTC	0x26
82 #define PCIE_MSG_CODE_DEASSERT_INTD	0x27
83 
84 extern const unsigned char pcie_link_speed[];
85 extern bool pci_early_dump;
86 
87 bool pcie_cap_has_lnkctl(const struct pci_dev *dev);
88 bool pcie_cap_has_lnkctl2(const struct pci_dev *dev);
89 bool pcie_cap_has_rtctl(const struct pci_dev *dev);
90 
91 /* Functions internal to the PCI core code */
92 
93 #ifdef CONFIG_DMI
94 extern const struct attribute_group pci_dev_smbios_attr_group;
95 #endif
96 
97 enum pci_mmap_api {
98 	PCI_MMAP_SYSFS,	/* mmap on /sys/bus/pci/devices/<BDF>/resource<N> */
99 	PCI_MMAP_PROCFS	/* mmap on /proc/bus/pci/<BDF> */
100 };
101 int pci_mmap_fits(struct pci_dev *pdev, int resno, struct vm_area_struct *vmai,
102 		  enum pci_mmap_api mmap_api);
103 
104 bool pci_reset_supported(struct pci_dev *dev);
105 void pci_init_reset_methods(struct pci_dev *dev);
106 int pci_bridge_secondary_bus_reset(struct pci_dev *dev);
107 int pci_bus_error_reset(struct pci_dev *dev);
108 int __pci_reset_bus(struct pci_bus *bus);
109 
110 struct pci_cap_saved_data {
111 	u16		cap_nr;
112 	bool		cap_extended;
113 	unsigned int	size;
114 	u32		data[];
115 };
116 
117 struct pci_cap_saved_state {
118 	struct hlist_node		next;
119 	struct pci_cap_saved_data	cap;
120 };
121 
122 void pci_allocate_cap_save_buffers(struct pci_dev *dev);
123 void pci_free_cap_save_buffers(struct pci_dev *dev);
124 int pci_add_cap_save_buffer(struct pci_dev *dev, char cap, unsigned int size);
125 int pci_add_ext_cap_save_buffer(struct pci_dev *dev,
126 				u16 cap, unsigned int size);
127 struct pci_cap_saved_state *pci_find_saved_cap(struct pci_dev *dev, char cap);
128 struct pci_cap_saved_state *pci_find_saved_ext_cap(struct pci_dev *dev,
129 						   u16 cap);
130 
131 #define PCI_PM_D2_DELAY         200	/* usec; see PCIe r4.0, sec 5.9.1 */
132 #define PCI_PM_D3HOT_WAIT       10	/* msec */
133 #define PCI_PM_D3COLD_WAIT      100	/* msec */
134 
135 void pci_update_current_state(struct pci_dev *dev, pci_power_t state);
136 void pci_refresh_power_state(struct pci_dev *dev);
137 int pci_power_up(struct pci_dev *dev);
138 void pci_disable_enabled_device(struct pci_dev *dev);
139 int pci_finish_runtime_suspend(struct pci_dev *dev);
140 void pcie_clear_device_status(struct pci_dev *dev);
141 void pcie_clear_root_pme_status(struct pci_dev *dev);
142 bool pci_check_pme_status(struct pci_dev *dev);
143 void pci_pme_wakeup_bus(struct pci_bus *bus);
144 void pci_pme_restore(struct pci_dev *dev);
145 bool pci_dev_need_resume(struct pci_dev *dev);
146 void pci_dev_adjust_pme(struct pci_dev *dev);
147 void pci_dev_complete_resume(struct pci_dev *pci_dev);
148 void pci_config_pm_runtime_get(struct pci_dev *dev);
149 void pci_config_pm_runtime_put(struct pci_dev *dev);
150 void pci_pm_init(struct pci_dev *dev);
151 void pci_ea_init(struct pci_dev *dev);
152 void pci_msi_init(struct pci_dev *dev);
153 void pci_msix_init(struct pci_dev *dev);
154 bool pci_bridge_d3_possible(struct pci_dev *dev);
155 void pci_bridge_d3_update(struct pci_dev *dev);
156 int pci_bridge_wait_for_secondary_bus(struct pci_dev *dev, char *reset_type);
157 
pci_bus_rrs_vendor_id(u32 l)158 static inline bool pci_bus_rrs_vendor_id(u32 l)
159 {
160 	return (l & 0xffff) == PCI_VENDOR_ID_PCI_SIG;
161 }
162 
pci_wakeup_event(struct pci_dev * dev)163 static inline void pci_wakeup_event(struct pci_dev *dev)
164 {
165 	/* Wait 100 ms before the system can be put into a sleep state. */
166 	pm_wakeup_event(&dev->dev, 100);
167 }
168 
169 /**
170  * pci_bar_index_is_valid - Check whether a BAR index is within valid range
171  * @bar: BAR index
172  *
173  * Protects against overflowing &struct pci_dev.resource array.
174  *
175  * Return: true for valid index, false otherwise.
176  */
pci_bar_index_is_valid(int bar)177 static inline bool pci_bar_index_is_valid(int bar)
178 {
179 	if (bar >= 0 && bar < PCI_NUM_RESOURCES)
180 		return true;
181 
182 	return false;
183 }
184 
pci_has_subordinate(struct pci_dev * pci_dev)185 static inline bool pci_has_subordinate(struct pci_dev *pci_dev)
186 {
187 	return !!(pci_dev->subordinate);
188 }
189 
pci_power_manageable(struct pci_dev * pci_dev)190 static inline bool pci_power_manageable(struct pci_dev *pci_dev)
191 {
192 	/*
193 	 * Currently we allow normal PCI devices and PCI bridges transition
194 	 * into D3 if their bridge_d3 is set.
195 	 */
196 	return !pci_has_subordinate(pci_dev) || pci_dev->bridge_d3;
197 }
198 
pcie_downstream_port(const struct pci_dev * dev)199 static inline bool pcie_downstream_port(const struct pci_dev *dev)
200 {
201 	int type = pci_pcie_type(dev);
202 
203 	return type == PCI_EXP_TYPE_ROOT_PORT ||
204 	       type == PCI_EXP_TYPE_DOWNSTREAM ||
205 	       type == PCI_EXP_TYPE_PCIE_BRIDGE;
206 }
207 
208 void pci_vpd_init(struct pci_dev *dev);
209 extern const struct attribute_group pci_dev_vpd_attr_group;
210 
211 /* PCI Virtual Channel */
212 int pci_save_vc_state(struct pci_dev *dev);
213 void pci_restore_vc_state(struct pci_dev *dev);
214 void pci_allocate_vc_save_buffers(struct pci_dev *dev);
215 
216 /* PCI /proc functions */
217 #ifdef CONFIG_PROC_FS
218 int pci_proc_attach_device(struct pci_dev *dev);
219 int pci_proc_detach_device(struct pci_dev *dev);
220 int pci_proc_detach_bus(struct pci_bus *bus);
221 #else
pci_proc_attach_device(struct pci_dev * dev)222 static inline int pci_proc_attach_device(struct pci_dev *dev) { return 0; }
pci_proc_detach_device(struct pci_dev * dev)223 static inline int pci_proc_detach_device(struct pci_dev *dev) { return 0; }
pci_proc_detach_bus(struct pci_bus * bus)224 static inline int pci_proc_detach_bus(struct pci_bus *bus) { return 0; }
225 #endif
226 
227 /* Functions for PCI Hotplug drivers to use */
228 int pci_hp_add_bridge(struct pci_dev *dev);
229 
230 #if defined(CONFIG_SYSFS) && defined(HAVE_PCI_LEGACY)
231 void pci_create_legacy_files(struct pci_bus *bus);
232 void pci_remove_legacy_files(struct pci_bus *bus);
233 #else
pci_create_legacy_files(struct pci_bus * bus)234 static inline void pci_create_legacy_files(struct pci_bus *bus) { }
pci_remove_legacy_files(struct pci_bus * bus)235 static inline void pci_remove_legacy_files(struct pci_bus *bus) { }
236 #endif
237 
238 /* Lock for read/write access to pci device and bus lists */
239 extern struct rw_semaphore pci_bus_sem;
240 extern struct mutex pci_slot_mutex;
241 
242 extern raw_spinlock_t pci_lock;
243 
244 extern unsigned int pci_pm_d3hot_delay;
245 
246 #ifdef CONFIG_PCI_MSI
247 void pci_no_msi(void);
248 #else
pci_no_msi(void)249 static inline void pci_no_msi(void) { }
250 #endif
251 
252 void pci_realloc_get_opt(char *);
253 
pci_no_d1d2(struct pci_dev * dev)254 static inline int pci_no_d1d2(struct pci_dev *dev)
255 {
256 	unsigned int parent_dstates = 0;
257 
258 	if (dev->bus->self)
259 		parent_dstates = dev->bus->self->no_d1d2;
260 	return (dev->no_d1d2 || parent_dstates);
261 
262 }
263 
264 #ifdef CONFIG_SYSFS
265 int pci_create_sysfs_dev_files(struct pci_dev *pdev);
266 void pci_remove_sysfs_dev_files(struct pci_dev *pdev);
267 extern const struct attribute_group *pci_dev_groups[];
268 extern const struct attribute_group *pci_dev_attr_groups[];
269 extern const struct attribute_group *pcibus_groups[];
270 extern const struct attribute_group *pci_bus_groups[];
271 #else
pci_create_sysfs_dev_files(struct pci_dev * pdev)272 static inline int pci_create_sysfs_dev_files(struct pci_dev *pdev) { return 0; }
pci_remove_sysfs_dev_files(struct pci_dev * pdev)273 static inline void pci_remove_sysfs_dev_files(struct pci_dev *pdev) { }
274 #define pci_dev_groups NULL
275 #define pci_dev_attr_groups NULL
276 #define pcibus_groups NULL
277 #define pci_bus_groups NULL
278 #endif
279 
280 extern unsigned long pci_hotplug_io_size;
281 extern unsigned long pci_hotplug_mmio_size;
282 extern unsigned long pci_hotplug_mmio_pref_size;
283 extern unsigned long pci_hotplug_bus_size;
284 
285 /**
286  * pci_match_one_device - Tell if a PCI device structure has a matching
287  *			  PCI device id structure
288  * @id: single PCI device id structure to match
289  * @dev: the PCI device structure to match against
290  *
291  * Returns the matching pci_device_id structure or %NULL if there is no match.
292  */
293 static inline const struct pci_device_id *
pci_match_one_device(const struct pci_device_id * id,const struct pci_dev * dev)294 pci_match_one_device(const struct pci_device_id *id, const struct pci_dev *dev)
295 {
296 	if ((id->vendor == PCI_ANY_ID || id->vendor == dev->vendor) &&
297 	    (id->device == PCI_ANY_ID || id->device == dev->device) &&
298 	    (id->subvendor == PCI_ANY_ID || id->subvendor == dev->subsystem_vendor) &&
299 	    (id->subdevice == PCI_ANY_ID || id->subdevice == dev->subsystem_device) &&
300 	    !((id->class ^ dev->class) & id->class_mask))
301 		return id;
302 	return NULL;
303 }
304 
305 /* PCI slot sysfs helper code */
306 #define to_pci_slot(s) container_of(s, struct pci_slot, kobj)
307 
308 extern struct kset *pci_slots_kset;
309 
310 struct pci_slot_attribute {
311 	struct attribute attr;
312 	ssize_t (*show)(struct pci_slot *, char *);
313 	ssize_t (*store)(struct pci_slot *, const char *, size_t);
314 };
315 #define to_pci_slot_attr(s) container_of(s, struct pci_slot_attribute, attr)
316 
317 enum pci_bar_type {
318 	pci_bar_unknown,	/* Standard PCI BAR probe */
319 	pci_bar_io,		/* An I/O port BAR */
320 	pci_bar_mem32,		/* A 32-bit memory BAR */
321 	pci_bar_mem64,		/* A 64-bit memory BAR */
322 };
323 
324 struct device *pci_get_host_bridge_device(struct pci_dev *dev);
325 void pci_put_host_bridge_device(struct device *dev);
326 
327 int pci_configure_extended_tags(struct pci_dev *dev, void *ign);
328 bool pci_bus_read_dev_vendor_id(struct pci_bus *bus, int devfn, u32 *pl,
329 				int rrs_timeout);
330 bool pci_bus_generic_read_dev_vendor_id(struct pci_bus *bus, int devfn, u32 *pl,
331 					int rrs_timeout);
332 int pci_idt_bus_quirk(struct pci_bus *bus, int devfn, u32 *pl, int rrs_timeout);
333 
334 int pci_setup_device(struct pci_dev *dev);
335 int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
336 		    struct resource *res, unsigned int reg);
337 void pci_configure_ari(struct pci_dev *dev);
338 void __pci_bus_size_bridges(struct pci_bus *bus,
339 			struct list_head *realloc_head);
340 void __pci_bus_assign_resources(const struct pci_bus *bus,
341 				struct list_head *realloc_head,
342 				struct list_head *fail_head);
343 bool pci_bus_clip_resource(struct pci_dev *dev, int idx);
344 
345 const char *pci_resource_name(struct pci_dev *dev, unsigned int i);
346 
347 void pci_reassigndev_resource_alignment(struct pci_dev *dev);
348 void pci_disable_bridge_window(struct pci_dev *dev);
349 struct pci_bus *pci_bus_get(struct pci_bus *bus);
350 void pci_bus_put(struct pci_bus *bus);
351 
352 /* PCIe link information from Link Capabilities 2 */
353 #define PCIE_LNKCAP2_SLS2SPEED(lnkcap2) \
354 	((lnkcap2) & PCI_EXP_LNKCAP2_SLS_64_0GB ? PCIE_SPEED_64_0GT : \
355 	 (lnkcap2) & PCI_EXP_LNKCAP2_SLS_32_0GB ? PCIE_SPEED_32_0GT : \
356 	 (lnkcap2) & PCI_EXP_LNKCAP2_SLS_16_0GB ? PCIE_SPEED_16_0GT : \
357 	 (lnkcap2) & PCI_EXP_LNKCAP2_SLS_8_0GB ? PCIE_SPEED_8_0GT : \
358 	 (lnkcap2) & PCI_EXP_LNKCAP2_SLS_5_0GB ? PCIE_SPEED_5_0GT : \
359 	 (lnkcap2) & PCI_EXP_LNKCAP2_SLS_2_5GB ? PCIE_SPEED_2_5GT : \
360 	 PCI_SPEED_UNKNOWN)
361 
362 /* PCIe speed to Mb/s reduced by encoding overhead */
363 #define PCIE_SPEED2MBS_ENC(speed) \
364 	((speed) == PCIE_SPEED_64_0GT ? 64000*1/1 : \
365 	 (speed) == PCIE_SPEED_32_0GT ? 32000*128/130 : \
366 	 (speed) == PCIE_SPEED_16_0GT ? 16000*128/130 : \
367 	 (speed) == PCIE_SPEED_8_0GT  ?  8000*128/130 : \
368 	 (speed) == PCIE_SPEED_5_0GT  ?  5000*8/10 : \
369 	 (speed) == PCIE_SPEED_2_5GT  ?  2500*8/10 : \
370 	 0)
371 
pcie_dev_speed_mbps(enum pci_bus_speed speed)372 static inline int pcie_dev_speed_mbps(enum pci_bus_speed speed)
373 {
374 	switch (speed) {
375 	case PCIE_SPEED_2_5GT:
376 		return 2500;
377 	case PCIE_SPEED_5_0GT:
378 		return 5000;
379 	case PCIE_SPEED_8_0GT:
380 		return 8000;
381 	case PCIE_SPEED_16_0GT:
382 		return 16000;
383 	case PCIE_SPEED_32_0GT:
384 		return 32000;
385 	case PCIE_SPEED_64_0GT:
386 		return 64000;
387 	default:
388 		break;
389 	}
390 
391 	return -EINVAL;
392 }
393 
394 const char *pci_speed_string(enum pci_bus_speed speed);
395 enum pci_bus_speed pcie_get_speed_cap(struct pci_dev *dev);
396 enum pcie_link_width pcie_get_width_cap(struct pci_dev *dev);
397 void __pcie_print_link_status(struct pci_dev *dev, bool verbose);
398 void pcie_report_downtraining(struct pci_dev *dev);
399 void pcie_update_link_speed(struct pci_bus *bus, u16 link_status);
400 
401 /* Single Root I/O Virtualization */
402 struct pci_sriov {
403 	int		pos;		/* Capability position */
404 	int		nres;		/* Number of resources */
405 	u32		cap;		/* SR-IOV Capabilities */
406 	u16		ctrl;		/* SR-IOV Control */
407 	u16		total_VFs;	/* Total VFs associated with the PF */
408 	u16		initial_VFs;	/* Initial VFs associated with the PF */
409 	u16		num_VFs;	/* Number of VFs available */
410 	u16		offset;		/* First VF Routing ID offset */
411 	u16		stride;		/* Following VF stride */
412 	u16		vf_device;	/* VF device ID */
413 	u32		pgsz;		/* Page size for BAR alignment */
414 	u8		link;		/* Function Dependency Link */
415 	u8		max_VF_buses;	/* Max buses consumed by VFs */
416 	u16		driver_max_VFs;	/* Max num VFs driver supports */
417 	struct pci_dev	*dev;		/* Lowest numbered PF */
418 	struct pci_dev	*self;		/* This PF */
419 	u32		class;		/* VF device */
420 	u8		hdr_type;	/* VF header type */
421 	u16		subsystem_vendor; /* VF subsystem vendor */
422 	u16		subsystem_device; /* VF subsystem device */
423 	resource_size_t	barsz[PCI_SRIOV_NUM_BARS];	/* VF BAR size */
424 	bool		drivers_autoprobe; /* Auto probing of VFs by driver */
425 
426 	ANDROID_KABI_RESERVE(1);
427 	ANDROID_KABI_RESERVE(2);
428 	ANDROID_KABI_RESERVE(3);
429 	ANDROID_KABI_RESERVE(4);
430 };
431 
432 #ifdef CONFIG_PCI_DOE
433 void pci_doe_init(struct pci_dev *pdev);
434 void pci_doe_destroy(struct pci_dev *pdev);
435 void pci_doe_disconnected(struct pci_dev *pdev);
436 #else
pci_doe_init(struct pci_dev * pdev)437 static inline void pci_doe_init(struct pci_dev *pdev) { }
pci_doe_destroy(struct pci_dev * pdev)438 static inline void pci_doe_destroy(struct pci_dev *pdev) { }
pci_doe_disconnected(struct pci_dev * pdev)439 static inline void pci_doe_disconnected(struct pci_dev *pdev) { }
440 #endif
441 
442 #ifdef CONFIG_PCI_NPEM
443 void pci_npem_create(struct pci_dev *dev);
444 void pci_npem_remove(struct pci_dev *dev);
445 #else
pci_npem_create(struct pci_dev * dev)446 static inline void pci_npem_create(struct pci_dev *dev) { }
pci_npem_remove(struct pci_dev * dev)447 static inline void pci_npem_remove(struct pci_dev *dev) { }
448 #endif
449 
450 /**
451  * pci_dev_set_io_state - Set the new error state if possible.
452  *
453  * @dev: PCI device to set new error_state
454  * @new: the state we want dev to be in
455  *
456  * If the device is experiencing perm_failure, it has to remain in that state.
457  * Any other transition is allowed.
458  *
459  * Returns true if state has been changed to the requested state.
460  */
pci_dev_set_io_state(struct pci_dev * dev,pci_channel_state_t new)461 static inline bool pci_dev_set_io_state(struct pci_dev *dev,
462 					pci_channel_state_t new)
463 {
464 	pci_channel_state_t old;
465 
466 	switch (new) {
467 	case pci_channel_io_perm_failure:
468 		xchg(&dev->error_state, pci_channel_io_perm_failure);
469 		return true;
470 	case pci_channel_io_frozen:
471 		old = cmpxchg(&dev->error_state, pci_channel_io_normal,
472 			      pci_channel_io_frozen);
473 		return old != pci_channel_io_perm_failure;
474 	case pci_channel_io_normal:
475 		old = cmpxchg(&dev->error_state, pci_channel_io_frozen,
476 			      pci_channel_io_normal);
477 		return old != pci_channel_io_perm_failure;
478 	default:
479 		return false;
480 	}
481 }
482 
pci_dev_set_disconnected(struct pci_dev * dev,void * unused)483 static inline int pci_dev_set_disconnected(struct pci_dev *dev, void *unused)
484 {
485 	pci_dev_set_io_state(dev, pci_channel_io_perm_failure);
486 	pci_doe_disconnected(dev);
487 
488 	return 0;
489 }
490 
491 /* pci_dev priv_flags */
492 #define PCI_DEV_ADDED 0
493 #define PCI_DPC_RECOVERED 1
494 #define PCI_DPC_RECOVERING 2
495 
pci_dev_assign_added(struct pci_dev * dev,bool added)496 static inline void pci_dev_assign_added(struct pci_dev *dev, bool added)
497 {
498 	assign_bit(PCI_DEV_ADDED, &dev->priv_flags, added);
499 }
500 
pci_dev_is_added(const struct pci_dev * dev)501 static inline bool pci_dev_is_added(const struct pci_dev *dev)
502 {
503 	return test_bit(PCI_DEV_ADDED, &dev->priv_flags);
504 }
505 
506 #ifdef CONFIG_PCIEAER
507 #include <linux/aer.h>
508 
509 #define AER_MAX_MULTI_ERR_DEVICES	5	/* Not likely to have more */
510 
511 struct aer_err_info {
512 	struct pci_dev *dev[AER_MAX_MULTI_ERR_DEVICES];
513 	int error_dev_num;
514 
515 	unsigned int id:16;
516 
517 	unsigned int severity:2;	/* 0:NONFATAL | 1:FATAL | 2:COR */
518 	unsigned int __pad1:5;
519 	unsigned int multi_error_valid:1;
520 
521 	unsigned int first_error:5;
522 	unsigned int __pad2:2;
523 	unsigned int tlp_header_valid:1;
524 
525 	unsigned int status;		/* COR/UNCOR Error Status */
526 	unsigned int mask;		/* COR/UNCOR Error Mask */
527 	struct pcie_tlp_log tlp;	/* TLP Header */
528 };
529 
530 int aer_get_device_error_info(struct pci_dev *dev, struct aer_err_info *info);
531 void aer_print_error(struct pci_dev *dev, struct aer_err_info *info);
532 #endif	/* CONFIG_PCIEAER */
533 
534 #ifdef CONFIG_PCIEPORTBUS
535 /* Cached RCEC Endpoint Association */
536 struct rcec_ea {
537 	u8		nextbusn;
538 	u8		lastbusn;
539 	u32		bitmap;
540 };
541 #endif
542 
543 #ifdef CONFIG_PCIE_DPC
544 void pci_save_dpc_state(struct pci_dev *dev);
545 void pci_restore_dpc_state(struct pci_dev *dev);
546 void pci_dpc_init(struct pci_dev *pdev);
547 void dpc_process_error(struct pci_dev *pdev);
548 pci_ers_result_t dpc_reset_link(struct pci_dev *pdev);
549 bool pci_dpc_recovered(struct pci_dev *pdev);
550 #else
pci_save_dpc_state(struct pci_dev * dev)551 static inline void pci_save_dpc_state(struct pci_dev *dev) { }
pci_restore_dpc_state(struct pci_dev * dev)552 static inline void pci_restore_dpc_state(struct pci_dev *dev) { }
pci_dpc_init(struct pci_dev * pdev)553 static inline void pci_dpc_init(struct pci_dev *pdev) { }
pci_dpc_recovered(struct pci_dev * pdev)554 static inline bool pci_dpc_recovered(struct pci_dev *pdev) { return false; }
555 #endif
556 
557 #ifdef CONFIG_PCIEPORTBUS
558 void pci_rcec_init(struct pci_dev *dev);
559 void pci_rcec_exit(struct pci_dev *dev);
560 void pcie_link_rcec(struct pci_dev *rcec);
561 void pcie_walk_rcec(struct pci_dev *rcec,
562 		    int (*cb)(struct pci_dev *, void *),
563 		    void *userdata);
564 #else
pci_rcec_init(struct pci_dev * dev)565 static inline void pci_rcec_init(struct pci_dev *dev) { }
pci_rcec_exit(struct pci_dev * dev)566 static inline void pci_rcec_exit(struct pci_dev *dev) { }
pcie_link_rcec(struct pci_dev * rcec)567 static inline void pcie_link_rcec(struct pci_dev *rcec) { }
pcie_walk_rcec(struct pci_dev * rcec,int (* cb)(struct pci_dev *,void *),void * userdata)568 static inline void pcie_walk_rcec(struct pci_dev *rcec,
569 				  int (*cb)(struct pci_dev *, void *),
570 				  void *userdata) { }
571 #endif
572 
573 #ifdef CONFIG_PCI_ATS
574 /* Address Translation Service */
575 void pci_ats_init(struct pci_dev *dev);
576 void pci_restore_ats_state(struct pci_dev *dev);
577 #else
pci_ats_init(struct pci_dev * d)578 static inline void pci_ats_init(struct pci_dev *d) { }
pci_restore_ats_state(struct pci_dev * dev)579 static inline void pci_restore_ats_state(struct pci_dev *dev) { }
580 #endif /* CONFIG_PCI_ATS */
581 
582 #ifdef CONFIG_PCI_PRI
583 void pci_pri_init(struct pci_dev *dev);
584 void pci_restore_pri_state(struct pci_dev *pdev);
585 #else
pci_pri_init(struct pci_dev * dev)586 static inline void pci_pri_init(struct pci_dev *dev) { }
pci_restore_pri_state(struct pci_dev * pdev)587 static inline void pci_restore_pri_state(struct pci_dev *pdev) { }
588 #endif
589 
590 #ifdef CONFIG_PCI_PASID
591 void pci_pasid_init(struct pci_dev *dev);
592 void pci_restore_pasid_state(struct pci_dev *pdev);
593 #else
pci_pasid_init(struct pci_dev * dev)594 static inline void pci_pasid_init(struct pci_dev *dev) { }
pci_restore_pasid_state(struct pci_dev * pdev)595 static inline void pci_restore_pasid_state(struct pci_dev *pdev) { }
596 #endif
597 
598 #ifdef CONFIG_PCI_IOV
599 int pci_iov_init(struct pci_dev *dev);
600 void pci_iov_release(struct pci_dev *dev);
601 void pci_iov_remove(struct pci_dev *dev);
602 void pci_iov_update_resource(struct pci_dev *dev, int resno);
603 resource_size_t pci_sriov_resource_alignment(struct pci_dev *dev, int resno);
604 void pci_restore_iov_state(struct pci_dev *dev);
605 int pci_iov_bus_range(struct pci_bus *bus);
606 extern const struct attribute_group sriov_pf_dev_attr_group;
607 extern const struct attribute_group sriov_vf_dev_attr_group;
608 #else
pci_iov_init(struct pci_dev * dev)609 static inline int pci_iov_init(struct pci_dev *dev)
610 {
611 	return -ENODEV;
612 }
pci_iov_release(struct pci_dev * dev)613 static inline void pci_iov_release(struct pci_dev *dev) { }
pci_iov_remove(struct pci_dev * dev)614 static inline void pci_iov_remove(struct pci_dev *dev) { }
pci_restore_iov_state(struct pci_dev * dev)615 static inline void pci_restore_iov_state(struct pci_dev *dev) { }
pci_iov_bus_range(struct pci_bus * bus)616 static inline int pci_iov_bus_range(struct pci_bus *bus)
617 {
618 	return 0;
619 }
620 
621 #endif /* CONFIG_PCI_IOV */
622 
623 #ifdef CONFIG_PCIE_PTM
624 void pci_ptm_init(struct pci_dev *dev);
625 void pci_save_ptm_state(struct pci_dev *dev);
626 void pci_restore_ptm_state(struct pci_dev *dev);
627 void pci_suspend_ptm(struct pci_dev *dev);
628 void pci_resume_ptm(struct pci_dev *dev);
629 #else
pci_ptm_init(struct pci_dev * dev)630 static inline void pci_ptm_init(struct pci_dev *dev) { }
pci_save_ptm_state(struct pci_dev * dev)631 static inline void pci_save_ptm_state(struct pci_dev *dev) { }
pci_restore_ptm_state(struct pci_dev * dev)632 static inline void pci_restore_ptm_state(struct pci_dev *dev) { }
pci_suspend_ptm(struct pci_dev * dev)633 static inline void pci_suspend_ptm(struct pci_dev *dev) { }
pci_resume_ptm(struct pci_dev * dev)634 static inline void pci_resume_ptm(struct pci_dev *dev) { }
635 #endif
636 
637 unsigned long pci_cardbus_resource_alignment(struct resource *);
638 
pci_resource_alignment(struct pci_dev * dev,struct resource * res)639 static inline resource_size_t pci_resource_alignment(struct pci_dev *dev,
640 						     struct resource *res)
641 {
642 #ifdef CONFIG_PCI_IOV
643 	int resno = res - dev->resource;
644 
645 	if (resno >= PCI_IOV_RESOURCES && resno <= PCI_IOV_RESOURCE_END)
646 		return pci_sriov_resource_alignment(dev, resno);
647 #endif
648 	if (dev->class >> 8 == PCI_CLASS_BRIDGE_CARDBUS)
649 		return pci_cardbus_resource_alignment(res);
650 	return resource_alignment(res);
651 }
652 
653 void pci_acs_init(struct pci_dev *dev);
654 #ifdef CONFIG_PCI_QUIRKS
655 int pci_dev_specific_acs_enabled(struct pci_dev *dev, u16 acs_flags);
656 int pci_dev_specific_enable_acs(struct pci_dev *dev);
657 int pci_dev_specific_disable_acs_redir(struct pci_dev *dev);
658 int pcie_failed_link_retrain(struct pci_dev *dev);
659 #else
pci_dev_specific_acs_enabled(struct pci_dev * dev,u16 acs_flags)660 static inline int pci_dev_specific_acs_enabled(struct pci_dev *dev,
661 					       u16 acs_flags)
662 {
663 	return -ENOTTY;
664 }
pci_dev_specific_enable_acs(struct pci_dev * dev)665 static inline int pci_dev_specific_enable_acs(struct pci_dev *dev)
666 {
667 	return -ENOTTY;
668 }
pci_dev_specific_disable_acs_redir(struct pci_dev * dev)669 static inline int pci_dev_specific_disable_acs_redir(struct pci_dev *dev)
670 {
671 	return -ENOTTY;
672 }
pcie_failed_link_retrain(struct pci_dev * dev)673 static inline int pcie_failed_link_retrain(struct pci_dev *dev)
674 {
675 	return -ENOTTY;
676 }
677 #endif
678 
679 /* PCI error reporting and recovery */
680 pci_ers_result_t pcie_do_recovery(struct pci_dev *dev,
681 		pci_channel_state_t state,
682 		pci_ers_result_t (*reset_subordinates)(struct pci_dev *pdev));
683 
684 bool pcie_wait_for_link(struct pci_dev *pdev, bool active);
685 int pcie_retrain_link(struct pci_dev *pdev, bool use_lt);
686 
687 /* ASPM-related functionality we need even without CONFIG_PCIEASPM */
688 void pci_save_ltr_state(struct pci_dev *dev);
689 void pci_restore_ltr_state(struct pci_dev *dev);
690 void pci_configure_aspm_l1ss(struct pci_dev *dev);
691 void pci_save_aspm_l1ss_state(struct pci_dev *dev);
692 void pci_restore_aspm_l1ss_state(struct pci_dev *dev);
693 
694 #ifdef CONFIG_PCIEASPM
695 void pcie_aspm_init_link_state(struct pci_dev *pdev);
696 void pcie_aspm_exit_link_state(struct pci_dev *pdev);
697 void pcie_aspm_pm_state_change(struct pci_dev *pdev, bool locked);
698 void pcie_aspm_powersave_config_link(struct pci_dev *pdev);
699 void pci_configure_ltr(struct pci_dev *pdev);
700 void pci_bridge_reconfigure_ltr(struct pci_dev *pdev);
701 #else
pcie_aspm_init_link_state(struct pci_dev * pdev)702 static inline void pcie_aspm_init_link_state(struct pci_dev *pdev) { }
pcie_aspm_exit_link_state(struct pci_dev * pdev)703 static inline void pcie_aspm_exit_link_state(struct pci_dev *pdev) { }
pcie_aspm_pm_state_change(struct pci_dev * pdev,bool locked)704 static inline void pcie_aspm_pm_state_change(struct pci_dev *pdev, bool locked) { }
pcie_aspm_powersave_config_link(struct pci_dev * pdev)705 static inline void pcie_aspm_powersave_config_link(struct pci_dev *pdev) { }
pci_configure_ltr(struct pci_dev * pdev)706 static inline void pci_configure_ltr(struct pci_dev *pdev) { }
pci_bridge_reconfigure_ltr(struct pci_dev * pdev)707 static inline void pci_bridge_reconfigure_ltr(struct pci_dev *pdev) { }
708 #endif
709 
710 #ifdef CONFIG_PCIE_ECRC
711 void pcie_set_ecrc_checking(struct pci_dev *dev);
712 void pcie_ecrc_get_policy(char *str);
713 #else
pcie_set_ecrc_checking(struct pci_dev * dev)714 static inline void pcie_set_ecrc_checking(struct pci_dev *dev) { }
pcie_ecrc_get_policy(char * str)715 static inline void pcie_ecrc_get_policy(char *str) { }
716 #endif
717 
718 struct pci_dev_reset_methods {
719 	u16 vendor;
720 	u16 device;
721 	int (*reset)(struct pci_dev *dev, bool probe);
722 };
723 
724 struct pci_reset_fn_method {
725 	int (*reset_fn)(struct pci_dev *pdev, bool probe);
726 	char *name;
727 };
728 
729 #ifdef CONFIG_PCI_QUIRKS
730 int pci_dev_specific_reset(struct pci_dev *dev, bool probe);
731 #else
pci_dev_specific_reset(struct pci_dev * dev,bool probe)732 static inline int pci_dev_specific_reset(struct pci_dev *dev, bool probe)
733 {
734 	return -ENOTTY;
735 }
736 #endif
737 
738 #if defined(CONFIG_PCI_QUIRKS) && defined(CONFIG_ARM64)
739 int acpi_get_rc_resources(struct device *dev, const char *hid, u16 segment,
740 			  struct resource *res);
741 #else
acpi_get_rc_resources(struct device * dev,const char * hid,u16 segment,struct resource * res)742 static inline int acpi_get_rc_resources(struct device *dev, const char *hid,
743 					u16 segment, struct resource *res)
744 {
745 	return -ENODEV;
746 }
747 #endif
748 
749 int pci_rebar_get_current_size(struct pci_dev *pdev, int bar);
750 int pci_rebar_set_size(struct pci_dev *pdev, int bar, int size);
pci_rebar_size_to_bytes(int size)751 static inline u64 pci_rebar_size_to_bytes(int size)
752 {
753 	return 1ULL << (size + 20);
754 }
755 
756 struct device_node;
757 
758 #ifdef CONFIG_OF
759 int of_pci_parse_bus_range(struct device_node *node, struct resource *res);
760 int of_get_pci_domain_nr(struct device_node *node);
761 int of_pci_get_max_link_speed(struct device_node *node);
762 u32 of_pci_get_slot_power_limit(struct device_node *node,
763 				u8 *slot_power_limit_value,
764 				u8 *slot_power_limit_scale);
765 bool of_pci_preserve_config(struct device_node *node);
766 int pci_set_of_node(struct pci_dev *dev);
767 void pci_release_of_node(struct pci_dev *dev);
768 void pci_set_bus_of_node(struct pci_bus *bus);
769 void pci_release_bus_of_node(struct pci_bus *bus);
770 
771 int devm_of_pci_bridge_init(struct device *dev, struct pci_host_bridge *bridge);
772 bool of_pci_supply_present(struct device_node *np);
773 
774 #else
775 static inline int
of_pci_parse_bus_range(struct device_node * node,struct resource * res)776 of_pci_parse_bus_range(struct device_node *node, struct resource *res)
777 {
778 	return -EINVAL;
779 }
780 
781 static inline int
of_get_pci_domain_nr(struct device_node * node)782 of_get_pci_domain_nr(struct device_node *node)
783 {
784 	return -1;
785 }
786 
787 static inline int
of_pci_get_max_link_speed(struct device_node * node)788 of_pci_get_max_link_speed(struct device_node *node)
789 {
790 	return -EINVAL;
791 }
792 
793 static inline u32
of_pci_get_slot_power_limit(struct device_node * node,u8 * slot_power_limit_value,u8 * slot_power_limit_scale)794 of_pci_get_slot_power_limit(struct device_node *node,
795 			    u8 *slot_power_limit_value,
796 			    u8 *slot_power_limit_scale)
797 {
798 	if (slot_power_limit_value)
799 		*slot_power_limit_value = 0;
800 	if (slot_power_limit_scale)
801 		*slot_power_limit_scale = 0;
802 	return 0;
803 }
804 
of_pci_preserve_config(struct device_node * node)805 static inline bool of_pci_preserve_config(struct device_node *node)
806 {
807 	return false;
808 }
809 
pci_set_of_node(struct pci_dev * dev)810 static inline int pci_set_of_node(struct pci_dev *dev) { return 0; }
pci_release_of_node(struct pci_dev * dev)811 static inline void pci_release_of_node(struct pci_dev *dev) { }
pci_set_bus_of_node(struct pci_bus * bus)812 static inline void pci_set_bus_of_node(struct pci_bus *bus) { }
pci_release_bus_of_node(struct pci_bus * bus)813 static inline void pci_release_bus_of_node(struct pci_bus *bus) { }
814 
devm_of_pci_bridge_init(struct device * dev,struct pci_host_bridge * bridge)815 static inline int devm_of_pci_bridge_init(struct device *dev, struct pci_host_bridge *bridge)
816 {
817 	return 0;
818 }
819 
of_pci_supply_present(struct device_node * np)820 static inline bool of_pci_supply_present(struct device_node *np)
821 {
822 	return false;
823 }
824 #endif /* CONFIG_OF */
825 
826 struct of_changeset;
827 
828 #ifdef CONFIG_PCI_DYNAMIC_OF_NODES
829 void of_pci_make_dev_node(struct pci_dev *pdev);
830 void of_pci_remove_node(struct pci_dev *pdev);
831 int of_pci_add_properties(struct pci_dev *pdev, struct of_changeset *ocs,
832 			  struct device_node *np);
833 #else
of_pci_make_dev_node(struct pci_dev * pdev)834 static inline void of_pci_make_dev_node(struct pci_dev *pdev) { }
of_pci_remove_node(struct pci_dev * pdev)835 static inline void of_pci_remove_node(struct pci_dev *pdev) { }
836 #endif
837 
838 #ifdef CONFIG_PCIEAER
839 void pci_no_aer(void);
840 void pci_aer_init(struct pci_dev *dev);
841 void pci_aer_exit(struct pci_dev *dev);
842 extern const struct attribute_group aer_stats_attr_group;
843 void pci_aer_clear_fatal_status(struct pci_dev *dev);
844 int pci_aer_clear_status(struct pci_dev *dev);
845 int pci_aer_raw_clear_status(struct pci_dev *dev);
846 void pci_save_aer_state(struct pci_dev *dev);
847 void pci_restore_aer_state(struct pci_dev *dev);
848 #else
pci_no_aer(void)849 static inline void pci_no_aer(void) { }
pci_aer_init(struct pci_dev * d)850 static inline void pci_aer_init(struct pci_dev *d) { }
pci_aer_exit(struct pci_dev * d)851 static inline void pci_aer_exit(struct pci_dev *d) { }
pci_aer_clear_fatal_status(struct pci_dev * dev)852 static inline void pci_aer_clear_fatal_status(struct pci_dev *dev) { }
pci_aer_clear_status(struct pci_dev * dev)853 static inline int pci_aer_clear_status(struct pci_dev *dev) { return -EINVAL; }
pci_aer_raw_clear_status(struct pci_dev * dev)854 static inline int pci_aer_raw_clear_status(struct pci_dev *dev) { return -EINVAL; }
pci_save_aer_state(struct pci_dev * dev)855 static inline void pci_save_aer_state(struct pci_dev *dev) { }
pci_restore_aer_state(struct pci_dev * dev)856 static inline void pci_restore_aer_state(struct pci_dev *dev) { }
857 #endif
858 
859 #ifdef CONFIG_ACPI
860 bool pci_acpi_preserve_config(struct pci_host_bridge *bridge);
861 int pci_acpi_program_hp_params(struct pci_dev *dev);
862 extern const struct attribute_group pci_dev_acpi_attr_group;
863 void pci_set_acpi_fwnode(struct pci_dev *dev);
864 int pci_dev_acpi_reset(struct pci_dev *dev, bool probe);
865 bool acpi_pci_power_manageable(struct pci_dev *dev);
866 bool acpi_pci_bridge_d3(struct pci_dev *dev);
867 int acpi_pci_set_power_state(struct pci_dev *dev, pci_power_t state);
868 pci_power_t acpi_pci_get_power_state(struct pci_dev *dev);
869 void acpi_pci_refresh_power_state(struct pci_dev *dev);
870 int acpi_pci_wakeup(struct pci_dev *dev, bool enable);
871 bool acpi_pci_need_resume(struct pci_dev *dev);
872 pci_power_t acpi_pci_choose_state(struct pci_dev *pdev);
873 #else
pci_acpi_preserve_config(struct pci_host_bridge * bridge)874 static inline bool pci_acpi_preserve_config(struct pci_host_bridge *bridge)
875 {
876 	return false;
877 }
pci_dev_acpi_reset(struct pci_dev * dev,bool probe)878 static inline int pci_dev_acpi_reset(struct pci_dev *dev, bool probe)
879 {
880 	return -ENOTTY;
881 }
pci_set_acpi_fwnode(struct pci_dev * dev)882 static inline void pci_set_acpi_fwnode(struct pci_dev *dev) { }
pci_acpi_program_hp_params(struct pci_dev * dev)883 static inline int pci_acpi_program_hp_params(struct pci_dev *dev)
884 {
885 	return -ENODEV;
886 }
acpi_pci_power_manageable(struct pci_dev * dev)887 static inline bool acpi_pci_power_manageable(struct pci_dev *dev)
888 {
889 	return false;
890 }
acpi_pci_bridge_d3(struct pci_dev * dev)891 static inline bool acpi_pci_bridge_d3(struct pci_dev *dev)
892 {
893 	return false;
894 }
acpi_pci_set_power_state(struct pci_dev * dev,pci_power_t state)895 static inline int acpi_pci_set_power_state(struct pci_dev *dev, pci_power_t state)
896 {
897 	return -ENODEV;
898 }
acpi_pci_get_power_state(struct pci_dev * dev)899 static inline pci_power_t acpi_pci_get_power_state(struct pci_dev *dev)
900 {
901 	return PCI_UNKNOWN;
902 }
acpi_pci_refresh_power_state(struct pci_dev * dev)903 static inline void acpi_pci_refresh_power_state(struct pci_dev *dev) { }
acpi_pci_wakeup(struct pci_dev * dev,bool enable)904 static inline int acpi_pci_wakeup(struct pci_dev *dev, bool enable)
905 {
906 	return -ENODEV;
907 }
acpi_pci_need_resume(struct pci_dev * dev)908 static inline bool acpi_pci_need_resume(struct pci_dev *dev)
909 {
910 	return false;
911 }
acpi_pci_choose_state(struct pci_dev * pdev)912 static inline pci_power_t acpi_pci_choose_state(struct pci_dev *pdev)
913 {
914 	return PCI_POWER_ERROR;
915 }
916 #endif
917 
918 #ifdef CONFIG_PCIEASPM
919 extern const struct attribute_group aspm_ctrl_attr_group;
920 #endif
921 
922 extern const struct attribute_group pci_dev_reset_method_attr_group;
923 
924 #ifdef CONFIG_X86_INTEL_MID
925 bool pci_use_mid_pm(void);
926 int mid_pci_set_power_state(struct pci_dev *pdev, pci_power_t state);
927 pci_power_t mid_pci_get_power_state(struct pci_dev *pdev);
928 #else
pci_use_mid_pm(void)929 static inline bool pci_use_mid_pm(void)
930 {
931 	return false;
932 }
mid_pci_set_power_state(struct pci_dev * pdev,pci_power_t state)933 static inline int mid_pci_set_power_state(struct pci_dev *pdev, pci_power_t state)
934 {
935 	return -ENODEV;
936 }
mid_pci_get_power_state(struct pci_dev * pdev)937 static inline pci_power_t mid_pci_get_power_state(struct pci_dev *pdev)
938 {
939 	return PCI_UNKNOWN;
940 }
941 #endif
942 
943 int pcim_intx(struct pci_dev *dev, int enable);
944 int pcim_request_region_exclusive(struct pci_dev *pdev, int bar,
945 				  const char *name);
946 void pcim_release_region(struct pci_dev *pdev, int bar);
947 
948 /*
949  * Config Address for PCI Configuration Mechanism #1
950  *
951  * See PCI Local Bus Specification, Revision 3.0,
952  * Section 3.2.2.3.2, Figure 3-2, p. 50.
953  */
954 
955 #define PCI_CONF1_BUS_SHIFT	16 /* Bus number */
956 #define PCI_CONF1_DEV_SHIFT	11 /* Device number */
957 #define PCI_CONF1_FUNC_SHIFT	8  /* Function number */
958 
959 #define PCI_CONF1_BUS_MASK	0xff
960 #define PCI_CONF1_DEV_MASK	0x1f
961 #define PCI_CONF1_FUNC_MASK	0x7
962 #define PCI_CONF1_REG_MASK	0xfc /* Limit aligned offset to a maximum of 256B */
963 
964 #define PCI_CONF1_ENABLE	BIT(31)
965 #define PCI_CONF1_BUS(x)	(((x) & PCI_CONF1_BUS_MASK) << PCI_CONF1_BUS_SHIFT)
966 #define PCI_CONF1_DEV(x)	(((x) & PCI_CONF1_DEV_MASK) << PCI_CONF1_DEV_SHIFT)
967 #define PCI_CONF1_FUNC(x)	(((x) & PCI_CONF1_FUNC_MASK) << PCI_CONF1_FUNC_SHIFT)
968 #define PCI_CONF1_REG(x)	((x) & PCI_CONF1_REG_MASK)
969 
970 #define PCI_CONF1_ADDRESS(bus, dev, func, reg) \
971 	(PCI_CONF1_ENABLE | \
972 	 PCI_CONF1_BUS(bus) | \
973 	 PCI_CONF1_DEV(dev) | \
974 	 PCI_CONF1_FUNC(func) | \
975 	 PCI_CONF1_REG(reg))
976 
977 /*
978  * Extension of PCI Config Address for accessing extended PCIe registers
979  *
980  * No standardized specification, but used on lot of non-ECAM-compliant ARM SoCs
981  * or on AMD Barcelona and new CPUs. Reserved bits [27:24] of PCI Config Address
982  * are used for specifying additional 4 high bits of PCI Express register.
983  */
984 
985 #define PCI_CONF1_EXT_REG_SHIFT	16
986 #define PCI_CONF1_EXT_REG_MASK	0xf00
987 #define PCI_CONF1_EXT_REG(x)	(((x) & PCI_CONF1_EXT_REG_MASK) << PCI_CONF1_EXT_REG_SHIFT)
988 
989 #define PCI_CONF1_EXT_ADDRESS(bus, dev, func, reg) \
990 	(PCI_CONF1_ADDRESS(bus, dev, func, reg) | \
991 	 PCI_CONF1_EXT_REG(reg))
992 
993 #endif /* DRIVERS_PCI_H */
994