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 | * |
| 7 | * Much of the core SMP work is based on previous work by Thomas Radke, to |
| 8 | * whom a great many thanks are extended. |
| 9 | * |
| 10 | * Thanks to Intel for making available several different Pentium, |
| 11 | * Pentium Pro and Pentium-II/Xeon MP machines. |
| 12 | * Original development of Linux SMP code supported by Caldera. |
| 13 | * |
| 14 | * This code is released under the GNU General Public License version 2 or |
| 15 | * later. |
| 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 BogoMIPS 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 | * Martin J. Bligh : Added support for multi-quad systems |
| 33 | * Dave Jones : Report invalid combinations of Athlon CPUs. |
| 34 | * Rusty Russell : Hacked into shape for new "hotplug" boot process. */ |
| 35 | |
| 36 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | #include <linux/init.h> |
| 38 | #include <linux/kernel.h> |
| 39 | |
| 40 | #include <linux/mm.h> |
| 41 | #include <linux/sched.h> |
| 42 | #include <linux/kernel_stat.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | #include <linux/bootmem.h> |
Zwane Mwaikambo | f370513 | 2005-06-25 14:54:50 -0700 | [diff] [blame] | 44 | #include <linux/notifier.h> |
| 45 | #include <linux/cpu.h> |
| 46 | #include <linux/percpu.h> |
Ingo Molnar | d04f41e | 2007-03-07 18:12:31 +0100 | [diff] [blame] | 47 | #include <linux/nmi.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | |
| 49 | #include <linux/delay.h> |
| 50 | #include <linux/mc146818rtc.h> |
| 51 | #include <asm/tlbflush.h> |
| 52 | #include <asm/desc.h> |
| 53 | #include <asm/arch_hooks.h> |
Don Zickus | 3e4ff11 | 2006-06-26 13:57:01 +0200 | [diff] [blame] | 54 | #include <asm/nmi.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | |
| 56 | #include <mach_apic.h> |
| 57 | #include <mach_wakecpu.h> |
| 58 | #include <smpboot_hooks.h> |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 59 | #include <asm/vmi.h> |
Bernhard Kaindl | 2b1f627 | 2007-05-02 19:27:17 +0200 | [diff] [blame] | 60 | #include <asm/mtrr.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | |
| 62 | /* Set if we find a B stepping CPU */ |
Adrian Bunk | f2206ec | 2007-12-19 23:20:18 +0100 | [diff] [blame] | 63 | static int __cpuinitdata smp_b_stepping; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | static cpumask_t smp_commenced_mask; |
| 66 | |
travis@sgi.com | 3b41908 | 2008-01-30 13:33:11 +0100 | [diff] [blame] | 67 | /* which logical CPU number maps to which CPU (physical APIC ID) */ |
Glauber Costa | 5382e89 | 2008-03-03 14:12:57 -0300 | [diff] [blame] | 68 | u16 x86_cpu_to_apicid_init[NR_CPUS] __initdata = |
Mike Travis | 71fff5e | 2007-10-19 20:35:03 +0200 | [diff] [blame] | 69 | { [0 ... NR_CPUS-1] = BAD_APICID }; |
travis@sgi.com | 3b41908 | 2008-01-30 13:33:11 +0100 | [diff] [blame] | 70 | void *x86_cpu_to_apicid_early_ptr; |
Glauber Costa | 5382e89 | 2008-03-03 14:12:57 -0300 | [diff] [blame] | 71 | DEFINE_PER_CPU(u16, x86_cpu_to_apicid) = BAD_APICID; |
Mike Travis | 71fff5e | 2007-10-19 20:35:03 +0200 | [diff] [blame] | 72 | EXPORT_PER_CPU_SYMBOL(x86_cpu_to_apicid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | |
keith mannthey | 3b08606 | 2006-09-29 01:58:46 -0700 | [diff] [blame] | 74 | u8 apicid_2_node[MAX_APICID]; |
| 75 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | static void map_cpu_to_logical_apicid(void); |
| 77 | |
Zwane Mwaikambo | f370513 | 2005-06-25 14:54:50 -0700 | [diff] [blame] | 78 | /* State of each CPU. */ |
| 79 | DEFINE_PER_CPU(int, cpu_state) = { 0 }; |
| 80 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | * The bootstrap kernel entry code has set these up. Save them for |
| 83 | * a given CPU |
| 84 | */ |
| 85 | |
Jeremy Fitzhardinge | 724faa8 | 2007-07-17 18:37:03 -0700 | [diff] [blame] | 86 | void __cpuinit smp_store_cpu_info(int id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | { |
Mike Travis | 92cb761 | 2007-10-19 20:35:04 +0200 | [diff] [blame] | 88 | struct cpuinfo_x86 *c = &cpu_data(id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | |
| 90 | *c = boot_cpu_data; |
Mike Travis | 92cb761 | 2007-10-19 20:35:04 +0200 | [diff] [blame] | 91 | c->cpu_index = id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | if (id!=0) |
Jeremy Fitzhardinge | a6c4e07 | 2007-05-02 19:27:12 +0200 | [diff] [blame] | 93 | identify_secondary_cpu(c); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | /* |
| 95 | * Mask B, Pentium, but not Pentium MMX |
| 96 | */ |
| 97 | if (c->x86_vendor == X86_VENDOR_INTEL && |
| 98 | c->x86 == 5 && |
| 99 | c->x86_mask >= 1 && c->x86_mask <= 4 && |
| 100 | c->x86_model <= 3) |
| 101 | /* |
| 102 | * Remember we have B step Pentia with bugs |
| 103 | */ |
| 104 | smp_b_stepping = 1; |
| 105 | |
| 106 | /* |
| 107 | * Certain Athlons might work (for various values of 'work') in SMP |
| 108 | * but they are not certified as MP capable. |
| 109 | */ |
| 110 | if ((c->x86_vendor == X86_VENDOR_AMD) && (c->x86 == 6)) { |
| 111 | |
Dave Jones | 3ca113e | 2006-09-26 10:52:34 +0200 | [diff] [blame] | 112 | if (num_possible_cpus() == 1) |
| 113 | goto valid_k7; |
| 114 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | /* Athlon 660/661 is valid. */ |
| 116 | if ((c->x86_model==6) && ((c->x86_mask==0) || (c->x86_mask==1))) |
| 117 | goto valid_k7; |
| 118 | |
| 119 | /* Duron 670 is valid */ |
| 120 | if ((c->x86_model==7) && (c->x86_mask==0)) |
| 121 | goto valid_k7; |
| 122 | |
| 123 | /* |
| 124 | * Athlon 662, Duron 671, and Athlon >model 7 have capability bit. |
| 125 | * It's worth noting that the A5 stepping (662) of some Athlon XP's |
| 126 | * have the MP bit set. |
| 127 | * See http://www.heise.de/newsticker/data/jow-18.10.01-000 for more. |
| 128 | */ |
| 129 | if (((c->x86_model==6) && (c->x86_mask>=2)) || |
| 130 | ((c->x86_model==7) && (c->x86_mask>=1)) || |
| 131 | (c->x86_model> 7)) |
| 132 | if (cpu_has_mp) |
| 133 | goto valid_k7; |
| 134 | |
| 135 | /* If we get here, it's not a certified SMP capable AMD system. */ |
Randy Dunlap | 9f15833 | 2005-09-13 01:25:16 -0700 | [diff] [blame] | 136 | add_taint(TAINT_UNSAFE_SMP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | valid_k7: |
| 140 | ; |
| 141 | } |
| 142 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | static atomic_t init_deasserted; |
| 144 | |
Vivek Goyal | 4a5d107 | 2007-01-11 01:52:44 +0100 | [diff] [blame] | 145 | static void __cpuinit smp_callin(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | { |
| 147 | int cpuid, phys_id; |
| 148 | unsigned long timeout; |
| 149 | |
| 150 | /* |
| 151 | * If waken up by an INIT in an 82489DX configuration |
| 152 | * we may get here before an INIT-deassert IPI reaches |
| 153 | * our local APIC. We have to wait for the IPI or we'll |
| 154 | * lock up on an APIC access. |
| 155 | */ |
| 156 | wait_for_init_deassert(&init_deasserted); |
| 157 | |
| 158 | /* |
| 159 | * (This works even if the APIC is not enabled.) |
| 160 | */ |
| 161 | phys_id = GET_APIC_ID(apic_read(APIC_ID)); |
| 162 | cpuid = smp_processor_id(); |
| 163 | if (cpu_isset(cpuid, cpu_callin_map)) { |
| 164 | printk("huh, phys CPU#%d, CPU#%d already present??\n", |
| 165 | phys_id, cpuid); |
| 166 | BUG(); |
| 167 | } |
| 168 | Dprintk("CPU#%d (phys ID: %d) waiting for CALLOUT\n", cpuid, phys_id); |
| 169 | |
| 170 | /* |
| 171 | * STARTUP IPIs are fragile beasts as they might sometimes |
| 172 | * trigger some glue motherboard logic. Complete APIC bus |
| 173 | * silence for 1 second, this overestimates the time the |
| 174 | * boot CPU is spending to send the up to 2 STARTUP IPIs |
| 175 | * by a factor of two. This should be enough. |
| 176 | */ |
| 177 | |
| 178 | /* |
| 179 | * Waiting 2s total for startup (udelay is not yet working) |
| 180 | */ |
| 181 | timeout = jiffies + 2*HZ; |
| 182 | while (time_before(jiffies, timeout)) { |
| 183 | /* |
| 184 | * Has the boot CPU finished it's STARTUP sequence? |
| 185 | */ |
| 186 | if (cpu_isset(cpuid, cpu_callout_map)) |
| 187 | break; |
Glauber Costa | e104383 | 2008-03-03 14:13:14 -0300 | [diff] [blame^] | 188 | cpu_relax(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | if (!time_before(jiffies, timeout)) { |
| 192 | printk("BUG: CPU%d started up but did not get a callout!\n", |
| 193 | cpuid); |
| 194 | BUG(); |
| 195 | } |
| 196 | |
| 197 | /* |
| 198 | * the boot CPU has finished the init stage and is spinning |
| 199 | * on callin_map until we finish. We are free to set up this |
| 200 | * CPU, first the APIC. (this is probably redundant on most |
| 201 | * boards) |
| 202 | */ |
| 203 | |
| 204 | Dprintk("CALLIN, before setup_local_APIC().\n"); |
| 205 | smp_callin_clear_local_apic(); |
| 206 | setup_local_APIC(); |
| 207 | map_cpu_to_logical_apicid(); |
| 208 | |
| 209 | /* |
| 210 | * Get our bogomips. |
| 211 | */ |
| 212 | calibrate_delay(); |
| 213 | Dprintk("Stack at about %p\n",&cpuid); |
| 214 | |
| 215 | /* |
| 216 | * Save our processor parameters |
| 217 | */ |
Thomas Gleixner | e9e2cdb | 2007-02-16 01:28:04 -0800 | [diff] [blame] | 218 | smp_store_cpu_info(cpuid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | |
| 220 | /* |
| 221 | * Allow the master to continue. |
| 222 | */ |
| 223 | cpu_set(cpuid, cpu_callin_map); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | static int cpucount; |
| 227 | |
| 228 | /* |
| 229 | * Activate a secondary processor. |
| 230 | */ |
Vivek Goyal | 4a5d107 | 2007-01-11 01:52:44 +0100 | [diff] [blame] | 231 | static void __cpuinit start_secondary(void *unused) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | { |
| 233 | /* |
Rusty Russell | d2cbcc4 | 2007-05-02 19:27:10 +0200 | [diff] [blame] | 234 | * Don't put *anything* before cpu_init(), SMP booting is too |
| 235 | * fragile that we want to limit the things done here to the |
| 236 | * most necessary things. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | */ |
Zachary Amsden | 7ce0bcf | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 238 | #ifdef CONFIG_VMI |
| 239 | vmi_bringup(); |
| 240 | #endif |
Rusty Russell | d2cbcc4 | 2007-05-02 19:27:10 +0200 | [diff] [blame] | 241 | cpu_init(); |
Nick Piggin | 5bfb5d6 | 2005-11-08 21:39:01 -0800 | [diff] [blame] | 242 | preempt_disable(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | smp_callin(); |
| 244 | while (!cpu_isset(smp_processor_id(), smp_commenced_mask)) |
Glauber Costa | e104383 | 2008-03-03 14:13:14 -0300 | [diff] [blame^] | 245 | cpu_relax(); |
Ingo Molnar | 95492e4 | 2007-02-16 01:27:34 -0800 | [diff] [blame] | 246 | /* |
| 247 | * Check TSC synchronization with the BP: |
| 248 | */ |
| 249 | check_tsc_sync_target(); |
| 250 | |
Zachary Amsden | bbab4f3 | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 251 | setup_secondary_clock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | if (nmi_watchdog == NMI_IO_APIC) { |
| 253 | disable_8259A_irq(0); |
Jan Beulich | e942710 | 2008-01-30 13:31:24 +0100 | [diff] [blame] | 254 | enable_NMI_through_LVT0(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | enable_8259A_irq(0); |
| 256 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | /* |
| 258 | * low-memory mappings have been cleared, flush them from |
| 259 | * the local TLBs too. |
| 260 | */ |
| 261 | local_flush_tlb(); |
Li Shaohua | 6fe940d | 2005-06-25 14:54:53 -0700 | [diff] [blame] | 262 | |
Li Shaohua | d720803 | 2005-06-25 14:54:54 -0700 | [diff] [blame] | 263 | /* This must be done before setting cpu_online_map */ |
| 264 | set_cpu_sibling_map(raw_smp_processor_id()); |
| 265 | wmb(); |
| 266 | |
Li Shaohua | 6fe940d | 2005-06-25 14:54:53 -0700 | [diff] [blame] | 267 | /* |
| 268 | * We need to hold call_lock, so there is no inconsistency |
| 269 | * between the time smp_call_function() determines number of |
Simon Arlott | 27b46d7 | 2007-10-20 01:13:56 +0200 | [diff] [blame] | 270 | * IPI recipients, and the time when the determination is made |
Li Shaohua | 6fe940d | 2005-06-25 14:54:53 -0700 | [diff] [blame] | 271 | * for which cpus receive the IPI. Holding this |
| 272 | * lock helps us to not include this cpu in a currently in progress |
| 273 | * smp_call_function(). |
| 274 | */ |
| 275 | lock_ipi_call_lock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | cpu_set(smp_processor_id(), cpu_online_map); |
Li Shaohua | 6fe940d | 2005-06-25 14:54:53 -0700 | [diff] [blame] | 277 | unlock_ipi_call_lock(); |
Li Shaohua | e1367da | 2005-06-25 14:54:56 -0700 | [diff] [blame] | 278 | per_cpu(cpu_state, smp_processor_id()) = CPU_ONLINE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | |
| 280 | /* We can take interrupts now: we're officially "up". */ |
| 281 | local_irq_enable(); |
| 282 | |
| 283 | wmb(); |
| 284 | cpu_idle(); |
| 285 | } |
| 286 | |
| 287 | /* |
| 288 | * Everything has been set up for the secondary |
| 289 | * CPUs - they just need to reload everything |
| 290 | * from the task structure |
| 291 | * This function must not return. |
| 292 | */ |
Li Shaohua | 0bb3184 | 2005-06-25 14:54:55 -0700 | [diff] [blame] | 293 | void __devinit initialize_secondary(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | { |
| 295 | /* |
| 296 | * We don't actually need to load the full TSS, |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 297 | * basically just the stack pointer and the ip. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | */ |
| 299 | |
| 300 | asm volatile( |
| 301 | "movl %0,%%esp\n\t" |
| 302 | "jmp *%1" |
| 303 | : |
H. Peter Anvin | faca622 | 2008-01-30 13:31:02 +0100 | [diff] [blame] | 304 | :"m" (current->thread.sp),"m" (current->thread.ip)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | } |
| 306 | |
Jeremy Fitzhardinge | 6211119 | 2006-12-07 02:14:02 +0100 | [diff] [blame] | 307 | /* Static state in head.S used to set up a CPU */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | extern struct { |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 309 | void * sp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | unsigned short ss; |
| 311 | } stack_start; |
| 312 | |
| 313 | #ifdef CONFIG_NUMA |
| 314 | |
| 315 | /* which logical CPUs are on which nodes */ |
Thomas Gleixner | fe21a44 | 2008-01-30 13:30:38 +0100 | [diff] [blame] | 316 | cpumask_t node_to_cpumask_map[MAX_NUMNODES] __read_mostly = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | { [0 ... MAX_NUMNODES-1] = CPU_MASK_NONE }; |
Thomas Gleixner | fe21a44 | 2008-01-30 13:30:38 +0100 | [diff] [blame] | 318 | EXPORT_SYMBOL(node_to_cpumask_map); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | /* which node each logical CPU is on */ |
travis@sgi.com | 602a54a | 2008-01-30 13:33:21 +0100 | [diff] [blame] | 320 | int cpu_to_node_map[NR_CPUS] __read_mostly = { [0 ... NR_CPUS-1] = 0 }; |
Thomas Gleixner | fe21a44 | 2008-01-30 13:30:38 +0100 | [diff] [blame] | 321 | EXPORT_SYMBOL(cpu_to_node_map); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | |
| 323 | /* set up a mapping between cpu and node. */ |
| 324 | static inline void map_cpu_to_node(int cpu, int node) |
| 325 | { |
| 326 | printk("Mapping cpu %d to node %d\n", cpu, node); |
Thomas Gleixner | fe21a44 | 2008-01-30 13:30:38 +0100 | [diff] [blame] | 327 | cpu_set(cpu, node_to_cpumask_map[node]); |
| 328 | cpu_to_node_map[cpu] = node; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | /* undo a mapping between cpu and node. */ |
| 332 | static inline void unmap_cpu_to_node(int cpu) |
| 333 | { |
| 334 | int node; |
| 335 | |
| 336 | printk("Unmapping cpu %d from all nodes\n", cpu); |
| 337 | for (node = 0; node < MAX_NUMNODES; node ++) |
Thomas Gleixner | fe21a44 | 2008-01-30 13:30:38 +0100 | [diff] [blame] | 338 | cpu_clear(cpu, node_to_cpumask_map[node]); |
| 339 | cpu_to_node_map[cpu] = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | } |
| 341 | #else /* !CONFIG_NUMA */ |
| 342 | |
| 343 | #define map_cpu_to_node(cpu, node) ({}) |
| 344 | #define unmap_cpu_to_node(cpu) ({}) |
| 345 | |
| 346 | #endif /* CONFIG_NUMA */ |
| 347 | |
Christoph Lameter | 6c03652 | 2005-07-07 17:56:59 -0700 | [diff] [blame] | 348 | u8 cpu_2_logical_apicid[NR_CPUS] __read_mostly = { [0 ... NR_CPUS-1] = BAD_APICID }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | |
| 350 | static void map_cpu_to_logical_apicid(void) |
| 351 | { |
| 352 | int cpu = smp_processor_id(); |
| 353 | int apicid = logical_smp_processor_id(); |
Keith Mannthey | 78b656b | 2006-10-03 18:25:52 -0700 | [diff] [blame] | 354 | int node = apicid_to_node(apicid); |
keith mannthey | bfa0e9a | 2006-09-25 16:25:35 -0700 | [diff] [blame] | 355 | |
| 356 | if (!node_online(node)) |
| 357 | node = first_online_node; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | |
| 359 | cpu_2_logical_apicid[cpu] = apicid; |
keith mannthey | bfa0e9a | 2006-09-25 16:25:35 -0700 | [diff] [blame] | 360 | map_cpu_to_node(cpu, node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | static void unmap_cpu_to_logical_apicid(int cpu) |
| 364 | { |
| 365 | cpu_2_logical_apicid[cpu] = BAD_APICID; |
| 366 | unmap_cpu_to_node(cpu); |
| 367 | } |
| 368 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | static inline void __inquire_remote_apic(int apicid) |
| 370 | { |
| 371 | int i, regs[] = { APIC_ID >> 4, APIC_LVR >> 4, APIC_SPIV >> 4 }; |
| 372 | char *names[] = { "ID", "VERSION", "SPIV" }; |
Fernando Luis VazquezCao | 4312fa8 | 2007-05-02 19:27:17 +0200 | [diff] [blame] | 373 | int timeout; |
| 374 | unsigned long status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | |
| 376 | printk("Inquiring remote APIC #%d...\n", apicid); |
| 377 | |
Tobias Klauser | 38e548e | 2005-11-07 00:58:31 -0800 | [diff] [blame] | 378 | for (i = 0; i < ARRAY_SIZE(regs); i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | printk("... APIC #%d %s: ", apicid, names[i]); |
| 380 | |
| 381 | /* |
| 382 | * Wait for idle. |
| 383 | */ |
Fernando Luis VazquezCao | 4312fa8 | 2007-05-02 19:27:17 +0200 | [diff] [blame] | 384 | status = safe_apic_wait_icr_idle(); |
| 385 | if (status) |
| 386 | printk("a previous APIC delivery may have failed\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | |
| 388 | apic_write_around(APIC_ICR2, SET_APIC_DEST_FIELD(apicid)); |
| 389 | apic_write_around(APIC_ICR, APIC_DM_REMRD | regs[i]); |
| 390 | |
| 391 | timeout = 0; |
| 392 | do { |
| 393 | udelay(100); |
| 394 | status = apic_read(APIC_ICR) & APIC_ICR_RR_MASK; |
| 395 | } while (status == APIC_ICR_RR_INPROG && timeout++ < 1000); |
| 396 | |
| 397 | switch (status) { |
| 398 | case APIC_ICR_RR_VALID: |
| 399 | status = apic_read(APIC_RRR); |
Andi Kleen | ec1180d | 2007-05-02 19:27:21 +0200 | [diff] [blame] | 400 | printk("%lx\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | break; |
| 402 | default: |
| 403 | printk("failed\n"); |
| 404 | } |
| 405 | } |
| 406 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | |
| 408 | #ifdef WAKE_SECONDARY_VIA_NMI |
| 409 | /* |
| 410 | * Poke the other CPU in the eye via NMI to wake it up. Remember that the normal |
| 411 | * INIT, INIT, STARTUP sequence will reset the chip hard for us, and this |
| 412 | * won't ... remember to clear down the APIC, etc later. |
| 413 | */ |
Li Shaohua | 0bb3184 | 2005-06-25 14:54:55 -0700 | [diff] [blame] | 414 | static int __devinit |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | wakeup_secondary_cpu(int logical_apicid, unsigned long start_eip) |
| 416 | { |
Fernando Luis VazquezCao | ae08e43 | 2007-05-02 19:27:17 +0200 | [diff] [blame] | 417 | unsigned long send_status, accept_status = 0; |
| 418 | int maxlvt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | |
| 420 | /* Target chip */ |
| 421 | apic_write_around(APIC_ICR2, SET_APIC_DEST_FIELD(logical_apicid)); |
| 422 | |
| 423 | /* Boot on the stack */ |
| 424 | /* Kick the second */ |
| 425 | apic_write_around(APIC_ICR, APIC_DM_NMI | APIC_DEST_LOGICAL); |
| 426 | |
| 427 | Dprintk("Waiting for send to finish...\n"); |
Fernando Luis VazquezCao | ae08e43 | 2007-05-02 19:27:17 +0200 | [diff] [blame] | 428 | send_status = safe_apic_wait_icr_idle(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | |
| 430 | /* |
| 431 | * Give the other CPU some time to accept the IPI. |
| 432 | */ |
| 433 | udelay(200); |
| 434 | /* |
| 435 | * Due to the Pentium erratum 3AP. |
| 436 | */ |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 437 | maxlvt = lapic_get_maxlvt(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | if (maxlvt > 3) { |
| 439 | apic_read_around(APIC_SPIV); |
| 440 | apic_write(APIC_ESR, 0); |
| 441 | } |
| 442 | accept_status = (apic_read(APIC_ESR) & 0xEF); |
| 443 | Dprintk("NMI sent.\n"); |
| 444 | |
| 445 | if (send_status) |
| 446 | printk("APIC never delivered???\n"); |
| 447 | if (accept_status) |
| 448 | printk("APIC delivery error (%lx).\n", accept_status); |
| 449 | |
| 450 | return (send_status | accept_status); |
| 451 | } |
| 452 | #endif /* WAKE_SECONDARY_VIA_NMI */ |
| 453 | |
| 454 | #ifdef WAKE_SECONDARY_VIA_INIT |
Li Shaohua | 0bb3184 | 2005-06-25 14:54:55 -0700 | [diff] [blame] | 455 | static int __devinit |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | wakeup_secondary_cpu(int phys_apicid, unsigned long start_eip) |
| 457 | { |
Fernando Luis VazquezCao | ae08e43 | 2007-05-02 19:27:17 +0200 | [diff] [blame] | 458 | unsigned long send_status, accept_status = 0; |
| 459 | int maxlvt, num_starts, j; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | |
| 461 | /* |
| 462 | * Be paranoid about clearing APIC errors. |
| 463 | */ |
| 464 | if (APIC_INTEGRATED(apic_version[phys_apicid])) { |
| 465 | apic_read_around(APIC_SPIV); |
| 466 | apic_write(APIC_ESR, 0); |
| 467 | apic_read(APIC_ESR); |
| 468 | } |
| 469 | |
| 470 | Dprintk("Asserting INIT.\n"); |
| 471 | |
| 472 | /* |
| 473 | * Turn INIT on target chip |
| 474 | */ |
| 475 | apic_write_around(APIC_ICR2, SET_APIC_DEST_FIELD(phys_apicid)); |
| 476 | |
| 477 | /* |
| 478 | * Send IPI |
| 479 | */ |
| 480 | apic_write_around(APIC_ICR, APIC_INT_LEVELTRIG | APIC_INT_ASSERT |
| 481 | | APIC_DM_INIT); |
| 482 | |
| 483 | Dprintk("Waiting for send to finish...\n"); |
Fernando Luis VazquezCao | ae08e43 | 2007-05-02 19:27:17 +0200 | [diff] [blame] | 484 | send_status = safe_apic_wait_icr_idle(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | |
| 486 | mdelay(10); |
| 487 | |
| 488 | Dprintk("Deasserting INIT.\n"); |
| 489 | |
| 490 | /* Target chip */ |
| 491 | apic_write_around(APIC_ICR2, SET_APIC_DEST_FIELD(phys_apicid)); |
| 492 | |
| 493 | /* Send IPI */ |
| 494 | apic_write_around(APIC_ICR, APIC_INT_LEVELTRIG | APIC_DM_INIT); |
| 495 | |
| 496 | Dprintk("Waiting for send to finish...\n"); |
Fernando Luis VazquezCao | ae08e43 | 2007-05-02 19:27:17 +0200 | [diff] [blame] | 497 | send_status = safe_apic_wait_icr_idle(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | |
| 499 | atomic_set(&init_deasserted, 1); |
| 500 | |
| 501 | /* |
| 502 | * Should we send STARTUP IPIs ? |
| 503 | * |
| 504 | * Determine this based on the APIC version. |
| 505 | * If we don't have an integrated APIC, don't send the STARTUP IPIs. |
| 506 | */ |
| 507 | if (APIC_INTEGRATED(apic_version[phys_apicid])) |
| 508 | num_starts = 2; |
| 509 | else |
| 510 | num_starts = 0; |
| 511 | |
| 512 | /* |
Zachary Amsden | ae5da27 | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 513 | * Paravirt / VMI wants a startup IPI hook here to set up the |
| 514 | * target processor state. |
| 515 | */ |
| 516 | startup_ipi_hook(phys_apicid, (unsigned long) start_secondary, |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 517 | (unsigned long) stack_start.sp); |
Zachary Amsden | ae5da27 | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 518 | |
| 519 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | * Run STARTUP IPI loop. |
| 521 | */ |
| 522 | Dprintk("#startup loops: %d.\n", num_starts); |
| 523 | |
Thomas Gleixner | e05d723 | 2007-02-16 01:27:58 -0800 | [diff] [blame] | 524 | maxlvt = lapic_get_maxlvt(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | |
| 526 | for (j = 1; j <= num_starts; j++) { |
| 527 | Dprintk("Sending STARTUP #%d.\n",j); |
| 528 | apic_read_around(APIC_SPIV); |
| 529 | apic_write(APIC_ESR, 0); |
| 530 | apic_read(APIC_ESR); |
| 531 | Dprintk("After apic_write.\n"); |
| 532 | |
| 533 | /* |
| 534 | * STARTUP IPI |
| 535 | */ |
| 536 | |
| 537 | /* Target chip */ |
| 538 | apic_write_around(APIC_ICR2, SET_APIC_DEST_FIELD(phys_apicid)); |
| 539 | |
| 540 | /* Boot on the stack */ |
| 541 | /* Kick the second */ |
| 542 | apic_write_around(APIC_ICR, APIC_DM_STARTUP |
| 543 | | (start_eip >> 12)); |
| 544 | |
| 545 | /* |
| 546 | * Give the other CPU some time to accept the IPI. |
| 547 | */ |
| 548 | udelay(300); |
| 549 | |
| 550 | Dprintk("Startup point 1.\n"); |
| 551 | |
| 552 | Dprintk("Waiting for send to finish...\n"); |
Fernando Luis VazquezCao | ae08e43 | 2007-05-02 19:27:17 +0200 | [diff] [blame] | 553 | send_status = safe_apic_wait_icr_idle(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | |
| 555 | /* |
| 556 | * Give the other CPU some time to accept the IPI. |
| 557 | */ |
| 558 | udelay(200); |
| 559 | /* |
| 560 | * Due to the Pentium erratum 3AP. |
| 561 | */ |
| 562 | if (maxlvt > 3) { |
| 563 | apic_read_around(APIC_SPIV); |
| 564 | apic_write(APIC_ESR, 0); |
| 565 | } |
| 566 | accept_status = (apic_read(APIC_ESR) & 0xEF); |
| 567 | if (send_status || accept_status) |
| 568 | break; |
| 569 | } |
| 570 | Dprintk("After Startup.\n"); |
| 571 | |
| 572 | if (send_status) |
| 573 | printk("APIC never delivered???\n"); |
| 574 | if (accept_status) |
| 575 | printk("APIC delivery error (%lx).\n", accept_status); |
| 576 | |
| 577 | return (send_status | accept_status); |
| 578 | } |
| 579 | #endif /* WAKE_SECONDARY_VIA_INIT */ |
| 580 | |
| 581 | extern cpumask_t cpu_initialized; |
Li Shaohua | e1367da | 2005-06-25 14:54:56 -0700 | [diff] [blame] | 582 | static inline int alloc_cpu_id(void) |
| 583 | { |
| 584 | cpumask_t tmp_map; |
| 585 | int cpu; |
| 586 | cpus_complement(tmp_map, cpu_present_map); |
| 587 | cpu = first_cpu(tmp_map); |
| 588 | if (cpu >= NR_CPUS) |
| 589 | return -ENODEV; |
| 590 | return cpu; |
| 591 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | |
Li Shaohua | e1367da | 2005-06-25 14:54:56 -0700 | [diff] [blame] | 593 | #ifdef CONFIG_HOTPLUG_CPU |
Adrian Bunk | f2206ec | 2007-12-19 23:20:18 +0100 | [diff] [blame] | 594 | static struct task_struct * __cpuinitdata cpu_idle_tasks[NR_CPUS]; |
| 595 | static inline struct task_struct * __cpuinit alloc_idle_task(int cpu) |
Li Shaohua | e1367da | 2005-06-25 14:54:56 -0700 | [diff] [blame] | 596 | { |
| 597 | struct task_struct *idle; |
| 598 | |
| 599 | if ((idle = cpu_idle_tasks[cpu]) != NULL) { |
| 600 | /* initialize thread_struct. we really want to avoid destroy |
| 601 | * idle tread |
| 602 | */ |
H. Peter Anvin | faca622 | 2008-01-30 13:31:02 +0100 | [diff] [blame] | 603 | idle->thread.sp = (unsigned long)task_pt_regs(idle); |
Li Shaohua | e1367da | 2005-06-25 14:54:56 -0700 | [diff] [blame] | 604 | init_idle(idle, cpu); |
| 605 | return idle; |
| 606 | } |
| 607 | idle = fork_idle(cpu); |
| 608 | |
| 609 | if (!IS_ERR(idle)) |
| 610 | cpu_idle_tasks[cpu] = idle; |
| 611 | return idle; |
| 612 | } |
| 613 | #else |
| 614 | #define alloc_idle_task(cpu) fork_idle(cpu) |
| 615 | #endif |
| 616 | |
Vivek Goyal | 4a5d107 | 2007-01-11 01:52:44 +0100 | [diff] [blame] | 617 | static int __cpuinit do_boot_cpu(int apicid, int cpu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | /* |
| 619 | * NOTE - on most systems this is a PHYSICAL apic ID, but on multiquad |
| 620 | * (ie clustered apic addressing mode), this is a LOGICAL apic ID. |
| 621 | * Returns zero if CPU booted OK, else error code from wakeup_secondary_cpu. |
| 622 | */ |
| 623 | { |
| 624 | struct task_struct *idle; |
| 625 | unsigned long boot_error; |
Li Shaohua | e1367da | 2005-06-25 14:54:56 -0700 | [diff] [blame] | 626 | int timeout; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | unsigned long start_eip; |
| 628 | unsigned short nmi_high = 0, nmi_low = 0; |
| 629 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | /* |
Bernhard Kaindl | 2b1f627 | 2007-05-02 19:27:17 +0200 | [diff] [blame] | 631 | * Save current MTRR state in case it was changed since early boot |
| 632 | * (e.g. by the ACPI SMI) to initialize new CPUs with MTRRs in sync: |
| 633 | */ |
| 634 | mtrr_save_state(); |
| 635 | |
| 636 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 | * We can't use kernel_thread since we must avoid to |
| 638 | * reschedule the child. |
| 639 | */ |
Li Shaohua | e1367da | 2005-06-25 14:54:56 -0700 | [diff] [blame] | 640 | idle = alloc_idle_task(cpu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | if (IS_ERR(idle)) |
| 642 | panic("failed fork for CPU %d", cpu); |
Jeremy Fitzhardinge | 6211119 | 2006-12-07 02:14:02 +0100 | [diff] [blame] | 643 | |
Jeremy Fitzhardinge | 7c3576d | 2007-05-02 19:27:16 +0200 | [diff] [blame] | 644 | init_gdt(cpu); |
| 645 | per_cpu(current_task, cpu) = idle; |
Rusty Russell | bf504672 | 2007-05-02 19:27:10 +0200 | [diff] [blame] | 646 | early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu); |
Jeremy Fitzhardinge | 6211119 | 2006-12-07 02:14:02 +0100 | [diff] [blame] | 647 | |
H. Peter Anvin | faca622 | 2008-01-30 13:31:02 +0100 | [diff] [blame] | 648 | idle->thread.ip = (unsigned long) start_secondary; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | /* start_eip had better be page-aligned! */ |
| 650 | start_eip = setup_trampoline(); |
| 651 | |
Jeremy Fitzhardinge | 6211119 | 2006-12-07 02:14:02 +0100 | [diff] [blame] | 652 | ++cpucount; |
| 653 | alternatives_smp_switch(1); |
| 654 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | /* So we see what's up */ |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 656 | printk("Booting processor %d/%d ip %lx\n", cpu, apicid, start_eip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | /* Stack for startup_32 can be just as for start_secondary onwards */ |
H. Peter Anvin | faca622 | 2008-01-30 13:31:02 +0100 | [diff] [blame] | 658 | stack_start.sp = (void *) idle->thread.sp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | |
| 660 | irq_ctx_init(cpu); |
| 661 | |
Mike Travis | 71fff5e | 2007-10-19 20:35:03 +0200 | [diff] [blame] | 662 | per_cpu(x86_cpu_to_apicid, cpu) = apicid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 | /* |
| 664 | * This grunge runs the startup process for |
| 665 | * the targeted processor. |
| 666 | */ |
| 667 | |
| 668 | atomic_set(&init_deasserted, 0); |
| 669 | |
| 670 | Dprintk("Setting warm reset code and vector.\n"); |
| 671 | |
| 672 | store_NMI_vector(&nmi_high, &nmi_low); |
| 673 | |
| 674 | smpboot_setup_warm_reset_vector(start_eip); |
| 675 | |
| 676 | /* |
| 677 | * Starting actual IPI sequence... |
| 678 | */ |
| 679 | boot_error = wakeup_secondary_cpu(apicid, start_eip); |
| 680 | |
| 681 | if (!boot_error) { |
| 682 | /* |
| 683 | * allow APs to start initializing. |
| 684 | */ |
| 685 | Dprintk("Before Callout %d.\n", cpu); |
| 686 | cpu_set(cpu, cpu_callout_map); |
| 687 | Dprintk("After Callout %d.\n", cpu); |
| 688 | |
| 689 | /* |
| 690 | * Wait 5s total for a response |
| 691 | */ |
| 692 | for (timeout = 0; timeout < 50000; timeout++) { |
| 693 | if (cpu_isset(cpu, cpu_callin_map)) |
| 694 | break; /* It has booted */ |
| 695 | udelay(100); |
| 696 | } |
| 697 | |
| 698 | if (cpu_isset(cpu, cpu_callin_map)) { |
| 699 | /* number CPUs logically, starting from 1 (BSP is 0) */ |
| 700 | Dprintk("OK.\n"); |
| 701 | printk("CPU%d: ", cpu); |
Mike Travis | 92cb761 | 2007-10-19 20:35:04 +0200 | [diff] [blame] | 702 | print_cpu_info(&cpu_data(cpu)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | Dprintk("CPU has booted.\n"); |
| 704 | } else { |
| 705 | boot_error= 1; |
| 706 | if (*((volatile unsigned char *)trampoline_base) |
| 707 | == 0xA5) |
| 708 | /* trampoline started but...? */ |
| 709 | printk("Stuck ??\n"); |
| 710 | else |
| 711 | /* trampoline code not run */ |
| 712 | printk("Not responding.\n"); |
| 713 | inquire_remote_apic(apicid); |
| 714 | } |
| 715 | } |
Li Shaohua | e1367da | 2005-06-25 14:54:56 -0700 | [diff] [blame] | 716 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 717 | if (boot_error) { |
| 718 | /* Try to put things back the way they were before ... */ |
| 719 | unmap_cpu_to_logical_apicid(cpu); |
| 720 | cpu_clear(cpu, cpu_callout_map); /* was set here (do_boot_cpu()) */ |
| 721 | cpu_clear(cpu, cpu_initialized); /* was set by cpu_init() */ |
| 722 | cpucount--; |
Li Shaohua | e1367da | 2005-06-25 14:54:56 -0700 | [diff] [blame] | 723 | } else { |
Mike Travis | 71fff5e | 2007-10-19 20:35:03 +0200 | [diff] [blame] | 724 | per_cpu(x86_cpu_to_apicid, cpu) = apicid; |
Li Shaohua | e1367da | 2005-06-25 14:54:56 -0700 | [diff] [blame] | 725 | cpu_set(cpu, cpu_present_map); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | } |
| 727 | |
| 728 | /* mark "stuck" area as not stuck */ |
| 729 | *((volatile unsigned long *)trampoline_base) = 0; |
| 730 | |
| 731 | return boot_error; |
| 732 | } |
| 733 | |
Li Shaohua | e1367da | 2005-06-25 14:54:56 -0700 | [diff] [blame] | 734 | #ifdef CONFIG_HOTPLUG_CPU |
| 735 | void cpu_exit_clear(void) |
| 736 | { |
| 737 | int cpu = raw_smp_processor_id(); |
| 738 | |
| 739 | idle_task_exit(); |
| 740 | |
| 741 | cpucount --; |
| 742 | cpu_uninit(); |
| 743 | irq_ctx_exit(cpu); |
| 744 | |
| 745 | cpu_clear(cpu, cpu_callout_map); |
| 746 | cpu_clear(cpu, cpu_callin_map); |
Li Shaohua | e1367da | 2005-06-25 14:54:56 -0700 | [diff] [blame] | 747 | |
| 748 | cpu_clear(cpu, smp_commenced_mask); |
| 749 | unmap_cpu_to_logical_apicid(cpu); |
| 750 | } |
| 751 | |
| 752 | struct warm_boot_cpu_info { |
| 753 | struct completion *complete; |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 754 | struct work_struct task; |
Li Shaohua | e1367da | 2005-06-25 14:54:56 -0700 | [diff] [blame] | 755 | int apicid; |
| 756 | int cpu; |
| 757 | }; |
| 758 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 759 | static void __cpuinit do_warm_boot_cpu(struct work_struct *work) |
Li Shaohua | e1367da | 2005-06-25 14:54:56 -0700 | [diff] [blame] | 760 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 761 | struct warm_boot_cpu_info *info = |
| 762 | container_of(work, struct warm_boot_cpu_info, task); |
Li Shaohua | e1367da | 2005-06-25 14:54:56 -0700 | [diff] [blame] | 763 | do_boot_cpu(info->apicid, info->cpu); |
| 764 | complete(info->complete); |
| 765 | } |
| 766 | |
Ashok Raj | 34f361a | 2006-03-25 03:08:18 -0800 | [diff] [blame] | 767 | static int __cpuinit __smp_prepare_cpu(int cpu) |
Li Shaohua | e1367da | 2005-06-25 14:54:56 -0700 | [diff] [blame] | 768 | { |
Peter Zijlstra | 6e9a473 | 2006-09-30 23:28:10 -0700 | [diff] [blame] | 769 | DECLARE_COMPLETION_ONSTACK(done); |
Li Shaohua | e1367da | 2005-06-25 14:54:56 -0700 | [diff] [blame] | 770 | struct warm_boot_cpu_info info; |
Li Shaohua | e1367da | 2005-06-25 14:54:56 -0700 | [diff] [blame] | 771 | int apicid, ret; |
| 772 | |
Mike Travis | 71fff5e | 2007-10-19 20:35:03 +0200 | [diff] [blame] | 773 | apicid = per_cpu(x86_cpu_to_apicid, cpu); |
Li Shaohua | e1367da | 2005-06-25 14:54:56 -0700 | [diff] [blame] | 774 | if (apicid == BAD_APICID) { |
| 775 | ret = -ENODEV; |
| 776 | goto exit; |
| 777 | } |
| 778 | |
| 779 | info.complete = &done; |
| 780 | info.apicid = apicid; |
| 781 | info.cpu = cpu; |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 782 | INIT_WORK(&info.task, do_warm_boot_cpu); |
Li Shaohua | e1367da | 2005-06-25 14:54:56 -0700 | [diff] [blame] | 783 | |
Li Shaohua | e1367da | 2005-06-25 14:54:56 -0700 | [diff] [blame] | 784 | /* init low mem mapping */ |
Zachary Amsden | d7271b1 | 2005-09-03 15:56:50 -0700 | [diff] [blame] | 785 | clone_pgd_range(swapper_pg_dir, swapper_pg_dir + USER_PGD_PTRS, |
Shaohua Li | 3b1bdf4 | 2006-12-08 02:41:13 -0800 | [diff] [blame] | 786 | min_t(unsigned long, KERNEL_PGD_PTRS, USER_PGD_PTRS)); |
Li Shaohua | e1367da | 2005-06-25 14:54:56 -0700 | [diff] [blame] | 787 | flush_tlb_all(); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 788 | schedule_work(&info.task); |
Li Shaohua | e1367da | 2005-06-25 14:54:56 -0700 | [diff] [blame] | 789 | wait_for_completion(&done); |
| 790 | |
Li Shaohua | e1367da | 2005-06-25 14:54:56 -0700 | [diff] [blame] | 791 | zap_low_mappings(); |
| 792 | ret = 0; |
| 793 | exit: |
Li Shaohua | e1367da | 2005-06-25 14:54:56 -0700 | [diff] [blame] | 794 | return ret; |
| 795 | } |
| 796 | #endif |
| 797 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | /* |
| 799 | * Cycle through the processors sending APIC IPIs to boot each. |
| 800 | */ |
| 801 | |
| 802 | static int boot_cpu_logical_apicid; |
| 803 | /* Where the IO area was mapped on multiquad, always 0 otherwise */ |
| 804 | void *xquad_portio; |
Alexey Dobriyan | 129f694 | 2005-06-23 00:08:33 -0700 | [diff] [blame] | 805 | #ifdef CONFIG_X86_NUMAQ |
| 806 | EXPORT_SYMBOL(xquad_portio); |
| 807 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 809 | static void __init smp_boot_cpus(unsigned int max_cpus) |
| 810 | { |
| 811 | int apicid, cpu, bit, kicked; |
| 812 | unsigned long bogosum = 0; |
| 813 | |
| 814 | /* |
| 815 | * Setup boot CPU information |
| 816 | */ |
| 817 | smp_store_cpu_info(0); /* Final full version of the data */ |
| 818 | printk("CPU%d: ", 0); |
Mike Travis | 92cb761 | 2007-10-19 20:35:04 +0200 | [diff] [blame] | 819 | print_cpu_info(&cpu_data(0)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | |
Linus Torvalds | 1e4c85f | 2005-10-31 19:16:17 -0800 | [diff] [blame] | 821 | boot_cpu_physical_apicid = GET_APIC_ID(apic_read(APIC_ID)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 822 | boot_cpu_logical_apicid = logical_smp_processor_id(); |
Mike Travis | 71fff5e | 2007-10-19 20:35:03 +0200 | [diff] [blame] | 823 | per_cpu(x86_cpu_to_apicid, 0) = boot_cpu_physical_apicid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 824 | |
| 825 | current_thread_info()->cpu = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 826 | |
Siddha, Suresh B | 94605ef | 2005-11-05 17:25:54 +0100 | [diff] [blame] | 827 | set_cpu_sibling_map(0); |
Andi Kleen | 3dd9d51 | 2005-04-16 15:25:15 -0700 | [diff] [blame] | 828 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 829 | /* |
| 830 | * If we couldn't find an SMP configuration at boot time, |
| 831 | * get out of here now! |
| 832 | */ |
| 833 | if (!smp_found_config && !acpi_lapic) { |
| 834 | printk(KERN_NOTICE "SMP motherboard not detected.\n"); |
Linus Torvalds | 1e4c85f | 2005-10-31 19:16:17 -0800 | [diff] [blame] | 835 | smpboot_clear_io_apic_irqs(); |
| 836 | phys_cpu_present_map = physid_mask_of_physid(0); |
| 837 | if (APIC_init_uniprocessor()) |
| 838 | printk(KERN_NOTICE "Local APIC not detected." |
| 839 | " Using dummy APIC emulation.\n"); |
| 840 | map_cpu_to_logical_apicid(); |
Mike Travis | d5a7430 | 2007-10-16 01:24:05 -0700 | [diff] [blame] | 841 | cpu_set(0, per_cpu(cpu_sibling_map, 0)); |
Mike Travis | 0835761 | 2007-10-16 01:24:04 -0700 | [diff] [blame] | 842 | cpu_set(0, per_cpu(cpu_core_map, 0)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 | return; |
| 844 | } |
| 845 | |
| 846 | /* |
Linus Torvalds | 1e4c85f | 2005-10-31 19:16:17 -0800 | [diff] [blame] | 847 | * Should not be necessary because the MP table should list the boot |
| 848 | * CPU too, but we do it for the sake of robustness anyway. |
| 849 | * Makes no sense to do this check in clustered apic mode, so skip it |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 850 | */ |
Linus Torvalds | 1e4c85f | 2005-10-31 19:16:17 -0800 | [diff] [blame] | 851 | if (!check_phys_apicid_present(boot_cpu_physical_apicid)) { |
| 852 | printk("weird, boot CPU (#%d) not listed by the BIOS.\n", |
| 853 | boot_cpu_physical_apicid); |
| 854 | physid_set(hard_smp_processor_id(), phys_cpu_present_map); |
| 855 | } |
| 856 | |
| 857 | /* |
| 858 | * If we couldn't find a local APIC, then get out of here now! |
| 859 | */ |
| 860 | if (APIC_INTEGRATED(apic_version[boot_cpu_physical_apicid]) && !cpu_has_apic) { |
| 861 | printk(KERN_ERR "BIOS bug, local APIC #%d not detected!...\n", |
| 862 | boot_cpu_physical_apicid); |
| 863 | printk(KERN_ERR "... forcing use of dummy APIC emulation. (tell your hw vendor)\n"); |
| 864 | smpboot_clear_io_apic_irqs(); |
| 865 | phys_cpu_present_map = physid_mask_of_physid(0); |
Ingo Molnar | 54ffaa4 | 2007-10-19 20:35:02 +0200 | [diff] [blame] | 866 | map_cpu_to_logical_apicid(); |
Mike Travis | d5a7430 | 2007-10-16 01:24:05 -0700 | [diff] [blame] | 867 | cpu_set(0, per_cpu(cpu_sibling_map, 0)); |
Mike Travis | 0835761 | 2007-10-16 01:24:04 -0700 | [diff] [blame] | 868 | cpu_set(0, per_cpu(cpu_core_map, 0)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 869 | return; |
| 870 | } |
| 871 | |
Linus Torvalds | 1e4c85f | 2005-10-31 19:16:17 -0800 | [diff] [blame] | 872 | verify_local_APIC(); |
| 873 | |
| 874 | /* |
| 875 | * If SMP should be disabled, then really disable it! |
| 876 | */ |
| 877 | if (!max_cpus) { |
| 878 | smp_found_config = 0; |
| 879 | printk(KERN_INFO "SMP mode deactivated, forcing use of dummy APIC emulation.\n"); |
Ingo Molnar | 3fb450a | 2007-10-17 18:04:34 +0200 | [diff] [blame] | 880 | |
| 881 | if (nmi_watchdog == NMI_LOCAL_APIC) { |
| 882 | printk(KERN_INFO "activating minimal APIC for NMI watchdog use.\n"); |
| 883 | connect_bsp_APIC(); |
| 884 | setup_local_APIC(); |
| 885 | } |
Linus Torvalds | 1e4c85f | 2005-10-31 19:16:17 -0800 | [diff] [blame] | 886 | smpboot_clear_io_apic_irqs(); |
| 887 | phys_cpu_present_map = physid_mask_of_physid(0); |
Ingo Molnar | 54ffaa4 | 2007-10-19 20:35:02 +0200 | [diff] [blame] | 888 | map_cpu_to_logical_apicid(); |
Mike Travis | d5a7430 | 2007-10-16 01:24:05 -0700 | [diff] [blame] | 889 | cpu_set(0, per_cpu(cpu_sibling_map, 0)); |
Mike Travis | 0835761 | 2007-10-16 01:24:04 -0700 | [diff] [blame] | 890 | cpu_set(0, per_cpu(cpu_core_map, 0)); |
Linus Torvalds | 1e4c85f | 2005-10-31 19:16:17 -0800 | [diff] [blame] | 891 | return; |
| 892 | } |
| 893 | |
| 894 | connect_bsp_APIC(); |
| 895 | setup_local_APIC(); |
| 896 | map_cpu_to_logical_apicid(); |
| 897 | |
| 898 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 899 | setup_portio_remap(); |
| 900 | |
| 901 | /* |
| 902 | * Scan the CPU present map and fire up the other CPUs via do_boot_cpu |
| 903 | * |
| 904 | * In clustered apic mode, phys_cpu_present_map is a constructed thus: |
| 905 | * bits 0-3 are quad0, 4-7 are quad1, etc. A perverse twist on the |
| 906 | * clustered apic ID. |
| 907 | */ |
| 908 | Dprintk("CPU present map: %lx\n", physids_coerce(phys_cpu_present_map)); |
| 909 | |
| 910 | kicked = 1; |
| 911 | for (bit = 0; kicked < NR_CPUS && bit < MAX_APICS; bit++) { |
| 912 | apicid = cpu_present_to_apicid(bit); |
| 913 | /* |
| 914 | * Don't even attempt to start the boot CPU! |
| 915 | */ |
| 916 | if ((apicid == boot_cpu_apicid) || (apicid == BAD_APICID)) |
| 917 | continue; |
| 918 | |
| 919 | if (!check_apicid_present(bit)) |
| 920 | continue; |
| 921 | if (max_cpus <= cpucount+1) |
| 922 | continue; |
| 923 | |
Li Shaohua | e1367da | 2005-06-25 14:54:56 -0700 | [diff] [blame] | 924 | if (((cpu = alloc_cpu_id()) <= 0) || do_boot_cpu(apicid, cpu)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 925 | printk("CPU #%d not responding - cannot use it.\n", |
| 926 | apicid); |
| 927 | else |
| 928 | ++kicked; |
| 929 | } |
| 930 | |
| 931 | /* |
| 932 | * Cleanup possible dangling ends... |
| 933 | */ |
| 934 | smpboot_restore_warm_reset_vector(); |
| 935 | |
| 936 | /* |
| 937 | * Allow the user to impress friends. |
| 938 | */ |
| 939 | Dprintk("Before bogomips.\n"); |
Mike Travis | 7bf0c23 | 2008-01-30 13:30:55 +0100 | [diff] [blame] | 940 | for_each_possible_cpu(cpu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 941 | if (cpu_isset(cpu, cpu_callout_map)) |
Mike Travis | 92cb761 | 2007-10-19 20:35:04 +0200 | [diff] [blame] | 942 | bogosum += cpu_data(cpu).loops_per_jiffy; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 943 | printk(KERN_INFO |
| 944 | "Total of %d processors activated (%lu.%02lu BogoMIPS).\n", |
| 945 | cpucount+1, |
| 946 | bogosum/(500000/HZ), |
| 947 | (bogosum/(5000/HZ))%100); |
| 948 | |
| 949 | Dprintk("Before bogocount - setting activated=1.\n"); |
| 950 | |
| 951 | if (smp_b_stepping) |
| 952 | printk(KERN_WARNING "WARNING: SMP operation may be unreliable with B stepping processors.\n"); |
| 953 | |
| 954 | /* |
| 955 | * Don't taint if we are running SMP kernel on a single non-MP |
| 956 | * approved Athlon |
| 957 | */ |
| 958 | if (tainted & TAINT_UNSAFE_SMP) { |
| 959 | if (cpucount) |
| 960 | printk (KERN_INFO "WARNING: This combination of AMD processors is not suitable for SMP.\n"); |
| 961 | else |
| 962 | tainted &= ~TAINT_UNSAFE_SMP; |
| 963 | } |
| 964 | |
| 965 | Dprintk("Boot done.\n"); |
| 966 | |
| 967 | /* |
Mike Travis | d5a7430 | 2007-10-16 01:24:05 -0700 | [diff] [blame] | 968 | * construct cpu_sibling_map, so that we can tell sibling CPUs |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 969 | * efficiently. |
| 970 | */ |
Mike Travis | 7bf0c23 | 2008-01-30 13:30:55 +0100 | [diff] [blame] | 971 | for_each_possible_cpu(cpu) { |
Mike Travis | d5a7430 | 2007-10-16 01:24:05 -0700 | [diff] [blame] | 972 | cpus_clear(per_cpu(cpu_sibling_map, cpu)); |
Mike Travis | 0835761 | 2007-10-16 01:24:04 -0700 | [diff] [blame] | 973 | cpus_clear(per_cpu(cpu_core_map, cpu)); |
Andi Kleen | 3dd9d51 | 2005-04-16 15:25:15 -0700 | [diff] [blame] | 974 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 975 | |
Mike Travis | d5a7430 | 2007-10-16 01:24:05 -0700 | [diff] [blame] | 976 | cpu_set(0, per_cpu(cpu_sibling_map, 0)); |
Mike Travis | 0835761 | 2007-10-16 01:24:04 -0700 | [diff] [blame] | 977 | cpu_set(0, per_cpu(cpu_core_map, 0)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 978 | |
Linus Torvalds | 1e4c85f | 2005-10-31 19:16:17 -0800 | [diff] [blame] | 979 | smpboot_setup_io_apic(); |
| 980 | |
Zachary Amsden | bbab4f3 | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 981 | setup_boot_clock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 982 | } |
| 983 | |
| 984 | /* These are wrappers to interface to the new boot process. Someone |
| 985 | who understands all this stuff should rewrite it properly. --RR 15/Jul/02 */ |
Jeremy Fitzhardinge | 01a2f43 | 2007-05-02 19:27:11 +0200 | [diff] [blame] | 986 | void __init native_smp_prepare_cpus(unsigned int max_cpus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 987 | { |
Zwane Mwaikambo | f370513 | 2005-06-25 14:54:50 -0700 | [diff] [blame] | 988 | smp_commenced_mask = cpumask_of_cpu(0); |
| 989 | cpu_callin_map = cpumask_of_cpu(0); |
| 990 | mb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 991 | smp_boot_cpus(max_cpus); |
| 992 | } |
| 993 | |
Jeremy Fitzhardinge | 01a2f43 | 2007-05-02 19:27:11 +0200 | [diff] [blame] | 994 | void __init native_smp_prepare_boot_cpu(void) |
Rusty Russell | bf504672 | 2007-05-02 19:27:10 +0200 | [diff] [blame] | 995 | { |
| 996 | unsigned int cpu = smp_processor_id(); |
| 997 | |
Jeremy Fitzhardinge | 7c3576d | 2007-05-02 19:27:16 +0200 | [diff] [blame] | 998 | init_gdt(cpu); |
Rusty Russell | bf504672 | 2007-05-02 19:27:10 +0200 | [diff] [blame] | 999 | switch_to_new_gdt(); |
| 1000 | |
| 1001 | cpu_set(cpu, cpu_online_map); |
| 1002 | cpu_set(cpu, cpu_callout_map); |
| 1003 | cpu_set(cpu, cpu_present_map); |
| 1004 | cpu_set(cpu, cpu_possible_map); |
| 1005 | __get_cpu_var(cpu_state) = CPU_ONLINE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1006 | } |
| 1007 | |
Jeremy Fitzhardinge | 01a2f43 | 2007-05-02 19:27:11 +0200 | [diff] [blame] | 1008 | int __cpuinit native_cpu_up(unsigned int cpu) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1009 | { |
Ingo Molnar | d04f41e | 2007-03-07 18:12:31 +0100 | [diff] [blame] | 1010 | unsigned long flags; |
Ashok Raj | 34f361a | 2006-03-25 03:08:18 -0800 | [diff] [blame] | 1011 | #ifdef CONFIG_HOTPLUG_CPU |
Ingo Molnar | d04f41e | 2007-03-07 18:12:31 +0100 | [diff] [blame] | 1012 | int ret = 0; |
Ashok Raj | 34f361a | 2006-03-25 03:08:18 -0800 | [diff] [blame] | 1013 | |
| 1014 | /* |
| 1015 | * We do warm boot only on cpus that had booted earlier |
| 1016 | * Otherwise cold boot is all handled from smp_boot_cpus(). |
| 1017 | * cpu_callin_map is set during AP kickstart process. Its reset |
| 1018 | * when a cpu is taken offline from cpu_exit_clear(). |
| 1019 | */ |
| 1020 | if (!cpu_isset(cpu, cpu_callin_map)) |
| 1021 | ret = __smp_prepare_cpu(cpu); |
| 1022 | |
| 1023 | if (ret) |
| 1024 | return -EIO; |
| 1025 | #endif |
| 1026 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1027 | /* In case one didn't come up */ |
| 1028 | if (!cpu_isset(cpu, cpu_callin_map)) { |
Zwane Mwaikambo | f370513 | 2005-06-25 14:54:50 -0700 | [diff] [blame] | 1029 | printk(KERN_DEBUG "skipping cpu%d, didn't come online\n", cpu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1030 | return -EIO; |
| 1031 | } |
| 1032 | |
Li Shaohua | e1367da | 2005-06-25 14:54:56 -0700 | [diff] [blame] | 1033 | per_cpu(cpu_state, cpu) = CPU_UP_PREPARE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1034 | /* Unleash the CPU! */ |
| 1035 | cpu_set(cpu, smp_commenced_mask); |
Ingo Molnar | 95492e4 | 2007-02-16 01:27:34 -0800 | [diff] [blame] | 1036 | |
| 1037 | /* |
Ingo Molnar | d04f41e | 2007-03-07 18:12:31 +0100 | [diff] [blame] | 1038 | * Check TSC synchronization with the AP (keep irqs disabled |
| 1039 | * while doing so): |
Ingo Molnar | 95492e4 | 2007-02-16 01:27:34 -0800 | [diff] [blame] | 1040 | */ |
Ingo Molnar | d04f41e | 2007-03-07 18:12:31 +0100 | [diff] [blame] | 1041 | local_irq_save(flags); |
Ingo Molnar | 95492e4 | 2007-02-16 01:27:34 -0800 | [diff] [blame] | 1042 | check_tsc_sync_source(cpu); |
Ingo Molnar | d04f41e | 2007-03-07 18:12:31 +0100 | [diff] [blame] | 1043 | local_irq_restore(flags); |
Ingo Molnar | 95492e4 | 2007-02-16 01:27:34 -0800 | [diff] [blame] | 1044 | |
Ingo Molnar | d04f41e | 2007-03-07 18:12:31 +0100 | [diff] [blame] | 1045 | while (!cpu_isset(cpu, cpu_online_map)) { |
Andreas Mohr | 1869891 | 2006-06-25 05:46:52 -0700 | [diff] [blame] | 1046 | cpu_relax(); |
Ingo Molnar | d04f41e | 2007-03-07 18:12:31 +0100 | [diff] [blame] | 1047 | touch_nmi_watchdog(); |
| 1048 | } |
Siddha, Suresh B | b0d0a4b | 2006-12-07 02:14:10 +0100 | [diff] [blame] | 1049 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1050 | return 0; |
| 1051 | } |
| 1052 | |
Jeremy Fitzhardinge | 01a2f43 | 2007-05-02 19:27:11 +0200 | [diff] [blame] | 1053 | void __init native_smp_cpus_done(unsigned int max_cpus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1054 | { |
| 1055 | #ifdef CONFIG_X86_IO_APIC |
| 1056 | setup_ioapic_dest(); |
| 1057 | #endif |
| 1058 | zap_low_mappings(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1059 | } |
| 1060 | |
| 1061 | void __init smp_intr_init(void) |
| 1062 | { |
| 1063 | /* |
| 1064 | * IRQ0 must be given a fixed assignment and initialized, |
| 1065 | * because it's used before the IO-APIC is set up. |
| 1066 | */ |
| 1067 | set_intr_gate(FIRST_DEVICE_VECTOR, interrupt[0]); |
| 1068 | |
| 1069 | /* |
| 1070 | * The reschedule interrupt is a CPU-to-CPU reschedule-helper |
| 1071 | * IPI, driven by wakeup. |
| 1072 | */ |
| 1073 | set_intr_gate(RESCHEDULE_VECTOR, reschedule_interrupt); |
| 1074 | |
| 1075 | /* IPI for invalidation */ |
| 1076 | set_intr_gate(INVALIDATE_TLB_VECTOR, invalidate_interrupt); |
| 1077 | |
| 1078 | /* IPI for generic function call */ |
| 1079 | set_intr_gate(CALL_FUNCTION_VECTOR, call_function_interrupt); |
| 1080 | } |