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"
22 * handle_bad_irq - handle spurious and unhandled irqs
23 * @irq: the interrupt number
24 * @desc: description of the interrupt
25 * @regs: pointer to a register structure
27 * Handles spurious and unhandled IRQ's. It also prints a debugmessage.
30 handle_bad_irq(unsigned int irq
, struct irq_desc
*desc
, struct pt_regs
*regs
)
32 print_irq_desc(irq
, desc
);
33 kstat_this_cpu
.irqs
[irq
]++;
38 * Linux has a controller-independent interrupt architecture.
39 * Every controller has a 'controller-template', that is used
40 * by the main code to do the right thing. Each driver-visible
41 * interrupt source is transparently wired to the appropriate
42 * controller. Thus drivers need not be aware of the
43 * interrupt-controller.
45 * The code is designed to be easily extended with new/different
46 * interrupt controllers, without having to do assembly magic or
47 * having to touch the generic code.
49 * Controller mappings for all interrupt sources:
51 struct irq_desc irq_desc
[NR_IRQS
] __cacheline_aligned
= {
53 .status
= IRQ_DISABLED
,
55 .handle_irq
= handle_bad_irq
,
57 .lock
= SPIN_LOCK_UNLOCKED
,
59 .affinity
= CPU_MASK_ALL
65 * What should we do if we get a hw irq event on an illegal vector?
66 * Each architecture has to answer this themself.
68 static void ack_bad(unsigned int irq
)
70 print_irq_desc(irq
, irq_desc
+ irq
);
77 static void noop(unsigned int irq
)
81 static unsigned int noop_ret(unsigned int irq
)
87 * Generic no controller implementation
89 struct irq_chip no_irq_chip
= {
100 * Generic dummy implementation which can be used for
101 * real dumb interrupt sources
103 struct irq_chip dummy_irq_chip
= {
116 * Special, empty irq handler:
118 irqreturn_t
no_action(int cpl
, void *dev_id
, struct pt_regs
*regs
)
124 * handle_IRQ_event - irq action chain handler
125 * @irq: the interrupt number
126 * @regs: pointer to a register structure
127 * @action: the interrupt action chain for this irq
129 * Handles the action chain of an irq event
131 irqreturn_t
handle_IRQ_event(unsigned int irq
, struct pt_regs
*regs
,
132 struct irqaction
*action
)
134 irqreturn_t ret
, retval
= IRQ_NONE
;
135 unsigned int status
= 0;
137 handle_dynamic_tick(action
);
139 if (!(action
->flags
& IRQF_DISABLED
))
140 local_irq_enable_in_hardirq();
143 ret
= action
->handler(irq
, action
->dev_id
, regs
);
144 if (ret
== IRQ_HANDLED
)
145 status
|= action
->flags
;
147 action
= action
->next
;
150 if (status
& IRQF_SAMPLE_RANDOM
)
151 add_interrupt_randomness(irq
);
158 * __do_IRQ - original all in one highlevel IRQ handler
159 * @irq: the interrupt number
160 * @regs: pointer to a register structure
162 * __do_IRQ handles all normal device IRQ's (the special
163 * SMP cross-CPU interrupts have their own specific
166 * This is the original x86 implementation which is used for every
169 fastcall
unsigned int __do_IRQ(unsigned int irq
, struct pt_regs
*regs
)
171 struct irq_desc
*desc
= irq_desc
+ irq
;
172 struct irqaction
*action
;
175 kstat_this_cpu
.irqs
[irq
]++;
176 if (CHECK_IRQ_PER_CPU(desc
->status
)) {
177 irqreturn_t action_ret
;
180 * No locking required for CPU-local interrupts:
183 desc
->chip
->ack(irq
);
184 action_ret
= handle_IRQ_event(irq
, regs
, desc
->action
);
185 desc
->chip
->end(irq
);
189 spin_lock(&desc
->lock
);
191 desc
->chip
->ack(irq
);
193 * REPLAY is when Linux resends an IRQ that was dropped earlier
194 * WAITING is used by probe to mark irqs that are being tested
196 status
= desc
->status
& ~(IRQ_REPLAY
| IRQ_WAITING
);
197 status
|= IRQ_PENDING
; /* we _want_ to handle it */
200 * If the IRQ is disabled for whatever reason, we cannot
201 * use the action we have.
204 if (likely(!(status
& (IRQ_DISABLED
| IRQ_INPROGRESS
)))) {
205 action
= desc
->action
;
206 status
&= ~IRQ_PENDING
; /* we commit to handling */
207 status
|= IRQ_INPROGRESS
; /* we are handling it */
209 desc
->status
= status
;
212 * If there is no IRQ handler or it was disabled, exit early.
213 * Since we set PENDING, if another processor is handling
214 * a different instance of this same irq, the other processor
215 * will take care of it.
217 if (unlikely(!action
))
221 * Edge triggered interrupts need to remember
223 * This applies to any hw interrupts that allow a second
224 * instance of the same irq to arrive while we are in do_IRQ
225 * or in the handler. But the code here only handles the _second_
226 * instance of the irq, not the third or fourth. So it is mostly
227 * useful for irq hardware that does not mask cleanly in an
231 irqreturn_t action_ret
;
233 spin_unlock(&desc
->lock
);
235 action_ret
= handle_IRQ_event(irq
, regs
, action
);
237 spin_lock(&desc
->lock
);
239 note_interrupt(irq
, desc
, action_ret
, regs
);
240 if (likely(!(desc
->status
& IRQ_PENDING
)))
242 desc
->status
&= ~IRQ_PENDING
;
244 desc
->status
&= ~IRQ_INPROGRESS
;
248 * The ->end() handler has to deal with interrupts which got
249 * disabled while the handler was running.
251 desc
->chip
->end(irq
);
252 spin_unlock(&desc
->lock
);
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)
268 for (i
= 0; i
< NR_IRQS
; i
++)
269 lockdep_set_class(&irq_desc
[i
].lock
, &irq_desc_lock_class
);