interrupts.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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 <malloc.h>
  29. #include <asm/microblaze_intc.h>
  30. #include <asm/asm.h>
  31. #undef DEBUG_INT
  32. extern void microblaze_disable_interrupts (void);
  33. extern void microblaze_enable_interrupts (void);
  34. void enable_interrupts (void)
  35. {
  36. MSRSET(0x2);
  37. }
  38. int disable_interrupts (void)
  39. {
  40. unsigned int msr;
  41. MFS(msr, rmsr);
  42. MSRCLR(0x2);
  43. return (msr & 0x2) != 0;
  44. }
  45. static struct irq_action *vecs;
  46. static u32 irq_no;
  47. /* mapping structure to interrupt controller */
  48. microblaze_intc_t *intc;
  49. /* default handler */
  50. static void def_hdlr(void)
  51. {
  52. puts ("def_hdlr\n");
  53. }
  54. static 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. static 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 > irq_no)) {
  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. static 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. #if defined(CONFIG_SYS_INTC_0_ADDR) && defined(CONFIG_SYS_INTC_0_NUM)
  120. intc = (microblaze_intc_t *) (CONFIG_SYS_INTC_0_ADDR);
  121. irq_no = CONFIG_SYS_INTC_0_NUM;
  122. #endif
  123. if (irq_no) {
  124. vecs = calloc(1, sizeof(struct irq_action) * irq_no);
  125. if (vecs == NULL) {
  126. puts("Interrupt vector allocation failed\n");
  127. return -1;
  128. }
  129. /* initialize irq list */
  130. for (i = 0; i < irq_no; i++) {
  131. vecs[i].handler = (interrupt_handler_t *) def_hdlr;
  132. vecs[i].arg = (void *)i;
  133. vecs[i].count = 0;
  134. }
  135. /* initialize intc controller */
  136. intc_init();
  137. enable_interrupts();
  138. } else {
  139. puts("Undefined interrupt controller\n");
  140. }
  141. return 0;
  142. }
  143. void interrupt_handler (void)
  144. {
  145. int irqs = intc->ivr; /* find active interrupt */
  146. int mask = 1;
  147. #ifdef DEBUG_INT
  148. int value;
  149. printf ("INTC isr %x, ier %x, iar %x, mer %x\n", intc->isr, intc->ier,
  150. intc->iar, intc->mer);
  151. R14(value);
  152. printf ("Interrupt handler on %x line, r14 %x\n", irqs, value);
  153. #endif
  154. struct irq_action *act = vecs + irqs;
  155. #ifdef DEBUG_INT
  156. printf
  157. ("Jumping to interrupt handler rutine addr %x,count %x,arg %x\n",
  158. act->handler, act->count, act->arg);
  159. #endif
  160. act->handler (act->arg);
  161. act->count++;
  162. intc->iar = mask << irqs;
  163. #ifdef DEBUG_INT
  164. printf ("Dump INTC reg, isr %x, ier %x, iar %x, mer %x\n", intc->isr,
  165. intc->ier, intc->iar, intc->mer);
  166. R14(value);
  167. printf ("Interrupt handler on %x line, r14 %x\n", irqs, value);
  168. #endif
  169. }
  170. #if defined(CONFIG_CMD_IRQ)
  171. int do_irqinfo(cmd_tbl_t *cmdtp, int flag, int argc, const char *argv[])
  172. {
  173. int i;
  174. struct irq_action *act = vecs;
  175. if (irq_no) {
  176. puts("\nInterrupt-Information:\n\n"
  177. "Nr Routine Arg Count\n"
  178. "-----------------------------\n");
  179. for (i = 0; i < irq_no; i++) {
  180. if (act->handler != (interrupt_handler_t *) def_hdlr) {
  181. printf("%02d %08x %08x %d\n", i,
  182. (int)act->handler, (int)act->arg,
  183. act->count);
  184. }
  185. act++;
  186. }
  187. puts("\n");
  188. } else {
  189. puts("Undefined interrupt controller\n");
  190. }
  191. return 0;
  192. }
  193. #endif