| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 |  | 
| S.Caglar Onur | 188fd89 | 2008-02-14 17:36:51 +0200 | [diff] [blame] | 9 | #include <linux/jiffies.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include <linux/irq.h> | 
|  | 11 | #include <linux/module.h> | 
|  | 12 | #include <linux/kallsyms.h> | 
|  | 13 | #include <linux/interrupt.h> | 
| Andi Kleen | 9e094c1 | 2008-01-30 13:32:48 +0100 | [diff] [blame] | 14 | #include <linux/moduleparam.h> | 
| Eric W. Biederman | f84dbb9 | 2008-07-10 14:48:54 -0700 | [diff] [blame] | 15 | #include <linux/timer.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 |  | 
| Andreas Mohr | 83d4e6e | 2006-06-23 02:05:32 -0700 | [diff] [blame] | 17 | static int irqfixup __read_mostly; | 
| Alan Cox | 200803d | 2005-06-28 20:45:18 -0700 | [diff] [blame] | 18 |  | 
| Eric W. Biederman | f84dbb9 | 2008-07-10 14:48:54 -0700 | [diff] [blame] | 19 | #define POLL_SPURIOUS_IRQ_INTERVAL (HZ/10) | 
|  | 20 | static void poll_spurious_irqs(unsigned long dummy); | 
|  | 21 | static DEFINE_TIMER(poll_spurious_irq_timer, poll_spurious_irqs, 0, 0); | 
|  | 22 |  | 
| Alan Cox | 200803d | 2005-06-28 20:45:18 -0700 | [diff] [blame] | 23 | /* | 
|  | 24 | * Recovery handler for misrouted interrupts. | 
|  | 25 | */ | 
| Eric W. Biederman | f84dbb9 | 2008-07-10 14:48:54 -0700 | [diff] [blame] | 26 | static int try_one_irq(int irq, struct irq_desc *desc) | 
|  | 27 | { | 
|  | 28 | struct irqaction *action; | 
| Thomas Gleixner | d3c6004 | 2008-10-16 09:55:00 +0200 | [diff] [blame] | 29 | int ok = 0, work = 0; | 
| Eric W. Biederman | f84dbb9 | 2008-07-10 14:48:54 -0700 | [diff] [blame] | 30 |  | 
| Thomas Gleixner | 239007b | 2009-11-17 16:46:45 +0100 | [diff] [blame] | 31 | raw_spin_lock(&desc->lock); | 
| Eric W. Biederman | f84dbb9 | 2008-07-10 14:48:54 -0700 | [diff] [blame] | 32 | /* Already running on another processor */ | 
|  | 33 | if (desc->status & IRQ_INPROGRESS) { | 
|  | 34 | /* | 
|  | 35 | * Already running: If it is shared get the other | 
|  | 36 | * CPU to go looking for our mystery interrupt too | 
|  | 37 | */ | 
|  | 38 | if (desc->action && (desc->action->flags & IRQF_SHARED)) | 
|  | 39 | desc->status |= IRQ_PENDING; | 
| Thomas Gleixner | 239007b | 2009-11-17 16:46:45 +0100 | [diff] [blame] | 40 | raw_spin_unlock(&desc->lock); | 
| Eric W. Biederman | f84dbb9 | 2008-07-10 14:48:54 -0700 | [diff] [blame] | 41 | return ok; | 
|  | 42 | } | 
|  | 43 | /* Honour the normal IRQ locking */ | 
|  | 44 | desc->status |= IRQ_INPROGRESS; | 
|  | 45 | action = desc->action; | 
| Thomas Gleixner | 239007b | 2009-11-17 16:46:45 +0100 | [diff] [blame] | 46 | raw_spin_unlock(&desc->lock); | 
| Eric W. Biederman | f84dbb9 | 2008-07-10 14:48:54 -0700 | [diff] [blame] | 47 |  | 
|  | 48 | while (action) { | 
|  | 49 | /* Only shared IRQ handlers are safe to call */ | 
|  | 50 | if (action->flags & IRQF_SHARED) { | 
|  | 51 | if (action->handler(irq, action->dev_id) == | 
|  | 52 | IRQ_HANDLED) | 
|  | 53 | ok = 1; | 
|  | 54 | } | 
|  | 55 | action = action->next; | 
|  | 56 | } | 
|  | 57 | local_irq_disable(); | 
|  | 58 | /* Now clean up the flags */ | 
| Thomas Gleixner | 239007b | 2009-11-17 16:46:45 +0100 | [diff] [blame] | 59 | raw_spin_lock(&desc->lock); | 
| Eric W. Biederman | f84dbb9 | 2008-07-10 14:48:54 -0700 | [diff] [blame] | 60 | action = desc->action; | 
|  | 61 |  | 
|  | 62 | /* | 
|  | 63 | * While we were looking for a fixup someone queued a real | 
|  | 64 | * IRQ clashing with our walk: | 
|  | 65 | */ | 
|  | 66 | while ((desc->status & IRQ_PENDING) && action) { | 
|  | 67 | /* | 
|  | 68 | * Perform real IRQ processing for the IRQ we deferred | 
|  | 69 | */ | 
|  | 70 | work = 1; | 
| Thomas Gleixner | 239007b | 2009-11-17 16:46:45 +0100 | [diff] [blame] | 71 | raw_spin_unlock(&desc->lock); | 
| Eric W. Biederman | f84dbb9 | 2008-07-10 14:48:54 -0700 | [diff] [blame] | 72 | handle_IRQ_event(irq, action); | 
| Thomas Gleixner | 239007b | 2009-11-17 16:46:45 +0100 | [diff] [blame] | 73 | raw_spin_lock(&desc->lock); | 
| Eric W. Biederman | f84dbb9 | 2008-07-10 14:48:54 -0700 | [diff] [blame] | 74 | desc->status &= ~IRQ_PENDING; | 
|  | 75 | } | 
|  | 76 | desc->status &= ~IRQ_INPROGRESS; | 
|  | 77 | /* | 
|  | 78 | * If we did actual work for the real IRQ line we must let the | 
|  | 79 | * IRQ controller clean up too | 
|  | 80 | */ | 
|  | 81 | if (work && desc->chip && desc->chip->end) | 
|  | 82 | desc->chip->end(irq); | 
| Thomas Gleixner | 239007b | 2009-11-17 16:46:45 +0100 | [diff] [blame] | 83 | raw_spin_unlock(&desc->lock); | 
| Eric W. Biederman | f84dbb9 | 2008-07-10 14:48:54 -0700 | [diff] [blame] | 84 |  | 
|  | 85 | return ok; | 
|  | 86 | } | 
|  | 87 |  | 
| David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 88 | static int misrouted_irq(int irq) | 
| Alan Cox | 200803d | 2005-06-28 20:45:18 -0700 | [diff] [blame] | 89 | { | 
| Yinghai Lu | e00585b | 2008-09-15 01:53:50 -0700 | [diff] [blame] | 90 | struct irq_desc *desc; | 
| Thomas Gleixner | d3c6004 | 2008-10-16 09:55:00 +0200 | [diff] [blame] | 91 | int i, ok = 0; | 
| Alan Cox | 200803d | 2005-06-28 20:45:18 -0700 | [diff] [blame] | 92 |  | 
| Yinghai Lu | e00585b | 2008-09-15 01:53:50 -0700 | [diff] [blame] | 93 | for_each_irq_desc(i, desc) { | 
|  | 94 | if (!i) | 
|  | 95 | continue; | 
| Alan Cox | 200803d | 2005-06-28 20:45:18 -0700 | [diff] [blame] | 96 |  | 
|  | 97 | if (i == irq)	/* Already tried */ | 
|  | 98 | continue; | 
| Ingo Molnar | 06fcb0c | 2006-06-29 02:24:40 -0700 | [diff] [blame] | 99 |  | 
| Eric W. Biederman | f84dbb9 | 2008-07-10 14:48:54 -0700 | [diff] [blame] | 100 | if (try_one_irq(i, desc)) | 
|  | 101 | ok = 1; | 
| Alan Cox | 200803d | 2005-06-28 20:45:18 -0700 | [diff] [blame] | 102 | } | 
|  | 103 | /* So the caller can adjust the irq error counts */ | 
|  | 104 | return ok; | 
|  | 105 | } | 
|  | 106 |  | 
| Thomas Gleixner | 663e695 | 2009-11-04 14:22:21 +0100 | [diff] [blame] | 107 | static void poll_spurious_irqs(unsigned long dummy) | 
| Eric W. Biederman | f84dbb9 | 2008-07-10 14:48:54 -0700 | [diff] [blame] | 108 | { | 
| Yinghai Lu | e00585b | 2008-09-15 01:53:50 -0700 | [diff] [blame] | 109 | struct irq_desc *desc; | 
| Thomas Gleixner | d3c6004 | 2008-10-16 09:55:00 +0200 | [diff] [blame] | 110 | int i; | 
| Yinghai Lu | e00585b | 2008-09-15 01:53:50 -0700 | [diff] [blame] | 111 |  | 
|  | 112 | for_each_irq_desc(i, desc) { | 
| Eric W. Biederman | f84dbb9 | 2008-07-10 14:48:54 -0700 | [diff] [blame] | 113 | unsigned int status; | 
|  | 114 |  | 
| Yinghai Lu | e00585b | 2008-09-15 01:53:50 -0700 | [diff] [blame] | 115 | if (!i) | 
|  | 116 | continue; | 
|  | 117 |  | 
| Eric W. Biederman | f84dbb9 | 2008-07-10 14:48:54 -0700 | [diff] [blame] | 118 | /* Racy but it doesn't matter */ | 
|  | 119 | status = desc->status; | 
|  | 120 | barrier(); | 
|  | 121 | if (!(status & IRQ_SPURIOUS_DISABLED)) | 
|  | 122 | continue; | 
|  | 123 |  | 
| Yong Zhang | e7e7e0c | 2009-11-07 11:16:13 +0800 | [diff] [blame] | 124 | local_irq_disable(); | 
| Eric W. Biederman | f84dbb9 | 2008-07-10 14:48:54 -0700 | [diff] [blame] | 125 | try_one_irq(i, desc); | 
| Yong Zhang | e7e7e0c | 2009-11-07 11:16:13 +0800 | [diff] [blame] | 126 | local_irq_enable(); | 
| Eric W. Biederman | f84dbb9 | 2008-07-10 14:48:54 -0700 | [diff] [blame] | 127 | } | 
|  | 128 |  | 
| Thomas Gleixner | d3c6004 | 2008-10-16 09:55:00 +0200 | [diff] [blame] | 129 | mod_timer(&poll_spurious_irq_timer, | 
|  | 130 | jiffies + POLL_SPURIOUS_IRQ_INTERVAL); | 
| Eric W. Biederman | f84dbb9 | 2008-07-10 14:48:54 -0700 | [diff] [blame] | 131 | } | 
|  | 132 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | /* | 
|  | 134 | * If 99,900 of the previous 100,000 interrupts have not been handled | 
|  | 135 | * then assume that the IRQ is stuck in some manner. Drop a diagnostic | 
|  | 136 | * and try to turn the IRQ off. | 
|  | 137 | * | 
|  | 138 | * (The other 100-of-100,000 interrupts may have been a correctly | 
|  | 139 | *  functioning device sharing an IRQ with the failing one) | 
|  | 140 | * | 
|  | 141 | * Called under desc->lock | 
|  | 142 | */ | 
|  | 143 |  | 
|  | 144 | static void | 
| Ingo Molnar | 34ffdb7 | 2006-06-29 02:24:40 -0700 | [diff] [blame] | 145 | __report_bad_irq(unsigned int irq, struct irq_desc *desc, | 
|  | 146 | irqreturn_t action_ret) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | { | 
|  | 148 | struct irqaction *action; | 
|  | 149 |  | 
|  | 150 | if (action_ret != IRQ_HANDLED && action_ret != IRQ_NONE) { | 
|  | 151 | printk(KERN_ERR "irq event %d: bogus return value %x\n", | 
|  | 152 | irq, action_ret); | 
|  | 153 | } else { | 
| Alan Cox | 200803d | 2005-06-28 20:45:18 -0700 | [diff] [blame] | 154 | printk(KERN_ERR "irq %d: nobody cared (try booting with " | 
|  | 155 | "the \"irqpoll\" option)\n", irq); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | } | 
|  | 157 | dump_stack(); | 
|  | 158 | printk(KERN_ERR "handlers:\n"); | 
| Ingo Molnar | 06fcb0c | 2006-06-29 02:24:40 -0700 | [diff] [blame] | 159 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | action = desc->action; | 
|  | 161 | while (action) { | 
|  | 162 | printk(KERN_ERR "[<%p>]", action->handler); | 
|  | 163 | print_symbol(" (%s)", | 
|  | 164 | (unsigned long)action->handler); | 
|  | 165 | printk("\n"); | 
|  | 166 | action = action->next; | 
|  | 167 | } | 
|  | 168 | } | 
|  | 169 |  | 
| Ingo Molnar | 06fcb0c | 2006-06-29 02:24:40 -0700 | [diff] [blame] | 170 | static void | 
| Ingo Molnar | 34ffdb7 | 2006-06-29 02:24:40 -0700 | [diff] [blame] | 171 | report_bad_irq(unsigned int irq, struct irq_desc *desc, irqreturn_t action_ret) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | { | 
|  | 173 | static int count = 100; | 
|  | 174 |  | 
|  | 175 | if (count > 0) { | 
|  | 176 | count--; | 
|  | 177 | __report_bad_irq(irq, desc, action_ret); | 
|  | 178 | } | 
|  | 179 | } | 
|  | 180 |  | 
| Thomas Gleixner | d3c6004 | 2008-10-16 09:55:00 +0200 | [diff] [blame] | 181 | static inline int | 
|  | 182 | try_misrouted_irq(unsigned int irq, struct irq_desc *desc, | 
|  | 183 | irqreturn_t action_ret) | 
| Linus Torvalds | 92ea772 | 2007-05-24 08:37:14 -0700 | [diff] [blame] | 184 | { | 
|  | 185 | struct irqaction *action; | 
|  | 186 |  | 
|  | 187 | if (!irqfixup) | 
|  | 188 | return 0; | 
|  | 189 |  | 
|  | 190 | /* We didn't actually handle the IRQ - see if it was misrouted? */ | 
|  | 191 | if (action_ret == IRQ_NONE) | 
|  | 192 | return 1; | 
|  | 193 |  | 
|  | 194 | /* | 
|  | 195 | * But for 'irqfixup == 2' we also do it for handled interrupts if | 
|  | 196 | * they are marked as IRQF_IRQPOLL (or for irq zero, which is the | 
|  | 197 | * traditional PC timer interrupt.. Legacy) | 
|  | 198 | */ | 
|  | 199 | if (irqfixup < 2) | 
|  | 200 | return 0; | 
|  | 201 |  | 
|  | 202 | if (!irq) | 
|  | 203 | return 1; | 
|  | 204 |  | 
|  | 205 | /* | 
|  | 206 | * Since we don't get the descriptor lock, "action" can | 
|  | 207 | * change under us.  We don't really care, but we don't | 
|  | 208 | * want to follow a NULL pointer. So tell the compiler to | 
|  | 209 | * just load it once by using a barrier. | 
|  | 210 | */ | 
|  | 211 | action = desc->action; | 
|  | 212 | barrier(); | 
|  | 213 | return action && (action->flags & IRQF_IRQPOLL); | 
|  | 214 | } | 
|  | 215 |  | 
| Ingo Molnar | 34ffdb7 | 2006-06-29 02:24:40 -0700 | [diff] [blame] | 216 | void note_interrupt(unsigned int irq, struct irq_desc *desc, | 
| David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 217 | irqreturn_t action_ret) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | { | 
| Andreas Mohr | 83d4e6e | 2006-06-23 02:05:32 -0700 | [diff] [blame] | 219 | if (unlikely(action_ret != IRQ_HANDLED)) { | 
| Alan Cox | 4f27c00 | 2007-07-15 23:40:55 -0700 | [diff] [blame] | 220 | /* | 
|  | 221 | * If we are seeing only the odd spurious IRQ caused by | 
|  | 222 | * bus asynchronicity then don't eventually trigger an error, | 
| Uwe Kleine-König | fbfecd3 | 2009-10-28 20:11:04 +0100 | [diff] [blame] | 223 | * otherwise the counter becomes a doomsday timer for otherwise | 
| Alan Cox | 4f27c00 | 2007-07-15 23:40:55 -0700 | [diff] [blame] | 224 | * working systems | 
|  | 225 | */ | 
| S.Caglar Onur | 188fd89 | 2008-02-14 17:36:51 +0200 | [diff] [blame] | 226 | if (time_after(jiffies, desc->last_unhandled + HZ/10)) | 
| Alan Cox | 4f27c00 | 2007-07-15 23:40:55 -0700 | [diff] [blame] | 227 | desc->irqs_unhandled = 1; | 
|  | 228 | else | 
|  | 229 | desc->irqs_unhandled++; | 
|  | 230 | desc->last_unhandled = jiffies; | 
| Andreas Mohr | 83d4e6e | 2006-06-23 02:05:32 -0700 | [diff] [blame] | 231 | if (unlikely(action_ret != IRQ_NONE)) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | report_bad_irq(irq, desc, action_ret); | 
|  | 233 | } | 
|  | 234 |  | 
| Linus Torvalds | 92ea772 | 2007-05-24 08:37:14 -0700 | [diff] [blame] | 235 | if (unlikely(try_misrouted_irq(irq, desc, action_ret))) { | 
|  | 236 | int ok = misrouted_irq(irq); | 
|  | 237 | if (action_ret == IRQ_NONE) | 
|  | 238 | desc->irqs_unhandled -= ok; | 
| Alan Cox | 200803d | 2005-06-28 20:45:18 -0700 | [diff] [blame] | 239 | } | 
|  | 240 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | desc->irq_count++; | 
| Andreas Mohr | 83d4e6e | 2006-06-23 02:05:32 -0700 | [diff] [blame] | 242 | if (likely(desc->irq_count < 100000)) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | return; | 
|  | 244 |  | 
|  | 245 | desc->irq_count = 0; | 
| Andreas Mohr | 83d4e6e | 2006-06-23 02:05:32 -0700 | [diff] [blame] | 246 | if (unlikely(desc->irqs_unhandled > 99900)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | /* | 
|  | 248 | * The interrupt is stuck | 
|  | 249 | */ | 
|  | 250 | __report_bad_irq(irq, desc, action_ret); | 
|  | 251 | /* | 
|  | 252 | * Now kill the IRQ | 
|  | 253 | */ | 
|  | 254 | printk(KERN_EMERG "Disabling IRQ #%d\n", irq); | 
| Thomas Gleixner | 1adb085 | 2008-04-28 17:01:56 +0200 | [diff] [blame] | 255 | desc->status |= IRQ_DISABLED | IRQ_SPURIOUS_DISABLED; | 
|  | 256 | desc->depth++; | 
| Ingo Molnar | d1bef4e | 2006-06-29 02:24:36 -0700 | [diff] [blame] | 257 | desc->chip->disable(irq); | 
| Eric W. Biederman | f84dbb9 | 2008-07-10 14:48:54 -0700 | [diff] [blame] | 258 |  | 
| Thomas Gleixner | d3c6004 | 2008-10-16 09:55:00 +0200 | [diff] [blame] | 259 | mod_timer(&poll_spurious_irq_timer, | 
|  | 260 | jiffies + POLL_SPURIOUS_IRQ_INTERVAL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | } | 
|  | 262 | desc->irqs_unhandled = 0; | 
|  | 263 | } | 
|  | 264 |  | 
| Andreas Mohr | 83d4e6e | 2006-06-23 02:05:32 -0700 | [diff] [blame] | 265 | int noirqdebug __read_mostly; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 |  | 
| Vivek Goyal | 343cde5 | 2007-01-11 01:52:44 +0100 | [diff] [blame] | 267 | int noirqdebug_setup(char *str) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | { | 
|  | 269 | noirqdebug = 1; | 
|  | 270 | printk(KERN_INFO "IRQ lockup detection disabled\n"); | 
| Ingo Molnar | 06fcb0c | 2006-06-29 02:24:40 -0700 | [diff] [blame] | 271 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | return 1; | 
|  | 273 | } | 
|  | 274 |  | 
|  | 275 | __setup("noirqdebug", noirqdebug_setup); | 
| Andi Kleen | 9e094c1 | 2008-01-30 13:32:48 +0100 | [diff] [blame] | 276 | module_param(noirqdebug, bool, 0644); | 
|  | 277 | MODULE_PARM_DESC(noirqdebug, "Disable irq lockup detection when true"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 |  | 
| Alan Cox | 200803d | 2005-06-28 20:45:18 -0700 | [diff] [blame] | 279 | static int __init irqfixup_setup(char *str) | 
|  | 280 | { | 
|  | 281 | irqfixup = 1; | 
|  | 282 | printk(KERN_WARNING "Misrouted IRQ fixup support enabled.\n"); | 
|  | 283 | printk(KERN_WARNING "This may impact system performance.\n"); | 
| Ingo Molnar | 06fcb0c | 2006-06-29 02:24:40 -0700 | [diff] [blame] | 284 |  | 
| Alan Cox | 200803d | 2005-06-28 20:45:18 -0700 | [diff] [blame] | 285 | return 1; | 
|  | 286 | } | 
|  | 287 |  | 
|  | 288 | __setup("irqfixup", irqfixup_setup); | 
| Andi Kleen | 9e094c1 | 2008-01-30 13:32:48 +0100 | [diff] [blame] | 289 | module_param(irqfixup, int, 0644); | 
| Alan Cox | 200803d | 2005-06-28 20:45:18 -0700 | [diff] [blame] | 290 |  | 
|  | 291 | static int __init irqpoll_setup(char *str) | 
|  | 292 | { | 
|  | 293 | irqfixup = 2; | 
|  | 294 | printk(KERN_WARNING "Misrouted IRQ fixup and polling support " | 
|  | 295 | "enabled\n"); | 
|  | 296 | printk(KERN_WARNING "This may significantly impact system " | 
|  | 297 | "performance\n"); | 
|  | 298 | return 1; | 
|  | 299 | } | 
|  | 300 |  | 
|  | 301 | __setup("irqpoll", irqpoll_setup); |