irqdomain.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. * irq_domain - IRQ translation domains
  3. *
  4. * Translation infrastructure between hw and linux irq numbers. This is
  5. * helpful for interrupt controllers to implement mapping between hardware
  6. * irq numbers and the Linux irq number space.
  7. *
  8. * irq_domains also have a hook for translating device tree interrupt
  9. * representation into a hardware irq number that can be mapped back to a
  10. * Linux irq number without any extra platform support code.
  11. *
  12. * irq_domain is expected to be embedded in an interrupt controller's private
  13. * data structure.
  14. */
  15. #ifndef _LINUX_IRQDOMAIN_H
  16. #define _LINUX_IRQDOMAIN_H
  17. #include <linux/irq.h>
  18. #include <linux/mod_devicetable.h>
  19. #ifdef CONFIG_IRQ_DOMAIN
  20. struct device_node;
  21. struct irq_domain;
  22. /**
  23. * struct irq_domain_ops - Methods for irq_domain objects
  24. * @to_irq: (optional) given a local hardware irq number, return the linux
  25. * irq number. If to_irq is not implemented, then the irq_domain
  26. * will use this translation: irq = (domain->irq_base + hwirq)
  27. * @dt_translate: Given a device tree node and interrupt specifier, decode
  28. * the hardware irq number and linux irq type value.
  29. */
  30. struct irq_domain_ops {
  31. unsigned int (*to_irq)(struct irq_domain *d, unsigned long hwirq);
  32. #ifdef CONFIG_OF
  33. int (*dt_translate)(struct irq_domain *d, struct device_node *node,
  34. const u32 *intspec, unsigned int intsize,
  35. unsigned long *out_hwirq, unsigned int *out_type);
  36. #endif /* CONFIG_OF */
  37. };
  38. /**
  39. * struct irq_domain - Hardware interrupt number translation object
  40. * @list: Element in global irq_domain list.
  41. * @irq_base: Start of irq_desc range assigned to the irq_domain. The creator
  42. * of the irq_domain is responsible for allocating the array of
  43. * irq_desc structures.
  44. * @nr_irq: Number of irqs managed by the irq domain
  45. * @hwirq_base: Starting number for hwirqs managed by the irq domain
  46. * @ops: pointer to irq_domain methods
  47. * @priv: private data pointer for use by owner. Not touched by irq_domain
  48. * core code.
  49. * @of_node: (optional) Pointer to device tree nodes associated with the
  50. * irq_domain. Used when decoding device tree interrupt specifiers.
  51. */
  52. struct irq_domain {
  53. struct list_head list;
  54. unsigned int irq_base;
  55. unsigned int nr_irq;
  56. unsigned int hwirq_base;
  57. const struct irq_domain_ops *ops;
  58. void *priv;
  59. struct device_node *of_node;
  60. };
  61. /**
  62. * irq_domain_to_irq() - Translate from a hardware irq to a linux irq number
  63. *
  64. * Returns the linux irq number associated with a hardware irq. By default,
  65. * the mapping is irq == domain->irq_base + hwirq, but this mapping can
  66. * be overridden if the irq_domain implements a .to_irq() hook.
  67. */
  68. static inline unsigned int irq_domain_to_irq(struct irq_domain *d,
  69. unsigned long hwirq)
  70. {
  71. if (d->ops->to_irq)
  72. return d->ops->to_irq(d, hwirq);
  73. if (WARN_ON(hwirq < d->hwirq_base))
  74. return 0;
  75. return d->irq_base + hwirq - d->hwirq_base;
  76. }
  77. #define irq_domain_for_each_hwirq(d, hw) \
  78. for (hw = d->hwirq_base; hw < d->hwirq_base + d->nr_irq; hw++)
  79. #define irq_domain_for_each_irq(d, hw, irq) \
  80. for (hw = d->hwirq_base, irq = irq_domain_to_irq(d, hw); \
  81. hw < d->hwirq_base + d->nr_irq; \
  82. hw++, irq = irq_domain_to_irq(d, hw))
  83. extern void irq_domain_add(struct irq_domain *domain);
  84. extern void irq_domain_del(struct irq_domain *domain);
  85. #endif /* CONFIG_IRQ_DOMAIN */
  86. #if defined(CONFIG_IRQ_DOMAIN) && defined(CONFIG_OF_IRQ)
  87. extern struct irq_domain_ops irq_domain_simple_ops;
  88. extern void irq_domain_add_simple(struct device_node *controller, int irq_base);
  89. extern void irq_domain_generate_simple(const struct of_device_id *match,
  90. u64 phys_base, unsigned int irq_start);
  91. #else /* CONFIG_IRQ_DOMAIN && CONFIG_OF_IRQ */
  92. static inline void irq_domain_generate_simple(const struct of_device_id *match,
  93. u64 phys_base, unsigned int irq_start) { }
  94. #endif /* CONFIG_IRQ_DOMAIN && CONFIG_OF_IRQ */
  95. #endif /* _LINUX_IRQDOMAIN_H */