blob: 6679ac5021608a6ea11ec37d73575df6f1ac4b54 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 Kleena8ab26f2005-04-16 15:25:19 -070015 * This code is released under the GNU General Public License version 2
Linus Torvalds1da177e2005-04-16 15:20:36 -070016 *
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 Kleena8ab26f2005-04-16 15:25:19 -070033 * 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 Raj76e4f662005-06-25 14:55:00 -070037 * Ashok Raj : CPU hotplug support
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 */
39
Andi Kleena8ab26f2005-04-16 15:25:19 -070040
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include <linux/init.h>
42
43#include <linux/mm.h>
44#include <linux/kernel_stat.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#include <linux/bootmem.h>
46#include <linux/thread_info.h>
47#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070048#include <linux/delay.h>
49#include <linux/mc146818rtc.h>
Andrew Mortona3bc0db2006-09-25 23:32:33 -070050#include <linux/smp.h>
Christoph Hellwig1eeb66a2007-05-08 00:27:03 -070051#include <linux/kdebug.h>
Andrew Mortona3bc0db2006-09-25 23:32:33 -070052
Linus Torvalds1da177e2005-04-16 15:20:36 -070053#include <asm/mtrr.h>
54#include <asm/pgalloc.h>
55#include <asm/desc.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070056#include <asm/tlbflush.h>
57#include <asm/proto.h>
Andi Kleen75152112005-05-16 21:53:34 -070058#include <asm/nmi.h>
Al Viro9cdd3042005-09-12 18:49:25 +020059#include <asm/irq.h>
60#include <asm/hw_irq.h>
Ravikiran G Thirumalai488fc082006-02-07 12:58:23 -080061#include <asm/numa.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070062
Glauber de Oliveira Costa8d770102008-03-19 14:25:31 -030063#include <mach_wakecpu.h>
Glauber de Oliveira Costaf6bc4022008-03-19 14:25:53 -030064#include <mach_apic.h>
Glauber de Oliveira Costaeb44d0a2008-03-19 14:25:32 -030065#include <smpboot_hooks.h>
Glauber de Oliveira Costa07178262008-03-19 14:25:54 -030066#include <mach_apic.h>
Glauber de Oliveira Costa8d770102008-03-19 14:25:31 -030067
Andi Kleena8ab26f2005-04-16 15:25:19 -070068/* Set when the idlers are all forked */
69int smp_threads_ready;
70
Andi Kleena8ab26f2005-04-16 15:25:19 -070071cycles_t cacheflush_time;
72unsigned long cache_decay_ticks;
73
Glauber de Oliveira Costa1db17f52008-03-19 14:26:07 -030074static int boot_cpu_logical_apicid;
Andi Kleena8ab26f2005-04-16 15:25:19 -070075/*
Andi Kleena8ab26f2005-04-16 15:25:19 -070076 * Fall back to non SMP mode after errors.
77 *
78 * RED-PEN audit/test this more. I bet there is more state messed up here.
79 */
Ashok Raje6982c62005-06-25 14:54:58 -070080static __init void disable_smp(void)
Andi Kleena8ab26f2005-04-16 15:25:19 -070081{
82 cpu_present_map = cpumask_of_cpu(0);
83 cpu_possible_map = cpumask_of_cpu(0);
84 if (smp_found_config)
Glauber de Oliveira Costac70dcb72008-03-19 14:25:58 -030085 phys_cpu_present_map =
86 physid_mask_of_physid(boot_cpu_physical_apicid);
Andi Kleena8ab26f2005-04-16 15:25:19 -070087 else
88 phys_cpu_present_map = physid_mask_of_physid(0);
Mike Travisd5a74302007-10-16 01:24:05 -070089 cpu_set(0, per_cpu(cpu_sibling_map, 0));
Mike Travis08357612007-10-16 01:24:04 -070090 cpu_set(0, per_cpu(cpu_core_map, 0));
Andi Kleena8ab26f2005-04-16 15:25:19 -070091}
92
Linus Torvalds1da177e2005-04-16 15:20:36 -070093/*
Andi Kleena8ab26f2005-04-16 15:25:19 -070094 * Various sanity checks.
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 */
Ashok Raje6982c62005-06-25 14:54:58 -070096static int __init smp_sanity_check(unsigned max_cpus)
Linus Torvalds1da177e2005-04-16 15:20:36 -070097{
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 if (!physid_isset(hard_smp_processor_id(), phys_cpu_present_map)) {
99 printk("weird, boot CPU (#%d) not listed by the BIOS.\n",
100 hard_smp_processor_id());
101 physid_set(hard_smp_processor_id(), phys_cpu_present_map);
102 }
103
104 /*
105 * If we couldn't find an SMP configuration at boot time,
106 * get out of here now!
107 */
108 if (!smp_found_config) {
109 printk(KERN_NOTICE "SMP motherboard not detected.\n");
Andi Kleena8ab26f2005-04-16 15:25:19 -0700110 disable_smp();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 if (APIC_init_uniprocessor())
112 printk(KERN_NOTICE "Local APIC not detected."
113 " Using dummy APIC emulation.\n");
Andi Kleena8ab26f2005-04-16 15:25:19 -0700114 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 }
116
117 /*
118 * Should not be necessary because the MP table should list the boot
119 * CPU too, but we do it for the sake of robustness anyway.
120 */
Glauber de Oliveira Costac70dcb72008-03-19 14:25:58 -0300121 if (!physid_isset(boot_cpu_physical_apicid, phys_cpu_present_map)) {
122 printk(KERN_NOTICE
123 "weird, boot CPU (#%d) not listed by the BIOS.\n",
124 boot_cpu_physical_apicid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 physid_set(hard_smp_processor_id(), phys_cpu_present_map);
126 }
127
128 /*
129 * If we couldn't find a local APIC, then get out of here now!
130 */
Andi Kleen11a8e772006-01-11 22:46:51 +0100131 if (!cpu_has_apic) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 printk(KERN_ERR "BIOS bug, local APIC #%d not detected!...\n",
Glauber de Oliveira Costac70dcb72008-03-19 14:25:58 -0300133 boot_cpu_physical_apicid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 printk(KERN_ERR "... forcing use of dummy APIC emulation. (tell your hw vendor)\n");
Andi Kleena8ab26f2005-04-16 15:25:19 -0700135 nr_ioapics = 0;
136 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 }
138
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 /*
140 * If SMP should be disabled, then really disable it!
141 */
142 if (!max_cpus) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 printk(KERN_INFO "SMP mode deactivated, forcing use of dummy APIC emulation.\n");
Andi Kleena8ab26f2005-04-16 15:25:19 -0700144 nr_ioapics = 0;
145 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 }
147
Andi Kleena8ab26f2005-04-16 15:25:19 -0700148 return 0;
149}
150
Yinghai Lu949ec322008-01-30 13:30:46 +0100151static void __init smp_cpu_index_default(void)
152{
153 int i;
154 struct cpuinfo_x86 *c;
155
156 for_each_cpu_mask(i, cpu_possible_map) {
157 c = &cpu_data(i);
158 /* mark all to hotplug */
159 c->cpu_index = NR_CPUS;
160 }
161}
162
Mike Travis71fff5e2007-10-19 20:35:03 +0200163/*
Andi Kleena8ab26f2005-04-16 15:25:19 -0700164 * Prepare for SMP bootup. The MP table or ACPI has been read
165 * earlier. Just do some sanity checking here and enable APIC mode.
166 */
Glauber Costa7557da62008-03-03 14:12:38 -0300167void __init native_smp_prepare_cpus(unsigned int max_cpus)
Andi Kleena8ab26f2005-04-16 15:25:19 -0700168{
Andi Kleena8ab26f2005-04-16 15:25:19 -0700169 nmi_watchdog_default();
Yinghai Lu949ec322008-01-30 13:30:46 +0100170 smp_cpu_index_default();
Glauber de Oliveira Costa1db17f52008-03-19 14:26:07 -0300171 cpu_callin_map = cpumask_of_cpu(0);
172 mb();
173
Andi Kleena8ab26f2005-04-16 15:25:19 -0700174 current_cpu_data = boot_cpu_data;
Glauber de Oliveira Costa1db17f52008-03-19 14:26:07 -0300175 boot_cpu_logical_apicid = logical_smp_processor_id();
Andi Kleena8ab26f2005-04-16 15:25:19 -0700176 current_thread_info()->cpu = 0; /* needed? */
Siddha, Suresh B94605ef2005-11-05 17:25:54 +0100177 set_cpu_sibling_map(0);
Andi Kleena8ab26f2005-04-16 15:25:19 -0700178
Andi Kleena8ab26f2005-04-16 15:25:19 -0700179 if (smp_sanity_check(max_cpus) < 0) {
180 printk(KERN_INFO "SMP disabled\n");
181 disable_smp();
182 return;
183 }
184
Glauber de Oliveira Costa1db17f52008-03-19 14:26:07 -0300185 if (GET_APIC_ID(apic_read(APIC_ID)) != boot_cpu_physical_apicid) {
186 panic("Boot APIC ID in local APIC unexpected (%d vs %d)",
187 GET_APIC_ID(apic_read(APIC_ID)), boot_cpu_physical_apicid);
188 /* Or can we switch back to PIC here? */
189 }
Andi Kleena8ab26f2005-04-16 15:25:19 -0700190
191 /*
192 * Switch from PIC to APIC mode.
193 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 setup_local_APIC();
195
Andi Kleen739f33b2008-01-30 13:30:40 +0100196 /*
197 * Enable IO APIC before setting up error vector
198 */
199 if (!skip_ioapic_setup && nr_ioapics)
200 enable_IO_APIC();
201 end_local_APIC_setup();
202
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 /*
Andi Kleena8ab26f2005-04-16 15:25:19 -0700204 * Set up local APIC timer on boot CPU.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206
Glauber de Oliveira Costa746ef0c2008-01-30 13:31:11 +0100207 setup_boot_clock();
Glauber de Oliveira Costa4f3ab192008-03-19 14:25:01 -0300208 printk(KERN_INFO "CPU%d: ", 0);
209 print_cpu_info(&cpu_data(0));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210}