17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5ee88d2b9Skchow * Common Development and Distribution License (the "License"). 6ee88d2b9Skchow * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 220e751525SEric Saxe * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate /* 277c478bd9Sstevel@tonic-gate * Various routines to handle identification 287c478bd9Sstevel@tonic-gate * and classification of x86 processors. 297c478bd9Sstevel@tonic-gate */ 307c478bd9Sstevel@tonic-gate 317c478bd9Sstevel@tonic-gate #include <sys/types.h> 327c478bd9Sstevel@tonic-gate #include <sys/archsystm.h> 337c478bd9Sstevel@tonic-gate #include <sys/x86_archext.h> 347c478bd9Sstevel@tonic-gate #include <sys/kmem.h> 357c478bd9Sstevel@tonic-gate #include <sys/systm.h> 367c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h> 377c478bd9Sstevel@tonic-gate #include <sys/sunddi.h> 387c478bd9Sstevel@tonic-gate #include <sys/sunndi.h> 397c478bd9Sstevel@tonic-gate #include <sys/cpuvar.h> 407c478bd9Sstevel@tonic-gate #include <sys/processor.h> 415b8a6efeSbholler #include <sys/sysmacros.h> 42fb2f18f8Sesaxe #include <sys/pg.h> 437c478bd9Sstevel@tonic-gate #include <sys/fp.h> 447c478bd9Sstevel@tonic-gate #include <sys/controlregs.h> 457c478bd9Sstevel@tonic-gate #include <sys/auxv_386.h> 467c478bd9Sstevel@tonic-gate #include <sys/bitmap.h> 477c478bd9Sstevel@tonic-gate #include <sys/memnode.h> 487c478bd9Sstevel@tonic-gate 49e4b86885SCheng Sean Ye #ifdef __xpv 50e4b86885SCheng Sean Ye #include <sys/hypervisor.h> 51*e774b42bSBill Holler #else 52*e774b42bSBill Holler #include <sys/ontrap.h> 53e4b86885SCheng Sean Ye #endif 54e4b86885SCheng Sean Ye 557c478bd9Sstevel@tonic-gate /* 567c478bd9Sstevel@tonic-gate * Pass 0 of cpuid feature analysis happens in locore. It contains special code 577c478bd9Sstevel@tonic-gate * to recognize Cyrix processors that are not cpuid-compliant, and to deal with 587c478bd9Sstevel@tonic-gate * them accordingly. For most modern processors, feature detection occurs here 597c478bd9Sstevel@tonic-gate * in pass 1. 607c478bd9Sstevel@tonic-gate * 617c478bd9Sstevel@tonic-gate * Pass 1 of cpuid feature analysis happens just at the beginning of mlsetup() 627c478bd9Sstevel@tonic-gate * for the boot CPU and does the basic analysis that the early kernel needs. 637c478bd9Sstevel@tonic-gate * x86_feature is set based on the return value of cpuid_pass1() of the boot 647c478bd9Sstevel@tonic-gate * CPU. 657c478bd9Sstevel@tonic-gate * 667c478bd9Sstevel@tonic-gate * Pass 1 includes: 677c478bd9Sstevel@tonic-gate * 687c478bd9Sstevel@tonic-gate * o Determining vendor/model/family/stepping and setting x86_type and 697c478bd9Sstevel@tonic-gate * x86_vendor accordingly. 707c478bd9Sstevel@tonic-gate * o Processing the feature flags returned by the cpuid instruction while 717c478bd9Sstevel@tonic-gate * applying any workarounds or tricks for the specific processor. 727c478bd9Sstevel@tonic-gate * o Mapping the feature flags into Solaris feature bits (X86_*). 737c478bd9Sstevel@tonic-gate * o Processing extended feature flags if supported by the processor, 747c478bd9Sstevel@tonic-gate * again while applying specific processor knowledge. 757c478bd9Sstevel@tonic-gate * o Determining the CMT characteristics of the system. 767c478bd9Sstevel@tonic-gate * 777c478bd9Sstevel@tonic-gate * Pass 1 is done on non-boot CPUs during their initialization and the results 787c478bd9Sstevel@tonic-gate * are used only as a meager attempt at ensuring that all processors within the 797c478bd9Sstevel@tonic-gate * system support the same features. 807c478bd9Sstevel@tonic-gate * 817c478bd9Sstevel@tonic-gate * Pass 2 of cpuid feature analysis happens just at the beginning 827c478bd9Sstevel@tonic-gate * of startup(). It just copies in and corrects the remainder 837c478bd9Sstevel@tonic-gate * of the cpuid data we depend on: standard cpuid functions that we didn't 847c478bd9Sstevel@tonic-gate * need for pass1 feature analysis, and extended cpuid functions beyond the 857c478bd9Sstevel@tonic-gate * simple feature processing done in pass1. 867c478bd9Sstevel@tonic-gate * 877c478bd9Sstevel@tonic-gate * Pass 3 of cpuid analysis is invoked after basic kernel services; in 887c478bd9Sstevel@tonic-gate * particular kernel memory allocation has been made available. It creates a 897c478bd9Sstevel@tonic-gate * readable brand string based on the data collected in the first two passes. 907c478bd9Sstevel@tonic-gate * 917c478bd9Sstevel@tonic-gate * Pass 4 of cpuid analysis is invoked after post_startup() when all 927c478bd9Sstevel@tonic-gate * the support infrastructure for various hardware features has been 937c478bd9Sstevel@tonic-gate * initialized. It determines which processor features will be reported 947c478bd9Sstevel@tonic-gate * to userland via the aux vector. 957c478bd9Sstevel@tonic-gate * 967c478bd9Sstevel@tonic-gate * All passes are executed on all CPUs, but only the boot CPU determines what 977c478bd9Sstevel@tonic-gate * features the kernel will use. 987c478bd9Sstevel@tonic-gate * 997c478bd9Sstevel@tonic-gate * Much of the worst junk in this file is for the support of processors 1007c478bd9Sstevel@tonic-gate * that didn't really implement the cpuid instruction properly. 1017c478bd9Sstevel@tonic-gate * 1027c478bd9Sstevel@tonic-gate * NOTE: The accessor functions (cpuid_get*) are aware of, and ASSERT upon, 1037c478bd9Sstevel@tonic-gate * the pass numbers. Accordingly, changes to the pass code may require changes 1047c478bd9Sstevel@tonic-gate * to the accessor code. 1057c478bd9Sstevel@tonic-gate */ 1067c478bd9Sstevel@tonic-gate 1077c478bd9Sstevel@tonic-gate uint_t x86_feature = 0; 1087c478bd9Sstevel@tonic-gate uint_t x86_vendor = X86_VENDOR_IntelClone; 1097c478bd9Sstevel@tonic-gate uint_t x86_type = X86_TYPE_OTHER; 11086c1f4dcSVikram Hegde uint_t x86_clflush_size = 0; 1117c478bd9Sstevel@tonic-gate 1127c478bd9Sstevel@tonic-gate uint_t pentiumpro_bug4046376; 1137c478bd9Sstevel@tonic-gate uint_t pentiumpro_bug4064495; 1147c478bd9Sstevel@tonic-gate 1157c478bd9Sstevel@tonic-gate uint_t enable486; 1167c478bd9Sstevel@tonic-gate 1177c478bd9Sstevel@tonic-gate /* 118f98fbcecSbholler * monitor/mwait info. 1195b8a6efeSbholler * 1205b8a6efeSbholler * size_actual and buf_actual are the real address and size allocated to get 1215b8a6efeSbholler * proper mwait_buf alignement. buf_actual and size_actual should be passed 1225b8a6efeSbholler * to kmem_free(). Currently kmem_alloc() and mwait happen to both use 1235b8a6efeSbholler * processor cache-line alignment, but this is not guarantied in the furture. 124f98fbcecSbholler */ 125f98fbcecSbholler struct mwait_info { 126f98fbcecSbholler size_t mon_min; /* min size to avoid missed wakeups */ 127f98fbcecSbholler size_t mon_max; /* size to avoid false wakeups */ 1285b8a6efeSbholler size_t size_actual; /* size actually allocated */ 1295b8a6efeSbholler void *buf_actual; /* memory actually allocated */ 130f98fbcecSbholler uint32_t support; /* processor support of monitor/mwait */ 131f98fbcecSbholler }; 132f98fbcecSbholler 133f98fbcecSbholler /* 1347c478bd9Sstevel@tonic-gate * These constants determine how many of the elements of the 1357c478bd9Sstevel@tonic-gate * cpuid we cache in the cpuid_info data structure; the 1367c478bd9Sstevel@tonic-gate * remaining elements are accessible via the cpuid instruction. 1377c478bd9Sstevel@tonic-gate */ 1387c478bd9Sstevel@tonic-gate 1397c478bd9Sstevel@tonic-gate #define NMAX_CPI_STD 6 /* eax = 0 .. 5 */ 1407c478bd9Sstevel@tonic-gate #define NMAX_CPI_EXTD 9 /* eax = 0x80000000 .. 0x80000008 */ 1417c478bd9Sstevel@tonic-gate 1427c478bd9Sstevel@tonic-gate struct cpuid_info { 1437c478bd9Sstevel@tonic-gate uint_t cpi_pass; /* last pass completed */ 1447c478bd9Sstevel@tonic-gate /* 1457c478bd9Sstevel@tonic-gate * standard function information 1467c478bd9Sstevel@tonic-gate */ 1477c478bd9Sstevel@tonic-gate uint_t cpi_maxeax; /* fn 0: %eax */ 1487c478bd9Sstevel@tonic-gate char cpi_vendorstr[13]; /* fn 0: %ebx:%ecx:%edx */ 1497c478bd9Sstevel@tonic-gate uint_t cpi_vendor; /* enum of cpi_vendorstr */ 1507c478bd9Sstevel@tonic-gate 1517c478bd9Sstevel@tonic-gate uint_t cpi_family; /* fn 1: extended family */ 1527c478bd9Sstevel@tonic-gate uint_t cpi_model; /* fn 1: extended model */ 1537c478bd9Sstevel@tonic-gate uint_t cpi_step; /* fn 1: stepping */ 1547c478bd9Sstevel@tonic-gate chipid_t cpi_chipid; /* fn 1: %ebx: chip # on ht cpus */ 1557c478bd9Sstevel@tonic-gate uint_t cpi_brandid; /* fn 1: %ebx: brand ID */ 1567c478bd9Sstevel@tonic-gate int cpi_clogid; /* fn 1: %ebx: thread # */ 1578949bcd6Sandrei uint_t cpi_ncpu_per_chip; /* fn 1: %ebx: logical cpu count */ 1587c478bd9Sstevel@tonic-gate uint8_t cpi_cacheinfo[16]; /* fn 2: intel-style cache desc */ 1597c478bd9Sstevel@tonic-gate uint_t cpi_ncache; /* fn 2: number of elements */ 160d129bde2Sesaxe uint_t cpi_ncpu_shr_last_cache; /* fn 4: %eax: ncpus sharing cache */ 161d129bde2Sesaxe id_t cpi_last_lvl_cacheid; /* fn 4: %eax: derived cache id */ 162d129bde2Sesaxe uint_t cpi_std_4_size; /* fn 4: number of fn 4 elements */ 163d129bde2Sesaxe struct cpuid_regs **cpi_std_4; /* fn 4: %ecx == 0 .. fn4_size */ 1648949bcd6Sandrei struct cpuid_regs cpi_std[NMAX_CPI_STD]; /* 0 .. 5 */ 1657c478bd9Sstevel@tonic-gate /* 1667c478bd9Sstevel@tonic-gate * extended function information 1677c478bd9Sstevel@tonic-gate */ 1687c478bd9Sstevel@tonic-gate uint_t cpi_xmaxeax; /* fn 0x80000000: %eax */ 1697c478bd9Sstevel@tonic-gate char cpi_brandstr[49]; /* fn 0x8000000[234] */ 1707c478bd9Sstevel@tonic-gate uint8_t cpi_pabits; /* fn 0x80000006: %eax */ 1717c478bd9Sstevel@tonic-gate uint8_t cpi_vabits; /* fn 0x80000006: %eax */ 1728949bcd6Sandrei struct cpuid_regs cpi_extd[NMAX_CPI_EXTD]; /* 0x8000000[0-8] */ 17310569901Sgavinm id_t cpi_coreid; /* same coreid => strands share core */ 17410569901Sgavinm int cpi_pkgcoreid; /* core number within single package */ 1758949bcd6Sandrei uint_t cpi_ncore_per_chip; /* AMD: fn 0x80000008: %ecx[7-0] */ 1768949bcd6Sandrei /* Intel: fn 4: %eax[31-26] */ 1777c478bd9Sstevel@tonic-gate /* 1787c478bd9Sstevel@tonic-gate * supported feature information 1797c478bd9Sstevel@tonic-gate */ 180ae115bc7Smrj uint32_t cpi_support[5]; 1817c478bd9Sstevel@tonic-gate #define STD_EDX_FEATURES 0 1827c478bd9Sstevel@tonic-gate #define AMD_EDX_FEATURES 1 1837c478bd9Sstevel@tonic-gate #define TM_EDX_FEATURES 2 1847c478bd9Sstevel@tonic-gate #define STD_ECX_FEATURES 3 185ae115bc7Smrj #define AMD_ECX_FEATURES 4 1868a40a695Sgavinm /* 1878a40a695Sgavinm * Synthesized information, where known. 1888a40a695Sgavinm */ 1898a40a695Sgavinm uint32_t cpi_chiprev; /* See X86_CHIPREV_* in x86_archext.h */ 1908a40a695Sgavinm const char *cpi_chiprevstr; /* May be NULL if chiprev unknown */ 1918a40a695Sgavinm uint32_t cpi_socket; /* Chip package/socket type */ 192f98fbcecSbholler 193f98fbcecSbholler struct mwait_info cpi_mwait; /* fn 5: monitor/mwait info */ 194b6917abeSmishra uint32_t cpi_apicid; 1957c478bd9Sstevel@tonic-gate }; 1967c478bd9Sstevel@tonic-gate 1977c478bd9Sstevel@tonic-gate 1987c478bd9Sstevel@tonic-gate static struct cpuid_info cpuid_info0; 1997c478bd9Sstevel@tonic-gate 2007c478bd9Sstevel@tonic-gate /* 2017c478bd9Sstevel@tonic-gate * These bit fields are defined by the Intel Application Note AP-485 2027c478bd9Sstevel@tonic-gate * "Intel Processor Identification and the CPUID Instruction" 2037c478bd9Sstevel@tonic-gate */ 2047c478bd9Sstevel@tonic-gate #define CPI_FAMILY_XTD(cpi) BITX((cpi)->cpi_std[1].cp_eax, 27, 20) 2057c478bd9Sstevel@tonic-gate #define CPI_MODEL_XTD(cpi) BITX((cpi)->cpi_std[1].cp_eax, 19, 16) 2067c478bd9Sstevel@tonic-gate #define CPI_TYPE(cpi) BITX((cpi)->cpi_std[1].cp_eax, 13, 12) 2077c478bd9Sstevel@tonic-gate #define CPI_FAMILY(cpi) BITX((cpi)->cpi_std[1].cp_eax, 11, 8) 2087c478bd9Sstevel@tonic-gate #define CPI_STEP(cpi) BITX((cpi)->cpi_std[1].cp_eax, 3, 0) 2097c478bd9Sstevel@tonic-gate #define CPI_MODEL(cpi) BITX((cpi)->cpi_std[1].cp_eax, 7, 4) 2107c478bd9Sstevel@tonic-gate 2117c478bd9Sstevel@tonic-gate #define CPI_FEATURES_EDX(cpi) ((cpi)->cpi_std[1].cp_edx) 2127c478bd9Sstevel@tonic-gate #define CPI_FEATURES_ECX(cpi) ((cpi)->cpi_std[1].cp_ecx) 2137c478bd9Sstevel@tonic-gate #define CPI_FEATURES_XTD_EDX(cpi) ((cpi)->cpi_extd[1].cp_edx) 2147c478bd9Sstevel@tonic-gate #define CPI_FEATURES_XTD_ECX(cpi) ((cpi)->cpi_extd[1].cp_ecx) 2157c478bd9Sstevel@tonic-gate 2167c478bd9Sstevel@tonic-gate #define CPI_BRANDID(cpi) BITX((cpi)->cpi_std[1].cp_ebx, 7, 0) 2177c478bd9Sstevel@tonic-gate #define CPI_CHUNKS(cpi) BITX((cpi)->cpi_std[1].cp_ebx, 15, 7) 2187c478bd9Sstevel@tonic-gate #define CPI_CPU_COUNT(cpi) BITX((cpi)->cpi_std[1].cp_ebx, 23, 16) 2197c478bd9Sstevel@tonic-gate #define CPI_APIC_ID(cpi) BITX((cpi)->cpi_std[1].cp_ebx, 31, 24) 2207c478bd9Sstevel@tonic-gate 2217c478bd9Sstevel@tonic-gate #define CPI_MAXEAX_MAX 0x100 /* sanity control */ 2227c478bd9Sstevel@tonic-gate #define CPI_XMAXEAX_MAX 0x80000100 223d129bde2Sesaxe #define CPI_FN4_ECX_MAX 0x20 /* sanity: max fn 4 levels */ 224b6917abeSmishra #define CPI_FNB_ECX_MAX 0x20 /* sanity: max fn B levels */ 225d129bde2Sesaxe 226d129bde2Sesaxe /* 227d129bde2Sesaxe * Function 4 (Deterministic Cache Parameters) macros 228d129bde2Sesaxe * Defined by Intel Application Note AP-485 229d129bde2Sesaxe */ 230d129bde2Sesaxe #define CPI_NUM_CORES(regs) BITX((regs)->cp_eax, 31, 26) 231d129bde2Sesaxe #define CPI_NTHR_SHR_CACHE(regs) BITX((regs)->cp_eax, 25, 14) 232d129bde2Sesaxe #define CPI_FULL_ASSOC_CACHE(regs) BITX((regs)->cp_eax, 9, 9) 233d129bde2Sesaxe #define CPI_SELF_INIT_CACHE(regs) BITX((regs)->cp_eax, 8, 8) 234d129bde2Sesaxe #define CPI_CACHE_LVL(regs) BITX((regs)->cp_eax, 7, 5) 235d129bde2Sesaxe #define CPI_CACHE_TYPE(regs) BITX((regs)->cp_eax, 4, 0) 236b6917abeSmishra #define CPI_CPU_LEVEL_TYPE(regs) BITX((regs)->cp_ecx, 15, 8) 237d129bde2Sesaxe 238d129bde2Sesaxe #define CPI_CACHE_WAYS(regs) BITX((regs)->cp_ebx, 31, 22) 239d129bde2Sesaxe #define CPI_CACHE_PARTS(regs) BITX((regs)->cp_ebx, 21, 12) 240d129bde2Sesaxe #define CPI_CACHE_COH_LN_SZ(regs) BITX((regs)->cp_ebx, 11, 0) 241d129bde2Sesaxe 242d129bde2Sesaxe #define CPI_CACHE_SETS(regs) BITX((regs)->cp_ecx, 31, 0) 243d129bde2Sesaxe 244d129bde2Sesaxe #define CPI_PREFCH_STRIDE(regs) BITX((regs)->cp_edx, 9, 0) 245d129bde2Sesaxe 2467c478bd9Sstevel@tonic-gate 2477c478bd9Sstevel@tonic-gate /* 2485ff02082Sdmick * A couple of shorthand macros to identify "later" P6-family chips 2495ff02082Sdmick * like the Pentium M and Core. First, the "older" P6-based stuff 2505ff02082Sdmick * (loosely defined as "pre-Pentium-4"): 2515ff02082Sdmick * P6, PII, Mobile PII, PII Xeon, PIII, Mobile PIII, PIII Xeon 2525ff02082Sdmick */ 2535ff02082Sdmick 2545ff02082Sdmick #define IS_LEGACY_P6(cpi) ( \ 2555ff02082Sdmick cpi->cpi_family == 6 && \ 2565ff02082Sdmick (cpi->cpi_model == 1 || \ 2575ff02082Sdmick cpi->cpi_model == 3 || \ 2585ff02082Sdmick cpi->cpi_model == 5 || \ 2595ff02082Sdmick cpi->cpi_model == 6 || \ 2605ff02082Sdmick cpi->cpi_model == 7 || \ 2615ff02082Sdmick cpi->cpi_model == 8 || \ 2625ff02082Sdmick cpi->cpi_model == 0xA || \ 2635ff02082Sdmick cpi->cpi_model == 0xB) \ 2645ff02082Sdmick ) 2655ff02082Sdmick 2665ff02082Sdmick /* A "new F6" is everything with family 6 that's not the above */ 2675ff02082Sdmick #define IS_NEW_F6(cpi) ((cpi->cpi_family == 6) && !IS_LEGACY_P6(cpi)) 2685ff02082Sdmick 269bf91205bSksadhukh /* Extended family/model support */ 270bf91205bSksadhukh #define IS_EXTENDED_MODEL_INTEL(cpi) (cpi->cpi_family == 0x6 || \ 271bf91205bSksadhukh cpi->cpi_family >= 0xf) 272bf91205bSksadhukh 2735ff02082Sdmick /* 274f98fbcecSbholler * Info for monitor/mwait idle loop. 275f98fbcecSbholler * 276f98fbcecSbholler * See cpuid section of "Intel 64 and IA-32 Architectures Software Developer's 277f98fbcecSbholler * Manual Volume 2A: Instruction Set Reference, A-M" #25366-022US, November 278f98fbcecSbholler * 2006. 279f98fbcecSbholler * See MONITOR/MWAIT section of "AMD64 Architecture Programmer's Manual 280f98fbcecSbholler * Documentation Updates" #33633, Rev 2.05, December 2006. 281f98fbcecSbholler */ 282f98fbcecSbholler #define MWAIT_SUPPORT (0x00000001) /* mwait supported */ 283f98fbcecSbholler #define MWAIT_EXTENSIONS (0x00000002) /* extenstion supported */ 284f98fbcecSbholler #define MWAIT_ECX_INT_ENABLE (0x00000004) /* ecx 1 extension supported */ 285f98fbcecSbholler #define MWAIT_SUPPORTED(cpi) ((cpi)->cpi_std[1].cp_ecx & CPUID_INTC_ECX_MON) 286f98fbcecSbholler #define MWAIT_INT_ENABLE(cpi) ((cpi)->cpi_std[5].cp_ecx & 0x2) 287f98fbcecSbholler #define MWAIT_EXTENSION(cpi) ((cpi)->cpi_std[5].cp_ecx & 0x1) 288f98fbcecSbholler #define MWAIT_SIZE_MIN(cpi) BITX((cpi)->cpi_std[5].cp_eax, 15, 0) 289f98fbcecSbholler #define MWAIT_SIZE_MAX(cpi) BITX((cpi)->cpi_std[5].cp_ebx, 15, 0) 290f98fbcecSbholler /* 291f98fbcecSbholler * Number of sub-cstates for a given c-state. 292f98fbcecSbholler */ 293f98fbcecSbholler #define MWAIT_NUM_SUBC_STATES(cpi, c_state) \ 294f98fbcecSbholler BITX((cpi)->cpi_std[5].cp_edx, c_state + 3, c_state) 295f98fbcecSbholler 2968a40a695Sgavinm /* 297e4b86885SCheng Sean Ye * Functions we consune from cpuid_subr.c; don't publish these in a header 298e4b86885SCheng Sean Ye * file to try and keep people using the expected cpuid_* interfaces. 2998a40a695Sgavinm */ 300e4b86885SCheng Sean Ye extern uint32_t _cpuid_skt(uint_t, uint_t, uint_t, uint_t); 301e4b86885SCheng Sean Ye extern uint32_t _cpuid_chiprev(uint_t, uint_t, uint_t, uint_t); 302e4b86885SCheng Sean Ye extern const char *_cpuid_chiprevstr(uint_t, uint_t, uint_t, uint_t); 303e4b86885SCheng Sean Ye extern uint_t _cpuid_vendorstr_to_vendorcode(char *); 3048a40a695Sgavinm 3058a40a695Sgavinm /* 306ae115bc7Smrj * Apply up various platform-dependent restrictions where the 307ae115bc7Smrj * underlying platform restrictions mean the CPU can be marked 308ae115bc7Smrj * as less capable than its cpuid instruction would imply. 309ae115bc7Smrj */ 310843e1988Sjohnlev #if defined(__xpv) 311843e1988Sjohnlev static void 312843e1988Sjohnlev platform_cpuid_mangle(uint_t vendor, uint32_t eax, struct cpuid_regs *cp) 313843e1988Sjohnlev { 314843e1988Sjohnlev switch (eax) { 315e4b86885SCheng Sean Ye case 1: { 316e4b86885SCheng Sean Ye uint32_t mcamask = DOMAIN_IS_INITDOMAIN(xen_info) ? 317e4b86885SCheng Sean Ye 0 : CPUID_INTC_EDX_MCA; 318843e1988Sjohnlev cp->cp_edx &= 319e4b86885SCheng Sean Ye ~(mcamask | 320e4b86885SCheng Sean Ye CPUID_INTC_EDX_PSE | 321843e1988Sjohnlev CPUID_INTC_EDX_VME | CPUID_INTC_EDX_DE | 322843e1988Sjohnlev CPUID_INTC_EDX_SEP | CPUID_INTC_EDX_MTRR | 323843e1988Sjohnlev CPUID_INTC_EDX_PGE | CPUID_INTC_EDX_PAT | 324843e1988Sjohnlev CPUID_AMD_EDX_SYSC | CPUID_INTC_EDX_SEP | 325843e1988Sjohnlev CPUID_INTC_EDX_PSE36 | CPUID_INTC_EDX_HTT); 326843e1988Sjohnlev break; 327e4b86885SCheng Sean Ye } 328ae115bc7Smrj 329843e1988Sjohnlev case 0x80000001: 330843e1988Sjohnlev cp->cp_edx &= 331843e1988Sjohnlev ~(CPUID_AMD_EDX_PSE | 332843e1988Sjohnlev CPUID_INTC_EDX_VME | CPUID_INTC_EDX_DE | 333843e1988Sjohnlev CPUID_AMD_EDX_MTRR | CPUID_AMD_EDX_PGE | 334843e1988Sjohnlev CPUID_AMD_EDX_PAT | CPUID_AMD_EDX_PSE36 | 335843e1988Sjohnlev CPUID_AMD_EDX_SYSC | CPUID_INTC_EDX_SEP | 336843e1988Sjohnlev CPUID_AMD_EDX_TSCP); 337843e1988Sjohnlev cp->cp_ecx &= ~CPUID_AMD_ECX_CMP_LGCY; 338843e1988Sjohnlev break; 339843e1988Sjohnlev default: 340843e1988Sjohnlev break; 341843e1988Sjohnlev } 342843e1988Sjohnlev 343843e1988Sjohnlev switch (vendor) { 344843e1988Sjohnlev case X86_VENDOR_Intel: 345843e1988Sjohnlev switch (eax) { 346843e1988Sjohnlev case 4: 347843e1988Sjohnlev /* 348843e1988Sjohnlev * Zero out the (ncores-per-chip - 1) field 349843e1988Sjohnlev */ 350843e1988Sjohnlev cp->cp_eax &= 0x03fffffff; 351843e1988Sjohnlev break; 352843e1988Sjohnlev default: 353843e1988Sjohnlev break; 354843e1988Sjohnlev } 355843e1988Sjohnlev break; 356843e1988Sjohnlev case X86_VENDOR_AMD: 357843e1988Sjohnlev switch (eax) { 358843e1988Sjohnlev case 0x80000008: 359843e1988Sjohnlev /* 360843e1988Sjohnlev * Zero out the (ncores-per-chip - 1) field 361843e1988Sjohnlev */ 362843e1988Sjohnlev cp->cp_ecx &= 0xffffff00; 363843e1988Sjohnlev break; 364843e1988Sjohnlev default: 365843e1988Sjohnlev break; 366843e1988Sjohnlev } 367843e1988Sjohnlev break; 368843e1988Sjohnlev default: 369843e1988Sjohnlev break; 370843e1988Sjohnlev } 371843e1988Sjohnlev } 372843e1988Sjohnlev #else 373ae115bc7Smrj #define platform_cpuid_mangle(vendor, eax, cp) /* nothing */ 374843e1988Sjohnlev #endif 375ae115bc7Smrj 376ae115bc7Smrj /* 3777c478bd9Sstevel@tonic-gate * Some undocumented ways of patching the results of the cpuid 3787c478bd9Sstevel@tonic-gate * instruction to permit running Solaris 10 on future cpus that 3797c478bd9Sstevel@tonic-gate * we don't currently support. Could be set to non-zero values 3807c478bd9Sstevel@tonic-gate * via settings in eeprom. 3817c478bd9Sstevel@tonic-gate */ 3827c478bd9Sstevel@tonic-gate 3837c478bd9Sstevel@tonic-gate uint32_t cpuid_feature_ecx_include; 3847c478bd9Sstevel@tonic-gate uint32_t cpuid_feature_ecx_exclude; 3857c478bd9Sstevel@tonic-gate uint32_t cpuid_feature_edx_include; 3867c478bd9Sstevel@tonic-gate uint32_t cpuid_feature_edx_exclude; 3877c478bd9Sstevel@tonic-gate 388ae115bc7Smrj void 389ae115bc7Smrj cpuid_alloc_space(cpu_t *cpu) 390ae115bc7Smrj { 391ae115bc7Smrj /* 392ae115bc7Smrj * By convention, cpu0 is the boot cpu, which is set up 393ae115bc7Smrj * before memory allocation is available. All other cpus get 394ae115bc7Smrj * their cpuid_info struct allocated here. 395ae115bc7Smrj */ 396ae115bc7Smrj ASSERT(cpu->cpu_id != 0); 397ae115bc7Smrj cpu->cpu_m.mcpu_cpi = 398ae115bc7Smrj kmem_zalloc(sizeof (*cpu->cpu_m.mcpu_cpi), KM_SLEEP); 399ae115bc7Smrj } 400ae115bc7Smrj 401ae115bc7Smrj void 402ae115bc7Smrj cpuid_free_space(cpu_t *cpu) 403ae115bc7Smrj { 404d129bde2Sesaxe struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 405d129bde2Sesaxe int i; 406d129bde2Sesaxe 407ae115bc7Smrj ASSERT(cpu->cpu_id != 0); 408d129bde2Sesaxe 409d129bde2Sesaxe /* 410d129bde2Sesaxe * Free up any function 4 related dynamic storage 411d129bde2Sesaxe */ 412d129bde2Sesaxe for (i = 1; i < cpi->cpi_std_4_size; i++) 413d129bde2Sesaxe kmem_free(cpi->cpi_std_4[i], sizeof (struct cpuid_regs)); 414d129bde2Sesaxe if (cpi->cpi_std_4_size > 0) 415d129bde2Sesaxe kmem_free(cpi->cpi_std_4, 416d129bde2Sesaxe cpi->cpi_std_4_size * sizeof (struct cpuid_regs *)); 417d129bde2Sesaxe 418ae115bc7Smrj kmem_free(cpu->cpu_m.mcpu_cpi, sizeof (*cpu->cpu_m.mcpu_cpi)); 419ae115bc7Smrj } 420ae115bc7Smrj 421551bc2a6Smrj #if !defined(__xpv) 422551bc2a6Smrj 423551bc2a6Smrj static void 424551bc2a6Smrj check_for_hvm() 425551bc2a6Smrj { 426551bc2a6Smrj struct cpuid_regs cp; 427551bc2a6Smrj char *xen_str; 428551bc2a6Smrj uint32_t xen_signature[4]; 429551bc2a6Smrj extern int xpv_is_hvm; 430551bc2a6Smrj 431551bc2a6Smrj /* 432551bc2a6Smrj * In a fully virtualized domain, Xen's pseudo-cpuid function 433551bc2a6Smrj * 0x40000000 returns a string representing the Xen signature in 434551bc2a6Smrj * %ebx, %ecx, and %edx. %eax contains the maximum supported cpuid 435551bc2a6Smrj * function. 436551bc2a6Smrj */ 437551bc2a6Smrj cp.cp_eax = 0x40000000; 438551bc2a6Smrj (void) __cpuid_insn(&cp); 439551bc2a6Smrj xen_signature[0] = cp.cp_ebx; 440551bc2a6Smrj xen_signature[1] = cp.cp_ecx; 441551bc2a6Smrj xen_signature[2] = cp.cp_edx; 442551bc2a6Smrj xen_signature[3] = 0; 443551bc2a6Smrj xen_str = (char *)xen_signature; 444551bc2a6Smrj if (strcmp("XenVMMXenVMM", xen_str) == 0 && cp.cp_eax <= 0x40000002) 445551bc2a6Smrj xpv_is_hvm = 1; 446551bc2a6Smrj } 447551bc2a6Smrj #endif /* __xpv */ 448551bc2a6Smrj 4497c478bd9Sstevel@tonic-gate uint_t 4507c478bd9Sstevel@tonic-gate cpuid_pass1(cpu_t *cpu) 4517c478bd9Sstevel@tonic-gate { 4527c478bd9Sstevel@tonic-gate uint32_t mask_ecx, mask_edx; 4537c478bd9Sstevel@tonic-gate uint_t feature = X86_CPUID; 4547c478bd9Sstevel@tonic-gate struct cpuid_info *cpi; 4558949bcd6Sandrei struct cpuid_regs *cp; 4567c478bd9Sstevel@tonic-gate int xcpuid; 457843e1988Sjohnlev #if !defined(__xpv) 4585b8a6efeSbholler extern int idle_cpu_prefer_mwait; 459843e1988Sjohnlev #endif 460ae115bc7Smrj 4617c478bd9Sstevel@tonic-gate /* 462ae115bc7Smrj * Space statically allocated for cpu0, ensure pointer is set 4637c478bd9Sstevel@tonic-gate */ 4647c478bd9Sstevel@tonic-gate if (cpu->cpu_id == 0) 465ae115bc7Smrj cpu->cpu_m.mcpu_cpi = &cpuid_info0; 466ae115bc7Smrj cpi = cpu->cpu_m.mcpu_cpi; 467ae115bc7Smrj ASSERT(cpi != NULL); 4687c478bd9Sstevel@tonic-gate cp = &cpi->cpi_std[0]; 4698949bcd6Sandrei cp->cp_eax = 0; 4708949bcd6Sandrei cpi->cpi_maxeax = __cpuid_insn(cp); 4717c478bd9Sstevel@tonic-gate { 4727c478bd9Sstevel@tonic-gate uint32_t *iptr = (uint32_t *)cpi->cpi_vendorstr; 4737c478bd9Sstevel@tonic-gate *iptr++ = cp->cp_ebx; 4747c478bd9Sstevel@tonic-gate *iptr++ = cp->cp_edx; 4757c478bd9Sstevel@tonic-gate *iptr++ = cp->cp_ecx; 4767c478bd9Sstevel@tonic-gate *(char *)&cpi->cpi_vendorstr[12] = '\0'; 4777c478bd9Sstevel@tonic-gate } 4787c478bd9Sstevel@tonic-gate 479e4b86885SCheng Sean Ye cpi->cpi_vendor = _cpuid_vendorstr_to_vendorcode(cpi->cpi_vendorstr); 4807c478bd9Sstevel@tonic-gate x86_vendor = cpi->cpi_vendor; /* for compatibility */ 4817c478bd9Sstevel@tonic-gate 4827c478bd9Sstevel@tonic-gate /* 4837c478bd9Sstevel@tonic-gate * Limit the range in case of weird hardware 4847c478bd9Sstevel@tonic-gate */ 4857c478bd9Sstevel@tonic-gate if (cpi->cpi_maxeax > CPI_MAXEAX_MAX) 4867c478bd9Sstevel@tonic-gate cpi->cpi_maxeax = CPI_MAXEAX_MAX; 4877c478bd9Sstevel@tonic-gate if (cpi->cpi_maxeax < 1) 4887c478bd9Sstevel@tonic-gate goto pass1_done; 4897c478bd9Sstevel@tonic-gate 4907c478bd9Sstevel@tonic-gate cp = &cpi->cpi_std[1]; 4918949bcd6Sandrei cp->cp_eax = 1; 4928949bcd6Sandrei (void) __cpuid_insn(cp); 4937c478bd9Sstevel@tonic-gate 4947c478bd9Sstevel@tonic-gate /* 4957c478bd9Sstevel@tonic-gate * Extract identifying constants for easy access. 4967c478bd9Sstevel@tonic-gate */ 4977c478bd9Sstevel@tonic-gate cpi->cpi_model = CPI_MODEL(cpi); 4987c478bd9Sstevel@tonic-gate cpi->cpi_family = CPI_FAMILY(cpi); 4997c478bd9Sstevel@tonic-gate 5005ff02082Sdmick if (cpi->cpi_family == 0xf) 5017c478bd9Sstevel@tonic-gate cpi->cpi_family += CPI_FAMILY_XTD(cpi); 5025ff02082Sdmick 50368c91426Sdmick /* 504875b116eSkchow * Beware: AMD uses "extended model" iff base *FAMILY* == 0xf. 50568c91426Sdmick * Intel, and presumably everyone else, uses model == 0xf, as 50668c91426Sdmick * one would expect (max value means possible overflow). Sigh. 50768c91426Sdmick */ 50868c91426Sdmick 50968c91426Sdmick switch (cpi->cpi_vendor) { 510bf91205bSksadhukh case X86_VENDOR_Intel: 511bf91205bSksadhukh if (IS_EXTENDED_MODEL_INTEL(cpi)) 512bf91205bSksadhukh cpi->cpi_model += CPI_MODEL_XTD(cpi) << 4; 513447af253Sksadhukh break; 51468c91426Sdmick case X86_VENDOR_AMD: 515875b116eSkchow if (CPI_FAMILY(cpi) == 0xf) 51668c91426Sdmick cpi->cpi_model += CPI_MODEL_XTD(cpi) << 4; 51768c91426Sdmick break; 51868c91426Sdmick default: 5195ff02082Sdmick if (cpi->cpi_model == 0xf) 5207c478bd9Sstevel@tonic-gate cpi->cpi_model += CPI_MODEL_XTD(cpi) << 4; 52168c91426Sdmick break; 52268c91426Sdmick } 5237c478bd9Sstevel@tonic-gate 5247c478bd9Sstevel@tonic-gate cpi->cpi_step = CPI_STEP(cpi); 5257c478bd9Sstevel@tonic-gate cpi->cpi_brandid = CPI_BRANDID(cpi); 5267c478bd9Sstevel@tonic-gate 5277c478bd9Sstevel@tonic-gate /* 5287c478bd9Sstevel@tonic-gate * *default* assumptions: 5297c478bd9Sstevel@tonic-gate * - believe %edx feature word 5307c478bd9Sstevel@tonic-gate * - ignore %ecx feature word 5317c478bd9Sstevel@tonic-gate * - 32-bit virtual and physical addressing 5327c478bd9Sstevel@tonic-gate */ 5337c478bd9Sstevel@tonic-gate mask_edx = 0xffffffff; 5347c478bd9Sstevel@tonic-gate mask_ecx = 0; 5357c478bd9Sstevel@tonic-gate 5367c478bd9Sstevel@tonic-gate cpi->cpi_pabits = cpi->cpi_vabits = 32; 5377c478bd9Sstevel@tonic-gate 5387c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 5397c478bd9Sstevel@tonic-gate case X86_VENDOR_Intel: 5407c478bd9Sstevel@tonic-gate if (cpi->cpi_family == 5) 5417c478bd9Sstevel@tonic-gate x86_type = X86_TYPE_P5; 5425ff02082Sdmick else if (IS_LEGACY_P6(cpi)) { 5437c478bd9Sstevel@tonic-gate x86_type = X86_TYPE_P6; 5447c478bd9Sstevel@tonic-gate pentiumpro_bug4046376 = 1; 5457c478bd9Sstevel@tonic-gate pentiumpro_bug4064495 = 1; 5467c478bd9Sstevel@tonic-gate /* 5477c478bd9Sstevel@tonic-gate * Clear the SEP bit when it was set erroneously 5487c478bd9Sstevel@tonic-gate */ 5497c478bd9Sstevel@tonic-gate if (cpi->cpi_model < 3 && cpi->cpi_step < 3) 5507c478bd9Sstevel@tonic-gate cp->cp_edx &= ~CPUID_INTC_EDX_SEP; 5515ff02082Sdmick } else if (IS_NEW_F6(cpi) || cpi->cpi_family == 0xf) { 5527c478bd9Sstevel@tonic-gate x86_type = X86_TYPE_P4; 5537c478bd9Sstevel@tonic-gate /* 5547c478bd9Sstevel@tonic-gate * We don't currently depend on any of the %ecx 5557c478bd9Sstevel@tonic-gate * features until Prescott, so we'll only check 5567c478bd9Sstevel@tonic-gate * this from P4 onwards. We might want to revisit 5577c478bd9Sstevel@tonic-gate * that idea later. 5587c478bd9Sstevel@tonic-gate */ 5597c478bd9Sstevel@tonic-gate mask_ecx = 0xffffffff; 5607c478bd9Sstevel@tonic-gate } else if (cpi->cpi_family > 0xf) 5617c478bd9Sstevel@tonic-gate mask_ecx = 0xffffffff; 5627c622d23Sbholler /* 5637c622d23Sbholler * We don't support MONITOR/MWAIT if leaf 5 is not available 5647c622d23Sbholler * to obtain the monitor linesize. 5657c622d23Sbholler */ 5667c622d23Sbholler if (cpi->cpi_maxeax < 5) 5677c622d23Sbholler mask_ecx &= ~CPUID_INTC_ECX_MON; 5687c478bd9Sstevel@tonic-gate break; 5697c478bd9Sstevel@tonic-gate case X86_VENDOR_IntelClone: 5707c478bd9Sstevel@tonic-gate default: 5717c478bd9Sstevel@tonic-gate break; 5727c478bd9Sstevel@tonic-gate case X86_VENDOR_AMD: 5737c478bd9Sstevel@tonic-gate #if defined(OPTERON_ERRATUM_108) 5747c478bd9Sstevel@tonic-gate if (cpi->cpi_family == 0xf && cpi->cpi_model == 0xe) { 5757c478bd9Sstevel@tonic-gate cp->cp_eax = (0xf0f & cp->cp_eax) | 0xc0; 5767c478bd9Sstevel@tonic-gate cpi->cpi_model = 0xc; 5777c478bd9Sstevel@tonic-gate } else 5787c478bd9Sstevel@tonic-gate #endif 5797c478bd9Sstevel@tonic-gate if (cpi->cpi_family == 5) { 5807c478bd9Sstevel@tonic-gate /* 5817c478bd9Sstevel@tonic-gate * AMD K5 and K6 5827c478bd9Sstevel@tonic-gate * 5837c478bd9Sstevel@tonic-gate * These CPUs have an incomplete implementation 5847c478bd9Sstevel@tonic-gate * of MCA/MCE which we mask away. 5857c478bd9Sstevel@tonic-gate */ 5868949bcd6Sandrei mask_edx &= ~(CPUID_INTC_EDX_MCE | CPUID_INTC_EDX_MCA); 5878949bcd6Sandrei 5887c478bd9Sstevel@tonic-gate /* 5897c478bd9Sstevel@tonic-gate * Model 0 uses the wrong (APIC) bit 5907c478bd9Sstevel@tonic-gate * to indicate PGE. Fix it here. 5917c478bd9Sstevel@tonic-gate */ 5928949bcd6Sandrei if (cpi->cpi_model == 0) { 5937c478bd9Sstevel@tonic-gate if (cp->cp_edx & 0x200) { 5947c478bd9Sstevel@tonic-gate cp->cp_edx &= ~0x200; 5957c478bd9Sstevel@tonic-gate cp->cp_edx |= CPUID_INTC_EDX_PGE; 5967c478bd9Sstevel@tonic-gate } 5977c478bd9Sstevel@tonic-gate } 5988949bcd6Sandrei 5998949bcd6Sandrei /* 6008949bcd6Sandrei * Early models had problems w/ MMX; disable. 6018949bcd6Sandrei */ 6028949bcd6Sandrei if (cpi->cpi_model < 6) 6038949bcd6Sandrei mask_edx &= ~CPUID_INTC_EDX_MMX; 6048949bcd6Sandrei } 6058949bcd6Sandrei 6068949bcd6Sandrei /* 6078949bcd6Sandrei * For newer families, SSE3 and CX16, at least, are valid; 6088949bcd6Sandrei * enable all 6098949bcd6Sandrei */ 6108949bcd6Sandrei if (cpi->cpi_family >= 0xf) 6118949bcd6Sandrei mask_ecx = 0xffffffff; 6127c622d23Sbholler /* 6137c622d23Sbholler * We don't support MONITOR/MWAIT if leaf 5 is not available 6147c622d23Sbholler * to obtain the monitor linesize. 6157c622d23Sbholler */ 6167c622d23Sbholler if (cpi->cpi_maxeax < 5) 6177c622d23Sbholler mask_ecx &= ~CPUID_INTC_ECX_MON; 6185b8a6efeSbholler 619843e1988Sjohnlev #if !defined(__xpv) 6205b8a6efeSbholler /* 6215b8a6efeSbholler * Do not use MONITOR/MWAIT to halt in the idle loop on any AMD 6225b8a6efeSbholler * processors. AMD does not intend MWAIT to be used in the cpu 6235b8a6efeSbholler * idle loop on current and future processors. 10h and future 6245b8a6efeSbholler * AMD processors use more power in MWAIT than HLT. 6255b8a6efeSbholler * Pre-family-10h Opterons do not have the MWAIT instruction. 6265b8a6efeSbholler */ 6275b8a6efeSbholler idle_cpu_prefer_mwait = 0; 628843e1988Sjohnlev #endif 6295b8a6efeSbholler 6307c478bd9Sstevel@tonic-gate break; 6317c478bd9Sstevel@tonic-gate case X86_VENDOR_TM: 6327c478bd9Sstevel@tonic-gate /* 6337c478bd9Sstevel@tonic-gate * workaround the NT workaround in CMS 4.1 6347c478bd9Sstevel@tonic-gate */ 6357c478bd9Sstevel@tonic-gate if (cpi->cpi_family == 5 && cpi->cpi_model == 4 && 6367c478bd9Sstevel@tonic-gate (cpi->cpi_step == 2 || cpi->cpi_step == 3)) 6377c478bd9Sstevel@tonic-gate cp->cp_edx |= CPUID_INTC_EDX_CX8; 6387c478bd9Sstevel@tonic-gate break; 6397c478bd9Sstevel@tonic-gate case X86_VENDOR_Centaur: 6407c478bd9Sstevel@tonic-gate /* 6417c478bd9Sstevel@tonic-gate * workaround the NT workarounds again 6427c478bd9Sstevel@tonic-gate */ 6437c478bd9Sstevel@tonic-gate if (cpi->cpi_family == 6) 6447c478bd9Sstevel@tonic-gate cp->cp_edx |= CPUID_INTC_EDX_CX8; 6457c478bd9Sstevel@tonic-gate break; 6467c478bd9Sstevel@tonic-gate case X86_VENDOR_Cyrix: 6477c478bd9Sstevel@tonic-gate /* 6487c478bd9Sstevel@tonic-gate * We rely heavily on the probing in locore 6497c478bd9Sstevel@tonic-gate * to actually figure out what parts, if any, 6507c478bd9Sstevel@tonic-gate * of the Cyrix cpuid instruction to believe. 6517c478bd9Sstevel@tonic-gate */ 6527c478bd9Sstevel@tonic-gate switch (x86_type) { 6537c478bd9Sstevel@tonic-gate case X86_TYPE_CYRIX_486: 6547c478bd9Sstevel@tonic-gate mask_edx = 0; 6557c478bd9Sstevel@tonic-gate break; 6567c478bd9Sstevel@tonic-gate case X86_TYPE_CYRIX_6x86: 6577c478bd9Sstevel@tonic-gate mask_edx = 0; 6587c478bd9Sstevel@tonic-gate break; 6597c478bd9Sstevel@tonic-gate case X86_TYPE_CYRIX_6x86L: 6607c478bd9Sstevel@tonic-gate mask_edx = 6617c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_DE | 6627c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_CX8; 6637c478bd9Sstevel@tonic-gate break; 6647c478bd9Sstevel@tonic-gate case X86_TYPE_CYRIX_6x86MX: 6657c478bd9Sstevel@tonic-gate mask_edx = 6667c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_DE | 6677c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_MSR | 6687c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_CX8 | 6697c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_PGE | 6707c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_CMOV | 6717c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_MMX; 6727c478bd9Sstevel@tonic-gate break; 6737c478bd9Sstevel@tonic-gate case X86_TYPE_CYRIX_GXm: 6747c478bd9Sstevel@tonic-gate mask_edx = 6757c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_MSR | 6767c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_CX8 | 6777c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_CMOV | 6787c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_MMX; 6797c478bd9Sstevel@tonic-gate break; 6807c478bd9Sstevel@tonic-gate case X86_TYPE_CYRIX_MediaGX: 6817c478bd9Sstevel@tonic-gate break; 6827c478bd9Sstevel@tonic-gate case X86_TYPE_CYRIX_MII: 6837c478bd9Sstevel@tonic-gate case X86_TYPE_VIA_CYRIX_III: 6847c478bd9Sstevel@tonic-gate mask_edx = 6857c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_DE | 6867c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_TSC | 6877c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_MSR | 6887c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_CX8 | 6897c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_PGE | 6907c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_CMOV | 6917c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_MMX; 6927c478bd9Sstevel@tonic-gate break; 6937c478bd9Sstevel@tonic-gate default: 6947c478bd9Sstevel@tonic-gate break; 6957c478bd9Sstevel@tonic-gate } 6967c478bd9Sstevel@tonic-gate break; 6977c478bd9Sstevel@tonic-gate } 6987c478bd9Sstevel@tonic-gate 699843e1988Sjohnlev #if defined(__xpv) 700843e1988Sjohnlev /* 701843e1988Sjohnlev * Do not support MONITOR/MWAIT under a hypervisor 702843e1988Sjohnlev */ 703843e1988Sjohnlev mask_ecx &= ~CPUID_INTC_ECX_MON; 704843e1988Sjohnlev #endif /* __xpv */ 705843e1988Sjohnlev 7067c478bd9Sstevel@tonic-gate /* 7077c478bd9Sstevel@tonic-gate * Now we've figured out the masks that determine 7087c478bd9Sstevel@tonic-gate * which bits we choose to believe, apply the masks 7097c478bd9Sstevel@tonic-gate * to the feature words, then map the kernel's view 7107c478bd9Sstevel@tonic-gate * of these feature words into its feature word. 7117c478bd9Sstevel@tonic-gate */ 7127c478bd9Sstevel@tonic-gate cp->cp_edx &= mask_edx; 7137c478bd9Sstevel@tonic-gate cp->cp_ecx &= mask_ecx; 7147c478bd9Sstevel@tonic-gate 7157c478bd9Sstevel@tonic-gate /* 716ae115bc7Smrj * apply any platform restrictions (we don't call this 717ae115bc7Smrj * immediately after __cpuid_insn here, because we need the 718ae115bc7Smrj * workarounds applied above first) 7197c478bd9Sstevel@tonic-gate */ 720ae115bc7Smrj platform_cpuid_mangle(cpi->cpi_vendor, 1, cp); 7217c478bd9Sstevel@tonic-gate 722ae115bc7Smrj /* 723ae115bc7Smrj * fold in overrides from the "eeprom" mechanism 724ae115bc7Smrj */ 7257c478bd9Sstevel@tonic-gate cp->cp_edx |= cpuid_feature_edx_include; 7267c478bd9Sstevel@tonic-gate cp->cp_edx &= ~cpuid_feature_edx_exclude; 7277c478bd9Sstevel@tonic-gate 7287c478bd9Sstevel@tonic-gate cp->cp_ecx |= cpuid_feature_ecx_include; 7297c478bd9Sstevel@tonic-gate cp->cp_ecx &= ~cpuid_feature_ecx_exclude; 7307c478bd9Sstevel@tonic-gate 7317c478bd9Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_PSE) 7327c478bd9Sstevel@tonic-gate feature |= X86_LARGEPAGE; 7337c478bd9Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_TSC) 7347c478bd9Sstevel@tonic-gate feature |= X86_TSC; 7357c478bd9Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_MSR) 7367c478bd9Sstevel@tonic-gate feature |= X86_MSR; 7377c478bd9Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_MTRR) 7387c478bd9Sstevel@tonic-gate feature |= X86_MTRR; 7397c478bd9Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_PGE) 7407c478bd9Sstevel@tonic-gate feature |= X86_PGE; 7417c478bd9Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_CMOV) 7427c478bd9Sstevel@tonic-gate feature |= X86_CMOV; 7437c478bd9Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_MMX) 7447c478bd9Sstevel@tonic-gate feature |= X86_MMX; 7457c478bd9Sstevel@tonic-gate if ((cp->cp_edx & CPUID_INTC_EDX_MCE) != 0 && 7467c478bd9Sstevel@tonic-gate (cp->cp_edx & CPUID_INTC_EDX_MCA) != 0) 7477c478bd9Sstevel@tonic-gate feature |= X86_MCA; 7487c478bd9Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_PAE) 7497c478bd9Sstevel@tonic-gate feature |= X86_PAE; 7507c478bd9Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_CX8) 7517c478bd9Sstevel@tonic-gate feature |= X86_CX8; 7527c478bd9Sstevel@tonic-gate if (cp->cp_ecx & CPUID_INTC_ECX_CX16) 7537c478bd9Sstevel@tonic-gate feature |= X86_CX16; 7547c478bd9Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_PAT) 7557c478bd9Sstevel@tonic-gate feature |= X86_PAT; 7567c478bd9Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_SEP) 7577c478bd9Sstevel@tonic-gate feature |= X86_SEP; 7587c478bd9Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_FXSR) { 7597c478bd9Sstevel@tonic-gate /* 7607c478bd9Sstevel@tonic-gate * In our implementation, fxsave/fxrstor 7617c478bd9Sstevel@tonic-gate * are prerequisites before we'll even 7627c478bd9Sstevel@tonic-gate * try and do SSE things. 7637c478bd9Sstevel@tonic-gate */ 7647c478bd9Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_SSE) 7657c478bd9Sstevel@tonic-gate feature |= X86_SSE; 7667c478bd9Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_SSE2) 7677c478bd9Sstevel@tonic-gate feature |= X86_SSE2; 7687c478bd9Sstevel@tonic-gate if (cp->cp_ecx & CPUID_INTC_ECX_SSE3) 7697c478bd9Sstevel@tonic-gate feature |= X86_SSE3; 770d0f8ff6eSkk208521 if (cpi->cpi_vendor == X86_VENDOR_Intel) { 771d0f8ff6eSkk208521 if (cp->cp_ecx & CPUID_INTC_ECX_SSSE3) 772d0f8ff6eSkk208521 feature |= X86_SSSE3; 773d0f8ff6eSkk208521 if (cp->cp_ecx & CPUID_INTC_ECX_SSE4_1) 774d0f8ff6eSkk208521 feature |= X86_SSE4_1; 775d0f8ff6eSkk208521 if (cp->cp_ecx & CPUID_INTC_ECX_SSE4_2) 776d0f8ff6eSkk208521 feature |= X86_SSE4_2; 777d0f8ff6eSkk208521 } 7787c478bd9Sstevel@tonic-gate } 7797c478bd9Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_DE) 780ae115bc7Smrj feature |= X86_DE; 7811d1a3942SBill Holler #if !defined(__xpv) 782f98fbcecSbholler if (cp->cp_ecx & CPUID_INTC_ECX_MON) { 7831d1a3942SBill Holler 7841d1a3942SBill Holler /* 7851d1a3942SBill Holler * We require the CLFLUSH instruction for erratum workaround 7861d1a3942SBill Holler * to use MONITOR/MWAIT. 7871d1a3942SBill Holler */ 7881d1a3942SBill Holler if (cp->cp_edx & CPUID_INTC_EDX_CLFSH) { 789f98fbcecSbholler cpi->cpi_mwait.support |= MWAIT_SUPPORT; 790f98fbcecSbholler feature |= X86_MWAIT; 7911d1a3942SBill Holler } else { 7921d1a3942SBill Holler extern int idle_cpu_assert_cflush_monitor; 7931d1a3942SBill Holler 7941d1a3942SBill Holler /* 7951d1a3942SBill Holler * All processors we are aware of which have 7961d1a3942SBill Holler * MONITOR/MWAIT also have CLFLUSH. 7971d1a3942SBill Holler */ 7981d1a3942SBill Holler if (idle_cpu_assert_cflush_monitor) { 7991d1a3942SBill Holler ASSERT((cp->cp_ecx & CPUID_INTC_ECX_MON) && 8001d1a3942SBill Holler (cp->cp_edx & CPUID_INTC_EDX_CLFSH)); 801f98fbcecSbholler } 8021d1a3942SBill Holler } 8031d1a3942SBill Holler } 8041d1a3942SBill Holler #endif /* __xpv */ 8057c478bd9Sstevel@tonic-gate 80686c1f4dcSVikram Hegde /* 80786c1f4dcSVikram Hegde * Only need it first time, rest of the cpus would follow suite. 80886c1f4dcSVikram Hegde * we only capture this for the bootcpu. 80986c1f4dcSVikram Hegde */ 81086c1f4dcSVikram Hegde if (cp->cp_edx & CPUID_INTC_EDX_CLFSH) { 81186c1f4dcSVikram Hegde feature |= X86_CLFSH; 81286c1f4dcSVikram Hegde x86_clflush_size = (BITX(cp->cp_ebx, 15, 8) * 8); 81386c1f4dcSVikram Hegde } 81486c1f4dcSVikram Hegde 8157c478bd9Sstevel@tonic-gate if (feature & X86_PAE) 8167c478bd9Sstevel@tonic-gate cpi->cpi_pabits = 36; 8177c478bd9Sstevel@tonic-gate 8187c478bd9Sstevel@tonic-gate /* 8197c478bd9Sstevel@tonic-gate * Hyperthreading configuration is slightly tricky on Intel 8207c478bd9Sstevel@tonic-gate * and pure clones, and even trickier on AMD. 8217c478bd9Sstevel@tonic-gate * 8227c478bd9Sstevel@tonic-gate * (AMD chose to set the HTT bit on their CMP processors, 8237c478bd9Sstevel@tonic-gate * even though they're not actually hyperthreaded. Thus it 8247c478bd9Sstevel@tonic-gate * takes a bit more work to figure out what's really going 825ae115bc7Smrj * on ... see the handling of the CMP_LGCY bit below) 8267c478bd9Sstevel@tonic-gate */ 8277c478bd9Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_HTT) { 8287c478bd9Sstevel@tonic-gate cpi->cpi_ncpu_per_chip = CPI_CPU_COUNT(cpi); 8297c478bd9Sstevel@tonic-gate if (cpi->cpi_ncpu_per_chip > 1) 8307c478bd9Sstevel@tonic-gate feature |= X86_HTT; 8318949bcd6Sandrei } else { 8328949bcd6Sandrei cpi->cpi_ncpu_per_chip = 1; 8337c478bd9Sstevel@tonic-gate } 8347c478bd9Sstevel@tonic-gate 8357c478bd9Sstevel@tonic-gate /* 8367c478bd9Sstevel@tonic-gate * Work on the "extended" feature information, doing 8377c478bd9Sstevel@tonic-gate * some basic initialization for cpuid_pass2() 8387c478bd9Sstevel@tonic-gate */ 8397c478bd9Sstevel@tonic-gate xcpuid = 0; 8407c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 8417c478bd9Sstevel@tonic-gate case X86_VENDOR_Intel: 8425ff02082Sdmick if (IS_NEW_F6(cpi) || cpi->cpi_family >= 0xf) 8437c478bd9Sstevel@tonic-gate xcpuid++; 8447c478bd9Sstevel@tonic-gate break; 8457c478bd9Sstevel@tonic-gate case X86_VENDOR_AMD: 8467c478bd9Sstevel@tonic-gate if (cpi->cpi_family > 5 || 8477c478bd9Sstevel@tonic-gate (cpi->cpi_family == 5 && cpi->cpi_model >= 1)) 8487c478bd9Sstevel@tonic-gate xcpuid++; 8497c478bd9Sstevel@tonic-gate break; 8507c478bd9Sstevel@tonic-gate case X86_VENDOR_Cyrix: 8517c478bd9Sstevel@tonic-gate /* 8527c478bd9Sstevel@tonic-gate * Only these Cyrix CPUs are -known- to support 8537c478bd9Sstevel@tonic-gate * extended cpuid operations. 8547c478bd9Sstevel@tonic-gate */ 8557c478bd9Sstevel@tonic-gate if (x86_type == X86_TYPE_VIA_CYRIX_III || 8567c478bd9Sstevel@tonic-gate x86_type == X86_TYPE_CYRIX_GXm) 8577c478bd9Sstevel@tonic-gate xcpuid++; 8587c478bd9Sstevel@tonic-gate break; 8597c478bd9Sstevel@tonic-gate case X86_VENDOR_Centaur: 8607c478bd9Sstevel@tonic-gate case X86_VENDOR_TM: 8617c478bd9Sstevel@tonic-gate default: 8627c478bd9Sstevel@tonic-gate xcpuid++; 8637c478bd9Sstevel@tonic-gate break; 8647c478bd9Sstevel@tonic-gate } 8657c478bd9Sstevel@tonic-gate 8667c478bd9Sstevel@tonic-gate if (xcpuid) { 8677c478bd9Sstevel@tonic-gate cp = &cpi->cpi_extd[0]; 8688949bcd6Sandrei cp->cp_eax = 0x80000000; 8698949bcd6Sandrei cpi->cpi_xmaxeax = __cpuid_insn(cp); 8707c478bd9Sstevel@tonic-gate } 8717c478bd9Sstevel@tonic-gate 8727c478bd9Sstevel@tonic-gate if (cpi->cpi_xmaxeax & 0x80000000) { 8737c478bd9Sstevel@tonic-gate 8747c478bd9Sstevel@tonic-gate if (cpi->cpi_xmaxeax > CPI_XMAXEAX_MAX) 8757c478bd9Sstevel@tonic-gate cpi->cpi_xmaxeax = CPI_XMAXEAX_MAX; 8767c478bd9Sstevel@tonic-gate 8777c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 8787c478bd9Sstevel@tonic-gate case X86_VENDOR_Intel: 8797c478bd9Sstevel@tonic-gate case X86_VENDOR_AMD: 8807c478bd9Sstevel@tonic-gate if (cpi->cpi_xmaxeax < 0x80000001) 8817c478bd9Sstevel@tonic-gate break; 8827c478bd9Sstevel@tonic-gate cp = &cpi->cpi_extd[1]; 8838949bcd6Sandrei cp->cp_eax = 0x80000001; 8848949bcd6Sandrei (void) __cpuid_insn(cp); 885ae115bc7Smrj 8867c478bd9Sstevel@tonic-gate if (cpi->cpi_vendor == X86_VENDOR_AMD && 8877c478bd9Sstevel@tonic-gate cpi->cpi_family == 5 && 8887c478bd9Sstevel@tonic-gate cpi->cpi_model == 6 && 8897c478bd9Sstevel@tonic-gate cpi->cpi_step == 6) { 8907c478bd9Sstevel@tonic-gate /* 8917c478bd9Sstevel@tonic-gate * K6 model 6 uses bit 10 to indicate SYSC 8927c478bd9Sstevel@tonic-gate * Later models use bit 11. Fix it here. 8937c478bd9Sstevel@tonic-gate */ 8947c478bd9Sstevel@tonic-gate if (cp->cp_edx & 0x400) { 8957c478bd9Sstevel@tonic-gate cp->cp_edx &= ~0x400; 8967c478bd9Sstevel@tonic-gate cp->cp_edx |= CPUID_AMD_EDX_SYSC; 8977c478bd9Sstevel@tonic-gate } 8987c478bd9Sstevel@tonic-gate } 8997c478bd9Sstevel@tonic-gate 900ae115bc7Smrj platform_cpuid_mangle(cpi->cpi_vendor, 0x80000001, cp); 901ae115bc7Smrj 9027c478bd9Sstevel@tonic-gate /* 9037c478bd9Sstevel@tonic-gate * Compute the additions to the kernel's feature word. 9047c478bd9Sstevel@tonic-gate */ 9057c478bd9Sstevel@tonic-gate if (cp->cp_edx & CPUID_AMD_EDX_NX) 9067c478bd9Sstevel@tonic-gate feature |= X86_NX; 9077c478bd9Sstevel@tonic-gate 90819397407SSherry Moore /* 90919397407SSherry Moore * Regardless whether or not we boot 64-bit, 91019397407SSherry Moore * we should have a way to identify whether 91119397407SSherry Moore * the CPU is capable of running 64-bit. 91219397407SSherry Moore */ 91319397407SSherry Moore if (cp->cp_edx & CPUID_AMD_EDX_LM) 91419397407SSherry Moore feature |= X86_64; 91519397407SSherry Moore 91602bc52beSkchow #if defined(__amd64) 91702bc52beSkchow /* 1 GB large page - enable only for 64 bit kernel */ 91802bc52beSkchow if (cp->cp_edx & CPUID_AMD_EDX_1GPG) 91902bc52beSkchow feature |= X86_1GPG; 92002bc52beSkchow #endif 92102bc52beSkchow 922f8801251Skk208521 if ((cpi->cpi_vendor == X86_VENDOR_AMD) && 923f8801251Skk208521 (cpi->cpi_std[1].cp_edx & CPUID_INTC_EDX_FXSR) && 924f8801251Skk208521 (cp->cp_ecx & CPUID_AMD_ECX_SSE4A)) 925f8801251Skk208521 feature |= X86_SSE4A; 926f8801251Skk208521 9277c478bd9Sstevel@tonic-gate /* 928ae115bc7Smrj * If both the HTT and CMP_LGCY bits are set, 9298949bcd6Sandrei * then we're not actually HyperThreaded. Read 9308949bcd6Sandrei * "AMD CPUID Specification" for more details. 9317c478bd9Sstevel@tonic-gate */ 9327c478bd9Sstevel@tonic-gate if (cpi->cpi_vendor == X86_VENDOR_AMD && 9338949bcd6Sandrei (feature & X86_HTT) && 934ae115bc7Smrj (cp->cp_ecx & CPUID_AMD_ECX_CMP_LGCY)) { 9357c478bd9Sstevel@tonic-gate feature &= ~X86_HTT; 9368949bcd6Sandrei feature |= X86_CMP; 9378949bcd6Sandrei } 938ae115bc7Smrj #if defined(__amd64) 9397c478bd9Sstevel@tonic-gate /* 9407c478bd9Sstevel@tonic-gate * It's really tricky to support syscall/sysret in 9417c478bd9Sstevel@tonic-gate * the i386 kernel; we rely on sysenter/sysexit 9427c478bd9Sstevel@tonic-gate * instead. In the amd64 kernel, things are -way- 9437c478bd9Sstevel@tonic-gate * better. 9447c478bd9Sstevel@tonic-gate */ 9457c478bd9Sstevel@tonic-gate if (cp->cp_edx & CPUID_AMD_EDX_SYSC) 9467c478bd9Sstevel@tonic-gate feature |= X86_ASYSC; 9477c478bd9Sstevel@tonic-gate 9487c478bd9Sstevel@tonic-gate /* 9497c478bd9Sstevel@tonic-gate * While we're thinking about system calls, note 9507c478bd9Sstevel@tonic-gate * that AMD processors don't support sysenter 9517c478bd9Sstevel@tonic-gate * in long mode at all, so don't try to program them. 9527c478bd9Sstevel@tonic-gate */ 9537c478bd9Sstevel@tonic-gate if (x86_vendor == X86_VENDOR_AMD) 9547c478bd9Sstevel@tonic-gate feature &= ~X86_SEP; 9557c478bd9Sstevel@tonic-gate #endif 956d36ea5d8Ssudheer if (cp->cp_edx & CPUID_AMD_EDX_TSCP) 957ae115bc7Smrj feature |= X86_TSCP; 9587c478bd9Sstevel@tonic-gate break; 9597c478bd9Sstevel@tonic-gate default: 9607c478bd9Sstevel@tonic-gate break; 9617c478bd9Sstevel@tonic-gate } 9627c478bd9Sstevel@tonic-gate 9638949bcd6Sandrei /* 9648949bcd6Sandrei * Get CPUID data about processor cores and hyperthreads. 9658949bcd6Sandrei */ 9667c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 9677c478bd9Sstevel@tonic-gate case X86_VENDOR_Intel: 9688949bcd6Sandrei if (cpi->cpi_maxeax >= 4) { 9698949bcd6Sandrei cp = &cpi->cpi_std[4]; 9708949bcd6Sandrei cp->cp_eax = 4; 9718949bcd6Sandrei cp->cp_ecx = 0; 9728949bcd6Sandrei (void) __cpuid_insn(cp); 973ae115bc7Smrj platform_cpuid_mangle(cpi->cpi_vendor, 4, cp); 9748949bcd6Sandrei } 9758949bcd6Sandrei /*FALLTHROUGH*/ 9767c478bd9Sstevel@tonic-gate case X86_VENDOR_AMD: 9777c478bd9Sstevel@tonic-gate if (cpi->cpi_xmaxeax < 0x80000008) 9787c478bd9Sstevel@tonic-gate break; 9797c478bd9Sstevel@tonic-gate cp = &cpi->cpi_extd[8]; 9808949bcd6Sandrei cp->cp_eax = 0x80000008; 9818949bcd6Sandrei (void) __cpuid_insn(cp); 982ae115bc7Smrj platform_cpuid_mangle(cpi->cpi_vendor, 0x80000008, cp); 983ae115bc7Smrj 9847c478bd9Sstevel@tonic-gate /* 9857c478bd9Sstevel@tonic-gate * Virtual and physical address limits from 9867c478bd9Sstevel@tonic-gate * cpuid override previously guessed values. 9877c478bd9Sstevel@tonic-gate */ 9887c478bd9Sstevel@tonic-gate cpi->cpi_pabits = BITX(cp->cp_eax, 7, 0); 9897c478bd9Sstevel@tonic-gate cpi->cpi_vabits = BITX(cp->cp_eax, 15, 8); 9907c478bd9Sstevel@tonic-gate break; 9917c478bd9Sstevel@tonic-gate default: 9927c478bd9Sstevel@tonic-gate break; 9937c478bd9Sstevel@tonic-gate } 9948949bcd6Sandrei 995d129bde2Sesaxe /* 996d129bde2Sesaxe * Derive the number of cores per chip 997d129bde2Sesaxe */ 9988949bcd6Sandrei switch (cpi->cpi_vendor) { 9998949bcd6Sandrei case X86_VENDOR_Intel: 10008949bcd6Sandrei if (cpi->cpi_maxeax < 4) { 10018949bcd6Sandrei cpi->cpi_ncore_per_chip = 1; 10028949bcd6Sandrei break; 10038949bcd6Sandrei } else { 10048949bcd6Sandrei cpi->cpi_ncore_per_chip = 10058949bcd6Sandrei BITX((cpi)->cpi_std[4].cp_eax, 31, 26) + 1; 10068949bcd6Sandrei } 10078949bcd6Sandrei break; 10088949bcd6Sandrei case X86_VENDOR_AMD: 10098949bcd6Sandrei if (cpi->cpi_xmaxeax < 0x80000008) { 10108949bcd6Sandrei cpi->cpi_ncore_per_chip = 1; 10118949bcd6Sandrei break; 10128949bcd6Sandrei } else { 101310569901Sgavinm /* 101410569901Sgavinm * On family 0xf cpuid fn 2 ECX[7:0] "NC" is 101510569901Sgavinm * 1 less than the number of physical cores on 101610569901Sgavinm * the chip. In family 0x10 this value can 101710569901Sgavinm * be affected by "downcoring" - it reflects 101810569901Sgavinm * 1 less than the number of cores actually 101910569901Sgavinm * enabled on this node. 102010569901Sgavinm */ 10218949bcd6Sandrei cpi->cpi_ncore_per_chip = 10228949bcd6Sandrei BITX((cpi)->cpi_extd[8].cp_ecx, 7, 0) + 1; 10238949bcd6Sandrei } 10248949bcd6Sandrei break; 10258949bcd6Sandrei default: 10268949bcd6Sandrei cpi->cpi_ncore_per_chip = 1; 10278949bcd6Sandrei break; 10287c478bd9Sstevel@tonic-gate } 10290e751525SEric Saxe 10300e751525SEric Saxe /* 10310e751525SEric Saxe * Get CPUID data about TSC Invariance in Deep C-State. 10320e751525SEric Saxe */ 10330e751525SEric Saxe switch (cpi->cpi_vendor) { 10340e751525SEric Saxe case X86_VENDOR_Intel: 10350e751525SEric Saxe if (cpi->cpi_maxeax >= 7) { 10360e751525SEric Saxe cp = &cpi->cpi_extd[7]; 10370e751525SEric Saxe cp->cp_eax = 0x80000007; 10380e751525SEric Saxe cp->cp_ecx = 0; 10390e751525SEric Saxe (void) __cpuid_insn(cp); 10400e751525SEric Saxe } 10410e751525SEric Saxe break; 10420e751525SEric Saxe default: 10430e751525SEric Saxe break; 10440e751525SEric Saxe } 1045fa2e767eSgavinm } else { 1046fa2e767eSgavinm cpi->cpi_ncore_per_chip = 1; 10478949bcd6Sandrei } 10488949bcd6Sandrei 10498949bcd6Sandrei /* 10508949bcd6Sandrei * If more than one core, then this processor is CMP. 10518949bcd6Sandrei */ 10528949bcd6Sandrei if (cpi->cpi_ncore_per_chip > 1) 10538949bcd6Sandrei feature |= X86_CMP; 1054ae115bc7Smrj 10558949bcd6Sandrei /* 10568949bcd6Sandrei * If the number of cores is the same as the number 10578949bcd6Sandrei * of CPUs, then we cannot have HyperThreading. 10588949bcd6Sandrei */ 10598949bcd6Sandrei if (cpi->cpi_ncpu_per_chip == cpi->cpi_ncore_per_chip) 10608949bcd6Sandrei feature &= ~X86_HTT; 10618949bcd6Sandrei 10627c478bd9Sstevel@tonic-gate if ((feature & (X86_HTT | X86_CMP)) == 0) { 10638949bcd6Sandrei /* 10648949bcd6Sandrei * Single-core single-threaded processors. 10658949bcd6Sandrei */ 10667c478bd9Sstevel@tonic-gate cpi->cpi_chipid = -1; 10677c478bd9Sstevel@tonic-gate cpi->cpi_clogid = 0; 10688949bcd6Sandrei cpi->cpi_coreid = cpu->cpu_id; 106910569901Sgavinm cpi->cpi_pkgcoreid = 0; 10707c478bd9Sstevel@tonic-gate } else if (cpi->cpi_ncpu_per_chip > 1) { 10718949bcd6Sandrei uint_t i; 10728949bcd6Sandrei uint_t chipid_shift = 0; 10738949bcd6Sandrei uint_t coreid_shift = 0; 10748949bcd6Sandrei uint_t apic_id = CPI_APIC_ID(cpi); 10757c478bd9Sstevel@tonic-gate 10768949bcd6Sandrei for (i = 1; i < cpi->cpi_ncpu_per_chip; i <<= 1) 10778949bcd6Sandrei chipid_shift++; 10788949bcd6Sandrei cpi->cpi_chipid = apic_id >> chipid_shift; 10798949bcd6Sandrei cpi->cpi_clogid = apic_id & ((1 << chipid_shift) - 1); 10808949bcd6Sandrei 10818949bcd6Sandrei if (cpi->cpi_vendor == X86_VENDOR_Intel) { 10828949bcd6Sandrei if (feature & X86_CMP) { 10838949bcd6Sandrei /* 10848949bcd6Sandrei * Multi-core (and possibly multi-threaded) 10858949bcd6Sandrei * processors. 10868949bcd6Sandrei */ 10878949bcd6Sandrei uint_t ncpu_per_core; 10888949bcd6Sandrei if (cpi->cpi_ncore_per_chip == 1) 10898949bcd6Sandrei ncpu_per_core = cpi->cpi_ncpu_per_chip; 10908949bcd6Sandrei else if (cpi->cpi_ncore_per_chip > 1) 10918949bcd6Sandrei ncpu_per_core = cpi->cpi_ncpu_per_chip / 10928949bcd6Sandrei cpi->cpi_ncore_per_chip; 10938949bcd6Sandrei /* 10948949bcd6Sandrei * 8bit APIC IDs on dual core Pentiums 10958949bcd6Sandrei * look like this: 10968949bcd6Sandrei * 10978949bcd6Sandrei * +-----------------------+------+------+ 10988949bcd6Sandrei * | Physical Package ID | MC | HT | 10998949bcd6Sandrei * +-----------------------+------+------+ 11008949bcd6Sandrei * <------- chipid --------> 11018949bcd6Sandrei * <------- coreid ---------------> 11028949bcd6Sandrei * <--- clogid --> 110310569901Sgavinm * <------> 110410569901Sgavinm * pkgcoreid 11058949bcd6Sandrei * 11068949bcd6Sandrei * Where the number of bits necessary to 11078949bcd6Sandrei * represent MC and HT fields together equals 11088949bcd6Sandrei * to the minimum number of bits necessary to 11098949bcd6Sandrei * store the value of cpi->cpi_ncpu_per_chip. 11108949bcd6Sandrei * Of those bits, the MC part uses the number 11118949bcd6Sandrei * of bits necessary to store the value of 11128949bcd6Sandrei * cpi->cpi_ncore_per_chip. 11138949bcd6Sandrei */ 11148949bcd6Sandrei for (i = 1; i < ncpu_per_core; i <<= 1) 11158949bcd6Sandrei coreid_shift++; 11163090b9a9Sandrei cpi->cpi_coreid = apic_id >> coreid_shift; 111710569901Sgavinm cpi->cpi_pkgcoreid = cpi->cpi_clogid >> 111810569901Sgavinm coreid_shift; 11198949bcd6Sandrei } else if (feature & X86_HTT) { 11208949bcd6Sandrei /* 11218949bcd6Sandrei * Single-core multi-threaded processors. 11228949bcd6Sandrei */ 11238949bcd6Sandrei cpi->cpi_coreid = cpi->cpi_chipid; 112410569901Sgavinm cpi->cpi_pkgcoreid = 0; 11258949bcd6Sandrei } 11268949bcd6Sandrei } else if (cpi->cpi_vendor == X86_VENDOR_AMD) { 11278949bcd6Sandrei /* 112810569901Sgavinm * AMD CMP chips currently have a single thread per 112910569901Sgavinm * core, with 2 cores on family 0xf and 2, 3 or 4 113010569901Sgavinm * cores on family 0x10. 113110569901Sgavinm * 113210569901Sgavinm * Since no two cpus share a core we must assign a 113310569901Sgavinm * distinct coreid per cpu, and we do this by using 113410569901Sgavinm * the cpu_id. This scheme does not, however, 113510569901Sgavinm * guarantee that sibling cores of a chip will have 113610569901Sgavinm * sequential coreids starting at a multiple of the 113710569901Sgavinm * number of cores per chip - that is usually the 113810569901Sgavinm * case, but if the ACPI MADT table is presented 113910569901Sgavinm * in a different order then we need to perform a 114010569901Sgavinm * few more gymnastics for the pkgcoreid. 114110569901Sgavinm * 114210569901Sgavinm * In family 0xf CMPs there are 2 cores on all nodes 114310569901Sgavinm * present - no mixing of single and dual core parts. 114410569901Sgavinm * 114510569901Sgavinm * In family 0x10 CMPs cpuid fn 2 ECX[15:12] 114610569901Sgavinm * "ApicIdCoreIdSize[3:0]" tells us how 114710569901Sgavinm * many least-significant bits in the ApicId 114810569901Sgavinm * are used to represent the core number 114910569901Sgavinm * within the node. Cores are always 115010569901Sgavinm * numbered sequentially from 0 regardless 115110569901Sgavinm * of how many or which are disabled, and 115210569901Sgavinm * there seems to be no way to discover the 115310569901Sgavinm * real core id when some are disabled. 11548949bcd6Sandrei */ 11558949bcd6Sandrei cpi->cpi_coreid = cpu->cpu_id; 115610569901Sgavinm 115710569901Sgavinm if (cpi->cpi_family == 0x10 && 115810569901Sgavinm cpi->cpi_xmaxeax >= 0x80000008) { 115910569901Sgavinm int coreidsz = 116010569901Sgavinm BITX((cpi)->cpi_extd[8].cp_ecx, 15, 12); 116110569901Sgavinm 116210569901Sgavinm cpi->cpi_pkgcoreid = 116310569901Sgavinm apic_id & ((1 << coreidsz) - 1); 116410569901Sgavinm } else { 116510569901Sgavinm cpi->cpi_pkgcoreid = cpi->cpi_clogid; 116610569901Sgavinm } 11678949bcd6Sandrei } else { 11688949bcd6Sandrei /* 11698949bcd6Sandrei * All other processors are currently 11708949bcd6Sandrei * assumed to have single cores. 11718949bcd6Sandrei */ 11728949bcd6Sandrei cpi->cpi_coreid = cpi->cpi_chipid; 117310569901Sgavinm cpi->cpi_pkgcoreid = 0; 11748949bcd6Sandrei } 11757c478bd9Sstevel@tonic-gate } 11767c478bd9Sstevel@tonic-gate 1177b6917abeSmishra cpi->cpi_apicid = CPI_APIC_ID(cpi); 1178b6917abeSmishra 11798a40a695Sgavinm /* 11808a40a695Sgavinm * Synthesize chip "revision" and socket type 11818a40a695Sgavinm */ 1182e4b86885SCheng Sean Ye cpi->cpi_chiprev = _cpuid_chiprev(cpi->cpi_vendor, cpi->cpi_family, 1183e4b86885SCheng Sean Ye cpi->cpi_model, cpi->cpi_step); 1184e4b86885SCheng Sean Ye cpi->cpi_chiprevstr = _cpuid_chiprevstr(cpi->cpi_vendor, 1185e4b86885SCheng Sean Ye cpi->cpi_family, cpi->cpi_model, cpi->cpi_step); 1186e4b86885SCheng Sean Ye cpi->cpi_socket = _cpuid_skt(cpi->cpi_vendor, cpi->cpi_family, 1187e4b86885SCheng Sean Ye cpi->cpi_model, cpi->cpi_step); 11888a40a695Sgavinm 11897c478bd9Sstevel@tonic-gate pass1_done: 1190551bc2a6Smrj #if !defined(__xpv) 1191551bc2a6Smrj check_for_hvm(); 1192551bc2a6Smrj #endif 11937c478bd9Sstevel@tonic-gate cpi->cpi_pass = 1; 11947c478bd9Sstevel@tonic-gate return (feature); 11957c478bd9Sstevel@tonic-gate } 11967c478bd9Sstevel@tonic-gate 11977c478bd9Sstevel@tonic-gate /* 11987c478bd9Sstevel@tonic-gate * Make copies of the cpuid table entries we depend on, in 11997c478bd9Sstevel@tonic-gate * part for ease of parsing now, in part so that we have only 12007c478bd9Sstevel@tonic-gate * one place to correct any of it, in part for ease of 12017c478bd9Sstevel@tonic-gate * later export to userland, and in part so we can look at 12027c478bd9Sstevel@tonic-gate * this stuff in a crash dump. 12037c478bd9Sstevel@tonic-gate */ 12047c478bd9Sstevel@tonic-gate 12057c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 12067c478bd9Sstevel@tonic-gate void 12077c478bd9Sstevel@tonic-gate cpuid_pass2(cpu_t *cpu) 12087c478bd9Sstevel@tonic-gate { 12097c478bd9Sstevel@tonic-gate uint_t n, nmax; 12107c478bd9Sstevel@tonic-gate int i; 12118949bcd6Sandrei struct cpuid_regs *cp; 12127c478bd9Sstevel@tonic-gate uint8_t *dp; 12137c478bd9Sstevel@tonic-gate uint32_t *iptr; 12147c478bd9Sstevel@tonic-gate struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 12157c478bd9Sstevel@tonic-gate 12167c478bd9Sstevel@tonic-gate ASSERT(cpi->cpi_pass == 1); 12177c478bd9Sstevel@tonic-gate 12187c478bd9Sstevel@tonic-gate if (cpi->cpi_maxeax < 1) 12197c478bd9Sstevel@tonic-gate goto pass2_done; 12207c478bd9Sstevel@tonic-gate 12217c478bd9Sstevel@tonic-gate if ((nmax = cpi->cpi_maxeax + 1) > NMAX_CPI_STD) 12227c478bd9Sstevel@tonic-gate nmax = NMAX_CPI_STD; 12237c478bd9Sstevel@tonic-gate /* 12247c478bd9Sstevel@tonic-gate * (We already handled n == 0 and n == 1 in pass 1) 12257c478bd9Sstevel@tonic-gate */ 12267c478bd9Sstevel@tonic-gate for (n = 2, cp = &cpi->cpi_std[2]; n < nmax; n++, cp++) { 12278949bcd6Sandrei cp->cp_eax = n; 1228d129bde2Sesaxe 1229d129bde2Sesaxe /* 1230d129bde2Sesaxe * CPUID function 4 expects %ecx to be initialized 1231d129bde2Sesaxe * with an index which indicates which cache to return 1232d129bde2Sesaxe * information about. The OS is expected to call function 4 1233d129bde2Sesaxe * with %ecx set to 0, 1, 2, ... until it returns with 1234d129bde2Sesaxe * EAX[4:0] set to 0, which indicates there are no more 1235d129bde2Sesaxe * caches. 1236d129bde2Sesaxe * 1237d129bde2Sesaxe * Here, populate cpi_std[4] with the information returned by 1238d129bde2Sesaxe * function 4 when %ecx == 0, and do the rest in cpuid_pass3() 1239d129bde2Sesaxe * when dynamic memory allocation becomes available. 1240d129bde2Sesaxe * 1241d129bde2Sesaxe * Note: we need to explicitly initialize %ecx here, since 1242d129bde2Sesaxe * function 4 may have been previously invoked. 1243d129bde2Sesaxe */ 1244d129bde2Sesaxe if (n == 4) 1245d129bde2Sesaxe cp->cp_ecx = 0; 1246d129bde2Sesaxe 12478949bcd6Sandrei (void) __cpuid_insn(cp); 1248ae115bc7Smrj platform_cpuid_mangle(cpi->cpi_vendor, n, cp); 12497c478bd9Sstevel@tonic-gate switch (n) { 12507c478bd9Sstevel@tonic-gate case 2: 12517c478bd9Sstevel@tonic-gate /* 12527c478bd9Sstevel@tonic-gate * "the lower 8 bits of the %eax register 12537c478bd9Sstevel@tonic-gate * contain a value that identifies the number 12547c478bd9Sstevel@tonic-gate * of times the cpuid [instruction] has to be 12557c478bd9Sstevel@tonic-gate * executed to obtain a complete image of the 12567c478bd9Sstevel@tonic-gate * processor's caching systems." 12577c478bd9Sstevel@tonic-gate * 12587c478bd9Sstevel@tonic-gate * How *do* they make this stuff up? 12597c478bd9Sstevel@tonic-gate */ 12607c478bd9Sstevel@tonic-gate cpi->cpi_ncache = sizeof (*cp) * 12617c478bd9Sstevel@tonic-gate BITX(cp->cp_eax, 7, 0); 12627c478bd9Sstevel@tonic-gate if (cpi->cpi_ncache == 0) 12637c478bd9Sstevel@tonic-gate break; 12647c478bd9Sstevel@tonic-gate cpi->cpi_ncache--; /* skip count byte */ 12657c478bd9Sstevel@tonic-gate 12667c478bd9Sstevel@tonic-gate /* 12677c478bd9Sstevel@tonic-gate * Well, for now, rather than attempt to implement 12687c478bd9Sstevel@tonic-gate * this slightly dubious algorithm, we just look 12697c478bd9Sstevel@tonic-gate * at the first 15 .. 12707c478bd9Sstevel@tonic-gate */ 12717c478bd9Sstevel@tonic-gate if (cpi->cpi_ncache > (sizeof (*cp) - 1)) 12727c478bd9Sstevel@tonic-gate cpi->cpi_ncache = sizeof (*cp) - 1; 12737c478bd9Sstevel@tonic-gate 12747c478bd9Sstevel@tonic-gate dp = cpi->cpi_cacheinfo; 12757c478bd9Sstevel@tonic-gate if (BITX(cp->cp_eax, 31, 31) == 0) { 12767c478bd9Sstevel@tonic-gate uint8_t *p = (void *)&cp->cp_eax; 127763d3f7dfSkk208521 for (i = 1; i < 4; i++) 12787c478bd9Sstevel@tonic-gate if (p[i] != 0) 12797c478bd9Sstevel@tonic-gate *dp++ = p[i]; 12807c478bd9Sstevel@tonic-gate } 12817c478bd9Sstevel@tonic-gate if (BITX(cp->cp_ebx, 31, 31) == 0) { 12827c478bd9Sstevel@tonic-gate uint8_t *p = (void *)&cp->cp_ebx; 12837c478bd9Sstevel@tonic-gate for (i = 0; i < 4; i++) 12847c478bd9Sstevel@tonic-gate if (p[i] != 0) 12857c478bd9Sstevel@tonic-gate *dp++ = p[i]; 12867c478bd9Sstevel@tonic-gate } 12877c478bd9Sstevel@tonic-gate if (BITX(cp->cp_ecx, 31, 31) == 0) { 12887c478bd9Sstevel@tonic-gate uint8_t *p = (void *)&cp->cp_ecx; 12897c478bd9Sstevel@tonic-gate for (i = 0; i < 4; i++) 12907c478bd9Sstevel@tonic-gate if (p[i] != 0) 12917c478bd9Sstevel@tonic-gate *dp++ = p[i]; 12927c478bd9Sstevel@tonic-gate } 12937c478bd9Sstevel@tonic-gate if (BITX(cp->cp_edx, 31, 31) == 0) { 12947c478bd9Sstevel@tonic-gate uint8_t *p = (void *)&cp->cp_edx; 12957c478bd9Sstevel@tonic-gate for (i = 0; i < 4; i++) 12967c478bd9Sstevel@tonic-gate if (p[i] != 0) 12977c478bd9Sstevel@tonic-gate *dp++ = p[i]; 12987c478bd9Sstevel@tonic-gate } 12997c478bd9Sstevel@tonic-gate break; 1300f98fbcecSbholler 13017c478bd9Sstevel@tonic-gate case 3: /* Processor serial number, if PSN supported */ 1302f98fbcecSbholler break; 1303f98fbcecSbholler 13047c478bd9Sstevel@tonic-gate case 4: /* Deterministic cache parameters */ 1305f98fbcecSbholler break; 1306f98fbcecSbholler 13077c478bd9Sstevel@tonic-gate case 5: /* Monitor/Mwait parameters */ 13085b8a6efeSbholler { 13095b8a6efeSbholler size_t mwait_size; 1310f98fbcecSbholler 1311f98fbcecSbholler /* 1312f98fbcecSbholler * check cpi_mwait.support which was set in cpuid_pass1 1313f98fbcecSbholler */ 1314f98fbcecSbholler if (!(cpi->cpi_mwait.support & MWAIT_SUPPORT)) 1315f98fbcecSbholler break; 1316f98fbcecSbholler 13175b8a6efeSbholler /* 13185b8a6efeSbholler * Protect ourself from insane mwait line size. 13195b8a6efeSbholler * Workaround for incomplete hardware emulator(s). 13205b8a6efeSbholler */ 13215b8a6efeSbholler mwait_size = (size_t)MWAIT_SIZE_MAX(cpi); 13225b8a6efeSbholler if (mwait_size < sizeof (uint32_t) || 13235b8a6efeSbholler !ISP2(mwait_size)) { 13245b8a6efeSbholler #if DEBUG 13255b8a6efeSbholler cmn_err(CE_NOTE, "Cannot handle cpu %d mwait " 13265d8efbbcSSaurabh Misra "size %ld", cpu->cpu_id, (long)mwait_size); 13275b8a6efeSbholler #endif 13285b8a6efeSbholler break; 13295b8a6efeSbholler } 13305b8a6efeSbholler 1331f98fbcecSbholler cpi->cpi_mwait.mon_min = (size_t)MWAIT_SIZE_MIN(cpi); 13325b8a6efeSbholler cpi->cpi_mwait.mon_max = mwait_size; 1333f98fbcecSbholler if (MWAIT_EXTENSION(cpi)) { 1334f98fbcecSbholler cpi->cpi_mwait.support |= MWAIT_EXTENSIONS; 1335f98fbcecSbholler if (MWAIT_INT_ENABLE(cpi)) 1336f98fbcecSbholler cpi->cpi_mwait.support |= 1337f98fbcecSbholler MWAIT_ECX_INT_ENABLE; 1338f98fbcecSbholler } 1339f98fbcecSbholler break; 13405b8a6efeSbholler } 13417c478bd9Sstevel@tonic-gate default: 13427c478bd9Sstevel@tonic-gate break; 13437c478bd9Sstevel@tonic-gate } 13447c478bd9Sstevel@tonic-gate } 13457c478bd9Sstevel@tonic-gate 1346b6917abeSmishra if (cpi->cpi_maxeax >= 0xB && cpi->cpi_vendor == X86_VENDOR_Intel) { 13475d8efbbcSSaurabh Misra struct cpuid_regs regs; 13485d8efbbcSSaurabh Misra 13495d8efbbcSSaurabh Misra cp = ®s; 1350b6917abeSmishra cp->cp_eax = 0xB; 13515d8efbbcSSaurabh Misra cp->cp_edx = cp->cp_ebx = cp->cp_ecx = 0; 1352b6917abeSmishra 1353b6917abeSmishra (void) __cpuid_insn(cp); 1354b6917abeSmishra 1355b6917abeSmishra /* 1356b6917abeSmishra * Check CPUID.EAX=0BH, ECX=0H:EBX is non-zero, which 1357b6917abeSmishra * indicates that the extended topology enumeration leaf is 1358b6917abeSmishra * available. 1359b6917abeSmishra */ 1360b6917abeSmishra if (cp->cp_ebx) { 1361b6917abeSmishra uint32_t x2apic_id; 1362b6917abeSmishra uint_t coreid_shift = 0; 1363b6917abeSmishra uint_t ncpu_per_core = 1; 1364b6917abeSmishra uint_t chipid_shift = 0; 1365b6917abeSmishra uint_t ncpu_per_chip = 1; 1366b6917abeSmishra uint_t i; 1367b6917abeSmishra uint_t level; 1368b6917abeSmishra 1369b6917abeSmishra for (i = 0; i < CPI_FNB_ECX_MAX; i++) { 1370b6917abeSmishra cp->cp_eax = 0xB; 1371b6917abeSmishra cp->cp_ecx = i; 1372b6917abeSmishra 1373b6917abeSmishra (void) __cpuid_insn(cp); 1374b6917abeSmishra level = CPI_CPU_LEVEL_TYPE(cp); 1375b6917abeSmishra 1376b6917abeSmishra if (level == 1) { 1377b6917abeSmishra x2apic_id = cp->cp_edx; 1378b6917abeSmishra coreid_shift = BITX(cp->cp_eax, 4, 0); 1379b6917abeSmishra ncpu_per_core = BITX(cp->cp_ebx, 15, 0); 1380b6917abeSmishra } else if (level == 2) { 1381b6917abeSmishra x2apic_id = cp->cp_edx; 1382b6917abeSmishra chipid_shift = BITX(cp->cp_eax, 4, 0); 1383b6917abeSmishra ncpu_per_chip = BITX(cp->cp_ebx, 15, 0); 1384b6917abeSmishra } 1385b6917abeSmishra } 1386b6917abeSmishra 1387b6917abeSmishra cpi->cpi_apicid = x2apic_id; 1388b6917abeSmishra cpi->cpi_ncpu_per_chip = ncpu_per_chip; 1389b6917abeSmishra cpi->cpi_ncore_per_chip = ncpu_per_chip / 1390b6917abeSmishra ncpu_per_core; 1391b6917abeSmishra cpi->cpi_chipid = x2apic_id >> chipid_shift; 1392b6917abeSmishra cpi->cpi_clogid = x2apic_id & ((1 << chipid_shift) - 1); 1393b6917abeSmishra cpi->cpi_coreid = x2apic_id >> coreid_shift; 1394b6917abeSmishra cpi->cpi_pkgcoreid = cpi->cpi_clogid >> coreid_shift; 1395b6917abeSmishra } 13965d8efbbcSSaurabh Misra 13975d8efbbcSSaurabh Misra /* Make cp NULL so that we don't stumble on others */ 13985d8efbbcSSaurabh Misra cp = NULL; 1399b6917abeSmishra } 1400b6917abeSmishra 14017c478bd9Sstevel@tonic-gate if ((cpi->cpi_xmaxeax & 0x80000000) == 0) 14027c478bd9Sstevel@tonic-gate goto pass2_done; 14037c478bd9Sstevel@tonic-gate 14047c478bd9Sstevel@tonic-gate if ((nmax = cpi->cpi_xmaxeax - 0x80000000 + 1) > NMAX_CPI_EXTD) 14057c478bd9Sstevel@tonic-gate nmax = NMAX_CPI_EXTD; 14067c478bd9Sstevel@tonic-gate /* 14077c478bd9Sstevel@tonic-gate * Copy the extended properties, fixing them as we go. 14087c478bd9Sstevel@tonic-gate * (We already handled n == 0 and n == 1 in pass 1) 14097c478bd9Sstevel@tonic-gate */ 14107c478bd9Sstevel@tonic-gate iptr = (void *)cpi->cpi_brandstr; 14117c478bd9Sstevel@tonic-gate for (n = 2, cp = &cpi->cpi_extd[2]; n < nmax; cp++, n++) { 14128949bcd6Sandrei cp->cp_eax = 0x80000000 + n; 14138949bcd6Sandrei (void) __cpuid_insn(cp); 1414ae115bc7Smrj platform_cpuid_mangle(cpi->cpi_vendor, 0x80000000 + n, cp); 14157c478bd9Sstevel@tonic-gate switch (n) { 14167c478bd9Sstevel@tonic-gate case 2: 14177c478bd9Sstevel@tonic-gate case 3: 14187c478bd9Sstevel@tonic-gate case 4: 14197c478bd9Sstevel@tonic-gate /* 14207c478bd9Sstevel@tonic-gate * Extract the brand string 14217c478bd9Sstevel@tonic-gate */ 14227c478bd9Sstevel@tonic-gate *iptr++ = cp->cp_eax; 14237c478bd9Sstevel@tonic-gate *iptr++ = cp->cp_ebx; 14247c478bd9Sstevel@tonic-gate *iptr++ = cp->cp_ecx; 14257c478bd9Sstevel@tonic-gate *iptr++ = cp->cp_edx; 14267c478bd9Sstevel@tonic-gate break; 14277c478bd9Sstevel@tonic-gate case 5: 14287c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 14297c478bd9Sstevel@tonic-gate case X86_VENDOR_AMD: 14307c478bd9Sstevel@tonic-gate /* 14317c478bd9Sstevel@tonic-gate * The Athlon and Duron were the first 14327c478bd9Sstevel@tonic-gate * parts to report the sizes of the 14337c478bd9Sstevel@tonic-gate * TLB for large pages. Before then, 14347c478bd9Sstevel@tonic-gate * we don't trust the data. 14357c478bd9Sstevel@tonic-gate */ 14367c478bd9Sstevel@tonic-gate if (cpi->cpi_family < 6 || 14377c478bd9Sstevel@tonic-gate (cpi->cpi_family == 6 && 14387c478bd9Sstevel@tonic-gate cpi->cpi_model < 1)) 14397c478bd9Sstevel@tonic-gate cp->cp_eax = 0; 14407c478bd9Sstevel@tonic-gate break; 14417c478bd9Sstevel@tonic-gate default: 14427c478bd9Sstevel@tonic-gate break; 14437c478bd9Sstevel@tonic-gate } 14447c478bd9Sstevel@tonic-gate break; 14457c478bd9Sstevel@tonic-gate case 6: 14467c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 14477c478bd9Sstevel@tonic-gate case X86_VENDOR_AMD: 14487c478bd9Sstevel@tonic-gate /* 14497c478bd9Sstevel@tonic-gate * The Athlon and Duron were the first 14507c478bd9Sstevel@tonic-gate * AMD parts with L2 TLB's. 14517c478bd9Sstevel@tonic-gate * Before then, don't trust the data. 14527c478bd9Sstevel@tonic-gate */ 14537c478bd9Sstevel@tonic-gate if (cpi->cpi_family < 6 || 14547c478bd9Sstevel@tonic-gate cpi->cpi_family == 6 && 14557c478bd9Sstevel@tonic-gate cpi->cpi_model < 1) 14567c478bd9Sstevel@tonic-gate cp->cp_eax = cp->cp_ebx = 0; 14577c478bd9Sstevel@tonic-gate /* 14587c478bd9Sstevel@tonic-gate * AMD Duron rev A0 reports L2 14597c478bd9Sstevel@tonic-gate * cache size incorrectly as 1K 14607c478bd9Sstevel@tonic-gate * when it is really 64K 14617c478bd9Sstevel@tonic-gate */ 14627c478bd9Sstevel@tonic-gate if (cpi->cpi_family == 6 && 14637c478bd9Sstevel@tonic-gate cpi->cpi_model == 3 && 14647c478bd9Sstevel@tonic-gate cpi->cpi_step == 0) { 14657c478bd9Sstevel@tonic-gate cp->cp_ecx &= 0xffff; 14667c478bd9Sstevel@tonic-gate cp->cp_ecx |= 0x400000; 14677c478bd9Sstevel@tonic-gate } 14687c478bd9Sstevel@tonic-gate break; 14697c478bd9Sstevel@tonic-gate case X86_VENDOR_Cyrix: /* VIA C3 */ 14707c478bd9Sstevel@tonic-gate /* 14717c478bd9Sstevel@tonic-gate * VIA C3 processors are a bit messed 14727c478bd9Sstevel@tonic-gate * up w.r.t. encoding cache sizes in %ecx 14737c478bd9Sstevel@tonic-gate */ 14747c478bd9Sstevel@tonic-gate if (cpi->cpi_family != 6) 14757c478bd9Sstevel@tonic-gate break; 14767c478bd9Sstevel@tonic-gate /* 14777c478bd9Sstevel@tonic-gate * model 7 and 8 were incorrectly encoded 14787c478bd9Sstevel@tonic-gate * 14797c478bd9Sstevel@tonic-gate * xxx is model 8 really broken? 14807c478bd9Sstevel@tonic-gate */ 14817c478bd9Sstevel@tonic-gate if (cpi->cpi_model == 7 || 14827c478bd9Sstevel@tonic-gate cpi->cpi_model == 8) 14837c478bd9Sstevel@tonic-gate cp->cp_ecx = 14847c478bd9Sstevel@tonic-gate BITX(cp->cp_ecx, 31, 24) << 16 | 14857c478bd9Sstevel@tonic-gate BITX(cp->cp_ecx, 23, 16) << 12 | 14867c478bd9Sstevel@tonic-gate BITX(cp->cp_ecx, 15, 8) << 8 | 14877c478bd9Sstevel@tonic-gate BITX(cp->cp_ecx, 7, 0); 14887c478bd9Sstevel@tonic-gate /* 14897c478bd9Sstevel@tonic-gate * model 9 stepping 1 has wrong associativity 14907c478bd9Sstevel@tonic-gate */ 14917c478bd9Sstevel@tonic-gate if (cpi->cpi_model == 9 && cpi->cpi_step == 1) 14927c478bd9Sstevel@tonic-gate cp->cp_ecx |= 8 << 12; 14937c478bd9Sstevel@tonic-gate break; 14947c478bd9Sstevel@tonic-gate case X86_VENDOR_Intel: 14957c478bd9Sstevel@tonic-gate /* 14967c478bd9Sstevel@tonic-gate * Extended L2 Cache features function. 14977c478bd9Sstevel@tonic-gate * First appeared on Prescott. 14987c478bd9Sstevel@tonic-gate */ 14997c478bd9Sstevel@tonic-gate default: 15007c478bd9Sstevel@tonic-gate break; 15017c478bd9Sstevel@tonic-gate } 15027c478bd9Sstevel@tonic-gate break; 15037c478bd9Sstevel@tonic-gate default: 15047c478bd9Sstevel@tonic-gate break; 15057c478bd9Sstevel@tonic-gate } 15067c478bd9Sstevel@tonic-gate } 15077c478bd9Sstevel@tonic-gate 15087c478bd9Sstevel@tonic-gate pass2_done: 15097c478bd9Sstevel@tonic-gate cpi->cpi_pass = 2; 15107c478bd9Sstevel@tonic-gate } 15117c478bd9Sstevel@tonic-gate 15127c478bd9Sstevel@tonic-gate static const char * 15137c478bd9Sstevel@tonic-gate intel_cpubrand(const struct cpuid_info *cpi) 15147c478bd9Sstevel@tonic-gate { 15157c478bd9Sstevel@tonic-gate int i; 15167c478bd9Sstevel@tonic-gate 15177c478bd9Sstevel@tonic-gate if ((x86_feature & X86_CPUID) == 0 || 15187c478bd9Sstevel@tonic-gate cpi->cpi_maxeax < 1 || cpi->cpi_family < 5) 15197c478bd9Sstevel@tonic-gate return ("i486"); 15207c478bd9Sstevel@tonic-gate 15217c478bd9Sstevel@tonic-gate switch (cpi->cpi_family) { 15227c478bd9Sstevel@tonic-gate case 5: 15237c478bd9Sstevel@tonic-gate return ("Intel Pentium(r)"); 15247c478bd9Sstevel@tonic-gate case 6: 15257c478bd9Sstevel@tonic-gate switch (cpi->cpi_model) { 15267c478bd9Sstevel@tonic-gate uint_t celeron, xeon; 15278949bcd6Sandrei const struct cpuid_regs *cp; 15287c478bd9Sstevel@tonic-gate case 0: 15297c478bd9Sstevel@tonic-gate case 1: 15307c478bd9Sstevel@tonic-gate case 2: 15317c478bd9Sstevel@tonic-gate return ("Intel Pentium(r) Pro"); 15327c478bd9Sstevel@tonic-gate case 3: 15337c478bd9Sstevel@tonic-gate case 4: 15347c478bd9Sstevel@tonic-gate return ("Intel Pentium(r) II"); 15357c478bd9Sstevel@tonic-gate case 6: 15367c478bd9Sstevel@tonic-gate return ("Intel Celeron(r)"); 15377c478bd9Sstevel@tonic-gate case 5: 15387c478bd9Sstevel@tonic-gate case 7: 15397c478bd9Sstevel@tonic-gate celeron = xeon = 0; 15407c478bd9Sstevel@tonic-gate cp = &cpi->cpi_std[2]; /* cache info */ 15417c478bd9Sstevel@tonic-gate 154263d3f7dfSkk208521 for (i = 1; i < 4; i++) { 15437c478bd9Sstevel@tonic-gate uint_t tmp; 15447c478bd9Sstevel@tonic-gate 15457c478bd9Sstevel@tonic-gate tmp = (cp->cp_eax >> (8 * i)) & 0xff; 15467c478bd9Sstevel@tonic-gate if (tmp == 0x40) 15477c478bd9Sstevel@tonic-gate celeron++; 15487c478bd9Sstevel@tonic-gate if (tmp >= 0x44 && tmp <= 0x45) 15497c478bd9Sstevel@tonic-gate xeon++; 15507c478bd9Sstevel@tonic-gate } 15517c478bd9Sstevel@tonic-gate 15527c478bd9Sstevel@tonic-gate for (i = 0; i < 2; i++) { 15537c478bd9Sstevel@tonic-gate uint_t tmp; 15547c478bd9Sstevel@tonic-gate 15557c478bd9Sstevel@tonic-gate tmp = (cp->cp_ebx >> (8 * i)) & 0xff; 15567c478bd9Sstevel@tonic-gate if (tmp == 0x40) 15577c478bd9Sstevel@tonic-gate celeron++; 15587c478bd9Sstevel@tonic-gate else if (tmp >= 0x44 && tmp <= 0x45) 15597c478bd9Sstevel@tonic-gate xeon++; 15607c478bd9Sstevel@tonic-gate } 15617c478bd9Sstevel@tonic-gate 15627c478bd9Sstevel@tonic-gate for (i = 0; i < 4; i++) { 15637c478bd9Sstevel@tonic-gate uint_t tmp; 15647c478bd9Sstevel@tonic-gate 15657c478bd9Sstevel@tonic-gate tmp = (cp->cp_ecx >> (8 * i)) & 0xff; 15667c478bd9Sstevel@tonic-gate if (tmp == 0x40) 15677c478bd9Sstevel@tonic-gate celeron++; 15687c478bd9Sstevel@tonic-gate else if (tmp >= 0x44 && tmp <= 0x45) 15697c478bd9Sstevel@tonic-gate xeon++; 15707c478bd9Sstevel@tonic-gate } 15717c478bd9Sstevel@tonic-gate 15727c478bd9Sstevel@tonic-gate for (i = 0; i < 4; i++) { 15737c478bd9Sstevel@tonic-gate uint_t tmp; 15747c478bd9Sstevel@tonic-gate 15757c478bd9Sstevel@tonic-gate tmp = (cp->cp_edx >> (8 * i)) & 0xff; 15767c478bd9Sstevel@tonic-gate if (tmp == 0x40) 15777c478bd9Sstevel@tonic-gate celeron++; 15787c478bd9Sstevel@tonic-gate else if (tmp >= 0x44 && tmp <= 0x45) 15797c478bd9Sstevel@tonic-gate xeon++; 15807c478bd9Sstevel@tonic-gate } 15817c478bd9Sstevel@tonic-gate 15827c478bd9Sstevel@tonic-gate if (celeron) 15837c478bd9Sstevel@tonic-gate return ("Intel Celeron(r)"); 15847c478bd9Sstevel@tonic-gate if (xeon) 15857c478bd9Sstevel@tonic-gate return (cpi->cpi_model == 5 ? 15867c478bd9Sstevel@tonic-gate "Intel Pentium(r) II Xeon(tm)" : 15877c478bd9Sstevel@tonic-gate "Intel Pentium(r) III Xeon(tm)"); 15887c478bd9Sstevel@tonic-gate return (cpi->cpi_model == 5 ? 15897c478bd9Sstevel@tonic-gate "Intel Pentium(r) II or Pentium(r) II Xeon(tm)" : 15907c478bd9Sstevel@tonic-gate "Intel Pentium(r) III or Pentium(r) III Xeon(tm)"); 15917c478bd9Sstevel@tonic-gate default: 15927c478bd9Sstevel@tonic-gate break; 15937c478bd9Sstevel@tonic-gate } 15947c478bd9Sstevel@tonic-gate default: 15957c478bd9Sstevel@tonic-gate break; 15967c478bd9Sstevel@tonic-gate } 15977c478bd9Sstevel@tonic-gate 15985ff02082Sdmick /* BrandID is present if the field is nonzero */ 15995ff02082Sdmick if (cpi->cpi_brandid != 0) { 16007c478bd9Sstevel@tonic-gate static const struct { 16017c478bd9Sstevel@tonic-gate uint_t bt_bid; 16027c478bd9Sstevel@tonic-gate const char *bt_str; 16037c478bd9Sstevel@tonic-gate } brand_tbl[] = { 16047c478bd9Sstevel@tonic-gate { 0x1, "Intel(r) Celeron(r)" }, 16057c478bd9Sstevel@tonic-gate { 0x2, "Intel(r) Pentium(r) III" }, 16067c478bd9Sstevel@tonic-gate { 0x3, "Intel(r) Pentium(r) III Xeon(tm)" }, 16077c478bd9Sstevel@tonic-gate { 0x4, "Intel(r) Pentium(r) III" }, 16087c478bd9Sstevel@tonic-gate { 0x6, "Mobile Intel(r) Pentium(r) III" }, 16097c478bd9Sstevel@tonic-gate { 0x7, "Mobile Intel(r) Celeron(r)" }, 16107c478bd9Sstevel@tonic-gate { 0x8, "Intel(r) Pentium(r) 4" }, 16117c478bd9Sstevel@tonic-gate { 0x9, "Intel(r) Pentium(r) 4" }, 16127c478bd9Sstevel@tonic-gate { 0xa, "Intel(r) Celeron(r)" }, 16137c478bd9Sstevel@tonic-gate { 0xb, "Intel(r) Xeon(tm)" }, 16147c478bd9Sstevel@tonic-gate { 0xc, "Intel(r) Xeon(tm) MP" }, 16157c478bd9Sstevel@tonic-gate { 0xe, "Mobile Intel(r) Pentium(r) 4" }, 16165ff02082Sdmick { 0xf, "Mobile Intel(r) Celeron(r)" }, 16175ff02082Sdmick { 0x11, "Mobile Genuine Intel(r)" }, 16185ff02082Sdmick { 0x12, "Intel(r) Celeron(r) M" }, 16195ff02082Sdmick { 0x13, "Mobile Intel(r) Celeron(r)" }, 16205ff02082Sdmick { 0x14, "Intel(r) Celeron(r)" }, 16215ff02082Sdmick { 0x15, "Mobile Genuine Intel(r)" }, 16225ff02082Sdmick { 0x16, "Intel(r) Pentium(r) M" }, 16235ff02082Sdmick { 0x17, "Mobile Intel(r) Celeron(r)" } 16247c478bd9Sstevel@tonic-gate }; 16257c478bd9Sstevel@tonic-gate uint_t btblmax = sizeof (brand_tbl) / sizeof (brand_tbl[0]); 16267c478bd9Sstevel@tonic-gate uint_t sgn; 16277c478bd9Sstevel@tonic-gate 16287c478bd9Sstevel@tonic-gate sgn = (cpi->cpi_family << 8) | 16297c478bd9Sstevel@tonic-gate (cpi->cpi_model << 4) | cpi->cpi_step; 16307c478bd9Sstevel@tonic-gate 16317c478bd9Sstevel@tonic-gate for (i = 0; i < btblmax; i++) 16327c478bd9Sstevel@tonic-gate if (brand_tbl[i].bt_bid == cpi->cpi_brandid) 16337c478bd9Sstevel@tonic-gate break; 16347c478bd9Sstevel@tonic-gate if (i < btblmax) { 16357c478bd9Sstevel@tonic-gate if (sgn == 0x6b1 && cpi->cpi_brandid == 3) 16367c478bd9Sstevel@tonic-gate return ("Intel(r) Celeron(r)"); 16377c478bd9Sstevel@tonic-gate if (sgn < 0xf13 && cpi->cpi_brandid == 0xb) 16387c478bd9Sstevel@tonic-gate return ("Intel(r) Xeon(tm) MP"); 16397c478bd9Sstevel@tonic-gate if (sgn < 0xf13 && cpi->cpi_brandid == 0xe) 16407c478bd9Sstevel@tonic-gate return ("Intel(r) Xeon(tm)"); 16417c478bd9Sstevel@tonic-gate return (brand_tbl[i].bt_str); 16427c478bd9Sstevel@tonic-gate } 16437c478bd9Sstevel@tonic-gate } 16447c478bd9Sstevel@tonic-gate 16457c478bd9Sstevel@tonic-gate return (NULL); 16467c478bd9Sstevel@tonic-gate } 16477c478bd9Sstevel@tonic-gate 16487c478bd9Sstevel@tonic-gate static const char * 16497c478bd9Sstevel@tonic-gate amd_cpubrand(const struct cpuid_info *cpi) 16507c478bd9Sstevel@tonic-gate { 16517c478bd9Sstevel@tonic-gate if ((x86_feature & X86_CPUID) == 0 || 16527c478bd9Sstevel@tonic-gate cpi->cpi_maxeax < 1 || cpi->cpi_family < 5) 16537c478bd9Sstevel@tonic-gate return ("i486 compatible"); 16547c478bd9Sstevel@tonic-gate 16557c478bd9Sstevel@tonic-gate switch (cpi->cpi_family) { 16567c478bd9Sstevel@tonic-gate case 5: 16577c478bd9Sstevel@tonic-gate switch (cpi->cpi_model) { 16587c478bd9Sstevel@tonic-gate case 0: 16597c478bd9Sstevel@tonic-gate case 1: 16607c478bd9Sstevel@tonic-gate case 2: 16617c478bd9Sstevel@tonic-gate case 3: 16627c478bd9Sstevel@tonic-gate case 4: 16637c478bd9Sstevel@tonic-gate case 5: 16647c478bd9Sstevel@tonic-gate return ("AMD-K5(r)"); 16657c478bd9Sstevel@tonic-gate case 6: 16667c478bd9Sstevel@tonic-gate case 7: 16677c478bd9Sstevel@tonic-gate return ("AMD-K6(r)"); 16687c478bd9Sstevel@tonic-gate case 8: 16697c478bd9Sstevel@tonic-gate return ("AMD-K6(r)-2"); 16707c478bd9Sstevel@tonic-gate case 9: 16717c478bd9Sstevel@tonic-gate return ("AMD-K6(r)-III"); 16727c478bd9Sstevel@tonic-gate default: 16737c478bd9Sstevel@tonic-gate return ("AMD (family 5)"); 16747c478bd9Sstevel@tonic-gate } 16757c478bd9Sstevel@tonic-gate case 6: 16767c478bd9Sstevel@tonic-gate switch (cpi->cpi_model) { 16777c478bd9Sstevel@tonic-gate case 1: 16787c478bd9Sstevel@tonic-gate return ("AMD-K7(tm)"); 16797c478bd9Sstevel@tonic-gate case 0: 16807c478bd9Sstevel@tonic-gate case 2: 16817c478bd9Sstevel@tonic-gate case 4: 16827c478bd9Sstevel@tonic-gate return ("AMD Athlon(tm)"); 16837c478bd9Sstevel@tonic-gate case 3: 16847c478bd9Sstevel@tonic-gate case 7: 16857c478bd9Sstevel@tonic-gate return ("AMD Duron(tm)"); 16867c478bd9Sstevel@tonic-gate case 6: 16877c478bd9Sstevel@tonic-gate case 8: 16887c478bd9Sstevel@tonic-gate case 10: 16897c478bd9Sstevel@tonic-gate /* 16907c478bd9Sstevel@tonic-gate * Use the L2 cache size to distinguish 16917c478bd9Sstevel@tonic-gate */ 16927c478bd9Sstevel@tonic-gate return ((cpi->cpi_extd[6].cp_ecx >> 16) >= 256 ? 16937c478bd9Sstevel@tonic-gate "AMD Athlon(tm)" : "AMD Duron(tm)"); 16947c478bd9Sstevel@tonic-gate default: 16957c478bd9Sstevel@tonic-gate return ("AMD (family 6)"); 16967c478bd9Sstevel@tonic-gate } 16977c478bd9Sstevel@tonic-gate default: 16987c478bd9Sstevel@tonic-gate break; 16997c478bd9Sstevel@tonic-gate } 17007c478bd9Sstevel@tonic-gate 17017c478bd9Sstevel@tonic-gate if (cpi->cpi_family == 0xf && cpi->cpi_model == 5 && 17027c478bd9Sstevel@tonic-gate cpi->cpi_brandid != 0) { 17037c478bd9Sstevel@tonic-gate switch (BITX(cpi->cpi_brandid, 7, 5)) { 17047c478bd9Sstevel@tonic-gate case 3: 17057c478bd9Sstevel@tonic-gate return ("AMD Opteron(tm) UP 1xx"); 17067c478bd9Sstevel@tonic-gate case 4: 17077c478bd9Sstevel@tonic-gate return ("AMD Opteron(tm) DP 2xx"); 17087c478bd9Sstevel@tonic-gate case 5: 17097c478bd9Sstevel@tonic-gate return ("AMD Opteron(tm) MP 8xx"); 17107c478bd9Sstevel@tonic-gate default: 17117c478bd9Sstevel@tonic-gate return ("AMD Opteron(tm)"); 17127c478bd9Sstevel@tonic-gate } 17137c478bd9Sstevel@tonic-gate } 17147c478bd9Sstevel@tonic-gate 17157c478bd9Sstevel@tonic-gate return (NULL); 17167c478bd9Sstevel@tonic-gate } 17177c478bd9Sstevel@tonic-gate 17187c478bd9Sstevel@tonic-gate static const char * 17197c478bd9Sstevel@tonic-gate cyrix_cpubrand(struct cpuid_info *cpi, uint_t type) 17207c478bd9Sstevel@tonic-gate { 17217c478bd9Sstevel@tonic-gate if ((x86_feature & X86_CPUID) == 0 || 17227c478bd9Sstevel@tonic-gate cpi->cpi_maxeax < 1 || cpi->cpi_family < 5 || 17237c478bd9Sstevel@tonic-gate type == X86_TYPE_CYRIX_486) 17247c478bd9Sstevel@tonic-gate return ("i486 compatible"); 17257c478bd9Sstevel@tonic-gate 17267c478bd9Sstevel@tonic-gate switch (type) { 17277c478bd9Sstevel@tonic-gate case X86_TYPE_CYRIX_6x86: 17287c478bd9Sstevel@tonic-gate return ("Cyrix 6x86"); 17297c478bd9Sstevel@tonic-gate case X86_TYPE_CYRIX_6x86L: 17307c478bd9Sstevel@tonic-gate return ("Cyrix 6x86L"); 17317c478bd9Sstevel@tonic-gate case X86_TYPE_CYRIX_6x86MX: 17327c478bd9Sstevel@tonic-gate return ("Cyrix 6x86MX"); 17337c478bd9Sstevel@tonic-gate case X86_TYPE_CYRIX_GXm: 17347c478bd9Sstevel@tonic-gate return ("Cyrix GXm"); 17357c478bd9Sstevel@tonic-gate case X86_TYPE_CYRIX_MediaGX: 17367c478bd9Sstevel@tonic-gate return ("Cyrix MediaGX"); 17377c478bd9Sstevel@tonic-gate case X86_TYPE_CYRIX_MII: 17387c478bd9Sstevel@tonic-gate return ("Cyrix M2"); 17397c478bd9Sstevel@tonic-gate case X86_TYPE_VIA_CYRIX_III: 17407c478bd9Sstevel@tonic-gate return ("VIA Cyrix M3"); 17417c478bd9Sstevel@tonic-gate default: 17427c478bd9Sstevel@tonic-gate /* 17437c478bd9Sstevel@tonic-gate * Have another wild guess .. 17447c478bd9Sstevel@tonic-gate */ 17457c478bd9Sstevel@tonic-gate if (cpi->cpi_family == 4 && cpi->cpi_model == 9) 17467c478bd9Sstevel@tonic-gate return ("Cyrix 5x86"); 17477c478bd9Sstevel@tonic-gate else if (cpi->cpi_family == 5) { 17487c478bd9Sstevel@tonic-gate switch (cpi->cpi_model) { 17497c478bd9Sstevel@tonic-gate case 2: 17507c478bd9Sstevel@tonic-gate return ("Cyrix 6x86"); /* Cyrix M1 */ 17517c478bd9Sstevel@tonic-gate case 4: 17527c478bd9Sstevel@tonic-gate return ("Cyrix MediaGX"); 17537c478bd9Sstevel@tonic-gate default: 17547c478bd9Sstevel@tonic-gate break; 17557c478bd9Sstevel@tonic-gate } 17567c478bd9Sstevel@tonic-gate } else if (cpi->cpi_family == 6) { 17577c478bd9Sstevel@tonic-gate switch (cpi->cpi_model) { 17587c478bd9Sstevel@tonic-gate case 0: 17597c478bd9Sstevel@tonic-gate return ("Cyrix 6x86MX"); /* Cyrix M2? */ 17607c478bd9Sstevel@tonic-gate case 5: 17617c478bd9Sstevel@tonic-gate case 6: 17627c478bd9Sstevel@tonic-gate case 7: 17637c478bd9Sstevel@tonic-gate case 8: 17647c478bd9Sstevel@tonic-gate case 9: 17657c478bd9Sstevel@tonic-gate return ("VIA C3"); 17667c478bd9Sstevel@tonic-gate default: 17677c478bd9Sstevel@tonic-gate break; 17687c478bd9Sstevel@tonic-gate } 17697c478bd9Sstevel@tonic-gate } 17707c478bd9Sstevel@tonic-gate break; 17717c478bd9Sstevel@tonic-gate } 17727c478bd9Sstevel@tonic-gate return (NULL); 17737c478bd9Sstevel@tonic-gate } 17747c478bd9Sstevel@tonic-gate 17757c478bd9Sstevel@tonic-gate /* 17767c478bd9Sstevel@tonic-gate * This only gets called in the case that the CPU extended 17777c478bd9Sstevel@tonic-gate * feature brand string (0x80000002, 0x80000003, 0x80000004) 17787c478bd9Sstevel@tonic-gate * aren't available, or contain null bytes for some reason. 17797c478bd9Sstevel@tonic-gate */ 17807c478bd9Sstevel@tonic-gate static void 17817c478bd9Sstevel@tonic-gate fabricate_brandstr(struct cpuid_info *cpi) 17827c478bd9Sstevel@tonic-gate { 17837c478bd9Sstevel@tonic-gate const char *brand = NULL; 17847c478bd9Sstevel@tonic-gate 17857c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 17867c478bd9Sstevel@tonic-gate case X86_VENDOR_Intel: 17877c478bd9Sstevel@tonic-gate brand = intel_cpubrand(cpi); 17887c478bd9Sstevel@tonic-gate break; 17897c478bd9Sstevel@tonic-gate case X86_VENDOR_AMD: 17907c478bd9Sstevel@tonic-gate brand = amd_cpubrand(cpi); 17917c478bd9Sstevel@tonic-gate break; 17927c478bd9Sstevel@tonic-gate case X86_VENDOR_Cyrix: 17937c478bd9Sstevel@tonic-gate brand = cyrix_cpubrand(cpi, x86_type); 17947c478bd9Sstevel@tonic-gate break; 17957c478bd9Sstevel@tonic-gate case X86_VENDOR_NexGen: 17967c478bd9Sstevel@tonic-gate if (cpi->cpi_family == 5 && cpi->cpi_model == 0) 17977c478bd9Sstevel@tonic-gate brand = "NexGen Nx586"; 17987c478bd9Sstevel@tonic-gate break; 17997c478bd9Sstevel@tonic-gate case X86_VENDOR_Centaur: 18007c478bd9Sstevel@tonic-gate if (cpi->cpi_family == 5) 18017c478bd9Sstevel@tonic-gate switch (cpi->cpi_model) { 18027c478bd9Sstevel@tonic-gate case 4: 18037c478bd9Sstevel@tonic-gate brand = "Centaur C6"; 18047c478bd9Sstevel@tonic-gate break; 18057c478bd9Sstevel@tonic-gate case 8: 18067c478bd9Sstevel@tonic-gate brand = "Centaur C2"; 18077c478bd9Sstevel@tonic-gate break; 18087c478bd9Sstevel@tonic-gate case 9: 18097c478bd9Sstevel@tonic-gate brand = "Centaur C3"; 18107c478bd9Sstevel@tonic-gate break; 18117c478bd9Sstevel@tonic-gate default: 18127c478bd9Sstevel@tonic-gate break; 18137c478bd9Sstevel@tonic-gate } 18147c478bd9Sstevel@tonic-gate break; 18157c478bd9Sstevel@tonic-gate case X86_VENDOR_Rise: 18167c478bd9Sstevel@tonic-gate if (cpi->cpi_family == 5 && 18177c478bd9Sstevel@tonic-gate (cpi->cpi_model == 0 || cpi->cpi_model == 2)) 18187c478bd9Sstevel@tonic-gate brand = "Rise mP6"; 18197c478bd9Sstevel@tonic-gate break; 18207c478bd9Sstevel@tonic-gate case X86_VENDOR_SiS: 18217c478bd9Sstevel@tonic-gate if (cpi->cpi_family == 5 && cpi->cpi_model == 0) 18227c478bd9Sstevel@tonic-gate brand = "SiS 55x"; 18237c478bd9Sstevel@tonic-gate break; 18247c478bd9Sstevel@tonic-gate case X86_VENDOR_TM: 18257c478bd9Sstevel@tonic-gate if (cpi->cpi_family == 5 && cpi->cpi_model == 4) 18267c478bd9Sstevel@tonic-gate brand = "Transmeta Crusoe TM3x00 or TM5x00"; 18277c478bd9Sstevel@tonic-gate break; 18287c478bd9Sstevel@tonic-gate case X86_VENDOR_NSC: 18297c478bd9Sstevel@tonic-gate case X86_VENDOR_UMC: 18307c478bd9Sstevel@tonic-gate default: 18317c478bd9Sstevel@tonic-gate break; 18327c478bd9Sstevel@tonic-gate } 18337c478bd9Sstevel@tonic-gate if (brand) { 18347c478bd9Sstevel@tonic-gate (void) strcpy((char *)cpi->cpi_brandstr, brand); 18357c478bd9Sstevel@tonic-gate return; 18367c478bd9Sstevel@tonic-gate } 18377c478bd9Sstevel@tonic-gate 18387c478bd9Sstevel@tonic-gate /* 18397c478bd9Sstevel@tonic-gate * If all else fails ... 18407c478bd9Sstevel@tonic-gate */ 18417c478bd9Sstevel@tonic-gate (void) snprintf(cpi->cpi_brandstr, sizeof (cpi->cpi_brandstr), 18427c478bd9Sstevel@tonic-gate "%s %d.%d.%d", cpi->cpi_vendorstr, cpi->cpi_family, 18437c478bd9Sstevel@tonic-gate cpi->cpi_model, cpi->cpi_step); 18447c478bd9Sstevel@tonic-gate } 18457c478bd9Sstevel@tonic-gate 18467c478bd9Sstevel@tonic-gate /* 18477c478bd9Sstevel@tonic-gate * This routine is called just after kernel memory allocation 18487c478bd9Sstevel@tonic-gate * becomes available on cpu0, and as part of mp_startup() on 18497c478bd9Sstevel@tonic-gate * the other cpus. 18507c478bd9Sstevel@tonic-gate * 1851d129bde2Sesaxe * Fixup the brand string, and collect any information from cpuid 1852d129bde2Sesaxe * that requires dynamicically allocated storage to represent. 18537c478bd9Sstevel@tonic-gate */ 18547c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 18557c478bd9Sstevel@tonic-gate void 18567c478bd9Sstevel@tonic-gate cpuid_pass3(cpu_t *cpu) 18577c478bd9Sstevel@tonic-gate { 1858d129bde2Sesaxe int i, max, shft, level, size; 1859d129bde2Sesaxe struct cpuid_regs regs; 1860d129bde2Sesaxe struct cpuid_regs *cp; 18617c478bd9Sstevel@tonic-gate struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 18627c478bd9Sstevel@tonic-gate 18637c478bd9Sstevel@tonic-gate ASSERT(cpi->cpi_pass == 2); 18647c478bd9Sstevel@tonic-gate 1865d129bde2Sesaxe /* 1866d129bde2Sesaxe * Function 4: Deterministic cache parameters 1867d129bde2Sesaxe * 1868d129bde2Sesaxe * Take this opportunity to detect the number of threads 1869d129bde2Sesaxe * sharing the last level cache, and construct a corresponding 1870d129bde2Sesaxe * cache id. The respective cpuid_info members are initialized 1871d129bde2Sesaxe * to the default case of "no last level cache sharing". 1872d129bde2Sesaxe */ 1873d129bde2Sesaxe cpi->cpi_ncpu_shr_last_cache = 1; 1874d129bde2Sesaxe cpi->cpi_last_lvl_cacheid = cpu->cpu_id; 1875d129bde2Sesaxe 1876d129bde2Sesaxe if (cpi->cpi_maxeax >= 4 && cpi->cpi_vendor == X86_VENDOR_Intel) { 1877d129bde2Sesaxe 1878d129bde2Sesaxe /* 1879d129bde2Sesaxe * Find the # of elements (size) returned by fn 4, and along 1880d129bde2Sesaxe * the way detect last level cache sharing details. 1881d129bde2Sesaxe */ 1882d129bde2Sesaxe bzero(®s, sizeof (regs)); 1883d129bde2Sesaxe cp = ®s; 1884d129bde2Sesaxe for (i = 0, max = 0; i < CPI_FN4_ECX_MAX; i++) { 1885d129bde2Sesaxe cp->cp_eax = 4; 1886d129bde2Sesaxe cp->cp_ecx = i; 1887d129bde2Sesaxe 1888d129bde2Sesaxe (void) __cpuid_insn(cp); 1889d129bde2Sesaxe 1890d129bde2Sesaxe if (CPI_CACHE_TYPE(cp) == 0) 1891d129bde2Sesaxe break; 1892d129bde2Sesaxe level = CPI_CACHE_LVL(cp); 1893d129bde2Sesaxe if (level > max) { 1894d129bde2Sesaxe max = level; 1895d129bde2Sesaxe cpi->cpi_ncpu_shr_last_cache = 1896d129bde2Sesaxe CPI_NTHR_SHR_CACHE(cp) + 1; 1897d129bde2Sesaxe } 1898d129bde2Sesaxe } 1899d129bde2Sesaxe cpi->cpi_std_4_size = size = i; 1900d129bde2Sesaxe 1901d129bde2Sesaxe /* 1902d129bde2Sesaxe * Allocate the cpi_std_4 array. The first element 1903d129bde2Sesaxe * references the regs for fn 4, %ecx == 0, which 1904d129bde2Sesaxe * cpuid_pass2() stashed in cpi->cpi_std[4]. 1905d129bde2Sesaxe */ 1906d129bde2Sesaxe if (size > 0) { 1907d129bde2Sesaxe cpi->cpi_std_4 = 1908d129bde2Sesaxe kmem_alloc(size * sizeof (cp), KM_SLEEP); 1909d129bde2Sesaxe cpi->cpi_std_4[0] = &cpi->cpi_std[4]; 1910d129bde2Sesaxe 1911d129bde2Sesaxe /* 1912d129bde2Sesaxe * Allocate storage to hold the additional regs 1913d129bde2Sesaxe * for function 4, %ecx == 1 .. cpi_std_4_size. 1914d129bde2Sesaxe * 1915d129bde2Sesaxe * The regs for fn 4, %ecx == 0 has already 1916d129bde2Sesaxe * been allocated as indicated above. 1917d129bde2Sesaxe */ 1918d129bde2Sesaxe for (i = 1; i < size; i++) { 1919d129bde2Sesaxe cp = cpi->cpi_std_4[i] = 1920d129bde2Sesaxe kmem_zalloc(sizeof (regs), KM_SLEEP); 1921d129bde2Sesaxe cp->cp_eax = 4; 1922d129bde2Sesaxe cp->cp_ecx = i; 1923d129bde2Sesaxe 1924d129bde2Sesaxe (void) __cpuid_insn(cp); 1925d129bde2Sesaxe } 1926d129bde2Sesaxe } 1927d129bde2Sesaxe /* 1928d129bde2Sesaxe * Determine the number of bits needed to represent 1929d129bde2Sesaxe * the number of CPUs sharing the last level cache. 1930d129bde2Sesaxe * 1931d129bde2Sesaxe * Shift off that number of bits from the APIC id to 1932d129bde2Sesaxe * derive the cache id. 1933d129bde2Sesaxe */ 1934d129bde2Sesaxe shft = 0; 1935d129bde2Sesaxe for (i = 1; i < cpi->cpi_ncpu_shr_last_cache; i <<= 1) 1936d129bde2Sesaxe shft++; 1937b6917abeSmishra cpi->cpi_last_lvl_cacheid = cpi->cpi_apicid >> shft; 1938d129bde2Sesaxe } 1939d129bde2Sesaxe 1940d129bde2Sesaxe /* 1941d129bde2Sesaxe * Now fixup the brand string 1942d129bde2Sesaxe */ 19437c478bd9Sstevel@tonic-gate if ((cpi->cpi_xmaxeax & 0x80000000) == 0) { 19447c478bd9Sstevel@tonic-gate fabricate_brandstr(cpi); 1945d129bde2Sesaxe } else { 19467c478bd9Sstevel@tonic-gate 19477c478bd9Sstevel@tonic-gate /* 19487c478bd9Sstevel@tonic-gate * If we successfully extracted a brand string from the cpuid 19497c478bd9Sstevel@tonic-gate * instruction, clean it up by removing leading spaces and 19507c478bd9Sstevel@tonic-gate * similar junk. 19517c478bd9Sstevel@tonic-gate */ 19527c478bd9Sstevel@tonic-gate if (cpi->cpi_brandstr[0]) { 19537c478bd9Sstevel@tonic-gate size_t maxlen = sizeof (cpi->cpi_brandstr); 19547c478bd9Sstevel@tonic-gate char *src, *dst; 19557c478bd9Sstevel@tonic-gate 19567c478bd9Sstevel@tonic-gate dst = src = (char *)cpi->cpi_brandstr; 19577c478bd9Sstevel@tonic-gate src[maxlen - 1] = '\0'; 19587c478bd9Sstevel@tonic-gate /* 19597c478bd9Sstevel@tonic-gate * strip leading spaces 19607c478bd9Sstevel@tonic-gate */ 19617c478bd9Sstevel@tonic-gate while (*src == ' ') 19627c478bd9Sstevel@tonic-gate src++; 19637c478bd9Sstevel@tonic-gate /* 19647c478bd9Sstevel@tonic-gate * Remove any 'Genuine' or "Authentic" prefixes 19657c478bd9Sstevel@tonic-gate */ 19667c478bd9Sstevel@tonic-gate if (strncmp(src, "Genuine ", 8) == 0) 19677c478bd9Sstevel@tonic-gate src += 8; 19687c478bd9Sstevel@tonic-gate if (strncmp(src, "Authentic ", 10) == 0) 19697c478bd9Sstevel@tonic-gate src += 10; 19707c478bd9Sstevel@tonic-gate 19717c478bd9Sstevel@tonic-gate /* 19727c478bd9Sstevel@tonic-gate * Now do an in-place copy. 19737c478bd9Sstevel@tonic-gate * Map (R) to (r) and (TM) to (tm). 19747c478bd9Sstevel@tonic-gate * The era of teletypes is long gone, and there's 19757c478bd9Sstevel@tonic-gate * -really- no need to shout. 19767c478bd9Sstevel@tonic-gate */ 19777c478bd9Sstevel@tonic-gate while (*src != '\0') { 19787c478bd9Sstevel@tonic-gate if (src[0] == '(') { 19797c478bd9Sstevel@tonic-gate if (strncmp(src + 1, "R)", 2) == 0) { 19807c478bd9Sstevel@tonic-gate (void) strncpy(dst, "(r)", 3); 19817c478bd9Sstevel@tonic-gate src += 3; 19827c478bd9Sstevel@tonic-gate dst += 3; 19837c478bd9Sstevel@tonic-gate continue; 19847c478bd9Sstevel@tonic-gate } 19857c478bd9Sstevel@tonic-gate if (strncmp(src + 1, "TM)", 3) == 0) { 19867c478bd9Sstevel@tonic-gate (void) strncpy(dst, "(tm)", 4); 19877c478bd9Sstevel@tonic-gate src += 4; 19887c478bd9Sstevel@tonic-gate dst += 4; 19897c478bd9Sstevel@tonic-gate continue; 19907c478bd9Sstevel@tonic-gate } 19917c478bd9Sstevel@tonic-gate } 19927c478bd9Sstevel@tonic-gate *dst++ = *src++; 19937c478bd9Sstevel@tonic-gate } 19947c478bd9Sstevel@tonic-gate *dst = '\0'; 19957c478bd9Sstevel@tonic-gate 19967c478bd9Sstevel@tonic-gate /* 19977c478bd9Sstevel@tonic-gate * Finally, remove any trailing spaces 19987c478bd9Sstevel@tonic-gate */ 19997c478bd9Sstevel@tonic-gate while (--dst > cpi->cpi_brandstr) 20007c478bd9Sstevel@tonic-gate if (*dst == ' ') 20017c478bd9Sstevel@tonic-gate *dst = '\0'; 20027c478bd9Sstevel@tonic-gate else 20037c478bd9Sstevel@tonic-gate break; 20047c478bd9Sstevel@tonic-gate } else 20057c478bd9Sstevel@tonic-gate fabricate_brandstr(cpi); 2006d129bde2Sesaxe } 20077c478bd9Sstevel@tonic-gate cpi->cpi_pass = 3; 20087c478bd9Sstevel@tonic-gate } 20097c478bd9Sstevel@tonic-gate 20107c478bd9Sstevel@tonic-gate /* 20117c478bd9Sstevel@tonic-gate * This routine is called out of bind_hwcap() much later in the life 20127c478bd9Sstevel@tonic-gate * of the kernel (post_startup()). The job of this routine is to resolve 20137c478bd9Sstevel@tonic-gate * the hardware feature support and kernel support for those features into 20147c478bd9Sstevel@tonic-gate * what we're actually going to tell applications via the aux vector. 20157c478bd9Sstevel@tonic-gate */ 20167c478bd9Sstevel@tonic-gate uint_t 20177c478bd9Sstevel@tonic-gate cpuid_pass4(cpu_t *cpu) 20187c478bd9Sstevel@tonic-gate { 20197c478bd9Sstevel@tonic-gate struct cpuid_info *cpi; 20207c478bd9Sstevel@tonic-gate uint_t hwcap_flags = 0; 20217c478bd9Sstevel@tonic-gate 20227c478bd9Sstevel@tonic-gate if (cpu == NULL) 20237c478bd9Sstevel@tonic-gate cpu = CPU; 20247c478bd9Sstevel@tonic-gate cpi = cpu->cpu_m.mcpu_cpi; 20257c478bd9Sstevel@tonic-gate 20267c478bd9Sstevel@tonic-gate ASSERT(cpi->cpi_pass == 3); 20277c478bd9Sstevel@tonic-gate 20287c478bd9Sstevel@tonic-gate if (cpi->cpi_maxeax >= 1) { 20297c478bd9Sstevel@tonic-gate uint32_t *edx = &cpi->cpi_support[STD_EDX_FEATURES]; 20307c478bd9Sstevel@tonic-gate uint32_t *ecx = &cpi->cpi_support[STD_ECX_FEATURES]; 20317c478bd9Sstevel@tonic-gate 20327c478bd9Sstevel@tonic-gate *edx = CPI_FEATURES_EDX(cpi); 20337c478bd9Sstevel@tonic-gate *ecx = CPI_FEATURES_ECX(cpi); 20347c478bd9Sstevel@tonic-gate 20357c478bd9Sstevel@tonic-gate /* 20367c478bd9Sstevel@tonic-gate * [these require explicit kernel support] 20377c478bd9Sstevel@tonic-gate */ 20387c478bd9Sstevel@tonic-gate if ((x86_feature & X86_SEP) == 0) 20397c478bd9Sstevel@tonic-gate *edx &= ~CPUID_INTC_EDX_SEP; 20407c478bd9Sstevel@tonic-gate 20417c478bd9Sstevel@tonic-gate if ((x86_feature & X86_SSE) == 0) 20427c478bd9Sstevel@tonic-gate *edx &= ~(CPUID_INTC_EDX_FXSR|CPUID_INTC_EDX_SSE); 20437c478bd9Sstevel@tonic-gate if ((x86_feature & X86_SSE2) == 0) 20447c478bd9Sstevel@tonic-gate *edx &= ~CPUID_INTC_EDX_SSE2; 20457c478bd9Sstevel@tonic-gate 20467c478bd9Sstevel@tonic-gate if ((x86_feature & X86_HTT) == 0) 20477c478bd9Sstevel@tonic-gate *edx &= ~CPUID_INTC_EDX_HTT; 20487c478bd9Sstevel@tonic-gate 20497c478bd9Sstevel@tonic-gate if ((x86_feature & X86_SSE3) == 0) 20507c478bd9Sstevel@tonic-gate *ecx &= ~CPUID_INTC_ECX_SSE3; 20517c478bd9Sstevel@tonic-gate 2052d0f8ff6eSkk208521 if (cpi->cpi_vendor == X86_VENDOR_Intel) { 2053d0f8ff6eSkk208521 if ((x86_feature & X86_SSSE3) == 0) 2054d0f8ff6eSkk208521 *ecx &= ~CPUID_INTC_ECX_SSSE3; 2055d0f8ff6eSkk208521 if ((x86_feature & X86_SSE4_1) == 0) 2056d0f8ff6eSkk208521 *ecx &= ~CPUID_INTC_ECX_SSE4_1; 2057d0f8ff6eSkk208521 if ((x86_feature & X86_SSE4_2) == 0) 2058d0f8ff6eSkk208521 *ecx &= ~CPUID_INTC_ECX_SSE4_2; 2059d0f8ff6eSkk208521 } 2060d0f8ff6eSkk208521 20617c478bd9Sstevel@tonic-gate /* 20627c478bd9Sstevel@tonic-gate * [no explicit support required beyond x87 fp context] 20637c478bd9Sstevel@tonic-gate */ 20647c478bd9Sstevel@tonic-gate if (!fpu_exists) 20657c478bd9Sstevel@tonic-gate *edx &= ~(CPUID_INTC_EDX_FPU | CPUID_INTC_EDX_MMX); 20667c478bd9Sstevel@tonic-gate 20677c478bd9Sstevel@tonic-gate /* 20687c478bd9Sstevel@tonic-gate * Now map the supported feature vector to things that we 20697c478bd9Sstevel@tonic-gate * think userland will care about. 20707c478bd9Sstevel@tonic-gate */ 20717c478bd9Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_SEP) 20727c478bd9Sstevel@tonic-gate hwcap_flags |= AV_386_SEP; 20737c478bd9Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_SSE) 20747c478bd9Sstevel@tonic-gate hwcap_flags |= AV_386_FXSR | AV_386_SSE; 20757c478bd9Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_SSE2) 20767c478bd9Sstevel@tonic-gate hwcap_flags |= AV_386_SSE2; 20777c478bd9Sstevel@tonic-gate if (*ecx & CPUID_INTC_ECX_SSE3) 20787c478bd9Sstevel@tonic-gate hwcap_flags |= AV_386_SSE3; 2079d0f8ff6eSkk208521 if (cpi->cpi_vendor == X86_VENDOR_Intel) { 2080d0f8ff6eSkk208521 if (*ecx & CPUID_INTC_ECX_SSSE3) 2081d0f8ff6eSkk208521 hwcap_flags |= AV_386_SSSE3; 2082d0f8ff6eSkk208521 if (*ecx & CPUID_INTC_ECX_SSE4_1) 2083d0f8ff6eSkk208521 hwcap_flags |= AV_386_SSE4_1; 2084d0f8ff6eSkk208521 if (*ecx & CPUID_INTC_ECX_SSE4_2) 2085d0f8ff6eSkk208521 hwcap_flags |= AV_386_SSE4_2; 20865087e485SKrishnendu Sadhukhan - Sun Microsystems if (*ecx & CPUID_INTC_ECX_MOVBE) 20875087e485SKrishnendu Sadhukhan - Sun Microsystems hwcap_flags |= AV_386_MOVBE; 2088d0f8ff6eSkk208521 } 2089f8801251Skk208521 if (*ecx & CPUID_INTC_ECX_POPCNT) 2090f8801251Skk208521 hwcap_flags |= AV_386_POPCNT; 20917c478bd9Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_FPU) 20927c478bd9Sstevel@tonic-gate hwcap_flags |= AV_386_FPU; 20937c478bd9Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_MMX) 20947c478bd9Sstevel@tonic-gate hwcap_flags |= AV_386_MMX; 20957c478bd9Sstevel@tonic-gate 20967c478bd9Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_TSC) 20977c478bd9Sstevel@tonic-gate hwcap_flags |= AV_386_TSC; 20987c478bd9Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_CX8) 20997c478bd9Sstevel@tonic-gate hwcap_flags |= AV_386_CX8; 21007c478bd9Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_CMOV) 21017c478bd9Sstevel@tonic-gate hwcap_flags |= AV_386_CMOV; 21027c478bd9Sstevel@tonic-gate if (*ecx & CPUID_INTC_ECX_MON) 21037c478bd9Sstevel@tonic-gate hwcap_flags |= AV_386_MON; 21047c478bd9Sstevel@tonic-gate if (*ecx & CPUID_INTC_ECX_CX16) 21057c478bd9Sstevel@tonic-gate hwcap_flags |= AV_386_CX16; 21067c478bd9Sstevel@tonic-gate } 21077c478bd9Sstevel@tonic-gate 21088949bcd6Sandrei if (x86_feature & X86_HTT) 21097c478bd9Sstevel@tonic-gate hwcap_flags |= AV_386_PAUSE; 21107c478bd9Sstevel@tonic-gate 21117c478bd9Sstevel@tonic-gate if (cpi->cpi_xmaxeax < 0x80000001) 21127c478bd9Sstevel@tonic-gate goto pass4_done; 21137c478bd9Sstevel@tonic-gate 21147c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 21158949bcd6Sandrei struct cpuid_regs cp; 2116ae115bc7Smrj uint32_t *edx, *ecx; 21177c478bd9Sstevel@tonic-gate 2118ae115bc7Smrj case X86_VENDOR_Intel: 2119ae115bc7Smrj /* 2120ae115bc7Smrj * Seems like Intel duplicated what we necessary 2121ae115bc7Smrj * here to make the initial crop of 64-bit OS's work. 2122ae115bc7Smrj * Hopefully, those are the only "extended" bits 2123ae115bc7Smrj * they'll add. 2124ae115bc7Smrj */ 2125ae115bc7Smrj /*FALLTHROUGH*/ 2126ae115bc7Smrj 21277c478bd9Sstevel@tonic-gate case X86_VENDOR_AMD: 21287c478bd9Sstevel@tonic-gate edx = &cpi->cpi_support[AMD_EDX_FEATURES]; 2129ae115bc7Smrj ecx = &cpi->cpi_support[AMD_ECX_FEATURES]; 21307c478bd9Sstevel@tonic-gate 21317c478bd9Sstevel@tonic-gate *edx = CPI_FEATURES_XTD_EDX(cpi); 2132ae115bc7Smrj *ecx = CPI_FEATURES_XTD_ECX(cpi); 2133ae115bc7Smrj 2134ae115bc7Smrj /* 2135ae115bc7Smrj * [these features require explicit kernel support] 2136ae115bc7Smrj */ 2137ae115bc7Smrj switch (cpi->cpi_vendor) { 2138ae115bc7Smrj case X86_VENDOR_Intel: 2139d36ea5d8Ssudheer if ((x86_feature & X86_TSCP) == 0) 2140d36ea5d8Ssudheer *edx &= ~CPUID_AMD_EDX_TSCP; 2141ae115bc7Smrj break; 2142ae115bc7Smrj 2143ae115bc7Smrj case X86_VENDOR_AMD: 2144ae115bc7Smrj if ((x86_feature & X86_TSCP) == 0) 2145ae115bc7Smrj *edx &= ~CPUID_AMD_EDX_TSCP; 2146f8801251Skk208521 if ((x86_feature & X86_SSE4A) == 0) 2147f8801251Skk208521 *ecx &= ~CPUID_AMD_ECX_SSE4A; 2148ae115bc7Smrj break; 2149ae115bc7Smrj 2150ae115bc7Smrj default: 2151ae115bc7Smrj break; 2152ae115bc7Smrj } 21537c478bd9Sstevel@tonic-gate 21547c478bd9Sstevel@tonic-gate /* 21557c478bd9Sstevel@tonic-gate * [no explicit support required beyond 21567c478bd9Sstevel@tonic-gate * x87 fp context and exception handlers] 21577c478bd9Sstevel@tonic-gate */ 21587c478bd9Sstevel@tonic-gate if (!fpu_exists) 21597c478bd9Sstevel@tonic-gate *edx &= ~(CPUID_AMD_EDX_MMXamd | 21607c478bd9Sstevel@tonic-gate CPUID_AMD_EDX_3DNow | CPUID_AMD_EDX_3DNowx); 21617c478bd9Sstevel@tonic-gate 21627c478bd9Sstevel@tonic-gate if ((x86_feature & X86_NX) == 0) 21637c478bd9Sstevel@tonic-gate *edx &= ~CPUID_AMD_EDX_NX; 2164ae115bc7Smrj #if !defined(__amd64) 21657c478bd9Sstevel@tonic-gate *edx &= ~CPUID_AMD_EDX_LM; 21667c478bd9Sstevel@tonic-gate #endif 21677c478bd9Sstevel@tonic-gate /* 21687c478bd9Sstevel@tonic-gate * Now map the supported feature vector to 21697c478bd9Sstevel@tonic-gate * things that we think userland will care about. 21707c478bd9Sstevel@tonic-gate */ 2171ae115bc7Smrj #if defined(__amd64) 21727c478bd9Sstevel@tonic-gate if (*edx & CPUID_AMD_EDX_SYSC) 21737c478bd9Sstevel@tonic-gate hwcap_flags |= AV_386_AMD_SYSC; 2174ae115bc7Smrj #endif 21757c478bd9Sstevel@tonic-gate if (*edx & CPUID_AMD_EDX_MMXamd) 21767c478bd9Sstevel@tonic-gate hwcap_flags |= AV_386_AMD_MMX; 21777c478bd9Sstevel@tonic-gate if (*edx & CPUID_AMD_EDX_3DNow) 21787c478bd9Sstevel@tonic-gate hwcap_flags |= AV_386_AMD_3DNow; 21797c478bd9Sstevel@tonic-gate if (*edx & CPUID_AMD_EDX_3DNowx) 21807c478bd9Sstevel@tonic-gate hwcap_flags |= AV_386_AMD_3DNowx; 2181ae115bc7Smrj 2182ae115bc7Smrj switch (cpi->cpi_vendor) { 2183ae115bc7Smrj case X86_VENDOR_AMD: 2184ae115bc7Smrj if (*edx & CPUID_AMD_EDX_TSCP) 2185ae115bc7Smrj hwcap_flags |= AV_386_TSCP; 2186ae115bc7Smrj if (*ecx & CPUID_AMD_ECX_AHF64) 2187ae115bc7Smrj hwcap_flags |= AV_386_AHF; 2188f8801251Skk208521 if (*ecx & CPUID_AMD_ECX_SSE4A) 2189f8801251Skk208521 hwcap_flags |= AV_386_AMD_SSE4A; 2190f8801251Skk208521 if (*ecx & CPUID_AMD_ECX_LZCNT) 2191f8801251Skk208521 hwcap_flags |= AV_386_AMD_LZCNT; 2192ae115bc7Smrj break; 2193ae115bc7Smrj 2194ae115bc7Smrj case X86_VENDOR_Intel: 2195d36ea5d8Ssudheer if (*edx & CPUID_AMD_EDX_TSCP) 2196d36ea5d8Ssudheer hwcap_flags |= AV_386_TSCP; 2197ae115bc7Smrj /* 2198ae115bc7Smrj * Aarrgh. 2199ae115bc7Smrj * Intel uses a different bit in the same word. 2200ae115bc7Smrj */ 2201ae115bc7Smrj if (*ecx & CPUID_INTC_ECX_AHF64) 2202ae115bc7Smrj hwcap_flags |= AV_386_AHF; 2203ae115bc7Smrj break; 2204ae115bc7Smrj 2205ae115bc7Smrj default: 2206ae115bc7Smrj break; 2207ae115bc7Smrj } 22087c478bd9Sstevel@tonic-gate break; 22097c478bd9Sstevel@tonic-gate 22107c478bd9Sstevel@tonic-gate case X86_VENDOR_TM: 22118949bcd6Sandrei cp.cp_eax = 0x80860001; 22128949bcd6Sandrei (void) __cpuid_insn(&cp); 22138949bcd6Sandrei cpi->cpi_support[TM_EDX_FEATURES] = cp.cp_edx; 22147c478bd9Sstevel@tonic-gate break; 22157c478bd9Sstevel@tonic-gate 22167c478bd9Sstevel@tonic-gate default: 22177c478bd9Sstevel@tonic-gate break; 22187c478bd9Sstevel@tonic-gate } 22197c478bd9Sstevel@tonic-gate 22207c478bd9Sstevel@tonic-gate pass4_done: 22217c478bd9Sstevel@tonic-gate cpi->cpi_pass = 4; 22227c478bd9Sstevel@tonic-gate return (hwcap_flags); 22237c478bd9Sstevel@tonic-gate } 22247c478bd9Sstevel@tonic-gate 22257c478bd9Sstevel@tonic-gate 22267c478bd9Sstevel@tonic-gate /* 22277c478bd9Sstevel@tonic-gate * Simulate the cpuid instruction using the data we previously 22287c478bd9Sstevel@tonic-gate * captured about this CPU. We try our best to return the truth 22297c478bd9Sstevel@tonic-gate * about the hardware, independently of kernel support. 22307c478bd9Sstevel@tonic-gate */ 22317c478bd9Sstevel@tonic-gate uint32_t 22328949bcd6Sandrei cpuid_insn(cpu_t *cpu, struct cpuid_regs *cp) 22337c478bd9Sstevel@tonic-gate { 22347c478bd9Sstevel@tonic-gate struct cpuid_info *cpi; 22358949bcd6Sandrei struct cpuid_regs *xcp; 22367c478bd9Sstevel@tonic-gate 22377c478bd9Sstevel@tonic-gate if (cpu == NULL) 22387c478bd9Sstevel@tonic-gate cpu = CPU; 22397c478bd9Sstevel@tonic-gate cpi = cpu->cpu_m.mcpu_cpi; 22407c478bd9Sstevel@tonic-gate 22417c478bd9Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 3)); 22427c478bd9Sstevel@tonic-gate 22437c478bd9Sstevel@tonic-gate /* 22447c478bd9Sstevel@tonic-gate * CPUID data is cached in two separate places: cpi_std for standard 22457c478bd9Sstevel@tonic-gate * CPUID functions, and cpi_extd for extended CPUID functions. 22467c478bd9Sstevel@tonic-gate */ 22478949bcd6Sandrei if (cp->cp_eax <= cpi->cpi_maxeax && cp->cp_eax < NMAX_CPI_STD) 22488949bcd6Sandrei xcp = &cpi->cpi_std[cp->cp_eax]; 22498949bcd6Sandrei else if (cp->cp_eax >= 0x80000000 && cp->cp_eax <= cpi->cpi_xmaxeax && 22508949bcd6Sandrei cp->cp_eax < 0x80000000 + NMAX_CPI_EXTD) 22518949bcd6Sandrei xcp = &cpi->cpi_extd[cp->cp_eax - 0x80000000]; 22527c478bd9Sstevel@tonic-gate else 22537c478bd9Sstevel@tonic-gate /* 22547c478bd9Sstevel@tonic-gate * The caller is asking for data from an input parameter which 22557c478bd9Sstevel@tonic-gate * the kernel has not cached. In this case we go fetch from 22567c478bd9Sstevel@tonic-gate * the hardware and return the data directly to the user. 22577c478bd9Sstevel@tonic-gate */ 22588949bcd6Sandrei return (__cpuid_insn(cp)); 22598949bcd6Sandrei 22608949bcd6Sandrei cp->cp_eax = xcp->cp_eax; 22618949bcd6Sandrei cp->cp_ebx = xcp->cp_ebx; 22628949bcd6Sandrei cp->cp_ecx = xcp->cp_ecx; 22638949bcd6Sandrei cp->cp_edx = xcp->cp_edx; 22647c478bd9Sstevel@tonic-gate return (cp->cp_eax); 22657c478bd9Sstevel@tonic-gate } 22667c478bd9Sstevel@tonic-gate 22677c478bd9Sstevel@tonic-gate int 22687c478bd9Sstevel@tonic-gate cpuid_checkpass(cpu_t *cpu, int pass) 22697c478bd9Sstevel@tonic-gate { 22707c478bd9Sstevel@tonic-gate return (cpu != NULL && cpu->cpu_m.mcpu_cpi != NULL && 22717c478bd9Sstevel@tonic-gate cpu->cpu_m.mcpu_cpi->cpi_pass >= pass); 22727c478bd9Sstevel@tonic-gate } 22737c478bd9Sstevel@tonic-gate 22747c478bd9Sstevel@tonic-gate int 22757c478bd9Sstevel@tonic-gate cpuid_getbrandstr(cpu_t *cpu, char *s, size_t n) 22767c478bd9Sstevel@tonic-gate { 22777c478bd9Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 3)); 22787c478bd9Sstevel@tonic-gate 22797c478bd9Sstevel@tonic-gate return (snprintf(s, n, "%s", cpu->cpu_m.mcpu_cpi->cpi_brandstr)); 22807c478bd9Sstevel@tonic-gate } 22817c478bd9Sstevel@tonic-gate 22827c478bd9Sstevel@tonic-gate int 22838949bcd6Sandrei cpuid_is_cmt(cpu_t *cpu) 22847c478bd9Sstevel@tonic-gate { 22857c478bd9Sstevel@tonic-gate if (cpu == NULL) 22867c478bd9Sstevel@tonic-gate cpu = CPU; 22877c478bd9Sstevel@tonic-gate 22887c478bd9Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 22897c478bd9Sstevel@tonic-gate 22907c478bd9Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_chipid >= 0); 22917c478bd9Sstevel@tonic-gate } 22927c478bd9Sstevel@tonic-gate 22937c478bd9Sstevel@tonic-gate /* 22947c478bd9Sstevel@tonic-gate * AMD and Intel both implement the 64-bit variant of the syscall 22957c478bd9Sstevel@tonic-gate * instruction (syscallq), so if there's -any- support for syscall, 22967c478bd9Sstevel@tonic-gate * cpuid currently says "yes, we support this". 22977c478bd9Sstevel@tonic-gate * 22987c478bd9Sstevel@tonic-gate * However, Intel decided to -not- implement the 32-bit variant of the 22997c478bd9Sstevel@tonic-gate * syscall instruction, so we provide a predicate to allow our caller 23007c478bd9Sstevel@tonic-gate * to test that subtlety here. 2301843e1988Sjohnlev * 2302843e1988Sjohnlev * XXPV Currently, 32-bit syscall instructions don't work via the hypervisor, 2303843e1988Sjohnlev * even in the case where the hardware would in fact support it. 23047c478bd9Sstevel@tonic-gate */ 23057c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 23067c478bd9Sstevel@tonic-gate int 23077c478bd9Sstevel@tonic-gate cpuid_syscall32_insn(cpu_t *cpu) 23087c478bd9Sstevel@tonic-gate { 23097c478bd9Sstevel@tonic-gate ASSERT(cpuid_checkpass((cpu == NULL ? CPU : cpu), 1)); 23107c478bd9Sstevel@tonic-gate 2311843e1988Sjohnlev #if !defined(__xpv) 2312ae115bc7Smrj if (cpu == NULL) 2313ae115bc7Smrj cpu = CPU; 2314ae115bc7Smrj 2315ae115bc7Smrj /*CSTYLED*/ 2316ae115bc7Smrj { 2317ae115bc7Smrj struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 2318ae115bc7Smrj 2319ae115bc7Smrj if (cpi->cpi_vendor == X86_VENDOR_AMD && 2320ae115bc7Smrj cpi->cpi_xmaxeax >= 0x80000001 && 2321ae115bc7Smrj (CPI_FEATURES_XTD_EDX(cpi) & CPUID_AMD_EDX_SYSC)) 2322ae115bc7Smrj return (1); 2323ae115bc7Smrj } 2324843e1988Sjohnlev #endif 23257c478bd9Sstevel@tonic-gate return (0); 23267c478bd9Sstevel@tonic-gate } 23277c478bd9Sstevel@tonic-gate 23287c478bd9Sstevel@tonic-gate int 23297c478bd9Sstevel@tonic-gate cpuid_getidstr(cpu_t *cpu, char *s, size_t n) 23307c478bd9Sstevel@tonic-gate { 23317c478bd9Sstevel@tonic-gate struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 23327c478bd9Sstevel@tonic-gate 23337c478bd9Sstevel@tonic-gate static const char fmt[] = 2334ecfa43a5Sdmick "x86 (%s %X family %d model %d step %d clock %d MHz)"; 23357c478bd9Sstevel@tonic-gate static const char fmt_ht[] = 2336ecfa43a5Sdmick "x86 (chipid 0x%x %s %X family %d model %d step %d clock %d MHz)"; 23377c478bd9Sstevel@tonic-gate 23387c478bd9Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 23397c478bd9Sstevel@tonic-gate 23408949bcd6Sandrei if (cpuid_is_cmt(cpu)) 23417c478bd9Sstevel@tonic-gate return (snprintf(s, n, fmt_ht, cpi->cpi_chipid, 2342ecfa43a5Sdmick cpi->cpi_vendorstr, cpi->cpi_std[1].cp_eax, 2343ecfa43a5Sdmick cpi->cpi_family, cpi->cpi_model, 23447c478bd9Sstevel@tonic-gate cpi->cpi_step, cpu->cpu_type_info.pi_clock)); 23457c478bd9Sstevel@tonic-gate return (snprintf(s, n, fmt, 2346ecfa43a5Sdmick cpi->cpi_vendorstr, cpi->cpi_std[1].cp_eax, 2347ecfa43a5Sdmick cpi->cpi_family, cpi->cpi_model, 23487c478bd9Sstevel@tonic-gate cpi->cpi_step, cpu->cpu_type_info.pi_clock)); 23497c478bd9Sstevel@tonic-gate } 23507c478bd9Sstevel@tonic-gate 23517c478bd9Sstevel@tonic-gate const char * 23527c478bd9Sstevel@tonic-gate cpuid_getvendorstr(cpu_t *cpu) 23537c478bd9Sstevel@tonic-gate { 23547c478bd9Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 23557c478bd9Sstevel@tonic-gate return ((const char *)cpu->cpu_m.mcpu_cpi->cpi_vendorstr); 23567c478bd9Sstevel@tonic-gate } 23577c478bd9Sstevel@tonic-gate 23587c478bd9Sstevel@tonic-gate uint_t 23597c478bd9Sstevel@tonic-gate cpuid_getvendor(cpu_t *cpu) 23607c478bd9Sstevel@tonic-gate { 23617c478bd9Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 23627c478bd9Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_vendor); 23637c478bd9Sstevel@tonic-gate } 23647c478bd9Sstevel@tonic-gate 23657c478bd9Sstevel@tonic-gate uint_t 23667c478bd9Sstevel@tonic-gate cpuid_getfamily(cpu_t *cpu) 23677c478bd9Sstevel@tonic-gate { 23687c478bd9Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 23697c478bd9Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_family); 23707c478bd9Sstevel@tonic-gate } 23717c478bd9Sstevel@tonic-gate 23727c478bd9Sstevel@tonic-gate uint_t 23737c478bd9Sstevel@tonic-gate cpuid_getmodel(cpu_t *cpu) 23747c478bd9Sstevel@tonic-gate { 23757c478bd9Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 23767c478bd9Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_model); 23777c478bd9Sstevel@tonic-gate } 23787c478bd9Sstevel@tonic-gate 23797c478bd9Sstevel@tonic-gate uint_t 23807c478bd9Sstevel@tonic-gate cpuid_get_ncpu_per_chip(cpu_t *cpu) 23817c478bd9Sstevel@tonic-gate { 23827c478bd9Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 23837c478bd9Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_ncpu_per_chip); 23847c478bd9Sstevel@tonic-gate } 23857c478bd9Sstevel@tonic-gate 23867c478bd9Sstevel@tonic-gate uint_t 23878949bcd6Sandrei cpuid_get_ncore_per_chip(cpu_t *cpu) 23888949bcd6Sandrei { 23898949bcd6Sandrei ASSERT(cpuid_checkpass(cpu, 1)); 23908949bcd6Sandrei return (cpu->cpu_m.mcpu_cpi->cpi_ncore_per_chip); 23918949bcd6Sandrei } 23928949bcd6Sandrei 23938949bcd6Sandrei uint_t 2394d129bde2Sesaxe cpuid_get_ncpu_sharing_last_cache(cpu_t *cpu) 2395d129bde2Sesaxe { 2396d129bde2Sesaxe ASSERT(cpuid_checkpass(cpu, 2)); 2397d129bde2Sesaxe return (cpu->cpu_m.mcpu_cpi->cpi_ncpu_shr_last_cache); 2398d129bde2Sesaxe } 2399d129bde2Sesaxe 2400d129bde2Sesaxe id_t 2401d129bde2Sesaxe cpuid_get_last_lvl_cacheid(cpu_t *cpu) 2402d129bde2Sesaxe { 2403d129bde2Sesaxe ASSERT(cpuid_checkpass(cpu, 2)); 2404d129bde2Sesaxe return (cpu->cpu_m.mcpu_cpi->cpi_last_lvl_cacheid); 2405d129bde2Sesaxe } 2406d129bde2Sesaxe 2407d129bde2Sesaxe uint_t 24087c478bd9Sstevel@tonic-gate cpuid_getstep(cpu_t *cpu) 24097c478bd9Sstevel@tonic-gate { 24107c478bd9Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 24117c478bd9Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_step); 24127c478bd9Sstevel@tonic-gate } 24137c478bd9Sstevel@tonic-gate 24142449e17fSsherrym uint_t 24152449e17fSsherrym cpuid_getsig(struct cpu *cpu) 24162449e17fSsherrym { 24172449e17fSsherrym ASSERT(cpuid_checkpass(cpu, 1)); 24182449e17fSsherrym return (cpu->cpu_m.mcpu_cpi->cpi_std[1].cp_eax); 24192449e17fSsherrym } 24202449e17fSsherrym 24218a40a695Sgavinm uint32_t 24228a40a695Sgavinm cpuid_getchiprev(struct cpu *cpu) 24238a40a695Sgavinm { 24248a40a695Sgavinm ASSERT(cpuid_checkpass(cpu, 1)); 24258a40a695Sgavinm return (cpu->cpu_m.mcpu_cpi->cpi_chiprev); 24268a40a695Sgavinm } 24278a40a695Sgavinm 24288a40a695Sgavinm const char * 24298a40a695Sgavinm cpuid_getchiprevstr(struct cpu *cpu) 24308a40a695Sgavinm { 24318a40a695Sgavinm ASSERT(cpuid_checkpass(cpu, 1)); 24328a40a695Sgavinm return (cpu->cpu_m.mcpu_cpi->cpi_chiprevstr); 24338a40a695Sgavinm } 24348a40a695Sgavinm 24358a40a695Sgavinm uint32_t 24368a40a695Sgavinm cpuid_getsockettype(struct cpu *cpu) 24378a40a695Sgavinm { 24388a40a695Sgavinm ASSERT(cpuid_checkpass(cpu, 1)); 24398a40a695Sgavinm return (cpu->cpu_m.mcpu_cpi->cpi_socket); 24408a40a695Sgavinm } 24418a40a695Sgavinm 2442fb2f18f8Sesaxe int 2443fb2f18f8Sesaxe cpuid_get_chipid(cpu_t *cpu) 24447c478bd9Sstevel@tonic-gate { 24457c478bd9Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 24467c478bd9Sstevel@tonic-gate 24478949bcd6Sandrei if (cpuid_is_cmt(cpu)) 24487c478bd9Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_chipid); 24497c478bd9Sstevel@tonic-gate return (cpu->cpu_id); 24507c478bd9Sstevel@tonic-gate } 24517c478bd9Sstevel@tonic-gate 24528949bcd6Sandrei id_t 2453fb2f18f8Sesaxe cpuid_get_coreid(cpu_t *cpu) 24548949bcd6Sandrei { 24558949bcd6Sandrei ASSERT(cpuid_checkpass(cpu, 1)); 24568949bcd6Sandrei return (cpu->cpu_m.mcpu_cpi->cpi_coreid); 24578949bcd6Sandrei } 24588949bcd6Sandrei 24597c478bd9Sstevel@tonic-gate int 246010569901Sgavinm cpuid_get_pkgcoreid(cpu_t *cpu) 246110569901Sgavinm { 246210569901Sgavinm ASSERT(cpuid_checkpass(cpu, 1)); 246310569901Sgavinm return (cpu->cpu_m.mcpu_cpi->cpi_pkgcoreid); 246410569901Sgavinm } 246510569901Sgavinm 246610569901Sgavinm int 2467fb2f18f8Sesaxe cpuid_get_clogid(cpu_t *cpu) 24687c478bd9Sstevel@tonic-gate { 24697c478bd9Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 24707c478bd9Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_clogid); 24717c478bd9Sstevel@tonic-gate } 24727c478bd9Sstevel@tonic-gate 24737c478bd9Sstevel@tonic-gate void 24747c478bd9Sstevel@tonic-gate cpuid_get_addrsize(cpu_t *cpu, uint_t *pabits, uint_t *vabits) 24757c478bd9Sstevel@tonic-gate { 24767c478bd9Sstevel@tonic-gate struct cpuid_info *cpi; 24777c478bd9Sstevel@tonic-gate 24787c478bd9Sstevel@tonic-gate if (cpu == NULL) 24797c478bd9Sstevel@tonic-gate cpu = CPU; 24807c478bd9Sstevel@tonic-gate cpi = cpu->cpu_m.mcpu_cpi; 24817c478bd9Sstevel@tonic-gate 24827c478bd9Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 24837c478bd9Sstevel@tonic-gate 24847c478bd9Sstevel@tonic-gate if (pabits) 24857c478bd9Sstevel@tonic-gate *pabits = cpi->cpi_pabits; 24867c478bd9Sstevel@tonic-gate if (vabits) 24877c478bd9Sstevel@tonic-gate *vabits = cpi->cpi_vabits; 24887c478bd9Sstevel@tonic-gate } 24897c478bd9Sstevel@tonic-gate 24907c478bd9Sstevel@tonic-gate /* 24917c478bd9Sstevel@tonic-gate * Returns the number of data TLB entries for a corresponding 24927c478bd9Sstevel@tonic-gate * pagesize. If it can't be computed, or isn't known, the 24937c478bd9Sstevel@tonic-gate * routine returns zero. If you ask about an architecturally 24947c478bd9Sstevel@tonic-gate * impossible pagesize, the routine will panic (so that the 24957c478bd9Sstevel@tonic-gate * hat implementor knows that things are inconsistent.) 24967c478bd9Sstevel@tonic-gate */ 24977c478bd9Sstevel@tonic-gate uint_t 24987c478bd9Sstevel@tonic-gate cpuid_get_dtlb_nent(cpu_t *cpu, size_t pagesize) 24997c478bd9Sstevel@tonic-gate { 25007c478bd9Sstevel@tonic-gate struct cpuid_info *cpi; 25017c478bd9Sstevel@tonic-gate uint_t dtlb_nent = 0; 25027c478bd9Sstevel@tonic-gate 25037c478bd9Sstevel@tonic-gate if (cpu == NULL) 25047c478bd9Sstevel@tonic-gate cpu = CPU; 25057c478bd9Sstevel@tonic-gate cpi = cpu->cpu_m.mcpu_cpi; 25067c478bd9Sstevel@tonic-gate 25077c478bd9Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 25087c478bd9Sstevel@tonic-gate 25097c478bd9Sstevel@tonic-gate /* 25107c478bd9Sstevel@tonic-gate * Check the L2 TLB info 25117c478bd9Sstevel@tonic-gate */ 25127c478bd9Sstevel@tonic-gate if (cpi->cpi_xmaxeax >= 0x80000006) { 25138949bcd6Sandrei struct cpuid_regs *cp = &cpi->cpi_extd[6]; 25147c478bd9Sstevel@tonic-gate 25157c478bd9Sstevel@tonic-gate switch (pagesize) { 25167c478bd9Sstevel@tonic-gate 25177c478bd9Sstevel@tonic-gate case 4 * 1024: 25187c478bd9Sstevel@tonic-gate /* 25197c478bd9Sstevel@tonic-gate * All zero in the top 16 bits of the register 25207c478bd9Sstevel@tonic-gate * indicates a unified TLB. Size is in low 16 bits. 25217c478bd9Sstevel@tonic-gate */ 25227c478bd9Sstevel@tonic-gate if ((cp->cp_ebx & 0xffff0000) == 0) 25237c478bd9Sstevel@tonic-gate dtlb_nent = cp->cp_ebx & 0x0000ffff; 25247c478bd9Sstevel@tonic-gate else 25257c478bd9Sstevel@tonic-gate dtlb_nent = BITX(cp->cp_ebx, 27, 16); 25267c478bd9Sstevel@tonic-gate break; 25277c478bd9Sstevel@tonic-gate 25287c478bd9Sstevel@tonic-gate case 2 * 1024 * 1024: 25297c478bd9Sstevel@tonic-gate if ((cp->cp_eax & 0xffff0000) == 0) 25307c478bd9Sstevel@tonic-gate dtlb_nent = cp->cp_eax & 0x0000ffff; 25317c478bd9Sstevel@tonic-gate else 25327c478bd9Sstevel@tonic-gate dtlb_nent = BITX(cp->cp_eax, 27, 16); 25337c478bd9Sstevel@tonic-gate break; 25347c478bd9Sstevel@tonic-gate 25357c478bd9Sstevel@tonic-gate default: 25367c478bd9Sstevel@tonic-gate panic("unknown L2 pagesize"); 25377c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 25387c478bd9Sstevel@tonic-gate } 25397c478bd9Sstevel@tonic-gate } 25407c478bd9Sstevel@tonic-gate 25417c478bd9Sstevel@tonic-gate if (dtlb_nent != 0) 25427c478bd9Sstevel@tonic-gate return (dtlb_nent); 25437c478bd9Sstevel@tonic-gate 25447c478bd9Sstevel@tonic-gate /* 25457c478bd9Sstevel@tonic-gate * No L2 TLB support for this size, try L1. 25467c478bd9Sstevel@tonic-gate */ 25477c478bd9Sstevel@tonic-gate if (cpi->cpi_xmaxeax >= 0x80000005) { 25488949bcd6Sandrei struct cpuid_regs *cp = &cpi->cpi_extd[5]; 25497c478bd9Sstevel@tonic-gate 25507c478bd9Sstevel@tonic-gate switch (pagesize) { 25517c478bd9Sstevel@tonic-gate case 4 * 1024: 25527c478bd9Sstevel@tonic-gate dtlb_nent = BITX(cp->cp_ebx, 23, 16); 25537c478bd9Sstevel@tonic-gate break; 25547c478bd9Sstevel@tonic-gate case 2 * 1024 * 1024: 25557c478bd9Sstevel@tonic-gate dtlb_nent = BITX(cp->cp_eax, 23, 16); 25567c478bd9Sstevel@tonic-gate break; 25577c478bd9Sstevel@tonic-gate default: 25587c478bd9Sstevel@tonic-gate panic("unknown L1 d-TLB pagesize"); 25597c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 25607c478bd9Sstevel@tonic-gate } 25617c478bd9Sstevel@tonic-gate } 25627c478bd9Sstevel@tonic-gate 25637c478bd9Sstevel@tonic-gate return (dtlb_nent); 25647c478bd9Sstevel@tonic-gate } 25657c478bd9Sstevel@tonic-gate 25667c478bd9Sstevel@tonic-gate /* 25677c478bd9Sstevel@tonic-gate * Return 0 if the erratum is not present or not applicable, positive 25687c478bd9Sstevel@tonic-gate * if it is, and negative if the status of the erratum is unknown. 25697c478bd9Sstevel@tonic-gate * 25707c478bd9Sstevel@tonic-gate * See "Revision Guide for AMD Athlon(tm) 64 and AMD Opteron(tm) 25712201b277Skucharsk * Processors" #25759, Rev 3.57, August 2005 25727c478bd9Sstevel@tonic-gate */ 25737c478bd9Sstevel@tonic-gate int 25747c478bd9Sstevel@tonic-gate cpuid_opteron_erratum(cpu_t *cpu, uint_t erratum) 25757c478bd9Sstevel@tonic-gate { 25767c478bd9Sstevel@tonic-gate struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 25778949bcd6Sandrei uint_t eax; 25787c478bd9Sstevel@tonic-gate 2579ea99987eSsethg /* 2580ea99987eSsethg * Bail out if this CPU isn't an AMD CPU, or if it's 2581ea99987eSsethg * a legacy (32-bit) AMD CPU. 2582ea99987eSsethg */ 2583ea99987eSsethg if (cpi->cpi_vendor != X86_VENDOR_AMD || 2584875b116eSkchow cpi->cpi_family == 4 || cpi->cpi_family == 5 || 2585875b116eSkchow cpi->cpi_family == 6) 25868a40a695Sgavinm 25877c478bd9Sstevel@tonic-gate return (0); 25887c478bd9Sstevel@tonic-gate 25897c478bd9Sstevel@tonic-gate eax = cpi->cpi_std[1].cp_eax; 25907c478bd9Sstevel@tonic-gate 25917c478bd9Sstevel@tonic-gate #define SH_B0(eax) (eax == 0xf40 || eax == 0xf50) 25927c478bd9Sstevel@tonic-gate #define SH_B3(eax) (eax == 0xf51) 2593ee88d2b9Skchow #define B(eax) (SH_B0(eax) || SH_B3(eax)) 25947c478bd9Sstevel@tonic-gate 25957c478bd9Sstevel@tonic-gate #define SH_C0(eax) (eax == 0xf48 || eax == 0xf58) 25967c478bd9Sstevel@tonic-gate 25977c478bd9Sstevel@tonic-gate #define SH_CG(eax) (eax == 0xf4a || eax == 0xf5a || eax == 0xf7a) 25987c478bd9Sstevel@tonic-gate #define DH_CG(eax) (eax == 0xfc0 || eax == 0xfe0 || eax == 0xff0) 25997c478bd9Sstevel@tonic-gate #define CH_CG(eax) (eax == 0xf82 || eax == 0xfb2) 2600ee88d2b9Skchow #define CG(eax) (SH_CG(eax) || DH_CG(eax) || CH_CG(eax)) 26017c478bd9Sstevel@tonic-gate 26027c478bd9Sstevel@tonic-gate #define SH_D0(eax) (eax == 0x10f40 || eax == 0x10f50 || eax == 0x10f70) 26037c478bd9Sstevel@tonic-gate #define DH_D0(eax) (eax == 0x10fc0 || eax == 0x10ff0) 26047c478bd9Sstevel@tonic-gate #define CH_D0(eax) (eax == 0x10f80 || eax == 0x10fb0) 2605ee88d2b9Skchow #define D0(eax) (SH_D0(eax) || DH_D0(eax) || CH_D0(eax)) 26067c478bd9Sstevel@tonic-gate 26077c478bd9Sstevel@tonic-gate #define SH_E0(eax) (eax == 0x20f50 || eax == 0x20f40 || eax == 0x20f70) 26087c478bd9Sstevel@tonic-gate #define JH_E1(eax) (eax == 0x20f10) /* JH8_E0 had 0x20f30 */ 26097c478bd9Sstevel@tonic-gate #define DH_E3(eax) (eax == 0x20fc0 || eax == 0x20ff0) 26107c478bd9Sstevel@tonic-gate #define SH_E4(eax) (eax == 0x20f51 || eax == 0x20f71) 26117c478bd9Sstevel@tonic-gate #define BH_E4(eax) (eax == 0x20fb1) 26127c478bd9Sstevel@tonic-gate #define SH_E5(eax) (eax == 0x20f42) 26137c478bd9Sstevel@tonic-gate #define DH_E6(eax) (eax == 0x20ff2 || eax == 0x20fc2) 26147c478bd9Sstevel@tonic-gate #define JH_E6(eax) (eax == 0x20f12 || eax == 0x20f32) 2615ee88d2b9Skchow #define EX(eax) (SH_E0(eax) || JH_E1(eax) || DH_E3(eax) || \ 2616ee88d2b9Skchow SH_E4(eax) || BH_E4(eax) || SH_E5(eax) || \ 2617ee88d2b9Skchow DH_E6(eax) || JH_E6(eax)) 26187c478bd9Sstevel@tonic-gate 2619512cf780Skchow #define DR_AX(eax) (eax == 0x100f00 || eax == 0x100f01 || eax == 0x100f02) 2620512cf780Skchow #define DR_B0(eax) (eax == 0x100f20) 2621512cf780Skchow #define DR_B1(eax) (eax == 0x100f21) 2622512cf780Skchow #define DR_BA(eax) (eax == 0x100f2a) 2623512cf780Skchow #define DR_B2(eax) (eax == 0x100f22) 2624512cf780Skchow #define DR_B3(eax) (eax == 0x100f23) 2625512cf780Skchow #define RB_C0(eax) (eax == 0x100f40) 2626512cf780Skchow 26277c478bd9Sstevel@tonic-gate switch (erratum) { 26287c478bd9Sstevel@tonic-gate case 1: 2629875b116eSkchow return (cpi->cpi_family < 0x10); 26307c478bd9Sstevel@tonic-gate case 51: /* what does the asterisk mean? */ 26317c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax)); 26327c478bd9Sstevel@tonic-gate case 52: 26337c478bd9Sstevel@tonic-gate return (B(eax)); 26347c478bd9Sstevel@tonic-gate case 57: 2635512cf780Skchow return (cpi->cpi_family <= 0x11); 26367c478bd9Sstevel@tonic-gate case 58: 26377c478bd9Sstevel@tonic-gate return (B(eax)); 26387c478bd9Sstevel@tonic-gate case 60: 2639512cf780Skchow return (cpi->cpi_family <= 0x11); 26407c478bd9Sstevel@tonic-gate case 61: 26417c478bd9Sstevel@tonic-gate case 62: 26427c478bd9Sstevel@tonic-gate case 63: 26437c478bd9Sstevel@tonic-gate case 64: 26447c478bd9Sstevel@tonic-gate case 65: 26457c478bd9Sstevel@tonic-gate case 66: 26467c478bd9Sstevel@tonic-gate case 68: 26477c478bd9Sstevel@tonic-gate case 69: 26487c478bd9Sstevel@tonic-gate case 70: 26497c478bd9Sstevel@tonic-gate case 71: 26507c478bd9Sstevel@tonic-gate return (B(eax)); 26517c478bd9Sstevel@tonic-gate case 72: 26527c478bd9Sstevel@tonic-gate return (SH_B0(eax)); 26537c478bd9Sstevel@tonic-gate case 74: 26547c478bd9Sstevel@tonic-gate return (B(eax)); 26557c478bd9Sstevel@tonic-gate case 75: 2656875b116eSkchow return (cpi->cpi_family < 0x10); 26577c478bd9Sstevel@tonic-gate case 76: 26587c478bd9Sstevel@tonic-gate return (B(eax)); 26597c478bd9Sstevel@tonic-gate case 77: 2660512cf780Skchow return (cpi->cpi_family <= 0x11); 26617c478bd9Sstevel@tonic-gate case 78: 26627c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax)); 26637c478bd9Sstevel@tonic-gate case 79: 26647c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax) || EX(eax)); 26657c478bd9Sstevel@tonic-gate case 80: 26667c478bd9Sstevel@tonic-gate case 81: 26677c478bd9Sstevel@tonic-gate case 82: 26687c478bd9Sstevel@tonic-gate return (B(eax)); 26697c478bd9Sstevel@tonic-gate case 83: 26707c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax)); 26717c478bd9Sstevel@tonic-gate case 85: 2672875b116eSkchow return (cpi->cpi_family < 0x10); 26737c478bd9Sstevel@tonic-gate case 86: 26747c478bd9Sstevel@tonic-gate return (SH_C0(eax) || CG(eax)); 26757c478bd9Sstevel@tonic-gate case 88: 26767c478bd9Sstevel@tonic-gate #if !defined(__amd64) 26777c478bd9Sstevel@tonic-gate return (0); 26787c478bd9Sstevel@tonic-gate #else 26797c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax)); 26807c478bd9Sstevel@tonic-gate #endif 26817c478bd9Sstevel@tonic-gate case 89: 2682875b116eSkchow return (cpi->cpi_family < 0x10); 26837c478bd9Sstevel@tonic-gate case 90: 26847c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax)); 26857c478bd9Sstevel@tonic-gate case 91: 26867c478bd9Sstevel@tonic-gate case 92: 26877c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax)); 26887c478bd9Sstevel@tonic-gate case 93: 26897c478bd9Sstevel@tonic-gate return (SH_C0(eax)); 26907c478bd9Sstevel@tonic-gate case 94: 26917c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax)); 26927c478bd9Sstevel@tonic-gate case 95: 26937c478bd9Sstevel@tonic-gate #if !defined(__amd64) 26947c478bd9Sstevel@tonic-gate return (0); 26957c478bd9Sstevel@tonic-gate #else 26967c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax)); 26977c478bd9Sstevel@tonic-gate #endif 26987c478bd9Sstevel@tonic-gate case 96: 26997c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax)); 27007c478bd9Sstevel@tonic-gate case 97: 27017c478bd9Sstevel@tonic-gate case 98: 27027c478bd9Sstevel@tonic-gate return (SH_C0(eax) || CG(eax)); 27037c478bd9Sstevel@tonic-gate case 99: 27047c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax)); 27057c478bd9Sstevel@tonic-gate case 100: 27067c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax)); 27077c478bd9Sstevel@tonic-gate case 101: 27087c478bd9Sstevel@tonic-gate case 103: 27097c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax)); 27107c478bd9Sstevel@tonic-gate case 104: 27117c478bd9Sstevel@tonic-gate return (SH_C0(eax) || CG(eax) || D0(eax)); 27127c478bd9Sstevel@tonic-gate case 105: 27137c478bd9Sstevel@tonic-gate case 106: 27147c478bd9Sstevel@tonic-gate case 107: 27157c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax)); 27167c478bd9Sstevel@tonic-gate case 108: 27177c478bd9Sstevel@tonic-gate return (DH_CG(eax)); 27187c478bd9Sstevel@tonic-gate case 109: 27197c478bd9Sstevel@tonic-gate return (SH_C0(eax) || CG(eax) || D0(eax)); 27207c478bd9Sstevel@tonic-gate case 110: 27217c478bd9Sstevel@tonic-gate return (D0(eax) || EX(eax)); 27227c478bd9Sstevel@tonic-gate case 111: 27237c478bd9Sstevel@tonic-gate return (CG(eax)); 27247c478bd9Sstevel@tonic-gate case 112: 27257c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax) || EX(eax)); 27267c478bd9Sstevel@tonic-gate case 113: 27277c478bd9Sstevel@tonic-gate return (eax == 0x20fc0); 27287c478bd9Sstevel@tonic-gate case 114: 27297c478bd9Sstevel@tonic-gate return (SH_E0(eax) || JH_E1(eax) || DH_E3(eax)); 27307c478bd9Sstevel@tonic-gate case 115: 27317c478bd9Sstevel@tonic-gate return (SH_E0(eax) || JH_E1(eax)); 27327c478bd9Sstevel@tonic-gate case 116: 27337c478bd9Sstevel@tonic-gate return (SH_E0(eax) || JH_E1(eax) || DH_E3(eax)); 27347c478bd9Sstevel@tonic-gate case 117: 27357c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax)); 27367c478bd9Sstevel@tonic-gate case 118: 27377c478bd9Sstevel@tonic-gate return (SH_E0(eax) || JH_E1(eax) || SH_E4(eax) || BH_E4(eax) || 27387c478bd9Sstevel@tonic-gate JH_E6(eax)); 27397c478bd9Sstevel@tonic-gate case 121: 27407c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax) || EX(eax)); 27417c478bd9Sstevel@tonic-gate case 122: 2742512cf780Skchow return (cpi->cpi_family < 0x10 || cpi->cpi_family == 0x11); 27437c478bd9Sstevel@tonic-gate case 123: 27447c478bd9Sstevel@tonic-gate return (JH_E1(eax) || BH_E4(eax) || JH_E6(eax)); 27452201b277Skucharsk case 131: 2746875b116eSkchow return (cpi->cpi_family < 0x10); 2747ef50d8c0Sesaxe case 6336786: 2748ef50d8c0Sesaxe /* 2749ef50d8c0Sesaxe * Test for AdvPowerMgmtInfo.TscPStateInvariant 2750875b116eSkchow * if this is a K8 family or newer processor 2751ef50d8c0Sesaxe */ 2752ef50d8c0Sesaxe if (CPI_FAMILY(cpi) == 0xf) { 27538949bcd6Sandrei struct cpuid_regs regs; 27548949bcd6Sandrei regs.cp_eax = 0x80000007; 27558949bcd6Sandrei (void) __cpuid_insn(®s); 27568949bcd6Sandrei return (!(regs.cp_edx & 0x100)); 2757ef50d8c0Sesaxe } 2758ef50d8c0Sesaxe return (0); 2759ee88d2b9Skchow case 6323525: 2760ee88d2b9Skchow return (((((eax >> 12) & 0xff00) + (eax & 0xf00)) | 2761ee88d2b9Skchow (((eax >> 4) & 0xf) | ((eax >> 12) & 0xf0))) < 0xf40); 2762ee88d2b9Skchow 2763512cf780Skchow case 6671130: 2764512cf780Skchow /* 2765512cf780Skchow * check for processors (pre-Shanghai) that do not provide 2766512cf780Skchow * optimal management of 1gb ptes in its tlb. 2767512cf780Skchow */ 2768512cf780Skchow return (cpi->cpi_family == 0x10 && cpi->cpi_model < 4); 2769512cf780Skchow 2770512cf780Skchow case 298: 2771512cf780Skchow return (DR_AX(eax) || DR_B0(eax) || DR_B1(eax) || DR_BA(eax) || 2772512cf780Skchow DR_B2(eax) || RB_C0(eax)); 2773512cf780Skchow 2774512cf780Skchow default: 2775512cf780Skchow return (-1); 2776512cf780Skchow 2777512cf780Skchow } 2778512cf780Skchow } 2779512cf780Skchow 2780512cf780Skchow /* 2781512cf780Skchow * Determine if specified erratum is present via OSVW (OS Visible Workaround). 2782512cf780Skchow * Return 1 if erratum is present, 0 if not present and -1 if indeterminate. 2783512cf780Skchow */ 2784512cf780Skchow int 2785512cf780Skchow osvw_opteron_erratum(cpu_t *cpu, uint_t erratum) 2786512cf780Skchow { 2787512cf780Skchow struct cpuid_info *cpi; 2788512cf780Skchow uint_t osvwid; 2789512cf780Skchow static int osvwfeature = -1; 2790512cf780Skchow uint64_t osvwlength; 2791512cf780Skchow 2792512cf780Skchow 2793512cf780Skchow cpi = cpu->cpu_m.mcpu_cpi; 2794512cf780Skchow 2795512cf780Skchow /* confirm OSVW supported */ 2796512cf780Skchow if (osvwfeature == -1) { 2797512cf780Skchow osvwfeature = cpi->cpi_extd[1].cp_ecx & CPUID_AMD_ECX_OSVW; 2798512cf780Skchow } else { 2799512cf780Skchow /* assert that osvw feature setting is consistent on all cpus */ 2800512cf780Skchow ASSERT(osvwfeature == 2801512cf780Skchow (cpi->cpi_extd[1].cp_ecx & CPUID_AMD_ECX_OSVW)); 2802512cf780Skchow } 2803512cf780Skchow if (!osvwfeature) 2804512cf780Skchow return (-1); 2805512cf780Skchow 2806512cf780Skchow osvwlength = rdmsr(MSR_AMD_OSVW_ID_LEN) & OSVW_ID_LEN_MASK; 2807512cf780Skchow 2808512cf780Skchow switch (erratum) { 2809512cf780Skchow case 298: /* osvwid is 0 */ 2810512cf780Skchow osvwid = 0; 2811512cf780Skchow if (osvwlength <= (uint64_t)osvwid) { 2812512cf780Skchow /* osvwid 0 is unknown */ 2813512cf780Skchow return (-1); 2814512cf780Skchow } 2815512cf780Skchow 2816512cf780Skchow /* 2817512cf780Skchow * Check the OSVW STATUS MSR to determine the state 2818512cf780Skchow * of the erratum where: 2819512cf780Skchow * 0 - fixed by HW 2820512cf780Skchow * 1 - BIOS has applied the workaround when BIOS 2821512cf780Skchow * workaround is available. (Or for other errata, 2822512cf780Skchow * OS workaround is required.) 2823512cf780Skchow * For a value of 1, caller will confirm that the 2824512cf780Skchow * erratum 298 workaround has indeed been applied by BIOS. 2825512cf780Skchow * 2826512cf780Skchow * A 1 may be set in cpus that have a HW fix 2827512cf780Skchow * in a mixed cpu system. Regarding erratum 298: 2828512cf780Skchow * In a multiprocessor platform, the workaround above 2829512cf780Skchow * should be applied to all processors regardless of 2830512cf780Skchow * silicon revision when an affected processor is 2831512cf780Skchow * present. 2832512cf780Skchow */ 2833512cf780Skchow 2834512cf780Skchow return (rdmsr(MSR_AMD_OSVW_STATUS + 2835512cf780Skchow (osvwid / OSVW_ID_CNT_PER_MSR)) & 2836512cf780Skchow (1ULL << (osvwid % OSVW_ID_CNT_PER_MSR))); 2837512cf780Skchow 28387c478bd9Sstevel@tonic-gate default: 28397c478bd9Sstevel@tonic-gate return (-1); 28407c478bd9Sstevel@tonic-gate } 28417c478bd9Sstevel@tonic-gate } 28427c478bd9Sstevel@tonic-gate 28437c478bd9Sstevel@tonic-gate static const char assoc_str[] = "associativity"; 28447c478bd9Sstevel@tonic-gate static const char line_str[] = "line-size"; 28457c478bd9Sstevel@tonic-gate static const char size_str[] = "size"; 28467c478bd9Sstevel@tonic-gate 28477c478bd9Sstevel@tonic-gate static void 28487c478bd9Sstevel@tonic-gate add_cache_prop(dev_info_t *devi, const char *label, const char *type, 28497c478bd9Sstevel@tonic-gate uint32_t val) 28507c478bd9Sstevel@tonic-gate { 28517c478bd9Sstevel@tonic-gate char buf[128]; 28527c478bd9Sstevel@tonic-gate 28537c478bd9Sstevel@tonic-gate /* 28547c478bd9Sstevel@tonic-gate * ndi_prop_update_int() is used because it is desirable for 28557c478bd9Sstevel@tonic-gate * DDI_PROP_HW_DEF and DDI_PROP_DONTSLEEP to be set. 28567c478bd9Sstevel@tonic-gate */ 28577c478bd9Sstevel@tonic-gate if (snprintf(buf, sizeof (buf), "%s-%s", label, type) < sizeof (buf)) 28587c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, devi, buf, val); 28597c478bd9Sstevel@tonic-gate } 28607c478bd9Sstevel@tonic-gate 28617c478bd9Sstevel@tonic-gate /* 28627c478bd9Sstevel@tonic-gate * Intel-style cache/tlb description 28637c478bd9Sstevel@tonic-gate * 28647c478bd9Sstevel@tonic-gate * Standard cpuid level 2 gives a randomly ordered 28657c478bd9Sstevel@tonic-gate * selection of tags that index into a table that describes 28667c478bd9Sstevel@tonic-gate * cache and tlb properties. 28677c478bd9Sstevel@tonic-gate */ 28687c478bd9Sstevel@tonic-gate 28697c478bd9Sstevel@tonic-gate static const char l1_icache_str[] = "l1-icache"; 28707c478bd9Sstevel@tonic-gate static const char l1_dcache_str[] = "l1-dcache"; 28717c478bd9Sstevel@tonic-gate static const char l2_cache_str[] = "l2-cache"; 2872ae115bc7Smrj static const char l3_cache_str[] = "l3-cache"; 28737c478bd9Sstevel@tonic-gate static const char itlb4k_str[] = "itlb-4K"; 28747c478bd9Sstevel@tonic-gate static const char dtlb4k_str[] = "dtlb-4K"; 2875824e4fecSvd224797 static const char itlb2M_str[] = "itlb-2M"; 28767c478bd9Sstevel@tonic-gate static const char itlb4M_str[] = "itlb-4M"; 28777c478bd9Sstevel@tonic-gate static const char dtlb4M_str[] = "dtlb-4M"; 287825dfb062Sksadhukh static const char dtlb24_str[] = "dtlb0-2M-4M"; 28797c478bd9Sstevel@tonic-gate static const char itlb424_str[] = "itlb-4K-2M-4M"; 288025dfb062Sksadhukh static const char itlb24_str[] = "itlb-2M-4M"; 28817c478bd9Sstevel@tonic-gate static const char dtlb44_str[] = "dtlb-4K-4M"; 28827c478bd9Sstevel@tonic-gate static const char sl1_dcache_str[] = "sectored-l1-dcache"; 28837c478bd9Sstevel@tonic-gate static const char sl2_cache_str[] = "sectored-l2-cache"; 28847c478bd9Sstevel@tonic-gate static const char itrace_str[] = "itrace-cache"; 28857c478bd9Sstevel@tonic-gate static const char sl3_cache_str[] = "sectored-l3-cache"; 288625dfb062Sksadhukh static const char sh_l2_tlb4k_str[] = "shared-l2-tlb-4k"; 28877c478bd9Sstevel@tonic-gate 28887c478bd9Sstevel@tonic-gate static const struct cachetab { 28897c478bd9Sstevel@tonic-gate uint8_t ct_code; 28907c478bd9Sstevel@tonic-gate uint8_t ct_assoc; 28917c478bd9Sstevel@tonic-gate uint16_t ct_line_size; 28927c478bd9Sstevel@tonic-gate size_t ct_size; 28937c478bd9Sstevel@tonic-gate const char *ct_label; 28947c478bd9Sstevel@tonic-gate } intel_ctab[] = { 2895824e4fecSvd224797 /* 2896824e4fecSvd224797 * maintain descending order! 2897824e4fecSvd224797 * 2898824e4fecSvd224797 * Codes ignored - Reason 2899824e4fecSvd224797 * ---------------------- 2900824e4fecSvd224797 * 40H - intel_cpuid_4_cache_info() disambiguates l2/l3 cache 2901824e4fecSvd224797 * f0H/f1H - Currently we do not interpret prefetch size by design 2902824e4fecSvd224797 */ 290325dfb062Sksadhukh { 0xe4, 16, 64, 8*1024*1024, l3_cache_str}, 290425dfb062Sksadhukh { 0xe3, 16, 64, 4*1024*1024, l3_cache_str}, 290525dfb062Sksadhukh { 0xe2, 16, 64, 2*1024*1024, l3_cache_str}, 290625dfb062Sksadhukh { 0xde, 12, 64, 6*1024*1024, l3_cache_str}, 290725dfb062Sksadhukh { 0xdd, 12, 64, 3*1024*1024, l3_cache_str}, 290825dfb062Sksadhukh { 0xdc, 12, 64, ((1*1024*1024)+(512*1024)), l3_cache_str}, 290925dfb062Sksadhukh { 0xd8, 8, 64, 4*1024*1024, l3_cache_str}, 291025dfb062Sksadhukh { 0xd7, 8, 64, 2*1024*1024, l3_cache_str}, 291125dfb062Sksadhukh { 0xd6, 8, 64, 1*1024*1024, l3_cache_str}, 291225dfb062Sksadhukh { 0xd2, 4, 64, 2*1024*1024, l3_cache_str}, 291325dfb062Sksadhukh { 0xd1, 4, 64, 1*1024*1024, l3_cache_str}, 291425dfb062Sksadhukh { 0xd0, 4, 64, 512*1024, l3_cache_str}, 291525dfb062Sksadhukh { 0xca, 4, 0, 512, sh_l2_tlb4k_str}, 2916824e4fecSvd224797 { 0xc0, 4, 0, 8, dtlb44_str }, 2917824e4fecSvd224797 { 0xba, 4, 0, 64, dtlb4k_str }, 2918ae115bc7Smrj { 0xb4, 4, 0, 256, dtlb4k_str }, 29197c478bd9Sstevel@tonic-gate { 0xb3, 4, 0, 128, dtlb4k_str }, 292025dfb062Sksadhukh { 0xb2, 4, 0, 64, itlb4k_str }, 29217c478bd9Sstevel@tonic-gate { 0xb0, 4, 0, 128, itlb4k_str }, 29227c478bd9Sstevel@tonic-gate { 0x87, 8, 64, 1024*1024, l2_cache_str}, 29237c478bd9Sstevel@tonic-gate { 0x86, 4, 64, 512*1024, l2_cache_str}, 29247c478bd9Sstevel@tonic-gate { 0x85, 8, 32, 2*1024*1024, l2_cache_str}, 29257c478bd9Sstevel@tonic-gate { 0x84, 8, 32, 1024*1024, l2_cache_str}, 29267c478bd9Sstevel@tonic-gate { 0x83, 8, 32, 512*1024, l2_cache_str}, 29277c478bd9Sstevel@tonic-gate { 0x82, 8, 32, 256*1024, l2_cache_str}, 2928824e4fecSvd224797 { 0x80, 8, 64, 512*1024, l2_cache_str}, 29297c478bd9Sstevel@tonic-gate { 0x7f, 2, 64, 512*1024, l2_cache_str}, 29307c478bd9Sstevel@tonic-gate { 0x7d, 8, 64, 2*1024*1024, sl2_cache_str}, 29317c478bd9Sstevel@tonic-gate { 0x7c, 8, 64, 1024*1024, sl2_cache_str}, 29327c478bd9Sstevel@tonic-gate { 0x7b, 8, 64, 512*1024, sl2_cache_str}, 29337c478bd9Sstevel@tonic-gate { 0x7a, 8, 64, 256*1024, sl2_cache_str}, 29347c478bd9Sstevel@tonic-gate { 0x79, 8, 64, 128*1024, sl2_cache_str}, 29357c478bd9Sstevel@tonic-gate { 0x78, 8, 64, 1024*1024, l2_cache_str}, 2936ae115bc7Smrj { 0x73, 8, 0, 64*1024, itrace_str}, 29377c478bd9Sstevel@tonic-gate { 0x72, 8, 0, 32*1024, itrace_str}, 29387c478bd9Sstevel@tonic-gate { 0x71, 8, 0, 16*1024, itrace_str}, 29397c478bd9Sstevel@tonic-gate { 0x70, 8, 0, 12*1024, itrace_str}, 29407c478bd9Sstevel@tonic-gate { 0x68, 4, 64, 32*1024, sl1_dcache_str}, 29417c478bd9Sstevel@tonic-gate { 0x67, 4, 64, 16*1024, sl1_dcache_str}, 29427c478bd9Sstevel@tonic-gate { 0x66, 4, 64, 8*1024, sl1_dcache_str}, 29437c478bd9Sstevel@tonic-gate { 0x60, 8, 64, 16*1024, sl1_dcache_str}, 29447c478bd9Sstevel@tonic-gate { 0x5d, 0, 0, 256, dtlb44_str}, 29457c478bd9Sstevel@tonic-gate { 0x5c, 0, 0, 128, dtlb44_str}, 29467c478bd9Sstevel@tonic-gate { 0x5b, 0, 0, 64, dtlb44_str}, 294725dfb062Sksadhukh { 0x5a, 4, 0, 32, dtlb24_str}, 2948824e4fecSvd224797 { 0x59, 0, 0, 16, dtlb4k_str}, 2949824e4fecSvd224797 { 0x57, 4, 0, 16, dtlb4k_str}, 2950824e4fecSvd224797 { 0x56, 4, 0, 16, dtlb4M_str}, 295125dfb062Sksadhukh { 0x55, 0, 0, 7, itlb24_str}, 29527c478bd9Sstevel@tonic-gate { 0x52, 0, 0, 256, itlb424_str}, 29537c478bd9Sstevel@tonic-gate { 0x51, 0, 0, 128, itlb424_str}, 29547c478bd9Sstevel@tonic-gate { 0x50, 0, 0, 64, itlb424_str}, 2955824e4fecSvd224797 { 0x4f, 0, 0, 32, itlb4k_str}, 2956824e4fecSvd224797 { 0x4e, 24, 64, 6*1024*1024, l2_cache_str}, 2957ae115bc7Smrj { 0x4d, 16, 64, 16*1024*1024, l3_cache_str}, 2958ae115bc7Smrj { 0x4c, 12, 64, 12*1024*1024, l3_cache_str}, 2959ae115bc7Smrj { 0x4b, 16, 64, 8*1024*1024, l3_cache_str}, 2960ae115bc7Smrj { 0x4a, 12, 64, 6*1024*1024, l3_cache_str}, 2961ae115bc7Smrj { 0x49, 16, 64, 4*1024*1024, l3_cache_str}, 2962824e4fecSvd224797 { 0x48, 12, 64, 3*1024*1024, l2_cache_str}, 2963ae115bc7Smrj { 0x47, 8, 64, 8*1024*1024, l3_cache_str}, 2964ae115bc7Smrj { 0x46, 4, 64, 4*1024*1024, l3_cache_str}, 29657c478bd9Sstevel@tonic-gate { 0x45, 4, 32, 2*1024*1024, l2_cache_str}, 29667c478bd9Sstevel@tonic-gate { 0x44, 4, 32, 1024*1024, l2_cache_str}, 29677c478bd9Sstevel@tonic-gate { 0x43, 4, 32, 512*1024, l2_cache_str}, 29687c478bd9Sstevel@tonic-gate { 0x42, 4, 32, 256*1024, l2_cache_str}, 29697c478bd9Sstevel@tonic-gate { 0x41, 4, 32, 128*1024, l2_cache_str}, 2970ae115bc7Smrj { 0x3e, 4, 64, 512*1024, sl2_cache_str}, 2971ae115bc7Smrj { 0x3d, 6, 64, 384*1024, sl2_cache_str}, 29727c478bd9Sstevel@tonic-gate { 0x3c, 4, 64, 256*1024, sl2_cache_str}, 29737c478bd9Sstevel@tonic-gate { 0x3b, 2, 64, 128*1024, sl2_cache_str}, 2974ae115bc7Smrj { 0x3a, 6, 64, 192*1024, sl2_cache_str}, 29757c478bd9Sstevel@tonic-gate { 0x39, 4, 64, 128*1024, sl2_cache_str}, 29767c478bd9Sstevel@tonic-gate { 0x30, 8, 64, 32*1024, l1_icache_str}, 29777c478bd9Sstevel@tonic-gate { 0x2c, 8, 64, 32*1024, l1_dcache_str}, 29787c478bd9Sstevel@tonic-gate { 0x29, 8, 64, 4096*1024, sl3_cache_str}, 29797c478bd9Sstevel@tonic-gate { 0x25, 8, 64, 2048*1024, sl3_cache_str}, 29807c478bd9Sstevel@tonic-gate { 0x23, 8, 64, 1024*1024, sl3_cache_str}, 29817c478bd9Sstevel@tonic-gate { 0x22, 4, 64, 512*1024, sl3_cache_str}, 2982824e4fecSvd224797 { 0x0e, 6, 64, 24*1024, l1_dcache_str}, 298325dfb062Sksadhukh { 0x0d, 4, 32, 16*1024, l1_dcache_str}, 29847c478bd9Sstevel@tonic-gate { 0x0c, 4, 32, 16*1024, l1_dcache_str}, 2985ae115bc7Smrj { 0x0b, 4, 0, 4, itlb4M_str}, 29867c478bd9Sstevel@tonic-gate { 0x0a, 2, 32, 8*1024, l1_dcache_str}, 29877c478bd9Sstevel@tonic-gate { 0x08, 4, 32, 16*1024, l1_icache_str}, 29887c478bd9Sstevel@tonic-gate { 0x06, 4, 32, 8*1024, l1_icache_str}, 2989824e4fecSvd224797 { 0x05, 4, 0, 32, dtlb4M_str}, 29907c478bd9Sstevel@tonic-gate { 0x04, 4, 0, 8, dtlb4M_str}, 29917c478bd9Sstevel@tonic-gate { 0x03, 4, 0, 64, dtlb4k_str}, 29927c478bd9Sstevel@tonic-gate { 0x02, 4, 0, 2, itlb4M_str}, 29937c478bd9Sstevel@tonic-gate { 0x01, 4, 0, 32, itlb4k_str}, 29947c478bd9Sstevel@tonic-gate { 0 } 29957c478bd9Sstevel@tonic-gate }; 29967c478bd9Sstevel@tonic-gate 29977c478bd9Sstevel@tonic-gate static const struct cachetab cyrix_ctab[] = { 29987c478bd9Sstevel@tonic-gate { 0x70, 4, 0, 32, "tlb-4K" }, 29997c478bd9Sstevel@tonic-gate { 0x80, 4, 16, 16*1024, "l1-cache" }, 30007c478bd9Sstevel@tonic-gate { 0 } 30017c478bd9Sstevel@tonic-gate }; 30027c478bd9Sstevel@tonic-gate 30037c478bd9Sstevel@tonic-gate /* 30047c478bd9Sstevel@tonic-gate * Search a cache table for a matching entry 30057c478bd9Sstevel@tonic-gate */ 30067c478bd9Sstevel@tonic-gate static const struct cachetab * 30077c478bd9Sstevel@tonic-gate find_cacheent(const struct cachetab *ct, uint_t code) 30087c478bd9Sstevel@tonic-gate { 30097c478bd9Sstevel@tonic-gate if (code != 0) { 30107c478bd9Sstevel@tonic-gate for (; ct->ct_code != 0; ct++) 30117c478bd9Sstevel@tonic-gate if (ct->ct_code <= code) 30127c478bd9Sstevel@tonic-gate break; 30137c478bd9Sstevel@tonic-gate if (ct->ct_code == code) 30147c478bd9Sstevel@tonic-gate return (ct); 30157c478bd9Sstevel@tonic-gate } 30167c478bd9Sstevel@tonic-gate return (NULL); 30177c478bd9Sstevel@tonic-gate } 30187c478bd9Sstevel@tonic-gate 30197c478bd9Sstevel@tonic-gate /* 30207dee861bSksadhukh * Populate cachetab entry with L2 or L3 cache-information using 30217dee861bSksadhukh * cpuid function 4. This function is called from intel_walk_cacheinfo() 30227dee861bSksadhukh * when descriptor 0x49 is encountered. It returns 0 if no such cache 30237dee861bSksadhukh * information is found. 30247dee861bSksadhukh */ 30257dee861bSksadhukh static int 30267dee861bSksadhukh intel_cpuid_4_cache_info(struct cachetab *ct, struct cpuid_info *cpi) 30277dee861bSksadhukh { 30287dee861bSksadhukh uint32_t level, i; 30297dee861bSksadhukh int ret = 0; 30307dee861bSksadhukh 30317dee861bSksadhukh for (i = 0; i < cpi->cpi_std_4_size; i++) { 30327dee861bSksadhukh level = CPI_CACHE_LVL(cpi->cpi_std_4[i]); 30337dee861bSksadhukh 30347dee861bSksadhukh if (level == 2 || level == 3) { 30357dee861bSksadhukh ct->ct_assoc = CPI_CACHE_WAYS(cpi->cpi_std_4[i]) + 1; 30367dee861bSksadhukh ct->ct_line_size = 30377dee861bSksadhukh CPI_CACHE_COH_LN_SZ(cpi->cpi_std_4[i]) + 1; 30387dee861bSksadhukh ct->ct_size = ct->ct_assoc * 30397dee861bSksadhukh (CPI_CACHE_PARTS(cpi->cpi_std_4[i]) + 1) * 30407dee861bSksadhukh ct->ct_line_size * 30417dee861bSksadhukh (cpi->cpi_std_4[i]->cp_ecx + 1); 30427dee861bSksadhukh 30437dee861bSksadhukh if (level == 2) { 30447dee861bSksadhukh ct->ct_label = l2_cache_str; 30457dee861bSksadhukh } else if (level == 3) { 30467dee861bSksadhukh ct->ct_label = l3_cache_str; 30477dee861bSksadhukh } 30487dee861bSksadhukh ret = 1; 30497dee861bSksadhukh } 30507dee861bSksadhukh } 30517dee861bSksadhukh 30527dee861bSksadhukh return (ret); 30537dee861bSksadhukh } 30547dee861bSksadhukh 30557dee861bSksadhukh /* 30567c478bd9Sstevel@tonic-gate * Walk the cacheinfo descriptor, applying 'func' to every valid element 30577c478bd9Sstevel@tonic-gate * The walk is terminated if the walker returns non-zero. 30587c478bd9Sstevel@tonic-gate */ 30597c478bd9Sstevel@tonic-gate static void 30607c478bd9Sstevel@tonic-gate intel_walk_cacheinfo(struct cpuid_info *cpi, 30617c478bd9Sstevel@tonic-gate void *arg, int (*func)(void *, const struct cachetab *)) 30627c478bd9Sstevel@tonic-gate { 30637c478bd9Sstevel@tonic-gate const struct cachetab *ct; 3064824e4fecSvd224797 struct cachetab des_49_ct, des_b1_ct; 30657c478bd9Sstevel@tonic-gate uint8_t *dp; 30667c478bd9Sstevel@tonic-gate int i; 30677c478bd9Sstevel@tonic-gate 30687c478bd9Sstevel@tonic-gate if ((dp = cpi->cpi_cacheinfo) == NULL) 30697c478bd9Sstevel@tonic-gate return; 3070f1d742a9Sksadhukh for (i = 0; i < cpi->cpi_ncache; i++, dp++) { 3071f1d742a9Sksadhukh /* 3072f1d742a9Sksadhukh * For overloaded descriptor 0x49 we use cpuid function 4 30737dee861bSksadhukh * if supported by the current processor, to create 3074f1d742a9Sksadhukh * cache information. 3075824e4fecSvd224797 * For overloaded descriptor 0xb1 we use X86_PAE flag 3076824e4fecSvd224797 * to disambiguate the cache information. 3077f1d742a9Sksadhukh */ 30787dee861bSksadhukh if (*dp == 0x49 && cpi->cpi_maxeax >= 0x4 && 30797dee861bSksadhukh intel_cpuid_4_cache_info(&des_49_ct, cpi) == 1) { 30807dee861bSksadhukh ct = &des_49_ct; 3081824e4fecSvd224797 } else if (*dp == 0xb1) { 3082824e4fecSvd224797 des_b1_ct.ct_code = 0xb1; 3083824e4fecSvd224797 des_b1_ct.ct_assoc = 4; 3084824e4fecSvd224797 des_b1_ct.ct_line_size = 0; 3085824e4fecSvd224797 if (x86_feature & X86_PAE) { 3086824e4fecSvd224797 des_b1_ct.ct_size = 8; 3087824e4fecSvd224797 des_b1_ct.ct_label = itlb2M_str; 3088824e4fecSvd224797 } else { 3089824e4fecSvd224797 des_b1_ct.ct_size = 4; 3090824e4fecSvd224797 des_b1_ct.ct_label = itlb4M_str; 3091824e4fecSvd224797 } 3092824e4fecSvd224797 ct = &des_b1_ct; 30937dee861bSksadhukh } else { 30947dee861bSksadhukh if ((ct = find_cacheent(intel_ctab, *dp)) == NULL) { 3095f1d742a9Sksadhukh continue; 3096f1d742a9Sksadhukh } 30977dee861bSksadhukh } 3098f1d742a9Sksadhukh 30997dee861bSksadhukh if (func(arg, ct) != 0) { 31007c478bd9Sstevel@tonic-gate break; 31017c478bd9Sstevel@tonic-gate } 31027c478bd9Sstevel@tonic-gate } 3103f1d742a9Sksadhukh } 31047c478bd9Sstevel@tonic-gate 31057c478bd9Sstevel@tonic-gate /* 31067c478bd9Sstevel@tonic-gate * (Like the Intel one, except for Cyrix CPUs) 31077c478bd9Sstevel@tonic-gate */ 31087c478bd9Sstevel@tonic-gate static void 31097c478bd9Sstevel@tonic-gate cyrix_walk_cacheinfo(struct cpuid_info *cpi, 31107c478bd9Sstevel@tonic-gate void *arg, int (*func)(void *, const struct cachetab *)) 31117c478bd9Sstevel@tonic-gate { 31127c478bd9Sstevel@tonic-gate const struct cachetab *ct; 31137c478bd9Sstevel@tonic-gate uint8_t *dp; 31147c478bd9Sstevel@tonic-gate int i; 31157c478bd9Sstevel@tonic-gate 31167c478bd9Sstevel@tonic-gate if ((dp = cpi->cpi_cacheinfo) == NULL) 31177c478bd9Sstevel@tonic-gate return; 31187c478bd9Sstevel@tonic-gate for (i = 0; i < cpi->cpi_ncache; i++, dp++) { 31197c478bd9Sstevel@tonic-gate /* 31207c478bd9Sstevel@tonic-gate * Search Cyrix-specific descriptor table first .. 31217c478bd9Sstevel@tonic-gate */ 31227c478bd9Sstevel@tonic-gate if ((ct = find_cacheent(cyrix_ctab, *dp)) != NULL) { 31237c478bd9Sstevel@tonic-gate if (func(arg, ct) != 0) 31247c478bd9Sstevel@tonic-gate break; 31257c478bd9Sstevel@tonic-gate continue; 31267c478bd9Sstevel@tonic-gate } 31277c478bd9Sstevel@tonic-gate /* 31287c478bd9Sstevel@tonic-gate * .. else fall back to the Intel one 31297c478bd9Sstevel@tonic-gate */ 31307c478bd9Sstevel@tonic-gate if ((ct = find_cacheent(intel_ctab, *dp)) != NULL) { 31317c478bd9Sstevel@tonic-gate if (func(arg, ct) != 0) 31327c478bd9Sstevel@tonic-gate break; 31337c478bd9Sstevel@tonic-gate continue; 31347c478bd9Sstevel@tonic-gate } 31357c478bd9Sstevel@tonic-gate } 31367c478bd9Sstevel@tonic-gate } 31377c478bd9Sstevel@tonic-gate 31387c478bd9Sstevel@tonic-gate /* 31397c478bd9Sstevel@tonic-gate * A cacheinfo walker that adds associativity, line-size, and size properties 31407c478bd9Sstevel@tonic-gate * to the devinfo node it is passed as an argument. 31417c478bd9Sstevel@tonic-gate */ 31427c478bd9Sstevel@tonic-gate static int 31437c478bd9Sstevel@tonic-gate add_cacheent_props(void *arg, const struct cachetab *ct) 31447c478bd9Sstevel@tonic-gate { 31457c478bd9Sstevel@tonic-gate dev_info_t *devi = arg; 31467c478bd9Sstevel@tonic-gate 31477c478bd9Sstevel@tonic-gate add_cache_prop(devi, ct->ct_label, assoc_str, ct->ct_assoc); 31487c478bd9Sstevel@tonic-gate if (ct->ct_line_size != 0) 31497c478bd9Sstevel@tonic-gate add_cache_prop(devi, ct->ct_label, line_str, 31507c478bd9Sstevel@tonic-gate ct->ct_line_size); 31517c478bd9Sstevel@tonic-gate add_cache_prop(devi, ct->ct_label, size_str, ct->ct_size); 31527c478bd9Sstevel@tonic-gate return (0); 31537c478bd9Sstevel@tonic-gate } 31547c478bd9Sstevel@tonic-gate 3155f1d742a9Sksadhukh 31567c478bd9Sstevel@tonic-gate static const char fully_assoc[] = "fully-associative?"; 31577c478bd9Sstevel@tonic-gate 31587c478bd9Sstevel@tonic-gate /* 31597c478bd9Sstevel@tonic-gate * AMD style cache/tlb description 31607c478bd9Sstevel@tonic-gate * 31617c478bd9Sstevel@tonic-gate * Extended functions 5 and 6 directly describe properties of 31627c478bd9Sstevel@tonic-gate * tlbs and various cache levels. 31637c478bd9Sstevel@tonic-gate */ 31647c478bd9Sstevel@tonic-gate static void 31657c478bd9Sstevel@tonic-gate add_amd_assoc(dev_info_t *devi, const char *label, uint_t assoc) 31667c478bd9Sstevel@tonic-gate { 31677c478bd9Sstevel@tonic-gate switch (assoc) { 31687c478bd9Sstevel@tonic-gate case 0: /* reserved; ignore */ 31697c478bd9Sstevel@tonic-gate break; 31707c478bd9Sstevel@tonic-gate default: 31717c478bd9Sstevel@tonic-gate add_cache_prop(devi, label, assoc_str, assoc); 31727c478bd9Sstevel@tonic-gate break; 31737c478bd9Sstevel@tonic-gate case 0xff: 31747c478bd9Sstevel@tonic-gate add_cache_prop(devi, label, fully_assoc, 1); 31757c478bd9Sstevel@tonic-gate break; 31767c478bd9Sstevel@tonic-gate } 31777c478bd9Sstevel@tonic-gate } 31787c478bd9Sstevel@tonic-gate 31797c478bd9Sstevel@tonic-gate static void 31807c478bd9Sstevel@tonic-gate add_amd_tlb(dev_info_t *devi, const char *label, uint_t assoc, uint_t size) 31817c478bd9Sstevel@tonic-gate { 31827c478bd9Sstevel@tonic-gate if (size == 0) 31837c478bd9Sstevel@tonic-gate return; 31847c478bd9Sstevel@tonic-gate add_cache_prop(devi, label, size_str, size); 31857c478bd9Sstevel@tonic-gate add_amd_assoc(devi, label, assoc); 31867c478bd9Sstevel@tonic-gate } 31877c478bd9Sstevel@tonic-gate 31887c478bd9Sstevel@tonic-gate static void 31897c478bd9Sstevel@tonic-gate add_amd_cache(dev_info_t *devi, const char *label, 31907c478bd9Sstevel@tonic-gate uint_t size, uint_t assoc, uint_t lines_per_tag, uint_t line_size) 31917c478bd9Sstevel@tonic-gate { 31927c478bd9Sstevel@tonic-gate if (size == 0 || line_size == 0) 31937c478bd9Sstevel@tonic-gate return; 31947c478bd9Sstevel@tonic-gate add_amd_assoc(devi, label, assoc); 31957c478bd9Sstevel@tonic-gate /* 31967c478bd9Sstevel@tonic-gate * Most AMD parts have a sectored cache. Multiple cache lines are 31977c478bd9Sstevel@tonic-gate * associated with each tag. A sector consists of all cache lines 31987c478bd9Sstevel@tonic-gate * associated with a tag. For example, the AMD K6-III has a sector 31997c478bd9Sstevel@tonic-gate * size of 2 cache lines per tag. 32007c478bd9Sstevel@tonic-gate */ 32017c478bd9Sstevel@tonic-gate if (lines_per_tag != 0) 32027c478bd9Sstevel@tonic-gate add_cache_prop(devi, label, "lines-per-tag", lines_per_tag); 32037c478bd9Sstevel@tonic-gate add_cache_prop(devi, label, line_str, line_size); 32047c478bd9Sstevel@tonic-gate add_cache_prop(devi, label, size_str, size * 1024); 32057c478bd9Sstevel@tonic-gate } 32067c478bd9Sstevel@tonic-gate 32077c478bd9Sstevel@tonic-gate static void 32087c478bd9Sstevel@tonic-gate add_amd_l2_assoc(dev_info_t *devi, const char *label, uint_t assoc) 32097c478bd9Sstevel@tonic-gate { 32107c478bd9Sstevel@tonic-gate switch (assoc) { 32117c478bd9Sstevel@tonic-gate case 0: /* off */ 32127c478bd9Sstevel@tonic-gate break; 32137c478bd9Sstevel@tonic-gate case 1: 32147c478bd9Sstevel@tonic-gate case 2: 32157c478bd9Sstevel@tonic-gate case 4: 32167c478bd9Sstevel@tonic-gate add_cache_prop(devi, label, assoc_str, assoc); 32177c478bd9Sstevel@tonic-gate break; 32187c478bd9Sstevel@tonic-gate case 6: 32197c478bd9Sstevel@tonic-gate add_cache_prop(devi, label, assoc_str, 8); 32207c478bd9Sstevel@tonic-gate break; 32217c478bd9Sstevel@tonic-gate case 8: 32227c478bd9Sstevel@tonic-gate add_cache_prop(devi, label, assoc_str, 16); 32237c478bd9Sstevel@tonic-gate break; 32247c478bd9Sstevel@tonic-gate case 0xf: 32257c478bd9Sstevel@tonic-gate add_cache_prop(devi, label, fully_assoc, 1); 32267c478bd9Sstevel@tonic-gate break; 32277c478bd9Sstevel@tonic-gate default: /* reserved; ignore */ 32287c478bd9Sstevel@tonic-gate break; 32297c478bd9Sstevel@tonic-gate } 32307c478bd9Sstevel@tonic-gate } 32317c478bd9Sstevel@tonic-gate 32327c478bd9Sstevel@tonic-gate static void 32337c478bd9Sstevel@tonic-gate add_amd_l2_tlb(dev_info_t *devi, const char *label, uint_t assoc, uint_t size) 32347c478bd9Sstevel@tonic-gate { 32357c478bd9Sstevel@tonic-gate if (size == 0 || assoc == 0) 32367c478bd9Sstevel@tonic-gate return; 32377c478bd9Sstevel@tonic-gate add_amd_l2_assoc(devi, label, assoc); 32387c478bd9Sstevel@tonic-gate add_cache_prop(devi, label, size_str, size); 32397c478bd9Sstevel@tonic-gate } 32407c478bd9Sstevel@tonic-gate 32417c478bd9Sstevel@tonic-gate static void 32427c478bd9Sstevel@tonic-gate add_amd_l2_cache(dev_info_t *devi, const char *label, 32437c478bd9Sstevel@tonic-gate uint_t size, uint_t assoc, uint_t lines_per_tag, uint_t line_size) 32447c478bd9Sstevel@tonic-gate { 32457c478bd9Sstevel@tonic-gate if (size == 0 || assoc == 0 || line_size == 0) 32467c478bd9Sstevel@tonic-gate return; 32477c478bd9Sstevel@tonic-gate add_amd_l2_assoc(devi, label, assoc); 32487c478bd9Sstevel@tonic-gate if (lines_per_tag != 0) 32497c478bd9Sstevel@tonic-gate add_cache_prop(devi, label, "lines-per-tag", lines_per_tag); 32507c478bd9Sstevel@tonic-gate add_cache_prop(devi, label, line_str, line_size); 32517c478bd9Sstevel@tonic-gate add_cache_prop(devi, label, size_str, size * 1024); 32527c478bd9Sstevel@tonic-gate } 32537c478bd9Sstevel@tonic-gate 32547c478bd9Sstevel@tonic-gate static void 32557c478bd9Sstevel@tonic-gate amd_cache_info(struct cpuid_info *cpi, dev_info_t *devi) 32567c478bd9Sstevel@tonic-gate { 32578949bcd6Sandrei struct cpuid_regs *cp; 32587c478bd9Sstevel@tonic-gate 32597c478bd9Sstevel@tonic-gate if (cpi->cpi_xmaxeax < 0x80000005) 32607c478bd9Sstevel@tonic-gate return; 32617c478bd9Sstevel@tonic-gate cp = &cpi->cpi_extd[5]; 32627c478bd9Sstevel@tonic-gate 32637c478bd9Sstevel@tonic-gate /* 32647c478bd9Sstevel@tonic-gate * 4M/2M L1 TLB configuration 32657c478bd9Sstevel@tonic-gate * 32667c478bd9Sstevel@tonic-gate * We report the size for 2M pages because AMD uses two 32677c478bd9Sstevel@tonic-gate * TLB entries for one 4M page. 32687c478bd9Sstevel@tonic-gate */ 32697c478bd9Sstevel@tonic-gate add_amd_tlb(devi, "dtlb-2M", 32707c478bd9Sstevel@tonic-gate BITX(cp->cp_eax, 31, 24), BITX(cp->cp_eax, 23, 16)); 32717c478bd9Sstevel@tonic-gate add_amd_tlb(devi, "itlb-2M", 32727c478bd9Sstevel@tonic-gate BITX(cp->cp_eax, 15, 8), BITX(cp->cp_eax, 7, 0)); 32737c478bd9Sstevel@tonic-gate 32747c478bd9Sstevel@tonic-gate /* 32757c478bd9Sstevel@tonic-gate * 4K L1 TLB configuration 32767c478bd9Sstevel@tonic-gate */ 32777c478bd9Sstevel@tonic-gate 32787c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 32797c478bd9Sstevel@tonic-gate uint_t nentries; 32807c478bd9Sstevel@tonic-gate case X86_VENDOR_TM: 32817c478bd9Sstevel@tonic-gate if (cpi->cpi_family >= 5) { 32827c478bd9Sstevel@tonic-gate /* 32837c478bd9Sstevel@tonic-gate * Crusoe processors have 256 TLB entries, but 32847c478bd9Sstevel@tonic-gate * cpuid data format constrains them to only 32857c478bd9Sstevel@tonic-gate * reporting 255 of them. 32867c478bd9Sstevel@tonic-gate */ 32877c478bd9Sstevel@tonic-gate if ((nentries = BITX(cp->cp_ebx, 23, 16)) == 255) 32887c478bd9Sstevel@tonic-gate nentries = 256; 32897c478bd9Sstevel@tonic-gate /* 32907c478bd9Sstevel@tonic-gate * Crusoe processors also have a unified TLB 32917c478bd9Sstevel@tonic-gate */ 32927c478bd9Sstevel@tonic-gate add_amd_tlb(devi, "tlb-4K", BITX(cp->cp_ebx, 31, 24), 32937c478bd9Sstevel@tonic-gate nentries); 32947c478bd9Sstevel@tonic-gate break; 32957c478bd9Sstevel@tonic-gate } 32967c478bd9Sstevel@tonic-gate /*FALLTHROUGH*/ 32977c478bd9Sstevel@tonic-gate default: 32987c478bd9Sstevel@tonic-gate add_amd_tlb(devi, itlb4k_str, 32997c478bd9Sstevel@tonic-gate BITX(cp->cp_ebx, 31, 24), BITX(cp->cp_ebx, 23, 16)); 33007c478bd9Sstevel@tonic-gate add_amd_tlb(devi, dtlb4k_str, 33017c478bd9Sstevel@tonic-gate BITX(cp->cp_ebx, 15, 8), BITX(cp->cp_ebx, 7, 0)); 33027c478bd9Sstevel@tonic-gate break; 33037c478bd9Sstevel@tonic-gate } 33047c478bd9Sstevel@tonic-gate 33057c478bd9Sstevel@tonic-gate /* 33067c478bd9Sstevel@tonic-gate * data L1 cache configuration 33077c478bd9Sstevel@tonic-gate */ 33087c478bd9Sstevel@tonic-gate 33097c478bd9Sstevel@tonic-gate add_amd_cache(devi, l1_dcache_str, 33107c478bd9Sstevel@tonic-gate BITX(cp->cp_ecx, 31, 24), BITX(cp->cp_ecx, 23, 16), 33117c478bd9Sstevel@tonic-gate BITX(cp->cp_ecx, 15, 8), BITX(cp->cp_ecx, 7, 0)); 33127c478bd9Sstevel@tonic-gate 33137c478bd9Sstevel@tonic-gate /* 33147c478bd9Sstevel@tonic-gate * code L1 cache configuration 33157c478bd9Sstevel@tonic-gate */ 33167c478bd9Sstevel@tonic-gate 33177c478bd9Sstevel@tonic-gate add_amd_cache(devi, l1_icache_str, 33187c478bd9Sstevel@tonic-gate BITX(cp->cp_edx, 31, 24), BITX(cp->cp_edx, 23, 16), 33197c478bd9Sstevel@tonic-gate BITX(cp->cp_edx, 15, 8), BITX(cp->cp_edx, 7, 0)); 33207c478bd9Sstevel@tonic-gate 33217c478bd9Sstevel@tonic-gate if (cpi->cpi_xmaxeax < 0x80000006) 33227c478bd9Sstevel@tonic-gate return; 33237c478bd9Sstevel@tonic-gate cp = &cpi->cpi_extd[6]; 33247c478bd9Sstevel@tonic-gate 33257c478bd9Sstevel@tonic-gate /* Check for a unified L2 TLB for large pages */ 33267c478bd9Sstevel@tonic-gate 33277c478bd9Sstevel@tonic-gate if (BITX(cp->cp_eax, 31, 16) == 0) 33287c478bd9Sstevel@tonic-gate add_amd_l2_tlb(devi, "l2-tlb-2M", 33297c478bd9Sstevel@tonic-gate BITX(cp->cp_eax, 15, 12), BITX(cp->cp_eax, 11, 0)); 33307c478bd9Sstevel@tonic-gate else { 33317c478bd9Sstevel@tonic-gate add_amd_l2_tlb(devi, "l2-dtlb-2M", 33327c478bd9Sstevel@tonic-gate BITX(cp->cp_eax, 31, 28), BITX(cp->cp_eax, 27, 16)); 33337c478bd9Sstevel@tonic-gate add_amd_l2_tlb(devi, "l2-itlb-2M", 33347c478bd9Sstevel@tonic-gate BITX(cp->cp_eax, 15, 12), BITX(cp->cp_eax, 11, 0)); 33357c478bd9Sstevel@tonic-gate } 33367c478bd9Sstevel@tonic-gate 33377c478bd9Sstevel@tonic-gate /* Check for a unified L2 TLB for 4K pages */ 33387c478bd9Sstevel@tonic-gate 33397c478bd9Sstevel@tonic-gate if (BITX(cp->cp_ebx, 31, 16) == 0) { 33407c478bd9Sstevel@tonic-gate add_amd_l2_tlb(devi, "l2-tlb-4K", 33417c478bd9Sstevel@tonic-gate BITX(cp->cp_eax, 15, 12), BITX(cp->cp_eax, 11, 0)); 33427c478bd9Sstevel@tonic-gate } else { 33437c478bd9Sstevel@tonic-gate add_amd_l2_tlb(devi, "l2-dtlb-4K", 33447c478bd9Sstevel@tonic-gate BITX(cp->cp_eax, 31, 28), BITX(cp->cp_eax, 27, 16)); 33457c478bd9Sstevel@tonic-gate add_amd_l2_tlb(devi, "l2-itlb-4K", 33467c478bd9Sstevel@tonic-gate BITX(cp->cp_eax, 15, 12), BITX(cp->cp_eax, 11, 0)); 33477c478bd9Sstevel@tonic-gate } 33487c478bd9Sstevel@tonic-gate 33497c478bd9Sstevel@tonic-gate add_amd_l2_cache(devi, l2_cache_str, 33507c478bd9Sstevel@tonic-gate BITX(cp->cp_ecx, 31, 16), BITX(cp->cp_ecx, 15, 12), 33517c478bd9Sstevel@tonic-gate BITX(cp->cp_ecx, 11, 8), BITX(cp->cp_ecx, 7, 0)); 33527c478bd9Sstevel@tonic-gate } 33537c478bd9Sstevel@tonic-gate 33547c478bd9Sstevel@tonic-gate /* 33557c478bd9Sstevel@tonic-gate * There are two basic ways that the x86 world describes it cache 33567c478bd9Sstevel@tonic-gate * and tlb architecture - Intel's way and AMD's way. 33577c478bd9Sstevel@tonic-gate * 33587c478bd9Sstevel@tonic-gate * Return which flavor of cache architecture we should use 33597c478bd9Sstevel@tonic-gate */ 33607c478bd9Sstevel@tonic-gate static int 33617c478bd9Sstevel@tonic-gate x86_which_cacheinfo(struct cpuid_info *cpi) 33627c478bd9Sstevel@tonic-gate { 33637c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 33647c478bd9Sstevel@tonic-gate case X86_VENDOR_Intel: 33657c478bd9Sstevel@tonic-gate if (cpi->cpi_maxeax >= 2) 33667c478bd9Sstevel@tonic-gate return (X86_VENDOR_Intel); 33677c478bd9Sstevel@tonic-gate break; 33687c478bd9Sstevel@tonic-gate case X86_VENDOR_AMD: 33697c478bd9Sstevel@tonic-gate /* 33707c478bd9Sstevel@tonic-gate * The K5 model 1 was the first part from AMD that reported 33717c478bd9Sstevel@tonic-gate * cache sizes via extended cpuid functions. 33727c478bd9Sstevel@tonic-gate */ 33737c478bd9Sstevel@tonic-gate if (cpi->cpi_family > 5 || 33747c478bd9Sstevel@tonic-gate (cpi->cpi_family == 5 && cpi->cpi_model >= 1)) 33757c478bd9Sstevel@tonic-gate return (X86_VENDOR_AMD); 33767c478bd9Sstevel@tonic-gate break; 33777c478bd9Sstevel@tonic-gate case X86_VENDOR_TM: 33787c478bd9Sstevel@tonic-gate if (cpi->cpi_family >= 5) 33797c478bd9Sstevel@tonic-gate return (X86_VENDOR_AMD); 33807c478bd9Sstevel@tonic-gate /*FALLTHROUGH*/ 33817c478bd9Sstevel@tonic-gate default: 33827c478bd9Sstevel@tonic-gate /* 33837c478bd9Sstevel@tonic-gate * If they have extended CPU data for 0x80000005 33847c478bd9Sstevel@tonic-gate * then we assume they have AMD-format cache 33857c478bd9Sstevel@tonic-gate * information. 33867c478bd9Sstevel@tonic-gate * 33877c478bd9Sstevel@tonic-gate * If not, and the vendor happens to be Cyrix, 33887c478bd9Sstevel@tonic-gate * then try our-Cyrix specific handler. 33897c478bd9Sstevel@tonic-gate * 33907c478bd9Sstevel@tonic-gate * If we're not Cyrix, then assume we're using Intel's 33917c478bd9Sstevel@tonic-gate * table-driven format instead. 33927c478bd9Sstevel@tonic-gate */ 33937c478bd9Sstevel@tonic-gate if (cpi->cpi_xmaxeax >= 0x80000005) 33947c478bd9Sstevel@tonic-gate return (X86_VENDOR_AMD); 33957c478bd9Sstevel@tonic-gate else if (cpi->cpi_vendor == X86_VENDOR_Cyrix) 33967c478bd9Sstevel@tonic-gate return (X86_VENDOR_Cyrix); 33977c478bd9Sstevel@tonic-gate else if (cpi->cpi_maxeax >= 2) 33987c478bd9Sstevel@tonic-gate return (X86_VENDOR_Intel); 33997c478bd9Sstevel@tonic-gate break; 34007c478bd9Sstevel@tonic-gate } 34017c478bd9Sstevel@tonic-gate return (-1); 34027c478bd9Sstevel@tonic-gate } 34037c478bd9Sstevel@tonic-gate 34047c478bd9Sstevel@tonic-gate /* 34057c478bd9Sstevel@tonic-gate * create a node for the given cpu under the prom root node. 34067c478bd9Sstevel@tonic-gate * Also, create a cpu node in the device tree. 34077c478bd9Sstevel@tonic-gate */ 34087c478bd9Sstevel@tonic-gate static dev_info_t *cpu_nex_devi = NULL; 34097c478bd9Sstevel@tonic-gate static kmutex_t cpu_node_lock; 34107c478bd9Sstevel@tonic-gate 34117c478bd9Sstevel@tonic-gate /* 34127c478bd9Sstevel@tonic-gate * Called from post_startup() and mp_startup() 34137c478bd9Sstevel@tonic-gate */ 34147c478bd9Sstevel@tonic-gate void 34157c478bd9Sstevel@tonic-gate add_cpunode2devtree(processorid_t cpu_id, struct cpuid_info *cpi) 34167c478bd9Sstevel@tonic-gate { 34177c478bd9Sstevel@tonic-gate dev_info_t *cpu_devi; 34187c478bd9Sstevel@tonic-gate int create; 34197c478bd9Sstevel@tonic-gate 34207c478bd9Sstevel@tonic-gate mutex_enter(&cpu_node_lock); 34217c478bd9Sstevel@tonic-gate 34227c478bd9Sstevel@tonic-gate /* 34237c478bd9Sstevel@tonic-gate * create a nexus node for all cpus identified as 'cpu_id' under 34247c478bd9Sstevel@tonic-gate * the root node. 34257c478bd9Sstevel@tonic-gate */ 34267c478bd9Sstevel@tonic-gate if (cpu_nex_devi == NULL) { 34277c478bd9Sstevel@tonic-gate if (ndi_devi_alloc(ddi_root_node(), "cpus", 3428fa9e4066Sahrens (pnode_t)DEVI_SID_NODEID, &cpu_nex_devi) != NDI_SUCCESS) { 34297c478bd9Sstevel@tonic-gate mutex_exit(&cpu_node_lock); 34307c478bd9Sstevel@tonic-gate return; 34317c478bd9Sstevel@tonic-gate } 34327c478bd9Sstevel@tonic-gate (void) ndi_devi_online(cpu_nex_devi, 0); 34337c478bd9Sstevel@tonic-gate } 34347c478bd9Sstevel@tonic-gate 34357c478bd9Sstevel@tonic-gate /* 34367c478bd9Sstevel@tonic-gate * create a child node for cpu identified as 'cpu_id' 34377c478bd9Sstevel@tonic-gate */ 34387c478bd9Sstevel@tonic-gate cpu_devi = ddi_add_child(cpu_nex_devi, "cpu", DEVI_SID_NODEID, 34397c478bd9Sstevel@tonic-gate cpu_id); 34407c478bd9Sstevel@tonic-gate if (cpu_devi == NULL) { 34417c478bd9Sstevel@tonic-gate mutex_exit(&cpu_node_lock); 34427c478bd9Sstevel@tonic-gate return; 34437c478bd9Sstevel@tonic-gate } 34447c478bd9Sstevel@tonic-gate 34457c478bd9Sstevel@tonic-gate /* device_type */ 34467c478bd9Sstevel@tonic-gate 34477c478bd9Sstevel@tonic-gate (void) ndi_prop_update_string(DDI_DEV_T_NONE, cpu_devi, 34487c478bd9Sstevel@tonic-gate "device_type", "cpu"); 34497c478bd9Sstevel@tonic-gate 34507c478bd9Sstevel@tonic-gate /* reg */ 34517c478bd9Sstevel@tonic-gate 34527c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 34537c478bd9Sstevel@tonic-gate "reg", cpu_id); 34547c478bd9Sstevel@tonic-gate 34557c478bd9Sstevel@tonic-gate /* cpu-mhz, and clock-frequency */ 34567c478bd9Sstevel@tonic-gate 34577c478bd9Sstevel@tonic-gate if (cpu_freq > 0) { 34587c478bd9Sstevel@tonic-gate long long mul; 34597c478bd9Sstevel@tonic-gate 34607c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 34617c478bd9Sstevel@tonic-gate "cpu-mhz", cpu_freq); 34627c478bd9Sstevel@tonic-gate 34637c478bd9Sstevel@tonic-gate if ((mul = cpu_freq * 1000000LL) <= INT_MAX) 34647c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 34657c478bd9Sstevel@tonic-gate "clock-frequency", (int)mul); 34667c478bd9Sstevel@tonic-gate } 34677c478bd9Sstevel@tonic-gate 34687c478bd9Sstevel@tonic-gate (void) ndi_devi_online(cpu_devi, 0); 34697c478bd9Sstevel@tonic-gate 34707c478bd9Sstevel@tonic-gate if ((x86_feature & X86_CPUID) == 0) { 34717c478bd9Sstevel@tonic-gate mutex_exit(&cpu_node_lock); 34727c478bd9Sstevel@tonic-gate return; 34737c478bd9Sstevel@tonic-gate } 34747c478bd9Sstevel@tonic-gate 34757c478bd9Sstevel@tonic-gate /* vendor-id */ 34767c478bd9Sstevel@tonic-gate 34777c478bd9Sstevel@tonic-gate (void) ndi_prop_update_string(DDI_DEV_T_NONE, cpu_devi, 34787c478bd9Sstevel@tonic-gate "vendor-id", cpi->cpi_vendorstr); 34797c478bd9Sstevel@tonic-gate 34807c478bd9Sstevel@tonic-gate if (cpi->cpi_maxeax == 0) { 34817c478bd9Sstevel@tonic-gate mutex_exit(&cpu_node_lock); 34827c478bd9Sstevel@tonic-gate return; 34837c478bd9Sstevel@tonic-gate } 34847c478bd9Sstevel@tonic-gate 34857c478bd9Sstevel@tonic-gate /* 34867c478bd9Sstevel@tonic-gate * family, model, and step 34877c478bd9Sstevel@tonic-gate */ 34887c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 34897c478bd9Sstevel@tonic-gate "family", CPI_FAMILY(cpi)); 34907c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 34917c478bd9Sstevel@tonic-gate "cpu-model", CPI_MODEL(cpi)); 34927c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 34937c478bd9Sstevel@tonic-gate "stepping-id", CPI_STEP(cpi)); 34947c478bd9Sstevel@tonic-gate 34957c478bd9Sstevel@tonic-gate /* type */ 34967c478bd9Sstevel@tonic-gate 34977c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 34987c478bd9Sstevel@tonic-gate case X86_VENDOR_Intel: 34997c478bd9Sstevel@tonic-gate create = 1; 35007c478bd9Sstevel@tonic-gate break; 35017c478bd9Sstevel@tonic-gate default: 35027c478bd9Sstevel@tonic-gate create = 0; 35037c478bd9Sstevel@tonic-gate break; 35047c478bd9Sstevel@tonic-gate } 35057c478bd9Sstevel@tonic-gate if (create) 35067c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 35077c478bd9Sstevel@tonic-gate "type", CPI_TYPE(cpi)); 35087c478bd9Sstevel@tonic-gate 35097c478bd9Sstevel@tonic-gate /* ext-family */ 35107c478bd9Sstevel@tonic-gate 35117c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 35127c478bd9Sstevel@tonic-gate case X86_VENDOR_Intel: 35137c478bd9Sstevel@tonic-gate case X86_VENDOR_AMD: 35147c478bd9Sstevel@tonic-gate create = cpi->cpi_family >= 0xf; 35157c478bd9Sstevel@tonic-gate break; 35167c478bd9Sstevel@tonic-gate default: 35177c478bd9Sstevel@tonic-gate create = 0; 35187c478bd9Sstevel@tonic-gate break; 35197c478bd9Sstevel@tonic-gate } 35207c478bd9Sstevel@tonic-gate if (create) 35217c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 35227c478bd9Sstevel@tonic-gate "ext-family", CPI_FAMILY_XTD(cpi)); 35237c478bd9Sstevel@tonic-gate 35247c478bd9Sstevel@tonic-gate /* ext-model */ 35257c478bd9Sstevel@tonic-gate 35267c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 35277c478bd9Sstevel@tonic-gate case X86_VENDOR_Intel: 352863d3f7dfSkk208521 create = IS_EXTENDED_MODEL_INTEL(cpi); 352968c91426Sdmick break; 35307c478bd9Sstevel@tonic-gate case X86_VENDOR_AMD: 3531ee88d2b9Skchow create = CPI_FAMILY(cpi) == 0xf; 35327c478bd9Sstevel@tonic-gate break; 35337c478bd9Sstevel@tonic-gate default: 35347c478bd9Sstevel@tonic-gate create = 0; 35357c478bd9Sstevel@tonic-gate break; 35367c478bd9Sstevel@tonic-gate } 35377c478bd9Sstevel@tonic-gate if (create) 35387c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 35397c478bd9Sstevel@tonic-gate "ext-model", CPI_MODEL_XTD(cpi)); 35407c478bd9Sstevel@tonic-gate 35417c478bd9Sstevel@tonic-gate /* generation */ 35427c478bd9Sstevel@tonic-gate 35437c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 35447c478bd9Sstevel@tonic-gate case X86_VENDOR_AMD: 35457c478bd9Sstevel@tonic-gate /* 35467c478bd9Sstevel@tonic-gate * AMD K5 model 1 was the first part to support this 35477c478bd9Sstevel@tonic-gate */ 35487c478bd9Sstevel@tonic-gate create = cpi->cpi_xmaxeax >= 0x80000001; 35497c478bd9Sstevel@tonic-gate break; 35507c478bd9Sstevel@tonic-gate default: 35517c478bd9Sstevel@tonic-gate create = 0; 35527c478bd9Sstevel@tonic-gate break; 35537c478bd9Sstevel@tonic-gate } 35547c478bd9Sstevel@tonic-gate if (create) 35557c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 35567c478bd9Sstevel@tonic-gate "generation", BITX((cpi)->cpi_extd[1].cp_eax, 11, 8)); 35577c478bd9Sstevel@tonic-gate 35587c478bd9Sstevel@tonic-gate /* brand-id */ 35597c478bd9Sstevel@tonic-gate 35607c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 35617c478bd9Sstevel@tonic-gate case X86_VENDOR_Intel: 35627c478bd9Sstevel@tonic-gate /* 35637c478bd9Sstevel@tonic-gate * brand id first appeared on Pentium III Xeon model 8, 35647c478bd9Sstevel@tonic-gate * and Celeron model 8 processors and Opteron 35657c478bd9Sstevel@tonic-gate */ 35667c478bd9Sstevel@tonic-gate create = cpi->cpi_family > 6 || 35677c478bd9Sstevel@tonic-gate (cpi->cpi_family == 6 && cpi->cpi_model >= 8); 35687c478bd9Sstevel@tonic-gate break; 35697c478bd9Sstevel@tonic-gate case X86_VENDOR_AMD: 35707c478bd9Sstevel@tonic-gate create = cpi->cpi_family >= 0xf; 35717c478bd9Sstevel@tonic-gate break; 35727c478bd9Sstevel@tonic-gate default: 35737c478bd9Sstevel@tonic-gate create = 0; 35747c478bd9Sstevel@tonic-gate break; 35757c478bd9Sstevel@tonic-gate } 35767c478bd9Sstevel@tonic-gate if (create && cpi->cpi_brandid != 0) { 35777c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 35787c478bd9Sstevel@tonic-gate "brand-id", cpi->cpi_brandid); 35797c478bd9Sstevel@tonic-gate } 35807c478bd9Sstevel@tonic-gate 35817c478bd9Sstevel@tonic-gate /* chunks, and apic-id */ 35827c478bd9Sstevel@tonic-gate 35837c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 35847c478bd9Sstevel@tonic-gate /* 35857c478bd9Sstevel@tonic-gate * first available on Pentium IV and Opteron (K8) 35867c478bd9Sstevel@tonic-gate */ 35875ff02082Sdmick case X86_VENDOR_Intel: 35885ff02082Sdmick create = IS_NEW_F6(cpi) || cpi->cpi_family >= 0xf; 35895ff02082Sdmick break; 35905ff02082Sdmick case X86_VENDOR_AMD: 35917c478bd9Sstevel@tonic-gate create = cpi->cpi_family >= 0xf; 35927c478bd9Sstevel@tonic-gate break; 35937c478bd9Sstevel@tonic-gate default: 35947c478bd9Sstevel@tonic-gate create = 0; 35957c478bd9Sstevel@tonic-gate break; 35967c478bd9Sstevel@tonic-gate } 35977c478bd9Sstevel@tonic-gate if (create) { 35987c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 35997c478bd9Sstevel@tonic-gate "chunks", CPI_CHUNKS(cpi)); 36007c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 3601b6917abeSmishra "apic-id", cpi->cpi_apicid); 36027aec1d6eScindi if (cpi->cpi_chipid >= 0) { 36037c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 36047c478bd9Sstevel@tonic-gate "chip#", cpi->cpi_chipid); 36057aec1d6eScindi (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 36067aec1d6eScindi "clog#", cpi->cpi_clogid); 36077aec1d6eScindi } 36087c478bd9Sstevel@tonic-gate } 36097c478bd9Sstevel@tonic-gate 36107c478bd9Sstevel@tonic-gate /* cpuid-features */ 36117c478bd9Sstevel@tonic-gate 36127c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 36137c478bd9Sstevel@tonic-gate "cpuid-features", CPI_FEATURES_EDX(cpi)); 36147c478bd9Sstevel@tonic-gate 36157c478bd9Sstevel@tonic-gate 36167c478bd9Sstevel@tonic-gate /* cpuid-features-ecx */ 36177c478bd9Sstevel@tonic-gate 36187c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 36197c478bd9Sstevel@tonic-gate case X86_VENDOR_Intel: 36205ff02082Sdmick create = IS_NEW_F6(cpi) || cpi->cpi_family >= 0xf; 36217c478bd9Sstevel@tonic-gate break; 36227c478bd9Sstevel@tonic-gate default: 36237c478bd9Sstevel@tonic-gate create = 0; 36247c478bd9Sstevel@tonic-gate break; 36257c478bd9Sstevel@tonic-gate } 36267c478bd9Sstevel@tonic-gate if (create) 36277c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 36287c478bd9Sstevel@tonic-gate "cpuid-features-ecx", CPI_FEATURES_ECX(cpi)); 36297c478bd9Sstevel@tonic-gate 36307c478bd9Sstevel@tonic-gate /* ext-cpuid-features */ 36317c478bd9Sstevel@tonic-gate 36327c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 36335ff02082Sdmick case X86_VENDOR_Intel: 36347c478bd9Sstevel@tonic-gate case X86_VENDOR_AMD: 36357c478bd9Sstevel@tonic-gate case X86_VENDOR_Cyrix: 36367c478bd9Sstevel@tonic-gate case X86_VENDOR_TM: 36377c478bd9Sstevel@tonic-gate case X86_VENDOR_Centaur: 36387c478bd9Sstevel@tonic-gate create = cpi->cpi_xmaxeax >= 0x80000001; 36397c478bd9Sstevel@tonic-gate break; 36407c478bd9Sstevel@tonic-gate default: 36417c478bd9Sstevel@tonic-gate create = 0; 36427c478bd9Sstevel@tonic-gate break; 36437c478bd9Sstevel@tonic-gate } 36445ff02082Sdmick if (create) { 36457c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 36467c478bd9Sstevel@tonic-gate "ext-cpuid-features", CPI_FEATURES_XTD_EDX(cpi)); 36475ff02082Sdmick (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 36485ff02082Sdmick "ext-cpuid-features-ecx", CPI_FEATURES_XTD_ECX(cpi)); 36495ff02082Sdmick } 36507c478bd9Sstevel@tonic-gate 36517c478bd9Sstevel@tonic-gate /* 36527c478bd9Sstevel@tonic-gate * Brand String first appeared in Intel Pentium IV, AMD K5 36537c478bd9Sstevel@tonic-gate * model 1, and Cyrix GXm. On earlier models we try and 36547c478bd9Sstevel@tonic-gate * simulate something similar .. so this string should always 36557c478bd9Sstevel@tonic-gate * same -something- about the processor, however lame. 36567c478bd9Sstevel@tonic-gate */ 36577c478bd9Sstevel@tonic-gate (void) ndi_prop_update_string(DDI_DEV_T_NONE, cpu_devi, 36587c478bd9Sstevel@tonic-gate "brand-string", cpi->cpi_brandstr); 36597c478bd9Sstevel@tonic-gate 36607c478bd9Sstevel@tonic-gate /* 36617c478bd9Sstevel@tonic-gate * Finally, cache and tlb information 36627c478bd9Sstevel@tonic-gate */ 36637c478bd9Sstevel@tonic-gate switch (x86_which_cacheinfo(cpi)) { 36647c478bd9Sstevel@tonic-gate case X86_VENDOR_Intel: 36657c478bd9Sstevel@tonic-gate intel_walk_cacheinfo(cpi, cpu_devi, add_cacheent_props); 36667c478bd9Sstevel@tonic-gate break; 36677c478bd9Sstevel@tonic-gate case X86_VENDOR_Cyrix: 36687c478bd9Sstevel@tonic-gate cyrix_walk_cacheinfo(cpi, cpu_devi, add_cacheent_props); 36697c478bd9Sstevel@tonic-gate break; 36707c478bd9Sstevel@tonic-gate case X86_VENDOR_AMD: 36717c478bd9Sstevel@tonic-gate amd_cache_info(cpi, cpu_devi); 36727c478bd9Sstevel@tonic-gate break; 36737c478bd9Sstevel@tonic-gate default: 36747c478bd9Sstevel@tonic-gate break; 36757c478bd9Sstevel@tonic-gate } 36767c478bd9Sstevel@tonic-gate 36777c478bd9Sstevel@tonic-gate mutex_exit(&cpu_node_lock); 36787c478bd9Sstevel@tonic-gate } 36797c478bd9Sstevel@tonic-gate 36807c478bd9Sstevel@tonic-gate struct l2info { 36817c478bd9Sstevel@tonic-gate int *l2i_csz; 36827c478bd9Sstevel@tonic-gate int *l2i_lsz; 36837c478bd9Sstevel@tonic-gate int *l2i_assoc; 36847c478bd9Sstevel@tonic-gate int l2i_ret; 36857c478bd9Sstevel@tonic-gate }; 36867c478bd9Sstevel@tonic-gate 36877c478bd9Sstevel@tonic-gate /* 36887c478bd9Sstevel@tonic-gate * A cacheinfo walker that fetches the size, line-size and associativity 36897c478bd9Sstevel@tonic-gate * of the L2 cache 36907c478bd9Sstevel@tonic-gate */ 36917c478bd9Sstevel@tonic-gate static int 36927c478bd9Sstevel@tonic-gate intel_l2cinfo(void *arg, const struct cachetab *ct) 36937c478bd9Sstevel@tonic-gate { 36947c478bd9Sstevel@tonic-gate struct l2info *l2i = arg; 36957c478bd9Sstevel@tonic-gate int *ip; 36967c478bd9Sstevel@tonic-gate 36977c478bd9Sstevel@tonic-gate if (ct->ct_label != l2_cache_str && 36987c478bd9Sstevel@tonic-gate ct->ct_label != sl2_cache_str) 36997c478bd9Sstevel@tonic-gate return (0); /* not an L2 -- keep walking */ 37007c478bd9Sstevel@tonic-gate 37017c478bd9Sstevel@tonic-gate if ((ip = l2i->l2i_csz) != NULL) 37027c478bd9Sstevel@tonic-gate *ip = ct->ct_size; 37037c478bd9Sstevel@tonic-gate if ((ip = l2i->l2i_lsz) != NULL) 37047c478bd9Sstevel@tonic-gate *ip = ct->ct_line_size; 37057c478bd9Sstevel@tonic-gate if ((ip = l2i->l2i_assoc) != NULL) 37067c478bd9Sstevel@tonic-gate *ip = ct->ct_assoc; 37077c478bd9Sstevel@tonic-gate l2i->l2i_ret = ct->ct_size; 37087c478bd9Sstevel@tonic-gate return (1); /* was an L2 -- terminate walk */ 37097c478bd9Sstevel@tonic-gate } 37107c478bd9Sstevel@tonic-gate 3711606303c9Skchow /* 3712606303c9Skchow * AMD L2/L3 Cache and TLB Associativity Field Definition: 3713606303c9Skchow * 3714606303c9Skchow * Unlike the associativity for the L1 cache and tlb where the 8 bit 3715606303c9Skchow * value is the associativity, the associativity for the L2 cache and 3716606303c9Skchow * tlb is encoded in the following table. The 4 bit L2 value serves as 3717606303c9Skchow * an index into the amd_afd[] array to determine the associativity. 3718606303c9Skchow * -1 is undefined. 0 is fully associative. 3719606303c9Skchow */ 3720606303c9Skchow 3721606303c9Skchow static int amd_afd[] = 3722606303c9Skchow {-1, 1, 2, -1, 4, -1, 8, -1, 16, -1, 32, 48, 64, 96, 128, 0}; 3723606303c9Skchow 37247c478bd9Sstevel@tonic-gate static void 37257c478bd9Sstevel@tonic-gate amd_l2cacheinfo(struct cpuid_info *cpi, struct l2info *l2i) 37267c478bd9Sstevel@tonic-gate { 37278949bcd6Sandrei struct cpuid_regs *cp; 37287c478bd9Sstevel@tonic-gate uint_t size, assoc; 3729606303c9Skchow int i; 37307c478bd9Sstevel@tonic-gate int *ip; 37317c478bd9Sstevel@tonic-gate 37327c478bd9Sstevel@tonic-gate if (cpi->cpi_xmaxeax < 0x80000006) 37337c478bd9Sstevel@tonic-gate return; 37347c478bd9Sstevel@tonic-gate cp = &cpi->cpi_extd[6]; 37357c478bd9Sstevel@tonic-gate 3736606303c9Skchow if ((i = BITX(cp->cp_ecx, 15, 12)) != 0 && 37377c478bd9Sstevel@tonic-gate (size = BITX(cp->cp_ecx, 31, 16)) != 0) { 37387c478bd9Sstevel@tonic-gate uint_t cachesz = size * 1024; 3739606303c9Skchow assoc = amd_afd[i]; 37407c478bd9Sstevel@tonic-gate 3741606303c9Skchow ASSERT(assoc != -1); 37427c478bd9Sstevel@tonic-gate 37437c478bd9Sstevel@tonic-gate if ((ip = l2i->l2i_csz) != NULL) 37447c478bd9Sstevel@tonic-gate *ip = cachesz; 37457c478bd9Sstevel@tonic-gate if ((ip = l2i->l2i_lsz) != NULL) 37467c478bd9Sstevel@tonic-gate *ip = BITX(cp->cp_ecx, 7, 0); 37477c478bd9Sstevel@tonic-gate if ((ip = l2i->l2i_assoc) != NULL) 37487c478bd9Sstevel@tonic-gate *ip = assoc; 37497c478bd9Sstevel@tonic-gate l2i->l2i_ret = cachesz; 37507c478bd9Sstevel@tonic-gate } 37517c478bd9Sstevel@tonic-gate } 37527c478bd9Sstevel@tonic-gate 37537c478bd9Sstevel@tonic-gate int 37547c478bd9Sstevel@tonic-gate getl2cacheinfo(cpu_t *cpu, int *csz, int *lsz, int *assoc) 37557c478bd9Sstevel@tonic-gate { 37567c478bd9Sstevel@tonic-gate struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 37577c478bd9Sstevel@tonic-gate struct l2info __l2info, *l2i = &__l2info; 37587c478bd9Sstevel@tonic-gate 37597c478bd9Sstevel@tonic-gate l2i->l2i_csz = csz; 37607c478bd9Sstevel@tonic-gate l2i->l2i_lsz = lsz; 37617c478bd9Sstevel@tonic-gate l2i->l2i_assoc = assoc; 37627c478bd9Sstevel@tonic-gate l2i->l2i_ret = -1; 37637c478bd9Sstevel@tonic-gate 37647c478bd9Sstevel@tonic-gate switch (x86_which_cacheinfo(cpi)) { 37657c478bd9Sstevel@tonic-gate case X86_VENDOR_Intel: 37667c478bd9Sstevel@tonic-gate intel_walk_cacheinfo(cpi, l2i, intel_l2cinfo); 37677c478bd9Sstevel@tonic-gate break; 37687c478bd9Sstevel@tonic-gate case X86_VENDOR_Cyrix: 37697c478bd9Sstevel@tonic-gate cyrix_walk_cacheinfo(cpi, l2i, intel_l2cinfo); 37707c478bd9Sstevel@tonic-gate break; 37717c478bd9Sstevel@tonic-gate case X86_VENDOR_AMD: 37727c478bd9Sstevel@tonic-gate amd_l2cacheinfo(cpi, l2i); 37737c478bd9Sstevel@tonic-gate break; 37747c478bd9Sstevel@tonic-gate default: 37757c478bd9Sstevel@tonic-gate break; 37767c478bd9Sstevel@tonic-gate } 37777c478bd9Sstevel@tonic-gate return (l2i->l2i_ret); 37787c478bd9Sstevel@tonic-gate } 3779f98fbcecSbholler 3780843e1988Sjohnlev #if !defined(__xpv) 3781843e1988Sjohnlev 37825b8a6efeSbholler uint32_t * 37835b8a6efeSbholler cpuid_mwait_alloc(cpu_t *cpu) 37845b8a6efeSbholler { 37855b8a6efeSbholler uint32_t *ret; 37865b8a6efeSbholler size_t mwait_size; 37875b8a6efeSbholler 37885b8a6efeSbholler ASSERT(cpuid_checkpass(cpu, 2)); 37895b8a6efeSbholler 37905b8a6efeSbholler mwait_size = cpu->cpu_m.mcpu_cpi->cpi_mwait.mon_max; 37915b8a6efeSbholler if (mwait_size == 0) 37925b8a6efeSbholler return (NULL); 37935b8a6efeSbholler 37945b8a6efeSbholler /* 37955b8a6efeSbholler * kmem_alloc() returns cache line size aligned data for mwait_size 37965b8a6efeSbholler * allocations. mwait_size is currently cache line sized. Neither 37975b8a6efeSbholler * of these implementation details are guarantied to be true in the 37985b8a6efeSbholler * future. 37995b8a6efeSbholler * 38005b8a6efeSbholler * First try allocating mwait_size as kmem_alloc() currently returns 38015b8a6efeSbholler * correctly aligned memory. If kmem_alloc() does not return 38025b8a6efeSbholler * mwait_size aligned memory, then use mwait_size ROUNDUP. 38035b8a6efeSbholler * 38045b8a6efeSbholler * Set cpi_mwait.buf_actual and cpi_mwait.size_actual in case we 38055b8a6efeSbholler * decide to free this memory. 38065b8a6efeSbholler */ 38075b8a6efeSbholler ret = kmem_zalloc(mwait_size, KM_SLEEP); 38085b8a6efeSbholler if (ret == (uint32_t *)P2ROUNDUP((uintptr_t)ret, mwait_size)) { 38095b8a6efeSbholler cpu->cpu_m.mcpu_cpi->cpi_mwait.buf_actual = ret; 38105b8a6efeSbholler cpu->cpu_m.mcpu_cpi->cpi_mwait.size_actual = mwait_size; 38115b8a6efeSbholler *ret = MWAIT_RUNNING; 38125b8a6efeSbholler return (ret); 38135b8a6efeSbholler } else { 38145b8a6efeSbholler kmem_free(ret, mwait_size); 38155b8a6efeSbholler ret = kmem_zalloc(mwait_size * 2, KM_SLEEP); 38165b8a6efeSbholler cpu->cpu_m.mcpu_cpi->cpi_mwait.buf_actual = ret; 38175b8a6efeSbholler cpu->cpu_m.mcpu_cpi->cpi_mwait.size_actual = mwait_size * 2; 38185b8a6efeSbholler ret = (uint32_t *)P2ROUNDUP((uintptr_t)ret, mwait_size); 38195b8a6efeSbholler *ret = MWAIT_RUNNING; 38205b8a6efeSbholler return (ret); 38215b8a6efeSbholler } 38225b8a6efeSbholler } 38235b8a6efeSbholler 38245b8a6efeSbholler void 38255b8a6efeSbholler cpuid_mwait_free(cpu_t *cpu) 3826f98fbcecSbholler { 3827f98fbcecSbholler ASSERT(cpuid_checkpass(cpu, 2)); 38285b8a6efeSbholler 38295b8a6efeSbholler if (cpu->cpu_m.mcpu_cpi->cpi_mwait.buf_actual != NULL && 38305b8a6efeSbholler cpu->cpu_m.mcpu_cpi->cpi_mwait.size_actual > 0) { 38315b8a6efeSbholler kmem_free(cpu->cpu_m.mcpu_cpi->cpi_mwait.buf_actual, 38325b8a6efeSbholler cpu->cpu_m.mcpu_cpi->cpi_mwait.size_actual); 38335b8a6efeSbholler } 38345b8a6efeSbholler 38355b8a6efeSbholler cpu->cpu_m.mcpu_cpi->cpi_mwait.buf_actual = NULL; 38365b8a6efeSbholler cpu->cpu_m.mcpu_cpi->cpi_mwait.size_actual = 0; 3837f98fbcecSbholler } 3838843e1988Sjohnlev 3839247dbb3dSsudheer void 3840247dbb3dSsudheer patch_tsc_read(int flag) 3841247dbb3dSsudheer { 3842247dbb3dSsudheer size_t cnt; 3843e4b86885SCheng Sean Ye 3844247dbb3dSsudheer switch (flag) { 3845247dbb3dSsudheer case X86_NO_TSC: 3846247dbb3dSsudheer cnt = &_no_rdtsc_end - &_no_rdtsc_start; 38472b0bcb26Ssudheer (void) memcpy((void *)tsc_read, (void *)&_no_rdtsc_start, cnt); 3848247dbb3dSsudheer break; 3849247dbb3dSsudheer case X86_HAVE_TSCP: 3850247dbb3dSsudheer cnt = &_tscp_end - &_tscp_start; 38512b0bcb26Ssudheer (void) memcpy((void *)tsc_read, (void *)&_tscp_start, cnt); 3852247dbb3dSsudheer break; 3853247dbb3dSsudheer case X86_TSC_MFENCE: 3854247dbb3dSsudheer cnt = &_tsc_mfence_end - &_tsc_mfence_start; 38552b0bcb26Ssudheer (void) memcpy((void *)tsc_read, 38562b0bcb26Ssudheer (void *)&_tsc_mfence_start, cnt); 3857247dbb3dSsudheer break; 385815363b27Ssudheer case X86_TSC_LFENCE: 385915363b27Ssudheer cnt = &_tsc_lfence_end - &_tsc_lfence_start; 386015363b27Ssudheer (void) memcpy((void *)tsc_read, 386115363b27Ssudheer (void *)&_tsc_lfence_start, cnt); 386215363b27Ssudheer break; 3863247dbb3dSsudheer default: 3864247dbb3dSsudheer break; 3865247dbb3dSsudheer } 3866247dbb3dSsudheer } 3867247dbb3dSsudheer 38680e751525SEric Saxe int 38690e751525SEric Saxe cpuid_deep_cstates_supported(void) 38700e751525SEric Saxe { 38710e751525SEric Saxe struct cpuid_info *cpi; 38720e751525SEric Saxe struct cpuid_regs regs; 38730e751525SEric Saxe 38740e751525SEric Saxe ASSERT(cpuid_checkpass(CPU, 1)); 38750e751525SEric Saxe 38760e751525SEric Saxe cpi = CPU->cpu_m.mcpu_cpi; 38770e751525SEric Saxe 38780e751525SEric Saxe if (!(x86_feature & X86_CPUID)) 38790e751525SEric Saxe return (0); 38800e751525SEric Saxe 38810e751525SEric Saxe switch (cpi->cpi_vendor) { 38820e751525SEric Saxe case X86_VENDOR_Intel: 38830e751525SEric Saxe if (cpi->cpi_xmaxeax < 0x80000007) 38840e751525SEric Saxe return (0); 38850e751525SEric Saxe 38860e751525SEric Saxe /* 38870e751525SEric Saxe * TSC run at a constant rate in all ACPI C-states? 38880e751525SEric Saxe */ 38890e751525SEric Saxe regs.cp_eax = 0x80000007; 38900e751525SEric Saxe (void) __cpuid_insn(®s); 38910e751525SEric Saxe return (regs.cp_edx & CPUID_TSC_CSTATE_INVARIANCE); 38920e751525SEric Saxe 38930e751525SEric Saxe default: 38940e751525SEric Saxe return (0); 38950e751525SEric Saxe } 38960e751525SEric Saxe } 38970e751525SEric Saxe 3898*e774b42bSBill Holler #endif /* !__xpv */ 3899*e774b42bSBill Holler 3900*e774b42bSBill Holler void 3901*e774b42bSBill Holler post_startup_cpu_fixups(void) 3902*e774b42bSBill Holler { 3903*e774b42bSBill Holler #ifndef __xpv 3904*e774b42bSBill Holler /* 3905*e774b42bSBill Holler * Some AMD processors support C1E state. Entering this state will 3906*e774b42bSBill Holler * cause the local APIC timer to stop, which we can't deal with at 3907*e774b42bSBill Holler * this time. 3908*e774b42bSBill Holler */ 3909*e774b42bSBill Holler if (cpuid_getvendor(CPU) == X86_VENDOR_AMD) { 3910*e774b42bSBill Holler on_trap_data_t otd; 3911*e774b42bSBill Holler uint64_t reg; 3912*e774b42bSBill Holler 3913*e774b42bSBill Holler if (!on_trap(&otd, OT_DATA_ACCESS)) { 3914*e774b42bSBill Holler reg = rdmsr(MSR_AMD_INT_PENDING_CMP_HALT); 3915*e774b42bSBill Holler /* Disable C1E state if it is enabled by BIOS */ 3916*e774b42bSBill Holler if ((reg >> AMD_ACTONCMPHALT_SHIFT) & 3917*e774b42bSBill Holler AMD_ACTONCMPHALT_MASK) { 3918*e774b42bSBill Holler reg &= ~(AMD_ACTONCMPHALT_MASK << 3919*e774b42bSBill Holler AMD_ACTONCMPHALT_SHIFT); 3920*e774b42bSBill Holler wrmsr(MSR_AMD_INT_PENDING_CMP_HALT, reg); 3921*e774b42bSBill Holler } 3922*e774b42bSBill Holler } 3923*e774b42bSBill Holler no_trap(); 3924*e774b42bSBill Holler } 3925*e774b42bSBill Holler #endif /* !__xpv */ 3926*e774b42bSBill Holler } 3927*e774b42bSBill Holler 392822cc0e45SBill Holler #if defined(__amd64) && !defined(__xpv) 392922cc0e45SBill Holler /* 393022cc0e45SBill Holler * Patch in versions of bcopy for high performance Intel Nhm processors 393122cc0e45SBill Holler * and later... 393222cc0e45SBill Holler */ 393322cc0e45SBill Holler void 393422cc0e45SBill Holler patch_memops(uint_t vendor) 393522cc0e45SBill Holler { 393622cc0e45SBill Holler size_t cnt, i; 393722cc0e45SBill Holler caddr_t to, from; 393822cc0e45SBill Holler 393922cc0e45SBill Holler if ((vendor == X86_VENDOR_Intel) && ((x86_feature & X86_SSE4_2) != 0)) { 394022cc0e45SBill Holler cnt = &bcopy_patch_end - &bcopy_patch_start; 394122cc0e45SBill Holler to = &bcopy_ck_size; 394222cc0e45SBill Holler from = &bcopy_patch_start; 394322cc0e45SBill Holler for (i = 0; i < cnt; i++) { 394422cc0e45SBill Holler *to++ = *from++; 394522cc0e45SBill Holler } 394622cc0e45SBill Holler } 394722cc0e45SBill Holler } 394822cc0e45SBill Holler #endif /* __amd64 && !__xpv */ 3949