Commit | Line | Data |
---|---|---|
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> |
1da177e4 | 15 | |
83d4e6e7 | 16 | static int irqfixup __read_mostly; |
200803df AC |
17 | |
18 | /* | |
19 | * Recovery handler for misrouted interrupts. | |
20 | */ | |
7d12e780 | 21 | static int misrouted_irq(int irq) |
200803df AC |
22 | { |
23 | int i; | |
200803df AC |
24 | int ok = 0; |
25 | int work = 0; /* Did we do work for a real IRQ */ | |
26 | ||
06fcb0c6 IM |
27 | for (i = 1; i < NR_IRQS; i++) { |
28 | struct irq_desc *desc = irq_desc + i; | |
200803df AC |
29 | struct irqaction *action; |
30 | ||
31 | if (i == irq) /* Already tried */ | |
32 | continue; | |
06fcb0c6 | 33 | |
200803df | 34 | spin_lock(&desc->lock); |
200803df AC |
35 | /* 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 | */ | |
3cca53b0 | 41 | if (desc->action && (desc->action->flags & IRQF_SHARED)) |
200803df AC |
42 | desc->status |= IRQ_PENDING; |
43 | spin_unlock(&desc->lock); | |
44 | continue; | |
45 | } | |
46 | /* Honour the normal IRQ locking */ | |
47 | desc->status |= IRQ_INPROGRESS; | |
06fcb0c6 | 48 | action = desc->action; |
200803df | 49 | spin_unlock(&desc->lock); |
06fcb0c6 | 50 | |
200803df AC |
51 | while (action) { |
52 | /* Only shared IRQ handlers are safe to call */ | |
3cca53b0 | 53 | if (action->flags & IRQF_SHARED) { |
7d12e780 | 54 | if (action->handler(i, action->dev_id) == |
200803df AC |
55 | 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 | |
06fcb0c6 | 67 | * IRQ clashing with our walk: |
200803df | 68 | */ |
200803df AC |
69 | 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); | |
7d12e780 | 75 | handle_IRQ_event(i, action); |
200803df AC |
76 | 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 | */ | |
dd87eb3a | 84 | if (work && desc->chip && desc->chip->end) |
d1bef4ed | 85 | desc->chip->end(i); |
200803df AC |
86 | spin_unlock(&desc->lock); |
87 | } | |
88 | /* So the caller can adjust the irq error counts */ | |
89 | return ok; | |
90 | } | |
91 | ||
1da177e4 LT |
92 | /* |
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 | ||
103 | static void | |
34ffdb72 IM |
104 | __report_bad_irq(unsigned int irq, struct irq_desc *desc, |
105 | irqreturn_t action_ret) | |
1da177e4 LT |
106 | { |
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 { | |
200803df AC |
113 | printk(KERN_ERR "irq %d: nobody cared (try booting with " |
114 | "the \"irqpoll\" option)\n", irq); | |
1da177e4 LT |
115 | } |
116 | dump_stack(); | |
117 | printk(KERN_ERR "handlers:\n"); | |
06fcb0c6 | 118 | |
1da177e4 LT |
119 | 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 | ||
06fcb0c6 | 129 | static void |
34ffdb72 | 130 | report_bad_irq(unsigned int irq, struct irq_desc *desc, irqreturn_t action_ret) |
1da177e4 LT |
131 | { |
132 | static int count = 100; | |
133 | ||
134 | if (count > 0) { | |
135 | count--; | |
136 | __report_bad_irq(irq, desc, action_ret); | |
137 | } | |
138 | } | |
139 | ||
92ea7727 LT |
140 | static 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 | ||
34ffdb72 | 173 | void note_interrupt(unsigned int irq, struct irq_desc *desc, |
7d12e780 | 174 | irqreturn_t action_ret) |
1da177e4 | 175 | { |
83d4e6e7 | 176 | if (unlikely(action_ret != IRQ_HANDLED)) { |
4f27c00b AC |
177 | /* |
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 | */ | |
188fd89d | 183 | if (time_after(jiffies, desc->last_unhandled + HZ/10)) |
4f27c00b AC |
184 | desc->irqs_unhandled = 1; |
185 | else | |
186 | desc->irqs_unhandled++; | |
187 | desc->last_unhandled = jiffies; | |
83d4e6e7 | 188 | if (unlikely(action_ret != IRQ_NONE)) |
1da177e4 LT |
189 | report_bad_irq(irq, desc, action_ret); |
190 | } | |
191 | ||
92ea7727 LT |
192 | 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; | |
200803df AC |
196 | } |
197 | ||
1da177e4 | 198 | desc->irq_count++; |
83d4e6e7 | 199 | if (likely(desc->irq_count < 100000)) |
1da177e4 LT |
200 | return; |
201 | ||
202 | desc->irq_count = 0; | |
83d4e6e7 | 203 | if (unlikely(desc->irqs_unhandled > 99900)) { |
1da177e4 LT |
204 | /* |
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); | |
212 | desc->status |= IRQ_DISABLED; | |
6a6de9ef | 213 | desc->depth = 1; |
d1bef4ed | 214 | desc->chip->disable(irq); |
1da177e4 LT |
215 | } |
216 | desc->irqs_unhandled = 0; | |
217 | } | |
218 | ||
83d4e6e7 | 219 | int noirqdebug __read_mostly; |
1da177e4 | 220 | |
343cde51 | 221 | int noirqdebug_setup(char *str) |
1da177e4 LT |
222 | { |
223 | noirqdebug = 1; | |
224 | printk(KERN_INFO "IRQ lockup detection disabled\n"); | |
06fcb0c6 | 225 | |
1da177e4 LT |
226 | return 1; |
227 | } | |
228 | ||
229 | __setup("noirqdebug", noirqdebug_setup); | |
9e094c17 AK |
230 | module_param(noirqdebug, bool, 0644); |
231 | MODULE_PARM_DESC(noirqdebug, "Disable irq lockup detection when true"); | |
1da177e4 | 232 | |
200803df AC |
233 | static 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"); | |
06fcb0c6 | 238 | |
200803df AC |
239 | return 1; |
240 | } | |
241 | ||
242 | __setup("irqfixup", irqfixup_setup); | |
9e094c17 AK |
243 | module_param(irqfixup, int, 0644); |
244 | MODULE_PARM_DESC("irqfixup", "0: No fixup, 1: irqfixup mode 2: irqpoll mode"); | |
200803df AC |
245 | |
246 | static 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); |