]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - kernel/irq/handle.c
irq: sparse irqs, export nr_irqs
[linux-2.6-omap-h63xx.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
29 handle_bad_irq(unsigned int irq, struct irq_desc *desc)
30 {
31         print_irq_desc(irq, desc);
32         kstat_this_cpu.irqs[irq]++;
33         ack_bad_irq(irq);
34 }
35
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
40  * interrupt source is transparently wired to the appropriate
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  */
50 int nr_irqs = NR_IRQS;
51 EXPORT_SYMBOL_GPL(nr_irqs);
52
53 #ifdef CONFIG_HAVE_DYN_ARRAY
54 static 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
65 static 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
77 struct irq_desc *irq_desc;
78 DEFINE_DYN_ARRAY(irq_desc, sizeof(struct irq_desc), nr_irqs, PAGE_SIZE, init_work);
79
80 #else
81
82 struct irq_desc irq_desc[NR_IRQS] __cacheline_aligned_in_smp = {
83         [0 ... NR_IRQS-1] = {
84                 .status = IRQ_DISABLED,
85                 .chip = &no_irq_chip,
86                 .handle_irq = handle_bad_irq,
87                 .depth = 1,
88                 .lock = __SPIN_LOCK_UNLOCKED(irq_desc->lock),
89 #ifdef CONFIG_SMP
90                 .affinity = CPU_MASK_ALL
91 #endif
92         }
93 };
94 #endif
95
96 /*
97  * What should we do if we get a hw irq event on an illegal vector?
98  * Each architecture has to answer this themself.
99  */
100 static void ack_bad(unsigned int irq)
101 {
102         print_irq_desc(irq, irq_desc + irq);
103         ack_bad_irq(irq);
104 }
105
106 /*
107  * NOP functions
108  */
109 static void noop(unsigned int irq)
110 {
111 }
112
113 static unsigned int noop_ret(unsigned int irq)
114 {
115         return 0;
116 }
117
118 /*
119  * Generic no controller implementation
120  */
121 struct irq_chip no_irq_chip = {
122         .name           = "none",
123         .startup        = noop_ret,
124         .shutdown       = noop,
125         .enable         = noop,
126         .disable        = noop,
127         .ack            = ack_bad,
128         .end            = noop,
129 };
130
131 /*
132  * Generic dummy implementation which can be used for
133  * real dumb interrupt sources
134  */
135 struct 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
147 /*
148  * Special, empty irq handler:
149  */
150 irqreturn_t no_action(int cpl, void *dev_id)
151 {
152         return IRQ_NONE;
153 }
154
155 /**
156  * handle_IRQ_event - irq action chain handler
157  * @irq:        the interrupt number
158  * @action:     the interrupt action chain for this irq
159  *
160  * Handles the action chain of an irq event
161  */
162 irqreturn_t handle_IRQ_event(unsigned int irq, struct irqaction *action)
163 {
164         irqreturn_t ret, retval = IRQ_NONE;
165         unsigned int status = 0;
166
167         if (!(action->flags & IRQF_DISABLED))
168                 local_irq_enable_in_hardirq();
169
170         do {
171                 ret = action->handler(irq, action->dev_id);
172                 if (ret == IRQ_HANDLED)
173                         status |= action->flags;
174                 retval |= ret;
175                 action = action->next;
176         } while (action);
177
178         if (status & IRQF_SAMPLE_RANDOM)
179                 add_interrupt_randomness(irq);
180         local_irq_disable();
181
182         return retval;
183 }
184
185 #ifndef CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ
186 /**
187  * __do_IRQ - original all in one highlevel IRQ handler
188  * @irq:        the interrupt number
189  *
190  * __do_IRQ handles all normal device IRQ's (the special
191  * SMP cross-CPU interrupts have their own specific
192  * handlers).
193  *
194  * This is the original x86 implementation which is used for every
195  * interrupt type.
196  */
197 unsigned int __do_IRQ(unsigned int irq)
198 {
199         struct irq_desc *desc = irq_desc + irq;
200         struct irqaction *action;
201         unsigned int status;
202
203         kstat_this_cpu.irqs[irq]++;
204         if (CHECK_IRQ_PER_CPU(desc->status)) {
205                 irqreturn_t action_ret;
206
207                 /*
208                  * No locking required for CPU-local interrupts:
209                  */
210                 if (desc->chip->ack)
211                         desc->chip->ack(irq);
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                 }
217                 desc->chip->end(irq);
218                 return 1;
219         }
220
221         spin_lock(&desc->lock);
222         if (desc->chip->ack)
223                 desc->chip->ack(irq);
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
267                 action_ret = handle_IRQ_event(irq, action);
268                 if (!noirqdebug)
269                         note_interrupt(irq, desc, action_ret);
270
271                 spin_lock(&desc->lock);
272                 if (likely(!(desc->status & IRQ_PENDING)))
273                         break;
274                 desc->status &= ~IRQ_PENDING;
275         }
276         desc->status &= ~IRQ_INPROGRESS;
277
278 out:
279         /*
280          * The ->end() handler has to deal with interrupts which got
281          * disabled while the handler was running.
282          */
283         desc->chip->end(irq);
284         spin_unlock(&desc->lock);
285
286         return 1;
287 }
288 #endif
289
290 #ifdef CONFIG_TRACE_IRQFLAGS
291
292 /*
293  * lockdep: we want to handle all irq_desc locks as a single lock-class:
294  */
295 static struct lock_class_key irq_desc_lock_class;
296
297 void early_init_irq_lock_class(void)
298 {
299         int i;
300
301         for (i = 0; i < nr_irqs; i++)
302                 lockdep_set_class(&irq_desc[i].lock, &irq_desc_lock_class);
303 }
304
305 #endif