pci.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /* Functions internal to the PCI core code */
  2. extern int pci_uevent(struct device *dev, struct kobj_uevent_env *env);
  3. extern int pci_create_sysfs_dev_files(struct pci_dev *pdev);
  4. extern void pci_remove_sysfs_dev_files(struct pci_dev *pdev);
  5. extern void pci_cleanup_rom(struct pci_dev *dev);
  6. /**
  7. * Firmware PM callbacks
  8. *
  9. * @is_manageable - returns 'true' if given device is power manageable by the
  10. * platform firmware
  11. *
  12. * @set_state - invokes the platform firmware to set the device's power state
  13. *
  14. * @choose_state - returns PCI power state of given device preferred by the
  15. * platform; to be used during system-wide transitions from a
  16. * sleeping state to the working state and vice versa
  17. *
  18. * If given platform is generally capable of power managing PCI devices, all of
  19. * these callbacks are mandatory.
  20. */
  21. struct pci_platform_pm_ops {
  22. bool (*is_manageable)(struct pci_dev *dev);
  23. int (*set_state)(struct pci_dev *dev, pci_power_t state);
  24. pci_power_t (*choose_state)(struct pci_dev *dev);
  25. };
  26. extern int pci_set_platform_pm(struct pci_platform_pm_ops *ops);
  27. extern int pci_user_read_config_byte(struct pci_dev *dev, int where, u8 *val);
  28. extern int pci_user_read_config_word(struct pci_dev *dev, int where, u16 *val);
  29. extern int pci_user_read_config_dword(struct pci_dev *dev, int where, u32 *val);
  30. extern int pci_user_write_config_byte(struct pci_dev *dev, int where, u8 val);
  31. extern int pci_user_write_config_word(struct pci_dev *dev, int where, u16 val);
  32. extern int pci_user_write_config_dword(struct pci_dev *dev, int where, u32 val);
  33. struct pci_vpd_ops {
  34. int (*read)(struct pci_dev *dev, int pos, int size, char *buf);
  35. int (*write)(struct pci_dev *dev, int pos, int size, const char *buf);
  36. int (*get_size)(struct pci_dev *dev);
  37. void (*release)(struct pci_dev *dev);
  38. };
  39. struct pci_vpd {
  40. struct pci_vpd_ops *ops;
  41. struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
  42. };
  43. extern int pci_vpd_pci22_init(struct pci_dev *dev);
  44. static inline void pci_vpd_release(struct pci_dev *dev)
  45. {
  46. if (dev->vpd)
  47. dev->vpd->ops->release(dev);
  48. }
  49. /* PCI /proc functions */
  50. #ifdef CONFIG_PROC_FS
  51. extern int pci_proc_attach_device(struct pci_dev *dev);
  52. extern int pci_proc_detach_device(struct pci_dev *dev);
  53. extern int pci_proc_detach_bus(struct pci_bus *bus);
  54. #else
  55. static inline int pci_proc_attach_device(struct pci_dev *dev) { return 0; }
  56. static inline int pci_proc_detach_device(struct pci_dev *dev) { return 0; }
  57. static inline int pci_proc_detach_bus(struct pci_bus *bus) { return 0; }
  58. #endif
  59. /* Functions for PCI Hotplug drivers to use */
  60. extern unsigned int pci_do_scan_bus(struct pci_bus *bus);
  61. extern void pci_remove_legacy_files(struct pci_bus *bus);
  62. /* Lock for read/write access to pci device and bus lists */
  63. extern struct rw_semaphore pci_bus_sem;
  64. extern unsigned int pci_pm_d3_delay;
  65. #ifdef CONFIG_PCI_MSI
  66. void pci_no_msi(void);
  67. extern void pci_msi_init_pci_dev(struct pci_dev *dev);
  68. #else
  69. static inline void pci_no_msi(void) { }
  70. static inline void pci_msi_init_pci_dev(struct pci_dev *dev) { }
  71. #endif
  72. #ifdef CONFIG_PCIEAER
  73. void pci_no_aer(void);
  74. #else
  75. static inline void pci_no_aer(void) { }
  76. #endif
  77. static inline int pci_no_d1d2(struct pci_dev *dev)
  78. {
  79. unsigned int parent_dstates = 0;
  80. if (dev->bus->self)
  81. parent_dstates = dev->bus->self->no_d1d2;
  82. return (dev->no_d1d2 || parent_dstates);
  83. }
  84. extern int pcie_mch_quirk;
  85. extern struct device_attribute pci_dev_attrs[];
  86. extern struct device_attribute dev_attr_cpuaffinity;
  87. /**
  88. * pci_match_one_device - Tell if a PCI device structure has a matching
  89. * PCI device id structure
  90. * @id: single PCI device id structure to match
  91. * @dev: the PCI device structure to match against
  92. *
  93. * Returns the matching pci_device_id structure or %NULL if there is no match.
  94. */
  95. static inline const struct pci_device_id *
  96. pci_match_one_device(const struct pci_device_id *id, const struct pci_dev *dev)
  97. {
  98. if ((id->vendor == PCI_ANY_ID || id->vendor == dev->vendor) &&
  99. (id->device == PCI_ANY_ID || id->device == dev->device) &&
  100. (id->subvendor == PCI_ANY_ID || id->subvendor == dev->subsystem_vendor) &&
  101. (id->subdevice == PCI_ANY_ID || id->subdevice == dev->subsystem_device) &&
  102. !((id->class ^ dev->class) & id->class_mask))
  103. return id;
  104. return NULL;
  105. }
  106. struct pci_dev *pci_find_upstream_pcie_bridge(struct pci_dev *pdev);
  107. /* PCI slot sysfs helper code */
  108. #define to_pci_slot(s) container_of(s, struct pci_slot, kobj)
  109. extern struct kset *pci_slots_kset;
  110. struct pci_slot_attribute {
  111. struct attribute attr;
  112. ssize_t (*show)(struct pci_slot *, char *);
  113. ssize_t (*store)(struct pci_slot *, const char *, size_t);
  114. };
  115. #define to_pci_slot_attr(s) container_of(s, struct pci_slot_attribute, attr)