x86: use specialized routine for setup per-cpu area
[deliverable/linux.git] / arch / x86 / kernel / setup.c
1 #include <linux/kernel.h>
2 #include <linux/module.h>
3 #include <linux/init.h>
4 #include <linux/bootmem.h>
5 #include <linux/percpu.h>
6 #include <asm/smp.h>
7 #include <asm/percpu.h>
8 #include <asm/sections.h>
9 #include <asm/processor.h>
10 #include <asm/setup.h>
11 #include <asm/topology.h>
12
13 #ifdef CONFIG_HAVE_SETUP_PER_CPU_AREA
14 /*
15 * Copy data used in early init routines from the initial arrays to the
16 * per cpu data areas. These arrays then become expendable and the
17 * *_early_ptr's are zeroed indicating that the static arrays are gone.
18 */
19 static void __init setup_per_cpu_maps(void)
20 {
21 int cpu;
22
23 for_each_possible_cpu(cpu) {
24 #ifdef CONFIG_SMP
25 if (per_cpu_offset(cpu)) {
26 #endif
27 per_cpu(x86_cpu_to_apicid, cpu) =
28 x86_cpu_to_apicid_init[cpu];
29 per_cpu(x86_bios_cpu_apicid, cpu) =
30 x86_bios_cpu_apicid_init[cpu];
31 #ifdef CONFIG_NUMA
32 per_cpu(x86_cpu_to_node_map, cpu) =
33 x86_cpu_to_node_map_init[cpu];
34 #endif
35 #ifdef CONFIG_SMP
36 } else
37 printk(KERN_NOTICE "per_cpu_offset zero for cpu %d\n",
38 cpu);
39 #endif
40 }
41
42 /* indicate the early static arrays will soon be gone */
43 x86_cpu_to_apicid_early_ptr = NULL;
44 x86_bios_cpu_apicid_early_ptr = NULL;
45 #ifdef CONFIG_NUMA
46 x86_cpu_to_node_map_early_ptr = NULL;
47 #endif
48 }
49
50 #ifdef CONFIG_X86_32
51 /*
52 * Great future not-so-futuristic plan: make i386 and x86_64 do it
53 * the same way
54 */
55 unsigned long __per_cpu_offset[NR_CPUS] __read_mostly;
56 EXPORT_SYMBOL(__per_cpu_offset);
57 #endif
58
59 /*
60 * Great future plan:
61 * Declare PDA itself and support (irqstack,tss,pgd) as per cpu data.
62 * Always point %gs to its beginning
63 */
64 void __init setup_per_cpu_areas(void)
65 {
66 int i;
67 unsigned long size;
68
69 #ifdef CONFIG_HOTPLUG_CPU
70 prefill_possible_map();
71 #endif
72
73 /* Copy section for each CPU (we discard the original) */
74 size = PERCPU_ENOUGH_ROOM;
75
76 printk(KERN_INFO "PERCPU: Allocating %lu bytes of per cpu data\n",
77 size);
78 for_each_cpu_mask(i, cpu_possible_map) {
79 char *ptr;
80 #ifndef CONFIG_NEED_MULTIPLE_NODES
81 ptr = alloc_bootmem_pages(size);
82 #else
83 int node = early_cpu_to_node(i);
84 if (!node_online(node) || !NODE_DATA(node))
85 ptr = alloc_bootmem_pages(size);
86 else
87 ptr = alloc_bootmem_pages_node(NODE_DATA(node), size);
88 #endif
89 if (!ptr)
90 panic("Cannot allocate cpu data for CPU %d\n", i);
91 #ifdef CONFIG_X86_64
92 cpu_pda(i)->data_offset = ptr - __per_cpu_start;
93 #else
94 __per_cpu_offset[i] = ptr - __per_cpu_start;
95 #endif
96 memcpy(ptr, __per_cpu_start, __per_cpu_end - __per_cpu_start);
97 }
98
99 /* setup percpu data maps early */
100 setup_per_cpu_maps();
101 }
102
103 #endif
This page took 0.034172 seconds and 6 git commands to generate.