11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * ip22-int.c: Routines for generic manipulation of the INT[23] ASIC 31da177e4SLinus Torvalds * found on INDY and Indigo2 workstations. 41da177e4SLinus Torvalds * 51da177e4SLinus Torvalds * Copyright (C) 1996 David S. Miller (dm@engr.sgi.com) 61da177e4SLinus Torvalds * Copyright (C) 1997, 1998 Ralf Baechle (ralf@gnu.org) 71da177e4SLinus Torvalds * Copyright (C) 1999 Andrew R. Baker (andrewb@uab.edu) 81da177e4SLinus Torvalds * - Indigo2 changes 91da177e4SLinus Torvalds * - Interrupt handling fixes 101da177e4SLinus Torvalds * Copyright (C) 2001, 2003 Ladislav Michl (ladis@linux-mips.org) 111da177e4SLinus Torvalds */ 121da177e4SLinus Torvalds #include <linux/types.h> 131da177e4SLinus Torvalds #include <linux/init.h> 141da177e4SLinus Torvalds #include <linux/kernel_stat.h> 151da177e4SLinus Torvalds #include <linux/interrupt.h> 161da177e4SLinus Torvalds 1797dcb82dSAtsushi Nemoto #include <asm/irq_cpu.h> 181da177e4SLinus Torvalds #include <asm/sgi/hpc3.h> 191da177e4SLinus Torvalds #include <asm/sgi/ip22.h> 201da177e4SLinus Torvalds 211da177e4SLinus Torvalds /* So far nothing hangs here */ 221da177e4SLinus Torvalds #undef USE_LIO3_IRQ 231da177e4SLinus Torvalds 241da177e4SLinus Torvalds struct sgint_regs *sgint; 251da177e4SLinus Torvalds 261da177e4SLinus Torvalds static char lc0msk_to_irqnr[256]; 271da177e4SLinus Torvalds static char lc1msk_to_irqnr[256]; 281da177e4SLinus Torvalds static char lc2msk_to_irqnr[256]; 291da177e4SLinus Torvalds static char lc3msk_to_irqnr[256]; 301da177e4SLinus Torvalds 311da177e4SLinus Torvalds extern int ip22_eisa_init(void); 321da177e4SLinus Torvalds 331da177e4SLinus Torvalds static void enable_local0_irq(unsigned int irq) 341da177e4SLinus Torvalds { 351da177e4SLinus Torvalds /* don't allow mappable interrupt to be enabled from setup_irq, 361da177e4SLinus Torvalds * we have our own way to do so */ 371da177e4SLinus Torvalds if (irq != SGI_MAP_0_IRQ) 381da177e4SLinus Torvalds sgint->imask0 |= (1 << (irq - SGINT_LOCAL0)); 391da177e4SLinus Torvalds } 401da177e4SLinus Torvalds 411da177e4SLinus Torvalds static void disable_local0_irq(unsigned int irq) 421da177e4SLinus Torvalds { 431da177e4SLinus Torvalds sgint->imask0 &= ~(1 << (irq - SGINT_LOCAL0)); 441da177e4SLinus Torvalds } 451da177e4SLinus Torvalds 4694dee171SRalf Baechle static struct irq_chip ip22_local0_irq_type = { 4770d21cdeSAtsushi Nemoto .name = "IP22 local 0", 481603b5acSAtsushi Nemoto .ack = disable_local0_irq, 491603b5acSAtsushi Nemoto .mask = disable_local0_irq, 501603b5acSAtsushi Nemoto .mask_ack = disable_local0_irq, 511603b5acSAtsushi Nemoto .unmask = enable_local0_irq, 521da177e4SLinus Torvalds }; 531da177e4SLinus Torvalds 541da177e4SLinus Torvalds static void enable_local1_irq(unsigned int irq) 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 */ 581da177e4SLinus Torvalds if (irq != SGI_MAP_1_IRQ) 591da177e4SLinus Torvalds sgint->imask1 |= (1 << (irq - SGINT_LOCAL1)); 601da177e4SLinus Torvalds } 611da177e4SLinus Torvalds 6214823ccbSDmitri Vorobiev static void disable_local1_irq(unsigned int irq) 631da177e4SLinus Torvalds { 641da177e4SLinus Torvalds sgint->imask1 &= ~(1 << (irq - SGINT_LOCAL1)); 651da177e4SLinus Torvalds } 661da177e4SLinus Torvalds 6794dee171SRalf Baechle static struct irq_chip ip22_local1_irq_type = { 6870d21cdeSAtsushi Nemoto .name = "IP22 local 1", 691603b5acSAtsushi Nemoto .ack = disable_local1_irq, 701603b5acSAtsushi Nemoto .mask = disable_local1_irq, 711603b5acSAtsushi Nemoto .mask_ack = disable_local1_irq, 721603b5acSAtsushi Nemoto .unmask = enable_local1_irq, 731da177e4SLinus Torvalds }; 741da177e4SLinus Torvalds 751da177e4SLinus Torvalds static void enable_local2_irq(unsigned int irq) 761da177e4SLinus Torvalds { 771da177e4SLinus Torvalds sgint->imask0 |= (1 << (SGI_MAP_0_IRQ - SGINT_LOCAL0)); 781da177e4SLinus Torvalds sgint->cmeimask0 |= (1 << (irq - SGINT_LOCAL2)); 791da177e4SLinus Torvalds } 801da177e4SLinus Torvalds 8114823ccbSDmitri Vorobiev static void disable_local2_irq(unsigned int irq) 821da177e4SLinus Torvalds { 831da177e4SLinus Torvalds sgint->cmeimask0 &= ~(1 << (irq - SGINT_LOCAL2)); 841da177e4SLinus Torvalds if (!sgint->cmeimask0) 851da177e4SLinus Torvalds sgint->imask0 &= ~(1 << (SGI_MAP_0_IRQ - SGINT_LOCAL0)); 861da177e4SLinus Torvalds } 871da177e4SLinus Torvalds 8894dee171SRalf Baechle static struct irq_chip ip22_local2_irq_type = { 8970d21cdeSAtsushi Nemoto .name = "IP22 local 2", 901603b5acSAtsushi Nemoto .ack = disable_local2_irq, 911603b5acSAtsushi Nemoto .mask = disable_local2_irq, 921603b5acSAtsushi Nemoto .mask_ack = disable_local2_irq, 931603b5acSAtsushi Nemoto .unmask = enable_local2_irq, 941da177e4SLinus Torvalds }; 951da177e4SLinus Torvalds 961da177e4SLinus Torvalds static void enable_local3_irq(unsigned int irq) 971da177e4SLinus Torvalds { 981da177e4SLinus Torvalds sgint->imask1 |= (1 << (SGI_MAP_1_IRQ - SGINT_LOCAL1)); 991da177e4SLinus Torvalds sgint->cmeimask1 |= (1 << (irq - SGINT_LOCAL3)); 1001da177e4SLinus Torvalds } 1011da177e4SLinus Torvalds 10214823ccbSDmitri Vorobiev static void disable_local3_irq(unsigned int irq) 1031da177e4SLinus Torvalds { 1041da177e4SLinus Torvalds sgint->cmeimask1 &= ~(1 << (irq - SGINT_LOCAL3)); 1051da177e4SLinus Torvalds if (!sgint->cmeimask1) 1061da177e4SLinus Torvalds sgint->imask1 &= ~(1 << (SGI_MAP_1_IRQ - SGINT_LOCAL1)); 1071da177e4SLinus Torvalds } 1081da177e4SLinus Torvalds 10994dee171SRalf Baechle static struct irq_chip ip22_local3_irq_type = { 11070d21cdeSAtsushi Nemoto .name = "IP22 local 3", 1111603b5acSAtsushi Nemoto .ack = disable_local3_irq, 1121603b5acSAtsushi Nemoto .mask = disable_local3_irq, 1131603b5acSAtsushi Nemoto .mask_ack = disable_local3_irq, 1141603b5acSAtsushi Nemoto .unmask = enable_local3_irq, 1151da177e4SLinus Torvalds }; 1161da177e4SLinus Torvalds 117937a8015SRalf Baechle static void indy_local0_irqdispatch(void) 1181da177e4SLinus Torvalds { 1191da177e4SLinus Torvalds u8 mask = sgint->istat0 & sgint->imask0; 1201da177e4SLinus Torvalds u8 mask2; 1211da177e4SLinus Torvalds int irq; 1221da177e4SLinus Torvalds 1231da177e4SLinus Torvalds if (mask & SGINT_ISTAT0_LIO2) { 1241da177e4SLinus Torvalds mask2 = sgint->vmeistat & sgint->cmeimask0; 1251da177e4SLinus Torvalds irq = lc2msk_to_irqnr[mask2]; 1261da177e4SLinus Torvalds } else 1271da177e4SLinus Torvalds irq = lc0msk_to_irqnr[mask]; 1281da177e4SLinus Torvalds 1291da177e4SLinus Torvalds /* if irq == 0, then the interrupt has already been cleared */ 1301da177e4SLinus Torvalds if (irq) 131937a8015SRalf Baechle do_IRQ(irq); 1321da177e4SLinus Torvalds } 1331da177e4SLinus Torvalds 134937a8015SRalf Baechle static void indy_local1_irqdispatch(void) 1351da177e4SLinus Torvalds { 1361da177e4SLinus Torvalds u8 mask = sgint->istat1 & sgint->imask1; 1371da177e4SLinus Torvalds u8 mask2; 1381da177e4SLinus Torvalds int irq; 1391da177e4SLinus Torvalds 1401da177e4SLinus Torvalds if (mask & SGINT_ISTAT1_LIO3) { 1411da177e4SLinus Torvalds mask2 = sgint->vmeistat & sgint->cmeimask1; 1421da177e4SLinus Torvalds irq = lc3msk_to_irqnr[mask2]; 1431da177e4SLinus Torvalds } else 1441da177e4SLinus Torvalds irq = lc1msk_to_irqnr[mask]; 1451da177e4SLinus Torvalds 1461da177e4SLinus Torvalds /* if irq == 0, then the interrupt has already been cleared */ 1471da177e4SLinus Torvalds if (irq) 148937a8015SRalf Baechle do_IRQ(irq); 1491da177e4SLinus Torvalds } 1501da177e4SLinus Torvalds 151937a8015SRalf Baechle extern void ip22_be_interrupt(int irq); 1521da177e4SLinus Torvalds 153937a8015SRalf Baechle static void indy_buserror_irq(void) 1541da177e4SLinus Torvalds { 1551da177e4SLinus Torvalds int irq = SGI_BUSERR_IRQ; 1561da177e4SLinus Torvalds 1571da177e4SLinus Torvalds irq_enter(); 158*d2287f5eSMike Travis kstat_incr_irqs_this_cpu(irq, irq_to_desc(irq)); 159937a8015SRalf Baechle ip22_be_interrupt(irq); 1601da177e4SLinus Torvalds irq_exit(); 1611da177e4SLinus Torvalds } 1621da177e4SLinus Torvalds 1631da177e4SLinus Torvalds static struct irqaction local0_cascade = { 1641da177e4SLinus Torvalds .handler = no_action, 165f40298fdSThomas Gleixner .flags = IRQF_DISABLED, 1661da177e4SLinus Torvalds .name = "local0 cascade", 1671da177e4SLinus Torvalds }; 1681da177e4SLinus Torvalds 1691da177e4SLinus Torvalds static struct irqaction local1_cascade = { 1701da177e4SLinus Torvalds .handler = no_action, 171f40298fdSThomas Gleixner .flags = IRQF_DISABLED, 1721da177e4SLinus Torvalds .name = "local1 cascade", 1731da177e4SLinus Torvalds }; 1741da177e4SLinus Torvalds 1751da177e4SLinus Torvalds static struct irqaction buserr = { 1761da177e4SLinus Torvalds .handler = no_action, 177f40298fdSThomas Gleixner .flags = IRQF_DISABLED, 1781da177e4SLinus Torvalds .name = "Bus Error", 1791da177e4SLinus Torvalds }; 1801da177e4SLinus Torvalds 1811da177e4SLinus Torvalds static struct irqaction map0_cascade = { 1821da177e4SLinus Torvalds .handler = no_action, 183f40298fdSThomas Gleixner .flags = IRQF_DISABLED, 1841da177e4SLinus Torvalds .name = "mapable0 cascade", 1851da177e4SLinus Torvalds }; 1861da177e4SLinus Torvalds 1871da177e4SLinus Torvalds #ifdef USE_LIO3_IRQ 1881da177e4SLinus Torvalds static struct irqaction map1_cascade = { 1891da177e4SLinus Torvalds .handler = no_action, 190f40298fdSThomas Gleixner .flags = IRQF_DISABLED, 1911da177e4SLinus Torvalds .name = "mapable1 cascade", 1921da177e4SLinus Torvalds }; 1931da177e4SLinus Torvalds #define SGI_INTERRUPTS SGINT_END 1941da177e4SLinus Torvalds #else 1951da177e4SLinus Torvalds #define SGI_INTERRUPTS SGINT_LOCAL3 1961da177e4SLinus Torvalds #endif 1971da177e4SLinus Torvalds 198937a8015SRalf Baechle extern void indy_8254timer_irq(void); 199e4ac58afSRalf Baechle 200e4ac58afSRalf Baechle /* 201e4ac58afSRalf Baechle * IRQs on the INDY look basically (barring software IRQs which we don't use 202e4ac58afSRalf Baechle * at all) like: 203e4ac58afSRalf Baechle * 204e4ac58afSRalf Baechle * MIPS IRQ Source 205e4ac58afSRalf Baechle * -------- ------ 206e4ac58afSRalf Baechle * 0 Software (ignored) 207e4ac58afSRalf Baechle * 1 Software (ignored) 208e4ac58afSRalf Baechle * 2 Local IRQ level zero 209e4ac58afSRalf Baechle * 3 Local IRQ level one 210e4ac58afSRalf Baechle * 4 8254 Timer zero 211e4ac58afSRalf Baechle * 5 8254 Timer one 212e4ac58afSRalf Baechle * 6 Bus Error 213e4ac58afSRalf Baechle * 7 R4k timer (what we use) 214e4ac58afSRalf Baechle * 215e4ac58afSRalf Baechle * We handle the IRQ according to _our_ priority which is: 216e4ac58afSRalf Baechle * 217e4ac58afSRalf Baechle * Highest ---- R4k Timer 218e4ac58afSRalf Baechle * Local IRQ zero 219e4ac58afSRalf Baechle * Local IRQ one 220e4ac58afSRalf Baechle * Bus Error 221e4ac58afSRalf Baechle * 8254 Timer zero 222e4ac58afSRalf Baechle * Lowest ---- 8254 Timer one 223e4ac58afSRalf Baechle * 224e4ac58afSRalf Baechle * then we just return, if multiple IRQs are pending then we will just take 225e4ac58afSRalf Baechle * another exception, big deal. 226e4ac58afSRalf Baechle */ 227e4ac58afSRalf Baechle 228937a8015SRalf Baechle asmlinkage void plat_irq_dispatch(void) 229e4ac58afSRalf Baechle { 230119537c0SThiemo Seufer unsigned int pending = read_c0_status() & read_c0_cause(); 231e4ac58afSRalf Baechle 232e4ac58afSRalf Baechle /* 233e4ac58afSRalf Baechle * First we check for r4k counter/timer IRQ. 234e4ac58afSRalf Baechle */ 235e4ac58afSRalf Baechle if (pending & CAUSEF_IP7) 2367bcf7717SRalf Baechle do_IRQ(SGI_TIMER_IRQ); 237e4ac58afSRalf Baechle else if (pending & CAUSEF_IP2) 238937a8015SRalf Baechle indy_local0_irqdispatch(); 239e4ac58afSRalf Baechle else if (pending & CAUSEF_IP3) 240937a8015SRalf Baechle indy_local1_irqdispatch(); 241e4ac58afSRalf Baechle else if (pending & CAUSEF_IP6) 242937a8015SRalf Baechle indy_buserror_irq(); 243e4ac58afSRalf Baechle else if (pending & (CAUSEF_IP4 | CAUSEF_IP5)) 244937a8015SRalf Baechle indy_8254timer_irq(); 245e4ac58afSRalf Baechle } 246e4ac58afSRalf Baechle 2471da177e4SLinus Torvalds void __init arch_init_irq(void) 2481da177e4SLinus Torvalds { 2491da177e4SLinus Torvalds int i; 2501da177e4SLinus Torvalds 2511da177e4SLinus Torvalds /* Init local mask --> irq tables. */ 2521da177e4SLinus Torvalds for (i = 0; i < 256; i++) { 2531da177e4SLinus Torvalds if (i & 0x80) { 2541da177e4SLinus Torvalds lc0msk_to_irqnr[i] = SGINT_LOCAL0 + 7; 2551da177e4SLinus Torvalds lc1msk_to_irqnr[i] = SGINT_LOCAL1 + 7; 2561da177e4SLinus Torvalds lc2msk_to_irqnr[i] = SGINT_LOCAL2 + 7; 2571da177e4SLinus Torvalds lc3msk_to_irqnr[i] = SGINT_LOCAL3 + 7; 2581da177e4SLinus Torvalds } else if (i & 0x40) { 2591da177e4SLinus Torvalds lc0msk_to_irqnr[i] = SGINT_LOCAL0 + 6; 2601da177e4SLinus Torvalds lc1msk_to_irqnr[i] = SGINT_LOCAL1 + 6; 2611da177e4SLinus Torvalds lc2msk_to_irqnr[i] = SGINT_LOCAL2 + 6; 2621da177e4SLinus Torvalds lc3msk_to_irqnr[i] = SGINT_LOCAL3 + 6; 2631da177e4SLinus Torvalds } else if (i & 0x20) { 2641da177e4SLinus Torvalds lc0msk_to_irqnr[i] = SGINT_LOCAL0 + 5; 2651da177e4SLinus Torvalds lc1msk_to_irqnr[i] = SGINT_LOCAL1 + 5; 2661da177e4SLinus Torvalds lc2msk_to_irqnr[i] = SGINT_LOCAL2 + 5; 2671da177e4SLinus Torvalds lc3msk_to_irqnr[i] = SGINT_LOCAL3 + 5; 2681da177e4SLinus Torvalds } else if (i & 0x10) { 2691da177e4SLinus Torvalds lc0msk_to_irqnr[i] = SGINT_LOCAL0 + 4; 2701da177e4SLinus Torvalds lc1msk_to_irqnr[i] = SGINT_LOCAL1 + 4; 2711da177e4SLinus Torvalds lc2msk_to_irqnr[i] = SGINT_LOCAL2 + 4; 2721da177e4SLinus Torvalds lc3msk_to_irqnr[i] = SGINT_LOCAL3 + 4; 2731da177e4SLinus Torvalds } else if (i & 0x08) { 2741da177e4SLinus Torvalds lc0msk_to_irqnr[i] = SGINT_LOCAL0 + 3; 2751da177e4SLinus Torvalds lc1msk_to_irqnr[i] = SGINT_LOCAL1 + 3; 2761da177e4SLinus Torvalds lc2msk_to_irqnr[i] = SGINT_LOCAL2 + 3; 2771da177e4SLinus Torvalds lc3msk_to_irqnr[i] = SGINT_LOCAL3 + 3; 2781da177e4SLinus Torvalds } else if (i & 0x04) { 2791da177e4SLinus Torvalds lc0msk_to_irqnr[i] = SGINT_LOCAL0 + 2; 2801da177e4SLinus Torvalds lc1msk_to_irqnr[i] = SGINT_LOCAL1 + 2; 2811da177e4SLinus Torvalds lc2msk_to_irqnr[i] = SGINT_LOCAL2 + 2; 2821da177e4SLinus Torvalds lc3msk_to_irqnr[i] = SGINT_LOCAL3 + 2; 2831da177e4SLinus Torvalds } else if (i & 0x02) { 2841da177e4SLinus Torvalds lc0msk_to_irqnr[i] = SGINT_LOCAL0 + 1; 2851da177e4SLinus Torvalds lc1msk_to_irqnr[i] = SGINT_LOCAL1 + 1; 2861da177e4SLinus Torvalds lc2msk_to_irqnr[i] = SGINT_LOCAL2 + 1; 2871da177e4SLinus Torvalds lc3msk_to_irqnr[i] = SGINT_LOCAL3 + 1; 2881da177e4SLinus Torvalds } else if (i & 0x01) { 2891da177e4SLinus Torvalds lc0msk_to_irqnr[i] = SGINT_LOCAL0 + 0; 2901da177e4SLinus Torvalds lc1msk_to_irqnr[i] = SGINT_LOCAL1 + 0; 2911da177e4SLinus Torvalds lc2msk_to_irqnr[i] = SGINT_LOCAL2 + 0; 2921da177e4SLinus Torvalds lc3msk_to_irqnr[i] = SGINT_LOCAL3 + 0; 2931da177e4SLinus Torvalds } else { 2941da177e4SLinus Torvalds lc0msk_to_irqnr[i] = 0; 2951da177e4SLinus Torvalds lc1msk_to_irqnr[i] = 0; 2961da177e4SLinus Torvalds lc2msk_to_irqnr[i] = 0; 2971da177e4SLinus Torvalds lc3msk_to_irqnr[i] = 0; 2981da177e4SLinus Torvalds } 2991da177e4SLinus Torvalds } 3001da177e4SLinus Torvalds 3011da177e4SLinus Torvalds /* Mask out all interrupts. */ 3021da177e4SLinus Torvalds sgint->imask0 = 0; 3031da177e4SLinus Torvalds sgint->imask1 = 0; 3041da177e4SLinus Torvalds sgint->cmeimask0 = 0; 3051da177e4SLinus Torvalds sgint->cmeimask1 = 0; 3061da177e4SLinus Torvalds 3071da177e4SLinus Torvalds /* init CPU irqs */ 30897dcb82dSAtsushi Nemoto mips_cpu_irq_init(); 3091da177e4SLinus Torvalds 3101da177e4SLinus Torvalds for (i = SGINT_LOCAL0; i < SGI_INTERRUPTS; i++) { 31194dee171SRalf Baechle struct irq_chip *handler; 3121da177e4SLinus Torvalds 3131da177e4SLinus Torvalds if (i < SGINT_LOCAL1) 3141da177e4SLinus Torvalds handler = &ip22_local0_irq_type; 3151da177e4SLinus Torvalds else if (i < SGINT_LOCAL2) 3161da177e4SLinus Torvalds handler = &ip22_local1_irq_type; 3171da177e4SLinus Torvalds else if (i < SGINT_LOCAL3) 3181da177e4SLinus Torvalds handler = &ip22_local2_irq_type; 3191da177e4SLinus Torvalds else 3201da177e4SLinus Torvalds handler = &ip22_local3_irq_type; 3211da177e4SLinus Torvalds 3221417836eSAtsushi Nemoto set_irq_chip_and_handler(i, handler, handle_level_irq); 3231da177e4SLinus Torvalds } 3241da177e4SLinus Torvalds 3251da177e4SLinus Torvalds /* vector handler. this register the IRQ as non-sharable */ 3261da177e4SLinus Torvalds setup_irq(SGI_LOCAL_0_IRQ, &local0_cascade); 3271da177e4SLinus Torvalds setup_irq(SGI_LOCAL_1_IRQ, &local1_cascade); 3281da177e4SLinus Torvalds setup_irq(SGI_BUSERR_IRQ, &buserr); 3291da177e4SLinus Torvalds 3301da177e4SLinus Torvalds /* cascade in cascade. i love Indy ;-) */ 3311da177e4SLinus Torvalds setup_irq(SGI_MAP_0_IRQ, &map0_cascade); 3321da177e4SLinus Torvalds #ifdef USE_LIO3_IRQ 3331da177e4SLinus Torvalds setup_irq(SGI_MAP_1_IRQ, &map1_cascade); 3341da177e4SLinus Torvalds #endif 3351da177e4SLinus Torvalds 3361da177e4SLinus Torvalds #ifdef CONFIG_EISA 3371da177e4SLinus Torvalds if (ip22_is_fullhouse()) /* Only Indigo-2 has EISA stuff */ 3381da177e4SLinus Torvalds ip22_eisa_init(); 3391da177e4SLinus Torvalds #endif 3401da177e4SLinus Torvalds } 341