Peter Zijlstra | acb0405 | 2017-01-19 14:36:33 +0100 | [diff] [blame] | 1 | |
| 2 | #include <linux/sched.h> |
Ingo Molnar | e601757 | 2017-02-01 16:36:40 +0100 | [diff] [blame] | 3 | #include <linux/sched/clock.h> |
Ingo Molnar | edc05e6 | 2008-02-18 03:30:47 +0100 | [diff] [blame] | 4 | |
Borislav Petkov | cd4d09e | 2016-01-26 22:12:04 +0100 | [diff] [blame] | 5 | #include <asm/cpufeature.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | #include <asm/e820.h> |
Jesper Juhl | 52f4a91 | 2006-03-23 02:59:50 -0800 | [diff] [blame] | 7 | #include <asm/mtrr.h> |
Sebastian Andrzej Siewior | 48f4c48 | 2009-03-14 12:24:02 +0100 | [diff] [blame] | 8 | #include <asm/msr.h> |
Ingo Molnar | edc05e6 | 2008-02-18 03:30:47 +0100 | [diff] [blame] | 9 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include "cpu.h" |
| 11 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #define ACE_PRESENT (1 << 6) |
| 13 | #define ACE_ENABLED (1 << 7) |
| 14 | #define ACE_FCR (1 << 28) /* MSR_VIA_FCR */ |
| 15 | |
| 16 | #define RNG_PRESENT (1 << 2) |
| 17 | #define RNG_ENABLED (1 << 3) |
| 18 | #define RNG_ENABLE (1 << 6) /* MSR_VIA_RNG */ |
| 19 | |
Paul Gortmaker | 148f9bb | 2013-06-18 18:23:59 -0400 | [diff] [blame] | 20 | static void init_c3(struct cpuinfo_x86 *c) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | { |
| 22 | u32 lo, hi; |
| 23 | |
| 24 | /* Test for Centaur Extended Feature Flags presence */ |
| 25 | if (cpuid_eax(0xC0000000) >= 0xC0000001) { |
| 26 | u32 tmp = cpuid_edx(0xC0000001); |
| 27 | |
| 28 | /* enable ACE unit, if present and disabled */ |
| 29 | if ((tmp & (ACE_PRESENT | ACE_ENABLED)) == ACE_PRESENT) { |
Paolo Ciarrocchi | 29a9994 | 2008-02-17 23:30:23 +0100 | [diff] [blame] | 30 | rdmsr(MSR_VIA_FCR, lo, hi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | lo |= ACE_FCR; /* enable ACE unit */ |
Paolo Ciarrocchi | 29a9994 | 2008-02-17 23:30:23 +0100 | [diff] [blame] | 32 | wrmsr(MSR_VIA_FCR, lo, hi); |
Chen Yucong | 1b74dde | 2016-02-02 11:45:02 +0800 | [diff] [blame] | 33 | pr_info("CPU: Enabled ACE h/w crypto\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | /* enable RNG unit, if present and disabled */ |
| 37 | if ((tmp & (RNG_PRESENT | RNG_ENABLED)) == RNG_PRESENT) { |
Paolo Ciarrocchi | 29a9994 | 2008-02-17 23:30:23 +0100 | [diff] [blame] | 38 | rdmsr(MSR_VIA_RNG, lo, hi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | lo |= RNG_ENABLE; /* enable RNG unit */ |
Paolo Ciarrocchi | 29a9994 | 2008-02-17 23:30:23 +0100 | [diff] [blame] | 40 | wrmsr(MSR_VIA_RNG, lo, hi); |
Chen Yucong | 1b74dde | 2016-02-02 11:45:02 +0800 | [diff] [blame] | 41 | pr_info("CPU: Enabled h/w RNG\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | /* store Centaur Extended Feature Flags as |
| 45 | * word 5 of the CPU capability bit array |
| 46 | */ |
Borislav Petkov | 39c06df | 2015-12-07 10:39:40 +0100 | [diff] [blame] | 47 | c->x86_capability[CPUID_C000_0001_EDX] = cpuid_edx(0xC0000001); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | } |
Sebastian Andrzej Siewior | 48f4c48 | 2009-03-14 12:24:02 +0100 | [diff] [blame] | 49 | #ifdef CONFIG_X86_32 |
Simon Arlott | 27b46d7 | 2007-10-20 01:13:56 +0200 | [diff] [blame] | 50 | /* Cyrix III family needs CX8 & PGE explicitly enabled. */ |
Timo Teräs | cb3f718 | 2011-12-15 17:11:28 +0200 | [diff] [blame] | 51 | if (c->x86_model >= 6 && c->x86_model <= 13) { |
Paolo Ciarrocchi | 29a9994 | 2008-02-17 23:30:23 +0100 | [diff] [blame] | 52 | rdmsr(MSR_VIA_FCR, lo, hi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | lo |= (1<<1 | 1<<7); |
Paolo Ciarrocchi | 29a9994 | 2008-02-17 23:30:23 +0100 | [diff] [blame] | 54 | wrmsr(MSR_VIA_FCR, lo, hi); |
Ingo Molnar | e1a94a9 | 2008-02-26 08:51:22 +0100 | [diff] [blame] | 55 | set_cpu_cap(c, X86_FEATURE_CX8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | /* Before Nehemiah, the C3's had 3dNOW! */ |
Paolo Ciarrocchi | 29a9994 | 2008-02-17 23:30:23 +0100 | [diff] [blame] | 59 | if (c->x86_model >= 6 && c->x86_model < 9) |
Ingo Molnar | e1a94a9 | 2008-02-26 08:51:22 +0100 | [diff] [blame] | 60 | set_cpu_cap(c, X86_FEATURE_3DNOW); |
Sebastian Andrzej Siewior | 48f4c48 | 2009-03-14 12:24:02 +0100 | [diff] [blame] | 61 | #endif |
| 62 | if (c->x86 == 0x6 && c->x86_model >= 0xf) { |
| 63 | c->x86_cache_alignment = c->x86_clflush_size * 2; |
| 64 | set_cpu_cap(c, X86_FEATURE_REP_GOOD); |
| 65 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | |
Borislav Petkov | 27c13ec | 2009-11-21 14:01:45 +0100 | [diff] [blame] | 67 | cpu_detect_cache_sizes(c); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | } |
| 69 | |
Ingo Molnar | edc05e6 | 2008-02-18 03:30:47 +0100 | [diff] [blame] | 70 | enum { |
| 71 | ECX8 = 1<<1, |
| 72 | EIERRINT = 1<<2, |
| 73 | DPM = 1<<3, |
| 74 | DMCE = 1<<4, |
| 75 | DSTPCLK = 1<<5, |
| 76 | ELINEAR = 1<<6, |
| 77 | DSMC = 1<<7, |
| 78 | DTLOCK = 1<<8, |
| 79 | EDCTLB = 1<<8, |
| 80 | EMMX = 1<<9, |
| 81 | DPDC = 1<<11, |
| 82 | EBRPRED = 1<<12, |
| 83 | DIC = 1<<13, |
| 84 | DDC = 1<<14, |
| 85 | DNA = 1<<15, |
| 86 | ERETSTK = 1<<16, |
| 87 | E2MMX = 1<<19, |
| 88 | EAMD3D = 1<<20, |
| 89 | }; |
| 90 | |
Paul Gortmaker | 148f9bb | 2013-06-18 18:23:59 -0400 | [diff] [blame] | 91 | static void early_init_centaur(struct cpuinfo_x86 *c) |
Yinghai Lu | 5fef55f | 2008-09-04 21:09:43 +0200 | [diff] [blame] | 92 | { |
| 93 | switch (c->x86) { |
Sebastian Andrzej Siewior | 48f4c48 | 2009-03-14 12:24:02 +0100 | [diff] [blame] | 94 | #ifdef CONFIG_X86_32 |
Yinghai Lu | 5fef55f | 2008-09-04 21:09:43 +0200 | [diff] [blame] | 95 | case 5: |
| 96 | /* Emulate MTRRs using Centaur's MCR. */ |
| 97 | set_cpu_cap(c, X86_FEATURE_CENTAUR_MCR); |
| 98 | break; |
Sebastian Andrzej Siewior | 48f4c48 | 2009-03-14 12:24:02 +0100 | [diff] [blame] | 99 | #endif |
| 100 | case 6: |
| 101 | if (c->x86_model >= 0xf) |
| 102 | set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC); |
| 103 | break; |
Yinghai Lu | 5fef55f | 2008-09-04 21:09:43 +0200 | [diff] [blame] | 104 | } |
Sebastian Andrzej Siewior | 48f4c48 | 2009-03-14 12:24:02 +0100 | [diff] [blame] | 105 | #ifdef CONFIG_X86_64 |
| 106 | set_cpu_cap(c, X86_FEATURE_SYSENTER32); |
| 107 | #endif |
Peter Zijlstra | acb0405 | 2017-01-19 14:36:33 +0100 | [diff] [blame] | 108 | |
| 109 | clear_sched_clock_stable(); |
Yinghai Lu | 5fef55f | 2008-09-04 21:09:43 +0200 | [diff] [blame] | 110 | } |
| 111 | |
Paul Gortmaker | 148f9bb | 2013-06-18 18:23:59 -0400 | [diff] [blame] | 112 | static void init_centaur(struct cpuinfo_x86 *c) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | { |
Sebastian Andrzej Siewior | 48f4c48 | 2009-03-14 12:24:02 +0100 | [diff] [blame] | 114 | #ifdef CONFIG_X86_32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | char *name; |
Paolo Ciarrocchi | 29a9994 | 2008-02-17 23:30:23 +0100 | [diff] [blame] | 116 | u32 fcr_set = 0; |
| 117 | u32 fcr_clr = 0; |
| 118 | u32 lo, hi, newlo; |
| 119 | u32 aa, bb, cc, dd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | |
Ingo Molnar | edc05e6 | 2008-02-18 03:30:47 +0100 | [diff] [blame] | 121 | /* |
| 122 | * Bit 31 in normal CPUID used for nonstandard 3DNow ID; |
| 123 | * 3DNow is IDd by bit 31 in extended CPUID (1*32+31) anyway |
| 124 | */ |
Ingo Molnar | e1a94a9 | 2008-02-26 08:51:22 +0100 | [diff] [blame] | 125 | clear_cpu_cap(c, 0*32+31); |
Sebastian Andrzej Siewior | 48f4c48 | 2009-03-14 12:24:02 +0100 | [diff] [blame] | 126 | #endif |
| 127 | early_init_centaur(c); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | switch (c->x86) { |
Sebastian Andrzej Siewior | 48f4c48 | 2009-03-14 12:24:02 +0100 | [diff] [blame] | 129 | #ifdef CONFIG_X86_32 |
Paolo Ciarrocchi | 29a9994 | 2008-02-17 23:30:23 +0100 | [diff] [blame] | 130 | case 5: |
Ingo Molnar | edc05e6 | 2008-02-18 03:30:47 +0100 | [diff] [blame] | 131 | switch (c->x86_model) { |
| 132 | case 4: |
| 133 | name = "C6"; |
| 134 | fcr_set = ECX8|DSMC|EDCTLB|EMMX|ERETSTK; |
| 135 | fcr_clr = DPDC; |
Chen Yucong | 1b74dde | 2016-02-02 11:45:02 +0800 | [diff] [blame] | 136 | pr_notice("Disabling bugged TSC.\n"); |
Ingo Molnar | e1a94a9 | 2008-02-26 08:51:22 +0100 | [diff] [blame] | 137 | clear_cpu_cap(c, X86_FEATURE_TSC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | break; |
Ingo Molnar | edc05e6 | 2008-02-18 03:30:47 +0100 | [diff] [blame] | 139 | case 8: |
| 140 | switch (c->x86_mask) { |
| 141 | default: |
| 142 | name = "2"; |
| 143 | break; |
| 144 | case 7 ... 9: |
| 145 | name = "2A"; |
| 146 | break; |
| 147 | case 10 ... 15: |
| 148 | name = "2B"; |
| 149 | break; |
| 150 | } |
| 151 | fcr_set = ECX8|DSMC|DTLOCK|EMMX|EBRPRED|ERETSTK| |
| 152 | E2MMX|EAMD3D; |
| 153 | fcr_clr = DPDC; |
Ingo Molnar | edc05e6 | 2008-02-18 03:30:47 +0100 | [diff] [blame] | 154 | break; |
| 155 | case 9: |
| 156 | name = "3"; |
| 157 | fcr_set = ECX8|DSMC|DTLOCK|EMMX|EBRPRED|ERETSTK| |
| 158 | E2MMX|EAMD3D; |
| 159 | fcr_clr = DPDC; |
Ingo Molnar | edc05e6 | 2008-02-18 03:30:47 +0100 | [diff] [blame] | 160 | break; |
| 161 | default: |
| 162 | name = "??"; |
| 163 | } |
| 164 | |
| 165 | rdmsr(MSR_IDT_FCR1, lo, hi); |
| 166 | newlo = (lo|fcr_set) & (~fcr_clr); |
| 167 | |
| 168 | if (newlo != lo) { |
Chen Yucong | 1b74dde | 2016-02-02 11:45:02 +0800 | [diff] [blame] | 169 | pr_info("Centaur FCR was 0x%X now 0x%X\n", |
Ingo Molnar | edc05e6 | 2008-02-18 03:30:47 +0100 | [diff] [blame] | 170 | lo, newlo); |
| 171 | wrmsr(MSR_IDT_FCR1, newlo, hi); |
| 172 | } else { |
Chen Yucong | 1b74dde | 2016-02-02 11:45:02 +0800 | [diff] [blame] | 173 | pr_info("Centaur FCR is 0x%X\n", lo); |
Ingo Molnar | edc05e6 | 2008-02-18 03:30:47 +0100 | [diff] [blame] | 174 | } |
| 175 | /* Emulate MTRRs using Centaur's MCR. */ |
Ingo Molnar | e1a94a9 | 2008-02-26 08:51:22 +0100 | [diff] [blame] | 176 | set_cpu_cap(c, X86_FEATURE_CENTAUR_MCR); |
Ingo Molnar | edc05e6 | 2008-02-18 03:30:47 +0100 | [diff] [blame] | 177 | /* Report CX8 */ |
Ingo Molnar | e1a94a9 | 2008-02-26 08:51:22 +0100 | [diff] [blame] | 178 | set_cpu_cap(c, X86_FEATURE_CX8); |
Ingo Molnar | edc05e6 | 2008-02-18 03:30:47 +0100 | [diff] [blame] | 179 | /* Set 3DNow! on Winchip 2 and above. */ |
| 180 | if (c->x86_model >= 8) |
Ingo Molnar | e1a94a9 | 2008-02-26 08:51:22 +0100 | [diff] [blame] | 181 | set_cpu_cap(c, X86_FEATURE_3DNOW); |
Ingo Molnar | edc05e6 | 2008-02-18 03:30:47 +0100 | [diff] [blame] | 182 | /* See if we can find out some more. */ |
| 183 | if (cpuid_eax(0x80000000) >= 0x80000005) { |
| 184 | /* Yes, we can. */ |
| 185 | cpuid(0x80000005, &aa, &bb, &cc, &dd); |
| 186 | /* Add L1 data and code cache sizes. */ |
| 187 | c->x86_cache_size = (cc>>24)+(dd>>24); |
| 188 | } |
| 189 | sprintf(c->x86_model_id, "WinChip %s", name); |
| 190 | break; |
Sebastian Andrzej Siewior | 48f4c48 | 2009-03-14 12:24:02 +0100 | [diff] [blame] | 191 | #endif |
Paolo Ciarrocchi | 29a9994 | 2008-02-17 23:30:23 +0100 | [diff] [blame] | 192 | case 6: |
Ingo Molnar | edc05e6 | 2008-02-18 03:30:47 +0100 | [diff] [blame] | 193 | init_c3(c); |
| 194 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | } |
Sebastian Andrzej Siewior | 48f4c48 | 2009-03-14 12:24:02 +0100 | [diff] [blame] | 196 | #ifdef CONFIG_X86_64 |
| 197 | set_cpu_cap(c, X86_FEATURE_LFENCE_RDTSC); |
| 198 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | } |
| 200 | |
Jan Beulich | 09dc68d | 2013-10-21 09:35:20 +0100 | [diff] [blame] | 201 | #ifdef CONFIG_X86_32 |
Paul Gortmaker | 148f9bb | 2013-06-18 18:23:59 -0400 | [diff] [blame] | 202 | static unsigned int |
Ingo Molnar | edc05e6 | 2008-02-18 03:30:47 +0100 | [diff] [blame] | 203 | centaur_size_cache(struct cpuinfo_x86 *c, unsigned int size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | { |
| 205 | /* VIA C3 CPUs (670-68F) need further shifting. */ |
| 206 | if ((c->x86 == 6) && ((c->x86_model == 7) || (c->x86_model == 8))) |
| 207 | size >>= 8; |
| 208 | |
Ingo Molnar | edc05e6 | 2008-02-18 03:30:47 +0100 | [diff] [blame] | 209 | /* |
| 210 | * There's also an erratum in Nehemiah stepping 1, which |
| 211 | * returns '65KB' instead of '64KB' |
| 212 | * - Note, it seems this may only be in engineering samples. |
| 213 | */ |
| 214 | if ((c->x86 == 6) && (c->x86_model == 9) && |
| 215 | (c->x86_mask == 1) && (size == 65)) |
Paolo Ciarrocchi | 29a9994 | 2008-02-17 23:30:23 +0100 | [diff] [blame] | 216 | size -= 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | return size; |
| 218 | } |
Jan Beulich | 09dc68d | 2013-10-21 09:35:20 +0100 | [diff] [blame] | 219 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | |
Paul Gortmaker | 148f9bb | 2013-06-18 18:23:59 -0400 | [diff] [blame] | 221 | static const struct cpu_dev centaur_cpu_dev = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | .c_vendor = "Centaur", |
| 223 | .c_ident = { "CentaurHauls" }, |
Yinghai Lu | 5fef55f | 2008-09-04 21:09:43 +0200 | [diff] [blame] | 224 | .c_early_init = early_init_centaur, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | .c_init = init_centaur, |
Jan Beulich | 09dc68d | 2013-10-21 09:35:20 +0100 | [diff] [blame] | 226 | #ifdef CONFIG_X86_32 |
| 227 | .legacy_cache_size = centaur_size_cache, |
| 228 | #endif |
Yinghai Lu | 10a434f | 2008-09-04 21:09:45 +0200 | [diff] [blame] | 229 | .c_x86_vendor = X86_VENDOR_CENTAUR, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | }; |
| 231 | |
Yinghai Lu | 10a434f | 2008-09-04 21:09:45 +0200 | [diff] [blame] | 232 | cpu_dev_register(centaur_cpu_dev); |