blob: e06ab0050d375156ff94eb3a2602a6a9493a57e5 [file] [log] [blame]
Mikael Starvik2e0cea12005-07-27 11:44:36 -07001/* $Id: irq.c,v 1.4 2005/01/04 12:22:28 starvik Exp $
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 *
3 * linux/arch/cris/kernel/irq.c
4 *
5 * Copyright (c) 2000-2002 Axis Communications AB
6 *
7 * Authors: Bjorn Wesen (bjornw@axis.com)
8 *
9 * This file contains the interrupt vectors and some
10 * helper functions
11 *
12 */
13
14#include <asm/irq.h>
Jesper Nilsson7b275522007-11-14 17:00:59 -080015#include <asm/current.h>
Mikael Starvik2e0cea12005-07-27 11:44:36 -070016#include <linux/irq.h>
Jesper Nilsson7b275522007-11-14 17:00:59 -080017#include <linux/interrupt.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#include <linux/kernel.h>
19#include <linux/init.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
Jesper Nilsson7b275522007-11-14 17:00:59 -080021/* From kgdb.c. */
22extern void kgdb_init(void);
23extern void breakpoint(void);
24
Mikael Starvik2e0cea12005-07-27 11:44:36 -070025#define mask_irq(irq_nr) (*R_VECT_MASK_CLR = 1 << (irq_nr));
26#define unmask_irq(irq_nr) (*R_VECT_MASK_SET = 1 << (irq_nr));
Linus Torvalds1da177e2005-04-16 15:20:36 -070027
28/* don't use set_int_vector, it bypasses the linux interrupt handlers. it is
29 * global just so that the kernel gdb can use it.
30 */
31
32void
33set_int_vector(int n, irqvectptr addr)
34{
35 etrax_irv->v[n + 0x20] = (irqvectptr)addr;
36}
37
38/* the breakpoint vector is obviously not made just like the normal irq handlers
39 * but needs to contain _code_ to jump to addr.
40 *
41 * the BREAK n instruction jumps to IBR + n * 8
42 */
43
44void
45set_break_vector(int n, irqvectptr addr)
46{
47 unsigned short *jinstr = (unsigned short *)&etrax_irv->v[n*2];
48 unsigned long *jaddr = (unsigned long *)(jinstr + 1);
49
50 /* if you don't know what this does, do not touch it! */
51
52 *jinstr = 0x0d3f;
53 *jaddr = (unsigned long)addr;
54
55 /* 00000026 <clrlop+1a> 3f0d82000000 jump 0x82 */
56}
57
58/*
59 * This builds up the IRQ handler stubs using some ugly macros in irq.h
60 *
61 * These macros create the low-level assembly IRQ routines that do all
62 * the operations that are needed. They are also written to be fast - and to
63 * disable interrupts as little as humanly possible.
64 *
65 */
66
67/* IRQ0 and 1 are special traps */
68void hwbreakpoint(void);
69void IRQ1_interrupt(void);
70BUILD_TIMER_IRQ(2, 0x04) /* the timer interrupt is somewhat special */
71BUILD_IRQ(3, 0x08)
72BUILD_IRQ(4, 0x10)
73BUILD_IRQ(5, 0x20)
74BUILD_IRQ(6, 0x40)
75BUILD_IRQ(7, 0x80)
76BUILD_IRQ(8, 0x100)
77BUILD_IRQ(9, 0x200)
78BUILD_IRQ(10, 0x400)
79BUILD_IRQ(11, 0x800)
80BUILD_IRQ(12, 0x1000)
81BUILD_IRQ(13, 0x2000)
82void mmu_bus_fault(void); /* IRQ 14 is the bus fault interrupt */
83void multiple_interrupt(void); /* IRQ 15 is the multiple IRQ interrupt */
Jesper Nilsson7b275522007-11-14 17:00:59 -080084BUILD_IRQ(16, 0x10000 | 0x20000) /* ethernet tx interrupt needs to block rx */
85BUILD_IRQ(17, 0x20000 | 0x10000) /* ...and vice versa */
Linus Torvalds1da177e2005-04-16 15:20:36 -070086BUILD_IRQ(18, 0x40000)
87BUILD_IRQ(19, 0x80000)
88BUILD_IRQ(20, 0x100000)
89BUILD_IRQ(21, 0x200000)
90BUILD_IRQ(22, 0x400000)
91BUILD_IRQ(23, 0x800000)
92BUILD_IRQ(24, 0x1000000)
93BUILD_IRQ(25, 0x2000000)
94/* IRQ 26-30 are reserved */
95BUILD_IRQ(31, 0x80000000)
96
97/*
98 * Pointers to the low-level handlers
99 */
100
101static void (*interrupt[NR_IRQS])(void) = {
102 NULL, NULL, IRQ2_interrupt, IRQ3_interrupt,
103 IRQ4_interrupt, IRQ5_interrupt, IRQ6_interrupt, IRQ7_interrupt,
104 IRQ8_interrupt, IRQ9_interrupt, IRQ10_interrupt, IRQ11_interrupt,
105 IRQ12_interrupt, IRQ13_interrupt, NULL, NULL,
106 IRQ16_interrupt, IRQ17_interrupt, IRQ18_interrupt, IRQ19_interrupt,
107 IRQ20_interrupt, IRQ21_interrupt, IRQ22_interrupt, IRQ23_interrupt,
108 IRQ24_interrupt, IRQ25_interrupt, NULL, NULL, NULL, NULL, NULL,
109 IRQ31_interrupt
110};
111
Mikael Starvik2e0cea12005-07-27 11:44:36 -0700112static void enable_crisv10_irq(unsigned int irq);
113
114static unsigned int startup_crisv10_irq(unsigned int irq)
115{
116 enable_crisv10_irq(irq);
117 return 0;
118}
119
120#define shutdown_crisv10_irq disable_crisv10_irq
121
122static void enable_crisv10_irq(unsigned int irq)
123{
124 unmask_irq(irq);
125}
126
127static void disable_crisv10_irq(unsigned int irq)
128{
129 mask_irq(irq);
130}
131
132static void ack_crisv10_irq(unsigned int irq)
133{
134}
135
136static void end_crisv10_irq(unsigned int irq)
137{
138}
139
140static struct hw_interrupt_type crisv10_irq_type = {
141 .typename = "CRISv10",
142 .startup = startup_crisv10_irq,
143 .shutdown = shutdown_crisv10_irq,
144 .enable = enable_crisv10_irq,
145 .disable = disable_crisv10_irq,
146 .ack = ack_crisv10_irq,
147 .end = end_crisv10_irq,
148 .set_affinity = NULL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149};
150
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151void weird_irq(void);
152void system_call(void); /* from entry.S */
153void do_sigtrap(void); /* from entry.S */
154void gdb_handle_breakpoint(void); /* from entry.S */
155
Jesper Nilsson7b275522007-11-14 17:00:59 -0800156extern void do_IRQ(int irq, struct pt_regs * regs);
157
158/* Handle multiple IRQs */
159void do_multiple_IRQ(struct pt_regs* regs)
160{
161 int bit;
162 unsigned masked;
163 unsigned mask;
164 unsigned ethmask = 0;
165
166 /* Get interrupts to mask and handle */
167 mask = masked = *R_VECT_MASK_RD;
168
169 /* Never mask timer IRQ */
170 mask &= ~(IO_MASK(R_VECT_MASK_RD, timer0));
171
172 /*
173 * If either ethernet interrupt (rx or tx) is active then block
174 * the other one too. Unblock afterwards also.
175 */
176 if (mask &
177 (IO_STATE(R_VECT_MASK_RD, dma0, active) |
178 IO_STATE(R_VECT_MASK_RD, dma1, active))) {
179 ethmask = (IO_MASK(R_VECT_MASK_RD, dma0) |
180 IO_MASK(R_VECT_MASK_RD, dma1));
181 }
182
183 /* Block them */
184 *R_VECT_MASK_CLR = (mask | ethmask);
185
186 /* An extra irq_enter here to prevent softIRQs to run after
187 * each do_IRQ. This will decrease the interrupt latency.
188 */
189 irq_enter();
190
191 /* Handle all IRQs */
192 for (bit = 2; bit < 32; bit++) {
193 if (masked & (1 << bit)) {
194 do_IRQ(bit, regs);
195 }
196 }
197
198 /* This irq_exit() will trigger the soft IRQs. */
199 irq_exit();
200
201 /* Unblock the IRQs again */
202 *R_VECT_MASK_SET = (masked | ethmask);
203}
204
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205/* init_IRQ() is called by start_kernel and is responsible for fixing IRQ masks and
Mikael Starvik2e0cea12005-07-27 11:44:36 -0700206 setting the irq vector table.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207*/
208
209void __init
210init_IRQ(void)
211{
212 int i;
213
214 /* clear all interrupt masks */
215
216#ifndef CONFIG_SVINTO_SIM
217 *R_IRQ_MASK0_CLR = 0xffffffff;
218 *R_IRQ_MASK1_CLR = 0xffffffff;
219 *R_IRQ_MASK2_CLR = 0xffffffff;
220#endif
221
222 *R_VECT_MASK_CLR = 0xffffffff;
223
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 for (i = 0; i < 256; i++)
225 etrax_irv->v[i] = weird_irq;
226
Simon Arlott49b4ff32007-10-20 01:08:50 +0200227 /* Initialize IRQ handler descriptors. */
Mikael Starvik2e0cea12005-07-27 11:44:36 -0700228 for(i = 2; i < NR_IRQS; i++) {
Ingo Molnard1bef4e2006-06-29 02:24:36 -0700229 irq_desc[i].chip = &crisv10_irq_type;
Mikael Starvik2e0cea12005-07-27 11:44:36 -0700230 set_int_vector(i, interrupt[i]);
231 }
232
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 /* the entries in the break vector contain actual code to be
234 executed by the associated break handler, rather than just a jump
235 address. therefore we need to setup a default breakpoint handler
236 for all breakpoints */
237
238 for (i = 0; i < 16; i++)
239 set_break_vector(i, do_sigtrap);
240
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 /* except IRQ 15 which is the multiple-IRQ handler on Etrax100 */
242
243 set_int_vector(15, multiple_interrupt);
244
245 /* 0 and 1 which are special breakpoint/NMI traps */
246
247 set_int_vector(0, hwbreakpoint);
248 set_int_vector(1, IRQ1_interrupt);
249
250 /* and irq 14 which is the mmu bus fault handler */
251
252 set_int_vector(14, mmu_bus_fault);
253
254 /* setup the system-call trap, which is reached by BREAK 13 */
255
256 set_break_vector(13, system_call);
257
258 /* setup a breakpoint handler for debugging used for both user and
259 kernel mode debugging (which is why it is not inside an ifdef
260 CONFIG_ETRAX_KGDB) */
261 set_break_vector(8, gdb_handle_breakpoint);
262
263#ifdef CONFIG_ETRAX_KGDB
264 /* setup kgdb if its enabled, and break into the debugger */
265 kgdb_init();
266 breakpoint();
267#endif
268}