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
51 #if defined(I586_CPU) && defined(CPU_WT_ALLOC)
52 void enable_K5_wt_alloc(void);
53 void enable_K6_wt_alloc(void);
54 void enable_K6_2_wt_alloc(void);
58 static void init_5x86(void);
59 static void init_bluelightning(void);
60 static void init_486dlc(void);
61 static void init_cy486dx(void);
62 #ifdef CPU_I486_ON_386
63 static void init_i486_on_386(void);
65 static void init_6x86(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 /* Must *NOT* be BSS or locore will bzero these after setting them */
85 int cpu = 0; /* Are we 386, 386sx, 486, etc? */
86 u_int cpu_feature = 0; /* Feature flags */
87 u_int cpu_feature2 = 0; /* Feature flags */
88 u_int amd_feature = 0; /* AMD feature flags */
89 u_int amd_feature2 = 0; /* AMD feature flags */
90 u_int amd_pminfo = 0; /* AMD advanced power management info */
91 u_int via_feature_rng = 0; /* VIA RNG features */
92 u_int via_feature_xcrypt = 0; /* VIA ACE features */
93 u_int cpu_high = 0; /* Highest arg to CPUID */
94 u_int cpu_id = 0; /* Stepping ID */
95 u_int cpu_procinfo = 0; /* HyperThreading Info / Brand Index / CLFUSH */
96 u_int cpu_procinfo2 = 0; /* Multicore info */
97 char cpu_vendor[20] = ""; /* CPU Origin code */
98 u_int cpu_vendor_id = 0; /* CPU vendor ID */
99 u_int cpu_clflush_line_size = 32;
100 u_int cpu_mon_mwait_flags; /* MONITOR/MWAIT flags (CPUID.05H.ECX) */
101 u_int cpu_mon_min_size; /* MONITOR minimum range size, bytes */
102 u_int cpu_mon_max_size; /* MONITOR minimum range size, bytes */
104 SYSCTL_UINT(_hw, OID_AUTO, via_feature_rng, CTLFLAG_RD,
105 &via_feature_rng, 0, "VIA RNG feature available in CPU");
106 SYSCTL_UINT(_hw, OID_AUTO, via_feature_xcrypt, CTLFLAG_RD,
107 &via_feature_xcrypt, 0, "VIA xcrypt feature available in CPU");
109 #ifdef CPU_ENABLE_SSE
110 u_int cpu_fxsr; /* SSE enabled */
111 u_int cpu_mxcsr_mask; /* valid bits in mxcsr */
119 init_bluelightning(void)
123 #if defined(PC98) && !defined(CPU_UPGRADE_HW_CACHE)
124 need_post_dma_flush = 1;
127 saveintr = intr_disable();
129 load_cr0(rcr0() | CR0_CD | CR0_NW);
132 #ifdef CPU_BLUELIGHTNING_FPU_OP_CACHE
133 wrmsr(0x1000, 0x9c92LL); /* FP operand can be cacheable on Cyrix FPU */
135 wrmsr(0x1000, 0x1c92LL); /* Intel FPU */
137 /* Enables 13MB and 0-640KB cache. */
138 wrmsr(0x1001, (0xd0LL << 32) | 0x3ff);
139 #ifdef CPU_BLUELIGHTNING_3X
140 wrmsr(0x1002, 0x04000000LL); /* Enables triple-clock mode. */
142 wrmsr(0x1002, 0x03000000LL); /* Enables double-clock mode. */
145 /* Enable caching in CR0. */
146 load_cr0(rcr0() & ~(CR0_CD | CR0_NW)); /* CD = 0 and NW = 0 */
148 intr_restore(saveintr);
152 * Cyrix 486SLC/DLC/SR/DR series
160 saveintr = intr_disable();
163 ccr0 = read_cyrix_reg(CCR0);
164 #ifndef CYRIX_CACHE_WORKS
165 ccr0 |= CCR0_NC1 | CCR0_BARB;
166 write_cyrix_reg(CCR0, ccr0);
170 #ifndef CYRIX_CACHE_REALLY_WORKS
171 ccr0 |= CCR0_NC1 | CCR0_BARB;
175 #ifdef CPU_DIRECT_MAPPED_CACHE
176 ccr0 |= CCR0_CO; /* Direct mapped mode. */
178 write_cyrix_reg(CCR0, ccr0);
180 /* Clear non-cacheable region. */
181 write_cyrix_reg(NCR1+2, NCR_SIZE_0K);
182 write_cyrix_reg(NCR2+2, NCR_SIZE_0K);
183 write_cyrix_reg(NCR3+2, NCR_SIZE_0K);
184 write_cyrix_reg(NCR4+2, NCR_SIZE_0K);
186 write_cyrix_reg(0, 0); /* dummy write */
188 /* Enable caching in CR0. */
189 load_cr0(rcr0() & ~(CR0_CD | CR0_NW)); /* CD = 0 and NW = 0 */
191 #endif /* !CYRIX_CACHE_WORKS */
192 intr_restore(saveintr);
197 * Cyrix 486S/DX series
205 saveintr = intr_disable();
208 ccr2 = read_cyrix_reg(CCR2);
210 ccr2 |= CCR2_SUSP_HLT;
214 /* Enables WB cache interface pin and Lock NW bit in CR0. */
215 ccr2 |= CCR2_WB | CCR2_LOCK_NW;
216 /* Unlock NW bit in CR0. */
217 write_cyrix_reg(CCR2, ccr2 & ~CCR2_LOCK_NW);
218 load_cr0((rcr0() & ~CR0_CD) | CR0_NW); /* CD = 0, NW = 1 */
221 write_cyrix_reg(CCR2, ccr2);
222 intr_restore(saveintr);
233 u_char ccr2, ccr3, ccr4, pcr0;
235 saveintr = intr_disable();
237 load_cr0(rcr0() | CR0_CD | CR0_NW);
240 (void)read_cyrix_reg(CCR3); /* dummy */
242 /* Initialize CCR2. */
243 ccr2 = read_cyrix_reg(CCR2);
246 ccr2 |= CCR2_SUSP_HLT;
248 ccr2 &= ~CCR2_SUSP_HLT;
251 write_cyrix_reg(CCR2, ccr2);
253 /* Initialize CCR4. */
254 ccr3 = read_cyrix_reg(CCR3);
255 write_cyrix_reg(CCR3, CCR3_MAPEN0);
257 ccr4 = read_cyrix_reg(CCR4);
260 #ifdef CPU_FASTER_5X86_FPU
261 ccr4 |= CCR4_FASTFPE;
263 ccr4 &= ~CCR4_FASTFPE;
265 ccr4 &= ~CCR4_IOMASK;
266 /********************************************************************
267 * WARNING: The "BIOS Writers Guide" mentions that I/O recovery time
268 * should be 0 for errata fix.
269 ********************************************************************/
271 ccr4 |= CPU_IORT & CCR4_IOMASK;
273 write_cyrix_reg(CCR4, ccr4);
275 /* Initialize PCR0. */
276 /****************************************************************
277 * WARNING: RSTK_EN and LOOP_EN could make your system unstable.
278 * BTB_EN might make your system unstable.
279 ****************************************************************/
280 pcr0 = read_cyrix_reg(PCR0);
297 /****************************************************************
298 * WARNING: if you use a memory mapped I/O device, don't use
299 * DISABLE_5X86_LSSER option, which may reorder memory mapped
301 * IF YOUR MOTHERBOARD HAS PCI BUS, DON'T DISABLE LSSER.
302 ****************************************************************/
303 #ifdef CPU_DISABLE_5X86_LSSER
308 write_cyrix_reg(PCR0, pcr0);
311 write_cyrix_reg(CCR3, ccr3);
313 (void)read_cyrix_reg(0x80); /* dummy */
315 /* Unlock NW bit in CR0. */
316 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) & ~CCR2_LOCK_NW);
317 load_cr0((rcr0() & ~CR0_CD) | CR0_NW); /* CD = 0, NW = 1 */
318 /* Lock NW bit in CR0. */
319 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) | CCR2_LOCK_NW);
321 intr_restore(saveintr);
324 #ifdef CPU_I486_ON_386
326 * There are i486 based upgrade products for i386 machines.
327 * In this case, BIOS doesn't enable CPU cache.
330 init_i486_on_386(void)
334 #if defined(PC98) && !defined(CPU_UPGRADE_HW_CACHE)
335 need_post_dma_flush = 1;
338 saveintr = intr_disable();
340 load_cr0(rcr0() & ~(CR0_CD | CR0_NW)); /* CD = 0, NW = 0 */
342 intr_restore(saveintr);
349 * XXX - What should I do here? Please let me know.
357 saveintr = intr_disable();
359 load_cr0(rcr0() | CR0_CD | CR0_NW);
362 /* Initialize CCR0. */
363 write_cyrix_reg(CCR0, read_cyrix_reg(CCR0) | CCR0_NC1);
365 /* Initialize CCR1. */
366 #ifdef CPU_CYRIX_NO_LOCK
367 write_cyrix_reg(CCR1, read_cyrix_reg(CCR1) | CCR1_NO_LOCK);
369 write_cyrix_reg(CCR1, read_cyrix_reg(CCR1) & ~CCR1_NO_LOCK);
372 /* Initialize CCR2. */
374 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) | CCR2_SUSP_HLT);
376 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) & ~CCR2_SUSP_HLT);
379 ccr3 = read_cyrix_reg(CCR3);
380 write_cyrix_reg(CCR3, CCR3_MAPEN0);
382 /* Initialize CCR4. */
383 ccr4 = read_cyrix_reg(CCR4);
385 ccr4 &= ~CCR4_IOMASK;
387 write_cyrix_reg(CCR4, ccr4 | (CPU_IORT & CCR4_IOMASK));
389 write_cyrix_reg(CCR4, ccr4 | 7);
392 /* Initialize CCR5. */
394 write_cyrix_reg(CCR5, read_cyrix_reg(CCR5) | CCR5_WT_ALLOC);
398 write_cyrix_reg(CCR3, ccr3);
400 /* Unlock NW bit in CR0. */
401 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) & ~CCR2_LOCK_NW);
404 * Earlier revision of the 6x86 CPU could crash the system if
405 * L1 cache is in write-back mode.
407 if ((cyrix_did & 0xff00) > 0x1600)
408 load_cr0(rcr0() & ~(CR0_CD | CR0_NW)); /* CD = 0 and NW = 0 */
410 /* Revision 2.6 and lower. */
411 #ifdef CYRIX_CACHE_REALLY_WORKS
412 load_cr0(rcr0() & ~(CR0_CD | CR0_NW)); /* CD = 0 and NW = 0 */
414 load_cr0((rcr0() & ~CR0_CD) | CR0_NW); /* CD = 0 and NW = 1 */
418 /* Lock NW bit in CR0. */
419 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) | CCR2_LOCK_NW);
421 intr_restore(saveintr);
423 #endif /* I486_CPU */
427 * IDT WinChip C6/2/2A/2B/3
429 * http://www.centtech.com/winchip_bios_writers_guide_v4_0.pdf
440 * Set ECX8, DSMC, DTLOCK/EDCTLB, EMMX, and ERETSTK and clear DPDC.
442 fcr |= (1 << 1) | (1 << 7) | (1 << 8) | (1 << 9) | (1 << 16);
443 fcr &= ~(1ULL << 11);
446 * Additioanlly, set EBRPRED, E2MMX and EAMD3D for WinChip 2 and 3.
448 if (CPUID_TO_MODEL(cpu_id) >= 8)
449 fcr |= (1 << 12) | (1 << 19) | (1 << 20);
453 cpu_feature = regs[3];
459 * Cyrix 6x86MX (code-named M2)
461 * XXX - What should I do here? Please let me know.
469 saveintr = intr_disable();
471 load_cr0(rcr0() | CR0_CD | CR0_NW);
474 /* Initialize CCR0. */
475 write_cyrix_reg(CCR0, read_cyrix_reg(CCR0) | CCR0_NC1);
477 /* Initialize CCR1. */
478 #ifdef CPU_CYRIX_NO_LOCK
479 write_cyrix_reg(CCR1, read_cyrix_reg(CCR1) | CCR1_NO_LOCK);
481 write_cyrix_reg(CCR1, read_cyrix_reg(CCR1) & ~CCR1_NO_LOCK);
484 /* Initialize CCR2. */
486 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) | CCR2_SUSP_HLT);
488 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) & ~CCR2_SUSP_HLT);
491 ccr3 = read_cyrix_reg(CCR3);
492 write_cyrix_reg(CCR3, CCR3_MAPEN0);
494 /* Initialize CCR4. */
495 ccr4 = read_cyrix_reg(CCR4);
496 ccr4 &= ~CCR4_IOMASK;
498 write_cyrix_reg(CCR4, ccr4 | (CPU_IORT & CCR4_IOMASK));
500 write_cyrix_reg(CCR4, ccr4 | 7);
503 /* Initialize CCR5. */
505 write_cyrix_reg(CCR5, read_cyrix_reg(CCR5) | CCR5_WT_ALLOC);
509 write_cyrix_reg(CCR3, ccr3);
511 /* Unlock NW bit in CR0. */
512 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) & ~CCR2_LOCK_NW);
514 load_cr0(rcr0() & ~(CR0_CD | CR0_NW)); /* CD = 0 and NW = 0 */
516 /* Lock NW bit in CR0. */
517 write_cyrix_reg(CCR2, read_cyrix_reg(CCR2) | CCR2_LOCK_NW);
519 intr_restore(saveintr);
528 * Local APIC should be disabled if it is not going to be used.
530 apicbase = rdmsr(MSR_APICBASE);
531 apicbase &= ~APICBASE_ENABLED;
532 wrmsr(MSR_APICBASE, apicbase);
536 * Initialize BBL_CR_CTL3 (Control register 3: used to configure the
542 #ifdef CPU_PPRO2CELERON
544 u_int64_t bbl_cr_ctl3;
546 saveintr = intr_disable();
548 load_cr0(rcr0() | CR0_CD | CR0_NW);
551 bbl_cr_ctl3 = rdmsr(MSR_BBL_CR_CTL3);
553 /* If the L2 cache is configured, do nothing. */
554 if (!(bbl_cr_ctl3 & 1)) {
555 bbl_cr_ctl3 = 0x134052bLL;
557 /* Set L2 Cache Latency (Default: 5). */
558 #ifdef CPU_CELERON_L2_LATENCY
559 #if CPU_L2_LATENCY > 15
560 #error invalid CPU_L2_LATENCY.
562 bbl_cr_ctl3 |= CPU_L2_LATENCY << 1;
564 bbl_cr_ctl3 |= 5 << 1;
566 wrmsr(MSR_BBL_CR_CTL3, bbl_cr_ctl3);
569 load_cr0(rcr0() & ~(CR0_CD | CR0_NW));
570 intr_restore(saveintr);
571 #endif /* CPU_PPRO2CELERON */
575 * Initialize special VIA features
584 * Explicitly enable CX8 and PGE on C3.
586 * http://www.via.com.tw/download/mainboards/6/13/VIA_C3_EBGA%20datasheet110.pdf
588 if (CPUID_TO_MODEL(cpu_id) <= 9)
589 fcr = (1 << 1) | (1 << 7);
594 * Check extended CPUID for PadLock features.
596 * http://www.via.com.tw/en/downloads/whitepapers/initiatives/padlock/programming_guide.pdf
598 do_cpuid(0xc0000000, regs);
599 if (regs[0] >= 0xc0000001) {
600 do_cpuid(0xc0000001, regs);
605 /* Enable RNG if present. */
606 if ((val & VIA_CPUID_HAS_RNG) != 0) {
607 via_feature_rng = VIA_HAS_RNG;
608 wrmsr(0x110B, rdmsr(0x110B) | VIA_CPUID_DO_RNG);
611 /* Enable PadLock if present. */
612 if ((val & VIA_CPUID_HAS_ACE) != 0)
613 via_feature_xcrypt |= VIA_HAS_AES;
614 if ((val & VIA_CPUID_HAS_ACE2) != 0)
615 via_feature_xcrypt |= VIA_HAS_AESCTR;
616 if ((val & VIA_CPUID_HAS_PHE) != 0)
617 via_feature_xcrypt |= VIA_HAS_SHA;
618 if ((val & VIA_CPUID_HAS_PMM) != 0)
619 via_feature_xcrypt |= VIA_HAS_MM;
620 if (via_feature_xcrypt != 0)
623 wrmsr(0x1107, rdmsr(0x1107) | fcr);
626 #endif /* I686_CPU */
628 #if defined(I586_CPU) || defined(I686_CPU)
634 /* Expose all hidden features. */
635 wrmsr(0x80860004, rdmsr(0x80860004) | ~0UL);
637 cpu_feature = regs[3];
642 * Initialize CR4 (Control register 4) to enable SSE instructions.
647 #if defined(CPU_ENABLE_SSE)
648 if ((cpu_feature & CPUID_XMM) && (cpu_feature & CPUID_FXSR)) {
649 load_cr4(rcr4() | CR4_FXSR | CR4_XMM);
650 cpu_fxsr = hw_instruction_sse = 1;
655 extern int elf32_nxstack;
664 init_bluelightning();
675 #ifdef CPU_I486_ON_386
683 #endif /* I486_CPU */
686 switch (cpu_vendor_id) {
687 case CPU_VENDOR_CENTAUR:
690 case CPU_VENDOR_TRANSMETA:
701 switch (cpu_vendor_id) {
702 case CPU_VENDOR_INTEL:
703 switch (cpu_id & 0xff0) {
712 #ifdef CPU_ATHLON_SSE_HACK
715 * Sometimes the BIOS doesn't enable SSE instructions.
716 * According to AMD document 20734, the mobile
717 * Duron, the (mobile) Athlon 4 and the Athlon MP
718 * support SSE. These correspond to cpu_id 0x66X
721 if ((cpu_feature & CPUID_XMM) == 0 &&
722 ((cpu_id & ~0xf) == 0x660 ||
723 (cpu_id & ~0xf) == 0x670 ||
724 (cpu_id & ~0xf) == 0x680)) {
726 wrmsr(MSR_HWCR, rdmsr(MSR_HWCR) & ~0x08000);
728 cpu_feature = regs[3];
732 case CPU_VENDOR_CENTAUR:
735 case CPU_VENDOR_TRANSMETA:
740 if ((amd_feature & AMDID_NX) != 0) {
743 msr = rdmsr(MSR_EFER) | EFER_NXE;
744 wrmsr(MSR_EFER, msr);
757 * CPUID with %eax = 1, %ebx returns
758 * Bits 15-8: CLFLUSH line size
759 * (Value * 8 = cache line size in bytes)
761 if ((cpu_feature & CPUID_CLFSH) != 0)
762 cpu_clflush_line_size = ((cpu_procinfo >> 8) & 0xff) * 8;
764 * XXXKIB: (temporary) hack to work around traps generated
765 * when CLFLUSHing APIC register window under virtualization
766 * environments. These environments tend to disable the
767 * CPUID_SS feature even though the native CPU supports it.
769 TUNABLE_INT_FETCH("hw.clflush_disable", &hw_clflush_disable);
770 if (vm_guest != VM_GUEST_NO && hw_clflush_disable == -1)
771 cpu_feature &= ~CPUID_CLFSH;
773 * Allow to disable CLFLUSH feature manually by
774 * hw.clflush_disable tunable.
776 if (hw_clflush_disable == 1)
777 cpu_feature &= ~CPUID_CLFSH;
779 #if defined(PC98) && !defined(CPU_UPGRADE_HW_CACHE)
781 * OS should flush L1 cache by itself because no PC-98 supports
782 * non-Intel CPUs. Use wbinvd instruction before DMA transfer
783 * when need_pre_dma_flush = 1, use invd instruction after DMA
784 * transfer when need_post_dma_flush = 1. If your CPU upgrade
785 * product supports hardware cache control, you can add the
786 * CPU_UPGRADE_HW_CACHE option in your kernel configuration file.
787 * This option eliminates unneeded cache flush instruction(s).
789 if (cpu_vendor_id == CPU_VENDOR_CYRIX) {
793 need_post_dma_flush = 1;
796 need_pre_dma_flush = 1;
799 need_pre_dma_flush = 1;
800 #ifdef CPU_I486_ON_386
801 need_post_dma_flush = 1;
808 } else if (cpu_vendor_id == CPU_VENDOR_AMD) {
809 switch (cpu_id & 0xFF0) {
810 case 0x470: /* Enhanced Am486DX2 WB */
811 case 0x490: /* Enhanced Am486DX4 WB */
812 case 0x4F0: /* Am5x86 WB */
813 need_pre_dma_flush = 1;
816 } else if (cpu_vendor_id == CPU_VENDOR_IBM) {
817 need_post_dma_flush = 1;
819 #ifdef CPU_I486_ON_386
820 need_pre_dma_flush = 1;
823 #endif /* PC98 && !CPU_UPGRADE_HW_CACHE */
826 #if defined(I586_CPU) && defined(CPU_WT_ALLOC)
828 * Enable write allocate feature of AMD processors.
829 * Following two functions require the Maxmem variable being set.
832 enable_K5_wt_alloc(void)
838 * Write allocate is supported only on models 1, 2, and 3, with
839 * a stepping of 4 or greater.
841 if (((cpu_id & 0xf0) > 0) && ((cpu_id & 0x0f) > 3)) {
842 saveintr = intr_disable();
843 msr = rdmsr(0x83); /* HWCR */
844 wrmsr(0x83, msr & !(0x10));
847 * We have to tell the chip where the top of memory is,
848 * since video cards could have frame bufferes there,
849 * memory-mapped I/O could be there, etc.
855 msr |= AMD_WT_ALLOC_TME | AMD_WT_ALLOC_FRE;
857 if (!(inb(0x43b) & 4)) {
858 wrmsr(0x86, 0x0ff00f0);
859 msr |= AMD_WT_ALLOC_PRE;
863 * There is no way to know wheter 15-16M hole exists or not.
864 * Therefore, we disable write allocate for this range.
866 wrmsr(0x86, 0x0ff00f0);
867 msr |= AMD_WT_ALLOC_PRE;
872 wrmsr(0x83, msr|0x10); /* enable write allocate */
873 intr_restore(saveintr);
878 enable_K6_wt_alloc(void)
884 saveintr = intr_disable();
887 #ifdef CPU_DISABLE_CACHE
889 * Certain K6-2 box becomes unstable when write allocation is
893 * The AMD-K6 processer provides the 64-bit Test Register 12(TR12),
894 * but only the Cache Inhibit(CI) (bit 3 of TR12) is suppported.
895 * All other bits in TR12 have no effect on the processer's operation.
896 * The I/O Trap Restart function (bit 9 of TR12) is always enabled
899 wrmsr(0x0000000e, (u_int64_t)0x0008);
901 /* Don't assume that memory size is aligned with 4M. */
903 size = ((Maxmem >> 8) + 3) >> 2;
907 /* Limit is 508M bytes. */
910 whcr = (rdmsr(0xc0000082) & ~(0x7fLL << 1)) | (size << 1);
912 #if defined(PC98) || defined(NO_MEMORY_HOLE)
913 if (whcr & (0x7fLL << 1)) {
916 * If bit 2 of port 0x43b is 0, disable wrte allocate for the
919 if (!(inb(0x43b) & 4))
927 * There is no way to know wheter 15-16M hole exists or not.
928 * Therefore, we disable write allocate for this range.
932 wrmsr(0x0c0000082, whcr);
934 intr_restore(saveintr);
938 enable_K6_2_wt_alloc(void)
944 saveintr = intr_disable();
947 #ifdef CPU_DISABLE_CACHE
949 * Certain K6-2 box becomes unstable when write allocation is
953 * The AMD-K6 processer provides the 64-bit Test Register 12(TR12),
954 * but only the Cache Inhibit(CI) (bit 3 of TR12) is suppported.
955 * All other bits in TR12 have no effect on the processer's operation.
956 * The I/O Trap Restart function (bit 9 of TR12) is always enabled
959 wrmsr(0x0000000e, (u_int64_t)0x0008);
961 /* Don't assume that memory size is aligned with 4M. */
963 size = ((Maxmem >> 8) + 3) >> 2;
967 /* Limit is 4092M bytes. */
970 whcr = (rdmsr(0xc0000082) & ~(0x3ffLL << 22)) | (size << 22);
972 #if defined(PC98) || defined(NO_MEMORY_HOLE)
973 if (whcr & (0x3ffLL << 22)) {
976 * If bit 2 of port 0x43b is 0, disable wrte allocate for the
979 if (!(inb(0x43b) & 4))
980 whcr &= ~(1LL << 16);
987 * There is no way to know wheter 15-16M hole exists or not.
988 * Therefore, we disable write allocate for this range.
990 whcr &= ~(1LL << 16);
992 wrmsr(0x0c0000082, whcr);
994 intr_restore(saveintr);
996 #endif /* I585_CPU && CPU_WT_ALLOC */
1000 #include <ddb/ddb.h>
1002 DB_SHOW_COMMAND(cyrixreg, cyrixreg)
1004 register_t saveintr;
1006 u_char ccr1, ccr2, ccr3;
1007 u_char ccr0 = 0, ccr4 = 0, ccr5 = 0, pcr0 = 0;
1010 if (cpu_vendor_id == CPU_VENDOR_CYRIX) {
1011 saveintr = intr_disable();
1014 if ((cpu != CPU_M1SC) && (cpu != CPU_CY486DX)) {
1015 ccr0 = read_cyrix_reg(CCR0);
1017 ccr1 = read_cyrix_reg(CCR1);
1018 ccr2 = read_cyrix_reg(CCR2);
1019 ccr3 = read_cyrix_reg(CCR3);
1020 if ((cpu == CPU_M1SC) || (cpu == CPU_M1) || (cpu == CPU_M2)) {
1021 write_cyrix_reg(CCR3, CCR3_MAPEN0);
1022 ccr4 = read_cyrix_reg(CCR4);
1023 if ((cpu == CPU_M1) || (cpu == CPU_M2))
1024 ccr5 = read_cyrix_reg(CCR5);
1026 pcr0 = read_cyrix_reg(PCR0);
1027 write_cyrix_reg(CCR3, ccr3); /* Restore CCR3. */
1029 intr_restore(saveintr);
1031 if ((cpu != CPU_M1SC) && (cpu != CPU_CY486DX))
1032 printf("CCR0=%x, ", (u_int)ccr0);
1034 printf("CCR1=%x, CCR2=%x, CCR3=%x",
1035 (u_int)ccr1, (u_int)ccr2, (u_int)ccr3);
1036 if ((cpu == CPU_M1SC) || (cpu == CPU_M1) || (cpu == CPU_M2)) {
1037 printf(", CCR4=%x, ", (u_int)ccr4);
1038 if (cpu == CPU_M1SC)
1039 printf("PCR0=%x\n", pcr0);
1041 printf("CCR5=%x\n", ccr5);
1044 printf("CR0=%x\n", cr0);