blob: 0ecd5fe9486ee183e750c014f6d2cfb3283bff9a [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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/interrupt.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016
Atsushi Nemoto97dcb822007-01-08 02:14:29 +090017#include <asm/irq_cpu.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <asm/sgi/hpc3.h>
19#include <asm/sgi/ip22.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
21/* So far nothing hangs here */
Ralf Baechle42a3b4f2005-09-03 15:56:17 -070022#undef USE_LIO3_IRQ
Linus Torvalds1da177e2005-04-16 15:20:36 -070023
24struct sgint_regs *sgint;
25
26static char lc0msk_to_irqnr[256];
27static char lc1msk_to_irqnr[256];
28static char lc2msk_to_irqnr[256];
29static char lc3msk_to_irqnr[256];
30
Linus Torvalds1da177e2005-04-16 15:20:36 -070031extern int ip22_eisa_init(void);
32
33static void enable_local0_irq(unsigned int irq)
34{
Linus Torvalds1da177e2005-04-16 15:20:36 -070035 /* don't allow mappable interrupt to be enabled from setup_irq,
36 * we have our own way to do so */
37 if (irq != SGI_MAP_0_IRQ)
38 sgint->imask0 |= (1 << (irq - SGINT_LOCAL0));
Linus Torvalds1da177e2005-04-16 15:20:36 -070039}
40
41static void disable_local0_irq(unsigned int irq)
42{
Linus Torvalds1da177e2005-04-16 15:20:36 -070043 sgint->imask0 &= ~(1 << (irq - SGINT_LOCAL0));
Linus Torvalds1da177e2005-04-16 15:20:36 -070044}
45
Ralf Baechle94dee172006-07-02 14:41:42 +010046static struct irq_chip ip22_local0_irq_type = {
Atsushi Nemoto70d21cd2007-01-15 00:07:25 +090047 .name = "IP22 local 0",
Atsushi Nemoto1603b5a2006-11-02 02:08:36 +090048 .ack = disable_local0_irq,
49 .mask = disable_local0_irq,
50 .mask_ack = disable_local0_irq,
51 .unmask = enable_local0_irq,
Linus Torvalds1da177e2005-04-16 15:20:36 -070052};
53
54static void enable_local1_irq(unsigned int irq)
55{
Linus Torvalds1da177e2005-04-16 15:20:36 -070056 /* don't allow mappable interrupt to be enabled from setup_irq,
57 * we have our own way to do so */
58 if (irq != SGI_MAP_1_IRQ)
59 sgint->imask1 |= (1 << (irq - SGINT_LOCAL1));
Linus Torvalds1da177e2005-04-16 15:20:36 -070060}
61
Dmitri Vorobiev14823cc2008-10-25 01:46:56 +030062static void disable_local1_irq(unsigned int irq)
Linus Torvalds1da177e2005-04-16 15:20:36 -070063{
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 sgint->imask1 &= ~(1 << (irq - SGINT_LOCAL1));
Linus Torvalds1da177e2005-04-16 15:20:36 -070065}
66
Ralf Baechle94dee172006-07-02 14:41:42 +010067static struct irq_chip ip22_local1_irq_type = {
Atsushi Nemoto70d21cd2007-01-15 00:07:25 +090068 .name = "IP22 local 1",
Atsushi Nemoto1603b5a2006-11-02 02:08:36 +090069 .ack = disable_local1_irq,
70 .mask = disable_local1_irq,
71 .mask_ack = disable_local1_irq,
72 .unmask = enable_local1_irq,
Linus Torvalds1da177e2005-04-16 15:20:36 -070073};
74
75static void enable_local2_irq(unsigned int irq)
76{
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 sgint->imask0 |= (1 << (SGI_MAP_0_IRQ - SGINT_LOCAL0));
78 sgint->cmeimask0 |= (1 << (irq - SGINT_LOCAL2));
Linus Torvalds1da177e2005-04-16 15:20:36 -070079}
80
Dmitri Vorobiev14823cc2008-10-25 01:46:56 +030081static void disable_local2_irq(unsigned int irq)
Linus Torvalds1da177e2005-04-16 15:20:36 -070082{
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 sgint->cmeimask0 &= ~(1 << (irq - SGINT_LOCAL2));
84 if (!sgint->cmeimask0)
85 sgint->imask0 &= ~(1 << (SGI_MAP_0_IRQ - SGINT_LOCAL0));
Linus Torvalds1da177e2005-04-16 15:20:36 -070086}
87
Ralf Baechle94dee172006-07-02 14:41:42 +010088static struct irq_chip ip22_local2_irq_type = {
Atsushi Nemoto70d21cd2007-01-15 00:07:25 +090089 .name = "IP22 local 2",
Atsushi Nemoto1603b5a2006-11-02 02:08:36 +090090 .ack = disable_local2_irq,
91 .mask = disable_local2_irq,
92 .mask_ack = disable_local2_irq,
93 .unmask = enable_local2_irq,
Linus Torvalds1da177e2005-04-16 15:20:36 -070094};
95
96static void enable_local3_irq(unsigned int irq)
97{
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 sgint->imask1 |= (1 << (SGI_MAP_1_IRQ - SGINT_LOCAL1));
99 sgint->cmeimask1 |= (1 << (irq - SGINT_LOCAL3));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100}
101
Dmitri Vorobiev14823cc2008-10-25 01:46:56 +0300102static void disable_local3_irq(unsigned int irq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 sgint->cmeimask1 &= ~(1 << (irq - SGINT_LOCAL3));
105 if (!sgint->cmeimask1)
106 sgint->imask1 &= ~(1 << (SGI_MAP_1_IRQ - SGINT_LOCAL1));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107}
108
Ralf Baechle94dee172006-07-02 14:41:42 +0100109static struct irq_chip ip22_local3_irq_type = {
Atsushi Nemoto70d21cd2007-01-15 00:07:25 +0900110 .name = "IP22 local 3",
Atsushi Nemoto1603b5a2006-11-02 02:08:36 +0900111 .ack = disable_local3_irq,
112 .mask = disable_local3_irq,
113 .mask_ack = disable_local3_irq,
114 .unmask = enable_local3_irq,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115};
116
Ralf Baechle937a8012006-10-07 19:44:33 +0100117static void indy_local0_irqdispatch(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118{
119 u8 mask = sgint->istat0 & sgint->imask0;
120 u8 mask2;
121 int irq;
122
123 if (mask & SGINT_ISTAT0_LIO2) {
124 mask2 = sgint->vmeistat & sgint->cmeimask0;
125 irq = lc2msk_to_irqnr[mask2];
126 } else
127 irq = lc0msk_to_irqnr[mask];
128
129 /* if irq == 0, then the interrupt has already been cleared */
130 if (irq)
Ralf Baechle937a8012006-10-07 19:44:33 +0100131 do_IRQ(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132}
133
Ralf Baechle937a8012006-10-07 19:44:33 +0100134static void indy_local1_irqdispatch(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135{
136 u8 mask = sgint->istat1 & sgint->imask1;
137 u8 mask2;
138 int irq;
139
140 if (mask & SGINT_ISTAT1_LIO3) {
141 mask2 = sgint->vmeistat & sgint->cmeimask1;
142 irq = lc3msk_to_irqnr[mask2];
143 } else
144 irq = lc1msk_to_irqnr[mask];
145
146 /* if irq == 0, then the interrupt has already been cleared */
147 if (irq)
Ralf Baechle937a8012006-10-07 19:44:33 +0100148 do_IRQ(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149}
150
Ralf Baechle937a8012006-10-07 19:44:33 +0100151extern void ip22_be_interrupt(int irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152
Ralf Baechle937a8012006-10-07 19:44:33 +0100153static void indy_buserror_irq(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154{
155 int irq = SGI_BUSERR_IRQ;
156
157 irq_enter();
Mike Travisd2287f52009-01-14 15:43:54 -0800158 kstat_incr_irqs_this_cpu(irq, irq_to_desc(irq));
Ralf Baechle937a8012006-10-07 19:44:33 +0100159 ip22_be_interrupt(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 irq_exit();
161}
162
Ralf Baechle42a3b4f2005-09-03 15:56:17 -0700163static struct irqaction local0_cascade = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 .handler = no_action,
Thomas Gleixnerf40298f2006-07-01 19:29:20 -0700165 .flags = IRQF_DISABLED,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 .name = "local0 cascade",
167};
168
Ralf Baechle42a3b4f2005-09-03 15:56:17 -0700169static struct irqaction local1_cascade = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 .handler = no_action,
Thomas Gleixnerf40298f2006-07-01 19:29:20 -0700171 .flags = IRQF_DISABLED,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 .name = "local1 cascade",
173};
174
Ralf Baechle42a3b4f2005-09-03 15:56:17 -0700175static struct irqaction buserr = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 .handler = no_action,
Thomas Gleixnerf40298f2006-07-01 19:29:20 -0700177 .flags = IRQF_DISABLED,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 .name = "Bus Error",
179};
180
Ralf Baechle42a3b4f2005-09-03 15:56:17 -0700181static struct irqaction map0_cascade = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 .handler = no_action,
Thomas Gleixnerf40298f2006-07-01 19:29:20 -0700183 .flags = IRQF_DISABLED,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 .name = "mapable0 cascade",
185};
186
187#ifdef USE_LIO3_IRQ
Ralf Baechle42a3b4f2005-09-03 15:56:17 -0700188static struct irqaction map1_cascade = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 .handler = no_action,
Thomas Gleixnerf40298f2006-07-01 19:29:20 -0700190 .flags = IRQF_DISABLED,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 .name = "mapable1 cascade",
192};
193#define SGI_INTERRUPTS SGINT_END
194#else
195#define SGI_INTERRUPTS SGINT_LOCAL3
196#endif
197
Ralf Baechle937a8012006-10-07 19:44:33 +0100198extern void indy_8254timer_irq(void);
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100199
200/*
201 * IRQs on the INDY look basically (barring software IRQs which we don't use
202 * at all) like:
203 *
204 * MIPS IRQ Source
205 * -------- ------
206 * 0 Software (ignored)
207 * 1 Software (ignored)
208 * 2 Local IRQ level zero
209 * 3 Local IRQ level one
210 * 4 8254 Timer zero
211 * 5 8254 Timer one
212 * 6 Bus Error
213 * 7 R4k timer (what we use)
214 *
215 * We handle the IRQ according to _our_ priority which is:
216 *
217 * Highest ---- R4k Timer
218 * Local IRQ zero
219 * Local IRQ one
220 * Bus Error
221 * 8254 Timer zero
222 * Lowest ---- 8254 Timer one
223 *
224 * then we just return, if multiple IRQs are pending then we will just take
225 * another exception, big deal.
226 */
227
Ralf Baechle937a8012006-10-07 19:44:33 +0100228asmlinkage void plat_irq_dispatch(void)
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100229{
Thiemo Seufer119537c2007-03-19 00:13:37 +0000230 unsigned int pending = read_c0_status() & read_c0_cause();
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100231
232 /*
233 * First we check for r4k counter/timer IRQ.
234 */
235 if (pending & CAUSEF_IP7)
Ralf Baechle7bcf7712007-10-11 23:46:09 +0100236 do_IRQ(SGI_TIMER_IRQ);
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100237 else if (pending & CAUSEF_IP2)
Ralf Baechle937a8012006-10-07 19:44:33 +0100238 indy_local0_irqdispatch();
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100239 else if (pending & CAUSEF_IP3)
Ralf Baechle937a8012006-10-07 19:44:33 +0100240 indy_local1_irqdispatch();
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100241 else if (pending & CAUSEF_IP6)
Ralf Baechle937a8012006-10-07 19:44:33 +0100242 indy_buserror_irq();
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100243 else if (pending & (CAUSEF_IP4 | CAUSEF_IP5))
Ralf Baechle937a8012006-10-07 19:44:33 +0100244 indy_8254timer_irq();
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100245}
246
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247void __init arch_init_irq(void)
248{
249 int i;
250
251 /* Init local mask --> irq tables. */
252 for (i = 0; i < 256; i++) {
253 if (i & 0x80) {
254 lc0msk_to_irqnr[i] = SGINT_LOCAL0 + 7;
255 lc1msk_to_irqnr[i] = SGINT_LOCAL1 + 7;
256 lc2msk_to_irqnr[i] = SGINT_LOCAL2 + 7;
257 lc3msk_to_irqnr[i] = SGINT_LOCAL3 + 7;
258 } else if (i & 0x40) {
259 lc0msk_to_irqnr[i] = SGINT_LOCAL0 + 6;
260 lc1msk_to_irqnr[i] = SGINT_LOCAL1 + 6;
261 lc2msk_to_irqnr[i] = SGINT_LOCAL2 + 6;
262 lc3msk_to_irqnr[i] = SGINT_LOCAL3 + 6;
263 } else if (i & 0x20) {
264 lc0msk_to_irqnr[i] = SGINT_LOCAL0 + 5;
265 lc1msk_to_irqnr[i] = SGINT_LOCAL1 + 5;
266 lc2msk_to_irqnr[i] = SGINT_LOCAL2 + 5;
267 lc3msk_to_irqnr[i] = SGINT_LOCAL3 + 5;
268 } else if (i & 0x10) {
269 lc0msk_to_irqnr[i] = SGINT_LOCAL0 + 4;
270 lc1msk_to_irqnr[i] = SGINT_LOCAL1 + 4;
271 lc2msk_to_irqnr[i] = SGINT_LOCAL2 + 4;
272 lc3msk_to_irqnr[i] = SGINT_LOCAL3 + 4;
273 } else if (i & 0x08) {
274 lc0msk_to_irqnr[i] = SGINT_LOCAL0 + 3;
275 lc1msk_to_irqnr[i] = SGINT_LOCAL1 + 3;
276 lc2msk_to_irqnr[i] = SGINT_LOCAL2 + 3;
277 lc3msk_to_irqnr[i] = SGINT_LOCAL3 + 3;
278 } else if (i & 0x04) {
279 lc0msk_to_irqnr[i] = SGINT_LOCAL0 + 2;
280 lc1msk_to_irqnr[i] = SGINT_LOCAL1 + 2;
281 lc2msk_to_irqnr[i] = SGINT_LOCAL2 + 2;
282 lc3msk_to_irqnr[i] = SGINT_LOCAL3 + 2;
283 } else if (i & 0x02) {
284 lc0msk_to_irqnr[i] = SGINT_LOCAL0 + 1;
285 lc1msk_to_irqnr[i] = SGINT_LOCAL1 + 1;
286 lc2msk_to_irqnr[i] = SGINT_LOCAL2 + 1;
287 lc3msk_to_irqnr[i] = SGINT_LOCAL3 + 1;
288 } else if (i & 0x01) {
289 lc0msk_to_irqnr[i] = SGINT_LOCAL0 + 0;
290 lc1msk_to_irqnr[i] = SGINT_LOCAL1 + 0;
291 lc2msk_to_irqnr[i] = SGINT_LOCAL2 + 0;
292 lc3msk_to_irqnr[i] = SGINT_LOCAL3 + 0;
293 } else {
294 lc0msk_to_irqnr[i] = 0;
295 lc1msk_to_irqnr[i] = 0;
296 lc2msk_to_irqnr[i] = 0;
297 lc3msk_to_irqnr[i] = 0;
298 }
299 }
300
301 /* Mask out all interrupts. */
302 sgint->imask0 = 0;
303 sgint->imask1 = 0;
304 sgint->cmeimask0 = 0;
305 sgint->cmeimask1 = 0;
306
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 /* init CPU irqs */
Atsushi Nemoto97dcb822007-01-08 02:14:29 +0900308 mips_cpu_irq_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309
310 for (i = SGINT_LOCAL0; i < SGI_INTERRUPTS; i++) {
Ralf Baechle94dee172006-07-02 14:41:42 +0100311 struct irq_chip *handler;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312
313 if (i < SGINT_LOCAL1)
314 handler = &ip22_local0_irq_type;
315 else if (i < SGINT_LOCAL2)
316 handler = &ip22_local1_irq_type;
317 else if (i < SGINT_LOCAL3)
318 handler = &ip22_local2_irq_type;
319 else
320 handler = &ip22_local3_irq_type;
321
Atsushi Nemoto14178362006-11-14 01:13:18 +0900322 set_irq_chip_and_handler(i, handler, handle_level_irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 }
324
325 /* vector handler. this register the IRQ as non-sharable */
326 setup_irq(SGI_LOCAL_0_IRQ, &local0_cascade);
327 setup_irq(SGI_LOCAL_1_IRQ, &local1_cascade);
328 setup_irq(SGI_BUSERR_IRQ, &buserr);
329
330 /* cascade in cascade. i love Indy ;-) */
331 setup_irq(SGI_MAP_0_IRQ, &map0_cascade);
332#ifdef USE_LIO3_IRQ
333 setup_irq(SGI_MAP_1_IRQ, &map1_cascade);
334#endif
335
336#ifdef CONFIG_EISA
337 if (ip22_is_fullhouse()) /* Only Indigo-2 has EISA stuff */
Dmitri Vorobiev14823cc2008-10-25 01:46:56 +0300338 ip22_eisa_init();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339#endif
340}