2 * linux/kernel/irq/chip.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, for irq-chip
10 * Detailed information is available in Documentation/DocBook/genericirq
13 #include <linux/irq.h>
14 #include <linux/module.h>
15 #include <linux/interrupt.h>
16 #include <linux/kernel_stat.h>
18 #include "internals.h"
21 * set_irq_chip - set the irq chip for an irq
23 * @chip: pointer to irq chip description structure
25 int set_irq_chip(unsigned int irq
, struct irq_chip
*chip
)
27 struct irq_desc
*desc
;
31 printk(KERN_ERR
"Trying to install chip for IRQ%d\n", irq
);
39 desc
= irq_desc
+ irq
;
40 spin_lock_irqsave(&desc
->lock
, flags
);
41 irq_chip_set_defaults(chip
);
43 spin_unlock_irqrestore(&desc
->lock
, flags
);
47 EXPORT_SYMBOL(set_irq_chip
);
50 * set_irq_type - set the irq type for an irq
52 * @type: interrupt type - see include/linux/interrupt.h
54 int set_irq_type(unsigned int irq
, unsigned int type
)
56 struct irq_desc
*desc
;
61 printk(KERN_ERR
"Trying to set irq type for IRQ%d\n", irq
);
65 desc
= irq_desc
+ irq
;
66 if (desc
->chip
->set_type
) {
67 spin_lock_irqsave(&desc
->lock
, flags
);
68 ret
= desc
->chip
->set_type(irq
, type
);
69 spin_unlock_irqrestore(&desc
->lock
, flags
);
73 EXPORT_SYMBOL(set_irq_type
);
76 * set_irq_data - set irq type data for an irq
77 * @irq: Interrupt number
78 * @data: Pointer to interrupt specific data
80 * Set the hardware irq controller data for an irq
82 int set_irq_data(unsigned int irq
, void *data
)
84 struct irq_desc
*desc
;
89 "Trying to install controller data for IRQ%d\n", irq
);
93 desc
= irq_desc
+ irq
;
94 spin_lock_irqsave(&desc
->lock
, flags
);
95 desc
->handler_data
= data
;
96 spin_unlock_irqrestore(&desc
->lock
, flags
);
99 EXPORT_SYMBOL(set_irq_data
);
102 * set_irq_chip_data - set irq chip data for an irq
103 * @irq: Interrupt number
104 * @data: Pointer to chip specific data
106 * Set the hardware irq chip data for an irq
108 int set_irq_chip_data(unsigned int irq
, void *data
)
110 struct irq_desc
*desc
= irq_desc
+ irq
;
113 if (irq
>= NR_IRQS
|| !desc
->chip
) {
114 printk(KERN_ERR
"BUG: bad set_irq_chip_data(IRQ#%d)\n", irq
);
118 spin_lock_irqsave(&desc
->lock
, flags
);
119 desc
->chip_data
= data
;
120 spin_unlock_irqrestore(&desc
->lock
, flags
);
124 EXPORT_SYMBOL(set_irq_chip_data
);
127 * default enable function
129 static void default_enable(unsigned int irq
)
131 struct irq_desc
*desc
= irq_desc
+ irq
;
133 desc
->chip
->unmask(irq
);
134 desc
->status
&= ~IRQ_MASKED
;
138 * default disable function
140 static void default_disable(unsigned int irq
)
142 struct irq_desc
*desc
= irq_desc
+ irq
;
144 if (!(desc
->status
& IRQ_DELAYED_DISABLE
))
145 desc
->chip
->mask(irq
);
149 * default startup function
151 static unsigned int default_startup(unsigned int irq
)
153 irq_desc
[irq
].chip
->enable(irq
);
159 * Fixup enable/disable function pointers
161 void irq_chip_set_defaults(struct irq_chip
*chip
)
164 chip
->enable
= default_enable
;
166 chip
->disable
= default_disable
;
168 chip
->startup
= default_startup
;
170 chip
->shutdown
= chip
->disable
;
172 chip
->name
= chip
->typename
;
175 static inline void mask_ack_irq(struct irq_desc
*desc
, int irq
)
177 if (desc
->chip
->mask_ack
)
178 desc
->chip
->mask_ack(irq
);
180 desc
->chip
->mask(irq
);
181 desc
->chip
->ack(irq
);
186 * handle_simple_irq - Simple and software-decoded IRQs.
187 * @irq: the interrupt number
188 * @desc: the interrupt description structure for this irq
189 * @regs: pointer to a register structure
191 * Simple interrupts are either sent from a demultiplexing interrupt
192 * handler or come from hardware, where no interrupt hardware control
195 * Note: The caller is expected to handle the ack, clear, mask and
196 * unmask issues if necessary.
199 handle_simple_irq(unsigned int irq
, struct irq_desc
*desc
, struct pt_regs
*regs
)
201 struct irqaction
*action
;
202 irqreturn_t action_ret
;
203 const unsigned int cpu
= smp_processor_id();
205 spin_lock(&desc
->lock
);
207 if (unlikely(desc
->status
& IRQ_INPROGRESS
))
209 desc
->status
&= ~(IRQ_REPLAY
| IRQ_WAITING
);
210 kstat_cpu(cpu
).irqs
[irq
]++;
212 action
= desc
->action
;
213 if (unlikely(!action
|| (desc
->status
& IRQ_DISABLED
)))
216 desc
->status
|= IRQ_INPROGRESS
;
217 spin_unlock(&desc
->lock
);
219 action_ret
= handle_IRQ_event(irq
, regs
, action
);
221 note_interrupt(irq
, desc
, action_ret
, regs
);
223 spin_lock(&desc
->lock
);
224 desc
->status
&= ~IRQ_INPROGRESS
;
226 spin_unlock(&desc
->lock
);
230 * handle_level_irq - Level type irq handler
231 * @irq: the interrupt number
232 * @desc: the interrupt description structure for this irq
233 * @regs: pointer to a register structure
235 * Level type interrupts are active as long as the hardware line has
236 * the active level. This may require to mask the interrupt and unmask
237 * it after the associated handler has acknowledged the device, so the
238 * interrupt line is back to inactive.
241 handle_level_irq(unsigned int irq
, struct irq_desc
*desc
, struct pt_regs
*regs
)
243 unsigned int cpu
= smp_processor_id();
244 struct irqaction
*action
;
245 irqreturn_t action_ret
;
247 spin_lock(&desc
->lock
);
248 mask_ack_irq(desc
, irq
);
250 if (unlikely(desc
->status
& IRQ_INPROGRESS
))
252 desc
->status
&= ~(IRQ_REPLAY
| IRQ_WAITING
);
253 kstat_cpu(cpu
).irqs
[irq
]++;
256 * If its disabled or no action available
257 * keep it masked and get out of here
259 action
= desc
->action
;
260 if (unlikely(!action
|| (desc
->status
& IRQ_DISABLED
))) {
261 desc
->status
|= IRQ_PENDING
;
265 desc
->status
|= IRQ_INPROGRESS
;
266 desc
->status
&= ~IRQ_PENDING
;
267 spin_unlock(&desc
->lock
);
269 action_ret
= handle_IRQ_event(irq
, regs
, action
);
271 note_interrupt(irq
, desc
, action_ret
, regs
);
273 spin_lock(&desc
->lock
);
274 desc
->status
&= ~IRQ_INPROGRESS
;
275 if (!(desc
->status
& IRQ_DISABLED
) && desc
->chip
->unmask
)
276 desc
->chip
->unmask(irq
);
278 spin_unlock(&desc
->lock
);
282 * handle_fasteoi_irq - irq handler for transparent controllers
283 * @irq: the interrupt number
284 * @desc: the interrupt description structure for this irq
285 * @regs: pointer to a register structure
287 * Only a single callback will be issued to the chip: an ->eoi()
288 * call when the interrupt has been serviced. This enables support
289 * for modern forms of interrupt handlers, which handle the flow
290 * details in hardware, transparently.
293 handle_fasteoi_irq(unsigned int irq
, struct irq_desc
*desc
,
294 struct pt_regs
*regs
)
296 unsigned int cpu
= smp_processor_id();
297 struct irqaction
*action
;
298 irqreturn_t action_ret
;
300 spin_lock(&desc
->lock
);
302 if (unlikely(desc
->status
& IRQ_INPROGRESS
))
305 desc
->status
&= ~(IRQ_REPLAY
| IRQ_WAITING
);
306 kstat_cpu(cpu
).irqs
[irq
]++;
309 * If its disabled or no action available
310 * keep it masked and get out of here
312 action
= desc
->action
;
313 if (unlikely(!action
|| (desc
->status
& IRQ_DISABLED
))) {
314 desc
->status
|= IRQ_PENDING
;
318 desc
->status
|= IRQ_INPROGRESS
;
319 desc
->status
&= ~IRQ_PENDING
;
320 spin_unlock(&desc
->lock
);
322 action_ret
= handle_IRQ_event(irq
, regs
, action
);
324 note_interrupt(irq
, desc
, action_ret
, regs
);
326 spin_lock(&desc
->lock
);
327 desc
->status
&= ~IRQ_INPROGRESS
;
329 desc
->chip
->eoi(irq
);
331 spin_unlock(&desc
->lock
);
335 * handle_edge_irq - edge type IRQ handler
336 * @irq: the interrupt number
337 * @desc: the interrupt description structure for this irq
338 * @regs: pointer to a register structure
340 * Interrupt occures on the falling and/or rising edge of a hardware
341 * signal. The occurence is latched into the irq controller hardware
342 * and must be acked in order to be reenabled. After the ack another
343 * interrupt can happen on the same source even before the first one
344 * is handled by the assosiacted event handler. If this happens it
345 * might be necessary to disable (mask) the interrupt depending on the
346 * controller hardware. This requires to reenable the interrupt inside
347 * of the loop which handles the interrupts which have arrived while
348 * the handler was running. If all pending interrupts are handled, the
352 handle_edge_irq(unsigned int irq
, struct irq_desc
*desc
, struct pt_regs
*regs
)
354 const unsigned int cpu
= smp_processor_id();
356 spin_lock(&desc
->lock
);
358 desc
->status
&= ~(IRQ_REPLAY
| IRQ_WAITING
);
361 * If we're currently running this IRQ, or its disabled,
362 * we shouldn't process the IRQ. Mark it pending, handle
363 * the necessary masking and go out
365 if (unlikely((desc
->status
& (IRQ_INPROGRESS
| IRQ_DISABLED
)) ||
367 desc
->status
|= (IRQ_PENDING
| IRQ_MASKED
);
368 mask_ack_irq(desc
, irq
);
372 kstat_cpu(cpu
).irqs
[irq
]++;
374 /* Start handling the irq */
375 desc
->chip
->ack(irq
);
377 /* Mark the IRQ currently in progress.*/
378 desc
->status
|= IRQ_INPROGRESS
;
381 struct irqaction
*action
= desc
->action
;
382 irqreturn_t action_ret
;
384 if (unlikely(!action
)) {
385 desc
->chip
->mask(irq
);
390 * When another irq arrived while we were handling
391 * one, we could have masked the irq.
392 * Renable it, if it was not disabled in meantime.
394 if (unlikely((desc
->status
&
395 (IRQ_PENDING
| IRQ_MASKED
| IRQ_DISABLED
)) ==
396 (IRQ_PENDING
| IRQ_MASKED
))) {
397 desc
->chip
->unmask(irq
);
398 desc
->status
&= ~IRQ_MASKED
;
401 desc
->status
&= ~IRQ_PENDING
;
402 spin_unlock(&desc
->lock
);
403 action_ret
= handle_IRQ_event(irq
, regs
, action
);
405 note_interrupt(irq
, desc
, action_ret
, regs
);
406 spin_lock(&desc
->lock
);
408 } while ((desc
->status
& (IRQ_PENDING
| IRQ_DISABLED
)) == IRQ_PENDING
);
410 desc
->status
&= ~IRQ_INPROGRESS
;
412 spin_unlock(&desc
->lock
);
417 * handle_percpu_IRQ - Per CPU local irq handler
418 * @irq: the interrupt number
419 * @desc: the interrupt description structure for this irq
420 * @regs: pointer to a register structure
422 * Per CPU interrupts on SMP machines without locking requirements
425 handle_percpu_irq(unsigned int irq
, struct irq_desc
*desc
, struct pt_regs
*regs
)
427 irqreturn_t action_ret
;
429 kstat_this_cpu
.irqs
[irq
]++;
432 desc
->chip
->ack(irq
);
434 action_ret
= handle_IRQ_event(irq
, regs
, desc
->action
);
436 note_interrupt(irq
, desc
, action_ret
, regs
);
439 desc
->chip
->eoi(irq
);
442 #endif /* CONFIG_SMP */
445 __set_irq_handler(unsigned int irq
,
446 void fastcall (*handle
)(unsigned int, irq_desc_t
*,
450 struct irq_desc
*desc
;
453 if (irq
>= NR_IRQS
) {
455 "Trying to install type control for IRQ%d\n", irq
);
459 desc
= irq_desc
+ irq
;
462 handle
= handle_bad_irq
;
464 if (desc
->chip
== &no_irq_chip
) {
465 printk(KERN_WARNING
"Trying to install %sinterrupt handler "
466 "for IRQ%d\n", is_chained
? "chained " : " ", irq
);
468 * Some ARM implementations install a handler for really dumb
469 * interrupt hardware without setting an irq_chip. This worked
470 * with the ARM no_irq_chip but the check in setup_irq would
471 * prevent us to setup the interrupt at all. Switch it to
472 * dummy_irq_chip for easy transition.
474 desc
->chip
= &dummy_irq_chip
;
477 spin_lock_irqsave(&desc
->lock
, flags
);
480 if (handle
== handle_bad_irq
) {
481 if (desc
->chip
!= &no_irq_chip
) {
482 desc
->chip
->mask(irq
);
483 desc
->chip
->ack(irq
);
485 desc
->status
|= IRQ_DISABLED
;
488 desc
->handle_irq
= handle
;
490 if (handle
!= handle_bad_irq
&& is_chained
) {
491 desc
->status
&= ~IRQ_DISABLED
;
492 desc
->status
|= IRQ_NOREQUEST
| IRQ_NOPROBE
;
494 desc
->chip
->unmask(irq
);
496 spin_unlock_irqrestore(&desc
->lock
, flags
);
500 set_irq_chip_and_handler(unsigned int irq
, struct irq_chip
*chip
,
501 void fastcall (*handle
)(unsigned int,
505 set_irq_chip(irq
, chip
);
506 __set_irq_handler(irq
, handle
, 0);
510 * Get a descriptive string for the highlevel handler, for
511 * /proc/interrupts output:
514 handle_irq_name(void fastcall (*handle
)(unsigned int, struct irq_desc
*,
517 if (handle
== handle_level_irq
)
519 if (handle
== handle_fasteoi_irq
)
521 if (handle
== handle_edge_irq
)
523 if (handle
== handle_simple_irq
)
526 if (handle
== handle_percpu_irq
)
529 if (handle
== handle_bad_irq
)
This page took 0.048715 seconds and 6 git commands to generate.