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
23 * @irq: the interrupt number
24 * @desc: description of the interrupt
26 * Handles spurious and unhandled IRQ's. It also prints a debugmessage.
28 void handle_bad_irq(unsigned int irq, struct irq_desc *desc)
30 print_irq_desc(irq, desc);
31 kstat_incr_irqs_this_cpu(irq, desc);
36 * Linux has a controller-independent interrupt architecture.
37 * Every controller has a 'controller-template', that is used
38 * by the main code to do the right thing. Each driver-visible
39 * interrupt source is transparently wired to the appropriate
40 * controller. Thus drivers need not be aware of the
41 * interrupt-controller.
43 * The code is designed to be easily extended with new/different
44 * interrupt controllers, without having to do assembly magic or
45 * having to touch the generic code.
47 * Controller mappings for all interrupt sources:
49 int nr_irqs = NR_IRQS;
50 EXPORT_SYMBOL_GPL(nr_irqs);
52 struct irq_desc irq_desc[NR_IRQS] __cacheline_aligned_in_smp = {
54 .status = IRQ_DISABLED,
56 .handle_irq = handle_bad_irq,
58 .lock = __SPIN_LOCK_UNLOCKED(irq_desc->lock),
60 .affinity = CPU_MASK_ALL
66 * What should we do if we get a hw irq event on an illegal vector?
67 * Each architecture has to answer this themself.
69 static void ack_bad(unsigned int irq)
71 struct irq_desc *desc = irq_to_desc(irq);
73 print_irq_desc(irq, desc);
80 static void noop(unsigned int irq)
84 static unsigned int noop_ret(unsigned int irq)
90 * Generic no controller implementation
92 struct irq_chip no_irq_chip = {
103 * Generic dummy implementation which can be used for
104 * real dumb interrupt sources
106 struct irq_chip dummy_irq_chip = {
119 * Special, empty irq handler:
121 irqreturn_t no_action(int cpl, void *dev_id)
127 * handle_IRQ_event - irq action chain handler
128 * @irq: the interrupt number
129 * @action: the interrupt action chain for this irq
131 * Handles the action chain of an irq event
133 irqreturn_t handle_IRQ_event(unsigned int irq, struct irqaction *action)
135 irqreturn_t ret, retval = IRQ_NONE;
136 unsigned int status = 0;
138 if (!(action->flags & IRQF_DISABLED))
139 local_irq_enable_in_hardirq();
142 ret = action->handler(irq, action->dev_id);
143 if (ret == IRQ_HANDLED)
144 status |= action->flags;
146 action = action->next;
149 if (status & IRQF_SAMPLE_RANDOM)
150 add_interrupt_randomness(irq);
156 #ifndef CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ
158 * __do_IRQ - original all in one highlevel IRQ handler
159 * @irq: the interrupt number
161 * __do_IRQ handles all normal device IRQ's (the special
162 * SMP cross-CPU interrupts have their own specific
165 * This is the original x86 implementation which is used for every
168 unsigned int __do_IRQ(unsigned int irq)
170 struct irq_desc *desc = irq_to_desc(irq);
171 struct irqaction *action;
174 kstat_incr_irqs_this_cpu(irq, desc);
176 if (CHECK_IRQ_PER_CPU(desc->status)) {
177 irqreturn_t action_ret;
180 * No locking required for CPU-local interrupts:
183 desc->chip->ack(irq);
184 if (likely(!(desc->status & IRQ_DISABLED))) {
185 action_ret = handle_IRQ_event(irq, desc->action);
187 note_interrupt(irq, desc, action_ret);
189 desc->chip->end(irq);
193 spin_lock(&desc->lock);
195 desc->chip->ack(irq);
197 * REPLAY is when Linux resends an IRQ that was dropped earlier
198 * WAITING is used by probe to mark irqs that are being tested
200 status = desc->status & ~(IRQ_REPLAY | IRQ_WAITING);
201 status |= IRQ_PENDING; /* we _want_ to handle it */
204 * If the IRQ is disabled for whatever reason, we cannot
205 * use the action we have.
208 if (likely(!(status & (IRQ_DISABLED | IRQ_INPROGRESS)))) {
209 action = desc->action;
210 status &= ~IRQ_PENDING; /* we commit to handling */
211 status |= IRQ_INPROGRESS; /* we are handling it */
213 desc->status = status;
216 * If there is no IRQ handler or it was disabled, exit early.
217 * Since we set PENDING, if another processor is handling
218 * a different instance of this same irq, the other processor
219 * will take care of it.
221 if (unlikely(!action))
225 * Edge triggered interrupts need to remember
227 * This applies to any hw interrupts that allow a second
228 * instance of the same irq to arrive while we are in do_IRQ
229 * or in the handler. But the code here only handles the _second_
230 * instance of the irq, not the third or fourth. So it is mostly
231 * useful for irq hardware that does not mask cleanly in an
235 irqreturn_t action_ret;
237 spin_unlock(&desc->lock);
239 action_ret = handle_IRQ_event(irq, action);
241 note_interrupt(irq, desc, action_ret);
243 spin_lock(&desc->lock);
244 if (likely(!(desc->status & IRQ_PENDING)))
246 desc->status &= ~IRQ_PENDING;
248 desc->status &= ~IRQ_INPROGRESS;
252 * The ->end() handler has to deal with interrupts which got
253 * disabled while the handler was running.
255 desc->chip->end(irq);
256 spin_unlock(&desc->lock);
263 #ifdef CONFIG_TRACE_IRQFLAGS
265 * lockdep: we want to handle all irq_desc locks as a single lock-class:
267 static struct lock_class_key irq_desc_lock_class;
269 void early_init_irq_lock_class(void)
271 struct irq_desc *desc;
274 for_each_irq_desc(i, desc)
275 lockdep_set_class(&desc->lock, &irq_desc_lock_class);