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>
48 static void init_5x86(void);
49 static void init_bluelightning(void);
50 static void init_486dlc(void);
51 static void init_cy486dx(void);
52 #ifdef CPU_I486_ON_386
53 static void init_i486_on_386(void);
55 static void init_6x86(void);
58 #if defined(I586_CPU) && defined(CPU_WT_ALLOC)
59 static void enable_K5_wt_alloc(void);
60 static void enable_K6_wt_alloc(void);
61 static void enable_K6_2_wt_alloc(void);
65 static void init_6x86MX(void);
66 static void init_ppro(void);
67 static void init_mendocino(void);
70 static int hw_instruction_sse;
71 SYSCTL_INT(_hw, OID_AUTO, instruction_sse, CTLFLAG_RD,
72 &hw_instruction_sse, 0, "SIMD/MMX2 instructions available in CPU");
74 * -1: automatic (default)
75 * 0: keep enable CLFLUSH
76 * 1: force disable CLFLUSH
78 static int hw_clflush_disable = -1;
80 u_int cyrix_did; /* Device ID of Cyrix CPU */
87 init_bluelightning(void)
91 #if defined(PC98) && !defined(CPU_UPGRADE_HW_CACHE)
92 need_post_dma_flush = 1;
95 saveintr = intr_disable();
97 load_cr0(rcr0() | CR0_CD | CR0_NW);
100 #ifdef CPU_BLUELIGHTNING_FPU_OP_CACHE
101 wrmsr(0x1000, 0x9c92LL); /* FP operand can be cacheable on Cyrix FPU */
103 wrmsr(0x1000, 0x1c92LL); /* Intel FPU */
105 /* Enables 13MB and 0-640KB cache. */
106 wrmsr(0x1001, (0xd0LL << 32) | 0x3ff);
107 #ifdef CPU_BLUELIGHTNING_3X
108 wrmsr(0x1002, 0x04000000LL); /* Enables triple-clock mode. */
110 wrmsr(0x1002, 0x03000000LL); /* Enables double-clock mode. */
113 /* Enable caching in CR0. */
114 load_cr0(rcr0() & ~(CR0_CD | CR0_NW)); /* CD = 0 and NW = 0 */
116 intr_restore(saveintr);
120 * Cyrix 486SLC/DLC/SR/DR series
128 saveintr = intr_disable();
131 ccr0 = read_cyrix_reg(CCR0);
132 #ifndef CYRIX_CACHE_WORKS
133 ccr0 |= CCR0_NC1 | CCR0_BARB;
134 write_cyrix_reg(CCR0, ccr0);
138 #ifndef CYRIX_CACHE_REALLY_WORKS
139 ccr0 |= CCR0_NC1 | CCR0_BARB;
143 #ifdef CPU_DIRECT_MAPPED_CACHE
144 ccr0 |= CCR0_CO; /* Direct mapped mode. */
146 write_cyrix_reg(CCR0, ccr0);
148 /* Clear non-cacheable region. */
149 write_cyrix_reg(NCR1+2, NCR_SIZE_0K);
150 write_cyrix_reg(NCR2+2, NCR_SIZE_0K);
151 write_cyrix_reg(NCR3+2, NCR_SIZE_0K);
152 write_cyrix_reg(NCR4+2, NCR_SIZE_0K);
154 write_cyrix_reg(0, 0); /* dummy write */
156 /* Enable caching in CR0. */
157 load_cr0(rcr0() & ~(CR0_CD | CR0_NW)); /* CD = 0 and NW = 0 */
159 #endif /* !CYRIX_CACHE_WORKS */
160 intr_restore(saveintr);
165 * Cyrix 486S/DX series
173 saveintr = intr_disable();
176 ccr2 = read_cyrix_reg(CCR2);
178 ccr2 |= CCR2_SUSP_HLT;
182 /* Enables WB cache interface pin and Lock NW bit in CR0. */
183 ccr2 |= CCR2_WB | CCR2_LOCK_NW;
184 /* Unlock NW bit in CR0. */
185 write_cyrix_reg(CCR2, ccr2 & ~CCR2_LOCK_NW);
186 load_cr0((rcr0() & ~CR0_CD) | CR0_NW); /* CD = 0, NW = 1 */
189 write_cyrix_reg(CCR2, ccr2);
190 intr_restore(saveintr);
201 u_char ccr2, ccr3, ccr4, pcr0;
203 saveintr = intr_disable();
205 load_cr0(rcr0() | CR0_CD | CR0_NW);
208 (void)read_cyrix_reg(CCR3); /* dummy */
210 /* Initialize CCR2. */
211 ccr2 = read_cyrix_reg(CCR2);
214 ccr2 |= CCR2_SUSP_HLT;
216 ccr2 &= ~CCR2_SUSP_HLT;
219 write_cyrix_reg(CCR2, ccr2);
221 /* Initialize CCR4. */
222 ccr3 = read_cyrix_reg(CCR3);
223 write_cyrix_reg(CCR3, CCR3_MAPEN0);
225 ccr4 = read_cyrix_reg(CCR4);
228 #ifdef CPU_FASTER_5X86_FPU
229 ccr4 |= CCR4_FASTFPE;
231 ccr4 &= ~CCR4_FASTFPE;
233 ccr4 &= ~CCR4_IOMASK;
234 /********************************************************************
235 * WARNING: The "BIOS Writers Guide" mentions that I/O recovery time
236 * should be 0 for errata fix.
237 ********************************************************************/
239 ccr4 |= CPU_IORT & CCR4_IOMASK;
241 write_cyrix_reg(CCR4, ccr4);
243 /* Initialize PCR0. */
244 /****************************************************************
245 * WARNING: RSTK_EN and LOOP_EN could make your system unstable.
246 * BTB_EN might make your system unstable.
247 ****************************************************************/
248 pcr0 = read_cyrix_reg(PCR0);
265 /****************************************************************
266 * WARNING: if you use a memory mapped I/O device, don't use
267 * DISABLE_5X86_LSSER option, which may reorder memory mapped
269 * IF YOUR MOTHERBOARD HAS PCI BUS, DON'T DISABLE LSSER.
270 ****************************************************************/
271 #ifdef CPU_DISABLE_5X86_LSSER
276 write_cyrix_reg(PCR0, pcr0);
279 write_cyrix_reg(CCR3, ccr3);
281 (void)read_cyrix_reg(0x80); /* dummy */
283 /* Unlock NW bit in CR0. */
284 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) & ~CCR2_LOCK_NW);
285 load_cr0((rcr0() & ~CR0_CD) | CR0_NW); /* CD = 0, NW = 1 */
286 /* Lock NW bit in CR0. */
287 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) | CCR2_LOCK_NW);
289 intr_restore(saveintr);
292 #ifdef CPU_I486_ON_386
294 * There are i486 based upgrade products for i386 machines.
295 * In this case, BIOS doesn't enable CPU cache.
298 init_i486_on_386(void)
302 #if defined(PC98) && !defined(CPU_UPGRADE_HW_CACHE)
303 need_post_dma_flush = 1;
306 saveintr = intr_disable();
308 load_cr0(rcr0() & ~(CR0_CD | CR0_NW)); /* CD = 0, NW = 0 */
310 intr_restore(saveintr);
317 * XXX - What should I do here? Please let me know.
325 saveintr = intr_disable();
327 load_cr0(rcr0() | CR0_CD | CR0_NW);
330 /* Initialize CCR0. */
331 write_cyrix_reg(CCR0, read_cyrix_reg(CCR0) | CCR0_NC1);
333 /* Initialize CCR1. */
334 #ifdef CPU_CYRIX_NO_LOCK
335 write_cyrix_reg(CCR1, read_cyrix_reg(CCR1) | CCR1_NO_LOCK);
337 write_cyrix_reg(CCR1, read_cyrix_reg(CCR1) & ~CCR1_NO_LOCK);
340 /* Initialize CCR2. */
342 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) | CCR2_SUSP_HLT);
344 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) & ~CCR2_SUSP_HLT);
347 ccr3 = read_cyrix_reg(CCR3);
348 write_cyrix_reg(CCR3, CCR3_MAPEN0);
350 /* Initialize CCR4. */
351 ccr4 = read_cyrix_reg(CCR4);
353 ccr4 &= ~CCR4_IOMASK;
355 write_cyrix_reg(CCR4, ccr4 | (CPU_IORT & CCR4_IOMASK));
357 write_cyrix_reg(CCR4, ccr4 | 7);
360 /* Initialize CCR5. */
362 write_cyrix_reg(CCR5, read_cyrix_reg(CCR5) | CCR5_WT_ALLOC);
366 write_cyrix_reg(CCR3, ccr3);
368 /* Unlock NW bit in CR0. */
369 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) & ~CCR2_LOCK_NW);
372 * Earlier revision of the 6x86 CPU could crash the system if
373 * L1 cache is in write-back mode.
375 if ((cyrix_did & 0xff00) > 0x1600)
376 load_cr0(rcr0() & ~(CR0_CD | CR0_NW)); /* CD = 0 and NW = 0 */
378 /* Revision 2.6 and lower. */
379 #ifdef CYRIX_CACHE_REALLY_WORKS
380 load_cr0(rcr0() & ~(CR0_CD | CR0_NW)); /* CD = 0 and NW = 0 */
382 load_cr0((rcr0() & ~CR0_CD) | CR0_NW); /* CD = 0 and NW = 1 */
386 /* Lock NW bit in CR0. */
387 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) | CCR2_LOCK_NW);
389 intr_restore(saveintr);
391 #endif /* I486_CPU */
402 * The CMPXCHG8B instruction is always available but hidden.
404 cpu_feature |= CPUID_CX8;
408 * IDT WinChip C6/2/2A/2B/3
410 * http://www.centtech.com/winchip_bios_writers_guide_v4_0.pdf
421 * Set ECX8, DSMC, DTLOCK/EDCTLB, EMMX, and ERETSTK and clear DPDC.
423 fcr |= (1 << 1) | (1 << 7) | (1 << 8) | (1 << 9) | (1 << 16);
424 fcr &= ~(1ULL << 11);
427 * Additionally, set EBRPRED, E2MMX and EAMD3D for WinChip 2 and 3.
429 if (CPUID_TO_MODEL(cpu_id) >= 8)
430 fcr |= (1 << 12) | (1 << 19) | (1 << 20);
434 cpu_feature = regs[3];
440 * Cyrix 6x86MX (code-named M2)
442 * XXX - What should I do here? Please let me know.
450 saveintr = intr_disable();
452 load_cr0(rcr0() | CR0_CD | CR0_NW);
455 /* Initialize CCR0. */
456 write_cyrix_reg(CCR0, read_cyrix_reg(CCR0) | CCR0_NC1);
458 /* Initialize CCR1. */
459 #ifdef CPU_CYRIX_NO_LOCK
460 write_cyrix_reg(CCR1, read_cyrix_reg(CCR1) | CCR1_NO_LOCK);
462 write_cyrix_reg(CCR1, read_cyrix_reg(CCR1) & ~CCR1_NO_LOCK);
465 /* Initialize CCR2. */
467 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) | CCR2_SUSP_HLT);
469 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) & ~CCR2_SUSP_HLT);
472 ccr3 = read_cyrix_reg(CCR3);
473 write_cyrix_reg(CCR3, CCR3_MAPEN0);
475 /* Initialize CCR4. */
476 ccr4 = read_cyrix_reg(CCR4);
477 ccr4 &= ~CCR4_IOMASK;
479 write_cyrix_reg(CCR4, ccr4 | (CPU_IORT & CCR4_IOMASK));
481 write_cyrix_reg(CCR4, ccr4 | 7);
484 /* Initialize CCR5. */
486 write_cyrix_reg(CCR5, read_cyrix_reg(CCR5) | CCR5_WT_ALLOC);
490 write_cyrix_reg(CCR3, ccr3);
492 /* Unlock NW bit in CR0. */
493 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) & ~CCR2_LOCK_NW);
495 load_cr0(rcr0() & ~(CR0_CD | CR0_NW)); /* CD = 0 and NW = 0 */
497 /* Lock NW bit in CR0. */
498 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) | CCR2_LOCK_NW);
500 intr_restore(saveintr);
503 static int ppro_apic_used = -1;
511 * Local APIC should be disabled if it is not going to be used.
513 if (ppro_apic_used != 1) {
514 apicbase = rdmsr(MSR_APICBASE);
515 apicbase &= ~APICBASE_ENABLED;
516 wrmsr(MSR_APICBASE, apicbase);
522 * If the local APIC is going to be used after being disabled above,
523 * re-enable it and don't disable it in the future.
526 ppro_reenable_apic(void)
530 if (ppro_apic_used == 0) {
531 apicbase = rdmsr(MSR_APICBASE);
532 apicbase |= APICBASE_ENABLED;
533 wrmsr(MSR_APICBASE, apicbase);
539 * Initialize BBL_CR_CTL3 (Control register 3: used to configure the
545 #ifdef CPU_PPRO2CELERON
547 u_int64_t bbl_cr_ctl3;
549 saveintr = intr_disable();
551 load_cr0(rcr0() | CR0_CD | CR0_NW);
554 bbl_cr_ctl3 = rdmsr(MSR_BBL_CR_CTL3);
556 /* If the L2 cache is configured, do nothing. */
557 if (!(bbl_cr_ctl3 & 1)) {
558 bbl_cr_ctl3 = 0x134052bLL;
560 /* Set L2 Cache Latency (Default: 5). */
561 #ifdef CPU_CELERON_L2_LATENCY
562 #if CPU_L2_LATENCY > 15
563 #error invalid CPU_L2_LATENCY.
565 bbl_cr_ctl3 |= CPU_L2_LATENCY << 1;
567 bbl_cr_ctl3 |= 5 << 1;
569 wrmsr(MSR_BBL_CR_CTL3, bbl_cr_ctl3);
572 load_cr0(rcr0() & ~(CR0_CD | CR0_NW));
573 intr_restore(saveintr);
574 #endif /* CPU_PPRO2CELERON */
578 * Initialize special VIA features
587 * Explicitly enable CX8 and PGE on C3.
589 * http://www.via.com.tw/download/mainboards/6/13/VIA_C3_EBGA%20datasheet110.pdf
591 if (CPUID_TO_MODEL(cpu_id) <= 9)
592 fcr = (1 << 1) | (1 << 7);
597 * Check extended CPUID for PadLock features.
599 * http://www.via.com.tw/en/downloads/whitepapers/initiatives/padlock/programming_guide.pdf
601 do_cpuid(0xc0000000, regs);
602 if (regs[0] >= 0xc0000001) {
603 do_cpuid(0xc0000001, regs);
608 /* Enable RNG if present. */
609 if ((val & VIA_CPUID_HAS_RNG) != 0) {
610 via_feature_rng = VIA_HAS_RNG;
611 wrmsr(0x110B, rdmsr(0x110B) | VIA_CPUID_DO_RNG);
614 /* Enable PadLock if present. */
615 if ((val & VIA_CPUID_HAS_ACE) != 0)
616 via_feature_xcrypt |= VIA_HAS_AES;
617 if ((val & VIA_CPUID_HAS_ACE2) != 0)
618 via_feature_xcrypt |= VIA_HAS_AESCTR;
619 if ((val & VIA_CPUID_HAS_PHE) != 0)
620 via_feature_xcrypt |= VIA_HAS_SHA;
621 if ((val & VIA_CPUID_HAS_PMM) != 0)
622 via_feature_xcrypt |= VIA_HAS_MM;
623 if (via_feature_xcrypt != 0)
626 wrmsr(0x1107, rdmsr(0x1107) | fcr);
629 #endif /* I686_CPU */
631 #if defined(I586_CPU) || defined(I686_CPU)
637 /* Expose all hidden features. */
638 wrmsr(0x80860004, rdmsr(0x80860004) | ~0UL);
640 cpu_feature = regs[3];
644 extern int elf32_nxstack;
653 init_bluelightning();
664 #ifdef CPU_I486_ON_386
672 #endif /* I486_CPU */
675 switch (cpu_vendor_id) {
678 if (((cpu_id & 0x0f0) > 0) &&
679 ((cpu_id & 0x0f0) < 0x60) &&
680 ((cpu_id & 0x00f) > 3))
681 enable_K5_wt_alloc();
682 else if (((cpu_id & 0x0f0) > 0x80) ||
683 (((cpu_id & 0x0f0) == 0x80) &&
684 (cpu_id & 0x00f) > 0x07))
685 enable_K6_2_wt_alloc();
686 else if ((cpu_id & 0x0f0) > 0x50)
687 enable_K6_wt_alloc();
689 if ((cpu_id & 0xf0) == 0xa0)
691 * Make sure the TSC runs through
692 * suspension, otherwise we can't use
695 wrmsr(0x1900, rdmsr(0x1900) | 0x20ULL);
697 case CPU_VENDOR_CENTAUR:
700 case CPU_VENDOR_TRANSMETA:
703 case CPU_VENDOR_RISE:
714 switch (cpu_vendor_id) {
715 case CPU_VENDOR_INTEL:
716 switch (cpu_id & 0xff0) {
725 #ifdef CPU_ATHLON_SSE_HACK
728 * Sometimes the BIOS doesn't enable SSE instructions.
729 * According to AMD document 20734, the mobile
730 * Duron, the (mobile) Athlon 4 and the Athlon MP
731 * support SSE. These correspond to cpu_id 0x66X
734 if ((cpu_feature & CPUID_XMM) == 0 &&
735 ((cpu_id & ~0xf) == 0x660 ||
736 (cpu_id & ~0xf) == 0x670 ||
737 (cpu_id & ~0xf) == 0x680)) {
739 wrmsr(MSR_HWCR, rdmsr(MSR_HWCR) & ~0x08000);
741 cpu_feature = regs[3];
745 case CPU_VENDOR_CENTAUR:
748 case CPU_VENDOR_TRANSMETA:
757 if ((cpu_feature & CPUID_XMM) && (cpu_feature & CPUID_FXSR)) {
758 load_cr4(rcr4() | CR4_FXSR | CR4_XMM);
759 cpu_fxsr = hw_instruction_sse = 1;
761 #if defined(PAE) || defined(PAE_TABLES)
762 if ((amd_feature & AMDID_NX) != 0) {
765 msr = rdmsr(MSR_EFER) | EFER_NXE;
766 wrmsr(MSR_EFER, msr);
771 hw_mds_recalculate();
775 initializecpucache(void)
779 * CPUID with %eax = 1, %ebx returns
780 * Bits 15-8: CLFLUSH line size
781 * (Value * 8 = cache line size in bytes)
783 if ((cpu_feature & CPUID_CLFSH) != 0)
784 cpu_clflush_line_size = ((cpu_procinfo >> 8) & 0xff) * 8;
786 * XXXKIB: (temporary) hack to work around traps generated
787 * when CLFLUSHing APIC register window under virtualization
788 * environments. These environments tend to disable the
789 * CPUID_SS feature even though the native CPU supports it.
791 TUNABLE_INT_FETCH("hw.clflush_disable", &hw_clflush_disable);
792 if (vm_guest != VM_GUEST_NO && hw_clflush_disable == -1) {
793 cpu_feature &= ~CPUID_CLFSH;
794 cpu_stdext_feature &= ~CPUID_STDEXT_CLFLUSHOPT;
797 * The kernel's use of CLFLUSH{,OPT} can be disabled manually
798 * by setting the hw.clflush_disable tunable.
800 if (hw_clflush_disable == 1) {
801 cpu_feature &= ~CPUID_CLFSH;
802 cpu_stdext_feature &= ~CPUID_STDEXT_CLFLUSHOPT;
805 #if defined(PC98) && !defined(CPU_UPGRADE_HW_CACHE)
807 * OS should flush L1 cache by itself because no PC-98 supports
808 * non-Intel CPUs. Use wbinvd instruction before DMA transfer
809 * when need_pre_dma_flush = 1, use invd instruction after DMA
810 * transfer when need_post_dma_flush = 1. If your CPU upgrade
811 * product supports hardware cache control, you can add the
812 * CPU_UPGRADE_HW_CACHE option in your kernel configuration file.
813 * This option eliminates unneeded cache flush instruction(s).
815 if (cpu_vendor_id == CPU_VENDOR_CYRIX) {
819 need_post_dma_flush = 1;
822 need_pre_dma_flush = 1;
825 need_pre_dma_flush = 1;
826 #ifdef CPU_I486_ON_386
827 need_post_dma_flush = 1;
834 } else if (cpu_vendor_id == CPU_VENDOR_AMD) {
835 switch (cpu_id & 0xFF0) {
836 case 0x470: /* Enhanced Am486DX2 WB */
837 case 0x490: /* Enhanced Am486DX4 WB */
838 case 0x4F0: /* Am5x86 WB */
839 need_pre_dma_flush = 1;
842 } else if (cpu_vendor_id == CPU_VENDOR_IBM) {
843 need_post_dma_flush = 1;
845 #ifdef CPU_I486_ON_386
846 need_pre_dma_flush = 1;
849 #endif /* PC98 && !CPU_UPGRADE_HW_CACHE */
852 #if defined(I586_CPU) && defined(CPU_WT_ALLOC)
854 * Enable write allocate feature of AMD processors.
855 * Following two functions require the Maxmem variable being set.
858 enable_K5_wt_alloc(void)
864 * Write allocate is supported only on models 1, 2, and 3, with
865 * a stepping of 4 or greater.
867 if (((cpu_id & 0xf0) > 0) && ((cpu_id & 0x0f) > 3)) {
868 saveintr = intr_disable();
869 msr = rdmsr(0x83); /* HWCR */
870 wrmsr(0x83, msr & !(0x10));
873 * We have to tell the chip where the top of memory is,
874 * since video cards could have frame bufferes there,
875 * memory-mapped I/O could be there, etc.
881 msr |= AMD_WT_ALLOC_TME | AMD_WT_ALLOC_FRE;
883 if (!(inb(0x43b) & 4)) {
884 wrmsr(0x86, 0x0ff00f0);
885 msr |= AMD_WT_ALLOC_PRE;
889 * There is no way to know wheter 15-16M hole exists or not.
890 * Therefore, we disable write allocate for this range.
892 wrmsr(0x86, 0x0ff00f0);
893 msr |= AMD_WT_ALLOC_PRE;
898 wrmsr(0x83, msr|0x10); /* enable write allocate */
899 intr_restore(saveintr);
904 enable_K6_wt_alloc(void)
910 saveintr = intr_disable();
913 #ifdef CPU_DISABLE_CACHE
915 * Certain K6-2 box becomes unstable when write allocation is
919 * The AMD-K6 processer provides the 64-bit Test Register 12(TR12),
920 * but only the Cache Inhibit(CI) (bit 3 of TR12) is suppported.
921 * All other bits in TR12 have no effect on the processer's operation.
922 * The I/O Trap Restart function (bit 9 of TR12) is always enabled
925 wrmsr(0x0000000e, (u_int64_t)0x0008);
927 /* Don't assume that memory size is aligned with 4M. */
929 size = ((Maxmem >> 8) + 3) >> 2;
933 /* Limit is 508M bytes. */
936 whcr = (rdmsr(0xc0000082) & ~(0x7fLL << 1)) | (size << 1);
938 #if defined(PC98) || defined(NO_MEMORY_HOLE)
939 if (whcr & (0x7fLL << 1)) {
942 * If bit 2 of port 0x43b is 0, disable wrte allocate for the
945 if (!(inb(0x43b) & 4))
953 * There is no way to know wheter 15-16M hole exists or not.
954 * Therefore, we disable write allocate for this range.
958 wrmsr(0x0c0000082, whcr);
960 intr_restore(saveintr);
964 enable_K6_2_wt_alloc(void)
970 saveintr = intr_disable();
973 #ifdef CPU_DISABLE_CACHE
975 * Certain K6-2 box becomes unstable when write allocation is
979 * The AMD-K6 processer provides the 64-bit Test Register 12(TR12),
980 * but only the Cache Inhibit(CI) (bit 3 of TR12) is suppported.
981 * All other bits in TR12 have no effect on the processer's operation.
982 * The I/O Trap Restart function (bit 9 of TR12) is always enabled
985 wrmsr(0x0000000e, (u_int64_t)0x0008);
987 /* Don't assume that memory size is aligned with 4M. */
989 size = ((Maxmem >> 8) + 3) >> 2;
993 /* Limit is 4092M bytes. */
996 whcr = (rdmsr(0xc0000082) & ~(0x3ffLL << 22)) | (size << 22);
998 #if defined(PC98) || defined(NO_MEMORY_HOLE)
999 if (whcr & (0x3ffLL << 22)) {
1002 * If bit 2 of port 0x43b is 0, disable wrte allocate for the
1005 if (!(inb(0x43b) & 4))
1006 whcr &= ~(1LL << 16);
1013 * There is no way to know wheter 15-16M hole exists or not.
1014 * Therefore, we disable write allocate for this range.
1016 whcr &= ~(1LL << 16);
1018 wrmsr(0x0c0000082, whcr);
1020 intr_restore(saveintr);
1022 #endif /* I585_CPU && CPU_WT_ALLOC */
1024 #include "opt_ddb.h"
1026 #include <ddb/ddb.h>
1028 DB_SHOW_COMMAND(cyrixreg, cyrixreg)
1030 register_t saveintr;
1032 u_char ccr1, ccr2, ccr3;
1033 u_char ccr0 = 0, ccr4 = 0, ccr5 = 0, pcr0 = 0;
1036 if (cpu_vendor_id == CPU_VENDOR_CYRIX) {
1037 saveintr = intr_disable();
1040 if ((cpu != CPU_M1SC) && (cpu != CPU_CY486DX)) {
1041 ccr0 = read_cyrix_reg(CCR0);
1043 ccr1 = read_cyrix_reg(CCR1);
1044 ccr2 = read_cyrix_reg(CCR2);
1045 ccr3 = read_cyrix_reg(CCR3);
1046 if ((cpu == CPU_M1SC) || (cpu == CPU_M1) || (cpu == CPU_M2)) {
1047 write_cyrix_reg(CCR3, CCR3_MAPEN0);
1048 ccr4 = read_cyrix_reg(CCR4);
1049 if ((cpu == CPU_M1) || (cpu == CPU_M2))
1050 ccr5 = read_cyrix_reg(CCR5);
1052 pcr0 = read_cyrix_reg(PCR0);
1053 write_cyrix_reg(CCR3, ccr3); /* Restore CCR3. */
1055 intr_restore(saveintr);
1057 if ((cpu != CPU_M1SC) && (cpu != CPU_CY486DX))
1058 printf("CCR0=%x, ", (u_int)ccr0);
1060 printf("CCR1=%x, CCR2=%x, CCR3=%x",
1061 (u_int)ccr1, (u_int)ccr2, (u_int)ccr3);
1062 if ((cpu == CPU_M1SC) || (cpu == CPU_M1) || (cpu == CPU_M2)) {
1063 printf(", CCR4=%x, ", (u_int)ccr4);
1064 if (cpu == CPU_M1SC)
1065 printf("PCR0=%x\n", pcr0);
1067 printf("CCR5=%x\n", ccr5);
1070 printf("CR0=%x\n", cr0);