#include "opt_cpu.h"
#include <sys/param.h>
#include <sys/bus.h>
#include <sys/eventhandler.h>
#include <sys/systm.h>
#include <sys/kernel.h>
#include <sys/sysctl.h>
#include <sys/power.h>
#include <machine/asmacros.h>
#include <machine/clock.h>
#include <machine/cputypes.h>
#include <machine/frame.h>
#include <machine/segments.h>
#include <machine/specialreg.h>
#include <machine/md_var.h>
#include <machine/npx.h>
static u_int find_cpu_vendor_id(void);
static void print_AMD_info(void);
static void print_INTEL_info(void);
static void print_via_padlock_info(void);
static void print_xsave_info(void);
static void print_svm_info(void);
static void print_vmx_info(void);
int cpu_type;
int cpu_class;
char machine[] = "x86_64";
SYSCTL_STRING(_hw, HW_MACHINE, machine, CTLFLAG_RD,
machine, 0, "Machine class");
static char cpu_model[128];
SYSCTL_STRING(_hw, HW_MODEL, model, CTLFLAG_RD,
cpu_model, 0, "Machine model");
static int hw_clockrate;
SYSCTL_INT(_hw, OID_AUTO, clockrate, CTLFLAG_RD,
&hw_clockrate, 0, "CPU instruction clock rate");
static char cpu_brand[48];
static struct {
char *cpu_name;
int cpu_class;
} x86_64_cpus[] = {
{ "Clawhammer", CPUCLASS_K8 },
{ "Sledgehammer", CPUCLASS_K8 },
};
static struct {
char *vendor;
u_int vendor_id;
} cpu_vendors[] = {
{ INTEL_VENDOR_ID, CPU_VENDOR_INTEL },
{ AMD_VENDOR_ID, CPU_VENDOR_AMD },
{ CENTAUR_VENDOR_ID, CPU_VENDOR_CENTAUR },
};
#if 0
static int cpu_cores;
static int cpu_logical;
#endif
void
printcpuinfo(void)
{
u_int regs[4], i;
char *brand;
kprintf("CPU: ");
strncpy(cpu_model, x86_64_cpus[cpu_type].cpu_name, sizeof (cpu_model));
if (cpu_exthigh >= 0x80000004) {
brand = cpu_brand;
for (i = 0x80000002; i < 0x80000005; i++) {
do_cpuid(i, regs);
memcpy(brand, regs, sizeof(regs));
brand += sizeof(regs);
}
}
switch (cpu_vendor_id) {
case CPU_VENDOR_INTEL:
strcat(cpu_model, "EM64T");
break;
case CPU_VENDOR_AMD:
strcpy(cpu_model, "AMD ");
if ((cpu_id & 0xf00) == 0xf00)
strcat(cpu_model, "AMD64 Processor");
else
strcat(cpu_model, "Unknown");
break;
case CPU_VENDOR_CENTAUR:
strcpy(cpu_model, "VIA ");
if ((cpu_id & 0xff0) == 0x6f0)
strcat(cpu_model, "Nano Processor");
else
strcat(cpu_model, "Unknown");
break;
default:
strcat(cpu_model, "Unknown");
break;
}
brand = cpu_brand;
while (*brand == ' ')
++brand;
if (*brand != '\0')
strcpy(cpu_model, brand);
kprintf("%s (", cpu_model);
switch(cpu_class) {
case CPUCLASS_K8:
hw_clockrate = (tsc_frequency + 5000) / 1000000;
kprintf("%jd.%02d-MHz ",
(intmax_t)(tsc_frequency + 4999) / 1000000,
(u_int)((tsc_frequency + 4999) / 10000) % 100);
kprintf("K8");
break;
default:
kprintf("Unknown");
}
kprintf("-class CPU)\n");
if (*cpu_vendor)
kprintf(" Origin=\"%s\"", cpu_vendor);
if (cpu_id)
kprintf(" Id=0x%x", cpu_id);
if (cpu_vendor_id == CPU_VENDOR_INTEL ||
cpu_vendor_id == CPU_VENDOR_AMD ||
cpu_vendor_id == CPU_VENDOR_CENTAUR) {
kprintf(" Family=0x%x", CPUID_TO_FAMILY(cpu_id));
kprintf(" Model=0x%x", CPUID_TO_MODEL(cpu_id));
kprintf(" Stepping=%u", cpu_id & CPUID_STEPPING);
if (cpu_high > 0) {
#if 0
u_int cmp = 1, htt = 1;
#endif
kprintf("\n Features=0x%pb%i",
"\020"
"\001FPU"
"\002VME"
"\003DE"
"\004PSE"
"\005TSC"
"\006MSR"
"\007PAE"
"\010MCE"
"\011CX8"
"\012APIC"
"\013oldMTRR"
"\014SEP"
"\015MTRR"
"\016PGE"
"\017MCA"
"\020CMOV"
"\021PAT"
"\022PSE36"
"\023PN"
"\024CLFLUSH"
"\025<b20>"
"\026DTS"
"\027ACPI"
"\030MMX"
"\031FXSR"
"\032SSE"
"\033SSE2"
"\034SS"
"\035HTT"
"\036TM"
"\037IA64"
"\040PBE"
, cpu_feature);
if (cpu_feature2 != 0) {
kprintf("\n Features2=0x%pb%i",
"\020"
"\001SSE3"
"\002PCLMULQDQ"
"\003DTES64"
"\004MON"
"\005DS_CPL"
"\006VMX"
"\007SMX"
"\010EST"
"\011TM2"
"\012SSSE3"
"\013CNXT-ID"
"\014SDBG"
"\015FMA"
"\016CX16"
"\017xTPR"
"\020PDCM"
"\021<b16>"
"\022PCID"
"\023DCA"
"\024SSE4.1"
"\025SSE4.2"
"\026x2APIC"
"\027MOVBE"
"\030POPCNT"
"\031TSCDLT"
"\032AESNI"
"\033XSAVE"
"\034OSXSAVE"
"\035AVX"
"\036F16C"
"\037RDRAND"
"\040VMM"
, cpu_feature2);
}
if ((cpu_feature2 & CPUID2_XSAVE) != 0)
print_xsave_info();
if (cpu_ia32_arch_caps != 0) {
kprintf("\n IA32_ARCH_CAPS=0x%pb%i",
"\020"
"\001RDCL_NO"
"\002IBRS_ALL"
"\003RSBA"
"\004SKIP_L1DFL_VME"
"\005SSB_NO"
"\006MDS_NO"
"\007IF_PSCHANGE_MC_NO"
"\010TSX_CTRL"
"\011TAA_NO",
(u_int)cpu_ia32_arch_caps
);
}
if (amd_feature != 0) {
kprintf("\n AMD Features=0x%pb%i",
"\020"
"\001<s0>"
"\002<s1>"
"\003<s2>"
"\004<s3>"
"\005<s4>"
"\006<s5>"
"\007<s6>"
"\010<s7>"
"\011<s8>"
"\012<s9>"
"\013<b10>"
"\014SYSCALL"
"\015<s12>"
"\016<s13>"
"\017<s14>"
"\020<s15>"
"\021<s16>"
"\022<s17>"
"\023<b18>"
"\024MP"
"\025NX"
"\026<b21>"
"\027MMX+"
"\030<s23>"
"\031<s24>"
"\032FFXSR"
"\033Page1GB"
"\034RDTSCP"
"\035<b28>"
"\036LM"
"\0373DNow!+"
"\0403DNow!"
, amd_feature);
}
if (amd_feature2 != 0) {
kprintf("\n AMD Features2=0x%pb%i",
"\020"
"\001LAHF"
"\002CMP"
"\003SVM"
"\004ExtAPIC"
"\005CR8"
"\006ABM"
"\007SSE4A"
"\010MAS"
"\011Prefetch"
"\012OSVW"
"\013IBS"
"\014XOP"
"\015SKINIT"
"\016WDT"
"\017<b14>"
"\020LWP"
"\021FMA4"
"\022TCE"
"\023<b18>"
"\024NodeId"
"\025<b20>"
"\026TBM"
"\027Topology"
"\030PCX_CORE"
"\031PCX_NB"
"\032SPM"
"\033DBE"
"\034PTSC"
"\035PCX_L2I"
"\036MWAITX"
"\037ADMSKX"
"\040<b31>"
, amd_feature2);
}
if (cpu_stdext_feature != 0) {
kprintf("\n Structured Extended Features=0x%pb%i",
"\020"
"\001GSFSBASE"
"\002TSCADJ"
"\004BMI1"
"\005HLE"
"\006AVX2"
"\007FDPEXC"
"\010SMEP"
"\011BMI2"
"\012ENHMOVSB"
"\013INVPCID"
"\014RTM"
"\015PQM"
"\016NFPUSG"
"\017MPX"
"\020PQE"
"\021AVX512F"
"\022AVX512DQ"
"\023RDSEED"
"\024ADX"
"\025SMAP"
"\026AVX512IFMA"
"\027<b22>"
"\030CLFLUSHOPT"
"\031CLWB"
"\032PROCTRACE"
"\033AVX512PF"
"\034AVX512ER"
"\035AVX512CD"
"\036SHA"
"\037AVX512BW"
"\040AVX512VL"
, cpu_stdext_feature);
}
if (cpu_stdext_feature2 != 0) {
kprintf("\n Structured Extended Features2=0x%pb%i",
"\020"
"\001PREFETCHWT1"
"\002AVX512VBMI"
"\003UMIP"
"\004PKU"
"\005OSPKE"
"\006WAITPKG"
"\007AVX512VBMI2"
"\010CET_SS"
"\011GFNI"
"\012VAES"
"\013VPCLMULQDQ"
"\014AVX512VNNI"
"\015AVX512BITALG"
"\016TME"
"\017AVX512VPOPCNTDQ"
"\021LA57"
"\027RDPID"
"\030KL"
"\031BUS_LOCK_DETECT"
"\032CLDEMOTE"
"\034MOVDIRI"
"\035MOVDIR64B"
"\036ENQCMD"
"\037SGXLC"
"\040PKS"
, cpu_stdext_feature2);
}
if (cpu_stdext_feature3 != 0) {
kprintf("\n Structured Extended Features3=0x%pb%i",
"\020"
"\003AVX512_4VNNIW"
"\004AVX512_4FMAPS"
"\005FSRM"
"\006UINTR"
"\011AVX512VP2INTERSECT"
"\012MCUOPT"
"\013MD_CLEAR"
"\016TSXFA"
"\017SERIALIZE"
"\020HYBRID"
"\021TSXLDTRK"
"\023PCONFIG"
"\025IBT"
"\033IBPB"
"\034STIBP"
"\035L1DFL"
"\036ARCH_CAP"
"\037CORE_CAP"
"\040SSBD"
, cpu_stdext_feature3);
}
if (cpu_thermal_feature != 0) {
kprintf("\n Thermal and PM Features=0x%pb%i",
"\020"
"\001SENSOR"
"\002TURBO"
"\003ARAT"
"\005PLN"
"\006ECMD"
"\007PTM"
"\010HWP"
, cpu_thermal_feature);
}
if (cpu_mwait_feature != 0) {
kprintf("\n MONITOR/MWAIT Features=0x%pb%i",
"\020"
"\001CST"
"\002INTBRK"
, cpu_mwait_feature);
}
if (cpu_vendor_id == CPU_VENDOR_CENTAUR)
print_via_padlock_info();
if (cpu_feature2 & CPUID2_VMX)
print_vmx_info();
if (amd_feature2 & AMDID2_SVM)
print_svm_info();
#if 0
if ((cpu_feature & CPUID_HTT) &&
cpu_vendor_id == CPU_VENDOR_AMD)
cpu_feature &= ~CPUID_HTT;
#endif
#if 0
if (cpu_feature & CPUID_HTT)
htt = (cpu_procinfo & CPUID_HTT_CORES) >> 16;
if (cpu_vendor_id == CPU_VENDOR_AMD &&
(amd_feature2 & AMDID2_CMP))
cmp = (cpu_procinfo2 & AMDID_CMP_CORES) + 1;
else if (cpu_vendor_id == CPU_VENDOR_INTEL &&
(cpu_high >= 4)) {
cpuid_count(4, 0, regs);
if ((regs[0] & 0x1f) != 0)
cmp = ((regs[0] >> 26) & 0x3f) + 1;
}
#endif
#if 0
cpu_cores = cmp;
cpu_logical = htt / cmp;
if (cpu_cores > 1)
kprintf("\n Cores per package: %d", cpu_cores);
if (cpu_logical > 1) {
kprintf("\n Logical CPUs per core: %d",
cpu_logical);
}
#endif
}
}
if (*cpu_vendor || cpu_id)
kprintf("\n");
if (cpu_stdext_feature & (CPUID_STDEXT_SMAP | CPUID_STDEXT_SMEP)) {
kprintf("CPU Special Features Installed:");
if (cpu_stdext_feature & CPUID_STDEXT_SMAP)
kprintf(" SMAP");
if (cpu_stdext_feature & CPUID_STDEXT_SMEP)
kprintf(" SMEP");
kprintf("\n");
}
if (bootverbose) {
if (cpu_vendor_id == CPU_VENDOR_AMD)
print_AMD_info();
else if (cpu_vendor_id == CPU_VENDOR_INTEL)
print_INTEL_info();
}
if (cpu_feature2 & CPUID2_VMM) {
if (*vmm_vendor != '\0')
kprintf("VMM/Hypervisor: Origin=\"%s\"\n", vmm_vendor);
else
kprintf("VMM/Hypervisor: Origin=(unknown)\n");
}
}
void
panicifcpuunsupported(void)
{
#ifndef HAMMER_CPU
#error "You need to specify a cpu type"
#endif
switch (cpu_class) {
case CPUCLASS_X86:
#ifndef HAMMER_CPU
case CPUCLASS_K8:
#endif
panic("CPU class not configured");
default:
break;
}
}
#if 0
static void
tsc_freq_changed(void *arg, const struct cf_level *level, int status)
{
if (status != 0)
return;
hw_clockrate = level->total_set.freq;
}
EVENTHANDLER_DEFINE(cpufreq_post_change, tsc_freq_changed, NULL,
EVENTHANDLER_PRI_ANY);
#endif
void
identify_cpu(void)
{
u_int regs[4];
u_int cpu_stdext_disable;
do_cpuid(0, regs);
cpu_high = regs[0];
((u_int *)&cpu_vendor)[0] = regs[1];
((u_int *)&cpu_vendor)[1] = regs[3];
((u_int *)&cpu_vendor)[2] = regs[2];
cpu_vendor[12] = '\0';
cpu_vendor_id = find_cpu_vendor_id();
do_cpuid(1, regs);
cpu_id = regs[0];
cpu_procinfo = regs[1];
cpu_feature = regs[3];
cpu_feature2 = regs[2];
if (cpu_high >= 5) {
do_cpuid(5, regs);
cpu_mwait_feature = regs[2];
if (cpu_mwait_feature & CPUID_MWAIT_EXT) {
cpu_mwait_extemu = regs[3];
if (CPUID_MWAIT_CX_SUBCNT(cpu_mwait_extemu, 1) == 0) {
cpu_mwait_feature &= ~CPUID_MWAIT_EXT;
cpu_mwait_extemu = 0;
}
}
}
if (cpu_high >= 6) {
do_cpuid(6, regs);
cpu_thermal_feature = regs[0];
}
if (cpu_high >= 7) {
cpuid_count(7, 0, regs);
cpu_stdext_feature = regs[1];
if (cpu_feature2 & CPUID2_VMM) {
cpu_stdext_disable = CPUID_STDEXT_FSGSBASE |
CPUID_STDEXT_SMEP;
} else {
cpu_stdext_disable = 0;
}
TUNABLE_INT_FETCH("hw.cpu_stdext_disable", &cpu_stdext_disable);
cpu_stdext_feature &= ~cpu_stdext_disable;
cpu_stdext_feature2 = regs[2];
cpu_stdext_feature3 = regs[3];
if (cpu_stdext_feature3 & CPUID_STDEXT3_ARCH_CAP) {
if (rdmsr_safe(MSR_IA32_ARCH_CAPABILITIES,
&cpu_ia32_arch_caps))
{
kprintf("Warning: MSR_IA32_ARCH_CAPABILITIES "
"cannot be accessed\n");
}
}
}
if (cpu_vendor_id == CPU_VENDOR_INTEL ||
cpu_vendor_id == CPU_VENDOR_AMD ||
cpu_vendor_id == CPU_VENDOR_CENTAUR) {
do_cpuid(0x80000000, regs);
cpu_exthigh = regs[0];
}
if (cpu_exthigh >= 0x80000001) {
do_cpuid(0x80000001, regs);
amd_feature = regs[3] & ~(cpu_feature & 0x0183f3ff);
amd_feature2 = regs[2];
}
if (cpu_exthigh >= 0x80000008) {
do_cpuid(0x80000008, regs);
cpu_procinfo2 = regs[2];
}
cpu_type = CPU_CLAWHAMMER;
cpu_class = x86_64_cpus[cpu_type].cpu_class;
if (cpu_feature & CPUID_SSE2)
cpu_mi_feature |= CPU_MI_BZERONT;
if (cpu_feature2 & CPUID2_MON)
cpu_mi_feature |= CPU_MI_MONITOR;
if ((cpu_feature & CPUID_SSE) && (cpu_feature & CPUID_FXSR))
npxprobemask();
}
static u_int
find_cpu_vendor_id(void)
{
int i;
for (i = 0; i < NELEM(cpu_vendors); i++)
if (strcmp(cpu_vendor, cpu_vendors[i].vendor) == 0)
return (cpu_vendors[i].vendor_id);
return (0);
}
static void
print_AMD_assoc(int i)
{
if (i == 255)
kprintf(", fully associative\n");
else
kprintf(", %d-way associative\n", i);
}
static void
print_AMD_l2_assoc(int i)
{
switch (i & 0x0f) {
case 0: kprintf(", disabled/not present\n"); break;
case 1: kprintf(", direct mapped\n"); break;
case 2: kprintf(", 2-way associative\n"); break;
case 4: kprintf(", 4-way associative\n"); break;
case 6: kprintf(", 8-way associative\n"); break;
case 8: kprintf(", 16-way associative\n"); break;
case 15: kprintf(", fully associative\n"); break;
default: kprintf(", reserved configuration\n"); break;
}
}
static void
print_AMD_info(void)
{
u_int regs[4];
if (cpu_exthigh < 0x80000005)
return;
do_cpuid(0x80000005, regs);
kprintf("L1 2MB data TLB: %d entries", (regs[0] >> 16) & 0xff);
print_AMD_assoc(regs[0] >> 24);
kprintf("L1 2MB instruction TLB: %d entries", regs[0] & 0xff);
print_AMD_assoc((regs[0] >> 8) & 0xff);
kprintf("L1 4KB data TLB: %d entries", (regs[1] >> 16) & 0xff);
print_AMD_assoc(regs[1] >> 24);
kprintf("L1 4KB instruction TLB: %d entries", regs[1] & 0xff);
print_AMD_assoc((regs[1] >> 8) & 0xff);
kprintf("L1 data cache: %d kbytes", regs[2] >> 24);
kprintf(", %d bytes/line", regs[2] & 0xff);
kprintf(", %d lines/tag", (regs[2] >> 8) & 0xff);
print_AMD_assoc((regs[2] >> 16) & 0xff);
kprintf("L1 instruction cache: %d kbytes", regs[3] >> 24);
kprintf(", %d bytes/line", regs[3] & 0xff);
kprintf(", %d lines/tag", (regs[3] >> 8) & 0xff);
print_AMD_assoc((regs[3] >> 16) & 0xff);
if (cpu_exthigh >= 0x80000006) {
do_cpuid(0x80000006, regs);
if ((regs[0] >> 16) != 0) {
kprintf("L2 2MB data TLB: %d entries",
(regs[0] >> 16) & 0xfff);
print_AMD_l2_assoc(regs[0] >> 28);
kprintf("L2 2MB instruction TLB: %d entries",
regs[0] & 0xfff);
print_AMD_l2_assoc((regs[0] >> 28) & 0xf);
} else {
kprintf("L2 2MB unified TLB: %d entries",
regs[0] & 0xfff);
print_AMD_l2_assoc((regs[0] >> 28) & 0xf);
}
if ((regs[1] >> 16) != 0) {
kprintf("L2 4KB data TLB: %d entries",
(regs[1] >> 16) & 0xfff);
print_AMD_l2_assoc(regs[1] >> 28);
kprintf("L2 4KB instruction TLB: %d entries",
(regs[1] >> 16) & 0xfff);
print_AMD_l2_assoc((regs[1] >> 28) & 0xf);
} else {
kprintf("L2 4KB unified TLB: %d entries",
(regs[1] >> 16) & 0xfff);
print_AMD_l2_assoc((regs[1] >> 28) & 0xf);
}
kprintf("L2 unified cache: %d kbytes", regs[2] >> 16);
kprintf(", %d bytes/line", regs[2] & 0xff);
kprintf(", %d lines/tag", (regs[2] >> 8) & 0x0f);
print_AMD_l2_assoc((regs[2] >> 12) & 0x0f);
}
}
static void
print_INTEL_TLB(u_int data)
{
switch (data) {
case 0x0:
case 0x40:
default:
break;
case 0x1:
kprintf("Instruction TLB: 4 KB pages, 4-way set associative, 32 entries\n");
break;
case 0x2:
kprintf("Instruction TLB: 4 MB pages, fully associative, 2 entries\n");
break;
case 0x3:
kprintf("Data TLB: 4 KB pages, 4-way set associative, 64 entries\n");
break;
case 0x4:
kprintf("Data TLB: 4 MB Pages, 4-way set associative, 8 entries\n");
break;
case 0x6:
kprintf("1st-level instruction cache: 8 KB, 4-way set associative, 32 byte line size\n");
break;
case 0x8:
kprintf("1st-level instruction cache: 16 KB, 4-way set associative, 32 byte line size\n");
break;
case 0x9:
kprintf("1st-level instruction cache: 32 KB, 4-way set associative, 64 byte line size\n");
break;
case 0xa:
kprintf("1st-level data cache: 8 KB, 2-way set associative, 32 byte line size\n");
break;
case 0xb:
kprintf("Instruction TLB: 4 MByte pages, 4-way set associative, 4 entries\n");
break;
case 0xc:
kprintf("1st-level data cache: 16 KB, 4-way set associative, 32 byte line size\n");
break;
case 0xd:
kprintf("1st-level data cache: 16 KBytes, 4-way set associative, 64 byte line size");
break;
case 0xe:
kprintf("1st-level data cache: 24 KBytes, 6-way set associative, 64 byte line size\n");
break;
case 0x1d:
kprintf("2nd-level cache: 128 KBytes, 2-way set associative, 64 byte line size\n");
break;
case 0x21:
kprintf("2nd-level cache: 256 KBytes, 8-way set associative, 64 byte line size\n");
break;
case 0x22:
kprintf("3rd-level cache: 512 KB, 4-way set associative, sectored cache, 64 byte line size\n");
break;
case 0x23:
kprintf("3rd-level cache: 1 MB, 8-way set associative, sectored cache, 64 byte line size\n");
break;
case 0x24:
kprintf("2nd-level cache: 1 MBytes, 16-way set associative, 64 byte line size\n");
break;
case 0x25:
kprintf("3rd-level cache: 2 MB, 8-way set associative, sectored cache, 64 byte line size\n");
break;
case 0x29:
kprintf("3rd-level cache: 4 MB, 8-way set associative, sectored cache, 64 byte line size\n");
break;
case 0x2c:
kprintf("1st-level data cache: 32 KB, 8-way set associative, 64 byte line size\n");
break;
case 0x30:
kprintf("1st-level instruction cache: 32 KB, 8-way set associative, 64 byte line size\n");
break;
case 0x39:
kprintf("2nd-level cache: 128 KB, 4-way set associative, sectored cache, 64 byte line size\n");
break;
case 0x3b:
kprintf("2nd-level cache: 128 KB, 2-way set associative, sectored cache, 64 byte line size\n");
break;
case 0x3c:
kprintf("2nd-level cache: 256 KB, 4-way set associative, sectored cache, 64 byte line size\n");
break;
case 0x41:
kprintf("2nd-level cache: 128 KB, 4-way set associative, 32 byte line size\n");
break;
case 0x42:
kprintf("2nd-level cache: 256 KB, 4-way set associative, 32 byte line size\n");
break;
case 0x43:
kprintf("2nd-level cache: 512 KB, 4-way set associative, 32 byte line size\n");
break;
case 0x44:
kprintf("2nd-level cache: 1 MB, 4-way set associative, 32 byte line size\n");
break;
case 0x45:
kprintf("2nd-level cache: 2 MB, 4-way set associative, 32 byte line size\n");
break;
case 0x46:
kprintf("3rd-level cache: 4 MB, 4-way set associative, 64 byte line size\n");
break;
case 0x47:
kprintf("3rd-level cache: 8 MB, 8-way set associative, 64 byte line size\n");
break;
case 0x48:
kprintf("2nd-level cache: 3MByte, 12-way set associative, 64 byte line size\n");
break;
case 0x49:
if (CPUID_TO_FAMILY(cpu_id) == 0xf &&
CPUID_TO_MODEL(cpu_id) == 0x6)
kprintf("3rd-level cache: 4MB, 16-way set associative, 64-byte line size\n");
else
kprintf("2nd-level cache: 4 MByte, 16-way set associative, 64 byte line size\n");
break;
case 0x4a:
kprintf("3rd-level cache: 6MByte, 12-way set associative, 64 byte line size\n");
break;
case 0x4b:
kprintf("3rd-level cache: 8MByte, 16-way set associative, 64 byte line size\n");
break;
case 0x4c:
kprintf("3rd-level cache: 12MByte, 12-way set associative, 64 byte line size\n");
break;
case 0x4d:
kprintf("3rd-level cache: 16MByte, 16-way set associative, 64 byte line size\n");
break;
case 0x4e:
kprintf("2nd-level cache: 6MByte, 24-way set associative, 64 byte line size\n");
break;
case 0x4f:
kprintf("Instruction TLB: 4 KByte pages, 32 entries\n");
break;
case 0x50:
kprintf("Instruction TLB: 4 KB, 2 MB or 4 MB pages, fully associative, 64 entries\n");
break;
case 0x51:
kprintf("Instruction TLB: 4 KB, 2 MB or 4 MB pages, fully associative, 128 entries\n");
break;
case 0x52:
kprintf("Instruction TLB: 4 KB, 2 MB or 4 MB pages, fully associative, 256 entries\n");
break;
case 0x55:
kprintf("Instruction TLB: 2-MByte or 4-MByte pages, fully associative, 7 entries\n");
break;
case 0x56:
kprintf("Data TLB0: 4 MByte pages, 4-way set associative, 16 entries\n");
break;
case 0x57:
kprintf("Data TLB0: 4 KByte pages, 4-way associative, 16 entries\n");
break;
case 0x59:
kprintf("Data TLB0: 4 KByte pages, fully associative, 16 entries\n");
break;
case 0x5a:
kprintf("Data TLB0: 2-MByte or 4 MByte pages, 4-way set associative, 32 entries\n");
break;
case 0x5b:
kprintf("Data TLB: 4 KB or 4 MB pages, fully associative, 64 entries\n");
break;
case 0x5c:
kprintf("Data TLB: 4 KB or 4 MB pages, fully associative, 128 entries\n");
break;
case 0x5d:
kprintf("Data TLB: 4 KB or 4 MB pages, fully associative, 256 entries\n");
break;
case 0x60:
kprintf("1st-level data cache: 16 KB, 8-way set associative, sectored cache, 64 byte line size\n");
break;
case 0x61:
kprintf("Instruction TLB: 4 KByte pages, fully associative, 48 entries\n");
break;
case 0x63:
kprintf("Data TLB: 2 MByte or 4 MByte pages, 4-way set associative, 32 entries and a separate array with 1 GByte pages, 4-way set associative, 4 entries\n");
break;
case 0x64:
kprintf("Data TLB: 4 KBytes pages, 4-way set associative, 512 entries\n");
break;
case 0x66:
kprintf("1st-level data cache: 8 KB, 4-way set associative, sectored cache, 64 byte line size\n");
break;
case 0x67:
kprintf("1st-level data cache: 16 KB, 4-way set associative, sectored cache, 64 byte line size\n");
break;
case 0x68:
kprintf("1st-level data cache: 32 KB, 4 way set associative, sectored cache, 64 byte line size\n");
break;
case 0x6a:
kprintf("uTLB: 4KByte pages, 8-way set associative, 64 entries\n");
break;
case 0x6b:
kprintf("DTLB: 4KByte pages, 8-way set associative, 256 entries\n");
break;
case 0x6c:
kprintf("DTLB: 2M/4M pages, 8-way set associative, 128 entries\n");
break;
case 0x6d:
kprintf("DTLB: 1 GByte pages, fully associative, 16 entries\n");
break;
case 0x70:
kprintf("Trace cache: 12K-uops, 8-way set associative\n");
break;
case 0x71:
kprintf("Trace cache: 16K-uops, 8-way set associative\n");
break;
case 0x72:
kprintf("Trace cache: 32K-uops, 8-way set associative\n");
break;
case 0x76:
kprintf("Instruction TLB: 2M/4M pages, fully associative, 8 entries\n");
break;
case 0x78:
kprintf("2nd-level cache: 1 MB, 4-way set associative, 64-byte line size\n");
break;
case 0x79:
kprintf("2nd-level cache: 128 KB, 8-way set associative, sectored cache, 64 byte line size\n");
break;
case 0x7a:
kprintf("2nd-level cache: 256 KB, 8-way set associative, sectored cache, 64 byte line size\n");
break;
case 0x7b:
kprintf("2nd-level cache: 512 KB, 8-way set associative, sectored cache, 64 byte line size\n");
break;
case 0x7c:
kprintf("2nd-level cache: 1 MB, 8-way set associative, sectored cache, 64 byte line size\n");
break;
case 0x7d:
kprintf("2nd-level cache: 2-MB, 8-way set associative, 64-byte line size\n");
break;
case 0x7f:
kprintf("2nd-level cache: 512-KB, 2-way set associative, 64-byte line size\n");
break;
case 0x80:
kprintf("2nd-level cache: 512 KByte, 8-way set associative, 64-byte line size\n");
break;
case 0x82:
kprintf("2nd-level cache: 256 KB, 8-way set associative, 32 byte line size\n");
break;
case 0x83:
kprintf("2nd-level cache: 512 KB, 8-way set associative, 32 byte line size\n");
break;
case 0x84:
kprintf("2nd-level cache: 1 MB, 8-way set associative, 32 byte line size\n");
break;
case 0x85:
kprintf("2nd-level cache: 2 MB, 8-way set associative, 32 byte line size\n");
break;
case 0x86:
kprintf("2nd-level cache: 512 KB, 4-way set associative, 64 byte line size\n");
break;
case 0x87:
kprintf("2nd-level cache: 1 MB, 8-way set associative, 64 byte line size\n");
break;
case 0xa0:
kprintf("DTLB: 4k pages, fully associative, 32 entries\n");
break;
case 0xb0:
kprintf("Instruction TLB: 4 KB Pages, 4-way set associative, 128 entries\n");
break;
case 0xb1:
kprintf("Instruction TLB: 2M pages, 4-way, 8 entries or 4M pages, 4-way, 4 entries\n");
break;
case 0xb2:
kprintf("Instruction TLB: 4KByte pages, 4-way set associative, 64 entries\n");
break;
case 0xb3:
kprintf("Data TLB: 4 KB Pages, 4-way set associative, 128 entries\n");
break;
case 0xb4:
kprintf("Data TLB1: 4 KByte pages, 4-way associative, 256 entries\n");
break;
case 0xb5:
kprintf("Instruction TLB: 4KByte pages, 8-way set associative, 64 entries\n");
break;
case 0xb6:
kprintf("Instruction TLB: 4KByte pages, 8-way set associative, 128 entries\n");
break;
case 0xba:
kprintf("Data TLB1: 4 KByte pages, 4-way associative, 64 entries\n");
break;
case 0xc0:
kprintf("Data TLB: 4 KByte and 4 MByte pages, 4-way associative, 8 entries\n");
break;
case 0xc1:
kprintf("Shared 2nd-Level TLB: 4 KByte/2MByte pages, 8-way associative, 1024 entries\n");
break;
case 0xc2:
kprintf("DTLB: 4 KByte/2 MByte pages, 4-way associative, 16 entries\n");
break;
case 0xc3:
kprintf("Shared 2nd-Level TLB: 4 KByte /2 MByte pages, 6-way associative, 1536 entries. Also 1GBbyte pages, 4-way, 16 entries\n");
break;
case 0xc4:
kprintf("DTLB: 2M/4M Byte pages, 4-way associative, 32 entries\n");
break;
case 0xca:
kprintf("Shared 2nd-Level TLB: 4 KByte pages, 4-way associative, 512 entries\n");
break;
case 0xd0:
kprintf("3rd-level cache: 512 KByte, 4-way set associative, 64 byte line size\n");
break;
case 0xd1:
kprintf("3rd-level cache: 1 MByte, 4-way set associative, 64 byte line size\n");
break;
case 0xd2:
kprintf("3rd-level cache: 2 MByte, 4-way set associative, 64 byte line size\n");
break;
case 0xd6:
kprintf("3rd-level cache: 1 MByte, 8-way set associative, 64 byte line size\n");
break;
case 0xd7:
kprintf("3rd-level cache: 2 MByte, 8-way set associative, 64 byte line size\n");
break;
case 0xd8:
kprintf("3rd-level cache: 4 MByte, 8-way set associative, 64 byte line size\n");
break;
case 0xdc:
kprintf("3rd-level cache: 1.5 MByte, 12-way set associative, 64 byte line size\n");
break;
case 0xdd:
kprintf("3rd-level cache: 3 MByte, 12-way set associative, 64 byte line size\n");
break;
case 0xde:
kprintf("3rd-level cache: 6 MByte, 12-way set associative, 64 byte line size\n");
break;
case 0xe2:
kprintf("3rd-level cache: 2 MByte, 16-way set associative, 64 byte line size\n");
break;
case 0xe3:
kprintf("3rd-level cache: 4 MByte, 16-way set associative, 64 byte line size\n");
break;
case 0xe4:
kprintf("3rd-level cache: 8 MByte, 16-way set associative, 64 byte line size\n");
break;
case 0xea:
kprintf("3rd-level cache: 12MByte, 24-way set associative, 64 byte line size\n");
break;
case 0xeb:
kprintf("3rd-level cache: 18MByte, 24-way set associative, 64 byte line size\n");
break;
case 0xec:
kprintf("3rd-level cache: 24MByte, 24-way set associative, 64 byte line size\n");
break;
case 0xf0:
kprintf("64-Byte prefetching\n");
break;
case 0xf1:
kprintf("128-Byte prefetching\n");
break;
}
}
static void
print_INTEL_info(void)
{
u_int regs[4];
u_int rounds, regnum;
u_int nwaycode, nway;
if (cpu_high >= 2) {
rounds = 0;
do {
do_cpuid(0x2, regs);
if (rounds == 0 && (rounds = (regs[0] & 0xff)) == 0)
break;
for (regnum = 0; regnum <= 3; ++regnum) {
if (regs[regnum] & (1<<31))
continue;
if (regnum != 0)
print_INTEL_TLB(regs[regnum] & 0xff);
print_INTEL_TLB((regs[regnum] >> 8) & 0xff);
print_INTEL_TLB((regs[regnum] >> 16) & 0xff);
print_INTEL_TLB((regs[regnum] >> 24) & 0xff);
}
} while (--rounds > 0);
}
if (cpu_exthigh >= 0x80000006) {
do_cpuid(0x80000006, regs);
nwaycode = (regs[2] >> 12) & 0x0f;
if (nwaycode >= 0x02 && nwaycode <= 0x08)
nway = 1 << (nwaycode / 2);
else
nway = 0;
kprintf("L2 cache: %u kbytes, %u-way associative, "
"%u bytes/line\n",
(regs[2] >> 16) & 0xffff, nway, regs[2] & 0xff);
}
}
static void
print_via_padlock_info(void)
{
u_int regs[4];
switch (cpu_id & 0xff0) {
case 0x690:
if ((cpu_id & 0xf) < 3)
return;
case 0x6a0:
case 0x6d0:
case 0x6f0:
break;
default:
return;
}
do_cpuid(0xc0000000, regs);
if (regs[0] >= 0xc0000001)
do_cpuid(0xc0000001, regs);
else
return;
kprintf("\n VIA Padlock Features=0x%pb%i",
"\020"
"\003RNG"
"\007AES"
"\011AES-CTR"
"\013SHA1,SHA256"
"\015RSA"
, regs[3]);
}
static void
print_xsave_info(void)
{
u_int regs[4];
cpuid_count(0xd, 0x1, regs);
if (regs[0] == 0)
return;
kprintf("\n XSAVE Features=0x%pb%i",
"\020"
"\001XSAVEOPT"
"\002XSAVEC"
"\003XGETBV"
"\004XSAVES"
, regs[0]);
}
static void
print_svm_info(void)
{
u_int features, regs[4];
uint64_t msr;
kprintf("\n SVM: ");
do_cpuid(0x8000000A, regs);
features = regs[3];
msr = rdmsr(MSR_AMD_VM_CR);
if ((msr & VM_CR_SVMDIS) && (msr & VM_CR_LOCK))
kprintf("(disabled in BIOS) ");
kprintf("Features=0x%pb%i",
"\020"
"\001NP"
"\002LbrVirt"
"\003SVML"
"\004NRIPS"
"\005TscRateMsr"
"\006VmcbClean"
"\007FlushByAsid"
"\010DecodeAssist"
"\011<b8>"
"\012<b9>"
"\013PauseFilter"
"\014EncryptedMcodePatch"
"\015PauseFilterThreshold"
"\016AVIC"
"\017<b14>"
"\020V_VMSAVE_VMLOAD"
"\021vGIF"
"\022GMET"
"\023<b18>"
"\024<b19>"
"\025SpecCtrl"
"\026<b21>"
"\027<b22>"
"\030<b23>"
"\031TlbICtrl"
"\032<b25>"
"\033<b26>"
"\034<b27>"
"\035<b28>"
"\036<b29>"
"\037<b30>"
"\040<b31>"
, features);
kprintf("\n Revision=%d, ASIDs=%d", regs[0] & 0xff, regs[1]);
}
static u_int
vmx_settable(uint64_t basic, int msr, int true_msr)
{
uint64_t val;
if (basic & (1ULL << 55))
val = rdmsr(true_msr);
else
val = rdmsr(msr);
return (u_int)(val >> 32);
}
static void
print_vmx_info(void)
{
uint64_t basic, msr;
u_int entry_ctls, exit_ctls, pin_ctls, proc_ctls, proc2_ctls;
kprintf("\n VT-x: ");
msr = rdmsr(MSR_IA32_FEATURE_CONTROL);
if ((msr & IA32_FEATURE_CONTROL_LOCK) != 0 &&
(msr & IA32_FEATURE_CONTROL_OUT_SMX) == 0)
kprintf("(disabled in BIOS) ");
basic = rdmsr(MSR_VMX_BASIC);
pin_ctls = vmx_settable(basic, MSR_VMX_PINBASED_CTLS,
MSR_VMX_TRUE_PINBASED_CTLS);
proc_ctls = vmx_settable(basic, MSR_VMX_PROCBASED_CTLS,
MSR_VMX_TRUE_PROCBASED_CTLS);
proc2_ctls = 0;
if (proc_ctls & (1U << 31 )) {
proc2_ctls = vmx_settable(basic, MSR_VMX_PROCBASED_CTLS2,
MSR_VMX_PROCBASED_CTLS2);
}
exit_ctls = vmx_settable(basic, MSR_VMX_EXIT_CTLS,
MSR_VMX_TRUE_EXIT_CTLS);
entry_ctls = vmx_settable(basic, MSR_VMX_ENTRY_CTLS,
MSR_VMX_TRUE_ENTRY_CTLS);
kprintf("Basic Features=0x%pb%i",
"\020"
"\02132PA"
"\022SMM"
"\027INS/OUTS"
"\030TRUE"
, (u_int)(basic >> 32));
kprintf("\n Pin-Based Controls=0x%pb%i",
"\020"
"\001ExtINT"
"\004NMI"
"\006VNMI"
"\007PreTmr"
"\010PostIntr"
, pin_ctls);
kprintf("\n Primary Processor Controls=0x%pb%i",
"\020"
"\003INTWIN"
"\004TSCOff"
"\010HLT"
"\012INVLPG"
"\013MWAIT"
"\014RDPMC"
"\015RDTSC"
"\020CR3-LD"
"\021CR3-ST"
"\024CR8-LD"
"\025CR8-ST"
"\026TPR"
"\027NMIWIN"
"\030MOV-DR"
"\031IO"
"\032IOmap"
"\034MTF"
"\035MSRmap"
"\036MONITOR"
"\037PAUSE"
, proc_ctls);
if (proc2_ctls != 0) {
kprintf("\n Secondary Processor Controls=0x%pb%i",
"\020"
"\001APIC"
"\002EPT"
"\003DT"
"\004RDTSCP"
"\005x2APIC"
"\006VPID"
"\007WBINVD"
"\010UG"
"\011APIC-reg"
"\012VID"
"\013PAUSE-loop"
"\014RDRAND"
"\015INVPCID"
"\016VMFUNC"
"\017VMCS"
"\020EPT#VE"
"\021XSAVES"
, proc2_ctls);
}
kprintf("\n Exit Controls=0x%pb%i",
"\020"
"\003DR"
"\015PERF"
"\012HostLMA"
"\020AckInt"
"\023PAT-SV"
"\024PAT-LD"
"\025EFER-SV"
"\026EFER-LD"
"\027PTMR-SV"
, exit_ctls);
kprintf("\n Entry Controls=0x%pb%i",
"\020"
"\003DR"
"\012GuestLMA"
"\016PERF"
"\017PAT"
"\020EFER"
, entry_ctls);
if ((proc2_ctls & (1U << 1 )) ||
(proc2_ctls & (1U << 5 )))
{
msr = rdmsr(MSR_VMX_EPT_VPID_CAP);
kprintf("\n EPT Features=0x%pb%i",
"\020"
"\001XO"
"\007PW4"
"\011UC"
"\017WB"
"\0212M"
"\0221G"
"\025INVEPT"
"\026AD"
"\032single"
"\033all"
, (u_int)msr);
kprintf("\n VPID Features=0x%pb%i",
"\020"
"\001INVVPID"
"\011individual"
"\012single"
"\013all"
"\014single-globals"
, (u_int)(msr >> 32));
}
}