| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
 | 2 |  * linux/kernel/irq/handle.c | 
 | 3 |  * | 
| Ingo Molnar | a34db9b | 2006-06-29 02:24:50 -0700 | [diff] [blame] | 4 |  * Copyright (C) 1992, 1998-2006 Linus Torvalds, Ingo Molnar | 
 | 5 |  * Copyright (C) 2005-2006, Thomas Gleixner, Russell King | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 |  * | 
 | 7 |  * This file contains the core interrupt handling code. | 
| Ingo Molnar | a34db9b | 2006-06-29 02:24:50 -0700 | [diff] [blame] | 8 |  * | 
 | 9 |  * Detailed information is available in Documentation/DocBook/genericirq | 
 | 10 |  * | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 |  */ | 
 | 12 |  | 
 | 13 | #include <linux/irq.h> | 
 | 14 | #include <linux/module.h> | 
 | 15 | #include <linux/random.h> | 
 | 16 | #include <linux/interrupt.h> | 
 | 17 | #include <linux/kernel_stat.h> | 
 | 18 |  | 
 | 19 | #include "internals.h" | 
 | 20 |  | 
| Thomas Gleixner | 6a6de9e | 2006-06-29 02:24:51 -0700 | [diff] [blame] | 21 | /** | 
 | 22 |  * handle_bad_irq - handle spurious and unhandled irqs | 
| Henrik Kretzschmar | 43a1dd5 | 2006-08-31 21:27:44 -0700 | [diff] [blame] | 23 |  * @irq:       the interrupt number | 
 | 24 |  * @desc:      description of the interrupt | 
| Henrik Kretzschmar | 43a1dd5 | 2006-08-31 21:27:44 -0700 | [diff] [blame] | 25 |  * | 
 | 26 |  * Handles spurious and unhandled IRQ's. It also prints a debugmessage. | 
| Thomas Gleixner | 6a6de9e | 2006-06-29 02:24:51 -0700 | [diff] [blame] | 27 |  */ | 
| Harvey Harrison | 7ad5b3a | 2008-02-08 04:19:53 -0800 | [diff] [blame] | 28 | void | 
| David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 29 | handle_bad_irq(unsigned int irq, struct irq_desc *desc) | 
| Thomas Gleixner | 6a6de9e | 2006-06-29 02:24:51 -0700 | [diff] [blame] | 30 | { | 
| Ingo Molnar | 43f7775 | 2006-06-29 02:24:58 -0700 | [diff] [blame] | 31 | 	print_irq_desc(irq, desc); | 
| Thomas Gleixner | 6a6de9e | 2006-06-29 02:24:51 -0700 | [diff] [blame] | 32 | 	kstat_this_cpu.irqs[irq]++; | 
 | 33 | 	ack_bad_irq(irq); | 
 | 34 | } | 
 | 35 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | /* | 
 | 37 |  * Linux has a controller-independent interrupt architecture. | 
 | 38 |  * Every controller has a 'controller-template', that is used | 
 | 39 |  * by the main code to do the right thing. Each driver-visible | 
| Ingo Molnar | 06fcb0c | 2006-06-29 02:24:40 -0700 | [diff] [blame] | 40 |  * interrupt source is transparently wired to the appropriate | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 |  * controller. Thus drivers need not be aware of the | 
 | 42 |  * interrupt-controller. | 
 | 43 |  * | 
 | 44 |  * The code is designed to be easily extended with new/different | 
 | 45 |  * interrupt controllers, without having to do assembly magic or | 
 | 46 |  * having to touch the generic code. | 
 | 47 |  * | 
 | 48 |  * Controller mappings for all interrupt sources: | 
 | 49 |  */ | 
| Ravikiran G Thirumalai | e729aa1 | 2007-05-08 00:29:13 -0700 | [diff] [blame] | 50 | struct irq_desc irq_desc[NR_IRQS] __cacheline_aligned_in_smp = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | 	[0 ... NR_IRQS-1] = { | 
| Zhang, Yanmin | 4f167fb | 2005-05-16 21:53:43 -0700 | [diff] [blame] | 52 | 		.status = IRQ_DISABLED, | 
| Ingo Molnar | f1c2662 | 2006-06-29 02:24:57 -0700 | [diff] [blame] | 53 | 		.chip = &no_irq_chip, | 
| Ingo Molnar | 7a55713 | 2006-06-29 02:24:54 -0700 | [diff] [blame] | 54 | 		.handle_irq = handle_bad_irq, | 
| Thomas Gleixner | 94d39e1 | 2006-06-29 02:24:50 -0700 | [diff] [blame] | 55 | 		.depth = 1, | 
| Peter Zijlstra | 6cfd76a | 2006-12-06 20:37:22 -0800 | [diff] [blame] | 56 | 		.lock = __SPIN_LOCK_UNLOCKED(irq_desc->lock), | 
| Ingo Molnar | a53da52 | 2006-06-29 02:24:38 -0700 | [diff] [blame] | 57 | #ifdef CONFIG_SMP | 
 | 58 | 		.affinity = CPU_MASK_ALL | 
 | 59 | #endif | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | 	} | 
 | 61 | }; | 
 | 62 |  | 
 | 63 | /* | 
| Ingo Molnar | 77a5afe | 2006-06-29 02:24:46 -0700 | [diff] [blame] | 64 |  * What should we do if we get a hw irq event on an illegal vector? | 
 | 65 |  * Each architecture has to answer this themself. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 |  */ | 
| Ingo Molnar | 77a5afe | 2006-06-29 02:24:46 -0700 | [diff] [blame] | 67 | static void ack_bad(unsigned int irq) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | { | 
| Ingo Molnar | 43f7775 | 2006-06-29 02:24:58 -0700 | [diff] [blame] | 69 | 	print_irq_desc(irq, irq_desc + irq); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | 	ack_bad_irq(irq); | 
 | 71 | } | 
 | 72 |  | 
| Ingo Molnar | 77a5afe | 2006-06-29 02:24:46 -0700 | [diff] [blame] | 73 | /* | 
 | 74 |  * NOP functions | 
 | 75 |  */ | 
 | 76 | static void noop(unsigned int irq) | 
 | 77 | { | 
 | 78 | } | 
 | 79 |  | 
 | 80 | static unsigned int noop_ret(unsigned int irq) | 
 | 81 | { | 
 | 82 | 	return 0; | 
 | 83 | } | 
 | 84 |  | 
 | 85 | /* | 
 | 86 |  * Generic no controller implementation | 
 | 87 |  */ | 
| Ingo Molnar | f1c2662 | 2006-06-29 02:24:57 -0700 | [diff] [blame] | 88 | struct irq_chip no_irq_chip = { | 
 | 89 | 	.name		= "none", | 
| Ingo Molnar | 77a5afe | 2006-06-29 02:24:46 -0700 | [diff] [blame] | 90 | 	.startup	= noop_ret, | 
 | 91 | 	.shutdown	= noop, | 
 | 92 | 	.enable		= noop, | 
 | 93 | 	.disable	= noop, | 
 | 94 | 	.ack		= ack_bad, | 
 | 95 | 	.end		= noop, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | }; | 
 | 97 |  | 
 | 98 | /* | 
| Thomas Gleixner | f8b5473 | 2006-07-01 22:30:08 +0100 | [diff] [blame] | 99 |  * Generic dummy implementation which can be used for | 
 | 100 |  * real dumb interrupt sources | 
 | 101 |  */ | 
 | 102 | struct irq_chip dummy_irq_chip = { | 
 | 103 | 	.name		= "dummy", | 
 | 104 | 	.startup	= noop_ret, | 
 | 105 | 	.shutdown	= noop, | 
 | 106 | 	.enable		= noop, | 
 | 107 | 	.disable	= noop, | 
 | 108 | 	.ack		= noop, | 
 | 109 | 	.mask		= noop, | 
 | 110 | 	.unmask		= noop, | 
 | 111 | 	.end		= noop, | 
 | 112 | }; | 
 | 113 |  | 
 | 114 | /* | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 |  * Special, empty irq handler: | 
 | 116 |  */ | 
| David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 117 | irqreturn_t no_action(int cpl, void *dev_id) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | { | 
 | 119 | 	return IRQ_NONE; | 
 | 120 | } | 
 | 121 |  | 
| Ingo Molnar | 8d28bc7 | 2006-06-29 02:24:46 -0700 | [diff] [blame] | 122 | /** | 
 | 123 |  * handle_IRQ_event - irq action chain handler | 
 | 124 |  * @irq:	the interrupt number | 
| Ingo Molnar | 8d28bc7 | 2006-06-29 02:24:46 -0700 | [diff] [blame] | 125 |  * @action:	the interrupt action chain for this irq | 
 | 126 |  * | 
 | 127 |  * Handles the action chain of an irq event | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 |  */ | 
| David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 129 | irqreturn_t handle_IRQ_event(unsigned int irq, struct irqaction *action) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | { | 
| Jan Beulich | 908dcec | 2006-06-23 02:06:00 -0700 | [diff] [blame] | 131 | 	irqreturn_t ret, retval = IRQ_NONE; | 
 | 132 | 	unsigned int status = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 |  | 
| Thomas Gleixner | d061daa | 2006-07-03 02:18:48 +0200 | [diff] [blame] | 134 | 	handle_dynamic_tick(action); | 
| Thomas Gleixner | a2166ab | 2006-07-01 22:30:07 +0100 | [diff] [blame] | 135 |  | 
| Thomas Gleixner | 3cca53b | 2006-07-01 19:29:31 -0700 | [diff] [blame] | 136 | 	if (!(action->flags & IRQF_DISABLED)) | 
| Ingo Molnar | 366c7f5 | 2006-07-03 00:25:25 -0700 | [diff] [blame] | 137 | 		local_irq_enable_in_hardirq(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 |  | 
 | 139 | 	do { | 
| David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 140 | 		ret = action->handler(irq, action->dev_id); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | 		if (ret == IRQ_HANDLED) | 
 | 142 | 			status |= action->flags; | 
 | 143 | 		retval |= ret; | 
 | 144 | 		action = action->next; | 
 | 145 | 	} while (action); | 
 | 146 |  | 
| Thomas Gleixner | 3cca53b | 2006-07-01 19:29:31 -0700 | [diff] [blame] | 147 | 	if (status & IRQF_SAMPLE_RANDOM) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | 		add_interrupt_randomness(irq); | 
 | 149 | 	local_irq_disable(); | 
 | 150 |  | 
 | 151 | 	return retval; | 
 | 152 | } | 
 | 153 |  | 
| David Howells | af8c65b | 2006-09-25 23:32:07 -0700 | [diff] [blame] | 154 | #ifndef CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ | 
| Ingo Molnar | 8d28bc7 | 2006-06-29 02:24:46 -0700 | [diff] [blame] | 155 | /** | 
 | 156 |  * __do_IRQ - original all in one highlevel IRQ handler | 
 | 157 |  * @irq:	the interrupt number | 
| Ingo Molnar | 8d28bc7 | 2006-06-29 02:24:46 -0700 | [diff] [blame] | 158 |  * | 
 | 159 |  * __do_IRQ handles all normal device IRQ's (the special | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 |  * SMP cross-CPU interrupts have their own specific | 
 | 161 |  * handlers). | 
| Ingo Molnar | 8d28bc7 | 2006-06-29 02:24:46 -0700 | [diff] [blame] | 162 |  * | 
 | 163 |  * This is the original x86 implementation which is used for every | 
 | 164 |  * interrupt type. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 |  */ | 
| Harvey Harrison | 7ad5b3a | 2008-02-08 04:19:53 -0800 | [diff] [blame] | 166 | unsigned int __do_IRQ(unsigned int irq) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | { | 
| Ingo Molnar | 34ffdb7 | 2006-06-29 02:24:40 -0700 | [diff] [blame] | 168 | 	struct irq_desc *desc = irq_desc + irq; | 
| Ingo Molnar | 06fcb0c | 2006-06-29 02:24:40 -0700 | [diff] [blame] | 169 | 	struct irqaction *action; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | 	unsigned int status; | 
 | 171 |  | 
 | 172 | 	kstat_this_cpu.irqs[irq]++; | 
| Karsten Wiese | f26fdd5 | 2005-09-06 15:17:25 -0700 | [diff] [blame] | 173 | 	if (CHECK_IRQ_PER_CPU(desc->status)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | 		irqreturn_t action_ret; | 
 | 175 |  | 
 | 176 | 		/* | 
 | 177 | 		 * No locking required for CPU-local interrupts: | 
 | 178 | 		 */ | 
| Ingo Molnar | d1bef4e | 2006-06-29 02:24:36 -0700 | [diff] [blame] | 179 | 		if (desc->chip->ack) | 
 | 180 | 			desc->chip->ack(irq); | 
| Russ Anderson | c642b83 | 2007-11-14 17:00:15 -0800 | [diff] [blame] | 181 | 		if (likely(!(desc->status & IRQ_DISABLED))) { | 
 | 182 | 			action_ret = handle_IRQ_event(irq, desc->action); | 
 | 183 | 			if (!noirqdebug) | 
 | 184 | 				note_interrupt(irq, desc, action_ret); | 
 | 185 | 		} | 
| Ingo Molnar | d1bef4e | 2006-06-29 02:24:36 -0700 | [diff] [blame] | 186 | 		desc->chip->end(irq); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | 		return 1; | 
 | 188 | 	} | 
 | 189 |  | 
 | 190 | 	spin_lock(&desc->lock); | 
| Ingo Molnar | d1bef4e | 2006-06-29 02:24:36 -0700 | [diff] [blame] | 191 | 	if (desc->chip->ack) | 
 | 192 | 		desc->chip->ack(irq); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | 	/* | 
 | 194 | 	 * REPLAY is when Linux resends an IRQ that was dropped earlier | 
 | 195 | 	 * WAITING is used by probe to mark irqs that are being tested | 
 | 196 | 	 */ | 
 | 197 | 	status = desc->status & ~(IRQ_REPLAY | IRQ_WAITING); | 
 | 198 | 	status |= IRQ_PENDING; /* we _want_ to handle it */ | 
 | 199 |  | 
 | 200 | 	/* | 
 | 201 | 	 * If the IRQ is disabled for whatever reason, we cannot | 
 | 202 | 	 * use the action we have. | 
 | 203 | 	 */ | 
 | 204 | 	action = NULL; | 
 | 205 | 	if (likely(!(status & (IRQ_DISABLED | IRQ_INPROGRESS)))) { | 
 | 206 | 		action = desc->action; | 
 | 207 | 		status &= ~IRQ_PENDING; /* we commit to handling */ | 
 | 208 | 		status |= IRQ_INPROGRESS; /* we are handling it */ | 
 | 209 | 	} | 
 | 210 | 	desc->status = status; | 
 | 211 |  | 
 | 212 | 	/* | 
 | 213 | 	 * If there is no IRQ handler or it was disabled, exit early. | 
 | 214 | 	 * Since we set PENDING, if another processor is handling | 
 | 215 | 	 * a different instance of this same irq, the other processor | 
 | 216 | 	 * will take care of it. | 
 | 217 | 	 */ | 
 | 218 | 	if (unlikely(!action)) | 
 | 219 | 		goto out; | 
 | 220 |  | 
 | 221 | 	/* | 
 | 222 | 	 * Edge triggered interrupts need to remember | 
 | 223 | 	 * pending events. | 
 | 224 | 	 * This applies to any hw interrupts that allow a second | 
 | 225 | 	 * instance of the same irq to arrive while we are in do_IRQ | 
 | 226 | 	 * or in the handler. But the code here only handles the _second_ | 
 | 227 | 	 * instance of the irq, not the third or fourth. So it is mostly | 
 | 228 | 	 * useful for irq hardware that does not mask cleanly in an | 
 | 229 | 	 * SMP environment. | 
 | 230 | 	 */ | 
 | 231 | 	for (;;) { | 
 | 232 | 		irqreturn_t action_ret; | 
 | 233 |  | 
 | 234 | 		spin_unlock(&desc->lock); | 
 | 235 |  | 
| David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 236 | 		action_ret = handle_IRQ_event(irq, action); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | 		if (!noirqdebug) | 
| David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 238 | 			note_interrupt(irq, desc, action_ret); | 
| Linus Torvalds | b42172f | 2006-11-22 09:32:06 -0800 | [diff] [blame] | 239 |  | 
 | 240 | 		spin_lock(&desc->lock); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | 		if (likely(!(desc->status & IRQ_PENDING))) | 
 | 242 | 			break; | 
 | 243 | 		desc->status &= ~IRQ_PENDING; | 
 | 244 | 	} | 
 | 245 | 	desc->status &= ~IRQ_INPROGRESS; | 
 | 246 |  | 
 | 247 | out: | 
 | 248 | 	/* | 
 | 249 | 	 * The ->end() handler has to deal with interrupts which got | 
 | 250 | 	 * disabled while the handler was running. | 
 | 251 | 	 */ | 
| Ingo Molnar | d1bef4e | 2006-06-29 02:24:36 -0700 | [diff] [blame] | 252 | 	desc->chip->end(irq); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | 	spin_unlock(&desc->lock); | 
 | 254 |  | 
 | 255 | 	return 1; | 
 | 256 | } | 
| David Howells | af8c65b | 2006-09-25 23:32:07 -0700 | [diff] [blame] | 257 | #endif | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 |  | 
| Ingo Molnar | 243c762 | 2006-07-03 00:25:06 -0700 | [diff] [blame] | 259 | #ifdef CONFIG_TRACE_IRQFLAGS | 
 | 260 |  | 
 | 261 | /* | 
 | 262 |  * lockdep: we want to handle all irq_desc locks as a single lock-class: | 
 | 263 |  */ | 
 | 264 | static struct lock_class_key irq_desc_lock_class; | 
 | 265 |  | 
 | 266 | void early_init_irq_lock_class(void) | 
 | 267 | { | 
 | 268 | 	int i; | 
 | 269 |  | 
 | 270 | 	for (i = 0; i < NR_IRQS; i++) | 
 | 271 | 		lockdep_set_class(&irq_desc[i].lock, &irq_desc_lock_class); | 
 | 272 | } | 
 | 273 |  | 
 | 274 | #endif |