xref: /OK3568_Linux_fs/kernel/arch/m68k/mac/macints.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  *	Macintosh interrupts
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * General design:
6*4882a593Smuzhiyun  * In contrary to the Amiga and Atari platforms, the Mac hardware seems to
7*4882a593Smuzhiyun  * exclusively use the autovector interrupts (the 'generic level0-level7'
8*4882a593Smuzhiyun  * interrupts with exception vectors 0x19-0x1f). The following interrupt levels
9*4882a593Smuzhiyun  * are used:
10*4882a593Smuzhiyun  *	1	- VIA1
11*4882a593Smuzhiyun  *		  - slot 0: one second interrupt (CA2)
12*4882a593Smuzhiyun  *		  - slot 1: VBlank (CA1)
13*4882a593Smuzhiyun  *		  - slot 2: ADB data ready (SR full)
14*4882a593Smuzhiyun  *		  - slot 3: ADB data  (CB2)
15*4882a593Smuzhiyun  *		  - slot 4: ADB clock (CB1)
16*4882a593Smuzhiyun  *		  - slot 5: timer 2
17*4882a593Smuzhiyun  *		  - slot 6: timer 1
18*4882a593Smuzhiyun  *		  - slot 7: status of IRQ; signals 'any enabled int.'
19*4882a593Smuzhiyun  *
20*4882a593Smuzhiyun  *	2	- VIA2 or RBV
21*4882a593Smuzhiyun  *		  - slot 0: SCSI DRQ (CA2)
22*4882a593Smuzhiyun  *		  - slot 1: NUBUS IRQ (CA1) need to read port A to find which
23*4882a593Smuzhiyun  *		  - slot 2: /EXP IRQ (only on IIci)
24*4882a593Smuzhiyun  *		  - slot 3: SCSI IRQ (CB2)
25*4882a593Smuzhiyun  *		  - slot 4: ASC IRQ (CB1)
26*4882a593Smuzhiyun  *		  - slot 5: timer 2 (not on IIci)
27*4882a593Smuzhiyun  *		  - slot 6: timer 1 (not on IIci)
28*4882a593Smuzhiyun  *		  - slot 7: status of IRQ; signals 'any enabled int.'
29*4882a593Smuzhiyun  *
30*4882a593Smuzhiyun  * Levels 3-6 vary by machine type. For VIA or RBV Macintoshes:
31*4882a593Smuzhiyun  *
32*4882a593Smuzhiyun  *	3	- unused (?)
33*4882a593Smuzhiyun  *
34*4882a593Smuzhiyun  *	4	- SCC
35*4882a593Smuzhiyun  *
36*4882a593Smuzhiyun  *	5	- unused (?)
37*4882a593Smuzhiyun  *		  [serial errors or special conditions seem to raise level 6
38*4882a593Smuzhiyun  *		  interrupts on some models (LC4xx?)]
39*4882a593Smuzhiyun  *
40*4882a593Smuzhiyun  *	6	- off switch (?)
41*4882a593Smuzhiyun  *
42*4882a593Smuzhiyun  * Machines with Quadra-like VIA hardware, except PSC and PMU machines, support
43*4882a593Smuzhiyun  * an alternate interrupt mapping, as used by A/UX. It spreads ethernet and
44*4882a593Smuzhiyun  * sound out to their own autovector IRQs and gives VIA1 a higher priority:
45*4882a593Smuzhiyun  *
46*4882a593Smuzhiyun  *	1	- unused (?)
47*4882a593Smuzhiyun  *
48*4882a593Smuzhiyun  *	3	- on-board SONIC
49*4882a593Smuzhiyun  *
50*4882a593Smuzhiyun  *	5	- Apple Sound Chip (ASC)
51*4882a593Smuzhiyun  *
52*4882a593Smuzhiyun  *	6	- VIA1
53*4882a593Smuzhiyun  *
54*4882a593Smuzhiyun  * For OSS Macintoshes (IIfx only), we apply an interrupt mapping similar to
55*4882a593Smuzhiyun  * the Quadra (A/UX) mapping:
56*4882a593Smuzhiyun  *
57*4882a593Smuzhiyun  *	1	- ISM IOP (ADB)
58*4882a593Smuzhiyun  *
59*4882a593Smuzhiyun  *	2	- SCSI
60*4882a593Smuzhiyun  *
61*4882a593Smuzhiyun  *	3	- NuBus
62*4882a593Smuzhiyun  *
63*4882a593Smuzhiyun  *	4	- SCC IOP
64*4882a593Smuzhiyun  *
65*4882a593Smuzhiyun  *	6	- VIA1
66*4882a593Smuzhiyun  *
67*4882a593Smuzhiyun  * For PSC Macintoshes (660AV, 840AV):
68*4882a593Smuzhiyun  *
69*4882a593Smuzhiyun  *	3	- PSC level 3
70*4882a593Smuzhiyun  *		  - slot 0: MACE
71*4882a593Smuzhiyun  *
72*4882a593Smuzhiyun  *	4	- PSC level 4
73*4882a593Smuzhiyun  *		  - slot 1: SCC channel A interrupt
74*4882a593Smuzhiyun  *		  - slot 2: SCC channel B interrupt
75*4882a593Smuzhiyun  *		  - slot 3: MACE DMA
76*4882a593Smuzhiyun  *
77*4882a593Smuzhiyun  *	5	- PSC level 5
78*4882a593Smuzhiyun  *
79*4882a593Smuzhiyun  *	6	- PSC level 6
80*4882a593Smuzhiyun  *
81*4882a593Smuzhiyun  * Finally we have good 'ole level 7, the non-maskable interrupt:
82*4882a593Smuzhiyun  *
83*4882a593Smuzhiyun  *	7	- NMI (programmer's switch on the back of some Macs)
84*4882a593Smuzhiyun  *		  Also RAM parity error on models which support it (IIc, IIfx?)
85*4882a593Smuzhiyun  *
86*4882a593Smuzhiyun  * The current interrupt logic looks something like this:
87*4882a593Smuzhiyun  *
88*4882a593Smuzhiyun  * - We install dispatchers for the autovector interrupts (1-7). These
89*4882a593Smuzhiyun  *   dispatchers are responsible for querying the hardware (the
90*4882a593Smuzhiyun  *   VIA/RBV/OSS/PSC chips) to determine the actual interrupt source. Using
91*4882a593Smuzhiyun  *   this information a machspec interrupt number is generated by placing the
92*4882a593Smuzhiyun  *   index of the interrupt hardware into the low three bits and the original
93*4882a593Smuzhiyun  *   autovector interrupt number in the upper 5 bits. The handlers for the
94*4882a593Smuzhiyun  *   resulting machspec interrupt are then called.
95*4882a593Smuzhiyun  *
96*4882a593Smuzhiyun  * - Nubus is a special case because its interrupts are hidden behind two
97*4882a593Smuzhiyun  *   layers of hardware. Nubus interrupts come in as index 1 on VIA #2,
98*4882a593Smuzhiyun  *   which translates to IRQ number 17. In this spot we install _another_
99*4882a593Smuzhiyun  *   dispatcher. This dispatcher finds the interrupting slot number (9-F) and
100*4882a593Smuzhiyun  *   then forms a new machspec interrupt number as above with the slot number
101*4882a593Smuzhiyun  *   minus 9 in the low three bits and the pseudo-level 7 in the upper five
102*4882a593Smuzhiyun  *   bits.  The handlers for this new machspec interrupt number are then
103*4882a593Smuzhiyun  *   called. This puts Nubus interrupts into the range 56-62.
104*4882a593Smuzhiyun  *
105*4882a593Smuzhiyun  * - The Baboon interrupts (used on some PowerBooks) are an even more special
106*4882a593Smuzhiyun  *   case. They're hidden behind the Nubus slot $C interrupt thus adding a
107*4882a593Smuzhiyun  *   third layer of indirection. Why oh why did the Apple engineers do that?
108*4882a593Smuzhiyun  *
109*4882a593Smuzhiyun  */
110*4882a593Smuzhiyun 
111*4882a593Smuzhiyun #include <linux/types.h>
112*4882a593Smuzhiyun #include <linux/kernel.h>
113*4882a593Smuzhiyun #include <linux/sched.h>
114*4882a593Smuzhiyun #include <linux/sched/debug.h>
115*4882a593Smuzhiyun #include <linux/interrupt.h>
116*4882a593Smuzhiyun #include <linux/irq.h>
117*4882a593Smuzhiyun #include <linux/delay.h>
118*4882a593Smuzhiyun 
119*4882a593Smuzhiyun #include <asm/irq.h>
120*4882a593Smuzhiyun #include <asm/macintosh.h>
121*4882a593Smuzhiyun #include <asm/macints.h>
122*4882a593Smuzhiyun #include <asm/mac_via.h>
123*4882a593Smuzhiyun #include <asm/mac_psc.h>
124*4882a593Smuzhiyun #include <asm/mac_oss.h>
125*4882a593Smuzhiyun #include <asm/mac_iop.h>
126*4882a593Smuzhiyun #include <asm/mac_baboon.h>
127*4882a593Smuzhiyun #include <asm/hwtest.h>
128*4882a593Smuzhiyun #include <asm/irq_regs.h>
129*4882a593Smuzhiyun 
130*4882a593Smuzhiyun extern void show_registers(struct pt_regs *);
131*4882a593Smuzhiyun 
132*4882a593Smuzhiyun irqreturn_t mac_nmi_handler(int, void *);
133*4882a593Smuzhiyun 
134*4882a593Smuzhiyun static unsigned int mac_irq_startup(struct irq_data *);
135*4882a593Smuzhiyun static void mac_irq_shutdown(struct irq_data *);
136*4882a593Smuzhiyun 
137*4882a593Smuzhiyun static struct irq_chip mac_irq_chip = {
138*4882a593Smuzhiyun 	.name		= "mac",
139*4882a593Smuzhiyun 	.irq_enable	= mac_irq_enable,
140*4882a593Smuzhiyun 	.irq_disable	= mac_irq_disable,
141*4882a593Smuzhiyun 	.irq_startup	= mac_irq_startup,
142*4882a593Smuzhiyun 	.irq_shutdown	= mac_irq_shutdown,
143*4882a593Smuzhiyun };
144*4882a593Smuzhiyun 
mac_init_IRQ(void)145*4882a593Smuzhiyun void __init mac_init_IRQ(void)
146*4882a593Smuzhiyun {
147*4882a593Smuzhiyun 	m68k_setup_irq_controller(&mac_irq_chip, handle_simple_irq, IRQ_USER,
148*4882a593Smuzhiyun 				  NUM_MAC_SOURCES - IRQ_USER);
149*4882a593Smuzhiyun 
150*4882a593Smuzhiyun 	/*
151*4882a593Smuzhiyun 	 * Now register the handlers for the master IRQ handlers
152*4882a593Smuzhiyun 	 * at levels 1-7. Most of the work is done elsewhere.
153*4882a593Smuzhiyun 	 */
154*4882a593Smuzhiyun 
155*4882a593Smuzhiyun 	if (oss_present)
156*4882a593Smuzhiyun 		oss_register_interrupts();
157*4882a593Smuzhiyun 	else
158*4882a593Smuzhiyun 		via_register_interrupts();
159*4882a593Smuzhiyun 	if (psc)
160*4882a593Smuzhiyun 		psc_register_interrupts();
161*4882a593Smuzhiyun 	if (baboon_present)
162*4882a593Smuzhiyun 		baboon_register_interrupts();
163*4882a593Smuzhiyun 	iop_register_interrupts();
164*4882a593Smuzhiyun 	if (request_irq(IRQ_AUTO_7, mac_nmi_handler, 0, "NMI",
165*4882a593Smuzhiyun 			mac_nmi_handler))
166*4882a593Smuzhiyun 		pr_err("Couldn't register NMI\n");
167*4882a593Smuzhiyun }
168*4882a593Smuzhiyun 
169*4882a593Smuzhiyun /*
170*4882a593Smuzhiyun  *  mac_irq_enable - enable an interrupt source
171*4882a593Smuzhiyun  * mac_irq_disable - disable an interrupt source
172*4882a593Smuzhiyun  *
173*4882a593Smuzhiyun  * These routines are just dispatchers to the VIA/OSS/PSC routines.
174*4882a593Smuzhiyun  */
175*4882a593Smuzhiyun 
mac_irq_enable(struct irq_data * data)176*4882a593Smuzhiyun void mac_irq_enable(struct irq_data *data)
177*4882a593Smuzhiyun {
178*4882a593Smuzhiyun 	int irq = data->irq;
179*4882a593Smuzhiyun 	int irq_src = IRQ_SRC(irq);
180*4882a593Smuzhiyun 
181*4882a593Smuzhiyun 	switch(irq_src) {
182*4882a593Smuzhiyun 	case 1:
183*4882a593Smuzhiyun 	case 2:
184*4882a593Smuzhiyun 	case 7:
185*4882a593Smuzhiyun 		if (oss_present)
186*4882a593Smuzhiyun 			oss_irq_enable(irq);
187*4882a593Smuzhiyun 		else
188*4882a593Smuzhiyun 			via_irq_enable(irq);
189*4882a593Smuzhiyun 		break;
190*4882a593Smuzhiyun 	case 3:
191*4882a593Smuzhiyun 	case 4:
192*4882a593Smuzhiyun 	case 5:
193*4882a593Smuzhiyun 	case 6:
194*4882a593Smuzhiyun 		if (psc)
195*4882a593Smuzhiyun 			psc_irq_enable(irq);
196*4882a593Smuzhiyun 		else if (oss_present)
197*4882a593Smuzhiyun 			oss_irq_enable(irq);
198*4882a593Smuzhiyun 		break;
199*4882a593Smuzhiyun 	case 8:
200*4882a593Smuzhiyun 		if (baboon_present)
201*4882a593Smuzhiyun 			baboon_irq_enable(irq);
202*4882a593Smuzhiyun 		break;
203*4882a593Smuzhiyun 	}
204*4882a593Smuzhiyun }
205*4882a593Smuzhiyun 
mac_irq_disable(struct irq_data * data)206*4882a593Smuzhiyun void mac_irq_disable(struct irq_data *data)
207*4882a593Smuzhiyun {
208*4882a593Smuzhiyun 	int irq = data->irq;
209*4882a593Smuzhiyun 	int irq_src = IRQ_SRC(irq);
210*4882a593Smuzhiyun 
211*4882a593Smuzhiyun 	switch(irq_src) {
212*4882a593Smuzhiyun 	case 1:
213*4882a593Smuzhiyun 	case 2:
214*4882a593Smuzhiyun 	case 7:
215*4882a593Smuzhiyun 		if (oss_present)
216*4882a593Smuzhiyun 			oss_irq_disable(irq);
217*4882a593Smuzhiyun 		else
218*4882a593Smuzhiyun 			via_irq_disable(irq);
219*4882a593Smuzhiyun 		break;
220*4882a593Smuzhiyun 	case 3:
221*4882a593Smuzhiyun 	case 4:
222*4882a593Smuzhiyun 	case 5:
223*4882a593Smuzhiyun 	case 6:
224*4882a593Smuzhiyun 		if (psc)
225*4882a593Smuzhiyun 			psc_irq_disable(irq);
226*4882a593Smuzhiyun 		else if (oss_present)
227*4882a593Smuzhiyun 			oss_irq_disable(irq);
228*4882a593Smuzhiyun 		break;
229*4882a593Smuzhiyun 	case 8:
230*4882a593Smuzhiyun 		if (baboon_present)
231*4882a593Smuzhiyun 			baboon_irq_disable(irq);
232*4882a593Smuzhiyun 		break;
233*4882a593Smuzhiyun 	}
234*4882a593Smuzhiyun }
235*4882a593Smuzhiyun 
mac_irq_startup(struct irq_data * data)236*4882a593Smuzhiyun static unsigned int mac_irq_startup(struct irq_data *data)
237*4882a593Smuzhiyun {
238*4882a593Smuzhiyun 	int irq = data->irq;
239*4882a593Smuzhiyun 
240*4882a593Smuzhiyun 	if (IRQ_SRC(irq) == 7 && !oss_present)
241*4882a593Smuzhiyun 		via_nubus_irq_startup(irq);
242*4882a593Smuzhiyun 	else
243*4882a593Smuzhiyun 		mac_irq_enable(data);
244*4882a593Smuzhiyun 
245*4882a593Smuzhiyun 	return 0;
246*4882a593Smuzhiyun }
247*4882a593Smuzhiyun 
mac_irq_shutdown(struct irq_data * data)248*4882a593Smuzhiyun static void mac_irq_shutdown(struct irq_data *data)
249*4882a593Smuzhiyun {
250*4882a593Smuzhiyun 	int irq = data->irq;
251*4882a593Smuzhiyun 
252*4882a593Smuzhiyun 	if (IRQ_SRC(irq) == 7 && !oss_present)
253*4882a593Smuzhiyun 		via_nubus_irq_shutdown(irq);
254*4882a593Smuzhiyun 	else
255*4882a593Smuzhiyun 		mac_irq_disable(data);
256*4882a593Smuzhiyun }
257*4882a593Smuzhiyun 
258*4882a593Smuzhiyun static volatile int in_nmi;
259*4882a593Smuzhiyun 
mac_nmi_handler(int irq,void * dev_id)260*4882a593Smuzhiyun irqreturn_t mac_nmi_handler(int irq, void *dev_id)
261*4882a593Smuzhiyun {
262*4882a593Smuzhiyun 	if (in_nmi)
263*4882a593Smuzhiyun 		return IRQ_HANDLED;
264*4882a593Smuzhiyun 	in_nmi = 1;
265*4882a593Smuzhiyun 
266*4882a593Smuzhiyun 	pr_info("Non-Maskable Interrupt\n");
267*4882a593Smuzhiyun 	show_registers(get_irq_regs());
268*4882a593Smuzhiyun 
269*4882a593Smuzhiyun 	in_nmi = 0;
270*4882a593Smuzhiyun 	return IRQ_HANDLED;
271*4882a593Smuzhiyun }
272