2 * linux/kernel/irq/spurious.c
4 * Copyright (C) 1992, 1998-2004 Linus Torvalds, Ingo Molnar
6 * This file contains spurious interrupt handling.
9 #include <linux/jiffies.h>
10 #include <linux/irq.h>
11 #include <linux/module.h>
12 #include <linux/kallsyms.h>
13 #include <linux/interrupt.h>
14 #include <linux/moduleparam.h>
15 #include <linux/timer.h>
17 #ifdef CONFIG_X86_IO_APIC
18 # include <asm/apicdef.h>
19 # include <asm/io_apic.h>
22 static int irqfixup __read_mostly
;
24 #define POLL_SPURIOUS_IRQ_INTERVAL (HZ/10)
25 static void poll_spurious_irqs(unsigned long dummy
);
26 static DEFINE_TIMER(poll_spurious_irq_timer
, poll_spurious_irqs
, 0, 0);
29 * Recovery handler for misrouted interrupts.
31 static int try_one_irq(int irq
, struct irq_desc
*desc
)
33 struct irqaction
*action
;
36 spin_lock(&desc
->lock
);
37 /* Already running on another processor */
38 if (desc
->status
& IRQ_INPROGRESS
) {
40 * Already running: If it is shared get the other
41 * CPU to go looking for our mystery interrupt too
43 if (desc
->action
&& (desc
->action
->flags
& IRQF_SHARED
))
44 desc
->status
|= IRQ_PENDING
;
45 spin_unlock(&desc
->lock
);
48 /* Honour the normal IRQ locking */
49 desc
->status
|= IRQ_INPROGRESS
;
50 action
= desc
->action
;
51 spin_unlock(&desc
->lock
);
54 /* Only shared IRQ handlers are safe to call */
55 if (action
->flags
& IRQF_SHARED
) {
56 if (action
->handler(irq
, action
->dev_id
) ==
60 action
= action
->next
;
62 /* Now clean up the flags */
63 spin_lock_irq(&desc
->lock
);
64 action
= desc
->action
;
67 * While we were looking for a fixup someone queued a real
68 * IRQ clashing with our walk:
70 while ((desc
->status
& IRQ_PENDING
) && action
) {
72 * Perform real IRQ processing for the IRQ we deferred
75 spin_unlock(&desc
->lock
);
76 handle_IRQ_event(irq
, action
);
77 spin_lock(&desc
->lock
);
78 desc
->status
&= ~IRQ_PENDING
;
80 desc
->status
&= ~IRQ_INPROGRESS
;
82 * If we did actual work for the real IRQ line we must let the
83 * IRQ controller clean up too
85 if (work
&& desc
->chip
&& desc
->chip
->end
)
87 spin_unlock(&desc
->lock
);
92 static int misrouted_irq(int irq
)
94 struct irq_desc
*desc
;
97 for_each_irq_desc(i
, desc
) {
101 if (i
== irq
) /* Already tried */
104 if (try_one_irq(i
, desc
))
107 /* So the caller can adjust the irq error counts */
111 static void poll_all_shared_irqs(void)
113 struct irq_desc
*desc
;
116 for_each_irq_desc(i
, desc
) {
122 /* Racy but it doesn't matter */
123 status
= desc
->status
;
125 if (!(status
& IRQ_SPURIOUS_DISABLED
))
128 try_one_irq(i
, desc
);
132 static void poll_spurious_irqs(unsigned long dummy
)
134 poll_all_shared_irqs();
136 mod_timer(&poll_spurious_irq_timer
,
137 jiffies
+ POLL_SPURIOUS_IRQ_INTERVAL
);
140 #ifdef CONFIG_DEBUG_SHIRQ
141 void debug_poll_all_shared_irqs(void)
143 poll_all_shared_irqs();
148 * If 99,900 of the previous 100,000 interrupts have not been handled
149 * then assume that the IRQ is stuck in some manner. Drop a diagnostic
150 * and try to turn the IRQ off.
152 * (The other 100-of-100,000 interrupts may have been a correctly
153 * functioning device sharing an IRQ with the failing one)
155 * Called under desc->lock
159 __report_bad_irq(unsigned int irq
, struct irq_desc
*desc
,
160 irqreturn_t action_ret
)
162 struct irqaction
*action
;
164 if (action_ret
!= IRQ_HANDLED
&& action_ret
!= IRQ_NONE
) {
165 printk(KERN_ERR
"irq event %d: bogus return value %x\n",
168 printk(KERN_ERR
"irq %d: nobody cared (try booting with "
169 "the \"irqpoll\" option)\n", irq
);
172 printk(KERN_ERR
"handlers:\n");
174 action
= desc
->action
;
176 printk(KERN_ERR
"[<%p>]", action
->handler
);
177 print_symbol(" (%s)",
178 (unsigned long)action
->handler
);
180 action
= action
->next
;
185 report_bad_irq(unsigned int irq
, struct irq_desc
*desc
, irqreturn_t action_ret
)
187 static int count
= 100;
191 __report_bad_irq(irq
, desc
, action_ret
);
196 try_misrouted_irq(unsigned int irq
, struct irq_desc
*desc
,
197 irqreturn_t action_ret
)
199 struct irqaction
*action
;
204 /* We didn't actually handle the IRQ - see if it was misrouted? */
205 if (action_ret
== IRQ_NONE
)
209 * But for 'irqfixup == 2' we also do it for handled interrupts if
210 * they are marked as IRQF_IRQPOLL (or for irq zero, which is the
211 * traditional PC timer interrupt.. Legacy)
220 * Since we don't get the descriptor lock, "action" can
221 * change under us. We don't really care, but we don't
222 * want to follow a NULL pointer. So tell the compiler to
223 * just load it once by using a barrier.
225 action
= desc
->action
;
227 return action
&& (action
->flags
& IRQF_IRQPOLL
);
230 void note_interrupt(unsigned int irq
, struct irq_desc
*desc
,
231 irqreturn_t action_ret
)
233 if (unlikely(action_ret
!= IRQ_HANDLED
)) {
235 * If we are seeing only the odd spurious IRQ caused by
236 * bus asynchronicity then don't eventually trigger an error,
237 * otherwise the couter becomes a doomsday timer for otherwise
240 if (time_after(jiffies
, desc
->last_unhandled
+ HZ
/10))
241 desc
->irqs_unhandled
= 1;
243 desc
->irqs_unhandled
++;
244 desc
->last_unhandled
= jiffies
;
245 if (unlikely(action_ret
!= IRQ_NONE
))
246 report_bad_irq(irq
, desc
, action_ret
);
249 if (unlikely(try_misrouted_irq(irq
, desc
, action_ret
))) {
250 int ok
= misrouted_irq(irq
);
251 if (action_ret
== IRQ_NONE
)
252 desc
->irqs_unhandled
-= ok
;
256 if (likely(desc
->irq_count
< 100000))
260 if (unlikely(desc
->irqs_unhandled
> 99900)) {
262 * The interrupt is stuck
264 __report_bad_irq(irq
, desc
, action_ret
);
265 #ifdef CONFIG_X86_IO_APIC
268 printk(KERN_ERR
"turning off IO-APIC fast mode.\n");
274 printk(KERN_EMERG
"Disabling IRQ #%d\n", irq
);
275 desc
->status
|= IRQ_DISABLED
| IRQ_SPURIOUS_DISABLED
;
277 desc
->chip
->disable(irq
);
279 mod_timer(&poll_spurious_irq_timer
,
280 jiffies
+ POLL_SPURIOUS_IRQ_INTERVAL
);
283 desc
->irqs_unhandled
= 0;
286 int noirqdebug __read_mostly
;
288 int noirqdebug_setup(char *str
)
291 printk(KERN_INFO
"IRQ lockup detection disabled\n");
296 __setup("noirqdebug", noirqdebug_setup
);
297 module_param(noirqdebug
, bool, 0644);
298 MODULE_PARM_DESC(noirqdebug
, "Disable irq lockup detection when true");
300 static int __init
irqfixup_setup(char *str
)
302 #ifdef CONFIG_PREEMPT_RT
303 printk(KERN_WARNING
"irqfixup boot option not supported "
304 "w/ CONFIG_PREEMPT_RT\n");
308 printk(KERN_WARNING
"Misrouted IRQ fixup support enabled.\n");
309 printk(KERN_WARNING
"This may impact system performance.\n");
314 __setup("irqfixup", irqfixup_setup
);
315 module_param(irqfixup
, int, 0644);
316 MODULE_PARM_DESC("irqfixup", "0: No fixup, 1: irqfixup mode, 2: irqpoll mode");
318 static int __init
irqpoll_setup(char *str
)
320 #ifdef CONFIG_PREEMPT_RT
321 printk(KERN_WARNING
"irqpoll boot option not supported "
322 "w/ CONFIG_PREEMPT_RT\n");
326 printk(KERN_WARNING
"Misrouted IRQ fixup and polling support "
328 printk(KERN_WARNING
"This may significantly impact system "
333 __setup("irqpoll", irqpoll_setup
);