Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/kernel/irq/handle.c |
| 3 | * |
Ingo Molnar | a34db9b | 2006-06-29 02:24:50 -0700 | [diff] [blame^] | 4 | * Copyright (C) 1992, 1998-2006 Linus Torvalds, Ingo Molnar |
| 5 | * Copyright (C) 2005-2006, Thomas Gleixner, Russell King |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * |
| 7 | * This file contains the core interrupt handling code. |
Ingo Molnar | a34db9b | 2006-06-29 02:24:50 -0700 | [diff] [blame^] | 8 | * |
| 9 | * Detailed information is available in Documentation/DocBook/genericirq |
| 10 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | */ |
| 12 | |
| 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> |
| 18 | |
| 19 | #include "internals.h" |
| 20 | |
| 21 | /* |
| 22 | * Linux has a controller-independent interrupt architecture. |
| 23 | * Every controller has a 'controller-template', that is used |
| 24 | * by the main code to do the right thing. Each driver-visible |
Ingo Molnar | 06fcb0c | 2006-06-29 02:24:40 -0700 | [diff] [blame] | 25 | * interrupt source is transparently wired to the appropriate |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | * controller. Thus drivers need not be aware of the |
| 27 | * interrupt-controller. |
| 28 | * |
| 29 | * The code is designed to be easily extended with new/different |
| 30 | * interrupt controllers, without having to do assembly magic or |
| 31 | * having to touch the generic code. |
| 32 | * |
| 33 | * Controller mappings for all interrupt sources: |
| 34 | */ |
Ingo Molnar | 34ffdb7 | 2006-06-29 02:24:40 -0700 | [diff] [blame] | 35 | struct irq_desc irq_desc[NR_IRQS] __cacheline_aligned = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | [0 ... NR_IRQS-1] = { |
Zhang, Yanmin | 4f167fb | 2005-05-16 21:53:43 -0700 | [diff] [blame] | 37 | .status = IRQ_DISABLED, |
Ingo Molnar | d1bef4e | 2006-06-29 02:24:36 -0700 | [diff] [blame] | 38 | .chip = &no_irq_type, |
Thomas Gleixner | 94d39e1 | 2006-06-29 02:24:50 -0700 | [diff] [blame] | 39 | .depth = 1, |
Ingo Molnar | a53da52 | 2006-06-29 02:24:38 -0700 | [diff] [blame] | 40 | .lock = SPIN_LOCK_UNLOCKED, |
| 41 | #ifdef CONFIG_SMP |
| 42 | .affinity = CPU_MASK_ALL |
| 43 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | } |
| 45 | }; |
| 46 | |
| 47 | /* |
Ingo Molnar | 77a5afe | 2006-06-29 02:24:46 -0700 | [diff] [blame] | 48 | * What should we do if we get a hw irq event on an illegal vector? |
| 49 | * Each architecture has to answer this themself. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | */ |
Ingo Molnar | 77a5afe | 2006-06-29 02:24:46 -0700 | [diff] [blame] | 51 | static void ack_bad(unsigned int irq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | ack_bad_irq(irq); |
| 54 | } |
| 55 | |
Ingo Molnar | 77a5afe | 2006-06-29 02:24:46 -0700 | [diff] [blame] | 56 | /* |
| 57 | * NOP functions |
| 58 | */ |
| 59 | static void noop(unsigned int irq) |
| 60 | { |
| 61 | } |
| 62 | |
| 63 | static unsigned int noop_ret(unsigned int irq) |
| 64 | { |
| 65 | return 0; |
| 66 | } |
| 67 | |
| 68 | /* |
| 69 | * Generic no controller implementation |
| 70 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | struct hw_interrupt_type no_irq_type = { |
Ingo Molnar | 77a5afe | 2006-06-29 02:24:46 -0700 | [diff] [blame] | 72 | .typename = "none", |
| 73 | .startup = noop_ret, |
| 74 | .shutdown = noop, |
| 75 | .enable = noop, |
| 76 | .disable = noop, |
| 77 | .ack = ack_bad, |
| 78 | .end = noop, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | }; |
| 80 | |
| 81 | /* |
| 82 | * Special, empty irq handler: |
| 83 | */ |
| 84 | irqreturn_t no_action(int cpl, void *dev_id, struct pt_regs *regs) |
| 85 | { |
| 86 | return IRQ_NONE; |
| 87 | } |
| 88 | |
Ingo Molnar | 8d28bc7 | 2006-06-29 02:24:46 -0700 | [diff] [blame] | 89 | /** |
| 90 | * handle_IRQ_event - irq action chain handler |
| 91 | * @irq: the interrupt number |
| 92 | * @regs: pointer to a register structure |
| 93 | * @action: the interrupt action chain for this irq |
| 94 | * |
| 95 | * Handles the action chain of an irq event |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | */ |
Ingo Molnar | 2e60bbb | 2006-06-29 02:24:39 -0700 | [diff] [blame] | 97 | irqreturn_t handle_IRQ_event(unsigned int irq, struct pt_regs *regs, |
| 98 | struct irqaction *action) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | { |
Jan Beulich | 908dcec | 2006-06-23 02:06:00 -0700 | [diff] [blame] | 100 | irqreturn_t ret, retval = IRQ_NONE; |
| 101 | unsigned int status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | |
| 103 | if (!(action->flags & SA_INTERRUPT)) |
| 104 | local_irq_enable(); |
| 105 | |
| 106 | do { |
| 107 | ret = action->handler(irq, action->dev_id, regs); |
| 108 | if (ret == IRQ_HANDLED) |
| 109 | status |= action->flags; |
| 110 | retval |= ret; |
| 111 | action = action->next; |
| 112 | } while (action); |
| 113 | |
| 114 | if (status & SA_SAMPLE_RANDOM) |
| 115 | add_interrupt_randomness(irq); |
| 116 | local_irq_disable(); |
| 117 | |
| 118 | return retval; |
| 119 | } |
| 120 | |
Ingo Molnar | 8d28bc7 | 2006-06-29 02:24:46 -0700 | [diff] [blame] | 121 | /** |
| 122 | * __do_IRQ - original all in one highlevel IRQ handler |
| 123 | * @irq: the interrupt number |
| 124 | * @regs: pointer to a register structure |
| 125 | * |
| 126 | * __do_IRQ handles all normal device IRQ's (the special |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | * SMP cross-CPU interrupts have their own specific |
| 128 | * handlers). |
Ingo Molnar | 8d28bc7 | 2006-06-29 02:24:46 -0700 | [diff] [blame] | 129 | * |
| 130 | * This is the original x86 implementation which is used for every |
| 131 | * interrupt type. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | */ |
| 133 | fastcall unsigned int __do_IRQ(unsigned int irq, struct pt_regs *regs) |
| 134 | { |
Ingo Molnar | 34ffdb7 | 2006-06-29 02:24:40 -0700 | [diff] [blame] | 135 | struct irq_desc *desc = irq_desc + irq; |
Ingo Molnar | 06fcb0c | 2006-06-29 02:24:40 -0700 | [diff] [blame] | 136 | struct irqaction *action; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | unsigned int status; |
| 138 | |
| 139 | kstat_this_cpu.irqs[irq]++; |
Karsten Wiese | f26fdd5 | 2005-09-06 15:17:25 -0700 | [diff] [blame] | 140 | if (CHECK_IRQ_PER_CPU(desc->status)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | irqreturn_t action_ret; |
| 142 | |
| 143 | /* |
| 144 | * No locking required for CPU-local interrupts: |
| 145 | */ |
Ingo Molnar | d1bef4e | 2006-06-29 02:24:36 -0700 | [diff] [blame] | 146 | if (desc->chip->ack) |
| 147 | desc->chip->ack(irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | action_ret = handle_IRQ_event(irq, regs, desc->action); |
Ingo Molnar | d1bef4e | 2006-06-29 02:24:36 -0700 | [diff] [blame] | 149 | desc->chip->end(irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | return 1; |
| 151 | } |
| 152 | |
| 153 | spin_lock(&desc->lock); |
Ingo Molnar | d1bef4e | 2006-06-29 02:24:36 -0700 | [diff] [blame] | 154 | if (desc->chip->ack) |
| 155 | desc->chip->ack(irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | /* |
| 157 | * REPLAY is when Linux resends an IRQ that was dropped earlier |
| 158 | * WAITING is used by probe to mark irqs that are being tested |
| 159 | */ |
| 160 | status = desc->status & ~(IRQ_REPLAY | IRQ_WAITING); |
| 161 | status |= IRQ_PENDING; /* we _want_ to handle it */ |
| 162 | |
| 163 | /* |
| 164 | * If the IRQ is disabled for whatever reason, we cannot |
| 165 | * use the action we have. |
| 166 | */ |
| 167 | action = NULL; |
| 168 | if (likely(!(status & (IRQ_DISABLED | IRQ_INPROGRESS)))) { |
| 169 | action = desc->action; |
| 170 | status &= ~IRQ_PENDING; /* we commit to handling */ |
| 171 | status |= IRQ_INPROGRESS; /* we are handling it */ |
| 172 | } |
| 173 | desc->status = status; |
| 174 | |
| 175 | /* |
| 176 | * If there is no IRQ handler or it was disabled, exit early. |
| 177 | * Since we set PENDING, if another processor is handling |
| 178 | * a different instance of this same irq, the other processor |
| 179 | * will take care of it. |
| 180 | */ |
| 181 | if (unlikely(!action)) |
| 182 | goto out; |
| 183 | |
| 184 | /* |
| 185 | * Edge triggered interrupts need to remember |
| 186 | * pending events. |
| 187 | * This applies to any hw interrupts that allow a second |
| 188 | * instance of the same irq to arrive while we are in do_IRQ |
| 189 | * or in the handler. But the code here only handles the _second_ |
| 190 | * instance of the irq, not the third or fourth. So it is mostly |
| 191 | * useful for irq hardware that does not mask cleanly in an |
| 192 | * SMP environment. |
| 193 | */ |
| 194 | for (;;) { |
| 195 | irqreturn_t action_ret; |
| 196 | |
| 197 | spin_unlock(&desc->lock); |
| 198 | |
| 199 | action_ret = handle_IRQ_event(irq, regs, action); |
| 200 | |
| 201 | spin_lock(&desc->lock); |
| 202 | if (!noirqdebug) |
Alan Cox | 200803d | 2005-06-28 20:45:18 -0700 | [diff] [blame] | 203 | note_interrupt(irq, desc, action_ret, regs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | if (likely(!(desc->status & IRQ_PENDING))) |
| 205 | break; |
| 206 | desc->status &= ~IRQ_PENDING; |
| 207 | } |
| 208 | desc->status &= ~IRQ_INPROGRESS; |
| 209 | |
| 210 | out: |
| 211 | /* |
| 212 | * The ->end() handler has to deal with interrupts which got |
| 213 | * disabled while the handler was running. |
| 214 | */ |
Ingo Molnar | d1bef4e | 2006-06-29 02:24:36 -0700 | [diff] [blame] | 215 | desc->chip->end(irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | spin_unlock(&desc->lock); |
| 217 | |
| 218 | return 1; |
| 219 | } |
| 220 | |