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 #include "internals.h"
19 static int irqfixup __read_mostly;
21 #define POLL_SPURIOUS_IRQ_INTERVAL (HZ/10)
22 static void poll_spurious_irqs(unsigned long dummy);
23 static DEFINE_TIMER(poll_spurious_irq_timer, poll_spurious_irqs, 0, 0);
26 * Recovery handler for misrouted interrupts.
28 static int try_one_irq(int irq, struct irq_desc *desc)
30 struct irqaction *action;
33 raw_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 raw_spin_unlock(&desc->lock);
45 /* Honour the normal IRQ locking */
46 desc->status |= IRQ_INPROGRESS;
47 action = desc->action;
48 raw_spin_unlock(&desc->lock);
51 /* Only shared IRQ handlers are safe to call */
52 if (action->flags & IRQF_SHARED) {
53 if (action->handler(irq, action->dev_id) ==
57 action = action->next;
60 /* Now clean up the flags */
61 raw_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 raw_spin_unlock(&desc->lock);
74 handle_IRQ_event(irq, action);
75 raw_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
85 raw_spin_unlock(&desc->lock);
90 static int misrouted_irq(int irq)
92 struct irq_desc *desc;
95 for_each_irq_desc(i, desc) {
99 if (i == irq) /* Already tried */
102 if (try_one_irq(i, desc))
105 /* So the caller can adjust the irq error counts */
109 static void poll_spurious_irqs(unsigned long dummy)
111 struct irq_desc *desc;
114 for_each_irq_desc(i, desc) {
120 /* Racy but it doesn't matter */
121 status = desc->status;
123 if (!(status & IRQ_SPURIOUS_DISABLED))
127 try_one_irq(i, desc);
131 mod_timer(&poll_spurious_irq_timer,
132 jiffies + POLL_SPURIOUS_IRQ_INTERVAL);
136 * If 99,900 of the previous 100,000 interrupts have not been handled
137 * then assume that the IRQ is stuck in some manner. Drop a diagnostic
138 * and try to turn the IRQ off.
140 * (The other 100-of-100,000 interrupts may have been a correctly
141 * functioning device sharing an IRQ with the failing one)
143 * Called under desc->lock
147 __report_bad_irq(unsigned int irq, struct irq_desc *desc,
148 irqreturn_t action_ret)
150 struct irqaction *action;
152 if (action_ret != IRQ_HANDLED && action_ret != IRQ_NONE) {
153 printk(KERN_ERR "irq event %d: bogus return value %x\n",
156 printk(KERN_ERR "irq %d: nobody cared (try booting with "
157 "the \"irqpoll\" option)\n", irq);
160 printk(KERN_ERR "handlers:\n");
162 action = desc->action;
164 printk(KERN_ERR "[<%p>]", action->handler);
165 print_symbol(" (%s)",
166 (unsigned long)action->handler);
168 action = action->next;
173 report_bad_irq(unsigned int irq, struct irq_desc *desc, irqreturn_t action_ret)
175 static int count = 100;
179 __report_bad_irq(irq, desc, action_ret);
184 try_misrouted_irq(unsigned int irq, struct irq_desc *desc,
185 irqreturn_t action_ret)
187 struct irqaction *action;
192 /* We didn't actually handle the IRQ - see if it was misrouted? */
193 if (action_ret == IRQ_NONE)
197 * But for 'irqfixup == 2' we also do it for handled interrupts if
198 * they are marked as IRQF_IRQPOLL (or for irq zero, which is the
199 * traditional PC timer interrupt.. Legacy)
208 * Since we don't get the descriptor lock, "action" can
209 * change under us. We don't really care, but we don't
210 * want to follow a NULL pointer. So tell the compiler to
211 * just load it once by using a barrier.
213 action = desc->action;
215 return action && (action->flags & IRQF_IRQPOLL);
218 void note_interrupt(unsigned int irq, struct irq_desc *desc,
219 irqreturn_t action_ret)
221 if (unlikely(action_ret != IRQ_HANDLED)) {
223 * If we are seeing only the odd spurious IRQ caused by
224 * bus asynchronicity then don't eventually trigger an error,
225 * otherwise the counter becomes a doomsday timer for otherwise
228 if (time_after(jiffies, desc->last_unhandled + HZ/10))
229 desc->irqs_unhandled = 1;
231 desc->irqs_unhandled++;
232 desc->last_unhandled = jiffies;
233 if (unlikely(action_ret != IRQ_NONE))
234 report_bad_irq(irq, desc, action_ret);
237 if (unlikely(try_misrouted_irq(irq, desc, action_ret))) {
238 int ok = misrouted_irq(irq);
239 if (action_ret == IRQ_NONE)
240 desc->irqs_unhandled -= ok;
244 if (likely(desc->irq_count < 100000))
248 if (unlikely(desc->irqs_unhandled > 99900)) {
250 * The interrupt is stuck
252 __report_bad_irq(irq, desc, action_ret);
256 printk(KERN_EMERG "Disabling IRQ #%d\n", irq);
257 desc->status |= IRQ_DISABLED | IRQ_SPURIOUS_DISABLED;
259 desc->irq_data.chip->irq_disable(&desc->irq_data);
261 mod_timer(&poll_spurious_irq_timer,
262 jiffies + POLL_SPURIOUS_IRQ_INTERVAL);
264 desc->irqs_unhandled = 0;
267 int noirqdebug __read_mostly;
269 int noirqdebug_setup(char *str)
272 printk(KERN_INFO "IRQ lockup detection disabled\n");
277 __setup("noirqdebug", noirqdebug_setup);
278 module_param(noirqdebug, bool, 0644);
279 MODULE_PARM_DESC(noirqdebug, "Disable irq lockup detection when true");
281 static int __init irqfixup_setup(char *str)
284 printk(KERN_WARNING "Misrouted IRQ fixup support enabled.\n");
285 printk(KERN_WARNING "This may impact system performance.\n");
290 __setup("irqfixup", irqfixup_setup);
291 module_param(irqfixup, int, 0644);
293 static int __init irqpoll_setup(char *str)
296 printk(KERN_WARNING "Misrouted IRQ fixup and polling support "
298 printk(KERN_WARNING "This may significantly impact system "
303 __setup("irqpoll", irqpoll_setup);