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> 43fb2f18f8Sesaxe #include <sys/pg.h> 447c478bd9Sstevel@tonic-gate #include <sys/fp.h> 457c478bd9Sstevel@tonic-gate #include <sys/controlregs.h> 467c478bd9Sstevel@tonic-gate #include <sys/auxv_386.h> 477c478bd9Sstevel@tonic-gate #include <sys/bitmap.h> 487c478bd9Sstevel@tonic-gate #include <sys/memnode.h> 497c478bd9Sstevel@tonic-gate 507c478bd9Sstevel@tonic-gate /* 517c478bd9Sstevel@tonic-gate * Pass 0 of cpuid feature analysis happens in locore. It contains special code 527c478bd9Sstevel@tonic-gate * to recognize Cyrix processors that are not cpuid-compliant, and to deal with 537c478bd9Sstevel@tonic-gate * them accordingly. For most modern processors, feature detection occurs here 547c478bd9Sstevel@tonic-gate * in pass 1. 557c478bd9Sstevel@tonic-gate * 567c478bd9Sstevel@tonic-gate * Pass 1 of cpuid feature analysis happens just at the beginning of mlsetup() 577c478bd9Sstevel@tonic-gate * for the boot CPU and does the basic analysis that the early kernel needs. 587c478bd9Sstevel@tonic-gate * x86_feature is set based on the return value of cpuid_pass1() of the boot 597c478bd9Sstevel@tonic-gate * CPU. 607c478bd9Sstevel@tonic-gate * 617c478bd9Sstevel@tonic-gate * Pass 1 includes: 627c478bd9Sstevel@tonic-gate * 637c478bd9Sstevel@tonic-gate * o Determining vendor/model/family/stepping and setting x86_type and 647c478bd9Sstevel@tonic-gate * x86_vendor accordingly. 657c478bd9Sstevel@tonic-gate * o Processing the feature flags returned by the cpuid instruction while 667c478bd9Sstevel@tonic-gate * applying any workarounds or tricks for the specific processor. 677c478bd9Sstevel@tonic-gate * o Mapping the feature flags into Solaris feature bits (X86_*). 687c478bd9Sstevel@tonic-gate * o Processing extended feature flags if supported by the processor, 697c478bd9Sstevel@tonic-gate * again while applying specific processor knowledge. 707c478bd9Sstevel@tonic-gate * o Determining the CMT characteristics of the system. 717c478bd9Sstevel@tonic-gate * 727c478bd9Sstevel@tonic-gate * Pass 1 is done on non-boot CPUs during their initialization and the results 737c478bd9Sstevel@tonic-gate * are used only as a meager attempt at ensuring that all processors within the 747c478bd9Sstevel@tonic-gate * system support the same features. 757c478bd9Sstevel@tonic-gate * 767c478bd9Sstevel@tonic-gate * Pass 2 of cpuid feature analysis happens just at the beginning 777c478bd9Sstevel@tonic-gate * of startup(). It just copies in and corrects the remainder 787c478bd9Sstevel@tonic-gate * of the cpuid data we depend on: standard cpuid functions that we didn't 797c478bd9Sstevel@tonic-gate * need for pass1 feature analysis, and extended cpuid functions beyond the 807c478bd9Sstevel@tonic-gate * simple feature processing done in pass1. 817c478bd9Sstevel@tonic-gate * 827c478bd9Sstevel@tonic-gate * Pass 3 of cpuid analysis is invoked after basic kernel services; in 837c478bd9Sstevel@tonic-gate * particular kernel memory allocation has been made available. It creates a 847c478bd9Sstevel@tonic-gate * readable brand string based on the data collected in the first two passes. 857c478bd9Sstevel@tonic-gate * 867c478bd9Sstevel@tonic-gate * Pass 4 of cpuid analysis is invoked after post_startup() when all 877c478bd9Sstevel@tonic-gate * the support infrastructure for various hardware features has been 887c478bd9Sstevel@tonic-gate * initialized. It determines which processor features will be reported 897c478bd9Sstevel@tonic-gate * to userland via the aux vector. 907c478bd9Sstevel@tonic-gate * 917c478bd9Sstevel@tonic-gate * All passes are executed on all CPUs, but only the boot CPU determines what 927c478bd9Sstevel@tonic-gate * features the kernel will use. 937c478bd9Sstevel@tonic-gate * 947c478bd9Sstevel@tonic-gate * Much of the worst junk in this file is for the support of processors 957c478bd9Sstevel@tonic-gate * that didn't really implement the cpuid instruction properly. 967c478bd9Sstevel@tonic-gate * 977c478bd9Sstevel@tonic-gate * NOTE: The accessor functions (cpuid_get*) are aware of, and ASSERT upon, 987c478bd9Sstevel@tonic-gate * the pass numbers. Accordingly, changes to the pass code may require changes 997c478bd9Sstevel@tonic-gate * to the accessor code. 1007c478bd9Sstevel@tonic-gate */ 1017c478bd9Sstevel@tonic-gate 1027c478bd9Sstevel@tonic-gate uint_t x86_feature = 0; 1037c478bd9Sstevel@tonic-gate uint_t x86_vendor = X86_VENDOR_IntelClone; 1047c478bd9Sstevel@tonic-gate uint_t x86_type = X86_TYPE_OTHER; 1057c478bd9Sstevel@tonic-gate 1067c478bd9Sstevel@tonic-gate uint_t pentiumpro_bug4046376; 1077c478bd9Sstevel@tonic-gate uint_t pentiumpro_bug4064495; 1087c478bd9Sstevel@tonic-gate 1097c478bd9Sstevel@tonic-gate uint_t enable486; 1107c478bd9Sstevel@tonic-gate 1117c478bd9Sstevel@tonic-gate /* 1127c478bd9Sstevel@tonic-gate * This set of strings are for processors rumored to support the cpuid 1137c478bd9Sstevel@tonic-gate * instruction, and is used by locore.s to figure out how to set x86_vendor 1147c478bd9Sstevel@tonic-gate */ 1157c478bd9Sstevel@tonic-gate const char CyrixInstead[] = "CyrixInstead"; 1167c478bd9Sstevel@tonic-gate 1177c478bd9Sstevel@tonic-gate /* 118f98fbcecSbholler * monitor/mwait info. 119f98fbcecSbholler */ 120f98fbcecSbholler struct mwait_info { 121f98fbcecSbholler size_t mon_min; /* min size to avoid missed wakeups */ 122f98fbcecSbholler size_t mon_max; /* size to avoid false wakeups */ 123f98fbcecSbholler uint32_t support; /* processor support of monitor/mwait */ 124f98fbcecSbholler }; 125f98fbcecSbholler 126f98fbcecSbholler /* 1277c478bd9Sstevel@tonic-gate * These constants determine how many of the elements of the 1287c478bd9Sstevel@tonic-gate * cpuid we cache in the cpuid_info data structure; the 1297c478bd9Sstevel@tonic-gate * remaining elements are accessible via the cpuid instruction. 1307c478bd9Sstevel@tonic-gate */ 1317c478bd9Sstevel@tonic-gate 1327c478bd9Sstevel@tonic-gate #define NMAX_CPI_STD 6 /* eax = 0 .. 5 */ 1337c478bd9Sstevel@tonic-gate #define NMAX_CPI_EXTD 9 /* eax = 0x80000000 .. 0x80000008 */ 1347c478bd9Sstevel@tonic-gate 1357c478bd9Sstevel@tonic-gate struct cpuid_info { 1367c478bd9Sstevel@tonic-gate uint_t cpi_pass; /* last pass completed */ 1377c478bd9Sstevel@tonic-gate /* 1387c478bd9Sstevel@tonic-gate * standard function information 1397c478bd9Sstevel@tonic-gate */ 1407c478bd9Sstevel@tonic-gate uint_t cpi_maxeax; /* fn 0: %eax */ 1417c478bd9Sstevel@tonic-gate char cpi_vendorstr[13]; /* fn 0: %ebx:%ecx:%edx */ 1427c478bd9Sstevel@tonic-gate uint_t cpi_vendor; /* enum of cpi_vendorstr */ 1437c478bd9Sstevel@tonic-gate 1447c478bd9Sstevel@tonic-gate uint_t cpi_family; /* fn 1: extended family */ 1457c478bd9Sstevel@tonic-gate uint_t cpi_model; /* fn 1: extended model */ 1467c478bd9Sstevel@tonic-gate uint_t cpi_step; /* fn 1: stepping */ 1477c478bd9Sstevel@tonic-gate chipid_t cpi_chipid; /* fn 1: %ebx: chip # on ht cpus */ 1487c478bd9Sstevel@tonic-gate uint_t cpi_brandid; /* fn 1: %ebx: brand ID */ 1497c478bd9Sstevel@tonic-gate int cpi_clogid; /* fn 1: %ebx: thread # */ 1508949bcd6Sandrei uint_t cpi_ncpu_per_chip; /* fn 1: %ebx: logical cpu count */ 1517c478bd9Sstevel@tonic-gate uint8_t cpi_cacheinfo[16]; /* fn 2: intel-style cache desc */ 1527c478bd9Sstevel@tonic-gate uint_t cpi_ncache; /* fn 2: number of elements */ 153*d129bde2Sesaxe uint_t cpi_ncpu_shr_last_cache; /* fn 4: %eax: ncpus sharing cache */ 154*d129bde2Sesaxe id_t cpi_last_lvl_cacheid; /* fn 4: %eax: derived cache id */ 155*d129bde2Sesaxe uint_t cpi_std_4_size; /* fn 4: number of fn 4 elements */ 156*d129bde2Sesaxe struct cpuid_regs **cpi_std_4; /* fn 4: %ecx == 0 .. fn4_size */ 1578949bcd6Sandrei struct cpuid_regs cpi_std[NMAX_CPI_STD]; /* 0 .. 5 */ 1587c478bd9Sstevel@tonic-gate /* 1597c478bd9Sstevel@tonic-gate * extended function information 1607c478bd9Sstevel@tonic-gate */ 1617c478bd9Sstevel@tonic-gate uint_t cpi_xmaxeax; /* fn 0x80000000: %eax */ 1627c478bd9Sstevel@tonic-gate char cpi_brandstr[49]; /* fn 0x8000000[234] */ 1637c478bd9Sstevel@tonic-gate uint8_t cpi_pabits; /* fn 0x80000006: %eax */ 1647c478bd9Sstevel@tonic-gate uint8_t cpi_vabits; /* fn 0x80000006: %eax */ 1658949bcd6Sandrei struct cpuid_regs cpi_extd[NMAX_CPI_EXTD]; /* 0x8000000[0-8] */ 1668949bcd6Sandrei id_t cpi_coreid; 1678949bcd6Sandrei uint_t cpi_ncore_per_chip; /* AMD: fn 0x80000008: %ecx[7-0] */ 1688949bcd6Sandrei /* Intel: fn 4: %eax[31-26] */ 1697c478bd9Sstevel@tonic-gate /* 1707c478bd9Sstevel@tonic-gate * supported feature information 1717c478bd9Sstevel@tonic-gate */ 172ae115bc7Smrj uint32_t cpi_support[5]; 1737c478bd9Sstevel@tonic-gate #define STD_EDX_FEATURES 0 1747c478bd9Sstevel@tonic-gate #define AMD_EDX_FEATURES 1 1757c478bd9Sstevel@tonic-gate #define TM_EDX_FEATURES 2 1767c478bd9Sstevel@tonic-gate #define STD_ECX_FEATURES 3 177ae115bc7Smrj #define AMD_ECX_FEATURES 4 1788a40a695Sgavinm /* 1798a40a695Sgavinm * Synthesized information, where known. 1808a40a695Sgavinm */ 1818a40a695Sgavinm uint32_t cpi_chiprev; /* See X86_CHIPREV_* in x86_archext.h */ 1828a40a695Sgavinm const char *cpi_chiprevstr; /* May be NULL if chiprev unknown */ 1838a40a695Sgavinm uint32_t cpi_socket; /* Chip package/socket type */ 184f98fbcecSbholler 185f98fbcecSbholler struct mwait_info cpi_mwait; /* fn 5: monitor/mwait info */ 1867c478bd9Sstevel@tonic-gate }; 1877c478bd9Sstevel@tonic-gate 1887c478bd9Sstevel@tonic-gate 1897c478bd9Sstevel@tonic-gate static struct cpuid_info cpuid_info0; 1907c478bd9Sstevel@tonic-gate 1917c478bd9Sstevel@tonic-gate /* 1927c478bd9Sstevel@tonic-gate * These bit fields are defined by the Intel Application Note AP-485 1937c478bd9Sstevel@tonic-gate * "Intel Processor Identification and the CPUID Instruction" 1947c478bd9Sstevel@tonic-gate */ 1957c478bd9Sstevel@tonic-gate #define CPI_FAMILY_XTD(cpi) BITX((cpi)->cpi_std[1].cp_eax, 27, 20) 1967c478bd9Sstevel@tonic-gate #define CPI_MODEL_XTD(cpi) BITX((cpi)->cpi_std[1].cp_eax, 19, 16) 1977c478bd9Sstevel@tonic-gate #define CPI_TYPE(cpi) BITX((cpi)->cpi_std[1].cp_eax, 13, 12) 1987c478bd9Sstevel@tonic-gate #define CPI_FAMILY(cpi) BITX((cpi)->cpi_std[1].cp_eax, 11, 8) 1997c478bd9Sstevel@tonic-gate #define CPI_STEP(cpi) BITX((cpi)->cpi_std[1].cp_eax, 3, 0) 2007c478bd9Sstevel@tonic-gate #define CPI_MODEL(cpi) BITX((cpi)->cpi_std[1].cp_eax, 7, 4) 2017c478bd9Sstevel@tonic-gate 2027c478bd9Sstevel@tonic-gate #define CPI_FEATURES_EDX(cpi) ((cpi)->cpi_std[1].cp_edx) 2037c478bd9Sstevel@tonic-gate #define CPI_FEATURES_ECX(cpi) ((cpi)->cpi_std[1].cp_ecx) 2047c478bd9Sstevel@tonic-gate #define CPI_FEATURES_XTD_EDX(cpi) ((cpi)->cpi_extd[1].cp_edx) 2057c478bd9Sstevel@tonic-gate #define CPI_FEATURES_XTD_ECX(cpi) ((cpi)->cpi_extd[1].cp_ecx) 2067c478bd9Sstevel@tonic-gate 2077c478bd9Sstevel@tonic-gate #define CPI_BRANDID(cpi) BITX((cpi)->cpi_std[1].cp_ebx, 7, 0) 2087c478bd9Sstevel@tonic-gate #define CPI_CHUNKS(cpi) BITX((cpi)->cpi_std[1].cp_ebx, 15, 7) 2097c478bd9Sstevel@tonic-gate #define CPI_CPU_COUNT(cpi) BITX((cpi)->cpi_std[1].cp_ebx, 23, 16) 2107c478bd9Sstevel@tonic-gate #define CPI_APIC_ID(cpi) BITX((cpi)->cpi_std[1].cp_ebx, 31, 24) 2117c478bd9Sstevel@tonic-gate 2127c478bd9Sstevel@tonic-gate #define CPI_MAXEAX_MAX 0x100 /* sanity control */ 2137c478bd9Sstevel@tonic-gate #define CPI_XMAXEAX_MAX 0x80000100 214*d129bde2Sesaxe #define CPI_FN4_ECX_MAX 0x20 /* sanity: max fn 4 levels */ 215*d129bde2Sesaxe 216*d129bde2Sesaxe /* 217*d129bde2Sesaxe * Function 4 (Deterministic Cache Parameters) macros 218*d129bde2Sesaxe * Defined by Intel Application Note AP-485 219*d129bde2Sesaxe */ 220*d129bde2Sesaxe #define CPI_NUM_CORES(regs) BITX((regs)->cp_eax, 31, 26) 221*d129bde2Sesaxe #define CPI_NTHR_SHR_CACHE(regs) BITX((regs)->cp_eax, 25, 14) 222*d129bde2Sesaxe #define CPI_FULL_ASSOC_CACHE(regs) BITX((regs)->cp_eax, 9, 9) 223*d129bde2Sesaxe #define CPI_SELF_INIT_CACHE(regs) BITX((regs)->cp_eax, 8, 8) 224*d129bde2Sesaxe #define CPI_CACHE_LVL(regs) BITX((regs)->cp_eax, 7, 5) 225*d129bde2Sesaxe #define CPI_CACHE_TYPE(regs) BITX((regs)->cp_eax, 4, 0) 226*d129bde2Sesaxe 227*d129bde2Sesaxe #define CPI_CACHE_WAYS(regs) BITX((regs)->cp_ebx, 31, 22) 228*d129bde2Sesaxe #define CPI_CACHE_PARTS(regs) BITX((regs)->cp_ebx, 21, 12) 229*d129bde2Sesaxe #define CPI_CACHE_COH_LN_SZ(regs) BITX((regs)->cp_ebx, 11, 0) 230*d129bde2Sesaxe 231*d129bde2Sesaxe #define CPI_CACHE_SETS(regs) BITX((regs)->cp_ecx, 31, 0) 232*d129bde2Sesaxe 233*d129bde2Sesaxe #define CPI_PREFCH_STRIDE(regs) BITX((regs)->cp_edx, 9, 0) 234*d129bde2Sesaxe 2357c478bd9Sstevel@tonic-gate 2367c478bd9Sstevel@tonic-gate /* 2375ff02082Sdmick * A couple of shorthand macros to identify "later" P6-family chips 2385ff02082Sdmick * like the Pentium M and Core. First, the "older" P6-based stuff 2395ff02082Sdmick * (loosely defined as "pre-Pentium-4"): 2405ff02082Sdmick * P6, PII, Mobile PII, PII Xeon, PIII, Mobile PIII, PIII Xeon 2415ff02082Sdmick */ 2425ff02082Sdmick 2435ff02082Sdmick #define IS_LEGACY_P6(cpi) ( \ 2445ff02082Sdmick cpi->cpi_family == 6 && \ 2455ff02082Sdmick (cpi->cpi_model == 1 || \ 2465ff02082Sdmick cpi->cpi_model == 3 || \ 2475ff02082Sdmick cpi->cpi_model == 5 || \ 2485ff02082Sdmick cpi->cpi_model == 6 || \ 2495ff02082Sdmick cpi->cpi_model == 7 || \ 2505ff02082Sdmick cpi->cpi_model == 8 || \ 2515ff02082Sdmick cpi->cpi_model == 0xA || \ 2525ff02082Sdmick cpi->cpi_model == 0xB) \ 2535ff02082Sdmick ) 2545ff02082Sdmick 2555ff02082Sdmick /* A "new F6" is everything with family 6 that's not the above */ 2565ff02082Sdmick #define IS_NEW_F6(cpi) ((cpi->cpi_family == 6) && !IS_LEGACY_P6(cpi)) 2575ff02082Sdmick 2585ff02082Sdmick /* 2598a40a695Sgavinm * AMD family 0xf socket types. 2608a40a695Sgavinm * First index is 0 for revs B thru E, 1 for F and G. 2618a40a695Sgavinm * Second index by (model & 0x3) 2628a40a695Sgavinm */ 2638a40a695Sgavinm static uint32_t amd_skts[2][4] = { 2648a40a695Sgavinm { 2658a40a695Sgavinm X86_SOCKET_754, /* 0b00 */ 2668a40a695Sgavinm X86_SOCKET_940, /* 0b01 */ 2678a40a695Sgavinm X86_SOCKET_754, /* 0b10 */ 2688a40a695Sgavinm X86_SOCKET_939 /* 0b11 */ 2698a40a695Sgavinm }, 2708a40a695Sgavinm { 2718a40a695Sgavinm X86_SOCKET_S1g1, /* 0b00 */ 2728a40a695Sgavinm X86_SOCKET_F1207, /* 0b01 */ 2738a40a695Sgavinm X86_SOCKET_UNKNOWN, /* 0b10 */ 2748a40a695Sgavinm X86_SOCKET_AM2 /* 0b11 */ 2758a40a695Sgavinm } 2768a40a695Sgavinm }; 2778a40a695Sgavinm 2788a40a695Sgavinm /* 2798a40a695Sgavinm * Table for mapping AMD Family 0xf model/stepping combination to 2808a40a695Sgavinm * chip "revision" and socket type. Only rm_family 0xf is used at the 2818a40a695Sgavinm * moment, but AMD family 0x10 will extend the exsiting revision names 2828a40a695Sgavinm * so will likely also use this table. 2838a40a695Sgavinm * 2848a40a695Sgavinm * The first member of this array that matches a given family, extended model 2858a40a695Sgavinm * plus model range, and stepping range will be considered a match. 2868a40a695Sgavinm */ 2878a40a695Sgavinm static const struct amd_rev_mapent { 2888a40a695Sgavinm uint_t rm_family; 2898a40a695Sgavinm uint_t rm_modello; 2908a40a695Sgavinm uint_t rm_modelhi; 2918a40a695Sgavinm uint_t rm_steplo; 2928a40a695Sgavinm uint_t rm_stephi; 2938a40a695Sgavinm uint32_t rm_chiprev; 2948a40a695Sgavinm const char *rm_chiprevstr; 2958a40a695Sgavinm int rm_sktidx; 2968a40a695Sgavinm } amd_revmap[] = { 2978a40a695Sgavinm /* 2988a40a695Sgavinm * Rev B includes model 0x4 stepping 0 and model 0x5 stepping 0 and 1. 2998a40a695Sgavinm */ 3008a40a695Sgavinm { 0xf, 0x04, 0x04, 0x0, 0x0, X86_CHIPREV_AMD_F_REV_B, "B", 0 }, 3018a40a695Sgavinm { 0xf, 0x05, 0x05, 0x0, 0x1, X86_CHIPREV_AMD_F_REV_B, "B", 0 }, 3028a40a695Sgavinm /* 3038a40a695Sgavinm * Rev C0 includes model 0x4 stepping 8 and model 0x5 stepping 8 3048a40a695Sgavinm */ 3058a40a695Sgavinm { 0xf, 0x04, 0x05, 0x8, 0x8, X86_CHIPREV_AMD_F_REV_C0, "C0", 0 }, 3068a40a695Sgavinm /* 3078a40a695Sgavinm * Rev CG is the rest of extended model 0x0 - i.e., everything 3088a40a695Sgavinm * but the rev B and C0 combinations covered above. 3098a40a695Sgavinm */ 3108a40a695Sgavinm { 0xf, 0x00, 0x0f, 0x0, 0xf, X86_CHIPREV_AMD_F_REV_CG, "CG", 0 }, 3118a40a695Sgavinm /* 3128a40a695Sgavinm * Rev D has extended model 0x1. 3138a40a695Sgavinm */ 3148a40a695Sgavinm { 0xf, 0x10, 0x1f, 0x0, 0xf, X86_CHIPREV_AMD_F_REV_D, "D", 0 }, 3158a40a695Sgavinm /* 3168a40a695Sgavinm * Rev E has extended model 0x2. 3178a40a695Sgavinm * Extended model 0x3 is unused but available to grow into. 3188a40a695Sgavinm */ 3198a40a695Sgavinm { 0xf, 0x20, 0x3f, 0x0, 0xf, X86_CHIPREV_AMD_F_REV_E, "E", 0 }, 3208a40a695Sgavinm /* 3218a40a695Sgavinm * Rev F has extended models 0x4 and 0x5. 3228a40a695Sgavinm */ 3238a40a695Sgavinm { 0xf, 0x40, 0x5f, 0x0, 0xf, X86_CHIPREV_AMD_F_REV_F, "F", 1 }, 3248a40a695Sgavinm /* 3258a40a695Sgavinm * Rev G has extended model 0x6. 3268a40a695Sgavinm */ 3278a40a695Sgavinm { 0xf, 0x60, 0x6f, 0x0, 0xf, X86_CHIPREV_AMD_F_REV_G, "G", 1 }, 3288a40a695Sgavinm }; 3298a40a695Sgavinm 330f98fbcecSbholler /* 331f98fbcecSbholler * Info for monitor/mwait idle loop. 332f98fbcecSbholler * 333f98fbcecSbholler * See cpuid section of "Intel 64 and IA-32 Architectures Software Developer's 334f98fbcecSbholler * Manual Volume 2A: Instruction Set Reference, A-M" #25366-022US, November 335f98fbcecSbholler * 2006. 336f98fbcecSbholler * See MONITOR/MWAIT section of "AMD64 Architecture Programmer's Manual 337f98fbcecSbholler * Documentation Updates" #33633, Rev 2.05, December 2006. 338f98fbcecSbholler */ 339f98fbcecSbholler #define MWAIT_SUPPORT (0x00000001) /* mwait supported */ 340f98fbcecSbholler #define MWAIT_EXTENSIONS (0x00000002) /* extenstion supported */ 341f98fbcecSbholler #define MWAIT_ECX_INT_ENABLE (0x00000004) /* ecx 1 extension supported */ 342f98fbcecSbholler #define MWAIT_SUPPORTED(cpi) ((cpi)->cpi_std[1].cp_ecx & CPUID_INTC_ECX_MON) 343f98fbcecSbholler #define MWAIT_INT_ENABLE(cpi) ((cpi)->cpi_std[5].cp_ecx & 0x2) 344f98fbcecSbholler #define MWAIT_EXTENSION(cpi) ((cpi)->cpi_std[5].cp_ecx & 0x1) 345f98fbcecSbholler #define MWAIT_SIZE_MIN(cpi) BITX((cpi)->cpi_std[5].cp_eax, 15, 0) 346f98fbcecSbholler #define MWAIT_SIZE_MAX(cpi) BITX((cpi)->cpi_std[5].cp_ebx, 15, 0) 347f98fbcecSbholler /* 348f98fbcecSbholler * Number of sub-cstates for a given c-state. 349f98fbcecSbholler */ 350f98fbcecSbholler #define MWAIT_NUM_SUBC_STATES(cpi, c_state) \ 351f98fbcecSbholler BITX((cpi)->cpi_std[5].cp_edx, c_state + 3, c_state) 352f98fbcecSbholler 3538a40a695Sgavinm static void 3548a40a695Sgavinm synth_amd_info(struct cpuid_info *cpi) 3558a40a695Sgavinm { 3568a40a695Sgavinm const struct amd_rev_mapent *rmp; 3578a40a695Sgavinm uint_t family, model, step; 3588a40a695Sgavinm int i; 3598a40a695Sgavinm 3608a40a695Sgavinm /* 3618a40a695Sgavinm * Currently only AMD family 0xf uses these fields. 3628a40a695Sgavinm */ 3638a40a695Sgavinm if (cpi->cpi_family != 0xf) 3648a40a695Sgavinm return; 3658a40a695Sgavinm 3668a40a695Sgavinm family = cpi->cpi_family; 3678a40a695Sgavinm model = cpi->cpi_model; 3688a40a695Sgavinm step = cpi->cpi_step; 3698a40a695Sgavinm 3708a40a695Sgavinm for (i = 0, rmp = amd_revmap; i < sizeof (amd_revmap) / sizeof (*rmp); 3718a40a695Sgavinm i++, rmp++) { 3728a40a695Sgavinm if (family == rmp->rm_family && 3738a40a695Sgavinm model >= rmp->rm_modello && model <= rmp->rm_modelhi && 3748a40a695Sgavinm step >= rmp->rm_steplo && step <= rmp->rm_stephi) { 3758a40a695Sgavinm cpi->cpi_chiprev = rmp->rm_chiprev; 3768a40a695Sgavinm cpi->cpi_chiprevstr = rmp->rm_chiprevstr; 3778a40a695Sgavinm cpi->cpi_socket = amd_skts[rmp->rm_sktidx][model & 0x3]; 3788a40a695Sgavinm return; 3798a40a695Sgavinm } 3808a40a695Sgavinm } 3818a40a695Sgavinm } 3828a40a695Sgavinm 3838a40a695Sgavinm static void 3848a40a695Sgavinm synth_info(struct cpuid_info *cpi) 3858a40a695Sgavinm { 3868a40a695Sgavinm cpi->cpi_chiprev = X86_CHIPREV_UNKNOWN; 3878a40a695Sgavinm cpi->cpi_chiprevstr = "Unknown"; 3888a40a695Sgavinm cpi->cpi_socket = X86_SOCKET_UNKNOWN; 3898a40a695Sgavinm 3908a40a695Sgavinm switch (cpi->cpi_vendor) { 3918a40a695Sgavinm case X86_VENDOR_AMD: 3928a40a695Sgavinm synth_amd_info(cpi); 3938a40a695Sgavinm break; 3948a40a695Sgavinm 3958a40a695Sgavinm default: 3968a40a695Sgavinm break; 3978a40a695Sgavinm 3988a40a695Sgavinm } 3998a40a695Sgavinm } 4008a40a695Sgavinm 4018a40a695Sgavinm /* 402ae115bc7Smrj * Apply up various platform-dependent restrictions where the 403ae115bc7Smrj * underlying platform restrictions mean the CPU can be marked 404ae115bc7Smrj * as less capable than its cpuid instruction would imply. 405ae115bc7Smrj */ 406ae115bc7Smrj 407ae115bc7Smrj #define platform_cpuid_mangle(vendor, eax, cp) /* nothing */ 408ae115bc7Smrj 409ae115bc7Smrj /* 4107c478bd9Sstevel@tonic-gate * Some undocumented ways of patching the results of the cpuid 4117c478bd9Sstevel@tonic-gate * instruction to permit running Solaris 10 on future cpus that 4127c478bd9Sstevel@tonic-gate * we don't currently support. Could be set to non-zero values 4137c478bd9Sstevel@tonic-gate * via settings in eeprom. 4147c478bd9Sstevel@tonic-gate */ 4157c478bd9Sstevel@tonic-gate 4167c478bd9Sstevel@tonic-gate uint32_t cpuid_feature_ecx_include; 4177c478bd9Sstevel@tonic-gate uint32_t cpuid_feature_ecx_exclude; 4187c478bd9Sstevel@tonic-gate uint32_t cpuid_feature_edx_include; 4197c478bd9Sstevel@tonic-gate uint32_t cpuid_feature_edx_exclude; 4207c478bd9Sstevel@tonic-gate 421ae115bc7Smrj void 422ae115bc7Smrj cpuid_alloc_space(cpu_t *cpu) 423ae115bc7Smrj { 424ae115bc7Smrj /* 425ae115bc7Smrj * By convention, cpu0 is the boot cpu, which is set up 426ae115bc7Smrj * before memory allocation is available. All other cpus get 427ae115bc7Smrj * their cpuid_info struct allocated here. 428ae115bc7Smrj */ 429ae115bc7Smrj ASSERT(cpu->cpu_id != 0); 430ae115bc7Smrj cpu->cpu_m.mcpu_cpi = 431ae115bc7Smrj kmem_zalloc(sizeof (*cpu->cpu_m.mcpu_cpi), KM_SLEEP); 432ae115bc7Smrj } 433ae115bc7Smrj 434ae115bc7Smrj void 435ae115bc7Smrj cpuid_free_space(cpu_t *cpu) 436ae115bc7Smrj { 437*d129bde2Sesaxe struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 438*d129bde2Sesaxe int i; 439*d129bde2Sesaxe 440ae115bc7Smrj ASSERT(cpu->cpu_id != 0); 441*d129bde2Sesaxe 442*d129bde2Sesaxe /* 443*d129bde2Sesaxe * Free up any function 4 related dynamic storage 444*d129bde2Sesaxe */ 445*d129bde2Sesaxe for (i = 1; i < cpi->cpi_std_4_size; i++) 446*d129bde2Sesaxe kmem_free(cpi->cpi_std_4[i], sizeof (struct cpuid_regs)); 447*d129bde2Sesaxe if (cpi->cpi_std_4_size > 0) 448*d129bde2Sesaxe kmem_free(cpi->cpi_std_4, 449*d129bde2Sesaxe cpi->cpi_std_4_size * sizeof (struct cpuid_regs *)); 450*d129bde2Sesaxe 451ae115bc7Smrj kmem_free(cpu->cpu_m.mcpu_cpi, sizeof (*cpu->cpu_m.mcpu_cpi)); 452ae115bc7Smrj } 453ae115bc7Smrj 4547c478bd9Sstevel@tonic-gate uint_t 4557c478bd9Sstevel@tonic-gate cpuid_pass1(cpu_t *cpu) 4567c478bd9Sstevel@tonic-gate { 4577c478bd9Sstevel@tonic-gate uint32_t mask_ecx, mask_edx; 4587c478bd9Sstevel@tonic-gate uint_t feature = X86_CPUID; 4597c478bd9Sstevel@tonic-gate struct cpuid_info *cpi; 4608949bcd6Sandrei struct cpuid_regs *cp; 4617c478bd9Sstevel@tonic-gate int xcpuid; 4627c478bd9Sstevel@tonic-gate 463ae115bc7Smrj 4647c478bd9Sstevel@tonic-gate /* 465ae115bc7Smrj * Space statically allocated for cpu0, ensure pointer is set 4667c478bd9Sstevel@tonic-gate */ 4677c478bd9Sstevel@tonic-gate if (cpu->cpu_id == 0) 468ae115bc7Smrj cpu->cpu_m.mcpu_cpi = &cpuid_info0; 469ae115bc7Smrj cpi = cpu->cpu_m.mcpu_cpi; 470ae115bc7Smrj ASSERT(cpi != NULL); 4717c478bd9Sstevel@tonic-gate cp = &cpi->cpi_std[0]; 4728949bcd6Sandrei cp->cp_eax = 0; 4738949bcd6Sandrei cpi->cpi_maxeax = __cpuid_insn(cp); 4747c478bd9Sstevel@tonic-gate { 4757c478bd9Sstevel@tonic-gate uint32_t *iptr = (uint32_t *)cpi->cpi_vendorstr; 4767c478bd9Sstevel@tonic-gate *iptr++ = cp->cp_ebx; 4777c478bd9Sstevel@tonic-gate *iptr++ = cp->cp_edx; 4787c478bd9Sstevel@tonic-gate *iptr++ = cp->cp_ecx; 4797c478bd9Sstevel@tonic-gate *(char *)&cpi->cpi_vendorstr[12] = '\0'; 4807c478bd9Sstevel@tonic-gate } 4817c478bd9Sstevel@tonic-gate 4827c478bd9Sstevel@tonic-gate /* 4837c478bd9Sstevel@tonic-gate * Map the vendor string to a type code 4847c478bd9Sstevel@tonic-gate */ 4857c478bd9Sstevel@tonic-gate if (strcmp(cpi->cpi_vendorstr, "GenuineIntel") == 0) 4867c478bd9Sstevel@tonic-gate cpi->cpi_vendor = X86_VENDOR_Intel; 4877c478bd9Sstevel@tonic-gate else if (strcmp(cpi->cpi_vendorstr, "AuthenticAMD") == 0) 4887c478bd9Sstevel@tonic-gate cpi->cpi_vendor = X86_VENDOR_AMD; 4897c478bd9Sstevel@tonic-gate else if (strcmp(cpi->cpi_vendorstr, "GenuineTMx86") == 0) 4907c478bd9Sstevel@tonic-gate cpi->cpi_vendor = X86_VENDOR_TM; 4917c478bd9Sstevel@tonic-gate else if (strcmp(cpi->cpi_vendorstr, CyrixInstead) == 0) 4927c478bd9Sstevel@tonic-gate /* 4937c478bd9Sstevel@tonic-gate * CyrixInstead is a variable used by the Cyrix detection code 4947c478bd9Sstevel@tonic-gate * in locore. 4957c478bd9Sstevel@tonic-gate */ 4967c478bd9Sstevel@tonic-gate cpi->cpi_vendor = X86_VENDOR_Cyrix; 4977c478bd9Sstevel@tonic-gate else if (strcmp(cpi->cpi_vendorstr, "UMC UMC UMC ") == 0) 4987c478bd9Sstevel@tonic-gate cpi->cpi_vendor = X86_VENDOR_UMC; 4997c478bd9Sstevel@tonic-gate else if (strcmp(cpi->cpi_vendorstr, "NexGenDriven") == 0) 5007c478bd9Sstevel@tonic-gate cpi->cpi_vendor = X86_VENDOR_NexGen; 5017c478bd9Sstevel@tonic-gate else if (strcmp(cpi->cpi_vendorstr, "CentaurHauls") == 0) 5027c478bd9Sstevel@tonic-gate cpi->cpi_vendor = X86_VENDOR_Centaur; 5037c478bd9Sstevel@tonic-gate else if (strcmp(cpi->cpi_vendorstr, "RiseRiseRise") == 0) 5047c478bd9Sstevel@tonic-gate cpi->cpi_vendor = X86_VENDOR_Rise; 5057c478bd9Sstevel@tonic-gate else if (strcmp(cpi->cpi_vendorstr, "SiS SiS SiS ") == 0) 5067c478bd9Sstevel@tonic-gate cpi->cpi_vendor = X86_VENDOR_SiS; 5077c478bd9Sstevel@tonic-gate else if (strcmp(cpi->cpi_vendorstr, "Geode by NSC") == 0) 5087c478bd9Sstevel@tonic-gate cpi->cpi_vendor = X86_VENDOR_NSC; 5097c478bd9Sstevel@tonic-gate else 5107c478bd9Sstevel@tonic-gate cpi->cpi_vendor = X86_VENDOR_IntelClone; 5117c478bd9Sstevel@tonic-gate 5127c478bd9Sstevel@tonic-gate x86_vendor = cpi->cpi_vendor; /* for compatibility */ 5137c478bd9Sstevel@tonic-gate 5147c478bd9Sstevel@tonic-gate /* 5157c478bd9Sstevel@tonic-gate * Limit the range in case of weird hardware 5167c478bd9Sstevel@tonic-gate */ 5177c478bd9Sstevel@tonic-gate if (cpi->cpi_maxeax > CPI_MAXEAX_MAX) 5187c478bd9Sstevel@tonic-gate cpi->cpi_maxeax = CPI_MAXEAX_MAX; 5197c478bd9Sstevel@tonic-gate if (cpi->cpi_maxeax < 1) 5207c478bd9Sstevel@tonic-gate goto pass1_done; 5217c478bd9Sstevel@tonic-gate 5227c478bd9Sstevel@tonic-gate cp = &cpi->cpi_std[1]; 5238949bcd6Sandrei cp->cp_eax = 1; 5248949bcd6Sandrei (void) __cpuid_insn(cp); 5257c478bd9Sstevel@tonic-gate 5267c478bd9Sstevel@tonic-gate /* 5277c478bd9Sstevel@tonic-gate * Extract identifying constants for easy access. 5287c478bd9Sstevel@tonic-gate */ 5297c478bd9Sstevel@tonic-gate cpi->cpi_model = CPI_MODEL(cpi); 5307c478bd9Sstevel@tonic-gate cpi->cpi_family = CPI_FAMILY(cpi); 5317c478bd9Sstevel@tonic-gate 5325ff02082Sdmick if (cpi->cpi_family == 0xf) 5337c478bd9Sstevel@tonic-gate cpi->cpi_family += CPI_FAMILY_XTD(cpi); 5345ff02082Sdmick 53568c91426Sdmick /* 536875b116eSkchow * Beware: AMD uses "extended model" iff base *FAMILY* == 0xf. 53768c91426Sdmick * Intel, and presumably everyone else, uses model == 0xf, as 53868c91426Sdmick * one would expect (max value means possible overflow). Sigh. 53968c91426Sdmick */ 54068c91426Sdmick 54168c91426Sdmick switch (cpi->cpi_vendor) { 54268c91426Sdmick case X86_VENDOR_AMD: 543875b116eSkchow if (CPI_FAMILY(cpi) == 0xf) 54468c91426Sdmick cpi->cpi_model += CPI_MODEL_XTD(cpi) << 4; 54568c91426Sdmick break; 54668c91426Sdmick default: 5475ff02082Sdmick if (cpi->cpi_model == 0xf) 5487c478bd9Sstevel@tonic-gate cpi->cpi_model += CPI_MODEL_XTD(cpi) << 4; 54968c91426Sdmick break; 55068c91426Sdmick } 5517c478bd9Sstevel@tonic-gate 5527c478bd9Sstevel@tonic-gate cpi->cpi_step = CPI_STEP(cpi); 5537c478bd9Sstevel@tonic-gate cpi->cpi_brandid = CPI_BRANDID(cpi); 5547c478bd9Sstevel@tonic-gate 5557c478bd9Sstevel@tonic-gate /* 5567c478bd9Sstevel@tonic-gate * *default* assumptions: 5577c478bd9Sstevel@tonic-gate * - believe %edx feature word 5587c478bd9Sstevel@tonic-gate * - ignore %ecx feature word 5597c478bd9Sstevel@tonic-gate * - 32-bit virtual and physical addressing 5607c478bd9Sstevel@tonic-gate */ 5617c478bd9Sstevel@tonic-gate mask_edx = 0xffffffff; 5627c478bd9Sstevel@tonic-gate mask_ecx = 0; 5637c478bd9Sstevel@tonic-gate 5647c478bd9Sstevel@tonic-gate cpi->cpi_pabits = cpi->cpi_vabits = 32; 5657c478bd9Sstevel@tonic-gate 5667c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 5677c478bd9Sstevel@tonic-gate case X86_VENDOR_Intel: 5687c478bd9Sstevel@tonic-gate if (cpi->cpi_family == 5) 5697c478bd9Sstevel@tonic-gate x86_type = X86_TYPE_P5; 5705ff02082Sdmick else if (IS_LEGACY_P6(cpi)) { 5717c478bd9Sstevel@tonic-gate x86_type = X86_TYPE_P6; 5727c478bd9Sstevel@tonic-gate pentiumpro_bug4046376 = 1; 5737c478bd9Sstevel@tonic-gate pentiumpro_bug4064495 = 1; 5747c478bd9Sstevel@tonic-gate /* 5757c478bd9Sstevel@tonic-gate * Clear the SEP bit when it was set erroneously 5767c478bd9Sstevel@tonic-gate */ 5777c478bd9Sstevel@tonic-gate if (cpi->cpi_model < 3 && cpi->cpi_step < 3) 5787c478bd9Sstevel@tonic-gate cp->cp_edx &= ~CPUID_INTC_EDX_SEP; 5795ff02082Sdmick } else if (IS_NEW_F6(cpi) || cpi->cpi_family == 0xf) { 5807c478bd9Sstevel@tonic-gate x86_type = X86_TYPE_P4; 5817c478bd9Sstevel@tonic-gate /* 5827c478bd9Sstevel@tonic-gate * We don't currently depend on any of the %ecx 5837c478bd9Sstevel@tonic-gate * features until Prescott, so we'll only check 5847c478bd9Sstevel@tonic-gate * this from P4 onwards. We might want to revisit 5857c478bd9Sstevel@tonic-gate * that idea later. 5867c478bd9Sstevel@tonic-gate */ 5877c478bd9Sstevel@tonic-gate mask_ecx = 0xffffffff; 5887c478bd9Sstevel@tonic-gate } else if (cpi->cpi_family > 0xf) 5897c478bd9Sstevel@tonic-gate mask_ecx = 0xffffffff; 5907c478bd9Sstevel@tonic-gate break; 5917c478bd9Sstevel@tonic-gate case X86_VENDOR_IntelClone: 5927c478bd9Sstevel@tonic-gate default: 5937c478bd9Sstevel@tonic-gate break; 5947c478bd9Sstevel@tonic-gate case X86_VENDOR_AMD: 5957c478bd9Sstevel@tonic-gate #if defined(OPTERON_ERRATUM_108) 5967c478bd9Sstevel@tonic-gate if (cpi->cpi_family == 0xf && cpi->cpi_model == 0xe) { 5977c478bd9Sstevel@tonic-gate cp->cp_eax = (0xf0f & cp->cp_eax) | 0xc0; 5987c478bd9Sstevel@tonic-gate cpi->cpi_model = 0xc; 5997c478bd9Sstevel@tonic-gate } else 6007c478bd9Sstevel@tonic-gate #endif 6017c478bd9Sstevel@tonic-gate if (cpi->cpi_family == 5) { 6027c478bd9Sstevel@tonic-gate /* 6037c478bd9Sstevel@tonic-gate * AMD K5 and K6 6047c478bd9Sstevel@tonic-gate * 6057c478bd9Sstevel@tonic-gate * These CPUs have an incomplete implementation 6067c478bd9Sstevel@tonic-gate * of MCA/MCE which we mask away. 6077c478bd9Sstevel@tonic-gate */ 6088949bcd6Sandrei mask_edx &= ~(CPUID_INTC_EDX_MCE | CPUID_INTC_EDX_MCA); 6098949bcd6Sandrei 6107c478bd9Sstevel@tonic-gate /* 6117c478bd9Sstevel@tonic-gate * Model 0 uses the wrong (APIC) bit 6127c478bd9Sstevel@tonic-gate * to indicate PGE. Fix it here. 6137c478bd9Sstevel@tonic-gate */ 6148949bcd6Sandrei if (cpi->cpi_model == 0) { 6157c478bd9Sstevel@tonic-gate if (cp->cp_edx & 0x200) { 6167c478bd9Sstevel@tonic-gate cp->cp_edx &= ~0x200; 6177c478bd9Sstevel@tonic-gate cp->cp_edx |= CPUID_INTC_EDX_PGE; 6187c478bd9Sstevel@tonic-gate } 6197c478bd9Sstevel@tonic-gate } 6208949bcd6Sandrei 6218949bcd6Sandrei /* 6228949bcd6Sandrei * Early models had problems w/ MMX; disable. 6238949bcd6Sandrei */ 6248949bcd6Sandrei if (cpi->cpi_model < 6) 6258949bcd6Sandrei mask_edx &= ~CPUID_INTC_EDX_MMX; 6268949bcd6Sandrei } 6278949bcd6Sandrei 6288949bcd6Sandrei /* 6298949bcd6Sandrei * For newer families, SSE3 and CX16, at least, are valid; 6308949bcd6Sandrei * enable all 6318949bcd6Sandrei */ 6328949bcd6Sandrei if (cpi->cpi_family >= 0xf) 6338949bcd6Sandrei mask_ecx = 0xffffffff; 6347c478bd9Sstevel@tonic-gate break; 6357c478bd9Sstevel@tonic-gate case X86_VENDOR_TM: 6367c478bd9Sstevel@tonic-gate /* 6377c478bd9Sstevel@tonic-gate * workaround the NT workaround in CMS 4.1 6387c478bd9Sstevel@tonic-gate */ 6397c478bd9Sstevel@tonic-gate if (cpi->cpi_family == 5 && cpi->cpi_model == 4 && 6407c478bd9Sstevel@tonic-gate (cpi->cpi_step == 2 || cpi->cpi_step == 3)) 6417c478bd9Sstevel@tonic-gate cp->cp_edx |= CPUID_INTC_EDX_CX8; 6427c478bd9Sstevel@tonic-gate break; 6437c478bd9Sstevel@tonic-gate case X86_VENDOR_Centaur: 6447c478bd9Sstevel@tonic-gate /* 6457c478bd9Sstevel@tonic-gate * workaround the NT workarounds again 6467c478bd9Sstevel@tonic-gate */ 6477c478bd9Sstevel@tonic-gate if (cpi->cpi_family == 6) 6487c478bd9Sstevel@tonic-gate cp->cp_edx |= CPUID_INTC_EDX_CX8; 6497c478bd9Sstevel@tonic-gate break; 6507c478bd9Sstevel@tonic-gate case X86_VENDOR_Cyrix: 6517c478bd9Sstevel@tonic-gate /* 6527c478bd9Sstevel@tonic-gate * We rely heavily on the probing in locore 6537c478bd9Sstevel@tonic-gate * to actually figure out what parts, if any, 6547c478bd9Sstevel@tonic-gate * of the Cyrix cpuid instruction to believe. 6557c478bd9Sstevel@tonic-gate */ 6567c478bd9Sstevel@tonic-gate switch (x86_type) { 6577c478bd9Sstevel@tonic-gate case X86_TYPE_CYRIX_486: 6587c478bd9Sstevel@tonic-gate mask_edx = 0; 6597c478bd9Sstevel@tonic-gate break; 6607c478bd9Sstevel@tonic-gate case X86_TYPE_CYRIX_6x86: 6617c478bd9Sstevel@tonic-gate mask_edx = 0; 6627c478bd9Sstevel@tonic-gate break; 6637c478bd9Sstevel@tonic-gate case X86_TYPE_CYRIX_6x86L: 6647c478bd9Sstevel@tonic-gate mask_edx = 6657c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_DE | 6667c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_CX8; 6677c478bd9Sstevel@tonic-gate break; 6687c478bd9Sstevel@tonic-gate case X86_TYPE_CYRIX_6x86MX: 6697c478bd9Sstevel@tonic-gate mask_edx = 6707c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_DE | 6717c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_MSR | 6727c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_CX8 | 6737c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_PGE | 6747c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_CMOV | 6757c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_MMX; 6767c478bd9Sstevel@tonic-gate break; 6777c478bd9Sstevel@tonic-gate case X86_TYPE_CYRIX_GXm: 6787c478bd9Sstevel@tonic-gate mask_edx = 6797c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_MSR | 6807c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_CX8 | 6817c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_CMOV | 6827c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_MMX; 6837c478bd9Sstevel@tonic-gate break; 6847c478bd9Sstevel@tonic-gate case X86_TYPE_CYRIX_MediaGX: 6857c478bd9Sstevel@tonic-gate break; 6867c478bd9Sstevel@tonic-gate case X86_TYPE_CYRIX_MII: 6877c478bd9Sstevel@tonic-gate case X86_TYPE_VIA_CYRIX_III: 6887c478bd9Sstevel@tonic-gate mask_edx = 6897c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_DE | 6907c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_TSC | 6917c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_MSR | 6927c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_CX8 | 6937c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_PGE | 6947c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_CMOV | 6957c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_MMX; 6967c478bd9Sstevel@tonic-gate break; 6977c478bd9Sstevel@tonic-gate default: 6987c478bd9Sstevel@tonic-gate break; 6997c478bd9Sstevel@tonic-gate } 7007c478bd9Sstevel@tonic-gate break; 7017c478bd9Sstevel@tonic-gate } 7027c478bd9Sstevel@tonic-gate 7037c478bd9Sstevel@tonic-gate /* 7047c478bd9Sstevel@tonic-gate * Now we've figured out the masks that determine 7057c478bd9Sstevel@tonic-gate * which bits we choose to believe, apply the masks 7067c478bd9Sstevel@tonic-gate * to the feature words, then map the kernel's view 7077c478bd9Sstevel@tonic-gate * of these feature words into its feature word. 7087c478bd9Sstevel@tonic-gate */ 7097c478bd9Sstevel@tonic-gate cp->cp_edx &= mask_edx; 7107c478bd9Sstevel@tonic-gate cp->cp_ecx &= mask_ecx; 7117c478bd9Sstevel@tonic-gate 7127c478bd9Sstevel@tonic-gate /* 713ae115bc7Smrj * apply any platform restrictions (we don't call this 714ae115bc7Smrj * immediately after __cpuid_insn here, because we need the 715ae115bc7Smrj * workarounds applied above first) 7167c478bd9Sstevel@tonic-gate */ 717ae115bc7Smrj platform_cpuid_mangle(cpi->cpi_vendor, 1, cp); 7187c478bd9Sstevel@tonic-gate 719ae115bc7Smrj /* 720ae115bc7Smrj * fold in overrides from the "eeprom" mechanism 721ae115bc7Smrj */ 7227c478bd9Sstevel@tonic-gate cp->cp_edx |= cpuid_feature_edx_include; 7237c478bd9Sstevel@tonic-gate cp->cp_edx &= ~cpuid_feature_edx_exclude; 7247c478bd9Sstevel@tonic-gate 7257c478bd9Sstevel@tonic-gate cp->cp_ecx |= cpuid_feature_ecx_include; 7267c478bd9Sstevel@tonic-gate cp->cp_ecx &= ~cpuid_feature_ecx_exclude; 7277c478bd9Sstevel@tonic-gate 7287c478bd9Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_PSE) 7297c478bd9Sstevel@tonic-gate feature |= X86_LARGEPAGE; 7307c478bd9Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_TSC) 7317c478bd9Sstevel@tonic-gate feature |= X86_TSC; 7327c478bd9Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_MSR) 7337c478bd9Sstevel@tonic-gate feature |= X86_MSR; 7347c478bd9Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_MTRR) 7357c478bd9Sstevel@tonic-gate feature |= X86_MTRR; 7367c478bd9Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_PGE) 7377c478bd9Sstevel@tonic-gate feature |= X86_PGE; 7387c478bd9Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_CMOV) 7397c478bd9Sstevel@tonic-gate feature |= X86_CMOV; 7407c478bd9Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_MMX) 7417c478bd9Sstevel@tonic-gate feature |= X86_MMX; 7427c478bd9Sstevel@tonic-gate if ((cp->cp_edx & CPUID_INTC_EDX_MCE) != 0 && 7437c478bd9Sstevel@tonic-gate (cp->cp_edx & CPUID_INTC_EDX_MCA) != 0) 7447c478bd9Sstevel@tonic-gate feature |= X86_MCA; 7457c478bd9Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_PAE) 7467c478bd9Sstevel@tonic-gate feature |= X86_PAE; 7477c478bd9Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_CX8) 7487c478bd9Sstevel@tonic-gate feature |= X86_CX8; 7497c478bd9Sstevel@tonic-gate if (cp->cp_ecx & CPUID_INTC_ECX_CX16) 7507c478bd9Sstevel@tonic-gate feature |= X86_CX16; 7517c478bd9Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_PAT) 7527c478bd9Sstevel@tonic-gate feature |= X86_PAT; 7537c478bd9Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_SEP) 7547c478bd9Sstevel@tonic-gate feature |= X86_SEP; 7557c478bd9Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_FXSR) { 7567c478bd9Sstevel@tonic-gate /* 7577c478bd9Sstevel@tonic-gate * In our implementation, fxsave/fxrstor 7587c478bd9Sstevel@tonic-gate * are prerequisites before we'll even 7597c478bd9Sstevel@tonic-gate * try and do SSE things. 7607c478bd9Sstevel@tonic-gate */ 7617c478bd9Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_SSE) 7627c478bd9Sstevel@tonic-gate feature |= X86_SSE; 7637c478bd9Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_SSE2) 7647c478bd9Sstevel@tonic-gate feature |= X86_SSE2; 7657c478bd9Sstevel@tonic-gate if (cp->cp_ecx & CPUID_INTC_ECX_SSE3) 7667c478bd9Sstevel@tonic-gate feature |= X86_SSE3; 7677c478bd9Sstevel@tonic-gate } 7687c478bd9Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_DE) 769ae115bc7Smrj feature |= X86_DE; 770f98fbcecSbholler if (cp->cp_ecx & CPUID_INTC_ECX_MON) { 771f98fbcecSbholler cpi->cpi_mwait.support |= MWAIT_SUPPORT; 772f98fbcecSbholler feature |= X86_MWAIT; 773f98fbcecSbholler } 7747c478bd9Sstevel@tonic-gate 7757c478bd9Sstevel@tonic-gate if (feature & X86_PAE) 7767c478bd9Sstevel@tonic-gate cpi->cpi_pabits = 36; 7777c478bd9Sstevel@tonic-gate 7787c478bd9Sstevel@tonic-gate /* 7797c478bd9Sstevel@tonic-gate * Hyperthreading configuration is slightly tricky on Intel 7807c478bd9Sstevel@tonic-gate * and pure clones, and even trickier on AMD. 7817c478bd9Sstevel@tonic-gate * 7827c478bd9Sstevel@tonic-gate * (AMD chose to set the HTT bit on their CMP processors, 7837c478bd9Sstevel@tonic-gate * even though they're not actually hyperthreaded. Thus it 7847c478bd9Sstevel@tonic-gate * takes a bit more work to figure out what's really going 785ae115bc7Smrj * on ... see the handling of the CMP_LGCY bit below) 7867c478bd9Sstevel@tonic-gate */ 7877c478bd9Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_HTT) { 7887c478bd9Sstevel@tonic-gate cpi->cpi_ncpu_per_chip = CPI_CPU_COUNT(cpi); 7897c478bd9Sstevel@tonic-gate if (cpi->cpi_ncpu_per_chip > 1) 7907c478bd9Sstevel@tonic-gate feature |= X86_HTT; 7918949bcd6Sandrei } else { 7928949bcd6Sandrei cpi->cpi_ncpu_per_chip = 1; 7937c478bd9Sstevel@tonic-gate } 7947c478bd9Sstevel@tonic-gate 7957c478bd9Sstevel@tonic-gate /* 7967c478bd9Sstevel@tonic-gate * Work on the "extended" feature information, doing 7977c478bd9Sstevel@tonic-gate * some basic initialization for cpuid_pass2() 7987c478bd9Sstevel@tonic-gate */ 7997c478bd9Sstevel@tonic-gate xcpuid = 0; 8007c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 8017c478bd9Sstevel@tonic-gate case X86_VENDOR_Intel: 8025ff02082Sdmick if (IS_NEW_F6(cpi) || cpi->cpi_family >= 0xf) 8037c478bd9Sstevel@tonic-gate xcpuid++; 8047c478bd9Sstevel@tonic-gate break; 8057c478bd9Sstevel@tonic-gate case X86_VENDOR_AMD: 8067c478bd9Sstevel@tonic-gate if (cpi->cpi_family > 5 || 8077c478bd9Sstevel@tonic-gate (cpi->cpi_family == 5 && cpi->cpi_model >= 1)) 8087c478bd9Sstevel@tonic-gate xcpuid++; 8097c478bd9Sstevel@tonic-gate break; 8107c478bd9Sstevel@tonic-gate case X86_VENDOR_Cyrix: 8117c478bd9Sstevel@tonic-gate /* 8127c478bd9Sstevel@tonic-gate * Only these Cyrix CPUs are -known- to support 8137c478bd9Sstevel@tonic-gate * extended cpuid operations. 8147c478bd9Sstevel@tonic-gate */ 8157c478bd9Sstevel@tonic-gate if (x86_type == X86_TYPE_VIA_CYRIX_III || 8167c478bd9Sstevel@tonic-gate x86_type == X86_TYPE_CYRIX_GXm) 8177c478bd9Sstevel@tonic-gate xcpuid++; 8187c478bd9Sstevel@tonic-gate break; 8197c478bd9Sstevel@tonic-gate case X86_VENDOR_Centaur: 8207c478bd9Sstevel@tonic-gate case X86_VENDOR_TM: 8217c478bd9Sstevel@tonic-gate default: 8227c478bd9Sstevel@tonic-gate xcpuid++; 8237c478bd9Sstevel@tonic-gate break; 8247c478bd9Sstevel@tonic-gate } 8257c478bd9Sstevel@tonic-gate 8267c478bd9Sstevel@tonic-gate if (xcpuid) { 8277c478bd9Sstevel@tonic-gate cp = &cpi->cpi_extd[0]; 8288949bcd6Sandrei cp->cp_eax = 0x80000000; 8298949bcd6Sandrei cpi->cpi_xmaxeax = __cpuid_insn(cp); 8307c478bd9Sstevel@tonic-gate } 8317c478bd9Sstevel@tonic-gate 8327c478bd9Sstevel@tonic-gate if (cpi->cpi_xmaxeax & 0x80000000) { 8337c478bd9Sstevel@tonic-gate 8347c478bd9Sstevel@tonic-gate if (cpi->cpi_xmaxeax > CPI_XMAXEAX_MAX) 8357c478bd9Sstevel@tonic-gate cpi->cpi_xmaxeax = CPI_XMAXEAX_MAX; 8367c478bd9Sstevel@tonic-gate 8377c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 8387c478bd9Sstevel@tonic-gate case X86_VENDOR_Intel: 8397c478bd9Sstevel@tonic-gate case X86_VENDOR_AMD: 8407c478bd9Sstevel@tonic-gate if (cpi->cpi_xmaxeax < 0x80000001) 8417c478bd9Sstevel@tonic-gate break; 8427c478bd9Sstevel@tonic-gate cp = &cpi->cpi_extd[1]; 8438949bcd6Sandrei cp->cp_eax = 0x80000001; 8448949bcd6Sandrei (void) __cpuid_insn(cp); 845ae115bc7Smrj 8467c478bd9Sstevel@tonic-gate if (cpi->cpi_vendor == X86_VENDOR_AMD && 8477c478bd9Sstevel@tonic-gate cpi->cpi_family == 5 && 8487c478bd9Sstevel@tonic-gate cpi->cpi_model == 6 && 8497c478bd9Sstevel@tonic-gate cpi->cpi_step == 6) { 8507c478bd9Sstevel@tonic-gate /* 8517c478bd9Sstevel@tonic-gate * K6 model 6 uses bit 10 to indicate SYSC 8527c478bd9Sstevel@tonic-gate * Later models use bit 11. Fix it here. 8537c478bd9Sstevel@tonic-gate */ 8547c478bd9Sstevel@tonic-gate if (cp->cp_edx & 0x400) { 8557c478bd9Sstevel@tonic-gate cp->cp_edx &= ~0x400; 8567c478bd9Sstevel@tonic-gate cp->cp_edx |= CPUID_AMD_EDX_SYSC; 8577c478bd9Sstevel@tonic-gate } 8587c478bd9Sstevel@tonic-gate } 8597c478bd9Sstevel@tonic-gate 860ae115bc7Smrj platform_cpuid_mangle(cpi->cpi_vendor, 0x80000001, cp); 861ae115bc7Smrj 8627c478bd9Sstevel@tonic-gate /* 8637c478bd9Sstevel@tonic-gate * Compute the additions to the kernel's feature word. 8647c478bd9Sstevel@tonic-gate */ 8657c478bd9Sstevel@tonic-gate if (cp->cp_edx & CPUID_AMD_EDX_NX) 8667c478bd9Sstevel@tonic-gate feature |= X86_NX; 8677c478bd9Sstevel@tonic-gate 8687c478bd9Sstevel@tonic-gate /* 869ae115bc7Smrj * If both the HTT and CMP_LGCY bits are set, 8708949bcd6Sandrei * then we're not actually HyperThreaded. Read 8718949bcd6Sandrei * "AMD CPUID Specification" for more details. 8727c478bd9Sstevel@tonic-gate */ 8737c478bd9Sstevel@tonic-gate if (cpi->cpi_vendor == X86_VENDOR_AMD && 8748949bcd6Sandrei (feature & X86_HTT) && 875ae115bc7Smrj (cp->cp_ecx & CPUID_AMD_ECX_CMP_LGCY)) { 8767c478bd9Sstevel@tonic-gate feature &= ~X86_HTT; 8778949bcd6Sandrei feature |= X86_CMP; 8788949bcd6Sandrei } 879ae115bc7Smrj #if defined(__amd64) 8807c478bd9Sstevel@tonic-gate /* 8817c478bd9Sstevel@tonic-gate * It's really tricky to support syscall/sysret in 8827c478bd9Sstevel@tonic-gate * the i386 kernel; we rely on sysenter/sysexit 8837c478bd9Sstevel@tonic-gate * instead. In the amd64 kernel, things are -way- 8847c478bd9Sstevel@tonic-gate * better. 8857c478bd9Sstevel@tonic-gate */ 8867c478bd9Sstevel@tonic-gate if (cp->cp_edx & CPUID_AMD_EDX_SYSC) 8877c478bd9Sstevel@tonic-gate feature |= X86_ASYSC; 8887c478bd9Sstevel@tonic-gate 8897c478bd9Sstevel@tonic-gate /* 8907c478bd9Sstevel@tonic-gate * While we're thinking about system calls, note 8917c478bd9Sstevel@tonic-gate * that AMD processors don't support sysenter 8927c478bd9Sstevel@tonic-gate * in long mode at all, so don't try to program them. 8937c478bd9Sstevel@tonic-gate */ 8947c478bd9Sstevel@tonic-gate if (x86_vendor == X86_VENDOR_AMD) 8957c478bd9Sstevel@tonic-gate feature &= ~X86_SEP; 8967c478bd9Sstevel@tonic-gate #endif 897ae115bc7Smrj if (cp->cp_edx & CPUID_AMD_EDX_TSCP) 898ae115bc7Smrj feature |= X86_TSCP; 8997c478bd9Sstevel@tonic-gate break; 9007c478bd9Sstevel@tonic-gate default: 9017c478bd9Sstevel@tonic-gate break; 9027c478bd9Sstevel@tonic-gate } 9037c478bd9Sstevel@tonic-gate 9048949bcd6Sandrei /* 9058949bcd6Sandrei * Get CPUID data about processor cores and hyperthreads. 9068949bcd6Sandrei */ 9077c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 9087c478bd9Sstevel@tonic-gate case X86_VENDOR_Intel: 9098949bcd6Sandrei if (cpi->cpi_maxeax >= 4) { 9108949bcd6Sandrei cp = &cpi->cpi_std[4]; 9118949bcd6Sandrei cp->cp_eax = 4; 9128949bcd6Sandrei cp->cp_ecx = 0; 9138949bcd6Sandrei (void) __cpuid_insn(cp); 914ae115bc7Smrj platform_cpuid_mangle(cpi->cpi_vendor, 4, cp); 9158949bcd6Sandrei } 9168949bcd6Sandrei /*FALLTHROUGH*/ 9177c478bd9Sstevel@tonic-gate case X86_VENDOR_AMD: 9187c478bd9Sstevel@tonic-gate if (cpi->cpi_xmaxeax < 0x80000008) 9197c478bd9Sstevel@tonic-gate break; 9207c478bd9Sstevel@tonic-gate cp = &cpi->cpi_extd[8]; 9218949bcd6Sandrei cp->cp_eax = 0x80000008; 9228949bcd6Sandrei (void) __cpuid_insn(cp); 923ae115bc7Smrj platform_cpuid_mangle(cpi->cpi_vendor, 0x80000008, cp); 924ae115bc7Smrj 9257c478bd9Sstevel@tonic-gate /* 9267c478bd9Sstevel@tonic-gate * Virtual and physical address limits from 9277c478bd9Sstevel@tonic-gate * cpuid override previously guessed values. 9287c478bd9Sstevel@tonic-gate */ 9297c478bd9Sstevel@tonic-gate cpi->cpi_pabits = BITX(cp->cp_eax, 7, 0); 9307c478bd9Sstevel@tonic-gate cpi->cpi_vabits = BITX(cp->cp_eax, 15, 8); 9317c478bd9Sstevel@tonic-gate break; 9327c478bd9Sstevel@tonic-gate default: 9337c478bd9Sstevel@tonic-gate break; 9347c478bd9Sstevel@tonic-gate } 9358949bcd6Sandrei 936*d129bde2Sesaxe /* 937*d129bde2Sesaxe * Derive the number of cores per chip 938*d129bde2Sesaxe */ 9398949bcd6Sandrei switch (cpi->cpi_vendor) { 9408949bcd6Sandrei case X86_VENDOR_Intel: 9418949bcd6Sandrei if (cpi->cpi_maxeax < 4) { 9428949bcd6Sandrei cpi->cpi_ncore_per_chip = 1; 9438949bcd6Sandrei break; 9448949bcd6Sandrei } else { 9458949bcd6Sandrei cpi->cpi_ncore_per_chip = 9468949bcd6Sandrei BITX((cpi)->cpi_std[4].cp_eax, 31, 26) + 1; 9478949bcd6Sandrei } 9488949bcd6Sandrei break; 9498949bcd6Sandrei case X86_VENDOR_AMD: 9508949bcd6Sandrei if (cpi->cpi_xmaxeax < 0x80000008) { 9518949bcd6Sandrei cpi->cpi_ncore_per_chip = 1; 9528949bcd6Sandrei break; 9538949bcd6Sandrei } else { 9548949bcd6Sandrei cpi->cpi_ncore_per_chip = 9558949bcd6Sandrei BITX((cpi)->cpi_extd[8].cp_ecx, 7, 0) + 1; 9568949bcd6Sandrei } 9578949bcd6Sandrei break; 9588949bcd6Sandrei default: 9598949bcd6Sandrei cpi->cpi_ncore_per_chip = 1; 9608949bcd6Sandrei break; 9617c478bd9Sstevel@tonic-gate } 9628949bcd6Sandrei } 9638949bcd6Sandrei 9648949bcd6Sandrei /* 9658949bcd6Sandrei * If more than one core, then this processor is CMP. 9668949bcd6Sandrei */ 9678949bcd6Sandrei if (cpi->cpi_ncore_per_chip > 1) 9688949bcd6Sandrei feature |= X86_CMP; 969ae115bc7Smrj 9708949bcd6Sandrei /* 9718949bcd6Sandrei * If the number of cores is the same as the number 9728949bcd6Sandrei * of CPUs, then we cannot have HyperThreading. 9738949bcd6Sandrei */ 9748949bcd6Sandrei if (cpi->cpi_ncpu_per_chip == cpi->cpi_ncore_per_chip) 9758949bcd6Sandrei feature &= ~X86_HTT; 9768949bcd6Sandrei 9777c478bd9Sstevel@tonic-gate if ((feature & (X86_HTT | X86_CMP)) == 0) { 9788949bcd6Sandrei /* 9798949bcd6Sandrei * Single-core single-threaded processors. 9808949bcd6Sandrei */ 9817c478bd9Sstevel@tonic-gate cpi->cpi_chipid = -1; 9827c478bd9Sstevel@tonic-gate cpi->cpi_clogid = 0; 9838949bcd6Sandrei cpi->cpi_coreid = cpu->cpu_id; 9847c478bd9Sstevel@tonic-gate } else if (cpi->cpi_ncpu_per_chip > 1) { 9858949bcd6Sandrei uint_t i; 9868949bcd6Sandrei uint_t chipid_shift = 0; 9878949bcd6Sandrei uint_t coreid_shift = 0; 9888949bcd6Sandrei uint_t apic_id = CPI_APIC_ID(cpi); 9897c478bd9Sstevel@tonic-gate 9908949bcd6Sandrei for (i = 1; i < cpi->cpi_ncpu_per_chip; i <<= 1) 9918949bcd6Sandrei chipid_shift++; 9928949bcd6Sandrei cpi->cpi_chipid = apic_id >> chipid_shift; 9938949bcd6Sandrei cpi->cpi_clogid = apic_id & ((1 << chipid_shift) - 1); 9948949bcd6Sandrei 9958949bcd6Sandrei if (cpi->cpi_vendor == X86_VENDOR_Intel) { 9968949bcd6Sandrei if (feature & X86_CMP) { 9978949bcd6Sandrei /* 9988949bcd6Sandrei * Multi-core (and possibly multi-threaded) 9998949bcd6Sandrei * processors. 10008949bcd6Sandrei */ 10018949bcd6Sandrei uint_t ncpu_per_core; 10028949bcd6Sandrei if (cpi->cpi_ncore_per_chip == 1) 10038949bcd6Sandrei ncpu_per_core = cpi->cpi_ncpu_per_chip; 10048949bcd6Sandrei else if (cpi->cpi_ncore_per_chip > 1) 10058949bcd6Sandrei ncpu_per_core = cpi->cpi_ncpu_per_chip / 10068949bcd6Sandrei cpi->cpi_ncore_per_chip; 10078949bcd6Sandrei /* 10088949bcd6Sandrei * 8bit APIC IDs on dual core Pentiums 10098949bcd6Sandrei * look like this: 10108949bcd6Sandrei * 10118949bcd6Sandrei * +-----------------------+------+------+ 10128949bcd6Sandrei * | Physical Package ID | MC | HT | 10138949bcd6Sandrei * +-----------------------+------+------+ 10148949bcd6Sandrei * <------- chipid --------> 10158949bcd6Sandrei * <------- coreid ---------------> 10168949bcd6Sandrei * <--- clogid --> 10178949bcd6Sandrei * 10188949bcd6Sandrei * Where the number of bits necessary to 10198949bcd6Sandrei * represent MC and HT fields together equals 10208949bcd6Sandrei * to the minimum number of bits necessary to 10218949bcd6Sandrei * store the value of cpi->cpi_ncpu_per_chip. 10228949bcd6Sandrei * Of those bits, the MC part uses the number 10238949bcd6Sandrei * of bits necessary to store the value of 10248949bcd6Sandrei * cpi->cpi_ncore_per_chip. 10258949bcd6Sandrei */ 10268949bcd6Sandrei for (i = 1; i < ncpu_per_core; i <<= 1) 10278949bcd6Sandrei coreid_shift++; 10283090b9a9Sandrei cpi->cpi_coreid = apic_id >> coreid_shift; 10298949bcd6Sandrei } else if (feature & X86_HTT) { 10308949bcd6Sandrei /* 10318949bcd6Sandrei * Single-core multi-threaded processors. 10328949bcd6Sandrei */ 10338949bcd6Sandrei cpi->cpi_coreid = cpi->cpi_chipid; 10348949bcd6Sandrei } 10358949bcd6Sandrei } else if (cpi->cpi_vendor == X86_VENDOR_AMD) { 10368949bcd6Sandrei /* 10378949bcd6Sandrei * AMD currently only has dual-core processors with 10388949bcd6Sandrei * single-threaded cores. If they ever release 10398949bcd6Sandrei * multi-threaded processors, then this code 10408949bcd6Sandrei * will have to be updated. 10418949bcd6Sandrei */ 10428949bcd6Sandrei cpi->cpi_coreid = cpu->cpu_id; 10438949bcd6Sandrei } else { 10448949bcd6Sandrei /* 10458949bcd6Sandrei * All other processors are currently 10468949bcd6Sandrei * assumed to have single cores. 10478949bcd6Sandrei */ 10488949bcd6Sandrei cpi->cpi_coreid = cpi->cpi_chipid; 10498949bcd6Sandrei } 10507c478bd9Sstevel@tonic-gate } 10517c478bd9Sstevel@tonic-gate 10528a40a695Sgavinm /* 10538a40a695Sgavinm * Synthesize chip "revision" and socket type 10548a40a695Sgavinm */ 10558a40a695Sgavinm synth_info(cpi); 10568a40a695Sgavinm 10577c478bd9Sstevel@tonic-gate pass1_done: 10587c478bd9Sstevel@tonic-gate cpi->cpi_pass = 1; 10597c478bd9Sstevel@tonic-gate return (feature); 10607c478bd9Sstevel@tonic-gate } 10617c478bd9Sstevel@tonic-gate 10627c478bd9Sstevel@tonic-gate /* 10637c478bd9Sstevel@tonic-gate * Make copies of the cpuid table entries we depend on, in 10647c478bd9Sstevel@tonic-gate * part for ease of parsing now, in part so that we have only 10657c478bd9Sstevel@tonic-gate * one place to correct any of it, in part for ease of 10667c478bd9Sstevel@tonic-gate * later export to userland, and in part so we can look at 10677c478bd9Sstevel@tonic-gate * this stuff in a crash dump. 10687c478bd9Sstevel@tonic-gate */ 10697c478bd9Sstevel@tonic-gate 10707c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 10717c478bd9Sstevel@tonic-gate void 10727c478bd9Sstevel@tonic-gate cpuid_pass2(cpu_t *cpu) 10737c478bd9Sstevel@tonic-gate { 10747c478bd9Sstevel@tonic-gate uint_t n, nmax; 10757c478bd9Sstevel@tonic-gate int i; 10768949bcd6Sandrei struct cpuid_regs *cp; 10777c478bd9Sstevel@tonic-gate uint8_t *dp; 10787c478bd9Sstevel@tonic-gate uint32_t *iptr; 10797c478bd9Sstevel@tonic-gate struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 10807c478bd9Sstevel@tonic-gate 10817c478bd9Sstevel@tonic-gate ASSERT(cpi->cpi_pass == 1); 10827c478bd9Sstevel@tonic-gate 10837c478bd9Sstevel@tonic-gate if (cpi->cpi_maxeax < 1) 10847c478bd9Sstevel@tonic-gate goto pass2_done; 10857c478bd9Sstevel@tonic-gate 10867c478bd9Sstevel@tonic-gate if ((nmax = cpi->cpi_maxeax + 1) > NMAX_CPI_STD) 10877c478bd9Sstevel@tonic-gate nmax = NMAX_CPI_STD; 10887c478bd9Sstevel@tonic-gate /* 10897c478bd9Sstevel@tonic-gate * (We already handled n == 0 and n == 1 in pass 1) 10907c478bd9Sstevel@tonic-gate */ 10917c478bd9Sstevel@tonic-gate for (n = 2, cp = &cpi->cpi_std[2]; n < nmax; n++, cp++) { 10928949bcd6Sandrei cp->cp_eax = n; 1093*d129bde2Sesaxe 1094*d129bde2Sesaxe /* 1095*d129bde2Sesaxe * CPUID function 4 expects %ecx to be initialized 1096*d129bde2Sesaxe * with an index which indicates which cache to return 1097*d129bde2Sesaxe * information about. The OS is expected to call function 4 1098*d129bde2Sesaxe * with %ecx set to 0, 1, 2, ... until it returns with 1099*d129bde2Sesaxe * EAX[4:0] set to 0, which indicates there are no more 1100*d129bde2Sesaxe * caches. 1101*d129bde2Sesaxe * 1102*d129bde2Sesaxe * Here, populate cpi_std[4] with the information returned by 1103*d129bde2Sesaxe * function 4 when %ecx == 0, and do the rest in cpuid_pass3() 1104*d129bde2Sesaxe * when dynamic memory allocation becomes available. 1105*d129bde2Sesaxe * 1106*d129bde2Sesaxe * Note: we need to explicitly initialize %ecx here, since 1107*d129bde2Sesaxe * function 4 may have been previously invoked. 1108*d129bde2Sesaxe */ 1109*d129bde2Sesaxe if (n == 4) 1110*d129bde2Sesaxe cp->cp_ecx = 0; 1111*d129bde2Sesaxe 11128949bcd6Sandrei (void) __cpuid_insn(cp); 1113ae115bc7Smrj platform_cpuid_mangle(cpi->cpi_vendor, n, cp); 11147c478bd9Sstevel@tonic-gate switch (n) { 11157c478bd9Sstevel@tonic-gate case 2: 11167c478bd9Sstevel@tonic-gate /* 11177c478bd9Sstevel@tonic-gate * "the lower 8 bits of the %eax register 11187c478bd9Sstevel@tonic-gate * contain a value that identifies the number 11197c478bd9Sstevel@tonic-gate * of times the cpuid [instruction] has to be 11207c478bd9Sstevel@tonic-gate * executed to obtain a complete image of the 11217c478bd9Sstevel@tonic-gate * processor's caching systems." 11227c478bd9Sstevel@tonic-gate * 11237c478bd9Sstevel@tonic-gate * How *do* they make this stuff up? 11247c478bd9Sstevel@tonic-gate */ 11257c478bd9Sstevel@tonic-gate cpi->cpi_ncache = sizeof (*cp) * 11267c478bd9Sstevel@tonic-gate BITX(cp->cp_eax, 7, 0); 11277c478bd9Sstevel@tonic-gate if (cpi->cpi_ncache == 0) 11287c478bd9Sstevel@tonic-gate break; 11297c478bd9Sstevel@tonic-gate cpi->cpi_ncache--; /* skip count byte */ 11307c478bd9Sstevel@tonic-gate 11317c478bd9Sstevel@tonic-gate /* 11327c478bd9Sstevel@tonic-gate * Well, for now, rather than attempt to implement 11337c478bd9Sstevel@tonic-gate * this slightly dubious algorithm, we just look 11347c478bd9Sstevel@tonic-gate * at the first 15 .. 11357c478bd9Sstevel@tonic-gate */ 11367c478bd9Sstevel@tonic-gate if (cpi->cpi_ncache > (sizeof (*cp) - 1)) 11377c478bd9Sstevel@tonic-gate cpi->cpi_ncache = sizeof (*cp) - 1; 11387c478bd9Sstevel@tonic-gate 11397c478bd9Sstevel@tonic-gate dp = cpi->cpi_cacheinfo; 11407c478bd9Sstevel@tonic-gate if (BITX(cp->cp_eax, 31, 31) == 0) { 11417c478bd9Sstevel@tonic-gate uint8_t *p = (void *)&cp->cp_eax; 11427c478bd9Sstevel@tonic-gate for (i = 1; i < 3; i++) 11437c478bd9Sstevel@tonic-gate if (p[i] != 0) 11447c478bd9Sstevel@tonic-gate *dp++ = p[i]; 11457c478bd9Sstevel@tonic-gate } 11467c478bd9Sstevel@tonic-gate if (BITX(cp->cp_ebx, 31, 31) == 0) { 11477c478bd9Sstevel@tonic-gate uint8_t *p = (void *)&cp->cp_ebx; 11487c478bd9Sstevel@tonic-gate for (i = 0; i < 4; i++) 11497c478bd9Sstevel@tonic-gate if (p[i] != 0) 11507c478bd9Sstevel@tonic-gate *dp++ = p[i]; 11517c478bd9Sstevel@tonic-gate } 11527c478bd9Sstevel@tonic-gate if (BITX(cp->cp_ecx, 31, 31) == 0) { 11537c478bd9Sstevel@tonic-gate uint8_t *p = (void *)&cp->cp_ecx; 11547c478bd9Sstevel@tonic-gate for (i = 0; i < 4; i++) 11557c478bd9Sstevel@tonic-gate if (p[i] != 0) 11567c478bd9Sstevel@tonic-gate *dp++ = p[i]; 11577c478bd9Sstevel@tonic-gate } 11587c478bd9Sstevel@tonic-gate if (BITX(cp->cp_edx, 31, 31) == 0) { 11597c478bd9Sstevel@tonic-gate uint8_t *p = (void *)&cp->cp_edx; 11607c478bd9Sstevel@tonic-gate for (i = 0; i < 4; i++) 11617c478bd9Sstevel@tonic-gate if (p[i] != 0) 11627c478bd9Sstevel@tonic-gate *dp++ = p[i]; 11637c478bd9Sstevel@tonic-gate } 11647c478bd9Sstevel@tonic-gate break; 1165f98fbcecSbholler 11667c478bd9Sstevel@tonic-gate case 3: /* Processor serial number, if PSN supported */ 1167f98fbcecSbholler break; 1168f98fbcecSbholler 11697c478bd9Sstevel@tonic-gate case 4: /* Deterministic cache parameters */ 1170f98fbcecSbholler break; 1171f98fbcecSbholler 11727c478bd9Sstevel@tonic-gate case 5: /* Monitor/Mwait parameters */ 1173f98fbcecSbholler 1174f98fbcecSbholler /* 1175f98fbcecSbholler * check cpi_mwait.support which was set in cpuid_pass1 1176f98fbcecSbholler */ 1177f98fbcecSbholler if (!(cpi->cpi_mwait.support & MWAIT_SUPPORT)) 1178f98fbcecSbholler break; 1179f98fbcecSbholler 1180f98fbcecSbholler cpi->cpi_mwait.mon_min = (size_t)MWAIT_SIZE_MIN(cpi); 1181f98fbcecSbholler cpi->cpi_mwait.mon_max = (size_t)MWAIT_SIZE_MAX(cpi); 1182f98fbcecSbholler if (MWAIT_EXTENSION(cpi)) { 1183f98fbcecSbholler cpi->cpi_mwait.support |= MWAIT_EXTENSIONS; 1184f98fbcecSbholler if (MWAIT_INT_ENABLE(cpi)) 1185f98fbcecSbholler cpi->cpi_mwait.support |= 1186f98fbcecSbholler MWAIT_ECX_INT_ENABLE; 1187f98fbcecSbholler } 1188f98fbcecSbholler break; 11897c478bd9Sstevel@tonic-gate default: 11907c478bd9Sstevel@tonic-gate break; 11917c478bd9Sstevel@tonic-gate } 11927c478bd9Sstevel@tonic-gate } 11937c478bd9Sstevel@tonic-gate 11947c478bd9Sstevel@tonic-gate if ((cpi->cpi_xmaxeax & 0x80000000) == 0) 11957c478bd9Sstevel@tonic-gate goto pass2_done; 11967c478bd9Sstevel@tonic-gate 11977c478bd9Sstevel@tonic-gate if ((nmax = cpi->cpi_xmaxeax - 0x80000000 + 1) > NMAX_CPI_EXTD) 11987c478bd9Sstevel@tonic-gate nmax = NMAX_CPI_EXTD; 11997c478bd9Sstevel@tonic-gate /* 12007c478bd9Sstevel@tonic-gate * Copy the extended properties, fixing them as we go. 12017c478bd9Sstevel@tonic-gate * (We already handled n == 0 and n == 1 in pass 1) 12027c478bd9Sstevel@tonic-gate */ 12037c478bd9Sstevel@tonic-gate iptr = (void *)cpi->cpi_brandstr; 12047c478bd9Sstevel@tonic-gate for (n = 2, cp = &cpi->cpi_extd[2]; n < nmax; cp++, n++) { 12058949bcd6Sandrei cp->cp_eax = 0x80000000 + n; 12068949bcd6Sandrei (void) __cpuid_insn(cp); 1207ae115bc7Smrj platform_cpuid_mangle(cpi->cpi_vendor, 0x80000000 + n, cp); 12087c478bd9Sstevel@tonic-gate switch (n) { 12097c478bd9Sstevel@tonic-gate case 2: 12107c478bd9Sstevel@tonic-gate case 3: 12117c478bd9Sstevel@tonic-gate case 4: 12127c478bd9Sstevel@tonic-gate /* 12137c478bd9Sstevel@tonic-gate * Extract the brand string 12147c478bd9Sstevel@tonic-gate */ 12157c478bd9Sstevel@tonic-gate *iptr++ = cp->cp_eax; 12167c478bd9Sstevel@tonic-gate *iptr++ = cp->cp_ebx; 12177c478bd9Sstevel@tonic-gate *iptr++ = cp->cp_ecx; 12187c478bd9Sstevel@tonic-gate *iptr++ = cp->cp_edx; 12197c478bd9Sstevel@tonic-gate break; 12207c478bd9Sstevel@tonic-gate case 5: 12217c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 12227c478bd9Sstevel@tonic-gate case X86_VENDOR_AMD: 12237c478bd9Sstevel@tonic-gate /* 12247c478bd9Sstevel@tonic-gate * The Athlon and Duron were the first 12257c478bd9Sstevel@tonic-gate * parts to report the sizes of the 12267c478bd9Sstevel@tonic-gate * TLB for large pages. Before then, 12277c478bd9Sstevel@tonic-gate * we don't trust the data. 12287c478bd9Sstevel@tonic-gate */ 12297c478bd9Sstevel@tonic-gate if (cpi->cpi_family < 6 || 12307c478bd9Sstevel@tonic-gate (cpi->cpi_family == 6 && 12317c478bd9Sstevel@tonic-gate cpi->cpi_model < 1)) 12327c478bd9Sstevel@tonic-gate cp->cp_eax = 0; 12337c478bd9Sstevel@tonic-gate break; 12347c478bd9Sstevel@tonic-gate default: 12357c478bd9Sstevel@tonic-gate break; 12367c478bd9Sstevel@tonic-gate } 12377c478bd9Sstevel@tonic-gate break; 12387c478bd9Sstevel@tonic-gate case 6: 12397c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 12407c478bd9Sstevel@tonic-gate case X86_VENDOR_AMD: 12417c478bd9Sstevel@tonic-gate /* 12427c478bd9Sstevel@tonic-gate * The Athlon and Duron were the first 12437c478bd9Sstevel@tonic-gate * AMD parts with L2 TLB's. 12447c478bd9Sstevel@tonic-gate * Before then, don't trust the data. 12457c478bd9Sstevel@tonic-gate */ 12467c478bd9Sstevel@tonic-gate if (cpi->cpi_family < 6 || 12477c478bd9Sstevel@tonic-gate cpi->cpi_family == 6 && 12487c478bd9Sstevel@tonic-gate cpi->cpi_model < 1) 12497c478bd9Sstevel@tonic-gate cp->cp_eax = cp->cp_ebx = 0; 12507c478bd9Sstevel@tonic-gate /* 12517c478bd9Sstevel@tonic-gate * AMD Duron rev A0 reports L2 12527c478bd9Sstevel@tonic-gate * cache size incorrectly as 1K 12537c478bd9Sstevel@tonic-gate * when it is really 64K 12547c478bd9Sstevel@tonic-gate */ 12557c478bd9Sstevel@tonic-gate if (cpi->cpi_family == 6 && 12567c478bd9Sstevel@tonic-gate cpi->cpi_model == 3 && 12577c478bd9Sstevel@tonic-gate cpi->cpi_step == 0) { 12587c478bd9Sstevel@tonic-gate cp->cp_ecx &= 0xffff; 12597c478bd9Sstevel@tonic-gate cp->cp_ecx |= 0x400000; 12607c478bd9Sstevel@tonic-gate } 12617c478bd9Sstevel@tonic-gate break; 12627c478bd9Sstevel@tonic-gate case X86_VENDOR_Cyrix: /* VIA C3 */ 12637c478bd9Sstevel@tonic-gate /* 12647c478bd9Sstevel@tonic-gate * VIA C3 processors are a bit messed 12657c478bd9Sstevel@tonic-gate * up w.r.t. encoding cache sizes in %ecx 12667c478bd9Sstevel@tonic-gate */ 12677c478bd9Sstevel@tonic-gate if (cpi->cpi_family != 6) 12687c478bd9Sstevel@tonic-gate break; 12697c478bd9Sstevel@tonic-gate /* 12707c478bd9Sstevel@tonic-gate * model 7 and 8 were incorrectly encoded 12717c478bd9Sstevel@tonic-gate * 12727c478bd9Sstevel@tonic-gate * xxx is model 8 really broken? 12737c478bd9Sstevel@tonic-gate */ 12747c478bd9Sstevel@tonic-gate if (cpi->cpi_model == 7 || 12757c478bd9Sstevel@tonic-gate cpi->cpi_model == 8) 12767c478bd9Sstevel@tonic-gate cp->cp_ecx = 12777c478bd9Sstevel@tonic-gate BITX(cp->cp_ecx, 31, 24) << 16 | 12787c478bd9Sstevel@tonic-gate BITX(cp->cp_ecx, 23, 16) << 12 | 12797c478bd9Sstevel@tonic-gate BITX(cp->cp_ecx, 15, 8) << 8 | 12807c478bd9Sstevel@tonic-gate BITX(cp->cp_ecx, 7, 0); 12817c478bd9Sstevel@tonic-gate /* 12827c478bd9Sstevel@tonic-gate * model 9 stepping 1 has wrong associativity 12837c478bd9Sstevel@tonic-gate */ 12847c478bd9Sstevel@tonic-gate if (cpi->cpi_model == 9 && cpi->cpi_step == 1) 12857c478bd9Sstevel@tonic-gate cp->cp_ecx |= 8 << 12; 12867c478bd9Sstevel@tonic-gate break; 12877c478bd9Sstevel@tonic-gate case X86_VENDOR_Intel: 12887c478bd9Sstevel@tonic-gate /* 12897c478bd9Sstevel@tonic-gate * Extended L2 Cache features function. 12907c478bd9Sstevel@tonic-gate * First appeared on Prescott. 12917c478bd9Sstevel@tonic-gate */ 12927c478bd9Sstevel@tonic-gate default: 12937c478bd9Sstevel@tonic-gate break; 12947c478bd9Sstevel@tonic-gate } 12957c478bd9Sstevel@tonic-gate break; 12967c478bd9Sstevel@tonic-gate default: 12977c478bd9Sstevel@tonic-gate break; 12987c478bd9Sstevel@tonic-gate } 12997c478bd9Sstevel@tonic-gate } 13007c478bd9Sstevel@tonic-gate 13017c478bd9Sstevel@tonic-gate pass2_done: 13027c478bd9Sstevel@tonic-gate cpi->cpi_pass = 2; 13037c478bd9Sstevel@tonic-gate } 13047c478bd9Sstevel@tonic-gate 13057c478bd9Sstevel@tonic-gate static const char * 13067c478bd9Sstevel@tonic-gate intel_cpubrand(const struct cpuid_info *cpi) 13077c478bd9Sstevel@tonic-gate { 13087c478bd9Sstevel@tonic-gate int i; 13097c478bd9Sstevel@tonic-gate 13107c478bd9Sstevel@tonic-gate if ((x86_feature & X86_CPUID) == 0 || 13117c478bd9Sstevel@tonic-gate cpi->cpi_maxeax < 1 || cpi->cpi_family < 5) 13127c478bd9Sstevel@tonic-gate return ("i486"); 13137c478bd9Sstevel@tonic-gate 13147c478bd9Sstevel@tonic-gate switch (cpi->cpi_family) { 13157c478bd9Sstevel@tonic-gate case 5: 13167c478bd9Sstevel@tonic-gate return ("Intel Pentium(r)"); 13177c478bd9Sstevel@tonic-gate case 6: 13187c478bd9Sstevel@tonic-gate switch (cpi->cpi_model) { 13197c478bd9Sstevel@tonic-gate uint_t celeron, xeon; 13208949bcd6Sandrei const struct cpuid_regs *cp; 13217c478bd9Sstevel@tonic-gate case 0: 13227c478bd9Sstevel@tonic-gate case 1: 13237c478bd9Sstevel@tonic-gate case 2: 13247c478bd9Sstevel@tonic-gate return ("Intel Pentium(r) Pro"); 13257c478bd9Sstevel@tonic-gate case 3: 13267c478bd9Sstevel@tonic-gate case 4: 13277c478bd9Sstevel@tonic-gate return ("Intel Pentium(r) II"); 13287c478bd9Sstevel@tonic-gate case 6: 13297c478bd9Sstevel@tonic-gate return ("Intel Celeron(r)"); 13307c478bd9Sstevel@tonic-gate case 5: 13317c478bd9Sstevel@tonic-gate case 7: 13327c478bd9Sstevel@tonic-gate celeron = xeon = 0; 13337c478bd9Sstevel@tonic-gate cp = &cpi->cpi_std[2]; /* cache info */ 13347c478bd9Sstevel@tonic-gate 13357c478bd9Sstevel@tonic-gate for (i = 1; i < 3; i++) { 13367c478bd9Sstevel@tonic-gate uint_t tmp; 13377c478bd9Sstevel@tonic-gate 13387c478bd9Sstevel@tonic-gate tmp = (cp->cp_eax >> (8 * i)) & 0xff; 13397c478bd9Sstevel@tonic-gate if (tmp == 0x40) 13407c478bd9Sstevel@tonic-gate celeron++; 13417c478bd9Sstevel@tonic-gate if (tmp >= 0x44 && tmp <= 0x45) 13427c478bd9Sstevel@tonic-gate xeon++; 13437c478bd9Sstevel@tonic-gate } 13447c478bd9Sstevel@tonic-gate 13457c478bd9Sstevel@tonic-gate for (i = 0; i < 2; i++) { 13467c478bd9Sstevel@tonic-gate uint_t tmp; 13477c478bd9Sstevel@tonic-gate 13487c478bd9Sstevel@tonic-gate tmp = (cp->cp_ebx >> (8 * i)) & 0xff; 13497c478bd9Sstevel@tonic-gate if (tmp == 0x40) 13507c478bd9Sstevel@tonic-gate celeron++; 13517c478bd9Sstevel@tonic-gate else if (tmp >= 0x44 && tmp <= 0x45) 13527c478bd9Sstevel@tonic-gate xeon++; 13537c478bd9Sstevel@tonic-gate } 13547c478bd9Sstevel@tonic-gate 13557c478bd9Sstevel@tonic-gate for (i = 0; i < 4; i++) { 13567c478bd9Sstevel@tonic-gate uint_t tmp; 13577c478bd9Sstevel@tonic-gate 13587c478bd9Sstevel@tonic-gate tmp = (cp->cp_ecx >> (8 * i)) & 0xff; 13597c478bd9Sstevel@tonic-gate if (tmp == 0x40) 13607c478bd9Sstevel@tonic-gate celeron++; 13617c478bd9Sstevel@tonic-gate else if (tmp >= 0x44 && tmp <= 0x45) 13627c478bd9Sstevel@tonic-gate xeon++; 13637c478bd9Sstevel@tonic-gate } 13647c478bd9Sstevel@tonic-gate 13657c478bd9Sstevel@tonic-gate for (i = 0; i < 4; i++) { 13667c478bd9Sstevel@tonic-gate uint_t tmp; 13677c478bd9Sstevel@tonic-gate 13687c478bd9Sstevel@tonic-gate tmp = (cp->cp_edx >> (8 * i)) & 0xff; 13697c478bd9Sstevel@tonic-gate if (tmp == 0x40) 13707c478bd9Sstevel@tonic-gate celeron++; 13717c478bd9Sstevel@tonic-gate else if (tmp >= 0x44 && tmp <= 0x45) 13727c478bd9Sstevel@tonic-gate xeon++; 13737c478bd9Sstevel@tonic-gate } 13747c478bd9Sstevel@tonic-gate 13757c478bd9Sstevel@tonic-gate if (celeron) 13767c478bd9Sstevel@tonic-gate return ("Intel Celeron(r)"); 13777c478bd9Sstevel@tonic-gate if (xeon) 13787c478bd9Sstevel@tonic-gate return (cpi->cpi_model == 5 ? 13797c478bd9Sstevel@tonic-gate "Intel Pentium(r) II Xeon(tm)" : 13807c478bd9Sstevel@tonic-gate "Intel Pentium(r) III Xeon(tm)"); 13817c478bd9Sstevel@tonic-gate return (cpi->cpi_model == 5 ? 13827c478bd9Sstevel@tonic-gate "Intel Pentium(r) II or Pentium(r) II Xeon(tm)" : 13837c478bd9Sstevel@tonic-gate "Intel Pentium(r) III or Pentium(r) III Xeon(tm)"); 13847c478bd9Sstevel@tonic-gate default: 13857c478bd9Sstevel@tonic-gate break; 13867c478bd9Sstevel@tonic-gate } 13877c478bd9Sstevel@tonic-gate default: 13887c478bd9Sstevel@tonic-gate break; 13897c478bd9Sstevel@tonic-gate } 13907c478bd9Sstevel@tonic-gate 13915ff02082Sdmick /* BrandID is present if the field is nonzero */ 13925ff02082Sdmick if (cpi->cpi_brandid != 0) { 13937c478bd9Sstevel@tonic-gate static const struct { 13947c478bd9Sstevel@tonic-gate uint_t bt_bid; 13957c478bd9Sstevel@tonic-gate const char *bt_str; 13967c478bd9Sstevel@tonic-gate } brand_tbl[] = { 13977c478bd9Sstevel@tonic-gate { 0x1, "Intel(r) Celeron(r)" }, 13987c478bd9Sstevel@tonic-gate { 0x2, "Intel(r) Pentium(r) III" }, 13997c478bd9Sstevel@tonic-gate { 0x3, "Intel(r) Pentium(r) III Xeon(tm)" }, 14007c478bd9Sstevel@tonic-gate { 0x4, "Intel(r) Pentium(r) III" }, 14017c478bd9Sstevel@tonic-gate { 0x6, "Mobile Intel(r) Pentium(r) III" }, 14027c478bd9Sstevel@tonic-gate { 0x7, "Mobile Intel(r) Celeron(r)" }, 14037c478bd9Sstevel@tonic-gate { 0x8, "Intel(r) Pentium(r) 4" }, 14047c478bd9Sstevel@tonic-gate { 0x9, "Intel(r) Pentium(r) 4" }, 14057c478bd9Sstevel@tonic-gate { 0xa, "Intel(r) Celeron(r)" }, 14067c478bd9Sstevel@tonic-gate { 0xb, "Intel(r) Xeon(tm)" }, 14077c478bd9Sstevel@tonic-gate { 0xc, "Intel(r) Xeon(tm) MP" }, 14087c478bd9Sstevel@tonic-gate { 0xe, "Mobile Intel(r) Pentium(r) 4" }, 14095ff02082Sdmick { 0xf, "Mobile Intel(r) Celeron(r)" }, 14105ff02082Sdmick { 0x11, "Mobile Genuine Intel(r)" }, 14115ff02082Sdmick { 0x12, "Intel(r) Celeron(r) M" }, 14125ff02082Sdmick { 0x13, "Mobile Intel(r) Celeron(r)" }, 14135ff02082Sdmick { 0x14, "Intel(r) Celeron(r)" }, 14145ff02082Sdmick { 0x15, "Mobile Genuine Intel(r)" }, 14155ff02082Sdmick { 0x16, "Intel(r) Pentium(r) M" }, 14165ff02082Sdmick { 0x17, "Mobile Intel(r) Celeron(r)" } 14177c478bd9Sstevel@tonic-gate }; 14187c478bd9Sstevel@tonic-gate uint_t btblmax = sizeof (brand_tbl) / sizeof (brand_tbl[0]); 14197c478bd9Sstevel@tonic-gate uint_t sgn; 14207c478bd9Sstevel@tonic-gate 14217c478bd9Sstevel@tonic-gate sgn = (cpi->cpi_family << 8) | 14227c478bd9Sstevel@tonic-gate (cpi->cpi_model << 4) | cpi->cpi_step; 14237c478bd9Sstevel@tonic-gate 14247c478bd9Sstevel@tonic-gate for (i = 0; i < btblmax; i++) 14257c478bd9Sstevel@tonic-gate if (brand_tbl[i].bt_bid == cpi->cpi_brandid) 14267c478bd9Sstevel@tonic-gate break; 14277c478bd9Sstevel@tonic-gate if (i < btblmax) { 14287c478bd9Sstevel@tonic-gate if (sgn == 0x6b1 && cpi->cpi_brandid == 3) 14297c478bd9Sstevel@tonic-gate return ("Intel(r) Celeron(r)"); 14307c478bd9Sstevel@tonic-gate if (sgn < 0xf13 && cpi->cpi_brandid == 0xb) 14317c478bd9Sstevel@tonic-gate return ("Intel(r) Xeon(tm) MP"); 14327c478bd9Sstevel@tonic-gate if (sgn < 0xf13 && cpi->cpi_brandid == 0xe) 14337c478bd9Sstevel@tonic-gate return ("Intel(r) Xeon(tm)"); 14347c478bd9Sstevel@tonic-gate return (brand_tbl[i].bt_str); 14357c478bd9Sstevel@tonic-gate } 14367c478bd9Sstevel@tonic-gate } 14377c478bd9Sstevel@tonic-gate 14387c478bd9Sstevel@tonic-gate return (NULL); 14397c478bd9Sstevel@tonic-gate } 14407c478bd9Sstevel@tonic-gate 14417c478bd9Sstevel@tonic-gate static const char * 14427c478bd9Sstevel@tonic-gate amd_cpubrand(const struct cpuid_info *cpi) 14437c478bd9Sstevel@tonic-gate { 14447c478bd9Sstevel@tonic-gate if ((x86_feature & X86_CPUID) == 0 || 14457c478bd9Sstevel@tonic-gate cpi->cpi_maxeax < 1 || cpi->cpi_family < 5) 14467c478bd9Sstevel@tonic-gate return ("i486 compatible"); 14477c478bd9Sstevel@tonic-gate 14487c478bd9Sstevel@tonic-gate switch (cpi->cpi_family) { 14497c478bd9Sstevel@tonic-gate case 5: 14507c478bd9Sstevel@tonic-gate switch (cpi->cpi_model) { 14517c478bd9Sstevel@tonic-gate case 0: 14527c478bd9Sstevel@tonic-gate case 1: 14537c478bd9Sstevel@tonic-gate case 2: 14547c478bd9Sstevel@tonic-gate case 3: 14557c478bd9Sstevel@tonic-gate case 4: 14567c478bd9Sstevel@tonic-gate case 5: 14577c478bd9Sstevel@tonic-gate return ("AMD-K5(r)"); 14587c478bd9Sstevel@tonic-gate case 6: 14597c478bd9Sstevel@tonic-gate case 7: 14607c478bd9Sstevel@tonic-gate return ("AMD-K6(r)"); 14617c478bd9Sstevel@tonic-gate case 8: 14627c478bd9Sstevel@tonic-gate return ("AMD-K6(r)-2"); 14637c478bd9Sstevel@tonic-gate case 9: 14647c478bd9Sstevel@tonic-gate return ("AMD-K6(r)-III"); 14657c478bd9Sstevel@tonic-gate default: 14667c478bd9Sstevel@tonic-gate return ("AMD (family 5)"); 14677c478bd9Sstevel@tonic-gate } 14687c478bd9Sstevel@tonic-gate case 6: 14697c478bd9Sstevel@tonic-gate switch (cpi->cpi_model) { 14707c478bd9Sstevel@tonic-gate case 1: 14717c478bd9Sstevel@tonic-gate return ("AMD-K7(tm)"); 14727c478bd9Sstevel@tonic-gate case 0: 14737c478bd9Sstevel@tonic-gate case 2: 14747c478bd9Sstevel@tonic-gate case 4: 14757c478bd9Sstevel@tonic-gate return ("AMD Athlon(tm)"); 14767c478bd9Sstevel@tonic-gate case 3: 14777c478bd9Sstevel@tonic-gate case 7: 14787c478bd9Sstevel@tonic-gate return ("AMD Duron(tm)"); 14797c478bd9Sstevel@tonic-gate case 6: 14807c478bd9Sstevel@tonic-gate case 8: 14817c478bd9Sstevel@tonic-gate case 10: 14827c478bd9Sstevel@tonic-gate /* 14837c478bd9Sstevel@tonic-gate * Use the L2 cache size to distinguish 14847c478bd9Sstevel@tonic-gate */ 14857c478bd9Sstevel@tonic-gate return ((cpi->cpi_extd[6].cp_ecx >> 16) >= 256 ? 14867c478bd9Sstevel@tonic-gate "AMD Athlon(tm)" : "AMD Duron(tm)"); 14877c478bd9Sstevel@tonic-gate default: 14887c478bd9Sstevel@tonic-gate return ("AMD (family 6)"); 14897c478bd9Sstevel@tonic-gate } 14907c478bd9Sstevel@tonic-gate default: 14917c478bd9Sstevel@tonic-gate break; 14927c478bd9Sstevel@tonic-gate } 14937c478bd9Sstevel@tonic-gate 14947c478bd9Sstevel@tonic-gate if (cpi->cpi_family == 0xf && cpi->cpi_model == 5 && 14957c478bd9Sstevel@tonic-gate cpi->cpi_brandid != 0) { 14967c478bd9Sstevel@tonic-gate switch (BITX(cpi->cpi_brandid, 7, 5)) { 14977c478bd9Sstevel@tonic-gate case 3: 14987c478bd9Sstevel@tonic-gate return ("AMD Opteron(tm) UP 1xx"); 14997c478bd9Sstevel@tonic-gate case 4: 15007c478bd9Sstevel@tonic-gate return ("AMD Opteron(tm) DP 2xx"); 15017c478bd9Sstevel@tonic-gate case 5: 15027c478bd9Sstevel@tonic-gate return ("AMD Opteron(tm) MP 8xx"); 15037c478bd9Sstevel@tonic-gate default: 15047c478bd9Sstevel@tonic-gate return ("AMD Opteron(tm)"); 15057c478bd9Sstevel@tonic-gate } 15067c478bd9Sstevel@tonic-gate } 15077c478bd9Sstevel@tonic-gate 15087c478bd9Sstevel@tonic-gate return (NULL); 15097c478bd9Sstevel@tonic-gate } 15107c478bd9Sstevel@tonic-gate 15117c478bd9Sstevel@tonic-gate static const char * 15127c478bd9Sstevel@tonic-gate cyrix_cpubrand(struct cpuid_info *cpi, uint_t type) 15137c478bd9Sstevel@tonic-gate { 15147c478bd9Sstevel@tonic-gate if ((x86_feature & X86_CPUID) == 0 || 15157c478bd9Sstevel@tonic-gate cpi->cpi_maxeax < 1 || cpi->cpi_family < 5 || 15167c478bd9Sstevel@tonic-gate type == X86_TYPE_CYRIX_486) 15177c478bd9Sstevel@tonic-gate return ("i486 compatible"); 15187c478bd9Sstevel@tonic-gate 15197c478bd9Sstevel@tonic-gate switch (type) { 15207c478bd9Sstevel@tonic-gate case X86_TYPE_CYRIX_6x86: 15217c478bd9Sstevel@tonic-gate return ("Cyrix 6x86"); 15227c478bd9Sstevel@tonic-gate case X86_TYPE_CYRIX_6x86L: 15237c478bd9Sstevel@tonic-gate return ("Cyrix 6x86L"); 15247c478bd9Sstevel@tonic-gate case X86_TYPE_CYRIX_6x86MX: 15257c478bd9Sstevel@tonic-gate return ("Cyrix 6x86MX"); 15267c478bd9Sstevel@tonic-gate case X86_TYPE_CYRIX_GXm: 15277c478bd9Sstevel@tonic-gate return ("Cyrix GXm"); 15287c478bd9Sstevel@tonic-gate case X86_TYPE_CYRIX_MediaGX: 15297c478bd9Sstevel@tonic-gate return ("Cyrix MediaGX"); 15307c478bd9Sstevel@tonic-gate case X86_TYPE_CYRIX_MII: 15317c478bd9Sstevel@tonic-gate return ("Cyrix M2"); 15327c478bd9Sstevel@tonic-gate case X86_TYPE_VIA_CYRIX_III: 15337c478bd9Sstevel@tonic-gate return ("VIA Cyrix M3"); 15347c478bd9Sstevel@tonic-gate default: 15357c478bd9Sstevel@tonic-gate /* 15367c478bd9Sstevel@tonic-gate * Have another wild guess .. 15377c478bd9Sstevel@tonic-gate */ 15387c478bd9Sstevel@tonic-gate if (cpi->cpi_family == 4 && cpi->cpi_model == 9) 15397c478bd9Sstevel@tonic-gate return ("Cyrix 5x86"); 15407c478bd9Sstevel@tonic-gate else if (cpi->cpi_family == 5) { 15417c478bd9Sstevel@tonic-gate switch (cpi->cpi_model) { 15427c478bd9Sstevel@tonic-gate case 2: 15437c478bd9Sstevel@tonic-gate return ("Cyrix 6x86"); /* Cyrix M1 */ 15447c478bd9Sstevel@tonic-gate case 4: 15457c478bd9Sstevel@tonic-gate return ("Cyrix MediaGX"); 15467c478bd9Sstevel@tonic-gate default: 15477c478bd9Sstevel@tonic-gate break; 15487c478bd9Sstevel@tonic-gate } 15497c478bd9Sstevel@tonic-gate } else if (cpi->cpi_family == 6) { 15507c478bd9Sstevel@tonic-gate switch (cpi->cpi_model) { 15517c478bd9Sstevel@tonic-gate case 0: 15527c478bd9Sstevel@tonic-gate return ("Cyrix 6x86MX"); /* Cyrix M2? */ 15537c478bd9Sstevel@tonic-gate case 5: 15547c478bd9Sstevel@tonic-gate case 6: 15557c478bd9Sstevel@tonic-gate case 7: 15567c478bd9Sstevel@tonic-gate case 8: 15577c478bd9Sstevel@tonic-gate case 9: 15587c478bd9Sstevel@tonic-gate return ("VIA C3"); 15597c478bd9Sstevel@tonic-gate default: 15607c478bd9Sstevel@tonic-gate break; 15617c478bd9Sstevel@tonic-gate } 15627c478bd9Sstevel@tonic-gate } 15637c478bd9Sstevel@tonic-gate break; 15647c478bd9Sstevel@tonic-gate } 15657c478bd9Sstevel@tonic-gate return (NULL); 15667c478bd9Sstevel@tonic-gate } 15677c478bd9Sstevel@tonic-gate 15687c478bd9Sstevel@tonic-gate /* 15697c478bd9Sstevel@tonic-gate * This only gets called in the case that the CPU extended 15707c478bd9Sstevel@tonic-gate * feature brand string (0x80000002, 0x80000003, 0x80000004) 15717c478bd9Sstevel@tonic-gate * aren't available, or contain null bytes for some reason. 15727c478bd9Sstevel@tonic-gate */ 15737c478bd9Sstevel@tonic-gate static void 15747c478bd9Sstevel@tonic-gate fabricate_brandstr(struct cpuid_info *cpi) 15757c478bd9Sstevel@tonic-gate { 15767c478bd9Sstevel@tonic-gate const char *brand = NULL; 15777c478bd9Sstevel@tonic-gate 15787c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 15797c478bd9Sstevel@tonic-gate case X86_VENDOR_Intel: 15807c478bd9Sstevel@tonic-gate brand = intel_cpubrand(cpi); 15817c478bd9Sstevel@tonic-gate break; 15827c478bd9Sstevel@tonic-gate case X86_VENDOR_AMD: 15837c478bd9Sstevel@tonic-gate brand = amd_cpubrand(cpi); 15847c478bd9Sstevel@tonic-gate break; 15857c478bd9Sstevel@tonic-gate case X86_VENDOR_Cyrix: 15867c478bd9Sstevel@tonic-gate brand = cyrix_cpubrand(cpi, x86_type); 15877c478bd9Sstevel@tonic-gate break; 15887c478bd9Sstevel@tonic-gate case X86_VENDOR_NexGen: 15897c478bd9Sstevel@tonic-gate if (cpi->cpi_family == 5 && cpi->cpi_model == 0) 15907c478bd9Sstevel@tonic-gate brand = "NexGen Nx586"; 15917c478bd9Sstevel@tonic-gate break; 15927c478bd9Sstevel@tonic-gate case X86_VENDOR_Centaur: 15937c478bd9Sstevel@tonic-gate if (cpi->cpi_family == 5) 15947c478bd9Sstevel@tonic-gate switch (cpi->cpi_model) { 15957c478bd9Sstevel@tonic-gate case 4: 15967c478bd9Sstevel@tonic-gate brand = "Centaur C6"; 15977c478bd9Sstevel@tonic-gate break; 15987c478bd9Sstevel@tonic-gate case 8: 15997c478bd9Sstevel@tonic-gate brand = "Centaur C2"; 16007c478bd9Sstevel@tonic-gate break; 16017c478bd9Sstevel@tonic-gate case 9: 16027c478bd9Sstevel@tonic-gate brand = "Centaur C3"; 16037c478bd9Sstevel@tonic-gate break; 16047c478bd9Sstevel@tonic-gate default: 16057c478bd9Sstevel@tonic-gate break; 16067c478bd9Sstevel@tonic-gate } 16077c478bd9Sstevel@tonic-gate break; 16087c478bd9Sstevel@tonic-gate case X86_VENDOR_Rise: 16097c478bd9Sstevel@tonic-gate if (cpi->cpi_family == 5 && 16107c478bd9Sstevel@tonic-gate (cpi->cpi_model == 0 || cpi->cpi_model == 2)) 16117c478bd9Sstevel@tonic-gate brand = "Rise mP6"; 16127c478bd9Sstevel@tonic-gate break; 16137c478bd9Sstevel@tonic-gate case X86_VENDOR_SiS: 16147c478bd9Sstevel@tonic-gate if (cpi->cpi_family == 5 && cpi->cpi_model == 0) 16157c478bd9Sstevel@tonic-gate brand = "SiS 55x"; 16167c478bd9Sstevel@tonic-gate break; 16177c478bd9Sstevel@tonic-gate case X86_VENDOR_TM: 16187c478bd9Sstevel@tonic-gate if (cpi->cpi_family == 5 && cpi->cpi_model == 4) 16197c478bd9Sstevel@tonic-gate brand = "Transmeta Crusoe TM3x00 or TM5x00"; 16207c478bd9Sstevel@tonic-gate break; 16217c478bd9Sstevel@tonic-gate case X86_VENDOR_NSC: 16227c478bd9Sstevel@tonic-gate case X86_VENDOR_UMC: 16237c478bd9Sstevel@tonic-gate default: 16247c478bd9Sstevel@tonic-gate break; 16257c478bd9Sstevel@tonic-gate } 16267c478bd9Sstevel@tonic-gate if (brand) { 16277c478bd9Sstevel@tonic-gate (void) strcpy((char *)cpi->cpi_brandstr, brand); 16287c478bd9Sstevel@tonic-gate return; 16297c478bd9Sstevel@tonic-gate } 16307c478bd9Sstevel@tonic-gate 16317c478bd9Sstevel@tonic-gate /* 16327c478bd9Sstevel@tonic-gate * If all else fails ... 16337c478bd9Sstevel@tonic-gate */ 16347c478bd9Sstevel@tonic-gate (void) snprintf(cpi->cpi_brandstr, sizeof (cpi->cpi_brandstr), 16357c478bd9Sstevel@tonic-gate "%s %d.%d.%d", cpi->cpi_vendorstr, cpi->cpi_family, 16367c478bd9Sstevel@tonic-gate cpi->cpi_model, cpi->cpi_step); 16377c478bd9Sstevel@tonic-gate } 16387c478bd9Sstevel@tonic-gate 16397c478bd9Sstevel@tonic-gate /* 16407c478bd9Sstevel@tonic-gate * This routine is called just after kernel memory allocation 16417c478bd9Sstevel@tonic-gate * becomes available on cpu0, and as part of mp_startup() on 16427c478bd9Sstevel@tonic-gate * the other cpus. 16437c478bd9Sstevel@tonic-gate * 1644*d129bde2Sesaxe * Fixup the brand string, and collect any information from cpuid 1645*d129bde2Sesaxe * that requires dynamicically allocated storage to represent. 16467c478bd9Sstevel@tonic-gate */ 16477c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 16487c478bd9Sstevel@tonic-gate void 16497c478bd9Sstevel@tonic-gate cpuid_pass3(cpu_t *cpu) 16507c478bd9Sstevel@tonic-gate { 1651*d129bde2Sesaxe int i, max, shft, level, size; 1652*d129bde2Sesaxe struct cpuid_regs regs; 1653*d129bde2Sesaxe struct cpuid_regs *cp; 16547c478bd9Sstevel@tonic-gate struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 16557c478bd9Sstevel@tonic-gate 16567c478bd9Sstevel@tonic-gate ASSERT(cpi->cpi_pass == 2); 16577c478bd9Sstevel@tonic-gate 1658*d129bde2Sesaxe /* 1659*d129bde2Sesaxe * Function 4: Deterministic cache parameters 1660*d129bde2Sesaxe * 1661*d129bde2Sesaxe * Take this opportunity to detect the number of threads 1662*d129bde2Sesaxe * sharing the last level cache, and construct a corresponding 1663*d129bde2Sesaxe * cache id. The respective cpuid_info members are initialized 1664*d129bde2Sesaxe * to the default case of "no last level cache sharing". 1665*d129bde2Sesaxe */ 1666*d129bde2Sesaxe cpi->cpi_ncpu_shr_last_cache = 1; 1667*d129bde2Sesaxe cpi->cpi_last_lvl_cacheid = cpu->cpu_id; 1668*d129bde2Sesaxe 1669*d129bde2Sesaxe if (cpi->cpi_maxeax >= 4 && cpi->cpi_vendor == X86_VENDOR_Intel) { 1670*d129bde2Sesaxe 1671*d129bde2Sesaxe /* 1672*d129bde2Sesaxe * Find the # of elements (size) returned by fn 4, and along 1673*d129bde2Sesaxe * the way detect last level cache sharing details. 1674*d129bde2Sesaxe */ 1675*d129bde2Sesaxe bzero(®s, sizeof (regs)); 1676*d129bde2Sesaxe cp = ®s; 1677*d129bde2Sesaxe for (i = 0, max = 0; i < CPI_FN4_ECX_MAX; i++) { 1678*d129bde2Sesaxe cp->cp_eax = 4; 1679*d129bde2Sesaxe cp->cp_ecx = i; 1680*d129bde2Sesaxe 1681*d129bde2Sesaxe (void) __cpuid_insn(cp); 1682*d129bde2Sesaxe 1683*d129bde2Sesaxe if (CPI_CACHE_TYPE(cp) == 0) 1684*d129bde2Sesaxe break; 1685*d129bde2Sesaxe level = CPI_CACHE_LVL(cp); 1686*d129bde2Sesaxe if (level > max) { 1687*d129bde2Sesaxe max = level; 1688*d129bde2Sesaxe cpi->cpi_ncpu_shr_last_cache = 1689*d129bde2Sesaxe CPI_NTHR_SHR_CACHE(cp) + 1; 1690*d129bde2Sesaxe } 1691*d129bde2Sesaxe } 1692*d129bde2Sesaxe cpi->cpi_std_4_size = size = i; 1693*d129bde2Sesaxe 1694*d129bde2Sesaxe /* 1695*d129bde2Sesaxe * Allocate the cpi_std_4 array. The first element 1696*d129bde2Sesaxe * references the regs for fn 4, %ecx == 0, which 1697*d129bde2Sesaxe * cpuid_pass2() stashed in cpi->cpi_std[4]. 1698*d129bde2Sesaxe */ 1699*d129bde2Sesaxe if (size > 0) { 1700*d129bde2Sesaxe cpi->cpi_std_4 = 1701*d129bde2Sesaxe kmem_alloc(size * sizeof (cp), KM_SLEEP); 1702*d129bde2Sesaxe cpi->cpi_std_4[0] = &cpi->cpi_std[4]; 1703*d129bde2Sesaxe 1704*d129bde2Sesaxe /* 1705*d129bde2Sesaxe * Allocate storage to hold the additional regs 1706*d129bde2Sesaxe * for function 4, %ecx == 1 .. cpi_std_4_size. 1707*d129bde2Sesaxe * 1708*d129bde2Sesaxe * The regs for fn 4, %ecx == 0 has already 1709*d129bde2Sesaxe * been allocated as indicated above. 1710*d129bde2Sesaxe */ 1711*d129bde2Sesaxe for (i = 1; i < size; i++) { 1712*d129bde2Sesaxe cp = cpi->cpi_std_4[i] = 1713*d129bde2Sesaxe kmem_zalloc(sizeof (regs), KM_SLEEP); 1714*d129bde2Sesaxe cp->cp_eax = 4; 1715*d129bde2Sesaxe cp->cp_ecx = i; 1716*d129bde2Sesaxe 1717*d129bde2Sesaxe (void) __cpuid_insn(cp); 1718*d129bde2Sesaxe } 1719*d129bde2Sesaxe } 1720*d129bde2Sesaxe /* 1721*d129bde2Sesaxe * Determine the number of bits needed to represent 1722*d129bde2Sesaxe * the number of CPUs sharing the last level cache. 1723*d129bde2Sesaxe * 1724*d129bde2Sesaxe * Shift off that number of bits from the APIC id to 1725*d129bde2Sesaxe * derive the cache id. 1726*d129bde2Sesaxe */ 1727*d129bde2Sesaxe shft = 0; 1728*d129bde2Sesaxe for (i = 1; i < cpi->cpi_ncpu_shr_last_cache; i <<= 1) 1729*d129bde2Sesaxe shft++; 1730*d129bde2Sesaxe cpi->cpi_last_lvl_cacheid = CPI_APIC_ID(cpi) >> shft; 1731*d129bde2Sesaxe } 1732*d129bde2Sesaxe 1733*d129bde2Sesaxe /* 1734*d129bde2Sesaxe * Now fixup the brand string 1735*d129bde2Sesaxe */ 17367c478bd9Sstevel@tonic-gate if ((cpi->cpi_xmaxeax & 0x80000000) == 0) { 17377c478bd9Sstevel@tonic-gate fabricate_brandstr(cpi); 1738*d129bde2Sesaxe } else { 17397c478bd9Sstevel@tonic-gate 17407c478bd9Sstevel@tonic-gate /* 17417c478bd9Sstevel@tonic-gate * If we successfully extracted a brand string from the cpuid 17427c478bd9Sstevel@tonic-gate * instruction, clean it up by removing leading spaces and 17437c478bd9Sstevel@tonic-gate * similar junk. 17447c478bd9Sstevel@tonic-gate */ 17457c478bd9Sstevel@tonic-gate if (cpi->cpi_brandstr[0]) { 17467c478bd9Sstevel@tonic-gate size_t maxlen = sizeof (cpi->cpi_brandstr); 17477c478bd9Sstevel@tonic-gate char *src, *dst; 17487c478bd9Sstevel@tonic-gate 17497c478bd9Sstevel@tonic-gate dst = src = (char *)cpi->cpi_brandstr; 17507c478bd9Sstevel@tonic-gate src[maxlen - 1] = '\0'; 17517c478bd9Sstevel@tonic-gate /* 17527c478bd9Sstevel@tonic-gate * strip leading spaces 17537c478bd9Sstevel@tonic-gate */ 17547c478bd9Sstevel@tonic-gate while (*src == ' ') 17557c478bd9Sstevel@tonic-gate src++; 17567c478bd9Sstevel@tonic-gate /* 17577c478bd9Sstevel@tonic-gate * Remove any 'Genuine' or "Authentic" prefixes 17587c478bd9Sstevel@tonic-gate */ 17597c478bd9Sstevel@tonic-gate if (strncmp(src, "Genuine ", 8) == 0) 17607c478bd9Sstevel@tonic-gate src += 8; 17617c478bd9Sstevel@tonic-gate if (strncmp(src, "Authentic ", 10) == 0) 17627c478bd9Sstevel@tonic-gate src += 10; 17637c478bd9Sstevel@tonic-gate 17647c478bd9Sstevel@tonic-gate /* 17657c478bd9Sstevel@tonic-gate * Now do an in-place copy. 17667c478bd9Sstevel@tonic-gate * Map (R) to (r) and (TM) to (tm). 17677c478bd9Sstevel@tonic-gate * The era of teletypes is long gone, and there's 17687c478bd9Sstevel@tonic-gate * -really- no need to shout. 17697c478bd9Sstevel@tonic-gate */ 17707c478bd9Sstevel@tonic-gate while (*src != '\0') { 17717c478bd9Sstevel@tonic-gate if (src[0] == '(') { 17727c478bd9Sstevel@tonic-gate if (strncmp(src + 1, "R)", 2) == 0) { 17737c478bd9Sstevel@tonic-gate (void) strncpy(dst, "(r)", 3); 17747c478bd9Sstevel@tonic-gate src += 3; 17757c478bd9Sstevel@tonic-gate dst += 3; 17767c478bd9Sstevel@tonic-gate continue; 17777c478bd9Sstevel@tonic-gate } 17787c478bd9Sstevel@tonic-gate if (strncmp(src + 1, "TM)", 3) == 0) { 17797c478bd9Sstevel@tonic-gate (void) strncpy(dst, "(tm)", 4); 17807c478bd9Sstevel@tonic-gate src += 4; 17817c478bd9Sstevel@tonic-gate dst += 4; 17827c478bd9Sstevel@tonic-gate continue; 17837c478bd9Sstevel@tonic-gate } 17847c478bd9Sstevel@tonic-gate } 17857c478bd9Sstevel@tonic-gate *dst++ = *src++; 17867c478bd9Sstevel@tonic-gate } 17877c478bd9Sstevel@tonic-gate *dst = '\0'; 17887c478bd9Sstevel@tonic-gate 17897c478bd9Sstevel@tonic-gate /* 17907c478bd9Sstevel@tonic-gate * Finally, remove any trailing spaces 17917c478bd9Sstevel@tonic-gate */ 17927c478bd9Sstevel@tonic-gate while (--dst > cpi->cpi_brandstr) 17937c478bd9Sstevel@tonic-gate if (*dst == ' ') 17947c478bd9Sstevel@tonic-gate *dst = '\0'; 17957c478bd9Sstevel@tonic-gate else 17967c478bd9Sstevel@tonic-gate break; 17977c478bd9Sstevel@tonic-gate } else 17987c478bd9Sstevel@tonic-gate fabricate_brandstr(cpi); 1799*d129bde2Sesaxe } 18007c478bd9Sstevel@tonic-gate cpi->cpi_pass = 3; 18017c478bd9Sstevel@tonic-gate } 18027c478bd9Sstevel@tonic-gate 18037c478bd9Sstevel@tonic-gate /* 18047c478bd9Sstevel@tonic-gate * This routine is called out of bind_hwcap() much later in the life 18057c478bd9Sstevel@tonic-gate * of the kernel (post_startup()). The job of this routine is to resolve 18067c478bd9Sstevel@tonic-gate * the hardware feature support and kernel support for those features into 18077c478bd9Sstevel@tonic-gate * what we're actually going to tell applications via the aux vector. 18087c478bd9Sstevel@tonic-gate */ 18097c478bd9Sstevel@tonic-gate uint_t 18107c478bd9Sstevel@tonic-gate cpuid_pass4(cpu_t *cpu) 18117c478bd9Sstevel@tonic-gate { 18127c478bd9Sstevel@tonic-gate struct cpuid_info *cpi; 18137c478bd9Sstevel@tonic-gate uint_t hwcap_flags = 0; 18147c478bd9Sstevel@tonic-gate 18157c478bd9Sstevel@tonic-gate if (cpu == NULL) 18167c478bd9Sstevel@tonic-gate cpu = CPU; 18177c478bd9Sstevel@tonic-gate cpi = cpu->cpu_m.mcpu_cpi; 18187c478bd9Sstevel@tonic-gate 18197c478bd9Sstevel@tonic-gate ASSERT(cpi->cpi_pass == 3); 18207c478bd9Sstevel@tonic-gate 18217c478bd9Sstevel@tonic-gate if (cpi->cpi_maxeax >= 1) { 18227c478bd9Sstevel@tonic-gate uint32_t *edx = &cpi->cpi_support[STD_EDX_FEATURES]; 18237c478bd9Sstevel@tonic-gate uint32_t *ecx = &cpi->cpi_support[STD_ECX_FEATURES]; 18247c478bd9Sstevel@tonic-gate 18257c478bd9Sstevel@tonic-gate *edx = CPI_FEATURES_EDX(cpi); 18267c478bd9Sstevel@tonic-gate *ecx = CPI_FEATURES_ECX(cpi); 18277c478bd9Sstevel@tonic-gate 18287c478bd9Sstevel@tonic-gate /* 18297c478bd9Sstevel@tonic-gate * [these require explicit kernel support] 18307c478bd9Sstevel@tonic-gate */ 18317c478bd9Sstevel@tonic-gate if ((x86_feature & X86_SEP) == 0) 18327c478bd9Sstevel@tonic-gate *edx &= ~CPUID_INTC_EDX_SEP; 18337c478bd9Sstevel@tonic-gate 18347c478bd9Sstevel@tonic-gate if ((x86_feature & X86_SSE) == 0) 18357c478bd9Sstevel@tonic-gate *edx &= ~(CPUID_INTC_EDX_FXSR|CPUID_INTC_EDX_SSE); 18367c478bd9Sstevel@tonic-gate if ((x86_feature & X86_SSE2) == 0) 18377c478bd9Sstevel@tonic-gate *edx &= ~CPUID_INTC_EDX_SSE2; 18387c478bd9Sstevel@tonic-gate 18397c478bd9Sstevel@tonic-gate if ((x86_feature & X86_HTT) == 0) 18407c478bd9Sstevel@tonic-gate *edx &= ~CPUID_INTC_EDX_HTT; 18417c478bd9Sstevel@tonic-gate 18427c478bd9Sstevel@tonic-gate if ((x86_feature & X86_SSE3) == 0) 18437c478bd9Sstevel@tonic-gate *ecx &= ~CPUID_INTC_ECX_SSE3; 18447c478bd9Sstevel@tonic-gate 18457c478bd9Sstevel@tonic-gate /* 18467c478bd9Sstevel@tonic-gate * [no explicit support required beyond x87 fp context] 18477c478bd9Sstevel@tonic-gate */ 18487c478bd9Sstevel@tonic-gate if (!fpu_exists) 18497c478bd9Sstevel@tonic-gate *edx &= ~(CPUID_INTC_EDX_FPU | CPUID_INTC_EDX_MMX); 18507c478bd9Sstevel@tonic-gate 18517c478bd9Sstevel@tonic-gate /* 18527c478bd9Sstevel@tonic-gate * Now map the supported feature vector to things that we 18537c478bd9Sstevel@tonic-gate * think userland will care about. 18547c478bd9Sstevel@tonic-gate */ 18557c478bd9Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_SEP) 18567c478bd9Sstevel@tonic-gate hwcap_flags |= AV_386_SEP; 18577c478bd9Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_SSE) 18587c478bd9Sstevel@tonic-gate hwcap_flags |= AV_386_FXSR | AV_386_SSE; 18597c478bd9Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_SSE2) 18607c478bd9Sstevel@tonic-gate hwcap_flags |= AV_386_SSE2; 18617c478bd9Sstevel@tonic-gate if (*ecx & CPUID_INTC_ECX_SSE3) 18627c478bd9Sstevel@tonic-gate hwcap_flags |= AV_386_SSE3; 18637c478bd9Sstevel@tonic-gate 18647c478bd9Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_FPU) 18657c478bd9Sstevel@tonic-gate hwcap_flags |= AV_386_FPU; 18667c478bd9Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_MMX) 18677c478bd9Sstevel@tonic-gate hwcap_flags |= AV_386_MMX; 18687c478bd9Sstevel@tonic-gate 18697c478bd9Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_TSC) 18707c478bd9Sstevel@tonic-gate hwcap_flags |= AV_386_TSC; 18717c478bd9Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_CX8) 18727c478bd9Sstevel@tonic-gate hwcap_flags |= AV_386_CX8; 18737c478bd9Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_CMOV) 18747c478bd9Sstevel@tonic-gate hwcap_flags |= AV_386_CMOV; 18757c478bd9Sstevel@tonic-gate if (*ecx & CPUID_INTC_ECX_MON) 18767c478bd9Sstevel@tonic-gate hwcap_flags |= AV_386_MON; 18777c478bd9Sstevel@tonic-gate if (*ecx & CPUID_INTC_ECX_CX16) 18787c478bd9Sstevel@tonic-gate hwcap_flags |= AV_386_CX16; 18797c478bd9Sstevel@tonic-gate } 18807c478bd9Sstevel@tonic-gate 18818949bcd6Sandrei if (x86_feature & X86_HTT) 18827c478bd9Sstevel@tonic-gate hwcap_flags |= AV_386_PAUSE; 18837c478bd9Sstevel@tonic-gate 18847c478bd9Sstevel@tonic-gate if (cpi->cpi_xmaxeax < 0x80000001) 18857c478bd9Sstevel@tonic-gate goto pass4_done; 18867c478bd9Sstevel@tonic-gate 18877c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 18888949bcd6Sandrei struct cpuid_regs cp; 1889ae115bc7Smrj uint32_t *edx, *ecx; 18907c478bd9Sstevel@tonic-gate 1891ae115bc7Smrj case X86_VENDOR_Intel: 1892ae115bc7Smrj /* 1893ae115bc7Smrj * Seems like Intel duplicated what we necessary 1894ae115bc7Smrj * here to make the initial crop of 64-bit OS's work. 1895ae115bc7Smrj * Hopefully, those are the only "extended" bits 1896ae115bc7Smrj * they'll add. 1897ae115bc7Smrj */ 1898ae115bc7Smrj /*FALLTHROUGH*/ 1899ae115bc7Smrj 19007c478bd9Sstevel@tonic-gate case X86_VENDOR_AMD: 19017c478bd9Sstevel@tonic-gate edx = &cpi->cpi_support[AMD_EDX_FEATURES]; 1902ae115bc7Smrj ecx = &cpi->cpi_support[AMD_ECX_FEATURES]; 19037c478bd9Sstevel@tonic-gate 19047c478bd9Sstevel@tonic-gate *edx = CPI_FEATURES_XTD_EDX(cpi); 1905ae115bc7Smrj *ecx = CPI_FEATURES_XTD_ECX(cpi); 1906ae115bc7Smrj 1907ae115bc7Smrj /* 1908ae115bc7Smrj * [these features require explicit kernel support] 1909ae115bc7Smrj */ 1910ae115bc7Smrj switch (cpi->cpi_vendor) { 1911ae115bc7Smrj case X86_VENDOR_Intel: 1912ae115bc7Smrj break; 1913ae115bc7Smrj 1914ae115bc7Smrj case X86_VENDOR_AMD: 1915ae115bc7Smrj if ((x86_feature & X86_TSCP) == 0) 1916ae115bc7Smrj *edx &= ~CPUID_AMD_EDX_TSCP; 1917ae115bc7Smrj break; 1918ae115bc7Smrj 1919ae115bc7Smrj default: 1920ae115bc7Smrj break; 1921ae115bc7Smrj } 19227c478bd9Sstevel@tonic-gate 19237c478bd9Sstevel@tonic-gate /* 19247c478bd9Sstevel@tonic-gate * [no explicit support required beyond 19257c478bd9Sstevel@tonic-gate * x87 fp context and exception handlers] 19267c478bd9Sstevel@tonic-gate */ 19277c478bd9Sstevel@tonic-gate if (!fpu_exists) 19287c478bd9Sstevel@tonic-gate *edx &= ~(CPUID_AMD_EDX_MMXamd | 19297c478bd9Sstevel@tonic-gate CPUID_AMD_EDX_3DNow | CPUID_AMD_EDX_3DNowx); 19307c478bd9Sstevel@tonic-gate 19317c478bd9Sstevel@tonic-gate if ((x86_feature & X86_NX) == 0) 19327c478bd9Sstevel@tonic-gate *edx &= ~CPUID_AMD_EDX_NX; 1933ae115bc7Smrj #if !defined(__amd64) 19347c478bd9Sstevel@tonic-gate *edx &= ~CPUID_AMD_EDX_LM; 19357c478bd9Sstevel@tonic-gate #endif 19367c478bd9Sstevel@tonic-gate /* 19377c478bd9Sstevel@tonic-gate * Now map the supported feature vector to 19387c478bd9Sstevel@tonic-gate * things that we think userland will care about. 19397c478bd9Sstevel@tonic-gate */ 1940ae115bc7Smrj #if defined(__amd64) 19417c478bd9Sstevel@tonic-gate if (*edx & CPUID_AMD_EDX_SYSC) 19427c478bd9Sstevel@tonic-gate hwcap_flags |= AV_386_AMD_SYSC; 1943ae115bc7Smrj #endif 19447c478bd9Sstevel@tonic-gate if (*edx & CPUID_AMD_EDX_MMXamd) 19457c478bd9Sstevel@tonic-gate hwcap_flags |= AV_386_AMD_MMX; 19467c478bd9Sstevel@tonic-gate if (*edx & CPUID_AMD_EDX_3DNow) 19477c478bd9Sstevel@tonic-gate hwcap_flags |= AV_386_AMD_3DNow; 19487c478bd9Sstevel@tonic-gate if (*edx & CPUID_AMD_EDX_3DNowx) 19497c478bd9Sstevel@tonic-gate hwcap_flags |= AV_386_AMD_3DNowx; 1950ae115bc7Smrj 1951ae115bc7Smrj switch (cpi->cpi_vendor) { 1952ae115bc7Smrj case X86_VENDOR_AMD: 1953ae115bc7Smrj if (*edx & CPUID_AMD_EDX_TSCP) 1954ae115bc7Smrj hwcap_flags |= AV_386_TSCP; 1955ae115bc7Smrj if (*ecx & CPUID_AMD_ECX_AHF64) 1956ae115bc7Smrj hwcap_flags |= AV_386_AHF; 1957ae115bc7Smrj break; 1958ae115bc7Smrj 1959ae115bc7Smrj case X86_VENDOR_Intel: 1960ae115bc7Smrj /* 1961ae115bc7Smrj * Aarrgh. 1962ae115bc7Smrj * Intel uses a different bit in the same word. 1963ae115bc7Smrj */ 1964ae115bc7Smrj if (*ecx & CPUID_INTC_ECX_AHF64) 1965ae115bc7Smrj hwcap_flags |= AV_386_AHF; 1966ae115bc7Smrj break; 1967ae115bc7Smrj 1968ae115bc7Smrj default: 1969ae115bc7Smrj break; 1970ae115bc7Smrj } 19717c478bd9Sstevel@tonic-gate break; 19727c478bd9Sstevel@tonic-gate 19737c478bd9Sstevel@tonic-gate case X86_VENDOR_TM: 19748949bcd6Sandrei cp.cp_eax = 0x80860001; 19758949bcd6Sandrei (void) __cpuid_insn(&cp); 19768949bcd6Sandrei cpi->cpi_support[TM_EDX_FEATURES] = cp.cp_edx; 19777c478bd9Sstevel@tonic-gate break; 19787c478bd9Sstevel@tonic-gate 19797c478bd9Sstevel@tonic-gate default: 19807c478bd9Sstevel@tonic-gate break; 19817c478bd9Sstevel@tonic-gate } 19827c478bd9Sstevel@tonic-gate 19837c478bd9Sstevel@tonic-gate pass4_done: 19847c478bd9Sstevel@tonic-gate cpi->cpi_pass = 4; 19857c478bd9Sstevel@tonic-gate return (hwcap_flags); 19867c478bd9Sstevel@tonic-gate } 19877c478bd9Sstevel@tonic-gate 19887c478bd9Sstevel@tonic-gate 19897c478bd9Sstevel@tonic-gate /* 19907c478bd9Sstevel@tonic-gate * Simulate the cpuid instruction using the data we previously 19917c478bd9Sstevel@tonic-gate * captured about this CPU. We try our best to return the truth 19927c478bd9Sstevel@tonic-gate * about the hardware, independently of kernel support. 19937c478bd9Sstevel@tonic-gate */ 19947c478bd9Sstevel@tonic-gate uint32_t 19958949bcd6Sandrei cpuid_insn(cpu_t *cpu, struct cpuid_regs *cp) 19967c478bd9Sstevel@tonic-gate { 19977c478bd9Sstevel@tonic-gate struct cpuid_info *cpi; 19988949bcd6Sandrei struct cpuid_regs *xcp; 19997c478bd9Sstevel@tonic-gate 20007c478bd9Sstevel@tonic-gate if (cpu == NULL) 20017c478bd9Sstevel@tonic-gate cpu = CPU; 20027c478bd9Sstevel@tonic-gate cpi = cpu->cpu_m.mcpu_cpi; 20037c478bd9Sstevel@tonic-gate 20047c478bd9Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 3)); 20057c478bd9Sstevel@tonic-gate 20067c478bd9Sstevel@tonic-gate /* 20077c478bd9Sstevel@tonic-gate * CPUID data is cached in two separate places: cpi_std for standard 20087c478bd9Sstevel@tonic-gate * CPUID functions, and cpi_extd for extended CPUID functions. 20097c478bd9Sstevel@tonic-gate */ 20108949bcd6Sandrei if (cp->cp_eax <= cpi->cpi_maxeax && cp->cp_eax < NMAX_CPI_STD) 20118949bcd6Sandrei xcp = &cpi->cpi_std[cp->cp_eax]; 20128949bcd6Sandrei else if (cp->cp_eax >= 0x80000000 && cp->cp_eax <= cpi->cpi_xmaxeax && 20138949bcd6Sandrei cp->cp_eax < 0x80000000 + NMAX_CPI_EXTD) 20148949bcd6Sandrei xcp = &cpi->cpi_extd[cp->cp_eax - 0x80000000]; 20157c478bd9Sstevel@tonic-gate else 20167c478bd9Sstevel@tonic-gate /* 20177c478bd9Sstevel@tonic-gate * The caller is asking for data from an input parameter which 20187c478bd9Sstevel@tonic-gate * the kernel has not cached. In this case we go fetch from 20197c478bd9Sstevel@tonic-gate * the hardware and return the data directly to the user. 20207c478bd9Sstevel@tonic-gate */ 20218949bcd6Sandrei return (__cpuid_insn(cp)); 20228949bcd6Sandrei 20238949bcd6Sandrei cp->cp_eax = xcp->cp_eax; 20248949bcd6Sandrei cp->cp_ebx = xcp->cp_ebx; 20258949bcd6Sandrei cp->cp_ecx = xcp->cp_ecx; 20268949bcd6Sandrei cp->cp_edx = xcp->cp_edx; 20277c478bd9Sstevel@tonic-gate return (cp->cp_eax); 20287c478bd9Sstevel@tonic-gate } 20297c478bd9Sstevel@tonic-gate 20307c478bd9Sstevel@tonic-gate int 20317c478bd9Sstevel@tonic-gate cpuid_checkpass(cpu_t *cpu, int pass) 20327c478bd9Sstevel@tonic-gate { 20337c478bd9Sstevel@tonic-gate return (cpu != NULL && cpu->cpu_m.mcpu_cpi != NULL && 20347c478bd9Sstevel@tonic-gate cpu->cpu_m.mcpu_cpi->cpi_pass >= pass); 20357c478bd9Sstevel@tonic-gate } 20367c478bd9Sstevel@tonic-gate 20377c478bd9Sstevel@tonic-gate int 20387c478bd9Sstevel@tonic-gate cpuid_getbrandstr(cpu_t *cpu, char *s, size_t n) 20397c478bd9Sstevel@tonic-gate { 20407c478bd9Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 3)); 20417c478bd9Sstevel@tonic-gate 20427c478bd9Sstevel@tonic-gate return (snprintf(s, n, "%s", cpu->cpu_m.mcpu_cpi->cpi_brandstr)); 20437c478bd9Sstevel@tonic-gate } 20447c478bd9Sstevel@tonic-gate 20457c478bd9Sstevel@tonic-gate int 20468949bcd6Sandrei cpuid_is_cmt(cpu_t *cpu) 20477c478bd9Sstevel@tonic-gate { 20487c478bd9Sstevel@tonic-gate if (cpu == NULL) 20497c478bd9Sstevel@tonic-gate cpu = CPU; 20507c478bd9Sstevel@tonic-gate 20517c478bd9Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 20527c478bd9Sstevel@tonic-gate 20537c478bd9Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_chipid >= 0); 20547c478bd9Sstevel@tonic-gate } 20557c478bd9Sstevel@tonic-gate 20567c478bd9Sstevel@tonic-gate /* 20577c478bd9Sstevel@tonic-gate * AMD and Intel both implement the 64-bit variant of the syscall 20587c478bd9Sstevel@tonic-gate * instruction (syscallq), so if there's -any- support for syscall, 20597c478bd9Sstevel@tonic-gate * cpuid currently says "yes, we support this". 20607c478bd9Sstevel@tonic-gate * 20617c478bd9Sstevel@tonic-gate * However, Intel decided to -not- implement the 32-bit variant of the 20627c478bd9Sstevel@tonic-gate * syscall instruction, so we provide a predicate to allow our caller 20637c478bd9Sstevel@tonic-gate * to test that subtlety here. 20647c478bd9Sstevel@tonic-gate */ 20657c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 20667c478bd9Sstevel@tonic-gate int 20677c478bd9Sstevel@tonic-gate cpuid_syscall32_insn(cpu_t *cpu) 20687c478bd9Sstevel@tonic-gate { 20697c478bd9Sstevel@tonic-gate ASSERT(cpuid_checkpass((cpu == NULL ? CPU : cpu), 1)); 20707c478bd9Sstevel@tonic-gate 2071ae115bc7Smrj if (cpu == NULL) 2072ae115bc7Smrj cpu = CPU; 2073ae115bc7Smrj 2074ae115bc7Smrj /*CSTYLED*/ 2075ae115bc7Smrj { 2076ae115bc7Smrj struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 2077ae115bc7Smrj 2078ae115bc7Smrj if (cpi->cpi_vendor == X86_VENDOR_AMD && 2079ae115bc7Smrj cpi->cpi_xmaxeax >= 0x80000001 && 2080ae115bc7Smrj (CPI_FEATURES_XTD_EDX(cpi) & CPUID_AMD_EDX_SYSC)) 2081ae115bc7Smrj return (1); 2082ae115bc7Smrj } 20837c478bd9Sstevel@tonic-gate return (0); 20847c478bd9Sstevel@tonic-gate } 20857c478bd9Sstevel@tonic-gate 20867c478bd9Sstevel@tonic-gate int 20877c478bd9Sstevel@tonic-gate cpuid_getidstr(cpu_t *cpu, char *s, size_t n) 20887c478bd9Sstevel@tonic-gate { 20897c478bd9Sstevel@tonic-gate struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 20907c478bd9Sstevel@tonic-gate 20917c478bd9Sstevel@tonic-gate static const char fmt[] = 2092ecfa43a5Sdmick "x86 (%s %X family %d model %d step %d clock %d MHz)"; 20937c478bd9Sstevel@tonic-gate static const char fmt_ht[] = 2094ecfa43a5Sdmick "x86 (chipid 0x%x %s %X family %d model %d step %d clock %d MHz)"; 20957c478bd9Sstevel@tonic-gate 20967c478bd9Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 20977c478bd9Sstevel@tonic-gate 20988949bcd6Sandrei if (cpuid_is_cmt(cpu)) 20997c478bd9Sstevel@tonic-gate return (snprintf(s, n, fmt_ht, cpi->cpi_chipid, 2100ecfa43a5Sdmick cpi->cpi_vendorstr, cpi->cpi_std[1].cp_eax, 2101ecfa43a5Sdmick cpi->cpi_family, cpi->cpi_model, 21027c478bd9Sstevel@tonic-gate cpi->cpi_step, cpu->cpu_type_info.pi_clock)); 21037c478bd9Sstevel@tonic-gate return (snprintf(s, n, fmt, 2104ecfa43a5Sdmick cpi->cpi_vendorstr, cpi->cpi_std[1].cp_eax, 2105ecfa43a5Sdmick cpi->cpi_family, cpi->cpi_model, 21067c478bd9Sstevel@tonic-gate cpi->cpi_step, cpu->cpu_type_info.pi_clock)); 21077c478bd9Sstevel@tonic-gate } 21087c478bd9Sstevel@tonic-gate 21097c478bd9Sstevel@tonic-gate const char * 21107c478bd9Sstevel@tonic-gate cpuid_getvendorstr(cpu_t *cpu) 21117c478bd9Sstevel@tonic-gate { 21127c478bd9Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 21137c478bd9Sstevel@tonic-gate return ((const char *)cpu->cpu_m.mcpu_cpi->cpi_vendorstr); 21147c478bd9Sstevel@tonic-gate } 21157c478bd9Sstevel@tonic-gate 21167c478bd9Sstevel@tonic-gate uint_t 21177c478bd9Sstevel@tonic-gate cpuid_getvendor(cpu_t *cpu) 21187c478bd9Sstevel@tonic-gate { 21197c478bd9Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 21207c478bd9Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_vendor); 21217c478bd9Sstevel@tonic-gate } 21227c478bd9Sstevel@tonic-gate 21237c478bd9Sstevel@tonic-gate uint_t 21247c478bd9Sstevel@tonic-gate cpuid_getfamily(cpu_t *cpu) 21257c478bd9Sstevel@tonic-gate { 21267c478bd9Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 21277c478bd9Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_family); 21287c478bd9Sstevel@tonic-gate } 21297c478bd9Sstevel@tonic-gate 21307c478bd9Sstevel@tonic-gate uint_t 21317c478bd9Sstevel@tonic-gate cpuid_getmodel(cpu_t *cpu) 21327c478bd9Sstevel@tonic-gate { 21337c478bd9Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 21347c478bd9Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_model); 21357c478bd9Sstevel@tonic-gate } 21367c478bd9Sstevel@tonic-gate 21377c478bd9Sstevel@tonic-gate uint_t 21387c478bd9Sstevel@tonic-gate cpuid_get_ncpu_per_chip(cpu_t *cpu) 21397c478bd9Sstevel@tonic-gate { 21407c478bd9Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 21417c478bd9Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_ncpu_per_chip); 21427c478bd9Sstevel@tonic-gate } 21437c478bd9Sstevel@tonic-gate 21447c478bd9Sstevel@tonic-gate uint_t 21458949bcd6Sandrei cpuid_get_ncore_per_chip(cpu_t *cpu) 21468949bcd6Sandrei { 21478949bcd6Sandrei ASSERT(cpuid_checkpass(cpu, 1)); 21488949bcd6Sandrei return (cpu->cpu_m.mcpu_cpi->cpi_ncore_per_chip); 21498949bcd6Sandrei } 21508949bcd6Sandrei 21518949bcd6Sandrei uint_t 2152*d129bde2Sesaxe cpuid_get_ncpu_sharing_last_cache(cpu_t *cpu) 2153*d129bde2Sesaxe { 2154*d129bde2Sesaxe ASSERT(cpuid_checkpass(cpu, 2)); 2155*d129bde2Sesaxe return (cpu->cpu_m.mcpu_cpi->cpi_ncpu_shr_last_cache); 2156*d129bde2Sesaxe } 2157*d129bde2Sesaxe 2158*d129bde2Sesaxe id_t 2159*d129bde2Sesaxe cpuid_get_last_lvl_cacheid(cpu_t *cpu) 2160*d129bde2Sesaxe { 2161*d129bde2Sesaxe ASSERT(cpuid_checkpass(cpu, 2)); 2162*d129bde2Sesaxe return (cpu->cpu_m.mcpu_cpi->cpi_last_lvl_cacheid); 2163*d129bde2Sesaxe } 2164*d129bde2Sesaxe 2165*d129bde2Sesaxe uint_t 21667c478bd9Sstevel@tonic-gate cpuid_getstep(cpu_t *cpu) 21677c478bd9Sstevel@tonic-gate { 21687c478bd9Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 21697c478bd9Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_step); 21707c478bd9Sstevel@tonic-gate } 21717c478bd9Sstevel@tonic-gate 21722449e17fSsherrym uint_t 21732449e17fSsherrym cpuid_getsig(struct cpu *cpu) 21742449e17fSsherrym { 21752449e17fSsherrym ASSERT(cpuid_checkpass(cpu, 1)); 21762449e17fSsherrym return (cpu->cpu_m.mcpu_cpi->cpi_std[1].cp_eax); 21772449e17fSsherrym } 21782449e17fSsherrym 21798a40a695Sgavinm uint32_t 21808a40a695Sgavinm cpuid_getchiprev(struct cpu *cpu) 21818a40a695Sgavinm { 21828a40a695Sgavinm ASSERT(cpuid_checkpass(cpu, 1)); 21838a40a695Sgavinm return (cpu->cpu_m.mcpu_cpi->cpi_chiprev); 21848a40a695Sgavinm } 21858a40a695Sgavinm 21868a40a695Sgavinm const char * 21878a40a695Sgavinm cpuid_getchiprevstr(struct cpu *cpu) 21888a40a695Sgavinm { 21898a40a695Sgavinm ASSERT(cpuid_checkpass(cpu, 1)); 21908a40a695Sgavinm return (cpu->cpu_m.mcpu_cpi->cpi_chiprevstr); 21918a40a695Sgavinm } 21928a40a695Sgavinm 21938a40a695Sgavinm uint32_t 21948a40a695Sgavinm cpuid_getsockettype(struct cpu *cpu) 21958a40a695Sgavinm { 21968a40a695Sgavinm ASSERT(cpuid_checkpass(cpu, 1)); 21978a40a695Sgavinm return (cpu->cpu_m.mcpu_cpi->cpi_socket); 21988a40a695Sgavinm } 21998a40a695Sgavinm 2200fb2f18f8Sesaxe int 2201fb2f18f8Sesaxe cpuid_get_chipid(cpu_t *cpu) 22027c478bd9Sstevel@tonic-gate { 22037c478bd9Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 22047c478bd9Sstevel@tonic-gate 22058949bcd6Sandrei if (cpuid_is_cmt(cpu)) 22067c478bd9Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_chipid); 22077c478bd9Sstevel@tonic-gate return (cpu->cpu_id); 22087c478bd9Sstevel@tonic-gate } 22097c478bd9Sstevel@tonic-gate 22108949bcd6Sandrei id_t 2211fb2f18f8Sesaxe cpuid_get_coreid(cpu_t *cpu) 22128949bcd6Sandrei { 22138949bcd6Sandrei ASSERT(cpuid_checkpass(cpu, 1)); 22148949bcd6Sandrei return (cpu->cpu_m.mcpu_cpi->cpi_coreid); 22158949bcd6Sandrei } 22168949bcd6Sandrei 22177c478bd9Sstevel@tonic-gate int 2218fb2f18f8Sesaxe cpuid_get_clogid(cpu_t *cpu) 22197c478bd9Sstevel@tonic-gate { 22207c478bd9Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 22217c478bd9Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_clogid); 22227c478bd9Sstevel@tonic-gate } 22237c478bd9Sstevel@tonic-gate 22247c478bd9Sstevel@tonic-gate void 22257c478bd9Sstevel@tonic-gate cpuid_get_addrsize(cpu_t *cpu, uint_t *pabits, uint_t *vabits) 22267c478bd9Sstevel@tonic-gate { 22277c478bd9Sstevel@tonic-gate struct cpuid_info *cpi; 22287c478bd9Sstevel@tonic-gate 22297c478bd9Sstevel@tonic-gate if (cpu == NULL) 22307c478bd9Sstevel@tonic-gate cpu = CPU; 22317c478bd9Sstevel@tonic-gate cpi = cpu->cpu_m.mcpu_cpi; 22327c478bd9Sstevel@tonic-gate 22337c478bd9Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 22347c478bd9Sstevel@tonic-gate 22357c478bd9Sstevel@tonic-gate if (pabits) 22367c478bd9Sstevel@tonic-gate *pabits = cpi->cpi_pabits; 22377c478bd9Sstevel@tonic-gate if (vabits) 22387c478bd9Sstevel@tonic-gate *vabits = cpi->cpi_vabits; 22397c478bd9Sstevel@tonic-gate } 22407c478bd9Sstevel@tonic-gate 22417c478bd9Sstevel@tonic-gate /* 22427c478bd9Sstevel@tonic-gate * Returns the number of data TLB entries for a corresponding 22437c478bd9Sstevel@tonic-gate * pagesize. If it can't be computed, or isn't known, the 22447c478bd9Sstevel@tonic-gate * routine returns zero. If you ask about an architecturally 22457c478bd9Sstevel@tonic-gate * impossible pagesize, the routine will panic (so that the 22467c478bd9Sstevel@tonic-gate * hat implementor knows that things are inconsistent.) 22477c478bd9Sstevel@tonic-gate */ 22487c478bd9Sstevel@tonic-gate uint_t 22497c478bd9Sstevel@tonic-gate cpuid_get_dtlb_nent(cpu_t *cpu, size_t pagesize) 22507c478bd9Sstevel@tonic-gate { 22517c478bd9Sstevel@tonic-gate struct cpuid_info *cpi; 22527c478bd9Sstevel@tonic-gate uint_t dtlb_nent = 0; 22537c478bd9Sstevel@tonic-gate 22547c478bd9Sstevel@tonic-gate if (cpu == NULL) 22557c478bd9Sstevel@tonic-gate cpu = CPU; 22567c478bd9Sstevel@tonic-gate cpi = cpu->cpu_m.mcpu_cpi; 22577c478bd9Sstevel@tonic-gate 22587c478bd9Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 22597c478bd9Sstevel@tonic-gate 22607c478bd9Sstevel@tonic-gate /* 22617c478bd9Sstevel@tonic-gate * Check the L2 TLB info 22627c478bd9Sstevel@tonic-gate */ 22637c478bd9Sstevel@tonic-gate if (cpi->cpi_xmaxeax >= 0x80000006) { 22648949bcd6Sandrei struct cpuid_regs *cp = &cpi->cpi_extd[6]; 22657c478bd9Sstevel@tonic-gate 22667c478bd9Sstevel@tonic-gate switch (pagesize) { 22677c478bd9Sstevel@tonic-gate 22687c478bd9Sstevel@tonic-gate case 4 * 1024: 22697c478bd9Sstevel@tonic-gate /* 22707c478bd9Sstevel@tonic-gate * All zero in the top 16 bits of the register 22717c478bd9Sstevel@tonic-gate * indicates a unified TLB. Size is in low 16 bits. 22727c478bd9Sstevel@tonic-gate */ 22737c478bd9Sstevel@tonic-gate if ((cp->cp_ebx & 0xffff0000) == 0) 22747c478bd9Sstevel@tonic-gate dtlb_nent = cp->cp_ebx & 0x0000ffff; 22757c478bd9Sstevel@tonic-gate else 22767c478bd9Sstevel@tonic-gate dtlb_nent = BITX(cp->cp_ebx, 27, 16); 22777c478bd9Sstevel@tonic-gate break; 22787c478bd9Sstevel@tonic-gate 22797c478bd9Sstevel@tonic-gate case 2 * 1024 * 1024: 22807c478bd9Sstevel@tonic-gate if ((cp->cp_eax & 0xffff0000) == 0) 22817c478bd9Sstevel@tonic-gate dtlb_nent = cp->cp_eax & 0x0000ffff; 22827c478bd9Sstevel@tonic-gate else 22837c478bd9Sstevel@tonic-gate dtlb_nent = BITX(cp->cp_eax, 27, 16); 22847c478bd9Sstevel@tonic-gate break; 22857c478bd9Sstevel@tonic-gate 22867c478bd9Sstevel@tonic-gate default: 22877c478bd9Sstevel@tonic-gate panic("unknown L2 pagesize"); 22887c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 22897c478bd9Sstevel@tonic-gate } 22907c478bd9Sstevel@tonic-gate } 22917c478bd9Sstevel@tonic-gate 22927c478bd9Sstevel@tonic-gate if (dtlb_nent != 0) 22937c478bd9Sstevel@tonic-gate return (dtlb_nent); 22947c478bd9Sstevel@tonic-gate 22957c478bd9Sstevel@tonic-gate /* 22967c478bd9Sstevel@tonic-gate * No L2 TLB support for this size, try L1. 22977c478bd9Sstevel@tonic-gate */ 22987c478bd9Sstevel@tonic-gate if (cpi->cpi_xmaxeax >= 0x80000005) { 22998949bcd6Sandrei struct cpuid_regs *cp = &cpi->cpi_extd[5]; 23007c478bd9Sstevel@tonic-gate 23017c478bd9Sstevel@tonic-gate switch (pagesize) { 23027c478bd9Sstevel@tonic-gate case 4 * 1024: 23037c478bd9Sstevel@tonic-gate dtlb_nent = BITX(cp->cp_ebx, 23, 16); 23047c478bd9Sstevel@tonic-gate break; 23057c478bd9Sstevel@tonic-gate case 2 * 1024 * 1024: 23067c478bd9Sstevel@tonic-gate dtlb_nent = BITX(cp->cp_eax, 23, 16); 23077c478bd9Sstevel@tonic-gate break; 23087c478bd9Sstevel@tonic-gate default: 23097c478bd9Sstevel@tonic-gate panic("unknown L1 d-TLB pagesize"); 23107c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 23117c478bd9Sstevel@tonic-gate } 23127c478bd9Sstevel@tonic-gate } 23137c478bd9Sstevel@tonic-gate 23147c478bd9Sstevel@tonic-gate return (dtlb_nent); 23157c478bd9Sstevel@tonic-gate } 23167c478bd9Sstevel@tonic-gate 23177c478bd9Sstevel@tonic-gate /* 23187c478bd9Sstevel@tonic-gate * Return 0 if the erratum is not present or not applicable, positive 23197c478bd9Sstevel@tonic-gate * if it is, and negative if the status of the erratum is unknown. 23207c478bd9Sstevel@tonic-gate * 23217c478bd9Sstevel@tonic-gate * See "Revision Guide for AMD Athlon(tm) 64 and AMD Opteron(tm) 23222201b277Skucharsk * Processors" #25759, Rev 3.57, August 2005 23237c478bd9Sstevel@tonic-gate */ 23247c478bd9Sstevel@tonic-gate int 23257c478bd9Sstevel@tonic-gate cpuid_opteron_erratum(cpu_t *cpu, uint_t erratum) 23267c478bd9Sstevel@tonic-gate { 23277c478bd9Sstevel@tonic-gate struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 23288949bcd6Sandrei uint_t eax; 23297c478bd9Sstevel@tonic-gate 2330ea99987eSsethg /* 2331ea99987eSsethg * Bail out if this CPU isn't an AMD CPU, or if it's 2332ea99987eSsethg * a legacy (32-bit) AMD CPU. 2333ea99987eSsethg */ 2334ea99987eSsethg if (cpi->cpi_vendor != X86_VENDOR_AMD || 2335875b116eSkchow cpi->cpi_family == 4 || cpi->cpi_family == 5 || 2336875b116eSkchow cpi->cpi_family == 6) 23378a40a695Sgavinm 23387c478bd9Sstevel@tonic-gate return (0); 23397c478bd9Sstevel@tonic-gate 23407c478bd9Sstevel@tonic-gate eax = cpi->cpi_std[1].cp_eax; 23417c478bd9Sstevel@tonic-gate 23427c478bd9Sstevel@tonic-gate #define SH_B0(eax) (eax == 0xf40 || eax == 0xf50) 23437c478bd9Sstevel@tonic-gate #define SH_B3(eax) (eax == 0xf51) 2344ee88d2b9Skchow #define B(eax) (SH_B0(eax) || SH_B3(eax)) 23457c478bd9Sstevel@tonic-gate 23467c478bd9Sstevel@tonic-gate #define SH_C0(eax) (eax == 0xf48 || eax == 0xf58) 23477c478bd9Sstevel@tonic-gate 23487c478bd9Sstevel@tonic-gate #define SH_CG(eax) (eax == 0xf4a || eax == 0xf5a || eax == 0xf7a) 23497c478bd9Sstevel@tonic-gate #define DH_CG(eax) (eax == 0xfc0 || eax == 0xfe0 || eax == 0xff0) 23507c478bd9Sstevel@tonic-gate #define CH_CG(eax) (eax == 0xf82 || eax == 0xfb2) 2351ee88d2b9Skchow #define CG(eax) (SH_CG(eax) || DH_CG(eax) || CH_CG(eax)) 23527c478bd9Sstevel@tonic-gate 23537c478bd9Sstevel@tonic-gate #define SH_D0(eax) (eax == 0x10f40 || eax == 0x10f50 || eax == 0x10f70) 23547c478bd9Sstevel@tonic-gate #define DH_D0(eax) (eax == 0x10fc0 || eax == 0x10ff0) 23557c478bd9Sstevel@tonic-gate #define CH_D0(eax) (eax == 0x10f80 || eax == 0x10fb0) 2356ee88d2b9Skchow #define D0(eax) (SH_D0(eax) || DH_D0(eax) || CH_D0(eax)) 23577c478bd9Sstevel@tonic-gate 23587c478bd9Sstevel@tonic-gate #define SH_E0(eax) (eax == 0x20f50 || eax == 0x20f40 || eax == 0x20f70) 23597c478bd9Sstevel@tonic-gate #define JH_E1(eax) (eax == 0x20f10) /* JH8_E0 had 0x20f30 */ 23607c478bd9Sstevel@tonic-gate #define DH_E3(eax) (eax == 0x20fc0 || eax == 0x20ff0) 23617c478bd9Sstevel@tonic-gate #define SH_E4(eax) (eax == 0x20f51 || eax == 0x20f71) 23627c478bd9Sstevel@tonic-gate #define BH_E4(eax) (eax == 0x20fb1) 23637c478bd9Sstevel@tonic-gate #define SH_E5(eax) (eax == 0x20f42) 23647c478bd9Sstevel@tonic-gate #define DH_E6(eax) (eax == 0x20ff2 || eax == 0x20fc2) 23657c478bd9Sstevel@tonic-gate #define JH_E6(eax) (eax == 0x20f12 || eax == 0x20f32) 2366ee88d2b9Skchow #define EX(eax) (SH_E0(eax) || JH_E1(eax) || DH_E3(eax) || \ 2367ee88d2b9Skchow SH_E4(eax) || BH_E4(eax) || SH_E5(eax) || \ 2368ee88d2b9Skchow DH_E6(eax) || JH_E6(eax)) 23697c478bd9Sstevel@tonic-gate 23707c478bd9Sstevel@tonic-gate switch (erratum) { 23717c478bd9Sstevel@tonic-gate case 1: 2372875b116eSkchow return (cpi->cpi_family < 0x10); 23737c478bd9Sstevel@tonic-gate case 51: /* what does the asterisk mean? */ 23747c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax)); 23757c478bd9Sstevel@tonic-gate case 52: 23767c478bd9Sstevel@tonic-gate return (B(eax)); 23777c478bd9Sstevel@tonic-gate case 57: 2378875b116eSkchow return (cpi->cpi_family <= 0x10); 23797c478bd9Sstevel@tonic-gate case 58: 23807c478bd9Sstevel@tonic-gate return (B(eax)); 23817c478bd9Sstevel@tonic-gate case 60: 2382875b116eSkchow return (cpi->cpi_family <= 0x10); 23837c478bd9Sstevel@tonic-gate case 61: 23847c478bd9Sstevel@tonic-gate case 62: 23857c478bd9Sstevel@tonic-gate case 63: 23867c478bd9Sstevel@tonic-gate case 64: 23877c478bd9Sstevel@tonic-gate case 65: 23887c478bd9Sstevel@tonic-gate case 66: 23897c478bd9Sstevel@tonic-gate case 68: 23907c478bd9Sstevel@tonic-gate case 69: 23917c478bd9Sstevel@tonic-gate case 70: 23927c478bd9Sstevel@tonic-gate case 71: 23937c478bd9Sstevel@tonic-gate return (B(eax)); 23947c478bd9Sstevel@tonic-gate case 72: 23957c478bd9Sstevel@tonic-gate return (SH_B0(eax)); 23967c478bd9Sstevel@tonic-gate case 74: 23977c478bd9Sstevel@tonic-gate return (B(eax)); 23987c478bd9Sstevel@tonic-gate case 75: 2399875b116eSkchow return (cpi->cpi_family < 0x10); 24007c478bd9Sstevel@tonic-gate case 76: 24017c478bd9Sstevel@tonic-gate return (B(eax)); 24027c478bd9Sstevel@tonic-gate case 77: 2403875b116eSkchow return (cpi->cpi_family <= 0x10); 24047c478bd9Sstevel@tonic-gate case 78: 24057c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax)); 24067c478bd9Sstevel@tonic-gate case 79: 24077c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax) || EX(eax)); 24087c478bd9Sstevel@tonic-gate case 80: 24097c478bd9Sstevel@tonic-gate case 81: 24107c478bd9Sstevel@tonic-gate case 82: 24117c478bd9Sstevel@tonic-gate return (B(eax)); 24127c478bd9Sstevel@tonic-gate case 83: 24137c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax)); 24147c478bd9Sstevel@tonic-gate case 85: 2415875b116eSkchow return (cpi->cpi_family < 0x10); 24167c478bd9Sstevel@tonic-gate case 86: 24177c478bd9Sstevel@tonic-gate return (SH_C0(eax) || CG(eax)); 24187c478bd9Sstevel@tonic-gate case 88: 24197c478bd9Sstevel@tonic-gate #if !defined(__amd64) 24207c478bd9Sstevel@tonic-gate return (0); 24217c478bd9Sstevel@tonic-gate #else 24227c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax)); 24237c478bd9Sstevel@tonic-gate #endif 24247c478bd9Sstevel@tonic-gate case 89: 2425875b116eSkchow return (cpi->cpi_family < 0x10); 24267c478bd9Sstevel@tonic-gate case 90: 24277c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax)); 24287c478bd9Sstevel@tonic-gate case 91: 24297c478bd9Sstevel@tonic-gate case 92: 24307c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax)); 24317c478bd9Sstevel@tonic-gate case 93: 24327c478bd9Sstevel@tonic-gate return (SH_C0(eax)); 24337c478bd9Sstevel@tonic-gate case 94: 24347c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax)); 24357c478bd9Sstevel@tonic-gate case 95: 24367c478bd9Sstevel@tonic-gate #if !defined(__amd64) 24377c478bd9Sstevel@tonic-gate return (0); 24387c478bd9Sstevel@tonic-gate #else 24397c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax)); 24407c478bd9Sstevel@tonic-gate #endif 24417c478bd9Sstevel@tonic-gate case 96: 24427c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax)); 24437c478bd9Sstevel@tonic-gate case 97: 24447c478bd9Sstevel@tonic-gate case 98: 24457c478bd9Sstevel@tonic-gate return (SH_C0(eax) || CG(eax)); 24467c478bd9Sstevel@tonic-gate case 99: 24477c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax)); 24487c478bd9Sstevel@tonic-gate case 100: 24497c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax)); 24507c478bd9Sstevel@tonic-gate case 101: 24517c478bd9Sstevel@tonic-gate case 103: 24527c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax)); 24537c478bd9Sstevel@tonic-gate case 104: 24547c478bd9Sstevel@tonic-gate return (SH_C0(eax) || CG(eax) || D0(eax)); 24557c478bd9Sstevel@tonic-gate case 105: 24567c478bd9Sstevel@tonic-gate case 106: 24577c478bd9Sstevel@tonic-gate case 107: 24587c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax)); 24597c478bd9Sstevel@tonic-gate case 108: 24607c478bd9Sstevel@tonic-gate return (DH_CG(eax)); 24617c478bd9Sstevel@tonic-gate case 109: 24627c478bd9Sstevel@tonic-gate return (SH_C0(eax) || CG(eax) || D0(eax)); 24637c478bd9Sstevel@tonic-gate case 110: 24647c478bd9Sstevel@tonic-gate return (D0(eax) || EX(eax)); 24657c478bd9Sstevel@tonic-gate case 111: 24667c478bd9Sstevel@tonic-gate return (CG(eax)); 24677c478bd9Sstevel@tonic-gate case 112: 24687c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax) || EX(eax)); 24697c478bd9Sstevel@tonic-gate case 113: 24707c478bd9Sstevel@tonic-gate return (eax == 0x20fc0); 24717c478bd9Sstevel@tonic-gate case 114: 24727c478bd9Sstevel@tonic-gate return (SH_E0(eax) || JH_E1(eax) || DH_E3(eax)); 24737c478bd9Sstevel@tonic-gate case 115: 24747c478bd9Sstevel@tonic-gate return (SH_E0(eax) || JH_E1(eax)); 24757c478bd9Sstevel@tonic-gate case 116: 24767c478bd9Sstevel@tonic-gate return (SH_E0(eax) || JH_E1(eax) || DH_E3(eax)); 24777c478bd9Sstevel@tonic-gate case 117: 24787c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax)); 24797c478bd9Sstevel@tonic-gate case 118: 24807c478bd9Sstevel@tonic-gate return (SH_E0(eax) || JH_E1(eax) || SH_E4(eax) || BH_E4(eax) || 24817c478bd9Sstevel@tonic-gate JH_E6(eax)); 24827c478bd9Sstevel@tonic-gate case 121: 24837c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax) || EX(eax)); 24847c478bd9Sstevel@tonic-gate case 122: 2485875b116eSkchow return (cpi->cpi_family < 0x10); 24867c478bd9Sstevel@tonic-gate case 123: 24877c478bd9Sstevel@tonic-gate return (JH_E1(eax) || BH_E4(eax) || JH_E6(eax)); 24882201b277Skucharsk case 131: 2489875b116eSkchow return (cpi->cpi_family < 0x10); 2490ef50d8c0Sesaxe case 6336786: 2491ef50d8c0Sesaxe /* 2492ef50d8c0Sesaxe * Test for AdvPowerMgmtInfo.TscPStateInvariant 2493875b116eSkchow * if this is a K8 family or newer processor 2494ef50d8c0Sesaxe */ 2495ef50d8c0Sesaxe if (CPI_FAMILY(cpi) == 0xf) { 24968949bcd6Sandrei struct cpuid_regs regs; 24978949bcd6Sandrei regs.cp_eax = 0x80000007; 24988949bcd6Sandrei (void) __cpuid_insn(®s); 24998949bcd6Sandrei return (!(regs.cp_edx & 0x100)); 2500ef50d8c0Sesaxe } 2501ef50d8c0Sesaxe return (0); 2502ee88d2b9Skchow case 6323525: 2503ee88d2b9Skchow return (((((eax >> 12) & 0xff00) + (eax & 0xf00)) | 2504ee88d2b9Skchow (((eax >> 4) & 0xf) | ((eax >> 12) & 0xf0))) < 0xf40); 2505ee88d2b9Skchow 25067c478bd9Sstevel@tonic-gate default: 25077c478bd9Sstevel@tonic-gate return (-1); 25087c478bd9Sstevel@tonic-gate } 25097c478bd9Sstevel@tonic-gate } 25107c478bd9Sstevel@tonic-gate 25117c478bd9Sstevel@tonic-gate static const char assoc_str[] = "associativity"; 25127c478bd9Sstevel@tonic-gate static const char line_str[] = "line-size"; 25137c478bd9Sstevel@tonic-gate static const char size_str[] = "size"; 25147c478bd9Sstevel@tonic-gate 25157c478bd9Sstevel@tonic-gate static void 25167c478bd9Sstevel@tonic-gate add_cache_prop(dev_info_t *devi, const char *label, const char *type, 25177c478bd9Sstevel@tonic-gate uint32_t val) 25187c478bd9Sstevel@tonic-gate { 25197c478bd9Sstevel@tonic-gate char buf[128]; 25207c478bd9Sstevel@tonic-gate 25217c478bd9Sstevel@tonic-gate /* 25227c478bd9Sstevel@tonic-gate * ndi_prop_update_int() is used because it is desirable for 25237c478bd9Sstevel@tonic-gate * DDI_PROP_HW_DEF and DDI_PROP_DONTSLEEP to be set. 25247c478bd9Sstevel@tonic-gate */ 25257c478bd9Sstevel@tonic-gate if (snprintf(buf, sizeof (buf), "%s-%s", label, type) < sizeof (buf)) 25267c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, devi, buf, val); 25277c478bd9Sstevel@tonic-gate } 25287c478bd9Sstevel@tonic-gate 25297c478bd9Sstevel@tonic-gate /* 25307c478bd9Sstevel@tonic-gate * Intel-style cache/tlb description 25317c478bd9Sstevel@tonic-gate * 25327c478bd9Sstevel@tonic-gate * Standard cpuid level 2 gives a randomly ordered 25337c478bd9Sstevel@tonic-gate * selection of tags that index into a table that describes 25347c478bd9Sstevel@tonic-gate * cache and tlb properties. 25357c478bd9Sstevel@tonic-gate */ 25367c478bd9Sstevel@tonic-gate 25377c478bd9Sstevel@tonic-gate static const char l1_icache_str[] = "l1-icache"; 25387c478bd9Sstevel@tonic-gate static const char l1_dcache_str[] = "l1-dcache"; 25397c478bd9Sstevel@tonic-gate static const char l2_cache_str[] = "l2-cache"; 2540ae115bc7Smrj static const char l3_cache_str[] = "l3-cache"; 25417c478bd9Sstevel@tonic-gate static const char itlb4k_str[] = "itlb-4K"; 25427c478bd9Sstevel@tonic-gate static const char dtlb4k_str[] = "dtlb-4K"; 25437c478bd9Sstevel@tonic-gate static const char itlb4M_str[] = "itlb-4M"; 25447c478bd9Sstevel@tonic-gate static const char dtlb4M_str[] = "dtlb-4M"; 25457c478bd9Sstevel@tonic-gate static const char itlb424_str[] = "itlb-4K-2M-4M"; 25467c478bd9Sstevel@tonic-gate static const char dtlb44_str[] = "dtlb-4K-4M"; 25477c478bd9Sstevel@tonic-gate static const char sl1_dcache_str[] = "sectored-l1-dcache"; 25487c478bd9Sstevel@tonic-gate static const char sl2_cache_str[] = "sectored-l2-cache"; 25497c478bd9Sstevel@tonic-gate static const char itrace_str[] = "itrace-cache"; 25507c478bd9Sstevel@tonic-gate static const char sl3_cache_str[] = "sectored-l3-cache"; 25517c478bd9Sstevel@tonic-gate 25527c478bd9Sstevel@tonic-gate static const struct cachetab { 25537c478bd9Sstevel@tonic-gate uint8_t ct_code; 25547c478bd9Sstevel@tonic-gate uint8_t ct_assoc; 25557c478bd9Sstevel@tonic-gate uint16_t ct_line_size; 25567c478bd9Sstevel@tonic-gate size_t ct_size; 25577c478bd9Sstevel@tonic-gate const char *ct_label; 25587c478bd9Sstevel@tonic-gate } intel_ctab[] = { 25597c478bd9Sstevel@tonic-gate /* maintain descending order! */ 2560ae115bc7Smrj { 0xb4, 4, 0, 256, dtlb4k_str }, 25617c478bd9Sstevel@tonic-gate { 0xb3, 4, 0, 128, dtlb4k_str }, 25627c478bd9Sstevel@tonic-gate { 0xb0, 4, 0, 128, itlb4k_str }, 25637c478bd9Sstevel@tonic-gate { 0x87, 8, 64, 1024*1024, l2_cache_str}, 25647c478bd9Sstevel@tonic-gate { 0x86, 4, 64, 512*1024, l2_cache_str}, 25657c478bd9Sstevel@tonic-gate { 0x85, 8, 32, 2*1024*1024, l2_cache_str}, 25667c478bd9Sstevel@tonic-gate { 0x84, 8, 32, 1024*1024, l2_cache_str}, 25677c478bd9Sstevel@tonic-gate { 0x83, 8, 32, 512*1024, l2_cache_str}, 25687c478bd9Sstevel@tonic-gate { 0x82, 8, 32, 256*1024, l2_cache_str}, 25697c478bd9Sstevel@tonic-gate { 0x7f, 2, 64, 512*1024, l2_cache_str}, 25707c478bd9Sstevel@tonic-gate { 0x7d, 8, 64, 2*1024*1024, sl2_cache_str}, 25717c478bd9Sstevel@tonic-gate { 0x7c, 8, 64, 1024*1024, sl2_cache_str}, 25727c478bd9Sstevel@tonic-gate { 0x7b, 8, 64, 512*1024, sl2_cache_str}, 25737c478bd9Sstevel@tonic-gate { 0x7a, 8, 64, 256*1024, sl2_cache_str}, 25747c478bd9Sstevel@tonic-gate { 0x79, 8, 64, 128*1024, sl2_cache_str}, 25757c478bd9Sstevel@tonic-gate { 0x78, 8, 64, 1024*1024, l2_cache_str}, 2576ae115bc7Smrj { 0x73, 8, 0, 64*1024, itrace_str}, 25777c478bd9Sstevel@tonic-gate { 0x72, 8, 0, 32*1024, itrace_str}, 25787c478bd9Sstevel@tonic-gate { 0x71, 8, 0, 16*1024, itrace_str}, 25797c478bd9Sstevel@tonic-gate { 0x70, 8, 0, 12*1024, itrace_str}, 25807c478bd9Sstevel@tonic-gate { 0x68, 4, 64, 32*1024, sl1_dcache_str}, 25817c478bd9Sstevel@tonic-gate { 0x67, 4, 64, 16*1024, sl1_dcache_str}, 25827c478bd9Sstevel@tonic-gate { 0x66, 4, 64, 8*1024, sl1_dcache_str}, 25837c478bd9Sstevel@tonic-gate { 0x60, 8, 64, 16*1024, sl1_dcache_str}, 25847c478bd9Sstevel@tonic-gate { 0x5d, 0, 0, 256, dtlb44_str}, 25857c478bd9Sstevel@tonic-gate { 0x5c, 0, 0, 128, dtlb44_str}, 25867c478bd9Sstevel@tonic-gate { 0x5b, 0, 0, 64, dtlb44_str}, 25877c478bd9Sstevel@tonic-gate { 0x52, 0, 0, 256, itlb424_str}, 25887c478bd9Sstevel@tonic-gate { 0x51, 0, 0, 128, itlb424_str}, 25897c478bd9Sstevel@tonic-gate { 0x50, 0, 0, 64, itlb424_str}, 2590ae115bc7Smrj { 0x4d, 16, 64, 16*1024*1024, l3_cache_str}, 2591ae115bc7Smrj { 0x4c, 12, 64, 12*1024*1024, l3_cache_str}, 2592ae115bc7Smrj { 0x4b, 16, 64, 8*1024*1024, l3_cache_str}, 2593ae115bc7Smrj { 0x4a, 12, 64, 6*1024*1024, l3_cache_str}, 2594ae115bc7Smrj { 0x49, 16, 64, 4*1024*1024, l3_cache_str}, 2595ae115bc7Smrj { 0x47, 8, 64, 8*1024*1024, l3_cache_str}, 2596ae115bc7Smrj { 0x46, 4, 64, 4*1024*1024, l3_cache_str}, 25977c478bd9Sstevel@tonic-gate { 0x45, 4, 32, 2*1024*1024, l2_cache_str}, 25987c478bd9Sstevel@tonic-gate { 0x44, 4, 32, 1024*1024, l2_cache_str}, 25997c478bd9Sstevel@tonic-gate { 0x43, 4, 32, 512*1024, l2_cache_str}, 26007c478bd9Sstevel@tonic-gate { 0x42, 4, 32, 256*1024, l2_cache_str}, 26017c478bd9Sstevel@tonic-gate { 0x41, 4, 32, 128*1024, l2_cache_str}, 2602ae115bc7Smrj { 0x3e, 4, 64, 512*1024, sl2_cache_str}, 2603ae115bc7Smrj { 0x3d, 6, 64, 384*1024, sl2_cache_str}, 26047c478bd9Sstevel@tonic-gate { 0x3c, 4, 64, 256*1024, sl2_cache_str}, 26057c478bd9Sstevel@tonic-gate { 0x3b, 2, 64, 128*1024, sl2_cache_str}, 2606ae115bc7Smrj { 0x3a, 6, 64, 192*1024, sl2_cache_str}, 26077c478bd9Sstevel@tonic-gate { 0x39, 4, 64, 128*1024, sl2_cache_str}, 26087c478bd9Sstevel@tonic-gate { 0x30, 8, 64, 32*1024, l1_icache_str}, 26097c478bd9Sstevel@tonic-gate { 0x2c, 8, 64, 32*1024, l1_dcache_str}, 26107c478bd9Sstevel@tonic-gate { 0x29, 8, 64, 4096*1024, sl3_cache_str}, 26117c478bd9Sstevel@tonic-gate { 0x25, 8, 64, 2048*1024, sl3_cache_str}, 26127c478bd9Sstevel@tonic-gate { 0x23, 8, 64, 1024*1024, sl3_cache_str}, 26137c478bd9Sstevel@tonic-gate { 0x22, 4, 64, 512*1024, sl3_cache_str}, 26147c478bd9Sstevel@tonic-gate { 0x0c, 4, 32, 16*1024, l1_dcache_str}, 2615ae115bc7Smrj { 0x0b, 4, 0, 4, itlb4M_str}, 26167c478bd9Sstevel@tonic-gate { 0x0a, 2, 32, 8*1024, l1_dcache_str}, 26177c478bd9Sstevel@tonic-gate { 0x08, 4, 32, 16*1024, l1_icache_str}, 26187c478bd9Sstevel@tonic-gate { 0x06, 4, 32, 8*1024, l1_icache_str}, 26197c478bd9Sstevel@tonic-gate { 0x04, 4, 0, 8, dtlb4M_str}, 26207c478bd9Sstevel@tonic-gate { 0x03, 4, 0, 64, dtlb4k_str}, 26217c478bd9Sstevel@tonic-gate { 0x02, 4, 0, 2, itlb4M_str}, 26227c478bd9Sstevel@tonic-gate { 0x01, 4, 0, 32, itlb4k_str}, 26237c478bd9Sstevel@tonic-gate { 0 } 26247c478bd9Sstevel@tonic-gate }; 26257c478bd9Sstevel@tonic-gate 26267c478bd9Sstevel@tonic-gate static const struct cachetab cyrix_ctab[] = { 26277c478bd9Sstevel@tonic-gate { 0x70, 4, 0, 32, "tlb-4K" }, 26287c478bd9Sstevel@tonic-gate { 0x80, 4, 16, 16*1024, "l1-cache" }, 26297c478bd9Sstevel@tonic-gate { 0 } 26307c478bd9Sstevel@tonic-gate }; 26317c478bd9Sstevel@tonic-gate 26327c478bd9Sstevel@tonic-gate /* 26337c478bd9Sstevel@tonic-gate * Search a cache table for a matching entry 26347c478bd9Sstevel@tonic-gate */ 26357c478bd9Sstevel@tonic-gate static const struct cachetab * 26367c478bd9Sstevel@tonic-gate find_cacheent(const struct cachetab *ct, uint_t code) 26377c478bd9Sstevel@tonic-gate { 26387c478bd9Sstevel@tonic-gate if (code != 0) { 26397c478bd9Sstevel@tonic-gate for (; ct->ct_code != 0; ct++) 26407c478bd9Sstevel@tonic-gate if (ct->ct_code <= code) 26417c478bd9Sstevel@tonic-gate break; 26427c478bd9Sstevel@tonic-gate if (ct->ct_code == code) 26437c478bd9Sstevel@tonic-gate return (ct); 26447c478bd9Sstevel@tonic-gate } 26457c478bd9Sstevel@tonic-gate return (NULL); 26467c478bd9Sstevel@tonic-gate } 26477c478bd9Sstevel@tonic-gate 26487c478bd9Sstevel@tonic-gate /* 26497c478bd9Sstevel@tonic-gate * Walk the cacheinfo descriptor, applying 'func' to every valid element 26507c478bd9Sstevel@tonic-gate * The walk is terminated if the walker returns non-zero. 26517c478bd9Sstevel@tonic-gate */ 26527c478bd9Sstevel@tonic-gate static void 26537c478bd9Sstevel@tonic-gate intel_walk_cacheinfo(struct cpuid_info *cpi, 26547c478bd9Sstevel@tonic-gate void *arg, int (*func)(void *, const struct cachetab *)) 26557c478bd9Sstevel@tonic-gate { 26567c478bd9Sstevel@tonic-gate const struct cachetab *ct; 26577c478bd9Sstevel@tonic-gate uint8_t *dp; 26587c478bd9Sstevel@tonic-gate int i; 26597c478bd9Sstevel@tonic-gate 26607c478bd9Sstevel@tonic-gate if ((dp = cpi->cpi_cacheinfo) == NULL) 26617c478bd9Sstevel@tonic-gate return; 26627c478bd9Sstevel@tonic-gate for (i = 0; i < cpi->cpi_ncache; i++, dp++) 26637c478bd9Sstevel@tonic-gate if ((ct = find_cacheent(intel_ctab, *dp)) != NULL) { 26647c478bd9Sstevel@tonic-gate if (func(arg, ct) != 0) 26657c478bd9Sstevel@tonic-gate break; 26667c478bd9Sstevel@tonic-gate } 26677c478bd9Sstevel@tonic-gate } 26687c478bd9Sstevel@tonic-gate 26697c478bd9Sstevel@tonic-gate /* 26707c478bd9Sstevel@tonic-gate * (Like the Intel one, except for Cyrix CPUs) 26717c478bd9Sstevel@tonic-gate */ 26727c478bd9Sstevel@tonic-gate static void 26737c478bd9Sstevel@tonic-gate cyrix_walk_cacheinfo(struct cpuid_info *cpi, 26747c478bd9Sstevel@tonic-gate void *arg, int (*func)(void *, const struct cachetab *)) 26757c478bd9Sstevel@tonic-gate { 26767c478bd9Sstevel@tonic-gate const struct cachetab *ct; 26777c478bd9Sstevel@tonic-gate uint8_t *dp; 26787c478bd9Sstevel@tonic-gate int i; 26797c478bd9Sstevel@tonic-gate 26807c478bd9Sstevel@tonic-gate if ((dp = cpi->cpi_cacheinfo) == NULL) 26817c478bd9Sstevel@tonic-gate return; 26827c478bd9Sstevel@tonic-gate for (i = 0; i < cpi->cpi_ncache; i++, dp++) { 26837c478bd9Sstevel@tonic-gate /* 26847c478bd9Sstevel@tonic-gate * Search Cyrix-specific descriptor table first .. 26857c478bd9Sstevel@tonic-gate */ 26867c478bd9Sstevel@tonic-gate if ((ct = find_cacheent(cyrix_ctab, *dp)) != NULL) { 26877c478bd9Sstevel@tonic-gate if (func(arg, ct) != 0) 26887c478bd9Sstevel@tonic-gate break; 26897c478bd9Sstevel@tonic-gate continue; 26907c478bd9Sstevel@tonic-gate } 26917c478bd9Sstevel@tonic-gate /* 26927c478bd9Sstevel@tonic-gate * .. else fall back to the Intel one 26937c478bd9Sstevel@tonic-gate */ 26947c478bd9Sstevel@tonic-gate if ((ct = find_cacheent(intel_ctab, *dp)) != NULL) { 26957c478bd9Sstevel@tonic-gate if (func(arg, ct) != 0) 26967c478bd9Sstevel@tonic-gate break; 26977c478bd9Sstevel@tonic-gate continue; 26987c478bd9Sstevel@tonic-gate } 26997c478bd9Sstevel@tonic-gate } 27007c478bd9Sstevel@tonic-gate } 27017c478bd9Sstevel@tonic-gate 27027c478bd9Sstevel@tonic-gate /* 27037c478bd9Sstevel@tonic-gate * A cacheinfo walker that adds associativity, line-size, and size properties 27047c478bd9Sstevel@tonic-gate * to the devinfo node it is passed as an argument. 27057c478bd9Sstevel@tonic-gate */ 27067c478bd9Sstevel@tonic-gate static int 27077c478bd9Sstevel@tonic-gate add_cacheent_props(void *arg, const struct cachetab *ct) 27087c478bd9Sstevel@tonic-gate { 27097c478bd9Sstevel@tonic-gate dev_info_t *devi = arg; 27107c478bd9Sstevel@tonic-gate 27117c478bd9Sstevel@tonic-gate add_cache_prop(devi, ct->ct_label, assoc_str, ct->ct_assoc); 27127c478bd9Sstevel@tonic-gate if (ct->ct_line_size != 0) 27137c478bd9Sstevel@tonic-gate add_cache_prop(devi, ct->ct_label, line_str, 27147c478bd9Sstevel@tonic-gate ct->ct_line_size); 27157c478bd9Sstevel@tonic-gate add_cache_prop(devi, ct->ct_label, size_str, ct->ct_size); 27167c478bd9Sstevel@tonic-gate return (0); 27177c478bd9Sstevel@tonic-gate } 27187c478bd9Sstevel@tonic-gate 27197c478bd9Sstevel@tonic-gate static const char fully_assoc[] = "fully-associative?"; 27207c478bd9Sstevel@tonic-gate 27217c478bd9Sstevel@tonic-gate /* 27227c478bd9Sstevel@tonic-gate * AMD style cache/tlb description 27237c478bd9Sstevel@tonic-gate * 27247c478bd9Sstevel@tonic-gate * Extended functions 5 and 6 directly describe properties of 27257c478bd9Sstevel@tonic-gate * tlbs and various cache levels. 27267c478bd9Sstevel@tonic-gate */ 27277c478bd9Sstevel@tonic-gate static void 27287c478bd9Sstevel@tonic-gate add_amd_assoc(dev_info_t *devi, const char *label, uint_t assoc) 27297c478bd9Sstevel@tonic-gate { 27307c478bd9Sstevel@tonic-gate switch (assoc) { 27317c478bd9Sstevel@tonic-gate case 0: /* reserved; ignore */ 27327c478bd9Sstevel@tonic-gate break; 27337c478bd9Sstevel@tonic-gate default: 27347c478bd9Sstevel@tonic-gate add_cache_prop(devi, label, assoc_str, assoc); 27357c478bd9Sstevel@tonic-gate break; 27367c478bd9Sstevel@tonic-gate case 0xff: 27377c478bd9Sstevel@tonic-gate add_cache_prop(devi, label, fully_assoc, 1); 27387c478bd9Sstevel@tonic-gate break; 27397c478bd9Sstevel@tonic-gate } 27407c478bd9Sstevel@tonic-gate } 27417c478bd9Sstevel@tonic-gate 27427c478bd9Sstevel@tonic-gate static void 27437c478bd9Sstevel@tonic-gate add_amd_tlb(dev_info_t *devi, const char *label, uint_t assoc, uint_t size) 27447c478bd9Sstevel@tonic-gate { 27457c478bd9Sstevel@tonic-gate if (size == 0) 27467c478bd9Sstevel@tonic-gate return; 27477c478bd9Sstevel@tonic-gate add_cache_prop(devi, label, size_str, size); 27487c478bd9Sstevel@tonic-gate add_amd_assoc(devi, label, assoc); 27497c478bd9Sstevel@tonic-gate } 27507c478bd9Sstevel@tonic-gate 27517c478bd9Sstevel@tonic-gate static void 27527c478bd9Sstevel@tonic-gate add_amd_cache(dev_info_t *devi, const char *label, 27537c478bd9Sstevel@tonic-gate uint_t size, uint_t assoc, uint_t lines_per_tag, uint_t line_size) 27547c478bd9Sstevel@tonic-gate { 27557c478bd9Sstevel@tonic-gate if (size == 0 || line_size == 0) 27567c478bd9Sstevel@tonic-gate return; 27577c478bd9Sstevel@tonic-gate add_amd_assoc(devi, label, assoc); 27587c478bd9Sstevel@tonic-gate /* 27597c478bd9Sstevel@tonic-gate * Most AMD parts have a sectored cache. Multiple cache lines are 27607c478bd9Sstevel@tonic-gate * associated with each tag. A sector consists of all cache lines 27617c478bd9Sstevel@tonic-gate * associated with a tag. For example, the AMD K6-III has a sector 27627c478bd9Sstevel@tonic-gate * size of 2 cache lines per tag. 27637c478bd9Sstevel@tonic-gate */ 27647c478bd9Sstevel@tonic-gate if (lines_per_tag != 0) 27657c478bd9Sstevel@tonic-gate add_cache_prop(devi, label, "lines-per-tag", lines_per_tag); 27667c478bd9Sstevel@tonic-gate add_cache_prop(devi, label, line_str, line_size); 27677c478bd9Sstevel@tonic-gate add_cache_prop(devi, label, size_str, size * 1024); 27687c478bd9Sstevel@tonic-gate } 27697c478bd9Sstevel@tonic-gate 27707c478bd9Sstevel@tonic-gate static void 27717c478bd9Sstevel@tonic-gate add_amd_l2_assoc(dev_info_t *devi, const char *label, uint_t assoc) 27727c478bd9Sstevel@tonic-gate { 27737c478bd9Sstevel@tonic-gate switch (assoc) { 27747c478bd9Sstevel@tonic-gate case 0: /* off */ 27757c478bd9Sstevel@tonic-gate break; 27767c478bd9Sstevel@tonic-gate case 1: 27777c478bd9Sstevel@tonic-gate case 2: 27787c478bd9Sstevel@tonic-gate case 4: 27797c478bd9Sstevel@tonic-gate add_cache_prop(devi, label, assoc_str, assoc); 27807c478bd9Sstevel@tonic-gate break; 27817c478bd9Sstevel@tonic-gate case 6: 27827c478bd9Sstevel@tonic-gate add_cache_prop(devi, label, assoc_str, 8); 27837c478bd9Sstevel@tonic-gate break; 27847c478bd9Sstevel@tonic-gate case 8: 27857c478bd9Sstevel@tonic-gate add_cache_prop(devi, label, assoc_str, 16); 27867c478bd9Sstevel@tonic-gate break; 27877c478bd9Sstevel@tonic-gate case 0xf: 27887c478bd9Sstevel@tonic-gate add_cache_prop(devi, label, fully_assoc, 1); 27897c478bd9Sstevel@tonic-gate break; 27907c478bd9Sstevel@tonic-gate default: /* reserved; ignore */ 27917c478bd9Sstevel@tonic-gate break; 27927c478bd9Sstevel@tonic-gate } 27937c478bd9Sstevel@tonic-gate } 27947c478bd9Sstevel@tonic-gate 27957c478bd9Sstevel@tonic-gate static void 27967c478bd9Sstevel@tonic-gate add_amd_l2_tlb(dev_info_t *devi, const char *label, uint_t assoc, uint_t size) 27977c478bd9Sstevel@tonic-gate { 27987c478bd9Sstevel@tonic-gate if (size == 0 || assoc == 0) 27997c478bd9Sstevel@tonic-gate return; 28007c478bd9Sstevel@tonic-gate add_amd_l2_assoc(devi, label, assoc); 28017c478bd9Sstevel@tonic-gate add_cache_prop(devi, label, size_str, size); 28027c478bd9Sstevel@tonic-gate } 28037c478bd9Sstevel@tonic-gate 28047c478bd9Sstevel@tonic-gate static void 28057c478bd9Sstevel@tonic-gate add_amd_l2_cache(dev_info_t *devi, const char *label, 28067c478bd9Sstevel@tonic-gate uint_t size, uint_t assoc, uint_t lines_per_tag, uint_t line_size) 28077c478bd9Sstevel@tonic-gate { 28087c478bd9Sstevel@tonic-gate if (size == 0 || assoc == 0 || line_size == 0) 28097c478bd9Sstevel@tonic-gate return; 28107c478bd9Sstevel@tonic-gate add_amd_l2_assoc(devi, label, assoc); 28117c478bd9Sstevel@tonic-gate if (lines_per_tag != 0) 28127c478bd9Sstevel@tonic-gate add_cache_prop(devi, label, "lines-per-tag", lines_per_tag); 28137c478bd9Sstevel@tonic-gate add_cache_prop(devi, label, line_str, line_size); 28147c478bd9Sstevel@tonic-gate add_cache_prop(devi, label, size_str, size * 1024); 28157c478bd9Sstevel@tonic-gate } 28167c478bd9Sstevel@tonic-gate 28177c478bd9Sstevel@tonic-gate static void 28187c478bd9Sstevel@tonic-gate amd_cache_info(struct cpuid_info *cpi, dev_info_t *devi) 28197c478bd9Sstevel@tonic-gate { 28208949bcd6Sandrei struct cpuid_regs *cp; 28217c478bd9Sstevel@tonic-gate 28227c478bd9Sstevel@tonic-gate if (cpi->cpi_xmaxeax < 0x80000005) 28237c478bd9Sstevel@tonic-gate return; 28247c478bd9Sstevel@tonic-gate cp = &cpi->cpi_extd[5]; 28257c478bd9Sstevel@tonic-gate 28267c478bd9Sstevel@tonic-gate /* 28277c478bd9Sstevel@tonic-gate * 4M/2M L1 TLB configuration 28287c478bd9Sstevel@tonic-gate * 28297c478bd9Sstevel@tonic-gate * We report the size for 2M pages because AMD uses two 28307c478bd9Sstevel@tonic-gate * TLB entries for one 4M page. 28317c478bd9Sstevel@tonic-gate */ 28327c478bd9Sstevel@tonic-gate add_amd_tlb(devi, "dtlb-2M", 28337c478bd9Sstevel@tonic-gate BITX(cp->cp_eax, 31, 24), BITX(cp->cp_eax, 23, 16)); 28347c478bd9Sstevel@tonic-gate add_amd_tlb(devi, "itlb-2M", 28357c478bd9Sstevel@tonic-gate BITX(cp->cp_eax, 15, 8), BITX(cp->cp_eax, 7, 0)); 28367c478bd9Sstevel@tonic-gate 28377c478bd9Sstevel@tonic-gate /* 28387c478bd9Sstevel@tonic-gate * 4K L1 TLB configuration 28397c478bd9Sstevel@tonic-gate */ 28407c478bd9Sstevel@tonic-gate 28417c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 28427c478bd9Sstevel@tonic-gate uint_t nentries; 28437c478bd9Sstevel@tonic-gate case X86_VENDOR_TM: 28447c478bd9Sstevel@tonic-gate if (cpi->cpi_family >= 5) { 28457c478bd9Sstevel@tonic-gate /* 28467c478bd9Sstevel@tonic-gate * Crusoe processors have 256 TLB entries, but 28477c478bd9Sstevel@tonic-gate * cpuid data format constrains them to only 28487c478bd9Sstevel@tonic-gate * reporting 255 of them. 28497c478bd9Sstevel@tonic-gate */ 28507c478bd9Sstevel@tonic-gate if ((nentries = BITX(cp->cp_ebx, 23, 16)) == 255) 28517c478bd9Sstevel@tonic-gate nentries = 256; 28527c478bd9Sstevel@tonic-gate /* 28537c478bd9Sstevel@tonic-gate * Crusoe processors also have a unified TLB 28547c478bd9Sstevel@tonic-gate */ 28557c478bd9Sstevel@tonic-gate add_amd_tlb(devi, "tlb-4K", BITX(cp->cp_ebx, 31, 24), 28567c478bd9Sstevel@tonic-gate nentries); 28577c478bd9Sstevel@tonic-gate break; 28587c478bd9Sstevel@tonic-gate } 28597c478bd9Sstevel@tonic-gate /*FALLTHROUGH*/ 28607c478bd9Sstevel@tonic-gate default: 28617c478bd9Sstevel@tonic-gate add_amd_tlb(devi, itlb4k_str, 28627c478bd9Sstevel@tonic-gate BITX(cp->cp_ebx, 31, 24), BITX(cp->cp_ebx, 23, 16)); 28637c478bd9Sstevel@tonic-gate add_amd_tlb(devi, dtlb4k_str, 28647c478bd9Sstevel@tonic-gate BITX(cp->cp_ebx, 15, 8), BITX(cp->cp_ebx, 7, 0)); 28657c478bd9Sstevel@tonic-gate break; 28667c478bd9Sstevel@tonic-gate } 28677c478bd9Sstevel@tonic-gate 28687c478bd9Sstevel@tonic-gate /* 28697c478bd9Sstevel@tonic-gate * data L1 cache configuration 28707c478bd9Sstevel@tonic-gate */ 28717c478bd9Sstevel@tonic-gate 28727c478bd9Sstevel@tonic-gate add_amd_cache(devi, l1_dcache_str, 28737c478bd9Sstevel@tonic-gate BITX(cp->cp_ecx, 31, 24), BITX(cp->cp_ecx, 23, 16), 28747c478bd9Sstevel@tonic-gate BITX(cp->cp_ecx, 15, 8), BITX(cp->cp_ecx, 7, 0)); 28757c478bd9Sstevel@tonic-gate 28767c478bd9Sstevel@tonic-gate /* 28777c478bd9Sstevel@tonic-gate * code L1 cache configuration 28787c478bd9Sstevel@tonic-gate */ 28797c478bd9Sstevel@tonic-gate 28807c478bd9Sstevel@tonic-gate add_amd_cache(devi, l1_icache_str, 28817c478bd9Sstevel@tonic-gate BITX(cp->cp_edx, 31, 24), BITX(cp->cp_edx, 23, 16), 28827c478bd9Sstevel@tonic-gate BITX(cp->cp_edx, 15, 8), BITX(cp->cp_edx, 7, 0)); 28837c478bd9Sstevel@tonic-gate 28847c478bd9Sstevel@tonic-gate if (cpi->cpi_xmaxeax < 0x80000006) 28857c478bd9Sstevel@tonic-gate return; 28867c478bd9Sstevel@tonic-gate cp = &cpi->cpi_extd[6]; 28877c478bd9Sstevel@tonic-gate 28887c478bd9Sstevel@tonic-gate /* Check for a unified L2 TLB for large pages */ 28897c478bd9Sstevel@tonic-gate 28907c478bd9Sstevel@tonic-gate if (BITX(cp->cp_eax, 31, 16) == 0) 28917c478bd9Sstevel@tonic-gate add_amd_l2_tlb(devi, "l2-tlb-2M", 28927c478bd9Sstevel@tonic-gate BITX(cp->cp_eax, 15, 12), BITX(cp->cp_eax, 11, 0)); 28937c478bd9Sstevel@tonic-gate else { 28947c478bd9Sstevel@tonic-gate add_amd_l2_tlb(devi, "l2-dtlb-2M", 28957c478bd9Sstevel@tonic-gate BITX(cp->cp_eax, 31, 28), BITX(cp->cp_eax, 27, 16)); 28967c478bd9Sstevel@tonic-gate add_amd_l2_tlb(devi, "l2-itlb-2M", 28977c478bd9Sstevel@tonic-gate BITX(cp->cp_eax, 15, 12), BITX(cp->cp_eax, 11, 0)); 28987c478bd9Sstevel@tonic-gate } 28997c478bd9Sstevel@tonic-gate 29007c478bd9Sstevel@tonic-gate /* Check for a unified L2 TLB for 4K pages */ 29017c478bd9Sstevel@tonic-gate 29027c478bd9Sstevel@tonic-gate if (BITX(cp->cp_ebx, 31, 16) == 0) { 29037c478bd9Sstevel@tonic-gate add_amd_l2_tlb(devi, "l2-tlb-4K", 29047c478bd9Sstevel@tonic-gate BITX(cp->cp_eax, 15, 12), BITX(cp->cp_eax, 11, 0)); 29057c478bd9Sstevel@tonic-gate } else { 29067c478bd9Sstevel@tonic-gate add_amd_l2_tlb(devi, "l2-dtlb-4K", 29077c478bd9Sstevel@tonic-gate BITX(cp->cp_eax, 31, 28), BITX(cp->cp_eax, 27, 16)); 29087c478bd9Sstevel@tonic-gate add_amd_l2_tlb(devi, "l2-itlb-4K", 29097c478bd9Sstevel@tonic-gate BITX(cp->cp_eax, 15, 12), BITX(cp->cp_eax, 11, 0)); 29107c478bd9Sstevel@tonic-gate } 29117c478bd9Sstevel@tonic-gate 29127c478bd9Sstevel@tonic-gate add_amd_l2_cache(devi, l2_cache_str, 29137c478bd9Sstevel@tonic-gate BITX(cp->cp_ecx, 31, 16), BITX(cp->cp_ecx, 15, 12), 29147c478bd9Sstevel@tonic-gate BITX(cp->cp_ecx, 11, 8), BITX(cp->cp_ecx, 7, 0)); 29157c478bd9Sstevel@tonic-gate } 29167c478bd9Sstevel@tonic-gate 29177c478bd9Sstevel@tonic-gate /* 29187c478bd9Sstevel@tonic-gate * There are two basic ways that the x86 world describes it cache 29197c478bd9Sstevel@tonic-gate * and tlb architecture - Intel's way and AMD's way. 29207c478bd9Sstevel@tonic-gate * 29217c478bd9Sstevel@tonic-gate * Return which flavor of cache architecture we should use 29227c478bd9Sstevel@tonic-gate */ 29237c478bd9Sstevel@tonic-gate static int 29247c478bd9Sstevel@tonic-gate x86_which_cacheinfo(struct cpuid_info *cpi) 29257c478bd9Sstevel@tonic-gate { 29267c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 29277c478bd9Sstevel@tonic-gate case X86_VENDOR_Intel: 29287c478bd9Sstevel@tonic-gate if (cpi->cpi_maxeax >= 2) 29297c478bd9Sstevel@tonic-gate return (X86_VENDOR_Intel); 29307c478bd9Sstevel@tonic-gate break; 29317c478bd9Sstevel@tonic-gate case X86_VENDOR_AMD: 29327c478bd9Sstevel@tonic-gate /* 29337c478bd9Sstevel@tonic-gate * The K5 model 1 was the first part from AMD that reported 29347c478bd9Sstevel@tonic-gate * cache sizes via extended cpuid functions. 29357c478bd9Sstevel@tonic-gate */ 29367c478bd9Sstevel@tonic-gate if (cpi->cpi_family > 5 || 29377c478bd9Sstevel@tonic-gate (cpi->cpi_family == 5 && cpi->cpi_model >= 1)) 29387c478bd9Sstevel@tonic-gate return (X86_VENDOR_AMD); 29397c478bd9Sstevel@tonic-gate break; 29407c478bd9Sstevel@tonic-gate case X86_VENDOR_TM: 29417c478bd9Sstevel@tonic-gate if (cpi->cpi_family >= 5) 29427c478bd9Sstevel@tonic-gate return (X86_VENDOR_AMD); 29437c478bd9Sstevel@tonic-gate /*FALLTHROUGH*/ 29447c478bd9Sstevel@tonic-gate default: 29457c478bd9Sstevel@tonic-gate /* 29467c478bd9Sstevel@tonic-gate * If they have extended CPU data for 0x80000005 29477c478bd9Sstevel@tonic-gate * then we assume they have AMD-format cache 29487c478bd9Sstevel@tonic-gate * information. 29497c478bd9Sstevel@tonic-gate * 29507c478bd9Sstevel@tonic-gate * If not, and the vendor happens to be Cyrix, 29517c478bd9Sstevel@tonic-gate * then try our-Cyrix specific handler. 29527c478bd9Sstevel@tonic-gate * 29537c478bd9Sstevel@tonic-gate * If we're not Cyrix, then assume we're using Intel's 29547c478bd9Sstevel@tonic-gate * table-driven format instead. 29557c478bd9Sstevel@tonic-gate */ 29567c478bd9Sstevel@tonic-gate if (cpi->cpi_xmaxeax >= 0x80000005) 29577c478bd9Sstevel@tonic-gate return (X86_VENDOR_AMD); 29587c478bd9Sstevel@tonic-gate else if (cpi->cpi_vendor == X86_VENDOR_Cyrix) 29597c478bd9Sstevel@tonic-gate return (X86_VENDOR_Cyrix); 29607c478bd9Sstevel@tonic-gate else if (cpi->cpi_maxeax >= 2) 29617c478bd9Sstevel@tonic-gate return (X86_VENDOR_Intel); 29627c478bd9Sstevel@tonic-gate break; 29637c478bd9Sstevel@tonic-gate } 29647c478bd9Sstevel@tonic-gate return (-1); 29657c478bd9Sstevel@tonic-gate } 29667c478bd9Sstevel@tonic-gate 29677c478bd9Sstevel@tonic-gate /* 29687c478bd9Sstevel@tonic-gate * create a node for the given cpu under the prom root node. 29697c478bd9Sstevel@tonic-gate * Also, create a cpu node in the device tree. 29707c478bd9Sstevel@tonic-gate */ 29717c478bd9Sstevel@tonic-gate static dev_info_t *cpu_nex_devi = NULL; 29727c478bd9Sstevel@tonic-gate static kmutex_t cpu_node_lock; 29737c478bd9Sstevel@tonic-gate 29747c478bd9Sstevel@tonic-gate /* 29757c478bd9Sstevel@tonic-gate * Called from post_startup() and mp_startup() 29767c478bd9Sstevel@tonic-gate */ 29777c478bd9Sstevel@tonic-gate void 29787c478bd9Sstevel@tonic-gate add_cpunode2devtree(processorid_t cpu_id, struct cpuid_info *cpi) 29797c478bd9Sstevel@tonic-gate { 29807c478bd9Sstevel@tonic-gate dev_info_t *cpu_devi; 29817c478bd9Sstevel@tonic-gate int create; 29827c478bd9Sstevel@tonic-gate 29837c478bd9Sstevel@tonic-gate mutex_enter(&cpu_node_lock); 29847c478bd9Sstevel@tonic-gate 29857c478bd9Sstevel@tonic-gate /* 29867c478bd9Sstevel@tonic-gate * create a nexus node for all cpus identified as 'cpu_id' under 29877c478bd9Sstevel@tonic-gate * the root node. 29887c478bd9Sstevel@tonic-gate */ 29897c478bd9Sstevel@tonic-gate if (cpu_nex_devi == NULL) { 29907c478bd9Sstevel@tonic-gate if (ndi_devi_alloc(ddi_root_node(), "cpus", 2991fa9e4066Sahrens (pnode_t)DEVI_SID_NODEID, &cpu_nex_devi) != NDI_SUCCESS) { 29927c478bd9Sstevel@tonic-gate mutex_exit(&cpu_node_lock); 29937c478bd9Sstevel@tonic-gate return; 29947c478bd9Sstevel@tonic-gate } 29957c478bd9Sstevel@tonic-gate (void) ndi_devi_online(cpu_nex_devi, 0); 29967c478bd9Sstevel@tonic-gate } 29977c478bd9Sstevel@tonic-gate 29987c478bd9Sstevel@tonic-gate /* 29997c478bd9Sstevel@tonic-gate * create a child node for cpu identified as 'cpu_id' 30007c478bd9Sstevel@tonic-gate */ 30017c478bd9Sstevel@tonic-gate cpu_devi = ddi_add_child(cpu_nex_devi, "cpu", DEVI_SID_NODEID, 30027c478bd9Sstevel@tonic-gate cpu_id); 30037c478bd9Sstevel@tonic-gate if (cpu_devi == NULL) { 30047c478bd9Sstevel@tonic-gate mutex_exit(&cpu_node_lock); 30057c478bd9Sstevel@tonic-gate return; 30067c478bd9Sstevel@tonic-gate } 30077c478bd9Sstevel@tonic-gate 30087c478bd9Sstevel@tonic-gate /* device_type */ 30097c478bd9Sstevel@tonic-gate 30107c478bd9Sstevel@tonic-gate (void) ndi_prop_update_string(DDI_DEV_T_NONE, cpu_devi, 30117c478bd9Sstevel@tonic-gate "device_type", "cpu"); 30127c478bd9Sstevel@tonic-gate 30137c478bd9Sstevel@tonic-gate /* reg */ 30147c478bd9Sstevel@tonic-gate 30157c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 30167c478bd9Sstevel@tonic-gate "reg", cpu_id); 30177c478bd9Sstevel@tonic-gate 30187c478bd9Sstevel@tonic-gate /* cpu-mhz, and clock-frequency */ 30197c478bd9Sstevel@tonic-gate 30207c478bd9Sstevel@tonic-gate if (cpu_freq > 0) { 30217c478bd9Sstevel@tonic-gate long long mul; 30227c478bd9Sstevel@tonic-gate 30237c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 30247c478bd9Sstevel@tonic-gate "cpu-mhz", cpu_freq); 30257c478bd9Sstevel@tonic-gate 30267c478bd9Sstevel@tonic-gate if ((mul = cpu_freq * 1000000LL) <= INT_MAX) 30277c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 30287c478bd9Sstevel@tonic-gate "clock-frequency", (int)mul); 30297c478bd9Sstevel@tonic-gate } 30307c478bd9Sstevel@tonic-gate 30317c478bd9Sstevel@tonic-gate (void) ndi_devi_online(cpu_devi, 0); 30327c478bd9Sstevel@tonic-gate 30337c478bd9Sstevel@tonic-gate if ((x86_feature & X86_CPUID) == 0) { 30347c478bd9Sstevel@tonic-gate mutex_exit(&cpu_node_lock); 30357c478bd9Sstevel@tonic-gate return; 30367c478bd9Sstevel@tonic-gate } 30377c478bd9Sstevel@tonic-gate 30387c478bd9Sstevel@tonic-gate /* vendor-id */ 30397c478bd9Sstevel@tonic-gate 30407c478bd9Sstevel@tonic-gate (void) ndi_prop_update_string(DDI_DEV_T_NONE, cpu_devi, 30417c478bd9Sstevel@tonic-gate "vendor-id", cpi->cpi_vendorstr); 30427c478bd9Sstevel@tonic-gate 30437c478bd9Sstevel@tonic-gate if (cpi->cpi_maxeax == 0) { 30447c478bd9Sstevel@tonic-gate mutex_exit(&cpu_node_lock); 30457c478bd9Sstevel@tonic-gate return; 30467c478bd9Sstevel@tonic-gate } 30477c478bd9Sstevel@tonic-gate 30487c478bd9Sstevel@tonic-gate /* 30497c478bd9Sstevel@tonic-gate * family, model, and step 30507c478bd9Sstevel@tonic-gate */ 30517c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 30527c478bd9Sstevel@tonic-gate "family", CPI_FAMILY(cpi)); 30537c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 30547c478bd9Sstevel@tonic-gate "cpu-model", CPI_MODEL(cpi)); 30557c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 30567c478bd9Sstevel@tonic-gate "stepping-id", CPI_STEP(cpi)); 30577c478bd9Sstevel@tonic-gate 30587c478bd9Sstevel@tonic-gate /* type */ 30597c478bd9Sstevel@tonic-gate 30607c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 30617c478bd9Sstevel@tonic-gate case X86_VENDOR_Intel: 30627c478bd9Sstevel@tonic-gate create = 1; 30637c478bd9Sstevel@tonic-gate break; 30647c478bd9Sstevel@tonic-gate default: 30657c478bd9Sstevel@tonic-gate create = 0; 30667c478bd9Sstevel@tonic-gate break; 30677c478bd9Sstevel@tonic-gate } 30687c478bd9Sstevel@tonic-gate if (create) 30697c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 30707c478bd9Sstevel@tonic-gate "type", CPI_TYPE(cpi)); 30717c478bd9Sstevel@tonic-gate 30727c478bd9Sstevel@tonic-gate /* ext-family */ 30737c478bd9Sstevel@tonic-gate 30747c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 30757c478bd9Sstevel@tonic-gate case X86_VENDOR_Intel: 30767c478bd9Sstevel@tonic-gate case X86_VENDOR_AMD: 30777c478bd9Sstevel@tonic-gate create = cpi->cpi_family >= 0xf; 30787c478bd9Sstevel@tonic-gate break; 30797c478bd9Sstevel@tonic-gate default: 30807c478bd9Sstevel@tonic-gate create = 0; 30817c478bd9Sstevel@tonic-gate break; 30827c478bd9Sstevel@tonic-gate } 30837c478bd9Sstevel@tonic-gate if (create) 30847c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 30857c478bd9Sstevel@tonic-gate "ext-family", CPI_FAMILY_XTD(cpi)); 30867c478bd9Sstevel@tonic-gate 30877c478bd9Sstevel@tonic-gate /* ext-model */ 30887c478bd9Sstevel@tonic-gate 30897c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 30907c478bd9Sstevel@tonic-gate case X86_VENDOR_Intel: 309168c91426Sdmick create = CPI_MODEL(cpi) == 0xf; 309268c91426Sdmick break; 30937c478bd9Sstevel@tonic-gate case X86_VENDOR_AMD: 3094ee88d2b9Skchow create = CPI_FAMILY(cpi) == 0xf; 30957c478bd9Sstevel@tonic-gate break; 30967c478bd9Sstevel@tonic-gate default: 30977c478bd9Sstevel@tonic-gate create = 0; 30987c478bd9Sstevel@tonic-gate break; 30997c478bd9Sstevel@tonic-gate } 31007c478bd9Sstevel@tonic-gate if (create) 31017c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 31027c478bd9Sstevel@tonic-gate "ext-model", CPI_MODEL_XTD(cpi)); 31037c478bd9Sstevel@tonic-gate 31047c478bd9Sstevel@tonic-gate /* generation */ 31057c478bd9Sstevel@tonic-gate 31067c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 31077c478bd9Sstevel@tonic-gate case X86_VENDOR_AMD: 31087c478bd9Sstevel@tonic-gate /* 31097c478bd9Sstevel@tonic-gate * AMD K5 model 1 was the first part to support this 31107c478bd9Sstevel@tonic-gate */ 31117c478bd9Sstevel@tonic-gate create = cpi->cpi_xmaxeax >= 0x80000001; 31127c478bd9Sstevel@tonic-gate break; 31137c478bd9Sstevel@tonic-gate default: 31147c478bd9Sstevel@tonic-gate create = 0; 31157c478bd9Sstevel@tonic-gate break; 31167c478bd9Sstevel@tonic-gate } 31177c478bd9Sstevel@tonic-gate if (create) 31187c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 31197c478bd9Sstevel@tonic-gate "generation", BITX((cpi)->cpi_extd[1].cp_eax, 11, 8)); 31207c478bd9Sstevel@tonic-gate 31217c478bd9Sstevel@tonic-gate /* brand-id */ 31227c478bd9Sstevel@tonic-gate 31237c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 31247c478bd9Sstevel@tonic-gate case X86_VENDOR_Intel: 31257c478bd9Sstevel@tonic-gate /* 31267c478bd9Sstevel@tonic-gate * brand id first appeared on Pentium III Xeon model 8, 31277c478bd9Sstevel@tonic-gate * and Celeron model 8 processors and Opteron 31287c478bd9Sstevel@tonic-gate */ 31297c478bd9Sstevel@tonic-gate create = cpi->cpi_family > 6 || 31307c478bd9Sstevel@tonic-gate (cpi->cpi_family == 6 && cpi->cpi_model >= 8); 31317c478bd9Sstevel@tonic-gate break; 31327c478bd9Sstevel@tonic-gate case X86_VENDOR_AMD: 31337c478bd9Sstevel@tonic-gate create = cpi->cpi_family >= 0xf; 31347c478bd9Sstevel@tonic-gate break; 31357c478bd9Sstevel@tonic-gate default: 31367c478bd9Sstevel@tonic-gate create = 0; 31377c478bd9Sstevel@tonic-gate break; 31387c478bd9Sstevel@tonic-gate } 31397c478bd9Sstevel@tonic-gate if (create && cpi->cpi_brandid != 0) { 31407c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 31417c478bd9Sstevel@tonic-gate "brand-id", cpi->cpi_brandid); 31427c478bd9Sstevel@tonic-gate } 31437c478bd9Sstevel@tonic-gate 31447c478bd9Sstevel@tonic-gate /* chunks, and apic-id */ 31457c478bd9Sstevel@tonic-gate 31467c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 31477c478bd9Sstevel@tonic-gate /* 31487c478bd9Sstevel@tonic-gate * first available on Pentium IV and Opteron (K8) 31497c478bd9Sstevel@tonic-gate */ 31505ff02082Sdmick case X86_VENDOR_Intel: 31515ff02082Sdmick create = IS_NEW_F6(cpi) || cpi->cpi_family >= 0xf; 31525ff02082Sdmick break; 31535ff02082Sdmick case X86_VENDOR_AMD: 31547c478bd9Sstevel@tonic-gate create = cpi->cpi_family >= 0xf; 31557c478bd9Sstevel@tonic-gate break; 31567c478bd9Sstevel@tonic-gate default: 31577c478bd9Sstevel@tonic-gate create = 0; 31587c478bd9Sstevel@tonic-gate break; 31597c478bd9Sstevel@tonic-gate } 31607c478bd9Sstevel@tonic-gate if (create) { 31617c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 31627c478bd9Sstevel@tonic-gate "chunks", CPI_CHUNKS(cpi)); 31637c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 31647c478bd9Sstevel@tonic-gate "apic-id", CPI_APIC_ID(cpi)); 31657aec1d6eScindi if (cpi->cpi_chipid >= 0) { 31667c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 31677c478bd9Sstevel@tonic-gate "chip#", cpi->cpi_chipid); 31687aec1d6eScindi (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 31697aec1d6eScindi "clog#", cpi->cpi_clogid); 31707aec1d6eScindi } 31717c478bd9Sstevel@tonic-gate } 31727c478bd9Sstevel@tonic-gate 31737c478bd9Sstevel@tonic-gate /* cpuid-features */ 31747c478bd9Sstevel@tonic-gate 31757c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 31767c478bd9Sstevel@tonic-gate "cpuid-features", CPI_FEATURES_EDX(cpi)); 31777c478bd9Sstevel@tonic-gate 31787c478bd9Sstevel@tonic-gate 31797c478bd9Sstevel@tonic-gate /* cpuid-features-ecx */ 31807c478bd9Sstevel@tonic-gate 31817c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 31827c478bd9Sstevel@tonic-gate case X86_VENDOR_Intel: 31835ff02082Sdmick create = IS_NEW_F6(cpi) || cpi->cpi_family >= 0xf; 31847c478bd9Sstevel@tonic-gate break; 31857c478bd9Sstevel@tonic-gate default: 31867c478bd9Sstevel@tonic-gate create = 0; 31877c478bd9Sstevel@tonic-gate break; 31887c478bd9Sstevel@tonic-gate } 31897c478bd9Sstevel@tonic-gate if (create) 31907c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 31917c478bd9Sstevel@tonic-gate "cpuid-features-ecx", CPI_FEATURES_ECX(cpi)); 31927c478bd9Sstevel@tonic-gate 31937c478bd9Sstevel@tonic-gate /* ext-cpuid-features */ 31947c478bd9Sstevel@tonic-gate 31957c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 31965ff02082Sdmick case X86_VENDOR_Intel: 31977c478bd9Sstevel@tonic-gate case X86_VENDOR_AMD: 31987c478bd9Sstevel@tonic-gate case X86_VENDOR_Cyrix: 31997c478bd9Sstevel@tonic-gate case X86_VENDOR_TM: 32007c478bd9Sstevel@tonic-gate case X86_VENDOR_Centaur: 32017c478bd9Sstevel@tonic-gate create = cpi->cpi_xmaxeax >= 0x80000001; 32027c478bd9Sstevel@tonic-gate break; 32037c478bd9Sstevel@tonic-gate default: 32047c478bd9Sstevel@tonic-gate create = 0; 32057c478bd9Sstevel@tonic-gate break; 32067c478bd9Sstevel@tonic-gate } 32075ff02082Sdmick if (create) { 32087c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 32097c478bd9Sstevel@tonic-gate "ext-cpuid-features", CPI_FEATURES_XTD_EDX(cpi)); 32105ff02082Sdmick (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 32115ff02082Sdmick "ext-cpuid-features-ecx", CPI_FEATURES_XTD_ECX(cpi)); 32125ff02082Sdmick } 32137c478bd9Sstevel@tonic-gate 32147c478bd9Sstevel@tonic-gate /* 32157c478bd9Sstevel@tonic-gate * Brand String first appeared in Intel Pentium IV, AMD K5 32167c478bd9Sstevel@tonic-gate * model 1, and Cyrix GXm. On earlier models we try and 32177c478bd9Sstevel@tonic-gate * simulate something similar .. so this string should always 32187c478bd9Sstevel@tonic-gate * same -something- about the processor, however lame. 32197c478bd9Sstevel@tonic-gate */ 32207c478bd9Sstevel@tonic-gate (void) ndi_prop_update_string(DDI_DEV_T_NONE, cpu_devi, 32217c478bd9Sstevel@tonic-gate "brand-string", cpi->cpi_brandstr); 32227c478bd9Sstevel@tonic-gate 32237c478bd9Sstevel@tonic-gate /* 32247c478bd9Sstevel@tonic-gate * Finally, cache and tlb information 32257c478bd9Sstevel@tonic-gate */ 32267c478bd9Sstevel@tonic-gate switch (x86_which_cacheinfo(cpi)) { 32277c478bd9Sstevel@tonic-gate case X86_VENDOR_Intel: 32287c478bd9Sstevel@tonic-gate intel_walk_cacheinfo(cpi, cpu_devi, add_cacheent_props); 32297c478bd9Sstevel@tonic-gate break; 32307c478bd9Sstevel@tonic-gate case X86_VENDOR_Cyrix: 32317c478bd9Sstevel@tonic-gate cyrix_walk_cacheinfo(cpi, cpu_devi, add_cacheent_props); 32327c478bd9Sstevel@tonic-gate break; 32337c478bd9Sstevel@tonic-gate case X86_VENDOR_AMD: 32347c478bd9Sstevel@tonic-gate amd_cache_info(cpi, cpu_devi); 32357c478bd9Sstevel@tonic-gate break; 32367c478bd9Sstevel@tonic-gate default: 32377c478bd9Sstevel@tonic-gate break; 32387c478bd9Sstevel@tonic-gate } 32397c478bd9Sstevel@tonic-gate 32407c478bd9Sstevel@tonic-gate mutex_exit(&cpu_node_lock); 32417c478bd9Sstevel@tonic-gate } 32427c478bd9Sstevel@tonic-gate 32437c478bd9Sstevel@tonic-gate struct l2info { 32447c478bd9Sstevel@tonic-gate int *l2i_csz; 32457c478bd9Sstevel@tonic-gate int *l2i_lsz; 32467c478bd9Sstevel@tonic-gate int *l2i_assoc; 32477c478bd9Sstevel@tonic-gate int l2i_ret; 32487c478bd9Sstevel@tonic-gate }; 32497c478bd9Sstevel@tonic-gate 32507c478bd9Sstevel@tonic-gate /* 32517c478bd9Sstevel@tonic-gate * A cacheinfo walker that fetches the size, line-size and associativity 32527c478bd9Sstevel@tonic-gate * of the L2 cache 32537c478bd9Sstevel@tonic-gate */ 32547c478bd9Sstevel@tonic-gate static int 32557c478bd9Sstevel@tonic-gate intel_l2cinfo(void *arg, const struct cachetab *ct) 32567c478bd9Sstevel@tonic-gate { 32577c478bd9Sstevel@tonic-gate struct l2info *l2i = arg; 32587c478bd9Sstevel@tonic-gate int *ip; 32597c478bd9Sstevel@tonic-gate 32607c478bd9Sstevel@tonic-gate if (ct->ct_label != l2_cache_str && 32617c478bd9Sstevel@tonic-gate ct->ct_label != sl2_cache_str) 32627c478bd9Sstevel@tonic-gate return (0); /* not an L2 -- keep walking */ 32637c478bd9Sstevel@tonic-gate 32647c478bd9Sstevel@tonic-gate if ((ip = l2i->l2i_csz) != NULL) 32657c478bd9Sstevel@tonic-gate *ip = ct->ct_size; 32667c478bd9Sstevel@tonic-gate if ((ip = l2i->l2i_lsz) != NULL) 32677c478bd9Sstevel@tonic-gate *ip = ct->ct_line_size; 32687c478bd9Sstevel@tonic-gate if ((ip = l2i->l2i_assoc) != NULL) 32697c478bd9Sstevel@tonic-gate *ip = ct->ct_assoc; 32707c478bd9Sstevel@tonic-gate l2i->l2i_ret = ct->ct_size; 32717c478bd9Sstevel@tonic-gate return (1); /* was an L2 -- terminate walk */ 32727c478bd9Sstevel@tonic-gate } 32737c478bd9Sstevel@tonic-gate 32747c478bd9Sstevel@tonic-gate static void 32757c478bd9Sstevel@tonic-gate amd_l2cacheinfo(struct cpuid_info *cpi, struct l2info *l2i) 32767c478bd9Sstevel@tonic-gate { 32778949bcd6Sandrei struct cpuid_regs *cp; 32787c478bd9Sstevel@tonic-gate uint_t size, assoc; 32797c478bd9Sstevel@tonic-gate int *ip; 32807c478bd9Sstevel@tonic-gate 32817c478bd9Sstevel@tonic-gate if (cpi->cpi_xmaxeax < 0x80000006) 32827c478bd9Sstevel@tonic-gate return; 32837c478bd9Sstevel@tonic-gate cp = &cpi->cpi_extd[6]; 32847c478bd9Sstevel@tonic-gate 32857c478bd9Sstevel@tonic-gate if ((assoc = BITX(cp->cp_ecx, 15, 12)) != 0 && 32867c478bd9Sstevel@tonic-gate (size = BITX(cp->cp_ecx, 31, 16)) != 0) { 32877c478bd9Sstevel@tonic-gate uint_t cachesz = size * 1024; 32887c478bd9Sstevel@tonic-gate 32897c478bd9Sstevel@tonic-gate 32907c478bd9Sstevel@tonic-gate if ((ip = l2i->l2i_csz) != NULL) 32917c478bd9Sstevel@tonic-gate *ip = cachesz; 32927c478bd9Sstevel@tonic-gate if ((ip = l2i->l2i_lsz) != NULL) 32937c478bd9Sstevel@tonic-gate *ip = BITX(cp->cp_ecx, 7, 0); 32947c478bd9Sstevel@tonic-gate if ((ip = l2i->l2i_assoc) != NULL) 32957c478bd9Sstevel@tonic-gate *ip = assoc; 32967c478bd9Sstevel@tonic-gate l2i->l2i_ret = cachesz; 32977c478bd9Sstevel@tonic-gate } 32987c478bd9Sstevel@tonic-gate } 32997c478bd9Sstevel@tonic-gate 33007c478bd9Sstevel@tonic-gate int 33017c478bd9Sstevel@tonic-gate getl2cacheinfo(cpu_t *cpu, int *csz, int *lsz, int *assoc) 33027c478bd9Sstevel@tonic-gate { 33037c478bd9Sstevel@tonic-gate struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 33047c478bd9Sstevel@tonic-gate struct l2info __l2info, *l2i = &__l2info; 33057c478bd9Sstevel@tonic-gate 33067c478bd9Sstevel@tonic-gate l2i->l2i_csz = csz; 33077c478bd9Sstevel@tonic-gate l2i->l2i_lsz = lsz; 33087c478bd9Sstevel@tonic-gate l2i->l2i_assoc = assoc; 33097c478bd9Sstevel@tonic-gate l2i->l2i_ret = -1; 33107c478bd9Sstevel@tonic-gate 33117c478bd9Sstevel@tonic-gate switch (x86_which_cacheinfo(cpi)) { 33127c478bd9Sstevel@tonic-gate case X86_VENDOR_Intel: 33137c478bd9Sstevel@tonic-gate intel_walk_cacheinfo(cpi, l2i, intel_l2cinfo); 33147c478bd9Sstevel@tonic-gate break; 33157c478bd9Sstevel@tonic-gate case X86_VENDOR_Cyrix: 33167c478bd9Sstevel@tonic-gate cyrix_walk_cacheinfo(cpi, l2i, intel_l2cinfo); 33177c478bd9Sstevel@tonic-gate break; 33187c478bd9Sstevel@tonic-gate case X86_VENDOR_AMD: 33197c478bd9Sstevel@tonic-gate amd_l2cacheinfo(cpi, l2i); 33207c478bd9Sstevel@tonic-gate break; 33217c478bd9Sstevel@tonic-gate default: 33227c478bd9Sstevel@tonic-gate break; 33237c478bd9Sstevel@tonic-gate } 33247c478bd9Sstevel@tonic-gate return (l2i->l2i_ret); 33257c478bd9Sstevel@tonic-gate } 3326f98fbcecSbholler 3327f98fbcecSbholler size_t 3328f98fbcecSbholler cpuid_get_mwait_size(cpu_t *cpu) 3329f98fbcecSbholler { 3330f98fbcecSbholler ASSERT(cpuid_checkpass(cpu, 2)); 3331f98fbcecSbholler return (cpu->cpu_m.mcpu_cpi->cpi_mwait.mon_max); 3332f98fbcecSbholler } 3333