diff options
Diffstat (limited to 'arch/x86/kernel/cpu/common.c')
-rw-r--r-- | arch/x86/kernel/cpu/common.c | 1001 |
1 files changed, 702 insertions, 299 deletions
diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c index 4e456bd955bb..25581dcb280e 100644 --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c | |||
@@ -1,28 +1,62 @@ | |||
1 | #include <linux/init.h> | 1 | #include <linux/init.h> |
2 | #include <linux/kernel.h> | ||
3 | #include <linux/sched.h> | ||
2 | #include <linux/string.h> | 4 | #include <linux/string.h> |
5 | #include <linux/bootmem.h> | ||
6 | #include <linux/bitops.h> | ||
7 | #include <linux/module.h> | ||
8 | #include <linux/kgdb.h> | ||
9 | #include <linux/topology.h> | ||
3 | #include <linux/delay.h> | 10 | #include <linux/delay.h> |
4 | #include <linux/smp.h> | 11 | #include <linux/smp.h> |
5 | #include <linux/module.h> | ||
6 | #include <linux/percpu.h> | 12 | #include <linux/percpu.h> |
7 | #include <linux/bootmem.h> | ||
8 | #include <asm/processor.h> | ||
9 | #include <asm/i387.h> | 13 | #include <asm/i387.h> |
10 | #include <asm/msr.h> | 14 | #include <asm/msr.h> |
11 | #include <asm/io.h> | 15 | #include <asm/io.h> |
16 | #include <asm/linkage.h> | ||
12 | #include <asm/mmu_context.h> | 17 | #include <asm/mmu_context.h> |
13 | #include <asm/mtrr.h> | 18 | #include <asm/mtrr.h> |
14 | #include <asm/mce.h> | 19 | #include <asm/mce.h> |
15 | #include <asm/pat.h> | 20 | #include <asm/pat.h> |
16 | #include <asm/asm.h> | 21 | #include <asm/asm.h> |
22 | #include <asm/numa.h> | ||
17 | #ifdef CONFIG_X86_LOCAL_APIC | 23 | #ifdef CONFIG_X86_LOCAL_APIC |
18 | #include <asm/mpspec.h> | 24 | #include <asm/mpspec.h> |
19 | #include <asm/apic.h> | 25 | #include <asm/apic.h> |
20 | #include <mach_apic.h> | 26 | #include <mach_apic.h> |
27 | #include <asm/genapic.h> | ||
21 | #endif | 28 | #endif |
22 | 29 | ||
30 | #include <asm/pda.h> | ||
31 | #include <asm/pgtable.h> | ||
32 | #include <asm/processor.h> | ||
33 | #include <asm/desc.h> | ||
34 | #include <asm/atomic.h> | ||
35 | #include <asm/proto.h> | ||
36 | #include <asm/sections.h> | ||
37 | #include <asm/setup.h> | ||
38 | |||
23 | #include "cpu.h" | 39 | #include "cpu.h" |
24 | 40 | ||
41 | static struct cpu_dev *this_cpu __cpuinitdata; | ||
42 | |||
43 | #ifdef CONFIG_X86_64 | ||
44 | /* We need valid kernel segments for data and code in long mode too | ||
45 | * IRET will check the segment types kkeil 2000/10/28 | ||
46 | * Also sysret mandates a special GDT layout | ||
47 | */ | ||
48 | /* The TLS descriptors are currently at a different place compared to i386. | ||
49 | Hopefully nobody expects them at a fixed place (Wine?) */ | ||
25 | DEFINE_PER_CPU(struct gdt_page, gdt_page) = { .gdt = { | 50 | DEFINE_PER_CPU(struct gdt_page, gdt_page) = { .gdt = { |
51 | [GDT_ENTRY_KERNEL32_CS] = { { { 0x0000ffff, 0x00cf9b00 } } }, | ||
52 | [GDT_ENTRY_KERNEL_CS] = { { { 0x0000ffff, 0x00af9b00 } } }, | ||
53 | [GDT_ENTRY_KERNEL_DS] = { { { 0x0000ffff, 0x00cf9300 } } }, | ||
54 | [GDT_ENTRY_DEFAULT_USER32_CS] = { { { 0x0000ffff, 0x00cffb00 } } }, | ||
55 | [GDT_ENTRY_DEFAULT_USER_DS] = { { { 0x0000ffff, 0x00cff300 } } }, | ||
56 | [GDT_ENTRY_DEFAULT_USER_CS] = { { { 0x0000ffff, 0x00affb00 } } }, | ||
57 | } }; | ||
58 | #else | ||
59 | DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = { | ||
26 | [GDT_ENTRY_KERNEL_CS] = { { { 0x0000ffff, 0x00cf9a00 } } }, | 60 | [GDT_ENTRY_KERNEL_CS] = { { { 0x0000ffff, 0x00cf9a00 } } }, |
27 | [GDT_ENTRY_KERNEL_DS] = { { { 0x0000ffff, 0x00cf9200 } } }, | 61 | [GDT_ENTRY_KERNEL_DS] = { { { 0x0000ffff, 0x00cf9200 } } }, |
28 | [GDT_ENTRY_DEFAULT_USER_CS] = { { { 0x0000ffff, 0x00cffa00 } } }, | 62 | [GDT_ENTRY_DEFAULT_USER_CS] = { { { 0x0000ffff, 0x00cffa00 } } }, |
@@ -56,17 +90,157 @@ DEFINE_PER_CPU(struct gdt_page, gdt_page) = { .gdt = { | |||
56 | [GDT_ENTRY_ESPFIX_SS] = { { { 0x00000000, 0x00c09200 } } }, | 90 | [GDT_ENTRY_ESPFIX_SS] = { { { 0x00000000, 0x00c09200 } } }, |
57 | [GDT_ENTRY_PERCPU] = { { { 0x00000000, 0x00000000 } } }, | 91 | [GDT_ENTRY_PERCPU] = { { { 0x00000000, 0x00000000 } } }, |
58 | } }; | 92 | } }; |
93 | #endif | ||
59 | EXPORT_PER_CPU_SYMBOL_GPL(gdt_page); | 94 | EXPORT_PER_CPU_SYMBOL_GPL(gdt_page); |
60 | 95 | ||
61 | __u32 cleared_cpu_caps[NCAPINTS] __cpuinitdata; | 96 | #ifdef CONFIG_X86_32 |
62 | |||
63 | static int cachesize_override __cpuinitdata = -1; | 97 | static int cachesize_override __cpuinitdata = -1; |
64 | static int disable_x86_serial_nr __cpuinitdata = 1; | 98 | static int disable_x86_serial_nr __cpuinitdata = 1; |
65 | 99 | ||
66 | struct cpu_dev *cpu_devs[X86_VENDOR_NUM] = {}; | 100 | static int __init cachesize_setup(char *str) |
101 | { | ||
102 | get_option(&str, &cachesize_override); | ||
103 | return 1; | ||
104 | } | ||
105 | __setup("cachesize=", cachesize_setup); | ||
106 | |||
107 | static int __init x86_fxsr_setup(char *s) | ||
108 | { | ||
109 | setup_clear_cpu_cap(X86_FEATURE_FXSR); | ||
110 | setup_clear_cpu_cap(X86_FEATURE_XMM); | ||
111 | return 1; | ||
112 | } | ||
113 | __setup("nofxsr", x86_fxsr_setup); | ||
114 | |||
115 | static int __init x86_sep_setup(char *s) | ||
116 | { | ||
117 | setup_clear_cpu_cap(X86_FEATURE_SEP); | ||
118 | return 1; | ||
119 | } | ||
120 | __setup("nosep", x86_sep_setup); | ||
121 | |||
122 | /* Standard macro to see if a specific flag is changeable */ | ||
123 | static inline int flag_is_changeable_p(u32 flag) | ||
124 | { | ||
125 | u32 f1, f2; | ||
126 | |||
127 | /* | ||
128 | * Cyrix and IDT cpus allow disabling of CPUID | ||
129 | * so the code below may return different results | ||
130 | * when it is executed before and after enabling | ||
131 | * the CPUID. Add "volatile" to not allow gcc to | ||
132 | * optimize the subsequent calls to this function. | ||
133 | */ | ||
134 | asm volatile ("pushfl\n\t" | ||
135 | "pushfl\n\t" | ||
136 | "popl %0\n\t" | ||
137 | "movl %0,%1\n\t" | ||
138 | "xorl %2,%0\n\t" | ||
139 | "pushl %0\n\t" | ||
140 | "popfl\n\t" | ||
141 | "pushfl\n\t" | ||
142 | "popl %0\n\t" | ||
143 | "popfl\n\t" | ||
144 | : "=&r" (f1), "=&r" (f2) | ||
145 | : "ir" (flag)); | ||
146 | |||
147 | return ((f1^f2) & flag) != 0; | ||
148 | } | ||
149 | |||
150 | /* Probe for the CPUID instruction */ | ||
151 | static int __cpuinit have_cpuid_p(void) | ||
152 | { | ||
153 | return flag_is_changeable_p(X86_EFLAGS_ID); | ||
154 | } | ||
155 | |||
156 | static void __cpuinit squash_the_stupid_serial_number(struct cpuinfo_x86 *c) | ||
157 | { | ||
158 | if (cpu_has(c, X86_FEATURE_PN) && disable_x86_serial_nr) { | ||
159 | /* Disable processor serial number */ | ||
160 | unsigned long lo, hi; | ||
161 | rdmsr(MSR_IA32_BBL_CR_CTL, lo, hi); | ||
162 | lo |= 0x200000; | ||
163 | wrmsr(MSR_IA32_BBL_CR_CTL, lo, hi); | ||
164 | printk(KERN_NOTICE "CPU serial number disabled.\n"); | ||
165 | clear_cpu_cap(c, X86_FEATURE_PN); | ||
166 | |||
167 | /* Disabling the serial number may affect the cpuid level */ | ||
168 | c->cpuid_level = cpuid_eax(0); | ||
169 | } | ||
170 | } | ||
171 | |||
172 | static int __init x86_serial_nr_setup(char *s) | ||
173 | { | ||
174 | disable_x86_serial_nr = 0; | ||
175 | return 1; | ||
176 | } | ||
177 | __setup("serialnumber", x86_serial_nr_setup); | ||
178 | #else | ||
179 | static inline int flag_is_changeable_p(u32 flag) | ||
180 | { | ||
181 | return 1; | ||
182 | } | ||
183 | /* Probe for the CPUID instruction */ | ||
184 | static inline int have_cpuid_p(void) | ||
185 | { | ||
186 | return 1; | ||
187 | } | ||
188 | static inline void squash_the_stupid_serial_number(struct cpuinfo_x86 *c) | ||
189 | { | ||
190 | } | ||
191 | #endif | ||
192 | |||
193 | /* | ||
194 | * Naming convention should be: <Name> [(<Codename>)] | ||
195 | * This table only is used unless init_<vendor>() below doesn't set it; | ||
196 | * in particular, if CPUID levels 0x80000002..4 are supported, this isn't used | ||
197 | * | ||
198 | */ | ||
199 | |||
200 | /* Look up CPU names by table lookup. */ | ||
201 | static char __cpuinit *table_lookup_model(struct cpuinfo_x86 *c) | ||
202 | { | ||
203 | struct cpu_model_info *info; | ||
204 | |||
205 | if (c->x86_model >= 16) | ||
206 | return NULL; /* Range check */ | ||
207 | |||
208 | if (!this_cpu) | ||
209 | return NULL; | ||
210 | |||
211 | info = this_cpu->c_models; | ||
212 | |||
213 | while (info && info->family) { | ||
214 | if (info->family == c->x86) | ||
215 | return info->model_names[c->x86_model]; | ||
216 | info++; | ||
217 | } | ||
218 | return NULL; /* Not found */ | ||
219 | } | ||
220 | |||
221 | __u32 cleared_cpu_caps[NCAPINTS] __cpuinitdata; | ||
222 | |||
223 | /* Current gdt points %fs at the "master" per-cpu area: after this, | ||
224 | * it's on the real one. */ | ||
225 | void switch_to_new_gdt(void) | ||
226 | { | ||
227 | struct desc_ptr gdt_descr; | ||
228 | |||
229 | gdt_descr.address = (long)get_cpu_gdt_table(smp_processor_id()); | ||
230 | gdt_descr.size = GDT_SIZE - 1; | ||
231 | load_gdt(&gdt_descr); | ||
232 | #ifdef CONFIG_X86_32 | ||
233 | asm("mov %0, %%fs" : : "r" (__KERNEL_PERCPU) : "memory"); | ||
234 | #endif | ||
235 | } | ||
236 | |||
237 | static struct cpu_dev *cpu_devs[X86_VENDOR_NUM] = {}; | ||
67 | 238 | ||
68 | static void __cpuinit default_init(struct cpuinfo_x86 *c) | 239 | static void __cpuinit default_init(struct cpuinfo_x86 *c) |
69 | { | 240 | { |
241 | #ifdef CONFIG_X86_64 | ||
242 | display_cacheinfo(c); | ||
243 | #else | ||
70 | /* Not much we can do here... */ | 244 | /* Not much we can do here... */ |
71 | /* Check if at least it has cpuid */ | 245 | /* Check if at least it has cpuid */ |
72 | if (c->cpuid_level == -1) { | 246 | if (c->cpuid_level == -1) { |
@@ -76,28 +250,22 @@ static void __cpuinit default_init(struct cpuinfo_x86 *c) | |||
76 | else if (c->x86 == 3) | 250 | else if (c->x86 == 3) |
77 | strcpy(c->x86_model_id, "386"); | 251 | strcpy(c->x86_model_id, "386"); |
78 | } | 252 | } |
253 | #endif | ||
79 | } | 254 | } |
80 | 255 | ||
81 | static struct cpu_dev __cpuinitdata default_cpu = { | 256 | static struct cpu_dev __cpuinitdata default_cpu = { |
82 | .c_init = default_init, | 257 | .c_init = default_init, |
83 | .c_vendor = "Unknown", | 258 | .c_vendor = "Unknown", |
259 | .c_x86_vendor = X86_VENDOR_UNKNOWN, | ||
84 | }; | 260 | }; |
85 | static struct cpu_dev *this_cpu __cpuinitdata = &default_cpu; | ||
86 | |||
87 | static int __init cachesize_setup(char *str) | ||
88 | { | ||
89 | get_option(&str, &cachesize_override); | ||
90 | return 1; | ||
91 | } | ||
92 | __setup("cachesize=", cachesize_setup); | ||
93 | 261 | ||
94 | int __cpuinit get_model_name(struct cpuinfo_x86 *c) | 262 | static void __cpuinit get_model_name(struct cpuinfo_x86 *c) |
95 | { | 263 | { |
96 | unsigned int *v; | 264 | unsigned int *v; |
97 | char *p, *q; | 265 | char *p, *q; |
98 | 266 | ||
99 | if (cpuid_eax(0x80000000) < 0x80000004) | 267 | if (c->extended_cpuid_level < 0x80000004) |
100 | return 0; | 268 | return; |
101 | 269 | ||
102 | v = (unsigned int *) c->x86_model_id; | 270 | v = (unsigned int *) c->x86_model_id; |
103 | cpuid(0x80000002, &v[0], &v[1], &v[2], &v[3]); | 271 | cpuid(0x80000002, &v[0], &v[1], &v[2], &v[3]); |
@@ -116,30 +284,34 @@ int __cpuinit get_model_name(struct cpuinfo_x86 *c) | |||
116 | while (q <= &c->x86_model_id[48]) | 284 | while (q <= &c->x86_model_id[48]) |
117 | *q++ = '\0'; /* Zero-pad the rest */ | 285 | *q++ = '\0'; /* Zero-pad the rest */ |
118 | } | 286 | } |
119 | |||
120 | return 1; | ||
121 | } | 287 | } |
122 | 288 | ||
123 | |||
124 | void __cpuinit display_cacheinfo(struct cpuinfo_x86 *c) | 289 | void __cpuinit display_cacheinfo(struct cpuinfo_x86 *c) |
125 | { | 290 | { |
126 | unsigned int n, dummy, ecx, edx, l2size; | 291 | unsigned int n, dummy, ebx, ecx, edx, l2size; |
127 | 292 | ||
128 | n = cpuid_eax(0x80000000); | 293 | n = c->extended_cpuid_level; |
129 | 294 | ||
130 | if (n >= 0x80000005) { | 295 | if (n >= 0x80000005) { |
131 | cpuid(0x80000005, &dummy, &dummy, &ecx, &edx); | 296 | cpuid(0x80000005, &dummy, &ebx, &ecx, &edx); |
132 | printk(KERN_INFO "CPU: L1 I Cache: %dK (%d bytes/line), D cache %dK (%d bytes/line)\n", | 297 | printk(KERN_INFO "CPU: L1 I Cache: %dK (%d bytes/line), D cache %dK (%d bytes/line)\n", |
133 | edx>>24, edx&0xFF, ecx>>24, ecx&0xFF); | 298 | edx>>24, edx&0xFF, ecx>>24, ecx&0xFF); |
134 | c->x86_cache_size = (ecx>>24)+(edx>>24); | 299 | c->x86_cache_size = (ecx>>24) + (edx>>24); |
300 | #ifdef CONFIG_X86_64 | ||
301 | /* On K8 L1 TLB is inclusive, so don't count it */ | ||
302 | c->x86_tlbsize = 0; | ||
303 | #endif | ||
135 | } | 304 | } |
136 | 305 | ||
137 | if (n < 0x80000006) /* Some chips just has a large L1. */ | 306 | if (n < 0x80000006) /* Some chips just has a large L1. */ |
138 | return; | 307 | return; |
139 | 308 | ||
140 | ecx = cpuid_ecx(0x80000006); | 309 | cpuid(0x80000006, &dummy, &ebx, &ecx, &edx); |
141 | l2size = ecx >> 16; | 310 | l2size = ecx >> 16; |
142 | 311 | ||
312 | #ifdef CONFIG_X86_64 | ||
313 | c->x86_tlbsize += ((ebx >> 16) & 0xfff) + (ebx & 0xfff); | ||
314 | #else | ||
143 | /* do processor-specific cache resizing */ | 315 | /* do processor-specific cache resizing */ |
144 | if (this_cpu->c_size_cache) | 316 | if (this_cpu->c_size_cache) |
145 | l2size = this_cpu->c_size_cache(c, l2size); | 317 | l2size = this_cpu->c_size_cache(c, l2size); |
@@ -150,116 +322,106 @@ void __cpuinit display_cacheinfo(struct cpuinfo_x86 *c) | |||
150 | 322 | ||
151 | if (l2size == 0) | 323 | if (l2size == 0) |
152 | return; /* Again, no L2 cache is possible */ | 324 | return; /* Again, no L2 cache is possible */ |
325 | #endif | ||
153 | 326 | ||
154 | c->x86_cache_size = l2size; | 327 | c->x86_cache_size = l2size; |
155 | 328 | ||
156 | printk(KERN_INFO "CPU: L2 Cache: %dK (%d bytes/line)\n", | 329 | printk(KERN_INFO "CPU: L2 Cache: %dK (%d bytes/line)\n", |
157 | l2size, ecx & 0xFF); | 330 | l2size, ecx & 0xFF); |
158 | } | 331 | } |
159 | 332 | ||
160 | /* | 333 | void __cpuinit detect_ht(struct cpuinfo_x86 *c) |
161 | * Naming convention should be: <Name> [(<Codename>)] | ||
162 | * This table only is used unless init_<vendor>() below doesn't set it; | ||
163 | * in particular, if CPUID levels 0x80000002..4 are supported, this isn't used | ||
164 | * | ||
165 | */ | ||
166 | |||
167 | /* Look up CPU names by table lookup. */ | ||
168 | static char __cpuinit *table_lookup_model(struct cpuinfo_x86 *c) | ||
169 | { | 334 | { |
170 | struct cpu_model_info *info; | 335 | #ifdef CONFIG_X86_HT |
336 | u32 eax, ebx, ecx, edx; | ||
337 | int index_msb, core_bits; | ||
171 | 338 | ||
172 | if (c->x86_model >= 16) | 339 | if (!cpu_has(c, X86_FEATURE_HT)) |
173 | return NULL; /* Range check */ | 340 | return; |
174 | 341 | ||
175 | if (!this_cpu) | 342 | if (cpu_has(c, X86_FEATURE_CMP_LEGACY)) |
176 | return NULL; | 343 | goto out; |
177 | 344 | ||
178 | info = this_cpu->c_models; | 345 | if (cpu_has(c, X86_FEATURE_XTOPOLOGY)) |
346 | return; | ||
179 | 347 | ||
180 | while (info && info->family) { | 348 | cpuid(1, &eax, &ebx, &ecx, &edx); |
181 | if (info->family == c->x86) | 349 | |
182 | return info->model_names[c->x86_model]; | 350 | smp_num_siblings = (ebx & 0xff0000) >> 16; |
183 | info++; | 351 | |
352 | if (smp_num_siblings == 1) { | ||
353 | printk(KERN_INFO "CPU: Hyper-Threading is disabled\n"); | ||
354 | } else if (smp_num_siblings > 1) { | ||
355 | |||
356 | if (smp_num_siblings > NR_CPUS) { | ||
357 | printk(KERN_WARNING "CPU: Unsupported number of siblings %d", | ||
358 | smp_num_siblings); | ||
359 | smp_num_siblings = 1; | ||
360 | return; | ||
361 | } | ||
362 | |||
363 | index_msb = get_count_order(smp_num_siblings); | ||
364 | #ifdef CONFIG_X86_64 | ||
365 | c->phys_proc_id = phys_pkg_id(index_msb); | ||
366 | #else | ||
367 | c->phys_proc_id = phys_pkg_id(c->initial_apicid, index_msb); | ||
368 | #endif | ||
369 | |||
370 | smp_num_siblings = smp_num_siblings / c->x86_max_cores; | ||
371 | |||
372 | index_msb = get_count_order(smp_num_siblings); | ||
373 | |||
374 | core_bits = get_count_order(c->x86_max_cores); | ||
375 | |||
376 | #ifdef CONFIG_X86_64 | ||
377 | c->cpu_core_id = phys_pkg_id(index_msb) & | ||
378 | ((1 << core_bits) - 1); | ||
379 | #else | ||
380 | c->cpu_core_id = phys_pkg_id(c->initial_apicid, index_msb) & | ||
381 | ((1 << core_bits) - 1); | ||
382 | #endif | ||
184 | } | 383 | } |
185 | return NULL; /* Not found */ | ||
186 | } | ||
187 | 384 | ||
385 | out: | ||
386 | if ((c->x86_max_cores * smp_num_siblings) > 1) { | ||
387 | printk(KERN_INFO "CPU: Physical Processor ID: %d\n", | ||
388 | c->phys_proc_id); | ||
389 | printk(KERN_INFO "CPU: Processor Core ID: %d\n", | ||
390 | c->cpu_core_id); | ||
391 | } | ||
392 | #endif | ||
393 | } | ||
188 | 394 | ||
189 | static void __cpuinit get_cpu_vendor(struct cpuinfo_x86 *c, int early) | 395 | static void __cpuinit get_cpu_vendor(struct cpuinfo_x86 *c) |
190 | { | 396 | { |
191 | char *v = c->x86_vendor_id; | 397 | char *v = c->x86_vendor_id; |
192 | int i; | 398 | int i; |
193 | static int printed; | 399 | static int printed; |
194 | 400 | ||
195 | for (i = 0; i < X86_VENDOR_NUM; i++) { | 401 | for (i = 0; i < X86_VENDOR_NUM; i++) { |
196 | if (cpu_devs[i]) { | 402 | if (!cpu_devs[i]) |
197 | if (!strcmp(v, cpu_devs[i]->c_ident[0]) || | 403 | break; |
198 | (cpu_devs[i]->c_ident[1] && | 404 | |
199 | !strcmp(v, cpu_devs[i]->c_ident[1]))) { | 405 | if (!strcmp(v, cpu_devs[i]->c_ident[0]) || |
200 | c->x86_vendor = i; | 406 | (cpu_devs[i]->c_ident[1] && |
201 | if (!early) | 407 | !strcmp(v, cpu_devs[i]->c_ident[1]))) { |
202 | this_cpu = cpu_devs[i]; | 408 | this_cpu = cpu_devs[i]; |
203 | return; | 409 | c->x86_vendor = this_cpu->c_x86_vendor; |
204 | } | 410 | return; |
205 | } | 411 | } |
206 | } | 412 | } |
413 | |||
207 | if (!printed) { | 414 | if (!printed) { |
208 | printed++; | 415 | printed++; |
209 | printk(KERN_ERR "CPU: Vendor unknown, using generic init.\n"); | 416 | printk(KERN_ERR "CPU: vendor_id '%s' unknown, using generic init.\n", v); |
210 | printk(KERN_ERR "CPU: Your system may be unstable.\n"); | 417 | printk(KERN_ERR "CPU: Your system may be unstable.\n"); |
211 | } | 418 | } |
419 | |||
212 | c->x86_vendor = X86_VENDOR_UNKNOWN; | 420 | c->x86_vendor = X86_VENDOR_UNKNOWN; |
213 | this_cpu = &default_cpu; | 421 | this_cpu = &default_cpu; |
214 | } | 422 | } |
215 | 423 | ||
216 | 424 | void __cpuinit cpu_detect(struct cpuinfo_x86 *c) | |
217 | static int __init x86_fxsr_setup(char *s) | ||
218 | { | ||
219 | setup_clear_cpu_cap(X86_FEATURE_FXSR); | ||
220 | setup_clear_cpu_cap(X86_FEATURE_XMM); | ||
221 | return 1; | ||
222 | } | ||
223 | __setup("nofxsr", x86_fxsr_setup); | ||
224 | |||
225 | |||
226 | static int __init x86_sep_setup(char *s) | ||
227 | { | ||
228 | setup_clear_cpu_cap(X86_FEATURE_SEP); | ||
229 | return 1; | ||
230 | } | ||
231 | __setup("nosep", x86_sep_setup); | ||
232 | |||
233 | |||
234 | /* Standard macro to see if a specific flag is changeable */ | ||
235 | static inline int flag_is_changeable_p(u32 flag) | ||
236 | { | ||
237 | u32 f1, f2; | ||
238 | |||
239 | asm("pushfl\n\t" | ||
240 | "pushfl\n\t" | ||
241 | "popl %0\n\t" | ||
242 | "movl %0,%1\n\t" | ||
243 | "xorl %2,%0\n\t" | ||
244 | "pushl %0\n\t" | ||
245 | "popfl\n\t" | ||
246 | "pushfl\n\t" | ||
247 | "popl %0\n\t" | ||
248 | "popfl\n\t" | ||
249 | : "=&r" (f1), "=&r" (f2) | ||
250 | : "ir" (flag)); | ||
251 | |||
252 | return ((f1^f2) & flag) != 0; | ||
253 | } | ||
254 | |||
255 | |||
256 | /* Probe for the CPUID instruction */ | ||
257 | static int __cpuinit have_cpuid_p(void) | ||
258 | { | ||
259 | return flag_is_changeable_p(X86_EFLAGS_ID); | ||
260 | } | ||
261 | |||
262 | void __init cpu_detect(struct cpuinfo_x86 *c) | ||
263 | { | 425 | { |
264 | /* Get vendor name */ | 426 | /* Get vendor name */ |
265 | cpuid(0x00000000, (unsigned int *)&c->cpuid_level, | 427 | cpuid(0x00000000, (unsigned int *)&c->cpuid_level, |
@@ -268,50 +430,87 @@ void __init cpu_detect(struct cpuinfo_x86 *c) | |||
268 | (unsigned int *)&c->x86_vendor_id[4]); | 430 | (unsigned int *)&c->x86_vendor_id[4]); |
269 | 431 | ||
270 | c->x86 = 4; | 432 | c->x86 = 4; |
433 | /* Intel-defined flags: level 0x00000001 */ | ||
271 | if (c->cpuid_level >= 0x00000001) { | 434 | if (c->cpuid_level >= 0x00000001) { |
272 | u32 junk, tfms, cap0, misc; | 435 | u32 junk, tfms, cap0, misc; |
273 | cpuid(0x00000001, &tfms, &misc, &junk, &cap0); | 436 | cpuid(0x00000001, &tfms, &misc, &junk, &cap0); |
274 | c->x86 = (tfms >> 8) & 15; | 437 | c->x86 = (tfms >> 8) & 0xf; |
275 | c->x86_model = (tfms >> 4) & 15; | 438 | c->x86_model = (tfms >> 4) & 0xf; |
439 | c->x86_mask = tfms & 0xf; | ||
276 | if (c->x86 == 0xf) | 440 | if (c->x86 == 0xf) |
277 | c->x86 += (tfms >> 20) & 0xff; | 441 | c->x86 += (tfms >> 20) & 0xff; |
278 | if (c->x86 >= 0x6) | 442 | if (c->x86 >= 0x6) |
279 | c->x86_model += ((tfms >> 16) & 0xF) << 4; | 443 | c->x86_model += ((tfms >> 16) & 0xf) << 4; |
280 | c->x86_mask = tfms & 15; | ||
281 | if (cap0 & (1<<19)) { | 444 | if (cap0 & (1<<19)) { |
282 | c->x86_cache_alignment = ((misc >> 8) & 0xff) * 8; | ||
283 | c->x86_clflush_size = ((misc >> 8) & 0xff) * 8; | 445 | c->x86_clflush_size = ((misc >> 8) & 0xff) * 8; |
446 | c->x86_cache_alignment = c->x86_clflush_size; | ||
284 | } | 447 | } |
285 | } | 448 | } |
286 | } | 449 | } |
287 | static void __cpuinit early_get_cap(struct cpuinfo_x86 *c) | 450 | |
451 | static void __cpuinit get_cpu_cap(struct cpuinfo_x86 *c) | ||
288 | { | 452 | { |
289 | u32 tfms, xlvl; | 453 | u32 tfms, xlvl; |
290 | unsigned int ebx; | 454 | u32 ebx; |
291 | 455 | ||
292 | memset(&c->x86_capability, 0, sizeof c->x86_capability); | 456 | /* Intel-defined flags: level 0x00000001 */ |
293 | if (have_cpuid_p()) { | 457 | if (c->cpuid_level >= 0x00000001) { |
294 | /* Intel-defined flags: level 0x00000001 */ | 458 | u32 capability, excap; |
295 | if (c->cpuid_level >= 0x00000001) { | 459 | cpuid(0x00000001, &tfms, &ebx, &excap, &capability); |
296 | u32 capability, excap; | 460 | c->x86_capability[0] = capability; |
297 | cpuid(0x00000001, &tfms, &ebx, &excap, &capability); | 461 | c->x86_capability[4] = excap; |
298 | c->x86_capability[0] = capability; | 462 | } |
299 | c->x86_capability[4] = excap; | ||
300 | } | ||
301 | 463 | ||
302 | /* AMD-defined flags: level 0x80000001 */ | 464 | /* AMD-defined flags: level 0x80000001 */ |
303 | xlvl = cpuid_eax(0x80000000); | 465 | xlvl = cpuid_eax(0x80000000); |
304 | if ((xlvl & 0xffff0000) == 0x80000000) { | 466 | c->extended_cpuid_level = xlvl; |
305 | if (xlvl >= 0x80000001) { | 467 | if ((xlvl & 0xffff0000) == 0x80000000) { |
306 | c->x86_capability[1] = cpuid_edx(0x80000001); | 468 | if (xlvl >= 0x80000001) { |
307 | c->x86_capability[6] = cpuid_ecx(0x80000001); | 469 | c->x86_capability[1] = cpuid_edx(0x80000001); |
308 | } | 470 | c->x86_capability[6] = cpuid_ecx(0x80000001); |
309 | } | 471 | } |
472 | } | ||
473 | |||
474 | #ifdef CONFIG_X86_64 | ||
475 | if (c->extended_cpuid_level >= 0x80000008) { | ||
476 | u32 eax = cpuid_eax(0x80000008); | ||
310 | 477 | ||
478 | c->x86_virt_bits = (eax >> 8) & 0xff; | ||
479 | c->x86_phys_bits = eax & 0xff; | ||
311 | } | 480 | } |
481 | #endif | ||
482 | |||
483 | if (c->extended_cpuid_level >= 0x80000007) | ||
484 | c->x86_power = cpuid_edx(0x80000007); | ||
312 | 485 | ||
313 | } | 486 | } |
314 | 487 | ||
488 | static void __cpuinit identify_cpu_without_cpuid(struct cpuinfo_x86 *c) | ||
489 | { | ||
490 | #ifdef CONFIG_X86_32 | ||
491 | int i; | ||
492 | |||
493 | /* | ||
494 | * First of all, decide if this is a 486 or higher | ||
495 | * It's a 486 if we can modify the AC flag | ||
496 | */ | ||
497 | if (flag_is_changeable_p(X86_EFLAGS_AC)) | ||
498 | c->x86 = 4; | ||
499 | else | ||
500 | c->x86 = 3; | ||
501 | |||
502 | for (i = 0; i < X86_VENDOR_NUM; i++) | ||
503 | if (cpu_devs[i] && cpu_devs[i]->c_identify) { | ||
504 | c->x86_vendor_id[0] = 0; | ||
505 | cpu_devs[i]->c_identify(c); | ||
506 | if (c->x86_vendor_id[0]) { | ||
507 | get_cpu_vendor(c); | ||
508 | break; | ||
509 | } | ||
510 | } | ||
511 | #endif | ||
512 | } | ||
513 | |||
315 | /* | 514 | /* |
316 | * Do minimum CPU detection early. | 515 | * Do minimum CPU detection early. |
317 | * Fields really needed: vendor, cpuid_level, family, model, mask, | 516 | * Fields really needed: vendor, cpuid_level, family, model, mask, |
@@ -321,25 +520,61 @@ static void __cpuinit early_get_cap(struct cpuinfo_x86 *c) | |||
321 | * WARNING: this function is only called on the BP. Don't add code here | 520 | * WARNING: this function is only called on the BP. Don't add code here |
322 | * that is supposed to run on all CPUs. | 521 | * that is supposed to run on all CPUs. |
323 | */ | 522 | */ |
324 | static void __init early_cpu_detect(void) | 523 | static void __init early_identify_cpu(struct cpuinfo_x86 *c) |
325 | { | 524 | { |
326 | struct cpuinfo_x86 *c = &boot_cpu_data; | 525 | #ifdef CONFIG_X86_64 |
327 | 526 | c->x86_clflush_size = 64; | |
328 | c->x86_cache_alignment = 32; | 527 | #else |
329 | c->x86_clflush_size = 32; | 528 | c->x86_clflush_size = 32; |
529 | #endif | ||
530 | c->x86_cache_alignment = c->x86_clflush_size; | ||
531 | |||
532 | memset(&c->x86_capability, 0, sizeof c->x86_capability); | ||
533 | c->extended_cpuid_level = 0; | ||
534 | |||
535 | if (!have_cpuid_p()) | ||
536 | identify_cpu_without_cpuid(c); | ||
330 | 537 | ||
538 | /* cyrix could have cpuid enabled via c_identify()*/ | ||
331 | if (!have_cpuid_p()) | 539 | if (!have_cpuid_p()) |
332 | return; | 540 | return; |
333 | 541 | ||
334 | cpu_detect(c); | 542 | cpu_detect(c); |
335 | 543 | ||
336 | get_cpu_vendor(c, 1); | 544 | get_cpu_vendor(c); |
545 | |||
546 | get_cpu_cap(c); | ||
337 | 547 | ||
338 | early_get_cap(c); | 548 | if (this_cpu->c_early_init) |
549 | this_cpu->c_early_init(c); | ||
339 | 550 | ||
340 | if (c->x86_vendor != X86_VENDOR_UNKNOWN && | 551 | validate_pat_support(c); |
341 | cpu_devs[c->x86_vendor]->c_early_init) | 552 | } |
342 | cpu_devs[c->x86_vendor]->c_early_init(c); | 553 | |
554 | void __init early_cpu_init(void) | ||
555 | { | ||
556 | struct cpu_dev **cdev; | ||
557 | int count = 0; | ||
558 | |||
559 | printk("KERNEL supported cpus:\n"); | ||
560 | for (cdev = __x86_cpu_dev_start; cdev < __x86_cpu_dev_end; cdev++) { | ||
561 | struct cpu_dev *cpudev = *cdev; | ||
562 | unsigned int j; | ||
563 | |||
564 | if (count >= X86_VENDOR_NUM) | ||
565 | break; | ||
566 | cpu_devs[count] = cpudev; | ||
567 | count++; | ||
568 | |||
569 | for (j = 0; j < 2; j++) { | ||
570 | if (!cpudev->c_ident[j]) | ||
571 | continue; | ||
572 | printk(" %s %s\n", cpudev->c_vendor, | ||
573 | cpudev->c_ident[j]); | ||
574 | } | ||
575 | } | ||
576 | |||
577 | early_identify_cpu(&boot_cpu_data); | ||
343 | } | 578 | } |
344 | 579 | ||
345 | /* | 580 | /* |
@@ -357,86 +592,41 @@ static void __cpuinit detect_nopl(struct cpuinfo_x86 *c) | |||
357 | 592 | ||
358 | static void __cpuinit generic_identify(struct cpuinfo_x86 *c) | 593 | static void __cpuinit generic_identify(struct cpuinfo_x86 *c) |
359 | { | 594 | { |
360 | u32 tfms, xlvl; | 595 | c->extended_cpuid_level = 0; |
361 | unsigned int ebx; | ||
362 | |||
363 | if (have_cpuid_p()) { | ||
364 | /* Get vendor name */ | ||
365 | cpuid(0x00000000, (unsigned int *)&c->cpuid_level, | ||
366 | (unsigned int *)&c->x86_vendor_id[0], | ||
367 | (unsigned int *)&c->x86_vendor_id[8], | ||
368 | (unsigned int *)&c->x86_vendor_id[4]); | ||
369 | |||
370 | get_cpu_vendor(c, 0); | ||
371 | /* Initialize the standard set of capabilities */ | ||
372 | /* Note that the vendor-specific code below might override */ | ||
373 | /* Intel-defined flags: level 0x00000001 */ | ||
374 | if (c->cpuid_level >= 0x00000001) { | ||
375 | u32 capability, excap; | ||
376 | cpuid(0x00000001, &tfms, &ebx, &excap, &capability); | ||
377 | c->x86_capability[0] = capability; | ||
378 | c->x86_capability[4] = excap; | ||
379 | c->x86 = (tfms >> 8) & 15; | ||
380 | c->x86_model = (tfms >> 4) & 15; | ||
381 | if (c->x86 == 0xf) | ||
382 | c->x86 += (tfms >> 20) & 0xff; | ||
383 | if (c->x86 >= 0x6) | ||
384 | c->x86_model += ((tfms >> 16) & 0xF) << 4; | ||
385 | c->x86_mask = tfms & 15; | ||
386 | c->initial_apicid = (ebx >> 24) & 0xFF; | ||
387 | #ifdef CONFIG_X86_HT | ||
388 | c->apicid = phys_pkg_id(c->initial_apicid, 0); | ||
389 | c->phys_proc_id = c->initial_apicid; | ||
390 | #else | ||
391 | c->apicid = c->initial_apicid; | ||
392 | #endif | ||
393 | if (test_cpu_cap(c, X86_FEATURE_CLFLSH)) | ||
394 | c->x86_clflush_size = ((ebx >> 8) & 0xff) * 8; | ||
395 | } else { | ||
396 | /* Have CPUID level 0 only - unheard of */ | ||
397 | c->x86 = 4; | ||
398 | } | ||
399 | 596 | ||
400 | /* AMD-defined flags: level 0x80000001 */ | 597 | if (!have_cpuid_p()) |
401 | xlvl = cpuid_eax(0x80000000); | 598 | identify_cpu_without_cpuid(c); |
402 | if ((xlvl & 0xffff0000) == 0x80000000) { | ||
403 | if (xlvl >= 0x80000001) { | ||
404 | c->x86_capability[1] = cpuid_edx(0x80000001); | ||
405 | c->x86_capability[6] = cpuid_ecx(0x80000001); | ||
406 | } | ||
407 | if (xlvl >= 0x80000004) | ||
408 | get_model_name(c); /* Default name */ | ||
409 | } | ||
410 | 599 | ||
411 | init_scattered_cpuid_features(c); | 600 | /* cyrix could have cpuid enabled via c_identify()*/ |
412 | detect_nopl(c); | 601 | if (!have_cpuid_p()) |
413 | } | 602 | return; |
414 | } | ||
415 | 603 | ||
416 | static void __cpuinit squash_the_stupid_serial_number(struct cpuinfo_x86 *c) | 604 | cpu_detect(c); |
417 | { | ||
418 | if (cpu_has(c, X86_FEATURE_PN) && disable_x86_serial_nr) { | ||
419 | /* Disable processor serial number */ | ||
420 | unsigned long lo, hi; | ||
421 | rdmsr(MSR_IA32_BBL_CR_CTL, lo, hi); | ||
422 | lo |= 0x200000; | ||
423 | wrmsr(MSR_IA32_BBL_CR_CTL, lo, hi); | ||
424 | printk(KERN_NOTICE "CPU serial number disabled.\n"); | ||
425 | clear_cpu_cap(c, X86_FEATURE_PN); | ||
426 | 605 | ||
427 | /* Disabling the serial number may affect the cpuid level */ | 606 | get_cpu_vendor(c); |
428 | c->cpuid_level = cpuid_eax(0); | ||
429 | } | ||
430 | } | ||
431 | 607 | ||
432 | static int __init x86_serial_nr_setup(char *s) | 608 | get_cpu_cap(c); |
433 | { | 609 | |
434 | disable_x86_serial_nr = 0; | 610 | if (c->cpuid_level >= 0x00000001) { |
435 | return 1; | 611 | c->initial_apicid = (cpuid_ebx(1) >> 24) & 0xFF; |
436 | } | 612 | #ifdef CONFIG_X86_32 |
437 | __setup("serialnumber", x86_serial_nr_setup); | 613 | # ifdef CONFIG_X86_HT |
614 | c->apicid = phys_pkg_id(c->initial_apicid, 0); | ||
615 | # else | ||
616 | c->apicid = c->initial_apicid; | ||
617 | # endif | ||
618 | #endif | ||
438 | 619 | ||
620 | #ifdef CONFIG_X86_HT | ||
621 | c->phys_proc_id = c->initial_apicid; | ||
622 | #endif | ||
623 | } | ||
439 | 624 | ||
625 | get_model_name(c); /* Default name */ | ||
626 | |||
627 | init_scattered_cpuid_features(c); | ||
628 | detect_nopl(c); | ||
629 | } | ||
440 | 630 | ||
441 | /* | 631 | /* |
442 | * This does the hard work of actually picking apart the CPU stuff... | 632 | * This does the hard work of actually picking apart the CPU stuff... |
@@ -448,30 +638,29 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c) | |||
448 | c->loops_per_jiffy = loops_per_jiffy; | 638 | c->loops_per_jiffy = loops_per_jiffy; |
449 | c->x86_cache_size = -1; | 639 | c->x86_cache_size = -1; |
450 | c->x86_vendor = X86_VENDOR_UNKNOWN; | 640 | c->x86_vendor = X86_VENDOR_UNKNOWN; |
451 | c->cpuid_level = -1; /* CPUID not detected */ | ||
452 | c->x86_model = c->x86_mask = 0; /* So far unknown... */ | 641 | c->x86_model = c->x86_mask = 0; /* So far unknown... */ |
453 | c->x86_vendor_id[0] = '\0'; /* Unset */ | 642 | c->x86_vendor_id[0] = '\0'; /* Unset */ |
454 | c->x86_model_id[0] = '\0'; /* Unset */ | 643 | c->x86_model_id[0] = '\0'; /* Unset */ |
455 | c->x86_max_cores = 1; | 644 | c->x86_max_cores = 1; |
645 | c->x86_coreid_bits = 0; | ||
646 | #ifdef CONFIG_X86_64 | ||
647 | c->x86_clflush_size = 64; | ||
648 | #else | ||
649 | c->cpuid_level = -1; /* CPUID not detected */ | ||
456 | c->x86_clflush_size = 32; | 650 | c->x86_clflush_size = 32; |
651 | #endif | ||
652 | c->x86_cache_alignment = c->x86_clflush_size; | ||
457 | memset(&c->x86_capability, 0, sizeof c->x86_capability); | 653 | memset(&c->x86_capability, 0, sizeof c->x86_capability); |
458 | 654 | ||
459 | if (!have_cpuid_p()) { | ||
460 | /* | ||
461 | * First of all, decide if this is a 486 or higher | ||
462 | * It's a 486 if we can modify the AC flag | ||
463 | */ | ||
464 | if (flag_is_changeable_p(X86_EFLAGS_AC)) | ||
465 | c->x86 = 4; | ||
466 | else | ||
467 | c->x86 = 3; | ||
468 | } | ||
469 | |||
470 | generic_identify(c); | 655 | generic_identify(c); |
471 | 656 | ||
472 | if (this_cpu->c_identify) | 657 | if (this_cpu->c_identify) |
473 | this_cpu->c_identify(c); | 658 | this_cpu->c_identify(c); |
474 | 659 | ||
660 | #ifdef CONFIG_X86_64 | ||
661 | c->apicid = phys_pkg_id(0); | ||
662 | #endif | ||
663 | |||
475 | /* | 664 | /* |
476 | * Vendor-specific initialization. In this section we | 665 | * Vendor-specific initialization. In this section we |
477 | * canonicalize the feature flags, meaning if there are | 666 | * canonicalize the feature flags, meaning if there are |
@@ -505,6 +694,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c) | |||
505 | c->x86, c->x86_model); | 694 | c->x86, c->x86_model); |
506 | } | 695 | } |
507 | 696 | ||
697 | #ifdef CONFIG_X86_64 | ||
698 | detect_ht(c); | ||
699 | #endif | ||
700 | |||
508 | /* | 701 | /* |
509 | * On SMP, boot_cpu_data holds the common feature set between | 702 | * On SMP, boot_cpu_data holds the common feature set between |
510 | * all CPUs; so make sure that we indicate which features are | 703 | * all CPUs; so make sure that we indicate which features are |
@@ -513,7 +706,7 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c) | |||
513 | */ | 706 | */ |
514 | if (c != &boot_cpu_data) { | 707 | if (c != &boot_cpu_data) { |
515 | /* AND the already accumulated flags with these */ | 708 | /* AND the already accumulated flags with these */ |
516 | for (i = 0 ; i < NCAPINTS ; i++) | 709 | for (i = 0; i < NCAPINTS; i++) |
517 | boot_cpu_data.x86_capability[i] &= c->x86_capability[i]; | 710 | boot_cpu_data.x86_capability[i] &= c->x86_capability[i]; |
518 | } | 711 | } |
519 | 712 | ||
@@ -521,72 +714,91 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c) | |||
521 | for (i = 0; i < NCAPINTS; i++) | 714 | for (i = 0; i < NCAPINTS; i++) |
522 | c->x86_capability[i] &= ~cleared_cpu_caps[i]; | 715 | c->x86_capability[i] &= ~cleared_cpu_caps[i]; |
523 | 716 | ||
717 | #ifdef CONFIG_X86_MCE | ||
524 | /* Init Machine Check Exception if available. */ | 718 | /* Init Machine Check Exception if available. */ |
525 | mcheck_init(c); | 719 | mcheck_init(c); |
720 | #endif | ||
526 | 721 | ||
527 | select_idle_routine(c); | 722 | select_idle_routine(c); |
723 | |||
724 | #if defined(CONFIG_NUMA) && defined(CONFIG_X86_64) | ||
725 | numa_add_cpu(smp_processor_id()); | ||
726 | #endif | ||
528 | } | 727 | } |
529 | 728 | ||
729 | #ifdef CONFIG_X86_64 | ||
730 | static void vgetcpu_set_mode(void) | ||
731 | { | ||
732 | if (cpu_has(&boot_cpu_data, X86_FEATURE_RDTSCP)) | ||
733 | vgetcpu_mode = VGETCPU_RDTSCP; | ||
734 | else | ||
735 | vgetcpu_mode = VGETCPU_LSL; | ||
736 | } | ||
737 | #endif | ||
738 | |||
530 | void __init identify_boot_cpu(void) | 739 | void __init identify_boot_cpu(void) |
531 | { | 740 | { |
532 | identify_cpu(&boot_cpu_data); | 741 | identify_cpu(&boot_cpu_data); |
742 | #ifdef CONFIG_X86_32 | ||
533 | sysenter_setup(); | 743 | sysenter_setup(); |
534 | enable_sep_cpu(); | 744 | enable_sep_cpu(); |
745 | #else | ||
746 | vgetcpu_set_mode(); | ||
747 | #endif | ||
535 | } | 748 | } |
536 | 749 | ||
537 | void __cpuinit identify_secondary_cpu(struct cpuinfo_x86 *c) | 750 | void __cpuinit identify_secondary_cpu(struct cpuinfo_x86 *c) |
538 | { | 751 | { |
539 | BUG_ON(c == &boot_cpu_data); | 752 | BUG_ON(c == &boot_cpu_data); |
540 | identify_cpu(c); | 753 | identify_cpu(c); |
754 | #ifdef CONFIG_X86_32 | ||
541 | enable_sep_cpu(); | 755 | enable_sep_cpu(); |
756 | #endif | ||
542 | mtrr_ap_init(); | 757 | mtrr_ap_init(); |
543 | } | 758 | } |
544 | 759 | ||
545 | #ifdef CONFIG_X86_HT | 760 | struct msr_range { |
546 | void __cpuinit detect_ht(struct cpuinfo_x86 *c) | 761 | unsigned min; |
547 | { | 762 | unsigned max; |
548 | u32 eax, ebx, ecx, edx; | 763 | }; |
549 | int index_msb, core_bits; | ||
550 | |||
551 | cpuid(1, &eax, &ebx, &ecx, &edx); | ||
552 | |||
553 | if (!cpu_has(c, X86_FEATURE_HT) || cpu_has(c, X86_FEATURE_CMP_LEGACY)) | ||
554 | return; | ||
555 | |||
556 | smp_num_siblings = (ebx & 0xff0000) >> 16; | ||
557 | 764 | ||
558 | if (smp_num_siblings == 1) { | 765 | static struct msr_range msr_range_array[] __cpuinitdata = { |
559 | printk(KERN_INFO "CPU: Hyper-Threading is disabled\n"); | 766 | { 0x00000000, 0x00000418}, |
560 | } else if (smp_num_siblings > 1) { | 767 | { 0xc0000000, 0xc000040b}, |
768 | { 0xc0010000, 0xc0010142}, | ||
769 | { 0xc0011000, 0xc001103b}, | ||
770 | }; | ||
561 | 771 | ||
562 | if (smp_num_siblings > NR_CPUS) { | 772 | static void __cpuinit print_cpu_msr(void) |
563 | printk(KERN_WARNING "CPU: Unsupported number of the " | 773 | { |
564 | "siblings %d", smp_num_siblings); | 774 | unsigned index; |
565 | smp_num_siblings = 1; | 775 | u64 val; |
566 | return; | 776 | int i; |
777 | unsigned index_min, index_max; | ||
778 | |||
779 | for (i = 0; i < ARRAY_SIZE(msr_range_array); i++) { | ||
780 | index_min = msr_range_array[i].min; | ||
781 | index_max = msr_range_array[i].max; | ||
782 | for (index = index_min; index < index_max; index++) { | ||
783 | if (rdmsrl_amd_safe(index, &val)) | ||
784 | continue; | ||
785 | printk(KERN_INFO " MSR%08x: %016llx\n", index, val); | ||
567 | } | 786 | } |
787 | } | ||
788 | } | ||
568 | 789 | ||
569 | index_msb = get_count_order(smp_num_siblings); | 790 | static int show_msr __cpuinitdata; |
570 | c->phys_proc_id = phys_pkg_id(c->initial_apicid, index_msb); | 791 | static __init int setup_show_msr(char *arg) |
571 | 792 | { | |
572 | printk(KERN_INFO "CPU: Physical Processor ID: %d\n", | 793 | int num; |
573 | c->phys_proc_id); | ||
574 | |||
575 | smp_num_siblings = smp_num_siblings / c->x86_max_cores; | ||
576 | |||
577 | index_msb = get_count_order(smp_num_siblings) ; | ||
578 | |||
579 | core_bits = get_count_order(c->x86_max_cores); | ||
580 | 794 | ||
581 | c->cpu_core_id = phys_pkg_id(c->initial_apicid, index_msb) & | 795 | get_option(&arg, &num); |
582 | ((1 << core_bits) - 1); | ||
583 | 796 | ||
584 | if (c->x86_max_cores > 1) | 797 | if (num > 0) |
585 | printk(KERN_INFO "CPU: Processor Core ID: %d\n", | 798 | show_msr = num; |
586 | c->cpu_core_id); | 799 | return 1; |
587 | } | ||
588 | } | 800 | } |
589 | #endif | 801 | __setup("show_msr=", setup_show_msr); |
590 | 802 | ||
591 | static __init int setup_noclflush(char *arg) | 803 | static __init int setup_noclflush(char *arg) |
592 | { | 804 | { |
@@ -604,18 +816,26 @@ void __cpuinit print_cpu_info(struct cpuinfo_x86 *c) | |||
604 | else if (c->cpuid_level >= 0) | 816 | else if (c->cpuid_level >= 0) |
605 | vendor = c->x86_vendor_id; | 817 | vendor = c->x86_vendor_id; |
606 | 818 | ||
607 | if (vendor && strncmp(c->x86_model_id, vendor, strlen(vendor))) | 819 | if (vendor && !strstr(c->x86_model_id, vendor)) |
608 | printk("%s ", vendor); | 820 | printk(KERN_CONT "%s ", vendor); |
609 | 821 | ||
610 | if (!c->x86_model_id[0]) | 822 | if (c->x86_model_id[0]) |
611 | printk("%d86", c->x86); | 823 | printk(KERN_CONT "%s", c->x86_model_id); |
612 | else | 824 | else |
613 | printk("%s", c->x86_model_id); | 825 | printk(KERN_CONT "%d86", c->x86); |
614 | 826 | ||
615 | if (c->x86_mask || c->cpuid_level >= 0) | 827 | if (c->x86_mask || c->cpuid_level >= 0) |
616 | printk(" stepping %02x\n", c->x86_mask); | 828 | printk(KERN_CONT " stepping %02x\n", c->x86_mask); |
617 | else | 829 | else |
618 | printk("\n"); | 830 | printk(KERN_CONT "\n"); |
831 | |||
832 | #ifdef CONFIG_SMP | ||
833 | if (c->cpu_index < show_msr) | ||
834 | print_cpu_msr(); | ||
835 | #else | ||
836 | if (show_msr) | ||
837 | print_cpu_msr(); | ||
838 | #endif | ||
619 | } | 839 | } |
620 | 840 | ||
621 | static __init int setup_disablecpuid(char *arg) | 841 | static __init int setup_disablecpuid(char *arg) |
@@ -631,19 +851,89 @@ __setup("clearcpuid=", setup_disablecpuid); | |||
631 | 851 | ||
632 | cpumask_t cpu_initialized __cpuinitdata = CPU_MASK_NONE; | 852 | cpumask_t cpu_initialized __cpuinitdata = CPU_MASK_NONE; |
633 | 853 | ||
634 | void __init early_cpu_init(void) | 854 | #ifdef CONFIG_X86_64 |
855 | struct x8664_pda **_cpu_pda __read_mostly; | ||
856 | EXPORT_SYMBOL(_cpu_pda); | ||
857 | |||
858 | struct desc_ptr idt_descr = { 256 * 16 - 1, (unsigned long) idt_table }; | ||
859 | |||
860 | char boot_cpu_stack[IRQSTACKSIZE] __page_aligned_bss; | ||
861 | |||
862 | void __cpuinit pda_init(int cpu) | ||
635 | { | 863 | { |
636 | struct cpu_vendor_dev *cvdev; | 864 | struct x8664_pda *pda = cpu_pda(cpu); |
865 | |||
866 | /* Setup up data that may be needed in __get_free_pages early */ | ||
867 | loadsegment(fs, 0); | ||
868 | loadsegment(gs, 0); | ||
869 | /* Memory clobbers used to order PDA accessed */ | ||
870 | mb(); | ||
871 | wrmsrl(MSR_GS_BASE, pda); | ||
872 | mb(); | ||
873 | |||
874 | pda->cpunumber = cpu; | ||
875 | pda->irqcount = -1; | ||
876 | pda->kernelstack = (unsigned long)stack_thread_info() - | ||
877 | PDA_STACKOFFSET + THREAD_SIZE; | ||
878 | pda->active_mm = &init_mm; | ||
879 | pda->mmu_state = 0; | ||
880 | |||
881 | if (cpu == 0) { | ||
882 | /* others are initialized in smpboot.c */ | ||
883 | pda->pcurrent = &init_task; | ||
884 | pda->irqstackptr = boot_cpu_stack; | ||
885 | pda->irqstackptr += IRQSTACKSIZE - 64; | ||
886 | } else { | ||
887 | if (!pda->irqstackptr) { | ||
888 | pda->irqstackptr = (char *) | ||
889 | __get_free_pages(GFP_ATOMIC, IRQSTACK_ORDER); | ||
890 | if (!pda->irqstackptr) | ||
891 | panic("cannot allocate irqstack for cpu %d", | ||
892 | cpu); | ||
893 | pda->irqstackptr += IRQSTACKSIZE - 64; | ||
894 | } | ||
895 | |||
896 | if (pda->nodenumber == 0 && cpu_to_node(cpu) != NUMA_NO_NODE) | ||
897 | pda->nodenumber = cpu_to_node(cpu); | ||
898 | } | ||
899 | } | ||
900 | |||
901 | char boot_exception_stacks[(N_EXCEPTION_STACKS - 1) * EXCEPTION_STKSZ + | ||
902 | DEBUG_STKSZ] __page_aligned_bss; | ||
637 | 903 | ||
638 | for (cvdev = __x86cpuvendor_start ; | 904 | extern asmlinkage void ignore_sysret(void); |
639 | cvdev < __x86cpuvendor_end ; | ||
640 | cvdev++) | ||
641 | cpu_devs[cvdev->vendor] = cvdev->cpu_dev; | ||
642 | 905 | ||
643 | early_cpu_detect(); | 906 | /* May not be marked __init: used by software suspend */ |
644 | validate_pat_support(&boot_cpu_data); | 907 | void syscall_init(void) |
908 | { | ||
909 | /* | ||
910 | * LSTAR and STAR live in a bit strange symbiosis. | ||
911 | * They both write to the same internal register. STAR allows to | ||
912 | * set CS/DS but only a 32bit target. LSTAR sets the 64bit rip. | ||
913 | */ | ||
914 | wrmsrl(MSR_STAR, ((u64)__USER32_CS)<<48 | ((u64)__KERNEL_CS)<<32); | ||
915 | wrmsrl(MSR_LSTAR, system_call); | ||
916 | wrmsrl(MSR_CSTAR, ignore_sysret); | ||
917 | |||
918 | #ifdef CONFIG_IA32_EMULATION | ||
919 | syscall32_cpu_init(); | ||
920 | #endif | ||
921 | |||
922 | /* Flags to clear on syscall */ | ||
923 | wrmsrl(MSR_SYSCALL_MASK, | ||
924 | X86_EFLAGS_TF|X86_EFLAGS_DF|X86_EFLAGS_IF|X86_EFLAGS_IOPL); | ||
645 | } | 925 | } |
646 | 926 | ||
927 | unsigned long kernel_eflags; | ||
928 | |||
929 | /* | ||
930 | * Copies of the original ist values from the tss are only accessed during | ||
931 | * debugging, no special alignment required. | ||
932 | */ | ||
933 | DEFINE_PER_CPU(struct orig_ist, orig_ist); | ||
934 | |||
935 | #else | ||
936 | |||
647 | /* Make sure %fs is initialized properly in idle threads */ | 937 | /* Make sure %fs is initialized properly in idle threads */ |
648 | struct pt_regs * __cpuinit idle_regs(struct pt_regs *regs) | 938 | struct pt_regs * __cpuinit idle_regs(struct pt_regs *regs) |
649 | { | 939 | { |
@@ -651,25 +941,136 @@ struct pt_regs * __cpuinit idle_regs(struct pt_regs *regs) | |||
651 | regs->fs = __KERNEL_PERCPU; | 941 | regs->fs = __KERNEL_PERCPU; |
652 | return regs; | 942 | return regs; |
653 | } | 943 | } |
654 | 944 | #endif | |
655 | /* Current gdt points %fs at the "master" per-cpu area: after this, | ||
656 | * it's on the real one. */ | ||
657 | void switch_to_new_gdt(void) | ||
658 | { | ||
659 | struct desc_ptr gdt_descr; | ||
660 | |||
661 | gdt_descr.address = (long)get_cpu_gdt_table(smp_processor_id()); | ||
662 | gdt_descr.size = GDT_SIZE - 1; | ||
663 | load_gdt(&gdt_descr); | ||
664 | asm("mov %0, %%fs" : : "r" (__KERNEL_PERCPU) : "memory"); | ||
665 | } | ||
666 | 945 | ||
667 | /* | 946 | /* |
668 | * cpu_init() initializes state that is per-CPU. Some data is already | 947 | * cpu_init() initializes state that is per-CPU. Some data is already |
669 | * initialized (naturally) in the bootstrap process, such as the GDT | 948 | * initialized (naturally) in the bootstrap process, such as the GDT |
670 | * and IDT. We reload them nevertheless, this function acts as a | 949 | * and IDT. We reload them nevertheless, this function acts as a |
671 | * 'CPU state barrier', nothing should get across. | 950 | * 'CPU state barrier', nothing should get across. |
951 | * A lot of state is already set up in PDA init for 64 bit | ||
672 | */ | 952 | */ |
953 | #ifdef CONFIG_X86_64 | ||
954 | void __cpuinit cpu_init(void) | ||
955 | { | ||
956 | int cpu = stack_smp_processor_id(); | ||
957 | struct tss_struct *t = &per_cpu(init_tss, cpu); | ||
958 | struct orig_ist *orig_ist = &per_cpu(orig_ist, cpu); | ||
959 | unsigned long v; | ||
960 | char *estacks = NULL; | ||
961 | struct task_struct *me; | ||
962 | int i; | ||
963 | |||
964 | /* CPU 0 is initialised in head64.c */ | ||
965 | if (cpu != 0) | ||
966 | pda_init(cpu); | ||
967 | else | ||
968 | estacks = boot_exception_stacks; | ||
969 | |||
970 | me = current; | ||
971 | |||
972 | if (cpu_test_and_set(cpu, cpu_initialized)) | ||
973 | panic("CPU#%d already initialized!\n", cpu); | ||
974 | |||
975 | printk(KERN_INFO "Initializing CPU#%d\n", cpu); | ||
976 | |||
977 | clear_in_cr4(X86_CR4_VME|X86_CR4_PVI|X86_CR4_TSD|X86_CR4_DE); | ||
978 | |||
979 | /* | ||
980 | * Initialize the per-CPU GDT with the boot GDT, | ||
981 | * and set up the GDT descriptor: | ||
982 | */ | ||
983 | |||
984 | switch_to_new_gdt(); | ||
985 | load_idt((const struct desc_ptr *)&idt_descr); | ||
986 | |||
987 | memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8); | ||
988 | syscall_init(); | ||
989 | |||
990 | wrmsrl(MSR_FS_BASE, 0); | ||
991 | wrmsrl(MSR_KERNEL_GS_BASE, 0); | ||
992 | barrier(); | ||
993 | |||
994 | check_efer(); | ||
995 | if (cpu != 0 && x2apic) | ||
996 | enable_x2apic(); | ||
997 | |||
998 | /* | ||
999 | * set up and load the per-CPU TSS | ||
1000 | */ | ||
1001 | if (!orig_ist->ist[0]) { | ||
1002 | static const unsigned int order[N_EXCEPTION_STACKS] = { | ||
1003 | [0 ... N_EXCEPTION_STACKS - 1] = EXCEPTION_STACK_ORDER, | ||
1004 | [DEBUG_STACK - 1] = DEBUG_STACK_ORDER | ||
1005 | }; | ||
1006 | for (v = 0; v < N_EXCEPTION_STACKS; v++) { | ||
1007 | if (cpu) { | ||
1008 | estacks = (char *)__get_free_pages(GFP_ATOMIC, order[v]); | ||
1009 | if (!estacks) | ||
1010 | panic("Cannot allocate exception " | ||
1011 | "stack %ld %d\n", v, cpu); | ||
1012 | } | ||
1013 | estacks += PAGE_SIZE << order[v]; | ||
1014 | orig_ist->ist[v] = t->x86_tss.ist[v] = | ||
1015 | (unsigned long)estacks; | ||
1016 | } | ||
1017 | } | ||
1018 | |||
1019 | t->x86_tss.io_bitmap_base = offsetof(struct tss_struct, io_bitmap); | ||
1020 | /* | ||
1021 | * <= is required because the CPU will access up to | ||
1022 | * 8 bits beyond the end of the IO permission bitmap. | ||
1023 | */ | ||
1024 | for (i = 0; i <= IO_BITMAP_LONGS; i++) | ||
1025 | t->io_bitmap[i] = ~0UL; | ||
1026 | |||
1027 | atomic_inc(&init_mm.mm_count); | ||
1028 | me->active_mm = &init_mm; | ||
1029 | if (me->mm) | ||
1030 | BUG(); | ||
1031 | enter_lazy_tlb(&init_mm, me); | ||
1032 | |||
1033 | load_sp0(t, ¤t->thread); | ||
1034 | set_tss_desc(cpu, t); | ||
1035 | load_TR_desc(); | ||
1036 | load_LDT(&init_mm.context); | ||
1037 | |||
1038 | #ifdef CONFIG_KGDB | ||
1039 | /* | ||
1040 | * If the kgdb is connected no debug regs should be altered. This | ||
1041 | * is only applicable when KGDB and a KGDB I/O module are built | ||
1042 | * into the kernel and you are using early debugging with | ||
1043 | * kgdbwait. KGDB will control the kernel HW breakpoint registers. | ||
1044 | */ | ||
1045 | if (kgdb_connected && arch_kgdb_ops.correct_hw_break) | ||
1046 | arch_kgdb_ops.correct_hw_break(); | ||
1047 | else { | ||
1048 | #endif | ||
1049 | /* | ||
1050 | * Clear all 6 debug registers: | ||
1051 | */ | ||
1052 | |||
1053 | set_debugreg(0UL, 0); | ||
1054 | set_debugreg(0UL, 1); | ||
1055 | set_debugreg(0UL, 2); | ||
1056 | set_debugreg(0UL, 3); | ||
1057 | set_debugreg(0UL, 6); | ||
1058 | set_debugreg(0UL, 7); | ||
1059 | #ifdef CONFIG_KGDB | ||
1060 | /* If the kgdb is connected no debug regs should be altered. */ | ||
1061 | } | ||
1062 | #endif | ||
1063 | |||
1064 | fpu_init(); | ||
1065 | |||
1066 | raw_local_save_flags(kernel_eflags); | ||
1067 | |||
1068 | if (is_uv_system()) | ||
1069 | uv_cpu_init(); | ||
1070 | } | ||
1071 | |||
1072 | #else | ||
1073 | |||
673 | void __cpuinit cpu_init(void) | 1074 | void __cpuinit cpu_init(void) |
674 | { | 1075 | { |
675 | int cpu = smp_processor_id(); | 1076 | int cpu = smp_processor_id(); |
@@ -723,19 +1124,21 @@ void __cpuinit cpu_init(void) | |||
723 | /* | 1124 | /* |
724 | * Force FPU initialization: | 1125 | * Force FPU initialization: |
725 | */ | 1126 | */ |
726 | current_thread_info()->status = 0; | 1127 | if (cpu_has_xsave) |
1128 | current_thread_info()->status = TS_XSAVE; | ||
1129 | else | ||
1130 | current_thread_info()->status = 0; | ||
727 | clear_used_math(); | 1131 | clear_used_math(); |
728 | mxcsr_feature_mask_init(); | 1132 | mxcsr_feature_mask_init(); |
729 | } | ||
730 | 1133 | ||
731 | #ifdef CONFIG_HOTPLUG_CPU | 1134 | /* |
732 | void __cpuinit cpu_uninit(void) | 1135 | * Boot processor to setup the FP and extended state context info. |
733 | { | 1136 | */ |
734 | int cpu = raw_smp_processor_id(); | 1137 | if (!smp_processor_id()) |
735 | cpu_clear(cpu, cpu_initialized); | 1138 | init_thread_xstate(); |
736 | 1139 | ||
737 | /* lazy TLB state */ | 1140 | xsave_init(); |
738 | per_cpu(cpu_tlbstate, cpu).state = 0; | ||
739 | per_cpu(cpu_tlbstate, cpu).active_mm = &init_mm; | ||
740 | } | 1141 | } |
1142 | |||
1143 | |||
741 | #endif | 1144 | #endif |