blob: e9d022cf593ef6384e9b2cd26f1ae50e4df57584 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/kernel/irq/handle.c
3 *
Ingo Molnara34db9b2006-06-29 02:24:50 -07004 * Copyright (C) 1992, 1998-2006 Linus Torvalds, Ingo Molnar
5 * Copyright (C) 2005-2006, Thomas Gleixner, Russell King
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 *
7 * This file contains the core interrupt handling code.
Ingo Molnara34db9b2006-06-29 02:24:50 -07008 *
9 * Detailed information is available in Documentation/DocBook/genericirq
10 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070011 */
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 Gleixner6a6de9e2006-06-29 02:24:51 -070021/**
22 * handle_bad_irq - handle spurious and unhandled irqs
Henrik Kretzschmar43a1dd52006-08-31 21:27:44 -070023 * @irq: the interrupt number
24 * @desc: description of the interrupt
Henrik Kretzschmar43a1dd52006-08-31 21:27:44 -070025 *
26 * Handles spurious and unhandled IRQ's. It also prints a debugmessage.
Thomas Gleixner6a6de9e2006-06-29 02:24:51 -070027 */
Harvey Harrison7ad5b3a2008-02-08 04:19:53 -080028void
David Howells7d12e782006-10-05 14:55:46 +010029handle_bad_irq(unsigned int irq, struct irq_desc *desc)
Thomas Gleixner6a6de9e2006-06-29 02:24:51 -070030{
Ingo Molnar43f77752006-06-29 02:24:58 -070031 print_irq_desc(irq, desc);
Thomas Gleixner6a6de9e2006-06-29 02:24:51 -070032 kstat_this_cpu.irqs[irq]++;
33 ack_bad_irq(irq);
34}
35
Linus Torvalds1da177e2005-04-16 15:20:36 -070036/*
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 Molnar06fcb0c2006-06-29 02:24:40 -070040 * interrupt source is transparently wired to the appropriate
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 * 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 */
Yinghai Lu85c0f902008-08-19 20:49:47 -070050int nr_irqs = NR_IRQS;
Ravikiran G Thirumalaie729aa12007-05-08 00:29:13 -070051struct irq_desc irq_desc[NR_IRQS] __cacheline_aligned_in_smp = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070052 [0 ... NR_IRQS-1] = {
Zhang, Yanmin4f167fb2005-05-16 21:53:43 -070053 .status = IRQ_DISABLED,
Ingo Molnarf1c26622006-06-29 02:24:57 -070054 .chip = &no_irq_chip,
Ingo Molnar7a557132006-06-29 02:24:54 -070055 .handle_irq = handle_bad_irq,
Thomas Gleixner94d39e12006-06-29 02:24:50 -070056 .depth = 1,
Peter Zijlstra6cfd76a2006-12-06 20:37:22 -080057 .lock = __SPIN_LOCK_UNLOCKED(irq_desc->lock),
Ingo Molnara53da522006-06-29 02:24:38 -070058#ifdef CONFIG_SMP
59 .affinity = CPU_MASK_ALL
60#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 }
62};
63
64/*
Ingo Molnar77a5afe2006-06-29 02:24:46 -070065 * What should we do if we get a hw irq event on an illegal vector?
66 * Each architecture has to answer this themself.
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 */
Ingo Molnar77a5afe2006-06-29 02:24:46 -070068static void ack_bad(unsigned int irq)
Linus Torvalds1da177e2005-04-16 15:20:36 -070069{
Ingo Molnar43f77752006-06-29 02:24:58 -070070 print_irq_desc(irq, irq_desc + irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 ack_bad_irq(irq);
72}
73
Ingo Molnar77a5afe2006-06-29 02:24:46 -070074/*
75 * NOP functions
76 */
77static void noop(unsigned int irq)
78{
79}
80
81static unsigned int noop_ret(unsigned int irq)
82{
83 return 0;
84}
85
86/*
87 * Generic no controller implementation
88 */
Ingo Molnarf1c26622006-06-29 02:24:57 -070089struct irq_chip no_irq_chip = {
90 .name = "none",
Ingo Molnar77a5afe2006-06-29 02:24:46 -070091 .startup = noop_ret,
92 .shutdown = noop,
93 .enable = noop,
94 .disable = noop,
95 .ack = ack_bad,
96 .end = noop,
Linus Torvalds1da177e2005-04-16 15:20:36 -070097};
98
99/*
Thomas Gleixnerf8b54732006-07-01 22:30:08 +0100100 * Generic dummy implementation which can be used for
101 * real dumb interrupt sources
102 */
103struct irq_chip dummy_irq_chip = {
104 .name = "dummy",
105 .startup = noop_ret,
106 .shutdown = noop,
107 .enable = noop,
108 .disable = noop,
109 .ack = noop,
110 .mask = noop,
111 .unmask = noop,
112 .end = noop,
113};
114
115/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 * Special, empty irq handler:
117 */
David Howells7d12e782006-10-05 14:55:46 +0100118irqreturn_t no_action(int cpl, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119{
120 return IRQ_NONE;
121}
122
Ingo Molnar8d28bc72006-06-29 02:24:46 -0700123/**
124 * handle_IRQ_event - irq action chain handler
125 * @irq: the interrupt number
Ingo Molnar8d28bc72006-06-29 02:24:46 -0700126 * @action: the interrupt action chain for this irq
127 *
128 * Handles the action chain of an irq event
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 */
David Howells7d12e782006-10-05 14:55:46 +0100130irqreturn_t handle_IRQ_event(unsigned int irq, struct irqaction *action)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131{
Jan Beulich908dcec2006-06-23 02:06:00 -0700132 irqreturn_t ret, retval = IRQ_NONE;
133 unsigned int status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134
Thomas Gleixner3cca53b2006-07-01 19:29:31 -0700135 if (!(action->flags & IRQF_DISABLED))
Ingo Molnar366c7f52006-07-03 00:25:25 -0700136 local_irq_enable_in_hardirq();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137
138 do {
David Howells7d12e782006-10-05 14:55:46 +0100139 ret = action->handler(irq, action->dev_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 if (ret == IRQ_HANDLED)
141 status |= action->flags;
142 retval |= ret;
143 action = action->next;
144 } while (action);
145
Thomas Gleixner3cca53b2006-07-01 19:29:31 -0700146 if (status & IRQF_SAMPLE_RANDOM)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 add_interrupt_randomness(irq);
148 local_irq_disable();
149
150 return retval;
151}
152
David Howellsaf8c65b2006-09-25 23:32:07 -0700153#ifndef CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ
Ingo Molnar8d28bc72006-06-29 02:24:46 -0700154/**
155 * __do_IRQ - original all in one highlevel IRQ handler
156 * @irq: the interrupt number
Ingo Molnar8d28bc72006-06-29 02:24:46 -0700157 *
158 * __do_IRQ handles all normal device IRQ's (the special
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 * SMP cross-CPU interrupts have their own specific
160 * handlers).
Ingo Molnar8d28bc72006-06-29 02:24:46 -0700161 *
162 * This is the original x86 implementation which is used for every
163 * interrupt type.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 */
Harvey Harrison7ad5b3a2008-02-08 04:19:53 -0800165unsigned int __do_IRQ(unsigned int irq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166{
Ingo Molnar34ffdb72006-06-29 02:24:40 -0700167 struct irq_desc *desc = irq_desc + irq;
Ingo Molnar06fcb0c2006-06-29 02:24:40 -0700168 struct irqaction *action;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 unsigned int status;
170
171 kstat_this_cpu.irqs[irq]++;
Karsten Wiesef26fdd52005-09-06 15:17:25 -0700172 if (CHECK_IRQ_PER_CPU(desc->status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 irqreturn_t action_ret;
174
175 /*
176 * No locking required for CPU-local interrupts:
177 */
Ingo Molnard1bef4e2006-06-29 02:24:36 -0700178 if (desc->chip->ack)
179 desc->chip->ack(irq);
Russ Andersonc642b832007-11-14 17:00:15 -0800180 if (likely(!(desc->status & IRQ_DISABLED))) {
181 action_ret = handle_IRQ_event(irq, desc->action);
182 if (!noirqdebug)
183 note_interrupt(irq, desc, action_ret);
184 }
Ingo Molnard1bef4e2006-06-29 02:24:36 -0700185 desc->chip->end(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 return 1;
187 }
188
189 spin_lock(&desc->lock);
Ingo Molnard1bef4e2006-06-29 02:24:36 -0700190 if (desc->chip->ack)
191 desc->chip->ack(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 /*
193 * REPLAY is when Linux resends an IRQ that was dropped earlier
194 * WAITING is used by probe to mark irqs that are being tested
195 */
196 status = desc->status & ~(IRQ_REPLAY | IRQ_WAITING);
197 status |= IRQ_PENDING; /* we _want_ to handle it */
198
199 /*
200 * If the IRQ is disabled for whatever reason, we cannot
201 * use the action we have.
202 */
203 action = NULL;
204 if (likely(!(status & (IRQ_DISABLED | IRQ_INPROGRESS)))) {
205 action = desc->action;
206 status &= ~IRQ_PENDING; /* we commit to handling */
207 status |= IRQ_INPROGRESS; /* we are handling it */
208 }
209 desc->status = status;
210
211 /*
212 * If there is no IRQ handler or it was disabled, exit early.
213 * Since we set PENDING, if another processor is handling
214 * a different instance of this same irq, the other processor
215 * will take care of it.
216 */
217 if (unlikely(!action))
218 goto out;
219
220 /*
221 * Edge triggered interrupts need to remember
222 * pending events.
223 * This applies to any hw interrupts that allow a second
224 * instance of the same irq to arrive while we are in do_IRQ
225 * or in the handler. But the code here only handles the _second_
226 * instance of the irq, not the third or fourth. So it is mostly
227 * useful for irq hardware that does not mask cleanly in an
228 * SMP environment.
229 */
230 for (;;) {
231 irqreturn_t action_ret;
232
233 spin_unlock(&desc->lock);
234
David Howells7d12e782006-10-05 14:55:46 +0100235 action_ret = handle_IRQ_event(irq, action);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 if (!noirqdebug)
David Howells7d12e782006-10-05 14:55:46 +0100237 note_interrupt(irq, desc, action_ret);
Linus Torvaldsb42172f2006-11-22 09:32:06 -0800238
239 spin_lock(&desc->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 if (likely(!(desc->status & IRQ_PENDING)))
241 break;
242 desc->status &= ~IRQ_PENDING;
243 }
244 desc->status &= ~IRQ_INPROGRESS;
245
246out:
247 /*
248 * The ->end() handler has to deal with interrupts which got
249 * disabled while the handler was running.
250 */
Ingo Molnard1bef4e2006-06-29 02:24:36 -0700251 desc->chip->end(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 spin_unlock(&desc->lock);
253
254 return 1;
255}
David Howellsaf8c65b2006-09-25 23:32:07 -0700256#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257
Ingo Molnar243c7622006-07-03 00:25:06 -0700258#ifdef CONFIG_TRACE_IRQFLAGS
259
260/*
261 * lockdep: we want to handle all irq_desc locks as a single lock-class:
262 */
263static struct lock_class_key irq_desc_lock_class;
264
265void early_init_irq_lock_class(void)
266{
267 int i;
268
Yinghai Lu85c0f902008-08-19 20:49:47 -0700269 for (i = 0; i < nr_irqs; i++)
Ingo Molnar243c7622006-07-03 00:25:06 -0700270 lockdep_set_class(&irq_desc[i].lock, &irq_desc_lock_class);
271}
272
273#endif