interrupts.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. /*
  2. * (C) Copyright 2007 Michal Simek
  3. * (C) Copyright 2004 Atmark Techno, Inc.
  4. *
  5. * Michal SIMEK <monstr@monstr.eu>
  6. * Yasushi SHOJI <yashi@atmark-techno.com>
  7. *
  8. * See file CREDITS for list of people who contributed to this
  9. * project.
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License as
  13. * published by the Free Software Foundation; either version 2 of
  14. * the License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  24. * MA 02111-1307 USA
  25. */
  26. #include <common.h>
  27. #include <command.h>
  28. #include <asm/microblaze_intc.h>
  29. #include <asm/asm.h>
  30. #undef DEBUG_INT
  31. extern void microblaze_disable_interrupts (void);
  32. extern void microblaze_enable_interrupts (void);
  33. void enable_interrupts (void)
  34. {
  35. __asm__ __volatile__ ("msrset r0, 0x2");
  36. //microblaze_enable_interrupts ();
  37. }
  38. int disable_interrupts (void)
  39. {
  40. __asm__ __volatile__ ("msrclr r0, 0x2");
  41. //microblaze_disable_interrupts ();
  42. return 0;
  43. }
  44. #ifdef CFG_INTC_0
  45. #ifdef CFG_TIMER_0
  46. extern void timer_init (void);
  47. #endif
  48. #ifdef CFG_FSL_2
  49. extern void fsl_init2 (void);
  50. #endif
  51. static struct irq_action vecs[CFG_INTC_0_NUM];
  52. /* mapping structure to interrupt controller */
  53. microblaze_intc_t *intc = (microblaze_intc_t *) (CFG_INTC_0_ADDR);
  54. /* default handler */
  55. void def_hdlr (void)
  56. {
  57. puts ("def_hdlr\n");
  58. }
  59. void enable_one_interrupt (int irq)
  60. {
  61. int mask;
  62. int offset = 1;
  63. offset <<= irq;
  64. mask = intc->ier;
  65. intc->ier = (mask | offset);
  66. #ifdef DEBUG_INT
  67. printf ("Enable one interrupt irq %x - mask %x,ier %x\n", offset, mask,
  68. intc->ier);
  69. printf ("INTC isr %x, ier %x, iar %x, mer %x\n", intc->isr, intc->ier,
  70. intc->iar, intc->mer);
  71. #endif
  72. }
  73. void disable_one_interrupt (int irq)
  74. {
  75. int mask;
  76. int offset = 1;
  77. offset <<= irq;
  78. mask = intc->ier;
  79. intc->ier = (mask & ~offset);
  80. #ifdef DEBUG_INT
  81. printf ("Disable one interrupt irq %x - mask %x,ier %x\n", irq, mask,
  82. intc->ier);
  83. printf ("INTC isr %x, ier %x, iar %x, mer %x\n", intc->isr, intc->ier,
  84. intc->iar, intc->mer);
  85. #endif
  86. }
  87. /* adding new handler for interrupt */
  88. void install_interrupt_handler (int irq, interrupt_handler_t * hdlr, void *arg)
  89. {
  90. struct irq_action *act;
  91. /* irq out of range */
  92. if ((irq < 0) || (irq > CFG_INTC_0_NUM)) {
  93. puts ("IRQ out of range\n");
  94. return;
  95. }
  96. act = &vecs[irq];
  97. if (hdlr) { /* enable */
  98. act->handler = hdlr;
  99. act->arg = arg;
  100. act->count = 0;
  101. enable_one_interrupt (irq);
  102. } else { /* disable */
  103. act->handler = (interrupt_handler_t *) def_hdlr;
  104. act->arg = (void *)irq;
  105. disable_one_interrupt (irq);
  106. }
  107. }
  108. /* initialization interrupt controller - hardware */
  109. void intc_init (void)
  110. {
  111. intc->mer = 0;
  112. intc->ier = 0;
  113. intc->iar = 0xFFFFFFFF;
  114. /* XIntc_Start - hw_interrupt enable and all interrupt enable */
  115. intc->mer = 0x3;
  116. #ifdef DEBUG_INT
  117. printf ("INTC isr %x, ier %x, iar %x, mer %x\n", intc->isr, intc->ier,
  118. intc->iar, intc->mer);
  119. #endif
  120. }
  121. int interrupts_init (void)
  122. {
  123. int i;
  124. /* initialize irq list */
  125. for (i = 0; i < CFG_INTC_0_NUM; i++) {
  126. vecs[i].handler = (interrupt_handler_t *) def_hdlr;
  127. vecs[i].arg = (void *)i;
  128. vecs[i].count = 0;
  129. }
  130. /* initialize intc controller */
  131. intc_init ();
  132. #ifdef CFG_TIMER_0
  133. timer_init ();
  134. #endif
  135. #ifdef CFG_FSL_2
  136. fsl_init2 ();
  137. #endif
  138. enable_interrupts ();
  139. return 0;
  140. }
  141. void interrupt_handler (void)
  142. {
  143. int irqs = (intc->isr & intc->ier); /* find active interrupt */
  144. int i = 1;
  145. #ifdef DEBUG_INT
  146. int value;
  147. printf ("INTC isr %x, ier %x, iar %x, mer %x\n", intc->isr, intc->ier,
  148. intc->iar, intc->mer);
  149. R14(value);
  150. printf ("Interrupt handler on %x line, r14 %x\n", irqs, value);
  151. #endif
  152. struct irq_action *act = vecs;
  153. while (irqs) {
  154. if (irqs & 1) {
  155. #ifdef DEBUG_INT
  156. printf
  157. ("Jumping to interrupt handler rutine addr %x,count %x,arg %x\n",
  158. act->handler, act->count, act->arg);
  159. #endif
  160. act->handler (act->arg);
  161. act->count++;
  162. intc->iar = i;
  163. return;
  164. }
  165. irqs >>= 1;
  166. act++;
  167. i <<= 1;
  168. }
  169. #ifdef DEBUG_INT
  170. printf ("Dump INTC reg, isr %x, ier %x, iar %x, mer %x\n", intc->isr,
  171. intc->ier, intc->iar, intc->mer);
  172. R14(value);
  173. printf ("Interrupt handler on %x line, r14 %x\n", irqs, value);
  174. #endif
  175. }
  176. #endif
  177. #if (CONFIG_COMMANDS & CFG_CMD_IRQ)
  178. #ifdef CFG_INTC_0
  179. int do_irqinfo (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
  180. {
  181. int i;
  182. struct irq_action *act = vecs;
  183. puts ("\nInterrupt-Information:\n\n"
  184. "Nr Routine Arg Count\n"
  185. "-----------------------------\n");
  186. for (i = 0; i < CFG_INTC_0_NUM; i++) {
  187. if (act->handler != (interrupt_handler_t*) def_hdlr) {
  188. printf ("%02d %08lx %08lx %d\n", i,
  189. (int)act->handler, (int)act->arg, act->count);
  190. }
  191. act++;
  192. }
  193. puts ("\n");
  194. return (0);
  195. }
  196. #else
  197. int do_irqinfo (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
  198. {
  199. puts ("Undefined interrupt controller\n");
  200. }
  201. #endif
  202. #endif /* CONFIG_COMMANDS & CFG_CMD_IRQ */