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