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;
30 int work = 0; /* Did we do work for a real IRQ */
32 spin_lock(&desc->lock);
33 /* Already running on another processor */
34 if (desc->status & IRQ_INPROGRESS) {
36 * Already running: If it is shared get the other
37 * CPU to go looking for our mystery interrupt too
39 if (desc->action && (desc->action->flags & IRQF_SHARED))
40 desc->status |= IRQ_PENDING;
41 spin_unlock(&desc->lock);
44 /* Honour the normal IRQ locking */
45 desc->status |= IRQ_INPROGRESS;
46 action = desc->action;
47 spin_unlock(&desc->lock);
50 /* Only shared IRQ handlers are safe to call */
51 if (action->flags & IRQF_SHARED) {
52 if (action->handler(irq, action->dev_id) ==
56 action = action->next;
59 /* Now clean up the flags */
60 spin_lock(&desc->lock);
61 action = desc->action;
64 * While we were looking for a fixup someone queued a real
65 * IRQ clashing with our walk:
67 while ((desc->status & IRQ_PENDING) && action) {
69 * Perform real IRQ processing for the IRQ we deferred
72 spin_unlock(&desc->lock);
73 handle_IRQ_event(irq, action);
74 spin_lock(&desc->lock);
75 desc->status &= ~IRQ_PENDING;
77 desc->status &= ~IRQ_INPROGRESS;
79 * If we did actual work for the real IRQ line we must let the
80 * IRQ controller clean up too
82 if (work && desc->chip && desc->chip->end)
84 spin_unlock(&desc->lock);
89 static int misrouted_irq(int irq)
94 for (i = 1; i < NR_IRQS; i++) {
95 struct irq_desc *desc = irq_desc + i;
97 if (i == irq) /* Already tried */
100 if (try_one_irq(i, desc))
103 /* So the caller can adjust the irq error counts */
107 static void poll_spurious_irqs(unsigned long dummy)
110 for (i = 1; i < NR_IRQS; i++) {
111 struct irq_desc *desc = irq_desc + i;
114 /* Racy but it doesn't matter */
115 status = desc->status;
117 if (!(status & IRQ_SPURIOUS_DISABLED))
120 try_one_irq(i, desc);
123 mod_timer(&poll_spurious_irq_timer, jiffies + POLL_SPURIOUS_IRQ_INTERVAL);
127 * If 99,900 of the previous 100,000 interrupts have not been handled
128 * then assume that the IRQ is stuck in some manner. Drop a diagnostic
129 * and try to turn the IRQ off.
131 * (The other 100-of-100,000 interrupts may have been a correctly
132 * functioning device sharing an IRQ with the failing one)
134 * Called under desc->lock
138 __report_bad_irq(unsigned int irq, struct irq_desc *desc,
139 irqreturn_t action_ret)
141 struct irqaction *action;
143 if (action_ret != IRQ_HANDLED && action_ret != IRQ_NONE) {
144 printk(KERN_ERR "irq event %d: bogus return value %x\n",
147 printk(KERN_ERR "irq %d: nobody cared (try booting with "
148 "the \"irqpoll\" option)\n", irq);
151 printk(KERN_ERR "handlers:\n");
153 action = desc->action;
155 printk(KERN_ERR "[<%p>]", action->handler);
156 print_symbol(" (%s)",
157 (unsigned long)action->handler);
159 action = action->next;
164 report_bad_irq(unsigned int irq, struct irq_desc *desc, irqreturn_t action_ret)
166 static int count = 100;
170 __report_bad_irq(irq, desc, action_ret);
174 static inline int try_misrouted_irq(unsigned int irq, struct irq_desc *desc, irqreturn_t action_ret)
176 struct irqaction *action;
181 /* We didn't actually handle the IRQ - see if it was misrouted? */
182 if (action_ret == IRQ_NONE)
186 * But for 'irqfixup == 2' we also do it for handled interrupts if
187 * they are marked as IRQF_IRQPOLL (or for irq zero, which is the
188 * traditional PC timer interrupt.. Legacy)
197 * Since we don't get the descriptor lock, "action" can
198 * change under us. We don't really care, but we don't
199 * want to follow a NULL pointer. So tell the compiler to
200 * just load it once by using a barrier.
202 action = desc->action;
204 return action && (action->flags & IRQF_IRQPOLL);
207 void note_interrupt(unsigned int irq, struct irq_desc *desc,
208 irqreturn_t action_ret)
210 if (unlikely(action_ret != IRQ_HANDLED)) {
212 * If we are seeing only the odd spurious IRQ caused by
213 * bus asynchronicity then don't eventually trigger an error,
214 * otherwise the couter becomes a doomsday timer for otherwise
217 if (time_after(jiffies, desc->last_unhandled + HZ/10))
218 desc->irqs_unhandled = 1;
220 desc->irqs_unhandled++;
221 desc->last_unhandled = jiffies;
222 if (unlikely(action_ret != IRQ_NONE))
223 report_bad_irq(irq, desc, action_ret);
226 if (unlikely(try_misrouted_irq(irq, desc, action_ret))) {
227 int ok = misrouted_irq(irq);
228 if (action_ret == IRQ_NONE)
229 desc->irqs_unhandled -= ok;
233 if (likely(desc->irq_count < 100000))
237 if (unlikely(desc->irqs_unhandled > 99900)) {
239 * The interrupt is stuck
241 __report_bad_irq(irq, desc, action_ret);
245 printk(KERN_EMERG "Disabling IRQ #%d\n", irq);
246 desc->status |= IRQ_DISABLED | IRQ_SPURIOUS_DISABLED;
248 desc->chip->disable(irq);
250 mod_timer(&poll_spurious_irq_timer, jiffies + POLL_SPURIOUS_IRQ_INTERVAL);
252 desc->irqs_unhandled = 0;
255 int noirqdebug __read_mostly;
257 int noirqdebug_setup(char *str)
260 printk(KERN_INFO "IRQ lockup detection disabled\n");
265 __setup("noirqdebug", noirqdebug_setup);
266 module_param(noirqdebug, bool, 0644);
267 MODULE_PARM_DESC(noirqdebug, "Disable irq lockup detection when true");
269 static int __init irqfixup_setup(char *str)
272 printk(KERN_WARNING "Misrouted IRQ fixup support enabled.\n");
273 printk(KERN_WARNING "This may impact system performance.\n");
278 __setup("irqfixup", irqfixup_setup);
279 module_param(irqfixup, int, 0644);
280 MODULE_PARM_DESC("irqfixup", "0: No fixup, 1: irqfixup mode 2: irqpoll mode");
282 static int __init irqpoll_setup(char *str)
285 printk(KERN_WARNING "Misrouted IRQ fixup and polling support "
287 printk(KERN_WARNING "This may significantly impact system "
292 __setup("irqpoll", irqpoll_setup);