50233e0345fba1e729d00293419d11f422a532b2
[linux-drm-fsl-dcu.git] / include / asm-i386 / bugs.h
1 /*
2  *  include/asm-i386/bugs.h
3  *
4  *  Copyright (C) 1994  Linus Torvalds
5  *
6  *  Cyrix stuff, June 1998 by:
7  *      - Rafael R. Reilova (moved everything from head.S),
8  *        <rreilova@ececs.uc.edu>
9  *      - Channing Corn (tests & fixes),
10  *      - Andrew D. Balsa (code cleanup).
11  */
12
13 /*
14  * This is included by init/main.c to check for architecture-dependent bugs.
15  *
16  * Needs:
17  *      void check_bugs(void);
18  */
19
20 #include <linux/config.h>
21 #include <linux/init.h>
22 #include <asm/processor.h>
23 #include <asm/i387.h>
24 #include <asm/msr.h>
25
26 static int __init no_halt(char *s)
27 {
28         boot_cpu_data.hlt_works_ok = 0;
29         return 1;
30 }
31
32 __setup("no-hlt", no_halt);
33
34 static int __init mca_pentium(char *s)
35 {
36         mca_pentium_flag = 1;
37         return 1;
38 }
39
40 __setup("mca-pentium", mca_pentium);
41
42 static int __init no_387(char *s)
43 {
44         boot_cpu_data.hard_math = 0;
45         write_cr0(0xE | read_cr0());
46         return 1;
47 }
48
49 __setup("no387", no_387);
50
51 static double __initdata x = 4195835.0;
52 static double __initdata y = 3145727.0;
53
54 /*
55  * This used to check for exceptions.. 
56  * However, it turns out that to support that,
57  * the XMM trap handlers basically had to
58  * be buggy. So let's have a correct XMM trap
59  * handler, and forget about printing out
60  * some status at boot.
61  *
62  * We should really only care about bugs here
63  * anyway. Not features.
64  */
65 static void __init check_fpu(void)
66 {
67         if (!boot_cpu_data.hard_math) {
68 #ifndef CONFIG_MATH_EMULATION
69                 printk(KERN_EMERG "No coprocessor found and no math emulation present.\n");
70                 printk(KERN_EMERG "Giving up.\n");
71                 for (;;) ;
72 #endif
73                 return;
74         }
75
76 /* trap_init() enabled FXSR and company _before_ testing for FP problems here. */
77         /* Test for the divl bug.. */
78         __asm__("fninit\n\t"
79                 "fldl %1\n\t"
80                 "fdivl %2\n\t"
81                 "fmull %2\n\t"
82                 "fldl %1\n\t"
83                 "fsubp %%st,%%st(1)\n\t"
84                 "fistpl %0\n\t"
85                 "fwait\n\t"
86                 "fninit"
87                 : "=m" (*&boot_cpu_data.fdiv_bug)
88                 : "m" (*&x), "m" (*&y));
89         if (boot_cpu_data.fdiv_bug)
90                 printk("Hmm, FPU with FDIV bug.\n");
91 }
92
93 static void __init check_hlt(void)
94 {
95         printk(KERN_INFO "Checking 'hlt' instruction... ");
96         if (!boot_cpu_data.hlt_works_ok) {
97                 printk("disabled\n");
98                 return;
99         }
100         halt();
101         halt();
102         halt();
103         halt();
104         printk("OK.\n");
105 }
106
107 /*
108  *      Most 386 processors have a bug where a POPAD can lock the 
109  *      machine even from user space.
110  */
111  
112 static void __init check_popad(void)
113 {
114 #ifndef CONFIG_X86_POPAD_OK
115         int res, inp = (int) &res;
116
117         printk(KERN_INFO "Checking for popad bug... ");
118         __asm__ __volatile__( 
119           "movl $12345678,%%eax; movl $0,%%edi; pusha; popa; movl (%%edx,%%edi),%%ecx "
120           : "=&a" (res)
121           : "d" (inp)
122           : "ecx", "edi" );
123         /* If this fails, it means that any user program may lock the CPU hard. Too bad. */
124         if (res != 12345678) printk( "Buggy.\n" );
125                         else printk( "OK.\n" );
126 #endif
127 }
128
129 /*
130  * Check whether we are able to run this kernel safely on SMP.
131  *
132  * - In order to run on a i386, we need to be compiled for i386
133  *   (for due to lack of "invlpg" and working WP on a i386)
134  * - In order to run on anything without a TSC, we need to be
135  *   compiled for a i486.
136  * - In order to support the local APIC on a buggy Pentium machine,
137  *   we need to be compiled with CONFIG_X86_GOOD_APIC disabled,
138  *   which happens implicitly if compiled for a Pentium or lower
139  *   (unless an advanced selection of CPU features is used) as an
140  *   otherwise config implies a properly working local APIC without
141  *   the need to do extra reads from the APIC.
142 */
143
144 static void __init check_config(void)
145 {
146 /*
147  * We'd better not be a i386 if we're configured to use some
148  * i486+ only features! (WP works in supervisor mode and the
149  * new "invlpg" and "bswap" instructions)
150  */
151 #if defined(CONFIG_X86_WP_WORKS_OK) || defined(CONFIG_X86_INVLPG) || defined(CONFIG_X86_BSWAP)
152         if (boot_cpu_data.x86 == 3)
153                 panic("Kernel requires i486+ for 'invlpg' and other features");
154 #endif
155
156 /*
157  * If we configured ourselves for a TSC, we'd better have one!
158  */
159 #ifdef CONFIG_X86_TSC
160         if (!cpu_has_tsc)
161                 panic("Kernel compiled for Pentium+, requires TSC feature!");
162 #endif
163
164 /*
165  * If we were told we had a good local APIC, check for buggy Pentia,
166  * i.e. all B steppings and the C2 stepping of P54C when using their
167  * integrated APIC (see 11AP erratum in "Pentium Processor
168  * Specification Update").
169  */
170 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86_GOOD_APIC)
171         if (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL
172             && cpu_has_apic
173             && boot_cpu_data.x86 == 5
174             && boot_cpu_data.x86_model == 2
175             && (boot_cpu_data.x86_mask < 6 || boot_cpu_data.x86_mask == 11))
176                 panic("Kernel compiled for PMMX+, assumes a local APIC without the read-before-write bug!");
177 #endif
178 }
179
180 extern void alternative_instructions(void);
181
182 static void __init check_bugs(void)
183 {
184         identify_cpu(&boot_cpu_data);
185 #ifndef CONFIG_SMP
186         printk("CPU: ");
187         print_cpu_info(&boot_cpu_data);
188 #endif
189         check_config();
190         check_fpu();
191         check_hlt();
192         check_popad();
193         system_utsname.machine[1] = '0' + (boot_cpu_data.x86 > 6 ? 6 : boot_cpu_data.x86);
194         alternative_instructions(); 
195 }