1 /*
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  *
37  *	4	- SCC (slot number determined by reading RR3 on the SSC itself)
38  *		  - slot 1: SCC channel A
39  *		  - slot 2: SCC channel B
40  *
41  *	5	- unused (?)
42  *		  [serial errors or special conditions seem to raise level 6
43  *		  interrupts on some models (LC4xx?)]
44  *
45  *	6	- off switch (?)
46  *
47  * For OSS Macintoshes (IIfx only at this point):
48  *
49  *	3	- Nubus interrupt
50  *		  - slot 0: Slot $9
51  *		  - slot 1: Slot $A
52  *		  - slot 2: Slot $B
53  *		  - slot 3: Slot $C
54  *		  - slot 4: Slot $D
55  *		  - slot 5: Slot $E
56  *
57  *	4	- SCC IOP
58  *		  - slot 1: SCC channel A
59  *		  - slot 2: SCC channel B
60  *
61  *	5	- ISM IOP (ADB?)
62  *
63  *	6	- unused
64  *
65  * For PSC Macintoshes (660AV, 840AV):
66  *
67  *	3	- PSC level 3
68  *		  - slot 0: MACE
69  *
70  *	4	- PSC level 4
71  *		  - slot 1: SCC channel A interrupt
72  *		  - slot 2: SCC channel B interrupt
73  *		  - slot 3: MACE DMA
74  *
75  *	5	- PSC level 5
76  *
77  *	6	- PSC level 6
78  *
79  * Finally we have good 'ole level 7, the non-maskable interrupt:
80  *
81  *	7	- NMI (programmer's switch on the back of some Macs)
82  *		  Also RAM parity error on models which support it (IIc, IIfx?)
83  *
84  * The current interrupt logic looks something like this:
85  *
86  * - We install dispatchers for the autovector interrupts (1-7). These
87  *   dispatchers are responsible for querying the hardware (the
88  *   VIA/RBV/OSS/PSC chips) to determine the actual interrupt source. Using
89  *   this information a machspec interrupt number is generated by placing the
90  *   index of the interrupt hardware into the low three bits and the original
91  *   autovector interrupt number in the upper 5 bits. The handlers for the
92  *   resulting machspec interrupt are then called.
93  *
94  * - Nubus is a special case because its interrupts are hidden behind two
95  *   layers of hardware. Nubus interrupts come in as index 1 on VIA #2,
96  *   which translates to IRQ number 17. In this spot we install _another_
97  *   dispatcher. This dispatcher finds the interrupting slot number (9-F) and
98  *   then forms a new machspec interrupt number as above with the slot number
99  *   minus 9 in the low three bits and the pseudo-level 7 in the upper five
100  *   bits.  The handlers for this new machspec interrupt number are then
101  *   called. This puts Nubus interrupts into the range 56-62.
102  *
103  * - The Baboon interrupts (used on some PowerBooks) are an even more special
104  *   case. They're hidden behind the Nubus slot $C interrupt thus adding a
105  *   third layer of indirection. Why oh why did the Apple engineers do that?
106  *
107  * - We support "fast" and "slow" handlers, just like the Amiga port. The
108  *   fast handlers are called first and with all interrupts disabled. They
109  *   are expected to execute quickly (hence the name). The slow handlers are
110  *   called last with interrupts enabled and the interrupt level restored.
111  *   They must therefore be reentrant.
112  *
113  *   TODO:
114  *
115  */
116 
117 #include <linux/types.h>
118 #include <linux/kernel.h>
119 #include <linux/sched.h>
120 #include <linux/kernel_stat.h>
121 #include <linux/interrupt.h> /* for intr_count */
122 #include <linux/delay.h>
123 
124 #include <asm/system.h>
125 #include <asm/irq.h>
126 #include <asm/traps.h>
127 #include <asm/bootinfo.h>
128 #include <asm/machw.h>
129 #include <asm/macintosh.h>
130 #include <asm/mac_via.h>
131 #include <asm/mac_psc.h>
132 #include <asm/hwtest.h>
133 
134 #include <asm/macints.h>
135 
136 #define DEBUG_SPURIOUS
137 #define SHUTUP_SONIC
138 
139 /*
140  * The mac_irq_list array is an array of linked lists of irq_node_t nodes.
141  * Each node contains one handler to be called whenever the interrupt
142  * occurs, with fast handlers listed before slow handlers.
143  */
144 
145 irq_node_t *mac_irq_list[NUM_MAC_SOURCES];
146 
147 /* SCC interrupt mask */
148 
149 static int scc_mask;
150 
151 /*
152  * VIA/RBV hooks
153  */
154 
155 extern void via_init(void);
156 extern void via_register_interrupts(void);
157 extern void via_irq_enable(int);
158 extern void via_irq_disable(int);
159 extern void via_irq_clear(int);
160 extern int  via_irq_pending(int);
161 
162 /*
163  * OSS hooks
164  */
165 
166 extern int oss_present;
167 
168 extern void oss_init(void);
169 extern void oss_register_interrupts(void);
170 extern void oss_irq_enable(int);
171 extern void oss_irq_disable(int);
172 extern void oss_irq_clear(int);
173 extern int  oss_irq_pending(int);
174 
175 /*
176  * PSC hooks
177  */
178 
179 extern int psc_present;
180 
181 extern void psc_init(void);
182 extern void psc_register_interrupts(void);
183 extern void psc_irq_enable(int);
184 extern void psc_irq_disable(int);
185 extern void psc_irq_clear(int);
186 extern int  psc_irq_pending(int);
187 
188 /*
189  * IOP hooks
190  */
191 
192 extern void iop_register_interrupts(void);
193 
194 /*
195  * Baboon hooks
196  */
197 
198 extern int baboon_present;
199 
200 extern void baboon_init(void);
201 extern void baboon_register_interrupts(void);
202 extern void baboon_irq_enable(int);
203 extern void baboon_irq_disable(int);
204 extern void baboon_irq_clear(int);
205 extern int  baboon_irq_pending(int);
206 
207 /*
208  * SCC interrupt routines
209  */
210 
211 static void scc_irq_enable(int);
212 static void scc_irq_disable(int);
213 
214 /*
215  * console_loglevel determines NMI handler function
216  */
217 
218 extern void mac_bang(int, void *, struct pt_regs *);
219 
220 void mac_nmi_handler(int, void *, struct pt_regs *);
221 void mac_debug_handler(int, void *, struct pt_regs *);
222 
223 /* #define DEBUG_MACINTS */
224 
mac_init_IRQ(void)225 void mac_init_IRQ(void)
226 {
227         int i;
228 
229 #ifdef DEBUG_MACINTS
230 	printk("mac_init_IRQ(): Setting things up...\n");
231 #endif
232 	/* Initialize the IRQ handler lists. Initially each list is empty, */
233 
234 	for (i = 0; i < NUM_MAC_SOURCES; i++) {
235 		mac_irq_list[i] = NULL;
236 	}
237 
238 	scc_mask = 0;
239 
240 	/* Make sure the SONIC interrupt is cleared or things get ugly */
241 #ifdef SHUTUP_SONIC
242 	printk("Killing onboard sonic... ");
243 	/* This address should hopefully be mapped already */
244 	if (hwreg_present((void*)(0x50f0a000))) {
245 		*(long *)(0x50f0a014) = 0x7fffL;
246 		*(long *)(0x50f0a010) = 0L;
247 	}
248 	printk("Done.\n");
249 #endif /* SHUTUP_SONIC */
250 
251 	/*
252 	 * Now register the handlers for the master IRQ handlers
253 	 * at levels 1-7. Most of the work is done elsewhere.
254 	 */
255 
256 	if (oss_present) {
257 		oss_register_interrupts();
258 	} else {
259 		via_register_interrupts();
260 	}
261 	if (psc_present) psc_register_interrupts();
262 	if (baboon_present) baboon_register_interrupts();
263 	iop_register_interrupts();
264 	sys_request_irq(7, mac_nmi_handler, IRQ_FLG_LOCK, "NMI", mac_nmi_handler);
265 #ifdef DEBUG_MACINTS
266 	printk("mac_init_IRQ(): Done!\n");
267 #endif
268 }
269 
270 /*
271  * Routines to work with irq_node_t's on linked lists lifted from
272  * the Amiga code written by Roman Zippel.
273  */
274 
mac_insert_irq(irq_node_t ** list,irq_node_t * node)275 static inline void mac_insert_irq(irq_node_t **list, irq_node_t *node)
276 {
277 	unsigned long cpu_flags;
278 	irq_node_t *cur;
279 
280 	if (!node->dev_id)
281 		printk("%s: Warning: dev_id of %s is zero\n",
282 		       __FUNCTION__, node->devname);
283 
284 	save_flags(cpu_flags);
285 	cli();
286 
287 	cur = *list;
288 
289 	if (node->flags & IRQ_FLG_FAST) {
290 		node->flags &= ~IRQ_FLG_SLOW;
291 		while (cur && cur->flags & IRQ_FLG_FAST) {
292 			list = &cur->next;
293 			cur = cur->next;
294 		}
295 	} else if (node->flags & IRQ_FLG_SLOW) {
296 		while (cur) {
297 			list = &cur->next;
298 			cur = cur->next;
299 		}
300 	} else {
301 		while (cur && !(cur->flags & IRQ_FLG_SLOW)) {
302 			list = &cur->next;
303 			cur = cur->next;
304 		}
305 	}
306 
307 	node->next = cur;
308 	*list = node;
309 
310 	restore_flags(cpu_flags);
311 }
312 
mac_delete_irq(irq_node_t ** list,void * dev_id)313 static inline void mac_delete_irq(irq_node_t **list, void *dev_id)
314 {
315 	unsigned long cpu_flags;
316 	irq_node_t *node;
317 
318 	save_flags(cpu_flags);
319 	cli();
320 
321 	for (node = *list; node; list = &node->next, node = *list) {
322 		if (node->dev_id == dev_id) {
323 			*list = node->next;
324 			/* Mark it as free. */
325 			node->handler = NULL;
326 			restore_flags(cpu_flags);
327 			return;
328 		}
329 	}
330 	restore_flags(cpu_flags);
331 	printk ("%s: tried to remove invalid irq\n", __FUNCTION__);
332 }
333 
334 /*
335  * Call all the handlers for a given interrupt. Fast handlers are called
336  * first followed by slow handlers.
337  *
338  * This code taken from the original Amiga code written by Roman Zippel.
339  */
340 
mac_do_irq_list(int irq,struct pt_regs * fp)341 void mac_do_irq_list(int irq, struct pt_regs *fp)
342 {
343 	irq_node_t *node, *slow_nodes;
344 	unsigned long cpu_flags;
345 
346 	kstat.irqs[0][irq]++;
347 
348 #ifdef DEBUG_SPURIOUS
349 	if (!mac_irq_list[irq] && (console_loglevel > 7)) {
350 		printk("mac_do_irq_list: spurious interrupt %d!\n", irq);
351 		return;
352 	}
353 #endif
354 
355 	/* serve first fast and normal handlers */
356 	for (node = mac_irq_list[irq];
357 	     node && (!(node->flags & IRQ_FLG_SLOW));
358 	     node = node->next)
359 		node->handler(irq, node->dev_id, fp);
360 	if (!node) return;
361 	save_flags(cpu_flags);
362 	restore_flags((cpu_flags & ~0x0700) | (fp->sr & 0x0700));
363 	/* if slow handlers exists, serve them now */
364 	slow_nodes = node;
365 	for (; node; node = node->next) {
366 		node->handler(irq, node->dev_id, fp);
367 	}
368 }
369 
370 /*
371  *  mac_enable_irq - enable an interrupt source
372  * mac_disable_irq - disable an interrupt source
373  *   mac_clear_irq - clears a pending interrupt
374  * mac_pending_irq - Returns the pending status of an IRQ (nonzero = pending)
375  *
376  * These routines are just dispatchers to the VIA/OSS/PSC routines.
377  */
378 
mac_enable_irq(unsigned int irq)379 void mac_enable_irq (unsigned int irq)
380 {
381 	int irq_src	= IRQ_SRC(irq);
382 
383 	switch(irq_src) {
384 		case 1: via_irq_enable(irq);
385 			break;
386 		case 2:
387 		case 7: if (oss_present) {
388 				oss_irq_enable(irq);
389 			} else {
390 				via_irq_enable(irq);
391 			}
392 			break;
393 		case 3:
394 		case 4:
395 		case 5:
396 		case 6: if (psc_present) {
397 				psc_irq_enable(irq);
398 			} else if (oss_present) {
399 				oss_irq_enable(irq);
400 			} else if (irq_src == 4) {
401 				scc_irq_enable(irq);
402 			}
403 			break;
404 		case 8: if (baboon_present) {
405 				baboon_irq_enable(irq);
406 			}
407 			break;
408 	}
409 }
410 
mac_disable_irq(unsigned int irq)411 void mac_disable_irq (unsigned int irq)
412 {
413 	int irq_src	= IRQ_SRC(irq);
414 
415 	switch(irq_src) {
416 		case 1: via_irq_disable(irq);
417 			break;
418 		case 2:
419 		case 7: if (oss_present) {
420 				oss_irq_disable(irq);
421 			} else {
422 				via_irq_disable(irq);
423 			}
424 			break;
425 		case 3:
426 		case 4:
427 		case 5:
428 		case 6: if (psc_present) {
429 				psc_irq_disable(irq);
430 			} else if (oss_present) {
431 				oss_irq_disable(irq);
432 			} else if (irq_src == 4) {
433 				scc_irq_disable(irq);
434 			}
435 			break;
436 		case 8: if (baboon_present) {
437 				baboon_irq_disable(irq);
438 			}
439 			break;
440 	}
441 }
442 
mac_clear_irq(unsigned int irq)443 void mac_clear_irq( unsigned int irq )
444 {
445 	switch(IRQ_SRC(irq)) {
446 		case 1: via_irq_clear(irq);
447 			break;
448 		case 2:
449 		case 7: if (oss_present) {
450 				oss_irq_clear(irq);
451 			} else {
452 				via_irq_clear(irq);
453 			}
454 			break;
455 		case 3:
456 		case 4:
457 		case 5:
458 		case 6: if (psc_present) {
459 				psc_irq_clear(irq);
460 			} else if (oss_present) {
461 				oss_irq_clear(irq);
462 			}
463 			break;
464 		case 8: if (baboon_present) {
465 				baboon_irq_clear(irq);
466 			}
467 			break;
468 	}
469 }
470 
mac_irq_pending(unsigned int irq)471 int mac_irq_pending( unsigned int irq )
472 {
473 	switch(IRQ_SRC(irq)) {
474 		case 1: return via_irq_pending(irq);
475 		case 2:
476 		case 7: if (oss_present) {
477 				return oss_irq_pending(irq);
478 			} else {
479 				return via_irq_pending(irq);
480 			}
481 		case 3:
482 		case 4:
483 		case 5:
484 		case 6: if (psc_present) {
485 				return psc_irq_pending(irq);
486 			} else if (oss_present) {
487 				return oss_irq_pending(irq);
488 			}
489 	}
490 	return 0;
491 }
492 
493 /*
494  * Add an interrupt service routine to an interrupt source.
495  * Returns 0 on success.
496  *
497  * FIXME: You can register interrupts on nonexistent source (ie PSC4 on a
498  *        non-PSC machine). We should return -EINVAL in those cases.
499  */
500 
mac_request_irq(unsigned int irq,void (* handler)(int,void *,struct pt_regs *),unsigned long flags,const char * devname,void * dev_id)501 int mac_request_irq(unsigned int irq,
502 		    void (*handler)(int, void *, struct pt_regs *),
503 		    unsigned long flags, const char *devname, void *dev_id)
504 {
505 	irq_node_t *node;
506 
507 #ifdef DEBUG_MACINTS
508 	printk ("%s: irq %d requested for %s\n", __FUNCTION__, irq, devname);
509 #endif
510 
511 	if (irq < VIA1_SOURCE_BASE) {
512 		return sys_request_irq(irq, handler, flags, devname, dev_id);
513 	}
514 
515 	if (irq >= NUM_MAC_SOURCES) {
516 		printk ("%s: unknown irq %d requested by %s\n",
517 		        __FUNCTION__, irq, devname);
518 	}
519 
520 	/* Get a node and stick it onto the right list */
521 
522 	if (!(node = new_irq_node())) return -ENOMEM;
523 
524 	node->handler	= handler;
525 	node->flags	= flags;
526 	node->dev_id	= dev_id;
527 	node->devname	= devname;
528 	node->next	= NULL;
529 	mac_insert_irq(&mac_irq_list[irq], node);
530 
531 	/* Now enable the IRQ source */
532 
533 	mac_enable_irq(irq);
534 
535 	return 0;
536 }
537 
538 /*
539  * Removes an interrupt service routine from an interrupt source.
540  */
541 
mac_free_irq(unsigned int irq,void * dev_id)542 void mac_free_irq(unsigned int irq, void *dev_id)
543 {
544 #ifdef DEBUG_MACINTS
545 	printk ("%s: irq %d freed by %p\n", __FUNCTION__, irq, dev_id);
546 #endif
547 
548 	if (irq < VIA1_SOURCE_BASE) {
549 		return sys_free_irq(irq, dev_id);
550 	}
551 
552 	if (irq >= NUM_MAC_SOURCES) {
553 		printk ("%s: unknown irq %d freed\n",
554 		        __FUNCTION__, irq);
555 		return;
556 	}
557 
558 	mac_delete_irq(&mac_irq_list[irq], dev_id);
559 
560 	/* If the list for this interrupt is */
561 	/* empty then disable the source.    */
562 
563 	if (!mac_irq_list[irq]) {
564 		mac_disable_irq(irq);
565 	}
566 }
567 
568 /*
569  * Generate a pretty listing for /proc/interrupts
570  *
571  * By the time we're called the autovector interrupt list has already been
572  * generated, so we just need to do the machspec interrupts.
573  *
574  * 990506 (jmt) - rewritten to handle chained machspec interrupt handlers.
575  *                Also removed display of num_spurious it is already
576  *		  displayed for us as autovector irq 0.
577  */
578 
mac_get_irq_list(char * buf)579 int mac_get_irq_list (char *buf)
580 {
581 	int i, len = 0;
582 	irq_node_t *node;
583 	char *base;
584 
585 	/* Don't do Nubus interrupts in this loop; we do them separately  */
586 	/* below so that we can print slot numbers instead of IRQ numbers */
587 
588 	for (i = VIA1_SOURCE_BASE ; i < NUM_MAC_SOURCES ; ++i) {
589 
590 		/* Nonexistant interrupt or nothing registered; skip it. */
591 
592 		if ((node = mac_irq_list[i]) == NULL) continue;
593 		if (node->flags & IRQ_FLG_STD) continue;
594 
595 		base = "";
596 		switch(IRQ_SRC(i)) {
597 			case 1: base = "via1";
598 				break;
599 			case 2: if (oss_present) {
600 					base = "oss";
601 				} else {
602 					base = "via2";
603 				}
604 				break;
605 			case 3:
606 			case 4:
607 			case 5:
608 			case 6: if (psc_present) {
609 					base = "psc";
610 				} else if (oss_present) {
611 					base = "oss";
612 				} else {
613 					if (IRQ_SRC(i) == 4) base = "scc";
614 				}
615 				break;
616 			case 7: base = "nbus";
617 				break;
618 			case 8: base = "bbn";
619 				break;
620 		}
621 		len += sprintf(buf+len, "%4s %2d: %10u ",
622 				base, i, kstat.irqs[0][i]);
623 
624 		do {
625 			if (node->flags & IRQ_FLG_FAST) {
626 				len += sprintf(buf+len, "F ");
627 			} else if (node->flags & IRQ_FLG_SLOW) {
628 				len += sprintf(buf+len, "S ");
629 			} else {
630 				len += sprintf(buf+len, "  ");
631 			}
632 			len += sprintf(buf+len, "%s\n", node->devname);
633 			if ((node = node->next)) {
634 				len += sprintf(buf+len, "                    ");
635 			}
636 		} while(node);
637 
638 	}
639 	return len;
640 }
641 
mac_default_handler(int irq,void * dev_id,struct pt_regs * regs)642 void mac_default_handler(int irq, void *dev_id, struct pt_regs *regs)
643 {
644 #ifdef DEBUG_SPURIOUS
645 	printk("Unexpected IRQ %d on device %p\n", irq, dev_id);
646 #endif
647 }
648 
649 static int num_debug[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
650 
mac_debug_handler(int irq,void * dev_id,struct pt_regs * regs)651 void mac_debug_handler(int irq, void *dev_id, struct pt_regs *regs)
652 {
653 	if (num_debug[irq] < 10) {
654 		printk("DEBUG: Unexpected IRQ %d\n", irq);
655 		num_debug[irq]++;
656 	}
657 }
658 
659 static int in_nmi = 0;
660 static volatile int nmi_hold = 0;
661 
mac_nmi_handler(int irq,void * dev_id,struct pt_regs * fp)662 void mac_nmi_handler(int irq, void *dev_id, struct pt_regs *fp)
663 {
664 	int i;
665 	/*
666 	 * generate debug output on NMI switch if 'debug' kernel option given
667 	 * (only works with Penguin!)
668 	 */
669 
670 	in_nmi++;
671 	for (i=0; i<100; i++)
672 		udelay(1000);
673 
674 	if (in_nmi == 1) {
675 		nmi_hold = 1;
676 		printk("... pausing, press NMI to resume ...");
677 	} else {
678 		printk(" ok!\n");
679 		nmi_hold = 0;
680 	}
681 
682 	barrier();
683 
684 	while (nmi_hold == 1)
685 		udelay(1000);
686 
687 	if ( console_loglevel >= 8 ) {
688 #if 0
689 		show_state();
690 		printk("PC: %08lx\nSR: %04x  SP: %p\n", fp->pc, fp->sr, fp);
691 		printk("d0: %08lx    d1: %08lx    d2: %08lx    d3: %08lx\n",
692 		       fp->d0, fp->d1, fp->d2, fp->d3);
693 		printk("d4: %08lx    d5: %08lx    a0: %08lx    a1: %08lx\n",
694 		       fp->d4, fp->d5, fp->a0, fp->a1);
695 
696 		if (STACK_MAGIC != *(unsigned long *)current->kernel_stack_page)
697 			printk("Corrupted stack page\n");
698 		printk("Process %s (pid: %d, stackpage=%08lx)\n",
699 			current->comm, current->pid, current->kernel_stack_page);
700 		if (intr_count == 1)
701 			dump_stack((struct frame *)fp);
702 #else
703 		/* printk("NMI "); */
704 #endif
705 	}
706 	in_nmi--;
707 }
708 
709 /*
710  * Simple routines for masking and unmasking
711  * SCC interrupts in cases where this can't be
712  * done in hardware (only the PSC can do that.)
713  */
714 
scc_irq_enable(int irq)715 static void scc_irq_enable(int irq) {
716 	int irq_idx     = IRQ_IDX(irq);
717 
718 	scc_mask |= (1 << irq_idx);
719 }
720 
scc_irq_disable(int irq)721 static void scc_irq_disable(int irq) {
722 	int irq_idx     = IRQ_IDX(irq);
723 
724 	scc_mask &= ~(1 << irq_idx);
725 }
726 
727 /*
728  * SCC master interrupt handler. We have to do a bit of magic here
729  * to figure out what channel gave us the interrupt; putting this
730  * here is cleaner than hacking it into drivers/char/macserial.c.
731  */
732 
mac_scc_dispatch(int irq,void * dev_id,struct pt_regs * regs)733 void mac_scc_dispatch(int irq, void *dev_id, struct pt_regs *regs)
734 {
735 	volatile unsigned char *scc = (unsigned char *) mac_bi_data.sccbase + 2;
736 	unsigned char reg;
737 	unsigned long cpu_flags;
738 
739 	/* Read RR3 from the chip. Always do this on channel A */
740 	/* This must be an atomic operation so disable irqs.   */
741 
742 	save_flags(cpu_flags); cli();
743 	*scc = 3;
744 	reg = *scc;
745 	restore_flags(cpu_flags);
746 
747 	/* Now dispatch. Bits 0-2 are for channel B and */
748 	/* bits 3-5 are for channel A. We can safely    */
749 	/* ignore the remaining bits here.              */
750 	/*                                              */
751 	/* Note that we're ignoring scc_mask for now.   */
752 	/* If we actually mask the ints then we tend to */
753 	/* get hammered by very persistant SCC irqs,    */
754 	/* and since they're autovector interrupts they */
755 	/* pretty much kill the system.                 */
756 
757 	if (reg & 0x38) mac_do_irq_list(IRQ_SCCA, regs);
758 	if (reg & 0x07) mac_do_irq_list(IRQ_SCCB, regs);
759 }
760