Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* $Id: irq.c,v 1.2 2004/06/09 05:30:27 starvik Exp $ |
| 2 | * |
| 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> |
| 15 | #include <linux/kernel.h> |
| 16 | #include <linux/init.h> |
| 17 | #include <linux/config.h> |
| 18 | |
| 19 | irqvectptr irq_shortcuts[NR_IRQS]; /* vector of shortcut jumps after the irq prologue */ |
| 20 | |
| 21 | /* don't use set_int_vector, it bypasses the linux interrupt handlers. it is |
| 22 | * global just so that the kernel gdb can use it. |
| 23 | */ |
| 24 | |
| 25 | void |
| 26 | set_int_vector(int n, irqvectptr addr) |
| 27 | { |
| 28 | etrax_irv->v[n + 0x20] = (irqvectptr)addr; |
| 29 | } |
| 30 | |
| 31 | /* the breakpoint vector is obviously not made just like the normal irq handlers |
| 32 | * but needs to contain _code_ to jump to addr. |
| 33 | * |
| 34 | * the BREAK n instruction jumps to IBR + n * 8 |
| 35 | */ |
| 36 | |
| 37 | void |
| 38 | set_break_vector(int n, irqvectptr addr) |
| 39 | { |
| 40 | unsigned short *jinstr = (unsigned short *)&etrax_irv->v[n*2]; |
| 41 | unsigned long *jaddr = (unsigned long *)(jinstr + 1); |
| 42 | |
| 43 | /* if you don't know what this does, do not touch it! */ |
| 44 | |
| 45 | *jinstr = 0x0d3f; |
| 46 | *jaddr = (unsigned long)addr; |
| 47 | |
| 48 | /* 00000026 <clrlop+1a> 3f0d82000000 jump 0x82 */ |
| 49 | } |
| 50 | |
| 51 | /* |
| 52 | * This builds up the IRQ handler stubs using some ugly macros in irq.h |
| 53 | * |
| 54 | * These macros create the low-level assembly IRQ routines that do all |
| 55 | * the operations that are needed. They are also written to be fast - and to |
| 56 | * disable interrupts as little as humanly possible. |
| 57 | * |
| 58 | */ |
| 59 | |
| 60 | /* IRQ0 and 1 are special traps */ |
| 61 | void hwbreakpoint(void); |
| 62 | void IRQ1_interrupt(void); |
| 63 | BUILD_TIMER_IRQ(2, 0x04) /* the timer interrupt is somewhat special */ |
| 64 | BUILD_IRQ(3, 0x08) |
| 65 | BUILD_IRQ(4, 0x10) |
| 66 | BUILD_IRQ(5, 0x20) |
| 67 | BUILD_IRQ(6, 0x40) |
| 68 | BUILD_IRQ(7, 0x80) |
| 69 | BUILD_IRQ(8, 0x100) |
| 70 | BUILD_IRQ(9, 0x200) |
| 71 | BUILD_IRQ(10, 0x400) |
| 72 | BUILD_IRQ(11, 0x800) |
| 73 | BUILD_IRQ(12, 0x1000) |
| 74 | BUILD_IRQ(13, 0x2000) |
| 75 | void mmu_bus_fault(void); /* IRQ 14 is the bus fault interrupt */ |
| 76 | void multiple_interrupt(void); /* IRQ 15 is the multiple IRQ interrupt */ |
| 77 | BUILD_IRQ(16, 0x10000) |
| 78 | BUILD_IRQ(17, 0x20000) |
| 79 | BUILD_IRQ(18, 0x40000) |
| 80 | BUILD_IRQ(19, 0x80000) |
| 81 | BUILD_IRQ(20, 0x100000) |
| 82 | BUILD_IRQ(21, 0x200000) |
| 83 | BUILD_IRQ(22, 0x400000) |
| 84 | BUILD_IRQ(23, 0x800000) |
| 85 | BUILD_IRQ(24, 0x1000000) |
| 86 | BUILD_IRQ(25, 0x2000000) |
| 87 | /* IRQ 26-30 are reserved */ |
| 88 | BUILD_IRQ(31, 0x80000000) |
| 89 | |
| 90 | /* |
| 91 | * Pointers to the low-level handlers |
| 92 | */ |
| 93 | |
| 94 | static void (*interrupt[NR_IRQS])(void) = { |
| 95 | NULL, NULL, IRQ2_interrupt, IRQ3_interrupt, |
| 96 | IRQ4_interrupt, IRQ5_interrupt, IRQ6_interrupt, IRQ7_interrupt, |
| 97 | IRQ8_interrupt, IRQ9_interrupt, IRQ10_interrupt, IRQ11_interrupt, |
| 98 | IRQ12_interrupt, IRQ13_interrupt, NULL, NULL, |
| 99 | IRQ16_interrupt, IRQ17_interrupt, IRQ18_interrupt, IRQ19_interrupt, |
| 100 | IRQ20_interrupt, IRQ21_interrupt, IRQ22_interrupt, IRQ23_interrupt, |
| 101 | IRQ24_interrupt, IRQ25_interrupt, NULL, NULL, NULL, NULL, NULL, |
| 102 | IRQ31_interrupt |
| 103 | }; |
| 104 | |
| 105 | static void (*bad_interrupt[NR_IRQS])(void) = { |
| 106 | NULL, NULL, |
| 107 | NULL, bad_IRQ3_interrupt, |
| 108 | bad_IRQ4_interrupt, bad_IRQ5_interrupt, |
| 109 | bad_IRQ6_interrupt, bad_IRQ7_interrupt, |
| 110 | bad_IRQ8_interrupt, bad_IRQ9_interrupt, |
| 111 | bad_IRQ10_interrupt, bad_IRQ11_interrupt, |
| 112 | bad_IRQ12_interrupt, bad_IRQ13_interrupt, |
| 113 | NULL, NULL, |
| 114 | bad_IRQ16_interrupt, bad_IRQ17_interrupt, |
| 115 | bad_IRQ18_interrupt, bad_IRQ19_interrupt, |
| 116 | bad_IRQ20_interrupt, bad_IRQ21_interrupt, |
| 117 | bad_IRQ22_interrupt, bad_IRQ23_interrupt, |
| 118 | bad_IRQ24_interrupt, bad_IRQ25_interrupt, |
| 119 | NULL, NULL, NULL, NULL, NULL, |
| 120 | bad_IRQ31_interrupt |
| 121 | }; |
| 122 | |
| 123 | void arch_setup_irq(int irq) |
| 124 | { |
| 125 | set_int_vector(irq, interrupt[irq]); |
| 126 | } |
| 127 | |
| 128 | void arch_free_irq(int irq) |
| 129 | { |
| 130 | set_int_vector(irq, bad_interrupt[irq]); |
| 131 | } |
| 132 | |
| 133 | void weird_irq(void); |
| 134 | void system_call(void); /* from entry.S */ |
| 135 | void do_sigtrap(void); /* from entry.S */ |
| 136 | void gdb_handle_breakpoint(void); /* from entry.S */ |
| 137 | |
| 138 | /* init_IRQ() is called by start_kernel and is responsible for fixing IRQ masks and |
| 139 | setting the irq vector table to point to bad_interrupt ptrs. |
| 140 | */ |
| 141 | |
| 142 | void __init |
| 143 | init_IRQ(void) |
| 144 | { |
| 145 | int i; |
| 146 | |
| 147 | /* clear all interrupt masks */ |
| 148 | |
| 149 | #ifndef CONFIG_SVINTO_SIM |
| 150 | *R_IRQ_MASK0_CLR = 0xffffffff; |
| 151 | *R_IRQ_MASK1_CLR = 0xffffffff; |
| 152 | *R_IRQ_MASK2_CLR = 0xffffffff; |
| 153 | #endif |
| 154 | |
| 155 | *R_VECT_MASK_CLR = 0xffffffff; |
| 156 | |
| 157 | /* clear the shortcut entry points */ |
| 158 | |
| 159 | for(i = 0; i < NR_IRQS; i++) |
| 160 | irq_shortcuts[i] = NULL; |
| 161 | |
| 162 | for (i = 0; i < 256; i++) |
| 163 | etrax_irv->v[i] = weird_irq; |
| 164 | |
| 165 | /* the entries in the break vector contain actual code to be |
| 166 | executed by the associated break handler, rather than just a jump |
| 167 | address. therefore we need to setup a default breakpoint handler |
| 168 | for all breakpoints */ |
| 169 | |
| 170 | for (i = 0; i < 16; i++) |
| 171 | set_break_vector(i, do_sigtrap); |
| 172 | |
| 173 | /* set all etrax irq's to the bad handlers */ |
| 174 | for (i = 2; i < NR_IRQS; i++) |
| 175 | set_int_vector(i, bad_interrupt[i]); |
| 176 | |
| 177 | /* except IRQ 15 which is the multiple-IRQ handler on Etrax100 */ |
| 178 | |
| 179 | set_int_vector(15, multiple_interrupt); |
| 180 | |
| 181 | /* 0 and 1 which are special breakpoint/NMI traps */ |
| 182 | |
| 183 | set_int_vector(0, hwbreakpoint); |
| 184 | set_int_vector(1, IRQ1_interrupt); |
| 185 | |
| 186 | /* and irq 14 which is the mmu bus fault handler */ |
| 187 | |
| 188 | set_int_vector(14, mmu_bus_fault); |
| 189 | |
| 190 | /* setup the system-call trap, which is reached by BREAK 13 */ |
| 191 | |
| 192 | set_break_vector(13, system_call); |
| 193 | |
| 194 | /* setup a breakpoint handler for debugging used for both user and |
| 195 | kernel mode debugging (which is why it is not inside an ifdef |
| 196 | CONFIG_ETRAX_KGDB) */ |
| 197 | set_break_vector(8, gdb_handle_breakpoint); |
| 198 | |
| 199 | #ifdef CONFIG_ETRAX_KGDB |
| 200 | /* setup kgdb if its enabled, and break into the debugger */ |
| 201 | kgdb_init(); |
| 202 | breakpoint(); |
| 203 | #endif |
| 204 | } |