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 * Levels 3-6 vary by machine type. For VIA or RBV Macintoshes: 301da177e4SLinus Torvalds * 311da177e4SLinus Torvalds * 3 - unused (?) 321da177e4SLinus Torvalds * 3380614e5aSFinn Thain * 4 - SCC 341da177e4SLinus Torvalds * 351da177e4SLinus Torvalds * 5 - unused (?) 361da177e4SLinus Torvalds * [serial errors or special conditions seem to raise level 6 371da177e4SLinus Torvalds * interrupts on some models (LC4xx?)] 381da177e4SLinus Torvalds * 391da177e4SLinus Torvalds * 6 - off switch (?) 401da177e4SLinus Torvalds * 418d9f014aSFinn Thain * Machines with Quadra-like VIA hardware, except PSC and PMU machines, support 428d9f014aSFinn Thain * an alternate interrupt mapping, as used by A/UX. It spreads ethernet and 438d9f014aSFinn Thain * sound out to their own autovector IRQs and gives VIA1 a higher priority: 448d9f014aSFinn Thain * 458d9f014aSFinn Thain * 1 - unused (?) 468d9f014aSFinn Thain * 478d9f014aSFinn Thain * 3 - on-board SONIC 488d9f014aSFinn Thain * 498d9f014aSFinn Thain * 5 - Apple Sound Chip (ASC) 508d9f014aSFinn Thain * 518d9f014aSFinn Thain * 6 - VIA1 528d9f014aSFinn Thain * 53da3fb3c9SFinn Thain * For OSS Macintoshes (IIfx only), we apply an interrupt mapping similar to 54da3fb3c9SFinn Thain * the Quadra (A/UX) mapping: 551da177e4SLinus Torvalds * 56da3fb3c9SFinn Thain * 1 - ISM IOP (ADB) 57da3fb3c9SFinn Thain * 58da3fb3c9SFinn Thain * 2 - SCSI 59da3fb3c9SFinn Thain * 60da3fb3c9SFinn Thain * 3 - NuBus 611da177e4SLinus Torvalds * 621da177e4SLinus Torvalds * 4 - SCC IOP 631da177e4SLinus Torvalds * 64da3fb3c9SFinn Thain * 6 - VIA1 651da177e4SLinus Torvalds * 661da177e4SLinus Torvalds * For PSC Macintoshes (660AV, 840AV): 671da177e4SLinus Torvalds * 681da177e4SLinus Torvalds * 3 - PSC level 3 691da177e4SLinus Torvalds * - slot 0: MACE 701da177e4SLinus Torvalds * 711da177e4SLinus Torvalds * 4 - PSC level 4 721da177e4SLinus Torvalds * - slot 1: SCC channel A interrupt 731da177e4SLinus Torvalds * - slot 2: SCC channel B interrupt 741da177e4SLinus Torvalds * - slot 3: MACE DMA 751da177e4SLinus Torvalds * 761da177e4SLinus Torvalds * 5 - PSC level 5 771da177e4SLinus Torvalds * 781da177e4SLinus Torvalds * 6 - PSC level 6 791da177e4SLinus Torvalds * 801da177e4SLinus Torvalds * Finally we have good 'ole level 7, the non-maskable interrupt: 811da177e4SLinus Torvalds * 821da177e4SLinus Torvalds * 7 - NMI (programmer's switch on the back of some Macs) 831da177e4SLinus Torvalds * Also RAM parity error on models which support it (IIc, IIfx?) 841da177e4SLinus Torvalds * 851da177e4SLinus Torvalds * The current interrupt logic looks something like this: 861da177e4SLinus Torvalds * 871da177e4SLinus Torvalds * - We install dispatchers for the autovector interrupts (1-7). These 881da177e4SLinus Torvalds * dispatchers are responsible for querying the hardware (the 891da177e4SLinus Torvalds * VIA/RBV/OSS/PSC chips) to determine the actual interrupt source. Using 901da177e4SLinus Torvalds * this information a machspec interrupt number is generated by placing the 911da177e4SLinus Torvalds * index of the interrupt hardware into the low three bits and the original 921da177e4SLinus Torvalds * autovector interrupt number in the upper 5 bits. The handlers for the 931da177e4SLinus Torvalds * resulting machspec interrupt are then called. 941da177e4SLinus Torvalds * 951da177e4SLinus Torvalds * - Nubus is a special case because its interrupts are hidden behind two 961da177e4SLinus Torvalds * layers of hardware. Nubus interrupts come in as index 1 on VIA #2, 971da177e4SLinus Torvalds * which translates to IRQ number 17. In this spot we install _another_ 981da177e4SLinus Torvalds * dispatcher. This dispatcher finds the interrupting slot number (9-F) and 991da177e4SLinus Torvalds * then forms a new machspec interrupt number as above with the slot number 1001da177e4SLinus Torvalds * minus 9 in the low three bits and the pseudo-level 7 in the upper five 1011da177e4SLinus Torvalds * bits. The handlers for this new machspec interrupt number are then 1021da177e4SLinus Torvalds * called. This puts Nubus interrupts into the range 56-62. 1031da177e4SLinus Torvalds * 1041da177e4SLinus Torvalds * - The Baboon interrupts (used on some PowerBooks) are an even more special 1051da177e4SLinus Torvalds * case. They're hidden behind the Nubus slot $C interrupt thus adding a 1061da177e4SLinus Torvalds * third layer of indirection. Why oh why did the Apple engineers do that? 1071da177e4SLinus Torvalds * 1081da177e4SLinus Torvalds */ 1091da177e4SLinus Torvalds 1101da177e4SLinus Torvalds #include <linux/types.h> 1111da177e4SLinus Torvalds #include <linux/kernel.h> 1121da177e4SLinus Torvalds #include <linux/sched.h> 113ed04c97dSFinn Thain #include <linux/interrupt.h> 114ed04c97dSFinn Thain #include <linux/irq.h> 1151da177e4SLinus Torvalds #include <linux/delay.h> 1161da177e4SLinus Torvalds 1171da177e4SLinus Torvalds #include <asm/irq.h> 1181da177e4SLinus Torvalds #include <asm/macintosh.h> 119ed04c97dSFinn Thain #include <asm/macints.h> 1201da177e4SLinus Torvalds #include <asm/mac_via.h> 1211da177e4SLinus Torvalds #include <asm/mac_psc.h> 122c85627fbSGeert Uytterhoeven #include <asm/mac_oss.h> 123ed04c97dSFinn Thain #include <asm/mac_iop.h> 124ed04c97dSFinn Thain #include <asm/mac_baboon.h> 125ed04c97dSFinn Thain #include <asm/hwtest.h> 126ed04c97dSFinn Thain #include <asm/irq_regs.h> 1271da177e4SLinus Torvalds 1281da177e4SLinus Torvalds #define SHUTUP_SONIC 1291da177e4SLinus Torvalds 1301da177e4SLinus Torvalds /* 1311da177e4SLinus Torvalds * console_loglevel determines NMI handler function 1321da177e4SLinus Torvalds */ 1331da177e4SLinus Torvalds 1342850bc27SAl Viro irqreturn_t mac_nmi_handler(int, void *); 1352850bc27SAl Viro irqreturn_t mac_debug_handler(int, void *); 1361da177e4SLinus Torvalds 1371da177e4SLinus Torvalds /* #define DEBUG_MACINTS */ 1381da177e4SLinus Torvalds 139c4af5da7SFinn Thain static unsigned int mac_irq_startup(struct irq_data *); 140c4af5da7SFinn Thain static void mac_irq_shutdown(struct irq_data *); 141c4af5da7SFinn Thain 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, 146c4af5da7SFinn Thain .irq_startup = mac_irq_startup, 147c4af5da7SFinn Thain .irq_shutdown = mac_irq_shutdown, 1489c5f4afdSRoman Zippel }; 1499c5f4afdSRoman Zippel 15066a3f820SAl Viro void __init mac_init_IRQ(void) 1511da177e4SLinus Torvalds { 1521da177e4SLinus Torvalds #ifdef DEBUG_MACINTS 1531da177e4SLinus Torvalds printk("mac_init_IRQ(): Setting things up...\n"); 1541da177e4SLinus Torvalds #endif 155edb34725SGeert Uytterhoeven m68k_setup_irq_controller(&mac_irq_chip, handle_simple_irq, IRQ_USER, 1569c5f4afdSRoman Zippel NUM_MAC_SOURCES - IRQ_USER); 1571da177e4SLinus Torvalds /* Make sure the SONIC interrupt is cleared or things get ugly */ 1581da177e4SLinus Torvalds #ifdef SHUTUP_SONIC 1591da177e4SLinus Torvalds printk("Killing onboard sonic... "); 1601da177e4SLinus Torvalds /* This address should hopefully be mapped already */ 1611da177e4SLinus Torvalds if (hwreg_present((void*)(0x50f0a000))) { 1621da177e4SLinus Torvalds *(long *)(0x50f0a014) = 0x7fffL; 1631da177e4SLinus Torvalds *(long *)(0x50f0a010) = 0L; 1641da177e4SLinus Torvalds } 1651da177e4SLinus Torvalds printk("Done.\n"); 1661da177e4SLinus Torvalds #endif /* SHUTUP_SONIC */ 1671da177e4SLinus Torvalds 1681da177e4SLinus Torvalds /* 1691da177e4SLinus Torvalds * Now register the handlers for the master IRQ handlers 1701da177e4SLinus Torvalds * at levels 1-7. Most of the work is done elsewhere. 1711da177e4SLinus Torvalds */ 1721da177e4SLinus Torvalds 1739c5f4afdSRoman Zippel if (oss_present) 1741da177e4SLinus Torvalds oss_register_interrupts(); 1759c5f4afdSRoman Zippel else 1761da177e4SLinus Torvalds via_register_interrupts(); 177*70bc53b4SGeert Uytterhoeven if (psc) 1789c5f4afdSRoman Zippel psc_register_interrupts(); 1799c5f4afdSRoman Zippel if (baboon_present) 1809c5f4afdSRoman Zippel baboon_register_interrupts(); 1811da177e4SLinus Torvalds iop_register_interrupts(); 18292c3dd15SGeert Uytterhoeven if (request_irq(IRQ_AUTO_7, mac_nmi_handler, 0, "NMI", 18392c3dd15SGeert Uytterhoeven mac_nmi_handler)) 18492c3dd15SGeert Uytterhoeven pr_err("Couldn't register NMI\n"); 1851da177e4SLinus Torvalds #ifdef DEBUG_MACINTS 1861da177e4SLinus Torvalds printk("mac_init_IRQ(): Done!\n"); 1871da177e4SLinus Torvalds #endif 1881da177e4SLinus Torvalds } 1891da177e4SLinus Torvalds 1901da177e4SLinus Torvalds /* 1912690e214SFinn Thain * mac_irq_enable - enable an interrupt source 1922690e214SFinn Thain * mac_irq_disable - disable an interrupt source 1931da177e4SLinus Torvalds * 1941da177e4SLinus Torvalds * These routines are just dispatchers to the VIA/OSS/PSC routines. 1951da177e4SLinus Torvalds */ 1961da177e4SLinus Torvalds 1972690e214SFinn Thain void mac_irq_enable(struct irq_data *data) 1981da177e4SLinus Torvalds { 1992690e214SFinn Thain int irq = data->irq; 2001da177e4SLinus Torvalds int irq_src = IRQ_SRC(irq); 2011da177e4SLinus Torvalds 2021da177e4SLinus Torvalds switch(irq_src) { 2039c5f4afdSRoman Zippel case 1: 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: 212da3fb3c9SFinn Thain case 4: 2131da177e4SLinus Torvalds case 5: 2149c5f4afdSRoman Zippel case 6: 215*70bc53b4SGeert Uytterhoeven if (psc) 2161da177e4SLinus Torvalds psc_irq_enable(irq); 2179c5f4afdSRoman Zippel else if (oss_present) 2181da177e4SLinus Torvalds oss_irq_enable(irq); 21980614e5aSFinn Thain break; 2209c5f4afdSRoman Zippel case 8: 2219c5f4afdSRoman Zippel if (baboon_present) 2221da177e4SLinus Torvalds baboon_irq_enable(irq); 2231da177e4SLinus Torvalds break; 2241da177e4SLinus Torvalds } 2251da177e4SLinus Torvalds } 2261da177e4SLinus Torvalds 2272690e214SFinn Thain void mac_irq_disable(struct irq_data *data) 2281da177e4SLinus Torvalds { 2292690e214SFinn Thain int irq = data->irq; 2301da177e4SLinus Torvalds int irq_src = IRQ_SRC(irq); 2311da177e4SLinus Torvalds 2321da177e4SLinus Torvalds switch(irq_src) { 2339c5f4afdSRoman Zippel case 1: 2341da177e4SLinus Torvalds case 2: 2359c5f4afdSRoman Zippel case 7: 2369c5f4afdSRoman Zippel if (oss_present) 2371da177e4SLinus Torvalds oss_irq_disable(irq); 2389c5f4afdSRoman Zippel else 2391da177e4SLinus Torvalds via_irq_disable(irq); 2401da177e4SLinus Torvalds break; 2411da177e4SLinus Torvalds case 3: 242da3fb3c9SFinn Thain case 4: 2431da177e4SLinus Torvalds case 5: 2449c5f4afdSRoman Zippel case 6: 245*70bc53b4SGeert Uytterhoeven if (psc) 2461da177e4SLinus Torvalds psc_irq_disable(irq); 2479c5f4afdSRoman Zippel else if (oss_present) 2481da177e4SLinus Torvalds oss_irq_disable(irq); 24980614e5aSFinn Thain break; 2509c5f4afdSRoman Zippel case 8: 2519c5f4afdSRoman Zippel if (baboon_present) 2521da177e4SLinus Torvalds baboon_irq_disable(irq); 2531da177e4SLinus Torvalds break; 2541da177e4SLinus Torvalds } 2551da177e4SLinus Torvalds } 2561da177e4SLinus Torvalds 257c4af5da7SFinn Thain static unsigned int mac_irq_startup(struct irq_data *data) 258c4af5da7SFinn Thain { 259c4af5da7SFinn Thain int irq = data->irq; 260c4af5da7SFinn Thain 261c4af5da7SFinn Thain if (IRQ_SRC(irq) == 7 && !oss_present) 262c4af5da7SFinn Thain via_nubus_irq_startup(irq); 263c4af5da7SFinn Thain else 264c4af5da7SFinn Thain mac_irq_enable(data); 265c4af5da7SFinn Thain 266c4af5da7SFinn Thain return 0; 267c4af5da7SFinn Thain } 268c4af5da7SFinn Thain 269c4af5da7SFinn Thain static void mac_irq_shutdown(struct irq_data *data) 270c4af5da7SFinn Thain { 271c4af5da7SFinn Thain int irq = data->irq; 272c4af5da7SFinn Thain 273c4af5da7SFinn Thain if (IRQ_SRC(irq) == 7 && !oss_present) 274c4af5da7SFinn Thain via_nubus_irq_shutdown(irq); 275c4af5da7SFinn Thain else 276c4af5da7SFinn Thain mac_irq_disable(data); 277c4af5da7SFinn Thain } 278c4af5da7SFinn Thain 2791da177e4SLinus Torvalds static int num_debug[8]; 2801da177e4SLinus Torvalds 2812850bc27SAl Viro irqreturn_t mac_debug_handler(int irq, void *dev_id) 2821da177e4SLinus Torvalds { 2831da177e4SLinus Torvalds if (num_debug[irq] < 10) { 2841da177e4SLinus Torvalds printk("DEBUG: Unexpected IRQ %d\n", irq); 2851da177e4SLinus Torvalds num_debug[irq]++; 2861da177e4SLinus Torvalds } 2871da177e4SLinus Torvalds return IRQ_HANDLED; 2881da177e4SLinus Torvalds } 2891da177e4SLinus Torvalds 2901da177e4SLinus Torvalds static int in_nmi; 2911da177e4SLinus Torvalds static volatile int nmi_hold; 2921da177e4SLinus Torvalds 2932850bc27SAl Viro irqreturn_t mac_nmi_handler(int irq, void *dev_id) 2941da177e4SLinus Torvalds { 2951da177e4SLinus Torvalds int i; 2961da177e4SLinus Torvalds /* 2971da177e4SLinus Torvalds * generate debug output on NMI switch if 'debug' kernel option given 2981da177e4SLinus Torvalds * (only works with Penguin!) 2991da177e4SLinus Torvalds */ 3001da177e4SLinus Torvalds 3011da177e4SLinus Torvalds in_nmi++; 3021da177e4SLinus Torvalds for (i=0; i<100; i++) 3031da177e4SLinus Torvalds udelay(1000); 3041da177e4SLinus Torvalds 3051da177e4SLinus Torvalds if (in_nmi == 1) { 3061da177e4SLinus Torvalds nmi_hold = 1; 3071da177e4SLinus Torvalds printk("... pausing, press NMI to resume ..."); 3081da177e4SLinus Torvalds } else { 3091da177e4SLinus Torvalds printk(" ok!\n"); 3101da177e4SLinus Torvalds nmi_hold = 0; 3111da177e4SLinus Torvalds } 3121da177e4SLinus Torvalds 3131da177e4SLinus Torvalds barrier(); 3141da177e4SLinus Torvalds 3151da177e4SLinus Torvalds while (nmi_hold == 1) 3161da177e4SLinus Torvalds udelay(1000); 3171da177e4SLinus Torvalds 3181da177e4SLinus Torvalds if (console_loglevel >= 8) { 3191da177e4SLinus Torvalds #if 0 3202850bc27SAl Viro struct pt_regs *fp = get_irq_regs(); 3211da177e4SLinus Torvalds show_state(); 3221da177e4SLinus Torvalds printk("PC: %08lx\nSR: %04x SP: %p\n", fp->pc, fp->sr, fp); 3231da177e4SLinus Torvalds printk("d0: %08lx d1: %08lx d2: %08lx d3: %08lx\n", 3241da177e4SLinus Torvalds fp->d0, fp->d1, fp->d2, fp->d3); 3251da177e4SLinus Torvalds printk("d4: %08lx d5: %08lx a0: %08lx a1: %08lx\n", 3261da177e4SLinus Torvalds fp->d4, fp->d5, fp->a0, fp->a1); 3271da177e4SLinus Torvalds 3281da177e4SLinus Torvalds if (STACK_MAGIC != *(unsigned long *)current->kernel_stack_page) 3291da177e4SLinus Torvalds printk("Corrupted stack page\n"); 3301da177e4SLinus Torvalds printk("Process %s (pid: %d, stackpage=%08lx)\n", 3311da177e4SLinus Torvalds current->comm, current->pid, current->kernel_stack_page); 3321da177e4SLinus Torvalds if (intr_count == 1) 3331da177e4SLinus Torvalds dump_stack((struct frame *)fp); 3341da177e4SLinus Torvalds #else 3351da177e4SLinus Torvalds /* printk("NMI "); */ 3361da177e4SLinus Torvalds #endif 3371da177e4SLinus Torvalds } 3381da177e4SLinus Torvalds in_nmi--; 3391da177e4SLinus Torvalds return IRQ_HANDLED; 3401da177e4SLinus Torvalds } 341