irq.c 6.7 KB

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