[PATCH] r/o bind mounts: unlink: monitor i_nlink
[linux-2.6/kvm.git] / kernel / irq / chip.c
blob736cb0bd498f8ff5c7a50d8b60e3130da43d9d7f
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 * set_irq_chip - set the irq chip for an irq
22 * @irq: irq number
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;
28 unsigned long flags;
30 if (irq >= NR_IRQS) {
31 printk(KERN_ERR "Trying to install chip for IRQ%d\n", irq);
32 WARN_ON(1);
33 return -EINVAL;
36 if (!chip)
37 chip = &no_irq_chip;
39 desc = irq_desc + irq;
40 spin_lock_irqsave(&desc->lock, flags);
41 irq_chip_set_defaults(chip);
42 desc->chip = chip;
43 spin_unlock_irqrestore(&desc->lock, flags);
45 return 0;
47 EXPORT_SYMBOL(set_irq_chip);
49 /**
50 * set_irq_type - set the irq type for an irq
51 * @irq: irq number
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;
57 unsigned long flags;
58 int ret = -ENXIO;
60 if (irq >= NR_IRQS) {
61 printk(KERN_ERR "Trying to set irq type for IRQ%d\n", irq);
62 return -ENODEV;
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);
71 return ret;
73 EXPORT_SYMBOL(set_irq_type);
75 /**
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;
85 unsigned long flags;
87 if (irq >= NR_IRQS) {
88 printk(KERN_ERR
89 "Trying to install controller data for IRQ%d\n", irq);
90 return -EINVAL;
93 desc = irq_desc + irq;
94 spin_lock_irqsave(&desc->lock, flags);
95 desc->handler_data = data;
96 spin_unlock_irqrestore(&desc->lock, flags);
97 return 0;
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;
111 unsigned long flags;
113 if (irq >= NR_IRQS || !desc->chip) {
114 printk(KERN_ERR "BUG: bad set_irq_chip_data(IRQ#%d)\n", irq);
115 return -EINVAL;
118 spin_lock_irqsave(&desc->lock, flags);
119 desc->chip_data = data;
120 spin_unlock_irqrestore(&desc->lock, flags);
122 return 0;
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);
155 return 0;
159 * Fixup enable/disable function pointers
161 void irq_chip_set_defaults(struct irq_chip *chip)
163 if (!chip->enable)
164 chip->enable = default_enable;
165 if (!chip->disable)
166 chip->disable = default_disable;
167 if (!chip->startup)
168 chip->startup = default_startup;
169 if (!chip->shutdown)
170 chip->shutdown = chip->disable;
171 if (!chip->name)
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);
179 else {
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
193 * is necessary.
195 * Note: The caller is expected to handle the ack, clear, mask and
196 * unmask issues if necessary.
198 void fastcall
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))
208 goto out_unlock;
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)))
214 goto out_unlock;
216 desc->status |= IRQ_INPROGRESS;
217 spin_unlock(&desc->lock);
219 action_ret = handle_IRQ_event(irq, regs, action);
220 if (!noirqdebug)
221 note_interrupt(irq, desc, action_ret, regs);
223 spin_lock(&desc->lock);
224 desc->status &= ~IRQ_INPROGRESS;
225 out_unlock:
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.
240 void fastcall
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))
251 goto out_unlock;
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;
262 goto out_unlock;
265 desc->status |= IRQ_INPROGRESS;
266 desc->status &= ~IRQ_PENDING;
267 spin_unlock(&desc->lock);
269 action_ret = handle_IRQ_event(irq, regs, action);
270 if (!noirqdebug)
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);
277 out_unlock:
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.
292 void fastcall
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))
303 goto out;
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;
315 goto out;
318 desc->status |= IRQ_INPROGRESS;
319 desc->status &= ~IRQ_PENDING;
320 spin_unlock(&desc->lock);
322 action_ret = handle_IRQ_event(irq, regs, action);
323 if (!noirqdebug)
324 note_interrupt(irq, desc, action_ret, regs);
326 spin_lock(&desc->lock);
327 desc->status &= ~IRQ_INPROGRESS;
328 out:
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
349 * loop is left.
351 void fastcall
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)) ||
366 !desc->action)) {
367 desc->status |= (IRQ_PENDING | IRQ_MASKED);
368 mask_ack_irq(desc, irq);
369 goto out_unlock;
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;
380 do {
381 struct irqaction *action = desc->action;
382 irqreturn_t action_ret;
384 if (unlikely(!action)) {
385 desc->chip->mask(irq);
386 goto out_unlock;
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);
404 if (!noirqdebug)
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;
411 out_unlock:
412 spin_unlock(&desc->lock);
415 #ifdef CONFIG_SMP
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
424 void fastcall
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]++;
431 if (desc->chip->ack)
432 desc->chip->ack(irq);
434 action_ret = handle_IRQ_event(irq, regs, desc->action);
435 if (!noirqdebug)
436 note_interrupt(irq, desc, action_ret, regs);
438 if (desc->chip->eoi)
439 desc->chip->eoi(irq);
442 #endif /* CONFIG_SMP */
444 void
445 __set_irq_handler(unsigned int irq,
446 void fastcall (*handle)(unsigned int, irq_desc_t *,
447 struct pt_regs *),
448 int is_chained)
450 struct irq_desc *desc;
451 unsigned long flags;
453 if (irq >= NR_IRQS) {
454 printk(KERN_ERR
455 "Trying to install type control for IRQ%d\n", irq);
456 return;
459 desc = irq_desc + irq;
461 if (!handle)
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);
479 /* Uninstall? */
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;
486 desc->depth = 1;
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;
493 desc->depth = 0;
494 desc->chip->unmask(irq);
496 spin_unlock_irqrestore(&desc->lock, flags);
499 void
500 set_irq_chip_and_handler(unsigned int irq, struct irq_chip *chip,
501 void fastcall (*handle)(unsigned int,
502 struct irq_desc *,
503 struct pt_regs *))
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:
513 const char *
514 handle_irq_name(void fastcall (*handle)(unsigned int, struct irq_desc *,
515 struct pt_regs *))
517 if (handle == handle_level_irq)
518 return "level ";
519 if (handle == handle_fasteoi_irq)
520 return "fasteoi";
521 if (handle == handle_edge_irq)
522 return "edge ";
523 if (handle == handle_simple_irq)
524 return "simple ";
525 #ifdef CONFIG_SMP
526 if (handle == handle_percpu_irq)
527 return "percpu ";
528 #endif
529 if (handle == handle_bad_irq)
530 return "bad ";
532 return NULL;