2 * linux/kernel/irq/handle.c
4 * Copyright (C) 1992, 1998-2006 Linus Torvalds, Ingo Molnar
5 * Copyright (C) 2005-2006, Thomas Gleixner, Russell King
7 * This file contains the core interrupt handling code.
9 * Detailed information is available in Documentation/DocBook/genericirq
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>
19 #include "internals.h"
22 * handle_bad_irq - handle spurious and unhandled irqs
23 * @irq: the interrupt number
24 * @desc: description of the interrupt
26 * Handles spurious and unhandled IRQ's. It also prints a debugmessage.
29 handle_bad_irq(unsigned int irq, struct irq_desc *desc)
31 print_irq_desc(irq, desc);
32 kstat_this_cpu.irqs[irq]++;
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
40 * interrupt source is transparently wired to the appropriate
41 * controller. Thus drivers need not be aware of the
42 * interrupt-controller.
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.
48 * Controller mappings for all interrupt sources:
50 int nr_irqs = NR_IRQS;
51 EXPORT_SYMBOL_GPL(nr_irqs);
53 #ifdef CONFIG_HAVE_DYN_ARRAY
54 static struct irq_desc irq_desc_init __initdata = {
55 .status = IRQ_DISABLED,
57 .handle_irq = handle_bad_irq,
59 .lock = __SPIN_LOCK_UNLOCKED(irq_desc_init.lock),
61 .affinity = CPU_MASK_ALL
65 static void __init init_work(void *data)
67 struct dyn_array *da = data;
69 struct irq_desc *desc;
73 for (i = 0; i < *da->nr; i++)
74 memcpy(&desc[i], &irq_desc_init, sizeof(struct irq_desc));
77 struct irq_desc *irq_desc;
78 DEFINE_DYN_ARRAY(irq_desc, sizeof(struct irq_desc), nr_irqs, PAGE_SIZE, init_work);
82 struct irq_desc irq_desc[NR_IRQS] __cacheline_aligned_in_smp = {
84 .status = IRQ_DISABLED,
86 .handle_irq = handle_bad_irq,
88 .lock = __SPIN_LOCK_UNLOCKED(irq_desc->lock),
90 .affinity = CPU_MASK_ALL
97 * What should we do if we get a hw irq event on an illegal vector?
98 * Each architecture has to answer this themself.
100 static void ack_bad(unsigned int irq)
102 print_irq_desc(irq, irq_desc + irq);
109 static void noop(unsigned int irq)
113 static unsigned int noop_ret(unsigned int irq)
119 * Generic no controller implementation
121 struct irq_chip no_irq_chip = {
132 * Generic dummy implementation which can be used for
133 * real dumb interrupt sources
135 struct irq_chip dummy_irq_chip = {
148 * Special, empty irq handler:
150 irqreturn_t no_action(int cpl, void *dev_id)
156 * handle_IRQ_event - irq action chain handler
157 * @irq: the interrupt number
158 * @action: the interrupt action chain for this irq
160 * Handles the action chain of an irq event
162 irqreturn_t handle_IRQ_event(unsigned int irq, struct irqaction *action)
164 irqreturn_t ret, retval = IRQ_NONE;
165 unsigned int status = 0;
167 if (!(action->flags & IRQF_DISABLED))
168 local_irq_enable_in_hardirq();
171 ret = action->handler(irq, action->dev_id);
172 if (ret == IRQ_HANDLED)
173 status |= action->flags;
175 action = action->next;
178 if (status & IRQF_SAMPLE_RANDOM)
179 add_interrupt_randomness(irq);
185 #ifndef CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ
187 * __do_IRQ - original all in one highlevel IRQ handler
188 * @irq: the interrupt number
190 * __do_IRQ handles all normal device IRQ's (the special
191 * SMP cross-CPU interrupts have their own specific
194 * This is the original x86 implementation which is used for every
197 unsigned int __do_IRQ(unsigned int irq)
199 struct irq_desc *desc = irq_desc + irq;
200 struct irqaction *action;
203 kstat_this_cpu.irqs[irq]++;
204 if (CHECK_IRQ_PER_CPU(desc->status)) {
205 irqreturn_t action_ret;
208 * No locking required for CPU-local interrupts:
211 desc->chip->ack(irq);
212 if (likely(!(desc->status & IRQ_DISABLED))) {
213 action_ret = handle_IRQ_event(irq, desc->action);
215 note_interrupt(irq, desc, action_ret);
217 desc->chip->end(irq);
221 spin_lock(&desc->lock);
223 desc->chip->ack(irq);
225 * REPLAY is when Linux resends an IRQ that was dropped earlier
226 * WAITING is used by probe to mark irqs that are being tested
228 status = desc->status & ~(IRQ_REPLAY | IRQ_WAITING);
229 status |= IRQ_PENDING; /* we _want_ to handle it */
232 * If the IRQ is disabled for whatever reason, we cannot
233 * use the action we have.
236 if (likely(!(status & (IRQ_DISABLED | IRQ_INPROGRESS)))) {
237 action = desc->action;
238 status &= ~IRQ_PENDING; /* we commit to handling */
239 status |= IRQ_INPROGRESS; /* we are handling it */
241 desc->status = status;
244 * If there is no IRQ handler or it was disabled, exit early.
245 * Since we set PENDING, if another processor is handling
246 * a different instance of this same irq, the other processor
247 * will take care of it.
249 if (unlikely(!action))
253 * Edge triggered interrupts need to remember
255 * This applies to any hw interrupts that allow a second
256 * instance of the same irq to arrive while we are in do_IRQ
257 * or in the handler. But the code here only handles the _second_
258 * instance of the irq, not the third or fourth. So it is mostly
259 * useful for irq hardware that does not mask cleanly in an
263 irqreturn_t action_ret;
265 spin_unlock(&desc->lock);
267 action_ret = handle_IRQ_event(irq, action);
269 note_interrupt(irq, desc, action_ret);
271 spin_lock(&desc->lock);
272 if (likely(!(desc->status & IRQ_PENDING)))
274 desc->status &= ~IRQ_PENDING;
276 desc->status &= ~IRQ_INPROGRESS;
280 * The ->end() handler has to deal with interrupts which got
281 * disabled while the handler was running.
283 desc->chip->end(irq);
284 spin_unlock(&desc->lock);
290 #ifdef CONFIG_TRACE_IRQFLAGS
293 * lockdep: we want to handle all irq_desc locks as a single lock-class:
295 static struct lock_class_key irq_desc_lock_class;
297 void early_init_irq_lock_class(void)
301 for (i = 0; i < nr_irqs; i++)
302 lockdep_set_class(&irq_desc[i].lock, &irq_desc_lock_class);