interrupts.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*
  2. * (C) Copyright 2009
  3. * Graeme Russ, graeme.russ@gmail.com
  4. *
  5. * (C) Copyright 2007
  6. * Daniel Hellstrom, Gaisler Research, daniel@gaisler.com
  7. *
  8. * (C) Copyright 2006
  9. * Detlev Zundel, DENX Software Engineering, dzu@denx.de
  10. *
  11. * (C) Copyright -2003
  12. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  13. *
  14. * (C) Copyright 2002
  15. * Daniel Engström, Omicron Ceti AB, daniel@omicron.se
  16. *
  17. * (C) Copyright 2001
  18. * Josh Huber <huber@mclx.com>, Mission Critical Linux, Inc.
  19. *
  20. * See file CREDITS for list of people who contributed to this
  21. * project.
  22. *
  23. * This program is free software; you can redistribute it and/or
  24. * modify it under the terms of the GNU General Public License as
  25. * published by the Free Software Foundation; either version 2 of
  26. * the License, or (at your option) any later version.
  27. *
  28. * This program is distributed in the hope that it will be useful,
  29. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  30. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  31. * GNU General Public License for more details.
  32. *
  33. * You should have received a copy of the GNU General Public License
  34. * along with this program; if not, write to the Free Software
  35. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  36. * MA 02111-1307 USA
  37. */
  38. /*
  39. * This file contains the high-level API for the interrupt sub-system
  40. * of the i386 port of U-Boot. Most of the functionality has been
  41. * shamelessly stolen from the leon2 / leon3 ports of U-Boot.
  42. * Daniel Hellstrom, Detlev Zundel, Wolfgang Denk and Josh Huber are
  43. * credited for the corresponding work on those ports. The original
  44. * interrupt handling routines for the i386 port were written by
  45. * Daniel Engström
  46. */
  47. #include <common.h>
  48. #include <asm/interrupt.h>
  49. struct irq_action {
  50. interrupt_handler_t *handler;
  51. void *arg;
  52. unsigned int count;
  53. };
  54. static struct irq_action irq_handlers[CONFIG_SYS_NUM_IRQS] = { {0} };
  55. static int spurious_irq_cnt = 0;
  56. static int spurious_irq = 0;
  57. void irq_install_handler(int irq, interrupt_handler_t *handler, void *arg)
  58. {
  59. int status;
  60. if (irq < 0 || irq >= CONFIG_SYS_NUM_IRQS) {
  61. printf("irq_install_handler: bad irq number %d\n", irq);
  62. return;
  63. }
  64. if (irq_handlers[irq].handler != NULL)
  65. printf("irq_install_handler: 0x%08lx replacing 0x%08lx\n",
  66. (ulong) handler,
  67. (ulong) irq_handlers[irq].handler);
  68. status = disable_interrupts ();
  69. irq_handlers[irq].handler = handler;
  70. irq_handlers[irq].arg = arg;
  71. irq_handlers[irq].count = 0;
  72. unmask_irq(irq);
  73. if (status)
  74. enable_interrupts();
  75. return;
  76. }
  77. void irq_free_handler(int irq)
  78. {
  79. int status;
  80. if (irq < 0 || irq >= CONFIG_SYS_NUM_IRQS) {
  81. printf("irq_free_handler: bad irq number %d\n", irq);
  82. return;
  83. }
  84. status = disable_interrupts ();
  85. mask_irq(irq);
  86. irq_handlers[irq].handler = NULL;
  87. irq_handlers[irq].arg = NULL;
  88. if (status)
  89. enable_interrupts();
  90. return;
  91. }
  92. __isr__ do_irq(int irq)
  93. {
  94. if (irq < 0 || irq >= CONFIG_SYS_NUM_IRQS) {
  95. printf("do_irq: bad irq number %d\n", irq);
  96. return;
  97. }
  98. if (irq_handlers[irq].handler) {
  99. mask_irq(irq);
  100. irq_handlers[irq].handler(irq_handlers[irq].arg);
  101. irq_handlers[irq].count++;
  102. unmask_irq(irq);
  103. specific_eoi(irq);
  104. } else {
  105. if ((irq & 7) != 7) {
  106. spurious_irq_cnt++;
  107. spurious_irq = irq;
  108. }
  109. }
  110. }
  111. #if defined(CONFIG_CMD_IRQ)
  112. int do_irqinfo(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  113. {
  114. int irq;
  115. printf("Spurious IRQ: %u, last unknown IRQ: %d\n",
  116. spurious_irq_cnt, spurious_irq);
  117. printf ("Interrupt-Information:\n");
  118. printf ("Nr Routine Arg Count\n");
  119. for (irq = 0; irq <= CONFIG_SYS_NUM_IRQS; irq++) {
  120. if (irq_handlers[irq].handler != NULL) {
  121. printf ("%02d %08lx %08lx %d\n",
  122. irq,
  123. (ulong)irq_handlers[irq].handler,
  124. (ulong)irq_handlers[irq].arg,
  125. irq_handlers[irq].count);
  126. }
  127. }
  128. return 0;
  129. }
  130. #endif