Import 2.1.81
[davej-history.git] / arch / alpha / kernel / irq.c
blobf94915bb29a4b9bb9418178be751460a3d09c9ad
1 /*
2 * linux/arch/alpha/kernel/irq.c
4 * Copyright (C) 1995 Linus Torvalds
6 * This file contains the code used by various IRQ handling routines:
7 * asking for different IRQ's should be done through these routines
8 * instead of just grabbing them. Thus setups with different IRQ numbers
9 * shouldn't result in any weird surprises, and installing new handlers
10 * should be easier.
13 #include <linux/config.h>
14 #include <linux/ptrace.h>
15 #include <linux/errno.h>
16 #include <linux/kernel_stat.h>
17 #include <linux/signal.h>
18 #include <linux/sched.h>
19 #include <linux/interrupt.h>
20 #include <linux/malloc.h>
21 #include <linux/random.h>
23 #include <asm/system.h>
24 #include <asm/io.h>
25 #include <asm/irq.h>
26 #include <asm/bitops.h>
27 #include <asm/dma.h>
29 #define vulp volatile unsigned long *
30 #define vuip volatile unsigned int *
32 #define RTC_IRQ 8
33 #ifdef CONFIG_RTC
34 #define TIMER_IRQ 0 /* timer is the pit */
35 #else
36 #define TIMER_IRQ RTC_IRQ /* the timer is, in fact, the rtc */
37 #endif
39 #if NR_IRQS > 64
40 # error Unable to handle more than 64 irq levels.
41 #endif
43 /* PROBE_MASK is the bitset of irqs that we consider for autoprobing: */
44 #if defined(CONFIG_ALPHA_P2K)
45 /* always mask out unused timer irq 0 and RTC irq 8 */
46 # define PROBE_MASK (((1UL << NR_IRQS) - 1) & ~0x101UL)
47 #elif defined(CONFIG_ALPHA_ALCOR)
48 /* always mask out unused timer irq 0, "irqs" 20-30, and the EISA cascade: */
49 # define PROBE_MASK (((1UL << NR_IRQS) - 1) & ~0xfff000000001UL)
50 #else
51 /* always mask out unused timer irq 0: */
52 # define PROBE_MASK (((1UL << NR_IRQS) - 1) & ~1UL)
53 #endif
55 /* Reserved interrupts. These must NEVER be requested by any driver!
57 #define IS_RESERVED_IRQ(irq) ((irq)==2) /* IRQ 2 used by hw cascade */
60 * Shadow-copy of masked interrupts.
61 * The bits are used as follows:
62 * 0.. 7 first (E)ISA PIC (irq level 0..7)
63 * 8..15 second (E)ISA PIC (irq level 8..15)
64 * Systems with PCI interrupt lines managed by GRU (e.g., Alcor, XLT)
65 * or PYXIS (e.g. Miata, PC164-LX):
66 * 16..47 PCI interrupts 0..31 (int at xxx_INT_MASK)
67 * Mikasa:
68 * 16..31 PCI interrupts 0..15 (short at I/O port 536)
69 * Other systems (not Mikasa) with 16 PCI interrupt lines:
70 * 16..23 PCI interrupts 0.. 7 (char at I/O port 26)
71 * 24..31 PCI interrupts 8..15 (char at I/O port 27)
72 * Systems with 17 PCI interrupt lines (e.g., Cabriolet and eb164):
73 * 16..32 PCI interrupts 0..31 (int at I/O port 804)
74 * For SABLE, which is really baroque, we manage 40 IRQ's, but the
75 * hardware really only supports 24, not via normal ISA PIC,
76 * but cascaded custom 8259's, etc.
77 * 0-7 (char at 536)
78 * 8-15 (char at 53a)
79 * 16-23 (char at 53c)
81 static unsigned long irq_mask = ~0UL;
83 #ifdef CONFIG_ALPHA_SABLE
85 * Note that the vector reported by the SRM PALcode corresponds to the
86 * interrupt mask bits, but we have to manage via more normal IRQs.
88 * We have to be able to go back and forth between MASK bits and IRQ:
89 * these tables help us do so.
91 static char sable_irq_to_mask[NR_IRQS] = {
92 -1, 6, -1, 8, 15, 12, 7, 9, /* pseudo PIC 0-7 */
93 -1, 16, 17, 18, 3, -1, 21, 22, /* pseudo PIC 8-15 */
94 -1, -1, -1, -1, -1, -1, -1, -1, /* pseudo EISA 0-7 */
95 -1, -1, -1, -1, -1, -1, -1, -1, /* pseudo EISA 8-15 */
96 2, 1, 0, 4, 5, -1, -1, -1, /* pseudo PCI */
98 #define IRQ_TO_MASK(irq) (sable_irq_to_mask[(irq)])
99 static char sable_mask_to_irq[NR_IRQS] = {
100 34, 33, 32, 12, 35, 36, 1, 6, /* mask 0-7 */
101 3, 7, -1, -1, 5, -1, -1, 4, /* mask 8-15 */
102 9, 10, 11, -1, -1, 14, 15, -1, /* mask 16-23 */
104 #else /* CONFIG_ALPHA_SABLE */
105 #define IRQ_TO_MASK(irq) (irq)
106 #endif /* CONFIG_ALPHA_SABLE */
109 * Update the hardware with the irq mask passed in MASK. The function
110 * exploits the fact that it is known that only bit IRQ has changed.
113 static inline void
114 sable_update_hw(unsigned long irq, unsigned long mask)
116 /* The "irq" argument is really the mask bit number */
117 switch (irq) {
118 default: /* 16 ... 23 */
119 outb(mask >> 16, 0x53d);
120 break;
121 case 8 ... 15:
122 outb(mask >> 8, 0x53b);
123 break;
124 case 0 ... 7:
125 outb(mask, 0x537);
126 break;
130 static inline void
131 noritake_update_hw(unsigned long irq, unsigned long mask)
133 switch (irq) {
134 default: /* 32 ... 47 */
135 outw(~(mask >> 32), 0x54c);
136 break;
137 case 16 ... 31:
138 outw(~(mask >> 16), 0x54a);
139 break;
140 case 8 ... 15: /* ISA PIC2 */
141 outb(mask >> 8, 0xA1);
142 break;
143 case 0 ... 7: /* ISA PIC1 */
144 outb(mask, 0x21);
145 break;
149 #ifdef CONFIG_ALPHA_MIATA
150 static inline void
151 miata_update_hw(unsigned long irq, unsigned long mask)
153 switch (irq) {
154 default: /* 16 ... 47 */
155 /* Make CERTAIN none of the bogus ints get enabled... */
156 *(vulp)PYXIS_INT_MASK =
157 ~((long)mask >> 16) & ~0x4000000000000e3bUL;
158 mb();
159 /* ... and read it back to make sure it got written. */
160 *(vulp)PYXIS_INT_MASK;
161 break;
162 case 8 ... 15: /* ISA PIC2 */
163 outb(mask >> 8, 0xA1);
164 break;
165 case 0 ... 7: /* ISA PIC1 */
166 outb(mask, 0x21);
167 break;
170 #endif
172 #if defined(CONFIG_ALPHA_ALCOR) || defined(CONFIG_ALPHA_XLT)
173 static inline void
174 alcor_and_xlt_update_hw(unsigned long irq, unsigned long mask)
176 switch (irq) {
177 default: /* 16 ... 47 */
178 /* On Alcor, at least, lines 20..30 are not connected and can
179 generate spurrious interrupts if we turn them on while IRQ
180 probing. So explicitly mask them out. */
181 mask |= 0x7ff000000000UL;
183 /* Note inverted sense of mask bits: */
184 *(vuip)GRU_INT_MASK = ~(mask >> 16);
185 mb();
186 break;
187 case 8 ... 15: /* ISA PIC2 */
188 outb(mask >> 8, 0xA1);
189 break;
190 case 0 ... 7: /* ISA PIC1 */
191 outb(mask, 0x21);
192 break;
195 #endif
197 static inline void
198 mikasa_update_hw(unsigned long irq, unsigned long mask)
200 switch (irq) {
201 default: /* 16 ... 31 */
202 outw(~(mask >> 16), 0x536); /* note invert */
203 break;
204 case 8 ... 15: /* ISA PIC2 */
205 outb(mask >> 8, 0xA1);
206 break;
207 case 0 ... 7: /* ISA PIC1 */
208 outb(mask, 0x21);
209 break;
213 /* Unlabeled mechanisms based on the number of irqs. Someone should
214 probably document and name these. */
216 static inline void
217 update_hw_33(unsigned long irq, unsigned long mask)
219 switch (irq) {
220 default: /* 16 ... 32 */
221 outl(mask >> 16, 0x804);
222 break;
224 case 8 ... 15: /* ISA PIC2 */
225 outb(mask >> 8, 0xA1);
226 break;
227 case 0 ... 7: /* ISA PIC1 */
228 outb(mask, 0x21);
229 break;
233 static inline void
234 update_hw_32(unsigned long irq, unsigned long mask)
236 switch (irq) {
237 default: /* 24 ... 31 */
238 outb(mask >> 24, 0x27);
239 break;
240 case 16 ... 23:
241 outb(mask >> 16, 0x26);
242 break;
243 case 8 ... 15: /* ISA PIC2 */
244 outb(mask >> 8, 0xA1);
245 break;
246 case 0 ... 7: /* ISA PIC1 */
247 outb(mask, 0x21);
248 break;
252 static inline void
253 update_hw_16(unsigned long irq, unsigned long mask)
255 switch (irq) {
256 default: /* 8 ... 15, ISA PIC2 */
257 outb(mask >> 8, 0xA1);
258 break;
259 case 0 ... 7: /* ISA PIC1 */
260 outb(mask, 0x21);
261 break;
265 #if defined(CONFIG_ALPHA_PC164) && defined(CONFIG_ALPHA_SRM)
267 * On the pc164, we cannot take over the IRQs from the SRM,
268 * so we call down to do our dirty work. Too bad the SRM
269 * isn't consistent across platforms otherwise we could do
270 * this always.
273 extern void cserve_ena(unsigned long);
274 extern void cserve_dis(unsigned long);
276 static inline void mask_irq(unsigned long irq)
278 irq_mask |= (1UL << irq);
279 cserve_dis(irq - 16);
282 static inline void unmask_irq(unsigned long irq)
284 irq_mask &= ~(1UL << irq);
285 cserve_ena(irq - 16);
288 /* Since we are calling down to PALcode, no need to diddle IPL. */
289 void disable_irq(unsigned int irq_nr)
291 mask_irq(IRQ_TO_MASK(irq_nr));
294 void enable_irq(unsigned int irq_nr)
296 unmask_irq(IRQ_TO_MASK(irq_nr));
299 #else
301 * We manipulate the hardware ourselves.
304 static void update_hw(unsigned long irq, unsigned long mask)
306 #if defined(CONFIG_ALPHA_SABLE)
307 sable_update_hw(irq, mask);
308 #elif defined(CONFIG_ALPHA_MIATA)
309 miata_update_hw(irq, mask);
310 #elif defined(CONFIG_ALPHA_NORITAKE)
311 noritake_update_hw(irq, mask);
312 #elif defined(CONFIG_ALPHA_ALCOR) || defined(CONFIG_ALPHA_XLT)
313 alcor_and_xlt_update_hw(irq, mask);
314 #elif defined(CONFIG_ALPHA_MIKASA)
315 mikasa_update_hw(irq, mask);
316 #elif NR_IRQS == 33
317 update_hw_33(irq, mask);
318 #elif NR_IRQS == 32
319 update_hw_32(irq, mask);
320 #elif NR_IRQS == 16
321 update_hw_16(irq, mask);
322 #else
323 #error "How do I update the IRQ hardware?"
324 #endif
327 static inline void mask_irq(unsigned long irq)
329 irq_mask |= (1UL << irq);
330 update_hw(irq, irq_mask);
333 static inline void unmask_irq(unsigned long irq)
335 irq_mask &= ~(1UL << irq);
336 update_hw(irq, irq_mask);
339 void disable_irq(unsigned int irq_nr)
341 unsigned long flags;
343 save_flags(flags);
344 cli();
345 mask_irq(IRQ_TO_MASK(irq_nr));
346 restore_flags(flags);
349 void enable_irq(unsigned int irq_nr)
351 unsigned long flags;
353 save_flags(flags);
354 cli();
355 unmask_irq(IRQ_TO_MASK(irq_nr));
356 restore_flags(flags);
358 #endif /* PC164 && SRM */
361 * Initial irq handlers.
363 static struct irqaction timer_irq = { NULL, 0, 0, NULL, NULL, NULL};
364 static struct irqaction *irq_action[NR_IRQS];
366 int get_irq_list(char *buf)
368 int i, len = 0;
369 struct irqaction * action;
371 for (i = 0; i < NR_IRQS; i++) {
372 action = irq_action[i];
373 if (!action)
374 continue;
375 len += sprintf(buf+len, "%2d: %10u %c %s",
376 i, kstat.interrupts[0][i],
377 (action->flags & SA_INTERRUPT) ? '+' : ' ',
378 action->name);
379 for (action=action->next; action; action = action->next) {
380 len += sprintf(buf+len, ",%s %s",
381 (action->flags & SA_INTERRUPT) ? " +" : "",
382 action->name);
384 len += sprintf(buf+len, "\n");
386 return len;
389 static inline void ack_irq(int irq)
391 #ifdef CONFIG_ALPHA_SABLE
392 /* Note that the "irq" here is really the mask bit number */
393 switch (irq) {
394 case 0 ... 7:
395 outb(0xE0 | (irq - 0), 0x536);
396 outb(0xE0 | 1, 0x534); /* slave 0 */
397 break;
398 case 8 ... 15:
399 outb(0xE0 | (irq - 8), 0x53a);
400 outb(0xE0 | 3, 0x534); /* slave 1 */
401 break;
402 case 16 ... 24:
403 outb(0xE0 | (irq - 16), 0x53c);
404 outb(0xE0 | 4, 0x534); /* slave 2 */
405 break;
407 #else /* CONFIG_ALPHA_SABLE */
408 if (irq < 16) {
409 /* ACK the interrupt making it the lowest priority */
410 /* First the slave .. */
411 if (irq > 7) {
412 outb(0xE0 | (irq - 8), 0xa0);
413 irq = 2;
415 /* .. then the master */
416 outb(0xE0 | irq, 0x20);
417 #if defined(CONFIG_ALPHA_ALCOR) || defined(CONFIG_ALPHA_XLT)
418 /* on ALCOR/XLT, need to dismiss interrupt via GRU */
419 *(vuip)GRU_INT_CLEAR = 0x80000000; mb();
420 *(vuip)GRU_INT_CLEAR = 0x00000000; mb();
421 #endif /* ALCOR || XLT */
423 #endif /* CONFIG_ALPHA_SABLE */
426 int request_irq(unsigned int irq,
427 void (*handler)(int, void *, struct pt_regs *),
428 unsigned long irqflags,
429 const char * devname,
430 void *dev_id)
432 int shared = 0;
433 struct irqaction * action, **p;
434 unsigned long flags;
436 if (irq >= NR_IRQS)
437 return -EINVAL;
438 if (IS_RESERVED_IRQ(irq))
439 return -EINVAL;
440 if (!handler)
441 return -EINVAL;
442 p = irq_action + irq;
443 action = *p;
444 if (action) {
445 /* Can't share interrupts unless both agree to */
446 if (!(action->flags & irqflags & SA_SHIRQ))
447 return -EBUSY;
449 /* Can't share interrupts unless both are same type */
450 if ((action->flags ^ irqflags) & SA_INTERRUPT)
451 return -EBUSY;
453 /* Add new interrupt at end of irq queue */
454 do {
455 p = &action->next;
456 action = *p;
457 } while (action);
458 shared = 1;
461 if (irq == TIMER_IRQ)
462 action = &timer_irq;
463 else
464 action = (struct irqaction *)kmalloc(sizeof(struct irqaction),
465 GFP_KERNEL);
466 if (!action)
467 return -ENOMEM;
469 if (irqflags & SA_SAMPLE_RANDOM)
470 rand_initialize_irq(irq);
472 action->handler = handler;
473 action->flags = irqflags;
474 action->mask = 0;
475 action->name = devname;
476 action->next = NULL;
477 action->dev_id = dev_id;
479 save_flags(flags);
480 cli();
481 *p = action;
483 if (!shared)
484 unmask_irq(IRQ_TO_MASK(irq));
486 restore_flags(flags);
487 return 0;
490 void free_irq(unsigned int irq, void *dev_id)
492 struct irqaction * action, **p;
493 unsigned long flags;
495 if (irq >= NR_IRQS) {
496 printk("Trying to free IRQ%d\n",irq);
497 return;
499 if (IS_RESERVED_IRQ(irq)) {
500 printk("Trying to free reserved IRQ %d\n", irq);
501 return;
503 for (p = irq + irq_action; (action = *p) != NULL; p = &action->next) {
504 if (action->dev_id != dev_id)
505 continue;
507 /* Found it - now free it */
508 save_flags(flags);
509 cli();
510 *p = action->next;
511 if (!irq[irq_action])
512 mask_irq(IRQ_TO_MASK(irq));
513 restore_flags(flags);
514 kfree(action);
515 return;
517 printk("Trying to free free IRQ%d\n",irq);
520 static inline void handle_nmi(struct pt_regs * regs)
522 printk("Whee.. NMI received. Probable hardware error\n");
523 printk("61=%02x, 461=%02x\n", inb(0x61), inb(0x461));
526 unsigned int local_irq_count[NR_CPUS];
527 atomic_t __alpha_bh_counter;
529 #ifdef __SMP__
530 #error "Me no hablo Alpha SMP"
531 #else
532 #define irq_enter(cpu, irq) (++local_irq_count[cpu])
533 #define irq_exit(cpu, irq) (--local_irq_count[cpu])
534 #endif
536 static void unexpected_irq(int irq, struct pt_regs * regs)
538 struct irqaction *action;
539 int i;
541 printk("IO device interrupt, irq = %d\n", irq);
542 printk("PC = %016lx PS=%04lx\n", regs->pc, regs->ps);
543 printk("Expecting: ");
544 for (i = 0; i < 16; i++)
545 if ((action = irq_action[i]))
546 while (action->handler) {
547 printk("[%s:%d] ", action->name, i);
548 action = action->next;
550 printk("\n");
552 #if defined(CONFIG_ALPHA_JENSEN)
553 /* ??? Is all this just debugging, or are the inb's and outb's
554 necessary to make things work? */
555 printk("64=%02x, 60=%02x, 3fa=%02x 2fa=%02x\n",
556 inb(0x64), inb(0x60), inb(0x3fa), inb(0x2fa));
557 outb(0x0c, 0x3fc);
558 outb(0x0c, 0x2fc);
559 outb(0,0x61);
560 outb(0,0x461);
561 #endif
564 static inline void handle_irq(int irq, struct pt_regs * regs)
566 struct irqaction * action = irq_action[irq];
567 int cpu = smp_processor_id();
569 irq_enter(cpu, irq);
570 kstat.interrupts[0][irq] += 1;
571 if (!action) {
572 unexpected_irq(irq, regs);
573 } else {
574 do {
575 action->handler(irq, action->dev_id, regs);
576 action = action->next;
577 } while (action);
579 irq_exit(cpu, irq);
582 static inline void device_interrupt(int irq, int ack, struct pt_regs * regs)
584 struct irqaction * action;
585 int cpu = smp_processor_id();
587 if ((unsigned) irq > NR_IRQS) {
588 printk("device_interrupt: illegal interrupt %d\n", irq);
589 return;
592 irq_enter(cpu, irq);
593 kstat.interrupts[0][irq] += 1;
594 action = irq_action[irq];
596 * For normal interrupts, we mask it out, and then ACK it.
597 * This way another (more timing-critical) interrupt can
598 * come through while we're doing this one.
600 * Note! An irq without a handler gets masked and acked, but
601 * never unmasked. The autoirq stuff depends on this (it looks
602 * at the masks before and after doing the probing).
604 mask_irq(ack);
605 ack_irq(ack);
606 if (action) {
607 if (action->flags & SA_SAMPLE_RANDOM)
608 add_interrupt_randomness(irq);
609 do {
610 action->handler(irq, action->dev_id, regs);
611 action = action->next;
612 } while (action);
613 unmask_irq(ack);
615 irq_exit(cpu, irq);
618 #ifdef CONFIG_PCI
621 * Handle ISA interrupt via the PICs.
623 static inline void isa_device_interrupt(unsigned long vector,
624 struct pt_regs * regs)
626 #if defined(CONFIG_ALPHA_APECS)
627 # define IACK_SC APECS_IACK_SC
628 #elif defined(CONFIG_ALPHA_LCA)
629 # define IACK_SC LCA_IACK_SC
630 #elif defined(CONFIG_ALPHA_CIA)
631 # define IACK_SC CIA_IACK_SC
632 #elif defined(CONFIG_ALPHA_PYXIS)
633 # define IACK_SC PYXIS_IACK_SC
634 #else
636 * This is bogus but necessary to get it to compile
637 * on all platforms. If you try to use this on any
638 * other than the intended platforms, you'll notice
639 * real fast...
641 # define IACK_SC 1L
642 #endif
643 int j;
645 #if 1
647 * Generate a PCI interrupt acknowledge cycle. The PIC will
648 * respond with the interrupt vector of the highest priority
649 * interrupt that is pending. The PALcode sets up the
650 * interrupts vectors such that irq level L generates vector L.
652 j = *(volatile int *) IACK_SC;
653 j &= 0xff;
654 if (j == 7) {
655 if (!(inb(0x20) & 0x80)) {
656 /* It's only a passive release... */
657 return;
660 device_interrupt(j, j, regs);
661 #else
662 unsigned long pic;
665 * It seems to me that the probability of two or more *device*
666 * interrupts occurring at almost exactly the same time is
667 * pretty low. So why pay the price of checking for
668 * additional interrupts here if the common case can be
669 * handled so much easier?
672 * The first read of gives you *all* interrupting lines.
673 * Therefore, read the mask register and and out those lines
674 * not enabled. Note that some documentation has 21 and a1
675 * write only. This is not true.
677 pic = inb(0x20) | (inb(0xA0) << 8); /* read isr */
678 pic &= ~irq_mask; /* apply mask */
679 pic &= 0xFFFB; /* mask out cascade & hibits */
681 while (pic) {
682 j = ffz(~pic);
683 pic &= pic - 1;
684 device_interrupt(j, j, regs);
686 #endif
689 #if defined(CONFIG_ALPHA_ALCOR) || defined(CONFIG_ALPHA_XLT)
690 /* We have to conditionally compile this because of GRU_xxx symbols */
691 static inline void
692 alcor_and_xlt_device_interrupt(unsigned long vector, struct pt_regs *regs)
694 unsigned long pld;
695 unsigned int i;
696 unsigned long flags;
698 save_flags(flags);
699 cli();
701 /* read the interrupt summary register of the GRU */
702 pld = (*(vuip)GRU_INT_REQ) & GRU_INT_REQ_BITS;
704 #if 0
705 printk("[0x%08lx/0x%04x]", pld, inb(0x20) | (inb(0xA0) << 8));
706 #endif
709 * Now for every possible bit set, work through them and call
710 * the appropriate interrupt handler.
712 while (pld) {
713 i = ffz(~pld);
714 pld &= pld - 1; /* clear least bit set */
715 if (i == 31) {
716 isa_device_interrupt(vector, regs);
717 } else {
718 device_interrupt(16 + i, 16 + i, regs);
721 restore_flags(flags);
723 #endif /* ALCOR || XLT */
725 static inline void
726 cabriolet_and_eb66p_device_interrupt(unsigned long vector,
727 struct pt_regs *regs)
729 unsigned long pld;
730 unsigned int i;
731 unsigned long flags;
733 save_flags(flags);
734 cli();
736 /* read the interrupt summary registers */
737 pld = inb(0x804) | (inb(0x805) << 8) | (inb(0x806) << 16);
739 #if 0
740 printk("[0x%04X/0x%04X]", pld, inb(0x20) | (inb(0xA0) << 8));
741 #endif
744 * Now for every possible bit set, work through them and call
745 * the appropriate interrupt handler.
747 while (pld) {
748 i = ffz(~pld);
749 pld &= pld - 1; /* clear least bit set */
750 if (i == 4) {
751 isa_device_interrupt(vector, regs);
752 } else {
753 device_interrupt(16 + i, 16 + i, regs);
756 restore_flags(flags);
759 static inline void
760 mikasa_device_interrupt(unsigned long vector, struct pt_regs *regs)
762 unsigned long pld;
763 unsigned int i;
764 unsigned long flags;
766 save_flags(flags);
767 cli();
769 /* read the interrupt summary registers */
770 pld = (((unsigned long) (~inw(0x534)) & 0x0000ffffUL) << 16) |
771 (((unsigned long) inb(0xa0)) << 8) |
772 ((unsigned long) inb(0x20));
774 #if 0
775 printk("[0x%08lx]", pld);
776 #endif
779 * Now for every possible bit set, work through them and call
780 * the appropriate interrupt handler.
782 while (pld) {
783 i = ffz(~pld);
784 pld &= pld - 1; /* clear least bit set */
785 if (i < 16) {
786 isa_device_interrupt(vector, regs);
787 } else {
788 device_interrupt(i, i, regs);
791 restore_flags(flags);
794 static inline void
795 eb66_and_eb64p_device_interrupt(unsigned long vector, struct pt_regs *regs)
797 unsigned long pld;
798 unsigned int i;
799 unsigned long flags;
801 save_flags(flags);
802 cli();
804 /* read the interrupt summary registers */
805 pld = inb(0x26) | (inb(0x27) << 8);
807 * Now, for every possible bit set, work through
808 * them and call the appropriate interrupt handler.
810 while (pld) {
811 i = ffz(~pld);
812 pld &= pld - 1; /* clear least bit set */
814 if (i == 5) {
815 isa_device_interrupt(vector, regs);
816 } else {
817 device_interrupt(16 + i, 16 + i, regs);
820 restore_flags(flags);
823 #if defined(CONFIG_ALPHA_MIATA)
824 /* We have to conditionally compile this because of PYXIS_xxx symbols */
825 static inline void
826 miata_device_interrupt(unsigned long vector, struct pt_regs *regs)
828 unsigned long pld, tmp;
829 unsigned int i;
830 unsigned long flags;
832 save_flags(flags);
833 cli();
835 /* read the interrupt summary register of PYXIS */
836 pld = (*(vulp)PYXIS_INT_REQ);
838 #if 0
839 printk("[0x%08lx/0x%08lx/0x%04x]", pld,
840 *(vulp)PYXIS_INT_MASK, inb(0x20) | (inb(0xA0) << 8));
841 #endif
843 #if 1
845 * For now, AND off any bits we are not interested in:
846 * HALT (2), timer (6), ISA Bridge (7), 21142/3 (8)
847 * then all the PCI slots/INTXs (12-31).
849 /* Maybe HALT should only be used for SRM console boots? */
850 pld &= 0x00000000fffff1c4UL;
851 #endif
854 * Now for every possible bit set, work through them and call
855 * the appropriate interrupt handler.
857 while (pld) {
858 i = ffz(~pld);
859 pld &= pld - 1; /* clear least bit set */
860 if (i == 7) {
861 isa_device_interrupt(vector, regs);
862 } else if (i == 6)
863 continue;
864 else { /* if not timer int */
865 device_interrupt(16 + i, 16 + i, regs);
867 *(vulp)PYXIS_INT_REQ = 1UL << i; mb();
868 tmp = *(vulp)PYXIS_INT_REQ;
870 restore_flags(flags);
872 #endif /* MIATA */
874 static inline void
875 noritake_device_interrupt(unsigned long vector, struct pt_regs *regs)
877 unsigned long pld;
878 unsigned int i;
879 unsigned long flags;
881 save_flags(flags);
882 cli();
884 /* read the interrupt summary registers of NORITAKE */
885 pld = ((unsigned long) inw(0x54c) << 32) |
886 ((unsigned long) inw(0x54a) << 16) |
887 ((unsigned long) inb(0xa0) << 8) |
888 ((unsigned long) inb(0x20));
890 #if 0
891 printk("[0x%08lx]", pld);
892 #endif
895 * Now for every possible bit set, work through them and call
896 * the appropriate interrupt handler.
898 while (pld) {
899 i = ffz(~pld);
900 pld &= pld - 1; /* clear least bit set */
901 if (i < 16) {
902 isa_device_interrupt(vector, regs);
903 } else {
904 device_interrupt(i, i, regs);
907 restore_flags(flags);
910 #endif /* CONFIG_PCI */
913 * Jensen is special: the vector is 0x8X0 for EISA interrupt X, and
914 * 0x9X0 for the local motherboard interrupts..
916 * 0x660 - NMI
918 * 0x800 - IRQ0 interval timer (not used, as we use the RTC timer)
919 * 0x810 - IRQ1 line printer (duh..)
920 * 0x860 - IRQ6 floppy disk
921 * 0x8E0 - IRQ14 SCSI controller
923 * 0x900 - COM1
924 * 0x920 - COM2
925 * 0x980 - keyboard
926 * 0x990 - mouse
928 * PCI-based systems are more sane: they don't have the local
929 * interrupts at all, and have only normal PCI interrupts from
930 * devices. Happily it's easy enough to do a sane mapping from the
931 * Jensen.. Note that this means that we may have to do a hardware
932 * "ack" to a different interrupt than we report to the rest of the
933 * world.
935 static inline void
936 srm_device_interrupt(unsigned long vector, struct pt_regs * regs)
938 int irq, ack;
939 unsigned long flags;
941 save_flags(flags);
942 cli();
945 ack = irq = (vector - 0x800) >> 4;
947 #ifdef CONFIG_ALPHA_JENSEN
948 switch (vector) {
949 case 0x660: handle_nmi(regs); return;
950 /* local device interrupts: */
951 case 0x900: handle_irq(4, regs); return; /* com1 -> irq 4 */
952 case 0x920: handle_irq(3, regs); return; /* com2 -> irq 3 */
953 case 0x980: handle_irq(1, regs); return; /* kbd -> irq 1 */
954 case 0x990: handle_irq(9, regs); return; /* mouse -> irq 9 */
955 default:
956 if (vector > 0x900) {
957 printk("Unknown local interrupt %lx\n", vector);
960 /* irq1 is supposed to be the keyboard, silly Jensen
961 (is this really needed??) */
962 if (irq == 1)
963 irq = 7;
964 #endif /* CONFIG_ALPHA_JENSEN */
966 #ifdef CONFIG_ALPHA_MIATA
968 * I really hate to do this, but the MIATA SRM console ignores the
969 * low 8 bits in the interrupt summary register, and reports the
970 * vector 0x80 *lower* than I expected from the bit numbering in
971 * the documentation.
972 * This was done because the low 8 summary bits really aren't used
973 * for reporting any interrupts (the PCI-ISA bridge, bit 7, isn't
974 * used for this purpose, as PIC interrupts are delivered as the
975 * vectors 0x800-0x8f0).
976 * But I really don't want to change the fixup code for allocation
977 * of IRQs, nor the irq_mask maintenance stuff, both of which look
978 * nice and clean now.
979 * So, here's this grotty hack... :-(
981 if (irq >= 16)
982 ack = irq = irq + 8;
983 #endif /* CONFIG_ALPHA_MIATA */
985 #ifdef CONFIG_ALPHA_NORITAKE
987 * I really hate to do this, but the NORITAKE SRM console reports
988 * PCI vectors *lower* than I expected from the bit numbering in
989 * the documentation.
990 * But I really don't want to change the fixup code for allocation
991 * of IRQs, nor the irq_mask maintenance stuff, both of which look
992 * nice and clean now.
993 * So, here's this additional grotty hack... :-(
995 if (irq >= 16)
996 ack = irq = irq + 1;
997 #endif /* CONFIG_ALPHA_NORITAKE */
999 #ifdef CONFIG_ALPHA_SABLE
1000 irq = sable_mask_to_irq[(ack)];
1001 #if 0
1002 if (irq == 5 || irq == 9 || irq == 10 || irq == 11 ||
1003 irq == 14 || irq == 15)
1004 printk("srm_device_interrupt: vector=0x%lx ack=0x%x"
1005 " irq=0x%x\n", vector, ack, irq);
1006 #endif
1007 #endif /* CONFIG_ALPHA_SABLE */
1009 device_interrupt(irq, ack, regs);
1011 restore_flags(flags);
1015 * Start listening for interrupts..
1017 unsigned long probe_irq_on(void)
1019 struct irqaction * action;
1020 unsigned long irqs = 0;
1021 unsigned long delay;
1022 unsigned int i;
1024 for (i = NR_IRQS - 1; i > 0; i--) {
1025 if (!(PROBE_MASK & (1UL << i))) {
1026 continue;
1028 action = irq_action[i];
1029 if (!action) {
1030 enable_irq(i);
1031 irqs |= (1UL << i);
1036 * Wait about 100ms for spurious interrupts to mask themselves
1037 * out again...
1039 for (delay = jiffies + HZ/10; delay > jiffies; )
1040 barrier();
1042 /* now filter out any obviously spurious interrupts */
1043 return irqs & ~irq_mask;
1047 * Get the result of the IRQ probe.. A negative result means that
1048 * we have several candidates (but we return the lowest-numbered
1049 * one).
1051 int probe_irq_off(unsigned long irqs)
1053 int i;
1055 irqs &= irq_mask;
1056 if (!irqs)
1057 return 0;
1058 i = ffz(~irqs);
1059 if (irqs != (1UL << i))
1060 i = -i;
1061 return i;
1064 extern void lca_machine_check (unsigned long vector, unsigned long la,
1065 struct pt_regs *regs);
1066 extern void apecs_machine_check(unsigned long vector, unsigned long la,
1067 struct pt_regs * regs);
1068 extern void cia_machine_check(unsigned long vector, unsigned long la,
1069 struct pt_regs * regs);
1070 extern void pyxis_machine_check(unsigned long vector, unsigned long la,
1071 struct pt_regs * regs);
1072 extern void t2_machine_check(unsigned long vector, unsigned long la,
1073 struct pt_regs * regs);
1075 static void
1076 machine_check(unsigned long vector, unsigned long la, struct pt_regs *regs)
1078 #if defined(CONFIG_ALPHA_LCA)
1079 lca_machine_check(vector, la, regs);
1080 #elif defined(CONFIG_ALPHA_APECS)
1081 apecs_machine_check(vector, la, regs);
1082 #elif defined(CONFIG_ALPHA_CIA)
1083 cia_machine_check(vector, la, regs);
1084 #elif defined(CONFIG_ALPHA_PYXIS)
1085 pyxis_machine_check(vector, la, regs);
1086 #elif defined(CONFIG_ALPHA_T2)
1087 t2_machine_check(vector, la, regs);
1088 #else
1089 printk("Machine check\n");
1090 #endif
1093 asmlinkage void
1094 do_entInt(unsigned long type, unsigned long vector, unsigned long la_ptr,
1095 unsigned long a3, unsigned long a4, unsigned long a5,
1096 struct pt_regs regs)
1098 switch (type) {
1099 case 0:
1100 printk("Interprocessor interrupt? You must be kidding\n");
1101 break;
1102 case 1:
1103 handle_irq(RTC_IRQ, &regs);
1104 return;
1105 case 2:
1106 machine_check(vector, la_ptr, &regs);
1107 return;
1108 case 3:
1109 #if defined(CONFIG_ALPHA_JENSEN) || defined(CONFIG_ALPHA_NONAME) || \
1110 defined(CONFIG_ALPHA_P2K) || defined(CONFIG_ALPHA_SRM)
1111 srm_device_interrupt(vector, &regs);
1112 #elif defined(CONFIG_ALPHA_MIATA)
1113 miata_device_interrupt(vector, &regs);
1114 #elif defined(CONFIG_ALPHA_NORITAKE)
1115 noritake_device_interrupt(vector, &regs);
1116 #elif defined(CONFIG_ALPHA_ALCOR) || defined(CONFIG_ALPHA_XLT)
1117 alcor_and_xlt_device_interrupt(vector, &regs);
1118 #elif NR_IRQS == 33
1119 cabriolet_and_eb66p_device_interrupt(vector, &regs);
1120 #elif defined(CONFIG_ALPHA_MIKASA)
1121 mikasa_device_interrupt(vector, &regs);
1122 #elif NR_IRQS == 32
1123 eb66_and_eb64p_device_interrupt(vector, &regs);
1124 #elif NR_IRQS == 16
1125 isa_device_interrupt(vector, &regs);
1126 #endif
1127 return;
1128 case 4:
1129 printk("Performance counter interrupt\n");
1130 break;
1131 default:
1132 printk("Hardware intr %ld %lx? Huh?\n", type, vector);
1134 printk("PC = %016lx PS=%04lx\n", regs.pc, regs.ps);
1137 extern asmlinkage void entInt(void);
1139 static inline void sable_init_IRQ(void)
1141 outb(irq_mask , 0x537); /* slave 0 */
1142 outb(irq_mask >> 8, 0x53b); /* slave 1 */
1143 outb(irq_mask >> 16, 0x53d); /* slave 2 */
1144 outb(0x44, 0x535); /* enable cascades in master */
1147 #ifdef CONFIG_ALPHA_MIATA
1148 static inline void miata_init_IRQ(void)
1150 /* note invert on MASK bits */
1151 *(vulp)PYXIS_INT_MASK = ~((long)irq_mask >> 16); mb(); /* invert */
1152 *(vulp)PYXIS_INT_HILO = 0x000000B2UL; mb(); /* ISA/NMI HI */
1153 *(vulp)PYXIS_RT_COUNT = 0UL; mb(); /* clear count */
1154 *(vulp)PYXIS_INT_REQ = 0x4000000000000000UL; mb(); /* clear upper timer */
1155 #if 0
1156 *(vulp)PYXIS_INT_ROUTE = 0UL; mb(); /* all are level */
1157 *(vulp)PYXIS_INT_CNFG = 0UL; mb(); /* all clear */
1158 #endif
1159 enable_irq(16 + 2); /* enable HALT switch - SRM only? */
1160 enable_irq(16 + 6); /* enable timer */
1161 enable_irq(16 + 7); /* enable ISA PIC cascade */
1162 enable_irq(2); /* enable cascade */
1164 #endif
1166 static inline void noritake_init_IRQ(void)
1168 outw(~(irq_mask >> 16), 0x54a); /* note invert */
1169 outw(~(irq_mask >> 32), 0x54c); /* note invert */
1170 enable_irq(2); /* enable cascade */
1173 #if defined(CONFIG_ALPHA_ALCOR) || defined(CONFIG_ALPHA_XLT)
1174 static inline void alcor_and_xlt_init_IRQ(void)
1176 *(vuip)GRU_INT_MASK = ~(irq_mask >> 16); mb(); /* note invert */
1177 *(vuip)GRU_INT_EDGE = 0U; mb(); /* all are level */
1178 *(vuip)GRU_INT_HILO = 0x80000000U; mb(); /* ISA only HI */
1179 *(vuip)GRU_INT_CLEAR = 0UL; mb(); /* all clear */
1181 enable_irq(16 + 31); /* enable (E)ISA PIC cascade */
1182 enable_irq(2); /* enable cascade */
1184 #endif
1186 static inline void mikasa_init_IRQ(void)
1188 outw(~(irq_mask >> 16), 0x536); /* note invert */
1189 enable_irq(2); /* enable cascade */
1192 static inline void init_IRQ_33(void)
1194 outl(irq_mask >> 16, 0x804);
1195 enable_irq(16 + 4); /* enable SIO cascade */
1196 enable_irq(2); /* enable cascade */
1199 static inline void init_IRQ_32(void)
1201 outb(irq_mask >> 16, 0x26);
1202 outb(irq_mask >> 24, 0x27);
1203 enable_irq(16 + 5); /* enable SIO cascade */
1204 enable_irq(2); /* enable cascade */
1207 static inline void init_IRQ_16(void)
1209 enable_irq(2); /* enable cascade */
1212 void init_IRQ(void)
1214 wrent(entInt, 0);
1215 dma_outb(0, DMA1_RESET_REG);
1216 dma_outb(0, DMA2_RESET_REG);
1217 dma_outb(0, DMA1_CLR_MASK_REG);
1218 dma_outb(0, DMA2_CLR_MASK_REG);
1220 #if defined(CONFIG_ALPHA_SABLE)
1221 sable_init_IRQ();
1222 #elif defined(CONFIG_ALPHA_MIATA)
1223 miata_init_IRQ();
1224 #elif defined(CONFIG_ALPHA_NORITAKE)
1225 noritake_init_IRQ();
1226 #elif defined(CONFIG_ALPHA_ALCOR) || defined(CONFIG_ALPHA_XLT)
1227 alcor_and_xlt_init_IRQ();
1228 #elif defined(CONFIG_ALPHA_PC164) && defined(CONFIG_ALPHA_SRM)
1229 /* Disable all the PCI interrupts? Otherwise, everthing was
1230 done by SRM already. */
1231 #elif defined(CONFIG_ALPHA_MIKASA)
1232 mikasa_init_IRQ();
1233 #elif NR_IRQS == 33
1234 init_IRQ_33();
1235 #elif NR_IRQS == 32
1236 init_IRQ_32();
1237 #elif NR_IRQS == 16
1238 init_IRQ_16();
1239 #else
1240 #error "How do I initialize the interrupt hardware?"
1241 #endif