interrupts.c 4.8 KB

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