spurious.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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;
  13. /*
  14. * Recovery handler for misrouted interrupts.
  15. */
  16. static int misrouted_irq(int irq, struct pt_regs *regs)
  17. {
  18. int i;
  19. irq_desc_t *desc;
  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 irqaction *action;
  24. if (i == irq) /* Already tried */
  25. continue;
  26. desc = &irq_desc[i];
  27. spin_lock(&desc->lock);
  28. action = desc->action;
  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 & SA_SHIRQ))
  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. spin_unlock(&desc->lock);
  43. while (action) {
  44. /* Only shared IRQ handlers are safe to call */
  45. if (action->flags & SA_SHIRQ) {
  46. if (action->handler(i, action->dev_id, regs) ==
  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, regs, 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)
  76. desc->handler->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, irq_desc_t *desc, 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 report_bad_irq(unsigned int irq, irq_desc_t *desc, irqreturn_t action_ret)
  115. {
  116. static int count = 100;
  117. if (count > 0) {
  118. count--;
  119. __report_bad_irq(irq, desc, action_ret);
  120. }
  121. }
  122. void note_interrupt(unsigned int irq, irq_desc_t *desc, irqreturn_t action_ret,
  123. struct pt_regs *regs)
  124. {
  125. if (action_ret != IRQ_HANDLED) {
  126. desc->irqs_unhandled++;
  127. if (action_ret != IRQ_NONE)
  128. report_bad_irq(irq, desc, action_ret);
  129. }
  130. if (unlikely(irqfixup)) {
  131. /* Don't punish working computers */
  132. if ((irqfixup == 2 && irq == 0) || action_ret == IRQ_NONE) {
  133. int ok = misrouted_irq(irq, regs);
  134. if (action_ret == IRQ_NONE)
  135. desc->irqs_unhandled -= ok;
  136. }
  137. }
  138. desc->irq_count++;
  139. if (desc->irq_count < 100000)
  140. return;
  141. desc->irq_count = 0;
  142. if (desc->irqs_unhandled > 99900) {
  143. /*
  144. * The interrupt is stuck
  145. */
  146. __report_bad_irq(irq, desc, action_ret);
  147. /*
  148. * Now kill the IRQ
  149. */
  150. printk(KERN_EMERG "Disabling IRQ #%d\n", irq);
  151. desc->status |= IRQ_DISABLED;
  152. desc->handler->disable(irq);
  153. }
  154. desc->irqs_unhandled = 0;
  155. }
  156. int noirqdebug;
  157. int __init noirqdebug_setup(char *str)
  158. {
  159. noirqdebug = 1;
  160. printk(KERN_INFO "IRQ lockup detection disabled\n");
  161. return 1;
  162. }
  163. __setup("noirqdebug", noirqdebug_setup);
  164. static int __init irqfixup_setup(char *str)
  165. {
  166. irqfixup = 1;
  167. printk(KERN_WARNING "Misrouted IRQ fixup support enabled.\n");
  168. printk(KERN_WARNING "This may impact system performance.\n");
  169. return 1;
  170. }
  171. __setup("irqfixup", irqfixup_setup);
  172. static int __init irqpoll_setup(char *str)
  173. {
  174. irqfixup = 2;
  175. printk(KERN_WARNING "Misrouted IRQ fixup and polling support "
  176. "enabled\n");
  177. printk(KERN_WARNING "This may significantly impact system "
  178. "performance\n");
  179. return 1;
  180. }
  181. __setup("irqpoll", irqpoll_setup);