blob: fc4e906aedbd77ef5cf7057dcb8b3d089b240e14 [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
19#include "internals.h"
20
Thomas Gleixner6a6de9e2006-06-29 02:24:51 -070021/**
22 * handle_bad_irq - handle spurious and unhandled irqs
23 */
24void fastcall
25handle_bad_irq(unsigned int irq, struct irq_desc *desc, struct pt_regs *regs)
26{
Ingo Molnar43f77752006-06-29 02:24:58 -070027 print_irq_desc(irq, desc);
Thomas Gleixner6a6de9e2006-06-29 02:24:51 -070028 kstat_this_cpu.irqs[irq]++;
29 ack_bad_irq(irq);
30}
31
Linus Torvalds1da177e2005-04-16 15:20:36 -070032/*
33 * Linux has a controller-independent interrupt architecture.
34 * Every controller has a 'controller-template', that is used
35 * by the main code to do the right thing. Each driver-visible
Ingo Molnar06fcb0c2006-06-29 02:24:40 -070036 * interrupt source is transparently wired to the appropriate
Linus Torvalds1da177e2005-04-16 15:20:36 -070037 * controller. Thus drivers need not be aware of the
38 * interrupt-controller.
39 *
40 * The code is designed to be easily extended with new/different
41 * interrupt controllers, without having to do assembly magic or
42 * having to touch the generic code.
43 *
44 * Controller mappings for all interrupt sources:
45 */
Ingo Molnar34ffdb72006-06-29 02:24:40 -070046struct irq_desc irq_desc[NR_IRQS] __cacheline_aligned = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070047 [0 ... NR_IRQS-1] = {
Zhang, Yanmin4f167fb2005-05-16 21:53:43 -070048 .status = IRQ_DISABLED,
Ingo Molnarf1c26622006-06-29 02:24:57 -070049 .chip = &no_irq_chip,
Ingo Molnar7a557132006-06-29 02:24:54 -070050 .handle_irq = handle_bad_irq,
Thomas Gleixner94d39e12006-06-29 02:24:50 -070051 .depth = 1,
Ingo Molnara53da522006-06-29 02:24:38 -070052 .lock = SPIN_LOCK_UNLOCKED,
53#ifdef CONFIG_SMP
54 .affinity = CPU_MASK_ALL
55#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070056 }
57};
58
59/*
Ingo Molnar77a5afe2006-06-29 02:24:46 -070060 * What should we do if we get a hw irq event on an illegal vector?
61 * Each architecture has to answer this themself.
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 */
Ingo Molnar77a5afe2006-06-29 02:24:46 -070063static void ack_bad(unsigned int irq)
Linus Torvalds1da177e2005-04-16 15:20:36 -070064{
Ingo Molnar43f77752006-06-29 02:24:58 -070065 print_irq_desc(irq, irq_desc + irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 ack_bad_irq(irq);
67}
68
Ingo Molnar77a5afe2006-06-29 02:24:46 -070069/*
70 * NOP functions
71 */
72static void noop(unsigned int irq)
73{
74}
75
76static unsigned int noop_ret(unsigned int irq)
77{
78 return 0;
79}
80
81/*
82 * Generic no controller implementation
83 */
Ingo Molnarf1c26622006-06-29 02:24:57 -070084struct irq_chip no_irq_chip = {
85 .name = "none",
Ingo Molnar77a5afe2006-06-29 02:24:46 -070086 .startup = noop_ret,
87 .shutdown = noop,
88 .enable = noop,
89 .disable = noop,
90 .ack = ack_bad,
91 .end = noop,
Linus Torvalds1da177e2005-04-16 15:20:36 -070092};
93
94/*
Thomas Gleixnerf8b54732006-07-01 22:30:08 +010095 * Generic dummy implementation which can be used for
96 * real dumb interrupt sources
97 */
98struct irq_chip dummy_irq_chip = {
99 .name = "dummy",
100 .startup = noop_ret,
101 .shutdown = noop,
102 .enable = noop,
103 .disable = noop,
104 .ack = noop,
105 .mask = noop,
106 .unmask = noop,
107 .end = noop,
108};
109
110/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 * Special, empty irq handler:
112 */
113irqreturn_t no_action(int cpl, void *dev_id, struct pt_regs *regs)
114{
115 return IRQ_NONE;
116}
117
Ingo Molnar8d28bc72006-06-29 02:24:46 -0700118/**
119 * handle_IRQ_event - irq action chain handler
120 * @irq: the interrupt number
121 * @regs: pointer to a register structure
122 * @action: the interrupt action chain for this irq
123 *
124 * Handles the action chain of an irq event
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 */
Ingo Molnar2e60bbb2006-06-29 02:24:39 -0700126irqreturn_t handle_IRQ_event(unsigned int irq, struct pt_regs *regs,
127 struct irqaction *action)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128{
Jan Beulich908dcec2006-06-23 02:06:00 -0700129 irqreturn_t ret, retval = IRQ_NONE;
130 unsigned int status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
Thomas Gleixnerd061daa2006-07-03 02:18:48 +0200132 handle_dynamic_tick(action);
Thomas Gleixnera2166ab2006-07-01 22:30:07 +0100133
Thomas Gleixner3cca53b2006-07-01 19:29:31 -0700134 if (!(action->flags & IRQF_DISABLED))
Ingo Molnar366c7f52006-07-03 00:25:25 -0700135 local_irq_enable_in_hardirq();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136
137 do {
138 ret = action->handler(irq, action->dev_id, regs);
139 if (ret == IRQ_HANDLED)
140 status |= action->flags;
141 retval |= ret;
142 action = action->next;
143 } while (action);
144
Thomas Gleixner3cca53b2006-07-01 19:29:31 -0700145 if (status & IRQF_SAMPLE_RANDOM)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 add_interrupt_randomness(irq);
147 local_irq_disable();
148
149 return retval;
150}
151
Ingo Molnar8d28bc72006-06-29 02:24:46 -0700152/**
153 * __do_IRQ - original all in one highlevel IRQ handler
154 * @irq: the interrupt number
155 * @regs: pointer to a register structure
156 *
157 * __do_IRQ handles all normal device IRQ's (the special
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 * SMP cross-CPU interrupts have their own specific
159 * handlers).
Ingo Molnar8d28bc72006-06-29 02:24:46 -0700160 *
161 * This is the original x86 implementation which is used for every
162 * interrupt type.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 */
164fastcall unsigned int __do_IRQ(unsigned int irq, struct pt_regs *regs)
165{
Ingo Molnar34ffdb72006-06-29 02:24:40 -0700166 struct irq_desc *desc = irq_desc + irq;
Ingo Molnar06fcb0c2006-06-29 02:24:40 -0700167 struct irqaction *action;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 unsigned int status;
169
170 kstat_this_cpu.irqs[irq]++;
Karsten Wiesef26fdd52005-09-06 15:17:25 -0700171 if (CHECK_IRQ_PER_CPU(desc->status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 irqreturn_t action_ret;
173
174 /*
175 * No locking required for CPU-local interrupts:
176 */
Ingo Molnard1bef4e2006-06-29 02:24:36 -0700177 if (desc->chip->ack)
178 desc->chip->ack(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 action_ret = handle_IRQ_event(irq, regs, desc->action);
Ingo Molnard1bef4e2006-06-29 02:24:36 -0700180 desc->chip->end(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 return 1;
182 }
183
184 spin_lock(&desc->lock);
Ingo Molnard1bef4e2006-06-29 02:24:36 -0700185 if (desc->chip->ack)
186 desc->chip->ack(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 /*
188 * REPLAY is when Linux resends an IRQ that was dropped earlier
189 * WAITING is used by probe to mark irqs that are being tested
190 */
191 status = desc->status & ~(IRQ_REPLAY | IRQ_WAITING);
192 status |= IRQ_PENDING; /* we _want_ to handle it */
193
194 /*
195 * If the IRQ is disabled for whatever reason, we cannot
196 * use the action we have.
197 */
198 action = NULL;
199 if (likely(!(status & (IRQ_DISABLED | IRQ_INPROGRESS)))) {
200 action = desc->action;
201 status &= ~IRQ_PENDING; /* we commit to handling */
202 status |= IRQ_INPROGRESS; /* we are handling it */
203 }
204 desc->status = status;
205
206 /*
207 * If there is no IRQ handler or it was disabled, exit early.
208 * Since we set PENDING, if another processor is handling
209 * a different instance of this same irq, the other processor
210 * will take care of it.
211 */
212 if (unlikely(!action))
213 goto out;
214
215 /*
216 * Edge triggered interrupts need to remember
217 * pending events.
218 * This applies to any hw interrupts that allow a second
219 * instance of the same irq to arrive while we are in do_IRQ
220 * or in the handler. But the code here only handles the _second_
221 * instance of the irq, not the third or fourth. So it is mostly
222 * useful for irq hardware that does not mask cleanly in an
223 * SMP environment.
224 */
225 for (;;) {
226 irqreturn_t action_ret;
227
228 spin_unlock(&desc->lock);
229
230 action_ret = handle_IRQ_event(irq, regs, action);
231
232 spin_lock(&desc->lock);
233 if (!noirqdebug)
Alan Cox200803d2005-06-28 20:45:18 -0700234 note_interrupt(irq, desc, action_ret, regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 if (likely(!(desc->status & IRQ_PENDING)))
236 break;
237 desc->status &= ~IRQ_PENDING;
238 }
239 desc->status &= ~IRQ_INPROGRESS;
240
241out:
242 /*
243 * The ->end() handler has to deal with interrupts which got
244 * disabled while the handler was running.
245 */
Ingo Molnard1bef4e2006-06-29 02:24:36 -0700246 desc->chip->end(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 spin_unlock(&desc->lock);
248
249 return 1;
250}
251
Ingo Molnar243c7622006-07-03 00:25:06 -0700252#ifdef CONFIG_TRACE_IRQFLAGS
253
254/*
255 * lockdep: we want to handle all irq_desc locks as a single lock-class:
256 */
257static struct lock_class_key irq_desc_lock_class;
258
259void early_init_irq_lock_class(void)
260{
261 int i;
262
263 for (i = 0; i < NR_IRQS; i++)
264 lockdep_set_class(&irq_desc[i].lock, &irq_desc_lock_class);
265}
266
267#endif