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
25 handle_bad_irq(unsigned int irq
, struct irq_desc
*desc
, struct pt_regs
*regs
)
27 print_irq_desc(irq
, desc
);
28 kstat_this_cpu
.irqs
[irq
]++;
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
36 * interrupt source is transparently wired to the appropriate
37 * controller. Thus drivers need not be aware of the
38 * interrupt-controller.
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.
44 * Controller mappings for all interrupt sources:
46 struct irq_desc irq_desc
[NR_IRQS
] __cacheline_aligned
= {
48 .status
= IRQ_DISABLED
,
50 .handle_irq
= handle_bad_irq
,
52 .lock
= SPIN_LOCK_UNLOCKED
,
54 .affinity
= CPU_MASK_ALL
60 * What should we do if we get a hw irq event on an illegal vector?
61 * Each architecture has to answer this themself.
63 static void ack_bad(unsigned int irq
)
65 print_irq_desc(irq
, irq_desc
+ irq
);
72 static void noop(unsigned int irq
)
76 static unsigned int noop_ret(unsigned int irq
)
82 * Generic no controller implementation
84 struct irq_chip no_irq_chip
= {
95 * Generic dummy implementation which can be used for
96 * real dumb interrupt sources
98 struct irq_chip dummy_irq_chip
= {
111 * Special, empty irq handler:
113 irqreturn_t
no_action(int cpl
, void *dev_id
, struct pt_regs
*regs
)
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
124 * Handles the action chain of an irq event
126 irqreturn_t
handle_IRQ_event(unsigned int irq
, struct pt_regs
*regs
,
127 struct irqaction
*action
)
129 irqreturn_t ret
, retval
= IRQ_NONE
;
130 unsigned int status
= 0;
132 handle_dynamic_tick(action
);
134 if (!(action
->flags
& IRQF_DISABLED
))
135 local_irq_enable_in_hardirq();
138 ret
= action
->handler(irq
, action
->dev_id
, regs
);
139 if (ret
== IRQ_HANDLED
)
140 status
|= action
->flags
;
142 action
= action
->next
;
145 if (status
& IRQF_SAMPLE_RANDOM
)
146 add_interrupt_randomness(irq
);
153 * __do_IRQ - original all in one highlevel IRQ handler
154 * @irq: the interrupt number
155 * @regs: pointer to a register structure
157 * __do_IRQ handles all normal device IRQ's (the special
158 * SMP cross-CPU interrupts have their own specific
161 * This is the original x86 implementation which is used for every
164 fastcall
unsigned int __do_IRQ(unsigned int irq
, struct pt_regs
*regs
)
166 struct irq_desc
*desc
= irq_desc
+ irq
;
167 struct irqaction
*action
;
170 kstat_this_cpu
.irqs
[irq
]++;
171 if (CHECK_IRQ_PER_CPU(desc
->status
)) {
172 irqreturn_t action_ret
;
175 * No locking required for CPU-local interrupts:
178 desc
->chip
->ack(irq
);
179 action_ret
= handle_IRQ_event(irq
, regs
, desc
->action
);
180 desc
->chip
->end(irq
);
184 spin_lock(&desc
->lock
);
186 desc
->chip
->ack(irq
);
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
191 status
= desc
->status
& ~(IRQ_REPLAY
| IRQ_WAITING
);
192 status
|= IRQ_PENDING
; /* we _want_ to handle it */
195 * If the IRQ is disabled for whatever reason, we cannot
196 * use the action we have.
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 */
204 desc
->status
= status
;
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.
212 if (unlikely(!action
))
216 * Edge triggered interrupts need to remember
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
226 irqreturn_t action_ret
;
228 spin_unlock(&desc
->lock
);
230 action_ret
= handle_IRQ_event(irq
, regs
, action
);
232 spin_lock(&desc
->lock
);
234 note_interrupt(irq
, desc
, action_ret
, regs
);
235 if (likely(!(desc
->status
& IRQ_PENDING
)))
237 desc
->status
&= ~IRQ_PENDING
;
239 desc
->status
&= ~IRQ_INPROGRESS
;
243 * The ->end() handler has to deal with interrupts which got
244 * disabled while the handler was running.
246 desc
->chip
->end(irq
);
247 spin_unlock(&desc
->lock
);
252 #ifdef CONFIG_TRACE_IRQFLAGS
255 * lockdep: we want to handle all irq_desc locks as a single lock-class:
257 static struct lock_class_key irq_desc_lock_class
;
259 void early_init_irq_lock_class(void)
263 for (i
= 0; i
< NR_IRQS
; i
++)
264 lockdep_set_class(&irq_desc
[i
].lock
, &irq_desc_lock_class
);