msi.h 11 KB

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