2 * Copyright (c) KATO Takenori, 1997, 1998.
4 * All rights reserved. Unpublished rights reserved under the copyright
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer as
13 * the first lines of this file unmodified.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include <sys/cdefs.h>
31 __FBSDID("$FreeBSD$");
35 #include <sys/param.h>
36 #include <sys/kernel.h>
37 #include <sys/systm.h>
38 #include <sys/sysctl.h>
40 #include <machine/cputypes.h>
41 #include <machine/md_var.h>
42 #include <machine/specialreg.h>
47 #if !defined(CPU_DISABLE_SSE) && defined(I686_CPU)
48 #define CPU_ENABLE_SSE
51 void initializecpu(void);
52 #if defined(I586_CPU) && defined(CPU_WT_ALLOC)
53 void enable_K5_wt_alloc(void);
54 void enable_K6_wt_alloc(void);
55 void enable_K6_2_wt_alloc(void);
59 static void init_5x86(void);
60 static void init_bluelightning(void);
61 static void init_486dlc(void);
62 static void init_cy486dx(void);
63 #ifdef CPU_I486_ON_386
64 static void init_i486_on_386(void);
66 static void init_6x86(void);
70 static void init_6x86MX(void);
71 static void init_ppro(void);
72 static void init_mendocino(void);
75 static int hw_instruction_sse;
76 SYSCTL_INT(_hw, OID_AUTO, instruction_sse, CTLFLAG_RD,
77 &hw_instruction_sse, 0, "SIMD/MMX2 instructions available in CPU");
79 * -1: automatic (default)
80 * 0: keep enable CLFLUSH
81 * 1: force disable CLFLUSH
83 static int hw_clflush_disable = -1;
85 /* Must *NOT* be BSS or locore will bzero these after setting them */
86 int cpu = 0; /* Are we 386, 386sx, 486, etc? */
87 u_int cpu_feature = 0; /* Feature flags */
88 u_int cpu_feature2 = 0; /* Feature flags */
89 u_int amd_feature = 0; /* AMD feature flags */
90 u_int amd_feature2 = 0; /* AMD feature flags */
91 u_int amd_pminfo = 0; /* AMD advanced power management info */
92 u_int via_feature_rng = 0; /* VIA RNG features */
93 u_int via_feature_xcrypt = 0; /* VIA ACE features */
94 u_int cpu_high = 0; /* Highest arg to CPUID */
95 u_int cpu_id = 0; /* Stepping ID */
96 u_int cpu_procinfo = 0; /* HyperThreading Info / Brand Index / CLFUSH */
97 u_int cpu_procinfo2 = 0; /* Multicore info */
98 char cpu_vendor[20] = ""; /* CPU Origin code */
99 u_int cpu_vendor_id = 0; /* CPU vendor ID */
100 u_int cpu_clflush_line_size = 32;
102 SYSCTL_UINT(_hw, OID_AUTO, via_feature_rng, CTLFLAG_RD,
103 &via_feature_rng, 0, "VIA C3/C7 RNG feature available in CPU");
104 SYSCTL_UINT(_hw, OID_AUTO, via_feature_xcrypt, CTLFLAG_RD,
105 &via_feature_xcrypt, 0, "VIA C3/C7 xcrypt feature available in CPU");
107 #ifdef CPU_ENABLE_SSE
108 u_int cpu_fxsr; /* SSE enabled */
109 u_int cpu_mxcsr_mask; /* valid bits in mxcsr */
117 init_bluelightning(void)
121 #if defined(PC98) && !defined(CPU_UPGRADE_HW_CACHE)
122 need_post_dma_flush = 1;
125 eflags = read_eflags();
128 load_cr0(rcr0() | CR0_CD | CR0_NW);
131 #ifdef CPU_BLUELIGHTNING_FPU_OP_CACHE
132 wrmsr(0x1000, 0x9c92LL); /* FP operand can be cacheable on Cyrix FPU */
134 wrmsr(0x1000, 0x1c92LL); /* Intel FPU */
136 /* Enables 13MB and 0-640KB cache. */
137 wrmsr(0x1001, (0xd0LL << 32) | 0x3ff);
138 #ifdef CPU_BLUELIGHTNING_3X
139 wrmsr(0x1002, 0x04000000LL); /* Enables triple-clock mode. */
141 wrmsr(0x1002, 0x03000000LL); /* Enables double-clock mode. */
144 /* Enable caching in CR0. */
145 load_cr0(rcr0() & ~(CR0_CD | CR0_NW)); /* CD = 0 and NW = 0 */
147 write_eflags(eflags);
151 * Cyrix 486SLC/DLC/SR/DR series
159 eflags = read_eflags();
163 ccr0 = read_cyrix_reg(CCR0);
164 #ifndef CYRIX_CACHE_WORKS
165 ccr0 |= CCR0_NC1 | CCR0_BARB;
166 write_cyrix_reg(CCR0, ccr0);
170 #ifndef CYRIX_CACHE_REALLY_WORKS
171 ccr0 |= CCR0_NC1 | CCR0_BARB;
175 #ifdef CPU_DIRECT_MAPPED_CACHE
176 ccr0 |= CCR0_CO; /* Direct mapped mode. */
178 write_cyrix_reg(CCR0, ccr0);
180 /* Clear non-cacheable region. */
181 write_cyrix_reg(NCR1+2, NCR_SIZE_0K);
182 write_cyrix_reg(NCR2+2, NCR_SIZE_0K);
183 write_cyrix_reg(NCR3+2, NCR_SIZE_0K);
184 write_cyrix_reg(NCR4+2, NCR_SIZE_0K);
186 write_cyrix_reg(0, 0); /* dummy write */
188 /* Enable caching in CR0. */
189 load_cr0(rcr0() & ~(CR0_CD | CR0_NW)); /* CD = 0 and NW = 0 */
191 #endif /* !CYRIX_CACHE_WORKS */
192 write_eflags(eflags);
197 * Cyrix 486S/DX series
205 eflags = read_eflags();
209 ccr2 = read_cyrix_reg(CCR2);
211 ccr2 |= CCR2_SUSP_HLT;
215 /* Enables WB cache interface pin and Lock NW bit in CR0. */
216 ccr2 |= CCR2_WB | CCR2_LOCK_NW;
217 /* Unlock NW bit in CR0. */
218 write_cyrix_reg(CCR2, ccr2 & ~CCR2_LOCK_NW);
219 load_cr0((rcr0() & ~CR0_CD) | CR0_NW); /* CD = 0, NW = 1 */
222 write_cyrix_reg(CCR2, ccr2);
223 write_eflags(eflags);
234 u_char ccr2, ccr3, ccr4, pcr0;
236 eflags = read_eflags();
239 load_cr0(rcr0() | CR0_CD | CR0_NW);
242 (void)read_cyrix_reg(CCR3); /* dummy */
244 /* Initialize CCR2. */
245 ccr2 = read_cyrix_reg(CCR2);
248 ccr2 |= CCR2_SUSP_HLT;
250 ccr2 &= ~CCR2_SUSP_HLT;
253 write_cyrix_reg(CCR2, ccr2);
255 /* Initialize CCR4. */
256 ccr3 = read_cyrix_reg(CCR3);
257 write_cyrix_reg(CCR3, CCR3_MAPEN0);
259 ccr4 = read_cyrix_reg(CCR4);
262 #ifdef CPU_FASTER_5X86_FPU
263 ccr4 |= CCR4_FASTFPE;
265 ccr4 &= ~CCR4_FASTFPE;
267 ccr4 &= ~CCR4_IOMASK;
268 /********************************************************************
269 * WARNING: The "BIOS Writers Guide" mentions that I/O recovery time
270 * should be 0 for errata fix.
271 ********************************************************************/
273 ccr4 |= CPU_IORT & CCR4_IOMASK;
275 write_cyrix_reg(CCR4, ccr4);
277 /* Initialize PCR0. */
278 /****************************************************************
279 * WARNING: RSTK_EN and LOOP_EN could make your system unstable.
280 * BTB_EN might make your system unstable.
281 ****************************************************************/
282 pcr0 = read_cyrix_reg(PCR0);
299 /****************************************************************
300 * WARNING: if you use a memory mapped I/O device, don't use
301 * DISABLE_5X86_LSSER option, which may reorder memory mapped
303 * IF YOUR MOTHERBOARD HAS PCI BUS, DON'T DISABLE LSSER.
304 ****************************************************************/
305 #ifdef CPU_DISABLE_5X86_LSSER
310 write_cyrix_reg(PCR0, pcr0);
313 write_cyrix_reg(CCR3, ccr3);
315 (void)read_cyrix_reg(0x80); /* dummy */
317 /* Unlock NW bit in CR0. */
318 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) & ~CCR2_LOCK_NW);
319 load_cr0((rcr0() & ~CR0_CD) | CR0_NW); /* CD = 0, NW = 1 */
320 /* Lock NW bit in CR0. */
321 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) | CCR2_LOCK_NW);
323 write_eflags(eflags);
326 #ifdef CPU_I486_ON_386
328 * There are i486 based upgrade products for i386 machines.
329 * In this case, BIOS doesn't enables CPU cache.
332 init_i486_on_386(void)
336 #if defined(PC98) && !defined(CPU_UPGRADE_HW_CACHE)
337 need_post_dma_flush = 1;
340 eflags = read_eflags();
343 load_cr0(rcr0() & ~(CR0_CD | CR0_NW)); /* CD = 0, NW = 0 */
345 write_eflags(eflags);
352 * XXX - What should I do here? Please let me know.
360 eflags = read_eflags();
363 load_cr0(rcr0() | CR0_CD | CR0_NW);
366 /* Initialize CCR0. */
367 write_cyrix_reg(CCR0, read_cyrix_reg(CCR0) | CCR0_NC1);
369 /* Initialize CCR1. */
370 #ifdef CPU_CYRIX_NO_LOCK
371 write_cyrix_reg(CCR1, read_cyrix_reg(CCR1) | CCR1_NO_LOCK);
373 write_cyrix_reg(CCR1, read_cyrix_reg(CCR1) & ~CCR1_NO_LOCK);
376 /* Initialize CCR2. */
378 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) | CCR2_SUSP_HLT);
380 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) & ~CCR2_SUSP_HLT);
383 ccr3 = read_cyrix_reg(CCR3);
384 write_cyrix_reg(CCR3, CCR3_MAPEN0);
386 /* Initialize CCR4. */
387 ccr4 = read_cyrix_reg(CCR4);
389 ccr4 &= ~CCR4_IOMASK;
391 write_cyrix_reg(CCR4, ccr4 | (CPU_IORT & CCR4_IOMASK));
393 write_cyrix_reg(CCR4, ccr4 | 7);
396 /* Initialize CCR5. */
398 write_cyrix_reg(CCR5, read_cyrix_reg(CCR5) | CCR5_WT_ALLOC);
402 write_cyrix_reg(CCR3, ccr3);
404 /* Unlock NW bit in CR0. */
405 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) & ~CCR2_LOCK_NW);
408 * Earlier revision of the 6x86 CPU could crash the system if
409 * L1 cache is in write-back mode.
411 if ((cyrix_did & 0xff00) > 0x1600)
412 load_cr0(rcr0() & ~(CR0_CD | CR0_NW)); /* CD = 0 and NW = 0 */
414 /* Revision 2.6 and lower. */
415 #ifdef CYRIX_CACHE_REALLY_WORKS
416 load_cr0(rcr0() & ~(CR0_CD | CR0_NW)); /* CD = 0 and NW = 0 */
418 load_cr0((rcr0() & ~CR0_CD) | CR0_NW); /* CD = 0 and NW = 1 */
422 /* Lock NW bit in CR0. */
423 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) | CCR2_LOCK_NW);
425 write_eflags(eflags);
427 #endif /* I486_CPU */
431 * Cyrix 6x86MX (code-named M2)
433 * XXX - What should I do here? Please let me know.
441 eflags = read_eflags();
444 load_cr0(rcr0() | CR0_CD | CR0_NW);
447 /* Initialize CCR0. */
448 write_cyrix_reg(CCR0, read_cyrix_reg(CCR0) | CCR0_NC1);
450 /* Initialize CCR1. */
451 #ifdef CPU_CYRIX_NO_LOCK
452 write_cyrix_reg(CCR1, read_cyrix_reg(CCR1) | CCR1_NO_LOCK);
454 write_cyrix_reg(CCR1, read_cyrix_reg(CCR1) & ~CCR1_NO_LOCK);
457 /* Initialize CCR2. */
459 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) | CCR2_SUSP_HLT);
461 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) & ~CCR2_SUSP_HLT);
464 ccr3 = read_cyrix_reg(CCR3);
465 write_cyrix_reg(CCR3, CCR3_MAPEN0);
467 /* Initialize CCR4. */
468 ccr4 = read_cyrix_reg(CCR4);
469 ccr4 &= ~CCR4_IOMASK;
471 write_cyrix_reg(CCR4, ccr4 | (CPU_IORT & CCR4_IOMASK));
473 write_cyrix_reg(CCR4, ccr4 | 7);
476 /* Initialize CCR5. */
478 write_cyrix_reg(CCR5, read_cyrix_reg(CCR5) | CCR5_WT_ALLOC);
482 write_cyrix_reg(CCR3, ccr3);
484 /* Unlock NW bit in CR0. */
485 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) & ~CCR2_LOCK_NW);
487 load_cr0(rcr0() & ~(CR0_CD | CR0_NW)); /* CD = 0 and NW = 0 */
489 /* Lock NW bit in CR0. */
490 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) | CCR2_LOCK_NW);
492 write_eflags(eflags);
501 * Local APIC should be disabled if it is not going to be used.
503 apicbase = rdmsr(MSR_APICBASE);
504 apicbase &= ~APICBASE_ENABLED;
505 wrmsr(MSR_APICBASE, apicbase);
509 * Initialize BBL_CR_CTL3 (Control register 3: used to configure the
515 #ifdef CPU_PPRO2CELERON
517 u_int64_t bbl_cr_ctl3;
519 eflags = read_eflags();
522 load_cr0(rcr0() | CR0_CD | CR0_NW);
525 bbl_cr_ctl3 = rdmsr(MSR_BBL_CR_CTL3);
527 /* If the L2 cache is configured, do nothing. */
528 if (!(bbl_cr_ctl3 & 1)) {
529 bbl_cr_ctl3 = 0x134052bLL;
531 /* Set L2 Cache Latency (Default: 5). */
532 #ifdef CPU_CELERON_L2_LATENCY
533 #if CPU_L2_LATENCY > 15
534 #error invalid CPU_L2_LATENCY.
536 bbl_cr_ctl3 |= CPU_L2_LATENCY << 1;
538 bbl_cr_ctl3 |= 5 << 1;
540 wrmsr(MSR_BBL_CR_CTL3, bbl_cr_ctl3);
543 load_cr0(rcr0() & ~(CR0_CD | CR0_NW));
544 write_eflags(eflags);
545 #endif /* CPU_PPRO2CELERON */
549 * Initialize special VIA C3/C7 features
557 do_cpuid(0xc0000000, regs);
559 if (val >= 0xc0000001) {
560 do_cpuid(0xc0000001, regs);
565 /* Enable RNG if present and disabled */
566 if (val & VIA_CPUID_HAS_RNG) {
567 if (!(val & VIA_CPUID_DO_RNG)) {
568 msreg = rdmsr(0x110B);
570 wrmsr(0x110B, msreg);
572 via_feature_rng = VIA_HAS_RNG;
574 /* Enable AES engine if present and disabled */
575 if (val & VIA_CPUID_HAS_ACE) {
576 if (!(val & VIA_CPUID_DO_ACE)) {
577 msreg = rdmsr(0x1107);
578 msreg |= (0x01 << 28);
579 wrmsr(0x1107, msreg);
581 via_feature_xcrypt |= VIA_HAS_AES;
583 /* Enable ACE2 engine if present and disabled */
584 if (val & VIA_CPUID_HAS_ACE2) {
585 if (!(val & VIA_CPUID_DO_ACE2)) {
586 msreg = rdmsr(0x1107);
587 msreg |= (0x01 << 28);
588 wrmsr(0x1107, msreg);
590 via_feature_xcrypt |= VIA_HAS_AESCTR;
592 /* Enable SHA engine if present and disabled */
593 if (val & VIA_CPUID_HAS_PHE) {
594 if (!(val & VIA_CPUID_DO_PHE)) {
595 msreg = rdmsr(0x1107);
596 msreg |= (0x01 << 28/**/);
597 wrmsr(0x1107, msreg);
599 via_feature_xcrypt |= VIA_HAS_SHA;
601 /* Enable MM engine if present and disabled */
602 if (val & VIA_CPUID_HAS_PMM) {
603 if (!(val & VIA_CPUID_DO_PMM)) {
604 msreg = rdmsr(0x1107);
605 msreg |= (0x01 << 28/**/);
606 wrmsr(0x1107, msreg);
608 via_feature_xcrypt |= VIA_HAS_MM;
612 #endif /* I686_CPU */
615 * Initialize CR4 (Control register 4) to enable SSE instructions.
620 #if defined(CPU_ENABLE_SSE)
621 if ((cpu_feature & CPUID_XMM) && (cpu_feature & CPUID_FXSR)) {
622 load_cr4(rcr4() | CR4_FXSR | CR4_XMM);
623 cpu_fxsr = hw_instruction_sse = 1;
635 init_bluelightning();
646 #ifdef CPU_I486_ON_386
654 #endif /* I486_CPU */
660 if (cpu_vendor_id == CPU_VENDOR_INTEL) {
661 switch (cpu_id & 0xff0) {
669 } else if (cpu_vendor_id == CPU_VENDOR_AMD) {
670 #if defined(I686_CPU) && defined(CPU_ATHLON_SSE_HACK)
672 * Sometimes the BIOS doesn't enable SSE instructions.
673 * According to AMD document 20734, the mobile
674 * Duron, the (mobile) Athlon 4 and the Athlon MP
675 * support SSE. These correspond to cpu_id 0x66X
678 if ((cpu_feature & CPUID_XMM) == 0 &&
679 ((cpu_id & ~0xf) == 0x660 ||
680 (cpu_id & ~0xf) == 0x670 ||
681 (cpu_id & ~0xf) == 0x680)) {
683 wrmsr(0xC0010015, rdmsr(0xC0010015) & ~0x08000);
685 cpu_feature = regs[3];
688 } else if (cpu_vendor_id == CPU_VENDOR_CENTAUR) {
689 switch (cpu_id & 0xff0) {
691 if ((cpu_id & 0xf) < 3)
704 if ((amd_feature & AMDID_NX) != 0) {
707 msr = rdmsr(MSR_EFER) | EFER_NXE;
708 wrmsr(MSR_EFER, msr);
720 * CPUID with %eax = 1, %ebx returns
721 * Bits 15-8: CLFLUSH line size
722 * (Value * 8 = cache line size in bytes)
724 if ((cpu_feature & CPUID_CLFSH) != 0)
725 cpu_clflush_line_size = ((cpu_procinfo >> 8) & 0xff) * 8;
727 * XXXKIB: (temporary) hack to work around traps generated when
728 * CLFLUSHing APIC registers window.
730 TUNABLE_INT_FETCH("hw.clflush_disable", &hw_clflush_disable);
731 if (cpu_vendor_id == CPU_VENDOR_INTEL && !(cpu_feature & CPUID_SS) &&
732 hw_clflush_disable == -1)
733 cpu_feature &= ~CPUID_CLFSH;
735 * Allow to disable CLFLUSH feature manually by
736 * hw.clflush_disable tunable. This may help Xen guest on some AMD
739 if (hw_clflush_disable == 1)
740 cpu_feature &= ~CPUID_CLFSH;
742 #if defined(PC98) && !defined(CPU_UPGRADE_HW_CACHE)
744 * OS should flush L1 cache by itself because no PC-98 supports
745 * non-Intel CPUs. Use wbinvd instruction before DMA transfer
746 * when need_pre_dma_flush = 1, use invd instruction after DMA
747 * transfer when need_post_dma_flush = 1. If your CPU upgrade
748 * product supports hardware cache control, you can add the
749 * CPU_UPGRADE_HW_CACHE option in your kernel configuration file.
750 * This option eliminates unneeded cache flush instruction(s).
752 if (cpu_vendor_id == CPU_VENDOR_CYRIX) {
756 need_post_dma_flush = 1;
759 need_pre_dma_flush = 1;
762 need_pre_dma_flush = 1;
763 #ifdef CPU_I486_ON_386
764 need_post_dma_flush = 1;
771 } else if (cpu_vendor_id == CPU_VENDOR_AMD) {
772 switch (cpu_id & 0xFF0) {
773 case 0x470: /* Enhanced Am486DX2 WB */
774 case 0x490: /* Enhanced Am486DX4 WB */
775 case 0x4F0: /* Am5x86 WB */
776 need_pre_dma_flush = 1;
779 } else if (cpu_vendor_id == CPU_VENDOR_IBM) {
780 need_post_dma_flush = 1;
782 #ifdef CPU_I486_ON_386
783 need_pre_dma_flush = 1;
786 #endif /* PC98 && !CPU_UPGRADE_HW_CACHE */
789 #if defined(I586_CPU) && defined(CPU_WT_ALLOC)
791 * Enable write allocate feature of AMD processors.
792 * Following two functions require the Maxmem variable being set.
795 enable_K5_wt_alloc(void)
801 * Write allocate is supported only on models 1, 2, and 3, with
802 * a stepping of 4 or greater.
804 if (((cpu_id & 0xf0) > 0) && ((cpu_id & 0x0f) > 3)) {
805 savecrit = intr_disable();
806 msr = rdmsr(0x83); /* HWCR */
807 wrmsr(0x83, msr & !(0x10));
810 * We have to tell the chip where the top of memory is,
811 * since video cards could have frame bufferes there,
812 * memory-mapped I/O could be there, etc.
818 msr |= AMD_WT_ALLOC_TME | AMD_WT_ALLOC_FRE;
820 if (!(inb(0x43b) & 4)) {
821 wrmsr(0x86, 0x0ff00f0);
822 msr |= AMD_WT_ALLOC_PRE;
826 * There is no way to know wheter 15-16M hole exists or not.
827 * Therefore, we disable write allocate for this range.
829 wrmsr(0x86, 0x0ff00f0);
830 msr |= AMD_WT_ALLOC_PRE;
835 wrmsr(0x83, msr|0x10); /* enable write allocate */
836 intr_restore(savecrit);
841 enable_K6_wt_alloc(void)
847 eflags = read_eflags();
851 #ifdef CPU_DISABLE_CACHE
853 * Certain K6-2 box becomes unstable when write allocation is
857 * The AMD-K6 processer provides the 64-bit Test Register 12(TR12),
858 * but only the Cache Inhibit(CI) (bit 3 of TR12) is suppported.
859 * All other bits in TR12 have no effect on the processer's operation.
860 * The I/O Trap Restart function (bit 9 of TR12) is always enabled
863 wrmsr(0x0000000e, (u_int64_t)0x0008);
865 /* Don't assume that memory size is aligned with 4M. */
867 size = ((Maxmem >> 8) + 3) >> 2;
871 /* Limit is 508M bytes. */
874 whcr = (rdmsr(0xc0000082) & ~(0x7fLL << 1)) | (size << 1);
876 #if defined(PC98) || defined(NO_MEMORY_HOLE)
877 if (whcr & (0x7fLL << 1)) {
880 * If bit 2 of port 0x43b is 0, disable wrte allocate for the
883 if (!(inb(0x43b) & 4))
891 * There is no way to know wheter 15-16M hole exists or not.
892 * Therefore, we disable write allocate for this range.
896 wrmsr(0x0c0000082, whcr);
898 write_eflags(eflags);
902 enable_K6_2_wt_alloc(void)
908 eflags = read_eflags();
912 #ifdef CPU_DISABLE_CACHE
914 * Certain K6-2 box becomes unstable when write allocation is
918 * The AMD-K6 processer provides the 64-bit Test Register 12(TR12),
919 * but only the Cache Inhibit(CI) (bit 3 of TR12) is suppported.
920 * All other bits in TR12 have no effect on the processer's operation.
921 * The I/O Trap Restart function (bit 9 of TR12) is always enabled
924 wrmsr(0x0000000e, (u_int64_t)0x0008);
926 /* Don't assume that memory size is aligned with 4M. */
928 size = ((Maxmem >> 8) + 3) >> 2;
932 /* Limit is 4092M bytes. */
935 whcr = (rdmsr(0xc0000082) & ~(0x3ffLL << 22)) | (size << 22);
937 #if defined(PC98) || defined(NO_MEMORY_HOLE)
938 if (whcr & (0x3ffLL << 22)) {
941 * If bit 2 of port 0x43b is 0, disable wrte allocate for the
944 if (!(inb(0x43b) & 4))
945 whcr &= ~(1LL << 16);
952 * There is no way to know wheter 15-16M hole exists or not.
953 * Therefore, we disable write allocate for this range.
955 whcr &= ~(1LL << 16);
957 wrmsr(0x0c0000082, whcr);
959 write_eflags(eflags);
961 #endif /* I585_CPU && CPU_WT_ALLOC */
967 DB_SHOW_COMMAND(cyrixreg, cyrixreg)
971 u_char ccr1, ccr2, ccr3;
972 u_char ccr0 = 0, ccr4 = 0, ccr5 = 0, pcr0 = 0;
975 if (cpu_vendor_id == CPU_VENDOR_CYRIX) {
976 eflags = read_eflags();
980 if ((cpu != CPU_M1SC) && (cpu != CPU_CY486DX)) {
981 ccr0 = read_cyrix_reg(CCR0);
983 ccr1 = read_cyrix_reg(CCR1);
984 ccr2 = read_cyrix_reg(CCR2);
985 ccr3 = read_cyrix_reg(CCR3);
986 if ((cpu == CPU_M1SC) || (cpu == CPU_M1) || (cpu == CPU_M2)) {
987 write_cyrix_reg(CCR3, CCR3_MAPEN0);
988 ccr4 = read_cyrix_reg(CCR4);
989 if ((cpu == CPU_M1) || (cpu == CPU_M2))
990 ccr5 = read_cyrix_reg(CCR5);
992 pcr0 = read_cyrix_reg(PCR0);
993 write_cyrix_reg(CCR3, ccr3); /* Restore CCR3. */
995 write_eflags(eflags);
997 if ((cpu != CPU_M1SC) && (cpu != CPU_CY486DX))
998 printf("CCR0=%x, ", (u_int)ccr0);
1000 printf("CCR1=%x, CCR2=%x, CCR3=%x",
1001 (u_int)ccr1, (u_int)ccr2, (u_int)ccr3);
1002 if ((cpu == CPU_M1SC) || (cpu == CPU_M1) || (cpu == CPU_M2)) {
1003 printf(", CCR4=%x, ", (u_int)ccr4);
1004 if (cpu == CPU_M1SC)
1005 printf("PCR0=%x\n", pcr0);
1007 printf("CCR5=%x\n", ccr5);
1010 printf("CR0=%x\n", cr0);