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> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #include <linux/bootmem.h> |
| 46 | #include <linux/thread_info.h> |
| 47 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | #include <linux/delay.h> |
| 49 | #include <linux/mc146818rtc.h> |
Andrew Morton | a3bc0db | 2006-09-25 23:32:33 -0700 | [diff] [blame] | 50 | #include <linux/smp.h> |
Christoph Hellwig | 1eeb66a | 2007-05-08 00:27:03 -0700 | [diff] [blame] | 51 | #include <linux/kdebug.h> |
Andrew Morton | a3bc0db | 2006-09-25 23:32:33 -0700 | [diff] [blame] | 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> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | #include <asm/tlbflush.h> |
| 57 | #include <asm/proto.h> |
Andi Kleen | 7515211 | 2005-05-16 21:53:34 -0700 | [diff] [blame] | 58 | #include <asm/nmi.h> |
Al Viro | 9cdd304 | 2005-09-12 18:49:25 +0200 | [diff] [blame] | 59 | #include <asm/irq.h> |
| 60 | #include <asm/hw_irq.h> |
Ravikiran G Thirumalai | 488fc08 | 2006-02-07 12:58:23 -0800 | [diff] [blame] | 61 | #include <asm/numa.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | |
Glauber de Oliveira Costa | 8d77010 | 2008-03-19 14:25:31 -0300 | [diff] [blame^] | 63 | #include <mach_wakecpu.h> |
| 64 | |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 65 | /* Set when the idlers are all forked */ |
| 66 | int smp_threads_ready; |
| 67 | |
Ashok Raj | 76e4f66 | 2005-06-25 14:55:00 -0700 | [diff] [blame] | 68 | /* State of each CPU */ |
| 69 | DEFINE_PER_CPU(int, cpu_state) = { 0 }; |
| 70 | |
| 71 | /* |
| 72 | * Store all idle threads, this can be reused instead of creating |
| 73 | * a new thread. Also avoids complicated thread destroy functionality |
| 74 | * for idle threads. |
| 75 | */ |
travis@sgi.com | 24b0d22 | 2008-01-30 13:33:11 +0100 | [diff] [blame] | 76 | #ifdef CONFIG_HOTPLUG_CPU |
| 77 | /* |
| 78 | * Needed only for CONFIG_HOTPLUG_CPU because __cpuinitdata is |
| 79 | * removed after init for !CONFIG_HOTPLUG_CPU. |
| 80 | */ |
| 81 | static DEFINE_PER_CPU(struct task_struct *, idle_thread_array); |
| 82 | #define get_idle_for_cpu(x) (per_cpu(idle_thread_array, x)) |
| 83 | #define set_idle_for_cpu(x,p) (per_cpu(idle_thread_array, x) = (p)) |
| 84 | #else |
Ashok Raj | 76e4f66 | 2005-06-25 14:55:00 -0700 | [diff] [blame] | 85 | struct task_struct *idle_thread_array[NR_CPUS] __cpuinitdata ; |
Ashok Raj | 76e4f66 | 2005-06-25 14:55:00 -0700 | [diff] [blame] | 86 | #define get_idle_for_cpu(x) (idle_thread_array[(x)]) |
| 87 | #define set_idle_for_cpu(x,p) (idle_thread_array[(x)] = (p)) |
travis@sgi.com | 24b0d22 | 2008-01-30 13:33:11 +0100 | [diff] [blame] | 88 | #endif |
| 89 | |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 90 | static atomic_t init_deasserted __cpuinitdata; |
| 91 | |
| 92 | /* |
| 93 | * Report back to the Boot Processor. |
| 94 | * Running on AP. |
| 95 | */ |
| 96 | void __cpuinit smp_callin(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | { |
| 98 | int cpuid, phys_id; |
| 99 | unsigned long timeout; |
| 100 | |
| 101 | /* |
| 102 | * If waken up by an INIT in an 82489DX configuration |
| 103 | * we may get here before an INIT-deassert IPI reaches |
| 104 | * our local APIC. We have to wait for the IPI or we'll |
| 105 | * lock up on an APIC access. |
| 106 | */ |
Glauber Costa | e90009b | 2008-03-03 14:13:13 -0300 | [diff] [blame] | 107 | wait_for_init_deassert(&init_deasserted); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | |
| 109 | /* |
| 110 | * (This works even if the APIC is not enabled.) |
| 111 | */ |
| 112 | phys_id = GET_APIC_ID(apic_read(APIC_ID)); |
| 113 | cpuid = smp_processor_id(); |
| 114 | if (cpu_isset(cpuid, cpu_callin_map)) { |
| 115 | panic("smp_callin: phys CPU#%d, CPU#%d already present??\n", |
| 116 | phys_id, cpuid); |
| 117 | } |
| 118 | Dprintk("CPU#%d (phys ID: %d) waiting for CALLOUT\n", cpuid, phys_id); |
| 119 | |
| 120 | /* |
| 121 | * STARTUP IPIs are fragile beasts as they might sometimes |
| 122 | * trigger some glue motherboard logic. Complete APIC bus |
| 123 | * silence for 1 second, this overestimates the time the |
| 124 | * boot CPU is spending to send the up to 2 STARTUP IPIs |
| 125 | * by a factor of two. This should be enough. |
| 126 | */ |
| 127 | |
| 128 | /* |
| 129 | * Waiting 2s total for startup (udelay is not yet working) |
| 130 | */ |
| 131 | timeout = jiffies + 2*HZ; |
| 132 | while (time_before(jiffies, timeout)) { |
| 133 | /* |
| 134 | * Has the boot CPU finished it's STARTUP sequence? |
| 135 | */ |
| 136 | if (cpu_isset(cpuid, cpu_callout_map)) |
| 137 | break; |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 138 | cpu_relax(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | if (!time_before(jiffies, timeout)) { |
| 142 | panic("smp_callin: CPU%d started up but did not get a callout!\n", |
| 143 | cpuid); |
| 144 | } |
| 145 | |
| 146 | /* |
| 147 | * the boot CPU has finished the init stage and is spinning |
| 148 | * on callin_map until we finish. We are free to set up this |
| 149 | * CPU, first the APIC. (this is probably redundant on most |
| 150 | * boards) |
| 151 | */ |
| 152 | |
| 153 | Dprintk("CALLIN, before setup_local_APIC().\n"); |
| 154 | setup_local_APIC(); |
Andi Kleen | 739f33b | 2008-01-30 13:30:40 +0100 | [diff] [blame] | 155 | end_local_APIC_setup(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | /* |
| 158 | * Get our bogomips. |
Andi Kleen | b445221 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 159 | * |
| 160 | * Need to enable IRQs because it can take longer and then |
| 161 | * the NMI watchdog might kill us. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | */ |
Andi Kleen | b445221 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 163 | local_irq_enable(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | calibrate_delay(); |
Andi Kleen | b445221 | 2005-09-12 18:49:24 +0200 | [diff] [blame] | 165 | local_irq_disable(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | Dprintk("Stack at about %p\n",&cpuid); |
| 167 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | /* |
| 169 | * Save our processor parameters |
| 170 | */ |
| 171 | smp_store_cpu_info(cpuid); |
| 172 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | /* |
| 174 | * Allow the master to continue. |
| 175 | */ |
| 176 | cpu_set(cpuid, cpu_callin_map); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | } |
| 178 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | /* |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 180 | * Setup code on secondary processor (after comming out of the trampoline) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | */ |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 182 | void __cpuinit start_secondary(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | { |
| 184 | /* |
| 185 | * Dont put anything before smp_callin(), SMP |
| 186 | * booting is too fragile that we want to limit the |
| 187 | * things done here to the most necessary things. |
| 188 | */ |
| 189 | cpu_init(); |
Nick Piggin | 5bfb5d6 | 2005-11-08 21:39:01 -0800 | [diff] [blame] | 190 | preempt_disable(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | smp_callin(); |
| 192 | |
| 193 | /* otherwise gcc will move up the smp_processor_id before the cpu_init */ |
| 194 | barrier(); |
| 195 | |
Ingo Molnar | 95492e4 | 2007-02-16 01:27:34 -0800 | [diff] [blame] | 196 | /* |
| 197 | * Check TSC sync first: |
| 198 | */ |
| 199 | check_tsc_sync_target(); |
| 200 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | if (nmi_watchdog == NMI_IO_APIC) { |
| 202 | disable_8259A_irq(0); |
Jan Beulich | e942710 | 2008-01-30 13:31:24 +0100 | [diff] [blame] | 203 | enable_NMI_through_LVT0(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | enable_8259A_irq(0); |
| 205 | } |
| 206 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | /* |
Ashok Raj | cb0cd8d | 2005-06-25 14:55:01 -0700 | [diff] [blame] | 208 | * The sibling maps must be set before turing the online map on for |
| 209 | * this cpu |
| 210 | */ |
| 211 | set_cpu_sibling_map(smp_processor_id()); |
| 212 | |
| 213 | /* |
Ashok Raj | 884d9e4 | 2005-06-25 14:55:02 -0700 | [diff] [blame] | 214 | * We need to hold call_lock, so there is no inconsistency |
| 215 | * between the time smp_call_function() determines number of |
Simon Arlott | 676b185 | 2007-10-20 01:25:36 +0200 | [diff] [blame] | 216 | * IPI recipients, and the time when the determination is made |
Ashok Raj | 884d9e4 | 2005-06-25 14:55:02 -0700 | [diff] [blame] | 217 | * for which cpus receive the IPI in genapic_flat.c. Holding this |
| 218 | * lock helps us to not include this cpu in a currently in progress |
| 219 | * smp_call_function(). |
| 220 | */ |
| 221 | lock_ipi_call_lock(); |
Eric W. Biederman | 70a0a53 | 2006-10-25 01:00:23 +0200 | [diff] [blame] | 222 | spin_lock(&vector_lock); |
Ashok Raj | 884d9e4 | 2005-06-25 14:55:02 -0700 | [diff] [blame] | 223 | |
Eric W. Biederman | 70a0a53 | 2006-10-25 01:00:23 +0200 | [diff] [blame] | 224 | /* Setup the per cpu irq handling data structures */ |
| 225 | __setup_vector_irq(smp_processor_id()); |
Ashok Raj | 884d9e4 | 2005-06-25 14:55:02 -0700 | [diff] [blame] | 226 | /* |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 227 | * Allow the master to continue. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | */ |
Glauber Costa | fc25da9 | 2008-03-03 14:13:04 -0300 | [diff] [blame] | 229 | spin_unlock(&vector_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | cpu_set(smp_processor_id(), cpu_online_map); |
Ashok Raj | 884d9e4 | 2005-06-25 14:55:02 -0700 | [diff] [blame] | 231 | unlock_ipi_call_lock(); |
| 232 | |
Glauber de Oliveira Costa | 5733f62 | 2008-03-19 14:25:09 -0300 | [diff] [blame] | 233 | per_cpu(cpu_state, smp_processor_id()) = CPU_ONLINE; |
| 234 | |
Glauber de Oliveira Costa | 746ef0c | 2008-01-30 13:31:11 +0100 | [diff] [blame] | 235 | setup_secondary_clock(); |
Thomas Gleixner | 3ac508b | 2007-10-14 22:57:45 +0200 | [diff] [blame] | 236 | |
Glauber de Oliveira Costa | fa8004d | 2008-03-19 14:25:12 -0300 | [diff] [blame] | 237 | wmb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | cpu_idle(); |
| 239 | } |
| 240 | |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 241 | extern volatile unsigned long init_rsp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | extern void (*initial_code)(void); |
| 243 | |
Olaf Hering | 44456d3 | 2005-07-27 11:45:17 -0700 | [diff] [blame] | 244 | #ifdef APIC_DEBUG |
Glauber de Oliveira Costa | 8d77010 | 2008-03-19 14:25:31 -0300 | [diff] [blame^] | 245 | static void __inquire_remote_apic(int apicid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | { |
| 247 | unsigned i, regs[] = { APIC_ID >> 4, APIC_LVR >> 4, APIC_SPIV >> 4 }; |
| 248 | char *names[] = { "ID", "VERSION", "SPIV" }; |
Fernando Luis VazquezCao | 3144c33 | 2007-05-02 19:27:17 +0200 | [diff] [blame] | 249 | int timeout; |
Thomas Gleixner | 3c6bb07 | 2008-01-30 13:30:15 +0100 | [diff] [blame] | 250 | u32 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | |
| 252 | printk(KERN_INFO "Inquiring remote APIC #%d...\n", apicid); |
| 253 | |
Alejandro Martinez Ruiz | 4d022ad | 2007-10-17 14:38:58 +0200 | [diff] [blame] | 254 | for (i = 0; i < ARRAY_SIZE(regs); i++) { |
Thomas Gleixner | 3c6bb07 | 2008-01-30 13:30:15 +0100 | [diff] [blame] | 255 | printk(KERN_INFO "... APIC #%d %s: ", apicid, names[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | |
| 257 | /* |
| 258 | * Wait for idle. |
| 259 | */ |
Fernando Luis VazquezCao | 3144c33 | 2007-05-02 19:27:17 +0200 | [diff] [blame] | 260 | status = safe_apic_wait_icr_idle(); |
| 261 | if (status) |
Thomas Gleixner | 3c6bb07 | 2008-01-30 13:30:15 +0100 | [diff] [blame] | 262 | printk(KERN_CONT |
| 263 | "a previous APIC delivery may have failed\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | |
Glauber de Oliveira Costa | 1af8a0c | 2008-03-19 14:24:58 -0300 | [diff] [blame] | 265 | apic_write_around(APIC_ICR2, SET_APIC_DEST_FIELD(apicid)); |
| 266 | apic_write_around(APIC_ICR, APIC_DM_REMRD | regs[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | |
| 268 | timeout = 0; |
| 269 | do { |
| 270 | udelay(100); |
| 271 | status = apic_read(APIC_ICR) & APIC_ICR_RR_MASK; |
| 272 | } while (status == APIC_ICR_RR_INPROG && timeout++ < 1000); |
| 273 | |
| 274 | switch (status) { |
| 275 | case APIC_ICR_RR_VALID: |
| 276 | status = apic_read(APIC_RRR); |
Thomas Gleixner | 3c6bb07 | 2008-01-30 13:30:15 +0100 | [diff] [blame] | 277 | printk(KERN_CONT "%08x\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | break; |
| 279 | default: |
Thomas Gleixner | 3c6bb07 | 2008-01-30 13:30:15 +0100 | [diff] [blame] | 280 | printk(KERN_CONT "failed\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | } |
| 282 | } |
| 283 | } |
| 284 | #endif |
| 285 | |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 286 | /* |
| 287 | * Kick the secondary to wake up. |
| 288 | */ |
| 289 | 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] | 290 | { |
Fernando Luis VazquezCao | ea8c733 | 2007-05-02 19:27:17 +0200 | [diff] [blame] | 291 | unsigned long send_status, accept_status = 0; |
| 292 | int maxlvt, num_starts, j; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | |
Glauber de Oliveira Costa | 148a30f | 2008-03-19 14:25:11 -0300 | [diff] [blame] | 294 | /* |
| 295 | * Be paranoid about clearing APIC errors. |
| 296 | */ |
| 297 | if (APIC_INTEGRATED(apic_version[phys_apicid])) { |
| 298 | apic_read_around(APIC_SPIV); |
| 299 | apic_write(APIC_ESR, 0); |
| 300 | apic_read(APIC_ESR); |
| 301 | } |
| 302 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | Dprintk("Asserting INIT.\n"); |
| 304 | |
| 305 | /* |
| 306 | * Turn INIT on target chip |
| 307 | */ |
Glauber de Oliveira Costa | 1af8a0c | 2008-03-19 14:24:58 -0300 | [diff] [blame] | 308 | apic_write_around(APIC_ICR2, SET_APIC_DEST_FIELD(phys_apicid)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | |
| 310 | /* |
| 311 | * Send IPI |
| 312 | */ |
Glauber de Oliveira Costa | 1af8a0c | 2008-03-19 14:24:58 -0300 | [diff] [blame] | 313 | apic_write_around(APIC_ICR, APIC_INT_LEVELTRIG | APIC_INT_ASSERT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | | APIC_DM_INIT); |
| 315 | |
| 316 | Dprintk("Waiting for send to finish...\n"); |
Fernando Luis VazquezCao | ea8c733 | 2007-05-02 19:27:17 +0200 | [diff] [blame] | 317 | send_status = safe_apic_wait_icr_idle(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | |
| 319 | mdelay(10); |
| 320 | |
| 321 | Dprintk("Deasserting INIT.\n"); |
| 322 | |
| 323 | /* Target chip */ |
Glauber de Oliveira Costa | 1af8a0c | 2008-03-19 14:24:58 -0300 | [diff] [blame] | 324 | apic_write_around(APIC_ICR2, SET_APIC_DEST_FIELD(phys_apicid)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | |
| 326 | /* Send IPI */ |
Glauber de Oliveira Costa | 1af8a0c | 2008-03-19 14:24:58 -0300 | [diff] [blame] | 327 | apic_write_around(APIC_ICR, APIC_INT_LEVELTRIG | APIC_DM_INIT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | |
| 329 | Dprintk("Waiting for send to finish...\n"); |
Fernando Luis VazquezCao | ea8c733 | 2007-05-02 19:27:17 +0200 | [diff] [blame] | 330 | send_status = safe_apic_wait_icr_idle(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | |
Benjamin LaHaise | f2ecfab | 2006-01-11 22:43:03 +0100 | [diff] [blame] | 332 | mb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | atomic_set(&init_deasserted, 1); |
| 334 | |
Glauber de Oliveira Costa | 148a30f | 2008-03-19 14:25:11 -0300 | [diff] [blame] | 335 | if (APIC_INTEGRATED(apic_version[phys_apicid])) |
| 336 | num_starts = 2; |
| 337 | else |
| 338 | num_starts = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | |
| 340 | /* |
Glauber de Oliveira Costa | d0173ae | 2008-03-19 14:24:59 -0300 | [diff] [blame] | 341 | * Paravirt / VMI wants a startup IPI hook here to set up the |
| 342 | * target processor state. |
| 343 | */ |
| 344 | startup_ipi_hook(phys_apicid, (unsigned long) start_secondary, |
| 345 | (unsigned long) init_rsp); |
| 346 | |
| 347 | |
| 348 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | * Run STARTUP IPI loop. |
| 350 | */ |
| 351 | Dprintk("#startup loops: %d.\n", num_starts); |
| 352 | |
Thomas Gleixner | 37e650c | 2008-01-30 13:30:14 +0100 | [diff] [blame] | 353 | maxlvt = lapic_get_maxlvt(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | |
| 355 | for (j = 1; j <= num_starts; j++) { |
| 356 | Dprintk("Sending STARTUP #%d.\n",j); |
Glauber de Oliveira Costa | 1af8a0c | 2008-03-19 14:24:58 -0300 | [diff] [blame] | 357 | apic_read_around(APIC_SPIV); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | apic_write(APIC_ESR, 0); |
| 359 | apic_read(APIC_ESR); |
| 360 | Dprintk("After apic_write.\n"); |
| 361 | |
| 362 | /* |
| 363 | * STARTUP IPI |
| 364 | */ |
| 365 | |
| 366 | /* Target chip */ |
Glauber de Oliveira Costa | 1af8a0c | 2008-03-19 14:24:58 -0300 | [diff] [blame] | 367 | apic_write_around(APIC_ICR2, SET_APIC_DEST_FIELD(phys_apicid)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | |
| 369 | /* Boot on the stack */ |
| 370 | /* Kick the second */ |
Glauber de Oliveira Costa | 1af8a0c | 2008-03-19 14:24:58 -0300 | [diff] [blame] | 371 | apic_write_around(APIC_ICR, APIC_DM_STARTUP | (start_rip>>12)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | |
| 373 | /* |
| 374 | * Give the other CPU some time to accept the IPI. |
| 375 | */ |
| 376 | udelay(300); |
| 377 | |
| 378 | Dprintk("Startup point 1.\n"); |
| 379 | |
| 380 | Dprintk("Waiting for send to finish...\n"); |
Fernando Luis VazquezCao | ea8c733 | 2007-05-02 19:27:17 +0200 | [diff] [blame] | 381 | send_status = safe_apic_wait_icr_idle(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | |
| 383 | /* |
| 384 | * Give the other CPU some time to accept the IPI. |
| 385 | */ |
| 386 | udelay(200); |
| 387 | /* |
| 388 | * Due to the Pentium erratum 3AP. |
| 389 | */ |
| 390 | if (maxlvt > 3) { |
Glauber de Oliveira Costa | 1af8a0c | 2008-03-19 14:24:58 -0300 | [diff] [blame] | 391 | apic_read_around(APIC_SPIV); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | apic_write(APIC_ESR, 0); |
| 393 | } |
| 394 | accept_status = (apic_read(APIC_ESR) & 0xEF); |
| 395 | if (send_status || accept_status) |
| 396 | break; |
| 397 | } |
| 398 | Dprintk("After Startup.\n"); |
| 399 | |
| 400 | if (send_status) |
| 401 | printk(KERN_ERR "APIC never delivered???\n"); |
| 402 | if (accept_status) |
| 403 | printk(KERN_ERR "APIC delivery error (%lx).\n", accept_status); |
| 404 | |
| 405 | return (send_status | accept_status); |
| 406 | } |
| 407 | |
Ashok Raj | 76e4f66 | 2005-06-25 14:55:00 -0700 | [diff] [blame] | 408 | struct create_idle { |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 409 | struct work_struct work; |
Ashok Raj | 76e4f66 | 2005-06-25 14:55:00 -0700 | [diff] [blame] | 410 | struct task_struct *idle; |
| 411 | struct completion done; |
| 412 | int cpu; |
| 413 | }; |
| 414 | |
Thomas Gleixner | a2b484a | 2008-01-09 00:18:28 +0100 | [diff] [blame] | 415 | static void __cpuinit do_fork_idle(struct work_struct *work) |
Ashok Raj | 76e4f66 | 2005-06-25 14:55:00 -0700 | [diff] [blame] | 416 | { |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 417 | struct create_idle *c_idle = |
| 418 | container_of(work, struct create_idle, work); |
Ashok Raj | 76e4f66 | 2005-06-25 14:55:00 -0700 | [diff] [blame] | 419 | |
| 420 | c_idle->idle = fork_idle(c_idle->cpu); |
| 421 | complete(&c_idle->done); |
| 422 | } |
| 423 | |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 424 | /* |
| 425 | * Boot one CPU. |
| 426 | */ |
| 427 | static int __cpuinit do_boot_cpu(int cpu, int apicid) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | unsigned long boot_error; |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 430 | int timeout; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | unsigned long start_rip; |
Ashok Raj | 76e4f66 | 2005-06-25 14:55:00 -0700 | [diff] [blame] | 432 | struct create_idle c_idle = { |
| 433 | .cpu = cpu, |
Ingo Molnar | f86bf9b | 2006-07-10 04:44:05 -0700 | [diff] [blame] | 434 | .done = COMPLETION_INITIALIZER_ONSTACK(c_idle.done), |
Ashok Raj | 76e4f66 | 2005-06-25 14:55:00 -0700 | [diff] [blame] | 435 | }; |
Glauber Costa | 2b775a2 | 2008-02-22 12:09:29 -0300 | [diff] [blame] | 436 | INIT_WORK(&c_idle.work, do_fork_idle); |
Ashok Raj | 76e4f66 | 2005-06-25 14:55:00 -0700 | [diff] [blame] | 437 | |
Ravikiran G Thirumalai | c11efdf | 2006-01-11 22:43:57 +0100 | [diff] [blame] | 438 | /* allocate memory for gdts of secondary cpus. Hotplug is considered */ |
| 439 | if (!cpu_gdt_descr[cpu].address && |
| 440 | !(cpu_gdt_descr[cpu].address = get_zeroed_page(GFP_KERNEL))) { |
| 441 | printk(KERN_ERR "Failed to allocate GDT for CPU %d\n", cpu); |
| 442 | return -1; |
| 443 | } |
| 444 | |
Ravikiran G Thirumalai | 365ba91 | 2006-01-11 22:45:42 +0100 | [diff] [blame] | 445 | /* Allocate node local memory for AP pdas */ |
| 446 | if (cpu_pda(cpu) == &boot_cpu_pda[cpu]) { |
| 447 | struct x8664_pda *newpda, *pda; |
| 448 | int node = cpu_to_node(cpu); |
| 449 | pda = cpu_pda(cpu); |
| 450 | newpda = kmalloc_node(sizeof (struct x8664_pda), GFP_ATOMIC, |
| 451 | node); |
| 452 | if (newpda) { |
| 453 | memcpy(newpda, pda, sizeof (struct x8664_pda)); |
| 454 | cpu_pda(cpu) = newpda; |
| 455 | } else |
| 456 | printk(KERN_ERR |
| 457 | "Could not allocate node local PDA for CPU %d on node %d\n", |
| 458 | cpu, node); |
| 459 | } |
| 460 | |
Gerd Hoffmann | d167a51 | 2006-06-26 13:56:16 +0200 | [diff] [blame] | 461 | alternatives_smp_switch(1); |
| 462 | |
Ashok Raj | 76e4f66 | 2005-06-25 14:55:00 -0700 | [diff] [blame] | 463 | c_idle.idle = get_idle_for_cpu(cpu); |
| 464 | |
| 465 | if (c_idle.idle) { |
H. Peter Anvin | faca622 | 2008-01-30 13:31:02 +0100 | [diff] [blame] | 466 | c_idle.idle->thread.sp = (unsigned long) (((struct pt_regs *) |
Al Viro | 57eafdc | 2006-01-12 01:05:39 -0800 | [diff] [blame] | 467 | (THREAD_SIZE + task_stack_page(c_idle.idle))) - 1); |
Ashok Raj | 76e4f66 | 2005-06-25 14:55:00 -0700 | [diff] [blame] | 468 | init_idle(c_idle.idle, cpu); |
| 469 | goto do_rest; |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 470 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | |
Ashok Raj | 76e4f66 | 2005-06-25 14:55:00 -0700 | [diff] [blame] | 472 | /* |
| 473 | * During cold boot process, keventd thread is not spun up yet. |
| 474 | * When we do cpu hot-add, we create idle threads on the fly, we should |
| 475 | * not acquire any attributes from the calling context. Hence the clean |
| 476 | * way to create kernel_threads() is to do that from keventd(). |
| 477 | * We do the current_is_keventd() due to the fact that ACPI notifier |
| 478 | * was also queuing to keventd() and when the caller is already running |
| 479 | * in context of keventd(), we would end up with locking up the keventd |
| 480 | * thread. |
| 481 | */ |
| 482 | if (!keventd_up() || current_is_keventd()) |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 483 | c_idle.work.func(&c_idle.work); |
Ashok Raj | 76e4f66 | 2005-06-25 14:55:00 -0700 | [diff] [blame] | 484 | else { |
David Howells | 65f27f3 | 2006-11-22 14:55:48 +0000 | [diff] [blame] | 485 | schedule_work(&c_idle.work); |
Ashok Raj | 76e4f66 | 2005-06-25 14:55:00 -0700 | [diff] [blame] | 486 | wait_for_completion(&c_idle.done); |
| 487 | } |
| 488 | |
| 489 | if (IS_ERR(c_idle.idle)) { |
| 490 | printk("failed fork for CPU %d\n", cpu); |
| 491 | return PTR_ERR(c_idle.idle); |
| 492 | } |
| 493 | |
| 494 | set_idle_for_cpu(cpu, c_idle.idle); |
| 495 | |
| 496 | do_rest: |
| 497 | |
Ravikiran G Thirumalai | df79efd | 2006-01-11 22:45:39 +0100 | [diff] [blame] | 498 | cpu_pda(cpu)->pcurrent = c_idle.idle; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | |
| 500 | start_rip = setup_trampoline(); |
| 501 | |
H. Peter Anvin | faca622 | 2008-01-30 13:31:02 +0100 | [diff] [blame] | 502 | init_rsp = c_idle.idle->thread.sp; |
Glauber de Oliveira Costa | 7818a1e | 2008-01-30 13:31:31 +0100 | [diff] [blame] | 503 | load_sp0(&per_cpu(init_tss, cpu), &c_idle.idle->thread); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | initial_code = start_secondary; |
Al Viro | e4f17c4 | 2006-01-12 01:05:38 -0800 | [diff] [blame] | 505 | clear_tsk_thread_flag(c_idle.idle, TIF_FORK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | |
Andi Kleen | de04f32 | 2005-07-28 21:15:29 -0700 | [diff] [blame] | 507 | printk(KERN_INFO "Booting processor %d/%d APIC 0x%x\n", cpu, |
| 508 | cpus_weight(cpu_present_map), |
| 509 | apicid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | |
| 511 | /* |
| 512 | * This grunge runs the startup process for |
| 513 | * the targeted processor. |
| 514 | */ |
| 515 | |
| 516 | atomic_set(&init_deasserted, 0); |
| 517 | |
| 518 | Dprintk("Setting warm reset code and vector.\n"); |
| 519 | |
| 520 | CMOS_WRITE(0xa, 0xf); |
| 521 | local_flush_tlb(); |
| 522 | Dprintk("1.\n"); |
| 523 | *((volatile unsigned short *) phys_to_virt(0x469)) = start_rip >> 4; |
| 524 | Dprintk("2.\n"); |
| 525 | *((volatile unsigned short *) phys_to_virt(0x467)) = start_rip & 0xf; |
| 526 | Dprintk("3.\n"); |
| 527 | |
| 528 | /* |
| 529 | * Be paranoid about clearing APIC errors. |
| 530 | */ |
Andi Kleen | 11a8e77 | 2006-01-11 22:46:51 +0100 | [diff] [blame] | 531 | apic_write(APIC_ESR, 0); |
| 532 | apic_read(APIC_ESR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | |
| 534 | /* |
| 535 | * Status is now clean |
| 536 | */ |
| 537 | boot_error = 0; |
| 538 | |
| 539 | /* |
| 540 | * Starting actual IPI sequence... |
| 541 | */ |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 542 | boot_error = wakeup_secondary_via_INIT(apicid, start_rip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | |
| 544 | if (!boot_error) { |
| 545 | /* |
| 546 | * allow APs to start initializing. |
| 547 | */ |
| 548 | Dprintk("Before Callout %d.\n", cpu); |
| 549 | cpu_set(cpu, cpu_callout_map); |
| 550 | Dprintk("After Callout %d.\n", cpu); |
| 551 | |
| 552 | /* |
| 553 | * Wait 5s total for a response |
| 554 | */ |
| 555 | for (timeout = 0; timeout < 50000; timeout++) { |
| 556 | if (cpu_isset(cpu, cpu_callin_map)) |
| 557 | break; /* It has booted */ |
| 558 | udelay(100); |
| 559 | } |
| 560 | |
| 561 | if (cpu_isset(cpu, cpu_callin_map)) { |
| 562 | /* number CPUs logically, starting from 1 (BSP is 0) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | Dprintk("CPU has booted.\n"); |
Glauber de Oliveira Costa | 4f3ab19 | 2008-03-19 14:25:01 -0300 | [diff] [blame] | 564 | printk(KERN_INFO "CPU%d: ", cpu); |
| 565 | print_cpu_info(&cpu_data(cpu)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 566 | } else { |
| 567 | boot_error = 1; |
| 568 | if (*((volatile unsigned char *)phys_to_virt(SMP_TRAMPOLINE_BASE)) |
| 569 | == 0xA5) |
| 570 | /* trampoline started but...? */ |
| 571 | printk("Stuck ??\n"); |
| 572 | else |
| 573 | /* trampoline code not run */ |
| 574 | printk("Not responding.\n"); |
Olaf Hering | 44456d3 | 2005-07-27 11:45:17 -0700 | [diff] [blame] | 575 | #ifdef APIC_DEBUG |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | inquire_remote_apic(apicid); |
| 577 | #endif |
| 578 | } |
| 579 | } |
| 580 | if (boot_error) { |
| 581 | cpu_clear(cpu, cpu_callout_map); /* was set here (do_boot_cpu()) */ |
Jeremy Fitzhardinge | 5548fec | 2008-01-30 13:30:55 +0100 | [diff] [blame] | 582 | clear_bit(cpu, (unsigned long *)&cpu_initialized); /* was set by cpu_init() */ |
Ravikiran G Thirumalai | 488fc08 | 2006-02-07 12:58:23 -0800 | [diff] [blame] | 583 | clear_node_cpumask(cpu); /* was set by numa_add_cpu */ |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 584 | cpu_clear(cpu, cpu_present_map); |
| 585 | cpu_clear(cpu, cpu_possible_map); |
Mike Travis | 71fff5e | 2007-10-19 20:35:03 +0200 | [diff] [blame] | 586 | per_cpu(x86_cpu_to_apicid, cpu) = BAD_APICID; |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 587 | return -EIO; |
| 588 | } |
| 589 | |
| 590 | return 0; |
| 591 | } |
| 592 | |
| 593 | cycles_t cacheflush_time; |
| 594 | unsigned long cache_decay_ticks; |
| 595 | |
| 596 | /* |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 597 | * Cleanup possible dangling ends... |
| 598 | */ |
| 599 | static __cpuinit void smp_cleanup_boot(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 600 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | /* |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 602 | * Paranoid: Set warm reset code and vector here back |
| 603 | * to default values. |
| 604 | */ |
| 605 | CMOS_WRITE(0, 0xf); |
| 606 | |
| 607 | /* |
| 608 | * Reset trampoline flag |
| 609 | */ |
| 610 | *((volatile int *) phys_to_virt(0x467)) = 0; |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 611 | } |
| 612 | |
| 613 | /* |
| 614 | * Fall back to non SMP mode after errors. |
| 615 | * |
| 616 | * RED-PEN audit/test this more. I bet there is more state messed up here. |
| 617 | */ |
Ashok Raj | e6982c6 | 2005-06-25 14:54:58 -0700 | [diff] [blame] | 618 | static __init void disable_smp(void) |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 619 | { |
| 620 | cpu_present_map = cpumask_of_cpu(0); |
| 621 | cpu_possible_map = cpumask_of_cpu(0); |
| 622 | if (smp_found_config) |
| 623 | phys_cpu_present_map = physid_mask_of_physid(boot_cpu_id); |
| 624 | else |
| 625 | phys_cpu_present_map = physid_mask_of_physid(0); |
Mike Travis | d5a7430 | 2007-10-16 01:24:05 -0700 | [diff] [blame] | 626 | cpu_set(0, per_cpu(cpu_sibling_map, 0)); |
Mike Travis | 0835761 | 2007-10-16 01:24:04 -0700 | [diff] [blame] | 627 | cpu_set(0, per_cpu(cpu_core_map, 0)); |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 628 | } |
| 629 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | /* |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 631 | * Various sanity checks. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | */ |
Ashok Raj | e6982c6 | 2005-06-25 14:54:58 -0700 | [diff] [blame] | 633 | static int __init smp_sanity_check(unsigned max_cpus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | if (!physid_isset(hard_smp_processor_id(), phys_cpu_present_map)) { |
| 636 | printk("weird, boot CPU (#%d) not listed by the BIOS.\n", |
| 637 | hard_smp_processor_id()); |
| 638 | physid_set(hard_smp_processor_id(), phys_cpu_present_map); |
| 639 | } |
| 640 | |
| 641 | /* |
| 642 | * If we couldn't find an SMP configuration at boot time, |
| 643 | * get out of here now! |
| 644 | */ |
| 645 | if (!smp_found_config) { |
| 646 | printk(KERN_NOTICE "SMP motherboard not detected.\n"); |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 647 | disable_smp(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | if (APIC_init_uniprocessor()) |
| 649 | printk(KERN_NOTICE "Local APIC not detected." |
| 650 | " Using dummy APIC emulation.\n"); |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 651 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | } |
| 653 | |
| 654 | /* |
| 655 | * Should not be necessary because the MP table should list the boot |
| 656 | * CPU too, but we do it for the sake of robustness anyway. |
| 657 | */ |
| 658 | if (!physid_isset(boot_cpu_id, phys_cpu_present_map)) { |
| 659 | printk(KERN_NOTICE "weird, boot CPU (#%d) not listed by the BIOS.\n", |
| 660 | boot_cpu_id); |
| 661 | physid_set(hard_smp_processor_id(), phys_cpu_present_map); |
| 662 | } |
| 663 | |
| 664 | /* |
| 665 | * If we couldn't find a local APIC, then get out of here now! |
| 666 | */ |
Andi Kleen | 11a8e77 | 2006-01-11 22:46:51 +0100 | [diff] [blame] | 667 | if (!cpu_has_apic) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | printk(KERN_ERR "BIOS bug, local APIC #%d not detected!...\n", |
| 669 | boot_cpu_id); |
| 670 | 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] | 671 | nr_ioapics = 0; |
| 672 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | } |
| 674 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 675 | /* |
| 676 | * If SMP should be disabled, then really disable it! |
| 677 | */ |
| 678 | if (!max_cpus) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | 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] | 680 | nr_ioapics = 0; |
| 681 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | } |
| 683 | |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 684 | return 0; |
| 685 | } |
| 686 | |
Yinghai Lu | 949ec32 | 2008-01-30 13:30:46 +0100 | [diff] [blame] | 687 | static void __init smp_cpu_index_default(void) |
| 688 | { |
| 689 | int i; |
| 690 | struct cpuinfo_x86 *c; |
| 691 | |
| 692 | for_each_cpu_mask(i, cpu_possible_map) { |
| 693 | c = &cpu_data(i); |
| 694 | /* mark all to hotplug */ |
| 695 | c->cpu_index = NR_CPUS; |
| 696 | } |
| 697 | } |
| 698 | |
Mike Travis | 71fff5e | 2007-10-19 20:35:03 +0200 | [diff] [blame] | 699 | /* |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 700 | * Prepare for SMP bootup. The MP table or ACPI has been read |
| 701 | * earlier. Just do some sanity checking here and enable APIC mode. |
| 702 | */ |
Glauber Costa | 7557da6 | 2008-03-03 14:12:38 -0300 | [diff] [blame] | 703 | void __init native_smp_prepare_cpus(unsigned int max_cpus) |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 704 | { |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 705 | nmi_watchdog_default(); |
Yinghai Lu | 949ec32 | 2008-01-30 13:30:46 +0100 | [diff] [blame] | 706 | smp_cpu_index_default(); |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 707 | current_cpu_data = boot_cpu_data; |
| 708 | current_thread_info()->cpu = 0; /* needed? */ |
Siddha, Suresh B | 94605ef | 2005-11-05 17:25:54 +0100 | [diff] [blame] | 709 | set_cpu_sibling_map(0); |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 710 | |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 711 | if (smp_sanity_check(max_cpus) < 0) { |
| 712 | printk(KERN_INFO "SMP disabled\n"); |
| 713 | disable_smp(); |
| 714 | return; |
| 715 | } |
| 716 | |
| 717 | |
| 718 | /* |
| 719 | * Switch from PIC to APIC mode. |
| 720 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 721 | setup_local_APIC(); |
| 722 | |
Andi Kleen | 739f33b | 2008-01-30 13:30:40 +0100 | [diff] [blame] | 723 | /* |
| 724 | * Enable IO APIC before setting up error vector |
| 725 | */ |
| 726 | if (!skip_ioapic_setup && nr_ioapics) |
| 727 | enable_IO_APIC(); |
| 728 | end_local_APIC_setup(); |
| 729 | |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 730 | if (GET_APIC_ID(apic_read(APIC_ID)) != boot_cpu_id) { |
| 731 | panic("Boot APIC ID in local APIC unexpected (%d vs %d)", |
| 732 | GET_APIC_ID(apic_read(APIC_ID)), boot_cpu_id); |
| 733 | /* Or can we switch back to PIC here? */ |
| 734 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | |
| 736 | /* |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 737 | * Now start the IO-APICs |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 738 | */ |
| 739 | if (!skip_ioapic_setup && nr_ioapics) |
| 740 | setup_IO_APIC(); |
| 741 | else |
| 742 | nr_ioapics = 0; |
| 743 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 744 | /* |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 745 | * Set up local APIC timer on boot CPU. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 746 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 | |
Glauber de Oliveira Costa | 746ef0c | 2008-01-30 13:31:11 +0100 | [diff] [blame] | 748 | setup_boot_clock(); |
Glauber de Oliveira Costa | 4f3ab19 | 2008-03-19 14:25:01 -0300 | [diff] [blame] | 749 | printk(KERN_INFO "CPU%d: ", 0); |
| 750 | print_cpu_info(&cpu_data(0)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | } |
| 752 | |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 753 | /* |
| 754 | * Early setup to make printk work. |
| 755 | */ |
Glauber Costa | 1e3fac8 | 2008-03-03 14:12:37 -0300 | [diff] [blame] | 756 | void __init native_smp_prepare_boot_cpu(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 757 | { |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 758 | int me = smp_processor_id(); |
Yinghai Lu | 23916d4 | 2008-01-30 13:33:39 +0100 | [diff] [blame] | 759 | /* already set me in cpu_online_map in boot_cpu_init() */ |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 760 | cpu_set(me, cpu_callout_map); |
Ashok Raj | 884d9e4 | 2005-06-25 14:55:02 -0700 | [diff] [blame] | 761 | per_cpu(cpu_state, me) = CPU_ONLINE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 762 | } |
| 763 | |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 764 | /* |
| 765 | * Entry point to boot a CPU. |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 766 | */ |
Glauber Costa | 71d1954 | 2008-03-03 14:12:36 -0300 | [diff] [blame] | 767 | int __cpuinit native_cpu_up(unsigned int cpu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 768 | { |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 769 | int apicid = cpu_present_to_apicid(cpu); |
Ingo Molnar | d04f41e | 2007-03-07 18:12:31 +0100 | [diff] [blame] | 770 | unsigned long flags; |
| 771 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 773 | WARN_ON(irqs_disabled()); |
| 774 | |
| 775 | Dprintk("++++++++++++++++++++=_---CPU UP %u\n", cpu); |
| 776 | |
| 777 | if (apicid == BAD_APICID || apicid == boot_cpu_id || |
| 778 | !physid_isset(apicid, phys_cpu_present_map)) { |
| 779 | printk("__cpu_up: bad cpu %d\n", cpu); |
| 780 | return -EINVAL; |
| 781 | } |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 782 | |
Ashok Raj | 76e4f66 | 2005-06-25 14:55:00 -0700 | [diff] [blame] | 783 | /* |
| 784 | * Already booted CPU? |
| 785 | */ |
| 786 | if (cpu_isset(cpu, cpu_callin_map)) { |
| 787 | Dprintk("do_boot_cpu %d Already started\n", cpu); |
| 788 | return -ENOSYS; |
| 789 | } |
| 790 | |
Bernhard Kaindl | 2b1f627 | 2007-05-02 19:27:17 +0200 | [diff] [blame] | 791 | /* |
| 792 | * Save current MTRR state in case it was changed since early boot |
| 793 | * (e.g. by the ACPI SMI) to initialize new CPUs with MTRRs in sync: |
| 794 | */ |
| 795 | mtrr_save_state(); |
| 796 | |
Ashok Raj | 884d9e4 | 2005-06-25 14:55:02 -0700 | [diff] [blame] | 797 | per_cpu(cpu_state, cpu) = CPU_UP_PREPARE; |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 798 | /* Boot it! */ |
| 799 | err = do_boot_cpu(cpu, apicid); |
| 800 | if (err < 0) { |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 801 | Dprintk("do_boot_cpu failed %d\n", err); |
| 802 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | } |
| 804 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 805 | /* Unleash the CPU! */ |
| 806 | Dprintk("waiting for cpu %d\n", cpu); |
| 807 | |
Ingo Molnar | 95492e4 | 2007-02-16 01:27:34 -0800 | [diff] [blame] | 808 | /* |
| 809 | * Make sure and check TSC sync: |
| 810 | */ |
Ingo Molnar | d04f41e | 2007-03-07 18:12:31 +0100 | [diff] [blame] | 811 | local_irq_save(flags); |
Ingo Molnar | 95492e4 | 2007-02-16 01:27:34 -0800 | [diff] [blame] | 812 | check_tsc_sync_source(cpu); |
Ingo Molnar | d04f41e | 2007-03-07 18:12:31 +0100 | [diff] [blame] | 813 | local_irq_restore(flags); |
Ingo Molnar | 95492e4 | 2007-02-16 01:27:34 -0800 | [diff] [blame] | 814 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | while (!cpu_isset(cpu, cpu_online_map)) |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 816 | cpu_relax(); |
Ashok Raj | 76e4f66 | 2005-06-25 14:55:00 -0700 | [diff] [blame] | 817 | err = 0; |
| 818 | |
| 819 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | } |
| 821 | |
Glauber de Oliveira Costa | f68e00a | 2008-03-19 14:25:29 -0300 | [diff] [blame] | 822 | extern void impress_friends(void); |
| 823 | extern void smp_checks(void); |
| 824 | |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 825 | /* |
| 826 | * Finish the SMP boot. |
| 827 | */ |
Glauber Costa | c559764 | 2008-03-03 14:12:39 -0300 | [diff] [blame] | 828 | void __init native_smp_cpus_done(unsigned int max_cpus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 829 | { |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 830 | smp_cleanup_boot(); |
Glauber de Oliveira Costa | f68e00a | 2008-03-19 14:25:29 -0300 | [diff] [blame] | 831 | |
| 832 | Dprintk("Boot done.\n"); |
| 833 | |
| 834 | impress_friends(); |
| 835 | smp_checks(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 836 | setup_ioapic_dest(); |
Andi Kleen | 7515211 | 2005-05-16 21:53:34 -0700 | [diff] [blame] | 837 | check_nmi_watchdog(); |
Andi Kleen | a8ab26f | 2005-04-16 15:25:19 -0700 | [diff] [blame] | 838 | } |