blob: af518898eaa147a04fa349eebc3c1f97bbf6976d [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * ip22-int.c: Routines for generic manipulation of the INT[23] ASIC
3 * found on INDY and Indigo2 workstations.
4 *
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)
8 * - Indigo2 changes
9 * - Interrupt handling fixes
10 * Copyright (C) 2001, 2003 Ladislav Michl (ladis@linux-mips.org)
11 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#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>
19
20#include <asm/mipsregs.h>
21#include <asm/addrspace.h>
22
23#include <asm/sgi/ioc.h>
24#include <asm/sgi/hpc3.h>
25#include <asm/sgi/ip22.h>
26
27/* #define DEBUG_SGINT */
28
29/* So far nothing hangs here */
Ralf Baechle42a3b4f2005-09-03 15:56:17 -070030#undef USE_LIO3_IRQ
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
32struct sgint_regs *sgint;
33
34static char lc0msk_to_irqnr[256];
35static char lc1msk_to_irqnr[256];
36static char lc2msk_to_irqnr[256];
37static char lc3msk_to_irqnr[256];
38
Linus Torvalds1da177e2005-04-16 15:20:36 -070039extern int ip22_eisa_init(void);
40
41static void enable_local0_irq(unsigned int irq)
42{
43 unsigned long flags;
44
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);
51}
52
53static unsigned int startup_local0_irq(unsigned int irq)
54{
55 enable_local0_irq(irq);
56 return 0; /* Never anything pending */
57}
58
59static void disable_local0_irq(unsigned int irq)
60{
61 unsigned long flags;
62
63 local_irq_save(flags);
64 sgint->imask0 &= ~(1 << (irq - SGINT_LOCAL0));
65 local_irq_restore(flags);
66}
67
68#define shutdown_local0_irq disable_local0_irq
69#define mask_and_ack_local0_irq disable_local0_irq
70
71static void end_local0_irq (unsigned int irq)
72{
73 if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
74 enable_local0_irq(irq);
75}
76
Ralf Baechle94dee172006-07-02 14:41:42 +010077static struct irq_chip ip22_local0_irq_type = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 .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,
85};
86
87static void enable_local1_irq(unsigned int irq)
88{
89 unsigned long flags;
90
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);
97}
98
99static unsigned int startup_local1_irq(unsigned int irq)
100{
101 enable_local1_irq(irq);
102 return 0; /* Never anything pending */
103}
104
105void disable_local1_irq(unsigned int irq)
106{
107 unsigned long flags;
108
109 local_irq_save(flags);
110 sgint->imask1 &= ~(1 << (irq - SGINT_LOCAL1));
111 local_irq_restore(flags);
112}
113
114#define shutdown_local1_irq disable_local1_irq
115#define mask_and_ack_local1_irq disable_local1_irq
116
117static void end_local1_irq (unsigned int irq)
118{
119 if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
120 enable_local1_irq(irq);
121}
122
Ralf Baechle94dee172006-07-02 14:41:42 +0100123static struct irq_chip ip22_local1_irq_type = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 .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,
131};
132
133static void enable_local2_irq(unsigned int irq)
134{
135 unsigned long flags;
136
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);
141}
142
143static unsigned int startup_local2_irq(unsigned int irq)
144{
145 enable_local2_irq(irq);
146 return 0; /* Never anything pending */
147}
148
149void disable_local2_irq(unsigned int irq)
150{
151 unsigned long flags;
152
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);
158}
159
160#define shutdown_local2_irq disable_local2_irq
161#define mask_and_ack_local2_irq disable_local2_irq
162
163static void end_local2_irq (unsigned int irq)
164{
165 if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
166 enable_local2_irq(irq);
167}
168
Ralf Baechle94dee172006-07-02 14:41:42 +0100169static struct irq_chip ip22_local2_irq_type = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 .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,
177};
178
179static void enable_local3_irq(unsigned int irq)
180{
181 unsigned long flags;
182
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);
187}
188
189static unsigned int startup_local3_irq(unsigned int irq)
190{
191 enable_local3_irq(irq);
192 return 0; /* Never anything pending */
193}
194
195void disable_local3_irq(unsigned int irq)
196{
197 unsigned long flags;
198
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);
204}
205
206#define shutdown_local3_irq disable_local3_irq
207#define mask_and_ack_local3_irq disable_local3_irq
208
209static void end_local3_irq (unsigned int irq)
210{
211 if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
212 enable_local3_irq(irq);
213}
214
Ralf Baechle94dee172006-07-02 14:41:42 +0100215static struct irq_chip ip22_local3_irq_type = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 .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,
223};
224
Ralf Baechle937a8012006-10-07 19:44:33 +0100225static void indy_local0_irqdispatch(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226{
227 u8 mask = sgint->istat0 & sgint->imask0;
228 u8 mask2;
229 int irq;
230
231 if (mask & SGINT_ISTAT0_LIO2) {
232 mask2 = sgint->vmeistat & sgint->cmeimask0;
233 irq = lc2msk_to_irqnr[mask2];
234 } else
235 irq = lc0msk_to_irqnr[mask];
236
237 /* if irq == 0, then the interrupt has already been cleared */
238 if (irq)
Ralf Baechle937a8012006-10-07 19:44:33 +0100239 do_IRQ(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240}
241
Ralf Baechle937a8012006-10-07 19:44:33 +0100242static void indy_local1_irqdispatch(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243{
244 u8 mask = sgint->istat1 & sgint->imask1;
245 u8 mask2;
246 int irq;
247
248 if (mask & SGINT_ISTAT1_LIO3) {
249 mask2 = sgint->vmeistat & sgint->cmeimask1;
250 irq = lc3msk_to_irqnr[mask2];
251 } else
252 irq = lc1msk_to_irqnr[mask];
253
254 /* if irq == 0, then the interrupt has already been cleared */
255 if (irq)
Ralf Baechle937a8012006-10-07 19:44:33 +0100256 do_IRQ(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257}
258
Ralf Baechle937a8012006-10-07 19:44:33 +0100259extern void ip22_be_interrupt(int irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260
Ralf Baechle937a8012006-10-07 19:44:33 +0100261static void indy_buserror_irq(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262{
263 int irq = SGI_BUSERR_IRQ;
264
265 irq_enter();
266 kstat_this_cpu.irqs[irq]++;
Ralf Baechle937a8012006-10-07 19:44:33 +0100267 ip22_be_interrupt(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 irq_exit();
269}
270
Ralf Baechle42a3b4f2005-09-03 15:56:17 -0700271static struct irqaction local0_cascade = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 .handler = no_action,
Thomas Gleixnerf40298f2006-07-01 19:29:20 -0700273 .flags = IRQF_DISABLED,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 .name = "local0 cascade",
275};
276
Ralf Baechle42a3b4f2005-09-03 15:56:17 -0700277static struct irqaction local1_cascade = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 .handler = no_action,
Thomas Gleixnerf40298f2006-07-01 19:29:20 -0700279 .flags = IRQF_DISABLED,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 .name = "local1 cascade",
281};
282
Ralf Baechle42a3b4f2005-09-03 15:56:17 -0700283static struct irqaction buserr = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 .handler = no_action,
Thomas Gleixnerf40298f2006-07-01 19:29:20 -0700285 .flags = IRQF_DISABLED,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 .name = "Bus Error",
287};
288
Ralf Baechle42a3b4f2005-09-03 15:56:17 -0700289static struct irqaction map0_cascade = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 .handler = no_action,
Thomas Gleixnerf40298f2006-07-01 19:29:20 -0700291 .flags = IRQF_DISABLED,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 .name = "mapable0 cascade",
293};
294
295#ifdef USE_LIO3_IRQ
Ralf Baechle42a3b4f2005-09-03 15:56:17 -0700296static struct irqaction map1_cascade = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 .handler = no_action,
Thomas Gleixnerf40298f2006-07-01 19:29:20 -0700298 .flags = IRQF_DISABLED,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 .name = "mapable1 cascade",
300};
301#define SGI_INTERRUPTS SGINT_END
302#else
303#define SGI_INTERRUPTS SGINT_LOCAL3
304#endif
305
Ralf Baechle937a8012006-10-07 19:44:33 +0100306extern void indy_r4k_timer_interrupt(void);
307extern void indy_8254timer_irq(void);
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100308
309/*
310 * IRQs on the INDY look basically (barring software IRQs which we don't use
311 * at all) like:
312 *
313 * MIPS IRQ Source
314 * -------- ------
315 * 0 Software (ignored)
316 * 1 Software (ignored)
317 * 2 Local IRQ level zero
318 * 3 Local IRQ level one
319 * 4 8254 Timer zero
320 * 5 8254 Timer one
321 * 6 Bus Error
322 * 7 R4k timer (what we use)
323 *
324 * We handle the IRQ according to _our_ priority which is:
325 *
326 * Highest ---- R4k Timer
327 * Local IRQ zero
328 * Local IRQ one
329 * Bus Error
330 * 8254 Timer zero
331 * Lowest ---- 8254 Timer one
332 *
333 * then we just return, if multiple IRQs are pending then we will just take
334 * another exception, big deal.
335 */
336
Ralf Baechle937a8012006-10-07 19:44:33 +0100337asmlinkage void plat_irq_dispatch(void)
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100338{
339 unsigned int pending = read_c0_cause();
340
341 /*
342 * First we check for r4k counter/timer IRQ.
343 */
344 if (pending & CAUSEF_IP7)
Ralf Baechle937a8012006-10-07 19:44:33 +0100345 indy_r4k_timer_interrupt();
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100346 else if (pending & CAUSEF_IP2)
Ralf Baechle937a8012006-10-07 19:44:33 +0100347 indy_local0_irqdispatch();
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100348 else if (pending & CAUSEF_IP3)
Ralf Baechle937a8012006-10-07 19:44:33 +0100349 indy_local1_irqdispatch();
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100350 else if (pending & CAUSEF_IP6)
Ralf Baechle937a8012006-10-07 19:44:33 +0100351 indy_buserror_irq();
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100352 else if (pending & (CAUSEF_IP4 | CAUSEF_IP5))
Ralf Baechle937a8012006-10-07 19:44:33 +0100353 indy_8254timer_irq();
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100354}
355
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356extern void mips_cpu_irq_init(unsigned int irq_base);
357
358void __init arch_init_irq(void)
359{
360 int i;
361
362 /* Init local mask --> irq tables. */
363 for (i = 0; i < 256; i++) {
364 if (i & 0x80) {
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;
404 } else {
405 lc0msk_to_irqnr[i] = 0;
406 lc1msk_to_irqnr[i] = 0;
407 lc2msk_to_irqnr[i] = 0;
408 lc3msk_to_irqnr[i] = 0;
409 }
410 }
411
412 /* Mask out all interrupts. */
413 sgint->imask0 = 0;
414 sgint->imask1 = 0;
415 sgint->cmeimask0 = 0;
416 sgint->cmeimask1 = 0;
417
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 /* init CPU irqs */
419 mips_cpu_irq_init(SGINT_CPU);
420
421 for (i = SGINT_LOCAL0; i < SGI_INTERRUPTS; i++) {
Ralf Baechle94dee172006-07-02 14:41:42 +0100422 struct irq_chip *handler;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423
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;
430 else
431 handler = &ip22_local3_irq_type;
432
433 irq_desc[i].status = IRQ_DISABLED;
434 irq_desc[i].action = 0;
435 irq_desc[i].depth = 1;
Ingo Molnard1bef4e2006-06-29 02:24:36 -0700436 irq_desc[i].chip = handler;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437 }
438
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);
443
444 /* cascade in cascade. i love Indy ;-) */
445 setup_irq(SGI_MAP_0_IRQ, &map0_cascade);
446#ifdef USE_LIO3_IRQ
447 setup_irq(SGI_MAP_1_IRQ, &map1_cascade);
448#endif
449
450#ifdef CONFIG_EISA
451 if (ip22_is_fullhouse()) /* Only Indigo-2 has EISA stuff */
452 ip22_eisa_init ();
453#endif
454}