interrupts.c 4.5 KB

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