interrupts.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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 <irq_func.h>
  32. #include <asm/interrupt.h>
  33. #if !CONFIG_IS_ENABLED(X86_64)
  34. struct irq_action {
  35. interrupt_handler_t *handler;
  36. void *arg;
  37. unsigned int count;
  38. };
  39. static struct irq_action irq_handlers[SYS_NUM_IRQS] = { {0} };
  40. static int spurious_irq_cnt;
  41. static int spurious_irq;
  42. void irq_install_handler(int irq, interrupt_handler_t *handler, void *arg)
  43. {
  44. int status;
  45. if (irq < 0 || irq >= SYS_NUM_IRQS) {
  46. printf("irq_install_handler: bad irq number %d\n", irq);
  47. return;
  48. }
  49. if (irq_handlers[irq].handler != NULL)
  50. printf("irq_install_handler: 0x%08lx replacing 0x%08lx\n",
  51. (ulong) handler,
  52. (ulong) irq_handlers[irq].handler);
  53. status = disable_interrupts();
  54. irq_handlers[irq].handler = handler;
  55. irq_handlers[irq].arg = arg;
  56. irq_handlers[irq].count = 0;
  57. if (CONFIG_IS_ENABLED(I8259_PIC))
  58. unmask_irq(irq);
  59. if (status)
  60. enable_interrupts();
  61. return;
  62. }
  63. void irq_free_handler(int irq)
  64. {
  65. int status;
  66. if (irq < 0 || irq >= SYS_NUM_IRQS) {
  67. printf("irq_free_handler: bad irq number %d\n", irq);
  68. return;
  69. }
  70. status = disable_interrupts();
  71. if (CONFIG_IS_ENABLED(I8259_PIC))
  72. mask_irq(irq);
  73. irq_handlers[irq].handler = NULL;
  74. irq_handlers[irq].arg = NULL;
  75. if (status)
  76. enable_interrupts();
  77. return;
  78. }
  79. void do_irq(int hw_irq)
  80. {
  81. int irq = hw_irq - 0x20;
  82. if (irq < 0 || irq >= SYS_NUM_IRQS) {
  83. printf("do_irq: bad irq number %d\n", irq);
  84. return;
  85. }
  86. if (irq_handlers[irq].handler) {
  87. if (CONFIG_IS_ENABLED(I8259_PIC))
  88. mask_irq(irq);
  89. irq_handlers[irq].handler(irq_handlers[irq].arg);
  90. irq_handlers[irq].count++;
  91. if (CONFIG_IS_ENABLED(I8259_PIC)) {
  92. unmask_irq(irq);
  93. specific_eoi(irq);
  94. }
  95. } else {
  96. if ((irq & 7) != 7) {
  97. spurious_irq_cnt++;
  98. spurious_irq = irq;
  99. }
  100. }
  101. }
  102. #endif
  103. #if defined(CONFIG_CMD_IRQ)
  104. int do_irqinfo(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
  105. {
  106. #if !CONFIG_IS_ENABLED(X86_64)
  107. int irq;
  108. printf("Spurious IRQ: %u, last unknown IRQ: %d\n",
  109. spurious_irq_cnt, spurious_irq);
  110. printf("Interrupt-Information:\n");
  111. printf("Nr Routine Arg Count\n");
  112. for (irq = 0; irq < SYS_NUM_IRQS; irq++) {
  113. if (irq_handlers[irq].handler != NULL) {
  114. printf("%02d %08lx %08lx %d\n",
  115. irq,
  116. (ulong)irq_handlers[irq].handler,
  117. (ulong)irq_handlers[irq].arg,
  118. irq_handlers[irq].count);
  119. }
  120. }
  121. #endif
  122. return 0;
  123. }
  124. #endif