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>
6 * Copyright 2001 Andi Kleen, SuSE Labs.
8 * Much of the core SMP work is based on previous work by Thomas Radke, to
9 * whom a great many thanks are extended.
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.
15 * This code is released under the GNU General Public License version 2
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
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.
33 * Rusty Russell : Hacked into shape for new "hotplug" boot process.
34 * Andi Kleen : Converted to new state machine.
36 * Probably mostly hotplug CPU ready now.
37 * Ashok Raj : CPU hotplug support
41 #include <linux/init.h>
44 #include <linux/kernel_stat.h>
45 #include <linux/bootmem.h>
46 #include <linux/thread_info.h>
47 #include <linux/module.h>
48 #include <linux/delay.h>
49 #include <linux/mc146818rtc.h>
50 #include <linux/smp.h>
51 #include <linux/kdebug.h>
54 #include <asm/pgalloc.h>
56 #include <asm/tlbflush.h>
57 #include <asm/proto.h>
60 #include <asm/hw_irq.h>
63 #include <mach_wakecpu.h>
64 #include <mach_apic.h>
65 #include <smpboot_hooks.h>
66 #include <mach_apic.h>
68 /* Set when the idlers are all forked */
69 int smp_threads_ready;
71 /* State of each CPU */
72 DEFINE_PER_CPU(int, cpu_state) = { 0 };
74 cycles_t cacheflush_time;
75 unsigned long cache_decay_ticks;
78 * Fall back to non SMP mode after errors.
80 * RED-PEN audit/test this more. I bet there is more state messed up here.
82 static __init void disable_smp(void)
84 cpu_present_map = cpumask_of_cpu(0);
85 cpu_possible_map = cpumask_of_cpu(0);
87 phys_cpu_present_map =
88 physid_mask_of_physid(boot_cpu_physical_apicid);
90 phys_cpu_present_map = physid_mask_of_physid(0);
91 cpu_set(0, per_cpu(cpu_sibling_map, 0));
92 cpu_set(0, per_cpu(cpu_core_map, 0));
96 * Various sanity checks.
98 static int __init smp_sanity_check(unsigned max_cpus)
100 if (!physid_isset(hard_smp_processor_id(), phys_cpu_present_map)) {
101 printk("weird, boot CPU (#%d) not listed by the BIOS.\n",
102 hard_smp_processor_id());
103 physid_set(hard_smp_processor_id(), phys_cpu_present_map);
107 * If we couldn't find an SMP configuration at boot time,
108 * get out of here now!
110 if (!smp_found_config) {
111 printk(KERN_NOTICE "SMP motherboard not detected.\n");
113 if (APIC_init_uniprocessor())
114 printk(KERN_NOTICE "Local APIC not detected."
115 " Using dummy APIC emulation.\n");
120 * Should not be necessary because the MP table should list the boot
121 * CPU too, but we do it for the sake of robustness anyway.
123 if (!physid_isset(boot_cpu_physical_apicid, phys_cpu_present_map)) {
125 "weird, boot CPU (#%d) not listed by the BIOS.\n",
126 boot_cpu_physical_apicid);
127 physid_set(hard_smp_processor_id(), phys_cpu_present_map);
131 * If we couldn't find a local APIC, then get out of here now!
134 printk(KERN_ERR "BIOS bug, local APIC #%d not detected!...\n",
135 boot_cpu_physical_apicid);
136 printk(KERN_ERR "... forcing use of dummy APIC emulation. (tell your hw vendor)\n");
142 * If SMP should be disabled, then really disable it!
145 printk(KERN_INFO "SMP mode deactivated, forcing use of dummy APIC emulation.\n");
153 static void __init smp_cpu_index_default(void)
156 struct cpuinfo_x86 *c;
158 for_each_cpu_mask(i, cpu_possible_map) {
160 /* mark all to hotplug */
161 c->cpu_index = NR_CPUS;
166 * Prepare for SMP bootup. The MP table or ACPI has been read
167 * earlier. Just do some sanity checking here and enable APIC mode.
169 void __init native_smp_prepare_cpus(unsigned int max_cpus)
171 nmi_watchdog_default();
172 smp_cpu_index_default();
173 current_cpu_data = boot_cpu_data;
174 current_thread_info()->cpu = 0; /* needed? */
175 set_cpu_sibling_map(0);
177 if (smp_sanity_check(max_cpus) < 0) {
178 printk(KERN_INFO "SMP disabled\n");
185 * Switch from PIC to APIC mode.
190 * Enable IO APIC before setting up error vector
192 if (!skip_ioapic_setup && nr_ioapics)
194 end_local_APIC_setup();
196 if (GET_APIC_ID(apic_read(APIC_ID)) != boot_cpu_physical_apicid) {
197 panic("Boot APIC ID in local APIC unexpected (%d vs %d)",
198 GET_APIC_ID(apic_read(APIC_ID)), boot_cpu_physical_apicid);
199 /* Or can we switch back to PIC here? */
203 * Now start the IO-APICs
205 if (!skip_ioapic_setup && nr_ioapics)
211 * Set up local APIC timer on boot CPU.
215 printk(KERN_INFO "CPU%d: ", 0);
216 print_cpu_info(&cpu_data(0));
220 * Early setup to make printk work.
222 void __init native_smp_prepare_boot_cpu(void)
224 int me = smp_processor_id();
225 /* already set me in cpu_online_map in boot_cpu_init() */
226 cpu_set(me, cpu_callout_map);
227 per_cpu(cpu_state, me) = CPU_ONLINE;
230 extern void impress_friends(void);
231 extern void smp_checks(void);
234 * Finish the SMP boot.
236 void __init native_smp_cpus_done(unsigned int max_cpus)
238 smpboot_restore_warm_reset_vector();
240 Dprintk("Boot done.\n");
245 check_nmi_watchdog();