2 * linux/kernel/irq/handle.c
4 * Copyright (C) 1992, 1998-2004 Linus Torvalds, Ingo Molnar
6 * This file contains the core interrupt handling code.
10 #include <linux/module.h>
11 #include <linux/random.h>
12 #include <linux/interrupt.h>
13 #include <linux/kernel_stat.h>
15 #include "internals.h"
18 * Linux has a controller-independent interrupt architecture.
19 * Every controller has a 'controller-template', that is used
20 * by the main code to do the right thing. Each driver-visible
21 * interrupt source is transparently wired to the apropriate
22 * controller. Thus drivers need not be aware of the
23 * interrupt-controller.
25 * The code is designed to be easily extended with new/different
26 * interrupt controllers, without having to do assembly magic or
27 * having to touch the generic code.
29 * Controller mappings for all interrupt sources:
31 irq_desc_t irq_desc[NR_IRQS] __cacheline_aligned = {
33 .status = IRQ_DISABLED,
34 .handler = &no_irq_type,
35 .lock = SPIN_LOCK_UNLOCKED
40 * Generic 'no controller' code
42 static void end_none(unsigned int irq) { }
43 static void enable_none(unsigned int irq) { }
44 static void disable_none(unsigned int irq) { }
45 static void shutdown_none(unsigned int irq) { }
46 static unsigned int startup_none(unsigned int irq) { return 0; }
48 static void ack_none(unsigned int irq)
51 * 'what should we do if we get a hw irq event on an illegal vector'.
52 * each architecture has to answer this themself.
57 struct hw_interrupt_type no_irq_type = {
59 .startup = startup_none,
60 .shutdown = shutdown_none,
61 .enable = enable_none,
62 .disable = disable_none,
69 * Special, empty irq handler:
71 irqreturn_t no_action(int cpl, void *dev_id, struct pt_regs *regs)
77 * Have got an event to handle:
79 fastcall irqreturn_t handle_IRQ_event(unsigned int irq, struct pt_regs *regs,
80 struct irqaction *action)
82 irqreturn_t ret, retval = IRQ_NONE;
83 unsigned int status = 0;
85 if (!(action->flags & SA_INTERRUPT))
89 ret = action->handler(irq, action->dev_id, regs);
90 if (ret == IRQ_HANDLED)
91 status |= action->flags;
93 action = action->next;
96 if (status & SA_SAMPLE_RANDOM)
97 add_interrupt_randomness(irq);
104 * do_IRQ handles all normal device IRQ's (the special
105 * SMP cross-CPU interrupts have their own specific
108 fastcall unsigned int __do_IRQ(unsigned int irq, struct pt_regs *regs)
110 irq_desc_t *desc = irq_desc + irq;
111 struct irqaction * action;
114 kstat_this_cpu.irqs[irq]++;
115 if (CHECK_IRQ_PER_CPU(desc->status)) {
116 irqreturn_t action_ret;
119 * No locking required for CPU-local interrupts:
121 if (desc->handler->ack)
122 desc->handler->ack(irq);
123 action_ret = handle_IRQ_event(irq, regs, desc->action);
124 desc->handler->end(irq);
128 spin_lock(&desc->lock);
129 if (desc->handler->ack)
130 desc->handler->ack(irq);
132 * REPLAY is when Linux resends an IRQ that was dropped earlier
133 * WAITING is used by probe to mark irqs that are being tested
135 status = desc->status & ~(IRQ_REPLAY | IRQ_WAITING);
136 status |= IRQ_PENDING; /* we _want_ to handle it */
139 * If the IRQ is disabled for whatever reason, we cannot
140 * use the action we have.
143 if (likely(!(status & (IRQ_DISABLED | IRQ_INPROGRESS)))) {
144 action = desc->action;
145 status &= ~IRQ_PENDING; /* we commit to handling */
146 status |= IRQ_INPROGRESS; /* we are handling it */
148 desc->status = status;
151 * If there is no IRQ handler or it was disabled, exit early.
152 * Since we set PENDING, if another processor is handling
153 * a different instance of this same irq, the other processor
154 * will take care of it.
156 if (unlikely(!action))
160 * Edge triggered interrupts need to remember
162 * This applies to any hw interrupts that allow a second
163 * instance of the same irq to arrive while we are in do_IRQ
164 * or in the handler. But the code here only handles the _second_
165 * instance of the irq, not the third or fourth. So it is mostly
166 * useful for irq hardware that does not mask cleanly in an
170 irqreturn_t action_ret;
172 spin_unlock(&desc->lock);
174 action_ret = handle_IRQ_event(irq, regs, action);
176 spin_lock(&desc->lock);
178 note_interrupt(irq, desc, action_ret, regs);
179 if (likely(!(desc->status & IRQ_PENDING)))
181 desc->status &= ~IRQ_PENDING;
183 desc->status &= ~IRQ_INPROGRESS;
187 * The ->end() handler has to deal with interrupts which got
188 * disabled while the handler was running.
190 desc->handler->end(irq);
191 spin_unlock(&desc->lock);