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) { 3675084Sjohnlev case 0x80000008: 3685084Sjohnlev /* 3695084Sjohnlev * Zero out the (ncores-per-chip - 1) field 3705084Sjohnlev */ 3715084Sjohnlev cp->cp_ecx &= 0xffffff00; 3725084Sjohnlev break; 3735084Sjohnlev default: 3745084Sjohnlev break; 3755084Sjohnlev } 3765084Sjohnlev break; 3775084Sjohnlev default: 3785084Sjohnlev break; 3795084Sjohnlev } 3805084Sjohnlev } 3815084Sjohnlev #else 3823446Smrj #define platform_cpuid_mangle(vendor, eax, cp) /* nothing */ 3835084Sjohnlev #endif 3843446Smrj 3853446Smrj /* 3860Sstevel@tonic-gate * Some undocumented ways of patching the results of the cpuid 3870Sstevel@tonic-gate * instruction to permit running Solaris 10 on future cpus that 3880Sstevel@tonic-gate * we don't currently support. Could be set to non-zero values 3890Sstevel@tonic-gate * via settings in eeprom. 3900Sstevel@tonic-gate */ 3910Sstevel@tonic-gate 3920Sstevel@tonic-gate uint32_t cpuid_feature_ecx_include; 3930Sstevel@tonic-gate uint32_t cpuid_feature_ecx_exclude; 3940Sstevel@tonic-gate uint32_t cpuid_feature_edx_include; 3950Sstevel@tonic-gate uint32_t cpuid_feature_edx_exclude; 3960Sstevel@tonic-gate 3973446Smrj void 3983446Smrj cpuid_alloc_space(cpu_t *cpu) 3993446Smrj { 4003446Smrj /* 4013446Smrj * By convention, cpu0 is the boot cpu, which is set up 4023446Smrj * before memory allocation is available. All other cpus get 4033446Smrj * their cpuid_info struct allocated here. 4043446Smrj */ 4053446Smrj ASSERT(cpu->cpu_id != 0); 4063446Smrj cpu->cpu_m.mcpu_cpi = 4073446Smrj kmem_zalloc(sizeof (*cpu->cpu_m.mcpu_cpi), KM_SLEEP); 4083446Smrj } 4093446Smrj 4103446Smrj void 4113446Smrj cpuid_free_space(cpu_t *cpu) 4123446Smrj { 4134606Sesaxe struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 4144606Sesaxe int i; 4154606Sesaxe 4163446Smrj ASSERT(cpu->cpu_id != 0); 4174606Sesaxe 4184606Sesaxe /* 4194606Sesaxe * Free up any function 4 related dynamic storage 4204606Sesaxe */ 4214606Sesaxe for (i = 1; i < cpi->cpi_std_4_size; i++) 4224606Sesaxe kmem_free(cpi->cpi_std_4[i], sizeof (struct cpuid_regs)); 4234606Sesaxe if (cpi->cpi_std_4_size > 0) 4244606Sesaxe kmem_free(cpi->cpi_std_4, 4254606Sesaxe cpi->cpi_std_4_size * sizeof (struct cpuid_regs *)); 4264606Sesaxe 4273446Smrj kmem_free(cpu->cpu_m.mcpu_cpi, sizeof (*cpu->cpu_m.mcpu_cpi)); 4283446Smrj } 4293446Smrj 4305741Smrj #if !defined(__xpv) 4315741Smrj 4325741Smrj static void 4339000SStuart.Maybee@Sun.COM determine_platform() 4345741Smrj { 4355741Smrj struct cpuid_regs cp; 4365741Smrj char *xen_str; 4375741Smrj uint32_t xen_signature[4]; 4385741Smrj 4395741Smrj /* 4405741Smrj * In a fully virtualized domain, Xen's pseudo-cpuid function 4415741Smrj * 0x40000000 returns a string representing the Xen signature in 4425741Smrj * %ebx, %ecx, and %edx. %eax contains the maximum supported cpuid 4435741Smrj * function. 4445741Smrj */ 4455741Smrj cp.cp_eax = 0x40000000; 4465741Smrj (void) __cpuid_insn(&cp); 4475741Smrj xen_signature[0] = cp.cp_ebx; 4485741Smrj xen_signature[1] = cp.cp_ecx; 4495741Smrj xen_signature[2] = cp.cp_edx; 4505741Smrj xen_signature[3] = 0; 4515741Smrj xen_str = (char *)xen_signature; 4529000SStuart.Maybee@Sun.COM if (strcmp("XenVMMXenVMM", xen_str) == 0 && cp.cp_eax <= 0x40000002) { 4539000SStuart.Maybee@Sun.COM platform_type = HW_XEN_HVM; 4549000SStuart.Maybee@Sun.COM } else if (vmware_platform()) { /* running under vmware hypervisor? */ 4559000SStuart.Maybee@Sun.COM platform_type = HW_VMWARE; 4569000SStuart.Maybee@Sun.COM } 4579000SStuart.Maybee@Sun.COM } 4589000SStuart.Maybee@Sun.COM 4599000SStuart.Maybee@Sun.COM int 4609000SStuart.Maybee@Sun.COM get_hwenv(void) 4619000SStuart.Maybee@Sun.COM { 4629000SStuart.Maybee@Sun.COM return (platform_type); 4635741Smrj } 4649000SStuart.Maybee@Sun.COM 4659000SStuart.Maybee@Sun.COM int 4669000SStuart.Maybee@Sun.COM is_controldom(void) 4679000SStuart.Maybee@Sun.COM { 4689000SStuart.Maybee@Sun.COM return (0); 4699000SStuart.Maybee@Sun.COM } 4709000SStuart.Maybee@Sun.COM 4719000SStuart.Maybee@Sun.COM #else 4729000SStuart.Maybee@Sun.COM 4739000SStuart.Maybee@Sun.COM int 4749000SStuart.Maybee@Sun.COM get_hwenv(void) 4759000SStuart.Maybee@Sun.COM { 4769000SStuart.Maybee@Sun.COM return (HW_XEN_PV); 4779000SStuart.Maybee@Sun.COM } 4789000SStuart.Maybee@Sun.COM 4799000SStuart.Maybee@Sun.COM int 4809000SStuart.Maybee@Sun.COM is_controldom(void) 4819000SStuart.Maybee@Sun.COM { 4829000SStuart.Maybee@Sun.COM return (DOMAIN_IS_INITDOMAIN(xen_info)); 4839000SStuart.Maybee@Sun.COM } 4849000SStuart.Maybee@Sun.COM 4855741Smrj #endif /* __xpv */ 4865741Smrj 4870Sstevel@tonic-gate uint_t 4880Sstevel@tonic-gate cpuid_pass1(cpu_t *cpu) 4890Sstevel@tonic-gate { 4900Sstevel@tonic-gate uint32_t mask_ecx, mask_edx; 4910Sstevel@tonic-gate uint_t feature = X86_CPUID; 4920Sstevel@tonic-gate struct cpuid_info *cpi; 4931228Sandrei struct cpuid_regs *cp; 4940Sstevel@tonic-gate int xcpuid; 4955084Sjohnlev #if !defined(__xpv) 4965045Sbholler extern int idle_cpu_prefer_mwait; 4975084Sjohnlev #endif 4983446Smrj 4999482SKuriakose.Kuruvilla@Sun.COM 5009482SKuriakose.Kuruvilla@Sun.COM #if !defined(__xpv) 5019482SKuriakose.Kuruvilla@Sun.COM determine_platform(); 5029482SKuriakose.Kuruvilla@Sun.COM #endif 5030Sstevel@tonic-gate /* 5043446Smrj * Space statically allocated for cpu0, ensure pointer is set 5050Sstevel@tonic-gate */ 5060Sstevel@tonic-gate if (cpu->cpu_id == 0) 5073446Smrj cpu->cpu_m.mcpu_cpi = &cpuid_info0; 5083446Smrj cpi = cpu->cpu_m.mcpu_cpi; 5093446Smrj ASSERT(cpi != NULL); 5100Sstevel@tonic-gate cp = &cpi->cpi_std[0]; 5111228Sandrei cp->cp_eax = 0; 5121228Sandrei cpi->cpi_maxeax = __cpuid_insn(cp); 5130Sstevel@tonic-gate { 5140Sstevel@tonic-gate uint32_t *iptr = (uint32_t *)cpi->cpi_vendorstr; 5150Sstevel@tonic-gate *iptr++ = cp->cp_ebx; 5160Sstevel@tonic-gate *iptr++ = cp->cp_edx; 5170Sstevel@tonic-gate *iptr++ = cp->cp_ecx; 5180Sstevel@tonic-gate *(char *)&cpi->cpi_vendorstr[12] = '\0'; 5190Sstevel@tonic-gate } 5200Sstevel@tonic-gate 5217532SSean.Ye@Sun.COM cpi->cpi_vendor = _cpuid_vendorstr_to_vendorcode(cpi->cpi_vendorstr); 5220Sstevel@tonic-gate x86_vendor = cpi->cpi_vendor; /* for compatibility */ 5230Sstevel@tonic-gate 5240Sstevel@tonic-gate /* 5250Sstevel@tonic-gate * Limit the range in case of weird hardware 5260Sstevel@tonic-gate */ 5270Sstevel@tonic-gate if (cpi->cpi_maxeax > CPI_MAXEAX_MAX) 5280Sstevel@tonic-gate cpi->cpi_maxeax = CPI_MAXEAX_MAX; 5290Sstevel@tonic-gate if (cpi->cpi_maxeax < 1) 5300Sstevel@tonic-gate goto pass1_done; 5310Sstevel@tonic-gate 5320Sstevel@tonic-gate cp = &cpi->cpi_std[1]; 5331228Sandrei cp->cp_eax = 1; 5341228Sandrei (void) __cpuid_insn(cp); 5350Sstevel@tonic-gate 5360Sstevel@tonic-gate /* 5370Sstevel@tonic-gate * Extract identifying constants for easy access. 5380Sstevel@tonic-gate */ 5390Sstevel@tonic-gate cpi->cpi_model = CPI_MODEL(cpi); 5400Sstevel@tonic-gate cpi->cpi_family = CPI_FAMILY(cpi); 5410Sstevel@tonic-gate 5421975Sdmick if (cpi->cpi_family == 0xf) 5430Sstevel@tonic-gate cpi->cpi_family += CPI_FAMILY_XTD(cpi); 5441975Sdmick 5452001Sdmick /* 5464265Skchow * Beware: AMD uses "extended model" iff base *FAMILY* == 0xf. 5472001Sdmick * Intel, and presumably everyone else, uses model == 0xf, as 5482001Sdmick * one would expect (max value means possible overflow). Sigh. 5492001Sdmick */ 5502001Sdmick 5512001Sdmick switch (cpi->cpi_vendor) { 5524855Sksadhukh case X86_VENDOR_Intel: 5534855Sksadhukh if (IS_EXTENDED_MODEL_INTEL(cpi)) 5544855Sksadhukh cpi->cpi_model += CPI_MODEL_XTD(cpi) << 4; 5554858Sksadhukh break; 5562001Sdmick case X86_VENDOR_AMD: 5574265Skchow if (CPI_FAMILY(cpi) == 0xf) 5582001Sdmick cpi->cpi_model += CPI_MODEL_XTD(cpi) << 4; 5592001Sdmick break; 5602001Sdmick default: 5612001Sdmick if (cpi->cpi_model == 0xf) 5622001Sdmick cpi->cpi_model += CPI_MODEL_XTD(cpi) << 4; 5632001Sdmick break; 5642001Sdmick } 5650Sstevel@tonic-gate 5660Sstevel@tonic-gate cpi->cpi_step = CPI_STEP(cpi); 5670Sstevel@tonic-gate cpi->cpi_brandid = CPI_BRANDID(cpi); 5680Sstevel@tonic-gate 5690Sstevel@tonic-gate /* 5700Sstevel@tonic-gate * *default* assumptions: 5710Sstevel@tonic-gate * - believe %edx feature word 5720Sstevel@tonic-gate * - ignore %ecx feature word 5730Sstevel@tonic-gate * - 32-bit virtual and physical addressing 5740Sstevel@tonic-gate */ 5750Sstevel@tonic-gate mask_edx = 0xffffffff; 5760Sstevel@tonic-gate mask_ecx = 0; 5770Sstevel@tonic-gate 5780Sstevel@tonic-gate cpi->cpi_pabits = cpi->cpi_vabits = 32; 5790Sstevel@tonic-gate 5800Sstevel@tonic-gate switch (cpi->cpi_vendor) { 5810Sstevel@tonic-gate case X86_VENDOR_Intel: 5820Sstevel@tonic-gate if (cpi->cpi_family == 5) 5830Sstevel@tonic-gate x86_type = X86_TYPE_P5; 5841975Sdmick else if (IS_LEGACY_P6(cpi)) { 5850Sstevel@tonic-gate x86_type = X86_TYPE_P6; 5860Sstevel@tonic-gate pentiumpro_bug4046376 = 1; 5870Sstevel@tonic-gate pentiumpro_bug4064495 = 1; 5880Sstevel@tonic-gate /* 5890Sstevel@tonic-gate * Clear the SEP bit when it was set erroneously 5900Sstevel@tonic-gate */ 5910Sstevel@tonic-gate if (cpi->cpi_model < 3 && cpi->cpi_step < 3) 5920Sstevel@tonic-gate cp->cp_edx &= ~CPUID_INTC_EDX_SEP; 5931975Sdmick } else if (IS_NEW_F6(cpi) || cpi->cpi_family == 0xf) { 5940Sstevel@tonic-gate x86_type = X86_TYPE_P4; 5950Sstevel@tonic-gate /* 5960Sstevel@tonic-gate * We don't currently depend on any of the %ecx 5970Sstevel@tonic-gate * features until Prescott, so we'll only check 5980Sstevel@tonic-gate * this from P4 onwards. We might want to revisit 5990Sstevel@tonic-gate * that idea later. 6000Sstevel@tonic-gate */ 6010Sstevel@tonic-gate mask_ecx = 0xffffffff; 6020Sstevel@tonic-gate } else if (cpi->cpi_family > 0xf) 6030Sstevel@tonic-gate mask_ecx = 0xffffffff; 6044636Sbholler /* 6054636Sbholler * We don't support MONITOR/MWAIT if leaf 5 is not available 6064636Sbholler * to obtain the monitor linesize. 6074636Sbholler */ 6084636Sbholler if (cpi->cpi_maxeax < 5) 6094636Sbholler mask_ecx &= ~CPUID_INTC_ECX_MON; 6100Sstevel@tonic-gate break; 6110Sstevel@tonic-gate case X86_VENDOR_IntelClone: 6120Sstevel@tonic-gate default: 6130Sstevel@tonic-gate break; 6140Sstevel@tonic-gate case X86_VENDOR_AMD: 6150Sstevel@tonic-gate #if defined(OPTERON_ERRATUM_108) 6160Sstevel@tonic-gate if (cpi->cpi_family == 0xf && cpi->cpi_model == 0xe) { 6170Sstevel@tonic-gate cp->cp_eax = (0xf0f & cp->cp_eax) | 0xc0; 6180Sstevel@tonic-gate cpi->cpi_model = 0xc; 6190Sstevel@tonic-gate } else 6200Sstevel@tonic-gate #endif 6210Sstevel@tonic-gate if (cpi->cpi_family == 5) { 6220Sstevel@tonic-gate /* 6230Sstevel@tonic-gate * AMD K5 and K6 6240Sstevel@tonic-gate * 6250Sstevel@tonic-gate * These CPUs have an incomplete implementation 6260Sstevel@tonic-gate * of MCA/MCE which we mask away. 6270Sstevel@tonic-gate */ 6281228Sandrei mask_edx &= ~(CPUID_INTC_EDX_MCE | CPUID_INTC_EDX_MCA); 6291228Sandrei 6301228Sandrei /* 6311228Sandrei * Model 0 uses the wrong (APIC) bit 6321228Sandrei * to indicate PGE. Fix it here. 6331228Sandrei */ 6340Sstevel@tonic-gate if (cpi->cpi_model == 0) { 6350Sstevel@tonic-gate if (cp->cp_edx & 0x200) { 6360Sstevel@tonic-gate cp->cp_edx &= ~0x200; 6370Sstevel@tonic-gate cp->cp_edx |= CPUID_INTC_EDX_PGE; 6380Sstevel@tonic-gate } 6391228Sandrei } 6401228Sandrei 6411228Sandrei /* 6421228Sandrei * Early models had problems w/ MMX; disable. 6431228Sandrei */ 6441228Sandrei if (cpi->cpi_model < 6) 6451228Sandrei mask_edx &= ~CPUID_INTC_EDX_MMX; 6461228Sandrei } 6471228Sandrei 6481228Sandrei /* 6491228Sandrei * For newer families, SSE3 and CX16, at least, are valid; 6501228Sandrei * enable all 6511228Sandrei */ 6521228Sandrei if (cpi->cpi_family >= 0xf) 653771Sdmick mask_ecx = 0xffffffff; 6544636Sbholler /* 6554636Sbholler * We don't support MONITOR/MWAIT if leaf 5 is not available 6564636Sbholler * to obtain the monitor linesize. 6574636Sbholler */ 6584636Sbholler if (cpi->cpi_maxeax < 5) 6594636Sbholler mask_ecx &= ~CPUID_INTC_ECX_MON; 6605045Sbholler 6615084Sjohnlev #if !defined(__xpv) 6625045Sbholler /* 6635045Sbholler * Do not use MONITOR/MWAIT to halt in the idle loop on any AMD 6645045Sbholler * processors. AMD does not intend MWAIT to be used in the cpu 6655045Sbholler * idle loop on current and future processors. 10h and future 6665045Sbholler * AMD processors use more power in MWAIT than HLT. 6675045Sbholler * Pre-family-10h Opterons do not have the MWAIT instruction. 6685045Sbholler */ 6695045Sbholler idle_cpu_prefer_mwait = 0; 6705084Sjohnlev #endif 6715045Sbholler 6720Sstevel@tonic-gate break; 6730Sstevel@tonic-gate case X86_VENDOR_TM: 6740Sstevel@tonic-gate /* 6750Sstevel@tonic-gate * workaround the NT workaround in CMS 4.1 6760Sstevel@tonic-gate */ 6770Sstevel@tonic-gate if (cpi->cpi_family == 5 && cpi->cpi_model == 4 && 6780Sstevel@tonic-gate (cpi->cpi_step == 2 || cpi->cpi_step == 3)) 6790Sstevel@tonic-gate cp->cp_edx |= CPUID_INTC_EDX_CX8; 6800Sstevel@tonic-gate break; 6810Sstevel@tonic-gate case X86_VENDOR_Centaur: 6820Sstevel@tonic-gate /* 6830Sstevel@tonic-gate * workaround the NT workarounds again 6840Sstevel@tonic-gate */ 6850Sstevel@tonic-gate if (cpi->cpi_family == 6) 6860Sstevel@tonic-gate cp->cp_edx |= CPUID_INTC_EDX_CX8; 6870Sstevel@tonic-gate break; 6880Sstevel@tonic-gate case X86_VENDOR_Cyrix: 6890Sstevel@tonic-gate /* 6900Sstevel@tonic-gate * We rely heavily on the probing in locore 6910Sstevel@tonic-gate * to actually figure out what parts, if any, 6920Sstevel@tonic-gate * of the Cyrix cpuid instruction to believe. 6930Sstevel@tonic-gate */ 6940Sstevel@tonic-gate switch (x86_type) { 6950Sstevel@tonic-gate case X86_TYPE_CYRIX_486: 6960Sstevel@tonic-gate mask_edx = 0; 6970Sstevel@tonic-gate break; 6980Sstevel@tonic-gate case X86_TYPE_CYRIX_6x86: 6990Sstevel@tonic-gate mask_edx = 0; 7000Sstevel@tonic-gate break; 7010Sstevel@tonic-gate case X86_TYPE_CYRIX_6x86L: 7020Sstevel@tonic-gate mask_edx = 7030Sstevel@tonic-gate CPUID_INTC_EDX_DE | 7040Sstevel@tonic-gate CPUID_INTC_EDX_CX8; 7050Sstevel@tonic-gate break; 7060Sstevel@tonic-gate case X86_TYPE_CYRIX_6x86MX: 7070Sstevel@tonic-gate mask_edx = 7080Sstevel@tonic-gate CPUID_INTC_EDX_DE | 7090Sstevel@tonic-gate CPUID_INTC_EDX_MSR | 7100Sstevel@tonic-gate CPUID_INTC_EDX_CX8 | 7110Sstevel@tonic-gate CPUID_INTC_EDX_PGE | 7120Sstevel@tonic-gate CPUID_INTC_EDX_CMOV | 7130Sstevel@tonic-gate CPUID_INTC_EDX_MMX; 7140Sstevel@tonic-gate break; 7150Sstevel@tonic-gate case X86_TYPE_CYRIX_GXm: 7160Sstevel@tonic-gate mask_edx = 7170Sstevel@tonic-gate CPUID_INTC_EDX_MSR | 7180Sstevel@tonic-gate CPUID_INTC_EDX_CX8 | 7190Sstevel@tonic-gate CPUID_INTC_EDX_CMOV | 7200Sstevel@tonic-gate CPUID_INTC_EDX_MMX; 7210Sstevel@tonic-gate break; 7220Sstevel@tonic-gate case X86_TYPE_CYRIX_MediaGX: 7230Sstevel@tonic-gate break; 7240Sstevel@tonic-gate case X86_TYPE_CYRIX_MII: 7250Sstevel@tonic-gate case X86_TYPE_VIA_CYRIX_III: 7260Sstevel@tonic-gate mask_edx = 7270Sstevel@tonic-gate CPUID_INTC_EDX_DE | 7280Sstevel@tonic-gate CPUID_INTC_EDX_TSC | 7290Sstevel@tonic-gate CPUID_INTC_EDX_MSR | 7300Sstevel@tonic-gate CPUID_INTC_EDX_CX8 | 7310Sstevel@tonic-gate CPUID_INTC_EDX_PGE | 7320Sstevel@tonic-gate CPUID_INTC_EDX_CMOV | 7330Sstevel@tonic-gate CPUID_INTC_EDX_MMX; 7340Sstevel@tonic-gate break; 7350Sstevel@tonic-gate default: 7360Sstevel@tonic-gate break; 7370Sstevel@tonic-gate } 7380Sstevel@tonic-gate break; 7390Sstevel@tonic-gate } 7400Sstevel@tonic-gate 7415084Sjohnlev #if defined(__xpv) 7425084Sjohnlev /* 7435084Sjohnlev * Do not support MONITOR/MWAIT under a hypervisor 7445084Sjohnlev */ 7455084Sjohnlev mask_ecx &= ~CPUID_INTC_ECX_MON; 7465084Sjohnlev #endif /* __xpv */ 7475084Sjohnlev 7480Sstevel@tonic-gate /* 7490Sstevel@tonic-gate * Now we've figured out the masks that determine 7500Sstevel@tonic-gate * which bits we choose to believe, apply the masks 7510Sstevel@tonic-gate * to the feature words, then map the kernel's view 7520Sstevel@tonic-gate * of these feature words into its feature word. 7530Sstevel@tonic-gate */ 7540Sstevel@tonic-gate cp->cp_edx &= mask_edx; 7550Sstevel@tonic-gate cp->cp_ecx &= mask_ecx; 7560Sstevel@tonic-gate 7570Sstevel@tonic-gate /* 7583446Smrj * apply any platform restrictions (we don't call this 7593446Smrj * immediately after __cpuid_insn here, because we need the 7603446Smrj * workarounds applied above first) 7610Sstevel@tonic-gate */ 7623446Smrj platform_cpuid_mangle(cpi->cpi_vendor, 1, cp); 7630Sstevel@tonic-gate 7643446Smrj /* 7653446Smrj * fold in overrides from the "eeprom" mechanism 7663446Smrj */ 7670Sstevel@tonic-gate cp->cp_edx |= cpuid_feature_edx_include; 7680Sstevel@tonic-gate cp->cp_edx &= ~cpuid_feature_edx_exclude; 7690Sstevel@tonic-gate 7700Sstevel@tonic-gate cp->cp_ecx |= cpuid_feature_ecx_include; 7710Sstevel@tonic-gate cp->cp_ecx &= ~cpuid_feature_ecx_exclude; 7720Sstevel@tonic-gate 7730Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_PSE) 7740Sstevel@tonic-gate feature |= X86_LARGEPAGE; 7750Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_TSC) 7760Sstevel@tonic-gate feature |= X86_TSC; 7770Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_MSR) 7780Sstevel@tonic-gate feature |= X86_MSR; 7790Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_MTRR) 7800Sstevel@tonic-gate feature |= X86_MTRR; 7810Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_PGE) 7820Sstevel@tonic-gate feature |= X86_PGE; 7830Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_CMOV) 7840Sstevel@tonic-gate feature |= X86_CMOV; 7850Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_MMX) 7860Sstevel@tonic-gate feature |= X86_MMX; 7870Sstevel@tonic-gate if ((cp->cp_edx & CPUID_INTC_EDX_MCE) != 0 && 7880Sstevel@tonic-gate (cp->cp_edx & CPUID_INTC_EDX_MCA) != 0) 7890Sstevel@tonic-gate feature |= X86_MCA; 7900Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_PAE) 7910Sstevel@tonic-gate feature |= X86_PAE; 7920Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_CX8) 7930Sstevel@tonic-gate feature |= X86_CX8; 7940Sstevel@tonic-gate if (cp->cp_ecx & CPUID_INTC_ECX_CX16) 7950Sstevel@tonic-gate feature |= X86_CX16; 7960Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_PAT) 7970Sstevel@tonic-gate feature |= X86_PAT; 7980Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_SEP) 7990Sstevel@tonic-gate feature |= X86_SEP; 8000Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_FXSR) { 8010Sstevel@tonic-gate /* 8020Sstevel@tonic-gate * In our implementation, fxsave/fxrstor 8030Sstevel@tonic-gate * are prerequisites before we'll even 8040Sstevel@tonic-gate * try and do SSE things. 8050Sstevel@tonic-gate */ 8060Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_SSE) 8070Sstevel@tonic-gate feature |= X86_SSE; 8080Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_SSE2) 8090Sstevel@tonic-gate feature |= X86_SSE2; 8100Sstevel@tonic-gate if (cp->cp_ecx & CPUID_INTC_ECX_SSE3) 8110Sstevel@tonic-gate feature |= X86_SSE3; 8125269Skk208521 if (cpi->cpi_vendor == X86_VENDOR_Intel) { 8135269Skk208521 if (cp->cp_ecx & CPUID_INTC_ECX_SSSE3) 8145269Skk208521 feature |= X86_SSSE3; 8155269Skk208521 if (cp->cp_ecx & CPUID_INTC_ECX_SSE4_1) 8165269Skk208521 feature |= X86_SSE4_1; 8175269Skk208521 if (cp->cp_ecx & CPUID_INTC_ECX_SSE4_2) 8185269Skk208521 feature |= X86_SSE4_2; 8199370SKuriakose.Kuruvilla@Sun.COM if (cp->cp_ecx & CPUID_INTC_ECX_AES) 8209370SKuriakose.Kuruvilla@Sun.COM feature |= X86_AES; 8215269Skk208521 } 8220Sstevel@tonic-gate } 8230Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_DE) 8243446Smrj feature |= X86_DE; 8257716SBill.Holler@Sun.COM #if !defined(__xpv) 8264481Sbholler if (cp->cp_ecx & CPUID_INTC_ECX_MON) { 8277716SBill.Holler@Sun.COM 8287716SBill.Holler@Sun.COM /* 8297716SBill.Holler@Sun.COM * We require the CLFLUSH instruction for erratum workaround 8307716SBill.Holler@Sun.COM * to use MONITOR/MWAIT. 8317716SBill.Holler@Sun.COM */ 8327716SBill.Holler@Sun.COM if (cp->cp_edx & CPUID_INTC_EDX_CLFSH) { 8337716SBill.Holler@Sun.COM cpi->cpi_mwait.support |= MWAIT_SUPPORT; 8347716SBill.Holler@Sun.COM feature |= X86_MWAIT; 8357716SBill.Holler@Sun.COM } else { 8367716SBill.Holler@Sun.COM extern int idle_cpu_assert_cflush_monitor; 8377716SBill.Holler@Sun.COM 8387716SBill.Holler@Sun.COM /* 8397716SBill.Holler@Sun.COM * All processors we are aware of which have 8407716SBill.Holler@Sun.COM * MONITOR/MWAIT also have CLFLUSH. 8417716SBill.Holler@Sun.COM */ 8427716SBill.Holler@Sun.COM if (idle_cpu_assert_cflush_monitor) { 8437716SBill.Holler@Sun.COM ASSERT((cp->cp_ecx & CPUID_INTC_ECX_MON) && 8447716SBill.Holler@Sun.COM (cp->cp_edx & CPUID_INTC_EDX_CLFSH)); 8457716SBill.Holler@Sun.COM } 8467716SBill.Holler@Sun.COM } 8474481Sbholler } 8487716SBill.Holler@Sun.COM #endif /* __xpv */ 8490Sstevel@tonic-gate 8507589SVikram.Hegde@Sun.COM /* 8517589SVikram.Hegde@Sun.COM * Only need it first time, rest of the cpus would follow suite. 8527589SVikram.Hegde@Sun.COM * we only capture this for the bootcpu. 8537589SVikram.Hegde@Sun.COM */ 8547589SVikram.Hegde@Sun.COM if (cp->cp_edx & CPUID_INTC_EDX_CLFSH) { 8557589SVikram.Hegde@Sun.COM feature |= X86_CLFSH; 8567589SVikram.Hegde@Sun.COM x86_clflush_size = (BITX(cp->cp_ebx, 15, 8) * 8); 8577589SVikram.Hegde@Sun.COM } 8587589SVikram.Hegde@Sun.COM 8590Sstevel@tonic-gate if (feature & X86_PAE) 8600Sstevel@tonic-gate cpi->cpi_pabits = 36; 8610Sstevel@tonic-gate 8620Sstevel@tonic-gate /* 8630Sstevel@tonic-gate * Hyperthreading configuration is slightly tricky on Intel 8640Sstevel@tonic-gate * and pure clones, and even trickier on AMD. 8650Sstevel@tonic-gate * 8660Sstevel@tonic-gate * (AMD chose to set the HTT bit on their CMP processors, 8670Sstevel@tonic-gate * even though they're not actually hyperthreaded. Thus it 8680Sstevel@tonic-gate * takes a bit more work to figure out what's really going 8693446Smrj * on ... see the handling of the CMP_LGCY bit below) 8700Sstevel@tonic-gate */ 8710Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_HTT) { 8720Sstevel@tonic-gate cpi->cpi_ncpu_per_chip = CPI_CPU_COUNT(cpi); 8730Sstevel@tonic-gate if (cpi->cpi_ncpu_per_chip > 1) 8740Sstevel@tonic-gate feature |= X86_HTT; 8751228Sandrei } else { 8761228Sandrei cpi->cpi_ncpu_per_chip = 1; 8770Sstevel@tonic-gate } 8780Sstevel@tonic-gate 8790Sstevel@tonic-gate /* 8800Sstevel@tonic-gate * Work on the "extended" feature information, doing 8810Sstevel@tonic-gate * some basic initialization for cpuid_pass2() 8820Sstevel@tonic-gate */ 8830Sstevel@tonic-gate xcpuid = 0; 8840Sstevel@tonic-gate switch (cpi->cpi_vendor) { 8850Sstevel@tonic-gate case X86_VENDOR_Intel: 8861975Sdmick if (IS_NEW_F6(cpi) || cpi->cpi_family >= 0xf) 8870Sstevel@tonic-gate xcpuid++; 8880Sstevel@tonic-gate break; 8890Sstevel@tonic-gate case X86_VENDOR_AMD: 8900Sstevel@tonic-gate if (cpi->cpi_family > 5 || 8910Sstevel@tonic-gate (cpi->cpi_family == 5 && cpi->cpi_model >= 1)) 8920Sstevel@tonic-gate xcpuid++; 8930Sstevel@tonic-gate break; 8940Sstevel@tonic-gate case X86_VENDOR_Cyrix: 8950Sstevel@tonic-gate /* 8960Sstevel@tonic-gate * Only these Cyrix CPUs are -known- to support 8970Sstevel@tonic-gate * extended cpuid operations. 8980Sstevel@tonic-gate */ 8990Sstevel@tonic-gate if (x86_type == X86_TYPE_VIA_CYRIX_III || 9000Sstevel@tonic-gate x86_type == X86_TYPE_CYRIX_GXm) 9010Sstevel@tonic-gate xcpuid++; 9020Sstevel@tonic-gate break; 9030Sstevel@tonic-gate case X86_VENDOR_Centaur: 9040Sstevel@tonic-gate case X86_VENDOR_TM: 9050Sstevel@tonic-gate default: 9060Sstevel@tonic-gate xcpuid++; 9070Sstevel@tonic-gate break; 9080Sstevel@tonic-gate } 9090Sstevel@tonic-gate 9100Sstevel@tonic-gate if (xcpuid) { 9110Sstevel@tonic-gate cp = &cpi->cpi_extd[0]; 9121228Sandrei cp->cp_eax = 0x80000000; 9131228Sandrei cpi->cpi_xmaxeax = __cpuid_insn(cp); 9140Sstevel@tonic-gate } 9150Sstevel@tonic-gate 9160Sstevel@tonic-gate if (cpi->cpi_xmaxeax & 0x80000000) { 9170Sstevel@tonic-gate 9180Sstevel@tonic-gate if (cpi->cpi_xmaxeax > CPI_XMAXEAX_MAX) 9190Sstevel@tonic-gate cpi->cpi_xmaxeax = CPI_XMAXEAX_MAX; 9200Sstevel@tonic-gate 9210Sstevel@tonic-gate switch (cpi->cpi_vendor) { 9220Sstevel@tonic-gate case X86_VENDOR_Intel: 9230Sstevel@tonic-gate case X86_VENDOR_AMD: 9240Sstevel@tonic-gate if (cpi->cpi_xmaxeax < 0x80000001) 9250Sstevel@tonic-gate break; 9260Sstevel@tonic-gate cp = &cpi->cpi_extd[1]; 9271228Sandrei cp->cp_eax = 0x80000001; 9281228Sandrei (void) __cpuid_insn(cp); 9293446Smrj 9300Sstevel@tonic-gate if (cpi->cpi_vendor == X86_VENDOR_AMD && 9310Sstevel@tonic-gate cpi->cpi_family == 5 && 9320Sstevel@tonic-gate cpi->cpi_model == 6 && 9330Sstevel@tonic-gate cpi->cpi_step == 6) { 9340Sstevel@tonic-gate /* 9350Sstevel@tonic-gate * K6 model 6 uses bit 10 to indicate SYSC 9360Sstevel@tonic-gate * Later models use bit 11. Fix it here. 9370Sstevel@tonic-gate */ 9380Sstevel@tonic-gate if (cp->cp_edx & 0x400) { 9390Sstevel@tonic-gate cp->cp_edx &= ~0x400; 9400Sstevel@tonic-gate cp->cp_edx |= CPUID_AMD_EDX_SYSC; 9410Sstevel@tonic-gate } 9420Sstevel@tonic-gate } 9430Sstevel@tonic-gate 9443446Smrj platform_cpuid_mangle(cpi->cpi_vendor, 0x80000001, cp); 9453446Smrj 9460Sstevel@tonic-gate /* 9470Sstevel@tonic-gate * Compute the additions to the kernel's feature word. 9480Sstevel@tonic-gate */ 9490Sstevel@tonic-gate if (cp->cp_edx & CPUID_AMD_EDX_NX) 9500Sstevel@tonic-gate feature |= X86_NX; 9510Sstevel@tonic-gate 9527656SSherry.Moore@Sun.COM /* 9537656SSherry.Moore@Sun.COM * Regardless whether or not we boot 64-bit, 9547656SSherry.Moore@Sun.COM * we should have a way to identify whether 9557656SSherry.Moore@Sun.COM * the CPU is capable of running 64-bit. 9567656SSherry.Moore@Sun.COM */ 9577656SSherry.Moore@Sun.COM if (cp->cp_edx & CPUID_AMD_EDX_LM) 9587656SSherry.Moore@Sun.COM feature |= X86_64; 9597656SSherry.Moore@Sun.COM 9605349Skchow #if defined(__amd64) 9615349Skchow /* 1 GB large page - enable only for 64 bit kernel */ 9625349Skchow if (cp->cp_edx & CPUID_AMD_EDX_1GPG) 9635349Skchow feature |= X86_1GPG; 9645349Skchow #endif 9655349Skchow 9664628Skk208521 if ((cpi->cpi_vendor == X86_VENDOR_AMD) && 9674628Skk208521 (cpi->cpi_std[1].cp_edx & CPUID_INTC_EDX_FXSR) && 9684628Skk208521 (cp->cp_ecx & CPUID_AMD_ECX_SSE4A)) 9694628Skk208521 feature |= X86_SSE4A; 9704628Skk208521 9710Sstevel@tonic-gate /* 9723446Smrj * If both the HTT and CMP_LGCY bits are set, 9731228Sandrei * then we're not actually HyperThreaded. Read 9741228Sandrei * "AMD CPUID Specification" for more details. 9750Sstevel@tonic-gate */ 9760Sstevel@tonic-gate if (cpi->cpi_vendor == X86_VENDOR_AMD && 9771228Sandrei (feature & X86_HTT) && 9783446Smrj (cp->cp_ecx & CPUID_AMD_ECX_CMP_LGCY)) { 9790Sstevel@tonic-gate feature &= ~X86_HTT; 9801228Sandrei feature |= X86_CMP; 9811228Sandrei } 9823446Smrj #if defined(__amd64) 9830Sstevel@tonic-gate /* 9840Sstevel@tonic-gate * It's really tricky to support syscall/sysret in 9850Sstevel@tonic-gate * the i386 kernel; we rely on sysenter/sysexit 9860Sstevel@tonic-gate * instead. In the amd64 kernel, things are -way- 9870Sstevel@tonic-gate * better. 9880Sstevel@tonic-gate */ 9890Sstevel@tonic-gate if (cp->cp_edx & CPUID_AMD_EDX_SYSC) 9900Sstevel@tonic-gate feature |= X86_ASYSC; 9910Sstevel@tonic-gate 9920Sstevel@tonic-gate /* 9930Sstevel@tonic-gate * While we're thinking about system calls, note 9940Sstevel@tonic-gate * that AMD processors don't support sysenter 9950Sstevel@tonic-gate * in long mode at all, so don't try to program them. 9960Sstevel@tonic-gate */ 9970Sstevel@tonic-gate if (x86_vendor == X86_VENDOR_AMD) 9980Sstevel@tonic-gate feature &= ~X86_SEP; 9990Sstevel@tonic-gate #endif 10006657Ssudheer if (cp->cp_edx & CPUID_AMD_EDX_TSCP) 10013446Smrj feature |= X86_TSCP; 10020Sstevel@tonic-gate break; 10030Sstevel@tonic-gate default: 10040Sstevel@tonic-gate break; 10050Sstevel@tonic-gate } 10060Sstevel@tonic-gate 10071228Sandrei /* 10081228Sandrei * Get CPUID data about processor cores and hyperthreads. 10091228Sandrei */ 10100Sstevel@tonic-gate switch (cpi->cpi_vendor) { 10110Sstevel@tonic-gate case X86_VENDOR_Intel: 10121228Sandrei if (cpi->cpi_maxeax >= 4) { 10131228Sandrei cp = &cpi->cpi_std[4]; 10141228Sandrei cp->cp_eax = 4; 10151228Sandrei cp->cp_ecx = 0; 10161228Sandrei (void) __cpuid_insn(cp); 10173446Smrj platform_cpuid_mangle(cpi->cpi_vendor, 4, cp); 10181228Sandrei } 10191228Sandrei /*FALLTHROUGH*/ 10200Sstevel@tonic-gate case X86_VENDOR_AMD: 10210Sstevel@tonic-gate if (cpi->cpi_xmaxeax < 0x80000008) 10220Sstevel@tonic-gate break; 10230Sstevel@tonic-gate cp = &cpi->cpi_extd[8]; 10241228Sandrei cp->cp_eax = 0x80000008; 10251228Sandrei (void) __cpuid_insn(cp); 10263446Smrj platform_cpuid_mangle(cpi->cpi_vendor, 0x80000008, cp); 10273446Smrj 10280Sstevel@tonic-gate /* 10290Sstevel@tonic-gate * Virtual and physical address limits from 10300Sstevel@tonic-gate * cpuid override previously guessed values. 10310Sstevel@tonic-gate */ 10320Sstevel@tonic-gate cpi->cpi_pabits = BITX(cp->cp_eax, 7, 0); 10330Sstevel@tonic-gate cpi->cpi_vabits = BITX(cp->cp_eax, 15, 8); 10340Sstevel@tonic-gate break; 10350Sstevel@tonic-gate default: 10360Sstevel@tonic-gate break; 10370Sstevel@tonic-gate } 10381228Sandrei 10394606Sesaxe /* 10404606Sesaxe * Derive the number of cores per chip 10414606Sesaxe */ 10421228Sandrei switch (cpi->cpi_vendor) { 10431228Sandrei case X86_VENDOR_Intel: 10441228Sandrei if (cpi->cpi_maxeax < 4) { 10451228Sandrei cpi->cpi_ncore_per_chip = 1; 10461228Sandrei break; 10471228Sandrei } else { 10481228Sandrei cpi->cpi_ncore_per_chip = 10491228Sandrei BITX((cpi)->cpi_std[4].cp_eax, 31, 26) + 1; 10501228Sandrei } 10511228Sandrei break; 10521228Sandrei case X86_VENDOR_AMD: 10531228Sandrei if (cpi->cpi_xmaxeax < 0x80000008) { 10541228Sandrei cpi->cpi_ncore_per_chip = 1; 10551228Sandrei break; 10561228Sandrei } else { 10575870Sgavinm /* 10585870Sgavinm * On family 0xf cpuid fn 2 ECX[7:0] "NC" is 10595870Sgavinm * 1 less than the number of physical cores on 10605870Sgavinm * the chip. In family 0x10 this value can 10615870Sgavinm * be affected by "downcoring" - it reflects 10625870Sgavinm * 1 less than the number of cores actually 10635870Sgavinm * enabled on this node. 10645870Sgavinm */ 10651228Sandrei cpi->cpi_ncore_per_chip = 10661228Sandrei BITX((cpi)->cpi_extd[8].cp_ecx, 7, 0) + 1; 10671228Sandrei } 10681228Sandrei break; 10691228Sandrei default: 10701228Sandrei cpi->cpi_ncore_per_chip = 1; 10711228Sandrei break; 10721228Sandrei } 10738906SEric.Saxe@Sun.COM 10748906SEric.Saxe@Sun.COM /* 10758906SEric.Saxe@Sun.COM * Get CPUID data about TSC Invariance in Deep C-State. 10768906SEric.Saxe@Sun.COM */ 10778906SEric.Saxe@Sun.COM switch (cpi->cpi_vendor) { 10788906SEric.Saxe@Sun.COM case X86_VENDOR_Intel: 10798906SEric.Saxe@Sun.COM if (cpi->cpi_maxeax >= 7) { 10808906SEric.Saxe@Sun.COM cp = &cpi->cpi_extd[7]; 10818906SEric.Saxe@Sun.COM cp->cp_eax = 0x80000007; 10828906SEric.Saxe@Sun.COM cp->cp_ecx = 0; 10838906SEric.Saxe@Sun.COM (void) __cpuid_insn(cp); 10848906SEric.Saxe@Sun.COM } 10858906SEric.Saxe@Sun.COM break; 10868906SEric.Saxe@Sun.COM default: 10878906SEric.Saxe@Sun.COM break; 10888906SEric.Saxe@Sun.COM } 10895284Sgavinm } else { 10905284Sgavinm cpi->cpi_ncore_per_chip = 1; 10910Sstevel@tonic-gate } 10920Sstevel@tonic-gate 10931228Sandrei /* 10941228Sandrei * If more than one core, then this processor is CMP. 10951228Sandrei */ 10961228Sandrei if (cpi->cpi_ncore_per_chip > 1) 10971228Sandrei feature |= X86_CMP; 10983446Smrj 10991228Sandrei /* 11001228Sandrei * If the number of cores is the same as the number 11011228Sandrei * of CPUs, then we cannot have HyperThreading. 11021228Sandrei */ 11031228Sandrei if (cpi->cpi_ncpu_per_chip == cpi->cpi_ncore_per_chip) 11041228Sandrei feature &= ~X86_HTT; 11051228Sandrei 11060Sstevel@tonic-gate if ((feature & (X86_HTT | X86_CMP)) == 0) { 11071228Sandrei /* 11081228Sandrei * Single-core single-threaded processors. 11091228Sandrei */ 11100Sstevel@tonic-gate cpi->cpi_chipid = -1; 11110Sstevel@tonic-gate cpi->cpi_clogid = 0; 11121228Sandrei cpi->cpi_coreid = cpu->cpu_id; 11135870Sgavinm cpi->cpi_pkgcoreid = 0; 11140Sstevel@tonic-gate } else if (cpi->cpi_ncpu_per_chip > 1) { 11151228Sandrei uint_t i; 11161228Sandrei uint_t chipid_shift = 0; 11171228Sandrei uint_t coreid_shift = 0; 11181228Sandrei uint_t apic_id = CPI_APIC_ID(cpi); 11191228Sandrei 11201228Sandrei for (i = 1; i < cpi->cpi_ncpu_per_chip; i <<= 1) 11211228Sandrei chipid_shift++; 11221228Sandrei cpi->cpi_chipid = apic_id >> chipid_shift; 11231228Sandrei cpi->cpi_clogid = apic_id & ((1 << chipid_shift) - 1); 11240Sstevel@tonic-gate 11251228Sandrei if (cpi->cpi_vendor == X86_VENDOR_Intel) { 11261228Sandrei if (feature & X86_CMP) { 11271228Sandrei /* 11281228Sandrei * Multi-core (and possibly multi-threaded) 11291228Sandrei * processors. 11301228Sandrei */ 11311228Sandrei uint_t ncpu_per_core; 11321228Sandrei if (cpi->cpi_ncore_per_chip == 1) 11331228Sandrei ncpu_per_core = cpi->cpi_ncpu_per_chip; 11341228Sandrei else if (cpi->cpi_ncore_per_chip > 1) 11351228Sandrei ncpu_per_core = cpi->cpi_ncpu_per_chip / 11361228Sandrei cpi->cpi_ncore_per_chip; 11371228Sandrei /* 11381228Sandrei * 8bit APIC IDs on dual core Pentiums 11391228Sandrei * look like this: 11401228Sandrei * 11411228Sandrei * +-----------------------+------+------+ 11421228Sandrei * | Physical Package ID | MC | HT | 11431228Sandrei * +-----------------------+------+------+ 11441228Sandrei * <------- chipid --------> 11451228Sandrei * <------- coreid ---------------> 11461228Sandrei * <--- clogid --> 11475870Sgavinm * <------> 11485870Sgavinm * pkgcoreid 11491228Sandrei * 11501228Sandrei * Where the number of bits necessary to 11511228Sandrei * represent MC and HT fields together equals 11521228Sandrei * to the minimum number of bits necessary to 11531228Sandrei * store the value of cpi->cpi_ncpu_per_chip. 11541228Sandrei * Of those bits, the MC part uses the number 11551228Sandrei * of bits necessary to store the value of 11561228Sandrei * cpi->cpi_ncore_per_chip. 11571228Sandrei */ 11581228Sandrei for (i = 1; i < ncpu_per_core; i <<= 1) 11591228Sandrei coreid_shift++; 11601727Sandrei cpi->cpi_coreid = apic_id >> coreid_shift; 11615870Sgavinm cpi->cpi_pkgcoreid = cpi->cpi_clogid >> 11625870Sgavinm coreid_shift; 11631228Sandrei } else if (feature & X86_HTT) { 11641228Sandrei /* 11651228Sandrei * Single-core multi-threaded processors. 11661228Sandrei */ 11671228Sandrei cpi->cpi_coreid = cpi->cpi_chipid; 11685870Sgavinm cpi->cpi_pkgcoreid = 0; 11691228Sandrei } 11701228Sandrei } else if (cpi->cpi_vendor == X86_VENDOR_AMD) { 11711228Sandrei /* 11725870Sgavinm * AMD CMP chips currently have a single thread per 11735870Sgavinm * core, with 2 cores on family 0xf and 2, 3 or 4 11745870Sgavinm * cores on family 0x10. 11755870Sgavinm * 11765870Sgavinm * Since no two cpus share a core we must assign a 11775870Sgavinm * distinct coreid per cpu, and we do this by using 11785870Sgavinm * the cpu_id. This scheme does not, however, 11795870Sgavinm * guarantee that sibling cores of a chip will have 11805870Sgavinm * sequential coreids starting at a multiple of the 11815870Sgavinm * number of cores per chip - that is usually the 11825870Sgavinm * case, but if the ACPI MADT table is presented 11835870Sgavinm * in a different order then we need to perform a 11845870Sgavinm * few more gymnastics for the pkgcoreid. 11855870Sgavinm * 11865870Sgavinm * In family 0xf CMPs there are 2 cores on all nodes 11875870Sgavinm * present - no mixing of single and dual core parts. 11885870Sgavinm * 11895870Sgavinm * In family 0x10 CMPs cpuid fn 2 ECX[15:12] 11905870Sgavinm * "ApicIdCoreIdSize[3:0]" tells us how 11915870Sgavinm * many least-significant bits in the ApicId 11925870Sgavinm * are used to represent the core number 11935870Sgavinm * within the node. Cores are always 11945870Sgavinm * numbered sequentially from 0 regardless 11955870Sgavinm * of how many or which are disabled, and 11965870Sgavinm * there seems to be no way to discover the 11975870Sgavinm * real core id when some are disabled. 11981228Sandrei */ 11991228Sandrei cpi->cpi_coreid = cpu->cpu_id; 12005870Sgavinm 12015870Sgavinm if (cpi->cpi_family == 0x10 && 12025870Sgavinm cpi->cpi_xmaxeax >= 0x80000008) { 12035870Sgavinm int coreidsz = 12045870Sgavinm BITX((cpi)->cpi_extd[8].cp_ecx, 15, 12); 12055870Sgavinm 12065870Sgavinm cpi->cpi_pkgcoreid = 12075870Sgavinm apic_id & ((1 << coreidsz) - 1); 12085870Sgavinm } else { 12095870Sgavinm cpi->cpi_pkgcoreid = cpi->cpi_clogid; 12105870Sgavinm } 12111228Sandrei } else { 12121228Sandrei /* 12131228Sandrei * All other processors are currently 12141228Sandrei * assumed to have single cores. 12151228Sandrei */ 12161228Sandrei cpi->cpi_coreid = cpi->cpi_chipid; 12175870Sgavinm cpi->cpi_pkgcoreid = 0; 12181228Sandrei } 12190Sstevel@tonic-gate } 12200Sstevel@tonic-gate 12217282Smishra cpi->cpi_apicid = CPI_APIC_ID(cpi); 12227282Smishra 12232869Sgavinm /* 12242869Sgavinm * Synthesize chip "revision" and socket type 12252869Sgavinm */ 12267532SSean.Ye@Sun.COM cpi->cpi_chiprev = _cpuid_chiprev(cpi->cpi_vendor, cpi->cpi_family, 12277532SSean.Ye@Sun.COM cpi->cpi_model, cpi->cpi_step); 12287532SSean.Ye@Sun.COM cpi->cpi_chiprevstr = _cpuid_chiprevstr(cpi->cpi_vendor, 12297532SSean.Ye@Sun.COM cpi->cpi_family, cpi->cpi_model, cpi->cpi_step); 12307532SSean.Ye@Sun.COM cpi->cpi_socket = _cpuid_skt(cpi->cpi_vendor, cpi->cpi_family, 12317532SSean.Ye@Sun.COM cpi->cpi_model, cpi->cpi_step); 12322869Sgavinm 12330Sstevel@tonic-gate pass1_done: 12340Sstevel@tonic-gate cpi->cpi_pass = 1; 12350Sstevel@tonic-gate return (feature); 12360Sstevel@tonic-gate } 12370Sstevel@tonic-gate 12380Sstevel@tonic-gate /* 12390Sstevel@tonic-gate * Make copies of the cpuid table entries we depend on, in 12400Sstevel@tonic-gate * part for ease of parsing now, in part so that we have only 12410Sstevel@tonic-gate * one place to correct any of it, in part for ease of 12420Sstevel@tonic-gate * later export to userland, and in part so we can look at 12430Sstevel@tonic-gate * this stuff in a crash dump. 12440Sstevel@tonic-gate */ 12450Sstevel@tonic-gate 12460Sstevel@tonic-gate /*ARGSUSED*/ 12470Sstevel@tonic-gate void 12480Sstevel@tonic-gate cpuid_pass2(cpu_t *cpu) 12490Sstevel@tonic-gate { 12500Sstevel@tonic-gate uint_t n, nmax; 12510Sstevel@tonic-gate int i; 12521228Sandrei struct cpuid_regs *cp; 12530Sstevel@tonic-gate uint8_t *dp; 12540Sstevel@tonic-gate uint32_t *iptr; 12550Sstevel@tonic-gate struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 12560Sstevel@tonic-gate 12570Sstevel@tonic-gate ASSERT(cpi->cpi_pass == 1); 12580Sstevel@tonic-gate 12590Sstevel@tonic-gate if (cpi->cpi_maxeax < 1) 12600Sstevel@tonic-gate goto pass2_done; 12610Sstevel@tonic-gate 12620Sstevel@tonic-gate if ((nmax = cpi->cpi_maxeax + 1) > NMAX_CPI_STD) 12630Sstevel@tonic-gate nmax = NMAX_CPI_STD; 12640Sstevel@tonic-gate /* 12650Sstevel@tonic-gate * (We already handled n == 0 and n == 1 in pass 1) 12660Sstevel@tonic-gate */ 12670Sstevel@tonic-gate for (n = 2, cp = &cpi->cpi_std[2]; n < nmax; n++, cp++) { 12681228Sandrei cp->cp_eax = n; 12694606Sesaxe 12704606Sesaxe /* 12714606Sesaxe * CPUID function 4 expects %ecx to be initialized 12724606Sesaxe * with an index which indicates which cache to return 12734606Sesaxe * information about. The OS is expected to call function 4 12744606Sesaxe * with %ecx set to 0, 1, 2, ... until it returns with 12754606Sesaxe * EAX[4:0] set to 0, which indicates there are no more 12764606Sesaxe * caches. 12774606Sesaxe * 12784606Sesaxe * Here, populate cpi_std[4] with the information returned by 12794606Sesaxe * function 4 when %ecx == 0, and do the rest in cpuid_pass3() 12804606Sesaxe * when dynamic memory allocation becomes available. 12814606Sesaxe * 12824606Sesaxe * Note: we need to explicitly initialize %ecx here, since 12834606Sesaxe * function 4 may have been previously invoked. 12844606Sesaxe */ 12854606Sesaxe if (n == 4) 12864606Sesaxe cp->cp_ecx = 0; 12874606Sesaxe 12881228Sandrei (void) __cpuid_insn(cp); 12893446Smrj platform_cpuid_mangle(cpi->cpi_vendor, n, cp); 12900Sstevel@tonic-gate switch (n) { 12910Sstevel@tonic-gate case 2: 12920Sstevel@tonic-gate /* 12930Sstevel@tonic-gate * "the lower 8 bits of the %eax register 12940Sstevel@tonic-gate * contain a value that identifies the number 12950Sstevel@tonic-gate * of times the cpuid [instruction] has to be 12960Sstevel@tonic-gate * executed to obtain a complete image of the 12970Sstevel@tonic-gate * processor's caching systems." 12980Sstevel@tonic-gate * 12990Sstevel@tonic-gate * How *do* they make this stuff up? 13000Sstevel@tonic-gate */ 13010Sstevel@tonic-gate cpi->cpi_ncache = sizeof (*cp) * 13020Sstevel@tonic-gate BITX(cp->cp_eax, 7, 0); 13030Sstevel@tonic-gate if (cpi->cpi_ncache == 0) 13040Sstevel@tonic-gate break; 13050Sstevel@tonic-gate cpi->cpi_ncache--; /* skip count byte */ 13060Sstevel@tonic-gate 13070Sstevel@tonic-gate /* 13080Sstevel@tonic-gate * Well, for now, rather than attempt to implement 13090Sstevel@tonic-gate * this slightly dubious algorithm, we just look 13100Sstevel@tonic-gate * at the first 15 .. 13110Sstevel@tonic-gate */ 13120Sstevel@tonic-gate if (cpi->cpi_ncache > (sizeof (*cp) - 1)) 13130Sstevel@tonic-gate cpi->cpi_ncache = sizeof (*cp) - 1; 13140Sstevel@tonic-gate 13150Sstevel@tonic-gate dp = cpi->cpi_cacheinfo; 13160Sstevel@tonic-gate if (BITX(cp->cp_eax, 31, 31) == 0) { 13170Sstevel@tonic-gate uint8_t *p = (void *)&cp->cp_eax; 13186317Skk208521 for (i = 1; i < 4; i++) 13190Sstevel@tonic-gate if (p[i] != 0) 13200Sstevel@tonic-gate *dp++ = p[i]; 13210Sstevel@tonic-gate } 13220Sstevel@tonic-gate if (BITX(cp->cp_ebx, 31, 31) == 0) { 13230Sstevel@tonic-gate uint8_t *p = (void *)&cp->cp_ebx; 13240Sstevel@tonic-gate for (i = 0; i < 4; i++) 13250Sstevel@tonic-gate if (p[i] != 0) 13260Sstevel@tonic-gate *dp++ = p[i]; 13270Sstevel@tonic-gate } 13280Sstevel@tonic-gate if (BITX(cp->cp_ecx, 31, 31) == 0) { 13290Sstevel@tonic-gate uint8_t *p = (void *)&cp->cp_ecx; 13300Sstevel@tonic-gate for (i = 0; i < 4; i++) 13310Sstevel@tonic-gate if (p[i] != 0) 13320Sstevel@tonic-gate *dp++ = p[i]; 13330Sstevel@tonic-gate } 13340Sstevel@tonic-gate if (BITX(cp->cp_edx, 31, 31) == 0) { 13350Sstevel@tonic-gate uint8_t *p = (void *)&cp->cp_edx; 13360Sstevel@tonic-gate for (i = 0; i < 4; i++) 13370Sstevel@tonic-gate if (p[i] != 0) 13380Sstevel@tonic-gate *dp++ = p[i]; 13390Sstevel@tonic-gate } 13400Sstevel@tonic-gate break; 13414481Sbholler 13420Sstevel@tonic-gate case 3: /* Processor serial number, if PSN supported */ 13434481Sbholler break; 13444481Sbholler 13450Sstevel@tonic-gate case 4: /* Deterministic cache parameters */ 13464481Sbholler break; 13474481Sbholler 13480Sstevel@tonic-gate case 5: /* Monitor/Mwait parameters */ 13495045Sbholler { 13505045Sbholler size_t mwait_size; 13514481Sbholler 13524481Sbholler /* 13534481Sbholler * check cpi_mwait.support which was set in cpuid_pass1 13544481Sbholler */ 13554481Sbholler if (!(cpi->cpi_mwait.support & MWAIT_SUPPORT)) 13564481Sbholler break; 13574481Sbholler 13585045Sbholler /* 13595045Sbholler * Protect ourself from insane mwait line size. 13605045Sbholler * Workaround for incomplete hardware emulator(s). 13615045Sbholler */ 13625045Sbholler mwait_size = (size_t)MWAIT_SIZE_MAX(cpi); 13635045Sbholler if (mwait_size < sizeof (uint32_t) || 13645045Sbholler !ISP2(mwait_size)) { 13655045Sbholler #if DEBUG 13665045Sbholler cmn_err(CE_NOTE, "Cannot handle cpu %d mwait " 13677798SSaurabh.Mishra@Sun.COM "size %ld", cpu->cpu_id, (long)mwait_size); 13685045Sbholler #endif 13695045Sbholler break; 13705045Sbholler } 13715045Sbholler 13724481Sbholler cpi->cpi_mwait.mon_min = (size_t)MWAIT_SIZE_MIN(cpi); 13735045Sbholler cpi->cpi_mwait.mon_max = mwait_size; 13744481Sbholler if (MWAIT_EXTENSION(cpi)) { 13754481Sbholler cpi->cpi_mwait.support |= MWAIT_EXTENSIONS; 13764481Sbholler if (MWAIT_INT_ENABLE(cpi)) 13774481Sbholler cpi->cpi_mwait.support |= 13784481Sbholler MWAIT_ECX_INT_ENABLE; 13794481Sbholler } 13804481Sbholler break; 13815045Sbholler } 13820Sstevel@tonic-gate default: 13830Sstevel@tonic-gate break; 13840Sstevel@tonic-gate } 13850Sstevel@tonic-gate } 13860Sstevel@tonic-gate 13877282Smishra if (cpi->cpi_maxeax >= 0xB && cpi->cpi_vendor == X86_VENDOR_Intel) { 13887798SSaurabh.Mishra@Sun.COM struct cpuid_regs regs; 13897798SSaurabh.Mishra@Sun.COM 13907798SSaurabh.Mishra@Sun.COM cp = ®s; 13917282Smishra cp->cp_eax = 0xB; 13927798SSaurabh.Mishra@Sun.COM cp->cp_edx = cp->cp_ebx = cp->cp_ecx = 0; 13937282Smishra 13947282Smishra (void) __cpuid_insn(cp); 13957282Smishra 13967282Smishra /* 13977282Smishra * Check CPUID.EAX=0BH, ECX=0H:EBX is non-zero, which 13987282Smishra * indicates that the extended topology enumeration leaf is 13997282Smishra * available. 14007282Smishra */ 14017282Smishra if (cp->cp_ebx) { 14027282Smishra uint32_t x2apic_id; 14037282Smishra uint_t coreid_shift = 0; 14047282Smishra uint_t ncpu_per_core = 1; 14057282Smishra uint_t chipid_shift = 0; 14067282Smishra uint_t ncpu_per_chip = 1; 14077282Smishra uint_t i; 14087282Smishra uint_t level; 14097282Smishra 14107282Smishra for (i = 0; i < CPI_FNB_ECX_MAX; i++) { 14117282Smishra cp->cp_eax = 0xB; 14127282Smishra cp->cp_ecx = i; 14137282Smishra 14147282Smishra (void) __cpuid_insn(cp); 14157282Smishra level = CPI_CPU_LEVEL_TYPE(cp); 14167282Smishra 14177282Smishra if (level == 1) { 14187282Smishra x2apic_id = cp->cp_edx; 14197282Smishra coreid_shift = BITX(cp->cp_eax, 4, 0); 14207282Smishra ncpu_per_core = BITX(cp->cp_ebx, 15, 0); 14217282Smishra } else if (level == 2) { 14227282Smishra x2apic_id = cp->cp_edx; 14237282Smishra chipid_shift = BITX(cp->cp_eax, 4, 0); 14247282Smishra ncpu_per_chip = BITX(cp->cp_ebx, 15, 0); 14257282Smishra } 14267282Smishra } 14277282Smishra 14287282Smishra cpi->cpi_apicid = x2apic_id; 14297282Smishra cpi->cpi_ncpu_per_chip = ncpu_per_chip; 14307282Smishra cpi->cpi_ncore_per_chip = ncpu_per_chip / 14317282Smishra ncpu_per_core; 14327282Smishra cpi->cpi_chipid = x2apic_id >> chipid_shift; 14337282Smishra cpi->cpi_clogid = x2apic_id & ((1 << chipid_shift) - 1); 14347282Smishra cpi->cpi_coreid = x2apic_id >> coreid_shift; 14357282Smishra cpi->cpi_pkgcoreid = cpi->cpi_clogid >> coreid_shift; 14367282Smishra } 14377798SSaurabh.Mishra@Sun.COM 14387798SSaurabh.Mishra@Sun.COM /* Make cp NULL so that we don't stumble on others */ 14397798SSaurabh.Mishra@Sun.COM cp = NULL; 14407282Smishra } 14417282Smishra 14420Sstevel@tonic-gate if ((cpi->cpi_xmaxeax & 0x80000000) == 0) 14430Sstevel@tonic-gate goto pass2_done; 14440Sstevel@tonic-gate 14450Sstevel@tonic-gate if ((nmax = cpi->cpi_xmaxeax - 0x80000000 + 1) > NMAX_CPI_EXTD) 14460Sstevel@tonic-gate nmax = NMAX_CPI_EXTD; 14470Sstevel@tonic-gate /* 14480Sstevel@tonic-gate * Copy the extended properties, fixing them as we go. 14490Sstevel@tonic-gate * (We already handled n == 0 and n == 1 in pass 1) 14500Sstevel@tonic-gate */ 14510Sstevel@tonic-gate iptr = (void *)cpi->cpi_brandstr; 14520Sstevel@tonic-gate for (n = 2, cp = &cpi->cpi_extd[2]; n < nmax; cp++, n++) { 14531228Sandrei cp->cp_eax = 0x80000000 + n; 14541228Sandrei (void) __cpuid_insn(cp); 14553446Smrj platform_cpuid_mangle(cpi->cpi_vendor, 0x80000000 + n, cp); 14560Sstevel@tonic-gate switch (n) { 14570Sstevel@tonic-gate case 2: 14580Sstevel@tonic-gate case 3: 14590Sstevel@tonic-gate case 4: 14600Sstevel@tonic-gate /* 14610Sstevel@tonic-gate * Extract the brand string 14620Sstevel@tonic-gate */ 14630Sstevel@tonic-gate *iptr++ = cp->cp_eax; 14640Sstevel@tonic-gate *iptr++ = cp->cp_ebx; 14650Sstevel@tonic-gate *iptr++ = cp->cp_ecx; 14660Sstevel@tonic-gate *iptr++ = cp->cp_edx; 14670Sstevel@tonic-gate break; 14680Sstevel@tonic-gate case 5: 14690Sstevel@tonic-gate switch (cpi->cpi_vendor) { 14700Sstevel@tonic-gate case X86_VENDOR_AMD: 14710Sstevel@tonic-gate /* 14720Sstevel@tonic-gate * The Athlon and Duron were the first 14730Sstevel@tonic-gate * parts to report the sizes of the 14740Sstevel@tonic-gate * TLB for large pages. Before then, 14750Sstevel@tonic-gate * we don't trust the data. 14760Sstevel@tonic-gate */ 14770Sstevel@tonic-gate if (cpi->cpi_family < 6 || 14780Sstevel@tonic-gate (cpi->cpi_family == 6 && 14790Sstevel@tonic-gate cpi->cpi_model < 1)) 14800Sstevel@tonic-gate cp->cp_eax = 0; 14810Sstevel@tonic-gate break; 14820Sstevel@tonic-gate default: 14830Sstevel@tonic-gate break; 14840Sstevel@tonic-gate } 14850Sstevel@tonic-gate break; 14860Sstevel@tonic-gate case 6: 14870Sstevel@tonic-gate switch (cpi->cpi_vendor) { 14880Sstevel@tonic-gate case X86_VENDOR_AMD: 14890Sstevel@tonic-gate /* 14900Sstevel@tonic-gate * The Athlon and Duron were the first 14910Sstevel@tonic-gate * AMD parts with L2 TLB's. 14920Sstevel@tonic-gate * Before then, don't trust the data. 14930Sstevel@tonic-gate */ 14940Sstevel@tonic-gate if (cpi->cpi_family < 6 || 14950Sstevel@tonic-gate cpi->cpi_family == 6 && 14960Sstevel@tonic-gate cpi->cpi_model < 1) 14970Sstevel@tonic-gate cp->cp_eax = cp->cp_ebx = 0; 14980Sstevel@tonic-gate /* 14990Sstevel@tonic-gate * AMD Duron rev A0 reports L2 15000Sstevel@tonic-gate * cache size incorrectly as 1K 15010Sstevel@tonic-gate * when it is really 64K 15020Sstevel@tonic-gate */ 15030Sstevel@tonic-gate if (cpi->cpi_family == 6 && 15040Sstevel@tonic-gate cpi->cpi_model == 3 && 15050Sstevel@tonic-gate cpi->cpi_step == 0) { 15060Sstevel@tonic-gate cp->cp_ecx &= 0xffff; 15070Sstevel@tonic-gate cp->cp_ecx |= 0x400000; 15080Sstevel@tonic-gate } 15090Sstevel@tonic-gate break; 15100Sstevel@tonic-gate case X86_VENDOR_Cyrix: /* VIA C3 */ 15110Sstevel@tonic-gate /* 15120Sstevel@tonic-gate * VIA C3 processors are a bit messed 15130Sstevel@tonic-gate * up w.r.t. encoding cache sizes in %ecx 15140Sstevel@tonic-gate */ 15150Sstevel@tonic-gate if (cpi->cpi_family != 6) 15160Sstevel@tonic-gate break; 15170Sstevel@tonic-gate /* 15180Sstevel@tonic-gate * model 7 and 8 were incorrectly encoded 15190Sstevel@tonic-gate * 15200Sstevel@tonic-gate * xxx is model 8 really broken? 15210Sstevel@tonic-gate */ 15220Sstevel@tonic-gate if (cpi->cpi_model == 7 || 15230Sstevel@tonic-gate cpi->cpi_model == 8) 15240Sstevel@tonic-gate cp->cp_ecx = 15250Sstevel@tonic-gate BITX(cp->cp_ecx, 31, 24) << 16 | 15260Sstevel@tonic-gate BITX(cp->cp_ecx, 23, 16) << 12 | 15270Sstevel@tonic-gate BITX(cp->cp_ecx, 15, 8) << 8 | 15280Sstevel@tonic-gate BITX(cp->cp_ecx, 7, 0); 15290Sstevel@tonic-gate /* 15300Sstevel@tonic-gate * model 9 stepping 1 has wrong associativity 15310Sstevel@tonic-gate */ 15320Sstevel@tonic-gate if (cpi->cpi_model == 9 && cpi->cpi_step == 1) 15330Sstevel@tonic-gate cp->cp_ecx |= 8 << 12; 15340Sstevel@tonic-gate break; 15350Sstevel@tonic-gate case X86_VENDOR_Intel: 15360Sstevel@tonic-gate /* 15370Sstevel@tonic-gate * Extended L2 Cache features function. 15380Sstevel@tonic-gate * First appeared on Prescott. 15390Sstevel@tonic-gate */ 15400Sstevel@tonic-gate default: 15410Sstevel@tonic-gate break; 15420Sstevel@tonic-gate } 15430Sstevel@tonic-gate break; 15440Sstevel@tonic-gate default: 15450Sstevel@tonic-gate break; 15460Sstevel@tonic-gate } 15470Sstevel@tonic-gate } 15480Sstevel@tonic-gate 15490Sstevel@tonic-gate pass2_done: 15500Sstevel@tonic-gate cpi->cpi_pass = 2; 15510Sstevel@tonic-gate } 15520Sstevel@tonic-gate 15530Sstevel@tonic-gate static const char * 15540Sstevel@tonic-gate intel_cpubrand(const struct cpuid_info *cpi) 15550Sstevel@tonic-gate { 15560Sstevel@tonic-gate int i; 15570Sstevel@tonic-gate 15580Sstevel@tonic-gate if ((x86_feature & X86_CPUID) == 0 || 15590Sstevel@tonic-gate cpi->cpi_maxeax < 1 || cpi->cpi_family < 5) 15600Sstevel@tonic-gate return ("i486"); 15610Sstevel@tonic-gate 15620Sstevel@tonic-gate switch (cpi->cpi_family) { 15630Sstevel@tonic-gate case 5: 15640Sstevel@tonic-gate return ("Intel Pentium(r)"); 15650Sstevel@tonic-gate case 6: 15660Sstevel@tonic-gate switch (cpi->cpi_model) { 15670Sstevel@tonic-gate uint_t celeron, xeon; 15681228Sandrei const struct cpuid_regs *cp; 15690Sstevel@tonic-gate case 0: 15700Sstevel@tonic-gate case 1: 15710Sstevel@tonic-gate case 2: 15720Sstevel@tonic-gate return ("Intel Pentium(r) Pro"); 15730Sstevel@tonic-gate case 3: 15740Sstevel@tonic-gate case 4: 15750Sstevel@tonic-gate return ("Intel Pentium(r) II"); 15760Sstevel@tonic-gate case 6: 15770Sstevel@tonic-gate return ("Intel Celeron(r)"); 15780Sstevel@tonic-gate case 5: 15790Sstevel@tonic-gate case 7: 15800Sstevel@tonic-gate celeron = xeon = 0; 15810Sstevel@tonic-gate cp = &cpi->cpi_std[2]; /* cache info */ 15820Sstevel@tonic-gate 15836317Skk208521 for (i = 1; i < 4; i++) { 15840Sstevel@tonic-gate uint_t tmp; 15850Sstevel@tonic-gate 15860Sstevel@tonic-gate tmp = (cp->cp_eax >> (8 * i)) & 0xff; 15870Sstevel@tonic-gate if (tmp == 0x40) 15880Sstevel@tonic-gate celeron++; 15890Sstevel@tonic-gate if (tmp >= 0x44 && tmp <= 0x45) 15900Sstevel@tonic-gate xeon++; 15910Sstevel@tonic-gate } 15920Sstevel@tonic-gate 15930Sstevel@tonic-gate for (i = 0; i < 2; i++) { 15940Sstevel@tonic-gate uint_t tmp; 15950Sstevel@tonic-gate 15960Sstevel@tonic-gate tmp = (cp->cp_ebx >> (8 * i)) & 0xff; 15970Sstevel@tonic-gate if (tmp == 0x40) 15980Sstevel@tonic-gate celeron++; 15990Sstevel@tonic-gate else if (tmp >= 0x44 && tmp <= 0x45) 16000Sstevel@tonic-gate xeon++; 16010Sstevel@tonic-gate } 16020Sstevel@tonic-gate 16030Sstevel@tonic-gate for (i = 0; i < 4; i++) { 16040Sstevel@tonic-gate uint_t tmp; 16050Sstevel@tonic-gate 16060Sstevel@tonic-gate tmp = (cp->cp_ecx >> (8 * i)) & 0xff; 16070Sstevel@tonic-gate if (tmp == 0x40) 16080Sstevel@tonic-gate celeron++; 16090Sstevel@tonic-gate else if (tmp >= 0x44 && tmp <= 0x45) 16100Sstevel@tonic-gate xeon++; 16110Sstevel@tonic-gate } 16120Sstevel@tonic-gate 16130Sstevel@tonic-gate for (i = 0; i < 4; i++) { 16140Sstevel@tonic-gate uint_t tmp; 16150Sstevel@tonic-gate 16160Sstevel@tonic-gate tmp = (cp->cp_edx >> (8 * i)) & 0xff; 16170Sstevel@tonic-gate if (tmp == 0x40) 16180Sstevel@tonic-gate celeron++; 16190Sstevel@tonic-gate else if (tmp >= 0x44 && tmp <= 0x45) 16200Sstevel@tonic-gate xeon++; 16210Sstevel@tonic-gate } 16220Sstevel@tonic-gate 16230Sstevel@tonic-gate if (celeron) 16240Sstevel@tonic-gate return ("Intel Celeron(r)"); 16250Sstevel@tonic-gate if (xeon) 16260Sstevel@tonic-gate return (cpi->cpi_model == 5 ? 16270Sstevel@tonic-gate "Intel Pentium(r) II Xeon(tm)" : 16280Sstevel@tonic-gate "Intel Pentium(r) III Xeon(tm)"); 16290Sstevel@tonic-gate return (cpi->cpi_model == 5 ? 16300Sstevel@tonic-gate "Intel Pentium(r) II or Pentium(r) II Xeon(tm)" : 16310Sstevel@tonic-gate "Intel Pentium(r) III or Pentium(r) III Xeon(tm)"); 16320Sstevel@tonic-gate default: 16330Sstevel@tonic-gate break; 16340Sstevel@tonic-gate } 16350Sstevel@tonic-gate default: 16360Sstevel@tonic-gate break; 16370Sstevel@tonic-gate } 16380Sstevel@tonic-gate 16391975Sdmick /* BrandID is present if the field is nonzero */ 16401975Sdmick if (cpi->cpi_brandid != 0) { 16410Sstevel@tonic-gate static const struct { 16420Sstevel@tonic-gate uint_t bt_bid; 16430Sstevel@tonic-gate const char *bt_str; 16440Sstevel@tonic-gate } brand_tbl[] = { 16450Sstevel@tonic-gate { 0x1, "Intel(r) Celeron(r)" }, 16460Sstevel@tonic-gate { 0x2, "Intel(r) Pentium(r) III" }, 16470Sstevel@tonic-gate { 0x3, "Intel(r) Pentium(r) III Xeon(tm)" }, 16480Sstevel@tonic-gate { 0x4, "Intel(r) Pentium(r) III" }, 16490Sstevel@tonic-gate { 0x6, "Mobile Intel(r) Pentium(r) III" }, 16500Sstevel@tonic-gate { 0x7, "Mobile Intel(r) Celeron(r)" }, 16510Sstevel@tonic-gate { 0x8, "Intel(r) Pentium(r) 4" }, 16520Sstevel@tonic-gate { 0x9, "Intel(r) Pentium(r) 4" }, 16530Sstevel@tonic-gate { 0xa, "Intel(r) Celeron(r)" }, 16540Sstevel@tonic-gate { 0xb, "Intel(r) Xeon(tm)" }, 16550Sstevel@tonic-gate { 0xc, "Intel(r) Xeon(tm) MP" }, 16560Sstevel@tonic-gate { 0xe, "Mobile Intel(r) Pentium(r) 4" }, 16571975Sdmick { 0xf, "Mobile Intel(r) Celeron(r)" }, 16581975Sdmick { 0x11, "Mobile Genuine Intel(r)" }, 16591975Sdmick { 0x12, "Intel(r) Celeron(r) M" }, 16601975Sdmick { 0x13, "Mobile Intel(r) Celeron(r)" }, 16611975Sdmick { 0x14, "Intel(r) Celeron(r)" }, 16621975Sdmick { 0x15, "Mobile Genuine Intel(r)" }, 16631975Sdmick { 0x16, "Intel(r) Pentium(r) M" }, 16641975Sdmick { 0x17, "Mobile Intel(r) Celeron(r)" } 16650Sstevel@tonic-gate }; 16660Sstevel@tonic-gate uint_t btblmax = sizeof (brand_tbl) / sizeof (brand_tbl[0]); 16670Sstevel@tonic-gate uint_t sgn; 16680Sstevel@tonic-gate 16690Sstevel@tonic-gate sgn = (cpi->cpi_family << 8) | 16700Sstevel@tonic-gate (cpi->cpi_model << 4) | cpi->cpi_step; 16710Sstevel@tonic-gate 16720Sstevel@tonic-gate for (i = 0; i < btblmax; i++) 16730Sstevel@tonic-gate if (brand_tbl[i].bt_bid == cpi->cpi_brandid) 16740Sstevel@tonic-gate break; 16750Sstevel@tonic-gate if (i < btblmax) { 16760Sstevel@tonic-gate if (sgn == 0x6b1 && cpi->cpi_brandid == 3) 16770Sstevel@tonic-gate return ("Intel(r) Celeron(r)"); 16780Sstevel@tonic-gate if (sgn < 0xf13 && cpi->cpi_brandid == 0xb) 16790Sstevel@tonic-gate return ("Intel(r) Xeon(tm) MP"); 16800Sstevel@tonic-gate if (sgn < 0xf13 && cpi->cpi_brandid == 0xe) 16810Sstevel@tonic-gate return ("Intel(r) Xeon(tm)"); 16820Sstevel@tonic-gate return (brand_tbl[i].bt_str); 16830Sstevel@tonic-gate } 16840Sstevel@tonic-gate } 16850Sstevel@tonic-gate 16860Sstevel@tonic-gate return (NULL); 16870Sstevel@tonic-gate } 16880Sstevel@tonic-gate 16890Sstevel@tonic-gate static const char * 16900Sstevel@tonic-gate amd_cpubrand(const struct cpuid_info *cpi) 16910Sstevel@tonic-gate { 16920Sstevel@tonic-gate if ((x86_feature & X86_CPUID) == 0 || 16930Sstevel@tonic-gate cpi->cpi_maxeax < 1 || cpi->cpi_family < 5) 16940Sstevel@tonic-gate return ("i486 compatible"); 16950Sstevel@tonic-gate 16960Sstevel@tonic-gate switch (cpi->cpi_family) { 16970Sstevel@tonic-gate case 5: 16980Sstevel@tonic-gate switch (cpi->cpi_model) { 16990Sstevel@tonic-gate case 0: 17000Sstevel@tonic-gate case 1: 17010Sstevel@tonic-gate case 2: 17020Sstevel@tonic-gate case 3: 17030Sstevel@tonic-gate case 4: 17040Sstevel@tonic-gate case 5: 17050Sstevel@tonic-gate return ("AMD-K5(r)"); 17060Sstevel@tonic-gate case 6: 17070Sstevel@tonic-gate case 7: 17080Sstevel@tonic-gate return ("AMD-K6(r)"); 17090Sstevel@tonic-gate case 8: 17100Sstevel@tonic-gate return ("AMD-K6(r)-2"); 17110Sstevel@tonic-gate case 9: 17120Sstevel@tonic-gate return ("AMD-K6(r)-III"); 17130Sstevel@tonic-gate default: 17140Sstevel@tonic-gate return ("AMD (family 5)"); 17150Sstevel@tonic-gate } 17160Sstevel@tonic-gate case 6: 17170Sstevel@tonic-gate switch (cpi->cpi_model) { 17180Sstevel@tonic-gate case 1: 17190Sstevel@tonic-gate return ("AMD-K7(tm)"); 17200Sstevel@tonic-gate case 0: 17210Sstevel@tonic-gate case 2: 17220Sstevel@tonic-gate case 4: 17230Sstevel@tonic-gate return ("AMD Athlon(tm)"); 17240Sstevel@tonic-gate case 3: 17250Sstevel@tonic-gate case 7: 17260Sstevel@tonic-gate return ("AMD Duron(tm)"); 17270Sstevel@tonic-gate case 6: 17280Sstevel@tonic-gate case 8: 17290Sstevel@tonic-gate case 10: 17300Sstevel@tonic-gate /* 17310Sstevel@tonic-gate * Use the L2 cache size to distinguish 17320Sstevel@tonic-gate */ 17330Sstevel@tonic-gate return ((cpi->cpi_extd[6].cp_ecx >> 16) >= 256 ? 17340Sstevel@tonic-gate "AMD Athlon(tm)" : "AMD Duron(tm)"); 17350Sstevel@tonic-gate default: 17360Sstevel@tonic-gate return ("AMD (family 6)"); 17370Sstevel@tonic-gate } 17380Sstevel@tonic-gate default: 17390Sstevel@tonic-gate break; 17400Sstevel@tonic-gate } 17410Sstevel@tonic-gate 17420Sstevel@tonic-gate if (cpi->cpi_family == 0xf && cpi->cpi_model == 5 && 17430Sstevel@tonic-gate cpi->cpi_brandid != 0) { 17440Sstevel@tonic-gate switch (BITX(cpi->cpi_brandid, 7, 5)) { 17450Sstevel@tonic-gate case 3: 17460Sstevel@tonic-gate return ("AMD Opteron(tm) UP 1xx"); 17470Sstevel@tonic-gate case 4: 17480Sstevel@tonic-gate return ("AMD Opteron(tm) DP 2xx"); 17490Sstevel@tonic-gate case 5: 17500Sstevel@tonic-gate return ("AMD Opteron(tm) MP 8xx"); 17510Sstevel@tonic-gate default: 17520Sstevel@tonic-gate return ("AMD Opteron(tm)"); 17530Sstevel@tonic-gate } 17540Sstevel@tonic-gate } 17550Sstevel@tonic-gate 17560Sstevel@tonic-gate return (NULL); 17570Sstevel@tonic-gate } 17580Sstevel@tonic-gate 17590Sstevel@tonic-gate static const char * 17600Sstevel@tonic-gate cyrix_cpubrand(struct cpuid_info *cpi, uint_t type) 17610Sstevel@tonic-gate { 17620Sstevel@tonic-gate if ((x86_feature & X86_CPUID) == 0 || 17630Sstevel@tonic-gate cpi->cpi_maxeax < 1 || cpi->cpi_family < 5 || 17640Sstevel@tonic-gate type == X86_TYPE_CYRIX_486) 17650Sstevel@tonic-gate return ("i486 compatible"); 17660Sstevel@tonic-gate 17670Sstevel@tonic-gate switch (type) { 17680Sstevel@tonic-gate case X86_TYPE_CYRIX_6x86: 17690Sstevel@tonic-gate return ("Cyrix 6x86"); 17700Sstevel@tonic-gate case X86_TYPE_CYRIX_6x86L: 17710Sstevel@tonic-gate return ("Cyrix 6x86L"); 17720Sstevel@tonic-gate case X86_TYPE_CYRIX_6x86MX: 17730Sstevel@tonic-gate return ("Cyrix 6x86MX"); 17740Sstevel@tonic-gate case X86_TYPE_CYRIX_GXm: 17750Sstevel@tonic-gate return ("Cyrix GXm"); 17760Sstevel@tonic-gate case X86_TYPE_CYRIX_MediaGX: 17770Sstevel@tonic-gate return ("Cyrix MediaGX"); 17780Sstevel@tonic-gate case X86_TYPE_CYRIX_MII: 17790Sstevel@tonic-gate return ("Cyrix M2"); 17800Sstevel@tonic-gate case X86_TYPE_VIA_CYRIX_III: 17810Sstevel@tonic-gate return ("VIA Cyrix M3"); 17820Sstevel@tonic-gate default: 17830Sstevel@tonic-gate /* 17840Sstevel@tonic-gate * Have another wild guess .. 17850Sstevel@tonic-gate */ 17860Sstevel@tonic-gate if (cpi->cpi_family == 4 && cpi->cpi_model == 9) 17870Sstevel@tonic-gate return ("Cyrix 5x86"); 17880Sstevel@tonic-gate else if (cpi->cpi_family == 5) { 17890Sstevel@tonic-gate switch (cpi->cpi_model) { 17900Sstevel@tonic-gate case 2: 17910Sstevel@tonic-gate return ("Cyrix 6x86"); /* Cyrix M1 */ 17920Sstevel@tonic-gate case 4: 17930Sstevel@tonic-gate return ("Cyrix MediaGX"); 17940Sstevel@tonic-gate default: 17950Sstevel@tonic-gate break; 17960Sstevel@tonic-gate } 17970Sstevel@tonic-gate } else if (cpi->cpi_family == 6) { 17980Sstevel@tonic-gate switch (cpi->cpi_model) { 17990Sstevel@tonic-gate case 0: 18000Sstevel@tonic-gate return ("Cyrix 6x86MX"); /* Cyrix M2? */ 18010Sstevel@tonic-gate case 5: 18020Sstevel@tonic-gate case 6: 18030Sstevel@tonic-gate case 7: 18040Sstevel@tonic-gate case 8: 18050Sstevel@tonic-gate case 9: 18060Sstevel@tonic-gate return ("VIA C3"); 18070Sstevel@tonic-gate default: 18080Sstevel@tonic-gate break; 18090Sstevel@tonic-gate } 18100Sstevel@tonic-gate } 18110Sstevel@tonic-gate break; 18120Sstevel@tonic-gate } 18130Sstevel@tonic-gate return (NULL); 18140Sstevel@tonic-gate } 18150Sstevel@tonic-gate 18160Sstevel@tonic-gate /* 18170Sstevel@tonic-gate * This only gets called in the case that the CPU extended 18180Sstevel@tonic-gate * feature brand string (0x80000002, 0x80000003, 0x80000004) 18190Sstevel@tonic-gate * aren't available, or contain null bytes for some reason. 18200Sstevel@tonic-gate */ 18210Sstevel@tonic-gate static void 18220Sstevel@tonic-gate fabricate_brandstr(struct cpuid_info *cpi) 18230Sstevel@tonic-gate { 18240Sstevel@tonic-gate const char *brand = NULL; 18250Sstevel@tonic-gate 18260Sstevel@tonic-gate switch (cpi->cpi_vendor) { 18270Sstevel@tonic-gate case X86_VENDOR_Intel: 18280Sstevel@tonic-gate brand = intel_cpubrand(cpi); 18290Sstevel@tonic-gate break; 18300Sstevel@tonic-gate case X86_VENDOR_AMD: 18310Sstevel@tonic-gate brand = amd_cpubrand(cpi); 18320Sstevel@tonic-gate break; 18330Sstevel@tonic-gate case X86_VENDOR_Cyrix: 18340Sstevel@tonic-gate brand = cyrix_cpubrand(cpi, x86_type); 18350Sstevel@tonic-gate break; 18360Sstevel@tonic-gate case X86_VENDOR_NexGen: 18370Sstevel@tonic-gate if (cpi->cpi_family == 5 && cpi->cpi_model == 0) 18380Sstevel@tonic-gate brand = "NexGen Nx586"; 18390Sstevel@tonic-gate break; 18400Sstevel@tonic-gate case X86_VENDOR_Centaur: 18410Sstevel@tonic-gate if (cpi->cpi_family == 5) 18420Sstevel@tonic-gate switch (cpi->cpi_model) { 18430Sstevel@tonic-gate case 4: 18440Sstevel@tonic-gate brand = "Centaur C6"; 18450Sstevel@tonic-gate break; 18460Sstevel@tonic-gate case 8: 18470Sstevel@tonic-gate brand = "Centaur C2"; 18480Sstevel@tonic-gate break; 18490Sstevel@tonic-gate case 9: 18500Sstevel@tonic-gate brand = "Centaur C3"; 18510Sstevel@tonic-gate break; 18520Sstevel@tonic-gate default: 18530Sstevel@tonic-gate break; 18540Sstevel@tonic-gate } 18550Sstevel@tonic-gate break; 18560Sstevel@tonic-gate case X86_VENDOR_Rise: 18570Sstevel@tonic-gate if (cpi->cpi_family == 5 && 18580Sstevel@tonic-gate (cpi->cpi_model == 0 || cpi->cpi_model == 2)) 18590Sstevel@tonic-gate brand = "Rise mP6"; 18600Sstevel@tonic-gate break; 18610Sstevel@tonic-gate case X86_VENDOR_SiS: 18620Sstevel@tonic-gate if (cpi->cpi_family == 5 && cpi->cpi_model == 0) 18630Sstevel@tonic-gate brand = "SiS 55x"; 18640Sstevel@tonic-gate break; 18650Sstevel@tonic-gate case X86_VENDOR_TM: 18660Sstevel@tonic-gate if (cpi->cpi_family == 5 && cpi->cpi_model == 4) 18670Sstevel@tonic-gate brand = "Transmeta Crusoe TM3x00 or TM5x00"; 18680Sstevel@tonic-gate break; 18690Sstevel@tonic-gate case X86_VENDOR_NSC: 18700Sstevel@tonic-gate case X86_VENDOR_UMC: 18710Sstevel@tonic-gate default: 18720Sstevel@tonic-gate break; 18730Sstevel@tonic-gate } 18740Sstevel@tonic-gate if (brand) { 18750Sstevel@tonic-gate (void) strcpy((char *)cpi->cpi_brandstr, brand); 18760Sstevel@tonic-gate return; 18770Sstevel@tonic-gate } 18780Sstevel@tonic-gate 18790Sstevel@tonic-gate /* 18800Sstevel@tonic-gate * If all else fails ... 18810Sstevel@tonic-gate */ 18820Sstevel@tonic-gate (void) snprintf(cpi->cpi_brandstr, sizeof (cpi->cpi_brandstr), 18830Sstevel@tonic-gate "%s %d.%d.%d", cpi->cpi_vendorstr, cpi->cpi_family, 18840Sstevel@tonic-gate cpi->cpi_model, cpi->cpi_step); 18850Sstevel@tonic-gate } 18860Sstevel@tonic-gate 18870Sstevel@tonic-gate /* 18880Sstevel@tonic-gate * This routine is called just after kernel memory allocation 18890Sstevel@tonic-gate * becomes available on cpu0, and as part of mp_startup() on 18900Sstevel@tonic-gate * the other cpus. 18910Sstevel@tonic-gate * 18924606Sesaxe * Fixup the brand string, and collect any information from cpuid 18934606Sesaxe * that requires dynamicically allocated storage to represent. 18940Sstevel@tonic-gate */ 18950Sstevel@tonic-gate /*ARGSUSED*/ 18960Sstevel@tonic-gate void 18970Sstevel@tonic-gate cpuid_pass3(cpu_t *cpu) 18980Sstevel@tonic-gate { 18994606Sesaxe int i, max, shft, level, size; 19004606Sesaxe struct cpuid_regs regs; 19014606Sesaxe struct cpuid_regs *cp; 19020Sstevel@tonic-gate struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 19030Sstevel@tonic-gate 19040Sstevel@tonic-gate ASSERT(cpi->cpi_pass == 2); 19050Sstevel@tonic-gate 19064606Sesaxe /* 19074606Sesaxe * Function 4: Deterministic cache parameters 19084606Sesaxe * 19094606Sesaxe * Take this opportunity to detect the number of threads 19104606Sesaxe * sharing the last level cache, and construct a corresponding 19114606Sesaxe * cache id. The respective cpuid_info members are initialized 19124606Sesaxe * to the default case of "no last level cache sharing". 19134606Sesaxe */ 19144606Sesaxe cpi->cpi_ncpu_shr_last_cache = 1; 19154606Sesaxe cpi->cpi_last_lvl_cacheid = cpu->cpu_id; 19164606Sesaxe 19174606Sesaxe if (cpi->cpi_maxeax >= 4 && cpi->cpi_vendor == X86_VENDOR_Intel) { 19184606Sesaxe 19194606Sesaxe /* 19204606Sesaxe * Find the # of elements (size) returned by fn 4, and along 19214606Sesaxe * the way detect last level cache sharing details. 19224606Sesaxe */ 19234606Sesaxe bzero(®s, sizeof (regs)); 19244606Sesaxe cp = ®s; 19254606Sesaxe for (i = 0, max = 0; i < CPI_FN4_ECX_MAX; i++) { 19264606Sesaxe cp->cp_eax = 4; 19274606Sesaxe cp->cp_ecx = i; 19284606Sesaxe 19294606Sesaxe (void) __cpuid_insn(cp); 19304606Sesaxe 19314606Sesaxe if (CPI_CACHE_TYPE(cp) == 0) 19324606Sesaxe break; 19334606Sesaxe level = CPI_CACHE_LVL(cp); 19344606Sesaxe if (level > max) { 19354606Sesaxe max = level; 19364606Sesaxe cpi->cpi_ncpu_shr_last_cache = 19374606Sesaxe CPI_NTHR_SHR_CACHE(cp) + 1; 19384606Sesaxe } 19394606Sesaxe } 19404606Sesaxe cpi->cpi_std_4_size = size = i; 19414606Sesaxe 19424606Sesaxe /* 19434606Sesaxe * Allocate the cpi_std_4 array. The first element 19444606Sesaxe * references the regs for fn 4, %ecx == 0, which 19454606Sesaxe * cpuid_pass2() stashed in cpi->cpi_std[4]. 19464606Sesaxe */ 19474606Sesaxe if (size > 0) { 19484606Sesaxe cpi->cpi_std_4 = 19494606Sesaxe kmem_alloc(size * sizeof (cp), KM_SLEEP); 19504606Sesaxe cpi->cpi_std_4[0] = &cpi->cpi_std[4]; 19514606Sesaxe 19524606Sesaxe /* 19534606Sesaxe * Allocate storage to hold the additional regs 19544606Sesaxe * for function 4, %ecx == 1 .. cpi_std_4_size. 19554606Sesaxe * 19564606Sesaxe * The regs for fn 4, %ecx == 0 has already 19574606Sesaxe * been allocated as indicated above. 19584606Sesaxe */ 19594606Sesaxe for (i = 1; i < size; i++) { 19604606Sesaxe cp = cpi->cpi_std_4[i] = 19614606Sesaxe kmem_zalloc(sizeof (regs), KM_SLEEP); 19624606Sesaxe cp->cp_eax = 4; 19634606Sesaxe cp->cp_ecx = i; 19644606Sesaxe 19654606Sesaxe (void) __cpuid_insn(cp); 19664606Sesaxe } 19674606Sesaxe } 19684606Sesaxe /* 19694606Sesaxe * Determine the number of bits needed to represent 19704606Sesaxe * the number of CPUs sharing the last level cache. 19714606Sesaxe * 19724606Sesaxe * Shift off that number of bits from the APIC id to 19734606Sesaxe * derive the cache id. 19744606Sesaxe */ 19754606Sesaxe shft = 0; 19764606Sesaxe for (i = 1; i < cpi->cpi_ncpu_shr_last_cache; i <<= 1) 19774606Sesaxe shft++; 19787282Smishra cpi->cpi_last_lvl_cacheid = cpi->cpi_apicid >> shft; 19790Sstevel@tonic-gate } 19800Sstevel@tonic-gate 19810Sstevel@tonic-gate /* 19824606Sesaxe * Now fixup the brand string 19830Sstevel@tonic-gate */ 19844606Sesaxe if ((cpi->cpi_xmaxeax & 0x80000000) == 0) { 19854606Sesaxe fabricate_brandstr(cpi); 19864606Sesaxe } else { 19870Sstevel@tonic-gate 19880Sstevel@tonic-gate /* 19894606Sesaxe * If we successfully extracted a brand string from the cpuid 19904606Sesaxe * instruction, clean it up by removing leading spaces and 19914606Sesaxe * similar junk. 19920Sstevel@tonic-gate */ 19934606Sesaxe if (cpi->cpi_brandstr[0]) { 19944606Sesaxe size_t maxlen = sizeof (cpi->cpi_brandstr); 19954606Sesaxe char *src, *dst; 19964606Sesaxe 19974606Sesaxe dst = src = (char *)cpi->cpi_brandstr; 19984606Sesaxe src[maxlen - 1] = '\0'; 19994606Sesaxe /* 20004606Sesaxe * strip leading spaces 20014606Sesaxe */ 20024606Sesaxe while (*src == ' ') 20034606Sesaxe src++; 20044606Sesaxe /* 20054606Sesaxe * Remove any 'Genuine' or "Authentic" prefixes 20064606Sesaxe */ 20074606Sesaxe if (strncmp(src, "Genuine ", 8) == 0) 20084606Sesaxe src += 8; 20094606Sesaxe if (strncmp(src, "Authentic ", 10) == 0) 20104606Sesaxe src += 10; 20114606Sesaxe 20124606Sesaxe /* 20134606Sesaxe * Now do an in-place copy. 20144606Sesaxe * Map (R) to (r) and (TM) to (tm). 20154606Sesaxe * The era of teletypes is long gone, and there's 20164606Sesaxe * -really- no need to shout. 20174606Sesaxe */ 20184606Sesaxe while (*src != '\0') { 20194606Sesaxe if (src[0] == '(') { 20204606Sesaxe if (strncmp(src + 1, "R)", 2) == 0) { 20214606Sesaxe (void) strncpy(dst, "(r)", 3); 20224606Sesaxe src += 3; 20234606Sesaxe dst += 3; 20244606Sesaxe continue; 20254606Sesaxe } 20264606Sesaxe if (strncmp(src + 1, "TM)", 3) == 0) { 20274606Sesaxe (void) strncpy(dst, "(tm)", 4); 20284606Sesaxe src += 4; 20294606Sesaxe dst += 4; 20304606Sesaxe continue; 20314606Sesaxe } 20320Sstevel@tonic-gate } 20334606Sesaxe *dst++ = *src++; 20340Sstevel@tonic-gate } 20354606Sesaxe *dst = '\0'; 20364606Sesaxe 20374606Sesaxe /* 20384606Sesaxe * Finally, remove any trailing spaces 20394606Sesaxe */ 20404606Sesaxe while (--dst > cpi->cpi_brandstr) 20414606Sesaxe if (*dst == ' ') 20424606Sesaxe *dst = '\0'; 20434606Sesaxe else 20444606Sesaxe break; 20454606Sesaxe } else 20464606Sesaxe fabricate_brandstr(cpi); 20474606Sesaxe } 20480Sstevel@tonic-gate cpi->cpi_pass = 3; 20490Sstevel@tonic-gate } 20500Sstevel@tonic-gate 20510Sstevel@tonic-gate /* 20520Sstevel@tonic-gate * This routine is called out of bind_hwcap() much later in the life 20530Sstevel@tonic-gate * of the kernel (post_startup()). The job of this routine is to resolve 20540Sstevel@tonic-gate * the hardware feature support and kernel support for those features into 20550Sstevel@tonic-gate * what we're actually going to tell applications via the aux vector. 20560Sstevel@tonic-gate */ 20570Sstevel@tonic-gate uint_t 20580Sstevel@tonic-gate cpuid_pass4(cpu_t *cpu) 20590Sstevel@tonic-gate { 20600Sstevel@tonic-gate struct cpuid_info *cpi; 20610Sstevel@tonic-gate uint_t hwcap_flags = 0; 20620Sstevel@tonic-gate 20630Sstevel@tonic-gate if (cpu == NULL) 20640Sstevel@tonic-gate cpu = CPU; 20650Sstevel@tonic-gate cpi = cpu->cpu_m.mcpu_cpi; 20660Sstevel@tonic-gate 20670Sstevel@tonic-gate ASSERT(cpi->cpi_pass == 3); 20680Sstevel@tonic-gate 20690Sstevel@tonic-gate if (cpi->cpi_maxeax >= 1) { 20700Sstevel@tonic-gate uint32_t *edx = &cpi->cpi_support[STD_EDX_FEATURES]; 20710Sstevel@tonic-gate uint32_t *ecx = &cpi->cpi_support[STD_ECX_FEATURES]; 20720Sstevel@tonic-gate 20730Sstevel@tonic-gate *edx = CPI_FEATURES_EDX(cpi); 20740Sstevel@tonic-gate *ecx = CPI_FEATURES_ECX(cpi); 20750Sstevel@tonic-gate 20760Sstevel@tonic-gate /* 20770Sstevel@tonic-gate * [these require explicit kernel support] 20780Sstevel@tonic-gate */ 20790Sstevel@tonic-gate if ((x86_feature & X86_SEP) == 0) 20800Sstevel@tonic-gate *edx &= ~CPUID_INTC_EDX_SEP; 20810Sstevel@tonic-gate 20820Sstevel@tonic-gate if ((x86_feature & X86_SSE) == 0) 20830Sstevel@tonic-gate *edx &= ~(CPUID_INTC_EDX_FXSR|CPUID_INTC_EDX_SSE); 20840Sstevel@tonic-gate if ((x86_feature & X86_SSE2) == 0) 20850Sstevel@tonic-gate *edx &= ~CPUID_INTC_EDX_SSE2; 20860Sstevel@tonic-gate 20870Sstevel@tonic-gate if ((x86_feature & X86_HTT) == 0) 20880Sstevel@tonic-gate *edx &= ~CPUID_INTC_EDX_HTT; 20890Sstevel@tonic-gate 20900Sstevel@tonic-gate if ((x86_feature & X86_SSE3) == 0) 20910Sstevel@tonic-gate *ecx &= ~CPUID_INTC_ECX_SSE3; 20920Sstevel@tonic-gate 20935269Skk208521 if (cpi->cpi_vendor == X86_VENDOR_Intel) { 20945269Skk208521 if ((x86_feature & X86_SSSE3) == 0) 20955269Skk208521 *ecx &= ~CPUID_INTC_ECX_SSSE3; 20965269Skk208521 if ((x86_feature & X86_SSE4_1) == 0) 20975269Skk208521 *ecx &= ~CPUID_INTC_ECX_SSE4_1; 20985269Skk208521 if ((x86_feature & X86_SSE4_2) == 0) 20995269Skk208521 *ecx &= ~CPUID_INTC_ECX_SSE4_2; 21009370SKuriakose.Kuruvilla@Sun.COM if ((x86_feature & X86_AES) == 0) 21019370SKuriakose.Kuruvilla@Sun.COM *ecx &= ~CPUID_INTC_ECX_AES; 21025269Skk208521 } 21035269Skk208521 21040Sstevel@tonic-gate /* 21050Sstevel@tonic-gate * [no explicit support required beyond x87 fp context] 21060Sstevel@tonic-gate */ 21070Sstevel@tonic-gate if (!fpu_exists) 21080Sstevel@tonic-gate *edx &= ~(CPUID_INTC_EDX_FPU | CPUID_INTC_EDX_MMX); 21090Sstevel@tonic-gate 21100Sstevel@tonic-gate /* 21110Sstevel@tonic-gate * Now map the supported feature vector to things that we 21120Sstevel@tonic-gate * think userland will care about. 21130Sstevel@tonic-gate */ 21140Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_SEP) 21150Sstevel@tonic-gate hwcap_flags |= AV_386_SEP; 21160Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_SSE) 21170Sstevel@tonic-gate hwcap_flags |= AV_386_FXSR | AV_386_SSE; 21180Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_SSE2) 21190Sstevel@tonic-gate hwcap_flags |= AV_386_SSE2; 21200Sstevel@tonic-gate if (*ecx & CPUID_INTC_ECX_SSE3) 21210Sstevel@tonic-gate hwcap_flags |= AV_386_SSE3; 21225269Skk208521 if (cpi->cpi_vendor == X86_VENDOR_Intel) { 21235269Skk208521 if (*ecx & CPUID_INTC_ECX_SSSE3) 21245269Skk208521 hwcap_flags |= AV_386_SSSE3; 21255269Skk208521 if (*ecx & CPUID_INTC_ECX_SSE4_1) 21265269Skk208521 hwcap_flags |= AV_386_SSE4_1; 21275269Skk208521 if (*ecx & CPUID_INTC_ECX_SSE4_2) 21285269Skk208521 hwcap_flags |= AV_386_SSE4_2; 21298418SKrishnendu.Sadhukhan@Sun.COM if (*ecx & CPUID_INTC_ECX_MOVBE) 21308418SKrishnendu.Sadhukhan@Sun.COM hwcap_flags |= AV_386_MOVBE; 21319370SKuriakose.Kuruvilla@Sun.COM if (*ecx & CPUID_INTC_ECX_AES) 21329370SKuriakose.Kuruvilla@Sun.COM hwcap_flags |= AV_386_AES; 21339370SKuriakose.Kuruvilla@Sun.COM if (*ecx & CPUID_INTC_ECX_PCLMULQDQ) 21349370SKuriakose.Kuruvilla@Sun.COM hwcap_flags |= AV_386_PCLMULQDQ; 21355269Skk208521 } 21364628Skk208521 if (*ecx & CPUID_INTC_ECX_POPCNT) 21374628Skk208521 hwcap_flags |= AV_386_POPCNT; 21380Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_FPU) 21390Sstevel@tonic-gate hwcap_flags |= AV_386_FPU; 21400Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_MMX) 21410Sstevel@tonic-gate hwcap_flags |= AV_386_MMX; 21420Sstevel@tonic-gate 21430Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_TSC) 21440Sstevel@tonic-gate hwcap_flags |= AV_386_TSC; 21450Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_CX8) 21460Sstevel@tonic-gate hwcap_flags |= AV_386_CX8; 21470Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_CMOV) 21480Sstevel@tonic-gate hwcap_flags |= AV_386_CMOV; 21490Sstevel@tonic-gate if (*ecx & CPUID_INTC_ECX_MON) 21500Sstevel@tonic-gate hwcap_flags |= AV_386_MON; 21510Sstevel@tonic-gate if (*ecx & CPUID_INTC_ECX_CX16) 21520Sstevel@tonic-gate hwcap_flags |= AV_386_CX16; 21530Sstevel@tonic-gate } 21540Sstevel@tonic-gate 21551228Sandrei if (x86_feature & X86_HTT) 21560Sstevel@tonic-gate hwcap_flags |= AV_386_PAUSE; 21570Sstevel@tonic-gate 21580Sstevel@tonic-gate if (cpi->cpi_xmaxeax < 0x80000001) 21590Sstevel@tonic-gate goto pass4_done; 21600Sstevel@tonic-gate 21610Sstevel@tonic-gate switch (cpi->cpi_vendor) { 21621228Sandrei struct cpuid_regs cp; 21633446Smrj uint32_t *edx, *ecx; 21640Sstevel@tonic-gate 21653446Smrj case X86_VENDOR_Intel: 21663446Smrj /* 21673446Smrj * Seems like Intel duplicated what we necessary 21683446Smrj * here to make the initial crop of 64-bit OS's work. 21693446Smrj * Hopefully, those are the only "extended" bits 21703446Smrj * they'll add. 21713446Smrj */ 21723446Smrj /*FALLTHROUGH*/ 21733446Smrj 21740Sstevel@tonic-gate case X86_VENDOR_AMD: 21750Sstevel@tonic-gate edx = &cpi->cpi_support[AMD_EDX_FEATURES]; 21763446Smrj ecx = &cpi->cpi_support[AMD_ECX_FEATURES]; 21770Sstevel@tonic-gate 21780Sstevel@tonic-gate *edx = CPI_FEATURES_XTD_EDX(cpi); 21793446Smrj *ecx = CPI_FEATURES_XTD_ECX(cpi); 21803446Smrj 21813446Smrj /* 21823446Smrj * [these features require explicit kernel support] 21833446Smrj */ 21843446Smrj switch (cpi->cpi_vendor) { 21853446Smrj case X86_VENDOR_Intel: 21866657Ssudheer if ((x86_feature & X86_TSCP) == 0) 21876657Ssudheer *edx &= ~CPUID_AMD_EDX_TSCP; 21883446Smrj break; 21893446Smrj 21903446Smrj case X86_VENDOR_AMD: 21913446Smrj if ((x86_feature & X86_TSCP) == 0) 21923446Smrj *edx &= ~CPUID_AMD_EDX_TSCP; 21934628Skk208521 if ((x86_feature & X86_SSE4A) == 0) 21944628Skk208521 *ecx &= ~CPUID_AMD_ECX_SSE4A; 21953446Smrj break; 21963446Smrj 21973446Smrj default: 21983446Smrj break; 21993446Smrj } 22000Sstevel@tonic-gate 22010Sstevel@tonic-gate /* 22020Sstevel@tonic-gate * [no explicit support required beyond 22030Sstevel@tonic-gate * x87 fp context and exception handlers] 22040Sstevel@tonic-gate */ 22050Sstevel@tonic-gate if (!fpu_exists) 22060Sstevel@tonic-gate *edx &= ~(CPUID_AMD_EDX_MMXamd | 22070Sstevel@tonic-gate CPUID_AMD_EDX_3DNow | CPUID_AMD_EDX_3DNowx); 22080Sstevel@tonic-gate 22090Sstevel@tonic-gate if ((x86_feature & X86_NX) == 0) 22100Sstevel@tonic-gate *edx &= ~CPUID_AMD_EDX_NX; 22113446Smrj #if !defined(__amd64) 22120Sstevel@tonic-gate *edx &= ~CPUID_AMD_EDX_LM; 22130Sstevel@tonic-gate #endif 22140Sstevel@tonic-gate /* 22150Sstevel@tonic-gate * Now map the supported feature vector to 22160Sstevel@tonic-gate * things that we think userland will care about. 22170Sstevel@tonic-gate */ 22183446Smrj #if defined(__amd64) 22190Sstevel@tonic-gate if (*edx & CPUID_AMD_EDX_SYSC) 22200Sstevel@tonic-gate hwcap_flags |= AV_386_AMD_SYSC; 22213446Smrj #endif 22220Sstevel@tonic-gate if (*edx & CPUID_AMD_EDX_MMXamd) 22230Sstevel@tonic-gate hwcap_flags |= AV_386_AMD_MMX; 22240Sstevel@tonic-gate if (*edx & CPUID_AMD_EDX_3DNow) 22250Sstevel@tonic-gate hwcap_flags |= AV_386_AMD_3DNow; 22260Sstevel@tonic-gate if (*edx & CPUID_AMD_EDX_3DNowx) 22270Sstevel@tonic-gate hwcap_flags |= AV_386_AMD_3DNowx; 22283446Smrj 22293446Smrj switch (cpi->cpi_vendor) { 22303446Smrj case X86_VENDOR_AMD: 22313446Smrj if (*edx & CPUID_AMD_EDX_TSCP) 22323446Smrj hwcap_flags |= AV_386_TSCP; 22333446Smrj if (*ecx & CPUID_AMD_ECX_AHF64) 22343446Smrj hwcap_flags |= AV_386_AHF; 22354628Skk208521 if (*ecx & CPUID_AMD_ECX_SSE4A) 22364628Skk208521 hwcap_flags |= AV_386_AMD_SSE4A; 22374628Skk208521 if (*ecx & CPUID_AMD_ECX_LZCNT) 22384628Skk208521 hwcap_flags |= AV_386_AMD_LZCNT; 22393446Smrj break; 22403446Smrj 22413446Smrj case X86_VENDOR_Intel: 22426657Ssudheer if (*edx & CPUID_AMD_EDX_TSCP) 22436657Ssudheer hwcap_flags |= AV_386_TSCP; 22443446Smrj /* 22453446Smrj * Aarrgh. 22463446Smrj * Intel uses a different bit in the same word. 22473446Smrj */ 22483446Smrj if (*ecx & CPUID_INTC_ECX_AHF64) 22493446Smrj hwcap_flags |= AV_386_AHF; 22503446Smrj break; 22513446Smrj 22523446Smrj default: 22533446Smrj break; 22543446Smrj } 22550Sstevel@tonic-gate break; 22560Sstevel@tonic-gate 22570Sstevel@tonic-gate case X86_VENDOR_TM: 22581228Sandrei cp.cp_eax = 0x80860001; 22591228Sandrei (void) __cpuid_insn(&cp); 22601228Sandrei cpi->cpi_support[TM_EDX_FEATURES] = cp.cp_edx; 22610Sstevel@tonic-gate break; 22620Sstevel@tonic-gate 22630Sstevel@tonic-gate default: 22640Sstevel@tonic-gate break; 22650Sstevel@tonic-gate } 22660Sstevel@tonic-gate 22670Sstevel@tonic-gate pass4_done: 22680Sstevel@tonic-gate cpi->cpi_pass = 4; 22690Sstevel@tonic-gate return (hwcap_flags); 22700Sstevel@tonic-gate } 22710Sstevel@tonic-gate 22720Sstevel@tonic-gate 22730Sstevel@tonic-gate /* 22740Sstevel@tonic-gate * Simulate the cpuid instruction using the data we previously 22750Sstevel@tonic-gate * captured about this CPU. We try our best to return the truth 22760Sstevel@tonic-gate * about the hardware, independently of kernel support. 22770Sstevel@tonic-gate */ 22780Sstevel@tonic-gate uint32_t 22791228Sandrei cpuid_insn(cpu_t *cpu, struct cpuid_regs *cp) 22800Sstevel@tonic-gate { 22810Sstevel@tonic-gate struct cpuid_info *cpi; 22821228Sandrei struct cpuid_regs *xcp; 22830Sstevel@tonic-gate 22840Sstevel@tonic-gate if (cpu == NULL) 22850Sstevel@tonic-gate cpu = CPU; 22860Sstevel@tonic-gate cpi = cpu->cpu_m.mcpu_cpi; 22870Sstevel@tonic-gate 22880Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 3)); 22890Sstevel@tonic-gate 22900Sstevel@tonic-gate /* 22910Sstevel@tonic-gate * CPUID data is cached in two separate places: cpi_std for standard 22920Sstevel@tonic-gate * CPUID functions, and cpi_extd for extended CPUID functions. 22930Sstevel@tonic-gate */ 22941228Sandrei if (cp->cp_eax <= cpi->cpi_maxeax && cp->cp_eax < NMAX_CPI_STD) 22951228Sandrei xcp = &cpi->cpi_std[cp->cp_eax]; 22961228Sandrei else if (cp->cp_eax >= 0x80000000 && cp->cp_eax <= cpi->cpi_xmaxeax && 22971228Sandrei cp->cp_eax < 0x80000000 + NMAX_CPI_EXTD) 22981228Sandrei xcp = &cpi->cpi_extd[cp->cp_eax - 0x80000000]; 22990Sstevel@tonic-gate else 23000Sstevel@tonic-gate /* 23010Sstevel@tonic-gate * The caller is asking for data from an input parameter which 23020Sstevel@tonic-gate * the kernel has not cached. In this case we go fetch from 23030Sstevel@tonic-gate * the hardware and return the data directly to the user. 23040Sstevel@tonic-gate */ 23051228Sandrei return (__cpuid_insn(cp)); 23061228Sandrei 23071228Sandrei cp->cp_eax = xcp->cp_eax; 23081228Sandrei cp->cp_ebx = xcp->cp_ebx; 23091228Sandrei cp->cp_ecx = xcp->cp_ecx; 23101228Sandrei cp->cp_edx = xcp->cp_edx; 23110Sstevel@tonic-gate return (cp->cp_eax); 23120Sstevel@tonic-gate } 23130Sstevel@tonic-gate 23140Sstevel@tonic-gate int 23150Sstevel@tonic-gate cpuid_checkpass(cpu_t *cpu, int pass) 23160Sstevel@tonic-gate { 23170Sstevel@tonic-gate return (cpu != NULL && cpu->cpu_m.mcpu_cpi != NULL && 23180Sstevel@tonic-gate cpu->cpu_m.mcpu_cpi->cpi_pass >= pass); 23190Sstevel@tonic-gate } 23200Sstevel@tonic-gate 23210Sstevel@tonic-gate int 23220Sstevel@tonic-gate cpuid_getbrandstr(cpu_t *cpu, char *s, size_t n) 23230Sstevel@tonic-gate { 23240Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 3)); 23250Sstevel@tonic-gate 23260Sstevel@tonic-gate return (snprintf(s, n, "%s", cpu->cpu_m.mcpu_cpi->cpi_brandstr)); 23270Sstevel@tonic-gate } 23280Sstevel@tonic-gate 23290Sstevel@tonic-gate int 23301228Sandrei cpuid_is_cmt(cpu_t *cpu) 23310Sstevel@tonic-gate { 23320Sstevel@tonic-gate if (cpu == NULL) 23330Sstevel@tonic-gate cpu = CPU; 23340Sstevel@tonic-gate 23350Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 23360Sstevel@tonic-gate 23370Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_chipid >= 0); 23380Sstevel@tonic-gate } 23390Sstevel@tonic-gate 23400Sstevel@tonic-gate /* 23410Sstevel@tonic-gate * AMD and Intel both implement the 64-bit variant of the syscall 23420Sstevel@tonic-gate * instruction (syscallq), so if there's -any- support for syscall, 23430Sstevel@tonic-gate * cpuid currently says "yes, we support this". 23440Sstevel@tonic-gate * 23450Sstevel@tonic-gate * However, Intel decided to -not- implement the 32-bit variant of the 23460Sstevel@tonic-gate * syscall instruction, so we provide a predicate to allow our caller 23470Sstevel@tonic-gate * to test that subtlety here. 23485084Sjohnlev * 23495084Sjohnlev * XXPV Currently, 32-bit syscall instructions don't work via the hypervisor, 23505084Sjohnlev * even in the case where the hardware would in fact support it. 23510Sstevel@tonic-gate */ 23520Sstevel@tonic-gate /*ARGSUSED*/ 23530Sstevel@tonic-gate int 23540Sstevel@tonic-gate cpuid_syscall32_insn(cpu_t *cpu) 23550Sstevel@tonic-gate { 23560Sstevel@tonic-gate ASSERT(cpuid_checkpass((cpu == NULL ? CPU : cpu), 1)); 23570Sstevel@tonic-gate 23585084Sjohnlev #if !defined(__xpv) 23593446Smrj if (cpu == NULL) 23603446Smrj cpu = CPU; 23613446Smrj 23623446Smrj /*CSTYLED*/ 23633446Smrj { 23643446Smrj struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 23653446Smrj 23663446Smrj if (cpi->cpi_vendor == X86_VENDOR_AMD && 23673446Smrj cpi->cpi_xmaxeax >= 0x80000001 && 23683446Smrj (CPI_FEATURES_XTD_EDX(cpi) & CPUID_AMD_EDX_SYSC)) 23693446Smrj return (1); 23703446Smrj } 23715084Sjohnlev #endif 23720Sstevel@tonic-gate return (0); 23730Sstevel@tonic-gate } 23740Sstevel@tonic-gate 23750Sstevel@tonic-gate int 23760Sstevel@tonic-gate cpuid_getidstr(cpu_t *cpu, char *s, size_t n) 23770Sstevel@tonic-gate { 23780Sstevel@tonic-gate struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 23790Sstevel@tonic-gate 23800Sstevel@tonic-gate static const char fmt[] = 23813779Sdmick "x86 (%s %X family %d model %d step %d clock %d MHz)"; 23820Sstevel@tonic-gate static const char fmt_ht[] = 23833779Sdmick "x86 (chipid 0x%x %s %X family %d model %d step %d clock %d MHz)"; 23840Sstevel@tonic-gate 23850Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 23860Sstevel@tonic-gate 23871228Sandrei if (cpuid_is_cmt(cpu)) 23880Sstevel@tonic-gate return (snprintf(s, n, fmt_ht, cpi->cpi_chipid, 23893779Sdmick cpi->cpi_vendorstr, cpi->cpi_std[1].cp_eax, 23903779Sdmick cpi->cpi_family, cpi->cpi_model, 23910Sstevel@tonic-gate cpi->cpi_step, cpu->cpu_type_info.pi_clock)); 23920Sstevel@tonic-gate return (snprintf(s, n, fmt, 23933779Sdmick cpi->cpi_vendorstr, cpi->cpi_std[1].cp_eax, 23943779Sdmick cpi->cpi_family, cpi->cpi_model, 23950Sstevel@tonic-gate cpi->cpi_step, cpu->cpu_type_info.pi_clock)); 23960Sstevel@tonic-gate } 23970Sstevel@tonic-gate 23980Sstevel@tonic-gate const char * 23990Sstevel@tonic-gate cpuid_getvendorstr(cpu_t *cpu) 24000Sstevel@tonic-gate { 24010Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 24020Sstevel@tonic-gate return ((const char *)cpu->cpu_m.mcpu_cpi->cpi_vendorstr); 24030Sstevel@tonic-gate } 24040Sstevel@tonic-gate 24050Sstevel@tonic-gate uint_t 24060Sstevel@tonic-gate cpuid_getvendor(cpu_t *cpu) 24070Sstevel@tonic-gate { 24080Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 24090Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_vendor); 24100Sstevel@tonic-gate } 24110Sstevel@tonic-gate 24120Sstevel@tonic-gate uint_t 24130Sstevel@tonic-gate cpuid_getfamily(cpu_t *cpu) 24140Sstevel@tonic-gate { 24150Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 24160Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_family); 24170Sstevel@tonic-gate } 24180Sstevel@tonic-gate 24190Sstevel@tonic-gate uint_t 24200Sstevel@tonic-gate cpuid_getmodel(cpu_t *cpu) 24210Sstevel@tonic-gate { 24220Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 24230Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_model); 24240Sstevel@tonic-gate } 24250Sstevel@tonic-gate 24260Sstevel@tonic-gate uint_t 24270Sstevel@tonic-gate cpuid_get_ncpu_per_chip(cpu_t *cpu) 24280Sstevel@tonic-gate { 24290Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 24300Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_ncpu_per_chip); 24310Sstevel@tonic-gate } 24320Sstevel@tonic-gate 24330Sstevel@tonic-gate uint_t 24341228Sandrei cpuid_get_ncore_per_chip(cpu_t *cpu) 24351228Sandrei { 24361228Sandrei ASSERT(cpuid_checkpass(cpu, 1)); 24371228Sandrei return (cpu->cpu_m.mcpu_cpi->cpi_ncore_per_chip); 24381228Sandrei } 24391228Sandrei 24401228Sandrei uint_t 24414606Sesaxe cpuid_get_ncpu_sharing_last_cache(cpu_t *cpu) 24424606Sesaxe { 24434606Sesaxe ASSERT(cpuid_checkpass(cpu, 2)); 24444606Sesaxe return (cpu->cpu_m.mcpu_cpi->cpi_ncpu_shr_last_cache); 24454606Sesaxe } 24464606Sesaxe 24474606Sesaxe id_t 24484606Sesaxe cpuid_get_last_lvl_cacheid(cpu_t *cpu) 24494606Sesaxe { 24504606Sesaxe ASSERT(cpuid_checkpass(cpu, 2)); 24514606Sesaxe return (cpu->cpu_m.mcpu_cpi->cpi_last_lvl_cacheid); 24524606Sesaxe } 24534606Sesaxe 24544606Sesaxe uint_t 24550Sstevel@tonic-gate cpuid_getstep(cpu_t *cpu) 24560Sstevel@tonic-gate { 24570Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 24580Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_step); 24590Sstevel@tonic-gate } 24600Sstevel@tonic-gate 24614581Ssherrym uint_t 24624581Ssherrym cpuid_getsig(struct cpu *cpu) 24634581Ssherrym { 24644581Ssherrym ASSERT(cpuid_checkpass(cpu, 1)); 24654581Ssherrym return (cpu->cpu_m.mcpu_cpi->cpi_std[1].cp_eax); 24664581Ssherrym } 24674581Ssherrym 24682869Sgavinm uint32_t 24692869Sgavinm cpuid_getchiprev(struct cpu *cpu) 24702869Sgavinm { 24712869Sgavinm ASSERT(cpuid_checkpass(cpu, 1)); 24722869Sgavinm return (cpu->cpu_m.mcpu_cpi->cpi_chiprev); 24732869Sgavinm } 24742869Sgavinm 24752869Sgavinm const char * 24762869Sgavinm cpuid_getchiprevstr(struct cpu *cpu) 24772869Sgavinm { 24782869Sgavinm ASSERT(cpuid_checkpass(cpu, 1)); 24792869Sgavinm return (cpu->cpu_m.mcpu_cpi->cpi_chiprevstr); 24802869Sgavinm } 24812869Sgavinm 24822869Sgavinm uint32_t 24832869Sgavinm cpuid_getsockettype(struct cpu *cpu) 24842869Sgavinm { 24852869Sgavinm ASSERT(cpuid_checkpass(cpu, 1)); 24862869Sgavinm return (cpu->cpu_m.mcpu_cpi->cpi_socket); 24872869Sgavinm } 24882869Sgavinm 24899482SKuriakose.Kuruvilla@Sun.COM const char * 24909482SKuriakose.Kuruvilla@Sun.COM cpuid_getsocketstr(cpu_t *cpu) 24919482SKuriakose.Kuruvilla@Sun.COM { 24929482SKuriakose.Kuruvilla@Sun.COM static const char *socketstr = NULL; 24939482SKuriakose.Kuruvilla@Sun.COM struct cpuid_info *cpi; 24949482SKuriakose.Kuruvilla@Sun.COM 24959482SKuriakose.Kuruvilla@Sun.COM ASSERT(cpuid_checkpass(cpu, 1)); 24969482SKuriakose.Kuruvilla@Sun.COM cpi = cpu->cpu_m.mcpu_cpi; 24979482SKuriakose.Kuruvilla@Sun.COM 24989482SKuriakose.Kuruvilla@Sun.COM /* Assume that socket types are the same across the system */ 24999482SKuriakose.Kuruvilla@Sun.COM if (socketstr == NULL) 25009482SKuriakose.Kuruvilla@Sun.COM socketstr = _cpuid_sktstr(cpi->cpi_vendor, cpi->cpi_family, 25019482SKuriakose.Kuruvilla@Sun.COM cpi->cpi_model, cpi->cpi_step); 25029482SKuriakose.Kuruvilla@Sun.COM 25039482SKuriakose.Kuruvilla@Sun.COM 25049482SKuriakose.Kuruvilla@Sun.COM return (socketstr); 25059482SKuriakose.Kuruvilla@Sun.COM } 25069482SKuriakose.Kuruvilla@Sun.COM 25073434Sesaxe int 25083434Sesaxe cpuid_get_chipid(cpu_t *cpu) 25090Sstevel@tonic-gate { 25100Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 25110Sstevel@tonic-gate 25121228Sandrei if (cpuid_is_cmt(cpu)) 25130Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_chipid); 25140Sstevel@tonic-gate return (cpu->cpu_id); 25150Sstevel@tonic-gate } 25160Sstevel@tonic-gate 25171228Sandrei id_t 25183434Sesaxe cpuid_get_coreid(cpu_t *cpu) 25191228Sandrei { 25201228Sandrei ASSERT(cpuid_checkpass(cpu, 1)); 25211228Sandrei return (cpu->cpu_m.mcpu_cpi->cpi_coreid); 25221228Sandrei } 25231228Sandrei 25240Sstevel@tonic-gate int 25255870Sgavinm cpuid_get_pkgcoreid(cpu_t *cpu) 25265870Sgavinm { 25275870Sgavinm ASSERT(cpuid_checkpass(cpu, 1)); 25285870Sgavinm return (cpu->cpu_m.mcpu_cpi->cpi_pkgcoreid); 25295870Sgavinm } 25305870Sgavinm 25315870Sgavinm int 25323434Sesaxe cpuid_get_clogid(cpu_t *cpu) 25330Sstevel@tonic-gate { 25340Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 25350Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_clogid); 25360Sstevel@tonic-gate } 25370Sstevel@tonic-gate 2538*9652SMichael.Corcoran@Sun.COM uint32_t 2539*9652SMichael.Corcoran@Sun.COM cpuid_get_apicid(cpu_t *cpu) 2540*9652SMichael.Corcoran@Sun.COM { 2541*9652SMichael.Corcoran@Sun.COM ASSERT(cpuid_checkpass(cpu, 1)); 2542*9652SMichael.Corcoran@Sun.COM if (cpu->cpu_m.mcpu_cpi->cpi_maxeax < 1) { 2543*9652SMichael.Corcoran@Sun.COM return (UINT32_MAX); 2544*9652SMichael.Corcoran@Sun.COM } else { 2545*9652SMichael.Corcoran@Sun.COM return (cpu->cpu_m.mcpu_cpi->cpi_apicid); 2546*9652SMichael.Corcoran@Sun.COM } 2547*9652SMichael.Corcoran@Sun.COM } 2548*9652SMichael.Corcoran@Sun.COM 25490Sstevel@tonic-gate void 25500Sstevel@tonic-gate cpuid_get_addrsize(cpu_t *cpu, uint_t *pabits, uint_t *vabits) 25510Sstevel@tonic-gate { 25520Sstevel@tonic-gate struct cpuid_info *cpi; 25530Sstevel@tonic-gate 25540Sstevel@tonic-gate if (cpu == NULL) 25550Sstevel@tonic-gate cpu = CPU; 25560Sstevel@tonic-gate cpi = cpu->cpu_m.mcpu_cpi; 25570Sstevel@tonic-gate 25580Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 25590Sstevel@tonic-gate 25600Sstevel@tonic-gate if (pabits) 25610Sstevel@tonic-gate *pabits = cpi->cpi_pabits; 25620Sstevel@tonic-gate if (vabits) 25630Sstevel@tonic-gate *vabits = cpi->cpi_vabits; 25640Sstevel@tonic-gate } 25650Sstevel@tonic-gate 25660Sstevel@tonic-gate /* 25670Sstevel@tonic-gate * Returns the number of data TLB entries for a corresponding 25680Sstevel@tonic-gate * pagesize. If it can't be computed, or isn't known, the 25690Sstevel@tonic-gate * routine returns zero. If you ask about an architecturally 25700Sstevel@tonic-gate * impossible pagesize, the routine will panic (so that the 25710Sstevel@tonic-gate * hat implementor knows that things are inconsistent.) 25720Sstevel@tonic-gate */ 25730Sstevel@tonic-gate uint_t 25740Sstevel@tonic-gate cpuid_get_dtlb_nent(cpu_t *cpu, size_t pagesize) 25750Sstevel@tonic-gate { 25760Sstevel@tonic-gate struct cpuid_info *cpi; 25770Sstevel@tonic-gate uint_t dtlb_nent = 0; 25780Sstevel@tonic-gate 25790Sstevel@tonic-gate if (cpu == NULL) 25800Sstevel@tonic-gate cpu = CPU; 25810Sstevel@tonic-gate cpi = cpu->cpu_m.mcpu_cpi; 25820Sstevel@tonic-gate 25830Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 25840Sstevel@tonic-gate 25850Sstevel@tonic-gate /* 25860Sstevel@tonic-gate * Check the L2 TLB info 25870Sstevel@tonic-gate */ 25880Sstevel@tonic-gate if (cpi->cpi_xmaxeax >= 0x80000006) { 25891228Sandrei struct cpuid_regs *cp = &cpi->cpi_extd[6]; 25900Sstevel@tonic-gate 25910Sstevel@tonic-gate switch (pagesize) { 25920Sstevel@tonic-gate 25930Sstevel@tonic-gate case 4 * 1024: 25940Sstevel@tonic-gate /* 25950Sstevel@tonic-gate * All zero in the top 16 bits of the register 25960Sstevel@tonic-gate * indicates a unified TLB. Size is in low 16 bits. 25970Sstevel@tonic-gate */ 25980Sstevel@tonic-gate if ((cp->cp_ebx & 0xffff0000) == 0) 25990Sstevel@tonic-gate dtlb_nent = cp->cp_ebx & 0x0000ffff; 26000Sstevel@tonic-gate else 26010Sstevel@tonic-gate dtlb_nent = BITX(cp->cp_ebx, 27, 16); 26020Sstevel@tonic-gate break; 26030Sstevel@tonic-gate 26040Sstevel@tonic-gate case 2 * 1024 * 1024: 26050Sstevel@tonic-gate if ((cp->cp_eax & 0xffff0000) == 0) 26060Sstevel@tonic-gate dtlb_nent = cp->cp_eax & 0x0000ffff; 26070Sstevel@tonic-gate else 26080Sstevel@tonic-gate dtlb_nent = BITX(cp->cp_eax, 27, 16); 26090Sstevel@tonic-gate break; 26100Sstevel@tonic-gate 26110Sstevel@tonic-gate default: 26120Sstevel@tonic-gate panic("unknown L2 pagesize"); 26130Sstevel@tonic-gate /*NOTREACHED*/ 26140Sstevel@tonic-gate } 26150Sstevel@tonic-gate } 26160Sstevel@tonic-gate 26170Sstevel@tonic-gate if (dtlb_nent != 0) 26180Sstevel@tonic-gate return (dtlb_nent); 26190Sstevel@tonic-gate 26200Sstevel@tonic-gate /* 26210Sstevel@tonic-gate * No L2 TLB support for this size, try L1. 26220Sstevel@tonic-gate */ 26230Sstevel@tonic-gate if (cpi->cpi_xmaxeax >= 0x80000005) { 26241228Sandrei struct cpuid_regs *cp = &cpi->cpi_extd[5]; 26250Sstevel@tonic-gate 26260Sstevel@tonic-gate switch (pagesize) { 26270Sstevel@tonic-gate case 4 * 1024: 26280Sstevel@tonic-gate dtlb_nent = BITX(cp->cp_ebx, 23, 16); 26290Sstevel@tonic-gate break; 26300Sstevel@tonic-gate case 2 * 1024 * 1024: 26310Sstevel@tonic-gate dtlb_nent = BITX(cp->cp_eax, 23, 16); 26320Sstevel@tonic-gate break; 26330Sstevel@tonic-gate default: 26340Sstevel@tonic-gate panic("unknown L1 d-TLB pagesize"); 26350Sstevel@tonic-gate /*NOTREACHED*/ 26360Sstevel@tonic-gate } 26370Sstevel@tonic-gate } 26380Sstevel@tonic-gate 26390Sstevel@tonic-gate return (dtlb_nent); 26400Sstevel@tonic-gate } 26410Sstevel@tonic-gate 26420Sstevel@tonic-gate /* 26430Sstevel@tonic-gate * Return 0 if the erratum is not present or not applicable, positive 26440Sstevel@tonic-gate * if it is, and negative if the status of the erratum is unknown. 26450Sstevel@tonic-gate * 26460Sstevel@tonic-gate * See "Revision Guide for AMD Athlon(tm) 64 and AMD Opteron(tm) 2647359Skucharsk * Processors" #25759, Rev 3.57, August 2005 26480Sstevel@tonic-gate */ 26490Sstevel@tonic-gate int 26500Sstevel@tonic-gate cpuid_opteron_erratum(cpu_t *cpu, uint_t erratum) 26510Sstevel@tonic-gate { 26520Sstevel@tonic-gate struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 26531228Sandrei uint_t eax; 26540Sstevel@tonic-gate 26552584Ssethg /* 26562584Ssethg * Bail out if this CPU isn't an AMD CPU, or if it's 26572584Ssethg * a legacy (32-bit) AMD CPU. 26582584Ssethg */ 26592584Ssethg if (cpi->cpi_vendor != X86_VENDOR_AMD || 26604265Skchow cpi->cpi_family == 4 || cpi->cpi_family == 5 || 26614265Skchow cpi->cpi_family == 6) 26622869Sgavinm 26630Sstevel@tonic-gate return (0); 26640Sstevel@tonic-gate 26650Sstevel@tonic-gate eax = cpi->cpi_std[1].cp_eax; 26660Sstevel@tonic-gate 26670Sstevel@tonic-gate #define SH_B0(eax) (eax == 0xf40 || eax == 0xf50) 26680Sstevel@tonic-gate #define SH_B3(eax) (eax == 0xf51) 26691582Skchow #define B(eax) (SH_B0(eax) || SH_B3(eax)) 26700Sstevel@tonic-gate 26710Sstevel@tonic-gate #define SH_C0(eax) (eax == 0xf48 || eax == 0xf58) 26720Sstevel@tonic-gate 26730Sstevel@tonic-gate #define SH_CG(eax) (eax == 0xf4a || eax == 0xf5a || eax == 0xf7a) 26740Sstevel@tonic-gate #define DH_CG(eax) (eax == 0xfc0 || eax == 0xfe0 || eax == 0xff0) 26750Sstevel@tonic-gate #define CH_CG(eax) (eax == 0xf82 || eax == 0xfb2) 26761582Skchow #define CG(eax) (SH_CG(eax) || DH_CG(eax) || CH_CG(eax)) 26770Sstevel@tonic-gate 26780Sstevel@tonic-gate #define SH_D0(eax) (eax == 0x10f40 || eax == 0x10f50 || eax == 0x10f70) 26790Sstevel@tonic-gate #define DH_D0(eax) (eax == 0x10fc0 || eax == 0x10ff0) 26800Sstevel@tonic-gate #define CH_D0(eax) (eax == 0x10f80 || eax == 0x10fb0) 26811582Skchow #define D0(eax) (SH_D0(eax) || DH_D0(eax) || CH_D0(eax)) 26820Sstevel@tonic-gate 26830Sstevel@tonic-gate #define SH_E0(eax) (eax == 0x20f50 || eax == 0x20f40 || eax == 0x20f70) 26840Sstevel@tonic-gate #define JH_E1(eax) (eax == 0x20f10) /* JH8_E0 had 0x20f30 */ 26850Sstevel@tonic-gate #define DH_E3(eax) (eax == 0x20fc0 || eax == 0x20ff0) 26860Sstevel@tonic-gate #define SH_E4(eax) (eax == 0x20f51 || eax == 0x20f71) 26870Sstevel@tonic-gate #define BH_E4(eax) (eax == 0x20fb1) 26880Sstevel@tonic-gate #define SH_E5(eax) (eax == 0x20f42) 26890Sstevel@tonic-gate #define DH_E6(eax) (eax == 0x20ff2 || eax == 0x20fc2) 26900Sstevel@tonic-gate #define JH_E6(eax) (eax == 0x20f12 || eax == 0x20f32) 26911582Skchow #define EX(eax) (SH_E0(eax) || JH_E1(eax) || DH_E3(eax) || \ 26921582Skchow SH_E4(eax) || BH_E4(eax) || SH_E5(eax) || \ 26931582Skchow DH_E6(eax) || JH_E6(eax)) 26940Sstevel@tonic-gate 26956691Skchow #define DR_AX(eax) (eax == 0x100f00 || eax == 0x100f01 || eax == 0x100f02) 26966691Skchow #define DR_B0(eax) (eax == 0x100f20) 26976691Skchow #define DR_B1(eax) (eax == 0x100f21) 26986691Skchow #define DR_BA(eax) (eax == 0x100f2a) 26996691Skchow #define DR_B2(eax) (eax == 0x100f22) 27006691Skchow #define DR_B3(eax) (eax == 0x100f23) 27016691Skchow #define RB_C0(eax) (eax == 0x100f40) 27026691Skchow 27030Sstevel@tonic-gate switch (erratum) { 27040Sstevel@tonic-gate case 1: 27054265Skchow return (cpi->cpi_family < 0x10); 27060Sstevel@tonic-gate case 51: /* what does the asterisk mean? */ 27070Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax)); 27080Sstevel@tonic-gate case 52: 27090Sstevel@tonic-gate return (B(eax)); 27100Sstevel@tonic-gate case 57: 27116691Skchow return (cpi->cpi_family <= 0x11); 27120Sstevel@tonic-gate case 58: 27130Sstevel@tonic-gate return (B(eax)); 27140Sstevel@tonic-gate case 60: 27156691Skchow return (cpi->cpi_family <= 0x11); 27160Sstevel@tonic-gate case 61: 27170Sstevel@tonic-gate case 62: 27180Sstevel@tonic-gate case 63: 27190Sstevel@tonic-gate case 64: 27200Sstevel@tonic-gate case 65: 27210Sstevel@tonic-gate case 66: 27220Sstevel@tonic-gate case 68: 27230Sstevel@tonic-gate case 69: 27240Sstevel@tonic-gate case 70: 27250Sstevel@tonic-gate case 71: 27260Sstevel@tonic-gate return (B(eax)); 27270Sstevel@tonic-gate case 72: 27280Sstevel@tonic-gate return (SH_B0(eax)); 27290Sstevel@tonic-gate case 74: 27300Sstevel@tonic-gate return (B(eax)); 27310Sstevel@tonic-gate case 75: 27324265Skchow return (cpi->cpi_family < 0x10); 27330Sstevel@tonic-gate case 76: 27340Sstevel@tonic-gate return (B(eax)); 27350Sstevel@tonic-gate case 77: 27366691Skchow return (cpi->cpi_family <= 0x11); 27370Sstevel@tonic-gate case 78: 27380Sstevel@tonic-gate return (B(eax) || SH_C0(eax)); 27390Sstevel@tonic-gate case 79: 27400Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax) || EX(eax)); 27410Sstevel@tonic-gate case 80: 27420Sstevel@tonic-gate case 81: 27430Sstevel@tonic-gate case 82: 27440Sstevel@tonic-gate return (B(eax)); 27450Sstevel@tonic-gate case 83: 27460Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax)); 27470Sstevel@tonic-gate case 85: 27484265Skchow return (cpi->cpi_family < 0x10); 27490Sstevel@tonic-gate case 86: 27500Sstevel@tonic-gate return (SH_C0(eax) || CG(eax)); 27510Sstevel@tonic-gate case 88: 27520Sstevel@tonic-gate #if !defined(__amd64) 27530Sstevel@tonic-gate return (0); 27540Sstevel@tonic-gate #else 27550Sstevel@tonic-gate return (B(eax) || SH_C0(eax)); 27560Sstevel@tonic-gate #endif 27570Sstevel@tonic-gate case 89: 27584265Skchow return (cpi->cpi_family < 0x10); 27590Sstevel@tonic-gate case 90: 27600Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax)); 27610Sstevel@tonic-gate case 91: 27620Sstevel@tonic-gate case 92: 27630Sstevel@tonic-gate return (B(eax) || SH_C0(eax)); 27640Sstevel@tonic-gate case 93: 27650Sstevel@tonic-gate return (SH_C0(eax)); 27660Sstevel@tonic-gate case 94: 27670Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax)); 27680Sstevel@tonic-gate case 95: 27690Sstevel@tonic-gate #if !defined(__amd64) 27700Sstevel@tonic-gate return (0); 27710Sstevel@tonic-gate #else 27720Sstevel@tonic-gate return (B(eax) || SH_C0(eax)); 27730Sstevel@tonic-gate #endif 27740Sstevel@tonic-gate case 96: 27750Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax)); 27760Sstevel@tonic-gate case 97: 27770Sstevel@tonic-gate case 98: 27780Sstevel@tonic-gate return (SH_C0(eax) || CG(eax)); 27790Sstevel@tonic-gate case 99: 27800Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax)); 27810Sstevel@tonic-gate case 100: 27820Sstevel@tonic-gate return (B(eax) || SH_C0(eax)); 27830Sstevel@tonic-gate case 101: 27840Sstevel@tonic-gate case 103: 27850Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax)); 27860Sstevel@tonic-gate case 104: 27870Sstevel@tonic-gate return (SH_C0(eax) || CG(eax) || D0(eax)); 27880Sstevel@tonic-gate case 105: 27890Sstevel@tonic-gate case 106: 27900Sstevel@tonic-gate case 107: 27910Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax)); 27920Sstevel@tonic-gate case 108: 27930Sstevel@tonic-gate return (DH_CG(eax)); 27940Sstevel@tonic-gate case 109: 27950Sstevel@tonic-gate return (SH_C0(eax) || CG(eax) || D0(eax)); 27960Sstevel@tonic-gate case 110: 27970Sstevel@tonic-gate return (D0(eax) || EX(eax)); 27980Sstevel@tonic-gate case 111: 27990Sstevel@tonic-gate return (CG(eax)); 28000Sstevel@tonic-gate case 112: 28010Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax) || EX(eax)); 28020Sstevel@tonic-gate case 113: 28030Sstevel@tonic-gate return (eax == 0x20fc0); 28040Sstevel@tonic-gate case 114: 28050Sstevel@tonic-gate return (SH_E0(eax) || JH_E1(eax) || DH_E3(eax)); 28060Sstevel@tonic-gate case 115: 28070Sstevel@tonic-gate return (SH_E0(eax) || JH_E1(eax)); 28080Sstevel@tonic-gate case 116: 28090Sstevel@tonic-gate return (SH_E0(eax) || JH_E1(eax) || DH_E3(eax)); 28100Sstevel@tonic-gate case 117: 28110Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax)); 28120Sstevel@tonic-gate case 118: 28130Sstevel@tonic-gate return (SH_E0(eax) || JH_E1(eax) || SH_E4(eax) || BH_E4(eax) || 28140Sstevel@tonic-gate JH_E6(eax)); 28150Sstevel@tonic-gate case 121: 28160Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax) || EX(eax)); 28170Sstevel@tonic-gate case 122: 28186691Skchow return (cpi->cpi_family < 0x10 || cpi->cpi_family == 0x11); 28190Sstevel@tonic-gate case 123: 28200Sstevel@tonic-gate return (JH_E1(eax) || BH_E4(eax) || JH_E6(eax)); 2821359Skucharsk case 131: 28224265Skchow return (cpi->cpi_family < 0x10); 2823938Sesaxe case 6336786: 2824938Sesaxe /* 2825938Sesaxe * Test for AdvPowerMgmtInfo.TscPStateInvariant 28264265Skchow * if this is a K8 family or newer processor 2827938Sesaxe */ 2828938Sesaxe if (CPI_FAMILY(cpi) == 0xf) { 28291228Sandrei struct cpuid_regs regs; 28301228Sandrei regs.cp_eax = 0x80000007; 28311228Sandrei (void) __cpuid_insn(®s); 28321228Sandrei return (!(regs.cp_edx & 0x100)); 2833938Sesaxe } 2834938Sesaxe return (0); 28351582Skchow case 6323525: 28361582Skchow return (((((eax >> 12) & 0xff00) + (eax & 0xf00)) | 28371582Skchow (((eax >> 4) & 0xf) | ((eax >> 12) & 0xf0))) < 0xf40); 28381582Skchow 28396691Skchow case 6671130: 28406691Skchow /* 28416691Skchow * check for processors (pre-Shanghai) that do not provide 28426691Skchow * optimal management of 1gb ptes in its tlb. 28436691Skchow */ 28446691Skchow return (cpi->cpi_family == 0x10 && cpi->cpi_model < 4); 28456691Skchow 28466691Skchow case 298: 28476691Skchow return (DR_AX(eax) || DR_B0(eax) || DR_B1(eax) || DR_BA(eax) || 28486691Skchow DR_B2(eax) || RB_C0(eax)); 28496691Skchow 28506691Skchow default: 28516691Skchow return (-1); 28526691Skchow 28536691Skchow } 28546691Skchow } 28556691Skchow 28566691Skchow /* 28576691Skchow * Determine if specified erratum is present via OSVW (OS Visible Workaround). 28586691Skchow * Return 1 if erratum is present, 0 if not present and -1 if indeterminate. 28596691Skchow */ 28606691Skchow int 28616691Skchow osvw_opteron_erratum(cpu_t *cpu, uint_t erratum) 28626691Skchow { 28636691Skchow struct cpuid_info *cpi; 28646691Skchow uint_t osvwid; 28656691Skchow static int osvwfeature = -1; 28666691Skchow uint64_t osvwlength; 28676691Skchow 28686691Skchow 28696691Skchow cpi = cpu->cpu_m.mcpu_cpi; 28706691Skchow 28716691Skchow /* confirm OSVW supported */ 28726691Skchow if (osvwfeature == -1) { 28736691Skchow osvwfeature = cpi->cpi_extd[1].cp_ecx & CPUID_AMD_ECX_OSVW; 28746691Skchow } else { 28756691Skchow /* assert that osvw feature setting is consistent on all cpus */ 28766691Skchow ASSERT(osvwfeature == 28776691Skchow (cpi->cpi_extd[1].cp_ecx & CPUID_AMD_ECX_OSVW)); 28786691Skchow } 28796691Skchow if (!osvwfeature) 28806691Skchow return (-1); 28816691Skchow 28826691Skchow osvwlength = rdmsr(MSR_AMD_OSVW_ID_LEN) & OSVW_ID_LEN_MASK; 28836691Skchow 28846691Skchow switch (erratum) { 28856691Skchow case 298: /* osvwid is 0 */ 28866691Skchow osvwid = 0; 28876691Skchow if (osvwlength <= (uint64_t)osvwid) { 28886691Skchow /* osvwid 0 is unknown */ 28896691Skchow return (-1); 28906691Skchow } 28916691Skchow 28926691Skchow /* 28936691Skchow * Check the OSVW STATUS MSR to determine the state 28946691Skchow * of the erratum where: 28956691Skchow * 0 - fixed by HW 28966691Skchow * 1 - BIOS has applied the workaround when BIOS 28976691Skchow * workaround is available. (Or for other errata, 28986691Skchow * OS workaround is required.) 28996691Skchow * For a value of 1, caller will confirm that the 29006691Skchow * erratum 298 workaround has indeed been applied by BIOS. 29016691Skchow * 29026691Skchow * A 1 may be set in cpus that have a HW fix 29036691Skchow * in a mixed cpu system. Regarding erratum 298: 29046691Skchow * In a multiprocessor platform, the workaround above 29056691Skchow * should be applied to all processors regardless of 29066691Skchow * silicon revision when an affected processor is 29076691Skchow * present. 29086691Skchow */ 29096691Skchow 29106691Skchow return (rdmsr(MSR_AMD_OSVW_STATUS + 29116691Skchow (osvwid / OSVW_ID_CNT_PER_MSR)) & 29126691Skchow (1ULL << (osvwid % OSVW_ID_CNT_PER_MSR))); 29136691Skchow 29140Sstevel@tonic-gate default: 29150Sstevel@tonic-gate return (-1); 29160Sstevel@tonic-gate } 29170Sstevel@tonic-gate } 29180Sstevel@tonic-gate 29190Sstevel@tonic-gate static const char assoc_str[] = "associativity"; 29200Sstevel@tonic-gate static const char line_str[] = "line-size"; 29210Sstevel@tonic-gate static const char size_str[] = "size"; 29220Sstevel@tonic-gate 29230Sstevel@tonic-gate static void 29240Sstevel@tonic-gate add_cache_prop(dev_info_t *devi, const char *label, const char *type, 29250Sstevel@tonic-gate uint32_t val) 29260Sstevel@tonic-gate { 29270Sstevel@tonic-gate char buf[128]; 29280Sstevel@tonic-gate 29290Sstevel@tonic-gate /* 29300Sstevel@tonic-gate * ndi_prop_update_int() is used because it is desirable for 29310Sstevel@tonic-gate * DDI_PROP_HW_DEF and DDI_PROP_DONTSLEEP to be set. 29320Sstevel@tonic-gate */ 29330Sstevel@tonic-gate if (snprintf(buf, sizeof (buf), "%s-%s", label, type) < sizeof (buf)) 29340Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, devi, buf, val); 29350Sstevel@tonic-gate } 29360Sstevel@tonic-gate 29370Sstevel@tonic-gate /* 29380Sstevel@tonic-gate * Intel-style cache/tlb description 29390Sstevel@tonic-gate * 29400Sstevel@tonic-gate * Standard cpuid level 2 gives a randomly ordered 29410Sstevel@tonic-gate * selection of tags that index into a table that describes 29420Sstevel@tonic-gate * cache and tlb properties. 29430Sstevel@tonic-gate */ 29440Sstevel@tonic-gate 29450Sstevel@tonic-gate static const char l1_icache_str[] = "l1-icache"; 29460Sstevel@tonic-gate static const char l1_dcache_str[] = "l1-dcache"; 29470Sstevel@tonic-gate static const char l2_cache_str[] = "l2-cache"; 29483446Smrj static const char l3_cache_str[] = "l3-cache"; 29490Sstevel@tonic-gate static const char itlb4k_str[] = "itlb-4K"; 29500Sstevel@tonic-gate static const char dtlb4k_str[] = "dtlb-4K"; 29516964Svd224797 static const char itlb2M_str[] = "itlb-2M"; 29520Sstevel@tonic-gate static const char itlb4M_str[] = "itlb-4M"; 29530Sstevel@tonic-gate static const char dtlb4M_str[] = "dtlb-4M"; 29546334Sksadhukh static const char dtlb24_str[] = "dtlb0-2M-4M"; 29550Sstevel@tonic-gate static const char itlb424_str[] = "itlb-4K-2M-4M"; 29566334Sksadhukh static const char itlb24_str[] = "itlb-2M-4M"; 29570Sstevel@tonic-gate static const char dtlb44_str[] = "dtlb-4K-4M"; 29580Sstevel@tonic-gate static const char sl1_dcache_str[] = "sectored-l1-dcache"; 29590Sstevel@tonic-gate static const char sl2_cache_str[] = "sectored-l2-cache"; 29600Sstevel@tonic-gate static const char itrace_str[] = "itrace-cache"; 29610Sstevel@tonic-gate static const char sl3_cache_str[] = "sectored-l3-cache"; 29626334Sksadhukh static const char sh_l2_tlb4k_str[] = "shared-l2-tlb-4k"; 29630Sstevel@tonic-gate 29640Sstevel@tonic-gate static const struct cachetab { 29650Sstevel@tonic-gate uint8_t ct_code; 29660Sstevel@tonic-gate uint8_t ct_assoc; 29670Sstevel@tonic-gate uint16_t ct_line_size; 29680Sstevel@tonic-gate size_t ct_size; 29690Sstevel@tonic-gate const char *ct_label; 29700Sstevel@tonic-gate } intel_ctab[] = { 29716964Svd224797 /* 29726964Svd224797 * maintain descending order! 29736964Svd224797 * 29746964Svd224797 * Codes ignored - Reason 29756964Svd224797 * ---------------------- 29766964Svd224797 * 40H - intel_cpuid_4_cache_info() disambiguates l2/l3 cache 29776964Svd224797 * f0H/f1H - Currently we do not interpret prefetch size by design 29786964Svd224797 */ 29796334Sksadhukh { 0xe4, 16, 64, 8*1024*1024, l3_cache_str}, 29806334Sksadhukh { 0xe3, 16, 64, 4*1024*1024, l3_cache_str}, 29816334Sksadhukh { 0xe2, 16, 64, 2*1024*1024, l3_cache_str}, 29826334Sksadhukh { 0xde, 12, 64, 6*1024*1024, l3_cache_str}, 29836334Sksadhukh { 0xdd, 12, 64, 3*1024*1024, l3_cache_str}, 29846334Sksadhukh { 0xdc, 12, 64, ((1*1024*1024)+(512*1024)), l3_cache_str}, 29856334Sksadhukh { 0xd8, 8, 64, 4*1024*1024, l3_cache_str}, 29866334Sksadhukh { 0xd7, 8, 64, 2*1024*1024, l3_cache_str}, 29876334Sksadhukh { 0xd6, 8, 64, 1*1024*1024, l3_cache_str}, 29886334Sksadhukh { 0xd2, 4, 64, 2*1024*1024, l3_cache_str}, 29896334Sksadhukh { 0xd1, 4, 64, 1*1024*1024, l3_cache_str}, 29906334Sksadhukh { 0xd0, 4, 64, 512*1024, l3_cache_str}, 29916334Sksadhukh { 0xca, 4, 0, 512, sh_l2_tlb4k_str}, 29926964Svd224797 { 0xc0, 4, 0, 8, dtlb44_str }, 29936964Svd224797 { 0xba, 4, 0, 64, dtlb4k_str }, 29943446Smrj { 0xb4, 4, 0, 256, dtlb4k_str }, 29950Sstevel@tonic-gate { 0xb3, 4, 0, 128, dtlb4k_str }, 29966334Sksadhukh { 0xb2, 4, 0, 64, itlb4k_str }, 29970Sstevel@tonic-gate { 0xb0, 4, 0, 128, itlb4k_str }, 29980Sstevel@tonic-gate { 0x87, 8, 64, 1024*1024, l2_cache_str}, 29990Sstevel@tonic-gate { 0x86, 4, 64, 512*1024, l2_cache_str}, 30000Sstevel@tonic-gate { 0x85, 8, 32, 2*1024*1024, l2_cache_str}, 30010Sstevel@tonic-gate { 0x84, 8, 32, 1024*1024, l2_cache_str}, 30020Sstevel@tonic-gate { 0x83, 8, 32, 512*1024, l2_cache_str}, 30030Sstevel@tonic-gate { 0x82, 8, 32, 256*1024, l2_cache_str}, 30046964Svd224797 { 0x80, 8, 64, 512*1024, l2_cache_str}, 30050Sstevel@tonic-gate { 0x7f, 2, 64, 512*1024, l2_cache_str}, 30060Sstevel@tonic-gate { 0x7d, 8, 64, 2*1024*1024, sl2_cache_str}, 30070Sstevel@tonic-gate { 0x7c, 8, 64, 1024*1024, sl2_cache_str}, 30080Sstevel@tonic-gate { 0x7b, 8, 64, 512*1024, sl2_cache_str}, 30090Sstevel@tonic-gate { 0x7a, 8, 64, 256*1024, sl2_cache_str}, 30100Sstevel@tonic-gate { 0x79, 8, 64, 128*1024, sl2_cache_str}, 30110Sstevel@tonic-gate { 0x78, 8, 64, 1024*1024, l2_cache_str}, 30123446Smrj { 0x73, 8, 0, 64*1024, itrace_str}, 30130Sstevel@tonic-gate { 0x72, 8, 0, 32*1024, itrace_str}, 30140Sstevel@tonic-gate { 0x71, 8, 0, 16*1024, itrace_str}, 30150Sstevel@tonic-gate { 0x70, 8, 0, 12*1024, itrace_str}, 30160Sstevel@tonic-gate { 0x68, 4, 64, 32*1024, sl1_dcache_str}, 30170Sstevel@tonic-gate { 0x67, 4, 64, 16*1024, sl1_dcache_str}, 30180Sstevel@tonic-gate { 0x66, 4, 64, 8*1024, sl1_dcache_str}, 30190Sstevel@tonic-gate { 0x60, 8, 64, 16*1024, sl1_dcache_str}, 30200Sstevel@tonic-gate { 0x5d, 0, 0, 256, dtlb44_str}, 30210Sstevel@tonic-gate { 0x5c, 0, 0, 128, dtlb44_str}, 30220Sstevel@tonic-gate { 0x5b, 0, 0, 64, dtlb44_str}, 30236334Sksadhukh { 0x5a, 4, 0, 32, dtlb24_str}, 30246964Svd224797 { 0x59, 0, 0, 16, dtlb4k_str}, 30256964Svd224797 { 0x57, 4, 0, 16, dtlb4k_str}, 30266964Svd224797 { 0x56, 4, 0, 16, dtlb4M_str}, 30276334Sksadhukh { 0x55, 0, 0, 7, itlb24_str}, 30280Sstevel@tonic-gate { 0x52, 0, 0, 256, itlb424_str}, 30290Sstevel@tonic-gate { 0x51, 0, 0, 128, itlb424_str}, 30300Sstevel@tonic-gate { 0x50, 0, 0, 64, itlb424_str}, 30316964Svd224797 { 0x4f, 0, 0, 32, itlb4k_str}, 30326964Svd224797 { 0x4e, 24, 64, 6*1024*1024, l2_cache_str}, 30333446Smrj { 0x4d, 16, 64, 16*1024*1024, l3_cache_str}, 30343446Smrj { 0x4c, 12, 64, 12*1024*1024, l3_cache_str}, 30353446Smrj { 0x4b, 16, 64, 8*1024*1024, l3_cache_str}, 30363446Smrj { 0x4a, 12, 64, 6*1024*1024, l3_cache_str}, 30373446Smrj { 0x49, 16, 64, 4*1024*1024, l3_cache_str}, 30386964Svd224797 { 0x48, 12, 64, 3*1024*1024, l2_cache_str}, 30393446Smrj { 0x47, 8, 64, 8*1024*1024, l3_cache_str}, 30403446Smrj { 0x46, 4, 64, 4*1024*1024, l3_cache_str}, 30410Sstevel@tonic-gate { 0x45, 4, 32, 2*1024*1024, l2_cache_str}, 30420Sstevel@tonic-gate { 0x44, 4, 32, 1024*1024, l2_cache_str}, 30430Sstevel@tonic-gate { 0x43, 4, 32, 512*1024, l2_cache_str}, 30440Sstevel@tonic-gate { 0x42, 4, 32, 256*1024, l2_cache_str}, 30450Sstevel@tonic-gate { 0x41, 4, 32, 128*1024, l2_cache_str}, 30463446Smrj { 0x3e, 4, 64, 512*1024, sl2_cache_str}, 30473446Smrj { 0x3d, 6, 64, 384*1024, sl2_cache_str}, 30480Sstevel@tonic-gate { 0x3c, 4, 64, 256*1024, sl2_cache_str}, 30490Sstevel@tonic-gate { 0x3b, 2, 64, 128*1024, sl2_cache_str}, 30503446Smrj { 0x3a, 6, 64, 192*1024, sl2_cache_str}, 30510Sstevel@tonic-gate { 0x39, 4, 64, 128*1024, sl2_cache_str}, 30520Sstevel@tonic-gate { 0x30, 8, 64, 32*1024, l1_icache_str}, 30530Sstevel@tonic-gate { 0x2c, 8, 64, 32*1024, l1_dcache_str}, 30540Sstevel@tonic-gate { 0x29, 8, 64, 4096*1024, sl3_cache_str}, 30550Sstevel@tonic-gate { 0x25, 8, 64, 2048*1024, sl3_cache_str}, 30560Sstevel@tonic-gate { 0x23, 8, 64, 1024*1024, sl3_cache_str}, 30570Sstevel@tonic-gate { 0x22, 4, 64, 512*1024, sl3_cache_str}, 30586964Svd224797 { 0x0e, 6, 64, 24*1024, l1_dcache_str}, 30596334Sksadhukh { 0x0d, 4, 32, 16*1024, l1_dcache_str}, 30600Sstevel@tonic-gate { 0x0c, 4, 32, 16*1024, l1_dcache_str}, 30613446Smrj { 0x0b, 4, 0, 4, itlb4M_str}, 30620Sstevel@tonic-gate { 0x0a, 2, 32, 8*1024, l1_dcache_str}, 30630Sstevel@tonic-gate { 0x08, 4, 32, 16*1024, l1_icache_str}, 30640Sstevel@tonic-gate { 0x06, 4, 32, 8*1024, l1_icache_str}, 30656964Svd224797 { 0x05, 4, 0, 32, dtlb4M_str}, 30660Sstevel@tonic-gate { 0x04, 4, 0, 8, dtlb4M_str}, 30670Sstevel@tonic-gate { 0x03, 4, 0, 64, dtlb4k_str}, 30680Sstevel@tonic-gate { 0x02, 4, 0, 2, itlb4M_str}, 30690Sstevel@tonic-gate { 0x01, 4, 0, 32, itlb4k_str}, 30700Sstevel@tonic-gate { 0 } 30710Sstevel@tonic-gate }; 30720Sstevel@tonic-gate 30730Sstevel@tonic-gate static const struct cachetab cyrix_ctab[] = { 30740Sstevel@tonic-gate { 0x70, 4, 0, 32, "tlb-4K" }, 30750Sstevel@tonic-gate { 0x80, 4, 16, 16*1024, "l1-cache" }, 30760Sstevel@tonic-gate { 0 } 30770Sstevel@tonic-gate }; 30780Sstevel@tonic-gate 30790Sstevel@tonic-gate /* 30800Sstevel@tonic-gate * Search a cache table for a matching entry 30810Sstevel@tonic-gate */ 30820Sstevel@tonic-gate static const struct cachetab * 30830Sstevel@tonic-gate find_cacheent(const struct cachetab *ct, uint_t code) 30840Sstevel@tonic-gate { 30850Sstevel@tonic-gate if (code != 0) { 30860Sstevel@tonic-gate for (; ct->ct_code != 0; ct++) 30870Sstevel@tonic-gate if (ct->ct_code <= code) 30880Sstevel@tonic-gate break; 30890Sstevel@tonic-gate if (ct->ct_code == code) 30900Sstevel@tonic-gate return (ct); 30910Sstevel@tonic-gate } 30920Sstevel@tonic-gate return (NULL); 30930Sstevel@tonic-gate } 30940Sstevel@tonic-gate 30950Sstevel@tonic-gate /* 30965438Sksadhukh * Populate cachetab entry with L2 or L3 cache-information using 30975438Sksadhukh * cpuid function 4. This function is called from intel_walk_cacheinfo() 30985438Sksadhukh * when descriptor 0x49 is encountered. It returns 0 if no such cache 30995438Sksadhukh * information is found. 31005438Sksadhukh */ 31015438Sksadhukh static int 31025438Sksadhukh intel_cpuid_4_cache_info(struct cachetab *ct, struct cpuid_info *cpi) 31035438Sksadhukh { 31045438Sksadhukh uint32_t level, i; 31055438Sksadhukh int ret = 0; 31065438Sksadhukh 31075438Sksadhukh for (i = 0; i < cpi->cpi_std_4_size; i++) { 31085438Sksadhukh level = CPI_CACHE_LVL(cpi->cpi_std_4[i]); 31095438Sksadhukh 31105438Sksadhukh if (level == 2 || level == 3) { 31115438Sksadhukh ct->ct_assoc = CPI_CACHE_WAYS(cpi->cpi_std_4[i]) + 1; 31125438Sksadhukh ct->ct_line_size = 31135438Sksadhukh CPI_CACHE_COH_LN_SZ(cpi->cpi_std_4[i]) + 1; 31145438Sksadhukh ct->ct_size = ct->ct_assoc * 31155438Sksadhukh (CPI_CACHE_PARTS(cpi->cpi_std_4[i]) + 1) * 31165438Sksadhukh ct->ct_line_size * 31175438Sksadhukh (cpi->cpi_std_4[i]->cp_ecx + 1); 31185438Sksadhukh 31195438Sksadhukh if (level == 2) { 31205438Sksadhukh ct->ct_label = l2_cache_str; 31215438Sksadhukh } else if (level == 3) { 31225438Sksadhukh ct->ct_label = l3_cache_str; 31235438Sksadhukh } 31245438Sksadhukh ret = 1; 31255438Sksadhukh } 31265438Sksadhukh } 31275438Sksadhukh 31285438Sksadhukh return (ret); 31295438Sksadhukh } 31305438Sksadhukh 31315438Sksadhukh /* 31320Sstevel@tonic-gate * Walk the cacheinfo descriptor, applying 'func' to every valid element 31330Sstevel@tonic-gate * The walk is terminated if the walker returns non-zero. 31340Sstevel@tonic-gate */ 31350Sstevel@tonic-gate static void 31360Sstevel@tonic-gate intel_walk_cacheinfo(struct cpuid_info *cpi, 31370Sstevel@tonic-gate void *arg, int (*func)(void *, const struct cachetab *)) 31380Sstevel@tonic-gate { 31390Sstevel@tonic-gate const struct cachetab *ct; 31406964Svd224797 struct cachetab des_49_ct, des_b1_ct; 31410Sstevel@tonic-gate uint8_t *dp; 31420Sstevel@tonic-gate int i; 31430Sstevel@tonic-gate 31440Sstevel@tonic-gate if ((dp = cpi->cpi_cacheinfo) == NULL) 31450Sstevel@tonic-gate return; 31464797Sksadhukh for (i = 0; i < cpi->cpi_ncache; i++, dp++) { 31474797Sksadhukh /* 31484797Sksadhukh * For overloaded descriptor 0x49 we use cpuid function 4 31495438Sksadhukh * if supported by the current processor, to create 31504797Sksadhukh * cache information. 31516964Svd224797 * For overloaded descriptor 0xb1 we use X86_PAE flag 31526964Svd224797 * to disambiguate the cache information. 31534797Sksadhukh */ 31545438Sksadhukh if (*dp == 0x49 && cpi->cpi_maxeax >= 0x4 && 31555438Sksadhukh intel_cpuid_4_cache_info(&des_49_ct, cpi) == 1) { 31565438Sksadhukh ct = &des_49_ct; 31576964Svd224797 } else if (*dp == 0xb1) { 31586964Svd224797 des_b1_ct.ct_code = 0xb1; 31596964Svd224797 des_b1_ct.ct_assoc = 4; 31606964Svd224797 des_b1_ct.ct_line_size = 0; 31616964Svd224797 if (x86_feature & X86_PAE) { 31626964Svd224797 des_b1_ct.ct_size = 8; 31636964Svd224797 des_b1_ct.ct_label = itlb2M_str; 31646964Svd224797 } else { 31656964Svd224797 des_b1_ct.ct_size = 4; 31666964Svd224797 des_b1_ct.ct_label = itlb4M_str; 31676964Svd224797 } 31686964Svd224797 ct = &des_b1_ct; 31695438Sksadhukh } else { 31705438Sksadhukh if ((ct = find_cacheent(intel_ctab, *dp)) == NULL) { 31715438Sksadhukh continue; 31725438Sksadhukh } 31734797Sksadhukh } 31744797Sksadhukh 31755438Sksadhukh if (func(arg, ct) != 0) { 31765438Sksadhukh break; 31770Sstevel@tonic-gate } 31784797Sksadhukh } 31790Sstevel@tonic-gate } 31800Sstevel@tonic-gate 31810Sstevel@tonic-gate /* 31820Sstevel@tonic-gate * (Like the Intel one, except for Cyrix CPUs) 31830Sstevel@tonic-gate */ 31840Sstevel@tonic-gate static void 31850Sstevel@tonic-gate cyrix_walk_cacheinfo(struct cpuid_info *cpi, 31860Sstevel@tonic-gate void *arg, int (*func)(void *, const struct cachetab *)) 31870Sstevel@tonic-gate { 31880Sstevel@tonic-gate const struct cachetab *ct; 31890Sstevel@tonic-gate uint8_t *dp; 31900Sstevel@tonic-gate int i; 31910Sstevel@tonic-gate 31920Sstevel@tonic-gate if ((dp = cpi->cpi_cacheinfo) == NULL) 31930Sstevel@tonic-gate return; 31940Sstevel@tonic-gate for (i = 0; i < cpi->cpi_ncache; i++, dp++) { 31950Sstevel@tonic-gate /* 31960Sstevel@tonic-gate * Search Cyrix-specific descriptor table first .. 31970Sstevel@tonic-gate */ 31980Sstevel@tonic-gate if ((ct = find_cacheent(cyrix_ctab, *dp)) != NULL) { 31990Sstevel@tonic-gate if (func(arg, ct) != 0) 32000Sstevel@tonic-gate break; 32010Sstevel@tonic-gate continue; 32020Sstevel@tonic-gate } 32030Sstevel@tonic-gate /* 32040Sstevel@tonic-gate * .. else fall back to the Intel one 32050Sstevel@tonic-gate */ 32060Sstevel@tonic-gate if ((ct = find_cacheent(intel_ctab, *dp)) != NULL) { 32070Sstevel@tonic-gate if (func(arg, ct) != 0) 32080Sstevel@tonic-gate break; 32090Sstevel@tonic-gate continue; 32100Sstevel@tonic-gate } 32110Sstevel@tonic-gate } 32120Sstevel@tonic-gate } 32130Sstevel@tonic-gate 32140Sstevel@tonic-gate /* 32150Sstevel@tonic-gate * A cacheinfo walker that adds associativity, line-size, and size properties 32160Sstevel@tonic-gate * to the devinfo node it is passed as an argument. 32170Sstevel@tonic-gate */ 32180Sstevel@tonic-gate static int 32190Sstevel@tonic-gate add_cacheent_props(void *arg, const struct cachetab *ct) 32200Sstevel@tonic-gate { 32210Sstevel@tonic-gate dev_info_t *devi = arg; 32220Sstevel@tonic-gate 32230Sstevel@tonic-gate add_cache_prop(devi, ct->ct_label, assoc_str, ct->ct_assoc); 32240Sstevel@tonic-gate if (ct->ct_line_size != 0) 32250Sstevel@tonic-gate add_cache_prop(devi, ct->ct_label, line_str, 32260Sstevel@tonic-gate ct->ct_line_size); 32270Sstevel@tonic-gate add_cache_prop(devi, ct->ct_label, size_str, ct->ct_size); 32280Sstevel@tonic-gate return (0); 32290Sstevel@tonic-gate } 32300Sstevel@tonic-gate 32314797Sksadhukh 32320Sstevel@tonic-gate static const char fully_assoc[] = "fully-associative?"; 32330Sstevel@tonic-gate 32340Sstevel@tonic-gate /* 32350Sstevel@tonic-gate * AMD style cache/tlb description 32360Sstevel@tonic-gate * 32370Sstevel@tonic-gate * Extended functions 5 and 6 directly describe properties of 32380Sstevel@tonic-gate * tlbs and various cache levels. 32390Sstevel@tonic-gate */ 32400Sstevel@tonic-gate static void 32410Sstevel@tonic-gate add_amd_assoc(dev_info_t *devi, const char *label, uint_t assoc) 32420Sstevel@tonic-gate { 32430Sstevel@tonic-gate switch (assoc) { 32440Sstevel@tonic-gate case 0: /* reserved; ignore */ 32450Sstevel@tonic-gate break; 32460Sstevel@tonic-gate default: 32470Sstevel@tonic-gate add_cache_prop(devi, label, assoc_str, assoc); 32480Sstevel@tonic-gate break; 32490Sstevel@tonic-gate case 0xff: 32500Sstevel@tonic-gate add_cache_prop(devi, label, fully_assoc, 1); 32510Sstevel@tonic-gate break; 32520Sstevel@tonic-gate } 32530Sstevel@tonic-gate } 32540Sstevel@tonic-gate 32550Sstevel@tonic-gate static void 32560Sstevel@tonic-gate add_amd_tlb(dev_info_t *devi, const char *label, uint_t assoc, uint_t size) 32570Sstevel@tonic-gate { 32580Sstevel@tonic-gate if (size == 0) 32590Sstevel@tonic-gate return; 32600Sstevel@tonic-gate add_cache_prop(devi, label, size_str, size); 32610Sstevel@tonic-gate add_amd_assoc(devi, label, assoc); 32620Sstevel@tonic-gate } 32630Sstevel@tonic-gate 32640Sstevel@tonic-gate static void 32650Sstevel@tonic-gate add_amd_cache(dev_info_t *devi, const char *label, 32660Sstevel@tonic-gate uint_t size, uint_t assoc, uint_t lines_per_tag, uint_t line_size) 32670Sstevel@tonic-gate { 32680Sstevel@tonic-gate if (size == 0 || line_size == 0) 32690Sstevel@tonic-gate return; 32700Sstevel@tonic-gate add_amd_assoc(devi, label, assoc); 32710Sstevel@tonic-gate /* 32720Sstevel@tonic-gate * Most AMD parts have a sectored cache. Multiple cache lines are 32730Sstevel@tonic-gate * associated with each tag. A sector consists of all cache lines 32740Sstevel@tonic-gate * associated with a tag. For example, the AMD K6-III has a sector 32750Sstevel@tonic-gate * size of 2 cache lines per tag. 32760Sstevel@tonic-gate */ 32770Sstevel@tonic-gate if (lines_per_tag != 0) 32780Sstevel@tonic-gate add_cache_prop(devi, label, "lines-per-tag", lines_per_tag); 32790Sstevel@tonic-gate add_cache_prop(devi, label, line_str, line_size); 32800Sstevel@tonic-gate add_cache_prop(devi, label, size_str, size * 1024); 32810Sstevel@tonic-gate } 32820Sstevel@tonic-gate 32830Sstevel@tonic-gate static void 32840Sstevel@tonic-gate add_amd_l2_assoc(dev_info_t *devi, const char *label, uint_t assoc) 32850Sstevel@tonic-gate { 32860Sstevel@tonic-gate switch (assoc) { 32870Sstevel@tonic-gate case 0: /* off */ 32880Sstevel@tonic-gate break; 32890Sstevel@tonic-gate case 1: 32900Sstevel@tonic-gate case 2: 32910Sstevel@tonic-gate case 4: 32920Sstevel@tonic-gate add_cache_prop(devi, label, assoc_str, assoc); 32930Sstevel@tonic-gate break; 32940Sstevel@tonic-gate case 6: 32950Sstevel@tonic-gate add_cache_prop(devi, label, assoc_str, 8); 32960Sstevel@tonic-gate break; 32970Sstevel@tonic-gate case 8: 32980Sstevel@tonic-gate add_cache_prop(devi, label, assoc_str, 16); 32990Sstevel@tonic-gate break; 33000Sstevel@tonic-gate case 0xf: 33010Sstevel@tonic-gate add_cache_prop(devi, label, fully_assoc, 1); 33020Sstevel@tonic-gate break; 33030Sstevel@tonic-gate default: /* reserved; ignore */ 33040Sstevel@tonic-gate break; 33050Sstevel@tonic-gate } 33060Sstevel@tonic-gate } 33070Sstevel@tonic-gate 33080Sstevel@tonic-gate static void 33090Sstevel@tonic-gate add_amd_l2_tlb(dev_info_t *devi, const char *label, uint_t assoc, uint_t size) 33100Sstevel@tonic-gate { 33110Sstevel@tonic-gate if (size == 0 || assoc == 0) 33120Sstevel@tonic-gate return; 33130Sstevel@tonic-gate add_amd_l2_assoc(devi, label, assoc); 33140Sstevel@tonic-gate add_cache_prop(devi, label, size_str, size); 33150Sstevel@tonic-gate } 33160Sstevel@tonic-gate 33170Sstevel@tonic-gate static void 33180Sstevel@tonic-gate add_amd_l2_cache(dev_info_t *devi, const char *label, 33190Sstevel@tonic-gate uint_t size, uint_t assoc, uint_t lines_per_tag, uint_t line_size) 33200Sstevel@tonic-gate { 33210Sstevel@tonic-gate if (size == 0 || assoc == 0 || line_size == 0) 33220Sstevel@tonic-gate return; 33230Sstevel@tonic-gate add_amd_l2_assoc(devi, label, assoc); 33240Sstevel@tonic-gate if (lines_per_tag != 0) 33250Sstevel@tonic-gate add_cache_prop(devi, label, "lines-per-tag", lines_per_tag); 33260Sstevel@tonic-gate add_cache_prop(devi, label, line_str, line_size); 33270Sstevel@tonic-gate add_cache_prop(devi, label, size_str, size * 1024); 33280Sstevel@tonic-gate } 33290Sstevel@tonic-gate 33300Sstevel@tonic-gate static void 33310Sstevel@tonic-gate amd_cache_info(struct cpuid_info *cpi, dev_info_t *devi) 33320Sstevel@tonic-gate { 33331228Sandrei struct cpuid_regs *cp; 33340Sstevel@tonic-gate 33350Sstevel@tonic-gate if (cpi->cpi_xmaxeax < 0x80000005) 33360Sstevel@tonic-gate return; 33370Sstevel@tonic-gate cp = &cpi->cpi_extd[5]; 33380Sstevel@tonic-gate 33390Sstevel@tonic-gate /* 33400Sstevel@tonic-gate * 4M/2M L1 TLB configuration 33410Sstevel@tonic-gate * 33420Sstevel@tonic-gate * We report the size for 2M pages because AMD uses two 33430Sstevel@tonic-gate * TLB entries for one 4M page. 33440Sstevel@tonic-gate */ 33450Sstevel@tonic-gate add_amd_tlb(devi, "dtlb-2M", 33460Sstevel@tonic-gate BITX(cp->cp_eax, 31, 24), BITX(cp->cp_eax, 23, 16)); 33470Sstevel@tonic-gate add_amd_tlb(devi, "itlb-2M", 33480Sstevel@tonic-gate BITX(cp->cp_eax, 15, 8), BITX(cp->cp_eax, 7, 0)); 33490Sstevel@tonic-gate 33500Sstevel@tonic-gate /* 33510Sstevel@tonic-gate * 4K L1 TLB configuration 33520Sstevel@tonic-gate */ 33530Sstevel@tonic-gate 33540Sstevel@tonic-gate switch (cpi->cpi_vendor) { 33550Sstevel@tonic-gate uint_t nentries; 33560Sstevel@tonic-gate case X86_VENDOR_TM: 33570Sstevel@tonic-gate if (cpi->cpi_family >= 5) { 33580Sstevel@tonic-gate /* 33590Sstevel@tonic-gate * Crusoe processors have 256 TLB entries, but 33600Sstevel@tonic-gate * cpuid data format constrains them to only 33610Sstevel@tonic-gate * reporting 255 of them. 33620Sstevel@tonic-gate */ 33630Sstevel@tonic-gate if ((nentries = BITX(cp->cp_ebx, 23, 16)) == 255) 33640Sstevel@tonic-gate nentries = 256; 33650Sstevel@tonic-gate /* 33660Sstevel@tonic-gate * Crusoe processors also have a unified TLB 33670Sstevel@tonic-gate */ 33680Sstevel@tonic-gate add_amd_tlb(devi, "tlb-4K", BITX(cp->cp_ebx, 31, 24), 33690Sstevel@tonic-gate nentries); 33700Sstevel@tonic-gate break; 33710Sstevel@tonic-gate } 33720Sstevel@tonic-gate /*FALLTHROUGH*/ 33730Sstevel@tonic-gate default: 33740Sstevel@tonic-gate add_amd_tlb(devi, itlb4k_str, 33750Sstevel@tonic-gate BITX(cp->cp_ebx, 31, 24), BITX(cp->cp_ebx, 23, 16)); 33760Sstevel@tonic-gate add_amd_tlb(devi, dtlb4k_str, 33770Sstevel@tonic-gate BITX(cp->cp_ebx, 15, 8), BITX(cp->cp_ebx, 7, 0)); 33780Sstevel@tonic-gate break; 33790Sstevel@tonic-gate } 33800Sstevel@tonic-gate 33810Sstevel@tonic-gate /* 33820Sstevel@tonic-gate * data L1 cache configuration 33830Sstevel@tonic-gate */ 33840Sstevel@tonic-gate 33850Sstevel@tonic-gate add_amd_cache(devi, l1_dcache_str, 33860Sstevel@tonic-gate BITX(cp->cp_ecx, 31, 24), BITX(cp->cp_ecx, 23, 16), 33870Sstevel@tonic-gate BITX(cp->cp_ecx, 15, 8), BITX(cp->cp_ecx, 7, 0)); 33880Sstevel@tonic-gate 33890Sstevel@tonic-gate /* 33900Sstevel@tonic-gate * code L1 cache configuration 33910Sstevel@tonic-gate */ 33920Sstevel@tonic-gate 33930Sstevel@tonic-gate add_amd_cache(devi, l1_icache_str, 33940Sstevel@tonic-gate BITX(cp->cp_edx, 31, 24), BITX(cp->cp_edx, 23, 16), 33950Sstevel@tonic-gate BITX(cp->cp_edx, 15, 8), BITX(cp->cp_edx, 7, 0)); 33960Sstevel@tonic-gate 33970Sstevel@tonic-gate if (cpi->cpi_xmaxeax < 0x80000006) 33980Sstevel@tonic-gate return; 33990Sstevel@tonic-gate cp = &cpi->cpi_extd[6]; 34000Sstevel@tonic-gate 34010Sstevel@tonic-gate /* Check for a unified L2 TLB for large pages */ 34020Sstevel@tonic-gate 34030Sstevel@tonic-gate if (BITX(cp->cp_eax, 31, 16) == 0) 34040Sstevel@tonic-gate add_amd_l2_tlb(devi, "l2-tlb-2M", 34050Sstevel@tonic-gate BITX(cp->cp_eax, 15, 12), BITX(cp->cp_eax, 11, 0)); 34060Sstevel@tonic-gate else { 34070Sstevel@tonic-gate add_amd_l2_tlb(devi, "l2-dtlb-2M", 34080Sstevel@tonic-gate BITX(cp->cp_eax, 31, 28), BITX(cp->cp_eax, 27, 16)); 34090Sstevel@tonic-gate add_amd_l2_tlb(devi, "l2-itlb-2M", 34100Sstevel@tonic-gate BITX(cp->cp_eax, 15, 12), BITX(cp->cp_eax, 11, 0)); 34110Sstevel@tonic-gate } 34120Sstevel@tonic-gate 34130Sstevel@tonic-gate /* Check for a unified L2 TLB for 4K pages */ 34140Sstevel@tonic-gate 34150Sstevel@tonic-gate if (BITX(cp->cp_ebx, 31, 16) == 0) { 34160Sstevel@tonic-gate add_amd_l2_tlb(devi, "l2-tlb-4K", 34170Sstevel@tonic-gate BITX(cp->cp_eax, 15, 12), BITX(cp->cp_eax, 11, 0)); 34180Sstevel@tonic-gate } else { 34190Sstevel@tonic-gate add_amd_l2_tlb(devi, "l2-dtlb-4K", 34200Sstevel@tonic-gate BITX(cp->cp_eax, 31, 28), BITX(cp->cp_eax, 27, 16)); 34210Sstevel@tonic-gate add_amd_l2_tlb(devi, "l2-itlb-4K", 34220Sstevel@tonic-gate BITX(cp->cp_eax, 15, 12), BITX(cp->cp_eax, 11, 0)); 34230Sstevel@tonic-gate } 34240Sstevel@tonic-gate 34250Sstevel@tonic-gate add_amd_l2_cache(devi, l2_cache_str, 34260Sstevel@tonic-gate BITX(cp->cp_ecx, 31, 16), BITX(cp->cp_ecx, 15, 12), 34270Sstevel@tonic-gate BITX(cp->cp_ecx, 11, 8), BITX(cp->cp_ecx, 7, 0)); 34280Sstevel@tonic-gate } 34290Sstevel@tonic-gate 34300Sstevel@tonic-gate /* 34310Sstevel@tonic-gate * There are two basic ways that the x86 world describes it cache 34320Sstevel@tonic-gate * and tlb architecture - Intel's way and AMD's way. 34330Sstevel@tonic-gate * 34340Sstevel@tonic-gate * Return which flavor of cache architecture we should use 34350Sstevel@tonic-gate */ 34360Sstevel@tonic-gate static int 34370Sstevel@tonic-gate x86_which_cacheinfo(struct cpuid_info *cpi) 34380Sstevel@tonic-gate { 34390Sstevel@tonic-gate switch (cpi->cpi_vendor) { 34400Sstevel@tonic-gate case X86_VENDOR_Intel: 34410Sstevel@tonic-gate if (cpi->cpi_maxeax >= 2) 34420Sstevel@tonic-gate return (X86_VENDOR_Intel); 34430Sstevel@tonic-gate break; 34440Sstevel@tonic-gate case X86_VENDOR_AMD: 34450Sstevel@tonic-gate /* 34460Sstevel@tonic-gate * The K5 model 1 was the first part from AMD that reported 34470Sstevel@tonic-gate * cache sizes via extended cpuid functions. 34480Sstevel@tonic-gate */ 34490Sstevel@tonic-gate if (cpi->cpi_family > 5 || 34500Sstevel@tonic-gate (cpi->cpi_family == 5 && cpi->cpi_model >= 1)) 34510Sstevel@tonic-gate return (X86_VENDOR_AMD); 34520Sstevel@tonic-gate break; 34530Sstevel@tonic-gate case X86_VENDOR_TM: 34540Sstevel@tonic-gate if (cpi->cpi_family >= 5) 34550Sstevel@tonic-gate return (X86_VENDOR_AMD); 34560Sstevel@tonic-gate /*FALLTHROUGH*/ 34570Sstevel@tonic-gate default: 34580Sstevel@tonic-gate /* 34590Sstevel@tonic-gate * If they have extended CPU data for 0x80000005 34600Sstevel@tonic-gate * then we assume they have AMD-format cache 34610Sstevel@tonic-gate * information. 34620Sstevel@tonic-gate * 34630Sstevel@tonic-gate * If not, and the vendor happens to be Cyrix, 34640Sstevel@tonic-gate * then try our-Cyrix specific handler. 34650Sstevel@tonic-gate * 34660Sstevel@tonic-gate * If we're not Cyrix, then assume we're using Intel's 34670Sstevel@tonic-gate * table-driven format instead. 34680Sstevel@tonic-gate */ 34690Sstevel@tonic-gate if (cpi->cpi_xmaxeax >= 0x80000005) 34700Sstevel@tonic-gate return (X86_VENDOR_AMD); 34710Sstevel@tonic-gate else if (cpi->cpi_vendor == X86_VENDOR_Cyrix) 34720Sstevel@tonic-gate return (X86_VENDOR_Cyrix); 34730Sstevel@tonic-gate else if (cpi->cpi_maxeax >= 2) 34740Sstevel@tonic-gate return (X86_VENDOR_Intel); 34750Sstevel@tonic-gate break; 34760Sstevel@tonic-gate } 34770Sstevel@tonic-gate return (-1); 34780Sstevel@tonic-gate } 34790Sstevel@tonic-gate 34800Sstevel@tonic-gate void 3481*9652SMichael.Corcoran@Sun.COM cpuid_set_cpu_properties(void *dip, processorid_t cpu_id, 3482*9652SMichael.Corcoran@Sun.COM struct cpuid_info *cpi) 34830Sstevel@tonic-gate { 34840Sstevel@tonic-gate dev_info_t *cpu_devi; 34850Sstevel@tonic-gate int create; 34860Sstevel@tonic-gate 3487*9652SMichael.Corcoran@Sun.COM cpu_devi = (dev_info_t *)dip; 34880Sstevel@tonic-gate 34890Sstevel@tonic-gate /* device_type */ 34900Sstevel@tonic-gate (void) ndi_prop_update_string(DDI_DEV_T_NONE, cpu_devi, 34910Sstevel@tonic-gate "device_type", "cpu"); 34920Sstevel@tonic-gate 34930Sstevel@tonic-gate /* reg */ 34940Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 34950Sstevel@tonic-gate "reg", cpu_id); 34960Sstevel@tonic-gate 34970Sstevel@tonic-gate /* cpu-mhz, and clock-frequency */ 34980Sstevel@tonic-gate if (cpu_freq > 0) { 34990Sstevel@tonic-gate long long mul; 35000Sstevel@tonic-gate 35010Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 35020Sstevel@tonic-gate "cpu-mhz", cpu_freq); 35030Sstevel@tonic-gate if ((mul = cpu_freq * 1000000LL) <= INT_MAX) 35040Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 35050Sstevel@tonic-gate "clock-frequency", (int)mul); 35060Sstevel@tonic-gate } 35070Sstevel@tonic-gate 35080Sstevel@tonic-gate if ((x86_feature & X86_CPUID) == 0) { 35090Sstevel@tonic-gate return; 35100Sstevel@tonic-gate } 35110Sstevel@tonic-gate 35120Sstevel@tonic-gate /* vendor-id */ 35130Sstevel@tonic-gate (void) ndi_prop_update_string(DDI_DEV_T_NONE, cpu_devi, 35144481Sbholler "vendor-id", cpi->cpi_vendorstr); 35150Sstevel@tonic-gate 35160Sstevel@tonic-gate if (cpi->cpi_maxeax == 0) { 35170Sstevel@tonic-gate return; 35180Sstevel@tonic-gate } 35190Sstevel@tonic-gate 35200Sstevel@tonic-gate /* 35210Sstevel@tonic-gate * family, model, and step 35220Sstevel@tonic-gate */ 35230Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 35244481Sbholler "family", CPI_FAMILY(cpi)); 35250Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 35264481Sbholler "cpu-model", CPI_MODEL(cpi)); 35270Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 35284481Sbholler "stepping-id", CPI_STEP(cpi)); 35290Sstevel@tonic-gate 35300Sstevel@tonic-gate /* type */ 35310Sstevel@tonic-gate switch (cpi->cpi_vendor) { 35320Sstevel@tonic-gate case X86_VENDOR_Intel: 35330Sstevel@tonic-gate create = 1; 35340Sstevel@tonic-gate break; 35350Sstevel@tonic-gate default: 35360Sstevel@tonic-gate create = 0; 35370Sstevel@tonic-gate break; 35380Sstevel@tonic-gate } 35390Sstevel@tonic-gate if (create) 35400Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 35414481Sbholler "type", CPI_TYPE(cpi)); 35420Sstevel@tonic-gate 35430Sstevel@tonic-gate /* ext-family */ 35440Sstevel@tonic-gate switch (cpi->cpi_vendor) { 35450Sstevel@tonic-gate case X86_VENDOR_Intel: 35460Sstevel@tonic-gate case X86_VENDOR_AMD: 35470Sstevel@tonic-gate create = cpi->cpi_family >= 0xf; 35480Sstevel@tonic-gate break; 35490Sstevel@tonic-gate default: 35500Sstevel@tonic-gate create = 0; 35510Sstevel@tonic-gate break; 35520Sstevel@tonic-gate } 35530Sstevel@tonic-gate if (create) 35540Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 35550Sstevel@tonic-gate "ext-family", CPI_FAMILY_XTD(cpi)); 35560Sstevel@tonic-gate 35570Sstevel@tonic-gate /* ext-model */ 35580Sstevel@tonic-gate switch (cpi->cpi_vendor) { 35590Sstevel@tonic-gate case X86_VENDOR_Intel: 35606317Skk208521 create = IS_EXTENDED_MODEL_INTEL(cpi); 35612001Sdmick break; 35620Sstevel@tonic-gate case X86_VENDOR_AMD: 35631582Skchow create = CPI_FAMILY(cpi) == 0xf; 35640Sstevel@tonic-gate break; 35650Sstevel@tonic-gate default: 35660Sstevel@tonic-gate create = 0; 35670Sstevel@tonic-gate break; 35680Sstevel@tonic-gate } 35690Sstevel@tonic-gate if (create) 35700Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 35714481Sbholler "ext-model", CPI_MODEL_XTD(cpi)); 35720Sstevel@tonic-gate 35730Sstevel@tonic-gate /* generation */ 35740Sstevel@tonic-gate switch (cpi->cpi_vendor) { 35750Sstevel@tonic-gate case X86_VENDOR_AMD: 35760Sstevel@tonic-gate /* 35770Sstevel@tonic-gate * AMD K5 model 1 was the first part to support this 35780Sstevel@tonic-gate */ 35790Sstevel@tonic-gate create = cpi->cpi_xmaxeax >= 0x80000001; 35800Sstevel@tonic-gate break; 35810Sstevel@tonic-gate default: 35820Sstevel@tonic-gate create = 0; 35830Sstevel@tonic-gate break; 35840Sstevel@tonic-gate } 35850Sstevel@tonic-gate if (create) 35860Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 35870Sstevel@tonic-gate "generation", BITX((cpi)->cpi_extd[1].cp_eax, 11, 8)); 35880Sstevel@tonic-gate 35890Sstevel@tonic-gate /* brand-id */ 35900Sstevel@tonic-gate switch (cpi->cpi_vendor) { 35910Sstevel@tonic-gate case X86_VENDOR_Intel: 35920Sstevel@tonic-gate /* 35930Sstevel@tonic-gate * brand id first appeared on Pentium III Xeon model 8, 35940Sstevel@tonic-gate * and Celeron model 8 processors and Opteron 35950Sstevel@tonic-gate */ 35960Sstevel@tonic-gate create = cpi->cpi_family > 6 || 35970Sstevel@tonic-gate (cpi->cpi_family == 6 && cpi->cpi_model >= 8); 35980Sstevel@tonic-gate break; 35990Sstevel@tonic-gate case X86_VENDOR_AMD: 36000Sstevel@tonic-gate create = cpi->cpi_family >= 0xf; 36010Sstevel@tonic-gate break; 36020Sstevel@tonic-gate default: 36030Sstevel@tonic-gate create = 0; 36040Sstevel@tonic-gate break; 36050Sstevel@tonic-gate } 36060Sstevel@tonic-gate if (create && cpi->cpi_brandid != 0) { 36070Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 36080Sstevel@tonic-gate "brand-id", cpi->cpi_brandid); 36090Sstevel@tonic-gate } 36100Sstevel@tonic-gate 36110Sstevel@tonic-gate /* chunks, and apic-id */ 36120Sstevel@tonic-gate switch (cpi->cpi_vendor) { 36130Sstevel@tonic-gate /* 36140Sstevel@tonic-gate * first available on Pentium IV and Opteron (K8) 36150Sstevel@tonic-gate */ 36161975Sdmick case X86_VENDOR_Intel: 36171975Sdmick create = IS_NEW_F6(cpi) || cpi->cpi_family >= 0xf; 36181975Sdmick break; 36191975Sdmick case X86_VENDOR_AMD: 36200Sstevel@tonic-gate create = cpi->cpi_family >= 0xf; 36210Sstevel@tonic-gate break; 36220Sstevel@tonic-gate default: 36230Sstevel@tonic-gate create = 0; 36240Sstevel@tonic-gate break; 36250Sstevel@tonic-gate } 36260Sstevel@tonic-gate if (create) { 36270Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 36284481Sbholler "chunks", CPI_CHUNKS(cpi)); 36290Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 36307282Smishra "apic-id", cpi->cpi_apicid); 36311414Scindi if (cpi->cpi_chipid >= 0) { 36320Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 36330Sstevel@tonic-gate "chip#", cpi->cpi_chipid); 36341414Scindi (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 36351414Scindi "clog#", cpi->cpi_clogid); 36361414Scindi } 36370Sstevel@tonic-gate } 36380Sstevel@tonic-gate 36390Sstevel@tonic-gate /* cpuid-features */ 36400Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 36410Sstevel@tonic-gate "cpuid-features", CPI_FEATURES_EDX(cpi)); 36420Sstevel@tonic-gate 36430Sstevel@tonic-gate 36440Sstevel@tonic-gate /* cpuid-features-ecx */ 36450Sstevel@tonic-gate switch (cpi->cpi_vendor) { 36460Sstevel@tonic-gate case X86_VENDOR_Intel: 36471975Sdmick create = IS_NEW_F6(cpi) || cpi->cpi_family >= 0xf; 36480Sstevel@tonic-gate break; 36490Sstevel@tonic-gate default: 36500Sstevel@tonic-gate create = 0; 36510Sstevel@tonic-gate break; 36520Sstevel@tonic-gate } 36530Sstevel@tonic-gate if (create) 36540Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 36550Sstevel@tonic-gate "cpuid-features-ecx", CPI_FEATURES_ECX(cpi)); 36560Sstevel@tonic-gate 36570Sstevel@tonic-gate /* ext-cpuid-features */ 36580Sstevel@tonic-gate switch (cpi->cpi_vendor) { 36591975Sdmick case X86_VENDOR_Intel: 36600Sstevel@tonic-gate case X86_VENDOR_AMD: 36610Sstevel@tonic-gate case X86_VENDOR_Cyrix: 36620Sstevel@tonic-gate case X86_VENDOR_TM: 36630Sstevel@tonic-gate case X86_VENDOR_Centaur: 36640Sstevel@tonic-gate create = cpi->cpi_xmaxeax >= 0x80000001; 36650Sstevel@tonic-gate break; 36660Sstevel@tonic-gate default: 36670Sstevel@tonic-gate create = 0; 36680Sstevel@tonic-gate break; 36690Sstevel@tonic-gate } 36701975Sdmick if (create) { 36710Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 36724481Sbholler "ext-cpuid-features", CPI_FEATURES_XTD_EDX(cpi)); 36731975Sdmick (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 36744481Sbholler "ext-cpuid-features-ecx", CPI_FEATURES_XTD_ECX(cpi)); 36751975Sdmick } 36760Sstevel@tonic-gate 36770Sstevel@tonic-gate /* 36780Sstevel@tonic-gate * Brand String first appeared in Intel Pentium IV, AMD K5 36790Sstevel@tonic-gate * model 1, and Cyrix GXm. On earlier models we try and 36800Sstevel@tonic-gate * simulate something similar .. so this string should always 36810Sstevel@tonic-gate * same -something- about the processor, however lame. 36820Sstevel@tonic-gate */ 36830Sstevel@tonic-gate (void) ndi_prop_update_string(DDI_DEV_T_NONE, cpu_devi, 36840Sstevel@tonic-gate "brand-string", cpi->cpi_brandstr); 36850Sstevel@tonic-gate 36860Sstevel@tonic-gate /* 36870Sstevel@tonic-gate * Finally, cache and tlb information 36880Sstevel@tonic-gate */ 36890Sstevel@tonic-gate switch (x86_which_cacheinfo(cpi)) { 36900Sstevel@tonic-gate case X86_VENDOR_Intel: 36910Sstevel@tonic-gate intel_walk_cacheinfo(cpi, cpu_devi, add_cacheent_props); 36920Sstevel@tonic-gate break; 36930Sstevel@tonic-gate case X86_VENDOR_Cyrix: 36940Sstevel@tonic-gate cyrix_walk_cacheinfo(cpi, cpu_devi, add_cacheent_props); 36950Sstevel@tonic-gate break; 36960Sstevel@tonic-gate case X86_VENDOR_AMD: 36970Sstevel@tonic-gate amd_cache_info(cpi, cpu_devi); 36980Sstevel@tonic-gate break; 36990Sstevel@tonic-gate default: 37000Sstevel@tonic-gate break; 37010Sstevel@tonic-gate } 37020Sstevel@tonic-gate } 37030Sstevel@tonic-gate 37040Sstevel@tonic-gate struct l2info { 37050Sstevel@tonic-gate int *l2i_csz; 37060Sstevel@tonic-gate int *l2i_lsz; 37070Sstevel@tonic-gate int *l2i_assoc; 37080Sstevel@tonic-gate int l2i_ret; 37090Sstevel@tonic-gate }; 37100Sstevel@tonic-gate 37110Sstevel@tonic-gate /* 37120Sstevel@tonic-gate * A cacheinfo walker that fetches the size, line-size and associativity 37130Sstevel@tonic-gate * of the L2 cache 37140Sstevel@tonic-gate */ 37150Sstevel@tonic-gate static int 37160Sstevel@tonic-gate intel_l2cinfo(void *arg, const struct cachetab *ct) 37170Sstevel@tonic-gate { 37180Sstevel@tonic-gate struct l2info *l2i = arg; 37190Sstevel@tonic-gate int *ip; 37200Sstevel@tonic-gate 37210Sstevel@tonic-gate if (ct->ct_label != l2_cache_str && 37220Sstevel@tonic-gate ct->ct_label != sl2_cache_str) 37230Sstevel@tonic-gate return (0); /* not an L2 -- keep walking */ 37240Sstevel@tonic-gate 37250Sstevel@tonic-gate if ((ip = l2i->l2i_csz) != NULL) 37260Sstevel@tonic-gate *ip = ct->ct_size; 37270Sstevel@tonic-gate if ((ip = l2i->l2i_lsz) != NULL) 37280Sstevel@tonic-gate *ip = ct->ct_line_size; 37290Sstevel@tonic-gate if ((ip = l2i->l2i_assoc) != NULL) 37300Sstevel@tonic-gate *ip = ct->ct_assoc; 37310Sstevel@tonic-gate l2i->l2i_ret = ct->ct_size; 37320Sstevel@tonic-gate return (1); /* was an L2 -- terminate walk */ 37330Sstevel@tonic-gate } 37340Sstevel@tonic-gate 37355070Skchow /* 37365070Skchow * AMD L2/L3 Cache and TLB Associativity Field Definition: 37375070Skchow * 37385070Skchow * Unlike the associativity for the L1 cache and tlb where the 8 bit 37395070Skchow * value is the associativity, the associativity for the L2 cache and 37405070Skchow * tlb is encoded in the following table. The 4 bit L2 value serves as 37415070Skchow * an index into the amd_afd[] array to determine the associativity. 37425070Skchow * -1 is undefined. 0 is fully associative. 37435070Skchow */ 37445070Skchow 37455070Skchow static int amd_afd[] = 37465070Skchow {-1, 1, 2, -1, 4, -1, 8, -1, 16, -1, 32, 48, 64, 96, 128, 0}; 37475070Skchow 37480Sstevel@tonic-gate static void 37490Sstevel@tonic-gate amd_l2cacheinfo(struct cpuid_info *cpi, struct l2info *l2i) 37500Sstevel@tonic-gate { 37511228Sandrei struct cpuid_regs *cp; 37520Sstevel@tonic-gate uint_t size, assoc; 37535070Skchow int i; 37540Sstevel@tonic-gate int *ip; 37550Sstevel@tonic-gate 37560Sstevel@tonic-gate if (cpi->cpi_xmaxeax < 0x80000006) 37570Sstevel@tonic-gate return; 37580Sstevel@tonic-gate cp = &cpi->cpi_extd[6]; 37590Sstevel@tonic-gate 37605070Skchow if ((i = BITX(cp->cp_ecx, 15, 12)) != 0 && 37610Sstevel@tonic-gate (size = BITX(cp->cp_ecx, 31, 16)) != 0) { 37620Sstevel@tonic-gate uint_t cachesz = size * 1024; 37635070Skchow assoc = amd_afd[i]; 37645070Skchow 37655070Skchow ASSERT(assoc != -1); 37660Sstevel@tonic-gate 37670Sstevel@tonic-gate if ((ip = l2i->l2i_csz) != NULL) 37680Sstevel@tonic-gate *ip = cachesz; 37690Sstevel@tonic-gate if ((ip = l2i->l2i_lsz) != NULL) 37700Sstevel@tonic-gate *ip = BITX(cp->cp_ecx, 7, 0); 37710Sstevel@tonic-gate if ((ip = l2i->l2i_assoc) != NULL) 37720Sstevel@tonic-gate *ip = assoc; 37730Sstevel@tonic-gate l2i->l2i_ret = cachesz; 37740Sstevel@tonic-gate } 37750Sstevel@tonic-gate } 37760Sstevel@tonic-gate 37770Sstevel@tonic-gate int 37780Sstevel@tonic-gate getl2cacheinfo(cpu_t *cpu, int *csz, int *lsz, int *assoc) 37790Sstevel@tonic-gate { 37800Sstevel@tonic-gate struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 37810Sstevel@tonic-gate struct l2info __l2info, *l2i = &__l2info; 37820Sstevel@tonic-gate 37830Sstevel@tonic-gate l2i->l2i_csz = csz; 37840Sstevel@tonic-gate l2i->l2i_lsz = lsz; 37850Sstevel@tonic-gate l2i->l2i_assoc = assoc; 37860Sstevel@tonic-gate l2i->l2i_ret = -1; 37870Sstevel@tonic-gate 37880Sstevel@tonic-gate switch (x86_which_cacheinfo(cpi)) { 37890Sstevel@tonic-gate case X86_VENDOR_Intel: 37900Sstevel@tonic-gate intel_walk_cacheinfo(cpi, l2i, intel_l2cinfo); 37910Sstevel@tonic-gate break; 37920Sstevel@tonic-gate case X86_VENDOR_Cyrix: 37930Sstevel@tonic-gate cyrix_walk_cacheinfo(cpi, l2i, intel_l2cinfo); 37940Sstevel@tonic-gate break; 37950Sstevel@tonic-gate case X86_VENDOR_AMD: 37960Sstevel@tonic-gate amd_l2cacheinfo(cpi, l2i); 37970Sstevel@tonic-gate break; 37980Sstevel@tonic-gate default: 37990Sstevel@tonic-gate break; 38000Sstevel@tonic-gate } 38010Sstevel@tonic-gate return (l2i->l2i_ret); 38020Sstevel@tonic-gate } 38034481Sbholler 38045084Sjohnlev #if !defined(__xpv) 38055084Sjohnlev 38065045Sbholler uint32_t * 38075045Sbholler cpuid_mwait_alloc(cpu_t *cpu) 38085045Sbholler { 38095045Sbholler uint32_t *ret; 38105045Sbholler size_t mwait_size; 38115045Sbholler 38125045Sbholler ASSERT(cpuid_checkpass(cpu, 2)); 38135045Sbholler 38145045Sbholler mwait_size = cpu->cpu_m.mcpu_cpi->cpi_mwait.mon_max; 38155045Sbholler if (mwait_size == 0) 38165045Sbholler return (NULL); 38175045Sbholler 38185045Sbholler /* 38195045Sbholler * kmem_alloc() returns cache line size aligned data for mwait_size 38205045Sbholler * allocations. mwait_size is currently cache line sized. Neither 38215045Sbholler * of these implementation details are guarantied to be true in the 38225045Sbholler * future. 38235045Sbholler * 38245045Sbholler * First try allocating mwait_size as kmem_alloc() currently returns 38255045Sbholler * correctly aligned memory. If kmem_alloc() does not return 38265045Sbholler * mwait_size aligned memory, then use mwait_size ROUNDUP. 38275045Sbholler * 38285045Sbholler * Set cpi_mwait.buf_actual and cpi_mwait.size_actual in case we 38295045Sbholler * decide to free this memory. 38305045Sbholler */ 38315045Sbholler ret = kmem_zalloc(mwait_size, KM_SLEEP); 38325045Sbholler if (ret == (uint32_t *)P2ROUNDUP((uintptr_t)ret, mwait_size)) { 38335045Sbholler cpu->cpu_m.mcpu_cpi->cpi_mwait.buf_actual = ret; 38345045Sbholler cpu->cpu_m.mcpu_cpi->cpi_mwait.size_actual = mwait_size; 38355045Sbholler *ret = MWAIT_RUNNING; 38365045Sbholler return (ret); 38375045Sbholler } else { 38385045Sbholler kmem_free(ret, mwait_size); 38395045Sbholler ret = kmem_zalloc(mwait_size * 2, KM_SLEEP); 38405045Sbholler cpu->cpu_m.mcpu_cpi->cpi_mwait.buf_actual = ret; 38415045Sbholler cpu->cpu_m.mcpu_cpi->cpi_mwait.size_actual = mwait_size * 2; 38425045Sbholler ret = (uint32_t *)P2ROUNDUP((uintptr_t)ret, mwait_size); 38435045Sbholler *ret = MWAIT_RUNNING; 38445045Sbholler return (ret); 38455045Sbholler } 38465045Sbholler } 38475045Sbholler 38485045Sbholler void 38495045Sbholler cpuid_mwait_free(cpu_t *cpu) 38504481Sbholler { 38514481Sbholler ASSERT(cpuid_checkpass(cpu, 2)); 38525045Sbholler 38535045Sbholler if (cpu->cpu_m.mcpu_cpi->cpi_mwait.buf_actual != NULL && 38545045Sbholler cpu->cpu_m.mcpu_cpi->cpi_mwait.size_actual > 0) { 38555045Sbholler kmem_free(cpu->cpu_m.mcpu_cpi->cpi_mwait.buf_actual, 38565045Sbholler cpu->cpu_m.mcpu_cpi->cpi_mwait.size_actual); 38575045Sbholler } 38585045Sbholler 38595045Sbholler cpu->cpu_m.mcpu_cpi->cpi_mwait.buf_actual = NULL; 38605045Sbholler cpu->cpu_m.mcpu_cpi->cpi_mwait.size_actual = 0; 38614481Sbholler } 38625084Sjohnlev 38635322Ssudheer void 38645322Ssudheer patch_tsc_read(int flag) 38655322Ssudheer { 38665322Ssudheer size_t cnt; 38677532SSean.Ye@Sun.COM 38685322Ssudheer switch (flag) { 38695322Ssudheer case X86_NO_TSC: 38705322Ssudheer cnt = &_no_rdtsc_end - &_no_rdtsc_start; 38715338Ssudheer (void) memcpy((void *)tsc_read, (void *)&_no_rdtsc_start, cnt); 38725322Ssudheer break; 38735322Ssudheer case X86_HAVE_TSCP: 38745322Ssudheer cnt = &_tscp_end - &_tscp_start; 38755338Ssudheer (void) memcpy((void *)tsc_read, (void *)&_tscp_start, cnt); 38765322Ssudheer break; 38775322Ssudheer case X86_TSC_MFENCE: 38785322Ssudheer cnt = &_tsc_mfence_end - &_tsc_mfence_start; 38795338Ssudheer (void) memcpy((void *)tsc_read, 38805338Ssudheer (void *)&_tsc_mfence_start, cnt); 38815322Ssudheer break; 38826642Ssudheer case X86_TSC_LFENCE: 38836642Ssudheer cnt = &_tsc_lfence_end - &_tsc_lfence_start; 38846642Ssudheer (void) memcpy((void *)tsc_read, 38856642Ssudheer (void *)&_tsc_lfence_start, cnt); 38866642Ssudheer break; 38875322Ssudheer default: 38885322Ssudheer break; 38895322Ssudheer } 38905322Ssudheer } 38915322Ssudheer 38928906SEric.Saxe@Sun.COM int 38938906SEric.Saxe@Sun.COM cpuid_deep_cstates_supported(void) 38948906SEric.Saxe@Sun.COM { 38958906SEric.Saxe@Sun.COM struct cpuid_info *cpi; 38968906SEric.Saxe@Sun.COM struct cpuid_regs regs; 38978906SEric.Saxe@Sun.COM 38988906SEric.Saxe@Sun.COM ASSERT(cpuid_checkpass(CPU, 1)); 38998906SEric.Saxe@Sun.COM 39008906SEric.Saxe@Sun.COM cpi = CPU->cpu_m.mcpu_cpi; 39018906SEric.Saxe@Sun.COM 39028906SEric.Saxe@Sun.COM if (!(x86_feature & X86_CPUID)) 39038906SEric.Saxe@Sun.COM return (0); 39048906SEric.Saxe@Sun.COM 39058906SEric.Saxe@Sun.COM switch (cpi->cpi_vendor) { 39068906SEric.Saxe@Sun.COM case X86_VENDOR_Intel: 39078906SEric.Saxe@Sun.COM if (cpi->cpi_xmaxeax < 0x80000007) 39088906SEric.Saxe@Sun.COM return (0); 39098906SEric.Saxe@Sun.COM 39108906SEric.Saxe@Sun.COM /* 39118906SEric.Saxe@Sun.COM * TSC run at a constant rate in all ACPI C-states? 39128906SEric.Saxe@Sun.COM */ 39138906SEric.Saxe@Sun.COM regs.cp_eax = 0x80000007; 39148906SEric.Saxe@Sun.COM (void) __cpuid_insn(®s); 39158906SEric.Saxe@Sun.COM return (regs.cp_edx & CPUID_TSC_CSTATE_INVARIANCE); 39168906SEric.Saxe@Sun.COM 39178906SEric.Saxe@Sun.COM default: 39188906SEric.Saxe@Sun.COM return (0); 39198906SEric.Saxe@Sun.COM } 39208906SEric.Saxe@Sun.COM } 39218906SEric.Saxe@Sun.COM 39228930SBill.Holler@Sun.COM #endif /* !__xpv */ 39238930SBill.Holler@Sun.COM 39248930SBill.Holler@Sun.COM void 39258930SBill.Holler@Sun.COM post_startup_cpu_fixups(void) 39268930SBill.Holler@Sun.COM { 39278930SBill.Holler@Sun.COM #ifndef __xpv 39288930SBill.Holler@Sun.COM /* 39298930SBill.Holler@Sun.COM * Some AMD processors support C1E state. Entering this state will 39308930SBill.Holler@Sun.COM * cause the local APIC timer to stop, which we can't deal with at 39318930SBill.Holler@Sun.COM * this time. 39328930SBill.Holler@Sun.COM */ 39338930SBill.Holler@Sun.COM if (cpuid_getvendor(CPU) == X86_VENDOR_AMD) { 39348930SBill.Holler@Sun.COM on_trap_data_t otd; 39358930SBill.Holler@Sun.COM uint64_t reg; 39368930SBill.Holler@Sun.COM 39378930SBill.Holler@Sun.COM if (!on_trap(&otd, OT_DATA_ACCESS)) { 39388930SBill.Holler@Sun.COM reg = rdmsr(MSR_AMD_INT_PENDING_CMP_HALT); 39398930SBill.Holler@Sun.COM /* Disable C1E state if it is enabled by BIOS */ 39408930SBill.Holler@Sun.COM if ((reg >> AMD_ACTONCMPHALT_SHIFT) & 39418930SBill.Holler@Sun.COM AMD_ACTONCMPHALT_MASK) { 39428930SBill.Holler@Sun.COM reg &= ~(AMD_ACTONCMPHALT_MASK << 39438930SBill.Holler@Sun.COM AMD_ACTONCMPHALT_SHIFT); 39448930SBill.Holler@Sun.COM wrmsr(MSR_AMD_INT_PENDING_CMP_HALT, reg); 39458930SBill.Holler@Sun.COM } 39468930SBill.Holler@Sun.COM } 39478930SBill.Holler@Sun.COM no_trap(); 39488930SBill.Holler@Sun.COM } 39498930SBill.Holler@Sun.COM #endif /* !__xpv */ 39508930SBill.Holler@Sun.COM } 39518930SBill.Holler@Sun.COM 39529283SBill.Holler@Sun.COM /* 39539283SBill.Holler@Sun.COM * Starting with the Westmere processor the local 39549283SBill.Holler@Sun.COM * APIC timer will continue running in all C-states, 39559283SBill.Holler@Sun.COM * including the deepest C-states. 39569283SBill.Holler@Sun.COM */ 39579283SBill.Holler@Sun.COM int 39589283SBill.Holler@Sun.COM cpuid_arat_supported(void) 39599283SBill.Holler@Sun.COM { 39609283SBill.Holler@Sun.COM struct cpuid_info *cpi; 39619283SBill.Holler@Sun.COM struct cpuid_regs regs; 39629283SBill.Holler@Sun.COM 39639283SBill.Holler@Sun.COM ASSERT(cpuid_checkpass(CPU, 1)); 39649283SBill.Holler@Sun.COM ASSERT(x86_feature & X86_CPUID); 39659283SBill.Holler@Sun.COM 39669283SBill.Holler@Sun.COM cpi = CPU->cpu_m.mcpu_cpi; 39679283SBill.Holler@Sun.COM 39689283SBill.Holler@Sun.COM switch (cpi->cpi_vendor) { 39699283SBill.Holler@Sun.COM case X86_VENDOR_Intel: 39709283SBill.Holler@Sun.COM /* 39719283SBill.Holler@Sun.COM * Always-running Local APIC Timer is 39729283SBill.Holler@Sun.COM * indicated by CPUID.6.EAX[2]. 39739283SBill.Holler@Sun.COM */ 39749283SBill.Holler@Sun.COM if (cpi->cpi_maxeax >= 6) { 39759283SBill.Holler@Sun.COM regs.cp_eax = 6; 39769283SBill.Holler@Sun.COM (void) cpuid_insn(NULL, ®s); 39779283SBill.Holler@Sun.COM return (regs.cp_eax & CPUID_CSTATE_ARAT); 39789283SBill.Holler@Sun.COM } else { 39799283SBill.Holler@Sun.COM return (0); 39809283SBill.Holler@Sun.COM } 39819283SBill.Holler@Sun.COM default: 39829283SBill.Holler@Sun.COM return (0); 39839283SBill.Holler@Sun.COM } 39849283SBill.Holler@Sun.COM } 39859283SBill.Holler@Sun.COM 39868377SBill.Holler@Sun.COM #if defined(__amd64) && !defined(__xpv) 39878377SBill.Holler@Sun.COM /* 39888377SBill.Holler@Sun.COM * Patch in versions of bcopy for high performance Intel Nhm processors 39898377SBill.Holler@Sun.COM * and later... 39908377SBill.Holler@Sun.COM */ 39918377SBill.Holler@Sun.COM void 39928377SBill.Holler@Sun.COM patch_memops(uint_t vendor) 39938377SBill.Holler@Sun.COM { 39948377SBill.Holler@Sun.COM size_t cnt, i; 39958377SBill.Holler@Sun.COM caddr_t to, from; 39968377SBill.Holler@Sun.COM 39978377SBill.Holler@Sun.COM if ((vendor == X86_VENDOR_Intel) && ((x86_feature & X86_SSE4_2) != 0)) { 39988377SBill.Holler@Sun.COM cnt = &bcopy_patch_end - &bcopy_patch_start; 39998377SBill.Holler@Sun.COM to = &bcopy_ck_size; 40008377SBill.Holler@Sun.COM from = &bcopy_patch_start; 40018377SBill.Holler@Sun.COM for (i = 0; i < cnt; i++) { 40028377SBill.Holler@Sun.COM *to++ = *from++; 40038377SBill.Holler@Sun.COM } 40048377SBill.Holler@Sun.COM } 40058377SBill.Holler@Sun.COM } 40068377SBill.Holler@Sun.COM #endif /* __amd64 && !__xpv */ 4007