[PATCH] RCU: CREDITS and MAINTAINERS
[linux-2.6/openmoko-kernel/knife-kernel.git] / kernel / irq / chip.c
blob4cf65f5c6a74f5697d7411391207cdcd5431e1ea
1 /*
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
8 * based architectures.
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"
20 /**
21 * dynamic_irq_init - initialize a dynamically allocated irq
22 * @irq: irq number to initialize
24 void dynamic_irq_init(unsigned int irq)
26 struct irq_desc *desc;
27 unsigned long flags;
29 if (irq >= NR_IRQS) {
30 printk(KERN_ERR "Trying to initialize invalid IRQ%d\n", irq);
31 WARN_ON(1);
32 return;
35 /* Ensure we don't have left over values from a previous use of this irq */
36 desc = irq_desc + irq;
37 spin_lock_irqsave(&desc->lock, flags);
38 desc->status = IRQ_DISABLED;
39 desc->chip = &no_irq_chip;
40 desc->handle_irq = handle_bad_irq;
41 desc->depth = 1;
42 desc->handler_data = NULL;
43 desc->chip_data = NULL;
44 desc->action = NULL;
45 desc->irq_count = 0;
46 desc->irqs_unhandled = 0;
47 #ifdef CONFIG_SMP
48 desc->affinity = CPU_MASK_ALL;
49 #endif
50 spin_unlock_irqrestore(&desc->lock, flags);
53 /**
54 * dynamic_irq_cleanup - cleanup a dynamically allocated irq
55 * @irq: irq number to initialize
57 void dynamic_irq_cleanup(unsigned int irq)
59 struct irq_desc *desc;
60 unsigned long flags;
62 if (irq >= NR_IRQS) {
63 printk(KERN_ERR "Trying to cleanup invalid IRQ%d\n", irq);
64 WARN_ON(1);
65 return;
68 desc = irq_desc + irq;
69 spin_lock_irqsave(&desc->lock, flags);
70 if (desc->action) {
71 spin_unlock_irqrestore(&desc->lock, flags);
72 printk(KERN_ERR "Destroying IRQ%d without calling free_irq\n",
73 irq);
74 WARN_ON(1);
75 return;
77 desc->handle_irq = handle_bad_irq;
78 desc->chip = &no_irq_chip;
79 spin_unlock_irqrestore(&desc->lock, flags);
83 /**
84 * set_irq_chip - set the irq chip for an irq
85 * @irq: irq number
86 * @chip: pointer to irq chip description structure
88 int set_irq_chip(unsigned int irq, struct irq_chip *chip)
90 struct irq_desc *desc;
91 unsigned long flags;
93 if (irq >= NR_IRQS) {
94 printk(KERN_ERR "Trying to install chip for IRQ%d\n", irq);
95 WARN_ON(1);
96 return -EINVAL;
99 if (!chip)
100 chip = &no_irq_chip;
102 desc = irq_desc + irq;
103 spin_lock_irqsave(&desc->lock, flags);
104 irq_chip_set_defaults(chip);
105 desc->chip = chip;
106 spin_unlock_irqrestore(&desc->lock, flags);
108 return 0;
110 EXPORT_SYMBOL(set_irq_chip);
113 * set_irq_type - set the irq type for an irq
114 * @irq: irq number
115 * @type: interrupt type - see include/linux/interrupt.h
117 int set_irq_type(unsigned int irq, unsigned int type)
119 struct irq_desc *desc;
120 unsigned long flags;
121 int ret = -ENXIO;
123 if (irq >= NR_IRQS) {
124 printk(KERN_ERR "Trying to set irq type for IRQ%d\n", irq);
125 return -ENODEV;
128 desc = irq_desc + irq;
129 if (desc->chip->set_type) {
130 spin_lock_irqsave(&desc->lock, flags);
131 ret = desc->chip->set_type(irq, type);
132 spin_unlock_irqrestore(&desc->lock, flags);
134 return ret;
136 EXPORT_SYMBOL(set_irq_type);
139 * set_irq_data - set irq type data for an irq
140 * @irq: Interrupt number
141 * @data: Pointer to interrupt specific data
143 * Set the hardware irq controller data for an irq
145 int set_irq_data(unsigned int irq, void *data)
147 struct irq_desc *desc;
148 unsigned long flags;
150 if (irq >= NR_IRQS) {
151 printk(KERN_ERR
152 "Trying to install controller data for IRQ%d\n", irq);
153 return -EINVAL;
156 desc = irq_desc + irq;
157 spin_lock_irqsave(&desc->lock, flags);
158 desc->handler_data = data;
159 spin_unlock_irqrestore(&desc->lock, flags);
160 return 0;
162 EXPORT_SYMBOL(set_irq_data);
165 * set_irq_chip_data - set irq chip data for an irq
166 * @irq: Interrupt number
167 * @data: Pointer to chip specific data
169 * Set the hardware irq chip data for an irq
171 int set_irq_chip_data(unsigned int irq, void *data)
173 struct irq_desc *desc = irq_desc + irq;
174 unsigned long flags;
176 if (irq >= NR_IRQS || !desc->chip) {
177 printk(KERN_ERR "BUG: bad set_irq_chip_data(IRQ#%d)\n", irq);
178 return -EINVAL;
181 spin_lock_irqsave(&desc->lock, flags);
182 desc->chip_data = data;
183 spin_unlock_irqrestore(&desc->lock, flags);
185 return 0;
187 EXPORT_SYMBOL(set_irq_chip_data);
190 * default enable function
192 static void default_enable(unsigned int irq)
194 struct irq_desc *desc = irq_desc + irq;
196 desc->chip->unmask(irq);
197 desc->status &= ~IRQ_MASKED;
201 * default disable function
203 static void default_disable(unsigned int irq)
205 struct irq_desc *desc = irq_desc + irq;
207 if (!(desc->status & IRQ_DELAYED_DISABLE))
208 desc->chip->mask(irq);
212 * default startup function
214 static unsigned int default_startup(unsigned int irq)
216 irq_desc[irq].chip->enable(irq);
218 return 0;
222 * Fixup enable/disable function pointers
224 void irq_chip_set_defaults(struct irq_chip *chip)
226 if (!chip->enable)
227 chip->enable = default_enable;
228 if (!chip->disable)
229 chip->disable = default_disable;
230 if (!chip->startup)
231 chip->startup = default_startup;
232 if (!chip->shutdown)
233 chip->shutdown = chip->disable;
234 if (!chip->name)
235 chip->name = chip->typename;
238 static inline void mask_ack_irq(struct irq_desc *desc, int irq)
240 if (desc->chip->mask_ack)
241 desc->chip->mask_ack(irq);
242 else {
243 desc->chip->mask(irq);
244 desc->chip->ack(irq);
249 * handle_simple_irq - Simple and software-decoded IRQs.
250 * @irq: the interrupt number
251 * @desc: the interrupt description structure for this irq
252 * @regs: pointer to a register structure
254 * Simple interrupts are either sent from a demultiplexing interrupt
255 * handler or come from hardware, where no interrupt hardware control
256 * is necessary.
258 * Note: The caller is expected to handle the ack, clear, mask and
259 * unmask issues if necessary.
261 void fastcall
262 handle_simple_irq(unsigned int irq, struct irq_desc *desc, struct pt_regs *regs)
264 struct irqaction *action;
265 irqreturn_t action_ret;
266 const unsigned int cpu = smp_processor_id();
268 spin_lock(&desc->lock);
270 if (unlikely(desc->status & IRQ_INPROGRESS))
271 goto out_unlock;
272 desc->status &= ~(IRQ_REPLAY | IRQ_WAITING);
273 kstat_cpu(cpu).irqs[irq]++;
275 action = desc->action;
276 if (unlikely(!action || (desc->status & IRQ_DISABLED)))
277 goto out_unlock;
279 desc->status |= IRQ_INPROGRESS;
280 spin_unlock(&desc->lock);
282 action_ret = handle_IRQ_event(irq, regs, action);
283 if (!noirqdebug)
284 note_interrupt(irq, desc, action_ret, regs);
286 spin_lock(&desc->lock);
287 desc->status &= ~IRQ_INPROGRESS;
288 out_unlock:
289 spin_unlock(&desc->lock);
293 * handle_level_irq - Level type irq handler
294 * @irq: the interrupt number
295 * @desc: the interrupt description structure for this irq
296 * @regs: pointer to a register structure
298 * Level type interrupts are active as long as the hardware line has
299 * the active level. This may require to mask the interrupt and unmask
300 * it after the associated handler has acknowledged the device, so the
301 * interrupt line is back to inactive.
303 void fastcall
304 handle_level_irq(unsigned int irq, struct irq_desc *desc, struct pt_regs *regs)
306 unsigned int cpu = smp_processor_id();
307 struct irqaction *action;
308 irqreturn_t action_ret;
310 spin_lock(&desc->lock);
311 mask_ack_irq(desc, irq);
313 if (unlikely(desc->status & IRQ_INPROGRESS))
314 goto out_unlock;
315 desc->status &= ~(IRQ_REPLAY | IRQ_WAITING);
316 kstat_cpu(cpu).irqs[irq]++;
319 * If its disabled or no action available
320 * keep it masked and get out of here
322 action = desc->action;
323 if (unlikely(!action || (desc->status & IRQ_DISABLED))) {
324 desc->status |= IRQ_PENDING;
325 goto out_unlock;
328 desc->status |= IRQ_INPROGRESS;
329 desc->status &= ~IRQ_PENDING;
330 spin_unlock(&desc->lock);
332 action_ret = handle_IRQ_event(irq, regs, action);
333 if (!noirqdebug)
334 note_interrupt(irq, desc, action_ret, regs);
336 spin_lock(&desc->lock);
337 desc->status &= ~IRQ_INPROGRESS;
338 if (!(desc->status & IRQ_DISABLED) && desc->chip->unmask)
339 desc->chip->unmask(irq);
340 out_unlock:
341 spin_unlock(&desc->lock);
345 * handle_fasteoi_irq - irq handler for transparent controllers
346 * @irq: the interrupt number
347 * @desc: the interrupt description structure for this irq
348 * @regs: pointer to a register structure
350 * Only a single callback will be issued to the chip: an ->eoi()
351 * call when the interrupt has been serviced. This enables support
352 * for modern forms of interrupt handlers, which handle the flow
353 * details in hardware, transparently.
355 void fastcall
356 handle_fasteoi_irq(unsigned int irq, struct irq_desc *desc,
357 struct pt_regs *regs)
359 unsigned int cpu = smp_processor_id();
360 struct irqaction *action;
361 irqreturn_t action_ret;
363 spin_lock(&desc->lock);
365 if (unlikely(desc->status & IRQ_INPROGRESS))
366 goto out;
368 desc->status &= ~(IRQ_REPLAY | IRQ_WAITING);
369 kstat_cpu(cpu).irqs[irq]++;
372 * If its disabled or no action available
373 * keep it masked and get out of here
375 action = desc->action;
376 if (unlikely(!action || (desc->status & IRQ_DISABLED))) {
377 desc->status |= IRQ_PENDING;
378 goto out;
381 desc->status |= IRQ_INPROGRESS;
382 desc->status &= ~IRQ_PENDING;
383 spin_unlock(&desc->lock);
385 action_ret = handle_IRQ_event(irq, regs, action);
386 if (!noirqdebug)
387 note_interrupt(irq, desc, action_ret, regs);
389 spin_lock(&desc->lock);
390 desc->status &= ~IRQ_INPROGRESS;
391 out:
392 desc->chip->eoi(irq);
394 spin_unlock(&desc->lock);
398 * handle_edge_irq - edge type IRQ handler
399 * @irq: the interrupt number
400 * @desc: the interrupt description structure for this irq
401 * @regs: pointer to a register structure
403 * Interrupt occures on the falling and/or rising edge of a hardware
404 * signal. The occurence is latched into the irq controller hardware
405 * and must be acked in order to be reenabled. After the ack another
406 * interrupt can happen on the same source even before the first one
407 * is handled by the assosiacted event handler. If this happens it
408 * might be necessary to disable (mask) the interrupt depending on the
409 * controller hardware. This requires to reenable the interrupt inside
410 * of the loop which handles the interrupts which have arrived while
411 * the handler was running. If all pending interrupts are handled, the
412 * loop is left.
414 void fastcall
415 handle_edge_irq(unsigned int irq, struct irq_desc *desc, struct pt_regs *regs)
417 const unsigned int cpu = smp_processor_id();
419 spin_lock(&desc->lock);
421 desc->status &= ~(IRQ_REPLAY | IRQ_WAITING);
424 * If we're currently running this IRQ, or its disabled,
425 * we shouldn't process the IRQ. Mark it pending, handle
426 * the necessary masking and go out
428 if (unlikely((desc->status & (IRQ_INPROGRESS | IRQ_DISABLED)) ||
429 !desc->action)) {
430 desc->status |= (IRQ_PENDING | IRQ_MASKED);
431 mask_ack_irq(desc, irq);
432 goto out_unlock;
435 kstat_cpu(cpu).irqs[irq]++;
437 /* Start handling the irq */
438 desc->chip->ack(irq);
440 /* Mark the IRQ currently in progress.*/
441 desc->status |= IRQ_INPROGRESS;
443 do {
444 struct irqaction *action = desc->action;
445 irqreturn_t action_ret;
447 if (unlikely(!action)) {
448 desc->chip->mask(irq);
449 goto out_unlock;
453 * When another irq arrived while we were handling
454 * one, we could have masked the irq.
455 * Renable it, if it was not disabled in meantime.
457 if (unlikely((desc->status &
458 (IRQ_PENDING | IRQ_MASKED | IRQ_DISABLED)) ==
459 (IRQ_PENDING | IRQ_MASKED))) {
460 desc->chip->unmask(irq);
461 desc->status &= ~IRQ_MASKED;
464 desc->status &= ~IRQ_PENDING;
465 spin_unlock(&desc->lock);
466 action_ret = handle_IRQ_event(irq, regs, action);
467 if (!noirqdebug)
468 note_interrupt(irq, desc, action_ret, regs);
469 spin_lock(&desc->lock);
471 } while ((desc->status & (IRQ_PENDING | IRQ_DISABLED)) == IRQ_PENDING);
473 desc->status &= ~IRQ_INPROGRESS;
474 out_unlock:
475 spin_unlock(&desc->lock);
478 #ifdef CONFIG_SMP
480 * handle_percpu_IRQ - Per CPU local irq handler
481 * @irq: the interrupt number
482 * @desc: the interrupt description structure for this irq
483 * @regs: pointer to a register structure
485 * Per CPU interrupts on SMP machines without locking requirements
487 void fastcall
488 handle_percpu_irq(unsigned int irq, struct irq_desc *desc, struct pt_regs *regs)
490 irqreturn_t action_ret;
492 kstat_this_cpu.irqs[irq]++;
494 if (desc->chip->ack)
495 desc->chip->ack(irq);
497 action_ret = handle_IRQ_event(irq, regs, desc->action);
498 if (!noirqdebug)
499 note_interrupt(irq, desc, action_ret, regs);
501 if (desc->chip->eoi)
502 desc->chip->eoi(irq);
505 #endif /* CONFIG_SMP */
507 void
508 __set_irq_handler(unsigned int irq,
509 void fastcall (*handle)(unsigned int, irq_desc_t *,
510 struct pt_regs *),
511 int is_chained)
513 struct irq_desc *desc;
514 unsigned long flags;
516 if (irq >= NR_IRQS) {
517 printk(KERN_ERR
518 "Trying to install type control for IRQ%d\n", irq);
519 return;
522 desc = irq_desc + irq;
524 if (!handle)
525 handle = handle_bad_irq;
527 if (desc->chip == &no_irq_chip) {
528 printk(KERN_WARNING "Trying to install %sinterrupt handler "
529 "for IRQ%d\n", is_chained ? "chained " : " ", irq);
531 * Some ARM implementations install a handler for really dumb
532 * interrupt hardware without setting an irq_chip. This worked
533 * with the ARM no_irq_chip but the check in setup_irq would
534 * prevent us to setup the interrupt at all. Switch it to
535 * dummy_irq_chip for easy transition.
537 desc->chip = &dummy_irq_chip;
540 spin_lock_irqsave(&desc->lock, flags);
542 /* Uninstall? */
543 if (handle == handle_bad_irq) {
544 if (desc->chip != &no_irq_chip) {
545 desc->chip->mask(irq);
546 desc->chip->ack(irq);
548 desc->status |= IRQ_DISABLED;
549 desc->depth = 1;
551 desc->handle_irq = handle;
553 if (handle != handle_bad_irq && is_chained) {
554 desc->status &= ~IRQ_DISABLED;
555 desc->status |= IRQ_NOREQUEST | IRQ_NOPROBE;
556 desc->depth = 0;
557 desc->chip->unmask(irq);
559 spin_unlock_irqrestore(&desc->lock, flags);
562 void
563 set_irq_chip_and_handler(unsigned int irq, struct irq_chip *chip,
564 void fastcall (*handle)(unsigned int,
565 struct irq_desc *,
566 struct pt_regs *))
568 set_irq_chip(irq, chip);
569 __set_irq_handler(irq, handle, 0);
573 * Get a descriptive string for the highlevel handler, for
574 * /proc/interrupts output:
576 const char *
577 handle_irq_name(void fastcall (*handle)(unsigned int, struct irq_desc *,
578 struct pt_regs *))
580 if (handle == handle_level_irq)
581 return "level ";
582 if (handle == handle_fasteoi_irq)
583 return "fasteoi";
584 if (handle == handle_edge_irq)
585 return "edge ";
586 if (handle == handle_simple_irq)
587 return "simple ";
588 #ifdef CONFIG_SMP
589 if (handle == handle_percpu_irq)
590 return "percpu ";
591 #endif
592 if (handle == handle_bad_irq)
593 return "bad ";
595 return NULL;