[PATCH] genirq: update copyrights
[pandora-kernel.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  * Linux has a controller-independent interrupt architecture.
23  * Every controller has a 'controller-template', that is used
24  * by the main code to do the right thing. Each driver-visible
25  * interrupt source is transparently wired to the appropriate
26  * controller. Thus drivers need not be aware of the
27  * interrupt-controller.
28  *
29  * The code is designed to be easily extended with new/different
30  * interrupt controllers, without having to do assembly magic or
31  * having to touch the generic code.
32  *
33  * Controller mappings for all interrupt sources:
34  */
35 struct irq_desc irq_desc[NR_IRQS] __cacheline_aligned = {
36         [0 ... NR_IRQS-1] = {
37                 .status = IRQ_DISABLED,
38                 .chip = &no_irq_type,
39                 .depth = 1,
40                 .lock = SPIN_LOCK_UNLOCKED,
41 #ifdef CONFIG_SMP
42                 .affinity = CPU_MASK_ALL
43 #endif
44         }
45 };
46
47 /*
48  * What should we do if we get a hw irq event on an illegal vector?
49  * Each architecture has to answer this themself.
50  */
51 static void ack_bad(unsigned int irq)
52 {
53         ack_bad_irq(irq);
54 }
55
56 /*
57  * NOP functions
58  */
59 static void noop(unsigned int irq)
60 {
61 }
62
63 static unsigned int noop_ret(unsigned int irq)
64 {
65         return 0;
66 }
67
68 /*
69  * Generic no controller implementation
70  */
71 struct hw_interrupt_type no_irq_type = {
72         .typename       = "none",
73         .startup        = noop_ret,
74         .shutdown       = noop,
75         .enable         = noop,
76         .disable        = noop,
77         .ack            = ack_bad,
78         .end            = noop,
79 };
80
81 /*
82  * Special, empty irq handler:
83  */
84 irqreturn_t no_action(int cpl, void *dev_id, struct pt_regs *regs)
85 {
86         return IRQ_NONE;
87 }
88
89 /**
90  * handle_IRQ_event - irq action chain handler
91  * @irq:        the interrupt number
92  * @regs:       pointer to a register structure
93  * @action:     the interrupt action chain for this irq
94  *
95  * Handles the action chain of an irq event
96  */
97 irqreturn_t handle_IRQ_event(unsigned int irq, struct pt_regs *regs,
98                              struct irqaction *action)
99 {
100         irqreturn_t ret, retval = IRQ_NONE;
101         unsigned int status = 0;
102
103         if (!(action->flags & SA_INTERRUPT))
104                 local_irq_enable();
105
106         do {
107                 ret = action->handler(irq, action->dev_id, regs);
108                 if (ret == IRQ_HANDLED)
109                         status |= action->flags;
110                 retval |= ret;
111                 action = action->next;
112         } while (action);
113
114         if (status & SA_SAMPLE_RANDOM)
115                 add_interrupt_randomness(irq);
116         local_irq_disable();
117
118         return retval;
119 }
120
121 /**
122  * __do_IRQ - original all in one highlevel IRQ handler
123  * @irq:        the interrupt number
124  * @regs:       pointer to a register structure
125  *
126  * __do_IRQ handles all normal device IRQ's (the special
127  * SMP cross-CPU interrupts have their own specific
128  * handlers).
129  *
130  * This is the original x86 implementation which is used for every
131  * interrupt type.
132  */
133 fastcall unsigned int __do_IRQ(unsigned int irq, struct pt_regs *regs)
134 {
135         struct irq_desc *desc = irq_desc + irq;
136         struct irqaction *action;
137         unsigned int status;
138
139         kstat_this_cpu.irqs[irq]++;
140         if (CHECK_IRQ_PER_CPU(desc->status)) {
141                 irqreturn_t action_ret;
142
143                 /*
144                  * No locking required for CPU-local interrupts:
145                  */
146                 if (desc->chip->ack)
147                         desc->chip->ack(irq);
148                 action_ret = handle_IRQ_event(irq, regs, desc->action);
149                 desc->chip->end(irq);
150                 return 1;
151         }
152
153         spin_lock(&desc->lock);
154         if (desc->chip->ack)
155                 desc->chip->ack(irq);
156         /*
157          * REPLAY is when Linux resends an IRQ that was dropped earlier
158          * WAITING is used by probe to mark irqs that are being tested
159          */
160         status = desc->status & ~(IRQ_REPLAY | IRQ_WAITING);
161         status |= IRQ_PENDING; /* we _want_ to handle it */
162
163         /*
164          * If the IRQ is disabled for whatever reason, we cannot
165          * use the action we have.
166          */
167         action = NULL;
168         if (likely(!(status & (IRQ_DISABLED | IRQ_INPROGRESS)))) {
169                 action = desc->action;
170                 status &= ~IRQ_PENDING; /* we commit to handling */
171                 status |= IRQ_INPROGRESS; /* we are handling it */
172         }
173         desc->status = status;
174
175         /*
176          * If there is no IRQ handler or it was disabled, exit early.
177          * Since we set PENDING, if another processor is handling
178          * a different instance of this same irq, the other processor
179          * will take care of it.
180          */
181         if (unlikely(!action))
182                 goto out;
183
184         /*
185          * Edge triggered interrupts need to remember
186          * pending events.
187          * This applies to any hw interrupts that allow a second
188          * instance of the same irq to arrive while we are in do_IRQ
189          * or in the handler. But the code here only handles the _second_
190          * instance of the irq, not the third or fourth. So it is mostly
191          * useful for irq hardware that does not mask cleanly in an
192          * SMP environment.
193          */
194         for (;;) {
195                 irqreturn_t action_ret;
196
197                 spin_unlock(&desc->lock);
198
199                 action_ret = handle_IRQ_event(irq, regs, action);
200
201                 spin_lock(&desc->lock);
202                 if (!noirqdebug)
203                         note_interrupt(irq, desc, action_ret, regs);
204                 if (likely(!(desc->status & IRQ_PENDING)))
205                         break;
206                 desc->status &= ~IRQ_PENDING;
207         }
208         desc->status &= ~IRQ_INPROGRESS;
209
210 out:
211         /*
212          * The ->end() handler has to deal with interrupts which got
213          * disabled while the handler was running.
214          */
215         desc->chip->end(irq);
216         spin_unlock(&desc->lock);
217
218         return 1;
219 }
220