blob: 5eae7bf3c3479f5ba74ac911fc80eaad60085c64 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
Andreas Mohr83d4e6e2006-06-23 02:05:32 -070014static int irqfixup __read_mostly;
Alan Cox200803d2005-06-28 20:45:18 -070015
16/*
17 * Recovery handler for misrouted interrupts.
18 */
Alan Cox200803d2005-06-28 20:45:18 -070019static int misrouted_irq(int irq, struct pt_regs *regs)
20{
21 int i;
Alan Cox200803d2005-06-28 20:45:18 -070022 int ok = 0;
23 int work = 0; /* Did we do work for a real IRQ */
24
Ingo Molnar06fcb0c2006-06-29 02:24:40 -070025 for (i = 1; i < NR_IRQS; i++) {
26 struct irq_desc *desc = irq_desc + i;
Alan Cox200803d2005-06-28 20:45:18 -070027 struct irqaction *action;
28
29 if (i == irq) /* Already tried */
30 continue;
Ingo Molnar06fcb0c2006-06-29 02:24:40 -070031
Alan Cox200803d2005-06-28 20:45:18 -070032 spin_lock(&desc->lock);
Alan Cox200803d2005-06-28 20:45:18 -070033 /* Already running on another processor */
34 if (desc->status & IRQ_INPROGRESS) {
35 /*
36 * Already running: If it is shared get the other
37 * CPU to go looking for our mystery interrupt too
38 */
39 if (desc->action && (desc->action->flags & SA_SHIRQ))
40 desc->status |= IRQ_PENDING;
41 spin_unlock(&desc->lock);
42 continue;
43 }
44 /* Honour the normal IRQ locking */
45 desc->status |= IRQ_INPROGRESS;
Ingo Molnar06fcb0c2006-06-29 02:24:40 -070046 action = desc->action;
Alan Cox200803d2005-06-28 20:45:18 -070047 spin_unlock(&desc->lock);
Ingo Molnar06fcb0c2006-06-29 02:24:40 -070048
Alan Cox200803d2005-06-28 20:45:18 -070049 while (action) {
50 /* Only shared IRQ handlers are safe to call */
51 if (action->flags & SA_SHIRQ) {
52 if (action->handler(i, action->dev_id, regs) ==
53 IRQ_HANDLED)
54 ok = 1;
55 }
56 action = action->next;
57 }
58 local_irq_disable();
59 /* Now clean up the flags */
60 spin_lock(&desc->lock);
61 action = desc->action;
62
63 /*
64 * While we were looking for a fixup someone queued a real
Ingo Molnar06fcb0c2006-06-29 02:24:40 -070065 * IRQ clashing with our walk:
Alan Cox200803d2005-06-28 20:45:18 -070066 */
Alan Cox200803d2005-06-28 20:45:18 -070067 while ((desc->status & IRQ_PENDING) && action) {
68 /*
69 * Perform real IRQ processing for the IRQ we deferred
70 */
71 work = 1;
72 spin_unlock(&desc->lock);
73 handle_IRQ_event(i, regs, action);
74 spin_lock(&desc->lock);
75 desc->status &= ~IRQ_PENDING;
76 }
77 desc->status &= ~IRQ_INPROGRESS;
78 /*
79 * If we did actual work for the real IRQ line we must let the
80 * IRQ controller clean up too
81 */
Ingo Molnar06fcb0c2006-06-29 02:24:40 -070082 if (work)
Ingo Molnard1bef4e2006-06-29 02:24:36 -070083 desc->chip->end(i);
Alan Cox200803d2005-06-28 20:45:18 -070084 spin_unlock(&desc->lock);
85 }
86 /* So the caller can adjust the irq error counts */
87 return ok;
88}
89
Linus Torvalds1da177e2005-04-16 15:20:36 -070090/*
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.
94 *
95 * (The other 100-of-100,000 interrupts may have been a correctly
96 * functioning device sharing an IRQ with the failing one)
97 *
98 * Called under desc->lock
99 */
100
101static void
102__report_bad_irq(unsigned int irq, irq_desc_t *desc, irqreturn_t action_ret)
103{
104 struct irqaction *action;
105
106 if (action_ret != IRQ_HANDLED && action_ret != IRQ_NONE) {
107 printk(KERN_ERR "irq event %d: bogus return value %x\n",
108 irq, action_ret);
109 } else {
Alan Cox200803d2005-06-28 20:45:18 -0700110 printk(KERN_ERR "irq %d: nobody cared (try booting with "
111 "the \"irqpoll\" option)\n", irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 }
113 dump_stack();
114 printk(KERN_ERR "handlers:\n");
Ingo Molnar06fcb0c2006-06-29 02:24:40 -0700115
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 action = desc->action;
117 while (action) {
118 printk(KERN_ERR "[<%p>]", action->handler);
119 print_symbol(" (%s)",
120 (unsigned long)action->handler);
121 printk("\n");
122 action = action->next;
123 }
124}
125
Ingo Molnar06fcb0c2006-06-29 02:24:40 -0700126static void
127report_bad_irq(unsigned int irq, irq_desc_t *desc, irqreturn_t action_ret)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128{
129 static int count = 100;
130
131 if (count > 0) {
132 count--;
133 __report_bad_irq(irq, desc, action_ret);
134 }
135}
136
Alan Cox200803d2005-06-28 20:45:18 -0700137void note_interrupt(unsigned int irq, irq_desc_t *desc, irqreturn_t action_ret,
Ingo Molnar06fcb0c2006-06-29 02:24:40 -0700138 struct pt_regs *regs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139{
Andreas Mohr83d4e6e2006-06-23 02:05:32 -0700140 if (unlikely(action_ret != IRQ_HANDLED)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 desc->irqs_unhandled++;
Andreas Mohr83d4e6e2006-06-23 02:05:32 -0700142 if (unlikely(action_ret != IRQ_NONE))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 report_bad_irq(irq, desc, action_ret);
144 }
145
Alan Cox200803d2005-06-28 20:45:18 -0700146 if (unlikely(irqfixup)) {
147 /* Don't punish working computers */
148 if ((irqfixup == 2 && irq == 0) || action_ret == IRQ_NONE) {
149 int ok = misrouted_irq(irq, regs);
150 if (action_ret == IRQ_NONE)
151 desc->irqs_unhandled -= ok;
152 }
153 }
154
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 desc->irq_count++;
Andreas Mohr83d4e6e2006-06-23 02:05:32 -0700156 if (likely(desc->irq_count < 100000))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 return;
158
159 desc->irq_count = 0;
Andreas Mohr83d4e6e2006-06-23 02:05:32 -0700160 if (unlikely(desc->irqs_unhandled > 99900)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 /*
162 * The interrupt is stuck
163 */
164 __report_bad_irq(irq, desc, action_ret);
165 /*
166 * Now kill the IRQ
167 */
168 printk(KERN_EMERG "Disabling IRQ #%d\n", irq);
169 desc->status |= IRQ_DISABLED;
Ingo Molnard1bef4e2006-06-29 02:24:36 -0700170 desc->chip->disable(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 }
172 desc->irqs_unhandled = 0;
173}
174
Andreas Mohr83d4e6e2006-06-23 02:05:32 -0700175int noirqdebug __read_mostly;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176
177int __init noirqdebug_setup(char *str)
178{
179 noirqdebug = 1;
180 printk(KERN_INFO "IRQ lockup detection disabled\n");
Ingo Molnar06fcb0c2006-06-29 02:24:40 -0700181
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 return 1;
183}
184
185__setup("noirqdebug", noirqdebug_setup);
186
Alan Cox200803d2005-06-28 20:45:18 -0700187static int __init irqfixup_setup(char *str)
188{
189 irqfixup = 1;
190 printk(KERN_WARNING "Misrouted IRQ fixup support enabled.\n");
191 printk(KERN_WARNING "This may impact system performance.\n");
Ingo Molnar06fcb0c2006-06-29 02:24:40 -0700192
Alan Cox200803d2005-06-28 20:45:18 -0700193 return 1;
194}
195
196__setup("irqfixup", irqfixup_setup);
197
198static int __init irqpoll_setup(char *str)
199{
200 irqfixup = 2;
201 printk(KERN_WARNING "Misrouted IRQ fixup and polling support "
202 "enabled\n");
203 printk(KERN_WARNING "This may significantly impact system "
204 "performance\n");
205 return 1;
206}
207
208__setup("irqpoll", irqpoll_setup);