blob: 011fcdd213ff8ea2c89bb46160baf5b8e781c632 [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>
Alexey Starikovskiy0fc09062008-04-04 23:40:48 +040012#include <asm/mpspec.h>
Alexey Starikovskiy76eb4132008-04-04 23:40:41 +040013#include <asm/apicdef.h>
14
15DEFINE_PER_CPU(u16, x86_cpu_to_apicid) = BAD_APICID;
16EXPORT_PER_CPU_SYMBOL(x86_cpu_to_apicid);
Glauber de Oliveira Costa4fe29a82008-03-19 14:25:23 -030017
Alexey Starikovskiy0fc09062008-04-04 23:40:48 +040018/* Bitmask of physically existing CPUs */
19physid_mask_t phys_cpu_present_map;
20
Mike Travisb447a462008-03-25 15:06:51 -070021#if defined(CONFIG_HAVE_SETUP_PER_CPU_AREA) && defined(CONFIG_SMP)
Glauber de Oliveira Costa4fe29a82008-03-19 14:25:23 -030022/*
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 */
27static void __init setup_per_cpu_maps(void)
28{
29 int cpu;
30
31 for_each_possible_cpu(cpu) {
Mike Travisb447a462008-03-25 15:06:51 -070032 per_cpu(x86_cpu_to_apicid, cpu) = x86_cpu_to_apicid_init[cpu];
33 per_cpu(x86_bios_cpu_apicid, cpu) =
Glauber de Oliveira Costa4fe29a82008-03-19 14:25:23 -030034 x86_bios_cpu_apicid_init[cpu];
35#ifdef CONFIG_NUMA
Mike Travisb447a462008-03-25 15:06:51 -070036 per_cpu(x86_cpu_to_node_map, cpu) =
Glauber de Oliveira Costa4fe29a82008-03-19 14:25:23 -030037 x86_cpu_to_node_map_init[cpu];
38#endif
Glauber de Oliveira Costa4fe29a82008-03-19 14:25:23 -030039 }
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 */
54unsigned long __per_cpu_offset[NR_CPUS] __read_mostly;
55EXPORT_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 */
63void __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;
Glauber de Oliveira Costa4fe29a82008-03-19 14:25:23 -030074 printk(KERN_INFO "PERCPU: Allocating %lu bytes of per cpu data\n",
75 size);
Mike Travisb447a462008-03-25 15:06:51 -070076
77 for_each_possible_cpu(i) {
Glauber de Oliveira Costa4fe29a82008-03-19 14:25:23 -030078 char *ptr;
79#ifndef CONFIG_NEED_MULTIPLE_NODES
80 ptr = alloc_bootmem_pages(size);
81#else
82 int node = early_cpu_to_node(i);
Mike Travisb447a462008-03-25 15:06:51 -070083 if (!node_online(node) || !NODE_DATA(node)) {
Glauber de Oliveira Costa4fe29a82008-03-19 14:25:23 -030084 ptr = alloc_bootmem_pages(size);
Mike Travisb447a462008-03-25 15:06:51 -070085 printk(KERN_INFO
86 "cpu %d has no node or node-local memory\n", i);
87 }
Glauber de Oliveira Costa4fe29a82008-03-19 14:25:23 -030088 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
Mike Travisb447a462008-03-25 15:06:51 -0700101 /* Setup percpu data maps */
Glauber de Oliveira Costa4fe29a82008-03-19 14:25:23 -0300102 setup_per_cpu_maps();
103}
104
105#endif