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