random: align rekey_work's timer
[linux-2.6/mini2440.git] / kernel / irq / spurious.c
blob4d568294de3ebfc1326432a9d7a7e4a01cdb115b
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>
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;
29 int ok = 0, work = 0;
31 spin_lock(&desc->lock);
32 /* Already running on another processor */
33 if (desc->status & IRQ_INPROGRESS) {
35 * Already running: If it is shared get the other
36 * CPU to go looking for our mystery interrupt too
38 if (desc->action && (desc->action->flags & IRQF_SHARED))
39 desc->status |= IRQ_PENDING;
40 spin_unlock(&desc->lock);
41 return ok;
43 /* Honour the normal IRQ locking */
44 desc->status |= IRQ_INPROGRESS;
45 action = desc->action;
46 spin_unlock(&desc->lock);
48 while (action) {
49 /* Only shared IRQ handlers are safe to call */
50 if (action->flags & IRQF_SHARED) {
51 if (action->handler(irq, action->dev_id) ==
52 IRQ_HANDLED)
53 ok = 1;
55 action = action->next;
57 local_irq_disable();
58 /* Now clean up the flags */
59 spin_lock(&desc->lock);
60 action = desc->action;
63 * While we were looking for a fixup someone queued a real
64 * IRQ clashing with our walk:
66 while ((desc->status & IRQ_PENDING) && action) {
68 * Perform real IRQ processing for the IRQ we deferred
70 work = 1;
71 spin_unlock(&desc->lock);
72 handle_IRQ_event(irq, action);
73 spin_lock(&desc->lock);
74 desc->status &= ~IRQ_PENDING;
76 desc->status &= ~IRQ_INPROGRESS;
78 * If we did actual work for the real IRQ line we must let the
79 * IRQ controller clean up too
81 if (work && desc->chip && desc->chip->end)
82 desc->chip->end(irq);
83 spin_unlock(&desc->lock);
85 return ok;
88 static int misrouted_irq(int irq)
90 struct irq_desc *desc;
91 int i, ok = 0;
93 for_each_irq_desc(i, desc) {
94 if (!i)
95 continue;
97 if (i == irq) /* Already tried */
98 continue;
100 if (try_one_irq(i, desc))
101 ok = 1;
103 /* So the caller can adjust the irq error counts */
104 return ok;
107 static void poll_all_shared_irqs(void)
109 struct irq_desc *desc;
110 int i;
112 for_each_irq_desc(i, desc) {
113 unsigned int status;
115 if (!i)
116 continue;
118 /* Racy but it doesn't matter */
119 status = desc->status;
120 barrier();
121 if (!(status & IRQ_SPURIOUS_DISABLED))
122 continue;
124 try_one_irq(i, desc);
128 static void poll_spurious_irqs(unsigned long dummy)
130 poll_all_shared_irqs();
132 mod_timer(&poll_spurious_irq_timer,
133 jiffies + POLL_SPURIOUS_IRQ_INTERVAL);
136 #ifdef CONFIG_DEBUG_SHIRQ
137 void debug_poll_all_shared_irqs(void)
139 poll_all_shared_irqs();
141 #endif
144 * If 99,900 of the previous 100,000 interrupts have not been handled
145 * then assume that the IRQ is stuck in some manner. Drop a diagnostic
146 * and try to turn the IRQ off.
148 * (The other 100-of-100,000 interrupts may have been a correctly
149 * functioning device sharing an IRQ with the failing one)
151 * Called under desc->lock
154 static void
155 __report_bad_irq(unsigned int irq, struct irq_desc *desc,
156 irqreturn_t action_ret)
158 struct irqaction *action;
160 if (action_ret != IRQ_HANDLED && action_ret != IRQ_NONE) {
161 printk(KERN_ERR "irq event %d: bogus return value %x\n",
162 irq, action_ret);
163 } else {
164 printk(KERN_ERR "irq %d: nobody cared (try booting with "
165 "the \"irqpoll\" option)\n", irq);
167 dump_stack();
168 printk(KERN_ERR "handlers:\n");
170 action = desc->action;
171 while (action) {
172 printk(KERN_ERR "[<%p>]", action->handler);
173 print_symbol(" (%s)",
174 (unsigned long)action->handler);
175 printk("\n");
176 action = action->next;
180 static void
181 report_bad_irq(unsigned int irq, struct irq_desc *desc, irqreturn_t action_ret)
183 static int count = 100;
185 if (count > 0) {
186 count--;
187 __report_bad_irq(irq, desc, action_ret);
191 static inline int
192 try_misrouted_irq(unsigned int irq, struct irq_desc *desc,
193 irqreturn_t action_ret)
195 struct irqaction *action;
197 if (!irqfixup)
198 return 0;
200 /* We didn't actually handle the IRQ - see if it was misrouted? */
201 if (action_ret == IRQ_NONE)
202 return 1;
205 * But for 'irqfixup == 2' we also do it for handled interrupts if
206 * they are marked as IRQF_IRQPOLL (or for irq zero, which is the
207 * traditional PC timer interrupt.. Legacy)
209 if (irqfixup < 2)
210 return 0;
212 if (!irq)
213 return 1;
216 * Since we don't get the descriptor lock, "action" can
217 * change under us. We don't really care, but we don't
218 * want to follow a NULL pointer. So tell the compiler to
219 * just load it once by using a barrier.
221 action = desc->action;
222 barrier();
223 return action && (action->flags & IRQF_IRQPOLL);
226 void note_interrupt(unsigned int irq, struct irq_desc *desc,
227 irqreturn_t action_ret)
229 if (unlikely(action_ret != IRQ_HANDLED)) {
231 * If we are seeing only the odd spurious IRQ caused by
232 * bus asynchronicity then don't eventually trigger an error,
233 * otherwise the couter becomes a doomsday timer for otherwise
234 * working systems
236 if (time_after(jiffies, desc->last_unhandled + HZ/10))
237 desc->irqs_unhandled = 1;
238 else
239 desc->irqs_unhandled++;
240 desc->last_unhandled = jiffies;
241 if (unlikely(action_ret != IRQ_NONE))
242 report_bad_irq(irq, desc, action_ret);
245 if (unlikely(try_misrouted_irq(irq, desc, action_ret))) {
246 int ok = misrouted_irq(irq);
247 if (action_ret == IRQ_NONE)
248 desc->irqs_unhandled -= ok;
251 desc->irq_count++;
252 if (likely(desc->irq_count < 100000))
253 return;
255 desc->irq_count = 0;
256 if (unlikely(desc->irqs_unhandled > 99900)) {
258 * The interrupt is stuck
260 __report_bad_irq(irq, desc, action_ret);
262 * Now kill the IRQ
264 printk(KERN_EMERG "Disabling IRQ #%d\n", irq);
265 desc->status |= IRQ_DISABLED | IRQ_SPURIOUS_DISABLED;
266 desc->depth++;
267 desc->chip->disable(irq);
269 mod_timer(&poll_spurious_irq_timer,
270 jiffies + POLL_SPURIOUS_IRQ_INTERVAL);
272 desc->irqs_unhandled = 0;
275 int noirqdebug __read_mostly;
277 int noirqdebug_setup(char *str)
279 noirqdebug = 1;
280 printk(KERN_INFO "IRQ lockup detection disabled\n");
282 return 1;
285 __setup("noirqdebug", noirqdebug_setup);
286 module_param(noirqdebug, bool, 0644);
287 MODULE_PARM_DESC(noirqdebug, "Disable irq lockup detection when true");
289 static int __init irqfixup_setup(char *str)
291 irqfixup = 1;
292 printk(KERN_WARNING "Misrouted IRQ fixup support enabled.\n");
293 printk(KERN_WARNING "This may impact system performance.\n");
295 return 1;
298 __setup("irqfixup", irqfixup_setup);
299 module_param(irqfixup, int, 0644);
300 MODULE_PARM_DESC("irqfixup", "0: No fixup, 1: irqfixup mode, 2: irqpoll mode");
302 static int __init irqpoll_setup(char *str)
304 irqfixup = 2;
305 printk(KERN_WARNING "Misrouted IRQ fixup and polling support "
306 "enabled\n");
307 printk(KERN_WARNING "This may significantly impact system "
308 "performance\n");
309 return 1;
312 __setup("irqpoll", irqpoll_setup);