pci.h 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857
  1. /*
  2. * pci.h
  3. *
  4. * PCI defines and function prototypes
  5. * Copyright 1994, Drew Eckhardt
  6. * Copyright 1997--1999 Martin Mares <mj@ucw.cz>
  7. *
  8. * For more information, please consult the following manuals (look at
  9. * http://www.pcisig.com/ for how to get them):
  10. *
  11. * PCI BIOS Specification
  12. * PCI Local Bus Specification
  13. * PCI to PCI Bridge Specification
  14. * PCI System Design Guide
  15. */
  16. #ifndef LINUX_PCI_H
  17. #define LINUX_PCI_H
  18. /* Include the pci register defines */
  19. #include <linux/pci_regs.h>
  20. /*
  21. * The PCI interface treats multi-function devices as independent
  22. * devices. The slot/function address of each device is encoded
  23. * in a single byte as follows:
  24. *
  25. * 7:3 = slot
  26. * 2:0 = function
  27. */
  28. #define PCI_DEVFN(slot,func) ((((slot) & 0x1f) << 3) | ((func) & 0x07))
  29. #define PCI_SLOT(devfn) (((devfn) >> 3) & 0x1f)
  30. #define PCI_FUNC(devfn) ((devfn) & 0x07)
  31. /* Ioctls for /proc/bus/pci/X/Y nodes. */
  32. #define PCIIOC_BASE ('P' << 24 | 'C' << 16 | 'I' << 8)
  33. #define PCIIOC_CONTROLLER (PCIIOC_BASE | 0x00) /* Get controller for PCI device. */
  34. #define PCIIOC_MMAP_IS_IO (PCIIOC_BASE | 0x01) /* Set mmap state to I/O space. */
  35. #define PCIIOC_MMAP_IS_MEM (PCIIOC_BASE | 0x02) /* Set mmap state to MEM space. */
  36. #define PCIIOC_WRITE_COMBINE (PCIIOC_BASE | 0x03) /* Enable/disable write-combining. */
  37. #ifdef __KERNEL__
  38. #include <linux/mod_devicetable.h>
  39. #include <linux/types.h>
  40. #include <linux/ioport.h>
  41. #include <linux/list.h>
  42. #include <linux/compiler.h>
  43. #include <linux/errno.h>
  44. #include <asm/atomic.h>
  45. #include <linux/device.h>
  46. /* Include the ID list */
  47. #include <linux/pci_ids.h>
  48. /* File state for mmap()s on /proc/bus/pci/X/Y */
  49. enum pci_mmap_state {
  50. pci_mmap_io,
  51. pci_mmap_mem
  52. };
  53. /* This defines the direction arg to the DMA mapping routines. */
  54. #define PCI_DMA_BIDIRECTIONAL 0
  55. #define PCI_DMA_TODEVICE 1
  56. #define PCI_DMA_FROMDEVICE 2
  57. #define PCI_DMA_NONE 3
  58. #define DEVICE_COUNT_COMPATIBLE 4
  59. #define DEVICE_COUNT_RESOURCE 12
  60. typedef int __bitwise pci_power_t;
  61. #define PCI_D0 ((pci_power_t __force) 0)
  62. #define PCI_D1 ((pci_power_t __force) 1)
  63. #define PCI_D2 ((pci_power_t __force) 2)
  64. #define PCI_D3hot ((pci_power_t __force) 3)
  65. #define PCI_D3cold ((pci_power_t __force) 4)
  66. #define PCI_UNKNOWN ((pci_power_t __force) 5)
  67. #define PCI_POWER_ERROR ((pci_power_t __force) -1)
  68. /** The pci_channel state describes connectivity between the CPU and
  69. * the pci device. If some PCI bus between here and the pci device
  70. * has crashed or locked up, this info is reflected here.
  71. */
  72. typedef unsigned int __bitwise pci_channel_state_t;
  73. enum pci_channel_state {
  74. /* I/O channel is in normal state */
  75. pci_channel_io_normal = (__force pci_channel_state_t) 1,
  76. /* I/O to channel is blocked */
  77. pci_channel_io_frozen = (__force pci_channel_state_t) 2,
  78. /* PCI card is dead */
  79. pci_channel_io_perm_failure = (__force pci_channel_state_t) 3,
  80. };
  81. typedef unsigned short __bitwise pci_bus_flags_t;
  82. enum pci_bus_flags {
  83. PCI_BUS_FLAGS_NO_MSI = (__force pci_bus_flags_t) 1,
  84. };
  85. struct pci_cap_saved_state {
  86. struct hlist_node next;
  87. char cap_nr;
  88. u32 data[0];
  89. };
  90. /*
  91. * The pci_dev structure is used to describe PCI devices.
  92. */
  93. struct pci_dev {
  94. struct list_head global_list; /* node in list of all PCI devices */
  95. struct list_head bus_list; /* node in per-bus list */
  96. struct pci_bus *bus; /* bus this device is on */
  97. struct pci_bus *subordinate; /* bus this device bridges to */
  98. void *sysdata; /* hook for sys-specific extension */
  99. struct proc_dir_entry *procent; /* device entry in /proc/bus/pci */
  100. unsigned int devfn; /* encoded device & function index */
  101. unsigned short vendor;
  102. unsigned short device;
  103. unsigned short subsystem_vendor;
  104. unsigned short subsystem_device;
  105. unsigned int class; /* 3 bytes: (base,sub,prog-if) */
  106. u8 hdr_type; /* PCI header type (`multi' flag masked out) */
  107. u8 rom_base_reg; /* which config register controls the ROM */
  108. u8 pin; /* which interrupt pin this device uses */
  109. struct pci_driver *driver; /* which driver has allocated this device */
  110. u64 dma_mask; /* Mask of the bits of bus address this
  111. device implements. Normally this is
  112. 0xffffffff. You only need to change
  113. this if your device has broken DMA
  114. or supports 64-bit transfers. */
  115. pci_power_t current_state; /* Current operating state. In ACPI-speak,
  116. this is D0-D3, D0 being fully functional,
  117. and D3 being off. */
  118. pci_channel_state_t error_state; /* current connectivity state */
  119. struct device dev; /* Generic device interface */
  120. /* device is compatible with these IDs */
  121. unsigned short vendor_compatible[DEVICE_COUNT_COMPATIBLE];
  122. unsigned short device_compatible[DEVICE_COUNT_COMPATIBLE];
  123. int cfg_size; /* Size of configuration space */
  124. /*
  125. * Instead of touching interrupt line and base address registers
  126. * directly, use the values stored here. They might be different!
  127. */
  128. unsigned int irq;
  129. struct resource resource[DEVICE_COUNT_RESOURCE]; /* I/O and memory regions + expansion ROMs */
  130. /* These fields are used by common fixups */
  131. unsigned int transparent:1; /* Transparent PCI bridge */
  132. unsigned int multifunction:1;/* Part of multi-function device */
  133. /* keep track of device state */
  134. unsigned int is_busmaster:1; /* device is busmaster */
  135. unsigned int no_msi:1; /* device may not use msi */
  136. unsigned int no_d1d2:1; /* only allow d0 or d3 */
  137. unsigned int block_ucfg_access:1; /* userspace config space access is blocked */
  138. unsigned int broken_parity_status:1; /* Device generates false positive parity */
  139. unsigned int msi_enabled:1;
  140. unsigned int msix_enabled:1;
  141. unsigned int is_managed:1;
  142. atomic_t enable_cnt; /* pci_enable_device has been called */
  143. u32 saved_config_space[16]; /* config space saved at suspend time */
  144. struct hlist_head saved_cap_space;
  145. struct bin_attribute *rom_attr; /* attribute descriptor for sysfs ROM entry */
  146. int rom_attr_enabled; /* has display of the rom attribute been enabled? */
  147. struct bin_attribute *res_attr[DEVICE_COUNT_RESOURCE]; /* sysfs file for resources */
  148. #ifdef CONFIG_PCI_MSI
  149. unsigned int first_msi_irq;
  150. #endif
  151. };
  152. #define pci_dev_g(n) list_entry(n, struct pci_dev, global_list)
  153. #define pci_dev_b(n) list_entry(n, struct pci_dev, bus_list)
  154. #define to_pci_dev(n) container_of(n, struct pci_dev, dev)
  155. #define for_each_pci_dev(d) while ((d = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, d)) != NULL)
  156. static inline int pci_channel_offline(struct pci_dev *pdev)
  157. {
  158. return (pdev->error_state != pci_channel_io_normal);
  159. }
  160. static inline struct pci_cap_saved_state *pci_find_saved_cap(
  161. struct pci_dev *pci_dev,char cap)
  162. {
  163. struct pci_cap_saved_state *tmp;
  164. struct hlist_node *pos;
  165. hlist_for_each_entry(tmp, pos, &pci_dev->saved_cap_space, next) {
  166. if (tmp->cap_nr == cap)
  167. return tmp;
  168. }
  169. return NULL;
  170. }
  171. static inline void pci_add_saved_cap(struct pci_dev *pci_dev,
  172. struct pci_cap_saved_state *new_cap)
  173. {
  174. hlist_add_head(&new_cap->next, &pci_dev->saved_cap_space);
  175. }
  176. /*
  177. * For PCI devices, the region numbers are assigned this way:
  178. *
  179. * 0-5 standard PCI regions
  180. * 6 expansion ROM
  181. * 7-10 bridges: address space assigned to buses behind the bridge
  182. */
  183. #define PCI_ROM_RESOURCE 6
  184. #define PCI_BRIDGE_RESOURCES 7
  185. #define PCI_NUM_RESOURCES 11
  186. #ifndef PCI_BUS_NUM_RESOURCES
  187. #define PCI_BUS_NUM_RESOURCES 8
  188. #endif
  189. #define PCI_REGION_FLAG_MASK 0x0fU /* These bits of resource flags tell us the PCI region flags */
  190. struct pci_bus {
  191. struct list_head node; /* node in list of buses */
  192. struct pci_bus *parent; /* parent bus this bridge is on */
  193. struct list_head children; /* list of child buses */
  194. struct list_head devices; /* list of devices on this bus */
  195. struct pci_dev *self; /* bridge device as seen by parent */
  196. struct resource *resource[PCI_BUS_NUM_RESOURCES];
  197. /* address space routed to this bus */
  198. struct pci_ops *ops; /* configuration access functions */
  199. void *sysdata; /* hook for sys-specific extension */
  200. struct proc_dir_entry *procdir; /* directory entry in /proc/bus/pci */
  201. unsigned char number; /* bus number */
  202. unsigned char primary; /* number of primary bridge */
  203. unsigned char secondary; /* number of secondary bridge */
  204. unsigned char subordinate; /* max number of subordinate buses */
  205. char name[48];
  206. unsigned short bridge_ctl; /* manage NO_ISA/FBB/et al behaviors */
  207. pci_bus_flags_t bus_flags; /* Inherited by child busses */
  208. struct device *bridge;
  209. struct class_device class_dev;
  210. struct bin_attribute *legacy_io; /* legacy I/O for this bus */
  211. struct bin_attribute *legacy_mem; /* legacy mem */
  212. };
  213. #define pci_bus_b(n) list_entry(n, struct pci_bus, node)
  214. #define to_pci_bus(n) container_of(n, struct pci_bus, class_dev)
  215. /*
  216. * Error values that may be returned by PCI functions.
  217. */
  218. #define PCIBIOS_SUCCESSFUL 0x00
  219. #define PCIBIOS_FUNC_NOT_SUPPORTED 0x81
  220. #define PCIBIOS_BAD_VENDOR_ID 0x83
  221. #define PCIBIOS_DEVICE_NOT_FOUND 0x86
  222. #define PCIBIOS_BAD_REGISTER_NUMBER 0x87
  223. #define PCIBIOS_SET_FAILED 0x88
  224. #define PCIBIOS_BUFFER_TOO_SMALL 0x89
  225. /* Low-level architecture-dependent routines */
  226. struct pci_ops {
  227. int (*read)(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 *val);
  228. int (*write)(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 val);
  229. };
  230. struct pci_raw_ops {
  231. int (*read)(unsigned int domain, unsigned int bus, unsigned int devfn,
  232. int reg, int len, u32 *val);
  233. int (*write)(unsigned int domain, unsigned int bus, unsigned int devfn,
  234. int reg, int len, u32 val);
  235. };
  236. extern struct pci_raw_ops *raw_pci_ops;
  237. struct pci_bus_region {
  238. unsigned long start;
  239. unsigned long end;
  240. };
  241. struct pci_dynids {
  242. spinlock_t lock; /* protects list, index */
  243. struct list_head list; /* for IDs added at runtime */
  244. unsigned int use_driver_data:1; /* pci_driver->driver_data is used */
  245. };
  246. /* ---------------------------------------------------------------- */
  247. /** PCI Error Recovery System (PCI-ERS). If a PCI device driver provides
  248. * a set fof callbacks in struct pci_error_handlers, then that device driver
  249. * will be notified of PCI bus errors, and will be driven to recovery
  250. * when an error occurs.
  251. */
  252. typedef unsigned int __bitwise pci_ers_result_t;
  253. enum pci_ers_result {
  254. /* no result/none/not supported in device driver */
  255. PCI_ERS_RESULT_NONE = (__force pci_ers_result_t) 1,
  256. /* Device driver can recover without slot reset */
  257. PCI_ERS_RESULT_CAN_RECOVER = (__force pci_ers_result_t) 2,
  258. /* Device driver wants slot to be reset. */
  259. PCI_ERS_RESULT_NEED_RESET = (__force pci_ers_result_t) 3,
  260. /* Device has completely failed, is unrecoverable */
  261. PCI_ERS_RESULT_DISCONNECT = (__force pci_ers_result_t) 4,
  262. /* Device driver is fully recovered and operational */
  263. PCI_ERS_RESULT_RECOVERED = (__force pci_ers_result_t) 5,
  264. };
  265. /* PCI bus error event callbacks */
  266. struct pci_error_handlers
  267. {
  268. /* PCI bus error detected on this device */
  269. pci_ers_result_t (*error_detected)(struct pci_dev *dev,
  270. enum pci_channel_state error);
  271. /* MMIO has been re-enabled, but not DMA */
  272. pci_ers_result_t (*mmio_enabled)(struct pci_dev *dev);
  273. /* PCI Express link has been reset */
  274. pci_ers_result_t (*link_reset)(struct pci_dev *dev);
  275. /* PCI slot has been reset */
  276. pci_ers_result_t (*slot_reset)(struct pci_dev *dev);
  277. /* Device driver may resume normal operations */
  278. void (*resume)(struct pci_dev *dev);
  279. };
  280. /* ---------------------------------------------------------------- */
  281. struct module;
  282. struct pci_driver {
  283. struct list_head node;
  284. char *name;
  285. const struct pci_device_id *id_table; /* must be non-NULL for probe to be called */
  286. int (*probe) (struct pci_dev *dev, const struct pci_device_id *id); /* New device inserted */
  287. void (*remove) (struct pci_dev *dev); /* Device removed (NULL if not a hot-plug capable driver) */
  288. int (*suspend) (struct pci_dev *dev, pm_message_t state); /* Device suspended */
  289. int (*suspend_late) (struct pci_dev *dev, pm_message_t state);
  290. int (*resume_early) (struct pci_dev *dev);
  291. int (*resume) (struct pci_dev *dev); /* Device woken up */
  292. int (*enable_wake) (struct pci_dev *dev, pci_power_t state, int enable); /* Enable wake event */
  293. void (*shutdown) (struct pci_dev *dev);
  294. struct pci_error_handlers *err_handler;
  295. struct device_driver driver;
  296. struct pci_dynids dynids;
  297. int multithread_probe;
  298. };
  299. #define to_pci_driver(drv) container_of(drv,struct pci_driver, driver)
  300. /**
  301. * PCI_DEVICE - macro used to describe a specific pci device
  302. * @vend: the 16 bit PCI Vendor ID
  303. * @dev: the 16 bit PCI Device ID
  304. *
  305. * This macro is used to create a struct pci_device_id that matches a
  306. * specific device. The subvendor and subdevice fields will be set to
  307. * PCI_ANY_ID.
  308. */
  309. #define PCI_DEVICE(vend,dev) \
  310. .vendor = (vend), .device = (dev), \
  311. .subvendor = PCI_ANY_ID, .subdevice = PCI_ANY_ID
  312. /**
  313. * PCI_DEVICE_CLASS - macro used to describe a specific pci device class
  314. * @dev_class: the class, subclass, prog-if triple for this device
  315. * @dev_class_mask: the class mask for this device
  316. *
  317. * This macro is used to create a struct pci_device_id that matches a
  318. * specific PCI class. The vendor, device, subvendor, and subdevice
  319. * fields will be set to PCI_ANY_ID.
  320. */
  321. #define PCI_DEVICE_CLASS(dev_class,dev_class_mask) \
  322. .class = (dev_class), .class_mask = (dev_class_mask), \
  323. .vendor = PCI_ANY_ID, .device = PCI_ANY_ID, \
  324. .subvendor = PCI_ANY_ID, .subdevice = PCI_ANY_ID
  325. /*
  326. * pci_module_init is obsolete, this stays here till we fix up all usages of it
  327. * in the tree.
  328. */
  329. #define pci_module_init pci_register_driver
  330. /**
  331. * PCI_VDEVICE - macro used to describe a specific pci device in short form
  332. * @vend: the vendor name
  333. * @dev: the 16 bit PCI Device ID
  334. *
  335. * This macro is used to create a struct pci_device_id that matches a
  336. * specific PCI device. The subvendor, and subdevice fields will be set
  337. * to PCI_ANY_ID. The macro allows the next field to follow as the device
  338. * private data.
  339. */
  340. #define PCI_VDEVICE(vendor, device) \
  341. PCI_VENDOR_ID_##vendor, (device), \
  342. PCI_ANY_ID, PCI_ANY_ID, 0, 0
  343. /* these external functions are only available when PCI support is enabled */
  344. #ifdef CONFIG_PCI
  345. extern struct bus_type pci_bus_type;
  346. /* Do NOT directly access these two variables, unless you are arch specific pci
  347. * code, or pci core code. */
  348. extern struct list_head pci_root_buses; /* list of all known PCI buses */
  349. extern struct list_head pci_devices; /* list of all devices */
  350. void pcibios_fixup_bus(struct pci_bus *);
  351. int __must_check pcibios_enable_device(struct pci_dev *, int mask);
  352. char *pcibios_setup (char *str);
  353. /* Used only when drivers/pci/setup.c is used */
  354. void pcibios_align_resource(void *, struct resource *, resource_size_t,
  355. resource_size_t);
  356. void pcibios_update_irq(struct pci_dev *, int irq);
  357. /* Generic PCI functions used internally */
  358. extern struct pci_bus *pci_find_bus(int domain, int busnr);
  359. void pci_bus_add_devices(struct pci_bus *bus);
  360. struct pci_bus *pci_scan_bus_parented(struct device *parent, int bus, struct pci_ops *ops, void *sysdata);
  361. static inline struct pci_bus *pci_scan_bus(int bus, struct pci_ops *ops, void *sysdata)
  362. {
  363. struct pci_bus *root_bus;
  364. root_bus = pci_scan_bus_parented(NULL, bus, ops, sysdata);
  365. if (root_bus)
  366. pci_bus_add_devices(root_bus);
  367. return root_bus;
  368. }
  369. struct pci_bus *pci_create_bus(struct device *parent, int bus, struct pci_ops *ops, void *sysdata);
  370. struct pci_bus * pci_add_new_bus(struct pci_bus *parent, struct pci_dev *dev, int busnr);
  371. int pci_scan_slot(struct pci_bus *bus, int devfn);
  372. struct pci_dev * pci_scan_single_device(struct pci_bus *bus, int devfn);
  373. void pci_device_add(struct pci_dev *dev, struct pci_bus *bus);
  374. unsigned int pci_scan_child_bus(struct pci_bus *bus);
  375. int __must_check pci_bus_add_device(struct pci_dev *dev);
  376. void pci_read_bridge_bases(struct pci_bus *child);
  377. struct resource *pci_find_parent_resource(const struct pci_dev *dev, struct resource *res);
  378. int pci_get_interrupt_pin(struct pci_dev *dev, struct pci_dev **bridge);
  379. extern struct pci_dev *pci_dev_get(struct pci_dev *dev);
  380. extern void pci_dev_put(struct pci_dev *dev);
  381. extern void pci_remove_bus(struct pci_bus *b);
  382. extern void pci_remove_bus_device(struct pci_dev *dev);
  383. extern void pci_stop_bus_device(struct pci_dev *dev);
  384. void pci_setup_cardbus(struct pci_bus *bus);
  385. extern void pci_sort_breadthfirst(void);
  386. /* Generic PCI functions exported to card drivers */
  387. struct pci_dev __deprecated *pci_find_device (unsigned int vendor, unsigned int device, const struct pci_dev *from);
  388. struct pci_dev *pci_find_slot (unsigned int bus, unsigned int devfn);
  389. int pci_find_capability (struct pci_dev *dev, int cap);
  390. int pci_find_next_capability (struct pci_dev *dev, u8 pos, int cap);
  391. int pci_find_ext_capability (struct pci_dev *dev, int cap);
  392. int pci_find_ht_capability (struct pci_dev *dev, int ht_cap);
  393. int pci_find_next_ht_capability (struct pci_dev *dev, int pos, int ht_cap);
  394. struct pci_bus *pci_find_next_bus(const struct pci_bus *from);
  395. struct pci_dev *pci_get_device(unsigned int vendor, unsigned int device,
  396. struct pci_dev *from);
  397. struct pci_dev *pci_get_device_reverse(unsigned int vendor, unsigned int device,
  398. struct pci_dev *from);
  399. struct pci_dev *pci_get_subsys (unsigned int vendor, unsigned int device,
  400. unsigned int ss_vendor, unsigned int ss_device,
  401. struct pci_dev *from);
  402. struct pci_dev *pci_get_slot (struct pci_bus *bus, unsigned int devfn);
  403. struct pci_dev *pci_get_bus_and_slot (unsigned int bus, unsigned int devfn);
  404. struct pci_dev *pci_get_class (unsigned int class, struct pci_dev *from);
  405. int pci_dev_present(const struct pci_device_id *ids);
  406. const struct pci_device_id *pci_find_present(const struct pci_device_id *ids);
  407. int pci_bus_read_config_byte (struct pci_bus *bus, unsigned int devfn, int where, u8 *val);
  408. int pci_bus_read_config_word (struct pci_bus *bus, unsigned int devfn, int where, u16 *val);
  409. int pci_bus_read_config_dword (struct pci_bus *bus, unsigned int devfn, int where, u32 *val);
  410. int pci_bus_write_config_byte (struct pci_bus *bus, unsigned int devfn, int where, u8 val);
  411. int pci_bus_write_config_word (struct pci_bus *bus, unsigned int devfn, int where, u16 val);
  412. int pci_bus_write_config_dword (struct pci_bus *bus, unsigned int devfn, int where, u32 val);
  413. static inline int pci_read_config_byte(struct pci_dev *dev, int where, u8 *val)
  414. {
  415. return pci_bus_read_config_byte (dev->bus, dev->devfn, where, val);
  416. }
  417. static inline int pci_read_config_word(struct pci_dev *dev, int where, u16 *val)
  418. {
  419. return pci_bus_read_config_word (dev->bus, dev->devfn, where, val);
  420. }
  421. static inline int pci_read_config_dword(struct pci_dev *dev, int where, u32 *val)
  422. {
  423. return pci_bus_read_config_dword (dev->bus, dev->devfn, where, val);
  424. }
  425. static inline int pci_write_config_byte(struct pci_dev *dev, int where, u8 val)
  426. {
  427. return pci_bus_write_config_byte (dev->bus, dev->devfn, where, val);
  428. }
  429. static inline int pci_write_config_word(struct pci_dev *dev, int where, u16 val)
  430. {
  431. return pci_bus_write_config_word (dev->bus, dev->devfn, where, val);
  432. }
  433. static inline int pci_write_config_dword(struct pci_dev *dev, int where, u32 val)
  434. {
  435. return pci_bus_write_config_dword (dev->bus, dev->devfn, where, val);
  436. }
  437. int __must_check pci_enable_device(struct pci_dev *dev);
  438. int __must_check pci_enable_device_bars(struct pci_dev *dev, int mask);
  439. int __must_check pcim_enable_device(struct pci_dev *pdev);
  440. void pcim_pin_device(struct pci_dev *pdev);
  441. static inline int pci_is_managed(struct pci_dev *pdev)
  442. {
  443. return pdev->is_managed;
  444. }
  445. void pci_disable_device(struct pci_dev *dev);
  446. void pci_set_master(struct pci_dev *dev);
  447. #define HAVE_PCI_SET_MWI
  448. int __must_check pci_set_mwi(struct pci_dev *dev);
  449. void pci_clear_mwi(struct pci_dev *dev);
  450. void pci_intx(struct pci_dev *dev, int enable);
  451. void pci_msi_off(struct pci_dev *dev);
  452. int pci_set_dma_mask(struct pci_dev *dev, u64 mask);
  453. int pci_set_consistent_dma_mask(struct pci_dev *dev, u64 mask);
  454. void pci_update_resource(struct pci_dev *dev, struct resource *res, int resno);
  455. int __must_check pci_assign_resource(struct pci_dev *dev, int i);
  456. int __must_check pci_assign_resource_fixed(struct pci_dev *dev, int i);
  457. void pci_restore_bars(struct pci_dev *dev);
  458. int pci_select_bars(struct pci_dev *dev, unsigned long flags);
  459. /* ROM control related routines */
  460. void __iomem __must_check *pci_map_rom(struct pci_dev *pdev, size_t *size);
  461. void __iomem __must_check *pci_map_rom_copy(struct pci_dev *pdev, size_t *size);
  462. void pci_unmap_rom(struct pci_dev *pdev, void __iomem *rom);
  463. void pci_remove_rom(struct pci_dev *pdev);
  464. /* Power management related routines */
  465. int pci_save_state(struct pci_dev *dev);
  466. int pci_restore_state(struct pci_dev *dev);
  467. int pci_set_power_state(struct pci_dev *dev, pci_power_t state);
  468. pci_power_t pci_choose_state(struct pci_dev *dev, pm_message_t state);
  469. int pci_enable_wake(struct pci_dev *dev, pci_power_t state, int enable);
  470. /* Helper functions for low-level code (drivers/pci/setup-[bus,res].c) */
  471. void pci_bus_assign_resources(struct pci_bus *bus);
  472. void pci_bus_size_bridges(struct pci_bus *bus);
  473. int pci_claim_resource(struct pci_dev *, int);
  474. void pci_assign_unassigned_resources(void);
  475. void pdev_enable_device(struct pci_dev *);
  476. void pdev_sort_resources(struct pci_dev *, struct resource_list *);
  477. void pci_fixup_irqs(u8 (*)(struct pci_dev *, u8 *),
  478. int (*)(struct pci_dev *, u8, u8));
  479. #define HAVE_PCI_REQ_REGIONS 2
  480. int __must_check pci_request_regions(struct pci_dev *, const char *);
  481. void pci_release_regions(struct pci_dev *);
  482. int __must_check pci_request_region(struct pci_dev *, int, const char *);
  483. void pci_release_region(struct pci_dev *, int);
  484. int pci_request_selected_regions(struct pci_dev *, int, const char *);
  485. void pci_release_selected_regions(struct pci_dev *, int);
  486. /* drivers/pci/bus.c */
  487. int __must_check pci_bus_alloc_resource(struct pci_bus *bus,
  488. struct resource *res, resource_size_t size,
  489. resource_size_t align, resource_size_t min,
  490. unsigned int type_mask,
  491. void (*alignf)(void *, struct resource *,
  492. resource_size_t, resource_size_t),
  493. void *alignf_data);
  494. void pci_enable_bridges(struct pci_bus *bus);
  495. /* Proper probing supporting hot-pluggable devices */
  496. int __must_check __pci_register_driver(struct pci_driver *, struct module *,
  497. const char *mod_name);
  498. static inline int __must_check pci_register_driver(struct pci_driver *driver)
  499. {
  500. return __pci_register_driver(driver, THIS_MODULE, KBUILD_MODNAME);
  501. }
  502. void pci_unregister_driver(struct pci_driver *);
  503. void pci_remove_behind_bridge(struct pci_dev *);
  504. struct pci_driver *pci_dev_driver(const struct pci_dev *);
  505. const struct pci_device_id *pci_match_device(struct pci_driver *drv, struct pci_dev *dev);
  506. const struct pci_device_id *pci_match_id(const struct pci_device_id *ids, struct pci_dev *dev);
  507. int pci_scan_bridge(struct pci_bus *bus, struct pci_dev * dev, int max, int pass);
  508. void pci_walk_bus(struct pci_bus *top, void (*cb)(struct pci_dev *, void *),
  509. void *userdata);
  510. int pci_cfg_space_size(struct pci_dev *dev);
  511. unsigned char pci_bus_max_busnr(struct pci_bus* bus);
  512. /* kmem_cache style wrapper around pci_alloc_consistent() */
  513. #include <linux/dmapool.h>
  514. #define pci_pool dma_pool
  515. #define pci_pool_create(name, pdev, size, align, allocation) \
  516. dma_pool_create(name, &pdev->dev, size, align, allocation)
  517. #define pci_pool_destroy(pool) dma_pool_destroy(pool)
  518. #define pci_pool_alloc(pool, flags, handle) dma_pool_alloc(pool, flags, handle)
  519. #define pci_pool_free(pool, vaddr, addr) dma_pool_free(pool, vaddr, addr)
  520. enum pci_dma_burst_strategy {
  521. PCI_DMA_BURST_INFINITY, /* make bursts as large as possible,
  522. strategy_parameter is N/A */
  523. PCI_DMA_BURST_BOUNDARY, /* disconnect at every strategy_parameter
  524. byte boundaries */
  525. PCI_DMA_BURST_MULTIPLE, /* disconnect at some multiple of
  526. strategy_parameter byte boundaries */
  527. };
  528. struct msix_entry {
  529. u16 vector; /* kernel uses to write allocated vector */
  530. u16 entry; /* driver uses to specify entry, OS writes */
  531. };
  532. #ifndef CONFIG_PCI_MSI
  533. static inline int pci_enable_msi(struct pci_dev *dev) {return -1;}
  534. static inline void pci_disable_msi(struct pci_dev *dev) {}
  535. static inline int pci_enable_msix(struct pci_dev* dev,
  536. struct msix_entry *entries, int nvec) {return -1;}
  537. static inline void pci_disable_msix(struct pci_dev *dev) {}
  538. static inline void msi_remove_pci_irq_vectors(struct pci_dev *dev) {}
  539. #else
  540. extern int pci_enable_msi(struct pci_dev *dev);
  541. extern void pci_disable_msi(struct pci_dev *dev);
  542. extern int pci_enable_msix(struct pci_dev* dev,
  543. struct msix_entry *entries, int nvec);
  544. extern void pci_disable_msix(struct pci_dev *dev);
  545. extern void msi_remove_pci_irq_vectors(struct pci_dev *dev);
  546. #endif
  547. #ifdef CONFIG_HT_IRQ
  548. /* The functions a driver should call */
  549. int ht_create_irq(struct pci_dev *dev, int idx);
  550. void ht_destroy_irq(unsigned int irq);
  551. #endif /* CONFIG_HT_IRQ */
  552. extern void pci_block_user_cfg_access(struct pci_dev *dev);
  553. extern void pci_unblock_user_cfg_access(struct pci_dev *dev);
  554. /*
  555. * PCI domain support. Sometimes called PCI segment (eg by ACPI),
  556. * a PCI domain is defined to be a set of PCI busses which share
  557. * configuration space.
  558. */
  559. #ifndef CONFIG_PCI_DOMAINS
  560. static inline int pci_domain_nr(struct pci_bus *bus) { return 0; }
  561. static inline int pci_proc_domain(struct pci_bus *bus)
  562. {
  563. return 0;
  564. }
  565. #endif
  566. #else /* CONFIG_PCI is not enabled */
  567. /*
  568. * If the system does not have PCI, clearly these return errors. Define
  569. * these as simple inline functions to avoid hair in drivers.
  570. */
  571. #define _PCI_NOP(o,s,t) \
  572. static inline int pci_##o##_config_##s (struct pci_dev *dev, int where, t val) \
  573. { return PCIBIOS_FUNC_NOT_SUPPORTED; }
  574. #define _PCI_NOP_ALL(o,x) _PCI_NOP(o,byte,u8 x) \
  575. _PCI_NOP(o,word,u16 x) \
  576. _PCI_NOP(o,dword,u32 x)
  577. _PCI_NOP_ALL(read, *)
  578. _PCI_NOP_ALL(write,)
  579. static inline struct pci_dev *pci_find_device(unsigned int vendor, unsigned int device, const struct pci_dev *from)
  580. { return NULL; }
  581. static inline struct pci_dev *pci_find_slot(unsigned int bus, unsigned int devfn)
  582. { return NULL; }
  583. static inline struct pci_dev *pci_get_device(unsigned int vendor,
  584. unsigned int device, struct pci_dev *from)
  585. { return NULL; }
  586. static inline struct pci_dev *pci_get_device_reverse(unsigned int vendor,
  587. unsigned int device, struct pci_dev *from)
  588. { return NULL; }
  589. static inline struct pci_dev *pci_get_subsys (unsigned int vendor, unsigned int device,
  590. unsigned int ss_vendor, unsigned int ss_device, struct pci_dev *from)
  591. { return NULL; }
  592. static inline struct pci_dev *pci_get_class(unsigned int class, struct pci_dev *from)
  593. { return NULL; }
  594. #define pci_dev_present(ids) (0)
  595. #define pci_find_present(ids) (NULL)
  596. #define pci_dev_put(dev) do { } while (0)
  597. static inline void pci_set_master(struct pci_dev *dev) { }
  598. static inline int pci_enable_device(struct pci_dev *dev) { return -EIO; }
  599. static inline void pci_disable_device(struct pci_dev *dev) { }
  600. static inline int pci_set_dma_mask(struct pci_dev *dev, u64 mask) { return -EIO; }
  601. static inline int pci_assign_resource(struct pci_dev *dev, int i) { return -EBUSY;}
  602. static inline int __pci_register_driver(struct pci_driver *drv, struct module *owner) { return 0;}
  603. static inline int pci_register_driver(struct pci_driver *drv) { return 0;}
  604. static inline void pci_unregister_driver(struct pci_driver *drv) { }
  605. static inline int pci_find_capability (struct pci_dev *dev, int cap) {return 0; }
  606. static inline int pci_find_next_capability (struct pci_dev *dev, u8 post, int cap) { return 0; }
  607. static inline int pci_find_ext_capability (struct pci_dev *dev, int cap) {return 0; }
  608. static inline const struct pci_device_id *pci_match_device(const struct pci_device_id *ids, const struct pci_dev *dev) { return NULL; }
  609. /* Power management related routines */
  610. static inline int pci_save_state(struct pci_dev *dev) { return 0; }
  611. static inline int pci_restore_state(struct pci_dev *dev) { return 0; }
  612. static inline int pci_set_power_state(struct pci_dev *dev, pci_power_t state) { return 0; }
  613. static inline pci_power_t pci_choose_state(struct pci_dev *dev, pm_message_t state) { return PCI_D0; }
  614. static inline int pci_enable_wake(struct pci_dev *dev, pci_power_t state, int enable) { return 0; }
  615. #define pci_dma_burst_advice(pdev, strat, strategy_parameter) do { } while (0)
  616. static inline void pci_block_user_cfg_access(struct pci_dev *dev) { }
  617. static inline void pci_unblock_user_cfg_access(struct pci_dev *dev) { }
  618. #endif /* CONFIG_PCI */
  619. /* Include architecture-dependent settings and functions */
  620. #include <asm/pci.h>
  621. /* these helpers provide future and backwards compatibility
  622. * for accessing popular PCI BAR info */
  623. #define pci_resource_start(dev,bar) ((dev)->resource[(bar)].start)
  624. #define pci_resource_end(dev,bar) ((dev)->resource[(bar)].end)
  625. #define pci_resource_flags(dev,bar) ((dev)->resource[(bar)].flags)
  626. #define pci_resource_len(dev,bar) \
  627. ((pci_resource_start((dev),(bar)) == 0 && \
  628. pci_resource_end((dev),(bar)) == \
  629. pci_resource_start((dev),(bar))) ? 0 : \
  630. \
  631. (pci_resource_end((dev),(bar)) - \
  632. pci_resource_start((dev),(bar)) + 1))
  633. /* Similar to the helpers above, these manipulate per-pci_dev
  634. * driver-specific data. They are really just a wrapper around
  635. * the generic device structure functions of these calls.
  636. */
  637. static inline void *pci_get_drvdata (struct pci_dev *pdev)
  638. {
  639. return dev_get_drvdata(&pdev->dev);
  640. }
  641. static inline void pci_set_drvdata (struct pci_dev *pdev, void *data)
  642. {
  643. dev_set_drvdata(&pdev->dev, data);
  644. }
  645. /* If you want to know what to call your pci_dev, ask this function.
  646. * Again, it's a wrapper around the generic device.
  647. */
  648. static inline char *pci_name(struct pci_dev *pdev)
  649. {
  650. return pdev->dev.bus_id;
  651. }
  652. /* Some archs don't want to expose struct resource to userland as-is
  653. * in sysfs and /proc
  654. */
  655. #ifndef HAVE_ARCH_PCI_RESOURCE_TO_USER
  656. static inline void pci_resource_to_user(const struct pci_dev *dev, int bar,
  657. const struct resource *rsrc, resource_size_t *start,
  658. resource_size_t *end)
  659. {
  660. *start = rsrc->start;
  661. *end = rsrc->end;
  662. }
  663. #endif /* HAVE_ARCH_PCI_RESOURCE_TO_USER */
  664. /*
  665. * The world is not perfect and supplies us with broken PCI devices.
  666. * For at least a part of these bugs we need a work-around, so both
  667. * generic (drivers/pci/quirks.c) and per-architecture code can define
  668. * fixup hooks to be called for particular buggy devices.
  669. */
  670. struct pci_fixup {
  671. u16 vendor, device; /* You can use PCI_ANY_ID here of course */
  672. void (*hook)(struct pci_dev *dev);
  673. };
  674. enum pci_fixup_pass {
  675. pci_fixup_early, /* Before probing BARs */
  676. pci_fixup_header, /* After reading configuration header */
  677. pci_fixup_final, /* Final phase of device fixups */
  678. pci_fixup_enable, /* pci_enable_device() time */
  679. pci_fixup_resume, /* pci_enable_device() time */
  680. };
  681. /* Anonymous variables would be nice... */
  682. #define DECLARE_PCI_FIXUP_SECTION(section, name, vendor, device, hook) \
  683. static const struct pci_fixup __pci_fixup_##name __attribute_used__ \
  684. __attribute__((__section__(#section))) = { vendor, device, hook };
  685. #define DECLARE_PCI_FIXUP_EARLY(vendor, device, hook) \
  686. DECLARE_PCI_FIXUP_SECTION(.pci_fixup_early, \
  687. vendor##device##hook, vendor, device, hook)
  688. #define DECLARE_PCI_FIXUP_HEADER(vendor, device, hook) \
  689. DECLARE_PCI_FIXUP_SECTION(.pci_fixup_header, \
  690. vendor##device##hook, vendor, device, hook)
  691. #define DECLARE_PCI_FIXUP_FINAL(vendor, device, hook) \
  692. DECLARE_PCI_FIXUP_SECTION(.pci_fixup_final, \
  693. vendor##device##hook, vendor, device, hook)
  694. #define DECLARE_PCI_FIXUP_ENABLE(vendor, device, hook) \
  695. DECLARE_PCI_FIXUP_SECTION(.pci_fixup_enable, \
  696. vendor##device##hook, vendor, device, hook)
  697. #define DECLARE_PCI_FIXUP_RESUME(vendor, device, hook) \
  698. DECLARE_PCI_FIXUP_SECTION(.pci_fixup_resume, \
  699. resume##vendor##device##hook, vendor, device, hook)
  700. void pci_fixup_device(enum pci_fixup_pass pass, struct pci_dev *dev);
  701. void __iomem * pcim_iomap(struct pci_dev *pdev, int bar, unsigned long maxlen);
  702. void pcim_iounmap(struct pci_dev *pdev, void __iomem *addr);
  703. void __iomem * const * pcim_iomap_table(struct pci_dev *pdev);
  704. int pcim_iomap_regions(struct pci_dev *pdev, u16 mask, const char *name);
  705. extern int pci_pci_problems;
  706. #define PCIPCI_FAIL 1 /* No PCI PCI DMA */
  707. #define PCIPCI_TRITON 2
  708. #define PCIPCI_NATOMA 4
  709. #define PCIPCI_VIAETBF 8
  710. #define PCIPCI_VSFX 16
  711. #define PCIPCI_ALIMAGIK 32 /* Need low latency setting */
  712. #define PCIAGP_FAIL 64 /* No PCI to AGP DMA */
  713. extern unsigned long pci_cardbus_io_size;
  714. extern unsigned long pci_cardbus_mem_size;
  715. #endif /* __KERNEL__ */
  716. #endif /* LINUX_PCI_H */