irq.c 6.3 KB

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