blob: 19fe9d6ebfe8658b8df7a62537947cd8a0aafd64 [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;
29 int ok = 0;
30 int work = 0; /* Did we do work for a real IRQ */
31
32 spin_lock(&desc->lock);
33 /* Already running on another processor */
34 if (desc->status & IRQ_INPROGRESS) {
35 /*
36 * Already running: If it is shared get the other
37 * CPU to go looking for our mystery interrupt too
38 */
39 if (desc->action && (desc->action->flags & IRQF_SHARED))
40 desc->status |= IRQ_PENDING;
41 spin_unlock(&desc->lock);
42 return ok;
43 }
44 /* Honour the normal IRQ locking */
45 desc->status |= IRQ_INPROGRESS;
46 action = desc->action;
47 spin_unlock(&desc->lock);
48
49 while (action) {
50 /* Only shared IRQ handlers are safe to call */
51 if (action->flags & IRQF_SHARED) {
52 if (action->handler(irq, action->dev_id) ==
53 IRQ_HANDLED)
54 ok = 1;
55 }
56 action = action->next;
57 }
58 local_irq_disable();
59 /* Now clean up the flags */
60 spin_lock(&desc->lock);
61 action = desc->action;
62
63 /*
64 * While we were looking for a fixup someone queued a real
65 * IRQ clashing with our walk:
66 */
67 while ((desc->status & IRQ_PENDING) && action) {
68 /*
69 * Perform real IRQ processing for the IRQ we deferred
70 */
71 work = 1;
72 spin_unlock(&desc->lock);
73 handle_IRQ_event(irq, action);
74 spin_lock(&desc->lock);
75 desc->status &= ~IRQ_PENDING;
76 }
77 desc->status &= ~IRQ_INPROGRESS;
78 /*
79 * If we did actual work for the real IRQ line we must let the
80 * IRQ controller clean up too
81 */
82 if (work && desc->chip && desc->chip->end)
83 desc->chip->end(irq);
84 spin_unlock(&desc->lock);
85
86 return ok;
87}
88
David Howells7d12e782006-10-05 14:55:46 +010089static int misrouted_irq(int irq)
Alan Cox200803d2005-06-28 20:45:18 -070090{
91 int i;
Alan Cox200803d2005-06-28 20:45:18 -070092 int ok = 0;
Alan Cox200803d2005-06-28 20:45:18 -070093
Ingo Molnar06fcb0c2006-06-29 02:24:40 -070094 for (i = 1; i < NR_IRQS; i++) {
95 struct irq_desc *desc = irq_desc + i;
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
Eric W. Biedermanf84dbb92008-07-10 14:48:54 -0700107static void poll_spurious_irqs(unsigned long dummy)
108{
109 int i;
110 for (i = 1; i < NR_IRQS; i++) {
111 struct irq_desc *desc = irq_desc + i;
112 unsigned int status;
113
114 /* Racy but it doesn't matter */
115 status = desc->status;
116 barrier();
117 if (!(status & IRQ_SPURIOUS_DISABLED))
118 continue;
119
120 try_one_irq(i, desc);
121 }
122
123 mod_timer(&poll_spurious_irq_timer, jiffies + POLL_SPURIOUS_IRQ_INTERVAL);
124}
125
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126/*
127 * If 99,900 of the previous 100,000 interrupts have not been handled
128 * then assume that the IRQ is stuck in some manner. Drop a diagnostic
129 * and try to turn the IRQ off.
130 *
131 * (The other 100-of-100,000 interrupts may have been a correctly
132 * functioning device sharing an IRQ with the failing one)
133 *
134 * Called under desc->lock
135 */
136
137static void
Ingo Molnar34ffdb72006-06-29 02:24:40 -0700138__report_bad_irq(unsigned int irq, struct irq_desc *desc,
139 irqreturn_t action_ret)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140{
141 struct irqaction *action;
142
143 if (action_ret != IRQ_HANDLED && action_ret != IRQ_NONE) {
144 printk(KERN_ERR "irq event %d: bogus return value %x\n",
145 irq, action_ret);
146 } else {
Alan Cox200803d2005-06-28 20:45:18 -0700147 printk(KERN_ERR "irq %d: nobody cared (try booting with "
148 "the \"irqpoll\" option)\n", irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 }
150 dump_stack();
151 printk(KERN_ERR "handlers:\n");
Ingo Molnar06fcb0c2006-06-29 02:24:40 -0700152
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 action = desc->action;
154 while (action) {
155 printk(KERN_ERR "[<%p>]", action->handler);
156 print_symbol(" (%s)",
157 (unsigned long)action->handler);
158 printk("\n");
159 action = action->next;
160 }
161}
162
Ingo Molnar06fcb0c2006-06-29 02:24:40 -0700163static void
Ingo Molnar34ffdb72006-06-29 02:24:40 -0700164report_bad_irq(unsigned int irq, struct irq_desc *desc, irqreturn_t action_ret)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165{
166 static int count = 100;
167
168 if (count > 0) {
169 count--;
170 __report_bad_irq(irq, desc, action_ret);
171 }
172}
173
Linus Torvalds92ea7722007-05-24 08:37:14 -0700174static inline int try_misrouted_irq(unsigned int irq, struct irq_desc *desc, irqreturn_t action_ret)
175{
176 struct irqaction *action;
177
178 if (!irqfixup)
179 return 0;
180
181 /* We didn't actually handle the IRQ - see if it was misrouted? */
182 if (action_ret == IRQ_NONE)
183 return 1;
184
185 /*
186 * But for 'irqfixup == 2' we also do it for handled interrupts if
187 * they are marked as IRQF_IRQPOLL (or for irq zero, which is the
188 * traditional PC timer interrupt.. Legacy)
189 */
190 if (irqfixup < 2)
191 return 0;
192
193 if (!irq)
194 return 1;
195
196 /*
197 * Since we don't get the descriptor lock, "action" can
198 * change under us. We don't really care, but we don't
199 * want to follow a NULL pointer. So tell the compiler to
200 * just load it once by using a barrier.
201 */
202 action = desc->action;
203 barrier();
204 return action && (action->flags & IRQF_IRQPOLL);
205}
206
Ingo Molnar34ffdb72006-06-29 02:24:40 -0700207void note_interrupt(unsigned int irq, struct irq_desc *desc,
David Howells7d12e782006-10-05 14:55:46 +0100208 irqreturn_t action_ret)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209{
Andreas Mohr83d4e6e2006-06-23 02:05:32 -0700210 if (unlikely(action_ret != IRQ_HANDLED)) {
Alan Cox4f27c002007-07-15 23:40:55 -0700211 /*
212 * If we are seeing only the odd spurious IRQ caused by
213 * bus asynchronicity then don't eventually trigger an error,
214 * otherwise the couter becomes a doomsday timer for otherwise
215 * working systems
216 */
S.Caglar Onur188fd892008-02-14 17:36:51 +0200217 if (time_after(jiffies, desc->last_unhandled + HZ/10))
Alan Cox4f27c002007-07-15 23:40:55 -0700218 desc->irqs_unhandled = 1;
219 else
220 desc->irqs_unhandled++;
221 desc->last_unhandled = jiffies;
Andreas Mohr83d4e6e2006-06-23 02:05:32 -0700222 if (unlikely(action_ret != IRQ_NONE))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 report_bad_irq(irq, desc, action_ret);
224 }
225
Linus Torvalds92ea7722007-05-24 08:37:14 -0700226 if (unlikely(try_misrouted_irq(irq, desc, action_ret))) {
227 int ok = misrouted_irq(irq);
228 if (action_ret == IRQ_NONE)
229 desc->irqs_unhandled -= ok;
Alan Cox200803d2005-06-28 20:45:18 -0700230 }
231
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 desc->irq_count++;
Andreas Mohr83d4e6e2006-06-23 02:05:32 -0700233 if (likely(desc->irq_count < 100000))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 return;
235
236 desc->irq_count = 0;
Andreas Mohr83d4e6e2006-06-23 02:05:32 -0700237 if (unlikely(desc->irqs_unhandled > 99900)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 /*
239 * The interrupt is stuck
240 */
241 __report_bad_irq(irq, desc, action_ret);
242 /*
243 * Now kill the IRQ
244 */
245 printk(KERN_EMERG "Disabling IRQ #%d\n", irq);
Thomas Gleixner1adb0852008-04-28 17:01:56 +0200246 desc->status |= IRQ_DISABLED | IRQ_SPURIOUS_DISABLED;
247 desc->depth++;
Ingo Molnard1bef4e2006-06-29 02:24:36 -0700248 desc->chip->disable(irq);
Eric W. Biedermanf84dbb92008-07-10 14:48:54 -0700249
250 mod_timer(&poll_spurious_irq_timer, jiffies + POLL_SPURIOUS_IRQ_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 }
252 desc->irqs_unhandled = 0;
253}
254
Andreas Mohr83d4e6e2006-06-23 02:05:32 -0700255int noirqdebug __read_mostly;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256
Vivek Goyal343cde52007-01-11 01:52:44 +0100257int noirqdebug_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258{
259 noirqdebug = 1;
260 printk(KERN_INFO "IRQ lockup detection disabled\n");
Ingo Molnar06fcb0c2006-06-29 02:24:40 -0700261
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 return 1;
263}
264
265__setup("noirqdebug", noirqdebug_setup);
Andi Kleen9e094c12008-01-30 13:32:48 +0100266module_param(noirqdebug, bool, 0644);
267MODULE_PARM_DESC(noirqdebug, "Disable irq lockup detection when true");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268
Alan Cox200803d2005-06-28 20:45:18 -0700269static int __init irqfixup_setup(char *str)
270{
271 irqfixup = 1;
272 printk(KERN_WARNING "Misrouted IRQ fixup support enabled.\n");
273 printk(KERN_WARNING "This may impact system performance.\n");
Ingo Molnar06fcb0c2006-06-29 02:24:40 -0700274
Alan Cox200803d2005-06-28 20:45:18 -0700275 return 1;
276}
277
278__setup("irqfixup", irqfixup_setup);
Andi Kleen9e094c12008-01-30 13:32:48 +0100279module_param(irqfixup, int, 0644);
280MODULE_PARM_DESC("irqfixup", "0: No fixup, 1: irqfixup mode 2: irqpoll mode");
Alan Cox200803d2005-06-28 20:45:18 -0700281
282static int __init irqpoll_setup(char *str)
283{
284 irqfixup = 2;
285 printk(KERN_WARNING "Misrouted IRQ fixup and polling support "
286 "enabled\n");
287 printk(KERN_WARNING "This may significantly impact system "
288 "performance\n");
289 return 1;
290}
291
292__setup("irqpoll", irqpoll_setup);