2008-09-05 03:09:00 +00:00
|
|
|
#include <linux/bootmem.h>
|
2009-03-14 05:49:49 +00:00
|
|
|
#include <linux/linkage.h>
|
2008-09-05 03:09:00 +00:00
|
|
|
#include <linux/bitops.h>
|
2009-03-14 05:49:49 +00:00
|
|
|
#include <linux/kernel.h>
|
2008-09-05 03:09:00 +00:00
|
|
|
#include <linux/module.h>
|
2009-03-14 05:49:49 +00:00
|
|
|
#include <linux/percpu.h>
|
|
|
|
#include <linux/string.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <linux/delay.h>
|
2009-03-14 05:49:49 +00:00
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/kgdb.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <linux/smp.h>
|
2009-03-14 05:49:49 +00:00
|
|
|
#include <linux/io.h>
|
|
|
|
|
|
|
|
#include <asm/stackprotector.h>
|
perf: Do the big rename: Performance Counters -> Performance Events
Bye-bye Performance Counters, welcome Performance Events!
In the past few months the perfcounters subsystem has grown out its
initial role of counting hardware events, and has become (and is
becoming) a much broader generic event enumeration, reporting, logging,
monitoring, analysis facility.
Naming its core object 'perf_counter' and naming the subsystem
'perfcounters' has become more and more of a misnomer. With pending
code like hw-breakpoints support the 'counter' name is less and
less appropriate.
All in one, we've decided to rename the subsystem to 'performance
events' and to propagate this rename through all fields, variables
and API names. (in an ABI compatible fashion)
The word 'event' is also a bit shorter than 'counter' - which makes
it slightly more convenient to write/handle as well.
Thanks goes to Stephane Eranian who first observed this misnomer and
suggested a rename.
User-space tooling and ABI compatibility is not affected - this patch
should be function-invariant. (Also, defconfigs were not touched to
keep the size down.)
This patch has been generated via the following script:
FILES=$(find * -type f | grep -vE 'oprofile|[^K]config')
sed -i \
-e 's/PERF_EVENT_/PERF_RECORD_/g' \
-e 's/PERF_COUNTER/PERF_EVENT/g' \
-e 's/perf_counter/perf_event/g' \
-e 's/nb_counters/nb_events/g' \
-e 's/swcounter/swevent/g' \
-e 's/tpcounter_event/tp_event/g' \
$FILES
for N in $(find . -name perf_counter.[ch]); do
M=$(echo $N | sed 's/perf_counter/perf_event/g')
mv $N $M
done
FILES=$(find . -name perf_event.*)
sed -i \
-e 's/COUNTER_MASK/REG_MASK/g' \
-e 's/COUNTER/EVENT/g' \
-e 's/\<event\>/event_id/g' \
-e 's/counter/event/g' \
-e 's/Counter/Event/g' \
$FILES
... to keep it as correct as possible. This script can also be
used by anyone who has pending perfcounters patches - it converts
a Linux kernel tree over to the new naming. We tried to time this
change to the point in time where the amount of pending patches
is the smallest: the end of the merge window.
Namespace clashes were fixed up in a preparatory patch - and some
stylistic fallout will be fixed up in a subsequent patch.
( NOTE: 'counters' are still the proper terminology when we deal
with hardware registers - and these sed scripts are a bit
over-eager in renaming them. I've undone some of that, but
in case there's something left where 'counter' would be
better than 'event' we can undo that on an individual basis
instead of touching an otherwise nicely automated patch. )
Suggested-by: Stephane Eranian <eranian@google.com>
Acked-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Acked-by: Paul Mackerras <paulus@samba.org>
Reviewed-by: Arjan van de Ven <arjan@linux.intel.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: David Howells <dhowells@redhat.com>
Cc: Kyle McMartin <kyle@mcmartin.ca>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: <linux-arch@vger.kernel.org>
LKML-Reference: <new-submission>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-09-21 10:02:48 +00:00
|
|
|
#include <asm/perf_event.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <asm/mmu_context.h>
|
2011-07-31 21:02:19 +00:00
|
|
|
#include <asm/archrandom.h>
|
2009-03-14 05:49:49 +00:00
|
|
|
#include <asm/hypervisor.h>
|
|
|
|
#include <asm/processor.h>
|
2012-01-20 21:24:09 +00:00
|
|
|
#include <asm/debugreg.h>
|
2009-03-14 05:49:49 +00:00
|
|
|
#include <asm/sections.h>
|
2009-07-03 23:35:45 +00:00
|
|
|
#include <linux/topology.h>
|
|
|
|
#include <linux/cpumask.h>
|
2009-03-14 05:49:49 +00:00
|
|
|
#include <asm/pgtable.h>
|
2011-07-26 23:09:06 +00:00
|
|
|
#include <linux/atomic.h>
|
2009-03-14 05:49:49 +00:00
|
|
|
#include <asm/proto.h>
|
|
|
|
#include <asm/setup.h>
|
|
|
|
#include <asm/apic.h>
|
|
|
|
#include <asm/desc.h>
|
|
|
|
#include <asm/i387.h>
|
2012-02-21 21:19:22 +00:00
|
|
|
#include <asm/fpu-internal.h>
|
2006-06-23 09:04:18 +00:00
|
|
|
#include <asm/mtrr.h>
|
2009-07-03 23:35:45 +00:00
|
|
|
#include <linux/numa.h>
|
2009-03-14 05:49:49 +00:00
|
|
|
#include <asm/asm.h>
|
|
|
|
#include <asm/cpu.h>
|
2006-06-23 09:04:20 +00:00
|
|
|
#include <asm/mce.h>
|
2009-03-14 05:49:49 +00:00
|
|
|
#include <asm/msr.h>
|
2008-05-08 07:18:43 +00:00
|
|
|
#include <asm/pat.h>
|
2009-02-17 13:02:01 +00:00
|
|
|
|
|
|
|
#ifdef CONFIG_X86_LOCAL_APIC
|
2009-01-21 08:26:06 +00:00
|
|
|
#include <asm/uv/uv.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "cpu.h"
|
|
|
|
|
2009-01-04 13:18:03 +00:00
|
|
|
/* all of these masks are initialized in setup_cpu_local_masks() */
|
|
|
|
cpumask_var_t cpu_initialized_mask;
|
2009-03-14 05:49:49 +00:00
|
|
|
cpumask_var_t cpu_callout_mask;
|
|
|
|
cpumask_var_t cpu_callin_mask;
|
2009-01-04 13:18:03 +00:00
|
|
|
|
|
|
|
/* representing cpus for which sibling maps can be computed */
|
|
|
|
cpumask_var_t cpu_sibling_setup_mask;
|
|
|
|
|
2009-01-27 03:56:47 +00:00
|
|
|
/* correctly size the local cpu masks */
|
2009-01-27 11:03:24 +00:00
|
|
|
void __init setup_cpu_local_masks(void)
|
2009-01-27 03:56:47 +00: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-08-11 18:00:11 +00:00
|
|
|
static void __cpuinit default_init(struct cpuinfo_x86 *c)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_X86_64
|
2009-11-21 13:01:45 +00:00
|
|
|
cpu_detect_cache_sizes(c);
|
2009-08-11 18:00:11 +00:00
|
|
|
#else
|
|
|
|
/* 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");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct cpu_dev __cpuinitconst default_cpu = {
|
|
|
|
.c_init = default_init,
|
|
|
|
.c_vendor = "Unknown",
|
|
|
|
.c_x86_vendor = X86_VENDOR_UNKNOWN,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
|
2008-09-04 19:09:47 +00:00
|
|
|
|
2009-01-21 08:26:05 +00:00
|
|
|
DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
|
2008-09-05 03:09:01 +00:00
|
|
|
#ifdef CONFIG_X86_64
|
2009-01-21 08:26:05 +00: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 05:49:49 +00:00
|
|
|
* TLS descriptors are currently at a different place compared to i386.
|
2009-01-21 08:26:05 +00:00
|
|
|
* Hopefully nobody expects them at a fixed place (Wine?)
|
|
|
|
*/
|
2009-07-18 15:12:20 +00:00
|
|
|
[GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
|
|
|
|
[GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
|
|
|
|
[GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
|
|
|
|
[GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
|
|
|
|
[GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
|
|
|
|
[GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
|
2008-09-05 03:09:01 +00:00
|
|
|
#else
|
2009-07-18 15:12:20 +00:00
|
|
|
[GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
|
|
|
|
[GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
|
|
|
|
[GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
|
|
|
|
[GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
|
2007-05-02 17:27:10 +00: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 12:31:11 +00:00
|
|
|
/* 32-bit code */
|
2009-07-18 15:12:20 +00:00
|
|
|
[GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
|
2008-01-30 12:31:11 +00:00
|
|
|
/* 16-bit code */
|
2009-07-18 15:12:20 +00:00
|
|
|
[GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
|
2008-01-30 12:31:11 +00:00
|
|
|
/* 16-bit data */
|
2009-07-18 15:12:20 +00:00
|
|
|
[GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
|
2008-01-30 12:31:11 +00:00
|
|
|
/* 16-bit data */
|
2009-07-18 15:12:20 +00:00
|
|
|
[GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
|
2008-01-30 12:31:11 +00:00
|
|
|
/* 16-bit data */
|
2009-07-18 15:12:20 +00:00
|
|
|
[GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
|
2007-05-02 17:27:10 +00:00
|
|
|
/*
|
|
|
|
* The APM segments have byte granularity and their bases
|
|
|
|
* are set at run time. All have 64k limits.
|
|
|
|
*/
|
2008-01-30 12:31:11 +00:00
|
|
|
/* 32-bit code */
|
2009-07-18 15:12:20 +00:00
|
|
|
[GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
|
2007-05-02 17:27:10 +00:00
|
|
|
/* 16-bit code */
|
2009-07-18 15:12:20 +00:00
|
|
|
[GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
|
2008-01-30 12:31:11 +00:00
|
|
|
/* data */
|
2009-08-03 06:47:07 +00:00
|
|
|
[GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
|
2007-05-02 17:27:10 +00:00
|
|
|
|
2009-07-18 15:12:20 +00:00
|
|
|
[GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
|
|
|
|
[GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
|
2009-02-09 13:17:40 +00:00
|
|
|
GDT_STACK_CANARY_INIT
|
2008-09-05 03:09:01 +00:00
|
|
|
#endif
|
2009-01-21 08:26:05 +00:00
|
|
|
} };
|
2007-05-02 17:27:15 +00:00
|
|
|
EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
|
2007-05-02 17:27:10 +00:00
|
|
|
|
2009-05-22 19:17:45 +00:00
|
|
|
static int __init x86_xsave_setup(char *s)
|
|
|
|
{
|
|
|
|
setup_clear_cpu_cap(X86_FEATURE_XSAVE);
|
2010-07-19 23:05:52 +00:00
|
|
|
setup_clear_cpu_cap(X86_FEATURE_XSAVEOPT);
|
2012-07-31 17:29:14 +00:00
|
|
|
setup_clear_cpu_cap(X86_FEATURE_AVX);
|
|
|
|
setup_clear_cpu_cap(X86_FEATURE_AVX2);
|
2009-05-22 19:17:45 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
__setup("noxsave", x86_xsave_setup);
|
|
|
|
|
2010-07-19 23:05:52 +00:00
|
|
|
static int __init x86_xsaveopt_setup(char *s)
|
|
|
|
{
|
|
|
|
setup_clear_cpu_cap(X86_FEATURE_XSAVEOPT);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
__setup("noxsaveopt", x86_xsaveopt_setup);
|
|
|
|
|
2008-09-05 03:09:02 +00:00
|
|
|
#ifdef CONFIG_X86_32
|
2006-03-23 10:59:33 +00:00
|
|
|
static int cachesize_override __cpuinitdata = -1;
|
|
|
|
static int disable_x86_serial_nr __cpuinitdata = 1;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-09-04 19:09:47 +00: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-09-30 21:17:51 +00: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 07:46:17 +00: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-09-30 21:17:51 +00:00
|
|
|
: "=&r" (f1), "=&r" (f2)
|
|
|
|
: "ir" (flag));
|
2008-09-04 19:09:47 +00: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 07:46:17 +00: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-04 19:09:47 +00: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 03:09:02 +00:00
|
|
|
#else
|
2008-09-05 03:09:13 +00:00
|
|
|
static inline int flag_is_changeable_p(u32 flag)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
2008-09-05 03:09:02 +00:00
|
|
|
/* Probe for the CPUID instruction */
|
|
|
|
static inline int have_cpuid_p(void)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
2008-09-05 03:09:13 +00:00
|
|
|
static inline void squash_the_stupid_serial_number(struct cpuinfo_x86 *c)
|
|
|
|
{
|
|
|
|
}
|
2008-09-05 03:09:02 +00:00
|
|
|
#endif
|
2008-09-04 19:09:47 +00:00
|
|
|
|
2011-05-23 04:37:01 +00:00
|
|
|
static int disable_smep __cpuinitdata;
|
2011-05-11 23:51:05 +00:00
|
|
|
static __init int setup_disable_smep(char *arg)
|
|
|
|
{
|
|
|
|
disable_smep = 1;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
__setup("nosmep", setup_disable_smep);
|
|
|
|
|
2011-05-23 04:37:01 +00:00
|
|
|
static __cpuinit void setup_smep(struct cpuinfo_x86 *c)
|
2011-05-11 23:51:05 +00:00
|
|
|
{
|
|
|
|
if (cpu_has(c, X86_FEATURE_SMEP)) {
|
|
|
|
if (unlikely(disable_smep)) {
|
|
|
|
setup_clear_cpu_cap(X86_FEATURE_SMEP);
|
|
|
|
clear_in_cr4(X86_CR4_SMEP);
|
|
|
|
} else
|
|
|
|
set_in_cr4(X86_CR4_SMEP);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-24 01:20:50 +00: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 07:46:17 +00:00
|
|
|
|
2009-01-24 01:20:50 +00: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 05:49:49 +00:00
|
|
|
|
2009-01-24 01:20:50 +00:00
|
|
|
for (df = cpuid_dependent_features; df->feature; df++) {
|
2009-03-14 07:46:17 +00:00
|
|
|
|
|
|
|
if (!cpu_has(c, df->feature))
|
|
|
|
continue;
|
2009-01-24 01:20:50 +00: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 07:46:17 +00:00
|
|
|
if (!((s32)df->level < 0 ?
|
2009-02-15 07:59:18 +00:00
|
|
|
(u32)df->level > (u32)c->extended_cpuid_level :
|
2009-03-14 07:46:17 +00: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 01:20:50 +00:00
|
|
|
}
|
2009-02-15 07:59:18 +00:00
|
|
|
}
|
2009-01-24 01:20:50 +00:00
|
|
|
|
2008-09-05 03:09:13 +00:00
|
|
|
/*
|
|
|
|
* Naming convention should be: <Name> [(<Codename>)]
|
|
|
|
* This table only is used unless init_<vendor>() below doesn't set it;
|
2009-03-14 07:46:17 +00:00
|
|
|
* in particular, if CPUID levels 0x80000002..4 are supported, this
|
|
|
|
* isn't used
|
2008-09-05 03:09:13 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* Look up CPU names by table lookup. */
|
2009-03-12 12:08:49 +00:00
|
|
|
static const char *__cpuinit table_lookup_model(struct cpuinfo_x86 *c)
|
2008-09-05 03:09:13 +00:00
|
|
|
{
|
2009-03-12 12:08:49 +00:00
|
|
|
const struct cpu_model_info *info;
|
2008-09-05 03:09:13 +00: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 06:47:42 +00:00
|
|
|
__u32 cpu_caps_cleared[NCAPINTS] __cpuinitdata;
|
|
|
|
__u32 cpu_caps_set[NCAPINTS] __cpuinitdata;
|
2008-01-30 12:33:20 +00:00
|
|
|
|
2009-01-30 08:47:54 +00: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 13:17:40 +00:00
|
|
|
load_stack_canary_segment();
|
2009-01-30 08:47:54 +00:00
|
|
|
}
|
|
|
|
|
2009-03-14 07:46:17 +00:00
|
|
|
/*
|
|
|
|
* Current gdt points %fs at the "master" per-cpu area: after this,
|
|
|
|
* it's on the real one.
|
|
|
|
*/
|
2009-01-30 08:47:53 +00:00
|
|
|
void switch_to_new_gdt(int cpu)
|
2008-09-04 19:09:44 +00:00
|
|
|
{
|
|
|
|
struct desc_ptr gdt_descr;
|
|
|
|
|
2009-01-27 03:56:48 +00:00
|
|
|
gdt_descr.address = (long)get_cpu_gdt_table(cpu);
|
2008-09-04 19:09:44 +00:00
|
|
|
gdt_descr.size = GDT_SIZE - 1;
|
|
|
|
load_gdt(&gdt_descr);
|
2009-01-27 03:56:48 +00:00
|
|
|
/* Reload the per-cpu base */
|
2009-01-30 08:47:54 +00:00
|
|
|
|
|
|
|
load_percpu_segment(cpu);
|
2008-09-04 19:09:44 +00:00
|
|
|
}
|
|
|
|
|
2009-03-12 12:08:49 +00:00
|
|
|
static const struct cpu_dev *__cpuinitdata cpu_devs[X86_VENDOR_NUM] = {};
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-09-06 08:52:27 +00:00
|
|
|
static void __cpuinit get_model_name(struct cpuinfo_x86 *c)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
unsigned int *v;
|
|
|
|
char *p, *q;
|
|
|
|
|
2008-09-04 19:09:44 +00:00
|
|
|
if (c->extended_cpuid_level < 0x80000004)
|
2008-09-06 08:52:27 +00:00
|
|
|
return;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2009-03-14 07:46:17 +00:00
|
|
|
v = (unsigned int *)c->x86_model_id;
|
2005-04-16 22:20:36 +00: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 07:46:17 +00:00
|
|
|
/*
|
|
|
|
* Intel chips right-justify this string for some dumb reason;
|
|
|
|
* undo that brain damage:
|
|
|
|
*/
|
2005-04-16 22:20:36 +00:00
|
|
|
p = q = &c->x86_model_id[0];
|
2008-02-24 10:58:13 +00:00
|
|
|
while (*p == ' ')
|
2009-03-14 05:49:49 +00:00
|
|
|
p++;
|
2008-02-24 10:58:13 +00:00
|
|
|
if (p != q) {
|
2009-03-14 05:49:49 +00:00
|
|
|
while (*p)
|
|
|
|
*q++ = *p++;
|
|
|
|
while (q <= &c->x86_model_id[48])
|
|
|
|
*q++ = '\0'; /* Zero-pad the rest */
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-21 13:01:45 +00:00
|
|
|
void __cpuinit cpu_detect_cache_sizes(struct cpuinfo_x86 *c)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-09-04 19:09:44 +00:00
|
|
|
unsigned int n, dummy, ebx, ecx, edx, l2size;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-09-04 19:09:44 +00:00
|
|
|
n = c->extended_cpuid_level;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (n >= 0x80000005) {
|
2008-09-04 19:09:44 +00:00
|
|
|
cpuid(0x80000005, &dummy, &ebx, &ecx, &edx);
|
|
|
|
c->x86_cache_size = (ecx>>24) + (edx>>24);
|
2008-09-05 03:09:07 +00:00
|
|
|
#ifdef CONFIG_X86_64
|
|
|
|
/* On K8 L1 TLB is inclusive, so don't count it */
|
|
|
|
c->x86_tlbsize = 0;
|
|
|
|
#endif
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (n < 0x80000006) /* Some chips just has a large L1. */
|
|
|
|
return;
|
|
|
|
|
2008-09-04 19:09:47 +00:00
|
|
|
cpuid(0x80000006, &dummy, &ebx, &ecx, &edx);
|
2005-04-16 22:20:36 +00:00
|
|
|
l2size = ecx >> 16;
|
2008-02-24 10:58:13 +00:00
|
|
|
|
2008-09-05 03:09:07 +00:00
|
|
|
#ifdef CONFIG_X86_64
|
|
|
|
c->x86_tlbsize += ((ebx >> 16) & 0xfff) + (ebx & 0xfff);
|
|
|
|
#else
|
2005-04-16 22:20:36 +00:00
|
|
|
/* do processor-specific cache resizing */
|
|
|
|
if (this_cpu->c_size_cache)
|
2008-02-24 10:58:13 +00:00
|
|
|
l2size = this_cpu->c_size_cache(c, l2size);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* Allow user to override all this if necessary. */
|
|
|
|
if (cachesize_override != -1)
|
|
|
|
l2size = cachesize_override;
|
|
|
|
|
2008-02-24 10:58:13 +00:00
|
|
|
if (l2size == 0)
|
2005-04-16 22:20:36 +00:00
|
|
|
return; /* Again, no L2 cache is possible */
|
2008-09-05 03:09:07 +00:00
|
|
|
#endif
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
c->x86_cache_size = l2size;
|
|
|
|
}
|
|
|
|
|
x86/tlb_info: get last level TLB entry number of CPU
For 4KB pages, x86 CPU has 2 or 1 level TLB, first level is data TLB and
instruction TLB, second level is shared TLB for both data and instructions.
For hupe page TLB, usually there is just one level and seperated by 2MB/4MB
and 1GB.
Although each levels TLB size is important for performance tuning, but for
genernal and rude optimizing, last level TLB entry number is suitable. And
in fact, last level TLB always has the biggest entry number.
This patch will get the biggest TLB entry number and use it in furture TLB
optimizing.
Accroding Borislav's suggestion, except tlb_ll[i/d]_* array, other
function and data will be released after system boot up.
For all kinds of x86 vendor friendly, vendor specific code was moved to its
specific files.
Signed-off-by: Alex Shi <alex.shi@intel.com>
Link: http://lkml.kernel.org/r/1340845344-27557-2-git-send-email-alex.shi@intel.com
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2012-06-28 01:02:16 +00:00
|
|
|
u16 __read_mostly tlb_lli_4k[NR_INFO];
|
|
|
|
u16 __read_mostly tlb_lli_2m[NR_INFO];
|
|
|
|
u16 __read_mostly tlb_lli_4m[NR_INFO];
|
|
|
|
u16 __read_mostly tlb_lld_4k[NR_INFO];
|
|
|
|
u16 __read_mostly tlb_lld_2m[NR_INFO];
|
|
|
|
u16 __read_mostly tlb_lld_4m[NR_INFO];
|
|
|
|
|
2012-06-28 01:02:19 +00:00
|
|
|
/*
|
|
|
|
* tlb_flushall_shift shows the balance point in replacing cr3 write
|
|
|
|
* with multiple 'invlpg'. It will do this replacement when
|
|
|
|
* flush_tlb_lines <= active_lines/2^tlb_flushall_shift.
|
|
|
|
* If tlb_flushall_shift is -1, means the replacement will be disabled.
|
|
|
|
*/
|
|
|
|
s8 __read_mostly tlb_flushall_shift = -1;
|
|
|
|
|
x86/tlb_info: get last level TLB entry number of CPU
For 4KB pages, x86 CPU has 2 or 1 level TLB, first level is data TLB and
instruction TLB, second level is shared TLB for both data and instructions.
For hupe page TLB, usually there is just one level and seperated by 2MB/4MB
and 1GB.
Although each levels TLB size is important for performance tuning, but for
genernal and rude optimizing, last level TLB entry number is suitable. And
in fact, last level TLB always has the biggest entry number.
This patch will get the biggest TLB entry number and use it in furture TLB
optimizing.
Accroding Borislav's suggestion, except tlb_ll[i/d]_* array, other
function and data will be released after system boot up.
For all kinds of x86 vendor friendly, vendor specific code was moved to its
specific files.
Signed-off-by: Alex Shi <alex.shi@intel.com>
Link: http://lkml.kernel.org/r/1340845344-27557-2-git-send-email-alex.shi@intel.com
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2012-06-28 01:02:16 +00:00
|
|
|
void __cpuinit cpu_detect_tlb(struct cpuinfo_x86 *c)
|
|
|
|
{
|
|
|
|
if (this_cpu->c_detect_tlb)
|
|
|
|
this_cpu->c_detect_tlb(c);
|
|
|
|
|
|
|
|
printk(KERN_INFO "Last level iTLB entries: 4KB %d, 2MB %d, 4MB %d\n" \
|
2012-06-28 01:02:19 +00:00
|
|
|
"Last level dTLB entries: 4KB %d, 2MB %d, 4MB %d\n" \
|
|
|
|
"tlb_flushall_shift is 0x%x\n",
|
x86/tlb_info: get last level TLB entry number of CPU
For 4KB pages, x86 CPU has 2 or 1 level TLB, first level is data TLB and
instruction TLB, second level is shared TLB for both data and instructions.
For hupe page TLB, usually there is just one level and seperated by 2MB/4MB
and 1GB.
Although each levels TLB size is important for performance tuning, but for
genernal and rude optimizing, last level TLB entry number is suitable. And
in fact, last level TLB always has the biggest entry number.
This patch will get the biggest TLB entry number and use it in furture TLB
optimizing.
Accroding Borislav's suggestion, except tlb_ll[i/d]_* array, other
function and data will be released after system boot up.
For all kinds of x86 vendor friendly, vendor specific code was moved to its
specific files.
Signed-off-by: Alex Shi <alex.shi@intel.com>
Link: http://lkml.kernel.org/r/1340845344-27557-2-git-send-email-alex.shi@intel.com
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2012-06-28 01:02:16 +00:00
|
|
|
tlb_lli_4k[ENTRIES], tlb_lli_2m[ENTRIES],
|
|
|
|
tlb_lli_4m[ENTRIES], tlb_lld_4k[ENTRIES],
|
2012-06-28 01:02:19 +00:00
|
|
|
tlb_lld_2m[ENTRIES], tlb_lld_4m[ENTRIES],
|
|
|
|
tlb_flushall_shift);
|
x86/tlb_info: get last level TLB entry number of CPU
For 4KB pages, x86 CPU has 2 or 1 level TLB, first level is data TLB and
instruction TLB, second level is shared TLB for both data and instructions.
For hupe page TLB, usually there is just one level and seperated by 2MB/4MB
and 1GB.
Although each levels TLB size is important for performance tuning, but for
genernal and rude optimizing, last level TLB entry number is suitable. And
in fact, last level TLB always has the biggest entry number.
This patch will get the biggest TLB entry number and use it in furture TLB
optimizing.
Accroding Borislav's suggestion, except tlb_ll[i/d]_* array, other
function and data will be released after system boot up.
For all kinds of x86 vendor friendly, vendor specific code was moved to its
specific files.
Signed-off-by: Alex Shi <alex.shi@intel.com>
Link: http://lkml.kernel.org/r/1340845344-27557-2-git-send-email-alex.shi@intel.com
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2012-06-28 01:02:16 +00:00
|
|
|
}
|
|
|
|
|
2008-09-04 19:09:44 +00:00
|
|
|
void __cpuinit detect_ht(struct cpuinfo_x86 *c)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-09-05 03:08:59 +00:00
|
|
|
#ifdef CONFIG_X86_HT
|
2008-09-04 19:09:47 +00:00
|
|
|
u32 eax, ebx, ecx, edx;
|
|
|
|
int index_msb, core_bits;
|
2009-12-11 01:19:36 +00:00
|
|
|
static bool printed;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-09-04 19:09:47 +00:00
|
|
|
if (!cpu_has(c, X86_FEATURE_HT))
|
2008-09-04 19:09:44 +00:00
|
|
|
return;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-09-04 19:09:47 +00:00
|
|
|
if (cpu_has(c, X86_FEATURE_CMP_LEGACY))
|
|
|
|
goto out;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-09-05 03:09:08 +00:00
|
|
|
if (cpu_has(c, X86_FEATURE_XTOPOLOGY))
|
|
|
|
return;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-09-04 19:09:47 +00:00
|
|
|
cpuid(1, &eax, &ebx, &ecx, &edx);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-09-04 19:09:44 +00:00
|
|
|
smp_num_siblings = (ebx & 0xff0000) >> 16;
|
|
|
|
|
|
|
|
if (smp_num_siblings == 1) {
|
2009-12-11 01:19:36 +00:00
|
|
|
printk_once(KERN_INFO "CPU0: Hyper-Threading is disabled\n");
|
2009-03-14 07:46:17 +00:00
|
|
|
goto out;
|
|
|
|
}
|
2008-09-04 19:09:44 +00:00
|
|
|
|
2009-03-14 07:46:17 +00:00
|
|
|
if (smp_num_siblings <= 1)
|
|
|
|
goto out;
|
2008-09-04 19:09:44 +00:00
|
|
|
|
2009-03-14 07:46:17 +00:00
|
|
|
index_msb = get_count_order(smp_num_siblings);
|
|
|
|
c->phys_proc_id = apic->phys_pkg_id(c->initial_apicid, index_msb);
|
2008-09-04 19:09:44 +00:00
|
|
|
|
2009-03-14 07:46:17 +00:00
|
|
|
smp_num_siblings = smp_num_siblings / c->x86_max_cores;
|
2008-09-04 19:09:44 +00:00
|
|
|
|
2009-03-14 07:46:17 +00:00
|
|
|
index_msb = get_count_order(smp_num_siblings);
|
2008-09-04 19:09:44 +00:00
|
|
|
|
2009-03-14 07:46:17 +00:00
|
|
|
core_bits = get_count_order(c->x86_max_cores);
|
2008-09-04 19:09:44 +00:00
|
|
|
|
2009-03-14 07:46:17 +00:00
|
|
|
c->cpu_core_id = apic->phys_pkg_id(c->initial_apicid, index_msb) &
|
|
|
|
((1 << core_bits) - 1);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-09-04 19:09:47 +00:00
|
|
|
out:
|
2009-12-11 01:19:36 +00:00
|
|
|
if (!printed && (c->x86_max_cores * smp_num_siblings) > 1) {
|
2008-09-04 19:09:47 +00:00
|
|
|
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);
|
2009-12-11 01:19:36 +00:00
|
|
|
printed = 1;
|
2008-09-04 19:09:44 +00:00
|
|
|
}
|
|
|
|
#endif
|
2008-09-05 03:08:59 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-09-04 19:09:44 +00:00
|
|
|
static void __cpuinit get_cpu_vendor(struct cpuinfo_x86 *c)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
char *v = c->x86_vendor_id;
|
2009-03-14 07:46:17 +00:00
|
|
|
int i;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
for (i = 0; i < X86_VENDOR_NUM; i++) {
|
2008-09-04 19:09:45 +00: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 07:46:17 +00:00
|
|
|
|
2008-09-04 19:09:45 +00:00
|
|
|
this_cpu = cpu_devs[i];
|
|
|
|
c->x86_vendor = this_cpu->c_x86_vendor;
|
|
|
|
return;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
}
|
2008-09-04 19:09:45 +00:00
|
|
|
|
2009-06-16 22:33:44 +00:00
|
|
|
printk_once(KERN_ERR
|
|
|
|
"CPU: vendor_id '%s' unknown, using generic init.\n" \
|
|
|
|
"CPU: Your system may be unstable.\n", v);
|
2008-09-04 19:09:45 +00:00
|
|
|
|
2006-02-05 07:28:03 +00:00
|
|
|
c->x86_vendor = X86_VENDOR_UNKNOWN;
|
|
|
|
this_cpu = &default_cpu;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2008-09-04 19:09:44 +00:00
|
|
|
void __cpuinit cpu_detect(struct cpuinfo_x86 *c)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
/* Get vendor name */
|
2008-02-01 16:49:43 +00: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-16 22:20:36 +00:00
|
|
|
|
|
|
|
c->x86 = 4;
|
2008-09-04 19:09:44 +00:00
|
|
|
/* Intel-defined flags: level 0x00000001 */
|
2005-04-16 22:20:36 +00:00
|
|
|
if (c->cpuid_level >= 0x00000001) {
|
|
|
|
u32 junk, tfms, cap0, misc;
|
2009-03-14 07:46:17 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
cpuid(0x00000001, &tfms, &misc, &junk, &cap0);
|
2008-09-04 19:09:44 +00:00
|
|
|
c->x86 = (tfms >> 8) & 0xf;
|
|
|
|
c->x86_model = (tfms >> 4) & 0xf;
|
|
|
|
c->x86_mask = tfms & 0xf;
|
2009-03-14 07:46:17 +00:00
|
|
|
|
2005-11-05 16:25:53 +00:00
|
|
|
if (c->x86 == 0xf)
|
2005-04-16 22:20:36 +00:00
|
|
|
c->x86 += (tfms >> 20) & 0xff;
|
2005-11-05 16:25:53 +00:00
|
|
|
if (c->x86 >= 0x6)
|
2008-09-04 19:09:44 +00:00
|
|
|
c->x86_model += ((tfms >> 16) & 0xf) << 4;
|
2009-03-14 07:46:17 +00:00
|
|
|
|
2008-01-31 21:05:45 +00:00
|
|
|
if (cap0 & (1<<19)) {
|
|
|
|
c->x86_clflush_size = ((misc >> 8) & 0xff) * 8;
|
2008-09-04 19:09:44 +00:00
|
|
|
c->x86_cache_alignment = c->x86_clflush_size;
|
2008-01-31 21:05:45 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
}
|
2008-09-04 19:09:44 +00:00
|
|
|
|
2010-09-28 22:35:01 +00:00
|
|
|
void __cpuinit get_cpu_cap(struct cpuinfo_x86 *c)
|
2008-01-30 12:33:32 +00:00
|
|
|
{
|
|
|
|
u32 tfms, xlvl;
|
2008-09-04 19:09:44 +00:00
|
|
|
u32 ebx;
|
2008-01-30 12:33:32 +00:00
|
|
|
|
2008-09-04 19:09:44 +00:00
|
|
|
/* Intel-defined flags: level 0x00000001 */
|
|
|
|
if (c->cpuid_level >= 0x00000001) {
|
|
|
|
u32 capability, excap;
|
2009-03-14 07:46:17 +00:00
|
|
|
|
2008-09-04 19:09:44 +00:00
|
|
|
cpuid(0x00000001, &tfms, &ebx, &excap, &capability);
|
|
|
|
c->x86_capability[0] = capability;
|
|
|
|
c->x86_capability[4] = excap;
|
|
|
|
}
|
2008-01-30 12:33:32 +00:00
|
|
|
|
2010-07-08 00:29:18 +00:00
|
|
|
/* Additional Intel-defined flags: level 0x00000007 */
|
|
|
|
if (c->cpuid_level >= 0x00000007) {
|
|
|
|
u32 eax, ebx, ecx, edx;
|
|
|
|
|
|
|
|
cpuid_count(0x00000007, 0, &eax, &ebx, &ecx, &edx);
|
|
|
|
|
2011-05-17 19:33:26 +00:00
|
|
|
c->x86_capability[9] = ebx;
|
2010-07-08 00:29:18 +00:00
|
|
|
}
|
|
|
|
|
2008-09-04 19:09:44 +00:00
|
|
|
/* AMD-defined flags: level 0x80000001 */
|
|
|
|
xlvl = cpuid_eax(0x80000000);
|
|
|
|
c->extended_cpuid_level = xlvl;
|
2009-03-14 07:46:17 +00:00
|
|
|
|
2008-09-04 19:09:44 +00: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 12:33:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-05 03:09:09 +00: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 12:33:32 +00:00
|
|
|
}
|
2009-03-12 12:37:34 +00: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 03:09:09 +00:00
|
|
|
#endif
|
2008-09-06 08:52:28 +00:00
|
|
|
|
|
|
|
if (c->extended_cpuid_level >= 0x80000007)
|
|
|
|
c->x86_power = cpuid_edx(0x80000007);
|
2008-01-30 12:33:32 +00:00
|
|
|
|
2010-05-19 19:01:23 +00:00
|
|
|
init_scattered_cpuid_features(c);
|
2008-01-30 12:33:32 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-09-14 09:33:15 +00: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 10:58:13 +00: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-04 19:09:44 +00:00
|
|
|
static void __init early_identify_cpu(struct cpuinfo_x86 *c)
|
2006-12-07 01:14:08 +00:00
|
|
|
{
|
2008-09-05 03:09:10 +00:00
|
|
|
#ifdef CONFIG_X86_64
|
|
|
|
c->x86_clflush_size = 64;
|
2009-03-12 12:37:34 +00:00
|
|
|
c->x86_phys_bits = 36;
|
|
|
|
c->x86_virt_bits = 48;
|
2008-09-05 03:09:10 +00:00
|
|
|
#else
|
2008-01-31 21:05:45 +00:00
|
|
|
c->x86_clflush_size = 32;
|
2009-03-12 12:37:34 +00:00
|
|
|
c->x86_phys_bits = 32;
|
|
|
|
c->x86_virt_bits = 32;
|
2008-09-05 03:09:10 +00:00
|
|
|
#endif
|
2008-09-04 19:09:47 +00:00
|
|
|
c->x86_cache_alignment = c->x86_clflush_size;
|
2006-12-07 01:14:08 +00:00
|
|
|
|
2008-09-04 19:09:44 +00:00
|
|
|
memset(&c->x86_capability, 0, sizeof c->x86_capability);
|
2008-09-04 19:09:47 +00:00
|
|
|
c->extended_cpuid_level = 0;
|
2006-12-07 01:14:08 +00:00
|
|
|
|
2008-09-14 09:33:15 +00:00
|
|
|
if (!have_cpuid_p())
|
|
|
|
identify_cpu_without_cpuid(c);
|
|
|
|
|
|
|
|
/* cyrix could have cpuid enabled via c_identify()*/
|
2006-12-07 01:14:08 +00:00
|
|
|
if (!have_cpuid_p())
|
|
|
|
return;
|
|
|
|
|
|
|
|
cpu_detect(c);
|
|
|
|
|
2008-09-04 19:09:44 +00:00
|
|
|
get_cpu_vendor(c);
|
2008-01-30 12:32:40 +00:00
|
|
|
|
2008-09-04 19:09:44 +00:00
|
|
|
get_cpu_cap(c);
|
2008-09-04 19:09:43 +00:00
|
|
|
|
2008-09-04 19:09:45 +00:00
|
|
|
if (this_cpu->c_early_init)
|
|
|
|
this_cpu->c_early_init(c);
|
2008-01-30 12:33:32 +00:00
|
|
|
|
2010-07-21 17:03:58 +00:00
|
|
|
c->cpu_index = 0;
|
2009-01-24 01:20:50 +00:00
|
|
|
filter_cpuid_features(c, false);
|
2011-05-11 23:51:05 +00:00
|
|
|
|
|
|
|
setup_smep(c);
|
2011-08-05 18:01:16 +00:00
|
|
|
|
|
|
|
if (this_cpu->c_bsp_init)
|
|
|
|
this_cpu->c_bsp_init(c);
|
2006-12-07 01:14:08 +00:00
|
|
|
}
|
|
|
|
|
2008-09-04 19:09:44 +00:00
|
|
|
void __init early_cpu_init(void)
|
|
|
|
{
|
2009-03-12 12:08:49 +00:00
|
|
|
const struct cpu_dev *const *cdev;
|
2008-09-04 19:09:45 +00:00
|
|
|
int count = 0;
|
|
|
|
|
2011-03-04 15:52:35 +00:00
|
|
|
#ifdef CONFIG_PROCESSOR_SELECT
|
2009-03-14 05:49:49 +00:00
|
|
|
printk(KERN_INFO "KERNEL supported cpus:\n");
|
2009-11-14 09:34:41 +00:00
|
|
|
#endif
|
|
|
|
|
2008-09-04 19:09:45 +00:00
|
|
|
for (cdev = __x86_cpu_dev_start; cdev < __x86_cpu_dev_end; cdev++) {
|
2009-03-12 12:08:49 +00:00
|
|
|
const struct cpu_dev *cpudev = *cdev;
|
2008-09-04 19:09:44 +00:00
|
|
|
|
2008-09-04 19:09:45 +00:00
|
|
|
if (count >= X86_VENDOR_NUM)
|
|
|
|
break;
|
|
|
|
cpu_devs[count] = cpudev;
|
|
|
|
count++;
|
|
|
|
|
2011-03-04 15:52:35 +00:00
|
|
|
#ifdef CONFIG_PROCESSOR_SELECT
|
2009-11-14 09:34:41 +00:00
|
|
|
{
|
|
|
|
unsigned int j;
|
|
|
|
|
|
|
|
for (j = 0; j < 2; j++) {
|
|
|
|
if (!cpudev->c_ident[j])
|
|
|
|
continue;
|
|
|
|
printk(KERN_INFO " %s %s\n", cpudev->c_vendor,
|
|
|
|
cpudev->c_ident[j]);
|
|
|
|
}
|
2008-09-04 19:09:45 +00:00
|
|
|
}
|
2009-11-13 20:30:00 +00:00
|
|
|
#endif
|
2008-09-04 19:09:45 +00:00
|
|
|
}
|
2008-09-04 19:09:44 +00:00
|
|
|
early_identify_cpu(&boot_cpu_data);
|
2006-12-07 01:14:08 +00:00
|
|
|
}
|
2008-01-30 12:33:32 +00:00
|
|
|
|
2008-08-19 00:39:32 +00:00
|
|
|
/*
|
2010-10-04 07:31:27 +00:00
|
|
|
* The NOPL instruction is supposed to exist on all CPUs of family >= 6;
|
|
|
|
* unfortunately, that's not true in practice because of early VIA
|
|
|
|
* chips and (more importantly) broken virtualizers that 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 on 32-bit
|
2008-09-16 16:29:40 +00:00
|
|
|
* unless we can find a reliable way to detect all the broken cases.
|
2010-10-04 07:31:27 +00:00
|
|
|
* Enable it explicitly on 64-bit for non-constant inputs of cpu_has().
|
2008-08-19 00:39:32 +00:00
|
|
|
*/
|
|
|
|
static void __cpuinit detect_nopl(struct cpuinfo_x86 *c)
|
|
|
|
{
|
2010-10-04 07:31:27 +00:00
|
|
|
#ifdef CONFIG_X86_32
|
2008-08-19 00:39:32 +00:00
|
|
|
clear_cpu_cap(c, X86_FEATURE_NOPL);
|
2010-10-04 07:31:27 +00:00
|
|
|
#else
|
|
|
|
set_cpu_cap(c, X86_FEATURE_NOPL);
|
|
|
|
#endif
|
2006-12-07 01:14:08 +00:00
|
|
|
}
|
|
|
|
|
2008-02-24 10:58:13 +00:00
|
|
|
static void __cpuinit generic_identify(struct cpuinfo_x86 *c)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-09-14 09:33:15 +00:00
|
|
|
c->extended_cpuid_level = 0;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-09-04 19:09:44 +00:00
|
|
|
if (!have_cpuid_p())
|
2008-09-14 09:33:15 +00:00
|
|
|
identify_cpu_without_cpuid(c);
|
2007-07-11 19:18:32 +00:00
|
|
|
|
2008-09-14 09:33:15 +00:00
|
|
|
/* cyrix could have cpuid enabled via c_identify()*/
|
2008-09-14 12:46:58 +00:00
|
|
|
if (!have_cpuid_p())
|
2008-09-14 09:33:15 +00:00
|
|
|
return;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-09-04 19:09:44 +00:00
|
|
|
cpu_detect(c);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-09-04 19:09:44 +00:00
|
|
|
get_cpu_vendor(c);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-09-04 19:09:44 +00:00
|
|
|
get_cpu_cap(c);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-09-04 19:09:44 +00:00
|
|
|
if (c->cpuid_level >= 0x00000001) {
|
|
|
|
c->initial_apicid = (cpuid_ebx(1) >> 24) & 0xFF;
|
2008-09-05 03:09:12 +00:00
|
|
|
#ifdef CONFIG_X86_32
|
|
|
|
# ifdef CONFIG_X86_HT
|
2009-01-28 12:24:54 +00:00
|
|
|
c->apicid = apic->phys_pkg_id(c->initial_apicid, 0);
|
2008-09-05 03:09:12 +00:00
|
|
|
# else
|
2008-09-04 19:09:44 +00:00
|
|
|
c->apicid = c->initial_apicid;
|
2008-09-05 03:09:12 +00:00
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
c->phys_proc_id = c->initial_apicid;
|
2008-09-04 19:09:44 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2011-05-11 23:51:05 +00:00
|
|
|
setup_smep(c);
|
|
|
|
|
2008-09-06 08:52:27 +00:00
|
|
|
get_model_name(c); /* Default name */
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-09-04 19:09:44 +00:00
|
|
|
detect_nopl(c);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This does the hard work of actually picking apart the CPU stuff...
|
|
|
|
*/
|
2008-06-21 10:24:00 +00:00
|
|
|
static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
|
2005-04-16 22:20:36 +00: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-05 16:25:54 +00:00
|
|
|
c->x86_max_cores = 1;
|
2008-09-05 03:09:13 +00:00
|
|
|
c->x86_coreid_bits = 0;
|
2008-09-08 00:58:50 +00:00
|
|
|
#ifdef CONFIG_X86_64
|
2008-09-05 03:09:13 +00:00
|
|
|
c->x86_clflush_size = 64;
|
2009-03-12 12:37:34 +00:00
|
|
|
c->x86_phys_bits = 36;
|
|
|
|
c->x86_virt_bits = 48;
|
2008-09-05 03:09:13 +00:00
|
|
|
#else
|
|
|
|
c->cpuid_level = -1; /* CPUID not detected */
|
2006-12-07 01:14:05 +00:00
|
|
|
c->x86_clflush_size = 32;
|
2009-03-12 12:37:34 +00:00
|
|
|
c->x86_phys_bits = 32;
|
|
|
|
c->x86_virt_bits = 32;
|
2008-09-05 03:09:13 +00:00
|
|
|
#endif
|
|
|
|
c->x86_cache_alignment = c->x86_clflush_size;
|
2005-04-16 22:20:36 +00:00
|
|
|
memset(&c->x86_capability, 0, sizeof c->x86_capability);
|
|
|
|
|
|
|
|
generic_identify(c);
|
|
|
|
|
2008-01-30 12:32:49 +00:00
|
|
|
if (this_cpu->c_identify)
|
2005-04-16 22:20:36 +00:00
|
|
|
this_cpu->c_identify(c);
|
|
|
|
|
2009-05-15 20:05:16 +00: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 03:09:13 +00:00
|
|
|
#ifdef CONFIG_X86_64
|
2009-01-28 12:24:54 +00:00
|
|
|
c->apicid = apic->phys_pkg_id(c->initial_apicid, 0);
|
2008-09-05 03:09:13 +00:00
|
|
|
#endif
|
|
|
|
|
2005-04-16 22:20:36 +00: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 07:46:17 +00:00
|
|
|
* The vendor-specific functions might have changed features.
|
|
|
|
* Now we do "generic changes."
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
|
|
|
|
2009-01-24 01:20:50 +00:00
|
|
|
/* Filter out anything that depends on CPUID levels we don't have */
|
|
|
|
filter_cpuid_features(c, true);
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/* If the model name is still unset, do table lookup. */
|
2008-02-24 10:58:13 +00:00
|
|
|
if (!c->x86_model_id[0]) {
|
2009-03-12 12:08:49 +00:00
|
|
|
const char *p;
|
2005-04-16 22:20:36 +00:00
|
|
|
p = table_lookup_model(c);
|
2008-02-24 10:58:13 +00:00
|
|
|
if (p)
|
2005-04-16 22:20:36 +00:00
|
|
|
strcpy(c->x86_model_id, p);
|
|
|
|
else
|
|
|
|
/* Last resort... */
|
|
|
|
sprintf(c->x86_model_id, "%02x/%02x",
|
2006-03-23 10:59:36 +00:00
|
|
|
c->x86, c->x86_model);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2008-09-05 03:09:13 +00:00
|
|
|
#ifdef CONFIG_X86_64
|
|
|
|
detect_ht(c);
|
|
|
|
#endif
|
|
|
|
|
2008-10-27 17:41:46 +00:00
|
|
|
init_hypervisor(c);
|
2011-07-31 21:02:19 +00:00
|
|
|
x86_init_rdrand(c);
|
2009-05-10 06:47:42 +00: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-16 22:20:36 +00: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 10:58:13 +00:00
|
|
|
if (c != &boot_cpu_data) {
|
2005-04-16 22:20:36 +00:00
|
|
|
/* AND the already accumulated flags with these */
|
2008-09-04 19:09:44 +00:00
|
|
|
for (i = 0; i < NCAPINTS; i++)
|
2005-04-16 22:20:36 +00:00
|
|
|
boot_cpu_data.x86_capability[i] &= c->x86_capability[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Init Machine Check Exception if available. */
|
2009-10-16 10:31:32 +00:00
|
|
|
mcheck_cpu_init(c);
|
2008-01-30 12:33:16 +00:00
|
|
|
|
|
|
|
select_idle_routine(c);
|
2008-09-05 03:09:13 +00:00
|
|
|
|
2011-01-23 13:37:41 +00:00
|
|
|
#ifdef CONFIG_NUMA
|
2008-09-05 03:09:13 +00:00
|
|
|
numa_add_cpu(smp_processor_id());
|
|
|
|
#endif
|
2007-05-02 17:27:12 +00:00
|
|
|
}
|
2005-11-07 08:58:42 +00:00
|
|
|
|
2008-09-22 17:35:08 +00: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-02 17:27:12 +00:00
|
|
|
void __init identify_boot_cpu(void)
|
|
|
|
{
|
|
|
|
identify_cpu(&boot_cpu_data);
|
2011-04-01 20:59:53 +00:00
|
|
|
init_amd_e400_c1e_mask();
|
2008-09-05 03:09:13 +00:00
|
|
|
#ifdef CONFIG_X86_32
|
2007-05-02 17:27:12 +00:00
|
|
|
sysenter_setup();
|
2005-06-25 21:54:53 +00:00
|
|
|
enable_sep_cpu();
|
2008-09-22 17:35:08 +00:00
|
|
|
#else
|
|
|
|
vgetcpu_set_mode();
|
2008-09-05 03:09:13 +00:00
|
|
|
#endif
|
x86/tlb_info: get last level TLB entry number of CPU
For 4KB pages, x86 CPU has 2 or 1 level TLB, first level is data TLB and
instruction TLB, second level is shared TLB for both data and instructions.
For hupe page TLB, usually there is just one level and seperated by 2MB/4MB
and 1GB.
Although each levels TLB size is important for performance tuning, but for
genernal and rude optimizing, last level TLB entry number is suitable. And
in fact, last level TLB always has the biggest entry number.
This patch will get the biggest TLB entry number and use it in furture TLB
optimizing.
Accroding Borislav's suggestion, except tlb_ll[i/d]_* array, other
function and data will be released after system boot up.
For all kinds of x86 vendor friendly, vendor specific code was moved to its
specific files.
Signed-off-by: Alex Shi <alex.shi@intel.com>
Link: http://lkml.kernel.org/r/1340845344-27557-2-git-send-email-alex.shi@intel.com
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2012-06-28 01:02:16 +00:00
|
|
|
if (boot_cpu_data.cpuid_level >= 2)
|
|
|
|
cpu_detect_tlb(&boot_cpu_data);
|
2007-05-02 17:27:12 +00:00
|
|
|
}
|
2005-07-08 00:56:38 +00:00
|
|
|
|
2007-05-02 17:27:12 +00:00
|
|
|
void __cpuinit identify_secondary_cpu(struct cpuinfo_x86 *c)
|
|
|
|
{
|
|
|
|
BUG_ON(c == &boot_cpu_data);
|
|
|
|
identify_cpu(c);
|
2008-09-05 03:09:13 +00:00
|
|
|
#ifdef CONFIG_X86_32
|
2007-05-02 17:27:12 +00:00
|
|
|
enable_sep_cpu();
|
2008-09-05 03:09:13 +00:00
|
|
|
#endif
|
2007-05-02 17:27:12 +00:00
|
|
|
mtrr_ap_init();
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2008-09-04 19:09:46 +00:00
|
|
|
struct msr_range {
|
2009-03-14 07:46:17 +00:00
|
|
|
unsigned min;
|
|
|
|
unsigned max;
|
2008-09-04 19:09:46 +00:00
|
|
|
};
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2009-03-12 12:08:49 +00:00
|
|
|
static const struct msr_range msr_range_array[] __cpuinitconst = {
|
2008-09-04 19:09:46 +00:00
|
|
|
{ 0x00000000, 0x00000418},
|
|
|
|
{ 0xc0000000, 0xc000040b},
|
|
|
|
{ 0xc0010000, 0xc0010142},
|
|
|
|
{ 0xc0011000, 0xc001103b},
|
|
|
|
};
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2012-02-12 17:53:57 +00:00
|
|
|
static void __cpuinit __print_cpu_msr(void)
|
2008-09-04 19:09:46 +00:00
|
|
|
{
|
2009-03-14 07:46:17 +00:00
|
|
|
unsigned index_min, index_max;
|
2008-09-04 19:09:46 +00: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 07:46:17 +00:00
|
|
|
|
2008-09-04 19:09:46 +00:00
|
|
|
for (index = index_min; index < index_max; index++) {
|
2012-06-01 14:52:36 +00:00
|
|
|
if (rdmsrl_safe(index, &val))
|
2008-09-04 19:09:46 +00:00
|
|
|
continue;
|
|
|
|
printk(KERN_INFO " MSR%08x: %016llx\n", index, val);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2008-09-04 19:09:46 +00:00
|
|
|
}
|
|
|
|
}
|
2005-11-05 16:25:54 +00:00
|
|
|
|
2008-09-04 19:09:46 +00:00
|
|
|
static int show_msr __cpuinitdata;
|
2009-03-14 07:46:17 +00:00
|
|
|
|
2008-09-04 19:09:46 +00:00
|
|
|
static __init int setup_show_msr(char *arg)
|
|
|
|
{
|
|
|
|
int num;
|
2005-04-16 22:25:15 +00:00
|
|
|
|
2008-09-04 19:09:46 +00:00
|
|
|
get_option(&arg, &num);
|
2005-04-16 22:25:15 +00:00
|
|
|
|
2008-09-04 19:09:46 +00:00
|
|
|
if (num > 0)
|
|
|
|
show_msr = num;
|
|
|
|
return 1;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2008-09-04 19:09:46 +00:00
|
|
|
__setup("show_msr=", setup_show_msr);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-01-30 12:33:21 +00:00
|
|
|
static __init int setup_noclflush(char *arg)
|
|
|
|
{
|
|
|
|
setup_clear_cpu_cap(X86_FEATURE_CLFLSH);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
__setup("noclflush", setup_noclflush);
|
|
|
|
|
2006-03-23 10:59:33 +00:00
|
|
|
void __cpuinit print_cpu_info(struct cpuinfo_x86 *c)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2009-03-12 12:08:49 +00:00
|
|
|
const char *vendor = NULL;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2009-03-14 07:46:17 +00:00
|
|
|
if (c->x86_vendor < X86_VENDOR_NUM) {
|
2005-04-16 22:20:36 +00:00
|
|
|
vendor = this_cpu->c_vendor;
|
2009-03-14 07:46:17 +00:00
|
|
|
} else {
|
|
|
|
if (c->cpuid_level >= 0)
|
|
|
|
vendor = c->x86_vendor_id;
|
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-09-20 01:41:16 +00:00
|
|
|
if (vendor && !strstr(c->x86_model_id, vendor))
|
2008-09-04 19:09:44 +00:00
|
|
|
printk(KERN_CONT "%s ", vendor);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-09-04 19:09:44 +00:00
|
|
|
if (c->x86_model_id[0])
|
|
|
|
printk(KERN_CONT "%s", c->x86_model_id);
|
2005-04-16 22:20:36 +00:00
|
|
|
else
|
2008-09-04 19:09:44 +00:00
|
|
|
printk(KERN_CONT "%d86", c->x86);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-02-24 10:58:13 +00:00
|
|
|
if (c->x86_mask || c->cpuid_level >= 0)
|
2008-09-04 19:09:44 +00:00
|
|
|
printk(KERN_CONT " stepping %02x\n", c->x86_mask);
|
2005-04-16 22:20:36 +00:00
|
|
|
else
|
2008-09-04 19:09:44 +00:00
|
|
|
printk(KERN_CONT "\n");
|
2008-09-04 19:09:46 +00:00
|
|
|
|
2012-03-23 04:31:43 +00:00
|
|
|
print_cpu_msr(c);
|
2012-02-12 17:53:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void __cpuinit print_cpu_msr(struct cpuinfo_x86 *c)
|
|
|
|
{
|
2008-09-04 19:09:46 +00:00
|
|
|
if (c->cpu_index < show_msr)
|
2012-02-12 17:53:57 +00:00
|
|
|
__print_cpu_msr();
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2008-01-30 12:33:21 +00:00
|
|
|
static __init int setup_disablecpuid(char *arg)
|
|
|
|
{
|
|
|
|
int bit;
|
2009-03-14 07:46:17 +00:00
|
|
|
|
2008-01-30 12:33:21 +00:00
|
|
|
if (get_option(&arg, &bit) && bit < NCAPINTS*32)
|
|
|
|
setup_clear_cpu_cap(bit);
|
|
|
|
else
|
|
|
|
return 0;
|
2009-03-14 07:46:17 +00:00
|
|
|
|
2008-01-30 12:33:21 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
__setup("clearcpuid=", setup_disablecpuid);
|
|
|
|
|
2008-09-05 03:09:03 +00:00
|
|
|
#ifdef CONFIG_X86_64
|
2009-07-08 18:03:53 +00:00
|
|
|
struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
|
2011-12-09 08:02:19 +00:00
|
|
|
struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1,
|
|
|
|
(unsigned long) nmi_idt_table };
|
2008-09-05 03:09:03 +00:00
|
|
|
|
2009-01-19 03:21:28 +00:00
|
|
|
DEFINE_PER_CPU_FIRST(union irq_stack_union,
|
|
|
|
irq_stack_union) __aligned(PAGE_SIZE);
|
2009-03-14 07:46:17 +00:00
|
|
|
|
2009-08-03 05:12:19 +00:00
|
|
|
/*
|
|
|
|
* The following four percpu variables are hot. Align current_task to
|
|
|
|
* cacheline size such that all four fall in the same cacheline.
|
|
|
|
*/
|
|
|
|
DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
|
|
|
|
&init_task;
|
|
|
|
EXPORT_PER_CPU_SYMBOL(current_task);
|
2008-09-05 03:09:03 +00:00
|
|
|
|
2009-01-18 15:38:58 +00: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-08-03 05:12:19 +00:00
|
|
|
DEFINE_PER_CPU(char *, irq_stack_ptr) =
|
|
|
|
init_per_cpu_var(irq_stack_union.irq_stack) + IRQ_STACK_SIZE - 64;
|
|
|
|
|
2009-01-18 15:38:58 +00:00
|
|
|
DEFINE_PER_CPU(unsigned int, irq_count) = -1;
|
2008-09-05 03:09:03 +00:00
|
|
|
|
i387: support lazy restore of FPU state
This makes us recognize when we try to restore FPU state that matches
what we already have in the FPU on this CPU, and avoids the restore
entirely if so.
To do this, we add two new data fields:
- a percpu 'fpu_owner_task' variable that gets written any time we
update the "has_fpu" field, and thus acts as a kind of back-pointer
to the task that owns the CPU. The exception is when we save the FPU
state as part of a context switch - if the save can keep the FPU
state around, we leave the 'fpu_owner_task' variable pointing at the
task whose FP state still remains on the CPU.
- a per-thread 'last_cpu' field, that indicates which CPU that thread
used its FPU on last. We update this on every context switch
(writing an invalid CPU number if the last context switch didn't
leave the FPU in a lazily usable state), so we know that *that*
thread has done nothing else with the FPU since.
These two fields together can be used when next switching back to the
task to see if the CPU still matches: if 'fpu_owner_task' matches the
task we are switching to, we know that no other task (or kernel FPU
usage) touched the FPU on this CPU in the meantime, and if the current
CPU number matches the 'last_cpu' field, we know that this thread did no
other FP work on any other CPU, so the FPU state on the CPU must match
what was saved on last context switch.
In that case, we can avoid the 'f[x]rstor' entirely, and just clear the
CR0.TS bit.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2012-02-19 21:27:00 +00:00
|
|
|
DEFINE_PER_CPU(struct task_struct *, fpu_owner_task);
|
|
|
|
|
2009-03-14 07:46:17 +00: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 15:38:58 +00:00
|
|
|
static DEFINE_PER_CPU_PAGE_ALIGNED(char, exception_stacks
|
2009-08-03 05:10:11 +00:00
|
|
|
[(N_EXCEPTION_STACKS - 1) * EXCEPTION_STKSZ + DEBUG_STKSZ]);
|
2008-09-05 03:09:03 +00:00
|
|
|
|
|
|
|
/* May not be marked __init: used by software suspend */
|
|
|
|
void syscall_init(void)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2008-09-05 03:09:03 +00: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 11:00:23 +00:00
|
|
|
|
2008-09-05 03:09:03 +00: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 11:00:23 +00:00
|
|
|
|
2008-09-05 03:09:03 +00:00
|
|
|
/* Flags to clear on syscall */
|
|
|
|
wrmsrl(MSR_SYSCALL_MASK,
|
2012-09-21 19:43:12 +00:00
|
|
|
X86_EFLAGS_TF|X86_EFLAGS_DF|X86_EFLAGS_IF|
|
|
|
|
X86_EFLAGS_IOPL|X86_EFLAGS_AC);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2006-12-07 01:14:02 +00:00
|
|
|
|
2008-09-05 03:09:03 +00: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);
|
|
|
|
|
2011-12-09 08:02:19 +00:00
|
|
|
static DEFINE_PER_CPU(unsigned long, debug_stack_addr);
|
2011-12-16 16:43:02 +00:00
|
|
|
DEFINE_PER_CPU(int, debug_stack_usage);
|
2011-12-09 08:02:19 +00:00
|
|
|
|
|
|
|
int is_debug_stack(unsigned long addr)
|
|
|
|
{
|
2011-12-16 16:43:02 +00:00
|
|
|
return __get_cpu_var(debug_stack_usage) ||
|
|
|
|
(addr <= __get_cpu_var(debug_stack_addr) &&
|
|
|
|
addr > (__get_cpu_var(debug_stack_addr) - DEBUG_STKSZ));
|
2011-12-09 08:02:19 +00:00
|
|
|
}
|
|
|
|
|
2012-05-30 15:47:00 +00:00
|
|
|
static DEFINE_PER_CPU(u32, debug_stack_use_ctr);
|
|
|
|
|
2011-12-09 08:02:19 +00:00
|
|
|
void debug_stack_set_zero(void)
|
|
|
|
{
|
2012-05-30 15:47:00 +00:00
|
|
|
this_cpu_inc(debug_stack_use_ctr);
|
2011-12-09 08:02:19 +00:00
|
|
|
load_idt((const struct desc_ptr *)&nmi_idt_descr);
|
|
|
|
}
|
|
|
|
|
|
|
|
void debug_stack_reset(void)
|
|
|
|
{
|
2012-05-30 15:47:00 +00:00
|
|
|
if (WARN_ON(!this_cpu_read(debug_stack_use_ctr)))
|
|
|
|
return;
|
|
|
|
if (this_cpu_dec_return(debug_stack_use_ctr) == 0)
|
|
|
|
load_idt((const struct desc_ptr *)&idt_descr);
|
2011-12-09 08:02:19 +00:00
|
|
|
}
|
|
|
|
|
2009-03-14 07:46:17 +00:00
|
|
|
#else /* CONFIG_X86_64 */
|
2008-09-05 03:09:03 +00:00
|
|
|
|
2009-08-03 05:12:19 +00:00
|
|
|
DEFINE_PER_CPU(struct task_struct *, current_task) = &init_task;
|
|
|
|
EXPORT_PER_CPU_SYMBOL(current_task);
|
2012-02-21 03:34:10 +00:00
|
|
|
DEFINE_PER_CPU(struct task_struct *, fpu_owner_task);
|
2009-08-03 05:12:19 +00:00
|
|
|
|
2009-02-09 13:17:40 +00:00
|
|
|
#ifdef CONFIG_CC_STACKPROTECTOR
|
2009-09-03 21:31:44 +00:00
|
|
|
DEFINE_PER_CPU_ALIGNED(struct stack_canary, stack_canary);
|
2009-02-09 13:17:40 +00:00
|
|
|
#endif
|
2008-09-05 03:09:03 +00:00
|
|
|
|
2009-02-09 13:17:40 +00:00
|
|
|
/* Make sure %fs and %gs are initialized properly in idle threads */
|
2008-02-06 09:37:55 +00: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 01:14:02 +00:00
|
|
|
{
|
|
|
|
memset(regs, 0, sizeof(struct pt_regs));
|
2008-01-30 12:30:56 +00:00
|
|
|
regs->fs = __KERNEL_PERCPU;
|
2009-02-09 13:17:40 +00:00
|
|
|
regs->gs = __KERNEL_STACK_CANARY;
|
2009-03-14 07:46:17 +00: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 01:14:02 +00:00
|
|
|
return regs;
|
|
|
|
}
|
2009-03-14 07:46:17 +00:00
|
|
|
#endif /* CONFIG_X86_64 */
|
2007-05-02 17:27:16 +00:00
|
|
|
|
2009-03-14 05:49:49 +00: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-02 17:27:16 +00:00
|
|
|
|
2010-05-21 02:04:30 +00:00
|
|
|
#ifdef CONFIG_KGDB
|
|
|
|
/*
|
|
|
|
* Restore debug regs if using kgdbwait and you have a kernel debugger
|
|
|
|
* connection established.
|
|
|
|
*/
|
|
|
|
static void dbg_restore_debug_regs(void)
|
|
|
|
{
|
|
|
|
if (unlikely(kgdb_connected && arch_kgdb_ops.correct_hw_break))
|
|
|
|
arch_kgdb_ops.correct_hw_break();
|
|
|
|
}
|
|
|
|
#else /* ! CONFIG_KGDB */
|
|
|
|
#define dbg_restore_debug_regs()
|
|
|
|
#endif /* ! CONFIG_KGDB */
|
|
|
|
|
2007-05-02 17:27:10 +00: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 03:09:04 +00:00
|
|
|
* A lot of state is already set up in PDA init for 64 bit
|
2007-05-02 17:27:10 +00:00
|
|
|
*/
|
2008-09-05 03:09:04 +00:00
|
|
|
#ifdef CONFIG_X86_64
|
2009-03-14 07:46:17 +00:00
|
|
|
|
2008-09-05 03:09:04 +00:00
|
|
|
void __cpuinit cpu_init(void)
|
|
|
|
{
|
2009-10-29 13:34:14 +00:00
|
|
|
struct orig_ist *oist;
|
2008-09-05 03:09:04 +00:00
|
|
|
struct task_struct *me;
|
2009-03-14 07:46:17 +00:00
|
|
|
struct tss_struct *t;
|
|
|
|
unsigned long v;
|
|
|
|
int cpu;
|
2008-09-05 03:09:04 +00:00
|
|
|
int i;
|
|
|
|
|
2009-03-14 07:46:17 +00:00
|
|
|
cpu = stack_smp_processor_id();
|
|
|
|
t = &per_cpu(init_tss, cpu);
|
2009-10-29 13:34:14 +00:00
|
|
|
oist = &per_cpu(orig_ist, cpu);
|
2009-03-14 07:46:17 +00:00
|
|
|
|
2009-01-18 15:38:59 +00:00
|
|
|
#ifdef CONFIG_NUMA
|
2012-05-11 07:35:27 +00:00
|
|
|
if (cpu != 0 && this_cpu_read(numa_node) == 0 &&
|
2010-05-26 21:44:58 +00:00
|
|
|
early_cpu_to_node(cpu) != NUMA_NO_NODE)
|
|
|
|
set_numa_node(early_cpu_to_node(cpu));
|
2009-01-18 15:38:59 +00:00
|
|
|
#endif
|
2008-09-05 03:09:04 +00:00
|
|
|
|
|
|
|
me = current;
|
|
|
|
|
2009-01-04 13:18:03 +00:00
|
|
|
if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask))
|
2008-09-05 03:09:04 +00:00
|
|
|
panic("CPU#%d already initialized!\n", cpu);
|
|
|
|
|
2009-12-11 01:19:36 +00:00
|
|
|
pr_debug("Initializing CPU#%d\n", cpu);
|
2008-09-05 03:09:04 +00:00
|
|
|
|
|
|
|
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 08:47:53 +00:00
|
|
|
switch_to_new_gdt(cpu);
|
2009-01-27 03:56:48 +00:00
|
|
|
loadsegment(fs, 0);
|
|
|
|
|
2008-09-05 03:09:04 +00: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();
|
|
|
|
|
2009-11-13 23:28:16 +00:00
|
|
|
x86_configure_nx();
|
2009-02-17 01:29:58 +00:00
|
|
|
if (cpu != 0)
|
2008-09-05 03:09:04 +00:00
|
|
|
enable_x2apic();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* set up and load the per-CPU TSS
|
|
|
|
*/
|
2009-10-29 13:34:14 +00:00
|
|
|
if (!oist->ist[0]) {
|
2009-01-18 15:38:58 +00:00
|
|
|
char *estacks = per_cpu(exception_stacks, cpu);
|
2009-03-14 07:46:17 +00:00
|
|
|
|
2008-09-05 03:09:04 +00:00
|
|
|
for (v = 0; v < N_EXCEPTION_STACKS; v++) {
|
2009-03-14 07:46:17 +00:00
|
|
|
estacks += exception_stack_sizes[v];
|
2009-10-29 13:34:14 +00:00
|
|
|
oist->ist[v] = t->x86_tss.ist[v] =
|
2008-09-05 03:09:04 +00:00
|
|
|
(unsigned long)estacks;
|
2011-12-09 08:02:19 +00:00
|
|
|
if (v == DEBUG_STACK-1)
|
|
|
|
per_cpu(debug_stack_addr, cpu) = (unsigned long)estacks;
|
2008-09-05 03:09:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
t->x86_tss.io_bitmap_base = offsetof(struct tss_struct, io_bitmap);
|
2009-03-14 07:46:17 +00:00
|
|
|
|
2008-09-05 03:09:04 +00: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 05:10:32 +00:00
|
|
|
BUG_ON(me->mm);
|
2008-09-05 03:09:04 +00: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);
|
|
|
|
|
2010-05-21 02:04:30 +00:00
|
|
|
clear_all_debug_regs();
|
|
|
|
dbg_restore_debug_regs();
|
2008-09-05 03:09:04 +00:00
|
|
|
|
|
|
|
fpu_init();
|
2010-07-21 17:03:52 +00:00
|
|
|
xsave_init();
|
2008-09-05 03:09:04 +00:00
|
|
|
|
|
|
|
raw_local_save_flags(kernel_eflags);
|
|
|
|
|
|
|
|
if (is_uv_system())
|
|
|
|
uv_cpu_init();
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
2007-05-02 17:27:10 +00:00
|
|
|
void __cpuinit cpu_init(void)
|
2007-01-22 15:18:31 +00:00
|
|
|
{
|
2007-05-02 17:27:10 +00:00
|
|
|
int cpu = smp_processor_id();
|
|
|
|
struct task_struct *curr = current;
|
2008-02-24 10:58:13 +00:00
|
|
|
struct tss_struct *t = &per_cpu(init_tss, cpu);
|
2007-01-22 15:18:31 +00:00
|
|
|
struct thread_struct *thread = &curr->thread;
|
2006-12-07 01:14:02 +00:00
|
|
|
|
2009-01-04 13:18:03 +00:00
|
|
|
if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
|
2006-12-07 01:14:02 +00:00
|
|
|
printk(KERN_WARNING "CPU#%d already initialized!\n", cpu);
|
2009-03-14 05:49:49 +00:00
|
|
|
for (;;)
|
|
|
|
local_irq_enable();
|
2006-12-07 01:14:02 +00: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-03 22:56:38 +00:00
|
|
|
load_idt(&idt_descr);
|
2009-01-30 08:47:53 +00:00
|
|
|
switch_to_new_gdt(cpu);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up and load the per-CPU TSS and LDT
|
|
|
|
*/
|
|
|
|
atomic_inc(&init_mm.mm_count);
|
2006-12-07 01:14:02 +00:00
|
|
|
curr->active_mm = &init_mm;
|
2009-03-10 05:10:32 +00:00
|
|
|
BUG_ON(curr->mm);
|
2006-12-07 01:14:02 +00:00
|
|
|
enter_lazy_tlb(&init_mm, curr);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2008-01-30 12:31:02 +00:00
|
|
|
load_sp0(t, thread);
|
2008-02-24 10:58:13 +00:00
|
|
|
set_tss_desc(cpu, t);
|
2005-04-16 22:20:36 +00:00
|
|
|
load_TR_desc();
|
|
|
|
load_LDT(&init_mm.context);
|
|
|
|
|
2009-05-01 18:59:25 +00:00
|
|
|
t->x86_tss.io_bitmap_base = offsetof(struct tss_struct, io_bitmap);
|
|
|
|
|
2006-01-08 09:05:24 +00:00
|
|
|
#ifdef CONFIG_DOUBLEFAULT
|
2005-04-16 22:20:36 +00:00
|
|
|
/* Set up doublefault TSS pointer in the GDT */
|
|
|
|
__set_tss_desc(cpu, GDT_ENTRY_DOUBLEFAULT_TSS, &doublefault_tss);
|
2006-01-08 09:05:24 +00:00
|
|
|
#endif
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2009-03-14 05:49:49 +00:00
|
|
|
clear_all_debug_regs();
|
2010-05-21 02:04:30 +00:00
|
|
|
dbg_restore_debug_regs();
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2010-07-21 17:03:52 +00:00
|
|
|
fpu_init();
|
2008-07-29 17:29:19 +00:00
|
|
|
xsave_init();
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2008-09-05 03:09:04 +00:00
|
|
|
#endif
|