interrupts.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2009
  4. * Graeme Russ, <graeme.russ@gmail.com>
  5. *
  6. * (C) Copyright 2007
  7. * Daniel Hellstrom, Gaisler Research, <daniel@gaisler.com>
  8. *
  9. * (C) Copyright 2006
  10. * Detlev Zundel, DENX Software Engineering, <dzu@denx.de>
  11. *
  12. * (C) Copyright -2003
  13. * Wolfgang Denk, DENX Software Engineering, <wd@denx.de>
  14. *
  15. * (C) Copyright 2002
  16. * Daniel Engström, Omicron Ceti AB, <daniel@omicron.se>
  17. *
  18. * (C) Copyright 2001
  19. * Josh Huber, Mission Critical Linux, Inc, <huber@mclx.com>
  20. */
  21. /*
  22. * This file contains the high-level API for the interrupt sub-system
  23. * of the x86 port of U-Boot. Most of the functionality has been
  24. * shamelessly stolen from the leon2 / leon3 ports of U-Boot.
  25. * Daniel Hellstrom, Detlev Zundel, Wolfgang Denk and Josh Huber are
  26. * credited for the corresponding work on those ports. The original
  27. * interrupt handling routines for the x86 port were written by
  28. * Daniel Engström
  29. */
  30. #include <common.h>
  31. #include <command.h>
  32. #include <irq_func.h>
  33. #include <asm/interrupt.h>
  34. #if !CONFIG_IS_ENABLED(X86_64)
  35. struct irq_action {
  36. interrupt_handler_t *handler;
  37. void *arg;
  38. unsigned int count;
  39. };
  40. static struct irq_action irq_handlers[SYS_NUM_IRQS] = { {0} };
  41. static int spurious_irq_cnt;
  42. static int spurious_irq;
  43. void irq_install_handler(int irq, interrupt_handler_t *handler, void *arg)
  44. {
  45. int status;
  46. if (irq < 0 || irq >= SYS_NUM_IRQS) {
  47. printf("irq_install_handler: bad irq number %d\n", irq);
  48. return;
  49. }
  50. if (irq_handlers[irq].handler != NULL)
  51. printf("irq_install_handler: 0x%08lx replacing 0x%08lx\n",
  52. (ulong) handler,
  53. (ulong) irq_handlers[irq].handler);
  54. status = disable_interrupts();
  55. irq_handlers[irq].handler = handler;
  56. irq_handlers[irq].arg = arg;
  57. irq_handlers[irq].count = 0;
  58. if (CONFIG_IS_ENABLED(I8259_PIC))
  59. unmask_irq(irq);
  60. if (status)
  61. enable_interrupts();
  62. return;
  63. }
  64. void irq_free_handler(int irq)
  65. {
  66. int status;
  67. if (irq < 0 || irq >= SYS_NUM_IRQS) {
  68. printf("irq_free_handler: bad irq number %d\n", irq);
  69. return;
  70. }
  71. status = disable_interrupts();
  72. if (CONFIG_IS_ENABLED(I8259_PIC))
  73. mask_irq(irq);
  74. irq_handlers[irq].handler = NULL;
  75. irq_handlers[irq].arg = NULL;
  76. if (status)
  77. enable_interrupts();
  78. return;
  79. }
  80. void do_irq(int hw_irq)
  81. {
  82. int irq = hw_irq - 0x20;
  83. if (irq < 0 || irq >= SYS_NUM_IRQS) {
  84. printf("do_irq: bad irq number %d\n", irq);
  85. return;
  86. }
  87. if (irq_handlers[irq].handler) {
  88. if (CONFIG_IS_ENABLED(I8259_PIC))
  89. mask_irq(irq);
  90. irq_handlers[irq].handler(irq_handlers[irq].arg);
  91. irq_handlers[irq].count++;
  92. if (CONFIG_IS_ENABLED(I8259_PIC)) {
  93. unmask_irq(irq);
  94. specific_eoi(irq);
  95. }
  96. } else {
  97. if ((irq & 7) != 7) {
  98. spurious_irq_cnt++;
  99. spurious_irq = irq;
  100. }
  101. }
  102. }
  103. #endif
  104. #if defined(CONFIG_CMD_IRQ)
  105. int do_irqinfo(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
  106. {
  107. #if !CONFIG_IS_ENABLED(X86_64)
  108. int irq;
  109. printf("Spurious IRQ: %u, last unknown IRQ: %d\n",
  110. spurious_irq_cnt, spurious_irq);
  111. printf("Interrupt-Information:\n");
  112. printf("Nr Routine Arg Count\n");
  113. for (irq = 0; irq < SYS_NUM_IRQS; irq++) {
  114. if (irq_handlers[irq].handler != NULL) {
  115. printf("%02d %08lx %08lx %d\n",
  116. irq,
  117. (ulong)irq_handlers[irq].handler,
  118. (ulong)irq_handlers[irq].arg,
  119. irq_handlers[irq].count);
  120. }
  121. }
  122. #endif
  123. return 0;
  124. }
  125. #endif