irqdomain.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. * Interrupt controller "domain" data structure. This could be defined as a
  13. * irq domain controller. That is, it handles the mapping between hardware
  14. * and virtual interrupt numbers for a given interrupt domain. The domain
  15. * structure is generally created by the PIC code for a given PIC instance
  16. * (though a domain can cover more than one PIC if they have a flat number
  17. * model). It's the domain callbacks that are responsible for setting the
  18. * irq_chip on a given irq_desc after it's been mapped.
  19. */
  20. #ifndef _LINUX_IRQDOMAIN_H
  21. #define _LINUX_IRQDOMAIN_H
  22. #include <linux/types.h>
  23. #include <linux/radix-tree.h>
  24. struct device_node;
  25. struct irq_domain;
  26. struct of_device_id;
  27. /* This type is the placeholder for a hardware interrupt number. It has to
  28. * be big enough to enclose whatever representation is used by a given
  29. * platform.
  30. */
  31. typedef unsigned long irq_hw_number_t;
  32. /**
  33. * struct irq_domain_ops - Methods for irq_domain objects
  34. * @match: Match an interrupt controller device node to a host, returns
  35. * 1 on a match
  36. * @map: Create or update a mapping between a virtual irq number and a hw
  37. * irq number. This is called only once for a given mapping.
  38. * @unmap: Dispose of such a mapping
  39. * @to_irq: (optional) given a local hardware irq number, return the linux
  40. * irq number. If to_irq is not implemented, then the irq_domain
  41. * will use this translation: irq = (domain->irq_base + hwirq)
  42. * @xlate: Given a device tree node and interrupt specifier, decode
  43. * the hardware irq number and linux irq type value.
  44. *
  45. * Functions below are provided by the driver and called whenever a new mapping
  46. * is created or an old mapping is disposed. The driver can then proceed to
  47. * whatever internal data structures management is required. It also needs
  48. * to setup the irq_desc when returning from map().
  49. */
  50. struct irq_domain_ops {
  51. int (*match)(struct irq_domain *d, struct device_node *node);
  52. int (*map)(struct irq_domain *d, unsigned int virq, irq_hw_number_t hw);
  53. void (*unmap)(struct irq_domain *d, unsigned int virq);
  54. unsigned int (*to_irq)(struct irq_domain *d, unsigned long hwirq);
  55. int (*xlate)(struct irq_domain *d, struct device_node *node,
  56. const u32 *intspec, unsigned int intsize,
  57. unsigned long *out_hwirq, unsigned int *out_type);
  58. };
  59. /**
  60. * struct irq_domain - Hardware interrupt number translation object
  61. * @link: Element in global irq_domain list.
  62. * @revmap_type: Method used for reverse mapping hwirq numbers to linux irq. This
  63. * will be one of the IRQ_DOMAIN_MAP_* values.
  64. * @revmap_data: Revmap method specific data.
  65. * @ops: pointer to irq_domain methods
  66. * @host_data: private data pointer for use by owner. Not touched by irq_domain
  67. * core code.
  68. * @irq_base: Start of irq_desc range assigned to the irq_domain. The creator
  69. * of the irq_domain is responsible for allocating the array of
  70. * irq_desc structures.
  71. * @nr_irq: Number of irqs managed by the irq domain
  72. * @hwirq_base: Starting number for hwirqs managed by the irq domain
  73. * @of_node: (optional) Pointer to device tree nodes associated with the
  74. * irq_domain. Used when decoding device tree interrupt specifiers.
  75. */
  76. struct irq_domain {
  77. struct list_head link;
  78. /* type of reverse mapping_technique */
  79. unsigned int revmap_type;
  80. #define IRQ_DOMAIN_MAP_LEGACY 0 /* legacy 8259, gets irqs 1..15 */
  81. #define IRQ_DOMAIN_MAP_NOMAP 1 /* no fast reverse mapping */
  82. #define IRQ_DOMAIN_MAP_LINEAR 2 /* linear map of interrupts */
  83. #define IRQ_DOMAIN_MAP_TREE 3 /* radix tree */
  84. union {
  85. struct {
  86. unsigned int size;
  87. unsigned int *revmap;
  88. } linear;
  89. struct radix_tree_root tree;
  90. } revmap_data;
  91. struct irq_domain_ops *ops;
  92. void *host_data;
  93. irq_hw_number_t inval_irq;
  94. unsigned int irq_base;
  95. unsigned int nr_irq;
  96. unsigned int hwirq_base;
  97. /* Optional device node pointer */
  98. struct device_node *of_node;
  99. };
  100. #ifdef CONFIG_IRQ_DOMAIN
  101. /**
  102. * irq_domain_to_irq() - Translate from a hardware irq to a linux irq number
  103. *
  104. * Returns the linux irq number associated with a hardware irq. By default,
  105. * the mapping is irq == domain->irq_base + hwirq, but this mapping can
  106. * be overridden if the irq_domain implements a .to_irq() hook.
  107. */
  108. static inline unsigned int irq_domain_to_irq(struct irq_domain *d,
  109. unsigned long hwirq)
  110. {
  111. if (d->ops->to_irq)
  112. return d->ops->to_irq(d, hwirq);
  113. if (WARN_ON(hwirq < d->hwirq_base))
  114. return 0;
  115. return d->irq_base + hwirq - d->hwirq_base;
  116. }
  117. #define irq_domain_for_each_hwirq(d, hw) \
  118. for (hw = d->hwirq_base; hw < d->hwirq_base + d->nr_irq; hw++)
  119. #define irq_domain_for_each_irq(d, hw, irq) \
  120. for (hw = d->hwirq_base, irq = irq_domain_to_irq(d, hw); \
  121. hw < d->hwirq_base + d->nr_irq; \
  122. hw++, irq = irq_domain_to_irq(d, hw))
  123. extern void irq_domain_add(struct irq_domain *domain);
  124. extern void irq_domain_del(struct irq_domain *domain);
  125. extern struct irq_domain_ops irq_domain_simple_ops;
  126. #endif /* CONFIG_IRQ_DOMAIN */
  127. #if defined(CONFIG_IRQ_DOMAIN) && defined(CONFIG_OF_IRQ)
  128. extern void irq_domain_add_simple(struct device_node *controller, int irq_base);
  129. extern void irq_domain_generate_simple(const struct of_device_id *match,
  130. u64 phys_base, unsigned int irq_start);
  131. #else /* CONFIG_IRQ_DOMAIN && CONFIG_OF_IRQ */
  132. static inline void irq_domain_generate_simple(const struct of_device_id *match,
  133. u64 phys_base, unsigned int irq_start) { }
  134. #endif /* CONFIG_IRQ_DOMAIN && CONFIG_OF_IRQ */
  135. #endif /* _LINUX_IRQDOMAIN_H */