centaur.c 5.2 KB
Newer Older
1
#include <linux/bitops.h>
L
Linus Torvalds 已提交
2
#include <linux/kernel.h>
3

4
#include <asm/cpufeature.h>
L
Linus Torvalds 已提交
5
#include <asm/e820.h>
6
#include <asm/mtrr.h>
7
#include <asm/msr.h>
8

L
Linus Torvalds 已提交
9 10 11 12 13 14 15 16 17 18
#include "cpu.h"

#define ACE_PRESENT	(1 << 6)
#define ACE_ENABLED	(1 << 7)
#define ACE_FCR		(1 << 28)	/* MSR_VIA_FCR */

#define RNG_PRESENT	(1 << 2)
#define RNG_ENABLED	(1 << 3)
#define RNG_ENABLE	(1 << 6)	/* MSR_VIA_RNG */

19
static void init_c3(struct cpuinfo_x86 *c)
L
Linus Torvalds 已提交
20 21 22 23 24 25 26 27 28
{
	u32  lo, hi;

	/* Test for Centaur Extended Feature Flags presence */
	if (cpuid_eax(0xC0000000) >= 0xC0000001) {
		u32 tmp = cpuid_edx(0xC0000001);

		/* enable ACE unit, if present and disabled */
		if ((tmp & (ACE_PRESENT | ACE_ENABLED)) == ACE_PRESENT) {
29
			rdmsr(MSR_VIA_FCR, lo, hi);
L
Linus Torvalds 已提交
30
			lo |= ACE_FCR;		/* enable ACE unit */
31
			wrmsr(MSR_VIA_FCR, lo, hi);
L
Linus Torvalds 已提交
32 33 34 35 36
			printk(KERN_INFO "CPU: Enabled ACE h/w crypto\n");
		}

		/* enable RNG unit, if present and disabled */
		if ((tmp & (RNG_PRESENT | RNG_ENABLED)) == RNG_PRESENT) {
37
			rdmsr(MSR_VIA_RNG, lo, hi);
L
Linus Torvalds 已提交
38
			lo |= RNG_ENABLE;	/* enable RNG unit */
39
			wrmsr(MSR_VIA_RNG, lo, hi);
L
Linus Torvalds 已提交
40 41 42 43 44 45
			printk(KERN_INFO "CPU: Enabled h/w RNG\n");
		}

		/* store Centaur Extended Feature Flags as
		 * word 5 of the CPU capability bit array
		 */
46
		c->x86_capability[CPUID_C000_0001_EDX] = cpuid_edx(0xC0000001);
L
Linus Torvalds 已提交
47
	}
48
#ifdef CONFIG_X86_32
S
Simon Arlott 已提交
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);
L
Linus Torvalds 已提交
52
		lo |= (1<<1 | 1<<7);
53
		wrmsr(MSR_VIA_FCR, lo, hi);
54
		set_cpu_cap(c, X86_FEATURE_CX8);
L
Linus Torvalds 已提交
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 61 62 63 64
#endif
	if (c->x86 == 0x6 && c->x86_model >= 0xf) {
		c->x86_cache_alignment = c->x86_clflush_size * 2;
		set_cpu_cap(c, X86_FEATURE_REP_GOOD);
	}
L
Linus Torvalds 已提交
65

66
	cpu_detect_cache_sizes(c);
L
Linus Torvalds 已提交
67 68
}

69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
enum {
		ECX8		= 1<<1,
		EIERRINT	= 1<<2,
		DPM		= 1<<3,
		DMCE		= 1<<4,
		DSTPCLK		= 1<<5,
		ELINEAR		= 1<<6,
		DSMC		= 1<<7,
		DTLOCK		= 1<<8,
		EDCTLB		= 1<<8,
		EMMX		= 1<<9,
		DPDC		= 1<<11,
		EBRPRED		= 1<<12,
		DIC		= 1<<13,
		DDC		= 1<<14,
		DNA		= 1<<15,
		ERETSTK		= 1<<16,
		E2MMX		= 1<<19,
		EAMD3D		= 1<<20,
};

90
static void early_init_centaur(struct cpuinfo_x86 *c)
91 92
{
	switch (c->x86) {
93
#ifdef CONFIG_X86_32
94 95 96 97
	case 5:
		/* Emulate MTRRs using Centaur's MCR. */
		set_cpu_cap(c, X86_FEATURE_CENTAUR_MCR);
		break;
98 99 100 101 102
#endif
	case 6:
		if (c->x86_model >= 0xf)
			set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC);
		break;
103
	}
104 105 106
#ifdef CONFIG_X86_64
	set_cpu_cap(c, X86_FEATURE_SYSENTER32);
#endif
107 108
}

109
static void init_centaur(struct cpuinfo_x86 *c)
L
Linus Torvalds 已提交
110
{
111
#ifdef CONFIG_X86_32
L
Linus Torvalds 已提交
112
	char *name;
113 114 115 116
	u32  fcr_set = 0;
	u32  fcr_clr = 0;
	u32  lo, hi, newlo;
	u32  aa, bb, cc, dd;
L
Linus Torvalds 已提交
117

118 119 120 121
	/*
	 * Bit 31 in normal CPUID used for nonstandard 3DNow ID;
	 * 3DNow is IDd by bit 31 in extended CPUID (1*32+31) anyway
	 */
122
	clear_cpu_cap(c, 0*32+31);
123 124
#endif
	early_init_centaur(c);
L
Linus Torvalds 已提交
125
	switch (c->x86) {
126
#ifdef CONFIG_X86_32
127
	case 5:
128 129 130 131 132 133
		switch (c->x86_model) {
		case 4:
			name = "C6";
			fcr_set = ECX8|DSMC|EDCTLB|EMMX|ERETSTK;
			fcr_clr = DPDC;
			printk(KERN_NOTICE "Disabling bugged TSC.\n");
134
			clear_cpu_cap(c, X86_FEATURE_TSC);
135 136 137 138 139
			break;
		case 8:
			switch (c->x86_mask) {
			default:
			name = "2";
L
Linus Torvalds 已提交
140
				break;
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
			case 7 ... 9:
				name = "2A";
				break;
			case 10 ... 15:
				name = "2B";
				break;
			}
			fcr_set = ECX8|DSMC|DTLOCK|EMMX|EBRPRED|ERETSTK|
				  E2MMX|EAMD3D;
			fcr_clr = DPDC;
			break;
		case 9:
			name = "3";
			fcr_set = ECX8|DSMC|DTLOCK|EMMX|EBRPRED|ERETSTK|
				  E2MMX|EAMD3D;
			fcr_clr = DPDC;
			break;
		default:
			name = "??";
		}
L
Linus Torvalds 已提交
161

162 163
		rdmsr(MSR_IDT_FCR1, lo, hi);
		newlo = (lo|fcr_set) & (~fcr_clr);
L
Linus Torvalds 已提交
164

165 166 167 168 169 170 171 172
		if (newlo != lo) {
			printk(KERN_INFO "Centaur FCR was 0x%X now 0x%X\n",
				lo, newlo);
			wrmsr(MSR_IDT_FCR1, newlo, hi);
		} else {
			printk(KERN_INFO "Centaur FCR is 0x%X\n", lo);
		}
		/* Emulate MTRRs using Centaur's MCR. */
173
		set_cpu_cap(c, X86_FEATURE_CENTAUR_MCR);
174
		/* Report CX8 */
175
		set_cpu_cap(c, X86_FEATURE_CX8);
176 177
		/* Set 3DNow! on Winchip 2 and above. */
		if (c->x86_model >= 8)
178
			set_cpu_cap(c, X86_FEATURE_3DNOW);
179 180 181 182 183 184 185 186 187
		/* See if we can find out some more. */
		if (cpuid_eax(0x80000000) >= 0x80000005) {
			/* Yes, we can. */
			cpuid(0x80000005, &aa, &bb, &cc, &dd);
			/* Add L1 data and code cache sizes. */
			c->x86_cache_size = (cc>>24)+(dd>>24);
		}
		sprintf(c->x86_model_id, "WinChip %s", name);
		break;
188
#endif
189
	case 6:
190 191
		init_c3(c);
		break;
L
Linus Torvalds 已提交
192
	}
193 194 195
#ifdef CONFIG_X86_64
	set_cpu_cap(c, X86_FEATURE_LFENCE_RDTSC);
#endif
L
Linus Torvalds 已提交
196 197
}

198
#ifdef CONFIG_X86_32
199
static unsigned int
200
centaur_size_cache(struct cpuinfo_x86 *c, unsigned int size)
L
Linus Torvalds 已提交
201 202 203 204 205
{
	/* VIA C3 CPUs (670-68F) need further shifting. */
	if ((c->x86 == 6) && ((c->x86_model == 7) || (c->x86_model == 8)))
		size >>= 8;

206 207 208 209 210 211 212
	/*
	 * There's also an erratum in Nehemiah stepping 1, which
	 * returns '65KB' instead of '64KB'
	 *  - Note, it seems this may only be in engineering samples.
	 */
	if ((c->x86 == 6) && (c->x86_model == 9) &&
				(c->x86_mask == 1) && (size == 65))
213
		size -= 1;
L
Linus Torvalds 已提交
214 215
	return size;
}
216
#endif
L
Linus Torvalds 已提交
217

218
static const struct cpu_dev centaur_cpu_dev = {
L
Linus Torvalds 已提交
219 220
	.c_vendor	= "Centaur",
	.c_ident	= { "CentaurHauls" },
221
	.c_early_init	= early_init_centaur,
L
Linus Torvalds 已提交
222
	.c_init		= init_centaur,
223 224 225
#ifdef CONFIG_X86_32
	.legacy_cache_size = centaur_size_cache,
#endif
Y
Yinghai Lu 已提交
226
	.c_x86_vendor	= X86_VENDOR_CENTAUR,
L
Linus Torvalds 已提交
227 228
};

Y
Yinghai Lu 已提交
229
cpu_dev_register(centaur_cpu_dev);