1 #include <linux/kernel.h>
2 #include <linux/init.h>
3 #include <linux/bitops.h>
4 #include <asm/processor.h>
9 #ifdef CONFIG_X86_OOSTORE
11 static u32 __init power2(u32 x)
21 * Set up an actual MCR
24 static void __init centaur_mcr_insert(int reg, u32 base, u32 size, int key)
29 lo = ~(size-1); /* Size is a power of 2 so this makes a mask */
30 lo &= ~0xFFF; /* Remove the ctrl value bits */
31 lo |= key; /* Attribute we wish to set */
32 wrmsr(reg+MSR_IDT_MCR0, lo, hi);
33 mtrr_centaur_report_mcr(reg, lo, hi); /* Tell the mtrr driver */
37 * Figure what we can cover with MCR's
39 * Shortcut: We know you can't put 4Gig of RAM on a winchip
42 static u32 __init ramtop(void) /* 16388 */
46 u32 clip = 0xFFFFFFFFUL;
48 for (i = 0; i < e820.nr_map; i++) {
49 unsigned long start, end;
51 if (e820.map[i].addr > 0xFFFFFFFFUL)
54 * Don't MCR over reserved space. Ignore the ISA hole
55 * we frob around that catastrophy already
58 if (e820.map[i].type == E820_RESERVED)
60 if(e820.map[i].addr >= 0x100000UL && e820.map[i].addr < clip)
61 clip = e820.map[i].addr;
64 start = e820.map[i].addr;
65 end = e820.map[i].addr + e820.map[i].size;
71 /* Everything below 'top' should be RAM except for the ISA hole.
72 Because of the limited MCR's we want to map NV/ACPI into our
73 MCR range for gunk in RAM
75 Clip might cause us to MCR insufficient RAM but that is an
76 acceptable failure mode and should only bite obscure boxes with
79 The second case Clip sometimes kicks in is when the EBDA is marked
80 as reserved. Again we fail safe with reasonable results
90 * Compute a set of MCR's to give maximum coverage
93 static int __init centaur_mcr_compute(int nr, int key)
96 u32 root = power2(mem);
107 * Find the largest block we will fill going upwards
110 u32 high = power2(mem-top);
113 * 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.
123 if(base <= 1024*1024)
127 * See how much space we could cover by filling below
133 else if(floor ==512*1024)
136 /* And forget ROM space */
139 * Now install the largest coverage we get
142 if(fspace > high && fspace > low)
144 centaur_mcr_insert(ct, floor, fspace, key);
149 centaur_mcr_insert(ct, top, high, key);
155 centaur_mcr_insert(ct, base, low, key);
161 * We loaded ct values. We now need to set the mask. The caller
168 static void __init centaur_create_optimal_mcr(void)
172 * Allocate up to 6 mcrs to mark as much of ram as possible
173 * as write combining and weak write ordered.
175 * To experiment with: Linux never uses stack operations for
176 * mmio spaces so we could globally enable stack operation wc
178 * Load the registers with type 31 - full write combining, all
179 * writes weakly ordered.
181 int used = centaur_mcr_compute(6, 31);
188 wrmsr(MSR_IDT_MCR0+i, 0, 0);
191 static void __init winchip2_create_optimal_mcr(void)
197 * Allocate up to 6 mcrs to mark as much of ram as possible
198 * as write combining, weak store ordered.
200 * Load the registers with type 25
201 * 8 - weak write ordering
202 * 16 - weak read ordering
203 * 1 - write combining
206 int used = centaur_mcr_compute(6, 25);
209 * Mark the registers we are using.
212 rdmsr(MSR_IDT_MCR_CTRL, lo, hi);
215 wrmsr(MSR_IDT_MCR_CTRL, lo, hi);
222 wrmsr(MSR_IDT_MCR0+i, 0, 0);
226 * Handle the MCR key on the Winchip 2.
229 static void __init winchip2_unprotect_mcr(void)
234 rdmsr(MSR_IDT_MCR_CTRL, lo, hi);
235 lo&=~0x1C0; /* blank bits 8-6 */
237 lo |= key<<6; /* replace with unlock key */
238 wrmsr(MSR_IDT_MCR_CTRL, lo, hi);
241 static void __init winchip2_protect_mcr(void)
245 rdmsr(MSR_IDT_MCR_CTRL, lo, hi);
246 lo&=~0x1C0; /* blank bits 8-6 */
247 wrmsr(MSR_IDT_MCR_CTRL, lo, hi);
249 #endif /* CONFIG_X86_OOSTORE */
251 #define ACE_PRESENT (1 << 6)
252 #define ACE_ENABLED (1 << 7)
253 #define ACE_FCR (1 << 28) /* MSR_VIA_FCR */
255 #define RNG_PRESENT (1 << 2)
256 #define RNG_ENABLED (1 << 3)
257 #define RNG_ENABLE (1 << 6) /* MSR_VIA_RNG */
259 static void __init init_c3(struct cpuinfo_x86 *c)
263 /* Test for Centaur Extended Feature Flags presence */
264 if (cpuid_eax(0xC0000000) >= 0xC0000001) {
265 u32 tmp = cpuid_edx(0xC0000001);
267 /* enable ACE unit, if present and disabled */
268 if ((tmp & (ACE_PRESENT | ACE_ENABLED)) == ACE_PRESENT) {
269 rdmsr (MSR_VIA_FCR, lo, hi);
270 lo |= ACE_FCR; /* enable ACE unit */
271 wrmsr (MSR_VIA_FCR, lo, hi);
272 printk(KERN_INFO "CPU: Enabled ACE h/w crypto\n");
275 /* enable RNG unit, if present and disabled */
276 if ((tmp & (RNG_PRESENT | RNG_ENABLED)) == RNG_PRESENT) {
277 rdmsr (MSR_VIA_RNG, lo, hi);
278 lo |= RNG_ENABLE; /* enable RNG unit */
279 wrmsr (MSR_VIA_RNG, lo, hi);
280 printk(KERN_INFO "CPU: Enabled h/w RNG\n");
283 /* store Centaur Extended Feature Flags as
284 * word 5 of the CPU capability bit array
286 c->x86_capability[5] = cpuid_edx(0xC0000001);
289 /* Cyrix III family needs CX8 & PGE explicity enabled. */
290 if (c->x86_model >=6 && c->x86_model <= 9) {
291 rdmsr (MSR_VIA_FCR, lo, hi);
293 wrmsr (MSR_VIA_FCR, lo, hi);
294 set_bit(X86_FEATURE_CX8, c->x86_capability);
297 /* Before Nehemiah, the C3's had 3dNOW! */
298 if (c->x86_model >=6 && c->x86_model <9)
299 set_bit(X86_FEATURE_3DNOW, c->x86_capability);
302 display_cacheinfo(c);
305 static void __init init_centaur(struct cpuinfo_x86 *c)
334 /* Bit 31 in normal CPUID used for nonstandard 3DNow ID;
335 3DNow is IDd by bit 31 in extended CPUID (1*32+31) anyway */
336 clear_bit(0*32+31, c->x86_capability);
341 switch(c->x86_model) {
344 fcr_set=ECX8|DSMC|EDCTLB|EMMX|ERETSTK;
346 printk(KERN_NOTICE "Disabling bugged TSC.\n");
347 clear_bit(X86_FEATURE_TSC, c->x86_capability);
348 #ifdef CONFIG_X86_OOSTORE
349 centaur_create_optimal_mcr();
351 write combining on non-stack, non-string
352 write combining on string, all types
355 The C6 original lacks weak read order
357 Note 0x120 is write only on Winchip 1 */
359 wrmsr(MSR_IDT_MCR_CTRL, 0x01F0001F, 0);
363 switch(c->x86_mask) {
374 fcr_set=ECX8|DSMC|DTLOCK|EMMX|EBRPRED|ERETSTK|E2MMX|EAMD3D;
376 #ifdef CONFIG_X86_OOSTORE
377 winchip2_unprotect_mcr();
378 winchip2_create_optimal_mcr();
379 rdmsr(MSR_IDT_MCR_CTRL, lo, hi);
381 write combining on non-stack, non-string
382 write combining on string, all types
386 wrmsr(MSR_IDT_MCR_CTRL, lo, hi);
387 winchip2_protect_mcr();
392 fcr_set=ECX8|DSMC|DTLOCK|EMMX|EBRPRED|ERETSTK|E2MMX|EAMD3D;
394 #ifdef CONFIG_X86_OOSTORE
395 winchip2_unprotect_mcr();
396 winchip2_create_optimal_mcr();
397 rdmsr(MSR_IDT_MCR_CTRL, lo, hi);
399 write combining on non-stack, non-string
400 write combining on string, all types
404 wrmsr(MSR_IDT_MCR_CTRL, lo, hi);
405 winchip2_protect_mcr();
412 rdmsr(MSR_IDT_FCR1, lo, hi);
413 newlo=(lo|fcr_set) & (~fcr_clr);
416 printk(KERN_INFO "Centaur FCR was 0x%X now 0x%X\n", lo, newlo );
417 wrmsr(MSR_IDT_FCR1, newlo, hi );
419 printk(KERN_INFO "Centaur FCR is 0x%X\n",lo);
421 /* Emulate MTRRs using Centaur's MCR. */
422 set_bit(X86_FEATURE_CENTAUR_MCR, c->x86_capability);
424 set_bit(X86_FEATURE_CX8, c->x86_capability);
425 /* Set 3DNow! on Winchip 2 and above. */
426 if (c->x86_model >=8)
427 set_bit(X86_FEATURE_3DNOW, c->x86_capability);
428 /* See if we can find out some more. */
429 if ( cpuid_eax(0x80000000) >= 0x80000005 ) {
431 cpuid(0x80000005,&aa,&bb,&cc,&dd);
432 /* Add L1 data and code cache sizes. */
433 c->x86_cache_size = (cc>>24)+(dd>>24);
435 sprintf( c->x86_model_id, "WinChip %s", name );
444 static unsigned int centaur_size_cache(struct cpuinfo_x86 * c, unsigned int size)
446 /* VIA C3 CPUs (670-68F) need further shifting. */
447 if ((c->x86 == 6) && ((c->x86_model == 7) || (c->x86_model == 8)))
450 /* VIA also screwed up Nehemiah stepping 1, and made
451 it return '65KB' instead of '64KB'
452 - Note, it seems this may only be in engineering samples. */
453 if ((c->x86==6) && (c->x86_model==9) && (c->x86_mask==1) && (size==65))
459 static struct cpu_dev centaur_cpu_dev __initdata = {
460 .c_vendor = "Centaur",
461 .c_ident = { "CentaurHauls" },
462 .c_init = init_centaur,
463 .c_size_cache = centaur_size_cache,
466 int __init centaur_init_cpu(void)
468 cpu_devs[X86_VENDOR_CENTAUR] = ¢aur_cpu_dev;
472 //early_arch_initcall(centaur_init_cpu);
474 static int __init centaur_exit_cpu(void)
476 cpu_devs[X86_VENDOR_CENTAUR] = NULL;
480 late_initcall(centaur_exit_cpu);