interrupts.c 4.9 KB

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