Skip to content

Commit e9de688

Browse files
abresticralfbaechle
authored andcommitted
irqchip: mips-gic: Support local interrupts
The MIPS GIC supports 7 local interrupts, 2 of which are the GIC local watchdog and count/compare timer. The remainder are CPU interrupts which may optionally be re-routed through the GIC. GIC hardware IRQs 0-6 are now used for local interrupts while hardware IRQs 7+ are used for external (shared) interrupts. Note that the 5 CPU interrupts may not be re-routable through the GIC. In that case mapping will fail and the vectors reported in C0_IntCtl should be used instead. gic_get_c0_compare_int() and gic_get_c0_perfcount_int() will return the correct IRQ number to use for the C0 timer and perfcounter interrupts based on the routability of those interrupts through the GIC. A separate irq_chip, with callbacks that mask/unmask the local interrupt on all CPUs, is used for the C0 timer and performance counter interrupts since all other platforms do not use the percpu IRQ API for those interrupts. Malta, SEAD-3, and the GIC clockevent driver have been updated to use local interrupts and the R4K clockevent driver has been updated to poll for C0 timer interrupts through the GIC when the GIC is present. Signed-off-by: Andrew Bresticker <abrestic@chromium.org> Acked-by: Jason Cooper <jason@lakedaemon.net> Reviewed-by: Qais Yousef <qais.yousef@imgtec.com> Tested-by: Qais Yousef <qais.yousef@imgtec.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Jeffrey Deans <jeffrey.deans@imgtec.com> Cc: Markos Chandras <markos.chandras@imgtec.com> Cc: Paul Burton <paul.burton@imgtec.com> Cc: Jonas Gorski <jogo@openwrt.org> Cc: John Crispin <blogic@openwrt.org> Cc: David Daney <ddaney.cavm@gmail.com> Cc: linux-mips@linux-mips.org Cc: linux-kernel@vger.kernel.org Patchwork: https://patchwork.linux-mips.org/patch/7819/ Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
1 parent 4a6a3ea commit e9de688

File tree

9 files changed

+279
-125
lines changed

9 files changed

+279
-125
lines changed

arch/mips/include/asm/gic.h

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@
209209
#define GIC_VPE_WD_MAP_OFS 0x0040
210210
#define GIC_VPE_COMPARE_MAP_OFS 0x0044
211211
#define GIC_VPE_TIMER_MAP_OFS 0x0048
212+
#define GIC_VPE_FDC_MAP_OFS 0x004c
212213
#define GIC_VPE_PERFCTR_MAP_OFS 0x0050
213214
#define GIC_VPE_SWINT0_MAP_OFS 0x0054
214215
#define GIC_VPE_SWINT1_MAP_OFS 0x0058
@@ -262,6 +263,10 @@
262263
#define GIC_MAP_MSK (MSK(6) << GIC_MAP_SHF)
263264

264265
/* GIC_VPE_CTL Masks */
266+
#define GIC_VPE_CTL_FDC_RTBL_SHF 4
267+
#define GIC_VPE_CTL_FDC_RTBL_MSK (MSK(1) << GIC_VPE_CTL_FDC_RTBL_SHF)
268+
#define GIC_VPE_CTL_SWINT_RTBL_SHF 3
269+
#define GIC_VPE_CTL_SWINT_RTBL_MSK (MSK(1) << GIC_VPE_CTL_SWINT_RTBL_SHF)
265270
#define GIC_VPE_CTL_PERFCNT_RTBL_SHF 2
266271
#define GIC_VPE_CTL_PERFCNT_RTBL_MSK (MSK(1) << GIC_VPE_CTL_PERFCNT_RTBL_SHF)
267272
#define GIC_VPE_CTL_TIMER_RTBL_SHF 1
@@ -329,16 +334,30 @@
329334
/* Add 2 to convert GIC CPU pin to core interrupt */
330335
#define GIC_CPU_PIN_OFFSET 2
331336

332-
/* Local GIC interrupts. */
333-
#define GIC_INT_TMR (GIC_CPU_INT5)
334-
#define GIC_INT_PERFCTR (GIC_CPU_INT5)
335-
336337
/* Add 2 to convert non-EIC hardware interrupt to EIC vector number. */
337338
#define GIC_CPU_TO_VEC_OFFSET (2)
338339

339340
/* Mapped interrupt to pin X, then GIC will generate the vector (X+1). */
340341
#define GIC_PIN_TO_VEC_OFFSET (1)
341342

343+
/* Local GIC interrupts. */
344+
#define GIC_LOCAL_INT_WD 0 /* GIC watchdog */
345+
#define GIC_LOCAL_INT_COMPARE 1 /* GIC count and compare timer */
346+
#define GIC_LOCAL_INT_TIMER 2 /* CPU timer interrupt */
347+
#define GIC_LOCAL_INT_PERFCTR 3 /* CPU performance counter */
348+
#define GIC_LOCAL_INT_SWINT0 4 /* CPU software interrupt 0 */
349+
#define GIC_LOCAL_INT_SWINT1 5 /* CPU software interrupt 1 */
350+
#define GIC_LOCAL_INT_FDC 6 /* CPU fast debug channel */
351+
#define GIC_NUM_LOCAL_INTRS 7
352+
353+
/* Convert between local/shared IRQ number and GIC HW IRQ number. */
354+
#define GIC_LOCAL_HWIRQ_BASE 0
355+
#define GIC_LOCAL_TO_HWIRQ(x) (GIC_LOCAL_HWIRQ_BASE + (x))
356+
#define GIC_HWIRQ_TO_LOCAL(x) ((x) - GIC_LOCAL_HWIRQ_BASE)
357+
#define GIC_SHARED_HWIRQ_BASE GIC_NUM_LOCAL_INTRS
358+
#define GIC_SHARED_TO_HWIRQ(x) (GIC_SHARED_HWIRQ_BASE + (x))
359+
#define GIC_HWIRQ_TO_SHARED(x) ((x) - GIC_SHARED_HWIRQ_BASE)
360+
342361
#include <linux/clocksource.h>
343362
#include <linux/irq.h>
344363

@@ -363,4 +382,6 @@ extern void gic_bind_eic_interrupt(int irq, int set);
363382
extern unsigned int gic_get_timer_pending(void);
364383
extern void gic_get_int_mask(unsigned long *dst, const unsigned long *src);
365384
extern unsigned int gic_get_int(void);
385+
extern int gic_get_c0_compare_int(void);
386+
extern int gic_get_c0_perfcount_int(void);
366387
#endif /* _ASM_GICREGS_H */

arch/mips/include/asm/mips-boards/maltaint.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#ifndef _MIPS_MALTAINT_H
1111
#define _MIPS_MALTAINT_H
1212

13+
#include <asm/gic.h>
14+
1315
/*
1416
* Interrupts 0..15 are used for Malta ISA compatible interrupts
1517
*/
@@ -61,6 +63,6 @@
6163
#define MSC01E_INT_CPUCTR 11
6264

6365
/* GIC external interrupts */
64-
#define GIC_INT_I8259A 3
66+
#define GIC_INT_I8259A GIC_SHARED_TO_HWIRQ(3)
6567

6668
#endif /* !(_MIPS_MALTAINT_H) */

arch/mips/include/asm/mips-boards/sead3int.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#ifndef _MIPS_SEAD3INT_H
1111
#define _MIPS_SEAD3INT_H
1212

13+
#include <asm/gic.h>
14+
1315
/* SEAD-3 GIC address space definitions. */
1416
#define GIC_BASE_ADDR 0x1b1c0000
1517
#define GIC_ADDRSPACE_SZ (128 * 1024)
@@ -22,9 +24,9 @@
2224
#define CPU_INT_NET 6
2325

2426
/* GIC interrupt offsets */
25-
#define GIC_INT_NET 0
26-
#define GIC_INT_UART1 2
27-
#define GIC_INT_UART0 3
28-
#define GIC_INT_EHCI 5
27+
#define GIC_INT_NET GIC_SHARED_TO_HWIRQ(0)
28+
#define GIC_INT_UART1 GIC_SHARED_TO_HWIRQ(2)
29+
#define GIC_INT_UART0 GIC_SHARED_TO_HWIRQ(3)
30+
#define GIC_INT_EHCI GIC_SHARED_TO_HWIRQ(5)
2931

3032
#endif /* !(_MIPS_SEAD3INT_H) */

arch/mips/kernel/cevt-gic.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ int gic_clockevent_init(void)
6868
if (!cpu_has_counter || !gic_frequency)
6969
return -ENXIO;
7070

71-
irq = MIPS_GIC_IRQ_BASE;
71+
irq = MIPS_GIC_IRQ_BASE + GIC_LOCAL_TO_HWIRQ(GIC_LOCAL_INT_COMPARE);
7272

7373
cd = &per_cpu(gic_clockevent_device, cpu);
7474

@@ -91,16 +91,13 @@ int gic_clockevent_init(void)
9191

9292
clockevents_register_device(cd);
9393

94-
GICWRITE(GIC_REG(VPE_LOCAL, GIC_VPE_COMPARE_MAP),
95-
GIC_MAP_TO_PIN_MSK | gic_cpu_pin);
96-
GICWRITE(GIC_REG(VPE_LOCAL, GIC_VPE_SMASK), GIC_VPE_SMASK_CMP_MSK);
94+
if (!gic_timer_irq_installed) {
95+
setup_percpu_irq(irq, &gic_compare_irqaction);
96+
gic_timer_irq_installed = 1;
97+
}
9798

98-
if (gic_timer_irq_installed)
99-
return 0;
99+
enable_percpu_irq(irq, IRQ_TYPE_NONE);
100100

101-
gic_timer_irq_installed = 1;
102101

103-
setup_irq(irq, &gic_compare_irqaction);
104-
irq_set_handler(irq, handle_percpu_irq);
105102
return 0;
106103
}

arch/mips/kernel/cevt-r4k.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ void mips_event_handler(struct clock_event_device *dev)
8686
static int c0_compare_int_pending(void)
8787
{
8888
#ifdef CONFIG_MIPS_GIC
89-
if (cpu_has_veic)
89+
if (gic_present)
9090
return gic_get_timer_pending();
9191
#endif
9292
return (read_c0_cause() >> cp0_compare_irq_shift) & (1ul << CAUSEB_IP);

arch/mips/mti-malta/malta-int.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -273,11 +273,7 @@ asmlinkage void plat_irq_dispatch(void)
273273

274274
irq = irq_ffs(pending);
275275

276-
/* HACK: GIC doesn't properly dispatch local interrupts yet */
277-
if (gic_present && irq == MIPSCPU_INT_GIC && gic_compare_int())
278-
do_IRQ(MIPS_GIC_IRQ_BASE);
279-
else
280-
do_IRQ(MIPS_CPU_IRQ_BASE + irq);
276+
do_IRQ(MIPS_CPU_IRQ_BASE + irq);
281277
}
282278

283279
#ifdef CONFIG_MIPS_MT_SMP

arch/mips/mti-malta/malta-time.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,9 @@ int get_c0_perfcount_int(void)
126126
if (cpu_has_veic) {
127127
set_vi_handler(MSC01E_INT_PERFCTR, mips_perf_dispatch);
128128
mips_cpu_perf_irq = MSC01E_INT_BASE + MSC01E_INT_PERFCTR;
129+
} else if (gic_present) {
130+
mips_cpu_perf_irq = gic_get_c0_perfcount_int();
129131
} else if (cp0_perfcount_irq >= 0) {
130-
if (cpu_has_vint)
131-
set_vi_handler(cp0_perfcount_irq, mips_perf_dispatch);
132132
mips_cpu_perf_irq = MIPS_CPU_IRQ_BASE + cp0_perfcount_irq;
133133
} else {
134134
mips_cpu_perf_irq = -1;
@@ -139,15 +139,12 @@ int get_c0_perfcount_int(void)
139139

140140
unsigned int get_c0_compare_int(void)
141141
{
142-
#ifdef MSC01E_INT_BASE
143142
if (cpu_has_veic) {
144143
set_vi_handler(MSC01E_INT_CPUCTR, mips_timer_dispatch);
145144
mips_cpu_timer_irq = MSC01E_INT_BASE + MSC01E_INT_CPUCTR;
146-
} else
147-
#endif
148-
{
149-
if (cpu_has_vint)
150-
set_vi_handler(cp0_compare_irq, mips_timer_dispatch);
145+
} else if (gic_present) {
146+
mips_cpu_timer_irq = gic_get_c0_compare_int();
147+
} else {
151148
mips_cpu_timer_irq = MIPS_CPU_IRQ_BASE + cp0_compare_irq;
152149
}
153150

arch/mips/mti-sead3/sead3-time.c

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,12 @@
88
#include <linux/init.h>
99

1010
#include <asm/cpu.h>
11+
#include <asm/gic.h>
1112
#include <asm/setup.h>
1213
#include <asm/time.h>
1314
#include <asm/irq.h>
1415
#include <asm/mips-boards/generic.h>
1516

16-
static int mips_cpu_timer_irq;
17-
static int mips_cpu_perf_irq;
18-
19-
static void mips_timer_dispatch(void)
20-
{
21-
do_IRQ(mips_cpu_timer_irq);
22-
}
23-
24-
static void mips_perf_dispatch(void)
25-
{
26-
do_IRQ(mips_cpu_perf_irq);
27-
}
28-
2917
static void __iomem *status_reg = (void __iomem *)0xbf000410;
3018

3119
/*
@@ -83,22 +71,18 @@ void read_persistent_clock(struct timespec *ts)
8371

8472
int get_c0_perfcount_int(void)
8573
{
86-
if (cp0_perfcount_irq >= 0) {
87-
if (cpu_has_vint)
88-
set_vi_handler(cp0_perfcount_irq, mips_perf_dispatch);
89-
mips_cpu_perf_irq = MIPS_CPU_IRQ_BASE + cp0_perfcount_irq;
90-
} else {
91-
mips_cpu_perf_irq = -1;
92-
}
93-
return mips_cpu_perf_irq;
74+
if (gic_present)
75+
return gic_get_c0_compare_int();
76+
if (cp0_perfcount_irq >= 0)
77+
return MIPS_CPU_IRQ_BASE + cp0_perfcount_irq;
78+
return -1;
9479
}
9580

9681
unsigned int get_c0_compare_int(void)
9782
{
98-
if (cpu_has_vint)
99-
set_vi_handler(cp0_compare_irq, mips_timer_dispatch);
100-
mips_cpu_timer_irq = MIPS_CPU_IRQ_BASE + cp0_compare_irq;
101-
return mips_cpu_timer_irq;
83+
if (gic_present)
84+
return gic_get_c0_compare_int();
85+
return MIPS_CPU_IRQ_BASE + cp0_compare_irq;
10286
}
10387

10488
void __init plat_time_init(void)

0 commit comments

Comments
 (0)