blob: bddcb8f5fea44f4f5da41db915c9fb71c81331a9 [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
21/*
22 * Linux has a controller-independent interrupt architecture.
23 * Every controller has a 'controller-template', that is used
24 * by the main code to do the right thing. Each driver-visible
Ingo Molnar06fcb0c2006-06-29 02:24:40 -070025 * interrupt source is transparently wired to the appropriate
Linus Torvalds1da177e2005-04-16 15:20:36 -070026 * controller. Thus drivers need not be aware of the
27 * interrupt-controller.
28 *
29 * The code is designed to be easily extended with new/different
30 * interrupt controllers, without having to do assembly magic or
31 * having to touch the generic code.
32 *
33 * Controller mappings for all interrupt sources:
34 */
Ingo Molnar34ffdb72006-06-29 02:24:40 -070035struct irq_desc irq_desc[NR_IRQS] __cacheline_aligned = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070036 [0 ... NR_IRQS-1] = {
Zhang, Yanmin4f167fb2005-05-16 21:53:43 -070037 .status = IRQ_DISABLED,
Ingo Molnard1bef4e2006-06-29 02:24:36 -070038 .chip = &no_irq_type,
Thomas Gleixner94d39e12006-06-29 02:24:50 -070039 .depth = 1,
Ingo Molnara53da522006-06-29 02:24:38 -070040 .lock = SPIN_LOCK_UNLOCKED,
41#ifdef CONFIG_SMP
42 .affinity = CPU_MASK_ALL
43#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070044 }
45};
46
47/*
Ingo Molnar77a5afe2006-06-29 02:24:46 -070048 * What should we do if we get a hw irq event on an illegal vector?
49 * Each architecture has to answer this themself.
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 */
Ingo Molnar77a5afe2006-06-29 02:24:46 -070051static void ack_bad(unsigned int irq)
Linus Torvalds1da177e2005-04-16 15:20:36 -070052{
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 ack_bad_irq(irq);
54}
55
Ingo Molnar77a5afe2006-06-29 02:24:46 -070056/*
57 * NOP functions
58 */
59static void noop(unsigned int irq)
60{
61}
62
63static unsigned int noop_ret(unsigned int irq)
64{
65 return 0;
66}
67
68/*
69 * Generic no controller implementation
70 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070071struct hw_interrupt_type no_irq_type = {
Ingo Molnar77a5afe2006-06-29 02:24:46 -070072 .typename = "none",
73 .startup = noop_ret,
74 .shutdown = noop,
75 .enable = noop,
76 .disable = noop,
77 .ack = ack_bad,
78 .end = noop,
Linus Torvalds1da177e2005-04-16 15:20:36 -070079};
80
81/*
82 * Special, empty irq handler:
83 */
84irqreturn_t no_action(int cpl, void *dev_id, struct pt_regs *regs)
85{
86 return IRQ_NONE;
87}
88
Ingo Molnar8d28bc72006-06-29 02:24:46 -070089/**
90 * handle_IRQ_event - irq action chain handler
91 * @irq: the interrupt number
92 * @regs: pointer to a register structure
93 * @action: the interrupt action chain for this irq
94 *
95 * Handles the action chain of an irq event
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 */
Ingo Molnar2e60bbb2006-06-29 02:24:39 -070097irqreturn_t handle_IRQ_event(unsigned int irq, struct pt_regs *regs,
98 struct irqaction *action)
Linus Torvalds1da177e2005-04-16 15:20:36 -070099{
Jan Beulich908dcec2006-06-23 02:06:00 -0700100 irqreturn_t ret, retval = IRQ_NONE;
101 unsigned int status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102
103 if (!(action->flags & SA_INTERRUPT))
104 local_irq_enable();
105
106 do {
107 ret = action->handler(irq, action->dev_id, regs);
108 if (ret == IRQ_HANDLED)
109 status |= action->flags;
110 retval |= ret;
111 action = action->next;
112 } while (action);
113
114 if (status & SA_SAMPLE_RANDOM)
115 add_interrupt_randomness(irq);
116 local_irq_disable();
117
118 return retval;
119}
120
Ingo Molnar8d28bc72006-06-29 02:24:46 -0700121/**
122 * __do_IRQ - original all in one highlevel IRQ handler
123 * @irq: the interrupt number
124 * @regs: pointer to a register structure
125 *
126 * __do_IRQ handles all normal device IRQ's (the special
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 * SMP cross-CPU interrupts have their own specific
128 * handlers).
Ingo Molnar8d28bc72006-06-29 02:24:46 -0700129 *
130 * This is the original x86 implementation which is used for every
131 * interrupt type.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 */
133fastcall unsigned int __do_IRQ(unsigned int irq, struct pt_regs *regs)
134{
Ingo Molnar34ffdb72006-06-29 02:24:40 -0700135 struct irq_desc *desc = irq_desc + irq;
Ingo Molnar06fcb0c2006-06-29 02:24:40 -0700136 struct irqaction *action;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 unsigned int status;
138
139 kstat_this_cpu.irqs[irq]++;
Karsten Wiesef26fdd52005-09-06 15:17:25 -0700140 if (CHECK_IRQ_PER_CPU(desc->status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 irqreturn_t action_ret;
142
143 /*
144 * No locking required for CPU-local interrupts:
145 */
Ingo Molnard1bef4e2006-06-29 02:24:36 -0700146 if (desc->chip->ack)
147 desc->chip->ack(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 action_ret = handle_IRQ_event(irq, regs, desc->action);
Ingo Molnard1bef4e2006-06-29 02:24:36 -0700149 desc->chip->end(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 return 1;
151 }
152
153 spin_lock(&desc->lock);
Ingo Molnard1bef4e2006-06-29 02:24:36 -0700154 if (desc->chip->ack)
155 desc->chip->ack(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 /*
157 * REPLAY is when Linux resends an IRQ that was dropped earlier
158 * WAITING is used by probe to mark irqs that are being tested
159 */
160 status = desc->status & ~(IRQ_REPLAY | IRQ_WAITING);
161 status |= IRQ_PENDING; /* we _want_ to handle it */
162
163 /*
164 * If the IRQ is disabled for whatever reason, we cannot
165 * use the action we have.
166 */
167 action = NULL;
168 if (likely(!(status & (IRQ_DISABLED | IRQ_INPROGRESS)))) {
169 action = desc->action;
170 status &= ~IRQ_PENDING; /* we commit to handling */
171 status |= IRQ_INPROGRESS; /* we are handling it */
172 }
173 desc->status = status;
174
175 /*
176 * If there is no IRQ handler or it was disabled, exit early.
177 * Since we set PENDING, if another processor is handling
178 * a different instance of this same irq, the other processor
179 * will take care of it.
180 */
181 if (unlikely(!action))
182 goto out;
183
184 /*
185 * Edge triggered interrupts need to remember
186 * pending events.
187 * This applies to any hw interrupts that allow a second
188 * instance of the same irq to arrive while we are in do_IRQ
189 * or in the handler. But the code here only handles the _second_
190 * instance of the irq, not the third or fourth. So it is mostly
191 * useful for irq hardware that does not mask cleanly in an
192 * SMP environment.
193 */
194 for (;;) {
195 irqreturn_t action_ret;
196
197 spin_unlock(&desc->lock);
198
199 action_ret = handle_IRQ_event(irq, regs, action);
200
201 spin_lock(&desc->lock);
202 if (!noirqdebug)
Alan Cox200803d2005-06-28 20:45:18 -0700203 note_interrupt(irq, desc, action_ret, regs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 if (likely(!(desc->status & IRQ_PENDING)))
205 break;
206 desc->status &= ~IRQ_PENDING;
207 }
208 desc->status &= ~IRQ_INPROGRESS;
209
210out:
211 /*
212 * The ->end() handler has to deal with interrupts which got
213 * disabled while the handler was running.
214 */
Ingo Molnard1bef4e2006-06-29 02:24:36 -0700215 desc->chip->end(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 spin_unlock(&desc->lock);
217
218 return 1;
219}
220