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