Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * x86 SMP booting functions |
| 3 | * |
| 4 | * (c) 1995 Alan Cox, Building #3 <alan@redhat.com> |
| 5 | * (c) 1998, 1999, 2000 Ingo Molnar <mingo@redhat.com> |
| 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 | * |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 15 | * This code is released under the GNU General Public License version 2 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | * |
| 17 | * Fixes |
| 18 | * Felix Koop : NR_CPUS used properly |
| 19 | * Jose Renau : Handle single CPU case. |
| 20 | * Alan Cox : By repeated request 8) - Total BogoMIP report. |
| 21 | * Greg Wright : Fix for kernel stacks panic. |
| 22 | * Erich Boleyn : MP v1.4 and additional changes. |
| 23 | * Matthias Sattler : Changes for 2.1 kernel map. |
| 24 | * Michel Lespinasse : Changes for 2.1 kernel map. |
| 25 | * Michael Chastain : Change trampoline.S to gnu as. |
| 26 | * Alan Cox : Dumb bug: 'B' step PPro's are fine |
| 27 | * Ingo Molnar : Added APIC timers, based on code |
| 28 | * from Jose Renau |
| 29 | * Ingo Molnar : various cleanups and rewrites |
| 30 | * Tigran Aivazian : fixed "0.00 in /proc/uptime on SMP" bug. |
| 31 | * Maciej W. Rozycki : Bits for genuine 82489DX APICs |
| 32 | * Andi Kleen : Changed for SMP boot into long mode. |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 33 | * Rusty Russell : Hacked into shape for new "hotplug" boot process. |
| 34 | * Andi Kleen : Converted to new state machine. |
| 35 | * Various cleanups. |
| 36 | * Probably mostly hotplug CPU ready now. |
Ashok Raj | 76e4f66 | 2005-06-25 14:55:00 -0700 | [diff] [blame] | 37 | * Ashok Raj : CPU hotplug support |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | */ |
| 39 | |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 40 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | #include <linux/init.h> |
| 42 | |
| 43 | #include <linux/mm.h> |
| 44 | #include <linux/kernel_stat.h> |
| 45 | #include <linux/smp_lock.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | #include <linux/bootmem.h> |
| 47 | #include <linux/thread_info.h> |
| 48 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | #include <linux/delay.h> |
| 50 | #include <linux/mc146818rtc.h> |
Andrew Morton | a3bc0db | 2006-09-25 23:32:33 -0700 | [diff] [blame] | 51 | #include <linux/smp.h> |
| 52 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | #include <asm/mtrr.h> |
| 54 | #include <asm/pgalloc.h> |
| 55 | #include <asm/desc.h> |
| 56 | #include <asm/kdebug.h> |
| 57 | #include <asm/tlbflush.h> |
| 58 | #include <asm/proto.h> |
Andi Kleen | 7515211 | 2005-05-16 21:53:34 -0700 | [diff] [blame] | 59 | #include <asm/nmi.h> |
Al Viro | 9cdd304 | 2005-09-12 18:49:25 +0200 | [diff] [blame] | 60 | #include <asm/irq.h> |
| 61 | #include <asm/hw_irq.h> |
Ravikiran G Thirumalai | 488fc08 | 2006-02-07 12:58:23 -0800 | [diff] [blame] | 62 | #include <asm/numa.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | |
| 64 | /* Number of siblings per CPU package */ |
| 65 | int smp_num_siblings = 1; |
Andi Kleen | 2ee60e17 | 2006-06-26 13:59:44 +0200 | [diff] [blame] | 66 | EXPORT_SYMBOL(smp_num_siblings); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | |
Siddha, Suresh B | 1e9f28f | 2006-03-27 01:15:22 -0800 | [diff] [blame] | 68 | /* Last level cache ID of each logical CPU */ |
| 69 | u8 cpu_llc_id[NR_CPUS] __cpuinitdata = {[0 ... NR_CPUS-1] = BAD_APICID}; |
Andi Kleen | 2ee60e17 | 2006-06-26 13:59:44 +0200 | [diff] [blame] | 70 | EXPORT_SYMBOL(cpu_llc_id); |
Siddha, Suresh B | 1e9f28f | 2006-03-27 01:15:22 -0800 | [diff] [blame] | 71 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | /* Bitmask of currently online CPUs */ |
Ravikiran G Thirumalai | 6c231b7 | 2005-09-06 15:17:45 -0700 | [diff] [blame] | 73 | cpumask_t cpu_online_map __read_mostly; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 75 | EXPORT_SYMBOL(cpu_online_map); |
| 76 | |
| 77 | /* |
| 78 | * Private maps to synchronize booting between AP and BP. |
| 79 | * Probably not needed anymore, but it makes for easier debugging. -AK |
| 80 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | cpumask_t cpu_callin_map; |
| 82 | cpumask_t cpu_callout_map; |
Andi Kleen | 2ee60e17 | 2006-06-26 13:59:44 +0200 | [diff] [blame] | 83 | EXPORT_SYMBOL(cpu_callout_map); |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 84 | |
| 85 | cpumask_t cpu_possible_map; |
| 86 | EXPORT_SYMBOL(cpu_possible_map); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | |
| 88 | /* Per CPU bogomips and other parameters */ |
| 89 | struct cpuinfo_x86 cpu_data[NR_CPUS] __cacheline_aligned; |
Andi Kleen | 2ee60e17 | 2006-06-26 13:59:44 +0200 | [diff] [blame] | 90 | EXPORT_SYMBOL(cpu_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 92 | /* Set when the idlers are all forked */ |
| 93 | int smp_threads_ready; |
| 94 | |
Siddha, Suresh B | 94605ef | 2005-11-05 17:25:54 +0100 | [diff] [blame] | 95 | /* representing HT siblings of each logical CPU */ |
Ravikiran G Thirumalai | 6c231b7 | 2005-09-06 15:17:45 -0700 | [diff] [blame] | 96 | cpumask_t cpu_sibling_map[NR_CPUS] __read_mostly; |
Andi Kleen | 2ee60e17 | 2006-06-26 13:59:44 +0200 | [diff] [blame] | 97 | EXPORT_SYMBOL(cpu_sibling_map); |
Siddha, Suresh B | 94605ef | 2005-11-05 17:25:54 +0100 | [diff] [blame] | 98 | |
| 99 | /* representing HT and core siblings of each logical CPU */ |
Ravikiran G Thirumalai | 6c231b7 | 2005-09-06 15:17:45 -0700 | [diff] [blame] | 100 | cpumask_t cpu_core_map[NR_CPUS] __read_mostly; |
Andi Kleen | 2df9fa3 | 2005-05-20 14:27:59 -0700 | [diff] [blame] | 101 | EXPORT_SYMBOL(cpu_core_map); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | |
| 103 | /* |
| 104 | * Trampoline 80x86 program as an array. |
| 105 | */ |
| 106 | |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 107 | extern unsigned char trampoline_data[]; |
| 108 | extern unsigned char trampoline_end[]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | |
Ashok Raj | 76e4f66 | 2005-06-25 14:55:00 -0700 | [diff] [blame] | 110 | /* State of each CPU */ |
| 111 | DEFINE_PER_CPU(int, cpu_state) = { 0 }; |
| 112 | |
| 113 | /* |
| 114 | * Store all idle threads, this can be reused instead of creating |
| 115 | * a new thread. Also avoids complicated thread destroy functionality |
| 116 | * for idle threads. |
| 117 | */ |
| 118 | struct task_struct *idle_thread_array[NR_CPUS] __cpuinitdata ; |
| 119 | |
| 120 | #define get_idle_for_cpu(x) (idle_thread_array[(x)]) |
| 121 | #define set_idle_for_cpu(x,p) (idle_thread_array[(x)] = (p)) |
| 122 | |
| 123 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | * Currently trivial. Write the real->protected mode |
| 125 | * bootstrap into the page concerned. The caller |
| 126 | * has made sure it's suitably aligned. |
| 127 | */ |
| 128 | |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 129 | static unsigned long __cpuinit setup_trampoline(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | { |
| 131 | void *tramp = __va(SMP_TRAMPOLINE_BASE); |
| 132 | memcpy(tramp, trampoline_data, trampoline_end - trampoline_data); |
| 133 | return virt_to_phys(tramp); |
| 134 | } |
| 135 | |
| 136 | /* |
| 137 | * The bootstrap kernel entry code has set these up. Save them for |
| 138 | * a given CPU |
| 139 | */ |
| 140 | |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 141 | static void __cpuinit smp_store_cpu_info(int id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | { |
| 143 | struct cpuinfo_x86 *c = cpu_data + id; |
| 144 | |
| 145 | *c = boot_cpu_data; |
| 146 | identify_cpu(c); |
Andi Kleen | dda50e7 | 2005-05-16 21:53:25 -0700 | [diff] [blame] | 147 | print_cpu_info(c); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | } |
| 149 | |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 150 | static atomic_t init_deasserted __cpuinitdata; |
| 151 | |
| 152 | /* |
| 153 | * Report back to the Boot Processor. |
| 154 | * Running on AP. |
| 155 | */ |
| 156 | void __cpuinit smp_callin(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | { |
| 158 | int cpuid, phys_id; |
| 159 | unsigned long timeout; |
| 160 | |
| 161 | /* |
| 162 | * If waken up by an INIT in an 82489DX configuration |
| 163 | * we may get here before an INIT-deassert IPI reaches |
| 164 | * our local APIC. We have to wait for the IPI or we'll |
| 165 | * lock up on an APIC access. |
| 166 | */ |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 167 | while (!atomic_read(&init_deasserted)) |
| 168 | cpu_relax(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | |
| 170 | /* |
| 171 | * (This works even if the APIC is not enabled.) |
| 172 | */ |
| 173 | phys_id = GET_APIC_ID(apic_read(APIC_ID)); |
| 174 | cpuid = smp_processor_id(); |
| 175 | if (cpu_isset(cpuid, cpu_callin_map)) { |
| 176 | panic("smp_callin: phys CPU#%d, CPU#%d already present??\n", |
| 177 | phys_id, cpuid); |
| 178 | } |
| 179 | Dprintk("CPU#%d (phys ID: %d) waiting for CALLOUT\n", cpuid, phys_id); |
| 180 | |
| 181 | /* |
| 182 | * STARTUP IPIs are fragile beasts as they might sometimes |
| 183 | * trigger some glue motherboard logic. Complete APIC bus |
| 184 | * silence for 1 second, this overestimates the time the |
| 185 | * boot CPU is spending to send the up to 2 STARTUP IPIs |
| 186 | * by a factor of two. This should be enough. |
| 187 | */ |
| 188 | |
| 189 | /* |
| 190 | * Waiting 2s total for startup (udelay is not yet working) |
| 191 | */ |
| 192 | timeout = jiffies + 2*HZ; |
| 193 | while (time_before(jiffies, timeout)) { |
| 194 | /* |
| 195 | * Has the boot CPU finished it's STARTUP sequence? |
| 196 | */ |
| 197 | if (cpu_isset(cpuid, cpu_callout_map)) |
| 198 | break; |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 199 | cpu_relax(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | if (!time_before(jiffies, timeout)) { |
| 203 | panic("smp_callin: CPU%d started up but did not get a callout!\n", |
| 204 | cpuid); |
| 205 | } |
| 206 | |
| 207 | /* |
| 208 | * the boot CPU has finished the init stage and is spinning |
| 209 | * on callin_map until we finish. We are free to set up this |
| 210 | * CPU, first the APIC. (this is probably redundant on most |
| 211 | * boards) |
| 212 | */ |
| 213 | |
| 214 | Dprintk("CALLIN, before setup_local_APIC().\n"); |
| 215 | setup_local_APIC(); |
| 216 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | /* |
| 218 | * Get our bogomips. |
Andi Kleen | b445221 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 219 | * |
| 220 | * Need to enable IRQs because it can take longer and then |
| 221 | * the NMI watchdog might kill us. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | */ |
Andi Kleen | b445221 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 223 | local_irq_enable(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | calibrate_delay(); |
Andi Kleen | b445221 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 225 | local_irq_disable(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | Dprintk("Stack at about %p\n",&cpuid); |
| 227 | |
| 228 | disable_APIC_timer(); |
| 229 | |
| 230 | /* |
| 231 | * Save our processor parameters |
| 232 | */ |
| 233 | smp_store_cpu_info(cpuid); |
| 234 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | /* |
| 236 | * Allow the master to continue. |
| 237 | */ |
| 238 | cpu_set(cpuid, cpu_callin_map); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | } |
| 240 | |
Siddha, Suresh B | 1e9f28f | 2006-03-27 01:15:22 -0800 | [diff] [blame] | 241 | /* maps the cpu to the sched domain representing multi-core */ |
| 242 | cpumask_t cpu_coregroup_map(int cpu) |
| 243 | { |
| 244 | struct cpuinfo_x86 *c = cpu_data + cpu; |
| 245 | /* |
| 246 | * For perf, we return last level cache shared map. |
Siddha, Suresh B | 5c45bf2 | 2006-06-27 02:54:42 -0700 | [diff] [blame] | 247 | * And for power savings, we return cpu_core_map |
Siddha, Suresh B | 1e9f28f | 2006-03-27 01:15:22 -0800 | [diff] [blame] | 248 | */ |
Siddha, Suresh B | 5c45bf2 | 2006-06-27 02:54:42 -0700 | [diff] [blame] | 249 | if (sched_mc_power_savings || sched_smt_power_savings) |
| 250 | return cpu_core_map[cpu]; |
| 251 | else |
| 252 | return c->llc_shared_map; |
Siddha, Suresh B | 1e9f28f | 2006-03-27 01:15:22 -0800 | [diff] [blame] | 253 | } |
| 254 | |
Siddha, Suresh B | 94605ef | 2005-11-05 17:25:54 +0100 | [diff] [blame] | 255 | /* representing cpus for which sibling maps can be computed */ |
| 256 | static cpumask_t cpu_sibling_setup_map; |
| 257 | |
Ashok Raj | cb0cd8d | 2005-06-25 14:55:01 -0700 | [diff] [blame] | 258 | static inline void set_cpu_sibling_map(int cpu) |
| 259 | { |
| 260 | int i; |
Siddha, Suresh B | 94605ef | 2005-11-05 17:25:54 +0100 | [diff] [blame] | 261 | struct cpuinfo_x86 *c = cpu_data; |
| 262 | |
| 263 | cpu_set(cpu, cpu_sibling_setup_map); |
Ashok Raj | cb0cd8d | 2005-06-25 14:55:01 -0700 | [diff] [blame] | 264 | |
| 265 | if (smp_num_siblings > 1) { |
Siddha, Suresh B | 94605ef | 2005-11-05 17:25:54 +0100 | [diff] [blame] | 266 | for_each_cpu_mask(i, cpu_sibling_setup_map) { |
Rohit Seth | f3fa8eb | 2006-06-26 13:58:17 +0200 | [diff] [blame] | 267 | if (c[cpu].phys_proc_id == c[i].phys_proc_id && |
| 268 | c[cpu].cpu_core_id == c[i].cpu_core_id) { |
Ashok Raj | cb0cd8d | 2005-06-25 14:55:01 -0700 | [diff] [blame] | 269 | cpu_set(i, cpu_sibling_map[cpu]); |
| 270 | cpu_set(cpu, cpu_sibling_map[i]); |
Siddha, Suresh B | 94605ef | 2005-11-05 17:25:54 +0100 | [diff] [blame] | 271 | cpu_set(i, cpu_core_map[cpu]); |
| 272 | cpu_set(cpu, cpu_core_map[i]); |
Siddha, Suresh B | 1e9f28f | 2006-03-27 01:15:22 -0800 | [diff] [blame] | 273 | cpu_set(i, c[cpu].llc_shared_map); |
| 274 | cpu_set(cpu, c[i].llc_shared_map); |
Ashok Raj | cb0cd8d | 2005-06-25 14:55:01 -0700 | [diff] [blame] | 275 | } |
| 276 | } |
| 277 | } else { |
| 278 | cpu_set(cpu, cpu_sibling_map[cpu]); |
| 279 | } |
| 280 | |
Siddha, Suresh B | 1e9f28f | 2006-03-27 01:15:22 -0800 | [diff] [blame] | 281 | cpu_set(cpu, c[cpu].llc_shared_map); |
| 282 | |
Siddha, Suresh B | 94605ef | 2005-11-05 17:25:54 +0100 | [diff] [blame] | 283 | if (current_cpu_data.x86_max_cores == 1) { |
Ashok Raj | cb0cd8d | 2005-06-25 14:55:01 -0700 | [diff] [blame] | 284 | cpu_core_map[cpu] = cpu_sibling_map[cpu]; |
Siddha, Suresh B | 94605ef | 2005-11-05 17:25:54 +0100 | [diff] [blame] | 285 | c[cpu].booted_cores = 1; |
| 286 | return; |
| 287 | } |
| 288 | |
| 289 | for_each_cpu_mask(i, cpu_sibling_setup_map) { |
Siddha, Suresh B | 1e9f28f | 2006-03-27 01:15:22 -0800 | [diff] [blame] | 290 | if (cpu_llc_id[cpu] != BAD_APICID && |
| 291 | cpu_llc_id[cpu] == cpu_llc_id[i]) { |
| 292 | cpu_set(i, c[cpu].llc_shared_map); |
| 293 | cpu_set(cpu, c[i].llc_shared_map); |
| 294 | } |
Rohit Seth | f3fa8eb | 2006-06-26 13:58:17 +0200 | [diff] [blame] | 295 | if (c[cpu].phys_proc_id == c[i].phys_proc_id) { |
Siddha, Suresh B | 94605ef | 2005-11-05 17:25:54 +0100 | [diff] [blame] | 296 | cpu_set(i, cpu_core_map[cpu]); |
| 297 | cpu_set(cpu, cpu_core_map[i]); |
| 298 | /* |
| 299 | * Does this new cpu bringup a new core? |
| 300 | */ |
| 301 | if (cpus_weight(cpu_sibling_map[cpu]) == 1) { |
| 302 | /* |
| 303 | * for each core in package, increment |
| 304 | * the booted_cores for this new cpu |
| 305 | */ |
| 306 | if (first_cpu(cpu_sibling_map[i]) == i) |
| 307 | c[cpu].booted_cores++; |
| 308 | /* |
| 309 | * increment the core count for all |
| 310 | * the other cpus in this package |
| 311 | */ |
| 312 | if (i != cpu) |
| 313 | c[i].booted_cores++; |
| 314 | } else if (i != cpu && !c[cpu].booted_cores) |
| 315 | c[cpu].booted_cores = c[i].booted_cores; |
| 316 | } |
Ashok Raj | cb0cd8d | 2005-06-25 14:55:01 -0700 | [diff] [blame] | 317 | } |
| 318 | } |
| 319 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | /* |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 321 | * Setup code on secondary processor (after comming out of the trampoline) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | */ |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 323 | void __cpuinit start_secondary(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | { |
| 325 | /* |
| 326 | * Dont put anything before smp_callin(), SMP |
| 327 | * booting is too fragile that we want to limit the |
| 328 | * things done here to the most necessary things. |
| 329 | */ |
| 330 | cpu_init(); |
Nick Piggin | 5bfb5d6 | 2005-11-08 21:39:01 -0800 | [diff] [blame] | 331 | preempt_disable(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | smp_callin(); |
| 333 | |
| 334 | /* otherwise gcc will move up the smp_processor_id before the cpu_init */ |
| 335 | barrier(); |
| 336 | |
Ingo Molnar | 95492e4 | 2007-02-16 01:27:34 -0800 | [diff] [blame] | 337 | /* |
| 338 | * Check TSC sync first: |
| 339 | */ |
| 340 | check_tsc_sync_target(); |
| 341 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | Dprintk("cpu %d: setting up apic clock\n", smp_processor_id()); |
| 343 | setup_secondary_APIC_clock(); |
| 344 | |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 345 | Dprintk("cpu %d: enabling apic timer\n", smp_processor_id()); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | |
| 347 | if (nmi_watchdog == NMI_IO_APIC) { |
| 348 | disable_8259A_irq(0); |
| 349 | enable_NMI_through_LVT0(NULL); |
| 350 | enable_8259A_irq(0); |
| 351 | } |
| 352 | |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 353 | enable_APIC_timer(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | |
| 355 | /* |
Ashok Raj | cb0cd8d | 2005-06-25 14:55:01 -0700 | [diff] [blame] | 356 | * The sibling maps must be set before turing the online map on for |
| 357 | * this cpu |
| 358 | */ |
| 359 | set_cpu_sibling_map(smp_processor_id()); |
| 360 | |
| 361 | /* |
Ashok Raj | 884d9e4 | 2005-06-25 14:55:02 -0700 | [diff] [blame] | 362 | * We need to hold call_lock, so there is no inconsistency |
| 363 | * between the time smp_call_function() determines number of |
| 364 | * IPI receipients, and the time when the determination is made |
| 365 | * for which cpus receive the IPI in genapic_flat.c. Holding this |
| 366 | * lock helps us to not include this cpu in a currently in progress |
| 367 | * smp_call_function(). |
| 368 | */ |
| 369 | lock_ipi_call_lock(); |
Eric W. Biederman | 70a0a53 | 2006-10-25 01:00:23 +0200 | [diff] [blame] | 370 | spin_lock(&vector_lock); |
Ashok Raj | 884d9e4 | 2005-06-25 14:55:02 -0700 | [diff] [blame] | 371 | |
Eric W. Biederman | 70a0a53 | 2006-10-25 01:00:23 +0200 | [diff] [blame] | 372 | /* Setup the per cpu irq handling data structures */ |
| 373 | __setup_vector_irq(smp_processor_id()); |
Ashok Raj | 884d9e4 | 2005-06-25 14:55:02 -0700 | [diff] [blame] | 374 | /* |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 375 | * Allow the master to continue. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | cpu_set(smp_processor_id(), cpu_online_map); |
Ashok Raj | 884d9e4 | 2005-06-25 14:55:02 -0700 | [diff] [blame] | 378 | per_cpu(cpu_state, smp_processor_id()) = CPU_ONLINE; |
Eric W. Biederman | 70a0a53 | 2006-10-25 01:00:23 +0200 | [diff] [blame] | 379 | spin_unlock(&vector_lock); |
Ingo Molnar | 95492e4 | 2007-02-16 01:27:34 -0800 | [diff] [blame] | 380 | |
Ashok Raj | 884d9e4 | 2005-06-25 14:55:02 -0700 | [diff] [blame] | 381 | unlock_ipi_call_lock(); |
| 382 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | cpu_idle(); |
| 384 | } |
| 385 | |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 386 | extern volatile unsigned long init_rsp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | extern void (*initial_code)(void); |
| 388 | |
Olaf Hering | 44456d3 | 2005-07-27 11:45:17 -0700 | [diff] [blame] | 389 | #ifdef APIC_DEBUG |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 390 | static void inquire_remote_apic(int apicid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | { |
| 392 | unsigned i, regs[] = { APIC_ID >> 4, APIC_LVR >> 4, APIC_SPIV >> 4 }; |
| 393 | char *names[] = { "ID", "VERSION", "SPIV" }; |
| 394 | int timeout, status; |
| 395 | |
| 396 | printk(KERN_INFO "Inquiring remote APIC #%d...\n", apicid); |
| 397 | |
| 398 | for (i = 0; i < sizeof(regs) / sizeof(*regs); i++) { |
| 399 | printk("... APIC #%d %s: ", apicid, names[i]); |
| 400 | |
| 401 | /* |
| 402 | * Wait for idle. |
| 403 | */ |
| 404 | apic_wait_icr_idle(); |
| 405 | |
Andi Kleen | c1507eb | 2005-09-12 18:49:23 +0200 | [diff] [blame] | 406 | apic_write(APIC_ICR2, SET_APIC_DEST_FIELD(apicid)); |
| 407 | apic_write(APIC_ICR, APIC_DM_REMRD | regs[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | |
| 409 | timeout = 0; |
| 410 | do { |
| 411 | udelay(100); |
| 412 | status = apic_read(APIC_ICR) & APIC_ICR_RR_MASK; |
| 413 | } while (status == APIC_ICR_RR_INPROG && timeout++ < 1000); |
| 414 | |
| 415 | switch (status) { |
| 416 | case APIC_ICR_RR_VALID: |
| 417 | status = apic_read(APIC_RRR); |
| 418 | printk("%08x\n", status); |
| 419 | break; |
| 420 | default: |
| 421 | printk("failed\n"); |
| 422 | } |
| 423 | } |
| 424 | } |
| 425 | #endif |
| 426 | |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 427 | /* |
| 428 | * Kick the secondary to wake up. |
| 429 | */ |
| 430 | static int __cpuinit wakeup_secondary_via_INIT(int phys_apicid, unsigned int start_rip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | { |
Fernando Luis VazquezCao | ea8c733 | 2007-05-02 19:27:17 +0200 | [diff] [blame^] | 432 | unsigned long send_status, accept_status = 0; |
| 433 | int maxlvt, num_starts, j; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | |
| 435 | Dprintk("Asserting INIT.\n"); |
| 436 | |
| 437 | /* |
| 438 | * Turn INIT on target chip |
| 439 | */ |
Andi Kleen | c1507eb | 2005-09-12 18:49:23 +0200 | [diff] [blame] | 440 | apic_write(APIC_ICR2, SET_APIC_DEST_FIELD(phys_apicid)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | |
| 442 | /* |
| 443 | * Send IPI |
| 444 | */ |
Andi Kleen | c1507eb | 2005-09-12 18:49:23 +0200 | [diff] [blame] | 445 | apic_write(APIC_ICR, APIC_INT_LEVELTRIG | APIC_INT_ASSERT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | | APIC_DM_INIT); |
| 447 | |
| 448 | Dprintk("Waiting for send to finish...\n"); |
Fernando Luis VazquezCao | ea8c733 | 2007-05-02 19:27:17 +0200 | [diff] [blame^] | 449 | send_status = safe_apic_wait_icr_idle(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | |
| 451 | mdelay(10); |
| 452 | |
| 453 | Dprintk("Deasserting INIT.\n"); |
| 454 | |
| 455 | /* Target chip */ |
Andi Kleen | c1507eb | 2005-09-12 18:49:23 +0200 | [diff] [blame] | 456 | apic_write(APIC_ICR2, SET_APIC_DEST_FIELD(phys_apicid)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | |
| 458 | /* Send IPI */ |
Andi Kleen | c1507eb | 2005-09-12 18:49:23 +0200 | [diff] [blame] | 459 | apic_write(APIC_ICR, APIC_INT_LEVELTRIG | APIC_DM_INIT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | |
| 461 | Dprintk("Waiting for send to finish...\n"); |
Fernando Luis VazquezCao | ea8c733 | 2007-05-02 19:27:17 +0200 | [diff] [blame^] | 462 | send_status = safe_apic_wait_icr_idle(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | |
Benjamin LaHaise | f2ecfab | 2006-01-11 22:43:03 +0100 | [diff] [blame] | 464 | mb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | atomic_set(&init_deasserted, 1); |
| 466 | |
Andi Kleen | 5a40b7c | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 467 | num_starts = 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | |
| 469 | /* |
| 470 | * Run STARTUP IPI loop. |
| 471 | */ |
| 472 | Dprintk("#startup loops: %d.\n", num_starts); |
| 473 | |
| 474 | maxlvt = get_maxlvt(); |
| 475 | |
| 476 | for (j = 1; j <= num_starts; j++) { |
| 477 | Dprintk("Sending STARTUP #%d.\n",j); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | apic_write(APIC_ESR, 0); |
| 479 | apic_read(APIC_ESR); |
| 480 | Dprintk("After apic_write.\n"); |
| 481 | |
| 482 | /* |
| 483 | * STARTUP IPI |
| 484 | */ |
| 485 | |
| 486 | /* Target chip */ |
Andi Kleen | c1507eb | 2005-09-12 18:49:23 +0200 | [diff] [blame] | 487 | apic_write(APIC_ICR2, SET_APIC_DEST_FIELD(phys_apicid)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | |
| 489 | /* Boot on the stack */ |
| 490 | /* Kick the second */ |
Andi Kleen | c1507eb | 2005-09-12 18:49:23 +0200 | [diff] [blame] | 491 | apic_write(APIC_ICR, APIC_DM_STARTUP | (start_rip >> 12)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | |
| 493 | /* |
| 494 | * Give the other CPU some time to accept the IPI. |
| 495 | */ |
| 496 | udelay(300); |
| 497 | |
| 498 | Dprintk("Startup point 1.\n"); |
| 499 | |
| 500 | Dprintk("Waiting for send to finish...\n"); |
Fernando Luis VazquezCao | ea8c733 | 2007-05-02 19:27:17 +0200 | [diff] [blame^] | 501 | send_status = safe_apic_wait_icr_idle(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | |
| 503 | /* |
| 504 | * Give the other CPU some time to accept the IPI. |
| 505 | */ |
| 506 | udelay(200); |
| 507 | /* |
| 508 | * Due to the Pentium erratum 3AP. |
| 509 | */ |
| 510 | if (maxlvt > 3) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | apic_write(APIC_ESR, 0); |
| 512 | } |
| 513 | accept_status = (apic_read(APIC_ESR) & 0xEF); |
| 514 | if (send_status || accept_status) |
| 515 | break; |
| 516 | } |
| 517 | Dprintk("After Startup.\n"); |
| 518 | |
| 519 | if (send_status) |
| 520 | printk(KERN_ERR "APIC never delivered???\n"); |
| 521 | if (accept_status) |
| 522 | printk(KERN_ERR "APIC delivery error (%lx).\n", accept_status); |
| 523 | |
| 524 | return (send_status | accept_status); |
| 525 | } |
| 526 | |
Ashok Raj | 76e4f66 | 2005-06-25 14:55:00 -0700 | [diff] [blame] | 527 | struct create_idle { |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 528 | struct work_struct work; |
Ashok Raj | 76e4f66 | 2005-06-25 14:55:00 -0700 | [diff] [blame] | 529 | struct task_struct *idle; |
| 530 | struct completion done; |
| 531 | int cpu; |
| 532 | }; |
| 533 | |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 534 | void do_fork_idle(struct work_struct *work) |
Ashok Raj | 76e4f66 | 2005-06-25 14:55:00 -0700 | [diff] [blame] | 535 | { |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 536 | struct create_idle *c_idle = |
| 537 | container_of(work, struct create_idle, work); |
Ashok Raj | 76e4f66 | 2005-06-25 14:55:00 -0700 | [diff] [blame] | 538 | |
| 539 | c_idle->idle = fork_idle(c_idle->cpu); |
| 540 | complete(&c_idle->done); |
| 541 | } |
| 542 | |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 543 | /* |
| 544 | * Boot one CPU. |
| 545 | */ |
| 546 | static int __cpuinit do_boot_cpu(int cpu, int apicid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | unsigned long boot_error; |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 549 | int timeout; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | unsigned long start_rip; |
Ashok Raj | 76e4f66 | 2005-06-25 14:55:00 -0700 | [diff] [blame] | 551 | struct create_idle c_idle = { |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 552 | .work = __WORK_INITIALIZER(c_idle.work, do_fork_idle), |
Ashok Raj | 76e4f66 | 2005-06-25 14:55:00 -0700 | [diff] [blame] | 553 | .cpu = cpu, |
Ingo Molnar | f86bf9b | 2006-07-10 04:44:05 -0700 | [diff] [blame] | 554 | .done = COMPLETION_INITIALIZER_ONSTACK(c_idle.done), |
Ashok Raj | 76e4f66 | 2005-06-25 14:55:00 -0700 | [diff] [blame] | 555 | }; |
Ashok Raj | 76e4f66 | 2005-06-25 14:55:00 -0700 | [diff] [blame] | 556 | |
Ravikiran G Thirumalai | c11efdf | 2006-01-11 22:43:57 +0100 | [diff] [blame] | 557 | /* allocate memory for gdts of secondary cpus. Hotplug is considered */ |
| 558 | if (!cpu_gdt_descr[cpu].address && |
| 559 | !(cpu_gdt_descr[cpu].address = get_zeroed_page(GFP_KERNEL))) { |
| 560 | printk(KERN_ERR "Failed to allocate GDT for CPU %d\n", cpu); |
| 561 | return -1; |
| 562 | } |
| 563 | |
Ravikiran G Thirumalai | 365ba91 | 2006-01-11 22:45:42 +0100 | [diff] [blame] | 564 | /* Allocate node local memory for AP pdas */ |
| 565 | if (cpu_pda(cpu) == &boot_cpu_pda[cpu]) { |
| 566 | struct x8664_pda *newpda, *pda; |
| 567 | int node = cpu_to_node(cpu); |
| 568 | pda = cpu_pda(cpu); |
| 569 | newpda = kmalloc_node(sizeof (struct x8664_pda), GFP_ATOMIC, |
| 570 | node); |
| 571 | if (newpda) { |
| 572 | memcpy(newpda, pda, sizeof (struct x8664_pda)); |
| 573 | cpu_pda(cpu) = newpda; |
| 574 | } else |
| 575 | printk(KERN_ERR |
| 576 | "Could not allocate node local PDA for CPU %d on node %d\n", |
| 577 | cpu, node); |
| 578 | } |
| 579 | |
Gerd Hoffmann | d167a51 | 2006-06-26 13:56:16 +0200 | [diff] [blame] | 580 | alternatives_smp_switch(1); |
| 581 | |
Ashok Raj | 76e4f66 | 2005-06-25 14:55:00 -0700 | [diff] [blame] | 582 | c_idle.idle = get_idle_for_cpu(cpu); |
| 583 | |
| 584 | if (c_idle.idle) { |
| 585 | c_idle.idle->thread.rsp = (unsigned long) (((struct pt_regs *) |
Al Viro | 57eafdc | 2006-01-12 01:05:39 -0800 | [diff] [blame] | 586 | (THREAD_SIZE + task_stack_page(c_idle.idle))) - 1); |
Ashok Raj | 76e4f66 | 2005-06-25 14:55:00 -0700 | [diff] [blame] | 587 | init_idle(c_idle.idle, cpu); |
| 588 | goto do_rest; |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 589 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | |
Ashok Raj | 76e4f66 | 2005-06-25 14:55:00 -0700 | [diff] [blame] | 591 | /* |
| 592 | * During cold boot process, keventd thread is not spun up yet. |
| 593 | * When we do cpu hot-add, we create idle threads on the fly, we should |
| 594 | * not acquire any attributes from the calling context. Hence the clean |
| 595 | * way to create kernel_threads() is to do that from keventd(). |
| 596 | * We do the current_is_keventd() due to the fact that ACPI notifier |
| 597 | * was also queuing to keventd() and when the caller is already running |
| 598 | * in context of keventd(), we would end up with locking up the keventd |
| 599 | * thread. |
| 600 | */ |
| 601 | if (!keventd_up() || current_is_keventd()) |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 602 | c_idle.work.func(&c_idle.work); |
Ashok Raj | 76e4f66 | 2005-06-25 14:55:00 -0700 | [diff] [blame] | 603 | else { |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 604 | schedule_work(&c_idle.work); |
Ashok Raj | 76e4f66 | 2005-06-25 14:55:00 -0700 | [diff] [blame] | 605 | wait_for_completion(&c_idle.done); |
| 606 | } |
| 607 | |
| 608 | if (IS_ERR(c_idle.idle)) { |
| 609 | printk("failed fork for CPU %d\n", cpu); |
| 610 | return PTR_ERR(c_idle.idle); |
| 611 | } |
| 612 | |
| 613 | set_idle_for_cpu(cpu, c_idle.idle); |
| 614 | |
| 615 | do_rest: |
| 616 | |
Ravikiran G Thirumalai | df79efd | 2006-01-11 22:45:39 +0100 | [diff] [blame] | 617 | cpu_pda(cpu)->pcurrent = c_idle.idle; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | |
| 619 | start_rip = setup_trampoline(); |
| 620 | |
Ashok Raj | 76e4f66 | 2005-06-25 14:55:00 -0700 | [diff] [blame] | 621 | init_rsp = c_idle.idle->thread.rsp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | per_cpu(init_tss,cpu).rsp0 = init_rsp; |
| 623 | initial_code = start_secondary; |
Al Viro | e4f17c4 | 2006-01-12 01:05:38 -0800 | [diff] [blame] | 624 | clear_tsk_thread_flag(c_idle.idle, TIF_FORK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | |
Andi Kleen | de04f32 | 2005-07-28 21:15:29 -0700 | [diff] [blame] | 626 | printk(KERN_INFO "Booting processor %d/%d APIC 0x%x\n", cpu, |
| 627 | cpus_weight(cpu_present_map), |
| 628 | apicid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | |
| 630 | /* |
| 631 | * This grunge runs the startup process for |
| 632 | * the targeted processor. |
| 633 | */ |
| 634 | |
| 635 | atomic_set(&init_deasserted, 0); |
| 636 | |
| 637 | Dprintk("Setting warm reset code and vector.\n"); |
| 638 | |
| 639 | CMOS_WRITE(0xa, 0xf); |
| 640 | local_flush_tlb(); |
| 641 | Dprintk("1.\n"); |
| 642 | *((volatile unsigned short *) phys_to_virt(0x469)) = start_rip >> 4; |
| 643 | Dprintk("2.\n"); |
| 644 | *((volatile unsigned short *) phys_to_virt(0x467)) = start_rip & 0xf; |
| 645 | Dprintk("3.\n"); |
| 646 | |
| 647 | /* |
| 648 | * Be paranoid about clearing APIC errors. |
| 649 | */ |
Andi Kleen | 11a8e77 | 2006-01-11 22:46:51 +0100 | [diff] [blame] | 650 | apic_write(APIC_ESR, 0); |
| 651 | apic_read(APIC_ESR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | |
| 653 | /* |
| 654 | * Status is now clean |
| 655 | */ |
| 656 | boot_error = 0; |
| 657 | |
| 658 | /* |
| 659 | * Starting actual IPI sequence... |
| 660 | */ |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 661 | boot_error = wakeup_secondary_via_INIT(apicid, start_rip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | |
| 663 | if (!boot_error) { |
| 664 | /* |
| 665 | * allow APs to start initializing. |
| 666 | */ |
| 667 | Dprintk("Before Callout %d.\n", cpu); |
| 668 | cpu_set(cpu, cpu_callout_map); |
| 669 | Dprintk("After Callout %d.\n", cpu); |
| 670 | |
| 671 | /* |
| 672 | * Wait 5s total for a response |
| 673 | */ |
| 674 | for (timeout = 0; timeout < 50000; timeout++) { |
| 675 | if (cpu_isset(cpu, cpu_callin_map)) |
| 676 | break; /* It has booted */ |
| 677 | udelay(100); |
| 678 | } |
| 679 | |
| 680 | if (cpu_isset(cpu, cpu_callin_map)) { |
| 681 | /* number CPUs logically, starting from 1 (BSP is 0) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | Dprintk("CPU has booted.\n"); |
| 683 | } else { |
| 684 | boot_error = 1; |
| 685 | if (*((volatile unsigned char *)phys_to_virt(SMP_TRAMPOLINE_BASE)) |
| 686 | == 0xA5) |
| 687 | /* trampoline started but...? */ |
| 688 | printk("Stuck ??\n"); |
| 689 | else |
| 690 | /* trampoline code not run */ |
| 691 | printk("Not responding.\n"); |
Olaf Hering | 44456d3 | 2005-07-27 11:45:17 -0700 | [diff] [blame] | 692 | #ifdef APIC_DEBUG |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | inquire_remote_apic(apicid); |
| 694 | #endif |
| 695 | } |
| 696 | } |
| 697 | if (boot_error) { |
| 698 | cpu_clear(cpu, cpu_callout_map); /* was set here (do_boot_cpu()) */ |
| 699 | clear_bit(cpu, &cpu_initialized); /* was set by cpu_init() */ |
Ravikiran G Thirumalai | 488fc08 | 2006-02-07 12:58:23 -0800 | [diff] [blame] | 700 | clear_node_cpumask(cpu); /* was set by numa_add_cpu */ |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 701 | cpu_clear(cpu, cpu_present_map); |
| 702 | cpu_clear(cpu, cpu_possible_map); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | x86_cpu_to_apicid[cpu] = BAD_APICID; |
| 704 | x86_cpu_to_log_apicid[cpu] = BAD_APICID; |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 705 | return -EIO; |
| 706 | } |
| 707 | |
| 708 | return 0; |
| 709 | } |
| 710 | |
| 711 | cycles_t cacheflush_time; |
| 712 | unsigned long cache_decay_ticks; |
| 713 | |
| 714 | /* |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 715 | * Cleanup possible dangling ends... |
| 716 | */ |
| 717 | static __cpuinit void smp_cleanup_boot(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 718 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | /* |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 720 | * Paranoid: Set warm reset code and vector here back |
| 721 | * to default values. |
| 722 | */ |
| 723 | CMOS_WRITE(0, 0xf); |
| 724 | |
| 725 | /* |
| 726 | * Reset trampoline flag |
| 727 | */ |
| 728 | *((volatile int *) phys_to_virt(0x467)) = 0; |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 729 | } |
| 730 | |
| 731 | /* |
| 732 | * Fall back to non SMP mode after errors. |
| 733 | * |
| 734 | * RED-PEN audit/test this more. I bet there is more state messed up here. |
| 735 | */ |
Ashok Raj | e6982c6 | 2005-06-25 14:54:58 -0700 | [diff] [blame] | 736 | static __init void disable_smp(void) |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 737 | { |
| 738 | cpu_present_map = cpumask_of_cpu(0); |
| 739 | cpu_possible_map = cpumask_of_cpu(0); |
| 740 | if (smp_found_config) |
| 741 | phys_cpu_present_map = physid_mask_of_physid(boot_cpu_id); |
| 742 | else |
| 743 | phys_cpu_present_map = physid_mask_of_physid(0); |
| 744 | cpu_set(0, cpu_sibling_map[0]); |
| 745 | cpu_set(0, cpu_core_map[0]); |
| 746 | } |
| 747 | |
Andi Kleen | 61b1b2d | 2005-07-28 21:15:27 -0700 | [diff] [blame] | 748 | #ifdef CONFIG_HOTPLUG_CPU |
Andi Kleen | 420f8f6 | 2005-11-05 17:25:54 +0100 | [diff] [blame] | 749 | |
| 750 | int additional_cpus __initdata = -1; |
| 751 | |
Andi Kleen | 61b1b2d | 2005-07-28 21:15:27 -0700 | [diff] [blame] | 752 | /* |
| 753 | * cpu_possible_map should be static, it cannot change as cpu's |
| 754 | * are onlined, or offlined. The reason is per-cpu data-structures |
| 755 | * are allocated by some modules at init time, and dont expect to |
| 756 | * do this dynamically on cpu arrival/departure. |
| 757 | * cpu_present_map on the other hand can change dynamically. |
| 758 | * In case when cpu_hotplug is not compiled, then we resort to current |
| 759 | * behaviour, which is cpu_possible == cpu_present. |
Andi Kleen | 61b1b2d | 2005-07-28 21:15:27 -0700 | [diff] [blame] | 760 | * - Ashok Raj |
Andi Kleen | 420f8f6 | 2005-11-05 17:25:54 +0100 | [diff] [blame] | 761 | * |
| 762 | * Three ways to find out the number of additional hotplug CPUs: |
| 763 | * - If the BIOS specified disabled CPUs in ACPI/mptables use that. |
Andi Kleen | 420f8f6 | 2005-11-05 17:25:54 +0100 | [diff] [blame] | 764 | * - The user can overwrite it with additional_cpus=NUM |
Andi Kleen | f62a91f | 2006-01-11 22:42:35 +0100 | [diff] [blame] | 765 | * - Otherwise don't reserve additional CPUs. |
Andi Kleen | 420f8f6 | 2005-11-05 17:25:54 +0100 | [diff] [blame] | 766 | * We do this because additional CPUs waste a lot of memory. |
| 767 | * -AK |
Andi Kleen | 61b1b2d | 2005-07-28 21:15:27 -0700 | [diff] [blame] | 768 | */ |
Andi Kleen | 421c7ce | 2005-10-10 22:32:45 +0200 | [diff] [blame] | 769 | __init void prefill_possible_map(void) |
Andi Kleen | 61b1b2d | 2005-07-28 21:15:27 -0700 | [diff] [blame] | 770 | { |
| 771 | int i; |
Andi Kleen | 420f8f6 | 2005-11-05 17:25:54 +0100 | [diff] [blame] | 772 | int possible; |
| 773 | |
| 774 | if (additional_cpus == -1) { |
Andi Kleen | f62a91f | 2006-01-11 22:42:35 +0100 | [diff] [blame] | 775 | if (disabled_cpus > 0) |
Andi Kleen | 420f8f6 | 2005-11-05 17:25:54 +0100 | [diff] [blame] | 776 | additional_cpus = disabled_cpus; |
Andi Kleen | f62a91f | 2006-01-11 22:42:35 +0100 | [diff] [blame] | 777 | else |
| 778 | additional_cpus = 0; |
Andi Kleen | 420f8f6 | 2005-11-05 17:25:54 +0100 | [diff] [blame] | 779 | } |
| 780 | possible = num_processors + additional_cpus; |
| 781 | if (possible > NR_CPUS) |
| 782 | possible = NR_CPUS; |
| 783 | |
| 784 | printk(KERN_INFO "SMP: Allowing %d CPUs, %d hotplug CPUs\n", |
| 785 | possible, |
| 786 | max_t(int, possible - num_processors, 0)); |
| 787 | |
| 788 | for (i = 0; i < possible; i++) |
Andi Kleen | 61b1b2d | 2005-07-28 21:15:27 -0700 | [diff] [blame] | 789 | cpu_set(i, cpu_possible_map); |
| 790 | } |
| 791 | #endif |
| 792 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 793 | /* |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 794 | * Various sanity checks. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | */ |
Ashok Raj | e6982c6 | 2005-06-25 14:54:58 -0700 | [diff] [blame] | 796 | static int __init smp_sanity_check(unsigned max_cpus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 797 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | if (!physid_isset(hard_smp_processor_id(), phys_cpu_present_map)) { |
| 799 | printk("weird, boot CPU (#%d) not listed by the BIOS.\n", |
| 800 | hard_smp_processor_id()); |
| 801 | physid_set(hard_smp_processor_id(), phys_cpu_present_map); |
| 802 | } |
| 803 | |
| 804 | /* |
| 805 | * If we couldn't find an SMP configuration at boot time, |
| 806 | * get out of here now! |
| 807 | */ |
| 808 | if (!smp_found_config) { |
| 809 | printk(KERN_NOTICE "SMP motherboard not detected.\n"); |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 810 | disable_smp(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 811 | if (APIC_init_uniprocessor()) |
| 812 | printk(KERN_NOTICE "Local APIC not detected." |
| 813 | " Using dummy APIC emulation.\n"); |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 814 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | } |
| 816 | |
| 817 | /* |
| 818 | * Should not be necessary because the MP table should list the boot |
| 819 | * CPU too, but we do it for the sake of robustness anyway. |
| 820 | */ |
| 821 | if (!physid_isset(boot_cpu_id, phys_cpu_present_map)) { |
| 822 | printk(KERN_NOTICE "weird, boot CPU (#%d) not listed by the BIOS.\n", |
| 823 | boot_cpu_id); |
| 824 | physid_set(hard_smp_processor_id(), phys_cpu_present_map); |
| 825 | } |
| 826 | |
| 827 | /* |
| 828 | * If we couldn't find a local APIC, then get out of here now! |
| 829 | */ |
Andi Kleen | 11a8e77 | 2006-01-11 22:46:51 +0100 | [diff] [blame] | 830 | if (!cpu_has_apic) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 831 | printk(KERN_ERR "BIOS bug, local APIC #%d not detected!...\n", |
| 832 | boot_cpu_id); |
| 833 | printk(KERN_ERR "... forcing use of dummy APIC emulation. (tell your hw vendor)\n"); |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 834 | nr_ioapics = 0; |
| 835 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 836 | } |
| 837 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 838 | /* |
| 839 | * If SMP should be disabled, then really disable it! |
| 840 | */ |
| 841 | if (!max_cpus) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 842 | printk(KERN_INFO "SMP mode deactivated, forcing use of dummy APIC emulation.\n"); |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 843 | nr_ioapics = 0; |
| 844 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 845 | } |
| 846 | |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 847 | return 0; |
| 848 | } |
| 849 | |
| 850 | /* |
| 851 | * Prepare for SMP bootup. The MP table or ACPI has been read |
| 852 | * earlier. Just do some sanity checking here and enable APIC mode. |
| 853 | */ |
Ashok Raj | e6982c6 | 2005-06-25 14:54:58 -0700 | [diff] [blame] | 854 | void __init smp_prepare_cpus(unsigned int max_cpus) |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 855 | { |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 856 | nmi_watchdog_default(); |
| 857 | current_cpu_data = boot_cpu_data; |
| 858 | current_thread_info()->cpu = 0; /* needed? */ |
Siddha, Suresh B | 94605ef | 2005-11-05 17:25:54 +0100 | [diff] [blame] | 859 | set_cpu_sibling_map(0); |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 860 | |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 861 | if (smp_sanity_check(max_cpus) < 0) { |
| 862 | printk(KERN_INFO "SMP disabled\n"); |
| 863 | disable_smp(); |
| 864 | return; |
| 865 | } |
| 866 | |
| 867 | |
| 868 | /* |
| 869 | * Switch from PIC to APIC mode. |
| 870 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 871 | setup_local_APIC(); |
| 872 | |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 873 | if (GET_APIC_ID(apic_read(APIC_ID)) != boot_cpu_id) { |
| 874 | panic("Boot APIC ID in local APIC unexpected (%d vs %d)", |
| 875 | GET_APIC_ID(apic_read(APIC_ID)), boot_cpu_id); |
| 876 | /* Or can we switch back to PIC here? */ |
| 877 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 878 | |
| 879 | /* |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 880 | * Now start the IO-APICs |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 881 | */ |
| 882 | if (!skip_ioapic_setup && nr_ioapics) |
| 883 | setup_IO_APIC(); |
| 884 | else |
| 885 | nr_ioapics = 0; |
| 886 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 887 | /* |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 888 | * Set up local APIC timer on boot CPU. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 889 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 890 | |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 891 | setup_boot_APIC_clock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 892 | } |
| 893 | |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 894 | /* |
| 895 | * Early setup to make printk work. |
| 896 | */ |
| 897 | void __init smp_prepare_boot_cpu(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 898 | { |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 899 | int me = smp_processor_id(); |
| 900 | cpu_set(me, cpu_online_map); |
| 901 | cpu_set(me, cpu_callout_map); |
Ashok Raj | 884d9e4 | 2005-06-25 14:55:02 -0700 | [diff] [blame] | 902 | per_cpu(cpu_state, me) = CPU_ONLINE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 903 | } |
| 904 | |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 905 | /* |
| 906 | * Entry point to boot a CPU. |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 907 | */ |
| 908 | int __cpuinit __cpu_up(unsigned int cpu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 909 | { |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 910 | int apicid = cpu_present_to_apicid(cpu); |
Ingo Molnar | d04f41e | 2007-03-07 18:12:31 +0100 | [diff] [blame] | 911 | unsigned long flags; |
| 912 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 913 | |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 914 | WARN_ON(irqs_disabled()); |
| 915 | |
| 916 | Dprintk("++++++++++++++++++++=_---CPU UP %u\n", cpu); |
| 917 | |
| 918 | if (apicid == BAD_APICID || apicid == boot_cpu_id || |
| 919 | !physid_isset(apicid, phys_cpu_present_map)) { |
| 920 | printk("__cpu_up: bad cpu %d\n", cpu); |
| 921 | return -EINVAL; |
| 922 | } |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 923 | |
Ashok Raj | 76e4f66 | 2005-06-25 14:55:00 -0700 | [diff] [blame] | 924 | /* |
| 925 | * Already booted CPU? |
| 926 | */ |
| 927 | if (cpu_isset(cpu, cpu_callin_map)) { |
| 928 | Dprintk("do_boot_cpu %d Already started\n", cpu); |
| 929 | return -ENOSYS; |
| 930 | } |
| 931 | |
Bernhard Kaindl | 2b1f627 | 2007-05-02 19:27:17 +0200 | [diff] [blame] | 932 | /* |
| 933 | * Save current MTRR state in case it was changed since early boot |
| 934 | * (e.g. by the ACPI SMI) to initialize new CPUs with MTRRs in sync: |
| 935 | */ |
| 936 | mtrr_save_state(); |
| 937 | |
Ashok Raj | 884d9e4 | 2005-06-25 14:55:02 -0700 | [diff] [blame] | 938 | per_cpu(cpu_state, cpu) = CPU_UP_PREPARE; |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 939 | /* Boot it! */ |
| 940 | err = do_boot_cpu(cpu, apicid); |
| 941 | if (err < 0) { |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 942 | Dprintk("do_boot_cpu failed %d\n", err); |
| 943 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 944 | } |
| 945 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 946 | /* Unleash the CPU! */ |
| 947 | Dprintk("waiting for cpu %d\n", cpu); |
| 948 | |
Ingo Molnar | 95492e4 | 2007-02-16 01:27:34 -0800 | [diff] [blame] | 949 | /* |
| 950 | * Make sure and check TSC sync: |
| 951 | */ |
Ingo Molnar | d04f41e | 2007-03-07 18:12:31 +0100 | [diff] [blame] | 952 | local_irq_save(flags); |
Ingo Molnar | 95492e4 | 2007-02-16 01:27:34 -0800 | [diff] [blame] | 953 | check_tsc_sync_source(cpu); |
Ingo Molnar | d04f41e | 2007-03-07 18:12:31 +0100 | [diff] [blame] | 954 | local_irq_restore(flags); |
Ingo Molnar | 95492e4 | 2007-02-16 01:27:34 -0800 | [diff] [blame] | 955 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 956 | while (!cpu_isset(cpu, cpu_online_map)) |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 957 | cpu_relax(); |
Ashok Raj | 76e4f66 | 2005-06-25 14:55:00 -0700 | [diff] [blame] | 958 | err = 0; |
| 959 | |
| 960 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 961 | } |
| 962 | |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 963 | /* |
| 964 | * Finish the SMP boot. |
| 965 | */ |
Ashok Raj | e6982c6 | 2005-06-25 14:54:58 -0700 | [diff] [blame] | 966 | void __init smp_cpus_done(unsigned int max_cpus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 967 | { |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 968 | smp_cleanup_boot(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 969 | setup_ioapic_dest(); |
Andi Kleen | 7515211 | 2005-05-16 21:53:34 -0700 | [diff] [blame] | 970 | check_nmi_watchdog(); |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 971 | } |
Ashok Raj | 76e4f66 | 2005-06-25 14:55:00 -0700 | [diff] [blame] | 972 | |
| 973 | #ifdef CONFIG_HOTPLUG_CPU |
| 974 | |
Ashok Raj | cb0cd8d | 2005-06-25 14:55:01 -0700 | [diff] [blame] | 975 | static void remove_siblinginfo(int cpu) |
Ashok Raj | 76e4f66 | 2005-06-25 14:55:00 -0700 | [diff] [blame] | 976 | { |
| 977 | int sibling; |
Siddha, Suresh B | 94605ef | 2005-11-05 17:25:54 +0100 | [diff] [blame] | 978 | struct cpuinfo_x86 *c = cpu_data; |
Ashok Raj | 76e4f66 | 2005-06-25 14:55:00 -0700 | [diff] [blame] | 979 | |
Siddha, Suresh B | 94605ef | 2005-11-05 17:25:54 +0100 | [diff] [blame] | 980 | for_each_cpu_mask(sibling, cpu_core_map[cpu]) { |
| 981 | cpu_clear(cpu, cpu_core_map[sibling]); |
| 982 | /* |
| 983 | * last thread sibling in this cpu core going down |
| 984 | */ |
| 985 | if (cpus_weight(cpu_sibling_map[cpu]) == 1) |
| 986 | c[sibling].booted_cores--; |
| 987 | } |
| 988 | |
Ashok Raj | 76e4f66 | 2005-06-25 14:55:00 -0700 | [diff] [blame] | 989 | for_each_cpu_mask(sibling, cpu_sibling_map[cpu]) |
| 990 | cpu_clear(cpu, cpu_sibling_map[sibling]); |
Ashok Raj | 76e4f66 | 2005-06-25 14:55:00 -0700 | [diff] [blame] | 991 | cpus_clear(cpu_sibling_map[cpu]); |
| 992 | cpus_clear(cpu_core_map[cpu]); |
Rohit Seth | f3fa8eb | 2006-06-26 13:58:17 +0200 | [diff] [blame] | 993 | c[cpu].phys_proc_id = 0; |
| 994 | c[cpu].cpu_core_id = 0; |
Siddha, Suresh B | 94605ef | 2005-11-05 17:25:54 +0100 | [diff] [blame] | 995 | cpu_clear(cpu, cpu_sibling_setup_map); |
Ashok Raj | 76e4f66 | 2005-06-25 14:55:00 -0700 | [diff] [blame] | 996 | } |
| 997 | |
| 998 | void remove_cpu_from_maps(void) |
| 999 | { |
| 1000 | int cpu = smp_processor_id(); |
| 1001 | |
| 1002 | cpu_clear(cpu, cpu_callout_map); |
| 1003 | cpu_clear(cpu, cpu_callin_map); |
| 1004 | clear_bit(cpu, &cpu_initialized); /* was set by cpu_init() */ |
Ravikiran G Thirumalai | 488fc08 | 2006-02-07 12:58:23 -0800 | [diff] [blame] | 1005 | clear_node_cpumask(cpu); |
Ashok Raj | 76e4f66 | 2005-06-25 14:55:00 -0700 | [diff] [blame] | 1006 | } |
| 1007 | |
| 1008 | int __cpu_disable(void) |
| 1009 | { |
| 1010 | int cpu = smp_processor_id(); |
| 1011 | |
| 1012 | /* |
| 1013 | * Perhaps use cpufreq to drop frequency, but that could go |
| 1014 | * into generic code. |
| 1015 | * |
| 1016 | * We won't take down the boot processor on i386 due to some |
| 1017 | * interrupts only being able to be serviced by the BSP. |
| 1018 | * Especially so if we're not using an IOAPIC -zwane |
| 1019 | */ |
| 1020 | if (cpu == 0) |
| 1021 | return -EBUSY; |
| 1022 | |
Shaohua Li | 4038f90 | 2006-09-26 10:52:27 +0200 | [diff] [blame] | 1023 | if (nmi_watchdog == NMI_LOCAL_APIC) |
| 1024 | stop_apic_nmi_watchdog(NULL); |
Shaohua Li | 5e9ef02 | 2005-12-12 22:17:08 -0800 | [diff] [blame] | 1025 | clear_local_APIC(); |
Ashok Raj | 76e4f66 | 2005-06-25 14:55:00 -0700 | [diff] [blame] | 1026 | |
| 1027 | /* |
| 1028 | * HACK: |
| 1029 | * Allow any queued timer interrupts to get serviced |
| 1030 | * This is only a temporary solution until we cleanup |
| 1031 | * fixup_irqs as we do for IA64. |
| 1032 | */ |
| 1033 | local_irq_enable(); |
| 1034 | mdelay(1); |
| 1035 | |
| 1036 | local_irq_disable(); |
| 1037 | remove_siblinginfo(cpu); |
| 1038 | |
Eric W. Biederman | 70a0a53 | 2006-10-25 01:00:23 +0200 | [diff] [blame] | 1039 | spin_lock(&vector_lock); |
Ashok Raj | 76e4f66 | 2005-06-25 14:55:00 -0700 | [diff] [blame] | 1040 | /* It's now safe to remove this processor from the online map */ |
| 1041 | cpu_clear(cpu, cpu_online_map); |
Eric W. Biederman | 70a0a53 | 2006-10-25 01:00:23 +0200 | [diff] [blame] | 1042 | spin_unlock(&vector_lock); |
Ashok Raj | 76e4f66 | 2005-06-25 14:55:00 -0700 | [diff] [blame] | 1043 | remove_cpu_from_maps(); |
| 1044 | fixup_irqs(cpu_online_map); |
| 1045 | return 0; |
| 1046 | } |
| 1047 | |
| 1048 | void __cpu_die(unsigned int cpu) |
| 1049 | { |
| 1050 | /* We don't do anything here: idle task is faking death itself. */ |
| 1051 | unsigned int i; |
| 1052 | |
| 1053 | for (i = 0; i < 10; i++) { |
| 1054 | /* They ack this in play_dead by setting CPU_DEAD */ |
Ashok Raj | 884d9e4 | 2005-06-25 14:55:02 -0700 | [diff] [blame] | 1055 | if (per_cpu(cpu_state, cpu) == CPU_DEAD) { |
| 1056 | printk ("CPU %d is now offline\n", cpu); |
Gerd Hoffmann | d167a51 | 2006-06-26 13:56:16 +0200 | [diff] [blame] | 1057 | if (1 == num_online_cpus()) |
| 1058 | alternatives_smp_switch(0); |
Ashok Raj | 76e4f66 | 2005-06-25 14:55:00 -0700 | [diff] [blame] | 1059 | return; |
Ashok Raj | 884d9e4 | 2005-06-25 14:55:02 -0700 | [diff] [blame] | 1060 | } |
Nishanth Aravamudan | ef6e525 | 2005-07-28 21:15:53 -0700 | [diff] [blame] | 1061 | msleep(100); |
Ashok Raj | 76e4f66 | 2005-06-25 14:55:00 -0700 | [diff] [blame] | 1062 | } |
| 1063 | printk(KERN_ERR "CPU %u didn't die...\n", cpu); |
| 1064 | } |
| 1065 | |
Andi Kleen | 2c8c0e6 | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 1066 | static __init int setup_additional_cpus(char *s) |
Andi Kleen | 420f8f6 | 2005-11-05 17:25:54 +0100 | [diff] [blame] | 1067 | { |
Andi Kleen | 2c8c0e6 | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 1068 | return s && get_option(&s, &additional_cpus) ? 0 : -EINVAL; |
Andi Kleen | 420f8f6 | 2005-11-05 17:25:54 +0100 | [diff] [blame] | 1069 | } |
Andi Kleen | 2c8c0e6 | 2006-09-26 10:52:32 +0200 | [diff] [blame] | 1070 | early_param("additional_cpus", setup_additional_cpus); |
Andi Kleen | 420f8f6 | 2005-11-05 17:25:54 +0100 | [diff] [blame] | 1071 | |
Ashok Raj | 76e4f66 | 2005-06-25 14:55:00 -0700 | [diff] [blame] | 1072 | #else /* ... !CONFIG_HOTPLUG_CPU */ |
| 1073 | |
| 1074 | int __cpu_disable(void) |
| 1075 | { |
| 1076 | return -ENOSYS; |
| 1077 | } |
| 1078 | |
| 1079 | void __cpu_die(unsigned int cpu) |
| 1080 | { |
| 1081 | /* We said "no" in __cpu_disable */ |
| 1082 | BUG(); |
| 1083 | } |
| 1084 | #endif /* CONFIG_HOTPLUG_CPU */ |