]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - include/linux/pci.h
PCI / PM: Simplify device wakeup settings code
[mirror_ubuntu-artful-kernel.git] / include / linux / pci.h
CommitLineData
1da177e4
LT
1/*
2 * pci.h
3 *
4 * PCI defines and function prototypes
5 * Copyright 1994, Drew Eckhardt
6 * Copyright 1997--1999 Martin Mares <mj@ucw.cz>
7 *
8 * For more information, please consult the following manuals (look at
9 * http://www.pcisig.com/ for how to get them):
10 *
11 * PCI BIOS Specification
12 * PCI Local Bus Specification
13 * PCI to PCI Bridge Specification
14 * PCI System Design Guide
15 */
1da177e4
LT
16#ifndef LINUX_PCI_H
17#define LINUX_PCI_H
18
1da177e4 19
778382e0
DW
20#include <linux/mod_devicetable.h>
21
1da177e4 22#include <linux/types.h>
98db6f19 23#include <linux/init.h>
1da177e4
LT
24#include <linux/ioport.h>
25#include <linux/list.h>
4a7fb636 26#include <linux/compiler.h>
1da177e4 27#include <linux/errno.h>
f46753c5 28#include <linux/kobject.h>
60063497 29#include <linux/atomic.h>
1da177e4 30#include <linux/device.h>
704e8953 31#include <linux/interrupt.h>
1388cc96 32#include <linux/io.h>
14d76b68 33#include <linux/resource_ext.h>
607ca46e 34#include <uapi/linux/pci.h>
1da177e4 35
7e7a43c3
AB
36#include <linux/pci_ids.h>
37
85467136
SK
38/*
39 * The PCI interface treats multi-function devices as independent
40 * devices. The slot/function address of each device is encoded
41 * in a single byte as follows:
42 *
43 * 7:3 = slot
44 * 2:0 = function
f7625980
BH
45 *
46 * PCI_DEVFN(), PCI_SLOT(), and PCI_FUNC() are defined in uapi/linux/pci.h.
85467136 47 * In the interest of not exposing interfaces to user-space unnecessarily,
f7625980 48 * the following kernel-only defines are being added here.
85467136 49 */
63ddc0b8 50#define PCI_DEVID(bus, devfn) ((((u16)(bus)) << 8) | (devfn))
85467136
SK
51/* return bus from PCI devid = ((u16)bus_number) << 8) | devfn */
52#define PCI_BUS_NUM(x) (((x) >> 8) & 0xff)
53
f46753c5
AC
54/* pci_slot represents a physical slot */
55struct pci_slot {
56 struct pci_bus *bus; /* The bus this slot is on */
57 struct list_head list; /* node in list of slots on this bus */
58 struct hotplug_slot *hotplug; /* Hotplug info (migrate over time) */
59 unsigned char number; /* PCI_SLOT(pci_dev->devfn) */
60 struct kobject kobj;
61};
62
0ad772ec
AC
63static inline const char *pci_slot_name(const struct pci_slot *slot)
64{
65 return kobject_name(&slot->kobj);
66}
67
1da177e4
LT
68/* File state for mmap()s on /proc/bus/pci/X/Y */
69enum pci_mmap_state {
70 pci_mmap_io,
71 pci_mmap_mem
72};
73
fde09c6d
YZ
74/*
75 * For PCI devices, the region numbers are assigned this way:
76 */
77enum {
78 /* #0-5: standard PCI resources */
79 PCI_STD_RESOURCES,
80 PCI_STD_RESOURCE_END = 5,
81
82 /* #6: expansion ROM resource */
83 PCI_ROM_RESOURCE,
84
d1b054da
YZ
85 /* device specific resources */
86#ifdef CONFIG_PCI_IOV
87 PCI_IOV_RESOURCES,
88 PCI_IOV_RESOURCE_END = PCI_IOV_RESOURCES + PCI_SRIOV_NUM_BARS - 1,
89#endif
90
fde09c6d
YZ
91 /* resources assigned to buses behind the bridge */
92#define PCI_BRIDGE_RESOURCE_NUM 4
93
94 PCI_BRIDGE_RESOURCES,
95 PCI_BRIDGE_RESOURCE_END = PCI_BRIDGE_RESOURCES +
96 PCI_BRIDGE_RESOURCE_NUM - 1,
97
98 /* total resources associated with a PCI device */
99 PCI_NUM_RESOURCES,
100
101 /* preserve this for compatibility */
cda57bf9 102 DEVICE_COUNT_RESOURCE = PCI_NUM_RESOURCES,
fde09c6d 103};
1da177e4 104
224abb67
BH
105/*
106 * pci_power_t values must match the bits in the Capabilities PME_Support
107 * and Control/Status PowerState fields in the Power Management capability.
108 */
1da177e4
LT
109typedef int __bitwise pci_power_t;
110
4352dfd5
GKH
111#define PCI_D0 ((pci_power_t __force) 0)
112#define PCI_D1 ((pci_power_t __force) 1)
113#define PCI_D2 ((pci_power_t __force) 2)
1da177e4
LT
114#define PCI_D3hot ((pci_power_t __force) 3)
115#define PCI_D3cold ((pci_power_t __force) 4)
3fe9d19f 116#define PCI_UNKNOWN ((pci_power_t __force) 5)
438510f6 117#define PCI_POWER_ERROR ((pci_power_t __force) -1)
1da177e4 118
00240c38
AS
119/* Remember to update this when the list above changes! */
120extern const char *pci_power_names[];
121
122static inline const char *pci_power_name(pci_power_t state)
123{
9661e783 124 return pci_power_names[1 + (__force int) state];
00240c38
AS
125}
126
448bd857
HY
127#define PCI_PM_D2_DELAY 200
128#define PCI_PM_D3_WAIT 10
129#define PCI_PM_D3COLD_WAIT 100
130#define PCI_PM_BUS_WAIT 50
aa8c6c93 131
392a1ce7
LV
132/** The pci_channel state describes connectivity between the CPU and
133 * the pci device. If some PCI bus between here and the pci device
134 * has crashed or locked up, this info is reflected here.
135 */
136typedef unsigned int __bitwise pci_channel_state_t;
137
138enum pci_channel_state {
139 /* I/O channel is in normal state */
140 pci_channel_io_normal = (__force pci_channel_state_t) 1,
141
142 /* I/O to channel is blocked */
143 pci_channel_io_frozen = (__force pci_channel_state_t) 2,
144
145 /* PCI card is dead */
146 pci_channel_io_perm_failure = (__force pci_channel_state_t) 3,
147};
148
f7bdd12d
BK
149typedef unsigned int __bitwise pcie_reset_state_t;
150
151enum pcie_reset_state {
152 /* Reset is NOT asserted (Use to deassert reset) */
153 pcie_deassert_reset = (__force pcie_reset_state_t) 1,
154
f7625980 155 /* Use #PERST to reset PCIe device */
f7bdd12d
BK
156 pcie_warm_reset = (__force pcie_reset_state_t) 2,
157
f7625980 158 /* Use PCIe Hot Reset to reset device */
f7bdd12d
BK
159 pcie_hot_reset = (__force pcie_reset_state_t) 3
160};
161
ba698ad4
DM
162typedef unsigned short __bitwise pci_dev_flags_t;
163enum pci_dev_flags {
164 /* INTX_DISABLE in PCI_COMMAND register disables MSI
165 * generation too.
166 */
6b121592 167 PCI_DEV_FLAGS_MSI_INTX_DISABLE_BUG = (__force pci_dev_flags_t) (1 << 0),
979b1791 168 /* Device configuration is irrevocably lost if disabled into D3 */
6b121592 169 PCI_DEV_FLAGS_NO_D3 = (__force pci_dev_flags_t) (1 << 1),
6777829c 170 /* Provide indication device is assigned by a Virtual Machine Manager */
6b121592 171 PCI_DEV_FLAGS_ASSIGNED = (__force pci_dev_flags_t) (1 << 2),
5757a769 172 /* Flag for quirk use to store if quirk-specific ACS is enabled */
6b121592 173 PCI_DEV_FLAGS_ACS_ENABLED_QUIRK = (__force pci_dev_flags_t) (1 << 3),
c8fe16e3
AW
174 /* Use a PCIe-to-PCI bridge alias even if !pci_is_pcie */
175 PCI_DEV_FLAG_PCIE_BRIDGE_ALIAS = (__force pci_dev_flags_t) (1 << 5),
f331a859
AW
176 /* Do not use bus resets for device */
177 PCI_DEV_FLAGS_NO_BUS_RESET = (__force pci_dev_flags_t) (1 << 6),
51e53738
AW
178 /* Do not use PM reset even if device advertises NoSoftRst- */
179 PCI_DEV_FLAGS_NO_PM_RESET = (__force pci_dev_flags_t) (1 << 7),
932c435c
MR
180 /* Get VPD from function 0 VPD */
181 PCI_DEV_FLAGS_VPD_REF_F0 = (__force pci_dev_flags_t) (1 << 8),
ffff8858
J
182 /* a non-root bridge where translation occurs, stop alias search here */
183 PCI_DEV_FLAGS_BRIDGE_XLATE_ROOT = (__force pci_dev_flags_t) (1 << 9),
f65fd1aa
SN
184 /* Do not use FLR even if device advertises PCI_AF_CAP */
185 PCI_DEV_FLAGS_NO_FLR_RESET = (__force pci_dev_flags_t) (1 << 10),
4d071c32
ID
186 /*
187 * Resume before calling the driver's system suspend hooks, disabling
188 * the direct_complete optimization.
189 */
190 PCI_DEV_FLAGS_NEEDS_RESUME = (__force pci_dev_flags_t) (1 << 11),
ba698ad4
DM
191};
192
e1d3a908
SA
193enum pci_irq_reroute_variant {
194 INTEL_IRQ_REROUTE_VARIANT = 1,
195 MAX_IRQ_REROUTE_VARIANTS = 3
196};
197
6e325a62
MT
198typedef unsigned short __bitwise pci_bus_flags_t;
199enum pci_bus_flags {
032c3d86
JD
200 PCI_BUS_FLAGS_NO_MSI = (__force pci_bus_flags_t) 1,
201 PCI_BUS_FLAGS_NO_MMRBC = (__force pci_bus_flags_t) 2,
202 PCI_BUS_FLAGS_NO_AERSID = (__force pci_bus_flags_t) 4,
6e325a62
MT
203};
204
59da381e
JK
205/* These values come from the PCI Express Spec */
206enum pcie_link_width {
207 PCIE_LNK_WIDTH_RESRV = 0x00,
208 PCIE_LNK_X1 = 0x01,
209 PCIE_LNK_X2 = 0x02,
210 PCIE_LNK_X4 = 0x04,
211 PCIE_LNK_X8 = 0x08,
212 PCIE_LNK_X12 = 0x0C,
213 PCIE_LNK_X16 = 0x10,
214 PCIE_LNK_X32 = 0x20,
215 PCIE_LNK_WIDTH_UNKNOWN = 0xFF,
216};
217
536c8cb4
MW
218/* Based on the PCI Hotplug Spec, but some values are made up by us */
219enum pci_bus_speed {
220 PCI_SPEED_33MHz = 0x00,
221 PCI_SPEED_66MHz = 0x01,
222 PCI_SPEED_66MHz_PCIX = 0x02,
223 PCI_SPEED_100MHz_PCIX = 0x03,
224 PCI_SPEED_133MHz_PCIX = 0x04,
225 PCI_SPEED_66MHz_PCIX_ECC = 0x05,
226 PCI_SPEED_100MHz_PCIX_ECC = 0x06,
227 PCI_SPEED_133MHz_PCIX_ECC = 0x07,
228 PCI_SPEED_66MHz_PCIX_266 = 0x09,
229 PCI_SPEED_100MHz_PCIX_266 = 0x0a,
230 PCI_SPEED_133MHz_PCIX_266 = 0x0b,
45b4cdd5
MW
231 AGP_UNKNOWN = 0x0c,
232 AGP_1X = 0x0d,
233 AGP_2X = 0x0e,
234 AGP_4X = 0x0f,
235 AGP_8X = 0x10,
536c8cb4
MW
236 PCI_SPEED_66MHz_PCIX_533 = 0x11,
237 PCI_SPEED_100MHz_PCIX_533 = 0x12,
238 PCI_SPEED_133MHz_PCIX_533 = 0x13,
239 PCIE_SPEED_2_5GT = 0x14,
240 PCIE_SPEED_5_0GT = 0x15,
9dfd97fe 241 PCIE_SPEED_8_0GT = 0x16,
536c8cb4
MW
242 PCI_SPEED_UNKNOWN = 0xff,
243};
244
24a4742f 245struct pci_cap_saved_data {
fd0f7f73
AW
246 u16 cap_nr;
247 bool cap_extended;
24a4742f 248 unsigned int size;
41017f0c
SL
249 u32 data[0];
250};
251
24a4742f
AW
252struct pci_cap_saved_state {
253 struct hlist_node next;
254 struct pci_cap_saved_data cap;
255};
256
402723ad 257struct irq_affinity;
7d715a6c 258struct pcie_link_state;
ee69439c 259struct pci_vpd;
d1b054da 260struct pci_sriov;
302b4215 261struct pci_ats;
ee69439c 262
1da177e4
LT
263/*
264 * The pci_dev structure is used to describe PCI devices.
265 */
266struct pci_dev {
1da177e4
LT
267 struct list_head bus_list; /* node in per-bus list */
268 struct pci_bus *bus; /* bus this device is on */
269 struct pci_bus *subordinate; /* bus this device bridges to */
270
271 void *sysdata; /* hook for sys-specific extension */
272 struct proc_dir_entry *procent; /* device entry in /proc/bus/pci */
f46753c5 273 struct pci_slot *slot; /* Physical slot this device is in */
1da177e4
LT
274
275 unsigned int devfn; /* encoded device & function index */
276 unsigned short vendor;
277 unsigned short device;
278 unsigned short subsystem_vendor;
279 unsigned short subsystem_device;
280 unsigned int class; /* 3 bytes: (base,sub,prog-if) */
b8a3a521 281 u8 revision; /* PCI revision, low byte of class word */
1da177e4 282 u8 hdr_type; /* PCI header type (`multi' flag masked out) */
66b80809
KB
283#ifdef CONFIG_PCIEAER
284 u16 aer_cap; /* AER capability offset */
285#endif
f7625980 286 u8 pcie_cap; /* PCIe capability offset */
e375b561
GS
287 u8 msi_cap; /* MSI capability offset */
288 u8 msix_cap; /* MSI-X capability offset */
f7625980 289 u8 pcie_mpss:3; /* PCIe Max Payload Size Supported */
1da177e4 290 u8 rom_base_reg; /* which config register controls the ROM */
f7625980
BH
291 u8 pin; /* which interrupt pin this device uses */
292 u16 pcie_flags_reg; /* cached PCIe Capabilities Register */
338c3149 293 unsigned long *dma_alias_mask;/* mask of enabled devfn aliases */
1da177e4
LT
294
295 struct pci_driver *driver; /* which driver has allocated this device */
296 u64 dma_mask; /* Mask of the bits of bus address this
297 device implements. Normally this is
298 0xffffffff. You only need to change
299 this if your device has broken DMA
300 or supports 64-bit transfers. */
301
4d57cdfa
FT
302 struct device_dma_parameters dma_parms;
303
1da177e4
LT
304 pci_power_t current_state; /* Current operating state. In ACPI-speak,
305 this is D0-D3, D0 being fully functional,
306 and D3 being off. */
703860ed 307 u8 pm_cap; /* PM capability offset */
337001b6
RW
308 unsigned int pme_support:5; /* Bitmask of states from which PME#
309 can be generated */
379021d5 310 unsigned int pme_poll:1; /* Poll device's PME status bit */
337001b6
RW
311 unsigned int d1_support:1; /* Low power state D1 is supported */
312 unsigned int d2_support:1; /* Low power state D2 is supported */
448bd857
HY
313 unsigned int no_d1d2:1; /* D1 and D2 are forbidden */
314 unsigned int no_d3cold:1; /* D3cold is forbidden */
9d26d3a8 315 unsigned int bridge_d3:1; /* Allow D3 for bridge */
448bd857 316 unsigned int d3cold_allowed:1; /* D3cold is allowed by user */
253d2e54
JP
317 unsigned int mmio_always_on:1; /* disallow turning off io/mem
318 decoding during bar sizing */
e80bb09d 319 unsigned int wakeup_prepared:1;
448bd857
HY
320 unsigned int runtime_d3cold:1; /* whether go through runtime
321 D3cold, not set for devices
322 powered on/off by the
323 corresponding bridge */
b440bde7 324 unsigned int ignore_hotplug:1; /* Ignore hotplug events */
576243b3
KB
325 unsigned int hotplug_user_indicators:1; /* SlotCtl indicators
326 controlled exclusively by
327 user sysfs */
1ae861e6 328 unsigned int d3_delay; /* D3->D0 transition time in ms */
448bd857 329 unsigned int d3cold_delay; /* D3cold->D0 transition time in ms */
1da177e4 330
7d715a6c 331#ifdef CONFIG_PCIEASPM
f7625980 332 struct pcie_link_state *link_state; /* ASPM link state */
7d715a6c
SL
333#endif
334
392a1ce7 335 pci_channel_state_t error_state; /* current connectivity state */
1da177e4
LT
336 struct device dev; /* Generic device interface */
337
1da177e4
LT
338 int cfg_size; /* Size of configuration space */
339
340 /*
341 * Instead of touching interrupt line and base address registers
342 * directly, use the values stored here. They might be different!
343 */
344 unsigned int irq;
345 struct resource resource[DEVICE_COUNT_RESOURCE]; /* I/O and memory regions + expansion ROMs */
346
58d9a38f 347 bool match_driver; /* Skip attaching driver */
1da177e4 348 /* These fields are used by common fixups */
f7625980 349 unsigned int transparent:1; /* Subtractive decode PCI bridge */
1da177e4
LT
350 unsigned int multifunction:1;/* Part of multi-function device */
351 /* keep track of device state */
8a1bc901 352 unsigned int is_added:1;
1da177e4 353 unsigned int is_busmaster:1; /* device is busmaster */
4602b88d 354 unsigned int no_msi:1; /* device may not use msi */
f144d149 355 unsigned int no_64bit_msi:1; /* device may only use 32-bit MSIs */
fb51ccbf 356 unsigned int block_cfg_access:1; /* config space access is blocked */
bd8481e1 357 unsigned int broken_parity_status:1; /* Device generates false positive parity */
e1d3a908 358 unsigned int irq_reroute_variant:2; /* device needs IRQ rerouting variant */
f7625980 359 unsigned int msi_enabled:1;
99dc804d 360 unsigned int msix_enabled:1;
58c3a727 361 unsigned int ari_enabled:1; /* ARI forwarding */
d544d75a 362 unsigned int ats_enabled:1; /* Address Translation Service */
9ac7849e 363 unsigned int is_managed:1;
260d703a 364 unsigned int needs_freset:1; /* Dev requires fundamental reset */
aa8c6c93 365 unsigned int state_saved:1;
d1b054da 366 unsigned int is_physfn:1;
dd7cc44d 367 unsigned int is_virtfn:1;
711d5779 368 unsigned int reset_fn:1;
28760489 369 unsigned int is_hotplug_bridge:1;
8531e283 370 unsigned int is_thunderbolt:1; /* Thunderbolt controller */
affb72c3
HY
371 unsigned int __aer_firmware_first_valid:1;
372 unsigned int __aer_firmware_first:1;
fbebb9fd 373 unsigned int broken_intx_masking:1;
2b28ae19 374 unsigned int io_window_1k:1; /* Intel P2P bridge 1K I/O windows */
cffe0a2b 375 unsigned int irq_managed:1;
d0751b98 376 unsigned int has_secondary_link:1;
b84106b4 377 unsigned int non_compliant_bars:1; /* broken BARs; ignore them */
ba698ad4 378 pci_dev_flags_t dev_flags;
bae94d02 379 atomic_t enable_cnt; /* pci_enable_device has been called */
4602b88d 380
1da177e4 381 u32 saved_config_space[16]; /* config space saved at suspend time */
41017f0c 382 struct hlist_head saved_cap_space;
1da177e4
LT
383 struct bin_attribute *rom_attr; /* attribute descriptor for sysfs ROM entry */
384 int rom_attr_enabled; /* has display of the rom attribute been enabled? */
385 struct bin_attribute *res_attr[DEVICE_COUNT_RESOURCE]; /* sysfs file for resources */
45aec1ae 386 struct bin_attribute *res_attr_wc[DEVICE_COUNT_RESOURCE]; /* sysfs file for WC mapping of resources */
9bb04a0c
JY
387
388#ifdef CONFIG_PCIE_PTM
389 unsigned int ptm_root:1;
390 unsigned int ptm_enabled:1;
8b2ec318 391 u8 ptm_granularity;
9bb04a0c 392#endif
ded86d8d 393#ifdef CONFIG_PCI_MSI
1c51b50c 394 const struct attribute_group **msi_irq_groups;
ded86d8d 395#endif
94e61088 396 struct pci_vpd *vpd;
466b3ddf 397#ifdef CONFIG_PCI_ATS
dd7cc44d
YZ
398 union {
399 struct pci_sriov *sriov; /* SR-IOV capability related */
400 struct pci_dev *physfn; /* the PF this VF is associated with */
401 };
67930995
BH
402 u16 ats_cap; /* ATS Capability offset */
403 u8 ats_stu; /* ATS Smallest Translation Unit */
d544d75a 404 atomic_t ats_ref_cnt; /* number of VFs with ATS enabled */
d1b054da 405#endif
dbd3fc33 406 phys_addr_t rom; /* Physical address of ROM if it's not from the BAR */
84c1b80e 407 size_t romlen; /* Length of ROM if it's not from the BAR */
782a985d 408 char *driver_override; /* Driver name to force a match */
89ee9f76
KB
409
410 unsigned long priv_flags; /* Private flags for the pci driver */
1da177e4
LT
411};
412
dda56549
Y
413static inline struct pci_dev *pci_physfn(struct pci_dev *dev)
414{
415#ifdef CONFIG_PCI_IOV
416 if (dev->is_virtfn)
417 dev = dev->physfn;
418#endif
dda56549
Y
419 return dev;
420}
421
3c6e6ae7 422struct pci_dev *pci_alloc_dev(struct pci_bus *bus);
65891215 423
1da177e4
LT
424#define to_pci_dev(n) container_of(n, struct pci_dev, dev)
425#define for_each_pci_dev(d) while ((d = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, d)) != NULL)
426
a7369f1f
LV
427static inline int pci_channel_offline(struct pci_dev *pdev)
428{
429 return (pdev->error_state != pci_channel_io_normal);
430}
431
5a21d70d 432struct pci_host_bridge {
7b543663 433 struct device dev;
5a21d70d 434 struct pci_bus *bus; /* root bus */
37d6a0a6
AB
435 struct pci_ops *ops;
436 void *sysdata;
437 int busnr;
14d76b68 438 struct list_head windows; /* resource_entry */
4fa2649a
YL
439 void (*release_fn)(struct pci_host_bridge *);
440 void *release_data;
37d6a0a6 441 struct msi_controller *msi;
e33caa82 442 unsigned int ignore_reset_delay:1; /* for entire hierarchy */
7c7a0e94
GP
443 /* Resource alignment requirements */
444 resource_size_t (*align_resource)(struct pci_dev *dev,
445 const struct resource *res,
446 resource_size_t start,
447 resource_size_t size,
448 resource_size_t align);
59094065 449 unsigned long private[0] ____cacheline_aligned;
5a21d70d 450};
41017f0c 451
7b543663 452#define to_pci_host_bridge(n) container_of(n, struct pci_host_bridge, dev)
7c7a0e94 453
59094065
TR
454static inline void *pci_host_bridge_priv(struct pci_host_bridge *bridge)
455{
456 return (void *)bridge->private;
457}
458
459static inline struct pci_host_bridge *pci_host_bridge_from_priv(void *priv)
460{
461 return container_of(priv, struct pci_host_bridge, private);
462}
463
a52d1443
TR
464struct pci_host_bridge *pci_alloc_host_bridge(size_t priv);
465int pci_register_host_bridge(struct pci_host_bridge *bridge);
7c7a0e94
GP
466struct pci_host_bridge *pci_find_host_bridge(struct pci_bus *bus);
467
4fa2649a
YL
468void pci_set_host_bridge_release(struct pci_host_bridge *bridge,
469 void (*release_fn)(struct pci_host_bridge *),
470 void *release_data);
7b543663 471
6c0cc950
RW
472int pcibios_root_bridge_prepare(struct pci_host_bridge *bridge);
473
2fe2abf8
BH
474/*
475 * The first PCI_BRIDGE_RESOURCE_NUM PCI bus resources (those that correspond
476 * to P2P or CardBus bridge windows) go in a table. Additional ones (for
477 * buses below host bridges or subtractive decode bridges) go in the list.
478 * Use pci_bus_for_each_resource() to iterate through all the resources.
479 */
480
481/*
482 * PCI_SUBTRACTIVE_DECODE means the bridge forwards the window implicitly
483 * and there's no way to program the bridge with the details of the window.
484 * This does not apply to ACPI _CRS windows, even with the _DEC subtractive-
485 * decode bit set, because they are explicit and can be programmed with _SRS.
486 */
487#define PCI_SUBTRACTIVE_DECODE 0x1
488
489struct pci_bus_resource {
490 struct list_head list;
491 struct resource *res;
492 unsigned int flags;
493};
4352dfd5
GKH
494
495#define PCI_REGION_FLAG_MASK 0x0fU /* These bits of resource flags tell us the PCI region flags */
1da177e4
LT
496
497struct pci_bus {
498 struct list_head node; /* node in list of buses */
499 struct pci_bus *parent; /* parent bus this bridge is on */
500 struct list_head children; /* list of child buses */
501 struct list_head devices; /* list of devices on this bus */
502 struct pci_dev *self; /* bridge device as seen by parent */
67546762
YW
503 struct list_head slots; /* list of slots on this bus;
504 protected by pci_slot_mutex */
2fe2abf8
BH
505 struct resource *resource[PCI_BRIDGE_RESOURCE_NUM];
506 struct list_head resources; /* address space routed to this bus */
92f02430 507 struct resource busn_res; /* bus numbers routed to this bus */
1da177e4
LT
508
509 struct pci_ops *ops; /* configuration access functions */
c2791b80 510 struct msi_controller *msi; /* MSI controller */
1da177e4
LT
511 void *sysdata; /* hook for sys-specific extension */
512 struct proc_dir_entry *procdir; /* directory entry in /proc/bus/pci */
513
514 unsigned char number; /* bus number */
515 unsigned char primary; /* number of primary bridge */
3749c51a
MW
516 unsigned char max_bus_speed; /* enum pci_bus_speed */
517 unsigned char cur_bus_speed; /* enum pci_bus_speed */
670ba0c8
CM
518#ifdef CONFIG_PCI_DOMAINS_GENERIC
519 int domain_nr;
520#endif
1da177e4
LT
521
522 char name[48];
523
524 unsigned short bridge_ctl; /* manage NO_ISA/FBB/et al behaviors */
f7625980 525 pci_bus_flags_t bus_flags; /* inherited by child buses */
1da177e4 526 struct device *bridge;
fd7d1ced 527 struct device dev;
1da177e4
LT
528 struct bin_attribute *legacy_io; /* legacy I/O for this bus */
529 struct bin_attribute *legacy_mem; /* legacy mem */
cc74d96f 530 unsigned int is_added:1;
1da177e4
LT
531};
532
fd7d1ced 533#define to_pci_bus(n) container_of(n, struct pci_bus, dev)
1da177e4 534
79af72d7 535/*
f7625980 536 * Returns true if the PCI bus is root (behind host-PCI bridge),
79af72d7 537 * false otherwise
77a0dfcd
BH
538 *
539 * Some code assumes that "bus->self == NULL" means that bus is a root bus.
540 * This is incorrect because "virtual" buses added for SR-IOV (via
541 * virtfn_add_bus()) have "bus->self == NULL" but are not root buses.
79af72d7
KK
542 */
543static inline bool pci_is_root_bus(struct pci_bus *pbus)
544{
545 return !(pbus->parent);
546}
547
1c86438c
YW
548/**
549 * pci_is_bridge - check if the PCI device is a bridge
550 * @dev: PCI device
551 *
552 * Return true if the PCI device is bridge whether it has subordinate
553 * or not.
554 */
555static inline bool pci_is_bridge(struct pci_dev *dev)
556{
557 return dev->hdr_type == PCI_HEADER_TYPE_BRIDGE ||
558 dev->hdr_type == PCI_HEADER_TYPE_CARDBUS;
559}
560
c6bde215
BH
561static inline struct pci_dev *pci_upstream_bridge(struct pci_dev *dev)
562{
563 dev = pci_physfn(dev);
564 if (pci_is_root_bus(dev->bus))
565 return NULL;
566
567 return dev->bus->self;
568}
569
6675a601
MK
570struct device *pci_get_host_bridge_device(struct pci_dev *dev);
571void pci_put_host_bridge_device(struct device *dev);
572
16cf0ebc
RW
573#ifdef CONFIG_PCI_MSI
574static inline bool pci_dev_msi_enabled(struct pci_dev *pci_dev)
575{
576 return pci_dev->msi_enabled || pci_dev->msix_enabled;
577}
578#else
579static inline bool pci_dev_msi_enabled(struct pci_dev *pci_dev) { return false; }
580#endif
581
1da177e4
LT
582/*
583 * Error values that may be returned by PCI functions.
584 */
585#define PCIBIOS_SUCCESSFUL 0x00
586#define PCIBIOS_FUNC_NOT_SUPPORTED 0x81
587#define PCIBIOS_BAD_VENDOR_ID 0x83
588#define PCIBIOS_DEVICE_NOT_FOUND 0x86
589#define PCIBIOS_BAD_REGISTER_NUMBER 0x87
590#define PCIBIOS_SET_FAILED 0x88
591#define PCIBIOS_BUFFER_TOO_SMALL 0x89
592
a6961651 593/*
f7625980 594 * Translate above to generic errno for passing back through non-PCI code.
a6961651
AW
595 */
596static inline int pcibios_err_to_errno(int err)
597{
598 if (err <= PCIBIOS_SUCCESSFUL)
599 return err; /* Assume already errno */
600
601 switch (err) {
602 case PCIBIOS_FUNC_NOT_SUPPORTED:
603 return -ENOENT;
604 case PCIBIOS_BAD_VENDOR_ID:
d97ffe23 605 return -ENOTTY;
a6961651
AW
606 case PCIBIOS_DEVICE_NOT_FOUND:
607 return -ENODEV;
608 case PCIBIOS_BAD_REGISTER_NUMBER:
609 return -EFAULT;
610 case PCIBIOS_SET_FAILED:
611 return -EIO;
612 case PCIBIOS_BUFFER_TOO_SMALL:
613 return -ENOSPC;
614 }
615
d97ffe23 616 return -ERANGE;
a6961651
AW
617}
618
1da177e4
LT
619/* Low-level architecture-dependent routines */
620
621struct pci_ops {
057bd2e0
TR
622 int (*add_bus)(struct pci_bus *bus);
623 void (*remove_bus)(struct pci_bus *bus);
1f94a94f 624 void __iomem *(*map_bus)(struct pci_bus *bus, unsigned int devfn, int where);
1da177e4
LT
625 int (*read)(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 *val);
626 int (*write)(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 val);
627};
628
b6ce068a
MW
629/*
630 * ACPI needs to be able to access PCI config space before we've done a
631 * PCI bus scan and created pci_bus structures.
632 */
f39d5b72
BH
633int raw_pci_read(unsigned int domain, unsigned int bus, unsigned int devfn,
634 int reg, int len, u32 *val);
635int raw_pci_write(unsigned int domain, unsigned int bus, unsigned int devfn,
636 int reg, int len, u32 val);
1da177e4 637
3a9ad0b4
YL
638#ifdef CONFIG_PCI_BUS_ADDR_T_64BIT
639typedef u64 pci_bus_addr_t;
640#else
641typedef u32 pci_bus_addr_t;
642#endif
643
1da177e4 644struct pci_bus_region {
3a9ad0b4
YL
645 pci_bus_addr_t start;
646 pci_bus_addr_t end;
1da177e4
LT
647};
648
649struct pci_dynids {
650 spinlock_t lock; /* protects list, index */
651 struct list_head list; /* for IDs added at runtime */
1da177e4
LT
652};
653
f7625980
BH
654
655/*
656 * PCI Error Recovery System (PCI-ERS). If a PCI device driver provides
657 * a set of callbacks in struct pci_error_handlers, that device driver
658 * will be notified of PCI bus errors, and will be driven to recovery
659 * when an error occurs.
392a1ce7
LV
660 */
661
662typedef unsigned int __bitwise pci_ers_result_t;
663
664enum pci_ers_result {
665 /* no result/none/not supported in device driver */
666 PCI_ERS_RESULT_NONE = (__force pci_ers_result_t) 1,
667
668 /* Device driver can recover without slot reset */
669 PCI_ERS_RESULT_CAN_RECOVER = (__force pci_ers_result_t) 2,
670
671 /* Device driver wants slot to be reset. */
672 PCI_ERS_RESULT_NEED_RESET = (__force pci_ers_result_t) 3,
673
674 /* Device has completely failed, is unrecoverable */
675 PCI_ERS_RESULT_DISCONNECT = (__force pci_ers_result_t) 4,
676
677 /* Device driver is fully recovered and operational */
678 PCI_ERS_RESULT_RECOVERED = (__force pci_ers_result_t) 5,
918b4053
VMP
679
680 /* No AER capabilities registered for the driver */
681 PCI_ERS_RESULT_NO_AER_DRIVER = (__force pci_ers_result_t) 6,
392a1ce7
LV
682};
683
684/* PCI bus error event callbacks */
05cca6e5 685struct pci_error_handlers {
392a1ce7
LV
686 /* PCI bus error detected on this device */
687 pci_ers_result_t (*error_detected)(struct pci_dev *dev,
05cca6e5 688 enum pci_channel_state error);
392a1ce7
LV
689
690 /* MMIO has been re-enabled, but not DMA */
691 pci_ers_result_t (*mmio_enabled)(struct pci_dev *dev);
692
392a1ce7
LV
693 /* PCI slot has been reset */
694 pci_ers_result_t (*slot_reset)(struct pci_dev *dev);
695
3ebe7f9f
KB
696 /* PCI function reset prepare or completed */
697 void (*reset_notify)(struct pci_dev *dev, bool prepare);
698
392a1ce7
LV
699 /* Device driver may resume normal operations */
700 void (*resume)(struct pci_dev *dev);
701};
702
392a1ce7 703
1da177e4
LT
704struct module;
705struct pci_driver {
706 struct list_head node;
42b21932 707 const char *name;
1da177e4
LT
708 const struct pci_device_id *id_table; /* must be non-NULL for probe to be called */
709 int (*probe) (struct pci_dev *dev, const struct pci_device_id *id); /* New device inserted */
710 void (*remove) (struct pci_dev *dev); /* Device removed (NULL if not a hot-plug capable driver) */
711 int (*suspend) (struct pci_dev *dev, pm_message_t state); /* Device suspended */
cbd69dbb
LT
712 int (*suspend_late) (struct pci_dev *dev, pm_message_t state);
713 int (*resume_early) (struct pci_dev *dev);
1da177e4 714 int (*resume) (struct pci_dev *dev); /* Device woken up */
c8958177 715 void (*shutdown) (struct pci_dev *dev);
1789382a 716 int (*sriov_configure) (struct pci_dev *dev, int num_vfs); /* PF pdev */
49453028 717 const struct pci_error_handlers *err_handler;
1da177e4
LT
718 struct device_driver driver;
719 struct pci_dynids dynids;
720};
721
05cca6e5 722#define to_pci_driver(drv) container_of(drv, struct pci_driver, driver)
1da177e4
LT
723
724/**
725 * PCI_DEVICE - macro used to describe a specific pci device
726 * @vend: the 16 bit PCI Vendor ID
727 * @dev: the 16 bit PCI Device ID
728 *
729 * This macro is used to create a struct pci_device_id that matches a
730 * specific device. The subvendor and subdevice fields will be set to
731 * PCI_ANY_ID.
732 */
733#define PCI_DEVICE(vend,dev) \
734 .vendor = (vend), .device = (dev), \
735 .subvendor = PCI_ANY_ID, .subdevice = PCI_ANY_ID
736
3d567e0e
NNS
737/**
738 * PCI_DEVICE_SUB - macro used to describe a specific pci device with subsystem
739 * @vend: the 16 bit PCI Vendor ID
740 * @dev: the 16 bit PCI Device ID
741 * @subvend: the 16 bit PCI Subvendor ID
742 * @subdev: the 16 bit PCI Subdevice ID
743 *
744 * This macro is used to create a struct pci_device_id that matches a
745 * specific device with subsystem information.
746 */
747#define PCI_DEVICE_SUB(vend, dev, subvend, subdev) \
748 .vendor = (vend), .device = (dev), \
749 .subvendor = (subvend), .subdevice = (subdev)
750
1da177e4
LT
751/**
752 * PCI_DEVICE_CLASS - macro used to describe a specific pci device class
753 * @dev_class: the class, subclass, prog-if triple for this device
754 * @dev_class_mask: the class mask for this device
755 *
756 * This macro is used to create a struct pci_device_id that matches a
4352dfd5 757 * specific PCI class. The vendor, device, subvendor, and subdevice
1da177e4
LT
758 * fields will be set to PCI_ANY_ID.
759 */
760#define PCI_DEVICE_CLASS(dev_class,dev_class_mask) \
761 .class = (dev_class), .class_mask = (dev_class_mask), \
762 .vendor = PCI_ANY_ID, .device = PCI_ANY_ID, \
763 .subvendor = PCI_ANY_ID, .subdevice = PCI_ANY_ID
764
1597cacb
AC
765/**
766 * PCI_VDEVICE - macro used to describe a specific pci device in short form
c1309040
MR
767 * @vend: the vendor name
768 * @dev: the 16 bit PCI Device ID
1597cacb
AC
769 *
770 * This macro is used to create a struct pci_device_id that matches a
771 * specific PCI device. The subvendor, and subdevice fields will be set
772 * to PCI_ANY_ID. The macro allows the next field to follow as the device
773 * private data.
774 */
775
c1309040
MR
776#define PCI_VDEVICE(vend, dev) \
777 .vendor = PCI_VENDOR_ID_##vend, .device = (dev), \
778 .subvendor = PCI_ANY_ID, .subdevice = PCI_ANY_ID, 0, 0
1597cacb 779
5bbe029f
BH
780enum {
781 PCI_REASSIGN_ALL_RSRC = 0x00000001, /* ignore firmware setup */
782 PCI_REASSIGN_ALL_BUS = 0x00000002, /* reassign all bus numbers */
783 PCI_PROBE_ONLY = 0x00000004, /* use existing setup */
784 PCI_CAN_SKIP_ISA_ALIGN = 0x00000008, /* don't do ISA alignment */
785 PCI_ENABLE_PROC_DOMAINS = 0x00000010, /* enable domains in /proc */
786 PCI_COMPAT_DOMAIN_0 = 0x00000020, /* ... except domain 0 */
787 PCI_SCAN_ALL_PCIE_DEVS = 0x00000040, /* scan all, not just dev 0 */
788};
789
1da177e4
LT
790/* these external functions are only available when PCI support is enabled */
791#ifdef CONFIG_PCI
792
5bbe029f
BH
793extern unsigned int pci_flags;
794
795static inline void pci_set_flags(int flags) { pci_flags = flags; }
796static inline void pci_add_flags(int flags) { pci_flags |= flags; }
797static inline void pci_clear_flags(int flags) { pci_flags &= ~flags; }
798static inline int pci_has_flag(int flag) { return pci_flags & flag; }
799
a58674ff 800void pcie_bus_configure_settings(struct pci_bus *bus);
b03e7495
JM
801
802enum pcie_bus_config_types {
27d868b5
KB
803 PCIE_BUS_TUNE_OFF, /* don't touch MPS at all */
804 PCIE_BUS_DEFAULT, /* ensure MPS matches upstream bridge */
805 PCIE_BUS_SAFE, /* use largest MPS boot-time devices support */
806 PCIE_BUS_PERFORMANCE, /* use MPS and MRRS for best performance */
807 PCIE_BUS_PEER2PEER, /* set MPS = 128 for all devices */
b03e7495
JM
808};
809
810extern enum pcie_bus_config_types pcie_bus_config;
811
1da177e4
LT
812extern struct bus_type pci_bus_type;
813
f7625980
BH
814/* Do NOT directly access these two variables, unless you are arch-specific PCI
815 * code, or PCI core code. */
1da177e4 816extern struct list_head pci_root_buses; /* list of all known PCI buses */
f7625980 817/* Some device drivers need know if PCI is initiated */
f39d5b72 818int no_pci_devices(void);
1da177e4 819
3c449ed0 820void pcibios_resource_survey_bus(struct pci_bus *bus);
7b77061f 821void pcibios_bus_add_device(struct pci_dev *pdev);
10a95747
JL
822void pcibios_add_bus(struct pci_bus *bus);
823void pcibios_remove_bus(struct pci_bus *bus);
1da177e4 824void pcibios_fixup_bus(struct pci_bus *);
4a7fb636 825int __must_check pcibios_enable_device(struct pci_dev *, int mask);
f7625980 826/* Architecture-specific versions may override this (weak) */
05cca6e5 827char *pcibios_setup(char *str);
1da177e4
LT
828
829/* Used only when drivers/pci/setup.c is used */
3b7a17fc 830resource_size_t pcibios_align_resource(void *, const struct resource *,
b26b2d49 831 resource_size_t,
e31dd6e4 832 resource_size_t);
1da177e4
LT
833void pcibios_update_irq(struct pci_dev *, int irq);
834
2d1c8618
BH
835/* Weak but can be overriden by arch */
836void pci_fixup_cardbus(struct pci_bus *);
837
1da177e4
LT
838/* Generic PCI functions used internally */
839
fc279850 840void pcibios_resource_to_bus(struct pci_bus *bus, struct pci_bus_region *region,
36a66cd6 841 struct resource *res);
fc279850 842void pcibios_bus_to_resource(struct pci_bus *bus, struct resource *res,
36a66cd6 843 struct pci_bus_region *region);
d1fd4fb6 844void pcibios_scan_specific_bus(int busn);
f39d5b72 845struct pci_bus *pci_find_bus(int domain, int busnr);
c48f1670 846void pci_bus_add_devices(const struct pci_bus *bus);
de4b2f76 847struct pci_bus *pci_scan_bus(int bus, struct pci_ops *ops, void *sysdata);
166c6370
BH
848struct pci_bus *pci_create_root_bus(struct device *parent, int bus,
849 struct pci_ops *ops, void *sysdata,
850 struct list_head *resources);
98a35831
YL
851int pci_bus_insert_busn_res(struct pci_bus *b, int bus, int busmax);
852int pci_bus_update_busn_res_end(struct pci_bus *b, int busmax);
853void pci_bus_release_busn_res(struct pci_bus *b);
d2a7926d
LP
854struct pci_bus *pci_scan_root_bus_msi(struct device *parent, int bus,
855 struct pci_ops *ops, void *sysdata,
856 struct list_head *resources,
857 struct msi_controller *msi);
15856ad5 858struct pci_bus *pci_scan_root_bus(struct device *parent, int bus,
a2ebb827
BH
859 struct pci_ops *ops, void *sysdata,
860 struct list_head *resources);
05cca6e5
GKH
861struct pci_bus *pci_add_new_bus(struct pci_bus *parent, struct pci_dev *dev,
862 int busnr);
3749c51a 863void pcie_update_link_speed(struct pci_bus *bus, u16 link_status);
f46753c5 864struct pci_slot *pci_create_slot(struct pci_bus *parent, int slot_nr,
828f3768
AC
865 const char *name,
866 struct hotplug_slot *hotplug);
f46753c5 867void pci_destroy_slot(struct pci_slot *slot);
017ffe64
YW
868#ifdef CONFIG_SYSFS
869void pci_dev_assign_slot(struct pci_dev *dev);
870#else
871static inline void pci_dev_assign_slot(struct pci_dev *dev) { }
872#endif
1da177e4 873int pci_scan_slot(struct pci_bus *bus, int devfn);
05cca6e5 874struct pci_dev *pci_scan_single_device(struct pci_bus *bus, int devfn);
cdb9b9f7 875void pci_device_add(struct pci_dev *dev, struct pci_bus *bus);
1da177e4 876unsigned int pci_scan_child_bus(struct pci_bus *bus);
c893d133 877void pci_bus_add_device(struct pci_dev *dev);
1da177e4 878void pci_read_bridge_bases(struct pci_bus *child);
05cca6e5
GKH
879struct resource *pci_find_parent_resource(const struct pci_dev *dev,
880 struct resource *res);
c56d4450 881struct pci_dev *pci_find_pcie_root_port(struct pci_dev *dev);
3df425f3 882u8 pci_swizzle_interrupt_pin(const struct pci_dev *dev, u8 pin);
1da177e4 883int pci_get_interrupt_pin(struct pci_dev *dev, struct pci_dev **bridge);
68feac87 884u8 pci_common_swizzle(struct pci_dev *dev, u8 *pinp);
f39d5b72
BH
885struct pci_dev *pci_dev_get(struct pci_dev *dev);
886void pci_dev_put(struct pci_dev *dev);
887void pci_remove_bus(struct pci_bus *b);
888void pci_stop_and_remove_bus_device(struct pci_dev *dev);
9d16947b 889void pci_stop_and_remove_bus_device_locked(struct pci_dev *dev);
cdfcc572
YL
890void pci_stop_root_bus(struct pci_bus *bus);
891void pci_remove_root_bus(struct pci_bus *bus);
b3743fa4 892void pci_setup_cardbus(struct pci_bus *bus);
d366d28c 893void pcibios_setup_bridge(struct pci_bus *bus, unsigned long type);
f39d5b72 894void pci_sort_breadthfirst(void);
fb8a0d9d
WM
895#define dev_is_pci(d) ((d)->bus == &pci_bus_type)
896#define dev_is_pf(d) ((dev_is_pci(d) ? to_pci_dev(d)->is_physfn : false))
1da177e4
LT
897
898/* Generic PCI functions exported to card drivers */
899
388c8c16
JB
900enum pci_lost_interrupt_reason {
901 PCI_LOST_IRQ_NO_INFORMATION = 0,
902 PCI_LOST_IRQ_DISABLE_MSI,
903 PCI_LOST_IRQ_DISABLE_MSIX,
904 PCI_LOST_IRQ_DISABLE_ACPI,
905};
906enum pci_lost_interrupt_reason pci_lost_interrupt(struct pci_dev *dev);
05cca6e5
GKH
907int pci_find_capability(struct pci_dev *dev, int cap);
908int pci_find_next_capability(struct pci_dev *dev, u8 pos, int cap);
909int pci_find_ext_capability(struct pci_dev *dev, int cap);
44a9a36f 910int pci_find_next_ext_capability(struct pci_dev *dev, int pos, int cap);
05cca6e5
GKH
911int pci_find_ht_capability(struct pci_dev *dev, int ht_cap);
912int pci_find_next_ht_capability(struct pci_dev *dev, int pos, int ht_cap);
29f3eb64 913struct pci_bus *pci_find_next_bus(const struct pci_bus *from);
1da177e4 914
d42552c3
AM
915struct pci_dev *pci_get_device(unsigned int vendor, unsigned int device,
916 struct pci_dev *from);
05cca6e5 917struct pci_dev *pci_get_subsys(unsigned int vendor, unsigned int device,
1da177e4 918 unsigned int ss_vendor, unsigned int ss_device,
b08508c4 919 struct pci_dev *from);
05cca6e5 920struct pci_dev *pci_get_slot(struct pci_bus *bus, unsigned int devfn);
3c299dc2
AP
921struct pci_dev *pci_get_domain_bus_and_slot(int domain, unsigned int bus,
922 unsigned int devfn);
923static inline struct pci_dev *pci_get_bus_and_slot(unsigned int bus,
924 unsigned int devfn)
925{
926 return pci_get_domain_bus_and_slot(0, bus, devfn);
927}
05cca6e5 928struct pci_dev *pci_get_class(unsigned int class, struct pci_dev *from);
1da177e4
LT
929int pci_dev_present(const struct pci_device_id *ids);
930
05cca6e5
GKH
931int pci_bus_read_config_byte(struct pci_bus *bus, unsigned int devfn,
932 int where, u8 *val);
933int pci_bus_read_config_word(struct pci_bus *bus, unsigned int devfn,
934 int where, u16 *val);
935int pci_bus_read_config_dword(struct pci_bus *bus, unsigned int devfn,
936 int where, u32 *val);
937int pci_bus_write_config_byte(struct pci_bus *bus, unsigned int devfn,
938 int where, u8 val);
939int pci_bus_write_config_word(struct pci_bus *bus, unsigned int devfn,
940 int where, u16 val);
941int pci_bus_write_config_dword(struct pci_bus *bus, unsigned int devfn,
942 int where, u32 val);
1f94a94f
RH
943
944int pci_generic_config_read(struct pci_bus *bus, unsigned int devfn,
945 int where, int size, u32 *val);
946int pci_generic_config_write(struct pci_bus *bus, unsigned int devfn,
947 int where, int size, u32 val);
948int pci_generic_config_read32(struct pci_bus *bus, unsigned int devfn,
949 int where, int size, u32 *val);
950int pci_generic_config_write32(struct pci_bus *bus, unsigned int devfn,
951 int where, int size, u32 val);
952
a72b46c3 953struct pci_ops *pci_bus_set_ops(struct pci_bus *bus, struct pci_ops *ops);
1da177e4 954
d3881e50
KB
955int pci_read_config_byte(const struct pci_dev *dev, int where, u8 *val);
956int pci_read_config_word(const struct pci_dev *dev, int where, u16 *val);
957int pci_read_config_dword(const struct pci_dev *dev, int where, u32 *val);
958int pci_write_config_byte(const struct pci_dev *dev, int where, u8 val);
959int pci_write_config_word(const struct pci_dev *dev, int where, u16 val);
960int pci_write_config_dword(const struct pci_dev *dev, int where, u32 val);
1da177e4 961
8c0d3a02
JL
962int pcie_capability_read_word(struct pci_dev *dev, int pos, u16 *val);
963int pcie_capability_read_dword(struct pci_dev *dev, int pos, u32 *val);
964int pcie_capability_write_word(struct pci_dev *dev, int pos, u16 val);
965int pcie_capability_write_dword(struct pci_dev *dev, int pos, u32 val);
966int pcie_capability_clear_and_set_word(struct pci_dev *dev, int pos,
967 u16 clear, u16 set);
968int pcie_capability_clear_and_set_dword(struct pci_dev *dev, int pos,
969 u32 clear, u32 set);
970
971static inline int pcie_capability_set_word(struct pci_dev *dev, int pos,
972 u16 set)
973{
974 return pcie_capability_clear_and_set_word(dev, pos, 0, set);
975}
976
977static inline int pcie_capability_set_dword(struct pci_dev *dev, int pos,
978 u32 set)
979{
980 return pcie_capability_clear_and_set_dword(dev, pos, 0, set);
981}
982
983static inline int pcie_capability_clear_word(struct pci_dev *dev, int pos,
984 u16 clear)
985{
986 return pcie_capability_clear_and_set_word(dev, pos, clear, 0);
987}
988
989static inline int pcie_capability_clear_dword(struct pci_dev *dev, int pos,
990 u32 clear)
991{
992 return pcie_capability_clear_and_set_dword(dev, pos, clear, 0);
993}
994
c63587d7
AW
995/* user-space driven config access */
996int pci_user_read_config_byte(struct pci_dev *dev, int where, u8 *val);
997int pci_user_read_config_word(struct pci_dev *dev, int where, u16 *val);
998int pci_user_read_config_dword(struct pci_dev *dev, int where, u32 *val);
999int pci_user_write_config_byte(struct pci_dev *dev, int where, u8 val);
1000int pci_user_write_config_word(struct pci_dev *dev, int where, u16 val);
1001int pci_user_write_config_dword(struct pci_dev *dev, int where, u32 val);
1002
4a7fb636 1003int __must_check pci_enable_device(struct pci_dev *dev);
b718989d
BH
1004int __must_check pci_enable_device_io(struct pci_dev *dev);
1005int __must_check pci_enable_device_mem(struct pci_dev *dev);
0b62e13b 1006int __must_check pci_reenable_device(struct pci_dev *);
9ac7849e
TH
1007int __must_check pcim_enable_device(struct pci_dev *pdev);
1008void pcim_pin_device(struct pci_dev *pdev);
1009
296ccb08
YS
1010static inline int pci_is_enabled(struct pci_dev *pdev)
1011{
1012 return (atomic_read(&pdev->enable_cnt) > 0);
1013}
1014
9ac7849e
TH
1015static inline int pci_is_managed(struct pci_dev *pdev)
1016{
1017 return pdev->is_managed;
1018}
1019
1da177e4 1020void pci_disable_device(struct pci_dev *dev);
96c55900
MS
1021
1022extern unsigned int pcibios_max_latency;
1da177e4 1023void pci_set_master(struct pci_dev *dev);
6a479079 1024void pci_clear_master(struct pci_dev *dev);
96c55900 1025
f7bdd12d 1026int pci_set_pcie_reset_state(struct pci_dev *dev, enum pcie_reset_state state);
15ea76d4 1027int pci_set_cacheline_size(struct pci_dev *dev);
1da177e4 1028#define HAVE_PCI_SET_MWI
4a7fb636 1029int __must_check pci_set_mwi(struct pci_dev *dev);
694625c0 1030int pci_try_set_mwi(struct pci_dev *dev);
1da177e4 1031void pci_clear_mwi(struct pci_dev *dev);
a04ce0ff 1032void pci_intx(struct pci_dev *dev, int enable);
a2e27787
JK
1033bool pci_intx_mask_supported(struct pci_dev *dev);
1034bool pci_check_and_mask_intx(struct pci_dev *dev);
1035bool pci_check_and_unmask_intx(struct pci_dev *dev);
157e876f 1036int pci_wait_for_pending(struct pci_dev *dev, int pos, u16 mask);
3775a209 1037int pci_wait_for_pending_transaction(struct pci_dev *dev);
d556ad4b
PO
1038int pcix_get_max_mmrbc(struct pci_dev *dev);
1039int pcix_get_mmrbc(struct pci_dev *dev);
1040int pcix_set_mmrbc(struct pci_dev *dev, int mmrbc);
2637e5b5 1041int pcie_get_readrq(struct pci_dev *dev);
d556ad4b 1042int pcie_set_readrq(struct pci_dev *dev, int rq);
b03e7495
JM
1043int pcie_get_mps(struct pci_dev *dev);
1044int pcie_set_mps(struct pci_dev *dev, int mps);
81377c8d
JK
1045int pcie_get_minimum_link(struct pci_dev *dev, enum pci_bus_speed *speed,
1046 enum pcie_link_width *width);
a60a2b73 1047void pcie_flr(struct pci_dev *dev);
8c1c699f 1048int __pci_reset_function(struct pci_dev *dev);
a96d627a 1049int __pci_reset_function_locked(struct pci_dev *dev);
8dd7f803 1050int pci_reset_function(struct pci_dev *dev);
61cf16d8 1051int pci_try_reset_function(struct pci_dev *dev);
9a3d2b9b 1052int pci_probe_reset_slot(struct pci_slot *slot);
090a3c53 1053int pci_reset_slot(struct pci_slot *slot);
61cf16d8 1054int pci_try_reset_slot(struct pci_slot *slot);
9a3d2b9b 1055int pci_probe_reset_bus(struct pci_bus *bus);
090a3c53 1056int pci_reset_bus(struct pci_bus *bus);
61cf16d8 1057int pci_try_reset_bus(struct pci_bus *bus);
9e33002f
GS
1058void pci_reset_secondary_bus(struct pci_dev *dev);
1059void pcibios_reset_secondary_bus(struct pci_dev *dev);
64e8674f 1060void pci_reset_bridge_secondary_bus(struct pci_dev *dev);
14add80b 1061void pci_update_resource(struct pci_dev *dev, int resno);
4a7fb636 1062int __must_check pci_assign_resource(struct pci_dev *dev, int i);
2bbc6942 1063int __must_check pci_reassign_resource(struct pci_dev *dev, int i, resource_size_t add_size, resource_size_t align);
c87deff7 1064int pci_select_bars(struct pci_dev *dev, unsigned long flags);
8496e85c 1065bool pci_device_is_present(struct pci_dev *pdev);
08249651 1066void pci_ignore_hotplug(struct pci_dev *dev);
1da177e4 1067
704e8953
CH
1068int __printf(6, 7) pci_request_irq(struct pci_dev *dev, unsigned int nr,
1069 irq_handler_t handler, irq_handler_t thread_fn, void *dev_id,
1070 const char *fmt, ...);
1071void pci_free_irq(struct pci_dev *dev, unsigned int nr, void *dev_id);
1072
1da177e4 1073/* ROM control related routines */
e416de5e
AC
1074int pci_enable_rom(struct pci_dev *pdev);
1075void pci_disable_rom(struct pci_dev *pdev);
144a50ea 1076void __iomem __must_check *pci_map_rom(struct pci_dev *pdev, size_t *size);
1da177e4 1077void pci_unmap_rom(struct pci_dev *pdev, void __iomem *rom);
97c44836 1078size_t pci_get_rom_size(struct pci_dev *pdev, void __iomem *rom, size_t size);
fffe01f7 1079void __iomem __must_check *pci_platform_rom(struct pci_dev *pdev, size_t *size);
1da177e4
LT
1080
1081/* Power management related routines */
1082int pci_save_state(struct pci_dev *dev);
1d3c16a8 1083void pci_restore_state(struct pci_dev *dev);
ffbdd3f7 1084struct pci_saved_state *pci_store_saved_state(struct pci_dev *dev);
98d9b271
KRW
1085int pci_load_saved_state(struct pci_dev *dev,
1086 struct pci_saved_state *state);
ffbdd3f7
AW
1087int pci_load_and_free_saved_state(struct pci_dev *dev,
1088 struct pci_saved_state **state);
fd0f7f73
AW
1089struct pci_cap_saved_state *pci_find_saved_cap(struct pci_dev *dev, char cap);
1090struct pci_cap_saved_state *pci_find_saved_ext_cap(struct pci_dev *dev,
1091 u16 cap);
1092int pci_add_cap_save_buffer(struct pci_dev *dev, char cap, unsigned int size);
1093int pci_add_ext_cap_save_buffer(struct pci_dev *dev,
1094 u16 cap, unsigned int size);
0e5dd46b 1095int __pci_complete_power_transition(struct pci_dev *dev, pci_power_t state);
9c8550ee
LT
1096int pci_set_power_state(struct pci_dev *dev, pci_power_t state);
1097pci_power_t pci_choose_state(struct pci_dev *dev, pm_message_t state);
e5899e1b 1098bool pci_pme_capable(struct pci_dev *dev, pci_power_t state);
5a6c9b60 1099void pci_pme_active(struct pci_dev *dev, bool enable);
0847684c 1100int pci_enable_wake(struct pci_dev *dev, pci_power_t state, bool enable);
0235c4fc 1101int pci_wake_from_d3(struct pci_dev *dev, bool enable);
404cc2d8
RW
1102int pci_prepare_to_sleep(struct pci_dev *dev);
1103int pci_back_from_sleep(struct pci_dev *dev);
b67ea761 1104bool pci_dev_run_wake(struct pci_dev *dev);
bf4d2908 1105bool pci_check_pme_status(struct pci_dev *dev);
bf4d2908 1106void pci_pme_wakeup_bus(struct pci_bus *bus);
9d26d3a8
MW
1107void pci_d3cold_enable(struct pci_dev *dev);
1108void pci_d3cold_disable(struct pci_dev *dev);
1da177e4 1109
425c1b22
AW
1110/* PCI Virtual Channel */
1111int pci_save_vc_state(struct pci_dev *dev);
1112void pci_restore_vc_state(struct pci_dev *dev);
1113void pci_allocate_vc_save_buffers(struct pci_dev *dev);
51c2e0a7 1114
bb209c82
BH
1115/* For use by arch with custom probe code */
1116void set_pcie_port_type(struct pci_dev *pdev);
1117void set_pcie_hotplug_bridge(struct pci_dev *pdev);
1118
ce5ccdef 1119/* Functions for PCI Hotplug drivers to use */
05cca6e5 1120int pci_bus_find_capability(struct pci_bus *bus, unsigned int devfn, int cap);
2f320521 1121unsigned int pci_rescan_bus_bridge_resize(struct pci_dev *bridge);
3ed4fd96 1122unsigned int pci_rescan_bus(struct pci_bus *bus);
9d16947b
RW
1123void pci_lock_rescan_remove(void);
1124void pci_unlock_rescan_remove(void);
ce5ccdef 1125
287d19ce
SH
1126/* Vital product data routines */
1127ssize_t pci_read_vpd(struct pci_dev *dev, loff_t pos, size_t count, void *buf);
1128ssize_t pci_write_vpd(struct pci_dev *dev, loff_t pos, size_t count, const void *buf);
cb92148b 1129int pci_set_vpd_size(struct pci_dev *dev, size_t len);
287d19ce 1130
1da177e4 1131/* Helper functions for low-level code (drivers/pci/setup-[bus,res].c) */
925845bd 1132resource_size_t pcibios_retrieve_fw_addr(struct pci_dev *dev, int idx);
ea741551 1133void pci_bus_assign_resources(const struct pci_bus *bus);
765bf9b7 1134void pci_bus_claim_resources(struct pci_bus *bus);
1da177e4
LT
1135void pci_bus_size_bridges(struct pci_bus *bus);
1136int pci_claim_resource(struct pci_dev *, int);
8505e729 1137int pci_claim_bridge_resource(struct pci_dev *bridge, int i);
1da177e4 1138void pci_assign_unassigned_resources(void);
6841ec68 1139void pci_assign_unassigned_bridge_resources(struct pci_dev *bridge);
17787940 1140void pci_assign_unassigned_bus_resources(struct pci_bus *bus);
39772038 1141void pci_assign_unassigned_root_bus_resources(struct pci_bus *bus);
1da177e4 1142void pdev_enable_device(struct pci_dev *);
842de40d 1143int pci_enable_resources(struct pci_dev *, int mask);
1da177e4 1144void pci_fixup_irqs(u8 (*)(struct pci_dev *, u8 *),
d5341942 1145 int (*)(const struct pci_dev *, u8, u8));
afd29f90 1146struct resource *pci_find_resource(struct pci_dev *dev, struct resource *res);
1da177e4 1147#define HAVE_PCI_REQ_REGIONS 2
4a7fb636 1148int __must_check pci_request_regions(struct pci_dev *, const char *);
e8de1481 1149int __must_check pci_request_regions_exclusive(struct pci_dev *, const char *);
1da177e4 1150void pci_release_regions(struct pci_dev *);
4a7fb636 1151int __must_check pci_request_region(struct pci_dev *, int, const char *);
e8de1481 1152int __must_check pci_request_region_exclusive(struct pci_dev *, int, const char *);
1da177e4 1153void pci_release_region(struct pci_dev *, int);
c87deff7 1154int pci_request_selected_regions(struct pci_dev *, int, const char *);
e8de1481 1155int pci_request_selected_regions_exclusive(struct pci_dev *, int, const char *);
c87deff7 1156void pci_release_selected_regions(struct pci_dev *, int);
1da177e4
LT
1157
1158/* drivers/pci/bus.c */
fe830ef6
JL
1159struct pci_bus *pci_bus_get(struct pci_bus *bus);
1160void pci_bus_put(struct pci_bus *bus);
45ca9e97 1161void pci_add_resource(struct list_head *resources, struct resource *res);
0efd5aab
BH
1162void pci_add_resource_offset(struct list_head *resources, struct resource *res,
1163 resource_size_t offset);
45ca9e97 1164void pci_free_resource_list(struct list_head *resources);
950334bc
BH
1165void pci_bus_add_resource(struct pci_bus *bus, struct resource *res,
1166 unsigned int flags);
2fe2abf8
BH
1167struct resource *pci_bus_resource_n(const struct pci_bus *bus, int n);
1168void pci_bus_remove_resources(struct pci_bus *bus);
950334bc
BH
1169int devm_request_pci_bus_resources(struct device *dev,
1170 struct list_head *resources);
2fe2abf8 1171
89a74ecc 1172#define pci_bus_for_each_resource(bus, res, i) \
2fe2abf8
BH
1173 for (i = 0; \
1174 (res = pci_bus_resource_n(bus, i)) || i < PCI_BRIDGE_RESOURCE_NUM; \
1175 i++)
89a74ecc 1176
4a7fb636
AM
1177int __must_check pci_bus_alloc_resource(struct pci_bus *bus,
1178 struct resource *res, resource_size_t size,
1179 resource_size_t align, resource_size_t min,
664c2848 1180 unsigned long type_mask,
3b7a17fc
DB
1181 resource_size_t (*alignf)(void *,
1182 const struct resource *,
b26b2d49
DB
1183 resource_size_t,
1184 resource_size_t),
4a7fb636 1185 void *alignf_data);
1da177e4 1186
8b921acf 1187
c5076cfe
TN
1188int pci_register_io_range(phys_addr_t addr, resource_size_t size);
1189unsigned long pci_address_to_pio(phys_addr_t addr);
1190phys_addr_t pci_pio_to_address(unsigned long pio);
8b921acf 1191int pci_remap_iospace(const struct resource *res, phys_addr_t phys_addr);
4d3f1384 1192void pci_unmap_iospace(struct resource *res);
490cb6dd
LP
1193void __iomem *devm_pci_remap_cfgspace(struct device *dev,
1194 resource_size_t offset,
1195 resource_size_t size);
1196void __iomem *devm_pci_remap_cfg_resource(struct device *dev,
1197 struct resource *res);
8b921acf 1198
3a9ad0b4 1199static inline pci_bus_addr_t pci_bus_address(struct pci_dev *pdev, int bar)
06cf56e4
BH
1200{
1201 struct pci_bus_region region;
1202
1203 pcibios_resource_to_bus(pdev->bus, &region, &pdev->resource[bar]);
1204 return region.start;
1205}
1206
863b18f4 1207/* Proper probing supporting hot-pluggable devices */
725522b5
GKH
1208int __must_check __pci_register_driver(struct pci_driver *, struct module *,
1209 const char *mod_name);
bba81165
AM
1210
1211/*
1212 * pci_register_driver must be a macro so that KBUILD_MODNAME can be expanded
1213 */
1214#define pci_register_driver(driver) \
1215 __pci_register_driver(driver, THIS_MODULE, KBUILD_MODNAME)
863b18f4 1216
05cca6e5 1217void pci_unregister_driver(struct pci_driver *dev);
aad4f400
GKH
1218
1219/**
1220 * module_pci_driver() - Helper macro for registering a PCI driver
1221 * @__pci_driver: pci_driver struct
1222 *
1223 * Helper macro for PCI drivers which do not do anything special in module
1224 * init/exit. This eliminates a lot of boilerplate. Each module may only
1225 * use this macro once, and calling it replaces module_init() and module_exit()
1226 */
1227#define module_pci_driver(__pci_driver) \
1228 module_driver(__pci_driver, pci_register_driver, \
1229 pci_unregister_driver)
1230
b4eb6cdb
PG
1231/**
1232 * builtin_pci_driver() - Helper macro for registering a PCI driver
1233 * @__pci_driver: pci_driver struct
1234 *
1235 * Helper macro for PCI drivers which do not do anything special in their
1236 * init code. This eliminates a lot of boilerplate. Each driver may only
1237 * use this macro once, and calling it replaces device_initcall(...)
1238 */
1239#define builtin_pci_driver(__pci_driver) \
1240 builtin_driver(__pci_driver, pci_register_driver)
1241
05cca6e5 1242struct pci_driver *pci_dev_driver(const struct pci_dev *dev);
9dba910e
TH
1243int pci_add_dynid(struct pci_driver *drv,
1244 unsigned int vendor, unsigned int device,
1245 unsigned int subvendor, unsigned int subdevice,
1246 unsigned int class, unsigned int class_mask,
1247 unsigned long driver_data);
05cca6e5
GKH
1248const struct pci_device_id *pci_match_id(const struct pci_device_id *ids,
1249 struct pci_dev *dev);
1250int pci_scan_bridge(struct pci_bus *bus, struct pci_dev *dev, int max,
1251 int pass);
1da177e4 1252
70298c6e 1253void pci_walk_bus(struct pci_bus *top, int (*cb)(struct pci_dev *, void *),
cecf4864 1254 void *userdata);
ac7dc65a 1255int pci_cfg_space_size(struct pci_dev *dev);
05cca6e5 1256unsigned char pci_bus_max_busnr(struct pci_bus *bus);
e2444273 1257void pci_setup_bridge(struct pci_bus *bus);
ac5ad93e
GS
1258resource_size_t pcibios_window_alignment(struct pci_bus *bus,
1259 unsigned long type);
978d2d68 1260resource_size_t pcibios_iov_resource_alignment(struct pci_dev *dev, int resno);
cecf4864 1261
3448a19d
DA
1262#define PCI_VGA_STATE_CHANGE_BRIDGE (1 << 0)
1263#define PCI_VGA_STATE_CHANGE_DECODES (1 << 1)
1264
deb2d2ec 1265int pci_set_vga_state(struct pci_dev *pdev, bool decode,
3448a19d 1266 unsigned int command_bits, u32 flags);
fe537670 1267
4fe0d154
CH
1268#define PCI_IRQ_LEGACY (1 << 0) /* allow legacy interrupts */
1269#define PCI_IRQ_MSI (1 << 1) /* allow MSI interrupts */
1270#define PCI_IRQ_MSIX (1 << 2) /* allow MSI-X interrupts */
1271#define PCI_IRQ_AFFINITY (1 << 3) /* auto-assign affinity */
1272#define PCI_IRQ_ALL_TYPES \
1273 (PCI_IRQ_LEGACY | PCI_IRQ_MSI | PCI_IRQ_MSIX)
aff17164 1274
1da177e4
LT
1275/* kmem_cache style wrapper around pci_alloc_consistent() */
1276
f41b1771 1277#include <linux/pci-dma.h>
1da177e4
LT
1278#include <linux/dmapool.h>
1279
1280#define pci_pool dma_pool
1281#define pci_pool_create(name, pdev, size, align, allocation) \
1282 dma_pool_create(name, &pdev->dev, size, align, allocation)
1283#define pci_pool_destroy(pool) dma_pool_destroy(pool)
1284#define pci_pool_alloc(pool, flags, handle) dma_pool_alloc(pool, flags, handle)
01a7fd33
SS
1285#define pci_pool_zalloc(pool, flags, handle) \
1286 dma_pool_zalloc(pool, flags, handle)
1da177e4
LT
1287#define pci_pool_free(pool, vaddr, addr) dma_pool_free(pool, vaddr, addr)
1288
1da177e4 1289struct msix_entry {
16dbef4a 1290 u32 vector; /* kernel uses to write allocated vector */
1da177e4
LT
1291 u16 entry; /* driver uses to specify entry, OS writes */
1292};
1293
4c859804
BH
1294#ifdef CONFIG_PCI_MSI
1295int pci_msi_vec_count(struct pci_dev *dev);
f39d5b72 1296void pci_disable_msi(struct pci_dev *dev);
4c859804 1297int pci_msix_vec_count(struct pci_dev *dev);
f39d5b72 1298void pci_disable_msix(struct pci_dev *dev);
f39d5b72
BH
1299void pci_restore_msi_state(struct pci_dev *dev);
1300int pci_msi_enabled(void);
4fe03955 1301int pci_enable_msi(struct pci_dev *dev);
4c859804
BH
1302int pci_enable_msix_range(struct pci_dev *dev, struct msix_entry *entries,
1303 int minvec, int maxvec);
f7fc32cb
AG
1304static inline int pci_enable_msix_exact(struct pci_dev *dev,
1305 struct msix_entry *entries, int nvec)
1306{
1307 int rc = pci_enable_msix_range(dev, entries, nvec, nvec);
1308 if (rc < 0)
1309 return rc;
1310 return 0;
1311}
402723ad
CH
1312int pci_alloc_irq_vectors_affinity(struct pci_dev *dev, unsigned int min_vecs,
1313 unsigned int max_vecs, unsigned int flags,
1314 const struct irq_affinity *affd);
1315
aff17164
CH
1316void pci_free_irq_vectors(struct pci_dev *dev);
1317int pci_irq_vector(struct pci_dev *dev, unsigned int nr);
ee8d41e5 1318const struct cpumask *pci_irq_get_affinity(struct pci_dev *pdev, int vec);
27ddb689 1319int pci_irq_get_node(struct pci_dev *pdev, int vec);
aff17164 1320
4c859804 1321#else
2ee546c4 1322static inline int pci_msi_vec_count(struct pci_dev *dev) { return -ENOSYS; }
2ee546c4
BH
1323static inline void pci_disable_msi(struct pci_dev *dev) { }
1324static inline int pci_msix_vec_count(struct pci_dev *dev) { return -ENOSYS; }
2ee546c4 1325static inline void pci_disable_msix(struct pci_dev *dev) { }
2ee546c4
BH
1326static inline void pci_restore_msi_state(struct pci_dev *dev) { }
1327static inline int pci_msi_enabled(void) { return 0; }
4fe03955 1328static inline int pci_enable_msi(struct pci_dev *dev)
f7fc32cb 1329{ return -ENOSYS; }
302a2523
AG
1330static inline int pci_enable_msix_range(struct pci_dev *dev,
1331 struct msix_entry *entries, int minvec, int maxvec)
2ee546c4 1332{ return -ENOSYS; }
f7fc32cb
AG
1333static inline int pci_enable_msix_exact(struct pci_dev *dev,
1334 struct msix_entry *entries, int nvec)
1335{ return -ENOSYS; }
402723ad
CH
1336
1337static inline int
1338pci_alloc_irq_vectors_affinity(struct pci_dev *dev, unsigned int min_vecs,
1339 unsigned int max_vecs, unsigned int flags,
1340 const struct irq_affinity *aff_desc)
aff17164 1341{
83b4605b
CH
1342 if ((flags & PCI_IRQ_LEGACY) && min_vecs == 1 && dev->irq)
1343 return 1;
1344 return -ENOSPC;
aff17164 1345}
402723ad 1346
aff17164
CH
1347static inline void pci_free_irq_vectors(struct pci_dev *dev)
1348{
1349}
1350
1351static inline int pci_irq_vector(struct pci_dev *dev, unsigned int nr)
1352{
1353 if (WARN_ON_ONCE(nr > 0))
1354 return -EINVAL;
1355 return dev->irq;
1356}
ee8d41e5
TG
1357static inline const struct cpumask *pci_irq_get_affinity(struct pci_dev *pdev,
1358 int vec)
1359{
1360 return cpu_possible_mask;
1361}
27ddb689
SL
1362
1363static inline int pci_irq_get_node(struct pci_dev *pdev, int vec)
1364{
1365 return first_online_node;
1366}
1da177e4
LT
1367#endif
1368
402723ad
CH
1369static inline int
1370pci_alloc_irq_vectors(struct pci_dev *dev, unsigned int min_vecs,
1371 unsigned int max_vecs, unsigned int flags)
1372{
1373 return pci_alloc_irq_vectors_affinity(dev, min_vecs, max_vecs, flags,
1374 NULL);
1375}
1376
ab0724ff 1377#ifdef CONFIG_PCIEPORTBUS
415e12b2
RW
1378extern bool pcie_ports_disabled;
1379extern bool pcie_ports_auto;
ab0724ff
MT
1380#else
1381#define pcie_ports_disabled true
1382#define pcie_ports_auto false
1383#endif
415e12b2 1384
4c859804 1385#ifdef CONFIG_PCIEASPM
f39d5b72 1386bool pcie_aspm_support_enabled(void);
4c859804
BH
1387#else
1388static inline bool pcie_aspm_support_enabled(void) { return false; }
3e1b1600
AP
1389#endif
1390
415e12b2
RW
1391#ifdef CONFIG_PCIEAER
1392void pci_no_aer(void);
1393bool pci_aer_available(void);
66b80809 1394int pci_aer_init(struct pci_dev *dev);
415e12b2
RW
1395#else
1396static inline void pci_no_aer(void) { }
1397static inline bool pci_aer_available(void) { return false; }
66b80809 1398static inline int pci_aer_init(struct pci_dev *d) { return -ENODEV; }
415e12b2
RW
1399#endif
1400
4c859804 1401#ifdef CONFIG_PCIE_ECRC
f39d5b72
BH
1402void pcie_set_ecrc_checking(struct pci_dev *dev);
1403void pcie_ecrc_get_policy(char *str);
4c859804 1404#else
2ee546c4
BH
1405static inline void pcie_set_ecrc_checking(struct pci_dev *dev) { }
1406static inline void pcie_ecrc_get_policy(char *str) { }
43c16408
AP
1407#endif
1408
8b955b0d 1409#ifdef CONFIG_HT_IRQ
8b955b0d
EB
1410/* The functions a driver should call */
1411int ht_create_irq(struct pci_dev *dev, int idx);
1412void ht_destroy_irq(unsigned int irq);
8b955b0d
EB
1413#endif /* CONFIG_HT_IRQ */
1414
edc90fee
BH
1415#ifdef CONFIG_PCI_ATS
1416/* Address Translation Service */
1417void pci_ats_init(struct pci_dev *dev);
ff9bee89
BH
1418int pci_enable_ats(struct pci_dev *dev, int ps);
1419void pci_disable_ats(struct pci_dev *dev);
1420int pci_ats_queue_depth(struct pci_dev *dev);
edc90fee 1421#else
ff9bee89
BH
1422static inline void pci_ats_init(struct pci_dev *d) { }
1423static inline int pci_enable_ats(struct pci_dev *d, int ps) { return -ENODEV; }
1424static inline void pci_disable_ats(struct pci_dev *d) { }
1425static inline int pci_ats_queue_depth(struct pci_dev *d) { return -ENODEV; }
edc90fee
BH
1426#endif
1427
eec097d4
BH
1428#ifdef CONFIG_PCIE_PTM
1429int pci_enable_ptm(struct pci_dev *dev, u8 *granularity);
1430#else
1431static inline int pci_enable_ptm(struct pci_dev *dev, u8 *granularity)
1432{ return -EINVAL; }
1433#endif
1434
f39d5b72
BH
1435void pci_cfg_access_lock(struct pci_dev *dev);
1436bool pci_cfg_access_trylock(struct pci_dev *dev);
1437void pci_cfg_access_unlock(struct pci_dev *dev);
e04b0ea2 1438
4352dfd5
GKH
1439/*
1440 * PCI domain support. Sometimes called PCI segment (eg by ACPI),
f7625980 1441 * a PCI domain is defined to be a set of PCI buses which share
4352dfd5
GKH
1442 * configuration space.
1443 */
32a2eea7
JG
1444#ifdef CONFIG_PCI_DOMAINS
1445extern int pci_domains_supported;
41e5c0f8 1446int pci_get_new_domain_nr(void);
32a2eea7
JG
1447#else
1448enum { pci_domains_supported = 0 };
2ee546c4
BH
1449static inline int pci_domain_nr(struct pci_bus *bus) { return 0; }
1450static inline int pci_proc_domain(struct pci_bus *bus) { return 0; }
41e5c0f8 1451static inline int pci_get_new_domain_nr(void) { return -ENOSYS; }
32a2eea7 1452#endif /* CONFIG_PCI_DOMAINS */
1da177e4 1453
670ba0c8
CM
1454/*
1455 * Generic implementation for PCI domain support. If your
1456 * architecture does not need custom management of PCI
1457 * domains then this implementation will be used
1458 */
1459#ifdef CONFIG_PCI_DOMAINS_GENERIC
1460static inline int pci_domain_nr(struct pci_bus *bus)
1461{
1462 return bus->domain_nr;
1463}
2ab51dde
TN
1464#ifdef CONFIG_ACPI
1465int acpi_pci_bus_find_domain_nr(struct pci_bus *bus);
670ba0c8 1466#else
2ab51dde
TN
1467static inline int acpi_pci_bus_find_domain_nr(struct pci_bus *bus)
1468{ return 0; }
1469#endif
9c7cb891 1470int pci_bus_find_domain_nr(struct pci_bus *bus, struct device *parent);
670ba0c8
CM
1471#endif
1472
95a8b6ef
MT
1473/* some architectures require additional setup to direct VGA traffic */
1474typedef int (*arch_set_vga_state_t)(struct pci_dev *pdev, bool decode,
3448a19d 1475 unsigned int command_bits, u32 flags);
f39d5b72 1476void pci_register_set_vga_state(arch_set_vga_state_t func);
95a8b6ef 1477
be9d2e89
JT
1478static inline int
1479pci_request_io_regions(struct pci_dev *pdev, const char *name)
1480{
1481 return pci_request_selected_regions(pdev,
1482 pci_select_bars(pdev, IORESOURCE_IO), name);
1483}
1484
1485static inline void
1486pci_release_io_regions(struct pci_dev *pdev)
1487{
1488 return pci_release_selected_regions(pdev,
1489 pci_select_bars(pdev, IORESOURCE_IO));
1490}
1491
1492static inline int
1493pci_request_mem_regions(struct pci_dev *pdev, const char *name)
1494{
1495 return pci_request_selected_regions(pdev,
1496 pci_select_bars(pdev, IORESOURCE_MEM), name);
1497}
1498
1499static inline void
1500pci_release_mem_regions(struct pci_dev *pdev)
1501{
1502 return pci_release_selected_regions(pdev,
1503 pci_select_bars(pdev, IORESOURCE_MEM));
1504}
1505
4352dfd5 1506#else /* CONFIG_PCI is not enabled */
1da177e4 1507
5bbe029f
BH
1508static inline void pci_set_flags(int flags) { }
1509static inline void pci_add_flags(int flags) { }
1510static inline void pci_clear_flags(int flags) { }
1511static inline int pci_has_flag(int flag) { return 0; }
1512
1da177e4
LT
1513/*
1514 * If the system does not have PCI, clearly these return errors. Define
1515 * these as simple inline functions to avoid hair in drivers.
1516 */
1517
05cca6e5
GKH
1518#define _PCI_NOP(o, s, t) \
1519 static inline int pci_##o##_config_##s(struct pci_dev *dev, \
1520 int where, t val) \
1da177e4 1521 { return PCIBIOS_FUNC_NOT_SUPPORTED; }
05cca6e5
GKH
1522
1523#define _PCI_NOP_ALL(o, x) _PCI_NOP(o, byte, u8 x) \
1524 _PCI_NOP(o, word, u16 x) \
1525 _PCI_NOP(o, dword, u32 x)
1da177e4
LT
1526_PCI_NOP_ALL(read, *)
1527_PCI_NOP_ALL(write,)
1528
d42552c3 1529static inline struct pci_dev *pci_get_device(unsigned int vendor,
05cca6e5
GKH
1530 unsigned int device,
1531 struct pci_dev *from)
2ee546c4 1532{ return NULL; }
d42552c3 1533
05cca6e5
GKH
1534static inline struct pci_dev *pci_get_subsys(unsigned int vendor,
1535 unsigned int device,
1536 unsigned int ss_vendor,
1537 unsigned int ss_device,
b08508c4 1538 struct pci_dev *from)
2ee546c4 1539{ return NULL; }
1da177e4 1540
05cca6e5
GKH
1541static inline struct pci_dev *pci_get_class(unsigned int class,
1542 struct pci_dev *from)
2ee546c4 1543{ return NULL; }
1da177e4
LT
1544
1545#define pci_dev_present(ids) (0)
ed4aaadb 1546#define no_pci_devices() (1)
1da177e4
LT
1547#define pci_dev_put(dev) do { } while (0)
1548
2ee546c4
BH
1549static inline void pci_set_master(struct pci_dev *dev) { }
1550static inline int pci_enable_device(struct pci_dev *dev) { return -EIO; }
1551static inline void pci_disable_device(struct pci_dev *dev) { }
05cca6e5 1552static inline int pci_assign_resource(struct pci_dev *dev, int i)
2ee546c4 1553{ return -EBUSY; }
05cca6e5
GKH
1554static inline int __pci_register_driver(struct pci_driver *drv,
1555 struct module *owner)
2ee546c4 1556{ return 0; }
05cca6e5 1557static inline int pci_register_driver(struct pci_driver *drv)
2ee546c4
BH
1558{ return 0; }
1559static inline void pci_unregister_driver(struct pci_driver *drv) { }
05cca6e5 1560static inline int pci_find_capability(struct pci_dev *dev, int cap)
2ee546c4 1561{ return 0; }
05cca6e5
GKH
1562static inline int pci_find_next_capability(struct pci_dev *dev, u8 post,
1563 int cap)
2ee546c4 1564{ return 0; }
05cca6e5 1565static inline int pci_find_ext_capability(struct pci_dev *dev, int cap)
2ee546c4 1566{ return 0; }
05cca6e5 1567
1da177e4 1568/* Power management related routines */
2ee546c4
BH
1569static inline int pci_save_state(struct pci_dev *dev) { return 0; }
1570static inline void pci_restore_state(struct pci_dev *dev) { }
05cca6e5 1571static inline int pci_set_power_state(struct pci_dev *dev, pci_power_t state)
2ee546c4 1572{ return 0; }
3449248c 1573static inline int pci_wake_from_d3(struct pci_dev *dev, bool enable)
2ee546c4 1574{ return 0; }
05cca6e5
GKH
1575static inline pci_power_t pci_choose_state(struct pci_dev *dev,
1576 pm_message_t state)
2ee546c4 1577{ return PCI_D0; }
05cca6e5
GKH
1578static inline int pci_enable_wake(struct pci_dev *dev, pci_power_t state,
1579 int enable)
2ee546c4 1580{ return 0; }
48a92a81 1581
afd29f90
MW
1582static inline struct resource *pci_find_resource(struct pci_dev *dev,
1583 struct resource *res)
1584{ return NULL; }
05cca6e5 1585static inline int pci_request_regions(struct pci_dev *dev, const char *res_name)
2ee546c4
BH
1586{ return -EIO; }
1587static inline void pci_release_regions(struct pci_dev *dev) { }
0da0ead9 1588
c5076cfe
TN
1589static inline unsigned long pci_address_to_pio(phys_addr_t addr) { return -1; }
1590
2ee546c4 1591static inline void pci_block_cfg_access(struct pci_dev *dev) { }
fb51ccbf
JK
1592static inline int pci_block_cfg_access_in_atomic(struct pci_dev *dev)
1593{ return 0; }
2ee546c4 1594static inline void pci_unblock_cfg_access(struct pci_dev *dev) { }
e04b0ea2 1595
d80d0217
RD
1596static inline struct pci_bus *pci_find_next_bus(const struct pci_bus *from)
1597{ return NULL; }
d80d0217
RD
1598static inline struct pci_dev *pci_get_slot(struct pci_bus *bus,
1599 unsigned int devfn)
1600{ return NULL; }
d80d0217
RD
1601static inline struct pci_dev *pci_get_bus_and_slot(unsigned int bus,
1602 unsigned int devfn)
1603{ return NULL; }
1604
2ee546c4
BH
1605static inline int pci_domain_nr(struct pci_bus *bus) { return 0; }
1606static inline struct pci_dev *pci_dev_get(struct pci_dev *dev) { return NULL; }
41e5c0f8 1607static inline int pci_get_new_domain_nr(void) { return -ENOSYS; }
12ea6cad 1608
fb8a0d9d
WM
1609#define dev_is_pci(d) (false)
1610#define dev_is_pf(d) (false)
4352dfd5 1611#endif /* CONFIG_PCI */
1da177e4 1612
4352dfd5
GKH
1613/* Include architecture-dependent settings and functions */
1614
1615#include <asm/pci.h>
1da177e4 1616
f7195824
DW
1617/* These two functions provide almost identical functionality. Depennding
1618 * on the architecture, one will be implemented as a wrapper around the
1619 * other (in drivers/pci/mmap.c).
1620 *
1621 * pci_mmap_resource_range() maps a specific BAR, and vm->vm_pgoff
1622 * is expected to be an offset within that region.
1623 *
1624 * pci_mmap_page_range() is the legacy architecture-specific interface,
1625 * which accepts a "user visible" resource address converted by
1626 * pci_resource_to_user(), as used in the legacy mmap() interface in
1627 * /proc/bus/pci/.
1628 */
1629int pci_mmap_resource_range(struct pci_dev *dev, int bar,
1630 struct vm_area_struct *vma,
1631 enum pci_mmap_state mmap_state, int write_combine);
f66e2258
DW
1632int pci_mmap_page_range(struct pci_dev *pdev, int bar,
1633 struct vm_area_struct *vma,
11df1954
DW
1634 enum pci_mmap_state mmap_state, int write_combine);
1635
ae749c7a
DW
1636#ifndef arch_can_pci_mmap_wc
1637#define arch_can_pci_mmap_wc() 0
1638#endif
2bea36fd 1639
e854d8b2
DW
1640#ifndef arch_can_pci_mmap_io
1641#define arch_can_pci_mmap_io() 0
2bea36fd
DW
1642#define pci_iobar_pfn(pdev, bar, vma) (-EINVAL)
1643#else
1644int pci_iobar_pfn(struct pci_dev *pdev, int bar, struct vm_area_struct *vma);
e854d8b2 1645#endif
ae749c7a 1646
92016ba5
JO
1647#ifndef pci_root_bus_fwnode
1648#define pci_root_bus_fwnode(bus) NULL
1649#endif
1650
1da177e4
LT
1651/* these helpers provide future and backwards compatibility
1652 * for accessing popular PCI BAR info */
05cca6e5
GKH
1653#define pci_resource_start(dev, bar) ((dev)->resource[(bar)].start)
1654#define pci_resource_end(dev, bar) ((dev)->resource[(bar)].end)
1655#define pci_resource_flags(dev, bar) ((dev)->resource[(bar)].flags)
1da177e4 1656#define pci_resource_len(dev,bar) \
05cca6e5
GKH
1657 ((pci_resource_start((dev), (bar)) == 0 && \
1658 pci_resource_end((dev), (bar)) == \
1659 pci_resource_start((dev), (bar))) ? 0 : \
1660 \
1661 (pci_resource_end((dev), (bar)) - \
1662 pci_resource_start((dev), (bar)) + 1))
1da177e4
LT
1663
1664/* Similar to the helpers above, these manipulate per-pci_dev
1665 * driver-specific data. They are really just a wrapper around
1666 * the generic device structure functions of these calls.
1667 */
05cca6e5 1668static inline void *pci_get_drvdata(struct pci_dev *pdev)
1da177e4
LT
1669{
1670 return dev_get_drvdata(&pdev->dev);
1671}
1672
05cca6e5 1673static inline void pci_set_drvdata(struct pci_dev *pdev, void *data)
1da177e4
LT
1674{
1675 dev_set_drvdata(&pdev->dev, data);
1676}
1677
1678/* If you want to know what to call your pci_dev, ask this function.
1679 * Again, it's a wrapper around the generic device.
1680 */
2fc90f61 1681static inline const char *pci_name(const struct pci_dev *pdev)
1da177e4 1682{
c6c4f070 1683 return dev_name(&pdev->dev);
1da177e4
LT
1684}
1685
2311b1f2
ME
1686
1687/* Some archs don't want to expose struct resource to userland as-is
1688 * in sysfs and /proc
1689 */
8221a013
BH
1690#ifdef HAVE_ARCH_PCI_RESOURCE_TO_USER
1691void pci_resource_to_user(const struct pci_dev *dev, int bar,
1692 const struct resource *rsrc,
1693 resource_size_t *start, resource_size_t *end);
1694#else
2311b1f2 1695static inline void pci_resource_to_user(const struct pci_dev *dev, int bar,
05cca6e5 1696 const struct resource *rsrc, resource_size_t *start,
e31dd6e4 1697 resource_size_t *end)
2311b1f2
ME
1698{
1699 *start = rsrc->start;
1700 *end = rsrc->end;
1701}
1702#endif /* HAVE_ARCH_PCI_RESOURCE_TO_USER */
1703
1704
1da177e4
LT
1705/*
1706 * The world is not perfect and supplies us with broken PCI devices.
1707 * For at least a part of these bugs we need a work-around, so both
1708 * generic (drivers/pci/quirks.c) and per-architecture code can define
1709 * fixup hooks to be called for particular buggy devices.
1710 */
1711
1712struct pci_fixup {
f4ca5c6a
YL
1713 u16 vendor; /* You can use PCI_ANY_ID here of course */
1714 u16 device; /* You can use PCI_ANY_ID here of course */
1715 u32 class; /* You can use PCI_ANY_ID here too */
1716 unsigned int class_shift; /* should be 0, 8, 16 */
1da177e4
LT
1717 void (*hook)(struct pci_dev *dev);
1718};
1719
1720enum pci_fixup_pass {
1721 pci_fixup_early, /* Before probing BARs */
1722 pci_fixup_header, /* After reading configuration header */
1723 pci_fixup_final, /* Final phase of device fixups */
1724 pci_fixup_enable, /* pci_enable_device() time */
e1a2a51e 1725 pci_fixup_resume, /* pci_device_resume() */
7d2a01b8 1726 pci_fixup_suspend, /* pci_device_suspend() */
e1a2a51e 1727 pci_fixup_resume_early, /* pci_device_resume_early() */
7d2a01b8 1728 pci_fixup_suspend_late, /* pci_device_suspend_late() */
1da177e4
LT
1729};
1730
1731/* Anonymous variables would be nice... */
f4ca5c6a
YL
1732#define DECLARE_PCI_FIXUP_SECTION(section, name, vendor, device, class, \
1733 class_shift, hook) \
ecf61c78 1734 static const struct pci_fixup __PASTE(__pci_fixup_##name,__LINE__) __used \
f4ca5c6a
YL
1735 __attribute__((__section__(#section), aligned((sizeof(void *))))) \
1736 = { vendor, device, class, class_shift, hook };
1737
1738#define DECLARE_PCI_FIXUP_CLASS_EARLY(vendor, device, class, \
1739 class_shift, hook) \
1740 DECLARE_PCI_FIXUP_SECTION(.pci_fixup_early, \
ecf61c78 1741 hook, vendor, device, class, class_shift, hook)
f4ca5c6a
YL
1742#define DECLARE_PCI_FIXUP_CLASS_HEADER(vendor, device, class, \
1743 class_shift, hook) \
1744 DECLARE_PCI_FIXUP_SECTION(.pci_fixup_header, \
ecf61c78 1745 hook, vendor, device, class, class_shift, hook)
f4ca5c6a
YL
1746#define DECLARE_PCI_FIXUP_CLASS_FINAL(vendor, device, class, \
1747 class_shift, hook) \
1748 DECLARE_PCI_FIXUP_SECTION(.pci_fixup_final, \
ecf61c78 1749 hook, vendor, device, class, class_shift, hook)
f4ca5c6a
YL
1750#define DECLARE_PCI_FIXUP_CLASS_ENABLE(vendor, device, class, \
1751 class_shift, hook) \
1752 DECLARE_PCI_FIXUP_SECTION(.pci_fixup_enable, \
ecf61c78 1753 hook, vendor, device, class, class_shift, hook)
f4ca5c6a
YL
1754#define DECLARE_PCI_FIXUP_CLASS_RESUME(vendor, device, class, \
1755 class_shift, hook) \
1756 DECLARE_PCI_FIXUP_SECTION(.pci_fixup_resume, \
ecf61c78 1757 resume##hook, vendor, device, class, \
f4ca5c6a
YL
1758 class_shift, hook)
1759#define DECLARE_PCI_FIXUP_CLASS_RESUME_EARLY(vendor, device, class, \
1760 class_shift, hook) \
1761 DECLARE_PCI_FIXUP_SECTION(.pci_fixup_resume_early, \
ecf61c78 1762 resume_early##hook, vendor, device, \
f4ca5c6a
YL
1763 class, class_shift, hook)
1764#define DECLARE_PCI_FIXUP_CLASS_SUSPEND(vendor, device, class, \
1765 class_shift, hook) \
1766 DECLARE_PCI_FIXUP_SECTION(.pci_fixup_suspend, \
ecf61c78 1767 suspend##hook, vendor, device, class, \
f4ca5c6a 1768 class_shift, hook)
7d2a01b8
AN
1769#define DECLARE_PCI_FIXUP_CLASS_SUSPEND_LATE(vendor, device, class, \
1770 class_shift, hook) \
1771 DECLARE_PCI_FIXUP_SECTION(.pci_fixup_suspend_late, \
1772 suspend_late##hook, vendor, device, \
1773 class, class_shift, hook)
f4ca5c6a 1774
1da177e4
LT
1775#define DECLARE_PCI_FIXUP_EARLY(vendor, device, hook) \
1776 DECLARE_PCI_FIXUP_SECTION(.pci_fixup_early, \
ecf61c78 1777 hook, vendor, device, PCI_ANY_ID, 0, hook)
1da177e4
LT
1778#define DECLARE_PCI_FIXUP_HEADER(vendor, device, hook) \
1779 DECLARE_PCI_FIXUP_SECTION(.pci_fixup_header, \
ecf61c78 1780 hook, vendor, device, PCI_ANY_ID, 0, hook)
1da177e4
LT
1781#define DECLARE_PCI_FIXUP_FINAL(vendor, device, hook) \
1782 DECLARE_PCI_FIXUP_SECTION(.pci_fixup_final, \
ecf61c78 1783 hook, vendor, device, PCI_ANY_ID, 0, hook)
1da177e4
LT
1784#define DECLARE_PCI_FIXUP_ENABLE(vendor, device, hook) \
1785 DECLARE_PCI_FIXUP_SECTION(.pci_fixup_enable, \
ecf61c78 1786 hook, vendor, device, PCI_ANY_ID, 0, hook)
1597cacb
AC
1787#define DECLARE_PCI_FIXUP_RESUME(vendor, device, hook) \
1788 DECLARE_PCI_FIXUP_SECTION(.pci_fixup_resume, \
ecf61c78 1789 resume##hook, vendor, device, \
f4ca5c6a 1790 PCI_ANY_ID, 0, hook)
e1a2a51e
RW
1791#define DECLARE_PCI_FIXUP_RESUME_EARLY(vendor, device, hook) \
1792 DECLARE_PCI_FIXUP_SECTION(.pci_fixup_resume_early, \
ecf61c78 1793 resume_early##hook, vendor, device, \
f4ca5c6a 1794 PCI_ANY_ID, 0, hook)
e1a2a51e
RW
1795#define DECLARE_PCI_FIXUP_SUSPEND(vendor, device, hook) \
1796 DECLARE_PCI_FIXUP_SECTION(.pci_fixup_suspend, \
ecf61c78 1797 suspend##hook, vendor, device, \
f4ca5c6a 1798 PCI_ANY_ID, 0, hook)
7d2a01b8
AN
1799#define DECLARE_PCI_FIXUP_SUSPEND_LATE(vendor, device, hook) \
1800 DECLARE_PCI_FIXUP_SECTION(.pci_fixup_suspend_late, \
1801 suspend_late##hook, vendor, device, \
1802 PCI_ANY_ID, 0, hook)
1da177e4 1803
93177a74 1804#ifdef CONFIG_PCI_QUIRKS
1da177e4 1805void pci_fixup_device(enum pci_fixup_pass pass, struct pci_dev *dev);
ad805758 1806int pci_dev_specific_acs_enabled(struct pci_dev *dev, u16 acs_flags);
c1d61c9b 1807int pci_dev_specific_enable_acs(struct pci_dev *dev);
93177a74
RW
1808#else
1809static inline void pci_fixup_device(enum pci_fixup_pass pass,
2ee546c4 1810 struct pci_dev *dev) { }
ad805758
AW
1811static inline int pci_dev_specific_acs_enabled(struct pci_dev *dev,
1812 u16 acs_flags)
1813{
1814 return -ENOTTY;
1815}
c1d61c9b
AW
1816static inline int pci_dev_specific_enable_acs(struct pci_dev *dev)
1817{
1818 return -ENOTTY;
1819}
93177a74 1820#endif
1da177e4 1821
05cca6e5 1822void __iomem *pcim_iomap(struct pci_dev *pdev, int bar, unsigned long maxlen);
5ea81769 1823void pcim_iounmap(struct pci_dev *pdev, void __iomem *addr);
05cca6e5 1824void __iomem * const *pcim_iomap_table(struct pci_dev *pdev);
fb7ebfe4
YL
1825int pcim_iomap_regions(struct pci_dev *pdev, int mask, const char *name);
1826int pcim_iomap_regions_request_all(struct pci_dev *pdev, int mask,
916fbfb7 1827 const char *name);
fb7ebfe4 1828void pcim_iounmap_regions(struct pci_dev *pdev, int mask);
5ea81769 1829
1da177e4 1830extern int pci_pci_problems;
236561e5 1831#define PCIPCI_FAIL 1 /* No PCI PCI DMA */
1da177e4
LT
1832#define PCIPCI_TRITON 2
1833#define PCIPCI_NATOMA 4
1834#define PCIPCI_VIAETBF 8
1835#define PCIPCI_VSFX 16
236561e5
AC
1836#define PCIPCI_ALIMAGIK 32 /* Need low latency setting */
1837#define PCIAGP_FAIL 64 /* No PCI to AGP DMA */
1da177e4 1838
4516a618
AN
1839extern unsigned long pci_cardbus_io_size;
1840extern unsigned long pci_cardbus_mem_size;
15856ad5 1841extern u8 pci_dfl_cache_line_size;
ac1aa47b 1842extern u8 pci_cache_line_size;
4516a618 1843
28760489
EB
1844extern unsigned long pci_hotplug_io_size;
1845extern unsigned long pci_hotplug_mem_size;
e16b4660 1846extern unsigned long pci_hotplug_bus_size;
28760489 1847
f7625980 1848/* Architecture-specific versions may override these (weak) */
19792a08 1849void pcibios_disable_device(struct pci_dev *dev);
cfce9fb8 1850void pcibios_set_master(struct pci_dev *dev);
19792a08
AB
1851int pcibios_set_pcie_reset_state(struct pci_dev *dev,
1852 enum pcie_reset_state state);
eca0d467 1853int pcibios_add_device(struct pci_dev *dev);
6ae32c53 1854void pcibios_release_device(struct pci_dev *dev);
a43ae58c 1855void pcibios_penalize_isa_irq(int irq, int active);
890e4847
JL
1856int pcibios_alloc_irq(struct pci_dev *dev);
1857void pcibios_free_irq(struct pci_dev *dev);
575e3348 1858
699c1985
SO
1859#ifdef CONFIG_HIBERNATE_CALLBACKS
1860extern struct dev_pm_ops pcibios_pm_ops;
1861#endif
1862
935c760e 1863#if defined(CONFIG_PCI_MMCONFIG) || defined(CONFIG_ACPI_MCFG)
f39d5b72
BH
1864void __init pci_mmcfg_early_init(void);
1865void __init pci_mmcfg_late_init(void);
7752d5cf 1866#else
bb63b421 1867static inline void pci_mmcfg_early_init(void) { }
7752d5cf
RH
1868static inline void pci_mmcfg_late_init(void) { }
1869#endif
1870
642c92da 1871int pci_ext_cfg_avail(void);
0ef5f8f6 1872
1684f5dd 1873void __iomem *pci_ioremap_bar(struct pci_dev *pdev, int bar);
c43996f4 1874void __iomem *pci_ioremap_wc_bar(struct pci_dev *pdev, int bar);
aa42d7c6 1875
dd7cc44d 1876#ifdef CONFIG_PCI_IOV
b07579c0
WY
1877int pci_iov_virtfn_bus(struct pci_dev *dev, int id);
1878int pci_iov_virtfn_devfn(struct pci_dev *dev, int id);
1879
f39d5b72
BH
1880int pci_enable_sriov(struct pci_dev *dev, int nr_virtfn);
1881void pci_disable_sriov(struct pci_dev *dev);
c194f7ea
WY
1882int pci_iov_add_virtfn(struct pci_dev *dev, int id, int reset);
1883void pci_iov_remove_virtfn(struct pci_dev *dev, int id, int reset);
f39d5b72 1884int pci_num_vf(struct pci_dev *dev);
5a8eb242 1885int pci_vfs_assigned(struct pci_dev *dev);
f39d5b72
BH
1886int pci_sriov_set_totalvfs(struct pci_dev *dev, u16 numvfs);
1887int pci_sriov_get_totalvfs(struct pci_dev *dev);
0e6c9122 1888resource_size_t pci_iov_resource_size(struct pci_dev *dev, int resno);
dd7cc44d 1889#else
b07579c0
WY
1890static inline int pci_iov_virtfn_bus(struct pci_dev *dev, int id)
1891{
1892 return -ENOSYS;
1893}
1894static inline int pci_iov_virtfn_devfn(struct pci_dev *dev, int id)
1895{
1896 return -ENOSYS;
1897}
dd7cc44d 1898static inline int pci_enable_sriov(struct pci_dev *dev, int nr_virtfn)
2ee546c4 1899{ return -ENODEV; }
c194f7ea
WY
1900static inline int pci_iov_add_virtfn(struct pci_dev *dev, int id, int reset)
1901{
1902 return -ENOSYS;
1903}
1904static inline void pci_iov_remove_virtfn(struct pci_dev *dev,
1905 int id, int reset) { }
2ee546c4 1906static inline void pci_disable_sriov(struct pci_dev *dev) { }
2ee546c4 1907static inline int pci_num_vf(struct pci_dev *dev) { return 0; }
5a8eb242 1908static inline int pci_vfs_assigned(struct pci_dev *dev)
2ee546c4 1909{ return 0; }
bff73156 1910static inline int pci_sriov_set_totalvfs(struct pci_dev *dev, u16 numvfs)
2ee546c4 1911{ return 0; }
bff73156 1912static inline int pci_sriov_get_totalvfs(struct pci_dev *dev)
2ee546c4 1913{ return 0; }
0e6c9122
WY
1914static inline resource_size_t pci_iov_resource_size(struct pci_dev *dev, int resno)
1915{ return 0; }
dd7cc44d
YZ
1916#endif
1917
c825bc94 1918#if defined(CONFIG_HOTPLUG_PCI) || defined(CONFIG_HOTPLUG_PCI_MODULE)
f39d5b72
BH
1919void pci_hp_create_module_link(struct pci_slot *pci_slot);
1920void pci_hp_remove_module_link(struct pci_slot *pci_slot);
c825bc94
KK
1921#endif
1922
d7b7e605
KK
1923/**
1924 * pci_pcie_cap - get the saved PCIe capability offset
1925 * @dev: PCI device
1926 *
1927 * PCIe capability offset is calculated at PCI device initialization
1928 * time and saved in the data structure. This function returns saved
1929 * PCIe capability offset. Using this instead of pci_find_capability()
1930 * reduces unnecessary search in the PCI configuration space. If you
1931 * need to calculate PCIe capability offset from raw device for some
1932 * reasons, please use pci_find_capability() instead.
1933 */
1934static inline int pci_pcie_cap(struct pci_dev *dev)
1935{
1936 return dev->pcie_cap;
1937}
1938
7eb776c4
KK
1939/**
1940 * pci_is_pcie - check if the PCI device is PCI Express capable
1941 * @dev: PCI device
1942 *
a895c28a 1943 * Returns: true if the PCI device is PCI Express capable, false otherwise.
7eb776c4
KK
1944 */
1945static inline bool pci_is_pcie(struct pci_dev *dev)
1946{
a895c28a 1947 return pci_pcie_cap(dev);
7eb776c4
KK
1948}
1949
7c9c003c
MS
1950/**
1951 * pcie_caps_reg - get the PCIe Capabilities Register
1952 * @dev: PCI device
1953 */
1954static inline u16 pcie_caps_reg(const struct pci_dev *dev)
1955{
1956 return dev->pcie_flags_reg;
1957}
1958
786e2288
YW
1959/**
1960 * pci_pcie_type - get the PCIe device/port type
1961 * @dev: PCI device
1962 */
1963static inline int pci_pcie_type(const struct pci_dev *dev)
1964{
1c531d82 1965 return (pcie_caps_reg(dev) & PCI_EXP_FLAGS_TYPE) >> 4;
786e2288
YW
1966}
1967
e784930b
JT
1968static inline struct pci_dev *pcie_find_root_port(struct pci_dev *dev)
1969{
1970 while (1) {
1971 if (!pci_is_pcie(dev))
1972 break;
1973 if (pci_pcie_type(dev) == PCI_EXP_TYPE_ROOT_PORT)
1974 return dev;
1975 if (!dev->bus->self)
1976 break;
1977 dev = dev->bus->self;
1978 }
1979 return NULL;
1980}
1981
5d990b62 1982void pci_request_acs(void);
ad805758
AW
1983bool pci_acs_enabled(struct pci_dev *pdev, u16 acs_flags);
1984bool pci_acs_path_enabled(struct pci_dev *start,
1985 struct pci_dev *end, u16 acs_flags);
a2ce7662 1986
7ad506fa 1987#define PCI_VPD_LRDT 0x80 /* Large Resource Data Type */
63ddc0b8 1988#define PCI_VPD_LRDT_ID(x) ((x) | PCI_VPD_LRDT)
7ad506fa
MC
1989
1990/* Large Resource Data Type Tag Item Names */
1991#define PCI_VPD_LTIN_ID_STRING 0x02 /* Identifier String */
1992#define PCI_VPD_LTIN_RO_DATA 0x10 /* Read-Only Data */
1993#define PCI_VPD_LTIN_RW_DATA 0x11 /* Read-Write Data */
1994
1995#define PCI_VPD_LRDT_ID_STRING PCI_VPD_LRDT_ID(PCI_VPD_LTIN_ID_STRING)
1996#define PCI_VPD_LRDT_RO_DATA PCI_VPD_LRDT_ID(PCI_VPD_LTIN_RO_DATA)
1997#define PCI_VPD_LRDT_RW_DATA PCI_VPD_LRDT_ID(PCI_VPD_LTIN_RW_DATA)
1998
1999/* Small Resource Data Type Tag Item Names */
9eb45d5c 2000#define PCI_VPD_STIN_END 0x0f /* End */
7ad506fa 2001
9eb45d5c 2002#define PCI_VPD_SRDT_END (PCI_VPD_STIN_END << 3)
7ad506fa
MC
2003
2004#define PCI_VPD_SRDT_TIN_MASK 0x78
2005#define PCI_VPD_SRDT_LEN_MASK 0x07
9eb45d5c 2006#define PCI_VPD_LRDT_TIN_MASK 0x7f
7ad506fa
MC
2007
2008#define PCI_VPD_LRDT_TAG_SIZE 3
2009#define PCI_VPD_SRDT_TAG_SIZE 1
a2ce7662 2010
e1d5bdab
MC
2011#define PCI_VPD_INFO_FLD_HDR_SIZE 3
2012
4067a854
MC
2013#define PCI_VPD_RO_KEYWORD_PARTNO "PN"
2014#define PCI_VPD_RO_KEYWORD_MFR_ID "MN"
2015#define PCI_VPD_RO_KEYWORD_VENDOR0 "V0"
d4894f3e 2016#define PCI_VPD_RO_KEYWORD_CHKSUM "RV"
4067a854 2017
a2ce7662
MC
2018/**
2019 * pci_vpd_lrdt_size - Extracts the Large Resource Data Type length
2020 * @lrdt: Pointer to the beginning of the Large Resource Data Type tag
2021 *
2022 * Returns the extracted Large Resource Data Type length.
2023 */
2024static inline u16 pci_vpd_lrdt_size(const u8 *lrdt)
2025{
2026 return (u16)lrdt[1] + ((u16)lrdt[2] << 8);
2027}
2028
9eb45d5c
HR
2029/**
2030 * pci_vpd_lrdt_tag - Extracts the Large Resource Data Type Tag Item
2031 * @lrdt: Pointer to the beginning of the Large Resource Data Type tag
2032 *
2033 * Returns the extracted Large Resource Data Type Tag item.
2034 */
2035static inline u16 pci_vpd_lrdt_tag(const u8 *lrdt)
2036{
2037 return (u16)(lrdt[0] & PCI_VPD_LRDT_TIN_MASK);
2038}
2039
7ad506fa
MC
2040/**
2041 * pci_vpd_srdt_size - Extracts the Small Resource Data Type length
2042 * @lrdt: Pointer to the beginning of the Small Resource Data Type tag
2043 *
2044 * Returns the extracted Small Resource Data Type length.
2045 */
2046static inline u8 pci_vpd_srdt_size(const u8 *srdt)
2047{
2048 return (*srdt) & PCI_VPD_SRDT_LEN_MASK;
2049}
2050
9eb45d5c
HR
2051/**
2052 * pci_vpd_srdt_tag - Extracts the Small Resource Data Type Tag Item
2053 * @lrdt: Pointer to the beginning of the Small Resource Data Type tag
2054 *
2055 * Returns the extracted Small Resource Data Type Tag Item.
2056 */
2057static inline u8 pci_vpd_srdt_tag(const u8 *srdt)
2058{
2059 return ((*srdt) & PCI_VPD_SRDT_TIN_MASK) >> 3;
2060}
2061
e1d5bdab
MC
2062/**
2063 * pci_vpd_info_field_size - Extracts the information field length
2064 * @lrdt: Pointer to the beginning of an information field header
2065 *
2066 * Returns the extracted information field length.
2067 */
2068static inline u8 pci_vpd_info_field_size(const u8 *info_field)
2069{
2070 return info_field[2];
2071}
2072
b55ac1b2
MC
2073/**
2074 * pci_vpd_find_tag - Locates the Resource Data Type tag provided
2075 * @buf: Pointer to buffered vpd data
2076 * @off: The offset into the buffer at which to begin the search
2077 * @len: The length of the vpd buffer
2078 * @rdt: The Resource Data Type to search for
2079 *
2080 * Returns the index where the Resource Data Type was found or
2081 * -ENOENT otherwise.
2082 */
2083int pci_vpd_find_tag(const u8 *buf, unsigned int off, unsigned int len, u8 rdt);
2084
4067a854
MC
2085/**
2086 * pci_vpd_find_info_keyword - Locates an information field keyword in the VPD
2087 * @buf: Pointer to buffered vpd data
2088 * @off: The offset into the buffer at which to begin the search
2089 * @len: The length of the buffer area, relative to off, in which to search
2090 * @kw: The keyword to search for
2091 *
2092 * Returns the index where the information field keyword was found or
2093 * -ENOENT otherwise.
2094 */
2095int pci_vpd_find_info_keyword(const u8 *buf, unsigned int off,
2096 unsigned int len, const char *kw);
2097
98d9f30c
BH
2098/* PCI <-> OF binding helpers */
2099#ifdef CONFIG_OF
2100struct device_node;
b165e2b6 2101struct irq_domain;
f39d5b72
BH
2102void pci_set_of_node(struct pci_dev *dev);
2103void pci_release_of_node(struct pci_dev *dev);
2104void pci_set_bus_of_node(struct pci_bus *bus);
2105void pci_release_bus_of_node(struct pci_bus *bus);
b165e2b6 2106struct irq_domain *pci_host_bridge_of_msi_domain(struct pci_bus *bus);
98d9f30c
BH
2107
2108/* Arch may override this (weak) */
723ec4d0 2109struct device_node *pcibios_get_phb_of_node(struct pci_bus *bus);
98d9f30c 2110
3df425f3
JC
2111static inline struct device_node *
2112pci_device_to_OF_node(const struct pci_dev *pdev)
64099d98
BH
2113{
2114 return pdev ? pdev->dev.of_node : NULL;
2115}
2116
ef3b4f8c
BH
2117static inline struct device_node *pci_bus_to_OF_node(struct pci_bus *bus)
2118{
2119 return bus ? bus->dev.of_node : NULL;
2120}
2121
98d9f30c
BH
2122#else /* CONFIG_OF */
2123static inline void pci_set_of_node(struct pci_dev *dev) { }
2124static inline void pci_release_of_node(struct pci_dev *dev) { }
2125static inline void pci_set_bus_of_node(struct pci_bus *bus) { }
2126static inline void pci_release_bus_of_node(struct pci_bus *bus) { }
f0b66a2c
KH
2127static inline struct device_node *
2128pci_device_to_OF_node(const struct pci_dev *pdev) { return NULL; }
b165e2b6
MZ
2129static inline struct irq_domain *
2130pci_host_bridge_of_msi_domain(struct pci_bus *bus) { return NULL; }
98d9f30c
BH
2131#endif /* CONFIG_OF */
2132
471036b2
SS
2133#ifdef CONFIG_ACPI
2134struct irq_domain *pci_host_bridge_acpi_msi_domain(struct pci_bus *bus);
2135
2136void
2137pci_msi_register_fwnode_provider(struct fwnode_handle *(*fn)(struct device *));
2138#else
2139static inline struct irq_domain *
2140pci_host_bridge_acpi_msi_domain(struct pci_bus *bus) { return NULL; }
2141#endif
2142
eb740b5f
GS
2143#ifdef CONFIG_EEH
2144static inline struct eeh_dev *pci_dev_to_eeh_dev(struct pci_dev *pdev)
2145{
2146 return pdev->dev.archdata.edev;
2147}
2148#endif
2149
f0af9593 2150void pci_add_dma_alias(struct pci_dev *dev, u8 devfn);
338c3149 2151bool pci_devs_are_dma_aliases(struct pci_dev *dev1, struct pci_dev *dev2);
c25dc828
AW
2152int pci_for_each_dma_alias(struct pci_dev *pdev,
2153 int (*fn)(struct pci_dev *pdev,
2154 u16 alias, void *data), void *data);
2155
ce052984
EZ
2156/* helper functions for operation of device flag */
2157static inline void pci_set_dev_assigned(struct pci_dev *pdev)
2158{
2159 pdev->dev_flags |= PCI_DEV_FLAGS_ASSIGNED;
2160}
2161static inline void pci_clear_dev_assigned(struct pci_dev *pdev)
2162{
2163 pdev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
2164}
2165static inline bool pci_is_dev_assigned(struct pci_dev *pdev)
2166{
2167 return (pdev->dev_flags & PCI_DEV_FLAGS_ASSIGNED) == PCI_DEV_FLAGS_ASSIGNED;
2168}
19bdb6e4
AW
2169
2170/**
2171 * pci_ari_enabled - query ARI forwarding status
2172 * @bus: the PCI bus
2173 *
2174 * Returns true if ARI forwarding is enabled.
2175 */
2176static inline bool pci_ari_enabled(struct pci_bus *bus)
2177{
2178 return bus->self && bus->self->ari_enabled;
2179}
bc4b024a 2180
8531e283
LW
2181/**
2182 * pci_is_thunderbolt_attached - whether device is on a Thunderbolt daisy chain
2183 * @pdev: PCI device to check
2184 *
2185 * Walk upwards from @pdev and check for each encountered bridge if it's part
2186 * of a Thunderbolt controller. Reaching the host bridge means @pdev is not
2187 * Thunderbolt-attached. (But rather soldered to the mainboard usually.)
2188 */
2189static inline bool pci_is_thunderbolt_attached(struct pci_dev *pdev)
2190{
2191 struct pci_dev *parent = pdev;
2192
2193 if (pdev->is_thunderbolt)
2194 return true;
2195
2196 while ((parent = pci_upstream_bridge(parent)))
2197 if (parent->is_thunderbolt)
2198 return true;
2199
2200 return false;
2201}
2202
bc4b024a
CH
2203/* provide the legacy pci_dma_* API */
2204#include <linux/pci-dma-compat.h>
2205
1da177e4 2206#endif /* LINUX_PCI_H */