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_mon_mwait_flags; /* MONITOR/MWAIT flags (CPUID.05H.ECX) */
106 u_int cpu_mon_min_size; /* MONITOR minimum range size, bytes */
107 u_int cpu_mon_max_size; /* MONITOR minimum range size, bytes */
108 u_int cyrix_did; /* Device ID of Cyrix CPU */
110 SYSCTL_UINT(_hw, OID_AUTO, via_feature_rng, CTLFLAG_RD,
111 &via_feature_rng, 0, "VIA RNG feature available in CPU");
112 SYSCTL_UINT(_hw, OID_AUTO, via_feature_xcrypt, CTLFLAG_RD,
113 &via_feature_xcrypt, 0, "VIA xcrypt feature available in CPU");
120 init_bluelightning(void)
124 #if defined(PC98) && !defined(CPU_UPGRADE_HW_CACHE)
125 need_post_dma_flush = 1;
128 saveintr = intr_disable();
130 load_cr0(rcr0() | CR0_CD | CR0_NW);
133 #ifdef CPU_BLUELIGHTNING_FPU_OP_CACHE
134 wrmsr(0x1000, 0x9c92LL); /* FP operand can be cacheable on Cyrix FPU */
136 wrmsr(0x1000, 0x1c92LL); /* Intel FPU */
138 /* Enables 13MB and 0-640KB cache. */
139 wrmsr(0x1001, (0xd0LL << 32) | 0x3ff);
140 #ifdef CPU_BLUELIGHTNING_3X
141 wrmsr(0x1002, 0x04000000LL); /* Enables triple-clock mode. */
143 wrmsr(0x1002, 0x03000000LL); /* Enables double-clock mode. */
146 /* Enable caching in CR0. */
147 load_cr0(rcr0() & ~(CR0_CD | CR0_NW)); /* CD = 0 and NW = 0 */
149 intr_restore(saveintr);
153 * Cyrix 486SLC/DLC/SR/DR series
161 saveintr = intr_disable();
164 ccr0 = read_cyrix_reg(CCR0);
165 #ifndef CYRIX_CACHE_WORKS
166 ccr0 |= CCR0_NC1 | CCR0_BARB;
167 write_cyrix_reg(CCR0, ccr0);
171 #ifndef CYRIX_CACHE_REALLY_WORKS
172 ccr0 |= CCR0_NC1 | CCR0_BARB;
176 #ifdef CPU_DIRECT_MAPPED_CACHE
177 ccr0 |= CCR0_CO; /* Direct mapped mode. */
179 write_cyrix_reg(CCR0, ccr0);
181 /* Clear non-cacheable region. */
182 write_cyrix_reg(NCR1+2, NCR_SIZE_0K);
183 write_cyrix_reg(NCR2+2, NCR_SIZE_0K);
184 write_cyrix_reg(NCR3+2, NCR_SIZE_0K);
185 write_cyrix_reg(NCR4+2, NCR_SIZE_0K);
187 write_cyrix_reg(0, 0); /* dummy write */
189 /* Enable caching in CR0. */
190 load_cr0(rcr0() & ~(CR0_CD | CR0_NW)); /* CD = 0 and NW = 0 */
192 #endif /* !CYRIX_CACHE_WORKS */
193 intr_restore(saveintr);
198 * Cyrix 486S/DX series
206 saveintr = intr_disable();
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 intr_restore(saveintr);
234 u_char ccr2, ccr3, ccr4, pcr0;
236 saveintr = intr_disable();
238 load_cr0(rcr0() | CR0_CD | CR0_NW);
241 (void)read_cyrix_reg(CCR3); /* dummy */
243 /* Initialize CCR2. */
244 ccr2 = read_cyrix_reg(CCR2);
247 ccr2 |= CCR2_SUSP_HLT;
249 ccr2 &= ~CCR2_SUSP_HLT;
252 write_cyrix_reg(CCR2, ccr2);
254 /* Initialize CCR4. */
255 ccr3 = read_cyrix_reg(CCR3);
256 write_cyrix_reg(CCR3, CCR3_MAPEN0);
258 ccr4 = read_cyrix_reg(CCR4);
261 #ifdef CPU_FASTER_5X86_FPU
262 ccr4 |= CCR4_FASTFPE;
264 ccr4 &= ~CCR4_FASTFPE;
266 ccr4 &= ~CCR4_IOMASK;
267 /********************************************************************
268 * WARNING: The "BIOS Writers Guide" mentions that I/O recovery time
269 * should be 0 for errata fix.
270 ********************************************************************/
272 ccr4 |= CPU_IORT & CCR4_IOMASK;
274 write_cyrix_reg(CCR4, ccr4);
276 /* Initialize PCR0. */
277 /****************************************************************
278 * WARNING: RSTK_EN and LOOP_EN could make your system unstable.
279 * BTB_EN might make your system unstable.
280 ****************************************************************/
281 pcr0 = read_cyrix_reg(PCR0);
298 /****************************************************************
299 * WARNING: if you use a memory mapped I/O device, don't use
300 * DISABLE_5X86_LSSER option, which may reorder memory mapped
302 * IF YOUR MOTHERBOARD HAS PCI BUS, DON'T DISABLE LSSER.
303 ****************************************************************/
304 #ifdef CPU_DISABLE_5X86_LSSER
309 write_cyrix_reg(PCR0, pcr0);
312 write_cyrix_reg(CCR3, ccr3);
314 (void)read_cyrix_reg(0x80); /* dummy */
316 /* Unlock NW bit in CR0. */
317 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) & ~CCR2_LOCK_NW);
318 load_cr0((rcr0() & ~CR0_CD) | CR0_NW); /* CD = 0, NW = 1 */
319 /* Lock NW bit in CR0. */
320 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) | CCR2_LOCK_NW);
322 intr_restore(saveintr);
325 #ifdef CPU_I486_ON_386
327 * There are i486 based upgrade products for i386 machines.
328 * In this case, BIOS doesn't enable CPU cache.
331 init_i486_on_386(void)
335 #if defined(PC98) && !defined(CPU_UPGRADE_HW_CACHE)
336 need_post_dma_flush = 1;
339 saveintr = intr_disable();
341 load_cr0(rcr0() & ~(CR0_CD | CR0_NW)); /* CD = 0, NW = 0 */
343 intr_restore(saveintr);
350 * XXX - What should I do here? Please let me know.
358 saveintr = intr_disable();
360 load_cr0(rcr0() | CR0_CD | CR0_NW);
363 /* Initialize CCR0. */
364 write_cyrix_reg(CCR0, read_cyrix_reg(CCR0) | CCR0_NC1);
366 /* Initialize CCR1. */
367 #ifdef CPU_CYRIX_NO_LOCK
368 write_cyrix_reg(CCR1, read_cyrix_reg(CCR1) | CCR1_NO_LOCK);
370 write_cyrix_reg(CCR1, read_cyrix_reg(CCR1) & ~CCR1_NO_LOCK);
373 /* Initialize CCR2. */
375 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) | CCR2_SUSP_HLT);
377 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) & ~CCR2_SUSP_HLT);
380 ccr3 = read_cyrix_reg(CCR3);
381 write_cyrix_reg(CCR3, CCR3_MAPEN0);
383 /* Initialize CCR4. */
384 ccr4 = read_cyrix_reg(CCR4);
386 ccr4 &= ~CCR4_IOMASK;
388 write_cyrix_reg(CCR4, ccr4 | (CPU_IORT & CCR4_IOMASK));
390 write_cyrix_reg(CCR4, ccr4 | 7);
393 /* Initialize CCR5. */
395 write_cyrix_reg(CCR5, read_cyrix_reg(CCR5) | CCR5_WT_ALLOC);
399 write_cyrix_reg(CCR3, ccr3);
401 /* Unlock NW bit in CR0. */
402 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) & ~CCR2_LOCK_NW);
405 * Earlier revision of the 6x86 CPU could crash the system if
406 * L1 cache is in write-back mode.
408 if ((cyrix_did & 0xff00) > 0x1600)
409 load_cr0(rcr0() & ~(CR0_CD | CR0_NW)); /* CD = 0 and NW = 0 */
411 /* Revision 2.6 and lower. */
412 #ifdef CYRIX_CACHE_REALLY_WORKS
413 load_cr0(rcr0() & ~(CR0_CD | CR0_NW)); /* CD = 0 and NW = 0 */
415 load_cr0((rcr0() & ~CR0_CD) | CR0_NW); /* CD = 0 and NW = 1 */
419 /* Lock NW bit in CR0. */
420 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) | CCR2_LOCK_NW);
422 intr_restore(saveintr);
424 #endif /* I486_CPU */
435 * The CMPXCHG8B instruction is always available but hidden.
437 cpu_feature |= CPUID_CX8;
441 * IDT WinChip C6/2/2A/2B/3
443 * http://www.centtech.com/winchip_bios_writers_guide_v4_0.pdf
454 * Set ECX8, DSMC, DTLOCK/EDCTLB, EMMX, and ERETSTK and clear DPDC.
456 fcr |= (1 << 1) | (1 << 7) | (1 << 8) | (1 << 9) | (1 << 16);
457 fcr &= ~(1ULL << 11);
460 * Additionally, set EBRPRED, E2MMX and EAMD3D for WinChip 2 and 3.
462 if (CPUID_TO_MODEL(cpu_id) >= 8)
463 fcr |= (1 << 12) | (1 << 19) | (1 << 20);
467 cpu_feature = regs[3];
473 * Cyrix 6x86MX (code-named M2)
475 * XXX - What should I do here? Please let me know.
483 saveintr = intr_disable();
485 load_cr0(rcr0() | CR0_CD | CR0_NW);
488 /* Initialize CCR0. */
489 write_cyrix_reg(CCR0, read_cyrix_reg(CCR0) | CCR0_NC1);
491 /* Initialize CCR1. */
492 #ifdef CPU_CYRIX_NO_LOCK
493 write_cyrix_reg(CCR1, read_cyrix_reg(CCR1) | CCR1_NO_LOCK);
495 write_cyrix_reg(CCR1, read_cyrix_reg(CCR1) & ~CCR1_NO_LOCK);
498 /* Initialize CCR2. */
500 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) | CCR2_SUSP_HLT);
502 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) & ~CCR2_SUSP_HLT);
505 ccr3 = read_cyrix_reg(CCR3);
506 write_cyrix_reg(CCR3, CCR3_MAPEN0);
508 /* Initialize CCR4. */
509 ccr4 = read_cyrix_reg(CCR4);
510 ccr4 &= ~CCR4_IOMASK;
512 write_cyrix_reg(CCR4, ccr4 | (CPU_IORT & CCR4_IOMASK));
514 write_cyrix_reg(CCR4, ccr4 | 7);
517 /* Initialize CCR5. */
519 write_cyrix_reg(CCR5, read_cyrix_reg(CCR5) | CCR5_WT_ALLOC);
523 write_cyrix_reg(CCR3, ccr3);
525 /* Unlock NW bit in CR0. */
526 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) & ~CCR2_LOCK_NW);
528 load_cr0(rcr0() & ~(CR0_CD | CR0_NW)); /* CD = 0 and NW = 0 */
530 /* Lock NW bit in CR0. */
531 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) | CCR2_LOCK_NW);
533 intr_restore(saveintr);
536 static int ppro_apic_used = -1;
544 * Local APIC should be disabled if it is not going to be used.
546 if (ppro_apic_used != 1) {
547 apicbase = rdmsr(MSR_APICBASE);
548 apicbase &= ~APICBASE_ENABLED;
549 wrmsr(MSR_APICBASE, apicbase);
555 * If the local APIC is going to be used after being disabled above,
556 * re-enable it and don't disable it in the future.
559 ppro_reenable_apic(void)
563 if (ppro_apic_used == 0) {
564 apicbase = rdmsr(MSR_APICBASE);
565 apicbase |= APICBASE_ENABLED;
566 wrmsr(MSR_APICBASE, apicbase);
572 * Initialize BBL_CR_CTL3 (Control register 3: used to configure the
578 #ifdef CPU_PPRO2CELERON
580 u_int64_t bbl_cr_ctl3;
582 saveintr = intr_disable();
584 load_cr0(rcr0() | CR0_CD | CR0_NW);
587 bbl_cr_ctl3 = rdmsr(MSR_BBL_CR_CTL3);
589 /* If the L2 cache is configured, do nothing. */
590 if (!(bbl_cr_ctl3 & 1)) {
591 bbl_cr_ctl3 = 0x134052bLL;
593 /* Set L2 Cache Latency (Default: 5). */
594 #ifdef CPU_CELERON_L2_LATENCY
595 #if CPU_L2_LATENCY > 15
596 #error invalid CPU_L2_LATENCY.
598 bbl_cr_ctl3 |= CPU_L2_LATENCY << 1;
600 bbl_cr_ctl3 |= 5 << 1;
602 wrmsr(MSR_BBL_CR_CTL3, bbl_cr_ctl3);
605 load_cr0(rcr0() & ~(CR0_CD | CR0_NW));
606 intr_restore(saveintr);
607 #endif /* CPU_PPRO2CELERON */
611 * Initialize special VIA features
620 * Explicitly enable CX8 and PGE on C3.
622 * http://www.via.com.tw/download/mainboards/6/13/VIA_C3_EBGA%20datasheet110.pdf
624 if (CPUID_TO_MODEL(cpu_id) <= 9)
625 fcr = (1 << 1) | (1 << 7);
630 * Check extended CPUID for PadLock features.
632 * http://www.via.com.tw/en/downloads/whitepapers/initiatives/padlock/programming_guide.pdf
634 do_cpuid(0xc0000000, regs);
635 if (regs[0] >= 0xc0000001) {
636 do_cpuid(0xc0000001, regs);
641 /* Enable RNG if present. */
642 if ((val & VIA_CPUID_HAS_RNG) != 0) {
643 via_feature_rng = VIA_HAS_RNG;
644 wrmsr(0x110B, rdmsr(0x110B) | VIA_CPUID_DO_RNG);
647 /* Enable PadLock if present. */
648 if ((val & VIA_CPUID_HAS_ACE) != 0)
649 via_feature_xcrypt |= VIA_HAS_AES;
650 if ((val & VIA_CPUID_HAS_ACE2) != 0)
651 via_feature_xcrypt |= VIA_HAS_AESCTR;
652 if ((val & VIA_CPUID_HAS_PHE) != 0)
653 via_feature_xcrypt |= VIA_HAS_SHA;
654 if ((val & VIA_CPUID_HAS_PMM) != 0)
655 via_feature_xcrypt |= VIA_HAS_MM;
656 if (via_feature_xcrypt != 0)
659 wrmsr(0x1107, rdmsr(0x1107) | fcr);
662 #endif /* I686_CPU */
664 #if defined(I586_CPU) || defined(I686_CPU)
670 /* Expose all hidden features. */
671 wrmsr(0x80860004, rdmsr(0x80860004) | ~0UL);
673 cpu_feature = regs[3];
677 extern int elf32_nxstack;
686 init_bluelightning();
697 #ifdef CPU_I486_ON_386
705 #endif /* I486_CPU */
708 switch (cpu_vendor_id) {
711 if (((cpu_id & 0x0f0) > 0) &&
712 ((cpu_id & 0x0f0) < 0x60) &&
713 ((cpu_id & 0x00f) > 3))
714 enable_K5_wt_alloc();
715 else if (((cpu_id & 0x0f0) > 0x80) ||
716 (((cpu_id & 0x0f0) == 0x80) &&
717 (cpu_id & 0x00f) > 0x07))
718 enable_K6_2_wt_alloc();
719 else if ((cpu_id & 0x0f0) > 0x50)
720 enable_K6_wt_alloc();
722 if ((cpu_id & 0xf0) == 0xa0)
724 * Make sure the TSC runs through
725 * suspension, otherwise we can't use
728 wrmsr(0x1900, rdmsr(0x1900) | 0x20ULL);
730 case CPU_VENDOR_CENTAUR:
733 case CPU_VENDOR_TRANSMETA:
736 case CPU_VENDOR_RISE:
747 switch (cpu_vendor_id) {
748 case CPU_VENDOR_INTEL:
749 switch (cpu_id & 0xff0) {
758 #ifdef CPU_ATHLON_SSE_HACK
761 * Sometimes the BIOS doesn't enable SSE instructions.
762 * According to AMD document 20734, the mobile
763 * Duron, the (mobile) Athlon 4 and the Athlon MP
764 * support SSE. These correspond to cpu_id 0x66X
767 if ((cpu_feature & CPUID_XMM) == 0 &&
768 ((cpu_id & ~0xf) == 0x660 ||
769 (cpu_id & ~0xf) == 0x670 ||
770 (cpu_id & ~0xf) == 0x680)) {
772 wrmsr(MSR_HWCR, rdmsr(MSR_HWCR) & ~0x08000);
774 cpu_feature = regs[3];
778 case CPU_VENDOR_CENTAUR:
781 case CPU_VENDOR_TRANSMETA:
786 if ((amd_feature & AMDID_NX) != 0) {
789 msr = rdmsr(MSR_EFER) | EFER_NXE;
790 wrmsr(MSR_EFER, msr);
800 #if defined(CPU_ENABLE_SSE)
801 if ((cpu_feature & CPUID_XMM) && (cpu_feature & CPUID_FXSR)) {
802 load_cr4(rcr4() | CR4_FXSR | CR4_XMM);
803 cpu_fxsr = hw_instruction_sse = 1;
809 initializecpucache(void)
813 * CPUID with %eax = 1, %ebx returns
814 * Bits 15-8: CLFLUSH line size
815 * (Value * 8 = cache line size in bytes)
817 if ((cpu_feature & CPUID_CLFSH) != 0)
818 cpu_clflush_line_size = ((cpu_procinfo >> 8) & 0xff) * 8;
820 * XXXKIB: (temporary) hack to work around traps generated
821 * when CLFLUSHing APIC register window under virtualization
822 * environments. These environments tend to disable the
823 * CPUID_SS feature even though the native CPU supports it.
825 TUNABLE_INT_FETCH("hw.clflush_disable", &hw_clflush_disable);
826 if (vm_guest != VM_GUEST_NO && hw_clflush_disable == -1)
827 cpu_feature &= ~CPUID_CLFSH;
829 * Allow to disable CLFLUSH feature manually by
830 * hw.clflush_disable tunable.
832 if (hw_clflush_disable == 1)
833 cpu_feature &= ~CPUID_CLFSH;
835 #if defined(PC98) && !defined(CPU_UPGRADE_HW_CACHE)
837 * OS should flush L1 cache by itself because no PC-98 supports
838 * non-Intel CPUs. Use wbinvd instruction before DMA transfer
839 * when need_pre_dma_flush = 1, use invd instruction after DMA
840 * transfer when need_post_dma_flush = 1. If your CPU upgrade
841 * product supports hardware cache control, you can add the
842 * CPU_UPGRADE_HW_CACHE option in your kernel configuration file.
843 * This option eliminates unneeded cache flush instruction(s).
845 if (cpu_vendor_id == CPU_VENDOR_CYRIX) {
849 need_post_dma_flush = 1;
852 need_pre_dma_flush = 1;
855 need_pre_dma_flush = 1;
856 #ifdef CPU_I486_ON_386
857 need_post_dma_flush = 1;
864 } else if (cpu_vendor_id == CPU_VENDOR_AMD) {
865 switch (cpu_id & 0xFF0) {
866 case 0x470: /* Enhanced Am486DX2 WB */
867 case 0x490: /* Enhanced Am486DX4 WB */
868 case 0x4F0: /* Am5x86 WB */
869 need_pre_dma_flush = 1;
872 } else if (cpu_vendor_id == CPU_VENDOR_IBM) {
873 need_post_dma_flush = 1;
875 #ifdef CPU_I486_ON_386
876 need_pre_dma_flush = 1;
879 #endif /* PC98 && !CPU_UPGRADE_HW_CACHE */
882 #if defined(I586_CPU) && defined(CPU_WT_ALLOC)
884 * Enable write allocate feature of AMD processors.
885 * Following two functions require the Maxmem variable being set.
888 enable_K5_wt_alloc(void)
894 * Write allocate is supported only on models 1, 2, and 3, with
895 * a stepping of 4 or greater.
897 if (((cpu_id & 0xf0) > 0) && ((cpu_id & 0x0f) > 3)) {
898 saveintr = intr_disable();
899 msr = rdmsr(0x83); /* HWCR */
900 wrmsr(0x83, msr & !(0x10));
903 * We have to tell the chip where the top of memory is,
904 * since video cards could have frame bufferes there,
905 * memory-mapped I/O could be there, etc.
911 msr |= AMD_WT_ALLOC_TME | AMD_WT_ALLOC_FRE;
913 if (!(inb(0x43b) & 4)) {
914 wrmsr(0x86, 0x0ff00f0);
915 msr |= AMD_WT_ALLOC_PRE;
919 * There is no way to know wheter 15-16M hole exists or not.
920 * Therefore, we disable write allocate for this range.
922 wrmsr(0x86, 0x0ff00f0);
923 msr |= AMD_WT_ALLOC_PRE;
928 wrmsr(0x83, msr|0x10); /* enable write allocate */
929 intr_restore(saveintr);
934 enable_K6_wt_alloc(void)
940 saveintr = intr_disable();
943 #ifdef CPU_DISABLE_CACHE
945 * Certain K6-2 box becomes unstable when write allocation is
949 * The AMD-K6 processer provides the 64-bit Test Register 12(TR12),
950 * but only the Cache Inhibit(CI) (bit 3 of TR12) is suppported.
951 * All other bits in TR12 have no effect on the processer's operation.
952 * The I/O Trap Restart function (bit 9 of TR12) is always enabled
955 wrmsr(0x0000000e, (u_int64_t)0x0008);
957 /* Don't assume that memory size is aligned with 4M. */
959 size = ((Maxmem >> 8) + 3) >> 2;
963 /* Limit is 508M bytes. */
966 whcr = (rdmsr(0xc0000082) & ~(0x7fLL << 1)) | (size << 1);
968 #if defined(PC98) || defined(NO_MEMORY_HOLE)
969 if (whcr & (0x7fLL << 1)) {
972 * If bit 2 of port 0x43b is 0, disable wrte allocate for the
975 if (!(inb(0x43b) & 4))
983 * There is no way to know wheter 15-16M hole exists or not.
984 * Therefore, we disable write allocate for this range.
988 wrmsr(0x0c0000082, whcr);
990 intr_restore(saveintr);
994 enable_K6_2_wt_alloc(void)
1000 saveintr = intr_disable();
1003 #ifdef CPU_DISABLE_CACHE
1005 * Certain K6-2 box becomes unstable when write allocation is
1009 * The AMD-K6 processer provides the 64-bit Test Register 12(TR12),
1010 * but only the Cache Inhibit(CI) (bit 3 of TR12) is suppported.
1011 * All other bits in TR12 have no effect on the processer's operation.
1012 * The I/O Trap Restart function (bit 9 of TR12) is always enabled
1015 wrmsr(0x0000000e, (u_int64_t)0x0008);
1017 /* Don't assume that memory size is aligned with 4M. */
1019 size = ((Maxmem >> 8) + 3) >> 2;
1023 /* Limit is 4092M bytes. */
1026 whcr = (rdmsr(0xc0000082) & ~(0x3ffLL << 22)) | (size << 22);
1028 #if defined(PC98) || defined(NO_MEMORY_HOLE)
1029 if (whcr & (0x3ffLL << 22)) {
1032 * If bit 2 of port 0x43b is 0, disable wrte allocate for the
1035 if (!(inb(0x43b) & 4))
1036 whcr &= ~(1LL << 16);
1043 * There is no way to know wheter 15-16M hole exists or not.
1044 * Therefore, we disable write allocate for this range.
1046 whcr &= ~(1LL << 16);
1048 wrmsr(0x0c0000082, whcr);
1050 intr_restore(saveintr);
1052 #endif /* I585_CPU && CPU_WT_ALLOC */
1054 #include "opt_ddb.h"
1056 #include <ddb/ddb.h>
1058 DB_SHOW_COMMAND(cyrixreg, cyrixreg)
1060 register_t saveintr;
1062 u_char ccr1, ccr2, ccr3;
1063 u_char ccr0 = 0, ccr4 = 0, ccr5 = 0, pcr0 = 0;
1066 if (cpu_vendor_id == CPU_VENDOR_CYRIX) {
1067 saveintr = intr_disable();
1070 if ((cpu != CPU_M1SC) && (cpu != CPU_CY486DX)) {
1071 ccr0 = read_cyrix_reg(CCR0);
1073 ccr1 = read_cyrix_reg(CCR1);
1074 ccr2 = read_cyrix_reg(CCR2);
1075 ccr3 = read_cyrix_reg(CCR3);
1076 if ((cpu == CPU_M1SC) || (cpu == CPU_M1) || (cpu == CPU_M2)) {
1077 write_cyrix_reg(CCR3, CCR3_MAPEN0);
1078 ccr4 = read_cyrix_reg(CCR4);
1079 if ((cpu == CPU_M1) || (cpu == CPU_M2))
1080 ccr5 = read_cyrix_reg(CCR5);
1082 pcr0 = read_cyrix_reg(PCR0);
1083 write_cyrix_reg(CCR3, ccr3); /* Restore CCR3. */
1085 intr_restore(saveintr);
1087 if ((cpu != CPU_M1SC) && (cpu != CPU_CY486DX))
1088 printf("CCR0=%x, ", (u_int)ccr0);
1090 printf("CCR1=%x, CCR2=%x, CCR3=%x",
1091 (u_int)ccr1, (u_int)ccr2, (u_int)ccr3);
1092 if ((cpu == CPU_M1SC) || (cpu == CPU_M1) || (cpu == CPU_M2)) {
1093 printf(", CCR4=%x, ", (u_int)ccr4);
1094 if (cpu == CPU_M1SC)
1095 printf("PCR0=%x\n", pcr0);
1097 printf("CCR5=%x\n", ccr5);
1100 printf("CR0=%x\n", cr0);