interrupts.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. #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. unmask_irq(irq);
  58. if (status)
  59. enable_interrupts();
  60. return;
  61. }
  62. void irq_free_handler(int irq)
  63. {
  64. int status;
  65. if (irq < 0 || irq >= SYS_NUM_IRQS) {
  66. printf("irq_free_handler: bad irq number %d\n", irq);
  67. return;
  68. }
  69. status = disable_interrupts();
  70. mask_irq(irq);
  71. irq_handlers[irq].handler = NULL;
  72. irq_handlers[irq].arg = NULL;
  73. if (status)
  74. enable_interrupts();
  75. return;
  76. }
  77. void do_irq(int hw_irq)
  78. {
  79. int irq = hw_irq - 0x20;
  80. if (irq < 0 || irq >= SYS_NUM_IRQS) {
  81. printf("do_irq: bad irq number %d\n", irq);
  82. return;
  83. }
  84. if (irq_handlers[irq].handler) {
  85. mask_irq(irq);
  86. irq_handlers[irq].handler(irq_handlers[irq].arg);
  87. irq_handlers[irq].count++;
  88. unmask_irq(irq);
  89. specific_eoi(irq);
  90. } else {
  91. if ((irq & 7) != 7) {
  92. spurious_irq_cnt++;
  93. spurious_irq = irq;
  94. }
  95. }
  96. }
  97. #endif
  98. #if defined(CONFIG_CMD_IRQ)
  99. int do_irqinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  100. {
  101. #if !CONFIG_IS_ENABLED(X86_64)
  102. int irq;
  103. printf("Spurious IRQ: %u, last unknown IRQ: %d\n",
  104. spurious_irq_cnt, spurious_irq);
  105. printf("Interrupt-Information:\n");
  106. printf("Nr Routine Arg Count\n");
  107. for (irq = 0; irq < SYS_NUM_IRQS; irq++) {
  108. if (irq_handlers[irq].handler != NULL) {
  109. printf("%02d %08lx %08lx %d\n",
  110. irq,
  111. (ulong)irq_handlers[irq].handler,
  112. (ulong)irq_handlers[irq].arg,
  113. irq_handlers[irq].count);
  114. }
  115. }
  116. #endif
  117. return 0;
  118. }
  119. #endif