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 /* Must *NOT* be BSS or locore will bzero these after setting them */
80 int cpu = 0; /* Are we 386, 386sx, 486, etc? */
81 u_int cpu_feature = 0; /* Feature flags */
82 u_int cpu_feature2 = 0; /* Feature flags */
83 u_int amd_feature = 0; /* AMD feature flags */
84 u_int amd_feature2 = 0; /* AMD feature flags */
85 u_int amd_pminfo = 0; /* AMD advanced power management info */
86 u_int via_feature_rng = 0; /* VIA RNG features */
87 u_int via_feature_xcrypt = 0; /* VIA ACE features */
88 u_int cpu_high = 0; /* Highest arg to CPUID */
89 u_int cpu_id = 0; /* Stepping ID */
90 u_int cpu_procinfo = 0; /* HyperThreading Info / Brand Index / CLFUSH */
91 u_int cpu_procinfo2 = 0; /* Multicore info */
92 char cpu_vendor[20] = ""; /* CPU Origin code */
93 u_int cpu_vendor_id = 0; /* CPU vendor ID */
94 u_int cpu_clflush_line_size = 32;
96 SYSCTL_UINT(_hw, OID_AUTO, via_feature_rng, CTLFLAG_RD,
97 &via_feature_rng, 0, "VIA C3/C7 RNG feature available in CPU");
98 SYSCTL_UINT(_hw, OID_AUTO, via_feature_xcrypt, CTLFLAG_RD,
99 &via_feature_xcrypt, 0, "VIA C3/C7 xcrypt feature available in CPU");
101 #ifdef CPU_ENABLE_SSE
102 u_int cpu_fxsr; /* SSE enabled */
103 u_int cpu_mxcsr_mask; /* valid bits in mxcsr */
111 init_bluelightning(void)
115 #if defined(PC98) && !defined(CPU_UPGRADE_HW_CACHE)
116 need_post_dma_flush = 1;
119 eflags = read_eflags();
122 load_cr0(rcr0() | CR0_CD | CR0_NW);
125 #ifdef CPU_BLUELIGHTNING_FPU_OP_CACHE
126 wrmsr(0x1000, 0x9c92LL); /* FP operand can be cacheable on Cyrix FPU */
128 wrmsr(0x1000, 0x1c92LL); /* Intel FPU */
130 /* Enables 13MB and 0-640KB cache. */
131 wrmsr(0x1001, (0xd0LL << 32) | 0x3ff);
132 #ifdef CPU_BLUELIGHTNING_3X
133 wrmsr(0x1002, 0x04000000LL); /* Enables triple-clock mode. */
135 wrmsr(0x1002, 0x03000000LL); /* Enables double-clock mode. */
138 /* Enable caching in CR0. */
139 load_cr0(rcr0() & ~(CR0_CD | CR0_NW)); /* CD = 0 and NW = 0 */
141 write_eflags(eflags);
145 * Cyrix 486SLC/DLC/SR/DR series
153 eflags = read_eflags();
157 ccr0 = read_cyrix_reg(CCR0);
158 #ifndef CYRIX_CACHE_WORKS
159 ccr0 |= CCR0_NC1 | CCR0_BARB;
160 write_cyrix_reg(CCR0, ccr0);
164 #ifndef CYRIX_CACHE_REALLY_WORKS
165 ccr0 |= CCR0_NC1 | CCR0_BARB;
169 #ifdef CPU_DIRECT_MAPPED_CACHE
170 ccr0 |= CCR0_CO; /* Direct mapped mode. */
172 write_cyrix_reg(CCR0, ccr0);
174 /* Clear non-cacheable region. */
175 write_cyrix_reg(NCR1+2, NCR_SIZE_0K);
176 write_cyrix_reg(NCR2+2, NCR_SIZE_0K);
177 write_cyrix_reg(NCR3+2, NCR_SIZE_0K);
178 write_cyrix_reg(NCR4+2, NCR_SIZE_0K);
180 write_cyrix_reg(0, 0); /* dummy write */
182 /* Enable caching in CR0. */
183 load_cr0(rcr0() & ~(CR0_CD | CR0_NW)); /* CD = 0 and NW = 0 */
185 #endif /* !CYRIX_CACHE_WORKS */
186 write_eflags(eflags);
191 * Cyrix 486S/DX series
199 eflags = read_eflags();
203 ccr2 = read_cyrix_reg(CCR2);
205 ccr2 |= CCR2_SUSP_HLT;
209 /* Enables WB cache interface pin and Lock NW bit in CR0. */
210 ccr2 |= CCR2_WB | CCR2_LOCK_NW;
211 /* Unlock NW bit in CR0. */
212 write_cyrix_reg(CCR2, ccr2 & ~CCR2_LOCK_NW);
213 load_cr0((rcr0() & ~CR0_CD) | CR0_NW); /* CD = 0, NW = 1 */
216 write_cyrix_reg(CCR2, ccr2);
217 write_eflags(eflags);
228 u_char ccr2, ccr3, ccr4, pcr0;
230 eflags = read_eflags();
233 load_cr0(rcr0() | CR0_CD | CR0_NW);
236 (void)read_cyrix_reg(CCR3); /* dummy */
238 /* Initialize CCR2. */
239 ccr2 = read_cyrix_reg(CCR2);
242 ccr2 |= CCR2_SUSP_HLT;
244 ccr2 &= ~CCR2_SUSP_HLT;
247 write_cyrix_reg(CCR2, ccr2);
249 /* Initialize CCR4. */
250 ccr3 = read_cyrix_reg(CCR3);
251 write_cyrix_reg(CCR3, CCR3_MAPEN0);
253 ccr4 = read_cyrix_reg(CCR4);
256 #ifdef CPU_FASTER_5X86_FPU
257 ccr4 |= CCR4_FASTFPE;
259 ccr4 &= ~CCR4_FASTFPE;
261 ccr4 &= ~CCR4_IOMASK;
262 /********************************************************************
263 * WARNING: The "BIOS Writers Guide" mentions that I/O recovery time
264 * should be 0 for errata fix.
265 ********************************************************************/
267 ccr4 |= CPU_IORT & CCR4_IOMASK;
269 write_cyrix_reg(CCR4, ccr4);
271 /* Initialize PCR0. */
272 /****************************************************************
273 * WARNING: RSTK_EN and LOOP_EN could make your system unstable.
274 * BTB_EN might make your system unstable.
275 ****************************************************************/
276 pcr0 = read_cyrix_reg(PCR0);
293 /****************************************************************
294 * WARNING: if you use a memory mapped I/O device, don't use
295 * DISABLE_5X86_LSSER option, which may reorder memory mapped
297 * IF YOUR MOTHERBOARD HAS PCI BUS, DON'T DISABLE LSSER.
298 ****************************************************************/
299 #ifdef CPU_DISABLE_5X86_LSSER
304 write_cyrix_reg(PCR0, pcr0);
307 write_cyrix_reg(CCR3, ccr3);
309 (void)read_cyrix_reg(0x80); /* dummy */
311 /* Unlock NW bit in CR0. */
312 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) & ~CCR2_LOCK_NW);
313 load_cr0((rcr0() & ~CR0_CD) | CR0_NW); /* CD = 0, NW = 1 */
314 /* Lock NW bit in CR0. */
315 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) | CCR2_LOCK_NW);
317 write_eflags(eflags);
320 #ifdef CPU_I486_ON_386
322 * There are i486 based upgrade products for i386 machines.
323 * In this case, BIOS doesn't enables CPU cache.
326 init_i486_on_386(void)
330 #if defined(PC98) && !defined(CPU_UPGRADE_HW_CACHE)
331 need_post_dma_flush = 1;
334 eflags = read_eflags();
337 load_cr0(rcr0() & ~(CR0_CD | CR0_NW)); /* CD = 0, NW = 0 */
339 write_eflags(eflags);
346 * XXX - What should I do here? Please let me know.
354 eflags = read_eflags();
357 load_cr0(rcr0() | CR0_CD | CR0_NW);
360 /* Initialize CCR0. */
361 write_cyrix_reg(CCR0, read_cyrix_reg(CCR0) | CCR0_NC1);
363 /* Initialize CCR1. */
364 #ifdef CPU_CYRIX_NO_LOCK
365 write_cyrix_reg(CCR1, read_cyrix_reg(CCR1) | CCR1_NO_LOCK);
367 write_cyrix_reg(CCR1, read_cyrix_reg(CCR1) & ~CCR1_NO_LOCK);
370 /* Initialize CCR2. */
372 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) | CCR2_SUSP_HLT);
374 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) & ~CCR2_SUSP_HLT);
377 ccr3 = read_cyrix_reg(CCR3);
378 write_cyrix_reg(CCR3, CCR3_MAPEN0);
380 /* Initialize CCR4. */
381 ccr4 = read_cyrix_reg(CCR4);
383 ccr4 &= ~CCR4_IOMASK;
385 write_cyrix_reg(CCR4, ccr4 | (CPU_IORT & CCR4_IOMASK));
387 write_cyrix_reg(CCR4, ccr4 | 7);
390 /* Initialize CCR5. */
392 write_cyrix_reg(CCR5, read_cyrix_reg(CCR5) | CCR5_WT_ALLOC);
396 write_cyrix_reg(CCR3, ccr3);
398 /* Unlock NW bit in CR0. */
399 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) & ~CCR2_LOCK_NW);
402 * Earlier revision of the 6x86 CPU could crash the system if
403 * L1 cache is in write-back mode.
405 if ((cyrix_did & 0xff00) > 0x1600)
406 load_cr0(rcr0() & ~(CR0_CD | CR0_NW)); /* CD = 0 and NW = 0 */
408 /* Revision 2.6 and lower. */
409 #ifdef CYRIX_CACHE_REALLY_WORKS
410 load_cr0(rcr0() & ~(CR0_CD | CR0_NW)); /* CD = 0 and NW = 0 */
412 load_cr0((rcr0() & ~CR0_CD) | CR0_NW); /* CD = 0 and NW = 1 */
416 /* Lock NW bit in CR0. */
417 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) | CCR2_LOCK_NW);
419 write_eflags(eflags);
421 #endif /* I486_CPU */
425 * Cyrix 6x86MX (code-named M2)
427 * XXX - What should I do here? Please let me know.
435 eflags = read_eflags();
438 load_cr0(rcr0() | CR0_CD | CR0_NW);
441 /* Initialize CCR0. */
442 write_cyrix_reg(CCR0, read_cyrix_reg(CCR0) | CCR0_NC1);
444 /* Initialize CCR1. */
445 #ifdef CPU_CYRIX_NO_LOCK
446 write_cyrix_reg(CCR1, read_cyrix_reg(CCR1) | CCR1_NO_LOCK);
448 write_cyrix_reg(CCR1, read_cyrix_reg(CCR1) & ~CCR1_NO_LOCK);
451 /* Initialize CCR2. */
453 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) | CCR2_SUSP_HLT);
455 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) & ~CCR2_SUSP_HLT);
458 ccr3 = read_cyrix_reg(CCR3);
459 write_cyrix_reg(CCR3, CCR3_MAPEN0);
461 /* Initialize CCR4. */
462 ccr4 = read_cyrix_reg(CCR4);
463 ccr4 &= ~CCR4_IOMASK;
465 write_cyrix_reg(CCR4, ccr4 | (CPU_IORT & CCR4_IOMASK));
467 write_cyrix_reg(CCR4, ccr4 | 7);
470 /* Initialize CCR5. */
472 write_cyrix_reg(CCR5, read_cyrix_reg(CCR5) | CCR5_WT_ALLOC);
476 write_cyrix_reg(CCR3, ccr3);
478 /* Unlock NW bit in CR0. */
479 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) & ~CCR2_LOCK_NW);
481 load_cr0(rcr0() & ~(CR0_CD | CR0_NW)); /* CD = 0 and NW = 0 */
483 /* Lock NW bit in CR0. */
484 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) | CCR2_LOCK_NW);
486 write_eflags(eflags);
495 * Local APIC should be disabled if it is not going to be used.
497 apicbase = rdmsr(MSR_APICBASE);
498 apicbase &= ~APICBASE_ENABLED;
499 wrmsr(MSR_APICBASE, apicbase);
503 * Initialize BBL_CR_CTL3 (Control register 3: used to configure the
509 #ifdef CPU_PPRO2CELERON
511 u_int64_t bbl_cr_ctl3;
513 eflags = read_eflags();
516 load_cr0(rcr0() | CR0_CD | CR0_NW);
519 bbl_cr_ctl3 = rdmsr(MSR_BBL_CR_CTL3);
521 /* If the L2 cache is configured, do nothing. */
522 if (!(bbl_cr_ctl3 & 1)) {
523 bbl_cr_ctl3 = 0x134052bLL;
525 /* Set L2 Cache Latency (Default: 5). */
526 #ifdef CPU_CELERON_L2_LATENCY
527 #if CPU_L2_LATENCY > 15
528 #error invalid CPU_L2_LATENCY.
530 bbl_cr_ctl3 |= CPU_L2_LATENCY << 1;
532 bbl_cr_ctl3 |= 5 << 1;
534 wrmsr(MSR_BBL_CR_CTL3, bbl_cr_ctl3);
537 load_cr0(rcr0() & ~(CR0_CD | CR0_NW));
538 write_eflags(eflags);
539 #endif /* CPU_PPRO2CELERON */
543 * Initialize special VIA C3/C7 features
551 do_cpuid(0xc0000000, regs);
553 if (val >= 0xc0000001) {
554 do_cpuid(0xc0000001, regs);
559 /* Enable RNG if present and disabled */
560 if (val & VIA_CPUID_HAS_RNG) {
561 if (!(val & VIA_CPUID_DO_RNG)) {
562 msreg = rdmsr(0x110B);
564 wrmsr(0x110B, msreg);
566 via_feature_rng = VIA_HAS_RNG;
568 /* Enable AES engine if present and disabled */
569 if (val & VIA_CPUID_HAS_ACE) {
570 if (!(val & VIA_CPUID_DO_ACE)) {
571 msreg = rdmsr(0x1107);
572 msreg |= (0x01 << 28);
573 wrmsr(0x1107, msreg);
575 via_feature_xcrypt |= VIA_HAS_AES;
577 /* Enable ACE2 engine if present and disabled */
578 if (val & VIA_CPUID_HAS_ACE2) {
579 if (!(val & VIA_CPUID_DO_ACE2)) {
580 msreg = rdmsr(0x1107);
581 msreg |= (0x01 << 28);
582 wrmsr(0x1107, msreg);
584 via_feature_xcrypt |= VIA_HAS_AESCTR;
586 /* Enable SHA engine if present and disabled */
587 if (val & VIA_CPUID_HAS_PHE) {
588 if (!(val & VIA_CPUID_DO_PHE)) {
589 msreg = rdmsr(0x1107);
590 msreg |= (0x01 << 28/**/);
591 wrmsr(0x1107, msreg);
593 via_feature_xcrypt |= VIA_HAS_SHA;
595 /* Enable MM engine if present and disabled */
596 if (val & VIA_CPUID_HAS_PMM) {
597 if (!(val & VIA_CPUID_DO_PMM)) {
598 msreg = rdmsr(0x1107);
599 msreg |= (0x01 << 28/**/);
600 wrmsr(0x1107, msreg);
602 via_feature_xcrypt |= VIA_HAS_MM;
606 #endif /* I686_CPU */
609 * Initialize CR4 (Control register 4) to enable SSE instructions.
614 #if defined(CPU_ENABLE_SSE)
615 if ((cpu_feature & CPUID_XMM) && (cpu_feature & CPUID_FXSR)) {
616 load_cr4(rcr4() | CR4_FXSR | CR4_XMM);
617 cpu_fxsr = hw_instruction_sse = 1;
629 init_bluelightning();
640 #ifdef CPU_I486_ON_386
648 #endif /* I486_CPU */
654 if (cpu_vendor_id == CPU_VENDOR_INTEL) {
655 switch (cpu_id & 0xff0) {
663 } else if (cpu_vendor_id == CPU_VENDOR_AMD) {
664 #if defined(I686_CPU) && defined(CPU_ATHLON_SSE_HACK)
666 * Sometimes the BIOS doesn't enable SSE instructions.
667 * According to AMD document 20734, the mobile
668 * Duron, the (mobile) Athlon 4 and the Athlon MP
669 * support SSE. These correspond to cpu_id 0x66X
672 if ((cpu_feature & CPUID_XMM) == 0 &&
673 ((cpu_id & ~0xf) == 0x660 ||
674 (cpu_id & ~0xf) == 0x670 ||
675 (cpu_id & ~0xf) == 0x680)) {
677 wrmsr(0xC0010015, rdmsr(0xC0010015) & ~0x08000);
679 cpu_feature = regs[3];
682 } else if (cpu_vendor_id == CPU_VENDOR_CENTAUR) {
683 switch (cpu_id & 0xff0) {
685 if ((cpu_id & 0xf) < 3)
698 if ((amd_feature & AMDID_NX) != 0) {
701 msr = rdmsr(MSR_EFER) | EFER_NXE;
702 wrmsr(MSR_EFER, msr);
714 * CPUID with %eax = 1, %ebx returns
715 * Bits 15-8: CLFLUSH line size
716 * (Value * 8 = cache line size in bytes)
718 if ((cpu_feature & CPUID_CLFSH) != 0)
719 cpu_clflush_line_size = ((cpu_procinfo >> 8) & 0xff) * 8;
721 * XXXKIB: (temporary) hack to work around traps generated when
722 * CLFLUSHing APIC registers window.
724 if (cpu_vendor_id == CPU_VENDOR_INTEL && !(cpu_feature & CPUID_SS))
725 cpu_feature &= ~CPUID_CLFSH;
727 #if defined(PC98) && !defined(CPU_UPGRADE_HW_CACHE)
729 * OS should flush L1 cache by itself because no PC-98 supports
730 * non-Intel CPUs. Use wbinvd instruction before DMA transfer
731 * when need_pre_dma_flush = 1, use invd instruction after DMA
732 * transfer when need_post_dma_flush = 1. If your CPU upgrade
733 * product supports hardware cache control, you can add the
734 * CPU_UPGRADE_HW_CACHE option in your kernel configuration file.
735 * This option eliminates unneeded cache flush instruction(s).
737 if (cpu_vendor_id == CPU_VENDOR_CYRIX) {
741 need_post_dma_flush = 1;
744 need_pre_dma_flush = 1;
747 need_pre_dma_flush = 1;
748 #ifdef CPU_I486_ON_386
749 need_post_dma_flush = 1;
756 } else if (cpu_vendor_id == CPU_VENDOR_AMD) {
757 switch (cpu_id & 0xFF0) {
758 case 0x470: /* Enhanced Am486DX2 WB */
759 case 0x490: /* Enhanced Am486DX4 WB */
760 case 0x4F0: /* Am5x86 WB */
761 need_pre_dma_flush = 1;
764 } else if (cpu_vendor_id == CPU_VENDOR_IBM) {
765 need_post_dma_flush = 1;
767 #ifdef CPU_I486_ON_386
768 need_pre_dma_flush = 1;
771 #endif /* PC98 && !CPU_UPGRADE_HW_CACHE */
774 #if defined(I586_CPU) && defined(CPU_WT_ALLOC)
776 * Enable write allocate feature of AMD processors.
777 * Following two functions require the Maxmem variable being set.
780 enable_K5_wt_alloc(void)
786 * Write allocate is supported only on models 1, 2, and 3, with
787 * a stepping of 4 or greater.
789 if (((cpu_id & 0xf0) > 0) && ((cpu_id & 0x0f) > 3)) {
790 savecrit = intr_disable();
791 msr = rdmsr(0x83); /* HWCR */
792 wrmsr(0x83, msr & !(0x10));
795 * We have to tell the chip where the top of memory is,
796 * since video cards could have frame bufferes there,
797 * memory-mapped I/O could be there, etc.
803 msr |= AMD_WT_ALLOC_TME | AMD_WT_ALLOC_FRE;
805 if (!(inb(0x43b) & 4)) {
806 wrmsr(0x86, 0x0ff00f0);
807 msr |= AMD_WT_ALLOC_PRE;
811 * There is no way to know wheter 15-16M hole exists or not.
812 * Therefore, we disable write allocate for this range.
814 wrmsr(0x86, 0x0ff00f0);
815 msr |= AMD_WT_ALLOC_PRE;
820 wrmsr(0x83, msr|0x10); /* enable write allocate */
821 intr_restore(savecrit);
826 enable_K6_wt_alloc(void)
832 eflags = read_eflags();
836 #ifdef CPU_DISABLE_CACHE
838 * Certain K6-2 box becomes unstable when write allocation is
842 * The AMD-K6 processer provides the 64-bit Test Register 12(TR12),
843 * but only the Cache Inhibit(CI) (bit 3 of TR12) is suppported.
844 * All other bits in TR12 have no effect on the processer's operation.
845 * The I/O Trap Restart function (bit 9 of TR12) is always enabled
848 wrmsr(0x0000000e, (u_int64_t)0x0008);
850 /* Don't assume that memory size is aligned with 4M. */
852 size = ((Maxmem >> 8) + 3) >> 2;
856 /* Limit is 508M bytes. */
859 whcr = (rdmsr(0xc0000082) & ~(0x7fLL << 1)) | (size << 1);
861 #if defined(PC98) || defined(NO_MEMORY_HOLE)
862 if (whcr & (0x7fLL << 1)) {
865 * If bit 2 of port 0x43b is 0, disable wrte allocate for the
868 if (!(inb(0x43b) & 4))
876 * There is no way to know wheter 15-16M hole exists or not.
877 * Therefore, we disable write allocate for this range.
881 wrmsr(0x0c0000082, whcr);
883 write_eflags(eflags);
887 enable_K6_2_wt_alloc(void)
893 eflags = read_eflags();
897 #ifdef CPU_DISABLE_CACHE
899 * Certain K6-2 box becomes unstable when write allocation is
903 * The AMD-K6 processer provides the 64-bit Test Register 12(TR12),
904 * but only the Cache Inhibit(CI) (bit 3 of TR12) is suppported.
905 * All other bits in TR12 have no effect on the processer's operation.
906 * The I/O Trap Restart function (bit 9 of TR12) is always enabled
909 wrmsr(0x0000000e, (u_int64_t)0x0008);
911 /* Don't assume that memory size is aligned with 4M. */
913 size = ((Maxmem >> 8) + 3) >> 2;
917 /* Limit is 4092M bytes. */
920 whcr = (rdmsr(0xc0000082) & ~(0x3ffLL << 22)) | (size << 22);
922 #if defined(PC98) || defined(NO_MEMORY_HOLE)
923 if (whcr & (0x3ffLL << 22)) {
926 * If bit 2 of port 0x43b is 0, disable wrte allocate for the
929 if (!(inb(0x43b) & 4))
930 whcr &= ~(1LL << 16);
937 * There is no way to know wheter 15-16M hole exists or not.
938 * Therefore, we disable write allocate for this range.
940 whcr &= ~(1LL << 16);
942 wrmsr(0x0c0000082, whcr);
944 write_eflags(eflags);
946 #endif /* I585_CPU && CPU_WT_ALLOC */
952 DB_SHOW_COMMAND(cyrixreg, cyrixreg)
956 u_char ccr1, ccr2, ccr3;
957 u_char ccr0 = 0, ccr4 = 0, ccr5 = 0, pcr0 = 0;
960 if (cpu_vendor_id == CPU_VENDOR_CYRIX) {
961 eflags = read_eflags();
965 if ((cpu != CPU_M1SC) && (cpu != CPU_CY486DX)) {
966 ccr0 = read_cyrix_reg(CCR0);
968 ccr1 = read_cyrix_reg(CCR1);
969 ccr2 = read_cyrix_reg(CCR2);
970 ccr3 = read_cyrix_reg(CCR3);
971 if ((cpu == CPU_M1SC) || (cpu == CPU_M1) || (cpu == CPU_M2)) {
972 write_cyrix_reg(CCR3, CCR3_MAPEN0);
973 ccr4 = read_cyrix_reg(CCR4);
974 if ((cpu == CPU_M1) || (cpu == CPU_M2))
975 ccr5 = read_cyrix_reg(CCR5);
977 pcr0 = read_cyrix_reg(PCR0);
978 write_cyrix_reg(CCR3, ccr3); /* Restore CCR3. */
980 write_eflags(eflags);
982 if ((cpu != CPU_M1SC) && (cpu != CPU_CY486DX))
983 printf("CCR0=%x, ", (u_int)ccr0);
985 printf("CCR1=%x, CCR2=%x, CCR3=%x",
986 (u_int)ccr1, (u_int)ccr2, (u_int)ccr3);
987 if ((cpu == CPU_M1SC) || (cpu == CPU_M1) || (cpu == CPU_M2)) {
988 printf(", CCR4=%x, ", (u_int)ccr4);
990 printf("PCR0=%x\n", pcr0);
992 printf("CCR5=%x\n", ccr5);
995 printf("CR0=%x\n", cr0);