12874c5fdSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */
2582e2b4aSPaul Burton /*
3582e2b4aSPaul Burton * Copyright (C) 2017 Imagination Technologies
4fb615d61SPaul Burton * Author: Paul Burton <paul.burton@mips.com>
5582e2b4aSPaul Burton */
6582e2b4aSPaul Burton
7582e2b4aSPaul Burton #ifndef __MIPS_ASM_MIPS_CPS_H__
8582e2b4aSPaul Burton # error Please include asm/mips-cps.h rather than asm/mips-gic.h
9582e2b4aSPaul Burton #endif
10582e2b4aSPaul Burton
11582e2b4aSPaul Burton #ifndef __MIPS_ASM_MIPS_GIC_H__
12582e2b4aSPaul Burton #define __MIPS_ASM_MIPS_GIC_H__
13582e2b4aSPaul Burton
14582e2b4aSPaul Burton #include <linux/bitops.h>
15582e2b4aSPaul Burton
16582e2b4aSPaul Burton /* The base address of the GIC registers */
17582e2b4aSPaul Burton extern void __iomem *mips_gic_base;
18582e2b4aSPaul Burton
19582e2b4aSPaul Burton /* Offsets from the GIC base address to various control blocks */
20582e2b4aSPaul Burton #define MIPS_GIC_SHARED_OFS 0x00000
21582e2b4aSPaul Burton #define MIPS_GIC_SHARED_SZ 0x08000
22582e2b4aSPaul Burton #define MIPS_GIC_LOCAL_OFS 0x08000
23582e2b4aSPaul Burton #define MIPS_GIC_LOCAL_SZ 0x04000
24582e2b4aSPaul Burton #define MIPS_GIC_REDIR_OFS 0x0c000
25582e2b4aSPaul Burton #define MIPS_GIC_REDIR_SZ 0x04000
26582e2b4aSPaul Burton #define MIPS_GIC_USER_OFS 0x10000
27582e2b4aSPaul Burton #define MIPS_GIC_USER_SZ 0x10000
28582e2b4aSPaul Burton
29582e2b4aSPaul Burton /* For read-only shared registers */
30582e2b4aSPaul Burton #define GIC_ACCESSOR_RO(sz, off, name) \
31582e2b4aSPaul Burton CPS_ACCESSOR_RO(gic, sz, MIPS_GIC_SHARED_OFS + off, name)
32582e2b4aSPaul Burton
33582e2b4aSPaul Burton /* For read-write shared registers */
34582e2b4aSPaul Burton #define GIC_ACCESSOR_RW(sz, off, name) \
35582e2b4aSPaul Burton CPS_ACCESSOR_RW(gic, sz, MIPS_GIC_SHARED_OFS + off, name)
36582e2b4aSPaul Burton
37582e2b4aSPaul Burton /* For read-only local registers */
38582e2b4aSPaul Burton #define GIC_VX_ACCESSOR_RO(sz, off, name) \
39582e2b4aSPaul Burton CPS_ACCESSOR_RO(gic, sz, MIPS_GIC_LOCAL_OFS + off, vl_##name) \
40582e2b4aSPaul Burton CPS_ACCESSOR_RO(gic, sz, MIPS_GIC_REDIR_OFS + off, vo_##name)
41582e2b4aSPaul Burton
42582e2b4aSPaul Burton /* For read-write local registers */
43582e2b4aSPaul Burton #define GIC_VX_ACCESSOR_RW(sz, off, name) \
44582e2b4aSPaul Burton CPS_ACCESSOR_RW(gic, sz, MIPS_GIC_LOCAL_OFS + off, vl_##name) \
45582e2b4aSPaul Burton CPS_ACCESSOR_RW(gic, sz, MIPS_GIC_REDIR_OFS + off, vo_##name)
46582e2b4aSPaul Burton
47582e2b4aSPaul Burton /* For read-only shared per-interrupt registers */
48582e2b4aSPaul Burton #define GIC_ACCESSOR_RO_INTR_REG(sz, off, stride, name) \
49582e2b4aSPaul Burton static inline void __iomem *addr_gic_##name(unsigned int intr) \
50582e2b4aSPaul Burton { \
51582e2b4aSPaul Burton return mips_gic_base + (off) + (intr * (stride)); \
52582e2b4aSPaul Burton } \
53582e2b4aSPaul Burton \
54582e2b4aSPaul Burton static inline unsigned int read_gic_##name(unsigned int intr) \
55582e2b4aSPaul Burton { \
56582e2b4aSPaul Burton BUILD_BUG_ON(sz != 32); \
57582e2b4aSPaul Burton return __raw_readl(addr_gic_##name(intr)); \
58582e2b4aSPaul Burton }
59582e2b4aSPaul Burton
60582e2b4aSPaul Burton /* For read-write shared per-interrupt registers */
61582e2b4aSPaul Burton #define GIC_ACCESSOR_RW_INTR_REG(sz, off, stride, name) \
62582e2b4aSPaul Burton GIC_ACCESSOR_RO_INTR_REG(sz, off, stride, name) \
63582e2b4aSPaul Burton \
64582e2b4aSPaul Burton static inline void write_gic_##name(unsigned int intr, \
65582e2b4aSPaul Burton unsigned int val) \
66582e2b4aSPaul Burton { \
67582e2b4aSPaul Burton BUILD_BUG_ON(sz != 32); \
68582e2b4aSPaul Burton __raw_writel(val, addr_gic_##name(intr)); \
69582e2b4aSPaul Burton }
70582e2b4aSPaul Burton
71582e2b4aSPaul Burton /* For read-only local per-interrupt registers */
72582e2b4aSPaul Burton #define GIC_VX_ACCESSOR_RO_INTR_REG(sz, off, stride, name) \
73582e2b4aSPaul Burton GIC_ACCESSOR_RO_INTR_REG(sz, MIPS_GIC_LOCAL_OFS + off, \
74582e2b4aSPaul Burton stride, vl_##name) \
75582e2b4aSPaul Burton GIC_ACCESSOR_RO_INTR_REG(sz, MIPS_GIC_REDIR_OFS + off, \
76582e2b4aSPaul Burton stride, vo_##name)
77582e2b4aSPaul Burton
78582e2b4aSPaul Burton /* For read-write local per-interrupt registers */
79582e2b4aSPaul Burton #define GIC_VX_ACCESSOR_RW_INTR_REG(sz, off, stride, name) \
80582e2b4aSPaul Burton GIC_ACCESSOR_RW_INTR_REG(sz, MIPS_GIC_LOCAL_OFS + off, \
81582e2b4aSPaul Burton stride, vl_##name) \
82582e2b4aSPaul Burton GIC_ACCESSOR_RW_INTR_REG(sz, MIPS_GIC_REDIR_OFS + off, \
83582e2b4aSPaul Burton stride, vo_##name)
84582e2b4aSPaul Burton
85582e2b4aSPaul Burton /* For read-only shared bit-per-interrupt registers */
86582e2b4aSPaul Burton #define GIC_ACCESSOR_RO_INTR_BIT(off, name) \
87582e2b4aSPaul Burton static inline void __iomem *addr_gic_##name(void) \
88582e2b4aSPaul Burton { \
89582e2b4aSPaul Burton return mips_gic_base + (off); \
90582e2b4aSPaul Burton } \
91582e2b4aSPaul Burton \
92582e2b4aSPaul Burton static inline unsigned int read_gic_##name(unsigned int intr) \
93582e2b4aSPaul Burton { \
94582e2b4aSPaul Burton void __iomem *addr = addr_gic_##name(); \
95582e2b4aSPaul Burton unsigned int val; \
96582e2b4aSPaul Burton \
97582e2b4aSPaul Burton if (mips_cm_is64) { \
98582e2b4aSPaul Burton addr += (intr / 64) * sizeof(uint64_t); \
99582e2b4aSPaul Burton val = __raw_readq(addr) >> intr % 64; \
100582e2b4aSPaul Burton } else { \
101582e2b4aSPaul Burton addr += (intr / 32) * sizeof(uint32_t); \
102582e2b4aSPaul Burton val = __raw_readl(addr) >> intr % 32; \
103582e2b4aSPaul Burton } \
104582e2b4aSPaul Burton \
105582e2b4aSPaul Burton return val & 0x1; \
106582e2b4aSPaul Burton }
107582e2b4aSPaul Burton
108582e2b4aSPaul Burton /* For read-write shared bit-per-interrupt registers */
109582e2b4aSPaul Burton #define GIC_ACCESSOR_RW_INTR_BIT(off, name) \
110582e2b4aSPaul Burton GIC_ACCESSOR_RO_INTR_BIT(off, name) \
111582e2b4aSPaul Burton \
112582e2b4aSPaul Burton static inline void write_gic_##name(unsigned int intr) \
113582e2b4aSPaul Burton { \
114582e2b4aSPaul Burton void __iomem *addr = addr_gic_##name(); \
115582e2b4aSPaul Burton \
116582e2b4aSPaul Burton if (mips_cm_is64) { \
117582e2b4aSPaul Burton addr += (intr / 64) * sizeof(uint64_t); \
118582e2b4aSPaul Burton __raw_writeq(BIT(intr % 64), addr); \
119582e2b4aSPaul Burton } else { \
120582e2b4aSPaul Burton addr += (intr / 32) * sizeof(uint32_t); \
121582e2b4aSPaul Burton __raw_writel(BIT(intr % 32), addr); \
122582e2b4aSPaul Burton } \
123582e2b4aSPaul Burton } \
124582e2b4aSPaul Burton \
125582e2b4aSPaul Burton static inline void change_gic_##name(unsigned int intr, \
126582e2b4aSPaul Burton unsigned int val) \
127582e2b4aSPaul Burton { \
128582e2b4aSPaul Burton void __iomem *addr = addr_gic_##name(); \
129582e2b4aSPaul Burton \
130582e2b4aSPaul Burton if (mips_cm_is64) { \
131582e2b4aSPaul Burton uint64_t _val; \
132582e2b4aSPaul Burton \
133582e2b4aSPaul Burton addr += (intr / 64) * sizeof(uint64_t); \
134582e2b4aSPaul Burton _val = __raw_readq(addr); \
135582e2b4aSPaul Burton _val &= ~BIT_ULL(intr % 64); \
136582e2b4aSPaul Burton _val |= (uint64_t)val << (intr % 64); \
137582e2b4aSPaul Burton __raw_writeq(_val, addr); \
138582e2b4aSPaul Burton } else { \
139582e2b4aSPaul Burton uint32_t _val; \
140582e2b4aSPaul Burton \
141582e2b4aSPaul Burton addr += (intr / 32) * sizeof(uint32_t); \
142582e2b4aSPaul Burton _val = __raw_readl(addr); \
143582e2b4aSPaul Burton _val &= ~BIT(intr % 32); \
144582e2b4aSPaul Burton _val |= val << (intr % 32); \
145582e2b4aSPaul Burton __raw_writel(_val, addr); \
146582e2b4aSPaul Burton } \
147582e2b4aSPaul Burton }
148582e2b4aSPaul Burton
149582e2b4aSPaul Burton /* For read-only local bit-per-interrupt registers */
150582e2b4aSPaul Burton #define GIC_VX_ACCESSOR_RO_INTR_BIT(sz, off, name) \
151582e2b4aSPaul Burton GIC_ACCESSOR_RO_INTR_BIT(sz, MIPS_GIC_LOCAL_OFS + off, \
152582e2b4aSPaul Burton vl_##name) \
153582e2b4aSPaul Burton GIC_ACCESSOR_RO_INTR_BIT(sz, MIPS_GIC_REDIR_OFS + off, \
154582e2b4aSPaul Burton vo_##name)
155582e2b4aSPaul Burton
156582e2b4aSPaul Burton /* For read-write local bit-per-interrupt registers */
157582e2b4aSPaul Burton #define GIC_VX_ACCESSOR_RW_INTR_BIT(sz, off, name) \
158582e2b4aSPaul Burton GIC_ACCESSOR_RW_INTR_BIT(sz, MIPS_GIC_LOCAL_OFS + off, \
159582e2b4aSPaul Burton vl_##name) \
160582e2b4aSPaul Burton GIC_ACCESSOR_RW_INTR_BIT(sz, MIPS_GIC_REDIR_OFS + off, \
161582e2b4aSPaul Burton vo_##name)
162582e2b4aSPaul Burton
163582e2b4aSPaul Burton /* GIC_SH_CONFIG - Information about the GIC configuration */
164582e2b4aSPaul Burton GIC_ACCESSOR_RW(32, 0x000, config)
165582e2b4aSPaul Burton #define GIC_CONFIG_COUNTSTOP BIT(28)
166582e2b4aSPaul Burton #define GIC_CONFIG_COUNTBITS GENMASK(27, 24)
167582e2b4aSPaul Burton #define GIC_CONFIG_NUMINTERRUPTS GENMASK(23, 16)
168582e2b4aSPaul Burton #define GIC_CONFIG_PVPS GENMASK(6, 0)
169582e2b4aSPaul Burton
170582e2b4aSPaul Burton /* GIC_SH_COUNTER - Shared global counter value */
171582e2b4aSPaul Burton GIC_ACCESSOR_RW(64, 0x010, counter)
172582e2b4aSPaul Burton GIC_ACCESSOR_RW(32, 0x010, counter_32l)
173582e2b4aSPaul Burton GIC_ACCESSOR_RW(32, 0x014, counter_32h)
174582e2b4aSPaul Burton
175582e2b4aSPaul Burton /* GIC_SH_POL_* - Configures interrupt polarity */
176582e2b4aSPaul Burton GIC_ACCESSOR_RW_INTR_BIT(0x100, pol)
177582e2b4aSPaul Burton #define GIC_POL_ACTIVE_LOW 0 /* when level triggered */
178582e2b4aSPaul Burton #define GIC_POL_ACTIVE_HIGH 1 /* when level triggered */
179582e2b4aSPaul Burton #define GIC_POL_FALLING_EDGE 0 /* when single-edge triggered */
180582e2b4aSPaul Burton #define GIC_POL_RISING_EDGE 1 /* when single-edge triggered */
181582e2b4aSPaul Burton
182582e2b4aSPaul Burton /* GIC_SH_TRIG_* - Configures interrupts to be edge or level triggered */
183582e2b4aSPaul Burton GIC_ACCESSOR_RW_INTR_BIT(0x180, trig)
184582e2b4aSPaul Burton #define GIC_TRIG_LEVEL 0
185582e2b4aSPaul Burton #define GIC_TRIG_EDGE 1
186582e2b4aSPaul Burton
187582e2b4aSPaul Burton /* GIC_SH_DUAL_* - Configures whether interrupts trigger on both edges */
188582e2b4aSPaul Burton GIC_ACCESSOR_RW_INTR_BIT(0x200, dual)
189582e2b4aSPaul Burton #define GIC_DUAL_SINGLE 0 /* when edge-triggered */
190582e2b4aSPaul Burton #define GIC_DUAL_DUAL 1 /* when edge-triggered */
191582e2b4aSPaul Burton
192582e2b4aSPaul Burton /* GIC_SH_WEDGE - Write an 'edge', ie. trigger an interrupt */
193582e2b4aSPaul Burton GIC_ACCESSOR_RW(32, 0x280, wedge)
194582e2b4aSPaul Burton #define GIC_WEDGE_RW BIT(31)
195582e2b4aSPaul Burton #define GIC_WEDGE_INTR GENMASK(7, 0)
196582e2b4aSPaul Burton
197582e2b4aSPaul Burton /* GIC_SH_RMASK_* - Reset/clear shared interrupt mask bits */
198582e2b4aSPaul Burton GIC_ACCESSOR_RW_INTR_BIT(0x300, rmask)
199582e2b4aSPaul Burton
200582e2b4aSPaul Burton /* GIC_SH_SMASK_* - Set shared interrupt mask bits */
201582e2b4aSPaul Burton GIC_ACCESSOR_RW_INTR_BIT(0x380, smask)
202582e2b4aSPaul Burton
203582e2b4aSPaul Burton /* GIC_SH_MASK_* - Read the current shared interrupt mask */
204582e2b4aSPaul Burton GIC_ACCESSOR_RO_INTR_BIT(0x400, mask)
205582e2b4aSPaul Burton
206582e2b4aSPaul Burton /* GIC_SH_PEND_* - Read currently pending shared interrupts */
207582e2b4aSPaul Burton GIC_ACCESSOR_RO_INTR_BIT(0x480, pend)
208582e2b4aSPaul Burton
209582e2b4aSPaul Burton /* GIC_SH_MAPx_PIN - Map shared interrupts to a particular CPU pin */
210582e2b4aSPaul Burton GIC_ACCESSOR_RW_INTR_REG(32, 0x500, 0x4, map_pin)
211582e2b4aSPaul Burton #define GIC_MAP_PIN_MAP_TO_PIN BIT(31)
212582e2b4aSPaul Burton #define GIC_MAP_PIN_MAP_TO_NMI BIT(30)
213582e2b4aSPaul Burton #define GIC_MAP_PIN_MAP GENMASK(5, 0)
214582e2b4aSPaul Burton
215582e2b4aSPaul Burton /* GIC_SH_MAPx_VP - Map shared interrupts to a particular Virtual Processor */
216582e2b4aSPaul Burton GIC_ACCESSOR_RW_INTR_REG(32, 0x2000, 0x20, map_vp)
217582e2b4aSPaul Burton
218582e2b4aSPaul Burton /* GIC_Vx_CTL - VP-level interrupt control */
219582e2b4aSPaul Burton GIC_VX_ACCESSOR_RW(32, 0x000, ctl)
220582e2b4aSPaul Burton #define GIC_VX_CTL_FDC_ROUTABLE BIT(4)
221582e2b4aSPaul Burton #define GIC_VX_CTL_SWINT_ROUTABLE BIT(3)
222582e2b4aSPaul Burton #define GIC_VX_CTL_PERFCNT_ROUTABLE BIT(2)
223582e2b4aSPaul Burton #define GIC_VX_CTL_TIMER_ROUTABLE BIT(1)
224582e2b4aSPaul Burton #define GIC_VX_CTL_EIC BIT(0)
225582e2b4aSPaul Burton
226582e2b4aSPaul Burton /* GIC_Vx_PEND - Read currently pending local interrupts */
227582e2b4aSPaul Burton GIC_VX_ACCESSOR_RO(32, 0x004, pend)
228582e2b4aSPaul Burton
229582e2b4aSPaul Burton /* GIC_Vx_MASK - Read the current local interrupt mask */
230582e2b4aSPaul Burton GIC_VX_ACCESSOR_RO(32, 0x008, mask)
231582e2b4aSPaul Burton
232582e2b4aSPaul Burton /* GIC_Vx_RMASK - Reset/clear local interrupt mask bits */
233582e2b4aSPaul Burton GIC_VX_ACCESSOR_RW(32, 0x00c, rmask)
234582e2b4aSPaul Burton
235582e2b4aSPaul Burton /* GIC_Vx_SMASK - Set local interrupt mask bits */
236582e2b4aSPaul Burton GIC_VX_ACCESSOR_RW(32, 0x010, smask)
237582e2b4aSPaul Burton
238582e2b4aSPaul Burton /* GIC_Vx_*_MAP - Route local interrupts to the desired pins */
239582e2b4aSPaul Burton GIC_VX_ACCESSOR_RW_INTR_REG(32, 0x040, 0x4, map)
240582e2b4aSPaul Burton
241582e2b4aSPaul Burton /* GIC_Vx_WD_MAP - Route the local watchdog timer interrupt */
242582e2b4aSPaul Burton GIC_VX_ACCESSOR_RW(32, 0x040, wd_map)
243582e2b4aSPaul Burton
244582e2b4aSPaul Burton /* GIC_Vx_COMPARE_MAP - Route the local count/compare interrupt */
245582e2b4aSPaul Burton GIC_VX_ACCESSOR_RW(32, 0x044, compare_map)
246582e2b4aSPaul Burton
247582e2b4aSPaul Burton /* GIC_Vx_TIMER_MAP - Route the local CPU timer (cp0 count/compare) interrupt */
248582e2b4aSPaul Burton GIC_VX_ACCESSOR_RW(32, 0x048, timer_map)
249582e2b4aSPaul Burton
250582e2b4aSPaul Burton /* GIC_Vx_FDC_MAP - Route the local fast debug channel interrupt */
251582e2b4aSPaul Burton GIC_VX_ACCESSOR_RW(32, 0x04c, fdc_map)
252582e2b4aSPaul Burton
253582e2b4aSPaul Burton /* GIC_Vx_PERFCTR_MAP - Route the local performance counter interrupt */
254582e2b4aSPaul Burton GIC_VX_ACCESSOR_RW(32, 0x050, perfctr_map)
255582e2b4aSPaul Burton
256582e2b4aSPaul Burton /* GIC_Vx_SWINT0_MAP - Route the local software interrupt 0 */
257582e2b4aSPaul Burton GIC_VX_ACCESSOR_RW(32, 0x054, swint0_map)
258582e2b4aSPaul Burton
259582e2b4aSPaul Burton /* GIC_Vx_SWINT1_MAP - Route the local software interrupt 1 */
260582e2b4aSPaul Burton GIC_VX_ACCESSOR_RW(32, 0x058, swint1_map)
261582e2b4aSPaul Burton
262582e2b4aSPaul Burton /* GIC_Vx_OTHER - Configure access to other Virtual Processor registers */
263582e2b4aSPaul Burton GIC_VX_ACCESSOR_RW(32, 0x080, other)
264582e2b4aSPaul Burton #define GIC_VX_OTHER_VPNUM GENMASK(5, 0)
265582e2b4aSPaul Burton
266582e2b4aSPaul Burton /* GIC_Vx_IDENT - Retrieve the local Virtual Processor's ID */
267582e2b4aSPaul Burton GIC_VX_ACCESSOR_RO(32, 0x088, ident)
268582e2b4aSPaul Burton #define GIC_VX_IDENT_VPNUM GENMASK(5, 0)
269582e2b4aSPaul Burton
270582e2b4aSPaul Burton /* GIC_Vx_COMPARE - Value to compare with GIC_SH_COUNTER */
271582e2b4aSPaul Burton GIC_VX_ACCESSOR_RW(64, 0x0a0, compare)
272582e2b4aSPaul Burton
273582e2b4aSPaul Burton /* GIC_Vx_EIC_SHADOW_SET_BASE - Set shadow register set for each interrupt */
274582e2b4aSPaul Burton GIC_VX_ACCESSOR_RW_INTR_REG(32, 0x100, 0x4, eic_shadow_set)
275582e2b4aSPaul Burton
276582e2b4aSPaul Burton /**
277ba9cc435SPaul Burton * enum mips_gic_local_interrupt - GIC local interrupts
278ba9cc435SPaul Burton * @GIC_LOCAL_INT_WD: GIC watchdog timer interrupt
279ba9cc435SPaul Burton * @GIC_LOCAL_INT_COMPARE: GIC count/compare interrupt
280ba9cc435SPaul Burton * @GIC_LOCAL_INT_TIMER: CP0 count/compare interrupt
281ba9cc435SPaul Burton * @GIC_LOCAL_INT_PERFCTR: Performance counter interrupt
282ba9cc435SPaul Burton * @GIC_LOCAL_INT_SWINT0: Software interrupt 0
283ba9cc435SPaul Burton * @GIC_LOCAL_INT_SWINT1: Software interrupt 1
284ba9cc435SPaul Burton * @GIC_LOCAL_INT_FDC: Fast debug channel interrupt
285ba9cc435SPaul Burton * @GIC_NUM_LOCAL_INTRS: The number of local interrupts
286ba9cc435SPaul Burton *
287ba9cc435SPaul Burton * Enumerates interrupts provided by the GIC that are local to a VP.
288ba9cc435SPaul Burton */
289ba9cc435SPaul Burton enum mips_gic_local_interrupt {
290ba9cc435SPaul Burton GIC_LOCAL_INT_WD,
291ba9cc435SPaul Burton GIC_LOCAL_INT_COMPARE,
292ba9cc435SPaul Burton GIC_LOCAL_INT_TIMER,
293ba9cc435SPaul Burton GIC_LOCAL_INT_PERFCTR,
294ba9cc435SPaul Burton GIC_LOCAL_INT_SWINT0,
295ba9cc435SPaul Burton GIC_LOCAL_INT_SWINT1,
296ba9cc435SPaul Burton GIC_LOCAL_INT_FDC,
297ba9cc435SPaul Burton GIC_NUM_LOCAL_INTRS
298ba9cc435SPaul Burton };
299ba9cc435SPaul Burton
300ba9cc435SPaul Burton /**
301582e2b4aSPaul Burton * mips_gic_present() - Determine whether a GIC is present
302582e2b4aSPaul Burton *
303582e2b4aSPaul Burton * Determines whether a MIPS Global Interrupt Controller (GIC) is present in
304582e2b4aSPaul Burton * the system that the kernel is running on.
305582e2b4aSPaul Burton *
306582e2b4aSPaul Burton * Return true if a GIC is present, else false.
307582e2b4aSPaul Burton */
mips_gic_present(void)308582e2b4aSPaul Burton static inline bool mips_gic_present(void)
309582e2b4aSPaul Burton {
310582e2b4aSPaul Burton return IS_ENABLED(CONFIG_MIPS_GIC) && mips_gic_base;
311582e2b4aSPaul Burton }
312582e2b4aSPaul Burton
313dd016350SPaul Burton /**
314*6d4d367dSPaul Burton * mips_gic_vx_map_reg() - Return GIC_Vx_<intr>_MAP register offset
315*6d4d367dSPaul Burton * @intr: A GIC local interrupt
316*6d4d367dSPaul Burton *
317*6d4d367dSPaul Burton * Determine the index of the GIC_VL_<intr>_MAP or GIC_VO_<intr>_MAP register
318*6d4d367dSPaul Burton * within the block of GIC map registers. This is almost the same as the order
319*6d4d367dSPaul Burton * of interrupts in the pending & mask registers, as used by enum
320*6d4d367dSPaul Burton * mips_gic_local_interrupt, but moves the FDC interrupt & thus offsets the
321*6d4d367dSPaul Burton * interrupts after it...
322*6d4d367dSPaul Burton *
323*6d4d367dSPaul Burton * Return: The map register index corresponding to @intr.
324*6d4d367dSPaul Burton *
325*6d4d367dSPaul Burton * The return value is suitable for use with the (read|write)_gic_v[lo]_map
326*6d4d367dSPaul Burton * accessor functions.
327*6d4d367dSPaul Burton */
328*6d4d367dSPaul Burton static inline unsigned int
mips_gic_vx_map_reg(enum mips_gic_local_interrupt intr)329*6d4d367dSPaul Burton mips_gic_vx_map_reg(enum mips_gic_local_interrupt intr)
330*6d4d367dSPaul Burton {
331*6d4d367dSPaul Burton /* WD, Compare & Timer are 1:1 */
332*6d4d367dSPaul Burton if (intr <= GIC_LOCAL_INT_TIMER)
333*6d4d367dSPaul Burton return intr;
334*6d4d367dSPaul Burton
335*6d4d367dSPaul Burton /* FDC moves to after Timer... */
336*6d4d367dSPaul Burton if (intr == GIC_LOCAL_INT_FDC)
337*6d4d367dSPaul Burton return GIC_LOCAL_INT_TIMER + 1;
338*6d4d367dSPaul Burton
339*6d4d367dSPaul Burton /* As a result everything else is offset by 1 */
340*6d4d367dSPaul Burton return intr + 1;
341*6d4d367dSPaul Burton }
342*6d4d367dSPaul Burton
343*6d4d367dSPaul Burton /**
344dd016350SPaul Burton * gic_get_c0_compare_int() - Return cp0 count/compare interrupt virq
345dd016350SPaul Burton *
346dd016350SPaul Burton * Determine the virq number to use for the coprocessor 0 count/compare
347dd016350SPaul Burton * interrupt, which may be routed via the GIC.
348dd016350SPaul Burton *
349dd016350SPaul Burton * Returns the virq number or a negative error number.
350dd016350SPaul Burton */
351dd016350SPaul Burton extern int gic_get_c0_compare_int(void);
352dd016350SPaul Burton
353dd016350SPaul Burton /**
354dd016350SPaul Burton * gic_get_c0_perfcount_int() - Return performance counter interrupt virq
355dd016350SPaul Burton *
356dd016350SPaul Burton * Determine the virq number to use for CPU performance counter interrupts,
357dd016350SPaul Burton * which may be routed via the GIC.
358dd016350SPaul Burton *
359dd016350SPaul Burton * Returns the virq number or a negative error number.
360dd016350SPaul Burton */
361dd016350SPaul Burton extern int gic_get_c0_perfcount_int(void);
362dd016350SPaul Burton
363dd016350SPaul Burton /**
364dd016350SPaul Burton * gic_get_c0_fdc_int() - Return fast debug channel interrupt virq
365dd016350SPaul Burton *
366dd016350SPaul Burton * Determine the virq number to use for fast debug channel (FDC) interrupts,
367dd016350SPaul Burton * which may be routed via the GIC.
368dd016350SPaul Burton *
369dd016350SPaul Burton * Returns the virq number or a negative error number.
370dd016350SPaul Burton */
371dd016350SPaul Burton extern int gic_get_c0_fdc_int(void);
372dd016350SPaul Burton
373582e2b4aSPaul Burton #endif /* __MIPS_ASM_MIPS_CPS_H__ */
374