interrupts.c 5.0 KB

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