blob: bd7273e6282ecf65a015c1e02239959497753a06 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/kernel/irq/spurious.c
3 *
4 * Copyright (C) 1992, 1998-2004 Linus Torvalds, Ingo Molnar
5 *
6 * This file contains spurious interrupt handling.
7 */
8
S.Caglar Onur188fd892008-02-14 17:36:51 +02009#include <linux/jiffies.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#include <linux/irq.h>
11#include <linux/module.h>
12#include <linux/kallsyms.h>
13#include <linux/interrupt.h>
Andi Kleen9e094c12008-01-30 13:32:48 +010014#include <linux/moduleparam.h>
Eric W. Biedermanf84dbb92008-07-10 14:48:54 -070015#include <linux/timer.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016
Andreas Mohr83d4e6e2006-06-23 02:05:32 -070017static int irqfixup __read_mostly;
Alan Cox200803d2005-06-28 20:45:18 -070018
Eric W. Biedermanf84dbb92008-07-10 14:48:54 -070019#define POLL_SPURIOUS_IRQ_INTERVAL (HZ/10)
20static void poll_spurious_irqs(unsigned long dummy);
21static DEFINE_TIMER(poll_spurious_irq_timer, poll_spurious_irqs, 0, 0);
22
Alan Cox200803d2005-06-28 20:45:18 -070023/*
24 * Recovery handler for misrouted interrupts.
25 */
Eric W. Biedermanf84dbb92008-07-10 14:48:54 -070026static int try_one_irq(int irq, struct irq_desc *desc)
27{
28 struct irqaction *action;
Thomas Gleixnerd3c60042008-10-16 09:55:00 +020029 int ok = 0, work = 0;
Eric W. Biedermanf84dbb92008-07-10 14:48:54 -070030
31 spin_lock(&desc->lock);
32 /* Already running on another processor */
33 if (desc->status & IRQ_INPROGRESS) {
34 /*
35 * Already running: If it is shared get the other
36 * CPU to go looking for our mystery interrupt too
37 */
38 if (desc->action && (desc->action->flags & IRQF_SHARED))
39 desc->status |= IRQ_PENDING;
40 spin_unlock(&desc->lock);
41 return ok;
42 }
43 /* Honour the normal IRQ locking */
44 desc->status |= IRQ_INPROGRESS;
45 action = desc->action;
46 spin_unlock(&desc->lock);
47
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;
54 }
55 action = action->next;
56 }
57 local_irq_disable();
58 /* Now clean up the flags */
59 spin_lock(&desc->lock);
60 action = desc->action;
61
62 /*
63 * While we were looking for a fixup someone queued a real
64 * IRQ clashing with our walk:
65 */
66 while ((desc->status & IRQ_PENDING) && action) {
67 /*
68 * Perform real IRQ processing for the IRQ we deferred
69 */
70 work = 1;
71 spin_unlock(&desc->lock);
72 handle_IRQ_event(irq, action);
73 spin_lock(&desc->lock);
74 desc->status &= ~IRQ_PENDING;
75 }
76 desc->status &= ~IRQ_INPROGRESS;
77 /*
78 * If we did actual work for the real IRQ line we must let the
79 * IRQ controller clean up too
80 */
81 if (work && desc->chip && desc->chip->end)
82 desc->chip->end(irq);
83 spin_unlock(&desc->lock);
84
85 return ok;
86}
87
David Howells7d12e782006-10-05 14:55:46 +010088static int misrouted_irq(int irq)
Alan Cox200803d2005-06-28 20:45:18 -070089{
Yinghai Lue00585b2008-09-15 01:53:50 -070090 struct irq_desc *desc;
Thomas Gleixnerd3c60042008-10-16 09:55:00 +020091 int i, ok = 0;
Alan Cox200803d2005-06-28 20:45:18 -070092
Yinghai Lue00585b2008-09-15 01:53:50 -070093 for_each_irq_desc(i, desc) {
94 if (!i)
95 continue;
Alan Cox200803d2005-06-28 20:45:18 -070096
97 if (i == irq) /* Already tried */
98 continue;
Ingo Molnar06fcb0c2006-06-29 02:24:40 -070099
Eric W. Biedermanf84dbb92008-07-10 14:48:54 -0700100 if (try_one_irq(i, desc))
101 ok = 1;
Alan Cox200803d2005-06-28 20:45:18 -0700102 }
103 /* So the caller can adjust the irq error counts */
104 return ok;
105}
106
Ingo Molnar74296a82009-01-16 17:43:50 +0100107static void poll_all_shared_irqs(void)
Eric W. Biedermanf84dbb92008-07-10 14:48:54 -0700108{
Yinghai Lue00585b2008-09-15 01:53:50 -0700109 struct irq_desc *desc;
Thomas Gleixnerd3c60042008-10-16 09:55:00 +0200110 int i;
Yinghai Lue00585b2008-09-15 01:53:50 -0700111
112 for_each_irq_desc(i, desc) {
Eric W. Biedermanf84dbb92008-07-10 14:48:54 -0700113 unsigned int status;
114
Yinghai Lue00585b2008-09-15 01:53:50 -0700115 if (!i)
116 continue;
117
Eric W. Biedermanf84dbb92008-07-10 14:48:54 -0700118 /* Racy but it doesn't matter */
119 status = desc->status;
120 barrier();
121 if (!(status & IRQ_SPURIOUS_DISABLED))
122 continue;
123
Yong Zhange7e7e0c2009-11-07 11:16:13 +0800124 local_irq_disable();
Eric W. Biedermanf84dbb92008-07-10 14:48:54 -0700125 try_one_irq(i, desc);
Yong Zhange7e7e0c2009-11-07 11:16:13 +0800126 local_irq_enable();
Eric W. Biedermanf84dbb92008-07-10 14:48:54 -0700127 }
Ingo Molnar74296a82009-01-16 17:43:50 +0100128}
129
130static void poll_spurious_irqs(unsigned long dummy)
131{
132 poll_all_shared_irqs();
Eric W. Biedermanf84dbb92008-07-10 14:48:54 -0700133
Thomas Gleixnerd3c60042008-10-16 09:55:00 +0200134 mod_timer(&poll_spurious_irq_timer,
135 jiffies + POLL_SPURIOUS_IRQ_INTERVAL);
Eric W. Biedermanf84dbb92008-07-10 14:48:54 -0700136}
137
Ingo Molnar74296a82009-01-16 17:43:50 +0100138#ifdef CONFIG_DEBUG_SHIRQ
139void debug_poll_all_shared_irqs(void)
140{
141 poll_all_shared_irqs();
142}
143#endif
144
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145/*
146 * If 99,900 of the previous 100,000 interrupts have not been handled
147 * then assume that the IRQ is stuck in some manner. Drop a diagnostic
148 * and try to turn the IRQ off.
149 *
150 * (The other 100-of-100,000 interrupts may have been a correctly
151 * functioning device sharing an IRQ with the failing one)
152 *
153 * Called under desc->lock
154 */
155
156static void
Ingo Molnar34ffdb72006-06-29 02:24:40 -0700157__report_bad_irq(unsigned int irq, struct irq_desc *desc,
158 irqreturn_t action_ret)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159{
160 struct irqaction *action;
161
162 if (action_ret != IRQ_HANDLED && action_ret != IRQ_NONE) {
163 printk(KERN_ERR "irq event %d: bogus return value %x\n",
164 irq, action_ret);
165 } else {
Alan Cox200803d2005-06-28 20:45:18 -0700166 printk(KERN_ERR "irq %d: nobody cared (try booting with "
167 "the \"irqpoll\" option)\n", irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 }
169 dump_stack();
170 printk(KERN_ERR "handlers:\n");
Ingo Molnar06fcb0c2006-06-29 02:24:40 -0700171
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 action = desc->action;
173 while (action) {
174 printk(KERN_ERR "[<%p>]", action->handler);
175 print_symbol(" (%s)",
176 (unsigned long)action->handler);
177 printk("\n");
178 action = action->next;
179 }
180}
181
Ingo Molnar06fcb0c2006-06-29 02:24:40 -0700182static void
Ingo Molnar34ffdb72006-06-29 02:24:40 -0700183report_bad_irq(unsigned int irq, struct irq_desc *desc, irqreturn_t action_ret)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184{
185 static int count = 100;
186
187 if (count > 0) {
188 count--;
189 __report_bad_irq(irq, desc, action_ret);
190 }
191}
192
Thomas Gleixnerd3c60042008-10-16 09:55:00 +0200193static inline int
194try_misrouted_irq(unsigned int irq, struct irq_desc *desc,
195 irqreturn_t action_ret)
Linus Torvalds92ea7722007-05-24 08:37:14 -0700196{
197 struct irqaction *action;
198
199 if (!irqfixup)
200 return 0;
201
202 /* We didn't actually handle the IRQ - see if it was misrouted? */
203 if (action_ret == IRQ_NONE)
204 return 1;
205
206 /*
207 * But for 'irqfixup == 2' we also do it for handled interrupts if
208 * they are marked as IRQF_IRQPOLL (or for irq zero, which is the
209 * traditional PC timer interrupt.. Legacy)
210 */
211 if (irqfixup < 2)
212 return 0;
213
214 if (!irq)
215 return 1;
216
217 /*
218 * Since we don't get the descriptor lock, "action" can
219 * change under us. We don't really care, but we don't
220 * want to follow a NULL pointer. So tell the compiler to
221 * just load it once by using a barrier.
222 */
223 action = desc->action;
224 barrier();
225 return action && (action->flags & IRQF_IRQPOLL);
226}
227
Ingo Molnar34ffdb72006-06-29 02:24:40 -0700228void note_interrupt(unsigned int irq, struct irq_desc *desc,
David Howells7d12e782006-10-05 14:55:46 +0100229 irqreturn_t action_ret)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230{
Andreas Mohr83d4e6e2006-06-23 02:05:32 -0700231 if (unlikely(action_ret != IRQ_HANDLED)) {
Alan Cox4f27c002007-07-15 23:40:55 -0700232 /*
233 * If we are seeing only the odd spurious IRQ caused by
234 * bus asynchronicity then don't eventually trigger an error,
235 * otherwise the couter becomes a doomsday timer for otherwise
236 * working systems
237 */
S.Caglar Onur188fd892008-02-14 17:36:51 +0200238 if (time_after(jiffies, desc->last_unhandled + HZ/10))
Alan Cox4f27c002007-07-15 23:40:55 -0700239 desc->irqs_unhandled = 1;
240 else
241 desc->irqs_unhandled++;
242 desc->last_unhandled = jiffies;
Andreas Mohr83d4e6e2006-06-23 02:05:32 -0700243 if (unlikely(action_ret != IRQ_NONE))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 report_bad_irq(irq, desc, action_ret);
245 }
246
Linus Torvalds92ea7722007-05-24 08:37:14 -0700247 if (unlikely(try_misrouted_irq(irq, desc, action_ret))) {
248 int ok = misrouted_irq(irq);
249 if (action_ret == IRQ_NONE)
250 desc->irqs_unhandled -= ok;
Alan Cox200803d2005-06-28 20:45:18 -0700251 }
252
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 desc->irq_count++;
Andreas Mohr83d4e6e2006-06-23 02:05:32 -0700254 if (likely(desc->irq_count < 100000))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 return;
256
257 desc->irq_count = 0;
Andreas Mohr83d4e6e2006-06-23 02:05:32 -0700258 if (unlikely(desc->irqs_unhandled > 99900)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 /*
260 * The interrupt is stuck
261 */
262 __report_bad_irq(irq, desc, action_ret);
263 /*
264 * Now kill the IRQ
265 */
266 printk(KERN_EMERG "Disabling IRQ #%d\n", irq);
Thomas Gleixner1adb0852008-04-28 17:01:56 +0200267 desc->status |= IRQ_DISABLED | IRQ_SPURIOUS_DISABLED;
268 desc->depth++;
Ingo Molnard1bef4e2006-06-29 02:24:36 -0700269 desc->chip->disable(irq);
Eric W. Biedermanf84dbb92008-07-10 14:48:54 -0700270
Thomas Gleixnerd3c60042008-10-16 09:55:00 +0200271 mod_timer(&poll_spurious_irq_timer,
272 jiffies + POLL_SPURIOUS_IRQ_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 }
274 desc->irqs_unhandled = 0;
275}
276
Andreas Mohr83d4e6e2006-06-23 02:05:32 -0700277int noirqdebug __read_mostly;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278
Vivek Goyal343cde52007-01-11 01:52:44 +0100279int noirqdebug_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280{
281 noirqdebug = 1;
282 printk(KERN_INFO "IRQ lockup detection disabled\n");
Ingo Molnar06fcb0c2006-06-29 02:24:40 -0700283
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 return 1;
285}
286
287__setup("noirqdebug", noirqdebug_setup);
Andi Kleen9e094c12008-01-30 13:32:48 +0100288module_param(noirqdebug, bool, 0644);
289MODULE_PARM_DESC(noirqdebug, "Disable irq lockup detection when true");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290
Alan Cox200803d2005-06-28 20:45:18 -0700291static int __init irqfixup_setup(char *str)
292{
293 irqfixup = 1;
294 printk(KERN_WARNING "Misrouted IRQ fixup support enabled.\n");
295 printk(KERN_WARNING "This may impact system performance.\n");
Ingo Molnar06fcb0c2006-06-29 02:24:40 -0700296
Alan Cox200803d2005-06-28 20:45:18 -0700297 return 1;
298}
299
300__setup("irqfixup", irqfixup_setup);
Andi Kleen9e094c12008-01-30 13:32:48 +0100301module_param(irqfixup, int, 0644);
Alan Cox200803d2005-06-28 20:45:18 -0700302
303static int __init irqpoll_setup(char *str)
304{
305 irqfixup = 2;
306 printk(KERN_WARNING "Misrouted IRQ fixup and polling support "
307 "enabled\n");
308 printk(KERN_WARNING "This may significantly impact system "
309 "performance\n");
310 return 1;
311}
312
313__setup("irqpoll", irqpoll_setup);