x86: call do_boot_cpu directly from native_cpu_up
[linux-2.6/verdex.git] / arch / x86 / kernel / smpboot_32.c
blob4ba5ab2d81fb4ce465d5edb37d1a1e96ac08e467
1 /*
2 * x86 SMP booting functions
4 * (c) 1995 Alan Cox, Building #3 <alan@redhat.com>
5 * (c) 1998, 1999, 2000 Ingo Molnar <mingo@redhat.com>
7 * Much of the core SMP work is based on previous work by Thomas Radke, to
8 * whom a great many thanks are extended.
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.
14 * This code is released under the GNU General Public License version 2 or
15 * later.
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. */
36 #include <linux/module.h>
37 #include <linux/init.h>
38 #include <linux/kernel.h>
40 #include <linux/mm.h>
41 #include <linux/sched.h>
42 #include <linux/kernel_stat.h>
43 #include <linux/bootmem.h>
44 #include <linux/notifier.h>
45 #include <linux/cpu.h>
46 #include <linux/percpu.h>
47 #include <linux/nmi.h>
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>
54 #include <asm/nmi.h>
56 #include <mach_apic.h>
57 #include <mach_wakecpu.h>
58 #include <smpboot_hooks.h>
59 #include <asm/vmi.h>
60 #include <asm/mtrr.h>
62 /* which logical CPU number maps to which CPU (physical APIC ID) */
63 u16 x86_cpu_to_apicid_init[NR_CPUS] __initdata =
64 { [0 ... NR_CPUS-1] = BAD_APICID };
65 void *x86_cpu_to_apicid_early_ptr;
66 DEFINE_PER_CPU(u16, x86_cpu_to_apicid) = BAD_APICID;
67 EXPORT_PER_CPU_SYMBOL(x86_cpu_to_apicid);
69 u16 x86_bios_cpu_apicid_init[NR_CPUS] __initdata
70 = { [0 ... NR_CPUS-1] = BAD_APICID };
71 void *x86_bios_cpu_apicid_early_ptr;
72 DEFINE_PER_CPU(u16, x86_bios_cpu_apicid) = BAD_APICID;
73 EXPORT_PER_CPU_SYMBOL(x86_bios_cpu_apicid);
75 u8 apicid_2_node[MAX_APICID];
77 static void map_cpu_to_logical_apicid(void);
79 /* State of each CPU. */
80 DEFINE_PER_CPU(int, cpu_state) = { 0 };
82 /* Store all idle threads, this can be reused instead of creating
83 * a new thread. Also avoids complicated thread destroy functionality
84 * for idle threads.
86 #ifdef CONFIG_HOTPLUG_CPU
88 * Needed only for CONFIG_HOTPLUG_CPU because __cpuinitdata is
89 * removed after init for !CONFIG_HOTPLUG_CPU.
91 static DEFINE_PER_CPU(struct task_struct *, idle_thread_array);
92 #define get_idle_for_cpu(x) (per_cpu(idle_thread_array, x))
93 #define set_idle_for_cpu(x, p) (per_cpu(idle_thread_array, x) = (p))
94 #else
95 struct task_struct *idle_thread_array[NR_CPUS] __cpuinitdata ;
96 #define get_idle_for_cpu(x) (idle_thread_array[(x)])
97 #define set_idle_for_cpu(x, p) (idle_thread_array[(x)] = (p))
98 #endif
100 static atomic_t init_deasserted;
102 static void __cpuinit smp_callin(void)
104 int cpuid, phys_id;
105 unsigned long timeout;
108 * If waken up by an INIT in an 82489DX configuration
109 * we may get here before an INIT-deassert IPI reaches
110 * our local APIC. We have to wait for the IPI or we'll
111 * lock up on an APIC access.
113 wait_for_init_deassert(&init_deasserted);
116 * (This works even if the APIC is not enabled.)
118 phys_id = GET_APIC_ID(apic_read(APIC_ID));
119 cpuid = smp_processor_id();
120 if (cpu_isset(cpuid, cpu_callin_map)) {
121 printk("huh, phys CPU#%d, CPU#%d already present??\n",
122 phys_id, cpuid);
123 BUG();
125 Dprintk("CPU#%d (phys ID: %d) waiting for CALLOUT\n", cpuid, phys_id);
128 * STARTUP IPIs are fragile beasts as they might sometimes
129 * trigger some glue motherboard logic. Complete APIC bus
130 * silence for 1 second, this overestimates the time the
131 * boot CPU is spending to send the up to 2 STARTUP IPIs
132 * by a factor of two. This should be enough.
136 * Waiting 2s total for startup (udelay is not yet working)
138 timeout = jiffies + 2*HZ;
139 while (time_before(jiffies, timeout)) {
141 * Has the boot CPU finished it's STARTUP sequence?
143 if (cpu_isset(cpuid, cpu_callout_map))
144 break;
145 cpu_relax();
148 if (!time_before(jiffies, timeout)) {
149 printk("BUG: CPU%d started up but did not get a callout!\n",
150 cpuid);
151 BUG();
155 * the boot CPU has finished the init stage and is spinning
156 * on callin_map until we finish. We are free to set up this
157 * CPU, first the APIC. (this is probably redundant on most
158 * boards)
161 Dprintk("CALLIN, before setup_local_APIC().\n");
162 smp_callin_clear_local_apic();
163 setup_local_APIC();
164 end_local_APIC_setup();
165 map_cpu_to_logical_apicid();
168 * Get our bogomips.
170 local_irq_enable();
171 calibrate_delay();
172 local_irq_disable();
173 Dprintk("Stack at about %p\n",&cpuid);
176 * Save our processor parameters
178 smp_store_cpu_info(cpuid);
181 * Allow the master to continue.
183 cpu_set(cpuid, cpu_callin_map);
187 * Activate a secondary processor.
189 static void __cpuinit start_secondary(void *unused)
192 * Don't put *anything* before cpu_init(), SMP booting is too
193 * fragile that we want to limit the things done here to the
194 * most necessary things.
196 #ifdef CONFIG_VMI
197 vmi_bringup();
198 #endif
199 cpu_init();
200 preempt_disable();
201 smp_callin();
203 /* otherwise gcc will move up smp_processor_id before the cpu_init */
204 barrier();
206 * Check TSC synchronization with the BP:
208 check_tsc_sync_target();
210 if (nmi_watchdog == NMI_IO_APIC) {
211 disable_8259A_irq(0);
212 enable_NMI_through_LVT0();
213 enable_8259A_irq(0);
216 /* This must be done before setting cpu_online_map */
217 set_cpu_sibling_map(raw_smp_processor_id());
218 wmb();
221 * We need to hold call_lock, so there is no inconsistency
222 * between the time smp_call_function() determines number of
223 * IPI recipients, and the time when the determination is made
224 * for which cpus receive the IPI. Holding this
225 * lock helps us to not include this cpu in a currently in progress
226 * smp_call_function().
228 lock_ipi_call_lock();
229 cpu_set(smp_processor_id(), cpu_online_map);
230 unlock_ipi_call_lock();
231 per_cpu(cpu_state, smp_processor_id()) = CPU_ONLINE;
233 setup_secondary_clock();
235 wmb();
236 cpu_idle();
240 * Everything has been set up for the secondary
241 * CPUs - they just need to reload everything
242 * from the task structure
243 * This function must not return.
245 void __devinit initialize_secondary(void)
248 * We don't actually need to load the full TSS,
249 * basically just the stack pointer and the ip.
252 asm volatile(
253 "movl %0,%%esp\n\t"
254 "jmp *%1"
256 :"m" (current->thread.sp),"m" (current->thread.ip));
259 /* Static state in head.S used to set up a CPU */
260 extern struct {
261 void * sp;
262 unsigned short ss;
263 } stack_start;
265 #ifdef CONFIG_NUMA
267 /* which logical CPUs are on which nodes */
268 cpumask_t node_to_cpumask_map[MAX_NUMNODES] __read_mostly =
269 { [0 ... MAX_NUMNODES-1] = CPU_MASK_NONE };
270 EXPORT_SYMBOL(node_to_cpumask_map);
271 /* which node each logical CPU is on */
272 int cpu_to_node_map[NR_CPUS] __read_mostly = { [0 ... NR_CPUS-1] = 0 };
273 EXPORT_SYMBOL(cpu_to_node_map);
275 /* set up a mapping between cpu and node. */
276 static inline void map_cpu_to_node(int cpu, int node)
278 printk("Mapping cpu %d to node %d\n", cpu, node);
279 cpu_set(cpu, node_to_cpumask_map[node]);
280 cpu_to_node_map[cpu] = node;
283 /* undo a mapping between cpu and node. */
284 static inline void unmap_cpu_to_node(int cpu)
286 int node;
288 printk("Unmapping cpu %d from all nodes\n", cpu);
289 for (node = 0; node < MAX_NUMNODES; node ++)
290 cpu_clear(cpu, node_to_cpumask_map[node]);
291 cpu_to_node_map[cpu] = 0;
293 #else /* !CONFIG_NUMA */
295 #define map_cpu_to_node(cpu, node) ({})
296 #define unmap_cpu_to_node(cpu) ({})
298 #endif /* CONFIG_NUMA */
300 u8 cpu_2_logical_apicid[NR_CPUS] __read_mostly = { [0 ... NR_CPUS-1] = BAD_APICID };
302 static void map_cpu_to_logical_apicid(void)
304 int cpu = smp_processor_id();
305 int apicid = logical_smp_processor_id();
306 int node = apicid_to_node(apicid);
308 if (!node_online(node))
309 node = first_online_node;
311 cpu_2_logical_apicid[cpu] = apicid;
312 map_cpu_to_node(cpu, node);
315 static void unmap_cpu_to_logical_apicid(int cpu)
317 cpu_2_logical_apicid[cpu] = BAD_APICID;
318 unmap_cpu_to_node(cpu);
321 static inline void __inquire_remote_apic(int apicid)
323 unsigned i, regs[] = { APIC_ID >> 4, APIC_LVR >> 4, APIC_SPIV >> 4 };
324 char *names[] = { "ID", "VERSION", "SPIV" };
325 int timeout;
326 u32 status;
328 printk(KERN_INFO "Inquiring remote APIC #%d...\n", apicid);
330 for (i = 0; i < ARRAY_SIZE(regs); i++) {
331 printk(KERN_INFO "... APIC #%d %s: ", apicid, names[i]);
334 * Wait for idle.
336 status = safe_apic_wait_icr_idle();
337 if (status)
338 printk(KERN_CONT
339 "a previous APIC delivery may have failed\n");
341 apic_write_around(APIC_ICR2, SET_APIC_DEST_FIELD(apicid));
342 apic_write_around(APIC_ICR, APIC_DM_REMRD | regs[i]);
344 timeout = 0;
345 do {
346 udelay(100);
347 status = apic_read(APIC_ICR) & APIC_ICR_RR_MASK;
348 } while (status == APIC_ICR_RR_INPROG && timeout++ < 1000);
350 switch (status) {
351 case APIC_ICR_RR_VALID:
352 status = apic_read(APIC_RRR);
353 printk(KERN_CONT "%08x\n", status);
354 break;
355 default:
356 printk(KERN_CONT "failed\n");
361 #ifdef WAKE_SECONDARY_VIA_NMI
363 * Poke the other CPU in the eye via NMI to wake it up. Remember that the normal
364 * INIT, INIT, STARTUP sequence will reset the chip hard for us, and this
365 * won't ... remember to clear down the APIC, etc later.
367 static int __devinit
368 wakeup_secondary_cpu(int logical_apicid, unsigned long start_eip)
370 unsigned long send_status, accept_status = 0;
371 int maxlvt;
373 /* Target chip */
374 apic_write_around(APIC_ICR2, SET_APIC_DEST_FIELD(logical_apicid));
376 /* Boot on the stack */
377 /* Kick the second */
378 apic_write_around(APIC_ICR, APIC_DM_NMI | APIC_DEST_LOGICAL);
380 Dprintk("Waiting for send to finish...\n");
381 send_status = safe_apic_wait_icr_idle();
384 * Give the other CPU some time to accept the IPI.
386 udelay(200);
388 * Due to the Pentium erratum 3AP.
390 maxlvt = lapic_get_maxlvt();
391 if (maxlvt > 3) {
392 apic_read_around(APIC_SPIV);
393 apic_write(APIC_ESR, 0);
395 accept_status = (apic_read(APIC_ESR) & 0xEF);
396 Dprintk("NMI sent.\n");
398 if (send_status)
399 printk("APIC never delivered???\n");
400 if (accept_status)
401 printk("APIC delivery error (%lx).\n", accept_status);
403 return (send_status | accept_status);
405 #endif /* WAKE_SECONDARY_VIA_NMI */
407 #ifdef WAKE_SECONDARY_VIA_INIT
408 static int __devinit
409 wakeup_secondary_cpu(int phys_apicid, unsigned long start_eip)
411 unsigned long send_status, accept_status = 0;
412 int maxlvt, num_starts, j;
415 * Be paranoid about clearing APIC errors.
417 if (APIC_INTEGRATED(apic_version[phys_apicid])) {
418 apic_read_around(APIC_SPIV);
419 apic_write(APIC_ESR, 0);
420 apic_read(APIC_ESR);
423 Dprintk("Asserting INIT.\n");
426 * Turn INIT on target chip
428 apic_write_around(APIC_ICR2, SET_APIC_DEST_FIELD(phys_apicid));
431 * Send IPI
433 apic_write_around(APIC_ICR, APIC_INT_LEVELTRIG | APIC_INT_ASSERT
434 | APIC_DM_INIT);
436 Dprintk("Waiting for send to finish...\n");
437 send_status = safe_apic_wait_icr_idle();
439 mdelay(10);
441 Dprintk("Deasserting INIT.\n");
443 /* Target chip */
444 apic_write_around(APIC_ICR2, SET_APIC_DEST_FIELD(phys_apicid));
446 /* Send IPI */
447 apic_write_around(APIC_ICR, APIC_INT_LEVELTRIG | APIC_DM_INIT);
449 Dprintk("Waiting for send to finish...\n");
450 send_status = safe_apic_wait_icr_idle();
452 mb();
453 atomic_set(&init_deasserted, 1);
456 * Should we send STARTUP IPIs ?
458 * Determine this based on the APIC version.
459 * If we don't have an integrated APIC, don't send the STARTUP IPIs.
461 if (APIC_INTEGRATED(apic_version[phys_apicid]))
462 num_starts = 2;
463 else
464 num_starts = 0;
467 * Paravirt / VMI wants a startup IPI hook here to set up the
468 * target processor state.
470 startup_ipi_hook(phys_apicid, (unsigned long) start_secondary,
471 (unsigned long) stack_start.sp);
474 * Run STARTUP IPI loop.
476 Dprintk("#startup loops: %d.\n", num_starts);
478 maxlvt = lapic_get_maxlvt();
480 for (j = 1; j <= num_starts; j++) {
481 Dprintk("Sending STARTUP #%d.\n",j);
482 apic_read_around(APIC_SPIV);
483 apic_write(APIC_ESR, 0);
484 apic_read(APIC_ESR);
485 Dprintk("After apic_write.\n");
488 * STARTUP IPI
491 /* Target chip */
492 apic_write_around(APIC_ICR2, SET_APIC_DEST_FIELD(phys_apicid));
494 /* Boot on the stack */
495 /* Kick the second */
496 apic_write_around(APIC_ICR, APIC_DM_STARTUP
497 | (start_eip >> 12));
500 * Give the other CPU some time to accept the IPI.
502 udelay(300);
504 Dprintk("Startup point 1.\n");
506 Dprintk("Waiting for send to finish...\n");
507 send_status = safe_apic_wait_icr_idle();
510 * Give the other CPU some time to accept the IPI.
512 udelay(200);
514 * Due to the Pentium erratum 3AP.
516 if (maxlvt > 3) {
517 apic_read_around(APIC_SPIV);
518 apic_write(APIC_ESR, 0);
520 accept_status = (apic_read(APIC_ESR) & 0xEF);
521 if (send_status || accept_status)
522 break;
524 Dprintk("After Startup.\n");
526 if (send_status)
527 printk("APIC never delivered???\n");
528 if (accept_status)
529 printk("APIC delivery error (%lx).\n", accept_status);
531 return (send_status | accept_status);
533 #endif /* WAKE_SECONDARY_VIA_INIT */
535 extern cpumask_t cpu_initialized;
537 struct create_idle {
538 struct work_struct work;
539 struct task_struct *idle;
540 struct completion done;
541 int cpu;
544 static void __cpuinit do_fork_idle(struct work_struct *work)
546 struct create_idle *c_idle =
547 container_of(work, struct create_idle, work);
549 c_idle->idle = fork_idle(c_idle->cpu);
550 complete(&c_idle->done);
552 static int __cpuinit do_boot_cpu(int apicid, int cpu)
554 * NOTE - on most systems this is a PHYSICAL apic ID, but on multiquad
555 * (ie clustered apic addressing mode), this is a LOGICAL apic ID.
556 * Returns zero if CPU booted OK, else error code from wakeup_secondary_cpu.
559 unsigned long boot_error = 0;
560 int timeout;
561 unsigned long start_eip;
562 unsigned short nmi_high = 0, nmi_low = 0;
563 struct create_idle c_idle = {
564 .cpu = cpu,
565 .done = COMPLETION_INITIALIZER_ONSTACK(c_idle.done),
567 INIT_WORK(&c_idle.work, do_fork_idle);
569 alternatives_smp_switch(1);
571 c_idle.idle = get_idle_for_cpu(cpu);
574 * We can't use kernel_thread since we must avoid to
575 * reschedule the child.
577 if (c_idle.idle) {
578 c_idle.idle->thread.sp = (unsigned long) (((struct pt_regs *)
579 (THREAD_SIZE + task_stack_page(c_idle.idle))) - 1);
580 init_idle(c_idle.idle, cpu);
581 goto do_rest;
584 if (!keventd_up() || current_is_keventd())
585 c_idle.work.func(&c_idle.work);
586 else {
587 schedule_work(&c_idle.work);
588 wait_for_completion(&c_idle.done);
591 if (IS_ERR(c_idle.idle)) {
592 printk(KERN_ERR "failed fork for CPU %d\n", cpu);
593 return PTR_ERR(c_idle.idle);
596 set_idle_for_cpu(cpu, c_idle.idle);
597 do_rest:
598 per_cpu(current_task, cpu) = c_idle.idle;
599 init_gdt(cpu);
600 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
602 c_idle.idle->thread.ip = (unsigned long) start_secondary;
603 /* start_eip had better be page-aligned! */
604 start_eip = setup_trampoline();
606 /* So we see what's up */
607 printk("Booting processor %d/%d ip %lx\n", cpu, apicid, start_eip);
608 /* Stack for startup_32 can be just as for start_secondary onwards */
609 stack_start.sp = (void *) c_idle.idle->thread.sp;
611 irq_ctx_init(cpu);
614 * This grunge runs the startup process for
615 * the targeted processor.
618 atomic_set(&init_deasserted, 0);
620 Dprintk("Setting warm reset code and vector.\n");
622 store_NMI_vector(&nmi_high, &nmi_low);
624 smpboot_setup_warm_reset_vector(start_eip);
626 * Be paranoid about clearing APIC errors.
628 apic_write(APIC_ESR, 0);
629 apic_read(APIC_ESR);
633 * Starting actual IPI sequence...
635 boot_error = wakeup_secondary_cpu(apicid, start_eip);
637 if (!boot_error) {
639 * allow APs to start initializing.
641 Dprintk("Before Callout %d.\n", cpu);
642 cpu_set(cpu, cpu_callout_map);
643 Dprintk("After Callout %d.\n", cpu);
646 * Wait 5s total for a response
648 for (timeout = 0; timeout < 50000; timeout++) {
649 if (cpu_isset(cpu, cpu_callin_map))
650 break; /* It has booted */
651 udelay(100);
654 if (cpu_isset(cpu, cpu_callin_map)) {
655 /* number CPUs logically, starting from 1 (BSP is 0) */
656 Dprintk("OK.\n");
657 printk("CPU%d: ", cpu);
658 print_cpu_info(&cpu_data(cpu));
659 Dprintk("CPU has booted.\n");
660 } else {
661 boot_error= 1;
662 if (*((volatile unsigned char *)trampoline_base)
663 == 0xA5)
664 /* trampoline started but...? */
665 printk("Stuck ??\n");
666 else
667 /* trampoline code not run */
668 printk("Not responding.\n");
669 inquire_remote_apic(apicid);
673 if (boot_error) {
674 /* Try to put things back the way they were before ... */
675 unmap_cpu_to_logical_apicid(cpu);
676 cpu_clear(cpu, cpu_callout_map); /* was set here (do_boot_cpu()) */
677 cpu_clear(cpu, cpu_initialized); /* was set by cpu_init() */
678 cpu_clear(cpu, cpu_possible_map);
679 per_cpu(x86_cpu_to_apicid, cpu) = BAD_APICID;
682 /* mark "stuck" area as not stuck */
683 *((volatile unsigned long *)trampoline_base) = 0;
685 return boot_error;
688 #ifdef CONFIG_HOTPLUG_CPU
689 void cpu_exit_clear(void)
691 int cpu = raw_smp_processor_id();
693 idle_task_exit();
695 cpu_uninit();
696 irq_ctx_exit(cpu);
698 cpu_clear(cpu, cpu_callout_map);
699 cpu_clear(cpu, cpu_callin_map);
701 unmap_cpu_to_logical_apicid(cpu);
703 #endif
705 static int boot_cpu_logical_apicid;
706 /* Where the IO area was mapped on multiquad, always 0 otherwise */
707 void *xquad_portio;
708 #ifdef CONFIG_X86_NUMAQ
709 EXPORT_SYMBOL(xquad_portio);
710 #endif
712 static void __init disable_smp(void)
714 cpu_possible_map = cpumask_of_cpu(0);
715 cpu_present_map = cpumask_of_cpu(0);
716 smpboot_clear_io_apic_irqs();
717 phys_cpu_present_map = physid_mask_of_physid(0);
718 map_cpu_to_logical_apicid();
719 cpu_set(0, per_cpu(cpu_sibling_map, 0));
720 cpu_set(0, per_cpu(cpu_core_map, 0));
723 static int __init smp_sanity_check(unsigned max_cpus)
726 * If we couldn't find an SMP configuration at boot time,
727 * get out of here now!
729 if (!smp_found_config && !acpi_lapic) {
730 printk(KERN_NOTICE "SMP motherboard not detected.\n");
731 disable_smp();
732 if (APIC_init_uniprocessor())
733 printk(KERN_NOTICE "Local APIC not detected."
734 " Using dummy APIC emulation.\n");
735 return -1;
739 * Should not be necessary because the MP table should list the boot
740 * CPU too, but we do it for the sake of robustness anyway.
741 * Makes no sense to do this check in clustered apic mode, so skip it
743 if (!check_phys_apicid_present(boot_cpu_physical_apicid)) {
744 printk("weird, boot CPU (#%d) not listed by the BIOS.\n",
745 boot_cpu_physical_apicid);
746 physid_set(hard_smp_processor_id(), phys_cpu_present_map);
750 * If we couldn't find a local APIC, then get out of here now!
752 if (APIC_INTEGRATED(apic_version[boot_cpu_physical_apicid]) && !cpu_has_apic) {
753 printk(KERN_ERR "BIOS bug, local APIC #%d not detected!...\n",
754 boot_cpu_physical_apicid);
755 printk(KERN_ERR "... forcing use of dummy APIC emulation. (tell your hw vendor)\n");
756 return -1;
759 verify_local_APIC();
762 * If SMP should be disabled, then really disable it!
764 if (!max_cpus) {
765 smp_found_config = 0;
766 printk(KERN_INFO "SMP mode deactivated, forcing use of dummy APIC emulation.\n");
768 if (nmi_watchdog == NMI_LOCAL_APIC) {
769 printk(KERN_INFO "activating minimal APIC for NMI watchdog use.\n");
770 connect_bsp_APIC();
771 setup_local_APIC();
772 end_local_APIC_setup();
774 return -1;
776 return 0;
780 * Cycle through the processors sending APIC IPIs to boot each.
782 static void __init smp_boot_cpus(unsigned int max_cpus)
785 * Setup boot CPU information
787 smp_store_cpu_info(0); /* Final full version of the data */
788 printk(KERN_INFO "CPU%d: ", 0);
789 print_cpu_info(&cpu_data(0));
791 boot_cpu_physical_apicid = GET_APIC_ID(apic_read(APIC_ID));
792 boot_cpu_logical_apicid = logical_smp_processor_id();
794 current_thread_info()->cpu = 0;
796 set_cpu_sibling_map(0);
798 if (smp_sanity_check(max_cpus) < 0) {
799 printk(KERN_INFO "SMP disabled\n");
800 disable_smp();
801 return;
804 connect_bsp_APIC();
805 setup_local_APIC();
806 end_local_APIC_setup();
807 map_cpu_to_logical_apicid();
810 setup_portio_remap();
812 smpboot_setup_io_apic();
814 setup_boot_clock();
817 /* These are wrappers to interface to the new boot process. Someone
818 who understands all this stuff should rewrite it properly. --RR 15/Jul/02 */
819 void __init native_smp_prepare_cpus(unsigned int max_cpus)
821 nmi_watchdog_default();
822 cpu_callin_map = cpumask_of_cpu(0);
823 mb();
824 smp_boot_cpus(max_cpus);
827 void __init native_smp_prepare_boot_cpu(void)
829 unsigned int cpu = smp_processor_id();
831 init_gdt(cpu);
832 switch_to_new_gdt();
834 cpu_set(cpu, cpu_callout_map);
835 __get_cpu_var(cpu_state) = CPU_ONLINE;
838 int __cpuinit native_cpu_up(unsigned int cpu)
840 int apicid = cpu_present_to_apicid(cpu);
841 unsigned long flags;
843 WARN_ON(irqs_disabled());
845 Dprintk("++++++++++++++++++++=_---CPU UP %u\n", cpu);
847 if (apicid == BAD_APICID || apicid == boot_cpu_physical_apicid ||
848 !physid_isset(apicid, phys_cpu_present_map)) {
849 printk(KERN_ERR "%s: bad cpu %d\n", __func__, cpu);
850 return -EINVAL;
854 * Save current MTRR state in case it was changed since early boot
855 * (e.g. by the ACPI SMI) to initialize new CPUs with MTRRs in sync:
857 mtrr_save_state();
859 per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
861 /* init low mem mapping */
862 clone_pgd_range(swapper_pg_dir, swapper_pg_dir + USER_PGD_PTRS,
863 min_t(unsigned long, KERNEL_PGD_PTRS, USER_PGD_PTRS));
864 flush_tlb_all();
866 do_boot_cpu(apicid, cpu);
868 /* In case one didn't come up */
869 if (!cpu_isset(cpu, cpu_callin_map)) {
870 printk(KERN_DEBUG "skipping cpu%d, didn't come online\n", cpu);
871 return -EIO;
876 * Check TSC synchronization with the AP (keep irqs disabled
877 * while doing so):
879 local_irq_save(flags);
880 check_tsc_sync_source(cpu);
881 local_irq_restore(flags);
883 while (!cpu_isset(cpu, cpu_online_map)) {
884 cpu_relax();
885 touch_nmi_watchdog();
888 return 0;
891 extern void impress_friends(void);
892 extern void smp_checks(void);
894 void __init native_smp_cpus_done(unsigned int max_cpus)
897 * Cleanup possible dangling ends...
899 smpboot_restore_warm_reset_vector();
901 Dprintk("Boot done.\n");
903 impress_friends();
904 smp_checks();
905 #ifdef CONFIG_X86_IO_APIC
906 setup_ioapic_dest();
907 #endif
908 check_nmi_watchdog();
909 zap_low_mappings();