blob: 32b161972fad2cda220f3f4698e9fb565017b6a1 [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
9#include <linux/irq.h>
10#include <linux/module.h>
11#include <linux/kallsyms.h>
12#include <linux/interrupt.h>
13
Andreas Mohr83d4e6e2006-06-23 02:05:32 -070014static int irqfixup __read_mostly;
Alan Cox200803d2005-06-28 20:45:18 -070015
16/*
17 * Recovery handler for misrouted interrupts.
18 */
David Howells7d12e782006-10-05 14:55:46 +010019static int misrouted_irq(int irq)
Alan Cox200803d2005-06-28 20:45:18 -070020{
21 int i;
Alan Cox200803d2005-06-28 20:45:18 -070022 int ok = 0;
23 int work = 0; /* Did we do work for a real IRQ */
24
Ingo Molnar06fcb0c2006-06-29 02:24:40 -070025 for (i = 1; i < NR_IRQS; i++) {
26 struct irq_desc *desc = irq_desc + i;
Alan Cox200803d2005-06-28 20:45:18 -070027 struct irqaction *action;
28
29 if (i == irq) /* Already tried */
30 continue;
Ingo Molnar06fcb0c2006-06-29 02:24:40 -070031
Alan Cox200803d2005-06-28 20:45:18 -070032 spin_lock(&desc->lock);
Alan Cox200803d2005-06-28 20:45:18 -070033 /* 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 */
Thomas Gleixner3cca53b2006-07-01 19:29:31 -070039 if (desc->action && (desc->action->flags & IRQF_SHARED))
Alan Cox200803d2005-06-28 20:45:18 -070040 desc->status |= IRQ_PENDING;
41 spin_unlock(&desc->lock);
42 continue;
43 }
44 /* Honour the normal IRQ locking */
45 desc->status |= IRQ_INPROGRESS;
Ingo Molnar06fcb0c2006-06-29 02:24:40 -070046 action = desc->action;
Alan Cox200803d2005-06-28 20:45:18 -070047 spin_unlock(&desc->lock);
Ingo Molnar06fcb0c2006-06-29 02:24:40 -070048
Alan Cox200803d2005-06-28 20:45:18 -070049 while (action) {
50 /* Only shared IRQ handlers are safe to call */
Thomas Gleixner3cca53b2006-07-01 19:29:31 -070051 if (action->flags & IRQF_SHARED) {
David Howells7d12e782006-10-05 14:55:46 +010052 if (action->handler(i, action->dev_id) ==
Alan Cox200803d2005-06-28 20:45:18 -070053 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
Ingo Molnar06fcb0c2006-06-29 02:24:40 -070065 * IRQ clashing with our walk:
Alan Cox200803d2005-06-28 20:45:18 -070066 */
Alan Cox200803d2005-06-28 20:45:18 -070067 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);
David Howells7d12e782006-10-05 14:55:46 +010073 handle_IRQ_event(i, action);
Alan Cox200803d2005-06-28 20:45:18 -070074 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 */
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070082 if (work && desc->chip && desc->chip->end)
Ingo Molnard1bef4e2006-06-29 02:24:36 -070083 desc->chip->end(i);
Alan Cox200803d2005-06-28 20:45:18 -070084 spin_unlock(&desc->lock);
85 }
86 /* So the caller can adjust the irq error counts */
87 return ok;
88}
89
Linus Torvalds1da177e2005-04-16 15:20:36 -070090/*
91 * If 99,900 of the previous 100,000 interrupts have not been handled
92 * then assume that the IRQ is stuck in some manner. Drop a diagnostic
93 * and try to turn the IRQ off.
94 *
95 * (The other 100-of-100,000 interrupts may have been a correctly
96 * functioning device sharing an IRQ with the failing one)
97 *
98 * Called under desc->lock
99 */
100
101static void
Ingo Molnar34ffdb72006-06-29 02:24:40 -0700102__report_bad_irq(unsigned int irq, struct irq_desc *desc,
103 irqreturn_t action_ret)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104{
105 struct irqaction *action;
106
107 if (action_ret != IRQ_HANDLED && action_ret != IRQ_NONE) {
108 printk(KERN_ERR "irq event %d: bogus return value %x\n",
109 irq, action_ret);
110 } else {
Alan Cox200803d2005-06-28 20:45:18 -0700111 printk(KERN_ERR "irq %d: nobody cared (try booting with "
112 "the \"irqpoll\" option)\n", irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 }
114 dump_stack();
115 printk(KERN_ERR "handlers:\n");
Ingo Molnar06fcb0c2006-06-29 02:24:40 -0700116
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 action = desc->action;
118 while (action) {
119 printk(KERN_ERR "[<%p>]", action->handler);
120 print_symbol(" (%s)",
121 (unsigned long)action->handler);
122 printk("\n");
123 action = action->next;
124 }
125}
126
Ingo Molnar06fcb0c2006-06-29 02:24:40 -0700127static void
Ingo Molnar34ffdb72006-06-29 02:24:40 -0700128report_bad_irq(unsigned int irq, struct irq_desc *desc, irqreturn_t action_ret)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129{
130 static int count = 100;
131
132 if (count > 0) {
133 count--;
134 __report_bad_irq(irq, desc, action_ret);
135 }
136}
137
Linus Torvalds92ea7722007-05-24 08:37:14 -0700138static inline int try_misrouted_irq(unsigned int irq, struct irq_desc *desc, irqreturn_t action_ret)
139{
140 struct irqaction *action;
141
142 if (!irqfixup)
143 return 0;
144
145 /* We didn't actually handle the IRQ - see if it was misrouted? */
146 if (action_ret == IRQ_NONE)
147 return 1;
148
149 /*
150 * But for 'irqfixup == 2' we also do it for handled interrupts if
151 * they are marked as IRQF_IRQPOLL (or for irq zero, which is the
152 * traditional PC timer interrupt.. Legacy)
153 */
154 if (irqfixup < 2)
155 return 0;
156
157 if (!irq)
158 return 1;
159
160 /*
161 * Since we don't get the descriptor lock, "action" can
162 * change under us. We don't really care, but we don't
163 * want to follow a NULL pointer. So tell the compiler to
164 * just load it once by using a barrier.
165 */
166 action = desc->action;
167 barrier();
168 return action && (action->flags & IRQF_IRQPOLL);
169}
170
Ingo Molnar34ffdb72006-06-29 02:24:40 -0700171void note_interrupt(unsigned int irq, struct irq_desc *desc,
David Howells7d12e782006-10-05 14:55:46 +0100172 irqreturn_t action_ret)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173{
Andreas Mohr83d4e6e2006-06-23 02:05:32 -0700174 if (unlikely(action_ret != IRQ_HANDLED)) {
Alan Cox4f27c002007-07-15 23:40:55 -0700175 /*
176 * If we are seeing only the odd spurious IRQ caused by
177 * bus asynchronicity then don't eventually trigger an error,
178 * otherwise the couter becomes a doomsday timer for otherwise
179 * working systems
180 */
181 if (jiffies - desc->last_unhandled > HZ/10)
182 desc->irqs_unhandled = 1;
183 else
184 desc->irqs_unhandled++;
185 desc->last_unhandled = jiffies;
Andreas Mohr83d4e6e2006-06-23 02:05:32 -0700186 if (unlikely(action_ret != IRQ_NONE))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 report_bad_irq(irq, desc, action_ret);
188 }
189
Linus Torvalds92ea7722007-05-24 08:37:14 -0700190 if (unlikely(try_misrouted_irq(irq, desc, action_ret))) {
191 int ok = misrouted_irq(irq);
192 if (action_ret == IRQ_NONE)
193 desc->irqs_unhandled -= ok;
Alan Cox200803d2005-06-28 20:45:18 -0700194 }
195
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 desc->irq_count++;
Andreas Mohr83d4e6e2006-06-23 02:05:32 -0700197 if (likely(desc->irq_count < 100000))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 return;
199
200 desc->irq_count = 0;
Andreas Mohr83d4e6e2006-06-23 02:05:32 -0700201 if (unlikely(desc->irqs_unhandled > 99900)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 /*
203 * The interrupt is stuck
204 */
205 __report_bad_irq(irq, desc, action_ret);
206 /*
207 * Now kill the IRQ
208 */
209 printk(KERN_EMERG "Disabling IRQ #%d\n", irq);
210 desc->status |= IRQ_DISABLED;
Thomas Gleixner6a6de9e2006-06-29 02:24:51 -0700211 desc->depth = 1;
Ingo Molnard1bef4e2006-06-29 02:24:36 -0700212 desc->chip->disable(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 }
214 desc->irqs_unhandled = 0;
215}
216
Andreas Mohr83d4e6e2006-06-23 02:05:32 -0700217int noirqdebug __read_mostly;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218
Vivek Goyal343cde52007-01-11 01:52:44 +0100219int noirqdebug_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220{
221 noirqdebug = 1;
222 printk(KERN_INFO "IRQ lockup detection disabled\n");
Ingo Molnar06fcb0c2006-06-29 02:24:40 -0700223
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 return 1;
225}
226
227__setup("noirqdebug", noirqdebug_setup);
228
Alan Cox200803d2005-06-28 20:45:18 -0700229static int __init irqfixup_setup(char *str)
230{
231 irqfixup = 1;
232 printk(KERN_WARNING "Misrouted IRQ fixup support enabled.\n");
233 printk(KERN_WARNING "This may impact system performance.\n");
Ingo Molnar06fcb0c2006-06-29 02:24:40 -0700234
Alan Cox200803d2005-06-28 20:45:18 -0700235 return 1;
236}
237
238__setup("irqfixup", irqfixup_setup);
239
240static int __init irqpoll_setup(char *str)
241{
242 irqfixup = 2;
243 printk(KERN_WARNING "Misrouted IRQ fixup and polling support "
244 "enabled\n");
245 printk(KERN_WARNING "This may significantly impact system "
246 "performance\n");
247 return 1;
248}
249
250__setup("irqpoll", irqpoll_setup);