2 * Carsten Langgaard, carstenl@mips.com
3 * Copyright (C) 1999,2000 MIPS Technologies, Inc. All rights reserved.
5 * ########################################################################
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.
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
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.
20 * ########################################################################
22 * Routines for generic manipulation of the interrupts found on the
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>
33 #include <asm/bootinfo.h>
35 #include <asm/lasat/lasatint.h>
36 #include <asm/gdb-stub.h>
38 static volatile int *lasat_int_status = NULL;
39 static volatile int *lasat_int_mask = NULL;
40 static volatile int lasat_int_mask_shift;
42 extern asmlinkage void mipsIRQ(void);
45 #define DEBUG_INT(x...) printk(x)
47 #define DEBUG_INT(x...)
50 void disable_lasat_irq(unsigned int irq_nr)
53 DEBUG_INT("disable_lasat_irq: %d", irq_nr);
55 local_irq_save(flags);
56 *lasat_int_mask &= ~(1 << irq_nr) << lasat_int_mask_shift;
57 local_irq_restore(flags);
60 void enable_lasat_irq(unsigned int irq_nr)
63 DEBUG_INT("enable_lasat_irq: %d", irq_nr);
65 local_irq_save(flags);
66 *lasat_int_mask |= (1 << irq_nr) << lasat_int_mask_shift;
67 local_irq_restore(flags);
70 static unsigned int startup_lasat_irq(unsigned int irq)
72 enable_lasat_irq(irq);
73 return 0; /* never anything pending */
76 #define shutdown_lasat_irq disable_lasat_irq
78 #define mask_and_ack_lasat_irq disable_lasat_irq
80 static void end_lasat_irq(unsigned int irq)
82 if (!(irq_desc[irq].status & (IRQ_DISABLED|IRQ_INPROGRESS)))
83 enable_lasat_irq(irq);
86 static struct hw_interrupt_type lasat_irq_type = {
92 mask_and_ack_lasat_irq,
97 static inline int ls1bit32(unsigned int x)
101 s = 16; if (x << 16 == 0) s = 0; b -= s; x <<= s;
102 s = 8; if (x << 8 == 0) s = 0; b -= s; x <<= s;
103 s = 4; if (x << 4 == 0) s = 0; b -= s; x <<= s;
104 s = 2; if (x << 2 == 0) s = 0; b -= s; x <<= s;
105 s = 1; if (x << 1 == 0) s = 0; b -= s;
110 static unsigned long (* get_int_status)(void);
112 static unsigned long get_int_status_100(void)
114 return (*lasat_int_status & *lasat_int_mask);
117 static unsigned long get_int_status_200(void)
119 unsigned long int_status;
121 int_status = *lasat_int_status;
122 int_status &= (int_status >> LASATINT_MASK_SHIFT_200) & 0xffff;
126 void lasat_hw0_irqdispatch(struct pt_regs *regs)
128 struct irqaction *action;
129 unsigned long int_status;
130 int irq, cpu = smp_processor_id();
132 int_status = get_int_status();
134 /* if int_status == 0, then the interrupt has already been cleared */
138 irq = ls1bit32(int_status);
139 action = irq_desc[irq].action;
141 DEBUG_INT("lasat_hw0_irqdispatch: irq=%d\n", irq);
143 /* if action == NULL, then we don't have a handler for the irq */
144 if (action == NULL) {
145 printk("No handler for hw0 irq: %i\n", irq);
146 atomic_inc(&irq_err_count);
151 kstat.irqs[0][irq]++;
152 action->handler(irq, action->dev_id, regs);
158 void __init init_IRQ(void)
164 switch (mips_machtype) {
166 lasat_int_status = (void *)LASAT_INT_STATUS_REG_100;
167 lasat_int_mask = (void *)LASAT_INT_MASK_REG_100;
168 lasat_int_mask_shift = LASATINT_MASK_SHIFT_100;
169 get_int_status = get_int_status_100;
173 lasat_int_status = (void *)LASAT_INT_STATUS_REG_200;
174 lasat_int_mask = (void *)LASAT_INT_MASK_REG_200;
175 lasat_int_mask_shift = LASATINT_MASK_SHIFT_200;
176 get_int_status = get_int_status_200;
177 *lasat_int_mask &= 0xffff;
180 panic("init_IRQ: mips_machtype incorrect");
183 /* Now safe to set the exception vector. */
184 set_except_vector(0, mipsIRQ);
186 for (i = 0; i <= LASATINT_END; i++) {
187 irq_desc[i].status = IRQ_DISABLED;
188 irq_desc[i].action = 0;
189 irq_desc[i].depth = 1;
190 irq_desc[i].handler = &lasat_irq_type;