2007-05-02 17:27:12 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 1994 Linus Torvalds
|
|
|
|
*
|
|
|
|
* Cyrix stuff, June 1998 by:
|
|
|
|
* - Rafael R. Reilova (moved everything from head.S),
|
|
|
|
* <rreilova@ececs.uc.edu>
|
|
|
|
* - Channing Corn (tests & fixes),
|
|
|
|
* - Andrew D. Balsa (code cleanup).
|
|
|
|
*/
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/utsname.h>
|
2007-07-31 07:39:20 +00:00
|
|
|
#include <asm/bugs.h>
|
2007-05-02 17:27:12 +00:00
|
|
|
#include <asm/processor.h>
|
2008-01-30 12:30:39 +00:00
|
|
|
#include <asm/processor-flags.h>
|
2007-05-02 17:27:12 +00:00
|
|
|
#include <asm/i387.h>
|
|
|
|
#include <asm/msr.h>
|
|
|
|
#include <asm/paravirt.h>
|
|
|
|
#include <asm/alternative.h>
|
|
|
|
|
|
|
|
static int __init no_halt(char *s)
|
|
|
|
{
|
2011-04-01 19:41:17 +00:00
|
|
|
WARN_ONCE(1, "\"no-hlt\" is deprecated, please use \"idle=poll\"\n");
|
2007-05-02 17:27:12 +00:00
|
|
|
boot_cpu_data.hlt_works_ok = 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
__setup("no-hlt", no_halt);
|
|
|
|
|
|
|
|
static int __init no_387(char *s)
|
|
|
|
{
|
|
|
|
boot_cpu_data.hard_math = 0;
|
2008-01-30 12:30:39 +00:00
|
|
|
write_cr0(X86_CR0_TS | X86_CR0_EM | X86_CR0_MP | read_cr0());
|
2007-05-02 17:27:12 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
__setup("no387", no_387);
|
|
|
|
|
|
|
|
static double __initdata x = 4195835.0;
|
|
|
|
static double __initdata y = 3145727.0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This used to check for exceptions..
|
|
|
|
* However, it turns out that to support that,
|
|
|
|
* the XMM trap handlers basically had to
|
|
|
|
* be buggy. So let's have a correct XMM trap
|
|
|
|
* handler, and forget about printing out
|
|
|
|
* some status at boot.
|
|
|
|
*
|
|
|
|
* We should really only care about bugs here
|
|
|
|
* anyway. Not features.
|
|
|
|
*/
|
|
|
|
static void __init check_fpu(void)
|
|
|
|
{
|
2008-07-31 21:43:44 +00:00
|
|
|
s32 fdiv_bug;
|
|
|
|
|
2007-05-02 17:27:12 +00:00
|
|
|
if (!boot_cpu_data.hard_math) {
|
|
|
|
#ifndef CONFIG_MATH_EMULATION
|
2012-05-22 02:50:07 +00:00
|
|
|
pr_emerg("No coprocessor found and no math emulation present\n");
|
|
|
|
pr_emerg("Giving up\n");
|
2007-05-02 17:27:12 +00:00
|
|
|
for (;;) ;
|
|
|
|
#endif
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-07-01 00:19:32 +00:00
|
|
|
kernel_fpu_begin();
|
|
|
|
|
2008-05-17 20:48:13 +00:00
|
|
|
/*
|
|
|
|
* trap_init() enabled FXSR and company _before_ testing for FP
|
|
|
|
* problems here.
|
|
|
|
*
|
|
|
|
* Test for the divl bug..
|
|
|
|
*/
|
2007-05-02 17:27:12 +00:00
|
|
|
__asm__("fninit\n\t"
|
|
|
|
"fldl %1\n\t"
|
|
|
|
"fdivl %2\n\t"
|
|
|
|
"fmull %2\n\t"
|
|
|
|
"fldl %1\n\t"
|
|
|
|
"fsubp %%st,%%st(1)\n\t"
|
|
|
|
"fistpl %0\n\t"
|
|
|
|
"fwait\n\t"
|
|
|
|
"fninit"
|
2008-07-31 21:43:44 +00:00
|
|
|
: "=m" (*&fdiv_bug)
|
2007-05-02 17:27:12 +00:00
|
|
|
: "m" (*&x), "m" (*&y));
|
2008-07-31 21:43:44 +00:00
|
|
|
|
2011-07-01 00:19:32 +00:00
|
|
|
kernel_fpu_end();
|
|
|
|
|
2008-07-31 21:43:44 +00:00
|
|
|
boot_cpu_data.fdiv_bug = fdiv_bug;
|
2007-05-02 17:27:12 +00:00
|
|
|
if (boot_cpu_data.fdiv_bug)
|
2012-05-22 02:50:07 +00:00
|
|
|
pr_warn("Hmm, FPU with FDIV bug\n");
|
2007-05-02 17:27:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void __init check_hlt(void)
|
|
|
|
{
|
2010-05-07 21:59:45 +00:00
|
|
|
if (boot_cpu_data.x86 >= 5 || paravirt_enabled())
|
2007-05-02 17:27:12 +00:00
|
|
|
return;
|
|
|
|
|
2012-05-22 02:50:07 +00:00
|
|
|
pr_info("Checking 'hlt' instruction... ");
|
2007-05-02 17:27:12 +00:00
|
|
|
if (!boot_cpu_data.hlt_works_ok) {
|
2012-05-22 02:50:07 +00:00
|
|
|
pr_cont("disabled\n");
|
2007-05-02 17:27:12 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
halt();
|
|
|
|
halt();
|
|
|
|
halt();
|
|
|
|
halt();
|
2012-05-22 02:50:07 +00:00
|
|
|
pr_cont("OK\n");
|
2007-05-02 17:27:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Most 386 processors have a bug where a POPAD can lock the
|
|
|
|
* machine even from user space.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void __init check_popad(void)
|
|
|
|
{
|
|
|
|
#ifndef CONFIG_X86_POPAD_OK
|
|
|
|
int res, inp = (int) &res;
|
|
|
|
|
2012-05-22 02:50:07 +00:00
|
|
|
pr_info("Checking for popad bug... ");
|
2007-05-02 17:27:12 +00:00
|
|
|
__asm__ __volatile__(
|
|
|
|
"movl $12345678,%%eax; movl $0,%%edi; pusha; popa; movl (%%edx,%%edi),%%ecx "
|
|
|
|
: "=&a" (res)
|
|
|
|
: "d" (inp)
|
2008-05-17 20:48:13 +00:00
|
|
|
: "ecx", "edi");
|
|
|
|
/*
|
|
|
|
* If this fails, it means that any user program may lock the
|
|
|
|
* CPU hard. Too bad.
|
|
|
|
*/
|
|
|
|
if (res != 12345678)
|
2012-05-22 02:50:07 +00:00
|
|
|
pr_cont("Buggy\n");
|
2008-05-17 20:48:13 +00:00
|
|
|
else
|
2012-05-22 02:50:07 +00:00
|
|
|
pr_cont("OK\n");
|
2007-05-02 17:27:12 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check whether we are able to run this kernel safely on SMP.
|
|
|
|
*
|
|
|
|
* - In order to run on a i386, we need to be compiled for i386
|
|
|
|
* (for due to lack of "invlpg" and working WP on a i386)
|
|
|
|
* - In order to run on anything without a TSC, we need to be
|
|
|
|
* compiled for a i486.
|
x86: APIC: remove apic_write_around(); use alternatives
Use alternatives to select the workaround for the 11AP Pentium erratum
for the affected steppings on the fly rather than build time. Remove the
X86_GOOD_APIC configuration option and replace all the calls to
apic_write_around() with plain apic_write(), protecting accesses to the
ESR as appropriate due to the 3AP Pentium erratum. Remove
apic_read_around() and all its invocations altogether as not needed.
Remove apic_write_atomic() and all its implementing backends. The use of
ASM_OUTPUT2() is not strictly needed for input constraints, but I have
used it for readability's sake.
I had the feeling no one else was brave enough to do it, so I went ahead
and here it is. Verified by checking the generated assembly and tested
with both a 32-bit and a 64-bit configuration, also with the 11AP
"feature" forced on and verified with gdb on /proc/kcore to work as
expected (as an 11AP machines are quite hard to get hands on these days).
Some script complained about the use of "volatile", but apic_write() needs
it for the same reason and is effectively a replacement for writel(), so I
have disregarded it.
I am not sure what the policy wrt defconfig files is, they are generated
and there is risk of a conflict resulting from an unrelated change, so I
have left changes to them out. The option will get removed from them at
the next run.
Some testing with machines other than mine will be needed to avoid some
stupid mistake, but despite its volume, the change is not really that
intrusive, so I am fairly confident that because it works for me, it will
everywhere.
Signed-off-by: Maciej W. Rozycki <macro@linux-mips.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2008-07-16 18:15:30 +00:00
|
|
|
*/
|
2007-05-02 17:27:12 +00:00
|
|
|
|
|
|
|
static void __init check_config(void)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* We'd better not be a i386 if we're configured to use some
|
|
|
|
* i486+ only features! (WP works in supervisor mode and the
|
|
|
|
* new "invlpg" and "bswap" instructions)
|
|
|
|
*/
|
2008-05-17 20:48:13 +00:00
|
|
|
#if defined(CONFIG_X86_WP_WORKS_OK) || defined(CONFIG_X86_INVLPG) || \
|
|
|
|
defined(CONFIG_X86_BSWAP)
|
2007-05-02 17:27:12 +00:00
|
|
|
if (boot_cpu_data.x86 == 3)
|
|
|
|
panic("Kernel requires i486+ for 'invlpg' and other features");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void __init check_bugs(void)
|
|
|
|
{
|
|
|
|
identify_boot_cpu();
|
|
|
|
#ifndef CONFIG_SMP
|
2012-05-22 02:50:07 +00:00
|
|
|
pr_info("CPU: ");
|
2007-05-02 17:27:12 +00:00
|
|
|
print_cpu_info(&boot_cpu_data);
|
|
|
|
#endif
|
|
|
|
check_config();
|
|
|
|
check_fpu();
|
|
|
|
check_hlt();
|
|
|
|
check_popad();
|
2008-05-17 20:48:13 +00:00
|
|
|
init_utsname()->machine[1] =
|
|
|
|
'0' + (boot_cpu_data.x86 > 6 ? 6 : boot_cpu_data.x86);
|
2007-05-02 17:27:12 +00:00
|
|
|
alternative_instructions();
|
|
|
|
}
|