interrupts.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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. microblaze_enable_interrupts ();
  36. }
  37. int disable_interrupts (void)
  38. {
  39. microblaze_disable_interrupts ();
  40. return 0;
  41. }
  42. #ifdef CFG_INTC_0
  43. #ifdef CFG_TIMER_0
  44. extern void timer_init (void);
  45. #endif
  46. static struct irq_action vecs[CFG_INTC_0_NUM];
  47. /* mapping structure to interrupt controller */
  48. microblaze_intc_t *intc = (microblaze_intc_t *) (CFG_INTC_0_ADDR);
  49. /* default handler */
  50. void def_hdlr (void)
  51. {
  52. puts ("def_hdlr\n");
  53. }
  54. void enable_one_interrupt (int irq)
  55. {
  56. int mask;
  57. int offset = 1;
  58. offset <<= irq;
  59. mask = intc->ier;
  60. intc->ier = (mask | offset);
  61. #ifdef DEBUG_INT
  62. printf ("Enable one interrupt irq %x - mask %x,ier %x\n", offset, mask,
  63. intc->ier);
  64. printf ("INTC isr %x, ier %x, iar %x, mer %x\n", intc->isr, intc->ier,
  65. intc->iar, intc->mer);
  66. #endif
  67. }
  68. void disable_one_interrupt (int irq)
  69. {
  70. int mask;
  71. int offset = 1;
  72. offset <<= irq;
  73. mask = intc->ier;
  74. intc->ier = (mask & ~offset);
  75. #ifdef DEBUG_INT
  76. printf ("Disable one interrupt irq %x - mask %x,ier %x\n", irq, mask,
  77. intc->ier);
  78. printf ("INTC isr %x, ier %x, iar %x, mer %x\n", intc->isr, intc->ier,
  79. intc->iar, intc->mer);
  80. #endif
  81. }
  82. /* adding new handler for interrupt */
  83. void install_interrupt_handler (int irq, interrupt_handler_t * hdlr, void *arg)
  84. {
  85. struct irq_action *act;
  86. /* irq out of range */
  87. if ((irq < 0) || (irq > CFG_INTC_0_NUM)) {
  88. puts ("IRQ out of range\n");
  89. return;
  90. }
  91. act = &vecs[irq];
  92. if (hdlr) { /* enable */
  93. act->handler = hdlr;
  94. act->arg = arg;
  95. act->count = 0;
  96. enable_one_interrupt (irq);
  97. } else { /* disable */
  98. act->handler = (interrupt_handler_t *) def_hdlr;
  99. act->arg = (void *)irq;
  100. disable_one_interrupt (irq);
  101. }
  102. }
  103. /* initialization interrupt controller - hardware */
  104. void intc_init (void)
  105. {
  106. intc->mer = 0;
  107. intc->ier = 0;
  108. intc->iar = 0xFFFFFFFF;
  109. /* XIntc_Start - hw_interrupt enable and all interrupt enable */
  110. intc->mer = 0x3;
  111. #ifdef DEBUG_INT
  112. printf ("INTC isr %x, ier %x, iar %x, mer %x\n", intc->isr, intc->ier,
  113. intc->iar, intc->mer);
  114. #endif
  115. }
  116. int interrupts_init (void)
  117. {
  118. int i;
  119. /* initialize irq list */
  120. for (i = 0; i < CFG_INTC_0_NUM; i++) {
  121. vecs[i].handler = (interrupt_handler_t *) def_hdlr;
  122. vecs[i].arg = (void *)i;
  123. vecs[i].count = 0;
  124. }
  125. /* initialize intc controller */
  126. intc_init ();
  127. #ifdef CFG_TIMER_0
  128. timer_init ();
  129. #endif
  130. enable_interrupts ();
  131. return 0;
  132. }
  133. void interrupt_handler (void)
  134. {
  135. int irqs = (intc->isr & intc->ier); /* find active interrupt */
  136. int i = 1;
  137. #ifdef DEBUG_INT
  138. int value;
  139. printf ("INTC isr %x, ier %x, iar %x, mer %x\n", intc->isr, intc->ier,
  140. intc->iar, intc->mer);
  141. R14(value);
  142. printf ("Interrupt handler on %x line, r14 %x\n", irqs, value);
  143. #endif
  144. struct irq_action *act = vecs;
  145. while (irqs) {
  146. if (irqs & 1) {
  147. #ifdef DEBUG_INT
  148. printf
  149. ("Jumping to interrupt handler rutine addr %x,count %x,arg %x\n",
  150. act->handler, act->count, act->arg);
  151. #endif
  152. act->handler (act->arg);
  153. act->count++;
  154. intc->iar = i;
  155. return;
  156. }
  157. irqs >>= 1;
  158. act++;
  159. i <<= 1;
  160. }
  161. #ifdef DEBUG_INT
  162. printf ("Dump INTC reg, isr %x, ier %x, iar %x, mer %x\n", intc->isr,
  163. intc->ier, intc->iar, intc->mer);
  164. R14(value);
  165. printf ("Interrupt handler on %x line, r14 %x\n", irqs, value);
  166. #endif
  167. }
  168. #endif
  169. #if (CONFIG_COMMANDS & CFG_CMD_IRQ)
  170. #ifdef CFG_INTC_0
  171. int do_irqinfo (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
  172. {
  173. int i;
  174. struct irq_action *act = vecs;
  175. puts ("\nInterrupt-Information:\n\n"
  176. "Nr Routine Arg Count\n"
  177. "-----------------------------\n");
  178. for (i = 0; i < CFG_INTC_0_NUM; i++) {
  179. if (act->handler != (interrupt_handler_t*) def_hdlr) {
  180. printf ("%02d %08lx %08lx %d\n", i,
  181. (int)act->handler, (int)act->arg, act->count);
  182. }
  183. act++;
  184. }
  185. puts ("\n");
  186. return (0);
  187. }
  188. #else
  189. int do_irqinfo (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
  190. {
  191. puts ("Undefined interrupt controller\n");
  192. }
  193. #endif
  194. #endif /* CONFIG_COMMANDS & CFG_CMD_IRQ */