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
52 static void init_5x86(void);
53 static void init_bluelightning(void);
54 static void init_486dlc(void);
55 static void init_cy486dx(void);
56 #ifdef CPU_I486_ON_386
57 static void init_i486_on_386(void);
59 static void init_6x86(void);
62 #if defined(I586_CPU) && defined(CPU_WT_ALLOC)
63 static void enable_K5_wt_alloc(void);
64 static void enable_K6_wt_alloc(void);
65 static void enable_K6_2_wt_alloc(void);
69 static void init_6x86MX(void);
70 static void init_ppro(void);
71 static void init_mendocino(void);
74 static int hw_instruction_sse;
75 SYSCTL_INT(_hw, OID_AUTO, instruction_sse, CTLFLAG_RD,
76 &hw_instruction_sse, 0, "SIMD/MMX2 instructions available in CPU");
78 * -1: automatic (default)
79 * 0: keep enable CLFLUSH
80 * 1: force disable CLFLUSH
82 static int hw_clflush_disable = -1;
84 int cpu; /* Are we 386, 386sx, 486, etc? */
85 u_int cpu_feature; /* Feature flags */
86 u_int cpu_feature2; /* Feature flags */
87 u_int amd_feature; /* AMD feature flags */
88 u_int amd_feature2; /* AMD feature flags */
89 u_int amd_pminfo; /* AMD advanced power management info */
90 u_int via_feature_rng; /* VIA RNG features */
91 u_int via_feature_xcrypt; /* VIA ACE features */
92 u_int cpu_high; /* Highest arg to CPUID */
93 u_int cpu_exthigh; /* Highest arg to extended CPUID */
94 u_int cpu_id; /* Stepping ID */
95 u_int cpu_procinfo; /* HyperThreading Info / Brand Index / CLFUSH */
96 u_int cpu_procinfo2; /* Multicore info */
97 char cpu_vendor[20]; /* CPU Origin code */
98 u_int cpu_vendor_id; /* CPU vendor ID */
100 u_int cpu_fxsr; /* SSE enabled */
101 u_int cpu_mxcsr_mask; /* Valid bits in mxcsr */
103 u_int cpu_clflush_line_size = 32;
104 u_int cpu_stdext_feature;
105 u_int cpu_max_ext_state_size;
106 u_int cpu_mon_mwait_flags; /* MONITOR/MWAIT flags (CPUID.05H.ECX) */
107 u_int cpu_mon_min_size; /* MONITOR minimum range size, bytes */
108 u_int cpu_mon_max_size; /* MONITOR minimum range size, bytes */
109 u_int cyrix_did; /* Device ID of Cyrix CPU */
111 SYSCTL_UINT(_hw, OID_AUTO, via_feature_rng, CTLFLAG_RD,
112 &via_feature_rng, 0, "VIA RNG feature available in CPU");
113 SYSCTL_UINT(_hw, OID_AUTO, via_feature_xcrypt, CTLFLAG_RD,
114 &via_feature_xcrypt, 0, "VIA xcrypt feature available in CPU");
121 init_bluelightning(void)
125 #if defined(PC98) && !defined(CPU_UPGRADE_HW_CACHE)
126 need_post_dma_flush = 1;
129 saveintr = intr_disable();
131 load_cr0(rcr0() | CR0_CD | CR0_NW);
134 #ifdef CPU_BLUELIGHTNING_FPU_OP_CACHE
135 wrmsr(0x1000, 0x9c92LL); /* FP operand can be cacheable on Cyrix FPU */
137 wrmsr(0x1000, 0x1c92LL); /* Intel FPU */
139 /* Enables 13MB and 0-640KB cache. */
140 wrmsr(0x1001, (0xd0LL << 32) | 0x3ff);
141 #ifdef CPU_BLUELIGHTNING_3X
142 wrmsr(0x1002, 0x04000000LL); /* Enables triple-clock mode. */
144 wrmsr(0x1002, 0x03000000LL); /* Enables double-clock mode. */
147 /* Enable caching in CR0. */
148 load_cr0(rcr0() & ~(CR0_CD | CR0_NW)); /* CD = 0 and NW = 0 */
150 intr_restore(saveintr);
154 * Cyrix 486SLC/DLC/SR/DR series
162 saveintr = intr_disable();
165 ccr0 = read_cyrix_reg(CCR0);
166 #ifndef CYRIX_CACHE_WORKS
167 ccr0 |= CCR0_NC1 | CCR0_BARB;
168 write_cyrix_reg(CCR0, ccr0);
172 #ifndef CYRIX_CACHE_REALLY_WORKS
173 ccr0 |= CCR0_NC1 | CCR0_BARB;
177 #ifdef CPU_DIRECT_MAPPED_CACHE
178 ccr0 |= CCR0_CO; /* Direct mapped mode. */
180 write_cyrix_reg(CCR0, ccr0);
182 /* Clear non-cacheable region. */
183 write_cyrix_reg(NCR1+2, NCR_SIZE_0K);
184 write_cyrix_reg(NCR2+2, NCR_SIZE_0K);
185 write_cyrix_reg(NCR3+2, NCR_SIZE_0K);
186 write_cyrix_reg(NCR4+2, NCR_SIZE_0K);
188 write_cyrix_reg(0, 0); /* dummy write */
190 /* Enable caching in CR0. */
191 load_cr0(rcr0() & ~(CR0_CD | CR0_NW)); /* CD = 0 and NW = 0 */
193 #endif /* !CYRIX_CACHE_WORKS */
194 intr_restore(saveintr);
199 * Cyrix 486S/DX series
207 saveintr = intr_disable();
210 ccr2 = read_cyrix_reg(CCR2);
212 ccr2 |= CCR2_SUSP_HLT;
216 /* Enables WB cache interface pin and Lock NW bit in CR0. */
217 ccr2 |= CCR2_WB | CCR2_LOCK_NW;
218 /* Unlock NW bit in CR0. */
219 write_cyrix_reg(CCR2, ccr2 & ~CCR2_LOCK_NW);
220 load_cr0((rcr0() & ~CR0_CD) | CR0_NW); /* CD = 0, NW = 1 */
223 write_cyrix_reg(CCR2, ccr2);
224 intr_restore(saveintr);
235 u_char ccr2, ccr3, ccr4, pcr0;
237 saveintr = intr_disable();
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 intr_restore(saveintr);
326 #ifdef CPU_I486_ON_386
328 * There are i486 based upgrade products for i386 machines.
329 * In this case, BIOS doesn't enable CPU cache.
332 init_i486_on_386(void)
336 #if defined(PC98) && !defined(CPU_UPGRADE_HW_CACHE)
337 need_post_dma_flush = 1;
340 saveintr = intr_disable();
342 load_cr0(rcr0() & ~(CR0_CD | CR0_NW)); /* CD = 0, NW = 0 */
344 intr_restore(saveintr);
351 * XXX - What should I do here? Please let me know.
359 saveintr = intr_disable();
361 load_cr0(rcr0() | CR0_CD | CR0_NW);
364 /* Initialize CCR0. */
365 write_cyrix_reg(CCR0, read_cyrix_reg(CCR0) | CCR0_NC1);
367 /* Initialize CCR1. */
368 #ifdef CPU_CYRIX_NO_LOCK
369 write_cyrix_reg(CCR1, read_cyrix_reg(CCR1) | CCR1_NO_LOCK);
371 write_cyrix_reg(CCR1, read_cyrix_reg(CCR1) & ~CCR1_NO_LOCK);
374 /* Initialize CCR2. */
376 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) | CCR2_SUSP_HLT);
378 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) & ~CCR2_SUSP_HLT);
381 ccr3 = read_cyrix_reg(CCR3);
382 write_cyrix_reg(CCR3, CCR3_MAPEN0);
384 /* Initialize CCR4. */
385 ccr4 = read_cyrix_reg(CCR4);
387 ccr4 &= ~CCR4_IOMASK;
389 write_cyrix_reg(CCR4, ccr4 | (CPU_IORT & CCR4_IOMASK));
391 write_cyrix_reg(CCR4, ccr4 | 7);
394 /* Initialize CCR5. */
396 write_cyrix_reg(CCR5, read_cyrix_reg(CCR5) | CCR5_WT_ALLOC);
400 write_cyrix_reg(CCR3, ccr3);
402 /* Unlock NW bit in CR0. */
403 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) & ~CCR2_LOCK_NW);
406 * Earlier revision of the 6x86 CPU could crash the system if
407 * L1 cache is in write-back mode.
409 if ((cyrix_did & 0xff00) > 0x1600)
410 load_cr0(rcr0() & ~(CR0_CD | CR0_NW)); /* CD = 0 and NW = 0 */
412 /* Revision 2.6 and lower. */
413 #ifdef CYRIX_CACHE_REALLY_WORKS
414 load_cr0(rcr0() & ~(CR0_CD | CR0_NW)); /* CD = 0 and NW = 0 */
416 load_cr0((rcr0() & ~CR0_CD) | CR0_NW); /* CD = 0 and NW = 1 */
420 /* Lock NW bit in CR0. */
421 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) | CCR2_LOCK_NW);
423 intr_restore(saveintr);
425 #endif /* I486_CPU */
436 * The CMPXCHG8B instruction is always available but hidden.
438 cpu_feature |= CPUID_CX8;
442 * IDT WinChip C6/2/2A/2B/3
444 * http://www.centtech.com/winchip_bios_writers_guide_v4_0.pdf
455 * Set ECX8, DSMC, DTLOCK/EDCTLB, EMMX, and ERETSTK and clear DPDC.
457 fcr |= (1 << 1) | (1 << 7) | (1 << 8) | (1 << 9) | (1 << 16);
458 fcr &= ~(1ULL << 11);
461 * Additionally, set EBRPRED, E2MMX and EAMD3D for WinChip 2 and 3.
463 if (CPUID_TO_MODEL(cpu_id) >= 8)
464 fcr |= (1 << 12) | (1 << 19) | (1 << 20);
468 cpu_feature = regs[3];
474 * Cyrix 6x86MX (code-named M2)
476 * XXX - What should I do here? Please let me know.
484 saveintr = intr_disable();
486 load_cr0(rcr0() | CR0_CD | CR0_NW);
489 /* Initialize CCR0. */
490 write_cyrix_reg(CCR0, read_cyrix_reg(CCR0) | CCR0_NC1);
492 /* Initialize CCR1. */
493 #ifdef CPU_CYRIX_NO_LOCK
494 write_cyrix_reg(CCR1, read_cyrix_reg(CCR1) | CCR1_NO_LOCK);
496 write_cyrix_reg(CCR1, read_cyrix_reg(CCR1) & ~CCR1_NO_LOCK);
499 /* Initialize CCR2. */
501 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) | CCR2_SUSP_HLT);
503 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) & ~CCR2_SUSP_HLT);
506 ccr3 = read_cyrix_reg(CCR3);
507 write_cyrix_reg(CCR3, CCR3_MAPEN0);
509 /* Initialize CCR4. */
510 ccr4 = read_cyrix_reg(CCR4);
511 ccr4 &= ~CCR4_IOMASK;
513 write_cyrix_reg(CCR4, ccr4 | (CPU_IORT & CCR4_IOMASK));
515 write_cyrix_reg(CCR4, ccr4 | 7);
518 /* Initialize CCR5. */
520 write_cyrix_reg(CCR5, read_cyrix_reg(CCR5) | CCR5_WT_ALLOC);
524 write_cyrix_reg(CCR3, ccr3);
526 /* Unlock NW bit in CR0. */
527 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) & ~CCR2_LOCK_NW);
529 load_cr0(rcr0() & ~(CR0_CD | CR0_NW)); /* CD = 0 and NW = 0 */
531 /* Lock NW bit in CR0. */
532 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) | CCR2_LOCK_NW);
534 intr_restore(saveintr);
537 static int ppro_apic_used = -1;
545 * Local APIC should be disabled if it is not going to be used.
547 if (ppro_apic_used != 1) {
548 apicbase = rdmsr(MSR_APICBASE);
549 apicbase &= ~APICBASE_ENABLED;
550 wrmsr(MSR_APICBASE, apicbase);
556 * If the local APIC is going to be used after being disabled above,
557 * re-enable it and don't disable it in the future.
560 ppro_reenable_apic(void)
564 if (ppro_apic_used == 0) {
565 apicbase = rdmsr(MSR_APICBASE);
566 apicbase |= APICBASE_ENABLED;
567 wrmsr(MSR_APICBASE, apicbase);
573 * Initialize BBL_CR_CTL3 (Control register 3: used to configure the
579 #ifdef CPU_PPRO2CELERON
581 u_int64_t bbl_cr_ctl3;
583 saveintr = intr_disable();
585 load_cr0(rcr0() | CR0_CD | CR0_NW);
588 bbl_cr_ctl3 = rdmsr(MSR_BBL_CR_CTL3);
590 /* If the L2 cache is configured, do nothing. */
591 if (!(bbl_cr_ctl3 & 1)) {
592 bbl_cr_ctl3 = 0x134052bLL;
594 /* Set L2 Cache Latency (Default: 5). */
595 #ifdef CPU_CELERON_L2_LATENCY
596 #if CPU_L2_LATENCY > 15
597 #error invalid CPU_L2_LATENCY.
599 bbl_cr_ctl3 |= CPU_L2_LATENCY << 1;
601 bbl_cr_ctl3 |= 5 << 1;
603 wrmsr(MSR_BBL_CR_CTL3, bbl_cr_ctl3);
606 load_cr0(rcr0() & ~(CR0_CD | CR0_NW));
607 intr_restore(saveintr);
608 #endif /* CPU_PPRO2CELERON */
612 * Initialize special VIA features
621 * Explicitly enable CX8 and PGE on C3.
623 * http://www.via.com.tw/download/mainboards/6/13/VIA_C3_EBGA%20datasheet110.pdf
625 if (CPUID_TO_MODEL(cpu_id) <= 9)
626 fcr = (1 << 1) | (1 << 7);
631 * Check extended CPUID for PadLock features.
633 * http://www.via.com.tw/en/downloads/whitepapers/initiatives/padlock/programming_guide.pdf
635 do_cpuid(0xc0000000, regs);
636 if (regs[0] >= 0xc0000001) {
637 do_cpuid(0xc0000001, regs);
642 /* Enable RNG if present. */
643 if ((val & VIA_CPUID_HAS_RNG) != 0) {
644 via_feature_rng = VIA_HAS_RNG;
645 wrmsr(0x110B, rdmsr(0x110B) | VIA_CPUID_DO_RNG);
648 /* Enable PadLock if present. */
649 if ((val & VIA_CPUID_HAS_ACE) != 0)
650 via_feature_xcrypt |= VIA_HAS_AES;
651 if ((val & VIA_CPUID_HAS_ACE2) != 0)
652 via_feature_xcrypt |= VIA_HAS_AESCTR;
653 if ((val & VIA_CPUID_HAS_PHE) != 0)
654 via_feature_xcrypt |= VIA_HAS_SHA;
655 if ((val & VIA_CPUID_HAS_PMM) != 0)
656 via_feature_xcrypt |= VIA_HAS_MM;
657 if (via_feature_xcrypt != 0)
660 wrmsr(0x1107, rdmsr(0x1107) | fcr);
663 #endif /* I686_CPU */
665 #if defined(I586_CPU) || defined(I686_CPU)
671 /* Expose all hidden features. */
672 wrmsr(0x80860004, rdmsr(0x80860004) | ~0UL);
674 cpu_feature = regs[3];
678 extern int elf32_nxstack;
687 init_bluelightning();
698 #ifdef CPU_I486_ON_386
706 #endif /* I486_CPU */
709 switch (cpu_vendor_id) {
712 if (((cpu_id & 0x0f0) > 0) &&
713 ((cpu_id & 0x0f0) < 0x60) &&
714 ((cpu_id & 0x00f) > 3))
715 enable_K5_wt_alloc();
716 else if (((cpu_id & 0x0f0) > 0x80) ||
717 (((cpu_id & 0x0f0) == 0x80) &&
718 (cpu_id & 0x00f) > 0x07))
719 enable_K6_2_wt_alloc();
720 else if ((cpu_id & 0x0f0) > 0x50)
721 enable_K6_wt_alloc();
723 if ((cpu_id & 0xf0) == 0xa0)
725 * Make sure the TSC runs through
726 * suspension, otherwise we can't use
729 wrmsr(0x1900, rdmsr(0x1900) | 0x20ULL);
731 case CPU_VENDOR_CENTAUR:
734 case CPU_VENDOR_TRANSMETA:
737 case CPU_VENDOR_RISE:
748 switch (cpu_vendor_id) {
749 case CPU_VENDOR_INTEL:
750 switch (cpu_id & 0xff0) {
759 #ifdef CPU_ATHLON_SSE_HACK
762 * Sometimes the BIOS doesn't enable SSE instructions.
763 * According to AMD document 20734, the mobile
764 * Duron, the (mobile) Athlon 4 and the Athlon MP
765 * support SSE. These correspond to cpu_id 0x66X
768 if ((cpu_feature & CPUID_XMM) == 0 &&
769 ((cpu_id & ~0xf) == 0x660 ||
770 (cpu_id & ~0xf) == 0x670 ||
771 (cpu_id & ~0xf) == 0x680)) {
773 wrmsr(MSR_HWCR, rdmsr(MSR_HWCR) & ~0x08000);
775 cpu_feature = regs[3];
779 case CPU_VENDOR_CENTAUR:
782 case CPU_VENDOR_TRANSMETA:
787 if ((amd_feature & AMDID_NX) != 0) {
790 msr = rdmsr(MSR_EFER) | EFER_NXE;
791 wrmsr(MSR_EFER, msr);
801 #if defined(CPU_ENABLE_SSE)
802 if ((cpu_feature & CPUID_XMM) && (cpu_feature & CPUID_FXSR)) {
803 load_cr4(rcr4() | CR4_FXSR | CR4_XMM);
804 cpu_fxsr = hw_instruction_sse = 1;
810 initializecpucache(void)
814 * CPUID with %eax = 1, %ebx returns
815 * Bits 15-8: CLFLUSH line size
816 * (Value * 8 = cache line size in bytes)
818 if ((cpu_feature & CPUID_CLFSH) != 0)
819 cpu_clflush_line_size = ((cpu_procinfo >> 8) & 0xff) * 8;
821 * XXXKIB: (temporary) hack to work around traps generated
822 * when CLFLUSHing APIC register window under virtualization
823 * environments. These environments tend to disable the
824 * CPUID_SS feature even though the native CPU supports it.
826 TUNABLE_INT_FETCH("hw.clflush_disable", &hw_clflush_disable);
827 if (vm_guest != VM_GUEST_NO && hw_clflush_disable == -1)
828 cpu_feature &= ~CPUID_CLFSH;
830 * Allow to disable CLFLUSH feature manually by
831 * hw.clflush_disable tunable.
833 if (hw_clflush_disable == 1)
834 cpu_feature &= ~CPUID_CLFSH;
836 #if defined(PC98) && !defined(CPU_UPGRADE_HW_CACHE)
838 * OS should flush L1 cache by itself because no PC-98 supports
839 * non-Intel CPUs. Use wbinvd instruction before DMA transfer
840 * when need_pre_dma_flush = 1, use invd instruction after DMA
841 * transfer when need_post_dma_flush = 1. If your CPU upgrade
842 * product supports hardware cache control, you can add the
843 * CPU_UPGRADE_HW_CACHE option in your kernel configuration file.
844 * This option eliminates unneeded cache flush instruction(s).
846 if (cpu_vendor_id == CPU_VENDOR_CYRIX) {
850 need_post_dma_flush = 1;
853 need_pre_dma_flush = 1;
856 need_pre_dma_flush = 1;
857 #ifdef CPU_I486_ON_386
858 need_post_dma_flush = 1;
865 } else if (cpu_vendor_id == CPU_VENDOR_AMD) {
866 switch (cpu_id & 0xFF0) {
867 case 0x470: /* Enhanced Am486DX2 WB */
868 case 0x490: /* Enhanced Am486DX4 WB */
869 case 0x4F0: /* Am5x86 WB */
870 need_pre_dma_flush = 1;
873 } else if (cpu_vendor_id == CPU_VENDOR_IBM) {
874 need_post_dma_flush = 1;
876 #ifdef CPU_I486_ON_386
877 need_pre_dma_flush = 1;
880 #endif /* PC98 && !CPU_UPGRADE_HW_CACHE */
883 #if defined(I586_CPU) && defined(CPU_WT_ALLOC)
885 * Enable write allocate feature of AMD processors.
886 * Following two functions require the Maxmem variable being set.
889 enable_K5_wt_alloc(void)
895 * Write allocate is supported only on models 1, 2, and 3, with
896 * a stepping of 4 or greater.
898 if (((cpu_id & 0xf0) > 0) && ((cpu_id & 0x0f) > 3)) {
899 saveintr = intr_disable();
900 msr = rdmsr(0x83); /* HWCR */
901 wrmsr(0x83, msr & !(0x10));
904 * We have to tell the chip where the top of memory is,
905 * since video cards could have frame bufferes there,
906 * memory-mapped I/O could be there, etc.
912 msr |= AMD_WT_ALLOC_TME | AMD_WT_ALLOC_FRE;
914 if (!(inb(0x43b) & 4)) {
915 wrmsr(0x86, 0x0ff00f0);
916 msr |= AMD_WT_ALLOC_PRE;
920 * There is no way to know wheter 15-16M hole exists or not.
921 * Therefore, we disable write allocate for this range.
923 wrmsr(0x86, 0x0ff00f0);
924 msr |= AMD_WT_ALLOC_PRE;
929 wrmsr(0x83, msr|0x10); /* enable write allocate */
930 intr_restore(saveintr);
935 enable_K6_wt_alloc(void)
941 saveintr = intr_disable();
944 #ifdef CPU_DISABLE_CACHE
946 * Certain K6-2 box becomes unstable when write allocation is
950 * The AMD-K6 processer provides the 64-bit Test Register 12(TR12),
951 * but only the Cache Inhibit(CI) (bit 3 of TR12) is suppported.
952 * All other bits in TR12 have no effect on the processer's operation.
953 * The I/O Trap Restart function (bit 9 of TR12) is always enabled
956 wrmsr(0x0000000e, (u_int64_t)0x0008);
958 /* Don't assume that memory size is aligned with 4M. */
960 size = ((Maxmem >> 8) + 3) >> 2;
964 /* Limit is 508M bytes. */
967 whcr = (rdmsr(0xc0000082) & ~(0x7fLL << 1)) | (size << 1);
969 #if defined(PC98) || defined(NO_MEMORY_HOLE)
970 if (whcr & (0x7fLL << 1)) {
973 * If bit 2 of port 0x43b is 0, disable wrte allocate for the
976 if (!(inb(0x43b) & 4))
984 * There is no way to know wheter 15-16M hole exists or not.
985 * Therefore, we disable write allocate for this range.
989 wrmsr(0x0c0000082, whcr);
991 intr_restore(saveintr);
995 enable_K6_2_wt_alloc(void)
1001 saveintr = intr_disable();
1004 #ifdef CPU_DISABLE_CACHE
1006 * Certain K6-2 box becomes unstable when write allocation is
1010 * The AMD-K6 processer provides the 64-bit Test Register 12(TR12),
1011 * but only the Cache Inhibit(CI) (bit 3 of TR12) is suppported.
1012 * All other bits in TR12 have no effect on the processer's operation.
1013 * The I/O Trap Restart function (bit 9 of TR12) is always enabled
1016 wrmsr(0x0000000e, (u_int64_t)0x0008);
1018 /* Don't assume that memory size is aligned with 4M. */
1020 size = ((Maxmem >> 8) + 3) >> 2;
1024 /* Limit is 4092M bytes. */
1027 whcr = (rdmsr(0xc0000082) & ~(0x3ffLL << 22)) | (size << 22);
1029 #if defined(PC98) || defined(NO_MEMORY_HOLE)
1030 if (whcr & (0x3ffLL << 22)) {
1033 * If bit 2 of port 0x43b is 0, disable wrte allocate for the
1036 if (!(inb(0x43b) & 4))
1037 whcr &= ~(1LL << 16);
1044 * There is no way to know wheter 15-16M hole exists or not.
1045 * Therefore, we disable write allocate for this range.
1047 whcr &= ~(1LL << 16);
1049 wrmsr(0x0c0000082, whcr);
1051 intr_restore(saveintr);
1053 #endif /* I585_CPU && CPU_WT_ALLOC */
1055 #include "opt_ddb.h"
1057 #include <ddb/ddb.h>
1059 DB_SHOW_COMMAND(cyrixreg, cyrixreg)
1061 register_t saveintr;
1063 u_char ccr1, ccr2, ccr3;
1064 u_char ccr0 = 0, ccr4 = 0, ccr5 = 0, pcr0 = 0;
1067 if (cpu_vendor_id == CPU_VENDOR_CYRIX) {
1068 saveintr = intr_disable();
1071 if ((cpu != CPU_M1SC) && (cpu != CPU_CY486DX)) {
1072 ccr0 = read_cyrix_reg(CCR0);
1074 ccr1 = read_cyrix_reg(CCR1);
1075 ccr2 = read_cyrix_reg(CCR2);
1076 ccr3 = read_cyrix_reg(CCR3);
1077 if ((cpu == CPU_M1SC) || (cpu == CPU_M1) || (cpu == CPU_M2)) {
1078 write_cyrix_reg(CCR3, CCR3_MAPEN0);
1079 ccr4 = read_cyrix_reg(CCR4);
1080 if ((cpu == CPU_M1) || (cpu == CPU_M2))
1081 ccr5 = read_cyrix_reg(CCR5);
1083 pcr0 = read_cyrix_reg(PCR0);
1084 write_cyrix_reg(CCR3, ccr3); /* Restore CCR3. */
1086 intr_restore(saveintr);
1088 if ((cpu != CPU_M1SC) && (cpu != CPU_CY486DX))
1089 printf("CCR0=%x, ", (u_int)ccr0);
1091 printf("CCR1=%x, CCR2=%x, CCR3=%x",
1092 (u_int)ccr1, (u_int)ccr2, (u_int)ccr3);
1093 if ((cpu == CPU_M1SC) || (cpu == CPU_M1) || (cpu == CPU_M2)) {
1094 printf(", CCR4=%x, ", (u_int)ccr4);
1095 if (cpu == CPU_M1SC)
1096 printf("PCR0=%x\n", pcr0);
1098 printf("CCR5=%x\n", ccr5);
1101 printf("CR0=%x\n", cr0);