2008-09-05 11:09:00 +08:00
|
|
|
#include <linux/bootmem.h>
|
2009-03-14 13:49:49 +08:00
|
|
|
#include <linux/linkage.h>
|
2008-09-05 11:09:00 +08:00
|
|
|
#include <linux/bitops.h>
|
2009-03-14 13:49:49 +08:00
|
|
|
#include <linux/kernel.h>
|
2008-09-05 11:09:00 +08:00
|
|
|
#include <linux/module.h>
|
2009-03-14 13:49:49 +08:00
|
|
|
#include <linux/percpu.h>
|
|
|
|
#include <linux/string.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/delay.h>
|
2009-03-14 13:49:49 +08:00
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/kgdb.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/smp.h>
|
2009-03-14 13:49:49 +08:00
|
|
|
#include <linux/io.h>
|
|
|
|
|
|
|
|
#include <asm/stackprotector.h>
|
2009-04-06 15:02:57 +08:00
|
|
|
#include <asm/perf_counter.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <asm/mmu_context.h>
|
2009-03-14 13:49:49 +08:00
|
|
|
#include <asm/hypervisor.h>
|
|
|
|
#include <asm/processor.h>
|
|
|
|
#include <asm/sections.h>
|
2009-03-14 15:46:17 +08:00
|
|
|
#include <asm/topology.h>
|
2009-03-14 13:49:49 +08:00
|
|
|
#include <asm/cpumask.h>
|
|
|
|
#include <asm/pgtable.h>
|
|
|
|
#include <asm/atomic.h>
|
|
|
|
#include <asm/proto.h>
|
|
|
|
#include <asm/setup.h>
|
|
|
|
#include <asm/apic.h>
|
|
|
|
#include <asm/desc.h>
|
|
|
|
#include <asm/i387.h>
|
2006-06-23 17:04:18 +08:00
|
|
|
#include <asm/mtrr.h>
|
2009-03-14 13:49:49 +08:00
|
|
|
#include <asm/numa.h>
|
|
|
|
#include <asm/asm.h>
|
|
|
|
#include <asm/cpu.h>
|
2006-06-23 17:04:20 +08:00
|
|
|
#include <asm/mce.h>
|
2009-03-14 13:49:49 +08:00
|
|
|
#include <asm/msr.h>
|
2008-05-08 15:18:43 +08:00
|
|
|
#include <asm/pat.h>
|
2008-10-31 16:31:38 +08:00
|
|
|
#include <asm/smp.h>
|
2009-02-17 21:02:01 +08:00
|
|
|
|
|
|
|
#ifdef CONFIG_X86_LOCAL_APIC
|
2009-01-21 16:26:06 +08:00
|
|
|
#include <asm/uv/uv.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "cpu.h"
|
|
|
|
|
2009-01-04 21:18:03 +08:00
|
|
|
/* all of these masks are initialized in setup_cpu_local_masks() */
|
|
|
|
cpumask_var_t cpu_initialized_mask;
|
2009-03-14 13:49:49 +08:00
|
|
|
cpumask_var_t cpu_callout_mask;
|
|
|
|
cpumask_var_t cpu_callin_mask;
|
2009-01-04 21:18:03 +08:00
|
|
|
|
|
|
|
/* representing cpus for which sibling maps can be computed */
|
|
|
|
cpumask_var_t cpu_sibling_setup_mask;
|
|
|
|
|
2009-01-27 11:56:47 +08:00
|
|
|
/* correctly size the local cpu masks */
|
2009-01-27 19:03:24 +08:00
|
|
|
void __init setup_cpu_local_masks(void)
|
2009-01-27 11:56:47 +08:00
|
|
|
{
|
|
|
|
alloc_bootmem_cpumask_var(&cpu_initialized_mask);
|
|
|
|
alloc_bootmem_cpumask_var(&cpu_callin_mask);
|
|
|
|
alloc_bootmem_cpumask_var(&cpu_callout_mask);
|
|
|
|
alloc_bootmem_cpumask_var(&cpu_sibling_setup_mask);
|
|
|
|
}
|
|
|
|
|
2009-03-12 20:08:49 +08:00
|
|
|
static const struct cpu_dev *this_cpu __cpuinitdata;
|
2008-09-05 03:09:47 +08:00
|
|
|
|
2009-01-21 16:26:05 +08:00
|
|
|
DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
|
2008-09-05 11:09:01 +08:00
|
|
|
#ifdef CONFIG_X86_64
|
2009-01-21 16:26:05 +08:00
|
|
|
/*
|
|
|
|
* We need valid kernel segments for data and code in long mode too
|
|
|
|
* IRET will check the segment types kkeil 2000/10/28
|
|
|
|
* Also sysret mandates a special GDT layout
|
|
|
|
*
|
2009-03-14 13:49:49 +08:00
|
|
|
* TLS descriptors are currently at a different place compared to i386.
|
2009-01-21 16:26:05 +08:00
|
|
|
* Hopefully nobody expects them at a fixed place (Wine?)
|
|
|
|
*/
|
2009-03-14 15:46:17 +08:00
|
|
|
[GDT_ENTRY_KERNEL32_CS] = { { { 0x0000ffff, 0x00cf9b00 } } },
|
|
|
|
[GDT_ENTRY_KERNEL_CS] = { { { 0x0000ffff, 0x00af9b00 } } },
|
|
|
|
[GDT_ENTRY_KERNEL_DS] = { { { 0x0000ffff, 0x00cf9300 } } },
|
|
|
|
[GDT_ENTRY_DEFAULT_USER32_CS] = { { { 0x0000ffff, 0x00cffb00 } } },
|
|
|
|
[GDT_ENTRY_DEFAULT_USER_DS] = { { { 0x0000ffff, 0x00cff300 } } },
|
|
|
|
[GDT_ENTRY_DEFAULT_USER_CS] = { { { 0x0000ffff, 0x00affb00 } } },
|
2008-09-05 11:09:01 +08:00
|
|
|
#else
|
2009-03-14 15:46:17 +08:00
|
|
|
[GDT_ENTRY_KERNEL_CS] = { { { 0x0000ffff, 0x00cf9a00 } } },
|
|
|
|
[GDT_ENTRY_KERNEL_DS] = { { { 0x0000ffff, 0x00cf9200 } } },
|
|
|
|
[GDT_ENTRY_DEFAULT_USER_CS] = { { { 0x0000ffff, 0x00cffa00 } } },
|
|
|
|
[GDT_ENTRY_DEFAULT_USER_DS] = { { { 0x0000ffff, 0x00cff200 } } },
|
2007-05-03 01:27:10 +08:00
|
|
|
/*
|
|
|
|
* Segments used for calling PnP BIOS have byte granularity.
|
|
|
|
* They code segments and data segments have fixed 64k limits,
|
|
|
|
* the transfer segment sizes are set at run time.
|
|
|
|
*/
|
2008-01-30 20:31:11 +08:00
|
|
|
/* 32-bit code */
|
2009-03-14 15:46:17 +08:00
|
|
|
[GDT_ENTRY_PNPBIOS_CS32] = { { { 0x0000ffff, 0x00409a00 } } },
|
2008-01-30 20:31:11 +08:00
|
|
|
/* 16-bit code */
|
2009-03-14 15:46:17 +08:00
|
|
|
[GDT_ENTRY_PNPBIOS_CS16] = { { { 0x0000ffff, 0x00009a00 } } },
|
2008-01-30 20:31:11 +08:00
|
|
|
/* 16-bit data */
|
2009-03-14 15:46:17 +08:00
|
|
|
[GDT_ENTRY_PNPBIOS_DS] = { { { 0x0000ffff, 0x00009200 } } },
|
2008-01-30 20:31:11 +08:00
|
|
|
/* 16-bit data */
|
2009-03-14 15:46:17 +08:00
|
|
|
[GDT_ENTRY_PNPBIOS_TS1] = { { { 0x00000000, 0x00009200 } } },
|
2008-01-30 20:31:11 +08:00
|
|
|
/* 16-bit data */
|
2009-03-14 15:46:17 +08:00
|
|
|
[GDT_ENTRY_PNPBIOS_TS2] = { { { 0x00000000, 0x00009200 } } },
|
2007-05-03 01:27:10 +08:00
|
|
|
/*
|
|
|
|
* The APM segments have byte granularity and their bases
|
|
|
|
* are set at run time. All have 64k limits.
|
|
|
|
*/
|
2008-01-30 20:31:11 +08:00
|
|
|
/* 32-bit code */
|
2009-03-14 15:46:17 +08:00
|
|
|
[GDT_ENTRY_APMBIOS_BASE] = { { { 0x0000ffff, 0x00409a00 } } },
|
2007-05-03 01:27:10 +08:00
|
|
|
/* 16-bit code */
|
2009-03-14 15:46:17 +08:00
|
|
|
[GDT_ENTRY_APMBIOS_BASE+1] = { { { 0x0000ffff, 0x00009a00 } } },
|
2008-01-30 20:31:11 +08:00
|
|
|
/* data */
|
2009-03-14 15:46:17 +08:00
|
|
|
[GDT_ENTRY_APMBIOS_BASE+2] = { { { 0x0000ffff, 0x00409200 } } },
|
2007-05-03 01:27:10 +08:00
|
|
|
|
i386: fix/simplify espfix stack switching, move it into assembly
The espfix code triggers if we have a protected mode userspace
application with a 16-bit stack. On returning to userspace, with iret,
the CPU doesn't restore the high word of the stack pointer. This is an
"official" bug, and the work-around used in the kernel is to temporarily
switch to a 32-bit stack segment/pointer pair where the high word of the
pointer is equal to the high word of the userspace stackpointer.
The current implementation uses THREAD_SIZE to determine the cut-off,
but there is no good reason not to use the more natural 64kb... However,
implementing this by simply substituting THREAD_SIZE with 65536 in
patch_espfix_desc crashed the test application. patch_espfix_desc tries
to do what is described above, but gets it subtly wrong if the userspace
stack pointer is just below a multiple of THREAD_SIZE: an overflow
occurs to bit 13... With a bit of luck, when the kernelspace
stackpointer is just below a 64kb-boundary, the overflow then ripples
trough to bit 16 and userspace will see its stack pointer changed by
65536.
This patch moves all espfix code into entry_32.S. Selecting a 16-bit
cut-off simplifies the code. The game with changing the limit dynamically
is removed too. It complicates matters and I see no value in it. Changing
only the top 16-bit word of ESP is one instruction and it also implies
that only two bytes of the ESPFIX GDT entry need to be changed and this
can be implemented in just a handful simple to understand instructions.
As a side effect, the operation to compute the original ESP from the
ESPFIX ESP and the GDT entry simplifies a bit too, and the remaining
three instructions have been expanded inline in entry_32.S.
impact: can now reliably run userspace with ESP=xxxxfffc on 16-bit
stack segment
Signed-off-by: Alexander van Heukelum <heukelum@fastmail.fm>
Acked-by: Stas Sergeev <stsp@aknet.ru>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-06-18 06:35:58 +08:00
|
|
|
[GDT_ENTRY_ESPFIX_SS] = { { { 0x0000ffff, 0x00cf9200 } } },
|
2009-03-14 15:46:17 +08:00
|
|
|
[GDT_ENTRY_PERCPU] = { { { 0x0000ffff, 0x00cf9200 } } },
|
2009-02-09 21:17:40 +08:00
|
|
|
GDT_STACK_CANARY_INIT
|
2008-09-05 11:09:01 +08:00
|
|
|
#endif
|
2009-01-21 16:26:05 +08:00
|
|
|
} };
|
2007-05-03 01:27:15 +08:00
|
|
|
EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
|
2007-05-03 01:27:10 +08:00
|
|
|
|
2009-05-23 03:17:45 +08:00
|
|
|
static int __init x86_xsave_setup(char *s)
|
|
|
|
{
|
|
|
|
setup_clear_cpu_cap(X86_FEATURE_XSAVE);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
__setup("noxsave", x86_xsave_setup);
|
|
|
|
|
2008-09-05 11:09:02 +08:00
|
|
|
#ifdef CONFIG_X86_32
|
2006-03-23 18:59:33 +08:00
|
|
|
static int cachesize_override __cpuinitdata = -1;
|
|
|
|
static int disable_x86_serial_nr __cpuinitdata = 1;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-09-05 03:09:47 +08:00
|
|
|
static int __init cachesize_setup(char *str)
|
|
|
|
{
|
|
|
|
get_option(&str, &cachesize_override);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
__setup("cachesize=", cachesize_setup);
|
|
|
|
|
|
|
|
static int __init x86_fxsr_setup(char *s)
|
|
|
|
{
|
|
|
|
setup_clear_cpu_cap(X86_FEATURE_FXSR);
|
|
|
|
setup_clear_cpu_cap(X86_FEATURE_XMM);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
__setup("nofxsr", x86_fxsr_setup);
|
|
|
|
|
|
|
|
static int __init x86_sep_setup(char *s)
|
|
|
|
{
|
|
|
|
setup_clear_cpu_cap(X86_FEATURE_SEP);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
__setup("nosep", x86_sep_setup);
|
|
|
|
|
|
|
|
/* Standard macro to see if a specific flag is changeable */
|
|
|
|
static inline int flag_is_changeable_p(u32 flag)
|
|
|
|
{
|
|
|
|
u32 f1, f2;
|
|
|
|
|
2008-10-01 05:17:51 +08:00
|
|
|
/*
|
|
|
|
* Cyrix and IDT cpus allow disabling of CPUID
|
|
|
|
* so the code below may return different results
|
|
|
|
* when it is executed before and after enabling
|
|
|
|
* the CPUID. Add "volatile" to not allow gcc to
|
|
|
|
* optimize the subsequent calls to this function.
|
|
|
|
*/
|
2009-03-14 15:46:17 +08:00
|
|
|
asm volatile ("pushfl \n\t"
|
|
|
|
"pushfl \n\t"
|
|
|
|
"popl %0 \n\t"
|
|
|
|
"movl %0, %1 \n\t"
|
|
|
|
"xorl %2, %0 \n\t"
|
|
|
|
"pushl %0 \n\t"
|
|
|
|
"popfl \n\t"
|
|
|
|
"pushfl \n\t"
|
|
|
|
"popl %0 \n\t"
|
|
|
|
"popfl \n\t"
|
|
|
|
|
2008-10-01 05:17:51 +08:00
|
|
|
: "=&r" (f1), "=&r" (f2)
|
|
|
|
: "ir" (flag));
|
2008-09-05 03:09:47 +08:00
|
|
|
|
|
|
|
return ((f1^f2) & flag) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Probe for the CPUID instruction */
|
|
|
|
static int __cpuinit have_cpuid_p(void)
|
|
|
|
{
|
|
|
|
return flag_is_changeable_p(X86_EFLAGS_ID);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __cpuinit squash_the_stupid_serial_number(struct cpuinfo_x86 *c)
|
|
|
|
{
|
2009-03-14 15:46:17 +08:00
|
|
|
unsigned long lo, hi;
|
|
|
|
|
|
|
|
if (!cpu_has(c, X86_FEATURE_PN) || !disable_x86_serial_nr)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Disable processor serial number: */
|
|
|
|
|
|
|
|
rdmsr(MSR_IA32_BBL_CR_CTL, lo, hi);
|
|
|
|
lo |= 0x200000;
|
|
|
|
wrmsr(MSR_IA32_BBL_CR_CTL, lo, hi);
|
|
|
|
|
|
|
|
printk(KERN_NOTICE "CPU serial number disabled.\n");
|
|
|
|
clear_cpu_cap(c, X86_FEATURE_PN);
|
|
|
|
|
|
|
|
/* Disabling the serial number may affect the cpuid level */
|
|
|
|
c->cpuid_level = cpuid_eax(0);
|
2008-09-05 03:09:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int __init x86_serial_nr_setup(char *s)
|
|
|
|
{
|
|
|
|
disable_x86_serial_nr = 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
__setup("serialnumber", x86_serial_nr_setup);
|
2008-09-05 11:09:02 +08:00
|
|
|
#else
|
2008-09-05 11:09:13 +08:00
|
|
|
static inline int flag_is_changeable_p(u32 flag)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
2008-09-05 11:09:02 +08:00
|
|
|
/* Probe for the CPUID instruction */
|
|
|
|
static inline int have_cpuid_p(void)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
2008-09-05 11:09:13 +08:00
|
|
|
static inline void squash_the_stupid_serial_number(struct cpuinfo_x86 *c)
|
|
|
|
{
|
|
|
|
}
|
2008-09-05 11:09:02 +08:00
|
|
|
#endif
|
2008-09-05 03:09:47 +08:00
|
|
|
|
2009-01-24 09:20:50 +08:00
|
|
|
/*
|
|
|
|
* Some CPU features depend on higher CPUID levels, which may not always
|
|
|
|
* be available due to CPUID level capping or broken virtualization
|
|
|
|
* software. Add those features to this table to auto-disable them.
|
|
|
|
*/
|
|
|
|
struct cpuid_dependent_feature {
|
|
|
|
u32 feature;
|
|
|
|
u32 level;
|
|
|
|
};
|
2009-03-14 15:46:17 +08:00
|
|
|
|
2009-01-24 09:20:50 +08:00
|
|
|
static const struct cpuid_dependent_feature __cpuinitconst
|
|
|
|
cpuid_dependent_features[] = {
|
|
|
|
{ X86_FEATURE_MWAIT, 0x00000005 },
|
|
|
|
{ X86_FEATURE_DCA, 0x00000009 },
|
|
|
|
{ X86_FEATURE_XSAVE, 0x0000000d },
|
|
|
|
{ 0, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
static void __cpuinit filter_cpuid_features(struct cpuinfo_x86 *c, bool warn)
|
|
|
|
{
|
|
|
|
const struct cpuid_dependent_feature *df;
|
2009-03-14 13:49:49 +08:00
|
|
|
|
2009-01-24 09:20:50 +08:00
|
|
|
for (df = cpuid_dependent_features; df->feature; df++) {
|
2009-03-14 15:46:17 +08:00
|
|
|
|
|
|
|
if (!cpu_has(c, df->feature))
|
|
|
|
continue;
|
2009-01-24 09:20:50 +08:00
|
|
|
/*
|
|
|
|
* Note: cpuid_level is set to -1 if unavailable, but
|
|
|
|
* extended_extended_level is set to 0 if unavailable
|
|
|
|
* and the legitimate extended levels are all negative
|
|
|
|
* when signed; hence the weird messing around with
|
|
|
|
* signs here...
|
|
|
|
*/
|
2009-03-14 15:46:17 +08:00
|
|
|
if (!((s32)df->level < 0 ?
|
2009-02-15 15:59:18 +08:00
|
|
|
(u32)df->level > (u32)c->extended_cpuid_level :
|
2009-03-14 15:46:17 +08:00
|
|
|
(s32)df->level > (s32)c->cpuid_level))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
clear_cpu_cap(c, df->feature);
|
|
|
|
if (!warn)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
printk(KERN_WARNING
|
|
|
|
"CPU: CPU feature %s disabled, no CPUID level 0x%x\n",
|
|
|
|
x86_cap_flags[df->feature], df->level);
|
2009-01-24 09:20:50 +08:00
|
|
|
}
|
2009-02-15 15:59:18 +08:00
|
|
|
}
|
2009-01-24 09:20:50 +08:00
|
|
|
|
2008-09-05 11:09:13 +08:00
|
|
|
/*
|
|
|
|
* Naming convention should be: <Name> [(<Codename>)]
|
|
|
|
* This table only is used unless init_<vendor>() below doesn't set it;
|
2009-03-14 15:46:17 +08:00
|
|
|
* in particular, if CPUID levels 0x80000002..4 are supported, this
|
|
|
|
* isn't used
|
2008-09-05 11:09:13 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* Look up CPU names by table lookup. */
|
2009-03-12 20:08:49 +08:00
|
|
|
static const char *__cpuinit table_lookup_model(struct cpuinfo_x86 *c)
|
2008-09-05 11:09:13 +08:00
|
|
|
{
|
2009-03-12 20:08:49 +08:00
|
|
|
const struct cpu_model_info *info;
|
2008-09-05 11:09:13 +08:00
|
|
|
|
|
|
|
if (c->x86_model >= 16)
|
|
|
|
return NULL; /* Range check */
|
|
|
|
|
|
|
|
if (!this_cpu)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
info = this_cpu->c_models;
|
|
|
|
|
|
|
|
while (info && info->family) {
|
|
|
|
if (info->family == c->x86)
|
|
|
|
return info->model_names[c->x86_model];
|
|
|
|
info++;
|
|
|
|
}
|
|
|
|
return NULL; /* Not found */
|
|
|
|
}
|
|
|
|
|
2009-05-10 14:47:42 +08:00
|
|
|
__u32 cpu_caps_cleared[NCAPINTS] __cpuinitdata;
|
|
|
|
__u32 cpu_caps_set[NCAPINTS] __cpuinitdata;
|
2008-01-30 20:33:20 +08:00
|
|
|
|
2009-01-30 16:47:54 +08:00
|
|
|
void load_percpu_segment(int cpu)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_X86_32
|
|
|
|
loadsegment(fs, __KERNEL_PERCPU);
|
|
|
|
#else
|
|
|
|
loadsegment(gs, 0);
|
|
|
|
wrmsrl(MSR_GS_BASE, (unsigned long)per_cpu(irq_stack_union.gs_base, cpu));
|
|
|
|
#endif
|
2009-02-09 21:17:40 +08:00
|
|
|
load_stack_canary_segment();
|
2009-01-30 16:47:54 +08:00
|
|
|
}
|
|
|
|
|
2009-03-14 15:46:17 +08:00
|
|
|
/*
|
|
|
|
* Current gdt points %fs at the "master" per-cpu area: after this,
|
|
|
|
* it's on the real one.
|
|
|
|
*/
|
2009-01-30 16:47:53 +08:00
|
|
|
void switch_to_new_gdt(int cpu)
|
2008-09-05 03:09:44 +08:00
|
|
|
{
|
|
|
|
struct desc_ptr gdt_descr;
|
|
|
|
|
2009-01-27 11:56:48 +08:00
|
|
|
gdt_descr.address = (long)get_cpu_gdt_table(cpu);
|
2008-09-05 03:09:44 +08:00
|
|
|
gdt_descr.size = GDT_SIZE - 1;
|
|
|
|
load_gdt(&gdt_descr);
|
2009-01-27 11:56:48 +08:00
|
|
|
/* Reload the per-cpu base */
|
2009-01-30 16:47:54 +08:00
|
|
|
|
|
|
|
load_percpu_segment(cpu);
|
2008-09-05 03:09:44 +08:00
|
|
|
}
|
|
|
|
|
2009-03-12 20:08:49 +08:00
|
|
|
static const struct cpu_dev *__cpuinitdata cpu_devs[X86_VENDOR_NUM] = {};
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-02-24 18:58:13 +08:00
|
|
|
static void __cpuinit default_init(struct cpuinfo_x86 *c)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-09-05 11:09:06 +08:00
|
|
|
#ifdef CONFIG_X86_64
|
|
|
|
display_cacheinfo(c);
|
|
|
|
#else
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Not much we can do here... */
|
|
|
|
/* Check if at least it has cpuid */
|
|
|
|
if (c->cpuid_level == -1) {
|
|
|
|
/* No cpuid. It must be an ancient CPU */
|
|
|
|
if (c->x86 == 4)
|
|
|
|
strcpy(c->x86_model_id, "486");
|
|
|
|
else if (c->x86 == 3)
|
|
|
|
strcpy(c->x86_model_id, "386");
|
|
|
|
}
|
2008-09-05 11:09:06 +08:00
|
|
|
#endif
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2009-03-12 20:08:49 +08:00
|
|
|
static const struct cpu_dev __cpuinitconst default_cpu = {
|
2005-04-17 06:20:36 +08:00
|
|
|
.c_init = default_init,
|
2006-02-05 15:28:03 +08:00
|
|
|
.c_vendor = "Unknown",
|
2008-09-05 03:09:45 +08:00
|
|
|
.c_x86_vendor = X86_VENDOR_UNKNOWN,
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
2008-09-06 16:52:27 +08:00
|
|
|
static void __cpuinit get_model_name(struct cpuinfo_x86 *c)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
unsigned int *v;
|
|
|
|
char *p, *q;
|
|
|
|
|
2008-09-05 03:09:44 +08:00
|
|
|
if (c->extended_cpuid_level < 0x80000004)
|
2008-09-06 16:52:27 +08:00
|
|
|
return;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-03-14 15:46:17 +08:00
|
|
|
v = (unsigned int *)c->x86_model_id;
|
2005-04-17 06:20:36 +08:00
|
|
|
cpuid(0x80000002, &v[0], &v[1], &v[2], &v[3]);
|
|
|
|
cpuid(0x80000003, &v[4], &v[5], &v[6], &v[7]);
|
|
|
|
cpuid(0x80000004, &v[8], &v[9], &v[10], &v[11]);
|
|
|
|
c->x86_model_id[48] = 0;
|
|
|
|
|
2009-03-14 15:46:17 +08:00
|
|
|
/*
|
|
|
|
* Intel chips right-justify this string for some dumb reason;
|
|
|
|
* undo that brain damage:
|
|
|
|
*/
|
2005-04-17 06:20:36 +08:00
|
|
|
p = q = &c->x86_model_id[0];
|
2008-02-24 18:58:13 +08:00
|
|
|
while (*p == ' ')
|
2009-03-14 13:49:49 +08:00
|
|
|
p++;
|
2008-02-24 18:58:13 +08:00
|
|
|
if (p != q) {
|
2009-03-14 13:49:49 +08:00
|
|
|
while (*p)
|
|
|
|
*q++ = *p++;
|
|
|
|
while (q <= &c->x86_model_id[48])
|
|
|
|
*q++ = '\0'; /* Zero-pad the rest */
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-03-23 18:59:33 +08:00
|
|
|
void __cpuinit display_cacheinfo(struct cpuinfo_x86 *c)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-09-05 03:09:44 +08:00
|
|
|
unsigned int n, dummy, ebx, ecx, edx, l2size;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-09-05 03:09:44 +08:00
|
|
|
n = c->extended_cpuid_level;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (n >= 0x80000005) {
|
2008-09-05 03:09:44 +08:00
|
|
|
cpuid(0x80000005, &dummy, &ebx, &ecx, &edx);
|
2005-04-17 06:20:36 +08:00
|
|
|
printk(KERN_INFO "CPU: L1 I Cache: %dK (%d bytes/line), D cache %dK (%d bytes/line)\n",
|
2008-09-05 03:09:44 +08:00
|
|
|
edx>>24, edx&0xFF, ecx>>24, ecx&0xFF);
|
|
|
|
c->x86_cache_size = (ecx>>24) + (edx>>24);
|
2008-09-05 11:09:07 +08:00
|
|
|
#ifdef CONFIG_X86_64
|
|
|
|
/* On K8 L1 TLB is inclusive, so don't count it */
|
|
|
|
c->x86_tlbsize = 0;
|
|
|
|
#endif
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (n < 0x80000006) /* Some chips just has a large L1. */
|
|
|
|
return;
|
|
|
|
|
2008-09-05 03:09:47 +08:00
|
|
|
cpuid(0x80000006, &dummy, &ebx, &ecx, &edx);
|
2005-04-17 06:20:36 +08:00
|
|
|
l2size = ecx >> 16;
|
2008-02-24 18:58:13 +08:00
|
|
|
|
2008-09-05 11:09:07 +08:00
|
|
|
#ifdef CONFIG_X86_64
|
|
|
|
c->x86_tlbsize += ((ebx >> 16) & 0xfff) + (ebx & 0xfff);
|
|
|
|
#else
|
2005-04-17 06:20:36 +08:00
|
|
|
/* do processor-specific cache resizing */
|
|
|
|
if (this_cpu->c_size_cache)
|
2008-02-24 18:58:13 +08:00
|
|
|
l2size = this_cpu->c_size_cache(c, l2size);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Allow user to override all this if necessary. */
|
|
|
|
if (cachesize_override != -1)
|
|
|
|
l2size = cachesize_override;
|
|
|
|
|
2008-02-24 18:58:13 +08:00
|
|
|
if (l2size == 0)
|
2005-04-17 06:20:36 +08:00
|
|
|
return; /* Again, no L2 cache is possible */
|
2008-09-05 11:09:07 +08:00
|
|
|
#endif
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
c->x86_cache_size = l2size;
|
|
|
|
|
|
|
|
printk(KERN_INFO "CPU: L2 Cache: %dK (%d bytes/line)\n",
|
2008-09-05 03:09:47 +08:00
|
|
|
l2size, ecx & 0xFF);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2008-09-05 03:09:44 +08:00
|
|
|
void __cpuinit detect_ht(struct cpuinfo_x86 *c)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-09-05 11:08:59 +08:00
|
|
|
#ifdef CONFIG_X86_HT
|
2008-09-05 03:09:47 +08:00
|
|
|
u32 eax, ebx, ecx, edx;
|
|
|
|
int index_msb, core_bits;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-09-05 03:09:47 +08:00
|
|
|
if (!cpu_has(c, X86_FEATURE_HT))
|
2008-09-05 03:09:44 +08:00
|
|
|
return;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-09-05 03:09:47 +08:00
|
|
|
if (cpu_has(c, X86_FEATURE_CMP_LEGACY))
|
|
|
|
goto out;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-09-05 11:09:08 +08:00
|
|
|
if (cpu_has(c, X86_FEATURE_XTOPOLOGY))
|
|
|
|
return;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-09-05 03:09:47 +08:00
|
|
|
cpuid(1, &eax, &ebx, &ecx, &edx);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-09-05 03:09:44 +08:00
|
|
|
smp_num_siblings = (ebx & 0xff0000) >> 16;
|
|
|
|
|
|
|
|
if (smp_num_siblings == 1) {
|
|
|
|
printk(KERN_INFO "CPU: Hyper-Threading is disabled\n");
|
2009-03-14 15:46:17 +08:00
|
|
|
goto out;
|
|
|
|
}
|
2008-09-05 03:09:44 +08:00
|
|
|
|
2009-03-14 15:46:17 +08:00
|
|
|
if (smp_num_siblings <= 1)
|
|
|
|
goto out;
|
2008-09-05 03:09:44 +08:00
|
|
|
|
2009-03-14 15:46:17 +08:00
|
|
|
if (smp_num_siblings > nr_cpu_ids) {
|
|
|
|
pr_warning("CPU: Unsupported number of siblings %d",
|
|
|
|
smp_num_siblings);
|
|
|
|
smp_num_siblings = 1;
|
|
|
|
return;
|
|
|
|
}
|
2008-09-05 03:09:44 +08:00
|
|
|
|
2009-03-14 15:46:17 +08:00
|
|
|
index_msb = get_count_order(smp_num_siblings);
|
|
|
|
c->phys_proc_id = apic->phys_pkg_id(c->initial_apicid, index_msb);
|
2008-09-05 03:09:44 +08:00
|
|
|
|
2009-03-14 15:46:17 +08:00
|
|
|
smp_num_siblings = smp_num_siblings / c->x86_max_cores;
|
2008-09-05 03:09:44 +08:00
|
|
|
|
2009-03-14 15:46:17 +08:00
|
|
|
index_msb = get_count_order(smp_num_siblings);
|
2008-09-05 03:09:44 +08:00
|
|
|
|
2009-03-14 15:46:17 +08:00
|
|
|
core_bits = get_count_order(c->x86_max_cores);
|
2008-09-05 03:09:44 +08:00
|
|
|
|
2009-03-14 15:46:17 +08:00
|
|
|
c->cpu_core_id = apic->phys_pkg_id(c->initial_apicid, index_msb) &
|
|
|
|
((1 << core_bits) - 1);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-09-05 03:09:47 +08:00
|
|
|
out:
|
|
|
|
if ((c->x86_max_cores * smp_num_siblings) > 1) {
|
|
|
|
printk(KERN_INFO "CPU: Physical Processor ID: %d\n",
|
|
|
|
c->phys_proc_id);
|
|
|
|
printk(KERN_INFO "CPU: Processor Core ID: %d\n",
|
|
|
|
c->cpu_core_id);
|
2008-09-05 03:09:44 +08:00
|
|
|
}
|
|
|
|
#endif
|
2008-09-05 11:08:59 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-09-05 03:09:44 +08:00
|
|
|
static void __cpuinit get_cpu_vendor(struct cpuinfo_x86 *c)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
char *v = c->x86_vendor_id;
|
2009-03-14 15:46:17 +08:00
|
|
|
int i;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
for (i = 0; i < X86_VENDOR_NUM; i++) {
|
2008-09-05 03:09:45 +08:00
|
|
|
if (!cpu_devs[i])
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (!strcmp(v, cpu_devs[i]->c_ident[0]) ||
|
|
|
|
(cpu_devs[i]->c_ident[1] &&
|
|
|
|
!strcmp(v, cpu_devs[i]->c_ident[1]))) {
|
2009-03-14 15:46:17 +08:00
|
|
|
|
2008-09-05 03:09:45 +08:00
|
|
|
this_cpu = cpu_devs[i];
|
|
|
|
c->x86_vendor = this_cpu->c_x86_vendor;
|
|
|
|
return;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
2008-09-05 03:09:45 +08:00
|
|
|
|
2009-06-17 06:33:44 +08:00
|
|
|
printk_once(KERN_ERR
|
|
|
|
"CPU: vendor_id '%s' unknown, using generic init.\n" \
|
|
|
|
"CPU: Your system may be unstable.\n", v);
|
2008-09-05 03:09:45 +08:00
|
|
|
|
2006-02-05 15:28:03 +08:00
|
|
|
c->x86_vendor = X86_VENDOR_UNKNOWN;
|
|
|
|
this_cpu = &default_cpu;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2008-09-05 03:09:44 +08:00
|
|
|
void __cpuinit cpu_detect(struct cpuinfo_x86 *c)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
/* Get vendor name */
|
2008-02-02 00:49:43 +08:00
|
|
|
cpuid(0x00000000, (unsigned int *)&c->cpuid_level,
|
|
|
|
(unsigned int *)&c->x86_vendor_id[0],
|
|
|
|
(unsigned int *)&c->x86_vendor_id[8],
|
|
|
|
(unsigned int *)&c->x86_vendor_id[4]);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
c->x86 = 4;
|
2008-09-05 03:09:44 +08:00
|
|
|
/* Intel-defined flags: level 0x00000001 */
|
2005-04-17 06:20:36 +08:00
|
|
|
if (c->cpuid_level >= 0x00000001) {
|
|
|
|
u32 junk, tfms, cap0, misc;
|
2009-03-14 15:46:17 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
cpuid(0x00000001, &tfms, &misc, &junk, &cap0);
|
2008-09-05 03:09:44 +08:00
|
|
|
c->x86 = (tfms >> 8) & 0xf;
|
|
|
|
c->x86_model = (tfms >> 4) & 0xf;
|
|
|
|
c->x86_mask = tfms & 0xf;
|
2009-03-14 15:46:17 +08:00
|
|
|
|
2005-11-06 00:25:53 +08:00
|
|
|
if (c->x86 == 0xf)
|
2005-04-17 06:20:36 +08:00
|
|
|
c->x86 += (tfms >> 20) & 0xff;
|
2005-11-06 00:25:53 +08:00
|
|
|
if (c->x86 >= 0x6)
|
2008-09-05 03:09:44 +08:00
|
|
|
c->x86_model += ((tfms >> 16) & 0xf) << 4;
|
2009-03-14 15:46:17 +08:00
|
|
|
|
2008-02-01 05:05:45 +08:00
|
|
|
if (cap0 & (1<<19)) {
|
|
|
|
c->x86_clflush_size = ((misc >> 8) & 0xff) * 8;
|
2008-09-05 03:09:44 +08:00
|
|
|
c->x86_cache_alignment = c->x86_clflush_size;
|
2008-02-01 05:05:45 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
2008-09-05 03:09:44 +08:00
|
|
|
|
|
|
|
static void __cpuinit get_cpu_cap(struct cpuinfo_x86 *c)
|
2008-01-30 20:33:32 +08:00
|
|
|
{
|
|
|
|
u32 tfms, xlvl;
|
2008-09-05 03:09:44 +08:00
|
|
|
u32 ebx;
|
2008-01-30 20:33:32 +08:00
|
|
|
|
2008-09-05 03:09:44 +08:00
|
|
|
/* Intel-defined flags: level 0x00000001 */
|
|
|
|
if (c->cpuid_level >= 0x00000001) {
|
|
|
|
u32 capability, excap;
|
2009-03-14 15:46:17 +08:00
|
|
|
|
2008-09-05 03:09:44 +08:00
|
|
|
cpuid(0x00000001, &tfms, &ebx, &excap, &capability);
|
|
|
|
c->x86_capability[0] = capability;
|
|
|
|
c->x86_capability[4] = excap;
|
|
|
|
}
|
2008-01-30 20:33:32 +08:00
|
|
|
|
2008-09-05 03:09:44 +08:00
|
|
|
/* AMD-defined flags: level 0x80000001 */
|
|
|
|
xlvl = cpuid_eax(0x80000000);
|
|
|
|
c->extended_cpuid_level = xlvl;
|
2009-03-14 15:46:17 +08:00
|
|
|
|
2008-09-05 03:09:44 +08:00
|
|
|
if ((xlvl & 0xffff0000) == 0x80000000) {
|
|
|
|
if (xlvl >= 0x80000001) {
|
|
|
|
c->x86_capability[1] = cpuid_edx(0x80000001);
|
|
|
|
c->x86_capability[6] = cpuid_ecx(0x80000001);
|
2008-01-30 20:33:32 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-05 11:09:09 +08:00
|
|
|
if (c->extended_cpuid_level >= 0x80000008) {
|
|
|
|
u32 eax = cpuid_eax(0x80000008);
|
|
|
|
|
|
|
|
c->x86_virt_bits = (eax >> 8) & 0xff;
|
|
|
|
c->x86_phys_bits = eax & 0xff;
|
2008-01-30 20:33:32 +08:00
|
|
|
}
|
2009-03-12 20:37:34 +08:00
|
|
|
#ifdef CONFIG_X86_32
|
|
|
|
else if (cpu_has(c, X86_FEATURE_PAE) || cpu_has(c, X86_FEATURE_PSE36))
|
|
|
|
c->x86_phys_bits = 36;
|
2008-09-05 11:09:09 +08:00
|
|
|
#endif
|
2008-09-06 16:52:28 +08:00
|
|
|
|
|
|
|
if (c->extended_cpuid_level >= 0x80000007)
|
|
|
|
c->x86_power = cpuid_edx(0x80000007);
|
2008-01-30 20:33:32 +08:00
|
|
|
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-09-14 17:33:15 +08:00
|
|
|
static void __cpuinit identify_cpu_without_cpuid(struct cpuinfo_x86 *c)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_X86_32
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* First of all, decide if this is a 486 or higher
|
|
|
|
* It's a 486 if we can modify the AC flag
|
|
|
|
*/
|
|
|
|
if (flag_is_changeable_p(X86_EFLAGS_AC))
|
|
|
|
c->x86 = 4;
|
|
|
|
else
|
|
|
|
c->x86 = 3;
|
|
|
|
|
|
|
|
for (i = 0; i < X86_VENDOR_NUM; i++)
|
|
|
|
if (cpu_devs[i] && cpu_devs[i]->c_identify) {
|
|
|
|
c->x86_vendor_id[0] = 0;
|
|
|
|
cpu_devs[i]->c_identify(c);
|
|
|
|
if (c->x86_vendor_id[0]) {
|
|
|
|
get_cpu_vendor(c);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2008-02-24 18:58:13 +08:00
|
|
|
/*
|
|
|
|
* Do minimum CPU detection early.
|
|
|
|
* Fields really needed: vendor, cpuid_level, family, model, mask,
|
|
|
|
* cache alignment.
|
|
|
|
* The others are not touched to avoid unwanted side effects.
|
|
|
|
*
|
|
|
|
* WARNING: this function is only called on the BP. Don't add code here
|
|
|
|
* that is supposed to run on all CPUs.
|
|
|
|
*/
|
2008-09-05 03:09:44 +08:00
|
|
|
static void __init early_identify_cpu(struct cpuinfo_x86 *c)
|
2006-12-07 09:14:08 +08:00
|
|
|
{
|
2008-09-05 11:09:10 +08:00
|
|
|
#ifdef CONFIG_X86_64
|
|
|
|
c->x86_clflush_size = 64;
|
2009-03-12 20:37:34 +08:00
|
|
|
c->x86_phys_bits = 36;
|
|
|
|
c->x86_virt_bits = 48;
|
2008-09-05 11:09:10 +08:00
|
|
|
#else
|
2008-02-01 05:05:45 +08:00
|
|
|
c->x86_clflush_size = 32;
|
2009-03-12 20:37:34 +08:00
|
|
|
c->x86_phys_bits = 32;
|
|
|
|
c->x86_virt_bits = 32;
|
2008-09-05 11:09:10 +08:00
|
|
|
#endif
|
2008-09-05 03:09:47 +08:00
|
|
|
c->x86_cache_alignment = c->x86_clflush_size;
|
2006-12-07 09:14:08 +08:00
|
|
|
|
2008-09-05 03:09:44 +08:00
|
|
|
memset(&c->x86_capability, 0, sizeof c->x86_capability);
|
2008-09-05 03:09:47 +08:00
|
|
|
c->extended_cpuid_level = 0;
|
2006-12-07 09:14:08 +08:00
|
|
|
|
2008-09-14 17:33:15 +08:00
|
|
|
if (!have_cpuid_p())
|
|
|
|
identify_cpu_without_cpuid(c);
|
|
|
|
|
|
|
|
/* cyrix could have cpuid enabled via c_identify()*/
|
2006-12-07 09:14:08 +08:00
|
|
|
if (!have_cpuid_p())
|
|
|
|
return;
|
|
|
|
|
|
|
|
cpu_detect(c);
|
|
|
|
|
2008-09-05 03:09:44 +08:00
|
|
|
get_cpu_vendor(c);
|
2008-01-30 20:32:40 +08:00
|
|
|
|
2008-09-05 03:09:44 +08:00
|
|
|
get_cpu_cap(c);
|
2008-09-05 03:09:43 +08:00
|
|
|
|
2008-09-05 03:09:45 +08:00
|
|
|
if (this_cpu->c_early_init)
|
|
|
|
this_cpu->c_early_init(c);
|
2008-01-30 20:33:32 +08:00
|
|
|
|
2008-10-31 07:43:03 +08:00
|
|
|
#ifdef CONFIG_SMP
|
2008-10-31 05:13:37 +08:00
|
|
|
c->cpu_index = boot_cpu_id;
|
2008-10-31 07:43:03 +08:00
|
|
|
#endif
|
2009-01-24 09:20:50 +08:00
|
|
|
filter_cpuid_features(c, false);
|
2006-12-07 09:14:08 +08:00
|
|
|
}
|
|
|
|
|
2008-09-05 03:09:44 +08:00
|
|
|
void __init early_cpu_init(void)
|
|
|
|
{
|
2009-03-12 20:08:49 +08:00
|
|
|
const struct cpu_dev *const *cdev;
|
2008-09-05 03:09:45 +08:00
|
|
|
int count = 0;
|
|
|
|
|
2009-03-14 13:49:49 +08:00
|
|
|
printk(KERN_INFO "KERNEL supported cpus:\n");
|
2008-09-05 03:09:45 +08:00
|
|
|
for (cdev = __x86_cpu_dev_start; cdev < __x86_cpu_dev_end; cdev++) {
|
2009-03-12 20:08:49 +08:00
|
|
|
const struct cpu_dev *cpudev = *cdev;
|
2008-09-05 03:09:45 +08:00
|
|
|
unsigned int j;
|
2008-09-05 03:09:44 +08:00
|
|
|
|
2008-09-05 03:09:45 +08:00
|
|
|
if (count >= X86_VENDOR_NUM)
|
|
|
|
break;
|
|
|
|
cpu_devs[count] = cpudev;
|
|
|
|
count++;
|
|
|
|
|
|
|
|
for (j = 0; j < 2; j++) {
|
|
|
|
if (!cpudev->c_ident[j])
|
|
|
|
continue;
|
2009-03-14 13:49:49 +08:00
|
|
|
printk(KERN_INFO " %s %s\n", cpudev->c_vendor,
|
2008-09-05 03:09:45 +08:00
|
|
|
cpudev->c_ident[j]);
|
|
|
|
}
|
|
|
|
}
|
2008-09-05 03:09:44 +08:00
|
|
|
|
|
|
|
early_identify_cpu(&boot_cpu_data);
|
2006-12-07 09:14:08 +08:00
|
|
|
}
|
2008-01-30 20:33:32 +08:00
|
|
|
|
2008-08-19 08:39:32 +08:00
|
|
|
/*
|
|
|
|
* The NOPL instruction is supposed to exist on all CPUs with
|
2008-09-17 00:29:40 +08:00
|
|
|
* family >= 6; unfortunately, that's not true in practice because
|
2008-08-19 08:39:32 +08:00
|
|
|
* of early VIA chips and (more importantly) broken virtualizers that
|
2008-09-17 00:29:40 +08:00
|
|
|
* are not easy to detect. In the latter case it doesn't even *fail*
|
|
|
|
* reliably, so probing for it doesn't even work. Disable it completely
|
|
|
|
* unless we can find a reliable way to detect all the broken cases.
|
2008-08-19 08:39:32 +08:00
|
|
|
*/
|
|
|
|
static void __cpuinit detect_nopl(struct cpuinfo_x86 *c)
|
|
|
|
{
|
|
|
|
clear_cpu_cap(c, X86_FEATURE_NOPL);
|
2006-12-07 09:14:08 +08:00
|
|
|
}
|
|
|
|
|
2008-02-24 18:58:13 +08:00
|
|
|
static void __cpuinit generic_identify(struct cpuinfo_x86 *c)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-09-14 17:33:15 +08:00
|
|
|
c->extended_cpuid_level = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-09-05 03:09:44 +08:00
|
|
|
if (!have_cpuid_p())
|
2008-09-14 17:33:15 +08:00
|
|
|
identify_cpu_without_cpuid(c);
|
2007-07-12 03:18:32 +08:00
|
|
|
|
2008-09-14 17:33:15 +08:00
|
|
|
/* cyrix could have cpuid enabled via c_identify()*/
|
2008-09-14 20:46:58 +08:00
|
|
|
if (!have_cpuid_p())
|
2008-09-14 17:33:15 +08:00
|
|
|
return;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-09-05 03:09:44 +08:00
|
|
|
cpu_detect(c);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-09-05 03:09:44 +08:00
|
|
|
get_cpu_vendor(c);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-09-05 03:09:44 +08:00
|
|
|
get_cpu_cap(c);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-09-05 03:09:44 +08:00
|
|
|
if (c->cpuid_level >= 0x00000001) {
|
|
|
|
c->initial_apicid = (cpuid_ebx(1) >> 24) & 0xFF;
|
2008-09-05 11:09:12 +08:00
|
|
|
#ifdef CONFIG_X86_32
|
|
|
|
# ifdef CONFIG_X86_HT
|
2009-01-28 20:24:54 +08:00
|
|
|
c->apicid = apic->phys_pkg_id(c->initial_apicid, 0);
|
2008-09-05 11:09:12 +08:00
|
|
|
# else
|
2008-09-05 03:09:44 +08:00
|
|
|
c->apicid = c->initial_apicid;
|
2008-09-05 11:09:12 +08:00
|
|
|
# endif
|
|
|
|
#endif
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-09-05 11:09:12 +08:00
|
|
|
#ifdef CONFIG_X86_HT
|
|
|
|
c->phys_proc_id = c->initial_apicid;
|
2006-03-27 17:15:22 +08:00
|
|
|
#endif
|
2008-09-05 03:09:44 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-09-06 16:52:27 +08:00
|
|
|
get_model_name(c); /* Default name */
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-09-05 03:09:44 +08:00
|
|
|
init_scattered_cpuid_features(c);
|
|
|
|
detect_nopl(c);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This does the hard work of actually picking apart the CPU stuff...
|
|
|
|
*/
|
2008-06-21 18:24:00 +08:00
|
|
|
static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
c->loops_per_jiffy = loops_per_jiffy;
|
|
|
|
c->x86_cache_size = -1;
|
|
|
|
c->x86_vendor = X86_VENDOR_UNKNOWN;
|
|
|
|
c->x86_model = c->x86_mask = 0; /* So far unknown... */
|
|
|
|
c->x86_vendor_id[0] = '\0'; /* Unset */
|
|
|
|
c->x86_model_id[0] = '\0'; /* Unset */
|
2005-11-06 00:25:54 +08:00
|
|
|
c->x86_max_cores = 1;
|
2008-09-05 11:09:13 +08:00
|
|
|
c->x86_coreid_bits = 0;
|
2008-09-08 08:58:50 +08:00
|
|
|
#ifdef CONFIG_X86_64
|
2008-09-05 11:09:13 +08:00
|
|
|
c->x86_clflush_size = 64;
|
2009-03-12 20:37:34 +08:00
|
|
|
c->x86_phys_bits = 36;
|
|
|
|
c->x86_virt_bits = 48;
|
2008-09-05 11:09:13 +08:00
|
|
|
#else
|
|
|
|
c->cpuid_level = -1; /* CPUID not detected */
|
2006-12-07 09:14:05 +08:00
|
|
|
c->x86_clflush_size = 32;
|
2009-03-12 20:37:34 +08:00
|
|
|
c->x86_phys_bits = 32;
|
|
|
|
c->x86_virt_bits = 32;
|
2008-09-05 11:09:13 +08:00
|
|
|
#endif
|
|
|
|
c->x86_cache_alignment = c->x86_clflush_size;
|
2005-04-17 06:20:36 +08:00
|
|
|
memset(&c->x86_capability, 0, sizeof c->x86_capability);
|
|
|
|
|
|
|
|
generic_identify(c);
|
|
|
|
|
2008-01-30 20:32:49 +08:00
|
|
|
if (this_cpu->c_identify)
|
2005-04-17 06:20:36 +08:00
|
|
|
this_cpu->c_identify(c);
|
|
|
|
|
2009-05-16 04:05:16 +08:00
|
|
|
/* Clear/Set all flags overriden by options, after probe */
|
|
|
|
for (i = 0; i < NCAPINTS; i++) {
|
|
|
|
c->x86_capability[i] &= ~cpu_caps_cleared[i];
|
|
|
|
c->x86_capability[i] |= cpu_caps_set[i];
|
|
|
|
}
|
|
|
|
|
2008-09-05 11:09:13 +08:00
|
|
|
#ifdef CONFIG_X86_64
|
2009-01-28 20:24:54 +08:00
|
|
|
c->apicid = apic->phys_pkg_id(c->initial_apicid, 0);
|
2008-09-05 11:09:13 +08:00
|
|
|
#endif
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Vendor-specific initialization. In this section we
|
|
|
|
* canonicalize the feature flags, meaning if there are
|
|
|
|
* features a certain CPU supports which CPUID doesn't
|
|
|
|
* tell us, CPUID claiming incorrect flags, or other bugs,
|
|
|
|
* we handle them here.
|
|
|
|
*
|
|
|
|
* At the end of this section, c->x86_capability better
|
|
|
|
* indicate the features this CPU genuinely supports!
|
|
|
|
*/
|
|
|
|
if (this_cpu->c_init)
|
|
|
|
this_cpu->c_init(c);
|
|
|
|
|
|
|
|
/* Disable the PN if appropriate */
|
|
|
|
squash_the_stupid_serial_number(c);
|
|
|
|
|
|
|
|
/*
|
2009-03-14 15:46:17 +08:00
|
|
|
* The vendor-specific functions might have changed features.
|
|
|
|
* Now we do "generic changes."
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
|
2009-01-24 09:20:50 +08:00
|
|
|
/* Filter out anything that depends on CPUID levels we don't have */
|
|
|
|
filter_cpuid_features(c, true);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* If the model name is still unset, do table lookup. */
|
2008-02-24 18:58:13 +08:00
|
|
|
if (!c->x86_model_id[0]) {
|
2009-03-12 20:08:49 +08:00
|
|
|
const char *p;
|
2005-04-17 06:20:36 +08:00
|
|
|
p = table_lookup_model(c);
|
2008-02-24 18:58:13 +08:00
|
|
|
if (p)
|
2005-04-17 06:20:36 +08:00
|
|
|
strcpy(c->x86_model_id, p);
|
|
|
|
else
|
|
|
|
/* Last resort... */
|
|
|
|
sprintf(c->x86_model_id, "%02x/%02x",
|
2006-03-23 18:59:36 +08:00
|
|
|
c->x86, c->x86_model);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2008-09-05 11:09:13 +08:00
|
|
|
#ifdef CONFIG_X86_64
|
|
|
|
detect_ht(c);
|
|
|
|
#endif
|
|
|
|
|
2008-10-28 01:41:46 +08:00
|
|
|
init_hypervisor(c);
|
2009-05-10 14:47:42 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Clear/Set all flags overriden by options, need do it
|
|
|
|
* before following smp all cpus cap AND.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < NCAPINTS; i++) {
|
|
|
|
c->x86_capability[i] &= ~cpu_caps_cleared[i];
|
|
|
|
c->x86_capability[i] |= cpu_caps_set[i];
|
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* On SMP, boot_cpu_data holds the common feature set between
|
|
|
|
* all CPUs; so make sure that we indicate which features are
|
|
|
|
* common between the CPUs. The first time this routine gets
|
|
|
|
* executed, c == &boot_cpu_data.
|
|
|
|
*/
|
2008-02-24 18:58:13 +08:00
|
|
|
if (c != &boot_cpu_data) {
|
2005-04-17 06:20:36 +08:00
|
|
|
/* AND the already accumulated flags with these */
|
2008-09-05 03:09:44 +08:00
|
|
|
for (i = 0; i < NCAPINTS; i++)
|
2005-04-17 06:20:36 +08:00
|
|
|
boot_cpu_data.x86_capability[i] &= c->x86_capability[i];
|
|
|
|
}
|
|
|
|
|
2008-09-05 11:09:13 +08:00
|
|
|
#ifdef CONFIG_X86_MCE
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Init Machine Check Exception if available. */
|
|
|
|
mcheck_init(c);
|
2008-09-05 11:09:13 +08:00
|
|
|
#endif
|
2008-01-30 20:33:16 +08:00
|
|
|
|
|
|
|
select_idle_routine(c);
|
2008-09-05 11:09:13 +08:00
|
|
|
|
|
|
|
#if defined(CONFIG_NUMA) && defined(CONFIG_X86_64)
|
|
|
|
numa_add_cpu(smp_processor_id());
|
|
|
|
#endif
|
2007-05-03 01:27:12 +08:00
|
|
|
}
|
2005-11-07 16:58:42 +08:00
|
|
|
|
2008-09-23 01:35:08 +08:00
|
|
|
#ifdef CONFIG_X86_64
|
|
|
|
static void vgetcpu_set_mode(void)
|
|
|
|
{
|
|
|
|
if (cpu_has(&boot_cpu_data, X86_FEATURE_RDTSCP))
|
|
|
|
vgetcpu_mode = VGETCPU_RDTSCP;
|
|
|
|
else
|
|
|
|
vgetcpu_mode = VGETCPU_LSL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-05-03 01:27:12 +08:00
|
|
|
void __init identify_boot_cpu(void)
|
|
|
|
{
|
|
|
|
identify_cpu(&boot_cpu_data);
|
2009-03-17 12:20:34 +08:00
|
|
|
init_c1e_mask();
|
2008-09-05 11:09:13 +08:00
|
|
|
#ifdef CONFIG_X86_32
|
2007-05-03 01:27:12 +08:00
|
|
|
sysenter_setup();
|
2005-06-26 05:54:53 +08:00
|
|
|
enable_sep_cpu();
|
2008-09-23 01:35:08 +08:00
|
|
|
#else
|
|
|
|
vgetcpu_set_mode();
|
2008-09-05 11:09:13 +08:00
|
|
|
#endif
|
2008-12-03 17:39:53 +08:00
|
|
|
init_hw_perf_counters();
|
2007-05-03 01:27:12 +08:00
|
|
|
}
|
2005-07-08 08:56:38 +08:00
|
|
|
|
2007-05-03 01:27:12 +08:00
|
|
|
void __cpuinit identify_secondary_cpu(struct cpuinfo_x86 *c)
|
|
|
|
{
|
|
|
|
BUG_ON(c == &boot_cpu_data);
|
|
|
|
identify_cpu(c);
|
2008-09-05 11:09:13 +08:00
|
|
|
#ifdef CONFIG_X86_32
|
2007-05-03 01:27:12 +08:00
|
|
|
enable_sep_cpu();
|
2008-09-05 11:09:13 +08:00
|
|
|
#endif
|
2007-05-03 01:27:12 +08:00
|
|
|
mtrr_ap_init();
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2008-09-05 03:09:46 +08:00
|
|
|
struct msr_range {
|
2009-03-14 15:46:17 +08:00
|
|
|
unsigned min;
|
|
|
|
unsigned max;
|
2008-09-05 03:09:46 +08:00
|
|
|
};
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-03-12 20:08:49 +08:00
|
|
|
static const struct msr_range msr_range_array[] __cpuinitconst = {
|
2008-09-05 03:09:46 +08:00
|
|
|
{ 0x00000000, 0x00000418},
|
|
|
|
{ 0xc0000000, 0xc000040b},
|
|
|
|
{ 0xc0010000, 0xc0010142},
|
|
|
|
{ 0xc0011000, 0xc001103b},
|
|
|
|
};
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-09-05 03:09:46 +08:00
|
|
|
static void __cpuinit print_cpu_msr(void)
|
|
|
|
{
|
2009-03-14 15:46:17 +08:00
|
|
|
unsigned index_min, index_max;
|
2008-09-05 03:09:46 +08:00
|
|
|
unsigned index;
|
|
|
|
u64 val;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(msr_range_array); i++) {
|
|
|
|
index_min = msr_range_array[i].min;
|
|
|
|
index_max = msr_range_array[i].max;
|
2009-03-14 15:46:17 +08:00
|
|
|
|
2008-09-05 03:09:46 +08:00
|
|
|
for (index = index_min; index < index_max; index++) {
|
|
|
|
if (rdmsrl_amd_safe(index, &val))
|
|
|
|
continue;
|
|
|
|
printk(KERN_INFO " MSR%08x: %016llx\n", index, val);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2008-09-05 03:09:46 +08:00
|
|
|
}
|
|
|
|
}
|
2005-11-06 00:25:54 +08:00
|
|
|
|
2008-09-05 03:09:46 +08:00
|
|
|
static int show_msr __cpuinitdata;
|
2009-03-14 15:46:17 +08:00
|
|
|
|
2008-09-05 03:09:46 +08:00
|
|
|
static __init int setup_show_msr(char *arg)
|
|
|
|
{
|
|
|
|
int num;
|
2005-04-17 06:25:15 +08:00
|
|
|
|
2008-09-05 03:09:46 +08:00
|
|
|
get_option(&arg, &num);
|
2005-04-17 06:25:15 +08:00
|
|
|
|
2008-09-05 03:09:46 +08:00
|
|
|
if (num > 0)
|
|
|
|
show_msr = num;
|
|
|
|
return 1;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2008-09-05 03:09:46 +08:00
|
|
|
__setup("show_msr=", setup_show_msr);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-01-30 20:33:21 +08:00
|
|
|
static __init int setup_noclflush(char *arg)
|
|
|
|
{
|
|
|
|
setup_clear_cpu_cap(X86_FEATURE_CLFLSH);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
__setup("noclflush", setup_noclflush);
|
|
|
|
|
2006-03-23 18:59:33 +08:00
|
|
|
void __cpuinit print_cpu_info(struct cpuinfo_x86 *c)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2009-03-12 20:08:49 +08:00
|
|
|
const char *vendor = NULL;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-03-14 15:46:17 +08:00
|
|
|
if (c->x86_vendor < X86_VENDOR_NUM) {
|
2005-04-17 06:20:36 +08:00
|
|
|
vendor = this_cpu->c_vendor;
|
2009-03-14 15:46:17 +08:00
|
|
|
} else {
|
|
|
|
if (c->cpuid_level >= 0)
|
|
|
|
vendor = c->x86_vendor_id;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-09-20 09:41:16 +08:00
|
|
|
if (vendor && !strstr(c->x86_model_id, vendor))
|
2008-09-05 03:09:44 +08:00
|
|
|
printk(KERN_CONT "%s ", vendor);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-09-05 03:09:44 +08:00
|
|
|
if (c->x86_model_id[0])
|
|
|
|
printk(KERN_CONT "%s", c->x86_model_id);
|
2005-04-17 06:20:36 +08:00
|
|
|
else
|
2008-09-05 03:09:44 +08:00
|
|
|
printk(KERN_CONT "%d86", c->x86);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-02-24 18:58:13 +08:00
|
|
|
if (c->x86_mask || c->cpuid_level >= 0)
|
2008-09-05 03:09:44 +08:00
|
|
|
printk(KERN_CONT " stepping %02x\n", c->x86_mask);
|
2005-04-17 06:20:36 +08:00
|
|
|
else
|
2008-09-05 03:09:44 +08:00
|
|
|
printk(KERN_CONT "\n");
|
2008-09-05 03:09:46 +08:00
|
|
|
|
|
|
|
#ifdef CONFIG_SMP
|
|
|
|
if (c->cpu_index < show_msr)
|
|
|
|
print_cpu_msr();
|
|
|
|
#else
|
|
|
|
if (show_msr)
|
|
|
|
print_cpu_msr();
|
|
|
|
#endif
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2008-01-30 20:33:21 +08:00
|
|
|
static __init int setup_disablecpuid(char *arg)
|
|
|
|
{
|
|
|
|
int bit;
|
2009-03-14 15:46:17 +08:00
|
|
|
|
2008-01-30 20:33:21 +08:00
|
|
|
if (get_option(&arg, &bit) && bit < NCAPINTS*32)
|
|
|
|
setup_clear_cpu_cap(bit);
|
|
|
|
else
|
|
|
|
return 0;
|
2009-03-14 15:46:17 +08:00
|
|
|
|
2008-01-30 20:33:21 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
__setup("clearcpuid=", setup_disablecpuid);
|
|
|
|
|
2008-09-05 11:09:03 +08:00
|
|
|
#ifdef CONFIG_X86_64
|
|
|
|
struct desc_ptr idt_descr = { 256 * 16 - 1, (unsigned long) idt_table };
|
|
|
|
|
2009-01-19 11:21:28 +08:00
|
|
|
DEFINE_PER_CPU_FIRST(union irq_stack_union,
|
|
|
|
irq_stack_union) __aligned(PAGE_SIZE);
|
2009-03-14 15:46:17 +08:00
|
|
|
|
2009-01-18 23:38:58 +08:00
|
|
|
DEFINE_PER_CPU(char *, irq_stack_ptr) =
|
2009-02-08 22:58:39 +08:00
|
|
|
init_per_cpu_var(irq_stack_union.irq_stack) + IRQ_STACK_SIZE - 64;
|
2008-09-05 11:09:03 +08:00
|
|
|
|
2009-01-18 23:38:58 +08:00
|
|
|
DEFINE_PER_CPU(unsigned long, kernel_stack) =
|
|
|
|
(unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
|
|
|
|
EXPORT_PER_CPU_SYMBOL(kernel_stack);
|
|
|
|
|
2009-01-18 23:38:58 +08:00
|
|
|
DEFINE_PER_CPU(unsigned int, irq_count) = -1;
|
2008-09-05 11:09:03 +08:00
|
|
|
|
2009-03-14 15:46:17 +08:00
|
|
|
/*
|
|
|
|
* Special IST stacks which the CPU switches to when it calls
|
|
|
|
* an IST-marked descriptor entry. Up to 7 stacks (hardware
|
|
|
|
* limit), all of them are 4K, except the debug stack which
|
|
|
|
* is 8K.
|
|
|
|
*/
|
|
|
|
static const unsigned int exception_stack_sizes[N_EXCEPTION_STACKS] = {
|
|
|
|
[0 ... N_EXCEPTION_STACKS - 1] = EXCEPTION_STKSZ,
|
|
|
|
[DEBUG_STACK - 1] = DEBUG_STKSZ
|
|
|
|
};
|
|
|
|
|
2009-01-18 23:38:58 +08:00
|
|
|
static DEFINE_PER_CPU_PAGE_ALIGNED(char, exception_stacks
|
|
|
|
[(N_EXCEPTION_STACKS - 1) * EXCEPTION_STKSZ + DEBUG_STKSZ])
|
|
|
|
__aligned(PAGE_SIZE);
|
2008-09-05 11:09:03 +08:00
|
|
|
|
|
|
|
/* May not be marked __init: used by software suspend */
|
|
|
|
void syscall_init(void)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-09-05 11:09:03 +08:00
|
|
|
/*
|
|
|
|
* LSTAR and STAR live in a bit strange symbiosis.
|
|
|
|
* They both write to the same internal register. STAR allows to
|
|
|
|
* set CS/DS but only a 32bit target. LSTAR sets the 64bit rip.
|
|
|
|
*/
|
|
|
|
wrmsrl(MSR_STAR, ((u64)__USER32_CS)<<48 | ((u64)__KERNEL_CS)<<32);
|
|
|
|
wrmsrl(MSR_LSTAR, system_call);
|
|
|
|
wrmsrl(MSR_CSTAR, ignore_sysret);
|
x86: use ELF section to list CPU vendor specific code
Replace the hardcoded list of initialization functions for each CPU
vendor by a list in an ELF section, which is read at initialization in
arch/x86/kernel/cpu/cpu.c to fill the cpu_devs[] array. The ELF
section, named .x86cpuvendor.init, is reclaimed after boot, and
contains entries of type "struct cpu_vendor_dev" which associates a
vendor number with a pointer to a "struct cpu_dev" structure.
This first modification allows to remove all the VENDOR_init_cpu()
functions.
This patch also removes the hardcoded calls to early_init_amd() and
early_init_intel(). Instead, we add a "c_early_init" member to the
cpu_dev structure, which is then called if not NULL by the generic CPU
initialization code. Unfortunately, in early_cpu_detect(), this_cpu is
not yet set, so we have to use the cpu_devs[] array directly.
This patch is part of the Linux Tiny project, and is needed for
further patch that will allow to disable compilation of unused CPU
support code.
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
2008-02-15 19:00:23 +08:00
|
|
|
|
2008-09-05 11:09:03 +08:00
|
|
|
#ifdef CONFIG_IA32_EMULATION
|
|
|
|
syscall32_cpu_init();
|
|
|
|
#endif
|
x86: use ELF section to list CPU vendor specific code
Replace the hardcoded list of initialization functions for each CPU
vendor by a list in an ELF section, which is read at initialization in
arch/x86/kernel/cpu/cpu.c to fill the cpu_devs[] array. The ELF
section, named .x86cpuvendor.init, is reclaimed after boot, and
contains entries of type "struct cpu_vendor_dev" which associates a
vendor number with a pointer to a "struct cpu_dev" structure.
This first modification allows to remove all the VENDOR_init_cpu()
functions.
This patch also removes the hardcoded calls to early_init_amd() and
early_init_intel(). Instead, we add a "c_early_init" member to the
cpu_dev structure, which is then called if not NULL by the generic CPU
initialization code. Unfortunately, in early_cpu_detect(), this_cpu is
not yet set, so we have to use the cpu_devs[] array directly.
This patch is part of the Linux Tiny project, and is needed for
further patch that will allow to disable compilation of unused CPU
support code.
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
2008-02-15 19:00:23 +08:00
|
|
|
|
2008-09-05 11:09:03 +08:00
|
|
|
/* Flags to clear on syscall */
|
|
|
|
wrmsrl(MSR_SYSCALL_MASK,
|
|
|
|
X86_EFLAGS_TF|X86_EFLAGS_DF|X86_EFLAGS_IF|X86_EFLAGS_IOPL);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2006-12-07 09:14:02 +08:00
|
|
|
|
2008-09-05 11:09:03 +08:00
|
|
|
unsigned long kernel_eflags;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copies of the original ist values from the tss are only accessed during
|
|
|
|
* debugging, no special alignment required.
|
|
|
|
*/
|
|
|
|
DEFINE_PER_CPU(struct orig_ist, orig_ist);
|
|
|
|
|
2009-03-14 15:46:17 +08:00
|
|
|
#else /* CONFIG_X86_64 */
|
2008-09-05 11:09:03 +08:00
|
|
|
|
2009-02-09 21:17:40 +08:00
|
|
|
#ifdef CONFIG_CC_STACKPROTECTOR
|
|
|
|
DEFINE_PER_CPU(unsigned long, stack_canary);
|
|
|
|
#endif
|
2008-09-05 11:09:03 +08:00
|
|
|
|
2009-02-09 21:17:40 +08:00
|
|
|
/* Make sure %fs and %gs are initialized properly in idle threads */
|
2008-02-06 17:37:55 +08:00
|
|
|
struct pt_regs * __cpuinit idle_regs(struct pt_regs *regs)
|
[PATCH] i386: Use %gs as the PDA base-segment in the kernel
This patch is the meat of the PDA change. This patch makes several related
changes:
1: Most significantly, %gs is now used in the kernel. This means that on
entry, the old value of %gs is saved away, and it is reloaded with
__KERNEL_PDA.
2: entry.S constructs the stack in the shape of struct pt_regs, and this
is passed around the kernel so that the process's saved register
state can be accessed.
Unfortunately struct pt_regs doesn't currently have space for %gs
(or %fs). This patch extends pt_regs to add space for gs (no space
is allocated for %fs, since it won't be used, and it would just
complicate the code in entry.S to work around the space).
3: Because %gs is now saved on the stack like %ds, %es and the integer
registers, there are a number of places where it no longer needs to
be handled specially; namely context switch, and saving/restoring the
register state in a signal context.
4: And since kernel threads run in kernel space and call normal kernel
code, they need to be created with their %gs == __KERNEL_PDA.
Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Signed-off-by: Andi Kleen <ak@suse.de>
Cc: Chuck Ebbert <76306.1226@compuserve.com>
Cc: Zachary Amsden <zach@vmware.com>
Cc: Jan Beulich <jbeulich@novell.com>
Cc: Andi Kleen <ak@suse.de>
Signed-off-by: Andrew Morton <akpm@osdl.org>
2006-12-07 09:14:02 +08:00
|
|
|
{
|
|
|
|
memset(regs, 0, sizeof(struct pt_regs));
|
2008-01-30 20:30:56 +08:00
|
|
|
regs->fs = __KERNEL_PERCPU;
|
2009-02-09 21:17:40 +08:00
|
|
|
regs->gs = __KERNEL_STACK_CANARY;
|
2009-03-14 15:46:17 +08:00
|
|
|
|
[PATCH] i386: Use %gs as the PDA base-segment in the kernel
This patch is the meat of the PDA change. This patch makes several related
changes:
1: Most significantly, %gs is now used in the kernel. This means that on
entry, the old value of %gs is saved away, and it is reloaded with
__KERNEL_PDA.
2: entry.S constructs the stack in the shape of struct pt_regs, and this
is passed around the kernel so that the process's saved register
state can be accessed.
Unfortunately struct pt_regs doesn't currently have space for %gs
(or %fs). This patch extends pt_regs to add space for gs (no space
is allocated for %fs, since it won't be used, and it would just
complicate the code in entry.S to work around the space).
3: Because %gs is now saved on the stack like %ds, %es and the integer
registers, there are a number of places where it no longer needs to
be handled specially; namely context switch, and saving/restoring the
register state in a signal context.
4: And since kernel threads run in kernel space and call normal kernel
code, they need to be created with their %gs == __KERNEL_PDA.
Signed-off-by: Jeremy Fitzhardinge <jeremy@xensource.com>
Signed-off-by: Andi Kleen <ak@suse.de>
Cc: Chuck Ebbert <76306.1226@compuserve.com>
Cc: Zachary Amsden <zach@vmware.com>
Cc: Jan Beulich <jbeulich@novell.com>
Cc: Andi Kleen <ak@suse.de>
Signed-off-by: Andrew Morton <akpm@osdl.org>
2006-12-07 09:14:02 +08:00
|
|
|
return regs;
|
|
|
|
}
|
2009-03-14 15:46:17 +08:00
|
|
|
#endif /* CONFIG_X86_64 */
|
2007-05-03 01:27:16 +08:00
|
|
|
|
2009-03-14 13:49:49 +08:00
|
|
|
/*
|
|
|
|
* Clear all 6 debug registers:
|
|
|
|
*/
|
|
|
|
static void clear_all_debug_regs(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < 8; i++) {
|
|
|
|
/* Ignore db4, db5 */
|
|
|
|
if ((i == 4) || (i == 5))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
set_debugreg(0, i);
|
|
|
|
}
|
|
|
|
}
|
2007-05-03 01:27:16 +08:00
|
|
|
|
2007-05-03 01:27:10 +08:00
|
|
|
/*
|
|
|
|
* cpu_init() initializes state that is per-CPU. Some data is already
|
|
|
|
* initialized (naturally) in the bootstrap process, such as the GDT
|
|
|
|
* and IDT. We reload them nevertheless, this function acts as a
|
|
|
|
* 'CPU state barrier', nothing should get across.
|
2008-09-05 11:09:04 +08:00
|
|
|
* A lot of state is already set up in PDA init for 64 bit
|
2007-05-03 01:27:10 +08:00
|
|
|
*/
|
2008-09-05 11:09:04 +08:00
|
|
|
#ifdef CONFIG_X86_64
|
2009-03-14 15:46:17 +08:00
|
|
|
|
2008-09-05 11:09:04 +08:00
|
|
|
void __cpuinit cpu_init(void)
|
|
|
|
{
|
2009-03-14 15:46:17 +08:00
|
|
|
struct orig_ist *orig_ist;
|
2008-09-05 11:09:04 +08:00
|
|
|
struct task_struct *me;
|
2009-03-14 15:46:17 +08:00
|
|
|
struct tss_struct *t;
|
|
|
|
unsigned long v;
|
|
|
|
int cpu;
|
2008-09-05 11:09:04 +08:00
|
|
|
int i;
|
|
|
|
|
2009-03-14 15:46:17 +08:00
|
|
|
cpu = stack_smp_processor_id();
|
|
|
|
t = &per_cpu(init_tss, cpu);
|
|
|
|
orig_ist = &per_cpu(orig_ist, cpu);
|
|
|
|
|
2009-01-18 23:38:59 +08:00
|
|
|
#ifdef CONFIG_NUMA
|
|
|
|
if (cpu != 0 && percpu_read(node_number) == 0 &&
|
|
|
|
cpu_to_node(cpu) != NUMA_NO_NODE)
|
|
|
|
percpu_write(node_number, cpu_to_node(cpu));
|
|
|
|
#endif
|
2008-09-05 11:09:04 +08:00
|
|
|
|
|
|
|
me = current;
|
|
|
|
|
2009-01-04 21:18:03 +08:00
|
|
|
if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask))
|
2008-09-05 11:09:04 +08:00
|
|
|
panic("CPU#%d already initialized!\n", cpu);
|
|
|
|
|
|
|
|
printk(KERN_INFO "Initializing CPU#%d\n", cpu);
|
|
|
|
|
|
|
|
clear_in_cr4(X86_CR4_VME|X86_CR4_PVI|X86_CR4_TSD|X86_CR4_DE);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize the per-CPU GDT with the boot GDT,
|
|
|
|
* and set up the GDT descriptor:
|
|
|
|
*/
|
|
|
|
|
2009-01-30 16:47:53 +08:00
|
|
|
switch_to_new_gdt(cpu);
|
2009-01-27 11:56:48 +08:00
|
|
|
loadsegment(fs, 0);
|
|
|
|
|
2008-09-05 11:09:04 +08:00
|
|
|
load_idt((const struct desc_ptr *)&idt_descr);
|
|
|
|
|
|
|
|
memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
|
|
|
|
syscall_init();
|
|
|
|
|
|
|
|
wrmsrl(MSR_FS_BASE, 0);
|
|
|
|
wrmsrl(MSR_KERNEL_GS_BASE, 0);
|
|
|
|
barrier();
|
|
|
|
|
|
|
|
check_efer();
|
2009-02-17 09:29:58 +08:00
|
|
|
if (cpu != 0)
|
2008-09-05 11:09:04 +08:00
|
|
|
enable_x2apic();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* set up and load the per-CPU TSS
|
|
|
|
*/
|
|
|
|
if (!orig_ist->ist[0]) {
|
2009-01-18 23:38:58 +08:00
|
|
|
char *estacks = per_cpu(exception_stacks, cpu);
|
2009-03-14 15:46:17 +08:00
|
|
|
|
2008-09-05 11:09:04 +08:00
|
|
|
for (v = 0; v < N_EXCEPTION_STACKS; v++) {
|
2009-03-14 15:46:17 +08:00
|
|
|
estacks += exception_stack_sizes[v];
|
2008-09-05 11:09:04 +08:00
|
|
|
orig_ist->ist[v] = t->x86_tss.ist[v] =
|
|
|
|
(unsigned long)estacks;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
t->x86_tss.io_bitmap_base = offsetof(struct tss_struct, io_bitmap);
|
2009-03-14 15:46:17 +08:00
|
|
|
|
2008-09-05 11:09:04 +08:00
|
|
|
/*
|
|
|
|
* <= is required because the CPU will access up to
|
|
|
|
* 8 bits beyond the end of the IO permission bitmap.
|
|
|
|
*/
|
|
|
|
for (i = 0; i <= IO_BITMAP_LONGS; i++)
|
|
|
|
t->io_bitmap[i] = ~0UL;
|
|
|
|
|
|
|
|
atomic_inc(&init_mm.mm_count);
|
|
|
|
me->active_mm = &init_mm;
|
2009-03-10 13:10:32 +08:00
|
|
|
BUG_ON(me->mm);
|
2008-09-05 11:09:04 +08:00
|
|
|
enter_lazy_tlb(&init_mm, me);
|
|
|
|
|
|
|
|
load_sp0(t, ¤t->thread);
|
|
|
|
set_tss_desc(cpu, t);
|
|
|
|
load_TR_desc();
|
|
|
|
load_LDT(&init_mm.context);
|
|
|
|
|
|
|
|
#ifdef CONFIG_KGDB
|
|
|
|
/*
|
|
|
|
* If the kgdb is connected no debug regs should be altered. This
|
|
|
|
* is only applicable when KGDB and a KGDB I/O module are built
|
|
|
|
* into the kernel and you are using early debugging with
|
|
|
|
* kgdbwait. KGDB will control the kernel HW breakpoint registers.
|
|
|
|
*/
|
|
|
|
if (kgdb_connected && arch_kgdb_ops.correct_hw_break)
|
|
|
|
arch_kgdb_ops.correct_hw_break();
|
2009-01-28 04:41:34 +08:00
|
|
|
else
|
2008-09-05 11:09:04 +08:00
|
|
|
#endif
|
2009-03-14 13:49:49 +08:00
|
|
|
clear_all_debug_regs();
|
2008-09-05 11:09:04 +08:00
|
|
|
|
|
|
|
fpu_init();
|
|
|
|
|
|
|
|
raw_local_save_flags(kernel_eflags);
|
|
|
|
|
|
|
|
if (is_uv_system())
|
|
|
|
uv_cpu_init();
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2007-05-03 01:27:10 +08:00
|
|
|
void __cpuinit cpu_init(void)
|
2007-01-22 23:18:31 +08:00
|
|
|
{
|
2007-05-03 01:27:10 +08:00
|
|
|
int cpu = smp_processor_id();
|
|
|
|
struct task_struct *curr = current;
|
2008-02-24 18:58:13 +08:00
|
|
|
struct tss_struct *t = &per_cpu(init_tss, cpu);
|
2007-01-22 23:18:31 +08:00
|
|
|
struct thread_struct *thread = &curr->thread;
|
2006-12-07 09:14:02 +08:00
|
|
|
|
2009-01-04 21:18:03 +08:00
|
|
|
if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
|
2006-12-07 09:14:02 +08:00
|
|
|
printk(KERN_WARNING "CPU#%d already initialized!\n", cpu);
|
2009-03-14 13:49:49 +08:00
|
|
|
for (;;)
|
|
|
|
local_irq_enable();
|
2006-12-07 09:14:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
printk(KERN_INFO "Initializing CPU#%d\n", cpu);
|
|
|
|
|
|
|
|
if (cpu_has_vme || cpu_has_tsc || cpu_has_de)
|
|
|
|
clear_in_cr4(X86_CR4_VME|X86_CR4_PVI|X86_CR4_TSD|X86_CR4_DE);
|
|
|
|
|
2005-09-04 06:56:38 +08:00
|
|
|
load_idt(&idt_descr);
|
2009-01-30 16:47:53 +08:00
|
|
|
switch_to_new_gdt(cpu);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up and load the per-CPU TSS and LDT
|
|
|
|
*/
|
|
|
|
atomic_inc(&init_mm.mm_count);
|
2006-12-07 09:14:02 +08:00
|
|
|
curr->active_mm = &init_mm;
|
2009-03-10 13:10:32 +08:00
|
|
|
BUG_ON(curr->mm);
|
2006-12-07 09:14:02 +08:00
|
|
|
enter_lazy_tlb(&init_mm, curr);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-01-30 20:31:02 +08:00
|
|
|
load_sp0(t, thread);
|
2008-02-24 18:58:13 +08:00
|
|
|
set_tss_desc(cpu, t);
|
2005-04-17 06:20:36 +08:00
|
|
|
load_TR_desc();
|
|
|
|
load_LDT(&init_mm.context);
|
|
|
|
|
2009-05-02 02:59:25 +08:00
|
|
|
t->x86_tss.io_bitmap_base = offsetof(struct tss_struct, io_bitmap);
|
|
|
|
|
2006-01-08 17:05:24 +08:00
|
|
|
#ifdef CONFIG_DOUBLEFAULT
|
2005-04-17 06:20:36 +08:00
|
|
|
/* Set up doublefault TSS pointer in the GDT */
|
|
|
|
__set_tss_desc(cpu, GDT_ENTRY_DOUBLEFAULT_TSS, &doublefault_tss);
|
2006-01-08 17:05:24 +08:00
|
|
|
#endif
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-03-14 13:49:49 +08:00
|
|
|
clear_all_debug_regs();
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Force FPU initialization:
|
|
|
|
*/
|
2008-07-30 01:29:20 +08:00
|
|
|
if (cpu_has_xsave)
|
|
|
|
current_thread_info()->status = TS_XSAVE;
|
|
|
|
else
|
|
|
|
current_thread_info()->status = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
clear_used_math();
|
|
|
|
mxcsr_feature_mask_init();
|
2008-07-30 01:29:19 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Boot processor to setup the FP and extended state context info.
|
|
|
|
*/
|
2008-10-31 05:00:59 +08:00
|
|
|
if (smp_processor_id() == boot_cpu_id)
|
2008-07-30 01:29:19 +08:00
|
|
|
init_thread_xstate();
|
|
|
|
|
|
|
|
xsave_init();
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
2008-09-05 11:09:04 +08:00
|
|
|
#endif
|