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 /* 2210569901Sgavinm * Copyright 2008 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 49*e4b86885SCheng Sean Ye #ifdef __xpv 50*e4b86885SCheng Sean Ye #include <sys/hypervisor.h> 51*e4b86885SCheng Sean Ye #endif 52*e4b86885SCheng Sean Ye 537c478bd9Sstevel@tonic-gate /* 547c478bd9Sstevel@tonic-gate * Pass 0 of cpuid feature analysis happens in locore. It contains special code 557c478bd9Sstevel@tonic-gate * to recognize Cyrix processors that are not cpuid-compliant, and to deal with 567c478bd9Sstevel@tonic-gate * them accordingly. For most modern processors, feature detection occurs here 577c478bd9Sstevel@tonic-gate * in pass 1. 587c478bd9Sstevel@tonic-gate * 597c478bd9Sstevel@tonic-gate * Pass 1 of cpuid feature analysis happens just at the beginning of mlsetup() 607c478bd9Sstevel@tonic-gate * for the boot CPU and does the basic analysis that the early kernel needs. 617c478bd9Sstevel@tonic-gate * x86_feature is set based on the return value of cpuid_pass1() of the boot 627c478bd9Sstevel@tonic-gate * CPU. 637c478bd9Sstevel@tonic-gate * 647c478bd9Sstevel@tonic-gate * Pass 1 includes: 657c478bd9Sstevel@tonic-gate * 667c478bd9Sstevel@tonic-gate * o Determining vendor/model/family/stepping and setting x86_type and 677c478bd9Sstevel@tonic-gate * x86_vendor accordingly. 687c478bd9Sstevel@tonic-gate * o Processing the feature flags returned by the cpuid instruction while 697c478bd9Sstevel@tonic-gate * applying any workarounds or tricks for the specific processor. 707c478bd9Sstevel@tonic-gate * o Mapping the feature flags into Solaris feature bits (X86_*). 717c478bd9Sstevel@tonic-gate * o Processing extended feature flags if supported by the processor, 727c478bd9Sstevel@tonic-gate * again while applying specific processor knowledge. 737c478bd9Sstevel@tonic-gate * o Determining the CMT characteristics of the system. 747c478bd9Sstevel@tonic-gate * 757c478bd9Sstevel@tonic-gate * Pass 1 is done on non-boot CPUs during their initialization and the results 767c478bd9Sstevel@tonic-gate * are used only as a meager attempt at ensuring that all processors within the 777c478bd9Sstevel@tonic-gate * system support the same features. 787c478bd9Sstevel@tonic-gate * 797c478bd9Sstevel@tonic-gate * Pass 2 of cpuid feature analysis happens just at the beginning 807c478bd9Sstevel@tonic-gate * of startup(). It just copies in and corrects the remainder 817c478bd9Sstevel@tonic-gate * of the cpuid data we depend on: standard cpuid functions that we didn't 827c478bd9Sstevel@tonic-gate * need for pass1 feature analysis, and extended cpuid functions beyond the 837c478bd9Sstevel@tonic-gate * simple feature processing done in pass1. 847c478bd9Sstevel@tonic-gate * 857c478bd9Sstevel@tonic-gate * Pass 3 of cpuid analysis is invoked after basic kernel services; in 867c478bd9Sstevel@tonic-gate * particular kernel memory allocation has been made available. It creates a 877c478bd9Sstevel@tonic-gate * readable brand string based on the data collected in the first two passes. 887c478bd9Sstevel@tonic-gate * 897c478bd9Sstevel@tonic-gate * Pass 4 of cpuid analysis is invoked after post_startup() when all 907c478bd9Sstevel@tonic-gate * the support infrastructure for various hardware features has been 917c478bd9Sstevel@tonic-gate * initialized. It determines which processor features will be reported 927c478bd9Sstevel@tonic-gate * to userland via the aux vector. 937c478bd9Sstevel@tonic-gate * 947c478bd9Sstevel@tonic-gate * All passes are executed on all CPUs, but only the boot CPU determines what 957c478bd9Sstevel@tonic-gate * features the kernel will use. 967c478bd9Sstevel@tonic-gate * 977c478bd9Sstevel@tonic-gate * Much of the worst junk in this file is for the support of processors 987c478bd9Sstevel@tonic-gate * that didn't really implement the cpuid instruction properly. 997c478bd9Sstevel@tonic-gate * 1007c478bd9Sstevel@tonic-gate * NOTE: The accessor functions (cpuid_get*) are aware of, and ASSERT upon, 1017c478bd9Sstevel@tonic-gate * the pass numbers. Accordingly, changes to the pass code may require changes 1027c478bd9Sstevel@tonic-gate * to the accessor code. 1037c478bd9Sstevel@tonic-gate */ 1047c478bd9Sstevel@tonic-gate 1057c478bd9Sstevel@tonic-gate uint_t x86_feature = 0; 1067c478bd9Sstevel@tonic-gate uint_t x86_vendor = X86_VENDOR_IntelClone; 1077c478bd9Sstevel@tonic-gate uint_t x86_type = X86_TYPE_OTHER; 1087c478bd9Sstevel@tonic-gate 1097c478bd9Sstevel@tonic-gate uint_t pentiumpro_bug4046376; 1107c478bd9Sstevel@tonic-gate uint_t pentiumpro_bug4064495; 1117c478bd9Sstevel@tonic-gate 1127c478bd9Sstevel@tonic-gate uint_t enable486; 1137c478bd9Sstevel@tonic-gate 1147c478bd9Sstevel@tonic-gate /* 115f98fbcecSbholler * monitor/mwait info. 1165b8a6efeSbholler * 1175b8a6efeSbholler * size_actual and buf_actual are the real address and size allocated to get 1185b8a6efeSbholler * proper mwait_buf alignement. buf_actual and size_actual should be passed 1195b8a6efeSbholler * to kmem_free(). Currently kmem_alloc() and mwait happen to both use 1205b8a6efeSbholler * processor cache-line alignment, but this is not guarantied in the furture. 121f98fbcecSbholler */ 122f98fbcecSbholler struct mwait_info { 123f98fbcecSbholler size_t mon_min; /* min size to avoid missed wakeups */ 124f98fbcecSbholler size_t mon_max; /* size to avoid false wakeups */ 1255b8a6efeSbholler size_t size_actual; /* size actually allocated */ 1265b8a6efeSbholler void *buf_actual; /* memory actually allocated */ 127f98fbcecSbholler uint32_t support; /* processor support of monitor/mwait */ 128f98fbcecSbholler }; 129f98fbcecSbholler 130f98fbcecSbholler /* 1317c478bd9Sstevel@tonic-gate * These constants determine how many of the elements of the 1327c478bd9Sstevel@tonic-gate * cpuid we cache in the cpuid_info data structure; the 1337c478bd9Sstevel@tonic-gate * remaining elements are accessible via the cpuid instruction. 1347c478bd9Sstevel@tonic-gate */ 1357c478bd9Sstevel@tonic-gate 1367c478bd9Sstevel@tonic-gate #define NMAX_CPI_STD 6 /* eax = 0 .. 5 */ 1377c478bd9Sstevel@tonic-gate #define NMAX_CPI_EXTD 9 /* eax = 0x80000000 .. 0x80000008 */ 1387c478bd9Sstevel@tonic-gate 1397c478bd9Sstevel@tonic-gate struct cpuid_info { 1407c478bd9Sstevel@tonic-gate uint_t cpi_pass; /* last pass completed */ 1417c478bd9Sstevel@tonic-gate /* 1427c478bd9Sstevel@tonic-gate * standard function information 1437c478bd9Sstevel@tonic-gate */ 1447c478bd9Sstevel@tonic-gate uint_t cpi_maxeax; /* fn 0: %eax */ 1457c478bd9Sstevel@tonic-gate char cpi_vendorstr[13]; /* fn 0: %ebx:%ecx:%edx */ 1467c478bd9Sstevel@tonic-gate uint_t cpi_vendor; /* enum of cpi_vendorstr */ 1477c478bd9Sstevel@tonic-gate 1487c478bd9Sstevel@tonic-gate uint_t cpi_family; /* fn 1: extended family */ 1497c478bd9Sstevel@tonic-gate uint_t cpi_model; /* fn 1: extended model */ 1507c478bd9Sstevel@tonic-gate uint_t cpi_step; /* fn 1: stepping */ 1517c478bd9Sstevel@tonic-gate chipid_t cpi_chipid; /* fn 1: %ebx: chip # on ht cpus */ 1527c478bd9Sstevel@tonic-gate uint_t cpi_brandid; /* fn 1: %ebx: brand ID */ 1537c478bd9Sstevel@tonic-gate int cpi_clogid; /* fn 1: %ebx: thread # */ 1548949bcd6Sandrei uint_t cpi_ncpu_per_chip; /* fn 1: %ebx: logical cpu count */ 1557c478bd9Sstevel@tonic-gate uint8_t cpi_cacheinfo[16]; /* fn 2: intel-style cache desc */ 1567c478bd9Sstevel@tonic-gate uint_t cpi_ncache; /* fn 2: number of elements */ 157d129bde2Sesaxe uint_t cpi_ncpu_shr_last_cache; /* fn 4: %eax: ncpus sharing cache */ 158d129bde2Sesaxe id_t cpi_last_lvl_cacheid; /* fn 4: %eax: derived cache id */ 159d129bde2Sesaxe uint_t cpi_std_4_size; /* fn 4: number of fn 4 elements */ 160d129bde2Sesaxe struct cpuid_regs **cpi_std_4; /* fn 4: %ecx == 0 .. fn4_size */ 1618949bcd6Sandrei struct cpuid_regs cpi_std[NMAX_CPI_STD]; /* 0 .. 5 */ 1627c478bd9Sstevel@tonic-gate /* 1637c478bd9Sstevel@tonic-gate * extended function information 1647c478bd9Sstevel@tonic-gate */ 1657c478bd9Sstevel@tonic-gate uint_t cpi_xmaxeax; /* fn 0x80000000: %eax */ 1667c478bd9Sstevel@tonic-gate char cpi_brandstr[49]; /* fn 0x8000000[234] */ 1677c478bd9Sstevel@tonic-gate uint8_t cpi_pabits; /* fn 0x80000006: %eax */ 1687c478bd9Sstevel@tonic-gate uint8_t cpi_vabits; /* fn 0x80000006: %eax */ 1698949bcd6Sandrei struct cpuid_regs cpi_extd[NMAX_CPI_EXTD]; /* 0x8000000[0-8] */ 17010569901Sgavinm id_t cpi_coreid; /* same coreid => strands share core */ 17110569901Sgavinm int cpi_pkgcoreid; /* core number within single package */ 1728949bcd6Sandrei uint_t cpi_ncore_per_chip; /* AMD: fn 0x80000008: %ecx[7-0] */ 1738949bcd6Sandrei /* Intel: fn 4: %eax[31-26] */ 1747c478bd9Sstevel@tonic-gate /* 1757c478bd9Sstevel@tonic-gate * supported feature information 1767c478bd9Sstevel@tonic-gate */ 177ae115bc7Smrj uint32_t cpi_support[5]; 1787c478bd9Sstevel@tonic-gate #define STD_EDX_FEATURES 0 1797c478bd9Sstevel@tonic-gate #define AMD_EDX_FEATURES 1 1807c478bd9Sstevel@tonic-gate #define TM_EDX_FEATURES 2 1817c478bd9Sstevel@tonic-gate #define STD_ECX_FEATURES 3 182ae115bc7Smrj #define AMD_ECX_FEATURES 4 1838a40a695Sgavinm /* 1848a40a695Sgavinm * Synthesized information, where known. 1858a40a695Sgavinm */ 1868a40a695Sgavinm uint32_t cpi_chiprev; /* See X86_CHIPREV_* in x86_archext.h */ 1878a40a695Sgavinm const char *cpi_chiprevstr; /* May be NULL if chiprev unknown */ 1888a40a695Sgavinm uint32_t cpi_socket; /* Chip package/socket type */ 189f98fbcecSbholler 190f98fbcecSbholler struct mwait_info cpi_mwait; /* fn 5: monitor/mwait info */ 191b6917abeSmishra uint32_t cpi_apicid; 1927c478bd9Sstevel@tonic-gate }; 1937c478bd9Sstevel@tonic-gate 1947c478bd9Sstevel@tonic-gate 1957c478bd9Sstevel@tonic-gate static struct cpuid_info cpuid_info0; 1967c478bd9Sstevel@tonic-gate 1977c478bd9Sstevel@tonic-gate /* 1987c478bd9Sstevel@tonic-gate * These bit fields are defined by the Intel Application Note AP-485 1997c478bd9Sstevel@tonic-gate * "Intel Processor Identification and the CPUID Instruction" 2007c478bd9Sstevel@tonic-gate */ 2017c478bd9Sstevel@tonic-gate #define CPI_FAMILY_XTD(cpi) BITX((cpi)->cpi_std[1].cp_eax, 27, 20) 2027c478bd9Sstevel@tonic-gate #define CPI_MODEL_XTD(cpi) BITX((cpi)->cpi_std[1].cp_eax, 19, 16) 2037c478bd9Sstevel@tonic-gate #define CPI_TYPE(cpi) BITX((cpi)->cpi_std[1].cp_eax, 13, 12) 2047c478bd9Sstevel@tonic-gate #define CPI_FAMILY(cpi) BITX((cpi)->cpi_std[1].cp_eax, 11, 8) 2057c478bd9Sstevel@tonic-gate #define CPI_STEP(cpi) BITX((cpi)->cpi_std[1].cp_eax, 3, 0) 2067c478bd9Sstevel@tonic-gate #define CPI_MODEL(cpi) BITX((cpi)->cpi_std[1].cp_eax, 7, 4) 2077c478bd9Sstevel@tonic-gate 2087c478bd9Sstevel@tonic-gate #define CPI_FEATURES_EDX(cpi) ((cpi)->cpi_std[1].cp_edx) 2097c478bd9Sstevel@tonic-gate #define CPI_FEATURES_ECX(cpi) ((cpi)->cpi_std[1].cp_ecx) 2107c478bd9Sstevel@tonic-gate #define CPI_FEATURES_XTD_EDX(cpi) ((cpi)->cpi_extd[1].cp_edx) 2117c478bd9Sstevel@tonic-gate #define CPI_FEATURES_XTD_ECX(cpi) ((cpi)->cpi_extd[1].cp_ecx) 2127c478bd9Sstevel@tonic-gate 2137c478bd9Sstevel@tonic-gate #define CPI_BRANDID(cpi) BITX((cpi)->cpi_std[1].cp_ebx, 7, 0) 2147c478bd9Sstevel@tonic-gate #define CPI_CHUNKS(cpi) BITX((cpi)->cpi_std[1].cp_ebx, 15, 7) 2157c478bd9Sstevel@tonic-gate #define CPI_CPU_COUNT(cpi) BITX((cpi)->cpi_std[1].cp_ebx, 23, 16) 2167c478bd9Sstevel@tonic-gate #define CPI_APIC_ID(cpi) BITX((cpi)->cpi_std[1].cp_ebx, 31, 24) 2177c478bd9Sstevel@tonic-gate 2187c478bd9Sstevel@tonic-gate #define CPI_MAXEAX_MAX 0x100 /* sanity control */ 2197c478bd9Sstevel@tonic-gate #define CPI_XMAXEAX_MAX 0x80000100 220d129bde2Sesaxe #define CPI_FN4_ECX_MAX 0x20 /* sanity: max fn 4 levels */ 221b6917abeSmishra #define CPI_FNB_ECX_MAX 0x20 /* sanity: max fn B levels */ 222d129bde2Sesaxe 223d129bde2Sesaxe /* 224d129bde2Sesaxe * Function 4 (Deterministic Cache Parameters) macros 225d129bde2Sesaxe * Defined by Intel Application Note AP-485 226d129bde2Sesaxe */ 227d129bde2Sesaxe #define CPI_NUM_CORES(regs) BITX((regs)->cp_eax, 31, 26) 228d129bde2Sesaxe #define CPI_NTHR_SHR_CACHE(regs) BITX((regs)->cp_eax, 25, 14) 229d129bde2Sesaxe #define CPI_FULL_ASSOC_CACHE(regs) BITX((regs)->cp_eax, 9, 9) 230d129bde2Sesaxe #define CPI_SELF_INIT_CACHE(regs) BITX((regs)->cp_eax, 8, 8) 231d129bde2Sesaxe #define CPI_CACHE_LVL(regs) BITX((regs)->cp_eax, 7, 5) 232d129bde2Sesaxe #define CPI_CACHE_TYPE(regs) BITX((regs)->cp_eax, 4, 0) 233b6917abeSmishra #define CPI_CPU_LEVEL_TYPE(regs) BITX((regs)->cp_ecx, 15, 8) 234d129bde2Sesaxe 235d129bde2Sesaxe #define CPI_CACHE_WAYS(regs) BITX((regs)->cp_ebx, 31, 22) 236d129bde2Sesaxe #define CPI_CACHE_PARTS(regs) BITX((regs)->cp_ebx, 21, 12) 237d129bde2Sesaxe #define CPI_CACHE_COH_LN_SZ(regs) BITX((regs)->cp_ebx, 11, 0) 238d129bde2Sesaxe 239d129bde2Sesaxe #define CPI_CACHE_SETS(regs) BITX((regs)->cp_ecx, 31, 0) 240d129bde2Sesaxe 241d129bde2Sesaxe #define CPI_PREFCH_STRIDE(regs) BITX((regs)->cp_edx, 9, 0) 242d129bde2Sesaxe 2437c478bd9Sstevel@tonic-gate 2447c478bd9Sstevel@tonic-gate /* 2455ff02082Sdmick * A couple of shorthand macros to identify "later" P6-family chips 2465ff02082Sdmick * like the Pentium M and Core. First, the "older" P6-based stuff 2475ff02082Sdmick * (loosely defined as "pre-Pentium-4"): 2485ff02082Sdmick * P6, PII, Mobile PII, PII Xeon, PIII, Mobile PIII, PIII Xeon 2495ff02082Sdmick */ 2505ff02082Sdmick 2515ff02082Sdmick #define IS_LEGACY_P6(cpi) ( \ 2525ff02082Sdmick cpi->cpi_family == 6 && \ 2535ff02082Sdmick (cpi->cpi_model == 1 || \ 2545ff02082Sdmick cpi->cpi_model == 3 || \ 2555ff02082Sdmick cpi->cpi_model == 5 || \ 2565ff02082Sdmick cpi->cpi_model == 6 || \ 2575ff02082Sdmick cpi->cpi_model == 7 || \ 2585ff02082Sdmick cpi->cpi_model == 8 || \ 2595ff02082Sdmick cpi->cpi_model == 0xA || \ 2605ff02082Sdmick cpi->cpi_model == 0xB) \ 2615ff02082Sdmick ) 2625ff02082Sdmick 2635ff02082Sdmick /* A "new F6" is everything with family 6 that's not the above */ 2645ff02082Sdmick #define IS_NEW_F6(cpi) ((cpi->cpi_family == 6) && !IS_LEGACY_P6(cpi)) 2655ff02082Sdmick 266bf91205bSksadhukh /* Extended family/model support */ 267bf91205bSksadhukh #define IS_EXTENDED_MODEL_INTEL(cpi) (cpi->cpi_family == 0x6 || \ 268bf91205bSksadhukh cpi->cpi_family >= 0xf) 269bf91205bSksadhukh 2705ff02082Sdmick /* 271f98fbcecSbholler * Info for monitor/mwait idle loop. 272f98fbcecSbholler * 273f98fbcecSbholler * See cpuid section of "Intel 64 and IA-32 Architectures Software Developer's 274f98fbcecSbholler * Manual Volume 2A: Instruction Set Reference, A-M" #25366-022US, November 275f98fbcecSbholler * 2006. 276f98fbcecSbholler * See MONITOR/MWAIT section of "AMD64 Architecture Programmer's Manual 277f98fbcecSbholler * Documentation Updates" #33633, Rev 2.05, December 2006. 278f98fbcecSbholler */ 279f98fbcecSbholler #define MWAIT_SUPPORT (0x00000001) /* mwait supported */ 280f98fbcecSbholler #define MWAIT_EXTENSIONS (0x00000002) /* extenstion supported */ 281f98fbcecSbholler #define MWAIT_ECX_INT_ENABLE (0x00000004) /* ecx 1 extension supported */ 282f98fbcecSbholler #define MWAIT_SUPPORTED(cpi) ((cpi)->cpi_std[1].cp_ecx & CPUID_INTC_ECX_MON) 283f98fbcecSbholler #define MWAIT_INT_ENABLE(cpi) ((cpi)->cpi_std[5].cp_ecx & 0x2) 284f98fbcecSbholler #define MWAIT_EXTENSION(cpi) ((cpi)->cpi_std[5].cp_ecx & 0x1) 285f98fbcecSbholler #define MWAIT_SIZE_MIN(cpi) BITX((cpi)->cpi_std[5].cp_eax, 15, 0) 286f98fbcecSbholler #define MWAIT_SIZE_MAX(cpi) BITX((cpi)->cpi_std[5].cp_ebx, 15, 0) 287f98fbcecSbholler /* 288f98fbcecSbholler * Number of sub-cstates for a given c-state. 289f98fbcecSbholler */ 290f98fbcecSbholler #define MWAIT_NUM_SUBC_STATES(cpi, c_state) \ 291f98fbcecSbholler BITX((cpi)->cpi_std[5].cp_edx, c_state + 3, c_state) 292f98fbcecSbholler 2938a40a695Sgavinm /* 294*e4b86885SCheng Sean Ye * Functions we consune from cpuid_subr.c; don't publish these in a header 295*e4b86885SCheng Sean Ye * file to try and keep people using the expected cpuid_* interfaces. 2968a40a695Sgavinm */ 297*e4b86885SCheng Sean Ye extern uint32_t _cpuid_skt(uint_t, uint_t, uint_t, uint_t); 298*e4b86885SCheng Sean Ye extern uint32_t _cpuid_chiprev(uint_t, uint_t, uint_t, uint_t); 299*e4b86885SCheng Sean Ye extern const char *_cpuid_chiprevstr(uint_t, uint_t, uint_t, uint_t); 300*e4b86885SCheng Sean Ye extern uint_t _cpuid_vendorstr_to_vendorcode(char *); 3018a40a695Sgavinm 3028a40a695Sgavinm /* 303ae115bc7Smrj * Apply up various platform-dependent restrictions where the 304ae115bc7Smrj * underlying platform restrictions mean the CPU can be marked 305ae115bc7Smrj * as less capable than its cpuid instruction would imply. 306ae115bc7Smrj */ 307843e1988Sjohnlev #if defined(__xpv) 308843e1988Sjohnlev static void 309843e1988Sjohnlev platform_cpuid_mangle(uint_t vendor, uint32_t eax, struct cpuid_regs *cp) 310843e1988Sjohnlev { 311843e1988Sjohnlev switch (eax) { 312*e4b86885SCheng Sean Ye case 1: { 313*e4b86885SCheng Sean Ye uint32_t mcamask = DOMAIN_IS_INITDOMAIN(xen_info) ? 314*e4b86885SCheng Sean Ye 0 : CPUID_INTC_EDX_MCA; 315843e1988Sjohnlev cp->cp_edx &= 316*e4b86885SCheng Sean Ye ~(mcamask | 317*e4b86885SCheng Sean Ye CPUID_INTC_EDX_PSE | 318843e1988Sjohnlev CPUID_INTC_EDX_VME | CPUID_INTC_EDX_DE | 319843e1988Sjohnlev CPUID_INTC_EDX_SEP | CPUID_INTC_EDX_MTRR | 320843e1988Sjohnlev CPUID_INTC_EDX_PGE | CPUID_INTC_EDX_PAT | 321843e1988Sjohnlev CPUID_AMD_EDX_SYSC | CPUID_INTC_EDX_SEP | 322843e1988Sjohnlev CPUID_INTC_EDX_PSE36 | CPUID_INTC_EDX_HTT); 323843e1988Sjohnlev break; 324*e4b86885SCheng Sean Ye } 325ae115bc7Smrj 326843e1988Sjohnlev case 0x80000001: 327843e1988Sjohnlev cp->cp_edx &= 328843e1988Sjohnlev ~(CPUID_AMD_EDX_PSE | 329843e1988Sjohnlev CPUID_INTC_EDX_VME | CPUID_INTC_EDX_DE | 330843e1988Sjohnlev CPUID_AMD_EDX_MTRR | CPUID_AMD_EDX_PGE | 331843e1988Sjohnlev CPUID_AMD_EDX_PAT | CPUID_AMD_EDX_PSE36 | 332843e1988Sjohnlev CPUID_AMD_EDX_SYSC | CPUID_INTC_EDX_SEP | 333843e1988Sjohnlev CPUID_AMD_EDX_TSCP); 334843e1988Sjohnlev cp->cp_ecx &= ~CPUID_AMD_ECX_CMP_LGCY; 335843e1988Sjohnlev break; 336843e1988Sjohnlev default: 337843e1988Sjohnlev break; 338843e1988Sjohnlev } 339843e1988Sjohnlev 340843e1988Sjohnlev switch (vendor) { 341843e1988Sjohnlev case X86_VENDOR_Intel: 342843e1988Sjohnlev switch (eax) { 343843e1988Sjohnlev case 4: 344843e1988Sjohnlev /* 345843e1988Sjohnlev * Zero out the (ncores-per-chip - 1) field 346843e1988Sjohnlev */ 347843e1988Sjohnlev cp->cp_eax &= 0x03fffffff; 348843e1988Sjohnlev break; 349843e1988Sjohnlev default: 350843e1988Sjohnlev break; 351843e1988Sjohnlev } 352843e1988Sjohnlev break; 353843e1988Sjohnlev case X86_VENDOR_AMD: 354843e1988Sjohnlev switch (eax) { 355843e1988Sjohnlev case 0x80000008: 356843e1988Sjohnlev /* 357843e1988Sjohnlev * Zero out the (ncores-per-chip - 1) field 358843e1988Sjohnlev */ 359843e1988Sjohnlev cp->cp_ecx &= 0xffffff00; 360843e1988Sjohnlev break; 361843e1988Sjohnlev default: 362843e1988Sjohnlev break; 363843e1988Sjohnlev } 364843e1988Sjohnlev break; 365843e1988Sjohnlev default: 366843e1988Sjohnlev break; 367843e1988Sjohnlev } 368843e1988Sjohnlev } 369843e1988Sjohnlev #else 370ae115bc7Smrj #define platform_cpuid_mangle(vendor, eax, cp) /* nothing */ 371843e1988Sjohnlev #endif 372ae115bc7Smrj 373ae115bc7Smrj /* 3747c478bd9Sstevel@tonic-gate * Some undocumented ways of patching the results of the cpuid 3757c478bd9Sstevel@tonic-gate * instruction to permit running Solaris 10 on future cpus that 3767c478bd9Sstevel@tonic-gate * we don't currently support. Could be set to non-zero values 3777c478bd9Sstevel@tonic-gate * via settings in eeprom. 3787c478bd9Sstevel@tonic-gate */ 3797c478bd9Sstevel@tonic-gate 3807c478bd9Sstevel@tonic-gate uint32_t cpuid_feature_ecx_include; 3817c478bd9Sstevel@tonic-gate uint32_t cpuid_feature_ecx_exclude; 3827c478bd9Sstevel@tonic-gate uint32_t cpuid_feature_edx_include; 3837c478bd9Sstevel@tonic-gate uint32_t cpuid_feature_edx_exclude; 3847c478bd9Sstevel@tonic-gate 385ae115bc7Smrj void 386ae115bc7Smrj cpuid_alloc_space(cpu_t *cpu) 387ae115bc7Smrj { 388ae115bc7Smrj /* 389ae115bc7Smrj * By convention, cpu0 is the boot cpu, which is set up 390ae115bc7Smrj * before memory allocation is available. All other cpus get 391ae115bc7Smrj * their cpuid_info struct allocated here. 392ae115bc7Smrj */ 393ae115bc7Smrj ASSERT(cpu->cpu_id != 0); 394ae115bc7Smrj cpu->cpu_m.mcpu_cpi = 395ae115bc7Smrj kmem_zalloc(sizeof (*cpu->cpu_m.mcpu_cpi), KM_SLEEP); 396ae115bc7Smrj } 397ae115bc7Smrj 398ae115bc7Smrj void 399ae115bc7Smrj cpuid_free_space(cpu_t *cpu) 400ae115bc7Smrj { 401d129bde2Sesaxe struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 402d129bde2Sesaxe int i; 403d129bde2Sesaxe 404ae115bc7Smrj ASSERT(cpu->cpu_id != 0); 405d129bde2Sesaxe 406d129bde2Sesaxe /* 407d129bde2Sesaxe * Free up any function 4 related dynamic storage 408d129bde2Sesaxe */ 409d129bde2Sesaxe for (i = 1; i < cpi->cpi_std_4_size; i++) 410d129bde2Sesaxe kmem_free(cpi->cpi_std_4[i], sizeof (struct cpuid_regs)); 411d129bde2Sesaxe if (cpi->cpi_std_4_size > 0) 412d129bde2Sesaxe kmem_free(cpi->cpi_std_4, 413d129bde2Sesaxe cpi->cpi_std_4_size * sizeof (struct cpuid_regs *)); 414d129bde2Sesaxe 415ae115bc7Smrj kmem_free(cpu->cpu_m.mcpu_cpi, sizeof (*cpu->cpu_m.mcpu_cpi)); 416ae115bc7Smrj } 417ae115bc7Smrj 418551bc2a6Smrj #if !defined(__xpv) 419551bc2a6Smrj 420551bc2a6Smrj static void 421551bc2a6Smrj check_for_hvm() 422551bc2a6Smrj { 423551bc2a6Smrj struct cpuid_regs cp; 424551bc2a6Smrj char *xen_str; 425551bc2a6Smrj uint32_t xen_signature[4]; 426551bc2a6Smrj extern int xpv_is_hvm; 427551bc2a6Smrj 428551bc2a6Smrj /* 429551bc2a6Smrj * In a fully virtualized domain, Xen's pseudo-cpuid function 430551bc2a6Smrj * 0x40000000 returns a string representing the Xen signature in 431551bc2a6Smrj * %ebx, %ecx, and %edx. %eax contains the maximum supported cpuid 432551bc2a6Smrj * function. 433551bc2a6Smrj */ 434551bc2a6Smrj cp.cp_eax = 0x40000000; 435551bc2a6Smrj (void) __cpuid_insn(&cp); 436551bc2a6Smrj xen_signature[0] = cp.cp_ebx; 437551bc2a6Smrj xen_signature[1] = cp.cp_ecx; 438551bc2a6Smrj xen_signature[2] = cp.cp_edx; 439551bc2a6Smrj xen_signature[3] = 0; 440551bc2a6Smrj xen_str = (char *)xen_signature; 441551bc2a6Smrj if (strcmp("XenVMMXenVMM", xen_str) == 0 && cp.cp_eax <= 0x40000002) 442551bc2a6Smrj xpv_is_hvm = 1; 443551bc2a6Smrj } 444551bc2a6Smrj #endif /* __xpv */ 445551bc2a6Smrj 4467c478bd9Sstevel@tonic-gate uint_t 4477c478bd9Sstevel@tonic-gate cpuid_pass1(cpu_t *cpu) 4487c478bd9Sstevel@tonic-gate { 4497c478bd9Sstevel@tonic-gate uint32_t mask_ecx, mask_edx; 4507c478bd9Sstevel@tonic-gate uint_t feature = X86_CPUID; 4517c478bd9Sstevel@tonic-gate struct cpuid_info *cpi; 4528949bcd6Sandrei struct cpuid_regs *cp; 4537c478bd9Sstevel@tonic-gate int xcpuid; 454843e1988Sjohnlev #if !defined(__xpv) 4555b8a6efeSbholler extern int idle_cpu_prefer_mwait; 456843e1988Sjohnlev #endif 457ae115bc7Smrj 4587c478bd9Sstevel@tonic-gate /* 459ae115bc7Smrj * Space statically allocated for cpu0, ensure pointer is set 4607c478bd9Sstevel@tonic-gate */ 4617c478bd9Sstevel@tonic-gate if (cpu->cpu_id == 0) 462ae115bc7Smrj cpu->cpu_m.mcpu_cpi = &cpuid_info0; 463ae115bc7Smrj cpi = cpu->cpu_m.mcpu_cpi; 464ae115bc7Smrj ASSERT(cpi != NULL); 4657c478bd9Sstevel@tonic-gate cp = &cpi->cpi_std[0]; 4668949bcd6Sandrei cp->cp_eax = 0; 4678949bcd6Sandrei cpi->cpi_maxeax = __cpuid_insn(cp); 4687c478bd9Sstevel@tonic-gate { 4697c478bd9Sstevel@tonic-gate uint32_t *iptr = (uint32_t *)cpi->cpi_vendorstr; 4707c478bd9Sstevel@tonic-gate *iptr++ = cp->cp_ebx; 4717c478bd9Sstevel@tonic-gate *iptr++ = cp->cp_edx; 4727c478bd9Sstevel@tonic-gate *iptr++ = cp->cp_ecx; 4737c478bd9Sstevel@tonic-gate *(char *)&cpi->cpi_vendorstr[12] = '\0'; 4747c478bd9Sstevel@tonic-gate } 4757c478bd9Sstevel@tonic-gate 476*e4b86885SCheng Sean Ye cpi->cpi_vendor = _cpuid_vendorstr_to_vendorcode(cpi->cpi_vendorstr); 4777c478bd9Sstevel@tonic-gate x86_vendor = cpi->cpi_vendor; /* for compatibility */ 4787c478bd9Sstevel@tonic-gate 4797c478bd9Sstevel@tonic-gate /* 4807c478bd9Sstevel@tonic-gate * Limit the range in case of weird hardware 4817c478bd9Sstevel@tonic-gate */ 4827c478bd9Sstevel@tonic-gate if (cpi->cpi_maxeax > CPI_MAXEAX_MAX) 4837c478bd9Sstevel@tonic-gate cpi->cpi_maxeax = CPI_MAXEAX_MAX; 4847c478bd9Sstevel@tonic-gate if (cpi->cpi_maxeax < 1) 4857c478bd9Sstevel@tonic-gate goto pass1_done; 4867c478bd9Sstevel@tonic-gate 4877c478bd9Sstevel@tonic-gate cp = &cpi->cpi_std[1]; 4888949bcd6Sandrei cp->cp_eax = 1; 4898949bcd6Sandrei (void) __cpuid_insn(cp); 4907c478bd9Sstevel@tonic-gate 4917c478bd9Sstevel@tonic-gate /* 4927c478bd9Sstevel@tonic-gate * Extract identifying constants for easy access. 4937c478bd9Sstevel@tonic-gate */ 4947c478bd9Sstevel@tonic-gate cpi->cpi_model = CPI_MODEL(cpi); 4957c478bd9Sstevel@tonic-gate cpi->cpi_family = CPI_FAMILY(cpi); 4967c478bd9Sstevel@tonic-gate 4975ff02082Sdmick if (cpi->cpi_family == 0xf) 4987c478bd9Sstevel@tonic-gate cpi->cpi_family += CPI_FAMILY_XTD(cpi); 4995ff02082Sdmick 50068c91426Sdmick /* 501875b116eSkchow * Beware: AMD uses "extended model" iff base *FAMILY* == 0xf. 50268c91426Sdmick * Intel, and presumably everyone else, uses model == 0xf, as 50368c91426Sdmick * one would expect (max value means possible overflow). Sigh. 50468c91426Sdmick */ 50568c91426Sdmick 50668c91426Sdmick switch (cpi->cpi_vendor) { 507bf91205bSksadhukh case X86_VENDOR_Intel: 508bf91205bSksadhukh if (IS_EXTENDED_MODEL_INTEL(cpi)) 509bf91205bSksadhukh cpi->cpi_model += CPI_MODEL_XTD(cpi) << 4; 510447af253Sksadhukh break; 51168c91426Sdmick case X86_VENDOR_AMD: 512875b116eSkchow if (CPI_FAMILY(cpi) == 0xf) 51368c91426Sdmick cpi->cpi_model += CPI_MODEL_XTD(cpi) << 4; 51468c91426Sdmick break; 51568c91426Sdmick default: 5165ff02082Sdmick if (cpi->cpi_model == 0xf) 5177c478bd9Sstevel@tonic-gate cpi->cpi_model += CPI_MODEL_XTD(cpi) << 4; 51868c91426Sdmick break; 51968c91426Sdmick } 5207c478bd9Sstevel@tonic-gate 5217c478bd9Sstevel@tonic-gate cpi->cpi_step = CPI_STEP(cpi); 5227c478bd9Sstevel@tonic-gate cpi->cpi_brandid = CPI_BRANDID(cpi); 5237c478bd9Sstevel@tonic-gate 5247c478bd9Sstevel@tonic-gate /* 5257c478bd9Sstevel@tonic-gate * *default* assumptions: 5267c478bd9Sstevel@tonic-gate * - believe %edx feature word 5277c478bd9Sstevel@tonic-gate * - ignore %ecx feature word 5287c478bd9Sstevel@tonic-gate * - 32-bit virtual and physical addressing 5297c478bd9Sstevel@tonic-gate */ 5307c478bd9Sstevel@tonic-gate mask_edx = 0xffffffff; 5317c478bd9Sstevel@tonic-gate mask_ecx = 0; 5327c478bd9Sstevel@tonic-gate 5337c478bd9Sstevel@tonic-gate cpi->cpi_pabits = cpi->cpi_vabits = 32; 5347c478bd9Sstevel@tonic-gate 5357c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 5367c478bd9Sstevel@tonic-gate case X86_VENDOR_Intel: 5377c478bd9Sstevel@tonic-gate if (cpi->cpi_family == 5) 5387c478bd9Sstevel@tonic-gate x86_type = X86_TYPE_P5; 5395ff02082Sdmick else if (IS_LEGACY_P6(cpi)) { 5407c478bd9Sstevel@tonic-gate x86_type = X86_TYPE_P6; 5417c478bd9Sstevel@tonic-gate pentiumpro_bug4046376 = 1; 5427c478bd9Sstevel@tonic-gate pentiumpro_bug4064495 = 1; 5437c478bd9Sstevel@tonic-gate /* 5447c478bd9Sstevel@tonic-gate * Clear the SEP bit when it was set erroneously 5457c478bd9Sstevel@tonic-gate */ 5467c478bd9Sstevel@tonic-gate if (cpi->cpi_model < 3 && cpi->cpi_step < 3) 5477c478bd9Sstevel@tonic-gate cp->cp_edx &= ~CPUID_INTC_EDX_SEP; 5485ff02082Sdmick } else if (IS_NEW_F6(cpi) || cpi->cpi_family == 0xf) { 5497c478bd9Sstevel@tonic-gate x86_type = X86_TYPE_P4; 5507c478bd9Sstevel@tonic-gate /* 5517c478bd9Sstevel@tonic-gate * We don't currently depend on any of the %ecx 5527c478bd9Sstevel@tonic-gate * features until Prescott, so we'll only check 5537c478bd9Sstevel@tonic-gate * this from P4 onwards. We might want to revisit 5547c478bd9Sstevel@tonic-gate * that idea later. 5557c478bd9Sstevel@tonic-gate */ 5567c478bd9Sstevel@tonic-gate mask_ecx = 0xffffffff; 5577c478bd9Sstevel@tonic-gate } else if (cpi->cpi_family > 0xf) 5587c478bd9Sstevel@tonic-gate mask_ecx = 0xffffffff; 5597c622d23Sbholler /* 5607c622d23Sbholler * We don't support MONITOR/MWAIT if leaf 5 is not available 5617c622d23Sbholler * to obtain the monitor linesize. 5627c622d23Sbholler */ 5637c622d23Sbholler if (cpi->cpi_maxeax < 5) 5647c622d23Sbholler mask_ecx &= ~CPUID_INTC_ECX_MON; 5657c478bd9Sstevel@tonic-gate break; 5667c478bd9Sstevel@tonic-gate case X86_VENDOR_IntelClone: 5677c478bd9Sstevel@tonic-gate default: 5687c478bd9Sstevel@tonic-gate break; 5697c478bd9Sstevel@tonic-gate case X86_VENDOR_AMD: 5707c478bd9Sstevel@tonic-gate #if defined(OPTERON_ERRATUM_108) 5717c478bd9Sstevel@tonic-gate if (cpi->cpi_family == 0xf && cpi->cpi_model == 0xe) { 5727c478bd9Sstevel@tonic-gate cp->cp_eax = (0xf0f & cp->cp_eax) | 0xc0; 5737c478bd9Sstevel@tonic-gate cpi->cpi_model = 0xc; 5747c478bd9Sstevel@tonic-gate } else 5757c478bd9Sstevel@tonic-gate #endif 5767c478bd9Sstevel@tonic-gate if (cpi->cpi_family == 5) { 5777c478bd9Sstevel@tonic-gate /* 5787c478bd9Sstevel@tonic-gate * AMD K5 and K6 5797c478bd9Sstevel@tonic-gate * 5807c478bd9Sstevel@tonic-gate * These CPUs have an incomplete implementation 5817c478bd9Sstevel@tonic-gate * of MCA/MCE which we mask away. 5827c478bd9Sstevel@tonic-gate */ 5838949bcd6Sandrei mask_edx &= ~(CPUID_INTC_EDX_MCE | CPUID_INTC_EDX_MCA); 5848949bcd6Sandrei 5857c478bd9Sstevel@tonic-gate /* 5867c478bd9Sstevel@tonic-gate * Model 0 uses the wrong (APIC) bit 5877c478bd9Sstevel@tonic-gate * to indicate PGE. Fix it here. 5887c478bd9Sstevel@tonic-gate */ 5898949bcd6Sandrei if (cpi->cpi_model == 0) { 5907c478bd9Sstevel@tonic-gate if (cp->cp_edx & 0x200) { 5917c478bd9Sstevel@tonic-gate cp->cp_edx &= ~0x200; 5927c478bd9Sstevel@tonic-gate cp->cp_edx |= CPUID_INTC_EDX_PGE; 5937c478bd9Sstevel@tonic-gate } 5947c478bd9Sstevel@tonic-gate } 5958949bcd6Sandrei 5968949bcd6Sandrei /* 5978949bcd6Sandrei * Early models had problems w/ MMX; disable. 5988949bcd6Sandrei */ 5998949bcd6Sandrei if (cpi->cpi_model < 6) 6008949bcd6Sandrei mask_edx &= ~CPUID_INTC_EDX_MMX; 6018949bcd6Sandrei } 6028949bcd6Sandrei 6038949bcd6Sandrei /* 6048949bcd6Sandrei * For newer families, SSE3 and CX16, at least, are valid; 6058949bcd6Sandrei * enable all 6068949bcd6Sandrei */ 6078949bcd6Sandrei if (cpi->cpi_family >= 0xf) 6088949bcd6Sandrei mask_ecx = 0xffffffff; 6097c622d23Sbholler /* 6107c622d23Sbholler * We don't support MONITOR/MWAIT if leaf 5 is not available 6117c622d23Sbholler * to obtain the monitor linesize. 6127c622d23Sbholler */ 6137c622d23Sbholler if (cpi->cpi_maxeax < 5) 6147c622d23Sbholler mask_ecx &= ~CPUID_INTC_ECX_MON; 6155b8a6efeSbholler 616843e1988Sjohnlev #if !defined(__xpv) 6175b8a6efeSbholler /* 6185b8a6efeSbholler * Do not use MONITOR/MWAIT to halt in the idle loop on any AMD 6195b8a6efeSbholler * processors. AMD does not intend MWAIT to be used in the cpu 6205b8a6efeSbholler * idle loop on current and future processors. 10h and future 6215b8a6efeSbholler * AMD processors use more power in MWAIT than HLT. 6225b8a6efeSbholler * Pre-family-10h Opterons do not have the MWAIT instruction. 6235b8a6efeSbholler */ 6245b8a6efeSbholler idle_cpu_prefer_mwait = 0; 625843e1988Sjohnlev #endif 6265b8a6efeSbholler 6277c478bd9Sstevel@tonic-gate break; 6287c478bd9Sstevel@tonic-gate case X86_VENDOR_TM: 6297c478bd9Sstevel@tonic-gate /* 6307c478bd9Sstevel@tonic-gate * workaround the NT workaround in CMS 4.1 6317c478bd9Sstevel@tonic-gate */ 6327c478bd9Sstevel@tonic-gate if (cpi->cpi_family == 5 && cpi->cpi_model == 4 && 6337c478bd9Sstevel@tonic-gate (cpi->cpi_step == 2 || cpi->cpi_step == 3)) 6347c478bd9Sstevel@tonic-gate cp->cp_edx |= CPUID_INTC_EDX_CX8; 6357c478bd9Sstevel@tonic-gate break; 6367c478bd9Sstevel@tonic-gate case X86_VENDOR_Centaur: 6377c478bd9Sstevel@tonic-gate /* 6387c478bd9Sstevel@tonic-gate * workaround the NT workarounds again 6397c478bd9Sstevel@tonic-gate */ 6407c478bd9Sstevel@tonic-gate if (cpi->cpi_family == 6) 6417c478bd9Sstevel@tonic-gate cp->cp_edx |= CPUID_INTC_EDX_CX8; 6427c478bd9Sstevel@tonic-gate break; 6437c478bd9Sstevel@tonic-gate case X86_VENDOR_Cyrix: 6447c478bd9Sstevel@tonic-gate /* 6457c478bd9Sstevel@tonic-gate * We rely heavily on the probing in locore 6467c478bd9Sstevel@tonic-gate * to actually figure out what parts, if any, 6477c478bd9Sstevel@tonic-gate * of the Cyrix cpuid instruction to believe. 6487c478bd9Sstevel@tonic-gate */ 6497c478bd9Sstevel@tonic-gate switch (x86_type) { 6507c478bd9Sstevel@tonic-gate case X86_TYPE_CYRIX_486: 6517c478bd9Sstevel@tonic-gate mask_edx = 0; 6527c478bd9Sstevel@tonic-gate break; 6537c478bd9Sstevel@tonic-gate case X86_TYPE_CYRIX_6x86: 6547c478bd9Sstevel@tonic-gate mask_edx = 0; 6557c478bd9Sstevel@tonic-gate break; 6567c478bd9Sstevel@tonic-gate case X86_TYPE_CYRIX_6x86L: 6577c478bd9Sstevel@tonic-gate mask_edx = 6587c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_DE | 6597c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_CX8; 6607c478bd9Sstevel@tonic-gate break; 6617c478bd9Sstevel@tonic-gate case X86_TYPE_CYRIX_6x86MX: 6627c478bd9Sstevel@tonic-gate mask_edx = 6637c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_DE | 6647c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_MSR | 6657c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_CX8 | 6667c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_PGE | 6677c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_CMOV | 6687c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_MMX; 6697c478bd9Sstevel@tonic-gate break; 6707c478bd9Sstevel@tonic-gate case X86_TYPE_CYRIX_GXm: 6717c478bd9Sstevel@tonic-gate mask_edx = 6727c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_MSR | 6737c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_CX8 | 6747c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_CMOV | 6757c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_MMX; 6767c478bd9Sstevel@tonic-gate break; 6777c478bd9Sstevel@tonic-gate case X86_TYPE_CYRIX_MediaGX: 6787c478bd9Sstevel@tonic-gate break; 6797c478bd9Sstevel@tonic-gate case X86_TYPE_CYRIX_MII: 6807c478bd9Sstevel@tonic-gate case X86_TYPE_VIA_CYRIX_III: 6817c478bd9Sstevel@tonic-gate mask_edx = 6827c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_DE | 6837c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_TSC | 6847c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_MSR | 6857c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_CX8 | 6867c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_PGE | 6877c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_CMOV | 6887c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_MMX; 6897c478bd9Sstevel@tonic-gate break; 6907c478bd9Sstevel@tonic-gate default: 6917c478bd9Sstevel@tonic-gate break; 6927c478bd9Sstevel@tonic-gate } 6937c478bd9Sstevel@tonic-gate break; 6947c478bd9Sstevel@tonic-gate } 6957c478bd9Sstevel@tonic-gate 696843e1988Sjohnlev #if defined(__xpv) 697843e1988Sjohnlev /* 698843e1988Sjohnlev * Do not support MONITOR/MWAIT under a hypervisor 699843e1988Sjohnlev */ 700843e1988Sjohnlev mask_ecx &= ~CPUID_INTC_ECX_MON; 701843e1988Sjohnlev #endif /* __xpv */ 702843e1988Sjohnlev 7037c478bd9Sstevel@tonic-gate /* 7047c478bd9Sstevel@tonic-gate * Now we've figured out the masks that determine 7057c478bd9Sstevel@tonic-gate * which bits we choose to believe, apply the masks 7067c478bd9Sstevel@tonic-gate * to the feature words, then map the kernel's view 7077c478bd9Sstevel@tonic-gate * of these feature words into its feature word. 7087c478bd9Sstevel@tonic-gate */ 7097c478bd9Sstevel@tonic-gate cp->cp_edx &= mask_edx; 7107c478bd9Sstevel@tonic-gate cp->cp_ecx &= mask_ecx; 7117c478bd9Sstevel@tonic-gate 7127c478bd9Sstevel@tonic-gate /* 713ae115bc7Smrj * apply any platform restrictions (we don't call this 714ae115bc7Smrj * immediately after __cpuid_insn here, because we need the 715ae115bc7Smrj * workarounds applied above first) 7167c478bd9Sstevel@tonic-gate */ 717ae115bc7Smrj platform_cpuid_mangle(cpi->cpi_vendor, 1, cp); 7187c478bd9Sstevel@tonic-gate 719ae115bc7Smrj /* 720ae115bc7Smrj * fold in overrides from the "eeprom" mechanism 721ae115bc7Smrj */ 7227c478bd9Sstevel@tonic-gate cp->cp_edx |= cpuid_feature_edx_include; 7237c478bd9Sstevel@tonic-gate cp->cp_edx &= ~cpuid_feature_edx_exclude; 7247c478bd9Sstevel@tonic-gate 7257c478bd9Sstevel@tonic-gate cp->cp_ecx |= cpuid_feature_ecx_include; 7267c478bd9Sstevel@tonic-gate cp->cp_ecx &= ~cpuid_feature_ecx_exclude; 7277c478bd9Sstevel@tonic-gate 7287c478bd9Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_PSE) 7297c478bd9Sstevel@tonic-gate feature |= X86_LARGEPAGE; 7307c478bd9Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_TSC) 7317c478bd9Sstevel@tonic-gate feature |= X86_TSC; 7327c478bd9Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_MSR) 7337c478bd9Sstevel@tonic-gate feature |= X86_MSR; 7347c478bd9Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_MTRR) 7357c478bd9Sstevel@tonic-gate feature |= X86_MTRR; 7367c478bd9Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_PGE) 7377c478bd9Sstevel@tonic-gate feature |= X86_PGE; 7387c478bd9Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_CMOV) 7397c478bd9Sstevel@tonic-gate feature |= X86_CMOV; 7407c478bd9Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_MMX) 7417c478bd9Sstevel@tonic-gate feature |= X86_MMX; 7427c478bd9Sstevel@tonic-gate if ((cp->cp_edx & CPUID_INTC_EDX_MCE) != 0 && 7437c478bd9Sstevel@tonic-gate (cp->cp_edx & CPUID_INTC_EDX_MCA) != 0) 7447c478bd9Sstevel@tonic-gate feature |= X86_MCA; 7457c478bd9Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_PAE) 7467c478bd9Sstevel@tonic-gate feature |= X86_PAE; 7477c478bd9Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_CX8) 7487c478bd9Sstevel@tonic-gate feature |= X86_CX8; 7497c478bd9Sstevel@tonic-gate if (cp->cp_ecx & CPUID_INTC_ECX_CX16) 7507c478bd9Sstevel@tonic-gate feature |= X86_CX16; 7517c478bd9Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_PAT) 7527c478bd9Sstevel@tonic-gate feature |= X86_PAT; 7537c478bd9Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_SEP) 7547c478bd9Sstevel@tonic-gate feature |= X86_SEP; 7557c478bd9Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_FXSR) { 7567c478bd9Sstevel@tonic-gate /* 7577c478bd9Sstevel@tonic-gate * In our implementation, fxsave/fxrstor 7587c478bd9Sstevel@tonic-gate * are prerequisites before we'll even 7597c478bd9Sstevel@tonic-gate * try and do SSE things. 7607c478bd9Sstevel@tonic-gate */ 7617c478bd9Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_SSE) 7627c478bd9Sstevel@tonic-gate feature |= X86_SSE; 7637c478bd9Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_SSE2) 7647c478bd9Sstevel@tonic-gate feature |= X86_SSE2; 7657c478bd9Sstevel@tonic-gate if (cp->cp_ecx & CPUID_INTC_ECX_SSE3) 7667c478bd9Sstevel@tonic-gate feature |= X86_SSE3; 767d0f8ff6eSkk208521 if (cpi->cpi_vendor == X86_VENDOR_Intel) { 768d0f8ff6eSkk208521 if (cp->cp_ecx & CPUID_INTC_ECX_SSSE3) 769d0f8ff6eSkk208521 feature |= X86_SSSE3; 770d0f8ff6eSkk208521 if (cp->cp_ecx & CPUID_INTC_ECX_SSE4_1) 771d0f8ff6eSkk208521 feature |= X86_SSE4_1; 772d0f8ff6eSkk208521 if (cp->cp_ecx & CPUID_INTC_ECX_SSE4_2) 773d0f8ff6eSkk208521 feature |= X86_SSE4_2; 774d0f8ff6eSkk208521 } 7757c478bd9Sstevel@tonic-gate } 7767c478bd9Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_DE) 777ae115bc7Smrj feature |= X86_DE; 778f98fbcecSbholler if (cp->cp_ecx & CPUID_INTC_ECX_MON) { 779f98fbcecSbholler cpi->cpi_mwait.support |= MWAIT_SUPPORT; 780f98fbcecSbholler feature |= X86_MWAIT; 781f98fbcecSbholler } 7827c478bd9Sstevel@tonic-gate 7837c478bd9Sstevel@tonic-gate if (feature & X86_PAE) 7847c478bd9Sstevel@tonic-gate cpi->cpi_pabits = 36; 7857c478bd9Sstevel@tonic-gate 7867c478bd9Sstevel@tonic-gate /* 7877c478bd9Sstevel@tonic-gate * Hyperthreading configuration is slightly tricky on Intel 7887c478bd9Sstevel@tonic-gate * and pure clones, and even trickier on AMD. 7897c478bd9Sstevel@tonic-gate * 7907c478bd9Sstevel@tonic-gate * (AMD chose to set the HTT bit on their CMP processors, 7917c478bd9Sstevel@tonic-gate * even though they're not actually hyperthreaded. Thus it 7927c478bd9Sstevel@tonic-gate * takes a bit more work to figure out what's really going 793ae115bc7Smrj * on ... see the handling of the CMP_LGCY bit below) 7947c478bd9Sstevel@tonic-gate */ 7957c478bd9Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_HTT) { 7967c478bd9Sstevel@tonic-gate cpi->cpi_ncpu_per_chip = CPI_CPU_COUNT(cpi); 7977c478bd9Sstevel@tonic-gate if (cpi->cpi_ncpu_per_chip > 1) 7987c478bd9Sstevel@tonic-gate feature |= X86_HTT; 7998949bcd6Sandrei } else { 8008949bcd6Sandrei cpi->cpi_ncpu_per_chip = 1; 8017c478bd9Sstevel@tonic-gate } 8027c478bd9Sstevel@tonic-gate 8037c478bd9Sstevel@tonic-gate /* 8047c478bd9Sstevel@tonic-gate * Work on the "extended" feature information, doing 8057c478bd9Sstevel@tonic-gate * some basic initialization for cpuid_pass2() 8067c478bd9Sstevel@tonic-gate */ 8077c478bd9Sstevel@tonic-gate xcpuid = 0; 8087c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 8097c478bd9Sstevel@tonic-gate case X86_VENDOR_Intel: 8105ff02082Sdmick if (IS_NEW_F6(cpi) || cpi->cpi_family >= 0xf) 8117c478bd9Sstevel@tonic-gate xcpuid++; 8127c478bd9Sstevel@tonic-gate break; 8137c478bd9Sstevel@tonic-gate case X86_VENDOR_AMD: 8147c478bd9Sstevel@tonic-gate if (cpi->cpi_family > 5 || 8157c478bd9Sstevel@tonic-gate (cpi->cpi_family == 5 && cpi->cpi_model >= 1)) 8167c478bd9Sstevel@tonic-gate xcpuid++; 8177c478bd9Sstevel@tonic-gate break; 8187c478bd9Sstevel@tonic-gate case X86_VENDOR_Cyrix: 8197c478bd9Sstevel@tonic-gate /* 8207c478bd9Sstevel@tonic-gate * Only these Cyrix CPUs are -known- to support 8217c478bd9Sstevel@tonic-gate * extended cpuid operations. 8227c478bd9Sstevel@tonic-gate */ 8237c478bd9Sstevel@tonic-gate if (x86_type == X86_TYPE_VIA_CYRIX_III || 8247c478bd9Sstevel@tonic-gate x86_type == X86_TYPE_CYRIX_GXm) 8257c478bd9Sstevel@tonic-gate xcpuid++; 8267c478bd9Sstevel@tonic-gate break; 8277c478bd9Sstevel@tonic-gate case X86_VENDOR_Centaur: 8287c478bd9Sstevel@tonic-gate case X86_VENDOR_TM: 8297c478bd9Sstevel@tonic-gate default: 8307c478bd9Sstevel@tonic-gate xcpuid++; 8317c478bd9Sstevel@tonic-gate break; 8327c478bd9Sstevel@tonic-gate } 8337c478bd9Sstevel@tonic-gate 8347c478bd9Sstevel@tonic-gate if (xcpuid) { 8357c478bd9Sstevel@tonic-gate cp = &cpi->cpi_extd[0]; 8368949bcd6Sandrei cp->cp_eax = 0x80000000; 8378949bcd6Sandrei cpi->cpi_xmaxeax = __cpuid_insn(cp); 8387c478bd9Sstevel@tonic-gate } 8397c478bd9Sstevel@tonic-gate 8407c478bd9Sstevel@tonic-gate if (cpi->cpi_xmaxeax & 0x80000000) { 8417c478bd9Sstevel@tonic-gate 8427c478bd9Sstevel@tonic-gate if (cpi->cpi_xmaxeax > CPI_XMAXEAX_MAX) 8437c478bd9Sstevel@tonic-gate cpi->cpi_xmaxeax = CPI_XMAXEAX_MAX; 8447c478bd9Sstevel@tonic-gate 8457c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 8467c478bd9Sstevel@tonic-gate case X86_VENDOR_Intel: 8477c478bd9Sstevel@tonic-gate case X86_VENDOR_AMD: 8487c478bd9Sstevel@tonic-gate if (cpi->cpi_xmaxeax < 0x80000001) 8497c478bd9Sstevel@tonic-gate break; 8507c478bd9Sstevel@tonic-gate cp = &cpi->cpi_extd[1]; 8518949bcd6Sandrei cp->cp_eax = 0x80000001; 8528949bcd6Sandrei (void) __cpuid_insn(cp); 853ae115bc7Smrj 8547c478bd9Sstevel@tonic-gate if (cpi->cpi_vendor == X86_VENDOR_AMD && 8557c478bd9Sstevel@tonic-gate cpi->cpi_family == 5 && 8567c478bd9Sstevel@tonic-gate cpi->cpi_model == 6 && 8577c478bd9Sstevel@tonic-gate cpi->cpi_step == 6) { 8587c478bd9Sstevel@tonic-gate /* 8597c478bd9Sstevel@tonic-gate * K6 model 6 uses bit 10 to indicate SYSC 8607c478bd9Sstevel@tonic-gate * Later models use bit 11. Fix it here. 8617c478bd9Sstevel@tonic-gate */ 8627c478bd9Sstevel@tonic-gate if (cp->cp_edx & 0x400) { 8637c478bd9Sstevel@tonic-gate cp->cp_edx &= ~0x400; 8647c478bd9Sstevel@tonic-gate cp->cp_edx |= CPUID_AMD_EDX_SYSC; 8657c478bd9Sstevel@tonic-gate } 8667c478bd9Sstevel@tonic-gate } 8677c478bd9Sstevel@tonic-gate 868ae115bc7Smrj platform_cpuid_mangle(cpi->cpi_vendor, 0x80000001, cp); 869ae115bc7Smrj 8707c478bd9Sstevel@tonic-gate /* 8717c478bd9Sstevel@tonic-gate * Compute the additions to the kernel's feature word. 8727c478bd9Sstevel@tonic-gate */ 8737c478bd9Sstevel@tonic-gate if (cp->cp_edx & CPUID_AMD_EDX_NX) 8747c478bd9Sstevel@tonic-gate feature |= X86_NX; 8757c478bd9Sstevel@tonic-gate 87602bc52beSkchow #if defined(__amd64) 87702bc52beSkchow /* 1 GB large page - enable only for 64 bit kernel */ 87802bc52beSkchow if (cp->cp_edx & CPUID_AMD_EDX_1GPG) 87902bc52beSkchow feature |= X86_1GPG; 88002bc52beSkchow #endif 88102bc52beSkchow 882f8801251Skk208521 if ((cpi->cpi_vendor == X86_VENDOR_AMD) && 883f8801251Skk208521 (cpi->cpi_std[1].cp_edx & CPUID_INTC_EDX_FXSR) && 884f8801251Skk208521 (cp->cp_ecx & CPUID_AMD_ECX_SSE4A)) 885f8801251Skk208521 feature |= X86_SSE4A; 886f8801251Skk208521 8877c478bd9Sstevel@tonic-gate /* 888ae115bc7Smrj * If both the HTT and CMP_LGCY bits are set, 8898949bcd6Sandrei * then we're not actually HyperThreaded. Read 8908949bcd6Sandrei * "AMD CPUID Specification" for more details. 8917c478bd9Sstevel@tonic-gate */ 8927c478bd9Sstevel@tonic-gate if (cpi->cpi_vendor == X86_VENDOR_AMD && 8938949bcd6Sandrei (feature & X86_HTT) && 894ae115bc7Smrj (cp->cp_ecx & CPUID_AMD_ECX_CMP_LGCY)) { 8957c478bd9Sstevel@tonic-gate feature &= ~X86_HTT; 8968949bcd6Sandrei feature |= X86_CMP; 8978949bcd6Sandrei } 898ae115bc7Smrj #if defined(__amd64) 8997c478bd9Sstevel@tonic-gate /* 9007c478bd9Sstevel@tonic-gate * It's really tricky to support syscall/sysret in 9017c478bd9Sstevel@tonic-gate * the i386 kernel; we rely on sysenter/sysexit 9027c478bd9Sstevel@tonic-gate * instead. In the amd64 kernel, things are -way- 9037c478bd9Sstevel@tonic-gate * better. 9047c478bd9Sstevel@tonic-gate */ 9057c478bd9Sstevel@tonic-gate if (cp->cp_edx & CPUID_AMD_EDX_SYSC) 9067c478bd9Sstevel@tonic-gate feature |= X86_ASYSC; 9077c478bd9Sstevel@tonic-gate 9087c478bd9Sstevel@tonic-gate /* 9097c478bd9Sstevel@tonic-gate * While we're thinking about system calls, note 9107c478bd9Sstevel@tonic-gate * that AMD processors don't support sysenter 9117c478bd9Sstevel@tonic-gate * in long mode at all, so don't try to program them. 9127c478bd9Sstevel@tonic-gate */ 9137c478bd9Sstevel@tonic-gate if (x86_vendor == X86_VENDOR_AMD) 9147c478bd9Sstevel@tonic-gate feature &= ~X86_SEP; 9157c478bd9Sstevel@tonic-gate #endif 916d36ea5d8Ssudheer if (cp->cp_edx & CPUID_AMD_EDX_TSCP) 917ae115bc7Smrj feature |= X86_TSCP; 9187c478bd9Sstevel@tonic-gate break; 9197c478bd9Sstevel@tonic-gate default: 9207c478bd9Sstevel@tonic-gate break; 9217c478bd9Sstevel@tonic-gate } 9227c478bd9Sstevel@tonic-gate 9238949bcd6Sandrei /* 9248949bcd6Sandrei * Get CPUID data about processor cores and hyperthreads. 9258949bcd6Sandrei */ 9267c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 9277c478bd9Sstevel@tonic-gate case X86_VENDOR_Intel: 9288949bcd6Sandrei if (cpi->cpi_maxeax >= 4) { 9298949bcd6Sandrei cp = &cpi->cpi_std[4]; 9308949bcd6Sandrei cp->cp_eax = 4; 9318949bcd6Sandrei cp->cp_ecx = 0; 9328949bcd6Sandrei (void) __cpuid_insn(cp); 933ae115bc7Smrj platform_cpuid_mangle(cpi->cpi_vendor, 4, cp); 9348949bcd6Sandrei } 9358949bcd6Sandrei /*FALLTHROUGH*/ 9367c478bd9Sstevel@tonic-gate case X86_VENDOR_AMD: 9377c478bd9Sstevel@tonic-gate if (cpi->cpi_xmaxeax < 0x80000008) 9387c478bd9Sstevel@tonic-gate break; 9397c478bd9Sstevel@tonic-gate cp = &cpi->cpi_extd[8]; 9408949bcd6Sandrei cp->cp_eax = 0x80000008; 9418949bcd6Sandrei (void) __cpuid_insn(cp); 942ae115bc7Smrj platform_cpuid_mangle(cpi->cpi_vendor, 0x80000008, cp); 943ae115bc7Smrj 9447c478bd9Sstevel@tonic-gate /* 9457c478bd9Sstevel@tonic-gate * Virtual and physical address limits from 9467c478bd9Sstevel@tonic-gate * cpuid override previously guessed values. 9477c478bd9Sstevel@tonic-gate */ 9487c478bd9Sstevel@tonic-gate cpi->cpi_pabits = BITX(cp->cp_eax, 7, 0); 9497c478bd9Sstevel@tonic-gate cpi->cpi_vabits = BITX(cp->cp_eax, 15, 8); 9507c478bd9Sstevel@tonic-gate break; 9517c478bd9Sstevel@tonic-gate default: 9527c478bd9Sstevel@tonic-gate break; 9537c478bd9Sstevel@tonic-gate } 9548949bcd6Sandrei 955d129bde2Sesaxe /* 956d129bde2Sesaxe * Derive the number of cores per chip 957d129bde2Sesaxe */ 9588949bcd6Sandrei switch (cpi->cpi_vendor) { 9598949bcd6Sandrei case X86_VENDOR_Intel: 9608949bcd6Sandrei if (cpi->cpi_maxeax < 4) { 9618949bcd6Sandrei cpi->cpi_ncore_per_chip = 1; 9628949bcd6Sandrei break; 9638949bcd6Sandrei } else { 9648949bcd6Sandrei cpi->cpi_ncore_per_chip = 9658949bcd6Sandrei BITX((cpi)->cpi_std[4].cp_eax, 31, 26) + 1; 9668949bcd6Sandrei } 9678949bcd6Sandrei break; 9688949bcd6Sandrei case X86_VENDOR_AMD: 9698949bcd6Sandrei if (cpi->cpi_xmaxeax < 0x80000008) { 9708949bcd6Sandrei cpi->cpi_ncore_per_chip = 1; 9718949bcd6Sandrei break; 9728949bcd6Sandrei } else { 97310569901Sgavinm /* 97410569901Sgavinm * On family 0xf cpuid fn 2 ECX[7:0] "NC" is 97510569901Sgavinm * 1 less than the number of physical cores on 97610569901Sgavinm * the chip. In family 0x10 this value can 97710569901Sgavinm * be affected by "downcoring" - it reflects 97810569901Sgavinm * 1 less than the number of cores actually 97910569901Sgavinm * enabled on this node. 98010569901Sgavinm */ 9818949bcd6Sandrei cpi->cpi_ncore_per_chip = 9828949bcd6Sandrei BITX((cpi)->cpi_extd[8].cp_ecx, 7, 0) + 1; 9838949bcd6Sandrei } 9848949bcd6Sandrei break; 9858949bcd6Sandrei default: 9868949bcd6Sandrei cpi->cpi_ncore_per_chip = 1; 9878949bcd6Sandrei break; 9887c478bd9Sstevel@tonic-gate } 989fa2e767eSgavinm } else { 990fa2e767eSgavinm cpi->cpi_ncore_per_chip = 1; 9918949bcd6Sandrei } 9928949bcd6Sandrei 9938949bcd6Sandrei /* 9948949bcd6Sandrei * If more than one core, then this processor is CMP. 9958949bcd6Sandrei */ 9968949bcd6Sandrei if (cpi->cpi_ncore_per_chip > 1) 9978949bcd6Sandrei feature |= X86_CMP; 998ae115bc7Smrj 9998949bcd6Sandrei /* 10008949bcd6Sandrei * If the number of cores is the same as the number 10018949bcd6Sandrei * of CPUs, then we cannot have HyperThreading. 10028949bcd6Sandrei */ 10038949bcd6Sandrei if (cpi->cpi_ncpu_per_chip == cpi->cpi_ncore_per_chip) 10048949bcd6Sandrei feature &= ~X86_HTT; 10058949bcd6Sandrei 10067c478bd9Sstevel@tonic-gate if ((feature & (X86_HTT | X86_CMP)) == 0) { 10078949bcd6Sandrei /* 10088949bcd6Sandrei * Single-core single-threaded processors. 10098949bcd6Sandrei */ 10107c478bd9Sstevel@tonic-gate cpi->cpi_chipid = -1; 10117c478bd9Sstevel@tonic-gate cpi->cpi_clogid = 0; 10128949bcd6Sandrei cpi->cpi_coreid = cpu->cpu_id; 101310569901Sgavinm cpi->cpi_pkgcoreid = 0; 10147c478bd9Sstevel@tonic-gate } else if (cpi->cpi_ncpu_per_chip > 1) { 10158949bcd6Sandrei uint_t i; 10168949bcd6Sandrei uint_t chipid_shift = 0; 10178949bcd6Sandrei uint_t coreid_shift = 0; 10188949bcd6Sandrei uint_t apic_id = CPI_APIC_ID(cpi); 10197c478bd9Sstevel@tonic-gate 10208949bcd6Sandrei for (i = 1; i < cpi->cpi_ncpu_per_chip; i <<= 1) 10218949bcd6Sandrei chipid_shift++; 10228949bcd6Sandrei cpi->cpi_chipid = apic_id >> chipid_shift; 10238949bcd6Sandrei cpi->cpi_clogid = apic_id & ((1 << chipid_shift) - 1); 10248949bcd6Sandrei 10258949bcd6Sandrei if (cpi->cpi_vendor == X86_VENDOR_Intel) { 10268949bcd6Sandrei if (feature & X86_CMP) { 10278949bcd6Sandrei /* 10288949bcd6Sandrei * Multi-core (and possibly multi-threaded) 10298949bcd6Sandrei * processors. 10308949bcd6Sandrei */ 10318949bcd6Sandrei uint_t ncpu_per_core; 10328949bcd6Sandrei if (cpi->cpi_ncore_per_chip == 1) 10338949bcd6Sandrei ncpu_per_core = cpi->cpi_ncpu_per_chip; 10348949bcd6Sandrei else if (cpi->cpi_ncore_per_chip > 1) 10358949bcd6Sandrei ncpu_per_core = cpi->cpi_ncpu_per_chip / 10368949bcd6Sandrei cpi->cpi_ncore_per_chip; 10378949bcd6Sandrei /* 10388949bcd6Sandrei * 8bit APIC IDs on dual core Pentiums 10398949bcd6Sandrei * look like this: 10408949bcd6Sandrei * 10418949bcd6Sandrei * +-----------------------+------+------+ 10428949bcd6Sandrei * | Physical Package ID | MC | HT | 10438949bcd6Sandrei * +-----------------------+------+------+ 10448949bcd6Sandrei * <------- chipid --------> 10458949bcd6Sandrei * <------- coreid ---------------> 10468949bcd6Sandrei * <--- clogid --> 104710569901Sgavinm * <------> 104810569901Sgavinm * pkgcoreid 10498949bcd6Sandrei * 10508949bcd6Sandrei * Where the number of bits necessary to 10518949bcd6Sandrei * represent MC and HT fields together equals 10528949bcd6Sandrei * to the minimum number of bits necessary to 10538949bcd6Sandrei * store the value of cpi->cpi_ncpu_per_chip. 10548949bcd6Sandrei * Of those bits, the MC part uses the number 10558949bcd6Sandrei * of bits necessary to store the value of 10568949bcd6Sandrei * cpi->cpi_ncore_per_chip. 10578949bcd6Sandrei */ 10588949bcd6Sandrei for (i = 1; i < ncpu_per_core; i <<= 1) 10598949bcd6Sandrei coreid_shift++; 10603090b9a9Sandrei cpi->cpi_coreid = apic_id >> coreid_shift; 106110569901Sgavinm cpi->cpi_pkgcoreid = cpi->cpi_clogid >> 106210569901Sgavinm coreid_shift; 10638949bcd6Sandrei } else if (feature & X86_HTT) { 10648949bcd6Sandrei /* 10658949bcd6Sandrei * Single-core multi-threaded processors. 10668949bcd6Sandrei */ 10678949bcd6Sandrei cpi->cpi_coreid = cpi->cpi_chipid; 106810569901Sgavinm cpi->cpi_pkgcoreid = 0; 10698949bcd6Sandrei } 10708949bcd6Sandrei } else if (cpi->cpi_vendor == X86_VENDOR_AMD) { 10718949bcd6Sandrei /* 107210569901Sgavinm * AMD CMP chips currently have a single thread per 107310569901Sgavinm * core, with 2 cores on family 0xf and 2, 3 or 4 107410569901Sgavinm * cores on family 0x10. 107510569901Sgavinm * 107610569901Sgavinm * Since no two cpus share a core we must assign a 107710569901Sgavinm * distinct coreid per cpu, and we do this by using 107810569901Sgavinm * the cpu_id. This scheme does not, however, 107910569901Sgavinm * guarantee that sibling cores of a chip will have 108010569901Sgavinm * sequential coreids starting at a multiple of the 108110569901Sgavinm * number of cores per chip - that is usually the 108210569901Sgavinm * case, but if the ACPI MADT table is presented 108310569901Sgavinm * in a different order then we need to perform a 108410569901Sgavinm * few more gymnastics for the pkgcoreid. 108510569901Sgavinm * 108610569901Sgavinm * In family 0xf CMPs there are 2 cores on all nodes 108710569901Sgavinm * present - no mixing of single and dual core parts. 108810569901Sgavinm * 108910569901Sgavinm * In family 0x10 CMPs cpuid fn 2 ECX[15:12] 109010569901Sgavinm * "ApicIdCoreIdSize[3:0]" tells us how 109110569901Sgavinm * many least-significant bits in the ApicId 109210569901Sgavinm * are used to represent the core number 109310569901Sgavinm * within the node. Cores are always 109410569901Sgavinm * numbered sequentially from 0 regardless 109510569901Sgavinm * of how many or which are disabled, and 109610569901Sgavinm * there seems to be no way to discover the 109710569901Sgavinm * real core id when some are disabled. 10988949bcd6Sandrei */ 10998949bcd6Sandrei cpi->cpi_coreid = cpu->cpu_id; 110010569901Sgavinm 110110569901Sgavinm if (cpi->cpi_family == 0x10 && 110210569901Sgavinm cpi->cpi_xmaxeax >= 0x80000008) { 110310569901Sgavinm int coreidsz = 110410569901Sgavinm BITX((cpi)->cpi_extd[8].cp_ecx, 15, 12); 110510569901Sgavinm 110610569901Sgavinm cpi->cpi_pkgcoreid = 110710569901Sgavinm apic_id & ((1 << coreidsz) - 1); 110810569901Sgavinm } else { 110910569901Sgavinm cpi->cpi_pkgcoreid = cpi->cpi_clogid; 111010569901Sgavinm } 11118949bcd6Sandrei } else { 11128949bcd6Sandrei /* 11138949bcd6Sandrei * All other processors are currently 11148949bcd6Sandrei * assumed to have single cores. 11158949bcd6Sandrei */ 11168949bcd6Sandrei cpi->cpi_coreid = cpi->cpi_chipid; 111710569901Sgavinm cpi->cpi_pkgcoreid = 0; 11188949bcd6Sandrei } 11197c478bd9Sstevel@tonic-gate } 11207c478bd9Sstevel@tonic-gate 1121b6917abeSmishra cpi->cpi_apicid = CPI_APIC_ID(cpi); 1122b6917abeSmishra 11238a40a695Sgavinm /* 11248a40a695Sgavinm * Synthesize chip "revision" and socket type 11258a40a695Sgavinm */ 1126*e4b86885SCheng Sean Ye cpi->cpi_chiprev = _cpuid_chiprev(cpi->cpi_vendor, cpi->cpi_family, 1127*e4b86885SCheng Sean Ye cpi->cpi_model, cpi->cpi_step); 1128*e4b86885SCheng Sean Ye cpi->cpi_chiprevstr = _cpuid_chiprevstr(cpi->cpi_vendor, 1129*e4b86885SCheng Sean Ye cpi->cpi_family, cpi->cpi_model, cpi->cpi_step); 1130*e4b86885SCheng Sean Ye cpi->cpi_socket = _cpuid_skt(cpi->cpi_vendor, cpi->cpi_family, 1131*e4b86885SCheng Sean Ye cpi->cpi_model, cpi->cpi_step); 11328a40a695Sgavinm 11337c478bd9Sstevel@tonic-gate pass1_done: 1134551bc2a6Smrj #if !defined(__xpv) 1135551bc2a6Smrj check_for_hvm(); 1136551bc2a6Smrj #endif 11377c478bd9Sstevel@tonic-gate cpi->cpi_pass = 1; 11387c478bd9Sstevel@tonic-gate return (feature); 11397c478bd9Sstevel@tonic-gate } 11407c478bd9Sstevel@tonic-gate 11417c478bd9Sstevel@tonic-gate /* 11427c478bd9Sstevel@tonic-gate * Make copies of the cpuid table entries we depend on, in 11437c478bd9Sstevel@tonic-gate * part for ease of parsing now, in part so that we have only 11447c478bd9Sstevel@tonic-gate * one place to correct any of it, in part for ease of 11457c478bd9Sstevel@tonic-gate * later export to userland, and in part so we can look at 11467c478bd9Sstevel@tonic-gate * this stuff in a crash dump. 11477c478bd9Sstevel@tonic-gate */ 11487c478bd9Sstevel@tonic-gate 11497c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 11507c478bd9Sstevel@tonic-gate void 11517c478bd9Sstevel@tonic-gate cpuid_pass2(cpu_t *cpu) 11527c478bd9Sstevel@tonic-gate { 11537c478bd9Sstevel@tonic-gate uint_t n, nmax; 11547c478bd9Sstevel@tonic-gate int i; 11558949bcd6Sandrei struct cpuid_regs *cp; 11567c478bd9Sstevel@tonic-gate uint8_t *dp; 11577c478bd9Sstevel@tonic-gate uint32_t *iptr; 11587c478bd9Sstevel@tonic-gate struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 11597c478bd9Sstevel@tonic-gate 11607c478bd9Sstevel@tonic-gate ASSERT(cpi->cpi_pass == 1); 11617c478bd9Sstevel@tonic-gate 11627c478bd9Sstevel@tonic-gate if (cpi->cpi_maxeax < 1) 11637c478bd9Sstevel@tonic-gate goto pass2_done; 11647c478bd9Sstevel@tonic-gate 11657c478bd9Sstevel@tonic-gate if ((nmax = cpi->cpi_maxeax + 1) > NMAX_CPI_STD) 11667c478bd9Sstevel@tonic-gate nmax = NMAX_CPI_STD; 11677c478bd9Sstevel@tonic-gate /* 11687c478bd9Sstevel@tonic-gate * (We already handled n == 0 and n == 1 in pass 1) 11697c478bd9Sstevel@tonic-gate */ 11707c478bd9Sstevel@tonic-gate for (n = 2, cp = &cpi->cpi_std[2]; n < nmax; n++, cp++) { 11718949bcd6Sandrei cp->cp_eax = n; 1172d129bde2Sesaxe 1173d129bde2Sesaxe /* 1174d129bde2Sesaxe * CPUID function 4 expects %ecx to be initialized 1175d129bde2Sesaxe * with an index which indicates which cache to return 1176d129bde2Sesaxe * information about. The OS is expected to call function 4 1177d129bde2Sesaxe * with %ecx set to 0, 1, 2, ... until it returns with 1178d129bde2Sesaxe * EAX[4:0] set to 0, which indicates there are no more 1179d129bde2Sesaxe * caches. 1180d129bde2Sesaxe * 1181d129bde2Sesaxe * Here, populate cpi_std[4] with the information returned by 1182d129bde2Sesaxe * function 4 when %ecx == 0, and do the rest in cpuid_pass3() 1183d129bde2Sesaxe * when dynamic memory allocation becomes available. 1184d129bde2Sesaxe * 1185d129bde2Sesaxe * Note: we need to explicitly initialize %ecx here, since 1186d129bde2Sesaxe * function 4 may have been previously invoked. 1187d129bde2Sesaxe */ 1188d129bde2Sesaxe if (n == 4) 1189d129bde2Sesaxe cp->cp_ecx = 0; 1190d129bde2Sesaxe 11918949bcd6Sandrei (void) __cpuid_insn(cp); 1192ae115bc7Smrj platform_cpuid_mangle(cpi->cpi_vendor, n, cp); 11937c478bd9Sstevel@tonic-gate switch (n) { 11947c478bd9Sstevel@tonic-gate case 2: 11957c478bd9Sstevel@tonic-gate /* 11967c478bd9Sstevel@tonic-gate * "the lower 8 bits of the %eax register 11977c478bd9Sstevel@tonic-gate * contain a value that identifies the number 11987c478bd9Sstevel@tonic-gate * of times the cpuid [instruction] has to be 11997c478bd9Sstevel@tonic-gate * executed to obtain a complete image of the 12007c478bd9Sstevel@tonic-gate * processor's caching systems." 12017c478bd9Sstevel@tonic-gate * 12027c478bd9Sstevel@tonic-gate * How *do* they make this stuff up? 12037c478bd9Sstevel@tonic-gate */ 12047c478bd9Sstevel@tonic-gate cpi->cpi_ncache = sizeof (*cp) * 12057c478bd9Sstevel@tonic-gate BITX(cp->cp_eax, 7, 0); 12067c478bd9Sstevel@tonic-gate if (cpi->cpi_ncache == 0) 12077c478bd9Sstevel@tonic-gate break; 12087c478bd9Sstevel@tonic-gate cpi->cpi_ncache--; /* skip count byte */ 12097c478bd9Sstevel@tonic-gate 12107c478bd9Sstevel@tonic-gate /* 12117c478bd9Sstevel@tonic-gate * Well, for now, rather than attempt to implement 12127c478bd9Sstevel@tonic-gate * this slightly dubious algorithm, we just look 12137c478bd9Sstevel@tonic-gate * at the first 15 .. 12147c478bd9Sstevel@tonic-gate */ 12157c478bd9Sstevel@tonic-gate if (cpi->cpi_ncache > (sizeof (*cp) - 1)) 12167c478bd9Sstevel@tonic-gate cpi->cpi_ncache = sizeof (*cp) - 1; 12177c478bd9Sstevel@tonic-gate 12187c478bd9Sstevel@tonic-gate dp = cpi->cpi_cacheinfo; 12197c478bd9Sstevel@tonic-gate if (BITX(cp->cp_eax, 31, 31) == 0) { 12207c478bd9Sstevel@tonic-gate uint8_t *p = (void *)&cp->cp_eax; 122163d3f7dfSkk208521 for (i = 1; i < 4; i++) 12227c478bd9Sstevel@tonic-gate if (p[i] != 0) 12237c478bd9Sstevel@tonic-gate *dp++ = p[i]; 12247c478bd9Sstevel@tonic-gate } 12257c478bd9Sstevel@tonic-gate if (BITX(cp->cp_ebx, 31, 31) == 0) { 12267c478bd9Sstevel@tonic-gate uint8_t *p = (void *)&cp->cp_ebx; 12277c478bd9Sstevel@tonic-gate for (i = 0; i < 4; i++) 12287c478bd9Sstevel@tonic-gate if (p[i] != 0) 12297c478bd9Sstevel@tonic-gate *dp++ = p[i]; 12307c478bd9Sstevel@tonic-gate } 12317c478bd9Sstevel@tonic-gate if (BITX(cp->cp_ecx, 31, 31) == 0) { 12327c478bd9Sstevel@tonic-gate uint8_t *p = (void *)&cp->cp_ecx; 12337c478bd9Sstevel@tonic-gate for (i = 0; i < 4; i++) 12347c478bd9Sstevel@tonic-gate if (p[i] != 0) 12357c478bd9Sstevel@tonic-gate *dp++ = p[i]; 12367c478bd9Sstevel@tonic-gate } 12377c478bd9Sstevel@tonic-gate if (BITX(cp->cp_edx, 31, 31) == 0) { 12387c478bd9Sstevel@tonic-gate uint8_t *p = (void *)&cp->cp_edx; 12397c478bd9Sstevel@tonic-gate for (i = 0; i < 4; i++) 12407c478bd9Sstevel@tonic-gate if (p[i] != 0) 12417c478bd9Sstevel@tonic-gate *dp++ = p[i]; 12427c478bd9Sstevel@tonic-gate } 12437c478bd9Sstevel@tonic-gate break; 1244f98fbcecSbholler 12457c478bd9Sstevel@tonic-gate case 3: /* Processor serial number, if PSN supported */ 1246f98fbcecSbholler break; 1247f98fbcecSbholler 12487c478bd9Sstevel@tonic-gate case 4: /* Deterministic cache parameters */ 1249f98fbcecSbholler break; 1250f98fbcecSbholler 12517c478bd9Sstevel@tonic-gate case 5: /* Monitor/Mwait parameters */ 12525b8a6efeSbholler { 12535b8a6efeSbholler size_t mwait_size; 1254f98fbcecSbholler 1255f98fbcecSbholler /* 1256f98fbcecSbholler * check cpi_mwait.support which was set in cpuid_pass1 1257f98fbcecSbholler */ 1258f98fbcecSbholler if (!(cpi->cpi_mwait.support & MWAIT_SUPPORT)) 1259f98fbcecSbholler break; 1260f98fbcecSbholler 12615b8a6efeSbholler /* 12625b8a6efeSbholler * Protect ourself from insane mwait line size. 12635b8a6efeSbholler * Workaround for incomplete hardware emulator(s). 12645b8a6efeSbholler */ 12655b8a6efeSbholler mwait_size = (size_t)MWAIT_SIZE_MAX(cpi); 12665b8a6efeSbholler if (mwait_size < sizeof (uint32_t) || 12675b8a6efeSbholler !ISP2(mwait_size)) { 12685b8a6efeSbholler #if DEBUG 12695b8a6efeSbholler cmn_err(CE_NOTE, "Cannot handle cpu %d mwait " 12705b8a6efeSbholler "size %ld", 12715b8a6efeSbholler cpu->cpu_id, (long)mwait_size); 12725b8a6efeSbholler #endif 12735b8a6efeSbholler break; 12745b8a6efeSbholler } 12755b8a6efeSbholler 1276f98fbcecSbholler cpi->cpi_mwait.mon_min = (size_t)MWAIT_SIZE_MIN(cpi); 12775b8a6efeSbholler cpi->cpi_mwait.mon_max = mwait_size; 1278f98fbcecSbholler if (MWAIT_EXTENSION(cpi)) { 1279f98fbcecSbholler cpi->cpi_mwait.support |= MWAIT_EXTENSIONS; 1280f98fbcecSbholler if (MWAIT_INT_ENABLE(cpi)) 1281f98fbcecSbholler cpi->cpi_mwait.support |= 1282f98fbcecSbholler MWAIT_ECX_INT_ENABLE; 1283f98fbcecSbholler } 1284f98fbcecSbholler break; 12855b8a6efeSbholler } 12867c478bd9Sstevel@tonic-gate default: 12877c478bd9Sstevel@tonic-gate break; 12887c478bd9Sstevel@tonic-gate } 12897c478bd9Sstevel@tonic-gate } 12907c478bd9Sstevel@tonic-gate 1291b6917abeSmishra if (cpi->cpi_maxeax >= 0xB && cpi->cpi_vendor == X86_VENDOR_Intel) { 1292b6917abeSmishra cp->cp_eax = 0xB; 1293b6917abeSmishra cp->cp_ecx = 0; 1294b6917abeSmishra 1295b6917abeSmishra (void) __cpuid_insn(cp); 1296b6917abeSmishra 1297b6917abeSmishra /* 1298b6917abeSmishra * Check CPUID.EAX=0BH, ECX=0H:EBX is non-zero, which 1299b6917abeSmishra * indicates that the extended topology enumeration leaf is 1300b6917abeSmishra * available. 1301b6917abeSmishra */ 1302b6917abeSmishra if (cp->cp_ebx) { 1303b6917abeSmishra uint32_t x2apic_id; 1304b6917abeSmishra uint_t coreid_shift = 0; 1305b6917abeSmishra uint_t ncpu_per_core = 1; 1306b6917abeSmishra uint_t chipid_shift = 0; 1307b6917abeSmishra uint_t ncpu_per_chip = 1; 1308b6917abeSmishra uint_t i; 1309b6917abeSmishra uint_t level; 1310b6917abeSmishra 1311b6917abeSmishra for (i = 0; i < CPI_FNB_ECX_MAX; i++) { 1312b6917abeSmishra cp->cp_eax = 0xB; 1313b6917abeSmishra cp->cp_ecx = i; 1314b6917abeSmishra 1315b6917abeSmishra (void) __cpuid_insn(cp); 1316b6917abeSmishra level = CPI_CPU_LEVEL_TYPE(cp); 1317b6917abeSmishra 1318b6917abeSmishra if (level == 1) { 1319b6917abeSmishra x2apic_id = cp->cp_edx; 1320b6917abeSmishra coreid_shift = BITX(cp->cp_eax, 4, 0); 1321b6917abeSmishra ncpu_per_core = BITX(cp->cp_ebx, 15, 0); 1322b6917abeSmishra } else if (level == 2) { 1323b6917abeSmishra x2apic_id = cp->cp_edx; 1324b6917abeSmishra chipid_shift = BITX(cp->cp_eax, 4, 0); 1325b6917abeSmishra ncpu_per_chip = BITX(cp->cp_ebx, 15, 0); 1326b6917abeSmishra } 1327b6917abeSmishra } 1328b6917abeSmishra 1329b6917abeSmishra cpi->cpi_apicid = x2apic_id; 1330b6917abeSmishra cpi->cpi_ncpu_per_chip = ncpu_per_chip; 1331b6917abeSmishra cpi->cpi_ncore_per_chip = ncpu_per_chip / 1332b6917abeSmishra ncpu_per_core; 1333b6917abeSmishra cpi->cpi_chipid = x2apic_id >> chipid_shift; 1334b6917abeSmishra cpi->cpi_clogid = x2apic_id & ((1 << chipid_shift) - 1); 1335b6917abeSmishra cpi->cpi_coreid = x2apic_id >> coreid_shift; 1336b6917abeSmishra cpi->cpi_pkgcoreid = cpi->cpi_clogid >> coreid_shift; 1337b6917abeSmishra } 1338b6917abeSmishra } 1339b6917abeSmishra 13407c478bd9Sstevel@tonic-gate if ((cpi->cpi_xmaxeax & 0x80000000) == 0) 13417c478bd9Sstevel@tonic-gate goto pass2_done; 13427c478bd9Sstevel@tonic-gate 13437c478bd9Sstevel@tonic-gate if ((nmax = cpi->cpi_xmaxeax - 0x80000000 + 1) > NMAX_CPI_EXTD) 13447c478bd9Sstevel@tonic-gate nmax = NMAX_CPI_EXTD; 13457c478bd9Sstevel@tonic-gate /* 13467c478bd9Sstevel@tonic-gate * Copy the extended properties, fixing them as we go. 13477c478bd9Sstevel@tonic-gate * (We already handled n == 0 and n == 1 in pass 1) 13487c478bd9Sstevel@tonic-gate */ 13497c478bd9Sstevel@tonic-gate iptr = (void *)cpi->cpi_brandstr; 13507c478bd9Sstevel@tonic-gate for (n = 2, cp = &cpi->cpi_extd[2]; n < nmax; cp++, n++) { 13518949bcd6Sandrei cp->cp_eax = 0x80000000 + n; 13528949bcd6Sandrei (void) __cpuid_insn(cp); 1353ae115bc7Smrj platform_cpuid_mangle(cpi->cpi_vendor, 0x80000000 + n, cp); 13547c478bd9Sstevel@tonic-gate switch (n) { 13557c478bd9Sstevel@tonic-gate case 2: 13567c478bd9Sstevel@tonic-gate case 3: 13577c478bd9Sstevel@tonic-gate case 4: 13587c478bd9Sstevel@tonic-gate /* 13597c478bd9Sstevel@tonic-gate * Extract the brand string 13607c478bd9Sstevel@tonic-gate */ 13617c478bd9Sstevel@tonic-gate *iptr++ = cp->cp_eax; 13627c478bd9Sstevel@tonic-gate *iptr++ = cp->cp_ebx; 13637c478bd9Sstevel@tonic-gate *iptr++ = cp->cp_ecx; 13647c478bd9Sstevel@tonic-gate *iptr++ = cp->cp_edx; 13657c478bd9Sstevel@tonic-gate break; 13667c478bd9Sstevel@tonic-gate case 5: 13677c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 13687c478bd9Sstevel@tonic-gate case X86_VENDOR_AMD: 13697c478bd9Sstevel@tonic-gate /* 13707c478bd9Sstevel@tonic-gate * The Athlon and Duron were the first 13717c478bd9Sstevel@tonic-gate * parts to report the sizes of the 13727c478bd9Sstevel@tonic-gate * TLB for large pages. Before then, 13737c478bd9Sstevel@tonic-gate * we don't trust the data. 13747c478bd9Sstevel@tonic-gate */ 13757c478bd9Sstevel@tonic-gate if (cpi->cpi_family < 6 || 13767c478bd9Sstevel@tonic-gate (cpi->cpi_family == 6 && 13777c478bd9Sstevel@tonic-gate cpi->cpi_model < 1)) 13787c478bd9Sstevel@tonic-gate cp->cp_eax = 0; 13797c478bd9Sstevel@tonic-gate break; 13807c478bd9Sstevel@tonic-gate default: 13817c478bd9Sstevel@tonic-gate break; 13827c478bd9Sstevel@tonic-gate } 13837c478bd9Sstevel@tonic-gate break; 13847c478bd9Sstevel@tonic-gate case 6: 13857c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 13867c478bd9Sstevel@tonic-gate case X86_VENDOR_AMD: 13877c478bd9Sstevel@tonic-gate /* 13887c478bd9Sstevel@tonic-gate * The Athlon and Duron were the first 13897c478bd9Sstevel@tonic-gate * AMD parts with L2 TLB's. 13907c478bd9Sstevel@tonic-gate * Before then, don't trust the data. 13917c478bd9Sstevel@tonic-gate */ 13927c478bd9Sstevel@tonic-gate if (cpi->cpi_family < 6 || 13937c478bd9Sstevel@tonic-gate cpi->cpi_family == 6 && 13947c478bd9Sstevel@tonic-gate cpi->cpi_model < 1) 13957c478bd9Sstevel@tonic-gate cp->cp_eax = cp->cp_ebx = 0; 13967c478bd9Sstevel@tonic-gate /* 13977c478bd9Sstevel@tonic-gate * AMD Duron rev A0 reports L2 13987c478bd9Sstevel@tonic-gate * cache size incorrectly as 1K 13997c478bd9Sstevel@tonic-gate * when it is really 64K 14007c478bd9Sstevel@tonic-gate */ 14017c478bd9Sstevel@tonic-gate if (cpi->cpi_family == 6 && 14027c478bd9Sstevel@tonic-gate cpi->cpi_model == 3 && 14037c478bd9Sstevel@tonic-gate cpi->cpi_step == 0) { 14047c478bd9Sstevel@tonic-gate cp->cp_ecx &= 0xffff; 14057c478bd9Sstevel@tonic-gate cp->cp_ecx |= 0x400000; 14067c478bd9Sstevel@tonic-gate } 14077c478bd9Sstevel@tonic-gate break; 14087c478bd9Sstevel@tonic-gate case X86_VENDOR_Cyrix: /* VIA C3 */ 14097c478bd9Sstevel@tonic-gate /* 14107c478bd9Sstevel@tonic-gate * VIA C3 processors are a bit messed 14117c478bd9Sstevel@tonic-gate * up w.r.t. encoding cache sizes in %ecx 14127c478bd9Sstevel@tonic-gate */ 14137c478bd9Sstevel@tonic-gate if (cpi->cpi_family != 6) 14147c478bd9Sstevel@tonic-gate break; 14157c478bd9Sstevel@tonic-gate /* 14167c478bd9Sstevel@tonic-gate * model 7 and 8 were incorrectly encoded 14177c478bd9Sstevel@tonic-gate * 14187c478bd9Sstevel@tonic-gate * xxx is model 8 really broken? 14197c478bd9Sstevel@tonic-gate */ 14207c478bd9Sstevel@tonic-gate if (cpi->cpi_model == 7 || 14217c478bd9Sstevel@tonic-gate cpi->cpi_model == 8) 14227c478bd9Sstevel@tonic-gate cp->cp_ecx = 14237c478bd9Sstevel@tonic-gate BITX(cp->cp_ecx, 31, 24) << 16 | 14247c478bd9Sstevel@tonic-gate BITX(cp->cp_ecx, 23, 16) << 12 | 14257c478bd9Sstevel@tonic-gate BITX(cp->cp_ecx, 15, 8) << 8 | 14267c478bd9Sstevel@tonic-gate BITX(cp->cp_ecx, 7, 0); 14277c478bd9Sstevel@tonic-gate /* 14287c478bd9Sstevel@tonic-gate * model 9 stepping 1 has wrong associativity 14297c478bd9Sstevel@tonic-gate */ 14307c478bd9Sstevel@tonic-gate if (cpi->cpi_model == 9 && cpi->cpi_step == 1) 14317c478bd9Sstevel@tonic-gate cp->cp_ecx |= 8 << 12; 14327c478bd9Sstevel@tonic-gate break; 14337c478bd9Sstevel@tonic-gate case X86_VENDOR_Intel: 14347c478bd9Sstevel@tonic-gate /* 14357c478bd9Sstevel@tonic-gate * Extended L2 Cache features function. 14367c478bd9Sstevel@tonic-gate * First appeared on Prescott. 14377c478bd9Sstevel@tonic-gate */ 14387c478bd9Sstevel@tonic-gate default: 14397c478bd9Sstevel@tonic-gate break; 14407c478bd9Sstevel@tonic-gate } 14417c478bd9Sstevel@tonic-gate break; 14427c478bd9Sstevel@tonic-gate default: 14437c478bd9Sstevel@tonic-gate break; 14447c478bd9Sstevel@tonic-gate } 14457c478bd9Sstevel@tonic-gate } 14467c478bd9Sstevel@tonic-gate 14477c478bd9Sstevel@tonic-gate pass2_done: 14487c478bd9Sstevel@tonic-gate cpi->cpi_pass = 2; 14497c478bd9Sstevel@tonic-gate } 14507c478bd9Sstevel@tonic-gate 14517c478bd9Sstevel@tonic-gate static const char * 14527c478bd9Sstevel@tonic-gate intel_cpubrand(const struct cpuid_info *cpi) 14537c478bd9Sstevel@tonic-gate { 14547c478bd9Sstevel@tonic-gate int i; 14557c478bd9Sstevel@tonic-gate 14567c478bd9Sstevel@tonic-gate if ((x86_feature & X86_CPUID) == 0 || 14577c478bd9Sstevel@tonic-gate cpi->cpi_maxeax < 1 || cpi->cpi_family < 5) 14587c478bd9Sstevel@tonic-gate return ("i486"); 14597c478bd9Sstevel@tonic-gate 14607c478bd9Sstevel@tonic-gate switch (cpi->cpi_family) { 14617c478bd9Sstevel@tonic-gate case 5: 14627c478bd9Sstevel@tonic-gate return ("Intel Pentium(r)"); 14637c478bd9Sstevel@tonic-gate case 6: 14647c478bd9Sstevel@tonic-gate switch (cpi->cpi_model) { 14657c478bd9Sstevel@tonic-gate uint_t celeron, xeon; 14668949bcd6Sandrei const struct cpuid_regs *cp; 14677c478bd9Sstevel@tonic-gate case 0: 14687c478bd9Sstevel@tonic-gate case 1: 14697c478bd9Sstevel@tonic-gate case 2: 14707c478bd9Sstevel@tonic-gate return ("Intel Pentium(r) Pro"); 14717c478bd9Sstevel@tonic-gate case 3: 14727c478bd9Sstevel@tonic-gate case 4: 14737c478bd9Sstevel@tonic-gate return ("Intel Pentium(r) II"); 14747c478bd9Sstevel@tonic-gate case 6: 14757c478bd9Sstevel@tonic-gate return ("Intel Celeron(r)"); 14767c478bd9Sstevel@tonic-gate case 5: 14777c478bd9Sstevel@tonic-gate case 7: 14787c478bd9Sstevel@tonic-gate celeron = xeon = 0; 14797c478bd9Sstevel@tonic-gate cp = &cpi->cpi_std[2]; /* cache info */ 14807c478bd9Sstevel@tonic-gate 148163d3f7dfSkk208521 for (i = 1; i < 4; i++) { 14827c478bd9Sstevel@tonic-gate uint_t tmp; 14837c478bd9Sstevel@tonic-gate 14847c478bd9Sstevel@tonic-gate tmp = (cp->cp_eax >> (8 * i)) & 0xff; 14857c478bd9Sstevel@tonic-gate if (tmp == 0x40) 14867c478bd9Sstevel@tonic-gate celeron++; 14877c478bd9Sstevel@tonic-gate if (tmp >= 0x44 && tmp <= 0x45) 14887c478bd9Sstevel@tonic-gate xeon++; 14897c478bd9Sstevel@tonic-gate } 14907c478bd9Sstevel@tonic-gate 14917c478bd9Sstevel@tonic-gate for (i = 0; i < 2; i++) { 14927c478bd9Sstevel@tonic-gate uint_t tmp; 14937c478bd9Sstevel@tonic-gate 14947c478bd9Sstevel@tonic-gate tmp = (cp->cp_ebx >> (8 * i)) & 0xff; 14957c478bd9Sstevel@tonic-gate if (tmp == 0x40) 14967c478bd9Sstevel@tonic-gate celeron++; 14977c478bd9Sstevel@tonic-gate else if (tmp >= 0x44 && tmp <= 0x45) 14987c478bd9Sstevel@tonic-gate xeon++; 14997c478bd9Sstevel@tonic-gate } 15007c478bd9Sstevel@tonic-gate 15017c478bd9Sstevel@tonic-gate for (i = 0; i < 4; i++) { 15027c478bd9Sstevel@tonic-gate uint_t tmp; 15037c478bd9Sstevel@tonic-gate 15047c478bd9Sstevel@tonic-gate tmp = (cp->cp_ecx >> (8 * i)) & 0xff; 15057c478bd9Sstevel@tonic-gate if (tmp == 0x40) 15067c478bd9Sstevel@tonic-gate celeron++; 15077c478bd9Sstevel@tonic-gate else if (tmp >= 0x44 && tmp <= 0x45) 15087c478bd9Sstevel@tonic-gate xeon++; 15097c478bd9Sstevel@tonic-gate } 15107c478bd9Sstevel@tonic-gate 15117c478bd9Sstevel@tonic-gate for (i = 0; i < 4; i++) { 15127c478bd9Sstevel@tonic-gate uint_t tmp; 15137c478bd9Sstevel@tonic-gate 15147c478bd9Sstevel@tonic-gate tmp = (cp->cp_edx >> (8 * i)) & 0xff; 15157c478bd9Sstevel@tonic-gate if (tmp == 0x40) 15167c478bd9Sstevel@tonic-gate celeron++; 15177c478bd9Sstevel@tonic-gate else if (tmp >= 0x44 && tmp <= 0x45) 15187c478bd9Sstevel@tonic-gate xeon++; 15197c478bd9Sstevel@tonic-gate } 15207c478bd9Sstevel@tonic-gate 15217c478bd9Sstevel@tonic-gate if (celeron) 15227c478bd9Sstevel@tonic-gate return ("Intel Celeron(r)"); 15237c478bd9Sstevel@tonic-gate if (xeon) 15247c478bd9Sstevel@tonic-gate return (cpi->cpi_model == 5 ? 15257c478bd9Sstevel@tonic-gate "Intel Pentium(r) II Xeon(tm)" : 15267c478bd9Sstevel@tonic-gate "Intel Pentium(r) III Xeon(tm)"); 15277c478bd9Sstevel@tonic-gate return (cpi->cpi_model == 5 ? 15287c478bd9Sstevel@tonic-gate "Intel Pentium(r) II or Pentium(r) II Xeon(tm)" : 15297c478bd9Sstevel@tonic-gate "Intel Pentium(r) III or Pentium(r) III Xeon(tm)"); 15307c478bd9Sstevel@tonic-gate default: 15317c478bd9Sstevel@tonic-gate break; 15327c478bd9Sstevel@tonic-gate } 15337c478bd9Sstevel@tonic-gate default: 15347c478bd9Sstevel@tonic-gate break; 15357c478bd9Sstevel@tonic-gate } 15367c478bd9Sstevel@tonic-gate 15375ff02082Sdmick /* BrandID is present if the field is nonzero */ 15385ff02082Sdmick if (cpi->cpi_brandid != 0) { 15397c478bd9Sstevel@tonic-gate static const struct { 15407c478bd9Sstevel@tonic-gate uint_t bt_bid; 15417c478bd9Sstevel@tonic-gate const char *bt_str; 15427c478bd9Sstevel@tonic-gate } brand_tbl[] = { 15437c478bd9Sstevel@tonic-gate { 0x1, "Intel(r) Celeron(r)" }, 15447c478bd9Sstevel@tonic-gate { 0x2, "Intel(r) Pentium(r) III" }, 15457c478bd9Sstevel@tonic-gate { 0x3, "Intel(r) Pentium(r) III Xeon(tm)" }, 15467c478bd9Sstevel@tonic-gate { 0x4, "Intel(r) Pentium(r) III" }, 15477c478bd9Sstevel@tonic-gate { 0x6, "Mobile Intel(r) Pentium(r) III" }, 15487c478bd9Sstevel@tonic-gate { 0x7, "Mobile Intel(r) Celeron(r)" }, 15497c478bd9Sstevel@tonic-gate { 0x8, "Intel(r) Pentium(r) 4" }, 15507c478bd9Sstevel@tonic-gate { 0x9, "Intel(r) Pentium(r) 4" }, 15517c478bd9Sstevel@tonic-gate { 0xa, "Intel(r) Celeron(r)" }, 15527c478bd9Sstevel@tonic-gate { 0xb, "Intel(r) Xeon(tm)" }, 15537c478bd9Sstevel@tonic-gate { 0xc, "Intel(r) Xeon(tm) MP" }, 15547c478bd9Sstevel@tonic-gate { 0xe, "Mobile Intel(r) Pentium(r) 4" }, 15555ff02082Sdmick { 0xf, "Mobile Intel(r) Celeron(r)" }, 15565ff02082Sdmick { 0x11, "Mobile Genuine Intel(r)" }, 15575ff02082Sdmick { 0x12, "Intel(r) Celeron(r) M" }, 15585ff02082Sdmick { 0x13, "Mobile Intel(r) Celeron(r)" }, 15595ff02082Sdmick { 0x14, "Intel(r) Celeron(r)" }, 15605ff02082Sdmick { 0x15, "Mobile Genuine Intel(r)" }, 15615ff02082Sdmick { 0x16, "Intel(r) Pentium(r) M" }, 15625ff02082Sdmick { 0x17, "Mobile Intel(r) Celeron(r)" } 15637c478bd9Sstevel@tonic-gate }; 15647c478bd9Sstevel@tonic-gate uint_t btblmax = sizeof (brand_tbl) / sizeof (brand_tbl[0]); 15657c478bd9Sstevel@tonic-gate uint_t sgn; 15667c478bd9Sstevel@tonic-gate 15677c478bd9Sstevel@tonic-gate sgn = (cpi->cpi_family << 8) | 15687c478bd9Sstevel@tonic-gate (cpi->cpi_model << 4) | cpi->cpi_step; 15697c478bd9Sstevel@tonic-gate 15707c478bd9Sstevel@tonic-gate for (i = 0; i < btblmax; i++) 15717c478bd9Sstevel@tonic-gate if (brand_tbl[i].bt_bid == cpi->cpi_brandid) 15727c478bd9Sstevel@tonic-gate break; 15737c478bd9Sstevel@tonic-gate if (i < btblmax) { 15747c478bd9Sstevel@tonic-gate if (sgn == 0x6b1 && cpi->cpi_brandid == 3) 15757c478bd9Sstevel@tonic-gate return ("Intel(r) Celeron(r)"); 15767c478bd9Sstevel@tonic-gate if (sgn < 0xf13 && cpi->cpi_brandid == 0xb) 15777c478bd9Sstevel@tonic-gate return ("Intel(r) Xeon(tm) MP"); 15787c478bd9Sstevel@tonic-gate if (sgn < 0xf13 && cpi->cpi_brandid == 0xe) 15797c478bd9Sstevel@tonic-gate return ("Intel(r) Xeon(tm)"); 15807c478bd9Sstevel@tonic-gate return (brand_tbl[i].bt_str); 15817c478bd9Sstevel@tonic-gate } 15827c478bd9Sstevel@tonic-gate } 15837c478bd9Sstevel@tonic-gate 15847c478bd9Sstevel@tonic-gate return (NULL); 15857c478bd9Sstevel@tonic-gate } 15867c478bd9Sstevel@tonic-gate 15877c478bd9Sstevel@tonic-gate static const char * 15887c478bd9Sstevel@tonic-gate amd_cpubrand(const struct cpuid_info *cpi) 15897c478bd9Sstevel@tonic-gate { 15907c478bd9Sstevel@tonic-gate if ((x86_feature & X86_CPUID) == 0 || 15917c478bd9Sstevel@tonic-gate cpi->cpi_maxeax < 1 || cpi->cpi_family < 5) 15927c478bd9Sstevel@tonic-gate return ("i486 compatible"); 15937c478bd9Sstevel@tonic-gate 15947c478bd9Sstevel@tonic-gate switch (cpi->cpi_family) { 15957c478bd9Sstevel@tonic-gate case 5: 15967c478bd9Sstevel@tonic-gate switch (cpi->cpi_model) { 15977c478bd9Sstevel@tonic-gate case 0: 15987c478bd9Sstevel@tonic-gate case 1: 15997c478bd9Sstevel@tonic-gate case 2: 16007c478bd9Sstevel@tonic-gate case 3: 16017c478bd9Sstevel@tonic-gate case 4: 16027c478bd9Sstevel@tonic-gate case 5: 16037c478bd9Sstevel@tonic-gate return ("AMD-K5(r)"); 16047c478bd9Sstevel@tonic-gate case 6: 16057c478bd9Sstevel@tonic-gate case 7: 16067c478bd9Sstevel@tonic-gate return ("AMD-K6(r)"); 16077c478bd9Sstevel@tonic-gate case 8: 16087c478bd9Sstevel@tonic-gate return ("AMD-K6(r)-2"); 16097c478bd9Sstevel@tonic-gate case 9: 16107c478bd9Sstevel@tonic-gate return ("AMD-K6(r)-III"); 16117c478bd9Sstevel@tonic-gate default: 16127c478bd9Sstevel@tonic-gate return ("AMD (family 5)"); 16137c478bd9Sstevel@tonic-gate } 16147c478bd9Sstevel@tonic-gate case 6: 16157c478bd9Sstevel@tonic-gate switch (cpi->cpi_model) { 16167c478bd9Sstevel@tonic-gate case 1: 16177c478bd9Sstevel@tonic-gate return ("AMD-K7(tm)"); 16187c478bd9Sstevel@tonic-gate case 0: 16197c478bd9Sstevel@tonic-gate case 2: 16207c478bd9Sstevel@tonic-gate case 4: 16217c478bd9Sstevel@tonic-gate return ("AMD Athlon(tm)"); 16227c478bd9Sstevel@tonic-gate case 3: 16237c478bd9Sstevel@tonic-gate case 7: 16247c478bd9Sstevel@tonic-gate return ("AMD Duron(tm)"); 16257c478bd9Sstevel@tonic-gate case 6: 16267c478bd9Sstevel@tonic-gate case 8: 16277c478bd9Sstevel@tonic-gate case 10: 16287c478bd9Sstevel@tonic-gate /* 16297c478bd9Sstevel@tonic-gate * Use the L2 cache size to distinguish 16307c478bd9Sstevel@tonic-gate */ 16317c478bd9Sstevel@tonic-gate return ((cpi->cpi_extd[6].cp_ecx >> 16) >= 256 ? 16327c478bd9Sstevel@tonic-gate "AMD Athlon(tm)" : "AMD Duron(tm)"); 16337c478bd9Sstevel@tonic-gate default: 16347c478bd9Sstevel@tonic-gate return ("AMD (family 6)"); 16357c478bd9Sstevel@tonic-gate } 16367c478bd9Sstevel@tonic-gate default: 16377c478bd9Sstevel@tonic-gate break; 16387c478bd9Sstevel@tonic-gate } 16397c478bd9Sstevel@tonic-gate 16407c478bd9Sstevel@tonic-gate if (cpi->cpi_family == 0xf && cpi->cpi_model == 5 && 16417c478bd9Sstevel@tonic-gate cpi->cpi_brandid != 0) { 16427c478bd9Sstevel@tonic-gate switch (BITX(cpi->cpi_brandid, 7, 5)) { 16437c478bd9Sstevel@tonic-gate case 3: 16447c478bd9Sstevel@tonic-gate return ("AMD Opteron(tm) UP 1xx"); 16457c478bd9Sstevel@tonic-gate case 4: 16467c478bd9Sstevel@tonic-gate return ("AMD Opteron(tm) DP 2xx"); 16477c478bd9Sstevel@tonic-gate case 5: 16487c478bd9Sstevel@tonic-gate return ("AMD Opteron(tm) MP 8xx"); 16497c478bd9Sstevel@tonic-gate default: 16507c478bd9Sstevel@tonic-gate return ("AMD Opteron(tm)"); 16517c478bd9Sstevel@tonic-gate } 16527c478bd9Sstevel@tonic-gate } 16537c478bd9Sstevel@tonic-gate 16547c478bd9Sstevel@tonic-gate return (NULL); 16557c478bd9Sstevel@tonic-gate } 16567c478bd9Sstevel@tonic-gate 16577c478bd9Sstevel@tonic-gate static const char * 16587c478bd9Sstevel@tonic-gate cyrix_cpubrand(struct cpuid_info *cpi, uint_t type) 16597c478bd9Sstevel@tonic-gate { 16607c478bd9Sstevel@tonic-gate if ((x86_feature & X86_CPUID) == 0 || 16617c478bd9Sstevel@tonic-gate cpi->cpi_maxeax < 1 || cpi->cpi_family < 5 || 16627c478bd9Sstevel@tonic-gate type == X86_TYPE_CYRIX_486) 16637c478bd9Sstevel@tonic-gate return ("i486 compatible"); 16647c478bd9Sstevel@tonic-gate 16657c478bd9Sstevel@tonic-gate switch (type) { 16667c478bd9Sstevel@tonic-gate case X86_TYPE_CYRIX_6x86: 16677c478bd9Sstevel@tonic-gate return ("Cyrix 6x86"); 16687c478bd9Sstevel@tonic-gate case X86_TYPE_CYRIX_6x86L: 16697c478bd9Sstevel@tonic-gate return ("Cyrix 6x86L"); 16707c478bd9Sstevel@tonic-gate case X86_TYPE_CYRIX_6x86MX: 16717c478bd9Sstevel@tonic-gate return ("Cyrix 6x86MX"); 16727c478bd9Sstevel@tonic-gate case X86_TYPE_CYRIX_GXm: 16737c478bd9Sstevel@tonic-gate return ("Cyrix GXm"); 16747c478bd9Sstevel@tonic-gate case X86_TYPE_CYRIX_MediaGX: 16757c478bd9Sstevel@tonic-gate return ("Cyrix MediaGX"); 16767c478bd9Sstevel@tonic-gate case X86_TYPE_CYRIX_MII: 16777c478bd9Sstevel@tonic-gate return ("Cyrix M2"); 16787c478bd9Sstevel@tonic-gate case X86_TYPE_VIA_CYRIX_III: 16797c478bd9Sstevel@tonic-gate return ("VIA Cyrix M3"); 16807c478bd9Sstevel@tonic-gate default: 16817c478bd9Sstevel@tonic-gate /* 16827c478bd9Sstevel@tonic-gate * Have another wild guess .. 16837c478bd9Sstevel@tonic-gate */ 16847c478bd9Sstevel@tonic-gate if (cpi->cpi_family == 4 && cpi->cpi_model == 9) 16857c478bd9Sstevel@tonic-gate return ("Cyrix 5x86"); 16867c478bd9Sstevel@tonic-gate else if (cpi->cpi_family == 5) { 16877c478bd9Sstevel@tonic-gate switch (cpi->cpi_model) { 16887c478bd9Sstevel@tonic-gate case 2: 16897c478bd9Sstevel@tonic-gate return ("Cyrix 6x86"); /* Cyrix M1 */ 16907c478bd9Sstevel@tonic-gate case 4: 16917c478bd9Sstevel@tonic-gate return ("Cyrix MediaGX"); 16927c478bd9Sstevel@tonic-gate default: 16937c478bd9Sstevel@tonic-gate break; 16947c478bd9Sstevel@tonic-gate } 16957c478bd9Sstevel@tonic-gate } else if (cpi->cpi_family == 6) { 16967c478bd9Sstevel@tonic-gate switch (cpi->cpi_model) { 16977c478bd9Sstevel@tonic-gate case 0: 16987c478bd9Sstevel@tonic-gate return ("Cyrix 6x86MX"); /* Cyrix M2? */ 16997c478bd9Sstevel@tonic-gate case 5: 17007c478bd9Sstevel@tonic-gate case 6: 17017c478bd9Sstevel@tonic-gate case 7: 17027c478bd9Sstevel@tonic-gate case 8: 17037c478bd9Sstevel@tonic-gate case 9: 17047c478bd9Sstevel@tonic-gate return ("VIA C3"); 17057c478bd9Sstevel@tonic-gate default: 17067c478bd9Sstevel@tonic-gate break; 17077c478bd9Sstevel@tonic-gate } 17087c478bd9Sstevel@tonic-gate } 17097c478bd9Sstevel@tonic-gate break; 17107c478bd9Sstevel@tonic-gate } 17117c478bd9Sstevel@tonic-gate return (NULL); 17127c478bd9Sstevel@tonic-gate } 17137c478bd9Sstevel@tonic-gate 17147c478bd9Sstevel@tonic-gate /* 17157c478bd9Sstevel@tonic-gate * This only gets called in the case that the CPU extended 17167c478bd9Sstevel@tonic-gate * feature brand string (0x80000002, 0x80000003, 0x80000004) 17177c478bd9Sstevel@tonic-gate * aren't available, or contain null bytes for some reason. 17187c478bd9Sstevel@tonic-gate */ 17197c478bd9Sstevel@tonic-gate static void 17207c478bd9Sstevel@tonic-gate fabricate_brandstr(struct cpuid_info *cpi) 17217c478bd9Sstevel@tonic-gate { 17227c478bd9Sstevel@tonic-gate const char *brand = NULL; 17237c478bd9Sstevel@tonic-gate 17247c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 17257c478bd9Sstevel@tonic-gate case X86_VENDOR_Intel: 17267c478bd9Sstevel@tonic-gate brand = intel_cpubrand(cpi); 17277c478bd9Sstevel@tonic-gate break; 17287c478bd9Sstevel@tonic-gate case X86_VENDOR_AMD: 17297c478bd9Sstevel@tonic-gate brand = amd_cpubrand(cpi); 17307c478bd9Sstevel@tonic-gate break; 17317c478bd9Sstevel@tonic-gate case X86_VENDOR_Cyrix: 17327c478bd9Sstevel@tonic-gate brand = cyrix_cpubrand(cpi, x86_type); 17337c478bd9Sstevel@tonic-gate break; 17347c478bd9Sstevel@tonic-gate case X86_VENDOR_NexGen: 17357c478bd9Sstevel@tonic-gate if (cpi->cpi_family == 5 && cpi->cpi_model == 0) 17367c478bd9Sstevel@tonic-gate brand = "NexGen Nx586"; 17377c478bd9Sstevel@tonic-gate break; 17387c478bd9Sstevel@tonic-gate case X86_VENDOR_Centaur: 17397c478bd9Sstevel@tonic-gate if (cpi->cpi_family == 5) 17407c478bd9Sstevel@tonic-gate switch (cpi->cpi_model) { 17417c478bd9Sstevel@tonic-gate case 4: 17427c478bd9Sstevel@tonic-gate brand = "Centaur C6"; 17437c478bd9Sstevel@tonic-gate break; 17447c478bd9Sstevel@tonic-gate case 8: 17457c478bd9Sstevel@tonic-gate brand = "Centaur C2"; 17467c478bd9Sstevel@tonic-gate break; 17477c478bd9Sstevel@tonic-gate case 9: 17487c478bd9Sstevel@tonic-gate brand = "Centaur C3"; 17497c478bd9Sstevel@tonic-gate break; 17507c478bd9Sstevel@tonic-gate default: 17517c478bd9Sstevel@tonic-gate break; 17527c478bd9Sstevel@tonic-gate } 17537c478bd9Sstevel@tonic-gate break; 17547c478bd9Sstevel@tonic-gate case X86_VENDOR_Rise: 17557c478bd9Sstevel@tonic-gate if (cpi->cpi_family == 5 && 17567c478bd9Sstevel@tonic-gate (cpi->cpi_model == 0 || cpi->cpi_model == 2)) 17577c478bd9Sstevel@tonic-gate brand = "Rise mP6"; 17587c478bd9Sstevel@tonic-gate break; 17597c478bd9Sstevel@tonic-gate case X86_VENDOR_SiS: 17607c478bd9Sstevel@tonic-gate if (cpi->cpi_family == 5 && cpi->cpi_model == 0) 17617c478bd9Sstevel@tonic-gate brand = "SiS 55x"; 17627c478bd9Sstevel@tonic-gate break; 17637c478bd9Sstevel@tonic-gate case X86_VENDOR_TM: 17647c478bd9Sstevel@tonic-gate if (cpi->cpi_family == 5 && cpi->cpi_model == 4) 17657c478bd9Sstevel@tonic-gate brand = "Transmeta Crusoe TM3x00 or TM5x00"; 17667c478bd9Sstevel@tonic-gate break; 17677c478bd9Sstevel@tonic-gate case X86_VENDOR_NSC: 17687c478bd9Sstevel@tonic-gate case X86_VENDOR_UMC: 17697c478bd9Sstevel@tonic-gate default: 17707c478bd9Sstevel@tonic-gate break; 17717c478bd9Sstevel@tonic-gate } 17727c478bd9Sstevel@tonic-gate if (brand) { 17737c478bd9Sstevel@tonic-gate (void) strcpy((char *)cpi->cpi_brandstr, brand); 17747c478bd9Sstevel@tonic-gate return; 17757c478bd9Sstevel@tonic-gate } 17767c478bd9Sstevel@tonic-gate 17777c478bd9Sstevel@tonic-gate /* 17787c478bd9Sstevel@tonic-gate * If all else fails ... 17797c478bd9Sstevel@tonic-gate */ 17807c478bd9Sstevel@tonic-gate (void) snprintf(cpi->cpi_brandstr, sizeof (cpi->cpi_brandstr), 17817c478bd9Sstevel@tonic-gate "%s %d.%d.%d", cpi->cpi_vendorstr, cpi->cpi_family, 17827c478bd9Sstevel@tonic-gate cpi->cpi_model, cpi->cpi_step); 17837c478bd9Sstevel@tonic-gate } 17847c478bd9Sstevel@tonic-gate 17857c478bd9Sstevel@tonic-gate /* 17867c478bd9Sstevel@tonic-gate * This routine is called just after kernel memory allocation 17877c478bd9Sstevel@tonic-gate * becomes available on cpu0, and as part of mp_startup() on 17887c478bd9Sstevel@tonic-gate * the other cpus. 17897c478bd9Sstevel@tonic-gate * 1790d129bde2Sesaxe * Fixup the brand string, and collect any information from cpuid 1791d129bde2Sesaxe * that requires dynamicically allocated storage to represent. 17927c478bd9Sstevel@tonic-gate */ 17937c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 17947c478bd9Sstevel@tonic-gate void 17957c478bd9Sstevel@tonic-gate cpuid_pass3(cpu_t *cpu) 17967c478bd9Sstevel@tonic-gate { 1797d129bde2Sesaxe int i, max, shft, level, size; 1798d129bde2Sesaxe struct cpuid_regs regs; 1799d129bde2Sesaxe struct cpuid_regs *cp; 18007c478bd9Sstevel@tonic-gate struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 18017c478bd9Sstevel@tonic-gate 18027c478bd9Sstevel@tonic-gate ASSERT(cpi->cpi_pass == 2); 18037c478bd9Sstevel@tonic-gate 1804d129bde2Sesaxe /* 1805d129bde2Sesaxe * Function 4: Deterministic cache parameters 1806d129bde2Sesaxe * 1807d129bde2Sesaxe * Take this opportunity to detect the number of threads 1808d129bde2Sesaxe * sharing the last level cache, and construct a corresponding 1809d129bde2Sesaxe * cache id. The respective cpuid_info members are initialized 1810d129bde2Sesaxe * to the default case of "no last level cache sharing". 1811d129bde2Sesaxe */ 1812d129bde2Sesaxe cpi->cpi_ncpu_shr_last_cache = 1; 1813d129bde2Sesaxe cpi->cpi_last_lvl_cacheid = cpu->cpu_id; 1814d129bde2Sesaxe 1815d129bde2Sesaxe if (cpi->cpi_maxeax >= 4 && cpi->cpi_vendor == X86_VENDOR_Intel) { 1816d129bde2Sesaxe 1817d129bde2Sesaxe /* 1818d129bde2Sesaxe * Find the # of elements (size) returned by fn 4, and along 1819d129bde2Sesaxe * the way detect last level cache sharing details. 1820d129bde2Sesaxe */ 1821d129bde2Sesaxe bzero(®s, sizeof (regs)); 1822d129bde2Sesaxe cp = ®s; 1823d129bde2Sesaxe for (i = 0, max = 0; i < CPI_FN4_ECX_MAX; i++) { 1824d129bde2Sesaxe cp->cp_eax = 4; 1825d129bde2Sesaxe cp->cp_ecx = i; 1826d129bde2Sesaxe 1827d129bde2Sesaxe (void) __cpuid_insn(cp); 1828d129bde2Sesaxe 1829d129bde2Sesaxe if (CPI_CACHE_TYPE(cp) == 0) 1830d129bde2Sesaxe break; 1831d129bde2Sesaxe level = CPI_CACHE_LVL(cp); 1832d129bde2Sesaxe if (level > max) { 1833d129bde2Sesaxe max = level; 1834d129bde2Sesaxe cpi->cpi_ncpu_shr_last_cache = 1835d129bde2Sesaxe CPI_NTHR_SHR_CACHE(cp) + 1; 1836d129bde2Sesaxe } 1837d129bde2Sesaxe } 1838d129bde2Sesaxe cpi->cpi_std_4_size = size = i; 1839d129bde2Sesaxe 1840d129bde2Sesaxe /* 1841d129bde2Sesaxe * Allocate the cpi_std_4 array. The first element 1842d129bde2Sesaxe * references the regs for fn 4, %ecx == 0, which 1843d129bde2Sesaxe * cpuid_pass2() stashed in cpi->cpi_std[4]. 1844d129bde2Sesaxe */ 1845d129bde2Sesaxe if (size > 0) { 1846d129bde2Sesaxe cpi->cpi_std_4 = 1847d129bde2Sesaxe kmem_alloc(size * sizeof (cp), KM_SLEEP); 1848d129bde2Sesaxe cpi->cpi_std_4[0] = &cpi->cpi_std[4]; 1849d129bde2Sesaxe 1850d129bde2Sesaxe /* 1851d129bde2Sesaxe * Allocate storage to hold the additional regs 1852d129bde2Sesaxe * for function 4, %ecx == 1 .. cpi_std_4_size. 1853d129bde2Sesaxe * 1854d129bde2Sesaxe * The regs for fn 4, %ecx == 0 has already 1855d129bde2Sesaxe * been allocated as indicated above. 1856d129bde2Sesaxe */ 1857d129bde2Sesaxe for (i = 1; i < size; i++) { 1858d129bde2Sesaxe cp = cpi->cpi_std_4[i] = 1859d129bde2Sesaxe kmem_zalloc(sizeof (regs), KM_SLEEP); 1860d129bde2Sesaxe cp->cp_eax = 4; 1861d129bde2Sesaxe cp->cp_ecx = i; 1862d129bde2Sesaxe 1863d129bde2Sesaxe (void) __cpuid_insn(cp); 1864d129bde2Sesaxe } 1865d129bde2Sesaxe } 1866d129bde2Sesaxe /* 1867d129bde2Sesaxe * Determine the number of bits needed to represent 1868d129bde2Sesaxe * the number of CPUs sharing the last level cache. 1869d129bde2Sesaxe * 1870d129bde2Sesaxe * Shift off that number of bits from the APIC id to 1871d129bde2Sesaxe * derive the cache id. 1872d129bde2Sesaxe */ 1873d129bde2Sesaxe shft = 0; 1874d129bde2Sesaxe for (i = 1; i < cpi->cpi_ncpu_shr_last_cache; i <<= 1) 1875d129bde2Sesaxe shft++; 1876b6917abeSmishra cpi->cpi_last_lvl_cacheid = cpi->cpi_apicid >> shft; 1877d129bde2Sesaxe } 1878d129bde2Sesaxe 1879d129bde2Sesaxe /* 1880d129bde2Sesaxe * Now fixup the brand string 1881d129bde2Sesaxe */ 18827c478bd9Sstevel@tonic-gate if ((cpi->cpi_xmaxeax & 0x80000000) == 0) { 18837c478bd9Sstevel@tonic-gate fabricate_brandstr(cpi); 1884d129bde2Sesaxe } else { 18857c478bd9Sstevel@tonic-gate 18867c478bd9Sstevel@tonic-gate /* 18877c478bd9Sstevel@tonic-gate * If we successfully extracted a brand string from the cpuid 18887c478bd9Sstevel@tonic-gate * instruction, clean it up by removing leading spaces and 18897c478bd9Sstevel@tonic-gate * similar junk. 18907c478bd9Sstevel@tonic-gate */ 18917c478bd9Sstevel@tonic-gate if (cpi->cpi_brandstr[0]) { 18927c478bd9Sstevel@tonic-gate size_t maxlen = sizeof (cpi->cpi_brandstr); 18937c478bd9Sstevel@tonic-gate char *src, *dst; 18947c478bd9Sstevel@tonic-gate 18957c478bd9Sstevel@tonic-gate dst = src = (char *)cpi->cpi_brandstr; 18967c478bd9Sstevel@tonic-gate src[maxlen - 1] = '\0'; 18977c478bd9Sstevel@tonic-gate /* 18987c478bd9Sstevel@tonic-gate * strip leading spaces 18997c478bd9Sstevel@tonic-gate */ 19007c478bd9Sstevel@tonic-gate while (*src == ' ') 19017c478bd9Sstevel@tonic-gate src++; 19027c478bd9Sstevel@tonic-gate /* 19037c478bd9Sstevel@tonic-gate * Remove any 'Genuine' or "Authentic" prefixes 19047c478bd9Sstevel@tonic-gate */ 19057c478bd9Sstevel@tonic-gate if (strncmp(src, "Genuine ", 8) == 0) 19067c478bd9Sstevel@tonic-gate src += 8; 19077c478bd9Sstevel@tonic-gate if (strncmp(src, "Authentic ", 10) == 0) 19087c478bd9Sstevel@tonic-gate src += 10; 19097c478bd9Sstevel@tonic-gate 19107c478bd9Sstevel@tonic-gate /* 19117c478bd9Sstevel@tonic-gate * Now do an in-place copy. 19127c478bd9Sstevel@tonic-gate * Map (R) to (r) and (TM) to (tm). 19137c478bd9Sstevel@tonic-gate * The era of teletypes is long gone, and there's 19147c478bd9Sstevel@tonic-gate * -really- no need to shout. 19157c478bd9Sstevel@tonic-gate */ 19167c478bd9Sstevel@tonic-gate while (*src != '\0') { 19177c478bd9Sstevel@tonic-gate if (src[0] == '(') { 19187c478bd9Sstevel@tonic-gate if (strncmp(src + 1, "R)", 2) == 0) { 19197c478bd9Sstevel@tonic-gate (void) strncpy(dst, "(r)", 3); 19207c478bd9Sstevel@tonic-gate src += 3; 19217c478bd9Sstevel@tonic-gate dst += 3; 19227c478bd9Sstevel@tonic-gate continue; 19237c478bd9Sstevel@tonic-gate } 19247c478bd9Sstevel@tonic-gate if (strncmp(src + 1, "TM)", 3) == 0) { 19257c478bd9Sstevel@tonic-gate (void) strncpy(dst, "(tm)", 4); 19267c478bd9Sstevel@tonic-gate src += 4; 19277c478bd9Sstevel@tonic-gate dst += 4; 19287c478bd9Sstevel@tonic-gate continue; 19297c478bd9Sstevel@tonic-gate } 19307c478bd9Sstevel@tonic-gate } 19317c478bd9Sstevel@tonic-gate *dst++ = *src++; 19327c478bd9Sstevel@tonic-gate } 19337c478bd9Sstevel@tonic-gate *dst = '\0'; 19347c478bd9Sstevel@tonic-gate 19357c478bd9Sstevel@tonic-gate /* 19367c478bd9Sstevel@tonic-gate * Finally, remove any trailing spaces 19377c478bd9Sstevel@tonic-gate */ 19387c478bd9Sstevel@tonic-gate while (--dst > cpi->cpi_brandstr) 19397c478bd9Sstevel@tonic-gate if (*dst == ' ') 19407c478bd9Sstevel@tonic-gate *dst = '\0'; 19417c478bd9Sstevel@tonic-gate else 19427c478bd9Sstevel@tonic-gate break; 19437c478bd9Sstevel@tonic-gate } else 19447c478bd9Sstevel@tonic-gate fabricate_brandstr(cpi); 1945d129bde2Sesaxe } 19467c478bd9Sstevel@tonic-gate cpi->cpi_pass = 3; 19477c478bd9Sstevel@tonic-gate } 19487c478bd9Sstevel@tonic-gate 19497c478bd9Sstevel@tonic-gate /* 19507c478bd9Sstevel@tonic-gate * This routine is called out of bind_hwcap() much later in the life 19517c478bd9Sstevel@tonic-gate * of the kernel (post_startup()). The job of this routine is to resolve 19527c478bd9Sstevel@tonic-gate * the hardware feature support and kernel support for those features into 19537c478bd9Sstevel@tonic-gate * what we're actually going to tell applications via the aux vector. 19547c478bd9Sstevel@tonic-gate */ 19557c478bd9Sstevel@tonic-gate uint_t 19567c478bd9Sstevel@tonic-gate cpuid_pass4(cpu_t *cpu) 19577c478bd9Sstevel@tonic-gate { 19587c478bd9Sstevel@tonic-gate struct cpuid_info *cpi; 19597c478bd9Sstevel@tonic-gate uint_t hwcap_flags = 0; 19607c478bd9Sstevel@tonic-gate 19617c478bd9Sstevel@tonic-gate if (cpu == NULL) 19627c478bd9Sstevel@tonic-gate cpu = CPU; 19637c478bd9Sstevel@tonic-gate cpi = cpu->cpu_m.mcpu_cpi; 19647c478bd9Sstevel@tonic-gate 19657c478bd9Sstevel@tonic-gate ASSERT(cpi->cpi_pass == 3); 19667c478bd9Sstevel@tonic-gate 19677c478bd9Sstevel@tonic-gate if (cpi->cpi_maxeax >= 1) { 19687c478bd9Sstevel@tonic-gate uint32_t *edx = &cpi->cpi_support[STD_EDX_FEATURES]; 19697c478bd9Sstevel@tonic-gate uint32_t *ecx = &cpi->cpi_support[STD_ECX_FEATURES]; 19707c478bd9Sstevel@tonic-gate 19717c478bd9Sstevel@tonic-gate *edx = CPI_FEATURES_EDX(cpi); 19727c478bd9Sstevel@tonic-gate *ecx = CPI_FEATURES_ECX(cpi); 19737c478bd9Sstevel@tonic-gate 19747c478bd9Sstevel@tonic-gate /* 19757c478bd9Sstevel@tonic-gate * [these require explicit kernel support] 19767c478bd9Sstevel@tonic-gate */ 19777c478bd9Sstevel@tonic-gate if ((x86_feature & X86_SEP) == 0) 19787c478bd9Sstevel@tonic-gate *edx &= ~CPUID_INTC_EDX_SEP; 19797c478bd9Sstevel@tonic-gate 19807c478bd9Sstevel@tonic-gate if ((x86_feature & X86_SSE) == 0) 19817c478bd9Sstevel@tonic-gate *edx &= ~(CPUID_INTC_EDX_FXSR|CPUID_INTC_EDX_SSE); 19827c478bd9Sstevel@tonic-gate if ((x86_feature & X86_SSE2) == 0) 19837c478bd9Sstevel@tonic-gate *edx &= ~CPUID_INTC_EDX_SSE2; 19847c478bd9Sstevel@tonic-gate 19857c478bd9Sstevel@tonic-gate if ((x86_feature & X86_HTT) == 0) 19867c478bd9Sstevel@tonic-gate *edx &= ~CPUID_INTC_EDX_HTT; 19877c478bd9Sstevel@tonic-gate 19887c478bd9Sstevel@tonic-gate if ((x86_feature & X86_SSE3) == 0) 19897c478bd9Sstevel@tonic-gate *ecx &= ~CPUID_INTC_ECX_SSE3; 19907c478bd9Sstevel@tonic-gate 1991d0f8ff6eSkk208521 if (cpi->cpi_vendor == X86_VENDOR_Intel) { 1992d0f8ff6eSkk208521 if ((x86_feature & X86_SSSE3) == 0) 1993d0f8ff6eSkk208521 *ecx &= ~CPUID_INTC_ECX_SSSE3; 1994d0f8ff6eSkk208521 if ((x86_feature & X86_SSE4_1) == 0) 1995d0f8ff6eSkk208521 *ecx &= ~CPUID_INTC_ECX_SSE4_1; 1996d0f8ff6eSkk208521 if ((x86_feature & X86_SSE4_2) == 0) 1997d0f8ff6eSkk208521 *ecx &= ~CPUID_INTC_ECX_SSE4_2; 1998d0f8ff6eSkk208521 } 1999d0f8ff6eSkk208521 20007c478bd9Sstevel@tonic-gate /* 20017c478bd9Sstevel@tonic-gate * [no explicit support required beyond x87 fp context] 20027c478bd9Sstevel@tonic-gate */ 20037c478bd9Sstevel@tonic-gate if (!fpu_exists) 20047c478bd9Sstevel@tonic-gate *edx &= ~(CPUID_INTC_EDX_FPU | CPUID_INTC_EDX_MMX); 20057c478bd9Sstevel@tonic-gate 20067c478bd9Sstevel@tonic-gate /* 20077c478bd9Sstevel@tonic-gate * Now map the supported feature vector to things that we 20087c478bd9Sstevel@tonic-gate * think userland will care about. 20097c478bd9Sstevel@tonic-gate */ 20107c478bd9Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_SEP) 20117c478bd9Sstevel@tonic-gate hwcap_flags |= AV_386_SEP; 20127c478bd9Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_SSE) 20137c478bd9Sstevel@tonic-gate hwcap_flags |= AV_386_FXSR | AV_386_SSE; 20147c478bd9Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_SSE2) 20157c478bd9Sstevel@tonic-gate hwcap_flags |= AV_386_SSE2; 20167c478bd9Sstevel@tonic-gate if (*ecx & CPUID_INTC_ECX_SSE3) 20177c478bd9Sstevel@tonic-gate hwcap_flags |= AV_386_SSE3; 2018d0f8ff6eSkk208521 if (cpi->cpi_vendor == X86_VENDOR_Intel) { 2019d0f8ff6eSkk208521 if (*ecx & CPUID_INTC_ECX_SSSE3) 2020d0f8ff6eSkk208521 hwcap_flags |= AV_386_SSSE3; 2021d0f8ff6eSkk208521 if (*ecx & CPUID_INTC_ECX_SSE4_1) 2022d0f8ff6eSkk208521 hwcap_flags |= AV_386_SSE4_1; 2023d0f8ff6eSkk208521 if (*ecx & CPUID_INTC_ECX_SSE4_2) 2024d0f8ff6eSkk208521 hwcap_flags |= AV_386_SSE4_2; 2025d0f8ff6eSkk208521 } 2026f8801251Skk208521 if (*ecx & CPUID_INTC_ECX_POPCNT) 2027f8801251Skk208521 hwcap_flags |= AV_386_POPCNT; 20287c478bd9Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_FPU) 20297c478bd9Sstevel@tonic-gate hwcap_flags |= AV_386_FPU; 20307c478bd9Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_MMX) 20317c478bd9Sstevel@tonic-gate hwcap_flags |= AV_386_MMX; 20327c478bd9Sstevel@tonic-gate 20337c478bd9Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_TSC) 20347c478bd9Sstevel@tonic-gate hwcap_flags |= AV_386_TSC; 20357c478bd9Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_CX8) 20367c478bd9Sstevel@tonic-gate hwcap_flags |= AV_386_CX8; 20377c478bd9Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_CMOV) 20387c478bd9Sstevel@tonic-gate hwcap_flags |= AV_386_CMOV; 20397c478bd9Sstevel@tonic-gate if (*ecx & CPUID_INTC_ECX_MON) 20407c478bd9Sstevel@tonic-gate hwcap_flags |= AV_386_MON; 20417c478bd9Sstevel@tonic-gate if (*ecx & CPUID_INTC_ECX_CX16) 20427c478bd9Sstevel@tonic-gate hwcap_flags |= AV_386_CX16; 20437c478bd9Sstevel@tonic-gate } 20447c478bd9Sstevel@tonic-gate 20458949bcd6Sandrei if (x86_feature & X86_HTT) 20467c478bd9Sstevel@tonic-gate hwcap_flags |= AV_386_PAUSE; 20477c478bd9Sstevel@tonic-gate 20487c478bd9Sstevel@tonic-gate if (cpi->cpi_xmaxeax < 0x80000001) 20497c478bd9Sstevel@tonic-gate goto pass4_done; 20507c478bd9Sstevel@tonic-gate 20517c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 20528949bcd6Sandrei struct cpuid_regs cp; 2053ae115bc7Smrj uint32_t *edx, *ecx; 20547c478bd9Sstevel@tonic-gate 2055ae115bc7Smrj case X86_VENDOR_Intel: 2056ae115bc7Smrj /* 2057ae115bc7Smrj * Seems like Intel duplicated what we necessary 2058ae115bc7Smrj * here to make the initial crop of 64-bit OS's work. 2059ae115bc7Smrj * Hopefully, those are the only "extended" bits 2060ae115bc7Smrj * they'll add. 2061ae115bc7Smrj */ 2062ae115bc7Smrj /*FALLTHROUGH*/ 2063ae115bc7Smrj 20647c478bd9Sstevel@tonic-gate case X86_VENDOR_AMD: 20657c478bd9Sstevel@tonic-gate edx = &cpi->cpi_support[AMD_EDX_FEATURES]; 2066ae115bc7Smrj ecx = &cpi->cpi_support[AMD_ECX_FEATURES]; 20677c478bd9Sstevel@tonic-gate 20687c478bd9Sstevel@tonic-gate *edx = CPI_FEATURES_XTD_EDX(cpi); 2069ae115bc7Smrj *ecx = CPI_FEATURES_XTD_ECX(cpi); 2070ae115bc7Smrj 2071ae115bc7Smrj /* 2072ae115bc7Smrj * [these features require explicit kernel support] 2073ae115bc7Smrj */ 2074ae115bc7Smrj switch (cpi->cpi_vendor) { 2075ae115bc7Smrj case X86_VENDOR_Intel: 2076d36ea5d8Ssudheer if ((x86_feature & X86_TSCP) == 0) 2077d36ea5d8Ssudheer *edx &= ~CPUID_AMD_EDX_TSCP; 2078ae115bc7Smrj break; 2079ae115bc7Smrj 2080ae115bc7Smrj case X86_VENDOR_AMD: 2081ae115bc7Smrj if ((x86_feature & X86_TSCP) == 0) 2082ae115bc7Smrj *edx &= ~CPUID_AMD_EDX_TSCP; 2083f8801251Skk208521 if ((x86_feature & X86_SSE4A) == 0) 2084f8801251Skk208521 *ecx &= ~CPUID_AMD_ECX_SSE4A; 2085ae115bc7Smrj break; 2086ae115bc7Smrj 2087ae115bc7Smrj default: 2088ae115bc7Smrj break; 2089ae115bc7Smrj } 20907c478bd9Sstevel@tonic-gate 20917c478bd9Sstevel@tonic-gate /* 20927c478bd9Sstevel@tonic-gate * [no explicit support required beyond 20937c478bd9Sstevel@tonic-gate * x87 fp context and exception handlers] 20947c478bd9Sstevel@tonic-gate */ 20957c478bd9Sstevel@tonic-gate if (!fpu_exists) 20967c478bd9Sstevel@tonic-gate *edx &= ~(CPUID_AMD_EDX_MMXamd | 20977c478bd9Sstevel@tonic-gate CPUID_AMD_EDX_3DNow | CPUID_AMD_EDX_3DNowx); 20987c478bd9Sstevel@tonic-gate 20997c478bd9Sstevel@tonic-gate if ((x86_feature & X86_NX) == 0) 21007c478bd9Sstevel@tonic-gate *edx &= ~CPUID_AMD_EDX_NX; 2101ae115bc7Smrj #if !defined(__amd64) 21027c478bd9Sstevel@tonic-gate *edx &= ~CPUID_AMD_EDX_LM; 21037c478bd9Sstevel@tonic-gate #endif 21047c478bd9Sstevel@tonic-gate /* 21057c478bd9Sstevel@tonic-gate * Now map the supported feature vector to 21067c478bd9Sstevel@tonic-gate * things that we think userland will care about. 21077c478bd9Sstevel@tonic-gate */ 2108ae115bc7Smrj #if defined(__amd64) 21097c478bd9Sstevel@tonic-gate if (*edx & CPUID_AMD_EDX_SYSC) 21107c478bd9Sstevel@tonic-gate hwcap_flags |= AV_386_AMD_SYSC; 2111ae115bc7Smrj #endif 21127c478bd9Sstevel@tonic-gate if (*edx & CPUID_AMD_EDX_MMXamd) 21137c478bd9Sstevel@tonic-gate hwcap_flags |= AV_386_AMD_MMX; 21147c478bd9Sstevel@tonic-gate if (*edx & CPUID_AMD_EDX_3DNow) 21157c478bd9Sstevel@tonic-gate hwcap_flags |= AV_386_AMD_3DNow; 21167c478bd9Sstevel@tonic-gate if (*edx & CPUID_AMD_EDX_3DNowx) 21177c478bd9Sstevel@tonic-gate hwcap_flags |= AV_386_AMD_3DNowx; 2118ae115bc7Smrj 2119ae115bc7Smrj switch (cpi->cpi_vendor) { 2120ae115bc7Smrj case X86_VENDOR_AMD: 2121ae115bc7Smrj if (*edx & CPUID_AMD_EDX_TSCP) 2122ae115bc7Smrj hwcap_flags |= AV_386_TSCP; 2123ae115bc7Smrj if (*ecx & CPUID_AMD_ECX_AHF64) 2124ae115bc7Smrj hwcap_flags |= AV_386_AHF; 2125f8801251Skk208521 if (*ecx & CPUID_AMD_ECX_SSE4A) 2126f8801251Skk208521 hwcap_flags |= AV_386_AMD_SSE4A; 2127f8801251Skk208521 if (*ecx & CPUID_AMD_ECX_LZCNT) 2128f8801251Skk208521 hwcap_flags |= AV_386_AMD_LZCNT; 2129ae115bc7Smrj break; 2130ae115bc7Smrj 2131ae115bc7Smrj case X86_VENDOR_Intel: 2132d36ea5d8Ssudheer if (*edx & CPUID_AMD_EDX_TSCP) 2133d36ea5d8Ssudheer hwcap_flags |= AV_386_TSCP; 2134ae115bc7Smrj /* 2135ae115bc7Smrj * Aarrgh. 2136ae115bc7Smrj * Intel uses a different bit in the same word. 2137ae115bc7Smrj */ 2138ae115bc7Smrj if (*ecx & CPUID_INTC_ECX_AHF64) 2139ae115bc7Smrj hwcap_flags |= AV_386_AHF; 2140ae115bc7Smrj break; 2141ae115bc7Smrj 2142ae115bc7Smrj default: 2143ae115bc7Smrj break; 2144ae115bc7Smrj } 21457c478bd9Sstevel@tonic-gate break; 21467c478bd9Sstevel@tonic-gate 21477c478bd9Sstevel@tonic-gate case X86_VENDOR_TM: 21488949bcd6Sandrei cp.cp_eax = 0x80860001; 21498949bcd6Sandrei (void) __cpuid_insn(&cp); 21508949bcd6Sandrei cpi->cpi_support[TM_EDX_FEATURES] = cp.cp_edx; 21517c478bd9Sstevel@tonic-gate break; 21527c478bd9Sstevel@tonic-gate 21537c478bd9Sstevel@tonic-gate default: 21547c478bd9Sstevel@tonic-gate break; 21557c478bd9Sstevel@tonic-gate } 21567c478bd9Sstevel@tonic-gate 21577c478bd9Sstevel@tonic-gate pass4_done: 21587c478bd9Sstevel@tonic-gate cpi->cpi_pass = 4; 21597c478bd9Sstevel@tonic-gate return (hwcap_flags); 21607c478bd9Sstevel@tonic-gate } 21617c478bd9Sstevel@tonic-gate 21627c478bd9Sstevel@tonic-gate 21637c478bd9Sstevel@tonic-gate /* 21647c478bd9Sstevel@tonic-gate * Simulate the cpuid instruction using the data we previously 21657c478bd9Sstevel@tonic-gate * captured about this CPU. We try our best to return the truth 21667c478bd9Sstevel@tonic-gate * about the hardware, independently of kernel support. 21677c478bd9Sstevel@tonic-gate */ 21687c478bd9Sstevel@tonic-gate uint32_t 21698949bcd6Sandrei cpuid_insn(cpu_t *cpu, struct cpuid_regs *cp) 21707c478bd9Sstevel@tonic-gate { 21717c478bd9Sstevel@tonic-gate struct cpuid_info *cpi; 21728949bcd6Sandrei struct cpuid_regs *xcp; 21737c478bd9Sstevel@tonic-gate 21747c478bd9Sstevel@tonic-gate if (cpu == NULL) 21757c478bd9Sstevel@tonic-gate cpu = CPU; 21767c478bd9Sstevel@tonic-gate cpi = cpu->cpu_m.mcpu_cpi; 21777c478bd9Sstevel@tonic-gate 21787c478bd9Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 3)); 21797c478bd9Sstevel@tonic-gate 21807c478bd9Sstevel@tonic-gate /* 21817c478bd9Sstevel@tonic-gate * CPUID data is cached in two separate places: cpi_std for standard 21827c478bd9Sstevel@tonic-gate * CPUID functions, and cpi_extd for extended CPUID functions. 21837c478bd9Sstevel@tonic-gate */ 21848949bcd6Sandrei if (cp->cp_eax <= cpi->cpi_maxeax && cp->cp_eax < NMAX_CPI_STD) 21858949bcd6Sandrei xcp = &cpi->cpi_std[cp->cp_eax]; 21868949bcd6Sandrei else if (cp->cp_eax >= 0x80000000 && cp->cp_eax <= cpi->cpi_xmaxeax && 21878949bcd6Sandrei cp->cp_eax < 0x80000000 + NMAX_CPI_EXTD) 21888949bcd6Sandrei xcp = &cpi->cpi_extd[cp->cp_eax - 0x80000000]; 21897c478bd9Sstevel@tonic-gate else 21907c478bd9Sstevel@tonic-gate /* 21917c478bd9Sstevel@tonic-gate * The caller is asking for data from an input parameter which 21927c478bd9Sstevel@tonic-gate * the kernel has not cached. In this case we go fetch from 21937c478bd9Sstevel@tonic-gate * the hardware and return the data directly to the user. 21947c478bd9Sstevel@tonic-gate */ 21958949bcd6Sandrei return (__cpuid_insn(cp)); 21968949bcd6Sandrei 21978949bcd6Sandrei cp->cp_eax = xcp->cp_eax; 21988949bcd6Sandrei cp->cp_ebx = xcp->cp_ebx; 21998949bcd6Sandrei cp->cp_ecx = xcp->cp_ecx; 22008949bcd6Sandrei cp->cp_edx = xcp->cp_edx; 22017c478bd9Sstevel@tonic-gate return (cp->cp_eax); 22027c478bd9Sstevel@tonic-gate } 22037c478bd9Sstevel@tonic-gate 22047c478bd9Sstevel@tonic-gate int 22057c478bd9Sstevel@tonic-gate cpuid_checkpass(cpu_t *cpu, int pass) 22067c478bd9Sstevel@tonic-gate { 22077c478bd9Sstevel@tonic-gate return (cpu != NULL && cpu->cpu_m.mcpu_cpi != NULL && 22087c478bd9Sstevel@tonic-gate cpu->cpu_m.mcpu_cpi->cpi_pass >= pass); 22097c478bd9Sstevel@tonic-gate } 22107c478bd9Sstevel@tonic-gate 22117c478bd9Sstevel@tonic-gate int 22127c478bd9Sstevel@tonic-gate cpuid_getbrandstr(cpu_t *cpu, char *s, size_t n) 22137c478bd9Sstevel@tonic-gate { 22147c478bd9Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 3)); 22157c478bd9Sstevel@tonic-gate 22167c478bd9Sstevel@tonic-gate return (snprintf(s, n, "%s", cpu->cpu_m.mcpu_cpi->cpi_brandstr)); 22177c478bd9Sstevel@tonic-gate } 22187c478bd9Sstevel@tonic-gate 22197c478bd9Sstevel@tonic-gate int 22208949bcd6Sandrei cpuid_is_cmt(cpu_t *cpu) 22217c478bd9Sstevel@tonic-gate { 22227c478bd9Sstevel@tonic-gate if (cpu == NULL) 22237c478bd9Sstevel@tonic-gate cpu = CPU; 22247c478bd9Sstevel@tonic-gate 22257c478bd9Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 22267c478bd9Sstevel@tonic-gate 22277c478bd9Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_chipid >= 0); 22287c478bd9Sstevel@tonic-gate } 22297c478bd9Sstevel@tonic-gate 22307c478bd9Sstevel@tonic-gate /* 22317c478bd9Sstevel@tonic-gate * AMD and Intel both implement the 64-bit variant of the syscall 22327c478bd9Sstevel@tonic-gate * instruction (syscallq), so if there's -any- support for syscall, 22337c478bd9Sstevel@tonic-gate * cpuid currently says "yes, we support this". 22347c478bd9Sstevel@tonic-gate * 22357c478bd9Sstevel@tonic-gate * However, Intel decided to -not- implement the 32-bit variant of the 22367c478bd9Sstevel@tonic-gate * syscall instruction, so we provide a predicate to allow our caller 22377c478bd9Sstevel@tonic-gate * to test that subtlety here. 2238843e1988Sjohnlev * 2239843e1988Sjohnlev * XXPV Currently, 32-bit syscall instructions don't work via the hypervisor, 2240843e1988Sjohnlev * even in the case where the hardware would in fact support it. 22417c478bd9Sstevel@tonic-gate */ 22427c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 22437c478bd9Sstevel@tonic-gate int 22447c478bd9Sstevel@tonic-gate cpuid_syscall32_insn(cpu_t *cpu) 22457c478bd9Sstevel@tonic-gate { 22467c478bd9Sstevel@tonic-gate ASSERT(cpuid_checkpass((cpu == NULL ? CPU : cpu), 1)); 22477c478bd9Sstevel@tonic-gate 2248843e1988Sjohnlev #if !defined(__xpv) 2249ae115bc7Smrj if (cpu == NULL) 2250ae115bc7Smrj cpu = CPU; 2251ae115bc7Smrj 2252ae115bc7Smrj /*CSTYLED*/ 2253ae115bc7Smrj { 2254ae115bc7Smrj struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 2255ae115bc7Smrj 2256ae115bc7Smrj if (cpi->cpi_vendor == X86_VENDOR_AMD && 2257ae115bc7Smrj cpi->cpi_xmaxeax >= 0x80000001 && 2258ae115bc7Smrj (CPI_FEATURES_XTD_EDX(cpi) & CPUID_AMD_EDX_SYSC)) 2259ae115bc7Smrj return (1); 2260ae115bc7Smrj } 2261843e1988Sjohnlev #endif 22627c478bd9Sstevel@tonic-gate return (0); 22637c478bd9Sstevel@tonic-gate } 22647c478bd9Sstevel@tonic-gate 22657c478bd9Sstevel@tonic-gate int 22667c478bd9Sstevel@tonic-gate cpuid_getidstr(cpu_t *cpu, char *s, size_t n) 22677c478bd9Sstevel@tonic-gate { 22687c478bd9Sstevel@tonic-gate struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 22697c478bd9Sstevel@tonic-gate 22707c478bd9Sstevel@tonic-gate static const char fmt[] = 2271ecfa43a5Sdmick "x86 (%s %X family %d model %d step %d clock %d MHz)"; 22727c478bd9Sstevel@tonic-gate static const char fmt_ht[] = 2273ecfa43a5Sdmick "x86 (chipid 0x%x %s %X family %d model %d step %d clock %d MHz)"; 22747c478bd9Sstevel@tonic-gate 22757c478bd9Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 22767c478bd9Sstevel@tonic-gate 22778949bcd6Sandrei if (cpuid_is_cmt(cpu)) 22787c478bd9Sstevel@tonic-gate return (snprintf(s, n, fmt_ht, cpi->cpi_chipid, 2279ecfa43a5Sdmick cpi->cpi_vendorstr, cpi->cpi_std[1].cp_eax, 2280ecfa43a5Sdmick cpi->cpi_family, cpi->cpi_model, 22817c478bd9Sstevel@tonic-gate cpi->cpi_step, cpu->cpu_type_info.pi_clock)); 22827c478bd9Sstevel@tonic-gate return (snprintf(s, n, fmt, 2283ecfa43a5Sdmick cpi->cpi_vendorstr, cpi->cpi_std[1].cp_eax, 2284ecfa43a5Sdmick cpi->cpi_family, cpi->cpi_model, 22857c478bd9Sstevel@tonic-gate cpi->cpi_step, cpu->cpu_type_info.pi_clock)); 22867c478bd9Sstevel@tonic-gate } 22877c478bd9Sstevel@tonic-gate 22887c478bd9Sstevel@tonic-gate const char * 22897c478bd9Sstevel@tonic-gate cpuid_getvendorstr(cpu_t *cpu) 22907c478bd9Sstevel@tonic-gate { 22917c478bd9Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 22927c478bd9Sstevel@tonic-gate return ((const char *)cpu->cpu_m.mcpu_cpi->cpi_vendorstr); 22937c478bd9Sstevel@tonic-gate } 22947c478bd9Sstevel@tonic-gate 22957c478bd9Sstevel@tonic-gate uint_t 22967c478bd9Sstevel@tonic-gate cpuid_getvendor(cpu_t *cpu) 22977c478bd9Sstevel@tonic-gate { 22987c478bd9Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 22997c478bd9Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_vendor); 23007c478bd9Sstevel@tonic-gate } 23017c478bd9Sstevel@tonic-gate 23027c478bd9Sstevel@tonic-gate uint_t 23037c478bd9Sstevel@tonic-gate cpuid_getfamily(cpu_t *cpu) 23047c478bd9Sstevel@tonic-gate { 23057c478bd9Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 23067c478bd9Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_family); 23077c478bd9Sstevel@tonic-gate } 23087c478bd9Sstevel@tonic-gate 23097c478bd9Sstevel@tonic-gate uint_t 23107c478bd9Sstevel@tonic-gate cpuid_getmodel(cpu_t *cpu) 23117c478bd9Sstevel@tonic-gate { 23127c478bd9Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 23137c478bd9Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_model); 23147c478bd9Sstevel@tonic-gate } 23157c478bd9Sstevel@tonic-gate 23167c478bd9Sstevel@tonic-gate uint_t 23177c478bd9Sstevel@tonic-gate cpuid_get_ncpu_per_chip(cpu_t *cpu) 23187c478bd9Sstevel@tonic-gate { 23197c478bd9Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 23207c478bd9Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_ncpu_per_chip); 23217c478bd9Sstevel@tonic-gate } 23227c478bd9Sstevel@tonic-gate 23237c478bd9Sstevel@tonic-gate uint_t 23248949bcd6Sandrei cpuid_get_ncore_per_chip(cpu_t *cpu) 23258949bcd6Sandrei { 23268949bcd6Sandrei ASSERT(cpuid_checkpass(cpu, 1)); 23278949bcd6Sandrei return (cpu->cpu_m.mcpu_cpi->cpi_ncore_per_chip); 23288949bcd6Sandrei } 23298949bcd6Sandrei 23308949bcd6Sandrei uint_t 2331d129bde2Sesaxe cpuid_get_ncpu_sharing_last_cache(cpu_t *cpu) 2332d129bde2Sesaxe { 2333d129bde2Sesaxe ASSERT(cpuid_checkpass(cpu, 2)); 2334d129bde2Sesaxe return (cpu->cpu_m.mcpu_cpi->cpi_ncpu_shr_last_cache); 2335d129bde2Sesaxe } 2336d129bde2Sesaxe 2337d129bde2Sesaxe id_t 2338d129bde2Sesaxe cpuid_get_last_lvl_cacheid(cpu_t *cpu) 2339d129bde2Sesaxe { 2340d129bde2Sesaxe ASSERT(cpuid_checkpass(cpu, 2)); 2341d129bde2Sesaxe return (cpu->cpu_m.mcpu_cpi->cpi_last_lvl_cacheid); 2342d129bde2Sesaxe } 2343d129bde2Sesaxe 2344d129bde2Sesaxe uint_t 23457c478bd9Sstevel@tonic-gate cpuid_getstep(cpu_t *cpu) 23467c478bd9Sstevel@tonic-gate { 23477c478bd9Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 23487c478bd9Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_step); 23497c478bd9Sstevel@tonic-gate } 23507c478bd9Sstevel@tonic-gate 23512449e17fSsherrym uint_t 23522449e17fSsherrym cpuid_getsig(struct cpu *cpu) 23532449e17fSsherrym { 23542449e17fSsherrym ASSERT(cpuid_checkpass(cpu, 1)); 23552449e17fSsherrym return (cpu->cpu_m.mcpu_cpi->cpi_std[1].cp_eax); 23562449e17fSsherrym } 23572449e17fSsherrym 23588a40a695Sgavinm uint32_t 23598a40a695Sgavinm cpuid_getchiprev(struct cpu *cpu) 23608a40a695Sgavinm { 23618a40a695Sgavinm ASSERT(cpuid_checkpass(cpu, 1)); 23628a40a695Sgavinm return (cpu->cpu_m.mcpu_cpi->cpi_chiprev); 23638a40a695Sgavinm } 23648a40a695Sgavinm 23658a40a695Sgavinm const char * 23668a40a695Sgavinm cpuid_getchiprevstr(struct cpu *cpu) 23678a40a695Sgavinm { 23688a40a695Sgavinm ASSERT(cpuid_checkpass(cpu, 1)); 23698a40a695Sgavinm return (cpu->cpu_m.mcpu_cpi->cpi_chiprevstr); 23708a40a695Sgavinm } 23718a40a695Sgavinm 23728a40a695Sgavinm uint32_t 23738a40a695Sgavinm cpuid_getsockettype(struct cpu *cpu) 23748a40a695Sgavinm { 23758a40a695Sgavinm ASSERT(cpuid_checkpass(cpu, 1)); 23768a40a695Sgavinm return (cpu->cpu_m.mcpu_cpi->cpi_socket); 23778a40a695Sgavinm } 23788a40a695Sgavinm 2379fb2f18f8Sesaxe int 2380fb2f18f8Sesaxe cpuid_get_chipid(cpu_t *cpu) 23817c478bd9Sstevel@tonic-gate { 23827c478bd9Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 23837c478bd9Sstevel@tonic-gate 23848949bcd6Sandrei if (cpuid_is_cmt(cpu)) 23857c478bd9Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_chipid); 23867c478bd9Sstevel@tonic-gate return (cpu->cpu_id); 23877c478bd9Sstevel@tonic-gate } 23887c478bd9Sstevel@tonic-gate 23898949bcd6Sandrei id_t 2390fb2f18f8Sesaxe cpuid_get_coreid(cpu_t *cpu) 23918949bcd6Sandrei { 23928949bcd6Sandrei ASSERT(cpuid_checkpass(cpu, 1)); 23938949bcd6Sandrei return (cpu->cpu_m.mcpu_cpi->cpi_coreid); 23948949bcd6Sandrei } 23958949bcd6Sandrei 23967c478bd9Sstevel@tonic-gate int 239710569901Sgavinm cpuid_get_pkgcoreid(cpu_t *cpu) 239810569901Sgavinm { 239910569901Sgavinm ASSERT(cpuid_checkpass(cpu, 1)); 240010569901Sgavinm return (cpu->cpu_m.mcpu_cpi->cpi_pkgcoreid); 240110569901Sgavinm } 240210569901Sgavinm 240310569901Sgavinm int 2404fb2f18f8Sesaxe cpuid_get_clogid(cpu_t *cpu) 24057c478bd9Sstevel@tonic-gate { 24067c478bd9Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 24077c478bd9Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_clogid); 24087c478bd9Sstevel@tonic-gate } 24097c478bd9Sstevel@tonic-gate 24107c478bd9Sstevel@tonic-gate void 24117c478bd9Sstevel@tonic-gate cpuid_get_addrsize(cpu_t *cpu, uint_t *pabits, uint_t *vabits) 24127c478bd9Sstevel@tonic-gate { 24137c478bd9Sstevel@tonic-gate struct cpuid_info *cpi; 24147c478bd9Sstevel@tonic-gate 24157c478bd9Sstevel@tonic-gate if (cpu == NULL) 24167c478bd9Sstevel@tonic-gate cpu = CPU; 24177c478bd9Sstevel@tonic-gate cpi = cpu->cpu_m.mcpu_cpi; 24187c478bd9Sstevel@tonic-gate 24197c478bd9Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 24207c478bd9Sstevel@tonic-gate 24217c478bd9Sstevel@tonic-gate if (pabits) 24227c478bd9Sstevel@tonic-gate *pabits = cpi->cpi_pabits; 24237c478bd9Sstevel@tonic-gate if (vabits) 24247c478bd9Sstevel@tonic-gate *vabits = cpi->cpi_vabits; 24257c478bd9Sstevel@tonic-gate } 24267c478bd9Sstevel@tonic-gate 24277c478bd9Sstevel@tonic-gate /* 24287c478bd9Sstevel@tonic-gate * Returns the number of data TLB entries for a corresponding 24297c478bd9Sstevel@tonic-gate * pagesize. If it can't be computed, or isn't known, the 24307c478bd9Sstevel@tonic-gate * routine returns zero. If you ask about an architecturally 24317c478bd9Sstevel@tonic-gate * impossible pagesize, the routine will panic (so that the 24327c478bd9Sstevel@tonic-gate * hat implementor knows that things are inconsistent.) 24337c478bd9Sstevel@tonic-gate */ 24347c478bd9Sstevel@tonic-gate uint_t 24357c478bd9Sstevel@tonic-gate cpuid_get_dtlb_nent(cpu_t *cpu, size_t pagesize) 24367c478bd9Sstevel@tonic-gate { 24377c478bd9Sstevel@tonic-gate struct cpuid_info *cpi; 24387c478bd9Sstevel@tonic-gate uint_t dtlb_nent = 0; 24397c478bd9Sstevel@tonic-gate 24407c478bd9Sstevel@tonic-gate if (cpu == NULL) 24417c478bd9Sstevel@tonic-gate cpu = CPU; 24427c478bd9Sstevel@tonic-gate cpi = cpu->cpu_m.mcpu_cpi; 24437c478bd9Sstevel@tonic-gate 24447c478bd9Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 24457c478bd9Sstevel@tonic-gate 24467c478bd9Sstevel@tonic-gate /* 24477c478bd9Sstevel@tonic-gate * Check the L2 TLB info 24487c478bd9Sstevel@tonic-gate */ 24497c478bd9Sstevel@tonic-gate if (cpi->cpi_xmaxeax >= 0x80000006) { 24508949bcd6Sandrei struct cpuid_regs *cp = &cpi->cpi_extd[6]; 24517c478bd9Sstevel@tonic-gate 24527c478bd9Sstevel@tonic-gate switch (pagesize) { 24537c478bd9Sstevel@tonic-gate 24547c478bd9Sstevel@tonic-gate case 4 * 1024: 24557c478bd9Sstevel@tonic-gate /* 24567c478bd9Sstevel@tonic-gate * All zero in the top 16 bits of the register 24577c478bd9Sstevel@tonic-gate * indicates a unified TLB. Size is in low 16 bits. 24587c478bd9Sstevel@tonic-gate */ 24597c478bd9Sstevel@tonic-gate if ((cp->cp_ebx & 0xffff0000) == 0) 24607c478bd9Sstevel@tonic-gate dtlb_nent = cp->cp_ebx & 0x0000ffff; 24617c478bd9Sstevel@tonic-gate else 24627c478bd9Sstevel@tonic-gate dtlb_nent = BITX(cp->cp_ebx, 27, 16); 24637c478bd9Sstevel@tonic-gate break; 24647c478bd9Sstevel@tonic-gate 24657c478bd9Sstevel@tonic-gate case 2 * 1024 * 1024: 24667c478bd9Sstevel@tonic-gate if ((cp->cp_eax & 0xffff0000) == 0) 24677c478bd9Sstevel@tonic-gate dtlb_nent = cp->cp_eax & 0x0000ffff; 24687c478bd9Sstevel@tonic-gate else 24697c478bd9Sstevel@tonic-gate dtlb_nent = BITX(cp->cp_eax, 27, 16); 24707c478bd9Sstevel@tonic-gate break; 24717c478bd9Sstevel@tonic-gate 24727c478bd9Sstevel@tonic-gate default: 24737c478bd9Sstevel@tonic-gate panic("unknown L2 pagesize"); 24747c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 24757c478bd9Sstevel@tonic-gate } 24767c478bd9Sstevel@tonic-gate } 24777c478bd9Sstevel@tonic-gate 24787c478bd9Sstevel@tonic-gate if (dtlb_nent != 0) 24797c478bd9Sstevel@tonic-gate return (dtlb_nent); 24807c478bd9Sstevel@tonic-gate 24817c478bd9Sstevel@tonic-gate /* 24827c478bd9Sstevel@tonic-gate * No L2 TLB support for this size, try L1. 24837c478bd9Sstevel@tonic-gate */ 24847c478bd9Sstevel@tonic-gate if (cpi->cpi_xmaxeax >= 0x80000005) { 24858949bcd6Sandrei struct cpuid_regs *cp = &cpi->cpi_extd[5]; 24867c478bd9Sstevel@tonic-gate 24877c478bd9Sstevel@tonic-gate switch (pagesize) { 24887c478bd9Sstevel@tonic-gate case 4 * 1024: 24897c478bd9Sstevel@tonic-gate dtlb_nent = BITX(cp->cp_ebx, 23, 16); 24907c478bd9Sstevel@tonic-gate break; 24917c478bd9Sstevel@tonic-gate case 2 * 1024 * 1024: 24927c478bd9Sstevel@tonic-gate dtlb_nent = BITX(cp->cp_eax, 23, 16); 24937c478bd9Sstevel@tonic-gate break; 24947c478bd9Sstevel@tonic-gate default: 24957c478bd9Sstevel@tonic-gate panic("unknown L1 d-TLB pagesize"); 24967c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 24977c478bd9Sstevel@tonic-gate } 24987c478bd9Sstevel@tonic-gate } 24997c478bd9Sstevel@tonic-gate 25007c478bd9Sstevel@tonic-gate return (dtlb_nent); 25017c478bd9Sstevel@tonic-gate } 25027c478bd9Sstevel@tonic-gate 25037c478bd9Sstevel@tonic-gate /* 25047c478bd9Sstevel@tonic-gate * Return 0 if the erratum is not present or not applicable, positive 25057c478bd9Sstevel@tonic-gate * if it is, and negative if the status of the erratum is unknown. 25067c478bd9Sstevel@tonic-gate * 25077c478bd9Sstevel@tonic-gate * See "Revision Guide for AMD Athlon(tm) 64 and AMD Opteron(tm) 25082201b277Skucharsk * Processors" #25759, Rev 3.57, August 2005 25097c478bd9Sstevel@tonic-gate */ 25107c478bd9Sstevel@tonic-gate int 25117c478bd9Sstevel@tonic-gate cpuid_opteron_erratum(cpu_t *cpu, uint_t erratum) 25127c478bd9Sstevel@tonic-gate { 25137c478bd9Sstevel@tonic-gate struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 25148949bcd6Sandrei uint_t eax; 25157c478bd9Sstevel@tonic-gate 2516ea99987eSsethg /* 2517ea99987eSsethg * Bail out if this CPU isn't an AMD CPU, or if it's 2518ea99987eSsethg * a legacy (32-bit) AMD CPU. 2519ea99987eSsethg */ 2520ea99987eSsethg if (cpi->cpi_vendor != X86_VENDOR_AMD || 2521875b116eSkchow cpi->cpi_family == 4 || cpi->cpi_family == 5 || 2522875b116eSkchow cpi->cpi_family == 6) 25238a40a695Sgavinm 25247c478bd9Sstevel@tonic-gate return (0); 25257c478bd9Sstevel@tonic-gate 25267c478bd9Sstevel@tonic-gate eax = cpi->cpi_std[1].cp_eax; 25277c478bd9Sstevel@tonic-gate 25287c478bd9Sstevel@tonic-gate #define SH_B0(eax) (eax == 0xf40 || eax == 0xf50) 25297c478bd9Sstevel@tonic-gate #define SH_B3(eax) (eax == 0xf51) 2530ee88d2b9Skchow #define B(eax) (SH_B0(eax) || SH_B3(eax)) 25317c478bd9Sstevel@tonic-gate 25327c478bd9Sstevel@tonic-gate #define SH_C0(eax) (eax == 0xf48 || eax == 0xf58) 25337c478bd9Sstevel@tonic-gate 25347c478bd9Sstevel@tonic-gate #define SH_CG(eax) (eax == 0xf4a || eax == 0xf5a || eax == 0xf7a) 25357c478bd9Sstevel@tonic-gate #define DH_CG(eax) (eax == 0xfc0 || eax == 0xfe0 || eax == 0xff0) 25367c478bd9Sstevel@tonic-gate #define CH_CG(eax) (eax == 0xf82 || eax == 0xfb2) 2537ee88d2b9Skchow #define CG(eax) (SH_CG(eax) || DH_CG(eax) || CH_CG(eax)) 25387c478bd9Sstevel@tonic-gate 25397c478bd9Sstevel@tonic-gate #define SH_D0(eax) (eax == 0x10f40 || eax == 0x10f50 || eax == 0x10f70) 25407c478bd9Sstevel@tonic-gate #define DH_D0(eax) (eax == 0x10fc0 || eax == 0x10ff0) 25417c478bd9Sstevel@tonic-gate #define CH_D0(eax) (eax == 0x10f80 || eax == 0x10fb0) 2542ee88d2b9Skchow #define D0(eax) (SH_D0(eax) || DH_D0(eax) || CH_D0(eax)) 25437c478bd9Sstevel@tonic-gate 25447c478bd9Sstevel@tonic-gate #define SH_E0(eax) (eax == 0x20f50 || eax == 0x20f40 || eax == 0x20f70) 25457c478bd9Sstevel@tonic-gate #define JH_E1(eax) (eax == 0x20f10) /* JH8_E0 had 0x20f30 */ 25467c478bd9Sstevel@tonic-gate #define DH_E3(eax) (eax == 0x20fc0 || eax == 0x20ff0) 25477c478bd9Sstevel@tonic-gate #define SH_E4(eax) (eax == 0x20f51 || eax == 0x20f71) 25487c478bd9Sstevel@tonic-gate #define BH_E4(eax) (eax == 0x20fb1) 25497c478bd9Sstevel@tonic-gate #define SH_E5(eax) (eax == 0x20f42) 25507c478bd9Sstevel@tonic-gate #define DH_E6(eax) (eax == 0x20ff2 || eax == 0x20fc2) 25517c478bd9Sstevel@tonic-gate #define JH_E6(eax) (eax == 0x20f12 || eax == 0x20f32) 2552ee88d2b9Skchow #define EX(eax) (SH_E0(eax) || JH_E1(eax) || DH_E3(eax) || \ 2553ee88d2b9Skchow SH_E4(eax) || BH_E4(eax) || SH_E5(eax) || \ 2554ee88d2b9Skchow DH_E6(eax) || JH_E6(eax)) 25557c478bd9Sstevel@tonic-gate 2556512cf780Skchow #define DR_AX(eax) (eax == 0x100f00 || eax == 0x100f01 || eax == 0x100f02) 2557512cf780Skchow #define DR_B0(eax) (eax == 0x100f20) 2558512cf780Skchow #define DR_B1(eax) (eax == 0x100f21) 2559512cf780Skchow #define DR_BA(eax) (eax == 0x100f2a) 2560512cf780Skchow #define DR_B2(eax) (eax == 0x100f22) 2561512cf780Skchow #define DR_B3(eax) (eax == 0x100f23) 2562512cf780Skchow #define RB_C0(eax) (eax == 0x100f40) 2563512cf780Skchow 25647c478bd9Sstevel@tonic-gate switch (erratum) { 25657c478bd9Sstevel@tonic-gate case 1: 2566875b116eSkchow return (cpi->cpi_family < 0x10); 25677c478bd9Sstevel@tonic-gate case 51: /* what does the asterisk mean? */ 25687c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax)); 25697c478bd9Sstevel@tonic-gate case 52: 25707c478bd9Sstevel@tonic-gate return (B(eax)); 25717c478bd9Sstevel@tonic-gate case 57: 2572512cf780Skchow return (cpi->cpi_family <= 0x11); 25737c478bd9Sstevel@tonic-gate case 58: 25747c478bd9Sstevel@tonic-gate return (B(eax)); 25757c478bd9Sstevel@tonic-gate case 60: 2576512cf780Skchow return (cpi->cpi_family <= 0x11); 25777c478bd9Sstevel@tonic-gate case 61: 25787c478bd9Sstevel@tonic-gate case 62: 25797c478bd9Sstevel@tonic-gate case 63: 25807c478bd9Sstevel@tonic-gate case 64: 25817c478bd9Sstevel@tonic-gate case 65: 25827c478bd9Sstevel@tonic-gate case 66: 25837c478bd9Sstevel@tonic-gate case 68: 25847c478bd9Sstevel@tonic-gate case 69: 25857c478bd9Sstevel@tonic-gate case 70: 25867c478bd9Sstevel@tonic-gate case 71: 25877c478bd9Sstevel@tonic-gate return (B(eax)); 25887c478bd9Sstevel@tonic-gate case 72: 25897c478bd9Sstevel@tonic-gate return (SH_B0(eax)); 25907c478bd9Sstevel@tonic-gate case 74: 25917c478bd9Sstevel@tonic-gate return (B(eax)); 25927c478bd9Sstevel@tonic-gate case 75: 2593875b116eSkchow return (cpi->cpi_family < 0x10); 25947c478bd9Sstevel@tonic-gate case 76: 25957c478bd9Sstevel@tonic-gate return (B(eax)); 25967c478bd9Sstevel@tonic-gate case 77: 2597512cf780Skchow return (cpi->cpi_family <= 0x11); 25987c478bd9Sstevel@tonic-gate case 78: 25997c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax)); 26007c478bd9Sstevel@tonic-gate case 79: 26017c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax) || EX(eax)); 26027c478bd9Sstevel@tonic-gate case 80: 26037c478bd9Sstevel@tonic-gate case 81: 26047c478bd9Sstevel@tonic-gate case 82: 26057c478bd9Sstevel@tonic-gate return (B(eax)); 26067c478bd9Sstevel@tonic-gate case 83: 26077c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax)); 26087c478bd9Sstevel@tonic-gate case 85: 2609875b116eSkchow return (cpi->cpi_family < 0x10); 26107c478bd9Sstevel@tonic-gate case 86: 26117c478bd9Sstevel@tonic-gate return (SH_C0(eax) || CG(eax)); 26127c478bd9Sstevel@tonic-gate case 88: 26137c478bd9Sstevel@tonic-gate #if !defined(__amd64) 26147c478bd9Sstevel@tonic-gate return (0); 26157c478bd9Sstevel@tonic-gate #else 26167c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax)); 26177c478bd9Sstevel@tonic-gate #endif 26187c478bd9Sstevel@tonic-gate case 89: 2619875b116eSkchow return (cpi->cpi_family < 0x10); 26207c478bd9Sstevel@tonic-gate case 90: 26217c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax)); 26227c478bd9Sstevel@tonic-gate case 91: 26237c478bd9Sstevel@tonic-gate case 92: 26247c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax)); 26257c478bd9Sstevel@tonic-gate case 93: 26267c478bd9Sstevel@tonic-gate return (SH_C0(eax)); 26277c478bd9Sstevel@tonic-gate case 94: 26287c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax)); 26297c478bd9Sstevel@tonic-gate case 95: 26307c478bd9Sstevel@tonic-gate #if !defined(__amd64) 26317c478bd9Sstevel@tonic-gate return (0); 26327c478bd9Sstevel@tonic-gate #else 26337c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax)); 26347c478bd9Sstevel@tonic-gate #endif 26357c478bd9Sstevel@tonic-gate case 96: 26367c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax)); 26377c478bd9Sstevel@tonic-gate case 97: 26387c478bd9Sstevel@tonic-gate case 98: 26397c478bd9Sstevel@tonic-gate return (SH_C0(eax) || CG(eax)); 26407c478bd9Sstevel@tonic-gate case 99: 26417c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax)); 26427c478bd9Sstevel@tonic-gate case 100: 26437c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax)); 26447c478bd9Sstevel@tonic-gate case 101: 26457c478bd9Sstevel@tonic-gate case 103: 26467c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax)); 26477c478bd9Sstevel@tonic-gate case 104: 26487c478bd9Sstevel@tonic-gate return (SH_C0(eax) || CG(eax) || D0(eax)); 26497c478bd9Sstevel@tonic-gate case 105: 26507c478bd9Sstevel@tonic-gate case 106: 26517c478bd9Sstevel@tonic-gate case 107: 26527c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax)); 26537c478bd9Sstevel@tonic-gate case 108: 26547c478bd9Sstevel@tonic-gate return (DH_CG(eax)); 26557c478bd9Sstevel@tonic-gate case 109: 26567c478bd9Sstevel@tonic-gate return (SH_C0(eax) || CG(eax) || D0(eax)); 26577c478bd9Sstevel@tonic-gate case 110: 26587c478bd9Sstevel@tonic-gate return (D0(eax) || EX(eax)); 26597c478bd9Sstevel@tonic-gate case 111: 26607c478bd9Sstevel@tonic-gate return (CG(eax)); 26617c478bd9Sstevel@tonic-gate case 112: 26627c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax) || EX(eax)); 26637c478bd9Sstevel@tonic-gate case 113: 26647c478bd9Sstevel@tonic-gate return (eax == 0x20fc0); 26657c478bd9Sstevel@tonic-gate case 114: 26667c478bd9Sstevel@tonic-gate return (SH_E0(eax) || JH_E1(eax) || DH_E3(eax)); 26677c478bd9Sstevel@tonic-gate case 115: 26687c478bd9Sstevel@tonic-gate return (SH_E0(eax) || JH_E1(eax)); 26697c478bd9Sstevel@tonic-gate case 116: 26707c478bd9Sstevel@tonic-gate return (SH_E0(eax) || JH_E1(eax) || DH_E3(eax)); 26717c478bd9Sstevel@tonic-gate case 117: 26727c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax)); 26737c478bd9Sstevel@tonic-gate case 118: 26747c478bd9Sstevel@tonic-gate return (SH_E0(eax) || JH_E1(eax) || SH_E4(eax) || BH_E4(eax) || 26757c478bd9Sstevel@tonic-gate JH_E6(eax)); 26767c478bd9Sstevel@tonic-gate case 121: 26777c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax) || EX(eax)); 26787c478bd9Sstevel@tonic-gate case 122: 2679512cf780Skchow return (cpi->cpi_family < 0x10 || cpi->cpi_family == 0x11); 26807c478bd9Sstevel@tonic-gate case 123: 26817c478bd9Sstevel@tonic-gate return (JH_E1(eax) || BH_E4(eax) || JH_E6(eax)); 26822201b277Skucharsk case 131: 2683875b116eSkchow return (cpi->cpi_family < 0x10); 2684ef50d8c0Sesaxe case 6336786: 2685ef50d8c0Sesaxe /* 2686ef50d8c0Sesaxe * Test for AdvPowerMgmtInfo.TscPStateInvariant 2687875b116eSkchow * if this is a K8 family or newer processor 2688ef50d8c0Sesaxe */ 2689ef50d8c0Sesaxe if (CPI_FAMILY(cpi) == 0xf) { 26908949bcd6Sandrei struct cpuid_regs regs; 26918949bcd6Sandrei regs.cp_eax = 0x80000007; 26928949bcd6Sandrei (void) __cpuid_insn(®s); 26938949bcd6Sandrei return (!(regs.cp_edx & 0x100)); 2694ef50d8c0Sesaxe } 2695ef50d8c0Sesaxe return (0); 2696ee88d2b9Skchow case 6323525: 2697ee88d2b9Skchow return (((((eax >> 12) & 0xff00) + (eax & 0xf00)) | 2698ee88d2b9Skchow (((eax >> 4) & 0xf) | ((eax >> 12) & 0xf0))) < 0xf40); 2699ee88d2b9Skchow 2700512cf780Skchow case 6671130: 2701512cf780Skchow /* 2702512cf780Skchow * check for processors (pre-Shanghai) that do not provide 2703512cf780Skchow * optimal management of 1gb ptes in its tlb. 2704512cf780Skchow */ 2705512cf780Skchow return (cpi->cpi_family == 0x10 && cpi->cpi_model < 4); 2706512cf780Skchow 2707512cf780Skchow case 298: 2708512cf780Skchow return (DR_AX(eax) || DR_B0(eax) || DR_B1(eax) || DR_BA(eax) || 2709512cf780Skchow DR_B2(eax) || RB_C0(eax)); 2710512cf780Skchow 2711512cf780Skchow default: 2712512cf780Skchow return (-1); 2713512cf780Skchow 2714512cf780Skchow } 2715512cf780Skchow } 2716512cf780Skchow 2717512cf780Skchow /* 2718512cf780Skchow * Determine if specified erratum is present via OSVW (OS Visible Workaround). 2719512cf780Skchow * Return 1 if erratum is present, 0 if not present and -1 if indeterminate. 2720512cf780Skchow */ 2721512cf780Skchow int 2722512cf780Skchow osvw_opteron_erratum(cpu_t *cpu, uint_t erratum) 2723512cf780Skchow { 2724512cf780Skchow struct cpuid_info *cpi; 2725512cf780Skchow uint_t osvwid; 2726512cf780Skchow static int osvwfeature = -1; 2727512cf780Skchow uint64_t osvwlength; 2728512cf780Skchow 2729512cf780Skchow 2730512cf780Skchow cpi = cpu->cpu_m.mcpu_cpi; 2731512cf780Skchow 2732512cf780Skchow /* confirm OSVW supported */ 2733512cf780Skchow if (osvwfeature == -1) { 2734512cf780Skchow osvwfeature = cpi->cpi_extd[1].cp_ecx & CPUID_AMD_ECX_OSVW; 2735512cf780Skchow } else { 2736512cf780Skchow /* assert that osvw feature setting is consistent on all cpus */ 2737512cf780Skchow ASSERT(osvwfeature == 2738512cf780Skchow (cpi->cpi_extd[1].cp_ecx & CPUID_AMD_ECX_OSVW)); 2739512cf780Skchow } 2740512cf780Skchow if (!osvwfeature) 2741512cf780Skchow return (-1); 2742512cf780Skchow 2743512cf780Skchow osvwlength = rdmsr(MSR_AMD_OSVW_ID_LEN) & OSVW_ID_LEN_MASK; 2744512cf780Skchow 2745512cf780Skchow switch (erratum) { 2746512cf780Skchow case 298: /* osvwid is 0 */ 2747512cf780Skchow osvwid = 0; 2748512cf780Skchow if (osvwlength <= (uint64_t)osvwid) { 2749512cf780Skchow /* osvwid 0 is unknown */ 2750512cf780Skchow return (-1); 2751512cf780Skchow } 2752512cf780Skchow 2753512cf780Skchow /* 2754512cf780Skchow * Check the OSVW STATUS MSR to determine the state 2755512cf780Skchow * of the erratum where: 2756512cf780Skchow * 0 - fixed by HW 2757512cf780Skchow * 1 - BIOS has applied the workaround when BIOS 2758512cf780Skchow * workaround is available. (Or for other errata, 2759512cf780Skchow * OS workaround is required.) 2760512cf780Skchow * For a value of 1, caller will confirm that the 2761512cf780Skchow * erratum 298 workaround has indeed been applied by BIOS. 2762512cf780Skchow * 2763512cf780Skchow * A 1 may be set in cpus that have a HW fix 2764512cf780Skchow * in a mixed cpu system. Regarding erratum 298: 2765512cf780Skchow * In a multiprocessor platform, the workaround above 2766512cf780Skchow * should be applied to all processors regardless of 2767512cf780Skchow * silicon revision when an affected processor is 2768512cf780Skchow * present. 2769512cf780Skchow */ 2770512cf780Skchow 2771512cf780Skchow return (rdmsr(MSR_AMD_OSVW_STATUS + 2772512cf780Skchow (osvwid / OSVW_ID_CNT_PER_MSR)) & 2773512cf780Skchow (1ULL << (osvwid % OSVW_ID_CNT_PER_MSR))); 2774512cf780Skchow 27757c478bd9Sstevel@tonic-gate default: 27767c478bd9Sstevel@tonic-gate return (-1); 27777c478bd9Sstevel@tonic-gate } 27787c478bd9Sstevel@tonic-gate } 27797c478bd9Sstevel@tonic-gate 27807c478bd9Sstevel@tonic-gate static const char assoc_str[] = "associativity"; 27817c478bd9Sstevel@tonic-gate static const char line_str[] = "line-size"; 27827c478bd9Sstevel@tonic-gate static const char size_str[] = "size"; 27837c478bd9Sstevel@tonic-gate 27847c478bd9Sstevel@tonic-gate static void 27857c478bd9Sstevel@tonic-gate add_cache_prop(dev_info_t *devi, const char *label, const char *type, 27867c478bd9Sstevel@tonic-gate uint32_t val) 27877c478bd9Sstevel@tonic-gate { 27887c478bd9Sstevel@tonic-gate char buf[128]; 27897c478bd9Sstevel@tonic-gate 27907c478bd9Sstevel@tonic-gate /* 27917c478bd9Sstevel@tonic-gate * ndi_prop_update_int() is used because it is desirable for 27927c478bd9Sstevel@tonic-gate * DDI_PROP_HW_DEF and DDI_PROP_DONTSLEEP to be set. 27937c478bd9Sstevel@tonic-gate */ 27947c478bd9Sstevel@tonic-gate if (snprintf(buf, sizeof (buf), "%s-%s", label, type) < sizeof (buf)) 27957c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, devi, buf, val); 27967c478bd9Sstevel@tonic-gate } 27977c478bd9Sstevel@tonic-gate 27987c478bd9Sstevel@tonic-gate /* 27997c478bd9Sstevel@tonic-gate * Intel-style cache/tlb description 28007c478bd9Sstevel@tonic-gate * 28017c478bd9Sstevel@tonic-gate * Standard cpuid level 2 gives a randomly ordered 28027c478bd9Sstevel@tonic-gate * selection of tags that index into a table that describes 28037c478bd9Sstevel@tonic-gate * cache and tlb properties. 28047c478bd9Sstevel@tonic-gate */ 28057c478bd9Sstevel@tonic-gate 28067c478bd9Sstevel@tonic-gate static const char l1_icache_str[] = "l1-icache"; 28077c478bd9Sstevel@tonic-gate static const char l1_dcache_str[] = "l1-dcache"; 28087c478bd9Sstevel@tonic-gate static const char l2_cache_str[] = "l2-cache"; 2809ae115bc7Smrj static const char l3_cache_str[] = "l3-cache"; 28107c478bd9Sstevel@tonic-gate static const char itlb4k_str[] = "itlb-4K"; 28117c478bd9Sstevel@tonic-gate static const char dtlb4k_str[] = "dtlb-4K"; 2812824e4fecSvd224797 static const char itlb2M_str[] = "itlb-2M"; 28137c478bd9Sstevel@tonic-gate static const char itlb4M_str[] = "itlb-4M"; 28147c478bd9Sstevel@tonic-gate static const char dtlb4M_str[] = "dtlb-4M"; 281525dfb062Sksadhukh static const char dtlb24_str[] = "dtlb0-2M-4M"; 28167c478bd9Sstevel@tonic-gate static const char itlb424_str[] = "itlb-4K-2M-4M"; 281725dfb062Sksadhukh static const char itlb24_str[] = "itlb-2M-4M"; 28187c478bd9Sstevel@tonic-gate static const char dtlb44_str[] = "dtlb-4K-4M"; 28197c478bd9Sstevel@tonic-gate static const char sl1_dcache_str[] = "sectored-l1-dcache"; 28207c478bd9Sstevel@tonic-gate static const char sl2_cache_str[] = "sectored-l2-cache"; 28217c478bd9Sstevel@tonic-gate static const char itrace_str[] = "itrace-cache"; 28227c478bd9Sstevel@tonic-gate static const char sl3_cache_str[] = "sectored-l3-cache"; 282325dfb062Sksadhukh static const char sh_l2_tlb4k_str[] = "shared-l2-tlb-4k"; 28247c478bd9Sstevel@tonic-gate 28257c478bd9Sstevel@tonic-gate static const struct cachetab { 28267c478bd9Sstevel@tonic-gate uint8_t ct_code; 28277c478bd9Sstevel@tonic-gate uint8_t ct_assoc; 28287c478bd9Sstevel@tonic-gate uint16_t ct_line_size; 28297c478bd9Sstevel@tonic-gate size_t ct_size; 28307c478bd9Sstevel@tonic-gate const char *ct_label; 28317c478bd9Sstevel@tonic-gate } intel_ctab[] = { 2832824e4fecSvd224797 /* 2833824e4fecSvd224797 * maintain descending order! 2834824e4fecSvd224797 * 2835824e4fecSvd224797 * Codes ignored - Reason 2836824e4fecSvd224797 * ---------------------- 2837824e4fecSvd224797 * 40H - intel_cpuid_4_cache_info() disambiguates l2/l3 cache 2838824e4fecSvd224797 * f0H/f1H - Currently we do not interpret prefetch size by design 2839824e4fecSvd224797 */ 284025dfb062Sksadhukh { 0xe4, 16, 64, 8*1024*1024, l3_cache_str}, 284125dfb062Sksadhukh { 0xe3, 16, 64, 4*1024*1024, l3_cache_str}, 284225dfb062Sksadhukh { 0xe2, 16, 64, 2*1024*1024, l3_cache_str}, 284325dfb062Sksadhukh { 0xde, 12, 64, 6*1024*1024, l3_cache_str}, 284425dfb062Sksadhukh { 0xdd, 12, 64, 3*1024*1024, l3_cache_str}, 284525dfb062Sksadhukh { 0xdc, 12, 64, ((1*1024*1024)+(512*1024)), l3_cache_str}, 284625dfb062Sksadhukh { 0xd8, 8, 64, 4*1024*1024, l3_cache_str}, 284725dfb062Sksadhukh { 0xd7, 8, 64, 2*1024*1024, l3_cache_str}, 284825dfb062Sksadhukh { 0xd6, 8, 64, 1*1024*1024, l3_cache_str}, 284925dfb062Sksadhukh { 0xd2, 4, 64, 2*1024*1024, l3_cache_str}, 285025dfb062Sksadhukh { 0xd1, 4, 64, 1*1024*1024, l3_cache_str}, 285125dfb062Sksadhukh { 0xd0, 4, 64, 512*1024, l3_cache_str}, 285225dfb062Sksadhukh { 0xca, 4, 0, 512, sh_l2_tlb4k_str}, 2853824e4fecSvd224797 { 0xc0, 4, 0, 8, dtlb44_str }, 2854824e4fecSvd224797 { 0xba, 4, 0, 64, dtlb4k_str }, 2855ae115bc7Smrj { 0xb4, 4, 0, 256, dtlb4k_str }, 28567c478bd9Sstevel@tonic-gate { 0xb3, 4, 0, 128, dtlb4k_str }, 285725dfb062Sksadhukh { 0xb2, 4, 0, 64, itlb4k_str }, 28587c478bd9Sstevel@tonic-gate { 0xb0, 4, 0, 128, itlb4k_str }, 28597c478bd9Sstevel@tonic-gate { 0x87, 8, 64, 1024*1024, l2_cache_str}, 28607c478bd9Sstevel@tonic-gate { 0x86, 4, 64, 512*1024, l2_cache_str}, 28617c478bd9Sstevel@tonic-gate { 0x85, 8, 32, 2*1024*1024, l2_cache_str}, 28627c478bd9Sstevel@tonic-gate { 0x84, 8, 32, 1024*1024, l2_cache_str}, 28637c478bd9Sstevel@tonic-gate { 0x83, 8, 32, 512*1024, l2_cache_str}, 28647c478bd9Sstevel@tonic-gate { 0x82, 8, 32, 256*1024, l2_cache_str}, 2865824e4fecSvd224797 { 0x80, 8, 64, 512*1024, l2_cache_str}, 28667c478bd9Sstevel@tonic-gate { 0x7f, 2, 64, 512*1024, l2_cache_str}, 28677c478bd9Sstevel@tonic-gate { 0x7d, 8, 64, 2*1024*1024, sl2_cache_str}, 28687c478bd9Sstevel@tonic-gate { 0x7c, 8, 64, 1024*1024, sl2_cache_str}, 28697c478bd9Sstevel@tonic-gate { 0x7b, 8, 64, 512*1024, sl2_cache_str}, 28707c478bd9Sstevel@tonic-gate { 0x7a, 8, 64, 256*1024, sl2_cache_str}, 28717c478bd9Sstevel@tonic-gate { 0x79, 8, 64, 128*1024, sl2_cache_str}, 28727c478bd9Sstevel@tonic-gate { 0x78, 8, 64, 1024*1024, l2_cache_str}, 2873ae115bc7Smrj { 0x73, 8, 0, 64*1024, itrace_str}, 28747c478bd9Sstevel@tonic-gate { 0x72, 8, 0, 32*1024, itrace_str}, 28757c478bd9Sstevel@tonic-gate { 0x71, 8, 0, 16*1024, itrace_str}, 28767c478bd9Sstevel@tonic-gate { 0x70, 8, 0, 12*1024, itrace_str}, 28777c478bd9Sstevel@tonic-gate { 0x68, 4, 64, 32*1024, sl1_dcache_str}, 28787c478bd9Sstevel@tonic-gate { 0x67, 4, 64, 16*1024, sl1_dcache_str}, 28797c478bd9Sstevel@tonic-gate { 0x66, 4, 64, 8*1024, sl1_dcache_str}, 28807c478bd9Sstevel@tonic-gate { 0x60, 8, 64, 16*1024, sl1_dcache_str}, 28817c478bd9Sstevel@tonic-gate { 0x5d, 0, 0, 256, dtlb44_str}, 28827c478bd9Sstevel@tonic-gate { 0x5c, 0, 0, 128, dtlb44_str}, 28837c478bd9Sstevel@tonic-gate { 0x5b, 0, 0, 64, dtlb44_str}, 288425dfb062Sksadhukh { 0x5a, 4, 0, 32, dtlb24_str}, 2885824e4fecSvd224797 { 0x59, 0, 0, 16, dtlb4k_str}, 2886824e4fecSvd224797 { 0x57, 4, 0, 16, dtlb4k_str}, 2887824e4fecSvd224797 { 0x56, 4, 0, 16, dtlb4M_str}, 288825dfb062Sksadhukh { 0x55, 0, 0, 7, itlb24_str}, 28897c478bd9Sstevel@tonic-gate { 0x52, 0, 0, 256, itlb424_str}, 28907c478bd9Sstevel@tonic-gate { 0x51, 0, 0, 128, itlb424_str}, 28917c478bd9Sstevel@tonic-gate { 0x50, 0, 0, 64, itlb424_str}, 2892824e4fecSvd224797 { 0x4f, 0, 0, 32, itlb4k_str}, 2893824e4fecSvd224797 { 0x4e, 24, 64, 6*1024*1024, l2_cache_str}, 2894ae115bc7Smrj { 0x4d, 16, 64, 16*1024*1024, l3_cache_str}, 2895ae115bc7Smrj { 0x4c, 12, 64, 12*1024*1024, l3_cache_str}, 2896ae115bc7Smrj { 0x4b, 16, 64, 8*1024*1024, l3_cache_str}, 2897ae115bc7Smrj { 0x4a, 12, 64, 6*1024*1024, l3_cache_str}, 2898ae115bc7Smrj { 0x49, 16, 64, 4*1024*1024, l3_cache_str}, 2899824e4fecSvd224797 { 0x48, 12, 64, 3*1024*1024, l2_cache_str}, 2900ae115bc7Smrj { 0x47, 8, 64, 8*1024*1024, l3_cache_str}, 2901ae115bc7Smrj { 0x46, 4, 64, 4*1024*1024, l3_cache_str}, 29027c478bd9Sstevel@tonic-gate { 0x45, 4, 32, 2*1024*1024, l2_cache_str}, 29037c478bd9Sstevel@tonic-gate { 0x44, 4, 32, 1024*1024, l2_cache_str}, 29047c478bd9Sstevel@tonic-gate { 0x43, 4, 32, 512*1024, l2_cache_str}, 29057c478bd9Sstevel@tonic-gate { 0x42, 4, 32, 256*1024, l2_cache_str}, 29067c478bd9Sstevel@tonic-gate { 0x41, 4, 32, 128*1024, l2_cache_str}, 2907ae115bc7Smrj { 0x3e, 4, 64, 512*1024, sl2_cache_str}, 2908ae115bc7Smrj { 0x3d, 6, 64, 384*1024, sl2_cache_str}, 29097c478bd9Sstevel@tonic-gate { 0x3c, 4, 64, 256*1024, sl2_cache_str}, 29107c478bd9Sstevel@tonic-gate { 0x3b, 2, 64, 128*1024, sl2_cache_str}, 2911ae115bc7Smrj { 0x3a, 6, 64, 192*1024, sl2_cache_str}, 29127c478bd9Sstevel@tonic-gate { 0x39, 4, 64, 128*1024, sl2_cache_str}, 29137c478bd9Sstevel@tonic-gate { 0x30, 8, 64, 32*1024, l1_icache_str}, 29147c478bd9Sstevel@tonic-gate { 0x2c, 8, 64, 32*1024, l1_dcache_str}, 29157c478bd9Sstevel@tonic-gate { 0x29, 8, 64, 4096*1024, sl3_cache_str}, 29167c478bd9Sstevel@tonic-gate { 0x25, 8, 64, 2048*1024, sl3_cache_str}, 29177c478bd9Sstevel@tonic-gate { 0x23, 8, 64, 1024*1024, sl3_cache_str}, 29187c478bd9Sstevel@tonic-gate { 0x22, 4, 64, 512*1024, sl3_cache_str}, 2919824e4fecSvd224797 { 0x0e, 6, 64, 24*1024, l1_dcache_str}, 292025dfb062Sksadhukh { 0x0d, 4, 32, 16*1024, l1_dcache_str}, 29217c478bd9Sstevel@tonic-gate { 0x0c, 4, 32, 16*1024, l1_dcache_str}, 2922ae115bc7Smrj { 0x0b, 4, 0, 4, itlb4M_str}, 29237c478bd9Sstevel@tonic-gate { 0x0a, 2, 32, 8*1024, l1_dcache_str}, 29247c478bd9Sstevel@tonic-gate { 0x08, 4, 32, 16*1024, l1_icache_str}, 29257c478bd9Sstevel@tonic-gate { 0x06, 4, 32, 8*1024, l1_icache_str}, 2926824e4fecSvd224797 { 0x05, 4, 0, 32, dtlb4M_str}, 29277c478bd9Sstevel@tonic-gate { 0x04, 4, 0, 8, dtlb4M_str}, 29287c478bd9Sstevel@tonic-gate { 0x03, 4, 0, 64, dtlb4k_str}, 29297c478bd9Sstevel@tonic-gate { 0x02, 4, 0, 2, itlb4M_str}, 29307c478bd9Sstevel@tonic-gate { 0x01, 4, 0, 32, itlb4k_str}, 29317c478bd9Sstevel@tonic-gate { 0 } 29327c478bd9Sstevel@tonic-gate }; 29337c478bd9Sstevel@tonic-gate 29347c478bd9Sstevel@tonic-gate static const struct cachetab cyrix_ctab[] = { 29357c478bd9Sstevel@tonic-gate { 0x70, 4, 0, 32, "tlb-4K" }, 29367c478bd9Sstevel@tonic-gate { 0x80, 4, 16, 16*1024, "l1-cache" }, 29377c478bd9Sstevel@tonic-gate { 0 } 29387c478bd9Sstevel@tonic-gate }; 29397c478bd9Sstevel@tonic-gate 29407c478bd9Sstevel@tonic-gate /* 29417c478bd9Sstevel@tonic-gate * Search a cache table for a matching entry 29427c478bd9Sstevel@tonic-gate */ 29437c478bd9Sstevel@tonic-gate static const struct cachetab * 29447c478bd9Sstevel@tonic-gate find_cacheent(const struct cachetab *ct, uint_t code) 29457c478bd9Sstevel@tonic-gate { 29467c478bd9Sstevel@tonic-gate if (code != 0) { 29477c478bd9Sstevel@tonic-gate for (; ct->ct_code != 0; ct++) 29487c478bd9Sstevel@tonic-gate if (ct->ct_code <= code) 29497c478bd9Sstevel@tonic-gate break; 29507c478bd9Sstevel@tonic-gate if (ct->ct_code == code) 29517c478bd9Sstevel@tonic-gate return (ct); 29527c478bd9Sstevel@tonic-gate } 29537c478bd9Sstevel@tonic-gate return (NULL); 29547c478bd9Sstevel@tonic-gate } 29557c478bd9Sstevel@tonic-gate 29567c478bd9Sstevel@tonic-gate /* 29577dee861bSksadhukh * Populate cachetab entry with L2 or L3 cache-information using 29587dee861bSksadhukh * cpuid function 4. This function is called from intel_walk_cacheinfo() 29597dee861bSksadhukh * when descriptor 0x49 is encountered. It returns 0 if no such cache 29607dee861bSksadhukh * information is found. 29617dee861bSksadhukh */ 29627dee861bSksadhukh static int 29637dee861bSksadhukh intel_cpuid_4_cache_info(struct cachetab *ct, struct cpuid_info *cpi) 29647dee861bSksadhukh { 29657dee861bSksadhukh uint32_t level, i; 29667dee861bSksadhukh int ret = 0; 29677dee861bSksadhukh 29687dee861bSksadhukh for (i = 0; i < cpi->cpi_std_4_size; i++) { 29697dee861bSksadhukh level = CPI_CACHE_LVL(cpi->cpi_std_4[i]); 29707dee861bSksadhukh 29717dee861bSksadhukh if (level == 2 || level == 3) { 29727dee861bSksadhukh ct->ct_assoc = CPI_CACHE_WAYS(cpi->cpi_std_4[i]) + 1; 29737dee861bSksadhukh ct->ct_line_size = 29747dee861bSksadhukh CPI_CACHE_COH_LN_SZ(cpi->cpi_std_4[i]) + 1; 29757dee861bSksadhukh ct->ct_size = ct->ct_assoc * 29767dee861bSksadhukh (CPI_CACHE_PARTS(cpi->cpi_std_4[i]) + 1) * 29777dee861bSksadhukh ct->ct_line_size * 29787dee861bSksadhukh (cpi->cpi_std_4[i]->cp_ecx + 1); 29797dee861bSksadhukh 29807dee861bSksadhukh if (level == 2) { 29817dee861bSksadhukh ct->ct_label = l2_cache_str; 29827dee861bSksadhukh } else if (level == 3) { 29837dee861bSksadhukh ct->ct_label = l3_cache_str; 29847dee861bSksadhukh } 29857dee861bSksadhukh ret = 1; 29867dee861bSksadhukh } 29877dee861bSksadhukh } 29887dee861bSksadhukh 29897dee861bSksadhukh return (ret); 29907dee861bSksadhukh } 29917dee861bSksadhukh 29927dee861bSksadhukh /* 29937c478bd9Sstevel@tonic-gate * Walk the cacheinfo descriptor, applying 'func' to every valid element 29947c478bd9Sstevel@tonic-gate * The walk is terminated if the walker returns non-zero. 29957c478bd9Sstevel@tonic-gate */ 29967c478bd9Sstevel@tonic-gate static void 29977c478bd9Sstevel@tonic-gate intel_walk_cacheinfo(struct cpuid_info *cpi, 29987c478bd9Sstevel@tonic-gate void *arg, int (*func)(void *, const struct cachetab *)) 29997c478bd9Sstevel@tonic-gate { 30007c478bd9Sstevel@tonic-gate const struct cachetab *ct; 3001824e4fecSvd224797 struct cachetab des_49_ct, des_b1_ct; 30027c478bd9Sstevel@tonic-gate uint8_t *dp; 30037c478bd9Sstevel@tonic-gate int i; 30047c478bd9Sstevel@tonic-gate 30057c478bd9Sstevel@tonic-gate if ((dp = cpi->cpi_cacheinfo) == NULL) 30067c478bd9Sstevel@tonic-gate return; 3007f1d742a9Sksadhukh for (i = 0; i < cpi->cpi_ncache; i++, dp++) { 3008f1d742a9Sksadhukh /* 3009f1d742a9Sksadhukh * For overloaded descriptor 0x49 we use cpuid function 4 30107dee861bSksadhukh * if supported by the current processor, to create 3011f1d742a9Sksadhukh * cache information. 3012824e4fecSvd224797 * For overloaded descriptor 0xb1 we use X86_PAE flag 3013824e4fecSvd224797 * to disambiguate the cache information. 3014f1d742a9Sksadhukh */ 30157dee861bSksadhukh if (*dp == 0x49 && cpi->cpi_maxeax >= 0x4 && 30167dee861bSksadhukh intel_cpuid_4_cache_info(&des_49_ct, cpi) == 1) { 30177dee861bSksadhukh ct = &des_49_ct; 3018824e4fecSvd224797 } else if (*dp == 0xb1) { 3019824e4fecSvd224797 des_b1_ct.ct_code = 0xb1; 3020824e4fecSvd224797 des_b1_ct.ct_assoc = 4; 3021824e4fecSvd224797 des_b1_ct.ct_line_size = 0; 3022824e4fecSvd224797 if (x86_feature & X86_PAE) { 3023824e4fecSvd224797 des_b1_ct.ct_size = 8; 3024824e4fecSvd224797 des_b1_ct.ct_label = itlb2M_str; 3025824e4fecSvd224797 } else { 3026824e4fecSvd224797 des_b1_ct.ct_size = 4; 3027824e4fecSvd224797 des_b1_ct.ct_label = itlb4M_str; 3028824e4fecSvd224797 } 3029824e4fecSvd224797 ct = &des_b1_ct; 30307dee861bSksadhukh } else { 30317dee861bSksadhukh if ((ct = find_cacheent(intel_ctab, *dp)) == NULL) { 3032f1d742a9Sksadhukh continue; 3033f1d742a9Sksadhukh } 30347dee861bSksadhukh } 3035f1d742a9Sksadhukh 30367dee861bSksadhukh if (func(arg, ct) != 0) { 30377c478bd9Sstevel@tonic-gate break; 30387c478bd9Sstevel@tonic-gate } 30397c478bd9Sstevel@tonic-gate } 3040f1d742a9Sksadhukh } 30417c478bd9Sstevel@tonic-gate 30427c478bd9Sstevel@tonic-gate /* 30437c478bd9Sstevel@tonic-gate * (Like the Intel one, except for Cyrix CPUs) 30447c478bd9Sstevel@tonic-gate */ 30457c478bd9Sstevel@tonic-gate static void 30467c478bd9Sstevel@tonic-gate cyrix_walk_cacheinfo(struct cpuid_info *cpi, 30477c478bd9Sstevel@tonic-gate void *arg, int (*func)(void *, const struct cachetab *)) 30487c478bd9Sstevel@tonic-gate { 30497c478bd9Sstevel@tonic-gate const struct cachetab *ct; 30507c478bd9Sstevel@tonic-gate uint8_t *dp; 30517c478bd9Sstevel@tonic-gate int i; 30527c478bd9Sstevel@tonic-gate 30537c478bd9Sstevel@tonic-gate if ((dp = cpi->cpi_cacheinfo) == NULL) 30547c478bd9Sstevel@tonic-gate return; 30557c478bd9Sstevel@tonic-gate for (i = 0; i < cpi->cpi_ncache; i++, dp++) { 30567c478bd9Sstevel@tonic-gate /* 30577c478bd9Sstevel@tonic-gate * Search Cyrix-specific descriptor table first .. 30587c478bd9Sstevel@tonic-gate */ 30597c478bd9Sstevel@tonic-gate if ((ct = find_cacheent(cyrix_ctab, *dp)) != NULL) { 30607c478bd9Sstevel@tonic-gate if (func(arg, ct) != 0) 30617c478bd9Sstevel@tonic-gate break; 30627c478bd9Sstevel@tonic-gate continue; 30637c478bd9Sstevel@tonic-gate } 30647c478bd9Sstevel@tonic-gate /* 30657c478bd9Sstevel@tonic-gate * .. else fall back to the Intel one 30667c478bd9Sstevel@tonic-gate */ 30677c478bd9Sstevel@tonic-gate if ((ct = find_cacheent(intel_ctab, *dp)) != NULL) { 30687c478bd9Sstevel@tonic-gate if (func(arg, ct) != 0) 30697c478bd9Sstevel@tonic-gate break; 30707c478bd9Sstevel@tonic-gate continue; 30717c478bd9Sstevel@tonic-gate } 30727c478bd9Sstevel@tonic-gate } 30737c478bd9Sstevel@tonic-gate } 30747c478bd9Sstevel@tonic-gate 30757c478bd9Sstevel@tonic-gate /* 30767c478bd9Sstevel@tonic-gate * A cacheinfo walker that adds associativity, line-size, and size properties 30777c478bd9Sstevel@tonic-gate * to the devinfo node it is passed as an argument. 30787c478bd9Sstevel@tonic-gate */ 30797c478bd9Sstevel@tonic-gate static int 30807c478bd9Sstevel@tonic-gate add_cacheent_props(void *arg, const struct cachetab *ct) 30817c478bd9Sstevel@tonic-gate { 30827c478bd9Sstevel@tonic-gate dev_info_t *devi = arg; 30837c478bd9Sstevel@tonic-gate 30847c478bd9Sstevel@tonic-gate add_cache_prop(devi, ct->ct_label, assoc_str, ct->ct_assoc); 30857c478bd9Sstevel@tonic-gate if (ct->ct_line_size != 0) 30867c478bd9Sstevel@tonic-gate add_cache_prop(devi, ct->ct_label, line_str, 30877c478bd9Sstevel@tonic-gate ct->ct_line_size); 30887c478bd9Sstevel@tonic-gate add_cache_prop(devi, ct->ct_label, size_str, ct->ct_size); 30897c478bd9Sstevel@tonic-gate return (0); 30907c478bd9Sstevel@tonic-gate } 30917c478bd9Sstevel@tonic-gate 3092f1d742a9Sksadhukh 30937c478bd9Sstevel@tonic-gate static const char fully_assoc[] = "fully-associative?"; 30947c478bd9Sstevel@tonic-gate 30957c478bd9Sstevel@tonic-gate /* 30967c478bd9Sstevel@tonic-gate * AMD style cache/tlb description 30977c478bd9Sstevel@tonic-gate * 30987c478bd9Sstevel@tonic-gate * Extended functions 5 and 6 directly describe properties of 30997c478bd9Sstevel@tonic-gate * tlbs and various cache levels. 31007c478bd9Sstevel@tonic-gate */ 31017c478bd9Sstevel@tonic-gate static void 31027c478bd9Sstevel@tonic-gate add_amd_assoc(dev_info_t *devi, const char *label, uint_t assoc) 31037c478bd9Sstevel@tonic-gate { 31047c478bd9Sstevel@tonic-gate switch (assoc) { 31057c478bd9Sstevel@tonic-gate case 0: /* reserved; ignore */ 31067c478bd9Sstevel@tonic-gate break; 31077c478bd9Sstevel@tonic-gate default: 31087c478bd9Sstevel@tonic-gate add_cache_prop(devi, label, assoc_str, assoc); 31097c478bd9Sstevel@tonic-gate break; 31107c478bd9Sstevel@tonic-gate case 0xff: 31117c478bd9Sstevel@tonic-gate add_cache_prop(devi, label, fully_assoc, 1); 31127c478bd9Sstevel@tonic-gate break; 31137c478bd9Sstevel@tonic-gate } 31147c478bd9Sstevel@tonic-gate } 31157c478bd9Sstevel@tonic-gate 31167c478bd9Sstevel@tonic-gate static void 31177c478bd9Sstevel@tonic-gate add_amd_tlb(dev_info_t *devi, const char *label, uint_t assoc, uint_t size) 31187c478bd9Sstevel@tonic-gate { 31197c478bd9Sstevel@tonic-gate if (size == 0) 31207c478bd9Sstevel@tonic-gate return; 31217c478bd9Sstevel@tonic-gate add_cache_prop(devi, label, size_str, size); 31227c478bd9Sstevel@tonic-gate add_amd_assoc(devi, label, assoc); 31237c478bd9Sstevel@tonic-gate } 31247c478bd9Sstevel@tonic-gate 31257c478bd9Sstevel@tonic-gate static void 31267c478bd9Sstevel@tonic-gate add_amd_cache(dev_info_t *devi, const char *label, 31277c478bd9Sstevel@tonic-gate uint_t size, uint_t assoc, uint_t lines_per_tag, uint_t line_size) 31287c478bd9Sstevel@tonic-gate { 31297c478bd9Sstevel@tonic-gate if (size == 0 || line_size == 0) 31307c478bd9Sstevel@tonic-gate return; 31317c478bd9Sstevel@tonic-gate add_amd_assoc(devi, label, assoc); 31327c478bd9Sstevel@tonic-gate /* 31337c478bd9Sstevel@tonic-gate * Most AMD parts have a sectored cache. Multiple cache lines are 31347c478bd9Sstevel@tonic-gate * associated with each tag. A sector consists of all cache lines 31357c478bd9Sstevel@tonic-gate * associated with a tag. For example, the AMD K6-III has a sector 31367c478bd9Sstevel@tonic-gate * size of 2 cache lines per tag. 31377c478bd9Sstevel@tonic-gate */ 31387c478bd9Sstevel@tonic-gate if (lines_per_tag != 0) 31397c478bd9Sstevel@tonic-gate add_cache_prop(devi, label, "lines-per-tag", lines_per_tag); 31407c478bd9Sstevel@tonic-gate add_cache_prop(devi, label, line_str, line_size); 31417c478bd9Sstevel@tonic-gate add_cache_prop(devi, label, size_str, size * 1024); 31427c478bd9Sstevel@tonic-gate } 31437c478bd9Sstevel@tonic-gate 31447c478bd9Sstevel@tonic-gate static void 31457c478bd9Sstevel@tonic-gate add_amd_l2_assoc(dev_info_t *devi, const char *label, uint_t assoc) 31467c478bd9Sstevel@tonic-gate { 31477c478bd9Sstevel@tonic-gate switch (assoc) { 31487c478bd9Sstevel@tonic-gate case 0: /* off */ 31497c478bd9Sstevel@tonic-gate break; 31507c478bd9Sstevel@tonic-gate case 1: 31517c478bd9Sstevel@tonic-gate case 2: 31527c478bd9Sstevel@tonic-gate case 4: 31537c478bd9Sstevel@tonic-gate add_cache_prop(devi, label, assoc_str, assoc); 31547c478bd9Sstevel@tonic-gate break; 31557c478bd9Sstevel@tonic-gate case 6: 31567c478bd9Sstevel@tonic-gate add_cache_prop(devi, label, assoc_str, 8); 31577c478bd9Sstevel@tonic-gate break; 31587c478bd9Sstevel@tonic-gate case 8: 31597c478bd9Sstevel@tonic-gate add_cache_prop(devi, label, assoc_str, 16); 31607c478bd9Sstevel@tonic-gate break; 31617c478bd9Sstevel@tonic-gate case 0xf: 31627c478bd9Sstevel@tonic-gate add_cache_prop(devi, label, fully_assoc, 1); 31637c478bd9Sstevel@tonic-gate break; 31647c478bd9Sstevel@tonic-gate default: /* reserved; ignore */ 31657c478bd9Sstevel@tonic-gate break; 31667c478bd9Sstevel@tonic-gate } 31677c478bd9Sstevel@tonic-gate } 31687c478bd9Sstevel@tonic-gate 31697c478bd9Sstevel@tonic-gate static void 31707c478bd9Sstevel@tonic-gate add_amd_l2_tlb(dev_info_t *devi, const char *label, uint_t assoc, uint_t size) 31717c478bd9Sstevel@tonic-gate { 31727c478bd9Sstevel@tonic-gate if (size == 0 || assoc == 0) 31737c478bd9Sstevel@tonic-gate return; 31747c478bd9Sstevel@tonic-gate add_amd_l2_assoc(devi, label, assoc); 31757c478bd9Sstevel@tonic-gate add_cache_prop(devi, label, size_str, size); 31767c478bd9Sstevel@tonic-gate } 31777c478bd9Sstevel@tonic-gate 31787c478bd9Sstevel@tonic-gate static void 31797c478bd9Sstevel@tonic-gate add_amd_l2_cache(dev_info_t *devi, const char *label, 31807c478bd9Sstevel@tonic-gate uint_t size, uint_t assoc, uint_t lines_per_tag, uint_t line_size) 31817c478bd9Sstevel@tonic-gate { 31827c478bd9Sstevel@tonic-gate if (size == 0 || assoc == 0 || line_size == 0) 31837c478bd9Sstevel@tonic-gate return; 31847c478bd9Sstevel@tonic-gate add_amd_l2_assoc(devi, label, assoc); 31857c478bd9Sstevel@tonic-gate if (lines_per_tag != 0) 31867c478bd9Sstevel@tonic-gate add_cache_prop(devi, label, "lines-per-tag", lines_per_tag); 31877c478bd9Sstevel@tonic-gate add_cache_prop(devi, label, line_str, line_size); 31887c478bd9Sstevel@tonic-gate add_cache_prop(devi, label, size_str, size * 1024); 31897c478bd9Sstevel@tonic-gate } 31907c478bd9Sstevel@tonic-gate 31917c478bd9Sstevel@tonic-gate static void 31927c478bd9Sstevel@tonic-gate amd_cache_info(struct cpuid_info *cpi, dev_info_t *devi) 31937c478bd9Sstevel@tonic-gate { 31948949bcd6Sandrei struct cpuid_regs *cp; 31957c478bd9Sstevel@tonic-gate 31967c478bd9Sstevel@tonic-gate if (cpi->cpi_xmaxeax < 0x80000005) 31977c478bd9Sstevel@tonic-gate return; 31987c478bd9Sstevel@tonic-gate cp = &cpi->cpi_extd[5]; 31997c478bd9Sstevel@tonic-gate 32007c478bd9Sstevel@tonic-gate /* 32017c478bd9Sstevel@tonic-gate * 4M/2M L1 TLB configuration 32027c478bd9Sstevel@tonic-gate * 32037c478bd9Sstevel@tonic-gate * We report the size for 2M pages because AMD uses two 32047c478bd9Sstevel@tonic-gate * TLB entries for one 4M page. 32057c478bd9Sstevel@tonic-gate */ 32067c478bd9Sstevel@tonic-gate add_amd_tlb(devi, "dtlb-2M", 32077c478bd9Sstevel@tonic-gate BITX(cp->cp_eax, 31, 24), BITX(cp->cp_eax, 23, 16)); 32087c478bd9Sstevel@tonic-gate add_amd_tlb(devi, "itlb-2M", 32097c478bd9Sstevel@tonic-gate BITX(cp->cp_eax, 15, 8), BITX(cp->cp_eax, 7, 0)); 32107c478bd9Sstevel@tonic-gate 32117c478bd9Sstevel@tonic-gate /* 32127c478bd9Sstevel@tonic-gate * 4K L1 TLB configuration 32137c478bd9Sstevel@tonic-gate */ 32147c478bd9Sstevel@tonic-gate 32157c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 32167c478bd9Sstevel@tonic-gate uint_t nentries; 32177c478bd9Sstevel@tonic-gate case X86_VENDOR_TM: 32187c478bd9Sstevel@tonic-gate if (cpi->cpi_family >= 5) { 32197c478bd9Sstevel@tonic-gate /* 32207c478bd9Sstevel@tonic-gate * Crusoe processors have 256 TLB entries, but 32217c478bd9Sstevel@tonic-gate * cpuid data format constrains them to only 32227c478bd9Sstevel@tonic-gate * reporting 255 of them. 32237c478bd9Sstevel@tonic-gate */ 32247c478bd9Sstevel@tonic-gate if ((nentries = BITX(cp->cp_ebx, 23, 16)) == 255) 32257c478bd9Sstevel@tonic-gate nentries = 256; 32267c478bd9Sstevel@tonic-gate /* 32277c478bd9Sstevel@tonic-gate * Crusoe processors also have a unified TLB 32287c478bd9Sstevel@tonic-gate */ 32297c478bd9Sstevel@tonic-gate add_amd_tlb(devi, "tlb-4K", BITX(cp->cp_ebx, 31, 24), 32307c478bd9Sstevel@tonic-gate nentries); 32317c478bd9Sstevel@tonic-gate break; 32327c478bd9Sstevel@tonic-gate } 32337c478bd9Sstevel@tonic-gate /*FALLTHROUGH*/ 32347c478bd9Sstevel@tonic-gate default: 32357c478bd9Sstevel@tonic-gate add_amd_tlb(devi, itlb4k_str, 32367c478bd9Sstevel@tonic-gate BITX(cp->cp_ebx, 31, 24), BITX(cp->cp_ebx, 23, 16)); 32377c478bd9Sstevel@tonic-gate add_amd_tlb(devi, dtlb4k_str, 32387c478bd9Sstevel@tonic-gate BITX(cp->cp_ebx, 15, 8), BITX(cp->cp_ebx, 7, 0)); 32397c478bd9Sstevel@tonic-gate break; 32407c478bd9Sstevel@tonic-gate } 32417c478bd9Sstevel@tonic-gate 32427c478bd9Sstevel@tonic-gate /* 32437c478bd9Sstevel@tonic-gate * data L1 cache configuration 32447c478bd9Sstevel@tonic-gate */ 32457c478bd9Sstevel@tonic-gate 32467c478bd9Sstevel@tonic-gate add_amd_cache(devi, l1_dcache_str, 32477c478bd9Sstevel@tonic-gate BITX(cp->cp_ecx, 31, 24), BITX(cp->cp_ecx, 23, 16), 32487c478bd9Sstevel@tonic-gate BITX(cp->cp_ecx, 15, 8), BITX(cp->cp_ecx, 7, 0)); 32497c478bd9Sstevel@tonic-gate 32507c478bd9Sstevel@tonic-gate /* 32517c478bd9Sstevel@tonic-gate * code L1 cache configuration 32527c478bd9Sstevel@tonic-gate */ 32537c478bd9Sstevel@tonic-gate 32547c478bd9Sstevel@tonic-gate add_amd_cache(devi, l1_icache_str, 32557c478bd9Sstevel@tonic-gate BITX(cp->cp_edx, 31, 24), BITX(cp->cp_edx, 23, 16), 32567c478bd9Sstevel@tonic-gate BITX(cp->cp_edx, 15, 8), BITX(cp->cp_edx, 7, 0)); 32577c478bd9Sstevel@tonic-gate 32587c478bd9Sstevel@tonic-gate if (cpi->cpi_xmaxeax < 0x80000006) 32597c478bd9Sstevel@tonic-gate return; 32607c478bd9Sstevel@tonic-gate cp = &cpi->cpi_extd[6]; 32617c478bd9Sstevel@tonic-gate 32627c478bd9Sstevel@tonic-gate /* Check for a unified L2 TLB for large pages */ 32637c478bd9Sstevel@tonic-gate 32647c478bd9Sstevel@tonic-gate if (BITX(cp->cp_eax, 31, 16) == 0) 32657c478bd9Sstevel@tonic-gate add_amd_l2_tlb(devi, "l2-tlb-2M", 32667c478bd9Sstevel@tonic-gate BITX(cp->cp_eax, 15, 12), BITX(cp->cp_eax, 11, 0)); 32677c478bd9Sstevel@tonic-gate else { 32687c478bd9Sstevel@tonic-gate add_amd_l2_tlb(devi, "l2-dtlb-2M", 32697c478bd9Sstevel@tonic-gate BITX(cp->cp_eax, 31, 28), BITX(cp->cp_eax, 27, 16)); 32707c478bd9Sstevel@tonic-gate add_amd_l2_tlb(devi, "l2-itlb-2M", 32717c478bd9Sstevel@tonic-gate BITX(cp->cp_eax, 15, 12), BITX(cp->cp_eax, 11, 0)); 32727c478bd9Sstevel@tonic-gate } 32737c478bd9Sstevel@tonic-gate 32747c478bd9Sstevel@tonic-gate /* Check for a unified L2 TLB for 4K pages */ 32757c478bd9Sstevel@tonic-gate 32767c478bd9Sstevel@tonic-gate if (BITX(cp->cp_ebx, 31, 16) == 0) { 32777c478bd9Sstevel@tonic-gate add_amd_l2_tlb(devi, "l2-tlb-4K", 32787c478bd9Sstevel@tonic-gate BITX(cp->cp_eax, 15, 12), BITX(cp->cp_eax, 11, 0)); 32797c478bd9Sstevel@tonic-gate } else { 32807c478bd9Sstevel@tonic-gate add_amd_l2_tlb(devi, "l2-dtlb-4K", 32817c478bd9Sstevel@tonic-gate BITX(cp->cp_eax, 31, 28), BITX(cp->cp_eax, 27, 16)); 32827c478bd9Sstevel@tonic-gate add_amd_l2_tlb(devi, "l2-itlb-4K", 32837c478bd9Sstevel@tonic-gate BITX(cp->cp_eax, 15, 12), BITX(cp->cp_eax, 11, 0)); 32847c478bd9Sstevel@tonic-gate } 32857c478bd9Sstevel@tonic-gate 32867c478bd9Sstevel@tonic-gate add_amd_l2_cache(devi, l2_cache_str, 32877c478bd9Sstevel@tonic-gate BITX(cp->cp_ecx, 31, 16), BITX(cp->cp_ecx, 15, 12), 32887c478bd9Sstevel@tonic-gate BITX(cp->cp_ecx, 11, 8), BITX(cp->cp_ecx, 7, 0)); 32897c478bd9Sstevel@tonic-gate } 32907c478bd9Sstevel@tonic-gate 32917c478bd9Sstevel@tonic-gate /* 32927c478bd9Sstevel@tonic-gate * There are two basic ways that the x86 world describes it cache 32937c478bd9Sstevel@tonic-gate * and tlb architecture - Intel's way and AMD's way. 32947c478bd9Sstevel@tonic-gate * 32957c478bd9Sstevel@tonic-gate * Return which flavor of cache architecture we should use 32967c478bd9Sstevel@tonic-gate */ 32977c478bd9Sstevel@tonic-gate static int 32987c478bd9Sstevel@tonic-gate x86_which_cacheinfo(struct cpuid_info *cpi) 32997c478bd9Sstevel@tonic-gate { 33007c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 33017c478bd9Sstevel@tonic-gate case X86_VENDOR_Intel: 33027c478bd9Sstevel@tonic-gate if (cpi->cpi_maxeax >= 2) 33037c478bd9Sstevel@tonic-gate return (X86_VENDOR_Intel); 33047c478bd9Sstevel@tonic-gate break; 33057c478bd9Sstevel@tonic-gate case X86_VENDOR_AMD: 33067c478bd9Sstevel@tonic-gate /* 33077c478bd9Sstevel@tonic-gate * The K5 model 1 was the first part from AMD that reported 33087c478bd9Sstevel@tonic-gate * cache sizes via extended cpuid functions. 33097c478bd9Sstevel@tonic-gate */ 33107c478bd9Sstevel@tonic-gate if (cpi->cpi_family > 5 || 33117c478bd9Sstevel@tonic-gate (cpi->cpi_family == 5 && cpi->cpi_model >= 1)) 33127c478bd9Sstevel@tonic-gate return (X86_VENDOR_AMD); 33137c478bd9Sstevel@tonic-gate break; 33147c478bd9Sstevel@tonic-gate case X86_VENDOR_TM: 33157c478bd9Sstevel@tonic-gate if (cpi->cpi_family >= 5) 33167c478bd9Sstevel@tonic-gate return (X86_VENDOR_AMD); 33177c478bd9Sstevel@tonic-gate /*FALLTHROUGH*/ 33187c478bd9Sstevel@tonic-gate default: 33197c478bd9Sstevel@tonic-gate /* 33207c478bd9Sstevel@tonic-gate * If they have extended CPU data for 0x80000005 33217c478bd9Sstevel@tonic-gate * then we assume they have AMD-format cache 33227c478bd9Sstevel@tonic-gate * information. 33237c478bd9Sstevel@tonic-gate * 33247c478bd9Sstevel@tonic-gate * If not, and the vendor happens to be Cyrix, 33257c478bd9Sstevel@tonic-gate * then try our-Cyrix specific handler. 33267c478bd9Sstevel@tonic-gate * 33277c478bd9Sstevel@tonic-gate * If we're not Cyrix, then assume we're using Intel's 33287c478bd9Sstevel@tonic-gate * table-driven format instead. 33297c478bd9Sstevel@tonic-gate */ 33307c478bd9Sstevel@tonic-gate if (cpi->cpi_xmaxeax >= 0x80000005) 33317c478bd9Sstevel@tonic-gate return (X86_VENDOR_AMD); 33327c478bd9Sstevel@tonic-gate else if (cpi->cpi_vendor == X86_VENDOR_Cyrix) 33337c478bd9Sstevel@tonic-gate return (X86_VENDOR_Cyrix); 33347c478bd9Sstevel@tonic-gate else if (cpi->cpi_maxeax >= 2) 33357c478bd9Sstevel@tonic-gate return (X86_VENDOR_Intel); 33367c478bd9Sstevel@tonic-gate break; 33377c478bd9Sstevel@tonic-gate } 33387c478bd9Sstevel@tonic-gate return (-1); 33397c478bd9Sstevel@tonic-gate } 33407c478bd9Sstevel@tonic-gate 33417c478bd9Sstevel@tonic-gate /* 33427c478bd9Sstevel@tonic-gate * create a node for the given cpu under the prom root node. 33437c478bd9Sstevel@tonic-gate * Also, create a cpu node in the device tree. 33447c478bd9Sstevel@tonic-gate */ 33457c478bd9Sstevel@tonic-gate static dev_info_t *cpu_nex_devi = NULL; 33467c478bd9Sstevel@tonic-gate static kmutex_t cpu_node_lock; 33477c478bd9Sstevel@tonic-gate 33487c478bd9Sstevel@tonic-gate /* 33497c478bd9Sstevel@tonic-gate * Called from post_startup() and mp_startup() 33507c478bd9Sstevel@tonic-gate */ 33517c478bd9Sstevel@tonic-gate void 33527c478bd9Sstevel@tonic-gate add_cpunode2devtree(processorid_t cpu_id, struct cpuid_info *cpi) 33537c478bd9Sstevel@tonic-gate { 33547c478bd9Sstevel@tonic-gate dev_info_t *cpu_devi; 33557c478bd9Sstevel@tonic-gate int create; 33567c478bd9Sstevel@tonic-gate 33577c478bd9Sstevel@tonic-gate mutex_enter(&cpu_node_lock); 33587c478bd9Sstevel@tonic-gate 33597c478bd9Sstevel@tonic-gate /* 33607c478bd9Sstevel@tonic-gate * create a nexus node for all cpus identified as 'cpu_id' under 33617c478bd9Sstevel@tonic-gate * the root node. 33627c478bd9Sstevel@tonic-gate */ 33637c478bd9Sstevel@tonic-gate if (cpu_nex_devi == NULL) { 33647c478bd9Sstevel@tonic-gate if (ndi_devi_alloc(ddi_root_node(), "cpus", 3365fa9e4066Sahrens (pnode_t)DEVI_SID_NODEID, &cpu_nex_devi) != NDI_SUCCESS) { 33667c478bd9Sstevel@tonic-gate mutex_exit(&cpu_node_lock); 33677c478bd9Sstevel@tonic-gate return; 33687c478bd9Sstevel@tonic-gate } 33697c478bd9Sstevel@tonic-gate (void) ndi_devi_online(cpu_nex_devi, 0); 33707c478bd9Sstevel@tonic-gate } 33717c478bd9Sstevel@tonic-gate 33727c478bd9Sstevel@tonic-gate /* 33737c478bd9Sstevel@tonic-gate * create a child node for cpu identified as 'cpu_id' 33747c478bd9Sstevel@tonic-gate */ 33757c478bd9Sstevel@tonic-gate cpu_devi = ddi_add_child(cpu_nex_devi, "cpu", DEVI_SID_NODEID, 33767c478bd9Sstevel@tonic-gate cpu_id); 33777c478bd9Sstevel@tonic-gate if (cpu_devi == NULL) { 33787c478bd9Sstevel@tonic-gate mutex_exit(&cpu_node_lock); 33797c478bd9Sstevel@tonic-gate return; 33807c478bd9Sstevel@tonic-gate } 33817c478bd9Sstevel@tonic-gate 33827c478bd9Sstevel@tonic-gate /* device_type */ 33837c478bd9Sstevel@tonic-gate 33847c478bd9Sstevel@tonic-gate (void) ndi_prop_update_string(DDI_DEV_T_NONE, cpu_devi, 33857c478bd9Sstevel@tonic-gate "device_type", "cpu"); 33867c478bd9Sstevel@tonic-gate 33877c478bd9Sstevel@tonic-gate /* reg */ 33887c478bd9Sstevel@tonic-gate 33897c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 33907c478bd9Sstevel@tonic-gate "reg", cpu_id); 33917c478bd9Sstevel@tonic-gate 33927c478bd9Sstevel@tonic-gate /* cpu-mhz, and clock-frequency */ 33937c478bd9Sstevel@tonic-gate 33947c478bd9Sstevel@tonic-gate if (cpu_freq > 0) { 33957c478bd9Sstevel@tonic-gate long long mul; 33967c478bd9Sstevel@tonic-gate 33977c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 33987c478bd9Sstevel@tonic-gate "cpu-mhz", cpu_freq); 33997c478bd9Sstevel@tonic-gate 34007c478bd9Sstevel@tonic-gate if ((mul = cpu_freq * 1000000LL) <= INT_MAX) 34017c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 34027c478bd9Sstevel@tonic-gate "clock-frequency", (int)mul); 34037c478bd9Sstevel@tonic-gate } 34047c478bd9Sstevel@tonic-gate 34057c478bd9Sstevel@tonic-gate (void) ndi_devi_online(cpu_devi, 0); 34067c478bd9Sstevel@tonic-gate 34077c478bd9Sstevel@tonic-gate if ((x86_feature & X86_CPUID) == 0) { 34087c478bd9Sstevel@tonic-gate mutex_exit(&cpu_node_lock); 34097c478bd9Sstevel@tonic-gate return; 34107c478bd9Sstevel@tonic-gate } 34117c478bd9Sstevel@tonic-gate 34127c478bd9Sstevel@tonic-gate /* vendor-id */ 34137c478bd9Sstevel@tonic-gate 34147c478bd9Sstevel@tonic-gate (void) ndi_prop_update_string(DDI_DEV_T_NONE, cpu_devi, 34157c478bd9Sstevel@tonic-gate "vendor-id", cpi->cpi_vendorstr); 34167c478bd9Sstevel@tonic-gate 34177c478bd9Sstevel@tonic-gate if (cpi->cpi_maxeax == 0) { 34187c478bd9Sstevel@tonic-gate mutex_exit(&cpu_node_lock); 34197c478bd9Sstevel@tonic-gate return; 34207c478bd9Sstevel@tonic-gate } 34217c478bd9Sstevel@tonic-gate 34227c478bd9Sstevel@tonic-gate /* 34237c478bd9Sstevel@tonic-gate * family, model, and step 34247c478bd9Sstevel@tonic-gate */ 34257c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 34267c478bd9Sstevel@tonic-gate "family", CPI_FAMILY(cpi)); 34277c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 34287c478bd9Sstevel@tonic-gate "cpu-model", CPI_MODEL(cpi)); 34297c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 34307c478bd9Sstevel@tonic-gate "stepping-id", CPI_STEP(cpi)); 34317c478bd9Sstevel@tonic-gate 34327c478bd9Sstevel@tonic-gate /* type */ 34337c478bd9Sstevel@tonic-gate 34347c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 34357c478bd9Sstevel@tonic-gate case X86_VENDOR_Intel: 34367c478bd9Sstevel@tonic-gate create = 1; 34377c478bd9Sstevel@tonic-gate break; 34387c478bd9Sstevel@tonic-gate default: 34397c478bd9Sstevel@tonic-gate create = 0; 34407c478bd9Sstevel@tonic-gate break; 34417c478bd9Sstevel@tonic-gate } 34427c478bd9Sstevel@tonic-gate if (create) 34437c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 34447c478bd9Sstevel@tonic-gate "type", CPI_TYPE(cpi)); 34457c478bd9Sstevel@tonic-gate 34467c478bd9Sstevel@tonic-gate /* ext-family */ 34477c478bd9Sstevel@tonic-gate 34487c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 34497c478bd9Sstevel@tonic-gate case X86_VENDOR_Intel: 34507c478bd9Sstevel@tonic-gate case X86_VENDOR_AMD: 34517c478bd9Sstevel@tonic-gate create = cpi->cpi_family >= 0xf; 34527c478bd9Sstevel@tonic-gate break; 34537c478bd9Sstevel@tonic-gate default: 34547c478bd9Sstevel@tonic-gate create = 0; 34557c478bd9Sstevel@tonic-gate break; 34567c478bd9Sstevel@tonic-gate } 34577c478bd9Sstevel@tonic-gate if (create) 34587c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 34597c478bd9Sstevel@tonic-gate "ext-family", CPI_FAMILY_XTD(cpi)); 34607c478bd9Sstevel@tonic-gate 34617c478bd9Sstevel@tonic-gate /* ext-model */ 34627c478bd9Sstevel@tonic-gate 34637c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 34647c478bd9Sstevel@tonic-gate case X86_VENDOR_Intel: 346563d3f7dfSkk208521 create = IS_EXTENDED_MODEL_INTEL(cpi); 346668c91426Sdmick break; 34677c478bd9Sstevel@tonic-gate case X86_VENDOR_AMD: 3468ee88d2b9Skchow create = CPI_FAMILY(cpi) == 0xf; 34697c478bd9Sstevel@tonic-gate break; 34707c478bd9Sstevel@tonic-gate default: 34717c478bd9Sstevel@tonic-gate create = 0; 34727c478bd9Sstevel@tonic-gate break; 34737c478bd9Sstevel@tonic-gate } 34747c478bd9Sstevel@tonic-gate if (create) 34757c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 34767c478bd9Sstevel@tonic-gate "ext-model", CPI_MODEL_XTD(cpi)); 34777c478bd9Sstevel@tonic-gate 34787c478bd9Sstevel@tonic-gate /* generation */ 34797c478bd9Sstevel@tonic-gate 34807c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 34817c478bd9Sstevel@tonic-gate case X86_VENDOR_AMD: 34827c478bd9Sstevel@tonic-gate /* 34837c478bd9Sstevel@tonic-gate * AMD K5 model 1 was the first part to support this 34847c478bd9Sstevel@tonic-gate */ 34857c478bd9Sstevel@tonic-gate create = cpi->cpi_xmaxeax >= 0x80000001; 34867c478bd9Sstevel@tonic-gate break; 34877c478bd9Sstevel@tonic-gate default: 34887c478bd9Sstevel@tonic-gate create = 0; 34897c478bd9Sstevel@tonic-gate break; 34907c478bd9Sstevel@tonic-gate } 34917c478bd9Sstevel@tonic-gate if (create) 34927c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 34937c478bd9Sstevel@tonic-gate "generation", BITX((cpi)->cpi_extd[1].cp_eax, 11, 8)); 34947c478bd9Sstevel@tonic-gate 34957c478bd9Sstevel@tonic-gate /* brand-id */ 34967c478bd9Sstevel@tonic-gate 34977c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 34987c478bd9Sstevel@tonic-gate case X86_VENDOR_Intel: 34997c478bd9Sstevel@tonic-gate /* 35007c478bd9Sstevel@tonic-gate * brand id first appeared on Pentium III Xeon model 8, 35017c478bd9Sstevel@tonic-gate * and Celeron model 8 processors and Opteron 35027c478bd9Sstevel@tonic-gate */ 35037c478bd9Sstevel@tonic-gate create = cpi->cpi_family > 6 || 35047c478bd9Sstevel@tonic-gate (cpi->cpi_family == 6 && cpi->cpi_model >= 8); 35057c478bd9Sstevel@tonic-gate break; 35067c478bd9Sstevel@tonic-gate case X86_VENDOR_AMD: 35077c478bd9Sstevel@tonic-gate create = cpi->cpi_family >= 0xf; 35087c478bd9Sstevel@tonic-gate break; 35097c478bd9Sstevel@tonic-gate default: 35107c478bd9Sstevel@tonic-gate create = 0; 35117c478bd9Sstevel@tonic-gate break; 35127c478bd9Sstevel@tonic-gate } 35137c478bd9Sstevel@tonic-gate if (create && cpi->cpi_brandid != 0) { 35147c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 35157c478bd9Sstevel@tonic-gate "brand-id", cpi->cpi_brandid); 35167c478bd9Sstevel@tonic-gate } 35177c478bd9Sstevel@tonic-gate 35187c478bd9Sstevel@tonic-gate /* chunks, and apic-id */ 35197c478bd9Sstevel@tonic-gate 35207c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 35217c478bd9Sstevel@tonic-gate /* 35227c478bd9Sstevel@tonic-gate * first available on Pentium IV and Opteron (K8) 35237c478bd9Sstevel@tonic-gate */ 35245ff02082Sdmick case X86_VENDOR_Intel: 35255ff02082Sdmick create = IS_NEW_F6(cpi) || cpi->cpi_family >= 0xf; 35265ff02082Sdmick break; 35275ff02082Sdmick case X86_VENDOR_AMD: 35287c478bd9Sstevel@tonic-gate create = cpi->cpi_family >= 0xf; 35297c478bd9Sstevel@tonic-gate break; 35307c478bd9Sstevel@tonic-gate default: 35317c478bd9Sstevel@tonic-gate create = 0; 35327c478bd9Sstevel@tonic-gate break; 35337c478bd9Sstevel@tonic-gate } 35347c478bd9Sstevel@tonic-gate if (create) { 35357c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 35367c478bd9Sstevel@tonic-gate "chunks", CPI_CHUNKS(cpi)); 35377c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 3538b6917abeSmishra "apic-id", cpi->cpi_apicid); 35397aec1d6eScindi if (cpi->cpi_chipid >= 0) { 35407c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 35417c478bd9Sstevel@tonic-gate "chip#", cpi->cpi_chipid); 35427aec1d6eScindi (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 35437aec1d6eScindi "clog#", cpi->cpi_clogid); 35447aec1d6eScindi } 35457c478bd9Sstevel@tonic-gate } 35467c478bd9Sstevel@tonic-gate 35477c478bd9Sstevel@tonic-gate /* cpuid-features */ 35487c478bd9Sstevel@tonic-gate 35497c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 35507c478bd9Sstevel@tonic-gate "cpuid-features", CPI_FEATURES_EDX(cpi)); 35517c478bd9Sstevel@tonic-gate 35527c478bd9Sstevel@tonic-gate 35537c478bd9Sstevel@tonic-gate /* cpuid-features-ecx */ 35547c478bd9Sstevel@tonic-gate 35557c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 35567c478bd9Sstevel@tonic-gate case X86_VENDOR_Intel: 35575ff02082Sdmick create = IS_NEW_F6(cpi) || cpi->cpi_family >= 0xf; 35587c478bd9Sstevel@tonic-gate break; 35597c478bd9Sstevel@tonic-gate default: 35607c478bd9Sstevel@tonic-gate create = 0; 35617c478bd9Sstevel@tonic-gate break; 35627c478bd9Sstevel@tonic-gate } 35637c478bd9Sstevel@tonic-gate if (create) 35647c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 35657c478bd9Sstevel@tonic-gate "cpuid-features-ecx", CPI_FEATURES_ECX(cpi)); 35667c478bd9Sstevel@tonic-gate 35677c478bd9Sstevel@tonic-gate /* ext-cpuid-features */ 35687c478bd9Sstevel@tonic-gate 35697c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 35705ff02082Sdmick case X86_VENDOR_Intel: 35717c478bd9Sstevel@tonic-gate case X86_VENDOR_AMD: 35727c478bd9Sstevel@tonic-gate case X86_VENDOR_Cyrix: 35737c478bd9Sstevel@tonic-gate case X86_VENDOR_TM: 35747c478bd9Sstevel@tonic-gate case X86_VENDOR_Centaur: 35757c478bd9Sstevel@tonic-gate create = cpi->cpi_xmaxeax >= 0x80000001; 35767c478bd9Sstevel@tonic-gate break; 35777c478bd9Sstevel@tonic-gate default: 35787c478bd9Sstevel@tonic-gate create = 0; 35797c478bd9Sstevel@tonic-gate break; 35807c478bd9Sstevel@tonic-gate } 35815ff02082Sdmick if (create) { 35827c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 35837c478bd9Sstevel@tonic-gate "ext-cpuid-features", CPI_FEATURES_XTD_EDX(cpi)); 35845ff02082Sdmick (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 35855ff02082Sdmick "ext-cpuid-features-ecx", CPI_FEATURES_XTD_ECX(cpi)); 35865ff02082Sdmick } 35877c478bd9Sstevel@tonic-gate 35887c478bd9Sstevel@tonic-gate /* 35897c478bd9Sstevel@tonic-gate * Brand String first appeared in Intel Pentium IV, AMD K5 35907c478bd9Sstevel@tonic-gate * model 1, and Cyrix GXm. On earlier models we try and 35917c478bd9Sstevel@tonic-gate * simulate something similar .. so this string should always 35927c478bd9Sstevel@tonic-gate * same -something- about the processor, however lame. 35937c478bd9Sstevel@tonic-gate */ 35947c478bd9Sstevel@tonic-gate (void) ndi_prop_update_string(DDI_DEV_T_NONE, cpu_devi, 35957c478bd9Sstevel@tonic-gate "brand-string", cpi->cpi_brandstr); 35967c478bd9Sstevel@tonic-gate 35977c478bd9Sstevel@tonic-gate /* 35987c478bd9Sstevel@tonic-gate * Finally, cache and tlb information 35997c478bd9Sstevel@tonic-gate */ 36007c478bd9Sstevel@tonic-gate switch (x86_which_cacheinfo(cpi)) { 36017c478bd9Sstevel@tonic-gate case X86_VENDOR_Intel: 36027c478bd9Sstevel@tonic-gate intel_walk_cacheinfo(cpi, cpu_devi, add_cacheent_props); 36037c478bd9Sstevel@tonic-gate break; 36047c478bd9Sstevel@tonic-gate case X86_VENDOR_Cyrix: 36057c478bd9Sstevel@tonic-gate cyrix_walk_cacheinfo(cpi, cpu_devi, add_cacheent_props); 36067c478bd9Sstevel@tonic-gate break; 36077c478bd9Sstevel@tonic-gate case X86_VENDOR_AMD: 36087c478bd9Sstevel@tonic-gate amd_cache_info(cpi, cpu_devi); 36097c478bd9Sstevel@tonic-gate break; 36107c478bd9Sstevel@tonic-gate default: 36117c478bd9Sstevel@tonic-gate break; 36127c478bd9Sstevel@tonic-gate } 36137c478bd9Sstevel@tonic-gate 36147c478bd9Sstevel@tonic-gate mutex_exit(&cpu_node_lock); 36157c478bd9Sstevel@tonic-gate } 36167c478bd9Sstevel@tonic-gate 36177c478bd9Sstevel@tonic-gate struct l2info { 36187c478bd9Sstevel@tonic-gate int *l2i_csz; 36197c478bd9Sstevel@tonic-gate int *l2i_lsz; 36207c478bd9Sstevel@tonic-gate int *l2i_assoc; 36217c478bd9Sstevel@tonic-gate int l2i_ret; 36227c478bd9Sstevel@tonic-gate }; 36237c478bd9Sstevel@tonic-gate 36247c478bd9Sstevel@tonic-gate /* 36257c478bd9Sstevel@tonic-gate * A cacheinfo walker that fetches the size, line-size and associativity 36267c478bd9Sstevel@tonic-gate * of the L2 cache 36277c478bd9Sstevel@tonic-gate */ 36287c478bd9Sstevel@tonic-gate static int 36297c478bd9Sstevel@tonic-gate intel_l2cinfo(void *arg, const struct cachetab *ct) 36307c478bd9Sstevel@tonic-gate { 36317c478bd9Sstevel@tonic-gate struct l2info *l2i = arg; 36327c478bd9Sstevel@tonic-gate int *ip; 36337c478bd9Sstevel@tonic-gate 36347c478bd9Sstevel@tonic-gate if (ct->ct_label != l2_cache_str && 36357c478bd9Sstevel@tonic-gate ct->ct_label != sl2_cache_str) 36367c478bd9Sstevel@tonic-gate return (0); /* not an L2 -- keep walking */ 36377c478bd9Sstevel@tonic-gate 36387c478bd9Sstevel@tonic-gate if ((ip = l2i->l2i_csz) != NULL) 36397c478bd9Sstevel@tonic-gate *ip = ct->ct_size; 36407c478bd9Sstevel@tonic-gate if ((ip = l2i->l2i_lsz) != NULL) 36417c478bd9Sstevel@tonic-gate *ip = ct->ct_line_size; 36427c478bd9Sstevel@tonic-gate if ((ip = l2i->l2i_assoc) != NULL) 36437c478bd9Sstevel@tonic-gate *ip = ct->ct_assoc; 36447c478bd9Sstevel@tonic-gate l2i->l2i_ret = ct->ct_size; 36457c478bd9Sstevel@tonic-gate return (1); /* was an L2 -- terminate walk */ 36467c478bd9Sstevel@tonic-gate } 36477c478bd9Sstevel@tonic-gate 3648606303c9Skchow /* 3649606303c9Skchow * AMD L2/L3 Cache and TLB Associativity Field Definition: 3650606303c9Skchow * 3651606303c9Skchow * Unlike the associativity for the L1 cache and tlb where the 8 bit 3652606303c9Skchow * value is the associativity, the associativity for the L2 cache and 3653606303c9Skchow * tlb is encoded in the following table. The 4 bit L2 value serves as 3654606303c9Skchow * an index into the amd_afd[] array to determine the associativity. 3655606303c9Skchow * -1 is undefined. 0 is fully associative. 3656606303c9Skchow */ 3657606303c9Skchow 3658606303c9Skchow static int amd_afd[] = 3659606303c9Skchow {-1, 1, 2, -1, 4, -1, 8, -1, 16, -1, 32, 48, 64, 96, 128, 0}; 3660606303c9Skchow 36617c478bd9Sstevel@tonic-gate static void 36627c478bd9Sstevel@tonic-gate amd_l2cacheinfo(struct cpuid_info *cpi, struct l2info *l2i) 36637c478bd9Sstevel@tonic-gate { 36648949bcd6Sandrei struct cpuid_regs *cp; 36657c478bd9Sstevel@tonic-gate uint_t size, assoc; 3666606303c9Skchow int i; 36677c478bd9Sstevel@tonic-gate int *ip; 36687c478bd9Sstevel@tonic-gate 36697c478bd9Sstevel@tonic-gate if (cpi->cpi_xmaxeax < 0x80000006) 36707c478bd9Sstevel@tonic-gate return; 36717c478bd9Sstevel@tonic-gate cp = &cpi->cpi_extd[6]; 36727c478bd9Sstevel@tonic-gate 3673606303c9Skchow if ((i = BITX(cp->cp_ecx, 15, 12)) != 0 && 36747c478bd9Sstevel@tonic-gate (size = BITX(cp->cp_ecx, 31, 16)) != 0) { 36757c478bd9Sstevel@tonic-gate uint_t cachesz = size * 1024; 3676606303c9Skchow assoc = amd_afd[i]; 36777c478bd9Sstevel@tonic-gate 3678606303c9Skchow ASSERT(assoc != -1); 36797c478bd9Sstevel@tonic-gate 36807c478bd9Sstevel@tonic-gate if ((ip = l2i->l2i_csz) != NULL) 36817c478bd9Sstevel@tonic-gate *ip = cachesz; 36827c478bd9Sstevel@tonic-gate if ((ip = l2i->l2i_lsz) != NULL) 36837c478bd9Sstevel@tonic-gate *ip = BITX(cp->cp_ecx, 7, 0); 36847c478bd9Sstevel@tonic-gate if ((ip = l2i->l2i_assoc) != NULL) 36857c478bd9Sstevel@tonic-gate *ip = assoc; 36867c478bd9Sstevel@tonic-gate l2i->l2i_ret = cachesz; 36877c478bd9Sstevel@tonic-gate } 36887c478bd9Sstevel@tonic-gate } 36897c478bd9Sstevel@tonic-gate 36907c478bd9Sstevel@tonic-gate int 36917c478bd9Sstevel@tonic-gate getl2cacheinfo(cpu_t *cpu, int *csz, int *lsz, int *assoc) 36927c478bd9Sstevel@tonic-gate { 36937c478bd9Sstevel@tonic-gate struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 36947c478bd9Sstevel@tonic-gate struct l2info __l2info, *l2i = &__l2info; 36957c478bd9Sstevel@tonic-gate 36967c478bd9Sstevel@tonic-gate l2i->l2i_csz = csz; 36977c478bd9Sstevel@tonic-gate l2i->l2i_lsz = lsz; 36987c478bd9Sstevel@tonic-gate l2i->l2i_assoc = assoc; 36997c478bd9Sstevel@tonic-gate l2i->l2i_ret = -1; 37007c478bd9Sstevel@tonic-gate 37017c478bd9Sstevel@tonic-gate switch (x86_which_cacheinfo(cpi)) { 37027c478bd9Sstevel@tonic-gate case X86_VENDOR_Intel: 37037c478bd9Sstevel@tonic-gate intel_walk_cacheinfo(cpi, l2i, intel_l2cinfo); 37047c478bd9Sstevel@tonic-gate break; 37057c478bd9Sstevel@tonic-gate case X86_VENDOR_Cyrix: 37067c478bd9Sstevel@tonic-gate cyrix_walk_cacheinfo(cpi, l2i, intel_l2cinfo); 37077c478bd9Sstevel@tonic-gate break; 37087c478bd9Sstevel@tonic-gate case X86_VENDOR_AMD: 37097c478bd9Sstevel@tonic-gate amd_l2cacheinfo(cpi, l2i); 37107c478bd9Sstevel@tonic-gate break; 37117c478bd9Sstevel@tonic-gate default: 37127c478bd9Sstevel@tonic-gate break; 37137c478bd9Sstevel@tonic-gate } 37147c478bd9Sstevel@tonic-gate return (l2i->l2i_ret); 37157c478bd9Sstevel@tonic-gate } 3716f98fbcecSbholler 3717843e1988Sjohnlev #if !defined(__xpv) 3718843e1988Sjohnlev 37195b8a6efeSbholler uint32_t * 37205b8a6efeSbholler cpuid_mwait_alloc(cpu_t *cpu) 37215b8a6efeSbholler { 37225b8a6efeSbholler uint32_t *ret; 37235b8a6efeSbholler size_t mwait_size; 37245b8a6efeSbholler 37255b8a6efeSbholler ASSERT(cpuid_checkpass(cpu, 2)); 37265b8a6efeSbholler 37275b8a6efeSbholler mwait_size = cpu->cpu_m.mcpu_cpi->cpi_mwait.mon_max; 37285b8a6efeSbholler if (mwait_size == 0) 37295b8a6efeSbholler return (NULL); 37305b8a6efeSbholler 37315b8a6efeSbholler /* 37325b8a6efeSbholler * kmem_alloc() returns cache line size aligned data for mwait_size 37335b8a6efeSbholler * allocations. mwait_size is currently cache line sized. Neither 37345b8a6efeSbholler * of these implementation details are guarantied to be true in the 37355b8a6efeSbholler * future. 37365b8a6efeSbholler * 37375b8a6efeSbholler * First try allocating mwait_size as kmem_alloc() currently returns 37385b8a6efeSbholler * correctly aligned memory. If kmem_alloc() does not return 37395b8a6efeSbholler * mwait_size aligned memory, then use mwait_size ROUNDUP. 37405b8a6efeSbholler * 37415b8a6efeSbholler * Set cpi_mwait.buf_actual and cpi_mwait.size_actual in case we 37425b8a6efeSbholler * decide to free this memory. 37435b8a6efeSbholler */ 37445b8a6efeSbholler ret = kmem_zalloc(mwait_size, KM_SLEEP); 37455b8a6efeSbholler if (ret == (uint32_t *)P2ROUNDUP((uintptr_t)ret, mwait_size)) { 37465b8a6efeSbholler cpu->cpu_m.mcpu_cpi->cpi_mwait.buf_actual = ret; 37475b8a6efeSbholler cpu->cpu_m.mcpu_cpi->cpi_mwait.size_actual = mwait_size; 37485b8a6efeSbholler *ret = MWAIT_RUNNING; 37495b8a6efeSbholler return (ret); 37505b8a6efeSbholler } else { 37515b8a6efeSbholler kmem_free(ret, mwait_size); 37525b8a6efeSbholler ret = kmem_zalloc(mwait_size * 2, KM_SLEEP); 37535b8a6efeSbholler cpu->cpu_m.mcpu_cpi->cpi_mwait.buf_actual = ret; 37545b8a6efeSbholler cpu->cpu_m.mcpu_cpi->cpi_mwait.size_actual = mwait_size * 2; 37555b8a6efeSbholler ret = (uint32_t *)P2ROUNDUP((uintptr_t)ret, mwait_size); 37565b8a6efeSbholler *ret = MWAIT_RUNNING; 37575b8a6efeSbholler return (ret); 37585b8a6efeSbholler } 37595b8a6efeSbholler } 37605b8a6efeSbholler 37615b8a6efeSbholler void 37625b8a6efeSbholler cpuid_mwait_free(cpu_t *cpu) 3763f98fbcecSbholler { 3764f98fbcecSbholler ASSERT(cpuid_checkpass(cpu, 2)); 37655b8a6efeSbholler 37665b8a6efeSbholler if (cpu->cpu_m.mcpu_cpi->cpi_mwait.buf_actual != NULL && 37675b8a6efeSbholler cpu->cpu_m.mcpu_cpi->cpi_mwait.size_actual > 0) { 37685b8a6efeSbholler kmem_free(cpu->cpu_m.mcpu_cpi->cpi_mwait.buf_actual, 37695b8a6efeSbholler cpu->cpu_m.mcpu_cpi->cpi_mwait.size_actual); 37705b8a6efeSbholler } 37715b8a6efeSbholler 37725b8a6efeSbholler cpu->cpu_m.mcpu_cpi->cpi_mwait.buf_actual = NULL; 37735b8a6efeSbholler cpu->cpu_m.mcpu_cpi->cpi_mwait.size_actual = 0; 3774f98fbcecSbholler } 3775843e1988Sjohnlev 3776247dbb3dSsudheer void 3777247dbb3dSsudheer patch_tsc_read(int flag) 3778247dbb3dSsudheer { 3779247dbb3dSsudheer size_t cnt; 3780*e4b86885SCheng Sean Ye 3781247dbb3dSsudheer switch (flag) { 3782247dbb3dSsudheer case X86_NO_TSC: 3783247dbb3dSsudheer cnt = &_no_rdtsc_end - &_no_rdtsc_start; 37842b0bcb26Ssudheer (void) memcpy((void *)tsc_read, (void *)&_no_rdtsc_start, cnt); 3785247dbb3dSsudheer break; 3786247dbb3dSsudheer case X86_HAVE_TSCP: 3787247dbb3dSsudheer cnt = &_tscp_end - &_tscp_start; 37882b0bcb26Ssudheer (void) memcpy((void *)tsc_read, (void *)&_tscp_start, cnt); 3789247dbb3dSsudheer break; 3790247dbb3dSsudheer case X86_TSC_MFENCE: 3791247dbb3dSsudheer cnt = &_tsc_mfence_end - &_tsc_mfence_start; 37922b0bcb26Ssudheer (void) memcpy((void *)tsc_read, 37932b0bcb26Ssudheer (void *)&_tsc_mfence_start, cnt); 3794247dbb3dSsudheer break; 379515363b27Ssudheer case X86_TSC_LFENCE: 379615363b27Ssudheer cnt = &_tsc_lfence_end - &_tsc_lfence_start; 379715363b27Ssudheer (void) memcpy((void *)tsc_read, 379815363b27Ssudheer (void *)&_tsc_lfence_start, cnt); 379915363b27Ssudheer break; 3800247dbb3dSsudheer default: 3801247dbb3dSsudheer break; 3802247dbb3dSsudheer } 3803247dbb3dSsudheer } 3804247dbb3dSsudheer 3805843e1988Sjohnlev #endif /* !__xpv */ 3806