internals.h 5.5 KB

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