Update to 3.4-final.
[linux-flexiantxendom0-3.2.10.git] / arch / x86 / kernel / cpu / bugs.c
1 /*
2  *  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>
12 #include <asm/bugs.h>
13 #include <asm/processor.h>
14 #include <asm/processor-flags.h>
15 #include <asm/i387.h>
16 #include <asm/msr.h>
17 #include <asm/paravirt.h>
18 #include <asm/alternative.h>
19
20 #ifndef CONFIG_XEN
21 static int __init no_halt(char *s)
22 {
23         WARN_ONCE(1, "\"no-hlt\" is deprecated, please use \"idle=poll\"\n");
24         boot_cpu_data.hlt_works_ok = 0;
25         return 1;
26 }
27
28 __setup("no-hlt", no_halt);
29 #endif
30
31 static int __init no_387(char *s)
32 {
33         boot_cpu_data.hard_math = 0;
34         write_cr0(X86_CR0_TS | X86_CR0_EM | X86_CR0_MP | read_cr0());
35         return 1;
36 }
37
38 __setup("no387", no_387);
39
40 static double __initdata x = 4195835.0;
41 static double __initdata y = 3145727.0;
42
43 /*
44  * This used to check for exceptions..
45  * However, it turns out that to support that,
46  * the XMM trap handlers basically had to
47  * be buggy. So let's have a correct XMM trap
48  * handler, and forget about printing out
49  * some status at boot.
50  *
51  * We should really only care about bugs here
52  * anyway. Not features.
53  */
54 static void __init check_fpu(void)
55 {
56         s32 fdiv_bug;
57
58         if (!boot_cpu_data.hard_math) {
59 #ifndef CONFIG_MATH_EMULATION
60                 printk(KERN_EMERG "No coprocessor found and no math emulation present.\n");
61                 printk(KERN_EMERG "Giving up.\n");
62                 for (;;) ;
63 #endif
64                 return;
65         }
66
67         kernel_fpu_begin();
68
69         /*
70          * trap_init() enabled FXSR and company _before_ testing for FP
71          * problems here.
72          *
73          * Test for the divl bug..
74          */
75         __asm__("fninit\n\t"
76                 "fldl %1\n\t"
77                 "fdivl %2\n\t"
78                 "fmull %2\n\t"
79                 "fldl %1\n\t"
80                 "fsubp %%st,%%st(1)\n\t"
81                 "fistpl %0\n\t"
82                 "fwait\n\t"
83                 "fninit"
84                 : "=m" (*&fdiv_bug)
85                 : "m" (*&x), "m" (*&y));
86
87         kernel_fpu_end();
88
89 #ifndef CONFIG_XEN
90         boot_cpu_data.fdiv_bug = fdiv_bug;
91         if (boot_cpu_data.fdiv_bug)
92                 printk(KERN_WARNING "Hmm, FPU with FDIV bug.\n");
93 #endif
94 }
95
96 static void __init check_hlt(void)
97 {
98 #ifndef CONFIG_XEN
99         if (boot_cpu_data.x86 >= 5 || paravirt_enabled())
100                 return;
101
102         printk(KERN_INFO "Checking 'hlt' instruction... ");
103         if (!boot_cpu_data.hlt_works_ok) {
104                 printk("disabled\n");
105                 return;
106         }
107         halt();
108         halt();
109         halt();
110         halt();
111         printk(KERN_CONT "OK.\n");
112 #endif
113 }
114
115 /*
116  *      Most 386 processors have a bug where a POPAD can lock the
117  *      machine even from user space.
118  */
119
120 static void __init check_popad(void)
121 {
122 #ifndef CONFIG_X86_POPAD_OK
123         int res, inp = (int) &res;
124
125         printk(KERN_INFO "Checking for popad bug... ");
126         __asm__ __volatile__(
127           "movl $12345678,%%eax; movl $0,%%edi; pusha; popa; movl (%%edx,%%edi),%%ecx "
128           : "=&a" (res)
129           : "d" (inp)
130           : "ecx", "edi");
131         /*
132          * If this fails, it means that any user program may lock the
133          * CPU hard. Too bad.
134          */
135         if (res != 12345678)
136                 printk(KERN_CONT "Buggy.\n");
137         else
138                 printk(KERN_CONT "OK.\n");
139 #endif
140 }
141
142 /*
143  * Check whether we are able to run this kernel safely on SMP.
144  *
145  * - In order to run on a i386, we need to be compiled for i386
146  *   (for due to lack of "invlpg" and working WP on a i386)
147  * - In order to run on anything without a TSC, we need to be
148  *   compiled for a i486.
149  */
150
151 static void __init check_config(void)
152 {
153 /*
154  * We'd better not be a i386 if we're configured to use some
155  * i486+ only features! (WP works in supervisor mode and the
156  * new "invlpg" and "bswap" instructions)
157  */
158 #if defined(CONFIG_X86_WP_WORKS_OK) || defined(CONFIG_X86_INVLPG) || \
159         defined(CONFIG_X86_BSWAP)
160         if (boot_cpu_data.x86 == 3)
161                 panic("Kernel requires i486+ for 'invlpg' and other features");
162 #endif
163 }
164
165
166 void __init check_bugs(void)
167 {
168         identify_boot_cpu();
169 #ifndef CONFIG_SMP
170         printk(KERN_INFO "CPU: ");
171         print_cpu_info(&boot_cpu_data);
172 #endif
173         check_config();
174         check_fpu();
175         check_hlt();
176         check_popad();
177         init_utsname()->machine[1] =
178                 '0' + (boot_cpu_data.x86 > 6 ? 6 : boot_cpu_data.x86);
179         alternative_instructions();
180 }