2 * linux/kernel/irq/spurious.c
4 * Copyright (C) 1992, 1998-2004 Linus Torvalds, Ingo Molnar
6 * This file contains spurious interrupt handling.
10 #include <linux/module.h>
11 #include <linux/kallsyms.h>
12 #include <linux/interrupt.h>
13 #include <linux/moduleparam.h>
15 static int irqfixup __read_mostly;
18 * Recovery handler for misrouted interrupts.
20 static int misrouted_irq(int irq)
24 int work = 0; /* Did we do work for a real IRQ */
26 for (i = 1; i < NR_IRQS; i++) {
27 struct irq_desc *desc = irq_desc + i;
28 struct irqaction *action;
30 if (i == irq) /* Already tried */
33 spin_lock(&desc->lock);
34 /* Already running on another processor */
35 if (desc->status & IRQ_INPROGRESS) {
37 * Already running: If it is shared get the other
38 * CPU to go looking for our mystery interrupt too
40 if (desc->action && (desc->action->flags & IRQF_SHARED))
41 desc->status |= IRQ_PENDING;
42 spin_unlock(&desc->lock);
45 /* Honour the normal IRQ locking */
46 desc->status |= IRQ_INPROGRESS;
47 action = desc->action;
48 spin_unlock(&desc->lock);
51 /* Only shared IRQ handlers are safe to call */
52 if (action->flags & IRQF_SHARED) {
53 if (action->handler(i, action->dev_id) ==
57 action = action->next;
60 /* Now clean up the flags */
61 spin_lock(&desc->lock);
62 action = desc->action;
65 * While we were looking for a fixup someone queued a real
66 * IRQ clashing with our walk:
68 while ((desc->status & IRQ_PENDING) && action) {
70 * Perform real IRQ processing for the IRQ we deferred
73 spin_unlock(&desc->lock);
74 handle_IRQ_event(i, action);
75 spin_lock(&desc->lock);
76 desc->status &= ~IRQ_PENDING;
78 desc->status &= ~IRQ_INPROGRESS;
80 * If we did actual work for the real IRQ line we must let the
81 * IRQ controller clean up too
83 if (work && desc->chip && desc->chip->end)
85 spin_unlock(&desc->lock);
87 /* So the caller can adjust the irq error counts */
92 * If 99,900 of the previous 100,000 interrupts have not been handled
93 * then assume that the IRQ is stuck in some manner. Drop a diagnostic
94 * and try to turn the IRQ off.
96 * (The other 100-of-100,000 interrupts may have been a correctly
97 * functioning device sharing an IRQ with the failing one)
99 * Called under desc->lock
103 __report_bad_irq(unsigned int irq, struct irq_desc *desc,
104 irqreturn_t action_ret)
106 struct irqaction *action;
108 if (action_ret != IRQ_HANDLED && action_ret != IRQ_NONE) {
109 printk(KERN_ERR "irq event %d: bogus return value %x\n",
112 printk(KERN_ERR "irq %d: nobody cared (try booting with "
113 "the \"irqpoll\" option)\n", irq);
116 printk(KERN_ERR "handlers:\n");
118 action = desc->action;
120 printk(KERN_ERR "[<%p>]", action->handler);
121 print_symbol(" (%s)",
122 (unsigned long)action->handler);
124 action = action->next;
129 report_bad_irq(unsigned int irq, struct irq_desc *desc, irqreturn_t action_ret)
131 static int count = 100;
135 __report_bad_irq(irq, desc, action_ret);
139 static inline int try_misrouted_irq(unsigned int irq, struct irq_desc *desc, irqreturn_t action_ret)
141 struct irqaction *action;
146 /* We didn't actually handle the IRQ - see if it was misrouted? */
147 if (action_ret == IRQ_NONE)
151 * But for 'irqfixup == 2' we also do it for handled interrupts if
152 * they are marked as IRQF_IRQPOLL (or for irq zero, which is the
153 * traditional PC timer interrupt.. Legacy)
162 * Since we don't get the descriptor lock, "action" can
163 * change under us. We don't really care, but we don't
164 * want to follow a NULL pointer. So tell the compiler to
165 * just load it once by using a barrier.
167 action = desc->action;
169 return action && (action->flags & IRQF_IRQPOLL);
172 void note_interrupt(unsigned int irq, struct irq_desc *desc,
173 irqreturn_t action_ret)
175 if (unlikely(action_ret != IRQ_HANDLED)) {
177 * If we are seeing only the odd spurious IRQ caused by
178 * bus asynchronicity then don't eventually trigger an error,
179 * otherwise the couter becomes a doomsday timer for otherwise
182 if (jiffies - desc->last_unhandled > HZ/10)
183 desc->irqs_unhandled = 1;
185 desc->irqs_unhandled++;
186 desc->last_unhandled = jiffies;
187 if (unlikely(action_ret != IRQ_NONE))
188 report_bad_irq(irq, desc, action_ret);
191 if (unlikely(try_misrouted_irq(irq, desc, action_ret))) {
192 int ok = misrouted_irq(irq);
193 if (action_ret == IRQ_NONE)
194 desc->irqs_unhandled -= ok;
198 if (likely(desc->irq_count < 100000))
202 if (unlikely(desc->irqs_unhandled > 99900)) {
204 * The interrupt is stuck
206 __report_bad_irq(irq, desc, action_ret);
210 printk(KERN_EMERG "Disabling IRQ #%d\n", irq);
211 desc->status |= IRQ_DISABLED;
213 desc->chip->disable(irq);
215 desc->irqs_unhandled = 0;
218 int noirqdebug __read_mostly;
220 int noirqdebug_setup(char *str)
223 printk(KERN_INFO "IRQ lockup detection disabled\n");
228 __setup("noirqdebug", noirqdebug_setup);
229 module_param(noirqdebug, bool, 0644);
230 MODULE_PARM_DESC(noirqdebug, "Disable irq lockup detection when true");
232 static int __init irqfixup_setup(char *str)
235 printk(KERN_WARNING "Misrouted IRQ fixup support enabled.\n");
236 printk(KERN_WARNING "This may impact system performance.\n");
241 __setup("irqfixup", irqfixup_setup);
242 module_param(irqfixup, int, 0644);
243 MODULE_PARM_DESC("irqfixup", "0: No fixup, 1: irqfixup mode 2: irqpoll mode");
245 static int __init irqpoll_setup(char *str)
248 printk(KERN_WARNING "Misrouted IRQ fixup and polling support "
250 printk(KERN_WARNING "This may significantly impact system "
255 __setup("irqpoll", irqpoll_setup);