2 * linux/kernel/irq/spurious.c
4 * Copyright (C) 1992, 1998-2004 Linus Torvalds, Ingo Molnar
6 * This file contains spurious interrupt handling.
10 #include <linux/module.h>
11 #include <linux/kallsyms.h>
12 #include <linux/interrupt.h>
14 static int irqfixup __read_mostly
;
17 * Recovery handler for misrouted interrupts.
19 static int misrouted_irq(int irq
)
23 int work
= 0; /* Did we do work for a real IRQ */
25 for (i
= 1; i
< NR_IRQS
; i
++) {
26 struct irq_desc
*desc
= irq_desc
+ i
;
27 struct irqaction
*action
;
29 if (i
== irq
) /* Already tried */
32 spin_lock(&desc
->lock
);
33 /* Already running on another processor */
34 if (desc
->status
& IRQ_INPROGRESS
) {
36 * Already running: If it is shared get the other
37 * CPU to go looking for our mystery interrupt too
39 if (desc
->action
&& (desc
->action
->flags
& IRQF_SHARED
))
40 desc
->status
|= IRQ_PENDING
;
41 spin_unlock(&desc
->lock
);
44 /* Honour the normal IRQ locking */
45 desc
->status
|= IRQ_INPROGRESS
;
46 action
= desc
->action
;
47 spin_unlock(&desc
->lock
);
50 /* Only shared IRQ handlers are safe to call */
51 if (action
->flags
& IRQF_SHARED
) {
52 if (action
->handler(i
, action
->dev_id
) ==
56 action
= action
->next
;
59 /* Now clean up the flags */
60 spin_lock(&desc
->lock
);
61 action
= desc
->action
;
64 * While we were looking for a fixup someone queued a real
65 * IRQ clashing with our walk:
67 while ((desc
->status
& IRQ_PENDING
) && action
) {
69 * Perform real IRQ processing for the IRQ we deferred
72 spin_unlock(&desc
->lock
);
73 handle_IRQ_event(i
, action
);
74 spin_lock(&desc
->lock
);
75 desc
->status
&= ~IRQ_PENDING
;
77 desc
->status
&= ~IRQ_INPROGRESS
;
79 * If we did actual work for the real IRQ line we must let the
80 * IRQ controller clean up too
82 if (work
&& desc
->chip
&& desc
->chip
->end
)
84 spin_unlock(&desc
->lock
);
86 /* So the caller can adjust the irq error counts */
91 * If 99,900 of the previous 100,000 interrupts have not been handled
92 * then assume that the IRQ is stuck in some manner. Drop a diagnostic
93 * and try to turn the IRQ off.
95 * (The other 100-of-100,000 interrupts may have been a correctly
96 * functioning device sharing an IRQ with the failing one)
98 * Called under desc->lock
102 __report_bad_irq(unsigned int irq
, struct irq_desc
*desc
,
103 irqreturn_t action_ret
)
105 struct irqaction
*action
;
107 if (action_ret
!= IRQ_HANDLED
&& action_ret
!= IRQ_NONE
) {
108 printk(KERN_ERR
"irq event %d: bogus return value %x\n",
111 printk(KERN_ERR
"irq %d: nobody cared (try booting with "
112 "the \"irqpoll\" option)\n", irq
);
115 printk(KERN_ERR
"handlers:\n");
117 action
= desc
->action
;
119 printk(KERN_ERR
"[<%p>]", action
->handler
);
120 print_symbol(" (%s)",
121 (unsigned long)action
->handler
);
123 action
= action
->next
;
128 report_bad_irq(unsigned int irq
, struct irq_desc
*desc
, irqreturn_t action_ret
)
130 static int count
= 100;
134 __report_bad_irq(irq
, desc
, action_ret
);
138 static inline int try_misrouted_irq(unsigned int irq
, struct irq_desc
*desc
, irqreturn_t action_ret
)
140 struct irqaction
*action
;
145 /* We didn't actually handle the IRQ - see if it was misrouted? */
146 if (action_ret
== IRQ_NONE
)
150 * But for 'irqfixup == 2' we also do it for handled interrupts if
151 * they are marked as IRQF_IRQPOLL (or for irq zero, which is the
152 * traditional PC timer interrupt.. Legacy)
161 * Since we don't get the descriptor lock, "action" can
162 * change under us. We don't really care, but we don't
163 * want to follow a NULL pointer. So tell the compiler to
164 * just load it once by using a barrier.
166 action
= desc
->action
;
168 return action
&& (action
->flags
& IRQF_IRQPOLL
);
171 void note_interrupt(unsigned int irq
, struct irq_desc
*desc
,
172 irqreturn_t action_ret
)
174 if (unlikely(action_ret
!= IRQ_HANDLED
)) {
175 desc
->irqs_unhandled
++;
176 if (unlikely(action_ret
!= IRQ_NONE
))
177 report_bad_irq(irq
, desc
, action_ret
);
180 if (unlikely(try_misrouted_irq(irq
, desc
, action_ret
))) {
181 int ok
= misrouted_irq(irq
);
182 if (action_ret
== IRQ_NONE
)
183 desc
->irqs_unhandled
-= ok
;
187 if (likely(desc
->irq_count
< 100000))
191 if (unlikely(desc
->irqs_unhandled
> 99900)) {
193 * The interrupt is stuck
195 __report_bad_irq(irq
, desc
, action_ret
);
199 printk(KERN_EMERG
"Disabling IRQ #%d\n", irq
);
200 desc
->status
|= IRQ_DISABLED
;
202 desc
->chip
->disable(irq
);
204 desc
->irqs_unhandled
= 0;
207 int noirqdebug __read_mostly
;
209 int noirqdebug_setup(char *str
)
212 printk(KERN_INFO
"IRQ lockup detection disabled\n");
217 __setup("noirqdebug", noirqdebug_setup
);
219 static int __init
irqfixup_setup(char *str
)
222 printk(KERN_WARNING
"Misrouted IRQ fixup support enabled.\n");
223 printk(KERN_WARNING
"This may impact system performance.\n");
228 __setup("irqfixup", irqfixup_setup
);
230 static int __init
irqpoll_setup(char *str
)
233 printk(KERN_WARNING
"Misrouted IRQ fixup and polling support "
235 printk(KERN_WARNING
"This may significantly impact system "
240 __setup("irqpoll", irqpoll_setup
);