resend.c 2.5 KB

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