1b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0
21da177e4SLinus Torvalds /*
31da177e4SLinus Torvalds * ip22-int.c: Routines for generic manipulation of the INT[23] ASIC
41da177e4SLinus Torvalds * found on INDY and Indigo2 workstations.
51da177e4SLinus Torvalds *
679add627SJustin P. Mattock * Copyright (C) 1996 David S. Miller (davem@davemloft.net)
71da177e4SLinus Torvalds * Copyright (C) 1997, 1998 Ralf Baechle (ralf@gnu.org)
81da177e4SLinus Torvalds * Copyright (C) 1999 Andrew R. Baker (andrewb@uab.edu)
91da177e4SLinus Torvalds * - Indigo2 changes
101da177e4SLinus Torvalds * - Interrupt handling fixes
111da177e4SLinus Torvalds * Copyright (C) 2001, 2003 Ladislav Michl (ladis@linux-mips.org)
121da177e4SLinus Torvalds */
131da177e4SLinus Torvalds #include <linux/types.h>
141da177e4SLinus Torvalds #include <linux/init.h>
151da177e4SLinus Torvalds #include <linux/kernel_stat.h>
161da177e4SLinus Torvalds #include <linux/interrupt.h>
178f99a162SWu Zhangjin #include <linux/ftrace.h>
181da177e4SLinus Torvalds
1997dcb82dSAtsushi Nemoto #include <asm/irq_cpu.h>
201da177e4SLinus Torvalds #include <asm/sgi/hpc3.h>
211da177e4SLinus Torvalds #include <asm/sgi/ip22.h>
221da177e4SLinus Torvalds
231da177e4SLinus Torvalds /* So far nothing hangs here */
241da177e4SLinus Torvalds #undef USE_LIO3_IRQ
251da177e4SLinus Torvalds
261da177e4SLinus Torvalds struct sgint_regs *sgint;
271da177e4SLinus Torvalds
281da177e4SLinus Torvalds static char lc0msk_to_irqnr[256];
291da177e4SLinus Torvalds static char lc1msk_to_irqnr[256];
301da177e4SLinus Torvalds static char lc2msk_to_irqnr[256];
311da177e4SLinus Torvalds static char lc3msk_to_irqnr[256];
321da177e4SLinus Torvalds
331da177e4SLinus Torvalds extern int ip22_eisa_init(void);
341da177e4SLinus Torvalds
enable_local0_irq(struct irq_data * d)359458ea56SThomas Gleixner static void enable_local0_irq(struct irq_data *d)
361da177e4SLinus Torvalds {
371da177e4SLinus Torvalds /* don't allow mappable interrupt to be enabled from setup_irq,
381da177e4SLinus Torvalds * we have our own way to do so */
399458ea56SThomas Gleixner if (d->irq != SGI_MAP_0_IRQ)
409458ea56SThomas Gleixner sgint->imask0 |= (1 << (d->irq - SGINT_LOCAL0));
411da177e4SLinus Torvalds }
421da177e4SLinus Torvalds
disable_local0_irq(struct irq_data * d)439458ea56SThomas Gleixner static void disable_local0_irq(struct irq_data *d)
441da177e4SLinus Torvalds {
459458ea56SThomas Gleixner sgint->imask0 &= ~(1 << (d->irq - SGINT_LOCAL0));
461da177e4SLinus Torvalds }
471da177e4SLinus Torvalds
4894dee171SRalf Baechle static struct irq_chip ip22_local0_irq_type = {
4970d21cdeSAtsushi Nemoto .name = "IP22 local 0",
509458ea56SThomas Gleixner .irq_mask = disable_local0_irq,
519458ea56SThomas Gleixner .irq_unmask = enable_local0_irq,
521da177e4SLinus Torvalds };
531da177e4SLinus Torvalds
enable_local1_irq(struct irq_data * d)549458ea56SThomas Gleixner static void enable_local1_irq(struct irq_data *d)
551da177e4SLinus Torvalds {
561da177e4SLinus Torvalds /* don't allow mappable interrupt to be enabled from setup_irq,
571da177e4SLinus Torvalds * we have our own way to do so */
589458ea56SThomas Gleixner if (d->irq != SGI_MAP_1_IRQ)
599458ea56SThomas Gleixner sgint->imask1 |= (1 << (d->irq - SGINT_LOCAL1));
601da177e4SLinus Torvalds }
611da177e4SLinus Torvalds
disable_local1_irq(struct irq_data * d)629458ea56SThomas Gleixner static void disable_local1_irq(struct irq_data *d)
631da177e4SLinus Torvalds {
649458ea56SThomas Gleixner sgint->imask1 &= ~(1 << (d->irq - SGINT_LOCAL1));
651da177e4SLinus Torvalds }
661da177e4SLinus Torvalds
6794dee171SRalf Baechle static struct irq_chip ip22_local1_irq_type = {
6870d21cdeSAtsushi Nemoto .name = "IP22 local 1",
699458ea56SThomas Gleixner .irq_mask = disable_local1_irq,
709458ea56SThomas Gleixner .irq_unmask = enable_local1_irq,
711da177e4SLinus Torvalds };
721da177e4SLinus Torvalds
enable_local2_irq(struct irq_data * d)739458ea56SThomas Gleixner static void enable_local2_irq(struct irq_data *d)
741da177e4SLinus Torvalds {
751da177e4SLinus Torvalds sgint->imask0 |= (1 << (SGI_MAP_0_IRQ - SGINT_LOCAL0));
769458ea56SThomas Gleixner sgint->cmeimask0 |= (1 << (d->irq - SGINT_LOCAL2));
771da177e4SLinus Torvalds }
781da177e4SLinus Torvalds
disable_local2_irq(struct irq_data * d)799458ea56SThomas Gleixner static void disable_local2_irq(struct irq_data *d)
801da177e4SLinus Torvalds {
819458ea56SThomas Gleixner sgint->cmeimask0 &= ~(1 << (d->irq - SGINT_LOCAL2));
821da177e4SLinus Torvalds if (!sgint->cmeimask0)
831da177e4SLinus Torvalds sgint->imask0 &= ~(1 << (SGI_MAP_0_IRQ - SGINT_LOCAL0));
841da177e4SLinus Torvalds }
851da177e4SLinus Torvalds
8694dee171SRalf Baechle static struct irq_chip ip22_local2_irq_type = {
8770d21cdeSAtsushi Nemoto .name = "IP22 local 2",
889458ea56SThomas Gleixner .irq_mask = disable_local2_irq,
899458ea56SThomas Gleixner .irq_unmask = enable_local2_irq,
901da177e4SLinus Torvalds };
911da177e4SLinus Torvalds
enable_local3_irq(struct irq_data * d)929458ea56SThomas Gleixner static void enable_local3_irq(struct irq_data *d)
931da177e4SLinus Torvalds {
941da177e4SLinus Torvalds sgint->imask1 |= (1 << (SGI_MAP_1_IRQ - SGINT_LOCAL1));
959458ea56SThomas Gleixner sgint->cmeimask1 |= (1 << (d->irq - SGINT_LOCAL3));
961da177e4SLinus Torvalds }
971da177e4SLinus Torvalds
disable_local3_irq(struct irq_data * d)989458ea56SThomas Gleixner static void disable_local3_irq(struct irq_data *d)
991da177e4SLinus Torvalds {
1009458ea56SThomas Gleixner sgint->cmeimask1 &= ~(1 << (d->irq - SGINT_LOCAL3));
1011da177e4SLinus Torvalds if (!sgint->cmeimask1)
1021da177e4SLinus Torvalds sgint->imask1 &= ~(1 << (SGI_MAP_1_IRQ - SGINT_LOCAL1));
1031da177e4SLinus Torvalds }
1041da177e4SLinus Torvalds
10594dee171SRalf Baechle static struct irq_chip ip22_local3_irq_type = {
10670d21cdeSAtsushi Nemoto .name = "IP22 local 3",
1079458ea56SThomas Gleixner .irq_mask = disable_local3_irq,
1089458ea56SThomas Gleixner .irq_unmask = enable_local3_irq,
1091da177e4SLinus Torvalds };
1101da177e4SLinus Torvalds
indy_local0_irqdispatch(void)111937a8015SRalf Baechle static void indy_local0_irqdispatch(void)
1121da177e4SLinus Torvalds {
1131da177e4SLinus Torvalds u8 mask = sgint->istat0 & sgint->imask0;
1141da177e4SLinus Torvalds u8 mask2;
1151da177e4SLinus Torvalds int irq;
1161da177e4SLinus Torvalds
1171da177e4SLinus Torvalds if (mask & SGINT_ISTAT0_LIO2) {
1181da177e4SLinus Torvalds mask2 = sgint->vmeistat & sgint->cmeimask0;
1191da177e4SLinus Torvalds irq = lc2msk_to_irqnr[mask2];
1201da177e4SLinus Torvalds } else
1211da177e4SLinus Torvalds irq = lc0msk_to_irqnr[mask];
1221da177e4SLinus Torvalds
1231d421ca9SThomas Bogendoerfer /*
1241d421ca9SThomas Bogendoerfer * workaround for INT2 bug; if irq == 0, INT2 has seen a fifo full
1251d421ca9SThomas Bogendoerfer * irq, but failed to latch it into status register
1261d421ca9SThomas Bogendoerfer */
1271da177e4SLinus Torvalds if (irq)
128937a8015SRalf Baechle do_IRQ(irq);
1291d421ca9SThomas Bogendoerfer else
1301d421ca9SThomas Bogendoerfer do_IRQ(SGINT_LOCAL0 + 0);
1311da177e4SLinus Torvalds }
1321da177e4SLinus Torvalds
indy_local1_irqdispatch(void)133937a8015SRalf Baechle static void indy_local1_irqdispatch(void)
1341da177e4SLinus Torvalds {
1351da177e4SLinus Torvalds u8 mask = sgint->istat1 & sgint->imask1;
1361da177e4SLinus Torvalds u8 mask2;
1371da177e4SLinus Torvalds int irq;
1381da177e4SLinus Torvalds
1391da177e4SLinus Torvalds if (mask & SGINT_ISTAT1_LIO3) {
1401da177e4SLinus Torvalds mask2 = sgint->vmeistat & sgint->cmeimask1;
1411da177e4SLinus Torvalds irq = lc3msk_to_irqnr[mask2];
1421da177e4SLinus Torvalds } else
1431da177e4SLinus Torvalds irq = lc1msk_to_irqnr[mask];
1441da177e4SLinus Torvalds
1451da177e4SLinus Torvalds /* if irq == 0, then the interrupt has already been cleared */
1461da177e4SLinus Torvalds if (irq)
147937a8015SRalf Baechle do_IRQ(irq);
1481da177e4SLinus Torvalds }
1491da177e4SLinus Torvalds
150937a8015SRalf Baechle extern void ip22_be_interrupt(int irq);
1511da177e4SLinus Torvalds
indy_buserror_irq(void)1528f99a162SWu Zhangjin static void __irq_entry indy_buserror_irq(void)
1531da177e4SLinus Torvalds {
1541da177e4SLinus Torvalds int irq = SGI_BUSERR_IRQ;
1551da177e4SLinus Torvalds
1561da177e4SLinus Torvalds irq_enter();
157310ff2c8SThomas Gleixner kstat_incr_irq_this_cpu(irq);
158937a8015SRalf Baechle ip22_be_interrupt(irq);
1591da177e4SLinus Torvalds irq_exit();
1601da177e4SLinus Torvalds }
1611da177e4SLinus Torvalds
1621da177e4SLinus Torvalds #ifdef USE_LIO3_IRQ
1631da177e4SLinus Torvalds #define SGI_INTERRUPTS SGINT_END
1641da177e4SLinus Torvalds #else
1651da177e4SLinus Torvalds #define SGI_INTERRUPTS SGINT_LOCAL3
1661da177e4SLinus Torvalds #endif
1671da177e4SLinus Torvalds
168e4ac58afSRalf Baechle /*
169e4ac58afSRalf Baechle * IRQs on the INDY look basically (barring software IRQs which we don't use
170e4ac58afSRalf Baechle * at all) like:
171e4ac58afSRalf Baechle *
172e4ac58afSRalf Baechle * MIPS IRQ Source
173e4ac58afSRalf Baechle * -------- ------
174e4ac58afSRalf Baechle * 0 Software (ignored)
175e4ac58afSRalf Baechle * 1 Software (ignored)
176e4ac58afSRalf Baechle * 2 Local IRQ level zero
177e4ac58afSRalf Baechle * 3 Local IRQ level one
178e4ac58afSRalf Baechle * 4 8254 Timer zero
179e4ac58afSRalf Baechle * 5 8254 Timer one
180e4ac58afSRalf Baechle * 6 Bus Error
181e4ac58afSRalf Baechle * 7 R4k timer (what we use)
182e4ac58afSRalf Baechle *
183e4ac58afSRalf Baechle * We handle the IRQ according to _our_ priority which is:
184e4ac58afSRalf Baechle *
185e4ac58afSRalf Baechle * Highest ---- R4k Timer
186e4ac58afSRalf Baechle * Local IRQ zero
187e4ac58afSRalf Baechle * Local IRQ one
188e4ac58afSRalf Baechle * Bus Error
189e4ac58afSRalf Baechle * 8254 Timer zero
190e4ac58afSRalf Baechle * Lowest ---- 8254 Timer one
191e4ac58afSRalf Baechle *
192e4ac58afSRalf Baechle * then we just return, if multiple IRQs are pending then we will just take
193e4ac58afSRalf Baechle * another exception, big deal.
194e4ac58afSRalf Baechle */
195e4ac58afSRalf Baechle
plat_irq_dispatch(void)196937a8015SRalf Baechle asmlinkage void plat_irq_dispatch(void)
197e4ac58afSRalf Baechle {
198119537c0SThiemo Seufer unsigned int pending = read_c0_status() & read_c0_cause();
199e4ac58afSRalf Baechle
200e4ac58afSRalf Baechle /*
201e4ac58afSRalf Baechle * First we check for r4k counter/timer IRQ.
202e4ac58afSRalf Baechle */
203e4ac58afSRalf Baechle if (pending & CAUSEF_IP7)
2047bcf7717SRalf Baechle do_IRQ(SGI_TIMER_IRQ);
205e4ac58afSRalf Baechle else if (pending & CAUSEF_IP2)
206937a8015SRalf Baechle indy_local0_irqdispatch();
207e4ac58afSRalf Baechle else if (pending & CAUSEF_IP3)
208937a8015SRalf Baechle indy_local1_irqdispatch();
209e4ac58afSRalf Baechle else if (pending & CAUSEF_IP6)
210937a8015SRalf Baechle indy_buserror_irq();
211e4ac58afSRalf Baechle else if (pending & (CAUSEF_IP4 | CAUSEF_IP5))
212937a8015SRalf Baechle indy_8254timer_irq();
213e4ac58afSRalf Baechle }
214e4ac58afSRalf Baechle
arch_init_irq(void)2151da177e4SLinus Torvalds void __init arch_init_irq(void)
2161da177e4SLinus Torvalds {
2171da177e4SLinus Torvalds int i;
2181da177e4SLinus Torvalds
2191da177e4SLinus Torvalds /* Init local mask --> irq tables. */
2201da177e4SLinus Torvalds for (i = 0; i < 256; i++) {
2211da177e4SLinus Torvalds if (i & 0x80) {
2221da177e4SLinus Torvalds lc0msk_to_irqnr[i] = SGINT_LOCAL0 + 7;
2231da177e4SLinus Torvalds lc1msk_to_irqnr[i] = SGINT_LOCAL1 + 7;
2241da177e4SLinus Torvalds lc2msk_to_irqnr[i] = SGINT_LOCAL2 + 7;
2251da177e4SLinus Torvalds lc3msk_to_irqnr[i] = SGINT_LOCAL3 + 7;
2261da177e4SLinus Torvalds } else if (i & 0x40) {
2271da177e4SLinus Torvalds lc0msk_to_irqnr[i] = SGINT_LOCAL0 + 6;
2281da177e4SLinus Torvalds lc1msk_to_irqnr[i] = SGINT_LOCAL1 + 6;
2291da177e4SLinus Torvalds lc2msk_to_irqnr[i] = SGINT_LOCAL2 + 6;
2301da177e4SLinus Torvalds lc3msk_to_irqnr[i] = SGINT_LOCAL3 + 6;
2311da177e4SLinus Torvalds } else if (i & 0x20) {
2321da177e4SLinus Torvalds lc0msk_to_irqnr[i] = SGINT_LOCAL0 + 5;
2331da177e4SLinus Torvalds lc1msk_to_irqnr[i] = SGINT_LOCAL1 + 5;
2341da177e4SLinus Torvalds lc2msk_to_irqnr[i] = SGINT_LOCAL2 + 5;
2351da177e4SLinus Torvalds lc3msk_to_irqnr[i] = SGINT_LOCAL3 + 5;
2361da177e4SLinus Torvalds } else if (i & 0x10) {
2371da177e4SLinus Torvalds lc0msk_to_irqnr[i] = SGINT_LOCAL0 + 4;
2381da177e4SLinus Torvalds lc1msk_to_irqnr[i] = SGINT_LOCAL1 + 4;
2391da177e4SLinus Torvalds lc2msk_to_irqnr[i] = SGINT_LOCAL2 + 4;
2401da177e4SLinus Torvalds lc3msk_to_irqnr[i] = SGINT_LOCAL3 + 4;
2411da177e4SLinus Torvalds } else if (i & 0x08) {
2421da177e4SLinus Torvalds lc0msk_to_irqnr[i] = SGINT_LOCAL0 + 3;
2431da177e4SLinus Torvalds lc1msk_to_irqnr[i] = SGINT_LOCAL1 + 3;
2441da177e4SLinus Torvalds lc2msk_to_irqnr[i] = SGINT_LOCAL2 + 3;
2451da177e4SLinus Torvalds lc3msk_to_irqnr[i] = SGINT_LOCAL3 + 3;
2461da177e4SLinus Torvalds } else if (i & 0x04) {
2471da177e4SLinus Torvalds lc0msk_to_irqnr[i] = SGINT_LOCAL0 + 2;
2481da177e4SLinus Torvalds lc1msk_to_irqnr[i] = SGINT_LOCAL1 + 2;
2491da177e4SLinus Torvalds lc2msk_to_irqnr[i] = SGINT_LOCAL2 + 2;
2501da177e4SLinus Torvalds lc3msk_to_irqnr[i] = SGINT_LOCAL3 + 2;
2511da177e4SLinus Torvalds } else if (i & 0x02) {
2521da177e4SLinus Torvalds lc0msk_to_irqnr[i] = SGINT_LOCAL0 + 1;
2531da177e4SLinus Torvalds lc1msk_to_irqnr[i] = SGINT_LOCAL1 + 1;
2541da177e4SLinus Torvalds lc2msk_to_irqnr[i] = SGINT_LOCAL2 + 1;
2551da177e4SLinus Torvalds lc3msk_to_irqnr[i] = SGINT_LOCAL3 + 1;
2561da177e4SLinus Torvalds } else if (i & 0x01) {
2571da177e4SLinus Torvalds lc0msk_to_irqnr[i] = SGINT_LOCAL0 + 0;
2581da177e4SLinus Torvalds lc1msk_to_irqnr[i] = SGINT_LOCAL1 + 0;
2591da177e4SLinus Torvalds lc2msk_to_irqnr[i] = SGINT_LOCAL2 + 0;
2601da177e4SLinus Torvalds lc3msk_to_irqnr[i] = SGINT_LOCAL3 + 0;
2611da177e4SLinus Torvalds } else {
2621da177e4SLinus Torvalds lc0msk_to_irqnr[i] = 0;
2631da177e4SLinus Torvalds lc1msk_to_irqnr[i] = 0;
2641da177e4SLinus Torvalds lc2msk_to_irqnr[i] = 0;
2651da177e4SLinus Torvalds lc3msk_to_irqnr[i] = 0;
2661da177e4SLinus Torvalds }
2671da177e4SLinus Torvalds }
2681da177e4SLinus Torvalds
2691da177e4SLinus Torvalds /* Mask out all interrupts. */
2701da177e4SLinus Torvalds sgint->imask0 = 0;
2711da177e4SLinus Torvalds sgint->imask1 = 0;
2721da177e4SLinus Torvalds sgint->cmeimask0 = 0;
2731da177e4SLinus Torvalds sgint->cmeimask1 = 0;
2741da177e4SLinus Torvalds
2751da177e4SLinus Torvalds /* init CPU irqs */
27697dcb82dSAtsushi Nemoto mips_cpu_irq_init();
2771da177e4SLinus Torvalds
2781da177e4SLinus Torvalds for (i = SGINT_LOCAL0; i < SGI_INTERRUPTS; i++) {
27994dee171SRalf Baechle struct irq_chip *handler;
2801da177e4SLinus Torvalds
2811da177e4SLinus Torvalds if (i < SGINT_LOCAL1)
2821da177e4SLinus Torvalds handler = &ip22_local0_irq_type;
2831da177e4SLinus Torvalds else if (i < SGINT_LOCAL2)
2841da177e4SLinus Torvalds handler = &ip22_local1_irq_type;
2851da177e4SLinus Torvalds else if (i < SGINT_LOCAL3)
2861da177e4SLinus Torvalds handler = &ip22_local2_irq_type;
2871da177e4SLinus Torvalds else
2881da177e4SLinus Torvalds handler = &ip22_local3_irq_type;
2891da177e4SLinus Torvalds
290e4ec7989SThomas Gleixner irq_set_chip_and_handler(i, handler, handle_level_irq);
2911da177e4SLinus Torvalds }
2921da177e4SLinus Torvalds
2931da177e4SLinus Torvalds /* vector handler. this register the IRQ as non-sharable */
294*ac8fd122Safzal mohammed if (request_irq(SGI_LOCAL_0_IRQ, no_action, IRQF_NO_THREAD,
295*ac8fd122Safzal mohammed "local0 cascade", NULL))
296*ac8fd122Safzal mohammed pr_err("Failed to register local0 cascade interrupt\n");
297*ac8fd122Safzal mohammed if (request_irq(SGI_LOCAL_1_IRQ, no_action, IRQF_NO_THREAD,
298*ac8fd122Safzal mohammed "local1 cascade", NULL))
299*ac8fd122Safzal mohammed pr_err("Failed to register local1 cascade interrupt\n");
300*ac8fd122Safzal mohammed if (request_irq(SGI_BUSERR_IRQ, no_action, IRQF_NO_THREAD,
301*ac8fd122Safzal mohammed "Bus Error", NULL))
302*ac8fd122Safzal mohammed pr_err("Failed to register Bus Error interrupt\n");
3031da177e4SLinus Torvalds
3041da177e4SLinus Torvalds /* cascade in cascade. i love Indy ;-) */
305*ac8fd122Safzal mohammed if (request_irq(SGI_MAP_0_IRQ, no_action, IRQF_NO_THREAD,
306*ac8fd122Safzal mohammed "mapable0 cascade", NULL))
307*ac8fd122Safzal mohammed pr_err("Failed to register mapable0 cascade interrupt\n");
3081da177e4SLinus Torvalds #ifdef USE_LIO3_IRQ
309*ac8fd122Safzal mohammed if (request_irq(SGI_MAP_1_IRQ, no_action, IRQF_NO_THREAD,
310*ac8fd122Safzal mohammed "mapable1 cascade", NULL))
311*ac8fd122Safzal mohammed pr_err("Failed to register mapable1 cascade interrupt\n");
3121da177e4SLinus Torvalds #endif
3131da177e4SLinus Torvalds
3141da177e4SLinus Torvalds #ifdef CONFIG_EISA
3151da177e4SLinus Torvalds if (ip22_is_fullhouse()) /* Only Indigo-2 has EISA stuff */
3161da177e4SLinus Torvalds ip22_eisa_init();
3171da177e4SLinus Torvalds #endif
3181da177e4SLinus Torvalds }
319