blob: c66d3f10e85326ab1041a29202047734769b9b10 [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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015
Andreas Mohr83d4e6e2006-06-23 02:05:32 -070016static int irqfixup __read_mostly;
Alan Cox200803d2005-06-28 20:45:18 -070017
18/*
19 * Recovery handler for misrouted interrupts.
20 */
David Howells7d12e782006-10-05 14:55:46 +010021static int misrouted_irq(int irq)
Alan Cox200803d2005-06-28 20:45:18 -070022{
23 int i;
Alan Cox200803d2005-06-28 20:45:18 -070024 int ok = 0;
25 int work = 0; /* Did we do work for a real IRQ */
26
Ingo Molnar06fcb0c2006-06-29 02:24:40 -070027 for (i = 1; i < NR_IRQS; i++) {
28 struct irq_desc *desc = irq_desc + i;
Alan Cox200803d2005-06-28 20:45:18 -070029 struct irqaction *action;
30
31 if (i == irq) /* Already tried */
32 continue;
Ingo Molnar06fcb0c2006-06-29 02:24:40 -070033
Alan Cox200803d2005-06-28 20:45:18 -070034 spin_lock(&desc->lock);
Alan Cox200803d2005-06-28 20:45:18 -070035 /* Already running on another processor */
36 if (desc->status & IRQ_INPROGRESS) {
37 /*
38 * Already running: If it is shared get the other
39 * CPU to go looking for our mystery interrupt too
40 */
Thomas Gleixner3cca53b2006-07-01 19:29:31 -070041 if (desc->action && (desc->action->flags & IRQF_SHARED))
Alan Cox200803d2005-06-28 20:45:18 -070042 desc->status |= IRQ_PENDING;
43 spin_unlock(&desc->lock);
44 continue;
45 }
46 /* Honour the normal IRQ locking */
47 desc->status |= IRQ_INPROGRESS;
Ingo Molnar06fcb0c2006-06-29 02:24:40 -070048 action = desc->action;
Alan Cox200803d2005-06-28 20:45:18 -070049 spin_unlock(&desc->lock);
Ingo Molnar06fcb0c2006-06-29 02:24:40 -070050
Alan Cox200803d2005-06-28 20:45:18 -070051 while (action) {
52 /* Only shared IRQ handlers are safe to call */
Thomas Gleixner3cca53b2006-07-01 19:29:31 -070053 if (action->flags & IRQF_SHARED) {
David Howells7d12e782006-10-05 14:55:46 +010054 if (action->handler(i, action->dev_id) ==
Alan Cox200803d2005-06-28 20:45:18 -070055 IRQ_HANDLED)
56 ok = 1;
57 }
58 action = action->next;
59 }
60 local_irq_disable();
61 /* Now clean up the flags */
62 spin_lock(&desc->lock);
63 action = desc->action;
64
65 /*
66 * While we were looking for a fixup someone queued a real
Ingo Molnar06fcb0c2006-06-29 02:24:40 -070067 * IRQ clashing with our walk:
Alan Cox200803d2005-06-28 20:45:18 -070068 */
Alan Cox200803d2005-06-28 20:45:18 -070069 while ((desc->status & IRQ_PENDING) && action) {
70 /*
71 * Perform real IRQ processing for the IRQ we deferred
72 */
73 work = 1;
74 spin_unlock(&desc->lock);
David Howells7d12e782006-10-05 14:55:46 +010075 handle_IRQ_event(i, action);
Alan Cox200803d2005-06-28 20:45:18 -070076 spin_lock(&desc->lock);
77 desc->status &= ~IRQ_PENDING;
78 }
79 desc->status &= ~IRQ_INPROGRESS;
80 /*
81 * If we did actual work for the real IRQ line we must let the
82 * IRQ controller clean up too
83 */
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070084 if (work && desc->chip && desc->chip->end)
Ingo Molnard1bef4e2006-06-29 02:24:36 -070085 desc->chip->end(i);
Alan Cox200803d2005-06-28 20:45:18 -070086 spin_unlock(&desc->lock);
87 }
88 /* So the caller can adjust the irq error counts */
89 return ok;
90}
91
Linus Torvalds1da177e2005-04-16 15:20:36 -070092/*
93 * If 99,900 of the previous 100,000 interrupts have not been handled
94 * then assume that the IRQ is stuck in some manner. Drop a diagnostic
95 * and try to turn the IRQ off.
96 *
97 * (The other 100-of-100,000 interrupts may have been a correctly
98 * functioning device sharing an IRQ with the failing one)
99 *
100 * Called under desc->lock
101 */
102
103static void
Ingo Molnar34ffdb72006-06-29 02:24:40 -0700104__report_bad_irq(unsigned int irq, struct irq_desc *desc,
105 irqreturn_t action_ret)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106{
107 struct irqaction *action;
108
109 if (action_ret != IRQ_HANDLED && action_ret != IRQ_NONE) {
110 printk(KERN_ERR "irq event %d: bogus return value %x\n",
111 irq, action_ret);
112 } else {
Alan Cox200803d2005-06-28 20:45:18 -0700113 printk(KERN_ERR "irq %d: nobody cared (try booting with "
114 "the \"irqpoll\" option)\n", irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 }
116 dump_stack();
117 printk(KERN_ERR "handlers:\n");
Ingo Molnar06fcb0c2006-06-29 02:24:40 -0700118
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 action = desc->action;
120 while (action) {
121 printk(KERN_ERR "[<%p>]", action->handler);
122 print_symbol(" (%s)",
123 (unsigned long)action->handler);
124 printk("\n");
125 action = action->next;
126 }
127}
128
Ingo Molnar06fcb0c2006-06-29 02:24:40 -0700129static void
Ingo Molnar34ffdb72006-06-29 02:24:40 -0700130report_bad_irq(unsigned int irq, struct irq_desc *desc, irqreturn_t action_ret)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131{
132 static int count = 100;
133
134 if (count > 0) {
135 count--;
136 __report_bad_irq(irq, desc, action_ret);
137 }
138}
139
Linus Torvalds92ea7722007-05-24 08:37:14 -0700140static inline int try_misrouted_irq(unsigned int irq, struct irq_desc *desc, irqreturn_t action_ret)
141{
142 struct irqaction *action;
143
144 if (!irqfixup)
145 return 0;
146
147 /* We didn't actually handle the IRQ - see if it was misrouted? */
148 if (action_ret == IRQ_NONE)
149 return 1;
150
151 /*
152 * But for 'irqfixup == 2' we also do it for handled interrupts if
153 * they are marked as IRQF_IRQPOLL (or for irq zero, which is the
154 * traditional PC timer interrupt.. Legacy)
155 */
156 if (irqfixup < 2)
157 return 0;
158
159 if (!irq)
160 return 1;
161
162 /*
163 * Since we don't get the descriptor lock, "action" can
164 * change under us. We don't really care, but we don't
165 * want to follow a NULL pointer. So tell the compiler to
166 * just load it once by using a barrier.
167 */
168 action = desc->action;
169 barrier();
170 return action && (action->flags & IRQF_IRQPOLL);
171}
172
Ingo Molnar34ffdb72006-06-29 02:24:40 -0700173void note_interrupt(unsigned int irq, struct irq_desc *desc,
David Howells7d12e782006-10-05 14:55:46 +0100174 irqreturn_t action_ret)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175{
Andreas Mohr83d4e6e2006-06-23 02:05:32 -0700176 if (unlikely(action_ret != IRQ_HANDLED)) {
Alan Cox4f27c002007-07-15 23:40:55 -0700177 /*
178 * If we are seeing only the odd spurious IRQ caused by
179 * bus asynchronicity then don't eventually trigger an error,
180 * otherwise the couter becomes a doomsday timer for otherwise
181 * working systems
182 */
S.Caglar Onur188fd892008-02-14 17:36:51 +0200183 if (time_after(jiffies, desc->last_unhandled + HZ/10))
Alan Cox4f27c002007-07-15 23:40:55 -0700184 desc->irqs_unhandled = 1;
185 else
186 desc->irqs_unhandled++;
187 desc->last_unhandled = jiffies;
Andreas Mohr83d4e6e2006-06-23 02:05:32 -0700188 if (unlikely(action_ret != IRQ_NONE))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 report_bad_irq(irq, desc, action_ret);
190 }
191
Linus Torvalds92ea7722007-05-24 08:37:14 -0700192 if (unlikely(try_misrouted_irq(irq, desc, action_ret))) {
193 int ok = misrouted_irq(irq);
194 if (action_ret == IRQ_NONE)
195 desc->irqs_unhandled -= ok;
Alan Cox200803d2005-06-28 20:45:18 -0700196 }
197
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 desc->irq_count++;
Andreas Mohr83d4e6e2006-06-23 02:05:32 -0700199 if (likely(desc->irq_count < 100000))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 return;
201
202 desc->irq_count = 0;
Andreas Mohr83d4e6e2006-06-23 02:05:32 -0700203 if (unlikely(desc->irqs_unhandled > 99900)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 /*
205 * The interrupt is stuck
206 */
207 __report_bad_irq(irq, desc, action_ret);
208 /*
209 * Now kill the IRQ
210 */
211 printk(KERN_EMERG "Disabling IRQ #%d\n", irq);
Thomas Gleixner1adb0852008-04-28 17:01:56 +0200212 desc->status |= IRQ_DISABLED | IRQ_SPURIOUS_DISABLED;
213 desc->depth++;
Ingo Molnard1bef4e2006-06-29 02:24:36 -0700214 desc->chip->disable(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 }
216 desc->irqs_unhandled = 0;
217}
218
Andreas Mohr83d4e6e2006-06-23 02:05:32 -0700219int noirqdebug __read_mostly;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220
Vivek Goyal343cde52007-01-11 01:52:44 +0100221int noirqdebug_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222{
223 noirqdebug = 1;
224 printk(KERN_INFO "IRQ lockup detection disabled\n");
Ingo Molnar06fcb0c2006-06-29 02:24:40 -0700225
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 return 1;
227}
228
229__setup("noirqdebug", noirqdebug_setup);
Andi Kleen9e094c12008-01-30 13:32:48 +0100230module_param(noirqdebug, bool, 0644);
231MODULE_PARM_DESC(noirqdebug, "Disable irq lockup detection when true");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232
Alan Cox200803d2005-06-28 20:45:18 -0700233static int __init irqfixup_setup(char *str)
234{
235 irqfixup = 1;
236 printk(KERN_WARNING "Misrouted IRQ fixup support enabled.\n");
237 printk(KERN_WARNING "This may impact system performance.\n");
Ingo Molnar06fcb0c2006-06-29 02:24:40 -0700238
Alan Cox200803d2005-06-28 20:45:18 -0700239 return 1;
240}
241
242__setup("irqfixup", irqfixup_setup);
Andi Kleen9e094c12008-01-30 13:32:48 +0100243module_param(irqfixup, int, 0644);
244MODULE_PARM_DESC("irqfixup", "0: No fixup, 1: irqfixup mode 2: irqpoll mode");
Alan Cox200803d2005-06-28 20:45:18 -0700245
246static int __init irqpoll_setup(char *str)
247{
248 irqfixup = 2;
249 printk(KERN_WARNING "Misrouted IRQ fixup and polling support "
250 "enabled\n");
251 printk(KERN_WARNING "This may significantly impact system "
252 "performance\n");
253 return 1;
254}
255
256__setup("irqpoll", irqpoll_setup);