[PATCH] lockdep: annotate enable_in_hardirq()
[linux/fpc-iii.git] / kernel / irq / handle.c
blobfc4e906aedbd77ef5cf7057dcb8b3d089b240e14
1 /*
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"
21 /**
22 * handle_bad_irq - handle spurious and unhandled irqs
24 void fastcall
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]++;
29 ack_bad_irq(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 = {
47 [0 ... NR_IRQS-1] = {
48 .status = IRQ_DISABLED,
49 .chip = &no_irq_chip,
50 .handle_irq = handle_bad_irq,
51 .depth = 1,
52 .lock = SPIN_LOCK_UNLOCKED,
53 #ifdef CONFIG_SMP
54 .affinity = CPU_MASK_ALL
55 #endif
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);
66 ack_bad_irq(irq);
70 * NOP functions
72 static void noop(unsigned int irq)
76 static unsigned int noop_ret(unsigned int irq)
78 return 0;
82 * Generic no controller implementation
84 struct irq_chip no_irq_chip = {
85 .name = "none",
86 .startup = noop_ret,
87 .shutdown = noop,
88 .enable = noop,
89 .disable = noop,
90 .ack = ack_bad,
91 .end = noop,
95 * Generic dummy implementation which can be used for
96 * real dumb interrupt sources
98 struct irq_chip dummy_irq_chip = {
99 .name = "dummy",
100 .startup = noop_ret,
101 .shutdown = noop,
102 .enable = noop,
103 .disable = noop,
104 .ack = noop,
105 .mask = noop,
106 .unmask = noop,
107 .end = noop,
111 * Special, empty irq handler:
113 irqreturn_t no_action(int cpl, void *dev_id, struct pt_regs *regs)
115 return IRQ_NONE;
119 * handle_IRQ_event - irq action chain handler
120 * @irq: the interrupt number
121 * @regs: pointer to a register structure
122 * @action: the interrupt action chain for this irq
124 * Handles the action chain of an irq event
126 irqreturn_t handle_IRQ_event(unsigned int irq, struct pt_regs *regs,
127 struct irqaction *action)
129 irqreturn_t ret, retval = IRQ_NONE;
130 unsigned int status = 0;
132 handle_dynamic_tick(action);
134 if (!(action->flags & IRQF_DISABLED))
135 local_irq_enable_in_hardirq();
137 do {
138 ret = action->handler(irq, action->dev_id, regs);
139 if (ret == IRQ_HANDLED)
140 status |= action->flags;
141 retval |= ret;
142 action = action->next;
143 } while (action);
145 if (status & IRQF_SAMPLE_RANDOM)
146 add_interrupt_randomness(irq);
147 local_irq_disable();
149 return retval;
153 * __do_IRQ - original all in one highlevel IRQ handler
154 * @irq: the interrupt number
155 * @regs: pointer to a register structure
157 * __do_IRQ handles all normal device IRQ's (the special
158 * SMP cross-CPU interrupts have their own specific
159 * handlers).
161 * This is the original x86 implementation which is used for every
162 * interrupt type.
164 fastcall unsigned int __do_IRQ(unsigned int irq, struct pt_regs *regs)
166 struct irq_desc *desc = irq_desc + irq;
167 struct irqaction *action;
168 unsigned int status;
170 kstat_this_cpu.irqs[irq]++;
171 if (CHECK_IRQ_PER_CPU(desc->status)) {
172 irqreturn_t action_ret;
175 * No locking required for CPU-local interrupts:
177 if (desc->chip->ack)
178 desc->chip->ack(irq);
179 action_ret = handle_IRQ_event(irq, regs, desc->action);
180 desc->chip->end(irq);
181 return 1;
184 spin_lock(&desc->lock);
185 if (desc->chip->ack)
186 desc->chip->ack(irq);
188 * REPLAY is when Linux resends an IRQ that was dropped earlier
189 * WAITING is used by probe to mark irqs that are being tested
191 status = desc->status & ~(IRQ_REPLAY | IRQ_WAITING);
192 status |= IRQ_PENDING; /* we _want_ to handle it */
195 * If the IRQ is disabled for whatever reason, we cannot
196 * use the action we have.
198 action = NULL;
199 if (likely(!(status & (IRQ_DISABLED | IRQ_INPROGRESS)))) {
200 action = desc->action;
201 status &= ~IRQ_PENDING; /* we commit to handling */
202 status |= IRQ_INPROGRESS; /* we are handling it */
204 desc->status = status;
207 * If there is no IRQ handler or it was disabled, exit early.
208 * Since we set PENDING, if another processor is handling
209 * a different instance of this same irq, the other processor
210 * will take care of it.
212 if (unlikely(!action))
213 goto out;
216 * Edge triggered interrupts need to remember
217 * pending events.
218 * This applies to any hw interrupts that allow a second
219 * instance of the same irq to arrive while we are in do_IRQ
220 * or in the handler. But the code here only handles the _second_
221 * instance of the irq, not the third or fourth. So it is mostly
222 * useful for irq hardware that does not mask cleanly in an
223 * SMP environment.
225 for (;;) {
226 irqreturn_t action_ret;
228 spin_unlock(&desc->lock);
230 action_ret = handle_IRQ_event(irq, regs, action);
232 spin_lock(&desc->lock);
233 if (!noirqdebug)
234 note_interrupt(irq, desc, action_ret, regs);
235 if (likely(!(desc->status & IRQ_PENDING)))
236 break;
237 desc->status &= ~IRQ_PENDING;
239 desc->status &= ~IRQ_INPROGRESS;
241 out:
243 * The ->end() handler has to deal with interrupts which got
244 * disabled while the handler was running.
246 desc->chip->end(irq);
247 spin_unlock(&desc->lock);
249 return 1;
252 #ifdef CONFIG_TRACE_IRQFLAGS
255 * lockdep: we want to handle all irq_desc locks as a single lock-class:
257 static struct lock_class_key irq_desc_lock_class;
259 void early_init_irq_lock_class(void)
261 int i;
263 for (i = 0; i < NR_IRQS; i++)
264 lockdep_set_class(&irq_desc[i].lock, &irq_desc_lock_class);
267 #endif