Merge git://git.kernel.org/pub/scm/linux/kernel/git/tglx/linux-2.6-genirq
[linux-2.6] / kernel / irq / spurious.c
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
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
16 static int irqfixup __read_mostly;
17
18 /*
19  * Recovery handler for misrouted interrupts.
20  */
21 static int misrouted_irq(int irq)
22 {
23         int i;
24         int ok = 0;
25         int work = 0;   /* Did we do work for a real IRQ */
26
27         for (i = 1; i < NR_IRQS; i++) {
28                 struct irq_desc *desc = irq_desc + i;
29                 struct irqaction *action;
30
31                 if (i == irq)   /* Already tried */
32                         continue;
33
34                 spin_lock(&desc->lock);
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                          */
41                         if (desc->action && (desc->action->flags & IRQF_SHARED))
42                                 desc->status |= IRQ_PENDING;
43                         spin_unlock(&desc->lock);
44                         continue;
45                 }
46                 /* Honour the normal IRQ locking */
47                 desc->status |= IRQ_INPROGRESS;
48                 action = desc->action;
49                 spin_unlock(&desc->lock);
50
51                 while (action) {
52                         /* Only shared IRQ handlers are safe to call */
53                         if (action->flags & IRQF_SHARED) {
54                                 if (action->handler(i, action->dev_id) ==
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
67                  * IRQ clashing with our walk:
68                  */
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);
75                         handle_IRQ_event(i, action);
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                  */
84                 if (work && desc->chip && desc->chip->end)
85                         desc->chip->end(i);
86                 spin_unlock(&desc->lock);
87         }
88         /* So the caller can adjust the irq error counts */
89         return ok;
90 }
91
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
104 __report_bad_irq(unsigned int irq, struct irq_desc *desc,
105                  irqreturn_t action_ret)
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 {
113                 printk(KERN_ERR "irq %d: nobody cared (try booting with "
114                                 "the \"irqpoll\" option)\n", irq);
115         }
116         dump_stack();
117         printk(KERN_ERR "handlers:\n");
118
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
129 static void
130 report_bad_irq(unsigned int irq, struct irq_desc *desc, irqreturn_t action_ret)
131 {
132         static int count = 100;
133
134         if (count > 0) {
135                 count--;
136                 __report_bad_irq(irq, desc, action_ret);
137         }
138 }
139
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
173 void note_interrupt(unsigned int irq, struct irq_desc *desc,
174                     irqreturn_t action_ret)
175 {
176         if (unlikely(action_ret != IRQ_HANDLED)) {
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                  */
183                 if (time_after(jiffies, desc->last_unhandled + HZ/10))
184                         desc->irqs_unhandled = 1;
185                 else
186                         desc->irqs_unhandled++;
187                 desc->last_unhandled = jiffies;
188                 if (unlikely(action_ret != IRQ_NONE))
189                         report_bad_irq(irq, desc, action_ret);
190         }
191
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;
196         }
197
198         desc->irq_count++;
199         if (likely(desc->irq_count < 100000))
200                 return;
201
202         desc->irq_count = 0;
203         if (unlikely(desc->irqs_unhandled > 99900)) {
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 | IRQ_SPURIOUS_DISABLED;
213                 desc->depth++;
214                 desc->chip->disable(irq);
215         }
216         desc->irqs_unhandled = 0;
217 }
218
219 int noirqdebug __read_mostly;
220
221 int noirqdebug_setup(char *str)
222 {
223         noirqdebug = 1;
224         printk(KERN_INFO "IRQ lockup detection disabled\n");
225
226         return 1;
227 }
228
229 __setup("noirqdebug", noirqdebug_setup);
230 module_param(noirqdebug, bool, 0644);
231 MODULE_PARM_DESC(noirqdebug, "Disable irq lockup detection when true");
232
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");
238
239         return 1;
240 }
241
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");
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);