added 2.6.29.6 aldebaran kernel
[nao-ulib.git] / kernel / 2.6.29.6-aldebaran-rt / kernel / irq / spurious.c
blob75f74895173c7fca120d6b37ed7eb8cdd579cf4e
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 #ifdef CONFIG_X86_IO_APIC
18 # include <asm/apicdef.h>
19 # include <asm/io_apic.h>
20 #endif
22 static int irqfixup __read_mostly;
24 #define POLL_SPURIOUS_IRQ_INTERVAL (HZ/10)
25 static void poll_spurious_irqs(unsigned long dummy);
26 static DEFINE_TIMER(poll_spurious_irq_timer, poll_spurious_irqs, 0, 0);
29 * Recovery handler for misrouted interrupts.
31 static int try_one_irq(int irq, struct irq_desc *desc)
33 struct irqaction *action;
34 int ok = 0, work = 0;
36 spin_lock(&desc->lock);
37 /* Already running on another processor */
38 if (desc->status & IRQ_INPROGRESS) {
40 * Already running: If it is shared get the other
41 * CPU to go looking for our mystery interrupt too
43 if (desc->action && (desc->action->flags & IRQF_SHARED))
44 desc->status |= IRQ_PENDING;
45 spin_unlock(&desc->lock);
46 return ok;
48 /* Honour the normal IRQ locking */
49 desc->status |= IRQ_INPROGRESS;
50 action = desc->action;
51 spin_unlock(&desc->lock);
53 while (action) {
54 /* Only shared IRQ handlers are safe to call */
55 if (action->flags & IRQF_SHARED) {
56 if (action->handler(irq, action->dev_id) ==
57 IRQ_HANDLED)
58 ok = 1;
60 action = action->next;
62 /* Now clean up the flags */
63 spin_lock_irq(&desc->lock);
64 action = desc->action;
67 * While we were looking for a fixup someone queued a real
68 * IRQ clashing with our walk:
70 while ((desc->status & IRQ_PENDING) && action) {
72 * Perform real IRQ processing for the IRQ we deferred
74 work = 1;
75 spin_unlock(&desc->lock);
76 handle_IRQ_event(irq, action);
77 spin_lock(&desc->lock);
78 desc->status &= ~IRQ_PENDING;
80 desc->status &= ~IRQ_INPROGRESS;
82 * If we did actual work for the real IRQ line we must let the
83 * IRQ controller clean up too
85 if (work && desc->chip && desc->chip->end)
86 desc->chip->end(irq);
87 spin_unlock(&desc->lock);
89 return ok;
92 static int misrouted_irq(int irq)
94 struct irq_desc *desc;
95 int i, ok = 0;
97 for_each_irq_desc(i, desc) {
98 if (!i)
99 continue;
101 if (i == irq) /* Already tried */
102 continue;
104 if (try_one_irq(i, desc))
105 ok = 1;
107 /* So the caller can adjust the irq error counts */
108 return ok;
111 static void poll_all_shared_irqs(void)
113 struct irq_desc *desc;
114 int i;
116 for_each_irq_desc(i, desc) {
117 unsigned int status;
119 if (!i)
120 continue;
122 /* Racy but it doesn't matter */
123 status = desc->status;
124 barrier();
125 if (!(status & IRQ_SPURIOUS_DISABLED))
126 continue;
128 try_one_irq(i, desc);
132 static void poll_spurious_irqs(unsigned long dummy)
134 poll_all_shared_irqs();
136 mod_timer(&poll_spurious_irq_timer,
137 jiffies + POLL_SPURIOUS_IRQ_INTERVAL);
140 #ifdef CONFIG_DEBUG_SHIRQ
141 void debug_poll_all_shared_irqs(void)
143 poll_all_shared_irqs();
145 #endif
148 * If 99,900 of the previous 100,000 interrupts have not been handled
149 * then assume that the IRQ is stuck in some manner. Drop a diagnostic
150 * and try to turn the IRQ off.
152 * (The other 100-of-100,000 interrupts may have been a correctly
153 * functioning device sharing an IRQ with the failing one)
155 * Called under desc->lock
158 static void
159 __report_bad_irq(unsigned int irq, struct irq_desc *desc,
160 irqreturn_t action_ret)
162 struct irqaction *action;
164 if (action_ret != IRQ_HANDLED && action_ret != IRQ_NONE) {
165 printk(KERN_ERR "irq event %d: bogus return value %x\n",
166 irq, action_ret);
167 } else {
168 printk(KERN_ERR "irq %d: nobody cared (try booting with "
169 "the \"irqpoll\" option)\n", irq);
171 dump_stack();
172 printk(KERN_ERR "handlers:\n");
174 action = desc->action;
175 while (action) {
176 printk(KERN_ERR "[<%p>]", action->handler);
177 print_symbol(" (%s)",
178 (unsigned long)action->handler);
179 printk("\n");
180 action = action->next;
184 static void
185 report_bad_irq(unsigned int irq, struct irq_desc *desc, irqreturn_t action_ret)
187 static int count = 100;
189 if (count > 0) {
190 count--;
191 __report_bad_irq(irq, desc, action_ret);
195 static inline int
196 try_misrouted_irq(unsigned int irq, struct irq_desc *desc,
197 irqreturn_t action_ret)
199 struct irqaction *action;
201 if (!irqfixup)
202 return 0;
204 /* We didn't actually handle the IRQ - see if it was misrouted? */
205 if (action_ret == IRQ_NONE)
206 return 1;
209 * But for 'irqfixup == 2' we also do it for handled interrupts if
210 * they are marked as IRQF_IRQPOLL (or for irq zero, which is the
211 * traditional PC timer interrupt.. Legacy)
213 if (irqfixup < 2)
214 return 0;
216 if (!irq)
217 return 1;
220 * Since we don't get the descriptor lock, "action" can
221 * change under us. We don't really care, but we don't
222 * want to follow a NULL pointer. So tell the compiler to
223 * just load it once by using a barrier.
225 action = desc->action;
226 barrier();
227 return action && (action->flags & IRQF_IRQPOLL);
230 void note_interrupt(unsigned int irq, struct irq_desc *desc,
231 irqreturn_t action_ret)
233 if (unlikely(action_ret != IRQ_HANDLED)) {
235 * If we are seeing only the odd spurious IRQ caused by
236 * bus asynchronicity then don't eventually trigger an error,
237 * otherwise the couter becomes a doomsday timer for otherwise
238 * working systems
240 if (time_after(jiffies, desc->last_unhandled + HZ/10))
241 desc->irqs_unhandled = 1;
242 else
243 desc->irqs_unhandled++;
244 desc->last_unhandled = jiffies;
245 if (unlikely(action_ret != IRQ_NONE))
246 report_bad_irq(irq, desc, action_ret);
249 if (unlikely(try_misrouted_irq(irq, desc, action_ret))) {
250 int ok = misrouted_irq(irq);
251 if (action_ret == IRQ_NONE)
252 desc->irqs_unhandled -= ok;
255 desc->irq_count++;
256 if (likely(desc->irq_count < 100000))
257 return;
259 desc->irq_count = 0;
260 if (unlikely(desc->irqs_unhandled > 99900)) {
262 * The interrupt is stuck
264 __report_bad_irq(irq, desc, action_ret);
265 #ifdef CONFIG_X86_IO_APIC
266 if (!sis_apic_bug) {
267 sis_apic_bug = 1;
268 printk(KERN_ERR "turning off IO-APIC fast mode.\n");
270 #else
272 * Now kill the IRQ
274 printk(KERN_EMERG "Disabling IRQ #%d\n", irq);
275 desc->status |= IRQ_DISABLED | IRQ_SPURIOUS_DISABLED;
276 desc->depth++;
277 desc->chip->disable(irq);
279 mod_timer(&poll_spurious_irq_timer,
280 jiffies + POLL_SPURIOUS_IRQ_INTERVAL);
281 #endif
283 desc->irqs_unhandled = 0;
286 int noirqdebug __read_mostly;
288 int noirqdebug_setup(char *str)
290 noirqdebug = 1;
291 printk(KERN_INFO "IRQ lockup detection disabled\n");
293 return 1;
296 __setup("noirqdebug", noirqdebug_setup);
297 module_param(noirqdebug, bool, 0644);
298 MODULE_PARM_DESC(noirqdebug, "Disable irq lockup detection when true");
300 static int __init irqfixup_setup(char *str)
302 #ifdef CONFIG_PREEMPT_RT
303 printk(KERN_WARNING "irqfixup boot option not supported "
304 "w/ CONFIG_PREEMPT_RT\n");
305 return 1;
306 #endif
307 irqfixup = 1;
308 printk(KERN_WARNING "Misrouted IRQ fixup support enabled.\n");
309 printk(KERN_WARNING "This may impact system performance.\n");
311 return 1;
314 __setup("irqfixup", irqfixup_setup);
315 module_param(irqfixup, int, 0644);
316 MODULE_PARM_DESC("irqfixup", "0: No fixup, 1: irqfixup mode, 2: irqpoll mode");
318 static int __init irqpoll_setup(char *str)
320 #ifdef CONFIG_PREEMPT_RT
321 printk(KERN_WARNING "irqpoll boot option not supported "
322 "w/ CONFIG_PREEMPT_RT\n");
323 return 1;
324 #endif
325 irqfixup = 2;
326 printk(KERN_WARNING "Misrouted IRQ fixup and polling support "
327 "enabled\n");
328 printk(KERN_WARNING "This may significantly impact system "
329 "performance\n");
330 return 1;
333 __setup("irqpoll", irqpoll_setup);