Merge to Fedora kernel-2.6.18-1.2255_FC5-vs2.0.2.2-rc9 patched with stable patch...
[linux-2.6.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 #include <linux/vs_context.h>
19
20 #include "internals.h"
21
22 /**
23  * handle_bad_irq - handle spurious and unhandled irqs
24  * @irq:       the interrupt number
25  * @desc:      description of the interrupt
26  * @regs:      pointer to a register structure
27  *
28  * Handles spurious and unhandled IRQ's. It also prints a debugmessage.
29  */
30 void fastcall
31 handle_bad_irq(unsigned int irq, struct irq_desc *desc, struct pt_regs *regs)
32 {
33         print_irq_desc(irq, desc);
34         kstat_this_cpu.irqs[irq]++;
35         ack_bad_irq(irq);
36 }
37
38 /*
39  * Linux has a controller-independent interrupt architecture.
40  * Every controller has a 'controller-template', that is used
41  * by the main code to do the right thing. Each driver-visible
42  * interrupt source is transparently wired to the appropriate
43  * controller. Thus drivers need not be aware of the
44  * interrupt-controller.
45  *
46  * The code is designed to be easily extended with new/different
47  * interrupt controllers, without having to do assembly magic or
48  * having to touch the generic code.
49  *
50  * Controller mappings for all interrupt sources:
51  */
52 struct irq_desc irq_desc[NR_IRQS] __cacheline_aligned = {
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,
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         print_irq_desc(irq, irq_desc + irq);
72         ack_bad_irq(irq);
73 }
74
75 /*
76  * NOP functions
77  */
78 static void noop(unsigned int irq)
79 {
80 }
81
82 static unsigned int noop_ret(unsigned int irq)
83 {
84         return 0;
85 }
86
87 /*
88  * Generic no controller implementation
89  */
90 struct irq_chip no_irq_chip = {
91         .name           = "none",
92         .startup        = noop_ret,
93         .shutdown       = noop,
94         .enable         = noop,
95         .disable        = noop,
96         .ack            = ack_bad,
97         .end            = noop,
98 };
99
100 /*
101  * Generic dummy implementation which can be used for
102  * real dumb interrupt sources
103  */
104 struct irq_chip dummy_irq_chip = {
105         .name           = "dummy",
106         .startup        = noop_ret,
107         .shutdown       = noop,
108         .enable         = noop,
109         .disable        = noop,
110         .ack            = noop,
111         .mask           = noop,
112         .unmask         = noop,
113         .end            = noop,
114 };
115
116 /*
117  * Special, empty irq handler:
118  */
119 irqreturn_t no_action(int cpl, void *dev_id, struct pt_regs *regs)
120 {
121         return IRQ_NONE;
122 }
123
124 /**
125  * handle_IRQ_event - irq action chain handler
126  * @irq:        the interrupt number
127  * @regs:       pointer to a register structure
128  * @action:     the interrupt action chain for this irq
129  *
130  * Handles the action chain of an irq event
131  */
132 irqreturn_t handle_IRQ_event(unsigned int irq, struct pt_regs *regs,
133                              struct irqaction *action)
134 {
135         irqreturn_t ret, retval = IRQ_NONE;
136         unsigned int status = 0;
137
138         handle_dynamic_tick(action);
139
140         if (!(action->flags & IRQF_DISABLED))
141                 local_irq_enable_in_hardirq();
142
143         do {
144                 ret = action->handler(irq, action->dev_id, regs);
145                 if (ret == IRQ_HANDLED)
146                         status |= action->flags;
147                 retval |= ret;
148                 action = action->next;
149         } while (action);
150
151         if (status & IRQF_SAMPLE_RANDOM)
152                 add_interrupt_randomness(irq);
153         local_irq_disable();
154
155         return retval;
156 }
157
158 /**
159  * __do_IRQ - original all in one highlevel IRQ handler
160  * @irq:        the interrupt number
161  * @regs:       pointer to a register structure
162  *
163  * __do_IRQ handles all normal device IRQ's (the special
164  * SMP cross-CPU interrupts have their own specific
165  * handlers).
166  *
167  * This is the original x86 implementation which is used for every
168  * interrupt type.
169  */
170 fastcall unsigned int __do_IRQ(unsigned int irq, struct pt_regs *regs)
171 {
172         struct irq_desc *desc = irq_desc + irq;
173         struct irqaction *action;
174         unsigned int status;
175
176         kstat_this_cpu.irqs[irq]++;
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                 action_ret = handle_IRQ_event(irq, regs, desc->action);
186                 desc->chip->end(irq);
187                 return 1;
188         }
189
190         spin_lock(&desc->lock);
191         if (desc->chip->ack)
192                 desc->chip->ack(irq);
193         /*
194          * REPLAY is when Linux resends an IRQ that was dropped earlier
195          * WAITING is used by probe to mark irqs that are being tested
196          */
197         status = desc->status & ~(IRQ_REPLAY | IRQ_WAITING);
198         status |= IRQ_PENDING; /* we _want_ to handle it */
199
200         /*
201          * If the IRQ is disabled for whatever reason, we cannot
202          * use the action we have.
203          */
204         action = NULL;
205         if (likely(!(status & (IRQ_DISABLED | IRQ_INPROGRESS)))) {
206                 action = desc->action;
207                 status &= ~IRQ_PENDING; /* we commit to handling */
208                 status |= IRQ_INPROGRESS; /* we are handling it */
209         }
210         desc->status = status;
211
212         /*
213          * If there is no IRQ handler or it was disabled, exit early.
214          * Since we set PENDING, if another processor is handling
215          * a different instance of this same irq, the other processor
216          * will take care of it.
217          */
218         if (unlikely(!action))
219                 goto out;
220
221         /*
222          * Edge triggered interrupts need to remember
223          * pending events.
224          * This applies to any hw interrupts that allow a second
225          * instance of the same irq to arrive while we are in do_IRQ
226          * or in the handler. But the code here only handles the _second_
227          * instance of the irq, not the third or fourth. So it is mostly
228          * useful for irq hardware that does not mask cleanly in an
229          * SMP environment.
230          */
231         for (;;) {
232                 irqreturn_t action_ret;
233
234                 spin_unlock(&desc->lock);
235
236                 action_ret = handle_IRQ_event(irq, regs, action);
237
238                 spin_lock(&desc->lock);
239                 if (!noirqdebug)
240                         note_interrupt(irq, desc, action_ret, regs);
241                 if (likely(!(desc->status & IRQ_PENDING)))
242                         break;
243                 desc->status &= ~IRQ_PENDING;
244         }
245         desc->status &= ~IRQ_INPROGRESS;
246
247 out:
248         /*
249          * The ->end() handler has to deal with interrupts which got
250          * disabled while the handler was running.
251          */
252         desc->chip->end(irq);
253         spin_unlock(&desc->lock);
254
255         return 1;
256 }
257
258 #ifdef CONFIG_TRACE_IRQFLAGS
259
260 /*
261  * lockdep: we want to handle all irq_desc locks as a single lock-class:
262  */
263 static struct lock_class_key irq_desc_lock_class;
264
265 void early_init_irq_lock_class(void)
266 {
267         int i;
268
269         for (i = 0; i < NR_IRQS; i++)
270                 lockdep_set_class(&irq_desc[i].lock, &irq_desc_lock_class);
271 }
272
273 #endif