spurious.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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. static inline int try_misrouted_irq(unsigned int irq, struct irq_desc *desc, irqreturn_t action_ret)
  124. {
  125. struct irqaction *action;
  126. if (!irqfixup)
  127. return 0;
  128. /* We didn't actually handle the IRQ - see if it was misrouted? */
  129. if (action_ret == IRQ_NONE)
  130. return 1;
  131. /*
  132. * But for 'irqfixup == 2' we also do it for handled interrupts if
  133. * they are marked as IRQF_IRQPOLL (or for irq zero, which is the
  134. * traditional PC timer interrupt.. Legacy)
  135. */
  136. if (irqfixup < 2)
  137. return 0;
  138. if (!irq)
  139. return 1;
  140. /*
  141. * Since we don't get the descriptor lock, "action" can
  142. * change under us. We don't really care, but we don't
  143. * want to follow a NULL pointer. So tell the compiler to
  144. * just load it once by using a barrier.
  145. */
  146. action = desc->action;
  147. barrier();
  148. return action && (action->flags & IRQF_IRQPOLL);
  149. }
  150. void note_interrupt(unsigned int irq, struct irq_desc *desc,
  151. irqreturn_t action_ret)
  152. {
  153. if (unlikely(action_ret != IRQ_HANDLED)) {
  154. /*
  155. * If we are seeing only the odd spurious IRQ caused by
  156. * bus asynchronicity then don't eventually trigger an error,
  157. * otherwise the couter becomes a doomsday timer for otherwise
  158. * working systems
  159. */
  160. if (jiffies - desc->last_unhandled > HZ/10)
  161. desc->irqs_unhandled = 1;
  162. else
  163. desc->irqs_unhandled++;
  164. desc->last_unhandled = jiffies;
  165. if (unlikely(action_ret != IRQ_NONE))
  166. report_bad_irq(irq, desc, action_ret);
  167. }
  168. if (unlikely(try_misrouted_irq(irq, desc, action_ret))) {
  169. int ok = misrouted_irq(irq);
  170. if (action_ret == IRQ_NONE)
  171. desc->irqs_unhandled -= ok;
  172. }
  173. desc->irq_count++;
  174. if (likely(desc->irq_count < 100000))
  175. return;
  176. desc->irq_count = 0;
  177. if (unlikely(desc->irqs_unhandled > 99900)) {
  178. /*
  179. * The interrupt is stuck
  180. */
  181. __report_bad_irq(irq, desc, action_ret);
  182. /*
  183. * Now kill the IRQ
  184. */
  185. printk(KERN_EMERG "Disabling IRQ #%d\n", irq);
  186. desc->status |= IRQ_DISABLED;
  187. desc->depth = 1;
  188. desc->chip->disable(irq);
  189. }
  190. desc->irqs_unhandled = 0;
  191. }
  192. int noirqdebug __read_mostly;
  193. int noirqdebug_setup(char *str)
  194. {
  195. noirqdebug = 1;
  196. printk(KERN_INFO "IRQ lockup detection disabled\n");
  197. return 1;
  198. }
  199. __setup("noirqdebug", noirqdebug_setup);
  200. static int __init irqfixup_setup(char *str)
  201. {
  202. irqfixup = 1;
  203. printk(KERN_WARNING "Misrouted IRQ fixup support enabled.\n");
  204. printk(KERN_WARNING "This may impact system performance.\n");
  205. return 1;
  206. }
  207. __setup("irqfixup", irqfixup_setup);
  208. static int __init irqpoll_setup(char *str)
  209. {
  210. irqfixup = 2;
  211. printk(KERN_WARNING "Misrouted IRQ fixup and polling support "
  212. "enabled\n");
  213. printk(KERN_WARNING "This may significantly impact system "
  214. "performance\n");
  215. return 1;
  216. }
  217. __setup("irqpoll", irqpoll_setup);