Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris...
[linux-2.6/verdex.git] / kernel / irq / spurious.c
blob088dabbf2d6a6cbca786ec80fe0ce6851175fef9
1 /*
2 * linux/kernel/irq/spurious.c
4 * Copyright (C) 1992, 1998-2004 Linus Torvalds, Ingo Molnar
6 * This file contains spurious interrupt handling.
7 */
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>
16 static int irqfixup __read_mostly;
19 * Recovery handler for misrouted interrupts.
21 static int misrouted_irq(int irq)
23 int i;
24 int ok = 0;
25 int work = 0; /* Did we do work for a real IRQ */
27 for (i = 1; i < NR_IRQS; i++) {
28 struct irq_desc *desc = irq_desc + i;
29 struct irqaction *action;
31 if (i == irq) /* Already tried */
32 continue;
34 spin_lock(&desc->lock);
35 /* Already running on another processor */
36 if (desc->status & IRQ_INPROGRESS) {
38 * Already running: If it is shared get the other
39 * CPU to go looking for our mystery interrupt too
41 if (desc->action && (desc->action->flags & IRQF_SHARED))
42 desc->status |= IRQ_PENDING;
43 spin_unlock(&desc->lock);
44 continue;
46 /* Honour the normal IRQ locking */
47 desc->status |= IRQ_INPROGRESS;
48 action = desc->action;
49 spin_unlock(&desc->lock);
51 while (action) {
52 /* Only shared IRQ handlers are safe to call */
53 if (action->flags & IRQF_SHARED) {
54 if (action->handler(i, action->dev_id) ==
55 IRQ_HANDLED)
56 ok = 1;
58 action = action->next;
60 local_irq_disable();
61 /* Now clean up the flags */
62 spin_lock(&desc->lock);
63 action = desc->action;
66 * While we were looking for a fixup someone queued a real
67 * IRQ clashing with our walk:
69 while ((desc->status & IRQ_PENDING) && action) {
71 * Perform real IRQ processing for the IRQ we deferred
73 work = 1;
74 spin_unlock(&desc->lock);
75 handle_IRQ_event(i, action);
76 spin_lock(&desc->lock);
77 desc->status &= ~IRQ_PENDING;
79 desc->status &= ~IRQ_INPROGRESS;
81 * If we did actual work for the real IRQ line we must let the
82 * IRQ controller clean up too
84 if (work && desc->chip && desc->chip->end)
85 desc->chip->end(i);
86 spin_unlock(&desc->lock);
88 /* So the caller can adjust the irq error counts */
89 return ok;
93 * If 99,900 of the previous 100,000 interrupts have not been handled
94 * then assume that the IRQ is stuck in some manner. Drop a diagnostic
95 * and try to turn the IRQ off.
97 * (The other 100-of-100,000 interrupts may have been a correctly
98 * functioning device sharing an IRQ with the failing one)
100 * Called under desc->lock
103 static void
104 __report_bad_irq(unsigned int irq, struct irq_desc *desc,
105 irqreturn_t action_ret)
107 struct irqaction *action;
109 if (action_ret != IRQ_HANDLED && action_ret != IRQ_NONE) {
110 printk(KERN_ERR "irq event %d: bogus return value %x\n",
111 irq, action_ret);
112 } else {
113 printk(KERN_ERR "irq %d: nobody cared (try booting with "
114 "the \"irqpoll\" option)\n", irq);
116 dump_stack();
117 printk(KERN_ERR "handlers:\n");
119 action = desc->action;
120 while (action) {
121 printk(KERN_ERR "[<%p>]", action->handler);
122 print_symbol(" (%s)",
123 (unsigned long)action->handler);
124 printk("\n");
125 action = action->next;
129 static void
130 report_bad_irq(unsigned int irq, struct irq_desc *desc, irqreturn_t action_ret)
132 static int count = 100;
134 if (count > 0) {
135 count--;
136 __report_bad_irq(irq, desc, action_ret);
140 static inline int try_misrouted_irq(unsigned int irq, struct irq_desc *desc, irqreturn_t action_ret)
142 struct irqaction *action;
144 if (!irqfixup)
145 return 0;
147 /* We didn't actually handle the IRQ - see if it was misrouted? */
148 if (action_ret == IRQ_NONE)
149 return 1;
152 * But for 'irqfixup == 2' we also do it for handled interrupts if
153 * they are marked as IRQF_IRQPOLL (or for irq zero, which is the
154 * traditional PC timer interrupt.. Legacy)
156 if (irqfixup < 2)
157 return 0;
159 if (!irq)
160 return 1;
163 * Since we don't get the descriptor lock, "action" can
164 * change under us. We don't really care, but we don't
165 * want to follow a NULL pointer. So tell the compiler to
166 * just load it once by using a barrier.
168 action = desc->action;
169 barrier();
170 return action && (action->flags & IRQF_IRQPOLL);
173 void note_interrupt(unsigned int irq, struct irq_desc *desc,
174 irqreturn_t action_ret)
176 if (unlikely(action_ret != IRQ_HANDLED)) {
178 * If we are seeing only the odd spurious IRQ caused by
179 * bus asynchronicity then don't eventually trigger an error,
180 * otherwise the couter becomes a doomsday timer for otherwise
181 * working systems
183 if (time_after(jiffies, desc->last_unhandled + HZ/10))
184 desc->irqs_unhandled = 1;
185 else
186 desc->irqs_unhandled++;
187 desc->last_unhandled = jiffies;
188 if (unlikely(action_ret != IRQ_NONE))
189 report_bad_irq(irq, desc, action_ret);
192 if (unlikely(try_misrouted_irq(irq, desc, action_ret))) {
193 int ok = misrouted_irq(irq);
194 if (action_ret == IRQ_NONE)
195 desc->irqs_unhandled -= ok;
198 desc->irq_count++;
199 if (likely(desc->irq_count < 100000))
200 return;
202 desc->irq_count = 0;
203 if (unlikely(desc->irqs_unhandled > 99900)) {
205 * The interrupt is stuck
207 __report_bad_irq(irq, desc, action_ret);
209 * Now kill the IRQ
211 printk(KERN_EMERG "Disabling IRQ #%d\n", irq);
212 desc->status |= IRQ_DISABLED;
213 desc->depth = 1;
214 desc->chip->disable(irq);
216 desc->irqs_unhandled = 0;
219 int noirqdebug __read_mostly;
221 int noirqdebug_setup(char *str)
223 noirqdebug = 1;
224 printk(KERN_INFO "IRQ lockup detection disabled\n");
226 return 1;
229 __setup("noirqdebug", noirqdebug_setup);
230 module_param(noirqdebug, bool, 0644);
231 MODULE_PARM_DESC(noirqdebug, "Disable irq lockup detection when true");
233 static int __init irqfixup_setup(char *str)
235 irqfixup = 1;
236 printk(KERN_WARNING "Misrouted IRQ fixup support enabled.\n");
237 printk(KERN_WARNING "This may impact system performance.\n");
239 return 1;
242 __setup("irqfixup", irqfixup_setup);
243 module_param(irqfixup, int, 0644);
244 MODULE_PARM_DESC("irqfixup", "0: No fixup, 1: irqfixup mode 2: irqpoll mode");
246 static int __init irqpoll_setup(char *str)
248 irqfixup = 2;
249 printk(KERN_WARNING "Misrouted IRQ fixup and polling support "
250 "enabled\n");
251 printk(KERN_WARNING "This may significantly impact system "
252 "performance\n");
253 return 1;
256 __setup("irqpoll", irqpoll_setup);