mips-gic.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 2000, 07 MIPS Technologies, Inc.
  7. */
  8. #ifndef __LINUX_IRQCHIP_MIPS_GIC_H
  9. #define __LINUX_IRQCHIP_MIPS_GIC_H
  10. #include <linux/clocksource.h>
  11. #include <linux/ioport.h>
  12. #define GIC_MAX_INTRS 256
  13. /* Constants */
  14. #define GIC_POL_POS 1
  15. #define GIC_POL_NEG 0
  16. #define GIC_TRIG_EDGE 1
  17. #define GIC_TRIG_LEVEL 0
  18. #define GIC_TRIG_DUAL_ENABLE 1
  19. #define GIC_TRIG_DUAL_DISABLE 0
  20. #define MSK(n) ((1 << (n)) - 1)
  21. /* Accessors */
  22. #define GIC_REG(segment, offset) (segment##_##SECTION_OFS + offset##_##OFS)
  23. /* GIC Address Space */
  24. #define SHARED_SECTION_OFS 0x0000
  25. #define SHARED_SECTION_SIZE 0x8000
  26. #define VPE_LOCAL_SECTION_OFS 0x8000
  27. #define VPE_LOCAL_SECTION_SIZE 0x4000
  28. #define VPE_OTHER_SECTION_OFS 0xc000
  29. #define VPE_OTHER_SECTION_SIZE 0x4000
  30. #define USM_VISIBLE_SECTION_OFS 0x10000
  31. #define USM_VISIBLE_SECTION_SIZE 0x10000
  32. /* Register Map for Shared Section */
  33. #define GIC_SH_CONFIG_OFS 0x0000
  34. /* Shared Global Counter */
  35. #define GIC_SH_COUNTER_31_00_OFS 0x0010
  36. /* 64-bit counter register for CM3 */
  37. #define GIC_SH_COUNTER_OFS GIC_SH_COUNTER_31_00_OFS
  38. #define GIC_SH_COUNTER_63_32_OFS 0x0014
  39. #define GIC_SH_REVISIONID_OFS 0x0020
  40. /* Convert an interrupt number to a byte offset/bit for multi-word registers */
  41. #define GIC_INTR_OFS(intr) ({ \
  42. unsigned bits = mips_cm_is64 ? 64 : 32; \
  43. unsigned reg_idx = (intr) / bits; \
  44. unsigned reg_width = bits / 8; \
  45. \
  46. reg_idx * reg_width; \
  47. })
  48. #define GIC_INTR_BIT(intr) ((intr) % (mips_cm_is64 ? 64 : 32))
  49. /* Polarity : Reset Value is always 0 */
  50. #define GIC_SH_SET_POLARITY_OFS 0x0100
  51. /* Triggering : Reset Value is always 0 */
  52. #define GIC_SH_SET_TRIGGER_OFS 0x0180
  53. /* Dual edge triggering : Reset Value is always 0 */
  54. #define GIC_SH_SET_DUAL_OFS 0x0200
  55. /* Set/Clear corresponding bit in Edge Detect Register */
  56. #define GIC_SH_WEDGE_OFS 0x0280
  57. /* Mask manipulation */
  58. #define GIC_SH_RMASK_OFS 0x0300
  59. #define GIC_SH_SMASK_OFS 0x0380
  60. /* Global Interrupt Mask Register (RO) - Bit Set == Interrupt enabled */
  61. #define GIC_SH_MASK_OFS 0x0400
  62. /* Pending Global Interrupts (RO) */
  63. #define GIC_SH_PEND_OFS 0x0480
  64. /* Maps Interrupt X to a Pin */
  65. #define GIC_SH_INTR_MAP_TO_PIN_BASE_OFS 0x0500
  66. #define GIC_SH_MAP_TO_PIN(intr) (4 * (intr))
  67. /* Maps Interrupt X to a VPE */
  68. #define GIC_SH_INTR_MAP_TO_VPE_BASE_OFS 0x2000
  69. #define GIC_SH_MAP_TO_VPE_REG_OFF(intr, vpe) \
  70. ((32 * (intr)) + (((vpe) / 32) * 4))
  71. #define GIC_SH_MAP_TO_VPE_REG_BIT(vpe) (1 << ((vpe) % 32))
  72. /* Register Map for Local Section */
  73. #define GIC_VPE_CTL_OFS 0x0000
  74. #define GIC_VPE_PEND_OFS 0x0004
  75. #define GIC_VPE_MASK_OFS 0x0008
  76. #define GIC_VPE_RMASK_OFS 0x000c
  77. #define GIC_VPE_SMASK_OFS 0x0010
  78. #define GIC_VPE_WD_MAP_OFS 0x0040
  79. #define GIC_VPE_COMPARE_MAP_OFS 0x0044
  80. #define GIC_VPE_TIMER_MAP_OFS 0x0048
  81. #define GIC_VPE_FDC_MAP_OFS 0x004c
  82. #define GIC_VPE_PERFCTR_MAP_OFS 0x0050
  83. #define GIC_VPE_SWINT0_MAP_OFS 0x0054
  84. #define GIC_VPE_SWINT1_MAP_OFS 0x0058
  85. #define GIC_VPE_OTHER_ADDR_OFS 0x0080
  86. #define GIC_VP_IDENT_OFS 0x0088
  87. #define GIC_VPE_WD_CONFIG0_OFS 0x0090
  88. #define GIC_VPE_WD_COUNT0_OFS 0x0094
  89. #define GIC_VPE_WD_INITIAL0_OFS 0x0098
  90. #define GIC_VPE_COMPARE_LO_OFS 0x00a0
  91. /* 64-bit Compare register on CM3 */
  92. #define GIC_VPE_COMPARE_OFS GIC_VPE_COMPARE_LO_OFS
  93. #define GIC_VPE_COMPARE_HI_OFS 0x00a4
  94. #define GIC_VPE_EIC_SHADOW_SET_BASE_OFS 0x0100
  95. #define GIC_VPE_EIC_SS(intr) (4 * (intr))
  96. #define GIC_VPE_EIC_VEC_BASE_OFS 0x0800
  97. #define GIC_VPE_EIC_VEC(intr) (4 * (intr))
  98. #define GIC_VPE_TENABLE_NMI_OFS 0x1000
  99. #define GIC_VPE_TENABLE_YQ_OFS 0x1004
  100. #define GIC_VPE_TENABLE_INT_31_0_OFS 0x1080
  101. #define GIC_VPE_TENABLE_INT_63_32_OFS 0x1084
  102. /* User Mode Visible Section Register Map */
  103. #define GIC_UMV_SH_COUNTER_31_00_OFS 0x0000
  104. #define GIC_UMV_SH_COUNTER_63_32_OFS 0x0004
  105. /* Masks */
  106. #define GIC_SH_CONFIG_COUNTSTOP_SHF 28
  107. #define GIC_SH_CONFIG_COUNTSTOP_MSK (MSK(1) << GIC_SH_CONFIG_COUNTSTOP_SHF)
  108. #define GIC_SH_CONFIG_COUNTBITS_SHF 24
  109. #define GIC_SH_CONFIG_COUNTBITS_MSK (MSK(4) << GIC_SH_CONFIG_COUNTBITS_SHF)
  110. #define GIC_SH_CONFIG_NUMINTRS_SHF 16
  111. #define GIC_SH_CONFIG_NUMINTRS_MSK (MSK(8) << GIC_SH_CONFIG_NUMINTRS_SHF)
  112. #define GIC_SH_CONFIG_NUMVPES_SHF 0
  113. #define GIC_SH_CONFIG_NUMVPES_MSK (MSK(8) << GIC_SH_CONFIG_NUMVPES_SHF)
  114. #define GIC_SH_WEDGE_SET(intr) ((intr) | (0x1 << 31))
  115. #define GIC_SH_WEDGE_CLR(intr) ((intr) & ~(0x1 << 31))
  116. #define GIC_MAP_TO_PIN_SHF 31
  117. #define GIC_MAP_TO_PIN_MSK (MSK(1) << GIC_MAP_TO_PIN_SHF)
  118. #define GIC_MAP_TO_NMI_SHF 30
  119. #define GIC_MAP_TO_NMI_MSK (MSK(1) << GIC_MAP_TO_NMI_SHF)
  120. #define GIC_MAP_TO_YQ_SHF 29
  121. #define GIC_MAP_TO_YQ_MSK (MSK(1) << GIC_MAP_TO_YQ_SHF)
  122. #define GIC_MAP_SHF 0
  123. #define GIC_MAP_MSK (MSK(6) << GIC_MAP_SHF)
  124. /* GIC_VPE_CTL Masks */
  125. #define GIC_VPE_CTL_FDC_RTBL_SHF 4
  126. #define GIC_VPE_CTL_FDC_RTBL_MSK (MSK(1) << GIC_VPE_CTL_FDC_RTBL_SHF)
  127. #define GIC_VPE_CTL_SWINT_RTBL_SHF 3
  128. #define GIC_VPE_CTL_SWINT_RTBL_MSK (MSK(1) << GIC_VPE_CTL_SWINT_RTBL_SHF)
  129. #define GIC_VPE_CTL_PERFCNT_RTBL_SHF 2
  130. #define GIC_VPE_CTL_PERFCNT_RTBL_MSK (MSK(1) << GIC_VPE_CTL_PERFCNT_RTBL_SHF)
  131. #define GIC_VPE_CTL_TIMER_RTBL_SHF 1
  132. #define GIC_VPE_CTL_TIMER_RTBL_MSK (MSK(1) << GIC_VPE_CTL_TIMER_RTBL_SHF)
  133. #define GIC_VPE_CTL_EIC_MODE_SHF 0
  134. #define GIC_VPE_CTL_EIC_MODE_MSK (MSK(1) << GIC_VPE_CTL_EIC_MODE_SHF)
  135. /* GIC_VPE_PEND Masks */
  136. #define GIC_VPE_PEND_WD_SHF 0
  137. #define GIC_VPE_PEND_WD_MSK (MSK(1) << GIC_VPE_PEND_WD_SHF)
  138. #define GIC_VPE_PEND_CMP_SHF 1
  139. #define GIC_VPE_PEND_CMP_MSK (MSK(1) << GIC_VPE_PEND_CMP_SHF)
  140. #define GIC_VPE_PEND_TIMER_SHF 2
  141. #define GIC_VPE_PEND_TIMER_MSK (MSK(1) << GIC_VPE_PEND_TIMER_SHF)
  142. #define GIC_VPE_PEND_PERFCOUNT_SHF 3
  143. #define GIC_VPE_PEND_PERFCOUNT_MSK (MSK(1) << GIC_VPE_PEND_PERFCOUNT_SHF)
  144. #define GIC_VPE_PEND_SWINT0_SHF 4
  145. #define GIC_VPE_PEND_SWINT0_MSK (MSK(1) << GIC_VPE_PEND_SWINT0_SHF)
  146. #define GIC_VPE_PEND_SWINT1_SHF 5
  147. #define GIC_VPE_PEND_SWINT1_MSK (MSK(1) << GIC_VPE_PEND_SWINT1_SHF)
  148. #define GIC_VPE_PEND_FDC_SHF 6
  149. #define GIC_VPE_PEND_FDC_MSK (MSK(1) << GIC_VPE_PEND_FDC_SHF)
  150. /* GIC_VPE_RMASK Masks */
  151. #define GIC_VPE_RMASK_WD_SHF 0
  152. #define GIC_VPE_RMASK_WD_MSK (MSK(1) << GIC_VPE_RMASK_WD_SHF)
  153. #define GIC_VPE_RMASK_CMP_SHF 1
  154. #define GIC_VPE_RMASK_CMP_MSK (MSK(1) << GIC_VPE_RMASK_CMP_SHF)
  155. #define GIC_VPE_RMASK_TIMER_SHF 2
  156. #define GIC_VPE_RMASK_TIMER_MSK (MSK(1) << GIC_VPE_RMASK_TIMER_SHF)
  157. #define GIC_VPE_RMASK_PERFCNT_SHF 3
  158. #define GIC_VPE_RMASK_PERFCNT_MSK (MSK(1) << GIC_VPE_RMASK_PERFCNT_SHF)
  159. #define GIC_VPE_RMASK_SWINT0_SHF 4
  160. #define GIC_VPE_RMASK_SWINT0_MSK (MSK(1) << GIC_VPE_RMASK_SWINT0_SHF)
  161. #define GIC_VPE_RMASK_SWINT1_SHF 5
  162. #define GIC_VPE_RMASK_SWINT1_MSK (MSK(1) << GIC_VPE_RMASK_SWINT1_SHF)
  163. #define GIC_VPE_RMASK_FDC_SHF 6
  164. #define GIC_VPE_RMASK_FDC_MSK (MSK(1) << GIC_VPE_RMASK_FDC_SHF)
  165. /* GIC_VPE_SMASK Masks */
  166. #define GIC_VPE_SMASK_WD_SHF 0
  167. #define GIC_VPE_SMASK_WD_MSK (MSK(1) << GIC_VPE_SMASK_WD_SHF)
  168. #define GIC_VPE_SMASK_CMP_SHF 1
  169. #define GIC_VPE_SMASK_CMP_MSK (MSK(1) << GIC_VPE_SMASK_CMP_SHF)
  170. #define GIC_VPE_SMASK_TIMER_SHF 2
  171. #define GIC_VPE_SMASK_TIMER_MSK (MSK(1) << GIC_VPE_SMASK_TIMER_SHF)
  172. #define GIC_VPE_SMASK_PERFCNT_SHF 3
  173. #define GIC_VPE_SMASK_PERFCNT_MSK (MSK(1) << GIC_VPE_SMASK_PERFCNT_SHF)
  174. #define GIC_VPE_SMASK_SWINT0_SHF 4
  175. #define GIC_VPE_SMASK_SWINT0_MSK (MSK(1) << GIC_VPE_SMASK_SWINT0_SHF)
  176. #define GIC_VPE_SMASK_SWINT1_SHF 5
  177. #define GIC_VPE_SMASK_SWINT1_MSK (MSK(1) << GIC_VPE_SMASK_SWINT1_SHF)
  178. #define GIC_VPE_SMASK_FDC_SHF 6
  179. #define GIC_VPE_SMASK_FDC_MSK (MSK(1) << GIC_VPE_SMASK_FDC_SHF)
  180. /* GIC_VP_IDENT fields */
  181. #define GIC_VP_IDENT_VCNUM_SHF 0
  182. #define GIC_VP_IDENT_VCNUM_MSK (MSK(6) << GIC_VP_IDENT_VCNUM_SHF)
  183. /* GIC nomenclature for Core Interrupt Pins. */
  184. #define GIC_CPU_INT0 0 /* Core Interrupt 2 */
  185. #define GIC_CPU_INT1 1 /* . */
  186. #define GIC_CPU_INT2 2 /* . */
  187. #define GIC_CPU_INT3 3 /* . */
  188. #define GIC_CPU_INT4 4 /* . */
  189. #define GIC_CPU_INT5 5 /* Core Interrupt 7 */
  190. /* Add 2 to convert GIC CPU pin to core interrupt */
  191. #define GIC_CPU_PIN_OFFSET 2
  192. /* Add 2 to convert non-EIC hardware interrupt to EIC vector number. */
  193. #define GIC_CPU_TO_VEC_OFFSET 2
  194. /* Mapped interrupt to pin X, then GIC will generate the vector (X+1). */
  195. #define GIC_PIN_TO_VEC_OFFSET 1
  196. /* Local GIC interrupts. */
  197. #define GIC_LOCAL_INT_WD 0 /* GIC watchdog */
  198. #define GIC_LOCAL_INT_COMPARE 1 /* GIC count and compare timer */
  199. #define GIC_LOCAL_INT_TIMER 2 /* CPU timer interrupt */
  200. #define GIC_LOCAL_INT_PERFCTR 3 /* CPU performance counter */
  201. #define GIC_LOCAL_INT_SWINT0 4 /* CPU software interrupt 0 */
  202. #define GIC_LOCAL_INT_SWINT1 5 /* CPU software interrupt 1 */
  203. #define GIC_LOCAL_INT_FDC 6 /* CPU fast debug channel */
  204. #define GIC_NUM_LOCAL_INTRS 7
  205. /* Convert between local/shared IRQ number and GIC HW IRQ number. */
  206. #define GIC_LOCAL_HWIRQ_BASE 0
  207. #define GIC_LOCAL_TO_HWIRQ(x) (GIC_LOCAL_HWIRQ_BASE + (x))
  208. #define GIC_HWIRQ_TO_LOCAL(x) ((x) - GIC_LOCAL_HWIRQ_BASE)
  209. #define GIC_SHARED_HWIRQ_BASE GIC_NUM_LOCAL_INTRS
  210. #define GIC_SHARED_TO_HWIRQ(x) (GIC_SHARED_HWIRQ_BASE + (x))
  211. #define GIC_HWIRQ_TO_SHARED(x) ((x) - GIC_SHARED_HWIRQ_BASE)
  212. #ifdef CONFIG_MIPS_GIC
  213. extern unsigned int gic_present;
  214. extern void gic_init(unsigned long gic_base_addr,
  215. unsigned long gic_addrspace_size, unsigned int cpu_vec,
  216. unsigned int irqbase);
  217. extern void gic_clocksource_init(unsigned int);
  218. extern cycle_t gic_read_count(void);
  219. extern unsigned int gic_get_count_width(void);
  220. extern cycle_t gic_read_compare(void);
  221. extern void gic_write_compare(cycle_t cnt);
  222. extern void gic_write_cpu_compare(cycle_t cnt, int cpu);
  223. extern void gic_start_count(void);
  224. extern void gic_stop_count(void);
  225. extern int gic_get_c0_compare_int(void);
  226. extern int gic_get_c0_perfcount_int(void);
  227. extern int gic_get_c0_fdc_int(void);
  228. extern int gic_get_usm_range(struct resource *gic_usm_res);
  229. #else /* CONFIG_MIPS_GIC */
  230. #define gic_present 0
  231. static inline int gic_get_usm_range(struct resource *gic_usm_res)
  232. {
  233. /* Shouldn't be called. */
  234. return -1;
  235. }
  236. #endif /* CONFIG_MIPS_GIC */
  237. /**
  238. * gic_read_local_vp_id() - read the local VPs VCNUM
  239. *
  240. * Read the VCNUM of the local VP from the GIC_VP_IDENT register and
  241. * return it to the caller. This ID should be used to refer to the VP
  242. * via the GICs VP-other region, or when calculating an offset to a
  243. * bit representing the VP in interrupt masks.
  244. *
  245. * Return: The VCNUM value for the local VP.
  246. */
  247. extern unsigned gic_read_local_vp_id(void);
  248. #endif /* __LINUX_IRQCHIP_MIPS_GIC_H */