10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 51582Skchow * Common Development and Distribution License (the "License"). 61582Skchow * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 228906SEric.Saxe@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 259283SBill.Holler@Sun.COM /* 269283SBill.Holler@Sun.COM * Copyright (c) 2009, Intel Corporation. 279283SBill.Holler@Sun.COM * All rights reserved. 289283SBill.Holler@Sun.COM */ 290Sstevel@tonic-gate 300Sstevel@tonic-gate /* 310Sstevel@tonic-gate * Various routines to handle identification 320Sstevel@tonic-gate * and classification of x86 processors. 330Sstevel@tonic-gate */ 340Sstevel@tonic-gate 350Sstevel@tonic-gate #include <sys/types.h> 360Sstevel@tonic-gate #include <sys/archsystm.h> 370Sstevel@tonic-gate #include <sys/x86_archext.h> 380Sstevel@tonic-gate #include <sys/kmem.h> 390Sstevel@tonic-gate #include <sys/systm.h> 400Sstevel@tonic-gate #include <sys/cmn_err.h> 410Sstevel@tonic-gate #include <sys/sunddi.h> 420Sstevel@tonic-gate #include <sys/sunndi.h> 430Sstevel@tonic-gate #include <sys/cpuvar.h> 440Sstevel@tonic-gate #include <sys/processor.h> 455045Sbholler #include <sys/sysmacros.h> 463434Sesaxe #include <sys/pg.h> 470Sstevel@tonic-gate #include <sys/fp.h> 480Sstevel@tonic-gate #include <sys/controlregs.h> 490Sstevel@tonic-gate #include <sys/auxv_386.h> 500Sstevel@tonic-gate #include <sys/bitmap.h> 510Sstevel@tonic-gate #include <sys/memnode.h> 520Sstevel@tonic-gate 537532SSean.Ye@Sun.COM #ifdef __xpv 547532SSean.Ye@Sun.COM #include <sys/hypervisor.h> 558930SBill.Holler@Sun.COM #else 568930SBill.Holler@Sun.COM #include <sys/ontrap.h> 577532SSean.Ye@Sun.COM #endif 587532SSean.Ye@Sun.COM 590Sstevel@tonic-gate /* 600Sstevel@tonic-gate * Pass 0 of cpuid feature analysis happens in locore. It contains special code 610Sstevel@tonic-gate * to recognize Cyrix processors that are not cpuid-compliant, and to deal with 620Sstevel@tonic-gate * them accordingly. For most modern processors, feature detection occurs here 630Sstevel@tonic-gate * in pass 1. 640Sstevel@tonic-gate * 650Sstevel@tonic-gate * Pass 1 of cpuid feature analysis happens just at the beginning of mlsetup() 660Sstevel@tonic-gate * for the boot CPU and does the basic analysis that the early kernel needs. 670Sstevel@tonic-gate * x86_feature is set based on the return value of cpuid_pass1() of the boot 680Sstevel@tonic-gate * CPU. 690Sstevel@tonic-gate * 700Sstevel@tonic-gate * Pass 1 includes: 710Sstevel@tonic-gate * 720Sstevel@tonic-gate * o Determining vendor/model/family/stepping and setting x86_type and 730Sstevel@tonic-gate * x86_vendor accordingly. 740Sstevel@tonic-gate * o Processing the feature flags returned by the cpuid instruction while 750Sstevel@tonic-gate * applying any workarounds or tricks for the specific processor. 760Sstevel@tonic-gate * o Mapping the feature flags into Solaris feature bits (X86_*). 770Sstevel@tonic-gate * o Processing extended feature flags if supported by the processor, 780Sstevel@tonic-gate * again while applying specific processor knowledge. 790Sstevel@tonic-gate * o Determining the CMT characteristics of the system. 800Sstevel@tonic-gate * 810Sstevel@tonic-gate * Pass 1 is done on non-boot CPUs during their initialization and the results 820Sstevel@tonic-gate * are used only as a meager attempt at ensuring that all processors within the 830Sstevel@tonic-gate * system support the same features. 840Sstevel@tonic-gate * 850Sstevel@tonic-gate * Pass 2 of cpuid feature analysis happens just at the beginning 860Sstevel@tonic-gate * of startup(). It just copies in and corrects the remainder 870Sstevel@tonic-gate * of the cpuid data we depend on: standard cpuid functions that we didn't 880Sstevel@tonic-gate * need for pass1 feature analysis, and extended cpuid functions beyond the 890Sstevel@tonic-gate * simple feature processing done in pass1. 900Sstevel@tonic-gate * 910Sstevel@tonic-gate * Pass 3 of cpuid analysis is invoked after basic kernel services; in 920Sstevel@tonic-gate * particular kernel memory allocation has been made available. It creates a 930Sstevel@tonic-gate * readable brand string based on the data collected in the first two passes. 940Sstevel@tonic-gate * 950Sstevel@tonic-gate * Pass 4 of cpuid analysis is invoked after post_startup() when all 960Sstevel@tonic-gate * the support infrastructure for various hardware features has been 970Sstevel@tonic-gate * initialized. It determines which processor features will be reported 980Sstevel@tonic-gate * to userland via the aux vector. 990Sstevel@tonic-gate * 1000Sstevel@tonic-gate * All passes are executed on all CPUs, but only the boot CPU determines what 1010Sstevel@tonic-gate * features the kernel will use. 1020Sstevel@tonic-gate * 1030Sstevel@tonic-gate * Much of the worst junk in this file is for the support of processors 1040Sstevel@tonic-gate * that didn't really implement the cpuid instruction properly. 1050Sstevel@tonic-gate * 1060Sstevel@tonic-gate * NOTE: The accessor functions (cpuid_get*) are aware of, and ASSERT upon, 1070Sstevel@tonic-gate * the pass numbers. Accordingly, changes to the pass code may require changes 1080Sstevel@tonic-gate * to the accessor code. 1090Sstevel@tonic-gate */ 1100Sstevel@tonic-gate 1110Sstevel@tonic-gate uint_t x86_feature = 0; 1120Sstevel@tonic-gate uint_t x86_vendor = X86_VENDOR_IntelClone; 1130Sstevel@tonic-gate uint_t x86_type = X86_TYPE_OTHER; 1147589SVikram.Hegde@Sun.COM uint_t x86_clflush_size = 0; 1150Sstevel@tonic-gate 1160Sstevel@tonic-gate uint_t pentiumpro_bug4046376; 1170Sstevel@tonic-gate uint_t pentiumpro_bug4064495; 1180Sstevel@tonic-gate 1190Sstevel@tonic-gate uint_t enable486; 1208990SSurya.Prakki@Sun.COM /* 1219000SStuart.Maybee@Sun.COM * This is set to platform type Solaris is running on. 1228990SSurya.Prakki@Sun.COM */ 1239000SStuart.Maybee@Sun.COM static int platform_type = HW_NATIVE; 1240Sstevel@tonic-gate 1250Sstevel@tonic-gate /* 1264481Sbholler * monitor/mwait info. 1275045Sbholler * 1285045Sbholler * size_actual and buf_actual are the real address and size allocated to get 1295045Sbholler * proper mwait_buf alignement. buf_actual and size_actual should be passed 1305045Sbholler * to kmem_free(). Currently kmem_alloc() and mwait happen to both use 1315045Sbholler * processor cache-line alignment, but this is not guarantied in the furture. 1324481Sbholler */ 1334481Sbholler struct mwait_info { 1344481Sbholler size_t mon_min; /* min size to avoid missed wakeups */ 1354481Sbholler size_t mon_max; /* size to avoid false wakeups */ 1365045Sbholler size_t size_actual; /* size actually allocated */ 1375045Sbholler void *buf_actual; /* memory actually allocated */ 1384481Sbholler uint32_t support; /* processor support of monitor/mwait */ 1394481Sbholler }; 1404481Sbholler 1414481Sbholler /* 1420Sstevel@tonic-gate * These constants determine how many of the elements of the 1430Sstevel@tonic-gate * cpuid we cache in the cpuid_info data structure; the 1440Sstevel@tonic-gate * remaining elements are accessible via the cpuid instruction. 1450Sstevel@tonic-gate */ 1460Sstevel@tonic-gate 1470Sstevel@tonic-gate #define NMAX_CPI_STD 6 /* eax = 0 .. 5 */ 1480Sstevel@tonic-gate #define NMAX_CPI_EXTD 9 /* eax = 0x80000000 .. 0x80000008 */ 1490Sstevel@tonic-gate 1500Sstevel@tonic-gate struct cpuid_info { 1510Sstevel@tonic-gate uint_t cpi_pass; /* last pass completed */ 1520Sstevel@tonic-gate /* 1530Sstevel@tonic-gate * standard function information 1540Sstevel@tonic-gate */ 1550Sstevel@tonic-gate uint_t cpi_maxeax; /* fn 0: %eax */ 1560Sstevel@tonic-gate char cpi_vendorstr[13]; /* fn 0: %ebx:%ecx:%edx */ 1570Sstevel@tonic-gate uint_t cpi_vendor; /* enum of cpi_vendorstr */ 1580Sstevel@tonic-gate 1590Sstevel@tonic-gate uint_t cpi_family; /* fn 1: extended family */ 1600Sstevel@tonic-gate uint_t cpi_model; /* fn 1: extended model */ 1610Sstevel@tonic-gate uint_t cpi_step; /* fn 1: stepping */ 1620Sstevel@tonic-gate chipid_t cpi_chipid; /* fn 1: %ebx: chip # on ht cpus */ 1630Sstevel@tonic-gate uint_t cpi_brandid; /* fn 1: %ebx: brand ID */ 1640Sstevel@tonic-gate int cpi_clogid; /* fn 1: %ebx: thread # */ 1651228Sandrei uint_t cpi_ncpu_per_chip; /* fn 1: %ebx: logical cpu count */ 1660Sstevel@tonic-gate uint8_t cpi_cacheinfo[16]; /* fn 2: intel-style cache desc */ 1670Sstevel@tonic-gate uint_t cpi_ncache; /* fn 2: number of elements */ 1684606Sesaxe uint_t cpi_ncpu_shr_last_cache; /* fn 4: %eax: ncpus sharing cache */ 1694606Sesaxe id_t cpi_last_lvl_cacheid; /* fn 4: %eax: derived cache id */ 1704606Sesaxe uint_t cpi_std_4_size; /* fn 4: number of fn 4 elements */ 1714606Sesaxe struct cpuid_regs **cpi_std_4; /* fn 4: %ecx == 0 .. fn4_size */ 1721228Sandrei struct cpuid_regs cpi_std[NMAX_CPI_STD]; /* 0 .. 5 */ 1730Sstevel@tonic-gate /* 1740Sstevel@tonic-gate * extended function information 1750Sstevel@tonic-gate */ 1760Sstevel@tonic-gate uint_t cpi_xmaxeax; /* fn 0x80000000: %eax */ 1770Sstevel@tonic-gate char cpi_brandstr[49]; /* fn 0x8000000[234] */ 1780Sstevel@tonic-gate uint8_t cpi_pabits; /* fn 0x80000006: %eax */ 1790Sstevel@tonic-gate uint8_t cpi_vabits; /* fn 0x80000006: %eax */ 1801228Sandrei struct cpuid_regs cpi_extd[NMAX_CPI_EXTD]; /* 0x8000000[0-8] */ 1815870Sgavinm id_t cpi_coreid; /* same coreid => strands share core */ 1825870Sgavinm int cpi_pkgcoreid; /* core number within single package */ 1831228Sandrei uint_t cpi_ncore_per_chip; /* AMD: fn 0x80000008: %ecx[7-0] */ 1841228Sandrei /* Intel: fn 4: %eax[31-26] */ 1850Sstevel@tonic-gate /* 1860Sstevel@tonic-gate * supported feature information 1870Sstevel@tonic-gate */ 1883446Smrj uint32_t cpi_support[5]; 1890Sstevel@tonic-gate #define STD_EDX_FEATURES 0 1900Sstevel@tonic-gate #define AMD_EDX_FEATURES 1 1910Sstevel@tonic-gate #define TM_EDX_FEATURES 2 1920Sstevel@tonic-gate #define STD_ECX_FEATURES 3 1933446Smrj #define AMD_ECX_FEATURES 4 1942869Sgavinm /* 1952869Sgavinm * Synthesized information, where known. 1962869Sgavinm */ 1972869Sgavinm uint32_t cpi_chiprev; /* See X86_CHIPREV_* in x86_archext.h */ 1982869Sgavinm const char *cpi_chiprevstr; /* May be NULL if chiprev unknown */ 1992869Sgavinm uint32_t cpi_socket; /* Chip package/socket type */ 2004481Sbholler 2014481Sbholler struct mwait_info cpi_mwait; /* fn 5: monitor/mwait info */ 2027282Smishra uint32_t cpi_apicid; 2030Sstevel@tonic-gate }; 2040Sstevel@tonic-gate 2050Sstevel@tonic-gate 2060Sstevel@tonic-gate static struct cpuid_info cpuid_info0; 2070Sstevel@tonic-gate 2080Sstevel@tonic-gate /* 2090Sstevel@tonic-gate * These bit fields are defined by the Intel Application Note AP-485 2100Sstevel@tonic-gate * "Intel Processor Identification and the CPUID Instruction" 2110Sstevel@tonic-gate */ 2120Sstevel@tonic-gate #define CPI_FAMILY_XTD(cpi) BITX((cpi)->cpi_std[1].cp_eax, 27, 20) 2130Sstevel@tonic-gate #define CPI_MODEL_XTD(cpi) BITX((cpi)->cpi_std[1].cp_eax, 19, 16) 2140Sstevel@tonic-gate #define CPI_TYPE(cpi) BITX((cpi)->cpi_std[1].cp_eax, 13, 12) 2150Sstevel@tonic-gate #define CPI_FAMILY(cpi) BITX((cpi)->cpi_std[1].cp_eax, 11, 8) 2160Sstevel@tonic-gate #define CPI_STEP(cpi) BITX((cpi)->cpi_std[1].cp_eax, 3, 0) 2170Sstevel@tonic-gate #define CPI_MODEL(cpi) BITX((cpi)->cpi_std[1].cp_eax, 7, 4) 2180Sstevel@tonic-gate 2190Sstevel@tonic-gate #define CPI_FEATURES_EDX(cpi) ((cpi)->cpi_std[1].cp_edx) 2200Sstevel@tonic-gate #define CPI_FEATURES_ECX(cpi) ((cpi)->cpi_std[1].cp_ecx) 2210Sstevel@tonic-gate #define CPI_FEATURES_XTD_EDX(cpi) ((cpi)->cpi_extd[1].cp_edx) 2220Sstevel@tonic-gate #define CPI_FEATURES_XTD_ECX(cpi) ((cpi)->cpi_extd[1].cp_ecx) 2230Sstevel@tonic-gate 2240Sstevel@tonic-gate #define CPI_BRANDID(cpi) BITX((cpi)->cpi_std[1].cp_ebx, 7, 0) 2250Sstevel@tonic-gate #define CPI_CHUNKS(cpi) BITX((cpi)->cpi_std[1].cp_ebx, 15, 7) 2260Sstevel@tonic-gate #define CPI_CPU_COUNT(cpi) BITX((cpi)->cpi_std[1].cp_ebx, 23, 16) 2270Sstevel@tonic-gate #define CPI_APIC_ID(cpi) BITX((cpi)->cpi_std[1].cp_ebx, 31, 24) 2280Sstevel@tonic-gate 2290Sstevel@tonic-gate #define CPI_MAXEAX_MAX 0x100 /* sanity control */ 2300Sstevel@tonic-gate #define CPI_XMAXEAX_MAX 0x80000100 2314606Sesaxe #define CPI_FN4_ECX_MAX 0x20 /* sanity: max fn 4 levels */ 2327282Smishra #define CPI_FNB_ECX_MAX 0x20 /* sanity: max fn B levels */ 2334606Sesaxe 2344606Sesaxe /* 2354606Sesaxe * Function 4 (Deterministic Cache Parameters) macros 2364606Sesaxe * Defined by Intel Application Note AP-485 2374606Sesaxe */ 2384606Sesaxe #define CPI_NUM_CORES(regs) BITX((regs)->cp_eax, 31, 26) 2394606Sesaxe #define CPI_NTHR_SHR_CACHE(regs) BITX((regs)->cp_eax, 25, 14) 2404606Sesaxe #define CPI_FULL_ASSOC_CACHE(regs) BITX((regs)->cp_eax, 9, 9) 2414606Sesaxe #define CPI_SELF_INIT_CACHE(regs) BITX((regs)->cp_eax, 8, 8) 2424606Sesaxe #define CPI_CACHE_LVL(regs) BITX((regs)->cp_eax, 7, 5) 2434606Sesaxe #define CPI_CACHE_TYPE(regs) BITX((regs)->cp_eax, 4, 0) 2447282Smishra #define CPI_CPU_LEVEL_TYPE(regs) BITX((regs)->cp_ecx, 15, 8) 2454606Sesaxe 2464606Sesaxe #define CPI_CACHE_WAYS(regs) BITX((regs)->cp_ebx, 31, 22) 2474606Sesaxe #define CPI_CACHE_PARTS(regs) BITX((regs)->cp_ebx, 21, 12) 2484606Sesaxe #define CPI_CACHE_COH_LN_SZ(regs) BITX((regs)->cp_ebx, 11, 0) 2494606Sesaxe 2504606Sesaxe #define CPI_CACHE_SETS(regs) BITX((regs)->cp_ecx, 31, 0) 2514606Sesaxe 2524606Sesaxe #define CPI_PREFCH_STRIDE(regs) BITX((regs)->cp_edx, 9, 0) 2534606Sesaxe 2540Sstevel@tonic-gate 2550Sstevel@tonic-gate /* 2561975Sdmick * A couple of shorthand macros to identify "later" P6-family chips 2571975Sdmick * like the Pentium M and Core. First, the "older" P6-based stuff 2581975Sdmick * (loosely defined as "pre-Pentium-4"): 2591975Sdmick * P6, PII, Mobile PII, PII Xeon, PIII, Mobile PIII, PIII Xeon 2601975Sdmick */ 2611975Sdmick 2621975Sdmick #define IS_LEGACY_P6(cpi) ( \ 2631975Sdmick cpi->cpi_family == 6 && \ 2641975Sdmick (cpi->cpi_model == 1 || \ 2651975Sdmick cpi->cpi_model == 3 || \ 2661975Sdmick cpi->cpi_model == 5 || \ 2671975Sdmick cpi->cpi_model == 6 || \ 2681975Sdmick cpi->cpi_model == 7 || \ 2691975Sdmick cpi->cpi_model == 8 || \ 2701975Sdmick cpi->cpi_model == 0xA || \ 2711975Sdmick cpi->cpi_model == 0xB) \ 2721975Sdmick ) 2731975Sdmick 2741975Sdmick /* A "new F6" is everything with family 6 that's not the above */ 2751975Sdmick #define IS_NEW_F6(cpi) ((cpi->cpi_family == 6) && !IS_LEGACY_P6(cpi)) 2761975Sdmick 2774855Sksadhukh /* Extended family/model support */ 2784855Sksadhukh #define IS_EXTENDED_MODEL_INTEL(cpi) (cpi->cpi_family == 0x6 || \ 2794855Sksadhukh cpi->cpi_family >= 0xf) 2804855Sksadhukh 2811975Sdmick /* 2824481Sbholler * Info for monitor/mwait idle loop. 2834481Sbholler * 2844481Sbholler * See cpuid section of "Intel 64 and IA-32 Architectures Software Developer's 2854481Sbholler * Manual Volume 2A: Instruction Set Reference, A-M" #25366-022US, November 2864481Sbholler * 2006. 2874481Sbholler * See MONITOR/MWAIT section of "AMD64 Architecture Programmer's Manual 2884481Sbholler * Documentation Updates" #33633, Rev 2.05, December 2006. 2894481Sbholler */ 2904481Sbholler #define MWAIT_SUPPORT (0x00000001) /* mwait supported */ 2914481Sbholler #define MWAIT_EXTENSIONS (0x00000002) /* extenstion supported */ 2924481Sbholler #define MWAIT_ECX_INT_ENABLE (0x00000004) /* ecx 1 extension supported */ 2934481Sbholler #define MWAIT_SUPPORTED(cpi) ((cpi)->cpi_std[1].cp_ecx & CPUID_INTC_ECX_MON) 2944481Sbholler #define MWAIT_INT_ENABLE(cpi) ((cpi)->cpi_std[5].cp_ecx & 0x2) 2954481Sbholler #define MWAIT_EXTENSION(cpi) ((cpi)->cpi_std[5].cp_ecx & 0x1) 2964481Sbholler #define MWAIT_SIZE_MIN(cpi) BITX((cpi)->cpi_std[5].cp_eax, 15, 0) 2974481Sbholler #define MWAIT_SIZE_MAX(cpi) BITX((cpi)->cpi_std[5].cp_ebx, 15, 0) 2984481Sbholler /* 2994481Sbholler * Number of sub-cstates for a given c-state. 3004481Sbholler */ 3014481Sbholler #define MWAIT_NUM_SUBC_STATES(cpi, c_state) \ 3024481Sbholler BITX((cpi)->cpi_std[5].cp_edx, c_state + 3, c_state) 3034481Sbholler 3047532SSean.Ye@Sun.COM /* 3057532SSean.Ye@Sun.COM * Functions we consune from cpuid_subr.c; don't publish these in a header 3067532SSean.Ye@Sun.COM * file to try and keep people using the expected cpuid_* interfaces. 3077532SSean.Ye@Sun.COM */ 3087532SSean.Ye@Sun.COM extern uint32_t _cpuid_skt(uint_t, uint_t, uint_t, uint_t); 3099482SKuriakose.Kuruvilla@Sun.COM extern const char *_cpuid_sktstr(uint_t, uint_t, uint_t, uint_t); 3107532SSean.Ye@Sun.COM extern uint32_t _cpuid_chiprev(uint_t, uint_t, uint_t, uint_t); 3117532SSean.Ye@Sun.COM extern const char *_cpuid_chiprevstr(uint_t, uint_t, uint_t, uint_t); 3127532SSean.Ye@Sun.COM extern uint_t _cpuid_vendorstr_to_vendorcode(char *); 3132869Sgavinm 3142869Sgavinm /* 3153446Smrj * Apply up various platform-dependent restrictions where the 3163446Smrj * underlying platform restrictions mean the CPU can be marked 3173446Smrj * as less capable than its cpuid instruction would imply. 3183446Smrj */ 3195084Sjohnlev #if defined(__xpv) 3205084Sjohnlev static void 3215084Sjohnlev platform_cpuid_mangle(uint_t vendor, uint32_t eax, struct cpuid_regs *cp) 3225084Sjohnlev { 3235084Sjohnlev switch (eax) { 3247532SSean.Ye@Sun.COM case 1: { 3257532SSean.Ye@Sun.COM uint32_t mcamask = DOMAIN_IS_INITDOMAIN(xen_info) ? 3267532SSean.Ye@Sun.COM 0 : CPUID_INTC_EDX_MCA; 3275084Sjohnlev cp->cp_edx &= 3287532SSean.Ye@Sun.COM ~(mcamask | 3297532SSean.Ye@Sun.COM CPUID_INTC_EDX_PSE | 3305084Sjohnlev CPUID_INTC_EDX_VME | CPUID_INTC_EDX_DE | 3315084Sjohnlev CPUID_INTC_EDX_SEP | CPUID_INTC_EDX_MTRR | 3325084Sjohnlev CPUID_INTC_EDX_PGE | CPUID_INTC_EDX_PAT | 3335084Sjohnlev CPUID_AMD_EDX_SYSC | CPUID_INTC_EDX_SEP | 3345084Sjohnlev CPUID_INTC_EDX_PSE36 | CPUID_INTC_EDX_HTT); 3355084Sjohnlev break; 3367532SSean.Ye@Sun.COM } 3375084Sjohnlev 3385084Sjohnlev case 0x80000001: 3395084Sjohnlev cp->cp_edx &= 3405084Sjohnlev ~(CPUID_AMD_EDX_PSE | 3415084Sjohnlev CPUID_INTC_EDX_VME | CPUID_INTC_EDX_DE | 3425084Sjohnlev CPUID_AMD_EDX_MTRR | CPUID_AMD_EDX_PGE | 3435084Sjohnlev CPUID_AMD_EDX_PAT | CPUID_AMD_EDX_PSE36 | 3445084Sjohnlev CPUID_AMD_EDX_SYSC | CPUID_INTC_EDX_SEP | 3455084Sjohnlev CPUID_AMD_EDX_TSCP); 3465084Sjohnlev cp->cp_ecx &= ~CPUID_AMD_ECX_CMP_LGCY; 3475084Sjohnlev break; 3485084Sjohnlev default: 3495084Sjohnlev break; 3505084Sjohnlev } 3515084Sjohnlev 3525084Sjohnlev switch (vendor) { 3535084Sjohnlev case X86_VENDOR_Intel: 3545084Sjohnlev switch (eax) { 3555084Sjohnlev case 4: 3565084Sjohnlev /* 3575084Sjohnlev * Zero out the (ncores-per-chip - 1) field 3585084Sjohnlev */ 3595084Sjohnlev cp->cp_eax &= 0x03fffffff; 3605084Sjohnlev break; 3615084Sjohnlev default: 3625084Sjohnlev break; 3635084Sjohnlev } 3645084Sjohnlev break; 3655084Sjohnlev case X86_VENDOR_AMD: 3665084Sjohnlev switch (eax) { 367*10080SJoe.Bonasera@sun.com 368*10080SJoe.Bonasera@sun.com case 0x80000001: 369*10080SJoe.Bonasera@sun.com cp->cp_ecx &= ~CPUID_AMD_ECX_CR8D; 370*10080SJoe.Bonasera@sun.com break; 371*10080SJoe.Bonasera@sun.com 3725084Sjohnlev case 0x80000008: 3735084Sjohnlev /* 3745084Sjohnlev * Zero out the (ncores-per-chip - 1) field 3755084Sjohnlev */ 3765084Sjohnlev cp->cp_ecx &= 0xffffff00; 3775084Sjohnlev break; 3785084Sjohnlev default: 3795084Sjohnlev break; 3805084Sjohnlev } 3815084Sjohnlev break; 3825084Sjohnlev default: 3835084Sjohnlev break; 3845084Sjohnlev } 3855084Sjohnlev } 3865084Sjohnlev #else 3873446Smrj #define platform_cpuid_mangle(vendor, eax, cp) /* nothing */ 3885084Sjohnlev #endif 3893446Smrj 3903446Smrj /* 3910Sstevel@tonic-gate * Some undocumented ways of patching the results of the cpuid 3920Sstevel@tonic-gate * instruction to permit running Solaris 10 on future cpus that 3930Sstevel@tonic-gate * we don't currently support. Could be set to non-zero values 3940Sstevel@tonic-gate * via settings in eeprom. 3950Sstevel@tonic-gate */ 3960Sstevel@tonic-gate 3970Sstevel@tonic-gate uint32_t cpuid_feature_ecx_include; 3980Sstevel@tonic-gate uint32_t cpuid_feature_ecx_exclude; 3990Sstevel@tonic-gate uint32_t cpuid_feature_edx_include; 4000Sstevel@tonic-gate uint32_t cpuid_feature_edx_exclude; 4010Sstevel@tonic-gate 4023446Smrj void 4033446Smrj cpuid_alloc_space(cpu_t *cpu) 4043446Smrj { 4053446Smrj /* 4063446Smrj * By convention, cpu0 is the boot cpu, which is set up 4073446Smrj * before memory allocation is available. All other cpus get 4083446Smrj * their cpuid_info struct allocated here. 4093446Smrj */ 4103446Smrj ASSERT(cpu->cpu_id != 0); 4113446Smrj cpu->cpu_m.mcpu_cpi = 4123446Smrj kmem_zalloc(sizeof (*cpu->cpu_m.mcpu_cpi), KM_SLEEP); 4133446Smrj } 4143446Smrj 4153446Smrj void 4163446Smrj cpuid_free_space(cpu_t *cpu) 4173446Smrj { 4184606Sesaxe struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 4194606Sesaxe int i; 4204606Sesaxe 4213446Smrj ASSERT(cpu->cpu_id != 0); 4224606Sesaxe 4234606Sesaxe /* 4244606Sesaxe * Free up any function 4 related dynamic storage 4254606Sesaxe */ 4264606Sesaxe for (i = 1; i < cpi->cpi_std_4_size; i++) 4274606Sesaxe kmem_free(cpi->cpi_std_4[i], sizeof (struct cpuid_regs)); 4284606Sesaxe if (cpi->cpi_std_4_size > 0) 4294606Sesaxe kmem_free(cpi->cpi_std_4, 4304606Sesaxe cpi->cpi_std_4_size * sizeof (struct cpuid_regs *)); 4314606Sesaxe 4323446Smrj kmem_free(cpu->cpu_m.mcpu_cpi, sizeof (*cpu->cpu_m.mcpu_cpi)); 4333446Smrj } 4343446Smrj 4355741Smrj #if !defined(__xpv) 4365741Smrj 4375741Smrj static void 4389000SStuart.Maybee@Sun.COM determine_platform() 4395741Smrj { 4405741Smrj struct cpuid_regs cp; 4415741Smrj char *xen_str; 4425741Smrj uint32_t xen_signature[4]; 4435741Smrj 4445741Smrj /* 4455741Smrj * In a fully virtualized domain, Xen's pseudo-cpuid function 4465741Smrj * 0x40000000 returns a string representing the Xen signature in 4475741Smrj * %ebx, %ecx, and %edx. %eax contains the maximum supported cpuid 4485741Smrj * function. 4495741Smrj */ 4505741Smrj cp.cp_eax = 0x40000000; 4515741Smrj (void) __cpuid_insn(&cp); 4525741Smrj xen_signature[0] = cp.cp_ebx; 4535741Smrj xen_signature[1] = cp.cp_ecx; 4545741Smrj xen_signature[2] = cp.cp_edx; 4555741Smrj xen_signature[3] = 0; 4565741Smrj xen_str = (char *)xen_signature; 4579000SStuart.Maybee@Sun.COM if (strcmp("XenVMMXenVMM", xen_str) == 0 && cp.cp_eax <= 0x40000002) { 4589000SStuart.Maybee@Sun.COM platform_type = HW_XEN_HVM; 4599000SStuart.Maybee@Sun.COM } else if (vmware_platform()) { /* running under vmware hypervisor? */ 4609000SStuart.Maybee@Sun.COM platform_type = HW_VMWARE; 4619000SStuart.Maybee@Sun.COM } 4629000SStuart.Maybee@Sun.COM } 4639000SStuart.Maybee@Sun.COM 4649000SStuart.Maybee@Sun.COM int 4659000SStuart.Maybee@Sun.COM get_hwenv(void) 4669000SStuart.Maybee@Sun.COM { 4679000SStuart.Maybee@Sun.COM return (platform_type); 4685741Smrj } 4699000SStuart.Maybee@Sun.COM 4709000SStuart.Maybee@Sun.COM int 4719000SStuart.Maybee@Sun.COM is_controldom(void) 4729000SStuart.Maybee@Sun.COM { 4739000SStuart.Maybee@Sun.COM return (0); 4749000SStuart.Maybee@Sun.COM } 4759000SStuart.Maybee@Sun.COM 4769000SStuart.Maybee@Sun.COM #else 4779000SStuart.Maybee@Sun.COM 4789000SStuart.Maybee@Sun.COM int 4799000SStuart.Maybee@Sun.COM get_hwenv(void) 4809000SStuart.Maybee@Sun.COM { 4819000SStuart.Maybee@Sun.COM return (HW_XEN_PV); 4829000SStuart.Maybee@Sun.COM } 4839000SStuart.Maybee@Sun.COM 4849000SStuart.Maybee@Sun.COM int 4859000SStuart.Maybee@Sun.COM is_controldom(void) 4869000SStuart.Maybee@Sun.COM { 4879000SStuart.Maybee@Sun.COM return (DOMAIN_IS_INITDOMAIN(xen_info)); 4889000SStuart.Maybee@Sun.COM } 4899000SStuart.Maybee@Sun.COM 4905741Smrj #endif /* __xpv */ 4915741Smrj 4920Sstevel@tonic-gate uint_t 4930Sstevel@tonic-gate cpuid_pass1(cpu_t *cpu) 4940Sstevel@tonic-gate { 4950Sstevel@tonic-gate uint32_t mask_ecx, mask_edx; 4960Sstevel@tonic-gate uint_t feature = X86_CPUID; 4970Sstevel@tonic-gate struct cpuid_info *cpi; 4981228Sandrei struct cpuid_regs *cp; 4990Sstevel@tonic-gate int xcpuid; 5005084Sjohnlev #if !defined(__xpv) 5015045Sbholler extern int idle_cpu_prefer_mwait; 5025084Sjohnlev #endif 5033446Smrj 5049482SKuriakose.Kuruvilla@Sun.COM 5059482SKuriakose.Kuruvilla@Sun.COM #if !defined(__xpv) 5069482SKuriakose.Kuruvilla@Sun.COM determine_platform(); 5079482SKuriakose.Kuruvilla@Sun.COM #endif 5080Sstevel@tonic-gate /* 5093446Smrj * Space statically allocated for cpu0, ensure pointer is set 5100Sstevel@tonic-gate */ 5110Sstevel@tonic-gate if (cpu->cpu_id == 0) 5123446Smrj cpu->cpu_m.mcpu_cpi = &cpuid_info0; 5133446Smrj cpi = cpu->cpu_m.mcpu_cpi; 5143446Smrj ASSERT(cpi != NULL); 5150Sstevel@tonic-gate cp = &cpi->cpi_std[0]; 5161228Sandrei cp->cp_eax = 0; 5171228Sandrei cpi->cpi_maxeax = __cpuid_insn(cp); 5180Sstevel@tonic-gate { 5190Sstevel@tonic-gate uint32_t *iptr = (uint32_t *)cpi->cpi_vendorstr; 5200Sstevel@tonic-gate *iptr++ = cp->cp_ebx; 5210Sstevel@tonic-gate *iptr++ = cp->cp_edx; 5220Sstevel@tonic-gate *iptr++ = cp->cp_ecx; 5230Sstevel@tonic-gate *(char *)&cpi->cpi_vendorstr[12] = '\0'; 5240Sstevel@tonic-gate } 5250Sstevel@tonic-gate 5267532SSean.Ye@Sun.COM cpi->cpi_vendor = _cpuid_vendorstr_to_vendorcode(cpi->cpi_vendorstr); 5270Sstevel@tonic-gate x86_vendor = cpi->cpi_vendor; /* for compatibility */ 5280Sstevel@tonic-gate 5290Sstevel@tonic-gate /* 5300Sstevel@tonic-gate * Limit the range in case of weird hardware 5310Sstevel@tonic-gate */ 5320Sstevel@tonic-gate if (cpi->cpi_maxeax > CPI_MAXEAX_MAX) 5330Sstevel@tonic-gate cpi->cpi_maxeax = CPI_MAXEAX_MAX; 5340Sstevel@tonic-gate if (cpi->cpi_maxeax < 1) 5350Sstevel@tonic-gate goto pass1_done; 5360Sstevel@tonic-gate 5370Sstevel@tonic-gate cp = &cpi->cpi_std[1]; 5381228Sandrei cp->cp_eax = 1; 5391228Sandrei (void) __cpuid_insn(cp); 5400Sstevel@tonic-gate 5410Sstevel@tonic-gate /* 5420Sstevel@tonic-gate * Extract identifying constants for easy access. 5430Sstevel@tonic-gate */ 5440Sstevel@tonic-gate cpi->cpi_model = CPI_MODEL(cpi); 5450Sstevel@tonic-gate cpi->cpi_family = CPI_FAMILY(cpi); 5460Sstevel@tonic-gate 5471975Sdmick if (cpi->cpi_family == 0xf) 5480Sstevel@tonic-gate cpi->cpi_family += CPI_FAMILY_XTD(cpi); 5491975Sdmick 5502001Sdmick /* 5514265Skchow * Beware: AMD uses "extended model" iff base *FAMILY* == 0xf. 5522001Sdmick * Intel, and presumably everyone else, uses model == 0xf, as 5532001Sdmick * one would expect (max value means possible overflow). Sigh. 5542001Sdmick */ 5552001Sdmick 5562001Sdmick switch (cpi->cpi_vendor) { 5574855Sksadhukh case X86_VENDOR_Intel: 5584855Sksadhukh if (IS_EXTENDED_MODEL_INTEL(cpi)) 5594855Sksadhukh cpi->cpi_model += CPI_MODEL_XTD(cpi) << 4; 5604858Sksadhukh break; 5612001Sdmick case X86_VENDOR_AMD: 5624265Skchow if (CPI_FAMILY(cpi) == 0xf) 5632001Sdmick cpi->cpi_model += CPI_MODEL_XTD(cpi) << 4; 5642001Sdmick break; 5652001Sdmick default: 5662001Sdmick if (cpi->cpi_model == 0xf) 5672001Sdmick cpi->cpi_model += CPI_MODEL_XTD(cpi) << 4; 5682001Sdmick break; 5692001Sdmick } 5700Sstevel@tonic-gate 5710Sstevel@tonic-gate cpi->cpi_step = CPI_STEP(cpi); 5720Sstevel@tonic-gate cpi->cpi_brandid = CPI_BRANDID(cpi); 5730Sstevel@tonic-gate 5740Sstevel@tonic-gate /* 5750Sstevel@tonic-gate * *default* assumptions: 5760Sstevel@tonic-gate * - believe %edx feature word 5770Sstevel@tonic-gate * - ignore %ecx feature word 5780Sstevel@tonic-gate * - 32-bit virtual and physical addressing 5790Sstevel@tonic-gate */ 5800Sstevel@tonic-gate mask_edx = 0xffffffff; 5810Sstevel@tonic-gate mask_ecx = 0; 5820Sstevel@tonic-gate 5830Sstevel@tonic-gate cpi->cpi_pabits = cpi->cpi_vabits = 32; 5840Sstevel@tonic-gate 5850Sstevel@tonic-gate switch (cpi->cpi_vendor) { 5860Sstevel@tonic-gate case X86_VENDOR_Intel: 5870Sstevel@tonic-gate if (cpi->cpi_family == 5) 5880Sstevel@tonic-gate x86_type = X86_TYPE_P5; 5891975Sdmick else if (IS_LEGACY_P6(cpi)) { 5900Sstevel@tonic-gate x86_type = X86_TYPE_P6; 5910Sstevel@tonic-gate pentiumpro_bug4046376 = 1; 5920Sstevel@tonic-gate pentiumpro_bug4064495 = 1; 5930Sstevel@tonic-gate /* 5940Sstevel@tonic-gate * Clear the SEP bit when it was set erroneously 5950Sstevel@tonic-gate */ 5960Sstevel@tonic-gate if (cpi->cpi_model < 3 && cpi->cpi_step < 3) 5970Sstevel@tonic-gate cp->cp_edx &= ~CPUID_INTC_EDX_SEP; 5981975Sdmick } else if (IS_NEW_F6(cpi) || cpi->cpi_family == 0xf) { 5990Sstevel@tonic-gate x86_type = X86_TYPE_P4; 6000Sstevel@tonic-gate /* 6010Sstevel@tonic-gate * We don't currently depend on any of the %ecx 6020Sstevel@tonic-gate * features until Prescott, so we'll only check 6030Sstevel@tonic-gate * this from P4 onwards. We might want to revisit 6040Sstevel@tonic-gate * that idea later. 6050Sstevel@tonic-gate */ 6060Sstevel@tonic-gate mask_ecx = 0xffffffff; 6070Sstevel@tonic-gate } else if (cpi->cpi_family > 0xf) 6080Sstevel@tonic-gate mask_ecx = 0xffffffff; 6094636Sbholler /* 6104636Sbholler * We don't support MONITOR/MWAIT if leaf 5 is not available 6114636Sbholler * to obtain the monitor linesize. 6124636Sbholler */ 6134636Sbholler if (cpi->cpi_maxeax < 5) 6144636Sbholler mask_ecx &= ~CPUID_INTC_ECX_MON; 6150Sstevel@tonic-gate break; 6160Sstevel@tonic-gate case X86_VENDOR_IntelClone: 6170Sstevel@tonic-gate default: 6180Sstevel@tonic-gate break; 6190Sstevel@tonic-gate case X86_VENDOR_AMD: 6200Sstevel@tonic-gate #if defined(OPTERON_ERRATUM_108) 6210Sstevel@tonic-gate if (cpi->cpi_family == 0xf && cpi->cpi_model == 0xe) { 6220Sstevel@tonic-gate cp->cp_eax = (0xf0f & cp->cp_eax) | 0xc0; 6230Sstevel@tonic-gate cpi->cpi_model = 0xc; 6240Sstevel@tonic-gate } else 6250Sstevel@tonic-gate #endif 6260Sstevel@tonic-gate if (cpi->cpi_family == 5) { 6270Sstevel@tonic-gate /* 6280Sstevel@tonic-gate * AMD K5 and K6 6290Sstevel@tonic-gate * 6300Sstevel@tonic-gate * These CPUs have an incomplete implementation 6310Sstevel@tonic-gate * of MCA/MCE which we mask away. 6320Sstevel@tonic-gate */ 6331228Sandrei mask_edx &= ~(CPUID_INTC_EDX_MCE | CPUID_INTC_EDX_MCA); 6341228Sandrei 6351228Sandrei /* 6361228Sandrei * Model 0 uses the wrong (APIC) bit 6371228Sandrei * to indicate PGE. Fix it here. 6381228Sandrei */ 6390Sstevel@tonic-gate if (cpi->cpi_model == 0) { 6400Sstevel@tonic-gate if (cp->cp_edx & 0x200) { 6410Sstevel@tonic-gate cp->cp_edx &= ~0x200; 6420Sstevel@tonic-gate cp->cp_edx |= CPUID_INTC_EDX_PGE; 6430Sstevel@tonic-gate } 6441228Sandrei } 6451228Sandrei 6461228Sandrei /* 6471228Sandrei * Early models had problems w/ MMX; disable. 6481228Sandrei */ 6491228Sandrei if (cpi->cpi_model < 6) 6501228Sandrei mask_edx &= ~CPUID_INTC_EDX_MMX; 6511228Sandrei } 6521228Sandrei 6531228Sandrei /* 6541228Sandrei * For newer families, SSE3 and CX16, at least, are valid; 6551228Sandrei * enable all 6561228Sandrei */ 6571228Sandrei if (cpi->cpi_family >= 0xf) 658771Sdmick mask_ecx = 0xffffffff; 6594636Sbholler /* 6604636Sbholler * We don't support MONITOR/MWAIT if leaf 5 is not available 6614636Sbholler * to obtain the monitor linesize. 6624636Sbholler */ 6634636Sbholler if (cpi->cpi_maxeax < 5) 6644636Sbholler mask_ecx &= ~CPUID_INTC_ECX_MON; 6655045Sbholler 6665084Sjohnlev #if !defined(__xpv) 6675045Sbholler /* 6685045Sbholler * Do not use MONITOR/MWAIT to halt in the idle loop on any AMD 6695045Sbholler * processors. AMD does not intend MWAIT to be used in the cpu 6705045Sbholler * idle loop on current and future processors. 10h and future 6715045Sbholler * AMD processors use more power in MWAIT than HLT. 6725045Sbholler * Pre-family-10h Opterons do not have the MWAIT instruction. 6735045Sbholler */ 6745045Sbholler idle_cpu_prefer_mwait = 0; 6755084Sjohnlev #endif 6765045Sbholler 6770Sstevel@tonic-gate break; 6780Sstevel@tonic-gate case X86_VENDOR_TM: 6790Sstevel@tonic-gate /* 6800Sstevel@tonic-gate * workaround the NT workaround in CMS 4.1 6810Sstevel@tonic-gate */ 6820Sstevel@tonic-gate if (cpi->cpi_family == 5 && cpi->cpi_model == 4 && 6830Sstevel@tonic-gate (cpi->cpi_step == 2 || cpi->cpi_step == 3)) 6840Sstevel@tonic-gate cp->cp_edx |= CPUID_INTC_EDX_CX8; 6850Sstevel@tonic-gate break; 6860Sstevel@tonic-gate case X86_VENDOR_Centaur: 6870Sstevel@tonic-gate /* 6880Sstevel@tonic-gate * workaround the NT workarounds again 6890Sstevel@tonic-gate */ 6900Sstevel@tonic-gate if (cpi->cpi_family == 6) 6910Sstevel@tonic-gate cp->cp_edx |= CPUID_INTC_EDX_CX8; 6920Sstevel@tonic-gate break; 6930Sstevel@tonic-gate case X86_VENDOR_Cyrix: 6940Sstevel@tonic-gate /* 6950Sstevel@tonic-gate * We rely heavily on the probing in locore 6960Sstevel@tonic-gate * to actually figure out what parts, if any, 6970Sstevel@tonic-gate * of the Cyrix cpuid instruction to believe. 6980Sstevel@tonic-gate */ 6990Sstevel@tonic-gate switch (x86_type) { 7000Sstevel@tonic-gate case X86_TYPE_CYRIX_486: 7010Sstevel@tonic-gate mask_edx = 0; 7020Sstevel@tonic-gate break; 7030Sstevel@tonic-gate case X86_TYPE_CYRIX_6x86: 7040Sstevel@tonic-gate mask_edx = 0; 7050Sstevel@tonic-gate break; 7060Sstevel@tonic-gate case X86_TYPE_CYRIX_6x86L: 7070Sstevel@tonic-gate mask_edx = 7080Sstevel@tonic-gate CPUID_INTC_EDX_DE | 7090Sstevel@tonic-gate CPUID_INTC_EDX_CX8; 7100Sstevel@tonic-gate break; 7110Sstevel@tonic-gate case X86_TYPE_CYRIX_6x86MX: 7120Sstevel@tonic-gate mask_edx = 7130Sstevel@tonic-gate CPUID_INTC_EDX_DE | 7140Sstevel@tonic-gate CPUID_INTC_EDX_MSR | 7150Sstevel@tonic-gate CPUID_INTC_EDX_CX8 | 7160Sstevel@tonic-gate CPUID_INTC_EDX_PGE | 7170Sstevel@tonic-gate CPUID_INTC_EDX_CMOV | 7180Sstevel@tonic-gate CPUID_INTC_EDX_MMX; 7190Sstevel@tonic-gate break; 7200Sstevel@tonic-gate case X86_TYPE_CYRIX_GXm: 7210Sstevel@tonic-gate mask_edx = 7220Sstevel@tonic-gate CPUID_INTC_EDX_MSR | 7230Sstevel@tonic-gate CPUID_INTC_EDX_CX8 | 7240Sstevel@tonic-gate CPUID_INTC_EDX_CMOV | 7250Sstevel@tonic-gate CPUID_INTC_EDX_MMX; 7260Sstevel@tonic-gate break; 7270Sstevel@tonic-gate case X86_TYPE_CYRIX_MediaGX: 7280Sstevel@tonic-gate break; 7290Sstevel@tonic-gate case X86_TYPE_CYRIX_MII: 7300Sstevel@tonic-gate case X86_TYPE_VIA_CYRIX_III: 7310Sstevel@tonic-gate mask_edx = 7320Sstevel@tonic-gate CPUID_INTC_EDX_DE | 7330Sstevel@tonic-gate CPUID_INTC_EDX_TSC | 7340Sstevel@tonic-gate CPUID_INTC_EDX_MSR | 7350Sstevel@tonic-gate CPUID_INTC_EDX_CX8 | 7360Sstevel@tonic-gate CPUID_INTC_EDX_PGE | 7370Sstevel@tonic-gate CPUID_INTC_EDX_CMOV | 7380Sstevel@tonic-gate CPUID_INTC_EDX_MMX; 7390Sstevel@tonic-gate break; 7400Sstevel@tonic-gate default: 7410Sstevel@tonic-gate break; 7420Sstevel@tonic-gate } 7430Sstevel@tonic-gate break; 7440Sstevel@tonic-gate } 7450Sstevel@tonic-gate 7465084Sjohnlev #if defined(__xpv) 7475084Sjohnlev /* 7485084Sjohnlev * Do not support MONITOR/MWAIT under a hypervisor 7495084Sjohnlev */ 7505084Sjohnlev mask_ecx &= ~CPUID_INTC_ECX_MON; 7515084Sjohnlev #endif /* __xpv */ 7525084Sjohnlev 7530Sstevel@tonic-gate /* 7540Sstevel@tonic-gate * Now we've figured out the masks that determine 7550Sstevel@tonic-gate * which bits we choose to believe, apply the masks 7560Sstevel@tonic-gate * to the feature words, then map the kernel's view 7570Sstevel@tonic-gate * of these feature words into its feature word. 7580Sstevel@tonic-gate */ 7590Sstevel@tonic-gate cp->cp_edx &= mask_edx; 7600Sstevel@tonic-gate cp->cp_ecx &= mask_ecx; 7610Sstevel@tonic-gate 7620Sstevel@tonic-gate /* 7633446Smrj * apply any platform restrictions (we don't call this 7643446Smrj * immediately after __cpuid_insn here, because we need the 7653446Smrj * workarounds applied above first) 7660Sstevel@tonic-gate */ 7673446Smrj platform_cpuid_mangle(cpi->cpi_vendor, 1, cp); 7680Sstevel@tonic-gate 7693446Smrj /* 7703446Smrj * fold in overrides from the "eeprom" mechanism 7713446Smrj */ 7720Sstevel@tonic-gate cp->cp_edx |= cpuid_feature_edx_include; 7730Sstevel@tonic-gate cp->cp_edx &= ~cpuid_feature_edx_exclude; 7740Sstevel@tonic-gate 7750Sstevel@tonic-gate cp->cp_ecx |= cpuid_feature_ecx_include; 7760Sstevel@tonic-gate cp->cp_ecx &= ~cpuid_feature_ecx_exclude; 7770Sstevel@tonic-gate 7780Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_PSE) 7790Sstevel@tonic-gate feature |= X86_LARGEPAGE; 7800Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_TSC) 7810Sstevel@tonic-gate feature |= X86_TSC; 7820Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_MSR) 7830Sstevel@tonic-gate feature |= X86_MSR; 7840Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_MTRR) 7850Sstevel@tonic-gate feature |= X86_MTRR; 7860Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_PGE) 7870Sstevel@tonic-gate feature |= X86_PGE; 7880Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_CMOV) 7890Sstevel@tonic-gate feature |= X86_CMOV; 7900Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_MMX) 7910Sstevel@tonic-gate feature |= X86_MMX; 7920Sstevel@tonic-gate if ((cp->cp_edx & CPUID_INTC_EDX_MCE) != 0 && 7930Sstevel@tonic-gate (cp->cp_edx & CPUID_INTC_EDX_MCA) != 0) 7940Sstevel@tonic-gate feature |= X86_MCA; 7950Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_PAE) 7960Sstevel@tonic-gate feature |= X86_PAE; 7970Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_CX8) 7980Sstevel@tonic-gate feature |= X86_CX8; 7990Sstevel@tonic-gate if (cp->cp_ecx & CPUID_INTC_ECX_CX16) 8000Sstevel@tonic-gate feature |= X86_CX16; 8010Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_PAT) 8020Sstevel@tonic-gate feature |= X86_PAT; 8030Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_SEP) 8040Sstevel@tonic-gate feature |= X86_SEP; 8050Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_FXSR) { 8060Sstevel@tonic-gate /* 8070Sstevel@tonic-gate * In our implementation, fxsave/fxrstor 8080Sstevel@tonic-gate * are prerequisites before we'll even 8090Sstevel@tonic-gate * try and do SSE things. 8100Sstevel@tonic-gate */ 8110Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_SSE) 8120Sstevel@tonic-gate feature |= X86_SSE; 8130Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_SSE2) 8140Sstevel@tonic-gate feature |= X86_SSE2; 8150Sstevel@tonic-gate if (cp->cp_ecx & CPUID_INTC_ECX_SSE3) 8160Sstevel@tonic-gate feature |= X86_SSE3; 8175269Skk208521 if (cpi->cpi_vendor == X86_VENDOR_Intel) { 8185269Skk208521 if (cp->cp_ecx & CPUID_INTC_ECX_SSSE3) 8195269Skk208521 feature |= X86_SSSE3; 8205269Skk208521 if (cp->cp_ecx & CPUID_INTC_ECX_SSE4_1) 8215269Skk208521 feature |= X86_SSE4_1; 8225269Skk208521 if (cp->cp_ecx & CPUID_INTC_ECX_SSE4_2) 8235269Skk208521 feature |= X86_SSE4_2; 8249370SKuriakose.Kuruvilla@Sun.COM if (cp->cp_ecx & CPUID_INTC_ECX_AES) 8259370SKuriakose.Kuruvilla@Sun.COM feature |= X86_AES; 8265269Skk208521 } 8270Sstevel@tonic-gate } 8280Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_DE) 8293446Smrj feature |= X86_DE; 8307716SBill.Holler@Sun.COM #if !defined(__xpv) 8314481Sbholler if (cp->cp_ecx & CPUID_INTC_ECX_MON) { 8327716SBill.Holler@Sun.COM 8337716SBill.Holler@Sun.COM /* 8347716SBill.Holler@Sun.COM * We require the CLFLUSH instruction for erratum workaround 8357716SBill.Holler@Sun.COM * to use MONITOR/MWAIT. 8367716SBill.Holler@Sun.COM */ 8377716SBill.Holler@Sun.COM if (cp->cp_edx & CPUID_INTC_EDX_CLFSH) { 8387716SBill.Holler@Sun.COM cpi->cpi_mwait.support |= MWAIT_SUPPORT; 8397716SBill.Holler@Sun.COM feature |= X86_MWAIT; 8407716SBill.Holler@Sun.COM } else { 8417716SBill.Holler@Sun.COM extern int idle_cpu_assert_cflush_monitor; 8427716SBill.Holler@Sun.COM 8437716SBill.Holler@Sun.COM /* 8447716SBill.Holler@Sun.COM * All processors we are aware of which have 8457716SBill.Holler@Sun.COM * MONITOR/MWAIT also have CLFLUSH. 8467716SBill.Holler@Sun.COM */ 8477716SBill.Holler@Sun.COM if (idle_cpu_assert_cflush_monitor) { 8487716SBill.Holler@Sun.COM ASSERT((cp->cp_ecx & CPUID_INTC_ECX_MON) && 8497716SBill.Holler@Sun.COM (cp->cp_edx & CPUID_INTC_EDX_CLFSH)); 8507716SBill.Holler@Sun.COM } 8517716SBill.Holler@Sun.COM } 8524481Sbholler } 8537716SBill.Holler@Sun.COM #endif /* __xpv */ 8540Sstevel@tonic-gate 8557589SVikram.Hegde@Sun.COM /* 8567589SVikram.Hegde@Sun.COM * Only need it first time, rest of the cpus would follow suite. 8577589SVikram.Hegde@Sun.COM * we only capture this for the bootcpu. 8587589SVikram.Hegde@Sun.COM */ 8597589SVikram.Hegde@Sun.COM if (cp->cp_edx & CPUID_INTC_EDX_CLFSH) { 8607589SVikram.Hegde@Sun.COM feature |= X86_CLFSH; 8617589SVikram.Hegde@Sun.COM x86_clflush_size = (BITX(cp->cp_ebx, 15, 8) * 8); 8627589SVikram.Hegde@Sun.COM } 8637589SVikram.Hegde@Sun.COM 8640Sstevel@tonic-gate if (feature & X86_PAE) 8650Sstevel@tonic-gate cpi->cpi_pabits = 36; 8660Sstevel@tonic-gate 8670Sstevel@tonic-gate /* 8680Sstevel@tonic-gate * Hyperthreading configuration is slightly tricky on Intel 8690Sstevel@tonic-gate * and pure clones, and even trickier on AMD. 8700Sstevel@tonic-gate * 8710Sstevel@tonic-gate * (AMD chose to set the HTT bit on their CMP processors, 8720Sstevel@tonic-gate * even though they're not actually hyperthreaded. Thus it 8730Sstevel@tonic-gate * takes a bit more work to figure out what's really going 8743446Smrj * on ... see the handling of the CMP_LGCY bit below) 8750Sstevel@tonic-gate */ 8760Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_HTT) { 8770Sstevel@tonic-gate cpi->cpi_ncpu_per_chip = CPI_CPU_COUNT(cpi); 8780Sstevel@tonic-gate if (cpi->cpi_ncpu_per_chip > 1) 8790Sstevel@tonic-gate feature |= X86_HTT; 8801228Sandrei } else { 8811228Sandrei cpi->cpi_ncpu_per_chip = 1; 8820Sstevel@tonic-gate } 8830Sstevel@tonic-gate 8840Sstevel@tonic-gate /* 8850Sstevel@tonic-gate * Work on the "extended" feature information, doing 8860Sstevel@tonic-gate * some basic initialization for cpuid_pass2() 8870Sstevel@tonic-gate */ 8880Sstevel@tonic-gate xcpuid = 0; 8890Sstevel@tonic-gate switch (cpi->cpi_vendor) { 8900Sstevel@tonic-gate case X86_VENDOR_Intel: 8911975Sdmick if (IS_NEW_F6(cpi) || cpi->cpi_family >= 0xf) 8920Sstevel@tonic-gate xcpuid++; 8930Sstevel@tonic-gate break; 8940Sstevel@tonic-gate case X86_VENDOR_AMD: 8950Sstevel@tonic-gate if (cpi->cpi_family > 5 || 8960Sstevel@tonic-gate (cpi->cpi_family == 5 && cpi->cpi_model >= 1)) 8970Sstevel@tonic-gate xcpuid++; 8980Sstevel@tonic-gate break; 8990Sstevel@tonic-gate case X86_VENDOR_Cyrix: 9000Sstevel@tonic-gate /* 9010Sstevel@tonic-gate * Only these Cyrix CPUs are -known- to support 9020Sstevel@tonic-gate * extended cpuid operations. 9030Sstevel@tonic-gate */ 9040Sstevel@tonic-gate if (x86_type == X86_TYPE_VIA_CYRIX_III || 9050Sstevel@tonic-gate x86_type == X86_TYPE_CYRIX_GXm) 9060Sstevel@tonic-gate xcpuid++; 9070Sstevel@tonic-gate break; 9080Sstevel@tonic-gate case X86_VENDOR_Centaur: 9090Sstevel@tonic-gate case X86_VENDOR_TM: 9100Sstevel@tonic-gate default: 9110Sstevel@tonic-gate xcpuid++; 9120Sstevel@tonic-gate break; 9130Sstevel@tonic-gate } 9140Sstevel@tonic-gate 9150Sstevel@tonic-gate if (xcpuid) { 9160Sstevel@tonic-gate cp = &cpi->cpi_extd[0]; 9171228Sandrei cp->cp_eax = 0x80000000; 9181228Sandrei cpi->cpi_xmaxeax = __cpuid_insn(cp); 9190Sstevel@tonic-gate } 9200Sstevel@tonic-gate 9210Sstevel@tonic-gate if (cpi->cpi_xmaxeax & 0x80000000) { 9220Sstevel@tonic-gate 9230Sstevel@tonic-gate if (cpi->cpi_xmaxeax > CPI_XMAXEAX_MAX) 9240Sstevel@tonic-gate cpi->cpi_xmaxeax = CPI_XMAXEAX_MAX; 9250Sstevel@tonic-gate 9260Sstevel@tonic-gate switch (cpi->cpi_vendor) { 9270Sstevel@tonic-gate case X86_VENDOR_Intel: 9280Sstevel@tonic-gate case X86_VENDOR_AMD: 9290Sstevel@tonic-gate if (cpi->cpi_xmaxeax < 0x80000001) 9300Sstevel@tonic-gate break; 9310Sstevel@tonic-gate cp = &cpi->cpi_extd[1]; 9321228Sandrei cp->cp_eax = 0x80000001; 9331228Sandrei (void) __cpuid_insn(cp); 9343446Smrj 9350Sstevel@tonic-gate if (cpi->cpi_vendor == X86_VENDOR_AMD && 9360Sstevel@tonic-gate cpi->cpi_family == 5 && 9370Sstevel@tonic-gate cpi->cpi_model == 6 && 9380Sstevel@tonic-gate cpi->cpi_step == 6) { 9390Sstevel@tonic-gate /* 9400Sstevel@tonic-gate * K6 model 6 uses bit 10 to indicate SYSC 9410Sstevel@tonic-gate * Later models use bit 11. Fix it here. 9420Sstevel@tonic-gate */ 9430Sstevel@tonic-gate if (cp->cp_edx & 0x400) { 9440Sstevel@tonic-gate cp->cp_edx &= ~0x400; 9450Sstevel@tonic-gate cp->cp_edx |= CPUID_AMD_EDX_SYSC; 9460Sstevel@tonic-gate } 9470Sstevel@tonic-gate } 9480Sstevel@tonic-gate 9493446Smrj platform_cpuid_mangle(cpi->cpi_vendor, 0x80000001, cp); 9503446Smrj 9510Sstevel@tonic-gate /* 9520Sstevel@tonic-gate * Compute the additions to the kernel's feature word. 9530Sstevel@tonic-gate */ 9540Sstevel@tonic-gate if (cp->cp_edx & CPUID_AMD_EDX_NX) 9550Sstevel@tonic-gate feature |= X86_NX; 9560Sstevel@tonic-gate 9577656SSherry.Moore@Sun.COM /* 9587656SSherry.Moore@Sun.COM * Regardless whether or not we boot 64-bit, 9597656SSherry.Moore@Sun.COM * we should have a way to identify whether 9607656SSherry.Moore@Sun.COM * the CPU is capable of running 64-bit. 9617656SSherry.Moore@Sun.COM */ 9627656SSherry.Moore@Sun.COM if (cp->cp_edx & CPUID_AMD_EDX_LM) 9637656SSherry.Moore@Sun.COM feature |= X86_64; 9647656SSherry.Moore@Sun.COM 9655349Skchow #if defined(__amd64) 9665349Skchow /* 1 GB large page - enable only for 64 bit kernel */ 9675349Skchow if (cp->cp_edx & CPUID_AMD_EDX_1GPG) 9685349Skchow feature |= X86_1GPG; 9695349Skchow #endif 9705349Skchow 9714628Skk208521 if ((cpi->cpi_vendor == X86_VENDOR_AMD) && 9724628Skk208521 (cpi->cpi_std[1].cp_edx & CPUID_INTC_EDX_FXSR) && 9734628Skk208521 (cp->cp_ecx & CPUID_AMD_ECX_SSE4A)) 9744628Skk208521 feature |= X86_SSE4A; 9754628Skk208521 9760Sstevel@tonic-gate /* 9773446Smrj * If both the HTT and CMP_LGCY bits are set, 9781228Sandrei * then we're not actually HyperThreaded. Read 9791228Sandrei * "AMD CPUID Specification" for more details. 9800Sstevel@tonic-gate */ 9810Sstevel@tonic-gate if (cpi->cpi_vendor == X86_VENDOR_AMD && 9821228Sandrei (feature & X86_HTT) && 9833446Smrj (cp->cp_ecx & CPUID_AMD_ECX_CMP_LGCY)) { 9840Sstevel@tonic-gate feature &= ~X86_HTT; 9851228Sandrei feature |= X86_CMP; 9861228Sandrei } 9873446Smrj #if defined(__amd64) 9880Sstevel@tonic-gate /* 9890Sstevel@tonic-gate * It's really tricky to support syscall/sysret in 9900Sstevel@tonic-gate * the i386 kernel; we rely on sysenter/sysexit 9910Sstevel@tonic-gate * instead. In the amd64 kernel, things are -way- 9920Sstevel@tonic-gate * better. 9930Sstevel@tonic-gate */ 9940Sstevel@tonic-gate if (cp->cp_edx & CPUID_AMD_EDX_SYSC) 9950Sstevel@tonic-gate feature |= X86_ASYSC; 9960Sstevel@tonic-gate 9970Sstevel@tonic-gate /* 9980Sstevel@tonic-gate * While we're thinking about system calls, note 9990Sstevel@tonic-gate * that AMD processors don't support sysenter 10000Sstevel@tonic-gate * in long mode at all, so don't try to program them. 10010Sstevel@tonic-gate */ 10020Sstevel@tonic-gate if (x86_vendor == X86_VENDOR_AMD) 10030Sstevel@tonic-gate feature &= ~X86_SEP; 10040Sstevel@tonic-gate #endif 10056657Ssudheer if (cp->cp_edx & CPUID_AMD_EDX_TSCP) 10063446Smrj feature |= X86_TSCP; 10070Sstevel@tonic-gate break; 10080Sstevel@tonic-gate default: 10090Sstevel@tonic-gate break; 10100Sstevel@tonic-gate } 10110Sstevel@tonic-gate 10121228Sandrei /* 10131228Sandrei * Get CPUID data about processor cores and hyperthreads. 10141228Sandrei */ 10150Sstevel@tonic-gate switch (cpi->cpi_vendor) { 10160Sstevel@tonic-gate case X86_VENDOR_Intel: 10171228Sandrei if (cpi->cpi_maxeax >= 4) { 10181228Sandrei cp = &cpi->cpi_std[4]; 10191228Sandrei cp->cp_eax = 4; 10201228Sandrei cp->cp_ecx = 0; 10211228Sandrei (void) __cpuid_insn(cp); 10223446Smrj platform_cpuid_mangle(cpi->cpi_vendor, 4, cp); 10231228Sandrei } 10241228Sandrei /*FALLTHROUGH*/ 10250Sstevel@tonic-gate case X86_VENDOR_AMD: 10260Sstevel@tonic-gate if (cpi->cpi_xmaxeax < 0x80000008) 10270Sstevel@tonic-gate break; 10280Sstevel@tonic-gate cp = &cpi->cpi_extd[8]; 10291228Sandrei cp->cp_eax = 0x80000008; 10301228Sandrei (void) __cpuid_insn(cp); 10313446Smrj platform_cpuid_mangle(cpi->cpi_vendor, 0x80000008, cp); 10323446Smrj 10330Sstevel@tonic-gate /* 10340Sstevel@tonic-gate * Virtual and physical address limits from 10350Sstevel@tonic-gate * cpuid override previously guessed values. 10360Sstevel@tonic-gate */ 10370Sstevel@tonic-gate cpi->cpi_pabits = BITX(cp->cp_eax, 7, 0); 10380Sstevel@tonic-gate cpi->cpi_vabits = BITX(cp->cp_eax, 15, 8); 10390Sstevel@tonic-gate break; 10400Sstevel@tonic-gate default: 10410Sstevel@tonic-gate break; 10420Sstevel@tonic-gate } 10431228Sandrei 10444606Sesaxe /* 10454606Sesaxe * Derive the number of cores per chip 10464606Sesaxe */ 10471228Sandrei switch (cpi->cpi_vendor) { 10481228Sandrei case X86_VENDOR_Intel: 10491228Sandrei if (cpi->cpi_maxeax < 4) { 10501228Sandrei cpi->cpi_ncore_per_chip = 1; 10511228Sandrei break; 10521228Sandrei } else { 10531228Sandrei cpi->cpi_ncore_per_chip = 10541228Sandrei BITX((cpi)->cpi_std[4].cp_eax, 31, 26) + 1; 10551228Sandrei } 10561228Sandrei break; 10571228Sandrei case X86_VENDOR_AMD: 10581228Sandrei if (cpi->cpi_xmaxeax < 0x80000008) { 10591228Sandrei cpi->cpi_ncore_per_chip = 1; 10601228Sandrei break; 10611228Sandrei } else { 10625870Sgavinm /* 10635870Sgavinm * On family 0xf cpuid fn 2 ECX[7:0] "NC" is 10645870Sgavinm * 1 less than the number of physical cores on 10655870Sgavinm * the chip. In family 0x10 this value can 10665870Sgavinm * be affected by "downcoring" - it reflects 10675870Sgavinm * 1 less than the number of cores actually 10685870Sgavinm * enabled on this node. 10695870Sgavinm */ 10701228Sandrei cpi->cpi_ncore_per_chip = 10711228Sandrei BITX((cpi)->cpi_extd[8].cp_ecx, 7, 0) + 1; 10721228Sandrei } 10731228Sandrei break; 10741228Sandrei default: 10751228Sandrei cpi->cpi_ncore_per_chip = 1; 10761228Sandrei break; 10771228Sandrei } 10788906SEric.Saxe@Sun.COM 10798906SEric.Saxe@Sun.COM /* 10808906SEric.Saxe@Sun.COM * Get CPUID data about TSC Invariance in Deep C-State. 10818906SEric.Saxe@Sun.COM */ 10828906SEric.Saxe@Sun.COM switch (cpi->cpi_vendor) { 10838906SEric.Saxe@Sun.COM case X86_VENDOR_Intel: 10848906SEric.Saxe@Sun.COM if (cpi->cpi_maxeax >= 7) { 10858906SEric.Saxe@Sun.COM cp = &cpi->cpi_extd[7]; 10868906SEric.Saxe@Sun.COM cp->cp_eax = 0x80000007; 10878906SEric.Saxe@Sun.COM cp->cp_ecx = 0; 10888906SEric.Saxe@Sun.COM (void) __cpuid_insn(cp); 10898906SEric.Saxe@Sun.COM } 10908906SEric.Saxe@Sun.COM break; 10918906SEric.Saxe@Sun.COM default: 10928906SEric.Saxe@Sun.COM break; 10938906SEric.Saxe@Sun.COM } 10945284Sgavinm } else { 10955284Sgavinm cpi->cpi_ncore_per_chip = 1; 10960Sstevel@tonic-gate } 10970Sstevel@tonic-gate 10981228Sandrei /* 10991228Sandrei * If more than one core, then this processor is CMP. 11001228Sandrei */ 11011228Sandrei if (cpi->cpi_ncore_per_chip > 1) 11021228Sandrei feature |= X86_CMP; 11033446Smrj 11041228Sandrei /* 11051228Sandrei * If the number of cores is the same as the number 11061228Sandrei * of CPUs, then we cannot have HyperThreading. 11071228Sandrei */ 11081228Sandrei if (cpi->cpi_ncpu_per_chip == cpi->cpi_ncore_per_chip) 11091228Sandrei feature &= ~X86_HTT; 11101228Sandrei 11110Sstevel@tonic-gate if ((feature & (X86_HTT | X86_CMP)) == 0) { 11121228Sandrei /* 11131228Sandrei * Single-core single-threaded processors. 11141228Sandrei */ 11150Sstevel@tonic-gate cpi->cpi_chipid = -1; 11160Sstevel@tonic-gate cpi->cpi_clogid = 0; 11171228Sandrei cpi->cpi_coreid = cpu->cpu_id; 11185870Sgavinm cpi->cpi_pkgcoreid = 0; 11190Sstevel@tonic-gate } else if (cpi->cpi_ncpu_per_chip > 1) { 11201228Sandrei uint_t i; 11211228Sandrei uint_t chipid_shift = 0; 11221228Sandrei uint_t coreid_shift = 0; 11231228Sandrei uint_t apic_id = CPI_APIC_ID(cpi); 11241228Sandrei 11251228Sandrei for (i = 1; i < cpi->cpi_ncpu_per_chip; i <<= 1) 11261228Sandrei chipid_shift++; 11271228Sandrei cpi->cpi_chipid = apic_id >> chipid_shift; 11281228Sandrei cpi->cpi_clogid = apic_id & ((1 << chipid_shift) - 1); 11290Sstevel@tonic-gate 11301228Sandrei if (cpi->cpi_vendor == X86_VENDOR_Intel) { 11311228Sandrei if (feature & X86_CMP) { 11321228Sandrei /* 11331228Sandrei * Multi-core (and possibly multi-threaded) 11341228Sandrei * processors. 11351228Sandrei */ 11361228Sandrei uint_t ncpu_per_core; 11371228Sandrei if (cpi->cpi_ncore_per_chip == 1) 11381228Sandrei ncpu_per_core = cpi->cpi_ncpu_per_chip; 11391228Sandrei else if (cpi->cpi_ncore_per_chip > 1) 11401228Sandrei ncpu_per_core = cpi->cpi_ncpu_per_chip / 11411228Sandrei cpi->cpi_ncore_per_chip; 11421228Sandrei /* 11431228Sandrei * 8bit APIC IDs on dual core Pentiums 11441228Sandrei * look like this: 11451228Sandrei * 11461228Sandrei * +-----------------------+------+------+ 11471228Sandrei * | Physical Package ID | MC | HT | 11481228Sandrei * +-----------------------+------+------+ 11491228Sandrei * <------- chipid --------> 11501228Sandrei * <------- coreid ---------------> 11511228Sandrei * <--- clogid --> 11525870Sgavinm * <------> 11535870Sgavinm * pkgcoreid 11541228Sandrei * 11551228Sandrei * Where the number of bits necessary to 11561228Sandrei * represent MC and HT fields together equals 11571228Sandrei * to the minimum number of bits necessary to 11581228Sandrei * store the value of cpi->cpi_ncpu_per_chip. 11591228Sandrei * Of those bits, the MC part uses the number 11601228Sandrei * of bits necessary to store the value of 11611228Sandrei * cpi->cpi_ncore_per_chip. 11621228Sandrei */ 11631228Sandrei for (i = 1; i < ncpu_per_core; i <<= 1) 11641228Sandrei coreid_shift++; 11651727Sandrei cpi->cpi_coreid = apic_id >> coreid_shift; 11665870Sgavinm cpi->cpi_pkgcoreid = cpi->cpi_clogid >> 11675870Sgavinm coreid_shift; 11681228Sandrei } else if (feature & X86_HTT) { 11691228Sandrei /* 11701228Sandrei * Single-core multi-threaded processors. 11711228Sandrei */ 11721228Sandrei cpi->cpi_coreid = cpi->cpi_chipid; 11735870Sgavinm cpi->cpi_pkgcoreid = 0; 11741228Sandrei } 11751228Sandrei } else if (cpi->cpi_vendor == X86_VENDOR_AMD) { 11761228Sandrei /* 11775870Sgavinm * AMD CMP chips currently have a single thread per 11785870Sgavinm * core, with 2 cores on family 0xf and 2, 3 or 4 11795870Sgavinm * cores on family 0x10. 11805870Sgavinm * 11815870Sgavinm * Since no two cpus share a core we must assign a 11825870Sgavinm * distinct coreid per cpu, and we do this by using 11835870Sgavinm * the cpu_id. This scheme does not, however, 11845870Sgavinm * guarantee that sibling cores of a chip will have 11855870Sgavinm * sequential coreids starting at a multiple of the 11865870Sgavinm * number of cores per chip - that is usually the 11875870Sgavinm * case, but if the ACPI MADT table is presented 11885870Sgavinm * in a different order then we need to perform a 11895870Sgavinm * few more gymnastics for the pkgcoreid. 11905870Sgavinm * 11915870Sgavinm * In family 0xf CMPs there are 2 cores on all nodes 11925870Sgavinm * present - no mixing of single and dual core parts. 11935870Sgavinm * 11945870Sgavinm * In family 0x10 CMPs cpuid fn 2 ECX[15:12] 11955870Sgavinm * "ApicIdCoreIdSize[3:0]" tells us how 11965870Sgavinm * many least-significant bits in the ApicId 11975870Sgavinm * are used to represent the core number 11985870Sgavinm * within the node. Cores are always 11995870Sgavinm * numbered sequentially from 0 regardless 12005870Sgavinm * of how many or which are disabled, and 12015870Sgavinm * there seems to be no way to discover the 12025870Sgavinm * real core id when some are disabled. 12031228Sandrei */ 12041228Sandrei cpi->cpi_coreid = cpu->cpu_id; 12055870Sgavinm 12065870Sgavinm if (cpi->cpi_family == 0x10 && 12075870Sgavinm cpi->cpi_xmaxeax >= 0x80000008) { 12085870Sgavinm int coreidsz = 12095870Sgavinm BITX((cpi)->cpi_extd[8].cp_ecx, 15, 12); 12105870Sgavinm 12115870Sgavinm cpi->cpi_pkgcoreid = 12125870Sgavinm apic_id & ((1 << coreidsz) - 1); 12135870Sgavinm } else { 12145870Sgavinm cpi->cpi_pkgcoreid = cpi->cpi_clogid; 12155870Sgavinm } 12161228Sandrei } else { 12171228Sandrei /* 12181228Sandrei * All other processors are currently 12191228Sandrei * assumed to have single cores. 12201228Sandrei */ 12211228Sandrei cpi->cpi_coreid = cpi->cpi_chipid; 12225870Sgavinm cpi->cpi_pkgcoreid = 0; 12231228Sandrei } 12240Sstevel@tonic-gate } 12250Sstevel@tonic-gate 12267282Smishra cpi->cpi_apicid = CPI_APIC_ID(cpi); 12277282Smishra 12282869Sgavinm /* 12292869Sgavinm * Synthesize chip "revision" and socket type 12302869Sgavinm */ 12317532SSean.Ye@Sun.COM cpi->cpi_chiprev = _cpuid_chiprev(cpi->cpi_vendor, cpi->cpi_family, 12327532SSean.Ye@Sun.COM cpi->cpi_model, cpi->cpi_step); 12337532SSean.Ye@Sun.COM cpi->cpi_chiprevstr = _cpuid_chiprevstr(cpi->cpi_vendor, 12347532SSean.Ye@Sun.COM cpi->cpi_family, cpi->cpi_model, cpi->cpi_step); 12357532SSean.Ye@Sun.COM cpi->cpi_socket = _cpuid_skt(cpi->cpi_vendor, cpi->cpi_family, 12367532SSean.Ye@Sun.COM cpi->cpi_model, cpi->cpi_step); 12372869Sgavinm 12380Sstevel@tonic-gate pass1_done: 12390Sstevel@tonic-gate cpi->cpi_pass = 1; 12400Sstevel@tonic-gate return (feature); 12410Sstevel@tonic-gate } 12420Sstevel@tonic-gate 12430Sstevel@tonic-gate /* 12440Sstevel@tonic-gate * Make copies of the cpuid table entries we depend on, in 12450Sstevel@tonic-gate * part for ease of parsing now, in part so that we have only 12460Sstevel@tonic-gate * one place to correct any of it, in part for ease of 12470Sstevel@tonic-gate * later export to userland, and in part so we can look at 12480Sstevel@tonic-gate * this stuff in a crash dump. 12490Sstevel@tonic-gate */ 12500Sstevel@tonic-gate 12510Sstevel@tonic-gate /*ARGSUSED*/ 12520Sstevel@tonic-gate void 12530Sstevel@tonic-gate cpuid_pass2(cpu_t *cpu) 12540Sstevel@tonic-gate { 12550Sstevel@tonic-gate uint_t n, nmax; 12560Sstevel@tonic-gate int i; 12571228Sandrei struct cpuid_regs *cp; 12580Sstevel@tonic-gate uint8_t *dp; 12590Sstevel@tonic-gate uint32_t *iptr; 12600Sstevel@tonic-gate struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 12610Sstevel@tonic-gate 12620Sstevel@tonic-gate ASSERT(cpi->cpi_pass == 1); 12630Sstevel@tonic-gate 12640Sstevel@tonic-gate if (cpi->cpi_maxeax < 1) 12650Sstevel@tonic-gate goto pass2_done; 12660Sstevel@tonic-gate 12670Sstevel@tonic-gate if ((nmax = cpi->cpi_maxeax + 1) > NMAX_CPI_STD) 12680Sstevel@tonic-gate nmax = NMAX_CPI_STD; 12690Sstevel@tonic-gate /* 12700Sstevel@tonic-gate * (We already handled n == 0 and n == 1 in pass 1) 12710Sstevel@tonic-gate */ 12720Sstevel@tonic-gate for (n = 2, cp = &cpi->cpi_std[2]; n < nmax; n++, cp++) { 12731228Sandrei cp->cp_eax = n; 12744606Sesaxe 12754606Sesaxe /* 12764606Sesaxe * CPUID function 4 expects %ecx to be initialized 12774606Sesaxe * with an index which indicates which cache to return 12784606Sesaxe * information about. The OS is expected to call function 4 12794606Sesaxe * with %ecx set to 0, 1, 2, ... until it returns with 12804606Sesaxe * EAX[4:0] set to 0, which indicates there are no more 12814606Sesaxe * caches. 12824606Sesaxe * 12834606Sesaxe * Here, populate cpi_std[4] with the information returned by 12844606Sesaxe * function 4 when %ecx == 0, and do the rest in cpuid_pass3() 12854606Sesaxe * when dynamic memory allocation becomes available. 12864606Sesaxe * 12874606Sesaxe * Note: we need to explicitly initialize %ecx here, since 12884606Sesaxe * function 4 may have been previously invoked. 12894606Sesaxe */ 12904606Sesaxe if (n == 4) 12914606Sesaxe cp->cp_ecx = 0; 12924606Sesaxe 12931228Sandrei (void) __cpuid_insn(cp); 12943446Smrj platform_cpuid_mangle(cpi->cpi_vendor, n, cp); 12950Sstevel@tonic-gate switch (n) { 12960Sstevel@tonic-gate case 2: 12970Sstevel@tonic-gate /* 12980Sstevel@tonic-gate * "the lower 8 bits of the %eax register 12990Sstevel@tonic-gate * contain a value that identifies the number 13000Sstevel@tonic-gate * of times the cpuid [instruction] has to be 13010Sstevel@tonic-gate * executed to obtain a complete image of the 13020Sstevel@tonic-gate * processor's caching systems." 13030Sstevel@tonic-gate * 13040Sstevel@tonic-gate * How *do* they make this stuff up? 13050Sstevel@tonic-gate */ 13060Sstevel@tonic-gate cpi->cpi_ncache = sizeof (*cp) * 13070Sstevel@tonic-gate BITX(cp->cp_eax, 7, 0); 13080Sstevel@tonic-gate if (cpi->cpi_ncache == 0) 13090Sstevel@tonic-gate break; 13100Sstevel@tonic-gate cpi->cpi_ncache--; /* skip count byte */ 13110Sstevel@tonic-gate 13120Sstevel@tonic-gate /* 13130Sstevel@tonic-gate * Well, for now, rather than attempt to implement 13140Sstevel@tonic-gate * this slightly dubious algorithm, we just look 13150Sstevel@tonic-gate * at the first 15 .. 13160Sstevel@tonic-gate */ 13170Sstevel@tonic-gate if (cpi->cpi_ncache > (sizeof (*cp) - 1)) 13180Sstevel@tonic-gate cpi->cpi_ncache = sizeof (*cp) - 1; 13190Sstevel@tonic-gate 13200Sstevel@tonic-gate dp = cpi->cpi_cacheinfo; 13210Sstevel@tonic-gate if (BITX(cp->cp_eax, 31, 31) == 0) { 13220Sstevel@tonic-gate uint8_t *p = (void *)&cp->cp_eax; 13236317Skk208521 for (i = 1; i < 4; i++) 13240Sstevel@tonic-gate if (p[i] != 0) 13250Sstevel@tonic-gate *dp++ = p[i]; 13260Sstevel@tonic-gate } 13270Sstevel@tonic-gate if (BITX(cp->cp_ebx, 31, 31) == 0) { 13280Sstevel@tonic-gate uint8_t *p = (void *)&cp->cp_ebx; 13290Sstevel@tonic-gate for (i = 0; i < 4; i++) 13300Sstevel@tonic-gate if (p[i] != 0) 13310Sstevel@tonic-gate *dp++ = p[i]; 13320Sstevel@tonic-gate } 13330Sstevel@tonic-gate if (BITX(cp->cp_ecx, 31, 31) == 0) { 13340Sstevel@tonic-gate uint8_t *p = (void *)&cp->cp_ecx; 13350Sstevel@tonic-gate for (i = 0; i < 4; i++) 13360Sstevel@tonic-gate if (p[i] != 0) 13370Sstevel@tonic-gate *dp++ = p[i]; 13380Sstevel@tonic-gate } 13390Sstevel@tonic-gate if (BITX(cp->cp_edx, 31, 31) == 0) { 13400Sstevel@tonic-gate uint8_t *p = (void *)&cp->cp_edx; 13410Sstevel@tonic-gate for (i = 0; i < 4; i++) 13420Sstevel@tonic-gate if (p[i] != 0) 13430Sstevel@tonic-gate *dp++ = p[i]; 13440Sstevel@tonic-gate } 13450Sstevel@tonic-gate break; 13464481Sbholler 13470Sstevel@tonic-gate case 3: /* Processor serial number, if PSN supported */ 13484481Sbholler break; 13494481Sbholler 13500Sstevel@tonic-gate case 4: /* Deterministic cache parameters */ 13514481Sbholler break; 13524481Sbholler 13530Sstevel@tonic-gate case 5: /* Monitor/Mwait parameters */ 13545045Sbholler { 13555045Sbholler size_t mwait_size; 13564481Sbholler 13574481Sbholler /* 13584481Sbholler * check cpi_mwait.support which was set in cpuid_pass1 13594481Sbholler */ 13604481Sbholler if (!(cpi->cpi_mwait.support & MWAIT_SUPPORT)) 13614481Sbholler break; 13624481Sbholler 13635045Sbholler /* 13645045Sbholler * Protect ourself from insane mwait line size. 13655045Sbholler * Workaround for incomplete hardware emulator(s). 13665045Sbholler */ 13675045Sbholler mwait_size = (size_t)MWAIT_SIZE_MAX(cpi); 13685045Sbholler if (mwait_size < sizeof (uint32_t) || 13695045Sbholler !ISP2(mwait_size)) { 13705045Sbholler #if DEBUG 13715045Sbholler cmn_err(CE_NOTE, "Cannot handle cpu %d mwait " 13727798SSaurabh.Mishra@Sun.COM "size %ld", cpu->cpu_id, (long)mwait_size); 13735045Sbholler #endif 13745045Sbholler break; 13755045Sbholler } 13765045Sbholler 13774481Sbholler cpi->cpi_mwait.mon_min = (size_t)MWAIT_SIZE_MIN(cpi); 13785045Sbholler cpi->cpi_mwait.mon_max = mwait_size; 13794481Sbholler if (MWAIT_EXTENSION(cpi)) { 13804481Sbholler cpi->cpi_mwait.support |= MWAIT_EXTENSIONS; 13814481Sbholler if (MWAIT_INT_ENABLE(cpi)) 13824481Sbholler cpi->cpi_mwait.support |= 13834481Sbholler MWAIT_ECX_INT_ENABLE; 13844481Sbholler } 13854481Sbholler break; 13865045Sbholler } 13870Sstevel@tonic-gate default: 13880Sstevel@tonic-gate break; 13890Sstevel@tonic-gate } 13900Sstevel@tonic-gate } 13910Sstevel@tonic-gate 13927282Smishra if (cpi->cpi_maxeax >= 0xB && cpi->cpi_vendor == X86_VENDOR_Intel) { 13937798SSaurabh.Mishra@Sun.COM struct cpuid_regs regs; 13947798SSaurabh.Mishra@Sun.COM 13957798SSaurabh.Mishra@Sun.COM cp = ®s; 13967282Smishra cp->cp_eax = 0xB; 13977798SSaurabh.Mishra@Sun.COM cp->cp_edx = cp->cp_ebx = cp->cp_ecx = 0; 13987282Smishra 13997282Smishra (void) __cpuid_insn(cp); 14007282Smishra 14017282Smishra /* 14027282Smishra * Check CPUID.EAX=0BH, ECX=0H:EBX is non-zero, which 14037282Smishra * indicates that the extended topology enumeration leaf is 14047282Smishra * available. 14057282Smishra */ 14067282Smishra if (cp->cp_ebx) { 14077282Smishra uint32_t x2apic_id; 14087282Smishra uint_t coreid_shift = 0; 14097282Smishra uint_t ncpu_per_core = 1; 14107282Smishra uint_t chipid_shift = 0; 14117282Smishra uint_t ncpu_per_chip = 1; 14127282Smishra uint_t i; 14137282Smishra uint_t level; 14147282Smishra 14157282Smishra for (i = 0; i < CPI_FNB_ECX_MAX; i++) { 14167282Smishra cp->cp_eax = 0xB; 14177282Smishra cp->cp_ecx = i; 14187282Smishra 14197282Smishra (void) __cpuid_insn(cp); 14207282Smishra level = CPI_CPU_LEVEL_TYPE(cp); 14217282Smishra 14227282Smishra if (level == 1) { 14237282Smishra x2apic_id = cp->cp_edx; 14247282Smishra coreid_shift = BITX(cp->cp_eax, 4, 0); 14257282Smishra ncpu_per_core = BITX(cp->cp_ebx, 15, 0); 14267282Smishra } else if (level == 2) { 14277282Smishra x2apic_id = cp->cp_edx; 14287282Smishra chipid_shift = BITX(cp->cp_eax, 4, 0); 14297282Smishra ncpu_per_chip = BITX(cp->cp_ebx, 15, 0); 14307282Smishra } 14317282Smishra } 14327282Smishra 14337282Smishra cpi->cpi_apicid = x2apic_id; 14347282Smishra cpi->cpi_ncpu_per_chip = ncpu_per_chip; 14357282Smishra cpi->cpi_ncore_per_chip = ncpu_per_chip / 14367282Smishra ncpu_per_core; 14377282Smishra cpi->cpi_chipid = x2apic_id >> chipid_shift; 14387282Smishra cpi->cpi_clogid = x2apic_id & ((1 << chipid_shift) - 1); 14397282Smishra cpi->cpi_coreid = x2apic_id >> coreid_shift; 14407282Smishra cpi->cpi_pkgcoreid = cpi->cpi_clogid >> coreid_shift; 14417282Smishra } 14427798SSaurabh.Mishra@Sun.COM 14437798SSaurabh.Mishra@Sun.COM /* Make cp NULL so that we don't stumble on others */ 14447798SSaurabh.Mishra@Sun.COM cp = NULL; 14457282Smishra } 14467282Smishra 14470Sstevel@tonic-gate if ((cpi->cpi_xmaxeax & 0x80000000) == 0) 14480Sstevel@tonic-gate goto pass2_done; 14490Sstevel@tonic-gate 14500Sstevel@tonic-gate if ((nmax = cpi->cpi_xmaxeax - 0x80000000 + 1) > NMAX_CPI_EXTD) 14510Sstevel@tonic-gate nmax = NMAX_CPI_EXTD; 14520Sstevel@tonic-gate /* 14530Sstevel@tonic-gate * Copy the extended properties, fixing them as we go. 14540Sstevel@tonic-gate * (We already handled n == 0 and n == 1 in pass 1) 14550Sstevel@tonic-gate */ 14560Sstevel@tonic-gate iptr = (void *)cpi->cpi_brandstr; 14570Sstevel@tonic-gate for (n = 2, cp = &cpi->cpi_extd[2]; n < nmax; cp++, n++) { 14581228Sandrei cp->cp_eax = 0x80000000 + n; 14591228Sandrei (void) __cpuid_insn(cp); 14603446Smrj platform_cpuid_mangle(cpi->cpi_vendor, 0x80000000 + n, cp); 14610Sstevel@tonic-gate switch (n) { 14620Sstevel@tonic-gate case 2: 14630Sstevel@tonic-gate case 3: 14640Sstevel@tonic-gate case 4: 14650Sstevel@tonic-gate /* 14660Sstevel@tonic-gate * Extract the brand string 14670Sstevel@tonic-gate */ 14680Sstevel@tonic-gate *iptr++ = cp->cp_eax; 14690Sstevel@tonic-gate *iptr++ = cp->cp_ebx; 14700Sstevel@tonic-gate *iptr++ = cp->cp_ecx; 14710Sstevel@tonic-gate *iptr++ = cp->cp_edx; 14720Sstevel@tonic-gate break; 14730Sstevel@tonic-gate case 5: 14740Sstevel@tonic-gate switch (cpi->cpi_vendor) { 14750Sstevel@tonic-gate case X86_VENDOR_AMD: 14760Sstevel@tonic-gate /* 14770Sstevel@tonic-gate * The Athlon and Duron were the first 14780Sstevel@tonic-gate * parts to report the sizes of the 14790Sstevel@tonic-gate * TLB for large pages. Before then, 14800Sstevel@tonic-gate * we don't trust the data. 14810Sstevel@tonic-gate */ 14820Sstevel@tonic-gate if (cpi->cpi_family < 6 || 14830Sstevel@tonic-gate (cpi->cpi_family == 6 && 14840Sstevel@tonic-gate cpi->cpi_model < 1)) 14850Sstevel@tonic-gate cp->cp_eax = 0; 14860Sstevel@tonic-gate break; 14870Sstevel@tonic-gate default: 14880Sstevel@tonic-gate break; 14890Sstevel@tonic-gate } 14900Sstevel@tonic-gate break; 14910Sstevel@tonic-gate case 6: 14920Sstevel@tonic-gate switch (cpi->cpi_vendor) { 14930Sstevel@tonic-gate case X86_VENDOR_AMD: 14940Sstevel@tonic-gate /* 14950Sstevel@tonic-gate * The Athlon and Duron were the first 14960Sstevel@tonic-gate * AMD parts with L2 TLB's. 14970Sstevel@tonic-gate * Before then, don't trust the data. 14980Sstevel@tonic-gate */ 14990Sstevel@tonic-gate if (cpi->cpi_family < 6 || 15000Sstevel@tonic-gate cpi->cpi_family == 6 && 15010Sstevel@tonic-gate cpi->cpi_model < 1) 15020Sstevel@tonic-gate cp->cp_eax = cp->cp_ebx = 0; 15030Sstevel@tonic-gate /* 15040Sstevel@tonic-gate * AMD Duron rev A0 reports L2 15050Sstevel@tonic-gate * cache size incorrectly as 1K 15060Sstevel@tonic-gate * when it is really 64K 15070Sstevel@tonic-gate */ 15080Sstevel@tonic-gate if (cpi->cpi_family == 6 && 15090Sstevel@tonic-gate cpi->cpi_model == 3 && 15100Sstevel@tonic-gate cpi->cpi_step == 0) { 15110Sstevel@tonic-gate cp->cp_ecx &= 0xffff; 15120Sstevel@tonic-gate cp->cp_ecx |= 0x400000; 15130Sstevel@tonic-gate } 15140Sstevel@tonic-gate break; 15150Sstevel@tonic-gate case X86_VENDOR_Cyrix: /* VIA C3 */ 15160Sstevel@tonic-gate /* 15170Sstevel@tonic-gate * VIA C3 processors are a bit messed 15180Sstevel@tonic-gate * up w.r.t. encoding cache sizes in %ecx 15190Sstevel@tonic-gate */ 15200Sstevel@tonic-gate if (cpi->cpi_family != 6) 15210Sstevel@tonic-gate break; 15220Sstevel@tonic-gate /* 15230Sstevel@tonic-gate * model 7 and 8 were incorrectly encoded 15240Sstevel@tonic-gate * 15250Sstevel@tonic-gate * xxx is model 8 really broken? 15260Sstevel@tonic-gate */ 15270Sstevel@tonic-gate if (cpi->cpi_model == 7 || 15280Sstevel@tonic-gate cpi->cpi_model == 8) 15290Sstevel@tonic-gate cp->cp_ecx = 15300Sstevel@tonic-gate BITX(cp->cp_ecx, 31, 24) << 16 | 15310Sstevel@tonic-gate BITX(cp->cp_ecx, 23, 16) << 12 | 15320Sstevel@tonic-gate BITX(cp->cp_ecx, 15, 8) << 8 | 15330Sstevel@tonic-gate BITX(cp->cp_ecx, 7, 0); 15340Sstevel@tonic-gate /* 15350Sstevel@tonic-gate * model 9 stepping 1 has wrong associativity 15360Sstevel@tonic-gate */ 15370Sstevel@tonic-gate if (cpi->cpi_model == 9 && cpi->cpi_step == 1) 15380Sstevel@tonic-gate cp->cp_ecx |= 8 << 12; 15390Sstevel@tonic-gate break; 15400Sstevel@tonic-gate case X86_VENDOR_Intel: 15410Sstevel@tonic-gate /* 15420Sstevel@tonic-gate * Extended L2 Cache features function. 15430Sstevel@tonic-gate * First appeared on Prescott. 15440Sstevel@tonic-gate */ 15450Sstevel@tonic-gate default: 15460Sstevel@tonic-gate break; 15470Sstevel@tonic-gate } 15480Sstevel@tonic-gate break; 15490Sstevel@tonic-gate default: 15500Sstevel@tonic-gate break; 15510Sstevel@tonic-gate } 15520Sstevel@tonic-gate } 15530Sstevel@tonic-gate 15540Sstevel@tonic-gate pass2_done: 15550Sstevel@tonic-gate cpi->cpi_pass = 2; 15560Sstevel@tonic-gate } 15570Sstevel@tonic-gate 15580Sstevel@tonic-gate static const char * 15590Sstevel@tonic-gate intel_cpubrand(const struct cpuid_info *cpi) 15600Sstevel@tonic-gate { 15610Sstevel@tonic-gate int i; 15620Sstevel@tonic-gate 15630Sstevel@tonic-gate if ((x86_feature & X86_CPUID) == 0 || 15640Sstevel@tonic-gate cpi->cpi_maxeax < 1 || cpi->cpi_family < 5) 15650Sstevel@tonic-gate return ("i486"); 15660Sstevel@tonic-gate 15670Sstevel@tonic-gate switch (cpi->cpi_family) { 15680Sstevel@tonic-gate case 5: 15690Sstevel@tonic-gate return ("Intel Pentium(r)"); 15700Sstevel@tonic-gate case 6: 15710Sstevel@tonic-gate switch (cpi->cpi_model) { 15720Sstevel@tonic-gate uint_t celeron, xeon; 15731228Sandrei const struct cpuid_regs *cp; 15740Sstevel@tonic-gate case 0: 15750Sstevel@tonic-gate case 1: 15760Sstevel@tonic-gate case 2: 15770Sstevel@tonic-gate return ("Intel Pentium(r) Pro"); 15780Sstevel@tonic-gate case 3: 15790Sstevel@tonic-gate case 4: 15800Sstevel@tonic-gate return ("Intel Pentium(r) II"); 15810Sstevel@tonic-gate case 6: 15820Sstevel@tonic-gate return ("Intel Celeron(r)"); 15830Sstevel@tonic-gate case 5: 15840Sstevel@tonic-gate case 7: 15850Sstevel@tonic-gate celeron = xeon = 0; 15860Sstevel@tonic-gate cp = &cpi->cpi_std[2]; /* cache info */ 15870Sstevel@tonic-gate 15886317Skk208521 for (i = 1; i < 4; i++) { 15890Sstevel@tonic-gate uint_t tmp; 15900Sstevel@tonic-gate 15910Sstevel@tonic-gate tmp = (cp->cp_eax >> (8 * i)) & 0xff; 15920Sstevel@tonic-gate if (tmp == 0x40) 15930Sstevel@tonic-gate celeron++; 15940Sstevel@tonic-gate if (tmp >= 0x44 && tmp <= 0x45) 15950Sstevel@tonic-gate xeon++; 15960Sstevel@tonic-gate } 15970Sstevel@tonic-gate 15980Sstevel@tonic-gate for (i = 0; i < 2; i++) { 15990Sstevel@tonic-gate uint_t tmp; 16000Sstevel@tonic-gate 16010Sstevel@tonic-gate tmp = (cp->cp_ebx >> (8 * i)) & 0xff; 16020Sstevel@tonic-gate if (tmp == 0x40) 16030Sstevel@tonic-gate celeron++; 16040Sstevel@tonic-gate else if (tmp >= 0x44 && tmp <= 0x45) 16050Sstevel@tonic-gate xeon++; 16060Sstevel@tonic-gate } 16070Sstevel@tonic-gate 16080Sstevel@tonic-gate for (i = 0; i < 4; i++) { 16090Sstevel@tonic-gate uint_t tmp; 16100Sstevel@tonic-gate 16110Sstevel@tonic-gate tmp = (cp->cp_ecx >> (8 * i)) & 0xff; 16120Sstevel@tonic-gate if (tmp == 0x40) 16130Sstevel@tonic-gate celeron++; 16140Sstevel@tonic-gate else if (tmp >= 0x44 && tmp <= 0x45) 16150Sstevel@tonic-gate xeon++; 16160Sstevel@tonic-gate } 16170Sstevel@tonic-gate 16180Sstevel@tonic-gate for (i = 0; i < 4; i++) { 16190Sstevel@tonic-gate uint_t tmp; 16200Sstevel@tonic-gate 16210Sstevel@tonic-gate tmp = (cp->cp_edx >> (8 * i)) & 0xff; 16220Sstevel@tonic-gate if (tmp == 0x40) 16230Sstevel@tonic-gate celeron++; 16240Sstevel@tonic-gate else if (tmp >= 0x44 && tmp <= 0x45) 16250Sstevel@tonic-gate xeon++; 16260Sstevel@tonic-gate } 16270Sstevel@tonic-gate 16280Sstevel@tonic-gate if (celeron) 16290Sstevel@tonic-gate return ("Intel Celeron(r)"); 16300Sstevel@tonic-gate if (xeon) 16310Sstevel@tonic-gate return (cpi->cpi_model == 5 ? 16320Sstevel@tonic-gate "Intel Pentium(r) II Xeon(tm)" : 16330Sstevel@tonic-gate "Intel Pentium(r) III Xeon(tm)"); 16340Sstevel@tonic-gate return (cpi->cpi_model == 5 ? 16350Sstevel@tonic-gate "Intel Pentium(r) II or Pentium(r) II Xeon(tm)" : 16360Sstevel@tonic-gate "Intel Pentium(r) III or Pentium(r) III Xeon(tm)"); 16370Sstevel@tonic-gate default: 16380Sstevel@tonic-gate break; 16390Sstevel@tonic-gate } 16400Sstevel@tonic-gate default: 16410Sstevel@tonic-gate break; 16420Sstevel@tonic-gate } 16430Sstevel@tonic-gate 16441975Sdmick /* BrandID is present if the field is nonzero */ 16451975Sdmick if (cpi->cpi_brandid != 0) { 16460Sstevel@tonic-gate static const struct { 16470Sstevel@tonic-gate uint_t bt_bid; 16480Sstevel@tonic-gate const char *bt_str; 16490Sstevel@tonic-gate } brand_tbl[] = { 16500Sstevel@tonic-gate { 0x1, "Intel(r) Celeron(r)" }, 16510Sstevel@tonic-gate { 0x2, "Intel(r) Pentium(r) III" }, 16520Sstevel@tonic-gate { 0x3, "Intel(r) Pentium(r) III Xeon(tm)" }, 16530Sstevel@tonic-gate { 0x4, "Intel(r) Pentium(r) III" }, 16540Sstevel@tonic-gate { 0x6, "Mobile Intel(r) Pentium(r) III" }, 16550Sstevel@tonic-gate { 0x7, "Mobile Intel(r) Celeron(r)" }, 16560Sstevel@tonic-gate { 0x8, "Intel(r) Pentium(r) 4" }, 16570Sstevel@tonic-gate { 0x9, "Intel(r) Pentium(r) 4" }, 16580Sstevel@tonic-gate { 0xa, "Intel(r) Celeron(r)" }, 16590Sstevel@tonic-gate { 0xb, "Intel(r) Xeon(tm)" }, 16600Sstevel@tonic-gate { 0xc, "Intel(r) Xeon(tm) MP" }, 16610Sstevel@tonic-gate { 0xe, "Mobile Intel(r) Pentium(r) 4" }, 16621975Sdmick { 0xf, "Mobile Intel(r) Celeron(r)" }, 16631975Sdmick { 0x11, "Mobile Genuine Intel(r)" }, 16641975Sdmick { 0x12, "Intel(r) Celeron(r) M" }, 16651975Sdmick { 0x13, "Mobile Intel(r) Celeron(r)" }, 16661975Sdmick { 0x14, "Intel(r) Celeron(r)" }, 16671975Sdmick { 0x15, "Mobile Genuine Intel(r)" }, 16681975Sdmick { 0x16, "Intel(r) Pentium(r) M" }, 16691975Sdmick { 0x17, "Mobile Intel(r) Celeron(r)" } 16700Sstevel@tonic-gate }; 16710Sstevel@tonic-gate uint_t btblmax = sizeof (brand_tbl) / sizeof (brand_tbl[0]); 16720Sstevel@tonic-gate uint_t sgn; 16730Sstevel@tonic-gate 16740Sstevel@tonic-gate sgn = (cpi->cpi_family << 8) | 16750Sstevel@tonic-gate (cpi->cpi_model << 4) | cpi->cpi_step; 16760Sstevel@tonic-gate 16770Sstevel@tonic-gate for (i = 0; i < btblmax; i++) 16780Sstevel@tonic-gate if (brand_tbl[i].bt_bid == cpi->cpi_brandid) 16790Sstevel@tonic-gate break; 16800Sstevel@tonic-gate if (i < btblmax) { 16810Sstevel@tonic-gate if (sgn == 0x6b1 && cpi->cpi_brandid == 3) 16820Sstevel@tonic-gate return ("Intel(r) Celeron(r)"); 16830Sstevel@tonic-gate if (sgn < 0xf13 && cpi->cpi_brandid == 0xb) 16840Sstevel@tonic-gate return ("Intel(r) Xeon(tm) MP"); 16850Sstevel@tonic-gate if (sgn < 0xf13 && cpi->cpi_brandid == 0xe) 16860Sstevel@tonic-gate return ("Intel(r) Xeon(tm)"); 16870Sstevel@tonic-gate return (brand_tbl[i].bt_str); 16880Sstevel@tonic-gate } 16890Sstevel@tonic-gate } 16900Sstevel@tonic-gate 16910Sstevel@tonic-gate return (NULL); 16920Sstevel@tonic-gate } 16930Sstevel@tonic-gate 16940Sstevel@tonic-gate static const char * 16950Sstevel@tonic-gate amd_cpubrand(const struct cpuid_info *cpi) 16960Sstevel@tonic-gate { 16970Sstevel@tonic-gate if ((x86_feature & X86_CPUID) == 0 || 16980Sstevel@tonic-gate cpi->cpi_maxeax < 1 || cpi->cpi_family < 5) 16990Sstevel@tonic-gate return ("i486 compatible"); 17000Sstevel@tonic-gate 17010Sstevel@tonic-gate switch (cpi->cpi_family) { 17020Sstevel@tonic-gate case 5: 17030Sstevel@tonic-gate switch (cpi->cpi_model) { 17040Sstevel@tonic-gate case 0: 17050Sstevel@tonic-gate case 1: 17060Sstevel@tonic-gate case 2: 17070Sstevel@tonic-gate case 3: 17080Sstevel@tonic-gate case 4: 17090Sstevel@tonic-gate case 5: 17100Sstevel@tonic-gate return ("AMD-K5(r)"); 17110Sstevel@tonic-gate case 6: 17120Sstevel@tonic-gate case 7: 17130Sstevel@tonic-gate return ("AMD-K6(r)"); 17140Sstevel@tonic-gate case 8: 17150Sstevel@tonic-gate return ("AMD-K6(r)-2"); 17160Sstevel@tonic-gate case 9: 17170Sstevel@tonic-gate return ("AMD-K6(r)-III"); 17180Sstevel@tonic-gate default: 17190Sstevel@tonic-gate return ("AMD (family 5)"); 17200Sstevel@tonic-gate } 17210Sstevel@tonic-gate case 6: 17220Sstevel@tonic-gate switch (cpi->cpi_model) { 17230Sstevel@tonic-gate case 1: 17240Sstevel@tonic-gate return ("AMD-K7(tm)"); 17250Sstevel@tonic-gate case 0: 17260Sstevel@tonic-gate case 2: 17270Sstevel@tonic-gate case 4: 17280Sstevel@tonic-gate return ("AMD Athlon(tm)"); 17290Sstevel@tonic-gate case 3: 17300Sstevel@tonic-gate case 7: 17310Sstevel@tonic-gate return ("AMD Duron(tm)"); 17320Sstevel@tonic-gate case 6: 17330Sstevel@tonic-gate case 8: 17340Sstevel@tonic-gate case 10: 17350Sstevel@tonic-gate /* 17360Sstevel@tonic-gate * Use the L2 cache size to distinguish 17370Sstevel@tonic-gate */ 17380Sstevel@tonic-gate return ((cpi->cpi_extd[6].cp_ecx >> 16) >= 256 ? 17390Sstevel@tonic-gate "AMD Athlon(tm)" : "AMD Duron(tm)"); 17400Sstevel@tonic-gate default: 17410Sstevel@tonic-gate return ("AMD (family 6)"); 17420Sstevel@tonic-gate } 17430Sstevel@tonic-gate default: 17440Sstevel@tonic-gate break; 17450Sstevel@tonic-gate } 17460Sstevel@tonic-gate 17470Sstevel@tonic-gate if (cpi->cpi_family == 0xf && cpi->cpi_model == 5 && 17480Sstevel@tonic-gate cpi->cpi_brandid != 0) { 17490Sstevel@tonic-gate switch (BITX(cpi->cpi_brandid, 7, 5)) { 17500Sstevel@tonic-gate case 3: 17510Sstevel@tonic-gate return ("AMD Opteron(tm) UP 1xx"); 17520Sstevel@tonic-gate case 4: 17530Sstevel@tonic-gate return ("AMD Opteron(tm) DP 2xx"); 17540Sstevel@tonic-gate case 5: 17550Sstevel@tonic-gate return ("AMD Opteron(tm) MP 8xx"); 17560Sstevel@tonic-gate default: 17570Sstevel@tonic-gate return ("AMD Opteron(tm)"); 17580Sstevel@tonic-gate } 17590Sstevel@tonic-gate } 17600Sstevel@tonic-gate 17610Sstevel@tonic-gate return (NULL); 17620Sstevel@tonic-gate } 17630Sstevel@tonic-gate 17640Sstevel@tonic-gate static const char * 17650Sstevel@tonic-gate cyrix_cpubrand(struct cpuid_info *cpi, uint_t type) 17660Sstevel@tonic-gate { 17670Sstevel@tonic-gate if ((x86_feature & X86_CPUID) == 0 || 17680Sstevel@tonic-gate cpi->cpi_maxeax < 1 || cpi->cpi_family < 5 || 17690Sstevel@tonic-gate type == X86_TYPE_CYRIX_486) 17700Sstevel@tonic-gate return ("i486 compatible"); 17710Sstevel@tonic-gate 17720Sstevel@tonic-gate switch (type) { 17730Sstevel@tonic-gate case X86_TYPE_CYRIX_6x86: 17740Sstevel@tonic-gate return ("Cyrix 6x86"); 17750Sstevel@tonic-gate case X86_TYPE_CYRIX_6x86L: 17760Sstevel@tonic-gate return ("Cyrix 6x86L"); 17770Sstevel@tonic-gate case X86_TYPE_CYRIX_6x86MX: 17780Sstevel@tonic-gate return ("Cyrix 6x86MX"); 17790Sstevel@tonic-gate case X86_TYPE_CYRIX_GXm: 17800Sstevel@tonic-gate return ("Cyrix GXm"); 17810Sstevel@tonic-gate case X86_TYPE_CYRIX_MediaGX: 17820Sstevel@tonic-gate return ("Cyrix MediaGX"); 17830Sstevel@tonic-gate case X86_TYPE_CYRIX_MII: 17840Sstevel@tonic-gate return ("Cyrix M2"); 17850Sstevel@tonic-gate case X86_TYPE_VIA_CYRIX_III: 17860Sstevel@tonic-gate return ("VIA Cyrix M3"); 17870Sstevel@tonic-gate default: 17880Sstevel@tonic-gate /* 17890Sstevel@tonic-gate * Have another wild guess .. 17900Sstevel@tonic-gate */ 17910Sstevel@tonic-gate if (cpi->cpi_family == 4 && cpi->cpi_model == 9) 17920Sstevel@tonic-gate return ("Cyrix 5x86"); 17930Sstevel@tonic-gate else if (cpi->cpi_family == 5) { 17940Sstevel@tonic-gate switch (cpi->cpi_model) { 17950Sstevel@tonic-gate case 2: 17960Sstevel@tonic-gate return ("Cyrix 6x86"); /* Cyrix M1 */ 17970Sstevel@tonic-gate case 4: 17980Sstevel@tonic-gate return ("Cyrix MediaGX"); 17990Sstevel@tonic-gate default: 18000Sstevel@tonic-gate break; 18010Sstevel@tonic-gate } 18020Sstevel@tonic-gate } else if (cpi->cpi_family == 6) { 18030Sstevel@tonic-gate switch (cpi->cpi_model) { 18040Sstevel@tonic-gate case 0: 18050Sstevel@tonic-gate return ("Cyrix 6x86MX"); /* Cyrix M2? */ 18060Sstevel@tonic-gate case 5: 18070Sstevel@tonic-gate case 6: 18080Sstevel@tonic-gate case 7: 18090Sstevel@tonic-gate case 8: 18100Sstevel@tonic-gate case 9: 18110Sstevel@tonic-gate return ("VIA C3"); 18120Sstevel@tonic-gate default: 18130Sstevel@tonic-gate break; 18140Sstevel@tonic-gate } 18150Sstevel@tonic-gate } 18160Sstevel@tonic-gate break; 18170Sstevel@tonic-gate } 18180Sstevel@tonic-gate return (NULL); 18190Sstevel@tonic-gate } 18200Sstevel@tonic-gate 18210Sstevel@tonic-gate /* 18220Sstevel@tonic-gate * This only gets called in the case that the CPU extended 18230Sstevel@tonic-gate * feature brand string (0x80000002, 0x80000003, 0x80000004) 18240Sstevel@tonic-gate * aren't available, or contain null bytes for some reason. 18250Sstevel@tonic-gate */ 18260Sstevel@tonic-gate static void 18270Sstevel@tonic-gate fabricate_brandstr(struct cpuid_info *cpi) 18280Sstevel@tonic-gate { 18290Sstevel@tonic-gate const char *brand = NULL; 18300Sstevel@tonic-gate 18310Sstevel@tonic-gate switch (cpi->cpi_vendor) { 18320Sstevel@tonic-gate case X86_VENDOR_Intel: 18330Sstevel@tonic-gate brand = intel_cpubrand(cpi); 18340Sstevel@tonic-gate break; 18350Sstevel@tonic-gate case X86_VENDOR_AMD: 18360Sstevel@tonic-gate brand = amd_cpubrand(cpi); 18370Sstevel@tonic-gate break; 18380Sstevel@tonic-gate case X86_VENDOR_Cyrix: 18390Sstevel@tonic-gate brand = cyrix_cpubrand(cpi, x86_type); 18400Sstevel@tonic-gate break; 18410Sstevel@tonic-gate case X86_VENDOR_NexGen: 18420Sstevel@tonic-gate if (cpi->cpi_family == 5 && cpi->cpi_model == 0) 18430Sstevel@tonic-gate brand = "NexGen Nx586"; 18440Sstevel@tonic-gate break; 18450Sstevel@tonic-gate case X86_VENDOR_Centaur: 18460Sstevel@tonic-gate if (cpi->cpi_family == 5) 18470Sstevel@tonic-gate switch (cpi->cpi_model) { 18480Sstevel@tonic-gate case 4: 18490Sstevel@tonic-gate brand = "Centaur C6"; 18500Sstevel@tonic-gate break; 18510Sstevel@tonic-gate case 8: 18520Sstevel@tonic-gate brand = "Centaur C2"; 18530Sstevel@tonic-gate break; 18540Sstevel@tonic-gate case 9: 18550Sstevel@tonic-gate brand = "Centaur C3"; 18560Sstevel@tonic-gate break; 18570Sstevel@tonic-gate default: 18580Sstevel@tonic-gate break; 18590Sstevel@tonic-gate } 18600Sstevel@tonic-gate break; 18610Sstevel@tonic-gate case X86_VENDOR_Rise: 18620Sstevel@tonic-gate if (cpi->cpi_family == 5 && 18630Sstevel@tonic-gate (cpi->cpi_model == 0 || cpi->cpi_model == 2)) 18640Sstevel@tonic-gate brand = "Rise mP6"; 18650Sstevel@tonic-gate break; 18660Sstevel@tonic-gate case X86_VENDOR_SiS: 18670Sstevel@tonic-gate if (cpi->cpi_family == 5 && cpi->cpi_model == 0) 18680Sstevel@tonic-gate brand = "SiS 55x"; 18690Sstevel@tonic-gate break; 18700Sstevel@tonic-gate case X86_VENDOR_TM: 18710Sstevel@tonic-gate if (cpi->cpi_family == 5 && cpi->cpi_model == 4) 18720Sstevel@tonic-gate brand = "Transmeta Crusoe TM3x00 or TM5x00"; 18730Sstevel@tonic-gate break; 18740Sstevel@tonic-gate case X86_VENDOR_NSC: 18750Sstevel@tonic-gate case X86_VENDOR_UMC: 18760Sstevel@tonic-gate default: 18770Sstevel@tonic-gate break; 18780Sstevel@tonic-gate } 18790Sstevel@tonic-gate if (brand) { 18800Sstevel@tonic-gate (void) strcpy((char *)cpi->cpi_brandstr, brand); 18810Sstevel@tonic-gate return; 18820Sstevel@tonic-gate } 18830Sstevel@tonic-gate 18840Sstevel@tonic-gate /* 18850Sstevel@tonic-gate * If all else fails ... 18860Sstevel@tonic-gate */ 18870Sstevel@tonic-gate (void) snprintf(cpi->cpi_brandstr, sizeof (cpi->cpi_brandstr), 18880Sstevel@tonic-gate "%s %d.%d.%d", cpi->cpi_vendorstr, cpi->cpi_family, 18890Sstevel@tonic-gate cpi->cpi_model, cpi->cpi_step); 18900Sstevel@tonic-gate } 18910Sstevel@tonic-gate 18920Sstevel@tonic-gate /* 18930Sstevel@tonic-gate * This routine is called just after kernel memory allocation 18940Sstevel@tonic-gate * becomes available on cpu0, and as part of mp_startup() on 18950Sstevel@tonic-gate * the other cpus. 18960Sstevel@tonic-gate * 18974606Sesaxe * Fixup the brand string, and collect any information from cpuid 18984606Sesaxe * that requires dynamicically allocated storage to represent. 18990Sstevel@tonic-gate */ 19000Sstevel@tonic-gate /*ARGSUSED*/ 19010Sstevel@tonic-gate void 19020Sstevel@tonic-gate cpuid_pass3(cpu_t *cpu) 19030Sstevel@tonic-gate { 19044606Sesaxe int i, max, shft, level, size; 19054606Sesaxe struct cpuid_regs regs; 19064606Sesaxe struct cpuid_regs *cp; 19070Sstevel@tonic-gate struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 19080Sstevel@tonic-gate 19090Sstevel@tonic-gate ASSERT(cpi->cpi_pass == 2); 19100Sstevel@tonic-gate 19114606Sesaxe /* 19124606Sesaxe * Function 4: Deterministic cache parameters 19134606Sesaxe * 19144606Sesaxe * Take this opportunity to detect the number of threads 19154606Sesaxe * sharing the last level cache, and construct a corresponding 19164606Sesaxe * cache id. The respective cpuid_info members are initialized 19174606Sesaxe * to the default case of "no last level cache sharing". 19184606Sesaxe */ 19194606Sesaxe cpi->cpi_ncpu_shr_last_cache = 1; 19204606Sesaxe cpi->cpi_last_lvl_cacheid = cpu->cpu_id; 19214606Sesaxe 19224606Sesaxe if (cpi->cpi_maxeax >= 4 && cpi->cpi_vendor == X86_VENDOR_Intel) { 19234606Sesaxe 19244606Sesaxe /* 19254606Sesaxe * Find the # of elements (size) returned by fn 4, and along 19264606Sesaxe * the way detect last level cache sharing details. 19274606Sesaxe */ 19284606Sesaxe bzero(®s, sizeof (regs)); 19294606Sesaxe cp = ®s; 19304606Sesaxe for (i = 0, max = 0; i < CPI_FN4_ECX_MAX; i++) { 19314606Sesaxe cp->cp_eax = 4; 19324606Sesaxe cp->cp_ecx = i; 19334606Sesaxe 19344606Sesaxe (void) __cpuid_insn(cp); 19354606Sesaxe 19364606Sesaxe if (CPI_CACHE_TYPE(cp) == 0) 19374606Sesaxe break; 19384606Sesaxe level = CPI_CACHE_LVL(cp); 19394606Sesaxe if (level > max) { 19404606Sesaxe max = level; 19414606Sesaxe cpi->cpi_ncpu_shr_last_cache = 19424606Sesaxe CPI_NTHR_SHR_CACHE(cp) + 1; 19434606Sesaxe } 19444606Sesaxe } 19454606Sesaxe cpi->cpi_std_4_size = size = i; 19464606Sesaxe 19474606Sesaxe /* 19484606Sesaxe * Allocate the cpi_std_4 array. The first element 19494606Sesaxe * references the regs for fn 4, %ecx == 0, which 19504606Sesaxe * cpuid_pass2() stashed in cpi->cpi_std[4]. 19514606Sesaxe */ 19524606Sesaxe if (size > 0) { 19534606Sesaxe cpi->cpi_std_4 = 19544606Sesaxe kmem_alloc(size * sizeof (cp), KM_SLEEP); 19554606Sesaxe cpi->cpi_std_4[0] = &cpi->cpi_std[4]; 19564606Sesaxe 19574606Sesaxe /* 19584606Sesaxe * Allocate storage to hold the additional regs 19594606Sesaxe * for function 4, %ecx == 1 .. cpi_std_4_size. 19604606Sesaxe * 19614606Sesaxe * The regs for fn 4, %ecx == 0 has already 19624606Sesaxe * been allocated as indicated above. 19634606Sesaxe */ 19644606Sesaxe for (i = 1; i < size; i++) { 19654606Sesaxe cp = cpi->cpi_std_4[i] = 19664606Sesaxe kmem_zalloc(sizeof (regs), KM_SLEEP); 19674606Sesaxe cp->cp_eax = 4; 19684606Sesaxe cp->cp_ecx = i; 19694606Sesaxe 19704606Sesaxe (void) __cpuid_insn(cp); 19714606Sesaxe } 19724606Sesaxe } 19734606Sesaxe /* 19744606Sesaxe * Determine the number of bits needed to represent 19754606Sesaxe * the number of CPUs sharing the last level cache. 19764606Sesaxe * 19774606Sesaxe * Shift off that number of bits from the APIC id to 19784606Sesaxe * derive the cache id. 19794606Sesaxe */ 19804606Sesaxe shft = 0; 19814606Sesaxe for (i = 1; i < cpi->cpi_ncpu_shr_last_cache; i <<= 1) 19824606Sesaxe shft++; 19837282Smishra cpi->cpi_last_lvl_cacheid = cpi->cpi_apicid >> shft; 19840Sstevel@tonic-gate } 19850Sstevel@tonic-gate 19860Sstevel@tonic-gate /* 19874606Sesaxe * Now fixup the brand string 19880Sstevel@tonic-gate */ 19894606Sesaxe if ((cpi->cpi_xmaxeax & 0x80000000) == 0) { 19904606Sesaxe fabricate_brandstr(cpi); 19914606Sesaxe } else { 19920Sstevel@tonic-gate 19930Sstevel@tonic-gate /* 19944606Sesaxe * If we successfully extracted a brand string from the cpuid 19954606Sesaxe * instruction, clean it up by removing leading spaces and 19964606Sesaxe * similar junk. 19970Sstevel@tonic-gate */ 19984606Sesaxe if (cpi->cpi_brandstr[0]) { 19994606Sesaxe size_t maxlen = sizeof (cpi->cpi_brandstr); 20004606Sesaxe char *src, *dst; 20014606Sesaxe 20024606Sesaxe dst = src = (char *)cpi->cpi_brandstr; 20034606Sesaxe src[maxlen - 1] = '\0'; 20044606Sesaxe /* 20054606Sesaxe * strip leading spaces 20064606Sesaxe */ 20074606Sesaxe while (*src == ' ') 20084606Sesaxe src++; 20094606Sesaxe /* 20104606Sesaxe * Remove any 'Genuine' or "Authentic" prefixes 20114606Sesaxe */ 20124606Sesaxe if (strncmp(src, "Genuine ", 8) == 0) 20134606Sesaxe src += 8; 20144606Sesaxe if (strncmp(src, "Authentic ", 10) == 0) 20154606Sesaxe src += 10; 20164606Sesaxe 20174606Sesaxe /* 20184606Sesaxe * Now do an in-place copy. 20194606Sesaxe * Map (R) to (r) and (TM) to (tm). 20204606Sesaxe * The era of teletypes is long gone, and there's 20214606Sesaxe * -really- no need to shout. 20224606Sesaxe */ 20234606Sesaxe while (*src != '\0') { 20244606Sesaxe if (src[0] == '(') { 20254606Sesaxe if (strncmp(src + 1, "R)", 2) == 0) { 20264606Sesaxe (void) strncpy(dst, "(r)", 3); 20274606Sesaxe src += 3; 20284606Sesaxe dst += 3; 20294606Sesaxe continue; 20304606Sesaxe } 20314606Sesaxe if (strncmp(src + 1, "TM)", 3) == 0) { 20324606Sesaxe (void) strncpy(dst, "(tm)", 4); 20334606Sesaxe src += 4; 20344606Sesaxe dst += 4; 20354606Sesaxe continue; 20364606Sesaxe } 20370Sstevel@tonic-gate } 20384606Sesaxe *dst++ = *src++; 20390Sstevel@tonic-gate } 20404606Sesaxe *dst = '\0'; 20414606Sesaxe 20424606Sesaxe /* 20434606Sesaxe * Finally, remove any trailing spaces 20444606Sesaxe */ 20454606Sesaxe while (--dst > cpi->cpi_brandstr) 20464606Sesaxe if (*dst == ' ') 20474606Sesaxe *dst = '\0'; 20484606Sesaxe else 20494606Sesaxe break; 20504606Sesaxe } else 20514606Sesaxe fabricate_brandstr(cpi); 20524606Sesaxe } 20530Sstevel@tonic-gate cpi->cpi_pass = 3; 20540Sstevel@tonic-gate } 20550Sstevel@tonic-gate 20560Sstevel@tonic-gate /* 20570Sstevel@tonic-gate * This routine is called out of bind_hwcap() much later in the life 20580Sstevel@tonic-gate * of the kernel (post_startup()). The job of this routine is to resolve 20590Sstevel@tonic-gate * the hardware feature support and kernel support for those features into 20600Sstevel@tonic-gate * what we're actually going to tell applications via the aux vector. 20610Sstevel@tonic-gate */ 20620Sstevel@tonic-gate uint_t 20630Sstevel@tonic-gate cpuid_pass4(cpu_t *cpu) 20640Sstevel@tonic-gate { 20650Sstevel@tonic-gate struct cpuid_info *cpi; 20660Sstevel@tonic-gate uint_t hwcap_flags = 0; 20670Sstevel@tonic-gate 20680Sstevel@tonic-gate if (cpu == NULL) 20690Sstevel@tonic-gate cpu = CPU; 20700Sstevel@tonic-gate cpi = cpu->cpu_m.mcpu_cpi; 20710Sstevel@tonic-gate 20720Sstevel@tonic-gate ASSERT(cpi->cpi_pass == 3); 20730Sstevel@tonic-gate 20740Sstevel@tonic-gate if (cpi->cpi_maxeax >= 1) { 20750Sstevel@tonic-gate uint32_t *edx = &cpi->cpi_support[STD_EDX_FEATURES]; 20760Sstevel@tonic-gate uint32_t *ecx = &cpi->cpi_support[STD_ECX_FEATURES]; 20770Sstevel@tonic-gate 20780Sstevel@tonic-gate *edx = CPI_FEATURES_EDX(cpi); 20790Sstevel@tonic-gate *ecx = CPI_FEATURES_ECX(cpi); 20800Sstevel@tonic-gate 20810Sstevel@tonic-gate /* 20820Sstevel@tonic-gate * [these require explicit kernel support] 20830Sstevel@tonic-gate */ 20840Sstevel@tonic-gate if ((x86_feature & X86_SEP) == 0) 20850Sstevel@tonic-gate *edx &= ~CPUID_INTC_EDX_SEP; 20860Sstevel@tonic-gate 20870Sstevel@tonic-gate if ((x86_feature & X86_SSE) == 0) 20880Sstevel@tonic-gate *edx &= ~(CPUID_INTC_EDX_FXSR|CPUID_INTC_EDX_SSE); 20890Sstevel@tonic-gate if ((x86_feature & X86_SSE2) == 0) 20900Sstevel@tonic-gate *edx &= ~CPUID_INTC_EDX_SSE2; 20910Sstevel@tonic-gate 20920Sstevel@tonic-gate if ((x86_feature & X86_HTT) == 0) 20930Sstevel@tonic-gate *edx &= ~CPUID_INTC_EDX_HTT; 20940Sstevel@tonic-gate 20950Sstevel@tonic-gate if ((x86_feature & X86_SSE3) == 0) 20960Sstevel@tonic-gate *ecx &= ~CPUID_INTC_ECX_SSE3; 20970Sstevel@tonic-gate 20985269Skk208521 if (cpi->cpi_vendor == X86_VENDOR_Intel) { 20995269Skk208521 if ((x86_feature & X86_SSSE3) == 0) 21005269Skk208521 *ecx &= ~CPUID_INTC_ECX_SSSE3; 21015269Skk208521 if ((x86_feature & X86_SSE4_1) == 0) 21025269Skk208521 *ecx &= ~CPUID_INTC_ECX_SSE4_1; 21035269Skk208521 if ((x86_feature & X86_SSE4_2) == 0) 21045269Skk208521 *ecx &= ~CPUID_INTC_ECX_SSE4_2; 21059370SKuriakose.Kuruvilla@Sun.COM if ((x86_feature & X86_AES) == 0) 21069370SKuriakose.Kuruvilla@Sun.COM *ecx &= ~CPUID_INTC_ECX_AES; 21075269Skk208521 } 21085269Skk208521 21090Sstevel@tonic-gate /* 21100Sstevel@tonic-gate * [no explicit support required beyond x87 fp context] 21110Sstevel@tonic-gate */ 21120Sstevel@tonic-gate if (!fpu_exists) 21130Sstevel@tonic-gate *edx &= ~(CPUID_INTC_EDX_FPU | CPUID_INTC_EDX_MMX); 21140Sstevel@tonic-gate 21150Sstevel@tonic-gate /* 21160Sstevel@tonic-gate * Now map the supported feature vector to things that we 21170Sstevel@tonic-gate * think userland will care about. 21180Sstevel@tonic-gate */ 21190Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_SEP) 21200Sstevel@tonic-gate hwcap_flags |= AV_386_SEP; 21210Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_SSE) 21220Sstevel@tonic-gate hwcap_flags |= AV_386_FXSR | AV_386_SSE; 21230Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_SSE2) 21240Sstevel@tonic-gate hwcap_flags |= AV_386_SSE2; 21250Sstevel@tonic-gate if (*ecx & CPUID_INTC_ECX_SSE3) 21260Sstevel@tonic-gate hwcap_flags |= AV_386_SSE3; 21275269Skk208521 if (cpi->cpi_vendor == X86_VENDOR_Intel) { 21285269Skk208521 if (*ecx & CPUID_INTC_ECX_SSSE3) 21295269Skk208521 hwcap_flags |= AV_386_SSSE3; 21305269Skk208521 if (*ecx & CPUID_INTC_ECX_SSE4_1) 21315269Skk208521 hwcap_flags |= AV_386_SSE4_1; 21325269Skk208521 if (*ecx & CPUID_INTC_ECX_SSE4_2) 21335269Skk208521 hwcap_flags |= AV_386_SSE4_2; 21348418SKrishnendu.Sadhukhan@Sun.COM if (*ecx & CPUID_INTC_ECX_MOVBE) 21358418SKrishnendu.Sadhukhan@Sun.COM hwcap_flags |= AV_386_MOVBE; 21369370SKuriakose.Kuruvilla@Sun.COM if (*ecx & CPUID_INTC_ECX_AES) 21379370SKuriakose.Kuruvilla@Sun.COM hwcap_flags |= AV_386_AES; 21389370SKuriakose.Kuruvilla@Sun.COM if (*ecx & CPUID_INTC_ECX_PCLMULQDQ) 21399370SKuriakose.Kuruvilla@Sun.COM hwcap_flags |= AV_386_PCLMULQDQ; 21405269Skk208521 } 21414628Skk208521 if (*ecx & CPUID_INTC_ECX_POPCNT) 21424628Skk208521 hwcap_flags |= AV_386_POPCNT; 21430Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_FPU) 21440Sstevel@tonic-gate hwcap_flags |= AV_386_FPU; 21450Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_MMX) 21460Sstevel@tonic-gate hwcap_flags |= AV_386_MMX; 21470Sstevel@tonic-gate 21480Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_TSC) 21490Sstevel@tonic-gate hwcap_flags |= AV_386_TSC; 21500Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_CX8) 21510Sstevel@tonic-gate hwcap_flags |= AV_386_CX8; 21520Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_CMOV) 21530Sstevel@tonic-gate hwcap_flags |= AV_386_CMOV; 21540Sstevel@tonic-gate if (*ecx & CPUID_INTC_ECX_MON) 21550Sstevel@tonic-gate hwcap_flags |= AV_386_MON; 21560Sstevel@tonic-gate if (*ecx & CPUID_INTC_ECX_CX16) 21570Sstevel@tonic-gate hwcap_flags |= AV_386_CX16; 21580Sstevel@tonic-gate } 21590Sstevel@tonic-gate 21601228Sandrei if (x86_feature & X86_HTT) 21610Sstevel@tonic-gate hwcap_flags |= AV_386_PAUSE; 21620Sstevel@tonic-gate 21630Sstevel@tonic-gate if (cpi->cpi_xmaxeax < 0x80000001) 21640Sstevel@tonic-gate goto pass4_done; 21650Sstevel@tonic-gate 21660Sstevel@tonic-gate switch (cpi->cpi_vendor) { 21671228Sandrei struct cpuid_regs cp; 21683446Smrj uint32_t *edx, *ecx; 21690Sstevel@tonic-gate 21703446Smrj case X86_VENDOR_Intel: 21713446Smrj /* 21723446Smrj * Seems like Intel duplicated what we necessary 21733446Smrj * here to make the initial crop of 64-bit OS's work. 21743446Smrj * Hopefully, those are the only "extended" bits 21753446Smrj * they'll add. 21763446Smrj */ 21773446Smrj /*FALLTHROUGH*/ 21783446Smrj 21790Sstevel@tonic-gate case X86_VENDOR_AMD: 21800Sstevel@tonic-gate edx = &cpi->cpi_support[AMD_EDX_FEATURES]; 21813446Smrj ecx = &cpi->cpi_support[AMD_ECX_FEATURES]; 21820Sstevel@tonic-gate 21830Sstevel@tonic-gate *edx = CPI_FEATURES_XTD_EDX(cpi); 21843446Smrj *ecx = CPI_FEATURES_XTD_ECX(cpi); 21853446Smrj 21863446Smrj /* 21873446Smrj * [these features require explicit kernel support] 21883446Smrj */ 21893446Smrj switch (cpi->cpi_vendor) { 21903446Smrj case X86_VENDOR_Intel: 21916657Ssudheer if ((x86_feature & X86_TSCP) == 0) 21926657Ssudheer *edx &= ~CPUID_AMD_EDX_TSCP; 21933446Smrj break; 21943446Smrj 21953446Smrj case X86_VENDOR_AMD: 21963446Smrj if ((x86_feature & X86_TSCP) == 0) 21973446Smrj *edx &= ~CPUID_AMD_EDX_TSCP; 21984628Skk208521 if ((x86_feature & X86_SSE4A) == 0) 21994628Skk208521 *ecx &= ~CPUID_AMD_ECX_SSE4A; 22003446Smrj break; 22013446Smrj 22023446Smrj default: 22033446Smrj break; 22043446Smrj } 22050Sstevel@tonic-gate 22060Sstevel@tonic-gate /* 22070Sstevel@tonic-gate * [no explicit support required beyond 22080Sstevel@tonic-gate * x87 fp context and exception handlers] 22090Sstevel@tonic-gate */ 22100Sstevel@tonic-gate if (!fpu_exists) 22110Sstevel@tonic-gate *edx &= ~(CPUID_AMD_EDX_MMXamd | 22120Sstevel@tonic-gate CPUID_AMD_EDX_3DNow | CPUID_AMD_EDX_3DNowx); 22130Sstevel@tonic-gate 22140Sstevel@tonic-gate if ((x86_feature & X86_NX) == 0) 22150Sstevel@tonic-gate *edx &= ~CPUID_AMD_EDX_NX; 22163446Smrj #if !defined(__amd64) 22170Sstevel@tonic-gate *edx &= ~CPUID_AMD_EDX_LM; 22180Sstevel@tonic-gate #endif 22190Sstevel@tonic-gate /* 22200Sstevel@tonic-gate * Now map the supported feature vector to 22210Sstevel@tonic-gate * things that we think userland will care about. 22220Sstevel@tonic-gate */ 22233446Smrj #if defined(__amd64) 22240Sstevel@tonic-gate if (*edx & CPUID_AMD_EDX_SYSC) 22250Sstevel@tonic-gate hwcap_flags |= AV_386_AMD_SYSC; 22263446Smrj #endif 22270Sstevel@tonic-gate if (*edx & CPUID_AMD_EDX_MMXamd) 22280Sstevel@tonic-gate hwcap_flags |= AV_386_AMD_MMX; 22290Sstevel@tonic-gate if (*edx & CPUID_AMD_EDX_3DNow) 22300Sstevel@tonic-gate hwcap_flags |= AV_386_AMD_3DNow; 22310Sstevel@tonic-gate if (*edx & CPUID_AMD_EDX_3DNowx) 22320Sstevel@tonic-gate hwcap_flags |= AV_386_AMD_3DNowx; 22333446Smrj 22343446Smrj switch (cpi->cpi_vendor) { 22353446Smrj case X86_VENDOR_AMD: 22363446Smrj if (*edx & CPUID_AMD_EDX_TSCP) 22373446Smrj hwcap_flags |= AV_386_TSCP; 22383446Smrj if (*ecx & CPUID_AMD_ECX_AHF64) 22393446Smrj hwcap_flags |= AV_386_AHF; 22404628Skk208521 if (*ecx & CPUID_AMD_ECX_SSE4A) 22414628Skk208521 hwcap_flags |= AV_386_AMD_SSE4A; 22424628Skk208521 if (*ecx & CPUID_AMD_ECX_LZCNT) 22434628Skk208521 hwcap_flags |= AV_386_AMD_LZCNT; 22443446Smrj break; 22453446Smrj 22463446Smrj case X86_VENDOR_Intel: 22476657Ssudheer if (*edx & CPUID_AMD_EDX_TSCP) 22486657Ssudheer hwcap_flags |= AV_386_TSCP; 22493446Smrj /* 22503446Smrj * Aarrgh. 22513446Smrj * Intel uses a different bit in the same word. 22523446Smrj */ 22533446Smrj if (*ecx & CPUID_INTC_ECX_AHF64) 22543446Smrj hwcap_flags |= AV_386_AHF; 22553446Smrj break; 22563446Smrj 22573446Smrj default: 22583446Smrj break; 22593446Smrj } 22600Sstevel@tonic-gate break; 22610Sstevel@tonic-gate 22620Sstevel@tonic-gate case X86_VENDOR_TM: 22631228Sandrei cp.cp_eax = 0x80860001; 22641228Sandrei (void) __cpuid_insn(&cp); 22651228Sandrei cpi->cpi_support[TM_EDX_FEATURES] = cp.cp_edx; 22660Sstevel@tonic-gate break; 22670Sstevel@tonic-gate 22680Sstevel@tonic-gate default: 22690Sstevel@tonic-gate break; 22700Sstevel@tonic-gate } 22710Sstevel@tonic-gate 22720Sstevel@tonic-gate pass4_done: 22730Sstevel@tonic-gate cpi->cpi_pass = 4; 22740Sstevel@tonic-gate return (hwcap_flags); 22750Sstevel@tonic-gate } 22760Sstevel@tonic-gate 22770Sstevel@tonic-gate 22780Sstevel@tonic-gate /* 22790Sstevel@tonic-gate * Simulate the cpuid instruction using the data we previously 22800Sstevel@tonic-gate * captured about this CPU. We try our best to return the truth 22810Sstevel@tonic-gate * about the hardware, independently of kernel support. 22820Sstevel@tonic-gate */ 22830Sstevel@tonic-gate uint32_t 22841228Sandrei cpuid_insn(cpu_t *cpu, struct cpuid_regs *cp) 22850Sstevel@tonic-gate { 22860Sstevel@tonic-gate struct cpuid_info *cpi; 22871228Sandrei struct cpuid_regs *xcp; 22880Sstevel@tonic-gate 22890Sstevel@tonic-gate if (cpu == NULL) 22900Sstevel@tonic-gate cpu = CPU; 22910Sstevel@tonic-gate cpi = cpu->cpu_m.mcpu_cpi; 22920Sstevel@tonic-gate 22930Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 3)); 22940Sstevel@tonic-gate 22950Sstevel@tonic-gate /* 22960Sstevel@tonic-gate * CPUID data is cached in two separate places: cpi_std for standard 22970Sstevel@tonic-gate * CPUID functions, and cpi_extd for extended CPUID functions. 22980Sstevel@tonic-gate */ 22991228Sandrei if (cp->cp_eax <= cpi->cpi_maxeax && cp->cp_eax < NMAX_CPI_STD) 23001228Sandrei xcp = &cpi->cpi_std[cp->cp_eax]; 23011228Sandrei else if (cp->cp_eax >= 0x80000000 && cp->cp_eax <= cpi->cpi_xmaxeax && 23021228Sandrei cp->cp_eax < 0x80000000 + NMAX_CPI_EXTD) 23031228Sandrei xcp = &cpi->cpi_extd[cp->cp_eax - 0x80000000]; 23040Sstevel@tonic-gate else 23050Sstevel@tonic-gate /* 23060Sstevel@tonic-gate * The caller is asking for data from an input parameter which 23070Sstevel@tonic-gate * the kernel has not cached. In this case we go fetch from 23080Sstevel@tonic-gate * the hardware and return the data directly to the user. 23090Sstevel@tonic-gate */ 23101228Sandrei return (__cpuid_insn(cp)); 23111228Sandrei 23121228Sandrei cp->cp_eax = xcp->cp_eax; 23131228Sandrei cp->cp_ebx = xcp->cp_ebx; 23141228Sandrei cp->cp_ecx = xcp->cp_ecx; 23151228Sandrei cp->cp_edx = xcp->cp_edx; 23160Sstevel@tonic-gate return (cp->cp_eax); 23170Sstevel@tonic-gate } 23180Sstevel@tonic-gate 23190Sstevel@tonic-gate int 23200Sstevel@tonic-gate cpuid_checkpass(cpu_t *cpu, int pass) 23210Sstevel@tonic-gate { 23220Sstevel@tonic-gate return (cpu != NULL && cpu->cpu_m.mcpu_cpi != NULL && 23230Sstevel@tonic-gate cpu->cpu_m.mcpu_cpi->cpi_pass >= pass); 23240Sstevel@tonic-gate } 23250Sstevel@tonic-gate 23260Sstevel@tonic-gate int 23270Sstevel@tonic-gate cpuid_getbrandstr(cpu_t *cpu, char *s, size_t n) 23280Sstevel@tonic-gate { 23290Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 3)); 23300Sstevel@tonic-gate 23310Sstevel@tonic-gate return (snprintf(s, n, "%s", cpu->cpu_m.mcpu_cpi->cpi_brandstr)); 23320Sstevel@tonic-gate } 23330Sstevel@tonic-gate 23340Sstevel@tonic-gate int 23351228Sandrei cpuid_is_cmt(cpu_t *cpu) 23360Sstevel@tonic-gate { 23370Sstevel@tonic-gate if (cpu == NULL) 23380Sstevel@tonic-gate cpu = CPU; 23390Sstevel@tonic-gate 23400Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 23410Sstevel@tonic-gate 23420Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_chipid >= 0); 23430Sstevel@tonic-gate } 23440Sstevel@tonic-gate 23450Sstevel@tonic-gate /* 23460Sstevel@tonic-gate * AMD and Intel both implement the 64-bit variant of the syscall 23470Sstevel@tonic-gate * instruction (syscallq), so if there's -any- support for syscall, 23480Sstevel@tonic-gate * cpuid currently says "yes, we support this". 23490Sstevel@tonic-gate * 23500Sstevel@tonic-gate * However, Intel decided to -not- implement the 32-bit variant of the 23510Sstevel@tonic-gate * syscall instruction, so we provide a predicate to allow our caller 23520Sstevel@tonic-gate * to test that subtlety here. 23535084Sjohnlev * 23545084Sjohnlev * XXPV Currently, 32-bit syscall instructions don't work via the hypervisor, 23555084Sjohnlev * even in the case where the hardware would in fact support it. 23560Sstevel@tonic-gate */ 23570Sstevel@tonic-gate /*ARGSUSED*/ 23580Sstevel@tonic-gate int 23590Sstevel@tonic-gate cpuid_syscall32_insn(cpu_t *cpu) 23600Sstevel@tonic-gate { 23610Sstevel@tonic-gate ASSERT(cpuid_checkpass((cpu == NULL ? CPU : cpu), 1)); 23620Sstevel@tonic-gate 23635084Sjohnlev #if !defined(__xpv) 23643446Smrj if (cpu == NULL) 23653446Smrj cpu = CPU; 23663446Smrj 23673446Smrj /*CSTYLED*/ 23683446Smrj { 23693446Smrj struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 23703446Smrj 23713446Smrj if (cpi->cpi_vendor == X86_VENDOR_AMD && 23723446Smrj cpi->cpi_xmaxeax >= 0x80000001 && 23733446Smrj (CPI_FEATURES_XTD_EDX(cpi) & CPUID_AMD_EDX_SYSC)) 23743446Smrj return (1); 23753446Smrj } 23765084Sjohnlev #endif 23770Sstevel@tonic-gate return (0); 23780Sstevel@tonic-gate } 23790Sstevel@tonic-gate 23800Sstevel@tonic-gate int 23810Sstevel@tonic-gate cpuid_getidstr(cpu_t *cpu, char *s, size_t n) 23820Sstevel@tonic-gate { 23830Sstevel@tonic-gate struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 23840Sstevel@tonic-gate 23850Sstevel@tonic-gate static const char fmt[] = 23863779Sdmick "x86 (%s %X family %d model %d step %d clock %d MHz)"; 23870Sstevel@tonic-gate static const char fmt_ht[] = 23883779Sdmick "x86 (chipid 0x%x %s %X family %d model %d step %d clock %d MHz)"; 23890Sstevel@tonic-gate 23900Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 23910Sstevel@tonic-gate 23921228Sandrei if (cpuid_is_cmt(cpu)) 23930Sstevel@tonic-gate return (snprintf(s, n, fmt_ht, cpi->cpi_chipid, 23943779Sdmick cpi->cpi_vendorstr, cpi->cpi_std[1].cp_eax, 23953779Sdmick cpi->cpi_family, cpi->cpi_model, 23960Sstevel@tonic-gate cpi->cpi_step, cpu->cpu_type_info.pi_clock)); 23970Sstevel@tonic-gate return (snprintf(s, n, fmt, 23983779Sdmick cpi->cpi_vendorstr, cpi->cpi_std[1].cp_eax, 23993779Sdmick cpi->cpi_family, cpi->cpi_model, 24000Sstevel@tonic-gate cpi->cpi_step, cpu->cpu_type_info.pi_clock)); 24010Sstevel@tonic-gate } 24020Sstevel@tonic-gate 24030Sstevel@tonic-gate const char * 24040Sstevel@tonic-gate cpuid_getvendorstr(cpu_t *cpu) 24050Sstevel@tonic-gate { 24060Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 24070Sstevel@tonic-gate return ((const char *)cpu->cpu_m.mcpu_cpi->cpi_vendorstr); 24080Sstevel@tonic-gate } 24090Sstevel@tonic-gate 24100Sstevel@tonic-gate uint_t 24110Sstevel@tonic-gate cpuid_getvendor(cpu_t *cpu) 24120Sstevel@tonic-gate { 24130Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 24140Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_vendor); 24150Sstevel@tonic-gate } 24160Sstevel@tonic-gate 24170Sstevel@tonic-gate uint_t 24180Sstevel@tonic-gate cpuid_getfamily(cpu_t *cpu) 24190Sstevel@tonic-gate { 24200Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 24210Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_family); 24220Sstevel@tonic-gate } 24230Sstevel@tonic-gate 24240Sstevel@tonic-gate uint_t 24250Sstevel@tonic-gate cpuid_getmodel(cpu_t *cpu) 24260Sstevel@tonic-gate { 24270Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 24280Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_model); 24290Sstevel@tonic-gate } 24300Sstevel@tonic-gate 24310Sstevel@tonic-gate uint_t 24320Sstevel@tonic-gate cpuid_get_ncpu_per_chip(cpu_t *cpu) 24330Sstevel@tonic-gate { 24340Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 24350Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_ncpu_per_chip); 24360Sstevel@tonic-gate } 24370Sstevel@tonic-gate 24380Sstevel@tonic-gate uint_t 24391228Sandrei cpuid_get_ncore_per_chip(cpu_t *cpu) 24401228Sandrei { 24411228Sandrei ASSERT(cpuid_checkpass(cpu, 1)); 24421228Sandrei return (cpu->cpu_m.mcpu_cpi->cpi_ncore_per_chip); 24431228Sandrei } 24441228Sandrei 24451228Sandrei uint_t 24464606Sesaxe cpuid_get_ncpu_sharing_last_cache(cpu_t *cpu) 24474606Sesaxe { 24484606Sesaxe ASSERT(cpuid_checkpass(cpu, 2)); 24494606Sesaxe return (cpu->cpu_m.mcpu_cpi->cpi_ncpu_shr_last_cache); 24504606Sesaxe } 24514606Sesaxe 24524606Sesaxe id_t 24534606Sesaxe cpuid_get_last_lvl_cacheid(cpu_t *cpu) 24544606Sesaxe { 24554606Sesaxe ASSERT(cpuid_checkpass(cpu, 2)); 24564606Sesaxe return (cpu->cpu_m.mcpu_cpi->cpi_last_lvl_cacheid); 24574606Sesaxe } 24584606Sesaxe 24594606Sesaxe uint_t 24600Sstevel@tonic-gate cpuid_getstep(cpu_t *cpu) 24610Sstevel@tonic-gate { 24620Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 24630Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_step); 24640Sstevel@tonic-gate } 24650Sstevel@tonic-gate 24664581Ssherrym uint_t 24674581Ssherrym cpuid_getsig(struct cpu *cpu) 24684581Ssherrym { 24694581Ssherrym ASSERT(cpuid_checkpass(cpu, 1)); 24704581Ssherrym return (cpu->cpu_m.mcpu_cpi->cpi_std[1].cp_eax); 24714581Ssherrym } 24724581Ssherrym 24732869Sgavinm uint32_t 24742869Sgavinm cpuid_getchiprev(struct cpu *cpu) 24752869Sgavinm { 24762869Sgavinm ASSERT(cpuid_checkpass(cpu, 1)); 24772869Sgavinm return (cpu->cpu_m.mcpu_cpi->cpi_chiprev); 24782869Sgavinm } 24792869Sgavinm 24802869Sgavinm const char * 24812869Sgavinm cpuid_getchiprevstr(struct cpu *cpu) 24822869Sgavinm { 24832869Sgavinm ASSERT(cpuid_checkpass(cpu, 1)); 24842869Sgavinm return (cpu->cpu_m.mcpu_cpi->cpi_chiprevstr); 24852869Sgavinm } 24862869Sgavinm 24872869Sgavinm uint32_t 24882869Sgavinm cpuid_getsockettype(struct cpu *cpu) 24892869Sgavinm { 24902869Sgavinm ASSERT(cpuid_checkpass(cpu, 1)); 24912869Sgavinm return (cpu->cpu_m.mcpu_cpi->cpi_socket); 24922869Sgavinm } 24932869Sgavinm 24949482SKuriakose.Kuruvilla@Sun.COM const char * 24959482SKuriakose.Kuruvilla@Sun.COM cpuid_getsocketstr(cpu_t *cpu) 24969482SKuriakose.Kuruvilla@Sun.COM { 24979482SKuriakose.Kuruvilla@Sun.COM static const char *socketstr = NULL; 24989482SKuriakose.Kuruvilla@Sun.COM struct cpuid_info *cpi; 24999482SKuriakose.Kuruvilla@Sun.COM 25009482SKuriakose.Kuruvilla@Sun.COM ASSERT(cpuid_checkpass(cpu, 1)); 25019482SKuriakose.Kuruvilla@Sun.COM cpi = cpu->cpu_m.mcpu_cpi; 25029482SKuriakose.Kuruvilla@Sun.COM 25039482SKuriakose.Kuruvilla@Sun.COM /* Assume that socket types are the same across the system */ 25049482SKuriakose.Kuruvilla@Sun.COM if (socketstr == NULL) 25059482SKuriakose.Kuruvilla@Sun.COM socketstr = _cpuid_sktstr(cpi->cpi_vendor, cpi->cpi_family, 25069482SKuriakose.Kuruvilla@Sun.COM cpi->cpi_model, cpi->cpi_step); 25079482SKuriakose.Kuruvilla@Sun.COM 25089482SKuriakose.Kuruvilla@Sun.COM 25099482SKuriakose.Kuruvilla@Sun.COM return (socketstr); 25109482SKuriakose.Kuruvilla@Sun.COM } 25119482SKuriakose.Kuruvilla@Sun.COM 25123434Sesaxe int 25133434Sesaxe cpuid_get_chipid(cpu_t *cpu) 25140Sstevel@tonic-gate { 25150Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 25160Sstevel@tonic-gate 25171228Sandrei if (cpuid_is_cmt(cpu)) 25180Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_chipid); 25190Sstevel@tonic-gate return (cpu->cpu_id); 25200Sstevel@tonic-gate } 25210Sstevel@tonic-gate 25221228Sandrei id_t 25233434Sesaxe cpuid_get_coreid(cpu_t *cpu) 25241228Sandrei { 25251228Sandrei ASSERT(cpuid_checkpass(cpu, 1)); 25261228Sandrei return (cpu->cpu_m.mcpu_cpi->cpi_coreid); 25271228Sandrei } 25281228Sandrei 25290Sstevel@tonic-gate int 25305870Sgavinm cpuid_get_pkgcoreid(cpu_t *cpu) 25315870Sgavinm { 25325870Sgavinm ASSERT(cpuid_checkpass(cpu, 1)); 25335870Sgavinm return (cpu->cpu_m.mcpu_cpi->cpi_pkgcoreid); 25345870Sgavinm } 25355870Sgavinm 25365870Sgavinm int 25373434Sesaxe cpuid_get_clogid(cpu_t *cpu) 25380Sstevel@tonic-gate { 25390Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 25400Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_clogid); 25410Sstevel@tonic-gate } 25420Sstevel@tonic-gate 2543*10080SJoe.Bonasera@sun.com /*ARGSUSED*/ 2544*10080SJoe.Bonasera@sun.com int 2545*10080SJoe.Bonasera@sun.com cpuid_have_cr8access(cpu_t *cpu) 2546*10080SJoe.Bonasera@sun.com { 2547*10080SJoe.Bonasera@sun.com #if defined(__amd64) 2548*10080SJoe.Bonasera@sun.com return (1); 2549*10080SJoe.Bonasera@sun.com #else 2550*10080SJoe.Bonasera@sun.com struct cpuid_info *cpi; 2551*10080SJoe.Bonasera@sun.com 2552*10080SJoe.Bonasera@sun.com ASSERT(cpu != NULL); 2553*10080SJoe.Bonasera@sun.com cpi = cpu->cpu_m.mcpu_cpi; 2554*10080SJoe.Bonasera@sun.com if (cpi->cpi_vendor == X86_VENDOR_AMD && cpi->cpi_maxeax >= 1 && 2555*10080SJoe.Bonasera@sun.com (CPI_FEATURES_XTD_ECX(cpi) & CPUID_AMD_ECX_CR8D) != 0) 2556*10080SJoe.Bonasera@sun.com return (1); 2557*10080SJoe.Bonasera@sun.com return (0); 2558*10080SJoe.Bonasera@sun.com #endif 2559*10080SJoe.Bonasera@sun.com } 2560*10080SJoe.Bonasera@sun.com 25619652SMichael.Corcoran@Sun.COM uint32_t 25629652SMichael.Corcoran@Sun.COM cpuid_get_apicid(cpu_t *cpu) 25639652SMichael.Corcoran@Sun.COM { 25649652SMichael.Corcoran@Sun.COM ASSERT(cpuid_checkpass(cpu, 1)); 25659652SMichael.Corcoran@Sun.COM if (cpu->cpu_m.mcpu_cpi->cpi_maxeax < 1) { 25669652SMichael.Corcoran@Sun.COM return (UINT32_MAX); 25679652SMichael.Corcoran@Sun.COM } else { 25689652SMichael.Corcoran@Sun.COM return (cpu->cpu_m.mcpu_cpi->cpi_apicid); 25699652SMichael.Corcoran@Sun.COM } 25709652SMichael.Corcoran@Sun.COM } 25719652SMichael.Corcoran@Sun.COM 25720Sstevel@tonic-gate void 25730Sstevel@tonic-gate cpuid_get_addrsize(cpu_t *cpu, uint_t *pabits, uint_t *vabits) 25740Sstevel@tonic-gate { 25750Sstevel@tonic-gate struct cpuid_info *cpi; 25760Sstevel@tonic-gate 25770Sstevel@tonic-gate if (cpu == NULL) 25780Sstevel@tonic-gate cpu = CPU; 25790Sstevel@tonic-gate cpi = cpu->cpu_m.mcpu_cpi; 25800Sstevel@tonic-gate 25810Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 25820Sstevel@tonic-gate 25830Sstevel@tonic-gate if (pabits) 25840Sstevel@tonic-gate *pabits = cpi->cpi_pabits; 25850Sstevel@tonic-gate if (vabits) 25860Sstevel@tonic-gate *vabits = cpi->cpi_vabits; 25870Sstevel@tonic-gate } 25880Sstevel@tonic-gate 25890Sstevel@tonic-gate /* 25900Sstevel@tonic-gate * Returns the number of data TLB entries for a corresponding 25910Sstevel@tonic-gate * pagesize. If it can't be computed, or isn't known, the 25920Sstevel@tonic-gate * routine returns zero. If you ask about an architecturally 25930Sstevel@tonic-gate * impossible pagesize, the routine will panic (so that the 25940Sstevel@tonic-gate * hat implementor knows that things are inconsistent.) 25950Sstevel@tonic-gate */ 25960Sstevel@tonic-gate uint_t 25970Sstevel@tonic-gate cpuid_get_dtlb_nent(cpu_t *cpu, size_t pagesize) 25980Sstevel@tonic-gate { 25990Sstevel@tonic-gate struct cpuid_info *cpi; 26000Sstevel@tonic-gate uint_t dtlb_nent = 0; 26010Sstevel@tonic-gate 26020Sstevel@tonic-gate if (cpu == NULL) 26030Sstevel@tonic-gate cpu = CPU; 26040Sstevel@tonic-gate cpi = cpu->cpu_m.mcpu_cpi; 26050Sstevel@tonic-gate 26060Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 26070Sstevel@tonic-gate 26080Sstevel@tonic-gate /* 26090Sstevel@tonic-gate * Check the L2 TLB info 26100Sstevel@tonic-gate */ 26110Sstevel@tonic-gate if (cpi->cpi_xmaxeax >= 0x80000006) { 26121228Sandrei struct cpuid_regs *cp = &cpi->cpi_extd[6]; 26130Sstevel@tonic-gate 26140Sstevel@tonic-gate switch (pagesize) { 26150Sstevel@tonic-gate 26160Sstevel@tonic-gate case 4 * 1024: 26170Sstevel@tonic-gate /* 26180Sstevel@tonic-gate * All zero in the top 16 bits of the register 26190Sstevel@tonic-gate * indicates a unified TLB. Size is in low 16 bits. 26200Sstevel@tonic-gate */ 26210Sstevel@tonic-gate if ((cp->cp_ebx & 0xffff0000) == 0) 26220Sstevel@tonic-gate dtlb_nent = cp->cp_ebx & 0x0000ffff; 26230Sstevel@tonic-gate else 26240Sstevel@tonic-gate dtlb_nent = BITX(cp->cp_ebx, 27, 16); 26250Sstevel@tonic-gate break; 26260Sstevel@tonic-gate 26270Sstevel@tonic-gate case 2 * 1024 * 1024: 26280Sstevel@tonic-gate if ((cp->cp_eax & 0xffff0000) == 0) 26290Sstevel@tonic-gate dtlb_nent = cp->cp_eax & 0x0000ffff; 26300Sstevel@tonic-gate else 26310Sstevel@tonic-gate dtlb_nent = BITX(cp->cp_eax, 27, 16); 26320Sstevel@tonic-gate break; 26330Sstevel@tonic-gate 26340Sstevel@tonic-gate default: 26350Sstevel@tonic-gate panic("unknown L2 pagesize"); 26360Sstevel@tonic-gate /*NOTREACHED*/ 26370Sstevel@tonic-gate } 26380Sstevel@tonic-gate } 26390Sstevel@tonic-gate 26400Sstevel@tonic-gate if (dtlb_nent != 0) 26410Sstevel@tonic-gate return (dtlb_nent); 26420Sstevel@tonic-gate 26430Sstevel@tonic-gate /* 26440Sstevel@tonic-gate * No L2 TLB support for this size, try L1. 26450Sstevel@tonic-gate */ 26460Sstevel@tonic-gate if (cpi->cpi_xmaxeax >= 0x80000005) { 26471228Sandrei struct cpuid_regs *cp = &cpi->cpi_extd[5]; 26480Sstevel@tonic-gate 26490Sstevel@tonic-gate switch (pagesize) { 26500Sstevel@tonic-gate case 4 * 1024: 26510Sstevel@tonic-gate dtlb_nent = BITX(cp->cp_ebx, 23, 16); 26520Sstevel@tonic-gate break; 26530Sstevel@tonic-gate case 2 * 1024 * 1024: 26540Sstevel@tonic-gate dtlb_nent = BITX(cp->cp_eax, 23, 16); 26550Sstevel@tonic-gate break; 26560Sstevel@tonic-gate default: 26570Sstevel@tonic-gate panic("unknown L1 d-TLB pagesize"); 26580Sstevel@tonic-gate /*NOTREACHED*/ 26590Sstevel@tonic-gate } 26600Sstevel@tonic-gate } 26610Sstevel@tonic-gate 26620Sstevel@tonic-gate return (dtlb_nent); 26630Sstevel@tonic-gate } 26640Sstevel@tonic-gate 26650Sstevel@tonic-gate /* 26660Sstevel@tonic-gate * Return 0 if the erratum is not present or not applicable, positive 26670Sstevel@tonic-gate * if it is, and negative if the status of the erratum is unknown. 26680Sstevel@tonic-gate * 26690Sstevel@tonic-gate * See "Revision Guide for AMD Athlon(tm) 64 and AMD Opteron(tm) 2670359Skucharsk * Processors" #25759, Rev 3.57, August 2005 26710Sstevel@tonic-gate */ 26720Sstevel@tonic-gate int 26730Sstevel@tonic-gate cpuid_opteron_erratum(cpu_t *cpu, uint_t erratum) 26740Sstevel@tonic-gate { 26750Sstevel@tonic-gate struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 26761228Sandrei uint_t eax; 26770Sstevel@tonic-gate 26782584Ssethg /* 26792584Ssethg * Bail out if this CPU isn't an AMD CPU, or if it's 26802584Ssethg * a legacy (32-bit) AMD CPU. 26812584Ssethg */ 26822584Ssethg if (cpi->cpi_vendor != X86_VENDOR_AMD || 26834265Skchow cpi->cpi_family == 4 || cpi->cpi_family == 5 || 26844265Skchow cpi->cpi_family == 6) 26852869Sgavinm 26860Sstevel@tonic-gate return (0); 26870Sstevel@tonic-gate 26880Sstevel@tonic-gate eax = cpi->cpi_std[1].cp_eax; 26890Sstevel@tonic-gate 26900Sstevel@tonic-gate #define SH_B0(eax) (eax == 0xf40 || eax == 0xf50) 26910Sstevel@tonic-gate #define SH_B3(eax) (eax == 0xf51) 26921582Skchow #define B(eax) (SH_B0(eax) || SH_B3(eax)) 26930Sstevel@tonic-gate 26940Sstevel@tonic-gate #define SH_C0(eax) (eax == 0xf48 || eax == 0xf58) 26950Sstevel@tonic-gate 26960Sstevel@tonic-gate #define SH_CG(eax) (eax == 0xf4a || eax == 0xf5a || eax == 0xf7a) 26970Sstevel@tonic-gate #define DH_CG(eax) (eax == 0xfc0 || eax == 0xfe0 || eax == 0xff0) 26980Sstevel@tonic-gate #define CH_CG(eax) (eax == 0xf82 || eax == 0xfb2) 26991582Skchow #define CG(eax) (SH_CG(eax) || DH_CG(eax) || CH_CG(eax)) 27000Sstevel@tonic-gate 27010Sstevel@tonic-gate #define SH_D0(eax) (eax == 0x10f40 || eax == 0x10f50 || eax == 0x10f70) 27020Sstevel@tonic-gate #define DH_D0(eax) (eax == 0x10fc0 || eax == 0x10ff0) 27030Sstevel@tonic-gate #define CH_D0(eax) (eax == 0x10f80 || eax == 0x10fb0) 27041582Skchow #define D0(eax) (SH_D0(eax) || DH_D0(eax) || CH_D0(eax)) 27050Sstevel@tonic-gate 27060Sstevel@tonic-gate #define SH_E0(eax) (eax == 0x20f50 || eax == 0x20f40 || eax == 0x20f70) 27070Sstevel@tonic-gate #define JH_E1(eax) (eax == 0x20f10) /* JH8_E0 had 0x20f30 */ 27080Sstevel@tonic-gate #define DH_E3(eax) (eax == 0x20fc0 || eax == 0x20ff0) 27090Sstevel@tonic-gate #define SH_E4(eax) (eax == 0x20f51 || eax == 0x20f71) 27100Sstevel@tonic-gate #define BH_E4(eax) (eax == 0x20fb1) 27110Sstevel@tonic-gate #define SH_E5(eax) (eax == 0x20f42) 27120Sstevel@tonic-gate #define DH_E6(eax) (eax == 0x20ff2 || eax == 0x20fc2) 27130Sstevel@tonic-gate #define JH_E6(eax) (eax == 0x20f12 || eax == 0x20f32) 27141582Skchow #define EX(eax) (SH_E0(eax) || JH_E1(eax) || DH_E3(eax) || \ 27151582Skchow SH_E4(eax) || BH_E4(eax) || SH_E5(eax) || \ 27161582Skchow DH_E6(eax) || JH_E6(eax)) 27170Sstevel@tonic-gate 27186691Skchow #define DR_AX(eax) (eax == 0x100f00 || eax == 0x100f01 || eax == 0x100f02) 27196691Skchow #define DR_B0(eax) (eax == 0x100f20) 27206691Skchow #define DR_B1(eax) (eax == 0x100f21) 27216691Skchow #define DR_BA(eax) (eax == 0x100f2a) 27226691Skchow #define DR_B2(eax) (eax == 0x100f22) 27236691Skchow #define DR_B3(eax) (eax == 0x100f23) 27246691Skchow #define RB_C0(eax) (eax == 0x100f40) 27256691Skchow 27260Sstevel@tonic-gate switch (erratum) { 27270Sstevel@tonic-gate case 1: 27284265Skchow return (cpi->cpi_family < 0x10); 27290Sstevel@tonic-gate case 51: /* what does the asterisk mean? */ 27300Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax)); 27310Sstevel@tonic-gate case 52: 27320Sstevel@tonic-gate return (B(eax)); 27330Sstevel@tonic-gate case 57: 27346691Skchow return (cpi->cpi_family <= 0x11); 27350Sstevel@tonic-gate case 58: 27360Sstevel@tonic-gate return (B(eax)); 27370Sstevel@tonic-gate case 60: 27386691Skchow return (cpi->cpi_family <= 0x11); 27390Sstevel@tonic-gate case 61: 27400Sstevel@tonic-gate case 62: 27410Sstevel@tonic-gate case 63: 27420Sstevel@tonic-gate case 64: 27430Sstevel@tonic-gate case 65: 27440Sstevel@tonic-gate case 66: 27450Sstevel@tonic-gate case 68: 27460Sstevel@tonic-gate case 69: 27470Sstevel@tonic-gate case 70: 27480Sstevel@tonic-gate case 71: 27490Sstevel@tonic-gate return (B(eax)); 27500Sstevel@tonic-gate case 72: 27510Sstevel@tonic-gate return (SH_B0(eax)); 27520Sstevel@tonic-gate case 74: 27530Sstevel@tonic-gate return (B(eax)); 27540Sstevel@tonic-gate case 75: 27554265Skchow return (cpi->cpi_family < 0x10); 27560Sstevel@tonic-gate case 76: 27570Sstevel@tonic-gate return (B(eax)); 27580Sstevel@tonic-gate case 77: 27596691Skchow return (cpi->cpi_family <= 0x11); 27600Sstevel@tonic-gate case 78: 27610Sstevel@tonic-gate return (B(eax) || SH_C0(eax)); 27620Sstevel@tonic-gate case 79: 27630Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax) || EX(eax)); 27640Sstevel@tonic-gate case 80: 27650Sstevel@tonic-gate case 81: 27660Sstevel@tonic-gate case 82: 27670Sstevel@tonic-gate return (B(eax)); 27680Sstevel@tonic-gate case 83: 27690Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax)); 27700Sstevel@tonic-gate case 85: 27714265Skchow return (cpi->cpi_family < 0x10); 27720Sstevel@tonic-gate case 86: 27730Sstevel@tonic-gate return (SH_C0(eax) || CG(eax)); 27740Sstevel@tonic-gate case 88: 27750Sstevel@tonic-gate #if !defined(__amd64) 27760Sstevel@tonic-gate return (0); 27770Sstevel@tonic-gate #else 27780Sstevel@tonic-gate return (B(eax) || SH_C0(eax)); 27790Sstevel@tonic-gate #endif 27800Sstevel@tonic-gate case 89: 27814265Skchow return (cpi->cpi_family < 0x10); 27820Sstevel@tonic-gate case 90: 27830Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax)); 27840Sstevel@tonic-gate case 91: 27850Sstevel@tonic-gate case 92: 27860Sstevel@tonic-gate return (B(eax) || SH_C0(eax)); 27870Sstevel@tonic-gate case 93: 27880Sstevel@tonic-gate return (SH_C0(eax)); 27890Sstevel@tonic-gate case 94: 27900Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax)); 27910Sstevel@tonic-gate case 95: 27920Sstevel@tonic-gate #if !defined(__amd64) 27930Sstevel@tonic-gate return (0); 27940Sstevel@tonic-gate #else 27950Sstevel@tonic-gate return (B(eax) || SH_C0(eax)); 27960Sstevel@tonic-gate #endif 27970Sstevel@tonic-gate case 96: 27980Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax)); 27990Sstevel@tonic-gate case 97: 28000Sstevel@tonic-gate case 98: 28010Sstevel@tonic-gate return (SH_C0(eax) || CG(eax)); 28020Sstevel@tonic-gate case 99: 28030Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax)); 28040Sstevel@tonic-gate case 100: 28050Sstevel@tonic-gate return (B(eax) || SH_C0(eax)); 28060Sstevel@tonic-gate case 101: 28070Sstevel@tonic-gate case 103: 28080Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax)); 28090Sstevel@tonic-gate case 104: 28100Sstevel@tonic-gate return (SH_C0(eax) || CG(eax) || D0(eax)); 28110Sstevel@tonic-gate case 105: 28120Sstevel@tonic-gate case 106: 28130Sstevel@tonic-gate case 107: 28140Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax)); 28150Sstevel@tonic-gate case 108: 28160Sstevel@tonic-gate return (DH_CG(eax)); 28170Sstevel@tonic-gate case 109: 28180Sstevel@tonic-gate return (SH_C0(eax) || CG(eax) || D0(eax)); 28190Sstevel@tonic-gate case 110: 28200Sstevel@tonic-gate return (D0(eax) || EX(eax)); 28210Sstevel@tonic-gate case 111: 28220Sstevel@tonic-gate return (CG(eax)); 28230Sstevel@tonic-gate case 112: 28240Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax) || EX(eax)); 28250Sstevel@tonic-gate case 113: 28260Sstevel@tonic-gate return (eax == 0x20fc0); 28270Sstevel@tonic-gate case 114: 28280Sstevel@tonic-gate return (SH_E0(eax) || JH_E1(eax) || DH_E3(eax)); 28290Sstevel@tonic-gate case 115: 28300Sstevel@tonic-gate return (SH_E0(eax) || JH_E1(eax)); 28310Sstevel@tonic-gate case 116: 28320Sstevel@tonic-gate return (SH_E0(eax) || JH_E1(eax) || DH_E3(eax)); 28330Sstevel@tonic-gate case 117: 28340Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax)); 28350Sstevel@tonic-gate case 118: 28360Sstevel@tonic-gate return (SH_E0(eax) || JH_E1(eax) || SH_E4(eax) || BH_E4(eax) || 28370Sstevel@tonic-gate JH_E6(eax)); 28380Sstevel@tonic-gate case 121: 28390Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax) || EX(eax)); 28400Sstevel@tonic-gate case 122: 28416691Skchow return (cpi->cpi_family < 0x10 || cpi->cpi_family == 0x11); 28420Sstevel@tonic-gate case 123: 28430Sstevel@tonic-gate return (JH_E1(eax) || BH_E4(eax) || JH_E6(eax)); 2844359Skucharsk case 131: 28454265Skchow return (cpi->cpi_family < 0x10); 2846938Sesaxe case 6336786: 2847938Sesaxe /* 2848938Sesaxe * Test for AdvPowerMgmtInfo.TscPStateInvariant 28494265Skchow * if this is a K8 family or newer processor 2850938Sesaxe */ 2851938Sesaxe if (CPI_FAMILY(cpi) == 0xf) { 28521228Sandrei struct cpuid_regs regs; 28531228Sandrei regs.cp_eax = 0x80000007; 28541228Sandrei (void) __cpuid_insn(®s); 28551228Sandrei return (!(regs.cp_edx & 0x100)); 2856938Sesaxe } 2857938Sesaxe return (0); 28581582Skchow case 6323525: 28591582Skchow return (((((eax >> 12) & 0xff00) + (eax & 0xf00)) | 28601582Skchow (((eax >> 4) & 0xf) | ((eax >> 12) & 0xf0))) < 0xf40); 28611582Skchow 28626691Skchow case 6671130: 28636691Skchow /* 28646691Skchow * check for processors (pre-Shanghai) that do not provide 28656691Skchow * optimal management of 1gb ptes in its tlb. 28666691Skchow */ 28676691Skchow return (cpi->cpi_family == 0x10 && cpi->cpi_model < 4); 28686691Skchow 28696691Skchow case 298: 28706691Skchow return (DR_AX(eax) || DR_B0(eax) || DR_B1(eax) || DR_BA(eax) || 28716691Skchow DR_B2(eax) || RB_C0(eax)); 28726691Skchow 28736691Skchow default: 28746691Skchow return (-1); 28756691Skchow 28766691Skchow } 28776691Skchow } 28786691Skchow 28796691Skchow /* 28806691Skchow * Determine if specified erratum is present via OSVW (OS Visible Workaround). 28816691Skchow * Return 1 if erratum is present, 0 if not present and -1 if indeterminate. 28826691Skchow */ 28836691Skchow int 28846691Skchow osvw_opteron_erratum(cpu_t *cpu, uint_t erratum) 28856691Skchow { 28866691Skchow struct cpuid_info *cpi; 28876691Skchow uint_t osvwid; 28886691Skchow static int osvwfeature = -1; 28896691Skchow uint64_t osvwlength; 28906691Skchow 28916691Skchow 28926691Skchow cpi = cpu->cpu_m.mcpu_cpi; 28936691Skchow 28946691Skchow /* confirm OSVW supported */ 28956691Skchow if (osvwfeature == -1) { 28966691Skchow osvwfeature = cpi->cpi_extd[1].cp_ecx & CPUID_AMD_ECX_OSVW; 28976691Skchow } else { 28986691Skchow /* assert that osvw feature setting is consistent on all cpus */ 28996691Skchow ASSERT(osvwfeature == 29006691Skchow (cpi->cpi_extd[1].cp_ecx & CPUID_AMD_ECX_OSVW)); 29016691Skchow } 29026691Skchow if (!osvwfeature) 29036691Skchow return (-1); 29046691Skchow 29056691Skchow osvwlength = rdmsr(MSR_AMD_OSVW_ID_LEN) & OSVW_ID_LEN_MASK; 29066691Skchow 29076691Skchow switch (erratum) { 29086691Skchow case 298: /* osvwid is 0 */ 29096691Skchow osvwid = 0; 29106691Skchow if (osvwlength <= (uint64_t)osvwid) { 29116691Skchow /* osvwid 0 is unknown */ 29126691Skchow return (-1); 29136691Skchow } 29146691Skchow 29156691Skchow /* 29166691Skchow * Check the OSVW STATUS MSR to determine the state 29176691Skchow * of the erratum where: 29186691Skchow * 0 - fixed by HW 29196691Skchow * 1 - BIOS has applied the workaround when BIOS 29206691Skchow * workaround is available. (Or for other errata, 29216691Skchow * OS workaround is required.) 29226691Skchow * For a value of 1, caller will confirm that the 29236691Skchow * erratum 298 workaround has indeed been applied by BIOS. 29246691Skchow * 29256691Skchow * A 1 may be set in cpus that have a HW fix 29266691Skchow * in a mixed cpu system. Regarding erratum 298: 29276691Skchow * In a multiprocessor platform, the workaround above 29286691Skchow * should be applied to all processors regardless of 29296691Skchow * silicon revision when an affected processor is 29306691Skchow * present. 29316691Skchow */ 29326691Skchow 29336691Skchow return (rdmsr(MSR_AMD_OSVW_STATUS + 29346691Skchow (osvwid / OSVW_ID_CNT_PER_MSR)) & 29356691Skchow (1ULL << (osvwid % OSVW_ID_CNT_PER_MSR))); 29366691Skchow 29370Sstevel@tonic-gate default: 29380Sstevel@tonic-gate return (-1); 29390Sstevel@tonic-gate } 29400Sstevel@tonic-gate } 29410Sstevel@tonic-gate 29420Sstevel@tonic-gate static const char assoc_str[] = "associativity"; 29430Sstevel@tonic-gate static const char line_str[] = "line-size"; 29440Sstevel@tonic-gate static const char size_str[] = "size"; 29450Sstevel@tonic-gate 29460Sstevel@tonic-gate static void 29470Sstevel@tonic-gate add_cache_prop(dev_info_t *devi, const char *label, const char *type, 29480Sstevel@tonic-gate uint32_t val) 29490Sstevel@tonic-gate { 29500Sstevel@tonic-gate char buf[128]; 29510Sstevel@tonic-gate 29520Sstevel@tonic-gate /* 29530Sstevel@tonic-gate * ndi_prop_update_int() is used because it is desirable for 29540Sstevel@tonic-gate * DDI_PROP_HW_DEF and DDI_PROP_DONTSLEEP to be set. 29550Sstevel@tonic-gate */ 29560Sstevel@tonic-gate if (snprintf(buf, sizeof (buf), "%s-%s", label, type) < sizeof (buf)) 29570Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, devi, buf, val); 29580Sstevel@tonic-gate } 29590Sstevel@tonic-gate 29600Sstevel@tonic-gate /* 29610Sstevel@tonic-gate * Intel-style cache/tlb description 29620Sstevel@tonic-gate * 29630Sstevel@tonic-gate * Standard cpuid level 2 gives a randomly ordered 29640Sstevel@tonic-gate * selection of tags that index into a table that describes 29650Sstevel@tonic-gate * cache and tlb properties. 29660Sstevel@tonic-gate */ 29670Sstevel@tonic-gate 29680Sstevel@tonic-gate static const char l1_icache_str[] = "l1-icache"; 29690Sstevel@tonic-gate static const char l1_dcache_str[] = "l1-dcache"; 29700Sstevel@tonic-gate static const char l2_cache_str[] = "l2-cache"; 29713446Smrj static const char l3_cache_str[] = "l3-cache"; 29720Sstevel@tonic-gate static const char itlb4k_str[] = "itlb-4K"; 29730Sstevel@tonic-gate static const char dtlb4k_str[] = "dtlb-4K"; 29746964Svd224797 static const char itlb2M_str[] = "itlb-2M"; 29750Sstevel@tonic-gate static const char itlb4M_str[] = "itlb-4M"; 29760Sstevel@tonic-gate static const char dtlb4M_str[] = "dtlb-4M"; 29776334Sksadhukh static const char dtlb24_str[] = "dtlb0-2M-4M"; 29780Sstevel@tonic-gate static const char itlb424_str[] = "itlb-4K-2M-4M"; 29796334Sksadhukh static const char itlb24_str[] = "itlb-2M-4M"; 29800Sstevel@tonic-gate static const char dtlb44_str[] = "dtlb-4K-4M"; 29810Sstevel@tonic-gate static const char sl1_dcache_str[] = "sectored-l1-dcache"; 29820Sstevel@tonic-gate static const char sl2_cache_str[] = "sectored-l2-cache"; 29830Sstevel@tonic-gate static const char itrace_str[] = "itrace-cache"; 29840Sstevel@tonic-gate static const char sl3_cache_str[] = "sectored-l3-cache"; 29856334Sksadhukh static const char sh_l2_tlb4k_str[] = "shared-l2-tlb-4k"; 29860Sstevel@tonic-gate 29870Sstevel@tonic-gate static const struct cachetab { 29880Sstevel@tonic-gate uint8_t ct_code; 29890Sstevel@tonic-gate uint8_t ct_assoc; 29900Sstevel@tonic-gate uint16_t ct_line_size; 29910Sstevel@tonic-gate size_t ct_size; 29920Sstevel@tonic-gate const char *ct_label; 29930Sstevel@tonic-gate } intel_ctab[] = { 29946964Svd224797 /* 29956964Svd224797 * maintain descending order! 29966964Svd224797 * 29976964Svd224797 * Codes ignored - Reason 29986964Svd224797 * ---------------------- 29996964Svd224797 * 40H - intel_cpuid_4_cache_info() disambiguates l2/l3 cache 30006964Svd224797 * f0H/f1H - Currently we do not interpret prefetch size by design 30016964Svd224797 */ 30026334Sksadhukh { 0xe4, 16, 64, 8*1024*1024, l3_cache_str}, 30036334Sksadhukh { 0xe3, 16, 64, 4*1024*1024, l3_cache_str}, 30046334Sksadhukh { 0xe2, 16, 64, 2*1024*1024, l3_cache_str}, 30056334Sksadhukh { 0xde, 12, 64, 6*1024*1024, l3_cache_str}, 30066334Sksadhukh { 0xdd, 12, 64, 3*1024*1024, l3_cache_str}, 30076334Sksadhukh { 0xdc, 12, 64, ((1*1024*1024)+(512*1024)), l3_cache_str}, 30086334Sksadhukh { 0xd8, 8, 64, 4*1024*1024, l3_cache_str}, 30096334Sksadhukh { 0xd7, 8, 64, 2*1024*1024, l3_cache_str}, 30106334Sksadhukh { 0xd6, 8, 64, 1*1024*1024, l3_cache_str}, 30116334Sksadhukh { 0xd2, 4, 64, 2*1024*1024, l3_cache_str}, 30126334Sksadhukh { 0xd1, 4, 64, 1*1024*1024, l3_cache_str}, 30136334Sksadhukh { 0xd0, 4, 64, 512*1024, l3_cache_str}, 30146334Sksadhukh { 0xca, 4, 0, 512, sh_l2_tlb4k_str}, 30156964Svd224797 { 0xc0, 4, 0, 8, dtlb44_str }, 30166964Svd224797 { 0xba, 4, 0, 64, dtlb4k_str }, 30173446Smrj { 0xb4, 4, 0, 256, dtlb4k_str }, 30180Sstevel@tonic-gate { 0xb3, 4, 0, 128, dtlb4k_str }, 30196334Sksadhukh { 0xb2, 4, 0, 64, itlb4k_str }, 30200Sstevel@tonic-gate { 0xb0, 4, 0, 128, itlb4k_str }, 30210Sstevel@tonic-gate { 0x87, 8, 64, 1024*1024, l2_cache_str}, 30220Sstevel@tonic-gate { 0x86, 4, 64, 512*1024, l2_cache_str}, 30230Sstevel@tonic-gate { 0x85, 8, 32, 2*1024*1024, l2_cache_str}, 30240Sstevel@tonic-gate { 0x84, 8, 32, 1024*1024, l2_cache_str}, 30250Sstevel@tonic-gate { 0x83, 8, 32, 512*1024, l2_cache_str}, 30260Sstevel@tonic-gate { 0x82, 8, 32, 256*1024, l2_cache_str}, 30276964Svd224797 { 0x80, 8, 64, 512*1024, l2_cache_str}, 30280Sstevel@tonic-gate { 0x7f, 2, 64, 512*1024, l2_cache_str}, 30290Sstevel@tonic-gate { 0x7d, 8, 64, 2*1024*1024, sl2_cache_str}, 30300Sstevel@tonic-gate { 0x7c, 8, 64, 1024*1024, sl2_cache_str}, 30310Sstevel@tonic-gate { 0x7b, 8, 64, 512*1024, sl2_cache_str}, 30320Sstevel@tonic-gate { 0x7a, 8, 64, 256*1024, sl2_cache_str}, 30330Sstevel@tonic-gate { 0x79, 8, 64, 128*1024, sl2_cache_str}, 30340Sstevel@tonic-gate { 0x78, 8, 64, 1024*1024, l2_cache_str}, 30353446Smrj { 0x73, 8, 0, 64*1024, itrace_str}, 30360Sstevel@tonic-gate { 0x72, 8, 0, 32*1024, itrace_str}, 30370Sstevel@tonic-gate { 0x71, 8, 0, 16*1024, itrace_str}, 30380Sstevel@tonic-gate { 0x70, 8, 0, 12*1024, itrace_str}, 30390Sstevel@tonic-gate { 0x68, 4, 64, 32*1024, sl1_dcache_str}, 30400Sstevel@tonic-gate { 0x67, 4, 64, 16*1024, sl1_dcache_str}, 30410Sstevel@tonic-gate { 0x66, 4, 64, 8*1024, sl1_dcache_str}, 30420Sstevel@tonic-gate { 0x60, 8, 64, 16*1024, sl1_dcache_str}, 30430Sstevel@tonic-gate { 0x5d, 0, 0, 256, dtlb44_str}, 30440Sstevel@tonic-gate { 0x5c, 0, 0, 128, dtlb44_str}, 30450Sstevel@tonic-gate { 0x5b, 0, 0, 64, dtlb44_str}, 30466334Sksadhukh { 0x5a, 4, 0, 32, dtlb24_str}, 30476964Svd224797 { 0x59, 0, 0, 16, dtlb4k_str}, 30486964Svd224797 { 0x57, 4, 0, 16, dtlb4k_str}, 30496964Svd224797 { 0x56, 4, 0, 16, dtlb4M_str}, 30506334Sksadhukh { 0x55, 0, 0, 7, itlb24_str}, 30510Sstevel@tonic-gate { 0x52, 0, 0, 256, itlb424_str}, 30520Sstevel@tonic-gate { 0x51, 0, 0, 128, itlb424_str}, 30530Sstevel@tonic-gate { 0x50, 0, 0, 64, itlb424_str}, 30546964Svd224797 { 0x4f, 0, 0, 32, itlb4k_str}, 30556964Svd224797 { 0x4e, 24, 64, 6*1024*1024, l2_cache_str}, 30563446Smrj { 0x4d, 16, 64, 16*1024*1024, l3_cache_str}, 30573446Smrj { 0x4c, 12, 64, 12*1024*1024, l3_cache_str}, 30583446Smrj { 0x4b, 16, 64, 8*1024*1024, l3_cache_str}, 30593446Smrj { 0x4a, 12, 64, 6*1024*1024, l3_cache_str}, 30603446Smrj { 0x49, 16, 64, 4*1024*1024, l3_cache_str}, 30616964Svd224797 { 0x48, 12, 64, 3*1024*1024, l2_cache_str}, 30623446Smrj { 0x47, 8, 64, 8*1024*1024, l3_cache_str}, 30633446Smrj { 0x46, 4, 64, 4*1024*1024, l3_cache_str}, 30640Sstevel@tonic-gate { 0x45, 4, 32, 2*1024*1024, l2_cache_str}, 30650Sstevel@tonic-gate { 0x44, 4, 32, 1024*1024, l2_cache_str}, 30660Sstevel@tonic-gate { 0x43, 4, 32, 512*1024, l2_cache_str}, 30670Sstevel@tonic-gate { 0x42, 4, 32, 256*1024, l2_cache_str}, 30680Sstevel@tonic-gate { 0x41, 4, 32, 128*1024, l2_cache_str}, 30693446Smrj { 0x3e, 4, 64, 512*1024, sl2_cache_str}, 30703446Smrj { 0x3d, 6, 64, 384*1024, sl2_cache_str}, 30710Sstevel@tonic-gate { 0x3c, 4, 64, 256*1024, sl2_cache_str}, 30720Sstevel@tonic-gate { 0x3b, 2, 64, 128*1024, sl2_cache_str}, 30733446Smrj { 0x3a, 6, 64, 192*1024, sl2_cache_str}, 30740Sstevel@tonic-gate { 0x39, 4, 64, 128*1024, sl2_cache_str}, 30750Sstevel@tonic-gate { 0x30, 8, 64, 32*1024, l1_icache_str}, 30760Sstevel@tonic-gate { 0x2c, 8, 64, 32*1024, l1_dcache_str}, 30770Sstevel@tonic-gate { 0x29, 8, 64, 4096*1024, sl3_cache_str}, 30780Sstevel@tonic-gate { 0x25, 8, 64, 2048*1024, sl3_cache_str}, 30790Sstevel@tonic-gate { 0x23, 8, 64, 1024*1024, sl3_cache_str}, 30800Sstevel@tonic-gate { 0x22, 4, 64, 512*1024, sl3_cache_str}, 30816964Svd224797 { 0x0e, 6, 64, 24*1024, l1_dcache_str}, 30826334Sksadhukh { 0x0d, 4, 32, 16*1024, l1_dcache_str}, 30830Sstevel@tonic-gate { 0x0c, 4, 32, 16*1024, l1_dcache_str}, 30843446Smrj { 0x0b, 4, 0, 4, itlb4M_str}, 30850Sstevel@tonic-gate { 0x0a, 2, 32, 8*1024, l1_dcache_str}, 30860Sstevel@tonic-gate { 0x08, 4, 32, 16*1024, l1_icache_str}, 30870Sstevel@tonic-gate { 0x06, 4, 32, 8*1024, l1_icache_str}, 30886964Svd224797 { 0x05, 4, 0, 32, dtlb4M_str}, 30890Sstevel@tonic-gate { 0x04, 4, 0, 8, dtlb4M_str}, 30900Sstevel@tonic-gate { 0x03, 4, 0, 64, dtlb4k_str}, 30910Sstevel@tonic-gate { 0x02, 4, 0, 2, itlb4M_str}, 30920Sstevel@tonic-gate { 0x01, 4, 0, 32, itlb4k_str}, 30930Sstevel@tonic-gate { 0 } 30940Sstevel@tonic-gate }; 30950Sstevel@tonic-gate 30960Sstevel@tonic-gate static const struct cachetab cyrix_ctab[] = { 30970Sstevel@tonic-gate { 0x70, 4, 0, 32, "tlb-4K" }, 30980Sstevel@tonic-gate { 0x80, 4, 16, 16*1024, "l1-cache" }, 30990Sstevel@tonic-gate { 0 } 31000Sstevel@tonic-gate }; 31010Sstevel@tonic-gate 31020Sstevel@tonic-gate /* 31030Sstevel@tonic-gate * Search a cache table for a matching entry 31040Sstevel@tonic-gate */ 31050Sstevel@tonic-gate static const struct cachetab * 31060Sstevel@tonic-gate find_cacheent(const struct cachetab *ct, uint_t code) 31070Sstevel@tonic-gate { 31080Sstevel@tonic-gate if (code != 0) { 31090Sstevel@tonic-gate for (; ct->ct_code != 0; ct++) 31100Sstevel@tonic-gate if (ct->ct_code <= code) 31110Sstevel@tonic-gate break; 31120Sstevel@tonic-gate if (ct->ct_code == code) 31130Sstevel@tonic-gate return (ct); 31140Sstevel@tonic-gate } 31150Sstevel@tonic-gate return (NULL); 31160Sstevel@tonic-gate } 31170Sstevel@tonic-gate 31180Sstevel@tonic-gate /* 31195438Sksadhukh * Populate cachetab entry with L2 or L3 cache-information using 31205438Sksadhukh * cpuid function 4. This function is called from intel_walk_cacheinfo() 31215438Sksadhukh * when descriptor 0x49 is encountered. It returns 0 if no such cache 31225438Sksadhukh * information is found. 31235438Sksadhukh */ 31245438Sksadhukh static int 31255438Sksadhukh intel_cpuid_4_cache_info(struct cachetab *ct, struct cpuid_info *cpi) 31265438Sksadhukh { 31275438Sksadhukh uint32_t level, i; 31285438Sksadhukh int ret = 0; 31295438Sksadhukh 31305438Sksadhukh for (i = 0; i < cpi->cpi_std_4_size; i++) { 31315438Sksadhukh level = CPI_CACHE_LVL(cpi->cpi_std_4[i]); 31325438Sksadhukh 31335438Sksadhukh if (level == 2 || level == 3) { 31345438Sksadhukh ct->ct_assoc = CPI_CACHE_WAYS(cpi->cpi_std_4[i]) + 1; 31355438Sksadhukh ct->ct_line_size = 31365438Sksadhukh CPI_CACHE_COH_LN_SZ(cpi->cpi_std_4[i]) + 1; 31375438Sksadhukh ct->ct_size = ct->ct_assoc * 31385438Sksadhukh (CPI_CACHE_PARTS(cpi->cpi_std_4[i]) + 1) * 31395438Sksadhukh ct->ct_line_size * 31405438Sksadhukh (cpi->cpi_std_4[i]->cp_ecx + 1); 31415438Sksadhukh 31425438Sksadhukh if (level == 2) { 31435438Sksadhukh ct->ct_label = l2_cache_str; 31445438Sksadhukh } else if (level == 3) { 31455438Sksadhukh ct->ct_label = l3_cache_str; 31465438Sksadhukh } 31475438Sksadhukh ret = 1; 31485438Sksadhukh } 31495438Sksadhukh } 31505438Sksadhukh 31515438Sksadhukh return (ret); 31525438Sksadhukh } 31535438Sksadhukh 31545438Sksadhukh /* 31550Sstevel@tonic-gate * Walk the cacheinfo descriptor, applying 'func' to every valid element 31560Sstevel@tonic-gate * The walk is terminated if the walker returns non-zero. 31570Sstevel@tonic-gate */ 31580Sstevel@tonic-gate static void 31590Sstevel@tonic-gate intel_walk_cacheinfo(struct cpuid_info *cpi, 31600Sstevel@tonic-gate void *arg, int (*func)(void *, const struct cachetab *)) 31610Sstevel@tonic-gate { 31620Sstevel@tonic-gate const struct cachetab *ct; 31636964Svd224797 struct cachetab des_49_ct, des_b1_ct; 31640Sstevel@tonic-gate uint8_t *dp; 31650Sstevel@tonic-gate int i; 31660Sstevel@tonic-gate 31670Sstevel@tonic-gate if ((dp = cpi->cpi_cacheinfo) == NULL) 31680Sstevel@tonic-gate return; 31694797Sksadhukh for (i = 0; i < cpi->cpi_ncache; i++, dp++) { 31704797Sksadhukh /* 31714797Sksadhukh * For overloaded descriptor 0x49 we use cpuid function 4 31725438Sksadhukh * if supported by the current processor, to create 31734797Sksadhukh * cache information. 31746964Svd224797 * For overloaded descriptor 0xb1 we use X86_PAE flag 31756964Svd224797 * to disambiguate the cache information. 31764797Sksadhukh */ 31775438Sksadhukh if (*dp == 0x49 && cpi->cpi_maxeax >= 0x4 && 31785438Sksadhukh intel_cpuid_4_cache_info(&des_49_ct, cpi) == 1) { 31795438Sksadhukh ct = &des_49_ct; 31806964Svd224797 } else if (*dp == 0xb1) { 31816964Svd224797 des_b1_ct.ct_code = 0xb1; 31826964Svd224797 des_b1_ct.ct_assoc = 4; 31836964Svd224797 des_b1_ct.ct_line_size = 0; 31846964Svd224797 if (x86_feature & X86_PAE) { 31856964Svd224797 des_b1_ct.ct_size = 8; 31866964Svd224797 des_b1_ct.ct_label = itlb2M_str; 31876964Svd224797 } else { 31886964Svd224797 des_b1_ct.ct_size = 4; 31896964Svd224797 des_b1_ct.ct_label = itlb4M_str; 31906964Svd224797 } 31916964Svd224797 ct = &des_b1_ct; 31925438Sksadhukh } else { 31935438Sksadhukh if ((ct = find_cacheent(intel_ctab, *dp)) == NULL) { 31945438Sksadhukh continue; 31955438Sksadhukh } 31964797Sksadhukh } 31974797Sksadhukh 31985438Sksadhukh if (func(arg, ct) != 0) { 31995438Sksadhukh break; 32000Sstevel@tonic-gate } 32014797Sksadhukh } 32020Sstevel@tonic-gate } 32030Sstevel@tonic-gate 32040Sstevel@tonic-gate /* 32050Sstevel@tonic-gate * (Like the Intel one, except for Cyrix CPUs) 32060Sstevel@tonic-gate */ 32070Sstevel@tonic-gate static void 32080Sstevel@tonic-gate cyrix_walk_cacheinfo(struct cpuid_info *cpi, 32090Sstevel@tonic-gate void *arg, int (*func)(void *, const struct cachetab *)) 32100Sstevel@tonic-gate { 32110Sstevel@tonic-gate const struct cachetab *ct; 32120Sstevel@tonic-gate uint8_t *dp; 32130Sstevel@tonic-gate int i; 32140Sstevel@tonic-gate 32150Sstevel@tonic-gate if ((dp = cpi->cpi_cacheinfo) == NULL) 32160Sstevel@tonic-gate return; 32170Sstevel@tonic-gate for (i = 0; i < cpi->cpi_ncache; i++, dp++) { 32180Sstevel@tonic-gate /* 32190Sstevel@tonic-gate * Search Cyrix-specific descriptor table first .. 32200Sstevel@tonic-gate */ 32210Sstevel@tonic-gate if ((ct = find_cacheent(cyrix_ctab, *dp)) != NULL) { 32220Sstevel@tonic-gate if (func(arg, ct) != 0) 32230Sstevel@tonic-gate break; 32240Sstevel@tonic-gate continue; 32250Sstevel@tonic-gate } 32260Sstevel@tonic-gate /* 32270Sstevel@tonic-gate * .. else fall back to the Intel one 32280Sstevel@tonic-gate */ 32290Sstevel@tonic-gate if ((ct = find_cacheent(intel_ctab, *dp)) != NULL) { 32300Sstevel@tonic-gate if (func(arg, ct) != 0) 32310Sstevel@tonic-gate break; 32320Sstevel@tonic-gate continue; 32330Sstevel@tonic-gate } 32340Sstevel@tonic-gate } 32350Sstevel@tonic-gate } 32360Sstevel@tonic-gate 32370Sstevel@tonic-gate /* 32380Sstevel@tonic-gate * A cacheinfo walker that adds associativity, line-size, and size properties 32390Sstevel@tonic-gate * to the devinfo node it is passed as an argument. 32400Sstevel@tonic-gate */ 32410Sstevel@tonic-gate static int 32420Sstevel@tonic-gate add_cacheent_props(void *arg, const struct cachetab *ct) 32430Sstevel@tonic-gate { 32440Sstevel@tonic-gate dev_info_t *devi = arg; 32450Sstevel@tonic-gate 32460Sstevel@tonic-gate add_cache_prop(devi, ct->ct_label, assoc_str, ct->ct_assoc); 32470Sstevel@tonic-gate if (ct->ct_line_size != 0) 32480Sstevel@tonic-gate add_cache_prop(devi, ct->ct_label, line_str, 32490Sstevel@tonic-gate ct->ct_line_size); 32500Sstevel@tonic-gate add_cache_prop(devi, ct->ct_label, size_str, ct->ct_size); 32510Sstevel@tonic-gate return (0); 32520Sstevel@tonic-gate } 32530Sstevel@tonic-gate 32544797Sksadhukh 32550Sstevel@tonic-gate static const char fully_assoc[] = "fully-associative?"; 32560Sstevel@tonic-gate 32570Sstevel@tonic-gate /* 32580Sstevel@tonic-gate * AMD style cache/tlb description 32590Sstevel@tonic-gate * 32600Sstevel@tonic-gate * Extended functions 5 and 6 directly describe properties of 32610Sstevel@tonic-gate * tlbs and various cache levels. 32620Sstevel@tonic-gate */ 32630Sstevel@tonic-gate static void 32640Sstevel@tonic-gate add_amd_assoc(dev_info_t *devi, const char *label, uint_t assoc) 32650Sstevel@tonic-gate { 32660Sstevel@tonic-gate switch (assoc) { 32670Sstevel@tonic-gate case 0: /* reserved; ignore */ 32680Sstevel@tonic-gate break; 32690Sstevel@tonic-gate default: 32700Sstevel@tonic-gate add_cache_prop(devi, label, assoc_str, assoc); 32710Sstevel@tonic-gate break; 32720Sstevel@tonic-gate case 0xff: 32730Sstevel@tonic-gate add_cache_prop(devi, label, fully_assoc, 1); 32740Sstevel@tonic-gate break; 32750Sstevel@tonic-gate } 32760Sstevel@tonic-gate } 32770Sstevel@tonic-gate 32780Sstevel@tonic-gate static void 32790Sstevel@tonic-gate add_amd_tlb(dev_info_t *devi, const char *label, uint_t assoc, uint_t size) 32800Sstevel@tonic-gate { 32810Sstevel@tonic-gate if (size == 0) 32820Sstevel@tonic-gate return; 32830Sstevel@tonic-gate add_cache_prop(devi, label, size_str, size); 32840Sstevel@tonic-gate add_amd_assoc(devi, label, assoc); 32850Sstevel@tonic-gate } 32860Sstevel@tonic-gate 32870Sstevel@tonic-gate static void 32880Sstevel@tonic-gate add_amd_cache(dev_info_t *devi, const char *label, 32890Sstevel@tonic-gate uint_t size, uint_t assoc, uint_t lines_per_tag, uint_t line_size) 32900Sstevel@tonic-gate { 32910Sstevel@tonic-gate if (size == 0 || line_size == 0) 32920Sstevel@tonic-gate return; 32930Sstevel@tonic-gate add_amd_assoc(devi, label, assoc); 32940Sstevel@tonic-gate /* 32950Sstevel@tonic-gate * Most AMD parts have a sectored cache. Multiple cache lines are 32960Sstevel@tonic-gate * associated with each tag. A sector consists of all cache lines 32970Sstevel@tonic-gate * associated with a tag. For example, the AMD K6-III has a sector 32980Sstevel@tonic-gate * size of 2 cache lines per tag. 32990Sstevel@tonic-gate */ 33000Sstevel@tonic-gate if (lines_per_tag != 0) 33010Sstevel@tonic-gate add_cache_prop(devi, label, "lines-per-tag", lines_per_tag); 33020Sstevel@tonic-gate add_cache_prop(devi, label, line_str, line_size); 33030Sstevel@tonic-gate add_cache_prop(devi, label, size_str, size * 1024); 33040Sstevel@tonic-gate } 33050Sstevel@tonic-gate 33060Sstevel@tonic-gate static void 33070Sstevel@tonic-gate add_amd_l2_assoc(dev_info_t *devi, const char *label, uint_t assoc) 33080Sstevel@tonic-gate { 33090Sstevel@tonic-gate switch (assoc) { 33100Sstevel@tonic-gate case 0: /* off */ 33110Sstevel@tonic-gate break; 33120Sstevel@tonic-gate case 1: 33130Sstevel@tonic-gate case 2: 33140Sstevel@tonic-gate case 4: 33150Sstevel@tonic-gate add_cache_prop(devi, label, assoc_str, assoc); 33160Sstevel@tonic-gate break; 33170Sstevel@tonic-gate case 6: 33180Sstevel@tonic-gate add_cache_prop(devi, label, assoc_str, 8); 33190Sstevel@tonic-gate break; 33200Sstevel@tonic-gate case 8: 33210Sstevel@tonic-gate add_cache_prop(devi, label, assoc_str, 16); 33220Sstevel@tonic-gate break; 33230Sstevel@tonic-gate case 0xf: 33240Sstevel@tonic-gate add_cache_prop(devi, label, fully_assoc, 1); 33250Sstevel@tonic-gate break; 33260Sstevel@tonic-gate default: /* reserved; ignore */ 33270Sstevel@tonic-gate break; 33280Sstevel@tonic-gate } 33290Sstevel@tonic-gate } 33300Sstevel@tonic-gate 33310Sstevel@tonic-gate static void 33320Sstevel@tonic-gate add_amd_l2_tlb(dev_info_t *devi, const char *label, uint_t assoc, uint_t size) 33330Sstevel@tonic-gate { 33340Sstevel@tonic-gate if (size == 0 || assoc == 0) 33350Sstevel@tonic-gate return; 33360Sstevel@tonic-gate add_amd_l2_assoc(devi, label, assoc); 33370Sstevel@tonic-gate add_cache_prop(devi, label, size_str, size); 33380Sstevel@tonic-gate } 33390Sstevel@tonic-gate 33400Sstevel@tonic-gate static void 33410Sstevel@tonic-gate add_amd_l2_cache(dev_info_t *devi, const char *label, 33420Sstevel@tonic-gate uint_t size, uint_t assoc, uint_t lines_per_tag, uint_t line_size) 33430Sstevel@tonic-gate { 33440Sstevel@tonic-gate if (size == 0 || assoc == 0 || line_size == 0) 33450Sstevel@tonic-gate return; 33460Sstevel@tonic-gate add_amd_l2_assoc(devi, label, assoc); 33470Sstevel@tonic-gate if (lines_per_tag != 0) 33480Sstevel@tonic-gate add_cache_prop(devi, label, "lines-per-tag", lines_per_tag); 33490Sstevel@tonic-gate add_cache_prop(devi, label, line_str, line_size); 33500Sstevel@tonic-gate add_cache_prop(devi, label, size_str, size * 1024); 33510Sstevel@tonic-gate } 33520Sstevel@tonic-gate 33530Sstevel@tonic-gate static void 33540Sstevel@tonic-gate amd_cache_info(struct cpuid_info *cpi, dev_info_t *devi) 33550Sstevel@tonic-gate { 33561228Sandrei struct cpuid_regs *cp; 33570Sstevel@tonic-gate 33580Sstevel@tonic-gate if (cpi->cpi_xmaxeax < 0x80000005) 33590Sstevel@tonic-gate return; 33600Sstevel@tonic-gate cp = &cpi->cpi_extd[5]; 33610Sstevel@tonic-gate 33620Sstevel@tonic-gate /* 33630Sstevel@tonic-gate * 4M/2M L1 TLB configuration 33640Sstevel@tonic-gate * 33650Sstevel@tonic-gate * We report the size for 2M pages because AMD uses two 33660Sstevel@tonic-gate * TLB entries for one 4M page. 33670Sstevel@tonic-gate */ 33680Sstevel@tonic-gate add_amd_tlb(devi, "dtlb-2M", 33690Sstevel@tonic-gate BITX(cp->cp_eax, 31, 24), BITX(cp->cp_eax, 23, 16)); 33700Sstevel@tonic-gate add_amd_tlb(devi, "itlb-2M", 33710Sstevel@tonic-gate BITX(cp->cp_eax, 15, 8), BITX(cp->cp_eax, 7, 0)); 33720Sstevel@tonic-gate 33730Sstevel@tonic-gate /* 33740Sstevel@tonic-gate * 4K L1 TLB configuration 33750Sstevel@tonic-gate */ 33760Sstevel@tonic-gate 33770Sstevel@tonic-gate switch (cpi->cpi_vendor) { 33780Sstevel@tonic-gate uint_t nentries; 33790Sstevel@tonic-gate case X86_VENDOR_TM: 33800Sstevel@tonic-gate if (cpi->cpi_family >= 5) { 33810Sstevel@tonic-gate /* 33820Sstevel@tonic-gate * Crusoe processors have 256 TLB entries, but 33830Sstevel@tonic-gate * cpuid data format constrains them to only 33840Sstevel@tonic-gate * reporting 255 of them. 33850Sstevel@tonic-gate */ 33860Sstevel@tonic-gate if ((nentries = BITX(cp->cp_ebx, 23, 16)) == 255) 33870Sstevel@tonic-gate nentries = 256; 33880Sstevel@tonic-gate /* 33890Sstevel@tonic-gate * Crusoe processors also have a unified TLB 33900Sstevel@tonic-gate */ 33910Sstevel@tonic-gate add_amd_tlb(devi, "tlb-4K", BITX(cp->cp_ebx, 31, 24), 33920Sstevel@tonic-gate nentries); 33930Sstevel@tonic-gate break; 33940Sstevel@tonic-gate } 33950Sstevel@tonic-gate /*FALLTHROUGH*/ 33960Sstevel@tonic-gate default: 33970Sstevel@tonic-gate add_amd_tlb(devi, itlb4k_str, 33980Sstevel@tonic-gate BITX(cp->cp_ebx, 31, 24), BITX(cp->cp_ebx, 23, 16)); 33990Sstevel@tonic-gate add_amd_tlb(devi, dtlb4k_str, 34000Sstevel@tonic-gate BITX(cp->cp_ebx, 15, 8), BITX(cp->cp_ebx, 7, 0)); 34010Sstevel@tonic-gate break; 34020Sstevel@tonic-gate } 34030Sstevel@tonic-gate 34040Sstevel@tonic-gate /* 34050Sstevel@tonic-gate * data L1 cache configuration 34060Sstevel@tonic-gate */ 34070Sstevel@tonic-gate 34080Sstevel@tonic-gate add_amd_cache(devi, l1_dcache_str, 34090Sstevel@tonic-gate BITX(cp->cp_ecx, 31, 24), BITX(cp->cp_ecx, 23, 16), 34100Sstevel@tonic-gate BITX(cp->cp_ecx, 15, 8), BITX(cp->cp_ecx, 7, 0)); 34110Sstevel@tonic-gate 34120Sstevel@tonic-gate /* 34130Sstevel@tonic-gate * code L1 cache configuration 34140Sstevel@tonic-gate */ 34150Sstevel@tonic-gate 34160Sstevel@tonic-gate add_amd_cache(devi, l1_icache_str, 34170Sstevel@tonic-gate BITX(cp->cp_edx, 31, 24), BITX(cp->cp_edx, 23, 16), 34180Sstevel@tonic-gate BITX(cp->cp_edx, 15, 8), BITX(cp->cp_edx, 7, 0)); 34190Sstevel@tonic-gate 34200Sstevel@tonic-gate if (cpi->cpi_xmaxeax < 0x80000006) 34210Sstevel@tonic-gate return; 34220Sstevel@tonic-gate cp = &cpi->cpi_extd[6]; 34230Sstevel@tonic-gate 34240Sstevel@tonic-gate /* Check for a unified L2 TLB for large pages */ 34250Sstevel@tonic-gate 34260Sstevel@tonic-gate if (BITX(cp->cp_eax, 31, 16) == 0) 34270Sstevel@tonic-gate add_amd_l2_tlb(devi, "l2-tlb-2M", 34280Sstevel@tonic-gate BITX(cp->cp_eax, 15, 12), BITX(cp->cp_eax, 11, 0)); 34290Sstevel@tonic-gate else { 34300Sstevel@tonic-gate add_amd_l2_tlb(devi, "l2-dtlb-2M", 34310Sstevel@tonic-gate BITX(cp->cp_eax, 31, 28), BITX(cp->cp_eax, 27, 16)); 34320Sstevel@tonic-gate add_amd_l2_tlb(devi, "l2-itlb-2M", 34330Sstevel@tonic-gate BITX(cp->cp_eax, 15, 12), BITX(cp->cp_eax, 11, 0)); 34340Sstevel@tonic-gate } 34350Sstevel@tonic-gate 34360Sstevel@tonic-gate /* Check for a unified L2 TLB for 4K pages */ 34370Sstevel@tonic-gate 34380Sstevel@tonic-gate if (BITX(cp->cp_ebx, 31, 16) == 0) { 34390Sstevel@tonic-gate add_amd_l2_tlb(devi, "l2-tlb-4K", 34400Sstevel@tonic-gate BITX(cp->cp_eax, 15, 12), BITX(cp->cp_eax, 11, 0)); 34410Sstevel@tonic-gate } else { 34420Sstevel@tonic-gate add_amd_l2_tlb(devi, "l2-dtlb-4K", 34430Sstevel@tonic-gate BITX(cp->cp_eax, 31, 28), BITX(cp->cp_eax, 27, 16)); 34440Sstevel@tonic-gate add_amd_l2_tlb(devi, "l2-itlb-4K", 34450Sstevel@tonic-gate BITX(cp->cp_eax, 15, 12), BITX(cp->cp_eax, 11, 0)); 34460Sstevel@tonic-gate } 34470Sstevel@tonic-gate 34480Sstevel@tonic-gate add_amd_l2_cache(devi, l2_cache_str, 34490Sstevel@tonic-gate BITX(cp->cp_ecx, 31, 16), BITX(cp->cp_ecx, 15, 12), 34500Sstevel@tonic-gate BITX(cp->cp_ecx, 11, 8), BITX(cp->cp_ecx, 7, 0)); 34510Sstevel@tonic-gate } 34520Sstevel@tonic-gate 34530Sstevel@tonic-gate /* 34540Sstevel@tonic-gate * There are two basic ways that the x86 world describes it cache 34550Sstevel@tonic-gate * and tlb architecture - Intel's way and AMD's way. 34560Sstevel@tonic-gate * 34570Sstevel@tonic-gate * Return which flavor of cache architecture we should use 34580Sstevel@tonic-gate */ 34590Sstevel@tonic-gate static int 34600Sstevel@tonic-gate x86_which_cacheinfo(struct cpuid_info *cpi) 34610Sstevel@tonic-gate { 34620Sstevel@tonic-gate switch (cpi->cpi_vendor) { 34630Sstevel@tonic-gate case X86_VENDOR_Intel: 34640Sstevel@tonic-gate if (cpi->cpi_maxeax >= 2) 34650Sstevel@tonic-gate return (X86_VENDOR_Intel); 34660Sstevel@tonic-gate break; 34670Sstevel@tonic-gate case X86_VENDOR_AMD: 34680Sstevel@tonic-gate /* 34690Sstevel@tonic-gate * The K5 model 1 was the first part from AMD that reported 34700Sstevel@tonic-gate * cache sizes via extended cpuid functions. 34710Sstevel@tonic-gate */ 34720Sstevel@tonic-gate if (cpi->cpi_family > 5 || 34730Sstevel@tonic-gate (cpi->cpi_family == 5 && cpi->cpi_model >= 1)) 34740Sstevel@tonic-gate return (X86_VENDOR_AMD); 34750Sstevel@tonic-gate break; 34760Sstevel@tonic-gate case X86_VENDOR_TM: 34770Sstevel@tonic-gate if (cpi->cpi_family >= 5) 34780Sstevel@tonic-gate return (X86_VENDOR_AMD); 34790Sstevel@tonic-gate /*FALLTHROUGH*/ 34800Sstevel@tonic-gate default: 34810Sstevel@tonic-gate /* 34820Sstevel@tonic-gate * If they have extended CPU data for 0x80000005 34830Sstevel@tonic-gate * then we assume they have AMD-format cache 34840Sstevel@tonic-gate * information. 34850Sstevel@tonic-gate * 34860Sstevel@tonic-gate * If not, and the vendor happens to be Cyrix, 34870Sstevel@tonic-gate * then try our-Cyrix specific handler. 34880Sstevel@tonic-gate * 34890Sstevel@tonic-gate * If we're not Cyrix, then assume we're using Intel's 34900Sstevel@tonic-gate * table-driven format instead. 34910Sstevel@tonic-gate */ 34920Sstevel@tonic-gate if (cpi->cpi_xmaxeax >= 0x80000005) 34930Sstevel@tonic-gate return (X86_VENDOR_AMD); 34940Sstevel@tonic-gate else if (cpi->cpi_vendor == X86_VENDOR_Cyrix) 34950Sstevel@tonic-gate return (X86_VENDOR_Cyrix); 34960Sstevel@tonic-gate else if (cpi->cpi_maxeax >= 2) 34970Sstevel@tonic-gate return (X86_VENDOR_Intel); 34980Sstevel@tonic-gate break; 34990Sstevel@tonic-gate } 35000Sstevel@tonic-gate return (-1); 35010Sstevel@tonic-gate } 35020Sstevel@tonic-gate 35030Sstevel@tonic-gate void 35049652SMichael.Corcoran@Sun.COM cpuid_set_cpu_properties(void *dip, processorid_t cpu_id, 35059652SMichael.Corcoran@Sun.COM struct cpuid_info *cpi) 35060Sstevel@tonic-gate { 35070Sstevel@tonic-gate dev_info_t *cpu_devi; 35080Sstevel@tonic-gate int create; 35090Sstevel@tonic-gate 35109652SMichael.Corcoran@Sun.COM cpu_devi = (dev_info_t *)dip; 35110Sstevel@tonic-gate 35120Sstevel@tonic-gate /* device_type */ 35130Sstevel@tonic-gate (void) ndi_prop_update_string(DDI_DEV_T_NONE, cpu_devi, 35140Sstevel@tonic-gate "device_type", "cpu"); 35150Sstevel@tonic-gate 35160Sstevel@tonic-gate /* reg */ 35170Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 35180Sstevel@tonic-gate "reg", cpu_id); 35190Sstevel@tonic-gate 35200Sstevel@tonic-gate /* cpu-mhz, and clock-frequency */ 35210Sstevel@tonic-gate if (cpu_freq > 0) { 35220Sstevel@tonic-gate long long mul; 35230Sstevel@tonic-gate 35240Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 35250Sstevel@tonic-gate "cpu-mhz", cpu_freq); 35260Sstevel@tonic-gate if ((mul = cpu_freq * 1000000LL) <= INT_MAX) 35270Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 35280Sstevel@tonic-gate "clock-frequency", (int)mul); 35290Sstevel@tonic-gate } 35300Sstevel@tonic-gate 35310Sstevel@tonic-gate if ((x86_feature & X86_CPUID) == 0) { 35320Sstevel@tonic-gate return; 35330Sstevel@tonic-gate } 35340Sstevel@tonic-gate 35350Sstevel@tonic-gate /* vendor-id */ 35360Sstevel@tonic-gate (void) ndi_prop_update_string(DDI_DEV_T_NONE, cpu_devi, 35374481Sbholler "vendor-id", cpi->cpi_vendorstr); 35380Sstevel@tonic-gate 35390Sstevel@tonic-gate if (cpi->cpi_maxeax == 0) { 35400Sstevel@tonic-gate return; 35410Sstevel@tonic-gate } 35420Sstevel@tonic-gate 35430Sstevel@tonic-gate /* 35440Sstevel@tonic-gate * family, model, and step 35450Sstevel@tonic-gate */ 35460Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 35474481Sbholler "family", CPI_FAMILY(cpi)); 35480Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 35494481Sbholler "cpu-model", CPI_MODEL(cpi)); 35500Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 35514481Sbholler "stepping-id", CPI_STEP(cpi)); 35520Sstevel@tonic-gate 35530Sstevel@tonic-gate /* type */ 35540Sstevel@tonic-gate switch (cpi->cpi_vendor) { 35550Sstevel@tonic-gate case X86_VENDOR_Intel: 35560Sstevel@tonic-gate create = 1; 35570Sstevel@tonic-gate break; 35580Sstevel@tonic-gate default: 35590Sstevel@tonic-gate create = 0; 35600Sstevel@tonic-gate break; 35610Sstevel@tonic-gate } 35620Sstevel@tonic-gate if (create) 35630Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 35644481Sbholler "type", CPI_TYPE(cpi)); 35650Sstevel@tonic-gate 35660Sstevel@tonic-gate /* ext-family */ 35670Sstevel@tonic-gate switch (cpi->cpi_vendor) { 35680Sstevel@tonic-gate case X86_VENDOR_Intel: 35690Sstevel@tonic-gate case X86_VENDOR_AMD: 35700Sstevel@tonic-gate create = cpi->cpi_family >= 0xf; 35710Sstevel@tonic-gate break; 35720Sstevel@tonic-gate default: 35730Sstevel@tonic-gate create = 0; 35740Sstevel@tonic-gate break; 35750Sstevel@tonic-gate } 35760Sstevel@tonic-gate if (create) 35770Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 35780Sstevel@tonic-gate "ext-family", CPI_FAMILY_XTD(cpi)); 35790Sstevel@tonic-gate 35800Sstevel@tonic-gate /* ext-model */ 35810Sstevel@tonic-gate switch (cpi->cpi_vendor) { 35820Sstevel@tonic-gate case X86_VENDOR_Intel: 35836317Skk208521 create = IS_EXTENDED_MODEL_INTEL(cpi); 35842001Sdmick break; 35850Sstevel@tonic-gate case X86_VENDOR_AMD: 35861582Skchow create = CPI_FAMILY(cpi) == 0xf; 35870Sstevel@tonic-gate break; 35880Sstevel@tonic-gate default: 35890Sstevel@tonic-gate create = 0; 35900Sstevel@tonic-gate break; 35910Sstevel@tonic-gate } 35920Sstevel@tonic-gate if (create) 35930Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 35944481Sbholler "ext-model", CPI_MODEL_XTD(cpi)); 35950Sstevel@tonic-gate 35960Sstevel@tonic-gate /* generation */ 35970Sstevel@tonic-gate switch (cpi->cpi_vendor) { 35980Sstevel@tonic-gate case X86_VENDOR_AMD: 35990Sstevel@tonic-gate /* 36000Sstevel@tonic-gate * AMD K5 model 1 was the first part to support this 36010Sstevel@tonic-gate */ 36020Sstevel@tonic-gate create = cpi->cpi_xmaxeax >= 0x80000001; 36030Sstevel@tonic-gate break; 36040Sstevel@tonic-gate default: 36050Sstevel@tonic-gate create = 0; 36060Sstevel@tonic-gate break; 36070Sstevel@tonic-gate } 36080Sstevel@tonic-gate if (create) 36090Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 36100Sstevel@tonic-gate "generation", BITX((cpi)->cpi_extd[1].cp_eax, 11, 8)); 36110Sstevel@tonic-gate 36120Sstevel@tonic-gate /* brand-id */ 36130Sstevel@tonic-gate switch (cpi->cpi_vendor) { 36140Sstevel@tonic-gate case X86_VENDOR_Intel: 36150Sstevel@tonic-gate /* 36160Sstevel@tonic-gate * brand id first appeared on Pentium III Xeon model 8, 36170Sstevel@tonic-gate * and Celeron model 8 processors and Opteron 36180Sstevel@tonic-gate */ 36190Sstevel@tonic-gate create = cpi->cpi_family > 6 || 36200Sstevel@tonic-gate (cpi->cpi_family == 6 && cpi->cpi_model >= 8); 36210Sstevel@tonic-gate break; 36220Sstevel@tonic-gate case X86_VENDOR_AMD: 36230Sstevel@tonic-gate create = cpi->cpi_family >= 0xf; 36240Sstevel@tonic-gate break; 36250Sstevel@tonic-gate default: 36260Sstevel@tonic-gate create = 0; 36270Sstevel@tonic-gate break; 36280Sstevel@tonic-gate } 36290Sstevel@tonic-gate if (create && cpi->cpi_brandid != 0) { 36300Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 36310Sstevel@tonic-gate "brand-id", cpi->cpi_brandid); 36320Sstevel@tonic-gate } 36330Sstevel@tonic-gate 36340Sstevel@tonic-gate /* chunks, and apic-id */ 36350Sstevel@tonic-gate switch (cpi->cpi_vendor) { 36360Sstevel@tonic-gate /* 36370Sstevel@tonic-gate * first available on Pentium IV and Opteron (K8) 36380Sstevel@tonic-gate */ 36391975Sdmick case X86_VENDOR_Intel: 36401975Sdmick create = IS_NEW_F6(cpi) || cpi->cpi_family >= 0xf; 36411975Sdmick break; 36421975Sdmick case X86_VENDOR_AMD: 36430Sstevel@tonic-gate create = cpi->cpi_family >= 0xf; 36440Sstevel@tonic-gate break; 36450Sstevel@tonic-gate default: 36460Sstevel@tonic-gate create = 0; 36470Sstevel@tonic-gate break; 36480Sstevel@tonic-gate } 36490Sstevel@tonic-gate if (create) { 36500Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 36514481Sbholler "chunks", CPI_CHUNKS(cpi)); 36520Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 36537282Smishra "apic-id", cpi->cpi_apicid); 36541414Scindi if (cpi->cpi_chipid >= 0) { 36550Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 36560Sstevel@tonic-gate "chip#", cpi->cpi_chipid); 36571414Scindi (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 36581414Scindi "clog#", cpi->cpi_clogid); 36591414Scindi } 36600Sstevel@tonic-gate } 36610Sstevel@tonic-gate 36620Sstevel@tonic-gate /* cpuid-features */ 36630Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 36640Sstevel@tonic-gate "cpuid-features", CPI_FEATURES_EDX(cpi)); 36650Sstevel@tonic-gate 36660Sstevel@tonic-gate 36670Sstevel@tonic-gate /* cpuid-features-ecx */ 36680Sstevel@tonic-gate switch (cpi->cpi_vendor) { 36690Sstevel@tonic-gate case X86_VENDOR_Intel: 36701975Sdmick create = IS_NEW_F6(cpi) || cpi->cpi_family >= 0xf; 36710Sstevel@tonic-gate break; 36720Sstevel@tonic-gate default: 36730Sstevel@tonic-gate create = 0; 36740Sstevel@tonic-gate break; 36750Sstevel@tonic-gate } 36760Sstevel@tonic-gate if (create) 36770Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 36780Sstevel@tonic-gate "cpuid-features-ecx", CPI_FEATURES_ECX(cpi)); 36790Sstevel@tonic-gate 36800Sstevel@tonic-gate /* ext-cpuid-features */ 36810Sstevel@tonic-gate switch (cpi->cpi_vendor) { 36821975Sdmick case X86_VENDOR_Intel: 36830Sstevel@tonic-gate case X86_VENDOR_AMD: 36840Sstevel@tonic-gate case X86_VENDOR_Cyrix: 36850Sstevel@tonic-gate case X86_VENDOR_TM: 36860Sstevel@tonic-gate case X86_VENDOR_Centaur: 36870Sstevel@tonic-gate create = cpi->cpi_xmaxeax >= 0x80000001; 36880Sstevel@tonic-gate break; 36890Sstevel@tonic-gate default: 36900Sstevel@tonic-gate create = 0; 36910Sstevel@tonic-gate break; 36920Sstevel@tonic-gate } 36931975Sdmick if (create) { 36940Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 36954481Sbholler "ext-cpuid-features", CPI_FEATURES_XTD_EDX(cpi)); 36961975Sdmick (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 36974481Sbholler "ext-cpuid-features-ecx", CPI_FEATURES_XTD_ECX(cpi)); 36981975Sdmick } 36990Sstevel@tonic-gate 37000Sstevel@tonic-gate /* 37010Sstevel@tonic-gate * Brand String first appeared in Intel Pentium IV, AMD K5 37020Sstevel@tonic-gate * model 1, and Cyrix GXm. On earlier models we try and 37030Sstevel@tonic-gate * simulate something similar .. so this string should always 37040Sstevel@tonic-gate * same -something- about the processor, however lame. 37050Sstevel@tonic-gate */ 37060Sstevel@tonic-gate (void) ndi_prop_update_string(DDI_DEV_T_NONE, cpu_devi, 37070Sstevel@tonic-gate "brand-string", cpi->cpi_brandstr); 37080Sstevel@tonic-gate 37090Sstevel@tonic-gate /* 37100Sstevel@tonic-gate * Finally, cache and tlb information 37110Sstevel@tonic-gate */ 37120Sstevel@tonic-gate switch (x86_which_cacheinfo(cpi)) { 37130Sstevel@tonic-gate case X86_VENDOR_Intel: 37140Sstevel@tonic-gate intel_walk_cacheinfo(cpi, cpu_devi, add_cacheent_props); 37150Sstevel@tonic-gate break; 37160Sstevel@tonic-gate case X86_VENDOR_Cyrix: 37170Sstevel@tonic-gate cyrix_walk_cacheinfo(cpi, cpu_devi, add_cacheent_props); 37180Sstevel@tonic-gate break; 37190Sstevel@tonic-gate case X86_VENDOR_AMD: 37200Sstevel@tonic-gate amd_cache_info(cpi, cpu_devi); 37210Sstevel@tonic-gate break; 37220Sstevel@tonic-gate default: 37230Sstevel@tonic-gate break; 37240Sstevel@tonic-gate } 37250Sstevel@tonic-gate } 37260Sstevel@tonic-gate 37270Sstevel@tonic-gate struct l2info { 37280Sstevel@tonic-gate int *l2i_csz; 37290Sstevel@tonic-gate int *l2i_lsz; 37300Sstevel@tonic-gate int *l2i_assoc; 37310Sstevel@tonic-gate int l2i_ret; 37320Sstevel@tonic-gate }; 37330Sstevel@tonic-gate 37340Sstevel@tonic-gate /* 37350Sstevel@tonic-gate * A cacheinfo walker that fetches the size, line-size and associativity 37360Sstevel@tonic-gate * of the L2 cache 37370Sstevel@tonic-gate */ 37380Sstevel@tonic-gate static int 37390Sstevel@tonic-gate intel_l2cinfo(void *arg, const struct cachetab *ct) 37400Sstevel@tonic-gate { 37410Sstevel@tonic-gate struct l2info *l2i = arg; 37420Sstevel@tonic-gate int *ip; 37430Sstevel@tonic-gate 37440Sstevel@tonic-gate if (ct->ct_label != l2_cache_str && 37450Sstevel@tonic-gate ct->ct_label != sl2_cache_str) 37460Sstevel@tonic-gate return (0); /* not an L2 -- keep walking */ 37470Sstevel@tonic-gate 37480Sstevel@tonic-gate if ((ip = l2i->l2i_csz) != NULL) 37490Sstevel@tonic-gate *ip = ct->ct_size; 37500Sstevel@tonic-gate if ((ip = l2i->l2i_lsz) != NULL) 37510Sstevel@tonic-gate *ip = ct->ct_line_size; 37520Sstevel@tonic-gate if ((ip = l2i->l2i_assoc) != NULL) 37530Sstevel@tonic-gate *ip = ct->ct_assoc; 37540Sstevel@tonic-gate l2i->l2i_ret = ct->ct_size; 37550Sstevel@tonic-gate return (1); /* was an L2 -- terminate walk */ 37560Sstevel@tonic-gate } 37570Sstevel@tonic-gate 37585070Skchow /* 37595070Skchow * AMD L2/L3 Cache and TLB Associativity Field Definition: 37605070Skchow * 37615070Skchow * Unlike the associativity for the L1 cache and tlb where the 8 bit 37625070Skchow * value is the associativity, the associativity for the L2 cache and 37635070Skchow * tlb is encoded in the following table. The 4 bit L2 value serves as 37645070Skchow * an index into the amd_afd[] array to determine the associativity. 37655070Skchow * -1 is undefined. 0 is fully associative. 37665070Skchow */ 37675070Skchow 37685070Skchow static int amd_afd[] = 37695070Skchow {-1, 1, 2, -1, 4, -1, 8, -1, 16, -1, 32, 48, 64, 96, 128, 0}; 37705070Skchow 37710Sstevel@tonic-gate static void 37720Sstevel@tonic-gate amd_l2cacheinfo(struct cpuid_info *cpi, struct l2info *l2i) 37730Sstevel@tonic-gate { 37741228Sandrei struct cpuid_regs *cp; 37750Sstevel@tonic-gate uint_t size, assoc; 37765070Skchow int i; 37770Sstevel@tonic-gate int *ip; 37780Sstevel@tonic-gate 37790Sstevel@tonic-gate if (cpi->cpi_xmaxeax < 0x80000006) 37800Sstevel@tonic-gate return; 37810Sstevel@tonic-gate cp = &cpi->cpi_extd[6]; 37820Sstevel@tonic-gate 37835070Skchow if ((i = BITX(cp->cp_ecx, 15, 12)) != 0 && 37840Sstevel@tonic-gate (size = BITX(cp->cp_ecx, 31, 16)) != 0) { 37850Sstevel@tonic-gate uint_t cachesz = size * 1024; 37865070Skchow assoc = amd_afd[i]; 37875070Skchow 37885070Skchow ASSERT(assoc != -1); 37890Sstevel@tonic-gate 37900Sstevel@tonic-gate if ((ip = l2i->l2i_csz) != NULL) 37910Sstevel@tonic-gate *ip = cachesz; 37920Sstevel@tonic-gate if ((ip = l2i->l2i_lsz) != NULL) 37930Sstevel@tonic-gate *ip = BITX(cp->cp_ecx, 7, 0); 37940Sstevel@tonic-gate if ((ip = l2i->l2i_assoc) != NULL) 37950Sstevel@tonic-gate *ip = assoc; 37960Sstevel@tonic-gate l2i->l2i_ret = cachesz; 37970Sstevel@tonic-gate } 37980Sstevel@tonic-gate } 37990Sstevel@tonic-gate 38000Sstevel@tonic-gate int 38010Sstevel@tonic-gate getl2cacheinfo(cpu_t *cpu, int *csz, int *lsz, int *assoc) 38020Sstevel@tonic-gate { 38030Sstevel@tonic-gate struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 38040Sstevel@tonic-gate struct l2info __l2info, *l2i = &__l2info; 38050Sstevel@tonic-gate 38060Sstevel@tonic-gate l2i->l2i_csz = csz; 38070Sstevel@tonic-gate l2i->l2i_lsz = lsz; 38080Sstevel@tonic-gate l2i->l2i_assoc = assoc; 38090Sstevel@tonic-gate l2i->l2i_ret = -1; 38100Sstevel@tonic-gate 38110Sstevel@tonic-gate switch (x86_which_cacheinfo(cpi)) { 38120Sstevel@tonic-gate case X86_VENDOR_Intel: 38130Sstevel@tonic-gate intel_walk_cacheinfo(cpi, l2i, intel_l2cinfo); 38140Sstevel@tonic-gate break; 38150Sstevel@tonic-gate case X86_VENDOR_Cyrix: 38160Sstevel@tonic-gate cyrix_walk_cacheinfo(cpi, l2i, intel_l2cinfo); 38170Sstevel@tonic-gate break; 38180Sstevel@tonic-gate case X86_VENDOR_AMD: 38190Sstevel@tonic-gate amd_l2cacheinfo(cpi, l2i); 38200Sstevel@tonic-gate break; 38210Sstevel@tonic-gate default: 38220Sstevel@tonic-gate break; 38230Sstevel@tonic-gate } 38240Sstevel@tonic-gate return (l2i->l2i_ret); 38250Sstevel@tonic-gate } 38264481Sbholler 38275084Sjohnlev #if !defined(__xpv) 38285084Sjohnlev 38295045Sbholler uint32_t * 38305045Sbholler cpuid_mwait_alloc(cpu_t *cpu) 38315045Sbholler { 38325045Sbholler uint32_t *ret; 38335045Sbholler size_t mwait_size; 38345045Sbholler 38355045Sbholler ASSERT(cpuid_checkpass(cpu, 2)); 38365045Sbholler 38375045Sbholler mwait_size = cpu->cpu_m.mcpu_cpi->cpi_mwait.mon_max; 38385045Sbholler if (mwait_size == 0) 38395045Sbholler return (NULL); 38405045Sbholler 38415045Sbholler /* 38425045Sbholler * kmem_alloc() returns cache line size aligned data for mwait_size 38435045Sbholler * allocations. mwait_size is currently cache line sized. Neither 38445045Sbholler * of these implementation details are guarantied to be true in the 38455045Sbholler * future. 38465045Sbholler * 38475045Sbholler * First try allocating mwait_size as kmem_alloc() currently returns 38485045Sbholler * correctly aligned memory. If kmem_alloc() does not return 38495045Sbholler * mwait_size aligned memory, then use mwait_size ROUNDUP. 38505045Sbholler * 38515045Sbholler * Set cpi_mwait.buf_actual and cpi_mwait.size_actual in case we 38525045Sbholler * decide to free this memory. 38535045Sbholler */ 38545045Sbholler ret = kmem_zalloc(mwait_size, KM_SLEEP); 38555045Sbholler if (ret == (uint32_t *)P2ROUNDUP((uintptr_t)ret, mwait_size)) { 38565045Sbholler cpu->cpu_m.mcpu_cpi->cpi_mwait.buf_actual = ret; 38575045Sbholler cpu->cpu_m.mcpu_cpi->cpi_mwait.size_actual = mwait_size; 38585045Sbholler *ret = MWAIT_RUNNING; 38595045Sbholler return (ret); 38605045Sbholler } else { 38615045Sbholler kmem_free(ret, mwait_size); 38625045Sbholler ret = kmem_zalloc(mwait_size * 2, KM_SLEEP); 38635045Sbholler cpu->cpu_m.mcpu_cpi->cpi_mwait.buf_actual = ret; 38645045Sbholler cpu->cpu_m.mcpu_cpi->cpi_mwait.size_actual = mwait_size * 2; 38655045Sbholler ret = (uint32_t *)P2ROUNDUP((uintptr_t)ret, mwait_size); 38665045Sbholler *ret = MWAIT_RUNNING; 38675045Sbholler return (ret); 38685045Sbholler } 38695045Sbholler } 38705045Sbholler 38715045Sbholler void 38725045Sbholler cpuid_mwait_free(cpu_t *cpu) 38734481Sbholler { 38744481Sbholler ASSERT(cpuid_checkpass(cpu, 2)); 38755045Sbholler 38765045Sbholler if (cpu->cpu_m.mcpu_cpi->cpi_mwait.buf_actual != NULL && 38775045Sbholler cpu->cpu_m.mcpu_cpi->cpi_mwait.size_actual > 0) { 38785045Sbholler kmem_free(cpu->cpu_m.mcpu_cpi->cpi_mwait.buf_actual, 38795045Sbholler cpu->cpu_m.mcpu_cpi->cpi_mwait.size_actual); 38805045Sbholler } 38815045Sbholler 38825045Sbholler cpu->cpu_m.mcpu_cpi->cpi_mwait.buf_actual = NULL; 38835045Sbholler cpu->cpu_m.mcpu_cpi->cpi_mwait.size_actual = 0; 38844481Sbholler } 38855084Sjohnlev 38865322Ssudheer void 38875322Ssudheer patch_tsc_read(int flag) 38885322Ssudheer { 38895322Ssudheer size_t cnt; 38907532SSean.Ye@Sun.COM 38915322Ssudheer switch (flag) { 38925322Ssudheer case X86_NO_TSC: 38935322Ssudheer cnt = &_no_rdtsc_end - &_no_rdtsc_start; 38945338Ssudheer (void) memcpy((void *)tsc_read, (void *)&_no_rdtsc_start, cnt); 38955322Ssudheer break; 38965322Ssudheer case X86_HAVE_TSCP: 38975322Ssudheer cnt = &_tscp_end - &_tscp_start; 38985338Ssudheer (void) memcpy((void *)tsc_read, (void *)&_tscp_start, cnt); 38995322Ssudheer break; 39005322Ssudheer case X86_TSC_MFENCE: 39015322Ssudheer cnt = &_tsc_mfence_end - &_tsc_mfence_start; 39025338Ssudheer (void) memcpy((void *)tsc_read, 39035338Ssudheer (void *)&_tsc_mfence_start, cnt); 39045322Ssudheer break; 39056642Ssudheer case X86_TSC_LFENCE: 39066642Ssudheer cnt = &_tsc_lfence_end - &_tsc_lfence_start; 39076642Ssudheer (void) memcpy((void *)tsc_read, 39086642Ssudheer (void *)&_tsc_lfence_start, cnt); 39096642Ssudheer break; 39105322Ssudheer default: 39115322Ssudheer break; 39125322Ssudheer } 39135322Ssudheer } 39145322Ssudheer 39158906SEric.Saxe@Sun.COM int 39168906SEric.Saxe@Sun.COM cpuid_deep_cstates_supported(void) 39178906SEric.Saxe@Sun.COM { 39188906SEric.Saxe@Sun.COM struct cpuid_info *cpi; 39198906SEric.Saxe@Sun.COM struct cpuid_regs regs; 39208906SEric.Saxe@Sun.COM 39218906SEric.Saxe@Sun.COM ASSERT(cpuid_checkpass(CPU, 1)); 39228906SEric.Saxe@Sun.COM 39238906SEric.Saxe@Sun.COM cpi = CPU->cpu_m.mcpu_cpi; 39248906SEric.Saxe@Sun.COM 39258906SEric.Saxe@Sun.COM if (!(x86_feature & X86_CPUID)) 39268906SEric.Saxe@Sun.COM return (0); 39278906SEric.Saxe@Sun.COM 39288906SEric.Saxe@Sun.COM switch (cpi->cpi_vendor) { 39298906SEric.Saxe@Sun.COM case X86_VENDOR_Intel: 39308906SEric.Saxe@Sun.COM if (cpi->cpi_xmaxeax < 0x80000007) 39318906SEric.Saxe@Sun.COM return (0); 39328906SEric.Saxe@Sun.COM 39338906SEric.Saxe@Sun.COM /* 39348906SEric.Saxe@Sun.COM * TSC run at a constant rate in all ACPI C-states? 39358906SEric.Saxe@Sun.COM */ 39368906SEric.Saxe@Sun.COM regs.cp_eax = 0x80000007; 39378906SEric.Saxe@Sun.COM (void) __cpuid_insn(®s); 39388906SEric.Saxe@Sun.COM return (regs.cp_edx & CPUID_TSC_CSTATE_INVARIANCE); 39398906SEric.Saxe@Sun.COM 39408906SEric.Saxe@Sun.COM default: 39418906SEric.Saxe@Sun.COM return (0); 39428906SEric.Saxe@Sun.COM } 39438906SEric.Saxe@Sun.COM } 39448906SEric.Saxe@Sun.COM 39458930SBill.Holler@Sun.COM #endif /* !__xpv */ 39468930SBill.Holler@Sun.COM 39478930SBill.Holler@Sun.COM void 39488930SBill.Holler@Sun.COM post_startup_cpu_fixups(void) 39498930SBill.Holler@Sun.COM { 39508930SBill.Holler@Sun.COM #ifndef __xpv 39518930SBill.Holler@Sun.COM /* 39528930SBill.Holler@Sun.COM * Some AMD processors support C1E state. Entering this state will 39538930SBill.Holler@Sun.COM * cause the local APIC timer to stop, which we can't deal with at 39548930SBill.Holler@Sun.COM * this time. 39558930SBill.Holler@Sun.COM */ 39568930SBill.Holler@Sun.COM if (cpuid_getvendor(CPU) == X86_VENDOR_AMD) { 39578930SBill.Holler@Sun.COM on_trap_data_t otd; 39588930SBill.Holler@Sun.COM uint64_t reg; 39598930SBill.Holler@Sun.COM 39608930SBill.Holler@Sun.COM if (!on_trap(&otd, OT_DATA_ACCESS)) { 39618930SBill.Holler@Sun.COM reg = rdmsr(MSR_AMD_INT_PENDING_CMP_HALT); 39628930SBill.Holler@Sun.COM /* Disable C1E state if it is enabled by BIOS */ 39638930SBill.Holler@Sun.COM if ((reg >> AMD_ACTONCMPHALT_SHIFT) & 39648930SBill.Holler@Sun.COM AMD_ACTONCMPHALT_MASK) { 39658930SBill.Holler@Sun.COM reg &= ~(AMD_ACTONCMPHALT_MASK << 39668930SBill.Holler@Sun.COM AMD_ACTONCMPHALT_SHIFT); 39678930SBill.Holler@Sun.COM wrmsr(MSR_AMD_INT_PENDING_CMP_HALT, reg); 39688930SBill.Holler@Sun.COM } 39698930SBill.Holler@Sun.COM } 39708930SBill.Holler@Sun.COM no_trap(); 39718930SBill.Holler@Sun.COM } 39728930SBill.Holler@Sun.COM #endif /* !__xpv */ 39738930SBill.Holler@Sun.COM } 39748930SBill.Holler@Sun.COM 39759283SBill.Holler@Sun.COM /* 39769283SBill.Holler@Sun.COM * Starting with the Westmere processor the local 39779283SBill.Holler@Sun.COM * APIC timer will continue running in all C-states, 39789283SBill.Holler@Sun.COM * including the deepest C-states. 39799283SBill.Holler@Sun.COM */ 39809283SBill.Holler@Sun.COM int 39819283SBill.Holler@Sun.COM cpuid_arat_supported(void) 39829283SBill.Holler@Sun.COM { 39839283SBill.Holler@Sun.COM struct cpuid_info *cpi; 39849283SBill.Holler@Sun.COM struct cpuid_regs regs; 39859283SBill.Holler@Sun.COM 39869283SBill.Holler@Sun.COM ASSERT(cpuid_checkpass(CPU, 1)); 39879283SBill.Holler@Sun.COM ASSERT(x86_feature & X86_CPUID); 39889283SBill.Holler@Sun.COM 39899283SBill.Holler@Sun.COM cpi = CPU->cpu_m.mcpu_cpi; 39909283SBill.Holler@Sun.COM 39919283SBill.Holler@Sun.COM switch (cpi->cpi_vendor) { 39929283SBill.Holler@Sun.COM case X86_VENDOR_Intel: 39939283SBill.Holler@Sun.COM /* 39949283SBill.Holler@Sun.COM * Always-running Local APIC Timer is 39959283SBill.Holler@Sun.COM * indicated by CPUID.6.EAX[2]. 39969283SBill.Holler@Sun.COM */ 39979283SBill.Holler@Sun.COM if (cpi->cpi_maxeax >= 6) { 39989283SBill.Holler@Sun.COM regs.cp_eax = 6; 39999283SBill.Holler@Sun.COM (void) cpuid_insn(NULL, ®s); 40009283SBill.Holler@Sun.COM return (regs.cp_eax & CPUID_CSTATE_ARAT); 40019283SBill.Holler@Sun.COM } else { 40029283SBill.Holler@Sun.COM return (0); 40039283SBill.Holler@Sun.COM } 40049283SBill.Holler@Sun.COM default: 40059283SBill.Holler@Sun.COM return (0); 40069283SBill.Holler@Sun.COM } 40079283SBill.Holler@Sun.COM } 40089283SBill.Holler@Sun.COM 40098377SBill.Holler@Sun.COM #if defined(__amd64) && !defined(__xpv) 40108377SBill.Holler@Sun.COM /* 40118377SBill.Holler@Sun.COM * Patch in versions of bcopy for high performance Intel Nhm processors 40128377SBill.Holler@Sun.COM * and later... 40138377SBill.Holler@Sun.COM */ 40148377SBill.Holler@Sun.COM void 40158377SBill.Holler@Sun.COM patch_memops(uint_t vendor) 40168377SBill.Holler@Sun.COM { 40178377SBill.Holler@Sun.COM size_t cnt, i; 40188377SBill.Holler@Sun.COM caddr_t to, from; 40198377SBill.Holler@Sun.COM 40208377SBill.Holler@Sun.COM if ((vendor == X86_VENDOR_Intel) && ((x86_feature & X86_SSE4_2) != 0)) { 40218377SBill.Holler@Sun.COM cnt = &bcopy_patch_end - &bcopy_patch_start; 40228377SBill.Holler@Sun.COM to = &bcopy_ck_size; 40238377SBill.Holler@Sun.COM from = &bcopy_patch_start; 40248377SBill.Holler@Sun.COM for (i = 0; i < cnt; i++) { 40258377SBill.Holler@Sun.COM *to++ = *from++; 40268377SBill.Holler@Sun.COM } 40278377SBill.Holler@Sun.COM } 40288377SBill.Holler@Sun.COM } 40298377SBill.Holler@Sun.COM #endif /* __amd64 && !__xpv */ 4030