blob: 45a5e247d45093af8db7305623e24d9f4a197ba5 [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
James Bottomleyf8955eb2008-05-10 09:01:48 -050015#ifdef CONFIG_X86_LOCAL_APIC
Alexey Starikovskiy2fe60142008-04-04 23:41:44 +040016unsigned int num_processors;
17unsigned disabled_cpus __cpuinitdata;
18/* Processor that is doing the boot up */
19unsigned int boot_cpu_physical_apicid = -1U;
Yinghai Lue0da3362008-06-08 18:29:22 -070020unsigned int max_physical_apicid;
Alexey Starikovskiy2fe60142008-04-04 23:41:44 +040021EXPORT_SYMBOL(boot_cpu_physical_apicid);
22
Alexey Starikovskiy76eb4132008-04-04 23:40:41 +040023DEFINE_PER_CPU(u16, x86_cpu_to_apicid) = BAD_APICID;
24EXPORT_PER_CPU_SYMBOL(x86_cpu_to_apicid);
Glauber de Oliveira Costa4fe29a82008-03-19 14:25:23 -030025
Alexey Starikovskiy0fc09062008-04-04 23:40:48 +040026/* Bitmask of physically existing CPUs */
27physid_mask_t phys_cpu_present_map;
James Bottomleyf8955eb2008-05-10 09:01:48 -050028#endif
Alexey Starikovskiy0fc09062008-04-04 23:40:48 +040029
James Bottomleyf8955eb2008-05-10 09:01:48 -050030#if defined(CONFIG_HAVE_SETUP_PER_CPU_AREA) && defined(CONFIG_X86_SMP)
Glauber de Oliveira Costa4fe29a82008-03-19 14:25:23 -030031/*
32 * Copy data used in early init routines from the initial arrays to the
33 * per cpu data areas. These arrays then become expendable and the
34 * *_early_ptr's are zeroed indicating that the static arrays are gone.
35 */
36static void __init setup_per_cpu_maps(void)
37{
38 int cpu;
39
40 for_each_possible_cpu(cpu) {
Mike Travisb447a462008-03-25 15:06:51 -070041 per_cpu(x86_cpu_to_apicid, cpu) = x86_cpu_to_apicid_init[cpu];
42 per_cpu(x86_bios_cpu_apicid, cpu) =
Glauber de Oliveira Costa4fe29a82008-03-19 14:25:23 -030043 x86_bios_cpu_apicid_init[cpu];
44#ifdef CONFIG_NUMA
Mike Travisb447a462008-03-25 15:06:51 -070045 per_cpu(x86_cpu_to_node_map, cpu) =
Glauber de Oliveira Costa4fe29a82008-03-19 14:25:23 -030046 x86_cpu_to_node_map_init[cpu];
47#endif
Glauber de Oliveira Costa4fe29a82008-03-19 14:25:23 -030048 }
49
50 /* indicate the early static arrays will soon be gone */
51 x86_cpu_to_apicid_early_ptr = NULL;
52 x86_bios_cpu_apicid_early_ptr = NULL;
53#ifdef CONFIG_NUMA
54 x86_cpu_to_node_map_early_ptr = NULL;
55#endif
56}
57
Mike Travis9f0e8d02008-04-04 18:11:01 -070058#ifdef CONFIG_HAVE_CPUMASK_OF_CPU_MAP
59cpumask_t *cpumask_of_cpu_map __read_mostly;
60EXPORT_SYMBOL(cpumask_of_cpu_map);
61
62/* requires nr_cpu_ids to be initialized */
63static void __init setup_cpumask_of_cpu(void)
64{
65 int i;
66
67 /* alloc_bootmem zeroes memory */
68 cpumask_of_cpu_map = alloc_bootmem_low(sizeof(cpumask_t) * nr_cpu_ids);
69 for (i = 0; i < nr_cpu_ids; i++)
70 cpu_set(i, cpumask_of_cpu_map[i]);
71}
72#else
73static inline void setup_cpumask_of_cpu(void) { }
74#endif
75
Glauber de Oliveira Costa4fe29a82008-03-19 14:25:23 -030076#ifdef CONFIG_X86_32
77/*
78 * Great future not-so-futuristic plan: make i386 and x86_64 do it
79 * the same way
80 */
81unsigned long __per_cpu_offset[NR_CPUS] __read_mostly;
82EXPORT_SYMBOL(__per_cpu_offset);
83#endif
84
85/*
86 * Great future plan:
87 * Declare PDA itself and support (irqstack,tss,pgd) as per cpu data.
88 * Always point %gs to its beginning
89 */
90void __init setup_per_cpu_areas(void)
91{
Mike Travis9f0e8d02008-04-04 18:11:01 -070092 int i, highest_cpu = 0;
Glauber de Oliveira Costa4fe29a82008-03-19 14:25:23 -030093 unsigned long size;
94
95#ifdef CONFIG_HOTPLUG_CPU
96 prefill_possible_map();
97#endif
98
99 /* Copy section for each CPU (we discard the original) */
100 size = PERCPU_ENOUGH_ROOM;
Thomas Gleixner5ecddce2008-05-08 16:38:11 +0200101 printk(KERN_INFO "PERCPU: Allocating %lu bytes of per cpu data\n",
Glauber de Oliveira Costa4fe29a82008-03-19 14:25:23 -0300102 size);
Mike Travisb447a462008-03-25 15:06:51 -0700103
104 for_each_possible_cpu(i) {
Glauber de Oliveira Costa4fe29a82008-03-19 14:25:23 -0300105 char *ptr;
106#ifndef CONFIG_NEED_MULTIPLE_NODES
107 ptr = alloc_bootmem_pages(size);
108#else
109 int node = early_cpu_to_node(i);
Mike Travisb447a462008-03-25 15:06:51 -0700110 if (!node_online(node) || !NODE_DATA(node)) {
Glauber de Oliveira Costa4fe29a82008-03-19 14:25:23 -0300111 ptr = alloc_bootmem_pages(size);
Mike Travisb447a462008-03-25 15:06:51 -0700112 printk(KERN_INFO
113 "cpu %d has no node or node-local memory\n", i);
114 }
Glauber de Oliveira Costa4fe29a82008-03-19 14:25:23 -0300115 else
116 ptr = alloc_bootmem_pages_node(NODE_DATA(node), size);
117#endif
118 if (!ptr)
119 panic("Cannot allocate cpu data for CPU %d\n", i);
120#ifdef CONFIG_X86_64
121 cpu_pda(i)->data_offset = ptr - __per_cpu_start;
122#else
123 __per_cpu_offset[i] = ptr - __per_cpu_start;
124#endif
125 memcpy(ptr, __per_cpu_start, __per_cpu_end - __per_cpu_start);
Mike Travis9f0e8d02008-04-04 18:11:01 -0700126
127 highest_cpu = i;
Glauber de Oliveira Costa4fe29a82008-03-19 14:25:23 -0300128 }
129
Mike Travis9f0e8d02008-04-04 18:11:01 -0700130 nr_cpu_ids = highest_cpu + 1;
131 printk(KERN_DEBUG "NR_CPUS: %d, nr_cpu_ids: %d\n", NR_CPUS, nr_cpu_ids);
132
Mike Travisb447a462008-03-25 15:06:51 -0700133 /* Setup percpu data maps */
Glauber de Oliveira Costa4fe29a82008-03-19 14:25:23 -0300134 setup_per_cpu_maps();
Mike Travis9f0e8d02008-04-04 18:11:01 -0700135
136 /* Setup cpumask_of_cpu map */
137 setup_cpumask_of_cpu();
Glauber de Oliveira Costa4fe29a82008-03-19 14:25:23 -0300138}
139
140#endif
Huang, Yingc45a7072008-06-02 14:26:25 +0800141
142void __init parse_setup_data(void)
143{
144 struct setup_data *data;
145 u64 pa_data;
146
147 if (boot_params.hdr.version < 0x0209)
148 return;
149 pa_data = boot_params.hdr.setup_data;
150 while (pa_data) {
151 data = early_ioremap(pa_data, PAGE_SIZE);
152 switch (data->type) {
153 default:
154 break;
155 }
156#ifndef CONFIG_DEBUG_BOOT_PARAMS
157 free_early(pa_data, pa_data+sizeof(*data)+data->len);
158#endif
159 pa_data = data->next;
160 early_iounmap(data, PAGE_SIZE);
161 }
162}