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 | 0fc0906 | 2008-04-04 23:40:48 +0400 | [diff] [blame] | 12 | #include <asm/mpspec.h> |
Alexey Starikovskiy | 76eb413 | 2008-04-04 23:40:41 +0400 | [diff] [blame] | 13 | #include <asm/apicdef.h> |
| 14 | |
James Bottomley | f8955eb | 2008-05-10 09:01:48 -0500 | [diff] [blame] | 15 | #ifdef CONFIG_X86_LOCAL_APIC |
Alexey Starikovskiy | 2fe6014 | 2008-04-04 23:41:44 +0400 | [diff] [blame] | 16 | unsigned int num_processors; |
| 17 | unsigned disabled_cpus __cpuinitdata; |
| 18 | /* Processor that is doing the boot up */ |
| 19 | unsigned int boot_cpu_physical_apicid = -1U; |
| 20 | EXPORT_SYMBOL(boot_cpu_physical_apicid); |
| 21 | |
Alexey Starikovskiy | 76eb413 | 2008-04-04 23:40:41 +0400 | [diff] [blame] | 22 | DEFINE_PER_CPU(u16, x86_cpu_to_apicid) = BAD_APICID; |
| 23 | EXPORT_PER_CPU_SYMBOL(x86_cpu_to_apicid); |
Glauber de Oliveira Costa | 4fe29a8 | 2008-03-19 14:25:23 -0300 | [diff] [blame] | 24 | |
Alexey Starikovskiy | 0fc0906 | 2008-04-04 23:40:48 +0400 | [diff] [blame] | 25 | /* Bitmask of physically existing CPUs */ |
| 26 | physid_mask_t phys_cpu_present_map; |
James Bottomley | f8955eb | 2008-05-10 09:01:48 -0500 | [diff] [blame] | 27 | #endif |
Alexey Starikovskiy | 0fc0906 | 2008-04-04 23:40:48 +0400 | [diff] [blame] | 28 | |
James Bottomley | f8955eb | 2008-05-10 09:01:48 -0500 | [diff] [blame] | 29 | #if defined(CONFIG_HAVE_SETUP_PER_CPU_AREA) && defined(CONFIG_X86_SMP) |
Glauber de Oliveira Costa | 4fe29a8 | 2008-03-19 14:25:23 -0300 | [diff] [blame] | 30 | /* |
| 31 | * Copy data used in early init routines from the initial arrays to the |
| 32 | * per cpu data areas. These arrays then become expendable and the |
| 33 | * *_early_ptr's are zeroed indicating that the static arrays are gone. |
| 34 | */ |
| 35 | static void __init setup_per_cpu_maps(void) |
| 36 | { |
| 37 | int cpu; |
| 38 | |
| 39 | for_each_possible_cpu(cpu) { |
Mike Travis | b447a46 | 2008-03-25 15:06:51 -0700 | [diff] [blame] | 40 | per_cpu(x86_cpu_to_apicid, cpu) = x86_cpu_to_apicid_init[cpu]; |
| 41 | per_cpu(x86_bios_cpu_apicid, cpu) = |
Glauber de Oliveira Costa | 4fe29a8 | 2008-03-19 14:25:23 -0300 | [diff] [blame] | 42 | x86_bios_cpu_apicid_init[cpu]; |
| 43 | #ifdef CONFIG_NUMA |
Mike Travis | b447a46 | 2008-03-25 15:06:51 -0700 | [diff] [blame] | 44 | per_cpu(x86_cpu_to_node_map, cpu) = |
Glauber de Oliveira Costa | 4fe29a8 | 2008-03-19 14:25:23 -0300 | [diff] [blame] | 45 | x86_cpu_to_node_map_init[cpu]; |
| 46 | #endif |
Glauber de Oliveira Costa | 4fe29a8 | 2008-03-19 14:25:23 -0300 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | /* indicate the early static arrays will soon be gone */ |
| 50 | x86_cpu_to_apicid_early_ptr = NULL; |
| 51 | x86_bios_cpu_apicid_early_ptr = NULL; |
| 52 | #ifdef CONFIG_NUMA |
| 53 | x86_cpu_to_node_map_early_ptr = NULL; |
| 54 | #endif |
| 55 | } |
| 56 | |
Mike Travis | 9f0e8d0 | 2008-04-04 18:11:01 -0700 | [diff] [blame] | 57 | #ifdef CONFIG_HAVE_CPUMASK_OF_CPU_MAP |
| 58 | cpumask_t *cpumask_of_cpu_map __read_mostly; |
| 59 | EXPORT_SYMBOL(cpumask_of_cpu_map); |
| 60 | |
| 61 | /* requires nr_cpu_ids to be initialized */ |
| 62 | static void __init setup_cpumask_of_cpu(void) |
| 63 | { |
| 64 | int i; |
| 65 | |
| 66 | /* alloc_bootmem zeroes memory */ |
| 67 | cpumask_of_cpu_map = alloc_bootmem_low(sizeof(cpumask_t) * nr_cpu_ids); |
| 68 | for (i = 0; i < nr_cpu_ids; i++) |
| 69 | cpu_set(i, cpumask_of_cpu_map[i]); |
| 70 | } |
| 71 | #else |
| 72 | static inline void setup_cpumask_of_cpu(void) { } |
| 73 | #endif |
| 74 | |
Glauber de Oliveira Costa | 4fe29a8 | 2008-03-19 14:25:23 -0300 | [diff] [blame] | 75 | #ifdef CONFIG_X86_32 |
| 76 | /* |
| 77 | * Great future not-so-futuristic plan: make i386 and x86_64 do it |
| 78 | * the same way |
| 79 | */ |
| 80 | unsigned long __per_cpu_offset[NR_CPUS] __read_mostly; |
| 81 | EXPORT_SYMBOL(__per_cpu_offset); |
| 82 | #endif |
| 83 | |
| 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 | */ |
| 89 | void __init setup_per_cpu_areas(void) |
| 90 | { |
Mike Travis | 9f0e8d0 | 2008-04-04 18:11:01 -0700 | [diff] [blame] | 91 | int i, highest_cpu = 0; |
Glauber de Oliveira Costa | 4fe29a8 | 2008-03-19 14:25:23 -0300 | [diff] [blame] | 92 | unsigned long size; |
| 93 | |
| 94 | #ifdef CONFIG_HOTPLUG_CPU |
| 95 | prefill_possible_map(); |
| 96 | #endif |
| 97 | |
| 98 | /* Copy section for each CPU (we discard the original) */ |
| 99 | size = PERCPU_ENOUGH_ROOM; |
Thomas Gleixner | 5ecddce | 2008-05-08 16:38:11 +0200 | [diff] [blame] | 100 | printk(KERN_INFO "PERCPU: Allocating %lu bytes of per cpu data\n", |
Glauber de Oliveira Costa | 4fe29a8 | 2008-03-19 14:25:23 -0300 | [diff] [blame] | 101 | size); |
Mike Travis | b447a46 | 2008-03-25 15:06:51 -0700 | [diff] [blame] | 102 | |
| 103 | for_each_possible_cpu(i) { |
Glauber de Oliveira Costa | 4fe29a8 | 2008-03-19 14:25:23 -0300 | [diff] [blame] | 104 | char *ptr; |
| 105 | #ifndef CONFIG_NEED_MULTIPLE_NODES |
| 106 | ptr = alloc_bootmem_pages(size); |
| 107 | #else |
| 108 | int node = early_cpu_to_node(i); |
Mike Travis | b447a46 | 2008-03-25 15:06:51 -0700 | [diff] [blame] | 109 | if (!node_online(node) || !NODE_DATA(node)) { |
Glauber de Oliveira Costa | 4fe29a8 | 2008-03-19 14:25:23 -0300 | [diff] [blame] | 110 | ptr = alloc_bootmem_pages(size); |
Mike Travis | b447a46 | 2008-03-25 15:06:51 -0700 | [diff] [blame] | 111 | printk(KERN_INFO |
| 112 | "cpu %d has no node or node-local memory\n", i); |
| 113 | } |
Glauber de Oliveira Costa | 4fe29a8 | 2008-03-19 14:25:23 -0300 | [diff] [blame] | 114 | else |
| 115 | ptr = alloc_bootmem_pages_node(NODE_DATA(node), size); |
| 116 | #endif |
| 117 | if (!ptr) |
| 118 | panic("Cannot allocate cpu data for CPU %d\n", i); |
| 119 | #ifdef CONFIG_X86_64 |
| 120 | cpu_pda(i)->data_offset = ptr - __per_cpu_start; |
| 121 | #else |
| 122 | __per_cpu_offset[i] = ptr - __per_cpu_start; |
| 123 | #endif |
| 124 | memcpy(ptr, __per_cpu_start, __per_cpu_end - __per_cpu_start); |
Mike Travis | 9f0e8d0 | 2008-04-04 18:11:01 -0700 | [diff] [blame] | 125 | |
| 126 | highest_cpu = i; |
Glauber de Oliveira Costa | 4fe29a8 | 2008-03-19 14:25:23 -0300 | [diff] [blame] | 127 | } |
| 128 | |
Mike Travis | 9f0e8d0 | 2008-04-04 18:11:01 -0700 | [diff] [blame] | 129 | nr_cpu_ids = highest_cpu + 1; |
| 130 | printk(KERN_DEBUG "NR_CPUS: %d, nr_cpu_ids: %d\n", NR_CPUS, nr_cpu_ids); |
| 131 | |
Mike Travis | b447a46 | 2008-03-25 15:06:51 -0700 | [diff] [blame] | 132 | /* Setup percpu data maps */ |
Glauber de Oliveira Costa | 4fe29a8 | 2008-03-19 14:25:23 -0300 | [diff] [blame] | 133 | setup_per_cpu_maps(); |
Mike Travis | 9f0e8d0 | 2008-04-04 18:11:01 -0700 | [diff] [blame] | 134 | |
| 135 | /* Setup cpumask_of_cpu map */ |
| 136 | setup_cpumask_of_cpu(); |
Glauber de Oliveira Costa | 4fe29a8 | 2008-03-19 14:25:23 -0300 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | #endif |
Huang, Ying | c45a707 | 2008-06-02 14:26:25 +0800 | [diff] [blame^] | 140 | |
| 141 | void __init parse_setup_data(void) |
| 142 | { |
| 143 | struct setup_data *data; |
| 144 | u64 pa_data; |
| 145 | |
| 146 | if (boot_params.hdr.version < 0x0209) |
| 147 | return; |
| 148 | pa_data = boot_params.hdr.setup_data; |
| 149 | while (pa_data) { |
| 150 | data = early_ioremap(pa_data, PAGE_SIZE); |
| 151 | switch (data->type) { |
| 152 | default: |
| 153 | break; |
| 154 | } |
| 155 | #ifndef CONFIG_DEBUG_BOOT_PARAMS |
| 156 | free_early(pa_data, pa_data+sizeof(*data)+data->len); |
| 157 | #endif |
| 158 | pa_data = data->next; |
| 159 | early_iounmap(data, PAGE_SIZE); |
| 160 | } |
| 161 | } |