2 * linux/kernel/irq/handle.c
4 * Copyright (C) 1992, 1998-2004 Linus Torvalds, Ingo Molnar
6 * This file contains the core interrupt handling code.
10 #include <linux/module.h>
11 #include <linux/random.h>
12 #include <linux/interrupt.h>
13 #include <linux/kernel_stat.h>
15 #include "internals.h"
18 * Linux has a controller-independent interrupt architecture.
19 * Every controller has a 'controller-template', that is used
20 * by the main code to do the right thing. Each driver-visible
21 * interrupt source is transparently wired to the appropriate
22 * controller. Thus drivers need not be aware of the
23 * interrupt-controller.
25 * The code is designed to be easily extended with new/different
26 * interrupt controllers, without having to do assembly magic or
27 * having to touch the generic code.
29 * Controller mappings for all interrupt sources:
31 struct irq_desc irq_desc[NR_IRQS] __cacheline_aligned = {
33 .status = IRQ_DISABLED,
36 .lock = SPIN_LOCK_UNLOCKED,
38 .affinity = CPU_MASK_ALL
44 * What should we do if we get a hw irq event on an illegal vector?
45 * Each architecture has to answer this themself.
47 static void ack_bad(unsigned int irq)
55 static void noop(unsigned int irq)
59 static unsigned int noop_ret(unsigned int irq)
65 * Generic no controller implementation
67 struct hw_interrupt_type no_irq_type = {
78 * Special, empty irq handler:
80 irqreturn_t no_action(int cpl, void *dev_id, struct pt_regs *regs)
86 * handle_IRQ_event - irq action chain handler
87 * @irq: the interrupt number
88 * @regs: pointer to a register structure
89 * @action: the interrupt action chain for this irq
91 * Handles the action chain of an irq event
93 irqreturn_t handle_IRQ_event(unsigned int irq, struct pt_regs *regs,
94 struct irqaction *action)
96 irqreturn_t ret, retval = IRQ_NONE;
97 unsigned int status = 0;
99 if (!(action->flags & SA_INTERRUPT))
103 ret = action->handler(irq, action->dev_id, regs);
104 if (ret == IRQ_HANDLED)
105 status |= action->flags;
107 action = action->next;
110 if (status & SA_SAMPLE_RANDOM)
111 add_interrupt_randomness(irq);
118 * __do_IRQ - original all in one highlevel IRQ handler
119 * @irq: the interrupt number
120 * @regs: pointer to a register structure
122 * __do_IRQ handles all normal device IRQ's (the special
123 * SMP cross-CPU interrupts have their own specific
126 * This is the original x86 implementation which is used for every
129 fastcall unsigned int __do_IRQ(unsigned int irq, struct pt_regs *regs)
131 struct irq_desc *desc = irq_desc + irq;
132 struct irqaction *action;
135 kstat_this_cpu.irqs[irq]++;
136 if (CHECK_IRQ_PER_CPU(desc->status)) {
137 irqreturn_t action_ret;
140 * No locking required for CPU-local interrupts:
143 desc->chip->ack(irq);
144 action_ret = handle_IRQ_event(irq, regs, desc->action);
145 desc->chip->end(irq);
149 spin_lock(&desc->lock);
151 desc->chip->ack(irq);
153 * REPLAY is when Linux resends an IRQ that was dropped earlier
154 * WAITING is used by probe to mark irqs that are being tested
156 status = desc->status & ~(IRQ_REPLAY | IRQ_WAITING);
157 status |= IRQ_PENDING; /* we _want_ to handle it */
160 * If the IRQ is disabled for whatever reason, we cannot
161 * use the action we have.
164 if (likely(!(status & (IRQ_DISABLED | IRQ_INPROGRESS)))) {
165 action = desc->action;
166 status &= ~IRQ_PENDING; /* we commit to handling */
167 status |= IRQ_INPROGRESS; /* we are handling it */
169 desc->status = status;
172 * If there is no IRQ handler or it was disabled, exit early.
173 * Since we set PENDING, if another processor is handling
174 * a different instance of this same irq, the other processor
175 * will take care of it.
177 if (unlikely(!action))
181 * Edge triggered interrupts need to remember
183 * This applies to any hw interrupts that allow a second
184 * instance of the same irq to arrive while we are in do_IRQ
185 * or in the handler. But the code here only handles the _second_
186 * instance of the irq, not the third or fourth. So it is mostly
187 * useful for irq hardware that does not mask cleanly in an
191 irqreturn_t action_ret;
193 spin_unlock(&desc->lock);
195 action_ret = handle_IRQ_event(irq, regs, action);
197 spin_lock(&desc->lock);
199 note_interrupt(irq, desc, action_ret, regs);
200 if (likely(!(desc->status & IRQ_PENDING)))
202 desc->status &= ~IRQ_PENDING;
204 desc->status &= ~IRQ_INPROGRESS;
208 * The ->end() handler has to deal with interrupts which got
209 * disabled while the handler was running.
211 desc->chip->end(irq);
212 spin_unlock(&desc->lock);