internals.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #include <linux/sh_intc.h>
  3. #include <linux/irq.h>
  4. #include <linux/irqdomain.h>
  5. #include <linux/list.h>
  6. #include <linux/kernel.h>
  7. #include <linux/types.h>
  8. #include <linux/radix-tree.h>
  9. #include <linux/device.h>
  10. #define _INTC_MK(fn, mode, addr_e, addr_d, width, shift) \
  11. ((shift) | ((width) << 5) | ((fn) << 9) | ((mode) << 13) | \
  12. ((addr_e) << 16) | ((addr_d << 24)))
  13. #define _INTC_SHIFT(h) (h & 0x1f)
  14. #define _INTC_WIDTH(h) ((h >> 5) & 0xf)
  15. #define _INTC_FN(h) ((h >> 9) & 0xf)
  16. #define _INTC_MODE(h) ((h >> 13) & 0x7)
  17. #define _INTC_ADDR_E(h) ((h >> 16) & 0xff)
  18. #define _INTC_ADDR_D(h) ((h >> 24) & 0xff)
  19. #ifdef CONFIG_SMP
  20. #define IS_SMP(x) (x.smp)
  21. #define INTC_REG(d, x, c) (d->reg[(x)] + ((d->smp[(x)] & 0xff) * c))
  22. #define SMP_NR(d, x) ((d->smp[(x)] >> 8) ? (d->smp[(x)] >> 8) : 1)
  23. #else
  24. #define IS_SMP(x) 0
  25. #define INTC_REG(d, x, c) (d->reg[(x)])
  26. #define SMP_NR(d, x) 1
  27. #endif
  28. struct intc_handle_int {
  29. unsigned int irq;
  30. unsigned long handle;
  31. };
  32. struct intc_window {
  33. phys_addr_t phys;
  34. void __iomem *virt;
  35. unsigned long size;
  36. };
  37. struct intc_map_entry {
  38. intc_enum enum_id;
  39. struct intc_desc_int *desc;
  40. };
  41. struct intc_subgroup_entry {
  42. unsigned int pirq;
  43. intc_enum enum_id;
  44. unsigned long handle;
  45. };
  46. struct intc_desc_int {
  47. struct list_head list;
  48. struct device dev;
  49. struct radix_tree_root tree;
  50. raw_spinlock_t lock;
  51. unsigned int index;
  52. unsigned long *reg;
  53. #ifdef CONFIG_SMP
  54. unsigned long *smp;
  55. #endif
  56. unsigned int nr_reg;
  57. struct intc_handle_int *prio;
  58. unsigned int nr_prio;
  59. struct intc_handle_int *sense;
  60. unsigned int nr_sense;
  61. struct intc_window *window;
  62. unsigned int nr_windows;
  63. struct irq_domain *domain;
  64. struct irq_chip chip;
  65. bool skip_suspend;
  66. };
  67. enum {
  68. REG_FN_ERR = 0,
  69. REG_FN_TEST_BASE = 1,
  70. REG_FN_WRITE_BASE = 5,
  71. REG_FN_MODIFY_BASE = 9
  72. };
  73. enum { MODE_ENABLE_REG = 0, /* Bit(s) set -> interrupt enabled */
  74. MODE_MASK_REG, /* Bit(s) set -> interrupt disabled */
  75. MODE_DUAL_REG, /* Two registers, set bit to enable / disable */
  76. MODE_PRIO_REG, /* Priority value written to enable interrupt */
  77. MODE_PCLR_REG, /* Above plus all bits set to disable interrupt */
  78. };
  79. static inline struct intc_desc_int *get_intc_desc(unsigned int irq)
  80. {
  81. struct irq_chip *chip = irq_get_chip(irq);
  82. return container_of(chip, struct intc_desc_int, chip);
  83. }
  84. /*
  85. * Grumble.
  86. */
  87. static inline void activate_irq(int irq)
  88. {
  89. irq_modify_status(irq, IRQ_NOREQUEST, IRQ_NOPROBE);
  90. }
  91. static inline int intc_handle_int_cmp(const void *a, const void *b)
  92. {
  93. const struct intc_handle_int *_a = a;
  94. const struct intc_handle_int *_b = b;
  95. return _a->irq - _b->irq;
  96. }
  97. /* access.c */
  98. extern unsigned long
  99. (*intc_reg_fns[])(unsigned long addr, unsigned long h, unsigned long data);
  100. extern unsigned long
  101. (*intc_enable_fns[])(unsigned long addr, unsigned long handle,
  102. unsigned long (*fn)(unsigned long,
  103. unsigned long, unsigned long),
  104. unsigned int irq);
  105. extern unsigned long
  106. (*intc_disable_fns[])(unsigned long addr, unsigned long handle,
  107. unsigned long (*fn)(unsigned long,
  108. unsigned long, unsigned long),
  109. unsigned int irq);
  110. extern unsigned long
  111. (*intc_enable_noprio_fns[])(unsigned long addr, unsigned long handle,
  112. unsigned long (*fn)(unsigned long,
  113. unsigned long, unsigned long),
  114. unsigned int irq);
  115. unsigned long intc_phys_to_virt(struct intc_desc_int *d, unsigned long address);
  116. unsigned int intc_get_reg(struct intc_desc_int *d, unsigned long address);
  117. unsigned int intc_set_field_from_handle(unsigned int value,
  118. unsigned int field_value,
  119. unsigned int handle);
  120. unsigned long intc_get_field_from_handle(unsigned int value,
  121. unsigned int handle);
  122. /* balancing.c */
  123. #ifdef CONFIG_INTC_BALANCING
  124. void intc_balancing_enable(unsigned int irq);
  125. void intc_balancing_disable(unsigned int irq);
  126. void intc_set_dist_handle(unsigned int irq, struct intc_desc *desc,
  127. struct intc_desc_int *d, intc_enum id);
  128. #else
  129. static inline void intc_balancing_enable(unsigned int irq) { }
  130. static inline void intc_balancing_disable(unsigned int irq) { }
  131. static inline void
  132. intc_set_dist_handle(unsigned int irq, struct intc_desc *desc,
  133. struct intc_desc_int *d, intc_enum id) { }
  134. #endif
  135. /* chip.c */
  136. extern struct irq_chip intc_irq_chip;
  137. void _intc_enable(struct irq_data *data, unsigned long handle);
  138. /* core.c */
  139. extern struct list_head intc_list;
  140. extern raw_spinlock_t intc_big_lock;
  141. extern struct bus_type intc_subsys;
  142. unsigned int intc_get_dfl_prio_level(void);
  143. unsigned int intc_get_prio_level(unsigned int irq);
  144. void intc_set_prio_level(unsigned int irq, unsigned int level);
  145. /* handle.c */
  146. unsigned int intc_get_mask_handle(struct intc_desc *desc,
  147. struct intc_desc_int *d,
  148. intc_enum enum_id, int do_grps);
  149. unsigned int intc_get_prio_handle(struct intc_desc *desc,
  150. struct intc_desc_int *d,
  151. intc_enum enum_id, int do_grps);
  152. unsigned int intc_get_sense_handle(struct intc_desc *desc,
  153. struct intc_desc_int *d,
  154. intc_enum enum_id);
  155. void intc_set_ack_handle(unsigned int irq, struct intc_desc *desc,
  156. struct intc_desc_int *d, intc_enum id);
  157. unsigned long intc_get_ack_handle(unsigned int irq);
  158. void intc_enable_disable_enum(struct intc_desc *desc, struct intc_desc_int *d,
  159. intc_enum enum_id, int enable);
  160. /* irqdomain.c */
  161. void intc_irq_domain_init(struct intc_desc_int *d, struct intc_hw_desc *hw);
  162. /* virq.c */
  163. void intc_subgroup_init(struct intc_desc *desc, struct intc_desc_int *d);
  164. void intc_irq_xlate_set(unsigned int irq, intc_enum id, struct intc_desc_int *d);
  165. struct intc_map_entry *intc_irq_xlate_get(unsigned int irq);