Blame view

drivers/pci/pci.h 10.5 KB
557848c3c   Zhao, Yu   PCI: replace cfg ...
1
2
  #ifndef DRIVERS_PCI_H
  #define DRIVERS_PCI_H
74bb1bcc7   Yu Zhao   PCI: handle SR-IO...
3
  #include <linux/workqueue.h>
557848c3c   Zhao, Yu   PCI: replace cfg ...
4
5
  #define PCI_CFG_SPACE_SIZE	256
  #define PCI_CFG_SPACE_EXP_SIZE	4096
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
6
  /* Functions internal to the PCI core code */
7eff2e7a8   Kay Sievers   Driver core: chan...
7
  extern int pci_uevent(struct device *dev, struct kobj_uevent_env *env);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
8
9
  extern int pci_create_sysfs_dev_files(struct pci_dev *pdev);
  extern void pci_remove_sysfs_dev_files(struct pci_dev *pdev);
6058989ba   Narendra_K@Dell.com   PCI: Export ACPI ...
10
  #if !defined(CONFIG_DMI) && !defined(CONFIG_ACPI)
911e1c9b0   Narendra K   PCI: export SMBIO...
11
  static inline void pci_create_firmware_label_files(struct pci_dev *pdev)
b879743f2   Narendra K   PCI: Fix warnings...
12
  { return; }
911e1c9b0   Narendra K   PCI: export SMBIO...
13
  static inline void pci_remove_firmware_label_files(struct pci_dev *pdev)
b879743f2   Narendra K   PCI: Fix warnings...
14
  { return; }
911e1c9b0   Narendra K   PCI: export SMBIO...
15
16
17
18
  #else
  extern void pci_create_firmware_label_files(struct pci_dev *pdev);
  extern void pci_remove_firmware_label_files(struct pci_dev *pdev);
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
19
  extern void pci_cleanup_rom(struct pci_dev *dev);
9eff02e20   Jesse Barnes   PCI: check mmap r...
20
  #ifdef HAVE_PCI_MMAP
3b519e4ea   Martin Wilck   PCI: fix size che...
21
22
23
24
  enum pci_mmap_api {
  	PCI_MMAP_SYSFS,	/* mmap on /sys/bus/pci/devices/<BDF>/resource<N> */
  	PCI_MMAP_PROCFS	/* mmap on /proc/bus/pci/<BDF> */
  };
9eff02e20   Jesse Barnes   PCI: check mmap r...
25
  extern int pci_mmap_fits(struct pci_dev *pdev, int resno,
3b519e4ea   Martin Wilck   PCI: fix size che...
26
27
  			 struct vm_area_struct *vmai,
  			 enum pci_mmap_api mmap_api);
9eff02e20   Jesse Barnes   PCI: check mmap r...
28
  #endif
711d57796   Michael S. Tsirkin   PCI: expose funct...
29
  int pci_probe_reset_function(struct pci_dev *dev);
ce5ccdef1   Kumar Gala   PCI: Move prototy...
30

961d9120f   Rafael J. Wysocki   PCI: Introduce pl...
31
  /**
b33bfdef2   Randy Dunlap   PCI: fix struct p...
32
   * struct pci_platform_pm_ops - Firmware PM callbacks
961d9120f   Rafael J. Wysocki   PCI: Introduce pl...
33
   *
b33bfdef2   Randy Dunlap   PCI: fix struct p...
34
35
   * @is_manageable: returns 'true' if given device is power manageable by the
   *                 platform firmware
961d9120f   Rafael J. Wysocki   PCI: Introduce pl...
36
   *
b33bfdef2   Randy Dunlap   PCI: fix struct p...
37
   * @set_state: invokes the platform firmware to set the device's power state
961d9120f   Rafael J. Wysocki   PCI: Introduce pl...
38
   *
b33bfdef2   Randy Dunlap   PCI: fix struct p...
39
40
41
   * @choose_state: returns PCI power state of given device preferred by the
   *                platform; to be used during system-wide transitions from a
   *                sleeping state to the working state and vice versa
961d9120f   Rafael J. Wysocki   PCI: Introduce pl...
42
   *
b33bfdef2   Randy Dunlap   PCI: fix struct p...
43
44
   * @can_wakeup: returns 'true' if given device is capable of waking up the
   *              system from a sleeping state
eb9d0fe40   Rafael J. Wysocki   PCI ACPI: Rework ...
45
   *
b33bfdef2   Randy Dunlap   PCI: fix struct p...
46
   * @sleep_wake: enables/disables the system wake up capability of given device
eb9d0fe40   Rafael J. Wysocki   PCI ACPI: Rework ...
47
   *
b67ea7617   Rafael J. Wysocki   PCI / ACPI / PM: ...
48
49
50
51
   * @run_wake: enables/disables the platform to generate run-time wake-up events
   *		for given device (the device's wake-up capability has to be
   *		enabled by @sleep_wake for this feature to work)
   *
961d9120f   Rafael J. Wysocki   PCI: Introduce pl...
52
53
54
55
56
57
58
   * If given platform is generally capable of power managing PCI devices, all of
   * these callbacks are mandatory.
   */
  struct pci_platform_pm_ops {
  	bool (*is_manageable)(struct pci_dev *dev);
  	int (*set_state)(struct pci_dev *dev, pci_power_t state);
  	pci_power_t (*choose_state)(struct pci_dev *dev);
eb9d0fe40   Rafael J. Wysocki   PCI ACPI: Rework ...
59
60
  	bool (*can_wakeup)(struct pci_dev *dev);
  	int (*sleep_wake)(struct pci_dev *dev, bool enable);
b67ea7617   Rafael J. Wysocki   PCI / ACPI / PM: ...
61
  	int (*run_wake)(struct pci_dev *dev, bool enable);
961d9120f   Rafael J. Wysocki   PCI: Introduce pl...
62
63
64
  };
  
  extern int pci_set_platform_pm(struct pci_platform_pm_ops *ops);
734104292   Rafael J. Wysocki   PCI PM: Avoid tou...
65
  extern void pci_update_current_state(struct pci_dev *dev, pci_power_t state);
fa58d305d   Rafael J. Wysocki   PCI PM: Add suspe...
66
  extern void pci_disable_enabled_device(struct pci_dev *dev);
6cbf82148   Rafael J. Wysocki   PCI PM: Run-time ...
67
  extern int pci_finish_runtime_suspend(struct pci_dev *dev);
b67ea7617   Rafael J. Wysocki   PCI / ACPI / PM: ...
68
  extern int __pci_pme_wakeup(struct pci_dev *dev, void *ign);
eb9d0fe40   Rafael J. Wysocki   PCI ACPI: Rework ...
69
  extern void pci_pm_init(struct pci_dev *dev);
eb9c39d03   Jesse Barnes   PCI: set device w...
70
  extern void platform_pci_wakeup_init(struct pci_dev *dev);
63f4898ac   Rafael J. Wysocki   PCI: handle PCI s...
71
  extern void pci_allocate_cap_save_buffers(struct pci_dev *dev);
aa8c6c937   Rafael J. Wysocki   PCI PM: Restore s...
72

b6e335aee   Rafael J. Wysocki   PCI/PM: Use pm_wa...
73
74
75
76
77
  static inline void pci_wakeup_event(struct pci_dev *dev)
  {
  	/* Wait 100 ms before the system can be put into a sleep state. */
  	pm_wakeup_event(&dev->dev, 100);
  }
aa8c6c937   Rafael J. Wysocki   PCI PM: Restore s...
78
79
80
81
  static inline bool pci_is_bridge(struct pci_dev *pci_dev)
  {
  	return !!(pci_dev->subordinate);
  }
0f64474b8   David Shaohua Li   [ACPI] PCI can no...
82

e04b0ea2e   Brian King   [PATCH] PCI: Bloc...
83
84
85
86
87
88
  extern int pci_user_read_config_byte(struct pci_dev *dev, int where, u8 *val);
  extern int pci_user_read_config_word(struct pci_dev *dev, int where, u16 *val);
  extern int pci_user_read_config_dword(struct pci_dev *dev, int where, u32 *val);
  extern int pci_user_write_config_byte(struct pci_dev *dev, int where, u8 val);
  extern int pci_user_write_config_word(struct pci_dev *dev, int where, u16 val);
  extern int pci_user_write_config_dword(struct pci_dev *dev, int where, u32 val);
94e610880   Ben Hutchings   PCI: Expose PCI V...
89
  struct pci_vpd_ops {
287d19ce2   Stephen Hemminger   PCI: revise VPD a...
90
91
  	ssize_t (*read)(struct pci_dev *dev, loff_t pos, size_t count, void *buf);
  	ssize_t (*write)(struct pci_dev *dev, loff_t pos, size_t count, const void *buf);
94e610880   Ben Hutchings   PCI: Expose PCI V...
92
93
94
95
  	void (*release)(struct pci_dev *dev);
  };
  
  struct pci_vpd {
99cb233d6   Benjamin Li   PCI: Limit VPD re...
96
  	unsigned int len;
287d19ce2   Stephen Hemminger   PCI: revise VPD a...
97
  	const struct pci_vpd_ops *ops;
94e610880   Ben Hutchings   PCI: Expose PCI V...
98
99
100
101
102
103
104
105
106
  	struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
  };
  
  extern int pci_vpd_pci22_init(struct pci_dev *dev);
  static inline void pci_vpd_release(struct pci_dev *dev)
  {
  	if (dev->vpd)
  		dev->vpd->ops->release(dev);
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
107
108
109
110
  /* PCI /proc functions */
  #ifdef CONFIG_PROC_FS
  extern int pci_proc_attach_device(struct pci_dev *dev);
  extern int pci_proc_detach_device(struct pci_dev *dev);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
111
112
113
114
  extern int pci_proc_detach_bus(struct pci_bus *bus);
  #else
  static inline int pci_proc_attach_device(struct pci_dev *dev) { return 0; }
  static inline int pci_proc_detach_device(struct pci_dev *dev) { return 0; }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
115
116
117
118
  static inline int pci_proc_detach_bus(struct pci_bus *bus) { return 0; }
  #endif
  
  /* Functions for PCI Hotplug drivers to use */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
119
  extern unsigned int pci_do_scan_bus(struct pci_bus *bus);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
120

f19aeb1f3   Benjamin Herrenschmidt   PCI: Add ability ...
121
122
  #ifdef HAVE_PCI_LEGACY
  extern void pci_create_legacy_files(struct pci_bus *bus);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
123
  extern void pci_remove_legacy_files(struct pci_bus *bus);
f19aeb1f3   Benjamin Herrenschmidt   PCI: Add ability ...
124
125
126
127
  #else
  static inline void pci_create_legacy_files(struct pci_bus *bus) { return; }
  static inline void pci_remove_legacy_files(struct pci_bus *bus) { return; }
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
128
129
  
  /* Lock for read/write access to pci device and bus lists */
d71374daf   Zhang Yanmin   [PATCH] PCI: fix ...
130
  extern struct rw_semaphore pci_bus_sem;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
131

a2e27787f   Jan Kiszka   PCI: Introduce IN...
132
  extern raw_spinlock_t pci_lock;
ffadcc2ff   Kristen Carlson Accardi   [PATCH] PCI: PCIE...
133
  extern unsigned int pci_pm_d3_delay;
88187dfa4   Michael Ellerman   MSI: Replace pci_...
134

4b47b0eef   Andrew Morton   [PATCH] PCI: fix ...
135
  #ifdef CONFIG_PCI_MSI
309e57df7   Matthew Wilcox   [PATCH] PCI: Prov...
136
  void pci_no_msi(void);
4aa9bc955   Michael Ellerman   MSI: Use a list i...
137
  extern void pci_msi_init_pci_dev(struct pci_dev *dev);
4b47b0eef   Andrew Morton   [PATCH] PCI: fix ...
138
  #else
309e57df7   Matthew Wilcox   [PATCH] PCI: Prov...
139
  static inline void pci_no_msi(void) { }
4aa9bc955   Michael Ellerman   MSI: Use a list i...
140
  static inline void pci_msi_init_pci_dev(struct pci_dev *dev) { }
4b47b0eef   Andrew Morton   [PATCH] PCI: fix ...
141
  #endif
8fed4b652   Michael Ellerman   MSI: Combine pci_...
142

f483d3923   Ram Pai   PCI: conditional ...
143
  extern void pci_realloc(void);
ffadcc2ff   Kristen Carlson Accardi   [PATCH] PCI: PCIE...
144
145
146
  static inline int pci_no_d1d2(struct pci_dev *dev)
  {
  	unsigned int parent_dstates = 0;
4b47b0eef   Andrew Morton   [PATCH] PCI: fix ...
147

ffadcc2ff   Kristen Carlson Accardi   [PATCH] PCI: PCIE...
148
149
150
151
152
  	if (dev->bus->self)
  		parent_dstates = dev->bus->self->no_d1d2;
  	return (dev->no_d1d2 || parent_dstates);
  
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
153
  extern struct device_attribute pci_dev_attrs[];
b9d320fcb   Yinghai Lu   PCI: add rescan t...
154
  extern struct device_attribute pcibus_dev_attrs[];
705b1aaa8   Alex Chiang   PCI: Introduce /s...
155
156
157
158
159
  #ifdef CONFIG_HOTPLUG
  extern struct bus_attribute pci_bus_attrs[];
  #else
  #define pci_bus_attrs	NULL
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
160
161
162
163
164
165
  
  /**
   * pci_match_one_device - Tell if a PCI device structure has a matching
   *                        PCI device id structure
   * @id: single PCI device id structure to match
   * @dev: the PCI device structure to match against
367b09fec   Greg Kroah-Hartman   PCI: fix codingst...
166
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
167
168
169
170
171
172
173
174
175
176
177
178
179
   * Returns the matching pci_device_id structure or %NULL if there is no match.
   */
  static inline const struct pci_device_id *
  pci_match_one_device(const struct pci_device_id *id, const struct pci_dev *dev)
  {
  	if ((id->vendor == PCI_ANY_ID || id->vendor == dev->vendor) &&
  	    (id->device == PCI_ANY_ID || id->device == dev->device) &&
  	    (id->subvendor == PCI_ANY_ID || id->subvendor == dev->subsystem_vendor) &&
  	    (id->subdevice == PCI_ANY_ID || id->subdevice == dev->subsystem_device) &&
  	    !((id->class ^ dev->class) & id->class_mask))
  		return id;
  	return NULL;
  }
f46753c5e   Alex Chiang   PCI: introduce pc...
180
181
182
183
184
185
186
187
188
189
190
  /* PCI slot sysfs helper code */
  #define to_pci_slot(s) container_of(s, struct pci_slot, kobj)
  
  extern struct kset *pci_slots_kset;
  
  struct pci_slot_attribute {
  	struct attribute attr;
  	ssize_t (*show)(struct pci_slot *, char *);
  	ssize_t (*store)(struct pci_slot *, const char *, size_t);
  };
  #define to_pci_slot_attr(s) container_of(s, struct pci_slot_attribute, attr)
0b400c7ed   Yu Zhao   PCI: export __pci...
191
192
193
194
195
196
  enum pci_bar_type {
  	pci_bar_unknown,	/* Standard PCI BAR probe */
  	pci_bar_io,		/* An io port BAR */
  	pci_bar_mem32,		/* A 32-bit memory BAR */
  	pci_bar_mem64,		/* A 64-bit memory BAR */
  };
480b93b78   Yu Zhao   PCI: centralize d...
197
  extern int pci_setup_device(struct pci_dev *dev);
0b400c7ed   Yu Zhao   PCI: export __pci...
198
199
  extern int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
  				struct resource *res, unsigned int reg);
613e7ed6f   Yu Zhao   PCI: add a new fu...
200
201
  extern int pci_resource_bar(struct pci_dev *dev, int resno,
  			    enum pci_bar_type *type);
876e501ab   Yu Zhao   PCI: factor pci_b...
202
  extern int pci_bus_add_child(struct pci_bus *bus);
58c3a727c   Yu Zhao   PCI: support PCIe...
203
204
205
  extern void pci_enable_ari(struct pci_dev *dev);
  /**
   * pci_ari_enabled - query ARI forwarding status
6a49d8120   Yu Zhao   PCI: enhance pci_...
206
   * @bus: the PCI bus
58c3a727c   Yu Zhao   PCI: support PCIe...
207
208
209
   *
   * Returns 1 if ARI forwarding is enabled, or 0 if not enabled;
   */
6a49d8120   Yu Zhao   PCI: enhance pci_...
210
  static inline int pci_ari_enabled(struct pci_bus *bus)
58c3a727c   Yu Zhao   PCI: support PCIe...
211
  {
6a49d8120   Yu Zhao   PCI: enhance pci_...
212
  	return bus->self && bus->self->ari_enabled;
58c3a727c   Yu Zhao   PCI: support PCIe...
213
  }
32a9a682b   Yuji Shimada   PCI: allow assign...
214
215
216
217
218
  #ifdef CONFIG_PCI_QUIRKS
  extern int pci_is_reassigndev(struct pci_dev *dev);
  resource_size_t pci_specified_resource_alignment(struct pci_dev *dev);
  extern void pci_disable_bridge_window(struct pci_dev *dev);
  #endif
d1b054da8   Yu Zhao   PCI: initialize a...
219
220
221
222
223
224
225
  /* Single Root I/O Virtualization */
  struct pci_sriov {
  	int pos;		/* capability position */
  	int nres;		/* number of resources */
  	u32 cap;		/* SR-IOV Capabilities */
  	u16 ctrl;		/* SR-IOV Control */
  	u16 total;		/* total VFs associated with the PF */
dd7cc44d0   Yu Zhao   PCI: add SR-IOV A...
226
227
  	u16 initial;		/* initial VFs associated with the PF */
  	u16 nr_virtfn;		/* number of VFs available */
d1b054da8   Yu Zhao   PCI: initialize a...
228
229
230
231
232
233
234
  	u16 offset;		/* first VF Routing ID offset */
  	u16 stride;		/* following VF stride */
  	u32 pgsz;		/* page size for BAR alignment */
  	u8 link;		/* Function Dependency Link */
  	struct pci_dev *dev;	/* lowest numbered PF */
  	struct pci_dev *self;	/* this PF */
  	struct mutex lock;	/* lock for VF bus */
74bb1bcc7   Yu Zhao   PCI: handle SR-IO...
235
236
  	struct work_struct mtask; /* VF Migration task */
  	u8 __iomem *mstate;	/* VF Migration State Array */
d1b054da8   Yu Zhao   PCI: initialize a...
237
  };
1900ca132   Hao, Xudong   PCI: Enable ATS a...
238
239
240
241
242
243
244
  #ifdef CONFIG_PCI_ATS
  extern void pci_restore_ats_state(struct pci_dev *dev);
  #else
  static inline void pci_restore_ats_state(struct pci_dev *dev)
  {
  }
  #endif /* CONFIG_PCI_ATS */
d1b054da8   Yu Zhao   PCI: initialize a...
245
246
247
248
249
  #ifdef CONFIG_PCI_IOV
  extern int pci_iov_init(struct pci_dev *dev);
  extern void pci_iov_release(struct pci_dev *dev);
  extern int pci_iov_resource_bar(struct pci_dev *dev, int resno,
  				enum pci_bar_type *type);
0e52247a2   Cam Macdonell   PCI: fix pci_reso...
250
251
  extern resource_size_t pci_sriov_resource_alignment(struct pci_dev *dev,
  						    int resno);
8c5cdb6ad   Yu Zhao   PCI: restore save...
252
  extern void pci_restore_iov_state(struct pci_dev *dev);
a28724b0f   Yu Zhao   PCI: reserve bus ...
253
  extern int pci_iov_bus_range(struct pci_bus *bus);
302b4215d   Yu Zhao   PCI: support the ...
254

d1b054da8   Yu Zhao   PCI: initialize a...
255
256
257
258
259
260
261
262
263
264
265
266
267
268
  #else
  static inline int pci_iov_init(struct pci_dev *dev)
  {
  	return -ENODEV;
  }
  static inline void pci_iov_release(struct pci_dev *dev)
  
  {
  }
  static inline int pci_iov_resource_bar(struct pci_dev *dev, int resno,
  				       enum pci_bar_type *type)
  {
  	return 0;
  }
8c5cdb6ad   Yu Zhao   PCI: restore save...
269
270
271
  static inline void pci_restore_iov_state(struct pci_dev *dev)
  {
  }
a28724b0f   Yu Zhao   PCI: reserve bus ...
272
273
274
275
  static inline int pci_iov_bus_range(struct pci_bus *bus)
  {
  	return 0;
  }
302b4215d   Yu Zhao   PCI: support the ...
276

d1b054da8   Yu Zhao   PCI: initialize a...
277
  #endif /* CONFIG_PCI_IOV */
0a2daa1cf   Ram Pai   PCI: make cardbus...
278
  extern unsigned long pci_cardbus_resource_alignment(struct resource *);
0e52247a2   Cam Macdonell   PCI: fix pci_reso...
279
  static inline resource_size_t pci_resource_alignment(struct pci_dev *dev,
6faf17f6f   Chris Wright   PCI SR-IOV: corre...
280
281
282
283
284
285
286
287
  					 struct resource *res)
  {
  #ifdef CONFIG_PCI_IOV
  	int resno = res - dev->resource;
  
  	if (resno >= PCI_IOV_RESOURCES && resno <= PCI_IOV_RESOURCE_END)
  		return pci_sriov_resource_alignment(dev, resno);
  #endif
0a2daa1cf   Ram Pai   PCI: make cardbus...
288
289
  	if (dev->class >> 8  == PCI_CLASS_BRIDGE_CARDBUS)
  		return pci_cardbus_resource_alignment(res);
6faf17f6f   Chris Wright   PCI SR-IOV: corre...
290
291
  	return resource_alignment(res);
  }
ae21ee65e   Allen Kay   PCI: acs p2p upst...
292
  extern void pci_enable_acs(struct pci_dev *dev);
b9c3b2664   Dexuan Cui   PCI: support devi...
293
294
295
296
297
  struct pci_dev_reset_methods {
  	u16 vendor;
  	u16 device;
  	int (*reset)(struct pci_dev *dev, int probe);
  };
93177a748   Rafael J. Wysocki   PCI: Clean up bui...
298
  #ifdef CONFIG_PCI_QUIRKS
5b889bf23   Rafael J. Wysocki   PCI: Fix build if...
299
  extern int pci_dev_specific_reset(struct pci_dev *dev, int probe);
93177a748   Rafael J. Wysocki   PCI: Clean up bui...
300
301
302
303
304
305
  #else
  static inline int pci_dev_specific_reset(struct pci_dev *dev, int probe)
  {
  	return -ENOTTY;
  }
  #endif
b9c3b2664   Dexuan Cui   PCI: support devi...
306

557848c3c   Zhao, Yu   PCI: replace cfg ...
307
  #endif /* DRIVERS_PCI_H */