import of upstream 2.4.34.4 from kernel.org
[linux-2.4.git] / arch / mips / mips-boards / atlas / atlas_int.c
1 /*
2  * Carsten Langgaard, carstenl@mips.com
3  * Copyright (C) 1999,2000 MIPS Technologies, Inc.  All rights reserved.
4  *
5  * ########################################################################
6  *
7  *  This program is free software; you can distribute it and/or modify it
8  *  under the terms of the GNU General Public License (Version 2) as
9  *  published by the Free Software Foundation.
10  *
11  *  This program is distributed in the hope it will be useful, but WITHOUT
12  *  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  *  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14  *  for more details.
15  *
16  *  You should have received a copy of the GNU General Public License along
17  *  with this program; if not, write to the Free Software Foundation, Inc.,
18  *  59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
19  *
20  * ########################################################################
21  *
22  * Routines for generic manipulation of the interrupts found on the MIPS
23  * Atlas board.
24  *
25  */
26 #include <linux/config.h>
27 #include <linux/init.h>
28 #include <linux/sched.h>
29 #include <linux/slab.h>
30 #include <linux/interrupt.h>
31 #include <linux/kernel_stat.h>
32
33 #include <asm/irq.h>
34 #include <asm/mips-boards/atlas.h>
35 #include <asm/mips-boards/atlasint.h>
36 #include <asm/gdb-stub.h>
37
38
39 struct atlas_ictrl_regs *atlas_hw0_icregs
40         = (struct atlas_ictrl_regs *)ATLAS_ICTRL_REGS_BASE;
41
42 extern asmlinkage void mipsIRQ(void);
43
44 #if 0
45 #define DEBUG_INT(x...) printk(x)
46 #else
47 #define DEBUG_INT(x...)
48 #endif
49
50 void disable_atlas_irq(unsigned int irq_nr)
51 {
52         atlas_hw0_icregs->intrsten = (1 << irq_nr);
53 }
54
55 void enable_atlas_irq(unsigned int irq_nr)
56 {
57         atlas_hw0_icregs->intseten = (1 << irq_nr);
58 }
59
60 static unsigned int startup_atlas_irq(unsigned int irq)
61 {
62         enable_atlas_irq(irq);
63         return 0; /* never anything pending */
64 }
65
66 #define shutdown_atlas_irq      disable_atlas_irq
67
68 #define mask_and_ack_atlas_irq disable_atlas_irq
69
70 static void end_atlas_irq(unsigned int irq)
71 {
72         if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
73                 enable_atlas_irq(irq);
74 }
75
76 static struct hw_interrupt_type atlas_irq_type = {
77         "Atlas",
78         startup_atlas_irq,
79         shutdown_atlas_irq,
80         enable_atlas_irq,
81         disable_atlas_irq,
82         mask_and_ack_atlas_irq,
83         end_atlas_irq,
84         NULL
85 };
86
87 static inline int ls1bit32(unsigned int x)
88 {
89         int b = 31, s;
90
91         s = 16; if (x << 16 == 0) s = 0; b -= s; x <<= s;
92         s =  8; if (x <<  8 == 0) s = 0; b -= s; x <<= s;
93         s =  4; if (x <<  4 == 0) s = 0; b -= s; x <<= s;
94         s =  2; if (x <<  2 == 0) s = 0; b -= s; x <<= s;
95         s =  1; if (x <<  1 == 0) s = 0; b -= s;
96
97         return b;
98 }
99
100 void atlas_hw0_irqdispatch(struct pt_regs *regs)
101 {
102         struct irqaction *action;
103         unsigned long int_status;
104         int irq, cpu = smp_processor_id();
105
106         int_status = atlas_hw0_icregs->intstatus;
107
108         /* if int_status == 0, then the interrupt has already been cleared */
109         if (int_status == 0)
110                 return;
111
112         irq = ls1bit32(int_status);
113         action = irq_desc[irq].action;
114
115         DEBUG_INT("atlas_hw0_irqdispatch: irq=%d\n", irq);
116
117         /* if action == NULL, then we don't have a handler for the irq */
118         if (action == NULL) {
119                 printk("No handler for hw0 irq: %i\n", irq);
120                 atomic_inc(&irq_err_count);
121                 return;
122         }
123
124         irq_enter(cpu, irq);
125         kstat.irqs[0][irq]++;
126         action->handler(irq, action->dev_id, regs);
127         irq_exit(cpu, irq);
128
129         return;
130 }
131
132 #ifdef CONFIG_KGDB
133 extern void breakpoint(void);
134 extern int remote_debug;
135 #endif
136
137 void __init init_IRQ(void)
138 {
139         int i;
140
141         /*
142          * Mask out all interrupt by writing "1" to all bit position in
143          * the interrupt reset reg.
144          */
145         atlas_hw0_icregs->intrsten = 0xffffffff;
146
147         /* Now safe to set the exception vector. */
148         set_except_vector(0, mipsIRQ);
149
150         for (i = 0; i <= ATLASINT_END; i++) {
151                 irq_desc[i].status      = IRQ_DISABLED;
152                 irq_desc[i].action      = 0;
153                 irq_desc[i].depth       = 1;
154                 irq_desc[i].handler     = &atlas_irq_type;
155         }
156
157 #ifdef CONFIG_KGDB
158         if (remote_debug) {
159                 set_debug_traps();
160                 breakpoint();
161         }
162 #endif
163 }