msi.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. #ifndef LINUX_MSI_H
  2. #define LINUX_MSI_H
  3. #include <linux/kobject.h>
  4. #include <linux/list.h>
  5. struct msi_msg {
  6. u32 address_lo; /* low 32 bits of msi message address */
  7. u32 address_hi; /* high 32 bits of msi message address */
  8. u32 data; /* 16 bits of msi message data */
  9. };
  10. extern int pci_msi_ignore_mask;
  11. /* Helper functions */
  12. struct irq_data;
  13. struct msi_desc;
  14. struct pci_dev;
  15. struct platform_msi_priv_data;
  16. void __get_cached_msi_msg(struct msi_desc *entry, struct msi_msg *msg);
  17. void get_cached_msi_msg(unsigned int irq, struct msi_msg *msg);
  18. typedef void (*irq_write_msi_msg_t)(struct msi_desc *desc,
  19. struct msi_msg *msg);
  20. /**
  21. * platform_msi_desc - Platform device specific msi descriptor data
  22. * @msi_priv_data: Pointer to platform private data
  23. * @msi_index: The index of the MSI descriptor for multi MSI
  24. */
  25. struct platform_msi_desc {
  26. struct platform_msi_priv_data *msi_priv_data;
  27. u16 msi_index;
  28. };
  29. /**
  30. * struct msi_desc - Descriptor structure for MSI based interrupts
  31. * @list: List head for management
  32. * @irq: The base interrupt number
  33. * @nvec_used: The number of vectors used
  34. * @dev: Pointer to the device which uses this descriptor
  35. * @msg: The last set MSI message cached for reuse
  36. *
  37. * @masked: [PCI MSI/X] Mask bits
  38. * @is_msix: [PCI MSI/X] True if MSI-X
  39. * @multiple: [PCI MSI/X] log2 num of messages allocated
  40. * @multi_cap: [PCI MSI/X] log2 num of messages supported
  41. * @maskbit: [PCI MSI/X] Mask-Pending bit supported?
  42. * @is_64: [PCI MSI/X] Address size: 0=32bit 1=64bit
  43. * @entry_nr: [PCI MSI/X] Entry which is described by this descriptor
  44. * @default_irq:[PCI MSI/X] The default pre-assigned non-MSI irq
  45. * @mask_pos: [PCI MSI] Mask register position
  46. * @mask_base: [PCI MSI-X] Mask register base address
  47. * @platform: [platform] Platform device specific msi descriptor data
  48. */
  49. struct msi_desc {
  50. /* Shared device/bus type independent data */
  51. struct list_head list;
  52. unsigned int irq;
  53. unsigned int nvec_used;
  54. struct device *dev;
  55. struct msi_msg msg;
  56. union {
  57. /* PCI MSI/X specific data */
  58. struct {
  59. u32 masked;
  60. struct {
  61. __u8 is_msix : 1;
  62. __u8 multiple : 3;
  63. __u8 multi_cap : 3;
  64. __u8 maskbit : 1;
  65. __u8 is_64 : 1;
  66. __u16 entry_nr;
  67. unsigned default_irq;
  68. } msi_attrib;
  69. union {
  70. u8 mask_pos;
  71. void __iomem *mask_base;
  72. };
  73. };
  74. /*
  75. * Non PCI variants add their data structure here. New
  76. * entries need to use a named structure. We want
  77. * proper name spaces for this. The PCI part is
  78. * anonymous for now as it would require an immediate
  79. * tree wide cleanup.
  80. */
  81. struct platform_msi_desc platform;
  82. };
  83. };
  84. /* Helpers to hide struct msi_desc implementation details */
  85. #define msi_desc_to_dev(desc) ((desc)->dev)
  86. #define dev_to_msi_list(dev) (&(dev)->msi_list)
  87. #define first_msi_entry(dev) \
  88. list_first_entry(dev_to_msi_list((dev)), struct msi_desc, list)
  89. #define for_each_msi_entry(desc, dev) \
  90. list_for_each_entry((desc), dev_to_msi_list((dev)), list)
  91. #ifdef CONFIG_PCI_MSI
  92. #define first_pci_msi_entry(pdev) first_msi_entry(&(pdev)->dev)
  93. #define for_each_pci_msi_entry(desc, pdev) \
  94. for_each_msi_entry((desc), &(pdev)->dev)
  95. struct pci_dev *msi_desc_to_pci_dev(struct msi_desc *desc);
  96. void *msi_desc_to_pci_sysdata(struct msi_desc *desc);
  97. #else /* CONFIG_PCI_MSI */
  98. static inline void *msi_desc_to_pci_sysdata(struct msi_desc *desc)
  99. {
  100. return NULL;
  101. }
  102. #endif /* CONFIG_PCI_MSI */
  103. struct msi_desc *alloc_msi_entry(struct device *dev);
  104. void free_msi_entry(struct msi_desc *entry);
  105. void __pci_read_msi_msg(struct msi_desc *entry, struct msi_msg *msg);
  106. void __pci_write_msi_msg(struct msi_desc *entry, struct msi_msg *msg);
  107. void pci_write_msi_msg(unsigned int irq, struct msi_msg *msg);
  108. u32 __pci_msix_desc_mask_irq(struct msi_desc *desc, u32 flag);
  109. u32 __pci_msi_desc_mask_irq(struct msi_desc *desc, u32 mask, u32 flag);
  110. void pci_msi_mask_irq(struct irq_data *data);
  111. void pci_msi_unmask_irq(struct irq_data *data);
  112. /* Conversion helpers. Should be removed after merging */
  113. static inline void __write_msi_msg(struct msi_desc *entry, struct msi_msg *msg)
  114. {
  115. __pci_write_msi_msg(entry, msg);
  116. }
  117. static inline void write_msi_msg(int irq, struct msi_msg *msg)
  118. {
  119. pci_write_msi_msg(irq, msg);
  120. }
  121. static inline void mask_msi_irq(struct irq_data *data)
  122. {
  123. pci_msi_mask_irq(data);
  124. }
  125. static inline void unmask_msi_irq(struct irq_data *data)
  126. {
  127. pci_msi_unmask_irq(data);
  128. }
  129. /*
  130. * The arch hooks to setup up msi irqs. Those functions are
  131. * implemented as weak symbols so that they /can/ be overriden by
  132. * architecture specific code if needed.
  133. */
  134. int arch_setup_msi_irq(struct pci_dev *dev, struct msi_desc *desc);
  135. void arch_teardown_msi_irq(unsigned int irq);
  136. int arch_setup_msi_irqs(struct pci_dev *dev, int nvec, int type);
  137. void arch_teardown_msi_irqs(struct pci_dev *dev);
  138. void arch_restore_msi_irqs(struct pci_dev *dev);
  139. void default_teardown_msi_irqs(struct pci_dev *dev);
  140. void default_restore_msi_irqs(struct pci_dev *dev);
  141. struct msi_controller {
  142. struct module *owner;
  143. struct device *dev;
  144. struct device_node *of_node;
  145. struct list_head list;
  146. int (*setup_irq)(struct msi_controller *chip, struct pci_dev *dev,
  147. struct msi_desc *desc);
  148. int (*setup_irqs)(struct msi_controller *chip, struct pci_dev *dev,
  149. int nvec, int type);
  150. void (*teardown_irq)(struct msi_controller *chip, unsigned int irq);
  151. };
  152. #ifdef CONFIG_GENERIC_MSI_IRQ_DOMAIN
  153. #include <linux/irqhandler.h>
  154. #include <asm/msi.h>
  155. struct irq_domain;
  156. struct irq_chip;
  157. struct device_node;
  158. struct fwnode_handle;
  159. struct msi_domain_info;
  160. /**
  161. * struct msi_domain_ops - MSI interrupt domain callbacks
  162. * @get_hwirq: Retrieve the resulting hw irq number
  163. * @msi_init: Domain specific init function for MSI interrupts
  164. * @msi_free: Domain specific function to free a MSI interrupts
  165. * @msi_check: Callback for verification of the domain/info/dev data
  166. * @msi_prepare: Prepare the allocation of the interrupts in the domain
  167. * @msi_finish: Optional callback to finalize the allocation
  168. * @set_desc: Set the msi descriptor for an interrupt
  169. * @handle_error: Optional error handler if the allocation fails
  170. *
  171. * @get_hwirq, @msi_init and @msi_free are callbacks used by
  172. * msi_create_irq_domain() and related interfaces
  173. *
  174. * @msi_check, @msi_prepare, @msi_finish, @set_desc and @handle_error
  175. * are callbacks used by msi_domain_alloc_irqs() and related
  176. * interfaces which are based on msi_desc.
  177. */
  178. struct msi_domain_ops {
  179. irq_hw_number_t (*get_hwirq)(struct msi_domain_info *info,
  180. msi_alloc_info_t *arg);
  181. int (*msi_init)(struct irq_domain *domain,
  182. struct msi_domain_info *info,
  183. unsigned int virq, irq_hw_number_t hwirq,
  184. msi_alloc_info_t *arg);
  185. void (*msi_free)(struct irq_domain *domain,
  186. struct msi_domain_info *info,
  187. unsigned int virq);
  188. int (*msi_check)(struct irq_domain *domain,
  189. struct msi_domain_info *info,
  190. struct device *dev);
  191. int (*msi_prepare)(struct irq_domain *domain,
  192. struct device *dev, int nvec,
  193. msi_alloc_info_t *arg);
  194. void (*msi_finish)(msi_alloc_info_t *arg, int retval);
  195. void (*set_desc)(msi_alloc_info_t *arg,
  196. struct msi_desc *desc);
  197. int (*handle_error)(struct irq_domain *domain,
  198. struct msi_desc *desc, int error);
  199. };
  200. /**
  201. * struct msi_domain_info - MSI interrupt domain data
  202. * @flags: Flags to decribe features and capabilities
  203. * @ops: The callback data structure
  204. * @chip: Optional: associated interrupt chip
  205. * @chip_data: Optional: associated interrupt chip data
  206. * @handler: Optional: associated interrupt flow handler
  207. * @handler_data: Optional: associated interrupt flow handler data
  208. * @handler_name: Optional: associated interrupt flow handler name
  209. * @data: Optional: domain specific data
  210. */
  211. struct msi_domain_info {
  212. u32 flags;
  213. struct msi_domain_ops *ops;
  214. struct irq_chip *chip;
  215. void *chip_data;
  216. irq_flow_handler_t handler;
  217. void *handler_data;
  218. const char *handler_name;
  219. void *data;
  220. };
  221. /* Flags for msi_domain_info */
  222. enum {
  223. /*
  224. * Init non implemented ops callbacks with default MSI domain
  225. * callbacks.
  226. */
  227. MSI_FLAG_USE_DEF_DOM_OPS = (1 << 0),
  228. /*
  229. * Init non implemented chip callbacks with default MSI chip
  230. * callbacks.
  231. */
  232. MSI_FLAG_USE_DEF_CHIP_OPS = (1 << 1),
  233. /* Build identity map between hwirq and irq */
  234. MSI_FLAG_IDENTITY_MAP = (1 << 2),
  235. /* Support multiple PCI MSI interrupts */
  236. MSI_FLAG_MULTI_PCI_MSI = (1 << 3),
  237. /* Support PCI MSIX interrupts */
  238. MSI_FLAG_PCI_MSIX = (1 << 4),
  239. };
  240. int msi_domain_set_affinity(struct irq_data *data, const struct cpumask *mask,
  241. bool force);
  242. struct irq_domain *msi_create_irq_domain(struct fwnode_handle *fwnode,
  243. struct msi_domain_info *info,
  244. struct irq_domain *parent);
  245. int msi_domain_alloc_irqs(struct irq_domain *domain, struct device *dev,
  246. int nvec);
  247. void msi_domain_free_irqs(struct irq_domain *domain, struct device *dev);
  248. struct msi_domain_info *msi_get_domain_info(struct irq_domain *domain);
  249. struct irq_domain *platform_msi_create_irq_domain(struct fwnode_handle *fwnode,
  250. struct msi_domain_info *info,
  251. struct irq_domain *parent);
  252. int platform_msi_domain_alloc_irqs(struct device *dev, unsigned int nvec,
  253. irq_write_msi_msg_t write_msi_msg);
  254. void platform_msi_domain_free_irqs(struct device *dev);
  255. #endif /* CONFIG_GENERIC_MSI_IRQ_DOMAIN */
  256. #ifdef CONFIG_PCI_MSI_IRQ_DOMAIN
  257. void pci_msi_domain_write_msg(struct irq_data *irq_data, struct msi_msg *msg);
  258. struct irq_domain *pci_msi_create_irq_domain(struct fwnode_handle *fwnode,
  259. struct msi_domain_info *info,
  260. struct irq_domain *parent);
  261. int pci_msi_domain_alloc_irqs(struct irq_domain *domain, struct pci_dev *dev,
  262. int nvec, int type);
  263. void pci_msi_domain_free_irqs(struct irq_domain *domain, struct pci_dev *dev);
  264. struct irq_domain *pci_msi_create_default_irq_domain(struct fwnode_handle *fwnode,
  265. struct msi_domain_info *info, struct irq_domain *parent);
  266. irq_hw_number_t pci_msi_domain_calc_hwirq(struct pci_dev *dev,
  267. struct msi_desc *desc);
  268. int pci_msi_domain_check_cap(struct irq_domain *domain,
  269. struct msi_domain_info *info, struct device *dev);
  270. u32 pci_msi_domain_get_msi_rid(struct irq_domain *domain, struct pci_dev *pdev);
  271. struct irq_domain *pci_msi_get_device_domain(struct pci_dev *pdev);
  272. #else
  273. static inline struct irq_domain *pci_msi_get_device_domain(struct pci_dev *pdev)
  274. {
  275. return NULL;
  276. }
  277. #endif /* CONFIG_PCI_MSI_IRQ_DOMAIN */
  278. #endif /* LINUX_MSI_H */