Merge branches 'release' and 'ppc-workaround' into release
[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/irq.h>
10 #include <linux/module.h>
11 #include <linux/kallsyms.h>
12 #include <linux/interrupt.h>
13 #include <linux/moduleparam.h>
14
15 static int irqfixup __read_mostly;
16
17 /*
18  * Recovery handler for misrouted interrupts.
19  */
20 static int misrouted_irq(int irq)
21 {
22         int i;
23         int ok = 0;
24         int work = 0;   /* Did we do work for a real IRQ */
25
26         for (i = 1; i < NR_IRQS; i++) {
27                 struct irq_desc *desc = irq_desc + i;
28                 struct irqaction *action;
29
30                 if (i == irq)   /* Already tried */
31                         continue;
32
33                 spin_lock(&desc->lock);
34                 /* Already running on another processor */
35                 if (desc->status & IRQ_INPROGRESS) {
36                         /*
37                          * Already running: If it is shared get the other
38                          * CPU to go looking for our mystery interrupt too
39                          */
40                         if (desc->action && (desc->action->flags & IRQF_SHARED))
41                                 desc->status |= IRQ_PENDING;
42                         spin_unlock(&desc->lock);
43                         continue;
44                 }
45                 /* Honour the normal IRQ locking */
46                 desc->status |= IRQ_INPROGRESS;
47                 action = desc->action;
48                 spin_unlock(&desc->lock);
49
50                 while (action) {
51                         /* Only shared IRQ handlers are safe to call */
52                         if (action->flags & IRQF_SHARED) {
53                                 if (action->handler(i, action->dev_id) ==
54                                                 IRQ_HANDLED)
55                                         ok = 1;
56                         }
57                         action = action->next;
58                 }
59                 local_irq_disable();
60                 /* Now clean up the flags */
61                 spin_lock(&desc->lock);
62                 action = desc->action;
63
64                 /*
65                  * While we were looking for a fixup someone queued a real
66                  * IRQ clashing with our walk:
67                  */
68                 while ((desc->status & IRQ_PENDING) && action) {
69                         /*
70                          * Perform real IRQ processing for the IRQ we deferred
71                          */
72                         work = 1;
73                         spin_unlock(&desc->lock);
74                         handle_IRQ_event(i, action);
75                         spin_lock(&desc->lock);
76                         desc->status &= ~IRQ_PENDING;
77                 }
78                 desc->status &= ~IRQ_INPROGRESS;
79                 /*
80                  * If we did actual work for the real IRQ line we must let the
81                  * IRQ controller clean up too
82                  */
83                 if (work && desc->chip && desc->chip->end)
84                         desc->chip->end(i);
85                 spin_unlock(&desc->lock);
86         }
87         /* So the caller can adjust the irq error counts */
88         return ok;
89 }
90
91 /*
92  * If 99,900 of the previous 100,000 interrupts have not been handled
93  * then assume that the IRQ is stuck in some manner. Drop a diagnostic
94  * and try to turn the IRQ off.
95  *
96  * (The other 100-of-100,000 interrupts may have been a correctly
97  *  functioning device sharing an IRQ with the failing one)
98  *
99  * Called under desc->lock
100  */
101
102 static void
103 __report_bad_irq(unsigned int irq, struct irq_desc *desc,
104                  irqreturn_t action_ret)
105 {
106         struct irqaction *action;
107
108         if (action_ret != IRQ_HANDLED && action_ret != IRQ_NONE) {
109                 printk(KERN_ERR "irq event %d: bogus return value %x\n",
110                                 irq, action_ret);
111         } else {
112                 printk(KERN_ERR "irq %d: nobody cared (try booting with "
113                                 "the \"irqpoll\" option)\n", irq);
114         }
115         dump_stack();
116         printk(KERN_ERR "handlers:\n");
117
118         action = desc->action;
119         while (action) {
120                 printk(KERN_ERR "[<%p>]", action->handler);
121                 print_symbol(" (%s)",
122                         (unsigned long)action->handler);
123                 printk("\n");
124                 action = action->next;
125         }
126 }
127
128 static void
129 report_bad_irq(unsigned int irq, struct irq_desc *desc, irqreturn_t action_ret)
130 {
131         static int count = 100;
132
133         if (count > 0) {
134                 count--;
135                 __report_bad_irq(irq, desc, action_ret);
136         }
137 }
138
139 static inline int try_misrouted_irq(unsigned int irq, struct irq_desc *desc, irqreturn_t action_ret)
140 {
141         struct irqaction *action;
142
143         if (!irqfixup)
144                 return 0;
145
146         /* We didn't actually handle the IRQ - see if it was misrouted? */
147         if (action_ret == IRQ_NONE)
148                 return 1;
149
150         /*
151          * But for 'irqfixup == 2' we also do it for handled interrupts if
152          * they are marked as IRQF_IRQPOLL (or for irq zero, which is the
153          * traditional PC timer interrupt.. Legacy)
154          */
155         if (irqfixup < 2)
156                 return 0;
157
158         if (!irq)
159                 return 1;
160
161         /*
162          * Since we don't get the descriptor lock, "action" can
163          * change under us.  We don't really care, but we don't
164          * want to follow a NULL pointer. So tell the compiler to
165          * just load it once by using a barrier.
166          */
167         action = desc->action;
168         barrier();
169         return action && (action->flags & IRQF_IRQPOLL);
170 }
171
172 void note_interrupt(unsigned int irq, struct irq_desc *desc,
173                     irqreturn_t action_ret)
174 {
175         if (unlikely(action_ret != IRQ_HANDLED)) {
176                 /*
177                  * If we are seeing only the odd spurious IRQ caused by
178                  * bus asynchronicity then don't eventually trigger an error,
179                  * otherwise the couter becomes a doomsday timer for otherwise
180                  * working systems
181                  */
182                 if (jiffies - desc->last_unhandled > HZ/10)
183                         desc->irqs_unhandled = 1;
184                 else
185                         desc->irqs_unhandled++;
186                 desc->last_unhandled = jiffies;
187                 if (unlikely(action_ret != IRQ_NONE))
188                         report_bad_irq(irq, desc, action_ret);
189         }
190
191         if (unlikely(try_misrouted_irq(irq, desc, action_ret))) {
192                 int ok = misrouted_irq(irq);
193                 if (action_ret == IRQ_NONE)
194                         desc->irqs_unhandled -= ok;
195         }
196
197         desc->irq_count++;
198         if (likely(desc->irq_count < 100000))
199                 return;
200
201         desc->irq_count = 0;
202         if (unlikely(desc->irqs_unhandled > 99900)) {
203                 /*
204                  * The interrupt is stuck
205                  */
206                 __report_bad_irq(irq, desc, action_ret);
207                 /*
208                  * Now kill the IRQ
209                  */
210                 printk(KERN_EMERG "Disabling IRQ #%d\n", irq);
211                 desc->status |= IRQ_DISABLED;
212                 desc->depth = 1;
213                 desc->chip->disable(irq);
214         }
215         desc->irqs_unhandled = 0;
216 }
217
218 int noirqdebug __read_mostly;
219
220 int noirqdebug_setup(char *str)
221 {
222         noirqdebug = 1;
223         printk(KERN_INFO "IRQ lockup detection disabled\n");
224
225         return 1;
226 }
227
228 __setup("noirqdebug", noirqdebug_setup);
229 module_param(noirqdebug, bool, 0644);
230 MODULE_PARM_DESC(noirqdebug, "Disable irq lockup detection when true");
231
232 static int __init irqfixup_setup(char *str)
233 {
234         irqfixup = 1;
235         printk(KERN_WARNING "Misrouted IRQ fixup support enabled.\n");
236         printk(KERN_WARNING "This may impact system performance.\n");
237
238         return 1;
239 }
240
241 __setup("irqfixup", irqfixup_setup);
242 module_param(irqfixup, int, 0644);
243 MODULE_PARM_DESC("irqfixup", "0: No fixup, 1: irqfixup mode 2: irqpoll mode");
244
245 static int __init irqpoll_setup(char *str)
246 {
247         irqfixup = 2;
248         printk(KERN_WARNING "Misrouted IRQ fixup and polling support "
249                                 "enabled\n");
250         printk(KERN_WARNING "This may significantly impact system "
251                                 "performance\n");
252         return 1;
253 }
254
255 __setup("irqpoll", irqpoll_setup);