Jeremy Fitzhardinge | 1353ebb | 2007-05-02 19:27:12 +0200 | [diff] [blame] | 1 | /* |
Jeremy Fitzhardinge | 1353ebb | 2007-05-02 19:27:12 +0200 | [diff] [blame] | 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> |
Josh Triplett | 91eb1b7 | 2007-07-31 00:39:20 -0700 | [diff] [blame] | 12 | #include <asm/bugs.h> |
Jeremy Fitzhardinge | 1353ebb | 2007-05-02 19:27:12 +0200 | [diff] [blame] | 13 | #include <asm/processor.h> |
Dave Jones | 7ebad70 | 2008-01-30 13:30:39 +0100 | [diff] [blame] | 14 | #include <asm/processor-flags.h> |
Jeremy Fitzhardinge | 1353ebb | 2007-05-02 19:27:12 +0200 | [diff] [blame] | 15 | #include <asm/i387.h> |
| 16 | #include <asm/msr.h> |
| 17 | #include <asm/paravirt.h> |
| 18 | #include <asm/alternative.h> |
| 19 | |
| 20 | static int __init no_halt(char *s) |
| 21 | { |
Len Brown | cdaab4a | 2011-04-01 15:41:17 -0400 | [diff] [blame] | 22 | WARN_ONCE(1, "\"no-hlt\" is deprecated, please use \"idle=poll\"\n"); |
Jeremy Fitzhardinge | 1353ebb | 2007-05-02 19:27:12 +0200 | [diff] [blame] | 23 | boot_cpu_data.hlt_works_ok = 0; |
| 24 | return 1; |
| 25 | } |
| 26 | |
| 27 | __setup("no-hlt", no_halt); |
| 28 | |
Jeremy Fitzhardinge | 1353ebb | 2007-05-02 19:27:12 +0200 | [diff] [blame] | 29 | static int __init no_387(char *s) |
| 30 | { |
| 31 | boot_cpu_data.hard_math = 0; |
Dave Jones | 7ebad70 | 2008-01-30 13:30:39 +0100 | [diff] [blame] | 32 | write_cr0(X86_CR0_TS | X86_CR0_EM | X86_CR0_MP | read_cr0()); |
Jeremy Fitzhardinge | 1353ebb | 2007-05-02 19:27:12 +0200 | [diff] [blame] | 33 | return 1; |
| 34 | } |
| 35 | |
| 36 | __setup("no387", no_387); |
| 37 | |
| 38 | static double __initdata x = 4195835.0; |
| 39 | static 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 | */ |
| 52 | static void __init check_fpu(void) |
| 53 | { |
Krzysztof Helt | e0d22d0 | 2008-07-31 23:43:44 +0200 | [diff] [blame] | 54 | s32 fdiv_bug; |
| 55 | |
Jeremy Fitzhardinge | 1353ebb | 2007-05-02 19:27:12 +0200 | [diff] [blame] | 56 | if (!boot_cpu_data.hard_math) { |
| 57 | #ifndef CONFIG_MATH_EMULATION |
| 58 | printk(KERN_EMERG "No coprocessor found and no math emulation present.\n"); |
| 59 | printk(KERN_EMERG "Giving up.\n"); |
| 60 | for (;;) ; |
| 61 | #endif |
| 62 | return; |
| 63 | } |
| 64 | |
Miklos Vajna | bfe4bb1 | 2008-05-17 22:48:13 +0200 | [diff] [blame] | 65 | /* |
| 66 | * trap_init() enabled FXSR and company _before_ testing for FP |
| 67 | * problems here. |
| 68 | * |
| 69 | * Test for the divl bug.. |
| 70 | */ |
Jeremy Fitzhardinge | 1353ebb | 2007-05-02 19:27:12 +0200 | [diff] [blame] | 71 | __asm__("fninit\n\t" |
| 72 | "fldl %1\n\t" |
| 73 | "fdivl %2\n\t" |
| 74 | "fmull %2\n\t" |
| 75 | "fldl %1\n\t" |
| 76 | "fsubp %%st,%%st(1)\n\t" |
| 77 | "fistpl %0\n\t" |
| 78 | "fwait\n\t" |
| 79 | "fninit" |
Krzysztof Helt | e0d22d0 | 2008-07-31 23:43:44 +0200 | [diff] [blame] | 80 | : "=m" (*&fdiv_bug) |
Jeremy Fitzhardinge | 1353ebb | 2007-05-02 19:27:12 +0200 | [diff] [blame] | 81 | : "m" (*&x), "m" (*&y)); |
Krzysztof Helt | e0d22d0 | 2008-07-31 23:43:44 +0200 | [diff] [blame] | 82 | |
| 83 | boot_cpu_data.fdiv_bug = fdiv_bug; |
Jeremy Fitzhardinge | 1353ebb | 2007-05-02 19:27:12 +0200 | [diff] [blame] | 84 | if (boot_cpu_data.fdiv_bug) |
Alan Cox | 8bdbd96 | 2009-07-04 00:35:45 +0100 | [diff] [blame] | 85 | printk(KERN_WARNING "Hmm, FPU with FDIV bug.\n"); |
Jeremy Fitzhardinge | 1353ebb | 2007-05-02 19:27:12 +0200 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | static void __init check_hlt(void) |
| 89 | { |
Jacob Pan | 2b107d9 | 2010-05-07 14:59:45 -0700 | [diff] [blame] | 90 | if (boot_cpu_data.x86 >= 5 || paravirt_enabled()) |
Jeremy Fitzhardinge | 1353ebb | 2007-05-02 19:27:12 +0200 | [diff] [blame] | 91 | return; |
| 92 | |
| 93 | printk(KERN_INFO "Checking 'hlt' instruction... "); |
| 94 | if (!boot_cpu_data.hlt_works_ok) { |
| 95 | printk("disabled\n"); |
| 96 | return; |
| 97 | } |
| 98 | halt(); |
| 99 | halt(); |
| 100 | halt(); |
| 101 | halt(); |
Alan Cox | 8bdbd96 | 2009-07-04 00:35:45 +0100 | [diff] [blame] | 102 | printk(KERN_CONT "OK.\n"); |
Jeremy Fitzhardinge | 1353ebb | 2007-05-02 19:27:12 +0200 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | /* |
| 106 | * Most 386 processors have a bug where a POPAD can lock the |
| 107 | * machine even from user space. |
| 108 | */ |
| 109 | |
| 110 | static void __init check_popad(void) |
| 111 | { |
| 112 | #ifndef CONFIG_X86_POPAD_OK |
| 113 | int res, inp = (int) &res; |
| 114 | |
| 115 | printk(KERN_INFO "Checking for popad bug... "); |
| 116 | __asm__ __volatile__( |
| 117 | "movl $12345678,%%eax; movl $0,%%edi; pusha; popa; movl (%%edx,%%edi),%%ecx " |
| 118 | : "=&a" (res) |
| 119 | : "d" (inp) |
Miklos Vajna | bfe4bb1 | 2008-05-17 22:48:13 +0200 | [diff] [blame] | 120 | : "ecx", "edi"); |
| 121 | /* |
| 122 | * If this fails, it means that any user program may lock the |
| 123 | * CPU hard. Too bad. |
| 124 | */ |
| 125 | if (res != 12345678) |
Alan Cox | 8bdbd96 | 2009-07-04 00:35:45 +0100 | [diff] [blame] | 126 | printk(KERN_CONT "Buggy.\n"); |
Miklos Vajna | bfe4bb1 | 2008-05-17 22:48:13 +0200 | [diff] [blame] | 127 | else |
Alan Cox | 8bdbd96 | 2009-07-04 00:35:45 +0100 | [diff] [blame] | 128 | printk(KERN_CONT "OK.\n"); |
Jeremy Fitzhardinge | 1353ebb | 2007-05-02 19:27:12 +0200 | [diff] [blame] | 129 | #endif |
| 130 | } |
| 131 | |
| 132 | /* |
| 133 | * Check whether we are able to run this kernel safely on SMP. |
| 134 | * |
| 135 | * - In order to run on a i386, we need to be compiled for i386 |
| 136 | * (for due to lack of "invlpg" and working WP on a i386) |
| 137 | * - In order to run on anything without a TSC, we need to be |
| 138 | * compiled for a i486. |
Maciej W. Rozycki | 593f4a7 | 2008-07-16 19:15:30 +0100 | [diff] [blame] | 139 | */ |
Jeremy Fitzhardinge | 1353ebb | 2007-05-02 19:27:12 +0200 | [diff] [blame] | 140 | |
| 141 | static void __init check_config(void) |
| 142 | { |
| 143 | /* |
| 144 | * We'd better not be a i386 if we're configured to use some |
| 145 | * i486+ only features! (WP works in supervisor mode and the |
| 146 | * new "invlpg" and "bswap" instructions) |
| 147 | */ |
Miklos Vajna | bfe4bb1 | 2008-05-17 22:48:13 +0200 | [diff] [blame] | 148 | #if defined(CONFIG_X86_WP_WORKS_OK) || defined(CONFIG_X86_INVLPG) || \ |
| 149 | defined(CONFIG_X86_BSWAP) |
Jeremy Fitzhardinge | 1353ebb | 2007-05-02 19:27:12 +0200 | [diff] [blame] | 150 | if (boot_cpu_data.x86 == 3) |
| 151 | panic("Kernel requires i486+ for 'invlpg' and other features"); |
| 152 | #endif |
Jeremy Fitzhardinge | 1353ebb | 2007-05-02 19:27:12 +0200 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | |
| 156 | void __init check_bugs(void) |
| 157 | { |
| 158 | identify_boot_cpu(); |
| 159 | #ifndef CONFIG_SMP |
Alan Cox | 8bdbd96 | 2009-07-04 00:35:45 +0100 | [diff] [blame] | 160 | printk(KERN_INFO "CPU: "); |
Jeremy Fitzhardinge | 1353ebb | 2007-05-02 19:27:12 +0200 | [diff] [blame] | 161 | print_cpu_info(&boot_cpu_data); |
| 162 | #endif |
| 163 | check_config(); |
| 164 | check_fpu(); |
| 165 | check_hlt(); |
| 166 | check_popad(); |
Miklos Vajna | bfe4bb1 | 2008-05-17 22:48:13 +0200 | [diff] [blame] | 167 | init_utsname()->machine[1] = |
| 168 | '0' + (boot_cpu_data.x86 > 6 ? 6 : boot_cpu_data.x86); |
Jeremy Fitzhardinge | 1353ebb | 2007-05-02 19:27:12 +0200 | [diff] [blame] | 169 | alternative_instructions(); |
| 170 | } |