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>
38 #include <sys/systm.h>
39 #include <sys/sysctl.h>
41 #include <machine/cputypes.h>
42 #include <machine/md_var.h>
43 #include <machine/specialreg.h>
49 static void init_5x86(void);
50 static void init_bluelightning(void);
51 static void init_486dlc(void);
52 static void init_cy486dx(void);
53 #ifdef CPU_I486_ON_386
54 static void init_i486_on_386(void);
56 static void init_6x86(void);
59 #if defined(I586_CPU) && defined(CPU_WT_ALLOC)
60 static void enable_K5_wt_alloc(void);
61 static void enable_K6_wt_alloc(void);
62 static void enable_K6_2_wt_alloc(void);
66 static void init_6x86MX(void);
67 static void init_ppro(void);
68 static void init_mendocino(void);
71 static int hw_instruction_sse;
72 SYSCTL_INT(_hw, OID_AUTO, instruction_sse, CTLFLAG_RD,
73 &hw_instruction_sse, 0, "SIMD/MMX2 instructions available in CPU");
75 * -1: automatic (default)
76 * 0: keep enable CLFLUSH
77 * 1: force disable CLFLUSH
79 static int hw_clflush_disable = -1;
81 u_int cyrix_did; /* Device ID of Cyrix CPU */
88 init_bluelightning(void)
92 #if defined(PC98) && !defined(CPU_UPGRADE_HW_CACHE)
93 need_post_dma_flush = 1;
96 saveintr = intr_disable();
98 load_cr0(rcr0() | CR0_CD | CR0_NW);
101 #ifdef CPU_BLUELIGHTNING_FPU_OP_CACHE
102 wrmsr(0x1000, 0x9c92LL); /* FP operand can be cacheable on Cyrix FPU */
104 wrmsr(0x1000, 0x1c92LL); /* Intel FPU */
106 /* Enables 13MB and 0-640KB cache. */
107 wrmsr(0x1001, (0xd0LL << 32) | 0x3ff);
108 #ifdef CPU_BLUELIGHTNING_3X
109 wrmsr(0x1002, 0x04000000LL); /* Enables triple-clock mode. */
111 wrmsr(0x1002, 0x03000000LL); /* Enables double-clock mode. */
114 /* Enable caching in CR0. */
115 load_cr0(rcr0() & ~(CR0_CD | CR0_NW)); /* CD = 0 and NW = 0 */
117 intr_restore(saveintr);
121 * Cyrix 486SLC/DLC/SR/DR series
129 saveintr = intr_disable();
132 ccr0 = read_cyrix_reg(CCR0);
133 #ifndef CYRIX_CACHE_WORKS
134 ccr0 |= CCR0_NC1 | CCR0_BARB;
135 write_cyrix_reg(CCR0, ccr0);
139 #ifndef CYRIX_CACHE_REALLY_WORKS
140 ccr0 |= CCR0_NC1 | CCR0_BARB;
144 #ifdef CPU_DIRECT_MAPPED_CACHE
145 ccr0 |= CCR0_CO; /* Direct mapped mode. */
147 write_cyrix_reg(CCR0, ccr0);
149 /* Clear non-cacheable region. */
150 write_cyrix_reg(NCR1+2, NCR_SIZE_0K);
151 write_cyrix_reg(NCR2+2, NCR_SIZE_0K);
152 write_cyrix_reg(NCR3+2, NCR_SIZE_0K);
153 write_cyrix_reg(NCR4+2, NCR_SIZE_0K);
155 write_cyrix_reg(0, 0); /* dummy write */
157 /* Enable caching in CR0. */
158 load_cr0(rcr0() & ~(CR0_CD | CR0_NW)); /* CD = 0 and NW = 0 */
160 #endif /* !CYRIX_CACHE_WORKS */
161 intr_restore(saveintr);
166 * Cyrix 486S/DX series
174 saveintr = intr_disable();
177 ccr2 = read_cyrix_reg(CCR2);
179 ccr2 |= CCR2_SUSP_HLT;
183 /* Enables WB cache interface pin and Lock NW bit in CR0. */
184 ccr2 |= CCR2_WB | CCR2_LOCK_NW;
185 /* Unlock NW bit in CR0. */
186 write_cyrix_reg(CCR2, ccr2 & ~CCR2_LOCK_NW);
187 load_cr0((rcr0() & ~CR0_CD) | CR0_NW); /* CD = 0, NW = 1 */
190 write_cyrix_reg(CCR2, ccr2);
191 intr_restore(saveintr);
202 u_char ccr2, ccr3, ccr4, pcr0;
204 saveintr = intr_disable();
206 load_cr0(rcr0() | CR0_CD | CR0_NW);
209 (void)read_cyrix_reg(CCR3); /* dummy */
211 /* Initialize CCR2. */
212 ccr2 = read_cyrix_reg(CCR2);
215 ccr2 |= CCR2_SUSP_HLT;
217 ccr2 &= ~CCR2_SUSP_HLT;
220 write_cyrix_reg(CCR2, ccr2);
222 /* Initialize CCR4. */
223 ccr3 = read_cyrix_reg(CCR3);
224 write_cyrix_reg(CCR3, CCR3_MAPEN0);
226 ccr4 = read_cyrix_reg(CCR4);
229 #ifdef CPU_FASTER_5X86_FPU
230 ccr4 |= CCR4_FASTFPE;
232 ccr4 &= ~CCR4_FASTFPE;
234 ccr4 &= ~CCR4_IOMASK;
235 /********************************************************************
236 * WARNING: The "BIOS Writers Guide" mentions that I/O recovery time
237 * should be 0 for errata fix.
238 ********************************************************************/
240 ccr4 |= CPU_IORT & CCR4_IOMASK;
242 write_cyrix_reg(CCR4, ccr4);
244 /* Initialize PCR0. */
245 /****************************************************************
246 * WARNING: RSTK_EN and LOOP_EN could make your system unstable.
247 * BTB_EN might make your system unstable.
248 ****************************************************************/
249 pcr0 = read_cyrix_reg(PCR0);
266 /****************************************************************
267 * WARNING: if you use a memory mapped I/O device, don't use
268 * DISABLE_5X86_LSSER option, which may reorder memory mapped
270 * IF YOUR MOTHERBOARD HAS PCI BUS, DON'T DISABLE LSSER.
271 ****************************************************************/
272 #ifdef CPU_DISABLE_5X86_LSSER
277 write_cyrix_reg(PCR0, pcr0);
280 write_cyrix_reg(CCR3, ccr3);
282 (void)read_cyrix_reg(0x80); /* dummy */
284 /* Unlock NW bit in CR0. */
285 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) & ~CCR2_LOCK_NW);
286 load_cr0((rcr0() & ~CR0_CD) | CR0_NW); /* CD = 0, NW = 1 */
287 /* Lock NW bit in CR0. */
288 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) | CCR2_LOCK_NW);
290 intr_restore(saveintr);
293 #ifdef CPU_I486_ON_386
295 * There are i486 based upgrade products for i386 machines.
296 * In this case, BIOS doesn't enable CPU cache.
299 init_i486_on_386(void)
303 #if defined(PC98) && !defined(CPU_UPGRADE_HW_CACHE)
304 need_post_dma_flush = 1;
307 saveintr = intr_disable();
309 load_cr0(rcr0() & ~(CR0_CD | CR0_NW)); /* CD = 0, NW = 0 */
311 intr_restore(saveintr);
318 * XXX - What should I do here? Please let me know.
326 saveintr = intr_disable();
328 load_cr0(rcr0() | CR0_CD | CR0_NW);
331 /* Initialize CCR0. */
332 write_cyrix_reg(CCR0, read_cyrix_reg(CCR0) | CCR0_NC1);
334 /* Initialize CCR1. */
335 #ifdef CPU_CYRIX_NO_LOCK
336 write_cyrix_reg(CCR1, read_cyrix_reg(CCR1) | CCR1_NO_LOCK);
338 write_cyrix_reg(CCR1, read_cyrix_reg(CCR1) & ~CCR1_NO_LOCK);
341 /* Initialize CCR2. */
343 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) | CCR2_SUSP_HLT);
345 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) & ~CCR2_SUSP_HLT);
348 ccr3 = read_cyrix_reg(CCR3);
349 write_cyrix_reg(CCR3, CCR3_MAPEN0);
351 /* Initialize CCR4. */
352 ccr4 = read_cyrix_reg(CCR4);
354 ccr4 &= ~CCR4_IOMASK;
356 write_cyrix_reg(CCR4, ccr4 | (CPU_IORT & CCR4_IOMASK));
358 write_cyrix_reg(CCR4, ccr4 | 7);
361 /* Initialize CCR5. */
363 write_cyrix_reg(CCR5, read_cyrix_reg(CCR5) | CCR5_WT_ALLOC);
367 write_cyrix_reg(CCR3, ccr3);
369 /* Unlock NW bit in CR0. */
370 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) & ~CCR2_LOCK_NW);
373 * Earlier revision of the 6x86 CPU could crash the system if
374 * L1 cache is in write-back mode.
376 if ((cyrix_did & 0xff00) > 0x1600)
377 load_cr0(rcr0() & ~(CR0_CD | CR0_NW)); /* CD = 0 and NW = 0 */
379 /* Revision 2.6 and lower. */
380 #ifdef CYRIX_CACHE_REALLY_WORKS
381 load_cr0(rcr0() & ~(CR0_CD | CR0_NW)); /* CD = 0 and NW = 0 */
383 load_cr0((rcr0() & ~CR0_CD) | CR0_NW); /* CD = 0 and NW = 1 */
387 /* Lock NW bit in CR0. */
388 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) | CCR2_LOCK_NW);
390 intr_restore(saveintr);
392 #endif /* I486_CPU */
403 * The CMPXCHG8B instruction is always available but hidden.
405 cpu_feature |= CPUID_CX8;
409 * IDT WinChip C6/2/2A/2B/3
411 * http://www.centtech.com/winchip_bios_writers_guide_v4_0.pdf
422 * Set ECX8, DSMC, DTLOCK/EDCTLB, EMMX, and ERETSTK and clear DPDC.
424 fcr |= (1 << 1) | (1 << 7) | (1 << 8) | (1 << 9) | (1 << 16);
425 fcr &= ~(1ULL << 11);
428 * Additionally, set EBRPRED, E2MMX and EAMD3D for WinChip 2 and 3.
430 if (CPUID_TO_MODEL(cpu_id) >= 8)
431 fcr |= (1 << 12) | (1 << 19) | (1 << 20);
435 cpu_feature = regs[3];
441 * Cyrix 6x86MX (code-named M2)
443 * XXX - What should I do here? Please let me know.
451 saveintr = intr_disable();
453 load_cr0(rcr0() | CR0_CD | CR0_NW);
456 /* Initialize CCR0. */
457 write_cyrix_reg(CCR0, read_cyrix_reg(CCR0) | CCR0_NC1);
459 /* Initialize CCR1. */
460 #ifdef CPU_CYRIX_NO_LOCK
461 write_cyrix_reg(CCR1, read_cyrix_reg(CCR1) | CCR1_NO_LOCK);
463 write_cyrix_reg(CCR1, read_cyrix_reg(CCR1) & ~CCR1_NO_LOCK);
466 /* Initialize CCR2. */
468 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) | CCR2_SUSP_HLT);
470 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) & ~CCR2_SUSP_HLT);
473 ccr3 = read_cyrix_reg(CCR3);
474 write_cyrix_reg(CCR3, CCR3_MAPEN0);
476 /* Initialize CCR4. */
477 ccr4 = read_cyrix_reg(CCR4);
478 ccr4 &= ~CCR4_IOMASK;
480 write_cyrix_reg(CCR4, ccr4 | (CPU_IORT & CCR4_IOMASK));
482 write_cyrix_reg(CCR4, ccr4 | 7);
485 /* Initialize CCR5. */
487 write_cyrix_reg(CCR5, read_cyrix_reg(CCR5) | CCR5_WT_ALLOC);
491 write_cyrix_reg(CCR3, ccr3);
493 /* Unlock NW bit in CR0. */
494 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) & ~CCR2_LOCK_NW);
496 load_cr0(rcr0() & ~(CR0_CD | CR0_NW)); /* CD = 0 and NW = 0 */
498 /* Lock NW bit in CR0. */
499 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) | CCR2_LOCK_NW);
501 intr_restore(saveintr);
504 static int ppro_apic_used = -1;
512 * Local APIC should be disabled if it is not going to be used.
514 if (ppro_apic_used != 1) {
515 apicbase = rdmsr(MSR_APICBASE);
516 apicbase &= ~APICBASE_ENABLED;
517 wrmsr(MSR_APICBASE, apicbase);
523 * If the local APIC is going to be used after being disabled above,
524 * re-enable it and don't disable it in the future.
527 ppro_reenable_apic(void)
531 if (ppro_apic_used == 0) {
532 apicbase = rdmsr(MSR_APICBASE);
533 apicbase |= APICBASE_ENABLED;
534 wrmsr(MSR_APICBASE, apicbase);
540 * Initialize BBL_CR_CTL3 (Control register 3: used to configure the
546 #ifdef CPU_PPRO2CELERON
548 u_int64_t bbl_cr_ctl3;
550 saveintr = intr_disable();
552 load_cr0(rcr0() | CR0_CD | CR0_NW);
555 bbl_cr_ctl3 = rdmsr(MSR_BBL_CR_CTL3);
557 /* If the L2 cache is configured, do nothing. */
558 if (!(bbl_cr_ctl3 & 1)) {
559 bbl_cr_ctl3 = 0x134052bLL;
561 /* Set L2 Cache Latency (Default: 5). */
562 #ifdef CPU_CELERON_L2_LATENCY
563 #if CPU_L2_LATENCY > 15
564 #error invalid CPU_L2_LATENCY.
566 bbl_cr_ctl3 |= CPU_L2_LATENCY << 1;
568 bbl_cr_ctl3 |= 5 << 1;
570 wrmsr(MSR_BBL_CR_CTL3, bbl_cr_ctl3);
573 load_cr0(rcr0() & ~(CR0_CD | CR0_NW));
574 intr_restore(saveintr);
575 #endif /* CPU_PPRO2CELERON */
579 * Initialize special VIA features
588 * Explicitly enable CX8 and PGE on C3.
590 * http://www.via.com.tw/download/mainboards/6/13/VIA_C3_EBGA%20datasheet110.pdf
592 if (CPUID_TO_MODEL(cpu_id) <= 9)
593 fcr = (1 << 1) | (1 << 7);
598 * Check extended CPUID for PadLock features.
600 * http://www.via.com.tw/en/downloads/whitepapers/initiatives/padlock/programming_guide.pdf
602 do_cpuid(0xc0000000, regs);
603 if (regs[0] >= 0xc0000001) {
604 do_cpuid(0xc0000001, regs);
609 /* Enable RNG if present. */
610 if ((val & VIA_CPUID_HAS_RNG) != 0) {
611 via_feature_rng = VIA_HAS_RNG;
612 wrmsr(0x110B, rdmsr(0x110B) | VIA_CPUID_DO_RNG);
615 /* Enable PadLock if present. */
616 if ((val & VIA_CPUID_HAS_ACE) != 0)
617 via_feature_xcrypt |= VIA_HAS_AES;
618 if ((val & VIA_CPUID_HAS_ACE2) != 0)
619 via_feature_xcrypt |= VIA_HAS_AESCTR;
620 if ((val & VIA_CPUID_HAS_PHE) != 0)
621 via_feature_xcrypt |= VIA_HAS_SHA;
622 if ((val & VIA_CPUID_HAS_PMM) != 0)
623 via_feature_xcrypt |= VIA_HAS_MM;
624 if (via_feature_xcrypt != 0)
627 wrmsr(0x1107, rdmsr(0x1107) | fcr);
630 #endif /* I686_CPU */
632 #if defined(I586_CPU) || defined(I686_CPU)
638 /* Expose all hidden features. */
639 wrmsr(0x80860004, rdmsr(0x80860004) | ~0UL);
641 cpu_feature = regs[3];
645 extern int elf32_nxstack;
654 init_bluelightning();
665 #ifdef CPU_I486_ON_386
673 #endif /* I486_CPU */
676 switch (cpu_vendor_id) {
679 if (((cpu_id & 0x0f0) > 0) &&
680 ((cpu_id & 0x0f0) < 0x60) &&
681 ((cpu_id & 0x00f) > 3))
682 enable_K5_wt_alloc();
683 else if (((cpu_id & 0x0f0) > 0x80) ||
684 (((cpu_id & 0x0f0) == 0x80) &&
685 (cpu_id & 0x00f) > 0x07))
686 enable_K6_2_wt_alloc();
687 else if ((cpu_id & 0x0f0) > 0x50)
688 enable_K6_wt_alloc();
690 if ((cpu_id & 0xf0) == 0xa0)
692 * Make sure the TSC runs through
693 * suspension, otherwise we can't use
696 wrmsr(0x1900, rdmsr(0x1900) | 0x20ULL);
698 case CPU_VENDOR_CENTAUR:
701 case CPU_VENDOR_TRANSMETA:
704 case CPU_VENDOR_RISE:
715 switch (cpu_vendor_id) {
716 case CPU_VENDOR_INTEL:
717 switch (cpu_id & 0xff0) {
726 #ifdef CPU_ATHLON_SSE_HACK
729 * Sometimes the BIOS doesn't enable SSE instructions.
730 * According to AMD document 20734, the mobile
731 * Duron, the (mobile) Athlon 4 and the Athlon MP
732 * support SSE. These correspond to cpu_id 0x66X
735 if ((cpu_feature & CPUID_XMM) == 0 &&
736 ((cpu_id & ~0xf) == 0x660 ||
737 (cpu_id & ~0xf) == 0x670 ||
738 (cpu_id & ~0xf) == 0x680)) {
740 wrmsr(MSR_HWCR, rdmsr(MSR_HWCR) & ~0x08000);
742 cpu_feature = regs[3];
746 case CPU_VENDOR_CENTAUR:
749 case CPU_VENDOR_TRANSMETA:
758 if ((cpu_feature & CPUID_XMM) && (cpu_feature & CPUID_FXSR)) {
759 load_cr4(rcr4() | CR4_FXSR | CR4_XMM);
760 cpu_fxsr = hw_instruction_sse = 1;
762 #if defined(PAE) || defined(PAE_TABLES)
763 if ((amd_feature & AMDID_NX) != 0) {
766 msr = rdmsr(MSR_EFER) | EFER_NXE;
767 wrmsr(MSR_EFER, msr);
772 if ((amd_feature & AMDID_RDTSCP) != 0 ||
773 (cpu_stdext_feature2 & CPUID_STDEXT2_RDPID) != 0)
774 wrmsr(MSR_TSC_AUX, PCPU_GET(cpuid));
778 initializecpucache(void)
782 * CPUID with %eax = 1, %ebx returns
783 * Bits 15-8: CLFLUSH line size
784 * (Value * 8 = cache line size in bytes)
786 if ((cpu_feature & CPUID_CLFSH) != 0)
787 cpu_clflush_line_size = ((cpu_procinfo >> 8) & 0xff) * 8;
789 * XXXKIB: (temporary) hack to work around traps generated
790 * when CLFLUSHing APIC register window under virtualization
791 * environments. These environments tend to disable the
792 * CPUID_SS feature even though the native CPU supports it.
794 TUNABLE_INT_FETCH("hw.clflush_disable", &hw_clflush_disable);
795 if (vm_guest != VM_GUEST_NO && hw_clflush_disable == -1) {
796 cpu_feature &= ~CPUID_CLFSH;
797 cpu_stdext_feature &= ~CPUID_STDEXT_CLFLUSHOPT;
800 * The kernel's use of CLFLUSH{,OPT} can be disabled manually
801 * by setting the hw.clflush_disable tunable.
803 if (hw_clflush_disable == 1) {
804 cpu_feature &= ~CPUID_CLFSH;
805 cpu_stdext_feature &= ~CPUID_STDEXT_CLFLUSHOPT;
808 #if defined(PC98) && !defined(CPU_UPGRADE_HW_CACHE)
810 * OS should flush L1 cache by itself because no PC-98 supports
811 * non-Intel CPUs. Use wbinvd instruction before DMA transfer
812 * when need_pre_dma_flush = 1, use invd instruction after DMA
813 * transfer when need_post_dma_flush = 1. If your CPU upgrade
814 * product supports hardware cache control, you can add the
815 * CPU_UPGRADE_HW_CACHE option in your kernel configuration file.
816 * This option eliminates unneeded cache flush instruction(s).
818 if (cpu_vendor_id == CPU_VENDOR_CYRIX) {
822 need_post_dma_flush = 1;
825 need_pre_dma_flush = 1;
828 need_pre_dma_flush = 1;
829 #ifdef CPU_I486_ON_386
830 need_post_dma_flush = 1;
837 } else if (cpu_vendor_id == CPU_VENDOR_AMD) {
838 switch (cpu_id & 0xFF0) {
839 case 0x470: /* Enhanced Am486DX2 WB */
840 case 0x490: /* Enhanced Am486DX4 WB */
841 case 0x4F0: /* Am5x86 WB */
842 need_pre_dma_flush = 1;
845 } else if (cpu_vendor_id == CPU_VENDOR_IBM) {
846 need_post_dma_flush = 1;
848 #ifdef CPU_I486_ON_386
849 need_pre_dma_flush = 1;
852 #endif /* PC98 && !CPU_UPGRADE_HW_CACHE */
855 #if defined(I586_CPU) && defined(CPU_WT_ALLOC)
857 * Enable write allocate feature of AMD processors.
858 * Following two functions require the Maxmem variable being set.
861 enable_K5_wt_alloc(void)
867 * Write allocate is supported only on models 1, 2, and 3, with
868 * a stepping of 4 or greater.
870 if (((cpu_id & 0xf0) > 0) && ((cpu_id & 0x0f) > 3)) {
871 saveintr = intr_disable();
872 msr = rdmsr(0x83); /* HWCR */
873 wrmsr(0x83, msr & !(0x10));
876 * We have to tell the chip where the top of memory is,
877 * since video cards could have frame bufferes there,
878 * memory-mapped I/O could be there, etc.
884 msr |= AMD_WT_ALLOC_TME | AMD_WT_ALLOC_FRE;
886 if (!(inb(0x43b) & 4)) {
887 wrmsr(0x86, 0x0ff00f0);
888 msr |= AMD_WT_ALLOC_PRE;
892 * There is no way to know wheter 15-16M hole exists or not.
893 * Therefore, we disable write allocate for this range.
895 wrmsr(0x86, 0x0ff00f0);
896 msr |= AMD_WT_ALLOC_PRE;
901 wrmsr(0x83, msr|0x10); /* enable write allocate */
902 intr_restore(saveintr);
907 enable_K6_wt_alloc(void)
913 saveintr = intr_disable();
916 #ifdef CPU_DISABLE_CACHE
918 * Certain K6-2 box becomes unstable when write allocation is
922 * The AMD-K6 processer provides the 64-bit Test Register 12(TR12),
923 * but only the Cache Inhibit(CI) (bit 3 of TR12) is suppported.
924 * All other bits in TR12 have no effect on the processer's operation.
925 * The I/O Trap Restart function (bit 9 of TR12) is always enabled
928 wrmsr(0x0000000e, (u_int64_t)0x0008);
930 /* Don't assume that memory size is aligned with 4M. */
932 size = ((Maxmem >> 8) + 3) >> 2;
936 /* Limit is 508M bytes. */
939 whcr = (rdmsr(0xc0000082) & ~(0x7fLL << 1)) | (size << 1);
941 #if defined(PC98) || defined(NO_MEMORY_HOLE)
942 if (whcr & (0x7fLL << 1)) {
945 * If bit 2 of port 0x43b is 0, disable wrte allocate for the
948 if (!(inb(0x43b) & 4))
956 * There is no way to know wheter 15-16M hole exists or not.
957 * Therefore, we disable write allocate for this range.
961 wrmsr(0x0c0000082, whcr);
963 intr_restore(saveintr);
967 enable_K6_2_wt_alloc(void)
973 saveintr = intr_disable();
976 #ifdef CPU_DISABLE_CACHE
978 * Certain K6-2 box becomes unstable when write allocation is
982 * The AMD-K6 processer provides the 64-bit Test Register 12(TR12),
983 * but only the Cache Inhibit(CI) (bit 3 of TR12) is suppported.
984 * All other bits in TR12 have no effect on the processer's operation.
985 * The I/O Trap Restart function (bit 9 of TR12) is always enabled
988 wrmsr(0x0000000e, (u_int64_t)0x0008);
990 /* Don't assume that memory size is aligned with 4M. */
992 size = ((Maxmem >> 8) + 3) >> 2;
996 /* Limit is 4092M bytes. */
999 whcr = (rdmsr(0xc0000082) & ~(0x3ffLL << 22)) | (size << 22);
1001 #if defined(PC98) || defined(NO_MEMORY_HOLE)
1002 if (whcr & (0x3ffLL << 22)) {
1005 * If bit 2 of port 0x43b is 0, disable wrte allocate for the
1008 if (!(inb(0x43b) & 4))
1009 whcr &= ~(1LL << 16);
1016 * There is no way to know wheter 15-16M hole exists or not.
1017 * Therefore, we disable write allocate for this range.
1019 whcr &= ~(1LL << 16);
1021 wrmsr(0x0c0000082, whcr);
1023 intr_restore(saveintr);
1025 #endif /* I585_CPU && CPU_WT_ALLOC */
1027 #include "opt_ddb.h"
1029 #include <ddb/ddb.h>
1031 DB_SHOW_COMMAND(cyrixreg, cyrixreg)
1033 register_t saveintr;
1035 u_char ccr1, ccr2, ccr3;
1036 u_char ccr0 = 0, ccr4 = 0, ccr5 = 0, pcr0 = 0;
1039 if (cpu_vendor_id == CPU_VENDOR_CYRIX) {
1040 saveintr = intr_disable();
1043 if ((cpu != CPU_M1SC) && (cpu != CPU_CY486DX)) {
1044 ccr0 = read_cyrix_reg(CCR0);
1046 ccr1 = read_cyrix_reg(CCR1);
1047 ccr2 = read_cyrix_reg(CCR2);
1048 ccr3 = read_cyrix_reg(CCR3);
1049 if ((cpu == CPU_M1SC) || (cpu == CPU_M1) || (cpu == CPU_M2)) {
1050 write_cyrix_reg(CCR3, CCR3_MAPEN0);
1051 ccr4 = read_cyrix_reg(CCR4);
1052 if ((cpu == CPU_M1) || (cpu == CPU_M2))
1053 ccr5 = read_cyrix_reg(CCR5);
1055 pcr0 = read_cyrix_reg(PCR0);
1056 write_cyrix_reg(CCR3, ccr3); /* Restore CCR3. */
1058 intr_restore(saveintr);
1060 if ((cpu != CPU_M1SC) && (cpu != CPU_CY486DX))
1061 printf("CCR0=%x, ", (u_int)ccr0);
1063 printf("CCR1=%x, CCR2=%x, CCR3=%x",
1064 (u_int)ccr1, (u_int)ccr2, (u_int)ccr3);
1065 if ((cpu == CPU_M1SC) || (cpu == CPU_M1) || (cpu == CPU_M2)) {
1066 printf(", CCR4=%x, ", (u_int)ccr4);
1067 if (cpu == CPU_M1SC)
1068 printf("PCR0=%x\n", pcr0);
1070 printf("CCR5=%x\n", ccr5);
1073 printf("CR0=%x\n", cr0);