md: set and test the ->persistent flag for md devices more consistently
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / kernel / irq / spurious.c
bloba6b2bc831dd05be5ee9cbff347566bf410870c26
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/irq.h>
10 #include <linux/module.h>
11 #include <linux/kallsyms.h>
12 #include <linux/interrupt.h>
13 #include <linux/moduleparam.h>
15 static int irqfixup __read_mostly;
18 * Recovery handler for misrouted interrupts.
20 static int misrouted_irq(int irq)
22 int i;
23 int ok = 0;
24 int work = 0; /* Did we do work for a real IRQ */
26 for (i = 1; i < NR_IRQS; i++) {
27 struct irq_desc *desc = irq_desc + i;
28 struct irqaction *action;
30 if (i == irq) /* Already tried */
31 continue;
33 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 spin_unlock(&desc->lock);
43 continue;
45 /* Honour the normal IRQ locking */
46 desc->status |= IRQ_INPROGRESS;
47 action = desc->action;
48 spin_unlock(&desc->lock);
50 while (action) {
51 /* Only shared IRQ handlers are safe to call */
52 if (action->flags & IRQF_SHARED) {
53 if (action->handler(i, action->dev_id) ==
54 IRQ_HANDLED)
55 ok = 1;
57 action = action->next;
59 local_irq_disable();
60 /* Now clean up the flags */
61 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
72 work = 1;
73 spin_unlock(&desc->lock);
74 handle_IRQ_event(i, action);
75 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
83 if (work && desc->chip && desc->chip->end)
84 desc->chip->end(i);
85 spin_unlock(&desc->lock);
87 /* So the caller can adjust the irq error counts */
88 return ok;
92 * If 99,900 of the previous 100,000 interrupts have not been handled
93 * then assume that the IRQ is stuck in some manner. Drop a diagnostic
94 * and try to turn the IRQ off.
96 * (The other 100-of-100,000 interrupts may have been a correctly
97 * functioning device sharing an IRQ with the failing one)
99 * Called under desc->lock
102 static void
103 __report_bad_irq(unsigned int irq, struct irq_desc *desc,
104 irqreturn_t action_ret)
106 struct irqaction *action;
108 if (action_ret != IRQ_HANDLED && action_ret != IRQ_NONE) {
109 printk(KERN_ERR "irq event %d: bogus return value %x\n",
110 irq, action_ret);
111 } else {
112 printk(KERN_ERR "irq %d: nobody cared (try booting with "
113 "the \"irqpoll\" option)\n", irq);
115 dump_stack();
116 printk(KERN_ERR "handlers:\n");
118 action = desc->action;
119 while (action) {
120 printk(KERN_ERR "[<%p>]", action->handler);
121 print_symbol(" (%s)",
122 (unsigned long)action->handler);
123 printk("\n");
124 action = action->next;
128 static void
129 report_bad_irq(unsigned int irq, struct irq_desc *desc, irqreturn_t action_ret)
131 static int count = 100;
133 if (count > 0) {
134 count--;
135 __report_bad_irq(irq, desc, action_ret);
139 static inline int try_misrouted_irq(unsigned int irq, struct irq_desc *desc, irqreturn_t action_ret)
141 struct irqaction *action;
143 if (!irqfixup)
144 return 0;
146 /* We didn't actually handle the IRQ - see if it was misrouted? */
147 if (action_ret == IRQ_NONE)
148 return 1;
151 * But for 'irqfixup == 2' we also do it for handled interrupts if
152 * they are marked as IRQF_IRQPOLL (or for irq zero, which is the
153 * traditional PC timer interrupt.. Legacy)
155 if (irqfixup < 2)
156 return 0;
158 if (!irq)
159 return 1;
162 * Since we don't get the descriptor lock, "action" can
163 * change under us. We don't really care, but we don't
164 * want to follow a NULL pointer. So tell the compiler to
165 * just load it once by using a barrier.
167 action = desc->action;
168 barrier();
169 return action && (action->flags & IRQF_IRQPOLL);
172 void note_interrupt(unsigned int irq, struct irq_desc *desc,
173 irqreturn_t action_ret)
175 if (unlikely(action_ret != IRQ_HANDLED)) {
177 * If we are seeing only the odd spurious IRQ caused by
178 * bus asynchronicity then don't eventually trigger an error,
179 * otherwise the couter becomes a doomsday timer for otherwise
180 * working systems
182 if (jiffies - desc->last_unhandled > HZ/10)
183 desc->irqs_unhandled = 1;
184 else
185 desc->irqs_unhandled++;
186 desc->last_unhandled = jiffies;
187 if (unlikely(action_ret != IRQ_NONE))
188 report_bad_irq(irq, desc, action_ret);
191 if (unlikely(try_misrouted_irq(irq, desc, action_ret))) {
192 int ok = misrouted_irq(irq);
193 if (action_ret == IRQ_NONE)
194 desc->irqs_unhandled -= ok;
197 desc->irq_count++;
198 if (likely(desc->irq_count < 100000))
199 return;
201 desc->irq_count = 0;
202 if (unlikely(desc->irqs_unhandled > 99900)) {
204 * The interrupt is stuck
206 __report_bad_irq(irq, desc, action_ret);
208 * Now kill the IRQ
210 printk(KERN_EMERG "Disabling IRQ #%d\n", irq);
211 desc->status |= IRQ_DISABLED;
212 desc->depth = 1;
213 desc->chip->disable(irq);
215 desc->irqs_unhandled = 0;
218 int noirqdebug __read_mostly;
220 int noirqdebug_setup(char *str)
222 noirqdebug = 1;
223 printk(KERN_INFO "IRQ lockup detection disabled\n");
225 return 1;
228 __setup("noirqdebug", noirqdebug_setup);
229 module_param(noirqdebug, bool, 0644);
230 MODULE_PARM_DESC(noirqdebug, "Disable irq lockup detection when true");
232 static int __init irqfixup_setup(char *str)
234 irqfixup = 1;
235 printk(KERN_WARNING "Misrouted IRQ fixup support enabled.\n");
236 printk(KERN_WARNING "This may impact system performance.\n");
238 return 1;
241 __setup("irqfixup", irqfixup_setup);
242 module_param(irqfixup, int, 0644);
243 MODULE_PARM_DESC("irqfixup", "0: No fixup, 1: irqfixup mode 2: irqpoll mode");
245 static int __init irqpoll_setup(char *str)
247 irqfixup = 2;
248 printk(KERN_WARNING "Misrouted IRQ fixup and polling support "
249 "enabled\n");
250 printk(KERN_WARNING "This may significantly impact system "
251 "performance\n");
252 return 1;
255 __setup("irqpoll", irqpoll_setup);