Glauber de Oliveira Costa | 4fe29a8 | 2008-03-19 14:25:23 -0300 | [diff] [blame] | 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> |
| 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 Starikovskiy | 76eb413 | 2008-04-04 23:40:41 +0400 | [diff] [blame^] | 12 | #include <asm/apicdef.h> |
| 13 | |
| 14 | DEFINE_PER_CPU(u16, x86_cpu_to_apicid) = BAD_APICID; |
| 15 | EXPORT_PER_CPU_SYMBOL(x86_cpu_to_apicid); |
Glauber de Oliveira Costa | 4fe29a8 | 2008-03-19 14:25:23 -0300 | [diff] [blame] | 16 | |
Mike Travis | b447a46 | 2008-03-25 15:06:51 -0700 | [diff] [blame] | 17 | #if defined(CONFIG_HAVE_SETUP_PER_CPU_AREA) && defined(CONFIG_SMP) |
Glauber de Oliveira Costa | 4fe29a8 | 2008-03-19 14:25:23 -0300 | [diff] [blame] | 18 | /* |
| 19 | * Copy data used in early init routines from the initial arrays to the |
| 20 | * per cpu data areas. These arrays then become expendable and the |
| 21 | * *_early_ptr's are zeroed indicating that the static arrays are gone. |
| 22 | */ |
| 23 | static void __init setup_per_cpu_maps(void) |
| 24 | { |
| 25 | int cpu; |
| 26 | |
| 27 | for_each_possible_cpu(cpu) { |
Mike Travis | b447a46 | 2008-03-25 15:06:51 -0700 | [diff] [blame] | 28 | per_cpu(x86_cpu_to_apicid, cpu) = x86_cpu_to_apicid_init[cpu]; |
| 29 | per_cpu(x86_bios_cpu_apicid, cpu) = |
Glauber de Oliveira Costa | 4fe29a8 | 2008-03-19 14:25:23 -0300 | [diff] [blame] | 30 | x86_bios_cpu_apicid_init[cpu]; |
| 31 | #ifdef CONFIG_NUMA |
Mike Travis | b447a46 | 2008-03-25 15:06:51 -0700 | [diff] [blame] | 32 | per_cpu(x86_cpu_to_node_map, cpu) = |
Glauber de Oliveira Costa | 4fe29a8 | 2008-03-19 14:25:23 -0300 | [diff] [blame] | 33 | x86_cpu_to_node_map_init[cpu]; |
| 34 | #endif |
Glauber de Oliveira Costa | 4fe29a8 | 2008-03-19 14:25:23 -0300 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | /* indicate the early static arrays will soon be gone */ |
| 38 | x86_cpu_to_apicid_early_ptr = NULL; |
| 39 | x86_bios_cpu_apicid_early_ptr = NULL; |
| 40 | #ifdef CONFIG_NUMA |
| 41 | x86_cpu_to_node_map_early_ptr = NULL; |
| 42 | #endif |
| 43 | } |
| 44 | |
| 45 | #ifdef CONFIG_X86_32 |
| 46 | /* |
| 47 | * Great future not-so-futuristic plan: make i386 and x86_64 do it |
| 48 | * the same way |
| 49 | */ |
| 50 | unsigned long __per_cpu_offset[NR_CPUS] __read_mostly; |
| 51 | EXPORT_SYMBOL(__per_cpu_offset); |
| 52 | #endif |
| 53 | |
| 54 | /* |
| 55 | * Great future plan: |
| 56 | * Declare PDA itself and support (irqstack,tss,pgd) as per cpu data. |
| 57 | * Always point %gs to its beginning |
| 58 | */ |
| 59 | void __init setup_per_cpu_areas(void) |
| 60 | { |
| 61 | int i; |
| 62 | unsigned long size; |
| 63 | |
| 64 | #ifdef CONFIG_HOTPLUG_CPU |
| 65 | prefill_possible_map(); |
| 66 | #endif |
| 67 | |
| 68 | /* Copy section for each CPU (we discard the original) */ |
| 69 | size = PERCPU_ENOUGH_ROOM; |
Glauber de Oliveira Costa | 4fe29a8 | 2008-03-19 14:25:23 -0300 | [diff] [blame] | 70 | printk(KERN_INFO "PERCPU: Allocating %lu bytes of per cpu data\n", |
| 71 | size); |
Mike Travis | b447a46 | 2008-03-25 15:06:51 -0700 | [diff] [blame] | 72 | |
| 73 | for_each_possible_cpu(i) { |
Glauber de Oliveira Costa | 4fe29a8 | 2008-03-19 14:25:23 -0300 | [diff] [blame] | 74 | char *ptr; |
| 75 | #ifndef CONFIG_NEED_MULTIPLE_NODES |
| 76 | ptr = alloc_bootmem_pages(size); |
| 77 | #else |
| 78 | int node = early_cpu_to_node(i); |
Mike Travis | b447a46 | 2008-03-25 15:06:51 -0700 | [diff] [blame] | 79 | if (!node_online(node) || !NODE_DATA(node)) { |
Glauber de Oliveira Costa | 4fe29a8 | 2008-03-19 14:25:23 -0300 | [diff] [blame] | 80 | ptr = alloc_bootmem_pages(size); |
Mike Travis | b447a46 | 2008-03-25 15:06:51 -0700 | [diff] [blame] | 81 | printk(KERN_INFO |
| 82 | "cpu %d has no node or node-local memory\n", i); |
| 83 | } |
Glauber de Oliveira Costa | 4fe29a8 | 2008-03-19 14:25:23 -0300 | [diff] [blame] | 84 | else |
| 85 | ptr = alloc_bootmem_pages_node(NODE_DATA(node), size); |
| 86 | #endif |
| 87 | if (!ptr) |
| 88 | panic("Cannot allocate cpu data for CPU %d\n", i); |
| 89 | #ifdef CONFIG_X86_64 |
| 90 | cpu_pda(i)->data_offset = ptr - __per_cpu_start; |
| 91 | #else |
| 92 | __per_cpu_offset[i] = ptr - __per_cpu_start; |
| 93 | #endif |
| 94 | memcpy(ptr, __per_cpu_start, __per_cpu_end - __per_cpu_start); |
| 95 | } |
| 96 | |
Mike Travis | b447a46 | 2008-03-25 15:06:51 -0700 | [diff] [blame] | 97 | /* Setup percpu data maps */ |
Glauber de Oliveira Costa | 4fe29a8 | 2008-03-19 14:25:23 -0300 | [diff] [blame] | 98 | setup_per_cpu_maps(); |
| 99 | } |
| 100 | |
| 101 | #endif |