blob: f4c8a03a9fbb12eccf046feb12aa36a6654d864d [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 */
Ravikiran G Thirumalaie729aa12007-05-08 00:29:13 -070050struct irq_desc irq_desc[NR_IRQS] __cacheline_aligned_in_smp = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 [0 ... NR_IRQS-1] = {
Zhang, Yanmin4f167fb2005-05-16 21:53:43 -070052 .status = IRQ_DISABLED,
Ingo Molnarf1c26622006-06-29 02:24:57 -070053 .chip = &no_irq_chip,
Ingo Molnar7a557132006-06-29 02:24:54 -070054 .handle_irq = handle_bad_irq,
Thomas Gleixner94d39e12006-06-29 02:24:50 -070055 .depth = 1,
Peter Zijlstra6cfd76a2006-12-06 20:37:22 -080056 .lock = __SPIN_LOCK_UNLOCKED(irq_desc->lock),
Ingo Molnara53da522006-06-29 02:24:38 -070057#ifdef CONFIG_SMP
58 .affinity = CPU_MASK_ALL
59#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 }
61};
62
63/*
Ingo Molnar77a5afe2006-06-29 02:24:46 -070064 * What should we do if we get a hw irq event on an illegal vector?
65 * Each architecture has to answer this themself.
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 */
Ingo Molnar77a5afe2006-06-29 02:24:46 -070067static void ack_bad(unsigned int irq)
Linus Torvalds1da177e2005-04-16 15:20:36 -070068{
Ingo Molnar43f77752006-06-29 02:24:58 -070069 print_irq_desc(irq, irq_desc + irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 ack_bad_irq(irq);
71}
72
Ingo Molnar77a5afe2006-06-29 02:24:46 -070073/*
74 * NOP functions
75 */
76static void noop(unsigned int irq)
77{
78}
79
80static unsigned int noop_ret(unsigned int irq)
81{
82 return 0;
83}
84
85/*
86 * Generic no controller implementation
87 */
Ingo Molnarf1c26622006-06-29 02:24:57 -070088struct irq_chip no_irq_chip = {
89 .name = "none",
Ingo Molnar77a5afe2006-06-29 02:24:46 -070090 .startup = noop_ret,
91 .shutdown = noop,
92 .enable = noop,
93 .disable = noop,
94 .ack = ack_bad,
95 .end = noop,
Linus Torvalds1da177e2005-04-16 15:20:36 -070096};
97
98/*
Thomas Gleixnerf8b54732006-07-01 22:30:08 +010099 * Generic dummy implementation which can be used for
100 * real dumb interrupt sources
101 */
102struct 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 Torvalds1da177e2005-04-16 15:20:36 -0700115 * Special, empty irq handler:
116 */
David Howells7d12e782006-10-05 14:55:46 +0100117irqreturn_t no_action(int cpl, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118{
119 return IRQ_NONE;
120}
121
Ingo Molnar8d28bc72006-06-29 02:24:46 -0700122/**
123 * handle_IRQ_event - irq action chain handler
124 * @irq: the interrupt number
Ingo Molnar8d28bc72006-06-29 02:24:46 -0700125 * @action: the interrupt action chain for this irq
126 *
127 * Handles the action chain of an irq event
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 */
David Howells7d12e782006-10-05 14:55:46 +0100129irqreturn_t handle_IRQ_event(unsigned int irq, struct irqaction *action)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130{
Jan Beulich908dcec2006-06-23 02:06:00 -0700131 irqreturn_t ret, retval = IRQ_NONE;
132 unsigned int status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133
Thomas Gleixner3cca53b2006-07-01 19:29:31 -0700134 if (!(action->flags & IRQF_DISABLED))
Ingo Molnar366c7f52006-07-03 00:25:25 -0700135 local_irq_enable_in_hardirq();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136
137 do {
David Howells7d12e782006-10-05 14:55:46 +0100138 ret = action->handler(irq, action->dev_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 if (ret == IRQ_HANDLED)
140 status |= action->flags;
141 retval |= ret;
142 action = action->next;
143 } while (action);
144
Thomas Gleixner3cca53b2006-07-01 19:29:31 -0700145 if (status & IRQF_SAMPLE_RANDOM)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 add_interrupt_randomness(irq);
147 local_irq_disable();
148
149 return retval;
150}
151
David Howellsaf8c65b2006-09-25 23:32:07 -0700152#ifndef CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ
Ingo Molnar8d28bc72006-06-29 02:24:46 -0700153/**
154 * __do_IRQ - original all in one highlevel IRQ handler
155 * @irq: the interrupt number
Ingo Molnar8d28bc72006-06-29 02:24:46 -0700156 *
157 * __do_IRQ handles all normal device IRQ's (the special
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 * SMP cross-CPU interrupts have their own specific
159 * handlers).
Ingo Molnar8d28bc72006-06-29 02:24:46 -0700160 *
161 * This is the original x86 implementation which is used for every
162 * interrupt type.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 */
Harvey Harrison7ad5b3a2008-02-08 04:19:53 -0800164unsigned int __do_IRQ(unsigned int irq)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165{
Ingo Molnar34ffdb72006-06-29 02:24:40 -0700166 struct irq_desc *desc = irq_desc + irq;
Ingo Molnar06fcb0c2006-06-29 02:24:40 -0700167 struct irqaction *action;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 unsigned int status;
169
170 kstat_this_cpu.irqs[irq]++;
Karsten Wiesef26fdd52005-09-06 15:17:25 -0700171 if (CHECK_IRQ_PER_CPU(desc->status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 irqreturn_t action_ret;
173
174 /*
175 * No locking required for CPU-local interrupts:
176 */
Ingo Molnard1bef4e2006-06-29 02:24:36 -0700177 if (desc->chip->ack)
178 desc->chip->ack(irq);
Russ Andersonc642b832007-11-14 17:00:15 -0800179 if (likely(!(desc->status & IRQ_DISABLED))) {
180 action_ret = handle_IRQ_event(irq, desc->action);
181 if (!noirqdebug)
182 note_interrupt(irq, desc, action_ret);
183 }
Ingo Molnard1bef4e2006-06-29 02:24:36 -0700184 desc->chip->end(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 return 1;
186 }
187
188 spin_lock(&desc->lock);
Ingo Molnard1bef4e2006-06-29 02:24:36 -0700189 if (desc->chip->ack)
190 desc->chip->ack(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 /*
192 * REPLAY is when Linux resends an IRQ that was dropped earlier
193 * WAITING is used by probe to mark irqs that are being tested
194 */
195 status = desc->status & ~(IRQ_REPLAY | IRQ_WAITING);
196 status |= IRQ_PENDING; /* we _want_ to handle it */
197
198 /*
199 * If the IRQ is disabled for whatever reason, we cannot
200 * use the action we have.
201 */
202 action = NULL;
203 if (likely(!(status & (IRQ_DISABLED | IRQ_INPROGRESS)))) {
204 action = desc->action;
205 status &= ~IRQ_PENDING; /* we commit to handling */
206 status |= IRQ_INPROGRESS; /* we are handling it */
207 }
208 desc->status = status;
209
210 /*
211 * If there is no IRQ handler or it was disabled, exit early.
212 * Since we set PENDING, if another processor is handling
213 * a different instance of this same irq, the other processor
214 * will take care of it.
215 */
216 if (unlikely(!action))
217 goto out;
218
219 /*
220 * Edge triggered interrupts need to remember
221 * pending events.
222 * This applies to any hw interrupts that allow a second
223 * instance of the same irq to arrive while we are in do_IRQ
224 * or in the handler. But the code here only handles the _second_
225 * instance of the irq, not the third or fourth. So it is mostly
226 * useful for irq hardware that does not mask cleanly in an
227 * SMP environment.
228 */
229 for (;;) {
230 irqreturn_t action_ret;
231
232 spin_unlock(&desc->lock);
233
David Howells7d12e782006-10-05 14:55:46 +0100234 action_ret = handle_IRQ_event(irq, action);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 if (!noirqdebug)
David Howells7d12e782006-10-05 14:55:46 +0100236 note_interrupt(irq, desc, action_ret);
Linus Torvaldsb42172f2006-11-22 09:32:06 -0800237
238 spin_lock(&desc->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 if (likely(!(desc->status & IRQ_PENDING)))
240 break;
241 desc->status &= ~IRQ_PENDING;
242 }
243 desc->status &= ~IRQ_INPROGRESS;
244
245out:
246 /*
247 * The ->end() handler has to deal with interrupts which got
248 * disabled while the handler was running.
249 */
Ingo Molnard1bef4e2006-06-29 02:24:36 -0700250 desc->chip->end(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 spin_unlock(&desc->lock);
252
253 return 1;
254}
David Howellsaf8c65b2006-09-25 23:32:07 -0700255#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256
Ingo Molnar243c7622006-07-03 00:25:06 -0700257#ifdef CONFIG_TRACE_IRQFLAGS
258
259/*
260 * lockdep: we want to handle all irq_desc locks as a single lock-class:
261 */
262static struct lock_class_key irq_desc_lock_class;
263
264void early_init_irq_lock_class(void)
265{
266 int i;
267
268 for (i = 0; i < NR_IRQS; i++)
269 lockdep_set_class(&irq_desc[i].lock, &irq_desc_lock_class);
270}
271
272#endif