blob: 74f5a97c98606a6d6e2c56d20e7c29e1f61ce2fa [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Macintosh interrupts
3 *
4 * General design:
5 * In contrary to the Amiga and Atari platforms, the Mac hardware seems to
6 * exclusively use the autovector interrupts (the 'generic level0-level7'
7 * interrupts with exception vectors 0x19-0x1f). The following interrupt levels
8 * are used:
9 * 1 - VIA1
10 * - slot 0: one second interrupt (CA2)
11 * - slot 1: VBlank (CA1)
12 * - slot 2: ADB data ready (SR full)
13 * - slot 3: ADB data (CB2)
14 * - slot 4: ADB clock (CB1)
15 * - slot 5: timer 2
16 * - slot 6: timer 1
17 * - slot 7: status of IRQ; signals 'any enabled int.'
18 *
19 * 2 - VIA2 or RBV
20 * - slot 0: SCSI DRQ (CA2)
21 * - slot 1: NUBUS IRQ (CA1) need to read port A to find which
22 * - slot 2: /EXP IRQ (only on IIci)
23 * - slot 3: SCSI IRQ (CB2)
24 * - slot 4: ASC IRQ (CB1)
25 * - slot 5: timer 2 (not on IIci)
26 * - slot 6: timer 1 (not on IIci)
27 * - slot 7: status of IRQ; signals 'any enabled int.'
28 *
29 * 2 - OSS (IIfx only?)
30 * - slot 0: SCSI interrupt
31 * - slot 1: Sound interrupt
32 *
33 * Levels 3-6 vary by machine type. For VIA or RBV Macintoshes:
34 *
35 * 3 - unused (?)
36 *
Finn Thain80614e52009-11-17 20:06:48 +110037 * 4 - SCC
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 *
39 * 5 - unused (?)
40 * [serial errors or special conditions seem to raise level 6
41 * interrupts on some models (LC4xx?)]
42 *
43 * 6 - off switch (?)
44 *
Finn Thain8d9f0142011-10-24 01:11:16 +110045 * Machines with Quadra-like VIA hardware, except PSC and PMU machines, support
46 * an alternate interrupt mapping, as used by A/UX. It spreads ethernet and
47 * sound out to their own autovector IRQs and gives VIA1 a higher priority:
48 *
49 * 1 - unused (?)
50 *
51 * 3 - on-board SONIC
52 *
53 * 5 - Apple Sound Chip (ASC)
54 *
55 * 6 - VIA1
56 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 * For OSS Macintoshes (IIfx only at this point):
58 *
59 * 3 - Nubus interrupt
60 * - slot 0: Slot $9
61 * - slot 1: Slot $A
62 * - slot 2: Slot $B
63 * - slot 3: Slot $C
64 * - slot 4: Slot $D
65 * - slot 5: Slot $E
66 *
67 * 4 - SCC IOP
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 *
69 * 5 - ISM IOP (ADB?)
70 *
71 * 6 - unused
72 *
73 * For PSC Macintoshes (660AV, 840AV):
74 *
75 * 3 - PSC level 3
76 * - slot 0: MACE
77 *
78 * 4 - PSC level 4
79 * - slot 1: SCC channel A interrupt
80 * - slot 2: SCC channel B interrupt
81 * - slot 3: MACE DMA
82 *
83 * 5 - PSC level 5
84 *
85 * 6 - PSC level 6
86 *
87 * Finally we have good 'ole level 7, the non-maskable interrupt:
88 *
89 * 7 - NMI (programmer's switch on the back of some Macs)
90 * Also RAM parity error on models which support it (IIc, IIfx?)
91 *
92 * The current interrupt logic looks something like this:
93 *
94 * - We install dispatchers for the autovector interrupts (1-7). These
95 * dispatchers are responsible for querying the hardware (the
96 * VIA/RBV/OSS/PSC chips) to determine the actual interrupt source. Using
97 * this information a machspec interrupt number is generated by placing the
98 * index of the interrupt hardware into the low three bits and the original
99 * autovector interrupt number in the upper 5 bits. The handlers for the
100 * resulting machspec interrupt are then called.
101 *
102 * - Nubus is a special case because its interrupts are hidden behind two
103 * layers of hardware. Nubus interrupts come in as index 1 on VIA #2,
104 * which translates to IRQ number 17. In this spot we install _another_
105 * dispatcher. This dispatcher finds the interrupting slot number (9-F) and
106 * then forms a new machspec interrupt number as above with the slot number
107 * minus 9 in the low three bits and the pseudo-level 7 in the upper five
108 * bits. The handlers for this new machspec interrupt number are then
109 * called. This puts Nubus interrupts into the range 56-62.
110 *
111 * - The Baboon interrupts (used on some PowerBooks) are an even more special
112 * case. They're hidden behind the Nubus slot $C interrupt thus adding a
113 * third layer of indirection. Why oh why did the Apple engineers do that?
114 *
115 * - We support "fast" and "slow" handlers, just like the Amiga port. The
116 * fast handlers are called first and with all interrupts disabled. They
117 * are expected to execute quickly (hence the name). The slow handlers are
118 * called last with interrupts enabled and the interrupt level restored.
119 * They must therefore be reentrant.
120 *
121 * TODO:
122 *
123 */
124
125#include <linux/types.h>
126#include <linux/kernel.h>
127#include <linux/sched.h>
Finn Thained04c972011-10-24 01:11:15 +1100128#include <linux/interrupt.h>
129#include <linux/irq.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130#include <linux/delay.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132#include <asm/irq.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133#include <asm/macintosh.h>
Finn Thained04c972011-10-24 01:11:15 +1100134#include <asm/macints.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135#include <asm/mac_via.h>
136#include <asm/mac_psc.h>
Geert Uytterhoevenc85627f2008-12-21 12:03:37 +0100137#include <asm/mac_oss.h>
Finn Thained04c972011-10-24 01:11:15 +1100138#include <asm/mac_iop.h>
139#include <asm/mac_baboon.h>
140#include <asm/hwtest.h>
141#include <asm/irq_regs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143#define SHUTUP_SONIC
144
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 * console_loglevel determines NMI handler function
147 */
148
Al Viro2850bc22006-10-07 14:16:45 +0100149irqreturn_t mac_nmi_handler(int, void *);
150irqreturn_t mac_debug_handler(int, void *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151
152/* #define DEBUG_MACINTS */
153
Finn Thainc4af5da2011-10-24 01:11:17 +1100154static unsigned int mac_irq_startup(struct irq_data *);
155static void mac_irq_shutdown(struct irq_data *);
156
Geert Uytterhoevenc288bf22011-04-13 22:31:28 +0200157static struct irq_chip mac_irq_chip = {
Roman Zippel9c5f4af2006-06-25 05:47:04 -0700158 .name = "mac",
Geert Uytterhoevene8abf5e2011-04-17 22:53:04 +0200159 .irq_enable = mac_irq_enable,
160 .irq_disable = mac_irq_disable,
Finn Thainc4af5da2011-10-24 01:11:17 +1100161 .irq_startup = mac_irq_startup,
162 .irq_shutdown = mac_irq_shutdown,
Roman Zippel9c5f4af2006-06-25 05:47:04 -0700163};
164
Al Viro66a3f822007-07-20 04:33:28 +0100165void __init mac_init_IRQ(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167#ifdef DEBUG_MACINTS
168 printk("mac_init_IRQ(): Setting things up...\n");
169#endif
Geert Uytterhoevenedb34722011-06-01 11:15:21 +0200170 m68k_setup_irq_controller(&mac_irq_chip, handle_simple_irq, IRQ_USER,
Roman Zippel9c5f4af2006-06-25 05:47:04 -0700171 NUM_MAC_SOURCES - IRQ_USER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 /* Make sure the SONIC interrupt is cleared or things get ugly */
173#ifdef SHUTUP_SONIC
174 printk("Killing onboard sonic... ");
175 /* This address should hopefully be mapped already */
176 if (hwreg_present((void*)(0x50f0a000))) {
177 *(long *)(0x50f0a014) = 0x7fffL;
178 *(long *)(0x50f0a010) = 0L;
179 }
180 printk("Done.\n");
181#endif /* SHUTUP_SONIC */
182
183 /*
184 * Now register the handlers for the master IRQ handlers
185 * at levels 1-7. Most of the work is done elsewhere.
186 */
187
Roman Zippel9c5f4af2006-06-25 05:47:04 -0700188 if (oss_present)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 oss_register_interrupts();
Roman Zippel9c5f4af2006-06-25 05:47:04 -0700190 else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 via_register_interrupts();
Roman Zippel9c5f4af2006-06-25 05:47:04 -0700192 if (psc_present)
193 psc_register_interrupts();
194 if (baboon_present)
195 baboon_register_interrupts();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 iop_register_interrupts();
Geert Uytterhoeven92c3dd12008-12-30 14:02:27 +0100197 if (request_irq(IRQ_AUTO_7, mac_nmi_handler, 0, "NMI",
198 mac_nmi_handler))
199 pr_err("Couldn't register NMI\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200#ifdef DEBUG_MACINTS
201 printk("mac_init_IRQ(): Done!\n");
202#endif
203}
204
205/*
Finn Thain2690e212011-09-11 23:40:50 +1000206 * mac_irq_enable - enable an interrupt source
207 * mac_irq_disable - disable an interrupt source
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 *
209 * These routines are just dispatchers to the VIA/OSS/PSC routines.
210 */
211
Finn Thain2690e212011-09-11 23:40:50 +1000212void mac_irq_enable(struct irq_data *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213{
Finn Thain2690e212011-09-11 23:40:50 +1000214 int irq = data->irq;
Roman Zippel9c5f4af2006-06-25 05:47:04 -0700215 int irq_src = IRQ_SRC(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216
217 switch(irq_src) {
Roman Zippel9c5f4af2006-06-25 05:47:04 -0700218 case 1:
219 via_irq_enable(irq);
220 break;
221 case 2:
222 case 7:
223 if (oss_present)
224 oss_irq_enable(irq);
225 else
226 via_irq_enable(irq);
227 break;
228 case 3:
Roman Zippel9c5f4af2006-06-25 05:47:04 -0700229 case 5:
230 case 6:
231 if (psc_present)
232 psc_irq_enable(irq);
233 else if (oss_present)
234 oss_irq_enable(irq);
Finn Thain80614e52009-11-17 20:06:48 +1100235 break;
236 case 4:
237 if (psc_present)
238 psc_irq_enable(irq);
Roman Zippel9c5f4af2006-06-25 05:47:04 -0700239 break;
240 case 8:
241 if (baboon_present)
242 baboon_irq_enable(irq);
243 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 }
245}
246
Finn Thain2690e212011-09-11 23:40:50 +1000247void mac_irq_disable(struct irq_data *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248{
Finn Thain2690e212011-09-11 23:40:50 +1000249 int irq = data->irq;
Roman Zippel9c5f4af2006-06-25 05:47:04 -0700250 int irq_src = IRQ_SRC(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251
252 switch(irq_src) {
Roman Zippel9c5f4af2006-06-25 05:47:04 -0700253 case 1:
254 via_irq_disable(irq);
255 break;
256 case 2:
257 case 7:
258 if (oss_present)
259 oss_irq_disable(irq);
260 else
261 via_irq_disable(irq);
262 break;
263 case 3:
Roman Zippel9c5f4af2006-06-25 05:47:04 -0700264 case 5:
265 case 6:
266 if (psc_present)
267 psc_irq_disable(irq);
268 else if (oss_present)
269 oss_irq_disable(irq);
Finn Thain80614e52009-11-17 20:06:48 +1100270 break;
271 case 4:
272 if (psc_present)
273 psc_irq_disable(irq);
Roman Zippel9c5f4af2006-06-25 05:47:04 -0700274 break;
275 case 8:
276 if (baboon_present)
277 baboon_irq_disable(irq);
278 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 }
280}
281
Finn Thainc4af5da2011-10-24 01:11:17 +1100282static unsigned int mac_irq_startup(struct irq_data *data)
283{
284 int irq = data->irq;
285
286 if (IRQ_SRC(irq) == 7 && !oss_present)
287 via_nubus_irq_startup(irq);
288 else
289 mac_irq_enable(data);
290
291 return 0;
292}
293
294static void mac_irq_shutdown(struct irq_data *data)
295{
296 int irq = data->irq;
297
298 if (IRQ_SRC(irq) == 7 && !oss_present)
299 via_nubus_irq_shutdown(irq);
300 else
301 mac_irq_disable(data);
302}
303
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304static int num_debug[8];
305
Al Viro2850bc22006-10-07 14:16:45 +0100306irqreturn_t mac_debug_handler(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307{
308 if (num_debug[irq] < 10) {
309 printk("DEBUG: Unexpected IRQ %d\n", irq);
310 num_debug[irq]++;
311 }
312 return IRQ_HANDLED;
313}
314
315static int in_nmi;
316static volatile int nmi_hold;
317
Al Viro2850bc22006-10-07 14:16:45 +0100318irqreturn_t mac_nmi_handler(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319{
320 int i;
321 /*
322 * generate debug output on NMI switch if 'debug' kernel option given
323 * (only works with Penguin!)
324 */
325
326 in_nmi++;
327 for (i=0; i<100; i++)
328 udelay(1000);
329
330 if (in_nmi == 1) {
331 nmi_hold = 1;
332 printk("... pausing, press NMI to resume ...");
333 } else {
334 printk(" ok!\n");
335 nmi_hold = 0;
336 }
337
338 barrier();
339
340 while (nmi_hold == 1)
341 udelay(1000);
342
Roman Zippel9c5f4af2006-06-25 05:47:04 -0700343 if (console_loglevel >= 8) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344#if 0
Al Viro2850bc22006-10-07 14:16:45 +0100345 struct pt_regs *fp = get_irq_regs();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 show_state();
347 printk("PC: %08lx\nSR: %04x SP: %p\n", fp->pc, fp->sr, fp);
348 printk("d0: %08lx d1: %08lx d2: %08lx d3: %08lx\n",
349 fp->d0, fp->d1, fp->d2, fp->d3);
350 printk("d4: %08lx d5: %08lx a0: %08lx a1: %08lx\n",
351 fp->d4, fp->d5, fp->a0, fp->a1);
352
353 if (STACK_MAGIC != *(unsigned long *)current->kernel_stack_page)
354 printk("Corrupted stack page\n");
355 printk("Process %s (pid: %d, stackpage=%08lx)\n",
356 current->comm, current->pid, current->kernel_stack_page);
357 if (intr_count == 1)
358 dump_stack((struct frame *)fp);
359#else
360 /* printk("NMI "); */
361#endif
362 }
363 in_nmi--;
364 return IRQ_HANDLED;
365}