blob: e71266c3803ef32f06a7620308d6450d4800274c [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/kernel/irq/handle.c
3 *
Ingo Molnara34db9b2006-06-29 02:24:50 -07004 * Copyright (C) 1992, 1998-2006 Linus Torvalds, Ingo Molnar
5 * Copyright (C) 2005-2006, Thomas Gleixner, Russell King
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 *
7 * This file contains the core interrupt handling code.
Ingo Molnara34db9b2006-06-29 02:24:50 -07008 *
9 * Detailed information is available in Documentation/DocBook/genericirq
10 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070011 */
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
Thomas Gleixnera2166ab2006-07-01 22:30:07 +010019#if defined(CONFIG_NO_IDLE_HZ) && defined(CONFIG_ARM)
20#include <asm/dyntick.h>
21#endif
22
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include "internals.h"
24
Thomas Gleixner6a6de9e2006-06-29 02:24:51 -070025/**
26 * handle_bad_irq - handle spurious and unhandled irqs
27 */
28void fastcall
29handle_bad_irq(unsigned int irq, struct irq_desc *desc, struct pt_regs *regs)
30{
Ingo Molnar43f77752006-06-29 02:24:58 -070031 print_irq_desc(irq, desc);
Thomas Gleixner6a6de9e2006-06-29 02:24:51 -070032 kstat_this_cpu.irqs[irq]++;
33 ack_bad_irq(irq);
34}
35
Linus Torvalds1da177e2005-04-16 15:20:36 -070036/*
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
Ingo Molnar06fcb0c2006-06-29 02:24:40 -070040 * interrupt source is transparently wired to the appropriate
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 * controller. Thus drivers need not be aware of the
42 * interrupt-controller.
43 *
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.
47 *
48 * Controller mappings for all interrupt sources:
49 */
Ingo Molnar34ffdb72006-06-29 02:24:40 -070050struct irq_desc irq_desc[NR_IRQS] __cacheline_aligned = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 [0 ... NR_IRQS-1] = {
Zhang, Yanmin4f167fb2005-05-16 21:53:43 -070052 .status = IRQ_DISABLED,
Ingo Molnarf1c26622006-06-29 02:24:57 -070053 .chip = &no_irq_chip,
Ingo Molnar7a557132006-06-29 02:24:54 -070054 .handle_irq = handle_bad_irq,
Thomas Gleixner94d39e12006-06-29 02:24:50 -070055 .depth = 1,
Ingo Molnara53da522006-06-29 02:24:38 -070056 .lock = SPIN_LOCK_UNLOCKED,
57#ifdef CONFIG_SMP
58 .affinity = CPU_MASK_ALL
59#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 }
61};
62
63/*
Ingo Molnar77a5afe2006-06-29 02:24:46 -070064 * What should we do if we get a hw irq event on an illegal vector?
65 * Each architecture has to answer this themself.
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 */
Ingo Molnar77a5afe2006-06-29 02:24:46 -070067static void ack_bad(unsigned int irq)
Linus Torvalds1da177e2005-04-16 15:20:36 -070068{
Ingo Molnar43f77752006-06-29 02:24:58 -070069 print_irq_desc(irq, irq_desc + irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 ack_bad_irq(irq);
71}
72
Ingo Molnar77a5afe2006-06-29 02:24:46 -070073/*
74 * NOP functions
75 */
76static void noop(unsigned int irq)
77{
78}
79
80static unsigned int noop_ret(unsigned int irq)
81{
82 return 0;
83}
84
85/*
86 * Generic no controller implementation
87 */
Ingo Molnarf1c26622006-06-29 02:24:57 -070088struct irq_chip no_irq_chip = {
89 .name = "none",
Ingo Molnar77a5afe2006-06-29 02:24:46 -070090 .startup = noop_ret,
91 .shutdown = noop,
92 .enable = noop,
93 .disable = noop,
94 .ack = ack_bad,
95 .end = noop,
Linus Torvalds1da177e2005-04-16 15:20:36 -070096};
97
98/*
Thomas Gleixnerf8b54732006-07-01 22:30:08 +010099 * Generic dummy implementation which can be used for
100 * real dumb interrupt sources
101 */
102struct 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,
112};
113
114/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 * Special, empty irq handler:
116 */
117irqreturn_t no_action(int cpl, void *dev_id, struct pt_regs *regs)
118{
119 return IRQ_NONE;
120}
121
Ingo Molnar8d28bc72006-06-29 02:24:46 -0700122/**
123 * handle_IRQ_event - irq action chain handler
124 * @irq: the interrupt number
125 * @regs: pointer to a register structure
126 * @action: the interrupt action chain for this irq
127 *
128 * Handles the action chain of an irq event
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 */
Ingo Molnar2e60bbb2006-06-29 02:24:39 -0700130irqreturn_t handle_IRQ_event(unsigned int irq, struct pt_regs *regs,
131 struct irqaction *action)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132{
Jan Beulich908dcec2006-06-23 02:06:00 -0700133 irqreturn_t ret, retval = IRQ_NONE;
134 unsigned int status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135
Thomas Gleixnera2166ab2006-07-01 22:30:07 +0100136#if defined(CONFIG_NO_IDLE_HZ) && defined(CONFIG_ARM)
137 if (!(action->flags & SA_TIMER) && system_timer->dyn_tick != NULL) {
138 write_seqlock(&xtime_lock);
139 if (system_timer->dyn_tick->state & DYN_TICK_ENABLED)
140 system_timer->dyn_tick->handler(irq, 0, regs);
141 write_sequnlock(&xtime_lock);
142 }
143#endif
144
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 if (!(action->flags & SA_INTERRUPT))
146 local_irq_enable();
147
148 do {
149 ret = action->handler(irq, action->dev_id, regs);
150 if (ret == IRQ_HANDLED)
151 status |= action->flags;
152 retval |= ret;
153 action = action->next;
154 } while (action);
155
156 if (status & SA_SAMPLE_RANDOM)
157 add_interrupt_randomness(irq);
158 local_irq_disable();
159
160 return retval;
161}
162
Ingo Molnar8d28bc72006-06-29 02:24:46 -0700163/**
164 * __do_IRQ - original all in one highlevel IRQ handler
165 * @irq: the interrupt number
166 * @regs: pointer to a register structure
167 *
168 * __do_IRQ handles all normal device IRQ's (the special
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 * SMP cross-CPU interrupts have their own specific
170 * handlers).
Ingo Molnar8d28bc72006-06-29 02:24:46 -0700171 *
172 * This is the original x86 implementation which is used for every
173 * interrupt type.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 */
175fastcall unsigned int __do_IRQ(unsigned int irq, struct pt_regs *regs)
176{
Ingo Molnar34ffdb72006-06-29 02:24:40 -0700177 struct irq_desc *desc = irq_desc + irq;
Ingo Molnar06fcb0c2006-06-29 02:24:40 -0700178 struct irqaction *action;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 unsigned int status;
180
181 kstat_this_cpu.irqs[irq]++;
Karsten Wiesef26fdd52005-09-06 15:17:25 -0700182 if (CHECK_IRQ_PER_CPU(desc->status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 irqreturn_t action_ret;
184
185 /*
186 * No locking required for CPU-local interrupts:
187 */
Ingo Molnard1bef4e2006-06-29 02:24:36 -0700188 if (desc->chip->ack)
189 desc->chip->ack(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190 action_ret = handle_IRQ_event(irq, regs, desc->action);
Ingo Molnard1bef4e2006-06-29 02:24:36 -0700191 desc->chip->end(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 return 1;
193 }
194
195 spin_lock(&desc->lock);
Ingo Molnard1bef4e2006-06-29 02:24:36 -0700196 if (desc->chip->ack)
197 desc->chip->ack(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 /*
199 * REPLAY is when Linux resends an IRQ that was dropped earlier
200 * WAITING is used by probe to mark irqs that are being tested
201 */
202 status = desc->status & ~(IRQ_REPLAY | IRQ_WAITING);
203 status |= IRQ_PENDING; /* we _want_ to handle it */
204
205 /*
206 * If the IRQ is disabled for whatever reason, we cannot
207 * use the action we have.
208 */
209 action = NULL;
210 if (likely(!(status & (IRQ_DISABLED | IRQ_INPROGRESS)))) {
211 action = desc->action;
212 status &= ~IRQ_PENDING; /* we commit to handling */
213 status |= IRQ_INPROGRESS; /* we are handling it */
214 }
215 desc->status = status;
216
217 /*
218 * If there is no IRQ handler or it was disabled, exit early.
219 * Since we set PENDING, if another processor is handling
220 * a different instance of this same irq, the other processor
221 * will take care of it.
222 */
223 if (unlikely(!action))
224 goto out;
225
226 /*
227 * Edge triggered interrupts need to remember
228 * pending events.
229 * This applies to any hw interrupts that allow a second
230 * instance of the same irq to arrive while we are in do_IRQ
231 * or in the handler. But the code here only handles the _second_
232 * instance of the irq, not the third or fourth. So it is mostly
233 * useful for irq hardware that does not mask cleanly in an
234 * SMP environment.
235 */
236 for (;;) {
237 irqreturn_t action_ret;
238
239 spin_unlock(&desc->lock);
240
241 action_ret = handle_IRQ_event(irq, regs, action);
242
243 spin_lock(&desc->lock);
244 if (!noirqdebug)
Alan Cox200803d2005-06-28 20:45:18 -0700245 note_interrupt(irq, desc, action_ret, regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 if (likely(!(desc->status & IRQ_PENDING)))
247 break;
248 desc->status &= ~IRQ_PENDING;
249 }
250 desc->status &= ~IRQ_INPROGRESS;
251
252out:
253 /*
254 * The ->end() handler has to deal with interrupts which got
255 * disabled while the handler was running.
256 */
Ingo Molnard1bef4e2006-06-29 02:24:36 -0700257 desc->chip->end(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 spin_unlock(&desc->lock);
259
260 return 1;
261}
262