Glauber de Oliveira Costa | 4cedb33 | 2008-03-19 14:26:14 -0300 | [diff] [blame] | 1 | /* |
| 2 | * x86 SMP booting functions |
| 3 | * |
Alan Cox | 87c6fe2 | 2009-01-05 14:08:04 +0000 | [diff] [blame] | 4 | * (c) 1995 Alan Cox, Building #3 <alan@lxorguk.ukuu.org.uk> |
Ingo Molnar | 8f47e16 | 2009-01-31 02:03:42 +0100 | [diff] [blame] | 5 | * (c) 1998, 1999, 2000, 2009 Ingo Molnar <mingo@redhat.com> |
Glauber de Oliveira Costa | 4cedb33 | 2008-03-19 14:26:14 -0300 | [diff] [blame] | 6 | * Copyright 2001 Andi Kleen, SuSE Labs. |
| 7 | * |
| 8 | * Much of the core SMP work is based on previous work by Thomas Radke, to |
| 9 | * whom a great many thanks are extended. |
| 10 | * |
| 11 | * Thanks to Intel for making available several different Pentium, |
| 12 | * Pentium Pro and Pentium-II/Xeon MP machines. |
| 13 | * Original development of Linux SMP code supported by Caldera. |
| 14 | * |
| 15 | * This code is released under the GNU General Public License version 2 or |
| 16 | * later. |
| 17 | * |
| 18 | * Fixes |
| 19 | * Felix Koop : NR_CPUS used properly |
| 20 | * Jose Renau : Handle single CPU case. |
| 21 | * Alan Cox : By repeated request 8) - Total BogoMIPS report. |
| 22 | * Greg Wright : Fix for kernel stacks panic. |
| 23 | * Erich Boleyn : MP v1.4 and additional changes. |
| 24 | * Matthias Sattler : Changes for 2.1 kernel map. |
| 25 | * Michel Lespinasse : Changes for 2.1 kernel map. |
| 26 | * Michael Chastain : Change trampoline.S to gnu as. |
| 27 | * Alan Cox : Dumb bug: 'B' step PPro's are fine |
| 28 | * Ingo Molnar : Added APIC timers, based on code |
| 29 | * from Jose Renau |
| 30 | * Ingo Molnar : various cleanups and rewrites |
| 31 | * Tigran Aivazian : fixed "0.00 in /proc/uptime on SMP" bug. |
| 32 | * Maciej W. Rozycki : Bits for genuine 82489DX APICs |
| 33 | * Andi Kleen : Changed for SMP boot into long mode. |
| 34 | * Martin J. Bligh : Added support for multi-quad systems |
| 35 | * Dave Jones : Report invalid combinations of Athlon CPUs. |
| 36 | * Rusty Russell : Hacked into shape for new "hotplug" boot process. |
| 37 | * Andi Kleen : Converted to new state machine. |
| 38 | * Ashok Raj : CPU hotplug support |
| 39 | * Glauber Costa : i386 and x86_64 integration |
| 40 | */ |
| 41 | |
Glauber Costa | 68a1c3f | 2008-03-03 14:12:42 -0300 | [diff] [blame] | 42 | #include <linux/init.h> |
| 43 | #include <linux/smp.h> |
Glauber Costa | a355352 | 2008-03-03 14:12:58 -0300 | [diff] [blame] | 44 | #include <linux/module.h> |
Glauber Costa | 70708a1 | 2008-03-03 14:13:03 -0300 | [diff] [blame] | 45 | #include <linux/sched.h> |
Glauber Costa | 69c18c1 | 2008-03-03 14:13:07 -0300 | [diff] [blame] | 46 | #include <linux/percpu.h> |
Glauber Costa | 91718e8 | 2008-03-03 14:13:12 -0300 | [diff] [blame] | 47 | #include <linux/bootmem.h> |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 48 | #include <linux/err.h> |
| 49 | #include <linux/nmi.h> |
Shane Wang | 69575d3 | 2009-09-01 18:25:07 -0700 | [diff] [blame] | 50 | #include <linux/tboot.h> |
Jacob Pan | 35f720c | 2009-09-17 07:36:43 -0700 | [diff] [blame] | 51 | #include <linux/stackprotector.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 52 | #include <linux/gfp.h> |
Boris Ostrovsky | 1a022e3 | 2012-03-13 19:55:09 +0100 | [diff] [blame] | 53 | #include <linux/cpuidle.h> |
Glauber Costa | 69c18c1 | 2008-03-03 14:13:07 -0300 | [diff] [blame] | 54 | |
Glauber de Oliveira Costa | 8aef135 | 2008-03-19 14:26:11 -0300 | [diff] [blame] | 55 | #include <asm/acpi.h> |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 56 | #include <asm/desc.h> |
Glauber Costa | 69c18c1 | 2008-03-03 14:13:07 -0300 | [diff] [blame] | 57 | #include <asm/nmi.h> |
| 58 | #include <asm/irq.h> |
Ingo Molnar | 07bbc16 | 2008-09-23 23:26:42 +0200 | [diff] [blame] | 59 | #include <asm/idle.h> |
Jarkko Sakkinen | 48927bb | 2012-05-08 21:22:28 +0300 | [diff] [blame] | 60 | #include <asm/realmode.h> |
Glauber Costa | 69c18c1 | 2008-03-03 14:13:07 -0300 | [diff] [blame] | 61 | #include <asm/cpu.h> |
| 62 | #include <asm/numa.h> |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 63 | #include <asm/pgtable.h> |
| 64 | #include <asm/tlbflush.h> |
| 65 | #include <asm/mtrr.h> |
H. Peter Anvin | ea53069 | 2010-09-17 15:39:11 -0700 | [diff] [blame] | 66 | #include <asm/mwait.h> |
Ingo Molnar | 7b6aa33 | 2009-02-17 13:58:15 +0100 | [diff] [blame] | 67 | #include <asm/apic.h> |
Henrik Kretzschmar | 7167d08 | 2011-02-22 15:38:05 +0100 | [diff] [blame] | 68 | #include <asm/io_apic.h> |
Yinghai Lu | 569712b | 2008-11-16 03:12:49 -0800 | [diff] [blame] | 69 | #include <asm/setup.h> |
Tejun Heo | bdbcdd4 | 2009-01-21 17:26:06 +0900 | [diff] [blame] | 70 | #include <asm/uv/uv.h> |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 71 | #include <linux/mc146818rtc.h> |
Glauber Costa | 68a1c3f | 2008-03-03 14:12:42 -0300 | [diff] [blame] | 72 | |
Ingo Molnar | 1164dd0 | 2009-01-28 19:34:09 +0100 | [diff] [blame] | 73 | #include <asm/smpboot_hooks.h> |
Jacob Pan | b81bb37 | 2009-11-09 11:27:04 -0800 | [diff] [blame] | 74 | #include <asm/i8259.h> |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 75 | |
Jarkko Sakkinen | 48927bb | 2012-05-08 21:22:28 +0300 | [diff] [blame] | 76 | #include <asm/realmode.h> |
| 77 | |
Glauber de Oliveira Costa | a8db845 | 2008-03-19 14:26:01 -0300 | [diff] [blame] | 78 | /* State of each CPU */ |
| 79 | DEFINE_PER_CPU(int, cpu_state) = { 0 }; |
| 80 | |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 81 | #ifdef CONFIG_HOTPLUG_CPU |
| 82 | /* |
Borislav Petkov | d7c53c9 | 2010-08-19 20:10:29 +0200 | [diff] [blame] | 83 | * We need this for trampoline_base protection from concurrent accesses when |
| 84 | * off- and onlining cores wildly. |
| 85 | */ |
| 86 | static DEFINE_MUTEX(x86_cpu_hotplug_driver_mutex); |
| 87 | |
Randy Dunlap | 91d88ce | 2011-01-08 19:59:14 -0800 | [diff] [blame] | 88 | void cpu_hotplug_driver_lock(void) |
Borislav Petkov | d7c53c9 | 2010-08-19 20:10:29 +0200 | [diff] [blame] | 89 | { |
Thomas Gleixner | 7eb43a6 | 2012-04-20 13:05:48 +0000 | [diff] [blame] | 90 | mutex_lock(&x86_cpu_hotplug_driver_mutex); |
Borislav Petkov | d7c53c9 | 2010-08-19 20:10:29 +0200 | [diff] [blame] | 91 | } |
| 92 | |
Randy Dunlap | 91d88ce | 2011-01-08 19:59:14 -0800 | [diff] [blame] | 93 | void cpu_hotplug_driver_unlock(void) |
Borislav Petkov | d7c53c9 | 2010-08-19 20:10:29 +0200 | [diff] [blame] | 94 | { |
Thomas Gleixner | 7eb43a6 | 2012-04-20 13:05:48 +0000 | [diff] [blame] | 95 | mutex_unlock(&x86_cpu_hotplug_driver_mutex); |
Borislav Petkov | d7c53c9 | 2010-08-19 20:10:29 +0200 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | ssize_t arch_cpu_probe(const char *buf, size_t count) { return -1; } |
| 99 | ssize_t arch_cpu_release(const char *buf, size_t count) { return -1; } |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 100 | #endif |
Glauber de Oliveira Costa | f6bc402 | 2008-03-19 14:25:53 -0300 | [diff] [blame] | 101 | |
Glauber Costa | a355352 | 2008-03-03 14:12:58 -0300 | [diff] [blame] | 102 | /* Number of siblings per CPU package */ |
| 103 | int smp_num_siblings = 1; |
| 104 | EXPORT_SYMBOL(smp_num_siblings); |
| 105 | |
| 106 | /* Last level cache ID of each logical CPU */ |
| 107 | DEFINE_PER_CPU(u16, cpu_llc_id) = BAD_APICID; |
| 108 | |
Glauber Costa | a355352 | 2008-03-03 14:12:58 -0300 | [diff] [blame] | 109 | /* representing HT siblings of each logical CPU */ |
Rusty Russell | 7ad728f | 2009-03-13 14:49:50 +1030 | [diff] [blame] | 110 | DEFINE_PER_CPU(cpumask_var_t, cpu_sibling_map); |
Glauber Costa | a355352 | 2008-03-03 14:12:58 -0300 | [diff] [blame] | 111 | EXPORT_PER_CPU_SYMBOL(cpu_sibling_map); |
| 112 | |
| 113 | /* representing HT and core siblings of each logical CPU */ |
Rusty Russell | 7ad728f | 2009-03-13 14:49:50 +1030 | [diff] [blame] | 114 | DEFINE_PER_CPU(cpumask_var_t, cpu_core_map); |
Glauber Costa | a355352 | 2008-03-03 14:12:58 -0300 | [diff] [blame] | 115 | EXPORT_PER_CPU_SYMBOL(cpu_core_map); |
| 116 | |
Yinghai Lu | b3d7336 | 2011-01-21 15:29:44 -0800 | [diff] [blame] | 117 | DEFINE_PER_CPU(cpumask_var_t, cpu_llc_shared_map); |
| 118 | |
Glauber Costa | a355352 | 2008-03-03 14:12:58 -0300 | [diff] [blame] | 119 | /* Per CPU bogomips and other parameters */ |
| 120 | DEFINE_PER_CPU_SHARED_ALIGNED(struct cpuinfo_x86, cpu_info); |
| 121 | EXPORT_PER_CPU_SYMBOL(cpu_info); |
Glauber Costa | 768d950 | 2008-03-03 14:13:02 -0300 | [diff] [blame] | 122 | |
Yinghai Lu | 2b6163b | 2009-02-25 20:50:49 -0800 | [diff] [blame] | 123 | atomic_t init_deasserted; |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 124 | |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 125 | /* |
| 126 | * Report back to the Boot Processor. |
| 127 | * Running on AP. |
| 128 | */ |
Ingo Molnar | a4928cf | 2008-04-23 13:20:56 +0200 | [diff] [blame] | 129 | static void __cpuinit smp_callin(void) |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 130 | { |
| 131 | int cpuid, phys_id; |
| 132 | unsigned long timeout; |
| 133 | |
| 134 | /* |
| 135 | * If waken up by an INIT in an 82489DX configuration |
| 136 | * we may get here before an INIT-deassert IPI reaches |
| 137 | * our local APIC. We have to wait for the IPI or we'll |
| 138 | * lock up on an APIC access. |
| 139 | */ |
Ingo Molnar | a965936 | 2009-01-28 16:21:32 +0100 | [diff] [blame] | 140 | if (apic->wait_for_init_deassert) |
| 141 | apic->wait_for_init_deassert(&init_deasserted); |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 142 | |
| 143 | /* |
| 144 | * (This works even if the APIC is not enabled.) |
| 145 | */ |
Yinghai Lu | 4c9961d | 2008-07-11 18:44:16 -0700 | [diff] [blame] | 146 | phys_id = read_apic_id(); |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 147 | cpuid = smp_processor_id(); |
Mike Travis | c2d1cec | 2009-01-04 05:18:03 -0800 | [diff] [blame] | 148 | if (cpumask_test_cpu(cpuid, cpu_callin_mask)) { |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 149 | panic("%s: phys CPU#%d, CPU#%d already present??\n", __func__, |
| 150 | phys_id, cpuid); |
| 151 | } |
Thomas Gleixner | cfc1b9a | 2008-07-21 21:35:38 +0200 | [diff] [blame] | 152 | pr_debug("CPU#%d (phys ID: %d) waiting for CALLOUT\n", cpuid, phys_id); |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 153 | |
| 154 | /* |
| 155 | * STARTUP IPIs are fragile beasts as they might sometimes |
| 156 | * trigger some glue motherboard logic. Complete APIC bus |
| 157 | * silence for 1 second, this overestimates the time the |
| 158 | * boot CPU is spending to send the up to 2 STARTUP IPIs |
| 159 | * by a factor of two. This should be enough. |
| 160 | */ |
| 161 | |
| 162 | /* |
| 163 | * Waiting 2s total for startup (udelay is not yet working) |
| 164 | */ |
| 165 | timeout = jiffies + 2*HZ; |
| 166 | while (time_before(jiffies, timeout)) { |
| 167 | /* |
| 168 | * Has the boot CPU finished it's STARTUP sequence? |
| 169 | */ |
Mike Travis | c2d1cec | 2009-01-04 05:18:03 -0800 | [diff] [blame] | 170 | if (cpumask_test_cpu(cpuid, cpu_callout_mask)) |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 171 | break; |
| 172 | cpu_relax(); |
| 173 | } |
| 174 | |
| 175 | if (!time_before(jiffies, timeout)) { |
| 176 | panic("%s: CPU%d started up but did not get a callout!\n", |
| 177 | __func__, cpuid); |
| 178 | } |
| 179 | |
| 180 | /* |
| 181 | * the boot CPU has finished the init stage and is spinning |
| 182 | * on callin_map until we finish. We are free to set up this |
| 183 | * CPU, first the APIC. (this is probably redundant on most |
| 184 | * boards) |
| 185 | */ |
| 186 | |
Thomas Gleixner | cfc1b9a | 2008-07-21 21:35:38 +0200 | [diff] [blame] | 187 | pr_debug("CALLIN, before setup_local_APIC().\n"); |
Ingo Molnar | 333344d | 2009-01-28 16:31:52 +0100 | [diff] [blame] | 188 | if (apic->smp_callin_clear_local_apic) |
| 189 | apic->smp_callin_clear_local_apic(); |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 190 | setup_local_APIC(); |
| 191 | end_local_APIC_setup(); |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 192 | |
Suresh Siddha | 9d133e5 | 2010-01-29 11:42:21 -0800 | [diff] [blame] | 193 | /* |
| 194 | * Need to setup vector mappings before we enable interrupts. |
| 195 | */ |
Suresh Siddha | 36e9e1e | 2010-03-15 14:33:06 -0800 | [diff] [blame] | 196 | setup_vector_irq(smp_processor_id()); |
Jack Steiner | b565201 | 2011-11-15 15:33:56 -0800 | [diff] [blame] | 197 | |
| 198 | /* |
| 199 | * Save our processor parameters. Note: this information |
| 200 | * is needed for clock calibration. |
| 201 | */ |
| 202 | smp_store_cpu_info(cpuid); |
| 203 | |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 204 | /* |
| 205 | * Get our bogomips. |
Jack Steiner | b565201 | 2011-11-15 15:33:56 -0800 | [diff] [blame] | 206 | * Update loops_per_jiffy in cpu_data. Previous call to |
| 207 | * smp_store_cpu_info() stored a value that is close but not as |
| 208 | * accurate as the value just calculated. |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 209 | */ |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 210 | calibrate_delay(); |
Jack Steiner | b565201 | 2011-11-15 15:33:56 -0800 | [diff] [blame] | 211 | cpu_data(cpuid).loops_per_jiffy = loops_per_jiffy; |
Thomas Gleixner | cfc1b9a | 2008-07-21 21:35:38 +0200 | [diff] [blame] | 212 | pr_debug("Stack at about %p\n", &cpuid); |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 213 | |
| 214 | /* |
Andi Kleen | 5ef428c | 2010-11-18 11:47:31 +0100 | [diff] [blame] | 215 | * This must be done before setting cpu_online_mask |
| 216 | * or calling notify_cpu_starting. |
| 217 | */ |
| 218 | set_cpu_sibling_map(raw_smp_processor_id()); |
| 219 | wmb(); |
| 220 | |
Peter Zijlstra | 8525702 | 2010-03-23 19:30:52 +0100 | [diff] [blame] | 221 | notify_cpu_starting(cpuid); |
| 222 | |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 223 | /* |
| 224 | * Allow the master to continue. |
| 225 | */ |
Mike Travis | c2d1cec | 2009-01-04 05:18:03 -0800 | [diff] [blame] | 226 | cpumask_set_cpu(cpuid, cpu_callin_mask); |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 227 | } |
| 228 | |
Glauber de Oliveira Costa | bbc2ff6 | 2008-03-19 14:26:00 -0300 | [diff] [blame] | 229 | /* |
| 230 | * Activate a secondary processor. |
| 231 | */ |
Frederic Weisbecker | 0ca59dd | 2008-12-24 23:30:02 +0100 | [diff] [blame] | 232 | notrace static void __cpuinit start_secondary(void *unused) |
Glauber de Oliveira Costa | bbc2ff6 | 2008-03-19 14:26:00 -0300 | [diff] [blame] | 233 | { |
| 234 | /* |
| 235 | * Don't put *anything* before cpu_init(), SMP booting is too |
| 236 | * fragile that we want to limit the things done here to the |
| 237 | * most necessary things. |
| 238 | */ |
Glauber de Oliveira Costa | bbc2ff6 | 2008-03-19 14:26:00 -0300 | [diff] [blame] | 239 | cpu_init(); |
Igor Mammedov | df156f9 | 2012-02-07 15:52:44 +0100 | [diff] [blame] | 240 | x86_cpuinit.early_percpu_clock_init(); |
Glauber de Oliveira Costa | bbc2ff6 | 2008-03-19 14:26:00 -0300 | [diff] [blame] | 241 | preempt_disable(); |
| 242 | smp_callin(); |
| 243 | |
Borislav Petkov | b40827fa | 2010-08-28 15:58:33 +0200 | [diff] [blame] | 244 | #ifdef CONFIG_X86_32 |
| 245 | /* switch away from the initial page table */ |
| 246 | load_cr3(swapper_pg_dir); |
| 247 | __flush_tlb_all(); |
| 248 | #endif |
| 249 | |
Glauber de Oliveira Costa | bbc2ff6 | 2008-03-19 14:26:00 -0300 | [diff] [blame] | 250 | /* otherwise gcc will move up smp_processor_id before the cpu_init */ |
| 251 | barrier(); |
| 252 | /* |
| 253 | * Check TSC synchronization with the BP: |
| 254 | */ |
| 255 | check_tsc_sync_target(); |
| 256 | |
Glauber de Oliveira Costa | bbc2ff6 | 2008-03-19 14:26:00 -0300 | [diff] [blame] | 257 | /* |
| 258 | * We need to hold call_lock, so there is no inconsistency |
| 259 | * between the time smp_call_function() determines number of |
| 260 | * IPI recipients, and the time when the determination is made |
| 261 | * for which cpus receive the IPI. Holding this |
| 262 | * lock helps us to not include this cpu in a currently in progress |
| 263 | * smp_call_function(). |
Eric W. Biederman | d388e5f | 2008-08-09 15:09:02 -0700 | [diff] [blame] | 264 | * |
| 265 | * We need to hold vector_lock so there the set of online cpus |
| 266 | * does not change while we are assigning vectors to cpus. Holding |
| 267 | * this lock ensures we don't half assign or remove an irq from a cpu. |
Glauber de Oliveira Costa | bbc2ff6 | 2008-03-19 14:26:00 -0300 | [diff] [blame] | 268 | */ |
Manfred Spraul | 0cefa5b9 | 2008-09-07 11:29:58 +0200 | [diff] [blame] | 269 | ipi_call_lock(); |
Eric W. Biederman | d388e5f | 2008-08-09 15:09:02 -0700 | [diff] [blame] | 270 | lock_vector_lock(); |
Mike Travis | c2d1cec | 2009-01-04 05:18:03 -0800 | [diff] [blame] | 271 | set_cpu_online(smp_processor_id(), true); |
Eric W. Biederman | d388e5f | 2008-08-09 15:09:02 -0700 | [diff] [blame] | 272 | unlock_vector_lock(); |
Manfred Spraul | 0cefa5b9 | 2008-09-07 11:29:58 +0200 | [diff] [blame] | 273 | ipi_call_unlock(); |
Glauber de Oliveira Costa | bbc2ff6 | 2008-03-19 14:26:00 -0300 | [diff] [blame] | 274 | per_cpu(cpu_state, smp_processor_id()) = CPU_ONLINE; |
Russ Anderson | 78c0617 | 2010-02-26 10:49:12 -0600 | [diff] [blame] | 275 | x86_platform.nmi_init(); |
Glauber de Oliveira Costa | bbc2ff6 | 2008-03-19 14:26:00 -0300 | [diff] [blame] | 276 | |
Manfred Spraul | 0cefa5b9 | 2008-09-07 11:29:58 +0200 | [diff] [blame] | 277 | /* enable local interrupts */ |
| 278 | local_irq_enable(); |
| 279 | |
Jacob Pan | 35f720c | 2009-09-17 07:36:43 -0700 | [diff] [blame] | 280 | /* to prevent fake stack check failure in clock setup */ |
| 281 | boot_init_stack_canary(); |
| 282 | |
Thomas Gleixner | 736deca | 2009-08-19 12:35:53 +0200 | [diff] [blame] | 283 | x86_cpuinit.setup_percpu_clockev(); |
Glauber de Oliveira Costa | bbc2ff6 | 2008-03-19 14:26:00 -0300 | [diff] [blame] | 284 | |
| 285 | wmb(); |
| 286 | cpu_idle(); |
| 287 | } |
| 288 | |
Glauber de Oliveira Costa | 1d89a7f | 2008-03-19 14:25:05 -0300 | [diff] [blame] | 289 | /* |
| 290 | * The bootstrap kernel entry code has set these up. Save them for |
| 291 | * a given CPU |
| 292 | */ |
| 293 | |
| 294 | void __cpuinit smp_store_cpu_info(int id) |
| 295 | { |
| 296 | struct cpuinfo_x86 *c = &cpu_data(id); |
| 297 | |
Yinghai Lu | b3d7336 | 2011-01-21 15:29:44 -0800 | [diff] [blame] | 298 | *c = boot_cpu_data; |
Glauber de Oliveira Costa | 1d89a7f | 2008-03-19 14:25:05 -0300 | [diff] [blame] | 299 | c->cpu_index = id; |
| 300 | if (id != 0) |
| 301 | identify_secondary_cpu(c); |
Glauber de Oliveira Costa | 1d89a7f | 2008-03-19 14:25:05 -0300 | [diff] [blame] | 302 | } |
| 303 | |
Peter Zijlstra | 316ad24 | 2012-05-11 13:05:59 +0200 | [diff] [blame] | 304 | static bool __cpuinit |
| 305 | topology_sane(struct cpuinfo_x86 *c, struct cpuinfo_x86 *o, const char *name) |
Andreas Herrmann | d4fbe4f | 2010-09-30 14:41:56 +0200 | [diff] [blame] | 306 | { |
Peter Zijlstra | 316ad24 | 2012-05-11 13:05:59 +0200 | [diff] [blame] | 307 | int cpu1 = c->cpu_index, cpu2 = o->cpu_index; |
| 308 | |
| 309 | return !WARN_ONCE(cpu_to_node(cpu1) != cpu_to_node(cpu2), |
| 310 | "sched: CPU #%d's %s-sibling CPU #%d is not on the same node! " |
| 311 | "[node: %d != %d]. Ignoring dependency.\n", |
| 312 | cpu1, name, cpu2, cpu_to_node(cpu1), cpu_to_node(cpu2)); |
Andreas Herrmann | d4fbe4f | 2010-09-30 14:41:56 +0200 | [diff] [blame] | 313 | } |
| 314 | |
Peter Zijlstra | 316ad24 | 2012-05-11 13:05:59 +0200 | [diff] [blame] | 315 | #define link_mask(_m, c1, c2) \ |
| 316 | do { \ |
| 317 | cpumask_set_cpu((c1), cpu_##_m##_mask(c2)); \ |
| 318 | cpumask_set_cpu((c2), cpu_##_m##_mask(c1)); \ |
| 319 | } while (0) |
| 320 | |
| 321 | static bool __cpuinit match_smt(struct cpuinfo_x86 *c, struct cpuinfo_x86 *o) |
| 322 | { |
| 323 | if (cpu_has(c, X86_FEATURE_TOPOEXT)) { |
| 324 | int cpu1 = c->cpu_index, cpu2 = o->cpu_index; |
| 325 | |
| 326 | if (c->phys_proc_id == o->phys_proc_id && |
| 327 | per_cpu(cpu_llc_id, cpu1) == per_cpu(cpu_llc_id, cpu2) && |
| 328 | c->compute_unit_id == o->compute_unit_id) |
| 329 | return topology_sane(c, o, "smt"); |
| 330 | |
| 331 | } else if (c->phys_proc_id == o->phys_proc_id && |
| 332 | c->cpu_core_id == o->cpu_core_id) { |
| 333 | return topology_sane(c, o, "smt"); |
| 334 | } |
| 335 | |
| 336 | return false; |
| 337 | } |
| 338 | |
| 339 | static bool __cpuinit match_llc(struct cpuinfo_x86 *c, struct cpuinfo_x86 *o) |
| 340 | { |
| 341 | int cpu1 = c->cpu_index, cpu2 = o->cpu_index; |
| 342 | |
| 343 | if (per_cpu(cpu_llc_id, cpu1) != BAD_APICID && |
| 344 | per_cpu(cpu_llc_id, cpu1) == per_cpu(cpu_llc_id, cpu2)) |
| 345 | return topology_sane(c, o, "llc"); |
| 346 | |
| 347 | return false; |
| 348 | } |
| 349 | |
| 350 | static bool __cpuinit match_mc(struct cpuinfo_x86 *c, struct cpuinfo_x86 *o) |
| 351 | { |
| 352 | if (c->phys_proc_id == o->phys_proc_id) |
| 353 | return topology_sane(c, o, "mc"); |
| 354 | |
| 355 | return false; |
| 356 | } |
Glauber de Oliveira Costa | 1d89a7f | 2008-03-19 14:25:05 -0300 | [diff] [blame] | 357 | |
Glauber Costa | 768d950 | 2008-03-03 14:13:02 -0300 | [diff] [blame] | 358 | void __cpuinit set_cpu_sibling_map(int cpu) |
| 359 | { |
Peter Zijlstra | 316ad24 | 2012-05-11 13:05:59 +0200 | [diff] [blame] | 360 | bool has_mc = boot_cpu_data.x86_max_cores > 1; |
| 361 | bool has_smt = smp_num_siblings > 1; |
Glauber Costa | 768d950 | 2008-03-03 14:13:02 -0300 | [diff] [blame] | 362 | struct cpuinfo_x86 *c = &cpu_data(cpu); |
Peter Zijlstra | 316ad24 | 2012-05-11 13:05:59 +0200 | [diff] [blame] | 363 | struct cpuinfo_x86 *o; |
| 364 | int i; |
Glauber Costa | 768d950 | 2008-03-03 14:13:02 -0300 | [diff] [blame] | 365 | |
Mike Travis | c2d1cec | 2009-01-04 05:18:03 -0800 | [diff] [blame] | 366 | cpumask_set_cpu(cpu, cpu_sibling_setup_mask); |
Glauber Costa | 768d950 | 2008-03-03 14:13:02 -0300 | [diff] [blame] | 367 | |
Peter Zijlstra | 316ad24 | 2012-05-11 13:05:59 +0200 | [diff] [blame] | 368 | if (!has_smt && !has_mc) { |
Mike Travis | c2d1cec | 2009-01-04 05:18:03 -0800 | [diff] [blame] | 369 | cpumask_set_cpu(cpu, cpu_sibling_mask(cpu)); |
Peter Zijlstra | 316ad24 | 2012-05-11 13:05:59 +0200 | [diff] [blame] | 370 | cpumask_set_cpu(cpu, cpu_llc_shared_mask(cpu)); |
| 371 | cpumask_set_cpu(cpu, cpu_core_mask(cpu)); |
Glauber Costa | 768d950 | 2008-03-03 14:13:02 -0300 | [diff] [blame] | 372 | c->booted_cores = 1; |
| 373 | return; |
| 374 | } |
| 375 | |
Mike Travis | c2d1cec | 2009-01-04 05:18:03 -0800 | [diff] [blame] | 376 | for_each_cpu(i, cpu_sibling_setup_mask) { |
Peter Zijlstra | 316ad24 | 2012-05-11 13:05:59 +0200 | [diff] [blame] | 377 | o = &cpu_data(i); |
Peter Zijlstra | 0acbb44 | 2012-04-18 19:04:09 +0200 | [diff] [blame] | 378 | |
Peter Zijlstra | 316ad24 | 2012-05-11 13:05:59 +0200 | [diff] [blame] | 379 | if ((i == cpu) || (has_smt && match_smt(c, o))) |
| 380 | link_mask(sibling, cpu, i); |
Peter Zijlstra | 0acbb44 | 2012-04-18 19:04:09 +0200 | [diff] [blame] | 381 | |
Peter Zijlstra | 316ad24 | 2012-05-11 13:05:59 +0200 | [diff] [blame] | 382 | if ((i == cpu) || (has_mc && match_llc(c, o))) |
| 383 | link_mask(llc_shared, cpu, i); |
| 384 | |
| 385 | if ((i == cpu) || (has_mc && match_mc(c, o))) { |
| 386 | link_mask(core, cpu, i); |
| 387 | |
Glauber Costa | 768d950 | 2008-03-03 14:13:02 -0300 | [diff] [blame] | 388 | /* |
| 389 | * Does this new cpu bringup a new core? |
| 390 | */ |
Mike Travis | c2d1cec | 2009-01-04 05:18:03 -0800 | [diff] [blame] | 391 | if (cpumask_weight(cpu_sibling_mask(cpu)) == 1) { |
Glauber Costa | 768d950 | 2008-03-03 14:13:02 -0300 | [diff] [blame] | 392 | /* |
| 393 | * for each core in package, increment |
| 394 | * the booted_cores for this new cpu |
| 395 | */ |
Mike Travis | c2d1cec | 2009-01-04 05:18:03 -0800 | [diff] [blame] | 396 | if (cpumask_first(cpu_sibling_mask(i)) == i) |
Glauber Costa | 768d950 | 2008-03-03 14:13:02 -0300 | [diff] [blame] | 397 | c->booted_cores++; |
| 398 | /* |
| 399 | * increment the core count for all |
| 400 | * the other cpus in this package |
| 401 | */ |
| 402 | if (i != cpu) |
| 403 | cpu_data(i).booted_cores++; |
| 404 | } else if (i != cpu && !c->booted_cores) |
| 405 | c->booted_cores = cpu_data(i).booted_cores; |
| 406 | } |
| 407 | } |
| 408 | } |
| 409 | |
Glauber Costa | 70708a1 | 2008-03-03 14:13:03 -0300 | [diff] [blame] | 410 | /* maps the cpu to the sched domain representing multi-core */ |
Rusty Russell | 030bb20 | 2008-12-26 22:23:41 +1030 | [diff] [blame] | 411 | const struct cpumask *cpu_coregroup_mask(int cpu) |
Glauber Costa | 70708a1 | 2008-03-03 14:13:03 -0300 | [diff] [blame] | 412 | { |
Peter Zijlstra | 9f64638 | 2012-05-29 16:39:09 +0200 | [diff] [blame^] | 413 | return cpu_llc_shared_mask(cpu); |
Rusty Russell | 030bb20 | 2008-12-26 22:23:41 +1030 | [diff] [blame] | 414 | } |
| 415 | |
Ingo Molnar | a4928cf | 2008-04-23 13:20:56 +0200 | [diff] [blame] | 416 | static void impress_friends(void) |
Glauber de Oliveira Costa | 904541e | 2008-03-19 14:25:27 -0300 | [diff] [blame] | 417 | { |
| 418 | int cpu; |
| 419 | unsigned long bogosum = 0; |
| 420 | /* |
| 421 | * Allow the user to impress friends. |
| 422 | */ |
Thomas Gleixner | cfc1b9a | 2008-07-21 21:35:38 +0200 | [diff] [blame] | 423 | pr_debug("Before bogomips.\n"); |
Glauber de Oliveira Costa | 904541e | 2008-03-19 14:25:27 -0300 | [diff] [blame] | 424 | for_each_possible_cpu(cpu) |
Mike Travis | c2d1cec | 2009-01-04 05:18:03 -0800 | [diff] [blame] | 425 | if (cpumask_test_cpu(cpu, cpu_callout_mask)) |
Glauber de Oliveira Costa | 904541e | 2008-03-19 14:25:27 -0300 | [diff] [blame] | 426 | bogosum += cpu_data(cpu).loops_per_jiffy; |
| 427 | printk(KERN_INFO |
| 428 | "Total of %d processors activated (%lu.%02lu BogoMIPS).\n", |
Glauber de Oliveira Costa | f68e00a | 2008-03-19 14:25:29 -0300 | [diff] [blame] | 429 | num_online_cpus(), |
Glauber de Oliveira Costa | 904541e | 2008-03-19 14:25:27 -0300 | [diff] [blame] | 430 | bogosum/(500000/HZ), |
| 431 | (bogosum/(5000/HZ))%100); |
| 432 | |
Thomas Gleixner | cfc1b9a | 2008-07-21 21:35:38 +0200 | [diff] [blame] | 433 | pr_debug("Before bogocount - setting activated=1.\n"); |
Glauber de Oliveira Costa | 904541e | 2008-03-19 14:25:27 -0300 | [diff] [blame] | 434 | } |
| 435 | |
Yinghai Lu | 569712b | 2008-11-16 03:12:49 -0800 | [diff] [blame] | 436 | void __inquire_remote_apic(int apicid) |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 437 | { |
| 438 | unsigned i, regs[] = { APIC_ID >> 4, APIC_LVR >> 4, APIC_SPIV >> 4 }; |
Greg Dietsche | a6c23905 | 2011-06-30 20:10:53 -0500 | [diff] [blame] | 439 | const char * const names[] = { "ID", "VERSION", "SPIV" }; |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 440 | int timeout; |
| 441 | u32 status; |
| 442 | |
Yinghai Lu | 823b259 | 2008-09-10 21:56:46 -0700 | [diff] [blame] | 443 | printk(KERN_INFO "Inquiring remote APIC 0x%x...\n", apicid); |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 444 | |
| 445 | for (i = 0; i < ARRAY_SIZE(regs); i++) { |
Yinghai Lu | 823b259 | 2008-09-10 21:56:46 -0700 | [diff] [blame] | 446 | printk(KERN_INFO "... APIC 0x%x %s: ", apicid, names[i]); |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 447 | |
| 448 | /* |
| 449 | * Wait for idle. |
| 450 | */ |
| 451 | status = safe_apic_wait_icr_idle(); |
| 452 | if (status) |
| 453 | printk(KERN_CONT |
| 454 | "a previous APIC delivery may have failed\n"); |
| 455 | |
Suresh Siddha | 1b374e4 | 2008-07-10 11:16:49 -0700 | [diff] [blame] | 456 | apic_icr_write(APIC_DM_REMRD | regs[i], apicid); |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 457 | |
| 458 | timeout = 0; |
| 459 | do { |
| 460 | udelay(100); |
| 461 | status = apic_read(APIC_ICR) & APIC_ICR_RR_MASK; |
| 462 | } while (status == APIC_ICR_RR_INPROG && timeout++ < 1000); |
| 463 | |
| 464 | switch (status) { |
| 465 | case APIC_ICR_RR_VALID: |
| 466 | status = apic_read(APIC_RRR); |
| 467 | printk(KERN_CONT "%08x\n", status); |
| 468 | break; |
| 469 | default: |
| 470 | printk(KERN_CONT "failed\n"); |
| 471 | } |
| 472 | } |
| 473 | } |
| 474 | |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 475 | /* |
| 476 | * Poke the other CPU in the eye via NMI to wake it up. Remember that the normal |
| 477 | * INIT, INIT, STARTUP sequence will reset the chip hard for us, and this |
| 478 | * won't ... remember to clear down the APIC, etc later. |
| 479 | */ |
Cyrill Gorcunov | cece315 | 2009-04-18 23:45:28 +0400 | [diff] [blame] | 480 | int __cpuinit |
Yinghai Lu | 569712b | 2008-11-16 03:12:49 -0800 | [diff] [blame] | 481 | wakeup_secondary_cpu_via_nmi(int logical_apicid, unsigned long start_eip) |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 482 | { |
| 483 | unsigned long send_status, accept_status = 0; |
| 484 | int maxlvt; |
| 485 | |
| 486 | /* Target chip */ |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 487 | /* Boot on the stack */ |
| 488 | /* Kick the second */ |
Ingo Molnar | bdb1a9b | 2009-01-28 05:29:25 +0100 | [diff] [blame] | 489 | apic_icr_write(APIC_DM_NMI | apic->dest_logical, logical_apicid); |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 490 | |
Thomas Gleixner | cfc1b9a | 2008-07-21 21:35:38 +0200 | [diff] [blame] | 491 | pr_debug("Waiting for send to finish...\n"); |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 492 | send_status = safe_apic_wait_icr_idle(); |
| 493 | |
| 494 | /* |
| 495 | * Give the other CPU some time to accept the IPI. |
| 496 | */ |
| 497 | udelay(200); |
Yinghai Lu | 569712b | 2008-11-16 03:12:49 -0800 | [diff] [blame] | 498 | if (APIC_INTEGRATED(apic_version[boot_cpu_physical_apicid])) { |
Cyrill Gorcunov | 59ef48a | 2008-09-14 21:58:49 +0400 | [diff] [blame] | 499 | maxlvt = lapic_get_maxlvt(); |
| 500 | if (maxlvt > 3) /* Due to the Pentium erratum 3AP. */ |
| 501 | apic_write(APIC_ESR, 0); |
| 502 | accept_status = (apic_read(APIC_ESR) & 0xEF); |
| 503 | } |
Thomas Gleixner | cfc1b9a | 2008-07-21 21:35:38 +0200 | [diff] [blame] | 504 | pr_debug("NMI sent.\n"); |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 505 | |
| 506 | if (send_status) |
| 507 | printk(KERN_ERR "APIC never delivered???\n"); |
| 508 | if (accept_status) |
| 509 | printk(KERN_ERR "APIC delivery error (%lx).\n", accept_status); |
| 510 | |
| 511 | return (send_status | accept_status); |
| 512 | } |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 513 | |
Cyrill Gorcunov | cece315 | 2009-04-18 23:45:28 +0400 | [diff] [blame] | 514 | static int __cpuinit |
Yinghai Lu | 569712b | 2008-11-16 03:12:49 -0800 | [diff] [blame] | 515 | wakeup_secondary_cpu_via_init(int phys_apicid, unsigned long start_eip) |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 516 | { |
| 517 | unsigned long send_status, accept_status = 0; |
| 518 | int maxlvt, num_starts, j; |
| 519 | |
Maciej W. Rozycki | 593f4a7 | 2008-07-16 19:15:30 +0100 | [diff] [blame] | 520 | maxlvt = lapic_get_maxlvt(); |
| 521 | |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 522 | /* |
| 523 | * Be paranoid about clearing APIC errors. |
| 524 | */ |
| 525 | if (APIC_INTEGRATED(apic_version[phys_apicid])) { |
Maciej W. Rozycki | 593f4a7 | 2008-07-16 19:15:30 +0100 | [diff] [blame] | 526 | if (maxlvt > 3) /* Due to the Pentium erratum 3AP. */ |
| 527 | apic_write(APIC_ESR, 0); |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 528 | apic_read(APIC_ESR); |
| 529 | } |
| 530 | |
Thomas Gleixner | cfc1b9a | 2008-07-21 21:35:38 +0200 | [diff] [blame] | 531 | pr_debug("Asserting INIT.\n"); |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 532 | |
| 533 | /* |
| 534 | * Turn INIT on target chip |
| 535 | */ |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 536 | /* |
| 537 | * Send IPI |
| 538 | */ |
Suresh Siddha | 1b374e4 | 2008-07-10 11:16:49 -0700 | [diff] [blame] | 539 | apic_icr_write(APIC_INT_LEVELTRIG | APIC_INT_ASSERT | APIC_DM_INIT, |
| 540 | phys_apicid); |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 541 | |
Thomas Gleixner | cfc1b9a | 2008-07-21 21:35:38 +0200 | [diff] [blame] | 542 | pr_debug("Waiting for send to finish...\n"); |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 543 | send_status = safe_apic_wait_icr_idle(); |
| 544 | |
| 545 | mdelay(10); |
| 546 | |
Thomas Gleixner | cfc1b9a | 2008-07-21 21:35:38 +0200 | [diff] [blame] | 547 | pr_debug("Deasserting INIT.\n"); |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 548 | |
| 549 | /* Target chip */ |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 550 | /* Send IPI */ |
Suresh Siddha | 1b374e4 | 2008-07-10 11:16:49 -0700 | [diff] [blame] | 551 | apic_icr_write(APIC_INT_LEVELTRIG | APIC_DM_INIT, phys_apicid); |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 552 | |
Thomas Gleixner | cfc1b9a | 2008-07-21 21:35:38 +0200 | [diff] [blame] | 553 | pr_debug("Waiting for send to finish...\n"); |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 554 | send_status = safe_apic_wait_icr_idle(); |
| 555 | |
| 556 | mb(); |
| 557 | atomic_set(&init_deasserted, 1); |
| 558 | |
| 559 | /* |
| 560 | * Should we send STARTUP IPIs ? |
| 561 | * |
| 562 | * Determine this based on the APIC version. |
| 563 | * If we don't have an integrated APIC, don't send the STARTUP IPIs. |
| 564 | */ |
| 565 | if (APIC_INTEGRATED(apic_version[phys_apicid])) |
| 566 | num_starts = 2; |
| 567 | else |
| 568 | num_starts = 0; |
| 569 | |
| 570 | /* |
| 571 | * Paravirt / VMI wants a startup IPI hook here to set up the |
| 572 | * target processor state. |
| 573 | */ |
| 574 | startup_ipi_hook(phys_apicid, (unsigned long) start_secondary, |
H. Peter Anvin | 11d4c3f | 2011-02-04 16:14:11 -0800 | [diff] [blame] | 575 | stack_start); |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 576 | |
| 577 | /* |
| 578 | * Run STARTUP IPI loop. |
| 579 | */ |
Thomas Gleixner | cfc1b9a | 2008-07-21 21:35:38 +0200 | [diff] [blame] | 580 | pr_debug("#startup loops: %d.\n", num_starts); |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 581 | |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 582 | for (j = 1; j <= num_starts; j++) { |
Thomas Gleixner | cfc1b9a | 2008-07-21 21:35:38 +0200 | [diff] [blame] | 583 | pr_debug("Sending STARTUP #%d.\n", j); |
Maciej W. Rozycki | 593f4a7 | 2008-07-16 19:15:30 +0100 | [diff] [blame] | 584 | if (maxlvt > 3) /* Due to the Pentium erratum 3AP. */ |
| 585 | apic_write(APIC_ESR, 0); |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 586 | apic_read(APIC_ESR); |
Thomas Gleixner | cfc1b9a | 2008-07-21 21:35:38 +0200 | [diff] [blame] | 587 | pr_debug("After apic_write.\n"); |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 588 | |
| 589 | /* |
| 590 | * STARTUP IPI |
| 591 | */ |
| 592 | |
| 593 | /* Target chip */ |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 594 | /* Boot on the stack */ |
| 595 | /* Kick the second */ |
Suresh Siddha | 1b374e4 | 2008-07-10 11:16:49 -0700 | [diff] [blame] | 596 | apic_icr_write(APIC_DM_STARTUP | (start_eip >> 12), |
| 597 | phys_apicid); |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 598 | |
| 599 | /* |
| 600 | * Give the other CPU some time to accept the IPI. |
| 601 | */ |
| 602 | udelay(300); |
| 603 | |
Thomas Gleixner | cfc1b9a | 2008-07-21 21:35:38 +0200 | [diff] [blame] | 604 | pr_debug("Startup point 1.\n"); |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 605 | |
Thomas Gleixner | cfc1b9a | 2008-07-21 21:35:38 +0200 | [diff] [blame] | 606 | pr_debug("Waiting for send to finish...\n"); |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 607 | send_status = safe_apic_wait_icr_idle(); |
| 608 | |
| 609 | /* |
| 610 | * Give the other CPU some time to accept the IPI. |
| 611 | */ |
| 612 | udelay(200); |
Maciej W. Rozycki | 593f4a7 | 2008-07-16 19:15:30 +0100 | [diff] [blame] | 613 | if (maxlvt > 3) /* Due to the Pentium erratum 3AP. */ |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 614 | apic_write(APIC_ESR, 0); |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 615 | accept_status = (apic_read(APIC_ESR) & 0xEF); |
| 616 | if (send_status || accept_status) |
| 617 | break; |
| 618 | } |
Thomas Gleixner | cfc1b9a | 2008-07-21 21:35:38 +0200 | [diff] [blame] | 619 | pr_debug("After Startup.\n"); |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 620 | |
| 621 | if (send_status) |
| 622 | printk(KERN_ERR "APIC never delivered???\n"); |
| 623 | if (accept_status) |
| 624 | printk(KERN_ERR "APIC delivery error (%lx).\n", accept_status); |
| 625 | |
| 626 | return (send_status | accept_status); |
| 627 | } |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 628 | |
Mike Travis | 2eaad1f | 2009-12-10 17:19:36 -0800 | [diff] [blame] | 629 | /* reduce the number of lines printed when booting a large cpu count system */ |
| 630 | static void __cpuinit announce_cpu(int cpu, int apicid) |
| 631 | { |
| 632 | static int current_node = -1; |
Borislav Petkov | 4adc8b7 | 2010-06-01 21:04:55 +0200 | [diff] [blame] | 633 | int node = early_cpu_to_node(cpu); |
Mike Travis | 2eaad1f | 2009-12-10 17:19:36 -0800 | [diff] [blame] | 634 | |
| 635 | if (system_state == SYSTEM_BOOTING) { |
| 636 | if (node != current_node) { |
| 637 | if (current_node > (-1)) |
| 638 | pr_cont(" Ok.\n"); |
| 639 | current_node = node; |
| 640 | pr_info("Booting Node %3d, Processors ", node); |
| 641 | } |
| 642 | pr_cont(" #%d%s", cpu, cpu == (nr_cpu_ids - 1) ? " Ok.\n" : ""); |
| 643 | return; |
| 644 | } else |
| 645 | pr_info("Booting Node %d Processor %d APIC 0x%x\n", |
| 646 | node, cpu, apicid); |
| 647 | } |
| 648 | |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 649 | /* |
| 650 | * NOTE - on most systems this is a PHYSICAL apic ID, but on multiquad |
| 651 | * (ie clustered apic addressing mode), this is a LOGICAL apic ID. |
Ingo Molnar | 1f5bcab | 2009-02-26 13:51:40 +0100 | [diff] [blame] | 652 | * Returns zero if CPU booted OK, else error code from |
| 653 | * ->wakeup_secondary_cpu. |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 654 | */ |
Thomas Gleixner | 7eb43a6 | 2012-04-20 13:05:48 +0000 | [diff] [blame] | 655 | static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle) |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 656 | { |
Jarkko Sakkinen | 48927bb | 2012-05-08 21:22:28 +0300 | [diff] [blame] | 657 | volatile u32 *trampoline_status = |
Jarkko Sakkinen | b429dbf | 2012-05-08 21:22:41 +0300 | [diff] [blame] | 658 | (volatile u32 *) __va(real_mode_header->trampoline_status); |
Jarkko Sakkinen | 48927bb | 2012-05-08 21:22:28 +0300 | [diff] [blame] | 659 | /* start_ip had better be page-aligned! */ |
Jarkko Sakkinen | f37240f | 2012-05-08 21:22:43 +0300 | [diff] [blame] | 660 | unsigned long start_ip = real_mode_header->trampoline_start; |
Jarkko Sakkinen | 48927bb | 2012-05-08 21:22:28 +0300 | [diff] [blame] | 661 | |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 662 | unsigned long boot_error = 0; |
Ingo Molnar | ab6fb7c | 2009-02-17 16:22:09 +0100 | [diff] [blame] | 663 | int timeout; |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 664 | |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 665 | alternatives_smp_switch(1); |
| 666 | |
Thomas Gleixner | 7eb43a6 | 2012-04-20 13:05:48 +0000 | [diff] [blame] | 667 | idle->thread.sp = (unsigned long) (((struct pt_regs *) |
| 668 | (THREAD_SIZE + task_stack_page(idle))) - 1); |
| 669 | per_cpu(current_task, cpu) = idle; |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 670 | |
Brian Gerst | c6f5e0a | 2009-01-19 00:38:58 +0900 | [diff] [blame] | 671 | #ifdef CONFIG_X86_32 |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 672 | /* Stack for startup_32 can be just as for start_secondary onwards */ |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 673 | irq_ctx_init(cpu); |
| 674 | #else |
Thomas Gleixner | 7eb43a6 | 2012-04-20 13:05:48 +0000 | [diff] [blame] | 675 | clear_tsk_thread_flag(idle, TIF_FORK); |
Tejun Heo | 004aa32 | 2009-01-13 20:41:35 +0900 | [diff] [blame] | 676 | initial_gs = per_cpu_offset(cpu); |
Brian Gerst | 9af4565 | 2009-01-19 00:38:58 +0900 | [diff] [blame] | 677 | per_cpu(kernel_stack, cpu) = |
Thomas Gleixner | 7eb43a6 | 2012-04-20 13:05:48 +0000 | [diff] [blame] | 678 | (unsigned long)task_stack_page(idle) - |
Brian Gerst | 9af4565 | 2009-01-19 00:38:58 +0900 | [diff] [blame] | 679 | KERNEL_STACK_OFFSET + THREAD_SIZE; |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 680 | #endif |
Glauber Costa | a939098 | 2008-05-28 16:19:53 -0700 | [diff] [blame] | 681 | early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu); |
Glauber Costa | 3e97047 | 2008-05-28 13:01:54 -0300 | [diff] [blame] | 682 | initial_code = (unsigned long)start_secondary; |
Thomas Gleixner | 7eb43a6 | 2012-04-20 13:05:48 +0000 | [diff] [blame] | 683 | stack_start = idle->thread.sp; |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 684 | |
Mike Travis | 2eaad1f | 2009-12-10 17:19:36 -0800 | [diff] [blame] | 685 | /* So we see what's up */ |
| 686 | announce_cpu(cpu, apicid); |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 687 | |
| 688 | /* |
| 689 | * This grunge runs the startup process for |
| 690 | * the targeted processor. |
| 691 | */ |
| 692 | |
| 693 | atomic_set(&init_deasserted, 0); |
| 694 | |
Jack Steiner | 34d0559 | 2008-04-16 11:45:15 -0500 | [diff] [blame] | 695 | if (get_uv_system_type() != UV_NON_UNIQUE_APIC) { |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 696 | |
Thomas Gleixner | cfc1b9a | 2008-07-21 21:35:38 +0200 | [diff] [blame] | 697 | pr_debug("Setting warm reset code and vector.\n"); |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 698 | |
Jack Steiner | 34d0559 | 2008-04-16 11:45:15 -0500 | [diff] [blame] | 699 | smpboot_setup_warm_reset_vector(start_ip); |
| 700 | /* |
| 701 | * Be paranoid about clearing APIC errors. |
Cyrill Gorcunov | db96b0a | 2008-10-22 18:00:09 +0400 | [diff] [blame] | 702 | */ |
| 703 | if (APIC_INTEGRATED(apic_version[boot_cpu_physical_apicid])) { |
| 704 | apic_write(APIC_ESR, 0); |
| 705 | apic_read(APIC_ESR); |
| 706 | } |
Jack Steiner | 34d0559 | 2008-04-16 11:45:15 -0500 | [diff] [blame] | 707 | } |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 708 | |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 709 | /* |
Ingo Molnar | 1f5bcab | 2009-02-26 13:51:40 +0100 | [diff] [blame] | 710 | * Kick the secondary CPU. Use the method in the APIC driver |
| 711 | * if it's defined - or use an INIT boot APIC message otherwise: |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 712 | */ |
Ingo Molnar | 1f5bcab | 2009-02-26 13:51:40 +0100 | [diff] [blame] | 713 | if (apic->wakeup_secondary_cpu) |
| 714 | boot_error = apic->wakeup_secondary_cpu(apicid, start_ip); |
| 715 | else |
| 716 | boot_error = wakeup_secondary_cpu_via_init(apicid, start_ip); |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 717 | |
| 718 | if (!boot_error) { |
| 719 | /* |
| 720 | * allow APs to start initializing. |
| 721 | */ |
Thomas Gleixner | cfc1b9a | 2008-07-21 21:35:38 +0200 | [diff] [blame] | 722 | pr_debug("Before Callout %d.\n", cpu); |
Mike Travis | c2d1cec | 2009-01-04 05:18:03 -0800 | [diff] [blame] | 723 | cpumask_set_cpu(cpu, cpu_callout_mask); |
Thomas Gleixner | cfc1b9a | 2008-07-21 21:35:38 +0200 | [diff] [blame] | 724 | pr_debug("After Callout %d.\n", cpu); |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 725 | |
| 726 | /* |
| 727 | * Wait 5s total for a response |
| 728 | */ |
| 729 | for (timeout = 0; timeout < 50000; timeout++) { |
Mike Travis | c2d1cec | 2009-01-04 05:18:03 -0800 | [diff] [blame] | 730 | if (cpumask_test_cpu(cpu, cpu_callin_mask)) |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 731 | break; /* It has booted */ |
| 732 | udelay(100); |
Suresh Siddha | 68f202e | 2010-07-30 11:46:42 -0700 | [diff] [blame] | 733 | /* |
| 734 | * Allow other tasks to run while we wait for the |
| 735 | * AP to come online. This also gives a chance |
| 736 | * for the MTRR work(triggered by the AP coming online) |
| 737 | * to be completed in the stop machine context. |
| 738 | */ |
| 739 | schedule(); |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 740 | } |
| 741 | |
Yinghai Lu | 21c3fcf | 2012-02-12 09:53:57 -0800 | [diff] [blame] | 742 | if (cpumask_test_cpu(cpu, cpu_callin_mask)) { |
| 743 | print_cpu_msr(&cpu_data(cpu)); |
Mike Travis | 2eaad1f | 2009-12-10 17:19:36 -0800 | [diff] [blame] | 744 | pr_debug("CPU%d: has booted.\n", cpu); |
Yinghai Lu | 21c3fcf | 2012-02-12 09:53:57 -0800 | [diff] [blame] | 745 | } else { |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 746 | boot_error = 1; |
Jarkko Sakkinen | 48927bb | 2012-05-08 21:22:28 +0300 | [diff] [blame] | 747 | if (*trampoline_status == 0xA5A5A5A5) |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 748 | /* trampoline started but...? */ |
Mike Travis | 2eaad1f | 2009-12-10 17:19:36 -0800 | [diff] [blame] | 749 | pr_err("CPU%d: Stuck ??\n", cpu); |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 750 | else |
| 751 | /* trampoline code not run */ |
Mike Travis | 2eaad1f | 2009-12-10 17:19:36 -0800 | [diff] [blame] | 752 | pr_err("CPU%d: Not responding.\n", cpu); |
Ingo Molnar | 25dc004 | 2009-01-28 16:31:52 +0100 | [diff] [blame] | 753 | if (apic->inquire_remote_apic) |
| 754 | apic->inquire_remote_apic(apicid); |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 755 | } |
| 756 | } |
Tejun Heo | 1a51e3a | 2009-01-13 20:41:35 +0900 | [diff] [blame] | 757 | |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 758 | if (boot_error) { |
| 759 | /* Try to put things back the way they were before ... */ |
Mike Travis | 23ca4bb | 2008-05-12 21:21:12 +0200 | [diff] [blame] | 760 | numa_remove_cpu(cpu); /* was set by numa_add_cpu */ |
Mike Travis | c2d1cec | 2009-01-04 05:18:03 -0800 | [diff] [blame] | 761 | |
| 762 | /* was set by do_boot_cpu() */ |
| 763 | cpumask_clear_cpu(cpu, cpu_callout_mask); |
| 764 | |
| 765 | /* was set by cpu_init() */ |
| 766 | cpumask_clear_cpu(cpu, cpu_initialized_mask); |
| 767 | |
| 768 | set_cpu_present(cpu, false); |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 769 | per_cpu(x86_cpu_to_apicid, cpu) = BAD_APICID; |
| 770 | } |
| 771 | |
| 772 | /* mark "stuck" area as not stuck */ |
Jarkko Sakkinen | 48927bb | 2012-05-08 21:22:28 +0300 | [diff] [blame] | 773 | *trampoline_status = 0; |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 774 | |
Yinghai Lu | 02421f9 | 2009-04-03 17:15:53 -0700 | [diff] [blame] | 775 | if (get_uv_system_type() != UV_NON_UNIQUE_APIC) { |
| 776 | /* |
| 777 | * Cleanup possible dangling ends... |
| 778 | */ |
| 779 | smpboot_restore_warm_reset_vector(); |
| 780 | } |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 781 | return boot_error; |
| 782 | } |
| 783 | |
Thomas Gleixner | 5cdaf18 | 2012-04-20 13:05:47 +0000 | [diff] [blame] | 784 | int __cpuinit native_cpu_up(unsigned int cpu, struct task_struct *tidle) |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 785 | { |
Ingo Molnar | a21769a4 | 2009-01-28 06:50:47 +0100 | [diff] [blame] | 786 | int apicid = apic->cpu_present_to_apicid(cpu); |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 787 | unsigned long flags; |
| 788 | int err; |
| 789 | |
| 790 | WARN_ON(irqs_disabled()); |
| 791 | |
Thomas Gleixner | cfc1b9a | 2008-07-21 21:35:38 +0200 | [diff] [blame] | 792 | pr_debug("++++++++++++++++++++=_---CPU UP %u\n", cpu); |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 793 | |
| 794 | if (apicid == BAD_APICID || apicid == boot_cpu_physical_apicid || |
Suresh Siddha | c284b42 | 2011-12-21 17:45:19 -0800 | [diff] [blame] | 795 | !physid_isset(apicid, phys_cpu_present_map) || |
Daniel J Blueman | fa63030 | 2012-03-14 15:17:34 +0800 | [diff] [blame] | 796 | !apic->apic_id_valid(apicid)) { |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 797 | printk(KERN_ERR "%s: bad cpu %d\n", __func__, cpu); |
| 798 | return -EINVAL; |
| 799 | } |
| 800 | |
| 801 | /* |
| 802 | * Already booted CPU? |
| 803 | */ |
Mike Travis | c2d1cec | 2009-01-04 05:18:03 -0800 | [diff] [blame] | 804 | if (cpumask_test_cpu(cpu, cpu_callin_mask)) { |
Thomas Gleixner | cfc1b9a | 2008-07-21 21:35:38 +0200 | [diff] [blame] | 805 | pr_debug("do_boot_cpu %d Already started\n", cpu); |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 806 | return -ENOSYS; |
| 807 | } |
| 808 | |
| 809 | /* |
| 810 | * Save current MTRR state in case it was changed since early boot |
| 811 | * (e.g. by the ACPI SMI) to initialize new CPUs with MTRRs in sync: |
| 812 | */ |
| 813 | mtrr_save_state(); |
| 814 | |
| 815 | per_cpu(cpu_state, cpu) = CPU_UP_PREPARE; |
| 816 | |
Thomas Gleixner | 7eb43a6 | 2012-04-20 13:05:48 +0000 | [diff] [blame] | 817 | err = do_boot_cpu(apicid, cpu, tidle); |
Hugh Dickins | 61165d7 | 2008-05-13 14:26:57 +0100 | [diff] [blame] | 818 | if (err) { |
Thomas Gleixner | cfc1b9a | 2008-07-21 21:35:38 +0200 | [diff] [blame] | 819 | pr_debug("do_boot_cpu failed %d\n", err); |
Hugh Dickins | 61165d7 | 2008-05-13 14:26:57 +0100 | [diff] [blame] | 820 | return -EIO; |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 821 | } |
| 822 | |
| 823 | /* |
| 824 | * Check TSC synchronization with the AP (keep irqs disabled |
| 825 | * while doing so): |
| 826 | */ |
| 827 | local_irq_save(flags); |
| 828 | check_tsc_sync_source(cpu); |
| 829 | local_irq_restore(flags); |
| 830 | |
Akinobu Mita | 7c04e64 | 2008-04-19 23:55:17 +0900 | [diff] [blame] | 831 | while (!cpu_online(cpu)) { |
Glauber de Oliveira Costa | cb3c8b9 | 2008-03-19 14:25:59 -0300 | [diff] [blame] | 832 | cpu_relax(); |
| 833 | touch_nmi_watchdog(); |
| 834 | } |
| 835 | |
| 836 | return 0; |
| 837 | } |
| 838 | |
Henrik Kretzschmar | 7167d08 | 2011-02-22 15:38:05 +0100 | [diff] [blame] | 839 | /** |
| 840 | * arch_disable_smp_support() - disables SMP support for x86 at runtime |
| 841 | */ |
| 842 | void arch_disable_smp_support(void) |
| 843 | { |
| 844 | disable_ioapic_support(); |
| 845 | } |
| 846 | |
Glauber de Oliveira Costa | a8db845 | 2008-03-19 14:26:01 -0300 | [diff] [blame] | 847 | /* |
Glauber de Oliveira Costa | 8aef135 | 2008-03-19 14:26:11 -0300 | [diff] [blame] | 848 | * Fall back to non SMP mode after errors. |
| 849 | * |
| 850 | * RED-PEN audit/test this more. I bet there is more state messed up here. |
| 851 | */ |
| 852 | static __init void disable_smp(void) |
| 853 | { |
Rusty Russell | 4f06289 | 2009-03-13 14:49:54 +1030 | [diff] [blame] | 854 | init_cpu_present(cpumask_of(0)); |
| 855 | init_cpu_possible(cpumask_of(0)); |
Glauber de Oliveira Costa | 8aef135 | 2008-03-19 14:26:11 -0300 | [diff] [blame] | 856 | smpboot_clear_io_apic_irqs(); |
Glauber Costa | 0f385d1 | 2008-05-28 17:09:53 -0700 | [diff] [blame] | 857 | |
Glauber de Oliveira Costa | 8aef135 | 2008-03-19 14:26:11 -0300 | [diff] [blame] | 858 | if (smp_found_config) |
Jack Steiner | b6df1b8 | 2008-06-19 21:51:05 -0500 | [diff] [blame] | 859 | physid_set_mask_of_physid(boot_cpu_physical_apicid, &phys_cpu_present_map); |
Glauber de Oliveira Costa | 8aef135 | 2008-03-19 14:26:11 -0300 | [diff] [blame] | 860 | else |
Jack Steiner | b6df1b8 | 2008-06-19 21:51:05 -0500 | [diff] [blame] | 861 | physid_set_mask_of_physid(0, &phys_cpu_present_map); |
Mike Travis | c2d1cec | 2009-01-04 05:18:03 -0800 | [diff] [blame] | 862 | cpumask_set_cpu(0, cpu_sibling_mask(0)); |
| 863 | cpumask_set_cpu(0, cpu_core_mask(0)); |
Glauber de Oliveira Costa | 8aef135 | 2008-03-19 14:26:11 -0300 | [diff] [blame] | 864 | } |
| 865 | |
| 866 | /* |
| 867 | * Various sanity checks. |
| 868 | */ |
| 869 | static int __init smp_sanity_check(unsigned max_cpus) |
| 870 | { |
Jack Steiner | ac23d4e | 2008-03-28 14:12:16 -0500 | [diff] [blame] | 871 | preempt_disable(); |
Yinghai Lu | a58f03b | 2008-08-14 02:16:30 -0700 | [diff] [blame] | 872 | |
Yinghai Lu | 1ff2f20 | 2009-01-29 19:30:04 -0800 | [diff] [blame] | 873 | #if !defined(CONFIG_X86_BIGSMP) && defined(CONFIG_X86_32) |
Yinghai Lu | a58f03b | 2008-08-14 02:16:30 -0700 | [diff] [blame] | 874 | if (def_to_bigsmp && nr_cpu_ids > 8) { |
| 875 | unsigned int cpu; |
| 876 | unsigned nr; |
| 877 | |
| 878 | printk(KERN_WARNING |
| 879 | "More than 8 CPUs detected - skipping them.\n" |
Yinghai Lu | 26f7ef1 | 2009-01-29 14:19:22 -0800 | [diff] [blame] | 880 | "Use CONFIG_X86_BIGSMP.\n"); |
Yinghai Lu | a58f03b | 2008-08-14 02:16:30 -0700 | [diff] [blame] | 881 | |
| 882 | nr = 0; |
| 883 | for_each_present_cpu(cpu) { |
| 884 | if (nr >= 8) |
Mike Travis | c2d1cec | 2009-01-04 05:18:03 -0800 | [diff] [blame] | 885 | set_cpu_present(cpu, false); |
Yinghai Lu | a58f03b | 2008-08-14 02:16:30 -0700 | [diff] [blame] | 886 | nr++; |
| 887 | } |
| 888 | |
| 889 | nr = 0; |
| 890 | for_each_possible_cpu(cpu) { |
| 891 | if (nr >= 8) |
Mike Travis | c2d1cec | 2009-01-04 05:18:03 -0800 | [diff] [blame] | 892 | set_cpu_possible(cpu, false); |
Yinghai Lu | a58f03b | 2008-08-14 02:16:30 -0700 | [diff] [blame] | 893 | nr++; |
| 894 | } |
| 895 | |
| 896 | nr_cpu_ids = 8; |
| 897 | } |
| 898 | #endif |
| 899 | |
Glauber de Oliveira Costa | 8aef135 | 2008-03-19 14:26:11 -0300 | [diff] [blame] | 900 | if (!physid_isset(hard_smp_processor_id(), phys_cpu_present_map)) { |
Michael Tokarev | 55c395b | 2008-12-05 14:42:20 +0300 | [diff] [blame] | 901 | printk(KERN_WARNING |
| 902 | "weird, boot CPU (#%d) not listed by the BIOS.\n", |
| 903 | hard_smp_processor_id()); |
| 904 | |
Glauber de Oliveira Costa | 8aef135 | 2008-03-19 14:26:11 -0300 | [diff] [blame] | 905 | physid_set(hard_smp_processor_id(), phys_cpu_present_map); |
| 906 | } |
| 907 | |
| 908 | /* |
| 909 | * If we couldn't find an SMP configuration at boot time, |
| 910 | * get out of here now! |
| 911 | */ |
| 912 | if (!smp_found_config && !acpi_lapic) { |
Jack Steiner | ac23d4e | 2008-03-28 14:12:16 -0500 | [diff] [blame] | 913 | preempt_enable(); |
Glauber de Oliveira Costa | 8aef135 | 2008-03-19 14:26:11 -0300 | [diff] [blame] | 914 | printk(KERN_NOTICE "SMP motherboard not detected.\n"); |
| 915 | disable_smp(); |
| 916 | if (APIC_init_uniprocessor()) |
| 917 | printk(KERN_NOTICE "Local APIC not detected." |
| 918 | " Using dummy APIC emulation.\n"); |
| 919 | return -1; |
| 920 | } |
| 921 | |
| 922 | /* |
| 923 | * Should not be necessary because the MP table should list the boot |
| 924 | * CPU too, but we do it for the sake of robustness anyway. |
| 925 | */ |
Ingo Molnar | a27a621 | 2009-01-28 12:43:18 +0100 | [diff] [blame] | 926 | if (!apic->check_phys_apicid_present(boot_cpu_physical_apicid)) { |
Glauber de Oliveira Costa | 8aef135 | 2008-03-19 14:26:11 -0300 | [diff] [blame] | 927 | printk(KERN_NOTICE |
| 928 | "weird, boot CPU (#%d) not listed by the BIOS.\n", |
| 929 | boot_cpu_physical_apicid); |
| 930 | physid_set(hard_smp_processor_id(), phys_cpu_present_map); |
| 931 | } |
Jack Steiner | ac23d4e | 2008-03-28 14:12:16 -0500 | [diff] [blame] | 932 | preempt_enable(); |
Glauber de Oliveira Costa | 8aef135 | 2008-03-19 14:26:11 -0300 | [diff] [blame] | 933 | |
| 934 | /* |
| 935 | * If we couldn't find a local APIC, then get out of here now! |
| 936 | */ |
| 937 | if (APIC_INTEGRATED(apic_version[boot_cpu_physical_apicid]) && |
| 938 | !cpu_has_apic) { |
Cyrill Gorcunov | 103428e | 2009-06-07 16:48:40 +0400 | [diff] [blame] | 939 | if (!disable_apic) { |
| 940 | pr_err("BIOS bug, local APIC #%d not detected!...\n", |
| 941 | boot_cpu_physical_apicid); |
| 942 | pr_err("... forcing use of dummy APIC emulation." |
Glauber de Oliveira Costa | 8aef135 | 2008-03-19 14:26:11 -0300 | [diff] [blame] | 943 | "(tell your hw vendor)\n"); |
Cyrill Gorcunov | 103428e | 2009-06-07 16:48:40 +0400 | [diff] [blame] | 944 | } |
Glauber de Oliveira Costa | 8aef135 | 2008-03-19 14:26:11 -0300 | [diff] [blame] | 945 | smpboot_clear_io_apic(); |
Henrik Kretzschmar | 7167d08 | 2011-02-22 15:38:05 +0100 | [diff] [blame] | 946 | disable_ioapic_support(); |
Glauber de Oliveira Costa | 8aef135 | 2008-03-19 14:26:11 -0300 | [diff] [blame] | 947 | return -1; |
| 948 | } |
| 949 | |
| 950 | verify_local_APIC(); |
| 951 | |
| 952 | /* |
| 953 | * If SMP should be disabled, then really disable it! |
| 954 | */ |
| 955 | if (!max_cpus) { |
Maciej W. Rozycki | 73d08e6 | 2008-05-21 22:09:43 +0100 | [diff] [blame] | 956 | printk(KERN_INFO "SMP mode deactivated.\n"); |
Glauber de Oliveira Costa | 8aef135 | 2008-03-19 14:26:11 -0300 | [diff] [blame] | 957 | smpboot_clear_io_apic(); |
Maciej W. Rozycki | d54db1a | 2008-06-06 03:28:02 +0100 | [diff] [blame] | 958 | |
Jesse Barnes | e90955c | 2008-04-21 14:14:44 -0700 | [diff] [blame] | 959 | connect_bsp_APIC(); |
Jesse Barnes | e90955c | 2008-04-21 14:14:44 -0700 | [diff] [blame] | 960 | setup_local_APIC(); |
Jan Beulich | 2fb270f | 2011-02-09 08:21:02 +0000 | [diff] [blame] | 961 | bsp_end_local_APIC_setup(); |
Glauber de Oliveira Costa | 8aef135 | 2008-03-19 14:26:11 -0300 | [diff] [blame] | 962 | return -1; |
| 963 | } |
| 964 | |
| 965 | return 0; |
| 966 | } |
| 967 | |
| 968 | static void __init smp_cpu_index_default(void) |
| 969 | { |
| 970 | int i; |
| 971 | struct cpuinfo_x86 *c; |
| 972 | |
Akinobu Mita | 7c04e64 | 2008-04-19 23:55:17 +0900 | [diff] [blame] | 973 | for_each_possible_cpu(i) { |
Glauber de Oliveira Costa | 8aef135 | 2008-03-19 14:26:11 -0300 | [diff] [blame] | 974 | c = &cpu_data(i); |
| 975 | /* mark all to hotplug */ |
Mike Travis | 9628937 | 2008-12-31 18:08:46 -0800 | [diff] [blame] | 976 | c->cpu_index = nr_cpu_ids; |
Glauber de Oliveira Costa | 8aef135 | 2008-03-19 14:26:11 -0300 | [diff] [blame] | 977 | } |
| 978 | } |
| 979 | |
| 980 | /* |
| 981 | * Prepare for SMP bootup. The MP table or ACPI has been read |
| 982 | * earlier. Just do some sanity checking here and enable APIC mode. |
| 983 | */ |
| 984 | void __init native_smp_prepare_cpus(unsigned int max_cpus) |
| 985 | { |
Rusty Russell | 7ad728f | 2009-03-13 14:49:50 +1030 | [diff] [blame] | 986 | unsigned int i; |
| 987 | |
Ingo Molnar | deef325 | 2008-05-12 15:44:38 +0200 | [diff] [blame] | 988 | preempt_disable(); |
Glauber de Oliveira Costa | 8aef135 | 2008-03-19 14:26:11 -0300 | [diff] [blame] | 989 | smp_cpu_index_default(); |
Yinghai Lu | 792363d | 2011-01-21 15:29:54 -0800 | [diff] [blame] | 990 | |
Glauber de Oliveira Costa | 8aef135 | 2008-03-19 14:26:11 -0300 | [diff] [blame] | 991 | /* |
| 992 | * Setup boot CPU information |
| 993 | */ |
| 994 | smp_store_cpu_info(0); /* Final full version of the data */ |
Yinghai Lu | 792363d | 2011-01-21 15:29:54 -0800 | [diff] [blame] | 995 | cpumask_copy(cpu_callin_mask, cpumask_of(0)); |
| 996 | mb(); |
Tejun Heo | bd22a2f | 2011-01-23 14:37:27 +0100 | [diff] [blame] | 997 | |
Glauber de Oliveira Costa | 8aef135 | 2008-03-19 14:26:11 -0300 | [diff] [blame] | 998 | current_thread_info()->cpu = 0; /* needed? */ |
Rusty Russell | 7ad728f | 2009-03-13 14:49:50 +1030 | [diff] [blame] | 999 | for_each_possible_cpu(i) { |
Li Zefan | 79f5599 | 2009-06-15 14:58:26 +0800 | [diff] [blame] | 1000 | zalloc_cpumask_var(&per_cpu(cpu_sibling_map, i), GFP_KERNEL); |
| 1001 | zalloc_cpumask_var(&per_cpu(cpu_core_map, i), GFP_KERNEL); |
Yinghai Lu | b3d7336 | 2011-01-21 15:29:44 -0800 | [diff] [blame] | 1002 | zalloc_cpumask_var(&per_cpu(cpu_llc_shared_map, i), GFP_KERNEL); |
Rusty Russell | 7ad728f | 2009-03-13 14:49:50 +1030 | [diff] [blame] | 1003 | } |
Glauber de Oliveira Costa | 8aef135 | 2008-03-19 14:26:11 -0300 | [diff] [blame] | 1004 | set_cpu_sibling_map(0); |
| 1005 | |
Suresh Siddha | 6e1cb38 | 2008-07-10 11:16:58 -0700 | [diff] [blame] | 1006 | |
Glauber de Oliveira Costa | 8aef135 | 2008-03-19 14:26:11 -0300 | [diff] [blame] | 1007 | if (smp_sanity_check(max_cpus) < 0) { |
| 1008 | printk(KERN_INFO "SMP disabled\n"); |
| 1009 | disable_smp(); |
Ingo Molnar | deef325 | 2008-05-12 15:44:38 +0200 | [diff] [blame] | 1010 | goto out; |
Glauber de Oliveira Costa | 8aef135 | 2008-03-19 14:26:11 -0300 | [diff] [blame] | 1011 | } |
| 1012 | |
Suresh Siddha | fa47f7e | 2010-08-27 11:09:50 -0700 | [diff] [blame] | 1013 | default_setup_apic_routing(); |
| 1014 | |
Jack Steiner | ac23d4e | 2008-03-28 14:12:16 -0500 | [diff] [blame] | 1015 | preempt_disable(); |
Yinghai Lu | 4c9961d | 2008-07-11 18:44:16 -0700 | [diff] [blame] | 1016 | if (read_apic_id() != boot_cpu_physical_apicid) { |
Glauber de Oliveira Costa | 8aef135 | 2008-03-19 14:26:11 -0300 | [diff] [blame] | 1017 | panic("Boot APIC ID in local APIC unexpected (%d vs %d)", |
Yinghai Lu | 4c9961d | 2008-07-11 18:44:16 -0700 | [diff] [blame] | 1018 | read_apic_id(), boot_cpu_physical_apicid); |
Glauber de Oliveira Costa | 8aef135 | 2008-03-19 14:26:11 -0300 | [diff] [blame] | 1019 | /* Or can we switch back to PIC here? */ |
| 1020 | } |
Jack Steiner | ac23d4e | 2008-03-28 14:12:16 -0500 | [diff] [blame] | 1021 | preempt_enable(); |
Glauber de Oliveira Costa | 8aef135 | 2008-03-19 14:26:11 -0300 | [diff] [blame] | 1022 | |
Glauber de Oliveira Costa | 8aef135 | 2008-03-19 14:26:11 -0300 | [diff] [blame] | 1023 | connect_bsp_APIC(); |
Glauber Costa | b584176 | 2008-05-28 13:38:28 -0300 | [diff] [blame] | 1024 | |
Glauber de Oliveira Costa | 8aef135 | 2008-03-19 14:26:11 -0300 | [diff] [blame] | 1025 | /* |
| 1026 | * Switch from PIC to APIC mode. |
| 1027 | */ |
| 1028 | setup_local_APIC(); |
| 1029 | |
Glauber de Oliveira Costa | 8aef135 | 2008-03-19 14:26:11 -0300 | [diff] [blame] | 1030 | /* |
| 1031 | * Enable IO APIC before setting up error vector |
| 1032 | */ |
| 1033 | if (!skip_ioapic_setup && nr_ioapics) |
| 1034 | enable_IO_APIC(); |
Yinghai Lu | 88d0f55 | 2009-02-14 23:57:28 -0800 | [diff] [blame] | 1035 | |
Jan Beulich | 2fb270f | 2011-02-09 08:21:02 +0000 | [diff] [blame] | 1036 | bsp_end_local_APIC_setup(); |
Glauber de Oliveira Costa | 8aef135 | 2008-03-19 14:26:11 -0300 | [diff] [blame] | 1037 | |
Ingo Molnar | d83093b | 2009-01-28 12:43:18 +0100 | [diff] [blame] | 1038 | if (apic->setup_portio_remap) |
| 1039 | apic->setup_portio_remap(); |
Glauber de Oliveira Costa | 8aef135 | 2008-03-19 14:26:11 -0300 | [diff] [blame] | 1040 | |
| 1041 | smpboot_setup_io_apic(); |
| 1042 | /* |
| 1043 | * Set up local APIC timer on boot CPU. |
| 1044 | */ |
| 1045 | |
| 1046 | printk(KERN_INFO "CPU%d: ", 0); |
| 1047 | print_cpu_info(&cpu_data(0)); |
Thomas Gleixner | 736deca | 2009-08-19 12:35:53 +0200 | [diff] [blame] | 1048 | x86_init.timers.setup_percpu_clockev(); |
Marcin Slusarz | c4bd1fd | 2008-08-21 20:49:05 +0200 | [diff] [blame] | 1049 | |
| 1050 | if (is_uv_system()) |
| 1051 | uv_system_init(); |
Suresh Siddha | d0af9ee | 2009-08-19 18:05:36 -0700 | [diff] [blame] | 1052 | |
| 1053 | set_mtrr_aps_delayed_init(); |
Ingo Molnar | deef325 | 2008-05-12 15:44:38 +0200 | [diff] [blame] | 1054 | out: |
| 1055 | preempt_enable(); |
Glauber de Oliveira Costa | 8aef135 | 2008-03-19 14:26:11 -0300 | [diff] [blame] | 1056 | } |
Suresh Siddha | d0af9ee | 2009-08-19 18:05:36 -0700 | [diff] [blame] | 1057 | |
Suresh Siddha | 3fb82d5 | 2010-11-23 16:11:40 -0800 | [diff] [blame] | 1058 | void arch_disable_nonboot_cpus_begin(void) |
| 1059 | { |
| 1060 | /* |
| 1061 | * Avoid the smp alternatives switch during the disable_nonboot_cpus(). |
| 1062 | * In the suspend path, we will be back in the SMP mode shortly anyways. |
| 1063 | */ |
| 1064 | skip_smp_alternatives = true; |
| 1065 | } |
| 1066 | |
| 1067 | void arch_disable_nonboot_cpus_end(void) |
| 1068 | { |
| 1069 | skip_smp_alternatives = false; |
| 1070 | } |
| 1071 | |
Suresh Siddha | d0af9ee | 2009-08-19 18:05:36 -0700 | [diff] [blame] | 1072 | void arch_enable_nonboot_cpus_begin(void) |
| 1073 | { |
| 1074 | set_mtrr_aps_delayed_init(); |
| 1075 | } |
| 1076 | |
| 1077 | void arch_enable_nonboot_cpus_end(void) |
| 1078 | { |
| 1079 | mtrr_aps_init(); |
| 1080 | } |
| 1081 | |
Glauber de Oliveira Costa | 8aef135 | 2008-03-19 14:26:11 -0300 | [diff] [blame] | 1082 | /* |
Glauber de Oliveira Costa | a8db845 | 2008-03-19 14:26:01 -0300 | [diff] [blame] | 1083 | * Early setup to make printk work. |
| 1084 | */ |
| 1085 | void __init native_smp_prepare_boot_cpu(void) |
| 1086 | { |
| 1087 | int me = smp_processor_id(); |
Brian Gerst | 552be87 | 2009-01-30 17:47:53 +0900 | [diff] [blame] | 1088 | switch_to_new_gdt(me); |
Mike Travis | c2d1cec | 2009-01-04 05:18:03 -0800 | [diff] [blame] | 1089 | /* already set me in cpu_online_mask in boot_cpu_init() */ |
| 1090 | cpumask_set_cpu(me, cpu_callout_mask); |
Glauber de Oliveira Costa | a8db845 | 2008-03-19 14:26:01 -0300 | [diff] [blame] | 1091 | per_cpu(cpu_state, me) = CPU_ONLINE; |
| 1092 | } |
| 1093 | |
Glauber de Oliveira Costa | 83f7eb9 | 2008-03-19 14:26:02 -0300 | [diff] [blame] | 1094 | void __init native_smp_cpus_done(unsigned int max_cpus) |
| 1095 | { |
Thomas Gleixner | cfc1b9a | 2008-07-21 21:35:38 +0200 | [diff] [blame] | 1096 | pr_debug("Boot done.\n"); |
Glauber de Oliveira Costa | 83f7eb9 | 2008-03-19 14:26:02 -0300 | [diff] [blame] | 1097 | |
Don Zickus | 99e8b9c | 2011-10-13 15:14:26 -0400 | [diff] [blame] | 1098 | nmi_selftest(); |
Glauber de Oliveira Costa | 83f7eb9 | 2008-03-19 14:26:02 -0300 | [diff] [blame] | 1099 | impress_friends(); |
Glauber de Oliveira Costa | 83f7eb9 | 2008-03-19 14:26:02 -0300 | [diff] [blame] | 1100 | #ifdef CONFIG_X86_IO_APIC |
| 1101 | setup_ioapic_dest(); |
| 1102 | #endif |
Suresh Siddha | d0af9ee | 2009-08-19 18:05:36 -0700 | [diff] [blame] | 1103 | mtrr_aps_init(); |
Glauber de Oliveira Costa | 83f7eb9 | 2008-03-19 14:26:02 -0300 | [diff] [blame] | 1104 | } |
| 1105 | |
Mike Travis | 3b11ce7 | 2008-12-17 15:21:39 -0800 | [diff] [blame] | 1106 | static int __initdata setup_possible_cpus = -1; |
| 1107 | static int __init _setup_possible_cpus(char *str) |
| 1108 | { |
| 1109 | get_option(&str, &setup_possible_cpus); |
| 1110 | return 0; |
| 1111 | } |
| 1112 | early_param("possible_cpus", _setup_possible_cpus); |
| 1113 | |
| 1114 | |
Glauber Costa | 68a1c3f | 2008-03-03 14:12:42 -0300 | [diff] [blame] | 1115 | /* |
Rusty Russell | 4f06289 | 2009-03-13 14:49:54 +1030 | [diff] [blame] | 1116 | * cpu_possible_mask should be static, it cannot change as cpu's |
Glauber Costa | 68a1c3f | 2008-03-03 14:12:42 -0300 | [diff] [blame] | 1117 | * are onlined, or offlined. The reason is per-cpu data-structures |
| 1118 | * are allocated by some modules at init time, and dont expect to |
| 1119 | * do this dynamically on cpu arrival/departure. |
Rusty Russell | 4f06289 | 2009-03-13 14:49:54 +1030 | [diff] [blame] | 1120 | * cpu_present_mask on the other hand can change dynamically. |
Glauber Costa | 68a1c3f | 2008-03-03 14:12:42 -0300 | [diff] [blame] | 1121 | * In case when cpu_hotplug is not compiled, then we resort to current |
| 1122 | * behaviour, which is cpu_possible == cpu_present. |
| 1123 | * - Ashok Raj |
| 1124 | * |
| 1125 | * Three ways to find out the number of additional hotplug CPUs: |
| 1126 | * - If the BIOS specified disabled CPUs in ACPI/mptables use that. |
Mike Travis | 3b11ce7 | 2008-12-17 15:21:39 -0800 | [diff] [blame] | 1127 | * - The user can overwrite it with possible_cpus=NUM |
Glauber Costa | 68a1c3f | 2008-03-03 14:12:42 -0300 | [diff] [blame] | 1128 | * - Otherwise don't reserve additional CPUs. |
| 1129 | * We do this because additional CPUs waste a lot of memory. |
| 1130 | * -AK |
| 1131 | */ |
| 1132 | __init void prefill_possible_map(void) |
| 1133 | { |
Thomas Gleixner | cb48bb5 | 2008-10-05 17:51:52 +0200 | [diff] [blame] | 1134 | int i, possible; |
Glauber Costa | 68a1c3f | 2008-03-03 14:12:42 -0300 | [diff] [blame] | 1135 | |
Yinghai Lu | 329513a | 2008-07-02 18:54:40 -0700 | [diff] [blame] | 1136 | /* no processor from mptable or madt */ |
| 1137 | if (!num_processors) |
| 1138 | num_processors = 1; |
| 1139 | |
Jan Beulich | 5f2eb55 | 2010-05-24 12:13:17 -0700 | [diff] [blame] | 1140 | i = setup_max_cpus ?: 1; |
| 1141 | if (setup_possible_cpus == -1) { |
| 1142 | possible = num_processors; |
| 1143 | #ifdef CONFIG_HOTPLUG_CPU |
| 1144 | if (setup_max_cpus) |
| 1145 | possible += disabled_cpus; |
| 1146 | #else |
| 1147 | if (possible > i) |
| 1148 | possible = i; |
| 1149 | #endif |
| 1150 | } else |
Mike Travis | 3b11ce7 | 2008-12-17 15:21:39 -0800 | [diff] [blame] | 1151 | possible = setup_possible_cpus; |
| 1152 | |
Mike Travis | 730cf27 | 2008-12-31 18:08:45 -0800 | [diff] [blame] | 1153 | total_cpus = max_t(int, possible, num_processors + disabled_cpus); |
| 1154 | |
Yinghai Lu | 2b633e3 | 2010-02-10 01:20:37 -0800 | [diff] [blame] | 1155 | /* nr_cpu_ids could be reduced via nr_cpus= */ |
| 1156 | if (possible > nr_cpu_ids) { |
Mike Travis | 3b11ce7 | 2008-12-17 15:21:39 -0800 | [diff] [blame] | 1157 | printk(KERN_WARNING |
| 1158 | "%d Processors exceeds NR_CPUS limit of %d\n", |
Yinghai Lu | 2b633e3 | 2010-02-10 01:20:37 -0800 | [diff] [blame] | 1159 | possible, nr_cpu_ids); |
| 1160 | possible = nr_cpu_ids; |
Mike Travis | 3b11ce7 | 2008-12-17 15:21:39 -0800 | [diff] [blame] | 1161 | } |
Glauber Costa | 68a1c3f | 2008-03-03 14:12:42 -0300 | [diff] [blame] | 1162 | |
Jan Beulich | 5f2eb55 | 2010-05-24 12:13:17 -0700 | [diff] [blame] | 1163 | #ifdef CONFIG_HOTPLUG_CPU |
| 1164 | if (!setup_max_cpus) |
| 1165 | #endif |
| 1166 | if (possible > i) { |
| 1167 | printk(KERN_WARNING |
| 1168 | "%d Processors exceeds max_cpus limit of %u\n", |
| 1169 | possible, setup_max_cpus); |
| 1170 | possible = i; |
| 1171 | } |
| 1172 | |
Glauber Costa | 68a1c3f | 2008-03-03 14:12:42 -0300 | [diff] [blame] | 1173 | printk(KERN_INFO "SMP: Allowing %d CPUs, %d hotplug CPUs\n", |
| 1174 | possible, max_t(int, possible - num_processors, 0)); |
| 1175 | |
| 1176 | for (i = 0; i < possible; i++) |
Mike Travis | c2d1cec | 2009-01-04 05:18:03 -0800 | [diff] [blame] | 1177 | set_cpu_possible(i, true); |
Jan Beulich | 5f2eb55 | 2010-05-24 12:13:17 -0700 | [diff] [blame] | 1178 | for (; i < NR_CPUS; i++) |
| 1179 | set_cpu_possible(i, false); |
Mike Travis | 3461b0af | 2008-05-12 21:21:13 +0200 | [diff] [blame] | 1180 | |
| 1181 | nr_cpu_ids = possible; |
Glauber Costa | 68a1c3f | 2008-03-03 14:12:42 -0300 | [diff] [blame] | 1182 | } |
Glauber Costa | 69c18c1 | 2008-03-03 14:13:07 -0300 | [diff] [blame] | 1183 | |
Chuck Ebbert | 14adf85 | 2008-09-29 18:29:42 -0400 | [diff] [blame] | 1184 | #ifdef CONFIG_HOTPLUG_CPU |
| 1185 | |
| 1186 | static void remove_siblinginfo(int cpu) |
| 1187 | { |
| 1188 | int sibling; |
| 1189 | struct cpuinfo_x86 *c = &cpu_data(cpu); |
| 1190 | |
Mike Travis | c2d1cec | 2009-01-04 05:18:03 -0800 | [diff] [blame] | 1191 | for_each_cpu(sibling, cpu_core_mask(cpu)) { |
| 1192 | cpumask_clear_cpu(cpu, cpu_core_mask(sibling)); |
Chuck Ebbert | 14adf85 | 2008-09-29 18:29:42 -0400 | [diff] [blame] | 1193 | /*/ |
| 1194 | * last thread sibling in this cpu core going down |
| 1195 | */ |
Mike Travis | c2d1cec | 2009-01-04 05:18:03 -0800 | [diff] [blame] | 1196 | if (cpumask_weight(cpu_sibling_mask(cpu)) == 1) |
Chuck Ebbert | 14adf85 | 2008-09-29 18:29:42 -0400 | [diff] [blame] | 1197 | cpu_data(sibling).booted_cores--; |
| 1198 | } |
| 1199 | |
Mike Travis | c2d1cec | 2009-01-04 05:18:03 -0800 | [diff] [blame] | 1200 | for_each_cpu(sibling, cpu_sibling_mask(cpu)) |
| 1201 | cpumask_clear_cpu(cpu, cpu_sibling_mask(sibling)); |
| 1202 | cpumask_clear(cpu_sibling_mask(cpu)); |
| 1203 | cpumask_clear(cpu_core_mask(cpu)); |
Chuck Ebbert | 14adf85 | 2008-09-29 18:29:42 -0400 | [diff] [blame] | 1204 | c->phys_proc_id = 0; |
| 1205 | c->cpu_core_id = 0; |
Mike Travis | c2d1cec | 2009-01-04 05:18:03 -0800 | [diff] [blame] | 1206 | cpumask_clear_cpu(cpu, cpu_sibling_setup_mask); |
Chuck Ebbert | 14adf85 | 2008-09-29 18:29:42 -0400 | [diff] [blame] | 1207 | } |
| 1208 | |
Glauber Costa | 69c18c1 | 2008-03-03 14:13:07 -0300 | [diff] [blame] | 1209 | static void __ref remove_cpu_from_maps(int cpu) |
| 1210 | { |
Mike Travis | c2d1cec | 2009-01-04 05:18:03 -0800 | [diff] [blame] | 1211 | set_cpu_online(cpu, false); |
| 1212 | cpumask_clear_cpu(cpu, cpu_callout_mask); |
| 1213 | cpumask_clear_cpu(cpu, cpu_callin_mask); |
Glauber Costa | 69c18c1 | 2008-03-03 14:13:07 -0300 | [diff] [blame] | 1214 | /* was set by cpu_init() */ |
Mike Travis | c2d1cec | 2009-01-04 05:18:03 -0800 | [diff] [blame] | 1215 | cpumask_clear_cpu(cpu, cpu_initialized_mask); |
Mike Travis | 23ca4bb | 2008-05-12 21:21:12 +0200 | [diff] [blame] | 1216 | numa_remove_cpu(cpu); |
Glauber Costa | 69c18c1 | 2008-03-03 14:13:07 -0300 | [diff] [blame] | 1217 | } |
| 1218 | |
Alex Nixon | 8227dce | 2008-08-22 11:52:14 +0100 | [diff] [blame] | 1219 | void cpu_disable_common(void) |
| 1220 | { |
| 1221 | int cpu = smp_processor_id(); |
Alex Nixon | 8227dce | 2008-08-22 11:52:14 +0100 | [diff] [blame] | 1222 | |
Alex Nixon | 8227dce | 2008-08-22 11:52:14 +0100 | [diff] [blame] | 1223 | remove_siblinginfo(cpu); |
| 1224 | |
| 1225 | /* It's now safe to remove this processor from the online map */ |
| 1226 | lock_vector_lock(); |
| 1227 | remove_cpu_from_maps(cpu); |
| 1228 | unlock_vector_lock(); |
Mike Travis | d7b381b | 2008-12-16 17:33:58 -0800 | [diff] [blame] | 1229 | fixup_irqs(); |
Alex Nixon | 8227dce | 2008-08-22 11:52:14 +0100 | [diff] [blame] | 1230 | } |
| 1231 | |
Alex Nixon | 93be71b | 2008-08-22 11:52:11 +0100 | [diff] [blame] | 1232 | int native_cpu_disable(void) |
Glauber Costa | 69c18c1 | 2008-03-03 14:13:07 -0300 | [diff] [blame] | 1233 | { |
| 1234 | int cpu = smp_processor_id(); |
| 1235 | |
| 1236 | /* |
| 1237 | * Perhaps use cpufreq to drop frequency, but that could go |
| 1238 | * into generic code. |
| 1239 | * |
| 1240 | * We won't take down the boot processor on i386 due to some |
| 1241 | * interrupts only being able to be serviced by the BSP. |
| 1242 | * Especially so if we're not using an IOAPIC -zwane |
| 1243 | */ |
| 1244 | if (cpu == 0) |
| 1245 | return -EBUSY; |
| 1246 | |
Glauber Costa | 69c18c1 | 2008-03-03 14:13:07 -0300 | [diff] [blame] | 1247 | clear_local_APIC(); |
| 1248 | |
Alex Nixon | 8227dce | 2008-08-22 11:52:14 +0100 | [diff] [blame] | 1249 | cpu_disable_common(); |
Glauber Costa | 69c18c1 | 2008-03-03 14:13:07 -0300 | [diff] [blame] | 1250 | return 0; |
| 1251 | } |
| 1252 | |
Alex Nixon | 93be71b | 2008-08-22 11:52:11 +0100 | [diff] [blame] | 1253 | void native_cpu_die(unsigned int cpu) |
Glauber Costa | 69c18c1 | 2008-03-03 14:13:07 -0300 | [diff] [blame] | 1254 | { |
| 1255 | /* We don't do anything here: idle task is faking death itself. */ |
| 1256 | unsigned int i; |
| 1257 | |
| 1258 | for (i = 0; i < 10; i++) { |
| 1259 | /* They ack this in play_dead by setting CPU_DEAD */ |
| 1260 | if (per_cpu(cpu_state, cpu) == CPU_DEAD) { |
Mike Travis | 2eaad1f | 2009-12-10 17:19:36 -0800 | [diff] [blame] | 1261 | if (system_state == SYSTEM_RUNNING) |
| 1262 | pr_info("CPU %u is now offline\n", cpu); |
| 1263 | |
Glauber Costa | 69c18c1 | 2008-03-03 14:13:07 -0300 | [diff] [blame] | 1264 | if (1 == num_online_cpus()) |
| 1265 | alternatives_smp_switch(0); |
| 1266 | return; |
| 1267 | } |
| 1268 | msleep(100); |
| 1269 | } |
Mike Travis | 2eaad1f | 2009-12-10 17:19:36 -0800 | [diff] [blame] | 1270 | pr_err("CPU %u didn't die...\n", cpu); |
Glauber Costa | 69c18c1 | 2008-03-03 14:13:07 -0300 | [diff] [blame] | 1271 | } |
Alex Nixon | a21f5d88 | 2008-08-22 11:52:13 +0100 | [diff] [blame] | 1272 | |
| 1273 | void play_dead_common(void) |
| 1274 | { |
| 1275 | idle_task_exit(); |
| 1276 | reset_lazy_tlbstate(); |
Len Brown | 02c68a0 | 2011-04-01 16:59:53 -0400 | [diff] [blame] | 1277 | amd_e400_remove_cpu(raw_smp_processor_id()); |
Alex Nixon | a21f5d88 | 2008-08-22 11:52:13 +0100 | [diff] [blame] | 1278 | |
| 1279 | mb(); |
| 1280 | /* Ack it */ |
Tejun Heo | 0a3aee0 | 2010-12-18 16:28:55 +0100 | [diff] [blame] | 1281 | __this_cpu_write(cpu_state, CPU_DEAD); |
Alex Nixon | a21f5d88 | 2008-08-22 11:52:13 +0100 | [diff] [blame] | 1282 | |
| 1283 | /* |
| 1284 | * With physical CPU hotplug, we should halt the cpu |
| 1285 | */ |
| 1286 | local_irq_disable(); |
| 1287 | } |
| 1288 | |
H. Peter Anvin | ea53069 | 2010-09-17 15:39:11 -0700 | [diff] [blame] | 1289 | /* |
| 1290 | * We need to flush the caches before going to sleep, lest we have |
| 1291 | * dirty data in our caches when we come back up. |
| 1292 | */ |
| 1293 | static inline void mwait_play_dead(void) |
| 1294 | { |
| 1295 | unsigned int eax, ebx, ecx, edx; |
| 1296 | unsigned int highest_cstate = 0; |
| 1297 | unsigned int highest_subcstate = 0; |
| 1298 | int i; |
H. Peter Anvin | ce5f682 | 2010-09-20 13:04:45 -0700 | [diff] [blame] | 1299 | void *mwait_ptr; |
Borislav Petkov | 93789b3 | 2011-01-20 15:42:52 +0100 | [diff] [blame] | 1300 | struct cpuinfo_x86 *c = __this_cpu_ptr(&cpu_info); |
H. Peter Anvin | ea53069 | 2010-09-17 15:39:11 -0700 | [diff] [blame] | 1301 | |
Avi Kivity | 4f3c125 | 2011-05-30 08:23:57 -0400 | [diff] [blame] | 1302 | if (!(this_cpu_has(X86_FEATURE_MWAIT) && mwait_usable(c))) |
H. Peter Anvin | ea53069 | 2010-09-17 15:39:11 -0700 | [diff] [blame] | 1303 | return; |
Christoph Lameter | 349c004 | 2011-03-12 12:50:10 +0100 | [diff] [blame] | 1304 | if (!this_cpu_has(X86_FEATURE_CLFLSH)) |
H. Peter Anvin | ce5f682 | 2010-09-20 13:04:45 -0700 | [diff] [blame] | 1305 | return; |
Tejun Heo | 7b543a5 | 2010-12-18 16:30:05 +0100 | [diff] [blame] | 1306 | if (__this_cpu_read(cpu_info.cpuid_level) < CPUID_MWAIT_LEAF) |
H. Peter Anvin | ea53069 | 2010-09-17 15:39:11 -0700 | [diff] [blame] | 1307 | return; |
| 1308 | |
| 1309 | eax = CPUID_MWAIT_LEAF; |
| 1310 | ecx = 0; |
| 1311 | native_cpuid(&eax, &ebx, &ecx, &edx); |
| 1312 | |
| 1313 | /* |
| 1314 | * eax will be 0 if EDX enumeration is not valid. |
| 1315 | * Initialized below to cstate, sub_cstate value when EDX is valid. |
| 1316 | */ |
| 1317 | if (!(ecx & CPUID5_ECX_EXTENSIONS_SUPPORTED)) { |
| 1318 | eax = 0; |
| 1319 | } else { |
| 1320 | edx >>= MWAIT_SUBSTATE_SIZE; |
| 1321 | for (i = 0; i < 7 && edx; i++, edx >>= MWAIT_SUBSTATE_SIZE) { |
| 1322 | if (edx & MWAIT_SUBSTATE_MASK) { |
| 1323 | highest_cstate = i; |
| 1324 | highest_subcstate = edx & MWAIT_SUBSTATE_MASK; |
| 1325 | } |
| 1326 | } |
| 1327 | eax = (highest_cstate << MWAIT_SUBSTATE_SIZE) | |
| 1328 | (highest_subcstate - 1); |
| 1329 | } |
| 1330 | |
H. Peter Anvin | ce5f682 | 2010-09-20 13:04:45 -0700 | [diff] [blame] | 1331 | /* |
| 1332 | * This should be a memory location in a cache line which is |
| 1333 | * unlikely to be touched by other processors. The actual |
| 1334 | * content is immaterial as it is not actually modified in any way. |
| 1335 | */ |
| 1336 | mwait_ptr = ¤t_thread_info()->flags; |
| 1337 | |
H. Peter Anvin | a68e5c9 | 2010-09-17 17:06:46 -0700 | [diff] [blame] | 1338 | wbinvd(); |
| 1339 | |
H. Peter Anvin | ea53069 | 2010-09-17 15:39:11 -0700 | [diff] [blame] | 1340 | while (1) { |
H. Peter Anvin | ce5f682 | 2010-09-20 13:04:45 -0700 | [diff] [blame] | 1341 | /* |
| 1342 | * The CLFLUSH is a workaround for erratum AAI65 for |
| 1343 | * the Xeon 7400 series. It's not clear it is actually |
| 1344 | * needed, but it should be harmless in either case. |
| 1345 | * The WBINVD is insufficient due to the spurious-wakeup |
| 1346 | * case where we return around the loop. |
| 1347 | */ |
| 1348 | clflush(mwait_ptr); |
| 1349 | __monitor(mwait_ptr, 0, 0); |
H. Peter Anvin | ea53069 | 2010-09-17 15:39:11 -0700 | [diff] [blame] | 1350 | mb(); |
| 1351 | __mwait(eax, 0); |
| 1352 | } |
| 1353 | } |
| 1354 | |
| 1355 | static inline void hlt_play_dead(void) |
| 1356 | { |
Tejun Heo | 7b543a5 | 2010-12-18 16:30:05 +0100 | [diff] [blame] | 1357 | if (__this_cpu_read(cpu_info.x86) >= 4) |
H. Peter Anvin | a68e5c9 | 2010-09-17 17:06:46 -0700 | [diff] [blame] | 1358 | wbinvd(); |
| 1359 | |
H. Peter Anvin | ea53069 | 2010-09-17 15:39:11 -0700 | [diff] [blame] | 1360 | while (1) { |
H. Peter Anvin | ea53069 | 2010-09-17 15:39:11 -0700 | [diff] [blame] | 1361 | native_halt(); |
| 1362 | } |
| 1363 | } |
| 1364 | |
Alex Nixon | a21f5d88 | 2008-08-22 11:52:13 +0100 | [diff] [blame] | 1365 | void native_play_dead(void) |
| 1366 | { |
| 1367 | play_dead_common(); |
Joseph Cihula | 86886e5 | 2009-06-30 19:31:07 -0700 | [diff] [blame] | 1368 | tboot_shutdown(TB_SHUTDOWN_WFS); |
H. Peter Anvin | ea53069 | 2010-09-17 15:39:11 -0700 | [diff] [blame] | 1369 | |
| 1370 | mwait_play_dead(); /* Only returns on failure */ |
Boris Ostrovsky | 1a022e3 | 2012-03-13 19:55:09 +0100 | [diff] [blame] | 1371 | if (cpuidle_play_dead()) |
| 1372 | hlt_play_dead(); |
Alex Nixon | a21f5d88 | 2008-08-22 11:52:13 +0100 | [diff] [blame] | 1373 | } |
| 1374 | |
Glauber Costa | 69c18c1 | 2008-03-03 14:13:07 -0300 | [diff] [blame] | 1375 | #else /* ... !CONFIG_HOTPLUG_CPU */ |
Alex Nixon | 93be71b | 2008-08-22 11:52:11 +0100 | [diff] [blame] | 1376 | int native_cpu_disable(void) |
Glauber Costa | 69c18c1 | 2008-03-03 14:13:07 -0300 | [diff] [blame] | 1377 | { |
| 1378 | return -ENOSYS; |
| 1379 | } |
| 1380 | |
Alex Nixon | 93be71b | 2008-08-22 11:52:11 +0100 | [diff] [blame] | 1381 | void native_cpu_die(unsigned int cpu) |
Glauber Costa | 69c18c1 | 2008-03-03 14:13:07 -0300 | [diff] [blame] | 1382 | { |
| 1383 | /* We said "no" in __cpu_disable */ |
| 1384 | BUG(); |
| 1385 | } |
Alex Nixon | a21f5d88 | 2008-08-22 11:52:13 +0100 | [diff] [blame] | 1386 | |
| 1387 | void native_play_dead(void) |
| 1388 | { |
| 1389 | BUG(); |
| 1390 | } |
| 1391 | |
Glauber Costa | 68a1c3f | 2008-03-03 14:12:42 -0300 | [diff] [blame] | 1392 | #endif |