2 * linux/kernel/irq/spurious.c
4 * Copyright (C) 1992, 1998-2004 Linus Torvalds, Ingo Molnar
6 * This file contains spurious interrupt handling.
9 #include <linux/jiffies.h>
10 #include <linux/irq.h>
11 #include <linux/module.h>
12 #include <linux/kallsyms.h>
13 #include <linux/interrupt.h>
14 #include <linux/moduleparam.h>
15 #include <linux/timer.h>
17 static int irqfixup __read_mostly;
19 #define POLL_SPURIOUS_IRQ_INTERVAL (HZ/10)
20 static void poll_spurious_irqs(unsigned long dummy);
21 static DEFINE_TIMER(poll_spurious_irq_timer, poll_spurious_irqs, 0, 0);
24 * Recovery handler for misrouted interrupts.
26 static int try_one_irq(int irq, struct irq_desc *desc)
28 struct irqaction *action;
31 spin_lock(&desc->lock);
32 /* Already running on another processor */
33 if (desc->status & IRQ_INPROGRESS) {
35 * Already running: If it is shared get the other
36 * CPU to go looking for our mystery interrupt too
38 if (desc->action && (desc->action->flags & IRQF_SHARED))
39 desc->status |= IRQ_PENDING;
40 spin_unlock(&desc->lock);
43 /* Honour the normal IRQ locking */
44 desc->status |= IRQ_INPROGRESS;
45 action = desc->action;
46 spin_unlock(&desc->lock);
49 /* Only shared IRQ handlers are safe to call */
50 if (action->flags & IRQF_SHARED) {
51 if (action->handler(irq, action->dev_id) ==
55 action = action->next;
58 /* Now clean up the flags */
59 spin_lock(&desc->lock);
60 action = desc->action;
63 * While we were looking for a fixup someone queued a real
64 * IRQ clashing with our walk:
66 while ((desc->status & IRQ_PENDING) && action) {
68 * Perform real IRQ processing for the IRQ we deferred
71 spin_unlock(&desc->lock);
72 handle_IRQ_event(irq, action);
73 spin_lock(&desc->lock);
74 desc->status &= ~IRQ_PENDING;
76 desc->status &= ~IRQ_INPROGRESS;
78 * If we did actual work for the real IRQ line we must let the
79 * IRQ controller clean up too
81 if (work && desc->chip && desc->chip->end)
83 spin_unlock(&desc->lock);
88 static int misrouted_irq(int irq)
90 struct irq_desc *desc;
93 for_each_irq_desc(i, desc) {
100 if (i == irq) /* Already tried */
103 if (try_one_irq(i, desc))
106 /* So the caller can adjust the irq error counts */
110 static void poll_spurious_irqs(unsigned long dummy)
112 struct irq_desc *desc;
115 for_each_irq_desc(i, desc) {
123 /* Racy but it doesn't matter */
124 status = desc->status;
126 if (!(status & IRQ_SPURIOUS_DISABLED))
129 try_one_irq(i, desc);
132 mod_timer(&poll_spurious_irq_timer,
133 jiffies + POLL_SPURIOUS_IRQ_INTERVAL);
137 * If 99,900 of the previous 100,000 interrupts have not been handled
138 * then assume that the IRQ is stuck in some manner. Drop a diagnostic
139 * and try to turn the IRQ off.
141 * (The other 100-of-100,000 interrupts may have been a correctly
142 * functioning device sharing an IRQ with the failing one)
144 * Called under desc->lock
148 __report_bad_irq(unsigned int irq, struct irq_desc *desc,
149 irqreturn_t action_ret)
151 struct irqaction *action;
153 if (action_ret != IRQ_HANDLED && action_ret != IRQ_NONE) {
154 printk(KERN_ERR "irq event %d: bogus return value %x\n",
157 printk(KERN_ERR "irq %d: nobody cared (try booting with "
158 "the \"irqpoll\" option)\n", irq);
161 printk(KERN_ERR "handlers:\n");
163 action = desc->action;
165 printk(KERN_ERR "[<%p>]", action->handler);
166 print_symbol(" (%s)",
167 (unsigned long)action->handler);
169 action = action->next;
174 report_bad_irq(unsigned int irq, struct irq_desc *desc, irqreturn_t action_ret)
176 static int count = 100;
180 __report_bad_irq(irq, desc, action_ret);
185 try_misrouted_irq(unsigned int irq, struct irq_desc *desc,
186 irqreturn_t action_ret)
188 struct irqaction *action;
193 /* We didn't actually handle the IRQ - see if it was misrouted? */
194 if (action_ret == IRQ_NONE)
198 * But for 'irqfixup == 2' we also do it for handled interrupts if
199 * they are marked as IRQF_IRQPOLL (or for irq zero, which is the
200 * traditional PC timer interrupt.. Legacy)
209 * Since we don't get the descriptor lock, "action" can
210 * change under us. We don't really care, but we don't
211 * want to follow a NULL pointer. So tell the compiler to
212 * just load it once by using a barrier.
214 action = desc->action;
216 return action && (action->flags & IRQF_IRQPOLL);
219 void note_interrupt(unsigned int irq, struct irq_desc *desc,
220 irqreturn_t action_ret)
222 if (unlikely(action_ret != IRQ_HANDLED)) {
224 * If we are seeing only the odd spurious IRQ caused by
225 * bus asynchronicity then don't eventually trigger an error,
226 * otherwise the couter becomes a doomsday timer for otherwise
229 if (time_after(jiffies, desc->last_unhandled + HZ/10))
230 desc->irqs_unhandled = 1;
232 desc->irqs_unhandled++;
233 desc->last_unhandled = jiffies;
234 if (unlikely(action_ret != IRQ_NONE))
235 report_bad_irq(irq, desc, action_ret);
238 if (unlikely(try_misrouted_irq(irq, desc, action_ret))) {
239 int ok = misrouted_irq(irq);
240 if (action_ret == IRQ_NONE)
241 desc->irqs_unhandled -= ok;
245 if (likely(desc->irq_count < 100000))
249 if (unlikely(desc->irqs_unhandled > 99900)) {
251 * The interrupt is stuck
253 __report_bad_irq(irq, desc, action_ret);
257 printk(KERN_EMERG "Disabling IRQ #%d\n", irq);
258 desc->status |= IRQ_DISABLED | IRQ_SPURIOUS_DISABLED;
260 desc->chip->disable(irq);
262 mod_timer(&poll_spurious_irq_timer,
263 jiffies + POLL_SPURIOUS_IRQ_INTERVAL);
265 desc->irqs_unhandled = 0;
268 int noirqdebug __read_mostly;
270 int noirqdebug_setup(char *str)
273 printk(KERN_INFO "IRQ lockup detection disabled\n");
278 __setup("noirqdebug", noirqdebug_setup);
279 module_param(noirqdebug, bool, 0644);
280 MODULE_PARM_DESC(noirqdebug, "Disable irq lockup detection when true");
282 static int __init irqfixup_setup(char *str)
285 printk(KERN_WARNING "Misrouted IRQ fixup support enabled.\n");
286 printk(KERN_WARNING "This may impact system performance.\n");
291 __setup("irqfixup", irqfixup_setup);
292 module_param(irqfixup, int, 0644);
293 MODULE_PARM_DESC("irqfixup", "0: No fixup, 1: irqfixup mode, 2: irqpoll mode");
295 static int __init irqpoll_setup(char *str)
298 printk(KERN_WARNING "Misrouted IRQ fixup and polling support "
300 printk(KERN_WARNING "This may significantly impact system "
305 __setup("irqpoll", irqpoll_setup);