Revert to Fedora kernel-2.6.17-1.2187_FC5 patched with vs2.0.2.1; there are too many...
[linux-2.6.git] / kernel / irq / handle.c
1 /*
2  * linux/kernel/irq/handle.c
3  *
4  * Copyright (C) 1992, 1998-2004 Linus Torvalds, Ingo Molnar
5  *
6  * This file contains the core interrupt handling code.
7  */
8
9 #include <linux/irq.h>
10 #include <linux/module.h>
11 #include <linux/random.h>
12 #include <linux/interrupt.h>
13 #include <linux/kernel_stat.h>
14 #include <linux/vs_base.h>
15 #include <linux/vs_context.h>
16
17 #include "internals.h"
18
19 /*
20  * Linux has a controller-independent interrupt architecture.
21  * Every controller has a 'controller-template', that is used
22  * by the main code to do the right thing. Each driver-visible
23  * interrupt source is transparently wired to the apropriate
24  * controller. Thus drivers need not be aware of the
25  * interrupt-controller.
26  *
27  * The code is designed to be easily extended with new/different
28  * interrupt controllers, without having to do assembly magic or
29  * having to touch the generic code.
30  *
31  * Controller mappings for all interrupt sources:
32  */
33 irq_desc_t irq_desc[NR_IRQS] __cacheline_aligned = {
34         [0 ... NR_IRQS-1] = {
35                 .status = IRQ_DISABLED,
36                 .handler = &no_irq_type,
37                 .lock = SPIN_LOCK_UNLOCKED
38         }
39 };
40
41 /*
42  * Generic 'no controller' code
43  */
44 static void end_none(unsigned int irq) { }
45 static void enable_none(unsigned int irq) { }
46 static void disable_none(unsigned int irq) { }
47 static void shutdown_none(unsigned int irq) { }
48 static unsigned int startup_none(unsigned int irq) { return 0; }
49
50 static void ack_none(unsigned int irq)
51 {
52         /*
53          * 'what should we do if we get a hw irq event on an illegal vector'.
54          * each architecture has to answer this themself.
55          */
56         ack_bad_irq(irq);
57 }
58
59 struct hw_interrupt_type no_irq_type = {
60         .typename =     "none",
61         .startup =      startup_none,
62         .shutdown =     shutdown_none,
63         .enable =       enable_none,
64         .disable =      disable_none,
65         .ack =          ack_none,
66         .end =          end_none,
67         .set_affinity = NULL
68 };
69
70 /*
71  * Special, empty irq handler:
72  */
73 irqreturn_t no_action(int cpl, void *dev_id, struct pt_regs *regs)
74 {
75         return IRQ_NONE;
76 }
77
78 /*
79  * Have got an event to handle:
80  */
81 fastcall int handle_IRQ_event(unsigned int irq, struct pt_regs *regs,
82                                 struct irqaction *action)
83 {
84         int ret, retval = 0, status = 0;
85
86         if (!(action->flags & SA_INTERRUPT))
87                 local_irq_enable();
88
89         do {
90                 ret = action->handler(irq, action->dev_id, regs);
91                 if (ret == IRQ_HANDLED)
92                         status |= action->flags;
93                 retval |= ret;
94                 action = action->next;
95         } while (action);
96
97         if (status & SA_SAMPLE_RANDOM)
98                 add_interrupt_randomness(irq);
99         local_irq_disable();
100
101         return retval;
102 }
103
104 /*
105  * do_IRQ handles all normal device IRQ's (the special
106  * SMP cross-CPU interrupts have their own specific
107  * handlers).
108  */
109 fastcall unsigned int __do_IRQ(unsigned int irq, struct pt_regs *regs)
110 {
111         irq_desc_t *desc = irq_desc + irq;
112         struct irqaction * action;
113         unsigned int status;
114
115         kstat_this_cpu.irqs[irq]++;
116         if (CHECK_IRQ_PER_CPU(desc->status)) {
117                 irqreturn_t action_ret;
118
119                 /*
120                  * No locking required for CPU-local interrupts:
121                  */
122                 if (desc->handler->ack)
123                         desc->handler->ack(irq);
124                 action_ret = handle_IRQ_event(irq, regs, desc->action);
125                 desc->handler->end(irq);
126                 return 1;
127         }
128
129         spin_lock(&desc->lock);
130         if (desc->handler->ack)
131                 desc->handler->ack(irq);
132         /*
133          * REPLAY is when Linux resends an IRQ that was dropped earlier
134          * WAITING is used by probe to mark irqs that are being tested
135          */
136         status = desc->status & ~(IRQ_REPLAY | IRQ_WAITING);
137         status |= IRQ_PENDING; /* we _want_ to handle it */
138
139         /*
140          * If the IRQ is disabled for whatever reason, we cannot
141          * use the action we have.
142          */
143         action = NULL;
144         if (likely(!(status & (IRQ_DISABLED | IRQ_INPROGRESS)))) {
145                 action = desc->action;
146                 status &= ~IRQ_PENDING; /* we commit to handling */
147                 status |= IRQ_INPROGRESS; /* we are handling it */
148         }
149         desc->status = status;
150
151         /*
152          * If there is no IRQ handler or it was disabled, exit early.
153          * Since we set PENDING, if another processor is handling
154          * a different instance of this same irq, the other processor
155          * will take care of it.
156          */
157         if (unlikely(!action))
158                 goto out;
159
160         /*
161          * Edge triggered interrupts need to remember
162          * pending events.
163          * This applies to any hw interrupts that allow a second
164          * instance of the same irq to arrive while we are in do_IRQ
165          * or in the handler. But the code here only handles the _second_
166          * instance of the irq, not the third or fourth. So it is mostly
167          * useful for irq hardware that does not mask cleanly in an
168          * SMP environment.
169          */
170         for (;;) {
171                 irqreturn_t action_ret;
172
173                 spin_unlock(&desc->lock);
174
175                 action_ret = handle_IRQ_event(irq, regs, action);
176
177                 spin_lock(&desc->lock);
178                 if (!noirqdebug)
179                         note_interrupt(irq, desc, action_ret, regs);
180                 if (likely(!(desc->status & IRQ_PENDING)))
181                         break;
182                 desc->status &= ~IRQ_PENDING;
183         }
184         desc->status &= ~IRQ_INPROGRESS;
185
186 out:
187         /*
188          * The ->end() handler has to deal with interrupts which got
189          * disabled while the handler was running.
190          */
191         desc->handler->end(irq);
192         spin_unlock(&desc->lock);
193
194         return 1;
195 }
196