Merge branch 'irqclean-submit1' of master.kernel.org:/pub/scm/linux/kernel/git/jgarzi...
[linux-2.6] / arch / mips / sgi-ip22 / ip22-int.c
1 /*
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  */
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>
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 */
30 #undef USE_LIO3_IRQ
31
32 struct sgint_regs *sgint;
33
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];
38
39 extern int ip22_eisa_init(void);
40
41 static 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
53 static unsigned int startup_local0_irq(unsigned int irq)
54 {
55         enable_local0_irq(irq);
56         return 0;               /* Never anything pending  */
57 }
58
59 static 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
71 static 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
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,
85 };
86
87 static 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
99 static unsigned int startup_local1_irq(unsigned int irq)
100 {
101         enable_local1_irq(irq);
102         return 0;               /* Never anything pending  */
103 }
104
105 void 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
117 static 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
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,
131 };
132
133 static 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
143 static unsigned int startup_local2_irq(unsigned int irq)
144 {
145         enable_local2_irq(irq);
146         return 0;               /* Never anything pending  */
147 }
148
149 void 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
163 static 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
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,
177 };
178
179 static 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
189 static unsigned int startup_local3_irq(unsigned int irq)
190 {
191         enable_local3_irq(irq);
192         return 0;               /* Never anything pending  */
193 }
194
195 void 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
209 static 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
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,
223 };
224
225 static void indy_local0_irqdispatch(void)
226 {
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)
239                 do_IRQ(irq);
240 }
241
242 static void indy_local1_irqdispatch(void)
243 {
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)
256                 do_IRQ(irq);
257 }
258
259 extern void ip22_be_interrupt(int irq);
260
261 static void indy_buserror_irq(void)
262 {
263         int irq = SGI_BUSERR_IRQ;
264
265         irq_enter();
266         kstat_this_cpu.irqs[irq]++;
267         ip22_be_interrupt(irq);
268         irq_exit();
269 }
270
271 static struct irqaction local0_cascade = {
272         .handler        = no_action,
273         .flags          = IRQF_DISABLED,
274         .name           = "local0 cascade",
275 };
276
277 static struct irqaction local1_cascade = {
278         .handler        = no_action,
279         .flags          = IRQF_DISABLED,
280         .name           = "local1 cascade",
281 };
282
283 static struct irqaction buserr = {
284         .handler        = no_action,
285         .flags          = IRQF_DISABLED,
286         .name           = "Bus Error",
287 };
288
289 static struct irqaction map0_cascade = {
290         .handler        = no_action,
291         .flags          = IRQF_DISABLED,
292         .name           = "mapable0 cascade",
293 };
294
295 #ifdef USE_LIO3_IRQ
296 static struct irqaction map1_cascade = {
297         .handler        = no_action,
298         .flags          = IRQF_DISABLED,
299         .name           = "mapable1 cascade",
300 };
301 #define SGI_INTERRUPTS  SGINT_END
302 #else
303 #define SGI_INTERRUPTS  SGINT_LOCAL3
304 #endif
305
306 extern void indy_r4k_timer_interrupt(void);
307 extern void indy_8254timer_irq(void);
308
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
337 asmlinkage void plat_irq_dispatch(void)
338 {
339         unsigned int pending = read_c0_cause();
340
341         /*
342          * First we check for r4k counter/timer IRQ.
343          */
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)
351                 indy_buserror_irq();
352         else if (pending & (CAUSEF_IP4 | CAUSEF_IP5))
353                 indy_8254timer_irq();
354 }
355
356 extern void mips_cpu_irq_init(unsigned int irq_base);
357
358 void __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
418         /* init CPU irqs */
419         mips_cpu_irq_init(SGINT_CPU);
420
421         for (i = SGINT_LOCAL0; i < SGI_INTERRUPTS; i++) {
422                 struct irq_chip *handler;
423
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;
436                 irq_desc[i].chip        = handler;
437         }
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 }