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 */
110 u_int cpu_maxphyaddr; /* Max phys addr width in bits */
112 SYSCTL_UINT(_hw, OID_AUTO, via_feature_rng, CTLFLAG_RD,
113 &via_feature_rng, 0, "VIA RNG feature available in CPU");
114 SYSCTL_UINT(_hw, OID_AUTO, via_feature_xcrypt, CTLFLAG_RD,
115 &via_feature_xcrypt, 0, "VIA xcrypt feature available in CPU");
122 init_bluelightning(void)
126 #if defined(PC98) && !defined(CPU_UPGRADE_HW_CACHE)
127 need_post_dma_flush = 1;
130 saveintr = intr_disable();
132 load_cr0(rcr0() | CR0_CD | CR0_NW);
135 #ifdef CPU_BLUELIGHTNING_FPU_OP_CACHE
136 wrmsr(0x1000, 0x9c92LL); /* FP operand can be cacheable on Cyrix FPU */
138 wrmsr(0x1000, 0x1c92LL); /* Intel FPU */
140 /* Enables 13MB and 0-640KB cache. */
141 wrmsr(0x1001, (0xd0LL << 32) | 0x3ff);
142 #ifdef CPU_BLUELIGHTNING_3X
143 wrmsr(0x1002, 0x04000000LL); /* Enables triple-clock mode. */
145 wrmsr(0x1002, 0x03000000LL); /* Enables double-clock mode. */
148 /* Enable caching in CR0. */
149 load_cr0(rcr0() & ~(CR0_CD | CR0_NW)); /* CD = 0 and NW = 0 */
151 intr_restore(saveintr);
155 * Cyrix 486SLC/DLC/SR/DR series
163 saveintr = intr_disable();
166 ccr0 = read_cyrix_reg(CCR0);
167 #ifndef CYRIX_CACHE_WORKS
168 ccr0 |= CCR0_NC1 | CCR0_BARB;
169 write_cyrix_reg(CCR0, ccr0);
173 #ifndef CYRIX_CACHE_REALLY_WORKS
174 ccr0 |= CCR0_NC1 | CCR0_BARB;
178 #ifdef CPU_DIRECT_MAPPED_CACHE
179 ccr0 |= CCR0_CO; /* Direct mapped mode. */
181 write_cyrix_reg(CCR0, ccr0);
183 /* Clear non-cacheable region. */
184 write_cyrix_reg(NCR1+2, NCR_SIZE_0K);
185 write_cyrix_reg(NCR2+2, NCR_SIZE_0K);
186 write_cyrix_reg(NCR3+2, NCR_SIZE_0K);
187 write_cyrix_reg(NCR4+2, NCR_SIZE_0K);
189 write_cyrix_reg(0, 0); /* dummy write */
191 /* Enable caching in CR0. */
192 load_cr0(rcr0() & ~(CR0_CD | CR0_NW)); /* CD = 0 and NW = 0 */
194 #endif /* !CYRIX_CACHE_WORKS */
195 intr_restore(saveintr);
200 * Cyrix 486S/DX series
208 saveintr = intr_disable();
211 ccr2 = read_cyrix_reg(CCR2);
213 ccr2 |= CCR2_SUSP_HLT;
217 /* Enables WB cache interface pin and Lock NW bit in CR0. */
218 ccr2 |= CCR2_WB | CCR2_LOCK_NW;
219 /* Unlock NW bit in CR0. */
220 write_cyrix_reg(CCR2, ccr2 & ~CCR2_LOCK_NW);
221 load_cr0((rcr0() & ~CR0_CD) | CR0_NW); /* CD = 0, NW = 1 */
224 write_cyrix_reg(CCR2, ccr2);
225 intr_restore(saveintr);
236 u_char ccr2, ccr3, ccr4, pcr0;
238 saveintr = intr_disable();
240 load_cr0(rcr0() | CR0_CD | CR0_NW);
243 (void)read_cyrix_reg(CCR3); /* dummy */
245 /* Initialize CCR2. */
246 ccr2 = read_cyrix_reg(CCR2);
249 ccr2 |= CCR2_SUSP_HLT;
251 ccr2 &= ~CCR2_SUSP_HLT;
254 write_cyrix_reg(CCR2, ccr2);
256 /* Initialize CCR4. */
257 ccr3 = read_cyrix_reg(CCR3);
258 write_cyrix_reg(CCR3, CCR3_MAPEN0);
260 ccr4 = read_cyrix_reg(CCR4);
263 #ifdef CPU_FASTER_5X86_FPU
264 ccr4 |= CCR4_FASTFPE;
266 ccr4 &= ~CCR4_FASTFPE;
268 ccr4 &= ~CCR4_IOMASK;
269 /********************************************************************
270 * WARNING: The "BIOS Writers Guide" mentions that I/O recovery time
271 * should be 0 for errata fix.
272 ********************************************************************/
274 ccr4 |= CPU_IORT & CCR4_IOMASK;
276 write_cyrix_reg(CCR4, ccr4);
278 /* Initialize PCR0. */
279 /****************************************************************
280 * WARNING: RSTK_EN and LOOP_EN could make your system unstable.
281 * BTB_EN might make your system unstable.
282 ****************************************************************/
283 pcr0 = read_cyrix_reg(PCR0);
300 /****************************************************************
301 * WARNING: if you use a memory mapped I/O device, don't use
302 * DISABLE_5X86_LSSER option, which may reorder memory mapped
304 * IF YOUR MOTHERBOARD HAS PCI BUS, DON'T DISABLE LSSER.
305 ****************************************************************/
306 #ifdef CPU_DISABLE_5X86_LSSER
311 write_cyrix_reg(PCR0, pcr0);
314 write_cyrix_reg(CCR3, ccr3);
316 (void)read_cyrix_reg(0x80); /* dummy */
318 /* Unlock NW bit in CR0. */
319 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) & ~CCR2_LOCK_NW);
320 load_cr0((rcr0() & ~CR0_CD) | CR0_NW); /* CD = 0, NW = 1 */
321 /* Lock NW bit in CR0. */
322 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) | CCR2_LOCK_NW);
324 intr_restore(saveintr);
327 #ifdef CPU_I486_ON_386
329 * There are i486 based upgrade products for i386 machines.
330 * In this case, BIOS doesn't enable CPU cache.
333 init_i486_on_386(void)
337 #if defined(PC98) && !defined(CPU_UPGRADE_HW_CACHE)
338 need_post_dma_flush = 1;
341 saveintr = intr_disable();
343 load_cr0(rcr0() & ~(CR0_CD | CR0_NW)); /* CD = 0, NW = 0 */
345 intr_restore(saveintr);
352 * XXX - What should I do here? Please let me know.
360 saveintr = intr_disable();
362 load_cr0(rcr0() | CR0_CD | CR0_NW);
365 /* Initialize CCR0. */
366 write_cyrix_reg(CCR0, read_cyrix_reg(CCR0) | CCR0_NC1);
368 /* Initialize CCR1. */
369 #ifdef CPU_CYRIX_NO_LOCK
370 write_cyrix_reg(CCR1, read_cyrix_reg(CCR1) | CCR1_NO_LOCK);
372 write_cyrix_reg(CCR1, read_cyrix_reg(CCR1) & ~CCR1_NO_LOCK);
375 /* Initialize CCR2. */
377 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) | CCR2_SUSP_HLT);
379 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) & ~CCR2_SUSP_HLT);
382 ccr3 = read_cyrix_reg(CCR3);
383 write_cyrix_reg(CCR3, CCR3_MAPEN0);
385 /* Initialize CCR4. */
386 ccr4 = read_cyrix_reg(CCR4);
388 ccr4 &= ~CCR4_IOMASK;
390 write_cyrix_reg(CCR4, ccr4 | (CPU_IORT & CCR4_IOMASK));
392 write_cyrix_reg(CCR4, ccr4 | 7);
395 /* Initialize CCR5. */
397 write_cyrix_reg(CCR5, read_cyrix_reg(CCR5) | CCR5_WT_ALLOC);
401 write_cyrix_reg(CCR3, ccr3);
403 /* Unlock NW bit in CR0. */
404 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) & ~CCR2_LOCK_NW);
407 * Earlier revision of the 6x86 CPU could crash the system if
408 * L1 cache is in write-back mode.
410 if ((cyrix_did & 0xff00) > 0x1600)
411 load_cr0(rcr0() & ~(CR0_CD | CR0_NW)); /* CD = 0 and NW = 0 */
413 /* Revision 2.6 and lower. */
414 #ifdef CYRIX_CACHE_REALLY_WORKS
415 load_cr0(rcr0() & ~(CR0_CD | CR0_NW)); /* CD = 0 and NW = 0 */
417 load_cr0((rcr0() & ~CR0_CD) | CR0_NW); /* CD = 0 and NW = 1 */
421 /* Lock NW bit in CR0. */
422 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) | CCR2_LOCK_NW);
424 intr_restore(saveintr);
426 #endif /* I486_CPU */
437 * The CMPXCHG8B instruction is always available but hidden.
439 cpu_feature |= CPUID_CX8;
443 * IDT WinChip C6/2/2A/2B/3
445 * http://www.centtech.com/winchip_bios_writers_guide_v4_0.pdf
456 * Set ECX8, DSMC, DTLOCK/EDCTLB, EMMX, and ERETSTK and clear DPDC.
458 fcr |= (1 << 1) | (1 << 7) | (1 << 8) | (1 << 9) | (1 << 16);
459 fcr &= ~(1ULL << 11);
462 * Additionally, set EBRPRED, E2MMX and EAMD3D for WinChip 2 and 3.
464 if (CPUID_TO_MODEL(cpu_id) >= 8)
465 fcr |= (1 << 12) | (1 << 19) | (1 << 20);
469 cpu_feature = regs[3];
475 * Cyrix 6x86MX (code-named M2)
477 * XXX - What should I do here? Please let me know.
485 saveintr = intr_disable();
487 load_cr0(rcr0() | CR0_CD | CR0_NW);
490 /* Initialize CCR0. */
491 write_cyrix_reg(CCR0, read_cyrix_reg(CCR0) | CCR0_NC1);
493 /* Initialize CCR1. */
494 #ifdef CPU_CYRIX_NO_LOCK
495 write_cyrix_reg(CCR1, read_cyrix_reg(CCR1) | CCR1_NO_LOCK);
497 write_cyrix_reg(CCR1, read_cyrix_reg(CCR1) & ~CCR1_NO_LOCK);
500 /* Initialize CCR2. */
502 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) | CCR2_SUSP_HLT);
504 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) & ~CCR2_SUSP_HLT);
507 ccr3 = read_cyrix_reg(CCR3);
508 write_cyrix_reg(CCR3, CCR3_MAPEN0);
510 /* Initialize CCR4. */
511 ccr4 = read_cyrix_reg(CCR4);
512 ccr4 &= ~CCR4_IOMASK;
514 write_cyrix_reg(CCR4, ccr4 | (CPU_IORT & CCR4_IOMASK));
516 write_cyrix_reg(CCR4, ccr4 | 7);
519 /* Initialize CCR5. */
521 write_cyrix_reg(CCR5, read_cyrix_reg(CCR5) | CCR5_WT_ALLOC);
525 write_cyrix_reg(CCR3, ccr3);
527 /* Unlock NW bit in CR0. */
528 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) & ~CCR2_LOCK_NW);
530 load_cr0(rcr0() & ~(CR0_CD | CR0_NW)); /* CD = 0 and NW = 0 */
532 /* Lock NW bit in CR0. */
533 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) | CCR2_LOCK_NW);
535 intr_restore(saveintr);
538 static int ppro_apic_used = -1;
546 * Local APIC should be disabled if it is not going to be used.
548 if (ppro_apic_used != 1) {
549 apicbase = rdmsr(MSR_APICBASE);
550 apicbase &= ~APICBASE_ENABLED;
551 wrmsr(MSR_APICBASE, apicbase);
557 * If the local APIC is going to be used after being disabled above,
558 * re-enable it and don't disable it in the future.
561 ppro_reenable_apic(void)
565 if (ppro_apic_used == 0) {
566 apicbase = rdmsr(MSR_APICBASE);
567 apicbase |= APICBASE_ENABLED;
568 wrmsr(MSR_APICBASE, apicbase);
574 * Initialize BBL_CR_CTL3 (Control register 3: used to configure the
580 #ifdef CPU_PPRO2CELERON
582 u_int64_t bbl_cr_ctl3;
584 saveintr = intr_disable();
586 load_cr0(rcr0() | CR0_CD | CR0_NW);
589 bbl_cr_ctl3 = rdmsr(MSR_BBL_CR_CTL3);
591 /* If the L2 cache is configured, do nothing. */
592 if (!(bbl_cr_ctl3 & 1)) {
593 bbl_cr_ctl3 = 0x134052bLL;
595 /* Set L2 Cache Latency (Default: 5). */
596 #ifdef CPU_CELERON_L2_LATENCY
597 #if CPU_L2_LATENCY > 15
598 #error invalid CPU_L2_LATENCY.
600 bbl_cr_ctl3 |= CPU_L2_LATENCY << 1;
602 bbl_cr_ctl3 |= 5 << 1;
604 wrmsr(MSR_BBL_CR_CTL3, bbl_cr_ctl3);
607 load_cr0(rcr0() & ~(CR0_CD | CR0_NW));
608 intr_restore(saveintr);
609 #endif /* CPU_PPRO2CELERON */
613 * Initialize special VIA features
622 * Explicitly enable CX8 and PGE on C3.
624 * http://www.via.com.tw/download/mainboards/6/13/VIA_C3_EBGA%20datasheet110.pdf
626 if (CPUID_TO_MODEL(cpu_id) <= 9)
627 fcr = (1 << 1) | (1 << 7);
632 * Check extended CPUID for PadLock features.
634 * http://www.via.com.tw/en/downloads/whitepapers/initiatives/padlock/programming_guide.pdf
636 do_cpuid(0xc0000000, regs);
637 if (regs[0] >= 0xc0000001) {
638 do_cpuid(0xc0000001, regs);
643 /* Enable RNG if present. */
644 if ((val & VIA_CPUID_HAS_RNG) != 0) {
645 via_feature_rng = VIA_HAS_RNG;
646 wrmsr(0x110B, rdmsr(0x110B) | VIA_CPUID_DO_RNG);
649 /* Enable PadLock if present. */
650 if ((val & VIA_CPUID_HAS_ACE) != 0)
651 via_feature_xcrypt |= VIA_HAS_AES;
652 if ((val & VIA_CPUID_HAS_ACE2) != 0)
653 via_feature_xcrypt |= VIA_HAS_AESCTR;
654 if ((val & VIA_CPUID_HAS_PHE) != 0)
655 via_feature_xcrypt |= VIA_HAS_SHA;
656 if ((val & VIA_CPUID_HAS_PMM) != 0)
657 via_feature_xcrypt |= VIA_HAS_MM;
658 if (via_feature_xcrypt != 0)
661 wrmsr(0x1107, rdmsr(0x1107) | fcr);
664 #endif /* I686_CPU */
666 #if defined(I586_CPU) || defined(I686_CPU)
672 /* Expose all hidden features. */
673 wrmsr(0x80860004, rdmsr(0x80860004) | ~0UL);
675 cpu_feature = regs[3];
679 extern int elf32_nxstack;
688 init_bluelightning();
699 #ifdef CPU_I486_ON_386
707 #endif /* I486_CPU */
710 switch (cpu_vendor_id) {
713 if (((cpu_id & 0x0f0) > 0) &&
714 ((cpu_id & 0x0f0) < 0x60) &&
715 ((cpu_id & 0x00f) > 3))
716 enable_K5_wt_alloc();
717 else if (((cpu_id & 0x0f0) > 0x80) ||
718 (((cpu_id & 0x0f0) == 0x80) &&
719 (cpu_id & 0x00f) > 0x07))
720 enable_K6_2_wt_alloc();
721 else if ((cpu_id & 0x0f0) > 0x50)
722 enable_K6_wt_alloc();
724 if ((cpu_id & 0xf0) == 0xa0)
726 * Make sure the TSC runs through
727 * suspension, otherwise we can't use
730 wrmsr(0x1900, rdmsr(0x1900) | 0x20ULL);
732 case CPU_VENDOR_CENTAUR:
735 case CPU_VENDOR_TRANSMETA:
738 case CPU_VENDOR_RISE:
749 switch (cpu_vendor_id) {
750 case CPU_VENDOR_INTEL:
751 switch (cpu_id & 0xff0) {
760 #ifdef CPU_ATHLON_SSE_HACK
763 * Sometimes the BIOS doesn't enable SSE instructions.
764 * According to AMD document 20734, the mobile
765 * Duron, the (mobile) Athlon 4 and the Athlon MP
766 * support SSE. These correspond to cpu_id 0x66X
769 if ((cpu_feature & CPUID_XMM) == 0 &&
770 ((cpu_id & ~0xf) == 0x660 ||
771 (cpu_id & ~0xf) == 0x670 ||
772 (cpu_id & ~0xf) == 0x680)) {
774 wrmsr(MSR_HWCR, rdmsr(MSR_HWCR) & ~0x08000);
776 cpu_feature = regs[3];
780 case CPU_VENDOR_CENTAUR:
783 case CPU_VENDOR_TRANSMETA:
787 #if defined(PAE) || defined(PAE_TABLES)
788 if ((amd_feature & AMDID_NX) != 0) {
791 msr = rdmsr(MSR_EFER) | EFER_NXE;
792 wrmsr(MSR_EFER, msr);
802 #if defined(CPU_ENABLE_SSE)
803 if ((cpu_feature & CPUID_XMM) && (cpu_feature & CPUID_FXSR)) {
804 load_cr4(rcr4() | CR4_FXSR | CR4_XMM);
805 cpu_fxsr = hw_instruction_sse = 1;
811 initializecpucache(void)
815 * CPUID with %eax = 1, %ebx returns
816 * Bits 15-8: CLFLUSH line size
817 * (Value * 8 = cache line size in bytes)
819 if ((cpu_feature & CPUID_CLFSH) != 0)
820 cpu_clflush_line_size = ((cpu_procinfo >> 8) & 0xff) * 8;
822 * XXXKIB: (temporary) hack to work around traps generated
823 * when CLFLUSHing APIC register window under virtualization
824 * environments. These environments tend to disable the
825 * CPUID_SS feature even though the native CPU supports it.
827 TUNABLE_INT_FETCH("hw.clflush_disable", &hw_clflush_disable);
828 if (vm_guest != VM_GUEST_NO && hw_clflush_disable == -1)
829 cpu_feature &= ~CPUID_CLFSH;
831 * Allow to disable CLFLUSH feature manually by
832 * hw.clflush_disable tunable.
834 if (hw_clflush_disable == 1)
835 cpu_feature &= ~CPUID_CLFSH;
837 #if defined(PC98) && !defined(CPU_UPGRADE_HW_CACHE)
839 * OS should flush L1 cache by itself because no PC-98 supports
840 * non-Intel CPUs. Use wbinvd instruction before DMA transfer
841 * when need_pre_dma_flush = 1, use invd instruction after DMA
842 * transfer when need_post_dma_flush = 1. If your CPU upgrade
843 * product supports hardware cache control, you can add the
844 * CPU_UPGRADE_HW_CACHE option in your kernel configuration file.
845 * This option eliminates unneeded cache flush instruction(s).
847 if (cpu_vendor_id == CPU_VENDOR_CYRIX) {
851 need_post_dma_flush = 1;
854 need_pre_dma_flush = 1;
857 need_pre_dma_flush = 1;
858 #ifdef CPU_I486_ON_386
859 need_post_dma_flush = 1;
866 } else if (cpu_vendor_id == CPU_VENDOR_AMD) {
867 switch (cpu_id & 0xFF0) {
868 case 0x470: /* Enhanced Am486DX2 WB */
869 case 0x490: /* Enhanced Am486DX4 WB */
870 case 0x4F0: /* Am5x86 WB */
871 need_pre_dma_flush = 1;
874 } else if (cpu_vendor_id == CPU_VENDOR_IBM) {
875 need_post_dma_flush = 1;
877 #ifdef CPU_I486_ON_386
878 need_pre_dma_flush = 1;
881 #endif /* PC98 && !CPU_UPGRADE_HW_CACHE */
884 #if defined(I586_CPU) && defined(CPU_WT_ALLOC)
886 * Enable write allocate feature of AMD processors.
887 * Following two functions require the Maxmem variable being set.
890 enable_K5_wt_alloc(void)
896 * Write allocate is supported only on models 1, 2, and 3, with
897 * a stepping of 4 or greater.
899 if (((cpu_id & 0xf0) > 0) && ((cpu_id & 0x0f) > 3)) {
900 saveintr = intr_disable();
901 msr = rdmsr(0x83); /* HWCR */
902 wrmsr(0x83, msr & !(0x10));
905 * We have to tell the chip where the top of memory is,
906 * since video cards could have frame bufferes there,
907 * memory-mapped I/O could be there, etc.
913 msr |= AMD_WT_ALLOC_TME | AMD_WT_ALLOC_FRE;
915 if (!(inb(0x43b) & 4)) {
916 wrmsr(0x86, 0x0ff00f0);
917 msr |= AMD_WT_ALLOC_PRE;
921 * There is no way to know wheter 15-16M hole exists or not.
922 * Therefore, we disable write allocate for this range.
924 wrmsr(0x86, 0x0ff00f0);
925 msr |= AMD_WT_ALLOC_PRE;
930 wrmsr(0x83, msr|0x10); /* enable write allocate */
931 intr_restore(saveintr);
936 enable_K6_wt_alloc(void)
942 saveintr = intr_disable();
945 #ifdef CPU_DISABLE_CACHE
947 * Certain K6-2 box becomes unstable when write allocation is
951 * The AMD-K6 processer provides the 64-bit Test Register 12(TR12),
952 * but only the Cache Inhibit(CI) (bit 3 of TR12) is suppported.
953 * All other bits in TR12 have no effect on the processer's operation.
954 * The I/O Trap Restart function (bit 9 of TR12) is always enabled
957 wrmsr(0x0000000e, (u_int64_t)0x0008);
959 /* Don't assume that memory size is aligned with 4M. */
961 size = ((Maxmem >> 8) + 3) >> 2;
965 /* Limit is 508M bytes. */
968 whcr = (rdmsr(0xc0000082) & ~(0x7fLL << 1)) | (size << 1);
970 #if defined(PC98) || defined(NO_MEMORY_HOLE)
971 if (whcr & (0x7fLL << 1)) {
974 * If bit 2 of port 0x43b is 0, disable wrte allocate for the
977 if (!(inb(0x43b) & 4))
985 * There is no way to know wheter 15-16M hole exists or not.
986 * Therefore, we disable write allocate for this range.
990 wrmsr(0x0c0000082, whcr);
992 intr_restore(saveintr);
996 enable_K6_2_wt_alloc(void)
1000 register_t saveintr;
1002 saveintr = intr_disable();
1005 #ifdef CPU_DISABLE_CACHE
1007 * Certain K6-2 box becomes unstable when write allocation is
1011 * The AMD-K6 processer provides the 64-bit Test Register 12(TR12),
1012 * but only the Cache Inhibit(CI) (bit 3 of TR12) is suppported.
1013 * All other bits in TR12 have no effect on the processer's operation.
1014 * The I/O Trap Restart function (bit 9 of TR12) is always enabled
1017 wrmsr(0x0000000e, (u_int64_t)0x0008);
1019 /* Don't assume that memory size is aligned with 4M. */
1021 size = ((Maxmem >> 8) + 3) >> 2;
1025 /* Limit is 4092M bytes. */
1028 whcr = (rdmsr(0xc0000082) & ~(0x3ffLL << 22)) | (size << 22);
1030 #if defined(PC98) || defined(NO_MEMORY_HOLE)
1031 if (whcr & (0x3ffLL << 22)) {
1034 * If bit 2 of port 0x43b is 0, disable wrte allocate for the
1037 if (!(inb(0x43b) & 4))
1038 whcr &= ~(1LL << 16);
1045 * There is no way to know wheter 15-16M hole exists or not.
1046 * Therefore, we disable write allocate for this range.
1048 whcr &= ~(1LL << 16);
1050 wrmsr(0x0c0000082, whcr);
1052 intr_restore(saveintr);
1054 #endif /* I585_CPU && CPU_WT_ALLOC */
1056 #include "opt_ddb.h"
1058 #include <ddb/ddb.h>
1060 DB_SHOW_COMMAND(cyrixreg, cyrixreg)
1062 register_t saveintr;
1064 u_char ccr1, ccr2, ccr3;
1065 u_char ccr0 = 0, ccr4 = 0, ccr5 = 0, pcr0 = 0;
1068 if (cpu_vendor_id == CPU_VENDOR_CYRIX) {
1069 saveintr = intr_disable();
1072 if ((cpu != CPU_M1SC) && (cpu != CPU_CY486DX)) {
1073 ccr0 = read_cyrix_reg(CCR0);
1075 ccr1 = read_cyrix_reg(CCR1);
1076 ccr2 = read_cyrix_reg(CCR2);
1077 ccr3 = read_cyrix_reg(CCR3);
1078 if ((cpu == CPU_M1SC) || (cpu == CPU_M1) || (cpu == CPU_M2)) {
1079 write_cyrix_reg(CCR3, CCR3_MAPEN0);
1080 ccr4 = read_cyrix_reg(CCR4);
1081 if ((cpu == CPU_M1) || (cpu == CPU_M2))
1082 ccr5 = read_cyrix_reg(CCR5);
1084 pcr0 = read_cyrix_reg(PCR0);
1085 write_cyrix_reg(CCR3, ccr3); /* Restore CCR3. */
1087 intr_restore(saveintr);
1089 if ((cpu != CPU_M1SC) && (cpu != CPU_CY486DX))
1090 printf("CCR0=%x, ", (u_int)ccr0);
1092 printf("CCR1=%x, CCR2=%x, CCR3=%x",
1093 (u_int)ccr1, (u_int)ccr2, (u_int)ccr3);
1094 if ((cpu == CPU_M1SC) || (cpu == CPU_M1) || (cpu == CPU_M2)) {
1095 printf(", CCR4=%x, ", (u_int)ccr4);
1096 if (cpu == CPU_M1SC)
1097 printf("PCR0=%x\n", pcr0);
1099 printf("CCR5=%x\n", ccr5);
1102 printf("CR0=%x\n", cr0);