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