blob: a6b2bc831dd05be5ee9cbff347566bf410870c26 [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>
Andi Kleen9e094c12008-01-30 13:32:48 +010013#include <linux/moduleparam.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014
Andreas Mohr83d4e6e2006-06-23 02:05:32 -070015static int irqfixup __read_mostly;
Alan Cox200803d2005-06-28 20:45:18 -070016
17/*
18 * Recovery handler for misrouted interrupts.
19 */
David Howells7d12e782006-10-05 14:55:46 +010020static int misrouted_irq(int irq)
Alan Cox200803d2005-06-28 20:45:18 -070021{
22 int i;
Alan Cox200803d2005-06-28 20:45:18 -070023 int ok = 0;
24 int work = 0; /* Did we do work for a real IRQ */
25
Ingo Molnar06fcb0c2006-06-29 02:24:40 -070026 for (i = 1; i < NR_IRQS; i++) {
27 struct irq_desc *desc = irq_desc + i;
Alan Cox200803d2005-06-28 20:45:18 -070028 struct irqaction *action;
29
30 if (i == irq) /* Already tried */
31 continue;
Ingo Molnar06fcb0c2006-06-29 02:24:40 -070032
Alan Cox200803d2005-06-28 20:45:18 -070033 spin_lock(&desc->lock);
Alan Cox200803d2005-06-28 20:45:18 -070034 /* Already running on another processor */
35 if (desc->status & IRQ_INPROGRESS) {
36 /*
37 * Already running: If it is shared get the other
38 * CPU to go looking for our mystery interrupt too
39 */
Thomas Gleixner3cca53b2006-07-01 19:29:31 -070040 if (desc->action && (desc->action->flags & IRQF_SHARED))
Alan Cox200803d2005-06-28 20:45:18 -070041 desc->status |= IRQ_PENDING;
42 spin_unlock(&desc->lock);
43 continue;
44 }
45 /* Honour the normal IRQ locking */
46 desc->status |= IRQ_INPROGRESS;
Ingo Molnar06fcb0c2006-06-29 02:24:40 -070047 action = desc->action;
Alan Cox200803d2005-06-28 20:45:18 -070048 spin_unlock(&desc->lock);
Ingo Molnar06fcb0c2006-06-29 02:24:40 -070049
Alan Cox200803d2005-06-28 20:45:18 -070050 while (action) {
51 /* Only shared IRQ handlers are safe to call */
Thomas Gleixner3cca53b2006-07-01 19:29:31 -070052 if (action->flags & IRQF_SHARED) {
David Howells7d12e782006-10-05 14:55:46 +010053 if (action->handler(i, action->dev_id) ==
Alan Cox200803d2005-06-28 20:45:18 -070054 IRQ_HANDLED)
55 ok = 1;
56 }
57 action = action->next;
58 }
59 local_irq_disable();
60 /* Now clean up the flags */
61 spin_lock(&desc->lock);
62 action = desc->action;
63
64 /*
65 * While we were looking for a fixup someone queued a real
Ingo Molnar06fcb0c2006-06-29 02:24:40 -070066 * IRQ clashing with our walk:
Alan Cox200803d2005-06-28 20:45:18 -070067 */
Alan Cox200803d2005-06-28 20:45:18 -070068 while ((desc->status & IRQ_PENDING) && action) {
69 /*
70 * Perform real IRQ processing for the IRQ we deferred
71 */
72 work = 1;
73 spin_unlock(&desc->lock);
David Howells7d12e782006-10-05 14:55:46 +010074 handle_IRQ_event(i, action);
Alan Cox200803d2005-06-28 20:45:18 -070075 spin_lock(&desc->lock);
76 desc->status &= ~IRQ_PENDING;
77 }
78 desc->status &= ~IRQ_INPROGRESS;
79 /*
80 * If we did actual work for the real IRQ line we must let the
81 * IRQ controller clean up too
82 */
Thomas Gleixnerdd87eb32006-06-29 02:24:53 -070083 if (work && desc->chip && desc->chip->end)
Ingo Molnard1bef4e2006-06-29 02:24:36 -070084 desc->chip->end(i);
Alan Cox200803d2005-06-28 20:45:18 -070085 spin_unlock(&desc->lock);
86 }
87 /* So the caller can adjust the irq error counts */
88 return ok;
89}
90
Linus Torvalds1da177e2005-04-16 15:20:36 -070091/*
92 * If 99,900 of the previous 100,000 interrupts have not been handled
93 * then assume that the IRQ is stuck in some manner. Drop a diagnostic
94 * and try to turn the IRQ off.
95 *
96 * (The other 100-of-100,000 interrupts may have been a correctly
97 * functioning device sharing an IRQ with the failing one)
98 *
99 * Called under desc->lock
100 */
101
102static void
Ingo Molnar34ffdb72006-06-29 02:24:40 -0700103__report_bad_irq(unsigned int irq, struct irq_desc *desc,
104 irqreturn_t action_ret)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105{
106 struct irqaction *action;
107
108 if (action_ret != IRQ_HANDLED && action_ret != IRQ_NONE) {
109 printk(KERN_ERR "irq event %d: bogus return value %x\n",
110 irq, action_ret);
111 } else {
Alan Cox200803d2005-06-28 20:45:18 -0700112 printk(KERN_ERR "irq %d: nobody cared (try booting with "
113 "the \"irqpoll\" option)\n", irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 }
115 dump_stack();
116 printk(KERN_ERR "handlers:\n");
Ingo Molnar06fcb0c2006-06-29 02:24:40 -0700117
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 action = desc->action;
119 while (action) {
120 printk(KERN_ERR "[<%p>]", action->handler);
121 print_symbol(" (%s)",
122 (unsigned long)action->handler);
123 printk("\n");
124 action = action->next;
125 }
126}
127
Ingo Molnar06fcb0c2006-06-29 02:24:40 -0700128static void
Ingo Molnar34ffdb72006-06-29 02:24:40 -0700129report_bad_irq(unsigned int irq, struct irq_desc *desc, irqreturn_t action_ret)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130{
131 static int count = 100;
132
133 if (count > 0) {
134 count--;
135 __report_bad_irq(irq, desc, action_ret);
136 }
137}
138
Linus Torvalds92ea7722007-05-24 08:37:14 -0700139static inline int try_misrouted_irq(unsigned int irq, struct irq_desc *desc, irqreturn_t action_ret)
140{
141 struct irqaction *action;
142
143 if (!irqfixup)
144 return 0;
145
146 /* We didn't actually handle the IRQ - see if it was misrouted? */
147 if (action_ret == IRQ_NONE)
148 return 1;
149
150 /*
151 * But for 'irqfixup == 2' we also do it for handled interrupts if
152 * they are marked as IRQF_IRQPOLL (or for irq zero, which is the
153 * traditional PC timer interrupt.. Legacy)
154 */
155 if (irqfixup < 2)
156 return 0;
157
158 if (!irq)
159 return 1;
160
161 /*
162 * Since we don't get the descriptor lock, "action" can
163 * change under us. We don't really care, but we don't
164 * want to follow a NULL pointer. So tell the compiler to
165 * just load it once by using a barrier.
166 */
167 action = desc->action;
168 barrier();
169 return action && (action->flags & IRQF_IRQPOLL);
170}
171
Ingo Molnar34ffdb72006-06-29 02:24:40 -0700172void note_interrupt(unsigned int irq, struct irq_desc *desc,
David Howells7d12e782006-10-05 14:55:46 +0100173 irqreturn_t action_ret)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174{
Andreas Mohr83d4e6e2006-06-23 02:05:32 -0700175 if (unlikely(action_ret != IRQ_HANDLED)) {
Alan Cox4f27c002007-07-15 23:40:55 -0700176 /*
177 * If we are seeing only the odd spurious IRQ caused by
178 * bus asynchronicity then don't eventually trigger an error,
179 * otherwise the couter becomes a doomsday timer for otherwise
180 * working systems
181 */
182 if (jiffies - desc->last_unhandled > HZ/10)
183 desc->irqs_unhandled = 1;
184 else
185 desc->irqs_unhandled++;
186 desc->last_unhandled = jiffies;
Andreas Mohr83d4e6e2006-06-23 02:05:32 -0700187 if (unlikely(action_ret != IRQ_NONE))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 report_bad_irq(irq, desc, action_ret);
189 }
190
Linus Torvalds92ea7722007-05-24 08:37:14 -0700191 if (unlikely(try_misrouted_irq(irq, desc, action_ret))) {
192 int ok = misrouted_irq(irq);
193 if (action_ret == IRQ_NONE)
194 desc->irqs_unhandled -= ok;
Alan Cox200803d2005-06-28 20:45:18 -0700195 }
196
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 desc->irq_count++;
Andreas Mohr83d4e6e2006-06-23 02:05:32 -0700198 if (likely(desc->irq_count < 100000))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 return;
200
201 desc->irq_count = 0;
Andreas Mohr83d4e6e2006-06-23 02:05:32 -0700202 if (unlikely(desc->irqs_unhandled > 99900)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 /*
204 * The interrupt is stuck
205 */
206 __report_bad_irq(irq, desc, action_ret);
207 /*
208 * Now kill the IRQ
209 */
210 printk(KERN_EMERG "Disabling IRQ #%d\n", irq);
211 desc->status |= IRQ_DISABLED;
Thomas Gleixner6a6de9e2006-06-29 02:24:51 -0700212 desc->depth = 1;
Ingo Molnard1bef4e2006-06-29 02:24:36 -0700213 desc->chip->disable(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 }
215 desc->irqs_unhandled = 0;
216}
217
Andreas Mohr83d4e6e2006-06-23 02:05:32 -0700218int noirqdebug __read_mostly;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219
Vivek Goyal343cde52007-01-11 01:52:44 +0100220int noirqdebug_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221{
222 noirqdebug = 1;
223 printk(KERN_INFO "IRQ lockup detection disabled\n");
Ingo Molnar06fcb0c2006-06-29 02:24:40 -0700224
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 return 1;
226}
227
228__setup("noirqdebug", noirqdebug_setup);
Andi Kleen9e094c12008-01-30 13:32:48 +0100229module_param(noirqdebug, bool, 0644);
230MODULE_PARM_DESC(noirqdebug, "Disable irq lockup detection when true");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231
Alan Cox200803d2005-06-28 20:45:18 -0700232static int __init irqfixup_setup(char *str)
233{
234 irqfixup = 1;
235 printk(KERN_WARNING "Misrouted IRQ fixup support enabled.\n");
236 printk(KERN_WARNING "This may impact system performance.\n");
Ingo Molnar06fcb0c2006-06-29 02:24:40 -0700237
Alan Cox200803d2005-06-28 20:45:18 -0700238 return 1;
239}
240
241__setup("irqfixup", irqfixup_setup);
Andi Kleen9e094c12008-01-30 13:32:48 +0100242module_param(irqfixup, int, 0644);
243MODULE_PARM_DESC("irqfixup", "0: No fixup, 1: irqfixup mode 2: irqpoll mode");
Alan Cox200803d2005-06-28 20:45:18 -0700244
245static int __init irqpoll_setup(char *str)
246{
247 irqfixup = 2;
248 printk(KERN_WARNING "Misrouted IRQ fixup and polling support "
249 "enabled\n");
250 printk(KERN_WARNING "This may significantly impact system "
251 "performance\n");
252 return 1;
253}
254
255__setup("irqpoll", irqpoll_setup);