11da177e4SLinus Torvalds /* 21da177e4SLinus Torvalds * Macintosh interrupts 31da177e4SLinus Torvalds * 41da177e4SLinus Torvalds * General design: 51da177e4SLinus Torvalds * In contrary to the Amiga and Atari platforms, the Mac hardware seems to 61da177e4SLinus Torvalds * exclusively use the autovector interrupts (the 'generic level0-level7' 71da177e4SLinus Torvalds * interrupts with exception vectors 0x19-0x1f). The following interrupt levels 81da177e4SLinus Torvalds * are used: 91da177e4SLinus Torvalds * 1 - VIA1 101da177e4SLinus Torvalds * - slot 0: one second interrupt (CA2) 111da177e4SLinus Torvalds * - slot 1: VBlank (CA1) 121da177e4SLinus Torvalds * - slot 2: ADB data ready (SR full) 131da177e4SLinus Torvalds * - slot 3: ADB data (CB2) 141da177e4SLinus Torvalds * - slot 4: ADB clock (CB1) 151da177e4SLinus Torvalds * - slot 5: timer 2 161da177e4SLinus Torvalds * - slot 6: timer 1 171da177e4SLinus Torvalds * - slot 7: status of IRQ; signals 'any enabled int.' 181da177e4SLinus Torvalds * 191da177e4SLinus Torvalds * 2 - VIA2 or RBV 201da177e4SLinus Torvalds * - slot 0: SCSI DRQ (CA2) 211da177e4SLinus Torvalds * - slot 1: NUBUS IRQ (CA1) need to read port A to find which 221da177e4SLinus Torvalds * - slot 2: /EXP IRQ (only on IIci) 231da177e4SLinus Torvalds * - slot 3: SCSI IRQ (CB2) 241da177e4SLinus Torvalds * - slot 4: ASC IRQ (CB1) 251da177e4SLinus Torvalds * - slot 5: timer 2 (not on IIci) 261da177e4SLinus Torvalds * - slot 6: timer 1 (not on IIci) 271da177e4SLinus Torvalds * - slot 7: status of IRQ; signals 'any enabled int.' 281da177e4SLinus Torvalds * 291da177e4SLinus Torvalds * 2 - OSS (IIfx only?) 301da177e4SLinus Torvalds * - slot 0: SCSI interrupt 311da177e4SLinus Torvalds * - slot 1: Sound interrupt 321da177e4SLinus Torvalds * 331da177e4SLinus Torvalds * Levels 3-6 vary by machine type. For VIA or RBV Macintoshes: 341da177e4SLinus Torvalds * 351da177e4SLinus Torvalds * 3 - unused (?) 361da177e4SLinus Torvalds * 3780614e5aSFinn Thain * 4 - SCC 381da177e4SLinus Torvalds * 391da177e4SLinus Torvalds * 5 - unused (?) 401da177e4SLinus Torvalds * [serial errors or special conditions seem to raise level 6 411da177e4SLinus Torvalds * interrupts on some models (LC4xx?)] 421da177e4SLinus Torvalds * 431da177e4SLinus Torvalds * 6 - off switch (?) 441da177e4SLinus Torvalds * 451da177e4SLinus Torvalds * For OSS Macintoshes (IIfx only at this point): 461da177e4SLinus Torvalds * 471da177e4SLinus Torvalds * 3 - Nubus interrupt 481da177e4SLinus Torvalds * - slot 0: Slot $9 491da177e4SLinus Torvalds * - slot 1: Slot $A 501da177e4SLinus Torvalds * - slot 2: Slot $B 511da177e4SLinus Torvalds * - slot 3: Slot $C 521da177e4SLinus Torvalds * - slot 4: Slot $D 531da177e4SLinus Torvalds * - slot 5: Slot $E 541da177e4SLinus Torvalds * 551da177e4SLinus Torvalds * 4 - SCC IOP 561da177e4SLinus Torvalds * 571da177e4SLinus Torvalds * 5 - ISM IOP (ADB?) 581da177e4SLinus Torvalds * 591da177e4SLinus Torvalds * 6 - unused 601da177e4SLinus Torvalds * 611da177e4SLinus Torvalds * For PSC Macintoshes (660AV, 840AV): 621da177e4SLinus Torvalds * 631da177e4SLinus Torvalds * 3 - PSC level 3 641da177e4SLinus Torvalds * - slot 0: MACE 651da177e4SLinus Torvalds * 661da177e4SLinus Torvalds * 4 - PSC level 4 671da177e4SLinus Torvalds * - slot 1: SCC channel A interrupt 681da177e4SLinus Torvalds * - slot 2: SCC channel B interrupt 691da177e4SLinus Torvalds * - slot 3: MACE DMA 701da177e4SLinus Torvalds * 711da177e4SLinus Torvalds * 5 - PSC level 5 721da177e4SLinus Torvalds * 731da177e4SLinus Torvalds * 6 - PSC level 6 741da177e4SLinus Torvalds * 751da177e4SLinus Torvalds * Finally we have good 'ole level 7, the non-maskable interrupt: 761da177e4SLinus Torvalds * 771da177e4SLinus Torvalds * 7 - NMI (programmer's switch on the back of some Macs) 781da177e4SLinus Torvalds * Also RAM parity error on models which support it (IIc, IIfx?) 791da177e4SLinus Torvalds * 801da177e4SLinus Torvalds * The current interrupt logic looks something like this: 811da177e4SLinus Torvalds * 821da177e4SLinus Torvalds * - We install dispatchers for the autovector interrupts (1-7). These 831da177e4SLinus Torvalds * dispatchers are responsible for querying the hardware (the 841da177e4SLinus Torvalds * VIA/RBV/OSS/PSC chips) to determine the actual interrupt source. Using 851da177e4SLinus Torvalds * this information a machspec interrupt number is generated by placing the 861da177e4SLinus Torvalds * index of the interrupt hardware into the low three bits and the original 871da177e4SLinus Torvalds * autovector interrupt number in the upper 5 bits. The handlers for the 881da177e4SLinus Torvalds * resulting machspec interrupt are then called. 891da177e4SLinus Torvalds * 901da177e4SLinus Torvalds * - Nubus is a special case because its interrupts are hidden behind two 911da177e4SLinus Torvalds * layers of hardware. Nubus interrupts come in as index 1 on VIA #2, 921da177e4SLinus Torvalds * which translates to IRQ number 17. In this spot we install _another_ 931da177e4SLinus Torvalds * dispatcher. This dispatcher finds the interrupting slot number (9-F) and 941da177e4SLinus Torvalds * then forms a new machspec interrupt number as above with the slot number 951da177e4SLinus Torvalds * minus 9 in the low three bits and the pseudo-level 7 in the upper five 961da177e4SLinus Torvalds * bits. The handlers for this new machspec interrupt number are then 971da177e4SLinus Torvalds * called. This puts Nubus interrupts into the range 56-62. 981da177e4SLinus Torvalds * 991da177e4SLinus Torvalds * - The Baboon interrupts (used on some PowerBooks) are an even more special 1001da177e4SLinus Torvalds * case. They're hidden behind the Nubus slot $C interrupt thus adding a 1011da177e4SLinus Torvalds * third layer of indirection. Why oh why did the Apple engineers do that? 1021da177e4SLinus Torvalds * 1031da177e4SLinus Torvalds * - We support "fast" and "slow" handlers, just like the Amiga port. The 1041da177e4SLinus Torvalds * fast handlers are called first and with all interrupts disabled. They 1051da177e4SLinus Torvalds * are expected to execute quickly (hence the name). The slow handlers are 1061da177e4SLinus Torvalds * called last with interrupts enabled and the interrupt level restored. 1071da177e4SLinus Torvalds * They must therefore be reentrant. 1081da177e4SLinus Torvalds * 1091da177e4SLinus Torvalds * TODO: 1101da177e4SLinus Torvalds * 1111da177e4SLinus Torvalds */ 1121da177e4SLinus Torvalds 1131da177e4SLinus Torvalds #include <linux/types.h> 1141da177e4SLinus Torvalds #include <linux/kernel.h> 1151da177e4SLinus Torvalds #include <linux/sched.h> 116*ed04c97dSFinn Thain #include <linux/interrupt.h> 117*ed04c97dSFinn Thain #include <linux/irq.h> 1181da177e4SLinus Torvalds #include <linux/delay.h> 1191da177e4SLinus Torvalds 1201da177e4SLinus Torvalds #include <asm/irq.h> 1211da177e4SLinus Torvalds #include <asm/macintosh.h> 122*ed04c97dSFinn Thain #include <asm/macints.h> 1231da177e4SLinus Torvalds #include <asm/mac_via.h> 1241da177e4SLinus Torvalds #include <asm/mac_psc.h> 125c85627fbSGeert Uytterhoeven #include <asm/mac_oss.h> 126*ed04c97dSFinn Thain #include <asm/mac_iop.h> 127*ed04c97dSFinn Thain #include <asm/mac_baboon.h> 128*ed04c97dSFinn Thain #include <asm/hwtest.h> 129*ed04c97dSFinn Thain #include <asm/irq_regs.h> 1301da177e4SLinus Torvalds 1311da177e4SLinus Torvalds #define SHUTUP_SONIC 1321da177e4SLinus Torvalds 1331da177e4SLinus Torvalds /* 1341da177e4SLinus Torvalds * console_loglevel determines NMI handler function 1351da177e4SLinus Torvalds */ 1361da177e4SLinus Torvalds 1372850bc27SAl Viro irqreturn_t mac_nmi_handler(int, void *); 1382850bc27SAl Viro irqreturn_t mac_debug_handler(int, void *); 1391da177e4SLinus Torvalds 1401da177e4SLinus Torvalds /* #define DEBUG_MACINTS */ 1411da177e4SLinus Torvalds 142c288bf25SGeert Uytterhoeven static struct irq_chip mac_irq_chip = { 1439c5f4afdSRoman Zippel .name = "mac", 144e8abf5e7SGeert Uytterhoeven .irq_enable = mac_irq_enable, 145e8abf5e7SGeert Uytterhoeven .irq_disable = mac_irq_disable, 1469c5f4afdSRoman Zippel }; 1479c5f4afdSRoman Zippel 14866a3f820SAl Viro void __init mac_init_IRQ(void) 1491da177e4SLinus Torvalds { 1501da177e4SLinus Torvalds #ifdef DEBUG_MACINTS 1511da177e4SLinus Torvalds printk("mac_init_IRQ(): Setting things up...\n"); 1521da177e4SLinus Torvalds #endif 153edb34725SGeert Uytterhoeven m68k_setup_irq_controller(&mac_irq_chip, handle_simple_irq, IRQ_USER, 1549c5f4afdSRoman Zippel NUM_MAC_SOURCES - IRQ_USER); 1551da177e4SLinus Torvalds /* Make sure the SONIC interrupt is cleared or things get ugly */ 1561da177e4SLinus Torvalds #ifdef SHUTUP_SONIC 1571da177e4SLinus Torvalds printk("Killing onboard sonic... "); 1581da177e4SLinus Torvalds /* This address should hopefully be mapped already */ 1591da177e4SLinus Torvalds if (hwreg_present((void*)(0x50f0a000))) { 1601da177e4SLinus Torvalds *(long *)(0x50f0a014) = 0x7fffL; 1611da177e4SLinus Torvalds *(long *)(0x50f0a010) = 0L; 1621da177e4SLinus Torvalds } 1631da177e4SLinus Torvalds printk("Done.\n"); 1641da177e4SLinus Torvalds #endif /* SHUTUP_SONIC */ 1651da177e4SLinus Torvalds 1661da177e4SLinus Torvalds /* 1671da177e4SLinus Torvalds * Now register the handlers for the master IRQ handlers 1681da177e4SLinus Torvalds * at levels 1-7. Most of the work is done elsewhere. 1691da177e4SLinus Torvalds */ 1701da177e4SLinus Torvalds 1719c5f4afdSRoman Zippel if (oss_present) 1721da177e4SLinus Torvalds oss_register_interrupts(); 1739c5f4afdSRoman Zippel else 1741da177e4SLinus Torvalds via_register_interrupts(); 1759c5f4afdSRoman Zippel if (psc_present) 1769c5f4afdSRoman Zippel psc_register_interrupts(); 1779c5f4afdSRoman Zippel if (baboon_present) 1789c5f4afdSRoman Zippel baboon_register_interrupts(); 1791da177e4SLinus Torvalds iop_register_interrupts(); 18092c3dd15SGeert Uytterhoeven if (request_irq(IRQ_AUTO_7, mac_nmi_handler, 0, "NMI", 18192c3dd15SGeert Uytterhoeven mac_nmi_handler)) 18292c3dd15SGeert Uytterhoeven pr_err("Couldn't register NMI\n"); 1831da177e4SLinus Torvalds #ifdef DEBUG_MACINTS 1841da177e4SLinus Torvalds printk("mac_init_IRQ(): Done!\n"); 1851da177e4SLinus Torvalds #endif 1861da177e4SLinus Torvalds } 1871da177e4SLinus Torvalds 1881da177e4SLinus Torvalds /* 1892690e214SFinn Thain * mac_irq_enable - enable an interrupt source 1902690e214SFinn Thain * mac_irq_disable - disable an interrupt source 1911da177e4SLinus Torvalds * 1921da177e4SLinus Torvalds * These routines are just dispatchers to the VIA/OSS/PSC routines. 1931da177e4SLinus Torvalds */ 1941da177e4SLinus Torvalds 1952690e214SFinn Thain void mac_irq_enable(struct irq_data *data) 1961da177e4SLinus Torvalds { 1972690e214SFinn Thain int irq = data->irq; 1981da177e4SLinus Torvalds int irq_src = IRQ_SRC(irq); 1991da177e4SLinus Torvalds 2001da177e4SLinus Torvalds switch(irq_src) { 2019c5f4afdSRoman Zippel case 1: 2021da177e4SLinus Torvalds via_irq_enable(irq); 2039c5f4afdSRoman Zippel break; 2049c5f4afdSRoman Zippel case 2: 2059c5f4afdSRoman Zippel case 7: 2069c5f4afdSRoman Zippel if (oss_present) 2079c5f4afdSRoman Zippel oss_irq_enable(irq); 2089c5f4afdSRoman Zippel else 2099c5f4afdSRoman Zippel via_irq_enable(irq); 2101da177e4SLinus Torvalds break; 2111da177e4SLinus Torvalds case 3: 2121da177e4SLinus Torvalds case 5: 2139c5f4afdSRoman Zippel case 6: 2149c5f4afdSRoman Zippel if (psc_present) 2151da177e4SLinus Torvalds psc_irq_enable(irq); 2169c5f4afdSRoman Zippel else if (oss_present) 2171da177e4SLinus Torvalds oss_irq_enable(irq); 21880614e5aSFinn Thain break; 21980614e5aSFinn Thain case 4: 22080614e5aSFinn Thain if (psc_present) 22180614e5aSFinn Thain psc_irq_enable(irq); 2221da177e4SLinus Torvalds break; 2239c5f4afdSRoman Zippel case 8: 2249c5f4afdSRoman Zippel if (baboon_present) 2251da177e4SLinus Torvalds baboon_irq_enable(irq); 2261da177e4SLinus Torvalds break; 2271da177e4SLinus Torvalds } 2281da177e4SLinus Torvalds } 2291da177e4SLinus Torvalds 2302690e214SFinn Thain void mac_irq_disable(struct irq_data *data) 2311da177e4SLinus Torvalds { 2322690e214SFinn Thain int irq = data->irq; 2331da177e4SLinus Torvalds int irq_src = IRQ_SRC(irq); 2341da177e4SLinus Torvalds 2351da177e4SLinus Torvalds switch(irq_src) { 2369c5f4afdSRoman Zippel case 1: 2379c5f4afdSRoman Zippel via_irq_disable(irq); 2381da177e4SLinus Torvalds break; 2391da177e4SLinus Torvalds case 2: 2409c5f4afdSRoman Zippel case 7: 2419c5f4afdSRoman Zippel if (oss_present) 2421da177e4SLinus Torvalds oss_irq_disable(irq); 2439c5f4afdSRoman Zippel else 2441da177e4SLinus Torvalds via_irq_disable(irq); 2451da177e4SLinus Torvalds break; 2461da177e4SLinus Torvalds case 3: 2471da177e4SLinus Torvalds case 5: 2489c5f4afdSRoman Zippel case 6: 2499c5f4afdSRoman Zippel if (psc_present) 2501da177e4SLinus Torvalds psc_irq_disable(irq); 2519c5f4afdSRoman Zippel else if (oss_present) 2521da177e4SLinus Torvalds oss_irq_disable(irq); 25380614e5aSFinn Thain break; 25480614e5aSFinn Thain case 4: 25580614e5aSFinn Thain if (psc_present) 25680614e5aSFinn Thain psc_irq_disable(irq); 2571da177e4SLinus Torvalds break; 2589c5f4afdSRoman Zippel case 8: 2599c5f4afdSRoman Zippel if (baboon_present) 2601da177e4SLinus Torvalds baboon_irq_disable(irq); 2611da177e4SLinus Torvalds break; 2621da177e4SLinus Torvalds } 2631da177e4SLinus Torvalds } 2641da177e4SLinus Torvalds 2651da177e4SLinus Torvalds static int num_debug[8]; 2661da177e4SLinus Torvalds 2672850bc27SAl Viro irqreturn_t mac_debug_handler(int irq, void *dev_id) 2681da177e4SLinus Torvalds { 2691da177e4SLinus Torvalds if (num_debug[irq] < 10) { 2701da177e4SLinus Torvalds printk("DEBUG: Unexpected IRQ %d\n", irq); 2711da177e4SLinus Torvalds num_debug[irq]++; 2721da177e4SLinus Torvalds } 2731da177e4SLinus Torvalds return IRQ_HANDLED; 2741da177e4SLinus Torvalds } 2751da177e4SLinus Torvalds 2761da177e4SLinus Torvalds static int in_nmi; 2771da177e4SLinus Torvalds static volatile int nmi_hold; 2781da177e4SLinus Torvalds 2792850bc27SAl Viro irqreturn_t mac_nmi_handler(int irq, void *dev_id) 2801da177e4SLinus Torvalds { 2811da177e4SLinus Torvalds int i; 2821da177e4SLinus Torvalds /* 2831da177e4SLinus Torvalds * generate debug output on NMI switch if 'debug' kernel option given 2841da177e4SLinus Torvalds * (only works with Penguin!) 2851da177e4SLinus Torvalds */ 2861da177e4SLinus Torvalds 2871da177e4SLinus Torvalds in_nmi++; 2881da177e4SLinus Torvalds for (i=0; i<100; i++) 2891da177e4SLinus Torvalds udelay(1000); 2901da177e4SLinus Torvalds 2911da177e4SLinus Torvalds if (in_nmi == 1) { 2921da177e4SLinus Torvalds nmi_hold = 1; 2931da177e4SLinus Torvalds printk("... pausing, press NMI to resume ..."); 2941da177e4SLinus Torvalds } else { 2951da177e4SLinus Torvalds printk(" ok!\n"); 2961da177e4SLinus Torvalds nmi_hold = 0; 2971da177e4SLinus Torvalds } 2981da177e4SLinus Torvalds 2991da177e4SLinus Torvalds barrier(); 3001da177e4SLinus Torvalds 3011da177e4SLinus Torvalds while (nmi_hold == 1) 3021da177e4SLinus Torvalds udelay(1000); 3031da177e4SLinus Torvalds 3041da177e4SLinus Torvalds if (console_loglevel >= 8) { 3051da177e4SLinus Torvalds #if 0 3062850bc27SAl Viro struct pt_regs *fp = get_irq_regs(); 3071da177e4SLinus Torvalds show_state(); 3081da177e4SLinus Torvalds printk("PC: %08lx\nSR: %04x SP: %p\n", fp->pc, fp->sr, fp); 3091da177e4SLinus Torvalds printk("d0: %08lx d1: %08lx d2: %08lx d3: %08lx\n", 3101da177e4SLinus Torvalds fp->d0, fp->d1, fp->d2, fp->d3); 3111da177e4SLinus Torvalds printk("d4: %08lx d5: %08lx a0: %08lx a1: %08lx\n", 3121da177e4SLinus Torvalds fp->d4, fp->d5, fp->a0, fp->a1); 3131da177e4SLinus Torvalds 3141da177e4SLinus Torvalds if (STACK_MAGIC != *(unsigned long *)current->kernel_stack_page) 3151da177e4SLinus Torvalds printk("Corrupted stack page\n"); 3161da177e4SLinus Torvalds printk("Process %s (pid: %d, stackpage=%08lx)\n", 3171da177e4SLinus Torvalds current->comm, current->pid, current->kernel_stack_page); 3181da177e4SLinus Torvalds if (intr_count == 1) 3191da177e4SLinus Torvalds dump_stack((struct frame *)fp); 3201da177e4SLinus Torvalds #else 3211da177e4SLinus Torvalds /* printk("NMI "); */ 3221da177e4SLinus Torvalds #endif 3231da177e4SLinus Torvalds } 3241da177e4SLinus Torvalds in_nmi--; 3251da177e4SLinus Torvalds return IRQ_HANDLED; 3261da177e4SLinus Torvalds } 327