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>
16 static int irqfixup __read_mostly
;
19 * Recovery handler for misrouted interrupts.
21 static int misrouted_irq(int irq
)
25 int work
= 0; /* Did we do work for a real IRQ */
27 for (i
= 1; i
< NR_IRQS
; i
++) {
28 struct irq_desc
*desc
= irq_desc
+ i
;
29 struct irqaction
*action
;
31 if (i
== irq
) /* Already tried */
34 spin_lock(&desc
->lock
);
35 /* Already running on another processor */
36 if (desc
->status
& IRQ_INPROGRESS
) {
38 * Already running: If it is shared get the other
39 * CPU to go looking for our mystery interrupt too
41 if (desc
->action
&& (desc
->action
->flags
& IRQF_SHARED
))
42 desc
->status
|= IRQ_PENDING
;
43 spin_unlock(&desc
->lock
);
46 /* Honour the normal IRQ locking */
47 desc
->status
|= IRQ_INPROGRESS
;
48 action
= desc
->action
;
49 spin_unlock(&desc
->lock
);
52 /* Only shared IRQ handlers are safe to call */
53 if (action
->flags
& IRQF_SHARED
) {
54 if (action
->handler(i
, action
->dev_id
) ==
58 action
= action
->next
;
61 /* Now clean up the flags */
62 spin_lock(&desc
->lock
);
63 action
= desc
->action
;
66 * While we were looking for a fixup someone queued a real
67 * IRQ clashing with our walk:
69 while ((desc
->status
& IRQ_PENDING
) && action
) {
71 * Perform real IRQ processing for the IRQ we deferred
74 spin_unlock(&desc
->lock
);
75 handle_IRQ_event(i
, action
);
76 spin_lock(&desc
->lock
);
77 desc
->status
&= ~IRQ_PENDING
;
79 desc
->status
&= ~IRQ_INPROGRESS
;
81 * If we did actual work for the real IRQ line we must let the
82 * IRQ controller clean up too
84 if (work
&& desc
->chip
&& desc
->chip
->end
)
86 spin_unlock(&desc
->lock
);
88 /* So the caller can adjust the irq error counts */
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.
97 * (The other 100-of-100,000 interrupts may have been a correctly
98 * functioning device sharing an IRQ with the failing one)
100 * Called under desc->lock
104 __report_bad_irq(unsigned int irq
, struct irq_desc
*desc
,
105 irqreturn_t action_ret
)
107 struct irqaction
*action
;
109 if (action_ret
!= IRQ_HANDLED
&& action_ret
!= IRQ_NONE
) {
110 printk(KERN_ERR
"irq event %d: bogus return value %x\n",
113 printk(KERN_ERR
"irq %d: nobody cared (try booting with "
114 "the \"irqpoll\" option)\n", irq
);
117 printk(KERN_ERR
"handlers:\n");
119 action
= desc
->action
;
121 printk(KERN_ERR
"[<%p>]", action
->handler
);
122 print_symbol(" (%s)",
123 (unsigned long)action
->handler
);
125 action
= action
->next
;
130 report_bad_irq(unsigned int irq
, struct irq_desc
*desc
, irqreturn_t action_ret
)
132 static int count
= 100;
136 __report_bad_irq(irq
, desc
, action_ret
);
140 static inline int try_misrouted_irq(unsigned int irq
, struct irq_desc
*desc
, irqreturn_t action_ret
)
142 struct irqaction
*action
;
147 /* We didn't actually handle the IRQ - see if it was misrouted? */
148 if (action_ret
== IRQ_NONE
)
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)
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.
168 action
= desc
->action
;
170 return action
&& (action
->flags
& IRQF_IRQPOLL
);
173 void note_interrupt(unsigned int irq
, struct irq_desc
*desc
,
174 irqreturn_t action_ret
)
176 if (unlikely(action_ret
!= IRQ_HANDLED
)) {
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
183 if (time_after(jiffies
, desc
->last_unhandled
+ HZ
/10))
184 desc
->irqs_unhandled
= 1;
186 desc
->irqs_unhandled
++;
187 desc
->last_unhandled
= jiffies
;
188 if (unlikely(action_ret
!= IRQ_NONE
))
189 report_bad_irq(irq
, desc
, action_ret
);
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
;
199 if (likely(desc
->irq_count
< 100000))
203 if (unlikely(desc
->irqs_unhandled
> 99900)) {
205 * The interrupt is stuck
207 __report_bad_irq(irq
, desc
, action_ret
);
211 printk(KERN_EMERG
"Disabling IRQ #%d\n", irq
);
212 desc
->status
|= IRQ_DISABLED
| IRQ_SPURIOUS_DISABLED
;
214 desc
->chip
->disable(irq
);
216 desc
->irqs_unhandled
= 0;
219 int noirqdebug __read_mostly
;
221 int noirqdebug_setup(char *str
)
224 printk(KERN_INFO
"IRQ lockup detection disabled\n");
229 __setup("noirqdebug", noirqdebug_setup
);
230 module_param(noirqdebug
, bool, 0644);
231 MODULE_PARM_DESC(noirqdebug
, "Disable irq lockup detection when true");
233 static int __init
irqfixup_setup(char *str
)
236 printk(KERN_WARNING
"Misrouted IRQ fixup support enabled.\n");
237 printk(KERN_WARNING
"This may impact system performance.\n");
242 __setup("irqfixup", irqfixup_setup
);
243 module_param(irqfixup
, int, 0644);
244 MODULE_PARM_DESC("irqfixup", "0: No fixup, 1: irqfixup mode 2: irqpoll mode");
246 static int __init
irqpoll_setup(char *str
)
249 printk(KERN_WARNING
"Misrouted IRQ fixup and polling support "
251 printk(KERN_WARNING
"This may significantly impact system "
256 __setup("irqpoll", irqpoll_setup
);