blob: cb6d622520bebb579524af62f8edbc390a48b5a2 [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>
Bernhard Walle1ecd2762008-06-20 15:38:22 +02006#include <linux/kexec.h>
Yinghai Lu17b4cce2008-06-21 21:02:20 -07007#include <linux/crash_dump.h>
Jaswinder Singh Rajput8a87dd92009-01-04 17:04:26 +05308#include <linux/smp.h>
9#include <linux/topology.h>
Glauber de Oliveira Costa4fe29a82008-03-19 14:25:23 -030010#include <asm/sections.h>
11#include <asm/processor.h>
12#include <asm/setup.h>
Alexey Starikovskiy0fc09062008-04-04 23:40:48 +040013#include <asm/mpspec.h>
Alexey Starikovskiy76eb4132008-04-04 23:40:41 +040014#include <asm/apicdef.h>
Bernhard Walle1ecd2762008-06-20 15:38:22 +020015#include <asm/highmem.h>
Tejun Heo1a51e3a2009-01-13 20:41:35 +090016#include <asm/proto.h>
Jaswinder Singh Rajput06879032009-01-10 12:17:37 +053017#include <asm/cpumask.h>
Alexey Starikovskiy76eb4132008-04-04 23:40:41 +040018
Mike Travisc90aa892009-01-13 20:41:34 +090019#ifdef CONFIG_DEBUG_PER_CPU_MAPS
20# define DBG(x...) printk(KERN_DEBUG x)
21#else
22# define DBG(x...)
23#endif
24
Brian Gerstea927902009-01-19 00:38:58 +090025/*
26 * Could be inside CONFIG_HAVE_SETUP_PER_CPU_AREA with other stuff but
27 * voyager wants cpu_number too.
28 */
29#ifdef CONFIG_SMP
30DEFINE_PER_CPU(int, cpu_number);
31EXPORT_PER_CPU_SYMBOL(cpu_number);
32#endif
33
James Bottomleyf8955eb2008-05-10 09:01:48 -050034#ifdef CONFIG_X86_LOCAL_APIC
Alexey Starikovskiy2fe60142008-04-04 23:41:44 +040035unsigned int num_processors;
36unsigned disabled_cpus __cpuinitdata;
37/* Processor that is doing the boot up */
38unsigned int boot_cpu_physical_apicid = -1U;
39EXPORT_SYMBOL(boot_cpu_physical_apicid);
Jaswinder Singh Rajput8a87dd92009-01-04 17:04:26 +053040unsigned int max_physical_apicid;
Alexey Starikovskiy2fe60142008-04-04 23:41:44 +040041
Alexey Starikovskiy0fc09062008-04-04 23:40:48 +040042/* Bitmask of physically existing CPUs */
43physid_mask_t phys_cpu_present_map;
James Bottomleyf8955eb2008-05-10 09:01:48 -050044#endif
Alexey Starikovskiy0fc09062008-04-04 23:40:48 +040045
Mike Travisc90aa892009-01-13 20:41:34 +090046/*
47 * Map cpu index to physical APIC ID
48 */
Mike Travis23ca4bb2008-05-12 21:21:12 +020049DEFINE_EARLY_PER_CPU(u16, x86_cpu_to_apicid, BAD_APICID);
50DEFINE_EARLY_PER_CPU(u16, x86_bios_cpu_apicid, BAD_APICID);
51EXPORT_EARLY_PER_CPU_SYMBOL(x86_cpu_to_apicid);
52EXPORT_EARLY_PER_CPU_SYMBOL(x86_bios_cpu_apicid);
53
Tejun Heo1a51e3a2009-01-13 20:41:35 +090054#ifdef CONFIG_X86_64
55
56/* correctly size the local cpu masks */
57static void setup_cpu_local_masks(void)
58{
59 alloc_bootmem_cpumask_var(&cpu_initialized_mask);
60 alloc_bootmem_cpumask_var(&cpu_callin_mask);
61 alloc_bootmem_cpumask_var(&cpu_callout_mask);
62 alloc_bootmem_cpumask_var(&cpu_sibling_setup_mask);
63}
64
65#else /* CONFIG_X86_32 */
66
67static inline void setup_cpu_local_masks(void)
68{
69}
70
71#endif /* CONFIG_X86_32 */
72
Mike Travisc90aa892009-01-13 20:41:34 +090073#ifdef CONFIG_HAVE_SETUP_PER_CPU_AREA
Glauber de Oliveira Costa4fe29a82008-03-19 14:25:23 -030074
Tejun Heo9939dda2009-01-13 20:41:35 +090075#ifdef CONFIG_X86_64
76unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
77 [0] = (unsigned long)__per_cpu_load,
78};
79#else
Glauber de Oliveira Costa4fe29a82008-03-19 14:25:23 -030080unsigned long __per_cpu_offset[NR_CPUS] __read_mostly;
Tejun Heo1a51e3a2009-01-13 20:41:35 +090081#endif
Tejun Heo9939dda2009-01-13 20:41:35 +090082EXPORT_SYMBOL(__per_cpu_offset);
Glauber de Oliveira Costa4fe29a82008-03-19 14:25:23 -030083
84/*
85 * Great future plan:
86 * Declare PDA itself and support (irqstack,tss,pgd) as per cpu data.
87 * Always point %gs to its beginning
88 */
89void __init setup_per_cpu_areas(void)
90{
Thomas Gleixnerd6c88a52008-10-15 15:27:23 +020091 ssize_t size, old_size;
Mike Travis3461b0a2008-05-12 21:21:13 +020092 char *ptr;
93 int cpu;
Yinghai Lu1f8ff032008-08-19 20:49:45 -070094 unsigned long align = 1;
Glauber de Oliveira Costa4fe29a82008-03-19 14:25:23 -030095
Glauber de Oliveira Costa4fe29a82008-03-19 14:25:23 -030096 /* Copy section for each CPU (we discard the original) */
Yinghai Lu1f3fcd42008-08-19 20:49:44 -070097 old_size = PERCPU_ENOUGH_ROOM;
Yinghai Lu1f8ff032008-08-19 20:49:45 -070098 align = max_t(unsigned long, PAGE_SIZE, align);
Thomas Gleixnerd6c88a52008-10-15 15:27:23 +020099 size = roundup(old_size, align);
Mike Travisa1681962008-12-16 17:33:53 -0800100
Cyrill Gorcunovab143982009-01-02 21:51:32 +0300101 pr_info("NR_CPUS:%d nr_cpumask_bits:%d nr_cpu_ids:%d nr_node_ids:%d\n",
Mike Travisa1681962008-12-16 17:33:53 -0800102 NR_CPUS, nr_cpumask_bits, nr_cpu_ids, nr_node_ids);
103
Cyrill Gorcunovab143982009-01-02 21:51:32 +0300104 pr_info("PERCPU: Allocating %zd bytes of per cpu data\n", size);
Mike Travisb447a462008-03-25 15:06:51 -0700105
Mike Travis3461b0a2008-05-12 21:21:13 +0200106 for_each_possible_cpu(cpu) {
Glauber de Oliveira Costa4fe29a82008-03-19 14:25:23 -0300107#ifndef CONFIG_NEED_MULTIPLE_NODES
Yinghai Lu1f8ff032008-08-19 20:49:45 -0700108 ptr = __alloc_bootmem(size, align,
109 __pa(MAX_DMA_ADDRESS));
Glauber de Oliveira Costa4fe29a82008-03-19 14:25:23 -0300110#else
Mike Travis3461b0a2008-05-12 21:21:13 +0200111 int node = early_cpu_to_node(cpu);
Mike Travisb447a462008-03-25 15:06:51 -0700112 if (!node_online(node) || !NODE_DATA(node)) {
Yinghai Lu1f8ff032008-08-19 20:49:45 -0700113 ptr = __alloc_bootmem(size, align,
114 __pa(MAX_DMA_ADDRESS));
Cyrill Gorcunovab143982009-01-02 21:51:32 +0300115 pr_info("cpu %d has no node %d or node-local memory\n",
Mike Travis3461b0a2008-05-12 21:21:13 +0200116 cpu, node);
Cyrill Gorcunovab143982009-01-02 21:51:32 +0300117 pr_debug("per cpu data for cpu%d at %016lx\n",
118 cpu, __pa(ptr));
119 } else {
Yinghai Lu1f8ff032008-08-19 20:49:45 -0700120 ptr = __alloc_bootmem_node(NODE_DATA(node), size, align,
121 __pa(MAX_DMA_ADDRESS));
Cyrill Gorcunovab143982009-01-02 21:51:32 +0300122 pr_debug("per cpu data for cpu%d on node%d at %016lx\n",
123 cpu, node, __pa(ptr));
Yinghai Lua677f582008-07-29 00:37:10 -0700124 }
Glauber de Oliveira Costa4fe29a82008-03-19 14:25:23 -0300125#endif
Tejun Heo1a51e3a2009-01-13 20:41:35 +0900126
Tejun Heo3e5d8f92009-01-13 20:41:35 +0900127 memcpy(ptr, __per_cpu_load, __per_cpu_end - __per_cpu_start);
Tejun Heo9939dda2009-01-13 20:41:35 +0900128 per_cpu_offset(cpu) = ptr - __per_cpu_start;
Brian Gerst26f80bd2009-01-19 00:38:58 +0900129 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
Brian Gerstea927902009-01-19 00:38:58 +0900130 per_cpu(cpu_number, cpu) = cpu;
Brian Gerst0d77e7f2009-01-27 12:56:47 +0900131 /*
132 * Copy data used in early init routines from the initial arrays to the
133 * per cpu data areas. These arrays then become expendable and the
134 * *_early_ptr's are zeroed indicating that the static arrays are gone.
135 */
136 per_cpu(x86_cpu_to_apicid, cpu) =
137 early_per_cpu_map(x86_cpu_to_apicid, cpu);
138 per_cpu(x86_bios_cpu_apicid, cpu) =
139 early_per_cpu_map(x86_bios_cpu_apicid, cpu);
Tejun Heo1a51e3a2009-01-13 20:41:35 +0900140#ifdef CONFIG_X86_64
Brian Gerst26f80bd2009-01-19 00:38:58 +0900141 per_cpu(irq_stack_ptr, cpu) =
Brian Gerst947e76c2009-01-19 12:21:28 +0900142 per_cpu(irq_stack_union.irq_stack, cpu) + IRQ_STACK_SIZE - 64;
Brian Gerst6470aff2009-01-27 12:56:47 +0900143#ifdef CONFIG_NUMA
144 per_cpu(x86_cpu_to_node_map, cpu) =
145 early_per_cpu_map(x86_cpu_to_node_map, cpu);
146#endif
Tejun Heo1a51e3a2009-01-13 20:41:35 +0900147 /*
Brian Gerst947e76c2009-01-19 12:21:28 +0900148 * Up to this point, CPU0 has been using .data.init
149 * area. Reload %gs offset for CPU0.
Tejun Heo1a51e3a2009-01-13 20:41:35 +0900150 */
151 if (cpu == 0)
Brian Gerst947e76c2009-01-19 12:21:28 +0900152 load_gs_base(cpu);
Tejun Heo1a51e3a2009-01-13 20:41:35 +0900153#endif
Mike Travisc90aa892009-01-13 20:41:34 +0900154
155 DBG("PERCPU: cpu %4d %p\n", cpu, ptr);
Glauber de Oliveira Costa4fe29a82008-03-19 14:25:23 -0300156 }
157
Brian Gerst0d77e7f2009-01-27 12:56:47 +0900158 /* indicate the early static arrays will soon be gone */
159 early_per_cpu_ptr(x86_cpu_to_apicid) = NULL;
160 early_per_cpu_ptr(x86_bios_cpu_apicid) = NULL;
Brian Gerst6470aff2009-01-27 12:56:47 +0900161#if defined(CONFIG_X86_64) && defined(CONFIG_NUMA)
Brian Gerst0d77e7f2009-01-27 12:56:47 +0900162 early_per_cpu_ptr(x86_cpu_to_node_map) = NULL;
163#endif
Mike Travis9f0e8d02008-04-04 18:11:01 -0700164
Mike Travis9f248bd2008-05-12 21:21:12 +0200165 /* Setup node to cpumask map */
166 setup_node_to_cpumask_map();
Mike Travisc2d1cec2009-01-04 05:18:03 -0800167
168 /* Setup cpu initialized, callin, callout masks */
169 setup_cpu_local_masks();
Glauber de Oliveira Costa4fe29a82008-03-19 14:25:23 -0300170}
171
172#endif
Huang, Yingc45a7072008-06-02 14:26:25 +0800173