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/types.h>
13 #include <linux/init.h>
14 #include <linux/kernel_stat.h>
15 #include <linux/signal.h>
16 #include <linux/sched.h>
17 #include <linux/interrupt.h>
18 #include <linux/irq.h>
20 #include <asm/mipsregs.h>
21 #include <asm/addrspace.h>
23 #include <asm/sgi/ioc.h>
24 #include <asm/sgi/hpc3.h>
25 #include <asm/sgi/ip22.h>
27 /* #define DEBUG_SGINT */
29 /* So far nothing hangs here */
32 struct sgint_regs *sgint;
34 static char lc0msk_to_irqnr[256];
35 static char lc1msk_to_irqnr[256];
36 static char lc2msk_to_irqnr[256];
37 static char lc3msk_to_irqnr[256];
39 extern int ip22_eisa_init(void);
41 static void enable_local0_irq(unsigned int irq)
45 local_irq_save(flags);
46 /* don't allow mappable interrupt to be enabled from setup_irq,
47 * we have our own way to do so */
48 if (irq != SGI_MAP_0_IRQ)
49 sgint->imask0 |= (1 << (irq - SGINT_LOCAL0));
50 local_irq_restore(flags);
53 static unsigned int startup_local0_irq(unsigned int irq)
55 enable_local0_irq(irq);
56 return 0; /* Never anything pending */
59 static void disable_local0_irq(unsigned int irq)
63 local_irq_save(flags);
64 sgint->imask0 &= ~(1 << (irq - SGINT_LOCAL0));
65 local_irq_restore(flags);
68 #define shutdown_local0_irq disable_local0_irq
69 #define mask_and_ack_local0_irq disable_local0_irq
71 static void end_local0_irq (unsigned int irq)
73 if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
74 enable_local0_irq(irq);
77 static struct irq_chip ip22_local0_irq_type = {
78 .typename = "IP22 local 0",
79 .startup = startup_local0_irq,
80 .shutdown = shutdown_local0_irq,
81 .enable = enable_local0_irq,
82 .disable = disable_local0_irq,
83 .ack = mask_and_ack_local0_irq,
84 .end = end_local0_irq,
87 static void enable_local1_irq(unsigned int irq)
91 local_irq_save(flags);
92 /* don't allow mappable interrupt to be enabled from setup_irq,
93 * we have our own way to do so */
94 if (irq != SGI_MAP_1_IRQ)
95 sgint->imask1 |= (1 << (irq - SGINT_LOCAL1));
96 local_irq_restore(flags);
99 static unsigned int startup_local1_irq(unsigned int irq)
101 enable_local1_irq(irq);
102 return 0; /* Never anything pending */
105 void disable_local1_irq(unsigned int irq)
109 local_irq_save(flags);
110 sgint->imask1 &= ~(1 << (irq - SGINT_LOCAL1));
111 local_irq_restore(flags);
114 #define shutdown_local1_irq disable_local1_irq
115 #define mask_and_ack_local1_irq disable_local1_irq
117 static void end_local1_irq (unsigned int irq)
119 if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
120 enable_local1_irq(irq);
123 static struct irq_chip ip22_local1_irq_type = {
124 .typename = "IP22 local 1",
125 .startup = startup_local1_irq,
126 .shutdown = shutdown_local1_irq,
127 .enable = enable_local1_irq,
128 .disable = disable_local1_irq,
129 .ack = mask_and_ack_local1_irq,
130 .end = end_local1_irq,
133 static void enable_local2_irq(unsigned int irq)
137 local_irq_save(flags);
138 sgint->imask0 |= (1 << (SGI_MAP_0_IRQ - SGINT_LOCAL0));
139 sgint->cmeimask0 |= (1 << (irq - SGINT_LOCAL2));
140 local_irq_restore(flags);
143 static unsigned int startup_local2_irq(unsigned int irq)
145 enable_local2_irq(irq);
146 return 0; /* Never anything pending */
149 void disable_local2_irq(unsigned int irq)
153 local_irq_save(flags);
154 sgint->cmeimask0 &= ~(1 << (irq - SGINT_LOCAL2));
155 if (!sgint->cmeimask0)
156 sgint->imask0 &= ~(1 << (SGI_MAP_0_IRQ - SGINT_LOCAL0));
157 local_irq_restore(flags);
160 #define shutdown_local2_irq disable_local2_irq
161 #define mask_and_ack_local2_irq disable_local2_irq
163 static void end_local2_irq (unsigned int irq)
165 if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
166 enable_local2_irq(irq);
169 static struct irq_chip ip22_local2_irq_type = {
170 .typename = "IP22 local 2",
171 .startup = startup_local2_irq,
172 .shutdown = shutdown_local2_irq,
173 .enable = enable_local2_irq,
174 .disable = disable_local2_irq,
175 .ack = mask_and_ack_local2_irq,
176 .end = end_local2_irq,
179 static void enable_local3_irq(unsigned int irq)
183 local_irq_save(flags);
184 sgint->imask1 |= (1 << (SGI_MAP_1_IRQ - SGINT_LOCAL1));
185 sgint->cmeimask1 |= (1 << (irq - SGINT_LOCAL3));
186 local_irq_restore(flags);
189 static unsigned int startup_local3_irq(unsigned int irq)
191 enable_local3_irq(irq);
192 return 0; /* Never anything pending */
195 void disable_local3_irq(unsigned int irq)
199 local_irq_save(flags);
200 sgint->cmeimask1 &= ~(1 << (irq - SGINT_LOCAL3));
201 if (!sgint->cmeimask1)
202 sgint->imask1 &= ~(1 << (SGI_MAP_1_IRQ - SGINT_LOCAL1));
203 local_irq_restore(flags);
206 #define shutdown_local3_irq disable_local3_irq
207 #define mask_and_ack_local3_irq disable_local3_irq
209 static void end_local3_irq (unsigned int irq)
211 if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
212 enable_local3_irq(irq);
215 static struct irq_chip ip22_local3_irq_type = {
216 .typename = "IP22 local 3",
217 .startup = startup_local3_irq,
218 .shutdown = shutdown_local3_irq,
219 .enable = enable_local3_irq,
220 .disable = disable_local3_irq,
221 .ack = mask_and_ack_local3_irq,
222 .end = end_local3_irq,
225 static void indy_local0_irqdispatch(void)
227 u8 mask = sgint->istat0 & sgint->imask0;
231 if (mask & SGINT_ISTAT0_LIO2) {
232 mask2 = sgint->vmeistat & sgint->cmeimask0;
233 irq = lc2msk_to_irqnr[mask2];
235 irq = lc0msk_to_irqnr[mask];
237 /* if irq == 0, then the interrupt has already been cleared */
242 static void indy_local1_irqdispatch(void)
244 u8 mask = sgint->istat1 & sgint->imask1;
248 if (mask & SGINT_ISTAT1_LIO3) {
249 mask2 = sgint->vmeistat & sgint->cmeimask1;
250 irq = lc3msk_to_irqnr[mask2];
252 irq = lc1msk_to_irqnr[mask];
254 /* if irq == 0, then the interrupt has already been cleared */
259 extern void ip22_be_interrupt(int irq);
261 static void indy_buserror_irq(void)
263 int irq = SGI_BUSERR_IRQ;
266 kstat_this_cpu.irqs[irq]++;
267 ip22_be_interrupt(irq);
271 static struct irqaction local0_cascade = {
272 .handler = no_action,
273 .flags = IRQF_DISABLED,
274 .name = "local0 cascade",
277 static struct irqaction local1_cascade = {
278 .handler = no_action,
279 .flags = IRQF_DISABLED,
280 .name = "local1 cascade",
283 static struct irqaction buserr = {
284 .handler = no_action,
285 .flags = IRQF_DISABLED,
289 static struct irqaction map0_cascade = {
290 .handler = no_action,
291 .flags = IRQF_DISABLED,
292 .name = "mapable0 cascade",
296 static struct irqaction map1_cascade = {
297 .handler = no_action,
298 .flags = IRQF_DISABLED,
299 .name = "mapable1 cascade",
301 #define SGI_INTERRUPTS SGINT_END
303 #define SGI_INTERRUPTS SGINT_LOCAL3
306 extern void indy_r4k_timer_interrupt(void);
307 extern void indy_8254timer_irq(void);
310 * IRQs on the INDY look basically (barring software IRQs which we don't use
315 * 0 Software (ignored)
316 * 1 Software (ignored)
317 * 2 Local IRQ level zero
318 * 3 Local IRQ level one
322 * 7 R4k timer (what we use)
324 * We handle the IRQ according to _our_ priority which is:
326 * Highest ---- R4k Timer
331 * Lowest ---- 8254 Timer one
333 * then we just return, if multiple IRQs are pending then we will just take
334 * another exception, big deal.
337 asmlinkage void plat_irq_dispatch(void)
339 unsigned int pending = read_c0_cause();
342 * First we check for r4k counter/timer IRQ.
344 if (pending & CAUSEF_IP7)
345 indy_r4k_timer_interrupt();
346 else if (pending & CAUSEF_IP2)
347 indy_local0_irqdispatch();
348 else if (pending & CAUSEF_IP3)
349 indy_local1_irqdispatch();
350 else if (pending & CAUSEF_IP6)
352 else if (pending & (CAUSEF_IP4 | CAUSEF_IP5))
353 indy_8254timer_irq();
356 extern void mips_cpu_irq_init(unsigned int irq_base);
358 void __init arch_init_irq(void)
362 /* Init local mask --> irq tables. */
363 for (i = 0; i < 256; i++) {
365 lc0msk_to_irqnr[i] = SGINT_LOCAL0 + 7;
366 lc1msk_to_irqnr[i] = SGINT_LOCAL1 + 7;
367 lc2msk_to_irqnr[i] = SGINT_LOCAL2 + 7;
368 lc3msk_to_irqnr[i] = SGINT_LOCAL3 + 7;
369 } else if (i & 0x40) {
370 lc0msk_to_irqnr[i] = SGINT_LOCAL0 + 6;
371 lc1msk_to_irqnr[i] = SGINT_LOCAL1 + 6;
372 lc2msk_to_irqnr[i] = SGINT_LOCAL2 + 6;
373 lc3msk_to_irqnr[i] = SGINT_LOCAL3 + 6;
374 } else if (i & 0x20) {
375 lc0msk_to_irqnr[i] = SGINT_LOCAL0 + 5;
376 lc1msk_to_irqnr[i] = SGINT_LOCAL1 + 5;
377 lc2msk_to_irqnr[i] = SGINT_LOCAL2 + 5;
378 lc3msk_to_irqnr[i] = SGINT_LOCAL3 + 5;
379 } else if (i & 0x10) {
380 lc0msk_to_irqnr[i] = SGINT_LOCAL0 + 4;
381 lc1msk_to_irqnr[i] = SGINT_LOCAL1 + 4;
382 lc2msk_to_irqnr[i] = SGINT_LOCAL2 + 4;
383 lc3msk_to_irqnr[i] = SGINT_LOCAL3 + 4;
384 } else if (i & 0x08) {
385 lc0msk_to_irqnr[i] = SGINT_LOCAL0 + 3;
386 lc1msk_to_irqnr[i] = SGINT_LOCAL1 + 3;
387 lc2msk_to_irqnr[i] = SGINT_LOCAL2 + 3;
388 lc3msk_to_irqnr[i] = SGINT_LOCAL3 + 3;
389 } else if (i & 0x04) {
390 lc0msk_to_irqnr[i] = SGINT_LOCAL0 + 2;
391 lc1msk_to_irqnr[i] = SGINT_LOCAL1 + 2;
392 lc2msk_to_irqnr[i] = SGINT_LOCAL2 + 2;
393 lc3msk_to_irqnr[i] = SGINT_LOCAL3 + 2;
394 } else if (i & 0x02) {
395 lc0msk_to_irqnr[i] = SGINT_LOCAL0 + 1;
396 lc1msk_to_irqnr[i] = SGINT_LOCAL1 + 1;
397 lc2msk_to_irqnr[i] = SGINT_LOCAL2 + 1;
398 lc3msk_to_irqnr[i] = SGINT_LOCAL3 + 1;
399 } else if (i & 0x01) {
400 lc0msk_to_irqnr[i] = SGINT_LOCAL0 + 0;
401 lc1msk_to_irqnr[i] = SGINT_LOCAL1 + 0;
402 lc2msk_to_irqnr[i] = SGINT_LOCAL2 + 0;
403 lc3msk_to_irqnr[i] = SGINT_LOCAL3 + 0;
405 lc0msk_to_irqnr[i] = 0;
406 lc1msk_to_irqnr[i] = 0;
407 lc2msk_to_irqnr[i] = 0;
408 lc3msk_to_irqnr[i] = 0;
412 /* Mask out all interrupts. */
415 sgint->cmeimask0 = 0;
416 sgint->cmeimask1 = 0;
419 mips_cpu_irq_init(SGINT_CPU);
421 for (i = SGINT_LOCAL0; i < SGI_INTERRUPTS; i++) {
422 struct irq_chip *handler;
424 if (i < SGINT_LOCAL1)
425 handler = &ip22_local0_irq_type;
426 else if (i < SGINT_LOCAL2)
427 handler = &ip22_local1_irq_type;
428 else if (i < SGINT_LOCAL3)
429 handler = &ip22_local2_irq_type;
431 handler = &ip22_local3_irq_type;
433 irq_desc[i].status = IRQ_DISABLED;
434 irq_desc[i].action = 0;
435 irq_desc[i].depth = 1;
436 irq_desc[i].chip = handler;
439 /* vector handler. this register the IRQ as non-sharable */
440 setup_irq(SGI_LOCAL_0_IRQ, &local0_cascade);
441 setup_irq(SGI_LOCAL_1_IRQ, &local1_cascade);
442 setup_irq(SGI_BUSERR_IRQ, &buserr);
444 /* cascade in cascade. i love Indy ;-) */
445 setup_irq(SGI_MAP_0_IRQ, &map0_cascade);
447 setup_irq(SGI_MAP_1_IRQ, &map1_cascade);
451 if (ip22_is_fullhouse()) /* Only Indigo-2 has EISA stuff */