internals.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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. irq_modify_status(irq, IRQ_NOREQUEST, IRQ_NOPROBE);
  89. }
  90. static inline int intc_handle_int_cmp(const void *a, const void *b)
  91. {
  92. const struct intc_handle_int *_a = a;
  93. const struct intc_handle_int *_b = b;
  94. return _a->irq - _b->irq;
  95. }
  96. /* access.c */
  97. extern unsigned long
  98. (*intc_reg_fns[])(unsigned long addr, unsigned long h, unsigned long data);
  99. extern unsigned long
  100. (*intc_enable_fns[])(unsigned long addr, unsigned long handle,
  101. unsigned long (*fn)(unsigned long,
  102. unsigned long, unsigned long),
  103. unsigned int irq);
  104. extern unsigned long
  105. (*intc_disable_fns[])(unsigned long addr, unsigned long handle,
  106. unsigned long (*fn)(unsigned long,
  107. unsigned long, unsigned long),
  108. unsigned int irq);
  109. extern unsigned long
  110. (*intc_enable_noprio_fns[])(unsigned long addr, unsigned long handle,
  111. unsigned long (*fn)(unsigned long,
  112. unsigned long, unsigned long),
  113. unsigned int irq);
  114. unsigned long intc_phys_to_virt(struct intc_desc_int *d, unsigned long address);
  115. unsigned int intc_get_reg(struct intc_desc_int *d, unsigned long address);
  116. unsigned int intc_set_field_from_handle(unsigned int value,
  117. unsigned int field_value,
  118. unsigned int handle);
  119. unsigned long intc_get_field_from_handle(unsigned int value,
  120. unsigned int handle);
  121. /* balancing.c */
  122. #ifdef CONFIG_INTC_BALANCING
  123. void intc_balancing_enable(unsigned int irq);
  124. void intc_balancing_disable(unsigned int irq);
  125. void intc_set_dist_handle(unsigned int irq, struct intc_desc *desc,
  126. struct intc_desc_int *d, intc_enum id);
  127. #else
  128. static inline void intc_balancing_enable(unsigned int irq) { }
  129. static inline void intc_balancing_disable(unsigned int irq) { }
  130. static inline void
  131. intc_set_dist_handle(unsigned int irq, struct intc_desc *desc,
  132. struct intc_desc_int *d, intc_enum id) { }
  133. #endif
  134. /* chip.c */
  135. extern struct irq_chip intc_irq_chip;
  136. void _intc_enable(struct irq_data *data, unsigned long handle);
  137. /* core.c */
  138. extern struct list_head intc_list;
  139. extern raw_spinlock_t intc_big_lock;
  140. extern struct bus_type intc_subsys;
  141. unsigned int intc_get_dfl_prio_level(void);
  142. unsigned int intc_get_prio_level(unsigned int irq);
  143. void intc_set_prio_level(unsigned int irq, unsigned int level);
  144. /* handle.c */
  145. unsigned int intc_get_mask_handle(struct intc_desc *desc,
  146. struct intc_desc_int *d,
  147. intc_enum enum_id, int do_grps);
  148. unsigned int intc_get_prio_handle(struct intc_desc *desc,
  149. struct intc_desc_int *d,
  150. intc_enum enum_id, int do_grps);
  151. unsigned int intc_get_sense_handle(struct intc_desc *desc,
  152. struct intc_desc_int *d,
  153. intc_enum enum_id);
  154. void intc_set_ack_handle(unsigned int irq, struct intc_desc *desc,
  155. struct intc_desc_int *d, intc_enum id);
  156. unsigned long intc_get_ack_handle(unsigned int irq);
  157. void intc_enable_disable_enum(struct intc_desc *desc, struct intc_desc_int *d,
  158. intc_enum enum_id, int enable);
  159. /* irqdomain.c */
  160. void intc_irq_domain_init(struct intc_desc_int *d, struct intc_hw_desc *hw);
  161. /* virq.c */
  162. void intc_subgroup_init(struct intc_desc *desc, struct intc_desc_int *d);
  163. void intc_irq_xlate_set(unsigned int irq, intc_enum id, struct intc_desc_int *d);
  164. struct intc_map_entry *intc_irq_xlate_get(unsigned int irq);