blob: 92dfec986a48ec97ffb680002f22a56f5a7b9262 [file] [log] [blame]
Jeremy Fitzhardinge1353ebb2007-05-02 19:27:12 +02001/*
Jeremy Fitzhardinge1353ebb2007-05-02 19:27:12 +02002 * Copyright (C) 1994 Linus Torvalds
3 *
4 * Cyrix stuff, June 1998 by:
5 * - Rafael R. Reilova (moved everything from head.S),
6 * <rreilova@ececs.uc.edu>
7 * - Channing Corn (tests & fixes),
8 * - Andrew D. Balsa (code cleanup).
9 */
10#include <linux/init.h>
11#include <linux/utsname.h>
Josh Triplett91eb1b72007-07-31 00:39:20 -070012#include <asm/bugs.h>
Jeremy Fitzhardinge1353ebb2007-05-02 19:27:12 +020013#include <asm/processor.h>
Dave Jones7ebad702008-01-30 13:30:39 +010014#include <asm/processor-flags.h>
Jeremy Fitzhardinge1353ebb2007-05-02 19:27:12 +020015#include <asm/i387.h>
16#include <asm/msr.h>
17#include <asm/paravirt.h>
18#include <asm/alternative.h>
19
20static int __init no_halt(char *s)
21{
Len Browncdaab4a2011-04-01 15:41:17 -040022 WARN_ONCE(1, "\"no-hlt\" is deprecated, please use \"idle=poll\"\n");
Jeremy Fitzhardinge1353ebb2007-05-02 19:27:12 +020023 boot_cpu_data.hlt_works_ok = 0;
24 return 1;
25}
26
27__setup("no-hlt", no_halt);
28
Jeremy Fitzhardinge1353ebb2007-05-02 19:27:12 +020029static int __init no_387(char *s)
30{
31 boot_cpu_data.hard_math = 0;
Dave Jones7ebad702008-01-30 13:30:39 +010032 write_cr0(X86_CR0_TS | X86_CR0_EM | X86_CR0_MP | read_cr0());
Jeremy Fitzhardinge1353ebb2007-05-02 19:27:12 +020033 return 1;
34}
35
36__setup("no387", no_387);
37
38static double __initdata x = 4195835.0;
39static double __initdata y = 3145727.0;
40
41/*
42 * This used to check for exceptions..
43 * However, it turns out that to support that,
44 * the XMM trap handlers basically had to
45 * be buggy. So let's have a correct XMM trap
46 * handler, and forget about printing out
47 * some status at boot.
48 *
49 * We should really only care about bugs here
50 * anyway. Not features.
51 */
52static void __init check_fpu(void)
53{
Krzysztof Helte0d22d02008-07-31 23:43:44 +020054 s32 fdiv_bug;
55
Jeremy Fitzhardinge1353ebb2007-05-02 19:27:12 +020056 if (!boot_cpu_data.hard_math) {
57#ifndef CONFIG_MATH_EMULATION
Joe Perchesc767a542012-05-21 19:50:07 -070058 pr_emerg("No coprocessor found and no math emulation present\n");
59 pr_emerg("Giving up\n");
Jeremy Fitzhardinge1353ebb2007-05-02 19:27:12 +020060 for (;;) ;
61#endif
62 return;
63 }
64
Suresh Siddha3e7cf5b2011-06-30 17:19:32 -070065 kernel_fpu_begin();
66
Miklos Vajnabfe4bb12008-05-17 22:48:13 +020067 /*
68 * trap_init() enabled FXSR and company _before_ testing for FP
69 * problems here.
70 *
71 * Test for the divl bug..
72 */
Jeremy Fitzhardinge1353ebb2007-05-02 19:27:12 +020073 __asm__("fninit\n\t"
74 "fldl %1\n\t"
75 "fdivl %2\n\t"
76 "fmull %2\n\t"
77 "fldl %1\n\t"
78 "fsubp %%st,%%st(1)\n\t"
79 "fistpl %0\n\t"
80 "fwait\n\t"
81 "fninit"
Krzysztof Helte0d22d02008-07-31 23:43:44 +020082 : "=m" (*&fdiv_bug)
Jeremy Fitzhardinge1353ebb2007-05-02 19:27:12 +020083 : "m" (*&x), "m" (*&y));
Krzysztof Helte0d22d02008-07-31 23:43:44 +020084
Suresh Siddha3e7cf5b2011-06-30 17:19:32 -070085 kernel_fpu_end();
86
Krzysztof Helte0d22d02008-07-31 23:43:44 +020087 boot_cpu_data.fdiv_bug = fdiv_bug;
Jeremy Fitzhardinge1353ebb2007-05-02 19:27:12 +020088 if (boot_cpu_data.fdiv_bug)
Joe Perchesc767a542012-05-21 19:50:07 -070089 pr_warn("Hmm, FPU with FDIV bug\n");
Jeremy Fitzhardinge1353ebb2007-05-02 19:27:12 +020090}
91
92static void __init check_hlt(void)
93{
Jacob Pan2b107d92010-05-07 14:59:45 -070094 if (boot_cpu_data.x86 >= 5 || paravirt_enabled())
Jeremy Fitzhardinge1353ebb2007-05-02 19:27:12 +020095 return;
96
Joe Perchesc767a542012-05-21 19:50:07 -070097 pr_info("Checking 'hlt' instruction... ");
Jeremy Fitzhardinge1353ebb2007-05-02 19:27:12 +020098 if (!boot_cpu_data.hlt_works_ok) {
Joe Perchesc767a542012-05-21 19:50:07 -070099 pr_cont("disabled\n");
Jeremy Fitzhardinge1353ebb2007-05-02 19:27:12 +0200100 return;
101 }
102 halt();
103 halt();
104 halt();
105 halt();
Joe Perchesc767a542012-05-21 19:50:07 -0700106 pr_cont("OK\n");
Jeremy Fitzhardinge1353ebb2007-05-02 19:27:12 +0200107}
108
109/*
Jeremy Fitzhardinge1353ebb2007-05-02 19:27:12 +0200110 * Check whether we are able to run this kernel safely on SMP.
111 *
H. Peter Anvine5bb8ad2012-11-28 11:50:26 -0800112 * - i386 is no longer supported.
Jeremy Fitzhardinge1353ebb2007-05-02 19:27:12 +0200113 * - In order to run on anything without a TSC, we need to be
114 * compiled for a i486.
Maciej W. Rozycki593f4a72008-07-16 19:15:30 +0100115 */
Jeremy Fitzhardinge1353ebb2007-05-02 19:27:12 +0200116
117static void __init check_config(void)
118{
H. Peter Anvine5bb8ad2012-11-28 11:50:26 -0800119 if (boot_cpu_data.x86 < 4)
Jeremy Fitzhardinge1353ebb2007-05-02 19:27:12 +0200120 panic("Kernel requires i486+ for 'invlpg' and other features");
Jeremy Fitzhardinge1353ebb2007-05-02 19:27:12 +0200121}
122
123
124void __init check_bugs(void)
125{
126 identify_boot_cpu();
127#ifndef CONFIG_SMP
Joe Perchesc767a542012-05-21 19:50:07 -0700128 pr_info("CPU: ");
Jeremy Fitzhardinge1353ebb2007-05-02 19:27:12 +0200129 print_cpu_info(&boot_cpu_data);
130#endif
131 check_config();
Jeremy Fitzhardinge1353ebb2007-05-02 19:27:12 +0200132 check_hlt();
Miklos Vajnabfe4bb12008-05-17 22:48:13 +0200133 init_utsname()->machine[1] =
134 '0' + (boot_cpu_data.x86 > 6 ? 6 : boot_cpu_data.x86);
Jeremy Fitzhardinge1353ebb2007-05-02 19:27:12 +0200135 alternative_instructions();
Suresh Siddha304bced2012-08-24 14:13:02 -0700136
137 /*
138 * kernel_fpu_begin/end() in check_fpu() relies on the patched
139 * alternative instructions.
140 */
141 check_fpu();
Jeremy Fitzhardinge1353ebb2007-05-02 19:27:12 +0200142}