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