interrupts.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. /*
  2. * (C) Copyright 2007
  3. * Daniel Hellstrom, Gaisler Research, daniel@gaisler.com
  4. *
  5. * (C) Copyright 2006
  6. * Detlev Zundel, DENX Software Engineering, dzu@denx.de
  7. *
  8. * (C) Copyright -2003
  9. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  10. *
  11. * (C) Copyright 2001
  12. * Josh Huber <huber@mclx.com>, Mission Critical Linux, Inc.
  13. *
  14. * See file CREDITS for list of people who contributed to this
  15. * project.
  16. *
  17. * This program is free software; you can redistribute it and/or
  18. * modify it under the terms of the GNU General Public License as
  19. * published by the Free Software Foundation; either version 2 of
  20. * the License, or (at your option) any later version.
  21. *
  22. * This program is distributed in the hope that it will be useful,
  23. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. * GNU General Public License for more details.
  26. *
  27. * You should have received a copy of the GNU General Public License
  28. * along with this program; if not, write to the Free Software
  29. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  30. * MA 02111-1307 USA
  31. */
  32. #include <asm/stack.h>
  33. #include <common.h>
  34. #include <asm/io.h>
  35. #include <asm/processor.h>
  36. #include <command.h>
  37. #include <asm/irq.h>
  38. #include <asm/leon.h>
  39. /* 15 normal irqs and a non maskable interrupt */
  40. #define NR_IRQS 15
  41. struct irq_action {
  42. interrupt_handler_t *handler;
  43. void *arg;
  44. unsigned int count;
  45. };
  46. static struct irq_action irq_handlers[NR_IRQS] = { {0}, };
  47. static int spurious_irq_cnt = 0;
  48. static int spurious_irq = 0;
  49. static inline unsigned int leon2_get_irqmask(unsigned int irq)
  50. {
  51. if ((irq < 0) || (irq >= NR_IRQS)) {
  52. return 0;
  53. } else {
  54. return (1 << irq);
  55. }
  56. }
  57. static void leon2_ic_disable(unsigned int irq)
  58. {
  59. unsigned int mask, pil;
  60. LEON2_regs *leon2 = (LEON2_regs *) LEON2_PREGS;
  61. pil = intLock();
  62. /* get mask of interrupt */
  63. mask = leon2_get_irqmask(irq);
  64. /* set int level */
  65. leon2->Interrupt_Mask =
  66. SPARC_NOCACHE_READ(&leon2->Interrupt_Mask) & (~mask);
  67. intUnlock(pil);
  68. }
  69. static void leon2_ic_enable(unsigned int irq)
  70. {
  71. unsigned int mask, pil;
  72. LEON2_regs *leon2 = (LEON2_regs *) LEON2_PREGS;
  73. pil = intLock();
  74. /* get mask of interrupt */
  75. mask = leon2_get_irqmask(irq);
  76. /* set int level */
  77. leon2->Interrupt_Mask =
  78. SPARC_NOCACHE_READ(&leon2->Interrupt_Mask) | mask;
  79. intUnlock(pil);
  80. }
  81. void handler_irq(int irq, struct pt_regs *regs)
  82. {
  83. if (irq_handlers[irq].handler) {
  84. if (((unsigned int)irq_handlers[irq].handler > CFG_RAM_END) ||
  85. ((unsigned int)irq_handlers[irq].handler < CFG_RAM_BASE)
  86. ) {
  87. printf("handler_irq: bad handler: %x, irq number %d\n",
  88. (unsigned int)irq_handlers[irq].handler, irq);
  89. return;
  90. }
  91. irq_handlers[irq].handler(irq_handlers[irq].arg);
  92. irq_handlers[irq].count++;
  93. } else {
  94. spurious_irq_cnt++;
  95. spurious_irq = irq;
  96. }
  97. }
  98. void leon2_force_int(int irq)
  99. {
  100. LEON2_regs *leon2 = (LEON2_regs *) LEON2_PREGS;
  101. if ((irq >= NR_IRQS) || (irq < 0))
  102. return;
  103. printf("Forcing interrupt %d\n", irq);
  104. leon2->Interrupt_Force =
  105. SPARC_NOCACHE_READ(&leon2->Interrupt_Force) | (1 << irq);
  106. }
  107. /****************************************************************************/
  108. int interrupt_init_cpu(void)
  109. {
  110. return (0);
  111. }
  112. /****************************************************************************/
  113. /* Handle Timer 0 IRQ */
  114. void timer_interrupt_cpu(void *arg)
  115. {
  116. LEON2_regs *leon2 = (LEON2_regs *) LEON2_PREGS;
  117. leon2->Timer_Control_1 =
  118. (LEON2_TIMER_CTRL_EN | LEON2_TIMER_CTRL_RS | LEON2_TIMER_CTRL_LD);
  119. /* nothing to do here */
  120. return;
  121. }
  122. /****************************************************************************/
  123. /*
  124. * Install and free a interrupt handler.
  125. */
  126. void irq_install_handler(int irq, interrupt_handler_t * handler, void *arg)
  127. {
  128. if (irq < 0 || irq >= NR_IRQS) {
  129. printf("irq_install_handler: bad irq number %d\n", irq);
  130. return;
  131. }
  132. if (irq_handlers[irq].handler != NULL)
  133. printf("irq_install_handler: 0x%08lx replacing 0x%08lx\n",
  134. (ulong) handler, (ulong) irq_handlers[irq].handler);
  135. if (((unsigned int)handler > CFG_RAM_END) ||
  136. ((unsigned int)handler < CFG_RAM_BASE)
  137. ) {
  138. printf("irq_install_handler: bad handler: %x, irq number %d\n",
  139. (unsigned int)handler, irq);
  140. return;
  141. }
  142. irq_handlers[irq].handler = handler;
  143. irq_handlers[irq].arg = arg;
  144. /* enable irq on LEON2 hardware */
  145. leon2_ic_enable(irq);
  146. }
  147. void irq_free_handler(int irq)
  148. {
  149. if (irq < 0 || irq >= NR_IRQS) {
  150. printf("irq_free_handler: bad irq number %d\n", irq);
  151. return;
  152. }
  153. /* disable irq on LEON2 hardware */
  154. leon2_ic_disable(irq);
  155. irq_handlers[irq].handler = NULL;
  156. irq_handlers[irq].arg = NULL;
  157. }
  158. /****************************************************************************/
  159. #if defined(CONFIG_CMD_IRQ)
  160. void do_irqinfo(cmd_tbl_t * cmdtp, bd_t * bd, int flag, int argc, char *argv[])
  161. {
  162. int irq;
  163. unsigned int pil = get_pil();
  164. printf("PIL level: %u\n\r", pil);
  165. printf("Spurious IRQ: %u, last unknown IRQ: %d\n",
  166. spurious_irq_cnt, spurious_irq);
  167. puts("\nInterrupt-Information:\n" "Nr Routine Arg Count\n");
  168. for (irq = 0; irq < NR_IRQS; irq++) {
  169. if (irq_handlers[irq].handler != NULL) {
  170. printf("%02d %08lx %08lx %ld\n", irq,
  171. (unsigned int)irq_handlers[irq].handler,
  172. (unsigned int)irq_handlers[irq].arg,
  173. irq_handlers[irq].count);
  174. }
  175. }
  176. }
  177. #endif