xref: /linux/arch/m68k/mac/macints.c (revision 8d9f014ad16711d79c8a575f2d3d009d2a16c7b7)
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  *
45*8d9f014aSFinn Thain  * Machines with Quadra-like VIA hardware, except PSC and PMU machines, support
46*8d9f014aSFinn Thain  * an alternate interrupt mapping, as used by A/UX. It spreads ethernet and
47*8d9f014aSFinn Thain  * sound out to their own autovector IRQs and gives VIA1 a higher priority:
48*8d9f014aSFinn Thain  *
49*8d9f014aSFinn Thain  *	1	- unused (?)
50*8d9f014aSFinn Thain  *
51*8d9f014aSFinn Thain  *	3	- on-board SONIC
52*8d9f014aSFinn Thain  *
53*8d9f014aSFinn Thain  *	5	- Apple Sound Chip (ASC)
54*8d9f014aSFinn Thain  *
55*8d9f014aSFinn Thain  *	6	- VIA1
56*8d9f014aSFinn Thain  *
571da177e4SLinus Torvalds  * For OSS Macintoshes (IIfx only at this point):
581da177e4SLinus Torvalds  *
591da177e4SLinus Torvalds  *	3	- Nubus interrupt
601da177e4SLinus Torvalds  *		  - slot 0: Slot $9
611da177e4SLinus Torvalds  *		  - slot 1: Slot $A
621da177e4SLinus Torvalds  *		  - slot 2: Slot $B
631da177e4SLinus Torvalds  *		  - slot 3: Slot $C
641da177e4SLinus Torvalds  *		  - slot 4: Slot $D
651da177e4SLinus Torvalds  *		  - slot 5: Slot $E
661da177e4SLinus Torvalds  *
671da177e4SLinus Torvalds  *	4	- SCC IOP
681da177e4SLinus Torvalds  *
691da177e4SLinus Torvalds  *	5	- ISM IOP (ADB?)
701da177e4SLinus Torvalds  *
711da177e4SLinus Torvalds  *	6	- unused
721da177e4SLinus Torvalds  *
731da177e4SLinus Torvalds  * For PSC Macintoshes (660AV, 840AV):
741da177e4SLinus Torvalds  *
751da177e4SLinus Torvalds  *	3	- PSC level 3
761da177e4SLinus Torvalds  *		  - slot 0: MACE
771da177e4SLinus Torvalds  *
781da177e4SLinus Torvalds  *	4	- PSC level 4
791da177e4SLinus Torvalds  *		  - slot 1: SCC channel A interrupt
801da177e4SLinus Torvalds  *		  - slot 2: SCC channel B interrupt
811da177e4SLinus Torvalds  *		  - slot 3: MACE DMA
821da177e4SLinus Torvalds  *
831da177e4SLinus Torvalds  *	5	- PSC level 5
841da177e4SLinus Torvalds  *
851da177e4SLinus Torvalds  *	6	- PSC level 6
861da177e4SLinus Torvalds  *
871da177e4SLinus Torvalds  * Finally we have good 'ole level 7, the non-maskable interrupt:
881da177e4SLinus Torvalds  *
891da177e4SLinus Torvalds  *	7	- NMI (programmer's switch on the back of some Macs)
901da177e4SLinus Torvalds  *		  Also RAM parity error on models which support it (IIc, IIfx?)
911da177e4SLinus Torvalds  *
921da177e4SLinus Torvalds  * The current interrupt logic looks something like this:
931da177e4SLinus Torvalds  *
941da177e4SLinus Torvalds  * - We install dispatchers for the autovector interrupts (1-7). These
951da177e4SLinus Torvalds  *   dispatchers are responsible for querying the hardware (the
961da177e4SLinus Torvalds  *   VIA/RBV/OSS/PSC chips) to determine the actual interrupt source. Using
971da177e4SLinus Torvalds  *   this information a machspec interrupt number is generated by placing the
981da177e4SLinus Torvalds  *   index of the interrupt hardware into the low three bits and the original
991da177e4SLinus Torvalds  *   autovector interrupt number in the upper 5 bits. The handlers for the
1001da177e4SLinus Torvalds  *   resulting machspec interrupt are then called.
1011da177e4SLinus Torvalds  *
1021da177e4SLinus Torvalds  * - Nubus is a special case because its interrupts are hidden behind two
1031da177e4SLinus Torvalds  *   layers of hardware. Nubus interrupts come in as index 1 on VIA #2,
1041da177e4SLinus Torvalds  *   which translates to IRQ number 17. In this spot we install _another_
1051da177e4SLinus Torvalds  *   dispatcher. This dispatcher finds the interrupting slot number (9-F) and
1061da177e4SLinus Torvalds  *   then forms a new machspec interrupt number as above with the slot number
1071da177e4SLinus Torvalds  *   minus 9 in the low three bits and the pseudo-level 7 in the upper five
1081da177e4SLinus Torvalds  *   bits.  The handlers for this new machspec interrupt number are then
1091da177e4SLinus Torvalds  *   called. This puts Nubus interrupts into the range 56-62.
1101da177e4SLinus Torvalds  *
1111da177e4SLinus Torvalds  * - The Baboon interrupts (used on some PowerBooks) are an even more special
1121da177e4SLinus Torvalds  *   case. They're hidden behind the Nubus slot $C interrupt thus adding a
1131da177e4SLinus Torvalds  *   third layer of indirection. Why oh why did the Apple engineers do that?
1141da177e4SLinus Torvalds  *
1151da177e4SLinus Torvalds  * - We support "fast" and "slow" handlers, just like the Amiga port. The
1161da177e4SLinus Torvalds  *   fast handlers are called first and with all interrupts disabled. They
1171da177e4SLinus Torvalds  *   are expected to execute quickly (hence the name). The slow handlers are
1181da177e4SLinus Torvalds  *   called last with interrupts enabled and the interrupt level restored.
1191da177e4SLinus Torvalds  *   They must therefore be reentrant.
1201da177e4SLinus Torvalds  *
1211da177e4SLinus Torvalds  *   TODO:
1221da177e4SLinus Torvalds  *
1231da177e4SLinus Torvalds  */
1241da177e4SLinus Torvalds 
1251da177e4SLinus Torvalds #include <linux/types.h>
1261da177e4SLinus Torvalds #include <linux/kernel.h>
1271da177e4SLinus Torvalds #include <linux/sched.h>
128ed04c97dSFinn Thain #include <linux/interrupt.h>
129ed04c97dSFinn Thain #include <linux/irq.h>
1301da177e4SLinus Torvalds #include <linux/delay.h>
1311da177e4SLinus Torvalds 
1321da177e4SLinus Torvalds #include <asm/irq.h>
1331da177e4SLinus Torvalds #include <asm/macintosh.h>
134ed04c97dSFinn Thain #include <asm/macints.h>
1351da177e4SLinus Torvalds #include <asm/mac_via.h>
1361da177e4SLinus Torvalds #include <asm/mac_psc.h>
137c85627fbSGeert Uytterhoeven #include <asm/mac_oss.h>
138ed04c97dSFinn Thain #include <asm/mac_iop.h>
139ed04c97dSFinn Thain #include <asm/mac_baboon.h>
140ed04c97dSFinn Thain #include <asm/hwtest.h>
141ed04c97dSFinn Thain #include <asm/irq_regs.h>
1421da177e4SLinus Torvalds 
1431da177e4SLinus Torvalds #define SHUTUP_SONIC
1441da177e4SLinus Torvalds 
1451da177e4SLinus Torvalds /*
1461da177e4SLinus Torvalds  * console_loglevel determines NMI handler function
1471da177e4SLinus Torvalds  */
1481da177e4SLinus Torvalds 
1492850bc27SAl Viro irqreturn_t mac_nmi_handler(int, void *);
1502850bc27SAl Viro irqreturn_t mac_debug_handler(int, void *);
1511da177e4SLinus Torvalds 
1521da177e4SLinus Torvalds /* #define DEBUG_MACINTS */
1531da177e4SLinus Torvalds 
154c288bf25SGeert Uytterhoeven static struct irq_chip mac_irq_chip = {
1559c5f4afdSRoman Zippel 	.name		= "mac",
156e8abf5e7SGeert Uytterhoeven 	.irq_enable	= mac_irq_enable,
157e8abf5e7SGeert Uytterhoeven 	.irq_disable	= mac_irq_disable,
1589c5f4afdSRoman Zippel };
1599c5f4afdSRoman Zippel 
16066a3f820SAl Viro void __init mac_init_IRQ(void)
1611da177e4SLinus Torvalds {
1621da177e4SLinus Torvalds #ifdef DEBUG_MACINTS
1631da177e4SLinus Torvalds 	printk("mac_init_IRQ(): Setting things up...\n");
1641da177e4SLinus Torvalds #endif
165edb34725SGeert Uytterhoeven 	m68k_setup_irq_controller(&mac_irq_chip, handle_simple_irq, IRQ_USER,
1669c5f4afdSRoman Zippel 				  NUM_MAC_SOURCES - IRQ_USER);
1671da177e4SLinus Torvalds 	/* Make sure the SONIC interrupt is cleared or things get ugly */
1681da177e4SLinus Torvalds #ifdef SHUTUP_SONIC
1691da177e4SLinus Torvalds 	printk("Killing onboard sonic... ");
1701da177e4SLinus Torvalds 	/* This address should hopefully be mapped already */
1711da177e4SLinus Torvalds 	if (hwreg_present((void*)(0x50f0a000))) {
1721da177e4SLinus Torvalds 		*(long *)(0x50f0a014) = 0x7fffL;
1731da177e4SLinus Torvalds 		*(long *)(0x50f0a010) = 0L;
1741da177e4SLinus Torvalds 	}
1751da177e4SLinus Torvalds 	printk("Done.\n");
1761da177e4SLinus Torvalds #endif /* SHUTUP_SONIC */
1771da177e4SLinus Torvalds 
1781da177e4SLinus Torvalds 	/*
1791da177e4SLinus Torvalds 	 * Now register the handlers for the master IRQ handlers
1801da177e4SLinus Torvalds 	 * at levels 1-7. Most of the work is done elsewhere.
1811da177e4SLinus Torvalds 	 */
1821da177e4SLinus Torvalds 
1839c5f4afdSRoman Zippel 	if (oss_present)
1841da177e4SLinus Torvalds 		oss_register_interrupts();
1859c5f4afdSRoman Zippel 	else
1861da177e4SLinus Torvalds 		via_register_interrupts();
1879c5f4afdSRoman Zippel 	if (psc_present)
1889c5f4afdSRoman Zippel 		psc_register_interrupts();
1899c5f4afdSRoman Zippel 	if (baboon_present)
1909c5f4afdSRoman Zippel 		baboon_register_interrupts();
1911da177e4SLinus Torvalds 	iop_register_interrupts();
19292c3dd15SGeert Uytterhoeven 	if (request_irq(IRQ_AUTO_7, mac_nmi_handler, 0, "NMI",
19392c3dd15SGeert Uytterhoeven 			mac_nmi_handler))
19492c3dd15SGeert Uytterhoeven 		pr_err("Couldn't register NMI\n");
1951da177e4SLinus Torvalds #ifdef DEBUG_MACINTS
1961da177e4SLinus Torvalds 	printk("mac_init_IRQ(): Done!\n");
1971da177e4SLinus Torvalds #endif
1981da177e4SLinus Torvalds }
1991da177e4SLinus Torvalds 
2001da177e4SLinus Torvalds /*
2012690e214SFinn Thain  *  mac_irq_enable - enable an interrupt source
2022690e214SFinn Thain  * mac_irq_disable - disable an interrupt source
2031da177e4SLinus Torvalds  *
2041da177e4SLinus Torvalds  * These routines are just dispatchers to the VIA/OSS/PSC routines.
2051da177e4SLinus Torvalds  */
2061da177e4SLinus Torvalds 
2072690e214SFinn Thain void mac_irq_enable(struct irq_data *data)
2081da177e4SLinus Torvalds {
2092690e214SFinn Thain 	int irq = data->irq;
2101da177e4SLinus Torvalds 	int irq_src = IRQ_SRC(irq);
2111da177e4SLinus Torvalds 
2121da177e4SLinus Torvalds 	switch(irq_src) {
2139c5f4afdSRoman Zippel 	case 1:
2141da177e4SLinus Torvalds 		via_irq_enable(irq);
2159c5f4afdSRoman Zippel 		break;
2169c5f4afdSRoman Zippel 	case 2:
2179c5f4afdSRoman Zippel 	case 7:
2189c5f4afdSRoman Zippel 		if (oss_present)
2199c5f4afdSRoman Zippel 			oss_irq_enable(irq);
2209c5f4afdSRoman Zippel 		else
2219c5f4afdSRoman Zippel 			via_irq_enable(irq);
2221da177e4SLinus Torvalds 		break;
2231da177e4SLinus Torvalds 	case 3:
2241da177e4SLinus Torvalds 	case 5:
2259c5f4afdSRoman Zippel 	case 6:
2269c5f4afdSRoman Zippel 		if (psc_present)
2271da177e4SLinus Torvalds 			psc_irq_enable(irq);
2289c5f4afdSRoman Zippel 		else if (oss_present)
2291da177e4SLinus Torvalds 			oss_irq_enable(irq);
23080614e5aSFinn Thain 		break;
23180614e5aSFinn Thain 	case 4:
23280614e5aSFinn Thain 		if (psc_present)
23380614e5aSFinn Thain 			psc_irq_enable(irq);
2341da177e4SLinus Torvalds 		break;
2359c5f4afdSRoman Zippel 	case 8:
2369c5f4afdSRoman Zippel 		if (baboon_present)
2371da177e4SLinus Torvalds 			baboon_irq_enable(irq);
2381da177e4SLinus Torvalds 		break;
2391da177e4SLinus Torvalds 	}
2401da177e4SLinus Torvalds }
2411da177e4SLinus Torvalds 
2422690e214SFinn Thain void mac_irq_disable(struct irq_data *data)
2431da177e4SLinus Torvalds {
2442690e214SFinn Thain 	int irq = data->irq;
2451da177e4SLinus Torvalds 	int irq_src = IRQ_SRC(irq);
2461da177e4SLinus Torvalds 
2471da177e4SLinus Torvalds 	switch(irq_src) {
2489c5f4afdSRoman Zippel 	case 1:
2499c5f4afdSRoman Zippel 		via_irq_disable(irq);
2501da177e4SLinus Torvalds 		break;
2511da177e4SLinus Torvalds 	case 2:
2529c5f4afdSRoman Zippel 	case 7:
2539c5f4afdSRoman Zippel 		if (oss_present)
2541da177e4SLinus Torvalds 			oss_irq_disable(irq);
2559c5f4afdSRoman Zippel 		else
2561da177e4SLinus Torvalds 			via_irq_disable(irq);
2571da177e4SLinus Torvalds 		break;
2581da177e4SLinus Torvalds 	case 3:
2591da177e4SLinus Torvalds 	case 5:
2609c5f4afdSRoman Zippel 	case 6:
2619c5f4afdSRoman Zippel 		if (psc_present)
2621da177e4SLinus Torvalds 			psc_irq_disable(irq);
2639c5f4afdSRoman Zippel 		else if (oss_present)
2641da177e4SLinus Torvalds 			oss_irq_disable(irq);
26580614e5aSFinn Thain 		break;
26680614e5aSFinn Thain 	case 4:
26780614e5aSFinn Thain 		if (psc_present)
26880614e5aSFinn Thain 			psc_irq_disable(irq);
2691da177e4SLinus Torvalds 		break;
2709c5f4afdSRoman Zippel 	case 8:
2719c5f4afdSRoman Zippel 		if (baboon_present)
2721da177e4SLinus Torvalds 			baboon_irq_disable(irq);
2731da177e4SLinus Torvalds 		break;
2741da177e4SLinus Torvalds 	}
2751da177e4SLinus Torvalds }
2761da177e4SLinus Torvalds 
2771da177e4SLinus Torvalds static int num_debug[8];
2781da177e4SLinus Torvalds 
2792850bc27SAl Viro irqreturn_t mac_debug_handler(int irq, void *dev_id)
2801da177e4SLinus Torvalds {
2811da177e4SLinus Torvalds 	if (num_debug[irq] < 10) {
2821da177e4SLinus Torvalds 		printk("DEBUG: Unexpected IRQ %d\n", irq);
2831da177e4SLinus Torvalds 		num_debug[irq]++;
2841da177e4SLinus Torvalds 	}
2851da177e4SLinus Torvalds 	return IRQ_HANDLED;
2861da177e4SLinus Torvalds }
2871da177e4SLinus Torvalds 
2881da177e4SLinus Torvalds static int in_nmi;
2891da177e4SLinus Torvalds static volatile int nmi_hold;
2901da177e4SLinus Torvalds 
2912850bc27SAl Viro irqreturn_t mac_nmi_handler(int irq, void *dev_id)
2921da177e4SLinus Torvalds {
2931da177e4SLinus Torvalds 	int i;
2941da177e4SLinus Torvalds 	/*
2951da177e4SLinus Torvalds 	 * generate debug output on NMI switch if 'debug' kernel option given
2961da177e4SLinus Torvalds 	 * (only works with Penguin!)
2971da177e4SLinus Torvalds 	 */
2981da177e4SLinus Torvalds 
2991da177e4SLinus Torvalds 	in_nmi++;
3001da177e4SLinus Torvalds 	for (i=0; i<100; i++)
3011da177e4SLinus Torvalds 		udelay(1000);
3021da177e4SLinus Torvalds 
3031da177e4SLinus Torvalds 	if (in_nmi == 1) {
3041da177e4SLinus Torvalds 		nmi_hold = 1;
3051da177e4SLinus Torvalds 		printk("... pausing, press NMI to resume ...");
3061da177e4SLinus Torvalds 	} else {
3071da177e4SLinus Torvalds 		printk(" ok!\n");
3081da177e4SLinus Torvalds 		nmi_hold = 0;
3091da177e4SLinus Torvalds 	}
3101da177e4SLinus Torvalds 
3111da177e4SLinus Torvalds 	barrier();
3121da177e4SLinus Torvalds 
3131da177e4SLinus Torvalds 	while (nmi_hold == 1)
3141da177e4SLinus Torvalds 		udelay(1000);
3151da177e4SLinus Torvalds 
3161da177e4SLinus Torvalds 	if (console_loglevel >= 8) {
3171da177e4SLinus Torvalds #if 0
3182850bc27SAl Viro 		struct pt_regs *fp = get_irq_regs();
3191da177e4SLinus Torvalds 		show_state();
3201da177e4SLinus Torvalds 		printk("PC: %08lx\nSR: %04x  SP: %p\n", fp->pc, fp->sr, fp);
3211da177e4SLinus Torvalds 		printk("d0: %08lx    d1: %08lx    d2: %08lx    d3: %08lx\n",
3221da177e4SLinus Torvalds 		       fp->d0, fp->d1, fp->d2, fp->d3);
3231da177e4SLinus Torvalds 		printk("d4: %08lx    d5: %08lx    a0: %08lx    a1: %08lx\n",
3241da177e4SLinus Torvalds 		       fp->d4, fp->d5, fp->a0, fp->a1);
3251da177e4SLinus Torvalds 
3261da177e4SLinus Torvalds 		if (STACK_MAGIC != *(unsigned long *)current->kernel_stack_page)
3271da177e4SLinus Torvalds 			printk("Corrupted stack page\n");
3281da177e4SLinus Torvalds 		printk("Process %s (pid: %d, stackpage=%08lx)\n",
3291da177e4SLinus Torvalds 			current->comm, current->pid, current->kernel_stack_page);
3301da177e4SLinus Torvalds 		if (intr_count == 1)
3311da177e4SLinus Torvalds 			dump_stack((struct frame *)fp);
3321da177e4SLinus Torvalds #else
3331da177e4SLinus Torvalds 		/* printk("NMI "); */
3341da177e4SLinus Torvalds #endif
3351da177e4SLinus Torvalds 	}
3361da177e4SLinus Torvalds 	in_nmi--;
3371da177e4SLinus Torvalds 	return IRQ_HANDLED;
3381da177e4SLinus Torvalds }
339