]>
Commit | Line | Data |
---|---|---|
4fe29a85 GOC |
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> | |
1ecd2765 | 6 | #include <linux/kexec.h> |
17b4cceb | 7 | #include <linux/crash_dump.h> |
8a87dd9a JSR |
8 | #include <linux/smp.h> |
9 | #include <linux/topology.h> | |
4fe29a85 GOC |
10 | #include <asm/sections.h> |
11 | #include <asm/processor.h> | |
12 | #include <asm/setup.h> | |
0fc0906e | 13 | #include <asm/mpspec.h> |
76eb4131 | 14 | #include <asm/apicdef.h> |
1ecd2765 | 15 | #include <asm/highmem.h> |
1a51e3a0 | 16 | #include <asm/proto.h> |
06879033 | 17 | #include <asm/cpumask.h> |
76eb4131 | 18 | |
c90aa894 MT |
19 | #ifdef CONFIG_DEBUG_PER_CPU_MAPS |
20 | # define DBG(x...) printk(KERN_DEBUG x) | |
21 | #else | |
22 | # define DBG(x...) | |
23 | #endif | |
24 | ||
ea927906 BG |
25 | DEFINE_PER_CPU(int, cpu_number); |
26 | EXPORT_PER_CPU_SYMBOL(cpu_number); | |
ea927906 | 27 | |
c90aa894 | 28 | #ifdef CONFIG_HAVE_SETUP_PER_CPU_AREA |
4fe29a85 | 29 | |
9939ddaf TH |
30 | #ifdef CONFIG_X86_64 |
31 | unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = { | |
32 | [0] = (unsigned long)__per_cpu_load, | |
33 | }; | |
34 | #else | |
4fe29a85 | 35 | unsigned long __per_cpu_offset[NR_CPUS] __read_mostly; |
1a51e3a0 | 36 | #endif |
9939ddaf | 37 | EXPORT_SYMBOL(__per_cpu_offset); |
4fe29a85 GOC |
38 | |
39 | /* | |
40 | * Great future plan: | |
41 | * Declare PDA itself and support (irqstack,tss,pgd) as per cpu data. | |
42 | * Always point %gs to its beginning | |
43 | */ | |
44 | void __init setup_per_cpu_areas(void) | |
45 | { | |
74631a24 | 46 | ssize_t size; |
3461b0af MT |
47 | char *ptr; |
48 | int cpu; | |
4fe29a85 | 49 | |
4fe29a85 | 50 | /* Copy section for each CPU (we discard the original) */ |
74631a24 | 51 | size = roundup(PERCPU_ENOUGH_ROOM, PAGE_SIZE); |
a1681965 | 52 | |
ab14398a | 53 | pr_info("NR_CPUS:%d nr_cpumask_bits:%d nr_cpu_ids:%d nr_node_ids:%d\n", |
a1681965 MT |
54 | NR_CPUS, nr_cpumask_bits, nr_cpu_ids, nr_node_ids); |
55 | ||
ab14398a | 56 | pr_info("PERCPU: Allocating %zd bytes of per cpu data\n", size); |
b447a468 | 57 | |
3461b0af | 58 | for_each_possible_cpu(cpu) { |
4fe29a85 | 59 | #ifndef CONFIG_NEED_MULTIPLE_NODES |
74631a24 | 60 | ptr = alloc_bootmem_pages(size); |
4fe29a85 | 61 | #else |
3461b0af | 62 | int node = early_cpu_to_node(cpu); |
b447a468 | 63 | if (!node_online(node) || !NODE_DATA(node)) { |
74631a24 | 64 | ptr = alloc_bootmem_pages(size); |
ab14398a | 65 | pr_info("cpu %d has no node %d or node-local memory\n", |
3461b0af | 66 | cpu, node); |
ab14398a CG |
67 | pr_debug("per cpu data for cpu%d at %016lx\n", |
68 | cpu, __pa(ptr)); | |
69 | } else { | |
74631a24 | 70 | ptr = alloc_bootmem_pages_node(NODE_DATA(node), size); |
ab14398a CG |
71 | pr_debug("per cpu data for cpu%d on node%d at %016lx\n", |
72 | cpu, node, __pa(ptr)); | |
a677f58a | 73 | } |
4fe29a85 | 74 | #endif |
1a51e3a0 | 75 | |
3e5d8f97 | 76 | memcpy(ptr, __per_cpu_load, __per_cpu_end - __per_cpu_start); |
9939ddaf | 77 | per_cpu_offset(cpu) = ptr - __per_cpu_start; |
26f80bd6 | 78 | per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu); |
ea927906 | 79 | per_cpu(cpu_number, cpu) = cpu; |
0d77e7f0 BG |
80 | /* |
81 | * Copy data used in early init routines from the initial arrays to the | |
82 | * per cpu data areas. These arrays then become expendable and the | |
83 | * *_early_ptr's are zeroed indicating that the static arrays are gone. | |
84 | */ | |
ec70de8b | 85 | #ifdef CONFIG_X86_LOCAL_APIC |
0d77e7f0 BG |
86 | per_cpu(x86_cpu_to_apicid, cpu) = |
87 | early_per_cpu_map(x86_cpu_to_apicid, cpu); | |
88 | per_cpu(x86_bios_cpu_apicid, cpu) = | |
89 | early_per_cpu_map(x86_bios_cpu_apicid, cpu); | |
ec70de8b | 90 | #endif |
1a51e3a0 | 91 | #ifdef CONFIG_X86_64 |
26f80bd6 | 92 | per_cpu(irq_stack_ptr, cpu) = |
947e76cd | 93 | per_cpu(irq_stack_union.irq_stack, cpu) + IRQ_STACK_SIZE - 64; |
6470aff6 BG |
94 | #ifdef CONFIG_NUMA |
95 | per_cpu(x86_cpu_to_node_map, cpu) = | |
96 | early_per_cpu_map(x86_cpu_to_node_map, cpu); | |
97 | #endif | |
1a51e3a0 | 98 | /* |
947e76cd BG |
99 | * Up to this point, CPU0 has been using .data.init |
100 | * area. Reload %gs offset for CPU0. | |
1a51e3a0 TH |
101 | */ |
102 | if (cpu == 0) | |
947e76cd | 103 | load_gs_base(cpu); |
1a51e3a0 | 104 | #endif |
c90aa894 MT |
105 | |
106 | DBG("PERCPU: cpu %4d %p\n", cpu, ptr); | |
4fe29a85 GOC |
107 | } |
108 | ||
0d77e7f0 BG |
109 | /* indicate the early static arrays will soon be gone */ |
110 | early_per_cpu_ptr(x86_cpu_to_apicid) = NULL; | |
111 | early_per_cpu_ptr(x86_bios_cpu_apicid) = NULL; | |
6470aff6 | 112 | #if defined(CONFIG_X86_64) && defined(CONFIG_NUMA) |
0d77e7f0 BG |
113 | early_per_cpu_ptr(x86_cpu_to_node_map) = NULL; |
114 | #endif | |
9f0e8d04 | 115 | |
9f248bde MT |
116 | /* Setup node to cpumask map */ |
117 | setup_node_to_cpumask_map(); | |
c2d1cec1 MT |
118 | |
119 | /* Setup cpu initialized, callin, callout masks */ | |
120 | setup_cpu_local_masks(); | |
4fe29a85 GOC |
121 | } |
122 | ||
123 | #endif | |
c45a707d | 124 |