spurious.c 6.1 KB

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