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 /* 22fb2f18f8Sesaxe * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 277c478bd9Sstevel@tonic-gate 287c478bd9Sstevel@tonic-gate /* 297c478bd9Sstevel@tonic-gate * Various routines to handle identification 307c478bd9Sstevel@tonic-gate * and classification of x86 processors. 317c478bd9Sstevel@tonic-gate */ 327c478bd9Sstevel@tonic-gate 337c478bd9Sstevel@tonic-gate #include <sys/types.h> 347c478bd9Sstevel@tonic-gate #include <sys/archsystm.h> 357c478bd9Sstevel@tonic-gate #include <sys/x86_archext.h> 367c478bd9Sstevel@tonic-gate #include <sys/kmem.h> 377c478bd9Sstevel@tonic-gate #include <sys/systm.h> 387c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h> 397c478bd9Sstevel@tonic-gate #include <sys/sunddi.h> 407c478bd9Sstevel@tonic-gate #include <sys/sunndi.h> 417c478bd9Sstevel@tonic-gate #include <sys/cpuvar.h> 427c478bd9Sstevel@tonic-gate #include <sys/processor.h> 435b8a6efeSbholler #include <sys/sysmacros.h> 44fb2f18f8Sesaxe #include <sys/pg.h> 457c478bd9Sstevel@tonic-gate #include <sys/fp.h> 467c478bd9Sstevel@tonic-gate #include <sys/controlregs.h> 477c478bd9Sstevel@tonic-gate #include <sys/auxv_386.h> 487c478bd9Sstevel@tonic-gate #include <sys/bitmap.h> 497c478bd9Sstevel@tonic-gate #include <sys/memnode.h> 507c478bd9Sstevel@tonic-gate 517c478bd9Sstevel@tonic-gate /* 527c478bd9Sstevel@tonic-gate * Pass 0 of cpuid feature analysis happens in locore. It contains special code 537c478bd9Sstevel@tonic-gate * to recognize Cyrix processors that are not cpuid-compliant, and to deal with 547c478bd9Sstevel@tonic-gate * them accordingly. For most modern processors, feature detection occurs here 557c478bd9Sstevel@tonic-gate * in pass 1. 567c478bd9Sstevel@tonic-gate * 577c478bd9Sstevel@tonic-gate * Pass 1 of cpuid feature analysis happens just at the beginning of mlsetup() 587c478bd9Sstevel@tonic-gate * for the boot CPU and does the basic analysis that the early kernel needs. 597c478bd9Sstevel@tonic-gate * x86_feature is set based on the return value of cpuid_pass1() of the boot 607c478bd9Sstevel@tonic-gate * CPU. 617c478bd9Sstevel@tonic-gate * 627c478bd9Sstevel@tonic-gate * Pass 1 includes: 637c478bd9Sstevel@tonic-gate * 647c478bd9Sstevel@tonic-gate * o Determining vendor/model/family/stepping and setting x86_type and 657c478bd9Sstevel@tonic-gate * x86_vendor accordingly. 667c478bd9Sstevel@tonic-gate * o Processing the feature flags returned by the cpuid instruction while 677c478bd9Sstevel@tonic-gate * applying any workarounds or tricks for the specific processor. 687c478bd9Sstevel@tonic-gate * o Mapping the feature flags into Solaris feature bits (X86_*). 697c478bd9Sstevel@tonic-gate * o Processing extended feature flags if supported by the processor, 707c478bd9Sstevel@tonic-gate * again while applying specific processor knowledge. 717c478bd9Sstevel@tonic-gate * o Determining the CMT characteristics of the system. 727c478bd9Sstevel@tonic-gate * 737c478bd9Sstevel@tonic-gate * Pass 1 is done on non-boot CPUs during their initialization and the results 747c478bd9Sstevel@tonic-gate * are used only as a meager attempt at ensuring that all processors within the 757c478bd9Sstevel@tonic-gate * system support the same features. 767c478bd9Sstevel@tonic-gate * 777c478bd9Sstevel@tonic-gate * Pass 2 of cpuid feature analysis happens just at the beginning 787c478bd9Sstevel@tonic-gate * of startup(). It just copies in and corrects the remainder 797c478bd9Sstevel@tonic-gate * of the cpuid data we depend on: standard cpuid functions that we didn't 807c478bd9Sstevel@tonic-gate * need for pass1 feature analysis, and extended cpuid functions beyond the 817c478bd9Sstevel@tonic-gate * simple feature processing done in pass1. 827c478bd9Sstevel@tonic-gate * 837c478bd9Sstevel@tonic-gate * Pass 3 of cpuid analysis is invoked after basic kernel services; in 847c478bd9Sstevel@tonic-gate * particular kernel memory allocation has been made available. It creates a 857c478bd9Sstevel@tonic-gate * readable brand string based on the data collected in the first two passes. 867c478bd9Sstevel@tonic-gate * 877c478bd9Sstevel@tonic-gate * Pass 4 of cpuid analysis is invoked after post_startup() when all 887c478bd9Sstevel@tonic-gate * the support infrastructure for various hardware features has been 897c478bd9Sstevel@tonic-gate * initialized. It determines which processor features will be reported 907c478bd9Sstevel@tonic-gate * to userland via the aux vector. 917c478bd9Sstevel@tonic-gate * 927c478bd9Sstevel@tonic-gate * All passes are executed on all CPUs, but only the boot CPU determines what 937c478bd9Sstevel@tonic-gate * features the kernel will use. 947c478bd9Sstevel@tonic-gate * 957c478bd9Sstevel@tonic-gate * Much of the worst junk in this file is for the support of processors 967c478bd9Sstevel@tonic-gate * that didn't really implement the cpuid instruction properly. 977c478bd9Sstevel@tonic-gate * 987c478bd9Sstevel@tonic-gate * NOTE: The accessor functions (cpuid_get*) are aware of, and ASSERT upon, 997c478bd9Sstevel@tonic-gate * the pass numbers. Accordingly, changes to the pass code may require changes 1007c478bd9Sstevel@tonic-gate * to the accessor code. 1017c478bd9Sstevel@tonic-gate */ 1027c478bd9Sstevel@tonic-gate 1037c478bd9Sstevel@tonic-gate uint_t x86_feature = 0; 1047c478bd9Sstevel@tonic-gate uint_t x86_vendor = X86_VENDOR_IntelClone; 1057c478bd9Sstevel@tonic-gate uint_t x86_type = X86_TYPE_OTHER; 1067c478bd9Sstevel@tonic-gate 1077c478bd9Sstevel@tonic-gate uint_t pentiumpro_bug4046376; 1087c478bd9Sstevel@tonic-gate uint_t pentiumpro_bug4064495; 1097c478bd9Sstevel@tonic-gate 1107c478bd9Sstevel@tonic-gate uint_t enable486; 1117c478bd9Sstevel@tonic-gate 1127c478bd9Sstevel@tonic-gate /* 1137c478bd9Sstevel@tonic-gate * This set of strings are for processors rumored to support the cpuid 1147c478bd9Sstevel@tonic-gate * instruction, and is used by locore.s to figure out how to set x86_vendor 1157c478bd9Sstevel@tonic-gate */ 1167c478bd9Sstevel@tonic-gate const char CyrixInstead[] = "CyrixInstead"; 1177c478bd9Sstevel@tonic-gate 1187c478bd9Sstevel@tonic-gate /* 119f98fbcecSbholler * monitor/mwait info. 1205b8a6efeSbholler * 1215b8a6efeSbholler * size_actual and buf_actual are the real address and size allocated to get 1225b8a6efeSbholler * proper mwait_buf alignement. buf_actual and size_actual should be passed 1235b8a6efeSbholler * to kmem_free(). Currently kmem_alloc() and mwait happen to both use 1245b8a6efeSbholler * processor cache-line alignment, but this is not guarantied in the furture. 125f98fbcecSbholler */ 126f98fbcecSbholler struct mwait_info { 127f98fbcecSbholler size_t mon_min; /* min size to avoid missed wakeups */ 128f98fbcecSbholler size_t mon_max; /* size to avoid false wakeups */ 1295b8a6efeSbholler size_t size_actual; /* size actually allocated */ 1305b8a6efeSbholler void *buf_actual; /* memory actually allocated */ 131f98fbcecSbholler uint32_t support; /* processor support of monitor/mwait */ 132f98fbcecSbholler }; 133f98fbcecSbholler 134f98fbcecSbholler /* 1357c478bd9Sstevel@tonic-gate * These constants determine how many of the elements of the 1367c478bd9Sstevel@tonic-gate * cpuid we cache in the cpuid_info data structure; the 1377c478bd9Sstevel@tonic-gate * remaining elements are accessible via the cpuid instruction. 1387c478bd9Sstevel@tonic-gate */ 1397c478bd9Sstevel@tonic-gate 1407c478bd9Sstevel@tonic-gate #define NMAX_CPI_STD 6 /* eax = 0 .. 5 */ 1417c478bd9Sstevel@tonic-gate #define NMAX_CPI_EXTD 9 /* eax = 0x80000000 .. 0x80000008 */ 1427c478bd9Sstevel@tonic-gate 1437c478bd9Sstevel@tonic-gate struct cpuid_info { 1447c478bd9Sstevel@tonic-gate uint_t cpi_pass; /* last pass completed */ 1457c478bd9Sstevel@tonic-gate /* 1467c478bd9Sstevel@tonic-gate * standard function information 1477c478bd9Sstevel@tonic-gate */ 1487c478bd9Sstevel@tonic-gate uint_t cpi_maxeax; /* fn 0: %eax */ 1497c478bd9Sstevel@tonic-gate char cpi_vendorstr[13]; /* fn 0: %ebx:%ecx:%edx */ 1507c478bd9Sstevel@tonic-gate uint_t cpi_vendor; /* enum of cpi_vendorstr */ 1517c478bd9Sstevel@tonic-gate 1527c478bd9Sstevel@tonic-gate uint_t cpi_family; /* fn 1: extended family */ 1537c478bd9Sstevel@tonic-gate uint_t cpi_model; /* fn 1: extended model */ 1547c478bd9Sstevel@tonic-gate uint_t cpi_step; /* fn 1: stepping */ 1557c478bd9Sstevel@tonic-gate chipid_t cpi_chipid; /* fn 1: %ebx: chip # on ht cpus */ 1567c478bd9Sstevel@tonic-gate uint_t cpi_brandid; /* fn 1: %ebx: brand ID */ 1577c478bd9Sstevel@tonic-gate int cpi_clogid; /* fn 1: %ebx: thread # */ 1588949bcd6Sandrei uint_t cpi_ncpu_per_chip; /* fn 1: %ebx: logical cpu count */ 1597c478bd9Sstevel@tonic-gate uint8_t cpi_cacheinfo[16]; /* fn 2: intel-style cache desc */ 1607c478bd9Sstevel@tonic-gate uint_t cpi_ncache; /* fn 2: number of elements */ 161d129bde2Sesaxe uint_t cpi_ncpu_shr_last_cache; /* fn 4: %eax: ncpus sharing cache */ 162d129bde2Sesaxe id_t cpi_last_lvl_cacheid; /* fn 4: %eax: derived cache id */ 163d129bde2Sesaxe uint_t cpi_std_4_size; /* fn 4: number of fn 4 elements */ 164d129bde2Sesaxe struct cpuid_regs **cpi_std_4; /* fn 4: %ecx == 0 .. fn4_size */ 1658949bcd6Sandrei struct cpuid_regs cpi_std[NMAX_CPI_STD]; /* 0 .. 5 */ 1667c478bd9Sstevel@tonic-gate /* 1677c478bd9Sstevel@tonic-gate * extended function information 1687c478bd9Sstevel@tonic-gate */ 1697c478bd9Sstevel@tonic-gate uint_t cpi_xmaxeax; /* fn 0x80000000: %eax */ 1707c478bd9Sstevel@tonic-gate char cpi_brandstr[49]; /* fn 0x8000000[234] */ 1717c478bd9Sstevel@tonic-gate uint8_t cpi_pabits; /* fn 0x80000006: %eax */ 1727c478bd9Sstevel@tonic-gate uint8_t cpi_vabits; /* fn 0x80000006: %eax */ 1738949bcd6Sandrei struct cpuid_regs cpi_extd[NMAX_CPI_EXTD]; /* 0x8000000[0-8] */ 1748949bcd6Sandrei id_t cpi_coreid; 1758949bcd6Sandrei uint_t cpi_ncore_per_chip; /* AMD: fn 0x80000008: %ecx[7-0] */ 1768949bcd6Sandrei /* Intel: fn 4: %eax[31-26] */ 1777c478bd9Sstevel@tonic-gate /* 1787c478bd9Sstevel@tonic-gate * supported feature information 1797c478bd9Sstevel@tonic-gate */ 180ae115bc7Smrj uint32_t cpi_support[5]; 1817c478bd9Sstevel@tonic-gate #define STD_EDX_FEATURES 0 1827c478bd9Sstevel@tonic-gate #define AMD_EDX_FEATURES 1 1837c478bd9Sstevel@tonic-gate #define TM_EDX_FEATURES 2 1847c478bd9Sstevel@tonic-gate #define STD_ECX_FEATURES 3 185ae115bc7Smrj #define AMD_ECX_FEATURES 4 1868a40a695Sgavinm /* 1878a40a695Sgavinm * Synthesized information, where known. 1888a40a695Sgavinm */ 1898a40a695Sgavinm uint32_t cpi_chiprev; /* See X86_CHIPREV_* in x86_archext.h */ 1908a40a695Sgavinm const char *cpi_chiprevstr; /* May be NULL if chiprev unknown */ 1918a40a695Sgavinm uint32_t cpi_socket; /* Chip package/socket type */ 192f98fbcecSbholler 193f98fbcecSbholler struct mwait_info cpi_mwait; /* fn 5: monitor/mwait info */ 1947c478bd9Sstevel@tonic-gate }; 1957c478bd9Sstevel@tonic-gate 1967c478bd9Sstevel@tonic-gate 1977c478bd9Sstevel@tonic-gate static struct cpuid_info cpuid_info0; 1987c478bd9Sstevel@tonic-gate 1997c478bd9Sstevel@tonic-gate /* 2007c478bd9Sstevel@tonic-gate * These bit fields are defined by the Intel Application Note AP-485 2017c478bd9Sstevel@tonic-gate * "Intel Processor Identification and the CPUID Instruction" 2027c478bd9Sstevel@tonic-gate */ 2037c478bd9Sstevel@tonic-gate #define CPI_FAMILY_XTD(cpi) BITX((cpi)->cpi_std[1].cp_eax, 27, 20) 2047c478bd9Sstevel@tonic-gate #define CPI_MODEL_XTD(cpi) BITX((cpi)->cpi_std[1].cp_eax, 19, 16) 2057c478bd9Sstevel@tonic-gate #define CPI_TYPE(cpi) BITX((cpi)->cpi_std[1].cp_eax, 13, 12) 2067c478bd9Sstevel@tonic-gate #define CPI_FAMILY(cpi) BITX((cpi)->cpi_std[1].cp_eax, 11, 8) 2077c478bd9Sstevel@tonic-gate #define CPI_STEP(cpi) BITX((cpi)->cpi_std[1].cp_eax, 3, 0) 2087c478bd9Sstevel@tonic-gate #define CPI_MODEL(cpi) BITX((cpi)->cpi_std[1].cp_eax, 7, 4) 2097c478bd9Sstevel@tonic-gate 2107c478bd9Sstevel@tonic-gate #define CPI_FEATURES_EDX(cpi) ((cpi)->cpi_std[1].cp_edx) 2117c478bd9Sstevel@tonic-gate #define CPI_FEATURES_ECX(cpi) ((cpi)->cpi_std[1].cp_ecx) 2127c478bd9Sstevel@tonic-gate #define CPI_FEATURES_XTD_EDX(cpi) ((cpi)->cpi_extd[1].cp_edx) 2137c478bd9Sstevel@tonic-gate #define CPI_FEATURES_XTD_ECX(cpi) ((cpi)->cpi_extd[1].cp_ecx) 2147c478bd9Sstevel@tonic-gate 2157c478bd9Sstevel@tonic-gate #define CPI_BRANDID(cpi) BITX((cpi)->cpi_std[1].cp_ebx, 7, 0) 2167c478bd9Sstevel@tonic-gate #define CPI_CHUNKS(cpi) BITX((cpi)->cpi_std[1].cp_ebx, 15, 7) 2177c478bd9Sstevel@tonic-gate #define CPI_CPU_COUNT(cpi) BITX((cpi)->cpi_std[1].cp_ebx, 23, 16) 2187c478bd9Sstevel@tonic-gate #define CPI_APIC_ID(cpi) BITX((cpi)->cpi_std[1].cp_ebx, 31, 24) 2197c478bd9Sstevel@tonic-gate 2207c478bd9Sstevel@tonic-gate #define CPI_MAXEAX_MAX 0x100 /* sanity control */ 2217c478bd9Sstevel@tonic-gate #define CPI_XMAXEAX_MAX 0x80000100 222d129bde2Sesaxe #define CPI_FN4_ECX_MAX 0x20 /* sanity: max fn 4 levels */ 223d129bde2Sesaxe 224d129bde2Sesaxe /* 225d129bde2Sesaxe * Function 4 (Deterministic Cache Parameters) macros 226d129bde2Sesaxe * Defined by Intel Application Note AP-485 227d129bde2Sesaxe */ 228d129bde2Sesaxe #define CPI_NUM_CORES(regs) BITX((regs)->cp_eax, 31, 26) 229d129bde2Sesaxe #define CPI_NTHR_SHR_CACHE(regs) BITX((regs)->cp_eax, 25, 14) 230d129bde2Sesaxe #define CPI_FULL_ASSOC_CACHE(regs) BITX((regs)->cp_eax, 9, 9) 231d129bde2Sesaxe #define CPI_SELF_INIT_CACHE(regs) BITX((regs)->cp_eax, 8, 8) 232d129bde2Sesaxe #define CPI_CACHE_LVL(regs) BITX((regs)->cp_eax, 7, 5) 233d129bde2Sesaxe #define CPI_CACHE_TYPE(regs) BITX((regs)->cp_eax, 4, 0) 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 /* 271*31725658Sksadhukh * AMD family 0xf and family 0x10 socket types. 272*31725658Sksadhukh * First index : 273*31725658Sksadhukh * 0 for family 0xf, revs B thru E 274*31725658Sksadhukh * 1 for family 0xf, revs F and G 275*31725658Sksadhukh * 2 for family 0x10, rev B 2768a40a695Sgavinm * Second index by (model & 0x3) 2778a40a695Sgavinm */ 278*31725658Sksadhukh static uint32_t amd_skts[3][4] = { 2798a40a695Sgavinm { 2808a40a695Sgavinm X86_SOCKET_754, /* 0b00 */ 2818a40a695Sgavinm X86_SOCKET_940, /* 0b01 */ 2828a40a695Sgavinm X86_SOCKET_754, /* 0b10 */ 2838a40a695Sgavinm X86_SOCKET_939 /* 0b11 */ 2848a40a695Sgavinm }, 2858a40a695Sgavinm { 2868a40a695Sgavinm X86_SOCKET_S1g1, /* 0b00 */ 2878a40a695Sgavinm X86_SOCKET_F1207, /* 0b01 */ 2888a40a695Sgavinm X86_SOCKET_UNKNOWN, /* 0b10 */ 2898a40a695Sgavinm X86_SOCKET_AM2 /* 0b11 */ 290*31725658Sksadhukh }, 291*31725658Sksadhukh { 292*31725658Sksadhukh X86_SOCKET_F1207, /* 0b00 */ 293*31725658Sksadhukh X86_SOCKET_F1207, /* 0b01 */ 294*31725658Sksadhukh X86_SOCKET_F1207, /* 0b10 */ 295*31725658Sksadhukh X86_SOCKET_F1207 /* 0b11 */ 2968a40a695Sgavinm } 2978a40a695Sgavinm }; 2988a40a695Sgavinm 2998a40a695Sgavinm /* 300*31725658Sksadhukh * Table for mapping AMD Family 0xf and AMD Family 0x10 model/stepping 301*31725658Sksadhukh * combination to chip "revision" and socket type. 3028a40a695Sgavinm * 3038a40a695Sgavinm * The first member of this array that matches a given family, extended model 3048a40a695Sgavinm * plus model range, and stepping range will be considered a match. 3058a40a695Sgavinm */ 3068a40a695Sgavinm static const struct amd_rev_mapent { 3078a40a695Sgavinm uint_t rm_family; 3088a40a695Sgavinm uint_t rm_modello; 3098a40a695Sgavinm uint_t rm_modelhi; 3108a40a695Sgavinm uint_t rm_steplo; 3118a40a695Sgavinm uint_t rm_stephi; 3128a40a695Sgavinm uint32_t rm_chiprev; 3138a40a695Sgavinm const char *rm_chiprevstr; 3148a40a695Sgavinm int rm_sktidx; 3158a40a695Sgavinm } amd_revmap[] = { 3168a40a695Sgavinm /* 3178a40a695Sgavinm * Rev B includes model 0x4 stepping 0 and model 0x5 stepping 0 and 1. 3188a40a695Sgavinm */ 3198a40a695Sgavinm { 0xf, 0x04, 0x04, 0x0, 0x0, X86_CHIPREV_AMD_F_REV_B, "B", 0 }, 3208a40a695Sgavinm { 0xf, 0x05, 0x05, 0x0, 0x1, X86_CHIPREV_AMD_F_REV_B, "B", 0 }, 3218a40a695Sgavinm /* 3228a40a695Sgavinm * Rev C0 includes model 0x4 stepping 8 and model 0x5 stepping 8 3238a40a695Sgavinm */ 3248a40a695Sgavinm { 0xf, 0x04, 0x05, 0x8, 0x8, X86_CHIPREV_AMD_F_REV_C0, "C0", 0 }, 3258a40a695Sgavinm /* 3268a40a695Sgavinm * Rev CG is the rest of extended model 0x0 - i.e., everything 3278a40a695Sgavinm * but the rev B and C0 combinations covered above. 3288a40a695Sgavinm */ 3298a40a695Sgavinm { 0xf, 0x00, 0x0f, 0x0, 0xf, X86_CHIPREV_AMD_F_REV_CG, "CG", 0 }, 3308a40a695Sgavinm /* 3318a40a695Sgavinm * Rev D has extended model 0x1. 3328a40a695Sgavinm */ 3338a40a695Sgavinm { 0xf, 0x10, 0x1f, 0x0, 0xf, X86_CHIPREV_AMD_F_REV_D, "D", 0 }, 3348a40a695Sgavinm /* 3358a40a695Sgavinm * Rev E has extended model 0x2. 3368a40a695Sgavinm * Extended model 0x3 is unused but available to grow into. 3378a40a695Sgavinm */ 3388a40a695Sgavinm { 0xf, 0x20, 0x3f, 0x0, 0xf, X86_CHIPREV_AMD_F_REV_E, "E", 0 }, 3398a40a695Sgavinm /* 3408a40a695Sgavinm * Rev F has extended models 0x4 and 0x5. 3418a40a695Sgavinm */ 3428a40a695Sgavinm { 0xf, 0x40, 0x5f, 0x0, 0xf, X86_CHIPREV_AMD_F_REV_F, "F", 1 }, 3438a40a695Sgavinm /* 3448a40a695Sgavinm * Rev G has extended model 0x6. 3458a40a695Sgavinm */ 3468a40a695Sgavinm { 0xf, 0x60, 0x6f, 0x0, 0xf, X86_CHIPREV_AMD_F_REV_G, "G", 1 }, 347*31725658Sksadhukh /* 348*31725658Sksadhukh * Family 0x10 Rev B has model 0x2. 349*31725658Sksadhukh */ 350*31725658Sksadhukh { 0x10, 0x02, 0x02, 0x0, 0xa, X86_CHIPREV_AMD_10_REV_B, "B", 2 } 3518a40a695Sgavinm }; 3528a40a695Sgavinm 353f98fbcecSbholler /* 354f98fbcecSbholler * Info for monitor/mwait idle loop. 355f98fbcecSbholler * 356f98fbcecSbholler * See cpuid section of "Intel 64 and IA-32 Architectures Software Developer's 357f98fbcecSbholler * Manual Volume 2A: Instruction Set Reference, A-M" #25366-022US, November 358f98fbcecSbholler * 2006. 359f98fbcecSbholler * See MONITOR/MWAIT section of "AMD64 Architecture Programmer's Manual 360f98fbcecSbholler * Documentation Updates" #33633, Rev 2.05, December 2006. 361f98fbcecSbholler */ 362f98fbcecSbholler #define MWAIT_SUPPORT (0x00000001) /* mwait supported */ 363f98fbcecSbholler #define MWAIT_EXTENSIONS (0x00000002) /* extenstion supported */ 364f98fbcecSbholler #define MWAIT_ECX_INT_ENABLE (0x00000004) /* ecx 1 extension supported */ 365f98fbcecSbholler #define MWAIT_SUPPORTED(cpi) ((cpi)->cpi_std[1].cp_ecx & CPUID_INTC_ECX_MON) 366f98fbcecSbholler #define MWAIT_INT_ENABLE(cpi) ((cpi)->cpi_std[5].cp_ecx & 0x2) 367f98fbcecSbholler #define MWAIT_EXTENSION(cpi) ((cpi)->cpi_std[5].cp_ecx & 0x1) 368f98fbcecSbholler #define MWAIT_SIZE_MIN(cpi) BITX((cpi)->cpi_std[5].cp_eax, 15, 0) 369f98fbcecSbholler #define MWAIT_SIZE_MAX(cpi) BITX((cpi)->cpi_std[5].cp_ebx, 15, 0) 370f98fbcecSbholler /* 371f98fbcecSbholler * Number of sub-cstates for a given c-state. 372f98fbcecSbholler */ 373f98fbcecSbholler #define MWAIT_NUM_SUBC_STATES(cpi, c_state) \ 374f98fbcecSbholler BITX((cpi)->cpi_std[5].cp_edx, c_state + 3, c_state) 375f98fbcecSbholler 376f1d742a9Sksadhukh static void intel_cpuid_4_cache_info(void *, struct cpuid_info *); 377f1d742a9Sksadhukh 3788a40a695Sgavinm static void 3798a40a695Sgavinm synth_amd_info(struct cpuid_info *cpi) 3808a40a695Sgavinm { 3818a40a695Sgavinm const struct amd_rev_mapent *rmp; 3828a40a695Sgavinm uint_t family, model, step; 3838a40a695Sgavinm int i; 3848a40a695Sgavinm 3858a40a695Sgavinm /* 386*31725658Sksadhukh * Currently only AMD family 0xf and family 0x10 use these fields. 3878a40a695Sgavinm */ 388*31725658Sksadhukh if (cpi->cpi_family != 0xf && cpi->cpi_family != 0x10) 3898a40a695Sgavinm return; 3908a40a695Sgavinm 3918a40a695Sgavinm family = cpi->cpi_family; 3928a40a695Sgavinm model = cpi->cpi_model; 3938a40a695Sgavinm step = cpi->cpi_step; 3948a40a695Sgavinm 3958a40a695Sgavinm for (i = 0, rmp = amd_revmap; i < sizeof (amd_revmap) / sizeof (*rmp); 3968a40a695Sgavinm i++, rmp++) { 3978a40a695Sgavinm if (family == rmp->rm_family && 3988a40a695Sgavinm model >= rmp->rm_modello && model <= rmp->rm_modelhi && 3998a40a695Sgavinm step >= rmp->rm_steplo && step <= rmp->rm_stephi) { 4008a40a695Sgavinm cpi->cpi_chiprev = rmp->rm_chiprev; 4018a40a695Sgavinm cpi->cpi_chiprevstr = rmp->rm_chiprevstr; 4028a40a695Sgavinm cpi->cpi_socket = amd_skts[rmp->rm_sktidx][model & 0x3]; 4038a40a695Sgavinm return; 4048a40a695Sgavinm } 4058a40a695Sgavinm } 4068a40a695Sgavinm } 4078a40a695Sgavinm 4088a40a695Sgavinm static void 4098a40a695Sgavinm synth_info(struct cpuid_info *cpi) 4108a40a695Sgavinm { 4118a40a695Sgavinm cpi->cpi_chiprev = X86_CHIPREV_UNKNOWN; 4128a40a695Sgavinm cpi->cpi_chiprevstr = "Unknown"; 4138a40a695Sgavinm cpi->cpi_socket = X86_SOCKET_UNKNOWN; 4148a40a695Sgavinm 4158a40a695Sgavinm switch (cpi->cpi_vendor) { 4168a40a695Sgavinm case X86_VENDOR_AMD: 4178a40a695Sgavinm synth_amd_info(cpi); 4188a40a695Sgavinm break; 4198a40a695Sgavinm 4208a40a695Sgavinm default: 4218a40a695Sgavinm break; 4228a40a695Sgavinm 4238a40a695Sgavinm } 4248a40a695Sgavinm } 4258a40a695Sgavinm 4268a40a695Sgavinm /* 427ae115bc7Smrj * Apply up various platform-dependent restrictions where the 428ae115bc7Smrj * underlying platform restrictions mean the CPU can be marked 429ae115bc7Smrj * as less capable than its cpuid instruction would imply. 430ae115bc7Smrj */ 431843e1988Sjohnlev #if defined(__xpv) 432843e1988Sjohnlev static void 433843e1988Sjohnlev platform_cpuid_mangle(uint_t vendor, uint32_t eax, struct cpuid_regs *cp) 434843e1988Sjohnlev { 435843e1988Sjohnlev switch (eax) { 436843e1988Sjohnlev case 1: 437843e1988Sjohnlev cp->cp_edx &= 438843e1988Sjohnlev ~(CPUID_INTC_EDX_PSE | 439843e1988Sjohnlev CPUID_INTC_EDX_VME | CPUID_INTC_EDX_DE | 440843e1988Sjohnlev CPUID_INTC_EDX_MCA | /* XXPV true on dom0? */ 441843e1988Sjohnlev CPUID_INTC_EDX_SEP | CPUID_INTC_EDX_MTRR | 442843e1988Sjohnlev CPUID_INTC_EDX_PGE | CPUID_INTC_EDX_PAT | 443843e1988Sjohnlev CPUID_AMD_EDX_SYSC | CPUID_INTC_EDX_SEP | 444843e1988Sjohnlev CPUID_INTC_EDX_PSE36 | CPUID_INTC_EDX_HTT); 445843e1988Sjohnlev break; 446ae115bc7Smrj 447843e1988Sjohnlev case 0x80000001: 448843e1988Sjohnlev cp->cp_edx &= 449843e1988Sjohnlev ~(CPUID_AMD_EDX_PSE | 450843e1988Sjohnlev CPUID_INTC_EDX_VME | CPUID_INTC_EDX_DE | 451843e1988Sjohnlev CPUID_AMD_EDX_MTRR | CPUID_AMD_EDX_PGE | 452843e1988Sjohnlev CPUID_AMD_EDX_PAT | CPUID_AMD_EDX_PSE36 | 453843e1988Sjohnlev CPUID_AMD_EDX_SYSC | CPUID_INTC_EDX_SEP | 454843e1988Sjohnlev CPUID_AMD_EDX_TSCP); 455843e1988Sjohnlev cp->cp_ecx &= ~CPUID_AMD_ECX_CMP_LGCY; 456843e1988Sjohnlev break; 457843e1988Sjohnlev default: 458843e1988Sjohnlev break; 459843e1988Sjohnlev } 460843e1988Sjohnlev 461843e1988Sjohnlev switch (vendor) { 462843e1988Sjohnlev case X86_VENDOR_Intel: 463843e1988Sjohnlev switch (eax) { 464843e1988Sjohnlev case 4: 465843e1988Sjohnlev /* 466843e1988Sjohnlev * Zero out the (ncores-per-chip - 1) field 467843e1988Sjohnlev */ 468843e1988Sjohnlev cp->cp_eax &= 0x03fffffff; 469843e1988Sjohnlev break; 470843e1988Sjohnlev default: 471843e1988Sjohnlev break; 472843e1988Sjohnlev } 473843e1988Sjohnlev break; 474843e1988Sjohnlev case X86_VENDOR_AMD: 475843e1988Sjohnlev switch (eax) { 476843e1988Sjohnlev case 0x80000008: 477843e1988Sjohnlev /* 478843e1988Sjohnlev * Zero out the (ncores-per-chip - 1) field 479843e1988Sjohnlev */ 480843e1988Sjohnlev cp->cp_ecx &= 0xffffff00; 481843e1988Sjohnlev break; 482843e1988Sjohnlev default: 483843e1988Sjohnlev break; 484843e1988Sjohnlev } 485843e1988Sjohnlev break; 486843e1988Sjohnlev default: 487843e1988Sjohnlev break; 488843e1988Sjohnlev } 489843e1988Sjohnlev } 490843e1988Sjohnlev #else 491ae115bc7Smrj #define platform_cpuid_mangle(vendor, eax, cp) /* nothing */ 492843e1988Sjohnlev #endif 493ae115bc7Smrj 494ae115bc7Smrj /* 4957c478bd9Sstevel@tonic-gate * Some undocumented ways of patching the results of the cpuid 4967c478bd9Sstevel@tonic-gate * instruction to permit running Solaris 10 on future cpus that 4977c478bd9Sstevel@tonic-gate * we don't currently support. Could be set to non-zero values 4987c478bd9Sstevel@tonic-gate * via settings in eeprom. 4997c478bd9Sstevel@tonic-gate */ 5007c478bd9Sstevel@tonic-gate 5017c478bd9Sstevel@tonic-gate uint32_t cpuid_feature_ecx_include; 5027c478bd9Sstevel@tonic-gate uint32_t cpuid_feature_ecx_exclude; 5037c478bd9Sstevel@tonic-gate uint32_t cpuid_feature_edx_include; 5047c478bd9Sstevel@tonic-gate uint32_t cpuid_feature_edx_exclude; 5057c478bd9Sstevel@tonic-gate 506ae115bc7Smrj void 507ae115bc7Smrj cpuid_alloc_space(cpu_t *cpu) 508ae115bc7Smrj { 509ae115bc7Smrj /* 510ae115bc7Smrj * By convention, cpu0 is the boot cpu, which is set up 511ae115bc7Smrj * before memory allocation is available. All other cpus get 512ae115bc7Smrj * their cpuid_info struct allocated here. 513ae115bc7Smrj */ 514ae115bc7Smrj ASSERT(cpu->cpu_id != 0); 515ae115bc7Smrj cpu->cpu_m.mcpu_cpi = 516ae115bc7Smrj kmem_zalloc(sizeof (*cpu->cpu_m.mcpu_cpi), KM_SLEEP); 517ae115bc7Smrj } 518ae115bc7Smrj 519ae115bc7Smrj void 520ae115bc7Smrj cpuid_free_space(cpu_t *cpu) 521ae115bc7Smrj { 522d129bde2Sesaxe struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 523d129bde2Sesaxe int i; 524d129bde2Sesaxe 525ae115bc7Smrj ASSERT(cpu->cpu_id != 0); 526d129bde2Sesaxe 527d129bde2Sesaxe /* 528d129bde2Sesaxe * Free up any function 4 related dynamic storage 529d129bde2Sesaxe */ 530d129bde2Sesaxe for (i = 1; i < cpi->cpi_std_4_size; i++) 531d129bde2Sesaxe kmem_free(cpi->cpi_std_4[i], sizeof (struct cpuid_regs)); 532d129bde2Sesaxe if (cpi->cpi_std_4_size > 0) 533d129bde2Sesaxe kmem_free(cpi->cpi_std_4, 534d129bde2Sesaxe cpi->cpi_std_4_size * sizeof (struct cpuid_regs *)); 535d129bde2Sesaxe 536ae115bc7Smrj kmem_free(cpu->cpu_m.mcpu_cpi, sizeof (*cpu->cpu_m.mcpu_cpi)); 537ae115bc7Smrj } 538ae115bc7Smrj 5397c478bd9Sstevel@tonic-gate uint_t 5407c478bd9Sstevel@tonic-gate cpuid_pass1(cpu_t *cpu) 5417c478bd9Sstevel@tonic-gate { 5427c478bd9Sstevel@tonic-gate uint32_t mask_ecx, mask_edx; 5437c478bd9Sstevel@tonic-gate uint_t feature = X86_CPUID; 5447c478bd9Sstevel@tonic-gate struct cpuid_info *cpi; 5458949bcd6Sandrei struct cpuid_regs *cp; 5467c478bd9Sstevel@tonic-gate int xcpuid; 547843e1988Sjohnlev #if !defined(__xpv) 5485b8a6efeSbholler extern int idle_cpu_prefer_mwait; 549843e1988Sjohnlev #endif 550ae115bc7Smrj 5517c478bd9Sstevel@tonic-gate /* 552ae115bc7Smrj * Space statically allocated for cpu0, ensure pointer is set 5537c478bd9Sstevel@tonic-gate */ 5547c478bd9Sstevel@tonic-gate if (cpu->cpu_id == 0) 555ae115bc7Smrj cpu->cpu_m.mcpu_cpi = &cpuid_info0; 556ae115bc7Smrj cpi = cpu->cpu_m.mcpu_cpi; 557ae115bc7Smrj ASSERT(cpi != NULL); 5587c478bd9Sstevel@tonic-gate cp = &cpi->cpi_std[0]; 5598949bcd6Sandrei cp->cp_eax = 0; 5608949bcd6Sandrei cpi->cpi_maxeax = __cpuid_insn(cp); 5617c478bd9Sstevel@tonic-gate { 5627c478bd9Sstevel@tonic-gate uint32_t *iptr = (uint32_t *)cpi->cpi_vendorstr; 5637c478bd9Sstevel@tonic-gate *iptr++ = cp->cp_ebx; 5647c478bd9Sstevel@tonic-gate *iptr++ = cp->cp_edx; 5657c478bd9Sstevel@tonic-gate *iptr++ = cp->cp_ecx; 5667c478bd9Sstevel@tonic-gate *(char *)&cpi->cpi_vendorstr[12] = '\0'; 5677c478bd9Sstevel@tonic-gate } 5687c478bd9Sstevel@tonic-gate 5697c478bd9Sstevel@tonic-gate /* 5707c478bd9Sstevel@tonic-gate * Map the vendor string to a type code 5717c478bd9Sstevel@tonic-gate */ 5727c478bd9Sstevel@tonic-gate if (strcmp(cpi->cpi_vendorstr, "GenuineIntel") == 0) 5737c478bd9Sstevel@tonic-gate cpi->cpi_vendor = X86_VENDOR_Intel; 5747c478bd9Sstevel@tonic-gate else if (strcmp(cpi->cpi_vendorstr, "AuthenticAMD") == 0) 5757c478bd9Sstevel@tonic-gate cpi->cpi_vendor = X86_VENDOR_AMD; 5767c478bd9Sstevel@tonic-gate else if (strcmp(cpi->cpi_vendorstr, "GenuineTMx86") == 0) 5777c478bd9Sstevel@tonic-gate cpi->cpi_vendor = X86_VENDOR_TM; 5787c478bd9Sstevel@tonic-gate else if (strcmp(cpi->cpi_vendorstr, CyrixInstead) == 0) 5797c478bd9Sstevel@tonic-gate /* 5807c478bd9Sstevel@tonic-gate * CyrixInstead is a variable used by the Cyrix detection code 5817c478bd9Sstevel@tonic-gate * in locore. 5827c478bd9Sstevel@tonic-gate */ 5837c478bd9Sstevel@tonic-gate cpi->cpi_vendor = X86_VENDOR_Cyrix; 5847c478bd9Sstevel@tonic-gate else if (strcmp(cpi->cpi_vendorstr, "UMC UMC UMC ") == 0) 5857c478bd9Sstevel@tonic-gate cpi->cpi_vendor = X86_VENDOR_UMC; 5867c478bd9Sstevel@tonic-gate else if (strcmp(cpi->cpi_vendorstr, "NexGenDriven") == 0) 5877c478bd9Sstevel@tonic-gate cpi->cpi_vendor = X86_VENDOR_NexGen; 5887c478bd9Sstevel@tonic-gate else if (strcmp(cpi->cpi_vendorstr, "CentaurHauls") == 0) 5897c478bd9Sstevel@tonic-gate cpi->cpi_vendor = X86_VENDOR_Centaur; 5907c478bd9Sstevel@tonic-gate else if (strcmp(cpi->cpi_vendorstr, "RiseRiseRise") == 0) 5917c478bd9Sstevel@tonic-gate cpi->cpi_vendor = X86_VENDOR_Rise; 5927c478bd9Sstevel@tonic-gate else if (strcmp(cpi->cpi_vendorstr, "SiS SiS SiS ") == 0) 5937c478bd9Sstevel@tonic-gate cpi->cpi_vendor = X86_VENDOR_SiS; 5947c478bd9Sstevel@tonic-gate else if (strcmp(cpi->cpi_vendorstr, "Geode by NSC") == 0) 5957c478bd9Sstevel@tonic-gate cpi->cpi_vendor = X86_VENDOR_NSC; 5967c478bd9Sstevel@tonic-gate else 5977c478bd9Sstevel@tonic-gate cpi->cpi_vendor = X86_VENDOR_IntelClone; 5987c478bd9Sstevel@tonic-gate 5997c478bd9Sstevel@tonic-gate x86_vendor = cpi->cpi_vendor; /* for compatibility */ 6007c478bd9Sstevel@tonic-gate 6017c478bd9Sstevel@tonic-gate /* 6027c478bd9Sstevel@tonic-gate * Limit the range in case of weird hardware 6037c478bd9Sstevel@tonic-gate */ 6047c478bd9Sstevel@tonic-gate if (cpi->cpi_maxeax > CPI_MAXEAX_MAX) 6057c478bd9Sstevel@tonic-gate cpi->cpi_maxeax = CPI_MAXEAX_MAX; 6067c478bd9Sstevel@tonic-gate if (cpi->cpi_maxeax < 1) 6077c478bd9Sstevel@tonic-gate goto pass1_done; 6087c478bd9Sstevel@tonic-gate 6097c478bd9Sstevel@tonic-gate cp = &cpi->cpi_std[1]; 6108949bcd6Sandrei cp->cp_eax = 1; 6118949bcd6Sandrei (void) __cpuid_insn(cp); 6127c478bd9Sstevel@tonic-gate 6137c478bd9Sstevel@tonic-gate /* 6147c478bd9Sstevel@tonic-gate * Extract identifying constants for easy access. 6157c478bd9Sstevel@tonic-gate */ 6167c478bd9Sstevel@tonic-gate cpi->cpi_model = CPI_MODEL(cpi); 6177c478bd9Sstevel@tonic-gate cpi->cpi_family = CPI_FAMILY(cpi); 6187c478bd9Sstevel@tonic-gate 6195ff02082Sdmick if (cpi->cpi_family == 0xf) 6207c478bd9Sstevel@tonic-gate cpi->cpi_family += CPI_FAMILY_XTD(cpi); 6215ff02082Sdmick 62268c91426Sdmick /* 623875b116eSkchow * Beware: AMD uses "extended model" iff base *FAMILY* == 0xf. 62468c91426Sdmick * Intel, and presumably everyone else, uses model == 0xf, as 62568c91426Sdmick * one would expect (max value means possible overflow). Sigh. 62668c91426Sdmick */ 62768c91426Sdmick 62868c91426Sdmick switch (cpi->cpi_vendor) { 629bf91205bSksadhukh case X86_VENDOR_Intel: 630bf91205bSksadhukh if (IS_EXTENDED_MODEL_INTEL(cpi)) 631bf91205bSksadhukh cpi->cpi_model += CPI_MODEL_XTD(cpi) << 4; 632447af253Sksadhukh break; 63368c91426Sdmick case X86_VENDOR_AMD: 634875b116eSkchow if (CPI_FAMILY(cpi) == 0xf) 63568c91426Sdmick cpi->cpi_model += CPI_MODEL_XTD(cpi) << 4; 63668c91426Sdmick break; 63768c91426Sdmick default: 6385ff02082Sdmick if (cpi->cpi_model == 0xf) 6397c478bd9Sstevel@tonic-gate cpi->cpi_model += CPI_MODEL_XTD(cpi) << 4; 64068c91426Sdmick break; 64168c91426Sdmick } 6427c478bd9Sstevel@tonic-gate 6437c478bd9Sstevel@tonic-gate cpi->cpi_step = CPI_STEP(cpi); 6447c478bd9Sstevel@tonic-gate cpi->cpi_brandid = CPI_BRANDID(cpi); 6457c478bd9Sstevel@tonic-gate 6467c478bd9Sstevel@tonic-gate /* 6477c478bd9Sstevel@tonic-gate * *default* assumptions: 6487c478bd9Sstevel@tonic-gate * - believe %edx feature word 6497c478bd9Sstevel@tonic-gate * - ignore %ecx feature word 6507c478bd9Sstevel@tonic-gate * - 32-bit virtual and physical addressing 6517c478bd9Sstevel@tonic-gate */ 6527c478bd9Sstevel@tonic-gate mask_edx = 0xffffffff; 6537c478bd9Sstevel@tonic-gate mask_ecx = 0; 6547c478bd9Sstevel@tonic-gate 6557c478bd9Sstevel@tonic-gate cpi->cpi_pabits = cpi->cpi_vabits = 32; 6567c478bd9Sstevel@tonic-gate 6577c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 6587c478bd9Sstevel@tonic-gate case X86_VENDOR_Intel: 6597c478bd9Sstevel@tonic-gate if (cpi->cpi_family == 5) 6607c478bd9Sstevel@tonic-gate x86_type = X86_TYPE_P5; 6615ff02082Sdmick else if (IS_LEGACY_P6(cpi)) { 6627c478bd9Sstevel@tonic-gate x86_type = X86_TYPE_P6; 6637c478bd9Sstevel@tonic-gate pentiumpro_bug4046376 = 1; 6647c478bd9Sstevel@tonic-gate pentiumpro_bug4064495 = 1; 6657c478bd9Sstevel@tonic-gate /* 6667c478bd9Sstevel@tonic-gate * Clear the SEP bit when it was set erroneously 6677c478bd9Sstevel@tonic-gate */ 6687c478bd9Sstevel@tonic-gate if (cpi->cpi_model < 3 && cpi->cpi_step < 3) 6697c478bd9Sstevel@tonic-gate cp->cp_edx &= ~CPUID_INTC_EDX_SEP; 6705ff02082Sdmick } else if (IS_NEW_F6(cpi) || cpi->cpi_family == 0xf) { 6717c478bd9Sstevel@tonic-gate x86_type = X86_TYPE_P4; 6727c478bd9Sstevel@tonic-gate /* 6737c478bd9Sstevel@tonic-gate * We don't currently depend on any of the %ecx 6747c478bd9Sstevel@tonic-gate * features until Prescott, so we'll only check 6757c478bd9Sstevel@tonic-gate * this from P4 onwards. We might want to revisit 6767c478bd9Sstevel@tonic-gate * that idea later. 6777c478bd9Sstevel@tonic-gate */ 6787c478bd9Sstevel@tonic-gate mask_ecx = 0xffffffff; 6797c478bd9Sstevel@tonic-gate } else if (cpi->cpi_family > 0xf) 6807c478bd9Sstevel@tonic-gate mask_ecx = 0xffffffff; 6817c622d23Sbholler /* 6827c622d23Sbholler * We don't support MONITOR/MWAIT if leaf 5 is not available 6837c622d23Sbholler * to obtain the monitor linesize. 6847c622d23Sbholler */ 6857c622d23Sbholler if (cpi->cpi_maxeax < 5) 6867c622d23Sbholler mask_ecx &= ~CPUID_INTC_ECX_MON; 6877c478bd9Sstevel@tonic-gate break; 6887c478bd9Sstevel@tonic-gate case X86_VENDOR_IntelClone: 6897c478bd9Sstevel@tonic-gate default: 6907c478bd9Sstevel@tonic-gate break; 6917c478bd9Sstevel@tonic-gate case X86_VENDOR_AMD: 6927c478bd9Sstevel@tonic-gate #if defined(OPTERON_ERRATUM_108) 6937c478bd9Sstevel@tonic-gate if (cpi->cpi_family == 0xf && cpi->cpi_model == 0xe) { 6947c478bd9Sstevel@tonic-gate cp->cp_eax = (0xf0f & cp->cp_eax) | 0xc0; 6957c478bd9Sstevel@tonic-gate cpi->cpi_model = 0xc; 6967c478bd9Sstevel@tonic-gate } else 6977c478bd9Sstevel@tonic-gate #endif 6987c478bd9Sstevel@tonic-gate if (cpi->cpi_family == 5) { 6997c478bd9Sstevel@tonic-gate /* 7007c478bd9Sstevel@tonic-gate * AMD K5 and K6 7017c478bd9Sstevel@tonic-gate * 7027c478bd9Sstevel@tonic-gate * These CPUs have an incomplete implementation 7037c478bd9Sstevel@tonic-gate * of MCA/MCE which we mask away. 7047c478bd9Sstevel@tonic-gate */ 7058949bcd6Sandrei mask_edx &= ~(CPUID_INTC_EDX_MCE | CPUID_INTC_EDX_MCA); 7068949bcd6Sandrei 7077c478bd9Sstevel@tonic-gate /* 7087c478bd9Sstevel@tonic-gate * Model 0 uses the wrong (APIC) bit 7097c478bd9Sstevel@tonic-gate * to indicate PGE. Fix it here. 7107c478bd9Sstevel@tonic-gate */ 7118949bcd6Sandrei if (cpi->cpi_model == 0) { 7127c478bd9Sstevel@tonic-gate if (cp->cp_edx & 0x200) { 7137c478bd9Sstevel@tonic-gate cp->cp_edx &= ~0x200; 7147c478bd9Sstevel@tonic-gate cp->cp_edx |= CPUID_INTC_EDX_PGE; 7157c478bd9Sstevel@tonic-gate } 7167c478bd9Sstevel@tonic-gate } 7178949bcd6Sandrei 7188949bcd6Sandrei /* 7198949bcd6Sandrei * Early models had problems w/ MMX; disable. 7208949bcd6Sandrei */ 7218949bcd6Sandrei if (cpi->cpi_model < 6) 7228949bcd6Sandrei mask_edx &= ~CPUID_INTC_EDX_MMX; 7238949bcd6Sandrei } 7248949bcd6Sandrei 7258949bcd6Sandrei /* 7268949bcd6Sandrei * For newer families, SSE3 and CX16, at least, are valid; 7278949bcd6Sandrei * enable all 7288949bcd6Sandrei */ 7298949bcd6Sandrei if (cpi->cpi_family >= 0xf) 7308949bcd6Sandrei mask_ecx = 0xffffffff; 7317c622d23Sbholler /* 7327c622d23Sbholler * We don't support MONITOR/MWAIT if leaf 5 is not available 7337c622d23Sbholler * to obtain the monitor linesize. 7347c622d23Sbholler */ 7357c622d23Sbholler if (cpi->cpi_maxeax < 5) 7367c622d23Sbholler mask_ecx &= ~CPUID_INTC_ECX_MON; 7375b8a6efeSbholler 738843e1988Sjohnlev #if !defined(__xpv) 7395b8a6efeSbholler /* 7405b8a6efeSbholler * Do not use MONITOR/MWAIT to halt in the idle loop on any AMD 7415b8a6efeSbholler * processors. AMD does not intend MWAIT to be used in the cpu 7425b8a6efeSbholler * idle loop on current and future processors. 10h and future 7435b8a6efeSbholler * AMD processors use more power in MWAIT than HLT. 7445b8a6efeSbholler * Pre-family-10h Opterons do not have the MWAIT instruction. 7455b8a6efeSbholler */ 7465b8a6efeSbholler idle_cpu_prefer_mwait = 0; 747843e1988Sjohnlev #endif 7485b8a6efeSbholler 7497c478bd9Sstevel@tonic-gate break; 7507c478bd9Sstevel@tonic-gate case X86_VENDOR_TM: 7517c478bd9Sstevel@tonic-gate /* 7527c478bd9Sstevel@tonic-gate * workaround the NT workaround in CMS 4.1 7537c478bd9Sstevel@tonic-gate */ 7547c478bd9Sstevel@tonic-gate if (cpi->cpi_family == 5 && cpi->cpi_model == 4 && 7557c478bd9Sstevel@tonic-gate (cpi->cpi_step == 2 || cpi->cpi_step == 3)) 7567c478bd9Sstevel@tonic-gate cp->cp_edx |= CPUID_INTC_EDX_CX8; 7577c478bd9Sstevel@tonic-gate break; 7587c478bd9Sstevel@tonic-gate case X86_VENDOR_Centaur: 7597c478bd9Sstevel@tonic-gate /* 7607c478bd9Sstevel@tonic-gate * workaround the NT workarounds again 7617c478bd9Sstevel@tonic-gate */ 7627c478bd9Sstevel@tonic-gate if (cpi->cpi_family == 6) 7637c478bd9Sstevel@tonic-gate cp->cp_edx |= CPUID_INTC_EDX_CX8; 7647c478bd9Sstevel@tonic-gate break; 7657c478bd9Sstevel@tonic-gate case X86_VENDOR_Cyrix: 7667c478bd9Sstevel@tonic-gate /* 7677c478bd9Sstevel@tonic-gate * We rely heavily on the probing in locore 7687c478bd9Sstevel@tonic-gate * to actually figure out what parts, if any, 7697c478bd9Sstevel@tonic-gate * of the Cyrix cpuid instruction to believe. 7707c478bd9Sstevel@tonic-gate */ 7717c478bd9Sstevel@tonic-gate switch (x86_type) { 7727c478bd9Sstevel@tonic-gate case X86_TYPE_CYRIX_486: 7737c478bd9Sstevel@tonic-gate mask_edx = 0; 7747c478bd9Sstevel@tonic-gate break; 7757c478bd9Sstevel@tonic-gate case X86_TYPE_CYRIX_6x86: 7767c478bd9Sstevel@tonic-gate mask_edx = 0; 7777c478bd9Sstevel@tonic-gate break; 7787c478bd9Sstevel@tonic-gate case X86_TYPE_CYRIX_6x86L: 7797c478bd9Sstevel@tonic-gate mask_edx = 7807c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_DE | 7817c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_CX8; 7827c478bd9Sstevel@tonic-gate break; 7837c478bd9Sstevel@tonic-gate case X86_TYPE_CYRIX_6x86MX: 7847c478bd9Sstevel@tonic-gate mask_edx = 7857c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_DE | 7867c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_MSR | 7877c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_CX8 | 7887c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_PGE | 7897c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_CMOV | 7907c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_MMX; 7917c478bd9Sstevel@tonic-gate break; 7927c478bd9Sstevel@tonic-gate case X86_TYPE_CYRIX_GXm: 7937c478bd9Sstevel@tonic-gate mask_edx = 7947c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_MSR | 7957c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_CX8 | 7967c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_CMOV | 7977c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_MMX; 7987c478bd9Sstevel@tonic-gate break; 7997c478bd9Sstevel@tonic-gate case X86_TYPE_CYRIX_MediaGX: 8007c478bd9Sstevel@tonic-gate break; 8017c478bd9Sstevel@tonic-gate case X86_TYPE_CYRIX_MII: 8027c478bd9Sstevel@tonic-gate case X86_TYPE_VIA_CYRIX_III: 8037c478bd9Sstevel@tonic-gate mask_edx = 8047c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_DE | 8057c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_TSC | 8067c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_MSR | 8077c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_CX8 | 8087c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_PGE | 8097c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_CMOV | 8107c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_MMX; 8117c478bd9Sstevel@tonic-gate break; 8127c478bd9Sstevel@tonic-gate default: 8137c478bd9Sstevel@tonic-gate break; 8147c478bd9Sstevel@tonic-gate } 8157c478bd9Sstevel@tonic-gate break; 8167c478bd9Sstevel@tonic-gate } 8177c478bd9Sstevel@tonic-gate 818843e1988Sjohnlev #if defined(__xpv) 819843e1988Sjohnlev /* 820843e1988Sjohnlev * Do not support MONITOR/MWAIT under a hypervisor 821843e1988Sjohnlev */ 822843e1988Sjohnlev mask_ecx &= ~CPUID_INTC_ECX_MON; 823843e1988Sjohnlev #endif /* __xpv */ 824843e1988Sjohnlev 8257c478bd9Sstevel@tonic-gate /* 8267c478bd9Sstevel@tonic-gate * Now we've figured out the masks that determine 8277c478bd9Sstevel@tonic-gate * which bits we choose to believe, apply the masks 8287c478bd9Sstevel@tonic-gate * to the feature words, then map the kernel's view 8297c478bd9Sstevel@tonic-gate * of these feature words into its feature word. 8307c478bd9Sstevel@tonic-gate */ 8317c478bd9Sstevel@tonic-gate cp->cp_edx &= mask_edx; 8327c478bd9Sstevel@tonic-gate cp->cp_ecx &= mask_ecx; 8337c478bd9Sstevel@tonic-gate 8347c478bd9Sstevel@tonic-gate /* 835ae115bc7Smrj * apply any platform restrictions (we don't call this 836ae115bc7Smrj * immediately after __cpuid_insn here, because we need the 837ae115bc7Smrj * workarounds applied above first) 8387c478bd9Sstevel@tonic-gate */ 839ae115bc7Smrj platform_cpuid_mangle(cpi->cpi_vendor, 1, cp); 8407c478bd9Sstevel@tonic-gate 841ae115bc7Smrj /* 842ae115bc7Smrj * fold in overrides from the "eeprom" mechanism 843ae115bc7Smrj */ 8447c478bd9Sstevel@tonic-gate cp->cp_edx |= cpuid_feature_edx_include; 8457c478bd9Sstevel@tonic-gate cp->cp_edx &= ~cpuid_feature_edx_exclude; 8467c478bd9Sstevel@tonic-gate 8477c478bd9Sstevel@tonic-gate cp->cp_ecx |= cpuid_feature_ecx_include; 8487c478bd9Sstevel@tonic-gate cp->cp_ecx &= ~cpuid_feature_ecx_exclude; 8497c478bd9Sstevel@tonic-gate 8507c478bd9Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_PSE) 8517c478bd9Sstevel@tonic-gate feature |= X86_LARGEPAGE; 8527c478bd9Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_TSC) 8537c478bd9Sstevel@tonic-gate feature |= X86_TSC; 8547c478bd9Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_MSR) 8557c478bd9Sstevel@tonic-gate feature |= X86_MSR; 8567c478bd9Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_MTRR) 8577c478bd9Sstevel@tonic-gate feature |= X86_MTRR; 8587c478bd9Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_PGE) 8597c478bd9Sstevel@tonic-gate feature |= X86_PGE; 8607c478bd9Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_CMOV) 8617c478bd9Sstevel@tonic-gate feature |= X86_CMOV; 8627c478bd9Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_MMX) 8637c478bd9Sstevel@tonic-gate feature |= X86_MMX; 8647c478bd9Sstevel@tonic-gate if ((cp->cp_edx & CPUID_INTC_EDX_MCE) != 0 && 8657c478bd9Sstevel@tonic-gate (cp->cp_edx & CPUID_INTC_EDX_MCA) != 0) 8667c478bd9Sstevel@tonic-gate feature |= X86_MCA; 8677c478bd9Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_PAE) 8687c478bd9Sstevel@tonic-gate feature |= X86_PAE; 8697c478bd9Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_CX8) 8707c478bd9Sstevel@tonic-gate feature |= X86_CX8; 8717c478bd9Sstevel@tonic-gate if (cp->cp_ecx & CPUID_INTC_ECX_CX16) 8727c478bd9Sstevel@tonic-gate feature |= X86_CX16; 8737c478bd9Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_PAT) 8747c478bd9Sstevel@tonic-gate feature |= X86_PAT; 8757c478bd9Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_SEP) 8767c478bd9Sstevel@tonic-gate feature |= X86_SEP; 8777c478bd9Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_FXSR) { 8787c478bd9Sstevel@tonic-gate /* 8797c478bd9Sstevel@tonic-gate * In our implementation, fxsave/fxrstor 8807c478bd9Sstevel@tonic-gate * are prerequisites before we'll even 8817c478bd9Sstevel@tonic-gate * try and do SSE things. 8827c478bd9Sstevel@tonic-gate */ 8837c478bd9Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_SSE) 8847c478bd9Sstevel@tonic-gate feature |= X86_SSE; 8857c478bd9Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_SSE2) 8867c478bd9Sstevel@tonic-gate feature |= X86_SSE2; 8877c478bd9Sstevel@tonic-gate if (cp->cp_ecx & CPUID_INTC_ECX_SSE3) 8887c478bd9Sstevel@tonic-gate feature |= X86_SSE3; 8897c478bd9Sstevel@tonic-gate } 8907c478bd9Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_DE) 891ae115bc7Smrj feature |= X86_DE; 892f98fbcecSbholler if (cp->cp_ecx & CPUID_INTC_ECX_MON) { 893f98fbcecSbholler cpi->cpi_mwait.support |= MWAIT_SUPPORT; 894f98fbcecSbholler feature |= X86_MWAIT; 895f98fbcecSbholler } 8967c478bd9Sstevel@tonic-gate 8977c478bd9Sstevel@tonic-gate if (feature & X86_PAE) 8987c478bd9Sstevel@tonic-gate cpi->cpi_pabits = 36; 8997c478bd9Sstevel@tonic-gate 9007c478bd9Sstevel@tonic-gate /* 9017c478bd9Sstevel@tonic-gate * Hyperthreading configuration is slightly tricky on Intel 9027c478bd9Sstevel@tonic-gate * and pure clones, and even trickier on AMD. 9037c478bd9Sstevel@tonic-gate * 9047c478bd9Sstevel@tonic-gate * (AMD chose to set the HTT bit on their CMP processors, 9057c478bd9Sstevel@tonic-gate * even though they're not actually hyperthreaded. Thus it 9067c478bd9Sstevel@tonic-gate * takes a bit more work to figure out what's really going 907ae115bc7Smrj * on ... see the handling of the CMP_LGCY bit below) 9087c478bd9Sstevel@tonic-gate */ 9097c478bd9Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_HTT) { 9107c478bd9Sstevel@tonic-gate cpi->cpi_ncpu_per_chip = CPI_CPU_COUNT(cpi); 9117c478bd9Sstevel@tonic-gate if (cpi->cpi_ncpu_per_chip > 1) 9127c478bd9Sstevel@tonic-gate feature |= X86_HTT; 9138949bcd6Sandrei } else { 9148949bcd6Sandrei cpi->cpi_ncpu_per_chip = 1; 9157c478bd9Sstevel@tonic-gate } 9167c478bd9Sstevel@tonic-gate 9177c478bd9Sstevel@tonic-gate /* 9187c478bd9Sstevel@tonic-gate * Work on the "extended" feature information, doing 9197c478bd9Sstevel@tonic-gate * some basic initialization for cpuid_pass2() 9207c478bd9Sstevel@tonic-gate */ 9217c478bd9Sstevel@tonic-gate xcpuid = 0; 9227c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 9237c478bd9Sstevel@tonic-gate case X86_VENDOR_Intel: 9245ff02082Sdmick if (IS_NEW_F6(cpi) || cpi->cpi_family >= 0xf) 9257c478bd9Sstevel@tonic-gate xcpuid++; 9267c478bd9Sstevel@tonic-gate break; 9277c478bd9Sstevel@tonic-gate case X86_VENDOR_AMD: 9287c478bd9Sstevel@tonic-gate if (cpi->cpi_family > 5 || 9297c478bd9Sstevel@tonic-gate (cpi->cpi_family == 5 && cpi->cpi_model >= 1)) 9307c478bd9Sstevel@tonic-gate xcpuid++; 9317c478bd9Sstevel@tonic-gate break; 9327c478bd9Sstevel@tonic-gate case X86_VENDOR_Cyrix: 9337c478bd9Sstevel@tonic-gate /* 9347c478bd9Sstevel@tonic-gate * Only these Cyrix CPUs are -known- to support 9357c478bd9Sstevel@tonic-gate * extended cpuid operations. 9367c478bd9Sstevel@tonic-gate */ 9377c478bd9Sstevel@tonic-gate if (x86_type == X86_TYPE_VIA_CYRIX_III || 9387c478bd9Sstevel@tonic-gate x86_type == X86_TYPE_CYRIX_GXm) 9397c478bd9Sstevel@tonic-gate xcpuid++; 9407c478bd9Sstevel@tonic-gate break; 9417c478bd9Sstevel@tonic-gate case X86_VENDOR_Centaur: 9427c478bd9Sstevel@tonic-gate case X86_VENDOR_TM: 9437c478bd9Sstevel@tonic-gate default: 9447c478bd9Sstevel@tonic-gate xcpuid++; 9457c478bd9Sstevel@tonic-gate break; 9467c478bd9Sstevel@tonic-gate } 9477c478bd9Sstevel@tonic-gate 9487c478bd9Sstevel@tonic-gate if (xcpuid) { 9497c478bd9Sstevel@tonic-gate cp = &cpi->cpi_extd[0]; 9508949bcd6Sandrei cp->cp_eax = 0x80000000; 9518949bcd6Sandrei cpi->cpi_xmaxeax = __cpuid_insn(cp); 9527c478bd9Sstevel@tonic-gate } 9537c478bd9Sstevel@tonic-gate 9547c478bd9Sstevel@tonic-gate if (cpi->cpi_xmaxeax & 0x80000000) { 9557c478bd9Sstevel@tonic-gate 9567c478bd9Sstevel@tonic-gate if (cpi->cpi_xmaxeax > CPI_XMAXEAX_MAX) 9577c478bd9Sstevel@tonic-gate cpi->cpi_xmaxeax = CPI_XMAXEAX_MAX; 9587c478bd9Sstevel@tonic-gate 9597c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 9607c478bd9Sstevel@tonic-gate case X86_VENDOR_Intel: 9617c478bd9Sstevel@tonic-gate case X86_VENDOR_AMD: 9627c478bd9Sstevel@tonic-gate if (cpi->cpi_xmaxeax < 0x80000001) 9637c478bd9Sstevel@tonic-gate break; 9647c478bd9Sstevel@tonic-gate cp = &cpi->cpi_extd[1]; 9658949bcd6Sandrei cp->cp_eax = 0x80000001; 9668949bcd6Sandrei (void) __cpuid_insn(cp); 967ae115bc7Smrj 9687c478bd9Sstevel@tonic-gate if (cpi->cpi_vendor == X86_VENDOR_AMD && 9697c478bd9Sstevel@tonic-gate cpi->cpi_family == 5 && 9707c478bd9Sstevel@tonic-gate cpi->cpi_model == 6 && 9717c478bd9Sstevel@tonic-gate cpi->cpi_step == 6) { 9727c478bd9Sstevel@tonic-gate /* 9737c478bd9Sstevel@tonic-gate * K6 model 6 uses bit 10 to indicate SYSC 9747c478bd9Sstevel@tonic-gate * Later models use bit 11. Fix it here. 9757c478bd9Sstevel@tonic-gate */ 9767c478bd9Sstevel@tonic-gate if (cp->cp_edx & 0x400) { 9777c478bd9Sstevel@tonic-gate cp->cp_edx &= ~0x400; 9787c478bd9Sstevel@tonic-gate cp->cp_edx |= CPUID_AMD_EDX_SYSC; 9797c478bd9Sstevel@tonic-gate } 9807c478bd9Sstevel@tonic-gate } 9817c478bd9Sstevel@tonic-gate 982ae115bc7Smrj platform_cpuid_mangle(cpi->cpi_vendor, 0x80000001, cp); 983ae115bc7Smrj 9847c478bd9Sstevel@tonic-gate /* 9857c478bd9Sstevel@tonic-gate * Compute the additions to the kernel's feature word. 9867c478bd9Sstevel@tonic-gate */ 9877c478bd9Sstevel@tonic-gate if (cp->cp_edx & CPUID_AMD_EDX_NX) 9887c478bd9Sstevel@tonic-gate feature |= X86_NX; 9897c478bd9Sstevel@tonic-gate 990f8801251Skk208521 if ((cpi->cpi_vendor == X86_VENDOR_AMD) && 991f8801251Skk208521 (cpi->cpi_std[1].cp_edx & CPUID_INTC_EDX_FXSR) && 992f8801251Skk208521 (cp->cp_ecx & CPUID_AMD_ECX_SSE4A)) 993f8801251Skk208521 feature |= X86_SSE4A; 994f8801251Skk208521 9957c478bd9Sstevel@tonic-gate /* 996ae115bc7Smrj * If both the HTT and CMP_LGCY bits are set, 9978949bcd6Sandrei * then we're not actually HyperThreaded. Read 9988949bcd6Sandrei * "AMD CPUID Specification" for more details. 9997c478bd9Sstevel@tonic-gate */ 10007c478bd9Sstevel@tonic-gate if (cpi->cpi_vendor == X86_VENDOR_AMD && 10018949bcd6Sandrei (feature & X86_HTT) && 1002ae115bc7Smrj (cp->cp_ecx & CPUID_AMD_ECX_CMP_LGCY)) { 10037c478bd9Sstevel@tonic-gate feature &= ~X86_HTT; 10048949bcd6Sandrei feature |= X86_CMP; 10058949bcd6Sandrei } 1006ae115bc7Smrj #if defined(__amd64) 10077c478bd9Sstevel@tonic-gate /* 10087c478bd9Sstevel@tonic-gate * It's really tricky to support syscall/sysret in 10097c478bd9Sstevel@tonic-gate * the i386 kernel; we rely on sysenter/sysexit 10107c478bd9Sstevel@tonic-gate * instead. In the amd64 kernel, things are -way- 10117c478bd9Sstevel@tonic-gate * better. 10127c478bd9Sstevel@tonic-gate */ 10137c478bd9Sstevel@tonic-gate if (cp->cp_edx & CPUID_AMD_EDX_SYSC) 10147c478bd9Sstevel@tonic-gate feature |= X86_ASYSC; 10157c478bd9Sstevel@tonic-gate 10167c478bd9Sstevel@tonic-gate /* 10177c478bd9Sstevel@tonic-gate * While we're thinking about system calls, note 10187c478bd9Sstevel@tonic-gate * that AMD processors don't support sysenter 10197c478bd9Sstevel@tonic-gate * in long mode at all, so don't try to program them. 10207c478bd9Sstevel@tonic-gate */ 10217c478bd9Sstevel@tonic-gate if (x86_vendor == X86_VENDOR_AMD) 10227c478bd9Sstevel@tonic-gate feature &= ~X86_SEP; 10237c478bd9Sstevel@tonic-gate #endif 1024ae115bc7Smrj if (cp->cp_edx & CPUID_AMD_EDX_TSCP) 1025ae115bc7Smrj feature |= X86_TSCP; 10267c478bd9Sstevel@tonic-gate break; 10277c478bd9Sstevel@tonic-gate default: 10287c478bd9Sstevel@tonic-gate break; 10297c478bd9Sstevel@tonic-gate } 10307c478bd9Sstevel@tonic-gate 10318949bcd6Sandrei /* 10328949bcd6Sandrei * Get CPUID data about processor cores and hyperthreads. 10338949bcd6Sandrei */ 10347c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 10357c478bd9Sstevel@tonic-gate case X86_VENDOR_Intel: 10368949bcd6Sandrei if (cpi->cpi_maxeax >= 4) { 10378949bcd6Sandrei cp = &cpi->cpi_std[4]; 10388949bcd6Sandrei cp->cp_eax = 4; 10398949bcd6Sandrei cp->cp_ecx = 0; 10408949bcd6Sandrei (void) __cpuid_insn(cp); 1041ae115bc7Smrj platform_cpuid_mangle(cpi->cpi_vendor, 4, cp); 10428949bcd6Sandrei } 10438949bcd6Sandrei /*FALLTHROUGH*/ 10447c478bd9Sstevel@tonic-gate case X86_VENDOR_AMD: 10457c478bd9Sstevel@tonic-gate if (cpi->cpi_xmaxeax < 0x80000008) 10467c478bd9Sstevel@tonic-gate break; 10477c478bd9Sstevel@tonic-gate cp = &cpi->cpi_extd[8]; 10488949bcd6Sandrei cp->cp_eax = 0x80000008; 10498949bcd6Sandrei (void) __cpuid_insn(cp); 1050ae115bc7Smrj platform_cpuid_mangle(cpi->cpi_vendor, 0x80000008, cp); 1051ae115bc7Smrj 10527c478bd9Sstevel@tonic-gate /* 10537c478bd9Sstevel@tonic-gate * Virtual and physical address limits from 10547c478bd9Sstevel@tonic-gate * cpuid override previously guessed values. 10557c478bd9Sstevel@tonic-gate */ 10567c478bd9Sstevel@tonic-gate cpi->cpi_pabits = BITX(cp->cp_eax, 7, 0); 10577c478bd9Sstevel@tonic-gate cpi->cpi_vabits = BITX(cp->cp_eax, 15, 8); 10587c478bd9Sstevel@tonic-gate break; 10597c478bd9Sstevel@tonic-gate default: 10607c478bd9Sstevel@tonic-gate break; 10617c478bd9Sstevel@tonic-gate } 10628949bcd6Sandrei 1063d129bde2Sesaxe /* 1064d129bde2Sesaxe * Derive the number of cores per chip 1065d129bde2Sesaxe */ 10668949bcd6Sandrei switch (cpi->cpi_vendor) { 10678949bcd6Sandrei case X86_VENDOR_Intel: 10688949bcd6Sandrei if (cpi->cpi_maxeax < 4) { 10698949bcd6Sandrei cpi->cpi_ncore_per_chip = 1; 10708949bcd6Sandrei break; 10718949bcd6Sandrei } else { 10728949bcd6Sandrei cpi->cpi_ncore_per_chip = 10738949bcd6Sandrei BITX((cpi)->cpi_std[4].cp_eax, 31, 26) + 1; 10748949bcd6Sandrei } 10758949bcd6Sandrei break; 10768949bcd6Sandrei case X86_VENDOR_AMD: 10778949bcd6Sandrei if (cpi->cpi_xmaxeax < 0x80000008) { 10788949bcd6Sandrei cpi->cpi_ncore_per_chip = 1; 10798949bcd6Sandrei break; 10808949bcd6Sandrei } else { 10818949bcd6Sandrei cpi->cpi_ncore_per_chip = 10828949bcd6Sandrei BITX((cpi)->cpi_extd[8].cp_ecx, 7, 0) + 1; 10838949bcd6Sandrei } 10848949bcd6Sandrei break; 10858949bcd6Sandrei default: 10868949bcd6Sandrei cpi->cpi_ncore_per_chip = 1; 10878949bcd6Sandrei break; 10887c478bd9Sstevel@tonic-gate } 10898949bcd6Sandrei } 10908949bcd6Sandrei 10918949bcd6Sandrei /* 10928949bcd6Sandrei * If more than one core, then this processor is CMP. 10938949bcd6Sandrei */ 10948949bcd6Sandrei if (cpi->cpi_ncore_per_chip > 1) 10958949bcd6Sandrei feature |= X86_CMP; 1096ae115bc7Smrj 10978949bcd6Sandrei /* 10988949bcd6Sandrei * If the number of cores is the same as the number 10998949bcd6Sandrei * of CPUs, then we cannot have HyperThreading. 11008949bcd6Sandrei */ 11018949bcd6Sandrei if (cpi->cpi_ncpu_per_chip == cpi->cpi_ncore_per_chip) 11028949bcd6Sandrei feature &= ~X86_HTT; 11038949bcd6Sandrei 11047c478bd9Sstevel@tonic-gate if ((feature & (X86_HTT | X86_CMP)) == 0) { 11058949bcd6Sandrei /* 11068949bcd6Sandrei * Single-core single-threaded processors. 11078949bcd6Sandrei */ 11087c478bd9Sstevel@tonic-gate cpi->cpi_chipid = -1; 11097c478bd9Sstevel@tonic-gate cpi->cpi_clogid = 0; 11108949bcd6Sandrei cpi->cpi_coreid = cpu->cpu_id; 11117c478bd9Sstevel@tonic-gate } else if (cpi->cpi_ncpu_per_chip > 1) { 11128949bcd6Sandrei uint_t i; 11138949bcd6Sandrei uint_t chipid_shift = 0; 11148949bcd6Sandrei uint_t coreid_shift = 0; 11158949bcd6Sandrei uint_t apic_id = CPI_APIC_ID(cpi); 11167c478bd9Sstevel@tonic-gate 11178949bcd6Sandrei for (i = 1; i < cpi->cpi_ncpu_per_chip; i <<= 1) 11188949bcd6Sandrei chipid_shift++; 11198949bcd6Sandrei cpi->cpi_chipid = apic_id >> chipid_shift; 11208949bcd6Sandrei cpi->cpi_clogid = apic_id & ((1 << chipid_shift) - 1); 11218949bcd6Sandrei 11228949bcd6Sandrei if (cpi->cpi_vendor == X86_VENDOR_Intel) { 11238949bcd6Sandrei if (feature & X86_CMP) { 11248949bcd6Sandrei /* 11258949bcd6Sandrei * Multi-core (and possibly multi-threaded) 11268949bcd6Sandrei * processors. 11278949bcd6Sandrei */ 11288949bcd6Sandrei uint_t ncpu_per_core; 11298949bcd6Sandrei if (cpi->cpi_ncore_per_chip == 1) 11308949bcd6Sandrei ncpu_per_core = cpi->cpi_ncpu_per_chip; 11318949bcd6Sandrei else if (cpi->cpi_ncore_per_chip > 1) 11328949bcd6Sandrei ncpu_per_core = cpi->cpi_ncpu_per_chip / 11338949bcd6Sandrei cpi->cpi_ncore_per_chip; 11348949bcd6Sandrei /* 11358949bcd6Sandrei * 8bit APIC IDs on dual core Pentiums 11368949bcd6Sandrei * look like this: 11378949bcd6Sandrei * 11388949bcd6Sandrei * +-----------------------+------+------+ 11398949bcd6Sandrei * | Physical Package ID | MC | HT | 11408949bcd6Sandrei * +-----------------------+------+------+ 11418949bcd6Sandrei * <------- chipid --------> 11428949bcd6Sandrei * <------- coreid ---------------> 11438949bcd6Sandrei * <--- clogid --> 11448949bcd6Sandrei * 11458949bcd6Sandrei * Where the number of bits necessary to 11468949bcd6Sandrei * represent MC and HT fields together equals 11478949bcd6Sandrei * to the minimum number of bits necessary to 11488949bcd6Sandrei * store the value of cpi->cpi_ncpu_per_chip. 11498949bcd6Sandrei * Of those bits, the MC part uses the number 11508949bcd6Sandrei * of bits necessary to store the value of 11518949bcd6Sandrei * cpi->cpi_ncore_per_chip. 11528949bcd6Sandrei */ 11538949bcd6Sandrei for (i = 1; i < ncpu_per_core; i <<= 1) 11548949bcd6Sandrei coreid_shift++; 11553090b9a9Sandrei cpi->cpi_coreid = apic_id >> coreid_shift; 11568949bcd6Sandrei } else if (feature & X86_HTT) { 11578949bcd6Sandrei /* 11588949bcd6Sandrei * Single-core multi-threaded processors. 11598949bcd6Sandrei */ 11608949bcd6Sandrei cpi->cpi_coreid = cpi->cpi_chipid; 11618949bcd6Sandrei } 11628949bcd6Sandrei } else if (cpi->cpi_vendor == X86_VENDOR_AMD) { 11638949bcd6Sandrei /* 11648949bcd6Sandrei * AMD currently only has dual-core processors with 11658949bcd6Sandrei * single-threaded cores. If they ever release 11668949bcd6Sandrei * multi-threaded processors, then this code 11678949bcd6Sandrei * will have to be updated. 11688949bcd6Sandrei */ 11698949bcd6Sandrei cpi->cpi_coreid = cpu->cpu_id; 11708949bcd6Sandrei } else { 11718949bcd6Sandrei /* 11728949bcd6Sandrei * All other processors are currently 11738949bcd6Sandrei * assumed to have single cores. 11748949bcd6Sandrei */ 11758949bcd6Sandrei cpi->cpi_coreid = cpi->cpi_chipid; 11768949bcd6Sandrei } 11777c478bd9Sstevel@tonic-gate } 11787c478bd9Sstevel@tonic-gate 11798a40a695Sgavinm /* 11808a40a695Sgavinm * Synthesize chip "revision" and socket type 11818a40a695Sgavinm */ 11828a40a695Sgavinm synth_info(cpi); 11838a40a695Sgavinm 11847c478bd9Sstevel@tonic-gate pass1_done: 11857c478bd9Sstevel@tonic-gate cpi->cpi_pass = 1; 11867c478bd9Sstevel@tonic-gate return (feature); 11877c478bd9Sstevel@tonic-gate } 11887c478bd9Sstevel@tonic-gate 11897c478bd9Sstevel@tonic-gate /* 11907c478bd9Sstevel@tonic-gate * Make copies of the cpuid table entries we depend on, in 11917c478bd9Sstevel@tonic-gate * part for ease of parsing now, in part so that we have only 11927c478bd9Sstevel@tonic-gate * one place to correct any of it, in part for ease of 11937c478bd9Sstevel@tonic-gate * later export to userland, and in part so we can look at 11947c478bd9Sstevel@tonic-gate * this stuff in a crash dump. 11957c478bd9Sstevel@tonic-gate */ 11967c478bd9Sstevel@tonic-gate 11977c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 11987c478bd9Sstevel@tonic-gate void 11997c478bd9Sstevel@tonic-gate cpuid_pass2(cpu_t *cpu) 12007c478bd9Sstevel@tonic-gate { 12017c478bd9Sstevel@tonic-gate uint_t n, nmax; 12027c478bd9Sstevel@tonic-gate int i; 12038949bcd6Sandrei struct cpuid_regs *cp; 12047c478bd9Sstevel@tonic-gate uint8_t *dp; 12057c478bd9Sstevel@tonic-gate uint32_t *iptr; 12067c478bd9Sstevel@tonic-gate struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 12077c478bd9Sstevel@tonic-gate 12087c478bd9Sstevel@tonic-gate ASSERT(cpi->cpi_pass == 1); 12097c478bd9Sstevel@tonic-gate 12107c478bd9Sstevel@tonic-gate if (cpi->cpi_maxeax < 1) 12117c478bd9Sstevel@tonic-gate goto pass2_done; 12127c478bd9Sstevel@tonic-gate 12137c478bd9Sstevel@tonic-gate if ((nmax = cpi->cpi_maxeax + 1) > NMAX_CPI_STD) 12147c478bd9Sstevel@tonic-gate nmax = NMAX_CPI_STD; 12157c478bd9Sstevel@tonic-gate /* 12167c478bd9Sstevel@tonic-gate * (We already handled n == 0 and n == 1 in pass 1) 12177c478bd9Sstevel@tonic-gate */ 12187c478bd9Sstevel@tonic-gate for (n = 2, cp = &cpi->cpi_std[2]; n < nmax; n++, cp++) { 12198949bcd6Sandrei cp->cp_eax = n; 1220d129bde2Sesaxe 1221d129bde2Sesaxe /* 1222d129bde2Sesaxe * CPUID function 4 expects %ecx to be initialized 1223d129bde2Sesaxe * with an index which indicates which cache to return 1224d129bde2Sesaxe * information about. The OS is expected to call function 4 1225d129bde2Sesaxe * with %ecx set to 0, 1, 2, ... until it returns with 1226d129bde2Sesaxe * EAX[4:0] set to 0, which indicates there are no more 1227d129bde2Sesaxe * caches. 1228d129bde2Sesaxe * 1229d129bde2Sesaxe * Here, populate cpi_std[4] with the information returned by 1230d129bde2Sesaxe * function 4 when %ecx == 0, and do the rest in cpuid_pass3() 1231d129bde2Sesaxe * when dynamic memory allocation becomes available. 1232d129bde2Sesaxe * 1233d129bde2Sesaxe * Note: we need to explicitly initialize %ecx here, since 1234d129bde2Sesaxe * function 4 may have been previously invoked. 1235d129bde2Sesaxe */ 1236d129bde2Sesaxe if (n == 4) 1237d129bde2Sesaxe cp->cp_ecx = 0; 1238d129bde2Sesaxe 12398949bcd6Sandrei (void) __cpuid_insn(cp); 1240ae115bc7Smrj platform_cpuid_mangle(cpi->cpi_vendor, n, cp); 12417c478bd9Sstevel@tonic-gate switch (n) { 12427c478bd9Sstevel@tonic-gate case 2: 12437c478bd9Sstevel@tonic-gate /* 12447c478bd9Sstevel@tonic-gate * "the lower 8 bits of the %eax register 12457c478bd9Sstevel@tonic-gate * contain a value that identifies the number 12467c478bd9Sstevel@tonic-gate * of times the cpuid [instruction] has to be 12477c478bd9Sstevel@tonic-gate * executed to obtain a complete image of the 12487c478bd9Sstevel@tonic-gate * processor's caching systems." 12497c478bd9Sstevel@tonic-gate * 12507c478bd9Sstevel@tonic-gate * How *do* they make this stuff up? 12517c478bd9Sstevel@tonic-gate */ 12527c478bd9Sstevel@tonic-gate cpi->cpi_ncache = sizeof (*cp) * 12537c478bd9Sstevel@tonic-gate BITX(cp->cp_eax, 7, 0); 12547c478bd9Sstevel@tonic-gate if (cpi->cpi_ncache == 0) 12557c478bd9Sstevel@tonic-gate break; 12567c478bd9Sstevel@tonic-gate cpi->cpi_ncache--; /* skip count byte */ 12577c478bd9Sstevel@tonic-gate 12587c478bd9Sstevel@tonic-gate /* 12597c478bd9Sstevel@tonic-gate * Well, for now, rather than attempt to implement 12607c478bd9Sstevel@tonic-gate * this slightly dubious algorithm, we just look 12617c478bd9Sstevel@tonic-gate * at the first 15 .. 12627c478bd9Sstevel@tonic-gate */ 12637c478bd9Sstevel@tonic-gate if (cpi->cpi_ncache > (sizeof (*cp) - 1)) 12647c478bd9Sstevel@tonic-gate cpi->cpi_ncache = sizeof (*cp) - 1; 12657c478bd9Sstevel@tonic-gate 12667c478bd9Sstevel@tonic-gate dp = cpi->cpi_cacheinfo; 12677c478bd9Sstevel@tonic-gate if (BITX(cp->cp_eax, 31, 31) == 0) { 12687c478bd9Sstevel@tonic-gate uint8_t *p = (void *)&cp->cp_eax; 12697c478bd9Sstevel@tonic-gate for (i = 1; i < 3; i++) 12707c478bd9Sstevel@tonic-gate if (p[i] != 0) 12717c478bd9Sstevel@tonic-gate *dp++ = p[i]; 12727c478bd9Sstevel@tonic-gate } 12737c478bd9Sstevel@tonic-gate if (BITX(cp->cp_ebx, 31, 31) == 0) { 12747c478bd9Sstevel@tonic-gate uint8_t *p = (void *)&cp->cp_ebx; 12757c478bd9Sstevel@tonic-gate for (i = 0; i < 4; i++) 12767c478bd9Sstevel@tonic-gate if (p[i] != 0) 12777c478bd9Sstevel@tonic-gate *dp++ = p[i]; 12787c478bd9Sstevel@tonic-gate } 12797c478bd9Sstevel@tonic-gate if (BITX(cp->cp_ecx, 31, 31) == 0) { 12807c478bd9Sstevel@tonic-gate uint8_t *p = (void *)&cp->cp_ecx; 12817c478bd9Sstevel@tonic-gate for (i = 0; i < 4; i++) 12827c478bd9Sstevel@tonic-gate if (p[i] != 0) 12837c478bd9Sstevel@tonic-gate *dp++ = p[i]; 12847c478bd9Sstevel@tonic-gate } 12857c478bd9Sstevel@tonic-gate if (BITX(cp->cp_edx, 31, 31) == 0) { 12867c478bd9Sstevel@tonic-gate uint8_t *p = (void *)&cp->cp_edx; 12877c478bd9Sstevel@tonic-gate for (i = 0; i < 4; i++) 12887c478bd9Sstevel@tonic-gate if (p[i] != 0) 12897c478bd9Sstevel@tonic-gate *dp++ = p[i]; 12907c478bd9Sstevel@tonic-gate } 12917c478bd9Sstevel@tonic-gate break; 1292f98fbcecSbholler 12937c478bd9Sstevel@tonic-gate case 3: /* Processor serial number, if PSN supported */ 1294f98fbcecSbholler break; 1295f98fbcecSbholler 12967c478bd9Sstevel@tonic-gate case 4: /* Deterministic cache parameters */ 1297f98fbcecSbholler break; 1298f98fbcecSbholler 12997c478bd9Sstevel@tonic-gate case 5: /* Monitor/Mwait parameters */ 13005b8a6efeSbholler { 13015b8a6efeSbholler size_t mwait_size; 1302f98fbcecSbholler 1303f98fbcecSbholler /* 1304f98fbcecSbholler * check cpi_mwait.support which was set in cpuid_pass1 1305f98fbcecSbholler */ 1306f98fbcecSbholler if (!(cpi->cpi_mwait.support & MWAIT_SUPPORT)) 1307f98fbcecSbholler break; 1308f98fbcecSbholler 13095b8a6efeSbholler /* 13105b8a6efeSbholler * Protect ourself from insane mwait line size. 13115b8a6efeSbholler * Workaround for incomplete hardware emulator(s). 13125b8a6efeSbholler */ 13135b8a6efeSbholler mwait_size = (size_t)MWAIT_SIZE_MAX(cpi); 13145b8a6efeSbholler if (mwait_size < sizeof (uint32_t) || 13155b8a6efeSbholler !ISP2(mwait_size)) { 13165b8a6efeSbholler #if DEBUG 13175b8a6efeSbholler cmn_err(CE_NOTE, "Cannot handle cpu %d mwait " 13185b8a6efeSbholler "size %ld", 13195b8a6efeSbholler cpu->cpu_id, (long)mwait_size); 13205b8a6efeSbholler #endif 13215b8a6efeSbholler break; 13225b8a6efeSbholler } 13235b8a6efeSbholler 1324f98fbcecSbholler cpi->cpi_mwait.mon_min = (size_t)MWAIT_SIZE_MIN(cpi); 13255b8a6efeSbholler cpi->cpi_mwait.mon_max = mwait_size; 1326f98fbcecSbholler if (MWAIT_EXTENSION(cpi)) { 1327f98fbcecSbholler cpi->cpi_mwait.support |= MWAIT_EXTENSIONS; 1328f98fbcecSbholler if (MWAIT_INT_ENABLE(cpi)) 1329f98fbcecSbholler cpi->cpi_mwait.support |= 1330f98fbcecSbholler MWAIT_ECX_INT_ENABLE; 1331f98fbcecSbholler } 1332f98fbcecSbholler break; 13335b8a6efeSbholler } 13347c478bd9Sstevel@tonic-gate default: 13357c478bd9Sstevel@tonic-gate break; 13367c478bd9Sstevel@tonic-gate } 13377c478bd9Sstevel@tonic-gate } 13387c478bd9Sstevel@tonic-gate 13397c478bd9Sstevel@tonic-gate if ((cpi->cpi_xmaxeax & 0x80000000) == 0) 13407c478bd9Sstevel@tonic-gate goto pass2_done; 13417c478bd9Sstevel@tonic-gate 13427c478bd9Sstevel@tonic-gate if ((nmax = cpi->cpi_xmaxeax - 0x80000000 + 1) > NMAX_CPI_EXTD) 13437c478bd9Sstevel@tonic-gate nmax = NMAX_CPI_EXTD; 13447c478bd9Sstevel@tonic-gate /* 13457c478bd9Sstevel@tonic-gate * Copy the extended properties, fixing them as we go. 13467c478bd9Sstevel@tonic-gate * (We already handled n == 0 and n == 1 in pass 1) 13477c478bd9Sstevel@tonic-gate */ 13487c478bd9Sstevel@tonic-gate iptr = (void *)cpi->cpi_brandstr; 13497c478bd9Sstevel@tonic-gate for (n = 2, cp = &cpi->cpi_extd[2]; n < nmax; cp++, n++) { 13508949bcd6Sandrei cp->cp_eax = 0x80000000 + n; 13518949bcd6Sandrei (void) __cpuid_insn(cp); 1352ae115bc7Smrj platform_cpuid_mangle(cpi->cpi_vendor, 0x80000000 + n, cp); 13537c478bd9Sstevel@tonic-gate switch (n) { 13547c478bd9Sstevel@tonic-gate case 2: 13557c478bd9Sstevel@tonic-gate case 3: 13567c478bd9Sstevel@tonic-gate case 4: 13577c478bd9Sstevel@tonic-gate /* 13587c478bd9Sstevel@tonic-gate * Extract the brand string 13597c478bd9Sstevel@tonic-gate */ 13607c478bd9Sstevel@tonic-gate *iptr++ = cp->cp_eax; 13617c478bd9Sstevel@tonic-gate *iptr++ = cp->cp_ebx; 13627c478bd9Sstevel@tonic-gate *iptr++ = cp->cp_ecx; 13637c478bd9Sstevel@tonic-gate *iptr++ = cp->cp_edx; 13647c478bd9Sstevel@tonic-gate break; 13657c478bd9Sstevel@tonic-gate case 5: 13667c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 13677c478bd9Sstevel@tonic-gate case X86_VENDOR_AMD: 13687c478bd9Sstevel@tonic-gate /* 13697c478bd9Sstevel@tonic-gate * The Athlon and Duron were the first 13707c478bd9Sstevel@tonic-gate * parts to report the sizes of the 13717c478bd9Sstevel@tonic-gate * TLB for large pages. Before then, 13727c478bd9Sstevel@tonic-gate * we don't trust the data. 13737c478bd9Sstevel@tonic-gate */ 13747c478bd9Sstevel@tonic-gate if (cpi->cpi_family < 6 || 13757c478bd9Sstevel@tonic-gate (cpi->cpi_family == 6 && 13767c478bd9Sstevel@tonic-gate cpi->cpi_model < 1)) 13777c478bd9Sstevel@tonic-gate cp->cp_eax = 0; 13787c478bd9Sstevel@tonic-gate break; 13797c478bd9Sstevel@tonic-gate default: 13807c478bd9Sstevel@tonic-gate break; 13817c478bd9Sstevel@tonic-gate } 13827c478bd9Sstevel@tonic-gate break; 13837c478bd9Sstevel@tonic-gate case 6: 13847c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 13857c478bd9Sstevel@tonic-gate case X86_VENDOR_AMD: 13867c478bd9Sstevel@tonic-gate /* 13877c478bd9Sstevel@tonic-gate * The Athlon and Duron were the first 13887c478bd9Sstevel@tonic-gate * AMD parts with L2 TLB's. 13897c478bd9Sstevel@tonic-gate * Before then, don't trust the data. 13907c478bd9Sstevel@tonic-gate */ 13917c478bd9Sstevel@tonic-gate if (cpi->cpi_family < 6 || 13927c478bd9Sstevel@tonic-gate cpi->cpi_family == 6 && 13937c478bd9Sstevel@tonic-gate cpi->cpi_model < 1) 13947c478bd9Sstevel@tonic-gate cp->cp_eax = cp->cp_ebx = 0; 13957c478bd9Sstevel@tonic-gate /* 13967c478bd9Sstevel@tonic-gate * AMD Duron rev A0 reports L2 13977c478bd9Sstevel@tonic-gate * cache size incorrectly as 1K 13987c478bd9Sstevel@tonic-gate * when it is really 64K 13997c478bd9Sstevel@tonic-gate */ 14007c478bd9Sstevel@tonic-gate if (cpi->cpi_family == 6 && 14017c478bd9Sstevel@tonic-gate cpi->cpi_model == 3 && 14027c478bd9Sstevel@tonic-gate cpi->cpi_step == 0) { 14037c478bd9Sstevel@tonic-gate cp->cp_ecx &= 0xffff; 14047c478bd9Sstevel@tonic-gate cp->cp_ecx |= 0x400000; 14057c478bd9Sstevel@tonic-gate } 14067c478bd9Sstevel@tonic-gate break; 14077c478bd9Sstevel@tonic-gate case X86_VENDOR_Cyrix: /* VIA C3 */ 14087c478bd9Sstevel@tonic-gate /* 14097c478bd9Sstevel@tonic-gate * VIA C3 processors are a bit messed 14107c478bd9Sstevel@tonic-gate * up w.r.t. encoding cache sizes in %ecx 14117c478bd9Sstevel@tonic-gate */ 14127c478bd9Sstevel@tonic-gate if (cpi->cpi_family != 6) 14137c478bd9Sstevel@tonic-gate break; 14147c478bd9Sstevel@tonic-gate /* 14157c478bd9Sstevel@tonic-gate * model 7 and 8 were incorrectly encoded 14167c478bd9Sstevel@tonic-gate * 14177c478bd9Sstevel@tonic-gate * xxx is model 8 really broken? 14187c478bd9Sstevel@tonic-gate */ 14197c478bd9Sstevel@tonic-gate if (cpi->cpi_model == 7 || 14207c478bd9Sstevel@tonic-gate cpi->cpi_model == 8) 14217c478bd9Sstevel@tonic-gate cp->cp_ecx = 14227c478bd9Sstevel@tonic-gate BITX(cp->cp_ecx, 31, 24) << 16 | 14237c478bd9Sstevel@tonic-gate BITX(cp->cp_ecx, 23, 16) << 12 | 14247c478bd9Sstevel@tonic-gate BITX(cp->cp_ecx, 15, 8) << 8 | 14257c478bd9Sstevel@tonic-gate BITX(cp->cp_ecx, 7, 0); 14267c478bd9Sstevel@tonic-gate /* 14277c478bd9Sstevel@tonic-gate * model 9 stepping 1 has wrong associativity 14287c478bd9Sstevel@tonic-gate */ 14297c478bd9Sstevel@tonic-gate if (cpi->cpi_model == 9 && cpi->cpi_step == 1) 14307c478bd9Sstevel@tonic-gate cp->cp_ecx |= 8 << 12; 14317c478bd9Sstevel@tonic-gate break; 14327c478bd9Sstevel@tonic-gate case X86_VENDOR_Intel: 14337c478bd9Sstevel@tonic-gate /* 14347c478bd9Sstevel@tonic-gate * Extended L2 Cache features function. 14357c478bd9Sstevel@tonic-gate * First appeared on Prescott. 14367c478bd9Sstevel@tonic-gate */ 14377c478bd9Sstevel@tonic-gate default: 14387c478bd9Sstevel@tonic-gate break; 14397c478bd9Sstevel@tonic-gate } 14407c478bd9Sstevel@tonic-gate break; 14417c478bd9Sstevel@tonic-gate default: 14427c478bd9Sstevel@tonic-gate break; 14437c478bd9Sstevel@tonic-gate } 14447c478bd9Sstevel@tonic-gate } 14457c478bd9Sstevel@tonic-gate 14467c478bd9Sstevel@tonic-gate pass2_done: 14477c478bd9Sstevel@tonic-gate cpi->cpi_pass = 2; 14487c478bd9Sstevel@tonic-gate } 14497c478bd9Sstevel@tonic-gate 14507c478bd9Sstevel@tonic-gate static const char * 14517c478bd9Sstevel@tonic-gate intel_cpubrand(const struct cpuid_info *cpi) 14527c478bd9Sstevel@tonic-gate { 14537c478bd9Sstevel@tonic-gate int i; 14547c478bd9Sstevel@tonic-gate 14557c478bd9Sstevel@tonic-gate if ((x86_feature & X86_CPUID) == 0 || 14567c478bd9Sstevel@tonic-gate cpi->cpi_maxeax < 1 || cpi->cpi_family < 5) 14577c478bd9Sstevel@tonic-gate return ("i486"); 14587c478bd9Sstevel@tonic-gate 14597c478bd9Sstevel@tonic-gate switch (cpi->cpi_family) { 14607c478bd9Sstevel@tonic-gate case 5: 14617c478bd9Sstevel@tonic-gate return ("Intel Pentium(r)"); 14627c478bd9Sstevel@tonic-gate case 6: 14637c478bd9Sstevel@tonic-gate switch (cpi->cpi_model) { 14647c478bd9Sstevel@tonic-gate uint_t celeron, xeon; 14658949bcd6Sandrei const struct cpuid_regs *cp; 14667c478bd9Sstevel@tonic-gate case 0: 14677c478bd9Sstevel@tonic-gate case 1: 14687c478bd9Sstevel@tonic-gate case 2: 14697c478bd9Sstevel@tonic-gate return ("Intel Pentium(r) Pro"); 14707c478bd9Sstevel@tonic-gate case 3: 14717c478bd9Sstevel@tonic-gate case 4: 14727c478bd9Sstevel@tonic-gate return ("Intel Pentium(r) II"); 14737c478bd9Sstevel@tonic-gate case 6: 14747c478bd9Sstevel@tonic-gate return ("Intel Celeron(r)"); 14757c478bd9Sstevel@tonic-gate case 5: 14767c478bd9Sstevel@tonic-gate case 7: 14777c478bd9Sstevel@tonic-gate celeron = xeon = 0; 14787c478bd9Sstevel@tonic-gate cp = &cpi->cpi_std[2]; /* cache info */ 14797c478bd9Sstevel@tonic-gate 14807c478bd9Sstevel@tonic-gate for (i = 1; i < 3; i++) { 14817c478bd9Sstevel@tonic-gate uint_t tmp; 14827c478bd9Sstevel@tonic-gate 14837c478bd9Sstevel@tonic-gate tmp = (cp->cp_eax >> (8 * i)) & 0xff; 14847c478bd9Sstevel@tonic-gate if (tmp == 0x40) 14857c478bd9Sstevel@tonic-gate celeron++; 14867c478bd9Sstevel@tonic-gate if (tmp >= 0x44 && tmp <= 0x45) 14877c478bd9Sstevel@tonic-gate xeon++; 14887c478bd9Sstevel@tonic-gate } 14897c478bd9Sstevel@tonic-gate 14907c478bd9Sstevel@tonic-gate for (i = 0; i < 2; i++) { 14917c478bd9Sstevel@tonic-gate uint_t tmp; 14927c478bd9Sstevel@tonic-gate 14937c478bd9Sstevel@tonic-gate tmp = (cp->cp_ebx >> (8 * i)) & 0xff; 14947c478bd9Sstevel@tonic-gate if (tmp == 0x40) 14957c478bd9Sstevel@tonic-gate celeron++; 14967c478bd9Sstevel@tonic-gate else if (tmp >= 0x44 && tmp <= 0x45) 14977c478bd9Sstevel@tonic-gate xeon++; 14987c478bd9Sstevel@tonic-gate } 14997c478bd9Sstevel@tonic-gate 15007c478bd9Sstevel@tonic-gate for (i = 0; i < 4; i++) { 15017c478bd9Sstevel@tonic-gate uint_t tmp; 15027c478bd9Sstevel@tonic-gate 15037c478bd9Sstevel@tonic-gate tmp = (cp->cp_ecx >> (8 * i)) & 0xff; 15047c478bd9Sstevel@tonic-gate if (tmp == 0x40) 15057c478bd9Sstevel@tonic-gate celeron++; 15067c478bd9Sstevel@tonic-gate else if (tmp >= 0x44 && tmp <= 0x45) 15077c478bd9Sstevel@tonic-gate xeon++; 15087c478bd9Sstevel@tonic-gate } 15097c478bd9Sstevel@tonic-gate 15107c478bd9Sstevel@tonic-gate for (i = 0; i < 4; i++) { 15117c478bd9Sstevel@tonic-gate uint_t tmp; 15127c478bd9Sstevel@tonic-gate 15137c478bd9Sstevel@tonic-gate tmp = (cp->cp_edx >> (8 * i)) & 0xff; 15147c478bd9Sstevel@tonic-gate if (tmp == 0x40) 15157c478bd9Sstevel@tonic-gate celeron++; 15167c478bd9Sstevel@tonic-gate else if (tmp >= 0x44 && tmp <= 0x45) 15177c478bd9Sstevel@tonic-gate xeon++; 15187c478bd9Sstevel@tonic-gate } 15197c478bd9Sstevel@tonic-gate 15207c478bd9Sstevel@tonic-gate if (celeron) 15217c478bd9Sstevel@tonic-gate return ("Intel Celeron(r)"); 15227c478bd9Sstevel@tonic-gate if (xeon) 15237c478bd9Sstevel@tonic-gate return (cpi->cpi_model == 5 ? 15247c478bd9Sstevel@tonic-gate "Intel Pentium(r) II Xeon(tm)" : 15257c478bd9Sstevel@tonic-gate "Intel Pentium(r) III Xeon(tm)"); 15267c478bd9Sstevel@tonic-gate return (cpi->cpi_model == 5 ? 15277c478bd9Sstevel@tonic-gate "Intel Pentium(r) II or Pentium(r) II Xeon(tm)" : 15287c478bd9Sstevel@tonic-gate "Intel Pentium(r) III or Pentium(r) III Xeon(tm)"); 15297c478bd9Sstevel@tonic-gate default: 15307c478bd9Sstevel@tonic-gate break; 15317c478bd9Sstevel@tonic-gate } 15327c478bd9Sstevel@tonic-gate default: 15337c478bd9Sstevel@tonic-gate break; 15347c478bd9Sstevel@tonic-gate } 15357c478bd9Sstevel@tonic-gate 15365ff02082Sdmick /* BrandID is present if the field is nonzero */ 15375ff02082Sdmick if (cpi->cpi_brandid != 0) { 15387c478bd9Sstevel@tonic-gate static const struct { 15397c478bd9Sstevel@tonic-gate uint_t bt_bid; 15407c478bd9Sstevel@tonic-gate const char *bt_str; 15417c478bd9Sstevel@tonic-gate } brand_tbl[] = { 15427c478bd9Sstevel@tonic-gate { 0x1, "Intel(r) Celeron(r)" }, 15437c478bd9Sstevel@tonic-gate { 0x2, "Intel(r) Pentium(r) III" }, 15447c478bd9Sstevel@tonic-gate { 0x3, "Intel(r) Pentium(r) III Xeon(tm)" }, 15457c478bd9Sstevel@tonic-gate { 0x4, "Intel(r) Pentium(r) III" }, 15467c478bd9Sstevel@tonic-gate { 0x6, "Mobile Intel(r) Pentium(r) III" }, 15477c478bd9Sstevel@tonic-gate { 0x7, "Mobile Intel(r) Celeron(r)" }, 15487c478bd9Sstevel@tonic-gate { 0x8, "Intel(r) Pentium(r) 4" }, 15497c478bd9Sstevel@tonic-gate { 0x9, "Intel(r) Pentium(r) 4" }, 15507c478bd9Sstevel@tonic-gate { 0xa, "Intel(r) Celeron(r)" }, 15517c478bd9Sstevel@tonic-gate { 0xb, "Intel(r) Xeon(tm)" }, 15527c478bd9Sstevel@tonic-gate { 0xc, "Intel(r) Xeon(tm) MP" }, 15537c478bd9Sstevel@tonic-gate { 0xe, "Mobile Intel(r) Pentium(r) 4" }, 15545ff02082Sdmick { 0xf, "Mobile Intel(r) Celeron(r)" }, 15555ff02082Sdmick { 0x11, "Mobile Genuine Intel(r)" }, 15565ff02082Sdmick { 0x12, "Intel(r) Celeron(r) M" }, 15575ff02082Sdmick { 0x13, "Mobile Intel(r) Celeron(r)" }, 15585ff02082Sdmick { 0x14, "Intel(r) Celeron(r)" }, 15595ff02082Sdmick { 0x15, "Mobile Genuine Intel(r)" }, 15605ff02082Sdmick { 0x16, "Intel(r) Pentium(r) M" }, 15615ff02082Sdmick { 0x17, "Mobile Intel(r) Celeron(r)" } 15627c478bd9Sstevel@tonic-gate }; 15637c478bd9Sstevel@tonic-gate uint_t btblmax = sizeof (brand_tbl) / sizeof (brand_tbl[0]); 15647c478bd9Sstevel@tonic-gate uint_t sgn; 15657c478bd9Sstevel@tonic-gate 15667c478bd9Sstevel@tonic-gate sgn = (cpi->cpi_family << 8) | 15677c478bd9Sstevel@tonic-gate (cpi->cpi_model << 4) | cpi->cpi_step; 15687c478bd9Sstevel@tonic-gate 15697c478bd9Sstevel@tonic-gate for (i = 0; i < btblmax; i++) 15707c478bd9Sstevel@tonic-gate if (brand_tbl[i].bt_bid == cpi->cpi_brandid) 15717c478bd9Sstevel@tonic-gate break; 15727c478bd9Sstevel@tonic-gate if (i < btblmax) { 15737c478bd9Sstevel@tonic-gate if (sgn == 0x6b1 && cpi->cpi_brandid == 3) 15747c478bd9Sstevel@tonic-gate return ("Intel(r) Celeron(r)"); 15757c478bd9Sstevel@tonic-gate if (sgn < 0xf13 && cpi->cpi_brandid == 0xb) 15767c478bd9Sstevel@tonic-gate return ("Intel(r) Xeon(tm) MP"); 15777c478bd9Sstevel@tonic-gate if (sgn < 0xf13 && cpi->cpi_brandid == 0xe) 15787c478bd9Sstevel@tonic-gate return ("Intel(r) Xeon(tm)"); 15797c478bd9Sstevel@tonic-gate return (brand_tbl[i].bt_str); 15807c478bd9Sstevel@tonic-gate } 15817c478bd9Sstevel@tonic-gate } 15827c478bd9Sstevel@tonic-gate 15837c478bd9Sstevel@tonic-gate return (NULL); 15847c478bd9Sstevel@tonic-gate } 15857c478bd9Sstevel@tonic-gate 15867c478bd9Sstevel@tonic-gate static const char * 15877c478bd9Sstevel@tonic-gate amd_cpubrand(const struct cpuid_info *cpi) 15887c478bd9Sstevel@tonic-gate { 15897c478bd9Sstevel@tonic-gate if ((x86_feature & X86_CPUID) == 0 || 15907c478bd9Sstevel@tonic-gate cpi->cpi_maxeax < 1 || cpi->cpi_family < 5) 15917c478bd9Sstevel@tonic-gate return ("i486 compatible"); 15927c478bd9Sstevel@tonic-gate 15937c478bd9Sstevel@tonic-gate switch (cpi->cpi_family) { 15947c478bd9Sstevel@tonic-gate case 5: 15957c478bd9Sstevel@tonic-gate switch (cpi->cpi_model) { 15967c478bd9Sstevel@tonic-gate case 0: 15977c478bd9Sstevel@tonic-gate case 1: 15987c478bd9Sstevel@tonic-gate case 2: 15997c478bd9Sstevel@tonic-gate case 3: 16007c478bd9Sstevel@tonic-gate case 4: 16017c478bd9Sstevel@tonic-gate case 5: 16027c478bd9Sstevel@tonic-gate return ("AMD-K5(r)"); 16037c478bd9Sstevel@tonic-gate case 6: 16047c478bd9Sstevel@tonic-gate case 7: 16057c478bd9Sstevel@tonic-gate return ("AMD-K6(r)"); 16067c478bd9Sstevel@tonic-gate case 8: 16077c478bd9Sstevel@tonic-gate return ("AMD-K6(r)-2"); 16087c478bd9Sstevel@tonic-gate case 9: 16097c478bd9Sstevel@tonic-gate return ("AMD-K6(r)-III"); 16107c478bd9Sstevel@tonic-gate default: 16117c478bd9Sstevel@tonic-gate return ("AMD (family 5)"); 16127c478bd9Sstevel@tonic-gate } 16137c478bd9Sstevel@tonic-gate case 6: 16147c478bd9Sstevel@tonic-gate switch (cpi->cpi_model) { 16157c478bd9Sstevel@tonic-gate case 1: 16167c478bd9Sstevel@tonic-gate return ("AMD-K7(tm)"); 16177c478bd9Sstevel@tonic-gate case 0: 16187c478bd9Sstevel@tonic-gate case 2: 16197c478bd9Sstevel@tonic-gate case 4: 16207c478bd9Sstevel@tonic-gate return ("AMD Athlon(tm)"); 16217c478bd9Sstevel@tonic-gate case 3: 16227c478bd9Sstevel@tonic-gate case 7: 16237c478bd9Sstevel@tonic-gate return ("AMD Duron(tm)"); 16247c478bd9Sstevel@tonic-gate case 6: 16257c478bd9Sstevel@tonic-gate case 8: 16267c478bd9Sstevel@tonic-gate case 10: 16277c478bd9Sstevel@tonic-gate /* 16287c478bd9Sstevel@tonic-gate * Use the L2 cache size to distinguish 16297c478bd9Sstevel@tonic-gate */ 16307c478bd9Sstevel@tonic-gate return ((cpi->cpi_extd[6].cp_ecx >> 16) >= 256 ? 16317c478bd9Sstevel@tonic-gate "AMD Athlon(tm)" : "AMD Duron(tm)"); 16327c478bd9Sstevel@tonic-gate default: 16337c478bd9Sstevel@tonic-gate return ("AMD (family 6)"); 16347c478bd9Sstevel@tonic-gate } 16357c478bd9Sstevel@tonic-gate default: 16367c478bd9Sstevel@tonic-gate break; 16377c478bd9Sstevel@tonic-gate } 16387c478bd9Sstevel@tonic-gate 16397c478bd9Sstevel@tonic-gate if (cpi->cpi_family == 0xf && cpi->cpi_model == 5 && 16407c478bd9Sstevel@tonic-gate cpi->cpi_brandid != 0) { 16417c478bd9Sstevel@tonic-gate switch (BITX(cpi->cpi_brandid, 7, 5)) { 16427c478bd9Sstevel@tonic-gate case 3: 16437c478bd9Sstevel@tonic-gate return ("AMD Opteron(tm) UP 1xx"); 16447c478bd9Sstevel@tonic-gate case 4: 16457c478bd9Sstevel@tonic-gate return ("AMD Opteron(tm) DP 2xx"); 16467c478bd9Sstevel@tonic-gate case 5: 16477c478bd9Sstevel@tonic-gate return ("AMD Opteron(tm) MP 8xx"); 16487c478bd9Sstevel@tonic-gate default: 16497c478bd9Sstevel@tonic-gate return ("AMD Opteron(tm)"); 16507c478bd9Sstevel@tonic-gate } 16517c478bd9Sstevel@tonic-gate } 16527c478bd9Sstevel@tonic-gate 16537c478bd9Sstevel@tonic-gate return (NULL); 16547c478bd9Sstevel@tonic-gate } 16557c478bd9Sstevel@tonic-gate 16567c478bd9Sstevel@tonic-gate static const char * 16577c478bd9Sstevel@tonic-gate cyrix_cpubrand(struct cpuid_info *cpi, uint_t type) 16587c478bd9Sstevel@tonic-gate { 16597c478bd9Sstevel@tonic-gate if ((x86_feature & X86_CPUID) == 0 || 16607c478bd9Sstevel@tonic-gate cpi->cpi_maxeax < 1 || cpi->cpi_family < 5 || 16617c478bd9Sstevel@tonic-gate type == X86_TYPE_CYRIX_486) 16627c478bd9Sstevel@tonic-gate return ("i486 compatible"); 16637c478bd9Sstevel@tonic-gate 16647c478bd9Sstevel@tonic-gate switch (type) { 16657c478bd9Sstevel@tonic-gate case X86_TYPE_CYRIX_6x86: 16667c478bd9Sstevel@tonic-gate return ("Cyrix 6x86"); 16677c478bd9Sstevel@tonic-gate case X86_TYPE_CYRIX_6x86L: 16687c478bd9Sstevel@tonic-gate return ("Cyrix 6x86L"); 16697c478bd9Sstevel@tonic-gate case X86_TYPE_CYRIX_6x86MX: 16707c478bd9Sstevel@tonic-gate return ("Cyrix 6x86MX"); 16717c478bd9Sstevel@tonic-gate case X86_TYPE_CYRIX_GXm: 16727c478bd9Sstevel@tonic-gate return ("Cyrix GXm"); 16737c478bd9Sstevel@tonic-gate case X86_TYPE_CYRIX_MediaGX: 16747c478bd9Sstevel@tonic-gate return ("Cyrix MediaGX"); 16757c478bd9Sstevel@tonic-gate case X86_TYPE_CYRIX_MII: 16767c478bd9Sstevel@tonic-gate return ("Cyrix M2"); 16777c478bd9Sstevel@tonic-gate case X86_TYPE_VIA_CYRIX_III: 16787c478bd9Sstevel@tonic-gate return ("VIA Cyrix M3"); 16797c478bd9Sstevel@tonic-gate default: 16807c478bd9Sstevel@tonic-gate /* 16817c478bd9Sstevel@tonic-gate * Have another wild guess .. 16827c478bd9Sstevel@tonic-gate */ 16837c478bd9Sstevel@tonic-gate if (cpi->cpi_family == 4 && cpi->cpi_model == 9) 16847c478bd9Sstevel@tonic-gate return ("Cyrix 5x86"); 16857c478bd9Sstevel@tonic-gate else if (cpi->cpi_family == 5) { 16867c478bd9Sstevel@tonic-gate switch (cpi->cpi_model) { 16877c478bd9Sstevel@tonic-gate case 2: 16887c478bd9Sstevel@tonic-gate return ("Cyrix 6x86"); /* Cyrix M1 */ 16897c478bd9Sstevel@tonic-gate case 4: 16907c478bd9Sstevel@tonic-gate return ("Cyrix MediaGX"); 16917c478bd9Sstevel@tonic-gate default: 16927c478bd9Sstevel@tonic-gate break; 16937c478bd9Sstevel@tonic-gate } 16947c478bd9Sstevel@tonic-gate } else if (cpi->cpi_family == 6) { 16957c478bd9Sstevel@tonic-gate switch (cpi->cpi_model) { 16967c478bd9Sstevel@tonic-gate case 0: 16977c478bd9Sstevel@tonic-gate return ("Cyrix 6x86MX"); /* Cyrix M2? */ 16987c478bd9Sstevel@tonic-gate case 5: 16997c478bd9Sstevel@tonic-gate case 6: 17007c478bd9Sstevel@tonic-gate case 7: 17017c478bd9Sstevel@tonic-gate case 8: 17027c478bd9Sstevel@tonic-gate case 9: 17037c478bd9Sstevel@tonic-gate return ("VIA C3"); 17047c478bd9Sstevel@tonic-gate default: 17057c478bd9Sstevel@tonic-gate break; 17067c478bd9Sstevel@tonic-gate } 17077c478bd9Sstevel@tonic-gate } 17087c478bd9Sstevel@tonic-gate break; 17097c478bd9Sstevel@tonic-gate } 17107c478bd9Sstevel@tonic-gate return (NULL); 17117c478bd9Sstevel@tonic-gate } 17127c478bd9Sstevel@tonic-gate 17137c478bd9Sstevel@tonic-gate /* 17147c478bd9Sstevel@tonic-gate * This only gets called in the case that the CPU extended 17157c478bd9Sstevel@tonic-gate * feature brand string (0x80000002, 0x80000003, 0x80000004) 17167c478bd9Sstevel@tonic-gate * aren't available, or contain null bytes for some reason. 17177c478bd9Sstevel@tonic-gate */ 17187c478bd9Sstevel@tonic-gate static void 17197c478bd9Sstevel@tonic-gate fabricate_brandstr(struct cpuid_info *cpi) 17207c478bd9Sstevel@tonic-gate { 17217c478bd9Sstevel@tonic-gate const char *brand = NULL; 17227c478bd9Sstevel@tonic-gate 17237c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 17247c478bd9Sstevel@tonic-gate case X86_VENDOR_Intel: 17257c478bd9Sstevel@tonic-gate brand = intel_cpubrand(cpi); 17267c478bd9Sstevel@tonic-gate break; 17277c478bd9Sstevel@tonic-gate case X86_VENDOR_AMD: 17287c478bd9Sstevel@tonic-gate brand = amd_cpubrand(cpi); 17297c478bd9Sstevel@tonic-gate break; 17307c478bd9Sstevel@tonic-gate case X86_VENDOR_Cyrix: 17317c478bd9Sstevel@tonic-gate brand = cyrix_cpubrand(cpi, x86_type); 17327c478bd9Sstevel@tonic-gate break; 17337c478bd9Sstevel@tonic-gate case X86_VENDOR_NexGen: 17347c478bd9Sstevel@tonic-gate if (cpi->cpi_family == 5 && cpi->cpi_model == 0) 17357c478bd9Sstevel@tonic-gate brand = "NexGen Nx586"; 17367c478bd9Sstevel@tonic-gate break; 17377c478bd9Sstevel@tonic-gate case X86_VENDOR_Centaur: 17387c478bd9Sstevel@tonic-gate if (cpi->cpi_family == 5) 17397c478bd9Sstevel@tonic-gate switch (cpi->cpi_model) { 17407c478bd9Sstevel@tonic-gate case 4: 17417c478bd9Sstevel@tonic-gate brand = "Centaur C6"; 17427c478bd9Sstevel@tonic-gate break; 17437c478bd9Sstevel@tonic-gate case 8: 17447c478bd9Sstevel@tonic-gate brand = "Centaur C2"; 17457c478bd9Sstevel@tonic-gate break; 17467c478bd9Sstevel@tonic-gate case 9: 17477c478bd9Sstevel@tonic-gate brand = "Centaur C3"; 17487c478bd9Sstevel@tonic-gate break; 17497c478bd9Sstevel@tonic-gate default: 17507c478bd9Sstevel@tonic-gate break; 17517c478bd9Sstevel@tonic-gate } 17527c478bd9Sstevel@tonic-gate break; 17537c478bd9Sstevel@tonic-gate case X86_VENDOR_Rise: 17547c478bd9Sstevel@tonic-gate if (cpi->cpi_family == 5 && 17557c478bd9Sstevel@tonic-gate (cpi->cpi_model == 0 || cpi->cpi_model == 2)) 17567c478bd9Sstevel@tonic-gate brand = "Rise mP6"; 17577c478bd9Sstevel@tonic-gate break; 17587c478bd9Sstevel@tonic-gate case X86_VENDOR_SiS: 17597c478bd9Sstevel@tonic-gate if (cpi->cpi_family == 5 && cpi->cpi_model == 0) 17607c478bd9Sstevel@tonic-gate brand = "SiS 55x"; 17617c478bd9Sstevel@tonic-gate break; 17627c478bd9Sstevel@tonic-gate case X86_VENDOR_TM: 17637c478bd9Sstevel@tonic-gate if (cpi->cpi_family == 5 && cpi->cpi_model == 4) 17647c478bd9Sstevel@tonic-gate brand = "Transmeta Crusoe TM3x00 or TM5x00"; 17657c478bd9Sstevel@tonic-gate break; 17667c478bd9Sstevel@tonic-gate case X86_VENDOR_NSC: 17677c478bd9Sstevel@tonic-gate case X86_VENDOR_UMC: 17687c478bd9Sstevel@tonic-gate default: 17697c478bd9Sstevel@tonic-gate break; 17707c478bd9Sstevel@tonic-gate } 17717c478bd9Sstevel@tonic-gate if (brand) { 17727c478bd9Sstevel@tonic-gate (void) strcpy((char *)cpi->cpi_brandstr, brand); 17737c478bd9Sstevel@tonic-gate return; 17747c478bd9Sstevel@tonic-gate } 17757c478bd9Sstevel@tonic-gate 17767c478bd9Sstevel@tonic-gate /* 17777c478bd9Sstevel@tonic-gate * If all else fails ... 17787c478bd9Sstevel@tonic-gate */ 17797c478bd9Sstevel@tonic-gate (void) snprintf(cpi->cpi_brandstr, sizeof (cpi->cpi_brandstr), 17807c478bd9Sstevel@tonic-gate "%s %d.%d.%d", cpi->cpi_vendorstr, cpi->cpi_family, 17817c478bd9Sstevel@tonic-gate cpi->cpi_model, cpi->cpi_step); 17827c478bd9Sstevel@tonic-gate } 17837c478bd9Sstevel@tonic-gate 17847c478bd9Sstevel@tonic-gate /* 17857c478bd9Sstevel@tonic-gate * This routine is called just after kernel memory allocation 17867c478bd9Sstevel@tonic-gate * becomes available on cpu0, and as part of mp_startup() on 17877c478bd9Sstevel@tonic-gate * the other cpus. 17887c478bd9Sstevel@tonic-gate * 1789d129bde2Sesaxe * Fixup the brand string, and collect any information from cpuid 1790d129bde2Sesaxe * that requires dynamicically allocated storage to represent. 17917c478bd9Sstevel@tonic-gate */ 17927c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 17937c478bd9Sstevel@tonic-gate void 17947c478bd9Sstevel@tonic-gate cpuid_pass3(cpu_t *cpu) 17957c478bd9Sstevel@tonic-gate { 1796d129bde2Sesaxe int i, max, shft, level, size; 1797d129bde2Sesaxe struct cpuid_regs regs; 1798d129bde2Sesaxe struct cpuid_regs *cp; 17997c478bd9Sstevel@tonic-gate struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 18007c478bd9Sstevel@tonic-gate 18017c478bd9Sstevel@tonic-gate ASSERT(cpi->cpi_pass == 2); 18027c478bd9Sstevel@tonic-gate 1803d129bde2Sesaxe /* 1804d129bde2Sesaxe * Function 4: Deterministic cache parameters 1805d129bde2Sesaxe * 1806d129bde2Sesaxe * Take this opportunity to detect the number of threads 1807d129bde2Sesaxe * sharing the last level cache, and construct a corresponding 1808d129bde2Sesaxe * cache id. The respective cpuid_info members are initialized 1809d129bde2Sesaxe * to the default case of "no last level cache sharing". 1810d129bde2Sesaxe */ 1811d129bde2Sesaxe cpi->cpi_ncpu_shr_last_cache = 1; 1812d129bde2Sesaxe cpi->cpi_last_lvl_cacheid = cpu->cpu_id; 1813d129bde2Sesaxe 1814d129bde2Sesaxe if (cpi->cpi_maxeax >= 4 && cpi->cpi_vendor == X86_VENDOR_Intel) { 1815d129bde2Sesaxe 1816d129bde2Sesaxe /* 1817d129bde2Sesaxe * Find the # of elements (size) returned by fn 4, and along 1818d129bde2Sesaxe * the way detect last level cache sharing details. 1819d129bde2Sesaxe */ 1820d129bde2Sesaxe bzero(®s, sizeof (regs)); 1821d129bde2Sesaxe cp = ®s; 1822d129bde2Sesaxe for (i = 0, max = 0; i < CPI_FN4_ECX_MAX; i++) { 1823d129bde2Sesaxe cp->cp_eax = 4; 1824d129bde2Sesaxe cp->cp_ecx = i; 1825d129bde2Sesaxe 1826d129bde2Sesaxe (void) __cpuid_insn(cp); 1827d129bde2Sesaxe 1828d129bde2Sesaxe if (CPI_CACHE_TYPE(cp) == 0) 1829d129bde2Sesaxe break; 1830d129bde2Sesaxe level = CPI_CACHE_LVL(cp); 1831d129bde2Sesaxe if (level > max) { 1832d129bde2Sesaxe max = level; 1833d129bde2Sesaxe cpi->cpi_ncpu_shr_last_cache = 1834d129bde2Sesaxe CPI_NTHR_SHR_CACHE(cp) + 1; 1835d129bde2Sesaxe } 1836d129bde2Sesaxe } 1837d129bde2Sesaxe cpi->cpi_std_4_size = size = i; 1838d129bde2Sesaxe 1839d129bde2Sesaxe /* 1840d129bde2Sesaxe * Allocate the cpi_std_4 array. The first element 1841d129bde2Sesaxe * references the regs for fn 4, %ecx == 0, which 1842d129bde2Sesaxe * cpuid_pass2() stashed in cpi->cpi_std[4]. 1843d129bde2Sesaxe */ 1844d129bde2Sesaxe if (size > 0) { 1845d129bde2Sesaxe cpi->cpi_std_4 = 1846d129bde2Sesaxe kmem_alloc(size * sizeof (cp), KM_SLEEP); 1847d129bde2Sesaxe cpi->cpi_std_4[0] = &cpi->cpi_std[4]; 1848d129bde2Sesaxe 1849d129bde2Sesaxe /* 1850d129bde2Sesaxe * Allocate storage to hold the additional regs 1851d129bde2Sesaxe * for function 4, %ecx == 1 .. cpi_std_4_size. 1852d129bde2Sesaxe * 1853d129bde2Sesaxe * The regs for fn 4, %ecx == 0 has already 1854d129bde2Sesaxe * been allocated as indicated above. 1855d129bde2Sesaxe */ 1856d129bde2Sesaxe for (i = 1; i < size; i++) { 1857d129bde2Sesaxe cp = cpi->cpi_std_4[i] = 1858d129bde2Sesaxe kmem_zalloc(sizeof (regs), KM_SLEEP); 1859d129bde2Sesaxe cp->cp_eax = 4; 1860d129bde2Sesaxe cp->cp_ecx = i; 1861d129bde2Sesaxe 1862d129bde2Sesaxe (void) __cpuid_insn(cp); 1863d129bde2Sesaxe } 1864d129bde2Sesaxe } 1865d129bde2Sesaxe /* 1866d129bde2Sesaxe * Determine the number of bits needed to represent 1867d129bde2Sesaxe * the number of CPUs sharing the last level cache. 1868d129bde2Sesaxe * 1869d129bde2Sesaxe * Shift off that number of bits from the APIC id to 1870d129bde2Sesaxe * derive the cache id. 1871d129bde2Sesaxe */ 1872d129bde2Sesaxe shft = 0; 1873d129bde2Sesaxe for (i = 1; i < cpi->cpi_ncpu_shr_last_cache; i <<= 1) 1874d129bde2Sesaxe shft++; 1875d129bde2Sesaxe cpi->cpi_last_lvl_cacheid = CPI_APIC_ID(cpi) >> shft; 1876d129bde2Sesaxe } 1877d129bde2Sesaxe 1878d129bde2Sesaxe /* 1879d129bde2Sesaxe * Now fixup the brand string 1880d129bde2Sesaxe */ 18817c478bd9Sstevel@tonic-gate if ((cpi->cpi_xmaxeax & 0x80000000) == 0) { 18827c478bd9Sstevel@tonic-gate fabricate_brandstr(cpi); 1883d129bde2Sesaxe } else { 18847c478bd9Sstevel@tonic-gate 18857c478bd9Sstevel@tonic-gate /* 18867c478bd9Sstevel@tonic-gate * If we successfully extracted a brand string from the cpuid 18877c478bd9Sstevel@tonic-gate * instruction, clean it up by removing leading spaces and 18887c478bd9Sstevel@tonic-gate * similar junk. 18897c478bd9Sstevel@tonic-gate */ 18907c478bd9Sstevel@tonic-gate if (cpi->cpi_brandstr[0]) { 18917c478bd9Sstevel@tonic-gate size_t maxlen = sizeof (cpi->cpi_brandstr); 18927c478bd9Sstevel@tonic-gate char *src, *dst; 18937c478bd9Sstevel@tonic-gate 18947c478bd9Sstevel@tonic-gate dst = src = (char *)cpi->cpi_brandstr; 18957c478bd9Sstevel@tonic-gate src[maxlen - 1] = '\0'; 18967c478bd9Sstevel@tonic-gate /* 18977c478bd9Sstevel@tonic-gate * strip leading spaces 18987c478bd9Sstevel@tonic-gate */ 18997c478bd9Sstevel@tonic-gate while (*src == ' ') 19007c478bd9Sstevel@tonic-gate src++; 19017c478bd9Sstevel@tonic-gate /* 19027c478bd9Sstevel@tonic-gate * Remove any 'Genuine' or "Authentic" prefixes 19037c478bd9Sstevel@tonic-gate */ 19047c478bd9Sstevel@tonic-gate if (strncmp(src, "Genuine ", 8) == 0) 19057c478bd9Sstevel@tonic-gate src += 8; 19067c478bd9Sstevel@tonic-gate if (strncmp(src, "Authentic ", 10) == 0) 19077c478bd9Sstevel@tonic-gate src += 10; 19087c478bd9Sstevel@tonic-gate 19097c478bd9Sstevel@tonic-gate /* 19107c478bd9Sstevel@tonic-gate * Now do an in-place copy. 19117c478bd9Sstevel@tonic-gate * Map (R) to (r) and (TM) to (tm). 19127c478bd9Sstevel@tonic-gate * The era of teletypes is long gone, and there's 19137c478bd9Sstevel@tonic-gate * -really- no need to shout. 19147c478bd9Sstevel@tonic-gate */ 19157c478bd9Sstevel@tonic-gate while (*src != '\0') { 19167c478bd9Sstevel@tonic-gate if (src[0] == '(') { 19177c478bd9Sstevel@tonic-gate if (strncmp(src + 1, "R)", 2) == 0) { 19187c478bd9Sstevel@tonic-gate (void) strncpy(dst, "(r)", 3); 19197c478bd9Sstevel@tonic-gate src += 3; 19207c478bd9Sstevel@tonic-gate dst += 3; 19217c478bd9Sstevel@tonic-gate continue; 19227c478bd9Sstevel@tonic-gate } 19237c478bd9Sstevel@tonic-gate if (strncmp(src + 1, "TM)", 3) == 0) { 19247c478bd9Sstevel@tonic-gate (void) strncpy(dst, "(tm)", 4); 19257c478bd9Sstevel@tonic-gate src += 4; 19267c478bd9Sstevel@tonic-gate dst += 4; 19277c478bd9Sstevel@tonic-gate continue; 19287c478bd9Sstevel@tonic-gate } 19297c478bd9Sstevel@tonic-gate } 19307c478bd9Sstevel@tonic-gate *dst++ = *src++; 19317c478bd9Sstevel@tonic-gate } 19327c478bd9Sstevel@tonic-gate *dst = '\0'; 19337c478bd9Sstevel@tonic-gate 19347c478bd9Sstevel@tonic-gate /* 19357c478bd9Sstevel@tonic-gate * Finally, remove any trailing spaces 19367c478bd9Sstevel@tonic-gate */ 19377c478bd9Sstevel@tonic-gate while (--dst > cpi->cpi_brandstr) 19387c478bd9Sstevel@tonic-gate if (*dst == ' ') 19397c478bd9Sstevel@tonic-gate *dst = '\0'; 19407c478bd9Sstevel@tonic-gate else 19417c478bd9Sstevel@tonic-gate break; 19427c478bd9Sstevel@tonic-gate } else 19437c478bd9Sstevel@tonic-gate fabricate_brandstr(cpi); 1944d129bde2Sesaxe } 19457c478bd9Sstevel@tonic-gate cpi->cpi_pass = 3; 19467c478bd9Sstevel@tonic-gate } 19477c478bd9Sstevel@tonic-gate 19487c478bd9Sstevel@tonic-gate /* 19497c478bd9Sstevel@tonic-gate * This routine is called out of bind_hwcap() much later in the life 19507c478bd9Sstevel@tonic-gate * of the kernel (post_startup()). The job of this routine is to resolve 19517c478bd9Sstevel@tonic-gate * the hardware feature support and kernel support for those features into 19527c478bd9Sstevel@tonic-gate * what we're actually going to tell applications via the aux vector. 19537c478bd9Sstevel@tonic-gate */ 19547c478bd9Sstevel@tonic-gate uint_t 19557c478bd9Sstevel@tonic-gate cpuid_pass4(cpu_t *cpu) 19567c478bd9Sstevel@tonic-gate { 19577c478bd9Sstevel@tonic-gate struct cpuid_info *cpi; 19587c478bd9Sstevel@tonic-gate uint_t hwcap_flags = 0; 19597c478bd9Sstevel@tonic-gate 19607c478bd9Sstevel@tonic-gate if (cpu == NULL) 19617c478bd9Sstevel@tonic-gate cpu = CPU; 19627c478bd9Sstevel@tonic-gate cpi = cpu->cpu_m.mcpu_cpi; 19637c478bd9Sstevel@tonic-gate 19647c478bd9Sstevel@tonic-gate ASSERT(cpi->cpi_pass == 3); 19657c478bd9Sstevel@tonic-gate 19667c478bd9Sstevel@tonic-gate if (cpi->cpi_maxeax >= 1) { 19677c478bd9Sstevel@tonic-gate uint32_t *edx = &cpi->cpi_support[STD_EDX_FEATURES]; 19687c478bd9Sstevel@tonic-gate uint32_t *ecx = &cpi->cpi_support[STD_ECX_FEATURES]; 19697c478bd9Sstevel@tonic-gate 19707c478bd9Sstevel@tonic-gate *edx = CPI_FEATURES_EDX(cpi); 19717c478bd9Sstevel@tonic-gate *ecx = CPI_FEATURES_ECX(cpi); 19727c478bd9Sstevel@tonic-gate 19737c478bd9Sstevel@tonic-gate /* 19747c478bd9Sstevel@tonic-gate * [these require explicit kernel support] 19757c478bd9Sstevel@tonic-gate */ 19767c478bd9Sstevel@tonic-gate if ((x86_feature & X86_SEP) == 0) 19777c478bd9Sstevel@tonic-gate *edx &= ~CPUID_INTC_EDX_SEP; 19787c478bd9Sstevel@tonic-gate 19797c478bd9Sstevel@tonic-gate if ((x86_feature & X86_SSE) == 0) 19807c478bd9Sstevel@tonic-gate *edx &= ~(CPUID_INTC_EDX_FXSR|CPUID_INTC_EDX_SSE); 19817c478bd9Sstevel@tonic-gate if ((x86_feature & X86_SSE2) == 0) 19827c478bd9Sstevel@tonic-gate *edx &= ~CPUID_INTC_EDX_SSE2; 19837c478bd9Sstevel@tonic-gate 19847c478bd9Sstevel@tonic-gate if ((x86_feature & X86_HTT) == 0) 19857c478bd9Sstevel@tonic-gate *edx &= ~CPUID_INTC_EDX_HTT; 19867c478bd9Sstevel@tonic-gate 19877c478bd9Sstevel@tonic-gate if ((x86_feature & X86_SSE3) == 0) 19887c478bd9Sstevel@tonic-gate *ecx &= ~CPUID_INTC_ECX_SSE3; 19897c478bd9Sstevel@tonic-gate 19907c478bd9Sstevel@tonic-gate /* 19917c478bd9Sstevel@tonic-gate * [no explicit support required beyond x87 fp context] 19927c478bd9Sstevel@tonic-gate */ 19937c478bd9Sstevel@tonic-gate if (!fpu_exists) 19947c478bd9Sstevel@tonic-gate *edx &= ~(CPUID_INTC_EDX_FPU | CPUID_INTC_EDX_MMX); 19957c478bd9Sstevel@tonic-gate 19967c478bd9Sstevel@tonic-gate /* 19977c478bd9Sstevel@tonic-gate * Now map the supported feature vector to things that we 19987c478bd9Sstevel@tonic-gate * think userland will care about. 19997c478bd9Sstevel@tonic-gate */ 20007c478bd9Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_SEP) 20017c478bd9Sstevel@tonic-gate hwcap_flags |= AV_386_SEP; 20027c478bd9Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_SSE) 20037c478bd9Sstevel@tonic-gate hwcap_flags |= AV_386_FXSR | AV_386_SSE; 20047c478bd9Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_SSE2) 20057c478bd9Sstevel@tonic-gate hwcap_flags |= AV_386_SSE2; 20067c478bd9Sstevel@tonic-gate if (*ecx & CPUID_INTC_ECX_SSE3) 20077c478bd9Sstevel@tonic-gate hwcap_flags |= AV_386_SSE3; 2008f8801251Skk208521 if (*ecx & CPUID_INTC_ECX_POPCNT) 2009f8801251Skk208521 hwcap_flags |= AV_386_POPCNT; 20107c478bd9Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_FPU) 20117c478bd9Sstevel@tonic-gate hwcap_flags |= AV_386_FPU; 20127c478bd9Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_MMX) 20137c478bd9Sstevel@tonic-gate hwcap_flags |= AV_386_MMX; 20147c478bd9Sstevel@tonic-gate 20157c478bd9Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_TSC) 20167c478bd9Sstevel@tonic-gate hwcap_flags |= AV_386_TSC; 20177c478bd9Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_CX8) 20187c478bd9Sstevel@tonic-gate hwcap_flags |= AV_386_CX8; 20197c478bd9Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_CMOV) 20207c478bd9Sstevel@tonic-gate hwcap_flags |= AV_386_CMOV; 20217c478bd9Sstevel@tonic-gate if (*ecx & CPUID_INTC_ECX_MON) 20227c478bd9Sstevel@tonic-gate hwcap_flags |= AV_386_MON; 20237c478bd9Sstevel@tonic-gate if (*ecx & CPUID_INTC_ECX_CX16) 20247c478bd9Sstevel@tonic-gate hwcap_flags |= AV_386_CX16; 20257c478bd9Sstevel@tonic-gate } 20267c478bd9Sstevel@tonic-gate 20278949bcd6Sandrei if (x86_feature & X86_HTT) 20287c478bd9Sstevel@tonic-gate hwcap_flags |= AV_386_PAUSE; 20297c478bd9Sstevel@tonic-gate 20307c478bd9Sstevel@tonic-gate if (cpi->cpi_xmaxeax < 0x80000001) 20317c478bd9Sstevel@tonic-gate goto pass4_done; 20327c478bd9Sstevel@tonic-gate 20337c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 20348949bcd6Sandrei struct cpuid_regs cp; 2035ae115bc7Smrj uint32_t *edx, *ecx; 20367c478bd9Sstevel@tonic-gate 2037ae115bc7Smrj case X86_VENDOR_Intel: 2038ae115bc7Smrj /* 2039ae115bc7Smrj * Seems like Intel duplicated what we necessary 2040ae115bc7Smrj * here to make the initial crop of 64-bit OS's work. 2041ae115bc7Smrj * Hopefully, those are the only "extended" bits 2042ae115bc7Smrj * they'll add. 2043ae115bc7Smrj */ 2044ae115bc7Smrj /*FALLTHROUGH*/ 2045ae115bc7Smrj 20467c478bd9Sstevel@tonic-gate case X86_VENDOR_AMD: 20477c478bd9Sstevel@tonic-gate edx = &cpi->cpi_support[AMD_EDX_FEATURES]; 2048ae115bc7Smrj ecx = &cpi->cpi_support[AMD_ECX_FEATURES]; 20497c478bd9Sstevel@tonic-gate 20507c478bd9Sstevel@tonic-gate *edx = CPI_FEATURES_XTD_EDX(cpi); 2051ae115bc7Smrj *ecx = CPI_FEATURES_XTD_ECX(cpi); 2052ae115bc7Smrj 2053ae115bc7Smrj /* 2054ae115bc7Smrj * [these features require explicit kernel support] 2055ae115bc7Smrj */ 2056ae115bc7Smrj switch (cpi->cpi_vendor) { 2057ae115bc7Smrj case X86_VENDOR_Intel: 2058ae115bc7Smrj break; 2059ae115bc7Smrj 2060ae115bc7Smrj case X86_VENDOR_AMD: 2061ae115bc7Smrj if ((x86_feature & X86_TSCP) == 0) 2062ae115bc7Smrj *edx &= ~CPUID_AMD_EDX_TSCP; 2063f8801251Skk208521 if ((x86_feature & X86_SSE4A) == 0) 2064f8801251Skk208521 *ecx &= ~CPUID_AMD_ECX_SSE4A; 2065ae115bc7Smrj break; 2066ae115bc7Smrj 2067ae115bc7Smrj default: 2068ae115bc7Smrj break; 2069ae115bc7Smrj } 20707c478bd9Sstevel@tonic-gate 20717c478bd9Sstevel@tonic-gate /* 20727c478bd9Sstevel@tonic-gate * [no explicit support required beyond 20737c478bd9Sstevel@tonic-gate * x87 fp context and exception handlers] 20747c478bd9Sstevel@tonic-gate */ 20757c478bd9Sstevel@tonic-gate if (!fpu_exists) 20767c478bd9Sstevel@tonic-gate *edx &= ~(CPUID_AMD_EDX_MMXamd | 20777c478bd9Sstevel@tonic-gate CPUID_AMD_EDX_3DNow | CPUID_AMD_EDX_3DNowx); 20787c478bd9Sstevel@tonic-gate 20797c478bd9Sstevel@tonic-gate if ((x86_feature & X86_NX) == 0) 20807c478bd9Sstevel@tonic-gate *edx &= ~CPUID_AMD_EDX_NX; 2081ae115bc7Smrj #if !defined(__amd64) 20827c478bd9Sstevel@tonic-gate *edx &= ~CPUID_AMD_EDX_LM; 20837c478bd9Sstevel@tonic-gate #endif 20847c478bd9Sstevel@tonic-gate /* 20857c478bd9Sstevel@tonic-gate * Now map the supported feature vector to 20867c478bd9Sstevel@tonic-gate * things that we think userland will care about. 20877c478bd9Sstevel@tonic-gate */ 2088ae115bc7Smrj #if defined(__amd64) 20897c478bd9Sstevel@tonic-gate if (*edx & CPUID_AMD_EDX_SYSC) 20907c478bd9Sstevel@tonic-gate hwcap_flags |= AV_386_AMD_SYSC; 2091ae115bc7Smrj #endif 20927c478bd9Sstevel@tonic-gate if (*edx & CPUID_AMD_EDX_MMXamd) 20937c478bd9Sstevel@tonic-gate hwcap_flags |= AV_386_AMD_MMX; 20947c478bd9Sstevel@tonic-gate if (*edx & CPUID_AMD_EDX_3DNow) 20957c478bd9Sstevel@tonic-gate hwcap_flags |= AV_386_AMD_3DNow; 20967c478bd9Sstevel@tonic-gate if (*edx & CPUID_AMD_EDX_3DNowx) 20977c478bd9Sstevel@tonic-gate hwcap_flags |= AV_386_AMD_3DNowx; 2098ae115bc7Smrj 2099ae115bc7Smrj switch (cpi->cpi_vendor) { 2100ae115bc7Smrj case X86_VENDOR_AMD: 2101ae115bc7Smrj if (*edx & CPUID_AMD_EDX_TSCP) 2102ae115bc7Smrj hwcap_flags |= AV_386_TSCP; 2103ae115bc7Smrj if (*ecx & CPUID_AMD_ECX_AHF64) 2104ae115bc7Smrj hwcap_flags |= AV_386_AHF; 2105f8801251Skk208521 if (*ecx & CPUID_AMD_ECX_SSE4A) 2106f8801251Skk208521 hwcap_flags |= AV_386_AMD_SSE4A; 2107f8801251Skk208521 if (*ecx & CPUID_AMD_ECX_LZCNT) 2108f8801251Skk208521 hwcap_flags |= AV_386_AMD_LZCNT; 2109ae115bc7Smrj break; 2110ae115bc7Smrj 2111ae115bc7Smrj case X86_VENDOR_Intel: 2112ae115bc7Smrj /* 2113ae115bc7Smrj * Aarrgh. 2114ae115bc7Smrj * Intel uses a different bit in the same word. 2115ae115bc7Smrj */ 2116ae115bc7Smrj if (*ecx & CPUID_INTC_ECX_AHF64) 2117ae115bc7Smrj hwcap_flags |= AV_386_AHF; 2118ae115bc7Smrj break; 2119ae115bc7Smrj 2120ae115bc7Smrj default: 2121ae115bc7Smrj break; 2122ae115bc7Smrj } 21237c478bd9Sstevel@tonic-gate break; 21247c478bd9Sstevel@tonic-gate 21257c478bd9Sstevel@tonic-gate case X86_VENDOR_TM: 21268949bcd6Sandrei cp.cp_eax = 0x80860001; 21278949bcd6Sandrei (void) __cpuid_insn(&cp); 21288949bcd6Sandrei cpi->cpi_support[TM_EDX_FEATURES] = cp.cp_edx; 21297c478bd9Sstevel@tonic-gate break; 21307c478bd9Sstevel@tonic-gate 21317c478bd9Sstevel@tonic-gate default: 21327c478bd9Sstevel@tonic-gate break; 21337c478bd9Sstevel@tonic-gate } 21347c478bd9Sstevel@tonic-gate 21357c478bd9Sstevel@tonic-gate pass4_done: 21367c478bd9Sstevel@tonic-gate cpi->cpi_pass = 4; 21377c478bd9Sstevel@tonic-gate return (hwcap_flags); 21387c478bd9Sstevel@tonic-gate } 21397c478bd9Sstevel@tonic-gate 21407c478bd9Sstevel@tonic-gate 21417c478bd9Sstevel@tonic-gate /* 21427c478bd9Sstevel@tonic-gate * Simulate the cpuid instruction using the data we previously 21437c478bd9Sstevel@tonic-gate * captured about this CPU. We try our best to return the truth 21447c478bd9Sstevel@tonic-gate * about the hardware, independently of kernel support. 21457c478bd9Sstevel@tonic-gate */ 21467c478bd9Sstevel@tonic-gate uint32_t 21478949bcd6Sandrei cpuid_insn(cpu_t *cpu, struct cpuid_regs *cp) 21487c478bd9Sstevel@tonic-gate { 21497c478bd9Sstevel@tonic-gate struct cpuid_info *cpi; 21508949bcd6Sandrei struct cpuid_regs *xcp; 21517c478bd9Sstevel@tonic-gate 21527c478bd9Sstevel@tonic-gate if (cpu == NULL) 21537c478bd9Sstevel@tonic-gate cpu = CPU; 21547c478bd9Sstevel@tonic-gate cpi = cpu->cpu_m.mcpu_cpi; 21557c478bd9Sstevel@tonic-gate 21567c478bd9Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 3)); 21577c478bd9Sstevel@tonic-gate 21587c478bd9Sstevel@tonic-gate /* 21597c478bd9Sstevel@tonic-gate * CPUID data is cached in two separate places: cpi_std for standard 21607c478bd9Sstevel@tonic-gate * CPUID functions, and cpi_extd for extended CPUID functions. 21617c478bd9Sstevel@tonic-gate */ 21628949bcd6Sandrei if (cp->cp_eax <= cpi->cpi_maxeax && cp->cp_eax < NMAX_CPI_STD) 21638949bcd6Sandrei xcp = &cpi->cpi_std[cp->cp_eax]; 21648949bcd6Sandrei else if (cp->cp_eax >= 0x80000000 && cp->cp_eax <= cpi->cpi_xmaxeax && 21658949bcd6Sandrei cp->cp_eax < 0x80000000 + NMAX_CPI_EXTD) 21668949bcd6Sandrei xcp = &cpi->cpi_extd[cp->cp_eax - 0x80000000]; 21677c478bd9Sstevel@tonic-gate else 21687c478bd9Sstevel@tonic-gate /* 21697c478bd9Sstevel@tonic-gate * The caller is asking for data from an input parameter which 21707c478bd9Sstevel@tonic-gate * the kernel has not cached. In this case we go fetch from 21717c478bd9Sstevel@tonic-gate * the hardware and return the data directly to the user. 21727c478bd9Sstevel@tonic-gate */ 21738949bcd6Sandrei return (__cpuid_insn(cp)); 21748949bcd6Sandrei 21758949bcd6Sandrei cp->cp_eax = xcp->cp_eax; 21768949bcd6Sandrei cp->cp_ebx = xcp->cp_ebx; 21778949bcd6Sandrei cp->cp_ecx = xcp->cp_ecx; 21788949bcd6Sandrei cp->cp_edx = xcp->cp_edx; 21797c478bd9Sstevel@tonic-gate return (cp->cp_eax); 21807c478bd9Sstevel@tonic-gate } 21817c478bd9Sstevel@tonic-gate 21827c478bd9Sstevel@tonic-gate int 21837c478bd9Sstevel@tonic-gate cpuid_checkpass(cpu_t *cpu, int pass) 21847c478bd9Sstevel@tonic-gate { 21857c478bd9Sstevel@tonic-gate return (cpu != NULL && cpu->cpu_m.mcpu_cpi != NULL && 21867c478bd9Sstevel@tonic-gate cpu->cpu_m.mcpu_cpi->cpi_pass >= pass); 21877c478bd9Sstevel@tonic-gate } 21887c478bd9Sstevel@tonic-gate 21897c478bd9Sstevel@tonic-gate int 21907c478bd9Sstevel@tonic-gate cpuid_getbrandstr(cpu_t *cpu, char *s, size_t n) 21917c478bd9Sstevel@tonic-gate { 21927c478bd9Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 3)); 21937c478bd9Sstevel@tonic-gate 21947c478bd9Sstevel@tonic-gate return (snprintf(s, n, "%s", cpu->cpu_m.mcpu_cpi->cpi_brandstr)); 21957c478bd9Sstevel@tonic-gate } 21967c478bd9Sstevel@tonic-gate 21977c478bd9Sstevel@tonic-gate int 21988949bcd6Sandrei cpuid_is_cmt(cpu_t *cpu) 21997c478bd9Sstevel@tonic-gate { 22007c478bd9Sstevel@tonic-gate if (cpu == NULL) 22017c478bd9Sstevel@tonic-gate cpu = CPU; 22027c478bd9Sstevel@tonic-gate 22037c478bd9Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 22047c478bd9Sstevel@tonic-gate 22057c478bd9Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_chipid >= 0); 22067c478bd9Sstevel@tonic-gate } 22077c478bd9Sstevel@tonic-gate 22087c478bd9Sstevel@tonic-gate /* 22097c478bd9Sstevel@tonic-gate * AMD and Intel both implement the 64-bit variant of the syscall 22107c478bd9Sstevel@tonic-gate * instruction (syscallq), so if there's -any- support for syscall, 22117c478bd9Sstevel@tonic-gate * cpuid currently says "yes, we support this". 22127c478bd9Sstevel@tonic-gate * 22137c478bd9Sstevel@tonic-gate * However, Intel decided to -not- implement the 32-bit variant of the 22147c478bd9Sstevel@tonic-gate * syscall instruction, so we provide a predicate to allow our caller 22157c478bd9Sstevel@tonic-gate * to test that subtlety here. 2216843e1988Sjohnlev * 2217843e1988Sjohnlev * XXPV Currently, 32-bit syscall instructions don't work via the hypervisor, 2218843e1988Sjohnlev * even in the case where the hardware would in fact support it. 22197c478bd9Sstevel@tonic-gate */ 22207c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 22217c478bd9Sstevel@tonic-gate int 22227c478bd9Sstevel@tonic-gate cpuid_syscall32_insn(cpu_t *cpu) 22237c478bd9Sstevel@tonic-gate { 22247c478bd9Sstevel@tonic-gate ASSERT(cpuid_checkpass((cpu == NULL ? CPU : cpu), 1)); 22257c478bd9Sstevel@tonic-gate 2226843e1988Sjohnlev #if !defined(__xpv) 2227ae115bc7Smrj if (cpu == NULL) 2228ae115bc7Smrj cpu = CPU; 2229ae115bc7Smrj 2230ae115bc7Smrj /*CSTYLED*/ 2231ae115bc7Smrj { 2232ae115bc7Smrj struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 2233ae115bc7Smrj 2234ae115bc7Smrj if (cpi->cpi_vendor == X86_VENDOR_AMD && 2235ae115bc7Smrj cpi->cpi_xmaxeax >= 0x80000001 && 2236ae115bc7Smrj (CPI_FEATURES_XTD_EDX(cpi) & CPUID_AMD_EDX_SYSC)) 2237ae115bc7Smrj return (1); 2238ae115bc7Smrj } 2239843e1988Sjohnlev #endif 22407c478bd9Sstevel@tonic-gate return (0); 22417c478bd9Sstevel@tonic-gate } 22427c478bd9Sstevel@tonic-gate 22437c478bd9Sstevel@tonic-gate int 22447c478bd9Sstevel@tonic-gate cpuid_getidstr(cpu_t *cpu, char *s, size_t n) 22457c478bd9Sstevel@tonic-gate { 22467c478bd9Sstevel@tonic-gate struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 22477c478bd9Sstevel@tonic-gate 22487c478bd9Sstevel@tonic-gate static const char fmt[] = 2249ecfa43a5Sdmick "x86 (%s %X family %d model %d step %d clock %d MHz)"; 22507c478bd9Sstevel@tonic-gate static const char fmt_ht[] = 2251ecfa43a5Sdmick "x86 (chipid 0x%x %s %X family %d model %d step %d clock %d MHz)"; 22527c478bd9Sstevel@tonic-gate 22537c478bd9Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 22547c478bd9Sstevel@tonic-gate 22558949bcd6Sandrei if (cpuid_is_cmt(cpu)) 22567c478bd9Sstevel@tonic-gate return (snprintf(s, n, fmt_ht, cpi->cpi_chipid, 2257ecfa43a5Sdmick cpi->cpi_vendorstr, cpi->cpi_std[1].cp_eax, 2258ecfa43a5Sdmick cpi->cpi_family, cpi->cpi_model, 22597c478bd9Sstevel@tonic-gate cpi->cpi_step, cpu->cpu_type_info.pi_clock)); 22607c478bd9Sstevel@tonic-gate return (snprintf(s, n, fmt, 2261ecfa43a5Sdmick cpi->cpi_vendorstr, cpi->cpi_std[1].cp_eax, 2262ecfa43a5Sdmick cpi->cpi_family, cpi->cpi_model, 22637c478bd9Sstevel@tonic-gate cpi->cpi_step, cpu->cpu_type_info.pi_clock)); 22647c478bd9Sstevel@tonic-gate } 22657c478bd9Sstevel@tonic-gate 22667c478bd9Sstevel@tonic-gate const char * 22677c478bd9Sstevel@tonic-gate cpuid_getvendorstr(cpu_t *cpu) 22687c478bd9Sstevel@tonic-gate { 22697c478bd9Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 22707c478bd9Sstevel@tonic-gate return ((const char *)cpu->cpu_m.mcpu_cpi->cpi_vendorstr); 22717c478bd9Sstevel@tonic-gate } 22727c478bd9Sstevel@tonic-gate 22737c478bd9Sstevel@tonic-gate uint_t 22747c478bd9Sstevel@tonic-gate cpuid_getvendor(cpu_t *cpu) 22757c478bd9Sstevel@tonic-gate { 22767c478bd9Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 22777c478bd9Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_vendor); 22787c478bd9Sstevel@tonic-gate } 22797c478bd9Sstevel@tonic-gate 22807c478bd9Sstevel@tonic-gate uint_t 22817c478bd9Sstevel@tonic-gate cpuid_getfamily(cpu_t *cpu) 22827c478bd9Sstevel@tonic-gate { 22837c478bd9Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 22847c478bd9Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_family); 22857c478bd9Sstevel@tonic-gate } 22867c478bd9Sstevel@tonic-gate 22877c478bd9Sstevel@tonic-gate uint_t 22887c478bd9Sstevel@tonic-gate cpuid_getmodel(cpu_t *cpu) 22897c478bd9Sstevel@tonic-gate { 22907c478bd9Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 22917c478bd9Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_model); 22927c478bd9Sstevel@tonic-gate } 22937c478bd9Sstevel@tonic-gate 22947c478bd9Sstevel@tonic-gate uint_t 22957c478bd9Sstevel@tonic-gate cpuid_get_ncpu_per_chip(cpu_t *cpu) 22967c478bd9Sstevel@tonic-gate { 22977c478bd9Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 22987c478bd9Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_ncpu_per_chip); 22997c478bd9Sstevel@tonic-gate } 23007c478bd9Sstevel@tonic-gate 23017c478bd9Sstevel@tonic-gate uint_t 23028949bcd6Sandrei cpuid_get_ncore_per_chip(cpu_t *cpu) 23038949bcd6Sandrei { 23048949bcd6Sandrei ASSERT(cpuid_checkpass(cpu, 1)); 23058949bcd6Sandrei return (cpu->cpu_m.mcpu_cpi->cpi_ncore_per_chip); 23068949bcd6Sandrei } 23078949bcd6Sandrei 23088949bcd6Sandrei uint_t 2309d129bde2Sesaxe cpuid_get_ncpu_sharing_last_cache(cpu_t *cpu) 2310d129bde2Sesaxe { 2311d129bde2Sesaxe ASSERT(cpuid_checkpass(cpu, 2)); 2312d129bde2Sesaxe return (cpu->cpu_m.mcpu_cpi->cpi_ncpu_shr_last_cache); 2313d129bde2Sesaxe } 2314d129bde2Sesaxe 2315d129bde2Sesaxe id_t 2316d129bde2Sesaxe cpuid_get_last_lvl_cacheid(cpu_t *cpu) 2317d129bde2Sesaxe { 2318d129bde2Sesaxe ASSERT(cpuid_checkpass(cpu, 2)); 2319d129bde2Sesaxe return (cpu->cpu_m.mcpu_cpi->cpi_last_lvl_cacheid); 2320d129bde2Sesaxe } 2321d129bde2Sesaxe 2322d129bde2Sesaxe uint_t 23237c478bd9Sstevel@tonic-gate cpuid_getstep(cpu_t *cpu) 23247c478bd9Sstevel@tonic-gate { 23257c478bd9Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 23267c478bd9Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_step); 23277c478bd9Sstevel@tonic-gate } 23287c478bd9Sstevel@tonic-gate 23292449e17fSsherrym uint_t 23302449e17fSsherrym cpuid_getsig(struct cpu *cpu) 23312449e17fSsherrym { 23322449e17fSsherrym ASSERT(cpuid_checkpass(cpu, 1)); 23332449e17fSsherrym return (cpu->cpu_m.mcpu_cpi->cpi_std[1].cp_eax); 23342449e17fSsherrym } 23352449e17fSsherrym 23368a40a695Sgavinm uint32_t 23378a40a695Sgavinm cpuid_getchiprev(struct cpu *cpu) 23388a40a695Sgavinm { 23398a40a695Sgavinm ASSERT(cpuid_checkpass(cpu, 1)); 23408a40a695Sgavinm return (cpu->cpu_m.mcpu_cpi->cpi_chiprev); 23418a40a695Sgavinm } 23428a40a695Sgavinm 23438a40a695Sgavinm const char * 23448a40a695Sgavinm cpuid_getchiprevstr(struct cpu *cpu) 23458a40a695Sgavinm { 23468a40a695Sgavinm ASSERT(cpuid_checkpass(cpu, 1)); 23478a40a695Sgavinm return (cpu->cpu_m.mcpu_cpi->cpi_chiprevstr); 23488a40a695Sgavinm } 23498a40a695Sgavinm 23508a40a695Sgavinm uint32_t 23518a40a695Sgavinm cpuid_getsockettype(struct cpu *cpu) 23528a40a695Sgavinm { 23538a40a695Sgavinm ASSERT(cpuid_checkpass(cpu, 1)); 23548a40a695Sgavinm return (cpu->cpu_m.mcpu_cpi->cpi_socket); 23558a40a695Sgavinm } 23568a40a695Sgavinm 2357fb2f18f8Sesaxe int 2358fb2f18f8Sesaxe cpuid_get_chipid(cpu_t *cpu) 23597c478bd9Sstevel@tonic-gate { 23607c478bd9Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 23617c478bd9Sstevel@tonic-gate 23628949bcd6Sandrei if (cpuid_is_cmt(cpu)) 23637c478bd9Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_chipid); 23647c478bd9Sstevel@tonic-gate return (cpu->cpu_id); 23657c478bd9Sstevel@tonic-gate } 23667c478bd9Sstevel@tonic-gate 23678949bcd6Sandrei id_t 2368fb2f18f8Sesaxe cpuid_get_coreid(cpu_t *cpu) 23698949bcd6Sandrei { 23708949bcd6Sandrei ASSERT(cpuid_checkpass(cpu, 1)); 23718949bcd6Sandrei return (cpu->cpu_m.mcpu_cpi->cpi_coreid); 23728949bcd6Sandrei } 23738949bcd6Sandrei 23747c478bd9Sstevel@tonic-gate int 2375fb2f18f8Sesaxe cpuid_get_clogid(cpu_t *cpu) 23767c478bd9Sstevel@tonic-gate { 23777c478bd9Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 23787c478bd9Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_clogid); 23797c478bd9Sstevel@tonic-gate } 23807c478bd9Sstevel@tonic-gate 23817c478bd9Sstevel@tonic-gate void 23827c478bd9Sstevel@tonic-gate cpuid_get_addrsize(cpu_t *cpu, uint_t *pabits, uint_t *vabits) 23837c478bd9Sstevel@tonic-gate { 23847c478bd9Sstevel@tonic-gate struct cpuid_info *cpi; 23857c478bd9Sstevel@tonic-gate 23867c478bd9Sstevel@tonic-gate if (cpu == NULL) 23877c478bd9Sstevel@tonic-gate cpu = CPU; 23887c478bd9Sstevel@tonic-gate cpi = cpu->cpu_m.mcpu_cpi; 23897c478bd9Sstevel@tonic-gate 23907c478bd9Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 23917c478bd9Sstevel@tonic-gate 23927c478bd9Sstevel@tonic-gate if (pabits) 23937c478bd9Sstevel@tonic-gate *pabits = cpi->cpi_pabits; 23947c478bd9Sstevel@tonic-gate if (vabits) 23957c478bd9Sstevel@tonic-gate *vabits = cpi->cpi_vabits; 23967c478bd9Sstevel@tonic-gate } 23977c478bd9Sstevel@tonic-gate 23987c478bd9Sstevel@tonic-gate /* 23997c478bd9Sstevel@tonic-gate * Returns the number of data TLB entries for a corresponding 24007c478bd9Sstevel@tonic-gate * pagesize. If it can't be computed, or isn't known, the 24017c478bd9Sstevel@tonic-gate * routine returns zero. If you ask about an architecturally 24027c478bd9Sstevel@tonic-gate * impossible pagesize, the routine will panic (so that the 24037c478bd9Sstevel@tonic-gate * hat implementor knows that things are inconsistent.) 24047c478bd9Sstevel@tonic-gate */ 24057c478bd9Sstevel@tonic-gate uint_t 24067c478bd9Sstevel@tonic-gate cpuid_get_dtlb_nent(cpu_t *cpu, size_t pagesize) 24077c478bd9Sstevel@tonic-gate { 24087c478bd9Sstevel@tonic-gate struct cpuid_info *cpi; 24097c478bd9Sstevel@tonic-gate uint_t dtlb_nent = 0; 24107c478bd9Sstevel@tonic-gate 24117c478bd9Sstevel@tonic-gate if (cpu == NULL) 24127c478bd9Sstevel@tonic-gate cpu = CPU; 24137c478bd9Sstevel@tonic-gate cpi = cpu->cpu_m.mcpu_cpi; 24147c478bd9Sstevel@tonic-gate 24157c478bd9Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 24167c478bd9Sstevel@tonic-gate 24177c478bd9Sstevel@tonic-gate /* 24187c478bd9Sstevel@tonic-gate * Check the L2 TLB info 24197c478bd9Sstevel@tonic-gate */ 24207c478bd9Sstevel@tonic-gate if (cpi->cpi_xmaxeax >= 0x80000006) { 24218949bcd6Sandrei struct cpuid_regs *cp = &cpi->cpi_extd[6]; 24227c478bd9Sstevel@tonic-gate 24237c478bd9Sstevel@tonic-gate switch (pagesize) { 24247c478bd9Sstevel@tonic-gate 24257c478bd9Sstevel@tonic-gate case 4 * 1024: 24267c478bd9Sstevel@tonic-gate /* 24277c478bd9Sstevel@tonic-gate * All zero in the top 16 bits of the register 24287c478bd9Sstevel@tonic-gate * indicates a unified TLB. Size is in low 16 bits. 24297c478bd9Sstevel@tonic-gate */ 24307c478bd9Sstevel@tonic-gate if ((cp->cp_ebx & 0xffff0000) == 0) 24317c478bd9Sstevel@tonic-gate dtlb_nent = cp->cp_ebx & 0x0000ffff; 24327c478bd9Sstevel@tonic-gate else 24337c478bd9Sstevel@tonic-gate dtlb_nent = BITX(cp->cp_ebx, 27, 16); 24347c478bd9Sstevel@tonic-gate break; 24357c478bd9Sstevel@tonic-gate 24367c478bd9Sstevel@tonic-gate case 2 * 1024 * 1024: 24377c478bd9Sstevel@tonic-gate if ((cp->cp_eax & 0xffff0000) == 0) 24387c478bd9Sstevel@tonic-gate dtlb_nent = cp->cp_eax & 0x0000ffff; 24397c478bd9Sstevel@tonic-gate else 24407c478bd9Sstevel@tonic-gate dtlb_nent = BITX(cp->cp_eax, 27, 16); 24417c478bd9Sstevel@tonic-gate break; 24427c478bd9Sstevel@tonic-gate 24437c478bd9Sstevel@tonic-gate default: 24447c478bd9Sstevel@tonic-gate panic("unknown L2 pagesize"); 24457c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 24467c478bd9Sstevel@tonic-gate } 24477c478bd9Sstevel@tonic-gate } 24487c478bd9Sstevel@tonic-gate 24497c478bd9Sstevel@tonic-gate if (dtlb_nent != 0) 24507c478bd9Sstevel@tonic-gate return (dtlb_nent); 24517c478bd9Sstevel@tonic-gate 24527c478bd9Sstevel@tonic-gate /* 24537c478bd9Sstevel@tonic-gate * No L2 TLB support for this size, try L1. 24547c478bd9Sstevel@tonic-gate */ 24557c478bd9Sstevel@tonic-gate if (cpi->cpi_xmaxeax >= 0x80000005) { 24568949bcd6Sandrei struct cpuid_regs *cp = &cpi->cpi_extd[5]; 24577c478bd9Sstevel@tonic-gate 24587c478bd9Sstevel@tonic-gate switch (pagesize) { 24597c478bd9Sstevel@tonic-gate case 4 * 1024: 24607c478bd9Sstevel@tonic-gate dtlb_nent = BITX(cp->cp_ebx, 23, 16); 24617c478bd9Sstevel@tonic-gate break; 24627c478bd9Sstevel@tonic-gate case 2 * 1024 * 1024: 24637c478bd9Sstevel@tonic-gate dtlb_nent = BITX(cp->cp_eax, 23, 16); 24647c478bd9Sstevel@tonic-gate break; 24657c478bd9Sstevel@tonic-gate default: 24667c478bd9Sstevel@tonic-gate panic("unknown L1 d-TLB pagesize"); 24677c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 24687c478bd9Sstevel@tonic-gate } 24697c478bd9Sstevel@tonic-gate } 24707c478bd9Sstevel@tonic-gate 24717c478bd9Sstevel@tonic-gate return (dtlb_nent); 24727c478bd9Sstevel@tonic-gate } 24737c478bd9Sstevel@tonic-gate 24747c478bd9Sstevel@tonic-gate /* 24757c478bd9Sstevel@tonic-gate * Return 0 if the erratum is not present or not applicable, positive 24767c478bd9Sstevel@tonic-gate * if it is, and negative if the status of the erratum is unknown. 24777c478bd9Sstevel@tonic-gate * 24787c478bd9Sstevel@tonic-gate * See "Revision Guide for AMD Athlon(tm) 64 and AMD Opteron(tm) 24792201b277Skucharsk * Processors" #25759, Rev 3.57, August 2005 24807c478bd9Sstevel@tonic-gate */ 24817c478bd9Sstevel@tonic-gate int 24827c478bd9Sstevel@tonic-gate cpuid_opteron_erratum(cpu_t *cpu, uint_t erratum) 24837c478bd9Sstevel@tonic-gate { 24847c478bd9Sstevel@tonic-gate struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 24858949bcd6Sandrei uint_t eax; 24867c478bd9Sstevel@tonic-gate 2487ea99987eSsethg /* 2488ea99987eSsethg * Bail out if this CPU isn't an AMD CPU, or if it's 2489ea99987eSsethg * a legacy (32-bit) AMD CPU. 2490ea99987eSsethg */ 2491ea99987eSsethg if (cpi->cpi_vendor != X86_VENDOR_AMD || 2492875b116eSkchow cpi->cpi_family == 4 || cpi->cpi_family == 5 || 2493875b116eSkchow cpi->cpi_family == 6) 24948a40a695Sgavinm 24957c478bd9Sstevel@tonic-gate return (0); 24967c478bd9Sstevel@tonic-gate 24977c478bd9Sstevel@tonic-gate eax = cpi->cpi_std[1].cp_eax; 24987c478bd9Sstevel@tonic-gate 24997c478bd9Sstevel@tonic-gate #define SH_B0(eax) (eax == 0xf40 || eax == 0xf50) 25007c478bd9Sstevel@tonic-gate #define SH_B3(eax) (eax == 0xf51) 2501ee88d2b9Skchow #define B(eax) (SH_B0(eax) || SH_B3(eax)) 25027c478bd9Sstevel@tonic-gate 25037c478bd9Sstevel@tonic-gate #define SH_C0(eax) (eax == 0xf48 || eax == 0xf58) 25047c478bd9Sstevel@tonic-gate 25057c478bd9Sstevel@tonic-gate #define SH_CG(eax) (eax == 0xf4a || eax == 0xf5a || eax == 0xf7a) 25067c478bd9Sstevel@tonic-gate #define DH_CG(eax) (eax == 0xfc0 || eax == 0xfe0 || eax == 0xff0) 25077c478bd9Sstevel@tonic-gate #define CH_CG(eax) (eax == 0xf82 || eax == 0xfb2) 2508ee88d2b9Skchow #define CG(eax) (SH_CG(eax) || DH_CG(eax) || CH_CG(eax)) 25097c478bd9Sstevel@tonic-gate 25107c478bd9Sstevel@tonic-gate #define SH_D0(eax) (eax == 0x10f40 || eax == 0x10f50 || eax == 0x10f70) 25117c478bd9Sstevel@tonic-gate #define DH_D0(eax) (eax == 0x10fc0 || eax == 0x10ff0) 25127c478bd9Sstevel@tonic-gate #define CH_D0(eax) (eax == 0x10f80 || eax == 0x10fb0) 2513ee88d2b9Skchow #define D0(eax) (SH_D0(eax) || DH_D0(eax) || CH_D0(eax)) 25147c478bd9Sstevel@tonic-gate 25157c478bd9Sstevel@tonic-gate #define SH_E0(eax) (eax == 0x20f50 || eax == 0x20f40 || eax == 0x20f70) 25167c478bd9Sstevel@tonic-gate #define JH_E1(eax) (eax == 0x20f10) /* JH8_E0 had 0x20f30 */ 25177c478bd9Sstevel@tonic-gate #define DH_E3(eax) (eax == 0x20fc0 || eax == 0x20ff0) 25187c478bd9Sstevel@tonic-gate #define SH_E4(eax) (eax == 0x20f51 || eax == 0x20f71) 25197c478bd9Sstevel@tonic-gate #define BH_E4(eax) (eax == 0x20fb1) 25207c478bd9Sstevel@tonic-gate #define SH_E5(eax) (eax == 0x20f42) 25217c478bd9Sstevel@tonic-gate #define DH_E6(eax) (eax == 0x20ff2 || eax == 0x20fc2) 25227c478bd9Sstevel@tonic-gate #define JH_E6(eax) (eax == 0x20f12 || eax == 0x20f32) 2523ee88d2b9Skchow #define EX(eax) (SH_E0(eax) || JH_E1(eax) || DH_E3(eax) || \ 2524ee88d2b9Skchow SH_E4(eax) || BH_E4(eax) || SH_E5(eax) || \ 2525ee88d2b9Skchow DH_E6(eax) || JH_E6(eax)) 25267c478bd9Sstevel@tonic-gate 25277c478bd9Sstevel@tonic-gate switch (erratum) { 25287c478bd9Sstevel@tonic-gate case 1: 2529875b116eSkchow return (cpi->cpi_family < 0x10); 25307c478bd9Sstevel@tonic-gate case 51: /* what does the asterisk mean? */ 25317c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax)); 25327c478bd9Sstevel@tonic-gate case 52: 25337c478bd9Sstevel@tonic-gate return (B(eax)); 25347c478bd9Sstevel@tonic-gate case 57: 2535875b116eSkchow return (cpi->cpi_family <= 0x10); 25367c478bd9Sstevel@tonic-gate case 58: 25377c478bd9Sstevel@tonic-gate return (B(eax)); 25387c478bd9Sstevel@tonic-gate case 60: 2539875b116eSkchow return (cpi->cpi_family <= 0x10); 25407c478bd9Sstevel@tonic-gate case 61: 25417c478bd9Sstevel@tonic-gate case 62: 25427c478bd9Sstevel@tonic-gate case 63: 25437c478bd9Sstevel@tonic-gate case 64: 25447c478bd9Sstevel@tonic-gate case 65: 25457c478bd9Sstevel@tonic-gate case 66: 25467c478bd9Sstevel@tonic-gate case 68: 25477c478bd9Sstevel@tonic-gate case 69: 25487c478bd9Sstevel@tonic-gate case 70: 25497c478bd9Sstevel@tonic-gate case 71: 25507c478bd9Sstevel@tonic-gate return (B(eax)); 25517c478bd9Sstevel@tonic-gate case 72: 25527c478bd9Sstevel@tonic-gate return (SH_B0(eax)); 25537c478bd9Sstevel@tonic-gate case 74: 25547c478bd9Sstevel@tonic-gate return (B(eax)); 25557c478bd9Sstevel@tonic-gate case 75: 2556875b116eSkchow return (cpi->cpi_family < 0x10); 25577c478bd9Sstevel@tonic-gate case 76: 25587c478bd9Sstevel@tonic-gate return (B(eax)); 25597c478bd9Sstevel@tonic-gate case 77: 2560875b116eSkchow return (cpi->cpi_family <= 0x10); 25617c478bd9Sstevel@tonic-gate case 78: 25627c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax)); 25637c478bd9Sstevel@tonic-gate case 79: 25647c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax) || EX(eax)); 25657c478bd9Sstevel@tonic-gate case 80: 25667c478bd9Sstevel@tonic-gate case 81: 25677c478bd9Sstevel@tonic-gate case 82: 25687c478bd9Sstevel@tonic-gate return (B(eax)); 25697c478bd9Sstevel@tonic-gate case 83: 25707c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax)); 25717c478bd9Sstevel@tonic-gate case 85: 2572875b116eSkchow return (cpi->cpi_family < 0x10); 25737c478bd9Sstevel@tonic-gate case 86: 25747c478bd9Sstevel@tonic-gate return (SH_C0(eax) || CG(eax)); 25757c478bd9Sstevel@tonic-gate case 88: 25767c478bd9Sstevel@tonic-gate #if !defined(__amd64) 25777c478bd9Sstevel@tonic-gate return (0); 25787c478bd9Sstevel@tonic-gate #else 25797c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax)); 25807c478bd9Sstevel@tonic-gate #endif 25817c478bd9Sstevel@tonic-gate case 89: 2582875b116eSkchow return (cpi->cpi_family < 0x10); 25837c478bd9Sstevel@tonic-gate case 90: 25847c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax)); 25857c478bd9Sstevel@tonic-gate case 91: 25867c478bd9Sstevel@tonic-gate case 92: 25877c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax)); 25887c478bd9Sstevel@tonic-gate case 93: 25897c478bd9Sstevel@tonic-gate return (SH_C0(eax)); 25907c478bd9Sstevel@tonic-gate case 94: 25917c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax)); 25927c478bd9Sstevel@tonic-gate case 95: 25937c478bd9Sstevel@tonic-gate #if !defined(__amd64) 25947c478bd9Sstevel@tonic-gate return (0); 25957c478bd9Sstevel@tonic-gate #else 25967c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax)); 25977c478bd9Sstevel@tonic-gate #endif 25987c478bd9Sstevel@tonic-gate case 96: 25997c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax)); 26007c478bd9Sstevel@tonic-gate case 97: 26017c478bd9Sstevel@tonic-gate case 98: 26027c478bd9Sstevel@tonic-gate return (SH_C0(eax) || CG(eax)); 26037c478bd9Sstevel@tonic-gate case 99: 26047c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax)); 26057c478bd9Sstevel@tonic-gate case 100: 26067c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax)); 26077c478bd9Sstevel@tonic-gate case 101: 26087c478bd9Sstevel@tonic-gate case 103: 26097c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax)); 26107c478bd9Sstevel@tonic-gate case 104: 26117c478bd9Sstevel@tonic-gate return (SH_C0(eax) || CG(eax) || D0(eax)); 26127c478bd9Sstevel@tonic-gate case 105: 26137c478bd9Sstevel@tonic-gate case 106: 26147c478bd9Sstevel@tonic-gate case 107: 26157c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax)); 26167c478bd9Sstevel@tonic-gate case 108: 26177c478bd9Sstevel@tonic-gate return (DH_CG(eax)); 26187c478bd9Sstevel@tonic-gate case 109: 26197c478bd9Sstevel@tonic-gate return (SH_C0(eax) || CG(eax) || D0(eax)); 26207c478bd9Sstevel@tonic-gate case 110: 26217c478bd9Sstevel@tonic-gate return (D0(eax) || EX(eax)); 26227c478bd9Sstevel@tonic-gate case 111: 26237c478bd9Sstevel@tonic-gate return (CG(eax)); 26247c478bd9Sstevel@tonic-gate case 112: 26257c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax) || EX(eax)); 26267c478bd9Sstevel@tonic-gate case 113: 26277c478bd9Sstevel@tonic-gate return (eax == 0x20fc0); 26287c478bd9Sstevel@tonic-gate case 114: 26297c478bd9Sstevel@tonic-gate return (SH_E0(eax) || JH_E1(eax) || DH_E3(eax)); 26307c478bd9Sstevel@tonic-gate case 115: 26317c478bd9Sstevel@tonic-gate return (SH_E0(eax) || JH_E1(eax)); 26327c478bd9Sstevel@tonic-gate case 116: 26337c478bd9Sstevel@tonic-gate return (SH_E0(eax) || JH_E1(eax) || DH_E3(eax)); 26347c478bd9Sstevel@tonic-gate case 117: 26357c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax)); 26367c478bd9Sstevel@tonic-gate case 118: 26377c478bd9Sstevel@tonic-gate return (SH_E0(eax) || JH_E1(eax) || SH_E4(eax) || BH_E4(eax) || 26387c478bd9Sstevel@tonic-gate JH_E6(eax)); 26397c478bd9Sstevel@tonic-gate case 121: 26407c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax) || EX(eax)); 26417c478bd9Sstevel@tonic-gate case 122: 2642875b116eSkchow return (cpi->cpi_family < 0x10); 26437c478bd9Sstevel@tonic-gate case 123: 26447c478bd9Sstevel@tonic-gate return (JH_E1(eax) || BH_E4(eax) || JH_E6(eax)); 26452201b277Skucharsk case 131: 2646875b116eSkchow return (cpi->cpi_family < 0x10); 2647ef50d8c0Sesaxe case 6336786: 2648ef50d8c0Sesaxe /* 2649ef50d8c0Sesaxe * Test for AdvPowerMgmtInfo.TscPStateInvariant 2650875b116eSkchow * if this is a K8 family or newer processor 2651ef50d8c0Sesaxe */ 2652ef50d8c0Sesaxe if (CPI_FAMILY(cpi) == 0xf) { 26538949bcd6Sandrei struct cpuid_regs regs; 26548949bcd6Sandrei regs.cp_eax = 0x80000007; 26558949bcd6Sandrei (void) __cpuid_insn(®s); 26568949bcd6Sandrei return (!(regs.cp_edx & 0x100)); 2657ef50d8c0Sesaxe } 2658ef50d8c0Sesaxe return (0); 2659ee88d2b9Skchow case 6323525: 2660ee88d2b9Skchow return (((((eax >> 12) & 0xff00) + (eax & 0xf00)) | 2661ee88d2b9Skchow (((eax >> 4) & 0xf) | ((eax >> 12) & 0xf0))) < 0xf40); 2662ee88d2b9Skchow 26637c478bd9Sstevel@tonic-gate default: 26647c478bd9Sstevel@tonic-gate return (-1); 26657c478bd9Sstevel@tonic-gate } 26667c478bd9Sstevel@tonic-gate } 26677c478bd9Sstevel@tonic-gate 26687c478bd9Sstevel@tonic-gate static const char assoc_str[] = "associativity"; 26697c478bd9Sstevel@tonic-gate static const char line_str[] = "line-size"; 26707c478bd9Sstevel@tonic-gate static const char size_str[] = "size"; 26717c478bd9Sstevel@tonic-gate 26727c478bd9Sstevel@tonic-gate static void 26737c478bd9Sstevel@tonic-gate add_cache_prop(dev_info_t *devi, const char *label, const char *type, 26747c478bd9Sstevel@tonic-gate uint32_t val) 26757c478bd9Sstevel@tonic-gate { 26767c478bd9Sstevel@tonic-gate char buf[128]; 26777c478bd9Sstevel@tonic-gate 26787c478bd9Sstevel@tonic-gate /* 26797c478bd9Sstevel@tonic-gate * ndi_prop_update_int() is used because it is desirable for 26807c478bd9Sstevel@tonic-gate * DDI_PROP_HW_DEF and DDI_PROP_DONTSLEEP to be set. 26817c478bd9Sstevel@tonic-gate */ 26827c478bd9Sstevel@tonic-gate if (snprintf(buf, sizeof (buf), "%s-%s", label, type) < sizeof (buf)) 26837c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, devi, buf, val); 26847c478bd9Sstevel@tonic-gate } 26857c478bd9Sstevel@tonic-gate 26867c478bd9Sstevel@tonic-gate /* 26877c478bd9Sstevel@tonic-gate * Intel-style cache/tlb description 26887c478bd9Sstevel@tonic-gate * 26897c478bd9Sstevel@tonic-gate * Standard cpuid level 2 gives a randomly ordered 26907c478bd9Sstevel@tonic-gate * selection of tags that index into a table that describes 26917c478bd9Sstevel@tonic-gate * cache and tlb properties. 26927c478bd9Sstevel@tonic-gate */ 26937c478bd9Sstevel@tonic-gate 26947c478bd9Sstevel@tonic-gate static const char l1_icache_str[] = "l1-icache"; 26957c478bd9Sstevel@tonic-gate static const char l1_dcache_str[] = "l1-dcache"; 26967c478bd9Sstevel@tonic-gate static const char l2_cache_str[] = "l2-cache"; 2697ae115bc7Smrj static const char l3_cache_str[] = "l3-cache"; 26987c478bd9Sstevel@tonic-gate static const char itlb4k_str[] = "itlb-4K"; 26997c478bd9Sstevel@tonic-gate static const char dtlb4k_str[] = "dtlb-4K"; 27007c478bd9Sstevel@tonic-gate static const char itlb4M_str[] = "itlb-4M"; 27017c478bd9Sstevel@tonic-gate static const char dtlb4M_str[] = "dtlb-4M"; 27027c478bd9Sstevel@tonic-gate static const char itlb424_str[] = "itlb-4K-2M-4M"; 27037c478bd9Sstevel@tonic-gate static const char dtlb44_str[] = "dtlb-4K-4M"; 27047c478bd9Sstevel@tonic-gate static const char sl1_dcache_str[] = "sectored-l1-dcache"; 27057c478bd9Sstevel@tonic-gate static const char sl2_cache_str[] = "sectored-l2-cache"; 27067c478bd9Sstevel@tonic-gate static const char itrace_str[] = "itrace-cache"; 27077c478bd9Sstevel@tonic-gate static const char sl3_cache_str[] = "sectored-l3-cache"; 27087c478bd9Sstevel@tonic-gate 27097c478bd9Sstevel@tonic-gate static const struct cachetab { 27107c478bd9Sstevel@tonic-gate uint8_t ct_code; 27117c478bd9Sstevel@tonic-gate uint8_t ct_assoc; 27127c478bd9Sstevel@tonic-gate uint16_t ct_line_size; 27137c478bd9Sstevel@tonic-gate size_t ct_size; 27147c478bd9Sstevel@tonic-gate const char *ct_label; 27157c478bd9Sstevel@tonic-gate } intel_ctab[] = { 27167c478bd9Sstevel@tonic-gate /* maintain descending order! */ 2717ae115bc7Smrj { 0xb4, 4, 0, 256, dtlb4k_str }, 27187c478bd9Sstevel@tonic-gate { 0xb3, 4, 0, 128, dtlb4k_str }, 27197c478bd9Sstevel@tonic-gate { 0xb0, 4, 0, 128, itlb4k_str }, 27207c478bd9Sstevel@tonic-gate { 0x87, 8, 64, 1024*1024, l2_cache_str}, 27217c478bd9Sstevel@tonic-gate { 0x86, 4, 64, 512*1024, l2_cache_str}, 27227c478bd9Sstevel@tonic-gate { 0x85, 8, 32, 2*1024*1024, l2_cache_str}, 27237c478bd9Sstevel@tonic-gate { 0x84, 8, 32, 1024*1024, l2_cache_str}, 27247c478bd9Sstevel@tonic-gate { 0x83, 8, 32, 512*1024, l2_cache_str}, 27257c478bd9Sstevel@tonic-gate { 0x82, 8, 32, 256*1024, l2_cache_str}, 27267c478bd9Sstevel@tonic-gate { 0x7f, 2, 64, 512*1024, l2_cache_str}, 27277c478bd9Sstevel@tonic-gate { 0x7d, 8, 64, 2*1024*1024, sl2_cache_str}, 27287c478bd9Sstevel@tonic-gate { 0x7c, 8, 64, 1024*1024, sl2_cache_str}, 27297c478bd9Sstevel@tonic-gate { 0x7b, 8, 64, 512*1024, sl2_cache_str}, 27307c478bd9Sstevel@tonic-gate { 0x7a, 8, 64, 256*1024, sl2_cache_str}, 27317c478bd9Sstevel@tonic-gate { 0x79, 8, 64, 128*1024, sl2_cache_str}, 27327c478bd9Sstevel@tonic-gate { 0x78, 8, 64, 1024*1024, l2_cache_str}, 2733ae115bc7Smrj { 0x73, 8, 0, 64*1024, itrace_str}, 27347c478bd9Sstevel@tonic-gate { 0x72, 8, 0, 32*1024, itrace_str}, 27357c478bd9Sstevel@tonic-gate { 0x71, 8, 0, 16*1024, itrace_str}, 27367c478bd9Sstevel@tonic-gate { 0x70, 8, 0, 12*1024, itrace_str}, 27377c478bd9Sstevel@tonic-gate { 0x68, 4, 64, 32*1024, sl1_dcache_str}, 27387c478bd9Sstevel@tonic-gate { 0x67, 4, 64, 16*1024, sl1_dcache_str}, 27397c478bd9Sstevel@tonic-gate { 0x66, 4, 64, 8*1024, sl1_dcache_str}, 27407c478bd9Sstevel@tonic-gate { 0x60, 8, 64, 16*1024, sl1_dcache_str}, 27417c478bd9Sstevel@tonic-gate { 0x5d, 0, 0, 256, dtlb44_str}, 27427c478bd9Sstevel@tonic-gate { 0x5c, 0, 0, 128, dtlb44_str}, 27437c478bd9Sstevel@tonic-gate { 0x5b, 0, 0, 64, dtlb44_str}, 27447c478bd9Sstevel@tonic-gate { 0x52, 0, 0, 256, itlb424_str}, 27457c478bd9Sstevel@tonic-gate { 0x51, 0, 0, 128, itlb424_str}, 27467c478bd9Sstevel@tonic-gate { 0x50, 0, 0, 64, itlb424_str}, 2747ae115bc7Smrj { 0x4d, 16, 64, 16*1024*1024, l3_cache_str}, 2748ae115bc7Smrj { 0x4c, 12, 64, 12*1024*1024, l3_cache_str}, 2749ae115bc7Smrj { 0x4b, 16, 64, 8*1024*1024, l3_cache_str}, 2750ae115bc7Smrj { 0x4a, 12, 64, 6*1024*1024, l3_cache_str}, 2751ae115bc7Smrj { 0x49, 16, 64, 4*1024*1024, l3_cache_str}, 2752ae115bc7Smrj { 0x47, 8, 64, 8*1024*1024, l3_cache_str}, 2753ae115bc7Smrj { 0x46, 4, 64, 4*1024*1024, l3_cache_str}, 27547c478bd9Sstevel@tonic-gate { 0x45, 4, 32, 2*1024*1024, l2_cache_str}, 27557c478bd9Sstevel@tonic-gate { 0x44, 4, 32, 1024*1024, l2_cache_str}, 27567c478bd9Sstevel@tonic-gate { 0x43, 4, 32, 512*1024, l2_cache_str}, 27577c478bd9Sstevel@tonic-gate { 0x42, 4, 32, 256*1024, l2_cache_str}, 27587c478bd9Sstevel@tonic-gate { 0x41, 4, 32, 128*1024, l2_cache_str}, 2759ae115bc7Smrj { 0x3e, 4, 64, 512*1024, sl2_cache_str}, 2760ae115bc7Smrj { 0x3d, 6, 64, 384*1024, sl2_cache_str}, 27617c478bd9Sstevel@tonic-gate { 0x3c, 4, 64, 256*1024, sl2_cache_str}, 27627c478bd9Sstevel@tonic-gate { 0x3b, 2, 64, 128*1024, sl2_cache_str}, 2763ae115bc7Smrj { 0x3a, 6, 64, 192*1024, sl2_cache_str}, 27647c478bd9Sstevel@tonic-gate { 0x39, 4, 64, 128*1024, sl2_cache_str}, 27657c478bd9Sstevel@tonic-gate { 0x30, 8, 64, 32*1024, l1_icache_str}, 27667c478bd9Sstevel@tonic-gate { 0x2c, 8, 64, 32*1024, l1_dcache_str}, 27677c478bd9Sstevel@tonic-gate { 0x29, 8, 64, 4096*1024, sl3_cache_str}, 27687c478bd9Sstevel@tonic-gate { 0x25, 8, 64, 2048*1024, sl3_cache_str}, 27697c478bd9Sstevel@tonic-gate { 0x23, 8, 64, 1024*1024, sl3_cache_str}, 27707c478bd9Sstevel@tonic-gate { 0x22, 4, 64, 512*1024, sl3_cache_str}, 27717c478bd9Sstevel@tonic-gate { 0x0c, 4, 32, 16*1024, l1_dcache_str}, 2772ae115bc7Smrj { 0x0b, 4, 0, 4, itlb4M_str}, 27737c478bd9Sstevel@tonic-gate { 0x0a, 2, 32, 8*1024, l1_dcache_str}, 27747c478bd9Sstevel@tonic-gate { 0x08, 4, 32, 16*1024, l1_icache_str}, 27757c478bd9Sstevel@tonic-gate { 0x06, 4, 32, 8*1024, l1_icache_str}, 27767c478bd9Sstevel@tonic-gate { 0x04, 4, 0, 8, dtlb4M_str}, 27777c478bd9Sstevel@tonic-gate { 0x03, 4, 0, 64, dtlb4k_str}, 27787c478bd9Sstevel@tonic-gate { 0x02, 4, 0, 2, itlb4M_str}, 27797c478bd9Sstevel@tonic-gate { 0x01, 4, 0, 32, itlb4k_str}, 27807c478bd9Sstevel@tonic-gate { 0 } 27817c478bd9Sstevel@tonic-gate }; 27827c478bd9Sstevel@tonic-gate 27837c478bd9Sstevel@tonic-gate static const struct cachetab cyrix_ctab[] = { 27847c478bd9Sstevel@tonic-gate { 0x70, 4, 0, 32, "tlb-4K" }, 27857c478bd9Sstevel@tonic-gate { 0x80, 4, 16, 16*1024, "l1-cache" }, 27867c478bd9Sstevel@tonic-gate { 0 } 27877c478bd9Sstevel@tonic-gate }; 27887c478bd9Sstevel@tonic-gate 27897c478bd9Sstevel@tonic-gate /* 27907c478bd9Sstevel@tonic-gate * Search a cache table for a matching entry 27917c478bd9Sstevel@tonic-gate */ 27927c478bd9Sstevel@tonic-gate static const struct cachetab * 27937c478bd9Sstevel@tonic-gate find_cacheent(const struct cachetab *ct, uint_t code) 27947c478bd9Sstevel@tonic-gate { 27957c478bd9Sstevel@tonic-gate if (code != 0) { 27967c478bd9Sstevel@tonic-gate for (; ct->ct_code != 0; ct++) 27977c478bd9Sstevel@tonic-gate if (ct->ct_code <= code) 27987c478bd9Sstevel@tonic-gate break; 27997c478bd9Sstevel@tonic-gate if (ct->ct_code == code) 28007c478bd9Sstevel@tonic-gate return (ct); 28017c478bd9Sstevel@tonic-gate } 28027c478bd9Sstevel@tonic-gate return (NULL); 28037c478bd9Sstevel@tonic-gate } 28047c478bd9Sstevel@tonic-gate 28057c478bd9Sstevel@tonic-gate /* 28067c478bd9Sstevel@tonic-gate * Walk the cacheinfo descriptor, applying 'func' to every valid element 28077c478bd9Sstevel@tonic-gate * The walk is terminated if the walker returns non-zero. 28087c478bd9Sstevel@tonic-gate */ 28097c478bd9Sstevel@tonic-gate static void 28107c478bd9Sstevel@tonic-gate intel_walk_cacheinfo(struct cpuid_info *cpi, 28117c478bd9Sstevel@tonic-gate void *arg, int (*func)(void *, const struct cachetab *)) 28127c478bd9Sstevel@tonic-gate { 28137c478bd9Sstevel@tonic-gate const struct cachetab *ct; 28147c478bd9Sstevel@tonic-gate uint8_t *dp; 28157c478bd9Sstevel@tonic-gate int i; 28167c478bd9Sstevel@tonic-gate 28177c478bd9Sstevel@tonic-gate if ((dp = cpi->cpi_cacheinfo) == NULL) 28187c478bd9Sstevel@tonic-gate return; 2819f1d742a9Sksadhukh for (i = 0; i < cpi->cpi_ncache; i++, dp++) { 2820f1d742a9Sksadhukh /* 2821f1d742a9Sksadhukh * For overloaded descriptor 0x49 we use cpuid function 4 2822f1d742a9Sksadhukh * if supported by the current processor, to update 2823f1d742a9Sksadhukh * cache information. 2824f1d742a9Sksadhukh */ 2825f1d742a9Sksadhukh if (*dp == 0x49 && cpi->cpi_maxeax >= 0x4) { 2826f1d742a9Sksadhukh intel_cpuid_4_cache_info(arg, cpi); 2827f1d742a9Sksadhukh continue; 2828f1d742a9Sksadhukh } 2829f1d742a9Sksadhukh 28307c478bd9Sstevel@tonic-gate if ((ct = find_cacheent(intel_ctab, *dp)) != NULL) { 28317c478bd9Sstevel@tonic-gate if (func(arg, ct) != 0) 28327c478bd9Sstevel@tonic-gate break; 28337c478bd9Sstevel@tonic-gate } 28347c478bd9Sstevel@tonic-gate } 2835f1d742a9Sksadhukh } 28367c478bd9Sstevel@tonic-gate 28377c478bd9Sstevel@tonic-gate /* 28387c478bd9Sstevel@tonic-gate * (Like the Intel one, except for Cyrix CPUs) 28397c478bd9Sstevel@tonic-gate */ 28407c478bd9Sstevel@tonic-gate static void 28417c478bd9Sstevel@tonic-gate cyrix_walk_cacheinfo(struct cpuid_info *cpi, 28427c478bd9Sstevel@tonic-gate void *arg, int (*func)(void *, const struct cachetab *)) 28437c478bd9Sstevel@tonic-gate { 28447c478bd9Sstevel@tonic-gate const struct cachetab *ct; 28457c478bd9Sstevel@tonic-gate uint8_t *dp; 28467c478bd9Sstevel@tonic-gate int i; 28477c478bd9Sstevel@tonic-gate 28487c478bd9Sstevel@tonic-gate if ((dp = cpi->cpi_cacheinfo) == NULL) 28497c478bd9Sstevel@tonic-gate return; 28507c478bd9Sstevel@tonic-gate for (i = 0; i < cpi->cpi_ncache; i++, dp++) { 28517c478bd9Sstevel@tonic-gate /* 28527c478bd9Sstevel@tonic-gate * Search Cyrix-specific descriptor table first .. 28537c478bd9Sstevel@tonic-gate */ 28547c478bd9Sstevel@tonic-gate if ((ct = find_cacheent(cyrix_ctab, *dp)) != NULL) { 28557c478bd9Sstevel@tonic-gate if (func(arg, ct) != 0) 28567c478bd9Sstevel@tonic-gate break; 28577c478bd9Sstevel@tonic-gate continue; 28587c478bd9Sstevel@tonic-gate } 28597c478bd9Sstevel@tonic-gate /* 28607c478bd9Sstevel@tonic-gate * .. else fall back to the Intel one 28617c478bd9Sstevel@tonic-gate */ 28627c478bd9Sstevel@tonic-gate if ((ct = find_cacheent(intel_ctab, *dp)) != NULL) { 28637c478bd9Sstevel@tonic-gate if (func(arg, ct) != 0) 28647c478bd9Sstevel@tonic-gate break; 28657c478bd9Sstevel@tonic-gate continue; 28667c478bd9Sstevel@tonic-gate } 28677c478bd9Sstevel@tonic-gate } 28687c478bd9Sstevel@tonic-gate } 28697c478bd9Sstevel@tonic-gate 28707c478bd9Sstevel@tonic-gate /* 28717c478bd9Sstevel@tonic-gate * A cacheinfo walker that adds associativity, line-size, and size properties 28727c478bd9Sstevel@tonic-gate * to the devinfo node it is passed as an argument. 28737c478bd9Sstevel@tonic-gate */ 28747c478bd9Sstevel@tonic-gate static int 28757c478bd9Sstevel@tonic-gate add_cacheent_props(void *arg, const struct cachetab *ct) 28767c478bd9Sstevel@tonic-gate { 28777c478bd9Sstevel@tonic-gate dev_info_t *devi = arg; 28787c478bd9Sstevel@tonic-gate 28797c478bd9Sstevel@tonic-gate add_cache_prop(devi, ct->ct_label, assoc_str, ct->ct_assoc); 28807c478bd9Sstevel@tonic-gate if (ct->ct_line_size != 0) 28817c478bd9Sstevel@tonic-gate add_cache_prop(devi, ct->ct_label, line_str, 28827c478bd9Sstevel@tonic-gate ct->ct_line_size); 28837c478bd9Sstevel@tonic-gate add_cache_prop(devi, ct->ct_label, size_str, ct->ct_size); 28847c478bd9Sstevel@tonic-gate return (0); 28857c478bd9Sstevel@tonic-gate } 28867c478bd9Sstevel@tonic-gate 2887f1d742a9Sksadhukh /* 2888f1d742a9Sksadhukh * Add L2 or L3 cache-information using cpuid function 4. This 2889f1d742a9Sksadhukh * function is called from intel_walk_cacheinfo() when descriptor 2890f1d742a9Sksadhukh * 0x49 is encountered. 2891f1d742a9Sksadhukh */ 2892f1d742a9Sksadhukh static void 2893f1d742a9Sksadhukh intel_cpuid_4_cache_info(void *arg, struct cpuid_info *cpi) 2894f1d742a9Sksadhukh { 2895f1d742a9Sksadhukh uint32_t level, i; 2896f1d742a9Sksadhukh 2897f1d742a9Sksadhukh struct cachetab ct; 2898f1d742a9Sksadhukh 2899f1d742a9Sksadhukh for (i = 0; i < cpi->cpi_std_4_size; i++) { 2900f1d742a9Sksadhukh level = CPI_CACHE_LVL(cpi->cpi_std_4[i]); 2901f1d742a9Sksadhukh 2902f1d742a9Sksadhukh if (level == 2 || level == 3) { 2903f1d742a9Sksadhukh ct.ct_assoc = CPI_CACHE_WAYS(cpi->cpi_std_4[i]) + 1; 2904f1d742a9Sksadhukh ct.ct_line_size = 2905f1d742a9Sksadhukh CPI_CACHE_COH_LN_SZ(cpi->cpi_std_4[i]) + 1; 2906f1d742a9Sksadhukh ct.ct_size = ct.ct_assoc * 2907f1d742a9Sksadhukh (CPI_CACHE_PARTS(cpi->cpi_std_4[i]) + 1) * 2908f1d742a9Sksadhukh ct.ct_line_size * 2909f1d742a9Sksadhukh (cpi->cpi_std_4[i]->cp_ecx + 1); 2910f1d742a9Sksadhukh 2911f1d742a9Sksadhukh if (level == 2) { 2912f1d742a9Sksadhukh ct.ct_label = l2_cache_str; 2913f1d742a9Sksadhukh } else if (level == 3) { 2914f1d742a9Sksadhukh ct.ct_label = l3_cache_str; 2915f1d742a9Sksadhukh } 2916f1d742a9Sksadhukh 2917f1d742a9Sksadhukh (void) add_cacheent_props(arg, 2918f1d742a9Sksadhukh (const struct cachetab *) (&ct)); 2919f1d742a9Sksadhukh } 2920f1d742a9Sksadhukh } 2921f1d742a9Sksadhukh } 2922f1d742a9Sksadhukh 29237c478bd9Sstevel@tonic-gate static const char fully_assoc[] = "fully-associative?"; 29247c478bd9Sstevel@tonic-gate 29257c478bd9Sstevel@tonic-gate /* 29267c478bd9Sstevel@tonic-gate * AMD style cache/tlb description 29277c478bd9Sstevel@tonic-gate * 29287c478bd9Sstevel@tonic-gate * Extended functions 5 and 6 directly describe properties of 29297c478bd9Sstevel@tonic-gate * tlbs and various cache levels. 29307c478bd9Sstevel@tonic-gate */ 29317c478bd9Sstevel@tonic-gate static void 29327c478bd9Sstevel@tonic-gate add_amd_assoc(dev_info_t *devi, const char *label, uint_t assoc) 29337c478bd9Sstevel@tonic-gate { 29347c478bd9Sstevel@tonic-gate switch (assoc) { 29357c478bd9Sstevel@tonic-gate case 0: /* reserved; ignore */ 29367c478bd9Sstevel@tonic-gate break; 29377c478bd9Sstevel@tonic-gate default: 29387c478bd9Sstevel@tonic-gate add_cache_prop(devi, label, assoc_str, assoc); 29397c478bd9Sstevel@tonic-gate break; 29407c478bd9Sstevel@tonic-gate case 0xff: 29417c478bd9Sstevel@tonic-gate add_cache_prop(devi, label, fully_assoc, 1); 29427c478bd9Sstevel@tonic-gate break; 29437c478bd9Sstevel@tonic-gate } 29447c478bd9Sstevel@tonic-gate } 29457c478bd9Sstevel@tonic-gate 29467c478bd9Sstevel@tonic-gate static void 29477c478bd9Sstevel@tonic-gate add_amd_tlb(dev_info_t *devi, const char *label, uint_t assoc, uint_t size) 29487c478bd9Sstevel@tonic-gate { 29497c478bd9Sstevel@tonic-gate if (size == 0) 29507c478bd9Sstevel@tonic-gate return; 29517c478bd9Sstevel@tonic-gate add_cache_prop(devi, label, size_str, size); 29527c478bd9Sstevel@tonic-gate add_amd_assoc(devi, label, assoc); 29537c478bd9Sstevel@tonic-gate } 29547c478bd9Sstevel@tonic-gate 29557c478bd9Sstevel@tonic-gate static void 29567c478bd9Sstevel@tonic-gate add_amd_cache(dev_info_t *devi, const char *label, 29577c478bd9Sstevel@tonic-gate uint_t size, uint_t assoc, uint_t lines_per_tag, uint_t line_size) 29587c478bd9Sstevel@tonic-gate { 29597c478bd9Sstevel@tonic-gate if (size == 0 || line_size == 0) 29607c478bd9Sstevel@tonic-gate return; 29617c478bd9Sstevel@tonic-gate add_amd_assoc(devi, label, assoc); 29627c478bd9Sstevel@tonic-gate /* 29637c478bd9Sstevel@tonic-gate * Most AMD parts have a sectored cache. Multiple cache lines are 29647c478bd9Sstevel@tonic-gate * associated with each tag. A sector consists of all cache lines 29657c478bd9Sstevel@tonic-gate * associated with a tag. For example, the AMD K6-III has a sector 29667c478bd9Sstevel@tonic-gate * size of 2 cache lines per tag. 29677c478bd9Sstevel@tonic-gate */ 29687c478bd9Sstevel@tonic-gate if (lines_per_tag != 0) 29697c478bd9Sstevel@tonic-gate add_cache_prop(devi, label, "lines-per-tag", lines_per_tag); 29707c478bd9Sstevel@tonic-gate add_cache_prop(devi, label, line_str, line_size); 29717c478bd9Sstevel@tonic-gate add_cache_prop(devi, label, size_str, size * 1024); 29727c478bd9Sstevel@tonic-gate } 29737c478bd9Sstevel@tonic-gate 29747c478bd9Sstevel@tonic-gate static void 29757c478bd9Sstevel@tonic-gate add_amd_l2_assoc(dev_info_t *devi, const char *label, uint_t assoc) 29767c478bd9Sstevel@tonic-gate { 29777c478bd9Sstevel@tonic-gate switch (assoc) { 29787c478bd9Sstevel@tonic-gate case 0: /* off */ 29797c478bd9Sstevel@tonic-gate break; 29807c478bd9Sstevel@tonic-gate case 1: 29817c478bd9Sstevel@tonic-gate case 2: 29827c478bd9Sstevel@tonic-gate case 4: 29837c478bd9Sstevel@tonic-gate add_cache_prop(devi, label, assoc_str, assoc); 29847c478bd9Sstevel@tonic-gate break; 29857c478bd9Sstevel@tonic-gate case 6: 29867c478bd9Sstevel@tonic-gate add_cache_prop(devi, label, assoc_str, 8); 29877c478bd9Sstevel@tonic-gate break; 29887c478bd9Sstevel@tonic-gate case 8: 29897c478bd9Sstevel@tonic-gate add_cache_prop(devi, label, assoc_str, 16); 29907c478bd9Sstevel@tonic-gate break; 29917c478bd9Sstevel@tonic-gate case 0xf: 29927c478bd9Sstevel@tonic-gate add_cache_prop(devi, label, fully_assoc, 1); 29937c478bd9Sstevel@tonic-gate break; 29947c478bd9Sstevel@tonic-gate default: /* reserved; ignore */ 29957c478bd9Sstevel@tonic-gate break; 29967c478bd9Sstevel@tonic-gate } 29977c478bd9Sstevel@tonic-gate } 29987c478bd9Sstevel@tonic-gate 29997c478bd9Sstevel@tonic-gate static void 30007c478bd9Sstevel@tonic-gate add_amd_l2_tlb(dev_info_t *devi, const char *label, uint_t assoc, uint_t size) 30017c478bd9Sstevel@tonic-gate { 30027c478bd9Sstevel@tonic-gate if (size == 0 || assoc == 0) 30037c478bd9Sstevel@tonic-gate return; 30047c478bd9Sstevel@tonic-gate add_amd_l2_assoc(devi, label, assoc); 30057c478bd9Sstevel@tonic-gate add_cache_prop(devi, label, size_str, size); 30067c478bd9Sstevel@tonic-gate } 30077c478bd9Sstevel@tonic-gate 30087c478bd9Sstevel@tonic-gate static void 30097c478bd9Sstevel@tonic-gate add_amd_l2_cache(dev_info_t *devi, const char *label, 30107c478bd9Sstevel@tonic-gate uint_t size, uint_t assoc, uint_t lines_per_tag, uint_t line_size) 30117c478bd9Sstevel@tonic-gate { 30127c478bd9Sstevel@tonic-gate if (size == 0 || assoc == 0 || line_size == 0) 30137c478bd9Sstevel@tonic-gate return; 30147c478bd9Sstevel@tonic-gate add_amd_l2_assoc(devi, label, assoc); 30157c478bd9Sstevel@tonic-gate if (lines_per_tag != 0) 30167c478bd9Sstevel@tonic-gate add_cache_prop(devi, label, "lines-per-tag", lines_per_tag); 30177c478bd9Sstevel@tonic-gate add_cache_prop(devi, label, line_str, line_size); 30187c478bd9Sstevel@tonic-gate add_cache_prop(devi, label, size_str, size * 1024); 30197c478bd9Sstevel@tonic-gate } 30207c478bd9Sstevel@tonic-gate 30217c478bd9Sstevel@tonic-gate static void 30227c478bd9Sstevel@tonic-gate amd_cache_info(struct cpuid_info *cpi, dev_info_t *devi) 30237c478bd9Sstevel@tonic-gate { 30248949bcd6Sandrei struct cpuid_regs *cp; 30257c478bd9Sstevel@tonic-gate 30267c478bd9Sstevel@tonic-gate if (cpi->cpi_xmaxeax < 0x80000005) 30277c478bd9Sstevel@tonic-gate return; 30287c478bd9Sstevel@tonic-gate cp = &cpi->cpi_extd[5]; 30297c478bd9Sstevel@tonic-gate 30307c478bd9Sstevel@tonic-gate /* 30317c478bd9Sstevel@tonic-gate * 4M/2M L1 TLB configuration 30327c478bd9Sstevel@tonic-gate * 30337c478bd9Sstevel@tonic-gate * We report the size for 2M pages because AMD uses two 30347c478bd9Sstevel@tonic-gate * TLB entries for one 4M page. 30357c478bd9Sstevel@tonic-gate */ 30367c478bd9Sstevel@tonic-gate add_amd_tlb(devi, "dtlb-2M", 30377c478bd9Sstevel@tonic-gate BITX(cp->cp_eax, 31, 24), BITX(cp->cp_eax, 23, 16)); 30387c478bd9Sstevel@tonic-gate add_amd_tlb(devi, "itlb-2M", 30397c478bd9Sstevel@tonic-gate BITX(cp->cp_eax, 15, 8), BITX(cp->cp_eax, 7, 0)); 30407c478bd9Sstevel@tonic-gate 30417c478bd9Sstevel@tonic-gate /* 30427c478bd9Sstevel@tonic-gate * 4K L1 TLB configuration 30437c478bd9Sstevel@tonic-gate */ 30447c478bd9Sstevel@tonic-gate 30457c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 30467c478bd9Sstevel@tonic-gate uint_t nentries; 30477c478bd9Sstevel@tonic-gate case X86_VENDOR_TM: 30487c478bd9Sstevel@tonic-gate if (cpi->cpi_family >= 5) { 30497c478bd9Sstevel@tonic-gate /* 30507c478bd9Sstevel@tonic-gate * Crusoe processors have 256 TLB entries, but 30517c478bd9Sstevel@tonic-gate * cpuid data format constrains them to only 30527c478bd9Sstevel@tonic-gate * reporting 255 of them. 30537c478bd9Sstevel@tonic-gate */ 30547c478bd9Sstevel@tonic-gate if ((nentries = BITX(cp->cp_ebx, 23, 16)) == 255) 30557c478bd9Sstevel@tonic-gate nentries = 256; 30567c478bd9Sstevel@tonic-gate /* 30577c478bd9Sstevel@tonic-gate * Crusoe processors also have a unified TLB 30587c478bd9Sstevel@tonic-gate */ 30597c478bd9Sstevel@tonic-gate add_amd_tlb(devi, "tlb-4K", BITX(cp->cp_ebx, 31, 24), 30607c478bd9Sstevel@tonic-gate nentries); 30617c478bd9Sstevel@tonic-gate break; 30627c478bd9Sstevel@tonic-gate } 30637c478bd9Sstevel@tonic-gate /*FALLTHROUGH*/ 30647c478bd9Sstevel@tonic-gate default: 30657c478bd9Sstevel@tonic-gate add_amd_tlb(devi, itlb4k_str, 30667c478bd9Sstevel@tonic-gate BITX(cp->cp_ebx, 31, 24), BITX(cp->cp_ebx, 23, 16)); 30677c478bd9Sstevel@tonic-gate add_amd_tlb(devi, dtlb4k_str, 30687c478bd9Sstevel@tonic-gate BITX(cp->cp_ebx, 15, 8), BITX(cp->cp_ebx, 7, 0)); 30697c478bd9Sstevel@tonic-gate break; 30707c478bd9Sstevel@tonic-gate } 30717c478bd9Sstevel@tonic-gate 30727c478bd9Sstevel@tonic-gate /* 30737c478bd9Sstevel@tonic-gate * data L1 cache configuration 30747c478bd9Sstevel@tonic-gate */ 30757c478bd9Sstevel@tonic-gate 30767c478bd9Sstevel@tonic-gate add_amd_cache(devi, l1_dcache_str, 30777c478bd9Sstevel@tonic-gate BITX(cp->cp_ecx, 31, 24), BITX(cp->cp_ecx, 23, 16), 30787c478bd9Sstevel@tonic-gate BITX(cp->cp_ecx, 15, 8), BITX(cp->cp_ecx, 7, 0)); 30797c478bd9Sstevel@tonic-gate 30807c478bd9Sstevel@tonic-gate /* 30817c478bd9Sstevel@tonic-gate * code L1 cache configuration 30827c478bd9Sstevel@tonic-gate */ 30837c478bd9Sstevel@tonic-gate 30847c478bd9Sstevel@tonic-gate add_amd_cache(devi, l1_icache_str, 30857c478bd9Sstevel@tonic-gate BITX(cp->cp_edx, 31, 24), BITX(cp->cp_edx, 23, 16), 30867c478bd9Sstevel@tonic-gate BITX(cp->cp_edx, 15, 8), BITX(cp->cp_edx, 7, 0)); 30877c478bd9Sstevel@tonic-gate 30887c478bd9Sstevel@tonic-gate if (cpi->cpi_xmaxeax < 0x80000006) 30897c478bd9Sstevel@tonic-gate return; 30907c478bd9Sstevel@tonic-gate cp = &cpi->cpi_extd[6]; 30917c478bd9Sstevel@tonic-gate 30927c478bd9Sstevel@tonic-gate /* Check for a unified L2 TLB for large pages */ 30937c478bd9Sstevel@tonic-gate 30947c478bd9Sstevel@tonic-gate if (BITX(cp->cp_eax, 31, 16) == 0) 30957c478bd9Sstevel@tonic-gate add_amd_l2_tlb(devi, "l2-tlb-2M", 30967c478bd9Sstevel@tonic-gate BITX(cp->cp_eax, 15, 12), BITX(cp->cp_eax, 11, 0)); 30977c478bd9Sstevel@tonic-gate else { 30987c478bd9Sstevel@tonic-gate add_amd_l2_tlb(devi, "l2-dtlb-2M", 30997c478bd9Sstevel@tonic-gate BITX(cp->cp_eax, 31, 28), BITX(cp->cp_eax, 27, 16)); 31007c478bd9Sstevel@tonic-gate add_amd_l2_tlb(devi, "l2-itlb-2M", 31017c478bd9Sstevel@tonic-gate BITX(cp->cp_eax, 15, 12), BITX(cp->cp_eax, 11, 0)); 31027c478bd9Sstevel@tonic-gate } 31037c478bd9Sstevel@tonic-gate 31047c478bd9Sstevel@tonic-gate /* Check for a unified L2 TLB for 4K pages */ 31057c478bd9Sstevel@tonic-gate 31067c478bd9Sstevel@tonic-gate if (BITX(cp->cp_ebx, 31, 16) == 0) { 31077c478bd9Sstevel@tonic-gate add_amd_l2_tlb(devi, "l2-tlb-4K", 31087c478bd9Sstevel@tonic-gate BITX(cp->cp_eax, 15, 12), BITX(cp->cp_eax, 11, 0)); 31097c478bd9Sstevel@tonic-gate } else { 31107c478bd9Sstevel@tonic-gate add_amd_l2_tlb(devi, "l2-dtlb-4K", 31117c478bd9Sstevel@tonic-gate BITX(cp->cp_eax, 31, 28), BITX(cp->cp_eax, 27, 16)); 31127c478bd9Sstevel@tonic-gate add_amd_l2_tlb(devi, "l2-itlb-4K", 31137c478bd9Sstevel@tonic-gate BITX(cp->cp_eax, 15, 12), BITX(cp->cp_eax, 11, 0)); 31147c478bd9Sstevel@tonic-gate } 31157c478bd9Sstevel@tonic-gate 31167c478bd9Sstevel@tonic-gate add_amd_l2_cache(devi, l2_cache_str, 31177c478bd9Sstevel@tonic-gate BITX(cp->cp_ecx, 31, 16), BITX(cp->cp_ecx, 15, 12), 31187c478bd9Sstevel@tonic-gate BITX(cp->cp_ecx, 11, 8), BITX(cp->cp_ecx, 7, 0)); 31197c478bd9Sstevel@tonic-gate } 31207c478bd9Sstevel@tonic-gate 31217c478bd9Sstevel@tonic-gate /* 31227c478bd9Sstevel@tonic-gate * There are two basic ways that the x86 world describes it cache 31237c478bd9Sstevel@tonic-gate * and tlb architecture - Intel's way and AMD's way. 31247c478bd9Sstevel@tonic-gate * 31257c478bd9Sstevel@tonic-gate * Return which flavor of cache architecture we should use 31267c478bd9Sstevel@tonic-gate */ 31277c478bd9Sstevel@tonic-gate static int 31287c478bd9Sstevel@tonic-gate x86_which_cacheinfo(struct cpuid_info *cpi) 31297c478bd9Sstevel@tonic-gate { 31307c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 31317c478bd9Sstevel@tonic-gate case X86_VENDOR_Intel: 31327c478bd9Sstevel@tonic-gate if (cpi->cpi_maxeax >= 2) 31337c478bd9Sstevel@tonic-gate return (X86_VENDOR_Intel); 31347c478bd9Sstevel@tonic-gate break; 31357c478bd9Sstevel@tonic-gate case X86_VENDOR_AMD: 31367c478bd9Sstevel@tonic-gate /* 31377c478bd9Sstevel@tonic-gate * The K5 model 1 was the first part from AMD that reported 31387c478bd9Sstevel@tonic-gate * cache sizes via extended cpuid functions. 31397c478bd9Sstevel@tonic-gate */ 31407c478bd9Sstevel@tonic-gate if (cpi->cpi_family > 5 || 31417c478bd9Sstevel@tonic-gate (cpi->cpi_family == 5 && cpi->cpi_model >= 1)) 31427c478bd9Sstevel@tonic-gate return (X86_VENDOR_AMD); 31437c478bd9Sstevel@tonic-gate break; 31447c478bd9Sstevel@tonic-gate case X86_VENDOR_TM: 31457c478bd9Sstevel@tonic-gate if (cpi->cpi_family >= 5) 31467c478bd9Sstevel@tonic-gate return (X86_VENDOR_AMD); 31477c478bd9Sstevel@tonic-gate /*FALLTHROUGH*/ 31487c478bd9Sstevel@tonic-gate default: 31497c478bd9Sstevel@tonic-gate /* 31507c478bd9Sstevel@tonic-gate * If they have extended CPU data for 0x80000005 31517c478bd9Sstevel@tonic-gate * then we assume they have AMD-format cache 31527c478bd9Sstevel@tonic-gate * information. 31537c478bd9Sstevel@tonic-gate * 31547c478bd9Sstevel@tonic-gate * If not, and the vendor happens to be Cyrix, 31557c478bd9Sstevel@tonic-gate * then try our-Cyrix specific handler. 31567c478bd9Sstevel@tonic-gate * 31577c478bd9Sstevel@tonic-gate * If we're not Cyrix, then assume we're using Intel's 31587c478bd9Sstevel@tonic-gate * table-driven format instead. 31597c478bd9Sstevel@tonic-gate */ 31607c478bd9Sstevel@tonic-gate if (cpi->cpi_xmaxeax >= 0x80000005) 31617c478bd9Sstevel@tonic-gate return (X86_VENDOR_AMD); 31627c478bd9Sstevel@tonic-gate else if (cpi->cpi_vendor == X86_VENDOR_Cyrix) 31637c478bd9Sstevel@tonic-gate return (X86_VENDOR_Cyrix); 31647c478bd9Sstevel@tonic-gate else if (cpi->cpi_maxeax >= 2) 31657c478bd9Sstevel@tonic-gate return (X86_VENDOR_Intel); 31667c478bd9Sstevel@tonic-gate break; 31677c478bd9Sstevel@tonic-gate } 31687c478bd9Sstevel@tonic-gate return (-1); 31697c478bd9Sstevel@tonic-gate } 31707c478bd9Sstevel@tonic-gate 31717c478bd9Sstevel@tonic-gate /* 31727c478bd9Sstevel@tonic-gate * create a node for the given cpu under the prom root node. 31737c478bd9Sstevel@tonic-gate * Also, create a cpu node in the device tree. 31747c478bd9Sstevel@tonic-gate */ 31757c478bd9Sstevel@tonic-gate static dev_info_t *cpu_nex_devi = NULL; 31767c478bd9Sstevel@tonic-gate static kmutex_t cpu_node_lock; 31777c478bd9Sstevel@tonic-gate 31787c478bd9Sstevel@tonic-gate /* 31797c478bd9Sstevel@tonic-gate * Called from post_startup() and mp_startup() 31807c478bd9Sstevel@tonic-gate */ 31817c478bd9Sstevel@tonic-gate void 31827c478bd9Sstevel@tonic-gate add_cpunode2devtree(processorid_t cpu_id, struct cpuid_info *cpi) 31837c478bd9Sstevel@tonic-gate { 31847c478bd9Sstevel@tonic-gate dev_info_t *cpu_devi; 31857c478bd9Sstevel@tonic-gate int create; 31867c478bd9Sstevel@tonic-gate 31877c478bd9Sstevel@tonic-gate mutex_enter(&cpu_node_lock); 31887c478bd9Sstevel@tonic-gate 31897c478bd9Sstevel@tonic-gate /* 31907c478bd9Sstevel@tonic-gate * create a nexus node for all cpus identified as 'cpu_id' under 31917c478bd9Sstevel@tonic-gate * the root node. 31927c478bd9Sstevel@tonic-gate */ 31937c478bd9Sstevel@tonic-gate if (cpu_nex_devi == NULL) { 31947c478bd9Sstevel@tonic-gate if (ndi_devi_alloc(ddi_root_node(), "cpus", 3195fa9e4066Sahrens (pnode_t)DEVI_SID_NODEID, &cpu_nex_devi) != NDI_SUCCESS) { 31967c478bd9Sstevel@tonic-gate mutex_exit(&cpu_node_lock); 31977c478bd9Sstevel@tonic-gate return; 31987c478bd9Sstevel@tonic-gate } 31997c478bd9Sstevel@tonic-gate (void) ndi_devi_online(cpu_nex_devi, 0); 32007c478bd9Sstevel@tonic-gate } 32017c478bd9Sstevel@tonic-gate 32027c478bd9Sstevel@tonic-gate /* 32037c478bd9Sstevel@tonic-gate * create a child node for cpu identified as 'cpu_id' 32047c478bd9Sstevel@tonic-gate */ 32057c478bd9Sstevel@tonic-gate cpu_devi = ddi_add_child(cpu_nex_devi, "cpu", DEVI_SID_NODEID, 32067c478bd9Sstevel@tonic-gate cpu_id); 32077c478bd9Sstevel@tonic-gate if (cpu_devi == NULL) { 32087c478bd9Sstevel@tonic-gate mutex_exit(&cpu_node_lock); 32097c478bd9Sstevel@tonic-gate return; 32107c478bd9Sstevel@tonic-gate } 32117c478bd9Sstevel@tonic-gate 32127c478bd9Sstevel@tonic-gate /* device_type */ 32137c478bd9Sstevel@tonic-gate 32147c478bd9Sstevel@tonic-gate (void) ndi_prop_update_string(DDI_DEV_T_NONE, cpu_devi, 32157c478bd9Sstevel@tonic-gate "device_type", "cpu"); 32167c478bd9Sstevel@tonic-gate 32177c478bd9Sstevel@tonic-gate /* reg */ 32187c478bd9Sstevel@tonic-gate 32197c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 32207c478bd9Sstevel@tonic-gate "reg", cpu_id); 32217c478bd9Sstevel@tonic-gate 32227c478bd9Sstevel@tonic-gate /* cpu-mhz, and clock-frequency */ 32237c478bd9Sstevel@tonic-gate 32247c478bd9Sstevel@tonic-gate if (cpu_freq > 0) { 32257c478bd9Sstevel@tonic-gate long long mul; 32267c478bd9Sstevel@tonic-gate 32277c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 32287c478bd9Sstevel@tonic-gate "cpu-mhz", cpu_freq); 32297c478bd9Sstevel@tonic-gate 32307c478bd9Sstevel@tonic-gate if ((mul = cpu_freq * 1000000LL) <= INT_MAX) 32317c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 32327c478bd9Sstevel@tonic-gate "clock-frequency", (int)mul); 32337c478bd9Sstevel@tonic-gate } 32347c478bd9Sstevel@tonic-gate 32357c478bd9Sstevel@tonic-gate (void) ndi_devi_online(cpu_devi, 0); 32367c478bd9Sstevel@tonic-gate 32377c478bd9Sstevel@tonic-gate if ((x86_feature & X86_CPUID) == 0) { 32387c478bd9Sstevel@tonic-gate mutex_exit(&cpu_node_lock); 32397c478bd9Sstevel@tonic-gate return; 32407c478bd9Sstevel@tonic-gate } 32417c478bd9Sstevel@tonic-gate 32427c478bd9Sstevel@tonic-gate /* vendor-id */ 32437c478bd9Sstevel@tonic-gate 32447c478bd9Sstevel@tonic-gate (void) ndi_prop_update_string(DDI_DEV_T_NONE, cpu_devi, 32457c478bd9Sstevel@tonic-gate "vendor-id", cpi->cpi_vendorstr); 32467c478bd9Sstevel@tonic-gate 32477c478bd9Sstevel@tonic-gate if (cpi->cpi_maxeax == 0) { 32487c478bd9Sstevel@tonic-gate mutex_exit(&cpu_node_lock); 32497c478bd9Sstevel@tonic-gate return; 32507c478bd9Sstevel@tonic-gate } 32517c478bd9Sstevel@tonic-gate 32527c478bd9Sstevel@tonic-gate /* 32537c478bd9Sstevel@tonic-gate * family, model, and step 32547c478bd9Sstevel@tonic-gate */ 32557c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 32567c478bd9Sstevel@tonic-gate "family", CPI_FAMILY(cpi)); 32577c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 32587c478bd9Sstevel@tonic-gate "cpu-model", CPI_MODEL(cpi)); 32597c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 32607c478bd9Sstevel@tonic-gate "stepping-id", CPI_STEP(cpi)); 32617c478bd9Sstevel@tonic-gate 32627c478bd9Sstevel@tonic-gate /* type */ 32637c478bd9Sstevel@tonic-gate 32647c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 32657c478bd9Sstevel@tonic-gate case X86_VENDOR_Intel: 32667c478bd9Sstevel@tonic-gate create = 1; 32677c478bd9Sstevel@tonic-gate break; 32687c478bd9Sstevel@tonic-gate default: 32697c478bd9Sstevel@tonic-gate create = 0; 32707c478bd9Sstevel@tonic-gate break; 32717c478bd9Sstevel@tonic-gate } 32727c478bd9Sstevel@tonic-gate if (create) 32737c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 32747c478bd9Sstevel@tonic-gate "type", CPI_TYPE(cpi)); 32757c478bd9Sstevel@tonic-gate 32767c478bd9Sstevel@tonic-gate /* ext-family */ 32777c478bd9Sstevel@tonic-gate 32787c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 32797c478bd9Sstevel@tonic-gate case X86_VENDOR_Intel: 32807c478bd9Sstevel@tonic-gate case X86_VENDOR_AMD: 32817c478bd9Sstevel@tonic-gate create = cpi->cpi_family >= 0xf; 32827c478bd9Sstevel@tonic-gate break; 32837c478bd9Sstevel@tonic-gate default: 32847c478bd9Sstevel@tonic-gate create = 0; 32857c478bd9Sstevel@tonic-gate break; 32867c478bd9Sstevel@tonic-gate } 32877c478bd9Sstevel@tonic-gate if (create) 32887c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 32897c478bd9Sstevel@tonic-gate "ext-family", CPI_FAMILY_XTD(cpi)); 32907c478bd9Sstevel@tonic-gate 32917c478bd9Sstevel@tonic-gate /* ext-model */ 32927c478bd9Sstevel@tonic-gate 32937c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 32947c478bd9Sstevel@tonic-gate case X86_VENDOR_Intel: 329568c91426Sdmick create = CPI_MODEL(cpi) == 0xf; 329668c91426Sdmick break; 32977c478bd9Sstevel@tonic-gate case X86_VENDOR_AMD: 3298ee88d2b9Skchow create = CPI_FAMILY(cpi) == 0xf; 32997c478bd9Sstevel@tonic-gate break; 33007c478bd9Sstevel@tonic-gate default: 33017c478bd9Sstevel@tonic-gate create = 0; 33027c478bd9Sstevel@tonic-gate break; 33037c478bd9Sstevel@tonic-gate } 33047c478bd9Sstevel@tonic-gate if (create) 33057c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 33067c478bd9Sstevel@tonic-gate "ext-model", CPI_MODEL_XTD(cpi)); 33077c478bd9Sstevel@tonic-gate 33087c478bd9Sstevel@tonic-gate /* generation */ 33097c478bd9Sstevel@tonic-gate 33107c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 33117c478bd9Sstevel@tonic-gate case X86_VENDOR_AMD: 33127c478bd9Sstevel@tonic-gate /* 33137c478bd9Sstevel@tonic-gate * AMD K5 model 1 was the first part to support this 33147c478bd9Sstevel@tonic-gate */ 33157c478bd9Sstevel@tonic-gate create = cpi->cpi_xmaxeax >= 0x80000001; 33167c478bd9Sstevel@tonic-gate break; 33177c478bd9Sstevel@tonic-gate default: 33187c478bd9Sstevel@tonic-gate create = 0; 33197c478bd9Sstevel@tonic-gate break; 33207c478bd9Sstevel@tonic-gate } 33217c478bd9Sstevel@tonic-gate if (create) 33227c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 33237c478bd9Sstevel@tonic-gate "generation", BITX((cpi)->cpi_extd[1].cp_eax, 11, 8)); 33247c478bd9Sstevel@tonic-gate 33257c478bd9Sstevel@tonic-gate /* brand-id */ 33267c478bd9Sstevel@tonic-gate 33277c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 33287c478bd9Sstevel@tonic-gate case X86_VENDOR_Intel: 33297c478bd9Sstevel@tonic-gate /* 33307c478bd9Sstevel@tonic-gate * brand id first appeared on Pentium III Xeon model 8, 33317c478bd9Sstevel@tonic-gate * and Celeron model 8 processors and Opteron 33327c478bd9Sstevel@tonic-gate */ 33337c478bd9Sstevel@tonic-gate create = cpi->cpi_family > 6 || 33347c478bd9Sstevel@tonic-gate (cpi->cpi_family == 6 && cpi->cpi_model >= 8); 33357c478bd9Sstevel@tonic-gate break; 33367c478bd9Sstevel@tonic-gate case X86_VENDOR_AMD: 33377c478bd9Sstevel@tonic-gate create = cpi->cpi_family >= 0xf; 33387c478bd9Sstevel@tonic-gate break; 33397c478bd9Sstevel@tonic-gate default: 33407c478bd9Sstevel@tonic-gate create = 0; 33417c478bd9Sstevel@tonic-gate break; 33427c478bd9Sstevel@tonic-gate } 33437c478bd9Sstevel@tonic-gate if (create && cpi->cpi_brandid != 0) { 33447c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 33457c478bd9Sstevel@tonic-gate "brand-id", cpi->cpi_brandid); 33467c478bd9Sstevel@tonic-gate } 33477c478bd9Sstevel@tonic-gate 33487c478bd9Sstevel@tonic-gate /* chunks, and apic-id */ 33497c478bd9Sstevel@tonic-gate 33507c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 33517c478bd9Sstevel@tonic-gate /* 33527c478bd9Sstevel@tonic-gate * first available on Pentium IV and Opteron (K8) 33537c478bd9Sstevel@tonic-gate */ 33545ff02082Sdmick case X86_VENDOR_Intel: 33555ff02082Sdmick create = IS_NEW_F6(cpi) || cpi->cpi_family >= 0xf; 33565ff02082Sdmick break; 33575ff02082Sdmick case X86_VENDOR_AMD: 33587c478bd9Sstevel@tonic-gate create = cpi->cpi_family >= 0xf; 33597c478bd9Sstevel@tonic-gate break; 33607c478bd9Sstevel@tonic-gate default: 33617c478bd9Sstevel@tonic-gate create = 0; 33627c478bd9Sstevel@tonic-gate break; 33637c478bd9Sstevel@tonic-gate } 33647c478bd9Sstevel@tonic-gate if (create) { 33657c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 33667c478bd9Sstevel@tonic-gate "chunks", CPI_CHUNKS(cpi)); 33677c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 33687c478bd9Sstevel@tonic-gate "apic-id", CPI_APIC_ID(cpi)); 33697aec1d6eScindi if (cpi->cpi_chipid >= 0) { 33707c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 33717c478bd9Sstevel@tonic-gate "chip#", cpi->cpi_chipid); 33727aec1d6eScindi (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 33737aec1d6eScindi "clog#", cpi->cpi_clogid); 33747aec1d6eScindi } 33757c478bd9Sstevel@tonic-gate } 33767c478bd9Sstevel@tonic-gate 33777c478bd9Sstevel@tonic-gate /* cpuid-features */ 33787c478bd9Sstevel@tonic-gate 33797c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 33807c478bd9Sstevel@tonic-gate "cpuid-features", CPI_FEATURES_EDX(cpi)); 33817c478bd9Sstevel@tonic-gate 33827c478bd9Sstevel@tonic-gate 33837c478bd9Sstevel@tonic-gate /* cpuid-features-ecx */ 33847c478bd9Sstevel@tonic-gate 33857c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 33867c478bd9Sstevel@tonic-gate case X86_VENDOR_Intel: 33875ff02082Sdmick create = IS_NEW_F6(cpi) || cpi->cpi_family >= 0xf; 33887c478bd9Sstevel@tonic-gate break; 33897c478bd9Sstevel@tonic-gate default: 33907c478bd9Sstevel@tonic-gate create = 0; 33917c478bd9Sstevel@tonic-gate break; 33927c478bd9Sstevel@tonic-gate } 33937c478bd9Sstevel@tonic-gate if (create) 33947c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 33957c478bd9Sstevel@tonic-gate "cpuid-features-ecx", CPI_FEATURES_ECX(cpi)); 33967c478bd9Sstevel@tonic-gate 33977c478bd9Sstevel@tonic-gate /* ext-cpuid-features */ 33987c478bd9Sstevel@tonic-gate 33997c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 34005ff02082Sdmick case X86_VENDOR_Intel: 34017c478bd9Sstevel@tonic-gate case X86_VENDOR_AMD: 34027c478bd9Sstevel@tonic-gate case X86_VENDOR_Cyrix: 34037c478bd9Sstevel@tonic-gate case X86_VENDOR_TM: 34047c478bd9Sstevel@tonic-gate case X86_VENDOR_Centaur: 34057c478bd9Sstevel@tonic-gate create = cpi->cpi_xmaxeax >= 0x80000001; 34067c478bd9Sstevel@tonic-gate break; 34077c478bd9Sstevel@tonic-gate default: 34087c478bd9Sstevel@tonic-gate create = 0; 34097c478bd9Sstevel@tonic-gate break; 34107c478bd9Sstevel@tonic-gate } 34115ff02082Sdmick if (create) { 34127c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 34137c478bd9Sstevel@tonic-gate "ext-cpuid-features", CPI_FEATURES_XTD_EDX(cpi)); 34145ff02082Sdmick (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 34155ff02082Sdmick "ext-cpuid-features-ecx", CPI_FEATURES_XTD_ECX(cpi)); 34165ff02082Sdmick } 34177c478bd9Sstevel@tonic-gate 34187c478bd9Sstevel@tonic-gate /* 34197c478bd9Sstevel@tonic-gate * Brand String first appeared in Intel Pentium IV, AMD K5 34207c478bd9Sstevel@tonic-gate * model 1, and Cyrix GXm. On earlier models we try and 34217c478bd9Sstevel@tonic-gate * simulate something similar .. so this string should always 34227c478bd9Sstevel@tonic-gate * same -something- about the processor, however lame. 34237c478bd9Sstevel@tonic-gate */ 34247c478bd9Sstevel@tonic-gate (void) ndi_prop_update_string(DDI_DEV_T_NONE, cpu_devi, 34257c478bd9Sstevel@tonic-gate "brand-string", cpi->cpi_brandstr); 34267c478bd9Sstevel@tonic-gate 34277c478bd9Sstevel@tonic-gate /* 34287c478bd9Sstevel@tonic-gate * Finally, cache and tlb information 34297c478bd9Sstevel@tonic-gate */ 34307c478bd9Sstevel@tonic-gate switch (x86_which_cacheinfo(cpi)) { 34317c478bd9Sstevel@tonic-gate case X86_VENDOR_Intel: 34327c478bd9Sstevel@tonic-gate intel_walk_cacheinfo(cpi, cpu_devi, add_cacheent_props); 34337c478bd9Sstevel@tonic-gate break; 34347c478bd9Sstevel@tonic-gate case X86_VENDOR_Cyrix: 34357c478bd9Sstevel@tonic-gate cyrix_walk_cacheinfo(cpi, cpu_devi, add_cacheent_props); 34367c478bd9Sstevel@tonic-gate break; 34377c478bd9Sstevel@tonic-gate case X86_VENDOR_AMD: 34387c478bd9Sstevel@tonic-gate amd_cache_info(cpi, cpu_devi); 34397c478bd9Sstevel@tonic-gate break; 34407c478bd9Sstevel@tonic-gate default: 34417c478bd9Sstevel@tonic-gate break; 34427c478bd9Sstevel@tonic-gate } 34437c478bd9Sstevel@tonic-gate 34447c478bd9Sstevel@tonic-gate mutex_exit(&cpu_node_lock); 34457c478bd9Sstevel@tonic-gate } 34467c478bd9Sstevel@tonic-gate 34477c478bd9Sstevel@tonic-gate struct l2info { 34487c478bd9Sstevel@tonic-gate int *l2i_csz; 34497c478bd9Sstevel@tonic-gate int *l2i_lsz; 34507c478bd9Sstevel@tonic-gate int *l2i_assoc; 34517c478bd9Sstevel@tonic-gate int l2i_ret; 34527c478bd9Sstevel@tonic-gate }; 34537c478bd9Sstevel@tonic-gate 34547c478bd9Sstevel@tonic-gate /* 34557c478bd9Sstevel@tonic-gate * A cacheinfo walker that fetches the size, line-size and associativity 34567c478bd9Sstevel@tonic-gate * of the L2 cache 34577c478bd9Sstevel@tonic-gate */ 34587c478bd9Sstevel@tonic-gate static int 34597c478bd9Sstevel@tonic-gate intel_l2cinfo(void *arg, const struct cachetab *ct) 34607c478bd9Sstevel@tonic-gate { 34617c478bd9Sstevel@tonic-gate struct l2info *l2i = arg; 34627c478bd9Sstevel@tonic-gate int *ip; 34637c478bd9Sstevel@tonic-gate 34647c478bd9Sstevel@tonic-gate if (ct->ct_label != l2_cache_str && 34657c478bd9Sstevel@tonic-gate ct->ct_label != sl2_cache_str) 34667c478bd9Sstevel@tonic-gate return (0); /* not an L2 -- keep walking */ 34677c478bd9Sstevel@tonic-gate 34687c478bd9Sstevel@tonic-gate if ((ip = l2i->l2i_csz) != NULL) 34697c478bd9Sstevel@tonic-gate *ip = ct->ct_size; 34707c478bd9Sstevel@tonic-gate if ((ip = l2i->l2i_lsz) != NULL) 34717c478bd9Sstevel@tonic-gate *ip = ct->ct_line_size; 34727c478bd9Sstevel@tonic-gate if ((ip = l2i->l2i_assoc) != NULL) 34737c478bd9Sstevel@tonic-gate *ip = ct->ct_assoc; 34747c478bd9Sstevel@tonic-gate l2i->l2i_ret = ct->ct_size; 34757c478bd9Sstevel@tonic-gate return (1); /* was an L2 -- terminate walk */ 34767c478bd9Sstevel@tonic-gate } 34777c478bd9Sstevel@tonic-gate 3478606303c9Skchow /* 3479606303c9Skchow * AMD L2/L3 Cache and TLB Associativity Field Definition: 3480606303c9Skchow * 3481606303c9Skchow * Unlike the associativity for the L1 cache and tlb where the 8 bit 3482606303c9Skchow * value is the associativity, the associativity for the L2 cache and 3483606303c9Skchow * tlb is encoded in the following table. The 4 bit L2 value serves as 3484606303c9Skchow * an index into the amd_afd[] array to determine the associativity. 3485606303c9Skchow * -1 is undefined. 0 is fully associative. 3486606303c9Skchow */ 3487606303c9Skchow 3488606303c9Skchow static int amd_afd[] = 3489606303c9Skchow {-1, 1, 2, -1, 4, -1, 8, -1, 16, -1, 32, 48, 64, 96, 128, 0}; 3490606303c9Skchow 34917c478bd9Sstevel@tonic-gate static void 34927c478bd9Sstevel@tonic-gate amd_l2cacheinfo(struct cpuid_info *cpi, struct l2info *l2i) 34937c478bd9Sstevel@tonic-gate { 34948949bcd6Sandrei struct cpuid_regs *cp; 34957c478bd9Sstevel@tonic-gate uint_t size, assoc; 3496606303c9Skchow int i; 34977c478bd9Sstevel@tonic-gate int *ip; 34987c478bd9Sstevel@tonic-gate 34997c478bd9Sstevel@tonic-gate if (cpi->cpi_xmaxeax < 0x80000006) 35007c478bd9Sstevel@tonic-gate return; 35017c478bd9Sstevel@tonic-gate cp = &cpi->cpi_extd[6]; 35027c478bd9Sstevel@tonic-gate 3503606303c9Skchow if ((i = BITX(cp->cp_ecx, 15, 12)) != 0 && 35047c478bd9Sstevel@tonic-gate (size = BITX(cp->cp_ecx, 31, 16)) != 0) { 35057c478bd9Sstevel@tonic-gate uint_t cachesz = size * 1024; 3506606303c9Skchow assoc = amd_afd[i]; 35077c478bd9Sstevel@tonic-gate 3508606303c9Skchow ASSERT(assoc != -1); 35097c478bd9Sstevel@tonic-gate 35107c478bd9Sstevel@tonic-gate if ((ip = l2i->l2i_csz) != NULL) 35117c478bd9Sstevel@tonic-gate *ip = cachesz; 35127c478bd9Sstevel@tonic-gate if ((ip = l2i->l2i_lsz) != NULL) 35137c478bd9Sstevel@tonic-gate *ip = BITX(cp->cp_ecx, 7, 0); 35147c478bd9Sstevel@tonic-gate if ((ip = l2i->l2i_assoc) != NULL) 35157c478bd9Sstevel@tonic-gate *ip = assoc; 35167c478bd9Sstevel@tonic-gate l2i->l2i_ret = cachesz; 35177c478bd9Sstevel@tonic-gate } 35187c478bd9Sstevel@tonic-gate } 35197c478bd9Sstevel@tonic-gate 35207c478bd9Sstevel@tonic-gate int 35217c478bd9Sstevel@tonic-gate getl2cacheinfo(cpu_t *cpu, int *csz, int *lsz, int *assoc) 35227c478bd9Sstevel@tonic-gate { 35237c478bd9Sstevel@tonic-gate struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 35247c478bd9Sstevel@tonic-gate struct l2info __l2info, *l2i = &__l2info; 35257c478bd9Sstevel@tonic-gate 35267c478bd9Sstevel@tonic-gate l2i->l2i_csz = csz; 35277c478bd9Sstevel@tonic-gate l2i->l2i_lsz = lsz; 35287c478bd9Sstevel@tonic-gate l2i->l2i_assoc = assoc; 35297c478bd9Sstevel@tonic-gate l2i->l2i_ret = -1; 35307c478bd9Sstevel@tonic-gate 35317c478bd9Sstevel@tonic-gate switch (x86_which_cacheinfo(cpi)) { 35327c478bd9Sstevel@tonic-gate case X86_VENDOR_Intel: 35337c478bd9Sstevel@tonic-gate intel_walk_cacheinfo(cpi, l2i, intel_l2cinfo); 35347c478bd9Sstevel@tonic-gate break; 35357c478bd9Sstevel@tonic-gate case X86_VENDOR_Cyrix: 35367c478bd9Sstevel@tonic-gate cyrix_walk_cacheinfo(cpi, l2i, intel_l2cinfo); 35377c478bd9Sstevel@tonic-gate break; 35387c478bd9Sstevel@tonic-gate case X86_VENDOR_AMD: 35397c478bd9Sstevel@tonic-gate amd_l2cacheinfo(cpi, l2i); 35407c478bd9Sstevel@tonic-gate break; 35417c478bd9Sstevel@tonic-gate default: 35427c478bd9Sstevel@tonic-gate break; 35437c478bd9Sstevel@tonic-gate } 35447c478bd9Sstevel@tonic-gate return (l2i->l2i_ret); 35457c478bd9Sstevel@tonic-gate } 3546f98fbcecSbholler 3547843e1988Sjohnlev #if !defined(__xpv) 3548843e1988Sjohnlev 35495b8a6efeSbholler uint32_t * 35505b8a6efeSbholler cpuid_mwait_alloc(cpu_t *cpu) 35515b8a6efeSbholler { 35525b8a6efeSbholler uint32_t *ret; 35535b8a6efeSbholler size_t mwait_size; 35545b8a6efeSbholler 35555b8a6efeSbholler ASSERT(cpuid_checkpass(cpu, 2)); 35565b8a6efeSbholler 35575b8a6efeSbholler mwait_size = cpu->cpu_m.mcpu_cpi->cpi_mwait.mon_max; 35585b8a6efeSbholler if (mwait_size == 0) 35595b8a6efeSbholler return (NULL); 35605b8a6efeSbholler 35615b8a6efeSbholler /* 35625b8a6efeSbholler * kmem_alloc() returns cache line size aligned data for mwait_size 35635b8a6efeSbholler * allocations. mwait_size is currently cache line sized. Neither 35645b8a6efeSbholler * of these implementation details are guarantied to be true in the 35655b8a6efeSbholler * future. 35665b8a6efeSbholler * 35675b8a6efeSbholler * First try allocating mwait_size as kmem_alloc() currently returns 35685b8a6efeSbholler * correctly aligned memory. If kmem_alloc() does not return 35695b8a6efeSbholler * mwait_size aligned memory, then use mwait_size ROUNDUP. 35705b8a6efeSbholler * 35715b8a6efeSbholler * Set cpi_mwait.buf_actual and cpi_mwait.size_actual in case we 35725b8a6efeSbholler * decide to free this memory. 35735b8a6efeSbholler */ 35745b8a6efeSbholler ret = kmem_zalloc(mwait_size, KM_SLEEP); 35755b8a6efeSbholler if (ret == (uint32_t *)P2ROUNDUP((uintptr_t)ret, mwait_size)) { 35765b8a6efeSbholler cpu->cpu_m.mcpu_cpi->cpi_mwait.buf_actual = ret; 35775b8a6efeSbholler cpu->cpu_m.mcpu_cpi->cpi_mwait.size_actual = mwait_size; 35785b8a6efeSbholler *ret = MWAIT_RUNNING; 35795b8a6efeSbholler return (ret); 35805b8a6efeSbholler } else { 35815b8a6efeSbholler kmem_free(ret, mwait_size); 35825b8a6efeSbholler ret = kmem_zalloc(mwait_size * 2, KM_SLEEP); 35835b8a6efeSbholler cpu->cpu_m.mcpu_cpi->cpi_mwait.buf_actual = ret; 35845b8a6efeSbholler cpu->cpu_m.mcpu_cpi->cpi_mwait.size_actual = mwait_size * 2; 35855b8a6efeSbholler ret = (uint32_t *)P2ROUNDUP((uintptr_t)ret, mwait_size); 35865b8a6efeSbholler *ret = MWAIT_RUNNING; 35875b8a6efeSbholler return (ret); 35885b8a6efeSbholler } 35895b8a6efeSbholler } 35905b8a6efeSbholler 35915b8a6efeSbholler void 35925b8a6efeSbholler cpuid_mwait_free(cpu_t *cpu) 3593f98fbcecSbholler { 3594f98fbcecSbholler ASSERT(cpuid_checkpass(cpu, 2)); 35955b8a6efeSbholler 35965b8a6efeSbholler if (cpu->cpu_m.mcpu_cpi->cpi_mwait.buf_actual != NULL && 35975b8a6efeSbholler cpu->cpu_m.mcpu_cpi->cpi_mwait.size_actual > 0) { 35985b8a6efeSbholler kmem_free(cpu->cpu_m.mcpu_cpi->cpi_mwait.buf_actual, 35995b8a6efeSbholler cpu->cpu_m.mcpu_cpi->cpi_mwait.size_actual); 36005b8a6efeSbholler } 36015b8a6efeSbholler 36025b8a6efeSbholler cpu->cpu_m.mcpu_cpi->cpi_mwait.buf_actual = NULL; 36035b8a6efeSbholler cpu->cpu_m.mcpu_cpi->cpi_mwait.size_actual = 0; 3604f98fbcecSbholler } 3605843e1988Sjohnlev 3606843e1988Sjohnlev #endif /* !__xpv */ 3607