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