Blame view

include/linux/pci.h 80.5 KB
b24413180   Greg Kroah-Hartman   License cleanup: ...
1
  /* SPDX-License-Identifier: GPL-2.0 */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
  /*
   *	pci.h
   *
   *	PCI defines and function prototypes
   *	Copyright 1994, Drew Eckhardt
   *	Copyright 1997--1999 Martin Mares <mj@ucw.cz>
   *
   *	For more information, please consult the following manuals (look at
   *	http://www.pcisig.com/ for how to get them):
   *
   *	PCI BIOS Specification
   *	PCI Local Bus Specification
   *	PCI to PCI Bridge Specification
   *	PCI System Design Guide
   */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
17
18
  #ifndef LINUX_PCI_H
  #define LINUX_PCI_H
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
19

778382e08   David Woodhouse   Don't include <li...
20
  #include <linux/mod_devicetable.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
21
  #include <linux/types.h>
98db6f193   Sam Ravnborg   x86: fix section ...
22
  #include <linux/init.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
23
24
  #include <linux/ioport.h>
  #include <linux/list.h>
4a7fb6363   Andrew Morton   add __must_check ...
25
  #include <linux/compiler.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
26
  #include <linux/errno.h>
f46753c5e   Alex Chiang   PCI: introduce pc...
27
  #include <linux/kobject.h>
60063497a   Arun Sharma   atomic: use <linu...
28
  #include <linux/atomic.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
29
  #include <linux/device.h>
704e8953d   Christoph Hellwig   PCI/irq: Add pci_...
30
  #include <linux/interrupt.h>
1388cc964   Stephen Rothwell   PCI: don't export...
31
  #include <linux/io.h>
14d76b68f   Jiang Liu   PCI: Use common r...
32
  #include <linux/resource_ext.h>
607ca46e9   David Howells   UAPI: (Scripted) ...
33
  #include <uapi/linux/pci.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
34

7e7a43c32   Adrian Bunk   PCI: don't export...
35
  #include <linux/pci_ids.h>
85467136c   Shuah Khan   PCI: Add PCI_BUS_...
36
37
38
39
40
41
42
  /*
   * The PCI interface treats multi-function devices as independent
   * devices.  The slot/function address of each device is encoded
   * in a single byte as follows:
   *
   *	7:3 = slot
   *	2:0 = function
f7625980f   Bjorn Helgaas   PCI: Fix whitespa...
43
44
   *
   * PCI_DEVFN(), PCI_SLOT(), and PCI_FUNC() are defined in uapi/linux/pci.h.
85467136c   Shuah Khan   PCI: Add PCI_BUS_...
45
   * In the interest of not exposing interfaces to user-space unnecessarily,
f7625980f   Bjorn Helgaas   PCI: Fix whitespa...
46
   * the following kernel-only defines are being added here.
85467136c   Shuah Khan   PCI: Add PCI_BUS_...
47
   */
63ddc0b8f   Megan Kamiya   PCI: Parenthesize...
48
  #define PCI_DEVID(bus, devfn)  ((((u16)(bus)) << 8) | (devfn))
85467136c   Shuah Khan   PCI: Add PCI_BUS_...
49
50
  /* return bus from PCI devid = ((u16)bus_number) << 8) | devfn */
  #define PCI_BUS_NUM(x) (((x) >> 8) & 0xff)
f46753c5e   Alex Chiang   PCI: introduce pc...
51
52
53
54
55
56
57
58
  /* pci_slot represents a physical slot */
  struct pci_slot {
  	struct pci_bus *bus;		/* The bus this slot is on */
  	struct list_head list;		/* node in list of slots on this bus */
  	struct hotplug_slot *hotplug;	/* Hotplug info (migrate over time) */
  	unsigned char number;		/* PCI_SLOT(pci_dev->devfn) */
  	struct kobject kobj;
  };
0ad772ec4   Alex Chiang   PCI, PCI Hotplug:...
59
60
61
62
  static inline const char *pci_slot_name(const struct pci_slot *slot)
  {
  	return kobject_name(&slot->kobj);
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
63
64
65
66
67
  /* File state for mmap()s on /proc/bus/pci/X/Y */
  enum pci_mmap_state {
  	pci_mmap_io,
  	pci_mmap_mem
  };
fde09c6d8   Yu Zhao   PCI: define PCI r...
68
69
70
71
72
73
74
75
76
77
  /*
   *  For PCI devices, the region numbers are assigned this way:
   */
  enum {
  	/* #0-5: standard PCI resources */
  	PCI_STD_RESOURCES,
  	PCI_STD_RESOURCE_END = 5,
  
  	/* #6: expansion ROM resource */
  	PCI_ROM_RESOURCE,
d1b054da8   Yu Zhao   PCI: initialize a...
78
79
80
81
82
  	/* device specific resources */
  #ifdef CONFIG_PCI_IOV
  	PCI_IOV_RESOURCES,
  	PCI_IOV_RESOURCE_END = PCI_IOV_RESOURCES + PCI_SRIOV_NUM_BARS - 1,
  #endif
fde09c6d8   Yu Zhao   PCI: define PCI r...
83
84
85
86
87
88
89
90
91
92
93
  	/* resources assigned to buses behind the bridge */
  #define PCI_BRIDGE_RESOURCE_NUM 4
  
  	PCI_BRIDGE_RESOURCES,
  	PCI_BRIDGE_RESOURCE_END = PCI_BRIDGE_RESOURCES +
  				  PCI_BRIDGE_RESOURCE_NUM - 1,
  
  	/* total resources associated with a PCI device */
  	PCI_NUM_RESOURCES,
  
  	/* preserve this for compatibility */
cda57bf93   Yinghai Lu   PCI: DEVICE_COUNT...
94
  	DEVICE_COUNT_RESOURCE = PCI_NUM_RESOURCES,
fde09c6d8   Yu Zhao   PCI: define PCI r...
95
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
96

b352baf15   Paul Burton   PCI: Move enum pc...
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
  /**
   * enum pci_interrupt_pin - PCI INTx interrupt values
   * @PCI_INTERRUPT_UNKNOWN: Unknown or unassigned interrupt
   * @PCI_INTERRUPT_INTA: PCI INTA pin
   * @PCI_INTERRUPT_INTB: PCI INTB pin
   * @PCI_INTERRUPT_INTC: PCI INTC pin
   * @PCI_INTERRUPT_INTD: PCI INTD pin
   *
   * Corresponds to values for legacy PCI INTx interrupts, as can be found in the
   * PCI_INTERRUPT_PIN register.
   */
  enum pci_interrupt_pin {
  	PCI_INTERRUPT_UNKNOWN,
  	PCI_INTERRUPT_INTA,
  	PCI_INTERRUPT_INTB,
  	PCI_INTERRUPT_INTC,
  	PCI_INTERRUPT_INTD,
  };
  
  /* The number of legacy PCI INTx interrupts */
  #define PCI_NUM_INTX	4
224abb67e   Bjorn Helgaas   PCI: Document con...
118
119
120
121
  /*
   * pci_power_t values must match the bits in the Capabilities PME_Support
   * and Control/Status PowerState fields in the Power Management capability.
   */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
122
  typedef int __bitwise pci_power_t;
4352dfd5c   Greg Kroah-Hartman   [PATCH] PCI: clea...
123
124
125
  #define PCI_D0		((pci_power_t __force) 0)
  #define PCI_D1		((pci_power_t __force) 1)
  #define PCI_D2		((pci_power_t __force) 2)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
126
127
  #define PCI_D3hot	((pci_power_t __force) 3)
  #define PCI_D3cold	((pci_power_t __force) 4)
3fe9d19f9   Daniel Ritz   [PATCH] PCI: Supp...
128
  #define PCI_UNKNOWN	((pci_power_t __force) 5)
438510f6f   Pavel Machek   [PATCH] pm_messag...
129
  #define PCI_POWER_ERROR	((pci_power_t __force) -1)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
130

00240c383   Alan Stern   PCI: add power-st...
131
132
133
134
135
  /* Remember to update this when the list above changes! */
  extern const char *pci_power_names[];
  
  static inline const char *pci_power_name(pci_power_t state)
  {
9661e783d   Andy Shevchenko   PCI / PM: Enforce...
136
  	return pci_power_names[1 + (__force int) state];
00240c383   Alan Stern   PCI: add power-st...
137
  }
448bd857d   Huang Ying   PCI/PM: add PCIe ...
138
139
140
141
  #define PCI_PM_D2_DELAY		200
  #define PCI_PM_D3_WAIT		10
  #define PCI_PM_D3COLD_WAIT	100
  #define PCI_PM_BUS_WAIT		50
aa8c6c937   Rafael J. Wysocki   PCI PM: Restore s...
142

392a1ce76   Linas Vepstas   [PATCH] PCI Error...
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
  /** The pci_channel state describes connectivity between the CPU and
   *  the pci device.  If some PCI bus between here and the pci device
   *  has crashed or locked up, this info is reflected here.
   */
  typedef unsigned int __bitwise pci_channel_state_t;
  
  enum pci_channel_state {
  	/* I/O channel is in normal state */
  	pci_channel_io_normal = (__force pci_channel_state_t) 1,
  
  	/* I/O to channel is blocked */
  	pci_channel_io_frozen = (__force pci_channel_state_t) 2,
  
  	/* PCI card is dead */
  	pci_channel_io_perm_failure = (__force pci_channel_state_t) 3,
  };
f7bdd12d2   Brian King   pci: New PCI-E re...
159
160
161
162
163
  typedef unsigned int __bitwise pcie_reset_state_t;
  
  enum pcie_reset_state {
  	/* Reset is NOT asserted (Use to deassert reset) */
  	pcie_deassert_reset = (__force pcie_reset_state_t) 1,
f7625980f   Bjorn Helgaas   PCI: Fix whitespa...
164
  	/* Use #PERST to reset PCIe device */
f7bdd12d2   Brian King   pci: New PCI-E re...
165
  	pcie_warm_reset = (__force pcie_reset_state_t) 2,
f7625980f   Bjorn Helgaas   PCI: Fix whitespa...
166
  	/* Use PCIe Hot Reset to reset device */
f7bdd12d2   Brian King   pci: New PCI-E re...
167
168
  	pcie_hot_reset = (__force pcie_reset_state_t) 3
  };
ba698ad4b   David Miller   PCI: Add quirk fo...
169
170
171
172
173
  typedef unsigned short __bitwise pci_dev_flags_t;
  enum pci_dev_flags {
  	/* INTX_DISABLE in PCI_COMMAND register disables MSI
  	 * generation too.
  	 */
6b121592f   Alex Williamson   PCI: Convert pci_...
174
  	PCI_DEV_FLAGS_MSI_INTX_DISABLE_BUG = (__force pci_dev_flags_t) (1 << 0),
979b1791e   Alan Cox   PCI: add D3 power...
175
  	/* Device configuration is irrevocably lost if disabled into D3 */
6b121592f   Alex Williamson   PCI: Convert pci_...
176
  	PCI_DEV_FLAGS_NO_D3 = (__force pci_dev_flags_t) (1 << 1),
6777829cf   Greg Rose   pci: Add flag ind...
177
  	/* Provide indication device is assigned by a Virtual Machine Manager */
6b121592f   Alex Williamson   PCI: Convert pci_...
178
  	PCI_DEV_FLAGS_ASSIGNED = (__force pci_dev_flags_t) (1 << 2),
5757a769e   Alex Williamson   PCI: Add pci_dev_...
179
  	/* Flag for quirk use to store if quirk-specific ACS is enabled */
6b121592f   Alex Williamson   PCI: Convert pci_...
180
  	PCI_DEV_FLAGS_ACS_ENABLED_QUIRK = (__force pci_dev_flags_t) (1 << 3),
c8fe16e3f   Alex Williamson   PCI: Add support ...
181
182
  	/* Use a PCIe-to-PCI bridge alias even if !pci_is_pcie */
  	PCI_DEV_FLAG_PCIE_BRIDGE_ALIAS = (__force pci_dev_flags_t) (1 << 5),
f331a859e   Alex Williamson   PCI: Add flag for...
183
184
  	/* Do not use bus resets for device */
  	PCI_DEV_FLAGS_NO_BUS_RESET = (__force pci_dev_flags_t) (1 << 6),
51e537387   Alex Williamson   PCI: Add flag for...
185
186
  	/* Do not use PM reset even if device advertises NoSoftRst- */
  	PCI_DEV_FLAGS_NO_PM_RESET = (__force pci_dev_flags_t) (1 << 7),
932c435ca   Mark Rustad   PCI: Add dev_flag...
187
188
  	/* Get VPD from function 0 VPD */
  	PCI_DEV_FLAGS_VPD_REF_F0 = (__force pci_dev_flags_t) (1 << 8),
ffff88583   Jayachandran C   PCI: Add device f...
189
190
  	/* a non-root bridge where translation occurs, stop alias search here */
  	PCI_DEV_FLAGS_BRIDGE_XLATE_ROOT = (__force pci_dev_flags_t) (1 << 9),
f65fd1aa4   Sasha Neftin   PCI: Avoid FLR fo...
191
192
  	/* Do not use FLR even if device advertises PCI_AF_CAP */
  	PCI_DEV_FLAGS_NO_FLR_RESET = (__force pci_dev_flags_t) (1 << 10),
4d071c323   Imre Deak   PCI/PM: Add needs...
193
194
195
196
197
  	/*
  	 * Resume before calling the driver's system suspend hooks, disabling
  	 * the direct_complete optimization.
  	 */
  	PCI_DEV_FLAGS_NEEDS_RESUME = (__force pci_dev_flags_t) (1 << 11),
a99b646af   dingtianhong   PCI: Disable PCIe...
198
199
  	/* Don't use Relaxed Ordering for TLPs directed at this device */
  	PCI_DEV_FLAGS_NO_RELAXED_ORDERING = (__force pci_dev_flags_t) (1 << 12),
ba698ad4b   David Miller   PCI: Add quirk fo...
200
  };
e1d3a9084   Stefan Assmann   pci, acpi: rerout...
201
202
203
204
  enum pci_irq_reroute_variant {
  	INTEL_IRQ_REROUTE_VARIANT = 1,
  	MAX_IRQ_REROUTE_VARIANTS = 3
  };
6e325a62a   Michael S. Tsirkin   [PATCH] PCI: make...
205
206
  typedef unsigned short __bitwise pci_bus_flags_t;
  enum pci_bus_flags {
032c3d86b   Jon Derrick   PCI/AER: Add bus ...
207
208
209
  	PCI_BUS_FLAGS_NO_MSI	= (__force pci_bus_flags_t) 1,
  	PCI_BUS_FLAGS_NO_MMRBC	= (__force pci_bus_flags_t) 2,
  	PCI_BUS_FLAGS_NO_AERSID	= (__force pci_bus_flags_t) 4,
6e325a62a   Michael S. Tsirkin   [PATCH] PCI: make...
210
  };
59da381ee   Jacob Keller   PCI: move enum pc...
211
212
213
214
215
216
217
218
219
220
221
222
  /* These values come from the PCI Express Spec */
  enum pcie_link_width {
  	PCIE_LNK_WIDTH_RESRV	= 0x00,
  	PCIE_LNK_X1		= 0x01,
  	PCIE_LNK_X2		= 0x02,
  	PCIE_LNK_X4		= 0x04,
  	PCIE_LNK_X8		= 0x08,
  	PCIE_LNK_X12		= 0x0C,
  	PCIE_LNK_X16		= 0x10,
  	PCIE_LNK_X32		= 0x20,
  	PCIE_LNK_WIDTH_UNKNOWN  = 0xFF,
  };
536c8cb49   Matthew Wilcox   PCI: Unify pcie_l...
223
224
225
226
227
228
229
230
231
232
233
234
235
  /* Based on the PCI Hotplug Spec, but some values are made up by us */
  enum pci_bus_speed {
  	PCI_SPEED_33MHz			= 0x00,
  	PCI_SPEED_66MHz			= 0x01,
  	PCI_SPEED_66MHz_PCIX		= 0x02,
  	PCI_SPEED_100MHz_PCIX		= 0x03,
  	PCI_SPEED_133MHz_PCIX		= 0x04,
  	PCI_SPEED_66MHz_PCIX_ECC	= 0x05,
  	PCI_SPEED_100MHz_PCIX_ECC	= 0x06,
  	PCI_SPEED_133MHz_PCIX_ECC	= 0x07,
  	PCI_SPEED_66MHz_PCIX_266	= 0x09,
  	PCI_SPEED_100MHz_PCIX_266	= 0x0a,
  	PCI_SPEED_133MHz_PCIX_266	= 0x0b,
45b4cdd57   Matthew Wilcox   PCI: Add support ...
236
237
238
239
240
  	AGP_UNKNOWN			= 0x0c,
  	AGP_1X				= 0x0d,
  	AGP_2X				= 0x0e,
  	AGP_4X				= 0x0f,
  	AGP_8X				= 0x10,
536c8cb49   Matthew Wilcox   PCI: Unify pcie_l...
241
242
243
244
245
  	PCI_SPEED_66MHz_PCIX_533	= 0x11,
  	PCI_SPEED_100MHz_PCIX_533	= 0x12,
  	PCI_SPEED_133MHz_PCIX_533	= 0x13,
  	PCIE_SPEED_2_5GT		= 0x14,
  	PCIE_SPEED_5_0GT		= 0x15,
9dfd97fe1   Matthew Wilcox   PCI: Add support ...
246
  	PCIE_SPEED_8_0GT		= 0x16,
536c8cb49   Matthew Wilcox   PCI: Unify pcie_l...
247
248
  	PCI_SPEED_UNKNOWN		= 0xff,
  };
24a4742f0   Alex Williamson   PCI: Track the si...
249
  struct pci_cap_saved_data {
fd0f7f73c   Alex Williamson   PCI: Add support ...
250
251
  	u16 cap_nr;
  	bool cap_extended;
24a4742f0   Alex Williamson   PCI: Track the si...
252
  	unsigned int size;
41017f0ca   Shaohua Li   [PATCH] PCI: MSI(...
253
254
  	u32 data[0];
  };
24a4742f0   Alex Williamson   PCI: Track the si...
255
256
257
258
  struct pci_cap_saved_state {
  	struct hlist_node next;
  	struct pci_cap_saved_data cap;
  };
402723ad5   Christoph Hellwig   PCI/MSI: Provide ...
259
  struct irq_affinity;
7d715a6c1   Shaohua Li   PCI: add PCI Expr...
260
  struct pcie_link_state;
ee69439cc   Jesse Barnes   PCI: don't expose...
261
  struct pci_vpd;
d1b054da8   Yu Zhao   PCI: initialize a...
262
  struct pci_sriov;
302b4215d   Yu Zhao   PCI: support the ...
263
  struct pci_ats;
ee69439cc   Jesse Barnes   PCI: don't expose...
264

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
265
266
267
268
  /*
   * The pci_dev structure is used to describe PCI devices.
   */
  struct pci_dev {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
269
270
271
272
273
274
  	struct list_head bus_list;	/* node in per-bus list */
  	struct pci_bus	*bus;		/* bus this device is on */
  	struct pci_bus	*subordinate;	/* bus this device bridges to */
  
  	void		*sysdata;	/* hook for sys-specific extension */
  	struct proc_dir_entry *procent;	/* device entry in /proc/bus/pci */
f46753c5e   Alex Chiang   PCI: introduce pc...
275
  	struct pci_slot	*slot;		/* Physical slot this device is in */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
276
277
278
279
280
281
282
  
  	unsigned int	devfn;		/* encoded device & function index */
  	unsigned short	vendor;
  	unsigned short	device;
  	unsigned short	subsystem_vendor;
  	unsigned short	subsystem_device;
  	unsigned int	class;		/* 3 bytes: (base,sub,prog-if) */
b8a3a5214   Auke Kok   PCI: read revisio...
283
  	u8		revision;	/* PCI revision, low byte of class word */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
284
  	u8		hdr_type;	/* PCI header type (`multi' flag masked out) */
66b808099   Keith Busch   PCI/AER: Cache ca...
285
286
287
  #ifdef CONFIG_PCIEAER
  	u16		aer_cap;	/* AER capability offset */
  #endif
f7625980f   Bjorn Helgaas   PCI: Fix whitespa...
288
  	u8		pcie_cap;	/* PCIe capability offset */
e375b5618   Gavin Shan   PCI: Cache MSI/MS...
289
290
  	u8		msi_cap;	/* MSI capability offset */
  	u8		msix_cap;	/* MSI-X capability offset */
f7625980f   Bjorn Helgaas   PCI: Fix whitespa...
291
  	u8		pcie_mpss:3;	/* PCIe Max Payload Size Supported */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
292
  	u8		rom_base_reg;	/* which config register controls the ROM */
f7625980f   Bjorn Helgaas   PCI: Fix whitespa...
293
294
  	u8		pin;		/* which interrupt pin this device uses */
  	u16		pcie_flags_reg;	/* cached PCIe Capabilities Register */
338c3149a   Jacek Lawrynowicz   PCI: Add support ...
295
  	unsigned long	*dma_alias_mask;/* mask of enabled devfn aliases */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
296
297
298
299
300
301
302
  
  	struct pci_driver *driver;	/* which driver has allocated this device */
  	u64		dma_mask;	/* Mask of the bits of bus address this
  					   device implements.  Normally this is
  					   0xffffffff.  You only need to change
  					   this if your device has broken DMA
  					   or supports 64-bit transfers.  */
4d57cdfac   FUJITA Tomonori   iommu sg merging:...
303
  	struct device_dma_parameters dma_parms;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
304
305
306
  	pci_power_t     current_state;  /* Current operating state. In ACPI-speak,
  					   this is D0-D3, D0 being fully functional,
  					   and D3 being off. */
703860ed4   Bjorn Helgaas   PCI: Use u8, not ...
307
  	u8		pm_cap;		/* PM capability offset */
337001b6c   Rafael J. Wysocki   PCI: Simplify PCI...
308
309
  	unsigned int	pme_support:5;	/* Bitmask of states from which PME#
  					   can be generated */
379021d5c   Rafael J. Wysocki   PCI / PM: Extend ...
310
  	unsigned int	pme_poll:1;	/* Poll device's PME status bit */
337001b6c   Rafael J. Wysocki   PCI: Simplify PCI...
311
312
  	unsigned int	d1_support:1;	/* Low power state D1 is supported */
  	unsigned int	d2_support:1;	/* Low power state D2 is supported */
448bd857d   Huang Ying   PCI/PM: add PCIe ...
313
314
  	unsigned int	no_d1d2:1;	/* D1 and D2 are forbidden */
  	unsigned int	no_d3cold:1;	/* D3cold is forbidden */
9d26d3a8f   Mika Westerberg   PCI: Put PCIe por...
315
  	unsigned int	bridge_d3:1;	/* Allow D3 for bridge */
448bd857d   Huang Ying   PCI/PM: add PCIe ...
316
  	unsigned int	d3cold_allowed:1;	/* D3cold is allowed by user */
253d2e549   Jacob Pan   PCI: disable mmio...
317
318
  	unsigned int	mmio_always_on:1;	/* disallow turning off io/mem
  						   decoding during bar sizing */
e80bb09d2   Rafael J. Wysocki   PCI PM: Introduce...
319
  	unsigned int	wakeup_prepared:1;
448bd857d   Huang Ying   PCI/PM: add PCIe ...
320
321
322
323
  	unsigned int	runtime_d3cold:1;	/* whether go through runtime
  						   D3cold, not set for devices
  						   powered on/off by the
  						   corresponding bridge */
b440bde74   Bjorn Helgaas   PCI: Add pci_igno...
324
  	unsigned int	ignore_hotplug:1;	/* Ignore hotplug events */
576243b3f   Keith Busch   PCI: pciehp: Allo...
325
326
327
  	unsigned int	hotplug_user_indicators:1; /* SlotCtl indicators
  						      controlled exclusively by
  						      user sysfs */
1ae861e65   Rafael J. Wysocki   PCI/PM: Use per-d...
328
  	unsigned int	d3_delay;	/* D3->D0 transition time in ms */
448bd857d   Huang Ying   PCI/PM: add PCIe ...
329
  	unsigned int	d3cold_delay;	/* D3cold->D0 transition time in ms */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
330

7d715a6c1   Shaohua Li   PCI: add PCI Expr...
331
  #ifdef CONFIG_PCIEASPM
f7625980f   Bjorn Helgaas   PCI: Fix whitespa...
332
  	struct pcie_link_state	*link_state;	/* ASPM link state */
7d715a6c1   Shaohua Li   PCI: add PCI Expr...
333
  #endif
392a1ce76   Linas Vepstas   [PATCH] PCI Error...
334
  	pci_channel_state_t error_state;	/* current connectivity state */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
335
  	struct	device	dev;		/* Generic device interface */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
336
337
338
339
340
341
342
343
  	int		cfg_size;	/* Size of configuration space */
  
  	/*
  	 * Instead of touching interrupt line and base address registers
  	 * directly, use the values stored here. They might be different!
  	 */
  	unsigned int	irq;
  	struct resource resource[DEVICE_COUNT_RESOURCE]; /* I/O and memory regions + expansion ROMs */
58d9a38f6   Yinghai Lu   PCI: Skip attachi...
344
  	bool match_driver;		/* Skip attaching driver */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
345
  	/* These fields are used by common fixups */
f7625980f   Bjorn Helgaas   PCI: Fix whitespa...
346
  	unsigned int	transparent:1;	/* Subtractive decode PCI bridge */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
347
348
  	unsigned int	multifunction:1;/* Part of multi-function device */
  	/* keep track of device state */
8a1bc9013   Greg Kroah-Hartman   PCI: add is_added...
349
  	unsigned int	is_added:1;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
350
  	unsigned int	is_busmaster:1; /* device is busmaster */
4602b88d9   Kristen Accardi   [PATCH] PCI: 6700...
351
  	unsigned int	no_msi:1;	/* device may not use msi */
f144d1496   Benjamin Herrenschmidt   PCI/MSI: Add devi...
352
  	unsigned int	no_64bit_msi:1; /* device may only use 32-bit MSIs */
fb51ccbf2   Jan Kiszka   PCI: Rework confi...
353
  	unsigned int	block_cfg_access:1;	/* config space access is blocked */
bd8481e16   Doug Thompson   [PATCH] PCI Bus P...
354
  	unsigned int	broken_parity_status:1;	/* Device generates false positive parity */
e1d3a9084   Stefan Assmann   pci, acpi: rerout...
355
  	unsigned int	irq_reroute_variant:2;	/* device needs IRQ rerouting variant */
f7625980f   Bjorn Helgaas   PCI: Fix whitespa...
356
  	unsigned int	msi_enabled:1;
99dc804d9   Shaohua Li   [PATCH] PCI: disa...
357
  	unsigned int	msix_enabled:1;
58c3a727c   Yu Zhao   PCI: support PCIe...
358
  	unsigned int	ari_enabled:1;	/* ARI forwarding */
d544d75ac   Bjorn Helgaas   PCI: Embed ATS in...
359
  	unsigned int	ats_enabled:1;	/* Address Translation Service */
a4f4fa681   Jean-Philippe Brucker   PCI: Cache PRI an...
360
361
  	unsigned int	pasid_enabled:1;	/* Process Address Space ID */
  	unsigned int	pri_enabled:1;		/* Page Request Interface */
9ac7849e3   Tejun Heo   devres: device re...
362
  	unsigned int	is_managed:1;
260d703ad   Mike Mason   PCI: support for ...
363
  	unsigned int    needs_freset:1; /* Dev requires fundamental reset */
aa8c6c937   Rafael J. Wysocki   PCI PM: Restore s...
364
  	unsigned int	state_saved:1;
d1b054da8   Yu Zhao   PCI: initialize a...
365
  	unsigned int	is_physfn:1;
dd7cc44d0   Yu Zhao   PCI: add SR-IOV A...
366
  	unsigned int	is_virtfn:1;
711d57796   Michael S. Tsirkin   PCI: expose funct...
367
  	unsigned int	reset_fn:1;
28760489a   Eric W. Biederman   PCI: pcie: Ensure...
368
  	unsigned int    is_hotplug_bridge:1;
8531e283b   Lukas Wunner   PCI: Recognize Th...
369
  	unsigned int	is_thunderbolt:1; /* Thunderbolt controller */
affb72c3a   Huang Ying   ACPI, APEI, PCIE ...
370
371
  	unsigned int    __aer_firmware_first_valid:1;
  	unsigned int	__aer_firmware_first:1;
99b3c58f7   Piotr Gregor   PCI: Test INTx ma...
372
  	unsigned int	broken_intx_masking:1; /* INTx masking can't be used */
2b28ae191   Bjorn Helgaas   PCI: reimplement ...
373
  	unsigned int	io_window_1k:1;	/* Intel P2P bridge 1K I/O windows */
cffe0a2b5   Jiang Liu   x86, irq: Keep ba...
374
  	unsigned int	irq_managed:1;
d0751b98d   Yijing Wang   PCI: Add dev->has...
375
  	unsigned int	has_secondary_link:1;
b84106b4e   Bjorn Helgaas   PCI: Disable IO/M...
376
  	unsigned int	non_compliant_bars:1;	/* broken BARs; ignore them */
0b2c2a71e   Thomas Gleixner   PCI: Replace the ...
377
  	unsigned int	is_probed:1;		/* device probing in progress */
ba698ad4b   David Miller   PCI: Add quirk fo...
378
  	pci_dev_flags_t dev_flags;
bae94d023   Inaky Perez-Gonzalez   PCI: switch pci_{...
379
  	atomic_t	enable_cnt;	/* pci_enable_device has been called */
4602b88d9   Kristen Accardi   [PATCH] PCI: 6700...
380

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
381
  	u32		saved_config_space[16]; /* config space saved at suspend time */
41017f0ca   Shaohua Li   [PATCH] PCI: MSI(...
382
  	struct hlist_head saved_cap_space;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
383
384
385
  	struct bin_attribute *rom_attr; /* attribute descriptor for sysfs ROM entry */
  	int rom_attr_enabled;		/* has display of the rom attribute been enabled? */
  	struct bin_attribute *res_attr[DEVICE_COUNT_RESOURCE]; /* sysfs file for resources */
45aec1ae7   venkatesh.pallipadi@intel.com   x86: PAT export r...
386
  	struct bin_attribute *res_attr_wc[DEVICE_COUNT_RESOURCE]; /* sysfs file for WC mapping of resources */
9bb04a0c4   Jonathan Yong   PCI: Add Precisio...
387
388
389
390
  
  #ifdef CONFIG_PCIE_PTM
  	unsigned int	ptm_root:1;
  	unsigned int	ptm_enabled:1;
8b2ec318e   Bjorn Helgaas   PCI: Add PTM cloc...
391
  	u8		ptm_granularity;
9bb04a0c4   Jonathan Yong   PCI: Add Precisio...
392
  #endif
ded86d8d3   Eric W. Biederman   msi: Kill msi_loo...
393
  #ifdef CONFIG_PCI_MSI
1c51b50c2   Greg Kroah-Hartman   PCI/MSI: Export M...
394
  	const struct attribute_group **msi_irq_groups;
ded86d8d3   Eric W. Biederman   msi: Kill msi_loo...
395
  #endif
94e610880   Ben Hutchings   PCI: Expose PCI V...
396
  	struct pci_vpd *vpd;
466b3ddfb   Joerg Roedel   PCI: Fix compile ...
397
  #ifdef CONFIG_PCI_ATS
dd7cc44d0   Yu Zhao   PCI: add SR-IOV A...
398
399
400
401
  	union {
  		struct pci_sriov *sriov;	/* SR-IOV capability related */
  		struct pci_dev *physfn;	/* the PF this VF is associated with */
  	};
67930995d   Bjorn Helgaas   PCI: Reduce size ...
402
403
  	u16		ats_cap;	/* ATS Capability offset */
  	u8		ats_stu;	/* ATS Smallest Translation Unit */
d544d75ac   Bjorn Helgaas   PCI: Embed ATS in...
404
  	atomic_t	ats_ref_cnt;	/* number of VFs with ATS enabled */
d1b054da8   Yu Zhao   PCI: initialize a...
405
  #endif
4ebeb1ec5   CQ Tang   PCI: Restore PRI ...
406
407
408
409
410
411
  #ifdef CONFIG_PCI_PRI
  	u32		pri_reqs_alloc; /* Number of PRI requests allocated */
  #endif
  #ifdef CONFIG_PCI_PASID
  	u16		pasid_features;
  #endif
dbd3fc334   Bjorn Helgaas   PCI: Use phys_add...
412
  	phys_addr_t rom; /* Physical address of ROM if it's not from the BAR */
84c1b80e3   Matthew Garrett   PCI: Add support ...
413
  	size_t romlen; /* Length of ROM if it's not from the BAR */
782a985d7   Alex Williamson   PCI: Introduce ne...
414
  	char *driver_override; /* Driver name to force a match */
89ee9f768   Keith Busch   PCI: Add device d...
415
416
  
  	unsigned long priv_flags; /* Private flags for the pci driver */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
417
  };
dda565492   Yinghai   intel-iommu: use ...
418
419
420
421
422
423
  static inline struct pci_dev *pci_physfn(struct pci_dev *dev)
  {
  #ifdef CONFIG_PCI_IOV
  	if (dev->is_virtfn)
  		dev = dev->physfn;
  #endif
dda565492   Yinghai   intel-iommu: use ...
424
425
  	return dev;
  }
3c6e6ae77   Gu Zheng   PCI: Introduce pc...
426
  struct pci_dev *pci_alloc_dev(struct pci_bus *bus);
65891215e   Michael Ellerman   PCI: Create alloc...
427

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
428
429
  #define	to_pci_dev(n) container_of(n, struct pci_dev, dev)
  #define for_each_pci_dev(d) while ((d = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, d)) != NULL)
a7369f1f6   Linas Vepstas   PCI: define inlin...
430
431
432
433
  static inline int pci_channel_offline(struct pci_dev *pdev)
  {
  	return (pdev->error_state != pci_channel_io_normal);
  }
5a21d70db   Bjorn Helgaas   PCI: add struct p...
434
  struct pci_host_bridge {
7b5436635   Yinghai Lu   PCI: add generic ...
435
  	struct device dev;
5a21d70db   Bjorn Helgaas   PCI: add struct p...
436
  	struct pci_bus *bus;		/* root bus */
37d6a0a6f   Arnd Bergmann   PCI: Add pci_regi...
437
438
439
  	struct pci_ops *ops;
  	void *sysdata;
  	int busnr;
14d76b68f   Jiang Liu   PCI: Use common r...
440
  	struct list_head windows;	/* resource_entry */
3aa8a41e0   Matthew Minter   PCI: Add IRQ mapp...
441
442
  	u8 (*swizzle_irq)(struct pci_dev *, u8 *); /* platform IRQ swizzler */
  	int (*map_irq)(const struct pci_dev *, u8, u8);
4fa2649a0   Yinghai Lu   PCI: add host bri...
443
444
  	void (*release_fn)(struct pci_host_bridge *);
  	void *release_data;
37d6a0a6f   Arnd Bergmann   PCI: Add pci_regi...
445
  	struct msi_controller *msi;
e33caa82e   Aaron Lu   PCI/ACPI: Optimiz...
446
  	unsigned int ignore_reset_delay:1;	/* for entire hierarchy */
62ce94a7a   Sinan Kaya   PCI: Mark Broadco...
447
  	unsigned int no_ext_tags:1;		/* no Extended Tags */
7c7a0e945   Gabriele Paoloni   ARM/PCI: Move ali...
448
449
450
451
452
453
  	/* Resource alignment requirements */
  	resource_size_t (*align_resource)(struct pci_dev *dev,
  			const struct resource *res,
  			resource_size_t start,
  			resource_size_t size,
  			resource_size_t align);
590940659   Thierry Reding   PCI: Allow driver...
454
  	unsigned long private[0] ____cacheline_aligned;
5a21d70db   Bjorn Helgaas   PCI: add struct p...
455
  };
41017f0ca   Shaohua Li   [PATCH] PCI: MSI(...
456

7b5436635   Yinghai Lu   PCI: add generic ...
457
  #define	to_pci_host_bridge(n) container_of(n, struct pci_host_bridge, dev)
7c7a0e945   Gabriele Paoloni   ARM/PCI: Move ali...
458

590940659   Thierry Reding   PCI: Allow driver...
459
460
461
462
463
464
465
466
467
  static inline void *pci_host_bridge_priv(struct pci_host_bridge *bridge)
  {
  	return (void *)bridge->private;
  }
  
  static inline struct pci_host_bridge *pci_host_bridge_from_priv(void *priv)
  {
  	return container_of(priv, struct pci_host_bridge, private);
  }
a52d1443b   Thierry Reding   PCI: Export host ...
468
  struct pci_host_bridge *pci_alloc_host_bridge(size_t priv);
5c3f18cce   Lorenzo Pieralisi   PCI: Add devm_pci...
469
470
  struct pci_host_bridge *devm_pci_alloc_host_bridge(struct device *dev,
  						   size_t priv);
dff79b91b   Lorenzo Pieralisi   PCI: Add pci_free...
471
  void pci_free_host_bridge(struct pci_host_bridge *bridge);
7c7a0e945   Gabriele Paoloni   ARM/PCI: Move ali...
472
  struct pci_host_bridge *pci_find_host_bridge(struct pci_bus *bus);
4fa2649a0   Yinghai Lu   PCI: add host bri...
473
474
475
  void pci_set_host_bridge_release(struct pci_host_bridge *bridge,
  		     void (*release_fn)(struct pci_host_bridge *),
  		     void *release_data);
7b5436635   Yinghai Lu   PCI: add generic ...
476

6c0cc950a   Rafael J. Wysocki   ACPI / PCI: Set r...
477
  int pcibios_root_bridge_prepare(struct pci_host_bridge *bridge);
2fe2abf89   Bjorn Helgaas   PCI: augment bus ...
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
  /*
   * The first PCI_BRIDGE_RESOURCE_NUM PCI bus resources (those that correspond
   * to P2P or CardBus bridge windows) go in a table.  Additional ones (for
   * buses below host bridges or subtractive decode bridges) go in the list.
   * Use pci_bus_for_each_resource() to iterate through all the resources.
   */
  
  /*
   * PCI_SUBTRACTIVE_DECODE means the bridge forwards the window implicitly
   * and there's no way to program the bridge with the details of the window.
   * This does not apply to ACPI _CRS windows, even with the _DEC subtractive-
   * decode bit set, because they are explicit and can be programmed with _SRS.
   */
  #define PCI_SUBTRACTIVE_DECODE	0x1
  
  struct pci_bus_resource {
  	struct list_head list;
  	struct resource *res;
  	unsigned int flags;
  };
4352dfd5c   Greg Kroah-Hartman   [PATCH] PCI: clea...
498
499
  
  #define PCI_REGION_FLAG_MASK	0x0fU	/* These bits of resource flags tell us the PCI region flags */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
500
501
502
503
504
505
506
  
  struct pci_bus {
  	struct list_head node;		/* node in list of buses */
  	struct pci_bus	*parent;	/* parent bus this bridge is on */
  	struct list_head children;	/* list of child buses */
  	struct list_head devices;	/* list of devices on this bus */
  	struct pci_dev	*self;		/* bridge device as seen by parent */
675467629   Yijing Wang   PCI: Protect pci_...
507
508
  	struct list_head slots;		/* list of slots on this bus;
  					   protected by pci_slot_mutex */
2fe2abf89   Bjorn Helgaas   PCI: augment bus ...
509
510
  	struct resource *resource[PCI_BRIDGE_RESOURCE_NUM];
  	struct list_head resources;	/* address space routed to this bus */
92f024309   Yinghai Lu   PCI: add busn_res...
511
  	struct resource busn_res;	/* bus numbers routed to this bus */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
512
513
  
  	struct pci_ops	*ops;		/* configuration access functions */
c2791b806   Yijing Wang   PCI/MSI: Rename "...
514
  	struct msi_controller *msi;	/* MSI controller */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
515
516
517
518
519
  	void		*sysdata;	/* hook for sys-specific extension */
  	struct proc_dir_entry *procdir;	/* directory entry in /proc/bus/pci */
  
  	unsigned char	number;		/* bus number */
  	unsigned char	primary;	/* number of primary bridge */
3749c51ac   Matthew Wilcox   PCI: Make current...
520
521
  	unsigned char	max_bus_speed;	/* enum pci_bus_speed */
  	unsigned char	cur_bus_speed;	/* enum pci_bus_speed */
670ba0c88   Catalin Marinas   PCI: Add generic ...
522
523
524
  #ifdef CONFIG_PCI_DOMAINS_GENERIC
  	int		domain_nr;
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
525
526
527
528
  
  	char		name[48];
  
  	unsigned short  bridge_ctl;	/* manage NO_ISA/FBB/et al behaviors */
f7625980f   Bjorn Helgaas   PCI: Fix whitespa...
529
  	pci_bus_flags_t bus_flags;	/* inherited by child buses */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
530
  	struct device		*bridge;
fd7d1ced2   Greg Kroah-Hartman   PCI: make pci_bus...
531
  	struct device		dev;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
532
533
  	struct bin_attribute	*legacy_io; /* legacy I/O for this bus */
  	struct bin_attribute	*legacy_mem; /* legacy mem */
cc74d96f4   Greg Kroah-Hartman   PCI: fix issue wi...
534
  	unsigned int		is_added:1;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
535
  };
fd7d1ced2   Greg Kroah-Hartman   PCI: make pci_bus...
536
  #define to_pci_bus(n)	container_of(n, struct pci_bus, dev)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
537

79af72d71   Kenji Kaneshige   PCI: pci_is_root_...
538
  /*
f7625980f   Bjorn Helgaas   PCI: Fix whitespa...
539
   * Returns true if the PCI bus is root (behind host-PCI bridge),
79af72d71   Kenji Kaneshige   PCI: pci_is_root_...
540
   * false otherwise
77a0dfcd8   Bjorn Helgaas   PCI: Document rea...
541
542
543
544
   *
   * Some code assumes that "bus->self == NULL" means that bus is a root bus.
   * This is incorrect because "virtual" buses added for SR-IOV (via
   * virtfn_add_bus()) have "bus->self == NULL" but are not root buses.
79af72d71   Kenji Kaneshige   PCI: pci_is_root_...
545
546
547
548
549
   */
  static inline bool pci_is_root_bus(struct pci_bus *pbus)
  {
  	return !(pbus->parent);
  }
1c86438c9   Yijing Wang   PCI: Add new pci_...
550
551
552
553
554
555
556
557
558
559
560
561
  /**
   * pci_is_bridge - check if the PCI device is a bridge
   * @dev: PCI device
   *
   * Return true if the PCI device is bridge whether it has subordinate
   * or not.
   */
  static inline bool pci_is_bridge(struct pci_dev *dev)
  {
  	return dev->hdr_type == PCI_HEADER_TYPE_BRIDGE ||
  		dev->hdr_type == PCI_HEADER_TYPE_CARDBUS;
  }
c6bde215a   Bjorn Helgaas   PCI: Add pci_upst...
562
563
564
565
566
567
568
569
  static inline struct pci_dev *pci_upstream_bridge(struct pci_dev *dev)
  {
  	dev = pci_physfn(dev);
  	if (pci_is_root_bus(dev->bus))
  		return NULL;
  
  	return dev->bus->self;
  }
6675a601d   Murali Karicheri   PCI: Add helper f...
570
571
  struct device *pci_get_host_bridge_device(struct pci_dev *dev);
  void pci_put_host_bridge_device(struct device *dev);
16cf0ebc3   Rafael J. Wysocki   x86/PCI: Do not u...
572
573
574
575
576
577
578
579
  #ifdef CONFIG_PCI_MSI
  static inline bool pci_dev_msi_enabled(struct pci_dev *pci_dev)
  {
  	return pci_dev->msi_enabled || pci_dev->msix_enabled;
  }
  #else
  static inline bool pci_dev_msi_enabled(struct pci_dev *pci_dev) { return false; }
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
580
581
582
583
584
585
586
587
588
589
  /*
   * Error values that may be returned by PCI functions.
   */
  #define PCIBIOS_SUCCESSFUL		0x00
  #define PCIBIOS_FUNC_NOT_SUPPORTED	0x81
  #define PCIBIOS_BAD_VENDOR_ID		0x83
  #define PCIBIOS_DEVICE_NOT_FOUND	0x86
  #define PCIBIOS_BAD_REGISTER_NUMBER	0x87
  #define PCIBIOS_SET_FAILED		0x88
  #define PCIBIOS_BUFFER_TOO_SMALL	0x89
a69616514   Alex Williamson   PCI: create commo...
590
  /*
f7625980f   Bjorn Helgaas   PCI: Fix whitespa...
591
   * Translate above to generic errno for passing back through non-PCI code.
a69616514   Alex Williamson   PCI: create commo...
592
593
594
595
596
597
598
599
600
601
   */
  static inline int pcibios_err_to_errno(int err)
  {
  	if (err <= PCIBIOS_SUCCESSFUL)
  		return err; /* Assume already errno */
  
  	switch (err) {
  	case PCIBIOS_FUNC_NOT_SUPPORTED:
  		return -ENOENT;
  	case PCIBIOS_BAD_VENDOR_ID:
d97ffe236   Gavin Shan   PCI: Fix return v...
602
  		return -ENOTTY;
a69616514   Alex Williamson   PCI: create commo...
603
604
605
606
607
608
609
610
611
  	case PCIBIOS_DEVICE_NOT_FOUND:
  		return -ENODEV;
  	case PCIBIOS_BAD_REGISTER_NUMBER:
  		return -EFAULT;
  	case PCIBIOS_SET_FAILED:
  		return -EIO;
  	case PCIBIOS_BUFFER_TOO_SMALL:
  		return -ENOSPC;
  	}
d97ffe236   Gavin Shan   PCI: Fix return v...
612
  	return -ERANGE;
a69616514   Alex Williamson   PCI: create commo...
613
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
614
615
616
  /* Low-level architecture-dependent routines */
  
  struct pci_ops {
057bd2e05   Thierry Reding   PCI: Add pci_ops....
617
618
  	int (*add_bus)(struct pci_bus *bus);
  	void (*remove_bus)(struct pci_bus *bus);
1f94a94f6   Rob Herring   PCI: Add generic ...
619
  	void __iomem *(*map_bus)(struct pci_bus *bus, unsigned int devfn, int where);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
620
621
622
  	int (*read)(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 *val);
  	int (*write)(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 val);
  };
b6ce068a1   Matthew Wilcox   Change pci_raw_op...
623
624
625
626
  /*
   * ACPI needs to be able to access PCI config space before we've done a
   * PCI bus scan and created pci_bus structures.
   */
f39d5b729   Bjorn Helgaas   PCI: Remove "exte...
627
628
629
630
  int raw_pci_read(unsigned int domain, unsigned int bus, unsigned int devfn,
  		 int reg, int len, u32 *val);
  int raw_pci_write(unsigned int domain, unsigned int bus, unsigned int devfn,
  		  int reg, int len, u32 val);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
631

3a9ad0b4f   Yinghai Lu   PCI: Add pci_bus_...
632
633
634
635
636
  #ifdef CONFIG_PCI_BUS_ADDR_T_64BIT
  typedef u64 pci_bus_addr_t;
  #else
  typedef u32 pci_bus_addr_t;
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
637
  struct pci_bus_region {
3a9ad0b4f   Yinghai Lu   PCI: Add pci_bus_...
638
639
  	pci_bus_addr_t start;
  	pci_bus_addr_t end;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
640
641
642
643
644
  };
  
  struct pci_dynids {
  	spinlock_t lock;            /* protects list, index */
  	struct list_head list;      /* for IDs added at runtime */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
645
  };
f7625980f   Bjorn Helgaas   PCI: Fix whitespa...
646
647
648
649
650
651
  
  /*
   * PCI Error Recovery System (PCI-ERS).  If a PCI device driver provides
   * a set of callbacks in struct pci_error_handlers, that device driver
   * will be notified of PCI bus errors, and will be driven to recovery
   * when an error occurs.
392a1ce76   Linas Vepstas   [PATCH] PCI Error...
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
   */
  
  typedef unsigned int __bitwise pci_ers_result_t;
  
  enum pci_ers_result {
  	/* no result/none/not supported in device driver */
  	PCI_ERS_RESULT_NONE = (__force pci_ers_result_t) 1,
  
  	/* Device driver can recover without slot reset */
  	PCI_ERS_RESULT_CAN_RECOVER = (__force pci_ers_result_t) 2,
  
  	/* Device driver wants slot to be reset. */
  	PCI_ERS_RESULT_NEED_RESET = (__force pci_ers_result_t) 3,
  
  	/* Device has completely failed, is unrecoverable */
  	PCI_ERS_RESULT_DISCONNECT = (__force pci_ers_result_t) 4,
  
  	/* Device driver is fully recovered and operational */
  	PCI_ERS_RESULT_RECOVERED = (__force pci_ers_result_t) 5,
918b40531   Vijay Mohan Pandarathil   PCI/AER: Report s...
671
672
673
  
  	/* No AER capabilities registered for the driver */
  	PCI_ERS_RESULT_NO_AER_DRIVER = (__force pci_ers_result_t) 6,
392a1ce76   Linas Vepstas   [PATCH] PCI Error...
674
675
676
  };
  
  /* PCI bus error event callbacks */
05cca6e52   Greg Kroah-Hartman   PCI: fix codingst...
677
  struct pci_error_handlers {
392a1ce76   Linas Vepstas   [PATCH] PCI Error...
678
679
  	/* PCI bus error detected on this device */
  	pci_ers_result_t (*error_detected)(struct pci_dev *dev,
05cca6e52   Greg Kroah-Hartman   PCI: fix codingst...
680
  					   enum pci_channel_state error);
392a1ce76   Linas Vepstas   [PATCH] PCI Error...
681
682
683
  
  	/* MMIO has been re-enabled, but not DMA */
  	pci_ers_result_t (*mmio_enabled)(struct pci_dev *dev);
392a1ce76   Linas Vepstas   [PATCH] PCI Error...
684
685
  	/* PCI slot has been reset */
  	pci_ers_result_t (*slot_reset)(struct pci_dev *dev);
3ebe7f9f7   Keith Busch   PCI: Notify drive...
686
  	/* PCI function reset prepare or completed */
775755ed3   Christoph Hellwig   PCI: Split ->rese...
687
688
  	void (*reset_prepare)(struct pci_dev *dev);
  	void (*reset_done)(struct pci_dev *dev);
3ebe7f9f7   Keith Busch   PCI: Notify drive...
689

392a1ce76   Linas Vepstas   [PATCH] PCI Error...
690
691
692
  	/* Device driver may resume normal operations */
  	void (*resume)(struct pci_dev *dev);
  };
392a1ce76   Linas Vepstas   [PATCH] PCI Error...
693

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
694
695
696
  struct module;
  struct pci_driver {
  	struct list_head node;
42b219322   Stephen Hemminger   PCI: pci_driver m...
697
  	const char *name;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
698
699
700
701
  	const struct pci_device_id *id_table;	/* must be non-NULL for probe to be called */
  	int  (*probe)  (struct pci_dev *dev, const struct pci_device_id *id);	/* New device inserted */
  	void (*remove) (struct pci_dev *dev);	/* Device removed (NULL if not a hot-plug capable driver) */
  	int  (*suspend) (struct pci_dev *dev, pm_message_t state);	/* Device suspended */
cbd69dbbf   Linus Torvalds   Suspend changes f...
702
703
  	int  (*suspend_late) (struct pci_dev *dev, pm_message_t state);
  	int  (*resume_early) (struct pci_dev *dev);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
704
  	int  (*resume) (struct pci_dev *dev);	                /* Device woken up */
c89581772   Greg Kroah-Hartman   [PATCH] PCI: Add ...
705
  	void (*shutdown) (struct pci_dev *dev);
1789382a7   Donald Dutile   PCI: SRIOV contro...
706
  	int (*sriov_configure) (struct pci_dev *dev, int num_vfs); /* PF pdev */
494530284   Stephen Hemminger   PCI: Make pci_err...
707
  	const struct pci_error_handlers *err_handler;
92d50fc16   Greg Kroah-Hartman   PCI/IB: add suppo...
708
  	const struct attribute_group **groups;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
709
710
711
  	struct device_driver	driver;
  	struct pci_dynids dynids;
  };
05cca6e52   Greg Kroah-Hartman   PCI: fix codingst...
712
  #define	to_pci_driver(drv) container_of(drv, struct pci_driver, driver)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
  
  /**
   * PCI_DEVICE - macro used to describe a specific pci device
   * @vend: the 16 bit PCI Vendor ID
   * @dev: the 16 bit PCI Device ID
   *
   * This macro is used to create a struct pci_device_id that matches a
   * specific device.  The subvendor and subdevice fields will be set to
   * PCI_ANY_ID.
   */
  #define PCI_DEVICE(vend,dev) \
  	.vendor = (vend), .device = (dev), \
  	.subvendor = PCI_ANY_ID, .subdevice = PCI_ANY_ID
  
  /**
3d567e0e2   Nithin Nayak Sujir   tg3: Set 10_100_O...
728
729
730
731
732
733
734
735
736
737
738
739
740
741
   * PCI_DEVICE_SUB - macro used to describe a specific pci device with subsystem
   * @vend: the 16 bit PCI Vendor ID
   * @dev: the 16 bit PCI Device ID
   * @subvend: the 16 bit PCI Subvendor ID
   * @subdev: the 16 bit PCI Subdevice ID
   *
   * This macro is used to create a struct pci_device_id that matches a
   * specific device with subsystem information.
   */
  #define PCI_DEVICE_SUB(vend, dev, subvend, subdev) \
  	.vendor = (vend), .device = (dev), \
  	.subvendor = (subvend), .subdevice = (subdev)
  
  /**
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
742
743
744
745
746
   * PCI_DEVICE_CLASS - macro used to describe a specific pci device class
   * @dev_class: the class, subclass, prog-if triple for this device
   * @dev_class_mask: the class mask for this device
   *
   * This macro is used to create a struct pci_device_id that matches a
4352dfd5c   Greg Kroah-Hartman   [PATCH] PCI: clea...
747
   * specific PCI class.  The vendor, device, subvendor, and subdevice
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
748
749
750
751
752
753
   * fields will be set to PCI_ANY_ID.
   */
  #define PCI_DEVICE_CLASS(dev_class,dev_class_mask) \
  	.class = (dev_class), .class_mask = (dev_class_mask), \
  	.vendor = PCI_ANY_ID, .device = PCI_ANY_ID, \
  	.subvendor = PCI_ANY_ID, .subdevice = PCI_ANY_ID
1597cacbe   Alan Cox   PCI: Fix multiple...
754
755
  /**
   * PCI_VDEVICE - macro used to describe a specific pci device in short form
c13090409   Mark Rustad   PCI: Use designat...
756
757
   * @vend: the vendor name
   * @dev: the 16 bit PCI Device ID
1597cacbe   Alan Cox   PCI: Fix multiple...
758
759
760
761
762
763
   *
   * This macro is used to create a struct pci_device_id that matches a
   * specific PCI device.  The subvendor, and subdevice fields will be set
   * to PCI_ANY_ID. The macro allows the next field to follow as the device
   * private data.
   */
c13090409   Mark Rustad   PCI: Use designat...
764
765
766
  #define PCI_VDEVICE(vend, dev) \
  	.vendor = PCI_VENDOR_ID_##vend, .device = (dev), \
  	.subvendor = PCI_ANY_ID, .subdevice = PCI_ANY_ID, 0, 0
1597cacbe   Alan Cox   PCI: Fix multiple...
767

5bbe029ff   Bjorn Helgaas   PCI: Move pci_set...
768
769
770
771
772
773
774
775
776
  enum {
  	PCI_REASSIGN_ALL_RSRC	= 0x00000001,	/* ignore firmware setup */
  	PCI_REASSIGN_ALL_BUS	= 0x00000002,	/* reassign all bus numbers */
  	PCI_PROBE_ONLY		= 0x00000004,	/* use existing setup */
  	PCI_CAN_SKIP_ISA_ALIGN	= 0x00000008,	/* don't do ISA alignment */
  	PCI_ENABLE_PROC_DOMAINS	= 0x00000010,	/* enable domains in /proc */
  	PCI_COMPAT_DOMAIN_0	= 0x00000020,	/* ... except domain 0 */
  	PCI_SCAN_ALL_PCIE_DEVS	= 0x00000040,	/* scan all, not just dev 0 */
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
777
778
  /* these external functions are only available when PCI support is enabled */
  #ifdef CONFIG_PCI
5bbe029ff   Bjorn Helgaas   PCI: Move pci_set...
779
780
781
782
783
784
  extern unsigned int pci_flags;
  
  static inline void pci_set_flags(int flags) { pci_flags = flags; }
  static inline void pci_add_flags(int flags) { pci_flags |= flags; }
  static inline void pci_clear_flags(int flags) { pci_flags &= ~flags; }
  static inline int pci_has_flag(int flag) { return pci_flags & flag; }
a58674ff8   Bjorn Helgaas   PCI: Simplify pci...
785
  void pcie_bus_configure_settings(struct pci_bus *bus);
b03e7495a   Jon Mason   PCI: Set PCI-E Ma...
786
787
  
  enum pcie_bus_config_types {
27d868b5e   Keith Busch   PCI: Set MPS to m...
788
789
790
791
792
  	PCIE_BUS_TUNE_OFF,	/* don't touch MPS at all */
  	PCIE_BUS_DEFAULT,	/* ensure MPS matches upstream bridge */
  	PCIE_BUS_SAFE,		/* use largest MPS boot-time devices support */
  	PCIE_BUS_PERFORMANCE,	/* use MPS and MRRS for best performance */
  	PCIE_BUS_PEER2PEER,	/* set MPS = 128 for all devices */
b03e7495a   Jon Mason   PCI: Set PCI-E Ma...
793
794
795
  };
  
  extern enum pcie_bus_config_types pcie_bus_config;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
796
  extern struct bus_type pci_bus_type;
f7625980f   Bjorn Helgaas   PCI: Fix whitespa...
797
798
  /* Do NOT directly access these two variables, unless you are arch-specific PCI
   * code, or PCI core code. */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
799
  extern struct list_head pci_root_buses;	/* list of all known PCI buses */
f7625980f   Bjorn Helgaas   PCI: Fix whitespa...
800
  /* Some device drivers need know if PCI is initiated */
f39d5b729   Bjorn Helgaas   PCI: Remove "exte...
801
  int no_pci_devices(void);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
802

3c449ed00   Yinghai Lu   PCI/ACPI: Reserve...
803
  void pcibios_resource_survey_bus(struct pci_bus *bus);
7b77061f8   Wei Yang   PCI: Add pcibios_...
804
  void pcibios_bus_add_device(struct pci_dev *pdev);
10a957475   Jiang Liu   PCI: Add pcibios ...
805
806
  void pcibios_add_bus(struct pci_bus *bus);
  void pcibios_remove_bus(struct pci_bus *bus);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
807
  void pcibios_fixup_bus(struct pci_bus *);
4a7fb6363   Andrew Morton   add __must_check ...
808
  int __must_check pcibios_enable_device(struct pci_dev *, int mask);
f7625980f   Bjorn Helgaas   PCI: Fix whitespa...
809
  /* Architecture-specific versions may override this (weak) */
05cca6e52   Greg Kroah-Hartman   PCI: fix codingst...
810
  char *pcibios_setup(char *str);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
811
812
  
  /* Used only when drivers/pci/setup.c is used */
3b7a17fcd   Dominik Brodowski   resource/PCI: mar...
813
  resource_size_t pcibios_align_resource(void *, const struct resource *,
b26b2d494   Dominik Brodowski   resource/PCI: ali...
814
  				resource_size_t,
e31dd6e45   Greg Kroah-Hartman   [PATCH] 64bit res...
815
  				resource_size_t);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
816

2d1c86187   Benjamin Herrenschmidt   PCI/cardbus: Add ...
817
818
  /* Weak but can be overriden by arch */
  void pci_fixup_cardbus(struct pci_bus *);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
819
  /* Generic PCI functions used internally */
fc2798502   Yinghai Lu   PCI: Convert pcib...
820
  void pcibios_resource_to_bus(struct pci_bus *bus, struct pci_bus_region *region,
36a66cd6f   Bjorn Helgaas   PCI: add generic ...
821
  			     struct resource *res);
fc2798502   Yinghai Lu   PCI: Convert pcib...
822
  void pcibios_bus_to_resource(struct pci_bus *bus, struct resource *res,
36a66cd6f   Bjorn Helgaas   PCI: add generic ...
823
  			     struct pci_bus_region *region);
d1fd4fb69   Mauro Carvalho Chehab   i7core_edac: Add ...
824
  void pcibios_scan_specific_bus(int busn);
f39d5b729   Bjorn Helgaas   PCI: Remove "exte...
825
  struct pci_bus *pci_find_bus(int domain, int busnr);
c48f1670f   akpm@linux-foundation.org   PCI: constify pci...
826
  void pci_bus_add_devices(const struct pci_bus *bus);
de4b2f76d   Bjorn Helgaas   PCI: convert pci_...
827
  struct pci_bus *pci_scan_bus(int bus, struct pci_ops *ops, void *sysdata);
166c63707   Bjorn Helgaas   PCI: add pci_crea...
828
829
830
  struct pci_bus *pci_create_root_bus(struct device *parent, int bus,
  				    struct pci_ops *ops, void *sysdata,
  				    struct list_head *resources);
98a358310   Yinghai Lu   PCI: add busn_res...
831
832
833
  int pci_bus_insert_busn_res(struct pci_bus *b, int bus, int busmax);
  int pci_bus_update_busn_res_end(struct pci_bus *b, int busmax);
  void pci_bus_release_busn_res(struct pci_bus *b);
15856ad50   Bill Pemberton   PCI: Remove __dev...
834
  struct pci_bus *pci_scan_root_bus(struct device *parent, int bus,
a2ebb8279   Bjorn Helgaas   PCI: add pci_scan...
835
836
  					     struct pci_ops *ops, void *sysdata,
  					     struct list_head *resources);
1228c4b6c   Lorenzo Pieralisi   PCI: Add pci_scan...
837
  int pci_scan_root_bus_bridge(struct pci_host_bridge *bridge);
05cca6e52   Greg Kroah-Hartman   PCI: fix codingst...
838
839
  struct pci_bus *pci_add_new_bus(struct pci_bus *parent, struct pci_dev *dev,
  				int busnr);
3749c51ac   Matthew Wilcox   PCI: Make current...
840
  void pcie_update_link_speed(struct pci_bus *bus, u16 link_status);
f46753c5e   Alex Chiang   PCI: introduce pc...
841
  struct pci_slot *pci_create_slot(struct pci_bus *parent, int slot_nr,
828f37683   Alex Chiang   PCI: update pci_c...
842
843
  				 const char *name,
  				 struct hotplug_slot *hotplug);
f46753c5e   Alex Chiang   PCI: introduce pc...
844
  void pci_destroy_slot(struct pci_slot *slot);
017ffe64e   Yijing Wang   PCI: Hold pci_slo...
845
846
847
848
849
  #ifdef CONFIG_SYSFS
  void pci_dev_assign_slot(struct pci_dev *dev);
  #else
  static inline void pci_dev_assign_slot(struct pci_dev *dev) { }
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
850
  int pci_scan_slot(struct pci_bus *bus, int devfn);
05cca6e52   Greg Kroah-Hartman   PCI: fix codingst...
851
  struct pci_dev *pci_scan_single_device(struct pci_bus *bus, int devfn);
cdb9b9f73   Paul Mackerras   [PATCH] PCI: Smal...
852
  void pci_device_add(struct pci_dev *dev, struct pci_bus *bus);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
853
  unsigned int pci_scan_child_bus(struct pci_bus *bus);
c893d133e   Yijing Wang   PCI: Make pci_bus...
854
  void pci_bus_add_device(struct pci_dev *dev);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
855
  void pci_read_bridge_bases(struct pci_bus *child);
05cca6e52   Greg Kroah-Hartman   PCI: fix codingst...
856
857
  struct resource *pci_find_parent_resource(const struct pci_dev *dev,
  					  struct resource *res);
c56d4450e   Hariprasad Shenai   PCI: Turn off Req...
858
  struct pci_dev *pci_find_pcie_root_port(struct pci_dev *dev);
3df425f31   John Crispin   OF: PCI: const us...
859
  u8 pci_swizzle_interrupt_pin(const struct pci_dev *dev, u8 pin);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
860
  int pci_get_interrupt_pin(struct pci_dev *dev, struct pci_dev **bridge);
68feac87d   Bjorn Helgaas   PCI: add pci_comm...
861
  u8 pci_common_swizzle(struct pci_dev *dev, u8 *pinp);
f39d5b729   Bjorn Helgaas   PCI: Remove "exte...
862
863
864
865
  struct pci_dev *pci_dev_get(struct pci_dev *dev);
  void pci_dev_put(struct pci_dev *dev);
  void pci_remove_bus(struct pci_bus *b);
  void pci_stop_and_remove_bus_device(struct pci_dev *dev);
9d16947b7   Rafael J. Wysocki   PCI: Add global p...
866
  void pci_stop_and_remove_bus_device_locked(struct pci_dev *dev);
cdfcc572b   Yinghai Lu   PCI: Add pci_stop...
867
868
  void pci_stop_root_bus(struct pci_bus *bus);
  void pci_remove_root_bus(struct pci_bus *bus);
b3743fa44   Dominik Brodowski   [PATCH] yenta: sh...
869
  void pci_setup_cardbus(struct pci_bus *bus);
d366d28cd   Gavin Shan   PCI: Add pcibios_...
870
  void pcibios_setup_bridge(struct pci_bus *bus, unsigned long type);
f39d5b729   Bjorn Helgaas   PCI: Remove "exte...
871
  void pci_sort_breadthfirst(void);
fb8a0d9d1   Williams, Mitch A   pci: Add SR-IOV c...
872
873
  #define dev_is_pci(d) ((d)->bus == &pci_bus_type)
  #define dev_is_pf(d) ((dev_is_pci(d) ? to_pci_dev(d)->is_physfn : false))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
874
875
  
  /* Generic PCI functions exported to card drivers */
388c8c16a   James Bottomley   PCI: add routines...
876
877
878
879
880
881
882
  enum pci_lost_interrupt_reason {
  	PCI_LOST_IRQ_NO_INFORMATION = 0,
  	PCI_LOST_IRQ_DISABLE_MSI,
  	PCI_LOST_IRQ_DISABLE_MSIX,
  	PCI_LOST_IRQ_DISABLE_ACPI,
  };
  enum pci_lost_interrupt_reason pci_lost_interrupt(struct pci_dev *dev);
05cca6e52   Greg Kroah-Hartman   PCI: fix codingst...
883
884
885
  int pci_find_capability(struct pci_dev *dev, int cap);
  int pci_find_next_capability(struct pci_dev *dev, u8 pos, int cap);
  int pci_find_ext_capability(struct pci_dev *dev, int cap);
44a9a36f6   Bjorn Helgaas   PCI: Add pci_find...
886
  int pci_find_next_ext_capability(struct pci_dev *dev, int pos, int cap);
05cca6e52   Greg Kroah-Hartman   PCI: fix codingst...
887
888
  int pci_find_ht_capability(struct pci_dev *dev, int ht_cap);
  int pci_find_next_ht_capability(struct pci_dev *dev, int pos, int ht_cap);
29f3eb646   Alan Cox   pci: Additional s...
889
  struct pci_bus *pci_find_next_bus(const struct pci_bus *from);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
890

d42552c3a   Andrew Morton   [PATCH] pci: decl...
891
892
  struct pci_dev *pci_get_device(unsigned int vendor, unsigned int device,
  				struct pci_dev *from);
05cca6e52   Greg Kroah-Hartman   PCI: fix codingst...
893
  struct pci_dev *pci_get_subsys(unsigned int vendor, unsigned int device,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
894
  				unsigned int ss_vendor, unsigned int ss_device,
b08508c40   Greg Kroah-Hartman   PCI: fix compiler...
895
  				struct pci_dev *from);
05cca6e52   Greg Kroah-Hartman   PCI: fix codingst...
896
  struct pci_dev *pci_get_slot(struct pci_bus *bus, unsigned int devfn);
3c299dc22   Andrew Patterson   PCI: add pci_get_...
897
898
899
900
901
902
903
  struct pci_dev *pci_get_domain_bus_and_slot(int domain, unsigned int bus,
  					    unsigned int devfn);
  static inline struct pci_dev *pci_get_bus_and_slot(unsigned int bus,
  						   unsigned int devfn)
  {
  	return pci_get_domain_bus_and_slot(0, bus, devfn);
  }
05cca6e52   Greg Kroah-Hartman   PCI: fix codingst...
904
  struct pci_dev *pci_get_class(unsigned int class, struct pci_dev *from);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
905
  int pci_dev_present(const struct pci_device_id *ids);
05cca6e52   Greg Kroah-Hartman   PCI: fix codingst...
906
907
908
909
910
911
912
913
914
915
916
917
  int pci_bus_read_config_byte(struct pci_bus *bus, unsigned int devfn,
  			     int where, u8 *val);
  int pci_bus_read_config_word(struct pci_bus *bus, unsigned int devfn,
  			     int where, u16 *val);
  int pci_bus_read_config_dword(struct pci_bus *bus, unsigned int devfn,
  			      int where, u32 *val);
  int pci_bus_write_config_byte(struct pci_bus *bus, unsigned int devfn,
  			      int where, u8 val);
  int pci_bus_write_config_word(struct pci_bus *bus, unsigned int devfn,
  			      int where, u16 val);
  int pci_bus_write_config_dword(struct pci_bus *bus, unsigned int devfn,
  			       int where, u32 val);
1f94a94f6   Rob Herring   PCI: Add generic ...
918
919
920
921
922
923
924
925
926
  
  int pci_generic_config_read(struct pci_bus *bus, unsigned int devfn,
  			    int where, int size, u32 *val);
  int pci_generic_config_write(struct pci_bus *bus, unsigned int devfn,
  			    int where, int size, u32 val);
  int pci_generic_config_read32(struct pci_bus *bus, unsigned int devfn,
  			      int where, int size, u32 *val);
  int pci_generic_config_write32(struct pci_bus *bus, unsigned int devfn,
  			       int where, int size, u32 val);
a72b46c38   Huang Ying   PCI: Add pci_bus_...
927
  struct pci_ops *pci_bus_set_ops(struct pci_bus *bus, struct pci_ops *ops);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
928

d3881e501   Keith Busch   PCI: Export PCI d...
929
930
931
932
933
934
  int pci_read_config_byte(const struct pci_dev *dev, int where, u8 *val);
  int pci_read_config_word(const struct pci_dev *dev, int where, u16 *val);
  int pci_read_config_dword(const struct pci_dev *dev, int where, u32 *val);
  int pci_write_config_byte(const struct pci_dev *dev, int where, u8 val);
  int pci_write_config_word(const struct pci_dev *dev, int where, u16 val);
  int pci_write_config_dword(const struct pci_dev *dev, int where, u32 val);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
935

8c0d3a02c   Jiang Liu   PCI: Add accessor...
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
  int pcie_capability_read_word(struct pci_dev *dev, int pos, u16 *val);
  int pcie_capability_read_dword(struct pci_dev *dev, int pos, u32 *val);
  int pcie_capability_write_word(struct pci_dev *dev, int pos, u16 val);
  int pcie_capability_write_dword(struct pci_dev *dev, int pos, u32 val);
  int pcie_capability_clear_and_set_word(struct pci_dev *dev, int pos,
  				       u16 clear, u16 set);
  int pcie_capability_clear_and_set_dword(struct pci_dev *dev, int pos,
  					u32 clear, u32 set);
  
  static inline int pcie_capability_set_word(struct pci_dev *dev, int pos,
  					   u16 set)
  {
  	return pcie_capability_clear_and_set_word(dev, pos, 0, set);
  }
  
  static inline int pcie_capability_set_dword(struct pci_dev *dev, int pos,
  					    u32 set)
  {
  	return pcie_capability_clear_and_set_dword(dev, pos, 0, set);
  }
  
  static inline int pcie_capability_clear_word(struct pci_dev *dev, int pos,
  					     u16 clear)
  {
  	return pcie_capability_clear_and_set_word(dev, pos, clear, 0);
  }
  
  static inline int pcie_capability_clear_dword(struct pci_dev *dev, int pos,
  					      u32 clear)
  {
  	return pcie_capability_clear_and_set_dword(dev, pos, clear, 0);
  }
c63587d7f   Alex Williamson   PCI: export pci_u...
968
969
970
971
972
973
974
  /* user-space driven config access */
  int pci_user_read_config_byte(struct pci_dev *dev, int where, u8 *val);
  int pci_user_read_config_word(struct pci_dev *dev, int where, u16 *val);
  int pci_user_read_config_dword(struct pci_dev *dev, int where, u32 *val);
  int pci_user_write_config_byte(struct pci_dev *dev, int where, u8 val);
  int pci_user_write_config_word(struct pci_dev *dev, int where, u16 val);
  int pci_user_write_config_dword(struct pci_dev *dev, int where, u32 val);
4a7fb6363   Andrew Morton   add __must_check ...
975
  int __must_check pci_enable_device(struct pci_dev *dev);
b718989da   Benjamin Herrenschmidt   PCI: Add pci_enab...
976
977
  int __must_check pci_enable_device_io(struct pci_dev *dev);
  int __must_check pci_enable_device_mem(struct pci_dev *dev);
0b62e13b5   Tejun Heo   pci: rename __pci...
978
  int __must_check pci_reenable_device(struct pci_dev *);
9ac7849e3   Tejun Heo   devres: device re...
979
980
  int __must_check pcim_enable_device(struct pci_dev *pdev);
  void pcim_pin_device(struct pci_dev *pdev);
99b3c58f7   Piotr Gregor   PCI: Test INTx ma...
981
982
983
984
985
986
987
988
  static inline bool pci_intx_mask_supported(struct pci_dev *pdev)
  {
  	/*
  	 * INTx masking is supported if PCI_COMMAND_INTX_DISABLE is
  	 * writable and no quirk has marked the feature broken.
  	 */
  	return !pdev->broken_intx_masking;
  }
296ccb086   Yuji Shimada   PCI: Setup disabl...
989
990
991
992
  static inline int pci_is_enabled(struct pci_dev *pdev)
  {
  	return (atomic_read(&pdev->enable_cnt) > 0);
  }
9ac7849e3   Tejun Heo   devres: device re...
993
994
995
996
  static inline int pci_is_managed(struct pci_dev *pdev)
  {
  	return pdev->is_managed;
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
997
  void pci_disable_device(struct pci_dev *dev);
96c559005   Myron Stowe   PCI: Pull PCI 'la...
998
999
  
  extern unsigned int pcibios_max_latency;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1000
  void pci_set_master(struct pci_dev *dev);
6a479079c   Ben Hutchings   PCI: Add pci_clea...
1001
  void pci_clear_master(struct pci_dev *dev);
96c559005   Myron Stowe   PCI: Pull PCI 'la...
1002

f7bdd12d2   Brian King   pci: New PCI-E re...
1003
  int pci_set_pcie_reset_state(struct pci_dev *dev, enum pcie_reset_state state);
15ea76d40   Tejun Heo   pccard: configure...
1004
  int pci_set_cacheline_size(struct pci_dev *dev);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1005
  #define HAVE_PCI_SET_MWI
4a7fb6363   Andrew Morton   add __must_check ...
1006
  int __must_check pci_set_mwi(struct pci_dev *dev);
694625c0b   Randy Dunlap   PCI: add pci_try_...
1007
  int pci_try_set_mwi(struct pci_dev *dev);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1008
  void pci_clear_mwi(struct pci_dev *dev);
a04ce0ffc   Brett M Russ   [PATCH] PCI/libat...
1009
  void pci_intx(struct pci_dev *dev, int enable);
a2e27787f   Jan Kiszka   PCI: Introduce IN...
1010
1011
  bool pci_check_and_mask_intx(struct pci_dev *dev);
  bool pci_check_and_unmask_intx(struct pci_dev *dev);
157e876ff   Alex Williamson   PCI: Add pci_wait...
1012
  int pci_wait_for_pending(struct pci_dev *dev, int pos, u16 mask);
3775a209d   Casey Leedom   PCI: Add pci_wait...
1013
  int pci_wait_for_pending_transaction(struct pci_dev *dev);
d556ad4bb   Peter Oruba   PCI: add PCI-X/PC...
1014
1015
1016
  int pcix_get_max_mmrbc(struct pci_dev *dev);
  int pcix_get_mmrbc(struct pci_dev *dev);
  int pcix_set_mmrbc(struct pci_dev *dev, int mmrbc);
2637e5b53   Brice Goglin   PCI: make pcie_ge...
1017
  int pcie_get_readrq(struct pci_dev *dev);
d556ad4bb   Peter Oruba   PCI: add PCI-X/PC...
1018
  int pcie_set_readrq(struct pci_dev *dev, int rq);
b03e7495a   Jon Mason   PCI: Set PCI-E Ma...
1019
1020
  int pcie_get_mps(struct pci_dev *dev);
  int pcie_set_mps(struct pci_dev *dev, int mps);
81377c8d3   Jacob Keller   PCI: Add function...
1021
1022
  int pcie_get_minimum_link(struct pci_dev *dev, enum pci_bus_speed *speed,
  			  enum pcie_link_width *width);
a60a2b73b   Christoph Hellwig   PCI: Export pcie_...
1023
  void pcie_flr(struct pci_dev *dev);
8c1c699fe   Yu Zhao   PCI: cleanup Func...
1024
  int __pci_reset_function(struct pci_dev *dev);
a96d627ab   Konrad Rzeszutek Wilk   pci: Introduce __...
1025
  int __pci_reset_function_locked(struct pci_dev *dev);
8dd7f8036   Sheng Yang   PCI: add support ...
1026
  int pci_reset_function(struct pci_dev *dev);
a477b9cd3   Marc Zyngier   PCI: Add pci_rese...
1027
  int pci_reset_function_locked(struct pci_dev *dev);
61cf16d8b   Alex Williamson   PCI: Add pci_try_...
1028
  int pci_try_reset_function(struct pci_dev *dev);
9a3d2b9be   Alex Williamson   PCI: Add pci_prob...
1029
  int pci_probe_reset_slot(struct pci_slot *slot);
090a3c532   Alex Williamson   PCI: Add pci_rese...
1030
  int pci_reset_slot(struct pci_slot *slot);
61cf16d8b   Alex Williamson   PCI: Add pci_try_...
1031
  int pci_try_reset_slot(struct pci_slot *slot);
9a3d2b9be   Alex Williamson   PCI: Add pci_prob...
1032
  int pci_probe_reset_bus(struct pci_bus *bus);
090a3c532   Alex Williamson   PCI: Add pci_rese...
1033
  int pci_reset_bus(struct pci_bus *bus);
61cf16d8b   Alex Williamson   PCI: Add pci_try_...
1034
  int pci_try_reset_bus(struct pci_bus *bus);
9e33002fd   Gavin Shan   PCI: Make resetti...
1035
1036
  void pci_reset_secondary_bus(struct pci_dev *dev);
  void pcibios_reset_secondary_bus(struct pci_dev *dev);
64e8674fb   Alex Williamson   PCI: Add pci_rese...
1037
  void pci_reset_bridge_secondary_bus(struct pci_dev *dev);
14add80b5   Yu Zhao   PCI: remove unnec...
1038
  void pci_update_resource(struct pci_dev *dev, int resno);
4a7fb6363   Andrew Morton   add __must_check ...
1039
  int __must_check pci_assign_resource(struct pci_dev *dev, int i);
2bbc69422   Ram Pai   PCI : ability to ...
1040
  int __must_check pci_reassign_resource(struct pci_dev *dev, int i, resource_size_t add_size, resource_size_t align);
c87deff77   Hidetoshi Seto   PCI : Add selecte...
1041
  int pci_select_bars(struct pci_dev *dev, unsigned long flags);
8496e85c2   Rafael J. Wysocki   PCI / tg3: Give u...
1042
  bool pci_device_is_present(struct pci_dev *pdev);
082496514   Rafael J. Wysocki   PCI: Propagate th...
1043
  void pci_ignore_hotplug(struct pci_dev *dev);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1044

704e8953d   Christoph Hellwig   PCI/irq: Add pci_...
1045
1046
1047
1048
  int __printf(6, 7) pci_request_irq(struct pci_dev *dev, unsigned int nr,
  		irq_handler_t handler, irq_handler_t thread_fn, void *dev_id,
  		const char *fmt, ...);
  void pci_free_irq(struct pci_dev *dev, unsigned int nr, void *dev_id);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1049
  /* ROM control related routines */
e416de5e6   Alan Cox   Export the ROM en...
1050
1051
  int pci_enable_rom(struct pci_dev *pdev);
  void pci_disable_rom(struct pci_dev *pdev);
144a50ea5   Dave Jones   [PATCH] must_chec...
1052
  void __iomem __must_check *pci_map_rom(struct pci_dev *pdev, size_t *size);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1053
  void pci_unmap_rom(struct pci_dev *pdev, void __iomem *rom);
97c44836c   Timothy S. Nelson   PCI: return error...
1054
  size_t pci_get_rom_size(struct pci_dev *pdev, void __iomem *rom, size_t size);
fffe01f7a   Matthew Garrett   PCI: Add PCI ROM ...
1055
  void __iomem __must_check *pci_platform_rom(struct pci_dev *pdev, size_t *size);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1056
1057
1058
  
  /* Power management related routines */
  int pci_save_state(struct pci_dev *dev);
1d3c16a81   Jon Mason   PCI: make pci_res...
1059
  void pci_restore_state(struct pci_dev *dev);
ffbdd3f79   Alex Williamson   PCI: Add interfac...
1060
  struct pci_saved_state *pci_store_saved_state(struct pci_dev *dev);
98d9b2712   Konrad Rzeszutek Wilk   PCI: Expose pci_l...
1061
1062
  int pci_load_saved_state(struct pci_dev *dev,
  			 struct pci_saved_state *state);
ffbdd3f79   Alex Williamson   PCI: Add interfac...
1063
1064
  int pci_load_and_free_saved_state(struct pci_dev *dev,
  				  struct pci_saved_state **state);
fd0f7f73c   Alex Williamson   PCI: Add support ...
1065
1066
1067
1068
1069
1070
  struct pci_cap_saved_state *pci_find_saved_cap(struct pci_dev *dev, char cap);
  struct pci_cap_saved_state *pci_find_saved_ext_cap(struct pci_dev *dev,
  						   u16 cap);
  int pci_add_cap_save_buffer(struct pci_dev *dev, char cap, unsigned int size);
  int pci_add_ext_cap_save_buffer(struct pci_dev *dev,
  				u16 cap, unsigned int size);
0e5dd46b7   Rafael J. Wysocki   PCI PM: Introduce...
1071
  int __pci_complete_power_transition(struct pci_dev *dev, pci_power_t state);
9c8550ee2   Linus Torvalds   Remove "must_chec...
1072
1073
  int pci_set_power_state(struct pci_dev *dev, pci_power_t state);
  pci_power_t pci_choose_state(struct pci_dev *dev, pm_message_t state);
e5899e1b7   Rafael J. Wysocki   PCI PM: make more...
1074
  bool pci_pme_capable(struct pci_dev *dev, pci_power_t state);
5a6c9b60b   Rafael J. Wysocki   PCI PM: Export pc...
1075
  void pci_pme_active(struct pci_dev *dev, bool enable);
0847684cf   Rafael J. Wysocki   PCI / PM: Simplif...
1076
  int pci_enable_wake(struct pci_dev *dev, pci_power_t state, bool enable);
0235c4fc7   Rafael J. Wysocki   PCI PM: Introduce...
1077
  int pci_wake_from_d3(struct pci_dev *dev, bool enable);
404cc2d8c   Rafael J. Wysocki   PCI PM: Introduce...
1078
1079
  int pci_prepare_to_sleep(struct pci_dev *dev);
  int pci_back_from_sleep(struct pci_dev *dev);
b67ea7617   Rafael J. Wysocki   PCI / ACPI / PM: ...
1080
  bool pci_dev_run_wake(struct pci_dev *dev);
bf4d29086   Matthew Garrett   PCI: Export some ...
1081
  bool pci_check_pme_status(struct pci_dev *dev);
bf4d29086   Matthew Garrett   PCI: Export some ...
1082
  void pci_pme_wakeup_bus(struct pci_bus *bus);
9d26d3a8f   Mika Westerberg   PCI: Put PCIe por...
1083
1084
  void pci_d3cold_enable(struct pci_dev *dev);
  void pci_d3cold_disable(struct pci_dev *dev);
a99b646af   dingtianhong   PCI: Disable PCIe...
1085
  bool pcie_relaxed_ordering_enabled(struct pci_dev *dev);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1086

425c1b223   Alex Williamson   PCI: Add Virtual ...
1087
1088
1089
1090
  /* PCI Virtual Channel */
  int pci_save_vc_state(struct pci_dev *dev);
  void pci_restore_vc_state(struct pci_dev *dev);
  void pci_allocate_vc_save_buffers(struct pci_dev *dev);
51c2e0a7e   Jesse Barnes   PCI: add latency ...
1091

bb209c828   Benjamin Herrenschmidt   powerpc/pci: Add ...
1092
1093
1094
  /* For use by arch with custom probe code */
  void set_pcie_port_type(struct pci_dev *pdev);
  void set_pcie_hotplug_bridge(struct pci_dev *pdev);
ce5ccdef1   Kumar Gala   PCI: Move prototy...
1095
  /* Functions for PCI Hotplug drivers to use */
05cca6e52   Greg Kroah-Hartman   PCI: fix codingst...
1096
  int pci_bus_find_capability(struct pci_bus *bus, unsigned int devfn, int cap);
2f320521a   Yinghai Lu   PCI: Make rescan ...
1097
  unsigned int pci_rescan_bus_bridge_resize(struct pci_dev *bridge);
3ed4fd96b   Alex Chiang   PCI: Introduce pc...
1098
  unsigned int pci_rescan_bus(struct pci_bus *bus);
9d16947b7   Rafael J. Wysocki   PCI: Add global p...
1099
1100
  void pci_lock_rescan_remove(void);
  void pci_unlock_rescan_remove(void);
ce5ccdef1   Kumar Gala   PCI: Move prototy...
1101

287d19ce2   Stephen Hemminger   PCI: revise VPD a...
1102
1103
1104
  /* Vital product data routines */
  ssize_t pci_read_vpd(struct pci_dev *dev, loff_t pos, size_t count, void *buf);
  ssize_t pci_write_vpd(struct pci_dev *dev, loff_t pos, size_t count, const void *buf);
cb92148b5   Hariprasad Shenai   PCI: Add pci_set_...
1105
  int pci_set_vpd_size(struct pci_dev *dev, size_t len);
287d19ce2   Stephen Hemminger   PCI: revise VPD a...
1106

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1107
  /* Helper functions for low-level code (drivers/pci/setup-[bus,res].c) */
925845bd4   Myron Stowe   x86/PCI: Infrastr...
1108
  resource_size_t pcibios_retrieve_fw_addr(struct pci_dev *dev, int idx);
ea7415512   Andrew Morton   PCI: constify pci...
1109
  void pci_bus_assign_resources(const struct pci_bus *bus);
765bf9b73   Lorenzo Pieralisi   PCI: Add generic ...
1110
  void pci_bus_claim_resources(struct pci_bus *bus);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1111
1112
  void pci_bus_size_bridges(struct pci_bus *bus);
  int pci_claim_resource(struct pci_dev *, int);
8505e729a   Yinghai Lu   PCI: Add pci_clai...
1113
  int pci_claim_bridge_resource(struct pci_dev *bridge, int i);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1114
  void pci_assign_unassigned_resources(void);
6841ec681   Yinghai Lu   PCI: introduce pc...
1115
  void pci_assign_unassigned_bridge_resources(struct pci_dev *bridge);
177879403   Yinghai Lu   PCI: Separate out...
1116
  void pci_assign_unassigned_bus_resources(struct pci_bus *bus);
39772038e   Yinghai Lu   PCI: Assign resou...
1117
  void pci_assign_unassigned_root_bus_resources(struct pci_bus *bus);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1118
  void pdev_enable_device(struct pci_dev *);
842de40d9   Bjorn Helgaas   PCI: add generic ...
1119
  int pci_enable_resources(struct pci_dev *, int mask);
47a650f27   Matthew Minter   PCI: Add pci_assi...
1120
  void pci_assign_irq(struct pci_dev *dev);
afd29f901   Mika Westerberg   PCI: Add pci_find...
1121
  struct resource *pci_find_resource(struct pci_dev *dev, struct resource *res);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1122
  #define HAVE_PCI_REQ_REGIONS	2
4a7fb6363   Andrew Morton   add __must_check ...
1123
  int __must_check pci_request_regions(struct pci_dev *, const char *);
e8de1481f   Arjan van de Ven   resource: allow M...
1124
  int __must_check pci_request_regions_exclusive(struct pci_dev *, const char *);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1125
  void pci_release_regions(struct pci_dev *);
4a7fb6363   Andrew Morton   add __must_check ...
1126
  int __must_check pci_request_region(struct pci_dev *, int, const char *);
e8de1481f   Arjan van de Ven   resource: allow M...
1127
  int __must_check pci_request_region_exclusive(struct pci_dev *, int, const char *);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1128
  void pci_release_region(struct pci_dev *, int);
c87deff77   Hidetoshi Seto   PCI : Add selecte...
1129
  int pci_request_selected_regions(struct pci_dev *, int, const char *);
e8de1481f   Arjan van de Ven   resource: allow M...
1130
  int pci_request_selected_regions_exclusive(struct pci_dev *, int, const char *);
c87deff77   Hidetoshi Seto   PCI : Add selecte...
1131
  void pci_release_selected_regions(struct pci_dev *, int);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1132
1133
  
  /* drivers/pci/bus.c */
fe830ef62   Jiang Liu   PCI: Introduce pc...
1134
1135
  struct pci_bus *pci_bus_get(struct pci_bus *bus);
  void pci_bus_put(struct pci_bus *bus);
45ca9e973   Bjorn Helgaas   PCI: add helpers ...
1136
  void pci_add_resource(struct list_head *resources, struct resource *res);
0efd5aab4   Bjorn Helgaas   PCI: add struct p...
1137
1138
  void pci_add_resource_offset(struct list_head *resources, struct resource *res,
  			     resource_size_t offset);
45ca9e973   Bjorn Helgaas   PCI: add helpers ...
1139
  void pci_free_resource_list(struct list_head *resources);
950334bcf   Bjorn Helgaas   PCI: Add devm_req...
1140
1141
  void pci_bus_add_resource(struct pci_bus *bus, struct resource *res,
  			  unsigned int flags);
2fe2abf89   Bjorn Helgaas   PCI: augment bus ...
1142
1143
  struct resource *pci_bus_resource_n(const struct pci_bus *bus, int n);
  void pci_bus_remove_resources(struct pci_bus *bus);
950334bcf   Bjorn Helgaas   PCI: Add devm_req...
1144
1145
  int devm_request_pci_bus_resources(struct device *dev,
  				   struct list_head *resources);
2fe2abf89   Bjorn Helgaas   PCI: augment bus ...
1146

89a74eccc   Bjorn Helgaas   PCI: add pci_bus_...
1147
  #define pci_bus_for_each_resource(bus, res, i)				\
2fe2abf89   Bjorn Helgaas   PCI: augment bus ...
1148
1149
1150
  	for (i = 0;							\
  	    (res = pci_bus_resource_n(bus, i)) || i < PCI_BRIDGE_RESOURCE_NUM; \
  	     i++)
89a74eccc   Bjorn Helgaas   PCI: add pci_bus_...
1151

4a7fb6363   Andrew Morton   add __must_check ...
1152
1153
1154
  int __must_check pci_bus_alloc_resource(struct pci_bus *bus,
  			struct resource *res, resource_size_t size,
  			resource_size_t align, resource_size_t min,
664c28480   Bjorn Helgaas   PCI: Change pci_b...
1155
  			unsigned long type_mask,
3b7a17fcd   Dominik Brodowski   resource/PCI: mar...
1156
1157
  			resource_size_t (*alignf)(void *,
  						  const struct resource *,
b26b2d494   Dominik Brodowski   resource/PCI: ali...
1158
1159
  						  resource_size_t,
  						  resource_size_t),
4a7fb6363   Andrew Morton   add __must_check ...
1160
  			void *alignf_data);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1161

8b921acfe   Liviu Dudau   PCI: Add pci_rema...
1162

c5076cfe7   Tomasz Nowicki   PCI, of: Move PCI...
1163
1164
1165
  int pci_register_io_range(phys_addr_t addr, resource_size_t size);
  unsigned long pci_address_to_pio(phys_addr_t addr);
  phys_addr_t pci_pio_to_address(unsigned long pio);
8b921acfe   Liviu Dudau   PCI: Add pci_rema...
1166
  int pci_remap_iospace(const struct resource *res, phys_addr_t phys_addr);
0e66392d9   Sergei Shtylyov   PCI: OF: Fix I/O ...
1167
1168
  int devm_pci_remap_iospace(struct device *dev, const struct resource *res,
  			   phys_addr_t phys_addr);
4d3f13845   Sinan Kaya   PCI: Add pci_unma...
1169
  void pci_unmap_iospace(struct resource *res);
490cb6ddb   Lorenzo Pieralisi   PCI: Implement de...
1170
1171
1172
1173
1174
  void __iomem *devm_pci_remap_cfgspace(struct device *dev,
  				      resource_size_t offset,
  				      resource_size_t size);
  void __iomem *devm_pci_remap_cfg_resource(struct device *dev,
  					  struct resource *res);
8b921acfe   Liviu Dudau   PCI: Add pci_rema...
1175

3a9ad0b4f   Yinghai Lu   PCI: Add pci_bus_...
1176
  static inline pci_bus_addr_t pci_bus_address(struct pci_dev *pdev, int bar)
06cf56e49   Bjorn Helgaas   PCI: Add pci_bus_...
1177
1178
1179
1180
1181
1182
  {
  	struct pci_bus_region region;
  
  	pcibios_resource_to_bus(pdev->bus, &region, &pdev->resource[bar]);
  	return region.start;
  }
863b18f4b   Laurent riffard   [PATCH] PCI: auto...
1183
  /* Proper probing supporting hot-pluggable devices */
725522b54   Greg Kroah-Hartman   PCI: add the sysf...
1184
1185
  int __must_check __pci_register_driver(struct pci_driver *, struct module *,
  				       const char *mod_name);
bba811658   Andrew Morton   PCI: make pci_reg...
1186
1187
1188
1189
1190
1191
  
  /*
   * pci_register_driver must be a macro so that KBUILD_MODNAME can be expanded
   */
  #define pci_register_driver(driver)		\
  	__pci_register_driver(driver, THIS_MODULE, KBUILD_MODNAME)
863b18f4b   Laurent riffard   [PATCH] PCI: auto...
1192

05cca6e52   Greg Kroah-Hartman   PCI: fix codingst...
1193
  void pci_unregister_driver(struct pci_driver *dev);
aad4f4000   Greg Kroah-Hartman   PCI: Add helper m...
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
  
  /**
   * module_pci_driver() - Helper macro for registering a PCI driver
   * @__pci_driver: pci_driver struct
   *
   * Helper macro for PCI drivers which do not do anything special in module
   * init/exit. This eliminates a lot of boilerplate. Each module may only
   * use this macro once, and calling it replaces module_init() and module_exit()
   */
  #define module_pci_driver(__pci_driver) \
  	module_driver(__pci_driver, pci_register_driver, \
  		       pci_unregister_driver)
b4eb6cdbb   Paul Gortmaker   PCI: Add builtin_...
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
  /**
   * builtin_pci_driver() - Helper macro for registering a PCI driver
   * @__pci_driver: pci_driver struct
   *
   * Helper macro for PCI drivers which do not do anything special in their
   * init code. This eliminates a lot of boilerplate. Each driver may only
   * use this macro once, and calling it replaces device_initcall(...)
   */
  #define builtin_pci_driver(__pci_driver) \
  	builtin_driver(__pci_driver, pci_register_driver)
05cca6e52   Greg Kroah-Hartman   PCI: fix codingst...
1216
  struct pci_driver *pci_dev_driver(const struct pci_dev *dev);
9dba910e9   Tejun Heo   PCI: separate out...
1217
1218
1219
1220
1221
  int pci_add_dynid(struct pci_driver *drv,
  		  unsigned int vendor, unsigned int device,
  		  unsigned int subvendor, unsigned int subdevice,
  		  unsigned int class, unsigned int class_mask,
  		  unsigned long driver_data);
05cca6e52   Greg Kroah-Hartman   PCI: fix codingst...
1222
1223
1224
1225
  const struct pci_device_id *pci_match_id(const struct pci_device_id *ids,
  					 struct pci_dev *dev);
  int pci_scan_bridge(struct pci_bus *bus, struct pci_dev *dev, int max,
  		    int pass);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1226

70298c6e6   Zhang, Yanmin   PCI AER: support ...
1227
  void pci_walk_bus(struct pci_bus *top, int (*cb)(struct pci_dev *, void *),
cecf4864c   Paul Mackerras   [PATCH] PCI: Add ...
1228
  		  void *userdata);
ac7dc65ac   Benjamin Herrenschmidt   [PATCH] PCI: Expo...
1229
  int pci_cfg_space_size(struct pci_dev *dev);
05cca6e52   Greg Kroah-Hartman   PCI: fix codingst...
1230
  unsigned char pci_bus_max_busnr(struct pci_bus *bus);
e24442733   Benjamin Herrenschmidt   PCI: Make pci_set...
1231
  void pci_setup_bridge(struct pci_bus *bus);
ac5ad93e9   Gavin Shan   PCI: Add weak pci...
1232
1233
  resource_size_t pcibios_window_alignment(struct pci_bus *bus,
  					 unsigned long type);
978d2d683   Wei Yang   PCI: Add pcibios_...
1234
  resource_size_t pcibios_iov_resource_alignment(struct pci_dev *dev, int resno);
cecf4864c   Paul Mackerras   [PATCH] PCI: Add ...
1235

3448a19da   Dave Airlie   vgaarb: use bridg...
1236
1237
  #define PCI_VGA_STATE_CHANGE_BRIDGE (1 << 0)
  #define PCI_VGA_STATE_CHANGE_DECODES (1 << 1)
deb2d2ecd   Benjamin Herrenschmidt   PCI/GPU: implemen...
1238
  int pci_set_vga_state(struct pci_dev *pdev, bool decode,
3448a19da   Dave Airlie   vgaarb: use bridg...
1239
  		      unsigned int command_bits, u32 flags);
fe537670e   Bjorn Helgaas   PCI: Consolidate ...
1240

4fe0d1548   Christoph Hellwig   PCI: Use positive...
1241
1242
1243
1244
1245
1246
  #define PCI_IRQ_LEGACY		(1 << 0) /* allow legacy interrupts */
  #define PCI_IRQ_MSI		(1 << 1) /* allow MSI interrupts */
  #define PCI_IRQ_MSIX		(1 << 2) /* allow MSI-X interrupts */
  #define PCI_IRQ_AFFINITY	(1 << 3) /* auto-assign affinity */
  #define PCI_IRQ_ALL_TYPES \
  	(PCI_IRQ_LEGACY | PCI_IRQ_MSI | PCI_IRQ_MSIX)
aff171641   Christoph Hellwig   PCI: Provide sens...
1247

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1248
  /* kmem_cache style wrapper around pci_alloc_consistent() */
f41b17715   FUJITA Tomonori   pci-dma: add linu...
1249
  #include <linux/pci-dma.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1250
1251
1252
1253
1254
1255
1256
  #include <linux/dmapool.h>
  
  #define	pci_pool dma_pool
  #define pci_pool_create(name, pdev, size, align, allocation) \
  		dma_pool_create(name, &pdev->dev, size, align, allocation)
  #define	pci_pool_destroy(pool) dma_pool_destroy(pool)
  #define	pci_pool_alloc(pool, flags, handle) dma_pool_alloc(pool, flags, handle)
01a7fd337   Sean O. Stalley   pci: mm: add pci_...
1257
1258
  #define	pci_pool_zalloc(pool, flags, handle) \
  		dma_pool_zalloc(pool, flags, handle)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1259
  #define	pci_pool_free(pool, vaddr, addr) dma_pool_free(pool, vaddr, addr)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1260
  struct msix_entry {
16dbef4a8   Yinghai Lu   PCI: change MSI-x...
1261
  	u32	vector;	/* kernel uses to write allocated vector */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1262
1263
  	u16	entry;	/* driver uses to specify entry, OS writes */
  };
4c8598042   Bjorn Helgaas   PCI: Reorder so a...
1264
1265
  #ifdef CONFIG_PCI_MSI
  int pci_msi_vec_count(struct pci_dev *dev);
f39d5b729   Bjorn Helgaas   PCI: Remove "exte...
1266
  void pci_disable_msi(struct pci_dev *dev);
4c8598042   Bjorn Helgaas   PCI: Reorder so a...
1267
  int pci_msix_vec_count(struct pci_dev *dev);
f39d5b729   Bjorn Helgaas   PCI: Remove "exte...
1268
  void pci_disable_msix(struct pci_dev *dev);
f39d5b729   Bjorn Helgaas   PCI: Remove "exte...
1269
1270
  void pci_restore_msi_state(struct pci_dev *dev);
  int pci_msi_enabled(void);
4fe039555   Christoph Hellwig   PCI/MSI: Remove p...
1271
  int pci_enable_msi(struct pci_dev *dev);
4c8598042   Bjorn Helgaas   PCI: Reorder so a...
1272
1273
  int pci_enable_msix_range(struct pci_dev *dev, struct msix_entry *entries,
  			  int minvec, int maxvec);
f7fc32cb2   Alexander Gordeev   PCI/MSI: Add pci_...
1274
1275
1276
1277
1278
1279
1280
1281
  static inline int pci_enable_msix_exact(struct pci_dev *dev,
  					struct msix_entry *entries, int nvec)
  {
  	int rc = pci_enable_msix_range(dev, entries, nvec, nvec);
  	if (rc < 0)
  		return rc;
  	return 0;
  }
402723ad5   Christoph Hellwig   PCI/MSI: Provide ...
1282
1283
1284
  int pci_alloc_irq_vectors_affinity(struct pci_dev *dev, unsigned int min_vecs,
  				   unsigned int max_vecs, unsigned int flags,
  				   const struct irq_affinity *affd);
aff171641   Christoph Hellwig   PCI: Provide sens...
1285
1286
  void pci_free_irq_vectors(struct pci_dev *dev);
  int pci_irq_vector(struct pci_dev *dev, unsigned int nr);
ee8d41e53   Thomas Gleixner   pci/msi: Retrieve...
1287
  const struct cpumask *pci_irq_get_affinity(struct pci_dev *pdev, int vec);
27ddb6899   Shaohua Li   PCI: add an API t...
1288
  int pci_irq_get_node(struct pci_dev *pdev, int vec);
aff171641   Christoph Hellwig   PCI: Provide sens...
1289

4c8598042   Bjorn Helgaas   PCI: Reorder so a...
1290
  #else
2ee546c4c   Bjorn Helgaas   PCI: Cleanup pci....
1291
  static inline int pci_msi_vec_count(struct pci_dev *dev) { return -ENOSYS; }
2ee546c4c   Bjorn Helgaas   PCI: Cleanup pci....
1292
1293
  static inline void pci_disable_msi(struct pci_dev *dev) { }
  static inline int pci_msix_vec_count(struct pci_dev *dev) { return -ENOSYS; }
2ee546c4c   Bjorn Helgaas   PCI: Cleanup pci....
1294
  static inline void pci_disable_msix(struct pci_dev *dev) { }
2ee546c4c   Bjorn Helgaas   PCI: Cleanup pci....
1295
1296
  static inline void pci_restore_msi_state(struct pci_dev *dev) { }
  static inline int pci_msi_enabled(void) { return 0; }
4fe039555   Christoph Hellwig   PCI/MSI: Remove p...
1297
  static inline int pci_enable_msi(struct pci_dev *dev)
f7fc32cb2   Alexander Gordeev   PCI/MSI: Add pci_...
1298
  { return -ENOSYS; }
302a2523c   Alexander Gordeev   PCI/MSI: Add pci_...
1299
1300
  static inline int pci_enable_msix_range(struct pci_dev *dev,
  		      struct msix_entry *entries, int minvec, int maxvec)
2ee546c4c   Bjorn Helgaas   PCI: Cleanup pci....
1301
  { return -ENOSYS; }
f7fc32cb2   Alexander Gordeev   PCI/MSI: Add pci_...
1302
1303
1304
  static inline int pci_enable_msix_exact(struct pci_dev *dev,
  		      struct msix_entry *entries, int nvec)
  { return -ENOSYS; }
402723ad5   Christoph Hellwig   PCI/MSI: Provide ...
1305
1306
1307
1308
1309
  
  static inline int
  pci_alloc_irq_vectors_affinity(struct pci_dev *dev, unsigned int min_vecs,
  			       unsigned int max_vecs, unsigned int flags,
  			       const struct irq_affinity *aff_desc)
aff171641   Christoph Hellwig   PCI: Provide sens...
1310
  {
83b4605b0   Christoph Hellwig   PCI/msi: fix the ...
1311
1312
1313
  	if ((flags & PCI_IRQ_LEGACY) && min_vecs == 1 && dev->irq)
  		return 1;
  	return -ENOSPC;
aff171641   Christoph Hellwig   PCI: Provide sens...
1314
  }
402723ad5   Christoph Hellwig   PCI/MSI: Provide ...
1315

aff171641   Christoph Hellwig   PCI: Provide sens...
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
  static inline void pci_free_irq_vectors(struct pci_dev *dev)
  {
  }
  
  static inline int pci_irq_vector(struct pci_dev *dev, unsigned int nr)
  {
  	if (WARN_ON_ONCE(nr > 0))
  		return -EINVAL;
  	return dev->irq;
  }
ee8d41e53   Thomas Gleixner   pci/msi: Retrieve...
1326
1327
1328
1329
1330
  static inline const struct cpumask *pci_irq_get_affinity(struct pci_dev *pdev,
  		int vec)
  {
  	return cpu_possible_mask;
  }
27ddb6899   Shaohua Li   PCI: add an API t...
1331
1332
1333
1334
1335
  
  static inline int pci_irq_get_node(struct pci_dev *pdev, int vec)
  {
  	return first_online_node;
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1336
  #endif
402723ad5   Christoph Hellwig   PCI/MSI: Provide ...
1337
1338
1339
1340
1341
1342
1343
  static inline int
  pci_alloc_irq_vectors(struct pci_dev *dev, unsigned int min_vecs,
  		      unsigned int max_vecs, unsigned int flags)
  {
  	return pci_alloc_irq_vectors_affinity(dev, min_vecs, max_vecs, flags,
  					      NULL);
  }
0d58e6c1b   Paul Burton   PCI: Add pci_irqd...
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
  /**
   * pci_irqd_intx_xlate() - Translate PCI INTx value to an IRQ domain hwirq
   * @d: the INTx IRQ domain
   * @node: the DT node for the device whose interrupt we're translating
   * @intspec: the interrupt specifier data from the DT
   * @intsize: the number of entries in @intspec
   * @out_hwirq: pointer at which to write the hwirq number
   * @out_type: pointer at which to write the interrupt type
   *
   * Translate a PCI INTx interrupt number from device tree in the range 1-4, as
   * stored in the standard PCI_INTERRUPT_PIN register, to a value in the range
   * 0-3 suitable for use in a 4 entry IRQ domain. That is, subtract one from the
   * INTx value to obtain the hwirq number.
   *
   * Returns 0 on success, or -EINVAL if the interrupt specifier is out of range.
   */
  static inline int pci_irqd_intx_xlate(struct irq_domain *d,
  				      struct device_node *node,
  				      const u32 *intspec,
  				      unsigned int intsize,
  				      unsigned long *out_hwirq,
  				      unsigned int *out_type)
  {
  	const u32 intx = intspec[0];
  
  	if (intx < PCI_INTERRUPT_INTA || intx > PCI_INTERRUPT_INTD)
  		return -EINVAL;
  
  	*out_hwirq = intx - PCI_INTERRUPT_INTA;
  	return 0;
  }
ab0724ffe   Markus Trippelsdorf   PCI / ACPI: Fix b...
1375
  #ifdef CONFIG_PCIEPORTBUS
415e12b23   Rafael J. Wysocki   PCI/ACPI: Request...
1376
1377
  extern bool pcie_ports_disabled;
  extern bool pcie_ports_auto;
ab0724ffe   Markus Trippelsdorf   PCI / ACPI: Fix b...
1378
1379
1380
1381
  #else
  #define pcie_ports_disabled	true
  #define pcie_ports_auto		false
  #endif
415e12b23   Rafael J. Wysocki   PCI/ACPI: Request...
1382

4c8598042   Bjorn Helgaas   PCI: Reorder so a...
1383
  #ifdef CONFIG_PCIEASPM
f39d5b729   Bjorn Helgaas   PCI: Remove "exte...
1384
  bool pcie_aspm_support_enabled(void);
4c8598042   Bjorn Helgaas   PCI: Reorder so a...
1385
1386
  #else
  static inline bool pcie_aspm_support_enabled(void) { return false; }
3e1b16002   Andrew Patterson   ACPI/PCI: PCIe AS...
1387
  #endif
415e12b23   Rafael J. Wysocki   PCI/ACPI: Request...
1388
1389
1390
  #ifdef CONFIG_PCIEAER
  void pci_no_aer(void);
  bool pci_aer_available(void);
66b808099   Keith Busch   PCI/AER: Cache ca...
1391
  int pci_aer_init(struct pci_dev *dev);
415e12b23   Rafael J. Wysocki   PCI/ACPI: Request...
1392
1393
1394
  #else
  static inline void pci_no_aer(void) { }
  static inline bool pci_aer_available(void) { return false; }
66b808099   Keith Busch   PCI/AER: Cache ca...
1395
  static inline int pci_aer_init(struct pci_dev *d) { return -ENODEV; }
415e12b23   Rafael J. Wysocki   PCI/ACPI: Request...
1396
  #endif
4c8598042   Bjorn Helgaas   PCI: Reorder so a...
1397
  #ifdef CONFIG_PCIE_ECRC
f39d5b729   Bjorn Helgaas   PCI: Remove "exte...
1398
1399
  void pcie_set_ecrc_checking(struct pci_dev *dev);
  void pcie_ecrc_get_policy(char *str);
4c8598042   Bjorn Helgaas   PCI: Reorder so a...
1400
  #else
2ee546c4c   Bjorn Helgaas   PCI: Cleanup pci....
1401
1402
  static inline void pcie_set_ecrc_checking(struct pci_dev *dev) { }
  static inline void pcie_ecrc_get_policy(char *str) { }
43c164088   Andrew Patterson   PCI: Add support ...
1403
  #endif
8b955b0dd   Eric W. Biederman   [PATCH] Initial g...
1404
  #ifdef CONFIG_HT_IRQ
8b955b0dd   Eric W. Biederman   [PATCH] Initial g...
1405
1406
1407
  /* The functions a driver should call */
  int  ht_create_irq(struct pci_dev *dev, int idx);
  void ht_destroy_irq(unsigned int irq);
8b955b0dd   Eric W. Biederman   [PATCH] Initial g...
1408
  #endif /* CONFIG_HT_IRQ */
edc90fee9   Bjorn Helgaas   PCI: Allocate ATS...
1409
1410
1411
  #ifdef CONFIG_PCI_ATS
  /* Address Translation Service */
  void pci_ats_init(struct pci_dev *dev);
ff9bee895   Bjorn Helgaas   PCI: Move ATS dec...
1412
1413
1414
  int pci_enable_ats(struct pci_dev *dev, int ps);
  void pci_disable_ats(struct pci_dev *dev);
  int pci_ats_queue_depth(struct pci_dev *dev);
edc90fee9   Bjorn Helgaas   PCI: Allocate ATS...
1415
  #else
ff9bee895   Bjorn Helgaas   PCI: Move ATS dec...
1416
1417
1418
1419
  static inline void pci_ats_init(struct pci_dev *d) { }
  static inline int pci_enable_ats(struct pci_dev *d, int ps) { return -ENODEV; }
  static inline void pci_disable_ats(struct pci_dev *d) { }
  static inline int pci_ats_queue_depth(struct pci_dev *d) { return -ENODEV; }
edc90fee9   Bjorn Helgaas   PCI: Allocate ATS...
1420
  #endif
eec097d43   Bjorn Helgaas   PCI: Add pci_enab...
1421
1422
1423
1424
1425
1426
  #ifdef CONFIG_PCIE_PTM
  int pci_enable_ptm(struct pci_dev *dev, u8 *granularity);
  #else
  static inline int pci_enable_ptm(struct pci_dev *dev, u8 *granularity)
  { return -EINVAL; }
  #endif
f39d5b729   Bjorn Helgaas   PCI: Remove "exte...
1427
1428
1429
  void pci_cfg_access_lock(struct pci_dev *dev);
  bool pci_cfg_access_trylock(struct pci_dev *dev);
  void pci_cfg_access_unlock(struct pci_dev *dev);
e04b0ea2e   Brian King   [PATCH] PCI: Bloc...
1430

4352dfd5c   Greg Kroah-Hartman   [PATCH] PCI: clea...
1431
1432
  /*
   * PCI domain support.  Sometimes called PCI segment (eg by ACPI),
f7625980f   Bjorn Helgaas   PCI: Fix whitespa...
1433
   * a PCI domain is defined to be a set of PCI buses which share
4352dfd5c   Greg Kroah-Hartman   [PATCH] PCI: clea...
1434
1435
   * configuration space.
   */
32a2eea79   Jeff Garzik   PCI: Add 'nodomai...
1436
1437
1438
1439
  #ifdef CONFIG_PCI_DOMAINS
  extern int pci_domains_supported;
  #else
  enum { pci_domains_supported = 0 };
2ee546c4c   Bjorn Helgaas   PCI: Cleanup pci....
1440
1441
  static inline int pci_domain_nr(struct pci_bus *bus) { return 0; }
  static inline int pci_proc_domain(struct pci_bus *bus) { return 0; }
32a2eea79   Jeff Garzik   PCI: Add 'nodomai...
1442
  #endif /* CONFIG_PCI_DOMAINS */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1443

670ba0c88   Catalin Marinas   PCI: Add generic ...
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
  /*
   * Generic implementation for PCI domain support. If your
   * architecture does not need custom management of PCI
   * domains then this implementation will be used
   */
  #ifdef CONFIG_PCI_DOMAINS_GENERIC
  static inline int pci_domain_nr(struct pci_bus *bus)
  {
  	return bus->domain_nr;
  }
2ab51ddec   Tomasz Nowicki   ARM64: PCI: Add a...
1454
1455
  #ifdef CONFIG_ACPI
  int acpi_pci_bus_find_domain_nr(struct pci_bus *bus);
670ba0c88   Catalin Marinas   PCI: Add generic ...
1456
  #else
2ab51ddec   Tomasz Nowicki   ARM64: PCI: Add a...
1457
1458
1459
  static inline int acpi_pci_bus_find_domain_nr(struct pci_bus *bus)
  { return 0; }
  #endif
9c7cb891e   Tomasz Nowicki   PCI: Refactor pci...
1460
  int pci_bus_find_domain_nr(struct pci_bus *bus, struct device *parent);
670ba0c88   Catalin Marinas   PCI: Add generic ...
1461
  #endif
95a8b6efc   Mike Travis   pci: Update pci_s...
1462
1463
  /* some architectures require additional setup to direct VGA traffic */
  typedef int (*arch_set_vga_state_t)(struct pci_dev *pdev, bool decode,
3448a19da   Dave Airlie   vgaarb: use bridg...
1464
  		      unsigned int command_bits, u32 flags);
f39d5b729   Bjorn Helgaas   PCI: Remove "exte...
1465
  void pci_register_set_vga_state(arch_set_vga_state_t func);
95a8b6efc   Mike Travis   pci: Update pci_s...
1466

be9d2e892   Johannes Thumshirn   PCI: Add helpers ...
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
  static inline int
  pci_request_io_regions(struct pci_dev *pdev, const char *name)
  {
  	return pci_request_selected_regions(pdev,
  			    pci_select_bars(pdev, IORESOURCE_IO), name);
  }
  
  static inline void
  pci_release_io_regions(struct pci_dev *pdev)
  {
  	return pci_release_selected_regions(pdev,
  			    pci_select_bars(pdev, IORESOURCE_IO));
  }
  
  static inline int
  pci_request_mem_regions(struct pci_dev *pdev, const char *name)
  {
  	return pci_request_selected_regions(pdev,
  			    pci_select_bars(pdev, IORESOURCE_MEM), name);
  }
  
  static inline void
  pci_release_mem_regions(struct pci_dev *pdev)
  {
  	return pci_release_selected_regions(pdev,
  			    pci_select_bars(pdev, IORESOURCE_MEM));
  }
4352dfd5c   Greg Kroah-Hartman   [PATCH] PCI: clea...
1494
  #else /* CONFIG_PCI is not enabled */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1495

5bbe029ff   Bjorn Helgaas   PCI: Move pci_set...
1496
1497
1498
1499
  static inline void pci_set_flags(int flags) { }
  static inline void pci_add_flags(int flags) { }
  static inline void pci_clear_flags(int flags) { }
  static inline int pci_has_flag(int flag) { return 0; }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1500
1501
1502
1503
  /*
   *  If the system does not have PCI, clearly these return errors.  Define
   *  these as simple inline functions to avoid hair in drivers.
   */
05cca6e52   Greg Kroah-Hartman   PCI: fix codingst...
1504
1505
1506
  #define _PCI_NOP(o, s, t) \
  	static inline int pci_##o##_config_##s(struct pci_dev *dev, \
  						int where, t val) \
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1507
  		{ return PCIBIOS_FUNC_NOT_SUPPORTED; }
05cca6e52   Greg Kroah-Hartman   PCI: fix codingst...
1508
1509
1510
1511
  
  #define _PCI_NOP_ALL(o, x)	_PCI_NOP(o, byte, u8 x) \
  				_PCI_NOP(o, word, u16 x) \
  				_PCI_NOP(o, dword, u32 x)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1512
1513
  _PCI_NOP_ALL(read, *)
  _PCI_NOP_ALL(write,)
d42552c3a   Andrew Morton   [PATCH] pci: decl...
1514
  static inline struct pci_dev *pci_get_device(unsigned int vendor,
05cca6e52   Greg Kroah-Hartman   PCI: fix codingst...
1515
1516
  					     unsigned int device,
  					     struct pci_dev *from)
2ee546c4c   Bjorn Helgaas   PCI: Cleanup pci....
1517
  { return NULL; }
d42552c3a   Andrew Morton   [PATCH] pci: decl...
1518

05cca6e52   Greg Kroah-Hartman   PCI: fix codingst...
1519
1520
1521
1522
  static inline struct pci_dev *pci_get_subsys(unsigned int vendor,
  					     unsigned int device,
  					     unsigned int ss_vendor,
  					     unsigned int ss_device,
b08508c40   Greg Kroah-Hartman   PCI: fix compiler...
1523
  					     struct pci_dev *from)
2ee546c4c   Bjorn Helgaas   PCI: Cleanup pci....
1524
  { return NULL; }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1525

05cca6e52   Greg Kroah-Hartman   PCI: fix codingst...
1526
1527
  static inline struct pci_dev *pci_get_class(unsigned int class,
  					    struct pci_dev *from)
2ee546c4c   Bjorn Helgaas   PCI: Cleanup pci....
1528
  { return NULL; }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1529
1530
  
  #define pci_dev_present(ids)	(0)
ed4aaadb1   Zhang, Yanmin   fix jvc cdrom dri...
1531
  #define no_pci_devices()	(1)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1532
  #define pci_dev_put(dev)	do { } while (0)
2ee546c4c   Bjorn Helgaas   PCI: Cleanup pci....
1533
1534
1535
  static inline void pci_set_master(struct pci_dev *dev) { }
  static inline int pci_enable_device(struct pci_dev *dev) { return -EIO; }
  static inline void pci_disable_device(struct pci_dev *dev) { }
05cca6e52   Greg Kroah-Hartman   PCI: fix codingst...
1536
  static inline int pci_assign_resource(struct pci_dev *dev, int i)
2ee546c4c   Bjorn Helgaas   PCI: Cleanup pci....
1537
  { return -EBUSY; }
05cca6e52   Greg Kroah-Hartman   PCI: fix codingst...
1538
1539
  static inline int __pci_register_driver(struct pci_driver *drv,
  					struct module *owner)
2ee546c4c   Bjorn Helgaas   PCI: Cleanup pci....
1540
  { return 0; }
05cca6e52   Greg Kroah-Hartman   PCI: fix codingst...
1541
  static inline int pci_register_driver(struct pci_driver *drv)
2ee546c4c   Bjorn Helgaas   PCI: Cleanup pci....
1542
1543
  { return 0; }
  static inline void pci_unregister_driver(struct pci_driver *drv) { }
05cca6e52   Greg Kroah-Hartman   PCI: fix codingst...
1544
  static inline int pci_find_capability(struct pci_dev *dev, int cap)
2ee546c4c   Bjorn Helgaas   PCI: Cleanup pci....
1545
  { return 0; }
05cca6e52   Greg Kroah-Hartman   PCI: fix codingst...
1546
1547
  static inline int pci_find_next_capability(struct pci_dev *dev, u8 post,
  					   int cap)
2ee546c4c   Bjorn Helgaas   PCI: Cleanup pci....
1548
  { return 0; }
05cca6e52   Greg Kroah-Hartman   PCI: fix codingst...
1549
  static inline int pci_find_ext_capability(struct pci_dev *dev, int cap)
2ee546c4c   Bjorn Helgaas   PCI: Cleanup pci....
1550
  { return 0; }
05cca6e52   Greg Kroah-Hartman   PCI: fix codingst...
1551

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1552
  /* Power management related routines */
2ee546c4c   Bjorn Helgaas   PCI: Cleanup pci....
1553
1554
  static inline int pci_save_state(struct pci_dev *dev) { return 0; }
  static inline void pci_restore_state(struct pci_dev *dev) { }
05cca6e52   Greg Kroah-Hartman   PCI: fix codingst...
1555
  static inline int pci_set_power_state(struct pci_dev *dev, pci_power_t state)
2ee546c4c   Bjorn Helgaas   PCI: Cleanup pci....
1556
  { return 0; }
3449248c8   Randy Dunlap   PCI: fix tlan bui...
1557
  static inline int pci_wake_from_d3(struct pci_dev *dev, bool enable)
2ee546c4c   Bjorn Helgaas   PCI: Cleanup pci....
1558
  { return 0; }
05cca6e52   Greg Kroah-Hartman   PCI: fix codingst...
1559
1560
  static inline pci_power_t pci_choose_state(struct pci_dev *dev,
  					   pm_message_t state)
2ee546c4c   Bjorn Helgaas   PCI: Cleanup pci....
1561
  { return PCI_D0; }
05cca6e52   Greg Kroah-Hartman   PCI: fix codingst...
1562
1563
  static inline int pci_enable_wake(struct pci_dev *dev, pci_power_t state,
  				  int enable)
2ee546c4c   Bjorn Helgaas   PCI: Cleanup pci....
1564
  { return 0; }
48a92a817   Jesse Barnes   PCI: add OBFF ena...
1565

afd29f901   Mika Westerberg   PCI: Add pci_find...
1566
1567
1568
  static inline struct resource *pci_find_resource(struct pci_dev *dev,
  						 struct resource *res)
  { return NULL; }
05cca6e52   Greg Kroah-Hartman   PCI: fix codingst...
1569
  static inline int pci_request_regions(struct pci_dev *dev, const char *res_name)
2ee546c4c   Bjorn Helgaas   PCI: Cleanup pci....
1570
1571
  { return -EIO; }
  static inline void pci_release_regions(struct pci_dev *dev) { }
0da0ead90   Sergei Shtylyov   PCI: define pci_r...
1572

c5076cfe7   Tomasz Nowicki   PCI, of: Move PCI...
1573
  static inline unsigned long pci_address_to_pio(phys_addr_t addr) { return -1; }
2ee546c4c   Bjorn Helgaas   PCI: Cleanup pci....
1574
  static inline void pci_block_cfg_access(struct pci_dev *dev) { }
fb51ccbf2   Jan Kiszka   PCI: Rework confi...
1575
1576
  static inline int pci_block_cfg_access_in_atomic(struct pci_dev *dev)
  { return 0; }
2ee546c4c   Bjorn Helgaas   PCI: Cleanup pci....
1577
  static inline void pci_unblock_cfg_access(struct pci_dev *dev) { }
e04b0ea2e   Brian King   [PATCH] PCI: Bloc...
1578

d80d02173   Randy Dunlap   pci.h stubs (for ...
1579
1580
  static inline struct pci_bus *pci_find_next_bus(const struct pci_bus *from)
  { return NULL; }
d80d02173   Randy Dunlap   pci.h stubs (for ...
1581
1582
1583
  static inline struct pci_dev *pci_get_slot(struct pci_bus *bus,
  						unsigned int devfn)
  { return NULL; }
d80d02173   Randy Dunlap   pci.h stubs (for ...
1584
1585
1586
  static inline struct pci_dev *pci_get_bus_and_slot(unsigned int bus,
  						unsigned int devfn)
  { return NULL; }
2ee546c4c   Bjorn Helgaas   PCI: Cleanup pci....
1587
1588
  static inline int pci_domain_nr(struct pci_bus *bus) { return 0; }
  static inline struct pci_dev *pci_dev_get(struct pci_dev *dev) { return NULL; }
12ea6cad1   Alex Williamson   PCI: add PCI DMA ...
1589

fb8a0d9d1   Williams, Mitch A   pci: Add SR-IOV c...
1590
1591
  #define dev_is_pci(d) (false)
  #define dev_is_pf(d) (false)
fe5949324   Geert Uytterhoeven   PCI: Add dummy pc...
1592
1593
  static inline bool pci_acs_enabled(struct pci_dev *pdev, u16 acs_flags)
  { return false; }
ebf5ffca1   Niklas Cassel   PCI: Add dummy pc...
1594
1595
1596
1597
1598
1599
1600
  static inline int pci_irqd_intx_xlate(struct irq_domain *d,
  				      struct device_node *node,
  				      const u32 *intspec,
  				      unsigned int intsize,
  				      unsigned long *out_hwirq,
  				      unsigned int *out_type)
  { return -EINVAL; }
4352dfd5c   Greg Kroah-Hartman   [PATCH] PCI: clea...
1601
  #endif /* CONFIG_PCI */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1602

4352dfd5c   Greg Kroah-Hartman   [PATCH] PCI: clea...
1603
1604
1605
  /* Include architecture-dependent settings and functions */
  
  #include <asm/pci.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1606

f71958243   David Woodhouse   PCI: Add pci_mmap...
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
  /* These two functions provide almost identical functionality. Depennding
   * on the architecture, one will be implemented as a wrapper around the
   * other (in drivers/pci/mmap.c).
   *
   * pci_mmap_resource_range() maps a specific BAR, and vm->vm_pgoff
   * is expected to be an offset within that region.
   *
   * pci_mmap_page_range() is the legacy architecture-specific interface,
   * which accepts a "user visible" resource address converted by
   * pci_resource_to_user(), as used in the legacy mmap() interface in
   * /proc/bus/pci/.
   */
  int pci_mmap_resource_range(struct pci_dev *dev, int bar,
  			    struct vm_area_struct *vma,
  			    enum pci_mmap_state mmap_state, int write_combine);
f66e22582   David Woodhouse   PCI: Add BAR inde...
1622
1623
  int pci_mmap_page_range(struct pci_dev *pdev, int bar,
  			struct vm_area_struct *vma,
11df19546   David Woodhouse   PCI: Move multipl...
1624
  			enum pci_mmap_state mmap_state, int write_combine);
ae749c7ab   David Woodhouse   PCI: Add arch_can...
1625
1626
1627
  #ifndef arch_can_pci_mmap_wc
  #define arch_can_pci_mmap_wc()		0
  #endif
2bea36fd1   David Woodhouse   PCI: Add I/O BAR ...
1628

e854d8b2a   David Woodhouse   PCI: Add arch_can...
1629
1630
  #ifndef arch_can_pci_mmap_io
  #define arch_can_pci_mmap_io()		0
2bea36fd1   David Woodhouse   PCI: Add I/O BAR ...
1631
1632
1633
  #define pci_iobar_pfn(pdev, bar, vma) (-EINVAL)
  #else
  int pci_iobar_pfn(struct pci_dev *pdev, int bar, struct vm_area_struct *vma);
e854d8b2a   David Woodhouse   PCI: Add arch_can...
1634
  #endif
ae749c7ab   David Woodhouse   PCI: Add arch_can...
1635

92016ba5c   Jake Oshins   PCI: Add fwnode_h...
1636
1637
1638
  #ifndef pci_root_bus_fwnode
  #define pci_root_bus_fwnode(bus)	NULL
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1639
1640
  /* these helpers provide future and backwards compatibility
   * for accessing popular PCI BAR info */
05cca6e52   Greg Kroah-Hartman   PCI: fix codingst...
1641
1642
1643
  #define pci_resource_start(dev, bar)	((dev)->resource[(bar)].start)
  #define pci_resource_end(dev, bar)	((dev)->resource[(bar)].end)
  #define pci_resource_flags(dev, bar)	((dev)->resource[(bar)].flags)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1644
  #define pci_resource_len(dev,bar) \
05cca6e52   Greg Kroah-Hartman   PCI: fix codingst...
1645
1646
1647
1648
1649
1650
  	((pci_resource_start((dev), (bar)) == 0 &&	\
  	  pci_resource_end((dev), (bar)) ==		\
  	  pci_resource_start((dev), (bar))) ? 0 :	\
  							\
  	 (pci_resource_end((dev), (bar)) -		\
  	  pci_resource_start((dev), (bar)) + 1))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1651
1652
1653
1654
1655
  
  /* Similar to the helpers above, these manipulate per-pci_dev
   * driver-specific data.  They are really just a wrapper around
   * the generic device structure functions of these calls.
   */
05cca6e52   Greg Kroah-Hartman   PCI: fix codingst...
1656
  static inline void *pci_get_drvdata(struct pci_dev *pdev)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1657
1658
1659
  {
  	return dev_get_drvdata(&pdev->dev);
  }
05cca6e52   Greg Kroah-Hartman   PCI: fix codingst...
1660
  static inline void pci_set_drvdata(struct pci_dev *pdev, void *data)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1661
1662
1663
1664
1665
1666
1667
  {
  	dev_set_drvdata(&pdev->dev, data);
  }
  
  /* If you want to know what to call your pci_dev, ask this function.
   * Again, it's a wrapper around the generic device.
   */
2fc90f613   Alexey Zaytsev   PCI: make pci_nam...
1668
  static inline const char *pci_name(const struct pci_dev *pdev)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1669
  {
c6c4f070a   Greg Kroah-Hartman   PCI: make pci_nam...
1670
  	return dev_name(&pdev->dev);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1671
  }
2311b1f2b   Michael Ellerman   [PATCH] PCI: fix-...
1672
1673
1674
1675
  
  /* Some archs don't want to expose struct resource to userland as-is
   * in sysfs and /proc
   */
8221a0135   Bjorn Helgaas   PCI: Unify pci_re...
1676
1677
1678
1679
1680
  #ifdef HAVE_ARCH_PCI_RESOURCE_TO_USER
  void pci_resource_to_user(const struct pci_dev *dev, int bar,
  			  const struct resource *rsrc,
  			  resource_size_t *start, resource_size_t *end);
  #else
2311b1f2b   Michael Ellerman   [PATCH] PCI: fix-...
1681
  static inline void pci_resource_to_user(const struct pci_dev *dev, int bar,
05cca6e52   Greg Kroah-Hartman   PCI: fix codingst...
1682
  		const struct resource *rsrc, resource_size_t *start,
e31dd6e45   Greg Kroah-Hartman   [PATCH] 64bit res...
1683
  		resource_size_t *end)
2311b1f2b   Michael Ellerman   [PATCH] PCI: fix-...
1684
1685
1686
1687
1688
  {
  	*start = rsrc->start;
  	*end = rsrc->end;
  }
  #endif /* HAVE_ARCH_PCI_RESOURCE_TO_USER */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1689
1690
1691
1692
1693
1694
1695
1696
  /*
   *  The world is not perfect and supplies us with broken PCI devices.
   *  For at least a part of these bugs we need a work-around, so both
   *  generic (drivers/pci/quirks.c) and per-architecture code can define
   *  fixup hooks to be called for particular buggy devices.
   */
  
  struct pci_fixup {
f4ca5c6a5   Yinghai Lu   PCI: Add class su...
1697
1698
1699
1700
  	u16 vendor;		/* You can use PCI_ANY_ID here of course */
  	u16 device;		/* You can use PCI_ANY_ID here of course */
  	u32 class;		/* You can use PCI_ANY_ID here too */
  	unsigned int class_shift;	/* should be 0, 8, 16 */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1701
1702
1703
1704
1705
1706
1707
1708
  	void (*hook)(struct pci_dev *dev);
  };
  
  enum pci_fixup_pass {
  	pci_fixup_early,	/* Before probing BARs */
  	pci_fixup_header,	/* After reading configuration header */
  	pci_fixup_final,	/* Final phase of device fixups */
  	pci_fixup_enable,	/* pci_enable_device() time */
e1a2a51e6   Rafael J. Wysocki   Suspend/Resume bu...
1709
  	pci_fixup_resume,	/* pci_device_resume() */
7d2a01b87   Andreas Noever   PCI: Add pci_fixu...
1710
  	pci_fixup_suspend,	/* pci_device_suspend() */
e1a2a51e6   Rafael J. Wysocki   Suspend/Resume bu...
1711
  	pci_fixup_resume_early, /* pci_device_resume_early() */
7d2a01b87   Andreas Noever   PCI: Add pci_fixu...
1712
  	pci_fixup_suspend_late,	/* pci_device_suspend_late() */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1713
1714
1715
  };
  
  /* Anonymous variables would be nice... */
f4ca5c6a5   Yinghai Lu   PCI: Add class su...
1716
1717
  #define DECLARE_PCI_FIXUP_SECTION(section, name, vendor, device, class,	\
  				  class_shift, hook)			\
ecf61c78b   Michal Marek   PCI: Omit PCI ID ...
1718
  	static const struct pci_fixup __PASTE(__pci_fixup_##name,__LINE__) __used	\
f4ca5c6a5   Yinghai Lu   PCI: Add class su...
1719
1720
1721
1722
1723
1724
  	__attribute__((__section__(#section), aligned((sizeof(void *)))))    \
  		= { vendor, device, class, class_shift, hook };
  
  #define DECLARE_PCI_FIXUP_CLASS_EARLY(vendor, device, class,		\
  					 class_shift, hook)		\
  	DECLARE_PCI_FIXUP_SECTION(.pci_fixup_early,			\
ecf61c78b   Michal Marek   PCI: Omit PCI ID ...
1725
  		hook, vendor, device, class, class_shift, hook)
f4ca5c6a5   Yinghai Lu   PCI: Add class su...
1726
1727
1728
  #define DECLARE_PCI_FIXUP_CLASS_HEADER(vendor, device, class,		\
  					 class_shift, hook)		\
  	DECLARE_PCI_FIXUP_SECTION(.pci_fixup_header,			\
ecf61c78b   Michal Marek   PCI: Omit PCI ID ...
1729
  		hook, vendor, device, class, class_shift, hook)
f4ca5c6a5   Yinghai Lu   PCI: Add class su...
1730
1731
1732
  #define DECLARE_PCI_FIXUP_CLASS_FINAL(vendor, device, class,		\
  					 class_shift, hook)		\
  	DECLARE_PCI_FIXUP_SECTION(.pci_fixup_final,			\
ecf61c78b   Michal Marek   PCI: Omit PCI ID ...
1733
  		hook, vendor, device, class, class_shift, hook)
f4ca5c6a5   Yinghai Lu   PCI: Add class su...
1734
1735
1736
  #define DECLARE_PCI_FIXUP_CLASS_ENABLE(vendor, device, class,		\
  					 class_shift, hook)		\
  	DECLARE_PCI_FIXUP_SECTION(.pci_fixup_enable,			\
ecf61c78b   Michal Marek   PCI: Omit PCI ID ...
1737
  		hook, vendor, device, class, class_shift, hook)
f4ca5c6a5   Yinghai Lu   PCI: Add class su...
1738
1739
1740
  #define DECLARE_PCI_FIXUP_CLASS_RESUME(vendor, device, class,		\
  					 class_shift, hook)		\
  	DECLARE_PCI_FIXUP_SECTION(.pci_fixup_resume,			\
ecf61c78b   Michal Marek   PCI: Omit PCI ID ...
1741
  		resume##hook, vendor, device, class,	\
f4ca5c6a5   Yinghai Lu   PCI: Add class su...
1742
1743
1744
1745
  		class_shift, hook)
  #define DECLARE_PCI_FIXUP_CLASS_RESUME_EARLY(vendor, device, class,	\
  					 class_shift, hook)		\
  	DECLARE_PCI_FIXUP_SECTION(.pci_fixup_resume_early,		\
ecf61c78b   Michal Marek   PCI: Omit PCI ID ...
1746
  		resume_early##hook, vendor, device,	\
f4ca5c6a5   Yinghai Lu   PCI: Add class su...
1747
1748
1749
1750
  		class, class_shift, hook)
  #define DECLARE_PCI_FIXUP_CLASS_SUSPEND(vendor, device, class,		\
  					 class_shift, hook)		\
  	DECLARE_PCI_FIXUP_SECTION(.pci_fixup_suspend,			\
ecf61c78b   Michal Marek   PCI: Omit PCI ID ...
1751
  		suspend##hook, vendor, device, class,	\
f4ca5c6a5   Yinghai Lu   PCI: Add class su...
1752
  		class_shift, hook)
7d2a01b87   Andreas Noever   PCI: Add pci_fixu...
1753
1754
1755
1756
1757
  #define DECLARE_PCI_FIXUP_CLASS_SUSPEND_LATE(vendor, device, class,	\
  					 class_shift, hook)		\
  	DECLARE_PCI_FIXUP_SECTION(.pci_fixup_suspend_late,		\
  		suspend_late##hook, vendor, device,	\
  		class, class_shift, hook)
f4ca5c6a5   Yinghai Lu   PCI: Add class su...
1758

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1759
1760
  #define DECLARE_PCI_FIXUP_EARLY(vendor, device, hook)			\
  	DECLARE_PCI_FIXUP_SECTION(.pci_fixup_early,			\
ecf61c78b   Michal Marek   PCI: Omit PCI ID ...
1761
  		hook, vendor, device, PCI_ANY_ID, 0, hook)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1762
1763
  #define DECLARE_PCI_FIXUP_HEADER(vendor, device, hook)			\
  	DECLARE_PCI_FIXUP_SECTION(.pci_fixup_header,			\
ecf61c78b   Michal Marek   PCI: Omit PCI ID ...
1764
  		hook, vendor, device, PCI_ANY_ID, 0, hook)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1765
1766
  #define DECLARE_PCI_FIXUP_FINAL(vendor, device, hook)			\
  	DECLARE_PCI_FIXUP_SECTION(.pci_fixup_final,			\
ecf61c78b   Michal Marek   PCI: Omit PCI ID ...
1767
  		hook, vendor, device, PCI_ANY_ID, 0, hook)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1768
1769
  #define DECLARE_PCI_FIXUP_ENABLE(vendor, device, hook)			\
  	DECLARE_PCI_FIXUP_SECTION(.pci_fixup_enable,			\
ecf61c78b   Michal Marek   PCI: Omit PCI ID ...
1770
  		hook, vendor, device, PCI_ANY_ID, 0, hook)
1597cacbe   Alan Cox   PCI: Fix multiple...
1771
1772
  #define DECLARE_PCI_FIXUP_RESUME(vendor, device, hook)			\
  	DECLARE_PCI_FIXUP_SECTION(.pci_fixup_resume,			\
ecf61c78b   Michal Marek   PCI: Omit PCI ID ...
1773
  		resume##hook, vendor, device,		\
f4ca5c6a5   Yinghai Lu   PCI: Add class su...
1774
  		PCI_ANY_ID, 0, hook)
e1a2a51e6   Rafael J. Wysocki   Suspend/Resume bu...
1775
1776
  #define DECLARE_PCI_FIXUP_RESUME_EARLY(vendor, device, hook)		\
  	DECLARE_PCI_FIXUP_SECTION(.pci_fixup_resume_early,		\
ecf61c78b   Michal Marek   PCI: Omit PCI ID ...
1777
  		resume_early##hook, vendor, device,	\
f4ca5c6a5   Yinghai Lu   PCI: Add class su...
1778
  		PCI_ANY_ID, 0, hook)
e1a2a51e6   Rafael J. Wysocki   Suspend/Resume bu...
1779
1780
  #define DECLARE_PCI_FIXUP_SUSPEND(vendor, device, hook)			\
  	DECLARE_PCI_FIXUP_SECTION(.pci_fixup_suspend,			\
ecf61c78b   Michal Marek   PCI: Omit PCI ID ...
1781
  		suspend##hook, vendor, device,		\
f4ca5c6a5   Yinghai Lu   PCI: Add class su...
1782
  		PCI_ANY_ID, 0, hook)
7d2a01b87   Andreas Noever   PCI: Add pci_fixu...
1783
1784
1785
1786
  #define DECLARE_PCI_FIXUP_SUSPEND_LATE(vendor, device, hook)		\
  	DECLARE_PCI_FIXUP_SECTION(.pci_fixup_suspend_late,		\
  		suspend_late##hook, vendor, device,	\
  		PCI_ANY_ID, 0, hook)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1787

93177a748   Rafael J. Wysocki   PCI: Clean up bui...
1788
  #ifdef CONFIG_PCI_QUIRKS
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1789
  void pci_fixup_device(enum pci_fixup_pass pass, struct pci_dev *dev);
ad805758c   Alex Williamson   PCI: add ACS vali...
1790
  int pci_dev_specific_acs_enabled(struct pci_dev *dev, u16 acs_flags);
c1d61c9bb   Alex Williamson   PCI: Reverse stan...
1791
  int pci_dev_specific_enable_acs(struct pci_dev *dev);
93177a748   Rafael J. Wysocki   PCI: Clean up bui...
1792
1793
  #else
  static inline void pci_fixup_device(enum pci_fixup_pass pass,
2ee546c4c   Bjorn Helgaas   PCI: Cleanup pci....
1794
  				    struct pci_dev *dev) { }
ad805758c   Alex Williamson   PCI: add ACS vali...
1795
1796
1797
1798
1799
  static inline int pci_dev_specific_acs_enabled(struct pci_dev *dev,
  					       u16 acs_flags)
  {
  	return -ENOTTY;
  }
c1d61c9bb   Alex Williamson   PCI: Reverse stan...
1800
1801
1802
1803
  static inline int pci_dev_specific_enable_acs(struct pci_dev *dev)
  {
  	return -ENOTTY;
  }
93177a748   Rafael J. Wysocki   PCI: Clean up bui...
1804
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1805

05cca6e52   Greg Kroah-Hartman   PCI: fix codingst...
1806
  void __iomem *pcim_iomap(struct pci_dev *pdev, int bar, unsigned long maxlen);
5ea817699   Al Viro   [PATCH] sort the ...
1807
  void pcim_iounmap(struct pci_dev *pdev, void __iomem *addr);
05cca6e52   Greg Kroah-Hartman   PCI: fix codingst...
1808
  void __iomem * const *pcim_iomap_table(struct pci_dev *pdev);
fb7ebfe41   Yinghai Lu   PCI: Increase res...
1809
1810
  int pcim_iomap_regions(struct pci_dev *pdev, int mask, const char *name);
  int pcim_iomap_regions_request_all(struct pci_dev *pdev, int mask,
916fbfb7a   Tejun Heo   devres: implement...
1811
  				   const char *name);
fb7ebfe41   Yinghai Lu   PCI: Increase res...
1812
  void pcim_iounmap_regions(struct pci_dev *pdev, int mask);
5ea817699   Al Viro   [PATCH] sort the ...
1813

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1814
  extern int pci_pci_problems;
236561e5d   Alan Cox   [PATCH] PCI quirk...
1815
  #define PCIPCI_FAIL		1	/* No PCI PCI DMA */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1816
1817
1818
1819
  #define PCIPCI_TRITON		2
  #define PCIPCI_NATOMA		4
  #define PCIPCI_VIAETBF		8
  #define PCIPCI_VSFX		16
236561e5d   Alan Cox   [PATCH] PCI quirk...
1820
1821
  #define PCIPCI_ALIMAGIK		32	/* Need low latency setting */
  #define PCIAGP_FAIL		64	/* No PCI to AGP DMA */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1822

4516a618a   Atsushi Nemoto   PCI: Make CARDBUS...
1823
1824
  extern unsigned long pci_cardbus_io_size;
  extern unsigned long pci_cardbus_mem_size;
15856ad50   Bill Pemberton   PCI: Remove __dev...
1825
  extern u8 pci_dfl_cache_line_size;
ac1aa47b1   Jesse Barnes   PCI: determine CL...
1826
  extern u8 pci_cache_line_size;
4516a618a   Atsushi Nemoto   PCI: Make CARDBUS...
1827

28760489a   Eric W. Biederman   PCI: pcie: Ensure...
1828
1829
  extern unsigned long pci_hotplug_io_size;
  extern unsigned long pci_hotplug_mem_size;
e16b46605   Keith Busch   PCI: Allow additi...
1830
  extern unsigned long pci_hotplug_bus_size;
28760489a   Eric W. Biederman   PCI: pcie: Ensure...
1831

f7625980f   Bjorn Helgaas   PCI: Fix whitespa...
1832
  /* Architecture-specific versions may override these (weak) */
19792a085   Adrian Bunk   PCI: drivers/pci/...
1833
  void pcibios_disable_device(struct pci_dev *dev);
cfce9fb80   Myron Stowe   PCI: add declarat...
1834
  void pcibios_set_master(struct pci_dev *dev);
19792a085   Adrian Bunk   PCI: drivers/pci/...
1835
1836
  int pcibios_set_pcie_reset_state(struct pci_dev *dev,
  				 enum pcie_reset_state state);
eca0d4676   Matthew Garrett   PCI: Add pcibios_...
1837
  int pcibios_add_device(struct pci_dev *dev);
6ae32c539   Sebastian Ott   PCI: Add pcibios_...
1838
  void pcibios_release_device(struct pci_dev *dev);
a43ae58c8   Hanjun Guo   PCI: Turn pcibios...
1839
  void pcibios_penalize_isa_irq(int irq, int active);
890e48475   Jiang Liu   PCI: Add pcibios_...
1840
1841
  int pcibios_alloc_irq(struct pci_dev *dev);
  void pcibios_free_irq(struct pci_dev *dev);
575e3348c   Michael Ellerman   PCI: Use a weak s...
1842

699c19855   Sebastian Ott   PCI: Add pcibios_...
1843
1844
1845
  #ifdef CONFIG_HIBERNATE_CALLBACKS
  extern struct dev_pm_ops pcibios_pm_ops;
  #endif
935c760ec   Tomasz Nowicki   PCI/ACPI: Add gen...
1846
  #if defined(CONFIG_PCI_MMCONFIG) || defined(CONFIG_ACPI_MCFG)
f39d5b729   Bjorn Helgaas   PCI: Remove "exte...
1847
1848
  void __init pci_mmcfg_early_init(void);
  void __init pci_mmcfg_late_init(void);
7752d5cfe   Robert Hancock   x86: validate aga...
1849
  #else
bb63b4219   Yinghai Lu   x86 pci: remove c...
1850
  static inline void pci_mmcfg_early_init(void) { }
7752d5cfe   Robert Hancock   x86: validate aga...
1851
1852
  static inline void pci_mmcfg_late_init(void) { }
  #endif
642c92da3   Taku Izumi   PCI: Don't pass p...
1853
  int pci_ext_cfg_avail(void);
0ef5f8f61   Andrew Patterson   ACPI/PCI: PCI ext...
1854

1684f5ddd   Andrew Morton   PCI: uninline pci...
1855
  void __iomem *pci_ioremap_bar(struct pci_dev *pdev, int bar);
c43996f40   Luis R. Rodriguez   PCI: Add pci_iore...
1856
  void __iomem *pci_ioremap_wc_bar(struct pci_dev *pdev, int bar);
aa42d7c61   Arjan van de Ven   PCI: introduce an...
1857

dd7cc44d0   Yu Zhao   PCI: add SR-IOV A...
1858
  #ifdef CONFIG_PCI_IOV
b07579c09   Wei Yang   PCI: Export pci_i...
1859
1860
  int pci_iov_virtfn_bus(struct pci_dev *dev, int id);
  int pci_iov_virtfn_devfn(struct pci_dev *dev, int id);
f39d5b729   Bjorn Helgaas   PCI: Remove "exte...
1861
1862
  int pci_enable_sriov(struct pci_dev *dev, int nr_virtfn);
  void pci_disable_sriov(struct pci_dev *dev);
c194f7ea7   Wei Yang   PCI/IOV: Rename a...
1863
1864
  int pci_iov_add_virtfn(struct pci_dev *dev, int id, int reset);
  void pci_iov_remove_virtfn(struct pci_dev *dev, int id, int reset);
f39d5b729   Bjorn Helgaas   PCI: Remove "exte...
1865
  int pci_num_vf(struct pci_dev *dev);
5a8eb2429   Alexander Duyck   pci: Add SRIOV he...
1866
  int pci_vfs_assigned(struct pci_dev *dev);
f39d5b729   Bjorn Helgaas   PCI: Remove "exte...
1867
1868
  int pci_sriov_set_totalvfs(struct pci_dev *dev, u16 numvfs);
  int pci_sriov_get_totalvfs(struct pci_dev *dev);
0e6c9122a   Wei Yang   PCI: Keep individ...
1869
  resource_size_t pci_iov_resource_size(struct pci_dev *dev, int resno);
dd7cc44d0   Yu Zhao   PCI: add SR-IOV A...
1870
  #else
b07579c09   Wei Yang   PCI: Export pci_i...
1871
1872
1873
1874
1875
1876
1877
1878
  static inline int pci_iov_virtfn_bus(struct pci_dev *dev, int id)
  {
  	return -ENOSYS;
  }
  static inline int pci_iov_virtfn_devfn(struct pci_dev *dev, int id)
  {
  	return -ENOSYS;
  }
dd7cc44d0   Yu Zhao   PCI: add SR-IOV A...
1879
  static inline int pci_enable_sriov(struct pci_dev *dev, int nr_virtfn)
2ee546c4c   Bjorn Helgaas   PCI: Cleanup pci....
1880
  { return -ENODEV; }
c194f7ea7   Wei Yang   PCI/IOV: Rename a...
1881
1882
1883
1884
1885
1886
  static inline int pci_iov_add_virtfn(struct pci_dev *dev, int id, int reset)
  {
  	return -ENOSYS;
  }
  static inline void pci_iov_remove_virtfn(struct pci_dev *dev,
  					 int id, int reset) { }
2ee546c4c   Bjorn Helgaas   PCI: Cleanup pci....
1887
  static inline void pci_disable_sriov(struct pci_dev *dev) { }
2ee546c4c   Bjorn Helgaas   PCI: Cleanup pci....
1888
  static inline int pci_num_vf(struct pci_dev *dev) { return 0; }
5a8eb2429   Alexander Duyck   pci: Add SRIOV he...
1889
  static inline int pci_vfs_assigned(struct pci_dev *dev)
2ee546c4c   Bjorn Helgaas   PCI: Cleanup pci....
1890
  { return 0; }
bff73156d   Donald Dutile   PCI: Provide meth...
1891
  static inline int pci_sriov_set_totalvfs(struct pci_dev *dev, u16 numvfs)
2ee546c4c   Bjorn Helgaas   PCI: Cleanup pci....
1892
  { return 0; }
bff73156d   Donald Dutile   PCI: Provide meth...
1893
  static inline int pci_sriov_get_totalvfs(struct pci_dev *dev)
2ee546c4c   Bjorn Helgaas   PCI: Cleanup pci....
1894
  { return 0; }
0e6c9122a   Wei Yang   PCI: Keep individ...
1895
1896
  static inline resource_size_t pci_iov_resource_size(struct pci_dev *dev, int resno)
  { return 0; }
dd7cc44d0   Yu Zhao   PCI: add SR-IOV A...
1897
  #endif
c825bc94c   Kenji Kaneshige   PCI hotplug: crea...
1898
  #if defined(CONFIG_HOTPLUG_PCI) || defined(CONFIG_HOTPLUG_PCI_MODULE)
f39d5b729   Bjorn Helgaas   PCI: Remove "exte...
1899
1900
  void pci_hp_create_module_link(struct pci_slot *pci_slot);
  void pci_hp_remove_module_link(struct pci_slot *pci_slot);
c825bc94c   Kenji Kaneshige   PCI hotplug: crea...
1901
  #endif
d7b7e6052   Kenji Kaneshige   PCI: introduce pc...
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
  /**
   * pci_pcie_cap - get the saved PCIe capability offset
   * @dev: PCI device
   *
   * PCIe capability offset is calculated at PCI device initialization
   * time and saved in the data structure. This function returns saved
   * PCIe capability offset. Using this instead of pci_find_capability()
   * reduces unnecessary search in the PCI configuration space. If you
   * need to calculate PCIe capability offset from raw device for some
   * reasons, please use pci_find_capability() instead.
   */
  static inline int pci_pcie_cap(struct pci_dev *dev)
  {
  	return dev->pcie_cap;
  }
7eb776c42   Kenji Kaneshige   PCI: introduce pc...
1917
1918
1919
1920
  /**
   * pci_is_pcie - check if the PCI device is PCI Express capable
   * @dev: PCI device
   *
a895c28a1   Joe Perches   PCI: Fix comment ...
1921
   * Returns: true if the PCI device is PCI Express capable, false otherwise.
7eb776c42   Kenji Kaneshige   PCI: introduce pc...
1922
1923
1924
   */
  static inline bool pci_is_pcie(struct pci_dev *dev)
  {
a895c28a1   Joe Perches   PCI: Fix comment ...
1925
  	return pci_pcie_cap(dev);
7eb776c42   Kenji Kaneshige   PCI: introduce pc...
1926
  }
786e22885   Yijing Wang   PCI: Add pcie_fla...
1927
  /**
7c9c003c6   Myron Stowe   PCI: Introduce ac...
1928
1929
1930
1931
1932
1933
1934
1935
1936
   * pcie_caps_reg - get the PCIe Capabilities Register
   * @dev: PCI device
   */
  static inline u16 pcie_caps_reg(const struct pci_dev *dev)
  {
  	return dev->pcie_flags_reg;
  }
  
  /**
786e22885   Yijing Wang   PCI: Add pcie_fla...
1937
1938
1939
1940
1941
   * pci_pcie_type - get the PCIe device/port type
   * @dev: PCI device
   */
  static inline int pci_pcie_type(const struct pci_dev *dev)
  {
1c531d82e   Myron Stowe   PCI: Use PCI Expr...
1942
  	return (pcie_caps_reg(dev) & PCI_EXP_FLAGS_TYPE) >> 4;
786e22885   Yijing Wang   PCI: Add pcie_fla...
1943
  }
e784930bd   Johannes Thumshirn   PCI: Export pcie_...
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
  static inline struct pci_dev *pcie_find_root_port(struct pci_dev *dev)
  {
  	while (1) {
  		if (!pci_is_pcie(dev))
  			break;
  		if (pci_pcie_type(dev) == PCI_EXP_TYPE_ROOT_PORT)
  			return dev;
  		if (!dev->bus->self)
  			break;
  		dev = dev->bus->self;
  	}
  	return NULL;
  }
5d990b627   Chris Wright   PCI: add pci_requ...
1957
  void pci_request_acs(void);
ad805758c   Alex Williamson   PCI: add ACS vali...
1958
1959
1960
  bool pci_acs_enabled(struct pci_dev *pdev, u16 acs_flags);
  bool pci_acs_path_enabled(struct pci_dev *start,
  			  struct pci_dev *end, u16 acs_flags);
a2ce76623   Matt Carlson   pci: Add PCI LRDT...
1961

7ad506fa1   Matt Carlson   pci: Add large an...
1962
  #define PCI_VPD_LRDT			0x80	/* Large Resource Data Type */
63ddc0b8f   Megan Kamiya   PCI: Parenthesize...
1963
  #define PCI_VPD_LRDT_ID(x)		((x) | PCI_VPD_LRDT)
7ad506fa1   Matt Carlson   pci: Add large an...
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
  
  /* Large Resource Data Type Tag Item Names */
  #define PCI_VPD_LTIN_ID_STRING		0x02	/* Identifier String */
  #define PCI_VPD_LTIN_RO_DATA		0x10	/* Read-Only Data */
  #define PCI_VPD_LTIN_RW_DATA		0x11	/* Read-Write Data */
  
  #define PCI_VPD_LRDT_ID_STRING		PCI_VPD_LRDT_ID(PCI_VPD_LTIN_ID_STRING)
  #define PCI_VPD_LRDT_RO_DATA		PCI_VPD_LRDT_ID(PCI_VPD_LTIN_RO_DATA)
  #define PCI_VPD_LRDT_RW_DATA		PCI_VPD_LRDT_ID(PCI_VPD_LTIN_RW_DATA)
  
  /* Small Resource Data Type Tag Item Names */
9eb45d5cc   Hannes Reinecke   PCI: Update VPD d...
1975
  #define PCI_VPD_STIN_END		0x0f	/* End */
7ad506fa1   Matt Carlson   pci: Add large an...
1976

9eb45d5cc   Hannes Reinecke   PCI: Update VPD d...
1977
  #define PCI_VPD_SRDT_END		(PCI_VPD_STIN_END << 3)
7ad506fa1   Matt Carlson   pci: Add large an...
1978
1979
1980
  
  #define PCI_VPD_SRDT_TIN_MASK		0x78
  #define PCI_VPD_SRDT_LEN_MASK		0x07
9eb45d5cc   Hannes Reinecke   PCI: Update VPD d...
1981
  #define PCI_VPD_LRDT_TIN_MASK		0x7f
7ad506fa1   Matt Carlson   pci: Add large an...
1982
1983
1984
  
  #define PCI_VPD_LRDT_TAG_SIZE		3
  #define PCI_VPD_SRDT_TAG_SIZE		1
a2ce76623   Matt Carlson   pci: Add PCI LRDT...
1985

e1d5bdabb   Matt Carlson   pci: Add VPD info...
1986
  #define PCI_VPD_INFO_FLD_HDR_SIZE	3
4067a8541   Matt Carlson   pci: Add helper t...
1987
1988
1989
  #define PCI_VPD_RO_KEYWORD_PARTNO	"PN"
  #define PCI_VPD_RO_KEYWORD_MFR_ID	"MN"
  #define PCI_VPD_RO_KEYWORD_VENDOR0	"V0"
d4894f3ea   Matt Carlson   tg3: Add code to ...
1990
  #define PCI_VPD_RO_KEYWORD_CHKSUM	"RV"
4067a8541   Matt Carlson   pci: Add helper t...
1991

a2ce76623   Matt Carlson   pci: Add PCI LRDT...
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
  /**
   * pci_vpd_lrdt_size - Extracts the Large Resource Data Type length
   * @lrdt: Pointer to the beginning of the Large Resource Data Type tag
   *
   * Returns the extracted Large Resource Data Type length.
   */
  static inline u16 pci_vpd_lrdt_size(const u8 *lrdt)
  {
  	return (u16)lrdt[1] + ((u16)lrdt[2] << 8);
  }
7ad506fa1   Matt Carlson   pci: Add large an...
2002
  /**
9eb45d5cc   Hannes Reinecke   PCI: Update VPD d...
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
   * pci_vpd_lrdt_tag - Extracts the Large Resource Data Type Tag Item
   * @lrdt: Pointer to the beginning of the Large Resource Data Type tag
   *
   * Returns the extracted Large Resource Data Type Tag item.
   */
  static inline u16 pci_vpd_lrdt_tag(const u8 *lrdt)
  {
      return (u16)(lrdt[0] & PCI_VPD_LRDT_TIN_MASK);
  }
  
  /**
7ad506fa1   Matt Carlson   pci: Add large an...
2014
   * pci_vpd_srdt_size - Extracts the Small Resource Data Type length
0142626d0   Shawn Lin   PCI: Correct kern...
2015
   * @srdt: Pointer to the beginning of the Small Resource Data Type tag
7ad506fa1   Matt Carlson   pci: Add large an...
2016
2017
2018
2019
2020
2021
2022
   *
   * Returns the extracted Small Resource Data Type length.
   */
  static inline u8 pci_vpd_srdt_size(const u8 *srdt)
  {
  	return (*srdt) & PCI_VPD_SRDT_LEN_MASK;
  }
b55ac1b22   Matt Carlson   pci: Add helper t...
2023
  /**
9eb45d5cc   Hannes Reinecke   PCI: Update VPD d...
2024
   * pci_vpd_srdt_tag - Extracts the Small Resource Data Type Tag Item
0142626d0   Shawn Lin   PCI: Correct kern...
2025
   * @srdt: Pointer to the beginning of the Small Resource Data Type tag
9eb45d5cc   Hannes Reinecke   PCI: Update VPD d...
2026
2027
2028
2029
2030
2031
2032
2033
2034
   *
   * Returns the extracted Small Resource Data Type Tag Item.
   */
  static inline u8 pci_vpd_srdt_tag(const u8 *srdt)
  {
  	return ((*srdt) & PCI_VPD_SRDT_TIN_MASK) >> 3;
  }
  
  /**
e1d5bdabb   Matt Carlson   pci: Add VPD info...
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
   * pci_vpd_info_field_size - Extracts the information field length
   * @lrdt: Pointer to the beginning of an information field header
   *
   * Returns the extracted information field length.
   */
  static inline u8 pci_vpd_info_field_size(const u8 *info_field)
  {
  	return info_field[2];
  }
  
  /**
b55ac1b22   Matt Carlson   pci: Add helper t...
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
   * pci_vpd_find_tag - Locates the Resource Data Type tag provided
   * @buf: Pointer to buffered vpd data
   * @off: The offset into the buffer at which to begin the search
   * @len: The length of the vpd buffer
   * @rdt: The Resource Data Type to search for
   *
   * Returns the index where the Resource Data Type was found or
   * -ENOENT otherwise.
   */
  int pci_vpd_find_tag(const u8 *buf, unsigned int off, unsigned int len, u8 rdt);
4067a8541   Matt Carlson   pci: Add helper t...
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
  /**
   * pci_vpd_find_info_keyword - Locates an information field keyword in the VPD
   * @buf: Pointer to buffered vpd data
   * @off: The offset into the buffer at which to begin the search
   * @len: The length of the buffer area, relative to off, in which to search
   * @kw: The keyword to search for
   *
   * Returns the index where the information field keyword was found or
   * -ENOENT otherwise.
   */
  int pci_vpd_find_info_keyword(const u8 *buf, unsigned int off,
  			      unsigned int len, const char *kw);
98d9f30c8   Benjamin Herrenschmidt   pci/of: Match PCI...
2068
2069
2070
  /* PCI <-> OF binding helpers */
  #ifdef CONFIG_OF
  struct device_node;
b165e2b60   Marc Zyngier   PCI/MSI: Add supp...
2071
  struct irq_domain;
f39d5b729   Bjorn Helgaas   PCI: Remove "exte...
2072
2073
2074
2075
  void pci_set_of_node(struct pci_dev *dev);
  void pci_release_of_node(struct pci_dev *dev);
  void pci_set_bus_of_node(struct pci_bus *bus);
  void pci_release_bus_of_node(struct pci_bus *bus);
b165e2b60   Marc Zyngier   PCI/MSI: Add supp...
2076
  struct irq_domain *pci_host_bridge_of_msi_domain(struct pci_bus *bus);
98d9f30c8   Benjamin Herrenschmidt   pci/of: Match PCI...
2077
2078
  
  /* Arch may override this (weak) */
723ec4d06   Bjorn Helgaas   Merge branch 'pci...
2079
  struct device_node *pcibios_get_phb_of_node(struct pci_bus *bus);
98d9f30c8   Benjamin Herrenschmidt   pci/of: Match PCI...
2080

3df425f31   John Crispin   OF: PCI: const us...
2081
2082
  static inline struct device_node *
  pci_device_to_OF_node(const struct pci_dev *pdev)
64099d981   Benjamin Herrenschmidt   pci/of: Consolida...
2083
2084
2085
  {
  	return pdev ? pdev->dev.of_node : NULL;
  }
ef3b4f8cc   Benjamin Herrenschmidt   pci/of: Consolida...
2086
2087
2088
2089
  static inline struct device_node *pci_bus_to_OF_node(struct pci_bus *bus)
  {
  	return bus ? bus->dev.of_node : NULL;
  }
98d9f30c8   Benjamin Herrenschmidt   pci/of: Match PCI...
2090
2091
2092
2093
2094
  #else /* CONFIG_OF */
  static inline void pci_set_of_node(struct pci_dev *dev) { }
  static inline void pci_release_of_node(struct pci_dev *dev) { }
  static inline void pci_set_bus_of_node(struct pci_bus *bus) { }
  static inline void pci_release_bus_of_node(struct pci_bus *bus) { }
f0b66a2cf   Kevin Hao   PCI: Add pci_devi...
2095
2096
  static inline struct device_node *
  pci_device_to_OF_node(const struct pci_dev *pdev) { return NULL; }
b165e2b60   Marc Zyngier   PCI/MSI: Add supp...
2097
2098
  static inline struct irq_domain *
  pci_host_bridge_of_msi_domain(struct pci_bus *bus) { return NULL; }
98d9f30c8   Benjamin Herrenschmidt   pci/of: Match PCI...
2099
  #endif  /* CONFIG_OF */
471036b2b   Suravee Suthikulpanit   acpi: pci: Setup ...
2100
2101
2102
2103
2104
2105
2106
2107
2108
  #ifdef CONFIG_ACPI
  struct irq_domain *pci_host_bridge_acpi_msi_domain(struct pci_bus *bus);
  
  void
  pci_msi_register_fwnode_provider(struct fwnode_handle *(*fn)(struct device *));
  #else
  static inline struct irq_domain *
  pci_host_bridge_acpi_msi_domain(struct pci_bus *bus) { return NULL; }
  #endif
eb740b5f3   Gavin Shan   powerpc/eeh: Intr...
2109
2110
2111
2112
2113
2114
  #ifdef CONFIG_EEH
  static inline struct eeh_dev *pci_dev_to_eeh_dev(struct pci_dev *pdev)
  {
  	return pdev->dev.archdata.edev;
  }
  #endif
f0af95933   Bjorn Helgaas   PCI: Add pci_add_...
2115
  void pci_add_dma_alias(struct pci_dev *dev, u8 devfn);
338c3149a   Jacek Lawrynowicz   PCI: Add support ...
2116
  bool pci_devs_are_dma_aliases(struct pci_dev *dev1, struct pci_dev *dev2);
c25dc8289   Alex Williamson   PCI: Add DMA alia...
2117
2118
2119
  int pci_for_each_dma_alias(struct pci_dev *pdev,
  			   int (*fn)(struct pci_dev *pdev,
  				     u16 alias, void *data), void *data);
ce0529843   Ethan Zhao   PCI: Add device f...
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
  /* helper functions for operation of device flag */
  static inline void pci_set_dev_assigned(struct pci_dev *pdev)
  {
  	pdev->dev_flags |= PCI_DEV_FLAGS_ASSIGNED;
  }
  static inline void pci_clear_dev_assigned(struct pci_dev *pdev)
  {
  	pdev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
  }
  static inline bool pci_is_dev_assigned(struct pci_dev *pdev)
  {
  	return (pdev->dev_flags & PCI_DEV_FLAGS_ASSIGNED) == PCI_DEV_FLAGS_ASSIGNED;
  }
19bdb6e4e   Alex Williamson   PCI: Move pci_ari...
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
  
  /**
   * pci_ari_enabled - query ARI forwarding status
   * @bus: the PCI bus
   *
   * Returns true if ARI forwarding is enabled.
   */
  static inline bool pci_ari_enabled(struct pci_bus *bus)
  {
  	return bus->self && bus->self->ari_enabled;
  }
bc4b024a8   Christoph Hellwig   PCI: Move pci_dma...
2144

8531e283b   Lukas Wunner   PCI: Recognize Th...
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
  /**
   * pci_is_thunderbolt_attached - whether device is on a Thunderbolt daisy chain
   * @pdev: PCI device to check
   *
   * Walk upwards from @pdev and check for each encountered bridge if it's part
   * of a Thunderbolt controller.  Reaching the host bridge means @pdev is not
   * Thunderbolt-attached.  (But rather soldered to the mainboard usually.)
   */
  static inline bool pci_is_thunderbolt_attached(struct pci_dev *pdev)
  {
  	struct pci_dev *parent = pdev;
  
  	if (pdev->is_thunderbolt)
  		return true;
  
  	while ((parent = pci_upstream_bridge(parent)))
  		if (parent->is_thunderbolt)
  			return true;
  
  	return false;
  }
bc4b024a8   Christoph Hellwig   PCI: Move pci_dma...
2166
2167
  /* provide the legacy pci_dma_* API */
  #include <linux/pci-dma-compat.h>
15677df25   Frederick Lawler   PCI: Add wrappers...
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
  #define pci_printk(level, pdev, fmt, arg...) \
  	dev_printk(level, &(pdev)->dev, fmt, ##arg)
  
  #define pci_emerg(pdev, fmt, arg...)	dev_emerg(&(pdev)->dev, fmt, ##arg)
  #define pci_alert(pdev, fmt, arg...)	dev_alert(&(pdev)->dev, fmt, ##arg)
  #define pci_crit(pdev, fmt, arg...)	dev_crit(&(pdev)->dev, fmt, ##arg)
  #define pci_err(pdev, fmt, arg...)	dev_err(&(pdev)->dev, fmt, ##arg)
  #define pci_warn(pdev, fmt, arg...)	dev_warn(&(pdev)->dev, fmt, ##arg)
  #define pci_notice(pdev, fmt, arg...)	dev_notice(&(pdev)->dev, fmt, ##arg)
  #define pci_info(pdev, fmt, arg...)	dev_info(&(pdev)->dev, fmt, ##arg)
  #define pci_dbg(pdev, fmt, arg...)	dev_dbg(&(pdev)->dev, fmt, ##arg)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2179
  #endif /* LINUX_PCI_H */