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 print_irq_desc(irq, desc);
28 kstat_this_cpu.irqs[irq]++;
33 * Linux has a controller-independent interrupt architecture.
34 * Every controller has a 'controller-template', that is used
35 * by the main code to do the right thing. Each driver-visible
36 * interrupt source is transparently wired to the appropriate
37 * controller. Thus drivers need not be aware of the
38 * interrupt-controller.
40 * The code is designed to be easily extended with new/different
41 * interrupt controllers, without having to do assembly magic or
42 * having to touch the generic code.
44 * Controller mappings for all interrupt sources:
46 struct irq_desc irq_desc[NR_IRQS] __cacheline_aligned = {
48 .status = IRQ_DISABLED,
50 .handle_irq = handle_bad_irq,
52 .lock = SPIN_LOCK_UNLOCKED,
54 .affinity = CPU_MASK_ALL
60 * What should we do if we get a hw irq event on an illegal vector?
61 * Each architecture has to answer this themself.
63 static void ack_bad(unsigned int irq)
65 print_irq_desc(irq, irq_desc + irq);
72 static void noop(unsigned int irq)
76 static unsigned int noop_ret(unsigned int irq)
82 * Generic no controller implementation
84 struct irq_chip no_irq_chip = {
95 * Special, empty irq handler:
97 irqreturn_t no_action(int cpl, void *dev_id, struct pt_regs *regs)
103 * handle_IRQ_event - irq action chain handler
104 * @irq: the interrupt number
105 * @regs: pointer to a register structure
106 * @action: the interrupt action chain for this irq
108 * Handles the action chain of an irq event
110 irqreturn_t handle_IRQ_event(unsigned int irq, struct pt_regs *regs,
111 struct irqaction *action)
113 irqreturn_t ret, retval = IRQ_NONE;
114 unsigned int status = 0;
116 if (!(action->flags & IRQF_DISABLED))
120 ret = action->handler(irq, action->dev_id, regs);
121 if (ret == IRQ_HANDLED)
122 status |= action->flags;
124 action = action->next;
127 if (status & IRQF_SAMPLE_RANDOM)
128 add_interrupt_randomness(irq);
135 * __do_IRQ - original all in one highlevel IRQ handler
136 * @irq: the interrupt number
137 * @regs: pointer to a register structure
139 * __do_IRQ handles all normal device IRQ's (the special
140 * SMP cross-CPU interrupts have their own specific
143 * This is the original x86 implementation which is used for every
146 fastcall unsigned int __do_IRQ(unsigned int irq, struct pt_regs *regs)
148 struct irq_desc *desc = irq_desc + irq;
149 struct irqaction *action;
152 kstat_this_cpu.irqs[irq]++;
153 if (CHECK_IRQ_PER_CPU(desc->status)) {
154 irqreturn_t action_ret;
157 * No locking required for CPU-local interrupts:
160 desc->chip->ack(irq);
161 action_ret = handle_IRQ_event(irq, regs, desc->action);
162 desc->chip->end(irq);
166 spin_lock(&desc->lock);
168 desc->chip->ack(irq);
170 * REPLAY is when Linux resends an IRQ that was dropped earlier
171 * WAITING is used by probe to mark irqs that are being tested
173 status = desc->status & ~(IRQ_REPLAY | IRQ_WAITING);
174 status |= IRQ_PENDING; /* we _want_ to handle it */
177 * If the IRQ is disabled for whatever reason, we cannot
178 * use the action we have.
181 if (likely(!(status & (IRQ_DISABLED | IRQ_INPROGRESS)))) {
182 action = desc->action;
183 status &= ~IRQ_PENDING; /* we commit to handling */
184 status |= IRQ_INPROGRESS; /* we are handling it */
186 desc->status = status;
189 * If there is no IRQ handler or it was disabled, exit early.
190 * Since we set PENDING, if another processor is handling
191 * a different instance of this same irq, the other processor
192 * will take care of it.
194 if (unlikely(!action))
198 * Edge triggered interrupts need to remember
200 * This applies to any hw interrupts that allow a second
201 * instance of the same irq to arrive while we are in do_IRQ
202 * or in the handler. But the code here only handles the _second_
203 * instance of the irq, not the third or fourth. So it is mostly
204 * useful for irq hardware that does not mask cleanly in an
208 irqreturn_t action_ret;
210 spin_unlock(&desc->lock);
212 action_ret = handle_IRQ_event(irq, regs, action);
214 spin_lock(&desc->lock);
216 note_interrupt(irq, desc, action_ret, regs);
217 if (likely(!(desc->status & IRQ_PENDING)))
219 desc->status &= ~IRQ_PENDING;
221 desc->status &= ~IRQ_INPROGRESS;
225 * The ->end() handler has to deal with interrupts which got
226 * disabled while the handler was running.
228 desc->chip->end(irq);
229 spin_unlock(&desc->lock);