Merge git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
[wrt350n-kernel.git] / kernel / irq / spurious.c
blobe0eb9808e6154718db0288801e20125189a069d2
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 <<<<<<< HEAD:kernel/irq/spurious.c
10 =======
11 #include <linux/jiffies.h>
12 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:kernel/irq/spurious.c
13 #include <linux/irq.h>
14 #include <linux/module.h>
15 #include <linux/kallsyms.h>
16 #include <linux/interrupt.h>
17 #include <linux/moduleparam.h>
19 static int irqfixup __read_mostly;
22 * Recovery handler for misrouted interrupts.
24 static int misrouted_irq(int irq)
26 int i;
27 int ok = 0;
28 int work = 0; /* Did we do work for a real IRQ */
30 for (i = 1; i < NR_IRQS; i++) {
31 struct irq_desc *desc = irq_desc + i;
32 struct irqaction *action;
34 if (i == irq) /* Already tried */
35 continue;
37 spin_lock(&desc->lock);
38 /* Already running on another processor */
39 if (desc->status & IRQ_INPROGRESS) {
41 * Already running: If it is shared get the other
42 * CPU to go looking for our mystery interrupt too
44 if (desc->action && (desc->action->flags & IRQF_SHARED))
45 desc->status |= IRQ_PENDING;
46 spin_unlock(&desc->lock);
47 continue;
49 /* Honour the normal IRQ locking */
50 desc->status |= IRQ_INPROGRESS;
51 action = desc->action;
52 spin_unlock(&desc->lock);
54 while (action) {
55 /* Only shared IRQ handlers are safe to call */
56 if (action->flags & IRQF_SHARED) {
57 if (action->handler(i, action->dev_id) ==
58 IRQ_HANDLED)
59 ok = 1;
61 action = action->next;
63 local_irq_disable();
64 /* Now clean up the flags */
65 spin_lock(&desc->lock);
66 action = desc->action;
69 * While we were looking for a fixup someone queued a real
70 * IRQ clashing with our walk:
72 while ((desc->status & IRQ_PENDING) && action) {
74 * Perform real IRQ processing for the IRQ we deferred
76 work = 1;
77 spin_unlock(&desc->lock);
78 handle_IRQ_event(i, action);
79 spin_lock(&desc->lock);
80 desc->status &= ~IRQ_PENDING;
82 desc->status &= ~IRQ_INPROGRESS;
84 * If we did actual work for the real IRQ line we must let the
85 * IRQ controller clean up too
87 if (work && desc->chip && desc->chip->end)
88 desc->chip->end(i);
89 spin_unlock(&desc->lock);
91 /* So the caller can adjust the irq error counts */
92 return ok;
96 * If 99,900 of the previous 100,000 interrupts have not been handled
97 * then assume that the IRQ is stuck in some manner. Drop a diagnostic
98 * and try to turn the IRQ off.
100 * (The other 100-of-100,000 interrupts may have been a correctly
101 * functioning device sharing an IRQ with the failing one)
103 * Called under desc->lock
106 static void
107 __report_bad_irq(unsigned int irq, struct irq_desc *desc,
108 irqreturn_t action_ret)
110 struct irqaction *action;
112 if (action_ret != IRQ_HANDLED && action_ret != IRQ_NONE) {
113 printk(KERN_ERR "irq event %d: bogus return value %x\n",
114 irq, action_ret);
115 } else {
116 printk(KERN_ERR "irq %d: nobody cared (try booting with "
117 "the \"irqpoll\" option)\n", irq);
119 dump_stack();
120 printk(KERN_ERR "handlers:\n");
122 action = desc->action;
123 while (action) {
124 printk(KERN_ERR "[<%p>]", action->handler);
125 print_symbol(" (%s)",
126 (unsigned long)action->handler);
127 printk("\n");
128 action = action->next;
132 static void
133 report_bad_irq(unsigned int irq, struct irq_desc *desc, irqreturn_t action_ret)
135 static int count = 100;
137 if (count > 0) {
138 count--;
139 __report_bad_irq(irq, desc, action_ret);
143 static inline int try_misrouted_irq(unsigned int irq, struct irq_desc *desc, irqreturn_t action_ret)
145 struct irqaction *action;
147 if (!irqfixup)
148 return 0;
150 /* We didn't actually handle the IRQ - see if it was misrouted? */
151 if (action_ret == IRQ_NONE)
152 return 1;
155 * But for 'irqfixup == 2' we also do it for handled interrupts if
156 * they are marked as IRQF_IRQPOLL (or for irq zero, which is the
157 * traditional PC timer interrupt.. Legacy)
159 if (irqfixup < 2)
160 return 0;
162 if (!irq)
163 return 1;
166 * Since we don't get the descriptor lock, "action" can
167 * change under us. We don't really care, but we don't
168 * want to follow a NULL pointer. So tell the compiler to
169 * just load it once by using a barrier.
171 action = desc->action;
172 barrier();
173 return action && (action->flags & IRQF_IRQPOLL);
176 void note_interrupt(unsigned int irq, struct irq_desc *desc,
177 irqreturn_t action_ret)
179 if (unlikely(action_ret != IRQ_HANDLED)) {
181 * If we are seeing only the odd spurious IRQ caused by
182 * bus asynchronicity then don't eventually trigger an error,
183 * otherwise the couter becomes a doomsday timer for otherwise
184 * working systems
186 <<<<<<< HEAD:kernel/irq/spurious.c
187 if (jiffies - desc->last_unhandled > HZ/10)
188 =======
189 if (time_after(jiffies, desc->last_unhandled + HZ/10))
190 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:kernel/irq/spurious.c
191 desc->irqs_unhandled = 1;
192 else
193 desc->irqs_unhandled++;
194 desc->last_unhandled = jiffies;
195 if (unlikely(action_ret != IRQ_NONE))
196 report_bad_irq(irq, desc, action_ret);
199 if (unlikely(try_misrouted_irq(irq, desc, action_ret))) {
200 int ok = misrouted_irq(irq);
201 if (action_ret == IRQ_NONE)
202 desc->irqs_unhandled -= ok;
205 desc->irq_count++;
206 if (likely(desc->irq_count < 100000))
207 return;
209 desc->irq_count = 0;
210 if (unlikely(desc->irqs_unhandled > 99900)) {
212 * The interrupt is stuck
214 __report_bad_irq(irq, desc, action_ret);
216 * Now kill the IRQ
218 printk(KERN_EMERG "Disabling IRQ #%d\n", irq);
219 desc->status |= IRQ_DISABLED;
220 desc->depth = 1;
221 desc->chip->disable(irq);
223 desc->irqs_unhandled = 0;
226 int noirqdebug __read_mostly;
228 int noirqdebug_setup(char *str)
230 noirqdebug = 1;
231 printk(KERN_INFO "IRQ lockup detection disabled\n");
233 return 1;
236 __setup("noirqdebug", noirqdebug_setup);
237 module_param(noirqdebug, bool, 0644);
238 MODULE_PARM_DESC(noirqdebug, "Disable irq lockup detection when true");
240 static int __init irqfixup_setup(char *str)
242 irqfixup = 1;
243 printk(KERN_WARNING "Misrouted IRQ fixup support enabled.\n");
244 printk(KERN_WARNING "This may impact system performance.\n");
246 return 1;
249 __setup("irqfixup", irqfixup_setup);
250 module_param(irqfixup, int, 0644);
251 MODULE_PARM_DESC("irqfixup", "0: No fixup, 1: irqfixup mode 2: irqpoll mode");
253 static int __init irqpoll_setup(char *str)
255 irqfixup = 2;
256 printk(KERN_WARNING "Misrouted IRQ fixup and polling support "
257 "enabled\n");
258 printk(KERN_WARNING "This may significantly impact system "
259 "performance\n");
260 return 1;
263 __setup("irqpoll", irqpoll_setup);