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