2 * Copyright (c) 1992 Terrence R. Lambert.
3 * Copyright (c) 1982, 1987, 1990 The Regents of the University of California.
4 * Copyright (c) 1997 KATO Takenori.
7 * This code is derived from software contributed to Berkeley by
10 * Redistribution and use in source and binary forms, with or without
11 * 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.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the University of
21 * California, Berkeley and its contributors.
22 * 4. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 * from: Id: machdep.c,v 1.193 1996/06/18 01:22:04 bde Exp
41 #include <sys/cdefs.h>
42 __FBSDID("$FreeBSD$");
46 #include <sys/param.h>
49 #include <sys/eventhandler.h>
50 #include <sys/systm.h>
51 #include <sys/kernel.h>
52 #include <sys/sysctl.h>
53 #include <sys/power.h>
55 #include <machine/asmacros.h>
56 #include <machine/clock.h>
57 #include <machine/cputypes.h>
58 #include <machine/intr_machdep.h>
59 #include <machine/md_var.h>
60 #include <machine/segments.h>
61 #include <machine/specialreg.h>
63 #define IDENTBLUE_CYRIX486 0
64 #define IDENTBLUE_IBMCPU 1
65 #define IDENTBLUE_CYRIXM2 2
67 /* XXX - should be in header file: */
68 void printcpuinfo(void);
69 void finishidentcpu(void);
70 void earlysetcpuclass(void);
71 #if defined(I586_CPU) && defined(CPU_WT_ALLOC)
72 void enable_K5_wt_alloc(void);
73 void enable_K6_wt_alloc(void);
74 void enable_K6_2_wt_alloc(void);
76 void panicifcpuunsupported(void);
78 static void identifycyrix(void);
79 static void init_exthigh(void);
80 static void print_AMD_info(void);
81 static void print_INTEL_info(void);
82 static void print_INTEL_TLB(u_int data);
83 static void print_AMD_assoc(int i);
84 static void print_transmeta_info(void);
85 static void print_via_padlock_info(void);
88 u_int cpu_exthigh; /* Highest arg to extended CPUID */
89 u_int cyrix_did; /* Device ID of Cyrix CPU */
90 char machine[] = MACHINE;
91 SYSCTL_STRING(_hw, HW_MACHINE, machine, CTLFLAG_RD,
92 machine, 0, "Machine class");
94 static char cpu_model[128];
95 SYSCTL_STRING(_hw, HW_MODEL, model, CTLFLAG_RD,
96 cpu_model, 0, "Machine model");
98 static int hw_clockrate;
99 SYSCTL_INT(_hw, OID_AUTO, clockrate, CTLFLAG_RD,
100 &hw_clockrate, 0, "CPU instruction clock rate");
102 static char cpu_brand[48];
104 #define MAX_BRAND_INDEX 8
106 static const char *cpu_brandtable[MAX_BRAND_INDEX + 1] = {
110 "Intel Pentium III Xeon",
122 { "Intel 80286", CPUCLASS_286 }, /* CPU_286 */
123 { "i386SX", CPUCLASS_386 }, /* CPU_386SX */
124 { "i386DX", CPUCLASS_386 }, /* CPU_386 */
125 { "i486SX", CPUCLASS_486 }, /* CPU_486SX */
126 { "i486DX", CPUCLASS_486 }, /* CPU_486 */
127 { "Pentium", CPUCLASS_586 }, /* CPU_586 */
128 { "Cyrix 486", CPUCLASS_486 }, /* CPU_486DLC */
129 { "Pentium Pro", CPUCLASS_686 }, /* CPU_686 */
130 { "Cyrix 5x86", CPUCLASS_486 }, /* CPU_M1SC */
131 { "Cyrix 6x86", CPUCLASS_486 }, /* CPU_M1 */
132 { "Blue Lightning", CPUCLASS_486 }, /* CPU_BLUE */
133 { "Cyrix 6x86MX", CPUCLASS_686 }, /* CPU_M2 */
134 { "NexGen 586", CPUCLASS_386 }, /* CPU_NX586 (XXX) */
135 { "Cyrix 486S/DX", CPUCLASS_486 }, /* CPU_CY486DX */
136 { "Pentium II", CPUCLASS_686 }, /* CPU_PII */
137 { "Pentium III", CPUCLASS_686 }, /* CPU_PIII */
138 { "Pentium 4", CPUCLASS_686 }, /* CPU_P4 */
144 #if defined(I586_CPU) && !defined(NO_F00F_HACK)
145 int has_f00f_bug = 0; /* Initialized so that it can be patched. */
156 (strcmp(cpu_vendor, "GenuineIntel") == 0 ||
157 strcmp(cpu_vendor, "AuthenticAMD") == 0 ||
158 strcmp(cpu_vendor, "GenuineTMx86") == 0 ||
159 strcmp(cpu_vendor, "TransmetaCPU") == 0 ||
160 strcmp(cpu_vendor, "CentaurHauls") == 0 ||
161 strcmp(cpu_vendor, "Geode by NSC") == 0)) {
162 do_cpuid(0x80000000, regs);
163 if (regs[0] >= 0x80000000)
164 cpu_exthigh = regs[0];
177 cpu_class = i386_cpus[cpu].cpu_class;
179 strncpy(cpu_model, i386_cpus[cpu].cpu_name, sizeof (cpu_model));
181 /* Check for extended CPUID information and a processor name. */
183 if (cpu_exthigh >= 0x80000004) {
185 for (i = 0x80000002; i < 0x80000005; i++) {
187 memcpy(brand, regs, sizeof(regs));
188 brand += sizeof(regs);
192 if (strcmp(cpu_vendor, "GenuineIntel") == 0) {
193 if ((cpu_id & 0xf00) > 0x300) {
199 switch (cpu_id & 0x3000) {
201 strcpy(cpu_model, "Overdrive ");
204 strcpy(cpu_model, "Dual ");
208 switch (cpu_id & 0xf00) {
210 strcat(cpu_model, "i486 ");
211 /* Check the particular flavor of 486 */
212 switch (cpu_id & 0xf0) {
215 strcat(cpu_model, "DX");
218 strcat(cpu_model, "SX");
221 strcat(cpu_model, "DX2");
224 strcat(cpu_model, "SL");
227 strcat(cpu_model, "SX2");
231 "DX2 Write-Back Enhanced");
234 strcat(cpu_model, "DX4");
239 /* Check the particular flavor of 586 */
240 strcat(cpu_model, "Pentium");
241 switch (cpu_id & 0xf0) {
243 strcat(cpu_model, " A-step");
246 strcat(cpu_model, "/P5");
249 strcat(cpu_model, "/P54C");
252 strcat(cpu_model, "/P54T Overdrive");
255 strcat(cpu_model, "/P55C");
258 strcat(cpu_model, "/P54C");
261 strcat(cpu_model, "/P55C (quarter-micron)");
267 #if defined(I586_CPU) && !defined(NO_F00F_HACK)
269 * XXX - If/when Intel fixes the bug, this
270 * should also check the version of the
271 * CPU, not just that it's a Pentium.
277 /* Check the particular flavor of 686 */
278 switch (cpu_id & 0xf0) {
280 strcat(cpu_model, "Pentium Pro A-step");
283 strcat(cpu_model, "Pentium Pro");
289 "Pentium II/Pentium II Xeon/Celeron");
297 "Pentium III/Pentium III Xeon/Celeron");
301 strcat(cpu_model, "Unknown 80686");
306 strcat(cpu_model, "Pentium 4");
308 model = (cpu_id & 0x0f0) >> 4;
309 if (model == 3 || model == 4 || model == 6) {
312 tmp = rdmsr(MSR_IA32_MISC_ENABLE);
313 wrmsr(MSR_IA32_MISC_ENABLE,
320 strcat(cpu_model, "unknown");
325 * If we didn't get a brand name from the extended
326 * CPUID, try to look it up in the brand table.
328 if (cpu_high > 0 && *cpu_brand == '\0') {
329 brand_index = cpu_procinfo & CPUID_BRAND_INDEX;
330 if (brand_index <= MAX_BRAND_INDEX &&
331 cpu_brandtable[brand_index] != NULL)
333 cpu_brandtable[brand_index]);
336 } else if (strcmp(cpu_vendor, "AuthenticAMD") == 0) {
338 * Values taken from AMD Processor Recognition
339 * http://www.amd.com/K6/k6docs/pdf/20734g.pdf
340 * (also describes ``Features'' encodings.
342 strcpy(cpu_model, "AMD ");
343 switch (cpu_id & 0xFF0) {
345 strcat(cpu_model, "Standard Am486DX");
348 strcat(cpu_model, "Enhanced Am486DX2 Write-Through");
351 strcat(cpu_model, "Enhanced Am486DX2 Write-Back");
354 strcat(cpu_model, "Enhanced Am486DX4/Am5x86 Write-Through");
357 strcat(cpu_model, "Enhanced Am486DX4/Am5x86 Write-Back");
360 strcat(cpu_model, "Am5x86 Write-Through");
363 strcat(cpu_model, "Am5x86 Write-Back");
366 strcat(cpu_model, "K5 model 0");
370 strcat(cpu_model, "K5 model 1");
373 strcat(cpu_model, "K5 PR166 (model 2)");
376 strcat(cpu_model, "K5 PR200 (model 3)");
379 strcat(cpu_model, "K6");
382 strcat(cpu_model, "K6 266 (model 1)");
385 strcat(cpu_model, "K6-2");
388 strcat(cpu_model, "K6-III");
391 strcat(cpu_model, "Geode LX");
393 * Make sure the TSC runs through suspension,
394 * otherwise we can't use it as timecounter
396 wrmsr(0x1900, rdmsr(0x1900) | 0x20ULL);
399 strcat(cpu_model, "Unknown");
402 #if defined(I586_CPU) && defined(CPU_WT_ALLOC)
403 if ((cpu_id & 0xf00) == 0x500) {
404 if (((cpu_id & 0x0f0) > 0)
405 && ((cpu_id & 0x0f0) < 0x60)
406 && ((cpu_id & 0x00f) > 3))
407 enable_K5_wt_alloc();
408 else if (((cpu_id & 0x0f0) > 0x80)
409 || (((cpu_id & 0x0f0) == 0x80)
410 && (cpu_id & 0x00f) > 0x07))
411 enable_K6_2_wt_alloc();
412 else if ((cpu_id & 0x0f0) > 0x50)
413 enable_K6_wt_alloc();
416 } else if (strcmp(cpu_vendor, "CyrixInstead") == 0) {
417 strcpy(cpu_model, "Cyrix ");
418 switch (cpu_id & 0xff0) {
420 strcat(cpu_model, "MediaGX");
423 strcat(cpu_model, "6x86");
426 cpu_class = CPUCLASS_586;
427 strcat(cpu_model, "GXm");
430 strcat(cpu_model, "6x86MX");
434 * Even though CPU supports the cpuid
435 * instruction, it can be disabled.
436 * Therefore, this routine supports all Cyrix
439 switch (cyrix_did & 0xf0) {
441 switch (cyrix_did & 0x0f) {
443 strcat(cpu_model, "486SLC");
446 strcat(cpu_model, "486DLC");
449 strcat(cpu_model, "486SLC2");
452 strcat(cpu_model, "486DLC2");
455 strcat(cpu_model, "486SRx");
458 strcat(cpu_model, "486DRx");
461 strcat(cpu_model, "486SRx2");
464 strcat(cpu_model, "486DRx2");
467 strcat(cpu_model, "486SRu");
470 strcat(cpu_model, "486DRu");
473 strcat(cpu_model, "486SRu2");
476 strcat(cpu_model, "486DRu2");
479 strcat(cpu_model, "Unknown");
484 switch (cyrix_did & 0x0f) {
486 strcat(cpu_model, "486S");
489 strcat(cpu_model, "486S2");
492 strcat(cpu_model, "486Se");
495 strcat(cpu_model, "486S2e");
498 strcat(cpu_model, "486DX");
501 strcat(cpu_model, "486DX2");
504 strcat(cpu_model, "486DX4");
507 strcat(cpu_model, "Unknown");
512 if ((cyrix_did & 0x0f) < 8)
513 strcat(cpu_model, "6x86"); /* Where did you get it? */
515 strcat(cpu_model, "5x86");
518 strcat(cpu_model, "6x86");
521 if ((cyrix_did & 0xf000) == 0x3000) {
522 cpu_class = CPUCLASS_586;
523 strcat(cpu_model, "GXm");
525 strcat(cpu_model, "MediaGX");
528 strcat(cpu_model, "6x86MX");
531 switch (cyrix_did & 0x0f) {
533 strcat(cpu_model, "Overdrive CPU");
536 strcpy(cpu_model, "Texas Instruments 486SXL");
539 strcat(cpu_model, "486SLC/DLC");
542 strcat(cpu_model, "Unknown");
547 strcat(cpu_model, "Unknown");
552 } else if (strcmp(cpu_vendor, "RiseRiseRise") == 0) {
553 strcpy(cpu_model, "Rise ");
554 switch (cpu_id & 0xff0) {
556 strcat(cpu_model, "mP6");
559 strcat(cpu_model, "Unknown");
561 } else if (strcmp(cpu_vendor, "CentaurHauls") == 0) {
562 switch (cpu_id & 0xff0) {
564 strcpy(cpu_model, "IDT WinChip C6");
568 strcpy(cpu_model, "IDT WinChip 2");
571 strcpy(cpu_model, "VIA C3 Samuel");
575 strcpy(cpu_model, "VIA C3 Ezra");
577 strcpy(cpu_model, "VIA C3 Samuel 2");
580 strcpy(cpu_model, "VIA C3 Ezra-T");
583 strcpy(cpu_model, "VIA C3 Nehemiah");
587 strcpy(cpu_model, "VIA C7 Esther");
590 strcpy(cpu_model, "VIA/IDT Unknown");
592 } else if (strcmp(cpu_vendor, "IBM") == 0) {
593 strcpy(cpu_model, "Blue Lightning CPU");
594 } else if (strcmp(cpu_vendor, "Geode by NSC") == 0) {
595 switch (cpu_id & 0xfff) {
597 strcpy(cpu_model, "Geode SC1100");
602 strcpy(cpu_model, "Geode/NSC unknown");
608 * Replace cpu_model with cpu_brand minus leading spaces if
612 while (*brand == ' ')
615 strcpy(cpu_model, brand);
617 printf("%s (", cpu_model);
625 #if defined(I486_CPU)
628 bzero_vector = i486_bzero;
631 #if defined(I586_CPU)
633 hw_clockrate = (tsc_freq + 5000) / 1000000;
634 printf("%jd.%02d-MHz ",
635 (intmax_t)(tsc_freq + 4999) / 1000000,
636 (u_int)((tsc_freq + 4999) / 10000) % 100);
640 #if defined(I686_CPU)
642 hw_clockrate = (tsc_freq + 5000) / 1000000;
643 printf("%jd.%02d-MHz ",
644 (intmax_t)(tsc_freq + 4999) / 1000000,
645 (u_int)((tsc_freq + 4999) / 10000) % 100);
650 printf("Unknown"); /* will panic below... */
652 printf("-class CPU)\n");
654 printf(" Origin = \"%s\"",cpu_vendor);
656 printf(" Id = 0x%x", cpu_id);
658 if (strcmp(cpu_vendor, "GenuineIntel") == 0 ||
659 strcmp(cpu_vendor, "AuthenticAMD") == 0 ||
660 strcmp(cpu_vendor, "GenuineTMx86") == 0 ||
661 strcmp(cpu_vendor, "TransmetaCPU") == 0 ||
662 strcmp(cpu_vendor, "RiseRiseRise") == 0 ||
663 strcmp(cpu_vendor, "CentaurHauls") == 0 ||
664 strcmp(cpu_vendor, "Geode by NSC") == 0 ||
665 ((strcmp(cpu_vendor, "CyrixInstead") == 0) &&
666 ((cpu_id & 0xf00) > 0x500))) {
667 printf(" Stepping = %u", cpu_id & 0xf);
668 if (strcmp(cpu_vendor, "CyrixInstead") == 0)
669 printf(" DIR=0x%04x", cyrix_did);
671 u_int cmp = 1, htt = 1;
674 * Here we should probably set up flags indicating
675 * whether or not various features are available.
676 * The interesting ones are probably VME, PSE, PAE,
677 * and PGE. The code already assumes without bothering
678 * to check that all CPUs >= Pentium have a TSC and
681 printf("\n Features=0x%b", cpu_feature,
683 "\001FPU" /* Integral FPU */
684 "\002VME" /* Extended VM86 mode support */
685 "\003DE" /* Debugging Extensions (CR4.DE) */
686 "\004PSE" /* 4MByte page tables */
687 "\005TSC" /* Timestamp counter */
688 "\006MSR" /* Machine specific registers */
689 "\007PAE" /* Physical address extension */
690 "\010MCE" /* Machine Check support */
691 "\011CX8" /* CMPEXCH8 instruction */
692 "\012APIC" /* SMP local APIC */
693 "\013oldMTRR" /* Previous implementation of MTRR */
694 "\014SEP" /* Fast System Call */
695 "\015MTRR" /* Memory Type Range Registers */
696 "\016PGE" /* PG_G (global bit) support */
697 "\017MCA" /* Machine Check Architecture */
698 "\020CMOV" /* CMOV instruction */
699 "\021PAT" /* Page attributes table */
700 "\022PSE36" /* 36 bit address space support */
701 "\023PN" /* Processor Serial number */
702 "\024CLFLUSH" /* Has the CLFLUSH instruction */
704 "\026DTS" /* Debug Trace Store */
705 "\027ACPI" /* ACPI support */
706 "\030MMX" /* MMX instructions */
707 "\031FXSR" /* FXSAVE/FXRSTOR */
708 "\032SSE" /* Streaming SIMD Extensions */
709 "\033SSE2" /* Streaming SIMD Extensions #2 */
710 "\034SS" /* Self snoop */
711 "\035HTT" /* Hyperthreading (see EBX bit 16-23) */
712 "\036TM" /* Thermal Monitor clock slowdown */
713 "\037IA64" /* CPU can execute IA64 instructions */
714 "\040PBE" /* Pending Break Enable */
717 if (cpu_feature2 != 0) {
718 printf("\n Features2=0x%b", cpu_feature2,
720 "\001SSE3" /* SSE3 */
722 "\003DTES64" /* 64-bit Debug Trace */
723 "\004MON" /* MONITOR/MWAIT Instructions */
724 "\005DS_CPL" /* CPL Qualified Debug Store */
725 "\006VMX" /* Virtual Machine Extensions */
726 "\007SMX" /* Safer Mode Extensions */
727 "\010EST" /* Enhanced SpeedStep */
728 "\011TM2" /* Thermal Monitor 2 */
729 "\012SSSE3" /* SSSE3 */
730 "\013CNXT-ID" /* L1 context ID available */
733 "\016CX16" /* CMPXCHG16B Instruction */
734 "\017xTPR" /* Send Task Priority Messages*/
735 "\020PDCM" /* Perf/Debug Capability MSR */
738 "\023DCA" /* Direct Cache Access */
741 "\026x2APIC" /* xAPIC Extensions */
756 * AMD64 Architecture Programmer's Manual Volume 3:
757 * General-Purpose and System Instructions
758 * http://www.amd.com/us-en/assets/content_type/white_papers_and_tech_docs/24594.pdf
760 * IA-32 Intel Architecture Software Developer's Manual,
761 * Volume 2A: Instruction Set Reference, A-M
762 * ftp://download.intel.com/design/Pentium4/manuals/25366617.pdf
764 if (amd_feature != 0) {
765 printf("\n AMD Features=0x%b", amd_feature,
767 "\001<s0>" /* Same */
768 "\002<s1>" /* Same */
769 "\003<s2>" /* Same */
770 "\004<s3>" /* Same */
771 "\005<s4>" /* Same */
772 "\006<s5>" /* Same */
773 "\007<s6>" /* Same */
774 "\010<s7>" /* Same */
775 "\011<s8>" /* Same */
776 "\012<s9>" /* Same */
777 "\013<b10>" /* Undefined */
778 "\014SYSCALL" /* Have SYSCALL/SYSRET */
779 "\015<s12>" /* Same */
780 "\016<s13>" /* Same */
781 "\017<s14>" /* Same */
782 "\020<s15>" /* Same */
783 "\021<s16>" /* Same */
784 "\022<s17>" /* Same */
785 "\023<b18>" /* Reserved, unknown */
786 "\024MP" /* Multiprocessor Capable */
787 "\025NX" /* Has EFER.NXE, NX */
788 "\026<b21>" /* Undefined */
789 "\027MMX+" /* AMD MMX Extensions */
790 "\030<s23>" /* Same */
791 "\031<s24>" /* Same */
792 "\032FFXSR" /* Fast FXSAVE/FXRSTOR */
793 "\033Page1GB" /* 1-GB large page support */
794 "\034RDTSCP" /* RDTSCP */
795 "\035<b28>" /* Undefined */
796 "\036LM" /* 64 bit long mode */
797 "\0373DNow!+" /* AMD 3DNow! Extensions */
798 "\0403DNow!" /* AMD 3DNow! */
802 if (amd_feature2 != 0) {
803 printf("\n AMD Features2=0x%b", amd_feature2,
805 "\001LAHF" /* LAHF/SAHF in long mode */
806 "\002CMP" /* CMP legacy */
807 "\003SVM" /* Secure Virtual Mode */
808 "\004ExtAPIC" /* Extended APIC register */
809 "\005CR8" /* CR8 in legacy mode */
813 "\011Prefetch" /* 3DNow! Prefetch/PrefetchW */
840 if (cpu_feature & CPUID_HTT && strcmp(cpu_vendor,
841 "AuthenticAMD") == 0)
842 cpu_feature &= ~CPUID_HTT;
845 * If this CPU supports HTT or CMP then mention the
846 * number of physical/logical cores it contains.
848 if (cpu_feature & CPUID_HTT)
849 htt = (cpu_procinfo & CPUID_HTT_CORES) >> 16;
850 if (strcmp(cpu_vendor, "AuthenticAMD") == 0 &&
851 (amd_feature2 & AMDID2_CMP))
852 cmp = (cpu_procinfo2 & AMDID_CMP_CORES) + 1;
853 else if (strcmp(cpu_vendor, "GenuineIntel") == 0 &&
855 cpuid_count(4, 0, regs);
856 if ((regs[0] & 0x1f) != 0)
857 cmp = ((regs[0] >> 26) & 0x3f) + 1;
860 cpu_logical = htt / cmp;
862 printf("\n Cores per package: %d", cmp);
864 printf("\n Logical CPUs per core: %d",
867 } else if (strcmp(cpu_vendor, "CyrixInstead") == 0) {
868 printf(" DIR=0x%04x", cyrix_did);
869 printf(" Stepping=%u", (cyrix_did & 0xf000) >> 12);
870 printf(" Revision=%u", (cyrix_did & 0x0f00) >> 8);
871 #ifndef CYRIX_CACHE_REALLY_WORKS
872 if (cpu == CPU_M1 && (cyrix_did & 0xff00) < 0x1700)
873 printf("\n CPU cache: write-through mode");
876 if (strcmp(cpu_vendor, "CentaurHauls") == 0)
877 print_via_padlock_info();
879 /* Avoid ugly blank lines: only print newline when we have to. */
880 if (*cpu_vendor || cpu_id)
886 if (strcmp(cpu_vendor, "AuthenticAMD") == 0)
888 else if (strcmp(cpu_vendor, "GenuineIntel") == 0)
890 else if (strcmp(cpu_vendor, "GenuineTMx86") == 0 ||
891 strcmp(cpu_vendor, "TransmetaCPU") == 0)
892 print_transmeta_info();
896 panicifcpuunsupported(void)
900 #if !defined(I486_CPU) && !defined(I586_CPU) && !defined(I686_CPU)
901 #error This kernel is not configured for one of the supported CPUs
906 * Now that we have told the user what they have,
907 * let them know if that machine type isn't configured.
910 case CPUCLASS_286: /* a 286 should not make it this far, anyway */
912 #if !defined(I486_CPU)
915 #if !defined(I586_CPU)
918 #if !defined(I686_CPU)
921 panic("CPU class not configured");
928 static volatile u_int trap_by_rdmsr;
931 * Special exception 6 handler.
932 * The rdmsr instruction generates invalid opcodes fault on 486-class
933 * Cyrix CPU. Stacked eip register points the rdmsr instruction in the
934 * function identblue() when this handler is called. Stacked eip should
938 #ifdef __GNUCLIKE_ASM
943 .type " __XSTRING(CNAME(bluetrap6)) ",@function \n\
944 " __XSTRING(CNAME(bluetrap6)) ": \n\
946 movl $0xa8c1d," __XSTRING(CNAME(trap_by_rdmsr)) " \n\
947 addl $2, (%esp) /* rdmsr is a 2-byte instruction */ \n\
953 * Special exception 13 handler.
954 * Accessing non-existent MSR generates general protection fault.
956 inthand_t bluetrap13;
957 #ifdef __GNUCLIKE_ASM
962 .type " __XSTRING(CNAME(bluetrap13)) ",@function \n\
963 " __XSTRING(CNAME(bluetrap13)) ": \n\
965 movl $0xa89c4," __XSTRING(CNAME(trap_by_rdmsr)) " \n\
966 popl %eax /* discard error code */ \n\
967 addl $2, (%esp) /* rdmsr is a 2-byte instruction */ \n\
973 * Distinguish IBM Blue Lightning CPU from Cyrix CPUs that does not
974 * support cpuid instruction. This function should be called after
975 * loading interrupt descriptor table register.
977 * I don't like this method that handles fault, but I couldn't get
978 * information for any other methods. Does blue giant know?
987 * Cyrix 486-class CPU does not support rdmsr instruction.
988 * The rdmsr instruction generates invalid opcode fault, and exception
989 * will be trapped by bluetrap6() on Cyrix 486-class CPU. The
990 * bluetrap6() set the magic number to trap_by_rdmsr.
992 setidt(IDT_UD, bluetrap6, SDT_SYS386TGT, SEL_KPL,
993 GSEL(GCODE_SEL, SEL_KPL));
996 * Certain BIOS disables cpuid instruction of Cyrix 6x86MX CPU.
997 * In this case, rdmsr generates general protection fault, and
998 * exception will be trapped by bluetrap13().
1000 setidt(IDT_GP, bluetrap13, SDT_SYS386TGT, SEL_KPL,
1001 GSEL(GCODE_SEL, SEL_KPL));
1003 rdmsr(0x1002); /* Cyrix CPU generates fault. */
1005 if (trap_by_rdmsr == 0xa8c1d)
1006 return IDENTBLUE_CYRIX486;
1007 else if (trap_by_rdmsr == 0xa89c4)
1008 return IDENTBLUE_CYRIXM2;
1009 return IDENTBLUE_IBMCPU;
1014 * identifycyrix() set lower 16 bits of cyrix_did as follows:
1016 * F E D C B A 9 8 7 6 5 4 3 2 1 0
1017 * +-------+-------+---------------+
1018 * | SID | RID | Device ID |
1019 * | (DIR 1) | (DIR 0) |
1020 * +-------+-------+---------------+
1026 int ccr2_test = 0, dir_test = 0;
1029 eflags = read_eflags();
1032 ccr2 = read_cyrix_reg(CCR2);
1033 write_cyrix_reg(CCR2, ccr2 ^ CCR2_LOCK_NW);
1034 read_cyrix_reg(CCR2);
1035 if (read_cyrix_reg(CCR2) != ccr2)
1037 write_cyrix_reg(CCR2, ccr2);
1039 ccr3 = read_cyrix_reg(CCR3);
1040 write_cyrix_reg(CCR3, ccr3 ^ CCR3_MAPEN3);
1041 read_cyrix_reg(CCR3);
1042 if (read_cyrix_reg(CCR3) != ccr3)
1043 dir_test = 1; /* CPU supports DIRs. */
1044 write_cyrix_reg(CCR3, ccr3);
1047 /* Device ID registers are available. */
1048 cyrix_did = read_cyrix_reg(DIR1) << 8;
1049 cyrix_did += read_cyrix_reg(DIR0);
1050 } else if (ccr2_test)
1051 cyrix_did = 0x0010; /* 486S A-step */
1053 cyrix_did = 0x00ff; /* Old 486SLC/DLC and TI486SXLC/SXL */
1055 write_eflags(eflags);
1058 /* Update TSC freq with the value indicated by the caller. */
1060 tsc_freq_changed(void *arg, const struct cf_level *level, int status)
1062 /* If there was an error during the transition, don't do anything. */
1066 /* Total setting for this level gives the new frequency in MHz. */
1067 hw_clockrate = level->total_set.freq;
1070 EVENTHANDLER_DEFINE(cpufreq_post_change, tsc_freq_changed, NULL,
1071 EVENTHANDLER_PRI_ANY);
1074 * Final stage of CPU identification. -- Should I check TI?
1077 finishidentcpu(void)
1083 /* Detect AMD features (PTE no-execute bit, 3dnow, 64 bit mode etc) */
1084 if (strcmp(cpu_vendor, "GenuineIntel") == 0 ||
1085 strcmp(cpu_vendor, "AuthenticAMD") == 0) {
1087 if (cpu_exthigh >= 0x80000001) {
1088 do_cpuid(0x80000001, regs);
1089 amd_feature = regs[3] & ~(cpu_feature & 0x0183f3ff);
1090 amd_feature2 = regs[2];
1092 if (cpu_exthigh >= 0x80000008) {
1093 do_cpuid(0x80000008, regs);
1094 cpu_procinfo2 = regs[2];
1096 } else if (strcmp(cpu_vendor, "CyrixInstead") == 0) {
1097 if (cpu == CPU_486) {
1099 * These conditions are equivalent to:
1100 * - CPU does not support cpuid instruction.
1101 * - Cyrix/IBM CPU is detected.
1103 isblue = identblue();
1104 if (isblue == IDENTBLUE_IBMCPU) {
1105 strcpy(cpu_vendor, "IBM");
1110 switch (cpu_id & 0xf00) {
1113 * Cyrix's datasheet does not describe DIRs.
1114 * Therefor, I assume it does not have them
1115 * and use the result of the cpuid instruction.
1116 * XXX they seem to have it for now at least. -Peter
1124 * This routine contains a trick.
1125 * Don't check (cpu_id & 0x00f0) == 0x50 to detect M2, now.
1127 switch (cyrix_did & 0x00f0) {
1136 if ((cyrix_did & 0x000f) < 8)
1149 /* M2 and later CPUs are treated as M2. */
1153 * enable cpuid instruction.
1155 ccr3 = read_cyrix_reg(CCR3);
1156 write_cyrix_reg(CCR3, CCR3_MAPEN0);
1157 write_cyrix_reg(CCR4, read_cyrix_reg(CCR4) | CCR4_CPUID);
1158 write_cyrix_reg(CCR3, ccr3);
1161 cpu_high = regs[0]; /* eax */
1163 cpu_id = regs[0]; /* eax */
1164 cpu_feature = regs[3]; /* edx */
1168 } else if (cpu == CPU_486 && *cpu_vendor == '\0') {
1170 * There are BlueLightning CPUs that do not change
1171 * undefined flags by dividing 5 by 2. In this case,
1172 * the CPU identification routine in locore.s leaves
1173 * cpu_vendor null string and puts CPU_486 into the
1176 isblue = identblue();
1177 if (isblue == IDENTBLUE_IBMCPU) {
1178 strcpy(cpu_vendor, "IBM");
1186 print_AMD_assoc(int i)
1189 printf(", fully associative\n");
1191 printf(", %d-way associative\n", i);
1195 print_AMD_info(void)
1199 if (cpu_exthigh >= 0x80000005) {
1202 do_cpuid(0x80000005, regs);
1203 printf("Data TLB: %d entries", (regs[1] >> 16) & 0xff);
1204 print_AMD_assoc(regs[1] >> 24);
1205 printf("Instruction TLB: %d entries", regs[1] & 0xff);
1206 print_AMD_assoc((regs[1] >> 8) & 0xff);
1207 printf("L1 data cache: %d kbytes", regs[2] >> 24);
1208 printf(", %d bytes/line", regs[2] & 0xff);
1209 printf(", %d lines/tag", (regs[2] >> 8) & 0xff);
1210 print_AMD_assoc((regs[2] >> 16) & 0xff);
1211 printf("L1 instruction cache: %d kbytes", regs[3] >> 24);
1212 printf(", %d bytes/line", regs[3] & 0xff);
1213 printf(", %d lines/tag", (regs[3] >> 8) & 0xff);
1214 print_AMD_assoc((regs[3] >> 16) & 0xff);
1215 if (cpu_exthigh >= 0x80000006) { /* K6-III only */
1216 do_cpuid(0x80000006, regs);
1217 printf("L2 internal cache: %d kbytes", regs[2] >> 16);
1218 printf(", %d bytes/line", regs[2] & 0xff);
1219 printf(", %d lines/tag", (regs[2] >> 8) & 0x0f);
1220 print_AMD_assoc((regs[2] >> 12) & 0x0f);
1223 if (((cpu_id & 0xf00) == 0x500)
1224 && (((cpu_id & 0x0f0) > 0x80)
1225 || (((cpu_id & 0x0f0) == 0x80)
1226 && (cpu_id & 0x00f) > 0x07))) {
1227 /* K6-2(new core [Stepping 8-F]), K6-III or later */
1228 amd_whcr = rdmsr(0xc0000082);
1229 if (!(amd_whcr & (0x3ff << 22))) {
1230 printf("Write Allocate Disable\n");
1232 printf("Write Allocate Enable Limit: %dM bytes\n",
1233 (u_int32_t)((amd_whcr & (0x3ff << 22)) >> 22) * 4);
1234 printf("Write Allocate 15-16M bytes: %s\n",
1235 (amd_whcr & (1 << 16)) ? "Enable" : "Disable");
1237 } else if (((cpu_id & 0xf00) == 0x500)
1238 && ((cpu_id & 0x0f0) > 0x50)) {
1239 /* K6, K6-2(old core) */
1240 amd_whcr = rdmsr(0xc0000082);
1241 if (!(amd_whcr & (0x7f << 1))) {
1242 printf("Write Allocate Disable\n");
1244 printf("Write Allocate Enable Limit: %dM bytes\n",
1245 (u_int32_t)((amd_whcr & (0x7f << 1)) >> 1) * 4);
1246 printf("Write Allocate 15-16M bytes: %s\n",
1247 (amd_whcr & 0x0001) ? "Enable" : "Disable");
1248 printf("Hardware Write Allocate Control: %s\n",
1249 (amd_whcr & 0x0100) ? "Enable" : "Disable");
1255 print_INTEL_info(void)
1258 u_int rounds, regnum;
1259 u_int nwaycode, nway;
1261 if (cpu_high >= 2) {
1264 do_cpuid(0x2, regs);
1265 if (rounds == 0 && (rounds = (regs[0] & 0xff)) == 0)
1266 break; /* we have a buggy CPU */
1268 for (regnum = 0; regnum <= 3; ++regnum) {
1269 if (regs[regnum] & (1<<31))
1272 print_INTEL_TLB(regs[regnum] & 0xff);
1273 print_INTEL_TLB((regs[regnum] >> 8) & 0xff);
1274 print_INTEL_TLB((regs[regnum] >> 16) & 0xff);
1275 print_INTEL_TLB((regs[regnum] >> 24) & 0xff);
1277 } while (--rounds > 0);
1280 if (cpu_exthigh >= 0x80000006) {
1281 do_cpuid(0x80000006, regs);
1282 nwaycode = (regs[2] >> 12) & 0x0f;
1283 if (nwaycode >= 0x02 && nwaycode <= 0x08)
1284 nway = 1 << (nwaycode / 2);
1287 printf("\nL2 cache: %u kbytes, %u-way associative, %u bytes/line",
1288 (regs[2] >> 16) & 0xffff, nway, regs[2] & 0xff);
1295 print_INTEL_TLB(u_int data)
1303 printf("\nInstruction TLB: 4 KB pages, 4-way set associative, 32 entries");
1306 printf("\nInstruction TLB: 4 MB pages, fully associative, 2 entries");
1309 printf("\nData TLB: 4 KB pages, 4-way set associative, 64 entries");
1312 printf("\nData TLB: 4 MB Pages, 4-way set associative, 8 entries");
1315 printf("\n1st-level instruction cache: 8 KB, 4-way set associative, 32 byte line size");
1318 printf("\n1st-level instruction cache: 16 KB, 4-way set associative, 32 byte line size");
1321 printf("\n1st-level data cache: 8 KB, 2-way set associative, 32 byte line size");
1324 printf("\n1st-level data cache: 16 KB, 4-way set associative, 32 byte line size");
1327 printf("\n3rd-level cache: 512 KB, 4-way set associative, sectored cache, 64 byte line size");
1330 printf("\n3rd-level cache: 1 MB, 8-way set associative, sectored cache, 64 byte line size");
1333 printf("\n3rd-level cache: 2 MB, 8-way set associative, sectored cache, 64 byte line size");
1336 printf("\n3rd-level cache: 4 MB, 8-way set associative, sectored cache, 64 byte line size");
1339 printf("\n1st-level data cache: 32 KB, 8-way set associative, 64 byte line size");
1342 printf("\n1st-level instruction cache: 32 KB, 8-way set associative, 64 byte line size");
1345 printf("\n2nd-level cache: 128 KB, 4-way set associative, sectored cache, 64 byte line size");
1348 printf("\n2nd-level cache: 128 KB, 2-way set associative, sectored cache, 64 byte line size");
1351 printf("\n2nd-level cache: 256 KB, 4-way set associative, sectored cache, 64 byte line size");
1354 printf("\n2nd-level cache: 128 KB, 4-way set associative, 32 byte line size");
1357 printf("\n2nd-level cache: 256 KB, 4-way set associative, 32 byte line size");
1360 printf("\n2nd-level cache: 512 KB, 4-way set associative, 32 byte line size");
1363 printf("\n2nd-level cache: 1 MB, 4-way set associative, 32 byte line size");
1366 printf("\n2nd-level cache: 2 MB, 4-way set associative, 32 byte line size");
1369 printf("\n3rd-level cache: 4 MB, 4-way set associative, 64 byte line size");
1372 printf("\n3rd-level cache: 8 MB, 8-way set associative, 64 byte line size");
1375 printf("\nInstruction TLB: 4 KB, 2 MB or 4 MB pages, fully associative, 64 entries");
1378 printf("\nInstruction TLB: 4 KB, 2 MB or 4 MB pages, fully associative, 128 entries");
1381 printf("\nInstruction TLB: 4 KB, 2 MB or 4 MB pages, fully associative, 256 entries");
1384 printf("\nData TLB: 4 KB or 4 MB pages, fully associative, 64 entries");
1387 printf("\nData TLB: 4 KB or 4 MB pages, fully associative, 128 entries");
1390 printf("\nData TLB: 4 KB or 4 MB pages, fully associative, 256 entries");
1393 printf("\n1st-level data cache: 16 KB, 8-way set associative, sectored cache, 64 byte line size");
1396 printf("\n1st-level data cache: 8 KB, 4-way set associative, sectored cache, 64 byte line size");
1399 printf("\n1st-level data cache: 16 KB, 4-way set associative, sectored cache, 64 byte line size");
1402 printf("\n1st-level data cache: 32 KB, 4 way set associative, sectored cache, 64 byte line size");
1405 printf("\nTrace cache: 12K-uops, 8-way set associative");
1408 printf("\nTrace cache: 16K-uops, 8-way set associative");
1411 printf("\nTrace cache: 32K-uops, 8-way set associative");
1414 printf("\n2nd-level cache: 1 MB, 4-way set associative, 64-byte line size");
1417 printf("\n2nd-level cache: 128 KB, 8-way set associative, sectored cache, 64 byte line size");
1420 printf("\n2nd-level cache: 256 KB, 8-way set associative, sectored cache, 64 byte line size");
1423 printf("\n2nd-level cache: 512 KB, 8-way set associative, sectored cache, 64 byte line size");
1426 printf("\n2nd-level cache: 1 MB, 8-way set associative, sectored cache, 64 byte line size");
1429 printf("\n2nd-level cache: 2-MB, 8-way set associative, 64-byte line size");
1432 printf("\n2nd-level cache: 512-KB, 2-way set associative, 64-byte line size");
1435 printf("\n2nd-level cache: 256 KB, 8-way set associative, 32 byte line size");
1438 printf("\n2nd-level cache: 512 KB, 8-way set associative, 32 byte line size");
1441 printf("\n2nd-level cache: 1 MB, 8-way set associative, 32 byte line size");
1444 printf("\n2nd-level cache: 2 MB, 8-way set associative, 32 byte line size");
1447 printf("\n2nd-level cache: 512 KB, 4-way set associative, 64 byte line size");
1450 printf("\n2nd-level cache: 1 MB, 8-way set associative, 64 byte line size");
1453 printf("\nInstruction TLB: 4 KB Pages, 4-way set associative, 128 entries");
1456 printf("\nData TLB: 4 KB Pages, 4-way set associative, 128 entries");
1462 print_transmeta_info(void)
1464 u_int regs[4], nreg = 0;
1466 do_cpuid(0x80860000, regs);
1468 if (nreg >= 0x80860001) {
1469 do_cpuid(0x80860001, regs);
1470 printf(" Processor revision %u.%u.%u.%u\n",
1471 (regs[1] >> 24) & 0xff,
1472 (regs[1] >> 16) & 0xff,
1473 (regs[1] >> 8) & 0xff,
1476 if (nreg >= 0x80860002) {
1477 do_cpuid(0x80860002, regs);
1478 printf(" Code Morphing Software revision %u.%u.%u-%u-%u\n",
1479 (regs[1] >> 24) & 0xff,
1480 (regs[1] >> 16) & 0xff,
1481 (regs[1] >> 8) & 0xff,
1485 if (nreg >= 0x80860006) {
1487 do_cpuid(0x80860003, (u_int*) &info[0]);
1488 do_cpuid(0x80860004, (u_int*) &info[16]);
1489 do_cpuid(0x80860005, (u_int*) &info[32]);
1490 do_cpuid(0x80860006, (u_int*) &info[48]);
1492 printf(" %s\n", info);
1497 print_via_padlock_info(void)
1501 /* Check for supported models. */
1502 switch (cpu_id & 0xff0) {
1504 if ((cpu_id & 0xf) < 3)
1513 do_cpuid(0xc0000000, regs);
1514 if (regs[0] >= 0xc0000001)
1515 do_cpuid(0xc0000001, regs);
1519 printf("\n VIA Padlock Features=0x%b", regs[3],
1523 "\011AES-CTR" /* ACE2 */
1524 "\013SHA1,SHA256" /* PHE */