PNPACPI: simplify irq_flags()
[pv_ops_mirror.git] / kernel / irq / handle.c
blobe391cbb1f56665e4f751706403d69bd3bd86c471
1 /*
2 * linux/kernel/irq/handle.c
4 * Copyright (C) 1992, 1998-2006 Linus Torvalds, Ingo Molnar
5 * Copyright (C) 2005-2006, Thomas Gleixner, Russell King
7 * This file contains the core interrupt handling code.
9 * Detailed information is available in Documentation/DocBook/genericirq
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>
19 #include "internals.h"
21 /**
22 * handle_bad_irq - handle spurious and unhandled irqs
23 * @irq: the interrupt number
24 * @desc: description of the interrupt
26 * Handles spurious and unhandled IRQ's. It also prints a debugmessage.
28 void fastcall
29 handle_bad_irq(unsigned int irq, struct irq_desc *desc)
31 print_irq_desc(irq, desc);
32 kstat_this_cpu.irqs[irq]++;
33 ack_bad_irq(irq);
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.
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.
48 * Controller mappings for all interrupt sources:
50 struct irq_desc irq_desc[NR_IRQS] __cacheline_aligned_in_smp = {
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(irq_desc->lock),
57 #ifdef CONFIG_SMP
58 .affinity = CPU_MASK_ALL
59 #endif
64 * What should we do if we get a hw irq event on an illegal vector?
65 * Each architecture has to answer this themself.
67 static void ack_bad(unsigned int irq)
69 print_irq_desc(irq, irq_desc + irq);
70 ack_bad_irq(irq);
74 * NOP functions
76 static void noop(unsigned int irq)
80 static unsigned int noop_ret(unsigned int irq)
82 return 0;
86 * Generic no controller implementation
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,
99 * Generic dummy implementation which can be used for
100 * real dumb interrupt sources
102 struct irq_chip dummy_irq_chip = {
103 .name = "dummy",
104 .startup = noop_ret,
105 .shutdown = noop,
106 .enable = noop,
107 .disable = noop,
108 .ack = noop,
109 .mask = noop,
110 .unmask = noop,
111 .end = noop,
115 * Special, empty irq handler:
117 irqreturn_t no_action(int cpl, void *dev_id)
119 return IRQ_NONE;
123 * handle_IRQ_event - irq action chain handler
124 * @irq: the interrupt number
125 * @action: the interrupt action chain for this irq
127 * Handles the action chain of an irq event
129 irqreturn_t handle_IRQ_event(unsigned int irq, struct irqaction *action)
131 irqreturn_t ret, retval = IRQ_NONE;
132 unsigned int status = 0;
134 handle_dynamic_tick(action);
136 if (!(action->flags & IRQF_DISABLED))
137 local_irq_enable_in_hardirq();
139 do {
140 ret = action->handler(irq, action->dev_id);
141 if (ret == IRQ_HANDLED)
142 status |= action->flags;
143 retval |= ret;
144 action = action->next;
145 } while (action);
147 if (status & IRQF_SAMPLE_RANDOM)
148 add_interrupt_randomness(irq);
149 local_irq_disable();
151 return retval;
154 #ifndef CONFIG_GENERIC_HARDIRQS_NO__DO_IRQ
156 * __do_IRQ - original all in one highlevel IRQ handler
157 * @irq: the interrupt number
159 * __do_IRQ handles all normal device IRQ's (the special
160 * SMP cross-CPU interrupts have their own specific
161 * handlers).
163 * This is the original x86 implementation which is used for every
164 * interrupt type.
166 fastcall unsigned int __do_IRQ(unsigned int irq)
168 struct irq_desc *desc = irq_desc + irq;
169 struct irqaction *action;
170 unsigned int status;
172 kstat_this_cpu.irqs[irq]++;
173 if (CHECK_IRQ_PER_CPU(desc->status)) {
174 irqreturn_t action_ret;
177 * No locking required for CPU-local interrupts:
179 if (desc->chip->ack)
180 desc->chip->ack(irq);
181 action_ret = handle_IRQ_event(irq, desc->action);
182 if (!noirqdebug)
183 note_interrupt(irq, desc, action_ret);
184 desc->chip->end(irq);
185 return 1;
188 spin_lock(&desc->lock);
189 if (desc->chip->ack)
190 desc->chip->ack(irq);
192 * REPLAY is when Linux resends an IRQ that was dropped earlier
193 * WAITING is used by probe to mark irqs that are being tested
195 status = desc->status & ~(IRQ_REPLAY | IRQ_WAITING);
196 status |= IRQ_PENDING; /* we _want_ to handle it */
199 * If the IRQ is disabled for whatever reason, we cannot
200 * use the action we have.
202 action = NULL;
203 if (likely(!(status & (IRQ_DISABLED | IRQ_INPROGRESS)))) {
204 action = desc->action;
205 status &= ~IRQ_PENDING; /* we commit to handling */
206 status |= IRQ_INPROGRESS; /* we are handling it */
208 desc->status = status;
211 * If there is no IRQ handler or it was disabled, exit early.
212 * Since we set PENDING, if another processor is handling
213 * a different instance of this same irq, the other processor
214 * will take care of it.
216 if (unlikely(!action))
217 goto out;
220 * Edge triggered interrupts need to remember
221 * pending events.
222 * This applies to any hw interrupts that allow a second
223 * instance of the same irq to arrive while we are in do_IRQ
224 * or in the handler. But the code here only handles the _second_
225 * instance of the irq, not the third or fourth. So it is mostly
226 * useful for irq hardware that does not mask cleanly in an
227 * SMP environment.
229 for (;;) {
230 irqreturn_t action_ret;
232 spin_unlock(&desc->lock);
234 action_ret = handle_IRQ_event(irq, action);
235 if (!noirqdebug)
236 note_interrupt(irq, desc, action_ret);
238 spin_lock(&desc->lock);
239 if (likely(!(desc->status & IRQ_PENDING)))
240 break;
241 desc->status &= ~IRQ_PENDING;
243 desc->status &= ~IRQ_INPROGRESS;
245 out:
247 * The ->end() handler has to deal with interrupts which got
248 * disabled while the handler was running.
250 desc->chip->end(irq);
251 spin_unlock(&desc->lock);
253 return 1;
255 #endif
257 #ifdef CONFIG_TRACE_IRQFLAGS
260 * lockdep: we want to handle all irq_desc locks as a single lock-class:
262 static struct lock_class_key irq_desc_lock_class;
264 void early_init_irq_lock_class(void)
266 int i;
268 for (i = 0; i < NR_IRQS; i++)
269 lockdep_set_class(&irq_desc[i].lock, &irq_desc_lock_class);
272 #endif