xref: /openbmc/linux/arch/x86/kernel/cpu/centaur.c (revision f7627e2513987bb5d4e8cb13c4e0a478352141ac)
1*f7627e25SThomas Gleixner #include <linux/kernel.h>
2*f7627e25SThomas Gleixner #include <linux/init.h>
3*f7627e25SThomas Gleixner #include <linux/bitops.h>
4*f7627e25SThomas Gleixner #include <asm/processor.h>
5*f7627e25SThomas Gleixner #include <asm/msr.h>
6*f7627e25SThomas Gleixner #include <asm/e820.h>
7*f7627e25SThomas Gleixner #include <asm/mtrr.h>
8*f7627e25SThomas Gleixner #include "cpu.h"
9*f7627e25SThomas Gleixner 
10*f7627e25SThomas Gleixner #ifdef CONFIG_X86_OOSTORE
11*f7627e25SThomas Gleixner 
12*f7627e25SThomas Gleixner static u32 __cpuinit power2(u32 x)
13*f7627e25SThomas Gleixner {
14*f7627e25SThomas Gleixner 	u32 s=1;
15*f7627e25SThomas Gleixner 	while(s<=x)
16*f7627e25SThomas Gleixner 		s<<=1;
17*f7627e25SThomas Gleixner 	return s>>=1;
18*f7627e25SThomas Gleixner }
19*f7627e25SThomas Gleixner 
20*f7627e25SThomas Gleixner 
21*f7627e25SThomas Gleixner /*
22*f7627e25SThomas Gleixner  *	Set up an actual MCR
23*f7627e25SThomas Gleixner  */
24*f7627e25SThomas Gleixner 
25*f7627e25SThomas Gleixner static void __cpuinit centaur_mcr_insert(int reg, u32 base, u32 size, int key)
26*f7627e25SThomas Gleixner {
27*f7627e25SThomas Gleixner 	u32 lo, hi;
28*f7627e25SThomas Gleixner 
29*f7627e25SThomas Gleixner 	hi = base & ~0xFFF;
30*f7627e25SThomas Gleixner 	lo = ~(size-1);		/* Size is a power of 2 so this makes a mask */
31*f7627e25SThomas Gleixner 	lo &= ~0xFFF;		/* Remove the ctrl value bits */
32*f7627e25SThomas Gleixner 	lo |= key;		/* Attribute we wish to set */
33*f7627e25SThomas Gleixner 	wrmsr(reg+MSR_IDT_MCR0, lo, hi);
34*f7627e25SThomas Gleixner 	mtrr_centaur_report_mcr(reg, lo, hi);	/* Tell the mtrr driver */
35*f7627e25SThomas Gleixner }
36*f7627e25SThomas Gleixner 
37*f7627e25SThomas Gleixner /*
38*f7627e25SThomas Gleixner  *	Figure what we can cover with MCR's
39*f7627e25SThomas Gleixner  *
40*f7627e25SThomas Gleixner  *	Shortcut: We know you can't put 4Gig of RAM on a winchip
41*f7627e25SThomas Gleixner  */
42*f7627e25SThomas Gleixner 
43*f7627e25SThomas Gleixner static u32 __cpuinit ramtop(void)		/* 16388 */
44*f7627e25SThomas Gleixner {
45*f7627e25SThomas Gleixner 	int i;
46*f7627e25SThomas Gleixner 	u32 top = 0;
47*f7627e25SThomas Gleixner 	u32 clip = 0xFFFFFFFFUL;
48*f7627e25SThomas Gleixner 
49*f7627e25SThomas Gleixner 	for (i = 0; i < e820.nr_map; i++) {
50*f7627e25SThomas Gleixner 		unsigned long start, end;
51*f7627e25SThomas Gleixner 
52*f7627e25SThomas Gleixner 		if (e820.map[i].addr > 0xFFFFFFFFUL)
53*f7627e25SThomas Gleixner 			continue;
54*f7627e25SThomas Gleixner 		/*
55*f7627e25SThomas Gleixner 		 *	Don't MCR over reserved space. Ignore the ISA hole
56*f7627e25SThomas Gleixner 		 *	we frob around that catastrophy already
57*f7627e25SThomas Gleixner 		 */
58*f7627e25SThomas Gleixner 
59*f7627e25SThomas Gleixner 		if (e820.map[i].type == E820_RESERVED)
60*f7627e25SThomas Gleixner 		{
61*f7627e25SThomas Gleixner 			if(e820.map[i].addr >= 0x100000UL && e820.map[i].addr < clip)
62*f7627e25SThomas Gleixner 				clip = e820.map[i].addr;
63*f7627e25SThomas Gleixner 			continue;
64*f7627e25SThomas Gleixner 		}
65*f7627e25SThomas Gleixner 		start = e820.map[i].addr;
66*f7627e25SThomas Gleixner 		end = e820.map[i].addr + e820.map[i].size;
67*f7627e25SThomas Gleixner 		if (start >= end)
68*f7627e25SThomas Gleixner 			continue;
69*f7627e25SThomas Gleixner 		if (end > top)
70*f7627e25SThomas Gleixner 			top = end;
71*f7627e25SThomas Gleixner 	}
72*f7627e25SThomas Gleixner 	/* Everything below 'top' should be RAM except for the ISA hole.
73*f7627e25SThomas Gleixner 	   Because of the limited MCR's we want to map NV/ACPI into our
74*f7627e25SThomas Gleixner 	   MCR range for gunk in RAM
75*f7627e25SThomas Gleixner 
76*f7627e25SThomas Gleixner 	   Clip might cause us to MCR insufficient RAM but that is an
77*f7627e25SThomas Gleixner 	   acceptable failure mode and should only bite obscure boxes with
78*f7627e25SThomas Gleixner 	   a VESA hole at 15Mb
79*f7627e25SThomas Gleixner 
80*f7627e25SThomas Gleixner 	   The second case Clip sometimes kicks in is when the EBDA is marked
81*f7627e25SThomas Gleixner 	   as reserved. Again we fail safe with reasonable results
82*f7627e25SThomas Gleixner 	*/
83*f7627e25SThomas Gleixner 
84*f7627e25SThomas Gleixner 	if(top>clip)
85*f7627e25SThomas Gleixner 		top=clip;
86*f7627e25SThomas Gleixner 
87*f7627e25SThomas Gleixner 	return top;
88*f7627e25SThomas Gleixner }
89*f7627e25SThomas Gleixner 
90*f7627e25SThomas Gleixner /*
91*f7627e25SThomas Gleixner  *	Compute a set of MCR's to give maximum coverage
92*f7627e25SThomas Gleixner  */
93*f7627e25SThomas Gleixner 
94*f7627e25SThomas Gleixner static int __cpuinit centaur_mcr_compute(int nr, int key)
95*f7627e25SThomas Gleixner {
96*f7627e25SThomas Gleixner 	u32 mem = ramtop();
97*f7627e25SThomas Gleixner 	u32 root = power2(mem);
98*f7627e25SThomas Gleixner 	u32 base = root;
99*f7627e25SThomas Gleixner 	u32 top = root;
100*f7627e25SThomas Gleixner 	u32 floor = 0;
101*f7627e25SThomas Gleixner 	int ct = 0;
102*f7627e25SThomas Gleixner 
103*f7627e25SThomas Gleixner 	while(ct<nr)
104*f7627e25SThomas Gleixner 	{
105*f7627e25SThomas Gleixner 		u32 fspace = 0;
106*f7627e25SThomas Gleixner 
107*f7627e25SThomas Gleixner 		/*
108*f7627e25SThomas Gleixner 		 *	Find the largest block we will fill going upwards
109*f7627e25SThomas Gleixner 		 */
110*f7627e25SThomas Gleixner 
111*f7627e25SThomas Gleixner 		u32 high = power2(mem-top);
112*f7627e25SThomas Gleixner 
113*f7627e25SThomas Gleixner 		/*
114*f7627e25SThomas Gleixner 		 *	Find the largest block we will fill going downwards
115*f7627e25SThomas Gleixner 		 */
116*f7627e25SThomas Gleixner 
117*f7627e25SThomas Gleixner 		u32 low = base/2;
118*f7627e25SThomas Gleixner 
119*f7627e25SThomas Gleixner 		/*
120*f7627e25SThomas Gleixner 		 *	Don't fill below 1Mb going downwards as there
121*f7627e25SThomas Gleixner 		 *	is an ISA hole in the way.
122*f7627e25SThomas Gleixner 		 */
123*f7627e25SThomas Gleixner 
124*f7627e25SThomas Gleixner 		if(base <= 1024*1024)
125*f7627e25SThomas Gleixner 			low = 0;
126*f7627e25SThomas Gleixner 
127*f7627e25SThomas Gleixner 		/*
128*f7627e25SThomas Gleixner 		 *	See how much space we could cover by filling below
129*f7627e25SThomas Gleixner 		 *	the ISA hole
130*f7627e25SThomas Gleixner 		 */
131*f7627e25SThomas Gleixner 
132*f7627e25SThomas Gleixner 		if(floor == 0)
133*f7627e25SThomas Gleixner 			fspace = 512*1024;
134*f7627e25SThomas Gleixner 		else if(floor ==512*1024)
135*f7627e25SThomas Gleixner 			fspace = 128*1024;
136*f7627e25SThomas Gleixner 
137*f7627e25SThomas Gleixner 		/* And forget ROM space */
138*f7627e25SThomas Gleixner 
139*f7627e25SThomas Gleixner 		/*
140*f7627e25SThomas Gleixner 		 *	Now install the largest coverage we get
141*f7627e25SThomas Gleixner 		 */
142*f7627e25SThomas Gleixner 
143*f7627e25SThomas Gleixner 		if(fspace > high && fspace > low)
144*f7627e25SThomas Gleixner 		{
145*f7627e25SThomas Gleixner 			centaur_mcr_insert(ct, floor, fspace, key);
146*f7627e25SThomas Gleixner 			floor += fspace;
147*f7627e25SThomas Gleixner 		}
148*f7627e25SThomas Gleixner 		else if(high > low)
149*f7627e25SThomas Gleixner 		{
150*f7627e25SThomas Gleixner 			centaur_mcr_insert(ct, top, high, key);
151*f7627e25SThomas Gleixner 			top += high;
152*f7627e25SThomas Gleixner 		}
153*f7627e25SThomas Gleixner 		else if(low > 0)
154*f7627e25SThomas Gleixner 		{
155*f7627e25SThomas Gleixner 			base -= low;
156*f7627e25SThomas Gleixner 			centaur_mcr_insert(ct, base, low, key);
157*f7627e25SThomas Gleixner 		}
158*f7627e25SThomas Gleixner 		else break;
159*f7627e25SThomas Gleixner 		ct++;
160*f7627e25SThomas Gleixner 	}
161*f7627e25SThomas Gleixner 	/*
162*f7627e25SThomas Gleixner 	 *	We loaded ct values. We now need to set the mask. The caller
163*f7627e25SThomas Gleixner 	 *	must do this bit.
164*f7627e25SThomas Gleixner 	 */
165*f7627e25SThomas Gleixner 
166*f7627e25SThomas Gleixner 	return ct;
167*f7627e25SThomas Gleixner }
168*f7627e25SThomas Gleixner 
169*f7627e25SThomas Gleixner static void __cpuinit centaur_create_optimal_mcr(void)
170*f7627e25SThomas Gleixner {
171*f7627e25SThomas Gleixner 	int i;
172*f7627e25SThomas Gleixner 	/*
173*f7627e25SThomas Gleixner 	 *	Allocate up to 6 mcrs to mark as much of ram as possible
174*f7627e25SThomas Gleixner 	 *	as write combining and weak write ordered.
175*f7627e25SThomas Gleixner 	 *
176*f7627e25SThomas Gleixner 	 *	To experiment with: Linux never uses stack operations for
177*f7627e25SThomas Gleixner 	 *	mmio spaces so we could globally enable stack operation wc
178*f7627e25SThomas Gleixner 	 *
179*f7627e25SThomas Gleixner 	 *	Load the registers with type 31 - full write combining, all
180*f7627e25SThomas Gleixner 	 *	writes weakly ordered.
181*f7627e25SThomas Gleixner 	 */
182*f7627e25SThomas Gleixner 	int used = centaur_mcr_compute(6, 31);
183*f7627e25SThomas Gleixner 
184*f7627e25SThomas Gleixner 	/*
185*f7627e25SThomas Gleixner 	 *	Wipe unused MCRs
186*f7627e25SThomas Gleixner 	 */
187*f7627e25SThomas Gleixner 
188*f7627e25SThomas Gleixner 	for(i=used;i<8;i++)
189*f7627e25SThomas Gleixner 		wrmsr(MSR_IDT_MCR0+i, 0, 0);
190*f7627e25SThomas Gleixner }
191*f7627e25SThomas Gleixner 
192*f7627e25SThomas Gleixner static void __cpuinit winchip2_create_optimal_mcr(void)
193*f7627e25SThomas Gleixner {
194*f7627e25SThomas Gleixner 	u32 lo, hi;
195*f7627e25SThomas Gleixner 	int i;
196*f7627e25SThomas Gleixner 
197*f7627e25SThomas Gleixner 	/*
198*f7627e25SThomas Gleixner 	 *	Allocate up to 6 mcrs to mark as much of ram as possible
199*f7627e25SThomas Gleixner 	 *	as write combining, weak store ordered.
200*f7627e25SThomas Gleixner 	 *
201*f7627e25SThomas Gleixner 	 *	Load the registers with type 25
202*f7627e25SThomas Gleixner 	 *		8	-	weak write ordering
203*f7627e25SThomas Gleixner 	 *		16	-	weak read ordering
204*f7627e25SThomas Gleixner 	 *		1	-	write combining
205*f7627e25SThomas Gleixner 	 */
206*f7627e25SThomas Gleixner 
207*f7627e25SThomas Gleixner 	int used = centaur_mcr_compute(6, 25);
208*f7627e25SThomas Gleixner 
209*f7627e25SThomas Gleixner 	/*
210*f7627e25SThomas Gleixner 	 *	Mark the registers we are using.
211*f7627e25SThomas Gleixner 	 */
212*f7627e25SThomas Gleixner 
213*f7627e25SThomas Gleixner 	rdmsr(MSR_IDT_MCR_CTRL, lo, hi);
214*f7627e25SThomas Gleixner 	for(i=0;i<used;i++)
215*f7627e25SThomas Gleixner 		lo|=1<<(9+i);
216*f7627e25SThomas Gleixner 	wrmsr(MSR_IDT_MCR_CTRL, lo, hi);
217*f7627e25SThomas Gleixner 
218*f7627e25SThomas Gleixner 	/*
219*f7627e25SThomas Gleixner 	 *	Wipe unused MCRs
220*f7627e25SThomas Gleixner 	 */
221*f7627e25SThomas Gleixner 
222*f7627e25SThomas Gleixner 	for(i=used;i<8;i++)
223*f7627e25SThomas Gleixner 		wrmsr(MSR_IDT_MCR0+i, 0, 0);
224*f7627e25SThomas Gleixner }
225*f7627e25SThomas Gleixner 
226*f7627e25SThomas Gleixner /*
227*f7627e25SThomas Gleixner  *	Handle the MCR key on the Winchip 2.
228*f7627e25SThomas Gleixner  */
229*f7627e25SThomas Gleixner 
230*f7627e25SThomas Gleixner static void __cpuinit winchip2_unprotect_mcr(void)
231*f7627e25SThomas Gleixner {
232*f7627e25SThomas Gleixner 	u32 lo, hi;
233*f7627e25SThomas Gleixner 	u32 key;
234*f7627e25SThomas Gleixner 
235*f7627e25SThomas Gleixner 	rdmsr(MSR_IDT_MCR_CTRL, lo, hi);
236*f7627e25SThomas Gleixner 	lo&=~0x1C0;	/* blank bits 8-6 */
237*f7627e25SThomas Gleixner 	key = (lo>>17) & 7;
238*f7627e25SThomas Gleixner 	lo |= key<<6;	/* replace with unlock key */
239*f7627e25SThomas Gleixner 	wrmsr(MSR_IDT_MCR_CTRL, lo, hi);
240*f7627e25SThomas Gleixner }
241*f7627e25SThomas Gleixner 
242*f7627e25SThomas Gleixner static void __cpuinit winchip2_protect_mcr(void)
243*f7627e25SThomas Gleixner {
244*f7627e25SThomas Gleixner 	u32 lo, hi;
245*f7627e25SThomas Gleixner 
246*f7627e25SThomas Gleixner 	rdmsr(MSR_IDT_MCR_CTRL, lo, hi);
247*f7627e25SThomas Gleixner 	lo&=~0x1C0;	/* blank bits 8-6 */
248*f7627e25SThomas Gleixner 	wrmsr(MSR_IDT_MCR_CTRL, lo, hi);
249*f7627e25SThomas Gleixner }
250*f7627e25SThomas Gleixner #endif /* CONFIG_X86_OOSTORE */
251*f7627e25SThomas Gleixner 
252*f7627e25SThomas Gleixner #define ACE_PRESENT	(1 << 6)
253*f7627e25SThomas Gleixner #define ACE_ENABLED	(1 << 7)
254*f7627e25SThomas Gleixner #define ACE_FCR		(1 << 28)	/* MSR_VIA_FCR */
255*f7627e25SThomas Gleixner 
256*f7627e25SThomas Gleixner #define RNG_PRESENT	(1 << 2)
257*f7627e25SThomas Gleixner #define RNG_ENABLED	(1 << 3)
258*f7627e25SThomas Gleixner #define RNG_ENABLE	(1 << 6)	/* MSR_VIA_RNG */
259*f7627e25SThomas Gleixner 
260*f7627e25SThomas Gleixner static void __cpuinit init_c3(struct cpuinfo_x86 *c)
261*f7627e25SThomas Gleixner {
262*f7627e25SThomas Gleixner 	u32  lo, hi;
263*f7627e25SThomas Gleixner 
264*f7627e25SThomas Gleixner 	/* Test for Centaur Extended Feature Flags presence */
265*f7627e25SThomas Gleixner 	if (cpuid_eax(0xC0000000) >= 0xC0000001) {
266*f7627e25SThomas Gleixner 		u32 tmp = cpuid_edx(0xC0000001);
267*f7627e25SThomas Gleixner 
268*f7627e25SThomas Gleixner 		/* enable ACE unit, if present and disabled */
269*f7627e25SThomas Gleixner 		if ((tmp & (ACE_PRESENT | ACE_ENABLED)) == ACE_PRESENT) {
270*f7627e25SThomas Gleixner 			rdmsr (MSR_VIA_FCR, lo, hi);
271*f7627e25SThomas Gleixner 			lo |= ACE_FCR;		/* enable ACE unit */
272*f7627e25SThomas Gleixner 			wrmsr (MSR_VIA_FCR, lo, hi);
273*f7627e25SThomas Gleixner 			printk(KERN_INFO "CPU: Enabled ACE h/w crypto\n");
274*f7627e25SThomas Gleixner 		}
275*f7627e25SThomas Gleixner 
276*f7627e25SThomas Gleixner 		/* enable RNG unit, if present and disabled */
277*f7627e25SThomas Gleixner 		if ((tmp & (RNG_PRESENT | RNG_ENABLED)) == RNG_PRESENT) {
278*f7627e25SThomas Gleixner 			rdmsr (MSR_VIA_RNG, lo, hi);
279*f7627e25SThomas Gleixner 			lo |= RNG_ENABLE;	/* enable RNG unit */
280*f7627e25SThomas Gleixner 			wrmsr (MSR_VIA_RNG, lo, hi);
281*f7627e25SThomas Gleixner 			printk(KERN_INFO "CPU: Enabled h/w RNG\n");
282*f7627e25SThomas Gleixner 		}
283*f7627e25SThomas Gleixner 
284*f7627e25SThomas Gleixner 		/* store Centaur Extended Feature Flags as
285*f7627e25SThomas Gleixner 		 * word 5 of the CPU capability bit array
286*f7627e25SThomas Gleixner 		 */
287*f7627e25SThomas Gleixner 		c->x86_capability[5] = cpuid_edx(0xC0000001);
288*f7627e25SThomas Gleixner 	}
289*f7627e25SThomas Gleixner 
290*f7627e25SThomas Gleixner 	/* Cyrix III family needs CX8 & PGE explicity enabled. */
291*f7627e25SThomas Gleixner 	if (c->x86_model >=6 && c->x86_model <= 9) {
292*f7627e25SThomas Gleixner 		rdmsr (MSR_VIA_FCR, lo, hi);
293*f7627e25SThomas Gleixner 		lo |= (1<<1 | 1<<7);
294*f7627e25SThomas Gleixner 		wrmsr (MSR_VIA_FCR, lo, hi);
295*f7627e25SThomas Gleixner 		set_bit(X86_FEATURE_CX8, c->x86_capability);
296*f7627e25SThomas Gleixner 	}
297*f7627e25SThomas Gleixner 
298*f7627e25SThomas Gleixner 	/* Before Nehemiah, the C3's had 3dNOW! */
299*f7627e25SThomas Gleixner 	if (c->x86_model >=6 && c->x86_model <9)
300*f7627e25SThomas Gleixner 		set_bit(X86_FEATURE_3DNOW, c->x86_capability);
301*f7627e25SThomas Gleixner 
302*f7627e25SThomas Gleixner 	get_model_name(c);
303*f7627e25SThomas Gleixner 	display_cacheinfo(c);
304*f7627e25SThomas Gleixner }
305*f7627e25SThomas Gleixner 
306*f7627e25SThomas Gleixner static void __cpuinit init_centaur(struct cpuinfo_x86 *c)
307*f7627e25SThomas Gleixner {
308*f7627e25SThomas Gleixner 	enum {
309*f7627e25SThomas Gleixner 		ECX8=1<<1,
310*f7627e25SThomas Gleixner 		EIERRINT=1<<2,
311*f7627e25SThomas Gleixner 		DPM=1<<3,
312*f7627e25SThomas Gleixner 		DMCE=1<<4,
313*f7627e25SThomas Gleixner 		DSTPCLK=1<<5,
314*f7627e25SThomas Gleixner 		ELINEAR=1<<6,
315*f7627e25SThomas Gleixner 		DSMC=1<<7,
316*f7627e25SThomas Gleixner 		DTLOCK=1<<8,
317*f7627e25SThomas Gleixner 		EDCTLB=1<<8,
318*f7627e25SThomas Gleixner 		EMMX=1<<9,
319*f7627e25SThomas Gleixner 		DPDC=1<<11,
320*f7627e25SThomas Gleixner 		EBRPRED=1<<12,
321*f7627e25SThomas Gleixner 		DIC=1<<13,
322*f7627e25SThomas Gleixner 		DDC=1<<14,
323*f7627e25SThomas Gleixner 		DNA=1<<15,
324*f7627e25SThomas Gleixner 		ERETSTK=1<<16,
325*f7627e25SThomas Gleixner 		E2MMX=1<<19,
326*f7627e25SThomas Gleixner 		EAMD3D=1<<20,
327*f7627e25SThomas Gleixner 	};
328*f7627e25SThomas Gleixner 
329*f7627e25SThomas Gleixner 	char *name;
330*f7627e25SThomas Gleixner 	u32  fcr_set=0;
331*f7627e25SThomas Gleixner 	u32  fcr_clr=0;
332*f7627e25SThomas Gleixner 	u32  lo,hi,newlo;
333*f7627e25SThomas Gleixner 	u32  aa,bb,cc,dd;
334*f7627e25SThomas Gleixner 
335*f7627e25SThomas Gleixner 	/* Bit 31 in normal CPUID used for nonstandard 3DNow ID;
336*f7627e25SThomas Gleixner 	   3DNow is IDd by bit 31 in extended CPUID (1*32+31) anyway */
337*f7627e25SThomas Gleixner 	clear_bit(0*32+31, c->x86_capability);
338*f7627e25SThomas Gleixner 
339*f7627e25SThomas Gleixner 	switch (c->x86) {
340*f7627e25SThomas Gleixner 
341*f7627e25SThomas Gleixner 		case 5:
342*f7627e25SThomas Gleixner 			switch(c->x86_model) {
343*f7627e25SThomas Gleixner 			case 4:
344*f7627e25SThomas Gleixner 				name="C6";
345*f7627e25SThomas Gleixner 				fcr_set=ECX8|DSMC|EDCTLB|EMMX|ERETSTK;
346*f7627e25SThomas Gleixner 				fcr_clr=DPDC;
347*f7627e25SThomas Gleixner 				printk(KERN_NOTICE "Disabling bugged TSC.\n");
348*f7627e25SThomas Gleixner 				clear_bit(X86_FEATURE_TSC, c->x86_capability);
349*f7627e25SThomas Gleixner #ifdef CONFIG_X86_OOSTORE
350*f7627e25SThomas Gleixner 				centaur_create_optimal_mcr();
351*f7627e25SThomas Gleixner 				/* Enable
352*f7627e25SThomas Gleixner 					write combining on non-stack, non-string
353*f7627e25SThomas Gleixner 					write combining on string, all types
354*f7627e25SThomas Gleixner 					weak write ordering
355*f7627e25SThomas Gleixner 
356*f7627e25SThomas Gleixner 				   The C6 original lacks weak read order
357*f7627e25SThomas Gleixner 
358*f7627e25SThomas Gleixner 				   Note 0x120 is write only on Winchip 1 */
359*f7627e25SThomas Gleixner 
360*f7627e25SThomas Gleixner 				wrmsr(MSR_IDT_MCR_CTRL, 0x01F0001F, 0);
361*f7627e25SThomas Gleixner #endif
362*f7627e25SThomas Gleixner 				break;
363*f7627e25SThomas Gleixner 			case 8:
364*f7627e25SThomas Gleixner 				switch(c->x86_mask) {
365*f7627e25SThomas Gleixner 				default:
366*f7627e25SThomas Gleixner 					name="2";
367*f7627e25SThomas Gleixner 					break;
368*f7627e25SThomas Gleixner 				case 7 ... 9:
369*f7627e25SThomas Gleixner 					name="2A";
370*f7627e25SThomas Gleixner 					break;
371*f7627e25SThomas Gleixner 				case 10 ... 15:
372*f7627e25SThomas Gleixner 					name="2B";
373*f7627e25SThomas Gleixner 					break;
374*f7627e25SThomas Gleixner 				}
375*f7627e25SThomas Gleixner 				fcr_set=ECX8|DSMC|DTLOCK|EMMX|EBRPRED|ERETSTK|E2MMX|EAMD3D;
376*f7627e25SThomas Gleixner 				fcr_clr=DPDC;
377*f7627e25SThomas Gleixner #ifdef CONFIG_X86_OOSTORE
378*f7627e25SThomas Gleixner 				winchip2_unprotect_mcr();
379*f7627e25SThomas Gleixner 				winchip2_create_optimal_mcr();
380*f7627e25SThomas Gleixner 				rdmsr(MSR_IDT_MCR_CTRL, lo, hi);
381*f7627e25SThomas Gleixner 				/* Enable
382*f7627e25SThomas Gleixner 					write combining on non-stack, non-string
383*f7627e25SThomas Gleixner 					write combining on string, all types
384*f7627e25SThomas Gleixner 					weak write ordering
385*f7627e25SThomas Gleixner 				*/
386*f7627e25SThomas Gleixner 				lo|=31;
387*f7627e25SThomas Gleixner 				wrmsr(MSR_IDT_MCR_CTRL, lo, hi);
388*f7627e25SThomas Gleixner 				winchip2_protect_mcr();
389*f7627e25SThomas Gleixner #endif
390*f7627e25SThomas Gleixner 				break;
391*f7627e25SThomas Gleixner 			case 9:
392*f7627e25SThomas Gleixner 				name="3";
393*f7627e25SThomas Gleixner 				fcr_set=ECX8|DSMC|DTLOCK|EMMX|EBRPRED|ERETSTK|E2MMX|EAMD3D;
394*f7627e25SThomas Gleixner 				fcr_clr=DPDC;
395*f7627e25SThomas Gleixner #ifdef CONFIG_X86_OOSTORE
396*f7627e25SThomas Gleixner 				winchip2_unprotect_mcr();
397*f7627e25SThomas Gleixner 				winchip2_create_optimal_mcr();
398*f7627e25SThomas Gleixner 				rdmsr(MSR_IDT_MCR_CTRL, lo, hi);
399*f7627e25SThomas Gleixner 				/* Enable
400*f7627e25SThomas Gleixner 					write combining on non-stack, non-string
401*f7627e25SThomas Gleixner 					write combining on string, all types
402*f7627e25SThomas Gleixner 					weak write ordering
403*f7627e25SThomas Gleixner 				*/
404*f7627e25SThomas Gleixner 				lo|=31;
405*f7627e25SThomas Gleixner 				wrmsr(MSR_IDT_MCR_CTRL, lo, hi);
406*f7627e25SThomas Gleixner 				winchip2_protect_mcr();
407*f7627e25SThomas Gleixner #endif
408*f7627e25SThomas Gleixner 				break;
409*f7627e25SThomas Gleixner 			default:
410*f7627e25SThomas Gleixner 				name="??";
411*f7627e25SThomas Gleixner 			}
412*f7627e25SThomas Gleixner 
413*f7627e25SThomas Gleixner 			rdmsr(MSR_IDT_FCR1, lo, hi);
414*f7627e25SThomas Gleixner 			newlo=(lo|fcr_set) & (~fcr_clr);
415*f7627e25SThomas Gleixner 
416*f7627e25SThomas Gleixner 			if (newlo!=lo) {
417*f7627e25SThomas Gleixner 				printk(KERN_INFO "Centaur FCR was 0x%X now 0x%X\n", lo, newlo );
418*f7627e25SThomas Gleixner 				wrmsr(MSR_IDT_FCR1, newlo, hi );
419*f7627e25SThomas Gleixner 			} else {
420*f7627e25SThomas Gleixner 				printk(KERN_INFO "Centaur FCR is 0x%X\n",lo);
421*f7627e25SThomas Gleixner 			}
422*f7627e25SThomas Gleixner 			/* Emulate MTRRs using Centaur's MCR. */
423*f7627e25SThomas Gleixner 			set_bit(X86_FEATURE_CENTAUR_MCR, c->x86_capability);
424*f7627e25SThomas Gleixner 			/* Report CX8 */
425*f7627e25SThomas Gleixner 			set_bit(X86_FEATURE_CX8, c->x86_capability);
426*f7627e25SThomas Gleixner 			/* Set 3DNow! on Winchip 2 and above. */
427*f7627e25SThomas Gleixner 			if (c->x86_model >=8)
428*f7627e25SThomas Gleixner 				set_bit(X86_FEATURE_3DNOW, c->x86_capability);
429*f7627e25SThomas Gleixner 			/* See if we can find out some more. */
430*f7627e25SThomas Gleixner 			if ( cpuid_eax(0x80000000) >= 0x80000005 ) {
431*f7627e25SThomas Gleixner 				/* Yes, we can. */
432*f7627e25SThomas Gleixner 				cpuid(0x80000005,&aa,&bb,&cc,&dd);
433*f7627e25SThomas Gleixner 				/* Add L1 data and code cache sizes. */
434*f7627e25SThomas Gleixner 				c->x86_cache_size = (cc>>24)+(dd>>24);
435*f7627e25SThomas Gleixner 			}
436*f7627e25SThomas Gleixner 			sprintf( c->x86_model_id, "WinChip %s", name );
437*f7627e25SThomas Gleixner 			break;
438*f7627e25SThomas Gleixner 
439*f7627e25SThomas Gleixner 		case 6:
440*f7627e25SThomas Gleixner 			init_c3(c);
441*f7627e25SThomas Gleixner 			break;
442*f7627e25SThomas Gleixner 	}
443*f7627e25SThomas Gleixner }
444*f7627e25SThomas Gleixner 
445*f7627e25SThomas Gleixner static unsigned int __cpuinit centaur_size_cache(struct cpuinfo_x86 * c, unsigned int size)
446*f7627e25SThomas Gleixner {
447*f7627e25SThomas Gleixner 	/* VIA C3 CPUs (670-68F) need further shifting. */
448*f7627e25SThomas Gleixner 	if ((c->x86 == 6) && ((c->x86_model == 7) || (c->x86_model == 8)))
449*f7627e25SThomas Gleixner 		size >>= 8;
450*f7627e25SThomas Gleixner 
451*f7627e25SThomas Gleixner 	/* VIA also screwed up Nehemiah stepping 1, and made
452*f7627e25SThomas Gleixner 	   it return '65KB' instead of '64KB'
453*f7627e25SThomas Gleixner 	   - Note, it seems this may only be in engineering samples. */
454*f7627e25SThomas Gleixner 	if ((c->x86==6) && (c->x86_model==9) && (c->x86_mask==1) && (size==65))
455*f7627e25SThomas Gleixner 		size -=1;
456*f7627e25SThomas Gleixner 
457*f7627e25SThomas Gleixner 	return size;
458*f7627e25SThomas Gleixner }
459*f7627e25SThomas Gleixner 
460*f7627e25SThomas Gleixner static struct cpu_dev centaur_cpu_dev __cpuinitdata = {
461*f7627e25SThomas Gleixner 	.c_vendor	= "Centaur",
462*f7627e25SThomas Gleixner 	.c_ident	= { "CentaurHauls" },
463*f7627e25SThomas Gleixner 	.c_init		= init_centaur,
464*f7627e25SThomas Gleixner 	.c_size_cache	= centaur_size_cache,
465*f7627e25SThomas Gleixner };
466*f7627e25SThomas Gleixner 
467*f7627e25SThomas Gleixner int __init centaur_init_cpu(void)
468*f7627e25SThomas Gleixner {
469*f7627e25SThomas Gleixner 	cpu_devs[X86_VENDOR_CENTAUR] = &centaur_cpu_dev;
470*f7627e25SThomas Gleixner 	return 0;
471*f7627e25SThomas Gleixner }
472