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
25 handle_bad_irq(unsigned int irq, struct irq_desc *desc, struct pt_regs *regs)
27 kstat_this_cpu.irqs[irq]++;
32 * Linux has a controller-independent interrupt architecture.
33 * Every controller has a 'controller-template', that is used
34 * by the main code to do the right thing. Each driver-visible
35 * interrupt source is transparently wired to the appropriate
36 * controller. Thus drivers need not be aware of the
37 * interrupt-controller.
39 * The code is designed to be easily extended with new/different
40 * interrupt controllers, without having to do assembly magic or
41 * having to touch the generic code.
43 * Controller mappings for all interrupt sources:
45 struct irq_desc irq_desc[NR_IRQS] __cacheline_aligned = {
47 .status = IRQ_DISABLED,
50 .lock = SPIN_LOCK_UNLOCKED,
52 .affinity = CPU_MASK_ALL
58 * What should we do if we get a hw irq event on an illegal vector?
59 * Each architecture has to answer this themself.
61 static void ack_bad(unsigned int irq)
69 static void noop(unsigned int irq)
73 static unsigned int noop_ret(unsigned int irq)
79 * Generic no controller implementation
81 struct hw_interrupt_type no_irq_type = {
92 * Special, empty irq handler:
94 irqreturn_t no_action(int cpl, void *dev_id, struct pt_regs *regs)
100 * handle_IRQ_event - irq action chain handler
101 * @irq: the interrupt number
102 * @regs: pointer to a register structure
103 * @action: the interrupt action chain for this irq
105 * Handles the action chain of an irq event
107 irqreturn_t handle_IRQ_event(unsigned int irq, struct pt_regs *regs,
108 struct irqaction *action)
110 irqreturn_t ret, retval = IRQ_NONE;
111 unsigned int status = 0;
113 if (!(action->flags & SA_INTERRUPT))
117 ret = action->handler(irq, action->dev_id, regs);
118 if (ret == IRQ_HANDLED)
119 status |= action->flags;
121 action = action->next;
124 if (status & SA_SAMPLE_RANDOM)
125 add_interrupt_randomness(irq);
132 * __do_IRQ - original all in one highlevel IRQ handler
133 * @irq: the interrupt number
134 * @regs: pointer to a register structure
136 * __do_IRQ handles all normal device IRQ's (the special
137 * SMP cross-CPU interrupts have their own specific
140 * This is the original x86 implementation which is used for every
143 fastcall unsigned int __do_IRQ(unsigned int irq, struct pt_regs *regs)
145 struct irq_desc *desc = irq_desc + irq;
146 struct irqaction *action;
149 kstat_this_cpu.irqs[irq]++;
150 if (CHECK_IRQ_PER_CPU(desc->status)) {
151 irqreturn_t action_ret;
154 * No locking required for CPU-local interrupts:
157 desc->chip->ack(irq);
158 action_ret = handle_IRQ_event(irq, regs, desc->action);
159 desc->chip->end(irq);
163 spin_lock(&desc->lock);
165 desc->chip->ack(irq);
167 * REPLAY is when Linux resends an IRQ that was dropped earlier
168 * WAITING is used by probe to mark irqs that are being tested
170 status = desc->status & ~(IRQ_REPLAY | IRQ_WAITING);
171 status |= IRQ_PENDING; /* we _want_ to handle it */
174 * If the IRQ is disabled for whatever reason, we cannot
175 * use the action we have.
178 if (likely(!(status & (IRQ_DISABLED | IRQ_INPROGRESS)))) {
179 action = desc->action;
180 status &= ~IRQ_PENDING; /* we commit to handling */
181 status |= IRQ_INPROGRESS; /* we are handling it */
183 desc->status = status;
186 * If there is no IRQ handler or it was disabled, exit early.
187 * Since we set PENDING, if another processor is handling
188 * a different instance of this same irq, the other processor
189 * will take care of it.
191 if (unlikely(!action))
195 * Edge triggered interrupts need to remember
197 * This applies to any hw interrupts that allow a second
198 * instance of the same irq to arrive while we are in do_IRQ
199 * or in the handler. But the code here only handles the _second_
200 * instance of the irq, not the third or fourth. So it is mostly
201 * useful for irq hardware that does not mask cleanly in an
205 irqreturn_t action_ret;
207 spin_unlock(&desc->lock);
209 action_ret = handle_IRQ_event(irq, regs, action);
211 spin_lock(&desc->lock);
213 note_interrupt(irq, desc, action_ret, regs);
214 if (likely(!(desc->status & IRQ_PENDING)))
216 desc->status &= ~IRQ_PENDING;
218 desc->status &= ~IRQ_INPROGRESS;
222 * The ->end() handler has to deal with interrupts which got
223 * disabled while the handler was running.
225 desc->chip->end(irq);
226 spin_unlock(&desc->lock);