blob: dc7940955b7a0febacf97498ae9ee0bbfed7e03f [file] [log] [blame]
Glauber de Oliveira Costa4fe29a82008-03-19 14:25:23 -03001#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
Mike Travisb447a462008-03-25 15:06:51 -070013#if defined(CONFIG_HAVE_SETUP_PER_CPU_AREA) && defined(CONFIG_SMP)
Glauber de Oliveira Costa4fe29a82008-03-19 14:25:23 -030014/*
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 */
19static void __init setup_per_cpu_maps(void)
20{
21 int cpu;
22
23 for_each_possible_cpu(cpu) {
Mike Travisb447a462008-03-25 15:06:51 -070024 per_cpu(x86_cpu_to_apicid, cpu) = x86_cpu_to_apicid_init[cpu];
25 per_cpu(x86_bios_cpu_apicid, cpu) =
Glauber de Oliveira Costa4fe29a82008-03-19 14:25:23 -030026 x86_bios_cpu_apicid_init[cpu];
27#ifdef CONFIG_NUMA
Mike Travisb447a462008-03-25 15:06:51 -070028 per_cpu(x86_cpu_to_node_map, cpu) =
Glauber de Oliveira Costa4fe29a82008-03-19 14:25:23 -030029 x86_cpu_to_node_map_init[cpu];
30#endif
Glauber de Oliveira Costa4fe29a82008-03-19 14:25:23 -030031 }
32
33 /* indicate the early static arrays will soon be gone */
34 x86_cpu_to_apicid_early_ptr = NULL;
35 x86_bios_cpu_apicid_early_ptr = NULL;
36#ifdef CONFIG_NUMA
37 x86_cpu_to_node_map_early_ptr = NULL;
38#endif
39}
40
41#ifdef CONFIG_X86_32
42/*
43 * Great future not-so-futuristic plan: make i386 and x86_64 do it
44 * the same way
45 */
46unsigned long __per_cpu_offset[NR_CPUS] __read_mostly;
47EXPORT_SYMBOL(__per_cpu_offset);
48#endif
49
50/*
51 * Great future plan:
52 * Declare PDA itself and support (irqstack,tss,pgd) as per cpu data.
53 * Always point %gs to its beginning
54 */
55void __init setup_per_cpu_areas(void)
56{
57 int i;
58 unsigned long size;
59
60#ifdef CONFIG_HOTPLUG_CPU
61 prefill_possible_map();
62#endif
63
64 /* Copy section for each CPU (we discard the original) */
65 size = PERCPU_ENOUGH_ROOM;
Glauber de Oliveira Costa4fe29a82008-03-19 14:25:23 -030066 printk(KERN_INFO "PERCPU: Allocating %lu bytes of per cpu data\n",
67 size);
Mike Travisb447a462008-03-25 15:06:51 -070068
69 for_each_possible_cpu(i) {
Glauber de Oliveira Costa4fe29a82008-03-19 14:25:23 -030070 char *ptr;
71#ifndef CONFIG_NEED_MULTIPLE_NODES
72 ptr = alloc_bootmem_pages(size);
73#else
74 int node = early_cpu_to_node(i);
Mike Travisb447a462008-03-25 15:06:51 -070075 if (!node_online(node) || !NODE_DATA(node)) {
Glauber de Oliveira Costa4fe29a82008-03-19 14:25:23 -030076 ptr = alloc_bootmem_pages(size);
Mike Travisb447a462008-03-25 15:06:51 -070077 printk(KERN_INFO
78 "cpu %d has no node or node-local memory\n", i);
79 }
Glauber de Oliveira Costa4fe29a82008-03-19 14:25:23 -030080 else
81 ptr = alloc_bootmem_pages_node(NODE_DATA(node), size);
82#endif
83 if (!ptr)
84 panic("Cannot allocate cpu data for CPU %d\n", i);
85#ifdef CONFIG_X86_64
86 cpu_pda(i)->data_offset = ptr - __per_cpu_start;
87#else
88 __per_cpu_offset[i] = ptr - __per_cpu_start;
89#endif
90 memcpy(ptr, __per_cpu_start, __per_cpu_end - __per_cpu_start);
91 }
92
Mike Travisb447a462008-03-25 15:06:51 -070093 /* Setup percpu data maps */
Glauber de Oliveira Costa4fe29a82008-03-19 14:25:23 -030094 setup_per_cpu_maps();
95}
96
97#endif