internals.h 5.7 KB

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