resend.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (C) 1992, 1998-2006 Linus Torvalds, Ingo Molnar
  4. * Copyright (C) 2005-2006, Thomas Gleixner
  5. *
  6. * This file contains the IRQ-resend code
  7. *
  8. * If the interrupt is waiting to be processed, we try to re-run it.
  9. * We can't directly run it from here since the caller might be in an
  10. * interrupt-protected region. Not all irq controller chips can
  11. * retrigger interrupts at the hardware level, so in those cases
  12. * we allow the resending of IRQs via a tasklet.
  13. */
  14. #include <linux/irq.h>
  15. #include <linux/module.h>
  16. #include <linux/random.h>
  17. #include <linux/interrupt.h>
  18. #include "internals.h"
  19. #ifdef CONFIG_HARDIRQS_SW_RESEND
  20. /* Bitmap to handle software resend of interrupts: */
  21. static DECLARE_BITMAP(irqs_resend, IRQ_BITMAP_BITS);
  22. /*
  23. * Run software resends of IRQ's
  24. */
  25. static void resend_irqs(unsigned long arg)
  26. {
  27. struct irq_desc *desc;
  28. int irq;
  29. while (!bitmap_empty(irqs_resend, nr_irqs)) {
  30. irq = find_first_bit(irqs_resend, nr_irqs);
  31. clear_bit(irq, irqs_resend);
  32. desc = irq_to_desc(irq);
  33. if (!desc)
  34. continue;
  35. local_irq_disable();
  36. desc->handle_irq(desc);
  37. local_irq_enable();
  38. }
  39. }
  40. /* Tasklet to handle resend: */
  41. static DECLARE_TASKLET(resend_tasklet, resend_irqs, 0);
  42. #endif
  43. /*
  44. * IRQ resend
  45. *
  46. * Is called with interrupts disabled and desc->lock held.
  47. */
  48. void check_irq_resend(struct irq_desc *desc)
  49. {
  50. /*
  51. * We do not resend level type interrupts. Level type
  52. * interrupts are resent by hardware when they are still
  53. * active. Clear the pending bit so suspend/resume does not
  54. * get confused.
  55. */
  56. if (irq_settings_is_level(desc)) {
  57. desc->istate &= ~IRQS_PENDING;
  58. return;
  59. }
  60. if (desc->istate & IRQS_REPLAY)
  61. return;
  62. if (desc->istate & IRQS_PENDING) {
  63. desc->istate &= ~IRQS_PENDING;
  64. desc->istate |= IRQS_REPLAY;
  65. if (!desc->irq_data.chip->irq_retrigger ||
  66. !desc->irq_data.chip->irq_retrigger(&desc->irq_data)) {
  67. #ifdef CONFIG_HARDIRQS_SW_RESEND
  68. unsigned int irq = irq_desc_get_irq(desc);
  69. /*
  70. * If the interrupt is running in the thread
  71. * context of the parent irq we need to be
  72. * careful, because we cannot trigger it
  73. * directly.
  74. */
  75. if (irq_settings_is_nested_thread(desc)) {
  76. /*
  77. * If the parent_irq is valid, we
  78. * retrigger the parent, otherwise we
  79. * do nothing.
  80. */
  81. if (!desc->parent_irq)
  82. return;
  83. irq = desc->parent_irq;
  84. }
  85. /* Set it pending and activate the softirq: */
  86. set_bit(irq, irqs_resend);
  87. tasklet_schedule(&resend_tasklet);
  88. #endif
  89. }
  90. }
  91. }