spurious.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. /*
  2. * linux/kernel/irq/spurious.c
  3. *
  4. * Copyright (C) 1992, 1998-2004 Linus Torvalds, Ingo Molnar
  5. *
  6. * This file contains spurious interrupt handling.
  7. */
  8. #include <linux/irq.h>
  9. #include <linux/module.h>
  10. #include <linux/kallsyms.h>
  11. #include <linux/interrupt.h>
  12. static int irqfixup __read_mostly;
  13. /*
  14. * Recovery handler for misrouted interrupts.
  15. */
  16. static int misrouted_irq(int irq)
  17. {
  18. int i;
  19. int ok = 0;
  20. int work = 0; /* Did we do work for a real IRQ */
  21. for (i = 1; i < NR_IRQS; i++) {
  22. struct irq_desc *desc = irq_desc + i;
  23. struct irqaction *action;
  24. if (i == irq) /* Already tried */
  25. continue;
  26. spin_lock(&desc->lock);
  27. /* Already running on another processor */
  28. if (desc->status & IRQ_INPROGRESS) {
  29. /*
  30. * Already running: If it is shared get the other
  31. * CPU to go looking for our mystery interrupt too
  32. */
  33. if (desc->action && (desc->action->flags & IRQF_SHARED))
  34. desc->status |= IRQ_PENDING;
  35. spin_unlock(&desc->lock);
  36. continue;
  37. }
  38. /* Honour the normal IRQ locking */
  39. desc->status |= IRQ_INPROGRESS;
  40. action = desc->action;
  41. spin_unlock(&desc->lock);
  42. while (action) {
  43. /* Only shared IRQ handlers are safe to call */
  44. if (action->flags & IRQF_SHARED) {
  45. if (action->handler(i, action->dev_id) ==
  46. IRQ_HANDLED)
  47. ok = 1;
  48. }
  49. action = action->next;
  50. }
  51. local_irq_disable();
  52. /* Now clean up the flags */
  53. spin_lock(&desc->lock);
  54. action = desc->action;
  55. /*
  56. * While we were looking for a fixup someone queued a real
  57. * IRQ clashing with our walk:
  58. */
  59. while ((desc->status & IRQ_PENDING) && action) {
  60. /*
  61. * Perform real IRQ processing for the IRQ we deferred
  62. */
  63. work = 1;
  64. spin_unlock(&desc->lock);
  65. handle_IRQ_event(i, action);
  66. spin_lock(&desc->lock);
  67. desc->status &= ~IRQ_PENDING;
  68. }
  69. desc->status &= ~IRQ_INPROGRESS;
  70. /*
  71. * If we did actual work for the real IRQ line we must let the
  72. * IRQ controller clean up too
  73. */
  74. if (work && desc->chip && desc->chip->end)
  75. desc->chip->end(i);
  76. spin_unlock(&desc->lock);
  77. }
  78. /* So the caller can adjust the irq error counts */
  79. return ok;
  80. }
  81. /*
  82. * If 99,900 of the previous 100,000 interrupts have not been handled
  83. * then assume that the IRQ is stuck in some manner. Drop a diagnostic
  84. * and try to turn the IRQ off.
  85. *
  86. * (The other 100-of-100,000 interrupts may have been a correctly
  87. * functioning device sharing an IRQ with the failing one)
  88. *
  89. * Called under desc->lock
  90. */
  91. static void
  92. __report_bad_irq(unsigned int irq, struct irq_desc *desc,
  93. irqreturn_t action_ret)
  94. {
  95. struct irqaction *action;
  96. if (action_ret != IRQ_HANDLED && action_ret != IRQ_NONE) {
  97. printk(KERN_ERR "irq event %d: bogus return value %x\n",
  98. irq, action_ret);
  99. } else {
  100. printk(KERN_ERR "irq %d: nobody cared (try booting with "
  101. "the \"irqpoll\" option)\n", irq);
  102. }
  103. dump_stack();
  104. printk(KERN_ERR "handlers:\n");
  105. action = desc->action;
  106. while (action) {
  107. printk(KERN_ERR "[<%p>]", action->handler);
  108. print_symbol(" (%s)",
  109. (unsigned long)action->handler);
  110. printk("\n");
  111. action = action->next;
  112. }
  113. }
  114. static void
  115. report_bad_irq(unsigned int irq, struct irq_desc *desc, irqreturn_t action_ret)
  116. {
  117. static int count = 100;
  118. if (count > 0) {
  119. count--;
  120. __report_bad_irq(irq, desc, action_ret);
  121. }
  122. }
  123. void note_interrupt(unsigned int irq, struct irq_desc *desc,
  124. irqreturn_t action_ret)
  125. {
  126. if (unlikely(action_ret != IRQ_HANDLED)) {
  127. desc->irqs_unhandled++;
  128. if (unlikely(action_ret != IRQ_NONE))
  129. report_bad_irq(irq, desc, action_ret);
  130. }
  131. if (unlikely(irqfixup)) {
  132. /* Don't punish working computers */
  133. if ((irqfixup == 2 && irq == 0) || action_ret == IRQ_NONE) {
  134. int ok = misrouted_irq(irq);
  135. if (action_ret == IRQ_NONE)
  136. desc->irqs_unhandled -= ok;
  137. }
  138. }
  139. desc->irq_count++;
  140. if (likely(desc->irq_count < 100000))
  141. return;
  142. desc->irq_count = 0;
  143. if (unlikely(desc->irqs_unhandled > 99900)) {
  144. /*
  145. * The interrupt is stuck
  146. */
  147. __report_bad_irq(irq, desc, action_ret);
  148. /*
  149. * Now kill the IRQ
  150. */
  151. printk(KERN_EMERG "Disabling IRQ #%d\n", irq);
  152. desc->status |= IRQ_DISABLED;
  153. desc->depth = 1;
  154. desc->chip->disable(irq);
  155. }
  156. desc->irqs_unhandled = 0;
  157. }
  158. int noirqdebug __read_mostly;
  159. int noirqdebug_setup(char *str)
  160. {
  161. noirqdebug = 1;
  162. printk(KERN_INFO "IRQ lockup detection disabled\n");
  163. return 1;
  164. }
  165. __setup("noirqdebug", noirqdebug_setup);
  166. static int __init irqfixup_setup(char *str)
  167. {
  168. irqfixup = 1;
  169. printk(KERN_WARNING "Misrouted IRQ fixup support enabled.\n");
  170. printk(KERN_WARNING "This may impact system performance.\n");
  171. return 1;
  172. }
  173. __setup("irqfixup", irqfixup_setup);
  174. static int __init irqpoll_setup(char *str)
  175. {
  176. irqfixup = 2;
  177. printk(KERN_WARNING "Misrouted IRQ fixup and polling support "
  178. "enabled\n");
  179. printk(KERN_WARNING "This may significantly impact system "
  180. "performance\n");
  181. return 1;
  182. }
  183. __setup("irqpoll", irqpoll_setup);