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> |
Bernhard Walle | 1ecd276 | 2008-06-20 15:38:22 +0200 | [diff] [blame] | 6 | #include <linux/kexec.h> |
Yinghai Lu | 17b4cce | 2008-06-21 21:02:20 -0700 | [diff] [blame^] | 7 | #include <linux/crash_dump.h> |
Glauber de Oliveira Costa | 4fe29a8 | 2008-03-19 14:25:23 -0300 | [diff] [blame] | 8 | #include <asm/smp.h> |
| 9 | #include <asm/percpu.h> |
| 10 | #include <asm/sections.h> |
| 11 | #include <asm/processor.h> |
| 12 | #include <asm/setup.h> |
| 13 | #include <asm/topology.h> |
Alexey Starikovskiy | 0fc0906 | 2008-04-04 23:40:48 +0400 | [diff] [blame] | 14 | #include <asm/mpspec.h> |
Alexey Starikovskiy | 76eb413 | 2008-04-04 23:40:41 +0400 | [diff] [blame] | 15 | #include <asm/apicdef.h> |
Bernhard Walle | 1ecd276 | 2008-06-20 15:38:22 +0200 | [diff] [blame] | 16 | #include <asm/highmem.h> |
Alexey Starikovskiy | 76eb413 | 2008-04-04 23:40:41 +0400 | [diff] [blame] | 17 | |
James Bottomley | f8955eb | 2008-05-10 09:01:48 -0500 | [diff] [blame] | 18 | #ifdef CONFIG_X86_LOCAL_APIC |
Alexey Starikovskiy | 2fe6014 | 2008-04-04 23:41:44 +0400 | [diff] [blame] | 19 | unsigned int num_processors; |
| 20 | unsigned disabled_cpus __cpuinitdata; |
| 21 | /* Processor that is doing the boot up */ |
| 22 | unsigned int boot_cpu_physical_apicid = -1U; |
Yinghai Lu | e0da336 | 2008-06-08 18:29:22 -0700 | [diff] [blame] | 23 | unsigned int max_physical_apicid; |
Alexey Starikovskiy | 2fe6014 | 2008-04-04 23:41:44 +0400 | [diff] [blame] | 24 | EXPORT_SYMBOL(boot_cpu_physical_apicid); |
| 25 | |
Alexey Starikovskiy | 0fc0906 | 2008-04-04 23:40:48 +0400 | [diff] [blame] | 26 | /* Bitmask of physically existing CPUs */ |
| 27 | physid_mask_t phys_cpu_present_map; |
James Bottomley | f8955eb | 2008-05-10 09:01:48 -0500 | [diff] [blame] | 28 | #endif |
Alexey Starikovskiy | 0fc0906 | 2008-04-04 23:40:48 +0400 | [diff] [blame] | 29 | |
Mike Travis | 23ca4bb | 2008-05-12 21:21:12 +0200 | [diff] [blame] | 30 | /* map cpu index to physical APIC ID */ |
| 31 | DEFINE_EARLY_PER_CPU(u16, x86_cpu_to_apicid, BAD_APICID); |
| 32 | DEFINE_EARLY_PER_CPU(u16, x86_bios_cpu_apicid, BAD_APICID); |
| 33 | EXPORT_EARLY_PER_CPU_SYMBOL(x86_cpu_to_apicid); |
| 34 | EXPORT_EARLY_PER_CPU_SYMBOL(x86_bios_cpu_apicid); |
| 35 | |
| 36 | #if defined(CONFIG_NUMA) && defined(CONFIG_X86_64) |
| 37 | #define X86_64_NUMA 1 |
| 38 | |
Mike Travis | 7891a24 | 2008-05-12 21:21:12 +0200 | [diff] [blame] | 39 | /* map cpu index to node index */ |
Mike Travis | 23ca4bb | 2008-05-12 21:21:12 +0200 | [diff] [blame] | 40 | DEFINE_EARLY_PER_CPU(int, x86_cpu_to_node_map, NUMA_NO_NODE); |
| 41 | EXPORT_EARLY_PER_CPU_SYMBOL(x86_cpu_to_node_map); |
Mike Travis | 9f248bd | 2008-05-12 21:21:12 +0200 | [diff] [blame] | 42 | |
| 43 | /* which logical CPUs are on which nodes */ |
| 44 | cpumask_t *node_to_cpumask_map; |
| 45 | EXPORT_SYMBOL(node_to_cpumask_map); |
| 46 | |
| 47 | /* setup node_to_cpumask_map */ |
| 48 | static void __init setup_node_to_cpumask_map(void); |
| 49 | |
| 50 | #else |
| 51 | static inline void setup_node_to_cpumask_map(void) { } |
Mike Travis | 23ca4bb | 2008-05-12 21:21:12 +0200 | [diff] [blame] | 52 | #endif |
| 53 | |
James Bottomley | f8955eb | 2008-05-10 09:01:48 -0500 | [diff] [blame] | 54 | #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] | 55 | /* |
| 56 | * Copy data used in early init routines from the initial arrays to the |
| 57 | * per cpu data areas. These arrays then become expendable and the |
| 58 | * *_early_ptr's are zeroed indicating that the static arrays are gone. |
| 59 | */ |
| 60 | static void __init setup_per_cpu_maps(void) |
| 61 | { |
| 62 | int cpu; |
| 63 | |
| 64 | for_each_possible_cpu(cpu) { |
Mike Travis | 23ca4bb | 2008-05-12 21:21:12 +0200 | [diff] [blame] | 65 | per_cpu(x86_cpu_to_apicid, cpu) = |
| 66 | early_per_cpu_map(x86_cpu_to_apicid, cpu); |
Mike Travis | b447a46 | 2008-03-25 15:06:51 -0700 | [diff] [blame] | 67 | per_cpu(x86_bios_cpu_apicid, cpu) = |
Mike Travis | 23ca4bb | 2008-05-12 21:21:12 +0200 | [diff] [blame] | 68 | early_per_cpu_map(x86_bios_cpu_apicid, cpu); |
| 69 | #ifdef X86_64_NUMA |
Mike Travis | b447a46 | 2008-03-25 15:06:51 -0700 | [diff] [blame] | 70 | per_cpu(x86_cpu_to_node_map, cpu) = |
Mike Travis | 23ca4bb | 2008-05-12 21:21:12 +0200 | [diff] [blame] | 71 | early_per_cpu_map(x86_cpu_to_node_map, cpu); |
Glauber de Oliveira Costa | 4fe29a8 | 2008-03-19 14:25:23 -0300 | [diff] [blame] | 72 | #endif |
Glauber de Oliveira Costa | 4fe29a8 | 2008-03-19 14:25:23 -0300 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | /* indicate the early static arrays will soon be gone */ |
Mike Travis | 23ca4bb | 2008-05-12 21:21:12 +0200 | [diff] [blame] | 76 | early_per_cpu_ptr(x86_cpu_to_apicid) = NULL; |
| 77 | early_per_cpu_ptr(x86_bios_cpu_apicid) = NULL; |
| 78 | #ifdef X86_64_NUMA |
| 79 | early_per_cpu_ptr(x86_cpu_to_node_map) = NULL; |
Glauber de Oliveira Costa | 4fe29a8 | 2008-03-19 14:25:23 -0300 | [diff] [blame] | 80 | #endif |
| 81 | } |
| 82 | |
Mike Travis | 9f0e8d0 | 2008-04-04 18:11:01 -0700 | [diff] [blame] | 83 | #ifdef CONFIG_HAVE_CPUMASK_OF_CPU_MAP |
| 84 | cpumask_t *cpumask_of_cpu_map __read_mostly; |
| 85 | EXPORT_SYMBOL(cpumask_of_cpu_map); |
| 86 | |
| 87 | /* requires nr_cpu_ids to be initialized */ |
| 88 | static void __init setup_cpumask_of_cpu(void) |
| 89 | { |
| 90 | int i; |
| 91 | |
| 92 | /* alloc_bootmem zeroes memory */ |
| 93 | cpumask_of_cpu_map = alloc_bootmem_low(sizeof(cpumask_t) * nr_cpu_ids); |
| 94 | for (i = 0; i < nr_cpu_ids; i++) |
| 95 | cpu_set(i, cpumask_of_cpu_map[i]); |
| 96 | } |
| 97 | #else |
| 98 | static inline void setup_cpumask_of_cpu(void) { } |
| 99 | #endif |
| 100 | |
Glauber de Oliveira Costa | 4fe29a8 | 2008-03-19 14:25:23 -0300 | [diff] [blame] | 101 | #ifdef CONFIG_X86_32 |
| 102 | /* |
| 103 | * Great future not-so-futuristic plan: make i386 and x86_64 do it |
| 104 | * the same way |
| 105 | */ |
| 106 | unsigned long __per_cpu_offset[NR_CPUS] __read_mostly; |
| 107 | EXPORT_SYMBOL(__per_cpu_offset); |
Mike Travis | 3461b0a | 2008-05-12 21:21:13 +0200 | [diff] [blame] | 108 | static inline void setup_cpu_pda_map(void) { } |
| 109 | |
| 110 | #elif !defined(CONFIG_SMP) |
| 111 | static inline void setup_cpu_pda_map(void) { } |
| 112 | |
| 113 | #else /* CONFIG_SMP && CONFIG_X86_64 */ |
| 114 | |
| 115 | /* |
| 116 | * Allocate cpu_pda pointer table and array via alloc_bootmem. |
| 117 | */ |
| 118 | static void __init setup_cpu_pda_map(void) |
| 119 | { |
| 120 | char *pda; |
| 121 | struct x8664_pda **new_cpu_pda; |
| 122 | unsigned long size; |
| 123 | int cpu; |
| 124 | |
| 125 | size = roundup(sizeof(struct x8664_pda), cache_line_size()); |
| 126 | |
| 127 | /* allocate cpu_pda array and pointer table */ |
| 128 | { |
| 129 | unsigned long tsize = nr_cpu_ids * sizeof(void *); |
| 130 | unsigned long asize = size * (nr_cpu_ids - 1); |
| 131 | |
| 132 | tsize = roundup(tsize, cache_line_size()); |
| 133 | new_cpu_pda = alloc_bootmem(tsize + asize); |
| 134 | pda = (char *)new_cpu_pda + tsize; |
| 135 | } |
| 136 | |
| 137 | /* initialize pointer table to static pda's */ |
| 138 | for_each_possible_cpu(cpu) { |
| 139 | if (cpu == 0) { |
| 140 | /* leave boot cpu pda in place */ |
| 141 | new_cpu_pda[0] = cpu_pda(0); |
| 142 | continue; |
| 143 | } |
| 144 | new_cpu_pda[cpu] = (struct x8664_pda *)pda; |
| 145 | new_cpu_pda[cpu]->in_bootmem = 1; |
| 146 | pda += size; |
| 147 | } |
| 148 | |
| 149 | /* point to new pointer table */ |
| 150 | _cpu_pda = new_cpu_pda; |
| 151 | } |
Glauber de Oliveira Costa | 4fe29a8 | 2008-03-19 14:25:23 -0300 | [diff] [blame] | 152 | #endif |
| 153 | |
| 154 | /* |
| 155 | * Great future plan: |
| 156 | * Declare PDA itself and support (irqstack,tss,pgd) as per cpu data. |
| 157 | * Always point %gs to its beginning |
| 158 | */ |
| 159 | void __init setup_per_cpu_areas(void) |
| 160 | { |
Mike Travis | 3461b0a | 2008-05-12 21:21:13 +0200 | [diff] [blame] | 161 | ssize_t size = PERCPU_ENOUGH_ROOM; |
| 162 | char *ptr; |
| 163 | int cpu; |
Glauber de Oliveira Costa | 4fe29a8 | 2008-03-19 14:25:23 -0300 | [diff] [blame] | 164 | |
Yinghai Lu | 3c999f1 | 2008-06-20 16:11:20 -0700 | [diff] [blame] | 165 | /* no processor from mptable or madt */ |
| 166 | if (!num_processors) |
| 167 | num_processors = 1; |
| 168 | |
Glauber de Oliveira Costa | 4fe29a8 | 2008-03-19 14:25:23 -0300 | [diff] [blame] | 169 | #ifdef CONFIG_HOTPLUG_CPU |
| 170 | prefill_possible_map(); |
Mike Travis | 3461b0a | 2008-05-12 21:21:13 +0200 | [diff] [blame] | 171 | #else |
| 172 | nr_cpu_ids = num_processors; |
Glauber de Oliveira Costa | 4fe29a8 | 2008-03-19 14:25:23 -0300 | [diff] [blame] | 173 | #endif |
| 174 | |
Mike Travis | 3461b0a | 2008-05-12 21:21:13 +0200 | [diff] [blame] | 175 | /* Setup cpu_pda map */ |
| 176 | setup_cpu_pda_map(); |
| 177 | |
Glauber de Oliveira Costa | 4fe29a8 | 2008-03-19 14:25:23 -0300 | [diff] [blame] | 178 | /* Copy section for each CPU (we discard the original) */ |
| 179 | size = PERCPU_ENOUGH_ROOM; |
Randy Dunlap | 053713f | 2008-06-05 11:10:59 -0700 | [diff] [blame] | 180 | printk(KERN_INFO "PERCPU: Allocating %zd bytes of per cpu data\n", |
Glauber de Oliveira Costa | 4fe29a8 | 2008-03-19 14:25:23 -0300 | [diff] [blame] | 181 | size); |
Mike Travis | b447a46 | 2008-03-25 15:06:51 -0700 | [diff] [blame] | 182 | |
Mike Travis | 3461b0a | 2008-05-12 21:21:13 +0200 | [diff] [blame] | 183 | for_each_possible_cpu(cpu) { |
Glauber de Oliveira Costa | 4fe29a8 | 2008-03-19 14:25:23 -0300 | [diff] [blame] | 184 | #ifndef CONFIG_NEED_MULTIPLE_NODES |
| 185 | ptr = alloc_bootmem_pages(size); |
| 186 | #else |
Mike Travis | 3461b0a | 2008-05-12 21:21:13 +0200 | [diff] [blame] | 187 | int node = early_cpu_to_node(cpu); |
Mike Travis | b447a46 | 2008-03-25 15:06:51 -0700 | [diff] [blame] | 188 | if (!node_online(node) || !NODE_DATA(node)) { |
Glauber de Oliveira Costa | 4fe29a8 | 2008-03-19 14:25:23 -0300 | [diff] [blame] | 189 | ptr = alloc_bootmem_pages(size); |
Mike Travis | b447a46 | 2008-03-25 15:06:51 -0700 | [diff] [blame] | 190 | printk(KERN_INFO |
Mike Travis | 23ca4bb | 2008-05-12 21:21:12 +0200 | [diff] [blame] | 191 | "cpu %d has no node %d or node-local memory\n", |
Mike Travis | 3461b0a | 2008-05-12 21:21:13 +0200 | [diff] [blame] | 192 | cpu, node); |
Mike Travis | b447a46 | 2008-03-25 15:06:51 -0700 | [diff] [blame] | 193 | } |
Glauber de Oliveira Costa | 4fe29a8 | 2008-03-19 14:25:23 -0300 | [diff] [blame] | 194 | else |
| 195 | ptr = alloc_bootmem_pages_node(NODE_DATA(node), size); |
| 196 | #endif |
Mike Travis | 3461b0a | 2008-05-12 21:21:13 +0200 | [diff] [blame] | 197 | per_cpu_offset(cpu) = ptr - __per_cpu_start; |
Glauber de Oliveira Costa | 4fe29a8 | 2008-03-19 14:25:23 -0300 | [diff] [blame] | 198 | memcpy(ptr, __per_cpu_start, __per_cpu_end - __per_cpu_start); |
Mike Travis | 9f0e8d0 | 2008-04-04 18:11:01 -0700 | [diff] [blame] | 199 | |
Glauber de Oliveira Costa | 4fe29a8 | 2008-03-19 14:25:23 -0300 | [diff] [blame] | 200 | } |
| 201 | |
Mike Travis | 9f248bd | 2008-05-12 21:21:12 +0200 | [diff] [blame] | 202 | printk(KERN_DEBUG "NR_CPUS: %d, nr_cpu_ids: %d, nr_node_ids %d\n", |
| 203 | NR_CPUS, nr_cpu_ids, nr_node_ids); |
Mike Travis | 9f0e8d0 | 2008-04-04 18:11:01 -0700 | [diff] [blame] | 204 | |
Mike Travis | b447a46 | 2008-03-25 15:06:51 -0700 | [diff] [blame] | 205 | /* Setup percpu data maps */ |
Glauber de Oliveira Costa | 4fe29a8 | 2008-03-19 14:25:23 -0300 | [diff] [blame] | 206 | setup_per_cpu_maps(); |
Mike Travis | 9f0e8d0 | 2008-04-04 18:11:01 -0700 | [diff] [blame] | 207 | |
Mike Travis | 9f248bd | 2008-05-12 21:21:12 +0200 | [diff] [blame] | 208 | /* Setup node to cpumask map */ |
| 209 | setup_node_to_cpumask_map(); |
| 210 | |
Mike Travis | 9f0e8d0 | 2008-04-04 18:11:01 -0700 | [diff] [blame] | 211 | /* Setup cpumask_of_cpu map */ |
| 212 | setup_cpumask_of_cpu(); |
Glauber de Oliveira Costa | 4fe29a8 | 2008-03-19 14:25:23 -0300 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | #endif |
Huang, Ying | c45a707 | 2008-06-02 14:26:25 +0800 | [diff] [blame] | 216 | |
| 217 | void __init parse_setup_data(void) |
| 218 | { |
| 219 | struct setup_data *data; |
| 220 | u64 pa_data; |
| 221 | |
| 222 | if (boot_params.hdr.version < 0x0209) |
| 223 | return; |
| 224 | pa_data = boot_params.hdr.setup_data; |
| 225 | while (pa_data) { |
| 226 | data = early_ioremap(pa_data, PAGE_SIZE); |
| 227 | switch (data->type) { |
Huang, Ying | 8c5beb5 | 2008-06-11 11:33:39 +0800 | [diff] [blame] | 228 | case SETUP_E820_EXT: |
| 229 | parse_e820_ext(data, pa_data); |
| 230 | break; |
Huang, Ying | c45a707 | 2008-06-02 14:26:25 +0800 | [diff] [blame] | 231 | default: |
| 232 | break; |
| 233 | } |
| 234 | #ifndef CONFIG_DEBUG_BOOT_PARAMS |
| 235 | free_early(pa_data, pa_data+sizeof(*data)+data->len); |
| 236 | #endif |
| 237 | pa_data = data->next; |
| 238 | early_iounmap(data, PAGE_SIZE); |
| 239 | } |
| 240 | } |
Ingo Molnar | 2b4fa85 | 2008-07-08 11:59:23 +0200 | [diff] [blame] | 241 | |
Mike Travis | 23ca4bb | 2008-05-12 21:21:12 +0200 | [diff] [blame] | 242 | #ifdef X86_64_NUMA |
Mike Travis | 9f248bd | 2008-05-12 21:21:12 +0200 | [diff] [blame] | 243 | |
| 244 | /* |
| 245 | * Allocate node_to_cpumask_map based on number of available nodes |
| 246 | * Requires node_possible_map to be valid. |
| 247 | * |
| 248 | * Note: node_to_cpumask() is not valid until after this is done. |
| 249 | */ |
| 250 | static void __init setup_node_to_cpumask_map(void) |
| 251 | { |
| 252 | unsigned int node, num = 0; |
| 253 | cpumask_t *map; |
| 254 | |
| 255 | /* setup nr_node_ids if not done yet */ |
| 256 | if (nr_node_ids == MAX_NUMNODES) { |
| 257 | for_each_node_mask(node, node_possible_map) |
| 258 | num = node; |
| 259 | nr_node_ids = num + 1; |
| 260 | } |
| 261 | |
| 262 | /* allocate the map */ |
| 263 | map = alloc_bootmem_low(nr_node_ids * sizeof(cpumask_t)); |
| 264 | |
| 265 | Dprintk(KERN_DEBUG "Node to cpumask map at %p for %d nodes\n", |
| 266 | map, nr_node_ids); |
| 267 | |
| 268 | /* node_to_cpumask() will now work */ |
| 269 | node_to_cpumask_map = map; |
| 270 | } |
| 271 | |
Mike Travis | 23ca4bb | 2008-05-12 21:21:12 +0200 | [diff] [blame] | 272 | void __cpuinit numa_set_node(int cpu, int node) |
| 273 | { |
| 274 | int *cpu_to_node_map = early_per_cpu_ptr(x86_cpu_to_node_map); |
| 275 | |
Mike Travis | 3461b0a | 2008-05-12 21:21:13 +0200 | [diff] [blame] | 276 | if (cpu_pda(cpu) && node != NUMA_NO_NODE) |
Mike Travis | 7891a24 | 2008-05-12 21:21:12 +0200 | [diff] [blame] | 277 | cpu_pda(cpu)->nodenumber = node; |
| 278 | |
Mike Travis | 23ca4bb | 2008-05-12 21:21:12 +0200 | [diff] [blame] | 279 | if (cpu_to_node_map) |
| 280 | cpu_to_node_map[cpu] = node; |
| 281 | |
| 282 | else if (per_cpu_offset(cpu)) |
| 283 | per_cpu(x86_cpu_to_node_map, cpu) = node; |
| 284 | |
| 285 | else |
| 286 | Dprintk(KERN_INFO "Setting node for non-present cpu %d\n", cpu); |
| 287 | } |
| 288 | |
| 289 | void __cpuinit numa_clear_node(int cpu) |
| 290 | { |
| 291 | numa_set_node(cpu, NUMA_NO_NODE); |
| 292 | } |
| 293 | |
Mike Travis | 9f248bd | 2008-05-12 21:21:12 +0200 | [diff] [blame] | 294 | #ifndef CONFIG_DEBUG_PER_CPU_MAPS |
| 295 | |
Mike Travis | 23ca4bb | 2008-05-12 21:21:12 +0200 | [diff] [blame] | 296 | void __cpuinit numa_add_cpu(int cpu) |
| 297 | { |
| 298 | cpu_set(cpu, node_to_cpumask_map[early_cpu_to_node(cpu)]); |
| 299 | } |
| 300 | |
| 301 | void __cpuinit numa_remove_cpu(int cpu) |
| 302 | { |
| 303 | cpu_clear(cpu, node_to_cpumask_map[cpu_to_node(cpu)]); |
| 304 | } |
Mike Travis | 23ca4bb | 2008-05-12 21:21:12 +0200 | [diff] [blame] | 305 | |
Mike Travis | 9f248bd | 2008-05-12 21:21:12 +0200 | [diff] [blame] | 306 | #else /* CONFIG_DEBUG_PER_CPU_MAPS */ |
| 307 | |
| 308 | /* |
| 309 | * --------- debug versions of the numa functions --------- |
| 310 | */ |
| 311 | static void __cpuinit numa_set_cpumask(int cpu, int enable) |
| 312 | { |
| 313 | int node = cpu_to_node(cpu); |
| 314 | cpumask_t *mask; |
| 315 | char buf[64]; |
| 316 | |
| 317 | if (node_to_cpumask_map == NULL) { |
| 318 | printk(KERN_ERR "node_to_cpumask_map NULL\n"); |
| 319 | dump_stack(); |
| 320 | return; |
| 321 | } |
| 322 | |
| 323 | mask = &node_to_cpumask_map[node]; |
| 324 | if (enable) |
| 325 | cpu_set(cpu, *mask); |
| 326 | else |
| 327 | cpu_clear(cpu, *mask); |
| 328 | |
| 329 | cpulist_scnprintf(buf, sizeof(buf), *mask); |
| 330 | printk(KERN_DEBUG "%s cpu %d node %d: mask now %s\n", |
| 331 | enable? "numa_add_cpu":"numa_remove_cpu", cpu, node, buf); |
| 332 | } |
| 333 | |
| 334 | void __cpuinit numa_add_cpu(int cpu) |
| 335 | { |
| 336 | numa_set_cpumask(cpu, 1); |
| 337 | } |
| 338 | |
| 339 | void __cpuinit numa_remove_cpu(int cpu) |
| 340 | { |
| 341 | numa_set_cpumask(cpu, 0); |
| 342 | } |
Mike Travis | 23ca4bb | 2008-05-12 21:21:12 +0200 | [diff] [blame] | 343 | |
| 344 | int cpu_to_node(int cpu) |
| 345 | { |
| 346 | if (early_per_cpu_ptr(x86_cpu_to_node_map)) { |
| 347 | printk(KERN_WARNING |
| 348 | "cpu_to_node(%d): usage too early!\n", cpu); |
| 349 | dump_stack(); |
| 350 | return early_per_cpu_ptr(x86_cpu_to_node_map)[cpu]; |
| 351 | } |
| 352 | return per_cpu(x86_cpu_to_node_map, cpu); |
| 353 | } |
| 354 | EXPORT_SYMBOL(cpu_to_node); |
| 355 | |
Mike Travis | 9f248bd | 2008-05-12 21:21:12 +0200 | [diff] [blame] | 356 | /* |
| 357 | * Same function as cpu_to_node() but used if called before the |
| 358 | * per_cpu areas are setup. |
| 359 | */ |
Mike Travis | 23ca4bb | 2008-05-12 21:21:12 +0200 | [diff] [blame] | 360 | int early_cpu_to_node(int cpu) |
| 361 | { |
| 362 | if (early_per_cpu_ptr(x86_cpu_to_node_map)) |
| 363 | return early_per_cpu_ptr(x86_cpu_to_node_map)[cpu]; |
| 364 | |
| 365 | if (!per_cpu_offset(cpu)) { |
| 366 | printk(KERN_WARNING |
| 367 | "early_cpu_to_node(%d): no per_cpu area!\n", cpu); |
Mike Travis | 9f248bd | 2008-05-12 21:21:12 +0200 | [diff] [blame] | 368 | dump_stack(); |
Mike Travis | 23ca4bb | 2008-05-12 21:21:12 +0200 | [diff] [blame] | 369 | return NUMA_NO_NODE; |
| 370 | } |
| 371 | return per_cpu(x86_cpu_to_node_map, cpu); |
| 372 | } |
Mike Travis | 9f248bd | 2008-05-12 21:21:12 +0200 | [diff] [blame] | 373 | |
| 374 | /* |
| 375 | * Returns a pointer to the bitmask of CPUs on Node 'node'. |
| 376 | */ |
| 377 | cpumask_t *_node_to_cpumask_ptr(int node) |
| 378 | { |
| 379 | if (node_to_cpumask_map == NULL) { |
| 380 | printk(KERN_WARNING |
| 381 | "_node_to_cpumask_ptr(%d): no node_to_cpumask_map!\n", |
| 382 | node); |
| 383 | dump_stack(); |
| 384 | return &cpu_online_map; |
| 385 | } |
Vegard Nossum | 03db1f7 | 2008-06-06 16:33:25 +0200 | [diff] [blame] | 386 | BUG_ON(node >= nr_node_ids); |
Mike Travis | 9f248bd | 2008-05-12 21:21:12 +0200 | [diff] [blame] | 387 | return &node_to_cpumask_map[node]; |
| 388 | } |
| 389 | EXPORT_SYMBOL(_node_to_cpumask_ptr); |
| 390 | |
| 391 | /* |
| 392 | * Returns a bitmask of CPUs on Node 'node'. |
| 393 | */ |
| 394 | cpumask_t node_to_cpumask(int node) |
| 395 | { |
| 396 | if (node_to_cpumask_map == NULL) { |
| 397 | printk(KERN_WARNING |
| 398 | "node_to_cpumask(%d): no node_to_cpumask_map!\n", node); |
| 399 | dump_stack(); |
| 400 | return cpu_online_map; |
| 401 | } |
Vegard Nossum | 03db1f7 | 2008-06-06 16:33:25 +0200 | [diff] [blame] | 402 | BUG_ON(node >= nr_node_ids); |
Mike Travis | 9f248bd | 2008-05-12 21:21:12 +0200 | [diff] [blame] | 403 | return node_to_cpumask_map[node]; |
| 404 | } |
| 405 | EXPORT_SYMBOL(node_to_cpumask); |
| 406 | |
| 407 | /* |
| 408 | * --------- end of debug versions of the numa functions --------- |
| 409 | */ |
| 410 | |
| 411 | #endif /* CONFIG_DEBUG_PER_CPU_MAPS */ |
| 412 | |
| 413 | #endif /* X86_64_NUMA */ |
Bernhard Walle | 1ecd276 | 2008-06-20 15:38:22 +0200 | [diff] [blame] | 414 | |
| 415 | |
| 416 | /* |
| 417 | * --------- Crashkernel reservation ------------------------------ |
| 418 | */ |
| 419 | |
| 420 | static inline unsigned long long get_total_mem(void) |
| 421 | { |
| 422 | unsigned long long total; |
| 423 | |
| 424 | total = max_low_pfn - min_low_pfn; |
| 425 | #ifdef CONFIG_HIGHMEM |
| 426 | total += highend_pfn - highstart_pfn; |
| 427 | #endif |
| 428 | |
| 429 | return total << PAGE_SHIFT; |
| 430 | } |
| 431 | |
| 432 | #ifdef CONFIG_KEXEC |
| 433 | void __init reserve_crashkernel(void) |
| 434 | { |
| 435 | unsigned long long total_mem; |
| 436 | unsigned long long crash_size, crash_base; |
| 437 | int ret; |
| 438 | |
| 439 | total_mem = get_total_mem(); |
| 440 | |
| 441 | ret = parse_crashkernel(boot_command_line, total_mem, |
| 442 | &crash_size, &crash_base); |
| 443 | if (ret == 0 && crash_size > 0) { |
| 444 | if (crash_base <= 0) { |
| 445 | printk(KERN_INFO "crashkernel reservation failed - " |
| 446 | "you have to specify a base address\n"); |
| 447 | return; |
| 448 | } |
| 449 | |
| 450 | if (reserve_bootmem_generic(crash_base, crash_size, |
| 451 | BOOTMEM_EXCLUSIVE) < 0) { |
| 452 | printk(KERN_INFO "crashkernel reservation failed - " |
| 453 | "memory is in use\n"); |
| 454 | return; |
| 455 | } |
| 456 | |
| 457 | printk(KERN_INFO "Reserving %ldMB of memory at %ldMB " |
| 458 | "for crashkernel (System RAM: %ldMB)\n", |
| 459 | (unsigned long)(crash_size >> 20), |
| 460 | (unsigned long)(crash_base >> 20), |
| 461 | (unsigned long)(total_mem >> 20)); |
| 462 | |
| 463 | crashk_res.start = crash_base; |
| 464 | crashk_res.end = crash_base + crash_size - 1; |
| 465 | insert_resource(&iomem_resource, &crashk_res); |
| 466 | } |
| 467 | } |
| 468 | #else |
| 469 | void __init reserve_crashkernel(void) |
| 470 | {} |
| 471 | #endif |
Yinghai Lu | ce97c40 | 2008-06-21 20:22:09 -0700 | [diff] [blame] | 472 | static struct resource standard_io_resources[] = { |
| 473 | { .name = "dma1", .start = 0x00, .end = 0x1f, |
| 474 | .flags = IORESOURCE_BUSY | IORESOURCE_IO }, |
| 475 | { .name = "pic1", .start = 0x20, .end = 0x21, |
| 476 | .flags = IORESOURCE_BUSY | IORESOURCE_IO }, |
| 477 | { .name = "timer0", .start = 0x40, .end = 0x43, |
| 478 | .flags = IORESOURCE_BUSY | IORESOURCE_IO }, |
| 479 | { .name = "timer1", .start = 0x50, .end = 0x53, |
| 480 | .flags = IORESOURCE_BUSY | IORESOURCE_IO }, |
| 481 | { .name = "keyboard", .start = 0x60, .end = 0x60, |
| 482 | .flags = IORESOURCE_BUSY | IORESOURCE_IO }, |
| 483 | { .name = "keyboard", .start = 0x64, .end = 0x64, |
| 484 | .flags = IORESOURCE_BUSY | IORESOURCE_IO }, |
| 485 | { .name = "dma page reg", .start = 0x80, .end = 0x8f, |
| 486 | .flags = IORESOURCE_BUSY | IORESOURCE_IO }, |
| 487 | { .name = "pic2", .start = 0xa0, .end = 0xa1, |
| 488 | .flags = IORESOURCE_BUSY | IORESOURCE_IO }, |
| 489 | { .name = "dma2", .start = 0xc0, .end = 0xdf, |
| 490 | .flags = IORESOURCE_BUSY | IORESOURCE_IO }, |
| 491 | { .name = "fpu", .start = 0xf0, .end = 0xff, |
| 492 | .flags = IORESOURCE_BUSY | IORESOURCE_IO } |
| 493 | }; |
| 494 | |
| 495 | void __init reserve_standard_io_resources(void) |
| 496 | { |
| 497 | int i; |
| 498 | |
| 499 | /* request I/O space for devices used on all i[345]86 PCs */ |
| 500 | for (i = 0; i < ARRAY_SIZE(standard_io_resources); i++) |
| 501 | request_resource(&ioport_resource, &standard_io_resources[i]); |
| 502 | |
| 503 | } |
Bernhard Walle | 1ecd276 | 2008-06-20 15:38:22 +0200 | [diff] [blame] | 504 | |
Yinghai Lu | 17b4cce | 2008-06-21 21:02:20 -0700 | [diff] [blame^] | 505 | #ifdef CONFIG_PROC_VMCORE |
| 506 | /* elfcorehdr= specifies the location of elf core header |
| 507 | * stored by the crashed kernel. This option will be passed |
| 508 | * by kexec loader to the capture kernel. |
| 509 | */ |
| 510 | static int __init setup_elfcorehdr(char *arg) |
| 511 | { |
| 512 | char *end; |
| 513 | if (!arg) |
| 514 | return -EINVAL; |
| 515 | elfcorehdr_addr = memparse(arg, &end); |
| 516 | return end > arg ? 0 : -EINVAL; |
| 517 | } |
| 518 | early_param("elfcorehdr", setup_elfcorehdr); |
| 519 | #endif |
| 520 | |
| 521 | |
| 522 | |