1*b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0 21da177e4SLinus Torvalds /* 31da177e4SLinus Torvalds * Macintosh interrupts 41da177e4SLinus Torvalds * 51da177e4SLinus Torvalds * General design: 61da177e4SLinus Torvalds * In contrary to the Amiga and Atari platforms, the Mac hardware seems to 71da177e4SLinus Torvalds * exclusively use the autovector interrupts (the 'generic level0-level7' 81da177e4SLinus Torvalds * interrupts with exception vectors 0x19-0x1f). The following interrupt levels 91da177e4SLinus Torvalds * are used: 101da177e4SLinus Torvalds * 1 - VIA1 111da177e4SLinus Torvalds * - slot 0: one second interrupt (CA2) 121da177e4SLinus Torvalds * - slot 1: VBlank (CA1) 131da177e4SLinus Torvalds * - slot 2: ADB data ready (SR full) 141da177e4SLinus Torvalds * - slot 3: ADB data (CB2) 151da177e4SLinus Torvalds * - slot 4: ADB clock (CB1) 161da177e4SLinus Torvalds * - slot 5: timer 2 171da177e4SLinus Torvalds * - slot 6: timer 1 181da177e4SLinus Torvalds * - slot 7: status of IRQ; signals 'any enabled int.' 191da177e4SLinus Torvalds * 201da177e4SLinus Torvalds * 2 - VIA2 or RBV 211da177e4SLinus Torvalds * - slot 0: SCSI DRQ (CA2) 221da177e4SLinus Torvalds * - slot 1: NUBUS IRQ (CA1) need to read port A to find which 231da177e4SLinus Torvalds * - slot 2: /EXP IRQ (only on IIci) 241da177e4SLinus Torvalds * - slot 3: SCSI IRQ (CB2) 251da177e4SLinus Torvalds * - slot 4: ASC IRQ (CB1) 261da177e4SLinus Torvalds * - slot 5: timer 2 (not on IIci) 271da177e4SLinus Torvalds * - slot 6: timer 1 (not on IIci) 281da177e4SLinus Torvalds * - slot 7: status of IRQ; signals 'any enabled int.' 291da177e4SLinus Torvalds * 301da177e4SLinus Torvalds * Levels 3-6 vary by machine type. For VIA or RBV Macintoshes: 311da177e4SLinus Torvalds * 321da177e4SLinus Torvalds * 3 - unused (?) 331da177e4SLinus Torvalds * 3480614e5aSFinn Thain * 4 - SCC 351da177e4SLinus Torvalds * 361da177e4SLinus Torvalds * 5 - unused (?) 371da177e4SLinus Torvalds * [serial errors or special conditions seem to raise level 6 381da177e4SLinus Torvalds * interrupts on some models (LC4xx?)] 391da177e4SLinus Torvalds * 401da177e4SLinus Torvalds * 6 - off switch (?) 411da177e4SLinus Torvalds * 428d9f014aSFinn Thain * Machines with Quadra-like VIA hardware, except PSC and PMU machines, support 438d9f014aSFinn Thain * an alternate interrupt mapping, as used by A/UX. It spreads ethernet and 448d9f014aSFinn Thain * sound out to their own autovector IRQs and gives VIA1 a higher priority: 458d9f014aSFinn Thain * 468d9f014aSFinn Thain * 1 - unused (?) 478d9f014aSFinn Thain * 488d9f014aSFinn Thain * 3 - on-board SONIC 498d9f014aSFinn Thain * 508d9f014aSFinn Thain * 5 - Apple Sound Chip (ASC) 518d9f014aSFinn Thain * 528d9f014aSFinn Thain * 6 - VIA1 538d9f014aSFinn Thain * 54da3fb3c9SFinn Thain * For OSS Macintoshes (IIfx only), we apply an interrupt mapping similar to 55da3fb3c9SFinn Thain * the Quadra (A/UX) mapping: 561da177e4SLinus Torvalds * 57da3fb3c9SFinn Thain * 1 - ISM IOP (ADB) 58da3fb3c9SFinn Thain * 59da3fb3c9SFinn Thain * 2 - SCSI 60da3fb3c9SFinn Thain * 61da3fb3c9SFinn Thain * 3 - NuBus 621da177e4SLinus Torvalds * 631da177e4SLinus Torvalds * 4 - SCC IOP 641da177e4SLinus Torvalds * 65da3fb3c9SFinn Thain * 6 - VIA1 661da177e4SLinus Torvalds * 671da177e4SLinus Torvalds * For PSC Macintoshes (660AV, 840AV): 681da177e4SLinus Torvalds * 691da177e4SLinus Torvalds * 3 - PSC level 3 701da177e4SLinus Torvalds * - slot 0: MACE 711da177e4SLinus Torvalds * 721da177e4SLinus Torvalds * 4 - PSC level 4 731da177e4SLinus Torvalds * - slot 1: SCC channel A interrupt 741da177e4SLinus Torvalds * - slot 2: SCC channel B interrupt 751da177e4SLinus Torvalds * - slot 3: MACE DMA 761da177e4SLinus Torvalds * 771da177e4SLinus Torvalds * 5 - PSC level 5 781da177e4SLinus Torvalds * 791da177e4SLinus Torvalds * 6 - PSC level 6 801da177e4SLinus Torvalds * 811da177e4SLinus Torvalds * Finally we have good 'ole level 7, the non-maskable interrupt: 821da177e4SLinus Torvalds * 831da177e4SLinus Torvalds * 7 - NMI (programmer's switch on the back of some Macs) 841da177e4SLinus Torvalds * Also RAM parity error on models which support it (IIc, IIfx?) 851da177e4SLinus Torvalds * 861da177e4SLinus Torvalds * The current interrupt logic looks something like this: 871da177e4SLinus Torvalds * 881da177e4SLinus Torvalds * - We install dispatchers for the autovector interrupts (1-7). These 891da177e4SLinus Torvalds * dispatchers are responsible for querying the hardware (the 901da177e4SLinus Torvalds * VIA/RBV/OSS/PSC chips) to determine the actual interrupt source. Using 911da177e4SLinus Torvalds * this information a machspec interrupt number is generated by placing the 921da177e4SLinus Torvalds * index of the interrupt hardware into the low three bits and the original 931da177e4SLinus Torvalds * autovector interrupt number in the upper 5 bits. The handlers for the 941da177e4SLinus Torvalds * resulting machspec interrupt are then called. 951da177e4SLinus Torvalds * 961da177e4SLinus Torvalds * - Nubus is a special case because its interrupts are hidden behind two 971da177e4SLinus Torvalds * layers of hardware. Nubus interrupts come in as index 1 on VIA #2, 981da177e4SLinus Torvalds * which translates to IRQ number 17. In this spot we install _another_ 991da177e4SLinus Torvalds * dispatcher. This dispatcher finds the interrupting slot number (9-F) and 1001da177e4SLinus Torvalds * then forms a new machspec interrupt number as above with the slot number 1011da177e4SLinus Torvalds * minus 9 in the low three bits and the pseudo-level 7 in the upper five 1021da177e4SLinus Torvalds * bits. The handlers for this new machspec interrupt number are then 1031da177e4SLinus Torvalds * called. This puts Nubus interrupts into the range 56-62. 1041da177e4SLinus Torvalds * 1051da177e4SLinus Torvalds * - The Baboon interrupts (used on some PowerBooks) are an even more special 1061da177e4SLinus Torvalds * case. They're hidden behind the Nubus slot $C interrupt thus adding a 1071da177e4SLinus Torvalds * third layer of indirection. Why oh why did the Apple engineers do that? 1081da177e4SLinus Torvalds * 1091da177e4SLinus Torvalds */ 1101da177e4SLinus Torvalds 1111da177e4SLinus Torvalds #include <linux/types.h> 1121da177e4SLinus Torvalds #include <linux/kernel.h> 1131da177e4SLinus Torvalds #include <linux/sched.h> 114b17b0153SIngo Molnar #include <linux/sched/debug.h> 115ed04c97dSFinn Thain #include <linux/interrupt.h> 116ed04c97dSFinn Thain #include <linux/irq.h> 1171da177e4SLinus Torvalds #include <linux/delay.h> 1181da177e4SLinus Torvalds 1191da177e4SLinus Torvalds #include <asm/irq.h> 1201da177e4SLinus Torvalds #include <asm/macintosh.h> 121ed04c97dSFinn Thain #include <asm/macints.h> 1221da177e4SLinus Torvalds #include <asm/mac_via.h> 1231da177e4SLinus Torvalds #include <asm/mac_psc.h> 124c85627fbSGeert Uytterhoeven #include <asm/mac_oss.h> 125ed04c97dSFinn Thain #include <asm/mac_iop.h> 126ed04c97dSFinn Thain #include <asm/mac_baboon.h> 127ed04c97dSFinn Thain #include <asm/hwtest.h> 128ed04c97dSFinn Thain #include <asm/irq_regs.h> 1291da177e4SLinus Torvalds 1303cd53b14SFinn Thain extern void show_registers(struct pt_regs *); 1311da177e4SLinus Torvalds 1322850bc27SAl Viro irqreturn_t mac_nmi_handler(int, void *); 1331da177e4SLinus Torvalds 134c4af5da7SFinn Thain static unsigned int mac_irq_startup(struct irq_data *); 135c4af5da7SFinn Thain static void mac_irq_shutdown(struct irq_data *); 136c4af5da7SFinn Thain 137c288bf25SGeert Uytterhoeven static struct irq_chip mac_irq_chip = { 1389c5f4afdSRoman Zippel .name = "mac", 139e8abf5e7SGeert Uytterhoeven .irq_enable = mac_irq_enable, 140e8abf5e7SGeert Uytterhoeven .irq_disable = mac_irq_disable, 141c4af5da7SFinn Thain .irq_startup = mac_irq_startup, 142c4af5da7SFinn Thain .irq_shutdown = mac_irq_shutdown, 1439c5f4afdSRoman Zippel }; 1449c5f4afdSRoman Zippel 14566a3f820SAl Viro void __init mac_init_IRQ(void) 1461da177e4SLinus Torvalds { 147edb34725SGeert Uytterhoeven m68k_setup_irq_controller(&mac_irq_chip, handle_simple_irq, IRQ_USER, 1489c5f4afdSRoman Zippel NUM_MAC_SOURCES - IRQ_USER); 1491da177e4SLinus Torvalds 1501da177e4SLinus Torvalds /* 1511da177e4SLinus Torvalds * Now register the handlers for the master IRQ handlers 1521da177e4SLinus Torvalds * at levels 1-7. Most of the work is done elsewhere. 1531da177e4SLinus Torvalds */ 1541da177e4SLinus Torvalds 1559c5f4afdSRoman Zippel if (oss_present) 1561da177e4SLinus Torvalds oss_register_interrupts(); 1579c5f4afdSRoman Zippel else 1581da177e4SLinus Torvalds via_register_interrupts(); 15970bc53b4SGeert Uytterhoeven if (psc) 1609c5f4afdSRoman Zippel psc_register_interrupts(); 1619c5f4afdSRoman Zippel if (baboon_present) 1629c5f4afdSRoman Zippel baboon_register_interrupts(); 1631da177e4SLinus Torvalds iop_register_interrupts(); 16492c3dd15SGeert Uytterhoeven if (request_irq(IRQ_AUTO_7, mac_nmi_handler, 0, "NMI", 16592c3dd15SGeert Uytterhoeven mac_nmi_handler)) 16692c3dd15SGeert Uytterhoeven pr_err("Couldn't register NMI\n"); 1671da177e4SLinus Torvalds } 1681da177e4SLinus Torvalds 1691da177e4SLinus Torvalds /* 1702690e214SFinn Thain * mac_irq_enable - enable an interrupt source 1712690e214SFinn Thain * mac_irq_disable - disable an interrupt source 1721da177e4SLinus Torvalds * 1731da177e4SLinus Torvalds * These routines are just dispatchers to the VIA/OSS/PSC routines. 1741da177e4SLinus Torvalds */ 1751da177e4SLinus Torvalds 1762690e214SFinn Thain void mac_irq_enable(struct irq_data *data) 1771da177e4SLinus Torvalds { 1782690e214SFinn Thain int irq = data->irq; 1791da177e4SLinus Torvalds int irq_src = IRQ_SRC(irq); 1801da177e4SLinus Torvalds 1811da177e4SLinus Torvalds switch(irq_src) { 1829c5f4afdSRoman Zippel case 1: 1839c5f4afdSRoman Zippel case 2: 1849c5f4afdSRoman Zippel case 7: 1859c5f4afdSRoman Zippel if (oss_present) 1869c5f4afdSRoman Zippel oss_irq_enable(irq); 1879c5f4afdSRoman Zippel else 1889c5f4afdSRoman Zippel via_irq_enable(irq); 1891da177e4SLinus Torvalds break; 1901da177e4SLinus Torvalds case 3: 191da3fb3c9SFinn Thain case 4: 1921da177e4SLinus Torvalds case 5: 1939c5f4afdSRoman Zippel case 6: 19470bc53b4SGeert Uytterhoeven if (psc) 1951da177e4SLinus Torvalds psc_irq_enable(irq); 1969c5f4afdSRoman Zippel else if (oss_present) 1971da177e4SLinus Torvalds oss_irq_enable(irq); 19880614e5aSFinn Thain break; 1999c5f4afdSRoman Zippel case 8: 2009c5f4afdSRoman Zippel if (baboon_present) 2011da177e4SLinus Torvalds baboon_irq_enable(irq); 2021da177e4SLinus Torvalds break; 2031da177e4SLinus Torvalds } 2041da177e4SLinus Torvalds } 2051da177e4SLinus Torvalds 2062690e214SFinn Thain void mac_irq_disable(struct irq_data *data) 2071da177e4SLinus Torvalds { 2082690e214SFinn Thain int irq = data->irq; 2091da177e4SLinus Torvalds int irq_src = IRQ_SRC(irq); 2101da177e4SLinus Torvalds 2111da177e4SLinus Torvalds switch(irq_src) { 2129c5f4afdSRoman Zippel case 1: 2131da177e4SLinus Torvalds case 2: 2149c5f4afdSRoman Zippel case 7: 2159c5f4afdSRoman Zippel if (oss_present) 2161da177e4SLinus Torvalds oss_irq_disable(irq); 2179c5f4afdSRoman Zippel else 2181da177e4SLinus Torvalds via_irq_disable(irq); 2191da177e4SLinus Torvalds break; 2201da177e4SLinus Torvalds case 3: 221da3fb3c9SFinn Thain case 4: 2221da177e4SLinus Torvalds case 5: 2239c5f4afdSRoman Zippel case 6: 22470bc53b4SGeert Uytterhoeven if (psc) 2251da177e4SLinus Torvalds psc_irq_disable(irq); 2269c5f4afdSRoman Zippel else if (oss_present) 2271da177e4SLinus Torvalds oss_irq_disable(irq); 22880614e5aSFinn Thain break; 2299c5f4afdSRoman Zippel case 8: 2309c5f4afdSRoman Zippel if (baboon_present) 2311da177e4SLinus Torvalds baboon_irq_disable(irq); 2321da177e4SLinus Torvalds break; 2331da177e4SLinus Torvalds } 2341da177e4SLinus Torvalds } 2351da177e4SLinus Torvalds 236c4af5da7SFinn Thain static unsigned int mac_irq_startup(struct irq_data *data) 237c4af5da7SFinn Thain { 238c4af5da7SFinn Thain int irq = data->irq; 239c4af5da7SFinn Thain 240c4af5da7SFinn Thain if (IRQ_SRC(irq) == 7 && !oss_present) 241c4af5da7SFinn Thain via_nubus_irq_startup(irq); 242c4af5da7SFinn Thain else 243c4af5da7SFinn Thain mac_irq_enable(data); 244c4af5da7SFinn Thain 245c4af5da7SFinn Thain return 0; 246c4af5da7SFinn Thain } 247c4af5da7SFinn Thain 248c4af5da7SFinn Thain static void mac_irq_shutdown(struct irq_data *data) 249c4af5da7SFinn Thain { 250c4af5da7SFinn Thain int irq = data->irq; 251c4af5da7SFinn Thain 252c4af5da7SFinn Thain if (IRQ_SRC(irq) == 7 && !oss_present) 253c4af5da7SFinn Thain via_nubus_irq_shutdown(irq); 254c4af5da7SFinn Thain else 255c4af5da7SFinn Thain mac_irq_disable(data); 256c4af5da7SFinn Thain } 257c4af5da7SFinn Thain 2583cd53b14SFinn Thain static volatile int in_nmi; 2591da177e4SLinus Torvalds 2602850bc27SAl Viro irqreturn_t mac_nmi_handler(int irq, void *dev_id) 2611da177e4SLinus Torvalds { 2623cd53b14SFinn Thain if (in_nmi) 2633cd53b14SFinn Thain return IRQ_HANDLED; 2643cd53b14SFinn Thain in_nmi = 1; 2651da177e4SLinus Torvalds 2663cd53b14SFinn Thain pr_info("Non-Maskable Interrupt\n"); 2673cd53b14SFinn Thain show_registers(get_irq_regs()); 2681da177e4SLinus Torvalds 2693cd53b14SFinn Thain in_nmi = 0; 2701da177e4SLinus Torvalds return IRQ_HANDLED; 2711da177e4SLinus Torvalds } 272