spurious.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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/jiffies.h>
  9. #include <linux/irq.h>
  10. #include <linux/module.h>
  11. #include <linux/kallsyms.h>
  12. #include <linux/interrupt.h>
  13. #include <linux/moduleparam.h>
  14. static int irqfixup __read_mostly;
  15. /*
  16. * Recovery handler for misrouted interrupts.
  17. */
  18. static int misrouted_irq(int irq)
  19. {
  20. int i;
  21. int ok = 0;
  22. int work = 0; /* Did we do work for a real IRQ */
  23. for (i = 1; i < NR_IRQS; i++) {
  24. struct irq_desc *desc = irq_desc + i;
  25. struct irqaction *action;
  26. if (i == irq) /* Already tried */
  27. continue;
  28. spin_lock(&desc->lock);
  29. /* Already running on another processor */
  30. if (desc->status & IRQ_INPROGRESS) {
  31. /*
  32. * Already running: If it is shared get the other
  33. * CPU to go looking for our mystery interrupt too
  34. */
  35. if (desc->action && (desc->action->flags & IRQF_SHARED))
  36. desc->status |= IRQ_PENDING;
  37. spin_unlock(&desc->lock);
  38. continue;
  39. }
  40. /* Honour the normal IRQ locking */
  41. desc->status |= IRQ_INPROGRESS;
  42. action = desc->action;
  43. spin_unlock(&desc->lock);
  44. while (action) {
  45. /* Only shared IRQ handlers are safe to call */
  46. if (action->flags & IRQF_SHARED) {
  47. if (action->handler(i, action->dev_id) ==
  48. IRQ_HANDLED)
  49. ok = 1;
  50. }
  51. action = action->next;
  52. }
  53. local_irq_disable();
  54. /* Now clean up the flags */
  55. spin_lock(&desc->lock);
  56. action = desc->action;
  57. /*
  58. * While we were looking for a fixup someone queued a real
  59. * IRQ clashing with our walk:
  60. */
  61. while ((desc->status & IRQ_PENDING) && action) {
  62. /*
  63. * Perform real IRQ processing for the IRQ we deferred
  64. */
  65. work = 1;
  66. spin_unlock(&desc->lock);
  67. handle_IRQ_event(i, action);
  68. spin_lock(&desc->lock);
  69. desc->status &= ~IRQ_PENDING;
  70. }
  71. desc->status &= ~IRQ_INPROGRESS;
  72. /*
  73. * If we did actual work for the real IRQ line we must let the
  74. * IRQ controller clean up too
  75. */
  76. if (work && desc->chip && desc->chip->end)
  77. desc->chip->end(i);
  78. spin_unlock(&desc->lock);
  79. }
  80. /* So the caller can adjust the irq error counts */
  81. return ok;
  82. }
  83. /*
  84. * If 99,900 of the previous 100,000 interrupts have not been handled
  85. * then assume that the IRQ is stuck in some manner. Drop a diagnostic
  86. * and try to turn the IRQ off.
  87. *
  88. * (The other 100-of-100,000 interrupts may have been a correctly
  89. * functioning device sharing an IRQ with the failing one)
  90. *
  91. * Called under desc->lock
  92. */
  93. static void
  94. __report_bad_irq(unsigned int irq, struct irq_desc *desc,
  95. irqreturn_t action_ret)
  96. {
  97. struct irqaction *action;
  98. if (action_ret != IRQ_HANDLED && action_ret != IRQ_NONE) {
  99. printk(KERN_ERR "irq event %d: bogus return value %x\n",
  100. irq, action_ret);
  101. } else {
  102. printk(KERN_ERR "irq %d: nobody cared (try booting with "
  103. "the \"irqpoll\" option)\n", irq);
  104. }
  105. dump_stack();
  106. printk(KERN_ERR "handlers:\n");
  107. action = desc->action;
  108. while (action) {
  109. printk(KERN_ERR "[<%p>]", action->handler);
  110. print_symbol(" (%s)",
  111. (unsigned long)action->handler);
  112. printk("\n");
  113. action = action->next;
  114. }
  115. }
  116. static void
  117. report_bad_irq(unsigned int irq, struct irq_desc *desc, irqreturn_t action_ret)
  118. {
  119. static int count = 100;
  120. if (count > 0) {
  121. count--;
  122. __report_bad_irq(irq, desc, action_ret);
  123. }
  124. }
  125. static inline int try_misrouted_irq(unsigned int irq, struct irq_desc *desc, irqreturn_t action_ret)
  126. {
  127. struct irqaction *action;
  128. if (!irqfixup)
  129. return 0;
  130. /* We didn't actually handle the IRQ - see if it was misrouted? */
  131. if (action_ret == IRQ_NONE)
  132. return 1;
  133. /*
  134. * But for 'irqfixup == 2' we also do it for handled interrupts if
  135. * they are marked as IRQF_IRQPOLL (or for irq zero, which is the
  136. * traditional PC timer interrupt.. Legacy)
  137. */
  138. if (irqfixup < 2)
  139. return 0;
  140. if (!irq)
  141. return 1;
  142. /*
  143. * Since we don't get the descriptor lock, "action" can
  144. * change under us. We don't really care, but we don't
  145. * want to follow a NULL pointer. So tell the compiler to
  146. * just load it once by using a barrier.
  147. */
  148. action = desc->action;
  149. barrier();
  150. return action && (action->flags & IRQF_IRQPOLL);
  151. }
  152. void note_interrupt(unsigned int irq, struct irq_desc *desc,
  153. irqreturn_t action_ret)
  154. {
  155. if (unlikely(action_ret != IRQ_HANDLED)) {
  156. /*
  157. * If we are seeing only the odd spurious IRQ caused by
  158. * bus asynchronicity then don't eventually trigger an error,
  159. * otherwise the couter becomes a doomsday timer for otherwise
  160. * working systems
  161. */
  162. if (time_after(jiffies, desc->last_unhandled + HZ/10))
  163. desc->irqs_unhandled = 1;
  164. else
  165. desc->irqs_unhandled++;
  166. desc->last_unhandled = jiffies;
  167. if (unlikely(action_ret != IRQ_NONE))
  168. report_bad_irq(irq, desc, action_ret);
  169. }
  170. if (unlikely(try_misrouted_irq(irq, desc, action_ret))) {
  171. int ok = misrouted_irq(irq);
  172. if (action_ret == IRQ_NONE)
  173. desc->irqs_unhandled -= ok;
  174. }
  175. desc->irq_count++;
  176. if (likely(desc->irq_count < 100000))
  177. return;
  178. desc->irq_count = 0;
  179. if (unlikely(desc->irqs_unhandled > 99900)) {
  180. /*
  181. * The interrupt is stuck
  182. */
  183. __report_bad_irq(irq, desc, action_ret);
  184. /*
  185. * Now kill the IRQ
  186. */
  187. printk(KERN_EMERG "Disabling IRQ #%d\n", irq);
  188. desc->status |= IRQ_DISABLED | IRQ_SPURIOUS_DISABLED;
  189. desc->depth++;
  190. desc->chip->disable(irq);
  191. }
  192. desc->irqs_unhandled = 0;
  193. }
  194. int noirqdebug __read_mostly;
  195. int noirqdebug_setup(char *str)
  196. {
  197. noirqdebug = 1;
  198. printk(KERN_INFO "IRQ lockup detection disabled\n");
  199. return 1;
  200. }
  201. __setup("noirqdebug", noirqdebug_setup);
  202. module_param(noirqdebug, bool, 0644);
  203. MODULE_PARM_DESC(noirqdebug, "Disable irq lockup detection when true");
  204. static int __init irqfixup_setup(char *str)
  205. {
  206. irqfixup = 1;
  207. printk(KERN_WARNING "Misrouted IRQ fixup support enabled.\n");
  208. printk(KERN_WARNING "This may impact system performance.\n");
  209. return 1;
  210. }
  211. __setup("irqfixup", irqfixup_setup);
  212. module_param(irqfixup, int, 0644);
  213. MODULE_PARM_DESC("irqfixup", "0: No fixup, 1: irqfixup mode 2: irqpoll mode");
  214. static int __init irqpoll_setup(char *str)
  215. {
  216. irqfixup = 2;
  217. printk(KERN_WARNING "Misrouted IRQ fixup and polling support "
  218. "enabled\n");
  219. printk(KERN_WARNING "This may significantly impact system "
  220. "performance\n");
  221. return 1;
  222. }
  223. __setup("irqpoll", irqpoll_setup);