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 * Linux has a controller-independent interrupt architecture.
23 * Every controller has a 'controller-template', that is used
24 * by the main code to do the right thing. Each driver-visible
25 * interrupt source is transparently wired to the appropriate
26 * controller. Thus drivers need not be aware of the
27 * interrupt-controller.
29 * The code is designed to be easily extended with new/different
30 * interrupt controllers, without having to do assembly magic or
31 * having to touch the generic code.
33 * Controller mappings for all interrupt sources:
35 struct irq_desc irq_desc[NR_IRQS] __cacheline_aligned = {
37 .status = IRQ_DISABLED,
40 .lock = SPIN_LOCK_UNLOCKED,
42 .affinity = CPU_MASK_ALL
48 * What should we do if we get a hw irq event on an illegal vector?
49 * Each architecture has to answer this themself.
51 static void ack_bad(unsigned int irq)
59 static void noop(unsigned int irq)
63 static unsigned int noop_ret(unsigned int irq)
69 * Generic no controller implementation
71 struct hw_interrupt_type no_irq_type = {
82 * Special, empty irq handler:
84 irqreturn_t no_action(int cpl, void *dev_id, struct pt_regs *regs)
90 * handle_IRQ_event - irq action chain handler
91 * @irq: the interrupt number
92 * @regs: pointer to a register structure
93 * @action: the interrupt action chain for this irq
95 * Handles the action chain of an irq event
97 irqreturn_t handle_IRQ_event(unsigned int irq, struct pt_regs *regs,
98 struct irqaction *action)
100 irqreturn_t ret, retval = IRQ_NONE;
101 unsigned int status = 0;
103 if (!(action->flags & SA_INTERRUPT))
107 ret = action->handler(irq, action->dev_id, regs);
108 if (ret == IRQ_HANDLED)
109 status |= action->flags;
111 action = action->next;
114 if (status & SA_SAMPLE_RANDOM)
115 add_interrupt_randomness(irq);
122 * __do_IRQ - original all in one highlevel IRQ handler
123 * @irq: the interrupt number
124 * @regs: pointer to a register structure
126 * __do_IRQ handles all normal device IRQ's (the special
127 * SMP cross-CPU interrupts have their own specific
130 * This is the original x86 implementation which is used for every
133 fastcall unsigned int __do_IRQ(unsigned int irq, struct pt_regs *regs)
135 struct irq_desc *desc = irq_desc + irq;
136 struct irqaction *action;
139 kstat_this_cpu.irqs[irq]++;
140 if (CHECK_IRQ_PER_CPU(desc->status)) {
141 irqreturn_t action_ret;
144 * No locking required for CPU-local interrupts:
147 desc->chip->ack(irq);
148 action_ret = handle_IRQ_event(irq, regs, desc->action);
149 desc->chip->end(irq);
153 spin_lock(&desc->lock);
155 desc->chip->ack(irq);
157 * REPLAY is when Linux resends an IRQ that was dropped earlier
158 * WAITING is used by probe to mark irqs that are being tested
160 status = desc->status & ~(IRQ_REPLAY | IRQ_WAITING);
161 status |= IRQ_PENDING; /* we _want_ to handle it */
164 * If the IRQ is disabled for whatever reason, we cannot
165 * use the action we have.
168 if (likely(!(status & (IRQ_DISABLED | IRQ_INPROGRESS)))) {
169 action = desc->action;
170 status &= ~IRQ_PENDING; /* we commit to handling */
171 status |= IRQ_INPROGRESS; /* we are handling it */
173 desc->status = status;
176 * If there is no IRQ handler or it was disabled, exit early.
177 * Since we set PENDING, if another processor is handling
178 * a different instance of this same irq, the other processor
179 * will take care of it.
181 if (unlikely(!action))
185 * Edge triggered interrupts need to remember
187 * This applies to any hw interrupts that allow a second
188 * instance of the same irq to arrive while we are in do_IRQ
189 * or in the handler. But the code here only handles the _second_
190 * instance of the irq, not the third or fourth. So it is mostly
191 * useful for irq hardware that does not mask cleanly in an
195 irqreturn_t action_ret;
197 spin_unlock(&desc->lock);
199 action_ret = handle_IRQ_event(irq, regs, action);
201 spin_lock(&desc->lock);
203 note_interrupt(irq, desc, action_ret, regs);
204 if (likely(!(desc->status & IRQ_PENDING)))
206 desc->status &= ~IRQ_PENDING;
208 desc->status &= ~IRQ_INPROGRESS;
212 * The ->end() handler has to deal with interrupts which got
213 * disabled while the handler was running.
215 desc->chip->end(irq);
216 spin_unlock(&desc->lock);