| 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> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 |  | 
| Andreas Mohr | 83d4e6e | 2006-06-23 02:05:32 -0700 | [diff] [blame] | 16 | static int irqfixup __read_mostly; | 
| Alan Cox | 200803d | 2005-06-28 20:45:18 -0700 | [diff] [blame] | 17 |  | 
|  | 18 | /* | 
|  | 19 | * Recovery handler for misrouted interrupts. | 
|  | 20 | */ | 
| David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 21 | static int misrouted_irq(int irq) | 
| Alan Cox | 200803d | 2005-06-28 20:45:18 -0700 | [diff] [blame] | 22 | { | 
|  | 23 | int i; | 
| Alan Cox | 200803d | 2005-06-28 20:45:18 -0700 | [diff] [blame] | 24 | int ok = 0; | 
|  | 25 | int work = 0;	/* Did we do work for a real IRQ */ | 
|  | 26 |  | 
| Ingo Molnar | 06fcb0c | 2006-06-29 02:24:40 -0700 | [diff] [blame] | 27 | for (i = 1; i < NR_IRQS; i++) { | 
|  | 28 | struct irq_desc *desc = irq_desc + i; | 
| Alan Cox | 200803d | 2005-06-28 20:45:18 -0700 | [diff] [blame] | 29 | struct irqaction *action; | 
|  | 30 |  | 
|  | 31 | if (i == irq)	/* Already tried */ | 
|  | 32 | continue; | 
| Ingo Molnar | 06fcb0c | 2006-06-29 02:24:40 -0700 | [diff] [blame] | 33 |  | 
| Alan Cox | 200803d | 2005-06-28 20:45:18 -0700 | [diff] [blame] | 34 | spin_lock(&desc->lock); | 
| Alan Cox | 200803d | 2005-06-28 20:45:18 -0700 | [diff] [blame] | 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 | */ | 
| Thomas Gleixner | 3cca53b | 2006-07-01 19:29:31 -0700 | [diff] [blame] | 41 | if (desc->action && (desc->action->flags & IRQF_SHARED)) | 
| Alan Cox | 200803d | 2005-06-28 20:45:18 -0700 | [diff] [blame] | 42 | desc->status |= IRQ_PENDING; | 
|  | 43 | spin_unlock(&desc->lock); | 
|  | 44 | continue; | 
|  | 45 | } | 
|  | 46 | /* Honour the normal IRQ locking */ | 
|  | 47 | desc->status |= IRQ_INPROGRESS; | 
| Ingo Molnar | 06fcb0c | 2006-06-29 02:24:40 -0700 | [diff] [blame] | 48 | action = desc->action; | 
| Alan Cox | 200803d | 2005-06-28 20:45:18 -0700 | [diff] [blame] | 49 | spin_unlock(&desc->lock); | 
| Ingo Molnar | 06fcb0c | 2006-06-29 02:24:40 -0700 | [diff] [blame] | 50 |  | 
| Alan Cox | 200803d | 2005-06-28 20:45:18 -0700 | [diff] [blame] | 51 | while (action) { | 
|  | 52 | /* Only shared IRQ handlers are safe to call */ | 
| Thomas Gleixner | 3cca53b | 2006-07-01 19:29:31 -0700 | [diff] [blame] | 53 | if (action->flags & IRQF_SHARED) { | 
| David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 54 | if (action->handler(i, action->dev_id) == | 
| Alan Cox | 200803d | 2005-06-28 20:45:18 -0700 | [diff] [blame] | 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 | 
| Ingo Molnar | 06fcb0c | 2006-06-29 02:24:40 -0700 | [diff] [blame] | 67 | * IRQ clashing with our walk: | 
| Alan Cox | 200803d | 2005-06-28 20:45:18 -0700 | [diff] [blame] | 68 | */ | 
| Alan Cox | 200803d | 2005-06-28 20:45:18 -0700 | [diff] [blame] | 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); | 
| David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 75 | handle_IRQ_event(i, action); | 
| Alan Cox | 200803d | 2005-06-28 20:45:18 -0700 | [diff] [blame] | 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 | */ | 
| Thomas Gleixner | dd87eb3 | 2006-06-29 02:24:53 -0700 | [diff] [blame] | 84 | if (work && desc->chip && desc->chip->end) | 
| Ingo Molnar | d1bef4e | 2006-06-29 02:24:36 -0700 | [diff] [blame] | 85 | desc->chip->end(i); | 
| Alan Cox | 200803d | 2005-06-28 20:45:18 -0700 | [diff] [blame] | 86 | spin_unlock(&desc->lock); | 
|  | 87 | } | 
|  | 88 | /* So the caller can adjust the irq error counts */ | 
|  | 89 | return ok; | 
|  | 90 | } | 
|  | 91 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | 
| Ingo Molnar | 34ffdb7 | 2006-06-29 02:24:40 -0700 | [diff] [blame] | 104 | __report_bad_irq(unsigned int irq, struct irq_desc *desc, | 
|  | 105 | irqreturn_t action_ret) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 { | 
| Alan Cox | 200803d | 2005-06-28 20:45:18 -0700 | [diff] [blame] | 113 | printk(KERN_ERR "irq %d: nobody cared (try booting with " | 
|  | 114 | "the \"irqpoll\" option)\n", irq); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | } | 
|  | 116 | dump_stack(); | 
|  | 117 | printk(KERN_ERR "handlers:\n"); | 
| Ingo Molnar | 06fcb0c | 2006-06-29 02:24:40 -0700 | [diff] [blame] | 118 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 |  | 
| Ingo Molnar | 06fcb0c | 2006-06-29 02:24:40 -0700 | [diff] [blame] | 129 | static void | 
| Ingo Molnar | 34ffdb7 | 2006-06-29 02:24:40 -0700 | [diff] [blame] | 130 | 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] | 131 | { | 
|  | 132 | static int count = 100; | 
|  | 133 |  | 
|  | 134 | if (count > 0) { | 
|  | 135 | count--; | 
|  | 136 | __report_bad_irq(irq, desc, action_ret); | 
|  | 137 | } | 
|  | 138 | } | 
|  | 139 |  | 
| Linus Torvalds | 92ea772 | 2007-05-24 08:37:14 -0700 | [diff] [blame] | 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 |  | 
| Ingo Molnar | 34ffdb7 | 2006-06-29 02:24:40 -0700 | [diff] [blame] | 173 | void note_interrupt(unsigned int irq, struct irq_desc *desc, | 
| David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 174 | irqreturn_t action_ret) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | { | 
| Andreas Mohr | 83d4e6e | 2006-06-23 02:05:32 -0700 | [diff] [blame] | 176 | if (unlikely(action_ret != IRQ_HANDLED)) { | 
| Alan Cox | 4f27c00 | 2007-07-15 23:40:55 -0700 | [diff] [blame] | 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 | */ | 
| S.Caglar Onur | 188fd89 | 2008-02-14 17:36:51 +0200 | [diff] [blame] | 183 | if (time_after(jiffies, desc->last_unhandled + HZ/10)) | 
| Alan Cox | 4f27c00 | 2007-07-15 23:40:55 -0700 | [diff] [blame] | 184 | desc->irqs_unhandled = 1; | 
|  | 185 | else | 
|  | 186 | desc->irqs_unhandled++; | 
|  | 187 | desc->last_unhandled = jiffies; | 
| Andreas Mohr | 83d4e6e | 2006-06-23 02:05:32 -0700 | [diff] [blame] | 188 | if (unlikely(action_ret != IRQ_NONE)) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | report_bad_irq(irq, desc, action_ret); | 
|  | 190 | } | 
|  | 191 |  | 
| Linus Torvalds | 92ea772 | 2007-05-24 08:37:14 -0700 | [diff] [blame] | 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; | 
| Alan Cox | 200803d | 2005-06-28 20:45:18 -0700 | [diff] [blame] | 196 | } | 
|  | 197 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | desc->irq_count++; | 
| Andreas Mohr | 83d4e6e | 2006-06-23 02:05:32 -0700 | [diff] [blame] | 199 | if (likely(desc->irq_count < 100000)) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | return; | 
|  | 201 |  | 
|  | 202 | desc->irq_count = 0; | 
| Andreas Mohr | 83d4e6e | 2006-06-23 02:05:32 -0700 | [diff] [blame] | 203 | if (unlikely(desc->irqs_unhandled > 99900)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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; | 
| Thomas Gleixner | 6a6de9e | 2006-06-29 02:24:51 -0700 | [diff] [blame] | 213 | desc->depth = 1; | 
| Ingo Molnar | d1bef4e | 2006-06-29 02:24:36 -0700 | [diff] [blame] | 214 | desc->chip->disable(irq); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | } | 
|  | 216 | desc->irqs_unhandled = 0; | 
|  | 217 | } | 
|  | 218 |  | 
| Andreas Mohr | 83d4e6e | 2006-06-23 02:05:32 -0700 | [diff] [blame] | 219 | int noirqdebug __read_mostly; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 |  | 
| Vivek Goyal | 343cde5 | 2007-01-11 01:52:44 +0100 | [diff] [blame] | 221 | int noirqdebug_setup(char *str) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | { | 
|  | 223 | noirqdebug = 1; | 
|  | 224 | printk(KERN_INFO "IRQ lockup detection disabled\n"); | 
| Ingo Molnar | 06fcb0c | 2006-06-29 02:24:40 -0700 | [diff] [blame] | 225 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | return 1; | 
|  | 227 | } | 
|  | 228 |  | 
|  | 229 | __setup("noirqdebug", noirqdebug_setup); | 
| Andi Kleen | 9e094c1 | 2008-01-30 13:32:48 +0100 | [diff] [blame] | 230 | module_param(noirqdebug, bool, 0644); | 
|  | 231 | MODULE_PARM_DESC(noirqdebug, "Disable irq lockup detection when true"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 |  | 
| Alan Cox | 200803d | 2005-06-28 20:45:18 -0700 | [diff] [blame] | 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"); | 
| Ingo Molnar | 06fcb0c | 2006-06-29 02:24:40 -0700 | [diff] [blame] | 238 |  | 
| Alan Cox | 200803d | 2005-06-28 20:45:18 -0700 | [diff] [blame] | 239 | return 1; | 
|  | 240 | } | 
|  | 241 |  | 
|  | 242 | __setup("irqfixup", irqfixup_setup); | 
| Andi Kleen | 9e094c1 | 2008-01-30 13:32:48 +0100 | [diff] [blame] | 243 | module_param(irqfixup, int, 0644); | 
|  | 244 | 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] | 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); |