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