]> pilppa.org Git - linux-2.6-omap-h63xx.git/blob - kernel/irq/handle.c
[ARM] 3679/1: ARM: Make ARM dyntick implementation work with genirq
[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 #if defined(CONFIG_NO_IDLE_HZ) && defined(CONFIG_ARM)
20 #include <asm/dyntick.h>
21 #endif
22
23 #include "internals.h"
24
25 /**
26  * handle_bad_irq - handle spurious and unhandled irqs
27  */
28 void fastcall
29 handle_bad_irq(unsigned int irq, struct irq_desc *desc, struct pt_regs *regs)
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 struct irq_desc irq_desc[NR_IRQS] __cacheline_aligned = {
51         [0 ... NR_IRQS-1] = {
52                 .status = IRQ_DISABLED,
53                 .chip = &no_irq_chip,
54                 .handle_irq = handle_bad_irq,
55                 .depth = 1,
56                 .lock = SPIN_LOCK_UNLOCKED,
57 #ifdef CONFIG_SMP
58                 .affinity = CPU_MASK_ALL
59 #endif
60         }
61 };
62
63 /*
64  * What should we do if we get a hw irq event on an illegal vector?
65  * Each architecture has to answer this themself.
66  */
67 static void ack_bad(unsigned int irq)
68 {
69         print_irq_desc(irq, irq_desc + irq);
70         ack_bad_irq(irq);
71 }
72
73 /*
74  * NOP functions
75  */
76 static void noop(unsigned int irq)
77 {
78 }
79
80 static unsigned int noop_ret(unsigned int irq)
81 {
82         return 0;
83 }
84
85 /*
86  * Generic no controller implementation
87  */
88 struct irq_chip no_irq_chip = {
89         .name           = "none",
90         .startup        = noop_ret,
91         .shutdown       = noop,
92         .enable         = noop,
93         .disable        = noop,
94         .ack            = ack_bad,
95         .end            = noop,
96 };
97
98 /*
99  * Special, empty irq handler:
100  */
101 irqreturn_t no_action(int cpl, void *dev_id, struct pt_regs *regs)
102 {
103         return IRQ_NONE;
104 }
105
106 /**
107  * handle_IRQ_event - irq action chain handler
108  * @irq:        the interrupt number
109  * @regs:       pointer to a register structure
110  * @action:     the interrupt action chain for this irq
111  *
112  * Handles the action chain of an irq event
113  */
114 irqreturn_t handle_IRQ_event(unsigned int irq, struct pt_regs *regs,
115                              struct irqaction *action)
116 {
117         irqreturn_t ret, retval = IRQ_NONE;
118         unsigned int status = 0;
119
120 #if defined(CONFIG_NO_IDLE_HZ) && defined(CONFIG_ARM)
121         if (!(action->flags & SA_TIMER) && system_timer->dyn_tick != NULL) {
122                 write_seqlock(&xtime_lock);
123                 if (system_timer->dyn_tick->state & DYN_TICK_ENABLED)
124                         system_timer->dyn_tick->handler(irq, 0, regs);
125                 write_sequnlock(&xtime_lock);
126         }
127 #endif
128
129         if (!(action->flags & SA_INTERRUPT))
130                 local_irq_enable();
131
132         do {
133                 ret = action->handler(irq, action->dev_id, regs);
134                 if (ret == IRQ_HANDLED)
135                         status |= action->flags;
136                 retval |= ret;
137                 action = action->next;
138         } while (action);
139
140         if (status & SA_SAMPLE_RANDOM)
141                 add_interrupt_randomness(irq);
142         local_irq_disable();
143
144         return retval;
145 }
146
147 /**
148  * __do_IRQ - original all in one highlevel IRQ handler
149  * @irq:        the interrupt number
150  * @regs:       pointer to a register structure
151  *
152  * __do_IRQ handles all normal device IRQ's (the special
153  * SMP cross-CPU interrupts have their own specific
154  * handlers).
155  *
156  * This is the original x86 implementation which is used for every
157  * interrupt type.
158  */
159 fastcall unsigned int __do_IRQ(unsigned int irq, struct pt_regs *regs)
160 {
161         struct irq_desc *desc = irq_desc + irq;
162         struct irqaction *action;
163         unsigned int status;
164
165         kstat_this_cpu.irqs[irq]++;
166         if (CHECK_IRQ_PER_CPU(desc->status)) {
167                 irqreturn_t action_ret;
168
169                 /*
170                  * No locking required for CPU-local interrupts:
171                  */
172                 if (desc->chip->ack)
173                         desc->chip->ack(irq);
174                 action_ret = handle_IRQ_event(irq, regs, desc->action);
175                 desc->chip->end(irq);
176                 return 1;
177         }
178
179         spin_lock(&desc->lock);
180         if (desc->chip->ack)
181                 desc->chip->ack(irq);
182         /*
183          * REPLAY is when Linux resends an IRQ that was dropped earlier
184          * WAITING is used by probe to mark irqs that are being tested
185          */
186         status = desc->status & ~(IRQ_REPLAY | IRQ_WAITING);
187         status |= IRQ_PENDING; /* we _want_ to handle it */
188
189         /*
190          * If the IRQ is disabled for whatever reason, we cannot
191          * use the action we have.
192          */
193         action = NULL;
194         if (likely(!(status & (IRQ_DISABLED | IRQ_INPROGRESS)))) {
195                 action = desc->action;
196                 status &= ~IRQ_PENDING; /* we commit to handling */
197                 status |= IRQ_INPROGRESS; /* we are handling it */
198         }
199         desc->status = status;
200
201         /*
202          * If there is no IRQ handler or it was disabled, exit early.
203          * Since we set PENDING, if another processor is handling
204          * a different instance of this same irq, the other processor
205          * will take care of it.
206          */
207         if (unlikely(!action))
208                 goto out;
209
210         /*
211          * Edge triggered interrupts need to remember
212          * pending events.
213          * This applies to any hw interrupts that allow a second
214          * instance of the same irq to arrive while we are in do_IRQ
215          * or in the handler. But the code here only handles the _second_
216          * instance of the irq, not the third or fourth. So it is mostly
217          * useful for irq hardware that does not mask cleanly in an
218          * SMP environment.
219          */
220         for (;;) {
221                 irqreturn_t action_ret;
222
223                 spin_unlock(&desc->lock);
224
225                 action_ret = handle_IRQ_event(irq, regs, action);
226
227                 spin_lock(&desc->lock);
228                 if (!noirqdebug)
229                         note_interrupt(irq, desc, action_ret, regs);
230                 if (likely(!(desc->status & IRQ_PENDING)))
231                         break;
232                 desc->status &= ~IRQ_PENDING;
233         }
234         desc->status &= ~IRQ_INPROGRESS;
235
236 out:
237         /*
238          * The ->end() handler has to deal with interrupts which got
239          * disabled while the handler was running.
240          */
241         desc->chip->end(irq);
242         spin_unlock(&desc->lock);
243
244         return 1;
245 }
246