2 * ip22-int.c: Routines for generic manipulation of the INT[23] ASIC
3 * found on INDY and Indigo2 workstations.
5 * Copyright (C) 1996 David S. Miller (dm@engr.sgi.com)
6 * Copyright (C) 1997, 1998 Ralf Baechle (ralf@gnu.org)
7 * Copyright (C) 1999 Andrew R. Baker (andrewb@uab.edu)
9 * - Interrupt handling fixes
10 * Copyright (C) 2001, 2003 Ladislav Michl (ladis@linux-mips.org)
12 #include <linux/config.h>
13 #include <linux/types.h>
14 #include <linux/init.h>
15 #include <linux/kernel_stat.h>
16 #include <linux/signal.h>
17 #include <linux/sched.h>
18 #include <linux/interrupt.h>
19 #include <linux/irq.h>
21 #include <asm/mipsregs.h>
22 #include <asm/addrspace.h>
24 #include <asm/sgi/ioc.h>
25 #include <asm/sgi/hpc3.h>
26 #include <asm/sgi/ip22.h>
28 /* #define DEBUG_SGINT */
30 /* So far nothing hangs here */
33 struct sgint_regs *sgint;
35 static char lc0msk_to_irqnr[256];
36 static char lc1msk_to_irqnr[256];
37 static char lc2msk_to_irqnr[256];
38 static char lc3msk_to_irqnr[256];
40 extern int ip22_eisa_init(void);
42 static void enable_local0_irq(unsigned int irq)
46 local_irq_save(flags);
47 /* don't allow mappable interrupt to be enabled from setup_irq,
48 * we have our own way to do so */
49 if (irq != SGI_MAP_0_IRQ)
50 sgint->imask0 |= (1 << (irq - SGINT_LOCAL0));
51 local_irq_restore(flags);
54 static unsigned int startup_local0_irq(unsigned int irq)
56 enable_local0_irq(irq);
57 return 0; /* Never anything pending */
60 static void disable_local0_irq(unsigned int irq)
64 local_irq_save(flags);
65 sgint->imask0 &= ~(1 << (irq - SGINT_LOCAL0));
66 local_irq_restore(flags);
69 #define shutdown_local0_irq disable_local0_irq
70 #define mask_and_ack_local0_irq disable_local0_irq
72 static void end_local0_irq (unsigned int irq)
74 if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
75 enable_local0_irq(irq);
78 static struct hw_interrupt_type ip22_local0_irq_type = {
79 .typename = "IP22 local 0",
80 .startup = startup_local0_irq,
81 .shutdown = shutdown_local0_irq,
82 .enable = enable_local0_irq,
83 .disable = disable_local0_irq,
84 .ack = mask_and_ack_local0_irq,
85 .end = end_local0_irq,
88 static void enable_local1_irq(unsigned int irq)
92 local_irq_save(flags);
93 /* don't allow mappable interrupt to be enabled from setup_irq,
94 * we have our own way to do so */
95 if (irq != SGI_MAP_1_IRQ)
96 sgint->imask1 |= (1 << (irq - SGINT_LOCAL1));
97 local_irq_restore(flags);
100 static unsigned int startup_local1_irq(unsigned int irq)
102 enable_local1_irq(irq);
103 return 0; /* Never anything pending */
106 void disable_local1_irq(unsigned int irq)
110 local_irq_save(flags);
111 sgint->imask1 &= ~(1 << (irq - SGINT_LOCAL1));
112 local_irq_restore(flags);
115 #define shutdown_local1_irq disable_local1_irq
116 #define mask_and_ack_local1_irq disable_local1_irq
118 static void end_local1_irq (unsigned int irq)
120 if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
121 enable_local1_irq(irq);
124 static struct hw_interrupt_type ip22_local1_irq_type = {
125 .typename = "IP22 local 1",
126 .startup = startup_local1_irq,
127 .shutdown = shutdown_local1_irq,
128 .enable = enable_local1_irq,
129 .disable = disable_local1_irq,
130 .ack = mask_and_ack_local1_irq,
131 .end = end_local1_irq,
134 static void enable_local2_irq(unsigned int irq)
138 local_irq_save(flags);
139 sgint->imask0 |= (1 << (SGI_MAP_0_IRQ - SGINT_LOCAL0));
140 sgint->cmeimask0 |= (1 << (irq - SGINT_LOCAL2));
141 local_irq_restore(flags);
144 static unsigned int startup_local2_irq(unsigned int irq)
146 enable_local2_irq(irq);
147 return 0; /* Never anything pending */
150 void disable_local2_irq(unsigned int irq)
154 local_irq_save(flags);
155 sgint->cmeimask0 &= ~(1 << (irq - SGINT_LOCAL2));
156 if (!sgint->cmeimask0)
157 sgint->imask0 &= ~(1 << (SGI_MAP_0_IRQ - SGINT_LOCAL0));
158 local_irq_restore(flags);
161 #define shutdown_local2_irq disable_local2_irq
162 #define mask_and_ack_local2_irq disable_local2_irq
164 static void end_local2_irq (unsigned int irq)
166 if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
167 enable_local2_irq(irq);
170 static struct hw_interrupt_type ip22_local2_irq_type = {
171 .typename = "IP22 local 2",
172 .startup = startup_local2_irq,
173 .shutdown = shutdown_local2_irq,
174 .enable = enable_local2_irq,
175 .disable = disable_local2_irq,
176 .ack = mask_and_ack_local2_irq,
177 .end = end_local2_irq,
180 static void enable_local3_irq(unsigned int irq)
184 local_irq_save(flags);
185 sgint->imask1 |= (1 << (SGI_MAP_1_IRQ - SGINT_LOCAL1));
186 sgint->cmeimask1 |= (1 << (irq - SGINT_LOCAL3));
187 local_irq_restore(flags);
190 static unsigned int startup_local3_irq(unsigned int irq)
192 enable_local3_irq(irq);
193 return 0; /* Never anything pending */
196 void disable_local3_irq(unsigned int irq)
200 local_irq_save(flags);
201 sgint->cmeimask1 &= ~(1 << (irq - SGINT_LOCAL3));
202 if (!sgint->cmeimask1)
203 sgint->imask1 &= ~(1 << (SGI_MAP_1_IRQ - SGINT_LOCAL1));
204 local_irq_restore(flags);
207 #define shutdown_local3_irq disable_local3_irq
208 #define mask_and_ack_local3_irq disable_local3_irq
210 static void end_local3_irq (unsigned int irq)
212 if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
213 enable_local3_irq(irq);
216 static struct hw_interrupt_type ip22_local3_irq_type = {
217 .typename = "IP22 local 3",
218 .startup = startup_local3_irq,
219 .shutdown = shutdown_local3_irq,
220 .enable = enable_local3_irq,
221 .disable = disable_local3_irq,
222 .ack = mask_and_ack_local3_irq,
223 .end = end_local3_irq,
226 static void indy_local0_irqdispatch(struct pt_regs *regs)
228 u8 mask = sgint->istat0 & sgint->imask0;
232 if (mask & SGINT_ISTAT0_LIO2) {
233 mask2 = sgint->vmeistat & sgint->cmeimask0;
234 irq = lc2msk_to_irqnr[mask2];
236 irq = lc0msk_to_irqnr[mask];
238 /* if irq == 0, then the interrupt has already been cleared */
244 static void indy_local1_irqdispatch(struct pt_regs *regs)
246 u8 mask = sgint->istat1 & sgint->imask1;
250 if (mask & SGINT_ISTAT1_LIO3) {
251 mask2 = sgint->vmeistat & sgint->cmeimask1;
252 irq = lc3msk_to_irqnr[mask2];
254 irq = lc1msk_to_irqnr[mask];
256 /* if irq == 0, then the interrupt has already been cleared */
262 extern void ip22_be_interrupt(int irq, struct pt_regs *regs);
264 static void indy_buserror_irq(struct pt_regs *regs)
266 int irq = SGI_BUSERR_IRQ;
269 kstat_this_cpu.irqs[irq]++;
270 ip22_be_interrupt(irq, regs);
274 static struct irqaction local0_cascade = {
275 .handler = no_action,
276 .flags = SA_INTERRUPT,
277 .name = "local0 cascade",
280 static struct irqaction local1_cascade = {
281 .handler = no_action,
282 .flags = SA_INTERRUPT,
283 .name = "local1 cascade",
286 static struct irqaction buserr = {
287 .handler = no_action,
288 .flags = SA_INTERRUPT,
292 static struct irqaction map0_cascade = {
293 .handler = no_action,
294 .flags = SA_INTERRUPT,
295 .name = "mapable0 cascade",
299 static struct irqaction map1_cascade = {
300 .handler = no_action,
301 .flags = SA_INTERRUPT,
302 .name = "mapable1 cascade",
304 #define SGI_INTERRUPTS SGINT_END
306 #define SGI_INTERRUPTS SGINT_LOCAL3
309 extern void indy_r4k_timer_interrupt(struct pt_regs *regs);
310 extern void indy_8254timer_irq(struct pt_regs *regs);
313 * IRQs on the INDY look basically (barring software IRQs which we don't use
318 * 0 Software (ignored)
319 * 1 Software (ignored)
320 * 2 Local IRQ level zero
321 * 3 Local IRQ level one
325 * 7 R4k timer (what we use)
327 * We handle the IRQ according to _our_ priority which is:
329 * Highest ---- R4k Timer
334 * Lowest ---- 8254 Timer one
336 * then we just return, if multiple IRQs are pending then we will just take
337 * another exception, big deal.
340 asmlinkage void plat_irq_dispatch(struct pt_regs *regs)
342 unsigned int pending = read_c0_cause();
345 * First we check for r4k counter/timer IRQ.
347 if (pending & CAUSEF_IP7)
348 indy_r4k_timer_interrupt(regs);
349 else if (pending & CAUSEF_IP2)
350 indy_local0_irqdispatch(regs);
351 else if (pending & CAUSEF_IP3)
352 indy_local1_irqdispatch(regs);
353 else if (pending & CAUSEF_IP6)
354 indy_buserror_irq(regs);
355 else if (pending & (CAUSEF_IP4 | CAUSEF_IP5))
356 indy_8254timer_irq(regs);
359 extern void mips_cpu_irq_init(unsigned int irq_base);
361 void __init arch_init_irq(void)
365 /* Init local mask --> irq tables. */
366 for (i = 0; i < 256; i++) {
368 lc0msk_to_irqnr[i] = SGINT_LOCAL0 + 7;
369 lc1msk_to_irqnr[i] = SGINT_LOCAL1 + 7;
370 lc2msk_to_irqnr[i] = SGINT_LOCAL2 + 7;
371 lc3msk_to_irqnr[i] = SGINT_LOCAL3 + 7;
372 } else if (i & 0x40) {
373 lc0msk_to_irqnr[i] = SGINT_LOCAL0 + 6;
374 lc1msk_to_irqnr[i] = SGINT_LOCAL1 + 6;
375 lc2msk_to_irqnr[i] = SGINT_LOCAL2 + 6;
376 lc3msk_to_irqnr[i] = SGINT_LOCAL3 + 6;
377 } else if (i & 0x20) {
378 lc0msk_to_irqnr[i] = SGINT_LOCAL0 + 5;
379 lc1msk_to_irqnr[i] = SGINT_LOCAL1 + 5;
380 lc2msk_to_irqnr[i] = SGINT_LOCAL2 + 5;
381 lc3msk_to_irqnr[i] = SGINT_LOCAL3 + 5;
382 } else if (i & 0x10) {
383 lc0msk_to_irqnr[i] = SGINT_LOCAL0 + 4;
384 lc1msk_to_irqnr[i] = SGINT_LOCAL1 + 4;
385 lc2msk_to_irqnr[i] = SGINT_LOCAL2 + 4;
386 lc3msk_to_irqnr[i] = SGINT_LOCAL3 + 4;
387 } else if (i & 0x08) {
388 lc0msk_to_irqnr[i] = SGINT_LOCAL0 + 3;
389 lc1msk_to_irqnr[i] = SGINT_LOCAL1 + 3;
390 lc2msk_to_irqnr[i] = SGINT_LOCAL2 + 3;
391 lc3msk_to_irqnr[i] = SGINT_LOCAL3 + 3;
392 } else if (i & 0x04) {
393 lc0msk_to_irqnr[i] = SGINT_LOCAL0 + 2;
394 lc1msk_to_irqnr[i] = SGINT_LOCAL1 + 2;
395 lc2msk_to_irqnr[i] = SGINT_LOCAL2 + 2;
396 lc3msk_to_irqnr[i] = SGINT_LOCAL3 + 2;
397 } else if (i & 0x02) {
398 lc0msk_to_irqnr[i] = SGINT_LOCAL0 + 1;
399 lc1msk_to_irqnr[i] = SGINT_LOCAL1 + 1;
400 lc2msk_to_irqnr[i] = SGINT_LOCAL2 + 1;
401 lc3msk_to_irqnr[i] = SGINT_LOCAL3 + 1;
402 } else if (i & 0x01) {
403 lc0msk_to_irqnr[i] = SGINT_LOCAL0 + 0;
404 lc1msk_to_irqnr[i] = SGINT_LOCAL1 + 0;
405 lc2msk_to_irqnr[i] = SGINT_LOCAL2 + 0;
406 lc3msk_to_irqnr[i] = SGINT_LOCAL3 + 0;
408 lc0msk_to_irqnr[i] = 0;
409 lc1msk_to_irqnr[i] = 0;
410 lc2msk_to_irqnr[i] = 0;
411 lc3msk_to_irqnr[i] = 0;
415 /* Mask out all interrupts. */
418 sgint->cmeimask0 = 0;
419 sgint->cmeimask1 = 0;
422 mips_cpu_irq_init(SGINT_CPU);
424 for (i = SGINT_LOCAL0; i < SGI_INTERRUPTS; i++) {
425 hw_irq_controller *handler;
427 if (i < SGINT_LOCAL1)
428 handler = &ip22_local0_irq_type;
429 else if (i < SGINT_LOCAL2)
430 handler = &ip22_local1_irq_type;
431 else if (i < SGINT_LOCAL3)
432 handler = &ip22_local2_irq_type;
434 handler = &ip22_local3_irq_type;
436 irq_desc[i].status = IRQ_DISABLED;
437 irq_desc[i].action = 0;
438 irq_desc[i].depth = 1;
439 irq_desc[i].handler = handler;
442 /* vector handler. this register the IRQ as non-sharable */
443 setup_irq(SGI_LOCAL_0_IRQ, &local0_cascade);
444 setup_irq(SGI_LOCAL_1_IRQ, &local1_cascade);
445 setup_irq(SGI_BUSERR_IRQ, &buserr);
447 /* cascade in cascade. i love Indy ;-) */
448 setup_irq(SGI_MAP_0_IRQ, &map0_cascade);
450 setup_irq(SGI_MAP_1_IRQ, &map1_cascade);
454 if (ip22_is_fullhouse()) /* Only Indigo-2 has EISA stuff */