1 2 #include <linux/sched.h> 3 #include <linux/sched/clock.h> 4 5 #include <asm/cpufeature.h> 6 #include <asm/e820.h> 7 #include <asm/mtrr.h> 8 #include <asm/msr.h> 9 10 #include "cpu.h" 11 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 20 static void init_c3(struct cpuinfo_x86 *c) 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) { 30 rdmsr(MSR_VIA_FCR, lo, hi); 31 lo |= ACE_FCR; /* enable ACE unit */ 32 wrmsr(MSR_VIA_FCR, lo, hi); 33 pr_info("CPU: Enabled ACE h/w crypto\n"); 34 } 35 36 /* enable RNG unit, if present and disabled */ 37 if ((tmp & (RNG_PRESENT | RNG_ENABLED)) == RNG_PRESENT) { 38 rdmsr(MSR_VIA_RNG, lo, hi); 39 lo |= RNG_ENABLE; /* enable RNG unit */ 40 wrmsr(MSR_VIA_RNG, lo, hi); 41 pr_info("CPU: Enabled h/w RNG\n"); 42 } 43 44 /* store Centaur Extended Feature Flags as 45 * word 5 of the CPU capability bit array 46 */ 47 c->x86_capability[CPUID_C000_0001_EDX] = cpuid_edx(0xC0000001); 48 } 49 #ifdef CONFIG_X86_32 50 /* Cyrix III family needs CX8 & PGE explicitly enabled. */ 51 if (c->x86_model >= 6 && c->x86_model <= 13) { 52 rdmsr(MSR_VIA_FCR, lo, hi); 53 lo |= (1<<1 | 1<<7); 54 wrmsr(MSR_VIA_FCR, lo, hi); 55 set_cpu_cap(c, X86_FEATURE_CX8); 56 } 57 58 /* Before Nehemiah, the C3's had 3dNOW! */ 59 if (c->x86_model >= 6 && c->x86_model < 9) 60 set_cpu_cap(c, X86_FEATURE_3DNOW); 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 } 66 67 cpu_detect_cache_sizes(c); 68 } 69 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 91 static void early_init_centaur(struct cpuinfo_x86 *c) 92 { 93 switch (c->x86) { 94 #ifdef CONFIG_X86_32 95 case 5: 96 /* Emulate MTRRs using Centaur's MCR. */ 97 set_cpu_cap(c, X86_FEATURE_CENTAUR_MCR); 98 break; 99 #endif 100 case 6: 101 if (c->x86_model >= 0xf) 102 set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC); 103 break; 104 } 105 #ifdef CONFIG_X86_64 106 set_cpu_cap(c, X86_FEATURE_SYSENTER32); 107 #endif 108 } 109 110 static void init_centaur(struct cpuinfo_x86 *c) 111 { 112 #ifdef CONFIG_X86_32 113 char *name; 114 u32 fcr_set = 0; 115 u32 fcr_clr = 0; 116 u32 lo, hi, newlo; 117 u32 aa, bb, cc, dd; 118 119 /* 120 * Bit 31 in normal CPUID used for nonstandard 3DNow ID; 121 * 3DNow is IDd by bit 31 in extended CPUID (1*32+31) anyway 122 */ 123 clear_cpu_cap(c, 0*32+31); 124 #endif 125 early_init_centaur(c); 126 switch (c->x86) { 127 #ifdef CONFIG_X86_32 128 case 5: 129 switch (c->x86_model) { 130 case 4: 131 name = "C6"; 132 fcr_set = ECX8|DSMC|EDCTLB|EMMX|ERETSTK; 133 fcr_clr = DPDC; 134 pr_notice("Disabling bugged TSC.\n"); 135 clear_cpu_cap(c, X86_FEATURE_TSC); 136 break; 137 case 8: 138 switch (c->x86_mask) { 139 default: 140 name = "2"; 141 break; 142 case 7 ... 9: 143 name = "2A"; 144 break; 145 case 10 ... 15: 146 name = "2B"; 147 break; 148 } 149 fcr_set = ECX8|DSMC|DTLOCK|EMMX|EBRPRED|ERETSTK| 150 E2MMX|EAMD3D; 151 fcr_clr = DPDC; 152 break; 153 case 9: 154 name = "3"; 155 fcr_set = ECX8|DSMC|DTLOCK|EMMX|EBRPRED|ERETSTK| 156 E2MMX|EAMD3D; 157 fcr_clr = DPDC; 158 break; 159 default: 160 name = "??"; 161 } 162 163 rdmsr(MSR_IDT_FCR1, lo, hi); 164 newlo = (lo|fcr_set) & (~fcr_clr); 165 166 if (newlo != lo) { 167 pr_info("Centaur FCR was 0x%X now 0x%X\n", 168 lo, newlo); 169 wrmsr(MSR_IDT_FCR1, newlo, hi); 170 } else { 171 pr_info("Centaur FCR is 0x%X\n", lo); 172 } 173 /* Emulate MTRRs using Centaur's MCR. */ 174 set_cpu_cap(c, X86_FEATURE_CENTAUR_MCR); 175 /* Report CX8 */ 176 set_cpu_cap(c, X86_FEATURE_CX8); 177 /* Set 3DNow! on Winchip 2 and above. */ 178 if (c->x86_model >= 8) 179 set_cpu_cap(c, X86_FEATURE_3DNOW); 180 /* See if we can find out some more. */ 181 if (cpuid_eax(0x80000000) >= 0x80000005) { 182 /* Yes, we can. */ 183 cpuid(0x80000005, &aa, &bb, &cc, &dd); 184 /* Add L1 data and code cache sizes. */ 185 c->x86_cache_size = (cc>>24)+(dd>>24); 186 } 187 sprintf(c->x86_model_id, "WinChip %s", name); 188 break; 189 #endif 190 case 6: 191 init_c3(c); 192 break; 193 } 194 #ifdef CONFIG_X86_64 195 set_cpu_cap(c, X86_FEATURE_LFENCE_RDTSC); 196 #endif 197 } 198 199 #ifdef CONFIG_X86_32 200 static unsigned int 201 centaur_size_cache(struct cpuinfo_x86 *c, unsigned int size) 202 { 203 /* VIA C3 CPUs (670-68F) need further shifting. */ 204 if ((c->x86 == 6) && ((c->x86_model == 7) || (c->x86_model == 8))) 205 size >>= 8; 206 207 /* 208 * There's also an erratum in Nehemiah stepping 1, which 209 * returns '65KB' instead of '64KB' 210 * - Note, it seems this may only be in engineering samples. 211 */ 212 if ((c->x86 == 6) && (c->x86_model == 9) && 213 (c->x86_mask == 1) && (size == 65)) 214 size -= 1; 215 return size; 216 } 217 #endif 218 219 static const struct cpu_dev centaur_cpu_dev = { 220 .c_vendor = "Centaur", 221 .c_ident = { "CentaurHauls" }, 222 .c_early_init = early_init_centaur, 223 .c_init = init_centaur, 224 #ifdef CONFIG_X86_32 225 .legacy_cache_size = centaur_size_cache, 226 #endif 227 .c_x86_vendor = X86_VENDOR_CENTAUR, 228 }; 229 230 cpu_dev_register(centaur_cpu_dev); 231