sparse irq_desc[] array: core kernel and x86 changes
[deliverable/linux.git] / kernel / irq / spurious.c
CommitLineData
1da177e4
LT
1/*
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
188fd89d 9#include <linux/jiffies.h>
1da177e4
LT
10#include <linux/irq.h>
11#include <linux/module.h>
12#include <linux/kallsyms.h>
13#include <linux/interrupt.h>
9e094c17 14#include <linux/moduleparam.h>
f84dbb91 15#include <linux/timer.h>
1da177e4 16
83d4e6e7 17static int irqfixup __read_mostly;
200803df 18
f84dbb91
EB
19#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
200803df
AC
23/*
24 * Recovery handler for misrouted interrupts.
25 */
f84dbb91 26static int try_one_irq(int irq, struct irq_desc *desc)
200803df 27{
f84dbb91 28 struct irqaction *action;
d3c60047 29 int ok = 0, work = 0;
200803df 30
f84dbb91
EB
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;
200803df 40 spin_unlock(&desc->lock);
f84dbb91
EB
41 return ok;
42 }
43 /* Honour the normal IRQ locking */
44 desc->status |= IRQ_INPROGRESS;
45 action = desc->action;
46 spin_unlock(&desc->lock);
06fcb0c6 47
f84dbb91
EB
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;
200803df 54 }
f84dbb91
EB
55 action = action->next;
56 }
57 local_irq_disable();
58 /* Now clean up the flags */
59 spin_lock(&desc->lock);
60 action = desc->action;
200803df 61
f84dbb91
EB
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) {
200803df 67 /*
f84dbb91 68 * Perform real IRQ processing for the IRQ we deferred
200803df 69 */
f84dbb91 70 work = 1;
200803df 71 spin_unlock(&desc->lock);
f84dbb91
EB
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
88static int misrouted_irq(int irq)
89{
e00585bb 90 struct irq_desc *desc;
d3c60047 91 int i, ok = 0;
f84dbb91 92
e00585bb 93 for_each_irq_desc(i, desc) {
0b8f1efa
YL
94 if (!desc)
95 continue;
96
e00585bb
YL
97 if (!i)
98 continue;
f84dbb91
EB
99
100 if (i == irq) /* Already tried */
101 continue;
102
103 if (try_one_irq(i, desc))
104 ok = 1;
200803df
AC
105 }
106 /* So the caller can adjust the irq error counts */
107 return ok;
108}
109
f84dbb91
EB
110static void poll_spurious_irqs(unsigned long dummy)
111{
e00585bb 112 struct irq_desc *desc;
d3c60047 113 int i;
e00585bb
YL
114
115 for_each_irq_desc(i, desc) {
f84dbb91
EB
116 unsigned int status;
117
0b8f1efa
YL
118 if (!desc)
119 continue;
e00585bb
YL
120 if (!i)
121 continue;
122
f84dbb91
EB
123 /* Racy but it doesn't matter */
124 status = desc->status;
125 barrier();
126 if (!(status & IRQ_SPURIOUS_DISABLED))
127 continue;
128
129 try_one_irq(i, desc);
130 }
131
d3c60047
TG
132 mod_timer(&poll_spurious_irq_timer,
133 jiffies + POLL_SPURIOUS_IRQ_INTERVAL);
f84dbb91
EB
134}
135
1da177e4
LT
136/*
137 * If 99,900 of the previous 100,000 interrupts have not been handled
138 * then assume that the IRQ is stuck in some manner. Drop a diagnostic
139 * and try to turn the IRQ off.
140 *
141 * (The other 100-of-100,000 interrupts may have been a correctly
142 * functioning device sharing an IRQ with the failing one)
143 *
144 * Called under desc->lock
145 */
146
147static void
34ffdb72
IM
148__report_bad_irq(unsigned int irq, struct irq_desc *desc,
149 irqreturn_t action_ret)
1da177e4
LT
150{
151 struct irqaction *action;
152
153 if (action_ret != IRQ_HANDLED && action_ret != IRQ_NONE) {
154 printk(KERN_ERR "irq event %d: bogus return value %x\n",
155 irq, action_ret);
156 } else {
200803df
AC
157 printk(KERN_ERR "irq %d: nobody cared (try booting with "
158 "the \"irqpoll\" option)\n", irq);
1da177e4
LT
159 }
160 dump_stack();
161 printk(KERN_ERR "handlers:\n");
06fcb0c6 162
1da177e4
LT
163 action = desc->action;
164 while (action) {
165 printk(KERN_ERR "[<%p>]", action->handler);
166 print_symbol(" (%s)",
167 (unsigned long)action->handler);
168 printk("\n");
169 action = action->next;
170 }
171}
172
06fcb0c6 173static void
34ffdb72 174report_bad_irq(unsigned int irq, struct irq_desc *desc, irqreturn_t action_ret)
1da177e4
LT
175{
176 static int count = 100;
177
178 if (count > 0) {
179 count--;
180 __report_bad_irq(irq, desc, action_ret);
181 }
182}
183
d3c60047
TG
184static inline int
185try_misrouted_irq(unsigned int irq, struct irq_desc *desc,
186 irqreturn_t action_ret)
92ea7727
LT
187{
188 struct irqaction *action;
189
190 if (!irqfixup)
191 return 0;
192
193 /* We didn't actually handle the IRQ - see if it was misrouted? */
194 if (action_ret == IRQ_NONE)
195 return 1;
196
197 /*
198 * But for 'irqfixup == 2' we also do it for handled interrupts if
199 * they are marked as IRQF_IRQPOLL (or for irq zero, which is the
200 * traditional PC timer interrupt.. Legacy)
201 */
202 if (irqfixup < 2)
203 return 0;
204
205 if (!irq)
206 return 1;
207
208 /*
209 * Since we don't get the descriptor lock, "action" can
210 * change under us. We don't really care, but we don't
211 * want to follow a NULL pointer. So tell the compiler to
212 * just load it once by using a barrier.
213 */
214 action = desc->action;
215 barrier();
216 return action && (action->flags & IRQF_IRQPOLL);
217}
218
34ffdb72 219void note_interrupt(unsigned int irq, struct irq_desc *desc,
7d12e780 220 irqreturn_t action_ret)
1da177e4 221{
83d4e6e7 222 if (unlikely(action_ret != IRQ_HANDLED)) {
4f27c00b
AC
223 /*
224 * If we are seeing only the odd spurious IRQ caused by
225 * bus asynchronicity then don't eventually trigger an error,
226 * otherwise the couter becomes a doomsday timer for otherwise
227 * working systems
228 */
188fd89d 229 if (time_after(jiffies, desc->last_unhandled + HZ/10))
4f27c00b
AC
230 desc->irqs_unhandled = 1;
231 else
232 desc->irqs_unhandled++;
233 desc->last_unhandled = jiffies;
83d4e6e7 234 if (unlikely(action_ret != IRQ_NONE))
1da177e4
LT
235 report_bad_irq(irq, desc, action_ret);
236 }
237
92ea7727
LT
238 if (unlikely(try_misrouted_irq(irq, desc, action_ret))) {
239 int ok = misrouted_irq(irq);
240 if (action_ret == IRQ_NONE)
241 desc->irqs_unhandled -= ok;
200803df
AC
242 }
243
1da177e4 244 desc->irq_count++;
83d4e6e7 245 if (likely(desc->irq_count < 100000))
1da177e4
LT
246 return;
247
248 desc->irq_count = 0;
83d4e6e7 249 if (unlikely(desc->irqs_unhandled > 99900)) {
1da177e4
LT
250 /*
251 * The interrupt is stuck
252 */
253 __report_bad_irq(irq, desc, action_ret);
254 /*
255 * Now kill the IRQ
256 */
257 printk(KERN_EMERG "Disabling IRQ #%d\n", irq);
1adb0850
TG
258 desc->status |= IRQ_DISABLED | IRQ_SPURIOUS_DISABLED;
259 desc->depth++;
d1bef4ed 260 desc->chip->disable(irq);
f84dbb91 261
d3c60047
TG
262 mod_timer(&poll_spurious_irq_timer,
263 jiffies + POLL_SPURIOUS_IRQ_INTERVAL);
1da177e4
LT
264 }
265 desc->irqs_unhandled = 0;
266}
267
83d4e6e7 268int noirqdebug __read_mostly;
1da177e4 269
343cde51 270int noirqdebug_setup(char *str)
1da177e4
LT
271{
272 noirqdebug = 1;
273 printk(KERN_INFO "IRQ lockup detection disabled\n");
06fcb0c6 274
1da177e4
LT
275 return 1;
276}
277
278__setup("noirqdebug", noirqdebug_setup);
9e094c17
AK
279module_param(noirqdebug, bool, 0644);
280MODULE_PARM_DESC(noirqdebug, "Disable irq lockup detection when true");
1da177e4 281
200803df
AC
282static int __init irqfixup_setup(char *str)
283{
284 irqfixup = 1;
285 printk(KERN_WARNING "Misrouted IRQ fixup support enabled.\n");
286 printk(KERN_WARNING "This may impact system performance.\n");
06fcb0c6 287
200803df
AC
288 return 1;
289}
290
291__setup("irqfixup", irqfixup_setup);
9e094c17 292module_param(irqfixup, int, 0644);
e00585bb 293MODULE_PARM_DESC("irqfixup", "0: No fixup, 1: irqfixup mode, 2: irqpoll mode");
200803df
AC
294
295static int __init irqpoll_setup(char *str)
296{
297 irqfixup = 2;
298 printk(KERN_WARNING "Misrouted IRQ fixup and polling support "
299 "enabled\n");
300 printk(KERN_WARNING "This may significantly impact system "
301 "performance\n");
302 return 1;
303}
304
305__setup("irqpoll", irqpoll_setup);
This page took 0.370363 seconds and 5 git commands to generate.