1 #include <linux/bitops.h>
2 #include <linux/kernel.h>
3 #include <linux/init.h>
5 #include <asm/processor.h>
12 #ifdef CONFIG_X86_OOSTORE
14 static u32 __cpuinit
power2(u32 x
)
26 * Set up an actual MCR
28 static void __cpuinit
centaur_mcr_insert(int reg
, u32 base
, u32 size
, int key
)
33 lo
= ~(size
-1); /* Size is a power of 2 so this makes a mask */
34 lo
&= ~0xFFF; /* Remove the ctrl value bits */
35 lo
|= key
; /* Attribute we wish to set */
36 wrmsr(reg
+MSR_IDT_MCR0
, lo
, hi
);
37 mtrr_centaur_report_mcr(reg
, lo
, hi
); /* Tell the mtrr driver */
41 * Figure what we can cover with MCR's
43 * Shortcut: We know you can't put 4Gig of RAM on a winchip
45 static u32 __cpuinit
ramtop(void)
47 u32 clip
= 0xFFFFFFFFUL
;
51 for (i
= 0; i
< e820
.nr_map
; i
++) {
52 unsigned long start
, end
;
54 if (e820
.map
[i
].addr
> 0xFFFFFFFFUL
)
57 * Don't MCR over reserved space. Ignore the ISA hole
58 * we frob around that catastrophe already
60 if (e820
.map
[i
].type
== E820_RESERVED
) {
61 if (e820
.map
[i
].addr
>= 0x100000UL
&&
62 e820
.map
[i
].addr
< clip
)
63 clip
= e820
.map
[i
].addr
;
66 start
= e820
.map
[i
].addr
;
67 end
= e820
.map
[i
].addr
+ e820
.map
[i
].size
;
74 * Everything below 'top' should be RAM except for the ISA hole.
75 * Because of the limited MCR's we want to map NV/ACPI into our
76 * MCR range for gunk in RAM
78 * Clip might cause us to MCR insufficient RAM but that is an
79 * acceptable failure mode and should only bite obscure boxes with
82 * The second case Clip sometimes kicks in is when the EBDA is marked
83 * as reserved. Again we fail safe with reasonable results
92 * Compute a set of MCR's to give maximum coverage
94 static int __cpuinit
centaur_mcr_compute(int nr
, int key
)
97 u32 root
= power2(mem
);
109 * Find the largest block we will fill going upwards
111 high
= power2(mem
-top
);
114 * Find the largest block we will fill going downwards
119 * Don't fill below 1Mb going downwards as there
120 * is an ISA hole in the way.
122 if (base
<= 1024*1024)
126 * See how much space we could cover by filling below
132 else if (floor
== 512*1024)
135 /* And forget ROM space */
138 * Now install the largest coverage we get
140 if (fspace
> high
&& fspace
> low
) {
141 centaur_mcr_insert(ct
, floor
, fspace
, key
);
143 } else if (high
> low
) {
144 centaur_mcr_insert(ct
, top
, high
, key
);
146 } else if (low
> 0) {
148 centaur_mcr_insert(ct
, base
, low
, key
);
154 * We loaded ct values. We now need to set the mask. The caller
160 static void __cpuinit
centaur_create_optimal_mcr(void)
166 * Allocate up to 6 mcrs to mark as much of ram as possible
167 * as write combining and weak write ordered.
169 * To experiment with: Linux never uses stack operations for
170 * mmio spaces so we could globally enable stack operation wc
172 * Load the registers with type 31 - full write combining, all
173 * writes weakly ordered.
175 used
= centaur_mcr_compute(6, 31);
180 for (i
= used
; i
< 8; i
++)
181 wrmsr(MSR_IDT_MCR0
+i
, 0, 0);
184 static void __cpuinit
winchip2_create_optimal_mcr(void)
191 * Allocate up to 6 mcrs to mark as much of ram as possible
192 * as write combining, weak store ordered.
194 * Load the registers with type 25
195 * 8 - weak write ordering
196 * 16 - weak read ordering
197 * 1 - write combining
199 used
= centaur_mcr_compute(6, 25);
202 * Mark the registers we are using.
204 rdmsr(MSR_IDT_MCR_CTRL
, lo
, hi
);
205 for (i
= 0; i
< used
; i
++)
207 wrmsr(MSR_IDT_MCR_CTRL
, lo
, hi
);
213 for (i
= used
; i
< 8; i
++)
214 wrmsr(MSR_IDT_MCR0
+i
, 0, 0);
218 * Handle the MCR key on the Winchip 2.
220 static void __cpuinit
winchip2_unprotect_mcr(void)
225 rdmsr(MSR_IDT_MCR_CTRL
, lo
, hi
);
226 lo
&= ~0x1C0; /* blank bits 8-6 */
228 lo
|= key
<<6; /* replace with unlock key */
229 wrmsr(MSR_IDT_MCR_CTRL
, lo
, hi
);
232 static void __cpuinit
winchip2_protect_mcr(void)
236 rdmsr(MSR_IDT_MCR_CTRL
, lo
, hi
);
237 lo
&= ~0x1C0; /* blank bits 8-6 */
238 wrmsr(MSR_IDT_MCR_CTRL
, lo
, hi
);
240 #endif /* CONFIG_X86_OOSTORE */
242 #define ACE_PRESENT (1 << 6)
243 #define ACE_ENABLED (1 << 7)
244 #define ACE_FCR (1 << 28) /* MSR_VIA_FCR */
246 #define RNG_PRESENT (1 << 2)
247 #define RNG_ENABLED (1 << 3)
248 #define RNG_ENABLE (1 << 6) /* MSR_VIA_RNG */
250 static void __cpuinit
init_c3(struct cpuinfo_x86
*c
)
254 /* Test for Centaur Extended Feature Flags presence */
255 if (cpuid_eax(0xC0000000) >= 0xC0000001) {
256 u32 tmp
= cpuid_edx(0xC0000001);
258 /* enable ACE unit, if present and disabled */
259 if ((tmp
& (ACE_PRESENT
| ACE_ENABLED
)) == ACE_PRESENT
) {
260 rdmsr(MSR_VIA_FCR
, lo
, hi
);
261 lo
|= ACE_FCR
; /* enable ACE unit */
262 wrmsr(MSR_VIA_FCR
, lo
, hi
);
263 printk(KERN_INFO
"CPU: Enabled ACE h/w crypto\n");
266 /* enable RNG unit, if present and disabled */
267 if ((tmp
& (RNG_PRESENT
| RNG_ENABLED
)) == RNG_PRESENT
) {
268 rdmsr(MSR_VIA_RNG
, lo
, hi
);
269 lo
|= RNG_ENABLE
; /* enable RNG unit */
270 wrmsr(MSR_VIA_RNG
, lo
, hi
);
271 printk(KERN_INFO
"CPU: Enabled h/w RNG\n");
274 /* store Centaur Extended Feature Flags as
275 * word 5 of the CPU capability bit array
277 c
->x86_capability
[5] = cpuid_edx(0xC0000001);
280 /* Cyrix III family needs CX8 & PGE explicitly enabled. */
281 if (c
->x86_model
>= 6 && c
->x86_model
<= 9) {
282 rdmsr(MSR_VIA_FCR
, lo
, hi
);
284 wrmsr(MSR_VIA_FCR
, lo
, hi
);
285 set_cpu_cap(c
, X86_FEATURE_CX8
);
288 /* Before Nehemiah, the C3's had 3dNOW! */
289 if (c
->x86_model
>= 6 && c
->x86_model
< 9)
290 set_cpu_cap(c
, X86_FEATURE_3DNOW
);
292 if (c
->x86
== 0x6 && c
->x86_model
>= 0xf) {
293 c
->x86_cache_alignment
= c
->x86_clflush_size
* 2;
294 set_cpu_cap(c
, X86_FEATURE_REP_GOOD
);
297 cpu_detect_cache_sizes(c
);
321 static void __cpuinit
early_init_centaur(struct cpuinfo_x86
*c
)
326 /* Emulate MTRRs using Centaur's MCR. */
327 set_cpu_cap(c
, X86_FEATURE_CENTAUR_MCR
);
331 if (c
->x86_model
>= 0xf)
332 set_cpu_cap(c
, X86_FEATURE_CONSTANT_TSC
);
336 set_cpu_cap(c
, X86_FEATURE_SYSENTER32
);
340 static void __cpuinit
init_centaur(struct cpuinfo_x86
*c
)
350 * Bit 31 in normal CPUID used for nonstandard 3DNow ID;
351 * 3DNow is IDd by bit 31 in extended CPUID (1*32+31) anyway
353 clear_cpu_cap(c
, 0*32+31);
355 early_init_centaur(c
);
359 switch (c
->x86_model
) {
362 fcr_set
= ECX8
|DSMC
|EDCTLB
|EMMX
|ERETSTK
;
364 printk(KERN_NOTICE
"Disabling bugged TSC.\n");
365 clear_cpu_cap(c
, X86_FEATURE_TSC
);
366 #ifdef CONFIG_X86_OOSTORE
367 centaur_create_optimal_mcr();
370 * write combining on non-stack, non-string
371 * write combining on string, all types
372 * weak write ordering
374 * The C6 original lacks weak read order
376 * Note 0x120 is write only on Winchip 1
378 wrmsr(MSR_IDT_MCR_CTRL
, 0x01F0001F, 0);
382 switch (c
->x86_mask
) {
393 fcr_set
= ECX8
|DSMC
|DTLOCK
|EMMX
|EBRPRED
|ERETSTK
|
396 #ifdef CONFIG_X86_OOSTORE
397 winchip2_unprotect_mcr();
398 winchip2_create_optimal_mcr();
399 rdmsr(MSR_IDT_MCR_CTRL
, lo
, hi
);
402 * write combining on non-stack, non-string
403 * write combining on string, all types
404 * weak write ordering
407 wrmsr(MSR_IDT_MCR_CTRL
, lo
, hi
);
408 winchip2_protect_mcr();
413 fcr_set
= ECX8
|DSMC
|DTLOCK
|EMMX
|EBRPRED
|ERETSTK
|
416 #ifdef CONFIG_X86_OOSTORE
417 winchip2_unprotect_mcr();
418 winchip2_create_optimal_mcr();
419 rdmsr(MSR_IDT_MCR_CTRL
, lo
, hi
);
422 * write combining on non-stack, non-string
423 * write combining on string, all types
424 * weak write ordering
427 wrmsr(MSR_IDT_MCR_CTRL
, lo
, hi
);
428 winchip2_protect_mcr();
435 rdmsr(MSR_IDT_FCR1
, lo
, hi
);
436 newlo
= (lo
|fcr_set
) & (~fcr_clr
);
439 printk(KERN_INFO
"Centaur FCR was 0x%X now 0x%X\n",
441 wrmsr(MSR_IDT_FCR1
, newlo
, hi
);
443 printk(KERN_INFO
"Centaur FCR is 0x%X\n", lo
);
445 /* Emulate MTRRs using Centaur's MCR. */
446 set_cpu_cap(c
, X86_FEATURE_CENTAUR_MCR
);
448 set_cpu_cap(c
, X86_FEATURE_CX8
);
449 /* Set 3DNow! on Winchip 2 and above. */
450 if (c
->x86_model
>= 8)
451 set_cpu_cap(c
, X86_FEATURE_3DNOW
);
452 /* See if we can find out some more. */
453 if (cpuid_eax(0x80000000) >= 0x80000005) {
455 cpuid(0x80000005, &aa
, &bb
, &cc
, &dd
);
456 /* Add L1 data and code cache sizes. */
457 c
->x86_cache_size
= (cc
>>24)+(dd
>>24);
459 sprintf(c
->x86_model_id
, "WinChip %s", name
);
467 set_cpu_cap(c
, X86_FEATURE_LFENCE_RDTSC
);
471 static unsigned int __cpuinit
472 centaur_size_cache(struct cpuinfo_x86
*c
, unsigned int size
)
475 /* VIA C3 CPUs (670-68F) need further shifting. */
476 if ((c
->x86
== 6) && ((c
->x86_model
== 7) || (c
->x86_model
== 8)))
480 * There's also an erratum in Nehemiah stepping 1, which
481 * returns '65KB' instead of '64KB'
482 * - Note, it seems this may only be in engineering samples.
484 if ((c
->x86
== 6) && (c
->x86_model
== 9) &&
485 (c
->x86_mask
== 1) && (size
== 65))
491 static const struct cpu_dev __cpuinitconst centaur_cpu_dev
= {
492 .c_vendor
= "Centaur",
493 .c_ident
= { "CentaurHauls" },
494 .c_early_init
= early_init_centaur
,
495 .c_init
= init_centaur
,
496 .c_size_cache
= centaur_size_cache
,
497 .c_x86_vendor
= X86_VENDOR_CENTAUR
,
500 cpu_dev_register(centaur_cpu_dev
);