interrupts.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. /*
  98. * Install and free a interrupt handler.
  99. */
  100. void irq_install_handler(int irq, interrupt_handler_t * handler, void *arg)
  101. {
  102. if (irq < 0 || irq >= NR_IRQS) {
  103. printf("irq_install_handler: bad irq number %d\n", irq);
  104. return;
  105. }
  106. if (irq_handlers[irq].handler != NULL)
  107. printf("irq_install_handler: 0x%08lx replacing 0x%08lx\n",
  108. (ulong) handler, (ulong) irq_handlers[irq].handler);
  109. if (((unsigned int)handler > CONFIG_SYS_RAM_END) ||
  110. ((unsigned int)handler < CONFIG_SYS_RAM_BASE)
  111. ) {
  112. printf("irq_install_handler: bad handler: %x, irq number %d\n",
  113. (unsigned int)handler, irq);
  114. return;
  115. }
  116. irq_handlers[irq].handler = handler;
  117. irq_handlers[irq].arg = arg;
  118. /* enable irq on LEON2 hardware */
  119. leon2_ic_enable(irq);
  120. }
  121. void irq_free_handler(int irq)
  122. {
  123. if (irq < 0 || irq >= NR_IRQS) {
  124. printf("irq_free_handler: bad irq number %d\n", irq);
  125. return;
  126. }
  127. /* disable irq on LEON2 hardware */
  128. leon2_ic_disable(irq);
  129. irq_handlers[irq].handler = NULL;
  130. irq_handlers[irq].arg = NULL;
  131. }
  132. /****************************************************************************/
  133. #if defined(CONFIG_CMD_IRQ)
  134. void do_irqinfo(cmd_tbl_t * cmdtp, bd_t * bd, int flag, int argc, char * const argv[])
  135. {
  136. int irq;
  137. unsigned int pil = get_pil();
  138. printf("PIL level: %u\n\r", pil);
  139. printf("Spurious IRQ: %u, last unknown IRQ: %d\n",
  140. spurious_irq_cnt, spurious_irq);
  141. puts("\nInterrupt-Information:\n" "Nr Routine Arg Count\n");
  142. for (irq = 0; irq < NR_IRQS; irq++) {
  143. if (irq_handlers[irq].handler != NULL) {
  144. printf("%02d %p %p %d\n", irq,
  145. irq_handlers[irq].handler,
  146. irq_handlers[irq].arg,
  147. irq_handlers[irq].count);
  148. }
  149. }
  150. }
  151. #endif