gic.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  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. * GIC Register Definitions
  9. *
  10. */
  11. #ifndef _ASM_GICREGS_H
  12. #define _ASM_GICREGS_H
  13. #include <linux/bitmap.h>
  14. #include <linux/threads.h>
  15. #include <irq.h>
  16. #undef GICISBYTELITTLEENDIAN
  17. /* Constants */
  18. #define GIC_POL_POS 1
  19. #define GIC_POL_NEG 0
  20. #define GIC_TRIG_EDGE 1
  21. #define GIC_TRIG_LEVEL 0
  22. #define MSK(n) ((1 << (n)) - 1)
  23. #define REG32(addr) (*(volatile unsigned int *) (addr))
  24. #define REG(base, offs) REG32((unsigned long)(base) + offs##_##OFS)
  25. #define REGP(base, phys) REG32((unsigned long)(base) + (phys))
  26. /* Accessors */
  27. #define GIC_REG(segment, offset) \
  28. REG32(_gic_base + segment##_##SECTION_OFS + offset##_##OFS)
  29. #define GIC_REG_ADDR(segment, offset) \
  30. REG32(_gic_base + segment##_##SECTION_OFS + offset)
  31. #define GIC_ABS_REG(segment, offset) \
  32. (_gic_base + segment##_##SECTION_OFS + offset##_##OFS)
  33. #define GIC_REG_ABS_ADDR(segment, offset) \
  34. (_gic_base + segment##_##SECTION_OFS + offset)
  35. #ifdef GICISBYTELITTLEENDIAN
  36. #define GICREAD(reg, data) ((data) = (reg), (data) = le32_to_cpu(data))
  37. #define GICWRITE(reg, data) ((reg) = cpu_to_le32(data))
  38. #else
  39. #define GICREAD(reg, data) ((data) = (reg))
  40. #define GICWRITE(reg, data) ((reg) = (data))
  41. #endif
  42. #define GICBIS(reg, mask, bits) \
  43. do { u32 data; \
  44. GICREAD(reg, data); \
  45. data &= ~(mask); \
  46. data |= ((bits) & (mask)); \
  47. GICWRITE((reg), data); \
  48. } while (0)
  49. /* GIC Address Space */
  50. #define SHARED_SECTION_OFS 0x0000
  51. #define SHARED_SECTION_SIZE 0x8000
  52. #define VPE_LOCAL_SECTION_OFS 0x8000
  53. #define VPE_LOCAL_SECTION_SIZE 0x4000
  54. #define VPE_OTHER_SECTION_OFS 0xc000
  55. #define VPE_OTHER_SECTION_SIZE 0x4000
  56. #define USM_VISIBLE_SECTION_OFS 0x10000
  57. #define USM_VISIBLE_SECTION_SIZE 0x10000
  58. /* Register Map for Shared Section */
  59. #define GIC_SH_CONFIG_OFS 0x0000
  60. /* Shared Global Counter */
  61. #define GIC_SH_COUNTER_31_00_OFS 0x0010
  62. #define GIC_SH_COUNTER_63_32_OFS 0x0014
  63. #define GIC_SH_REVISIONID_OFS 0x0020
  64. /* Interrupt Polarity */
  65. #define GIC_SH_POL_31_0_OFS 0x0100
  66. #define GIC_SH_POL_63_32_OFS 0x0104
  67. #define GIC_SH_POL_95_64_OFS 0x0108
  68. #define GIC_SH_POL_127_96_OFS 0x010c
  69. #define GIC_SH_POL_159_128_OFS 0x0110
  70. #define GIC_SH_POL_191_160_OFS 0x0114
  71. #define GIC_SH_POL_223_192_OFS 0x0118
  72. #define GIC_SH_POL_255_224_OFS 0x011c
  73. /* Edge/Level Triggering */
  74. #define GIC_SH_TRIG_31_0_OFS 0x0180
  75. #define GIC_SH_TRIG_63_32_OFS 0x0184
  76. #define GIC_SH_TRIG_95_64_OFS 0x0188
  77. #define GIC_SH_TRIG_127_96_OFS 0x018c
  78. #define GIC_SH_TRIG_159_128_OFS 0x0190
  79. #define GIC_SH_TRIG_191_160_OFS 0x0194
  80. #define GIC_SH_TRIG_223_192_OFS 0x0198
  81. #define GIC_SH_TRIG_255_224_OFS 0x019c
  82. /* Dual Edge Triggering */
  83. #define GIC_SH_DUAL_31_0_OFS 0x0200
  84. #define GIC_SH_DUAL_63_32_OFS 0x0204
  85. #define GIC_SH_DUAL_95_64_OFS 0x0208
  86. #define GIC_SH_DUAL_127_96_OFS 0x020c
  87. #define GIC_SH_DUAL_159_128_OFS 0x0210
  88. #define GIC_SH_DUAL_191_160_OFS 0x0214
  89. #define GIC_SH_DUAL_223_192_OFS 0x0218
  90. #define GIC_SH_DUAL_255_224_OFS 0x021c
  91. /* Set/Clear corresponding bit in Edge Detect Register */
  92. #define GIC_SH_WEDGE_OFS 0x0280
  93. /* Reset Mask - Disables Interrupt */
  94. #define GIC_SH_RMASK_31_0_OFS 0x0300
  95. #define GIC_SH_RMASK_63_32_OFS 0x0304
  96. #define GIC_SH_RMASK_95_64_OFS 0x0308
  97. #define GIC_SH_RMASK_127_96_OFS 0x030c
  98. #define GIC_SH_RMASK_159_128_OFS 0x0310
  99. #define GIC_SH_RMASK_191_160_OFS 0x0314
  100. #define GIC_SH_RMASK_223_192_OFS 0x0318
  101. #define GIC_SH_RMASK_255_224_OFS 0x031c
  102. /* Set Mask (WO) - Enables Interrupt */
  103. #define GIC_SH_SMASK_31_0_OFS 0x0380
  104. #define GIC_SH_SMASK_63_32_OFS 0x0384
  105. #define GIC_SH_SMASK_95_64_OFS 0x0388
  106. #define GIC_SH_SMASK_127_96_OFS 0x038c
  107. #define GIC_SH_SMASK_159_128_OFS 0x0390
  108. #define GIC_SH_SMASK_191_160_OFS 0x0394
  109. #define GIC_SH_SMASK_223_192_OFS 0x0398
  110. #define GIC_SH_SMASK_255_224_OFS 0x039c
  111. /* Global Interrupt Mask Register (RO) - Bit Set == Interrupt enabled */
  112. #define GIC_SH_MASK_31_0_OFS 0x0400
  113. #define GIC_SH_MASK_63_32_OFS 0x0404
  114. #define GIC_SH_MASK_95_64_OFS 0x0408
  115. #define GIC_SH_MASK_127_96_OFS 0x040c
  116. #define GIC_SH_MASK_159_128_OFS 0x0410
  117. #define GIC_SH_MASK_191_160_OFS 0x0414
  118. #define GIC_SH_MASK_223_192_OFS 0x0418
  119. #define GIC_SH_MASK_255_224_OFS 0x041c
  120. /* Pending Global Interrupts (RO) */
  121. #define GIC_SH_PEND_31_0_OFS 0x0480
  122. #define GIC_SH_PEND_63_32_OFS 0x0484
  123. #define GIC_SH_PEND_95_64_OFS 0x0488
  124. #define GIC_SH_PEND_127_96_OFS 0x048c
  125. #define GIC_SH_PEND_159_128_OFS 0x0490
  126. #define GIC_SH_PEND_191_160_OFS 0x0494
  127. #define GIC_SH_PEND_223_192_OFS 0x0498
  128. #define GIC_SH_PEND_255_224_OFS 0x049c
  129. #define GIC_SH_INTR_MAP_TO_PIN_BASE_OFS 0x0500
  130. /* Maps Interrupt X to a Pin */
  131. #define GIC_SH_MAP_TO_PIN(intr) \
  132. (GIC_SH_INTR_MAP_TO_PIN_BASE_OFS + (4 * intr))
  133. #define GIC_SH_INTR_MAP_TO_VPE_BASE_OFS 0x2000
  134. /* Maps Interrupt X to a VPE */
  135. #define GIC_SH_MAP_TO_VPE_REG_OFF(intr, vpe) \
  136. (GIC_SH_INTR_MAP_TO_VPE_BASE_OFS + (32 * (intr)) + (((vpe) / 32) * 4))
  137. #define GIC_SH_MAP_TO_VPE_REG_BIT(vpe) (1 << ((vpe) % 32))
  138. /* Convert an interrupt number to a byte offset/bit for multi-word registers */
  139. #define GIC_INTR_OFS(intr) (((intr) / 32)*4)
  140. #define GIC_INTR_BIT(intr) ((intr) % 32)
  141. /* Polarity : Reset Value is always 0 */
  142. #define GIC_SH_SET_POLARITY_OFS 0x0100
  143. #define GIC_SET_POLARITY(intr, pol) \
  144. GICBIS(GIC_REG_ADDR(SHARED, GIC_SH_SET_POLARITY_OFS + \
  145. GIC_INTR_OFS(intr)), (1 << GIC_INTR_BIT(intr)), \
  146. (pol) << GIC_INTR_BIT(intr))
  147. /* Triggering : Reset Value is always 0 */
  148. #define GIC_SH_SET_TRIGGER_OFS 0x0180
  149. #define GIC_SET_TRIGGER(intr, trig) \
  150. GICBIS(GIC_REG_ADDR(SHARED, GIC_SH_SET_TRIGGER_OFS + \
  151. GIC_INTR_OFS(intr)), (1 << GIC_INTR_BIT(intr)), \
  152. (trig) << GIC_INTR_BIT(intr))
  153. /* Mask manipulation */
  154. #define GIC_SH_SMASK_OFS 0x0380
  155. #define GIC_SET_INTR_MASK(intr) \
  156. GICWRITE(GIC_REG_ADDR(SHARED, GIC_SH_SMASK_OFS + \
  157. GIC_INTR_OFS(intr)), 1 << GIC_INTR_BIT(intr))
  158. #define GIC_SH_RMASK_OFS 0x0300
  159. #define GIC_CLR_INTR_MASK(intr) \
  160. GICWRITE(GIC_REG_ADDR(SHARED, GIC_SH_RMASK_OFS + \
  161. GIC_INTR_OFS(intr)), 1 << GIC_INTR_BIT(intr))
  162. /* Register Map for Local Section */
  163. #define GIC_VPE_CTL_OFS 0x0000
  164. #define GIC_VPE_PEND_OFS 0x0004
  165. #define GIC_VPE_MASK_OFS 0x0008
  166. #define GIC_VPE_RMASK_OFS 0x000c
  167. #define GIC_VPE_SMASK_OFS 0x0010
  168. #define GIC_VPE_WD_MAP_OFS 0x0040
  169. #define GIC_VPE_COMPARE_MAP_OFS 0x0044
  170. #define GIC_VPE_TIMER_MAP_OFS 0x0048
  171. #define GIC_VPE_PERFCTR_MAP_OFS 0x0050
  172. #define GIC_VPE_SWINT0_MAP_OFS 0x0054
  173. #define GIC_VPE_SWINT1_MAP_OFS 0x0058
  174. #define GIC_VPE_OTHER_ADDR_OFS 0x0080
  175. #define GIC_VPE_WD_CONFIG0_OFS 0x0090
  176. #define GIC_VPE_WD_COUNT0_OFS 0x0094
  177. #define GIC_VPE_WD_INITIAL0_OFS 0x0098
  178. #define GIC_VPE_COMPARE_LO_OFS 0x00a0
  179. #define GIC_VPE_COMPARE_HI_OFS 0x00a4
  180. #define GIC_VPE_EIC_SHADOW_SET_BASE 0x0100
  181. #define GIC_VPE_EIC_SS(intr) \
  182. (GIC_VPE_EIC_SHADOW_SET_BASE + (4 * intr))
  183. #define GIC_VPE_EIC_VEC_BASE 0x0800
  184. #define GIC_VPE_EIC_VEC(intr) \
  185. (GIC_VPE_EIC_VEC_BASE + (4 * intr))
  186. #define GIC_VPE_TENABLE_NMI_OFS 0x1000
  187. #define GIC_VPE_TENABLE_YQ_OFS 0x1004
  188. #define GIC_VPE_TENABLE_INT_31_0_OFS 0x1080
  189. #define GIC_VPE_TENABLE_INT_63_32_OFS 0x1084
  190. /* User Mode Visible Section Register Map */
  191. #define GIC_UMV_SH_COUNTER_31_00_OFS 0x0000
  192. #define GIC_UMV_SH_COUNTER_63_32_OFS 0x0004
  193. /* Masks */
  194. #define GIC_SH_CONFIG_COUNTSTOP_SHF 28
  195. #define GIC_SH_CONFIG_COUNTSTOP_MSK (MSK(1) << GIC_SH_CONFIG_COUNTSTOP_SHF)
  196. #define GIC_SH_CONFIG_COUNTBITS_SHF 24
  197. #define GIC_SH_CONFIG_COUNTBITS_MSK (MSK(4) << GIC_SH_CONFIG_COUNTBITS_SHF)
  198. #define GIC_SH_CONFIG_NUMINTRS_SHF 16
  199. #define GIC_SH_CONFIG_NUMINTRS_MSK (MSK(8) << GIC_SH_CONFIG_NUMINTRS_SHF)
  200. #define GIC_SH_CONFIG_NUMVPES_SHF 0
  201. #define GIC_SH_CONFIG_NUMVPES_MSK (MSK(8) << GIC_SH_CONFIG_NUMVPES_SHF)
  202. #define GIC_SH_WEDGE_SET(intr) (intr | (0x1 << 31))
  203. #define GIC_SH_WEDGE_CLR(intr) (intr & ~(0x1 << 31))
  204. #define GIC_MAP_TO_PIN_SHF 31
  205. #define GIC_MAP_TO_PIN_MSK (MSK(1) << GIC_MAP_TO_PIN_SHF)
  206. #define GIC_MAP_TO_NMI_SHF 30
  207. #define GIC_MAP_TO_NMI_MSK (MSK(1) << GIC_MAP_TO_NMI_SHF)
  208. #define GIC_MAP_TO_YQ_SHF 29
  209. #define GIC_MAP_TO_YQ_MSK (MSK(1) << GIC_MAP_TO_YQ_SHF)
  210. #define GIC_MAP_SHF 0
  211. #define GIC_MAP_MSK (MSK(6) << GIC_MAP_SHF)
  212. /* GIC_VPE_CTL Masks */
  213. #define GIC_VPE_CTL_PERFCNT_RTBL_SHF 2
  214. #define GIC_VPE_CTL_PERFCNT_RTBL_MSK (MSK(1) << GIC_VPE_CTL_PERFCNT_RTBL_SHF)
  215. #define GIC_VPE_CTL_TIMER_RTBL_SHF 1
  216. #define GIC_VPE_CTL_TIMER_RTBL_MSK (MSK(1) << GIC_VPE_CTL_TIMER_RTBL_SHF)
  217. #define GIC_VPE_CTL_EIC_MODE_SHF 0
  218. #define GIC_VPE_CTL_EIC_MODE_MSK (MSK(1) << GIC_VPE_CTL_EIC_MODE_SHF)
  219. /* GIC_VPE_PEND Masks */
  220. #define GIC_VPE_PEND_WD_SHF 0
  221. #define GIC_VPE_PEND_WD_MSK (MSK(1) << GIC_VPE_PEND_WD_SHF)
  222. #define GIC_VPE_PEND_CMP_SHF 1
  223. #define GIC_VPE_PEND_CMP_MSK (MSK(1) << GIC_VPE_PEND_CMP_SHF)
  224. #define GIC_VPE_PEND_TIMER_SHF 2
  225. #define GIC_VPE_PEND_TIMER_MSK (MSK(1) << GIC_VPE_PEND_TIMER_SHF)
  226. #define GIC_VPE_PEND_PERFCOUNT_SHF 3
  227. #define GIC_VPE_PEND_PERFCOUNT_MSK (MSK(1) << GIC_VPE_PEND_PERFCOUNT_SHF)
  228. #define GIC_VPE_PEND_SWINT0_SHF 4
  229. #define GIC_VPE_PEND_SWINT0_MSK (MSK(1) << GIC_VPE_PEND_SWINT0_SHF)
  230. #define GIC_VPE_PEND_SWINT1_SHF 5
  231. #define GIC_VPE_PEND_SWINT1_MSK (MSK(1) << GIC_VPE_PEND_SWINT1_SHF)
  232. /* GIC_VPE_RMASK Masks */
  233. #define GIC_VPE_RMASK_WD_SHF 0
  234. #define GIC_VPE_RMASK_WD_MSK (MSK(1) << GIC_VPE_RMASK_WD_SHF)
  235. #define GIC_VPE_RMASK_CMP_SHF 1
  236. #define GIC_VPE_RMASK_CMP_MSK (MSK(1) << GIC_VPE_RMASK_CMP_SHF)
  237. #define GIC_VPE_RMASK_TIMER_SHF 2
  238. #define GIC_VPE_RMASK_TIMER_MSK (MSK(1) << GIC_VPE_RMASK_TIMER_SHF)
  239. #define GIC_VPE_RMASK_PERFCNT_SHF 3
  240. #define GIC_VPE_RMASK_PERFCNT_MSK (MSK(1) << GIC_VPE_RMASK_PERFCNT_SHF)
  241. #define GIC_VPE_RMASK_SWINT0_SHF 4
  242. #define GIC_VPE_RMASK_SWINT0_MSK (MSK(1) << GIC_VPE_RMASK_SWINT0_SHF)
  243. #define GIC_VPE_RMASK_SWINT1_SHF 5
  244. #define GIC_VPE_RMASK_SWINT1_MSK (MSK(1) << GIC_VPE_RMASK_SWINT1_SHF)
  245. /* GIC_VPE_SMASK Masks */
  246. #define GIC_VPE_SMASK_WD_SHF 0
  247. #define GIC_VPE_SMASK_WD_MSK (MSK(1) << GIC_VPE_SMASK_WD_SHF)
  248. #define GIC_VPE_SMASK_CMP_SHF 1
  249. #define GIC_VPE_SMASK_CMP_MSK (MSK(1) << GIC_VPE_SMASK_CMP_SHF)
  250. #define GIC_VPE_SMASK_TIMER_SHF 2
  251. #define GIC_VPE_SMASK_TIMER_MSK (MSK(1) << GIC_VPE_SMASK_TIMER_SHF)
  252. #define GIC_VPE_SMASK_PERFCNT_SHF 3
  253. #define GIC_VPE_SMASK_PERFCNT_MSK (MSK(1) << GIC_VPE_SMASK_PERFCNT_SHF)
  254. #define GIC_VPE_SMASK_SWINT0_SHF 4
  255. #define GIC_VPE_SMASK_SWINT0_MSK (MSK(1) << GIC_VPE_SMASK_SWINT0_SHF)
  256. #define GIC_VPE_SMASK_SWINT1_SHF 5
  257. #define GIC_VPE_SMASK_SWINT1_MSK (MSK(1) << GIC_VPE_SMASK_SWINT1_SHF)
  258. /*
  259. * Set the Mapping of Interrupt X to a VPE.
  260. */
  261. #define GIC_SH_MAP_TO_VPE_SMASK(intr, vpe) \
  262. GICWRITE(GIC_REG_ADDR(SHARED, GIC_SH_MAP_TO_VPE_REG_OFF(intr, vpe)), \
  263. GIC_SH_MAP_TO_VPE_REG_BIT(vpe))
  264. /*
  265. * Interrupt Meta-data specification. The ipiflag helps
  266. * in building ipi_map.
  267. */
  268. struct gic_intr_map {
  269. unsigned int cpunum; /* Directed to this CPU */
  270. #define GIC_UNUSED 0xdead /* Dummy data */
  271. unsigned int pin; /* Directed to this Pin */
  272. unsigned int polarity; /* Polarity : +/- */
  273. unsigned int trigtype; /* Trigger : Edge/Levl */
  274. unsigned int flags; /* Misc flags */
  275. #define GIC_FLAG_TRANSPARENT 0x01
  276. };
  277. /*
  278. * This is only used in EIC mode. This helps to figure out which
  279. * shared interrupts we need to process when we get a vector interrupt.
  280. */
  281. #define GIC_MAX_SHARED_INTR 0x5
  282. struct gic_shared_intr_map {
  283. unsigned int num_shared_intr;
  284. unsigned int intr_list[GIC_MAX_SHARED_INTR];
  285. unsigned int local_intr_mask;
  286. };
  287. /* GIC nomenclature for Core Interrupt Pins. */
  288. #define GIC_CPU_INT0 0 /* Core Interrupt 2 */
  289. #define GIC_CPU_INT1 1 /* . */
  290. #define GIC_CPU_INT2 2 /* . */
  291. #define GIC_CPU_INT3 3 /* . */
  292. #define GIC_CPU_INT4 4 /* . */
  293. #define GIC_CPU_INT5 5 /* Core Interrupt 7 */
  294. /* Local GIC interrupts. */
  295. #define GIC_INT_TMR (GIC_CPU_INT5)
  296. #define GIC_INT_PERFCTR (GIC_CPU_INT5)
  297. /* Add 2 to convert non-EIC hardware interrupt to EIC vector number. */
  298. #define GIC_CPU_TO_VEC_OFFSET (2)
  299. /* Mapped interrupt to pin X, then GIC will generate the vector (X+1). */
  300. #define GIC_PIN_TO_VEC_OFFSET (1)
  301. #include <linux/clocksource.h>
  302. #include <linux/irq.h>
  303. extern unsigned int gic_present;
  304. extern unsigned int gic_frequency;
  305. extern unsigned long _gic_base;
  306. extern unsigned int gic_irq_base;
  307. extern unsigned int gic_irq_flags[];
  308. extern struct gic_shared_intr_map gic_shared_intr_map[];
  309. extern void gic_init(unsigned long gic_base_addr,
  310. unsigned long gic_addrspace_size, struct gic_intr_map *intrmap,
  311. unsigned int intrmap_size, unsigned int irqbase);
  312. extern void gic_clocksource_init(unsigned int);
  313. extern unsigned int gic_compare_int (void);
  314. extern cycle_t gic_read_count(void);
  315. extern cycle_t gic_read_compare(void);
  316. extern void gic_write_compare(cycle_t cnt);
  317. extern void gic_write_cpu_compare(cycle_t cnt, int cpu);
  318. extern void gic_send_ipi(unsigned int intr);
  319. extern unsigned int plat_ipi_call_int_xlate(unsigned int);
  320. extern unsigned int plat_ipi_resched_int_xlate(unsigned int);
  321. extern void gic_bind_eic_interrupt(int irq, int set);
  322. extern unsigned int gic_get_timer_pending(void);
  323. extern void gic_get_int_mask(unsigned long *dst, const unsigned long *src);
  324. extern unsigned int gic_get_int(void);
  325. extern void gic_enable_interrupt(int irq_vec);
  326. extern void gic_disable_interrupt(int irq_vec);
  327. extern void gic_irq_ack(struct irq_data *d);
  328. extern void gic_finish_irq(struct irq_data *d);
  329. extern void gic_platform_init(int irqs, struct irq_chip *irq_controller);
  330. #endif /* _ASM_GICREGS_H */