interrupts.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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. #include <ambapp.h>
  40. /* 15 normal irqs and a non maskable interrupt */
  41. #define NR_IRQS 15
  42. struct irq_action {
  43. interrupt_handler_t *handler;
  44. void *arg;
  45. unsigned int count;
  46. };
  47. extern ambapp_dev_irqmp *irqmp;
  48. extern ambapp_dev_gptimer *gptimer;
  49. static struct irq_action irq_handlers[NR_IRQS] = { {0}, };
  50. static int spurious_irq_cnt = 0;
  51. static int spurious_irq = 0;
  52. static inline unsigned int irqmp_get_irqmask(unsigned int irq)
  53. {
  54. if ((irq < 0) || (irq >= NR_IRQS)) {
  55. return 0;
  56. } else {
  57. return (1 << irq);
  58. }
  59. }
  60. static void leon3_ic_disable(unsigned int irq)
  61. {
  62. unsigned int mask, pil;
  63. if (!irqmp)
  64. return;
  65. pil = intLock();
  66. /* get mask of interrupt */
  67. mask = irqmp_get_irqmask(irq);
  68. /* set int level */
  69. irqmp->cpu_mask[0] = SPARC_NOCACHE_READ(&irqmp->cpu_mask[0]) & (~mask);
  70. intUnlock(pil);
  71. }
  72. static void leon3_ic_enable(unsigned int irq)
  73. {
  74. unsigned int mask, pil;
  75. if (!irqmp)
  76. return;
  77. pil = intLock();
  78. /* get mask of interrupt */
  79. mask = irqmp_get_irqmask(irq);
  80. /* set int level */
  81. irqmp->cpu_mask[0] = SPARC_NOCACHE_READ(&irqmp->cpu_mask[0]) | mask;
  82. intUnlock(pil);
  83. }
  84. void handler_irq(int irq, struct pt_regs *regs)
  85. {
  86. if (irq_handlers[irq].handler) {
  87. if (((unsigned int)irq_handlers[irq].handler > CFG_RAM_END) ||
  88. ((unsigned int)irq_handlers[irq].handler < CFG_RAM_BASE)
  89. ) {
  90. printf("handler_irq: bad handler: %x, irq number %d\n",
  91. (unsigned int)irq_handlers[irq].handler, irq);
  92. return;
  93. }
  94. irq_handlers[irq].handler(irq_handlers[irq].arg);
  95. irq_handlers[irq].count++;
  96. } else {
  97. spurious_irq_cnt++;
  98. spurious_irq = irq;
  99. }
  100. }
  101. void leon3_force_int(int irq)
  102. {
  103. if (!irqmp || (irq >= NR_IRQS) || (irq < 0))
  104. return;
  105. printf("Forcing interrupt %d\n", irq);
  106. irqmp->iforce = SPARC_NOCACHE_READ(&irqmp->iforce) | (1 << irq);
  107. }
  108. /****************************************************************************/
  109. int interrupt_init_cpu(void)
  110. {
  111. return (0);
  112. }
  113. /****************************************************************************/
  114. /* Handle Timer 0 IRQ */
  115. void timer_interrupt_cpu(void *arg)
  116. {
  117. gptimer->e[0].ctrl = (LEON3_GPTIMER_EN |
  118. LEON3_GPTIMER_RL |
  119. LEON3_GPTIMER_LD | LEON3_GPTIMER_IRQEN);
  120. /* nothing to do here */
  121. return;
  122. }
  123. /****************************************************************************/
  124. /*
  125. * Install and free a interrupt handler.
  126. */
  127. void irq_install_handler(int irq, interrupt_handler_t * handler, void *arg)
  128. {
  129. if (irq < 0 || irq >= NR_IRQS) {
  130. printf("irq_install_handler: bad irq number %d\n", irq);
  131. return;
  132. }
  133. if (irq_handlers[irq].handler != NULL)
  134. printf("irq_install_handler: 0x%08lx replacing 0x%08lx\n",
  135. (ulong) handler, (ulong) irq_handlers[irq].handler);
  136. if (((unsigned int)handler > CFG_RAM_END) ||
  137. ((unsigned int)handler < CFG_RAM_BASE)
  138. ) {
  139. printf("irq_install_handler: bad handler: %x, irq number %d\n",
  140. (unsigned int)handler, irq);
  141. return;
  142. }
  143. irq_handlers[irq].handler = handler;
  144. irq_handlers[irq].arg = arg;
  145. /* enable irq on IRQMP hardware */
  146. leon3_ic_enable(irq);
  147. }
  148. void irq_free_handler(int irq)
  149. {
  150. if (irq < 0 || irq >= NR_IRQS) {
  151. printf("irq_free_handler: bad irq number %d\n", irq);
  152. return;
  153. }
  154. /* disable irq on IRQMP hardware */
  155. leon3_ic_disable(irq);
  156. irq_handlers[irq].handler = NULL;
  157. irq_handlers[irq].arg = NULL;
  158. }
  159. /****************************************************************************/
  160. #if defined(CONFIG_CMD_IRQ)
  161. void do_irqinfo(cmd_tbl_t * cmdtp, bd_t * bd, int flag, int argc, char *argv[])
  162. {
  163. int irq;
  164. unsigned int pil = get_pil();
  165. printf("PIL level: %u\n\r", pil);
  166. printf("Spurious IRQ: %u, last unknown IRQ: %d\n",
  167. spurious_irq_cnt, spurious_irq);
  168. puts("\nInterrupt-Information:\n" "Nr Routine Arg Count\n");
  169. for (irq = 0; irq < NR_IRQS; irq++) {
  170. if (irq_handlers[irq].handler != NULL) {
  171. printf("%02d %08lx %08lx %ld\n", irq,
  172. (unsigned int)irq_handlers[irq].handler,
  173. (unsigned int)irq_handlers[irq].arg,
  174. irq_handlers[irq].count);
  175. }
  176. }
  177. }
  178. #endif