blob: 5a360dd4331b0505a6f4e54c0c26317f23d3c189 [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/*
95 * Special, empty irq handler:
96 */
97irqreturn_t no_action(int cpl, void *dev_id, struct pt_regs *regs)
98{
99 return IRQ_NONE;
100}
101
Ingo Molnar8d28bc72006-06-29 02:24:46 -0700102/**
103 * handle_IRQ_event - irq action chain handler
104 * @irq: the interrupt number
105 * @regs: pointer to a register structure
106 * @action: the interrupt action chain for this irq
107 *
108 * Handles the action chain of an irq event
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 */
Ingo Molnar2e60bbb2006-06-29 02:24:39 -0700110irqreturn_t handle_IRQ_event(unsigned int irq, struct pt_regs *regs,
111 struct irqaction *action)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112{
Jan Beulich908dcec2006-06-23 02:06:00 -0700113 irqreturn_t ret, retval = IRQ_NONE;
114 unsigned int status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115
116 if (!(action->flags & SA_INTERRUPT))
117 local_irq_enable();
118
119 do {
120 ret = action->handler(irq, action->dev_id, regs);
121 if (ret == IRQ_HANDLED)
122 status |= action->flags;
123 retval |= ret;
124 action = action->next;
125 } while (action);
126
127 if (status & SA_SAMPLE_RANDOM)
128 add_interrupt_randomness(irq);
129 local_irq_disable();
130
131 return retval;
132}
133
Ingo Molnar8d28bc72006-06-29 02:24:46 -0700134/**
135 * __do_IRQ - original all in one highlevel IRQ handler
136 * @irq: the interrupt number
137 * @regs: pointer to a register structure
138 *
139 * __do_IRQ handles all normal device IRQ's (the special
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 * SMP cross-CPU interrupts have their own specific
141 * handlers).
Ingo Molnar8d28bc72006-06-29 02:24:46 -0700142 *
143 * This is the original x86 implementation which is used for every
144 * interrupt type.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 */
146fastcall unsigned int __do_IRQ(unsigned int irq, struct pt_regs *regs)
147{
Ingo Molnar34ffdb72006-06-29 02:24:40 -0700148 struct irq_desc *desc = irq_desc + irq;
Ingo Molnar06fcb0c2006-06-29 02:24:40 -0700149 struct irqaction *action;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 unsigned int status;
151
152 kstat_this_cpu.irqs[irq]++;
Karsten Wiesef26fdd52005-09-06 15:17:25 -0700153 if (CHECK_IRQ_PER_CPU(desc->status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 irqreturn_t action_ret;
155
156 /*
157 * No locking required for CPU-local interrupts:
158 */
Ingo Molnard1bef4e2006-06-29 02:24:36 -0700159 if (desc->chip->ack)
160 desc->chip->ack(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 action_ret = handle_IRQ_event(irq, regs, desc->action);
Ingo Molnard1bef4e2006-06-29 02:24:36 -0700162 desc->chip->end(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 return 1;
164 }
165
166 spin_lock(&desc->lock);
Ingo Molnard1bef4e2006-06-29 02:24:36 -0700167 if (desc->chip->ack)
168 desc->chip->ack(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 /*
170 * REPLAY is when Linux resends an IRQ that was dropped earlier
171 * WAITING is used by probe to mark irqs that are being tested
172 */
173 status = desc->status & ~(IRQ_REPLAY | IRQ_WAITING);
174 status |= IRQ_PENDING; /* we _want_ to handle it */
175
176 /*
177 * If the IRQ is disabled for whatever reason, we cannot
178 * use the action we have.
179 */
180 action = NULL;
181 if (likely(!(status & (IRQ_DISABLED | IRQ_INPROGRESS)))) {
182 action = desc->action;
183 status &= ~IRQ_PENDING; /* we commit to handling */
184 status |= IRQ_INPROGRESS; /* we are handling it */
185 }
186 desc->status = status;
187
188 /*
189 * If there is no IRQ handler or it was disabled, exit early.
190 * Since we set PENDING, if another processor is handling
191 * a different instance of this same irq, the other processor
192 * will take care of it.
193 */
194 if (unlikely(!action))
195 goto out;
196
197 /*
198 * Edge triggered interrupts need to remember
199 * pending events.
200 * This applies to any hw interrupts that allow a second
201 * instance of the same irq to arrive while we are in do_IRQ
202 * or in the handler. But the code here only handles the _second_
203 * instance of the irq, not the third or fourth. So it is mostly
204 * useful for irq hardware that does not mask cleanly in an
205 * SMP environment.
206 */
207 for (;;) {
208 irqreturn_t action_ret;
209
210 spin_unlock(&desc->lock);
211
212 action_ret = handle_IRQ_event(irq, regs, action);
213
214 spin_lock(&desc->lock);
215 if (!noirqdebug)
Alan Cox200803d2005-06-28 20:45:18 -0700216 note_interrupt(irq, desc, action_ret, regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 if (likely(!(desc->status & IRQ_PENDING)))
218 break;
219 desc->status &= ~IRQ_PENDING;
220 }
221 desc->status &= ~IRQ_INPROGRESS;
222
223out:
224 /*
225 * The ->end() handler has to deal with interrupts which got
226 * disabled while the handler was running.
227 */
Ingo Molnard1bef4e2006-06-29 02:24:36 -0700228 desc->chip->end(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 spin_unlock(&desc->lock);
230
231 return 1;
232}
233