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> |
Jaswinder Singh Rajput | 8a87dd9 | 2009-01-04 17:04:26 +0530 | [diff] [blame] | 8 | #include <linux/smp.h> |
| 9 | #include <linux/topology.h> |
Glauber de Oliveira Costa | 4fe29a8 | 2008-03-19 14:25:23 -0300 | [diff] [blame] | 10 | #include <asm/sections.h> |
| 11 | #include <asm/processor.h> |
| 12 | #include <asm/setup.h> |
Alexey Starikovskiy | 0fc0906 | 2008-04-04 23:40:48 +0400 | [diff] [blame] | 13 | #include <asm/mpspec.h> |
Alexey Starikovskiy | 76eb413 | 2008-04-04 23:40:41 +0400 | [diff] [blame] | 14 | #include <asm/apicdef.h> |
Bernhard Walle | 1ecd276 | 2008-06-20 15:38:22 +0200 | [diff] [blame] | 15 | #include <asm/highmem.h> |
Tejun Heo | 1a51e3a | 2009-01-13 20:41:35 +0900 | [diff] [blame] | 16 | #include <asm/proto.h> |
Jaswinder Singh Rajput | 0687903 | 2009-01-10 12:17:37 +0530 | [diff] [blame] | 17 | #include <asm/cpumask.h> |
Alexey Starikovskiy | 76eb413 | 2008-04-04 23:40:41 +0400 | [diff] [blame] | 18 | |
Mike Travis | c90aa89 | 2009-01-13 20:41:34 +0900 | [diff] [blame] | 19 | #ifdef CONFIG_DEBUG_PER_CPU_MAPS |
| 20 | # define DBG(x...) printk(KERN_DEBUG x) |
| 21 | #else |
| 22 | # define DBG(x...) |
| 23 | #endif |
| 24 | |
Brian Gerst | ea92790 | 2009-01-19 00:38:58 +0900 | [diff] [blame] | 25 | /* |
| 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 |
| 30 | DEFINE_PER_CPU(int, cpu_number); |
| 31 | EXPORT_PER_CPU_SYMBOL(cpu_number); |
| 32 | #endif |
| 33 | |
James Bottomley | f8955eb | 2008-05-10 09:01:48 -0500 | [diff] [blame] | 34 | #ifdef CONFIG_X86_LOCAL_APIC |
Alexey Starikovskiy | 2fe6014 | 2008-04-04 23:41:44 +0400 | [diff] [blame] | 35 | unsigned int num_processors; |
| 36 | unsigned disabled_cpus __cpuinitdata; |
| 37 | /* Processor that is doing the boot up */ |
| 38 | unsigned int boot_cpu_physical_apicid = -1U; |
| 39 | EXPORT_SYMBOL(boot_cpu_physical_apicid); |
Jaswinder Singh Rajput | 8a87dd9 | 2009-01-04 17:04:26 +0530 | [diff] [blame] | 40 | unsigned int max_physical_apicid; |
Alexey Starikovskiy | 2fe6014 | 2008-04-04 23:41:44 +0400 | [diff] [blame] | 41 | |
Alexey Starikovskiy | 0fc0906 | 2008-04-04 23:40:48 +0400 | [diff] [blame] | 42 | /* Bitmask of physically existing CPUs */ |
| 43 | physid_mask_t phys_cpu_present_map; |
James Bottomley | f8955eb | 2008-05-10 09:01:48 -0500 | [diff] [blame] | 44 | #endif |
Alexey Starikovskiy | 0fc0906 | 2008-04-04 23:40:48 +0400 | [diff] [blame] | 45 | |
Mike Travis | c90aa89 | 2009-01-13 20:41:34 +0900 | [diff] [blame] | 46 | /* |
| 47 | * Map cpu index to physical APIC ID |
| 48 | */ |
Mike Travis | 23ca4bb | 2008-05-12 21:21:12 +0200 | [diff] [blame] | 49 | DEFINE_EARLY_PER_CPU(u16, x86_cpu_to_apicid, BAD_APICID); |
| 50 | DEFINE_EARLY_PER_CPU(u16, x86_bios_cpu_apicid, BAD_APICID); |
| 51 | EXPORT_EARLY_PER_CPU_SYMBOL(x86_cpu_to_apicid); |
| 52 | EXPORT_EARLY_PER_CPU_SYMBOL(x86_bios_cpu_apicid); |
| 53 | |
Mike Travis | c90aa89 | 2009-01-13 20:41:34 +0900 | [diff] [blame] | 54 | #ifdef CONFIG_HAVE_SETUP_PER_CPU_AREA |
Glauber de Oliveira Costa | 4fe29a8 | 2008-03-19 14:25:23 -0300 | [diff] [blame] | 55 | |
Tejun Heo | 9939dda | 2009-01-13 20:41:35 +0900 | [diff] [blame] | 56 | #ifdef CONFIG_X86_64 |
| 57 | unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = { |
| 58 | [0] = (unsigned long)__per_cpu_load, |
| 59 | }; |
| 60 | #else |
Glauber de Oliveira Costa | 4fe29a8 | 2008-03-19 14:25:23 -0300 | [diff] [blame] | 61 | unsigned long __per_cpu_offset[NR_CPUS] __read_mostly; |
Tejun Heo | 1a51e3a | 2009-01-13 20:41:35 +0900 | [diff] [blame] | 62 | #endif |
Tejun Heo | 9939dda | 2009-01-13 20:41:35 +0900 | [diff] [blame] | 63 | EXPORT_SYMBOL(__per_cpu_offset); |
Glauber de Oliveira Costa | 4fe29a8 | 2008-03-19 14:25:23 -0300 | [diff] [blame] | 64 | |
| 65 | /* |
| 66 | * Great future plan: |
| 67 | * Declare PDA itself and support (irqstack,tss,pgd) as per cpu data. |
| 68 | * Always point %gs to its beginning |
| 69 | */ |
| 70 | void __init setup_per_cpu_areas(void) |
| 71 | { |
Brian Gerst | 74631a2 | 2009-01-27 12:56:47 +0900 | [diff] [blame^] | 72 | ssize_t size; |
Mike Travis | 3461b0a | 2008-05-12 21:21:13 +0200 | [diff] [blame] | 73 | char *ptr; |
| 74 | int cpu; |
Glauber de Oliveira Costa | 4fe29a8 | 2008-03-19 14:25:23 -0300 | [diff] [blame] | 75 | |
Glauber de Oliveira Costa | 4fe29a8 | 2008-03-19 14:25:23 -0300 | [diff] [blame] | 76 | /* Copy section for each CPU (we discard the original) */ |
Brian Gerst | 74631a2 | 2009-01-27 12:56:47 +0900 | [diff] [blame^] | 77 | size = roundup(PERCPU_ENOUGH_ROOM, PAGE_SIZE); |
Mike Travis | a168196 | 2008-12-16 17:33:53 -0800 | [diff] [blame] | 78 | |
Cyrill Gorcunov | ab14398 | 2009-01-02 21:51:32 +0300 | [diff] [blame] | 79 | pr_info("NR_CPUS:%d nr_cpumask_bits:%d nr_cpu_ids:%d nr_node_ids:%d\n", |
Mike Travis | a168196 | 2008-12-16 17:33:53 -0800 | [diff] [blame] | 80 | NR_CPUS, nr_cpumask_bits, nr_cpu_ids, nr_node_ids); |
| 81 | |
Cyrill Gorcunov | ab14398 | 2009-01-02 21:51:32 +0300 | [diff] [blame] | 82 | pr_info("PERCPU: Allocating %zd bytes of per cpu data\n", size); |
Mike Travis | b447a46 | 2008-03-25 15:06:51 -0700 | [diff] [blame] | 83 | |
Mike Travis | 3461b0a | 2008-05-12 21:21:13 +0200 | [diff] [blame] | 84 | for_each_possible_cpu(cpu) { |
Glauber de Oliveira Costa | 4fe29a8 | 2008-03-19 14:25:23 -0300 | [diff] [blame] | 85 | #ifndef CONFIG_NEED_MULTIPLE_NODES |
Brian Gerst | 74631a2 | 2009-01-27 12:56:47 +0900 | [diff] [blame^] | 86 | ptr = alloc_bootmem_pages(size); |
Glauber de Oliveira Costa | 4fe29a8 | 2008-03-19 14:25:23 -0300 | [diff] [blame] | 87 | #else |
Mike Travis | 3461b0a | 2008-05-12 21:21:13 +0200 | [diff] [blame] | 88 | int node = early_cpu_to_node(cpu); |
Mike Travis | b447a46 | 2008-03-25 15:06:51 -0700 | [diff] [blame] | 89 | if (!node_online(node) || !NODE_DATA(node)) { |
Brian Gerst | 74631a2 | 2009-01-27 12:56:47 +0900 | [diff] [blame^] | 90 | ptr = alloc_bootmem_pages(size); |
Cyrill Gorcunov | ab14398 | 2009-01-02 21:51:32 +0300 | [diff] [blame] | 91 | pr_info("cpu %d has no node %d or node-local memory\n", |
Mike Travis | 3461b0a | 2008-05-12 21:21:13 +0200 | [diff] [blame] | 92 | cpu, node); |
Cyrill Gorcunov | ab14398 | 2009-01-02 21:51:32 +0300 | [diff] [blame] | 93 | pr_debug("per cpu data for cpu%d at %016lx\n", |
| 94 | cpu, __pa(ptr)); |
| 95 | } else { |
Brian Gerst | 74631a2 | 2009-01-27 12:56:47 +0900 | [diff] [blame^] | 96 | ptr = alloc_bootmem_pages_node(NODE_DATA(node), size); |
Cyrill Gorcunov | ab14398 | 2009-01-02 21:51:32 +0300 | [diff] [blame] | 97 | pr_debug("per cpu data for cpu%d on node%d at %016lx\n", |
| 98 | cpu, node, __pa(ptr)); |
Yinghai Lu | a677f58 | 2008-07-29 00:37:10 -0700 | [diff] [blame] | 99 | } |
Glauber de Oliveira Costa | 4fe29a8 | 2008-03-19 14:25:23 -0300 | [diff] [blame] | 100 | #endif |
Tejun Heo | 1a51e3a | 2009-01-13 20:41:35 +0900 | [diff] [blame] | 101 | |
Tejun Heo | 3e5d8f9 | 2009-01-13 20:41:35 +0900 | [diff] [blame] | 102 | memcpy(ptr, __per_cpu_load, __per_cpu_end - __per_cpu_start); |
Tejun Heo | 9939dda | 2009-01-13 20:41:35 +0900 | [diff] [blame] | 103 | per_cpu_offset(cpu) = ptr - __per_cpu_start; |
Brian Gerst | 26f80bd | 2009-01-19 00:38:58 +0900 | [diff] [blame] | 104 | per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu); |
Brian Gerst | ea92790 | 2009-01-19 00:38:58 +0900 | [diff] [blame] | 105 | per_cpu(cpu_number, cpu) = cpu; |
Brian Gerst | 0d77e7f | 2009-01-27 12:56:47 +0900 | [diff] [blame] | 106 | /* |
| 107 | * Copy data used in early init routines from the initial arrays to the |
| 108 | * per cpu data areas. These arrays then become expendable and the |
| 109 | * *_early_ptr's are zeroed indicating that the static arrays are gone. |
| 110 | */ |
| 111 | per_cpu(x86_cpu_to_apicid, cpu) = |
| 112 | early_per_cpu_map(x86_cpu_to_apicid, cpu); |
| 113 | per_cpu(x86_bios_cpu_apicid, cpu) = |
| 114 | early_per_cpu_map(x86_bios_cpu_apicid, cpu); |
Tejun Heo | 1a51e3a | 2009-01-13 20:41:35 +0900 | [diff] [blame] | 115 | #ifdef CONFIG_X86_64 |
Brian Gerst | 26f80bd | 2009-01-19 00:38:58 +0900 | [diff] [blame] | 116 | per_cpu(irq_stack_ptr, cpu) = |
Brian Gerst | 947e76c | 2009-01-19 12:21:28 +0900 | [diff] [blame] | 117 | per_cpu(irq_stack_union.irq_stack, cpu) + IRQ_STACK_SIZE - 64; |
Brian Gerst | 6470aff | 2009-01-27 12:56:47 +0900 | [diff] [blame] | 118 | #ifdef CONFIG_NUMA |
| 119 | per_cpu(x86_cpu_to_node_map, cpu) = |
| 120 | early_per_cpu_map(x86_cpu_to_node_map, cpu); |
| 121 | #endif |
Tejun Heo | 1a51e3a | 2009-01-13 20:41:35 +0900 | [diff] [blame] | 122 | /* |
Brian Gerst | 947e76c | 2009-01-19 12:21:28 +0900 | [diff] [blame] | 123 | * Up to this point, CPU0 has been using .data.init |
| 124 | * area. Reload %gs offset for CPU0. |
Tejun Heo | 1a51e3a | 2009-01-13 20:41:35 +0900 | [diff] [blame] | 125 | */ |
| 126 | if (cpu == 0) |
Brian Gerst | 947e76c | 2009-01-19 12:21:28 +0900 | [diff] [blame] | 127 | load_gs_base(cpu); |
Tejun Heo | 1a51e3a | 2009-01-13 20:41:35 +0900 | [diff] [blame] | 128 | #endif |
Mike Travis | c90aa89 | 2009-01-13 20:41:34 +0900 | [diff] [blame] | 129 | |
| 130 | DBG("PERCPU: cpu %4d %p\n", cpu, ptr); |
Glauber de Oliveira Costa | 4fe29a8 | 2008-03-19 14:25:23 -0300 | [diff] [blame] | 131 | } |
| 132 | |
Brian Gerst | 0d77e7f | 2009-01-27 12:56:47 +0900 | [diff] [blame] | 133 | /* indicate the early static arrays will soon be gone */ |
| 134 | early_per_cpu_ptr(x86_cpu_to_apicid) = NULL; |
| 135 | early_per_cpu_ptr(x86_bios_cpu_apicid) = NULL; |
Brian Gerst | 6470aff | 2009-01-27 12:56:47 +0900 | [diff] [blame] | 136 | #if defined(CONFIG_X86_64) && defined(CONFIG_NUMA) |
Brian Gerst | 0d77e7f | 2009-01-27 12:56:47 +0900 | [diff] [blame] | 137 | early_per_cpu_ptr(x86_cpu_to_node_map) = NULL; |
| 138 | #endif |
Mike Travis | 9f0e8d0 | 2008-04-04 18:11:01 -0700 | [diff] [blame] | 139 | |
Mike Travis | 9f248bd | 2008-05-12 21:21:12 +0200 | [diff] [blame] | 140 | /* Setup node to cpumask map */ |
| 141 | setup_node_to_cpumask_map(); |
Mike Travis | c2d1cec | 2009-01-04 05:18:03 -0800 | [diff] [blame] | 142 | |
| 143 | /* Setup cpu initialized, callin, callout masks */ |
| 144 | setup_cpu_local_masks(); |
Glauber de Oliveira Costa | 4fe29a8 | 2008-03-19 14:25:23 -0300 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | #endif |
Huang, Ying | c45a707 | 2008-06-02 14:26:25 +0800 | [diff] [blame] | 148 | |