V4L/DVB (10680): gspca - zc3xx: Bad probe of the ov7xxx sensors.
[linux-2.6.git] / kernel / irq / numa_migrate.c
blob243d6121e50e08c1b54972fd3bb61c827a8c3dfe
1 /*
2 * NUMA irq-desc migration code
4 * Migrate IRQ data structures (irq_desc, chip_data, etc.) over to
5 * the new "home node" of the IRQ.
6 */
8 #include <linux/irq.h>
9 #include <linux/module.h>
10 #include <linux/random.h>
11 #include <linux/interrupt.h>
12 #include <linux/kernel_stat.h>
14 #include "internals.h"
16 static void init_copy_kstat_irqs(struct irq_desc *old_desc,
17 struct irq_desc *desc,
18 int cpu, int nr)
20 init_kstat_irqs(desc, cpu, nr);
22 if (desc->kstat_irqs != old_desc->kstat_irqs)
23 memcpy(desc->kstat_irqs, old_desc->kstat_irqs,
24 nr * sizeof(*desc->kstat_irqs));
27 static void free_kstat_irqs(struct irq_desc *old_desc, struct irq_desc *desc)
29 if (old_desc->kstat_irqs == desc->kstat_irqs)
30 return;
32 kfree(old_desc->kstat_irqs);
33 old_desc->kstat_irqs = NULL;
36 static bool init_copy_one_irq_desc(int irq, struct irq_desc *old_desc,
37 struct irq_desc *desc, int cpu)
39 memcpy(desc, old_desc, sizeof(struct irq_desc));
40 if (!init_alloc_desc_masks(desc, cpu, false)) {
41 printk(KERN_ERR "irq %d: can not get new irq_desc cpumask "
42 "for migration.\n", irq);
43 return false;
45 spin_lock_init(&desc->lock);
46 desc->cpu = cpu;
47 lockdep_set_class(&desc->lock, &irq_desc_lock_class);
48 init_copy_kstat_irqs(old_desc, desc, cpu, nr_cpu_ids);
49 init_copy_desc_masks(old_desc, desc);
50 arch_init_copy_chip_data(old_desc, desc, cpu);
51 return true;
54 static void free_one_irq_desc(struct irq_desc *old_desc, struct irq_desc *desc)
56 free_kstat_irqs(old_desc, desc);
57 arch_free_chip_data(old_desc, desc);
60 static struct irq_desc *__real_move_irq_desc(struct irq_desc *old_desc,
61 int cpu)
63 struct irq_desc *desc;
64 unsigned int irq;
65 unsigned long flags;
66 int node;
68 irq = old_desc->irq;
70 spin_lock_irqsave(&sparse_irq_lock, flags);
72 /* We have to check it to avoid races with another CPU */
73 desc = irq_desc_ptrs[irq];
75 if (desc && old_desc != desc)
76 goto out_unlock;
78 node = cpu_to_node(cpu);
79 desc = kzalloc_node(sizeof(*desc), GFP_ATOMIC, node);
80 if (!desc) {
81 printk(KERN_ERR "irq %d: can not get new irq_desc "
82 "for migration.\n", irq);
83 /* still use old one */
84 desc = old_desc;
85 goto out_unlock;
87 if (!init_copy_one_irq_desc(irq, old_desc, desc, cpu)) {
88 /* still use old one */
89 kfree(desc);
90 desc = old_desc;
91 goto out_unlock;
94 irq_desc_ptrs[irq] = desc;
95 spin_unlock_irqrestore(&sparse_irq_lock, flags);
97 /* free the old one */
98 free_one_irq_desc(old_desc, desc);
99 spin_unlock(&old_desc->lock);
100 kfree(old_desc);
101 spin_lock(&desc->lock);
103 return desc;
105 out_unlock:
106 spin_unlock_irqrestore(&sparse_irq_lock, flags);
108 return desc;
111 struct irq_desc *move_irq_desc(struct irq_desc *desc, int cpu)
113 int old_cpu;
114 int node, old_node;
116 /* those all static, do move them */
117 if (desc->irq < NR_IRQS_LEGACY)
118 return desc;
120 old_cpu = desc->cpu;
121 if (old_cpu != cpu) {
122 node = cpu_to_node(cpu);
123 old_node = cpu_to_node(old_cpu);
124 if (old_node != node)
125 desc = __real_move_irq_desc(desc, cpu);
126 else
127 desc->cpu = cpu;
130 return desc;