interrupts.c 4.5 KB

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