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