2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) KATO Takenori, 1997, 1998.
6 * All rights reserved. Unpublished rights reserved under the copyright
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer as
15 * the first lines of this file unmodified.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/cdefs.h>
33 __FBSDID("$FreeBSD$");
37 #include <sys/param.h>
38 #include <sys/kernel.h>
39 #include <sys/systm.h>
40 #include <sys/sysctl.h>
42 #include <machine/cputypes.h>
43 #include <machine/md_var.h>
44 #include <machine/specialreg.h>
50 static void init_5x86(void);
51 static void init_bluelightning(void);
52 static void init_486dlc(void);
53 static void init_cy486dx(void);
54 #ifdef CPU_I486_ON_386
55 static void init_i486_on_386(void);
57 static void init_6x86(void);
60 #if defined(I586_CPU) && defined(CPU_WT_ALLOC)
61 static void enable_K5_wt_alloc(void);
62 static void enable_K6_wt_alloc(void);
63 static void enable_K6_2_wt_alloc(void);
67 static void init_6x86MX(void);
68 static void init_ppro(void);
69 static void init_mendocino(void);
72 static int hw_instruction_sse;
73 SYSCTL_INT(_hw, OID_AUTO, instruction_sse, CTLFLAG_RD,
74 &hw_instruction_sse, 0, "SIMD/MMX2 instructions available in CPU");
76 * -1: automatic (default)
77 * 0: keep enable CLFLUSH
78 * 1: force disable CLFLUSH
80 static int hw_clflush_disable = -1;
82 u_int cyrix_did; /* Device ID of Cyrix CPU */
89 init_bluelightning(void)
93 #if defined(PC98) && !defined(CPU_UPGRADE_HW_CACHE)
94 need_post_dma_flush = 1;
97 saveintr = intr_disable();
99 load_cr0(rcr0() | CR0_CD | CR0_NW);
102 #ifdef CPU_BLUELIGHTNING_FPU_OP_CACHE
103 wrmsr(0x1000, 0x9c92LL); /* FP operand can be cacheable on Cyrix FPU */
105 wrmsr(0x1000, 0x1c92LL); /* Intel FPU */
107 /* Enables 13MB and 0-640KB cache. */
108 wrmsr(0x1001, (0xd0LL << 32) | 0x3ff);
109 #ifdef CPU_BLUELIGHTNING_3X
110 wrmsr(0x1002, 0x04000000LL); /* Enables triple-clock mode. */
112 wrmsr(0x1002, 0x03000000LL); /* Enables double-clock mode. */
115 /* Enable caching in CR0. */
116 load_cr0(rcr0() & ~(CR0_CD | CR0_NW)); /* CD = 0 and NW = 0 */
118 intr_restore(saveintr);
122 * Cyrix 486SLC/DLC/SR/DR series
130 saveintr = intr_disable();
133 ccr0 = read_cyrix_reg(CCR0);
134 #ifndef CYRIX_CACHE_WORKS
135 ccr0 |= CCR0_NC1 | CCR0_BARB;
136 write_cyrix_reg(CCR0, ccr0);
140 #ifndef CYRIX_CACHE_REALLY_WORKS
141 ccr0 |= CCR0_NC1 | CCR0_BARB;
145 #ifdef CPU_DIRECT_MAPPED_CACHE
146 ccr0 |= CCR0_CO; /* Direct mapped mode. */
148 write_cyrix_reg(CCR0, ccr0);
150 /* Clear non-cacheable region. */
151 write_cyrix_reg(NCR1+2, NCR_SIZE_0K);
152 write_cyrix_reg(NCR2+2, NCR_SIZE_0K);
153 write_cyrix_reg(NCR3+2, NCR_SIZE_0K);
154 write_cyrix_reg(NCR4+2, NCR_SIZE_0K);
156 write_cyrix_reg(0, 0); /* dummy write */
158 /* Enable caching in CR0. */
159 load_cr0(rcr0() & ~(CR0_CD | CR0_NW)); /* CD = 0 and NW = 0 */
161 #endif /* !CYRIX_CACHE_WORKS */
162 intr_restore(saveintr);
167 * Cyrix 486S/DX series
175 saveintr = intr_disable();
178 ccr2 = read_cyrix_reg(CCR2);
180 ccr2 |= CCR2_SUSP_HLT;
184 /* Enables WB cache interface pin and Lock NW bit in CR0. */
185 ccr2 |= CCR2_WB | CCR2_LOCK_NW;
186 /* Unlock NW bit in CR0. */
187 write_cyrix_reg(CCR2, ccr2 & ~CCR2_LOCK_NW);
188 load_cr0((rcr0() & ~CR0_CD) | CR0_NW); /* CD = 0, NW = 1 */
191 write_cyrix_reg(CCR2, ccr2);
192 intr_restore(saveintr);
203 u_char ccr2, ccr3, ccr4, pcr0;
205 saveintr = intr_disable();
207 load_cr0(rcr0() | CR0_CD | CR0_NW);
210 (void)read_cyrix_reg(CCR3); /* dummy */
212 /* Initialize CCR2. */
213 ccr2 = read_cyrix_reg(CCR2);
216 ccr2 |= CCR2_SUSP_HLT;
218 ccr2 &= ~CCR2_SUSP_HLT;
221 write_cyrix_reg(CCR2, ccr2);
223 /* Initialize CCR4. */
224 ccr3 = read_cyrix_reg(CCR3);
225 write_cyrix_reg(CCR3, CCR3_MAPEN0);
227 ccr4 = read_cyrix_reg(CCR4);
230 #ifdef CPU_FASTER_5X86_FPU
231 ccr4 |= CCR4_FASTFPE;
233 ccr4 &= ~CCR4_FASTFPE;
235 ccr4 &= ~CCR4_IOMASK;
236 /********************************************************************
237 * WARNING: The "BIOS Writers Guide" mentions that I/O recovery time
238 * should be 0 for errata fix.
239 ********************************************************************/
241 ccr4 |= CPU_IORT & CCR4_IOMASK;
243 write_cyrix_reg(CCR4, ccr4);
245 /* Initialize PCR0. */
246 /****************************************************************
247 * WARNING: RSTK_EN and LOOP_EN could make your system unstable.
248 * BTB_EN might make your system unstable.
249 ****************************************************************/
250 pcr0 = read_cyrix_reg(PCR0);
267 /****************************************************************
268 * WARNING: if you use a memory mapped I/O device, don't use
269 * DISABLE_5X86_LSSER option, which may reorder memory mapped
271 * IF YOUR MOTHERBOARD HAS PCI BUS, DON'T DISABLE LSSER.
272 ****************************************************************/
273 #ifdef CPU_DISABLE_5X86_LSSER
278 write_cyrix_reg(PCR0, pcr0);
281 write_cyrix_reg(CCR3, ccr3);
283 (void)read_cyrix_reg(0x80); /* dummy */
285 /* Unlock NW bit in CR0. */
286 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) & ~CCR2_LOCK_NW);
287 load_cr0((rcr0() & ~CR0_CD) | CR0_NW); /* CD = 0, NW = 1 */
288 /* Lock NW bit in CR0. */
289 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) | CCR2_LOCK_NW);
291 intr_restore(saveintr);
294 #ifdef CPU_I486_ON_386
296 * There are i486 based upgrade products for i386 machines.
297 * In this case, BIOS doesn't enable CPU cache.
300 init_i486_on_386(void)
304 #if defined(PC98) && !defined(CPU_UPGRADE_HW_CACHE)
305 need_post_dma_flush = 1;
308 saveintr = intr_disable();
310 load_cr0(rcr0() & ~(CR0_CD | CR0_NW)); /* CD = 0, NW = 0 */
312 intr_restore(saveintr);
319 * XXX - What should I do here? Please let me know.
327 saveintr = intr_disable();
329 load_cr0(rcr0() | CR0_CD | CR0_NW);
332 /* Initialize CCR0. */
333 write_cyrix_reg(CCR0, read_cyrix_reg(CCR0) | CCR0_NC1);
335 /* Initialize CCR1. */
336 #ifdef CPU_CYRIX_NO_LOCK
337 write_cyrix_reg(CCR1, read_cyrix_reg(CCR1) | CCR1_NO_LOCK);
339 write_cyrix_reg(CCR1, read_cyrix_reg(CCR1) & ~CCR1_NO_LOCK);
342 /* Initialize CCR2. */
344 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) | CCR2_SUSP_HLT);
346 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) & ~CCR2_SUSP_HLT);
349 ccr3 = read_cyrix_reg(CCR3);
350 write_cyrix_reg(CCR3, CCR3_MAPEN0);
352 /* Initialize CCR4. */
353 ccr4 = read_cyrix_reg(CCR4);
355 ccr4 &= ~CCR4_IOMASK;
357 write_cyrix_reg(CCR4, ccr4 | (CPU_IORT & CCR4_IOMASK));
359 write_cyrix_reg(CCR4, ccr4 | 7);
362 /* Initialize CCR5. */
364 write_cyrix_reg(CCR5, read_cyrix_reg(CCR5) | CCR5_WT_ALLOC);
368 write_cyrix_reg(CCR3, ccr3);
370 /* Unlock NW bit in CR0. */
371 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) & ~CCR2_LOCK_NW);
374 * Earlier revision of the 6x86 CPU could crash the system if
375 * L1 cache is in write-back mode.
377 if ((cyrix_did & 0xff00) > 0x1600)
378 load_cr0(rcr0() & ~(CR0_CD | CR0_NW)); /* CD = 0 and NW = 0 */
380 /* Revision 2.6 and lower. */
381 #ifdef CYRIX_CACHE_REALLY_WORKS
382 load_cr0(rcr0() & ~(CR0_CD | CR0_NW)); /* CD = 0 and NW = 0 */
384 load_cr0((rcr0() & ~CR0_CD) | CR0_NW); /* CD = 0 and NW = 1 */
388 /* Lock NW bit in CR0. */
389 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) | CCR2_LOCK_NW);
391 intr_restore(saveintr);
393 #endif /* I486_CPU */
404 * The CMPXCHG8B instruction is always available but hidden.
406 cpu_feature |= CPUID_CX8;
410 * IDT WinChip C6/2/2A/2B/3
412 * http://www.centtech.com/winchip_bios_writers_guide_v4_0.pdf
423 * Set ECX8, DSMC, DTLOCK/EDCTLB, EMMX, and ERETSTK and clear DPDC.
425 fcr |= (1 << 1) | (1 << 7) | (1 << 8) | (1 << 9) | (1 << 16);
426 fcr &= ~(1ULL << 11);
429 * Additionally, set EBRPRED, E2MMX and EAMD3D for WinChip 2 and 3.
431 if (CPUID_TO_MODEL(cpu_id) >= 8)
432 fcr |= (1 << 12) | (1 << 19) | (1 << 20);
436 cpu_feature = regs[3];
442 * Cyrix 6x86MX (code-named M2)
444 * XXX - What should I do here? Please let me know.
452 saveintr = intr_disable();
454 load_cr0(rcr0() | CR0_CD | CR0_NW);
457 /* Initialize CCR0. */
458 write_cyrix_reg(CCR0, read_cyrix_reg(CCR0) | CCR0_NC1);
460 /* Initialize CCR1. */
461 #ifdef CPU_CYRIX_NO_LOCK
462 write_cyrix_reg(CCR1, read_cyrix_reg(CCR1) | CCR1_NO_LOCK);
464 write_cyrix_reg(CCR1, read_cyrix_reg(CCR1) & ~CCR1_NO_LOCK);
467 /* Initialize CCR2. */
469 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) | CCR2_SUSP_HLT);
471 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) & ~CCR2_SUSP_HLT);
474 ccr3 = read_cyrix_reg(CCR3);
475 write_cyrix_reg(CCR3, CCR3_MAPEN0);
477 /* Initialize CCR4. */
478 ccr4 = read_cyrix_reg(CCR4);
479 ccr4 &= ~CCR4_IOMASK;
481 write_cyrix_reg(CCR4, ccr4 | (CPU_IORT & CCR4_IOMASK));
483 write_cyrix_reg(CCR4, ccr4 | 7);
486 /* Initialize CCR5. */
488 write_cyrix_reg(CCR5, read_cyrix_reg(CCR5) | CCR5_WT_ALLOC);
492 write_cyrix_reg(CCR3, ccr3);
494 /* Unlock NW bit in CR0. */
495 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) & ~CCR2_LOCK_NW);
497 load_cr0(rcr0() & ~(CR0_CD | CR0_NW)); /* CD = 0 and NW = 0 */
499 /* Lock NW bit in CR0. */
500 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) | CCR2_LOCK_NW);
502 intr_restore(saveintr);
505 static int ppro_apic_used = -1;
513 * Local APIC should be disabled if it is not going to be used.
515 if (ppro_apic_used != 1) {
516 apicbase = rdmsr(MSR_APICBASE);
517 apicbase &= ~APICBASE_ENABLED;
518 wrmsr(MSR_APICBASE, apicbase);
524 * If the local APIC is going to be used after being disabled above,
525 * re-enable it and don't disable it in the future.
528 ppro_reenable_apic(void)
532 if (ppro_apic_used == 0) {
533 apicbase = rdmsr(MSR_APICBASE);
534 apicbase |= APICBASE_ENABLED;
535 wrmsr(MSR_APICBASE, apicbase);
541 * Initialize BBL_CR_CTL3 (Control register 3: used to configure the
547 #ifdef CPU_PPRO2CELERON
549 u_int64_t bbl_cr_ctl3;
551 saveintr = intr_disable();
553 load_cr0(rcr0() | CR0_CD | CR0_NW);
556 bbl_cr_ctl3 = rdmsr(MSR_BBL_CR_CTL3);
558 /* If the L2 cache is configured, do nothing. */
559 if (!(bbl_cr_ctl3 & 1)) {
560 bbl_cr_ctl3 = 0x134052bLL;
562 /* Set L2 Cache Latency (Default: 5). */
563 #ifdef CPU_CELERON_L2_LATENCY
564 #if CPU_L2_LATENCY > 15
565 #error invalid CPU_L2_LATENCY.
567 bbl_cr_ctl3 |= CPU_L2_LATENCY << 1;
569 bbl_cr_ctl3 |= 5 << 1;
571 wrmsr(MSR_BBL_CR_CTL3, bbl_cr_ctl3);
574 load_cr0(rcr0() & ~(CR0_CD | CR0_NW));
575 intr_restore(saveintr);
576 #endif /* CPU_PPRO2CELERON */
580 * Initialize special VIA features
589 * Explicitly enable CX8 and PGE on C3.
591 * http://www.via.com.tw/download/mainboards/6/13/VIA_C3_EBGA%20datasheet110.pdf
593 if (CPUID_TO_MODEL(cpu_id) <= 9)
594 fcr = (1 << 1) | (1 << 7);
599 * Check extended CPUID for PadLock features.
601 * http://www.via.com.tw/en/downloads/whitepapers/initiatives/padlock/programming_guide.pdf
603 do_cpuid(0xc0000000, regs);
604 if (regs[0] >= 0xc0000001) {
605 do_cpuid(0xc0000001, regs);
610 /* Enable RNG if present. */
611 if ((val & VIA_CPUID_HAS_RNG) != 0) {
612 via_feature_rng = VIA_HAS_RNG;
613 wrmsr(0x110B, rdmsr(0x110B) | VIA_CPUID_DO_RNG);
616 /* Enable PadLock if present. */
617 if ((val & VIA_CPUID_HAS_ACE) != 0)
618 via_feature_xcrypt |= VIA_HAS_AES;
619 if ((val & VIA_CPUID_HAS_ACE2) != 0)
620 via_feature_xcrypt |= VIA_HAS_AESCTR;
621 if ((val & VIA_CPUID_HAS_PHE) != 0)
622 via_feature_xcrypt |= VIA_HAS_SHA;
623 if ((val & VIA_CPUID_HAS_PMM) != 0)
624 via_feature_xcrypt |= VIA_HAS_MM;
625 if (via_feature_xcrypt != 0)
628 wrmsr(0x1107, rdmsr(0x1107) | fcr);
631 #endif /* I686_CPU */
633 #if defined(I586_CPU) || defined(I686_CPU)
639 /* Expose all hidden features. */
640 wrmsr(0x80860004, rdmsr(0x80860004) | ~0UL);
642 cpu_feature = regs[3];
646 extern int elf32_nxstack;
655 init_bluelightning();
666 #ifdef CPU_I486_ON_386
674 #endif /* I486_CPU */
677 switch (cpu_vendor_id) {
680 if (((cpu_id & 0x0f0) > 0) &&
681 ((cpu_id & 0x0f0) < 0x60) &&
682 ((cpu_id & 0x00f) > 3))
683 enable_K5_wt_alloc();
684 else if (((cpu_id & 0x0f0) > 0x80) ||
685 (((cpu_id & 0x0f0) == 0x80) &&
686 (cpu_id & 0x00f) > 0x07))
687 enable_K6_2_wt_alloc();
688 else if ((cpu_id & 0x0f0) > 0x50)
689 enable_K6_wt_alloc();
691 if ((cpu_id & 0xf0) == 0xa0)
693 * Make sure the TSC runs through
694 * suspension, otherwise we can't use
697 wrmsr(0x1900, rdmsr(0x1900) | 0x20ULL);
699 case CPU_VENDOR_CENTAUR:
702 case CPU_VENDOR_TRANSMETA:
705 case CPU_VENDOR_RISE:
716 switch (cpu_vendor_id) {
717 case CPU_VENDOR_INTEL:
718 switch (cpu_id & 0xff0) {
727 #ifdef CPU_ATHLON_SSE_HACK
730 * Sometimes the BIOS doesn't enable SSE instructions.
731 * According to AMD document 20734, the mobile
732 * Duron, the (mobile) Athlon 4 and the Athlon MP
733 * support SSE. These correspond to cpu_id 0x66X
736 if ((cpu_feature & CPUID_XMM) == 0 &&
737 ((cpu_id & ~0xf) == 0x660 ||
738 (cpu_id & ~0xf) == 0x670 ||
739 (cpu_id & ~0xf) == 0x680)) {
741 wrmsr(MSR_HWCR, rdmsr(MSR_HWCR) & ~0x08000);
743 cpu_feature = regs[3];
747 case CPU_VENDOR_CENTAUR:
750 case CPU_VENDOR_TRANSMETA:
759 if ((cpu_feature & CPUID_XMM) && (cpu_feature & CPUID_FXSR)) {
760 load_cr4(rcr4() | CR4_FXSR | CR4_XMM);
761 cpu_fxsr = hw_instruction_sse = 1;
763 #if defined(PAE) || defined(PAE_TABLES)
764 if ((amd_feature & AMDID_NX) != 0) {
767 msr = rdmsr(MSR_EFER) | EFER_NXE;
768 wrmsr(MSR_EFER, msr);
776 initializecpucache(void)
780 * CPUID with %eax = 1, %ebx returns
781 * Bits 15-8: CLFLUSH line size
782 * (Value * 8 = cache line size in bytes)
784 if ((cpu_feature & CPUID_CLFSH) != 0)
785 cpu_clflush_line_size = ((cpu_procinfo >> 8) & 0xff) * 8;
787 * XXXKIB: (temporary) hack to work around traps generated
788 * when CLFLUSHing APIC register window under virtualization
789 * environments. These environments tend to disable the
790 * CPUID_SS feature even though the native CPU supports it.
792 TUNABLE_INT_FETCH("hw.clflush_disable", &hw_clflush_disable);
793 if (vm_guest != VM_GUEST_NO && hw_clflush_disable == -1) {
794 cpu_feature &= ~CPUID_CLFSH;
795 cpu_stdext_feature &= ~CPUID_STDEXT_CLFLUSHOPT;
798 * The kernel's use of CLFLUSH{,OPT} can be disabled manually
799 * by setting the hw.clflush_disable tunable.
801 if (hw_clflush_disable == 1) {
802 cpu_feature &= ~CPUID_CLFSH;
803 cpu_stdext_feature &= ~CPUID_STDEXT_CLFLUSHOPT;
806 #if defined(PC98) && !defined(CPU_UPGRADE_HW_CACHE)
808 * OS should flush L1 cache by itself because no PC-98 supports
809 * non-Intel CPUs. Use wbinvd instruction before DMA transfer
810 * when need_pre_dma_flush = 1, use invd instruction after DMA
811 * transfer when need_post_dma_flush = 1. If your CPU upgrade
812 * product supports hardware cache control, you can add the
813 * CPU_UPGRADE_HW_CACHE option in your kernel configuration file.
814 * This option eliminates unneeded cache flush instruction(s).
816 if (cpu_vendor_id == CPU_VENDOR_CYRIX) {
820 need_post_dma_flush = 1;
823 need_pre_dma_flush = 1;
826 need_pre_dma_flush = 1;
827 #ifdef CPU_I486_ON_386
828 need_post_dma_flush = 1;
835 } else if (cpu_vendor_id == CPU_VENDOR_AMD) {
836 switch (cpu_id & 0xFF0) {
837 case 0x470: /* Enhanced Am486DX2 WB */
838 case 0x490: /* Enhanced Am486DX4 WB */
839 case 0x4F0: /* Am5x86 WB */
840 need_pre_dma_flush = 1;
843 } else if (cpu_vendor_id == CPU_VENDOR_IBM) {
844 need_post_dma_flush = 1;
846 #ifdef CPU_I486_ON_386
847 need_pre_dma_flush = 1;
850 #endif /* PC98 && !CPU_UPGRADE_HW_CACHE */
853 #if defined(I586_CPU) && defined(CPU_WT_ALLOC)
855 * Enable write allocate feature of AMD processors.
856 * Following two functions require the Maxmem variable being set.
859 enable_K5_wt_alloc(void)
865 * Write allocate is supported only on models 1, 2, and 3, with
866 * a stepping of 4 or greater.
868 if (((cpu_id & 0xf0) > 0) && ((cpu_id & 0x0f) > 3)) {
869 saveintr = intr_disable();
870 msr = rdmsr(0x83); /* HWCR */
871 wrmsr(0x83, msr & !(0x10));
874 * We have to tell the chip where the top of memory is,
875 * since video cards could have frame bufferes there,
876 * memory-mapped I/O could be there, etc.
882 msr |= AMD_WT_ALLOC_TME | AMD_WT_ALLOC_FRE;
884 if (!(inb(0x43b) & 4)) {
885 wrmsr(0x86, 0x0ff00f0);
886 msr |= AMD_WT_ALLOC_PRE;
890 * There is no way to know wheter 15-16M hole exists or not.
891 * Therefore, we disable write allocate for this range.
893 wrmsr(0x86, 0x0ff00f0);
894 msr |= AMD_WT_ALLOC_PRE;
899 wrmsr(0x83, msr|0x10); /* enable write allocate */
900 intr_restore(saveintr);
905 enable_K6_wt_alloc(void)
911 saveintr = intr_disable();
914 #ifdef CPU_DISABLE_CACHE
916 * Certain K6-2 box becomes unstable when write allocation is
920 * The AMD-K6 processer provides the 64-bit Test Register 12(TR12),
921 * but only the Cache Inhibit(CI) (bit 3 of TR12) is suppported.
922 * All other bits in TR12 have no effect on the processer's operation.
923 * The I/O Trap Restart function (bit 9 of TR12) is always enabled
926 wrmsr(0x0000000e, (u_int64_t)0x0008);
928 /* Don't assume that memory size is aligned with 4M. */
930 size = ((Maxmem >> 8) + 3) >> 2;
934 /* Limit is 508M bytes. */
937 whcr = (rdmsr(0xc0000082) & ~(0x7fLL << 1)) | (size << 1);
939 #if defined(PC98) || defined(NO_MEMORY_HOLE)
940 if (whcr & (0x7fLL << 1)) {
943 * If bit 2 of port 0x43b is 0, disable wrte allocate for the
946 if (!(inb(0x43b) & 4))
954 * There is no way to know wheter 15-16M hole exists or not.
955 * Therefore, we disable write allocate for this range.
959 wrmsr(0x0c0000082, whcr);
961 intr_restore(saveintr);
965 enable_K6_2_wt_alloc(void)
971 saveintr = intr_disable();
974 #ifdef CPU_DISABLE_CACHE
976 * Certain K6-2 box becomes unstable when write allocation is
980 * The AMD-K6 processer provides the 64-bit Test Register 12(TR12),
981 * but only the Cache Inhibit(CI) (bit 3 of TR12) is suppported.
982 * All other bits in TR12 have no effect on the processer's operation.
983 * The I/O Trap Restart function (bit 9 of TR12) is always enabled
986 wrmsr(0x0000000e, (u_int64_t)0x0008);
988 /* Don't assume that memory size is aligned with 4M. */
990 size = ((Maxmem >> 8) + 3) >> 2;
994 /* Limit is 4092M bytes. */
997 whcr = (rdmsr(0xc0000082) & ~(0x3ffLL << 22)) | (size << 22);
999 #if defined(PC98) || defined(NO_MEMORY_HOLE)
1000 if (whcr & (0x3ffLL << 22)) {
1003 * If bit 2 of port 0x43b is 0, disable wrte allocate for the
1006 if (!(inb(0x43b) & 4))
1007 whcr &= ~(1LL << 16);
1014 * There is no way to know wheter 15-16M hole exists or not.
1015 * Therefore, we disable write allocate for this range.
1017 whcr &= ~(1LL << 16);
1019 wrmsr(0x0c0000082, whcr);
1021 intr_restore(saveintr);
1023 #endif /* I585_CPU && CPU_WT_ALLOC */
1025 #include "opt_ddb.h"
1027 #include <ddb/ddb.h>
1029 DB_SHOW_COMMAND(cyrixreg, cyrixreg)
1031 register_t saveintr;
1033 u_char ccr1, ccr2, ccr3;
1034 u_char ccr0 = 0, ccr4 = 0, ccr5 = 0, pcr0 = 0;
1037 if (cpu_vendor_id == CPU_VENDOR_CYRIX) {
1038 saveintr = intr_disable();
1041 if ((cpu != CPU_M1SC) && (cpu != CPU_CY486DX)) {
1042 ccr0 = read_cyrix_reg(CCR0);
1044 ccr1 = read_cyrix_reg(CCR1);
1045 ccr2 = read_cyrix_reg(CCR2);
1046 ccr3 = read_cyrix_reg(CCR3);
1047 if ((cpu == CPU_M1SC) || (cpu == CPU_M1) || (cpu == CPU_M2)) {
1048 write_cyrix_reg(CCR3, CCR3_MAPEN0);
1049 ccr4 = read_cyrix_reg(CCR4);
1050 if ((cpu == CPU_M1) || (cpu == CPU_M2))
1051 ccr5 = read_cyrix_reg(CCR5);
1053 pcr0 = read_cyrix_reg(PCR0);
1054 write_cyrix_reg(CCR3, ccr3); /* Restore CCR3. */
1056 intr_restore(saveintr);
1058 if ((cpu != CPU_M1SC) && (cpu != CPU_CY486DX))
1059 printf("CCR0=%x, ", (u_int)ccr0);
1061 printf("CCR1=%x, CCR2=%x, CCR3=%x",
1062 (u_int)ccr1, (u_int)ccr2, (u_int)ccr3);
1063 if ((cpu == CPU_M1SC) || (cpu == CPU_M1) || (cpu == CPU_M2)) {
1064 printf(", CCR4=%x, ", (u_int)ccr4);
1065 if (cpu == CPU_M1SC)
1066 printf("PCR0=%x\n", pcr0);
1068 printf("CCR5=%x\n", ccr5);
1071 printf("CR0=%x\n", cr0);