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