xref: /linux/arch/m68k/mac/macints.c (revision c07a16404c8f82a10bec12fd1b3a4064ca30f142)
1b2441318SGreg 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>
129*c07a1640SGeert Uytterhoeven #include <asm/processor.h>
1301da177e4SLinus Torvalds 
131c4af5da7SFinn Thain static unsigned int mac_irq_startup(struct irq_data *);
132c4af5da7SFinn Thain static void mac_irq_shutdown(struct irq_data *);
133c4af5da7SFinn Thain 
134c288bf25SGeert Uytterhoeven static struct irq_chip mac_irq_chip = {
1359c5f4afdSRoman Zippel 	.name		= "mac",
136e8abf5e7SGeert Uytterhoeven 	.irq_enable	= mac_irq_enable,
137e8abf5e7SGeert Uytterhoeven 	.irq_disable	= mac_irq_disable,
138c4af5da7SFinn Thain 	.irq_startup	= mac_irq_startup,
139c4af5da7SFinn Thain 	.irq_shutdown	= mac_irq_shutdown,
1409c5f4afdSRoman Zippel };
1419c5f4afdSRoman Zippel 
142c36dd297SGeert Uytterhoeven static irqreturn_t mac_nmi_handler(int irq, void *dev_id)
143c36dd297SGeert Uytterhoeven {
144c36dd297SGeert Uytterhoeven 	static volatile int in_nmi;
145c36dd297SGeert Uytterhoeven 
146c36dd297SGeert Uytterhoeven 	if (in_nmi)
147c36dd297SGeert Uytterhoeven 		return IRQ_HANDLED;
148c36dd297SGeert Uytterhoeven 	in_nmi = 1;
149c36dd297SGeert Uytterhoeven 
150c36dd297SGeert Uytterhoeven 	pr_info("Non-Maskable Interrupt\n");
151c36dd297SGeert Uytterhoeven 	show_registers(get_irq_regs());
152c36dd297SGeert Uytterhoeven 
153c36dd297SGeert Uytterhoeven 	in_nmi = 0;
154c36dd297SGeert Uytterhoeven 	return IRQ_HANDLED;
155c36dd297SGeert Uytterhoeven }
156c36dd297SGeert Uytterhoeven 
15766a3f820SAl Viro void __init mac_init_IRQ(void)
1581da177e4SLinus Torvalds {
159edb34725SGeert Uytterhoeven 	m68k_setup_irq_controller(&mac_irq_chip, handle_simple_irq, IRQ_USER,
1609c5f4afdSRoman Zippel 				  NUM_MAC_SOURCES - IRQ_USER);
1611da177e4SLinus Torvalds 
1621da177e4SLinus Torvalds 	/*
1631da177e4SLinus Torvalds 	 * Now register the handlers for the master IRQ handlers
1641da177e4SLinus Torvalds 	 * at levels 1-7. Most of the work is done elsewhere.
1651da177e4SLinus Torvalds 	 */
1661da177e4SLinus Torvalds 
1679c5f4afdSRoman Zippel 	if (oss_present)
1681da177e4SLinus Torvalds 		oss_register_interrupts();
1699c5f4afdSRoman Zippel 	else
1701da177e4SLinus Torvalds 		via_register_interrupts();
17170bc53b4SGeert Uytterhoeven 	if (psc)
1729c5f4afdSRoman Zippel 		psc_register_interrupts();
1739c5f4afdSRoman Zippel 	if (baboon_present)
1749c5f4afdSRoman Zippel 		baboon_register_interrupts();
1751da177e4SLinus Torvalds 	iop_register_interrupts();
17692c3dd15SGeert Uytterhoeven 	if (request_irq(IRQ_AUTO_7, mac_nmi_handler, 0, "NMI",
17792c3dd15SGeert Uytterhoeven 			mac_nmi_handler))
17892c3dd15SGeert Uytterhoeven 		pr_err("Couldn't register NMI\n");
1791da177e4SLinus Torvalds }
1801da177e4SLinus Torvalds 
1811da177e4SLinus Torvalds /*
1822690e214SFinn Thain  *  mac_irq_enable - enable an interrupt source
1832690e214SFinn Thain  * mac_irq_disable - disable an interrupt source
1841da177e4SLinus Torvalds  *
1851da177e4SLinus Torvalds  * These routines are just dispatchers to the VIA/OSS/PSC routines.
1861da177e4SLinus Torvalds  */
1871da177e4SLinus Torvalds 
1882690e214SFinn Thain void mac_irq_enable(struct irq_data *data)
1891da177e4SLinus Torvalds {
1902690e214SFinn Thain 	int irq = data->irq;
1911da177e4SLinus Torvalds 	int irq_src = IRQ_SRC(irq);
1921da177e4SLinus Torvalds 
1931da177e4SLinus Torvalds 	switch(irq_src) {
1949c5f4afdSRoman Zippel 	case 1:
1959c5f4afdSRoman Zippel 	case 2:
1969c5f4afdSRoman Zippel 	case 7:
1979c5f4afdSRoman Zippel 		if (oss_present)
1989c5f4afdSRoman Zippel 			oss_irq_enable(irq);
1999c5f4afdSRoman Zippel 		else
2009c5f4afdSRoman Zippel 			via_irq_enable(irq);
2011da177e4SLinus Torvalds 		break;
2021da177e4SLinus Torvalds 	case 3:
203da3fb3c9SFinn Thain 	case 4:
2041da177e4SLinus Torvalds 	case 5:
2059c5f4afdSRoman Zippel 	case 6:
20670bc53b4SGeert Uytterhoeven 		if (psc)
2071da177e4SLinus Torvalds 			psc_irq_enable(irq);
2089c5f4afdSRoman Zippel 		else if (oss_present)
2091da177e4SLinus Torvalds 			oss_irq_enable(irq);
21080614e5aSFinn Thain 		break;
2119c5f4afdSRoman Zippel 	case 8:
2129c5f4afdSRoman Zippel 		if (baboon_present)
2131da177e4SLinus Torvalds 			baboon_irq_enable(irq);
2141da177e4SLinus Torvalds 		break;
2151da177e4SLinus Torvalds 	}
2161da177e4SLinus Torvalds }
2171da177e4SLinus Torvalds 
2182690e214SFinn Thain void mac_irq_disable(struct irq_data *data)
2191da177e4SLinus Torvalds {
2202690e214SFinn Thain 	int irq = data->irq;
2211da177e4SLinus Torvalds 	int irq_src = IRQ_SRC(irq);
2221da177e4SLinus Torvalds 
2231da177e4SLinus Torvalds 	switch(irq_src) {
2249c5f4afdSRoman Zippel 	case 1:
2251da177e4SLinus Torvalds 	case 2:
2269c5f4afdSRoman Zippel 	case 7:
2279c5f4afdSRoman Zippel 		if (oss_present)
2281da177e4SLinus Torvalds 			oss_irq_disable(irq);
2299c5f4afdSRoman Zippel 		else
2301da177e4SLinus Torvalds 			via_irq_disable(irq);
2311da177e4SLinus Torvalds 		break;
2321da177e4SLinus Torvalds 	case 3:
233da3fb3c9SFinn Thain 	case 4:
2341da177e4SLinus Torvalds 	case 5:
2359c5f4afdSRoman Zippel 	case 6:
23670bc53b4SGeert Uytterhoeven 		if (psc)
2371da177e4SLinus Torvalds 			psc_irq_disable(irq);
2389c5f4afdSRoman Zippel 		else if (oss_present)
2391da177e4SLinus Torvalds 			oss_irq_disable(irq);
24080614e5aSFinn Thain 		break;
2419c5f4afdSRoman Zippel 	case 8:
2429c5f4afdSRoman Zippel 		if (baboon_present)
2431da177e4SLinus Torvalds 			baboon_irq_disable(irq);
2441da177e4SLinus Torvalds 		break;
2451da177e4SLinus Torvalds 	}
2461da177e4SLinus Torvalds }
2471da177e4SLinus Torvalds 
248c4af5da7SFinn Thain static unsigned int mac_irq_startup(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_startup(irq);
254c4af5da7SFinn Thain 	else
255c4af5da7SFinn Thain 		mac_irq_enable(data);
256c4af5da7SFinn Thain 
257c4af5da7SFinn Thain 	return 0;
258c4af5da7SFinn Thain }
259c4af5da7SFinn Thain 
260c4af5da7SFinn Thain static void mac_irq_shutdown(struct irq_data *data)
261c4af5da7SFinn Thain {
262c4af5da7SFinn Thain 	int irq = data->irq;
263c4af5da7SFinn Thain 
264c4af5da7SFinn Thain 	if (IRQ_SRC(irq) == 7 && !oss_present)
265c4af5da7SFinn Thain 		via_nubus_irq_shutdown(irq);
266c4af5da7SFinn Thain 	else
267c4af5da7SFinn Thain 		mac_irq_disable(data);
268c4af5da7SFinn Thain }
269