diff options
Diffstat (limited to 'kernel/irq/handle.c')
| -rw-r--r-- | kernel/irq/handle.c | 80 |
1 files changed, 39 insertions, 41 deletions
diff --git a/kernel/irq/handle.c b/kernel/irq/handle.c index 17c71bb565c6..76d5a671bfe1 100644 --- a/kernel/irq/handle.c +++ b/kernel/irq/handle.c | |||
| @@ -19,7 +19,7 @@ | |||
| 19 | #include <linux/kernel_stat.h> | 19 | #include <linux/kernel_stat.h> |
| 20 | #include <linux/rculist.h> | 20 | #include <linux/rculist.h> |
| 21 | #include <linux/hash.h> | 21 | #include <linux/hash.h> |
| 22 | #include <linux/bootmem.h> | 22 | #include <linux/radix-tree.h> |
| 23 | #include <trace/events/irq.h> | 23 | #include <trace/events/irq.h> |
| 24 | 24 | ||
| 25 | #include "internals.h" | 25 | #include "internals.h" |
| @@ -80,19 +80,15 @@ static struct irq_desc irq_desc_init = { | |||
| 80 | .chip = &no_irq_chip, | 80 | .chip = &no_irq_chip, |
| 81 | .handle_irq = handle_bad_irq, | 81 | .handle_irq = handle_bad_irq, |
| 82 | .depth = 1, | 82 | .depth = 1, |
| 83 | .lock = __SPIN_LOCK_UNLOCKED(irq_desc_init.lock), | 83 | .lock = __RAW_SPIN_LOCK_UNLOCKED(irq_desc_init.lock), |
| 84 | }; | 84 | }; |
| 85 | 85 | ||
| 86 | void __ref init_kstat_irqs(struct irq_desc *desc, int node, int nr) | 86 | void __ref init_kstat_irqs(struct irq_desc *desc, int node, int nr) |
| 87 | { | 87 | { |
| 88 | void *ptr; | 88 | void *ptr; |
| 89 | 89 | ||
| 90 | if (slab_is_available()) | 90 | ptr = kzalloc_node(nr * sizeof(*desc->kstat_irqs), |
| 91 | ptr = kzalloc_node(nr * sizeof(*desc->kstat_irqs), | 91 | GFP_ATOMIC, node); |
| 92 | GFP_ATOMIC, node); | ||
| 93 | else | ||
| 94 | ptr = alloc_bootmem_node(NODE_DATA(node), | ||
| 95 | nr * sizeof(*desc->kstat_irqs)); | ||
| 96 | 92 | ||
| 97 | /* | 93 | /* |
| 98 | * don't overwite if can not get new one | 94 | * don't overwite if can not get new one |
| @@ -108,7 +104,7 @@ static void init_one_irq_desc(int irq, struct irq_desc *desc, int node) | |||
| 108 | { | 104 | { |
| 109 | memcpy(desc, &irq_desc_init, sizeof(struct irq_desc)); | 105 | memcpy(desc, &irq_desc_init, sizeof(struct irq_desc)); |
| 110 | 106 | ||
| 111 | spin_lock_init(&desc->lock); | 107 | raw_spin_lock_init(&desc->lock); |
| 112 | desc->irq = irq; | 108 | desc->irq = irq; |
| 113 | #ifdef CONFIG_SMP | 109 | #ifdef CONFIG_SMP |
| 114 | desc->node = node; | 110 | desc->node = node; |
| @@ -130,9 +126,28 @@ static void init_one_irq_desc(int irq, struct irq_desc *desc, int node) | |||
| 130 | /* | 126 | /* |
| 131 | * Protect the sparse_irqs: | 127 | * Protect the sparse_irqs: |
| 132 | */ | 128 | */ |
| 133 | DEFINE_SPINLOCK(sparse_irq_lock); | 129 | DEFINE_RAW_SPINLOCK(sparse_irq_lock); |
| 134 | 130 | ||
| 135 | struct irq_desc **irq_desc_ptrs __read_mostly; | 131 | static RADIX_TREE(irq_desc_tree, GFP_ATOMIC); |
| 132 | |||
| 133 | static void set_irq_desc(unsigned int irq, struct irq_desc *desc) | ||
| 134 | { | ||
| 135 | radix_tree_insert(&irq_desc_tree, irq, desc); | ||
| 136 | } | ||
| 137 | |||
| 138 | struct irq_desc *irq_to_desc(unsigned int irq) | ||
| 139 | { | ||
| 140 | return radix_tree_lookup(&irq_desc_tree, irq); | ||
| 141 | } | ||
| 142 | |||
| 143 | void replace_irq_desc(unsigned int irq, struct irq_desc *desc) | ||
| 144 | { | ||
| 145 | void **ptr; | ||
| 146 | |||
| 147 | ptr = radix_tree_lookup_slot(&irq_desc_tree, irq); | ||
| 148 | if (ptr) | ||
| 149 | radix_tree_replace_slot(ptr, desc); | ||
| 150 | } | ||
| 136 | 151 | ||
| 137 | static struct irq_desc irq_desc_legacy[NR_IRQS_LEGACY] __cacheline_aligned_in_smp = { | 152 | static struct irq_desc irq_desc_legacy[NR_IRQS_LEGACY] __cacheline_aligned_in_smp = { |
| 138 | [0 ... NR_IRQS_LEGACY-1] = { | 153 | [0 ... NR_IRQS_LEGACY-1] = { |
| @@ -141,7 +156,7 @@ static struct irq_desc irq_desc_legacy[NR_IRQS_LEGACY] __cacheline_aligned_in_sm | |||
| 141 | .chip = &no_irq_chip, | 156 | .chip = &no_irq_chip, |
| 142 | .handle_irq = handle_bad_irq, | 157 | .handle_irq = handle_bad_irq, |
| 143 | .depth = 1, | 158 | .depth = 1, |
| 144 | .lock = __SPIN_LOCK_UNLOCKED(irq_desc_init.lock), | 159 | .lock = __RAW_SPIN_LOCK_UNLOCKED(irq_desc_init.lock), |
| 145 | } | 160 | } |
| 146 | }; | 161 | }; |
| 147 | 162 | ||
| @@ -164,9 +179,6 @@ int __init early_irq_init(void) | |||
| 164 | legacy_count = ARRAY_SIZE(irq_desc_legacy); | 179 | legacy_count = ARRAY_SIZE(irq_desc_legacy); |
| 165 | node = first_online_node; | 180 | node = first_online_node; |
| 166 | 181 | ||
| 167 | /* allocate irq_desc_ptrs array based on nr_irqs */ | ||
| 168 | irq_desc_ptrs = kcalloc(nr_irqs, sizeof(void *), GFP_NOWAIT); | ||
| 169 | |||
| 170 | /* allocate based on nr_cpu_ids */ | 182 | /* allocate based on nr_cpu_ids */ |
| 171 | kstat_irqs_legacy = kzalloc_node(NR_IRQS_LEGACY * nr_cpu_ids * | 183 | kstat_irqs_legacy = kzalloc_node(NR_IRQS_LEGACY * nr_cpu_ids * |
| 172 | sizeof(int), GFP_NOWAIT, node); | 184 | sizeof(int), GFP_NOWAIT, node); |
| @@ -180,23 +192,12 @@ int __init early_irq_init(void) | |||
| 180 | lockdep_set_class(&desc[i].lock, &irq_desc_lock_class); | 192 | lockdep_set_class(&desc[i].lock, &irq_desc_lock_class); |
| 181 | alloc_desc_masks(&desc[i], node, true); | 193 | alloc_desc_masks(&desc[i], node, true); |
| 182 | init_desc_masks(&desc[i]); | 194 | init_desc_masks(&desc[i]); |
| 183 | irq_desc_ptrs[i] = desc + i; | 195 | set_irq_desc(i, &desc[i]); |
| 184 | } | 196 | } |
| 185 | 197 | ||
| 186 | for (i = legacy_count; i < nr_irqs; i++) | ||
| 187 | irq_desc_ptrs[i] = NULL; | ||
| 188 | |||
| 189 | return arch_early_irq_init(); | 198 | return arch_early_irq_init(); |
| 190 | } | 199 | } |
| 191 | 200 | ||
| 192 | struct irq_desc *irq_to_desc(unsigned int irq) | ||
| 193 | { | ||
| 194 | if (irq_desc_ptrs && irq < nr_irqs) | ||
| 195 | return irq_desc_ptrs[irq]; | ||
| 196 | |||
| 197 | return NULL; | ||
| 198 | } | ||
| 199 | |||
| 200 | struct irq_desc * __ref irq_to_desc_alloc_node(unsigned int irq, int node) | 201 | struct irq_desc * __ref irq_to_desc_alloc_node(unsigned int irq, int node) |
| 201 | { | 202 | { |
| 202 | struct irq_desc *desc; | 203 | struct irq_desc *desc; |
| @@ -208,21 +209,18 @@ struct irq_desc * __ref irq_to_desc_alloc_node(unsigned int irq, int node) | |||
| 208 | return NULL; | 209 | return NULL; |
| 209 | } | 210 | } |
| 210 | 211 | ||
| 211 | desc = irq_desc_ptrs[irq]; | 212 | desc = irq_to_desc(irq); |
| 212 | if (desc) | 213 | if (desc) |
| 213 | return desc; | 214 | return desc; |
| 214 | 215 | ||
| 215 | spin_lock_irqsave(&sparse_irq_lock, flags); | 216 | raw_spin_lock_irqsave(&sparse_irq_lock, flags); |
| 216 | 217 | ||
| 217 | /* We have to check it to avoid races with another CPU */ | 218 | /* We have to check it to avoid races with another CPU */ |
| 218 | desc = irq_desc_ptrs[irq]; | 219 | desc = irq_to_desc(irq); |
| 219 | if (desc) | 220 | if (desc) |
| 220 | goto out_unlock; | 221 | goto out_unlock; |
| 221 | 222 | ||
| 222 | if (slab_is_available()) | 223 | desc = kzalloc_node(sizeof(*desc), GFP_ATOMIC, node); |
| 223 | desc = kzalloc_node(sizeof(*desc), GFP_ATOMIC, node); | ||
| 224 | else | ||
| 225 | desc = alloc_bootmem_node(NODE_DATA(node), sizeof(*desc)); | ||
| 226 | 224 | ||
| 227 | printk(KERN_DEBUG " alloc irq_desc for %d on node %d\n", irq, node); | 225 | printk(KERN_DEBUG " alloc irq_desc for %d on node %d\n", irq, node); |
| 228 | if (!desc) { | 226 | if (!desc) { |
| @@ -231,10 +229,10 @@ struct irq_desc * __ref irq_to_desc_alloc_node(unsigned int irq, int node) | |||
| 231 | } | 229 | } |
| 232 | init_one_irq_desc(irq, desc, node); | 230 | init_one_irq_desc(irq, desc, node); |
| 233 | 231 | ||
| 234 | irq_desc_ptrs[irq] = desc; | 232 | set_irq_desc(irq, desc); |
| 235 | 233 | ||
| 236 | out_unlock: | 234 | out_unlock: |
| 237 | spin_unlock_irqrestore(&sparse_irq_lock, flags); | 235 | raw_spin_unlock_irqrestore(&sparse_irq_lock, flags); |
| 238 | 236 | ||
| 239 | return desc; | 237 | return desc; |
| 240 | } | 238 | } |
| @@ -247,7 +245,7 @@ struct irq_desc irq_desc[NR_IRQS] __cacheline_aligned_in_smp = { | |||
| 247 | .chip = &no_irq_chip, | 245 | .chip = &no_irq_chip, |
| 248 | .handle_irq = handle_bad_irq, | 246 | .handle_irq = handle_bad_irq, |
| 249 | .depth = 1, | 247 | .depth = 1, |
| 250 | .lock = __SPIN_LOCK_UNLOCKED(irq_desc->lock), | 248 | .lock = __RAW_SPIN_LOCK_UNLOCKED(irq_desc->lock), |
| 251 | } | 249 | } |
| 252 | }; | 250 | }; |
| 253 | 251 | ||
| @@ -473,7 +471,7 @@ unsigned int __do_IRQ(unsigned int irq) | |||
| 473 | return 1; | 471 | return 1; |
| 474 | } | 472 | } |
| 475 | 473 | ||
| 476 | spin_lock(&desc->lock); | 474 | raw_spin_lock(&desc->lock); |
| 477 | if (desc->chip->ack) | 475 | if (desc->chip->ack) |
| 478 | desc->chip->ack(irq); | 476 | desc->chip->ack(irq); |
| 479 | /* | 477 | /* |
| @@ -517,13 +515,13 @@ unsigned int __do_IRQ(unsigned int irq) | |||
| 517 | for (;;) { | 515 | for (;;) { |
| 518 | irqreturn_t action_ret; | 516 | irqreturn_t action_ret; |
| 519 | 517 | ||
| 520 | spin_unlock(&desc->lock); | 518 | raw_spin_unlock(&desc->lock); |
| 521 | 519 | ||
| 522 | action_ret = handle_IRQ_event(irq, action); | 520 | action_ret = handle_IRQ_event(irq, action); |
| 523 | if (!noirqdebug) | 521 | if (!noirqdebug) |
| 524 | note_interrupt(irq, desc, action_ret); | 522 | note_interrupt(irq, desc, action_ret); |
| 525 | 523 | ||
| 526 | spin_lock(&desc->lock); | 524 | raw_spin_lock(&desc->lock); |
| 527 | if (likely(!(desc->status & IRQ_PENDING))) | 525 | if (likely(!(desc->status & IRQ_PENDING))) |
| 528 | break; | 526 | break; |
| 529 | desc->status &= ~IRQ_PENDING; | 527 | desc->status &= ~IRQ_PENDING; |
| @@ -536,7 +534,7 @@ out: | |||
| 536 | * disabled while the handler was running. | 534 | * disabled while the handler was running. |
| 537 | */ | 535 | */ |
| 538 | desc->chip->end(irq); | 536 | desc->chip->end(irq); |
| 539 | spin_unlock(&desc->lock); | 537 | raw_spin_unlock(&desc->lock); |
| 540 | 538 | ||
| 541 | return 1; | 539 | return 1; |
| 542 | } | 540 | } |
