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 #if defined(CONFIG_NO_IDLE_HZ) && defined(CONFIG_ARM)
20 #include <asm/dyntick.h>
23 #include "internals.h"
26 * handle_bad_irq - handle spurious and unhandled irqs
29 handle_bad_irq(unsigned int irq, struct irq_desc *desc, struct pt_regs *regs)
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 struct irq_desc irq_desc[NR_IRQS] __cacheline_aligned = {
52 .status = IRQ_DISABLED,
54 .handle_irq = handle_bad_irq,
56 .lock = SPIN_LOCK_UNLOCKED,
58 .affinity = CPU_MASK_ALL
64 * What should we do if we get a hw irq event on an illegal vector?
65 * Each architecture has to answer this themself.
67 static void ack_bad(unsigned int irq)
69 print_irq_desc(irq, irq_desc + irq);
76 static void noop(unsigned int irq)
80 static unsigned int noop_ret(unsigned int irq)
86 * Generic no controller implementation
88 struct irq_chip no_irq_chip = {
99 * Generic dummy implementation which can be used for
100 * real dumb interrupt sources
102 struct irq_chip dummy_irq_chip = {
115 * Special, empty irq handler:
117 irqreturn_t no_action(int cpl, void *dev_id, struct pt_regs *regs)
123 * handle_IRQ_event - irq action chain handler
124 * @irq: the interrupt number
125 * @regs: pointer to a register structure
126 * @action: the interrupt action chain for this irq
128 * Handles the action chain of an irq event
130 irqreturn_t handle_IRQ_event(unsigned int irq, struct pt_regs *regs,
131 struct irqaction *action)
133 irqreturn_t ret, retval = IRQ_NONE;
134 unsigned int status = 0;
136 #if defined(CONFIG_NO_IDLE_HZ) && defined(CONFIG_ARM)
137 if (!(action->flags & SA_TIMER) && system_timer->dyn_tick != NULL) {
138 write_seqlock(&xtime_lock);
139 if (system_timer->dyn_tick->state & DYN_TICK_ENABLED)
140 system_timer->dyn_tick->handler(irq, 0, regs);
141 write_sequnlock(&xtime_lock);
145 if (!(action->flags & IRQF_DISABLED))
149 ret = action->handler(irq, action->dev_id, regs);
150 if (ret == IRQ_HANDLED)
151 status |= action->flags;
153 action = action->next;
156 if (status & IRQF_SAMPLE_RANDOM)
157 add_interrupt_randomness(irq);
164 * __do_IRQ - original all in one highlevel IRQ handler
165 * @irq: the interrupt number
166 * @regs: pointer to a register structure
168 * __do_IRQ handles all normal device IRQ's (the special
169 * SMP cross-CPU interrupts have their own specific
172 * This is the original x86 implementation which is used for every
175 fastcall unsigned int __do_IRQ(unsigned int irq, struct pt_regs *regs)
177 struct irq_desc *desc = irq_desc + irq;
178 struct irqaction *action;
181 kstat_this_cpu.irqs[irq]++;
182 if (CHECK_IRQ_PER_CPU(desc->status)) {
183 irqreturn_t action_ret;
186 * No locking required for CPU-local interrupts:
189 desc->chip->ack(irq);
190 action_ret = handle_IRQ_event(irq, regs, desc->action);
191 desc->chip->end(irq);
195 spin_lock(&desc->lock);
197 desc->chip->ack(irq);
199 * REPLAY is when Linux resends an IRQ that was dropped earlier
200 * WAITING is used by probe to mark irqs that are being tested
202 status = desc->status & ~(IRQ_REPLAY | IRQ_WAITING);
203 status |= IRQ_PENDING; /* we _want_ to handle it */
206 * If the IRQ is disabled for whatever reason, we cannot
207 * use the action we have.
210 if (likely(!(status & (IRQ_DISABLED | IRQ_INPROGRESS)))) {
211 action = desc->action;
212 status &= ~IRQ_PENDING; /* we commit to handling */
213 status |= IRQ_INPROGRESS; /* we are handling it */
215 desc->status = status;
218 * If there is no IRQ handler or it was disabled, exit early.
219 * Since we set PENDING, if another processor is handling
220 * a different instance of this same irq, the other processor
221 * will take care of it.
223 if (unlikely(!action))
227 * Edge triggered interrupts need to remember
229 * This applies to any hw interrupts that allow a second
230 * instance of the same irq to arrive while we are in do_IRQ
231 * or in the handler. But the code here only handles the _second_
232 * instance of the irq, not the third or fourth. So it is mostly
233 * useful for irq hardware that does not mask cleanly in an
237 irqreturn_t action_ret;
239 spin_unlock(&desc->lock);
241 action_ret = handle_IRQ_event(irq, regs, action);
243 spin_lock(&desc->lock);
245 note_interrupt(irq, desc, action_ret, regs);
246 if (likely(!(desc->status & IRQ_PENDING)))
248 desc->status &= ~IRQ_PENDING;
250 desc->status &= ~IRQ_INPROGRESS;
254 * The ->end() handler has to deal with interrupts which got
255 * disabled while the handler was running.
257 desc->chip->end(irq);
258 spin_unlock(&desc->lock);