interrupts.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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. unsigned int msr;
  40. MFS(msr, rmsr);
  41. MSRCLR(0x2);
  42. return (msr & 0x2) != 0;
  43. }
  44. #ifdef CONFIG_SYS_INTC_0
  45. static struct irq_action vecs[CONFIG_SYS_INTC_0_NUM];
  46. /* mapping structure to interrupt controller */
  47. microblaze_intc_t *intc = (microblaze_intc_t *) (CONFIG_SYS_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 > CONFIG_SYS_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 < CONFIG_SYS_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. enable_interrupts ();
  127. return 0;
  128. }
  129. void interrupt_handler (void)
  130. {
  131. int irqs = intc->ivr; /* find active interrupt */
  132. int mask = 1;
  133. #ifdef DEBUG_INT
  134. int value;
  135. printf ("INTC isr %x, ier %x, iar %x, mer %x\n", intc->isr, intc->ier,
  136. intc->iar, intc->mer);
  137. R14(value);
  138. printf ("Interrupt handler on %x line, r14 %x\n", irqs, value);
  139. #endif
  140. struct irq_action *act = vecs + irqs;
  141. intc->iar = mask << irqs;
  142. #ifdef DEBUG_INT
  143. printf
  144. ("Jumping to interrupt handler rutine addr %x,count %x,arg %x\n",
  145. act->handler, act->count, act->arg);
  146. #endif
  147. act->handler (act->arg);
  148. act->count++;
  149. #ifdef DEBUG_INT
  150. printf ("Dump INTC reg, isr %x, ier %x, iar %x, mer %x\n", intc->isr,
  151. intc->ier, intc->iar, intc->mer);
  152. R14(value);
  153. printf ("Interrupt handler on %x line, r14 %x\n", irqs, value);
  154. #endif
  155. }
  156. #endif
  157. #if defined(CONFIG_CMD_IRQ)
  158. #ifdef CONFIG_SYS_INTC_0
  159. int do_irqinfo (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
  160. {
  161. int i;
  162. struct irq_action *act = vecs;
  163. puts ("\nInterrupt-Information:\n\n"
  164. "Nr Routine Arg Count\n"
  165. "-----------------------------\n");
  166. for (i = 0; i < CONFIG_SYS_INTC_0_NUM; i++) {
  167. if (act->handler != (interrupt_handler_t*) def_hdlr) {
  168. printf ("%02d %08x %08x %d\n", i,
  169. (int)act->handler, (int)act->arg, act->count);
  170. }
  171. act++;
  172. }
  173. puts ("\n");
  174. return (0);
  175. }
  176. #else
  177. int do_irqinfo (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
  178. {
  179. puts ("Undefined interrupt controller\n");
  180. }
  181. #endif
  182. #endif