10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 51582Skchow * Common Development and Distribution License (the "License"). 61582Skchow * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 225870Sgavinm * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 270Sstevel@tonic-gate 280Sstevel@tonic-gate /* 290Sstevel@tonic-gate * Various routines to handle identification 300Sstevel@tonic-gate * and classification of x86 processors. 310Sstevel@tonic-gate */ 320Sstevel@tonic-gate 330Sstevel@tonic-gate #include <sys/types.h> 340Sstevel@tonic-gate #include <sys/archsystm.h> 350Sstevel@tonic-gate #include <sys/x86_archext.h> 360Sstevel@tonic-gate #include <sys/kmem.h> 370Sstevel@tonic-gate #include <sys/systm.h> 380Sstevel@tonic-gate #include <sys/cmn_err.h> 390Sstevel@tonic-gate #include <sys/sunddi.h> 400Sstevel@tonic-gate #include <sys/sunndi.h> 410Sstevel@tonic-gate #include <sys/cpuvar.h> 420Sstevel@tonic-gate #include <sys/processor.h> 435045Sbholler #include <sys/sysmacros.h> 443434Sesaxe #include <sys/pg.h> 450Sstevel@tonic-gate #include <sys/fp.h> 460Sstevel@tonic-gate #include <sys/controlregs.h> 470Sstevel@tonic-gate #include <sys/auxv_386.h> 480Sstevel@tonic-gate #include <sys/bitmap.h> 490Sstevel@tonic-gate #include <sys/memnode.h> 500Sstevel@tonic-gate 510Sstevel@tonic-gate /* 520Sstevel@tonic-gate * Pass 0 of cpuid feature analysis happens in locore. It contains special code 530Sstevel@tonic-gate * to recognize Cyrix processors that are not cpuid-compliant, and to deal with 540Sstevel@tonic-gate * them accordingly. For most modern processors, feature detection occurs here 550Sstevel@tonic-gate * in pass 1. 560Sstevel@tonic-gate * 570Sstevel@tonic-gate * Pass 1 of cpuid feature analysis happens just at the beginning of mlsetup() 580Sstevel@tonic-gate * for the boot CPU and does the basic analysis that the early kernel needs. 590Sstevel@tonic-gate * x86_feature is set based on the return value of cpuid_pass1() of the boot 600Sstevel@tonic-gate * CPU. 610Sstevel@tonic-gate * 620Sstevel@tonic-gate * Pass 1 includes: 630Sstevel@tonic-gate * 640Sstevel@tonic-gate * o Determining vendor/model/family/stepping and setting x86_type and 650Sstevel@tonic-gate * x86_vendor accordingly. 660Sstevel@tonic-gate * o Processing the feature flags returned by the cpuid instruction while 670Sstevel@tonic-gate * applying any workarounds or tricks for the specific processor. 680Sstevel@tonic-gate * o Mapping the feature flags into Solaris feature bits (X86_*). 690Sstevel@tonic-gate * o Processing extended feature flags if supported by the processor, 700Sstevel@tonic-gate * again while applying specific processor knowledge. 710Sstevel@tonic-gate * o Determining the CMT characteristics of the system. 720Sstevel@tonic-gate * 730Sstevel@tonic-gate * Pass 1 is done on non-boot CPUs during their initialization and the results 740Sstevel@tonic-gate * are used only as a meager attempt at ensuring that all processors within the 750Sstevel@tonic-gate * system support the same features. 760Sstevel@tonic-gate * 770Sstevel@tonic-gate * Pass 2 of cpuid feature analysis happens just at the beginning 780Sstevel@tonic-gate * of startup(). It just copies in and corrects the remainder 790Sstevel@tonic-gate * of the cpuid data we depend on: standard cpuid functions that we didn't 800Sstevel@tonic-gate * need for pass1 feature analysis, and extended cpuid functions beyond the 810Sstevel@tonic-gate * simple feature processing done in pass1. 820Sstevel@tonic-gate * 830Sstevel@tonic-gate * Pass 3 of cpuid analysis is invoked after basic kernel services; in 840Sstevel@tonic-gate * particular kernel memory allocation has been made available. It creates a 850Sstevel@tonic-gate * readable brand string based on the data collected in the first two passes. 860Sstevel@tonic-gate * 870Sstevel@tonic-gate * Pass 4 of cpuid analysis is invoked after post_startup() when all 880Sstevel@tonic-gate * the support infrastructure for various hardware features has been 890Sstevel@tonic-gate * initialized. It determines which processor features will be reported 900Sstevel@tonic-gate * to userland via the aux vector. 910Sstevel@tonic-gate * 920Sstevel@tonic-gate * All passes are executed on all CPUs, but only the boot CPU determines what 930Sstevel@tonic-gate * features the kernel will use. 940Sstevel@tonic-gate * 950Sstevel@tonic-gate * Much of the worst junk in this file is for the support of processors 960Sstevel@tonic-gate * that didn't really implement the cpuid instruction properly. 970Sstevel@tonic-gate * 980Sstevel@tonic-gate * NOTE: The accessor functions (cpuid_get*) are aware of, and ASSERT upon, 990Sstevel@tonic-gate * the pass numbers. Accordingly, changes to the pass code may require changes 1000Sstevel@tonic-gate * to the accessor code. 1010Sstevel@tonic-gate */ 1020Sstevel@tonic-gate 1030Sstevel@tonic-gate uint_t x86_feature = 0; 1040Sstevel@tonic-gate uint_t x86_vendor = X86_VENDOR_IntelClone; 1050Sstevel@tonic-gate uint_t x86_type = X86_TYPE_OTHER; 1060Sstevel@tonic-gate 1070Sstevel@tonic-gate uint_t pentiumpro_bug4046376; 1080Sstevel@tonic-gate uint_t pentiumpro_bug4064495; 1090Sstevel@tonic-gate 1100Sstevel@tonic-gate uint_t enable486; 1110Sstevel@tonic-gate 1120Sstevel@tonic-gate /* 1130Sstevel@tonic-gate * This set of strings are for processors rumored to support the cpuid 1140Sstevel@tonic-gate * instruction, and is used by locore.s to figure out how to set x86_vendor 1150Sstevel@tonic-gate */ 1160Sstevel@tonic-gate const char CyrixInstead[] = "CyrixInstead"; 1170Sstevel@tonic-gate 1180Sstevel@tonic-gate /* 1194481Sbholler * monitor/mwait info. 1205045Sbholler * 1215045Sbholler * size_actual and buf_actual are the real address and size allocated to get 1225045Sbholler * proper mwait_buf alignement. buf_actual and size_actual should be passed 1235045Sbholler * to kmem_free(). Currently kmem_alloc() and mwait happen to both use 1245045Sbholler * processor cache-line alignment, but this is not guarantied in the furture. 1254481Sbholler */ 1264481Sbholler struct mwait_info { 1274481Sbholler size_t mon_min; /* min size to avoid missed wakeups */ 1284481Sbholler size_t mon_max; /* size to avoid false wakeups */ 1295045Sbholler size_t size_actual; /* size actually allocated */ 1305045Sbholler void *buf_actual; /* memory actually allocated */ 1314481Sbholler uint32_t support; /* processor support of monitor/mwait */ 1324481Sbholler }; 1334481Sbholler 1344481Sbholler /* 1350Sstevel@tonic-gate * These constants determine how many of the elements of the 1360Sstevel@tonic-gate * cpuid we cache in the cpuid_info data structure; the 1370Sstevel@tonic-gate * remaining elements are accessible via the cpuid instruction. 1380Sstevel@tonic-gate */ 1390Sstevel@tonic-gate 1400Sstevel@tonic-gate #define NMAX_CPI_STD 6 /* eax = 0 .. 5 */ 1410Sstevel@tonic-gate #define NMAX_CPI_EXTD 9 /* eax = 0x80000000 .. 0x80000008 */ 1420Sstevel@tonic-gate 1430Sstevel@tonic-gate struct cpuid_info { 1440Sstevel@tonic-gate uint_t cpi_pass; /* last pass completed */ 1450Sstevel@tonic-gate /* 1460Sstevel@tonic-gate * standard function information 1470Sstevel@tonic-gate */ 1480Sstevel@tonic-gate uint_t cpi_maxeax; /* fn 0: %eax */ 1490Sstevel@tonic-gate char cpi_vendorstr[13]; /* fn 0: %ebx:%ecx:%edx */ 1500Sstevel@tonic-gate uint_t cpi_vendor; /* enum of cpi_vendorstr */ 1510Sstevel@tonic-gate 1520Sstevel@tonic-gate uint_t cpi_family; /* fn 1: extended family */ 1530Sstevel@tonic-gate uint_t cpi_model; /* fn 1: extended model */ 1540Sstevel@tonic-gate uint_t cpi_step; /* fn 1: stepping */ 1550Sstevel@tonic-gate chipid_t cpi_chipid; /* fn 1: %ebx: chip # on ht cpus */ 1560Sstevel@tonic-gate uint_t cpi_brandid; /* fn 1: %ebx: brand ID */ 1570Sstevel@tonic-gate int cpi_clogid; /* fn 1: %ebx: thread # */ 1581228Sandrei uint_t cpi_ncpu_per_chip; /* fn 1: %ebx: logical cpu count */ 1590Sstevel@tonic-gate uint8_t cpi_cacheinfo[16]; /* fn 2: intel-style cache desc */ 1600Sstevel@tonic-gate uint_t cpi_ncache; /* fn 2: number of elements */ 1614606Sesaxe uint_t cpi_ncpu_shr_last_cache; /* fn 4: %eax: ncpus sharing cache */ 1624606Sesaxe id_t cpi_last_lvl_cacheid; /* fn 4: %eax: derived cache id */ 1634606Sesaxe uint_t cpi_std_4_size; /* fn 4: number of fn 4 elements */ 1644606Sesaxe struct cpuid_regs **cpi_std_4; /* fn 4: %ecx == 0 .. fn4_size */ 1651228Sandrei struct cpuid_regs cpi_std[NMAX_CPI_STD]; /* 0 .. 5 */ 1660Sstevel@tonic-gate /* 1670Sstevel@tonic-gate * extended function information 1680Sstevel@tonic-gate */ 1690Sstevel@tonic-gate uint_t cpi_xmaxeax; /* fn 0x80000000: %eax */ 1700Sstevel@tonic-gate char cpi_brandstr[49]; /* fn 0x8000000[234] */ 1710Sstevel@tonic-gate uint8_t cpi_pabits; /* fn 0x80000006: %eax */ 1720Sstevel@tonic-gate uint8_t cpi_vabits; /* fn 0x80000006: %eax */ 1731228Sandrei struct cpuid_regs cpi_extd[NMAX_CPI_EXTD]; /* 0x8000000[0-8] */ 1745870Sgavinm id_t cpi_coreid; /* same coreid => strands share core */ 1755870Sgavinm int cpi_pkgcoreid; /* core number within single package */ 1761228Sandrei uint_t cpi_ncore_per_chip; /* AMD: fn 0x80000008: %ecx[7-0] */ 1771228Sandrei /* Intel: fn 4: %eax[31-26] */ 1780Sstevel@tonic-gate /* 1790Sstevel@tonic-gate * supported feature information 1800Sstevel@tonic-gate */ 1813446Smrj uint32_t cpi_support[5]; 1820Sstevel@tonic-gate #define STD_EDX_FEATURES 0 1830Sstevel@tonic-gate #define AMD_EDX_FEATURES 1 1840Sstevel@tonic-gate #define TM_EDX_FEATURES 2 1850Sstevel@tonic-gate #define STD_ECX_FEATURES 3 1863446Smrj #define AMD_ECX_FEATURES 4 1872869Sgavinm /* 1882869Sgavinm * Synthesized information, where known. 1892869Sgavinm */ 1902869Sgavinm uint32_t cpi_chiprev; /* See X86_CHIPREV_* in x86_archext.h */ 1912869Sgavinm const char *cpi_chiprevstr; /* May be NULL if chiprev unknown */ 1922869Sgavinm uint32_t cpi_socket; /* Chip package/socket type */ 1934481Sbholler 1944481Sbholler struct mwait_info cpi_mwait; /* fn 5: monitor/mwait info */ 1950Sstevel@tonic-gate }; 1960Sstevel@tonic-gate 1970Sstevel@tonic-gate 1980Sstevel@tonic-gate static struct cpuid_info cpuid_info0; 1990Sstevel@tonic-gate 2000Sstevel@tonic-gate /* 2010Sstevel@tonic-gate * These bit fields are defined by the Intel Application Note AP-485 2020Sstevel@tonic-gate * "Intel Processor Identification and the CPUID Instruction" 2030Sstevel@tonic-gate */ 2040Sstevel@tonic-gate #define CPI_FAMILY_XTD(cpi) BITX((cpi)->cpi_std[1].cp_eax, 27, 20) 2050Sstevel@tonic-gate #define CPI_MODEL_XTD(cpi) BITX((cpi)->cpi_std[1].cp_eax, 19, 16) 2060Sstevel@tonic-gate #define CPI_TYPE(cpi) BITX((cpi)->cpi_std[1].cp_eax, 13, 12) 2070Sstevel@tonic-gate #define CPI_FAMILY(cpi) BITX((cpi)->cpi_std[1].cp_eax, 11, 8) 2080Sstevel@tonic-gate #define CPI_STEP(cpi) BITX((cpi)->cpi_std[1].cp_eax, 3, 0) 2090Sstevel@tonic-gate #define CPI_MODEL(cpi) BITX((cpi)->cpi_std[1].cp_eax, 7, 4) 2100Sstevel@tonic-gate 2110Sstevel@tonic-gate #define CPI_FEATURES_EDX(cpi) ((cpi)->cpi_std[1].cp_edx) 2120Sstevel@tonic-gate #define CPI_FEATURES_ECX(cpi) ((cpi)->cpi_std[1].cp_ecx) 2130Sstevel@tonic-gate #define CPI_FEATURES_XTD_EDX(cpi) ((cpi)->cpi_extd[1].cp_edx) 2140Sstevel@tonic-gate #define CPI_FEATURES_XTD_ECX(cpi) ((cpi)->cpi_extd[1].cp_ecx) 2150Sstevel@tonic-gate 2160Sstevel@tonic-gate #define CPI_BRANDID(cpi) BITX((cpi)->cpi_std[1].cp_ebx, 7, 0) 2170Sstevel@tonic-gate #define CPI_CHUNKS(cpi) BITX((cpi)->cpi_std[1].cp_ebx, 15, 7) 2180Sstevel@tonic-gate #define CPI_CPU_COUNT(cpi) BITX((cpi)->cpi_std[1].cp_ebx, 23, 16) 2190Sstevel@tonic-gate #define CPI_APIC_ID(cpi) BITX((cpi)->cpi_std[1].cp_ebx, 31, 24) 2200Sstevel@tonic-gate 2210Sstevel@tonic-gate #define CPI_MAXEAX_MAX 0x100 /* sanity control */ 2220Sstevel@tonic-gate #define CPI_XMAXEAX_MAX 0x80000100 2234606Sesaxe #define CPI_FN4_ECX_MAX 0x20 /* sanity: max fn 4 levels */ 2244606Sesaxe 2254606Sesaxe /* 2264606Sesaxe * Function 4 (Deterministic Cache Parameters) macros 2274606Sesaxe * Defined by Intel Application Note AP-485 2284606Sesaxe */ 2294606Sesaxe #define CPI_NUM_CORES(regs) BITX((regs)->cp_eax, 31, 26) 2304606Sesaxe #define CPI_NTHR_SHR_CACHE(regs) BITX((regs)->cp_eax, 25, 14) 2314606Sesaxe #define CPI_FULL_ASSOC_CACHE(regs) BITX((regs)->cp_eax, 9, 9) 2324606Sesaxe #define CPI_SELF_INIT_CACHE(regs) BITX((regs)->cp_eax, 8, 8) 2334606Sesaxe #define CPI_CACHE_LVL(regs) BITX((regs)->cp_eax, 7, 5) 2344606Sesaxe #define CPI_CACHE_TYPE(regs) BITX((regs)->cp_eax, 4, 0) 2354606Sesaxe 2364606Sesaxe #define CPI_CACHE_WAYS(regs) BITX((regs)->cp_ebx, 31, 22) 2374606Sesaxe #define CPI_CACHE_PARTS(regs) BITX((regs)->cp_ebx, 21, 12) 2384606Sesaxe #define CPI_CACHE_COH_LN_SZ(regs) BITX((regs)->cp_ebx, 11, 0) 2394606Sesaxe 2404606Sesaxe #define CPI_CACHE_SETS(regs) BITX((regs)->cp_ecx, 31, 0) 2414606Sesaxe 2424606Sesaxe #define CPI_PREFCH_STRIDE(regs) BITX((regs)->cp_edx, 9, 0) 2434606Sesaxe 2440Sstevel@tonic-gate 2450Sstevel@tonic-gate /* 2461975Sdmick * A couple of shorthand macros to identify "later" P6-family chips 2471975Sdmick * like the Pentium M and Core. First, the "older" P6-based stuff 2481975Sdmick * (loosely defined as "pre-Pentium-4"): 2491975Sdmick * P6, PII, Mobile PII, PII Xeon, PIII, Mobile PIII, PIII Xeon 2501975Sdmick */ 2511975Sdmick 2521975Sdmick #define IS_LEGACY_P6(cpi) ( \ 2531975Sdmick cpi->cpi_family == 6 && \ 2541975Sdmick (cpi->cpi_model == 1 || \ 2551975Sdmick cpi->cpi_model == 3 || \ 2561975Sdmick cpi->cpi_model == 5 || \ 2571975Sdmick cpi->cpi_model == 6 || \ 2581975Sdmick cpi->cpi_model == 7 || \ 2591975Sdmick cpi->cpi_model == 8 || \ 2601975Sdmick cpi->cpi_model == 0xA || \ 2611975Sdmick cpi->cpi_model == 0xB) \ 2621975Sdmick ) 2631975Sdmick 2641975Sdmick /* A "new F6" is everything with family 6 that's not the above */ 2651975Sdmick #define IS_NEW_F6(cpi) ((cpi->cpi_family == 6) && !IS_LEGACY_P6(cpi)) 2661975Sdmick 2674855Sksadhukh /* Extended family/model support */ 2684855Sksadhukh #define IS_EXTENDED_MODEL_INTEL(cpi) (cpi->cpi_family == 0x6 || \ 2694855Sksadhukh cpi->cpi_family >= 0xf) 2704855Sksadhukh 2711975Sdmick /* 2725248Sksadhukh * AMD family 0xf and family 0x10 socket types. 2735248Sksadhukh * First index : 2745248Sksadhukh * 0 for family 0xf, revs B thru E 2755248Sksadhukh * 1 for family 0xf, revs F and G 2765248Sksadhukh * 2 for family 0x10, rev B 2772869Sgavinm * Second index by (model & 0x3) 2782869Sgavinm */ 2795248Sksadhukh static uint32_t amd_skts[3][4] = { 2805254Sgavinm /* 2815254Sgavinm * Family 0xf revisions B through E 2825254Sgavinm */ 2835254Sgavinm #define A_SKTS_0 0 2842869Sgavinm { 2852869Sgavinm X86_SOCKET_754, /* 0b00 */ 2862869Sgavinm X86_SOCKET_940, /* 0b01 */ 2872869Sgavinm X86_SOCKET_754, /* 0b10 */ 2882869Sgavinm X86_SOCKET_939 /* 0b11 */ 2892869Sgavinm }, 2905254Sgavinm /* 2915254Sgavinm * Family 0xf revisions F and G 2925254Sgavinm */ 2935254Sgavinm #define A_SKTS_1 1 2942869Sgavinm { 2952869Sgavinm X86_SOCKET_S1g1, /* 0b00 */ 2962869Sgavinm X86_SOCKET_F1207, /* 0b01 */ 2972869Sgavinm X86_SOCKET_UNKNOWN, /* 0b10 */ 2982869Sgavinm X86_SOCKET_AM2 /* 0b11 */ 2995248Sksadhukh }, 3005254Sgavinm /* 3015254Sgavinm * Family 0x10 revisions A and B 3025254Sgavinm * It is not clear whether, as new sockets release, that 3035254Sgavinm * model & 0x3 will id socket for this family 3045254Sgavinm */ 3055254Sgavinm #define A_SKTS_2 2 3065248Sksadhukh { 3075248Sksadhukh X86_SOCKET_F1207, /* 0b00 */ 3085248Sksadhukh X86_SOCKET_F1207, /* 0b01 */ 3095248Sksadhukh X86_SOCKET_F1207, /* 0b10 */ 3105254Sgavinm X86_SOCKET_F1207, /* 0b11 */ 3112869Sgavinm } 3122869Sgavinm }; 3132869Sgavinm 3142869Sgavinm /* 3155248Sksadhukh * Table for mapping AMD Family 0xf and AMD Family 0x10 model/stepping 3165248Sksadhukh * combination to chip "revision" and socket type. 3172869Sgavinm * 3182869Sgavinm * The first member of this array that matches a given family, extended model 3192869Sgavinm * plus model range, and stepping range will be considered a match. 3202869Sgavinm */ 3212869Sgavinm static const struct amd_rev_mapent { 3222869Sgavinm uint_t rm_family; 3232869Sgavinm uint_t rm_modello; 3242869Sgavinm uint_t rm_modelhi; 3252869Sgavinm uint_t rm_steplo; 3262869Sgavinm uint_t rm_stephi; 3272869Sgavinm uint32_t rm_chiprev; 3282869Sgavinm const char *rm_chiprevstr; 3292869Sgavinm int rm_sktidx; 3302869Sgavinm } amd_revmap[] = { 3312869Sgavinm /* 3325254Sgavinm * =============== AuthenticAMD Family 0xf =============== 3335254Sgavinm */ 3345254Sgavinm 3355254Sgavinm /* 3362869Sgavinm * Rev B includes model 0x4 stepping 0 and model 0x5 stepping 0 and 1. 3372869Sgavinm */ 3385254Sgavinm { 0xf, 0x04, 0x04, 0x0, 0x0, X86_CHIPREV_AMD_F_REV_B, "B", A_SKTS_0 }, 3395254Sgavinm { 0xf, 0x05, 0x05, 0x0, 0x1, X86_CHIPREV_AMD_F_REV_B, "B", A_SKTS_0 }, 3402869Sgavinm /* 3412869Sgavinm * Rev C0 includes model 0x4 stepping 8 and model 0x5 stepping 8 3422869Sgavinm */ 3435254Sgavinm { 0xf, 0x04, 0x05, 0x8, 0x8, X86_CHIPREV_AMD_F_REV_C0, "C0", A_SKTS_0 }, 3442869Sgavinm /* 3452869Sgavinm * Rev CG is the rest of extended model 0x0 - i.e., everything 3462869Sgavinm * but the rev B and C0 combinations covered above. 3472869Sgavinm */ 3485254Sgavinm { 0xf, 0x00, 0x0f, 0x0, 0xf, X86_CHIPREV_AMD_F_REV_CG, "CG", A_SKTS_0 }, 3492869Sgavinm /* 3502869Sgavinm * Rev D has extended model 0x1. 3512869Sgavinm */ 3525254Sgavinm { 0xf, 0x10, 0x1f, 0x0, 0xf, X86_CHIPREV_AMD_F_REV_D, "D", A_SKTS_0 }, 3532869Sgavinm /* 3542869Sgavinm * Rev E has extended model 0x2. 3552869Sgavinm * Extended model 0x3 is unused but available to grow into. 3562869Sgavinm */ 3575254Sgavinm { 0xf, 0x20, 0x3f, 0x0, 0xf, X86_CHIPREV_AMD_F_REV_E, "E", A_SKTS_0 }, 3582869Sgavinm /* 3592869Sgavinm * Rev F has extended models 0x4 and 0x5. 3602869Sgavinm */ 3615254Sgavinm { 0xf, 0x40, 0x5f, 0x0, 0xf, X86_CHIPREV_AMD_F_REV_F, "F", A_SKTS_1 }, 3622869Sgavinm /* 3632869Sgavinm * Rev G has extended model 0x6. 3642869Sgavinm */ 3655254Sgavinm { 0xf, 0x60, 0x6f, 0x0, 0xf, X86_CHIPREV_AMD_F_REV_G, "G", A_SKTS_1 }, 3665254Sgavinm 3675254Sgavinm /* 3685254Sgavinm * =============== AuthenticAMD Family 0x10 =============== 3695254Sgavinm */ 3705254Sgavinm 3715248Sksadhukh /* 3725254Sgavinm * Rev A has model 0 and stepping 0/1/2 for DR-{A0,A1,A2}. 3735254Sgavinm * Give all of model 0 stepping range to rev A. 3745248Sksadhukh */ 3755254Sgavinm { 0x10, 0x00, 0x00, 0x0, 0x2, X86_CHIPREV_AMD_10_REV_A, "A", A_SKTS_2 }, 3765254Sgavinm 3775254Sgavinm /* 3785254Sgavinm * Rev B has model 2 and steppings 0/1/0xa/2 for DR-{B0,B1,BA,B2}. 3795254Sgavinm * Give all of model 2 stepping range to rev B. 3805254Sgavinm */ 3815254Sgavinm { 0x10, 0x02, 0x02, 0x0, 0xf, X86_CHIPREV_AMD_10_REV_B, "B", A_SKTS_2 }, 3822869Sgavinm }; 3832869Sgavinm 3844481Sbholler /* 3854481Sbholler * Info for monitor/mwait idle loop. 3864481Sbholler * 3874481Sbholler * See cpuid section of "Intel 64 and IA-32 Architectures Software Developer's 3884481Sbholler * Manual Volume 2A: Instruction Set Reference, A-M" #25366-022US, November 3894481Sbholler * 2006. 3904481Sbholler * See MONITOR/MWAIT section of "AMD64 Architecture Programmer's Manual 3914481Sbholler * Documentation Updates" #33633, Rev 2.05, December 2006. 3924481Sbholler */ 3934481Sbholler #define MWAIT_SUPPORT (0x00000001) /* mwait supported */ 3944481Sbholler #define MWAIT_EXTENSIONS (0x00000002) /* extenstion supported */ 3954481Sbholler #define MWAIT_ECX_INT_ENABLE (0x00000004) /* ecx 1 extension supported */ 3964481Sbholler #define MWAIT_SUPPORTED(cpi) ((cpi)->cpi_std[1].cp_ecx & CPUID_INTC_ECX_MON) 3974481Sbholler #define MWAIT_INT_ENABLE(cpi) ((cpi)->cpi_std[5].cp_ecx & 0x2) 3984481Sbholler #define MWAIT_EXTENSION(cpi) ((cpi)->cpi_std[5].cp_ecx & 0x1) 3994481Sbholler #define MWAIT_SIZE_MIN(cpi) BITX((cpi)->cpi_std[5].cp_eax, 15, 0) 4004481Sbholler #define MWAIT_SIZE_MAX(cpi) BITX((cpi)->cpi_std[5].cp_ebx, 15, 0) 4014481Sbholler /* 4024481Sbholler * Number of sub-cstates for a given c-state. 4034481Sbholler */ 4044481Sbholler #define MWAIT_NUM_SUBC_STATES(cpi, c_state) \ 4054481Sbholler BITX((cpi)->cpi_std[5].cp_edx, c_state + 3, c_state) 4064481Sbholler 4072869Sgavinm static void 4082869Sgavinm synth_amd_info(struct cpuid_info *cpi) 4092869Sgavinm { 4102869Sgavinm const struct amd_rev_mapent *rmp; 4112869Sgavinm uint_t family, model, step; 4122869Sgavinm int i; 4132869Sgavinm 4142869Sgavinm /* 4155248Sksadhukh * Currently only AMD family 0xf and family 0x10 use these fields. 4162869Sgavinm */ 4175248Sksadhukh if (cpi->cpi_family != 0xf && cpi->cpi_family != 0x10) 4182869Sgavinm return; 4192869Sgavinm 4202869Sgavinm family = cpi->cpi_family; 4212869Sgavinm model = cpi->cpi_model; 4222869Sgavinm step = cpi->cpi_step; 4232869Sgavinm 4242869Sgavinm for (i = 0, rmp = amd_revmap; i < sizeof (amd_revmap) / sizeof (*rmp); 4252869Sgavinm i++, rmp++) { 4262869Sgavinm if (family == rmp->rm_family && 4272869Sgavinm model >= rmp->rm_modello && model <= rmp->rm_modelhi && 4282869Sgavinm step >= rmp->rm_steplo && step <= rmp->rm_stephi) { 4292869Sgavinm cpi->cpi_chiprev = rmp->rm_chiprev; 4302869Sgavinm cpi->cpi_chiprevstr = rmp->rm_chiprevstr; 4312869Sgavinm cpi->cpi_socket = amd_skts[rmp->rm_sktidx][model & 0x3]; 4322869Sgavinm return; 4332869Sgavinm } 4342869Sgavinm } 4352869Sgavinm } 4362869Sgavinm 4372869Sgavinm static void 4382869Sgavinm synth_info(struct cpuid_info *cpi) 4392869Sgavinm { 4402869Sgavinm cpi->cpi_chiprev = X86_CHIPREV_UNKNOWN; 4412869Sgavinm cpi->cpi_chiprevstr = "Unknown"; 4422869Sgavinm cpi->cpi_socket = X86_SOCKET_UNKNOWN; 4432869Sgavinm 4442869Sgavinm switch (cpi->cpi_vendor) { 4452869Sgavinm case X86_VENDOR_AMD: 4462869Sgavinm synth_amd_info(cpi); 4472869Sgavinm break; 4482869Sgavinm 4492869Sgavinm default: 4502869Sgavinm break; 4512869Sgavinm 4522869Sgavinm } 4532869Sgavinm } 4542869Sgavinm 4552869Sgavinm /* 4563446Smrj * Apply up various platform-dependent restrictions where the 4573446Smrj * underlying platform restrictions mean the CPU can be marked 4583446Smrj * as less capable than its cpuid instruction would imply. 4593446Smrj */ 4605084Sjohnlev #if defined(__xpv) 4615084Sjohnlev static void 4625084Sjohnlev platform_cpuid_mangle(uint_t vendor, uint32_t eax, struct cpuid_regs *cp) 4635084Sjohnlev { 4645084Sjohnlev switch (eax) { 4655084Sjohnlev case 1: 4665084Sjohnlev cp->cp_edx &= 4675084Sjohnlev ~(CPUID_INTC_EDX_PSE | 4685084Sjohnlev CPUID_INTC_EDX_VME | CPUID_INTC_EDX_DE | 4695084Sjohnlev CPUID_INTC_EDX_MCA | /* XXPV true on dom0? */ 4705084Sjohnlev CPUID_INTC_EDX_SEP | CPUID_INTC_EDX_MTRR | 4715084Sjohnlev CPUID_INTC_EDX_PGE | CPUID_INTC_EDX_PAT | 4725084Sjohnlev CPUID_AMD_EDX_SYSC | CPUID_INTC_EDX_SEP | 4735084Sjohnlev CPUID_INTC_EDX_PSE36 | CPUID_INTC_EDX_HTT); 4745084Sjohnlev break; 4755084Sjohnlev 4765084Sjohnlev case 0x80000001: 4775084Sjohnlev cp->cp_edx &= 4785084Sjohnlev ~(CPUID_AMD_EDX_PSE | 4795084Sjohnlev CPUID_INTC_EDX_VME | CPUID_INTC_EDX_DE | 4805084Sjohnlev CPUID_AMD_EDX_MTRR | CPUID_AMD_EDX_PGE | 4815084Sjohnlev CPUID_AMD_EDX_PAT | CPUID_AMD_EDX_PSE36 | 4825084Sjohnlev CPUID_AMD_EDX_SYSC | CPUID_INTC_EDX_SEP | 4835084Sjohnlev CPUID_AMD_EDX_TSCP); 4845084Sjohnlev cp->cp_ecx &= ~CPUID_AMD_ECX_CMP_LGCY; 4855084Sjohnlev break; 4865084Sjohnlev default: 4875084Sjohnlev break; 4885084Sjohnlev } 4895084Sjohnlev 4905084Sjohnlev switch (vendor) { 4915084Sjohnlev case X86_VENDOR_Intel: 4925084Sjohnlev switch (eax) { 4935084Sjohnlev case 4: 4945084Sjohnlev /* 4955084Sjohnlev * Zero out the (ncores-per-chip - 1) field 4965084Sjohnlev */ 4975084Sjohnlev cp->cp_eax &= 0x03fffffff; 4985084Sjohnlev break; 4995084Sjohnlev default: 5005084Sjohnlev break; 5015084Sjohnlev } 5025084Sjohnlev break; 5035084Sjohnlev case X86_VENDOR_AMD: 5045084Sjohnlev switch (eax) { 5055084Sjohnlev case 0x80000008: 5065084Sjohnlev /* 5075084Sjohnlev * Zero out the (ncores-per-chip - 1) field 5085084Sjohnlev */ 5095084Sjohnlev cp->cp_ecx &= 0xffffff00; 5105084Sjohnlev break; 5115084Sjohnlev default: 5125084Sjohnlev break; 5135084Sjohnlev } 5145084Sjohnlev break; 5155084Sjohnlev default: 5165084Sjohnlev break; 5175084Sjohnlev } 5185084Sjohnlev } 5195084Sjohnlev #else 5203446Smrj #define platform_cpuid_mangle(vendor, eax, cp) /* nothing */ 5215084Sjohnlev #endif 5223446Smrj 5233446Smrj /* 5240Sstevel@tonic-gate * Some undocumented ways of patching the results of the cpuid 5250Sstevel@tonic-gate * instruction to permit running Solaris 10 on future cpus that 5260Sstevel@tonic-gate * we don't currently support. Could be set to non-zero values 5270Sstevel@tonic-gate * via settings in eeprom. 5280Sstevel@tonic-gate */ 5290Sstevel@tonic-gate 5300Sstevel@tonic-gate uint32_t cpuid_feature_ecx_include; 5310Sstevel@tonic-gate uint32_t cpuid_feature_ecx_exclude; 5320Sstevel@tonic-gate uint32_t cpuid_feature_edx_include; 5330Sstevel@tonic-gate uint32_t cpuid_feature_edx_exclude; 5340Sstevel@tonic-gate 5353446Smrj void 5363446Smrj cpuid_alloc_space(cpu_t *cpu) 5373446Smrj { 5383446Smrj /* 5393446Smrj * By convention, cpu0 is the boot cpu, which is set up 5403446Smrj * before memory allocation is available. All other cpus get 5413446Smrj * their cpuid_info struct allocated here. 5423446Smrj */ 5433446Smrj ASSERT(cpu->cpu_id != 0); 5443446Smrj cpu->cpu_m.mcpu_cpi = 5453446Smrj kmem_zalloc(sizeof (*cpu->cpu_m.mcpu_cpi), KM_SLEEP); 5463446Smrj } 5473446Smrj 5483446Smrj void 5493446Smrj cpuid_free_space(cpu_t *cpu) 5503446Smrj { 5514606Sesaxe struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 5524606Sesaxe int i; 5534606Sesaxe 5543446Smrj ASSERT(cpu->cpu_id != 0); 5554606Sesaxe 5564606Sesaxe /* 5574606Sesaxe * Free up any function 4 related dynamic storage 5584606Sesaxe */ 5594606Sesaxe for (i = 1; i < cpi->cpi_std_4_size; i++) 5604606Sesaxe kmem_free(cpi->cpi_std_4[i], sizeof (struct cpuid_regs)); 5614606Sesaxe if (cpi->cpi_std_4_size > 0) 5624606Sesaxe kmem_free(cpi->cpi_std_4, 5634606Sesaxe cpi->cpi_std_4_size * sizeof (struct cpuid_regs *)); 5644606Sesaxe 5653446Smrj kmem_free(cpu->cpu_m.mcpu_cpi, sizeof (*cpu->cpu_m.mcpu_cpi)); 5663446Smrj } 5673446Smrj 5685741Smrj #if !defined(__xpv) 5695741Smrj 5705741Smrj static void 5715741Smrj check_for_hvm() 5725741Smrj { 5735741Smrj struct cpuid_regs cp; 5745741Smrj char *xen_str; 5755741Smrj uint32_t xen_signature[4]; 5765741Smrj extern int xpv_is_hvm; 5775741Smrj 5785741Smrj /* 5795741Smrj * In a fully virtualized domain, Xen's pseudo-cpuid function 5805741Smrj * 0x40000000 returns a string representing the Xen signature in 5815741Smrj * %ebx, %ecx, and %edx. %eax contains the maximum supported cpuid 5825741Smrj * function. 5835741Smrj */ 5845741Smrj cp.cp_eax = 0x40000000; 5855741Smrj (void) __cpuid_insn(&cp); 5865741Smrj xen_signature[0] = cp.cp_ebx; 5875741Smrj xen_signature[1] = cp.cp_ecx; 5885741Smrj xen_signature[2] = cp.cp_edx; 5895741Smrj xen_signature[3] = 0; 5905741Smrj xen_str = (char *)xen_signature; 5915741Smrj if (strcmp("XenVMMXenVMM", xen_str) == 0 && cp.cp_eax <= 0x40000002) 5925741Smrj xpv_is_hvm = 1; 5935741Smrj } 5945741Smrj #endif /* __xpv */ 5955741Smrj 5960Sstevel@tonic-gate uint_t 5970Sstevel@tonic-gate cpuid_pass1(cpu_t *cpu) 5980Sstevel@tonic-gate { 5990Sstevel@tonic-gate uint32_t mask_ecx, mask_edx; 6000Sstevel@tonic-gate uint_t feature = X86_CPUID; 6010Sstevel@tonic-gate struct cpuid_info *cpi; 6021228Sandrei struct cpuid_regs *cp; 6030Sstevel@tonic-gate int xcpuid; 6045084Sjohnlev #if !defined(__xpv) 6055045Sbholler extern int idle_cpu_prefer_mwait; 6065084Sjohnlev #endif 6073446Smrj 6080Sstevel@tonic-gate /* 6093446Smrj * Space statically allocated for cpu0, ensure pointer is set 6100Sstevel@tonic-gate */ 6110Sstevel@tonic-gate if (cpu->cpu_id == 0) 6123446Smrj cpu->cpu_m.mcpu_cpi = &cpuid_info0; 6133446Smrj cpi = cpu->cpu_m.mcpu_cpi; 6143446Smrj ASSERT(cpi != NULL); 6150Sstevel@tonic-gate cp = &cpi->cpi_std[0]; 6161228Sandrei cp->cp_eax = 0; 6171228Sandrei cpi->cpi_maxeax = __cpuid_insn(cp); 6180Sstevel@tonic-gate { 6190Sstevel@tonic-gate uint32_t *iptr = (uint32_t *)cpi->cpi_vendorstr; 6200Sstevel@tonic-gate *iptr++ = cp->cp_ebx; 6210Sstevel@tonic-gate *iptr++ = cp->cp_edx; 6220Sstevel@tonic-gate *iptr++ = cp->cp_ecx; 6230Sstevel@tonic-gate *(char *)&cpi->cpi_vendorstr[12] = '\0'; 6240Sstevel@tonic-gate } 6250Sstevel@tonic-gate 6260Sstevel@tonic-gate /* 6270Sstevel@tonic-gate * Map the vendor string to a type code 6280Sstevel@tonic-gate */ 6290Sstevel@tonic-gate if (strcmp(cpi->cpi_vendorstr, "GenuineIntel") == 0) 6300Sstevel@tonic-gate cpi->cpi_vendor = X86_VENDOR_Intel; 6310Sstevel@tonic-gate else if (strcmp(cpi->cpi_vendorstr, "AuthenticAMD") == 0) 6320Sstevel@tonic-gate cpi->cpi_vendor = X86_VENDOR_AMD; 6330Sstevel@tonic-gate else if (strcmp(cpi->cpi_vendorstr, "GenuineTMx86") == 0) 6340Sstevel@tonic-gate cpi->cpi_vendor = X86_VENDOR_TM; 6350Sstevel@tonic-gate else if (strcmp(cpi->cpi_vendorstr, CyrixInstead) == 0) 6360Sstevel@tonic-gate /* 6370Sstevel@tonic-gate * CyrixInstead is a variable used by the Cyrix detection code 6380Sstevel@tonic-gate * in locore. 6390Sstevel@tonic-gate */ 6400Sstevel@tonic-gate cpi->cpi_vendor = X86_VENDOR_Cyrix; 6410Sstevel@tonic-gate else if (strcmp(cpi->cpi_vendorstr, "UMC UMC UMC ") == 0) 6420Sstevel@tonic-gate cpi->cpi_vendor = X86_VENDOR_UMC; 6430Sstevel@tonic-gate else if (strcmp(cpi->cpi_vendorstr, "NexGenDriven") == 0) 6440Sstevel@tonic-gate cpi->cpi_vendor = X86_VENDOR_NexGen; 6450Sstevel@tonic-gate else if (strcmp(cpi->cpi_vendorstr, "CentaurHauls") == 0) 6460Sstevel@tonic-gate cpi->cpi_vendor = X86_VENDOR_Centaur; 6470Sstevel@tonic-gate else if (strcmp(cpi->cpi_vendorstr, "RiseRiseRise") == 0) 6480Sstevel@tonic-gate cpi->cpi_vendor = X86_VENDOR_Rise; 6490Sstevel@tonic-gate else if (strcmp(cpi->cpi_vendorstr, "SiS SiS SiS ") == 0) 6500Sstevel@tonic-gate cpi->cpi_vendor = X86_VENDOR_SiS; 6510Sstevel@tonic-gate else if (strcmp(cpi->cpi_vendorstr, "Geode by NSC") == 0) 6520Sstevel@tonic-gate cpi->cpi_vendor = X86_VENDOR_NSC; 6530Sstevel@tonic-gate else 6540Sstevel@tonic-gate cpi->cpi_vendor = X86_VENDOR_IntelClone; 6550Sstevel@tonic-gate 6560Sstevel@tonic-gate x86_vendor = cpi->cpi_vendor; /* for compatibility */ 6570Sstevel@tonic-gate 6580Sstevel@tonic-gate /* 6590Sstevel@tonic-gate * Limit the range in case of weird hardware 6600Sstevel@tonic-gate */ 6610Sstevel@tonic-gate if (cpi->cpi_maxeax > CPI_MAXEAX_MAX) 6620Sstevel@tonic-gate cpi->cpi_maxeax = CPI_MAXEAX_MAX; 6630Sstevel@tonic-gate if (cpi->cpi_maxeax < 1) 6640Sstevel@tonic-gate goto pass1_done; 6650Sstevel@tonic-gate 6660Sstevel@tonic-gate cp = &cpi->cpi_std[1]; 6671228Sandrei cp->cp_eax = 1; 6681228Sandrei (void) __cpuid_insn(cp); 6690Sstevel@tonic-gate 6700Sstevel@tonic-gate /* 6710Sstevel@tonic-gate * Extract identifying constants for easy access. 6720Sstevel@tonic-gate */ 6730Sstevel@tonic-gate cpi->cpi_model = CPI_MODEL(cpi); 6740Sstevel@tonic-gate cpi->cpi_family = CPI_FAMILY(cpi); 6750Sstevel@tonic-gate 6761975Sdmick if (cpi->cpi_family == 0xf) 6770Sstevel@tonic-gate cpi->cpi_family += CPI_FAMILY_XTD(cpi); 6781975Sdmick 6792001Sdmick /* 6804265Skchow * Beware: AMD uses "extended model" iff base *FAMILY* == 0xf. 6812001Sdmick * Intel, and presumably everyone else, uses model == 0xf, as 6822001Sdmick * one would expect (max value means possible overflow). Sigh. 6832001Sdmick */ 6842001Sdmick 6852001Sdmick switch (cpi->cpi_vendor) { 6864855Sksadhukh case X86_VENDOR_Intel: 6874855Sksadhukh if (IS_EXTENDED_MODEL_INTEL(cpi)) 6884855Sksadhukh cpi->cpi_model += CPI_MODEL_XTD(cpi) << 4; 6894858Sksadhukh break; 6902001Sdmick case X86_VENDOR_AMD: 6914265Skchow if (CPI_FAMILY(cpi) == 0xf) 6922001Sdmick cpi->cpi_model += CPI_MODEL_XTD(cpi) << 4; 6932001Sdmick break; 6942001Sdmick default: 6952001Sdmick if (cpi->cpi_model == 0xf) 6962001Sdmick cpi->cpi_model += CPI_MODEL_XTD(cpi) << 4; 6972001Sdmick break; 6982001Sdmick } 6990Sstevel@tonic-gate 7000Sstevel@tonic-gate cpi->cpi_step = CPI_STEP(cpi); 7010Sstevel@tonic-gate cpi->cpi_brandid = CPI_BRANDID(cpi); 7020Sstevel@tonic-gate 7030Sstevel@tonic-gate /* 7040Sstevel@tonic-gate * *default* assumptions: 7050Sstevel@tonic-gate * - believe %edx feature word 7060Sstevel@tonic-gate * - ignore %ecx feature word 7070Sstevel@tonic-gate * - 32-bit virtual and physical addressing 7080Sstevel@tonic-gate */ 7090Sstevel@tonic-gate mask_edx = 0xffffffff; 7100Sstevel@tonic-gate mask_ecx = 0; 7110Sstevel@tonic-gate 7120Sstevel@tonic-gate cpi->cpi_pabits = cpi->cpi_vabits = 32; 7130Sstevel@tonic-gate 7140Sstevel@tonic-gate switch (cpi->cpi_vendor) { 7150Sstevel@tonic-gate case X86_VENDOR_Intel: 7160Sstevel@tonic-gate if (cpi->cpi_family == 5) 7170Sstevel@tonic-gate x86_type = X86_TYPE_P5; 7181975Sdmick else if (IS_LEGACY_P6(cpi)) { 7190Sstevel@tonic-gate x86_type = X86_TYPE_P6; 7200Sstevel@tonic-gate pentiumpro_bug4046376 = 1; 7210Sstevel@tonic-gate pentiumpro_bug4064495 = 1; 7220Sstevel@tonic-gate /* 7230Sstevel@tonic-gate * Clear the SEP bit when it was set erroneously 7240Sstevel@tonic-gate */ 7250Sstevel@tonic-gate if (cpi->cpi_model < 3 && cpi->cpi_step < 3) 7260Sstevel@tonic-gate cp->cp_edx &= ~CPUID_INTC_EDX_SEP; 7271975Sdmick } else if (IS_NEW_F6(cpi) || cpi->cpi_family == 0xf) { 7280Sstevel@tonic-gate x86_type = X86_TYPE_P4; 7290Sstevel@tonic-gate /* 7300Sstevel@tonic-gate * We don't currently depend on any of the %ecx 7310Sstevel@tonic-gate * features until Prescott, so we'll only check 7320Sstevel@tonic-gate * this from P4 onwards. We might want to revisit 7330Sstevel@tonic-gate * that idea later. 7340Sstevel@tonic-gate */ 7350Sstevel@tonic-gate mask_ecx = 0xffffffff; 7360Sstevel@tonic-gate } else if (cpi->cpi_family > 0xf) 7370Sstevel@tonic-gate mask_ecx = 0xffffffff; 7384636Sbholler /* 7394636Sbholler * We don't support MONITOR/MWAIT if leaf 5 is not available 7404636Sbholler * to obtain the monitor linesize. 7414636Sbholler */ 7424636Sbholler if (cpi->cpi_maxeax < 5) 7434636Sbholler mask_ecx &= ~CPUID_INTC_ECX_MON; 7440Sstevel@tonic-gate break; 7450Sstevel@tonic-gate case X86_VENDOR_IntelClone: 7460Sstevel@tonic-gate default: 7470Sstevel@tonic-gate break; 7480Sstevel@tonic-gate case X86_VENDOR_AMD: 7490Sstevel@tonic-gate #if defined(OPTERON_ERRATUM_108) 7500Sstevel@tonic-gate if (cpi->cpi_family == 0xf && cpi->cpi_model == 0xe) { 7510Sstevel@tonic-gate cp->cp_eax = (0xf0f & cp->cp_eax) | 0xc0; 7520Sstevel@tonic-gate cpi->cpi_model = 0xc; 7530Sstevel@tonic-gate } else 7540Sstevel@tonic-gate #endif 7550Sstevel@tonic-gate if (cpi->cpi_family == 5) { 7560Sstevel@tonic-gate /* 7570Sstevel@tonic-gate * AMD K5 and K6 7580Sstevel@tonic-gate * 7590Sstevel@tonic-gate * These CPUs have an incomplete implementation 7600Sstevel@tonic-gate * of MCA/MCE which we mask away. 7610Sstevel@tonic-gate */ 7621228Sandrei mask_edx &= ~(CPUID_INTC_EDX_MCE | CPUID_INTC_EDX_MCA); 7631228Sandrei 7641228Sandrei /* 7651228Sandrei * Model 0 uses the wrong (APIC) bit 7661228Sandrei * to indicate PGE. Fix it here. 7671228Sandrei */ 7680Sstevel@tonic-gate if (cpi->cpi_model == 0) { 7690Sstevel@tonic-gate if (cp->cp_edx & 0x200) { 7700Sstevel@tonic-gate cp->cp_edx &= ~0x200; 7710Sstevel@tonic-gate cp->cp_edx |= CPUID_INTC_EDX_PGE; 7720Sstevel@tonic-gate } 7731228Sandrei } 7741228Sandrei 7751228Sandrei /* 7761228Sandrei * Early models had problems w/ MMX; disable. 7771228Sandrei */ 7781228Sandrei if (cpi->cpi_model < 6) 7791228Sandrei mask_edx &= ~CPUID_INTC_EDX_MMX; 7801228Sandrei } 7811228Sandrei 7821228Sandrei /* 7831228Sandrei * For newer families, SSE3 and CX16, at least, are valid; 7841228Sandrei * enable all 7851228Sandrei */ 7861228Sandrei if (cpi->cpi_family >= 0xf) 787771Sdmick mask_ecx = 0xffffffff; 7884636Sbholler /* 7894636Sbholler * We don't support MONITOR/MWAIT if leaf 5 is not available 7904636Sbholler * to obtain the monitor linesize. 7914636Sbholler */ 7924636Sbholler if (cpi->cpi_maxeax < 5) 7934636Sbholler mask_ecx &= ~CPUID_INTC_ECX_MON; 7945045Sbholler 7955084Sjohnlev #if !defined(__xpv) 7965045Sbholler /* 7975045Sbholler * Do not use MONITOR/MWAIT to halt in the idle loop on any AMD 7985045Sbholler * processors. AMD does not intend MWAIT to be used in the cpu 7995045Sbholler * idle loop on current and future processors. 10h and future 8005045Sbholler * AMD processors use more power in MWAIT than HLT. 8015045Sbholler * Pre-family-10h Opterons do not have the MWAIT instruction. 8025045Sbholler */ 8035045Sbholler idle_cpu_prefer_mwait = 0; 8045084Sjohnlev #endif 8055045Sbholler 8060Sstevel@tonic-gate break; 8070Sstevel@tonic-gate case X86_VENDOR_TM: 8080Sstevel@tonic-gate /* 8090Sstevel@tonic-gate * workaround the NT workaround in CMS 4.1 8100Sstevel@tonic-gate */ 8110Sstevel@tonic-gate if (cpi->cpi_family == 5 && cpi->cpi_model == 4 && 8120Sstevel@tonic-gate (cpi->cpi_step == 2 || cpi->cpi_step == 3)) 8130Sstevel@tonic-gate cp->cp_edx |= CPUID_INTC_EDX_CX8; 8140Sstevel@tonic-gate break; 8150Sstevel@tonic-gate case X86_VENDOR_Centaur: 8160Sstevel@tonic-gate /* 8170Sstevel@tonic-gate * workaround the NT workarounds again 8180Sstevel@tonic-gate */ 8190Sstevel@tonic-gate if (cpi->cpi_family == 6) 8200Sstevel@tonic-gate cp->cp_edx |= CPUID_INTC_EDX_CX8; 8210Sstevel@tonic-gate break; 8220Sstevel@tonic-gate case X86_VENDOR_Cyrix: 8230Sstevel@tonic-gate /* 8240Sstevel@tonic-gate * We rely heavily on the probing in locore 8250Sstevel@tonic-gate * to actually figure out what parts, if any, 8260Sstevel@tonic-gate * of the Cyrix cpuid instruction to believe. 8270Sstevel@tonic-gate */ 8280Sstevel@tonic-gate switch (x86_type) { 8290Sstevel@tonic-gate case X86_TYPE_CYRIX_486: 8300Sstevel@tonic-gate mask_edx = 0; 8310Sstevel@tonic-gate break; 8320Sstevel@tonic-gate case X86_TYPE_CYRIX_6x86: 8330Sstevel@tonic-gate mask_edx = 0; 8340Sstevel@tonic-gate break; 8350Sstevel@tonic-gate case X86_TYPE_CYRIX_6x86L: 8360Sstevel@tonic-gate mask_edx = 8370Sstevel@tonic-gate CPUID_INTC_EDX_DE | 8380Sstevel@tonic-gate CPUID_INTC_EDX_CX8; 8390Sstevel@tonic-gate break; 8400Sstevel@tonic-gate case X86_TYPE_CYRIX_6x86MX: 8410Sstevel@tonic-gate mask_edx = 8420Sstevel@tonic-gate CPUID_INTC_EDX_DE | 8430Sstevel@tonic-gate CPUID_INTC_EDX_MSR | 8440Sstevel@tonic-gate CPUID_INTC_EDX_CX8 | 8450Sstevel@tonic-gate CPUID_INTC_EDX_PGE | 8460Sstevel@tonic-gate CPUID_INTC_EDX_CMOV | 8470Sstevel@tonic-gate CPUID_INTC_EDX_MMX; 8480Sstevel@tonic-gate break; 8490Sstevel@tonic-gate case X86_TYPE_CYRIX_GXm: 8500Sstevel@tonic-gate mask_edx = 8510Sstevel@tonic-gate CPUID_INTC_EDX_MSR | 8520Sstevel@tonic-gate CPUID_INTC_EDX_CX8 | 8530Sstevel@tonic-gate CPUID_INTC_EDX_CMOV | 8540Sstevel@tonic-gate CPUID_INTC_EDX_MMX; 8550Sstevel@tonic-gate break; 8560Sstevel@tonic-gate case X86_TYPE_CYRIX_MediaGX: 8570Sstevel@tonic-gate break; 8580Sstevel@tonic-gate case X86_TYPE_CYRIX_MII: 8590Sstevel@tonic-gate case X86_TYPE_VIA_CYRIX_III: 8600Sstevel@tonic-gate mask_edx = 8610Sstevel@tonic-gate CPUID_INTC_EDX_DE | 8620Sstevel@tonic-gate CPUID_INTC_EDX_TSC | 8630Sstevel@tonic-gate CPUID_INTC_EDX_MSR | 8640Sstevel@tonic-gate CPUID_INTC_EDX_CX8 | 8650Sstevel@tonic-gate CPUID_INTC_EDX_PGE | 8660Sstevel@tonic-gate CPUID_INTC_EDX_CMOV | 8670Sstevel@tonic-gate CPUID_INTC_EDX_MMX; 8680Sstevel@tonic-gate break; 8690Sstevel@tonic-gate default: 8700Sstevel@tonic-gate break; 8710Sstevel@tonic-gate } 8720Sstevel@tonic-gate break; 8730Sstevel@tonic-gate } 8740Sstevel@tonic-gate 8755084Sjohnlev #if defined(__xpv) 8765084Sjohnlev /* 8775084Sjohnlev * Do not support MONITOR/MWAIT under a hypervisor 8785084Sjohnlev */ 8795084Sjohnlev mask_ecx &= ~CPUID_INTC_ECX_MON; 8805084Sjohnlev #endif /* __xpv */ 8815084Sjohnlev 8820Sstevel@tonic-gate /* 8830Sstevel@tonic-gate * Now we've figured out the masks that determine 8840Sstevel@tonic-gate * which bits we choose to believe, apply the masks 8850Sstevel@tonic-gate * to the feature words, then map the kernel's view 8860Sstevel@tonic-gate * of these feature words into its feature word. 8870Sstevel@tonic-gate */ 8880Sstevel@tonic-gate cp->cp_edx &= mask_edx; 8890Sstevel@tonic-gate cp->cp_ecx &= mask_ecx; 8900Sstevel@tonic-gate 8910Sstevel@tonic-gate /* 8923446Smrj * apply any platform restrictions (we don't call this 8933446Smrj * immediately after __cpuid_insn here, because we need the 8943446Smrj * workarounds applied above first) 8950Sstevel@tonic-gate */ 8963446Smrj platform_cpuid_mangle(cpi->cpi_vendor, 1, cp); 8970Sstevel@tonic-gate 8983446Smrj /* 8993446Smrj * fold in overrides from the "eeprom" mechanism 9003446Smrj */ 9010Sstevel@tonic-gate cp->cp_edx |= cpuid_feature_edx_include; 9020Sstevel@tonic-gate cp->cp_edx &= ~cpuid_feature_edx_exclude; 9030Sstevel@tonic-gate 9040Sstevel@tonic-gate cp->cp_ecx |= cpuid_feature_ecx_include; 9050Sstevel@tonic-gate cp->cp_ecx &= ~cpuid_feature_ecx_exclude; 9060Sstevel@tonic-gate 9070Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_PSE) 9080Sstevel@tonic-gate feature |= X86_LARGEPAGE; 9090Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_TSC) 9100Sstevel@tonic-gate feature |= X86_TSC; 9110Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_MSR) 9120Sstevel@tonic-gate feature |= X86_MSR; 9130Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_MTRR) 9140Sstevel@tonic-gate feature |= X86_MTRR; 9150Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_PGE) 9160Sstevel@tonic-gate feature |= X86_PGE; 9170Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_CMOV) 9180Sstevel@tonic-gate feature |= X86_CMOV; 9190Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_MMX) 9200Sstevel@tonic-gate feature |= X86_MMX; 9210Sstevel@tonic-gate if ((cp->cp_edx & CPUID_INTC_EDX_MCE) != 0 && 9220Sstevel@tonic-gate (cp->cp_edx & CPUID_INTC_EDX_MCA) != 0) 9230Sstevel@tonic-gate feature |= X86_MCA; 9240Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_PAE) 9250Sstevel@tonic-gate feature |= X86_PAE; 9260Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_CX8) 9270Sstevel@tonic-gate feature |= X86_CX8; 9280Sstevel@tonic-gate if (cp->cp_ecx & CPUID_INTC_ECX_CX16) 9290Sstevel@tonic-gate feature |= X86_CX16; 9300Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_PAT) 9310Sstevel@tonic-gate feature |= X86_PAT; 9320Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_SEP) 9330Sstevel@tonic-gate feature |= X86_SEP; 9340Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_FXSR) { 9350Sstevel@tonic-gate /* 9360Sstevel@tonic-gate * In our implementation, fxsave/fxrstor 9370Sstevel@tonic-gate * are prerequisites before we'll even 9380Sstevel@tonic-gate * try and do SSE things. 9390Sstevel@tonic-gate */ 9400Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_SSE) 9410Sstevel@tonic-gate feature |= X86_SSE; 9420Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_SSE2) 9430Sstevel@tonic-gate feature |= X86_SSE2; 9440Sstevel@tonic-gate if (cp->cp_ecx & CPUID_INTC_ECX_SSE3) 9450Sstevel@tonic-gate feature |= X86_SSE3; 9465269Skk208521 if (cpi->cpi_vendor == X86_VENDOR_Intel) { 9475269Skk208521 if (cp->cp_ecx & CPUID_INTC_ECX_SSSE3) 9485269Skk208521 feature |= X86_SSSE3; 9495269Skk208521 if (cp->cp_ecx & CPUID_INTC_ECX_SSE4_1) 9505269Skk208521 feature |= X86_SSE4_1; 9515269Skk208521 if (cp->cp_ecx & CPUID_INTC_ECX_SSE4_2) 9525269Skk208521 feature |= X86_SSE4_2; 9535269Skk208521 } 9540Sstevel@tonic-gate } 9550Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_DE) 9563446Smrj feature |= X86_DE; 9574481Sbholler if (cp->cp_ecx & CPUID_INTC_ECX_MON) { 9584481Sbholler cpi->cpi_mwait.support |= MWAIT_SUPPORT; 9594481Sbholler feature |= X86_MWAIT; 9604481Sbholler } 9610Sstevel@tonic-gate 9620Sstevel@tonic-gate if (feature & X86_PAE) 9630Sstevel@tonic-gate cpi->cpi_pabits = 36; 9640Sstevel@tonic-gate 9650Sstevel@tonic-gate /* 9660Sstevel@tonic-gate * Hyperthreading configuration is slightly tricky on Intel 9670Sstevel@tonic-gate * and pure clones, and even trickier on AMD. 9680Sstevel@tonic-gate * 9690Sstevel@tonic-gate * (AMD chose to set the HTT bit on their CMP processors, 9700Sstevel@tonic-gate * even though they're not actually hyperthreaded. Thus it 9710Sstevel@tonic-gate * takes a bit more work to figure out what's really going 9723446Smrj * on ... see the handling of the CMP_LGCY bit below) 9730Sstevel@tonic-gate */ 9740Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_HTT) { 9750Sstevel@tonic-gate cpi->cpi_ncpu_per_chip = CPI_CPU_COUNT(cpi); 9760Sstevel@tonic-gate if (cpi->cpi_ncpu_per_chip > 1) 9770Sstevel@tonic-gate feature |= X86_HTT; 9781228Sandrei } else { 9791228Sandrei cpi->cpi_ncpu_per_chip = 1; 9800Sstevel@tonic-gate } 9810Sstevel@tonic-gate 9820Sstevel@tonic-gate /* 9830Sstevel@tonic-gate * Work on the "extended" feature information, doing 9840Sstevel@tonic-gate * some basic initialization for cpuid_pass2() 9850Sstevel@tonic-gate */ 9860Sstevel@tonic-gate xcpuid = 0; 9870Sstevel@tonic-gate switch (cpi->cpi_vendor) { 9880Sstevel@tonic-gate case X86_VENDOR_Intel: 9891975Sdmick if (IS_NEW_F6(cpi) || cpi->cpi_family >= 0xf) 9900Sstevel@tonic-gate xcpuid++; 9910Sstevel@tonic-gate break; 9920Sstevel@tonic-gate case X86_VENDOR_AMD: 9930Sstevel@tonic-gate if (cpi->cpi_family > 5 || 9940Sstevel@tonic-gate (cpi->cpi_family == 5 && cpi->cpi_model >= 1)) 9950Sstevel@tonic-gate xcpuid++; 9960Sstevel@tonic-gate break; 9970Sstevel@tonic-gate case X86_VENDOR_Cyrix: 9980Sstevel@tonic-gate /* 9990Sstevel@tonic-gate * Only these Cyrix CPUs are -known- to support 10000Sstevel@tonic-gate * extended cpuid operations. 10010Sstevel@tonic-gate */ 10020Sstevel@tonic-gate if (x86_type == X86_TYPE_VIA_CYRIX_III || 10030Sstevel@tonic-gate x86_type == X86_TYPE_CYRIX_GXm) 10040Sstevel@tonic-gate xcpuid++; 10050Sstevel@tonic-gate break; 10060Sstevel@tonic-gate case X86_VENDOR_Centaur: 10070Sstevel@tonic-gate case X86_VENDOR_TM: 10080Sstevel@tonic-gate default: 10090Sstevel@tonic-gate xcpuid++; 10100Sstevel@tonic-gate break; 10110Sstevel@tonic-gate } 10120Sstevel@tonic-gate 10130Sstevel@tonic-gate if (xcpuid) { 10140Sstevel@tonic-gate cp = &cpi->cpi_extd[0]; 10151228Sandrei cp->cp_eax = 0x80000000; 10161228Sandrei cpi->cpi_xmaxeax = __cpuid_insn(cp); 10170Sstevel@tonic-gate } 10180Sstevel@tonic-gate 10190Sstevel@tonic-gate if (cpi->cpi_xmaxeax & 0x80000000) { 10200Sstevel@tonic-gate 10210Sstevel@tonic-gate if (cpi->cpi_xmaxeax > CPI_XMAXEAX_MAX) 10220Sstevel@tonic-gate cpi->cpi_xmaxeax = CPI_XMAXEAX_MAX; 10230Sstevel@tonic-gate 10240Sstevel@tonic-gate switch (cpi->cpi_vendor) { 10250Sstevel@tonic-gate case X86_VENDOR_Intel: 10260Sstevel@tonic-gate case X86_VENDOR_AMD: 10270Sstevel@tonic-gate if (cpi->cpi_xmaxeax < 0x80000001) 10280Sstevel@tonic-gate break; 10290Sstevel@tonic-gate cp = &cpi->cpi_extd[1]; 10301228Sandrei cp->cp_eax = 0x80000001; 10311228Sandrei (void) __cpuid_insn(cp); 10323446Smrj 10330Sstevel@tonic-gate if (cpi->cpi_vendor == X86_VENDOR_AMD && 10340Sstevel@tonic-gate cpi->cpi_family == 5 && 10350Sstevel@tonic-gate cpi->cpi_model == 6 && 10360Sstevel@tonic-gate cpi->cpi_step == 6) { 10370Sstevel@tonic-gate /* 10380Sstevel@tonic-gate * K6 model 6 uses bit 10 to indicate SYSC 10390Sstevel@tonic-gate * Later models use bit 11. Fix it here. 10400Sstevel@tonic-gate */ 10410Sstevel@tonic-gate if (cp->cp_edx & 0x400) { 10420Sstevel@tonic-gate cp->cp_edx &= ~0x400; 10430Sstevel@tonic-gate cp->cp_edx |= CPUID_AMD_EDX_SYSC; 10440Sstevel@tonic-gate } 10450Sstevel@tonic-gate } 10460Sstevel@tonic-gate 10473446Smrj platform_cpuid_mangle(cpi->cpi_vendor, 0x80000001, cp); 10483446Smrj 10490Sstevel@tonic-gate /* 10500Sstevel@tonic-gate * Compute the additions to the kernel's feature word. 10510Sstevel@tonic-gate */ 10520Sstevel@tonic-gate if (cp->cp_edx & CPUID_AMD_EDX_NX) 10530Sstevel@tonic-gate feature |= X86_NX; 10540Sstevel@tonic-gate 10555349Skchow #if defined(__amd64) 10565349Skchow /* 1 GB large page - enable only for 64 bit kernel */ 10575349Skchow if (cp->cp_edx & CPUID_AMD_EDX_1GPG) 10585349Skchow feature |= X86_1GPG; 10595349Skchow #endif 10605349Skchow 10614628Skk208521 if ((cpi->cpi_vendor == X86_VENDOR_AMD) && 10624628Skk208521 (cpi->cpi_std[1].cp_edx & CPUID_INTC_EDX_FXSR) && 10634628Skk208521 (cp->cp_ecx & CPUID_AMD_ECX_SSE4A)) 10644628Skk208521 feature |= X86_SSE4A; 10654628Skk208521 10660Sstevel@tonic-gate /* 10673446Smrj * If both the HTT and CMP_LGCY bits are set, 10681228Sandrei * then we're not actually HyperThreaded. Read 10691228Sandrei * "AMD CPUID Specification" for more details. 10700Sstevel@tonic-gate */ 10710Sstevel@tonic-gate if (cpi->cpi_vendor == X86_VENDOR_AMD && 10721228Sandrei (feature & X86_HTT) && 10733446Smrj (cp->cp_ecx & CPUID_AMD_ECX_CMP_LGCY)) { 10740Sstevel@tonic-gate feature &= ~X86_HTT; 10751228Sandrei feature |= X86_CMP; 10761228Sandrei } 10773446Smrj #if defined(__amd64) 10780Sstevel@tonic-gate /* 10790Sstevel@tonic-gate * It's really tricky to support syscall/sysret in 10800Sstevel@tonic-gate * the i386 kernel; we rely on sysenter/sysexit 10810Sstevel@tonic-gate * instead. In the amd64 kernel, things are -way- 10820Sstevel@tonic-gate * better. 10830Sstevel@tonic-gate */ 10840Sstevel@tonic-gate if (cp->cp_edx & CPUID_AMD_EDX_SYSC) 10850Sstevel@tonic-gate feature |= X86_ASYSC; 10860Sstevel@tonic-gate 10870Sstevel@tonic-gate /* 10880Sstevel@tonic-gate * While we're thinking about system calls, note 10890Sstevel@tonic-gate * that AMD processors don't support sysenter 10900Sstevel@tonic-gate * in long mode at all, so don't try to program them. 10910Sstevel@tonic-gate */ 10920Sstevel@tonic-gate if (x86_vendor == X86_VENDOR_AMD) 10930Sstevel@tonic-gate feature &= ~X86_SEP; 10940Sstevel@tonic-gate #endif 10955322Ssudheer if (x86_vendor == X86_VENDOR_AMD && 10965322Ssudheer cp->cp_edx & CPUID_AMD_EDX_TSCP) 10973446Smrj feature |= X86_TSCP; 10980Sstevel@tonic-gate break; 10990Sstevel@tonic-gate default: 11000Sstevel@tonic-gate break; 11010Sstevel@tonic-gate } 11020Sstevel@tonic-gate 11031228Sandrei /* 11041228Sandrei * Get CPUID data about processor cores and hyperthreads. 11051228Sandrei */ 11060Sstevel@tonic-gate switch (cpi->cpi_vendor) { 11070Sstevel@tonic-gate case X86_VENDOR_Intel: 11081228Sandrei if (cpi->cpi_maxeax >= 4) { 11091228Sandrei cp = &cpi->cpi_std[4]; 11101228Sandrei cp->cp_eax = 4; 11111228Sandrei cp->cp_ecx = 0; 11121228Sandrei (void) __cpuid_insn(cp); 11133446Smrj platform_cpuid_mangle(cpi->cpi_vendor, 4, cp); 11141228Sandrei } 11151228Sandrei /*FALLTHROUGH*/ 11160Sstevel@tonic-gate case X86_VENDOR_AMD: 11170Sstevel@tonic-gate if (cpi->cpi_xmaxeax < 0x80000008) 11180Sstevel@tonic-gate break; 11190Sstevel@tonic-gate cp = &cpi->cpi_extd[8]; 11201228Sandrei cp->cp_eax = 0x80000008; 11211228Sandrei (void) __cpuid_insn(cp); 11223446Smrj platform_cpuid_mangle(cpi->cpi_vendor, 0x80000008, cp); 11233446Smrj 11240Sstevel@tonic-gate /* 11250Sstevel@tonic-gate * Virtual and physical address limits from 11260Sstevel@tonic-gate * cpuid override previously guessed values. 11270Sstevel@tonic-gate */ 11280Sstevel@tonic-gate cpi->cpi_pabits = BITX(cp->cp_eax, 7, 0); 11290Sstevel@tonic-gate cpi->cpi_vabits = BITX(cp->cp_eax, 15, 8); 11300Sstevel@tonic-gate break; 11310Sstevel@tonic-gate default: 11320Sstevel@tonic-gate break; 11330Sstevel@tonic-gate } 11341228Sandrei 11354606Sesaxe /* 11364606Sesaxe * Derive the number of cores per chip 11374606Sesaxe */ 11381228Sandrei switch (cpi->cpi_vendor) { 11391228Sandrei case X86_VENDOR_Intel: 11401228Sandrei if (cpi->cpi_maxeax < 4) { 11411228Sandrei cpi->cpi_ncore_per_chip = 1; 11421228Sandrei break; 11431228Sandrei } else { 11441228Sandrei cpi->cpi_ncore_per_chip = 11451228Sandrei BITX((cpi)->cpi_std[4].cp_eax, 31, 26) + 1; 11461228Sandrei } 11471228Sandrei break; 11481228Sandrei case X86_VENDOR_AMD: 11491228Sandrei if (cpi->cpi_xmaxeax < 0x80000008) { 11501228Sandrei cpi->cpi_ncore_per_chip = 1; 11511228Sandrei break; 11521228Sandrei } else { 11535870Sgavinm /* 11545870Sgavinm * On family 0xf cpuid fn 2 ECX[7:0] "NC" is 11555870Sgavinm * 1 less than the number of physical cores on 11565870Sgavinm * the chip. In family 0x10 this value can 11575870Sgavinm * be affected by "downcoring" - it reflects 11585870Sgavinm * 1 less than the number of cores actually 11595870Sgavinm * enabled on this node. 11605870Sgavinm */ 11611228Sandrei cpi->cpi_ncore_per_chip = 11621228Sandrei BITX((cpi)->cpi_extd[8].cp_ecx, 7, 0) + 1; 11631228Sandrei } 11641228Sandrei break; 11651228Sandrei default: 11661228Sandrei cpi->cpi_ncore_per_chip = 1; 11671228Sandrei break; 11681228Sandrei } 11695284Sgavinm } else { 11705284Sgavinm cpi->cpi_ncore_per_chip = 1; 11710Sstevel@tonic-gate } 11720Sstevel@tonic-gate 11731228Sandrei /* 11741228Sandrei * If more than one core, then this processor is CMP. 11751228Sandrei */ 11761228Sandrei if (cpi->cpi_ncore_per_chip > 1) 11771228Sandrei feature |= X86_CMP; 11783446Smrj 11791228Sandrei /* 11801228Sandrei * If the number of cores is the same as the number 11811228Sandrei * of CPUs, then we cannot have HyperThreading. 11821228Sandrei */ 11831228Sandrei if (cpi->cpi_ncpu_per_chip == cpi->cpi_ncore_per_chip) 11841228Sandrei feature &= ~X86_HTT; 11851228Sandrei 11860Sstevel@tonic-gate if ((feature & (X86_HTT | X86_CMP)) == 0) { 11871228Sandrei /* 11881228Sandrei * Single-core single-threaded processors. 11891228Sandrei */ 11900Sstevel@tonic-gate cpi->cpi_chipid = -1; 11910Sstevel@tonic-gate cpi->cpi_clogid = 0; 11921228Sandrei cpi->cpi_coreid = cpu->cpu_id; 11935870Sgavinm cpi->cpi_pkgcoreid = 0; 11940Sstevel@tonic-gate } else if (cpi->cpi_ncpu_per_chip > 1) { 11951228Sandrei uint_t i; 11961228Sandrei uint_t chipid_shift = 0; 11971228Sandrei uint_t coreid_shift = 0; 11981228Sandrei uint_t apic_id = CPI_APIC_ID(cpi); 11991228Sandrei 12001228Sandrei for (i = 1; i < cpi->cpi_ncpu_per_chip; i <<= 1) 12011228Sandrei chipid_shift++; 12021228Sandrei cpi->cpi_chipid = apic_id >> chipid_shift; 12031228Sandrei cpi->cpi_clogid = apic_id & ((1 << chipid_shift) - 1); 12040Sstevel@tonic-gate 12051228Sandrei if (cpi->cpi_vendor == X86_VENDOR_Intel) { 12061228Sandrei if (feature & X86_CMP) { 12071228Sandrei /* 12081228Sandrei * Multi-core (and possibly multi-threaded) 12091228Sandrei * processors. 12101228Sandrei */ 12111228Sandrei uint_t ncpu_per_core; 12121228Sandrei if (cpi->cpi_ncore_per_chip == 1) 12131228Sandrei ncpu_per_core = cpi->cpi_ncpu_per_chip; 12141228Sandrei else if (cpi->cpi_ncore_per_chip > 1) 12151228Sandrei ncpu_per_core = cpi->cpi_ncpu_per_chip / 12161228Sandrei cpi->cpi_ncore_per_chip; 12171228Sandrei /* 12181228Sandrei * 8bit APIC IDs on dual core Pentiums 12191228Sandrei * look like this: 12201228Sandrei * 12211228Sandrei * +-----------------------+------+------+ 12221228Sandrei * | Physical Package ID | MC | HT | 12231228Sandrei * +-----------------------+------+------+ 12241228Sandrei * <------- chipid --------> 12251228Sandrei * <------- coreid ---------------> 12261228Sandrei * <--- clogid --> 12275870Sgavinm * <------> 12285870Sgavinm * pkgcoreid 12291228Sandrei * 12301228Sandrei * Where the number of bits necessary to 12311228Sandrei * represent MC and HT fields together equals 12321228Sandrei * to the minimum number of bits necessary to 12331228Sandrei * store the value of cpi->cpi_ncpu_per_chip. 12341228Sandrei * Of those bits, the MC part uses the number 12351228Sandrei * of bits necessary to store the value of 12361228Sandrei * cpi->cpi_ncore_per_chip. 12371228Sandrei */ 12381228Sandrei for (i = 1; i < ncpu_per_core; i <<= 1) 12391228Sandrei coreid_shift++; 12401727Sandrei cpi->cpi_coreid = apic_id >> coreid_shift; 12415870Sgavinm cpi->cpi_pkgcoreid = cpi->cpi_clogid >> 12425870Sgavinm coreid_shift; 12431228Sandrei } else if (feature & X86_HTT) { 12441228Sandrei /* 12451228Sandrei * Single-core multi-threaded processors. 12461228Sandrei */ 12471228Sandrei cpi->cpi_coreid = cpi->cpi_chipid; 12485870Sgavinm cpi->cpi_pkgcoreid = 0; 12491228Sandrei } 12501228Sandrei } else if (cpi->cpi_vendor == X86_VENDOR_AMD) { 12511228Sandrei /* 12525870Sgavinm * AMD CMP chips currently have a single thread per 12535870Sgavinm * core, with 2 cores on family 0xf and 2, 3 or 4 12545870Sgavinm * cores on family 0x10. 12555870Sgavinm * 12565870Sgavinm * Since no two cpus share a core we must assign a 12575870Sgavinm * distinct coreid per cpu, and we do this by using 12585870Sgavinm * the cpu_id. This scheme does not, however, 12595870Sgavinm * guarantee that sibling cores of a chip will have 12605870Sgavinm * sequential coreids starting at a multiple of the 12615870Sgavinm * number of cores per chip - that is usually the 12625870Sgavinm * case, but if the ACPI MADT table is presented 12635870Sgavinm * in a different order then we need to perform a 12645870Sgavinm * few more gymnastics for the pkgcoreid. 12655870Sgavinm * 12665870Sgavinm * In family 0xf CMPs there are 2 cores on all nodes 12675870Sgavinm * present - no mixing of single and dual core parts. 12685870Sgavinm * 12695870Sgavinm * In family 0x10 CMPs cpuid fn 2 ECX[15:12] 12705870Sgavinm * "ApicIdCoreIdSize[3:0]" tells us how 12715870Sgavinm * many least-significant bits in the ApicId 12725870Sgavinm * are used to represent the core number 12735870Sgavinm * within the node. Cores are always 12745870Sgavinm * numbered sequentially from 0 regardless 12755870Sgavinm * of how many or which are disabled, and 12765870Sgavinm * there seems to be no way to discover the 12775870Sgavinm * real core id when some are disabled. 12781228Sandrei */ 12791228Sandrei cpi->cpi_coreid = cpu->cpu_id; 12805870Sgavinm 12815870Sgavinm if (cpi->cpi_family == 0x10 && 12825870Sgavinm cpi->cpi_xmaxeax >= 0x80000008) { 12835870Sgavinm int coreidsz = 12845870Sgavinm BITX((cpi)->cpi_extd[8].cp_ecx, 15, 12); 12855870Sgavinm 12865870Sgavinm cpi->cpi_pkgcoreid = 12875870Sgavinm apic_id & ((1 << coreidsz) - 1); 12885870Sgavinm } else { 12895870Sgavinm cpi->cpi_pkgcoreid = cpi->cpi_clogid; 12905870Sgavinm } 12911228Sandrei } else { 12921228Sandrei /* 12931228Sandrei * All other processors are currently 12941228Sandrei * assumed to have single cores. 12951228Sandrei */ 12961228Sandrei cpi->cpi_coreid = cpi->cpi_chipid; 12975870Sgavinm cpi->cpi_pkgcoreid = 0; 12981228Sandrei } 12990Sstevel@tonic-gate } 13000Sstevel@tonic-gate 13012869Sgavinm /* 13022869Sgavinm * Synthesize chip "revision" and socket type 13032869Sgavinm */ 13042869Sgavinm synth_info(cpi); 13052869Sgavinm 13060Sstevel@tonic-gate pass1_done: 13075741Smrj #if !defined(__xpv) 13085741Smrj check_for_hvm(); 13095741Smrj #endif 13100Sstevel@tonic-gate cpi->cpi_pass = 1; 13110Sstevel@tonic-gate return (feature); 13120Sstevel@tonic-gate } 13130Sstevel@tonic-gate 13140Sstevel@tonic-gate /* 13150Sstevel@tonic-gate * Make copies of the cpuid table entries we depend on, in 13160Sstevel@tonic-gate * part for ease of parsing now, in part so that we have only 13170Sstevel@tonic-gate * one place to correct any of it, in part for ease of 13180Sstevel@tonic-gate * later export to userland, and in part so we can look at 13190Sstevel@tonic-gate * this stuff in a crash dump. 13200Sstevel@tonic-gate */ 13210Sstevel@tonic-gate 13220Sstevel@tonic-gate /*ARGSUSED*/ 13230Sstevel@tonic-gate void 13240Sstevel@tonic-gate cpuid_pass2(cpu_t *cpu) 13250Sstevel@tonic-gate { 13260Sstevel@tonic-gate uint_t n, nmax; 13270Sstevel@tonic-gate int i; 13281228Sandrei struct cpuid_regs *cp; 13290Sstevel@tonic-gate uint8_t *dp; 13300Sstevel@tonic-gate uint32_t *iptr; 13310Sstevel@tonic-gate struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 13320Sstevel@tonic-gate 13330Sstevel@tonic-gate ASSERT(cpi->cpi_pass == 1); 13340Sstevel@tonic-gate 13350Sstevel@tonic-gate if (cpi->cpi_maxeax < 1) 13360Sstevel@tonic-gate goto pass2_done; 13370Sstevel@tonic-gate 13380Sstevel@tonic-gate if ((nmax = cpi->cpi_maxeax + 1) > NMAX_CPI_STD) 13390Sstevel@tonic-gate nmax = NMAX_CPI_STD; 13400Sstevel@tonic-gate /* 13410Sstevel@tonic-gate * (We already handled n == 0 and n == 1 in pass 1) 13420Sstevel@tonic-gate */ 13430Sstevel@tonic-gate for (n = 2, cp = &cpi->cpi_std[2]; n < nmax; n++, cp++) { 13441228Sandrei cp->cp_eax = n; 13454606Sesaxe 13464606Sesaxe /* 13474606Sesaxe * CPUID function 4 expects %ecx to be initialized 13484606Sesaxe * with an index which indicates which cache to return 13494606Sesaxe * information about. The OS is expected to call function 4 13504606Sesaxe * with %ecx set to 0, 1, 2, ... until it returns with 13514606Sesaxe * EAX[4:0] set to 0, which indicates there are no more 13524606Sesaxe * caches. 13534606Sesaxe * 13544606Sesaxe * Here, populate cpi_std[4] with the information returned by 13554606Sesaxe * function 4 when %ecx == 0, and do the rest in cpuid_pass3() 13564606Sesaxe * when dynamic memory allocation becomes available. 13574606Sesaxe * 13584606Sesaxe * Note: we need to explicitly initialize %ecx here, since 13594606Sesaxe * function 4 may have been previously invoked. 13604606Sesaxe */ 13614606Sesaxe if (n == 4) 13624606Sesaxe cp->cp_ecx = 0; 13634606Sesaxe 13641228Sandrei (void) __cpuid_insn(cp); 13653446Smrj platform_cpuid_mangle(cpi->cpi_vendor, n, cp); 13660Sstevel@tonic-gate switch (n) { 13670Sstevel@tonic-gate case 2: 13680Sstevel@tonic-gate /* 13690Sstevel@tonic-gate * "the lower 8 bits of the %eax register 13700Sstevel@tonic-gate * contain a value that identifies the number 13710Sstevel@tonic-gate * of times the cpuid [instruction] has to be 13720Sstevel@tonic-gate * executed to obtain a complete image of the 13730Sstevel@tonic-gate * processor's caching systems." 13740Sstevel@tonic-gate * 13750Sstevel@tonic-gate * How *do* they make this stuff up? 13760Sstevel@tonic-gate */ 13770Sstevel@tonic-gate cpi->cpi_ncache = sizeof (*cp) * 13780Sstevel@tonic-gate BITX(cp->cp_eax, 7, 0); 13790Sstevel@tonic-gate if (cpi->cpi_ncache == 0) 13800Sstevel@tonic-gate break; 13810Sstevel@tonic-gate cpi->cpi_ncache--; /* skip count byte */ 13820Sstevel@tonic-gate 13830Sstevel@tonic-gate /* 13840Sstevel@tonic-gate * Well, for now, rather than attempt to implement 13850Sstevel@tonic-gate * this slightly dubious algorithm, we just look 13860Sstevel@tonic-gate * at the first 15 .. 13870Sstevel@tonic-gate */ 13880Sstevel@tonic-gate if (cpi->cpi_ncache > (sizeof (*cp) - 1)) 13890Sstevel@tonic-gate cpi->cpi_ncache = sizeof (*cp) - 1; 13900Sstevel@tonic-gate 13910Sstevel@tonic-gate dp = cpi->cpi_cacheinfo; 13920Sstevel@tonic-gate if (BITX(cp->cp_eax, 31, 31) == 0) { 13930Sstevel@tonic-gate uint8_t *p = (void *)&cp->cp_eax; 1394*6317Skk208521 for (i = 1; i < 4; i++) 13950Sstevel@tonic-gate if (p[i] != 0) 13960Sstevel@tonic-gate *dp++ = p[i]; 13970Sstevel@tonic-gate } 13980Sstevel@tonic-gate if (BITX(cp->cp_ebx, 31, 31) == 0) { 13990Sstevel@tonic-gate uint8_t *p = (void *)&cp->cp_ebx; 14000Sstevel@tonic-gate for (i = 0; i < 4; i++) 14010Sstevel@tonic-gate if (p[i] != 0) 14020Sstevel@tonic-gate *dp++ = p[i]; 14030Sstevel@tonic-gate } 14040Sstevel@tonic-gate if (BITX(cp->cp_ecx, 31, 31) == 0) { 14050Sstevel@tonic-gate uint8_t *p = (void *)&cp->cp_ecx; 14060Sstevel@tonic-gate for (i = 0; i < 4; i++) 14070Sstevel@tonic-gate if (p[i] != 0) 14080Sstevel@tonic-gate *dp++ = p[i]; 14090Sstevel@tonic-gate } 14100Sstevel@tonic-gate if (BITX(cp->cp_edx, 31, 31) == 0) { 14110Sstevel@tonic-gate uint8_t *p = (void *)&cp->cp_edx; 14120Sstevel@tonic-gate for (i = 0; i < 4; i++) 14130Sstevel@tonic-gate if (p[i] != 0) 14140Sstevel@tonic-gate *dp++ = p[i]; 14150Sstevel@tonic-gate } 14160Sstevel@tonic-gate break; 14174481Sbholler 14180Sstevel@tonic-gate case 3: /* Processor serial number, if PSN supported */ 14194481Sbholler break; 14204481Sbholler 14210Sstevel@tonic-gate case 4: /* Deterministic cache parameters */ 14224481Sbholler break; 14234481Sbholler 14240Sstevel@tonic-gate case 5: /* Monitor/Mwait parameters */ 14255045Sbholler { 14265045Sbholler size_t mwait_size; 14274481Sbholler 14284481Sbholler /* 14294481Sbholler * check cpi_mwait.support which was set in cpuid_pass1 14304481Sbholler */ 14314481Sbholler if (!(cpi->cpi_mwait.support & MWAIT_SUPPORT)) 14324481Sbholler break; 14334481Sbholler 14345045Sbholler /* 14355045Sbholler * Protect ourself from insane mwait line size. 14365045Sbholler * Workaround for incomplete hardware emulator(s). 14375045Sbholler */ 14385045Sbholler mwait_size = (size_t)MWAIT_SIZE_MAX(cpi); 14395045Sbholler if (mwait_size < sizeof (uint32_t) || 14405045Sbholler !ISP2(mwait_size)) { 14415045Sbholler #if DEBUG 14425045Sbholler cmn_err(CE_NOTE, "Cannot handle cpu %d mwait " 14435045Sbholler "size %ld", 14445045Sbholler cpu->cpu_id, (long)mwait_size); 14455045Sbholler #endif 14465045Sbholler break; 14475045Sbholler } 14485045Sbholler 14494481Sbholler cpi->cpi_mwait.mon_min = (size_t)MWAIT_SIZE_MIN(cpi); 14505045Sbholler cpi->cpi_mwait.mon_max = mwait_size; 14514481Sbholler if (MWAIT_EXTENSION(cpi)) { 14524481Sbholler cpi->cpi_mwait.support |= MWAIT_EXTENSIONS; 14534481Sbholler if (MWAIT_INT_ENABLE(cpi)) 14544481Sbholler cpi->cpi_mwait.support |= 14554481Sbholler MWAIT_ECX_INT_ENABLE; 14564481Sbholler } 14574481Sbholler break; 14585045Sbholler } 14590Sstevel@tonic-gate default: 14600Sstevel@tonic-gate break; 14610Sstevel@tonic-gate } 14620Sstevel@tonic-gate } 14630Sstevel@tonic-gate 14640Sstevel@tonic-gate if ((cpi->cpi_xmaxeax & 0x80000000) == 0) 14650Sstevel@tonic-gate goto pass2_done; 14660Sstevel@tonic-gate 14670Sstevel@tonic-gate if ((nmax = cpi->cpi_xmaxeax - 0x80000000 + 1) > NMAX_CPI_EXTD) 14680Sstevel@tonic-gate nmax = NMAX_CPI_EXTD; 14690Sstevel@tonic-gate /* 14700Sstevel@tonic-gate * Copy the extended properties, fixing them as we go. 14710Sstevel@tonic-gate * (We already handled n == 0 and n == 1 in pass 1) 14720Sstevel@tonic-gate */ 14730Sstevel@tonic-gate iptr = (void *)cpi->cpi_brandstr; 14740Sstevel@tonic-gate for (n = 2, cp = &cpi->cpi_extd[2]; n < nmax; cp++, n++) { 14751228Sandrei cp->cp_eax = 0x80000000 + n; 14761228Sandrei (void) __cpuid_insn(cp); 14773446Smrj platform_cpuid_mangle(cpi->cpi_vendor, 0x80000000 + n, cp); 14780Sstevel@tonic-gate switch (n) { 14790Sstevel@tonic-gate case 2: 14800Sstevel@tonic-gate case 3: 14810Sstevel@tonic-gate case 4: 14820Sstevel@tonic-gate /* 14830Sstevel@tonic-gate * Extract the brand string 14840Sstevel@tonic-gate */ 14850Sstevel@tonic-gate *iptr++ = cp->cp_eax; 14860Sstevel@tonic-gate *iptr++ = cp->cp_ebx; 14870Sstevel@tonic-gate *iptr++ = cp->cp_ecx; 14880Sstevel@tonic-gate *iptr++ = cp->cp_edx; 14890Sstevel@tonic-gate break; 14900Sstevel@tonic-gate case 5: 14910Sstevel@tonic-gate switch (cpi->cpi_vendor) { 14920Sstevel@tonic-gate case X86_VENDOR_AMD: 14930Sstevel@tonic-gate /* 14940Sstevel@tonic-gate * The Athlon and Duron were the first 14950Sstevel@tonic-gate * parts to report the sizes of the 14960Sstevel@tonic-gate * TLB for large pages. Before then, 14970Sstevel@tonic-gate * we don't trust the data. 14980Sstevel@tonic-gate */ 14990Sstevel@tonic-gate if (cpi->cpi_family < 6 || 15000Sstevel@tonic-gate (cpi->cpi_family == 6 && 15010Sstevel@tonic-gate cpi->cpi_model < 1)) 15020Sstevel@tonic-gate cp->cp_eax = 0; 15030Sstevel@tonic-gate break; 15040Sstevel@tonic-gate default: 15050Sstevel@tonic-gate break; 15060Sstevel@tonic-gate } 15070Sstevel@tonic-gate break; 15080Sstevel@tonic-gate case 6: 15090Sstevel@tonic-gate switch (cpi->cpi_vendor) { 15100Sstevel@tonic-gate case X86_VENDOR_AMD: 15110Sstevel@tonic-gate /* 15120Sstevel@tonic-gate * The Athlon and Duron were the first 15130Sstevel@tonic-gate * AMD parts with L2 TLB's. 15140Sstevel@tonic-gate * Before then, don't trust the data. 15150Sstevel@tonic-gate */ 15160Sstevel@tonic-gate if (cpi->cpi_family < 6 || 15170Sstevel@tonic-gate cpi->cpi_family == 6 && 15180Sstevel@tonic-gate cpi->cpi_model < 1) 15190Sstevel@tonic-gate cp->cp_eax = cp->cp_ebx = 0; 15200Sstevel@tonic-gate /* 15210Sstevel@tonic-gate * AMD Duron rev A0 reports L2 15220Sstevel@tonic-gate * cache size incorrectly as 1K 15230Sstevel@tonic-gate * when it is really 64K 15240Sstevel@tonic-gate */ 15250Sstevel@tonic-gate if (cpi->cpi_family == 6 && 15260Sstevel@tonic-gate cpi->cpi_model == 3 && 15270Sstevel@tonic-gate cpi->cpi_step == 0) { 15280Sstevel@tonic-gate cp->cp_ecx &= 0xffff; 15290Sstevel@tonic-gate cp->cp_ecx |= 0x400000; 15300Sstevel@tonic-gate } 15310Sstevel@tonic-gate break; 15320Sstevel@tonic-gate case X86_VENDOR_Cyrix: /* VIA C3 */ 15330Sstevel@tonic-gate /* 15340Sstevel@tonic-gate * VIA C3 processors are a bit messed 15350Sstevel@tonic-gate * up w.r.t. encoding cache sizes in %ecx 15360Sstevel@tonic-gate */ 15370Sstevel@tonic-gate if (cpi->cpi_family != 6) 15380Sstevel@tonic-gate break; 15390Sstevel@tonic-gate /* 15400Sstevel@tonic-gate * model 7 and 8 were incorrectly encoded 15410Sstevel@tonic-gate * 15420Sstevel@tonic-gate * xxx is model 8 really broken? 15430Sstevel@tonic-gate */ 15440Sstevel@tonic-gate if (cpi->cpi_model == 7 || 15450Sstevel@tonic-gate cpi->cpi_model == 8) 15460Sstevel@tonic-gate cp->cp_ecx = 15470Sstevel@tonic-gate BITX(cp->cp_ecx, 31, 24) << 16 | 15480Sstevel@tonic-gate BITX(cp->cp_ecx, 23, 16) << 12 | 15490Sstevel@tonic-gate BITX(cp->cp_ecx, 15, 8) << 8 | 15500Sstevel@tonic-gate BITX(cp->cp_ecx, 7, 0); 15510Sstevel@tonic-gate /* 15520Sstevel@tonic-gate * model 9 stepping 1 has wrong associativity 15530Sstevel@tonic-gate */ 15540Sstevel@tonic-gate if (cpi->cpi_model == 9 && cpi->cpi_step == 1) 15550Sstevel@tonic-gate cp->cp_ecx |= 8 << 12; 15560Sstevel@tonic-gate break; 15570Sstevel@tonic-gate case X86_VENDOR_Intel: 15580Sstevel@tonic-gate /* 15590Sstevel@tonic-gate * Extended L2 Cache features function. 15600Sstevel@tonic-gate * First appeared on Prescott. 15610Sstevel@tonic-gate */ 15620Sstevel@tonic-gate default: 15630Sstevel@tonic-gate break; 15640Sstevel@tonic-gate } 15650Sstevel@tonic-gate break; 15660Sstevel@tonic-gate default: 15670Sstevel@tonic-gate break; 15680Sstevel@tonic-gate } 15690Sstevel@tonic-gate } 15700Sstevel@tonic-gate 15710Sstevel@tonic-gate pass2_done: 15720Sstevel@tonic-gate cpi->cpi_pass = 2; 15730Sstevel@tonic-gate } 15740Sstevel@tonic-gate 15750Sstevel@tonic-gate static const char * 15760Sstevel@tonic-gate intel_cpubrand(const struct cpuid_info *cpi) 15770Sstevel@tonic-gate { 15780Sstevel@tonic-gate int i; 15790Sstevel@tonic-gate 15800Sstevel@tonic-gate if ((x86_feature & X86_CPUID) == 0 || 15810Sstevel@tonic-gate cpi->cpi_maxeax < 1 || cpi->cpi_family < 5) 15820Sstevel@tonic-gate return ("i486"); 15830Sstevel@tonic-gate 15840Sstevel@tonic-gate switch (cpi->cpi_family) { 15850Sstevel@tonic-gate case 5: 15860Sstevel@tonic-gate return ("Intel Pentium(r)"); 15870Sstevel@tonic-gate case 6: 15880Sstevel@tonic-gate switch (cpi->cpi_model) { 15890Sstevel@tonic-gate uint_t celeron, xeon; 15901228Sandrei const struct cpuid_regs *cp; 15910Sstevel@tonic-gate case 0: 15920Sstevel@tonic-gate case 1: 15930Sstevel@tonic-gate case 2: 15940Sstevel@tonic-gate return ("Intel Pentium(r) Pro"); 15950Sstevel@tonic-gate case 3: 15960Sstevel@tonic-gate case 4: 15970Sstevel@tonic-gate return ("Intel Pentium(r) II"); 15980Sstevel@tonic-gate case 6: 15990Sstevel@tonic-gate return ("Intel Celeron(r)"); 16000Sstevel@tonic-gate case 5: 16010Sstevel@tonic-gate case 7: 16020Sstevel@tonic-gate celeron = xeon = 0; 16030Sstevel@tonic-gate cp = &cpi->cpi_std[2]; /* cache info */ 16040Sstevel@tonic-gate 1605*6317Skk208521 for (i = 1; i < 4; i++) { 16060Sstevel@tonic-gate uint_t tmp; 16070Sstevel@tonic-gate 16080Sstevel@tonic-gate tmp = (cp->cp_eax >> (8 * i)) & 0xff; 16090Sstevel@tonic-gate if (tmp == 0x40) 16100Sstevel@tonic-gate celeron++; 16110Sstevel@tonic-gate if (tmp >= 0x44 && tmp <= 0x45) 16120Sstevel@tonic-gate xeon++; 16130Sstevel@tonic-gate } 16140Sstevel@tonic-gate 16150Sstevel@tonic-gate for (i = 0; i < 2; i++) { 16160Sstevel@tonic-gate uint_t tmp; 16170Sstevel@tonic-gate 16180Sstevel@tonic-gate tmp = (cp->cp_ebx >> (8 * i)) & 0xff; 16190Sstevel@tonic-gate if (tmp == 0x40) 16200Sstevel@tonic-gate celeron++; 16210Sstevel@tonic-gate else if (tmp >= 0x44 && tmp <= 0x45) 16220Sstevel@tonic-gate xeon++; 16230Sstevel@tonic-gate } 16240Sstevel@tonic-gate 16250Sstevel@tonic-gate for (i = 0; i < 4; i++) { 16260Sstevel@tonic-gate uint_t tmp; 16270Sstevel@tonic-gate 16280Sstevel@tonic-gate tmp = (cp->cp_ecx >> (8 * i)) & 0xff; 16290Sstevel@tonic-gate if (tmp == 0x40) 16300Sstevel@tonic-gate celeron++; 16310Sstevel@tonic-gate else if (tmp >= 0x44 && tmp <= 0x45) 16320Sstevel@tonic-gate xeon++; 16330Sstevel@tonic-gate } 16340Sstevel@tonic-gate 16350Sstevel@tonic-gate for (i = 0; i < 4; i++) { 16360Sstevel@tonic-gate uint_t tmp; 16370Sstevel@tonic-gate 16380Sstevel@tonic-gate tmp = (cp->cp_edx >> (8 * i)) & 0xff; 16390Sstevel@tonic-gate if (tmp == 0x40) 16400Sstevel@tonic-gate celeron++; 16410Sstevel@tonic-gate else if (tmp >= 0x44 && tmp <= 0x45) 16420Sstevel@tonic-gate xeon++; 16430Sstevel@tonic-gate } 16440Sstevel@tonic-gate 16450Sstevel@tonic-gate if (celeron) 16460Sstevel@tonic-gate return ("Intel Celeron(r)"); 16470Sstevel@tonic-gate if (xeon) 16480Sstevel@tonic-gate return (cpi->cpi_model == 5 ? 16490Sstevel@tonic-gate "Intel Pentium(r) II Xeon(tm)" : 16500Sstevel@tonic-gate "Intel Pentium(r) III Xeon(tm)"); 16510Sstevel@tonic-gate return (cpi->cpi_model == 5 ? 16520Sstevel@tonic-gate "Intel Pentium(r) II or Pentium(r) II Xeon(tm)" : 16530Sstevel@tonic-gate "Intel Pentium(r) III or Pentium(r) III Xeon(tm)"); 16540Sstevel@tonic-gate default: 16550Sstevel@tonic-gate break; 16560Sstevel@tonic-gate } 16570Sstevel@tonic-gate default: 16580Sstevel@tonic-gate break; 16590Sstevel@tonic-gate } 16600Sstevel@tonic-gate 16611975Sdmick /* BrandID is present if the field is nonzero */ 16621975Sdmick if (cpi->cpi_brandid != 0) { 16630Sstevel@tonic-gate static const struct { 16640Sstevel@tonic-gate uint_t bt_bid; 16650Sstevel@tonic-gate const char *bt_str; 16660Sstevel@tonic-gate } brand_tbl[] = { 16670Sstevel@tonic-gate { 0x1, "Intel(r) Celeron(r)" }, 16680Sstevel@tonic-gate { 0x2, "Intel(r) Pentium(r) III" }, 16690Sstevel@tonic-gate { 0x3, "Intel(r) Pentium(r) III Xeon(tm)" }, 16700Sstevel@tonic-gate { 0x4, "Intel(r) Pentium(r) III" }, 16710Sstevel@tonic-gate { 0x6, "Mobile Intel(r) Pentium(r) III" }, 16720Sstevel@tonic-gate { 0x7, "Mobile Intel(r) Celeron(r)" }, 16730Sstevel@tonic-gate { 0x8, "Intel(r) Pentium(r) 4" }, 16740Sstevel@tonic-gate { 0x9, "Intel(r) Pentium(r) 4" }, 16750Sstevel@tonic-gate { 0xa, "Intel(r) Celeron(r)" }, 16760Sstevel@tonic-gate { 0xb, "Intel(r) Xeon(tm)" }, 16770Sstevel@tonic-gate { 0xc, "Intel(r) Xeon(tm) MP" }, 16780Sstevel@tonic-gate { 0xe, "Mobile Intel(r) Pentium(r) 4" }, 16791975Sdmick { 0xf, "Mobile Intel(r) Celeron(r)" }, 16801975Sdmick { 0x11, "Mobile Genuine Intel(r)" }, 16811975Sdmick { 0x12, "Intel(r) Celeron(r) M" }, 16821975Sdmick { 0x13, "Mobile Intel(r) Celeron(r)" }, 16831975Sdmick { 0x14, "Intel(r) Celeron(r)" }, 16841975Sdmick { 0x15, "Mobile Genuine Intel(r)" }, 16851975Sdmick { 0x16, "Intel(r) Pentium(r) M" }, 16861975Sdmick { 0x17, "Mobile Intel(r) Celeron(r)" } 16870Sstevel@tonic-gate }; 16880Sstevel@tonic-gate uint_t btblmax = sizeof (brand_tbl) / sizeof (brand_tbl[0]); 16890Sstevel@tonic-gate uint_t sgn; 16900Sstevel@tonic-gate 16910Sstevel@tonic-gate sgn = (cpi->cpi_family << 8) | 16920Sstevel@tonic-gate (cpi->cpi_model << 4) | cpi->cpi_step; 16930Sstevel@tonic-gate 16940Sstevel@tonic-gate for (i = 0; i < btblmax; i++) 16950Sstevel@tonic-gate if (brand_tbl[i].bt_bid == cpi->cpi_brandid) 16960Sstevel@tonic-gate break; 16970Sstevel@tonic-gate if (i < btblmax) { 16980Sstevel@tonic-gate if (sgn == 0x6b1 && cpi->cpi_brandid == 3) 16990Sstevel@tonic-gate return ("Intel(r) Celeron(r)"); 17000Sstevel@tonic-gate if (sgn < 0xf13 && cpi->cpi_brandid == 0xb) 17010Sstevel@tonic-gate return ("Intel(r) Xeon(tm) MP"); 17020Sstevel@tonic-gate if (sgn < 0xf13 && cpi->cpi_brandid == 0xe) 17030Sstevel@tonic-gate return ("Intel(r) Xeon(tm)"); 17040Sstevel@tonic-gate return (brand_tbl[i].bt_str); 17050Sstevel@tonic-gate } 17060Sstevel@tonic-gate } 17070Sstevel@tonic-gate 17080Sstevel@tonic-gate return (NULL); 17090Sstevel@tonic-gate } 17100Sstevel@tonic-gate 17110Sstevel@tonic-gate static const char * 17120Sstevel@tonic-gate amd_cpubrand(const struct cpuid_info *cpi) 17130Sstevel@tonic-gate { 17140Sstevel@tonic-gate if ((x86_feature & X86_CPUID) == 0 || 17150Sstevel@tonic-gate cpi->cpi_maxeax < 1 || cpi->cpi_family < 5) 17160Sstevel@tonic-gate return ("i486 compatible"); 17170Sstevel@tonic-gate 17180Sstevel@tonic-gate switch (cpi->cpi_family) { 17190Sstevel@tonic-gate case 5: 17200Sstevel@tonic-gate switch (cpi->cpi_model) { 17210Sstevel@tonic-gate case 0: 17220Sstevel@tonic-gate case 1: 17230Sstevel@tonic-gate case 2: 17240Sstevel@tonic-gate case 3: 17250Sstevel@tonic-gate case 4: 17260Sstevel@tonic-gate case 5: 17270Sstevel@tonic-gate return ("AMD-K5(r)"); 17280Sstevel@tonic-gate case 6: 17290Sstevel@tonic-gate case 7: 17300Sstevel@tonic-gate return ("AMD-K6(r)"); 17310Sstevel@tonic-gate case 8: 17320Sstevel@tonic-gate return ("AMD-K6(r)-2"); 17330Sstevel@tonic-gate case 9: 17340Sstevel@tonic-gate return ("AMD-K6(r)-III"); 17350Sstevel@tonic-gate default: 17360Sstevel@tonic-gate return ("AMD (family 5)"); 17370Sstevel@tonic-gate } 17380Sstevel@tonic-gate case 6: 17390Sstevel@tonic-gate switch (cpi->cpi_model) { 17400Sstevel@tonic-gate case 1: 17410Sstevel@tonic-gate return ("AMD-K7(tm)"); 17420Sstevel@tonic-gate case 0: 17430Sstevel@tonic-gate case 2: 17440Sstevel@tonic-gate case 4: 17450Sstevel@tonic-gate return ("AMD Athlon(tm)"); 17460Sstevel@tonic-gate case 3: 17470Sstevel@tonic-gate case 7: 17480Sstevel@tonic-gate return ("AMD Duron(tm)"); 17490Sstevel@tonic-gate case 6: 17500Sstevel@tonic-gate case 8: 17510Sstevel@tonic-gate case 10: 17520Sstevel@tonic-gate /* 17530Sstevel@tonic-gate * Use the L2 cache size to distinguish 17540Sstevel@tonic-gate */ 17550Sstevel@tonic-gate return ((cpi->cpi_extd[6].cp_ecx >> 16) >= 256 ? 17560Sstevel@tonic-gate "AMD Athlon(tm)" : "AMD Duron(tm)"); 17570Sstevel@tonic-gate default: 17580Sstevel@tonic-gate return ("AMD (family 6)"); 17590Sstevel@tonic-gate } 17600Sstevel@tonic-gate default: 17610Sstevel@tonic-gate break; 17620Sstevel@tonic-gate } 17630Sstevel@tonic-gate 17640Sstevel@tonic-gate if (cpi->cpi_family == 0xf && cpi->cpi_model == 5 && 17650Sstevel@tonic-gate cpi->cpi_brandid != 0) { 17660Sstevel@tonic-gate switch (BITX(cpi->cpi_brandid, 7, 5)) { 17670Sstevel@tonic-gate case 3: 17680Sstevel@tonic-gate return ("AMD Opteron(tm) UP 1xx"); 17690Sstevel@tonic-gate case 4: 17700Sstevel@tonic-gate return ("AMD Opteron(tm) DP 2xx"); 17710Sstevel@tonic-gate case 5: 17720Sstevel@tonic-gate return ("AMD Opteron(tm) MP 8xx"); 17730Sstevel@tonic-gate default: 17740Sstevel@tonic-gate return ("AMD Opteron(tm)"); 17750Sstevel@tonic-gate } 17760Sstevel@tonic-gate } 17770Sstevel@tonic-gate 17780Sstevel@tonic-gate return (NULL); 17790Sstevel@tonic-gate } 17800Sstevel@tonic-gate 17810Sstevel@tonic-gate static const char * 17820Sstevel@tonic-gate cyrix_cpubrand(struct cpuid_info *cpi, uint_t type) 17830Sstevel@tonic-gate { 17840Sstevel@tonic-gate if ((x86_feature & X86_CPUID) == 0 || 17850Sstevel@tonic-gate cpi->cpi_maxeax < 1 || cpi->cpi_family < 5 || 17860Sstevel@tonic-gate type == X86_TYPE_CYRIX_486) 17870Sstevel@tonic-gate return ("i486 compatible"); 17880Sstevel@tonic-gate 17890Sstevel@tonic-gate switch (type) { 17900Sstevel@tonic-gate case X86_TYPE_CYRIX_6x86: 17910Sstevel@tonic-gate return ("Cyrix 6x86"); 17920Sstevel@tonic-gate case X86_TYPE_CYRIX_6x86L: 17930Sstevel@tonic-gate return ("Cyrix 6x86L"); 17940Sstevel@tonic-gate case X86_TYPE_CYRIX_6x86MX: 17950Sstevel@tonic-gate return ("Cyrix 6x86MX"); 17960Sstevel@tonic-gate case X86_TYPE_CYRIX_GXm: 17970Sstevel@tonic-gate return ("Cyrix GXm"); 17980Sstevel@tonic-gate case X86_TYPE_CYRIX_MediaGX: 17990Sstevel@tonic-gate return ("Cyrix MediaGX"); 18000Sstevel@tonic-gate case X86_TYPE_CYRIX_MII: 18010Sstevel@tonic-gate return ("Cyrix M2"); 18020Sstevel@tonic-gate case X86_TYPE_VIA_CYRIX_III: 18030Sstevel@tonic-gate return ("VIA Cyrix M3"); 18040Sstevel@tonic-gate default: 18050Sstevel@tonic-gate /* 18060Sstevel@tonic-gate * Have another wild guess .. 18070Sstevel@tonic-gate */ 18080Sstevel@tonic-gate if (cpi->cpi_family == 4 && cpi->cpi_model == 9) 18090Sstevel@tonic-gate return ("Cyrix 5x86"); 18100Sstevel@tonic-gate else if (cpi->cpi_family == 5) { 18110Sstevel@tonic-gate switch (cpi->cpi_model) { 18120Sstevel@tonic-gate case 2: 18130Sstevel@tonic-gate return ("Cyrix 6x86"); /* Cyrix M1 */ 18140Sstevel@tonic-gate case 4: 18150Sstevel@tonic-gate return ("Cyrix MediaGX"); 18160Sstevel@tonic-gate default: 18170Sstevel@tonic-gate break; 18180Sstevel@tonic-gate } 18190Sstevel@tonic-gate } else if (cpi->cpi_family == 6) { 18200Sstevel@tonic-gate switch (cpi->cpi_model) { 18210Sstevel@tonic-gate case 0: 18220Sstevel@tonic-gate return ("Cyrix 6x86MX"); /* Cyrix M2? */ 18230Sstevel@tonic-gate case 5: 18240Sstevel@tonic-gate case 6: 18250Sstevel@tonic-gate case 7: 18260Sstevel@tonic-gate case 8: 18270Sstevel@tonic-gate case 9: 18280Sstevel@tonic-gate return ("VIA C3"); 18290Sstevel@tonic-gate default: 18300Sstevel@tonic-gate break; 18310Sstevel@tonic-gate } 18320Sstevel@tonic-gate } 18330Sstevel@tonic-gate break; 18340Sstevel@tonic-gate } 18350Sstevel@tonic-gate return (NULL); 18360Sstevel@tonic-gate } 18370Sstevel@tonic-gate 18380Sstevel@tonic-gate /* 18390Sstevel@tonic-gate * This only gets called in the case that the CPU extended 18400Sstevel@tonic-gate * feature brand string (0x80000002, 0x80000003, 0x80000004) 18410Sstevel@tonic-gate * aren't available, or contain null bytes for some reason. 18420Sstevel@tonic-gate */ 18430Sstevel@tonic-gate static void 18440Sstevel@tonic-gate fabricate_brandstr(struct cpuid_info *cpi) 18450Sstevel@tonic-gate { 18460Sstevel@tonic-gate const char *brand = NULL; 18470Sstevel@tonic-gate 18480Sstevel@tonic-gate switch (cpi->cpi_vendor) { 18490Sstevel@tonic-gate case X86_VENDOR_Intel: 18500Sstevel@tonic-gate brand = intel_cpubrand(cpi); 18510Sstevel@tonic-gate break; 18520Sstevel@tonic-gate case X86_VENDOR_AMD: 18530Sstevel@tonic-gate brand = amd_cpubrand(cpi); 18540Sstevel@tonic-gate break; 18550Sstevel@tonic-gate case X86_VENDOR_Cyrix: 18560Sstevel@tonic-gate brand = cyrix_cpubrand(cpi, x86_type); 18570Sstevel@tonic-gate break; 18580Sstevel@tonic-gate case X86_VENDOR_NexGen: 18590Sstevel@tonic-gate if (cpi->cpi_family == 5 && cpi->cpi_model == 0) 18600Sstevel@tonic-gate brand = "NexGen Nx586"; 18610Sstevel@tonic-gate break; 18620Sstevel@tonic-gate case X86_VENDOR_Centaur: 18630Sstevel@tonic-gate if (cpi->cpi_family == 5) 18640Sstevel@tonic-gate switch (cpi->cpi_model) { 18650Sstevel@tonic-gate case 4: 18660Sstevel@tonic-gate brand = "Centaur C6"; 18670Sstevel@tonic-gate break; 18680Sstevel@tonic-gate case 8: 18690Sstevel@tonic-gate brand = "Centaur C2"; 18700Sstevel@tonic-gate break; 18710Sstevel@tonic-gate case 9: 18720Sstevel@tonic-gate brand = "Centaur C3"; 18730Sstevel@tonic-gate break; 18740Sstevel@tonic-gate default: 18750Sstevel@tonic-gate break; 18760Sstevel@tonic-gate } 18770Sstevel@tonic-gate break; 18780Sstevel@tonic-gate case X86_VENDOR_Rise: 18790Sstevel@tonic-gate if (cpi->cpi_family == 5 && 18800Sstevel@tonic-gate (cpi->cpi_model == 0 || cpi->cpi_model == 2)) 18810Sstevel@tonic-gate brand = "Rise mP6"; 18820Sstevel@tonic-gate break; 18830Sstevel@tonic-gate case X86_VENDOR_SiS: 18840Sstevel@tonic-gate if (cpi->cpi_family == 5 && cpi->cpi_model == 0) 18850Sstevel@tonic-gate brand = "SiS 55x"; 18860Sstevel@tonic-gate break; 18870Sstevel@tonic-gate case X86_VENDOR_TM: 18880Sstevel@tonic-gate if (cpi->cpi_family == 5 && cpi->cpi_model == 4) 18890Sstevel@tonic-gate brand = "Transmeta Crusoe TM3x00 or TM5x00"; 18900Sstevel@tonic-gate break; 18910Sstevel@tonic-gate case X86_VENDOR_NSC: 18920Sstevel@tonic-gate case X86_VENDOR_UMC: 18930Sstevel@tonic-gate default: 18940Sstevel@tonic-gate break; 18950Sstevel@tonic-gate } 18960Sstevel@tonic-gate if (brand) { 18970Sstevel@tonic-gate (void) strcpy((char *)cpi->cpi_brandstr, brand); 18980Sstevel@tonic-gate return; 18990Sstevel@tonic-gate } 19000Sstevel@tonic-gate 19010Sstevel@tonic-gate /* 19020Sstevel@tonic-gate * If all else fails ... 19030Sstevel@tonic-gate */ 19040Sstevel@tonic-gate (void) snprintf(cpi->cpi_brandstr, sizeof (cpi->cpi_brandstr), 19050Sstevel@tonic-gate "%s %d.%d.%d", cpi->cpi_vendorstr, cpi->cpi_family, 19060Sstevel@tonic-gate cpi->cpi_model, cpi->cpi_step); 19070Sstevel@tonic-gate } 19080Sstevel@tonic-gate 19090Sstevel@tonic-gate /* 19100Sstevel@tonic-gate * This routine is called just after kernel memory allocation 19110Sstevel@tonic-gate * becomes available on cpu0, and as part of mp_startup() on 19120Sstevel@tonic-gate * the other cpus. 19130Sstevel@tonic-gate * 19144606Sesaxe * Fixup the brand string, and collect any information from cpuid 19154606Sesaxe * that requires dynamicically allocated storage to represent. 19160Sstevel@tonic-gate */ 19170Sstevel@tonic-gate /*ARGSUSED*/ 19180Sstevel@tonic-gate void 19190Sstevel@tonic-gate cpuid_pass3(cpu_t *cpu) 19200Sstevel@tonic-gate { 19214606Sesaxe int i, max, shft, level, size; 19224606Sesaxe struct cpuid_regs regs; 19234606Sesaxe struct cpuid_regs *cp; 19240Sstevel@tonic-gate struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 19250Sstevel@tonic-gate 19260Sstevel@tonic-gate ASSERT(cpi->cpi_pass == 2); 19270Sstevel@tonic-gate 19284606Sesaxe /* 19294606Sesaxe * Function 4: Deterministic cache parameters 19304606Sesaxe * 19314606Sesaxe * Take this opportunity to detect the number of threads 19324606Sesaxe * sharing the last level cache, and construct a corresponding 19334606Sesaxe * cache id. The respective cpuid_info members are initialized 19344606Sesaxe * to the default case of "no last level cache sharing". 19354606Sesaxe */ 19364606Sesaxe cpi->cpi_ncpu_shr_last_cache = 1; 19374606Sesaxe cpi->cpi_last_lvl_cacheid = cpu->cpu_id; 19384606Sesaxe 19394606Sesaxe if (cpi->cpi_maxeax >= 4 && cpi->cpi_vendor == X86_VENDOR_Intel) { 19404606Sesaxe 19414606Sesaxe /* 19424606Sesaxe * Find the # of elements (size) returned by fn 4, and along 19434606Sesaxe * the way detect last level cache sharing details. 19444606Sesaxe */ 19454606Sesaxe bzero(®s, sizeof (regs)); 19464606Sesaxe cp = ®s; 19474606Sesaxe for (i = 0, max = 0; i < CPI_FN4_ECX_MAX; i++) { 19484606Sesaxe cp->cp_eax = 4; 19494606Sesaxe cp->cp_ecx = i; 19504606Sesaxe 19514606Sesaxe (void) __cpuid_insn(cp); 19524606Sesaxe 19534606Sesaxe if (CPI_CACHE_TYPE(cp) == 0) 19544606Sesaxe break; 19554606Sesaxe level = CPI_CACHE_LVL(cp); 19564606Sesaxe if (level > max) { 19574606Sesaxe max = level; 19584606Sesaxe cpi->cpi_ncpu_shr_last_cache = 19594606Sesaxe CPI_NTHR_SHR_CACHE(cp) + 1; 19604606Sesaxe } 19614606Sesaxe } 19624606Sesaxe cpi->cpi_std_4_size = size = i; 19634606Sesaxe 19644606Sesaxe /* 19654606Sesaxe * Allocate the cpi_std_4 array. The first element 19664606Sesaxe * references the regs for fn 4, %ecx == 0, which 19674606Sesaxe * cpuid_pass2() stashed in cpi->cpi_std[4]. 19684606Sesaxe */ 19694606Sesaxe if (size > 0) { 19704606Sesaxe cpi->cpi_std_4 = 19714606Sesaxe kmem_alloc(size * sizeof (cp), KM_SLEEP); 19724606Sesaxe cpi->cpi_std_4[0] = &cpi->cpi_std[4]; 19734606Sesaxe 19744606Sesaxe /* 19754606Sesaxe * Allocate storage to hold the additional regs 19764606Sesaxe * for function 4, %ecx == 1 .. cpi_std_4_size. 19774606Sesaxe * 19784606Sesaxe * The regs for fn 4, %ecx == 0 has already 19794606Sesaxe * been allocated as indicated above. 19804606Sesaxe */ 19814606Sesaxe for (i = 1; i < size; i++) { 19824606Sesaxe cp = cpi->cpi_std_4[i] = 19834606Sesaxe kmem_zalloc(sizeof (regs), KM_SLEEP); 19844606Sesaxe cp->cp_eax = 4; 19854606Sesaxe cp->cp_ecx = i; 19864606Sesaxe 19874606Sesaxe (void) __cpuid_insn(cp); 19884606Sesaxe } 19894606Sesaxe } 19904606Sesaxe /* 19914606Sesaxe * Determine the number of bits needed to represent 19924606Sesaxe * the number of CPUs sharing the last level cache. 19934606Sesaxe * 19944606Sesaxe * Shift off that number of bits from the APIC id to 19954606Sesaxe * derive the cache id. 19964606Sesaxe */ 19974606Sesaxe shft = 0; 19984606Sesaxe for (i = 1; i < cpi->cpi_ncpu_shr_last_cache; i <<= 1) 19994606Sesaxe shft++; 20004606Sesaxe cpi->cpi_last_lvl_cacheid = CPI_APIC_ID(cpi) >> shft; 20010Sstevel@tonic-gate } 20020Sstevel@tonic-gate 20030Sstevel@tonic-gate /* 20044606Sesaxe * Now fixup the brand string 20050Sstevel@tonic-gate */ 20064606Sesaxe if ((cpi->cpi_xmaxeax & 0x80000000) == 0) { 20074606Sesaxe fabricate_brandstr(cpi); 20084606Sesaxe } else { 20090Sstevel@tonic-gate 20100Sstevel@tonic-gate /* 20114606Sesaxe * If we successfully extracted a brand string from the cpuid 20124606Sesaxe * instruction, clean it up by removing leading spaces and 20134606Sesaxe * similar junk. 20140Sstevel@tonic-gate */ 20154606Sesaxe if (cpi->cpi_brandstr[0]) { 20164606Sesaxe size_t maxlen = sizeof (cpi->cpi_brandstr); 20174606Sesaxe char *src, *dst; 20184606Sesaxe 20194606Sesaxe dst = src = (char *)cpi->cpi_brandstr; 20204606Sesaxe src[maxlen - 1] = '\0'; 20214606Sesaxe /* 20224606Sesaxe * strip leading spaces 20234606Sesaxe */ 20244606Sesaxe while (*src == ' ') 20254606Sesaxe src++; 20264606Sesaxe /* 20274606Sesaxe * Remove any 'Genuine' or "Authentic" prefixes 20284606Sesaxe */ 20294606Sesaxe if (strncmp(src, "Genuine ", 8) == 0) 20304606Sesaxe src += 8; 20314606Sesaxe if (strncmp(src, "Authentic ", 10) == 0) 20324606Sesaxe src += 10; 20334606Sesaxe 20344606Sesaxe /* 20354606Sesaxe * Now do an in-place copy. 20364606Sesaxe * Map (R) to (r) and (TM) to (tm). 20374606Sesaxe * The era of teletypes is long gone, and there's 20384606Sesaxe * -really- no need to shout. 20394606Sesaxe */ 20404606Sesaxe while (*src != '\0') { 20414606Sesaxe if (src[0] == '(') { 20424606Sesaxe if (strncmp(src + 1, "R)", 2) == 0) { 20434606Sesaxe (void) strncpy(dst, "(r)", 3); 20444606Sesaxe src += 3; 20454606Sesaxe dst += 3; 20464606Sesaxe continue; 20474606Sesaxe } 20484606Sesaxe if (strncmp(src + 1, "TM)", 3) == 0) { 20494606Sesaxe (void) strncpy(dst, "(tm)", 4); 20504606Sesaxe src += 4; 20514606Sesaxe dst += 4; 20524606Sesaxe continue; 20534606Sesaxe } 20540Sstevel@tonic-gate } 20554606Sesaxe *dst++ = *src++; 20560Sstevel@tonic-gate } 20574606Sesaxe *dst = '\0'; 20584606Sesaxe 20594606Sesaxe /* 20604606Sesaxe * Finally, remove any trailing spaces 20614606Sesaxe */ 20624606Sesaxe while (--dst > cpi->cpi_brandstr) 20634606Sesaxe if (*dst == ' ') 20644606Sesaxe *dst = '\0'; 20654606Sesaxe else 20664606Sesaxe break; 20674606Sesaxe } else 20684606Sesaxe fabricate_brandstr(cpi); 20694606Sesaxe } 20700Sstevel@tonic-gate cpi->cpi_pass = 3; 20710Sstevel@tonic-gate } 20720Sstevel@tonic-gate 20730Sstevel@tonic-gate /* 20740Sstevel@tonic-gate * This routine is called out of bind_hwcap() much later in the life 20750Sstevel@tonic-gate * of the kernel (post_startup()). The job of this routine is to resolve 20760Sstevel@tonic-gate * the hardware feature support and kernel support for those features into 20770Sstevel@tonic-gate * what we're actually going to tell applications via the aux vector. 20780Sstevel@tonic-gate */ 20790Sstevel@tonic-gate uint_t 20800Sstevel@tonic-gate cpuid_pass4(cpu_t *cpu) 20810Sstevel@tonic-gate { 20820Sstevel@tonic-gate struct cpuid_info *cpi; 20830Sstevel@tonic-gate uint_t hwcap_flags = 0; 20840Sstevel@tonic-gate 20850Sstevel@tonic-gate if (cpu == NULL) 20860Sstevel@tonic-gate cpu = CPU; 20870Sstevel@tonic-gate cpi = cpu->cpu_m.mcpu_cpi; 20880Sstevel@tonic-gate 20890Sstevel@tonic-gate ASSERT(cpi->cpi_pass == 3); 20900Sstevel@tonic-gate 20910Sstevel@tonic-gate if (cpi->cpi_maxeax >= 1) { 20920Sstevel@tonic-gate uint32_t *edx = &cpi->cpi_support[STD_EDX_FEATURES]; 20930Sstevel@tonic-gate uint32_t *ecx = &cpi->cpi_support[STD_ECX_FEATURES]; 20940Sstevel@tonic-gate 20950Sstevel@tonic-gate *edx = CPI_FEATURES_EDX(cpi); 20960Sstevel@tonic-gate *ecx = CPI_FEATURES_ECX(cpi); 20970Sstevel@tonic-gate 20980Sstevel@tonic-gate /* 20990Sstevel@tonic-gate * [these require explicit kernel support] 21000Sstevel@tonic-gate */ 21010Sstevel@tonic-gate if ((x86_feature & X86_SEP) == 0) 21020Sstevel@tonic-gate *edx &= ~CPUID_INTC_EDX_SEP; 21030Sstevel@tonic-gate 21040Sstevel@tonic-gate if ((x86_feature & X86_SSE) == 0) 21050Sstevel@tonic-gate *edx &= ~(CPUID_INTC_EDX_FXSR|CPUID_INTC_EDX_SSE); 21060Sstevel@tonic-gate if ((x86_feature & X86_SSE2) == 0) 21070Sstevel@tonic-gate *edx &= ~CPUID_INTC_EDX_SSE2; 21080Sstevel@tonic-gate 21090Sstevel@tonic-gate if ((x86_feature & X86_HTT) == 0) 21100Sstevel@tonic-gate *edx &= ~CPUID_INTC_EDX_HTT; 21110Sstevel@tonic-gate 21120Sstevel@tonic-gate if ((x86_feature & X86_SSE3) == 0) 21130Sstevel@tonic-gate *ecx &= ~CPUID_INTC_ECX_SSE3; 21140Sstevel@tonic-gate 21155269Skk208521 if (cpi->cpi_vendor == X86_VENDOR_Intel) { 21165269Skk208521 if ((x86_feature & X86_SSSE3) == 0) 21175269Skk208521 *ecx &= ~CPUID_INTC_ECX_SSSE3; 21185269Skk208521 if ((x86_feature & X86_SSE4_1) == 0) 21195269Skk208521 *ecx &= ~CPUID_INTC_ECX_SSE4_1; 21205269Skk208521 if ((x86_feature & X86_SSE4_2) == 0) 21215269Skk208521 *ecx &= ~CPUID_INTC_ECX_SSE4_2; 21225269Skk208521 } 21235269Skk208521 21240Sstevel@tonic-gate /* 21250Sstevel@tonic-gate * [no explicit support required beyond x87 fp context] 21260Sstevel@tonic-gate */ 21270Sstevel@tonic-gate if (!fpu_exists) 21280Sstevel@tonic-gate *edx &= ~(CPUID_INTC_EDX_FPU | CPUID_INTC_EDX_MMX); 21290Sstevel@tonic-gate 21300Sstevel@tonic-gate /* 21310Sstevel@tonic-gate * Now map the supported feature vector to things that we 21320Sstevel@tonic-gate * think userland will care about. 21330Sstevel@tonic-gate */ 21340Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_SEP) 21350Sstevel@tonic-gate hwcap_flags |= AV_386_SEP; 21360Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_SSE) 21370Sstevel@tonic-gate hwcap_flags |= AV_386_FXSR | AV_386_SSE; 21380Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_SSE2) 21390Sstevel@tonic-gate hwcap_flags |= AV_386_SSE2; 21400Sstevel@tonic-gate if (*ecx & CPUID_INTC_ECX_SSE3) 21410Sstevel@tonic-gate hwcap_flags |= AV_386_SSE3; 21425269Skk208521 if (cpi->cpi_vendor == X86_VENDOR_Intel) { 21435269Skk208521 if (*ecx & CPUID_INTC_ECX_SSSE3) 21445269Skk208521 hwcap_flags |= AV_386_SSSE3; 21455269Skk208521 if (*ecx & CPUID_INTC_ECX_SSE4_1) 21465269Skk208521 hwcap_flags |= AV_386_SSE4_1; 21475269Skk208521 if (*ecx & CPUID_INTC_ECX_SSE4_2) 21485269Skk208521 hwcap_flags |= AV_386_SSE4_2; 21495269Skk208521 } 21504628Skk208521 if (*ecx & CPUID_INTC_ECX_POPCNT) 21514628Skk208521 hwcap_flags |= AV_386_POPCNT; 21520Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_FPU) 21530Sstevel@tonic-gate hwcap_flags |= AV_386_FPU; 21540Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_MMX) 21550Sstevel@tonic-gate hwcap_flags |= AV_386_MMX; 21560Sstevel@tonic-gate 21570Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_TSC) 21580Sstevel@tonic-gate hwcap_flags |= AV_386_TSC; 21590Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_CX8) 21600Sstevel@tonic-gate hwcap_flags |= AV_386_CX8; 21610Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_CMOV) 21620Sstevel@tonic-gate hwcap_flags |= AV_386_CMOV; 21630Sstevel@tonic-gate if (*ecx & CPUID_INTC_ECX_MON) 21640Sstevel@tonic-gate hwcap_flags |= AV_386_MON; 21650Sstevel@tonic-gate if (*ecx & CPUID_INTC_ECX_CX16) 21660Sstevel@tonic-gate hwcap_flags |= AV_386_CX16; 21670Sstevel@tonic-gate } 21680Sstevel@tonic-gate 21691228Sandrei if (x86_feature & X86_HTT) 21700Sstevel@tonic-gate hwcap_flags |= AV_386_PAUSE; 21710Sstevel@tonic-gate 21720Sstevel@tonic-gate if (cpi->cpi_xmaxeax < 0x80000001) 21730Sstevel@tonic-gate goto pass4_done; 21740Sstevel@tonic-gate 21750Sstevel@tonic-gate switch (cpi->cpi_vendor) { 21761228Sandrei struct cpuid_regs cp; 21773446Smrj uint32_t *edx, *ecx; 21780Sstevel@tonic-gate 21793446Smrj case X86_VENDOR_Intel: 21803446Smrj /* 21813446Smrj * Seems like Intel duplicated what we necessary 21823446Smrj * here to make the initial crop of 64-bit OS's work. 21833446Smrj * Hopefully, those are the only "extended" bits 21843446Smrj * they'll add. 21853446Smrj */ 21863446Smrj /*FALLTHROUGH*/ 21873446Smrj 21880Sstevel@tonic-gate case X86_VENDOR_AMD: 21890Sstevel@tonic-gate edx = &cpi->cpi_support[AMD_EDX_FEATURES]; 21903446Smrj ecx = &cpi->cpi_support[AMD_ECX_FEATURES]; 21910Sstevel@tonic-gate 21920Sstevel@tonic-gate *edx = CPI_FEATURES_XTD_EDX(cpi); 21933446Smrj *ecx = CPI_FEATURES_XTD_ECX(cpi); 21943446Smrj 21953446Smrj /* 21963446Smrj * [these features require explicit kernel support] 21973446Smrj */ 21983446Smrj switch (cpi->cpi_vendor) { 21993446Smrj case X86_VENDOR_Intel: 22003446Smrj break; 22013446Smrj 22023446Smrj case X86_VENDOR_AMD: 22033446Smrj if ((x86_feature & X86_TSCP) == 0) 22043446Smrj *edx &= ~CPUID_AMD_EDX_TSCP; 22054628Skk208521 if ((x86_feature & X86_SSE4A) == 0) 22064628Skk208521 *ecx &= ~CPUID_AMD_ECX_SSE4A; 22073446Smrj break; 22083446Smrj 22093446Smrj default: 22103446Smrj break; 22113446Smrj } 22120Sstevel@tonic-gate 22130Sstevel@tonic-gate /* 22140Sstevel@tonic-gate * [no explicit support required beyond 22150Sstevel@tonic-gate * x87 fp context and exception handlers] 22160Sstevel@tonic-gate */ 22170Sstevel@tonic-gate if (!fpu_exists) 22180Sstevel@tonic-gate *edx &= ~(CPUID_AMD_EDX_MMXamd | 22190Sstevel@tonic-gate CPUID_AMD_EDX_3DNow | CPUID_AMD_EDX_3DNowx); 22200Sstevel@tonic-gate 22210Sstevel@tonic-gate if ((x86_feature & X86_NX) == 0) 22220Sstevel@tonic-gate *edx &= ~CPUID_AMD_EDX_NX; 22233446Smrj #if !defined(__amd64) 22240Sstevel@tonic-gate *edx &= ~CPUID_AMD_EDX_LM; 22250Sstevel@tonic-gate #endif 22260Sstevel@tonic-gate /* 22270Sstevel@tonic-gate * Now map the supported feature vector to 22280Sstevel@tonic-gate * things that we think userland will care about. 22290Sstevel@tonic-gate */ 22303446Smrj #if defined(__amd64) 22310Sstevel@tonic-gate if (*edx & CPUID_AMD_EDX_SYSC) 22320Sstevel@tonic-gate hwcap_flags |= AV_386_AMD_SYSC; 22333446Smrj #endif 22340Sstevel@tonic-gate if (*edx & CPUID_AMD_EDX_MMXamd) 22350Sstevel@tonic-gate hwcap_flags |= AV_386_AMD_MMX; 22360Sstevel@tonic-gate if (*edx & CPUID_AMD_EDX_3DNow) 22370Sstevel@tonic-gate hwcap_flags |= AV_386_AMD_3DNow; 22380Sstevel@tonic-gate if (*edx & CPUID_AMD_EDX_3DNowx) 22390Sstevel@tonic-gate hwcap_flags |= AV_386_AMD_3DNowx; 22403446Smrj 22413446Smrj switch (cpi->cpi_vendor) { 22423446Smrj case X86_VENDOR_AMD: 22433446Smrj if (*edx & CPUID_AMD_EDX_TSCP) 22443446Smrj hwcap_flags |= AV_386_TSCP; 22453446Smrj if (*ecx & CPUID_AMD_ECX_AHF64) 22463446Smrj hwcap_flags |= AV_386_AHF; 22474628Skk208521 if (*ecx & CPUID_AMD_ECX_SSE4A) 22484628Skk208521 hwcap_flags |= AV_386_AMD_SSE4A; 22494628Skk208521 if (*ecx & CPUID_AMD_ECX_LZCNT) 22504628Skk208521 hwcap_flags |= AV_386_AMD_LZCNT; 22513446Smrj break; 22523446Smrj 22533446Smrj case X86_VENDOR_Intel: 22543446Smrj /* 22553446Smrj * Aarrgh. 22563446Smrj * Intel uses a different bit in the same word. 22573446Smrj */ 22583446Smrj if (*ecx & CPUID_INTC_ECX_AHF64) 22593446Smrj hwcap_flags |= AV_386_AHF; 22603446Smrj break; 22613446Smrj 22623446Smrj default: 22633446Smrj break; 22643446Smrj } 22650Sstevel@tonic-gate break; 22660Sstevel@tonic-gate 22670Sstevel@tonic-gate case X86_VENDOR_TM: 22681228Sandrei cp.cp_eax = 0x80860001; 22691228Sandrei (void) __cpuid_insn(&cp); 22701228Sandrei cpi->cpi_support[TM_EDX_FEATURES] = cp.cp_edx; 22710Sstevel@tonic-gate break; 22720Sstevel@tonic-gate 22730Sstevel@tonic-gate default: 22740Sstevel@tonic-gate break; 22750Sstevel@tonic-gate } 22760Sstevel@tonic-gate 22770Sstevel@tonic-gate pass4_done: 22780Sstevel@tonic-gate cpi->cpi_pass = 4; 22790Sstevel@tonic-gate return (hwcap_flags); 22800Sstevel@tonic-gate } 22810Sstevel@tonic-gate 22820Sstevel@tonic-gate 22830Sstevel@tonic-gate /* 22840Sstevel@tonic-gate * Simulate the cpuid instruction using the data we previously 22850Sstevel@tonic-gate * captured about this CPU. We try our best to return the truth 22860Sstevel@tonic-gate * about the hardware, independently of kernel support. 22870Sstevel@tonic-gate */ 22880Sstevel@tonic-gate uint32_t 22891228Sandrei cpuid_insn(cpu_t *cpu, struct cpuid_regs *cp) 22900Sstevel@tonic-gate { 22910Sstevel@tonic-gate struct cpuid_info *cpi; 22921228Sandrei struct cpuid_regs *xcp; 22930Sstevel@tonic-gate 22940Sstevel@tonic-gate if (cpu == NULL) 22950Sstevel@tonic-gate cpu = CPU; 22960Sstevel@tonic-gate cpi = cpu->cpu_m.mcpu_cpi; 22970Sstevel@tonic-gate 22980Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 3)); 22990Sstevel@tonic-gate 23000Sstevel@tonic-gate /* 23010Sstevel@tonic-gate * CPUID data is cached in two separate places: cpi_std for standard 23020Sstevel@tonic-gate * CPUID functions, and cpi_extd for extended CPUID functions. 23030Sstevel@tonic-gate */ 23041228Sandrei if (cp->cp_eax <= cpi->cpi_maxeax && cp->cp_eax < NMAX_CPI_STD) 23051228Sandrei xcp = &cpi->cpi_std[cp->cp_eax]; 23061228Sandrei else if (cp->cp_eax >= 0x80000000 && cp->cp_eax <= cpi->cpi_xmaxeax && 23071228Sandrei cp->cp_eax < 0x80000000 + NMAX_CPI_EXTD) 23081228Sandrei xcp = &cpi->cpi_extd[cp->cp_eax - 0x80000000]; 23090Sstevel@tonic-gate else 23100Sstevel@tonic-gate /* 23110Sstevel@tonic-gate * The caller is asking for data from an input parameter which 23120Sstevel@tonic-gate * the kernel has not cached. In this case we go fetch from 23130Sstevel@tonic-gate * the hardware and return the data directly to the user. 23140Sstevel@tonic-gate */ 23151228Sandrei return (__cpuid_insn(cp)); 23161228Sandrei 23171228Sandrei cp->cp_eax = xcp->cp_eax; 23181228Sandrei cp->cp_ebx = xcp->cp_ebx; 23191228Sandrei cp->cp_ecx = xcp->cp_ecx; 23201228Sandrei cp->cp_edx = xcp->cp_edx; 23210Sstevel@tonic-gate return (cp->cp_eax); 23220Sstevel@tonic-gate } 23230Sstevel@tonic-gate 23240Sstevel@tonic-gate int 23250Sstevel@tonic-gate cpuid_checkpass(cpu_t *cpu, int pass) 23260Sstevel@tonic-gate { 23270Sstevel@tonic-gate return (cpu != NULL && cpu->cpu_m.mcpu_cpi != NULL && 23280Sstevel@tonic-gate cpu->cpu_m.mcpu_cpi->cpi_pass >= pass); 23290Sstevel@tonic-gate } 23300Sstevel@tonic-gate 23310Sstevel@tonic-gate int 23320Sstevel@tonic-gate cpuid_getbrandstr(cpu_t *cpu, char *s, size_t n) 23330Sstevel@tonic-gate { 23340Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 3)); 23350Sstevel@tonic-gate 23360Sstevel@tonic-gate return (snprintf(s, n, "%s", cpu->cpu_m.mcpu_cpi->cpi_brandstr)); 23370Sstevel@tonic-gate } 23380Sstevel@tonic-gate 23390Sstevel@tonic-gate int 23401228Sandrei cpuid_is_cmt(cpu_t *cpu) 23410Sstevel@tonic-gate { 23420Sstevel@tonic-gate if (cpu == NULL) 23430Sstevel@tonic-gate cpu = CPU; 23440Sstevel@tonic-gate 23450Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 23460Sstevel@tonic-gate 23470Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_chipid >= 0); 23480Sstevel@tonic-gate } 23490Sstevel@tonic-gate 23500Sstevel@tonic-gate /* 23510Sstevel@tonic-gate * AMD and Intel both implement the 64-bit variant of the syscall 23520Sstevel@tonic-gate * instruction (syscallq), so if there's -any- support for syscall, 23530Sstevel@tonic-gate * cpuid currently says "yes, we support this". 23540Sstevel@tonic-gate * 23550Sstevel@tonic-gate * However, Intel decided to -not- implement the 32-bit variant of the 23560Sstevel@tonic-gate * syscall instruction, so we provide a predicate to allow our caller 23570Sstevel@tonic-gate * to test that subtlety here. 23585084Sjohnlev * 23595084Sjohnlev * XXPV Currently, 32-bit syscall instructions don't work via the hypervisor, 23605084Sjohnlev * even in the case where the hardware would in fact support it. 23610Sstevel@tonic-gate */ 23620Sstevel@tonic-gate /*ARGSUSED*/ 23630Sstevel@tonic-gate int 23640Sstevel@tonic-gate cpuid_syscall32_insn(cpu_t *cpu) 23650Sstevel@tonic-gate { 23660Sstevel@tonic-gate ASSERT(cpuid_checkpass((cpu == NULL ? CPU : cpu), 1)); 23670Sstevel@tonic-gate 23685084Sjohnlev #if !defined(__xpv) 23693446Smrj if (cpu == NULL) 23703446Smrj cpu = CPU; 23713446Smrj 23723446Smrj /*CSTYLED*/ 23733446Smrj { 23743446Smrj struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 23753446Smrj 23763446Smrj if (cpi->cpi_vendor == X86_VENDOR_AMD && 23773446Smrj cpi->cpi_xmaxeax >= 0x80000001 && 23783446Smrj (CPI_FEATURES_XTD_EDX(cpi) & CPUID_AMD_EDX_SYSC)) 23793446Smrj return (1); 23803446Smrj } 23815084Sjohnlev #endif 23820Sstevel@tonic-gate return (0); 23830Sstevel@tonic-gate } 23840Sstevel@tonic-gate 23850Sstevel@tonic-gate int 23860Sstevel@tonic-gate cpuid_getidstr(cpu_t *cpu, char *s, size_t n) 23870Sstevel@tonic-gate { 23880Sstevel@tonic-gate struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 23890Sstevel@tonic-gate 23900Sstevel@tonic-gate static const char fmt[] = 23913779Sdmick "x86 (%s %X family %d model %d step %d clock %d MHz)"; 23920Sstevel@tonic-gate static const char fmt_ht[] = 23933779Sdmick "x86 (chipid 0x%x %s %X family %d model %d step %d clock %d MHz)"; 23940Sstevel@tonic-gate 23950Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 23960Sstevel@tonic-gate 23971228Sandrei if (cpuid_is_cmt(cpu)) 23980Sstevel@tonic-gate return (snprintf(s, n, fmt_ht, cpi->cpi_chipid, 23993779Sdmick cpi->cpi_vendorstr, cpi->cpi_std[1].cp_eax, 24003779Sdmick cpi->cpi_family, cpi->cpi_model, 24010Sstevel@tonic-gate cpi->cpi_step, cpu->cpu_type_info.pi_clock)); 24020Sstevel@tonic-gate return (snprintf(s, n, fmt, 24033779Sdmick cpi->cpi_vendorstr, cpi->cpi_std[1].cp_eax, 24043779Sdmick cpi->cpi_family, cpi->cpi_model, 24050Sstevel@tonic-gate cpi->cpi_step, cpu->cpu_type_info.pi_clock)); 24060Sstevel@tonic-gate } 24070Sstevel@tonic-gate 24080Sstevel@tonic-gate const char * 24090Sstevel@tonic-gate cpuid_getvendorstr(cpu_t *cpu) 24100Sstevel@tonic-gate { 24110Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 24120Sstevel@tonic-gate return ((const char *)cpu->cpu_m.mcpu_cpi->cpi_vendorstr); 24130Sstevel@tonic-gate } 24140Sstevel@tonic-gate 24150Sstevel@tonic-gate uint_t 24160Sstevel@tonic-gate cpuid_getvendor(cpu_t *cpu) 24170Sstevel@tonic-gate { 24180Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 24190Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_vendor); 24200Sstevel@tonic-gate } 24210Sstevel@tonic-gate 24220Sstevel@tonic-gate uint_t 24230Sstevel@tonic-gate cpuid_getfamily(cpu_t *cpu) 24240Sstevel@tonic-gate { 24250Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 24260Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_family); 24270Sstevel@tonic-gate } 24280Sstevel@tonic-gate 24290Sstevel@tonic-gate uint_t 24300Sstevel@tonic-gate cpuid_getmodel(cpu_t *cpu) 24310Sstevel@tonic-gate { 24320Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 24330Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_model); 24340Sstevel@tonic-gate } 24350Sstevel@tonic-gate 24360Sstevel@tonic-gate uint_t 24370Sstevel@tonic-gate cpuid_get_ncpu_per_chip(cpu_t *cpu) 24380Sstevel@tonic-gate { 24390Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 24400Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_ncpu_per_chip); 24410Sstevel@tonic-gate } 24420Sstevel@tonic-gate 24430Sstevel@tonic-gate uint_t 24441228Sandrei cpuid_get_ncore_per_chip(cpu_t *cpu) 24451228Sandrei { 24461228Sandrei ASSERT(cpuid_checkpass(cpu, 1)); 24471228Sandrei return (cpu->cpu_m.mcpu_cpi->cpi_ncore_per_chip); 24481228Sandrei } 24491228Sandrei 24501228Sandrei uint_t 24514606Sesaxe cpuid_get_ncpu_sharing_last_cache(cpu_t *cpu) 24524606Sesaxe { 24534606Sesaxe ASSERT(cpuid_checkpass(cpu, 2)); 24544606Sesaxe return (cpu->cpu_m.mcpu_cpi->cpi_ncpu_shr_last_cache); 24554606Sesaxe } 24564606Sesaxe 24574606Sesaxe id_t 24584606Sesaxe cpuid_get_last_lvl_cacheid(cpu_t *cpu) 24594606Sesaxe { 24604606Sesaxe ASSERT(cpuid_checkpass(cpu, 2)); 24614606Sesaxe return (cpu->cpu_m.mcpu_cpi->cpi_last_lvl_cacheid); 24624606Sesaxe } 24634606Sesaxe 24644606Sesaxe uint_t 24650Sstevel@tonic-gate cpuid_getstep(cpu_t *cpu) 24660Sstevel@tonic-gate { 24670Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 24680Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_step); 24690Sstevel@tonic-gate } 24700Sstevel@tonic-gate 24714581Ssherrym uint_t 24724581Ssherrym cpuid_getsig(struct cpu *cpu) 24734581Ssherrym { 24744581Ssherrym ASSERT(cpuid_checkpass(cpu, 1)); 24754581Ssherrym return (cpu->cpu_m.mcpu_cpi->cpi_std[1].cp_eax); 24764581Ssherrym } 24774581Ssherrym 24782869Sgavinm uint32_t 24792869Sgavinm cpuid_getchiprev(struct cpu *cpu) 24802869Sgavinm { 24812869Sgavinm ASSERT(cpuid_checkpass(cpu, 1)); 24822869Sgavinm return (cpu->cpu_m.mcpu_cpi->cpi_chiprev); 24832869Sgavinm } 24842869Sgavinm 24852869Sgavinm const char * 24862869Sgavinm cpuid_getchiprevstr(struct cpu *cpu) 24872869Sgavinm { 24882869Sgavinm ASSERT(cpuid_checkpass(cpu, 1)); 24892869Sgavinm return (cpu->cpu_m.mcpu_cpi->cpi_chiprevstr); 24902869Sgavinm } 24912869Sgavinm 24922869Sgavinm uint32_t 24932869Sgavinm cpuid_getsockettype(struct cpu *cpu) 24942869Sgavinm { 24952869Sgavinm ASSERT(cpuid_checkpass(cpu, 1)); 24962869Sgavinm return (cpu->cpu_m.mcpu_cpi->cpi_socket); 24972869Sgavinm } 24982869Sgavinm 24993434Sesaxe int 25003434Sesaxe cpuid_get_chipid(cpu_t *cpu) 25010Sstevel@tonic-gate { 25020Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 25030Sstevel@tonic-gate 25041228Sandrei if (cpuid_is_cmt(cpu)) 25050Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_chipid); 25060Sstevel@tonic-gate return (cpu->cpu_id); 25070Sstevel@tonic-gate } 25080Sstevel@tonic-gate 25091228Sandrei id_t 25103434Sesaxe cpuid_get_coreid(cpu_t *cpu) 25111228Sandrei { 25121228Sandrei ASSERT(cpuid_checkpass(cpu, 1)); 25131228Sandrei return (cpu->cpu_m.mcpu_cpi->cpi_coreid); 25141228Sandrei } 25151228Sandrei 25160Sstevel@tonic-gate int 25175870Sgavinm cpuid_get_pkgcoreid(cpu_t *cpu) 25185870Sgavinm { 25195870Sgavinm ASSERT(cpuid_checkpass(cpu, 1)); 25205870Sgavinm return (cpu->cpu_m.mcpu_cpi->cpi_pkgcoreid); 25215870Sgavinm } 25225870Sgavinm 25235870Sgavinm int 25243434Sesaxe cpuid_get_clogid(cpu_t *cpu) 25250Sstevel@tonic-gate { 25260Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 25270Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_clogid); 25280Sstevel@tonic-gate } 25290Sstevel@tonic-gate 25300Sstevel@tonic-gate void 25310Sstevel@tonic-gate cpuid_get_addrsize(cpu_t *cpu, uint_t *pabits, uint_t *vabits) 25320Sstevel@tonic-gate { 25330Sstevel@tonic-gate struct cpuid_info *cpi; 25340Sstevel@tonic-gate 25350Sstevel@tonic-gate if (cpu == NULL) 25360Sstevel@tonic-gate cpu = CPU; 25370Sstevel@tonic-gate cpi = cpu->cpu_m.mcpu_cpi; 25380Sstevel@tonic-gate 25390Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 25400Sstevel@tonic-gate 25410Sstevel@tonic-gate if (pabits) 25420Sstevel@tonic-gate *pabits = cpi->cpi_pabits; 25430Sstevel@tonic-gate if (vabits) 25440Sstevel@tonic-gate *vabits = cpi->cpi_vabits; 25450Sstevel@tonic-gate } 25460Sstevel@tonic-gate 25470Sstevel@tonic-gate /* 25480Sstevel@tonic-gate * Returns the number of data TLB entries for a corresponding 25490Sstevel@tonic-gate * pagesize. If it can't be computed, or isn't known, the 25500Sstevel@tonic-gate * routine returns zero. If you ask about an architecturally 25510Sstevel@tonic-gate * impossible pagesize, the routine will panic (so that the 25520Sstevel@tonic-gate * hat implementor knows that things are inconsistent.) 25530Sstevel@tonic-gate */ 25540Sstevel@tonic-gate uint_t 25550Sstevel@tonic-gate cpuid_get_dtlb_nent(cpu_t *cpu, size_t pagesize) 25560Sstevel@tonic-gate { 25570Sstevel@tonic-gate struct cpuid_info *cpi; 25580Sstevel@tonic-gate uint_t dtlb_nent = 0; 25590Sstevel@tonic-gate 25600Sstevel@tonic-gate if (cpu == NULL) 25610Sstevel@tonic-gate cpu = CPU; 25620Sstevel@tonic-gate cpi = cpu->cpu_m.mcpu_cpi; 25630Sstevel@tonic-gate 25640Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 25650Sstevel@tonic-gate 25660Sstevel@tonic-gate /* 25670Sstevel@tonic-gate * Check the L2 TLB info 25680Sstevel@tonic-gate */ 25690Sstevel@tonic-gate if (cpi->cpi_xmaxeax >= 0x80000006) { 25701228Sandrei struct cpuid_regs *cp = &cpi->cpi_extd[6]; 25710Sstevel@tonic-gate 25720Sstevel@tonic-gate switch (pagesize) { 25730Sstevel@tonic-gate 25740Sstevel@tonic-gate case 4 * 1024: 25750Sstevel@tonic-gate /* 25760Sstevel@tonic-gate * All zero in the top 16 bits of the register 25770Sstevel@tonic-gate * indicates a unified TLB. Size is in low 16 bits. 25780Sstevel@tonic-gate */ 25790Sstevel@tonic-gate if ((cp->cp_ebx & 0xffff0000) == 0) 25800Sstevel@tonic-gate dtlb_nent = cp->cp_ebx & 0x0000ffff; 25810Sstevel@tonic-gate else 25820Sstevel@tonic-gate dtlb_nent = BITX(cp->cp_ebx, 27, 16); 25830Sstevel@tonic-gate break; 25840Sstevel@tonic-gate 25850Sstevel@tonic-gate case 2 * 1024 * 1024: 25860Sstevel@tonic-gate if ((cp->cp_eax & 0xffff0000) == 0) 25870Sstevel@tonic-gate dtlb_nent = cp->cp_eax & 0x0000ffff; 25880Sstevel@tonic-gate else 25890Sstevel@tonic-gate dtlb_nent = BITX(cp->cp_eax, 27, 16); 25900Sstevel@tonic-gate break; 25910Sstevel@tonic-gate 25920Sstevel@tonic-gate default: 25930Sstevel@tonic-gate panic("unknown L2 pagesize"); 25940Sstevel@tonic-gate /*NOTREACHED*/ 25950Sstevel@tonic-gate } 25960Sstevel@tonic-gate } 25970Sstevel@tonic-gate 25980Sstevel@tonic-gate if (dtlb_nent != 0) 25990Sstevel@tonic-gate return (dtlb_nent); 26000Sstevel@tonic-gate 26010Sstevel@tonic-gate /* 26020Sstevel@tonic-gate * No L2 TLB support for this size, try L1. 26030Sstevel@tonic-gate */ 26040Sstevel@tonic-gate if (cpi->cpi_xmaxeax >= 0x80000005) { 26051228Sandrei struct cpuid_regs *cp = &cpi->cpi_extd[5]; 26060Sstevel@tonic-gate 26070Sstevel@tonic-gate switch (pagesize) { 26080Sstevel@tonic-gate case 4 * 1024: 26090Sstevel@tonic-gate dtlb_nent = BITX(cp->cp_ebx, 23, 16); 26100Sstevel@tonic-gate break; 26110Sstevel@tonic-gate case 2 * 1024 * 1024: 26120Sstevel@tonic-gate dtlb_nent = BITX(cp->cp_eax, 23, 16); 26130Sstevel@tonic-gate break; 26140Sstevel@tonic-gate default: 26150Sstevel@tonic-gate panic("unknown L1 d-TLB pagesize"); 26160Sstevel@tonic-gate /*NOTREACHED*/ 26170Sstevel@tonic-gate } 26180Sstevel@tonic-gate } 26190Sstevel@tonic-gate 26200Sstevel@tonic-gate return (dtlb_nent); 26210Sstevel@tonic-gate } 26220Sstevel@tonic-gate 26230Sstevel@tonic-gate /* 26240Sstevel@tonic-gate * Return 0 if the erratum is not present or not applicable, positive 26250Sstevel@tonic-gate * if it is, and negative if the status of the erratum is unknown. 26260Sstevel@tonic-gate * 26270Sstevel@tonic-gate * See "Revision Guide for AMD Athlon(tm) 64 and AMD Opteron(tm) 2628359Skucharsk * Processors" #25759, Rev 3.57, August 2005 26290Sstevel@tonic-gate */ 26300Sstevel@tonic-gate int 26310Sstevel@tonic-gate cpuid_opteron_erratum(cpu_t *cpu, uint_t erratum) 26320Sstevel@tonic-gate { 26330Sstevel@tonic-gate struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 26341228Sandrei uint_t eax; 26350Sstevel@tonic-gate 26362584Ssethg /* 26372584Ssethg * Bail out if this CPU isn't an AMD CPU, or if it's 26382584Ssethg * a legacy (32-bit) AMD CPU. 26392584Ssethg */ 26402584Ssethg if (cpi->cpi_vendor != X86_VENDOR_AMD || 26414265Skchow cpi->cpi_family == 4 || cpi->cpi_family == 5 || 26424265Skchow cpi->cpi_family == 6) 26432869Sgavinm 26440Sstevel@tonic-gate return (0); 26450Sstevel@tonic-gate 26460Sstevel@tonic-gate eax = cpi->cpi_std[1].cp_eax; 26470Sstevel@tonic-gate 26480Sstevel@tonic-gate #define SH_B0(eax) (eax == 0xf40 || eax == 0xf50) 26490Sstevel@tonic-gate #define SH_B3(eax) (eax == 0xf51) 26501582Skchow #define B(eax) (SH_B0(eax) || SH_B3(eax)) 26510Sstevel@tonic-gate 26520Sstevel@tonic-gate #define SH_C0(eax) (eax == 0xf48 || eax == 0xf58) 26530Sstevel@tonic-gate 26540Sstevel@tonic-gate #define SH_CG(eax) (eax == 0xf4a || eax == 0xf5a || eax == 0xf7a) 26550Sstevel@tonic-gate #define DH_CG(eax) (eax == 0xfc0 || eax == 0xfe0 || eax == 0xff0) 26560Sstevel@tonic-gate #define CH_CG(eax) (eax == 0xf82 || eax == 0xfb2) 26571582Skchow #define CG(eax) (SH_CG(eax) || DH_CG(eax) || CH_CG(eax)) 26580Sstevel@tonic-gate 26590Sstevel@tonic-gate #define SH_D0(eax) (eax == 0x10f40 || eax == 0x10f50 || eax == 0x10f70) 26600Sstevel@tonic-gate #define DH_D0(eax) (eax == 0x10fc0 || eax == 0x10ff0) 26610Sstevel@tonic-gate #define CH_D0(eax) (eax == 0x10f80 || eax == 0x10fb0) 26621582Skchow #define D0(eax) (SH_D0(eax) || DH_D0(eax) || CH_D0(eax)) 26630Sstevel@tonic-gate 26640Sstevel@tonic-gate #define SH_E0(eax) (eax == 0x20f50 || eax == 0x20f40 || eax == 0x20f70) 26650Sstevel@tonic-gate #define JH_E1(eax) (eax == 0x20f10) /* JH8_E0 had 0x20f30 */ 26660Sstevel@tonic-gate #define DH_E3(eax) (eax == 0x20fc0 || eax == 0x20ff0) 26670Sstevel@tonic-gate #define SH_E4(eax) (eax == 0x20f51 || eax == 0x20f71) 26680Sstevel@tonic-gate #define BH_E4(eax) (eax == 0x20fb1) 26690Sstevel@tonic-gate #define SH_E5(eax) (eax == 0x20f42) 26700Sstevel@tonic-gate #define DH_E6(eax) (eax == 0x20ff2 || eax == 0x20fc2) 26710Sstevel@tonic-gate #define JH_E6(eax) (eax == 0x20f12 || eax == 0x20f32) 26721582Skchow #define EX(eax) (SH_E0(eax) || JH_E1(eax) || DH_E3(eax) || \ 26731582Skchow SH_E4(eax) || BH_E4(eax) || SH_E5(eax) || \ 26741582Skchow DH_E6(eax) || JH_E6(eax)) 26750Sstevel@tonic-gate 26760Sstevel@tonic-gate switch (erratum) { 26770Sstevel@tonic-gate case 1: 26784265Skchow return (cpi->cpi_family < 0x10); 26790Sstevel@tonic-gate case 51: /* what does the asterisk mean? */ 26800Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax)); 26810Sstevel@tonic-gate case 52: 26820Sstevel@tonic-gate return (B(eax)); 26830Sstevel@tonic-gate case 57: 26844265Skchow return (cpi->cpi_family <= 0x10); 26850Sstevel@tonic-gate case 58: 26860Sstevel@tonic-gate return (B(eax)); 26870Sstevel@tonic-gate case 60: 26884265Skchow return (cpi->cpi_family <= 0x10); 26890Sstevel@tonic-gate case 61: 26900Sstevel@tonic-gate case 62: 26910Sstevel@tonic-gate case 63: 26920Sstevel@tonic-gate case 64: 26930Sstevel@tonic-gate case 65: 26940Sstevel@tonic-gate case 66: 26950Sstevel@tonic-gate case 68: 26960Sstevel@tonic-gate case 69: 26970Sstevel@tonic-gate case 70: 26980Sstevel@tonic-gate case 71: 26990Sstevel@tonic-gate return (B(eax)); 27000Sstevel@tonic-gate case 72: 27010Sstevel@tonic-gate return (SH_B0(eax)); 27020Sstevel@tonic-gate case 74: 27030Sstevel@tonic-gate return (B(eax)); 27040Sstevel@tonic-gate case 75: 27054265Skchow return (cpi->cpi_family < 0x10); 27060Sstevel@tonic-gate case 76: 27070Sstevel@tonic-gate return (B(eax)); 27080Sstevel@tonic-gate case 77: 27094265Skchow return (cpi->cpi_family <= 0x10); 27100Sstevel@tonic-gate case 78: 27110Sstevel@tonic-gate return (B(eax) || SH_C0(eax)); 27120Sstevel@tonic-gate case 79: 27130Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax) || EX(eax)); 27140Sstevel@tonic-gate case 80: 27150Sstevel@tonic-gate case 81: 27160Sstevel@tonic-gate case 82: 27170Sstevel@tonic-gate return (B(eax)); 27180Sstevel@tonic-gate case 83: 27190Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax)); 27200Sstevel@tonic-gate case 85: 27214265Skchow return (cpi->cpi_family < 0x10); 27220Sstevel@tonic-gate case 86: 27230Sstevel@tonic-gate return (SH_C0(eax) || CG(eax)); 27240Sstevel@tonic-gate case 88: 27250Sstevel@tonic-gate #if !defined(__amd64) 27260Sstevel@tonic-gate return (0); 27270Sstevel@tonic-gate #else 27280Sstevel@tonic-gate return (B(eax) || SH_C0(eax)); 27290Sstevel@tonic-gate #endif 27300Sstevel@tonic-gate case 89: 27314265Skchow return (cpi->cpi_family < 0x10); 27320Sstevel@tonic-gate case 90: 27330Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax)); 27340Sstevel@tonic-gate case 91: 27350Sstevel@tonic-gate case 92: 27360Sstevel@tonic-gate return (B(eax) || SH_C0(eax)); 27370Sstevel@tonic-gate case 93: 27380Sstevel@tonic-gate return (SH_C0(eax)); 27390Sstevel@tonic-gate case 94: 27400Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax)); 27410Sstevel@tonic-gate case 95: 27420Sstevel@tonic-gate #if !defined(__amd64) 27430Sstevel@tonic-gate return (0); 27440Sstevel@tonic-gate #else 27450Sstevel@tonic-gate return (B(eax) || SH_C0(eax)); 27460Sstevel@tonic-gate #endif 27470Sstevel@tonic-gate case 96: 27480Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax)); 27490Sstevel@tonic-gate case 97: 27500Sstevel@tonic-gate case 98: 27510Sstevel@tonic-gate return (SH_C0(eax) || CG(eax)); 27520Sstevel@tonic-gate case 99: 27530Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax)); 27540Sstevel@tonic-gate case 100: 27550Sstevel@tonic-gate return (B(eax) || SH_C0(eax)); 27560Sstevel@tonic-gate case 101: 27570Sstevel@tonic-gate case 103: 27580Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax)); 27590Sstevel@tonic-gate case 104: 27600Sstevel@tonic-gate return (SH_C0(eax) || CG(eax) || D0(eax)); 27610Sstevel@tonic-gate case 105: 27620Sstevel@tonic-gate case 106: 27630Sstevel@tonic-gate case 107: 27640Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax)); 27650Sstevel@tonic-gate case 108: 27660Sstevel@tonic-gate return (DH_CG(eax)); 27670Sstevel@tonic-gate case 109: 27680Sstevel@tonic-gate return (SH_C0(eax) || CG(eax) || D0(eax)); 27690Sstevel@tonic-gate case 110: 27700Sstevel@tonic-gate return (D0(eax) || EX(eax)); 27710Sstevel@tonic-gate case 111: 27720Sstevel@tonic-gate return (CG(eax)); 27730Sstevel@tonic-gate case 112: 27740Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax) || EX(eax)); 27750Sstevel@tonic-gate case 113: 27760Sstevel@tonic-gate return (eax == 0x20fc0); 27770Sstevel@tonic-gate case 114: 27780Sstevel@tonic-gate return (SH_E0(eax) || JH_E1(eax) || DH_E3(eax)); 27790Sstevel@tonic-gate case 115: 27800Sstevel@tonic-gate return (SH_E0(eax) || JH_E1(eax)); 27810Sstevel@tonic-gate case 116: 27820Sstevel@tonic-gate return (SH_E0(eax) || JH_E1(eax) || DH_E3(eax)); 27830Sstevel@tonic-gate case 117: 27840Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax)); 27850Sstevel@tonic-gate case 118: 27860Sstevel@tonic-gate return (SH_E0(eax) || JH_E1(eax) || SH_E4(eax) || BH_E4(eax) || 27870Sstevel@tonic-gate JH_E6(eax)); 27880Sstevel@tonic-gate case 121: 27890Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax) || EX(eax)); 27900Sstevel@tonic-gate case 122: 27914265Skchow return (cpi->cpi_family < 0x10); 27920Sstevel@tonic-gate case 123: 27930Sstevel@tonic-gate return (JH_E1(eax) || BH_E4(eax) || JH_E6(eax)); 2794359Skucharsk case 131: 27954265Skchow return (cpi->cpi_family < 0x10); 2796938Sesaxe case 6336786: 2797938Sesaxe /* 2798938Sesaxe * Test for AdvPowerMgmtInfo.TscPStateInvariant 27994265Skchow * if this is a K8 family or newer processor 2800938Sesaxe */ 2801938Sesaxe if (CPI_FAMILY(cpi) == 0xf) { 28021228Sandrei struct cpuid_regs regs; 28031228Sandrei regs.cp_eax = 0x80000007; 28041228Sandrei (void) __cpuid_insn(®s); 28051228Sandrei return (!(regs.cp_edx & 0x100)); 2806938Sesaxe } 2807938Sesaxe return (0); 28081582Skchow case 6323525: 28091582Skchow return (((((eax >> 12) & 0xff00) + (eax & 0xf00)) | 28101582Skchow (((eax >> 4) & 0xf) | ((eax >> 12) & 0xf0))) < 0xf40); 28111582Skchow 28120Sstevel@tonic-gate default: 28130Sstevel@tonic-gate return (-1); 28140Sstevel@tonic-gate } 28150Sstevel@tonic-gate } 28160Sstevel@tonic-gate 28170Sstevel@tonic-gate static const char assoc_str[] = "associativity"; 28180Sstevel@tonic-gate static const char line_str[] = "line-size"; 28190Sstevel@tonic-gate static const char size_str[] = "size"; 28200Sstevel@tonic-gate 28210Sstevel@tonic-gate static void 28220Sstevel@tonic-gate add_cache_prop(dev_info_t *devi, const char *label, const char *type, 28230Sstevel@tonic-gate uint32_t val) 28240Sstevel@tonic-gate { 28250Sstevel@tonic-gate char buf[128]; 28260Sstevel@tonic-gate 28270Sstevel@tonic-gate /* 28280Sstevel@tonic-gate * ndi_prop_update_int() is used because it is desirable for 28290Sstevel@tonic-gate * DDI_PROP_HW_DEF and DDI_PROP_DONTSLEEP to be set. 28300Sstevel@tonic-gate */ 28310Sstevel@tonic-gate if (snprintf(buf, sizeof (buf), "%s-%s", label, type) < sizeof (buf)) 28320Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, devi, buf, val); 28330Sstevel@tonic-gate } 28340Sstevel@tonic-gate 28350Sstevel@tonic-gate /* 28360Sstevel@tonic-gate * Intel-style cache/tlb description 28370Sstevel@tonic-gate * 28380Sstevel@tonic-gate * Standard cpuid level 2 gives a randomly ordered 28390Sstevel@tonic-gate * selection of tags that index into a table that describes 28400Sstevel@tonic-gate * cache and tlb properties. 28410Sstevel@tonic-gate */ 28420Sstevel@tonic-gate 28430Sstevel@tonic-gate static const char l1_icache_str[] = "l1-icache"; 28440Sstevel@tonic-gate static const char l1_dcache_str[] = "l1-dcache"; 28450Sstevel@tonic-gate static const char l2_cache_str[] = "l2-cache"; 28463446Smrj static const char l3_cache_str[] = "l3-cache"; 28470Sstevel@tonic-gate static const char itlb4k_str[] = "itlb-4K"; 28480Sstevel@tonic-gate static const char dtlb4k_str[] = "dtlb-4K"; 28490Sstevel@tonic-gate static const char itlb4M_str[] = "itlb-4M"; 28500Sstevel@tonic-gate static const char dtlb4M_str[] = "dtlb-4M"; 28510Sstevel@tonic-gate static const char itlb424_str[] = "itlb-4K-2M-4M"; 28520Sstevel@tonic-gate static const char dtlb44_str[] = "dtlb-4K-4M"; 28530Sstevel@tonic-gate static const char sl1_dcache_str[] = "sectored-l1-dcache"; 28540Sstevel@tonic-gate static const char sl2_cache_str[] = "sectored-l2-cache"; 28550Sstevel@tonic-gate static const char itrace_str[] = "itrace-cache"; 28560Sstevel@tonic-gate static const char sl3_cache_str[] = "sectored-l3-cache"; 28570Sstevel@tonic-gate 28580Sstevel@tonic-gate static const struct cachetab { 28590Sstevel@tonic-gate uint8_t ct_code; 28600Sstevel@tonic-gate uint8_t ct_assoc; 28610Sstevel@tonic-gate uint16_t ct_line_size; 28620Sstevel@tonic-gate size_t ct_size; 28630Sstevel@tonic-gate const char *ct_label; 28640Sstevel@tonic-gate } intel_ctab[] = { 28650Sstevel@tonic-gate /* maintain descending order! */ 28663446Smrj { 0xb4, 4, 0, 256, dtlb4k_str }, 28670Sstevel@tonic-gate { 0xb3, 4, 0, 128, dtlb4k_str }, 28680Sstevel@tonic-gate { 0xb0, 4, 0, 128, itlb4k_str }, 28690Sstevel@tonic-gate { 0x87, 8, 64, 1024*1024, l2_cache_str}, 28700Sstevel@tonic-gate { 0x86, 4, 64, 512*1024, l2_cache_str}, 28710Sstevel@tonic-gate { 0x85, 8, 32, 2*1024*1024, l2_cache_str}, 28720Sstevel@tonic-gate { 0x84, 8, 32, 1024*1024, l2_cache_str}, 28730Sstevel@tonic-gate { 0x83, 8, 32, 512*1024, l2_cache_str}, 28740Sstevel@tonic-gate { 0x82, 8, 32, 256*1024, l2_cache_str}, 28750Sstevel@tonic-gate { 0x7f, 2, 64, 512*1024, l2_cache_str}, 28760Sstevel@tonic-gate { 0x7d, 8, 64, 2*1024*1024, sl2_cache_str}, 28770Sstevel@tonic-gate { 0x7c, 8, 64, 1024*1024, sl2_cache_str}, 28780Sstevel@tonic-gate { 0x7b, 8, 64, 512*1024, sl2_cache_str}, 28790Sstevel@tonic-gate { 0x7a, 8, 64, 256*1024, sl2_cache_str}, 28800Sstevel@tonic-gate { 0x79, 8, 64, 128*1024, sl2_cache_str}, 28810Sstevel@tonic-gate { 0x78, 8, 64, 1024*1024, l2_cache_str}, 28823446Smrj { 0x73, 8, 0, 64*1024, itrace_str}, 28830Sstevel@tonic-gate { 0x72, 8, 0, 32*1024, itrace_str}, 28840Sstevel@tonic-gate { 0x71, 8, 0, 16*1024, itrace_str}, 28850Sstevel@tonic-gate { 0x70, 8, 0, 12*1024, itrace_str}, 28860Sstevel@tonic-gate { 0x68, 4, 64, 32*1024, sl1_dcache_str}, 28870Sstevel@tonic-gate { 0x67, 4, 64, 16*1024, sl1_dcache_str}, 28880Sstevel@tonic-gate { 0x66, 4, 64, 8*1024, sl1_dcache_str}, 28890Sstevel@tonic-gate { 0x60, 8, 64, 16*1024, sl1_dcache_str}, 28900Sstevel@tonic-gate { 0x5d, 0, 0, 256, dtlb44_str}, 28910Sstevel@tonic-gate { 0x5c, 0, 0, 128, dtlb44_str}, 28920Sstevel@tonic-gate { 0x5b, 0, 0, 64, dtlb44_str}, 28930Sstevel@tonic-gate { 0x52, 0, 0, 256, itlb424_str}, 28940Sstevel@tonic-gate { 0x51, 0, 0, 128, itlb424_str}, 28950Sstevel@tonic-gate { 0x50, 0, 0, 64, itlb424_str}, 28963446Smrj { 0x4d, 16, 64, 16*1024*1024, l3_cache_str}, 28973446Smrj { 0x4c, 12, 64, 12*1024*1024, l3_cache_str}, 28983446Smrj { 0x4b, 16, 64, 8*1024*1024, l3_cache_str}, 28993446Smrj { 0x4a, 12, 64, 6*1024*1024, l3_cache_str}, 29003446Smrj { 0x49, 16, 64, 4*1024*1024, l3_cache_str}, 29013446Smrj { 0x47, 8, 64, 8*1024*1024, l3_cache_str}, 29023446Smrj { 0x46, 4, 64, 4*1024*1024, l3_cache_str}, 29030Sstevel@tonic-gate { 0x45, 4, 32, 2*1024*1024, l2_cache_str}, 29040Sstevel@tonic-gate { 0x44, 4, 32, 1024*1024, l2_cache_str}, 29050Sstevel@tonic-gate { 0x43, 4, 32, 512*1024, l2_cache_str}, 29060Sstevel@tonic-gate { 0x42, 4, 32, 256*1024, l2_cache_str}, 29070Sstevel@tonic-gate { 0x41, 4, 32, 128*1024, l2_cache_str}, 29083446Smrj { 0x3e, 4, 64, 512*1024, sl2_cache_str}, 29093446Smrj { 0x3d, 6, 64, 384*1024, sl2_cache_str}, 29100Sstevel@tonic-gate { 0x3c, 4, 64, 256*1024, sl2_cache_str}, 29110Sstevel@tonic-gate { 0x3b, 2, 64, 128*1024, sl2_cache_str}, 29123446Smrj { 0x3a, 6, 64, 192*1024, sl2_cache_str}, 29130Sstevel@tonic-gate { 0x39, 4, 64, 128*1024, sl2_cache_str}, 29140Sstevel@tonic-gate { 0x30, 8, 64, 32*1024, l1_icache_str}, 29150Sstevel@tonic-gate { 0x2c, 8, 64, 32*1024, l1_dcache_str}, 29160Sstevel@tonic-gate { 0x29, 8, 64, 4096*1024, sl3_cache_str}, 29170Sstevel@tonic-gate { 0x25, 8, 64, 2048*1024, sl3_cache_str}, 29180Sstevel@tonic-gate { 0x23, 8, 64, 1024*1024, sl3_cache_str}, 29190Sstevel@tonic-gate { 0x22, 4, 64, 512*1024, sl3_cache_str}, 29200Sstevel@tonic-gate { 0x0c, 4, 32, 16*1024, l1_dcache_str}, 29213446Smrj { 0x0b, 4, 0, 4, itlb4M_str}, 29220Sstevel@tonic-gate { 0x0a, 2, 32, 8*1024, l1_dcache_str}, 29230Sstevel@tonic-gate { 0x08, 4, 32, 16*1024, l1_icache_str}, 29240Sstevel@tonic-gate { 0x06, 4, 32, 8*1024, l1_icache_str}, 29250Sstevel@tonic-gate { 0x04, 4, 0, 8, dtlb4M_str}, 29260Sstevel@tonic-gate { 0x03, 4, 0, 64, dtlb4k_str}, 29270Sstevel@tonic-gate { 0x02, 4, 0, 2, itlb4M_str}, 29280Sstevel@tonic-gate { 0x01, 4, 0, 32, itlb4k_str}, 29290Sstevel@tonic-gate { 0 } 29300Sstevel@tonic-gate }; 29310Sstevel@tonic-gate 29320Sstevel@tonic-gate static const struct cachetab cyrix_ctab[] = { 29330Sstevel@tonic-gate { 0x70, 4, 0, 32, "tlb-4K" }, 29340Sstevel@tonic-gate { 0x80, 4, 16, 16*1024, "l1-cache" }, 29350Sstevel@tonic-gate { 0 } 29360Sstevel@tonic-gate }; 29370Sstevel@tonic-gate 29380Sstevel@tonic-gate /* 29390Sstevel@tonic-gate * Search a cache table for a matching entry 29400Sstevel@tonic-gate */ 29410Sstevel@tonic-gate static const struct cachetab * 29420Sstevel@tonic-gate find_cacheent(const struct cachetab *ct, uint_t code) 29430Sstevel@tonic-gate { 29440Sstevel@tonic-gate if (code != 0) { 29450Sstevel@tonic-gate for (; ct->ct_code != 0; ct++) 29460Sstevel@tonic-gate if (ct->ct_code <= code) 29470Sstevel@tonic-gate break; 29480Sstevel@tonic-gate if (ct->ct_code == code) 29490Sstevel@tonic-gate return (ct); 29500Sstevel@tonic-gate } 29510Sstevel@tonic-gate return (NULL); 29520Sstevel@tonic-gate } 29530Sstevel@tonic-gate 29540Sstevel@tonic-gate /* 29555438Sksadhukh * Populate cachetab entry with L2 or L3 cache-information using 29565438Sksadhukh * cpuid function 4. This function is called from intel_walk_cacheinfo() 29575438Sksadhukh * when descriptor 0x49 is encountered. It returns 0 if no such cache 29585438Sksadhukh * information is found. 29595438Sksadhukh */ 29605438Sksadhukh static int 29615438Sksadhukh intel_cpuid_4_cache_info(struct cachetab *ct, struct cpuid_info *cpi) 29625438Sksadhukh { 29635438Sksadhukh uint32_t level, i; 29645438Sksadhukh int ret = 0; 29655438Sksadhukh 29665438Sksadhukh for (i = 0; i < cpi->cpi_std_4_size; i++) { 29675438Sksadhukh level = CPI_CACHE_LVL(cpi->cpi_std_4[i]); 29685438Sksadhukh 29695438Sksadhukh if (level == 2 || level == 3) { 29705438Sksadhukh ct->ct_assoc = CPI_CACHE_WAYS(cpi->cpi_std_4[i]) + 1; 29715438Sksadhukh ct->ct_line_size = 29725438Sksadhukh CPI_CACHE_COH_LN_SZ(cpi->cpi_std_4[i]) + 1; 29735438Sksadhukh ct->ct_size = ct->ct_assoc * 29745438Sksadhukh (CPI_CACHE_PARTS(cpi->cpi_std_4[i]) + 1) * 29755438Sksadhukh ct->ct_line_size * 29765438Sksadhukh (cpi->cpi_std_4[i]->cp_ecx + 1); 29775438Sksadhukh 29785438Sksadhukh if (level == 2) { 29795438Sksadhukh ct->ct_label = l2_cache_str; 29805438Sksadhukh } else if (level == 3) { 29815438Sksadhukh ct->ct_label = l3_cache_str; 29825438Sksadhukh } 29835438Sksadhukh ret = 1; 29845438Sksadhukh } 29855438Sksadhukh } 29865438Sksadhukh 29875438Sksadhukh return (ret); 29885438Sksadhukh } 29895438Sksadhukh 29905438Sksadhukh /* 29910Sstevel@tonic-gate * Walk the cacheinfo descriptor, applying 'func' to every valid element 29920Sstevel@tonic-gate * The walk is terminated if the walker returns non-zero. 29930Sstevel@tonic-gate */ 29940Sstevel@tonic-gate static void 29950Sstevel@tonic-gate intel_walk_cacheinfo(struct cpuid_info *cpi, 29960Sstevel@tonic-gate void *arg, int (*func)(void *, const struct cachetab *)) 29970Sstevel@tonic-gate { 29980Sstevel@tonic-gate const struct cachetab *ct; 29995438Sksadhukh struct cachetab des_49_ct; 30000Sstevel@tonic-gate uint8_t *dp; 30010Sstevel@tonic-gate int i; 30020Sstevel@tonic-gate 30030Sstevel@tonic-gate if ((dp = cpi->cpi_cacheinfo) == NULL) 30040Sstevel@tonic-gate return; 30054797Sksadhukh for (i = 0; i < cpi->cpi_ncache; i++, dp++) { 30064797Sksadhukh /* 30074797Sksadhukh * For overloaded descriptor 0x49 we use cpuid function 4 30085438Sksadhukh * if supported by the current processor, to create 30094797Sksadhukh * cache information. 30104797Sksadhukh */ 30115438Sksadhukh if (*dp == 0x49 && cpi->cpi_maxeax >= 0x4 && 30125438Sksadhukh intel_cpuid_4_cache_info(&des_49_ct, cpi) == 1) { 30135438Sksadhukh ct = &des_49_ct; 30145438Sksadhukh } else { 30155438Sksadhukh if ((ct = find_cacheent(intel_ctab, *dp)) == NULL) { 30165438Sksadhukh continue; 30175438Sksadhukh } 30184797Sksadhukh } 30194797Sksadhukh 30205438Sksadhukh if (func(arg, ct) != 0) { 30215438Sksadhukh break; 30220Sstevel@tonic-gate } 30234797Sksadhukh } 30240Sstevel@tonic-gate } 30250Sstevel@tonic-gate 30260Sstevel@tonic-gate /* 30270Sstevel@tonic-gate * (Like the Intel one, except for Cyrix CPUs) 30280Sstevel@tonic-gate */ 30290Sstevel@tonic-gate static void 30300Sstevel@tonic-gate cyrix_walk_cacheinfo(struct cpuid_info *cpi, 30310Sstevel@tonic-gate void *arg, int (*func)(void *, const struct cachetab *)) 30320Sstevel@tonic-gate { 30330Sstevel@tonic-gate const struct cachetab *ct; 30340Sstevel@tonic-gate uint8_t *dp; 30350Sstevel@tonic-gate int i; 30360Sstevel@tonic-gate 30370Sstevel@tonic-gate if ((dp = cpi->cpi_cacheinfo) == NULL) 30380Sstevel@tonic-gate return; 30390Sstevel@tonic-gate for (i = 0; i < cpi->cpi_ncache; i++, dp++) { 30400Sstevel@tonic-gate /* 30410Sstevel@tonic-gate * Search Cyrix-specific descriptor table first .. 30420Sstevel@tonic-gate */ 30430Sstevel@tonic-gate if ((ct = find_cacheent(cyrix_ctab, *dp)) != NULL) { 30440Sstevel@tonic-gate if (func(arg, ct) != 0) 30450Sstevel@tonic-gate break; 30460Sstevel@tonic-gate continue; 30470Sstevel@tonic-gate } 30480Sstevel@tonic-gate /* 30490Sstevel@tonic-gate * .. else fall back to the Intel one 30500Sstevel@tonic-gate */ 30510Sstevel@tonic-gate if ((ct = find_cacheent(intel_ctab, *dp)) != NULL) { 30520Sstevel@tonic-gate if (func(arg, ct) != 0) 30530Sstevel@tonic-gate break; 30540Sstevel@tonic-gate continue; 30550Sstevel@tonic-gate } 30560Sstevel@tonic-gate } 30570Sstevel@tonic-gate } 30580Sstevel@tonic-gate 30590Sstevel@tonic-gate /* 30600Sstevel@tonic-gate * A cacheinfo walker that adds associativity, line-size, and size properties 30610Sstevel@tonic-gate * to the devinfo node it is passed as an argument. 30620Sstevel@tonic-gate */ 30630Sstevel@tonic-gate static int 30640Sstevel@tonic-gate add_cacheent_props(void *arg, const struct cachetab *ct) 30650Sstevel@tonic-gate { 30660Sstevel@tonic-gate dev_info_t *devi = arg; 30670Sstevel@tonic-gate 30680Sstevel@tonic-gate add_cache_prop(devi, ct->ct_label, assoc_str, ct->ct_assoc); 30690Sstevel@tonic-gate if (ct->ct_line_size != 0) 30700Sstevel@tonic-gate add_cache_prop(devi, ct->ct_label, line_str, 30710Sstevel@tonic-gate ct->ct_line_size); 30720Sstevel@tonic-gate add_cache_prop(devi, ct->ct_label, size_str, ct->ct_size); 30730Sstevel@tonic-gate return (0); 30740Sstevel@tonic-gate } 30750Sstevel@tonic-gate 30764797Sksadhukh 30770Sstevel@tonic-gate static const char fully_assoc[] = "fully-associative?"; 30780Sstevel@tonic-gate 30790Sstevel@tonic-gate /* 30800Sstevel@tonic-gate * AMD style cache/tlb description 30810Sstevel@tonic-gate * 30820Sstevel@tonic-gate * Extended functions 5 and 6 directly describe properties of 30830Sstevel@tonic-gate * tlbs and various cache levels. 30840Sstevel@tonic-gate */ 30850Sstevel@tonic-gate static void 30860Sstevel@tonic-gate add_amd_assoc(dev_info_t *devi, const char *label, uint_t assoc) 30870Sstevel@tonic-gate { 30880Sstevel@tonic-gate switch (assoc) { 30890Sstevel@tonic-gate case 0: /* reserved; ignore */ 30900Sstevel@tonic-gate break; 30910Sstevel@tonic-gate default: 30920Sstevel@tonic-gate add_cache_prop(devi, label, assoc_str, assoc); 30930Sstevel@tonic-gate break; 30940Sstevel@tonic-gate case 0xff: 30950Sstevel@tonic-gate add_cache_prop(devi, label, fully_assoc, 1); 30960Sstevel@tonic-gate break; 30970Sstevel@tonic-gate } 30980Sstevel@tonic-gate } 30990Sstevel@tonic-gate 31000Sstevel@tonic-gate static void 31010Sstevel@tonic-gate add_amd_tlb(dev_info_t *devi, const char *label, uint_t assoc, uint_t size) 31020Sstevel@tonic-gate { 31030Sstevel@tonic-gate if (size == 0) 31040Sstevel@tonic-gate return; 31050Sstevel@tonic-gate add_cache_prop(devi, label, size_str, size); 31060Sstevel@tonic-gate add_amd_assoc(devi, label, assoc); 31070Sstevel@tonic-gate } 31080Sstevel@tonic-gate 31090Sstevel@tonic-gate static void 31100Sstevel@tonic-gate add_amd_cache(dev_info_t *devi, const char *label, 31110Sstevel@tonic-gate uint_t size, uint_t assoc, uint_t lines_per_tag, uint_t line_size) 31120Sstevel@tonic-gate { 31130Sstevel@tonic-gate if (size == 0 || line_size == 0) 31140Sstevel@tonic-gate return; 31150Sstevel@tonic-gate add_amd_assoc(devi, label, assoc); 31160Sstevel@tonic-gate /* 31170Sstevel@tonic-gate * Most AMD parts have a sectored cache. Multiple cache lines are 31180Sstevel@tonic-gate * associated with each tag. A sector consists of all cache lines 31190Sstevel@tonic-gate * associated with a tag. For example, the AMD K6-III has a sector 31200Sstevel@tonic-gate * size of 2 cache lines per tag. 31210Sstevel@tonic-gate */ 31220Sstevel@tonic-gate if (lines_per_tag != 0) 31230Sstevel@tonic-gate add_cache_prop(devi, label, "lines-per-tag", lines_per_tag); 31240Sstevel@tonic-gate add_cache_prop(devi, label, line_str, line_size); 31250Sstevel@tonic-gate add_cache_prop(devi, label, size_str, size * 1024); 31260Sstevel@tonic-gate } 31270Sstevel@tonic-gate 31280Sstevel@tonic-gate static void 31290Sstevel@tonic-gate add_amd_l2_assoc(dev_info_t *devi, const char *label, uint_t assoc) 31300Sstevel@tonic-gate { 31310Sstevel@tonic-gate switch (assoc) { 31320Sstevel@tonic-gate case 0: /* off */ 31330Sstevel@tonic-gate break; 31340Sstevel@tonic-gate case 1: 31350Sstevel@tonic-gate case 2: 31360Sstevel@tonic-gate case 4: 31370Sstevel@tonic-gate add_cache_prop(devi, label, assoc_str, assoc); 31380Sstevel@tonic-gate break; 31390Sstevel@tonic-gate case 6: 31400Sstevel@tonic-gate add_cache_prop(devi, label, assoc_str, 8); 31410Sstevel@tonic-gate break; 31420Sstevel@tonic-gate case 8: 31430Sstevel@tonic-gate add_cache_prop(devi, label, assoc_str, 16); 31440Sstevel@tonic-gate break; 31450Sstevel@tonic-gate case 0xf: 31460Sstevel@tonic-gate add_cache_prop(devi, label, fully_assoc, 1); 31470Sstevel@tonic-gate break; 31480Sstevel@tonic-gate default: /* reserved; ignore */ 31490Sstevel@tonic-gate break; 31500Sstevel@tonic-gate } 31510Sstevel@tonic-gate } 31520Sstevel@tonic-gate 31530Sstevel@tonic-gate static void 31540Sstevel@tonic-gate add_amd_l2_tlb(dev_info_t *devi, const char *label, uint_t assoc, uint_t size) 31550Sstevel@tonic-gate { 31560Sstevel@tonic-gate if (size == 0 || assoc == 0) 31570Sstevel@tonic-gate return; 31580Sstevel@tonic-gate add_amd_l2_assoc(devi, label, assoc); 31590Sstevel@tonic-gate add_cache_prop(devi, label, size_str, size); 31600Sstevel@tonic-gate } 31610Sstevel@tonic-gate 31620Sstevel@tonic-gate static void 31630Sstevel@tonic-gate add_amd_l2_cache(dev_info_t *devi, const char *label, 31640Sstevel@tonic-gate uint_t size, uint_t assoc, uint_t lines_per_tag, uint_t line_size) 31650Sstevel@tonic-gate { 31660Sstevel@tonic-gate if (size == 0 || assoc == 0 || line_size == 0) 31670Sstevel@tonic-gate return; 31680Sstevel@tonic-gate add_amd_l2_assoc(devi, label, assoc); 31690Sstevel@tonic-gate if (lines_per_tag != 0) 31700Sstevel@tonic-gate add_cache_prop(devi, label, "lines-per-tag", lines_per_tag); 31710Sstevel@tonic-gate add_cache_prop(devi, label, line_str, line_size); 31720Sstevel@tonic-gate add_cache_prop(devi, label, size_str, size * 1024); 31730Sstevel@tonic-gate } 31740Sstevel@tonic-gate 31750Sstevel@tonic-gate static void 31760Sstevel@tonic-gate amd_cache_info(struct cpuid_info *cpi, dev_info_t *devi) 31770Sstevel@tonic-gate { 31781228Sandrei struct cpuid_regs *cp; 31790Sstevel@tonic-gate 31800Sstevel@tonic-gate if (cpi->cpi_xmaxeax < 0x80000005) 31810Sstevel@tonic-gate return; 31820Sstevel@tonic-gate cp = &cpi->cpi_extd[5]; 31830Sstevel@tonic-gate 31840Sstevel@tonic-gate /* 31850Sstevel@tonic-gate * 4M/2M L1 TLB configuration 31860Sstevel@tonic-gate * 31870Sstevel@tonic-gate * We report the size for 2M pages because AMD uses two 31880Sstevel@tonic-gate * TLB entries for one 4M page. 31890Sstevel@tonic-gate */ 31900Sstevel@tonic-gate add_amd_tlb(devi, "dtlb-2M", 31910Sstevel@tonic-gate BITX(cp->cp_eax, 31, 24), BITX(cp->cp_eax, 23, 16)); 31920Sstevel@tonic-gate add_amd_tlb(devi, "itlb-2M", 31930Sstevel@tonic-gate BITX(cp->cp_eax, 15, 8), BITX(cp->cp_eax, 7, 0)); 31940Sstevel@tonic-gate 31950Sstevel@tonic-gate /* 31960Sstevel@tonic-gate * 4K L1 TLB configuration 31970Sstevel@tonic-gate */ 31980Sstevel@tonic-gate 31990Sstevel@tonic-gate switch (cpi->cpi_vendor) { 32000Sstevel@tonic-gate uint_t nentries; 32010Sstevel@tonic-gate case X86_VENDOR_TM: 32020Sstevel@tonic-gate if (cpi->cpi_family >= 5) { 32030Sstevel@tonic-gate /* 32040Sstevel@tonic-gate * Crusoe processors have 256 TLB entries, but 32050Sstevel@tonic-gate * cpuid data format constrains them to only 32060Sstevel@tonic-gate * reporting 255 of them. 32070Sstevel@tonic-gate */ 32080Sstevel@tonic-gate if ((nentries = BITX(cp->cp_ebx, 23, 16)) == 255) 32090Sstevel@tonic-gate nentries = 256; 32100Sstevel@tonic-gate /* 32110Sstevel@tonic-gate * Crusoe processors also have a unified TLB 32120Sstevel@tonic-gate */ 32130Sstevel@tonic-gate add_amd_tlb(devi, "tlb-4K", BITX(cp->cp_ebx, 31, 24), 32140Sstevel@tonic-gate nentries); 32150Sstevel@tonic-gate break; 32160Sstevel@tonic-gate } 32170Sstevel@tonic-gate /*FALLTHROUGH*/ 32180Sstevel@tonic-gate default: 32190Sstevel@tonic-gate add_amd_tlb(devi, itlb4k_str, 32200Sstevel@tonic-gate BITX(cp->cp_ebx, 31, 24), BITX(cp->cp_ebx, 23, 16)); 32210Sstevel@tonic-gate add_amd_tlb(devi, dtlb4k_str, 32220Sstevel@tonic-gate BITX(cp->cp_ebx, 15, 8), BITX(cp->cp_ebx, 7, 0)); 32230Sstevel@tonic-gate break; 32240Sstevel@tonic-gate } 32250Sstevel@tonic-gate 32260Sstevel@tonic-gate /* 32270Sstevel@tonic-gate * data L1 cache configuration 32280Sstevel@tonic-gate */ 32290Sstevel@tonic-gate 32300Sstevel@tonic-gate add_amd_cache(devi, l1_dcache_str, 32310Sstevel@tonic-gate BITX(cp->cp_ecx, 31, 24), BITX(cp->cp_ecx, 23, 16), 32320Sstevel@tonic-gate BITX(cp->cp_ecx, 15, 8), BITX(cp->cp_ecx, 7, 0)); 32330Sstevel@tonic-gate 32340Sstevel@tonic-gate /* 32350Sstevel@tonic-gate * code L1 cache configuration 32360Sstevel@tonic-gate */ 32370Sstevel@tonic-gate 32380Sstevel@tonic-gate add_amd_cache(devi, l1_icache_str, 32390Sstevel@tonic-gate BITX(cp->cp_edx, 31, 24), BITX(cp->cp_edx, 23, 16), 32400Sstevel@tonic-gate BITX(cp->cp_edx, 15, 8), BITX(cp->cp_edx, 7, 0)); 32410Sstevel@tonic-gate 32420Sstevel@tonic-gate if (cpi->cpi_xmaxeax < 0x80000006) 32430Sstevel@tonic-gate return; 32440Sstevel@tonic-gate cp = &cpi->cpi_extd[6]; 32450Sstevel@tonic-gate 32460Sstevel@tonic-gate /* Check for a unified L2 TLB for large pages */ 32470Sstevel@tonic-gate 32480Sstevel@tonic-gate if (BITX(cp->cp_eax, 31, 16) == 0) 32490Sstevel@tonic-gate add_amd_l2_tlb(devi, "l2-tlb-2M", 32500Sstevel@tonic-gate BITX(cp->cp_eax, 15, 12), BITX(cp->cp_eax, 11, 0)); 32510Sstevel@tonic-gate else { 32520Sstevel@tonic-gate add_amd_l2_tlb(devi, "l2-dtlb-2M", 32530Sstevel@tonic-gate BITX(cp->cp_eax, 31, 28), BITX(cp->cp_eax, 27, 16)); 32540Sstevel@tonic-gate add_amd_l2_tlb(devi, "l2-itlb-2M", 32550Sstevel@tonic-gate BITX(cp->cp_eax, 15, 12), BITX(cp->cp_eax, 11, 0)); 32560Sstevel@tonic-gate } 32570Sstevel@tonic-gate 32580Sstevel@tonic-gate /* Check for a unified L2 TLB for 4K pages */ 32590Sstevel@tonic-gate 32600Sstevel@tonic-gate if (BITX(cp->cp_ebx, 31, 16) == 0) { 32610Sstevel@tonic-gate add_amd_l2_tlb(devi, "l2-tlb-4K", 32620Sstevel@tonic-gate BITX(cp->cp_eax, 15, 12), BITX(cp->cp_eax, 11, 0)); 32630Sstevel@tonic-gate } else { 32640Sstevel@tonic-gate add_amd_l2_tlb(devi, "l2-dtlb-4K", 32650Sstevel@tonic-gate BITX(cp->cp_eax, 31, 28), BITX(cp->cp_eax, 27, 16)); 32660Sstevel@tonic-gate add_amd_l2_tlb(devi, "l2-itlb-4K", 32670Sstevel@tonic-gate BITX(cp->cp_eax, 15, 12), BITX(cp->cp_eax, 11, 0)); 32680Sstevel@tonic-gate } 32690Sstevel@tonic-gate 32700Sstevel@tonic-gate add_amd_l2_cache(devi, l2_cache_str, 32710Sstevel@tonic-gate BITX(cp->cp_ecx, 31, 16), BITX(cp->cp_ecx, 15, 12), 32720Sstevel@tonic-gate BITX(cp->cp_ecx, 11, 8), BITX(cp->cp_ecx, 7, 0)); 32730Sstevel@tonic-gate } 32740Sstevel@tonic-gate 32750Sstevel@tonic-gate /* 32760Sstevel@tonic-gate * There are two basic ways that the x86 world describes it cache 32770Sstevel@tonic-gate * and tlb architecture - Intel's way and AMD's way. 32780Sstevel@tonic-gate * 32790Sstevel@tonic-gate * Return which flavor of cache architecture we should use 32800Sstevel@tonic-gate */ 32810Sstevel@tonic-gate static int 32820Sstevel@tonic-gate x86_which_cacheinfo(struct cpuid_info *cpi) 32830Sstevel@tonic-gate { 32840Sstevel@tonic-gate switch (cpi->cpi_vendor) { 32850Sstevel@tonic-gate case X86_VENDOR_Intel: 32860Sstevel@tonic-gate if (cpi->cpi_maxeax >= 2) 32870Sstevel@tonic-gate return (X86_VENDOR_Intel); 32880Sstevel@tonic-gate break; 32890Sstevel@tonic-gate case X86_VENDOR_AMD: 32900Sstevel@tonic-gate /* 32910Sstevel@tonic-gate * The K5 model 1 was the first part from AMD that reported 32920Sstevel@tonic-gate * cache sizes via extended cpuid functions. 32930Sstevel@tonic-gate */ 32940Sstevel@tonic-gate if (cpi->cpi_family > 5 || 32950Sstevel@tonic-gate (cpi->cpi_family == 5 && cpi->cpi_model >= 1)) 32960Sstevel@tonic-gate return (X86_VENDOR_AMD); 32970Sstevel@tonic-gate break; 32980Sstevel@tonic-gate case X86_VENDOR_TM: 32990Sstevel@tonic-gate if (cpi->cpi_family >= 5) 33000Sstevel@tonic-gate return (X86_VENDOR_AMD); 33010Sstevel@tonic-gate /*FALLTHROUGH*/ 33020Sstevel@tonic-gate default: 33030Sstevel@tonic-gate /* 33040Sstevel@tonic-gate * If they have extended CPU data for 0x80000005 33050Sstevel@tonic-gate * then we assume they have AMD-format cache 33060Sstevel@tonic-gate * information. 33070Sstevel@tonic-gate * 33080Sstevel@tonic-gate * If not, and the vendor happens to be Cyrix, 33090Sstevel@tonic-gate * then try our-Cyrix specific handler. 33100Sstevel@tonic-gate * 33110Sstevel@tonic-gate * If we're not Cyrix, then assume we're using Intel's 33120Sstevel@tonic-gate * table-driven format instead. 33130Sstevel@tonic-gate */ 33140Sstevel@tonic-gate if (cpi->cpi_xmaxeax >= 0x80000005) 33150Sstevel@tonic-gate return (X86_VENDOR_AMD); 33160Sstevel@tonic-gate else if (cpi->cpi_vendor == X86_VENDOR_Cyrix) 33170Sstevel@tonic-gate return (X86_VENDOR_Cyrix); 33180Sstevel@tonic-gate else if (cpi->cpi_maxeax >= 2) 33190Sstevel@tonic-gate return (X86_VENDOR_Intel); 33200Sstevel@tonic-gate break; 33210Sstevel@tonic-gate } 33220Sstevel@tonic-gate return (-1); 33230Sstevel@tonic-gate } 33240Sstevel@tonic-gate 33250Sstevel@tonic-gate /* 33260Sstevel@tonic-gate * create a node for the given cpu under the prom root node. 33270Sstevel@tonic-gate * Also, create a cpu node in the device tree. 33280Sstevel@tonic-gate */ 33290Sstevel@tonic-gate static dev_info_t *cpu_nex_devi = NULL; 33300Sstevel@tonic-gate static kmutex_t cpu_node_lock; 33310Sstevel@tonic-gate 33320Sstevel@tonic-gate /* 33330Sstevel@tonic-gate * Called from post_startup() and mp_startup() 33340Sstevel@tonic-gate */ 33350Sstevel@tonic-gate void 33360Sstevel@tonic-gate add_cpunode2devtree(processorid_t cpu_id, struct cpuid_info *cpi) 33370Sstevel@tonic-gate { 33380Sstevel@tonic-gate dev_info_t *cpu_devi; 33390Sstevel@tonic-gate int create; 33400Sstevel@tonic-gate 33410Sstevel@tonic-gate mutex_enter(&cpu_node_lock); 33420Sstevel@tonic-gate 33430Sstevel@tonic-gate /* 33440Sstevel@tonic-gate * create a nexus node for all cpus identified as 'cpu_id' under 33450Sstevel@tonic-gate * the root node. 33460Sstevel@tonic-gate */ 33470Sstevel@tonic-gate if (cpu_nex_devi == NULL) { 33480Sstevel@tonic-gate if (ndi_devi_alloc(ddi_root_node(), "cpus", 3349789Sahrens (pnode_t)DEVI_SID_NODEID, &cpu_nex_devi) != NDI_SUCCESS) { 33500Sstevel@tonic-gate mutex_exit(&cpu_node_lock); 33510Sstevel@tonic-gate return; 33520Sstevel@tonic-gate } 33530Sstevel@tonic-gate (void) ndi_devi_online(cpu_nex_devi, 0); 33540Sstevel@tonic-gate } 33550Sstevel@tonic-gate 33560Sstevel@tonic-gate /* 33570Sstevel@tonic-gate * create a child node for cpu identified as 'cpu_id' 33580Sstevel@tonic-gate */ 33590Sstevel@tonic-gate cpu_devi = ddi_add_child(cpu_nex_devi, "cpu", DEVI_SID_NODEID, 33604481Sbholler cpu_id); 33610Sstevel@tonic-gate if (cpu_devi == NULL) { 33620Sstevel@tonic-gate mutex_exit(&cpu_node_lock); 33630Sstevel@tonic-gate return; 33640Sstevel@tonic-gate } 33650Sstevel@tonic-gate 33660Sstevel@tonic-gate /* device_type */ 33670Sstevel@tonic-gate 33680Sstevel@tonic-gate (void) ndi_prop_update_string(DDI_DEV_T_NONE, cpu_devi, 33690Sstevel@tonic-gate "device_type", "cpu"); 33700Sstevel@tonic-gate 33710Sstevel@tonic-gate /* reg */ 33720Sstevel@tonic-gate 33730Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 33740Sstevel@tonic-gate "reg", cpu_id); 33750Sstevel@tonic-gate 33760Sstevel@tonic-gate /* cpu-mhz, and clock-frequency */ 33770Sstevel@tonic-gate 33780Sstevel@tonic-gate if (cpu_freq > 0) { 33790Sstevel@tonic-gate long long mul; 33800Sstevel@tonic-gate 33810Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 33820Sstevel@tonic-gate "cpu-mhz", cpu_freq); 33830Sstevel@tonic-gate 33840Sstevel@tonic-gate if ((mul = cpu_freq * 1000000LL) <= INT_MAX) 33850Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 33860Sstevel@tonic-gate "clock-frequency", (int)mul); 33870Sstevel@tonic-gate } 33880Sstevel@tonic-gate 33890Sstevel@tonic-gate (void) ndi_devi_online(cpu_devi, 0); 33900Sstevel@tonic-gate 33910Sstevel@tonic-gate if ((x86_feature & X86_CPUID) == 0) { 33920Sstevel@tonic-gate mutex_exit(&cpu_node_lock); 33930Sstevel@tonic-gate return; 33940Sstevel@tonic-gate } 33950Sstevel@tonic-gate 33960Sstevel@tonic-gate /* vendor-id */ 33970Sstevel@tonic-gate 33980Sstevel@tonic-gate (void) ndi_prop_update_string(DDI_DEV_T_NONE, cpu_devi, 33994481Sbholler "vendor-id", cpi->cpi_vendorstr); 34000Sstevel@tonic-gate 34010Sstevel@tonic-gate if (cpi->cpi_maxeax == 0) { 34020Sstevel@tonic-gate mutex_exit(&cpu_node_lock); 34030Sstevel@tonic-gate return; 34040Sstevel@tonic-gate } 34050Sstevel@tonic-gate 34060Sstevel@tonic-gate /* 34070Sstevel@tonic-gate * family, model, and step 34080Sstevel@tonic-gate */ 34090Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 34104481Sbholler "family", CPI_FAMILY(cpi)); 34110Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 34124481Sbholler "cpu-model", CPI_MODEL(cpi)); 34130Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 34144481Sbholler "stepping-id", CPI_STEP(cpi)); 34150Sstevel@tonic-gate 34160Sstevel@tonic-gate /* type */ 34170Sstevel@tonic-gate 34180Sstevel@tonic-gate switch (cpi->cpi_vendor) { 34190Sstevel@tonic-gate case X86_VENDOR_Intel: 34200Sstevel@tonic-gate create = 1; 34210Sstevel@tonic-gate break; 34220Sstevel@tonic-gate default: 34230Sstevel@tonic-gate create = 0; 34240Sstevel@tonic-gate break; 34250Sstevel@tonic-gate } 34260Sstevel@tonic-gate if (create) 34270Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 34284481Sbholler "type", CPI_TYPE(cpi)); 34290Sstevel@tonic-gate 34300Sstevel@tonic-gate /* ext-family */ 34310Sstevel@tonic-gate 34320Sstevel@tonic-gate switch (cpi->cpi_vendor) { 34330Sstevel@tonic-gate case X86_VENDOR_Intel: 34340Sstevel@tonic-gate case X86_VENDOR_AMD: 34350Sstevel@tonic-gate create = cpi->cpi_family >= 0xf; 34360Sstevel@tonic-gate break; 34370Sstevel@tonic-gate default: 34380Sstevel@tonic-gate create = 0; 34390Sstevel@tonic-gate break; 34400Sstevel@tonic-gate } 34410Sstevel@tonic-gate if (create) 34420Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 34430Sstevel@tonic-gate "ext-family", CPI_FAMILY_XTD(cpi)); 34440Sstevel@tonic-gate 34450Sstevel@tonic-gate /* ext-model */ 34460Sstevel@tonic-gate 34470Sstevel@tonic-gate switch (cpi->cpi_vendor) { 34480Sstevel@tonic-gate case X86_VENDOR_Intel: 3449*6317Skk208521 create = IS_EXTENDED_MODEL_INTEL(cpi); 34502001Sdmick break; 34510Sstevel@tonic-gate case X86_VENDOR_AMD: 34521582Skchow create = CPI_FAMILY(cpi) == 0xf; 34530Sstevel@tonic-gate break; 34540Sstevel@tonic-gate default: 34550Sstevel@tonic-gate create = 0; 34560Sstevel@tonic-gate break; 34570Sstevel@tonic-gate } 34580Sstevel@tonic-gate if (create) 34590Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 34604481Sbholler "ext-model", CPI_MODEL_XTD(cpi)); 34610Sstevel@tonic-gate 34620Sstevel@tonic-gate /* generation */ 34630Sstevel@tonic-gate 34640Sstevel@tonic-gate switch (cpi->cpi_vendor) { 34650Sstevel@tonic-gate case X86_VENDOR_AMD: 34660Sstevel@tonic-gate /* 34670Sstevel@tonic-gate * AMD K5 model 1 was the first part to support this 34680Sstevel@tonic-gate */ 34690Sstevel@tonic-gate create = cpi->cpi_xmaxeax >= 0x80000001; 34700Sstevel@tonic-gate break; 34710Sstevel@tonic-gate default: 34720Sstevel@tonic-gate create = 0; 34730Sstevel@tonic-gate break; 34740Sstevel@tonic-gate } 34750Sstevel@tonic-gate if (create) 34760Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 34770Sstevel@tonic-gate "generation", BITX((cpi)->cpi_extd[1].cp_eax, 11, 8)); 34780Sstevel@tonic-gate 34790Sstevel@tonic-gate /* brand-id */ 34800Sstevel@tonic-gate 34810Sstevel@tonic-gate switch (cpi->cpi_vendor) { 34820Sstevel@tonic-gate case X86_VENDOR_Intel: 34830Sstevel@tonic-gate /* 34840Sstevel@tonic-gate * brand id first appeared on Pentium III Xeon model 8, 34850Sstevel@tonic-gate * and Celeron model 8 processors and Opteron 34860Sstevel@tonic-gate */ 34870Sstevel@tonic-gate create = cpi->cpi_family > 6 || 34880Sstevel@tonic-gate (cpi->cpi_family == 6 && cpi->cpi_model >= 8); 34890Sstevel@tonic-gate break; 34900Sstevel@tonic-gate case X86_VENDOR_AMD: 34910Sstevel@tonic-gate create = cpi->cpi_family >= 0xf; 34920Sstevel@tonic-gate break; 34930Sstevel@tonic-gate default: 34940Sstevel@tonic-gate create = 0; 34950Sstevel@tonic-gate break; 34960Sstevel@tonic-gate } 34970Sstevel@tonic-gate if (create && cpi->cpi_brandid != 0) { 34980Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 34990Sstevel@tonic-gate "brand-id", cpi->cpi_brandid); 35000Sstevel@tonic-gate } 35010Sstevel@tonic-gate 35020Sstevel@tonic-gate /* chunks, and apic-id */ 35030Sstevel@tonic-gate 35040Sstevel@tonic-gate switch (cpi->cpi_vendor) { 35050Sstevel@tonic-gate /* 35060Sstevel@tonic-gate * first available on Pentium IV and Opteron (K8) 35070Sstevel@tonic-gate */ 35081975Sdmick case X86_VENDOR_Intel: 35091975Sdmick create = IS_NEW_F6(cpi) || cpi->cpi_family >= 0xf; 35101975Sdmick break; 35111975Sdmick case X86_VENDOR_AMD: 35120Sstevel@tonic-gate create = cpi->cpi_family >= 0xf; 35130Sstevel@tonic-gate break; 35140Sstevel@tonic-gate default: 35150Sstevel@tonic-gate create = 0; 35160Sstevel@tonic-gate break; 35170Sstevel@tonic-gate } 35180Sstevel@tonic-gate if (create) { 35190Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 35204481Sbholler "chunks", CPI_CHUNKS(cpi)); 35210Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 35224481Sbholler "apic-id", CPI_APIC_ID(cpi)); 35231414Scindi if (cpi->cpi_chipid >= 0) { 35240Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 35250Sstevel@tonic-gate "chip#", cpi->cpi_chipid); 35261414Scindi (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 35271414Scindi "clog#", cpi->cpi_clogid); 35281414Scindi } 35290Sstevel@tonic-gate } 35300Sstevel@tonic-gate 35310Sstevel@tonic-gate /* cpuid-features */ 35320Sstevel@tonic-gate 35330Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 35340Sstevel@tonic-gate "cpuid-features", CPI_FEATURES_EDX(cpi)); 35350Sstevel@tonic-gate 35360Sstevel@tonic-gate 35370Sstevel@tonic-gate /* cpuid-features-ecx */ 35380Sstevel@tonic-gate 35390Sstevel@tonic-gate switch (cpi->cpi_vendor) { 35400Sstevel@tonic-gate case X86_VENDOR_Intel: 35411975Sdmick create = IS_NEW_F6(cpi) || cpi->cpi_family >= 0xf; 35420Sstevel@tonic-gate break; 35430Sstevel@tonic-gate default: 35440Sstevel@tonic-gate create = 0; 35450Sstevel@tonic-gate break; 35460Sstevel@tonic-gate } 35470Sstevel@tonic-gate if (create) 35480Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 35490Sstevel@tonic-gate "cpuid-features-ecx", CPI_FEATURES_ECX(cpi)); 35500Sstevel@tonic-gate 35510Sstevel@tonic-gate /* ext-cpuid-features */ 35520Sstevel@tonic-gate 35530Sstevel@tonic-gate switch (cpi->cpi_vendor) { 35541975Sdmick case X86_VENDOR_Intel: 35550Sstevel@tonic-gate case X86_VENDOR_AMD: 35560Sstevel@tonic-gate case X86_VENDOR_Cyrix: 35570Sstevel@tonic-gate case X86_VENDOR_TM: 35580Sstevel@tonic-gate case X86_VENDOR_Centaur: 35590Sstevel@tonic-gate create = cpi->cpi_xmaxeax >= 0x80000001; 35600Sstevel@tonic-gate break; 35610Sstevel@tonic-gate default: 35620Sstevel@tonic-gate create = 0; 35630Sstevel@tonic-gate break; 35640Sstevel@tonic-gate } 35651975Sdmick if (create) { 35660Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 35674481Sbholler "ext-cpuid-features", CPI_FEATURES_XTD_EDX(cpi)); 35681975Sdmick (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 35694481Sbholler "ext-cpuid-features-ecx", CPI_FEATURES_XTD_ECX(cpi)); 35701975Sdmick } 35710Sstevel@tonic-gate 35720Sstevel@tonic-gate /* 35730Sstevel@tonic-gate * Brand String first appeared in Intel Pentium IV, AMD K5 35740Sstevel@tonic-gate * model 1, and Cyrix GXm. On earlier models we try and 35750Sstevel@tonic-gate * simulate something similar .. so this string should always 35760Sstevel@tonic-gate * same -something- about the processor, however lame. 35770Sstevel@tonic-gate */ 35780Sstevel@tonic-gate (void) ndi_prop_update_string(DDI_DEV_T_NONE, cpu_devi, 35790Sstevel@tonic-gate "brand-string", cpi->cpi_brandstr); 35800Sstevel@tonic-gate 35810Sstevel@tonic-gate /* 35820Sstevel@tonic-gate * Finally, cache and tlb information 35830Sstevel@tonic-gate */ 35840Sstevel@tonic-gate switch (x86_which_cacheinfo(cpi)) { 35850Sstevel@tonic-gate case X86_VENDOR_Intel: 35860Sstevel@tonic-gate intel_walk_cacheinfo(cpi, cpu_devi, add_cacheent_props); 35870Sstevel@tonic-gate break; 35880Sstevel@tonic-gate case X86_VENDOR_Cyrix: 35890Sstevel@tonic-gate cyrix_walk_cacheinfo(cpi, cpu_devi, add_cacheent_props); 35900Sstevel@tonic-gate break; 35910Sstevel@tonic-gate case X86_VENDOR_AMD: 35920Sstevel@tonic-gate amd_cache_info(cpi, cpu_devi); 35930Sstevel@tonic-gate break; 35940Sstevel@tonic-gate default: 35950Sstevel@tonic-gate break; 35960Sstevel@tonic-gate } 35970Sstevel@tonic-gate 35980Sstevel@tonic-gate mutex_exit(&cpu_node_lock); 35990Sstevel@tonic-gate } 36000Sstevel@tonic-gate 36010Sstevel@tonic-gate struct l2info { 36020Sstevel@tonic-gate int *l2i_csz; 36030Sstevel@tonic-gate int *l2i_lsz; 36040Sstevel@tonic-gate int *l2i_assoc; 36050Sstevel@tonic-gate int l2i_ret; 36060Sstevel@tonic-gate }; 36070Sstevel@tonic-gate 36080Sstevel@tonic-gate /* 36090Sstevel@tonic-gate * A cacheinfo walker that fetches the size, line-size and associativity 36100Sstevel@tonic-gate * of the L2 cache 36110Sstevel@tonic-gate */ 36120Sstevel@tonic-gate static int 36130Sstevel@tonic-gate intel_l2cinfo(void *arg, const struct cachetab *ct) 36140Sstevel@tonic-gate { 36150Sstevel@tonic-gate struct l2info *l2i = arg; 36160Sstevel@tonic-gate int *ip; 36170Sstevel@tonic-gate 36180Sstevel@tonic-gate if (ct->ct_label != l2_cache_str && 36190Sstevel@tonic-gate ct->ct_label != sl2_cache_str) 36200Sstevel@tonic-gate return (0); /* not an L2 -- keep walking */ 36210Sstevel@tonic-gate 36220Sstevel@tonic-gate if ((ip = l2i->l2i_csz) != NULL) 36230Sstevel@tonic-gate *ip = ct->ct_size; 36240Sstevel@tonic-gate if ((ip = l2i->l2i_lsz) != NULL) 36250Sstevel@tonic-gate *ip = ct->ct_line_size; 36260Sstevel@tonic-gate if ((ip = l2i->l2i_assoc) != NULL) 36270Sstevel@tonic-gate *ip = ct->ct_assoc; 36280Sstevel@tonic-gate l2i->l2i_ret = ct->ct_size; 36290Sstevel@tonic-gate return (1); /* was an L2 -- terminate walk */ 36300Sstevel@tonic-gate } 36310Sstevel@tonic-gate 36325070Skchow /* 36335070Skchow * AMD L2/L3 Cache and TLB Associativity Field Definition: 36345070Skchow * 36355070Skchow * Unlike the associativity for the L1 cache and tlb where the 8 bit 36365070Skchow * value is the associativity, the associativity for the L2 cache and 36375070Skchow * tlb is encoded in the following table. The 4 bit L2 value serves as 36385070Skchow * an index into the amd_afd[] array to determine the associativity. 36395070Skchow * -1 is undefined. 0 is fully associative. 36405070Skchow */ 36415070Skchow 36425070Skchow static int amd_afd[] = 36435070Skchow {-1, 1, 2, -1, 4, -1, 8, -1, 16, -1, 32, 48, 64, 96, 128, 0}; 36445070Skchow 36450Sstevel@tonic-gate static void 36460Sstevel@tonic-gate amd_l2cacheinfo(struct cpuid_info *cpi, struct l2info *l2i) 36470Sstevel@tonic-gate { 36481228Sandrei struct cpuid_regs *cp; 36490Sstevel@tonic-gate uint_t size, assoc; 36505070Skchow int i; 36510Sstevel@tonic-gate int *ip; 36520Sstevel@tonic-gate 36530Sstevel@tonic-gate if (cpi->cpi_xmaxeax < 0x80000006) 36540Sstevel@tonic-gate return; 36550Sstevel@tonic-gate cp = &cpi->cpi_extd[6]; 36560Sstevel@tonic-gate 36575070Skchow if ((i = BITX(cp->cp_ecx, 15, 12)) != 0 && 36580Sstevel@tonic-gate (size = BITX(cp->cp_ecx, 31, 16)) != 0) { 36590Sstevel@tonic-gate uint_t cachesz = size * 1024; 36605070Skchow assoc = amd_afd[i]; 36615070Skchow 36625070Skchow ASSERT(assoc != -1); 36630Sstevel@tonic-gate 36640Sstevel@tonic-gate if ((ip = l2i->l2i_csz) != NULL) 36650Sstevel@tonic-gate *ip = cachesz; 36660Sstevel@tonic-gate if ((ip = l2i->l2i_lsz) != NULL) 36670Sstevel@tonic-gate *ip = BITX(cp->cp_ecx, 7, 0); 36680Sstevel@tonic-gate if ((ip = l2i->l2i_assoc) != NULL) 36690Sstevel@tonic-gate *ip = assoc; 36700Sstevel@tonic-gate l2i->l2i_ret = cachesz; 36710Sstevel@tonic-gate } 36720Sstevel@tonic-gate } 36730Sstevel@tonic-gate 36740Sstevel@tonic-gate int 36750Sstevel@tonic-gate getl2cacheinfo(cpu_t *cpu, int *csz, int *lsz, int *assoc) 36760Sstevel@tonic-gate { 36770Sstevel@tonic-gate struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 36780Sstevel@tonic-gate struct l2info __l2info, *l2i = &__l2info; 36790Sstevel@tonic-gate 36800Sstevel@tonic-gate l2i->l2i_csz = csz; 36810Sstevel@tonic-gate l2i->l2i_lsz = lsz; 36820Sstevel@tonic-gate l2i->l2i_assoc = assoc; 36830Sstevel@tonic-gate l2i->l2i_ret = -1; 36840Sstevel@tonic-gate 36850Sstevel@tonic-gate switch (x86_which_cacheinfo(cpi)) { 36860Sstevel@tonic-gate case X86_VENDOR_Intel: 36870Sstevel@tonic-gate intel_walk_cacheinfo(cpi, l2i, intel_l2cinfo); 36880Sstevel@tonic-gate break; 36890Sstevel@tonic-gate case X86_VENDOR_Cyrix: 36900Sstevel@tonic-gate cyrix_walk_cacheinfo(cpi, l2i, intel_l2cinfo); 36910Sstevel@tonic-gate break; 36920Sstevel@tonic-gate case X86_VENDOR_AMD: 36930Sstevel@tonic-gate amd_l2cacheinfo(cpi, l2i); 36940Sstevel@tonic-gate break; 36950Sstevel@tonic-gate default: 36960Sstevel@tonic-gate break; 36970Sstevel@tonic-gate } 36980Sstevel@tonic-gate return (l2i->l2i_ret); 36990Sstevel@tonic-gate } 37004481Sbholler 37015084Sjohnlev #if !defined(__xpv) 37025084Sjohnlev 37035045Sbholler uint32_t * 37045045Sbholler cpuid_mwait_alloc(cpu_t *cpu) 37055045Sbholler { 37065045Sbholler uint32_t *ret; 37075045Sbholler size_t mwait_size; 37085045Sbholler 37095045Sbholler ASSERT(cpuid_checkpass(cpu, 2)); 37105045Sbholler 37115045Sbholler mwait_size = cpu->cpu_m.mcpu_cpi->cpi_mwait.mon_max; 37125045Sbholler if (mwait_size == 0) 37135045Sbholler return (NULL); 37145045Sbholler 37155045Sbholler /* 37165045Sbholler * kmem_alloc() returns cache line size aligned data for mwait_size 37175045Sbholler * allocations. mwait_size is currently cache line sized. Neither 37185045Sbholler * of these implementation details are guarantied to be true in the 37195045Sbholler * future. 37205045Sbholler * 37215045Sbholler * First try allocating mwait_size as kmem_alloc() currently returns 37225045Sbholler * correctly aligned memory. If kmem_alloc() does not return 37235045Sbholler * mwait_size aligned memory, then use mwait_size ROUNDUP. 37245045Sbholler * 37255045Sbholler * Set cpi_mwait.buf_actual and cpi_mwait.size_actual in case we 37265045Sbholler * decide to free this memory. 37275045Sbholler */ 37285045Sbholler ret = kmem_zalloc(mwait_size, KM_SLEEP); 37295045Sbholler if (ret == (uint32_t *)P2ROUNDUP((uintptr_t)ret, mwait_size)) { 37305045Sbholler cpu->cpu_m.mcpu_cpi->cpi_mwait.buf_actual = ret; 37315045Sbholler cpu->cpu_m.mcpu_cpi->cpi_mwait.size_actual = mwait_size; 37325045Sbholler *ret = MWAIT_RUNNING; 37335045Sbholler return (ret); 37345045Sbholler } else { 37355045Sbholler kmem_free(ret, mwait_size); 37365045Sbholler ret = kmem_zalloc(mwait_size * 2, KM_SLEEP); 37375045Sbholler cpu->cpu_m.mcpu_cpi->cpi_mwait.buf_actual = ret; 37385045Sbholler cpu->cpu_m.mcpu_cpi->cpi_mwait.size_actual = mwait_size * 2; 37395045Sbholler ret = (uint32_t *)P2ROUNDUP((uintptr_t)ret, mwait_size); 37405045Sbholler *ret = MWAIT_RUNNING; 37415045Sbholler return (ret); 37425045Sbholler } 37435045Sbholler } 37445045Sbholler 37455045Sbholler void 37465045Sbholler cpuid_mwait_free(cpu_t *cpu) 37474481Sbholler { 37484481Sbholler ASSERT(cpuid_checkpass(cpu, 2)); 37495045Sbholler 37505045Sbholler if (cpu->cpu_m.mcpu_cpi->cpi_mwait.buf_actual != NULL && 37515045Sbholler cpu->cpu_m.mcpu_cpi->cpi_mwait.size_actual > 0) { 37525045Sbholler kmem_free(cpu->cpu_m.mcpu_cpi->cpi_mwait.buf_actual, 37535045Sbholler cpu->cpu_m.mcpu_cpi->cpi_mwait.size_actual); 37545045Sbholler } 37555045Sbholler 37565045Sbholler cpu->cpu_m.mcpu_cpi->cpi_mwait.buf_actual = NULL; 37575045Sbholler cpu->cpu_m.mcpu_cpi->cpi_mwait.size_actual = 0; 37584481Sbholler } 37595084Sjohnlev 37605322Ssudheer void 37615322Ssudheer patch_tsc_read(int flag) 37625322Ssudheer { 37635322Ssudheer size_t cnt; 37645322Ssudheer switch (flag) { 37655322Ssudheer case X86_NO_TSC: 37665322Ssudheer cnt = &_no_rdtsc_end - &_no_rdtsc_start; 37675338Ssudheer (void) memcpy((void *)tsc_read, (void *)&_no_rdtsc_start, cnt); 37685322Ssudheer break; 37695322Ssudheer case X86_HAVE_TSCP: 37705322Ssudheer cnt = &_tscp_end - &_tscp_start; 37715338Ssudheer (void) memcpy((void *)tsc_read, (void *)&_tscp_start, cnt); 37725322Ssudheer break; 37735322Ssudheer case X86_TSC_MFENCE: 37745322Ssudheer cnt = &_tsc_mfence_end - &_tsc_mfence_start; 37755338Ssudheer (void) memcpy((void *)tsc_read, 37765338Ssudheer (void *)&_tsc_mfence_start, cnt); 37775322Ssudheer break; 37785322Ssudheer default: 37795322Ssudheer break; 37805322Ssudheer } 37815322Ssudheer } 37825322Ssudheer 37835084Sjohnlev #endif /* !__xpv */ 3784