ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.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/compiler.h>
28 #include <linux/init.h>
29 #include <linux/sched.h>
30 #include <linux/slab.h>
31 #include <linux/interrupt.h>
32 #include <linux/kernel_stat.h>
33
34 #include <asm/irq.h>
35 #include <asm/io.h>
36 #include <asm/mips-boards/atlas.h>
37 #include <asm/mips-boards/atlasint.h>
38 #include <asm/gdb-stub.h>
39
40
41 static struct atlas_ictrl_regs *atlas_hw0_icregs;
42
43 extern asmlinkage void mipsIRQ(void);
44
45 #if 0
46 #define DEBUG_INT(x...) printk(x)
47 #else
48 #define DEBUG_INT(x...)
49 #endif
50
51 void disable_atlas_irq(unsigned int irq_nr)
52 {
53         atlas_hw0_icregs->intrsten = (1 << (irq_nr-ATLASINT_BASE));
54         iob();
55 }
56
57 void enable_atlas_irq(unsigned int irq_nr)
58 {
59         atlas_hw0_icregs->intseten = (1 << (irq_nr-ATLASINT_BASE));
60         iob();
61 }
62
63 static unsigned int startup_atlas_irq(unsigned int irq)
64 {
65         enable_atlas_irq(irq);
66         return 0; /* never anything pending */
67 }
68
69 #define shutdown_atlas_irq      disable_atlas_irq
70
71 #define mask_and_ack_atlas_irq disable_atlas_irq
72
73 static void end_atlas_irq(unsigned int irq)
74 {
75         if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
76                 enable_atlas_irq(irq);
77 }
78
79 static struct hw_interrupt_type atlas_irq_type = {
80         "Atlas",
81         startup_atlas_irq,
82         shutdown_atlas_irq,
83         enable_atlas_irq,
84         disable_atlas_irq,
85         mask_and_ack_atlas_irq,
86         end_atlas_irq,
87         NULL
88 };
89
90 static inline int ls1bit32(unsigned int x)
91 {
92         int b = 31, s;
93
94         s = 16; if (x << 16 == 0) s = 0; b -= s; x <<= s;
95         s =  8; if (x <<  8 == 0) s = 0; b -= s; x <<= s;
96         s =  4; if (x <<  4 == 0) s = 0; b -= s; x <<= s;
97         s =  2; if (x <<  2 == 0) s = 0; b -= s; x <<= s;
98         s =  1; if (x <<  1 == 0) s = 0; b -= s;
99
100         return b;
101 }
102
103 void atlas_hw0_irqdispatch(struct pt_regs *regs)
104 {
105         unsigned long int_status;
106         int irq;
107
108         int_status = atlas_hw0_icregs->intstatus;
109
110         /* if int_status == 0, then the interrupt has already been cleared */
111         if (unlikely(int_status == 0))
112                 return;
113
114         irq = ATLASINT_BASE + ls1bit32(int_status);
115
116         DEBUG_INT("atlas_hw0_irqdispatch: irq=%d\n", irq);
117
118         do_IRQ(irq, regs);
119 }
120
121 #ifdef CONFIG_KGDB
122 extern void breakpoint(void);
123 extern int remote_debug;
124 #endif
125
126 void __init init_IRQ(void)
127 {
128         int i;
129
130         atlas_hw0_icregs = (struct atlas_ictrl_regs *)ioremap (ATLAS_ICTRL_REGS_BASE, sizeof(struct atlas_ictrl_regs *));
131         
132         /*
133          * Mask out all interrupt by writing "1" to all bit position in
134          * the interrupt reset reg.
135          */
136         atlas_hw0_icregs->intrsten = 0xffffffff;
137
138         /* Now safe to set the exception vector. */
139         set_except_vector(0, mipsIRQ);
140
141         for (i = ATLASINT_BASE; i <= ATLASINT_END; i++) {
142                 irq_desc[i].status      = IRQ_DISABLED;
143                 irq_desc[i].action      = 0;
144                 irq_desc[i].depth       = 1;
145                 irq_desc[i].handler     = &atlas_irq_type;
146                 spin_lock_init(&irq_desc[i].lock);
147         }
148
149 #ifdef CONFIG_KGDB
150         if (remote_debug) {
151                 set_debug_traps();
152                 breakpoint();
153         }
154 #endif
155 }