genirq: revert dynarray
[deliverable/linux.git] / kernel / irq / handle.c
1 /*
2 * linux/kernel/irq/handle.c
3 *
4 * Copyright (C) 1992, 1998-2006 Linus Torvalds, Ingo Molnar
5 * Copyright (C) 2005-2006, Thomas Gleixner, Russell King
6 *
7 * This file contains the core interrupt handling code.
8 *
9 * Detailed information is available in Documentation/DocBook/genericirq
10 *
11 */
12
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>
18
19 #include "internals.h"
20
21 /**
22 * handle_bad_irq - handle spurious and unhandled irqs
23 * @irq: the interrupt number
24 * @desc: description of the interrupt
25 *
26 * Handles spurious and unhandled IRQ's. It also prints a debugmessage.
27 */
28 void handle_bad_irq(unsigned int irq, struct irq_desc *desc)
29 {
30 print_irq_desc(irq, desc);
31 kstat_incr_irqs_this_cpu(irq, desc);
32 ack_bad_irq(irq);
33 }
34
35 /*
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.
42 *
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.
46 *
47 * Controller mappings for all interrupt sources:
48 */
49 int nr_irqs = NR_IRQS;
50 EXPORT_SYMBOL_GPL(nr_irqs);
51
52 struct irq_desc irq_desc[NR_IRQS] __cacheline_aligned_in_smp = {
53 [0 ... NR_IRQS-1] = {
54 .status = IRQ_DISABLED,
55 .chip = &no_irq_chip,
56 .handle_irq = handle_bad_irq,
57 .depth = 1,
58 .lock = __SPIN_LOCK_UNLOCKED(irq_desc->lock),
59 #ifdef CONFIG_SMP
60 .affinity = CPU_MASK_ALL
61 #endif
62 }
63 };
64
65 /*
66 * What should we do if we get a hw irq event on an illegal vector?
67 * Each architecture has to answer this themself.
68 */
69 static void ack_bad(unsigned int irq)
70 {
71 struct irq_desc *desc;
72
73 desc = irq_to_desc(irq);
74 print_irq_desc(irq, desc);
75 ack_bad_irq(irq);
76 }
77
78 /*
79 * NOP functions
80 */
81 static void noop(unsigned int irq)
82 {
83 }
84
85 static unsigned int noop_ret(unsigned int irq)
86 {
87 return 0;
88 }
89
90 /*
91 * Generic no controller implementation
92 */
93 struct irq_chip no_irq_chip = {
94 .name = "none",
95 .startup = noop_ret,
96 .shutdown = noop,
97 .enable = noop,
98 .disable = noop,
99 .ack = ack_bad,
100 .end = noop,
101 };
102
103 /*
104 * Generic dummy implementation which can be used for
105 * real dumb interrupt sources
106 */
107 struct irq_chip dummy_irq_chip = {
108 .name = "dummy",
109 .startup = noop_ret,
110 .shutdown = noop,
111 .enable = noop,
112 .disable = noop,
113 .ack = noop,
114 .mask = noop,
115 .unmask = noop,
116 .end = noop,
117 };
118
119 /*
120 * Special, empty irq handler:
121 */
122 irqreturn_t no_action(int cpl, void *dev_id)
123 {
124 return IRQ_NONE;
125 }
126
127 /**
128 * handle_IRQ_event - irq action chain handler
129 * @irq: the interrupt number
130 * @action: the interrupt action chain for this irq
131 *
132 * Handles the action chain of an irq event
133 */
134 irqreturn_t handle_IRQ_event(unsigned int irq, struct irqaction *action)
135 {
136 irqreturn_t ret, retval = IRQ_NONE;
137 unsigned int status = 0;
138
139 if (!(action->flags & IRQF_DISABLED))
140 local_irq_enable_in_hardirq();
141
142 do {
143 ret = action->handler(irq, action->dev_id);
144 if (ret == IRQ_HANDLED)
145 status |= action->flags;
146 retval |= ret;
147 action = action->next;
148 } while (action);
149
150 if (status & IRQF_SAMPLE_RANDOM)
151 add_interrupt_randomness(irq);
152 local_irq_disable();
153
154 return retval;
155 }
156
157 #ifndef CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ
158 /**
159 * __do_IRQ - original all in one highlevel IRQ handler
160 * @irq: the interrupt number
161 *
162 * __do_IRQ handles all normal device IRQ's (the special
163 * SMP cross-CPU interrupts have their own specific
164 * handlers).
165 *
166 * This is the original x86 implementation which is used for every
167 * interrupt type.
168 */
169 unsigned int __do_IRQ(unsigned int irq)
170 {
171 struct irq_desc *desc = irq_to_desc(irq);
172 struct irqaction *action;
173 unsigned int status;
174
175 kstat_incr_irqs_this_cpu(irq, desc);
176
177 if (CHECK_IRQ_PER_CPU(desc->status)) {
178 irqreturn_t action_ret;
179
180 /*
181 * No locking required for CPU-local interrupts:
182 */
183 if (desc->chip->ack)
184 desc->chip->ack(irq);
185 if (likely(!(desc->status & IRQ_DISABLED))) {
186 action_ret = handle_IRQ_event(irq, desc->action);
187 if (!noirqdebug)
188 note_interrupt(irq, desc, action_ret);
189 }
190 desc->chip->end(irq);
191 return 1;
192 }
193
194 spin_lock(&desc->lock);
195 if (desc->chip->ack)
196 desc->chip->ack(irq);
197 /*
198 * REPLAY is when Linux resends an IRQ that was dropped earlier
199 * WAITING is used by probe to mark irqs that are being tested
200 */
201 status = desc->status & ~(IRQ_REPLAY | IRQ_WAITING);
202 status |= IRQ_PENDING; /* we _want_ to handle it */
203
204 /*
205 * If the IRQ is disabled for whatever reason, we cannot
206 * use the action we have.
207 */
208 action = NULL;
209 if (likely(!(status & (IRQ_DISABLED | IRQ_INPROGRESS)))) {
210 action = desc->action;
211 status &= ~IRQ_PENDING; /* we commit to handling */
212 status |= IRQ_INPROGRESS; /* we are handling it */
213 }
214 desc->status = status;
215
216 /*
217 * If there is no IRQ handler or it was disabled, exit early.
218 * Since we set PENDING, if another processor is handling
219 * a different instance of this same irq, the other processor
220 * will take care of it.
221 */
222 if (unlikely(!action))
223 goto out;
224
225 /*
226 * Edge triggered interrupts need to remember
227 * pending events.
228 * This applies to any hw interrupts that allow a second
229 * instance of the same irq to arrive while we are in do_IRQ
230 * or in the handler. But the code here only handles the _second_
231 * instance of the irq, not the third or fourth. So it is mostly
232 * useful for irq hardware that does not mask cleanly in an
233 * SMP environment.
234 */
235 for (;;) {
236 irqreturn_t action_ret;
237
238 spin_unlock(&desc->lock);
239
240 action_ret = handle_IRQ_event(irq, action);
241 if (!noirqdebug)
242 note_interrupt(irq, desc, action_ret);
243
244 spin_lock(&desc->lock);
245 if (likely(!(desc->status & IRQ_PENDING)))
246 break;
247 desc->status &= ~IRQ_PENDING;
248 }
249 desc->status &= ~IRQ_INPROGRESS;
250
251 out:
252 /*
253 * The ->end() handler has to deal with interrupts which got
254 * disabled while the handler was running.
255 */
256 desc->chip->end(irq);
257 spin_unlock(&desc->lock);
258
259 return 1;
260 }
261 #endif
262
263
264 #ifdef CONFIG_TRACE_IRQFLAGS
265 /*
266 * lockdep: we want to handle all irq_desc locks as a single lock-class:
267 */
268 static struct lock_class_key irq_desc_lock_class;
269
270 void early_init_irq_lock_class(void)
271 {
272 int i;
273
274 for (i = 0; i < nr_irqs; i++)
275 lockdep_set_class(&irq_desc[i].lock, &irq_desc_lock_class);
276 }
277 #endif
This page took 0.06892 seconds and 6 git commands to generate.