interrupts.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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, Mission Critical Linux, Inc, <huber@mclx.com>
  19. *
  20. * SPDX-License-Identifier: GPL-2.0+
  21. */
  22. /*
  23. * This file contains the high-level API for the interrupt sub-system
  24. * of the x86 port of U-Boot. Most of the functionality has been
  25. * shamelessly stolen from the leon2 / leon3 ports of U-Boot.
  26. * Daniel Hellstrom, Detlev Zundel, Wolfgang Denk and Josh Huber are
  27. * credited for the corresponding work on those ports. The original
  28. * interrupt handling routines for the x86 port were written by
  29. * Daniel Engström
  30. */
  31. #include <common.h>
  32. #include <asm/interrupt.h>
  33. struct irq_action {
  34. interrupt_handler_t *handler;
  35. void *arg;
  36. unsigned int count;
  37. };
  38. static struct irq_action irq_handlers[SYS_NUM_IRQS] = { {0} };
  39. static int spurious_irq_cnt;
  40. static int spurious_irq;
  41. void irq_install_handler(int irq, interrupt_handler_t *handler, void *arg)
  42. {
  43. int status;
  44. if (irq < 0 || irq >= SYS_NUM_IRQS) {
  45. printf("irq_install_handler: bad irq number %d\n", irq);
  46. return;
  47. }
  48. if (irq_handlers[irq].handler != NULL)
  49. printf("irq_install_handler: 0x%08lx replacing 0x%08lx\n",
  50. (ulong) handler,
  51. (ulong) irq_handlers[irq].handler);
  52. status = disable_interrupts();
  53. irq_handlers[irq].handler = handler;
  54. irq_handlers[irq].arg = arg;
  55. irq_handlers[irq].count = 0;
  56. unmask_irq(irq);
  57. if (status)
  58. enable_interrupts();
  59. return;
  60. }
  61. void irq_free_handler(int irq)
  62. {
  63. int status;
  64. if (irq < 0 || irq >= SYS_NUM_IRQS) {
  65. printf("irq_free_handler: bad irq number %d\n", irq);
  66. return;
  67. }
  68. status = disable_interrupts();
  69. mask_irq(irq);
  70. irq_handlers[irq].handler = NULL;
  71. irq_handlers[irq].arg = NULL;
  72. if (status)
  73. enable_interrupts();
  74. return;
  75. }
  76. void do_irq(int hw_irq)
  77. {
  78. int irq = hw_irq - 0x20;
  79. if (irq < 0 || irq >= SYS_NUM_IRQS) {
  80. printf("do_irq: bad irq number %d\n", irq);
  81. return;
  82. }
  83. if (irq_handlers[irq].handler) {
  84. mask_irq(irq);
  85. irq_handlers[irq].handler(irq_handlers[irq].arg);
  86. irq_handlers[irq].count++;
  87. unmask_irq(irq);
  88. specific_eoi(irq);
  89. } else {
  90. if ((irq & 7) != 7) {
  91. spurious_irq_cnt++;
  92. spurious_irq = irq;
  93. }
  94. }
  95. }
  96. #if defined(CONFIG_CMD_IRQ)
  97. int do_irqinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  98. {
  99. int irq;
  100. printf("Spurious IRQ: %u, last unknown IRQ: %d\n",
  101. spurious_irq_cnt, spurious_irq);
  102. printf("Interrupt-Information:\n");
  103. printf("Nr Routine Arg Count\n");
  104. for (irq = 0; irq < SYS_NUM_IRQS; irq++) {
  105. if (irq_handlers[irq].handler != NULL) {
  106. printf("%02d %08lx %08lx %d\n",
  107. irq,
  108. (ulong)irq_handlers[irq].handler,
  109. (ulong)irq_handlers[irq].arg,
  110. irq_handlers[irq].count);
  111. }
  112. }
  113. return 0;
  114. }
  115. #endif