pci.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. #ifndef DRIVERS_PCI_H
  2. #define DRIVERS_PCI_H
  3. #include <linux/workqueue.h>
  4. #define PCI_CFG_SPACE_SIZE 256
  5. #define PCI_CFG_SPACE_EXP_SIZE 4096
  6. /* Functions internal to the PCI core code */
  7. extern int pci_uevent(struct device *dev, struct kobj_uevent_env *env);
  8. extern int pci_create_sysfs_dev_files(struct pci_dev *pdev);
  9. extern void pci_remove_sysfs_dev_files(struct pci_dev *pdev);
  10. extern void pci_cleanup_rom(struct pci_dev *dev);
  11. #ifdef HAVE_PCI_MMAP
  12. extern int pci_mmap_fits(struct pci_dev *pdev, int resno,
  13. struct vm_area_struct *vma);
  14. #endif
  15. int pci_probe_reset_function(struct pci_dev *dev);
  16. /**
  17. * struct pci_platform_pm_ops - Firmware PM callbacks
  18. *
  19. * @is_manageable: returns 'true' if given device is power manageable by the
  20. * platform firmware
  21. *
  22. * @set_state: invokes the platform firmware to set the device's power state
  23. *
  24. * @choose_state: returns PCI power state of given device preferred by the
  25. * platform; to be used during system-wide transitions from a
  26. * sleeping state to the working state and vice versa
  27. *
  28. * @can_wakeup: returns 'true' if given device is capable of waking up the
  29. * system from a sleeping state
  30. *
  31. * @sleep_wake: enables/disables the system wake up capability of given device
  32. *
  33. * @run_wake: enables/disables the platform to generate run-time wake-up events
  34. * for given device (the device's wake-up capability has to be
  35. * enabled by @sleep_wake for this feature to work)
  36. *
  37. * If given platform is generally capable of power managing PCI devices, all of
  38. * these callbacks are mandatory.
  39. */
  40. struct pci_platform_pm_ops {
  41. bool (*is_manageable)(struct pci_dev *dev);
  42. int (*set_state)(struct pci_dev *dev, pci_power_t state);
  43. pci_power_t (*choose_state)(struct pci_dev *dev);
  44. bool (*can_wakeup)(struct pci_dev *dev);
  45. int (*sleep_wake)(struct pci_dev *dev, bool enable);
  46. int (*run_wake)(struct pci_dev *dev, bool enable);
  47. };
  48. extern int pci_set_platform_pm(struct pci_platform_pm_ops *ops);
  49. extern void pci_update_current_state(struct pci_dev *dev, pci_power_t state);
  50. extern void pci_disable_enabled_device(struct pci_dev *dev);
  51. extern bool pci_check_pme_status(struct pci_dev *dev);
  52. extern int pci_finish_runtime_suspend(struct pci_dev *dev);
  53. extern void pci_wakeup_event(struct pci_dev *dev);
  54. extern int __pci_pme_wakeup(struct pci_dev *dev, void *ign);
  55. extern void pci_pme_wakeup_bus(struct pci_bus *bus);
  56. extern void pci_pm_init(struct pci_dev *dev);
  57. extern void platform_pci_wakeup_init(struct pci_dev *dev);
  58. extern void pci_allocate_cap_save_buffers(struct pci_dev *dev);
  59. static inline bool pci_is_bridge(struct pci_dev *pci_dev)
  60. {
  61. return !!(pci_dev->subordinate);
  62. }
  63. extern int pci_user_read_config_byte(struct pci_dev *dev, int where, u8 *val);
  64. extern int pci_user_read_config_word(struct pci_dev *dev, int where, u16 *val);
  65. extern int pci_user_read_config_dword(struct pci_dev *dev, int where, u32 *val);
  66. extern int pci_user_write_config_byte(struct pci_dev *dev, int where, u8 val);
  67. extern int pci_user_write_config_word(struct pci_dev *dev, int where, u16 val);
  68. extern int pci_user_write_config_dword(struct pci_dev *dev, int where, u32 val);
  69. struct pci_vpd_ops {
  70. ssize_t (*read)(struct pci_dev *dev, loff_t pos, size_t count, void *buf);
  71. ssize_t (*write)(struct pci_dev *dev, loff_t pos, size_t count, const void *buf);
  72. void (*release)(struct pci_dev *dev);
  73. };
  74. struct pci_vpd {
  75. unsigned int len;
  76. const struct pci_vpd_ops *ops;
  77. struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
  78. };
  79. extern int pci_vpd_pci22_init(struct pci_dev *dev);
  80. static inline void pci_vpd_release(struct pci_dev *dev)
  81. {
  82. if (dev->vpd)
  83. dev->vpd->ops->release(dev);
  84. }
  85. /* PCI /proc functions */
  86. #ifdef CONFIG_PROC_FS
  87. extern int pci_proc_attach_device(struct pci_dev *dev);
  88. extern int pci_proc_detach_device(struct pci_dev *dev);
  89. extern int pci_proc_detach_bus(struct pci_bus *bus);
  90. #else
  91. static inline int pci_proc_attach_device(struct pci_dev *dev) { return 0; }
  92. static inline int pci_proc_detach_device(struct pci_dev *dev) { return 0; }
  93. static inline int pci_proc_detach_bus(struct pci_bus *bus) { return 0; }
  94. #endif
  95. /* Functions for PCI Hotplug drivers to use */
  96. extern unsigned int pci_do_scan_bus(struct pci_bus *bus);
  97. #ifdef HAVE_PCI_LEGACY
  98. extern void pci_create_legacy_files(struct pci_bus *bus);
  99. extern void pci_remove_legacy_files(struct pci_bus *bus);
  100. #else
  101. static inline void pci_create_legacy_files(struct pci_bus *bus) { return; }
  102. static inline void pci_remove_legacy_files(struct pci_bus *bus) { return; }
  103. #endif
  104. /* Lock for read/write access to pci device and bus lists */
  105. extern struct rw_semaphore pci_bus_sem;
  106. extern unsigned int pci_pm_d3_delay;
  107. #ifdef CONFIG_PCI_MSI
  108. void pci_no_msi(void);
  109. extern void pci_msi_init_pci_dev(struct pci_dev *dev);
  110. #else
  111. static inline void pci_no_msi(void) { }
  112. static inline void pci_msi_init_pci_dev(struct pci_dev *dev) { }
  113. #endif
  114. #ifdef CONFIG_PCIEAER
  115. void pci_no_aer(void);
  116. #else
  117. static inline void pci_no_aer(void) { }
  118. #endif
  119. static inline int pci_no_d1d2(struct pci_dev *dev)
  120. {
  121. unsigned int parent_dstates = 0;
  122. if (dev->bus->self)
  123. parent_dstates = dev->bus->self->no_d1d2;
  124. return (dev->no_d1d2 || parent_dstates);
  125. }
  126. extern struct device_attribute pci_dev_attrs[];
  127. extern struct device_attribute dev_attr_cpuaffinity;
  128. extern struct device_attribute dev_attr_cpulistaffinity;
  129. #ifdef CONFIG_HOTPLUG
  130. extern struct bus_attribute pci_bus_attrs[];
  131. #else
  132. #define pci_bus_attrs NULL
  133. #endif
  134. /**
  135. * pci_match_one_device - Tell if a PCI device structure has a matching
  136. * PCI device id structure
  137. * @id: single PCI device id structure to match
  138. * @dev: the PCI device structure to match against
  139. *
  140. * Returns the matching pci_device_id structure or %NULL if there is no match.
  141. */
  142. static inline const struct pci_device_id *
  143. pci_match_one_device(const struct pci_device_id *id, const struct pci_dev *dev)
  144. {
  145. if ((id->vendor == PCI_ANY_ID || id->vendor == dev->vendor) &&
  146. (id->device == PCI_ANY_ID || id->device == dev->device) &&
  147. (id->subvendor == PCI_ANY_ID || id->subvendor == dev->subsystem_vendor) &&
  148. (id->subdevice == PCI_ANY_ID || id->subdevice == dev->subsystem_device) &&
  149. !((id->class ^ dev->class) & id->class_mask))
  150. return id;
  151. return NULL;
  152. }
  153. struct pci_dev *pci_find_upstream_pcie_bridge(struct pci_dev *pdev);
  154. /* PCI slot sysfs helper code */
  155. #define to_pci_slot(s) container_of(s, struct pci_slot, kobj)
  156. extern struct kset *pci_slots_kset;
  157. struct pci_slot_attribute {
  158. struct attribute attr;
  159. ssize_t (*show)(struct pci_slot *, char *);
  160. ssize_t (*store)(struct pci_slot *, const char *, size_t);
  161. };
  162. #define to_pci_slot_attr(s) container_of(s, struct pci_slot_attribute, attr)
  163. enum pci_bar_type {
  164. pci_bar_unknown, /* Standard PCI BAR probe */
  165. pci_bar_io, /* An io port BAR */
  166. pci_bar_mem32, /* A 32-bit memory BAR */
  167. pci_bar_mem64, /* A 64-bit memory BAR */
  168. };
  169. extern int pci_setup_device(struct pci_dev *dev);
  170. extern int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
  171. struct resource *res, unsigned int reg);
  172. extern int pci_resource_bar(struct pci_dev *dev, int resno,
  173. enum pci_bar_type *type);
  174. extern int pci_bus_add_child(struct pci_bus *bus);
  175. extern void pci_enable_ari(struct pci_dev *dev);
  176. /**
  177. * pci_ari_enabled - query ARI forwarding status
  178. * @bus: the PCI bus
  179. *
  180. * Returns 1 if ARI forwarding is enabled, or 0 if not enabled;
  181. */
  182. static inline int pci_ari_enabled(struct pci_bus *bus)
  183. {
  184. return bus->self && bus->self->ari_enabled;
  185. }
  186. #ifdef CONFIG_PCI_QUIRKS
  187. extern int pci_is_reassigndev(struct pci_dev *dev);
  188. resource_size_t pci_specified_resource_alignment(struct pci_dev *dev);
  189. extern void pci_disable_bridge_window(struct pci_dev *dev);
  190. #endif
  191. /* Single Root I/O Virtualization */
  192. struct pci_sriov {
  193. int pos; /* capability position */
  194. int nres; /* number of resources */
  195. u32 cap; /* SR-IOV Capabilities */
  196. u16 ctrl; /* SR-IOV Control */
  197. u16 total; /* total VFs associated with the PF */
  198. u16 initial; /* initial VFs associated with the PF */
  199. u16 nr_virtfn; /* number of VFs available */
  200. u16 offset; /* first VF Routing ID offset */
  201. u16 stride; /* following VF stride */
  202. u32 pgsz; /* page size for BAR alignment */
  203. u8 link; /* Function Dependency Link */
  204. struct pci_dev *dev; /* lowest numbered PF */
  205. struct pci_dev *self; /* this PF */
  206. struct mutex lock; /* lock for VF bus */
  207. struct work_struct mtask; /* VF Migration task */
  208. u8 __iomem *mstate; /* VF Migration State Array */
  209. };
  210. /* Address Translation Service */
  211. struct pci_ats {
  212. int pos; /* capability position */
  213. int stu; /* Smallest Translation Unit */
  214. int qdep; /* Invalidate Queue Depth */
  215. int ref_cnt; /* Physical Function reference count */
  216. unsigned int is_enabled:1; /* Enable bit is set */
  217. };
  218. #ifdef CONFIG_PCI_IOV
  219. extern int pci_iov_init(struct pci_dev *dev);
  220. extern void pci_iov_release(struct pci_dev *dev);
  221. extern int pci_iov_resource_bar(struct pci_dev *dev, int resno,
  222. enum pci_bar_type *type);
  223. extern int pci_sriov_resource_alignment(struct pci_dev *dev, int resno);
  224. extern void pci_restore_iov_state(struct pci_dev *dev);
  225. extern int pci_iov_bus_range(struct pci_bus *bus);
  226. extern int pci_enable_ats(struct pci_dev *dev, int ps);
  227. extern void pci_disable_ats(struct pci_dev *dev);
  228. extern int pci_ats_queue_depth(struct pci_dev *dev);
  229. /**
  230. * pci_ats_enabled - query the ATS status
  231. * @dev: the PCI device
  232. *
  233. * Returns 1 if ATS capability is enabled, or 0 if not.
  234. */
  235. static inline int pci_ats_enabled(struct pci_dev *dev)
  236. {
  237. return dev->ats && dev->ats->is_enabled;
  238. }
  239. #else
  240. static inline int pci_iov_init(struct pci_dev *dev)
  241. {
  242. return -ENODEV;
  243. }
  244. static inline void pci_iov_release(struct pci_dev *dev)
  245. {
  246. }
  247. static inline int pci_iov_resource_bar(struct pci_dev *dev, int resno,
  248. enum pci_bar_type *type)
  249. {
  250. return 0;
  251. }
  252. static inline void pci_restore_iov_state(struct pci_dev *dev)
  253. {
  254. }
  255. static inline int pci_iov_bus_range(struct pci_bus *bus)
  256. {
  257. return 0;
  258. }
  259. static inline int pci_enable_ats(struct pci_dev *dev, int ps)
  260. {
  261. return -ENODEV;
  262. }
  263. static inline void pci_disable_ats(struct pci_dev *dev)
  264. {
  265. }
  266. static inline int pci_ats_queue_depth(struct pci_dev *dev)
  267. {
  268. return -ENODEV;
  269. }
  270. static inline int pci_ats_enabled(struct pci_dev *dev)
  271. {
  272. return 0;
  273. }
  274. #endif /* CONFIG_PCI_IOV */
  275. static inline int pci_resource_alignment(struct pci_dev *dev,
  276. struct resource *res)
  277. {
  278. #ifdef CONFIG_PCI_IOV
  279. int resno = res - dev->resource;
  280. if (resno >= PCI_IOV_RESOURCES && resno <= PCI_IOV_RESOURCE_END)
  281. return pci_sriov_resource_alignment(dev, resno);
  282. #endif
  283. return resource_alignment(res);
  284. }
  285. extern void pci_enable_acs(struct pci_dev *dev);
  286. struct pci_dev_reset_methods {
  287. u16 vendor;
  288. u16 device;
  289. int (*reset)(struct pci_dev *dev, int probe);
  290. };
  291. #ifdef CONFIG_PCI_QUIRKS
  292. extern int pci_dev_specific_reset(struct pci_dev *dev, int probe);
  293. #else
  294. static inline int pci_dev_specific_reset(struct pci_dev *dev, int probe)
  295. {
  296. return -ENOTTY;
  297. }
  298. #endif
  299. #endif /* DRIVERS_PCI_H */