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 */ 2910947SSrihari.Venkatesan@Sun.COM /* 3010947SSrihari.Venkatesan@Sun.COM * Portions Copyright 2009 Advanced Micro Devices, Inc. 3110947SSrihari.Venkatesan@Sun.COM */ 320Sstevel@tonic-gate 330Sstevel@tonic-gate /* 340Sstevel@tonic-gate * Various routines to handle identification 350Sstevel@tonic-gate * and classification of x86 processors. 360Sstevel@tonic-gate */ 370Sstevel@tonic-gate 380Sstevel@tonic-gate #include <sys/types.h> 390Sstevel@tonic-gate #include <sys/archsystm.h> 400Sstevel@tonic-gate #include <sys/x86_archext.h> 410Sstevel@tonic-gate #include <sys/kmem.h> 420Sstevel@tonic-gate #include <sys/systm.h> 430Sstevel@tonic-gate #include <sys/cmn_err.h> 440Sstevel@tonic-gate #include <sys/sunddi.h> 450Sstevel@tonic-gate #include <sys/sunndi.h> 460Sstevel@tonic-gate #include <sys/cpuvar.h> 470Sstevel@tonic-gate #include <sys/processor.h> 485045Sbholler #include <sys/sysmacros.h> 493434Sesaxe #include <sys/pg.h> 500Sstevel@tonic-gate #include <sys/fp.h> 510Sstevel@tonic-gate #include <sys/controlregs.h> 520Sstevel@tonic-gate #include <sys/auxv_386.h> 530Sstevel@tonic-gate #include <sys/bitmap.h> 540Sstevel@tonic-gate #include <sys/memnode.h> 5510947SSrihari.Venkatesan@Sun.COM #include <sys/pci_cfgspace.h> 560Sstevel@tonic-gate 577532SSean.Ye@Sun.COM #ifdef __xpv 587532SSean.Ye@Sun.COM #include <sys/hypervisor.h> 598930SBill.Holler@Sun.COM #else 608930SBill.Holler@Sun.COM #include <sys/ontrap.h> 617532SSean.Ye@Sun.COM #endif 627532SSean.Ye@Sun.COM 630Sstevel@tonic-gate /* 640Sstevel@tonic-gate * Pass 0 of cpuid feature analysis happens in locore. It contains special code 650Sstevel@tonic-gate * to recognize Cyrix processors that are not cpuid-compliant, and to deal with 660Sstevel@tonic-gate * them accordingly. For most modern processors, feature detection occurs here 670Sstevel@tonic-gate * in pass 1. 680Sstevel@tonic-gate * 690Sstevel@tonic-gate * Pass 1 of cpuid feature analysis happens just at the beginning of mlsetup() 700Sstevel@tonic-gate * for the boot CPU and does the basic analysis that the early kernel needs. 710Sstevel@tonic-gate * x86_feature is set based on the return value of cpuid_pass1() of the boot 720Sstevel@tonic-gate * CPU. 730Sstevel@tonic-gate * 740Sstevel@tonic-gate * Pass 1 includes: 750Sstevel@tonic-gate * 760Sstevel@tonic-gate * o Determining vendor/model/family/stepping and setting x86_type and 770Sstevel@tonic-gate * x86_vendor accordingly. 780Sstevel@tonic-gate * o Processing the feature flags returned by the cpuid instruction while 790Sstevel@tonic-gate * applying any workarounds or tricks for the specific processor. 800Sstevel@tonic-gate * o Mapping the feature flags into Solaris feature bits (X86_*). 810Sstevel@tonic-gate * o Processing extended feature flags if supported by the processor, 820Sstevel@tonic-gate * again while applying specific processor knowledge. 830Sstevel@tonic-gate * o Determining the CMT characteristics of the system. 840Sstevel@tonic-gate * 850Sstevel@tonic-gate * Pass 1 is done on non-boot CPUs during their initialization and the results 860Sstevel@tonic-gate * are used only as a meager attempt at ensuring that all processors within the 870Sstevel@tonic-gate * system support the same features. 880Sstevel@tonic-gate * 890Sstevel@tonic-gate * Pass 2 of cpuid feature analysis happens just at the beginning 900Sstevel@tonic-gate * of startup(). It just copies in and corrects the remainder 910Sstevel@tonic-gate * of the cpuid data we depend on: standard cpuid functions that we didn't 920Sstevel@tonic-gate * need for pass1 feature analysis, and extended cpuid functions beyond the 930Sstevel@tonic-gate * simple feature processing done in pass1. 940Sstevel@tonic-gate * 950Sstevel@tonic-gate * Pass 3 of cpuid analysis is invoked after basic kernel services; in 960Sstevel@tonic-gate * particular kernel memory allocation has been made available. It creates a 970Sstevel@tonic-gate * readable brand string based on the data collected in the first two passes. 980Sstevel@tonic-gate * 990Sstevel@tonic-gate * Pass 4 of cpuid analysis is invoked after post_startup() when all 1000Sstevel@tonic-gate * the support infrastructure for various hardware features has been 1010Sstevel@tonic-gate * initialized. It determines which processor features will be reported 1020Sstevel@tonic-gate * to userland via the aux vector. 1030Sstevel@tonic-gate * 1040Sstevel@tonic-gate * All passes are executed on all CPUs, but only the boot CPU determines what 1050Sstevel@tonic-gate * features the kernel will use. 1060Sstevel@tonic-gate * 1070Sstevel@tonic-gate * Much of the worst junk in this file is for the support of processors 1080Sstevel@tonic-gate * that didn't really implement the cpuid instruction properly. 1090Sstevel@tonic-gate * 1100Sstevel@tonic-gate * NOTE: The accessor functions (cpuid_get*) are aware of, and ASSERT upon, 1110Sstevel@tonic-gate * the pass numbers. Accordingly, changes to the pass code may require changes 1120Sstevel@tonic-gate * to the accessor code. 1130Sstevel@tonic-gate */ 1140Sstevel@tonic-gate 1150Sstevel@tonic-gate uint_t x86_feature = 0; 1160Sstevel@tonic-gate uint_t x86_vendor = X86_VENDOR_IntelClone; 1170Sstevel@tonic-gate uint_t x86_type = X86_TYPE_OTHER; 1187589SVikram.Hegde@Sun.COM uint_t x86_clflush_size = 0; 1190Sstevel@tonic-gate 1200Sstevel@tonic-gate uint_t pentiumpro_bug4046376; 1210Sstevel@tonic-gate uint_t pentiumpro_bug4064495; 1220Sstevel@tonic-gate 1230Sstevel@tonic-gate uint_t enable486; 1248990SSurya.Prakki@Sun.COM /* 1259000SStuart.Maybee@Sun.COM * This is set to platform type Solaris is running on. 1268990SSurya.Prakki@Sun.COM */ 12710175SStuart.Maybee@Sun.COM static int platform_type = -1; 12810175SStuart.Maybee@Sun.COM 12910175SStuart.Maybee@Sun.COM #if !defined(__xpv) 13010175SStuart.Maybee@Sun.COM /* 13110175SStuart.Maybee@Sun.COM * Variable to patch if hypervisor platform detection needs to be 13210175SStuart.Maybee@Sun.COM * disabled (e.g. platform_type will always be HW_NATIVE if this is 0). 13310175SStuart.Maybee@Sun.COM */ 13410175SStuart.Maybee@Sun.COM int enable_platform_detection = 1; 13510175SStuart.Maybee@Sun.COM #endif 1360Sstevel@tonic-gate 1370Sstevel@tonic-gate /* 1384481Sbholler * monitor/mwait info. 1395045Sbholler * 1405045Sbholler * size_actual and buf_actual are the real address and size allocated to get 1415045Sbholler * proper mwait_buf alignement. buf_actual and size_actual should be passed 1425045Sbholler * to kmem_free(). Currently kmem_alloc() and mwait happen to both use 1435045Sbholler * processor cache-line alignment, but this is not guarantied in the furture. 1444481Sbholler */ 1454481Sbholler struct mwait_info { 1464481Sbholler size_t mon_min; /* min size to avoid missed wakeups */ 1474481Sbholler size_t mon_max; /* size to avoid false wakeups */ 1485045Sbholler size_t size_actual; /* size actually allocated */ 1495045Sbholler void *buf_actual; /* memory actually allocated */ 1504481Sbholler uint32_t support; /* processor support of monitor/mwait */ 1514481Sbholler }; 1524481Sbholler 1534481Sbholler /* 1540Sstevel@tonic-gate * These constants determine how many of the elements of the 1550Sstevel@tonic-gate * cpuid we cache in the cpuid_info data structure; the 1560Sstevel@tonic-gate * remaining elements are accessible via the cpuid instruction. 1570Sstevel@tonic-gate */ 1580Sstevel@tonic-gate 1590Sstevel@tonic-gate #define NMAX_CPI_STD 6 /* eax = 0 .. 5 */ 16010947SSrihari.Venkatesan@Sun.COM #define NMAX_CPI_EXTD 0x1c /* eax = 0x80000000 .. 0x8000001b */ 16110947SSrihari.Venkatesan@Sun.COM 16210947SSrihari.Venkatesan@Sun.COM /* 16310947SSrihari.Venkatesan@Sun.COM * Some terminology needs to be explained: 16410947SSrihari.Venkatesan@Sun.COM * - Socket: Something that can be plugged into a motherboard. 16510947SSrihari.Venkatesan@Sun.COM * - Package: Same as socket 16610947SSrihari.Venkatesan@Sun.COM * - Chip: Same as socket. Note that AMD's documentation uses term "chip" 16710947SSrihari.Venkatesan@Sun.COM * differently: there, chip is the same as processor node (below) 16810947SSrihari.Venkatesan@Sun.COM * - Processor node: Some AMD processors have more than one 16910947SSrihari.Venkatesan@Sun.COM * "subprocessor" embedded in a package. These subprocessors (nodes) 17010947SSrihari.Venkatesan@Sun.COM * are fully-functional processors themselves with cores, caches, 17110947SSrihari.Venkatesan@Sun.COM * memory controllers, PCI configuration spaces. They are connected 17210947SSrihari.Venkatesan@Sun.COM * inside the package with Hypertransport links. On single-node 17310947SSrihari.Venkatesan@Sun.COM * processors, processor node is equivalent to chip/socket/package. 17410947SSrihari.Venkatesan@Sun.COM */ 1750Sstevel@tonic-gate 1760Sstevel@tonic-gate struct cpuid_info { 1770Sstevel@tonic-gate uint_t cpi_pass; /* last pass completed */ 1780Sstevel@tonic-gate /* 1790Sstevel@tonic-gate * standard function information 1800Sstevel@tonic-gate */ 1810Sstevel@tonic-gate uint_t cpi_maxeax; /* fn 0: %eax */ 1820Sstevel@tonic-gate char cpi_vendorstr[13]; /* fn 0: %ebx:%ecx:%edx */ 1830Sstevel@tonic-gate uint_t cpi_vendor; /* enum of cpi_vendorstr */ 1840Sstevel@tonic-gate 1850Sstevel@tonic-gate uint_t cpi_family; /* fn 1: extended family */ 1860Sstevel@tonic-gate uint_t cpi_model; /* fn 1: extended model */ 1870Sstevel@tonic-gate uint_t cpi_step; /* fn 1: stepping */ 18810947SSrihari.Venkatesan@Sun.COM chipid_t cpi_chipid; /* fn 1: %ebx: Intel: chip # */ 18910947SSrihari.Venkatesan@Sun.COM /* AMD: package/socket # */ 1900Sstevel@tonic-gate uint_t cpi_brandid; /* fn 1: %ebx: brand ID */ 1910Sstevel@tonic-gate int cpi_clogid; /* fn 1: %ebx: thread # */ 1921228Sandrei uint_t cpi_ncpu_per_chip; /* fn 1: %ebx: logical cpu count */ 1930Sstevel@tonic-gate uint8_t cpi_cacheinfo[16]; /* fn 2: intel-style cache desc */ 1940Sstevel@tonic-gate uint_t cpi_ncache; /* fn 2: number of elements */ 1954606Sesaxe uint_t cpi_ncpu_shr_last_cache; /* fn 4: %eax: ncpus sharing cache */ 1964606Sesaxe id_t cpi_last_lvl_cacheid; /* fn 4: %eax: derived cache id */ 1974606Sesaxe uint_t cpi_std_4_size; /* fn 4: number of fn 4 elements */ 1984606Sesaxe struct cpuid_regs **cpi_std_4; /* fn 4: %ecx == 0 .. fn4_size */ 1991228Sandrei struct cpuid_regs cpi_std[NMAX_CPI_STD]; /* 0 .. 5 */ 2000Sstevel@tonic-gate /* 2010Sstevel@tonic-gate * extended function information 2020Sstevel@tonic-gate */ 2030Sstevel@tonic-gate uint_t cpi_xmaxeax; /* fn 0x80000000: %eax */ 2040Sstevel@tonic-gate char cpi_brandstr[49]; /* fn 0x8000000[234] */ 2050Sstevel@tonic-gate uint8_t cpi_pabits; /* fn 0x80000006: %eax */ 20610947SSrihari.Venkatesan@Sun.COM uint8_t cpi_vabits; /* fn 0x80000006: %eax */ 20710947SSrihari.Venkatesan@Sun.COM struct cpuid_regs cpi_extd[NMAX_CPI_EXTD]; /* 0x800000XX */ 20810947SSrihari.Venkatesan@Sun.COM 2095870Sgavinm id_t cpi_coreid; /* same coreid => strands share core */ 2105870Sgavinm int cpi_pkgcoreid; /* core number within single package */ 2111228Sandrei uint_t cpi_ncore_per_chip; /* AMD: fn 0x80000008: %ecx[7-0] */ 2121228Sandrei /* Intel: fn 4: %eax[31-26] */ 2130Sstevel@tonic-gate /* 2140Sstevel@tonic-gate * supported feature information 2150Sstevel@tonic-gate */ 2163446Smrj uint32_t cpi_support[5]; 2170Sstevel@tonic-gate #define STD_EDX_FEATURES 0 2180Sstevel@tonic-gate #define AMD_EDX_FEATURES 1 2190Sstevel@tonic-gate #define TM_EDX_FEATURES 2 2200Sstevel@tonic-gate #define STD_ECX_FEATURES 3 2213446Smrj #define AMD_ECX_FEATURES 4 2222869Sgavinm /* 2232869Sgavinm * Synthesized information, where known. 2242869Sgavinm */ 2252869Sgavinm uint32_t cpi_chiprev; /* See X86_CHIPREV_* in x86_archext.h */ 2262869Sgavinm const char *cpi_chiprevstr; /* May be NULL if chiprev unknown */ 2272869Sgavinm uint32_t cpi_socket; /* Chip package/socket type */ 2284481Sbholler 2294481Sbholler struct mwait_info cpi_mwait; /* fn 5: monitor/mwait info */ 2307282Smishra uint32_t cpi_apicid; 23110947SSrihari.Venkatesan@Sun.COM uint_t cpi_procnodeid; /* AMD: nodeID on HT, Intel: chipid */ 23210947SSrihari.Venkatesan@Sun.COM uint_t cpi_procnodes_per_pkg; /* AMD: # of nodes in the package */ 23310947SSrihari.Venkatesan@Sun.COM /* Intel: 1 */ 2340Sstevel@tonic-gate }; 2350Sstevel@tonic-gate 2360Sstevel@tonic-gate 2370Sstevel@tonic-gate static struct cpuid_info cpuid_info0; 2380Sstevel@tonic-gate 2390Sstevel@tonic-gate /* 2400Sstevel@tonic-gate * These bit fields are defined by the Intel Application Note AP-485 2410Sstevel@tonic-gate * "Intel Processor Identification and the CPUID Instruction" 2420Sstevel@tonic-gate */ 2430Sstevel@tonic-gate #define CPI_FAMILY_XTD(cpi) BITX((cpi)->cpi_std[1].cp_eax, 27, 20) 2440Sstevel@tonic-gate #define CPI_MODEL_XTD(cpi) BITX((cpi)->cpi_std[1].cp_eax, 19, 16) 2450Sstevel@tonic-gate #define CPI_TYPE(cpi) BITX((cpi)->cpi_std[1].cp_eax, 13, 12) 2460Sstevel@tonic-gate #define CPI_FAMILY(cpi) BITX((cpi)->cpi_std[1].cp_eax, 11, 8) 2470Sstevel@tonic-gate #define CPI_STEP(cpi) BITX((cpi)->cpi_std[1].cp_eax, 3, 0) 2480Sstevel@tonic-gate #define CPI_MODEL(cpi) BITX((cpi)->cpi_std[1].cp_eax, 7, 4) 2490Sstevel@tonic-gate 2500Sstevel@tonic-gate #define CPI_FEATURES_EDX(cpi) ((cpi)->cpi_std[1].cp_edx) 2510Sstevel@tonic-gate #define CPI_FEATURES_ECX(cpi) ((cpi)->cpi_std[1].cp_ecx) 2520Sstevel@tonic-gate #define CPI_FEATURES_XTD_EDX(cpi) ((cpi)->cpi_extd[1].cp_edx) 2530Sstevel@tonic-gate #define CPI_FEATURES_XTD_ECX(cpi) ((cpi)->cpi_extd[1].cp_ecx) 2540Sstevel@tonic-gate 2550Sstevel@tonic-gate #define CPI_BRANDID(cpi) BITX((cpi)->cpi_std[1].cp_ebx, 7, 0) 2560Sstevel@tonic-gate #define CPI_CHUNKS(cpi) BITX((cpi)->cpi_std[1].cp_ebx, 15, 7) 2570Sstevel@tonic-gate #define CPI_CPU_COUNT(cpi) BITX((cpi)->cpi_std[1].cp_ebx, 23, 16) 2580Sstevel@tonic-gate #define CPI_APIC_ID(cpi) BITX((cpi)->cpi_std[1].cp_ebx, 31, 24) 2590Sstevel@tonic-gate 2600Sstevel@tonic-gate #define CPI_MAXEAX_MAX 0x100 /* sanity control */ 2610Sstevel@tonic-gate #define CPI_XMAXEAX_MAX 0x80000100 2624606Sesaxe #define CPI_FN4_ECX_MAX 0x20 /* sanity: max fn 4 levels */ 2637282Smishra #define CPI_FNB_ECX_MAX 0x20 /* sanity: max fn B levels */ 2644606Sesaxe 2654606Sesaxe /* 2664606Sesaxe * Function 4 (Deterministic Cache Parameters) macros 2674606Sesaxe * Defined by Intel Application Note AP-485 2684606Sesaxe */ 2694606Sesaxe #define CPI_NUM_CORES(regs) BITX((regs)->cp_eax, 31, 26) 2704606Sesaxe #define CPI_NTHR_SHR_CACHE(regs) BITX((regs)->cp_eax, 25, 14) 2714606Sesaxe #define CPI_FULL_ASSOC_CACHE(regs) BITX((regs)->cp_eax, 9, 9) 2724606Sesaxe #define CPI_SELF_INIT_CACHE(regs) BITX((regs)->cp_eax, 8, 8) 2734606Sesaxe #define CPI_CACHE_LVL(regs) BITX((regs)->cp_eax, 7, 5) 2744606Sesaxe #define CPI_CACHE_TYPE(regs) BITX((regs)->cp_eax, 4, 0) 2757282Smishra #define CPI_CPU_LEVEL_TYPE(regs) BITX((regs)->cp_ecx, 15, 8) 2764606Sesaxe 2774606Sesaxe #define CPI_CACHE_WAYS(regs) BITX((regs)->cp_ebx, 31, 22) 2784606Sesaxe #define CPI_CACHE_PARTS(regs) BITX((regs)->cp_ebx, 21, 12) 2794606Sesaxe #define CPI_CACHE_COH_LN_SZ(regs) BITX((regs)->cp_ebx, 11, 0) 2804606Sesaxe 2814606Sesaxe #define CPI_CACHE_SETS(regs) BITX((regs)->cp_ecx, 31, 0) 2824606Sesaxe 2834606Sesaxe #define CPI_PREFCH_STRIDE(regs) BITX((regs)->cp_edx, 9, 0) 2844606Sesaxe 2850Sstevel@tonic-gate 2860Sstevel@tonic-gate /* 2871975Sdmick * A couple of shorthand macros to identify "later" P6-family chips 2881975Sdmick * like the Pentium M and Core. First, the "older" P6-based stuff 2891975Sdmick * (loosely defined as "pre-Pentium-4"): 2901975Sdmick * P6, PII, Mobile PII, PII Xeon, PIII, Mobile PIII, PIII Xeon 2911975Sdmick */ 2921975Sdmick 2931975Sdmick #define IS_LEGACY_P6(cpi) ( \ 2941975Sdmick cpi->cpi_family == 6 && \ 2951975Sdmick (cpi->cpi_model == 1 || \ 2961975Sdmick cpi->cpi_model == 3 || \ 2971975Sdmick cpi->cpi_model == 5 || \ 2981975Sdmick cpi->cpi_model == 6 || \ 2991975Sdmick cpi->cpi_model == 7 || \ 3001975Sdmick cpi->cpi_model == 8 || \ 3011975Sdmick cpi->cpi_model == 0xA || \ 3021975Sdmick cpi->cpi_model == 0xB) \ 3031975Sdmick ) 3041975Sdmick 3051975Sdmick /* A "new F6" is everything with family 6 that's not the above */ 3061975Sdmick #define IS_NEW_F6(cpi) ((cpi->cpi_family == 6) && !IS_LEGACY_P6(cpi)) 3071975Sdmick 3084855Sksadhukh /* Extended family/model support */ 3094855Sksadhukh #define IS_EXTENDED_MODEL_INTEL(cpi) (cpi->cpi_family == 0x6 || \ 3104855Sksadhukh cpi->cpi_family >= 0xf) 3114855Sksadhukh 3121975Sdmick /* 3134481Sbholler * Info for monitor/mwait idle loop. 3144481Sbholler * 3154481Sbholler * See cpuid section of "Intel 64 and IA-32 Architectures Software Developer's 3164481Sbholler * Manual Volume 2A: Instruction Set Reference, A-M" #25366-022US, November 3174481Sbholler * 2006. 3184481Sbholler * See MONITOR/MWAIT section of "AMD64 Architecture Programmer's Manual 3194481Sbholler * Documentation Updates" #33633, Rev 2.05, December 2006. 3204481Sbholler */ 3214481Sbholler #define MWAIT_SUPPORT (0x00000001) /* mwait supported */ 3224481Sbholler #define MWAIT_EXTENSIONS (0x00000002) /* extenstion supported */ 3234481Sbholler #define MWAIT_ECX_INT_ENABLE (0x00000004) /* ecx 1 extension supported */ 3244481Sbholler #define MWAIT_SUPPORTED(cpi) ((cpi)->cpi_std[1].cp_ecx & CPUID_INTC_ECX_MON) 3254481Sbholler #define MWAIT_INT_ENABLE(cpi) ((cpi)->cpi_std[5].cp_ecx & 0x2) 3264481Sbholler #define MWAIT_EXTENSION(cpi) ((cpi)->cpi_std[5].cp_ecx & 0x1) 3274481Sbholler #define MWAIT_SIZE_MIN(cpi) BITX((cpi)->cpi_std[5].cp_eax, 15, 0) 3284481Sbholler #define MWAIT_SIZE_MAX(cpi) BITX((cpi)->cpi_std[5].cp_ebx, 15, 0) 3294481Sbholler /* 3304481Sbholler * Number of sub-cstates for a given c-state. 3314481Sbholler */ 3324481Sbholler #define MWAIT_NUM_SUBC_STATES(cpi, c_state) \ 3334481Sbholler BITX((cpi)->cpi_std[5].cp_edx, c_state + 3, c_state) 3344481Sbholler 3357532SSean.Ye@Sun.COM /* 3367532SSean.Ye@Sun.COM * Functions we consune from cpuid_subr.c; don't publish these in a header 3377532SSean.Ye@Sun.COM * file to try and keep people using the expected cpuid_* interfaces. 3387532SSean.Ye@Sun.COM */ 3397532SSean.Ye@Sun.COM extern uint32_t _cpuid_skt(uint_t, uint_t, uint_t, uint_t); 3409482SKuriakose.Kuruvilla@Sun.COM extern const char *_cpuid_sktstr(uint_t, uint_t, uint_t, uint_t); 3417532SSean.Ye@Sun.COM extern uint32_t _cpuid_chiprev(uint_t, uint_t, uint_t, uint_t); 3427532SSean.Ye@Sun.COM extern const char *_cpuid_chiprevstr(uint_t, uint_t, uint_t, uint_t); 3437532SSean.Ye@Sun.COM extern uint_t _cpuid_vendorstr_to_vendorcode(char *); 3442869Sgavinm 3452869Sgavinm /* 3463446Smrj * Apply up various platform-dependent restrictions where the 3473446Smrj * underlying platform restrictions mean the CPU can be marked 3483446Smrj * as less capable than its cpuid instruction would imply. 3493446Smrj */ 3505084Sjohnlev #if defined(__xpv) 3515084Sjohnlev static void 3525084Sjohnlev platform_cpuid_mangle(uint_t vendor, uint32_t eax, struct cpuid_regs *cp) 3535084Sjohnlev { 3545084Sjohnlev switch (eax) { 3557532SSean.Ye@Sun.COM case 1: { 3567532SSean.Ye@Sun.COM uint32_t mcamask = DOMAIN_IS_INITDOMAIN(xen_info) ? 3577532SSean.Ye@Sun.COM 0 : CPUID_INTC_EDX_MCA; 3585084Sjohnlev cp->cp_edx &= 3597532SSean.Ye@Sun.COM ~(mcamask | 3607532SSean.Ye@Sun.COM CPUID_INTC_EDX_PSE | 3615084Sjohnlev CPUID_INTC_EDX_VME | CPUID_INTC_EDX_DE | 3625084Sjohnlev CPUID_INTC_EDX_SEP | CPUID_INTC_EDX_MTRR | 3635084Sjohnlev CPUID_INTC_EDX_PGE | CPUID_INTC_EDX_PAT | 3645084Sjohnlev CPUID_AMD_EDX_SYSC | CPUID_INTC_EDX_SEP | 3655084Sjohnlev CPUID_INTC_EDX_PSE36 | CPUID_INTC_EDX_HTT); 3665084Sjohnlev break; 3677532SSean.Ye@Sun.COM } 3685084Sjohnlev 3695084Sjohnlev case 0x80000001: 3705084Sjohnlev cp->cp_edx &= 3715084Sjohnlev ~(CPUID_AMD_EDX_PSE | 3725084Sjohnlev CPUID_INTC_EDX_VME | CPUID_INTC_EDX_DE | 3735084Sjohnlev CPUID_AMD_EDX_MTRR | CPUID_AMD_EDX_PGE | 3745084Sjohnlev CPUID_AMD_EDX_PAT | CPUID_AMD_EDX_PSE36 | 3755084Sjohnlev CPUID_AMD_EDX_SYSC | CPUID_INTC_EDX_SEP | 3765084Sjohnlev CPUID_AMD_EDX_TSCP); 3775084Sjohnlev cp->cp_ecx &= ~CPUID_AMD_ECX_CMP_LGCY; 3785084Sjohnlev break; 3795084Sjohnlev default: 3805084Sjohnlev break; 3815084Sjohnlev } 3825084Sjohnlev 3835084Sjohnlev switch (vendor) { 3845084Sjohnlev case X86_VENDOR_Intel: 3855084Sjohnlev switch (eax) { 3865084Sjohnlev case 4: 3875084Sjohnlev /* 3885084Sjohnlev * Zero out the (ncores-per-chip - 1) field 3895084Sjohnlev */ 3905084Sjohnlev cp->cp_eax &= 0x03fffffff; 3915084Sjohnlev break; 3925084Sjohnlev default: 3935084Sjohnlev break; 3945084Sjohnlev } 3955084Sjohnlev break; 3965084Sjohnlev case X86_VENDOR_AMD: 3975084Sjohnlev switch (eax) { 39810080SJoe.Bonasera@sun.com 39910080SJoe.Bonasera@sun.com case 0x80000001: 40010080SJoe.Bonasera@sun.com cp->cp_ecx &= ~CPUID_AMD_ECX_CR8D; 40110080SJoe.Bonasera@sun.com break; 40210080SJoe.Bonasera@sun.com 4035084Sjohnlev case 0x80000008: 4045084Sjohnlev /* 4055084Sjohnlev * Zero out the (ncores-per-chip - 1) field 4065084Sjohnlev */ 4075084Sjohnlev cp->cp_ecx &= 0xffffff00; 4085084Sjohnlev break; 4095084Sjohnlev default: 4105084Sjohnlev break; 4115084Sjohnlev } 4125084Sjohnlev break; 4135084Sjohnlev default: 4145084Sjohnlev break; 4155084Sjohnlev } 4165084Sjohnlev } 4175084Sjohnlev #else 4183446Smrj #define platform_cpuid_mangle(vendor, eax, cp) /* nothing */ 4195084Sjohnlev #endif 4203446Smrj 4213446Smrj /* 4220Sstevel@tonic-gate * Some undocumented ways of patching the results of the cpuid 4230Sstevel@tonic-gate * instruction to permit running Solaris 10 on future cpus that 4240Sstevel@tonic-gate * we don't currently support. Could be set to non-zero values 4250Sstevel@tonic-gate * via settings in eeprom. 4260Sstevel@tonic-gate */ 4270Sstevel@tonic-gate 4280Sstevel@tonic-gate uint32_t cpuid_feature_ecx_include; 4290Sstevel@tonic-gate uint32_t cpuid_feature_ecx_exclude; 4300Sstevel@tonic-gate uint32_t cpuid_feature_edx_include; 4310Sstevel@tonic-gate uint32_t cpuid_feature_edx_exclude; 4320Sstevel@tonic-gate 4333446Smrj void 4343446Smrj cpuid_alloc_space(cpu_t *cpu) 4353446Smrj { 4363446Smrj /* 4373446Smrj * By convention, cpu0 is the boot cpu, which is set up 4383446Smrj * before memory allocation is available. All other cpus get 4393446Smrj * their cpuid_info struct allocated here. 4403446Smrj */ 4413446Smrj ASSERT(cpu->cpu_id != 0); 4423446Smrj cpu->cpu_m.mcpu_cpi = 4433446Smrj kmem_zalloc(sizeof (*cpu->cpu_m.mcpu_cpi), KM_SLEEP); 4443446Smrj } 4453446Smrj 4463446Smrj void 4473446Smrj cpuid_free_space(cpu_t *cpu) 4483446Smrj { 4494606Sesaxe struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 4504606Sesaxe int i; 4514606Sesaxe 4523446Smrj ASSERT(cpu->cpu_id != 0); 4534606Sesaxe 4544606Sesaxe /* 4554606Sesaxe * Free up any function 4 related dynamic storage 4564606Sesaxe */ 4574606Sesaxe for (i = 1; i < cpi->cpi_std_4_size; i++) 4584606Sesaxe kmem_free(cpi->cpi_std_4[i], sizeof (struct cpuid_regs)); 4594606Sesaxe if (cpi->cpi_std_4_size > 0) 4604606Sesaxe kmem_free(cpi->cpi_std_4, 4614606Sesaxe cpi->cpi_std_4_size * sizeof (struct cpuid_regs *)); 4624606Sesaxe 4633446Smrj kmem_free(cpu->cpu_m.mcpu_cpi, sizeof (*cpu->cpu_m.mcpu_cpi)); 4643446Smrj } 4653446Smrj 4665741Smrj #if !defined(__xpv) 4675741Smrj 4685741Smrj static void 4699000SStuart.Maybee@Sun.COM determine_platform() 4705741Smrj { 4715741Smrj struct cpuid_regs cp; 4725741Smrj char *xen_str; 4735741Smrj uint32_t xen_signature[4]; 4745741Smrj 47510175SStuart.Maybee@Sun.COM platform_type = HW_NATIVE; 47610175SStuart.Maybee@Sun.COM 47710175SStuart.Maybee@Sun.COM if (!enable_platform_detection) 47810175SStuart.Maybee@Sun.COM return; 47910175SStuart.Maybee@Sun.COM 4805741Smrj /* 4815741Smrj * In a fully virtualized domain, Xen's pseudo-cpuid function 4825741Smrj * 0x40000000 returns a string representing the Xen signature in 4835741Smrj * %ebx, %ecx, and %edx. %eax contains the maximum supported cpuid 4845741Smrj * function. 4855741Smrj */ 4865741Smrj cp.cp_eax = 0x40000000; 4875741Smrj (void) __cpuid_insn(&cp); 4885741Smrj xen_signature[0] = cp.cp_ebx; 4895741Smrj xen_signature[1] = cp.cp_ecx; 4905741Smrj xen_signature[2] = cp.cp_edx; 4915741Smrj xen_signature[3] = 0; 4925741Smrj xen_str = (char *)xen_signature; 4939000SStuart.Maybee@Sun.COM if (strcmp("XenVMMXenVMM", xen_str) == 0 && cp.cp_eax <= 0x40000002) { 4949000SStuart.Maybee@Sun.COM platform_type = HW_XEN_HVM; 4959000SStuart.Maybee@Sun.COM } else if (vmware_platform()) { /* running under vmware hypervisor? */ 4969000SStuart.Maybee@Sun.COM platform_type = HW_VMWARE; 4979000SStuart.Maybee@Sun.COM } 4989000SStuart.Maybee@Sun.COM } 4999000SStuart.Maybee@Sun.COM 5009000SStuart.Maybee@Sun.COM int 5019000SStuart.Maybee@Sun.COM get_hwenv(void) 5029000SStuart.Maybee@Sun.COM { 50310175SStuart.Maybee@Sun.COM if (platform_type == -1) 50410175SStuart.Maybee@Sun.COM determine_platform(); 50510175SStuart.Maybee@Sun.COM 5069000SStuart.Maybee@Sun.COM return (platform_type); 5075741Smrj } 5089000SStuart.Maybee@Sun.COM 5099000SStuart.Maybee@Sun.COM int 5109000SStuart.Maybee@Sun.COM is_controldom(void) 5119000SStuart.Maybee@Sun.COM { 5129000SStuart.Maybee@Sun.COM return (0); 5139000SStuart.Maybee@Sun.COM } 5149000SStuart.Maybee@Sun.COM 5159000SStuart.Maybee@Sun.COM #else 5169000SStuart.Maybee@Sun.COM 5179000SStuart.Maybee@Sun.COM int 5189000SStuart.Maybee@Sun.COM get_hwenv(void) 5199000SStuart.Maybee@Sun.COM { 5209000SStuart.Maybee@Sun.COM return (HW_XEN_PV); 5219000SStuart.Maybee@Sun.COM } 5229000SStuart.Maybee@Sun.COM 5239000SStuart.Maybee@Sun.COM int 5249000SStuart.Maybee@Sun.COM is_controldom(void) 5259000SStuart.Maybee@Sun.COM { 5269000SStuart.Maybee@Sun.COM return (DOMAIN_IS_INITDOMAIN(xen_info)); 5279000SStuart.Maybee@Sun.COM } 5289000SStuart.Maybee@Sun.COM 5295741Smrj #endif /* __xpv */ 5305741Smrj 53110947SSrihari.Venkatesan@Sun.COM static void 53210947SSrihari.Venkatesan@Sun.COM cpuid_intel_getids(cpu_t *cpu, uint_t feature) 53310947SSrihari.Venkatesan@Sun.COM { 53410947SSrihari.Venkatesan@Sun.COM uint_t i; 53510947SSrihari.Venkatesan@Sun.COM uint_t chipid_shift = 0; 53610947SSrihari.Venkatesan@Sun.COM uint_t coreid_shift = 0; 53710947SSrihari.Venkatesan@Sun.COM struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 53810947SSrihari.Venkatesan@Sun.COM 53910947SSrihari.Venkatesan@Sun.COM for (i = 1; i < cpi->cpi_ncpu_per_chip; i <<= 1) 54010947SSrihari.Venkatesan@Sun.COM chipid_shift++; 54110947SSrihari.Venkatesan@Sun.COM 54210947SSrihari.Venkatesan@Sun.COM cpi->cpi_chipid = cpi->cpi_apicid >> chipid_shift; 54310947SSrihari.Venkatesan@Sun.COM cpi->cpi_clogid = cpi->cpi_apicid & ((1 << chipid_shift) - 1); 54410947SSrihari.Venkatesan@Sun.COM 54510947SSrihari.Venkatesan@Sun.COM if (feature & X86_CMP) { 54610947SSrihari.Venkatesan@Sun.COM /* 54710947SSrihari.Venkatesan@Sun.COM * Multi-core (and possibly multi-threaded) 54810947SSrihari.Venkatesan@Sun.COM * processors. 54910947SSrihari.Venkatesan@Sun.COM */ 55010947SSrihari.Venkatesan@Sun.COM uint_t ncpu_per_core; 55110947SSrihari.Venkatesan@Sun.COM if (cpi->cpi_ncore_per_chip == 1) 55210947SSrihari.Venkatesan@Sun.COM ncpu_per_core = cpi->cpi_ncpu_per_chip; 55310947SSrihari.Venkatesan@Sun.COM else if (cpi->cpi_ncore_per_chip > 1) 55410947SSrihari.Venkatesan@Sun.COM ncpu_per_core = cpi->cpi_ncpu_per_chip / 55510947SSrihari.Venkatesan@Sun.COM cpi->cpi_ncore_per_chip; 55610947SSrihari.Venkatesan@Sun.COM /* 55710947SSrihari.Venkatesan@Sun.COM * 8bit APIC IDs on dual core Pentiums 55810947SSrihari.Venkatesan@Sun.COM * look like this: 55910947SSrihari.Venkatesan@Sun.COM * 56010947SSrihari.Venkatesan@Sun.COM * +-----------------------+------+------+ 56110947SSrihari.Venkatesan@Sun.COM * | Physical Package ID | MC | HT | 56210947SSrihari.Venkatesan@Sun.COM * +-----------------------+------+------+ 56310947SSrihari.Venkatesan@Sun.COM * <------- chipid --------> 56410947SSrihari.Venkatesan@Sun.COM * <------- coreid ---------------> 56510947SSrihari.Venkatesan@Sun.COM * <--- clogid --> 56610947SSrihari.Venkatesan@Sun.COM * <------> 56710947SSrihari.Venkatesan@Sun.COM * pkgcoreid 56810947SSrihari.Venkatesan@Sun.COM * 56910947SSrihari.Venkatesan@Sun.COM * Where the number of bits necessary to 57010947SSrihari.Venkatesan@Sun.COM * represent MC and HT fields together equals 57110947SSrihari.Venkatesan@Sun.COM * to the minimum number of bits necessary to 57210947SSrihari.Venkatesan@Sun.COM * store the value of cpi->cpi_ncpu_per_chip. 57310947SSrihari.Venkatesan@Sun.COM * Of those bits, the MC part uses the number 57410947SSrihari.Venkatesan@Sun.COM * of bits necessary to store the value of 57510947SSrihari.Venkatesan@Sun.COM * cpi->cpi_ncore_per_chip. 57610947SSrihari.Venkatesan@Sun.COM */ 57710947SSrihari.Venkatesan@Sun.COM for (i = 1; i < ncpu_per_core; i <<= 1) 57810947SSrihari.Venkatesan@Sun.COM coreid_shift++; 57910947SSrihari.Venkatesan@Sun.COM cpi->cpi_coreid = cpi->cpi_apicid >> coreid_shift; 58010947SSrihari.Venkatesan@Sun.COM cpi->cpi_pkgcoreid = cpi->cpi_clogid >> coreid_shift; 58110947SSrihari.Venkatesan@Sun.COM } else if (feature & X86_HTT) { 58210947SSrihari.Venkatesan@Sun.COM /* 58310947SSrihari.Venkatesan@Sun.COM * Single-core multi-threaded processors. 58410947SSrihari.Venkatesan@Sun.COM */ 58510947SSrihari.Venkatesan@Sun.COM cpi->cpi_coreid = cpi->cpi_chipid; 58610947SSrihari.Venkatesan@Sun.COM cpi->cpi_pkgcoreid = 0; 58710947SSrihari.Venkatesan@Sun.COM } 58810947SSrihari.Venkatesan@Sun.COM cpi->cpi_procnodeid = cpi->cpi_chipid; 58910947SSrihari.Venkatesan@Sun.COM } 59010947SSrihari.Venkatesan@Sun.COM 59110947SSrihari.Venkatesan@Sun.COM static void 59210947SSrihari.Venkatesan@Sun.COM cpuid_amd_getids(cpu_t *cpu) 59310947SSrihari.Venkatesan@Sun.COM { 59411013SSrihari.Venkatesan@Sun.COM int i, first_half, coreidsz; 59510947SSrihari.Venkatesan@Sun.COM uint32_t nb_caps_reg; 59610947SSrihari.Venkatesan@Sun.COM uint_t node2_1; 59710947SSrihari.Venkatesan@Sun.COM struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 59810947SSrihari.Venkatesan@Sun.COM 59910947SSrihari.Venkatesan@Sun.COM /* 60010947SSrihari.Venkatesan@Sun.COM * AMD CMP chips currently have a single thread per core. 60110947SSrihari.Venkatesan@Sun.COM * 60210947SSrihari.Venkatesan@Sun.COM * Since no two cpus share a core we must assign a distinct coreid 60310947SSrihari.Venkatesan@Sun.COM * per cpu, and we do this by using the cpu_id. This scheme does not, 60410947SSrihari.Venkatesan@Sun.COM * however, guarantee that sibling cores of a chip will have sequential 60510947SSrihari.Venkatesan@Sun.COM * coreids starting at a multiple of the number of cores per chip - 60610947SSrihari.Venkatesan@Sun.COM * that is usually the case, but if the ACPI MADT table is presented 60710947SSrihari.Venkatesan@Sun.COM * in a different order then we need to perform a few more gymnastics 60810947SSrihari.Venkatesan@Sun.COM * for the pkgcoreid. 60910947SSrihari.Venkatesan@Sun.COM * 61010947SSrihari.Venkatesan@Sun.COM * All processors in the system have the same number of enabled 61110947SSrihari.Venkatesan@Sun.COM * cores. Cores within a processor are always numbered sequentially 61210947SSrihari.Venkatesan@Sun.COM * from 0 regardless of how many or which are disabled, and there 61310947SSrihari.Venkatesan@Sun.COM * is no way for operating system to discover the real core id when some 61410947SSrihari.Venkatesan@Sun.COM * are disabled. 61510947SSrihari.Venkatesan@Sun.COM */ 61610947SSrihari.Venkatesan@Sun.COM 61710947SSrihari.Venkatesan@Sun.COM cpi->cpi_coreid = cpu->cpu_id; 61810947SSrihari.Venkatesan@Sun.COM 61910947SSrihari.Venkatesan@Sun.COM if (cpi->cpi_xmaxeax >= 0x80000008) { 62010947SSrihari.Venkatesan@Sun.COM 62110947SSrihari.Venkatesan@Sun.COM coreidsz = BITX((cpi)->cpi_extd[8].cp_ecx, 15, 12); 62210947SSrihari.Venkatesan@Sun.COM 62310947SSrihari.Venkatesan@Sun.COM /* 62410947SSrihari.Venkatesan@Sun.COM * In AMD parlance chip is really a node while Solaris 62510947SSrihari.Venkatesan@Sun.COM * sees chip as equivalent to socket/package. 62610947SSrihari.Venkatesan@Sun.COM */ 62710947SSrihari.Venkatesan@Sun.COM cpi->cpi_ncore_per_chip = 62810947SSrihari.Venkatesan@Sun.COM BITX((cpi)->cpi_extd[8].cp_ecx, 7, 0) + 1; 62911013SSrihari.Venkatesan@Sun.COM if (coreidsz == 0) { 63010947SSrihari.Venkatesan@Sun.COM /* Use legacy method */ 63111013SSrihari.Venkatesan@Sun.COM for (i = 1; i < cpi->cpi_ncore_per_chip; i <<= 1) 63211013SSrihari.Venkatesan@Sun.COM coreidsz++; 63311013SSrihari.Venkatesan@Sun.COM if (coreidsz == 0) 63411013SSrihari.Venkatesan@Sun.COM coreidsz = 1; 63511013SSrihari.Venkatesan@Sun.COM } 63610947SSrihari.Venkatesan@Sun.COM } else { 63710947SSrihari.Venkatesan@Sun.COM /* Assume single-core part */ 63811013SSrihari.Venkatesan@Sun.COM cpi->cpi_ncore_per_chip = 1; 63910947SSrihari.Venkatesan@Sun.COM } 64010947SSrihari.Venkatesan@Sun.COM 64111013SSrihari.Venkatesan@Sun.COM cpi->cpi_clogid = cpi->cpi_pkgcoreid = 64211013SSrihari.Venkatesan@Sun.COM cpi->cpi_apicid & ((1<<coreidsz) - 1); 64310947SSrihari.Venkatesan@Sun.COM cpi->cpi_ncpu_per_chip = cpi->cpi_ncore_per_chip; 64410947SSrihari.Venkatesan@Sun.COM 64510947SSrihari.Venkatesan@Sun.COM /* Get nodeID */ 64610947SSrihari.Venkatesan@Sun.COM if (cpi->cpi_family == 0xf) { 64711013SSrihari.Venkatesan@Sun.COM cpi->cpi_procnodeid = (cpi->cpi_apicid >> coreidsz) & 7; 64810947SSrihari.Venkatesan@Sun.COM cpi->cpi_chipid = cpi->cpi_procnodeid; 64910947SSrihari.Venkatesan@Sun.COM } else if (cpi->cpi_family == 0x10) { 65010947SSrihari.Venkatesan@Sun.COM /* 65110947SSrihari.Venkatesan@Sun.COM * See if we are a multi-node processor. 65210947SSrihari.Venkatesan@Sun.COM * All processors in the system have the same number of nodes 65310947SSrihari.Venkatesan@Sun.COM */ 65410947SSrihari.Venkatesan@Sun.COM nb_caps_reg = pci_getl_func(0, 24, 3, 0xe8); 65510947SSrihari.Venkatesan@Sun.COM if ((cpi->cpi_model < 8) || BITX(nb_caps_reg, 29, 29) == 0) { 65610947SSrihari.Venkatesan@Sun.COM /* Single-node */ 65711013SSrihari.Venkatesan@Sun.COM cpi->cpi_procnodeid = BITX(cpi->cpi_apicid, 5, 65811013SSrihari.Venkatesan@Sun.COM coreidsz); 65910947SSrihari.Venkatesan@Sun.COM cpi->cpi_chipid = cpi->cpi_procnodeid; 66010947SSrihari.Venkatesan@Sun.COM } else { 66110947SSrihari.Venkatesan@Sun.COM 66210947SSrihari.Venkatesan@Sun.COM /* 66310947SSrihari.Venkatesan@Sun.COM * Multi-node revision D (2 nodes per package 66410947SSrihari.Venkatesan@Sun.COM * are supported) 66510947SSrihari.Venkatesan@Sun.COM */ 66610947SSrihari.Venkatesan@Sun.COM cpi->cpi_procnodes_per_pkg = 2; 66710947SSrihari.Venkatesan@Sun.COM 66810947SSrihari.Venkatesan@Sun.COM first_half = (cpi->cpi_pkgcoreid <= 66910947SSrihari.Venkatesan@Sun.COM (cpi->cpi_ncore_per_chip/2 - 1)); 67010947SSrihari.Venkatesan@Sun.COM 67110947SSrihari.Venkatesan@Sun.COM if (cpi->cpi_apicid == cpi->cpi_pkgcoreid) { 67210947SSrihari.Venkatesan@Sun.COM /* We are BSP */ 67310947SSrihari.Venkatesan@Sun.COM cpi->cpi_procnodeid = (first_half ? 0 : 1); 67410947SSrihari.Venkatesan@Sun.COM cpi->cpi_chipid = cpi->cpi_procnodeid >> 1; 67510947SSrihari.Venkatesan@Sun.COM } else { 67610947SSrihari.Venkatesan@Sun.COM 67710947SSrihari.Venkatesan@Sun.COM /* We are AP */ 67810947SSrihari.Venkatesan@Sun.COM /* NodeId[2:1] bits to use for reading F3xe8 */ 67910947SSrihari.Venkatesan@Sun.COM node2_1 = BITX(cpi->cpi_apicid, 5, 4) << 1; 68010947SSrihari.Venkatesan@Sun.COM 68110947SSrihari.Venkatesan@Sun.COM nb_caps_reg = 68210947SSrihari.Venkatesan@Sun.COM pci_getl_func(0, 24 + node2_1, 3, 0xe8); 68310947SSrihari.Venkatesan@Sun.COM 68410947SSrihari.Venkatesan@Sun.COM /* 68510947SSrihari.Venkatesan@Sun.COM * Check IntNodeNum bit (31:30, but bit 31 is 68610947SSrihari.Venkatesan@Sun.COM * always 0 on dual-node processors) 68710947SSrihari.Venkatesan@Sun.COM */ 68810947SSrihari.Venkatesan@Sun.COM if (BITX(nb_caps_reg, 30, 30) == 0) 68910947SSrihari.Venkatesan@Sun.COM cpi->cpi_procnodeid = node2_1 + 69010947SSrihari.Venkatesan@Sun.COM !first_half; 69110947SSrihari.Venkatesan@Sun.COM else 69210947SSrihari.Venkatesan@Sun.COM cpi->cpi_procnodeid = node2_1 + 69310947SSrihari.Venkatesan@Sun.COM first_half; 69410947SSrihari.Venkatesan@Sun.COM 69510947SSrihari.Venkatesan@Sun.COM cpi->cpi_chipid = cpi->cpi_procnodeid >> 1; 69610947SSrihari.Venkatesan@Sun.COM } 69710947SSrihari.Venkatesan@Sun.COM } 69810947SSrihari.Venkatesan@Sun.COM } else if (cpi->cpi_family >= 0x11) { 69910947SSrihari.Venkatesan@Sun.COM cpi->cpi_procnodeid = (cpi->cpi_apicid >> coreidsz) & 7; 70010947SSrihari.Venkatesan@Sun.COM cpi->cpi_chipid = cpi->cpi_procnodeid; 70110947SSrihari.Venkatesan@Sun.COM } else { 70210947SSrihari.Venkatesan@Sun.COM cpi->cpi_procnodeid = 0; 70310947SSrihari.Venkatesan@Sun.COM cpi->cpi_chipid = cpi->cpi_procnodeid; 70410947SSrihari.Venkatesan@Sun.COM } 70510947SSrihari.Venkatesan@Sun.COM } 70610947SSrihari.Venkatesan@Sun.COM 7070Sstevel@tonic-gate uint_t 7080Sstevel@tonic-gate cpuid_pass1(cpu_t *cpu) 7090Sstevel@tonic-gate { 7100Sstevel@tonic-gate uint32_t mask_ecx, mask_edx; 7110Sstevel@tonic-gate uint_t feature = X86_CPUID; 7120Sstevel@tonic-gate struct cpuid_info *cpi; 7131228Sandrei struct cpuid_regs *cp; 7140Sstevel@tonic-gate int xcpuid; 7155084Sjohnlev #if !defined(__xpv) 7165045Sbholler extern int idle_cpu_prefer_mwait; 7175084Sjohnlev #endif 7183446Smrj 7199482SKuriakose.Kuruvilla@Sun.COM 7209482SKuriakose.Kuruvilla@Sun.COM #if !defined(__xpv) 7219482SKuriakose.Kuruvilla@Sun.COM determine_platform(); 7229482SKuriakose.Kuruvilla@Sun.COM #endif 7230Sstevel@tonic-gate /* 7243446Smrj * Space statically allocated for cpu0, ensure pointer is set 7250Sstevel@tonic-gate */ 7260Sstevel@tonic-gate if (cpu->cpu_id == 0) 7273446Smrj cpu->cpu_m.mcpu_cpi = &cpuid_info0; 7283446Smrj cpi = cpu->cpu_m.mcpu_cpi; 7293446Smrj ASSERT(cpi != NULL); 7300Sstevel@tonic-gate cp = &cpi->cpi_std[0]; 7311228Sandrei cp->cp_eax = 0; 7321228Sandrei cpi->cpi_maxeax = __cpuid_insn(cp); 7330Sstevel@tonic-gate { 7340Sstevel@tonic-gate uint32_t *iptr = (uint32_t *)cpi->cpi_vendorstr; 7350Sstevel@tonic-gate *iptr++ = cp->cp_ebx; 7360Sstevel@tonic-gate *iptr++ = cp->cp_edx; 7370Sstevel@tonic-gate *iptr++ = cp->cp_ecx; 7380Sstevel@tonic-gate *(char *)&cpi->cpi_vendorstr[12] = '\0'; 7390Sstevel@tonic-gate } 7400Sstevel@tonic-gate 7417532SSean.Ye@Sun.COM cpi->cpi_vendor = _cpuid_vendorstr_to_vendorcode(cpi->cpi_vendorstr); 7420Sstevel@tonic-gate x86_vendor = cpi->cpi_vendor; /* for compatibility */ 7430Sstevel@tonic-gate 7440Sstevel@tonic-gate /* 7450Sstevel@tonic-gate * Limit the range in case of weird hardware 7460Sstevel@tonic-gate */ 7470Sstevel@tonic-gate if (cpi->cpi_maxeax > CPI_MAXEAX_MAX) 7480Sstevel@tonic-gate cpi->cpi_maxeax = CPI_MAXEAX_MAX; 7490Sstevel@tonic-gate if (cpi->cpi_maxeax < 1) 7500Sstevel@tonic-gate goto pass1_done; 7510Sstevel@tonic-gate 7520Sstevel@tonic-gate cp = &cpi->cpi_std[1]; 7531228Sandrei cp->cp_eax = 1; 7541228Sandrei (void) __cpuid_insn(cp); 7550Sstevel@tonic-gate 7560Sstevel@tonic-gate /* 7570Sstevel@tonic-gate * Extract identifying constants for easy access. 7580Sstevel@tonic-gate */ 7590Sstevel@tonic-gate cpi->cpi_model = CPI_MODEL(cpi); 7600Sstevel@tonic-gate cpi->cpi_family = CPI_FAMILY(cpi); 7610Sstevel@tonic-gate 7621975Sdmick if (cpi->cpi_family == 0xf) 7630Sstevel@tonic-gate cpi->cpi_family += CPI_FAMILY_XTD(cpi); 7641975Sdmick 7652001Sdmick /* 7664265Skchow * Beware: AMD uses "extended model" iff base *FAMILY* == 0xf. 7672001Sdmick * Intel, and presumably everyone else, uses model == 0xf, as 7682001Sdmick * one would expect (max value means possible overflow). Sigh. 7692001Sdmick */ 7702001Sdmick 7712001Sdmick switch (cpi->cpi_vendor) { 7724855Sksadhukh case X86_VENDOR_Intel: 7734855Sksadhukh if (IS_EXTENDED_MODEL_INTEL(cpi)) 7744855Sksadhukh cpi->cpi_model += CPI_MODEL_XTD(cpi) << 4; 7754858Sksadhukh break; 7762001Sdmick case X86_VENDOR_AMD: 7774265Skchow if (CPI_FAMILY(cpi) == 0xf) 7782001Sdmick cpi->cpi_model += CPI_MODEL_XTD(cpi) << 4; 7792001Sdmick break; 7802001Sdmick default: 7812001Sdmick if (cpi->cpi_model == 0xf) 7822001Sdmick cpi->cpi_model += CPI_MODEL_XTD(cpi) << 4; 7832001Sdmick break; 7842001Sdmick } 7850Sstevel@tonic-gate 7860Sstevel@tonic-gate cpi->cpi_step = CPI_STEP(cpi); 7870Sstevel@tonic-gate cpi->cpi_brandid = CPI_BRANDID(cpi); 7880Sstevel@tonic-gate 7890Sstevel@tonic-gate /* 7900Sstevel@tonic-gate * *default* assumptions: 7910Sstevel@tonic-gate * - believe %edx feature word 7920Sstevel@tonic-gate * - ignore %ecx feature word 7930Sstevel@tonic-gate * - 32-bit virtual and physical addressing 7940Sstevel@tonic-gate */ 7950Sstevel@tonic-gate mask_edx = 0xffffffff; 7960Sstevel@tonic-gate mask_ecx = 0; 7970Sstevel@tonic-gate 7980Sstevel@tonic-gate cpi->cpi_pabits = cpi->cpi_vabits = 32; 7990Sstevel@tonic-gate 8000Sstevel@tonic-gate switch (cpi->cpi_vendor) { 8010Sstevel@tonic-gate case X86_VENDOR_Intel: 8020Sstevel@tonic-gate if (cpi->cpi_family == 5) 8030Sstevel@tonic-gate x86_type = X86_TYPE_P5; 8041975Sdmick else if (IS_LEGACY_P6(cpi)) { 8050Sstevel@tonic-gate x86_type = X86_TYPE_P6; 8060Sstevel@tonic-gate pentiumpro_bug4046376 = 1; 8070Sstevel@tonic-gate pentiumpro_bug4064495 = 1; 8080Sstevel@tonic-gate /* 8090Sstevel@tonic-gate * Clear the SEP bit when it was set erroneously 8100Sstevel@tonic-gate */ 8110Sstevel@tonic-gate if (cpi->cpi_model < 3 && cpi->cpi_step < 3) 8120Sstevel@tonic-gate cp->cp_edx &= ~CPUID_INTC_EDX_SEP; 8131975Sdmick } else if (IS_NEW_F6(cpi) || cpi->cpi_family == 0xf) { 8140Sstevel@tonic-gate x86_type = X86_TYPE_P4; 8150Sstevel@tonic-gate /* 8160Sstevel@tonic-gate * We don't currently depend on any of the %ecx 8170Sstevel@tonic-gate * features until Prescott, so we'll only check 8180Sstevel@tonic-gate * this from P4 onwards. We might want to revisit 8190Sstevel@tonic-gate * that idea later. 8200Sstevel@tonic-gate */ 8210Sstevel@tonic-gate mask_ecx = 0xffffffff; 8220Sstevel@tonic-gate } else if (cpi->cpi_family > 0xf) 8230Sstevel@tonic-gate mask_ecx = 0xffffffff; 8244636Sbholler /* 8254636Sbholler * We don't support MONITOR/MWAIT if leaf 5 is not available 8264636Sbholler * to obtain the monitor linesize. 8274636Sbholler */ 8284636Sbholler if (cpi->cpi_maxeax < 5) 8294636Sbholler mask_ecx &= ~CPUID_INTC_ECX_MON; 8300Sstevel@tonic-gate break; 8310Sstevel@tonic-gate case X86_VENDOR_IntelClone: 8320Sstevel@tonic-gate default: 8330Sstevel@tonic-gate break; 8340Sstevel@tonic-gate case X86_VENDOR_AMD: 8350Sstevel@tonic-gate #if defined(OPTERON_ERRATUM_108) 8360Sstevel@tonic-gate if (cpi->cpi_family == 0xf && cpi->cpi_model == 0xe) { 8370Sstevel@tonic-gate cp->cp_eax = (0xf0f & cp->cp_eax) | 0xc0; 8380Sstevel@tonic-gate cpi->cpi_model = 0xc; 8390Sstevel@tonic-gate } else 8400Sstevel@tonic-gate #endif 8410Sstevel@tonic-gate if (cpi->cpi_family == 5) { 8420Sstevel@tonic-gate /* 8430Sstevel@tonic-gate * AMD K5 and K6 8440Sstevel@tonic-gate * 8450Sstevel@tonic-gate * These CPUs have an incomplete implementation 8460Sstevel@tonic-gate * of MCA/MCE which we mask away. 8470Sstevel@tonic-gate */ 8481228Sandrei mask_edx &= ~(CPUID_INTC_EDX_MCE | CPUID_INTC_EDX_MCA); 8491228Sandrei 8501228Sandrei /* 8511228Sandrei * Model 0 uses the wrong (APIC) bit 8521228Sandrei * to indicate PGE. Fix it here. 8531228Sandrei */ 8540Sstevel@tonic-gate if (cpi->cpi_model == 0) { 8550Sstevel@tonic-gate if (cp->cp_edx & 0x200) { 8560Sstevel@tonic-gate cp->cp_edx &= ~0x200; 8570Sstevel@tonic-gate cp->cp_edx |= CPUID_INTC_EDX_PGE; 8580Sstevel@tonic-gate } 8591228Sandrei } 8601228Sandrei 8611228Sandrei /* 8621228Sandrei * Early models had problems w/ MMX; disable. 8631228Sandrei */ 8641228Sandrei if (cpi->cpi_model < 6) 8651228Sandrei mask_edx &= ~CPUID_INTC_EDX_MMX; 8661228Sandrei } 8671228Sandrei 8681228Sandrei /* 8691228Sandrei * For newer families, SSE3 and CX16, at least, are valid; 8701228Sandrei * enable all 8711228Sandrei */ 8721228Sandrei if (cpi->cpi_family >= 0xf) 873771Sdmick mask_ecx = 0xffffffff; 8744636Sbholler /* 8754636Sbholler * We don't support MONITOR/MWAIT if leaf 5 is not available 8764636Sbholler * to obtain the monitor linesize. 8774636Sbholler */ 8784636Sbholler if (cpi->cpi_maxeax < 5) 8794636Sbholler mask_ecx &= ~CPUID_INTC_ECX_MON; 8805045Sbholler 8815084Sjohnlev #if !defined(__xpv) 8825045Sbholler /* 8835045Sbholler * Do not use MONITOR/MWAIT to halt in the idle loop on any AMD 8845045Sbholler * processors. AMD does not intend MWAIT to be used in the cpu 8855045Sbholler * idle loop on current and future processors. 10h and future 8865045Sbholler * AMD processors use more power in MWAIT than HLT. 8875045Sbholler * Pre-family-10h Opterons do not have the MWAIT instruction. 8885045Sbholler */ 8895045Sbholler idle_cpu_prefer_mwait = 0; 8905084Sjohnlev #endif 8915045Sbholler 8920Sstevel@tonic-gate break; 8930Sstevel@tonic-gate case X86_VENDOR_TM: 8940Sstevel@tonic-gate /* 8950Sstevel@tonic-gate * workaround the NT workaround in CMS 4.1 8960Sstevel@tonic-gate */ 8970Sstevel@tonic-gate if (cpi->cpi_family == 5 && cpi->cpi_model == 4 && 8980Sstevel@tonic-gate (cpi->cpi_step == 2 || cpi->cpi_step == 3)) 8990Sstevel@tonic-gate cp->cp_edx |= CPUID_INTC_EDX_CX8; 9000Sstevel@tonic-gate break; 9010Sstevel@tonic-gate case X86_VENDOR_Centaur: 9020Sstevel@tonic-gate /* 9030Sstevel@tonic-gate * workaround the NT workarounds again 9040Sstevel@tonic-gate */ 9050Sstevel@tonic-gate if (cpi->cpi_family == 6) 9060Sstevel@tonic-gate cp->cp_edx |= CPUID_INTC_EDX_CX8; 9070Sstevel@tonic-gate break; 9080Sstevel@tonic-gate case X86_VENDOR_Cyrix: 9090Sstevel@tonic-gate /* 9100Sstevel@tonic-gate * We rely heavily on the probing in locore 9110Sstevel@tonic-gate * to actually figure out what parts, if any, 9120Sstevel@tonic-gate * of the Cyrix cpuid instruction to believe. 9130Sstevel@tonic-gate */ 9140Sstevel@tonic-gate switch (x86_type) { 9150Sstevel@tonic-gate case X86_TYPE_CYRIX_486: 9160Sstevel@tonic-gate mask_edx = 0; 9170Sstevel@tonic-gate break; 9180Sstevel@tonic-gate case X86_TYPE_CYRIX_6x86: 9190Sstevel@tonic-gate mask_edx = 0; 9200Sstevel@tonic-gate break; 9210Sstevel@tonic-gate case X86_TYPE_CYRIX_6x86L: 9220Sstevel@tonic-gate mask_edx = 9230Sstevel@tonic-gate CPUID_INTC_EDX_DE | 9240Sstevel@tonic-gate CPUID_INTC_EDX_CX8; 9250Sstevel@tonic-gate break; 9260Sstevel@tonic-gate case X86_TYPE_CYRIX_6x86MX: 9270Sstevel@tonic-gate mask_edx = 9280Sstevel@tonic-gate CPUID_INTC_EDX_DE | 9290Sstevel@tonic-gate CPUID_INTC_EDX_MSR | 9300Sstevel@tonic-gate CPUID_INTC_EDX_CX8 | 9310Sstevel@tonic-gate CPUID_INTC_EDX_PGE | 9320Sstevel@tonic-gate CPUID_INTC_EDX_CMOV | 9330Sstevel@tonic-gate CPUID_INTC_EDX_MMX; 9340Sstevel@tonic-gate break; 9350Sstevel@tonic-gate case X86_TYPE_CYRIX_GXm: 9360Sstevel@tonic-gate mask_edx = 9370Sstevel@tonic-gate CPUID_INTC_EDX_MSR | 9380Sstevel@tonic-gate CPUID_INTC_EDX_CX8 | 9390Sstevel@tonic-gate CPUID_INTC_EDX_CMOV | 9400Sstevel@tonic-gate CPUID_INTC_EDX_MMX; 9410Sstevel@tonic-gate break; 9420Sstevel@tonic-gate case X86_TYPE_CYRIX_MediaGX: 9430Sstevel@tonic-gate break; 9440Sstevel@tonic-gate case X86_TYPE_CYRIX_MII: 9450Sstevel@tonic-gate case X86_TYPE_VIA_CYRIX_III: 9460Sstevel@tonic-gate mask_edx = 9470Sstevel@tonic-gate CPUID_INTC_EDX_DE | 9480Sstevel@tonic-gate CPUID_INTC_EDX_TSC | 9490Sstevel@tonic-gate CPUID_INTC_EDX_MSR | 9500Sstevel@tonic-gate CPUID_INTC_EDX_CX8 | 9510Sstevel@tonic-gate CPUID_INTC_EDX_PGE | 9520Sstevel@tonic-gate CPUID_INTC_EDX_CMOV | 9530Sstevel@tonic-gate CPUID_INTC_EDX_MMX; 9540Sstevel@tonic-gate break; 9550Sstevel@tonic-gate default: 9560Sstevel@tonic-gate break; 9570Sstevel@tonic-gate } 9580Sstevel@tonic-gate break; 9590Sstevel@tonic-gate } 9600Sstevel@tonic-gate 9615084Sjohnlev #if defined(__xpv) 9625084Sjohnlev /* 9635084Sjohnlev * Do not support MONITOR/MWAIT under a hypervisor 9645084Sjohnlev */ 9655084Sjohnlev mask_ecx &= ~CPUID_INTC_ECX_MON; 9665084Sjohnlev #endif /* __xpv */ 9675084Sjohnlev 9680Sstevel@tonic-gate /* 9690Sstevel@tonic-gate * Now we've figured out the masks that determine 9700Sstevel@tonic-gate * which bits we choose to believe, apply the masks 9710Sstevel@tonic-gate * to the feature words, then map the kernel's view 9720Sstevel@tonic-gate * of these feature words into its feature word. 9730Sstevel@tonic-gate */ 9740Sstevel@tonic-gate cp->cp_edx &= mask_edx; 9750Sstevel@tonic-gate cp->cp_ecx &= mask_ecx; 9760Sstevel@tonic-gate 9770Sstevel@tonic-gate /* 9783446Smrj * apply any platform restrictions (we don't call this 9793446Smrj * immediately after __cpuid_insn here, because we need the 9803446Smrj * workarounds applied above first) 9810Sstevel@tonic-gate */ 9823446Smrj platform_cpuid_mangle(cpi->cpi_vendor, 1, cp); 9830Sstevel@tonic-gate 9843446Smrj /* 9853446Smrj * fold in overrides from the "eeprom" mechanism 9863446Smrj */ 9870Sstevel@tonic-gate cp->cp_edx |= cpuid_feature_edx_include; 9880Sstevel@tonic-gate cp->cp_edx &= ~cpuid_feature_edx_exclude; 9890Sstevel@tonic-gate 9900Sstevel@tonic-gate cp->cp_ecx |= cpuid_feature_ecx_include; 9910Sstevel@tonic-gate cp->cp_ecx &= ~cpuid_feature_ecx_exclude; 9920Sstevel@tonic-gate 9930Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_PSE) 9940Sstevel@tonic-gate feature |= X86_LARGEPAGE; 9950Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_TSC) 9960Sstevel@tonic-gate feature |= X86_TSC; 9970Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_MSR) 9980Sstevel@tonic-gate feature |= X86_MSR; 9990Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_MTRR) 10000Sstevel@tonic-gate feature |= X86_MTRR; 10010Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_PGE) 10020Sstevel@tonic-gate feature |= X86_PGE; 10030Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_CMOV) 10040Sstevel@tonic-gate feature |= X86_CMOV; 10050Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_MMX) 10060Sstevel@tonic-gate feature |= X86_MMX; 10070Sstevel@tonic-gate if ((cp->cp_edx & CPUID_INTC_EDX_MCE) != 0 && 10080Sstevel@tonic-gate (cp->cp_edx & CPUID_INTC_EDX_MCA) != 0) 10090Sstevel@tonic-gate feature |= X86_MCA; 10100Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_PAE) 10110Sstevel@tonic-gate feature |= X86_PAE; 10120Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_CX8) 10130Sstevel@tonic-gate feature |= X86_CX8; 10140Sstevel@tonic-gate if (cp->cp_ecx & CPUID_INTC_ECX_CX16) 10150Sstevel@tonic-gate feature |= X86_CX16; 10160Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_PAT) 10170Sstevel@tonic-gate feature |= X86_PAT; 10180Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_SEP) 10190Sstevel@tonic-gate feature |= X86_SEP; 10200Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_FXSR) { 10210Sstevel@tonic-gate /* 10220Sstevel@tonic-gate * In our implementation, fxsave/fxrstor 10230Sstevel@tonic-gate * are prerequisites before we'll even 10240Sstevel@tonic-gate * try and do SSE things. 10250Sstevel@tonic-gate */ 10260Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_SSE) 10270Sstevel@tonic-gate feature |= X86_SSE; 10280Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_SSE2) 10290Sstevel@tonic-gate feature |= X86_SSE2; 10300Sstevel@tonic-gate if (cp->cp_ecx & CPUID_INTC_ECX_SSE3) 10310Sstevel@tonic-gate feature |= X86_SSE3; 10325269Skk208521 if (cpi->cpi_vendor == X86_VENDOR_Intel) { 10335269Skk208521 if (cp->cp_ecx & CPUID_INTC_ECX_SSSE3) 10345269Skk208521 feature |= X86_SSSE3; 10355269Skk208521 if (cp->cp_ecx & CPUID_INTC_ECX_SSE4_1) 10365269Skk208521 feature |= X86_SSE4_1; 10375269Skk208521 if (cp->cp_ecx & CPUID_INTC_ECX_SSE4_2) 10385269Skk208521 feature |= X86_SSE4_2; 10399370SKuriakose.Kuruvilla@Sun.COM if (cp->cp_ecx & CPUID_INTC_ECX_AES) 10409370SKuriakose.Kuruvilla@Sun.COM feature |= X86_AES; 10415269Skk208521 } 10420Sstevel@tonic-gate } 10430Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_DE) 10443446Smrj feature |= X86_DE; 10457716SBill.Holler@Sun.COM #if !defined(__xpv) 10464481Sbholler if (cp->cp_ecx & CPUID_INTC_ECX_MON) { 10477716SBill.Holler@Sun.COM 10487716SBill.Holler@Sun.COM /* 10497716SBill.Holler@Sun.COM * We require the CLFLUSH instruction for erratum workaround 10507716SBill.Holler@Sun.COM * to use MONITOR/MWAIT. 10517716SBill.Holler@Sun.COM */ 10527716SBill.Holler@Sun.COM if (cp->cp_edx & CPUID_INTC_EDX_CLFSH) { 10537716SBill.Holler@Sun.COM cpi->cpi_mwait.support |= MWAIT_SUPPORT; 10547716SBill.Holler@Sun.COM feature |= X86_MWAIT; 10557716SBill.Holler@Sun.COM } else { 10567716SBill.Holler@Sun.COM extern int idle_cpu_assert_cflush_monitor; 10577716SBill.Holler@Sun.COM 10587716SBill.Holler@Sun.COM /* 10597716SBill.Holler@Sun.COM * All processors we are aware of which have 10607716SBill.Holler@Sun.COM * MONITOR/MWAIT also have CLFLUSH. 10617716SBill.Holler@Sun.COM */ 10627716SBill.Holler@Sun.COM if (idle_cpu_assert_cflush_monitor) { 10637716SBill.Holler@Sun.COM ASSERT((cp->cp_ecx & CPUID_INTC_ECX_MON) && 10647716SBill.Holler@Sun.COM (cp->cp_edx & CPUID_INTC_EDX_CLFSH)); 10657716SBill.Holler@Sun.COM } 10667716SBill.Holler@Sun.COM } 10674481Sbholler } 10687716SBill.Holler@Sun.COM #endif /* __xpv */ 10690Sstevel@tonic-gate 10707589SVikram.Hegde@Sun.COM /* 10717589SVikram.Hegde@Sun.COM * Only need it first time, rest of the cpus would follow suite. 10727589SVikram.Hegde@Sun.COM * we only capture this for the bootcpu. 10737589SVikram.Hegde@Sun.COM */ 10747589SVikram.Hegde@Sun.COM if (cp->cp_edx & CPUID_INTC_EDX_CLFSH) { 10757589SVikram.Hegde@Sun.COM feature |= X86_CLFSH; 10767589SVikram.Hegde@Sun.COM x86_clflush_size = (BITX(cp->cp_ebx, 15, 8) * 8); 10777589SVikram.Hegde@Sun.COM } 10787589SVikram.Hegde@Sun.COM 10790Sstevel@tonic-gate if (feature & X86_PAE) 10800Sstevel@tonic-gate cpi->cpi_pabits = 36; 10810Sstevel@tonic-gate 10820Sstevel@tonic-gate /* 10830Sstevel@tonic-gate * Hyperthreading configuration is slightly tricky on Intel 10840Sstevel@tonic-gate * and pure clones, and even trickier on AMD. 10850Sstevel@tonic-gate * 10860Sstevel@tonic-gate * (AMD chose to set the HTT bit on their CMP processors, 10870Sstevel@tonic-gate * even though they're not actually hyperthreaded. Thus it 10880Sstevel@tonic-gate * takes a bit more work to figure out what's really going 10893446Smrj * on ... see the handling of the CMP_LGCY bit below) 10900Sstevel@tonic-gate */ 10910Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_HTT) { 10920Sstevel@tonic-gate cpi->cpi_ncpu_per_chip = CPI_CPU_COUNT(cpi); 10930Sstevel@tonic-gate if (cpi->cpi_ncpu_per_chip > 1) 10940Sstevel@tonic-gate feature |= X86_HTT; 10951228Sandrei } else { 10961228Sandrei cpi->cpi_ncpu_per_chip = 1; 10970Sstevel@tonic-gate } 10980Sstevel@tonic-gate 10990Sstevel@tonic-gate /* 11000Sstevel@tonic-gate * Work on the "extended" feature information, doing 11010Sstevel@tonic-gate * some basic initialization for cpuid_pass2() 11020Sstevel@tonic-gate */ 11030Sstevel@tonic-gate xcpuid = 0; 11040Sstevel@tonic-gate switch (cpi->cpi_vendor) { 11050Sstevel@tonic-gate case X86_VENDOR_Intel: 11061975Sdmick if (IS_NEW_F6(cpi) || cpi->cpi_family >= 0xf) 11070Sstevel@tonic-gate xcpuid++; 11080Sstevel@tonic-gate break; 11090Sstevel@tonic-gate case X86_VENDOR_AMD: 11100Sstevel@tonic-gate if (cpi->cpi_family > 5 || 11110Sstevel@tonic-gate (cpi->cpi_family == 5 && cpi->cpi_model >= 1)) 11120Sstevel@tonic-gate xcpuid++; 11130Sstevel@tonic-gate break; 11140Sstevel@tonic-gate case X86_VENDOR_Cyrix: 11150Sstevel@tonic-gate /* 11160Sstevel@tonic-gate * Only these Cyrix CPUs are -known- to support 11170Sstevel@tonic-gate * extended cpuid operations. 11180Sstevel@tonic-gate */ 11190Sstevel@tonic-gate if (x86_type == X86_TYPE_VIA_CYRIX_III || 11200Sstevel@tonic-gate x86_type == X86_TYPE_CYRIX_GXm) 11210Sstevel@tonic-gate xcpuid++; 11220Sstevel@tonic-gate break; 11230Sstevel@tonic-gate case X86_VENDOR_Centaur: 11240Sstevel@tonic-gate case X86_VENDOR_TM: 11250Sstevel@tonic-gate default: 11260Sstevel@tonic-gate xcpuid++; 11270Sstevel@tonic-gate break; 11280Sstevel@tonic-gate } 11290Sstevel@tonic-gate 11300Sstevel@tonic-gate if (xcpuid) { 11310Sstevel@tonic-gate cp = &cpi->cpi_extd[0]; 11321228Sandrei cp->cp_eax = 0x80000000; 11331228Sandrei cpi->cpi_xmaxeax = __cpuid_insn(cp); 11340Sstevel@tonic-gate } 11350Sstevel@tonic-gate 11360Sstevel@tonic-gate if (cpi->cpi_xmaxeax & 0x80000000) { 11370Sstevel@tonic-gate 11380Sstevel@tonic-gate if (cpi->cpi_xmaxeax > CPI_XMAXEAX_MAX) 11390Sstevel@tonic-gate cpi->cpi_xmaxeax = CPI_XMAXEAX_MAX; 11400Sstevel@tonic-gate 11410Sstevel@tonic-gate switch (cpi->cpi_vendor) { 11420Sstevel@tonic-gate case X86_VENDOR_Intel: 11430Sstevel@tonic-gate case X86_VENDOR_AMD: 11440Sstevel@tonic-gate if (cpi->cpi_xmaxeax < 0x80000001) 11450Sstevel@tonic-gate break; 11460Sstevel@tonic-gate cp = &cpi->cpi_extd[1]; 11471228Sandrei cp->cp_eax = 0x80000001; 11481228Sandrei (void) __cpuid_insn(cp); 11493446Smrj 11500Sstevel@tonic-gate if (cpi->cpi_vendor == X86_VENDOR_AMD && 11510Sstevel@tonic-gate cpi->cpi_family == 5 && 11520Sstevel@tonic-gate cpi->cpi_model == 6 && 11530Sstevel@tonic-gate cpi->cpi_step == 6) { 11540Sstevel@tonic-gate /* 11550Sstevel@tonic-gate * K6 model 6 uses bit 10 to indicate SYSC 11560Sstevel@tonic-gate * Later models use bit 11. Fix it here. 11570Sstevel@tonic-gate */ 11580Sstevel@tonic-gate if (cp->cp_edx & 0x400) { 11590Sstevel@tonic-gate cp->cp_edx &= ~0x400; 11600Sstevel@tonic-gate cp->cp_edx |= CPUID_AMD_EDX_SYSC; 11610Sstevel@tonic-gate } 11620Sstevel@tonic-gate } 11630Sstevel@tonic-gate 11643446Smrj platform_cpuid_mangle(cpi->cpi_vendor, 0x80000001, cp); 11653446Smrj 11660Sstevel@tonic-gate /* 11670Sstevel@tonic-gate * Compute the additions to the kernel's feature word. 11680Sstevel@tonic-gate */ 11690Sstevel@tonic-gate if (cp->cp_edx & CPUID_AMD_EDX_NX) 11700Sstevel@tonic-gate feature |= X86_NX; 11710Sstevel@tonic-gate 11727656SSherry.Moore@Sun.COM /* 11737656SSherry.Moore@Sun.COM * Regardless whether or not we boot 64-bit, 11747656SSherry.Moore@Sun.COM * we should have a way to identify whether 11757656SSherry.Moore@Sun.COM * the CPU is capable of running 64-bit. 11767656SSherry.Moore@Sun.COM */ 11777656SSherry.Moore@Sun.COM if (cp->cp_edx & CPUID_AMD_EDX_LM) 11787656SSherry.Moore@Sun.COM feature |= X86_64; 11797656SSherry.Moore@Sun.COM 11805349Skchow #if defined(__amd64) 11815349Skchow /* 1 GB large page - enable only for 64 bit kernel */ 11825349Skchow if (cp->cp_edx & CPUID_AMD_EDX_1GPG) 11835349Skchow feature |= X86_1GPG; 11845349Skchow #endif 11855349Skchow 11864628Skk208521 if ((cpi->cpi_vendor == X86_VENDOR_AMD) && 11874628Skk208521 (cpi->cpi_std[1].cp_edx & CPUID_INTC_EDX_FXSR) && 11884628Skk208521 (cp->cp_ecx & CPUID_AMD_ECX_SSE4A)) 11894628Skk208521 feature |= X86_SSE4A; 11904628Skk208521 11910Sstevel@tonic-gate /* 11923446Smrj * If both the HTT and CMP_LGCY bits are set, 11931228Sandrei * then we're not actually HyperThreaded. Read 11941228Sandrei * "AMD CPUID Specification" for more details. 11950Sstevel@tonic-gate */ 11960Sstevel@tonic-gate if (cpi->cpi_vendor == X86_VENDOR_AMD && 11971228Sandrei (feature & X86_HTT) && 11983446Smrj (cp->cp_ecx & CPUID_AMD_ECX_CMP_LGCY)) { 11990Sstevel@tonic-gate feature &= ~X86_HTT; 12001228Sandrei feature |= X86_CMP; 12011228Sandrei } 12023446Smrj #if defined(__amd64) 12030Sstevel@tonic-gate /* 12040Sstevel@tonic-gate * It's really tricky to support syscall/sysret in 12050Sstevel@tonic-gate * the i386 kernel; we rely on sysenter/sysexit 12060Sstevel@tonic-gate * instead. In the amd64 kernel, things are -way- 12070Sstevel@tonic-gate * better. 12080Sstevel@tonic-gate */ 12090Sstevel@tonic-gate if (cp->cp_edx & CPUID_AMD_EDX_SYSC) 12100Sstevel@tonic-gate feature |= X86_ASYSC; 12110Sstevel@tonic-gate 12120Sstevel@tonic-gate /* 12130Sstevel@tonic-gate * While we're thinking about system calls, note 12140Sstevel@tonic-gate * that AMD processors don't support sysenter 12150Sstevel@tonic-gate * in long mode at all, so don't try to program them. 12160Sstevel@tonic-gate */ 12170Sstevel@tonic-gate if (x86_vendor == X86_VENDOR_AMD) 12180Sstevel@tonic-gate feature &= ~X86_SEP; 12190Sstevel@tonic-gate #endif 12206657Ssudheer if (cp->cp_edx & CPUID_AMD_EDX_TSCP) 12213446Smrj feature |= X86_TSCP; 12220Sstevel@tonic-gate break; 12230Sstevel@tonic-gate default: 12240Sstevel@tonic-gate break; 12250Sstevel@tonic-gate } 12260Sstevel@tonic-gate 12271228Sandrei /* 12281228Sandrei * Get CPUID data about processor cores and hyperthreads. 12291228Sandrei */ 12300Sstevel@tonic-gate switch (cpi->cpi_vendor) { 12310Sstevel@tonic-gate case X86_VENDOR_Intel: 12321228Sandrei if (cpi->cpi_maxeax >= 4) { 12331228Sandrei cp = &cpi->cpi_std[4]; 12341228Sandrei cp->cp_eax = 4; 12351228Sandrei cp->cp_ecx = 0; 12361228Sandrei (void) __cpuid_insn(cp); 12373446Smrj platform_cpuid_mangle(cpi->cpi_vendor, 4, cp); 12381228Sandrei } 12391228Sandrei /*FALLTHROUGH*/ 12400Sstevel@tonic-gate case X86_VENDOR_AMD: 12410Sstevel@tonic-gate if (cpi->cpi_xmaxeax < 0x80000008) 12420Sstevel@tonic-gate break; 12430Sstevel@tonic-gate cp = &cpi->cpi_extd[8]; 12441228Sandrei cp->cp_eax = 0x80000008; 12451228Sandrei (void) __cpuid_insn(cp); 12463446Smrj platform_cpuid_mangle(cpi->cpi_vendor, 0x80000008, cp); 12473446Smrj 12480Sstevel@tonic-gate /* 12490Sstevel@tonic-gate * Virtual and physical address limits from 12500Sstevel@tonic-gate * cpuid override previously guessed values. 12510Sstevel@tonic-gate */ 12520Sstevel@tonic-gate cpi->cpi_pabits = BITX(cp->cp_eax, 7, 0); 12530Sstevel@tonic-gate cpi->cpi_vabits = BITX(cp->cp_eax, 15, 8); 12540Sstevel@tonic-gate break; 12550Sstevel@tonic-gate default: 12560Sstevel@tonic-gate break; 12570Sstevel@tonic-gate } 12581228Sandrei 12594606Sesaxe /* 12604606Sesaxe * Derive the number of cores per chip 12614606Sesaxe */ 12621228Sandrei switch (cpi->cpi_vendor) { 12631228Sandrei case X86_VENDOR_Intel: 12641228Sandrei if (cpi->cpi_maxeax < 4) { 12651228Sandrei cpi->cpi_ncore_per_chip = 1; 12661228Sandrei break; 12671228Sandrei } else { 12681228Sandrei cpi->cpi_ncore_per_chip = 12691228Sandrei BITX((cpi)->cpi_std[4].cp_eax, 31, 26) + 1; 12701228Sandrei } 12711228Sandrei break; 12721228Sandrei case X86_VENDOR_AMD: 12731228Sandrei if (cpi->cpi_xmaxeax < 0x80000008) { 12741228Sandrei cpi->cpi_ncore_per_chip = 1; 12751228Sandrei break; 12761228Sandrei } else { 12775870Sgavinm /* 12785870Sgavinm * On family 0xf cpuid fn 2 ECX[7:0] "NC" is 12795870Sgavinm * 1 less than the number of physical cores on 12805870Sgavinm * the chip. In family 0x10 this value can 12815870Sgavinm * be affected by "downcoring" - it reflects 12825870Sgavinm * 1 less than the number of cores actually 12835870Sgavinm * enabled on this node. 12845870Sgavinm */ 12851228Sandrei cpi->cpi_ncore_per_chip = 12861228Sandrei BITX((cpi)->cpi_extd[8].cp_ecx, 7, 0) + 1; 12871228Sandrei } 12881228Sandrei break; 12891228Sandrei default: 12901228Sandrei cpi->cpi_ncore_per_chip = 1; 12911228Sandrei break; 12921228Sandrei } 12938906SEric.Saxe@Sun.COM 12948906SEric.Saxe@Sun.COM /* 12958906SEric.Saxe@Sun.COM * Get CPUID data about TSC Invariance in Deep C-State. 12968906SEric.Saxe@Sun.COM */ 12978906SEric.Saxe@Sun.COM switch (cpi->cpi_vendor) { 12988906SEric.Saxe@Sun.COM case X86_VENDOR_Intel: 12998906SEric.Saxe@Sun.COM if (cpi->cpi_maxeax >= 7) { 13008906SEric.Saxe@Sun.COM cp = &cpi->cpi_extd[7]; 13018906SEric.Saxe@Sun.COM cp->cp_eax = 0x80000007; 13028906SEric.Saxe@Sun.COM cp->cp_ecx = 0; 13038906SEric.Saxe@Sun.COM (void) __cpuid_insn(cp); 13048906SEric.Saxe@Sun.COM } 13058906SEric.Saxe@Sun.COM break; 13068906SEric.Saxe@Sun.COM default: 13078906SEric.Saxe@Sun.COM break; 13088906SEric.Saxe@Sun.COM } 13095284Sgavinm } else { 13105284Sgavinm cpi->cpi_ncore_per_chip = 1; 13110Sstevel@tonic-gate } 13120Sstevel@tonic-gate 13131228Sandrei /* 13141228Sandrei * If more than one core, then this processor is CMP. 13151228Sandrei */ 13161228Sandrei if (cpi->cpi_ncore_per_chip > 1) 13171228Sandrei feature |= X86_CMP; 13183446Smrj 13191228Sandrei /* 13201228Sandrei * If the number of cores is the same as the number 13211228Sandrei * of CPUs, then we cannot have HyperThreading. 13221228Sandrei */ 13231228Sandrei if (cpi->cpi_ncpu_per_chip == cpi->cpi_ncore_per_chip) 13241228Sandrei feature &= ~X86_HTT; 13251228Sandrei 132610947SSrihari.Venkatesan@Sun.COM cpi->cpi_apicid = CPI_APIC_ID(cpi); 132710947SSrihari.Venkatesan@Sun.COM cpi->cpi_procnodes_per_pkg = 1; 132810947SSrihari.Venkatesan@Sun.COM 13290Sstevel@tonic-gate if ((feature & (X86_HTT | X86_CMP)) == 0) { 13301228Sandrei /* 13311228Sandrei * Single-core single-threaded processors. 13321228Sandrei */ 13330Sstevel@tonic-gate cpi->cpi_chipid = -1; 13340Sstevel@tonic-gate cpi->cpi_clogid = 0; 13351228Sandrei cpi->cpi_coreid = cpu->cpu_id; 13365870Sgavinm cpi->cpi_pkgcoreid = 0; 133710947SSrihari.Venkatesan@Sun.COM if (cpi->cpi_vendor == X86_VENDOR_AMD) 133810947SSrihari.Venkatesan@Sun.COM cpi->cpi_procnodeid = BITX(cpi->cpi_apicid, 3, 0); 133910947SSrihari.Venkatesan@Sun.COM else 134010947SSrihari.Venkatesan@Sun.COM cpi->cpi_procnodeid = cpi->cpi_chipid; 13410Sstevel@tonic-gate } else if (cpi->cpi_ncpu_per_chip > 1) { 134210947SSrihari.Venkatesan@Sun.COM if (cpi->cpi_vendor == X86_VENDOR_Intel) 134310947SSrihari.Venkatesan@Sun.COM cpuid_intel_getids(cpu, feature); 134410947SSrihari.Venkatesan@Sun.COM else if (cpi->cpi_vendor == X86_VENDOR_AMD) 134510947SSrihari.Venkatesan@Sun.COM cpuid_amd_getids(cpu); 134610947SSrihari.Venkatesan@Sun.COM else { 13471228Sandrei /* 13481228Sandrei * All other processors are currently 13491228Sandrei * assumed to have single cores. 13501228Sandrei */ 13511228Sandrei cpi->cpi_coreid = cpi->cpi_chipid; 13525870Sgavinm cpi->cpi_pkgcoreid = 0; 135310947SSrihari.Venkatesan@Sun.COM cpi->cpi_procnodeid = cpi->cpi_chipid; 13541228Sandrei } 13550Sstevel@tonic-gate } 13560Sstevel@tonic-gate 13572869Sgavinm /* 13582869Sgavinm * Synthesize chip "revision" and socket type 13592869Sgavinm */ 13607532SSean.Ye@Sun.COM cpi->cpi_chiprev = _cpuid_chiprev(cpi->cpi_vendor, cpi->cpi_family, 13617532SSean.Ye@Sun.COM cpi->cpi_model, cpi->cpi_step); 13627532SSean.Ye@Sun.COM cpi->cpi_chiprevstr = _cpuid_chiprevstr(cpi->cpi_vendor, 13637532SSean.Ye@Sun.COM cpi->cpi_family, cpi->cpi_model, cpi->cpi_step); 13647532SSean.Ye@Sun.COM cpi->cpi_socket = _cpuid_skt(cpi->cpi_vendor, cpi->cpi_family, 13657532SSean.Ye@Sun.COM cpi->cpi_model, cpi->cpi_step); 13662869Sgavinm 13670Sstevel@tonic-gate pass1_done: 13680Sstevel@tonic-gate cpi->cpi_pass = 1; 13690Sstevel@tonic-gate return (feature); 13700Sstevel@tonic-gate } 13710Sstevel@tonic-gate 13720Sstevel@tonic-gate /* 13730Sstevel@tonic-gate * Make copies of the cpuid table entries we depend on, in 13740Sstevel@tonic-gate * part for ease of parsing now, in part so that we have only 13750Sstevel@tonic-gate * one place to correct any of it, in part for ease of 13760Sstevel@tonic-gate * later export to userland, and in part so we can look at 13770Sstevel@tonic-gate * this stuff in a crash dump. 13780Sstevel@tonic-gate */ 13790Sstevel@tonic-gate 13800Sstevel@tonic-gate /*ARGSUSED*/ 13810Sstevel@tonic-gate void 13820Sstevel@tonic-gate cpuid_pass2(cpu_t *cpu) 13830Sstevel@tonic-gate { 13840Sstevel@tonic-gate uint_t n, nmax; 13850Sstevel@tonic-gate int i; 13861228Sandrei struct cpuid_regs *cp; 13870Sstevel@tonic-gate uint8_t *dp; 13880Sstevel@tonic-gate uint32_t *iptr; 13890Sstevel@tonic-gate struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 13900Sstevel@tonic-gate 13910Sstevel@tonic-gate ASSERT(cpi->cpi_pass == 1); 13920Sstevel@tonic-gate 13930Sstevel@tonic-gate if (cpi->cpi_maxeax < 1) 13940Sstevel@tonic-gate goto pass2_done; 13950Sstevel@tonic-gate 13960Sstevel@tonic-gate if ((nmax = cpi->cpi_maxeax + 1) > NMAX_CPI_STD) 13970Sstevel@tonic-gate nmax = NMAX_CPI_STD; 13980Sstevel@tonic-gate /* 13990Sstevel@tonic-gate * (We already handled n == 0 and n == 1 in pass 1) 14000Sstevel@tonic-gate */ 14010Sstevel@tonic-gate for (n = 2, cp = &cpi->cpi_std[2]; n < nmax; n++, cp++) { 14021228Sandrei cp->cp_eax = n; 14034606Sesaxe 14044606Sesaxe /* 14054606Sesaxe * CPUID function 4 expects %ecx to be initialized 14064606Sesaxe * with an index which indicates which cache to return 14074606Sesaxe * information about. The OS is expected to call function 4 14084606Sesaxe * with %ecx set to 0, 1, 2, ... until it returns with 14094606Sesaxe * EAX[4:0] set to 0, which indicates there are no more 14104606Sesaxe * caches. 14114606Sesaxe * 14124606Sesaxe * Here, populate cpi_std[4] with the information returned by 14134606Sesaxe * function 4 when %ecx == 0, and do the rest in cpuid_pass3() 14144606Sesaxe * when dynamic memory allocation becomes available. 14154606Sesaxe * 14164606Sesaxe * Note: we need to explicitly initialize %ecx here, since 14174606Sesaxe * function 4 may have been previously invoked. 14184606Sesaxe */ 14194606Sesaxe if (n == 4) 14204606Sesaxe cp->cp_ecx = 0; 14214606Sesaxe 14221228Sandrei (void) __cpuid_insn(cp); 14233446Smrj platform_cpuid_mangle(cpi->cpi_vendor, n, cp); 14240Sstevel@tonic-gate switch (n) { 14250Sstevel@tonic-gate case 2: 14260Sstevel@tonic-gate /* 14270Sstevel@tonic-gate * "the lower 8 bits of the %eax register 14280Sstevel@tonic-gate * contain a value that identifies the number 14290Sstevel@tonic-gate * of times the cpuid [instruction] has to be 14300Sstevel@tonic-gate * executed to obtain a complete image of the 14310Sstevel@tonic-gate * processor's caching systems." 14320Sstevel@tonic-gate * 14330Sstevel@tonic-gate * How *do* they make this stuff up? 14340Sstevel@tonic-gate */ 14350Sstevel@tonic-gate cpi->cpi_ncache = sizeof (*cp) * 14360Sstevel@tonic-gate BITX(cp->cp_eax, 7, 0); 14370Sstevel@tonic-gate if (cpi->cpi_ncache == 0) 14380Sstevel@tonic-gate break; 14390Sstevel@tonic-gate cpi->cpi_ncache--; /* skip count byte */ 14400Sstevel@tonic-gate 14410Sstevel@tonic-gate /* 14420Sstevel@tonic-gate * Well, for now, rather than attempt to implement 14430Sstevel@tonic-gate * this slightly dubious algorithm, we just look 14440Sstevel@tonic-gate * at the first 15 .. 14450Sstevel@tonic-gate */ 14460Sstevel@tonic-gate if (cpi->cpi_ncache > (sizeof (*cp) - 1)) 14470Sstevel@tonic-gate cpi->cpi_ncache = sizeof (*cp) - 1; 14480Sstevel@tonic-gate 14490Sstevel@tonic-gate dp = cpi->cpi_cacheinfo; 14500Sstevel@tonic-gate if (BITX(cp->cp_eax, 31, 31) == 0) { 14510Sstevel@tonic-gate uint8_t *p = (void *)&cp->cp_eax; 14526317Skk208521 for (i = 1; i < 4; i++) 14530Sstevel@tonic-gate if (p[i] != 0) 14540Sstevel@tonic-gate *dp++ = p[i]; 14550Sstevel@tonic-gate } 14560Sstevel@tonic-gate if (BITX(cp->cp_ebx, 31, 31) == 0) { 14570Sstevel@tonic-gate uint8_t *p = (void *)&cp->cp_ebx; 14580Sstevel@tonic-gate for (i = 0; i < 4; i++) 14590Sstevel@tonic-gate if (p[i] != 0) 14600Sstevel@tonic-gate *dp++ = p[i]; 14610Sstevel@tonic-gate } 14620Sstevel@tonic-gate if (BITX(cp->cp_ecx, 31, 31) == 0) { 14630Sstevel@tonic-gate uint8_t *p = (void *)&cp->cp_ecx; 14640Sstevel@tonic-gate for (i = 0; i < 4; i++) 14650Sstevel@tonic-gate if (p[i] != 0) 14660Sstevel@tonic-gate *dp++ = p[i]; 14670Sstevel@tonic-gate } 14680Sstevel@tonic-gate if (BITX(cp->cp_edx, 31, 31) == 0) { 14690Sstevel@tonic-gate uint8_t *p = (void *)&cp->cp_edx; 14700Sstevel@tonic-gate for (i = 0; i < 4; i++) 14710Sstevel@tonic-gate if (p[i] != 0) 14720Sstevel@tonic-gate *dp++ = p[i]; 14730Sstevel@tonic-gate } 14740Sstevel@tonic-gate break; 14754481Sbholler 14760Sstevel@tonic-gate case 3: /* Processor serial number, if PSN supported */ 14774481Sbholler break; 14784481Sbholler 14790Sstevel@tonic-gate case 4: /* Deterministic cache parameters */ 14804481Sbholler break; 14814481Sbholler 14820Sstevel@tonic-gate case 5: /* Monitor/Mwait parameters */ 14835045Sbholler { 14845045Sbholler size_t mwait_size; 14854481Sbholler 14864481Sbholler /* 14874481Sbholler * check cpi_mwait.support which was set in cpuid_pass1 14884481Sbholler */ 14894481Sbholler if (!(cpi->cpi_mwait.support & MWAIT_SUPPORT)) 14904481Sbholler break; 14914481Sbholler 14925045Sbholler /* 14935045Sbholler * Protect ourself from insane mwait line size. 14945045Sbholler * Workaround for incomplete hardware emulator(s). 14955045Sbholler */ 14965045Sbholler mwait_size = (size_t)MWAIT_SIZE_MAX(cpi); 14975045Sbholler if (mwait_size < sizeof (uint32_t) || 14985045Sbholler !ISP2(mwait_size)) { 14995045Sbholler #if DEBUG 15005045Sbholler cmn_err(CE_NOTE, "Cannot handle cpu %d mwait " 15017798SSaurabh.Mishra@Sun.COM "size %ld", cpu->cpu_id, (long)mwait_size); 15025045Sbholler #endif 15035045Sbholler break; 15045045Sbholler } 15055045Sbholler 15064481Sbholler cpi->cpi_mwait.mon_min = (size_t)MWAIT_SIZE_MIN(cpi); 15075045Sbholler cpi->cpi_mwait.mon_max = mwait_size; 15084481Sbholler if (MWAIT_EXTENSION(cpi)) { 15094481Sbholler cpi->cpi_mwait.support |= MWAIT_EXTENSIONS; 15104481Sbholler if (MWAIT_INT_ENABLE(cpi)) 15114481Sbholler cpi->cpi_mwait.support |= 15124481Sbholler MWAIT_ECX_INT_ENABLE; 15134481Sbholler } 15144481Sbholler break; 15155045Sbholler } 15160Sstevel@tonic-gate default: 15170Sstevel@tonic-gate break; 15180Sstevel@tonic-gate } 15190Sstevel@tonic-gate } 15200Sstevel@tonic-gate 15217282Smishra if (cpi->cpi_maxeax >= 0xB && cpi->cpi_vendor == X86_VENDOR_Intel) { 15227798SSaurabh.Mishra@Sun.COM struct cpuid_regs regs; 15237798SSaurabh.Mishra@Sun.COM 15247798SSaurabh.Mishra@Sun.COM cp = ®s; 15257282Smishra cp->cp_eax = 0xB; 15267798SSaurabh.Mishra@Sun.COM cp->cp_edx = cp->cp_ebx = cp->cp_ecx = 0; 15277282Smishra 15287282Smishra (void) __cpuid_insn(cp); 15297282Smishra 15307282Smishra /* 15317282Smishra * Check CPUID.EAX=0BH, ECX=0H:EBX is non-zero, which 15327282Smishra * indicates that the extended topology enumeration leaf is 15337282Smishra * available. 15347282Smishra */ 15357282Smishra if (cp->cp_ebx) { 15367282Smishra uint32_t x2apic_id; 15377282Smishra uint_t coreid_shift = 0; 15387282Smishra uint_t ncpu_per_core = 1; 15397282Smishra uint_t chipid_shift = 0; 15407282Smishra uint_t ncpu_per_chip = 1; 15417282Smishra uint_t i; 15427282Smishra uint_t level; 15437282Smishra 15447282Smishra for (i = 0; i < CPI_FNB_ECX_MAX; i++) { 15457282Smishra cp->cp_eax = 0xB; 15467282Smishra cp->cp_ecx = i; 15477282Smishra 15487282Smishra (void) __cpuid_insn(cp); 15497282Smishra level = CPI_CPU_LEVEL_TYPE(cp); 15507282Smishra 15517282Smishra if (level == 1) { 15527282Smishra x2apic_id = cp->cp_edx; 15537282Smishra coreid_shift = BITX(cp->cp_eax, 4, 0); 15547282Smishra ncpu_per_core = BITX(cp->cp_ebx, 15, 0); 15557282Smishra } else if (level == 2) { 15567282Smishra x2apic_id = cp->cp_edx; 15577282Smishra chipid_shift = BITX(cp->cp_eax, 4, 0); 15587282Smishra ncpu_per_chip = BITX(cp->cp_ebx, 15, 0); 15597282Smishra } 15607282Smishra } 15617282Smishra 15627282Smishra cpi->cpi_apicid = x2apic_id; 15637282Smishra cpi->cpi_ncpu_per_chip = ncpu_per_chip; 15647282Smishra cpi->cpi_ncore_per_chip = ncpu_per_chip / 15657282Smishra ncpu_per_core; 15667282Smishra cpi->cpi_chipid = x2apic_id >> chipid_shift; 15677282Smishra cpi->cpi_clogid = x2apic_id & ((1 << chipid_shift) - 1); 15687282Smishra cpi->cpi_coreid = x2apic_id >> coreid_shift; 15697282Smishra cpi->cpi_pkgcoreid = cpi->cpi_clogid >> coreid_shift; 15707282Smishra } 15717798SSaurabh.Mishra@Sun.COM 15727798SSaurabh.Mishra@Sun.COM /* Make cp NULL so that we don't stumble on others */ 15737798SSaurabh.Mishra@Sun.COM cp = NULL; 15747282Smishra } 15757282Smishra 15760Sstevel@tonic-gate if ((cpi->cpi_xmaxeax & 0x80000000) == 0) 15770Sstevel@tonic-gate goto pass2_done; 15780Sstevel@tonic-gate 15790Sstevel@tonic-gate if ((nmax = cpi->cpi_xmaxeax - 0x80000000 + 1) > NMAX_CPI_EXTD) 15800Sstevel@tonic-gate nmax = NMAX_CPI_EXTD; 15810Sstevel@tonic-gate /* 15820Sstevel@tonic-gate * Copy the extended properties, fixing them as we go. 15830Sstevel@tonic-gate * (We already handled n == 0 and n == 1 in pass 1) 15840Sstevel@tonic-gate */ 15850Sstevel@tonic-gate iptr = (void *)cpi->cpi_brandstr; 15860Sstevel@tonic-gate for (n = 2, cp = &cpi->cpi_extd[2]; n < nmax; cp++, n++) { 15871228Sandrei cp->cp_eax = 0x80000000 + n; 15881228Sandrei (void) __cpuid_insn(cp); 15893446Smrj platform_cpuid_mangle(cpi->cpi_vendor, 0x80000000 + n, cp); 15900Sstevel@tonic-gate switch (n) { 15910Sstevel@tonic-gate case 2: 15920Sstevel@tonic-gate case 3: 15930Sstevel@tonic-gate case 4: 15940Sstevel@tonic-gate /* 15950Sstevel@tonic-gate * Extract the brand string 15960Sstevel@tonic-gate */ 15970Sstevel@tonic-gate *iptr++ = cp->cp_eax; 15980Sstevel@tonic-gate *iptr++ = cp->cp_ebx; 15990Sstevel@tonic-gate *iptr++ = cp->cp_ecx; 16000Sstevel@tonic-gate *iptr++ = cp->cp_edx; 16010Sstevel@tonic-gate break; 16020Sstevel@tonic-gate case 5: 16030Sstevel@tonic-gate switch (cpi->cpi_vendor) { 16040Sstevel@tonic-gate case X86_VENDOR_AMD: 16050Sstevel@tonic-gate /* 16060Sstevel@tonic-gate * The Athlon and Duron were the first 16070Sstevel@tonic-gate * parts to report the sizes of the 16080Sstevel@tonic-gate * TLB for large pages. Before then, 16090Sstevel@tonic-gate * we don't trust the data. 16100Sstevel@tonic-gate */ 16110Sstevel@tonic-gate if (cpi->cpi_family < 6 || 16120Sstevel@tonic-gate (cpi->cpi_family == 6 && 16130Sstevel@tonic-gate cpi->cpi_model < 1)) 16140Sstevel@tonic-gate cp->cp_eax = 0; 16150Sstevel@tonic-gate break; 16160Sstevel@tonic-gate default: 16170Sstevel@tonic-gate break; 16180Sstevel@tonic-gate } 16190Sstevel@tonic-gate break; 16200Sstevel@tonic-gate case 6: 16210Sstevel@tonic-gate switch (cpi->cpi_vendor) { 16220Sstevel@tonic-gate case X86_VENDOR_AMD: 16230Sstevel@tonic-gate /* 16240Sstevel@tonic-gate * The Athlon and Duron were the first 16250Sstevel@tonic-gate * AMD parts with L2 TLB's. 16260Sstevel@tonic-gate * Before then, don't trust the data. 16270Sstevel@tonic-gate */ 16280Sstevel@tonic-gate if (cpi->cpi_family < 6 || 16290Sstevel@tonic-gate cpi->cpi_family == 6 && 16300Sstevel@tonic-gate cpi->cpi_model < 1) 16310Sstevel@tonic-gate cp->cp_eax = cp->cp_ebx = 0; 16320Sstevel@tonic-gate /* 16330Sstevel@tonic-gate * AMD Duron rev A0 reports L2 16340Sstevel@tonic-gate * cache size incorrectly as 1K 16350Sstevel@tonic-gate * when it is really 64K 16360Sstevel@tonic-gate */ 16370Sstevel@tonic-gate if (cpi->cpi_family == 6 && 16380Sstevel@tonic-gate cpi->cpi_model == 3 && 16390Sstevel@tonic-gate cpi->cpi_step == 0) { 16400Sstevel@tonic-gate cp->cp_ecx &= 0xffff; 16410Sstevel@tonic-gate cp->cp_ecx |= 0x400000; 16420Sstevel@tonic-gate } 16430Sstevel@tonic-gate break; 16440Sstevel@tonic-gate case X86_VENDOR_Cyrix: /* VIA C3 */ 16450Sstevel@tonic-gate /* 16460Sstevel@tonic-gate * VIA C3 processors are a bit messed 16470Sstevel@tonic-gate * up w.r.t. encoding cache sizes in %ecx 16480Sstevel@tonic-gate */ 16490Sstevel@tonic-gate if (cpi->cpi_family != 6) 16500Sstevel@tonic-gate break; 16510Sstevel@tonic-gate /* 16520Sstevel@tonic-gate * model 7 and 8 were incorrectly encoded 16530Sstevel@tonic-gate * 16540Sstevel@tonic-gate * xxx is model 8 really broken? 16550Sstevel@tonic-gate */ 16560Sstevel@tonic-gate if (cpi->cpi_model == 7 || 16570Sstevel@tonic-gate cpi->cpi_model == 8) 16580Sstevel@tonic-gate cp->cp_ecx = 16590Sstevel@tonic-gate BITX(cp->cp_ecx, 31, 24) << 16 | 16600Sstevel@tonic-gate BITX(cp->cp_ecx, 23, 16) << 12 | 16610Sstevel@tonic-gate BITX(cp->cp_ecx, 15, 8) << 8 | 16620Sstevel@tonic-gate BITX(cp->cp_ecx, 7, 0); 16630Sstevel@tonic-gate /* 16640Sstevel@tonic-gate * model 9 stepping 1 has wrong associativity 16650Sstevel@tonic-gate */ 16660Sstevel@tonic-gate if (cpi->cpi_model == 9 && cpi->cpi_step == 1) 16670Sstevel@tonic-gate cp->cp_ecx |= 8 << 12; 16680Sstevel@tonic-gate break; 16690Sstevel@tonic-gate case X86_VENDOR_Intel: 16700Sstevel@tonic-gate /* 16710Sstevel@tonic-gate * Extended L2 Cache features function. 16720Sstevel@tonic-gate * First appeared on Prescott. 16730Sstevel@tonic-gate */ 16740Sstevel@tonic-gate default: 16750Sstevel@tonic-gate break; 16760Sstevel@tonic-gate } 16770Sstevel@tonic-gate break; 16780Sstevel@tonic-gate default: 16790Sstevel@tonic-gate break; 16800Sstevel@tonic-gate } 16810Sstevel@tonic-gate } 16820Sstevel@tonic-gate 16830Sstevel@tonic-gate pass2_done: 16840Sstevel@tonic-gate cpi->cpi_pass = 2; 16850Sstevel@tonic-gate } 16860Sstevel@tonic-gate 16870Sstevel@tonic-gate static const char * 16880Sstevel@tonic-gate intel_cpubrand(const struct cpuid_info *cpi) 16890Sstevel@tonic-gate { 16900Sstevel@tonic-gate int i; 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"); 16950Sstevel@tonic-gate 16960Sstevel@tonic-gate switch (cpi->cpi_family) { 16970Sstevel@tonic-gate case 5: 16980Sstevel@tonic-gate return ("Intel Pentium(r)"); 16990Sstevel@tonic-gate case 6: 17000Sstevel@tonic-gate switch (cpi->cpi_model) { 17010Sstevel@tonic-gate uint_t celeron, xeon; 17021228Sandrei const struct cpuid_regs *cp; 17030Sstevel@tonic-gate case 0: 17040Sstevel@tonic-gate case 1: 17050Sstevel@tonic-gate case 2: 17060Sstevel@tonic-gate return ("Intel Pentium(r) Pro"); 17070Sstevel@tonic-gate case 3: 17080Sstevel@tonic-gate case 4: 17090Sstevel@tonic-gate return ("Intel Pentium(r) II"); 17100Sstevel@tonic-gate case 6: 17110Sstevel@tonic-gate return ("Intel Celeron(r)"); 17120Sstevel@tonic-gate case 5: 17130Sstevel@tonic-gate case 7: 17140Sstevel@tonic-gate celeron = xeon = 0; 17150Sstevel@tonic-gate cp = &cpi->cpi_std[2]; /* cache info */ 17160Sstevel@tonic-gate 17176317Skk208521 for (i = 1; i < 4; i++) { 17180Sstevel@tonic-gate uint_t tmp; 17190Sstevel@tonic-gate 17200Sstevel@tonic-gate tmp = (cp->cp_eax >> (8 * i)) & 0xff; 17210Sstevel@tonic-gate if (tmp == 0x40) 17220Sstevel@tonic-gate celeron++; 17230Sstevel@tonic-gate if (tmp >= 0x44 && tmp <= 0x45) 17240Sstevel@tonic-gate xeon++; 17250Sstevel@tonic-gate } 17260Sstevel@tonic-gate 17270Sstevel@tonic-gate for (i = 0; i < 2; i++) { 17280Sstevel@tonic-gate uint_t tmp; 17290Sstevel@tonic-gate 17300Sstevel@tonic-gate tmp = (cp->cp_ebx >> (8 * i)) & 0xff; 17310Sstevel@tonic-gate if (tmp == 0x40) 17320Sstevel@tonic-gate celeron++; 17330Sstevel@tonic-gate else if (tmp >= 0x44 && tmp <= 0x45) 17340Sstevel@tonic-gate xeon++; 17350Sstevel@tonic-gate } 17360Sstevel@tonic-gate 17370Sstevel@tonic-gate for (i = 0; i < 4; i++) { 17380Sstevel@tonic-gate uint_t tmp; 17390Sstevel@tonic-gate 17400Sstevel@tonic-gate tmp = (cp->cp_ecx >> (8 * i)) & 0xff; 17410Sstevel@tonic-gate if (tmp == 0x40) 17420Sstevel@tonic-gate celeron++; 17430Sstevel@tonic-gate else if (tmp >= 0x44 && tmp <= 0x45) 17440Sstevel@tonic-gate xeon++; 17450Sstevel@tonic-gate } 17460Sstevel@tonic-gate 17470Sstevel@tonic-gate for (i = 0; i < 4; i++) { 17480Sstevel@tonic-gate uint_t tmp; 17490Sstevel@tonic-gate 17500Sstevel@tonic-gate tmp = (cp->cp_edx >> (8 * i)) & 0xff; 17510Sstevel@tonic-gate if (tmp == 0x40) 17520Sstevel@tonic-gate celeron++; 17530Sstevel@tonic-gate else if (tmp >= 0x44 && tmp <= 0x45) 17540Sstevel@tonic-gate xeon++; 17550Sstevel@tonic-gate } 17560Sstevel@tonic-gate 17570Sstevel@tonic-gate if (celeron) 17580Sstevel@tonic-gate return ("Intel Celeron(r)"); 17590Sstevel@tonic-gate if (xeon) 17600Sstevel@tonic-gate return (cpi->cpi_model == 5 ? 17610Sstevel@tonic-gate "Intel Pentium(r) II Xeon(tm)" : 17620Sstevel@tonic-gate "Intel Pentium(r) III Xeon(tm)"); 17630Sstevel@tonic-gate return (cpi->cpi_model == 5 ? 17640Sstevel@tonic-gate "Intel Pentium(r) II or Pentium(r) II Xeon(tm)" : 17650Sstevel@tonic-gate "Intel Pentium(r) III or Pentium(r) III Xeon(tm)"); 17660Sstevel@tonic-gate default: 17670Sstevel@tonic-gate break; 17680Sstevel@tonic-gate } 17690Sstevel@tonic-gate default: 17700Sstevel@tonic-gate break; 17710Sstevel@tonic-gate } 17720Sstevel@tonic-gate 17731975Sdmick /* BrandID is present if the field is nonzero */ 17741975Sdmick if (cpi->cpi_brandid != 0) { 17750Sstevel@tonic-gate static const struct { 17760Sstevel@tonic-gate uint_t bt_bid; 17770Sstevel@tonic-gate const char *bt_str; 17780Sstevel@tonic-gate } brand_tbl[] = { 17790Sstevel@tonic-gate { 0x1, "Intel(r) Celeron(r)" }, 17800Sstevel@tonic-gate { 0x2, "Intel(r) Pentium(r) III" }, 17810Sstevel@tonic-gate { 0x3, "Intel(r) Pentium(r) III Xeon(tm)" }, 17820Sstevel@tonic-gate { 0x4, "Intel(r) Pentium(r) III" }, 17830Sstevel@tonic-gate { 0x6, "Mobile Intel(r) Pentium(r) III" }, 17840Sstevel@tonic-gate { 0x7, "Mobile Intel(r) Celeron(r)" }, 17850Sstevel@tonic-gate { 0x8, "Intel(r) Pentium(r) 4" }, 17860Sstevel@tonic-gate { 0x9, "Intel(r) Pentium(r) 4" }, 17870Sstevel@tonic-gate { 0xa, "Intel(r) Celeron(r)" }, 17880Sstevel@tonic-gate { 0xb, "Intel(r) Xeon(tm)" }, 17890Sstevel@tonic-gate { 0xc, "Intel(r) Xeon(tm) MP" }, 17900Sstevel@tonic-gate { 0xe, "Mobile Intel(r) Pentium(r) 4" }, 17911975Sdmick { 0xf, "Mobile Intel(r) Celeron(r)" }, 17921975Sdmick { 0x11, "Mobile Genuine Intel(r)" }, 17931975Sdmick { 0x12, "Intel(r) Celeron(r) M" }, 17941975Sdmick { 0x13, "Mobile Intel(r) Celeron(r)" }, 17951975Sdmick { 0x14, "Intel(r) Celeron(r)" }, 17961975Sdmick { 0x15, "Mobile Genuine Intel(r)" }, 17971975Sdmick { 0x16, "Intel(r) Pentium(r) M" }, 17981975Sdmick { 0x17, "Mobile Intel(r) Celeron(r)" } 17990Sstevel@tonic-gate }; 18000Sstevel@tonic-gate uint_t btblmax = sizeof (brand_tbl) / sizeof (brand_tbl[0]); 18010Sstevel@tonic-gate uint_t sgn; 18020Sstevel@tonic-gate 18030Sstevel@tonic-gate sgn = (cpi->cpi_family << 8) | 18040Sstevel@tonic-gate (cpi->cpi_model << 4) | cpi->cpi_step; 18050Sstevel@tonic-gate 18060Sstevel@tonic-gate for (i = 0; i < btblmax; i++) 18070Sstevel@tonic-gate if (brand_tbl[i].bt_bid == cpi->cpi_brandid) 18080Sstevel@tonic-gate break; 18090Sstevel@tonic-gate if (i < btblmax) { 18100Sstevel@tonic-gate if (sgn == 0x6b1 && cpi->cpi_brandid == 3) 18110Sstevel@tonic-gate return ("Intel(r) Celeron(r)"); 18120Sstevel@tonic-gate if (sgn < 0xf13 && cpi->cpi_brandid == 0xb) 18130Sstevel@tonic-gate return ("Intel(r) Xeon(tm) MP"); 18140Sstevel@tonic-gate if (sgn < 0xf13 && cpi->cpi_brandid == 0xe) 18150Sstevel@tonic-gate return ("Intel(r) Xeon(tm)"); 18160Sstevel@tonic-gate return (brand_tbl[i].bt_str); 18170Sstevel@tonic-gate } 18180Sstevel@tonic-gate } 18190Sstevel@tonic-gate 18200Sstevel@tonic-gate return (NULL); 18210Sstevel@tonic-gate } 18220Sstevel@tonic-gate 18230Sstevel@tonic-gate static const char * 18240Sstevel@tonic-gate amd_cpubrand(const struct cpuid_info *cpi) 18250Sstevel@tonic-gate { 18260Sstevel@tonic-gate if ((x86_feature & X86_CPUID) == 0 || 18270Sstevel@tonic-gate cpi->cpi_maxeax < 1 || cpi->cpi_family < 5) 18280Sstevel@tonic-gate return ("i486 compatible"); 18290Sstevel@tonic-gate 18300Sstevel@tonic-gate switch (cpi->cpi_family) { 18310Sstevel@tonic-gate case 5: 18320Sstevel@tonic-gate switch (cpi->cpi_model) { 18330Sstevel@tonic-gate case 0: 18340Sstevel@tonic-gate case 1: 18350Sstevel@tonic-gate case 2: 18360Sstevel@tonic-gate case 3: 18370Sstevel@tonic-gate case 4: 18380Sstevel@tonic-gate case 5: 18390Sstevel@tonic-gate return ("AMD-K5(r)"); 18400Sstevel@tonic-gate case 6: 18410Sstevel@tonic-gate case 7: 18420Sstevel@tonic-gate return ("AMD-K6(r)"); 18430Sstevel@tonic-gate case 8: 18440Sstevel@tonic-gate return ("AMD-K6(r)-2"); 18450Sstevel@tonic-gate case 9: 18460Sstevel@tonic-gate return ("AMD-K6(r)-III"); 18470Sstevel@tonic-gate default: 18480Sstevel@tonic-gate return ("AMD (family 5)"); 18490Sstevel@tonic-gate } 18500Sstevel@tonic-gate case 6: 18510Sstevel@tonic-gate switch (cpi->cpi_model) { 18520Sstevel@tonic-gate case 1: 18530Sstevel@tonic-gate return ("AMD-K7(tm)"); 18540Sstevel@tonic-gate case 0: 18550Sstevel@tonic-gate case 2: 18560Sstevel@tonic-gate case 4: 18570Sstevel@tonic-gate return ("AMD Athlon(tm)"); 18580Sstevel@tonic-gate case 3: 18590Sstevel@tonic-gate case 7: 18600Sstevel@tonic-gate return ("AMD Duron(tm)"); 18610Sstevel@tonic-gate case 6: 18620Sstevel@tonic-gate case 8: 18630Sstevel@tonic-gate case 10: 18640Sstevel@tonic-gate /* 18650Sstevel@tonic-gate * Use the L2 cache size to distinguish 18660Sstevel@tonic-gate */ 18670Sstevel@tonic-gate return ((cpi->cpi_extd[6].cp_ecx >> 16) >= 256 ? 18680Sstevel@tonic-gate "AMD Athlon(tm)" : "AMD Duron(tm)"); 18690Sstevel@tonic-gate default: 18700Sstevel@tonic-gate return ("AMD (family 6)"); 18710Sstevel@tonic-gate } 18720Sstevel@tonic-gate default: 18730Sstevel@tonic-gate break; 18740Sstevel@tonic-gate } 18750Sstevel@tonic-gate 18760Sstevel@tonic-gate if (cpi->cpi_family == 0xf && cpi->cpi_model == 5 && 18770Sstevel@tonic-gate cpi->cpi_brandid != 0) { 18780Sstevel@tonic-gate switch (BITX(cpi->cpi_brandid, 7, 5)) { 18790Sstevel@tonic-gate case 3: 18800Sstevel@tonic-gate return ("AMD Opteron(tm) UP 1xx"); 18810Sstevel@tonic-gate case 4: 18820Sstevel@tonic-gate return ("AMD Opteron(tm) DP 2xx"); 18830Sstevel@tonic-gate case 5: 18840Sstevel@tonic-gate return ("AMD Opteron(tm) MP 8xx"); 18850Sstevel@tonic-gate default: 18860Sstevel@tonic-gate return ("AMD Opteron(tm)"); 18870Sstevel@tonic-gate } 18880Sstevel@tonic-gate } 18890Sstevel@tonic-gate 18900Sstevel@tonic-gate return (NULL); 18910Sstevel@tonic-gate } 18920Sstevel@tonic-gate 18930Sstevel@tonic-gate static const char * 18940Sstevel@tonic-gate cyrix_cpubrand(struct cpuid_info *cpi, uint_t type) 18950Sstevel@tonic-gate { 18960Sstevel@tonic-gate if ((x86_feature & X86_CPUID) == 0 || 18970Sstevel@tonic-gate cpi->cpi_maxeax < 1 || cpi->cpi_family < 5 || 18980Sstevel@tonic-gate type == X86_TYPE_CYRIX_486) 18990Sstevel@tonic-gate return ("i486 compatible"); 19000Sstevel@tonic-gate 19010Sstevel@tonic-gate switch (type) { 19020Sstevel@tonic-gate case X86_TYPE_CYRIX_6x86: 19030Sstevel@tonic-gate return ("Cyrix 6x86"); 19040Sstevel@tonic-gate case X86_TYPE_CYRIX_6x86L: 19050Sstevel@tonic-gate return ("Cyrix 6x86L"); 19060Sstevel@tonic-gate case X86_TYPE_CYRIX_6x86MX: 19070Sstevel@tonic-gate return ("Cyrix 6x86MX"); 19080Sstevel@tonic-gate case X86_TYPE_CYRIX_GXm: 19090Sstevel@tonic-gate return ("Cyrix GXm"); 19100Sstevel@tonic-gate case X86_TYPE_CYRIX_MediaGX: 19110Sstevel@tonic-gate return ("Cyrix MediaGX"); 19120Sstevel@tonic-gate case X86_TYPE_CYRIX_MII: 19130Sstevel@tonic-gate return ("Cyrix M2"); 19140Sstevel@tonic-gate case X86_TYPE_VIA_CYRIX_III: 19150Sstevel@tonic-gate return ("VIA Cyrix M3"); 19160Sstevel@tonic-gate default: 19170Sstevel@tonic-gate /* 19180Sstevel@tonic-gate * Have another wild guess .. 19190Sstevel@tonic-gate */ 19200Sstevel@tonic-gate if (cpi->cpi_family == 4 && cpi->cpi_model == 9) 19210Sstevel@tonic-gate return ("Cyrix 5x86"); 19220Sstevel@tonic-gate else if (cpi->cpi_family == 5) { 19230Sstevel@tonic-gate switch (cpi->cpi_model) { 19240Sstevel@tonic-gate case 2: 19250Sstevel@tonic-gate return ("Cyrix 6x86"); /* Cyrix M1 */ 19260Sstevel@tonic-gate case 4: 19270Sstevel@tonic-gate return ("Cyrix MediaGX"); 19280Sstevel@tonic-gate default: 19290Sstevel@tonic-gate break; 19300Sstevel@tonic-gate } 19310Sstevel@tonic-gate } else if (cpi->cpi_family == 6) { 19320Sstevel@tonic-gate switch (cpi->cpi_model) { 19330Sstevel@tonic-gate case 0: 19340Sstevel@tonic-gate return ("Cyrix 6x86MX"); /* Cyrix M2? */ 19350Sstevel@tonic-gate case 5: 19360Sstevel@tonic-gate case 6: 19370Sstevel@tonic-gate case 7: 19380Sstevel@tonic-gate case 8: 19390Sstevel@tonic-gate case 9: 19400Sstevel@tonic-gate return ("VIA C3"); 19410Sstevel@tonic-gate default: 19420Sstevel@tonic-gate break; 19430Sstevel@tonic-gate } 19440Sstevel@tonic-gate } 19450Sstevel@tonic-gate break; 19460Sstevel@tonic-gate } 19470Sstevel@tonic-gate return (NULL); 19480Sstevel@tonic-gate } 19490Sstevel@tonic-gate 19500Sstevel@tonic-gate /* 19510Sstevel@tonic-gate * This only gets called in the case that the CPU extended 19520Sstevel@tonic-gate * feature brand string (0x80000002, 0x80000003, 0x80000004) 19530Sstevel@tonic-gate * aren't available, or contain null bytes for some reason. 19540Sstevel@tonic-gate */ 19550Sstevel@tonic-gate static void 19560Sstevel@tonic-gate fabricate_brandstr(struct cpuid_info *cpi) 19570Sstevel@tonic-gate { 19580Sstevel@tonic-gate const char *brand = NULL; 19590Sstevel@tonic-gate 19600Sstevel@tonic-gate switch (cpi->cpi_vendor) { 19610Sstevel@tonic-gate case X86_VENDOR_Intel: 19620Sstevel@tonic-gate brand = intel_cpubrand(cpi); 19630Sstevel@tonic-gate break; 19640Sstevel@tonic-gate case X86_VENDOR_AMD: 19650Sstevel@tonic-gate brand = amd_cpubrand(cpi); 19660Sstevel@tonic-gate break; 19670Sstevel@tonic-gate case X86_VENDOR_Cyrix: 19680Sstevel@tonic-gate brand = cyrix_cpubrand(cpi, x86_type); 19690Sstevel@tonic-gate break; 19700Sstevel@tonic-gate case X86_VENDOR_NexGen: 19710Sstevel@tonic-gate if (cpi->cpi_family == 5 && cpi->cpi_model == 0) 19720Sstevel@tonic-gate brand = "NexGen Nx586"; 19730Sstevel@tonic-gate break; 19740Sstevel@tonic-gate case X86_VENDOR_Centaur: 19750Sstevel@tonic-gate if (cpi->cpi_family == 5) 19760Sstevel@tonic-gate switch (cpi->cpi_model) { 19770Sstevel@tonic-gate case 4: 19780Sstevel@tonic-gate brand = "Centaur C6"; 19790Sstevel@tonic-gate break; 19800Sstevel@tonic-gate case 8: 19810Sstevel@tonic-gate brand = "Centaur C2"; 19820Sstevel@tonic-gate break; 19830Sstevel@tonic-gate case 9: 19840Sstevel@tonic-gate brand = "Centaur C3"; 19850Sstevel@tonic-gate break; 19860Sstevel@tonic-gate default: 19870Sstevel@tonic-gate break; 19880Sstevel@tonic-gate } 19890Sstevel@tonic-gate break; 19900Sstevel@tonic-gate case X86_VENDOR_Rise: 19910Sstevel@tonic-gate if (cpi->cpi_family == 5 && 19920Sstevel@tonic-gate (cpi->cpi_model == 0 || cpi->cpi_model == 2)) 19930Sstevel@tonic-gate brand = "Rise mP6"; 19940Sstevel@tonic-gate break; 19950Sstevel@tonic-gate case X86_VENDOR_SiS: 19960Sstevel@tonic-gate if (cpi->cpi_family == 5 && cpi->cpi_model == 0) 19970Sstevel@tonic-gate brand = "SiS 55x"; 19980Sstevel@tonic-gate break; 19990Sstevel@tonic-gate case X86_VENDOR_TM: 20000Sstevel@tonic-gate if (cpi->cpi_family == 5 && cpi->cpi_model == 4) 20010Sstevel@tonic-gate brand = "Transmeta Crusoe TM3x00 or TM5x00"; 20020Sstevel@tonic-gate break; 20030Sstevel@tonic-gate case X86_VENDOR_NSC: 20040Sstevel@tonic-gate case X86_VENDOR_UMC: 20050Sstevel@tonic-gate default: 20060Sstevel@tonic-gate break; 20070Sstevel@tonic-gate } 20080Sstevel@tonic-gate if (brand) { 20090Sstevel@tonic-gate (void) strcpy((char *)cpi->cpi_brandstr, brand); 20100Sstevel@tonic-gate return; 20110Sstevel@tonic-gate } 20120Sstevel@tonic-gate 20130Sstevel@tonic-gate /* 20140Sstevel@tonic-gate * If all else fails ... 20150Sstevel@tonic-gate */ 20160Sstevel@tonic-gate (void) snprintf(cpi->cpi_brandstr, sizeof (cpi->cpi_brandstr), 20170Sstevel@tonic-gate "%s %d.%d.%d", cpi->cpi_vendorstr, cpi->cpi_family, 20180Sstevel@tonic-gate cpi->cpi_model, cpi->cpi_step); 20190Sstevel@tonic-gate } 20200Sstevel@tonic-gate 20210Sstevel@tonic-gate /* 20220Sstevel@tonic-gate * This routine is called just after kernel memory allocation 20230Sstevel@tonic-gate * becomes available on cpu0, and as part of mp_startup() on 20240Sstevel@tonic-gate * the other cpus. 20250Sstevel@tonic-gate * 20264606Sesaxe * Fixup the brand string, and collect any information from cpuid 20274606Sesaxe * that requires dynamicically allocated storage to represent. 20280Sstevel@tonic-gate */ 20290Sstevel@tonic-gate /*ARGSUSED*/ 20300Sstevel@tonic-gate void 20310Sstevel@tonic-gate cpuid_pass3(cpu_t *cpu) 20320Sstevel@tonic-gate { 20334606Sesaxe int i, max, shft, level, size; 20344606Sesaxe struct cpuid_regs regs; 20354606Sesaxe struct cpuid_regs *cp; 20360Sstevel@tonic-gate struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 20370Sstevel@tonic-gate 20380Sstevel@tonic-gate ASSERT(cpi->cpi_pass == 2); 20390Sstevel@tonic-gate 20404606Sesaxe /* 20414606Sesaxe * Function 4: Deterministic cache parameters 20424606Sesaxe * 20434606Sesaxe * Take this opportunity to detect the number of threads 20444606Sesaxe * sharing the last level cache, and construct a corresponding 20454606Sesaxe * cache id. The respective cpuid_info members are initialized 20464606Sesaxe * to the default case of "no last level cache sharing". 20474606Sesaxe */ 20484606Sesaxe cpi->cpi_ncpu_shr_last_cache = 1; 20494606Sesaxe cpi->cpi_last_lvl_cacheid = cpu->cpu_id; 20504606Sesaxe 20514606Sesaxe if (cpi->cpi_maxeax >= 4 && cpi->cpi_vendor == X86_VENDOR_Intel) { 20524606Sesaxe 20534606Sesaxe /* 20544606Sesaxe * Find the # of elements (size) returned by fn 4, and along 20554606Sesaxe * the way detect last level cache sharing details. 20564606Sesaxe */ 20574606Sesaxe bzero(®s, sizeof (regs)); 20584606Sesaxe cp = ®s; 20594606Sesaxe for (i = 0, max = 0; i < CPI_FN4_ECX_MAX; i++) { 20604606Sesaxe cp->cp_eax = 4; 20614606Sesaxe cp->cp_ecx = i; 20624606Sesaxe 20634606Sesaxe (void) __cpuid_insn(cp); 20644606Sesaxe 20654606Sesaxe if (CPI_CACHE_TYPE(cp) == 0) 20664606Sesaxe break; 20674606Sesaxe level = CPI_CACHE_LVL(cp); 20684606Sesaxe if (level > max) { 20694606Sesaxe max = level; 20704606Sesaxe cpi->cpi_ncpu_shr_last_cache = 20714606Sesaxe CPI_NTHR_SHR_CACHE(cp) + 1; 20724606Sesaxe } 20734606Sesaxe } 20744606Sesaxe cpi->cpi_std_4_size = size = i; 20754606Sesaxe 20764606Sesaxe /* 20774606Sesaxe * Allocate the cpi_std_4 array. The first element 20784606Sesaxe * references the regs for fn 4, %ecx == 0, which 20794606Sesaxe * cpuid_pass2() stashed in cpi->cpi_std[4]. 20804606Sesaxe */ 20814606Sesaxe if (size > 0) { 20824606Sesaxe cpi->cpi_std_4 = 20834606Sesaxe kmem_alloc(size * sizeof (cp), KM_SLEEP); 20844606Sesaxe cpi->cpi_std_4[0] = &cpi->cpi_std[4]; 20854606Sesaxe 20864606Sesaxe /* 20874606Sesaxe * Allocate storage to hold the additional regs 20884606Sesaxe * for function 4, %ecx == 1 .. cpi_std_4_size. 20894606Sesaxe * 20904606Sesaxe * The regs for fn 4, %ecx == 0 has already 20914606Sesaxe * been allocated as indicated above. 20924606Sesaxe */ 20934606Sesaxe for (i = 1; i < size; i++) { 20944606Sesaxe cp = cpi->cpi_std_4[i] = 20954606Sesaxe kmem_zalloc(sizeof (regs), KM_SLEEP); 20964606Sesaxe cp->cp_eax = 4; 20974606Sesaxe cp->cp_ecx = i; 20984606Sesaxe 20994606Sesaxe (void) __cpuid_insn(cp); 21004606Sesaxe } 21014606Sesaxe } 21024606Sesaxe /* 21034606Sesaxe * Determine the number of bits needed to represent 21044606Sesaxe * the number of CPUs sharing the last level cache. 21054606Sesaxe * 21064606Sesaxe * Shift off that number of bits from the APIC id to 21074606Sesaxe * derive the cache id. 21084606Sesaxe */ 21094606Sesaxe shft = 0; 21104606Sesaxe for (i = 1; i < cpi->cpi_ncpu_shr_last_cache; i <<= 1) 21114606Sesaxe shft++; 21127282Smishra cpi->cpi_last_lvl_cacheid = cpi->cpi_apicid >> shft; 21130Sstevel@tonic-gate } 21140Sstevel@tonic-gate 21150Sstevel@tonic-gate /* 21164606Sesaxe * Now fixup the brand string 21170Sstevel@tonic-gate */ 21184606Sesaxe if ((cpi->cpi_xmaxeax & 0x80000000) == 0) { 21194606Sesaxe fabricate_brandstr(cpi); 21204606Sesaxe } else { 21210Sstevel@tonic-gate 21220Sstevel@tonic-gate /* 21234606Sesaxe * If we successfully extracted a brand string from the cpuid 21244606Sesaxe * instruction, clean it up by removing leading spaces and 21254606Sesaxe * similar junk. 21260Sstevel@tonic-gate */ 21274606Sesaxe if (cpi->cpi_brandstr[0]) { 21284606Sesaxe size_t maxlen = sizeof (cpi->cpi_brandstr); 21294606Sesaxe char *src, *dst; 21304606Sesaxe 21314606Sesaxe dst = src = (char *)cpi->cpi_brandstr; 21324606Sesaxe src[maxlen - 1] = '\0'; 21334606Sesaxe /* 21344606Sesaxe * strip leading spaces 21354606Sesaxe */ 21364606Sesaxe while (*src == ' ') 21374606Sesaxe src++; 21384606Sesaxe /* 21394606Sesaxe * Remove any 'Genuine' or "Authentic" prefixes 21404606Sesaxe */ 21414606Sesaxe if (strncmp(src, "Genuine ", 8) == 0) 21424606Sesaxe src += 8; 21434606Sesaxe if (strncmp(src, "Authentic ", 10) == 0) 21444606Sesaxe src += 10; 21454606Sesaxe 21464606Sesaxe /* 21474606Sesaxe * Now do an in-place copy. 21484606Sesaxe * Map (R) to (r) and (TM) to (tm). 21494606Sesaxe * The era of teletypes is long gone, and there's 21504606Sesaxe * -really- no need to shout. 21514606Sesaxe */ 21524606Sesaxe while (*src != '\0') { 21534606Sesaxe if (src[0] == '(') { 21544606Sesaxe if (strncmp(src + 1, "R)", 2) == 0) { 21554606Sesaxe (void) strncpy(dst, "(r)", 3); 21564606Sesaxe src += 3; 21574606Sesaxe dst += 3; 21584606Sesaxe continue; 21594606Sesaxe } 21604606Sesaxe if (strncmp(src + 1, "TM)", 3) == 0) { 21614606Sesaxe (void) strncpy(dst, "(tm)", 4); 21624606Sesaxe src += 4; 21634606Sesaxe dst += 4; 21644606Sesaxe continue; 21654606Sesaxe } 21660Sstevel@tonic-gate } 21674606Sesaxe *dst++ = *src++; 21680Sstevel@tonic-gate } 21694606Sesaxe *dst = '\0'; 21704606Sesaxe 21714606Sesaxe /* 21724606Sesaxe * Finally, remove any trailing spaces 21734606Sesaxe */ 21744606Sesaxe while (--dst > cpi->cpi_brandstr) 21754606Sesaxe if (*dst == ' ') 21764606Sesaxe *dst = '\0'; 21774606Sesaxe else 21784606Sesaxe break; 21794606Sesaxe } else 21804606Sesaxe fabricate_brandstr(cpi); 21814606Sesaxe } 21820Sstevel@tonic-gate cpi->cpi_pass = 3; 21830Sstevel@tonic-gate } 21840Sstevel@tonic-gate 21850Sstevel@tonic-gate /* 21860Sstevel@tonic-gate * This routine is called out of bind_hwcap() much later in the life 21870Sstevel@tonic-gate * of the kernel (post_startup()). The job of this routine is to resolve 21880Sstevel@tonic-gate * the hardware feature support and kernel support for those features into 21890Sstevel@tonic-gate * what we're actually going to tell applications via the aux vector. 21900Sstevel@tonic-gate */ 21910Sstevel@tonic-gate uint_t 21920Sstevel@tonic-gate cpuid_pass4(cpu_t *cpu) 21930Sstevel@tonic-gate { 21940Sstevel@tonic-gate struct cpuid_info *cpi; 21950Sstevel@tonic-gate uint_t hwcap_flags = 0; 21960Sstevel@tonic-gate 21970Sstevel@tonic-gate if (cpu == NULL) 21980Sstevel@tonic-gate cpu = CPU; 21990Sstevel@tonic-gate cpi = cpu->cpu_m.mcpu_cpi; 22000Sstevel@tonic-gate 22010Sstevel@tonic-gate ASSERT(cpi->cpi_pass == 3); 22020Sstevel@tonic-gate 22030Sstevel@tonic-gate if (cpi->cpi_maxeax >= 1) { 22040Sstevel@tonic-gate uint32_t *edx = &cpi->cpi_support[STD_EDX_FEATURES]; 22050Sstevel@tonic-gate uint32_t *ecx = &cpi->cpi_support[STD_ECX_FEATURES]; 22060Sstevel@tonic-gate 22070Sstevel@tonic-gate *edx = CPI_FEATURES_EDX(cpi); 22080Sstevel@tonic-gate *ecx = CPI_FEATURES_ECX(cpi); 22090Sstevel@tonic-gate 22100Sstevel@tonic-gate /* 22110Sstevel@tonic-gate * [these require explicit kernel support] 22120Sstevel@tonic-gate */ 22130Sstevel@tonic-gate if ((x86_feature & X86_SEP) == 0) 22140Sstevel@tonic-gate *edx &= ~CPUID_INTC_EDX_SEP; 22150Sstevel@tonic-gate 22160Sstevel@tonic-gate if ((x86_feature & X86_SSE) == 0) 22170Sstevel@tonic-gate *edx &= ~(CPUID_INTC_EDX_FXSR|CPUID_INTC_EDX_SSE); 22180Sstevel@tonic-gate if ((x86_feature & X86_SSE2) == 0) 22190Sstevel@tonic-gate *edx &= ~CPUID_INTC_EDX_SSE2; 22200Sstevel@tonic-gate 22210Sstevel@tonic-gate if ((x86_feature & X86_HTT) == 0) 22220Sstevel@tonic-gate *edx &= ~CPUID_INTC_EDX_HTT; 22230Sstevel@tonic-gate 22240Sstevel@tonic-gate if ((x86_feature & X86_SSE3) == 0) 22250Sstevel@tonic-gate *ecx &= ~CPUID_INTC_ECX_SSE3; 22260Sstevel@tonic-gate 22275269Skk208521 if (cpi->cpi_vendor == X86_VENDOR_Intel) { 22285269Skk208521 if ((x86_feature & X86_SSSE3) == 0) 22295269Skk208521 *ecx &= ~CPUID_INTC_ECX_SSSE3; 22305269Skk208521 if ((x86_feature & X86_SSE4_1) == 0) 22315269Skk208521 *ecx &= ~CPUID_INTC_ECX_SSE4_1; 22325269Skk208521 if ((x86_feature & X86_SSE4_2) == 0) 22335269Skk208521 *ecx &= ~CPUID_INTC_ECX_SSE4_2; 22349370SKuriakose.Kuruvilla@Sun.COM if ((x86_feature & X86_AES) == 0) 22359370SKuriakose.Kuruvilla@Sun.COM *ecx &= ~CPUID_INTC_ECX_AES; 22365269Skk208521 } 22375269Skk208521 22380Sstevel@tonic-gate /* 22390Sstevel@tonic-gate * [no explicit support required beyond x87 fp context] 22400Sstevel@tonic-gate */ 22410Sstevel@tonic-gate if (!fpu_exists) 22420Sstevel@tonic-gate *edx &= ~(CPUID_INTC_EDX_FPU | CPUID_INTC_EDX_MMX); 22430Sstevel@tonic-gate 22440Sstevel@tonic-gate /* 22450Sstevel@tonic-gate * Now map the supported feature vector to things that we 22460Sstevel@tonic-gate * think userland will care about. 22470Sstevel@tonic-gate */ 22480Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_SEP) 22490Sstevel@tonic-gate hwcap_flags |= AV_386_SEP; 22500Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_SSE) 22510Sstevel@tonic-gate hwcap_flags |= AV_386_FXSR | AV_386_SSE; 22520Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_SSE2) 22530Sstevel@tonic-gate hwcap_flags |= AV_386_SSE2; 22540Sstevel@tonic-gate if (*ecx & CPUID_INTC_ECX_SSE3) 22550Sstevel@tonic-gate hwcap_flags |= AV_386_SSE3; 22565269Skk208521 if (cpi->cpi_vendor == X86_VENDOR_Intel) { 22575269Skk208521 if (*ecx & CPUID_INTC_ECX_SSSE3) 22585269Skk208521 hwcap_flags |= AV_386_SSSE3; 22595269Skk208521 if (*ecx & CPUID_INTC_ECX_SSE4_1) 22605269Skk208521 hwcap_flags |= AV_386_SSE4_1; 22615269Skk208521 if (*ecx & CPUID_INTC_ECX_SSE4_2) 22625269Skk208521 hwcap_flags |= AV_386_SSE4_2; 22638418SKrishnendu.Sadhukhan@Sun.COM if (*ecx & CPUID_INTC_ECX_MOVBE) 22648418SKrishnendu.Sadhukhan@Sun.COM hwcap_flags |= AV_386_MOVBE; 22659370SKuriakose.Kuruvilla@Sun.COM if (*ecx & CPUID_INTC_ECX_AES) 22669370SKuriakose.Kuruvilla@Sun.COM hwcap_flags |= AV_386_AES; 22679370SKuriakose.Kuruvilla@Sun.COM if (*ecx & CPUID_INTC_ECX_PCLMULQDQ) 22689370SKuriakose.Kuruvilla@Sun.COM hwcap_flags |= AV_386_PCLMULQDQ; 22695269Skk208521 } 22704628Skk208521 if (*ecx & CPUID_INTC_ECX_POPCNT) 22714628Skk208521 hwcap_flags |= AV_386_POPCNT; 22720Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_FPU) 22730Sstevel@tonic-gate hwcap_flags |= AV_386_FPU; 22740Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_MMX) 22750Sstevel@tonic-gate hwcap_flags |= AV_386_MMX; 22760Sstevel@tonic-gate 22770Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_TSC) 22780Sstevel@tonic-gate hwcap_flags |= AV_386_TSC; 22790Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_CX8) 22800Sstevel@tonic-gate hwcap_flags |= AV_386_CX8; 22810Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_CMOV) 22820Sstevel@tonic-gate hwcap_flags |= AV_386_CMOV; 22830Sstevel@tonic-gate if (*ecx & CPUID_INTC_ECX_MON) 22840Sstevel@tonic-gate hwcap_flags |= AV_386_MON; 22850Sstevel@tonic-gate if (*ecx & CPUID_INTC_ECX_CX16) 22860Sstevel@tonic-gate hwcap_flags |= AV_386_CX16; 22870Sstevel@tonic-gate } 22880Sstevel@tonic-gate 22891228Sandrei if (x86_feature & X86_HTT) 22900Sstevel@tonic-gate hwcap_flags |= AV_386_PAUSE; 22910Sstevel@tonic-gate 22920Sstevel@tonic-gate if (cpi->cpi_xmaxeax < 0x80000001) 22930Sstevel@tonic-gate goto pass4_done; 22940Sstevel@tonic-gate 22950Sstevel@tonic-gate switch (cpi->cpi_vendor) { 22961228Sandrei struct cpuid_regs cp; 22973446Smrj uint32_t *edx, *ecx; 22980Sstevel@tonic-gate 22993446Smrj case X86_VENDOR_Intel: 23003446Smrj /* 23013446Smrj * Seems like Intel duplicated what we necessary 23023446Smrj * here to make the initial crop of 64-bit OS's work. 23033446Smrj * Hopefully, those are the only "extended" bits 23043446Smrj * they'll add. 23053446Smrj */ 23063446Smrj /*FALLTHROUGH*/ 23073446Smrj 23080Sstevel@tonic-gate case X86_VENDOR_AMD: 23090Sstevel@tonic-gate edx = &cpi->cpi_support[AMD_EDX_FEATURES]; 23103446Smrj ecx = &cpi->cpi_support[AMD_ECX_FEATURES]; 23110Sstevel@tonic-gate 23120Sstevel@tonic-gate *edx = CPI_FEATURES_XTD_EDX(cpi); 23133446Smrj *ecx = CPI_FEATURES_XTD_ECX(cpi); 23143446Smrj 23153446Smrj /* 23163446Smrj * [these features require explicit kernel support] 23173446Smrj */ 23183446Smrj switch (cpi->cpi_vendor) { 23193446Smrj case X86_VENDOR_Intel: 23206657Ssudheer if ((x86_feature & X86_TSCP) == 0) 23216657Ssudheer *edx &= ~CPUID_AMD_EDX_TSCP; 23223446Smrj break; 23233446Smrj 23243446Smrj case X86_VENDOR_AMD: 23253446Smrj if ((x86_feature & X86_TSCP) == 0) 23263446Smrj *edx &= ~CPUID_AMD_EDX_TSCP; 23274628Skk208521 if ((x86_feature & X86_SSE4A) == 0) 23284628Skk208521 *ecx &= ~CPUID_AMD_ECX_SSE4A; 23293446Smrj break; 23303446Smrj 23313446Smrj default: 23323446Smrj break; 23333446Smrj } 23340Sstevel@tonic-gate 23350Sstevel@tonic-gate /* 23360Sstevel@tonic-gate * [no explicit support required beyond 23370Sstevel@tonic-gate * x87 fp context and exception handlers] 23380Sstevel@tonic-gate */ 23390Sstevel@tonic-gate if (!fpu_exists) 23400Sstevel@tonic-gate *edx &= ~(CPUID_AMD_EDX_MMXamd | 23410Sstevel@tonic-gate CPUID_AMD_EDX_3DNow | CPUID_AMD_EDX_3DNowx); 23420Sstevel@tonic-gate 23430Sstevel@tonic-gate if ((x86_feature & X86_NX) == 0) 23440Sstevel@tonic-gate *edx &= ~CPUID_AMD_EDX_NX; 23453446Smrj #if !defined(__amd64) 23460Sstevel@tonic-gate *edx &= ~CPUID_AMD_EDX_LM; 23470Sstevel@tonic-gate #endif 23480Sstevel@tonic-gate /* 23490Sstevel@tonic-gate * Now map the supported feature vector to 23500Sstevel@tonic-gate * things that we think userland will care about. 23510Sstevel@tonic-gate */ 23523446Smrj #if defined(__amd64) 23530Sstevel@tonic-gate if (*edx & CPUID_AMD_EDX_SYSC) 23540Sstevel@tonic-gate hwcap_flags |= AV_386_AMD_SYSC; 23553446Smrj #endif 23560Sstevel@tonic-gate if (*edx & CPUID_AMD_EDX_MMXamd) 23570Sstevel@tonic-gate hwcap_flags |= AV_386_AMD_MMX; 23580Sstevel@tonic-gate if (*edx & CPUID_AMD_EDX_3DNow) 23590Sstevel@tonic-gate hwcap_flags |= AV_386_AMD_3DNow; 23600Sstevel@tonic-gate if (*edx & CPUID_AMD_EDX_3DNowx) 23610Sstevel@tonic-gate hwcap_flags |= AV_386_AMD_3DNowx; 23623446Smrj 23633446Smrj switch (cpi->cpi_vendor) { 23643446Smrj case X86_VENDOR_AMD: 23653446Smrj if (*edx & CPUID_AMD_EDX_TSCP) 23663446Smrj hwcap_flags |= AV_386_TSCP; 23673446Smrj if (*ecx & CPUID_AMD_ECX_AHF64) 23683446Smrj hwcap_flags |= AV_386_AHF; 23694628Skk208521 if (*ecx & CPUID_AMD_ECX_SSE4A) 23704628Skk208521 hwcap_flags |= AV_386_AMD_SSE4A; 23714628Skk208521 if (*ecx & CPUID_AMD_ECX_LZCNT) 23724628Skk208521 hwcap_flags |= AV_386_AMD_LZCNT; 23733446Smrj break; 23743446Smrj 23753446Smrj case X86_VENDOR_Intel: 23766657Ssudheer if (*edx & CPUID_AMD_EDX_TSCP) 23776657Ssudheer hwcap_flags |= AV_386_TSCP; 23783446Smrj /* 23793446Smrj * Aarrgh. 23803446Smrj * Intel uses a different bit in the same word. 23813446Smrj */ 23823446Smrj if (*ecx & CPUID_INTC_ECX_AHF64) 23833446Smrj hwcap_flags |= AV_386_AHF; 23843446Smrj break; 23853446Smrj 23863446Smrj default: 23873446Smrj break; 23883446Smrj } 23890Sstevel@tonic-gate break; 23900Sstevel@tonic-gate 23910Sstevel@tonic-gate case X86_VENDOR_TM: 23921228Sandrei cp.cp_eax = 0x80860001; 23931228Sandrei (void) __cpuid_insn(&cp); 23941228Sandrei cpi->cpi_support[TM_EDX_FEATURES] = cp.cp_edx; 23950Sstevel@tonic-gate break; 23960Sstevel@tonic-gate 23970Sstevel@tonic-gate default: 23980Sstevel@tonic-gate break; 23990Sstevel@tonic-gate } 24000Sstevel@tonic-gate 24010Sstevel@tonic-gate pass4_done: 24020Sstevel@tonic-gate cpi->cpi_pass = 4; 24030Sstevel@tonic-gate return (hwcap_flags); 24040Sstevel@tonic-gate } 24050Sstevel@tonic-gate 24060Sstevel@tonic-gate 24070Sstevel@tonic-gate /* 24080Sstevel@tonic-gate * Simulate the cpuid instruction using the data we previously 24090Sstevel@tonic-gate * captured about this CPU. We try our best to return the truth 24100Sstevel@tonic-gate * about the hardware, independently of kernel support. 24110Sstevel@tonic-gate */ 24120Sstevel@tonic-gate uint32_t 24131228Sandrei cpuid_insn(cpu_t *cpu, struct cpuid_regs *cp) 24140Sstevel@tonic-gate { 24150Sstevel@tonic-gate struct cpuid_info *cpi; 24161228Sandrei struct cpuid_regs *xcp; 24170Sstevel@tonic-gate 24180Sstevel@tonic-gate if (cpu == NULL) 24190Sstevel@tonic-gate cpu = CPU; 24200Sstevel@tonic-gate cpi = cpu->cpu_m.mcpu_cpi; 24210Sstevel@tonic-gate 24220Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 3)); 24230Sstevel@tonic-gate 24240Sstevel@tonic-gate /* 24250Sstevel@tonic-gate * CPUID data is cached in two separate places: cpi_std for standard 24260Sstevel@tonic-gate * CPUID functions, and cpi_extd for extended CPUID functions. 24270Sstevel@tonic-gate */ 24281228Sandrei if (cp->cp_eax <= cpi->cpi_maxeax && cp->cp_eax < NMAX_CPI_STD) 24291228Sandrei xcp = &cpi->cpi_std[cp->cp_eax]; 24301228Sandrei else if (cp->cp_eax >= 0x80000000 && cp->cp_eax <= cpi->cpi_xmaxeax && 24311228Sandrei cp->cp_eax < 0x80000000 + NMAX_CPI_EXTD) 24321228Sandrei xcp = &cpi->cpi_extd[cp->cp_eax - 0x80000000]; 24330Sstevel@tonic-gate else 24340Sstevel@tonic-gate /* 24350Sstevel@tonic-gate * The caller is asking for data from an input parameter which 24360Sstevel@tonic-gate * the kernel has not cached. In this case we go fetch from 24370Sstevel@tonic-gate * the hardware and return the data directly to the user. 24380Sstevel@tonic-gate */ 24391228Sandrei return (__cpuid_insn(cp)); 24401228Sandrei 24411228Sandrei cp->cp_eax = xcp->cp_eax; 24421228Sandrei cp->cp_ebx = xcp->cp_ebx; 24431228Sandrei cp->cp_ecx = xcp->cp_ecx; 24441228Sandrei cp->cp_edx = xcp->cp_edx; 24450Sstevel@tonic-gate return (cp->cp_eax); 24460Sstevel@tonic-gate } 24470Sstevel@tonic-gate 24480Sstevel@tonic-gate int 24490Sstevel@tonic-gate cpuid_checkpass(cpu_t *cpu, int pass) 24500Sstevel@tonic-gate { 24510Sstevel@tonic-gate return (cpu != NULL && cpu->cpu_m.mcpu_cpi != NULL && 24520Sstevel@tonic-gate cpu->cpu_m.mcpu_cpi->cpi_pass >= pass); 24530Sstevel@tonic-gate } 24540Sstevel@tonic-gate 24550Sstevel@tonic-gate int 24560Sstevel@tonic-gate cpuid_getbrandstr(cpu_t *cpu, char *s, size_t n) 24570Sstevel@tonic-gate { 24580Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 3)); 24590Sstevel@tonic-gate 24600Sstevel@tonic-gate return (snprintf(s, n, "%s", cpu->cpu_m.mcpu_cpi->cpi_brandstr)); 24610Sstevel@tonic-gate } 24620Sstevel@tonic-gate 24630Sstevel@tonic-gate int 24641228Sandrei cpuid_is_cmt(cpu_t *cpu) 24650Sstevel@tonic-gate { 24660Sstevel@tonic-gate if (cpu == NULL) 24670Sstevel@tonic-gate cpu = CPU; 24680Sstevel@tonic-gate 24690Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 24700Sstevel@tonic-gate 24710Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_chipid >= 0); 24720Sstevel@tonic-gate } 24730Sstevel@tonic-gate 24740Sstevel@tonic-gate /* 24750Sstevel@tonic-gate * AMD and Intel both implement the 64-bit variant of the syscall 24760Sstevel@tonic-gate * instruction (syscallq), so if there's -any- support for syscall, 24770Sstevel@tonic-gate * cpuid currently says "yes, we support this". 24780Sstevel@tonic-gate * 24790Sstevel@tonic-gate * However, Intel decided to -not- implement the 32-bit variant of the 24800Sstevel@tonic-gate * syscall instruction, so we provide a predicate to allow our caller 24810Sstevel@tonic-gate * to test that subtlety here. 24825084Sjohnlev * 24835084Sjohnlev * XXPV Currently, 32-bit syscall instructions don't work via the hypervisor, 24845084Sjohnlev * even in the case where the hardware would in fact support it. 24850Sstevel@tonic-gate */ 24860Sstevel@tonic-gate /*ARGSUSED*/ 24870Sstevel@tonic-gate int 24880Sstevel@tonic-gate cpuid_syscall32_insn(cpu_t *cpu) 24890Sstevel@tonic-gate { 24900Sstevel@tonic-gate ASSERT(cpuid_checkpass((cpu == NULL ? CPU : cpu), 1)); 24910Sstevel@tonic-gate 24925084Sjohnlev #if !defined(__xpv) 24933446Smrj if (cpu == NULL) 24943446Smrj cpu = CPU; 24953446Smrj 24963446Smrj /*CSTYLED*/ 24973446Smrj { 24983446Smrj struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 24993446Smrj 25003446Smrj if (cpi->cpi_vendor == X86_VENDOR_AMD && 25013446Smrj cpi->cpi_xmaxeax >= 0x80000001 && 25023446Smrj (CPI_FEATURES_XTD_EDX(cpi) & CPUID_AMD_EDX_SYSC)) 25033446Smrj return (1); 25043446Smrj } 25055084Sjohnlev #endif 25060Sstevel@tonic-gate return (0); 25070Sstevel@tonic-gate } 25080Sstevel@tonic-gate 25090Sstevel@tonic-gate int 25100Sstevel@tonic-gate cpuid_getidstr(cpu_t *cpu, char *s, size_t n) 25110Sstevel@tonic-gate { 25120Sstevel@tonic-gate struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 25130Sstevel@tonic-gate 25140Sstevel@tonic-gate static const char fmt[] = 25153779Sdmick "x86 (%s %X family %d model %d step %d clock %d MHz)"; 25160Sstevel@tonic-gate static const char fmt_ht[] = 25173779Sdmick "x86 (chipid 0x%x %s %X family %d model %d step %d clock %d MHz)"; 25180Sstevel@tonic-gate 25190Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 25200Sstevel@tonic-gate 25211228Sandrei if (cpuid_is_cmt(cpu)) 25220Sstevel@tonic-gate return (snprintf(s, n, fmt_ht, cpi->cpi_chipid, 25233779Sdmick cpi->cpi_vendorstr, cpi->cpi_std[1].cp_eax, 25243779Sdmick cpi->cpi_family, cpi->cpi_model, 25250Sstevel@tonic-gate cpi->cpi_step, cpu->cpu_type_info.pi_clock)); 25260Sstevel@tonic-gate return (snprintf(s, n, fmt, 25273779Sdmick cpi->cpi_vendorstr, cpi->cpi_std[1].cp_eax, 25283779Sdmick cpi->cpi_family, cpi->cpi_model, 25290Sstevel@tonic-gate cpi->cpi_step, cpu->cpu_type_info.pi_clock)); 25300Sstevel@tonic-gate } 25310Sstevel@tonic-gate 25320Sstevel@tonic-gate const char * 25330Sstevel@tonic-gate cpuid_getvendorstr(cpu_t *cpu) 25340Sstevel@tonic-gate { 25350Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 25360Sstevel@tonic-gate return ((const char *)cpu->cpu_m.mcpu_cpi->cpi_vendorstr); 25370Sstevel@tonic-gate } 25380Sstevel@tonic-gate 25390Sstevel@tonic-gate uint_t 25400Sstevel@tonic-gate cpuid_getvendor(cpu_t *cpu) 25410Sstevel@tonic-gate { 25420Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 25430Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_vendor); 25440Sstevel@tonic-gate } 25450Sstevel@tonic-gate 25460Sstevel@tonic-gate uint_t 25470Sstevel@tonic-gate cpuid_getfamily(cpu_t *cpu) 25480Sstevel@tonic-gate { 25490Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 25500Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_family); 25510Sstevel@tonic-gate } 25520Sstevel@tonic-gate 25530Sstevel@tonic-gate uint_t 25540Sstevel@tonic-gate cpuid_getmodel(cpu_t *cpu) 25550Sstevel@tonic-gate { 25560Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 25570Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_model); 25580Sstevel@tonic-gate } 25590Sstevel@tonic-gate 25600Sstevel@tonic-gate uint_t 25610Sstevel@tonic-gate cpuid_get_ncpu_per_chip(cpu_t *cpu) 25620Sstevel@tonic-gate { 25630Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 25640Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_ncpu_per_chip); 25650Sstevel@tonic-gate } 25660Sstevel@tonic-gate 25670Sstevel@tonic-gate uint_t 25681228Sandrei cpuid_get_ncore_per_chip(cpu_t *cpu) 25691228Sandrei { 25701228Sandrei ASSERT(cpuid_checkpass(cpu, 1)); 25711228Sandrei return (cpu->cpu_m.mcpu_cpi->cpi_ncore_per_chip); 25721228Sandrei } 25731228Sandrei 25741228Sandrei uint_t 25754606Sesaxe cpuid_get_ncpu_sharing_last_cache(cpu_t *cpu) 25764606Sesaxe { 25774606Sesaxe ASSERT(cpuid_checkpass(cpu, 2)); 25784606Sesaxe return (cpu->cpu_m.mcpu_cpi->cpi_ncpu_shr_last_cache); 25794606Sesaxe } 25804606Sesaxe 25814606Sesaxe id_t 25824606Sesaxe cpuid_get_last_lvl_cacheid(cpu_t *cpu) 25834606Sesaxe { 25844606Sesaxe ASSERT(cpuid_checkpass(cpu, 2)); 25854606Sesaxe return (cpu->cpu_m.mcpu_cpi->cpi_last_lvl_cacheid); 25864606Sesaxe } 25874606Sesaxe 25884606Sesaxe uint_t 25890Sstevel@tonic-gate cpuid_getstep(cpu_t *cpu) 25900Sstevel@tonic-gate { 25910Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 25920Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_step); 25930Sstevel@tonic-gate } 25940Sstevel@tonic-gate 25954581Ssherrym uint_t 25964581Ssherrym cpuid_getsig(struct cpu *cpu) 25974581Ssherrym { 25984581Ssherrym ASSERT(cpuid_checkpass(cpu, 1)); 25994581Ssherrym return (cpu->cpu_m.mcpu_cpi->cpi_std[1].cp_eax); 26004581Ssherrym } 26014581Ssherrym 26022869Sgavinm uint32_t 26032869Sgavinm cpuid_getchiprev(struct cpu *cpu) 26042869Sgavinm { 26052869Sgavinm ASSERT(cpuid_checkpass(cpu, 1)); 26062869Sgavinm return (cpu->cpu_m.mcpu_cpi->cpi_chiprev); 26072869Sgavinm } 26082869Sgavinm 26092869Sgavinm const char * 26102869Sgavinm cpuid_getchiprevstr(struct cpu *cpu) 26112869Sgavinm { 26122869Sgavinm ASSERT(cpuid_checkpass(cpu, 1)); 26132869Sgavinm return (cpu->cpu_m.mcpu_cpi->cpi_chiprevstr); 26142869Sgavinm } 26152869Sgavinm 26162869Sgavinm uint32_t 26172869Sgavinm cpuid_getsockettype(struct cpu *cpu) 26182869Sgavinm { 26192869Sgavinm ASSERT(cpuid_checkpass(cpu, 1)); 26202869Sgavinm return (cpu->cpu_m.mcpu_cpi->cpi_socket); 26212869Sgavinm } 26222869Sgavinm 26239482SKuriakose.Kuruvilla@Sun.COM const char * 26249482SKuriakose.Kuruvilla@Sun.COM cpuid_getsocketstr(cpu_t *cpu) 26259482SKuriakose.Kuruvilla@Sun.COM { 26269482SKuriakose.Kuruvilla@Sun.COM static const char *socketstr = NULL; 26279482SKuriakose.Kuruvilla@Sun.COM struct cpuid_info *cpi; 26289482SKuriakose.Kuruvilla@Sun.COM 26299482SKuriakose.Kuruvilla@Sun.COM ASSERT(cpuid_checkpass(cpu, 1)); 26309482SKuriakose.Kuruvilla@Sun.COM cpi = cpu->cpu_m.mcpu_cpi; 26319482SKuriakose.Kuruvilla@Sun.COM 26329482SKuriakose.Kuruvilla@Sun.COM /* Assume that socket types are the same across the system */ 26339482SKuriakose.Kuruvilla@Sun.COM if (socketstr == NULL) 26349482SKuriakose.Kuruvilla@Sun.COM socketstr = _cpuid_sktstr(cpi->cpi_vendor, cpi->cpi_family, 26359482SKuriakose.Kuruvilla@Sun.COM cpi->cpi_model, cpi->cpi_step); 26369482SKuriakose.Kuruvilla@Sun.COM 26379482SKuriakose.Kuruvilla@Sun.COM 26389482SKuriakose.Kuruvilla@Sun.COM return (socketstr); 26399482SKuriakose.Kuruvilla@Sun.COM } 26409482SKuriakose.Kuruvilla@Sun.COM 26413434Sesaxe int 26423434Sesaxe cpuid_get_chipid(cpu_t *cpu) 26430Sstevel@tonic-gate { 26440Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 26450Sstevel@tonic-gate 26461228Sandrei if (cpuid_is_cmt(cpu)) 26470Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_chipid); 26480Sstevel@tonic-gate return (cpu->cpu_id); 26490Sstevel@tonic-gate } 26500Sstevel@tonic-gate 26511228Sandrei id_t 26523434Sesaxe cpuid_get_coreid(cpu_t *cpu) 26531228Sandrei { 26541228Sandrei ASSERT(cpuid_checkpass(cpu, 1)); 26551228Sandrei return (cpu->cpu_m.mcpu_cpi->cpi_coreid); 26561228Sandrei } 26571228Sandrei 26580Sstevel@tonic-gate int 26595870Sgavinm cpuid_get_pkgcoreid(cpu_t *cpu) 26605870Sgavinm { 26615870Sgavinm ASSERT(cpuid_checkpass(cpu, 1)); 26625870Sgavinm return (cpu->cpu_m.mcpu_cpi->cpi_pkgcoreid); 26635870Sgavinm } 26645870Sgavinm 26655870Sgavinm int 26663434Sesaxe cpuid_get_clogid(cpu_t *cpu) 26670Sstevel@tonic-gate { 26680Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 26690Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_clogid); 26700Sstevel@tonic-gate } 26710Sstevel@tonic-gate 2672*11389SAlexander.Kolbasov@Sun.COM int 2673*11389SAlexander.Kolbasov@Sun.COM cpuid_get_cacheid(cpu_t *cpu) 2674*11389SAlexander.Kolbasov@Sun.COM { 2675*11389SAlexander.Kolbasov@Sun.COM ASSERT(cpuid_checkpass(cpu, 1)); 2676*11389SAlexander.Kolbasov@Sun.COM return (cpu->cpu_m.mcpu_cpi->cpi_last_lvl_cacheid); 2677*11389SAlexander.Kolbasov@Sun.COM } 2678*11389SAlexander.Kolbasov@Sun.COM 267910947SSrihari.Venkatesan@Sun.COM uint_t 268010947SSrihari.Venkatesan@Sun.COM cpuid_get_procnodeid(cpu_t *cpu) 268110947SSrihari.Venkatesan@Sun.COM { 268210947SSrihari.Venkatesan@Sun.COM ASSERT(cpuid_checkpass(cpu, 1)); 268310947SSrihari.Venkatesan@Sun.COM return (cpu->cpu_m.mcpu_cpi->cpi_procnodeid); 268410947SSrihari.Venkatesan@Sun.COM } 268510947SSrihari.Venkatesan@Sun.COM 268610947SSrihari.Venkatesan@Sun.COM uint_t 268710947SSrihari.Venkatesan@Sun.COM cpuid_get_procnodes_per_pkg(cpu_t *cpu) 268810947SSrihari.Venkatesan@Sun.COM { 268910947SSrihari.Venkatesan@Sun.COM ASSERT(cpuid_checkpass(cpu, 1)); 269010947SSrihari.Venkatesan@Sun.COM return (cpu->cpu_m.mcpu_cpi->cpi_procnodes_per_pkg); 269110947SSrihari.Venkatesan@Sun.COM } 269210947SSrihari.Venkatesan@Sun.COM 269310080SJoe.Bonasera@sun.com /*ARGSUSED*/ 269410080SJoe.Bonasera@sun.com int 269510080SJoe.Bonasera@sun.com cpuid_have_cr8access(cpu_t *cpu) 269610080SJoe.Bonasera@sun.com { 269710080SJoe.Bonasera@sun.com #if defined(__amd64) 269810080SJoe.Bonasera@sun.com return (1); 269910080SJoe.Bonasera@sun.com #else 270010080SJoe.Bonasera@sun.com struct cpuid_info *cpi; 270110080SJoe.Bonasera@sun.com 270210080SJoe.Bonasera@sun.com ASSERT(cpu != NULL); 270310080SJoe.Bonasera@sun.com cpi = cpu->cpu_m.mcpu_cpi; 270410080SJoe.Bonasera@sun.com if (cpi->cpi_vendor == X86_VENDOR_AMD && cpi->cpi_maxeax >= 1 && 270510080SJoe.Bonasera@sun.com (CPI_FEATURES_XTD_ECX(cpi) & CPUID_AMD_ECX_CR8D) != 0) 270610080SJoe.Bonasera@sun.com return (1); 270710080SJoe.Bonasera@sun.com return (0); 270810080SJoe.Bonasera@sun.com #endif 270910080SJoe.Bonasera@sun.com } 271010080SJoe.Bonasera@sun.com 27119652SMichael.Corcoran@Sun.COM uint32_t 27129652SMichael.Corcoran@Sun.COM cpuid_get_apicid(cpu_t *cpu) 27139652SMichael.Corcoran@Sun.COM { 27149652SMichael.Corcoran@Sun.COM ASSERT(cpuid_checkpass(cpu, 1)); 27159652SMichael.Corcoran@Sun.COM if (cpu->cpu_m.mcpu_cpi->cpi_maxeax < 1) { 27169652SMichael.Corcoran@Sun.COM return (UINT32_MAX); 27179652SMichael.Corcoran@Sun.COM } else { 27189652SMichael.Corcoran@Sun.COM return (cpu->cpu_m.mcpu_cpi->cpi_apicid); 27199652SMichael.Corcoran@Sun.COM } 27209652SMichael.Corcoran@Sun.COM } 27219652SMichael.Corcoran@Sun.COM 27220Sstevel@tonic-gate void 27230Sstevel@tonic-gate cpuid_get_addrsize(cpu_t *cpu, uint_t *pabits, uint_t *vabits) 27240Sstevel@tonic-gate { 27250Sstevel@tonic-gate struct cpuid_info *cpi; 27260Sstevel@tonic-gate 27270Sstevel@tonic-gate if (cpu == NULL) 27280Sstevel@tonic-gate cpu = CPU; 27290Sstevel@tonic-gate cpi = cpu->cpu_m.mcpu_cpi; 27300Sstevel@tonic-gate 27310Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 27320Sstevel@tonic-gate 27330Sstevel@tonic-gate if (pabits) 27340Sstevel@tonic-gate *pabits = cpi->cpi_pabits; 27350Sstevel@tonic-gate if (vabits) 27360Sstevel@tonic-gate *vabits = cpi->cpi_vabits; 27370Sstevel@tonic-gate } 27380Sstevel@tonic-gate 27390Sstevel@tonic-gate /* 27400Sstevel@tonic-gate * Returns the number of data TLB entries for a corresponding 27410Sstevel@tonic-gate * pagesize. If it can't be computed, or isn't known, the 27420Sstevel@tonic-gate * routine returns zero. If you ask about an architecturally 27430Sstevel@tonic-gate * impossible pagesize, the routine will panic (so that the 27440Sstevel@tonic-gate * hat implementor knows that things are inconsistent.) 27450Sstevel@tonic-gate */ 27460Sstevel@tonic-gate uint_t 27470Sstevel@tonic-gate cpuid_get_dtlb_nent(cpu_t *cpu, size_t pagesize) 27480Sstevel@tonic-gate { 27490Sstevel@tonic-gate struct cpuid_info *cpi; 27500Sstevel@tonic-gate uint_t dtlb_nent = 0; 27510Sstevel@tonic-gate 27520Sstevel@tonic-gate if (cpu == NULL) 27530Sstevel@tonic-gate cpu = CPU; 27540Sstevel@tonic-gate cpi = cpu->cpu_m.mcpu_cpi; 27550Sstevel@tonic-gate 27560Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 27570Sstevel@tonic-gate 27580Sstevel@tonic-gate /* 27590Sstevel@tonic-gate * Check the L2 TLB info 27600Sstevel@tonic-gate */ 27610Sstevel@tonic-gate if (cpi->cpi_xmaxeax >= 0x80000006) { 27621228Sandrei struct cpuid_regs *cp = &cpi->cpi_extd[6]; 27630Sstevel@tonic-gate 27640Sstevel@tonic-gate switch (pagesize) { 27650Sstevel@tonic-gate 27660Sstevel@tonic-gate case 4 * 1024: 27670Sstevel@tonic-gate /* 27680Sstevel@tonic-gate * All zero in the top 16 bits of the register 27690Sstevel@tonic-gate * indicates a unified TLB. Size is in low 16 bits. 27700Sstevel@tonic-gate */ 27710Sstevel@tonic-gate if ((cp->cp_ebx & 0xffff0000) == 0) 27720Sstevel@tonic-gate dtlb_nent = cp->cp_ebx & 0x0000ffff; 27730Sstevel@tonic-gate else 27740Sstevel@tonic-gate dtlb_nent = BITX(cp->cp_ebx, 27, 16); 27750Sstevel@tonic-gate break; 27760Sstevel@tonic-gate 27770Sstevel@tonic-gate case 2 * 1024 * 1024: 27780Sstevel@tonic-gate if ((cp->cp_eax & 0xffff0000) == 0) 27790Sstevel@tonic-gate dtlb_nent = cp->cp_eax & 0x0000ffff; 27800Sstevel@tonic-gate else 27810Sstevel@tonic-gate dtlb_nent = BITX(cp->cp_eax, 27, 16); 27820Sstevel@tonic-gate break; 27830Sstevel@tonic-gate 27840Sstevel@tonic-gate default: 27850Sstevel@tonic-gate panic("unknown L2 pagesize"); 27860Sstevel@tonic-gate /*NOTREACHED*/ 27870Sstevel@tonic-gate } 27880Sstevel@tonic-gate } 27890Sstevel@tonic-gate 27900Sstevel@tonic-gate if (dtlb_nent != 0) 27910Sstevel@tonic-gate return (dtlb_nent); 27920Sstevel@tonic-gate 27930Sstevel@tonic-gate /* 27940Sstevel@tonic-gate * No L2 TLB support for this size, try L1. 27950Sstevel@tonic-gate */ 27960Sstevel@tonic-gate if (cpi->cpi_xmaxeax >= 0x80000005) { 27971228Sandrei struct cpuid_regs *cp = &cpi->cpi_extd[5]; 27980Sstevel@tonic-gate 27990Sstevel@tonic-gate switch (pagesize) { 28000Sstevel@tonic-gate case 4 * 1024: 28010Sstevel@tonic-gate dtlb_nent = BITX(cp->cp_ebx, 23, 16); 28020Sstevel@tonic-gate break; 28030Sstevel@tonic-gate case 2 * 1024 * 1024: 28040Sstevel@tonic-gate dtlb_nent = BITX(cp->cp_eax, 23, 16); 28050Sstevel@tonic-gate break; 28060Sstevel@tonic-gate default: 28070Sstevel@tonic-gate panic("unknown L1 d-TLB pagesize"); 28080Sstevel@tonic-gate /*NOTREACHED*/ 28090Sstevel@tonic-gate } 28100Sstevel@tonic-gate } 28110Sstevel@tonic-gate 28120Sstevel@tonic-gate return (dtlb_nent); 28130Sstevel@tonic-gate } 28140Sstevel@tonic-gate 28150Sstevel@tonic-gate /* 28160Sstevel@tonic-gate * Return 0 if the erratum is not present or not applicable, positive 28170Sstevel@tonic-gate * if it is, and negative if the status of the erratum is unknown. 28180Sstevel@tonic-gate * 28190Sstevel@tonic-gate * See "Revision Guide for AMD Athlon(tm) 64 and AMD Opteron(tm) 2820359Skucharsk * Processors" #25759, Rev 3.57, August 2005 28210Sstevel@tonic-gate */ 28220Sstevel@tonic-gate int 28230Sstevel@tonic-gate cpuid_opteron_erratum(cpu_t *cpu, uint_t erratum) 28240Sstevel@tonic-gate { 28250Sstevel@tonic-gate struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 28261228Sandrei uint_t eax; 28270Sstevel@tonic-gate 28282584Ssethg /* 28292584Ssethg * Bail out if this CPU isn't an AMD CPU, or if it's 28302584Ssethg * a legacy (32-bit) AMD CPU. 28312584Ssethg */ 28322584Ssethg if (cpi->cpi_vendor != X86_VENDOR_AMD || 28334265Skchow cpi->cpi_family == 4 || cpi->cpi_family == 5 || 28344265Skchow cpi->cpi_family == 6) 28352869Sgavinm 28360Sstevel@tonic-gate return (0); 28370Sstevel@tonic-gate 28380Sstevel@tonic-gate eax = cpi->cpi_std[1].cp_eax; 28390Sstevel@tonic-gate 28400Sstevel@tonic-gate #define SH_B0(eax) (eax == 0xf40 || eax == 0xf50) 28410Sstevel@tonic-gate #define SH_B3(eax) (eax == 0xf51) 28421582Skchow #define B(eax) (SH_B0(eax) || SH_B3(eax)) 28430Sstevel@tonic-gate 28440Sstevel@tonic-gate #define SH_C0(eax) (eax == 0xf48 || eax == 0xf58) 28450Sstevel@tonic-gate 28460Sstevel@tonic-gate #define SH_CG(eax) (eax == 0xf4a || eax == 0xf5a || eax == 0xf7a) 28470Sstevel@tonic-gate #define DH_CG(eax) (eax == 0xfc0 || eax == 0xfe0 || eax == 0xff0) 28480Sstevel@tonic-gate #define CH_CG(eax) (eax == 0xf82 || eax == 0xfb2) 28491582Skchow #define CG(eax) (SH_CG(eax) || DH_CG(eax) || CH_CG(eax)) 28500Sstevel@tonic-gate 28510Sstevel@tonic-gate #define SH_D0(eax) (eax == 0x10f40 || eax == 0x10f50 || eax == 0x10f70) 28520Sstevel@tonic-gate #define DH_D0(eax) (eax == 0x10fc0 || eax == 0x10ff0) 28530Sstevel@tonic-gate #define CH_D0(eax) (eax == 0x10f80 || eax == 0x10fb0) 28541582Skchow #define D0(eax) (SH_D0(eax) || DH_D0(eax) || CH_D0(eax)) 28550Sstevel@tonic-gate 28560Sstevel@tonic-gate #define SH_E0(eax) (eax == 0x20f50 || eax == 0x20f40 || eax == 0x20f70) 28570Sstevel@tonic-gate #define JH_E1(eax) (eax == 0x20f10) /* JH8_E0 had 0x20f30 */ 28580Sstevel@tonic-gate #define DH_E3(eax) (eax == 0x20fc0 || eax == 0x20ff0) 28590Sstevel@tonic-gate #define SH_E4(eax) (eax == 0x20f51 || eax == 0x20f71) 28600Sstevel@tonic-gate #define BH_E4(eax) (eax == 0x20fb1) 28610Sstevel@tonic-gate #define SH_E5(eax) (eax == 0x20f42) 28620Sstevel@tonic-gate #define DH_E6(eax) (eax == 0x20ff2 || eax == 0x20fc2) 28630Sstevel@tonic-gate #define JH_E6(eax) (eax == 0x20f12 || eax == 0x20f32) 28641582Skchow #define EX(eax) (SH_E0(eax) || JH_E1(eax) || DH_E3(eax) || \ 28651582Skchow SH_E4(eax) || BH_E4(eax) || SH_E5(eax) || \ 28661582Skchow DH_E6(eax) || JH_E6(eax)) 28670Sstevel@tonic-gate 28686691Skchow #define DR_AX(eax) (eax == 0x100f00 || eax == 0x100f01 || eax == 0x100f02) 28696691Skchow #define DR_B0(eax) (eax == 0x100f20) 28706691Skchow #define DR_B1(eax) (eax == 0x100f21) 28716691Skchow #define DR_BA(eax) (eax == 0x100f2a) 28726691Skchow #define DR_B2(eax) (eax == 0x100f22) 28736691Skchow #define DR_B3(eax) (eax == 0x100f23) 28746691Skchow #define RB_C0(eax) (eax == 0x100f40) 28756691Skchow 28760Sstevel@tonic-gate switch (erratum) { 28770Sstevel@tonic-gate case 1: 28784265Skchow return (cpi->cpi_family < 0x10); 28790Sstevel@tonic-gate case 51: /* what does the asterisk mean? */ 28800Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax)); 28810Sstevel@tonic-gate case 52: 28820Sstevel@tonic-gate return (B(eax)); 28830Sstevel@tonic-gate case 57: 28846691Skchow return (cpi->cpi_family <= 0x11); 28850Sstevel@tonic-gate case 58: 28860Sstevel@tonic-gate return (B(eax)); 28870Sstevel@tonic-gate case 60: 28886691Skchow return (cpi->cpi_family <= 0x11); 28890Sstevel@tonic-gate case 61: 28900Sstevel@tonic-gate case 62: 28910Sstevel@tonic-gate case 63: 28920Sstevel@tonic-gate case 64: 28930Sstevel@tonic-gate case 65: 28940Sstevel@tonic-gate case 66: 28950Sstevel@tonic-gate case 68: 28960Sstevel@tonic-gate case 69: 28970Sstevel@tonic-gate case 70: 28980Sstevel@tonic-gate case 71: 28990Sstevel@tonic-gate return (B(eax)); 29000Sstevel@tonic-gate case 72: 29010Sstevel@tonic-gate return (SH_B0(eax)); 29020Sstevel@tonic-gate case 74: 29030Sstevel@tonic-gate return (B(eax)); 29040Sstevel@tonic-gate case 75: 29054265Skchow return (cpi->cpi_family < 0x10); 29060Sstevel@tonic-gate case 76: 29070Sstevel@tonic-gate return (B(eax)); 29080Sstevel@tonic-gate case 77: 29096691Skchow return (cpi->cpi_family <= 0x11); 29100Sstevel@tonic-gate case 78: 29110Sstevel@tonic-gate return (B(eax) || SH_C0(eax)); 29120Sstevel@tonic-gate case 79: 29130Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax) || EX(eax)); 29140Sstevel@tonic-gate case 80: 29150Sstevel@tonic-gate case 81: 29160Sstevel@tonic-gate case 82: 29170Sstevel@tonic-gate return (B(eax)); 29180Sstevel@tonic-gate case 83: 29190Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax)); 29200Sstevel@tonic-gate case 85: 29214265Skchow return (cpi->cpi_family < 0x10); 29220Sstevel@tonic-gate case 86: 29230Sstevel@tonic-gate return (SH_C0(eax) || CG(eax)); 29240Sstevel@tonic-gate case 88: 29250Sstevel@tonic-gate #if !defined(__amd64) 29260Sstevel@tonic-gate return (0); 29270Sstevel@tonic-gate #else 29280Sstevel@tonic-gate return (B(eax) || SH_C0(eax)); 29290Sstevel@tonic-gate #endif 29300Sstevel@tonic-gate case 89: 29314265Skchow return (cpi->cpi_family < 0x10); 29320Sstevel@tonic-gate case 90: 29330Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax)); 29340Sstevel@tonic-gate case 91: 29350Sstevel@tonic-gate case 92: 29360Sstevel@tonic-gate return (B(eax) || SH_C0(eax)); 29370Sstevel@tonic-gate case 93: 29380Sstevel@tonic-gate return (SH_C0(eax)); 29390Sstevel@tonic-gate case 94: 29400Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax)); 29410Sstevel@tonic-gate case 95: 29420Sstevel@tonic-gate #if !defined(__amd64) 29430Sstevel@tonic-gate return (0); 29440Sstevel@tonic-gate #else 29450Sstevel@tonic-gate return (B(eax) || SH_C0(eax)); 29460Sstevel@tonic-gate #endif 29470Sstevel@tonic-gate case 96: 29480Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax)); 29490Sstevel@tonic-gate case 97: 29500Sstevel@tonic-gate case 98: 29510Sstevel@tonic-gate return (SH_C0(eax) || CG(eax)); 29520Sstevel@tonic-gate case 99: 29530Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax)); 29540Sstevel@tonic-gate case 100: 29550Sstevel@tonic-gate return (B(eax) || SH_C0(eax)); 29560Sstevel@tonic-gate case 101: 29570Sstevel@tonic-gate case 103: 29580Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax)); 29590Sstevel@tonic-gate case 104: 29600Sstevel@tonic-gate return (SH_C0(eax) || CG(eax) || D0(eax)); 29610Sstevel@tonic-gate case 105: 29620Sstevel@tonic-gate case 106: 29630Sstevel@tonic-gate case 107: 29640Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax)); 29650Sstevel@tonic-gate case 108: 29660Sstevel@tonic-gate return (DH_CG(eax)); 29670Sstevel@tonic-gate case 109: 29680Sstevel@tonic-gate return (SH_C0(eax) || CG(eax) || D0(eax)); 29690Sstevel@tonic-gate case 110: 29700Sstevel@tonic-gate return (D0(eax) || EX(eax)); 29710Sstevel@tonic-gate case 111: 29720Sstevel@tonic-gate return (CG(eax)); 29730Sstevel@tonic-gate case 112: 29740Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax) || EX(eax)); 29750Sstevel@tonic-gate case 113: 29760Sstevel@tonic-gate return (eax == 0x20fc0); 29770Sstevel@tonic-gate case 114: 29780Sstevel@tonic-gate return (SH_E0(eax) || JH_E1(eax) || DH_E3(eax)); 29790Sstevel@tonic-gate case 115: 29800Sstevel@tonic-gate return (SH_E0(eax) || JH_E1(eax)); 29810Sstevel@tonic-gate case 116: 29820Sstevel@tonic-gate return (SH_E0(eax) || JH_E1(eax) || DH_E3(eax)); 29830Sstevel@tonic-gate case 117: 29840Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax)); 29850Sstevel@tonic-gate case 118: 29860Sstevel@tonic-gate return (SH_E0(eax) || JH_E1(eax) || SH_E4(eax) || BH_E4(eax) || 29870Sstevel@tonic-gate JH_E6(eax)); 29880Sstevel@tonic-gate case 121: 29890Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax) || EX(eax)); 29900Sstevel@tonic-gate case 122: 29916691Skchow return (cpi->cpi_family < 0x10 || cpi->cpi_family == 0x11); 29920Sstevel@tonic-gate case 123: 29930Sstevel@tonic-gate return (JH_E1(eax) || BH_E4(eax) || JH_E6(eax)); 2994359Skucharsk case 131: 29954265Skchow return (cpi->cpi_family < 0x10); 2996938Sesaxe case 6336786: 2997938Sesaxe /* 2998938Sesaxe * Test for AdvPowerMgmtInfo.TscPStateInvariant 29994265Skchow * if this is a K8 family or newer processor 3000938Sesaxe */ 3001938Sesaxe if (CPI_FAMILY(cpi) == 0xf) { 30021228Sandrei struct cpuid_regs regs; 30031228Sandrei regs.cp_eax = 0x80000007; 30041228Sandrei (void) __cpuid_insn(®s); 30051228Sandrei return (!(regs.cp_edx & 0x100)); 3006938Sesaxe } 3007938Sesaxe return (0); 30081582Skchow case 6323525: 30091582Skchow return (((((eax >> 12) & 0xff00) + (eax & 0xf00)) | 30101582Skchow (((eax >> 4) & 0xf) | ((eax >> 12) & 0xf0))) < 0xf40); 30111582Skchow 30126691Skchow case 6671130: 30136691Skchow /* 30146691Skchow * check for processors (pre-Shanghai) that do not provide 30156691Skchow * optimal management of 1gb ptes in its tlb. 30166691Skchow */ 30176691Skchow return (cpi->cpi_family == 0x10 && cpi->cpi_model < 4); 30186691Skchow 30196691Skchow case 298: 30206691Skchow return (DR_AX(eax) || DR_B0(eax) || DR_B1(eax) || DR_BA(eax) || 30216691Skchow DR_B2(eax) || RB_C0(eax)); 30226691Skchow 30236691Skchow default: 30246691Skchow return (-1); 30256691Skchow 30266691Skchow } 30276691Skchow } 30286691Skchow 30296691Skchow /* 30306691Skchow * Determine if specified erratum is present via OSVW (OS Visible Workaround). 30316691Skchow * Return 1 if erratum is present, 0 if not present and -1 if indeterminate. 30326691Skchow */ 30336691Skchow int 30346691Skchow osvw_opteron_erratum(cpu_t *cpu, uint_t erratum) 30356691Skchow { 30366691Skchow struct cpuid_info *cpi; 30376691Skchow uint_t osvwid; 30386691Skchow static int osvwfeature = -1; 30396691Skchow uint64_t osvwlength; 30406691Skchow 30416691Skchow 30426691Skchow cpi = cpu->cpu_m.mcpu_cpi; 30436691Skchow 30446691Skchow /* confirm OSVW supported */ 30456691Skchow if (osvwfeature == -1) { 30466691Skchow osvwfeature = cpi->cpi_extd[1].cp_ecx & CPUID_AMD_ECX_OSVW; 30476691Skchow } else { 30486691Skchow /* assert that osvw feature setting is consistent on all cpus */ 30496691Skchow ASSERT(osvwfeature == 30506691Skchow (cpi->cpi_extd[1].cp_ecx & CPUID_AMD_ECX_OSVW)); 30516691Skchow } 30526691Skchow if (!osvwfeature) 30536691Skchow return (-1); 30546691Skchow 30556691Skchow osvwlength = rdmsr(MSR_AMD_OSVW_ID_LEN) & OSVW_ID_LEN_MASK; 30566691Skchow 30576691Skchow switch (erratum) { 30586691Skchow case 298: /* osvwid is 0 */ 30596691Skchow osvwid = 0; 30606691Skchow if (osvwlength <= (uint64_t)osvwid) { 30616691Skchow /* osvwid 0 is unknown */ 30626691Skchow return (-1); 30636691Skchow } 30646691Skchow 30656691Skchow /* 30666691Skchow * Check the OSVW STATUS MSR to determine the state 30676691Skchow * of the erratum where: 30686691Skchow * 0 - fixed by HW 30696691Skchow * 1 - BIOS has applied the workaround when BIOS 30706691Skchow * workaround is available. (Or for other errata, 30716691Skchow * OS workaround is required.) 30726691Skchow * For a value of 1, caller will confirm that the 30736691Skchow * erratum 298 workaround has indeed been applied by BIOS. 30746691Skchow * 30756691Skchow * A 1 may be set in cpus that have a HW fix 30766691Skchow * in a mixed cpu system. Regarding erratum 298: 30776691Skchow * In a multiprocessor platform, the workaround above 30786691Skchow * should be applied to all processors regardless of 30796691Skchow * silicon revision when an affected processor is 30806691Skchow * present. 30816691Skchow */ 30826691Skchow 30836691Skchow return (rdmsr(MSR_AMD_OSVW_STATUS + 30846691Skchow (osvwid / OSVW_ID_CNT_PER_MSR)) & 30856691Skchow (1ULL << (osvwid % OSVW_ID_CNT_PER_MSR))); 30866691Skchow 30870Sstevel@tonic-gate default: 30880Sstevel@tonic-gate return (-1); 30890Sstevel@tonic-gate } 30900Sstevel@tonic-gate } 30910Sstevel@tonic-gate 30920Sstevel@tonic-gate static const char assoc_str[] = "associativity"; 30930Sstevel@tonic-gate static const char line_str[] = "line-size"; 30940Sstevel@tonic-gate static const char size_str[] = "size"; 30950Sstevel@tonic-gate 30960Sstevel@tonic-gate static void 30970Sstevel@tonic-gate add_cache_prop(dev_info_t *devi, const char *label, const char *type, 30980Sstevel@tonic-gate uint32_t val) 30990Sstevel@tonic-gate { 31000Sstevel@tonic-gate char buf[128]; 31010Sstevel@tonic-gate 31020Sstevel@tonic-gate /* 31030Sstevel@tonic-gate * ndi_prop_update_int() is used because it is desirable for 31040Sstevel@tonic-gate * DDI_PROP_HW_DEF and DDI_PROP_DONTSLEEP to be set. 31050Sstevel@tonic-gate */ 31060Sstevel@tonic-gate if (snprintf(buf, sizeof (buf), "%s-%s", label, type) < sizeof (buf)) 31070Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, devi, buf, val); 31080Sstevel@tonic-gate } 31090Sstevel@tonic-gate 31100Sstevel@tonic-gate /* 31110Sstevel@tonic-gate * Intel-style cache/tlb description 31120Sstevel@tonic-gate * 31130Sstevel@tonic-gate * Standard cpuid level 2 gives a randomly ordered 31140Sstevel@tonic-gate * selection of tags that index into a table that describes 31150Sstevel@tonic-gate * cache and tlb properties. 31160Sstevel@tonic-gate */ 31170Sstevel@tonic-gate 31180Sstevel@tonic-gate static const char l1_icache_str[] = "l1-icache"; 31190Sstevel@tonic-gate static const char l1_dcache_str[] = "l1-dcache"; 31200Sstevel@tonic-gate static const char l2_cache_str[] = "l2-cache"; 31213446Smrj static const char l3_cache_str[] = "l3-cache"; 31220Sstevel@tonic-gate static const char itlb4k_str[] = "itlb-4K"; 31230Sstevel@tonic-gate static const char dtlb4k_str[] = "dtlb-4K"; 31246964Svd224797 static const char itlb2M_str[] = "itlb-2M"; 31250Sstevel@tonic-gate static const char itlb4M_str[] = "itlb-4M"; 31260Sstevel@tonic-gate static const char dtlb4M_str[] = "dtlb-4M"; 31276334Sksadhukh static const char dtlb24_str[] = "dtlb0-2M-4M"; 31280Sstevel@tonic-gate static const char itlb424_str[] = "itlb-4K-2M-4M"; 31296334Sksadhukh static const char itlb24_str[] = "itlb-2M-4M"; 31300Sstevel@tonic-gate static const char dtlb44_str[] = "dtlb-4K-4M"; 31310Sstevel@tonic-gate static const char sl1_dcache_str[] = "sectored-l1-dcache"; 31320Sstevel@tonic-gate static const char sl2_cache_str[] = "sectored-l2-cache"; 31330Sstevel@tonic-gate static const char itrace_str[] = "itrace-cache"; 31340Sstevel@tonic-gate static const char sl3_cache_str[] = "sectored-l3-cache"; 31356334Sksadhukh static const char sh_l2_tlb4k_str[] = "shared-l2-tlb-4k"; 31360Sstevel@tonic-gate 31370Sstevel@tonic-gate static const struct cachetab { 31380Sstevel@tonic-gate uint8_t ct_code; 31390Sstevel@tonic-gate uint8_t ct_assoc; 31400Sstevel@tonic-gate uint16_t ct_line_size; 31410Sstevel@tonic-gate size_t ct_size; 31420Sstevel@tonic-gate const char *ct_label; 31430Sstevel@tonic-gate } intel_ctab[] = { 31446964Svd224797 /* 31456964Svd224797 * maintain descending order! 31466964Svd224797 * 31476964Svd224797 * Codes ignored - Reason 31486964Svd224797 * ---------------------- 31496964Svd224797 * 40H - intel_cpuid_4_cache_info() disambiguates l2/l3 cache 31506964Svd224797 * f0H/f1H - Currently we do not interpret prefetch size by design 31516964Svd224797 */ 31526334Sksadhukh { 0xe4, 16, 64, 8*1024*1024, l3_cache_str}, 31536334Sksadhukh { 0xe3, 16, 64, 4*1024*1024, l3_cache_str}, 31546334Sksadhukh { 0xe2, 16, 64, 2*1024*1024, l3_cache_str}, 31556334Sksadhukh { 0xde, 12, 64, 6*1024*1024, l3_cache_str}, 31566334Sksadhukh { 0xdd, 12, 64, 3*1024*1024, l3_cache_str}, 31576334Sksadhukh { 0xdc, 12, 64, ((1*1024*1024)+(512*1024)), l3_cache_str}, 31586334Sksadhukh { 0xd8, 8, 64, 4*1024*1024, l3_cache_str}, 31596334Sksadhukh { 0xd7, 8, 64, 2*1024*1024, l3_cache_str}, 31606334Sksadhukh { 0xd6, 8, 64, 1*1024*1024, l3_cache_str}, 31616334Sksadhukh { 0xd2, 4, 64, 2*1024*1024, l3_cache_str}, 31626334Sksadhukh { 0xd1, 4, 64, 1*1024*1024, l3_cache_str}, 31636334Sksadhukh { 0xd0, 4, 64, 512*1024, l3_cache_str}, 31646334Sksadhukh { 0xca, 4, 0, 512, sh_l2_tlb4k_str}, 31656964Svd224797 { 0xc0, 4, 0, 8, dtlb44_str }, 31666964Svd224797 { 0xba, 4, 0, 64, dtlb4k_str }, 31673446Smrj { 0xb4, 4, 0, 256, dtlb4k_str }, 31680Sstevel@tonic-gate { 0xb3, 4, 0, 128, dtlb4k_str }, 31696334Sksadhukh { 0xb2, 4, 0, 64, itlb4k_str }, 31700Sstevel@tonic-gate { 0xb0, 4, 0, 128, itlb4k_str }, 31710Sstevel@tonic-gate { 0x87, 8, 64, 1024*1024, l2_cache_str}, 31720Sstevel@tonic-gate { 0x86, 4, 64, 512*1024, l2_cache_str}, 31730Sstevel@tonic-gate { 0x85, 8, 32, 2*1024*1024, l2_cache_str}, 31740Sstevel@tonic-gate { 0x84, 8, 32, 1024*1024, l2_cache_str}, 31750Sstevel@tonic-gate { 0x83, 8, 32, 512*1024, l2_cache_str}, 31760Sstevel@tonic-gate { 0x82, 8, 32, 256*1024, l2_cache_str}, 31776964Svd224797 { 0x80, 8, 64, 512*1024, l2_cache_str}, 31780Sstevel@tonic-gate { 0x7f, 2, 64, 512*1024, l2_cache_str}, 31790Sstevel@tonic-gate { 0x7d, 8, 64, 2*1024*1024, sl2_cache_str}, 31800Sstevel@tonic-gate { 0x7c, 8, 64, 1024*1024, sl2_cache_str}, 31810Sstevel@tonic-gate { 0x7b, 8, 64, 512*1024, sl2_cache_str}, 31820Sstevel@tonic-gate { 0x7a, 8, 64, 256*1024, sl2_cache_str}, 31830Sstevel@tonic-gate { 0x79, 8, 64, 128*1024, sl2_cache_str}, 31840Sstevel@tonic-gate { 0x78, 8, 64, 1024*1024, l2_cache_str}, 31853446Smrj { 0x73, 8, 0, 64*1024, itrace_str}, 31860Sstevel@tonic-gate { 0x72, 8, 0, 32*1024, itrace_str}, 31870Sstevel@tonic-gate { 0x71, 8, 0, 16*1024, itrace_str}, 31880Sstevel@tonic-gate { 0x70, 8, 0, 12*1024, itrace_str}, 31890Sstevel@tonic-gate { 0x68, 4, 64, 32*1024, sl1_dcache_str}, 31900Sstevel@tonic-gate { 0x67, 4, 64, 16*1024, sl1_dcache_str}, 31910Sstevel@tonic-gate { 0x66, 4, 64, 8*1024, sl1_dcache_str}, 31920Sstevel@tonic-gate { 0x60, 8, 64, 16*1024, sl1_dcache_str}, 31930Sstevel@tonic-gate { 0x5d, 0, 0, 256, dtlb44_str}, 31940Sstevel@tonic-gate { 0x5c, 0, 0, 128, dtlb44_str}, 31950Sstevel@tonic-gate { 0x5b, 0, 0, 64, dtlb44_str}, 31966334Sksadhukh { 0x5a, 4, 0, 32, dtlb24_str}, 31976964Svd224797 { 0x59, 0, 0, 16, dtlb4k_str}, 31986964Svd224797 { 0x57, 4, 0, 16, dtlb4k_str}, 31996964Svd224797 { 0x56, 4, 0, 16, dtlb4M_str}, 32006334Sksadhukh { 0x55, 0, 0, 7, itlb24_str}, 32010Sstevel@tonic-gate { 0x52, 0, 0, 256, itlb424_str}, 32020Sstevel@tonic-gate { 0x51, 0, 0, 128, itlb424_str}, 32030Sstevel@tonic-gate { 0x50, 0, 0, 64, itlb424_str}, 32046964Svd224797 { 0x4f, 0, 0, 32, itlb4k_str}, 32056964Svd224797 { 0x4e, 24, 64, 6*1024*1024, l2_cache_str}, 32063446Smrj { 0x4d, 16, 64, 16*1024*1024, l3_cache_str}, 32073446Smrj { 0x4c, 12, 64, 12*1024*1024, l3_cache_str}, 32083446Smrj { 0x4b, 16, 64, 8*1024*1024, l3_cache_str}, 32093446Smrj { 0x4a, 12, 64, 6*1024*1024, l3_cache_str}, 32103446Smrj { 0x49, 16, 64, 4*1024*1024, l3_cache_str}, 32116964Svd224797 { 0x48, 12, 64, 3*1024*1024, l2_cache_str}, 32123446Smrj { 0x47, 8, 64, 8*1024*1024, l3_cache_str}, 32133446Smrj { 0x46, 4, 64, 4*1024*1024, l3_cache_str}, 32140Sstevel@tonic-gate { 0x45, 4, 32, 2*1024*1024, l2_cache_str}, 32150Sstevel@tonic-gate { 0x44, 4, 32, 1024*1024, l2_cache_str}, 32160Sstevel@tonic-gate { 0x43, 4, 32, 512*1024, l2_cache_str}, 32170Sstevel@tonic-gate { 0x42, 4, 32, 256*1024, l2_cache_str}, 32180Sstevel@tonic-gate { 0x41, 4, 32, 128*1024, l2_cache_str}, 32193446Smrj { 0x3e, 4, 64, 512*1024, sl2_cache_str}, 32203446Smrj { 0x3d, 6, 64, 384*1024, sl2_cache_str}, 32210Sstevel@tonic-gate { 0x3c, 4, 64, 256*1024, sl2_cache_str}, 32220Sstevel@tonic-gate { 0x3b, 2, 64, 128*1024, sl2_cache_str}, 32233446Smrj { 0x3a, 6, 64, 192*1024, sl2_cache_str}, 32240Sstevel@tonic-gate { 0x39, 4, 64, 128*1024, sl2_cache_str}, 32250Sstevel@tonic-gate { 0x30, 8, 64, 32*1024, l1_icache_str}, 32260Sstevel@tonic-gate { 0x2c, 8, 64, 32*1024, l1_dcache_str}, 32270Sstevel@tonic-gate { 0x29, 8, 64, 4096*1024, sl3_cache_str}, 32280Sstevel@tonic-gate { 0x25, 8, 64, 2048*1024, sl3_cache_str}, 32290Sstevel@tonic-gate { 0x23, 8, 64, 1024*1024, sl3_cache_str}, 32300Sstevel@tonic-gate { 0x22, 4, 64, 512*1024, sl3_cache_str}, 32316964Svd224797 { 0x0e, 6, 64, 24*1024, l1_dcache_str}, 32326334Sksadhukh { 0x0d, 4, 32, 16*1024, l1_dcache_str}, 32330Sstevel@tonic-gate { 0x0c, 4, 32, 16*1024, l1_dcache_str}, 32343446Smrj { 0x0b, 4, 0, 4, itlb4M_str}, 32350Sstevel@tonic-gate { 0x0a, 2, 32, 8*1024, l1_dcache_str}, 32360Sstevel@tonic-gate { 0x08, 4, 32, 16*1024, l1_icache_str}, 32370Sstevel@tonic-gate { 0x06, 4, 32, 8*1024, l1_icache_str}, 32386964Svd224797 { 0x05, 4, 0, 32, dtlb4M_str}, 32390Sstevel@tonic-gate { 0x04, 4, 0, 8, dtlb4M_str}, 32400Sstevel@tonic-gate { 0x03, 4, 0, 64, dtlb4k_str}, 32410Sstevel@tonic-gate { 0x02, 4, 0, 2, itlb4M_str}, 32420Sstevel@tonic-gate { 0x01, 4, 0, 32, itlb4k_str}, 32430Sstevel@tonic-gate { 0 } 32440Sstevel@tonic-gate }; 32450Sstevel@tonic-gate 32460Sstevel@tonic-gate static const struct cachetab cyrix_ctab[] = { 32470Sstevel@tonic-gate { 0x70, 4, 0, 32, "tlb-4K" }, 32480Sstevel@tonic-gate { 0x80, 4, 16, 16*1024, "l1-cache" }, 32490Sstevel@tonic-gate { 0 } 32500Sstevel@tonic-gate }; 32510Sstevel@tonic-gate 32520Sstevel@tonic-gate /* 32530Sstevel@tonic-gate * Search a cache table for a matching entry 32540Sstevel@tonic-gate */ 32550Sstevel@tonic-gate static const struct cachetab * 32560Sstevel@tonic-gate find_cacheent(const struct cachetab *ct, uint_t code) 32570Sstevel@tonic-gate { 32580Sstevel@tonic-gate if (code != 0) { 32590Sstevel@tonic-gate for (; ct->ct_code != 0; ct++) 32600Sstevel@tonic-gate if (ct->ct_code <= code) 32610Sstevel@tonic-gate break; 32620Sstevel@tonic-gate if (ct->ct_code == code) 32630Sstevel@tonic-gate return (ct); 32640Sstevel@tonic-gate } 32650Sstevel@tonic-gate return (NULL); 32660Sstevel@tonic-gate } 32670Sstevel@tonic-gate 32680Sstevel@tonic-gate /* 32695438Sksadhukh * Populate cachetab entry with L2 or L3 cache-information using 32705438Sksadhukh * cpuid function 4. This function is called from intel_walk_cacheinfo() 32715438Sksadhukh * when descriptor 0x49 is encountered. It returns 0 if no such cache 32725438Sksadhukh * information is found. 32735438Sksadhukh */ 32745438Sksadhukh static int 32755438Sksadhukh intel_cpuid_4_cache_info(struct cachetab *ct, struct cpuid_info *cpi) 32765438Sksadhukh { 32775438Sksadhukh uint32_t level, i; 32785438Sksadhukh int ret = 0; 32795438Sksadhukh 32805438Sksadhukh for (i = 0; i < cpi->cpi_std_4_size; i++) { 32815438Sksadhukh level = CPI_CACHE_LVL(cpi->cpi_std_4[i]); 32825438Sksadhukh 32835438Sksadhukh if (level == 2 || level == 3) { 32845438Sksadhukh ct->ct_assoc = CPI_CACHE_WAYS(cpi->cpi_std_4[i]) + 1; 32855438Sksadhukh ct->ct_line_size = 32865438Sksadhukh CPI_CACHE_COH_LN_SZ(cpi->cpi_std_4[i]) + 1; 32875438Sksadhukh ct->ct_size = ct->ct_assoc * 32885438Sksadhukh (CPI_CACHE_PARTS(cpi->cpi_std_4[i]) + 1) * 32895438Sksadhukh ct->ct_line_size * 32905438Sksadhukh (cpi->cpi_std_4[i]->cp_ecx + 1); 32915438Sksadhukh 32925438Sksadhukh if (level == 2) { 32935438Sksadhukh ct->ct_label = l2_cache_str; 32945438Sksadhukh } else if (level == 3) { 32955438Sksadhukh ct->ct_label = l3_cache_str; 32965438Sksadhukh } 32975438Sksadhukh ret = 1; 32985438Sksadhukh } 32995438Sksadhukh } 33005438Sksadhukh 33015438Sksadhukh return (ret); 33025438Sksadhukh } 33035438Sksadhukh 33045438Sksadhukh /* 33050Sstevel@tonic-gate * Walk the cacheinfo descriptor, applying 'func' to every valid element 33060Sstevel@tonic-gate * The walk is terminated if the walker returns non-zero. 33070Sstevel@tonic-gate */ 33080Sstevel@tonic-gate static void 33090Sstevel@tonic-gate intel_walk_cacheinfo(struct cpuid_info *cpi, 33100Sstevel@tonic-gate void *arg, int (*func)(void *, const struct cachetab *)) 33110Sstevel@tonic-gate { 33120Sstevel@tonic-gate const struct cachetab *ct; 33136964Svd224797 struct cachetab des_49_ct, des_b1_ct; 33140Sstevel@tonic-gate uint8_t *dp; 33150Sstevel@tonic-gate int i; 33160Sstevel@tonic-gate 33170Sstevel@tonic-gate if ((dp = cpi->cpi_cacheinfo) == NULL) 33180Sstevel@tonic-gate return; 33194797Sksadhukh for (i = 0; i < cpi->cpi_ncache; i++, dp++) { 33204797Sksadhukh /* 33214797Sksadhukh * For overloaded descriptor 0x49 we use cpuid function 4 33225438Sksadhukh * if supported by the current processor, to create 33234797Sksadhukh * cache information. 33246964Svd224797 * For overloaded descriptor 0xb1 we use X86_PAE flag 33256964Svd224797 * to disambiguate the cache information. 33264797Sksadhukh */ 33275438Sksadhukh if (*dp == 0x49 && cpi->cpi_maxeax >= 0x4 && 33285438Sksadhukh intel_cpuid_4_cache_info(&des_49_ct, cpi) == 1) { 33295438Sksadhukh ct = &des_49_ct; 33306964Svd224797 } else if (*dp == 0xb1) { 33316964Svd224797 des_b1_ct.ct_code = 0xb1; 33326964Svd224797 des_b1_ct.ct_assoc = 4; 33336964Svd224797 des_b1_ct.ct_line_size = 0; 33346964Svd224797 if (x86_feature & X86_PAE) { 33356964Svd224797 des_b1_ct.ct_size = 8; 33366964Svd224797 des_b1_ct.ct_label = itlb2M_str; 33376964Svd224797 } else { 33386964Svd224797 des_b1_ct.ct_size = 4; 33396964Svd224797 des_b1_ct.ct_label = itlb4M_str; 33406964Svd224797 } 33416964Svd224797 ct = &des_b1_ct; 33425438Sksadhukh } else { 33435438Sksadhukh if ((ct = find_cacheent(intel_ctab, *dp)) == NULL) { 33445438Sksadhukh continue; 33455438Sksadhukh } 33464797Sksadhukh } 33474797Sksadhukh 33485438Sksadhukh if (func(arg, ct) != 0) { 33495438Sksadhukh break; 33500Sstevel@tonic-gate } 33514797Sksadhukh } 33520Sstevel@tonic-gate } 33530Sstevel@tonic-gate 33540Sstevel@tonic-gate /* 33550Sstevel@tonic-gate * (Like the Intel one, except for Cyrix CPUs) 33560Sstevel@tonic-gate */ 33570Sstevel@tonic-gate static void 33580Sstevel@tonic-gate cyrix_walk_cacheinfo(struct cpuid_info *cpi, 33590Sstevel@tonic-gate void *arg, int (*func)(void *, const struct cachetab *)) 33600Sstevel@tonic-gate { 33610Sstevel@tonic-gate const struct cachetab *ct; 33620Sstevel@tonic-gate uint8_t *dp; 33630Sstevel@tonic-gate int i; 33640Sstevel@tonic-gate 33650Sstevel@tonic-gate if ((dp = cpi->cpi_cacheinfo) == NULL) 33660Sstevel@tonic-gate return; 33670Sstevel@tonic-gate for (i = 0; i < cpi->cpi_ncache; i++, dp++) { 33680Sstevel@tonic-gate /* 33690Sstevel@tonic-gate * Search Cyrix-specific descriptor table first .. 33700Sstevel@tonic-gate */ 33710Sstevel@tonic-gate if ((ct = find_cacheent(cyrix_ctab, *dp)) != NULL) { 33720Sstevel@tonic-gate if (func(arg, ct) != 0) 33730Sstevel@tonic-gate break; 33740Sstevel@tonic-gate continue; 33750Sstevel@tonic-gate } 33760Sstevel@tonic-gate /* 33770Sstevel@tonic-gate * .. else fall back to the Intel one 33780Sstevel@tonic-gate */ 33790Sstevel@tonic-gate if ((ct = find_cacheent(intel_ctab, *dp)) != NULL) { 33800Sstevel@tonic-gate if (func(arg, ct) != 0) 33810Sstevel@tonic-gate break; 33820Sstevel@tonic-gate continue; 33830Sstevel@tonic-gate } 33840Sstevel@tonic-gate } 33850Sstevel@tonic-gate } 33860Sstevel@tonic-gate 33870Sstevel@tonic-gate /* 33880Sstevel@tonic-gate * A cacheinfo walker that adds associativity, line-size, and size properties 33890Sstevel@tonic-gate * to the devinfo node it is passed as an argument. 33900Sstevel@tonic-gate */ 33910Sstevel@tonic-gate static int 33920Sstevel@tonic-gate add_cacheent_props(void *arg, const struct cachetab *ct) 33930Sstevel@tonic-gate { 33940Sstevel@tonic-gate dev_info_t *devi = arg; 33950Sstevel@tonic-gate 33960Sstevel@tonic-gate add_cache_prop(devi, ct->ct_label, assoc_str, ct->ct_assoc); 33970Sstevel@tonic-gate if (ct->ct_line_size != 0) 33980Sstevel@tonic-gate add_cache_prop(devi, ct->ct_label, line_str, 33990Sstevel@tonic-gate ct->ct_line_size); 34000Sstevel@tonic-gate add_cache_prop(devi, ct->ct_label, size_str, ct->ct_size); 34010Sstevel@tonic-gate return (0); 34020Sstevel@tonic-gate } 34030Sstevel@tonic-gate 34044797Sksadhukh 34050Sstevel@tonic-gate static const char fully_assoc[] = "fully-associative?"; 34060Sstevel@tonic-gate 34070Sstevel@tonic-gate /* 34080Sstevel@tonic-gate * AMD style cache/tlb description 34090Sstevel@tonic-gate * 34100Sstevel@tonic-gate * Extended functions 5 and 6 directly describe properties of 34110Sstevel@tonic-gate * tlbs and various cache levels. 34120Sstevel@tonic-gate */ 34130Sstevel@tonic-gate static void 34140Sstevel@tonic-gate add_amd_assoc(dev_info_t *devi, const char *label, uint_t assoc) 34150Sstevel@tonic-gate { 34160Sstevel@tonic-gate switch (assoc) { 34170Sstevel@tonic-gate case 0: /* reserved; ignore */ 34180Sstevel@tonic-gate break; 34190Sstevel@tonic-gate default: 34200Sstevel@tonic-gate add_cache_prop(devi, label, assoc_str, assoc); 34210Sstevel@tonic-gate break; 34220Sstevel@tonic-gate case 0xff: 34230Sstevel@tonic-gate add_cache_prop(devi, label, fully_assoc, 1); 34240Sstevel@tonic-gate break; 34250Sstevel@tonic-gate } 34260Sstevel@tonic-gate } 34270Sstevel@tonic-gate 34280Sstevel@tonic-gate static void 34290Sstevel@tonic-gate add_amd_tlb(dev_info_t *devi, const char *label, uint_t assoc, uint_t size) 34300Sstevel@tonic-gate { 34310Sstevel@tonic-gate if (size == 0) 34320Sstevel@tonic-gate return; 34330Sstevel@tonic-gate add_cache_prop(devi, label, size_str, size); 34340Sstevel@tonic-gate add_amd_assoc(devi, label, assoc); 34350Sstevel@tonic-gate } 34360Sstevel@tonic-gate 34370Sstevel@tonic-gate static void 34380Sstevel@tonic-gate add_amd_cache(dev_info_t *devi, const char *label, 34390Sstevel@tonic-gate uint_t size, uint_t assoc, uint_t lines_per_tag, uint_t line_size) 34400Sstevel@tonic-gate { 34410Sstevel@tonic-gate if (size == 0 || line_size == 0) 34420Sstevel@tonic-gate return; 34430Sstevel@tonic-gate add_amd_assoc(devi, label, assoc); 34440Sstevel@tonic-gate /* 34450Sstevel@tonic-gate * Most AMD parts have a sectored cache. Multiple cache lines are 34460Sstevel@tonic-gate * associated with each tag. A sector consists of all cache lines 34470Sstevel@tonic-gate * associated with a tag. For example, the AMD K6-III has a sector 34480Sstevel@tonic-gate * size of 2 cache lines per tag. 34490Sstevel@tonic-gate */ 34500Sstevel@tonic-gate if (lines_per_tag != 0) 34510Sstevel@tonic-gate add_cache_prop(devi, label, "lines-per-tag", lines_per_tag); 34520Sstevel@tonic-gate add_cache_prop(devi, label, line_str, line_size); 34530Sstevel@tonic-gate add_cache_prop(devi, label, size_str, size * 1024); 34540Sstevel@tonic-gate } 34550Sstevel@tonic-gate 34560Sstevel@tonic-gate static void 34570Sstevel@tonic-gate add_amd_l2_assoc(dev_info_t *devi, const char *label, uint_t assoc) 34580Sstevel@tonic-gate { 34590Sstevel@tonic-gate switch (assoc) { 34600Sstevel@tonic-gate case 0: /* off */ 34610Sstevel@tonic-gate break; 34620Sstevel@tonic-gate case 1: 34630Sstevel@tonic-gate case 2: 34640Sstevel@tonic-gate case 4: 34650Sstevel@tonic-gate add_cache_prop(devi, label, assoc_str, assoc); 34660Sstevel@tonic-gate break; 34670Sstevel@tonic-gate case 6: 34680Sstevel@tonic-gate add_cache_prop(devi, label, assoc_str, 8); 34690Sstevel@tonic-gate break; 34700Sstevel@tonic-gate case 8: 34710Sstevel@tonic-gate add_cache_prop(devi, label, assoc_str, 16); 34720Sstevel@tonic-gate break; 34730Sstevel@tonic-gate case 0xf: 34740Sstevel@tonic-gate add_cache_prop(devi, label, fully_assoc, 1); 34750Sstevel@tonic-gate break; 34760Sstevel@tonic-gate default: /* reserved; ignore */ 34770Sstevel@tonic-gate break; 34780Sstevel@tonic-gate } 34790Sstevel@tonic-gate } 34800Sstevel@tonic-gate 34810Sstevel@tonic-gate static void 34820Sstevel@tonic-gate add_amd_l2_tlb(dev_info_t *devi, const char *label, uint_t assoc, uint_t size) 34830Sstevel@tonic-gate { 34840Sstevel@tonic-gate if (size == 0 || assoc == 0) 34850Sstevel@tonic-gate return; 34860Sstevel@tonic-gate add_amd_l2_assoc(devi, label, assoc); 34870Sstevel@tonic-gate add_cache_prop(devi, label, size_str, size); 34880Sstevel@tonic-gate } 34890Sstevel@tonic-gate 34900Sstevel@tonic-gate static void 34910Sstevel@tonic-gate add_amd_l2_cache(dev_info_t *devi, const char *label, 34920Sstevel@tonic-gate uint_t size, uint_t assoc, uint_t lines_per_tag, uint_t line_size) 34930Sstevel@tonic-gate { 34940Sstevel@tonic-gate if (size == 0 || assoc == 0 || line_size == 0) 34950Sstevel@tonic-gate return; 34960Sstevel@tonic-gate add_amd_l2_assoc(devi, label, assoc); 34970Sstevel@tonic-gate if (lines_per_tag != 0) 34980Sstevel@tonic-gate add_cache_prop(devi, label, "lines-per-tag", lines_per_tag); 34990Sstevel@tonic-gate add_cache_prop(devi, label, line_str, line_size); 35000Sstevel@tonic-gate add_cache_prop(devi, label, size_str, size * 1024); 35010Sstevel@tonic-gate } 35020Sstevel@tonic-gate 35030Sstevel@tonic-gate static void 35040Sstevel@tonic-gate amd_cache_info(struct cpuid_info *cpi, dev_info_t *devi) 35050Sstevel@tonic-gate { 35061228Sandrei struct cpuid_regs *cp; 35070Sstevel@tonic-gate 35080Sstevel@tonic-gate if (cpi->cpi_xmaxeax < 0x80000005) 35090Sstevel@tonic-gate return; 35100Sstevel@tonic-gate cp = &cpi->cpi_extd[5]; 35110Sstevel@tonic-gate 35120Sstevel@tonic-gate /* 35130Sstevel@tonic-gate * 4M/2M L1 TLB configuration 35140Sstevel@tonic-gate * 35150Sstevel@tonic-gate * We report the size for 2M pages because AMD uses two 35160Sstevel@tonic-gate * TLB entries for one 4M page. 35170Sstevel@tonic-gate */ 35180Sstevel@tonic-gate add_amd_tlb(devi, "dtlb-2M", 35190Sstevel@tonic-gate BITX(cp->cp_eax, 31, 24), BITX(cp->cp_eax, 23, 16)); 35200Sstevel@tonic-gate add_amd_tlb(devi, "itlb-2M", 35210Sstevel@tonic-gate BITX(cp->cp_eax, 15, 8), BITX(cp->cp_eax, 7, 0)); 35220Sstevel@tonic-gate 35230Sstevel@tonic-gate /* 35240Sstevel@tonic-gate * 4K L1 TLB configuration 35250Sstevel@tonic-gate */ 35260Sstevel@tonic-gate 35270Sstevel@tonic-gate switch (cpi->cpi_vendor) { 35280Sstevel@tonic-gate uint_t nentries; 35290Sstevel@tonic-gate case X86_VENDOR_TM: 35300Sstevel@tonic-gate if (cpi->cpi_family >= 5) { 35310Sstevel@tonic-gate /* 35320Sstevel@tonic-gate * Crusoe processors have 256 TLB entries, but 35330Sstevel@tonic-gate * cpuid data format constrains them to only 35340Sstevel@tonic-gate * reporting 255 of them. 35350Sstevel@tonic-gate */ 35360Sstevel@tonic-gate if ((nentries = BITX(cp->cp_ebx, 23, 16)) == 255) 35370Sstevel@tonic-gate nentries = 256; 35380Sstevel@tonic-gate /* 35390Sstevel@tonic-gate * Crusoe processors also have a unified TLB 35400Sstevel@tonic-gate */ 35410Sstevel@tonic-gate add_amd_tlb(devi, "tlb-4K", BITX(cp->cp_ebx, 31, 24), 35420Sstevel@tonic-gate nentries); 35430Sstevel@tonic-gate break; 35440Sstevel@tonic-gate } 35450Sstevel@tonic-gate /*FALLTHROUGH*/ 35460Sstevel@tonic-gate default: 35470Sstevel@tonic-gate add_amd_tlb(devi, itlb4k_str, 35480Sstevel@tonic-gate BITX(cp->cp_ebx, 31, 24), BITX(cp->cp_ebx, 23, 16)); 35490Sstevel@tonic-gate add_amd_tlb(devi, dtlb4k_str, 35500Sstevel@tonic-gate BITX(cp->cp_ebx, 15, 8), BITX(cp->cp_ebx, 7, 0)); 35510Sstevel@tonic-gate break; 35520Sstevel@tonic-gate } 35530Sstevel@tonic-gate 35540Sstevel@tonic-gate /* 35550Sstevel@tonic-gate * data L1 cache configuration 35560Sstevel@tonic-gate */ 35570Sstevel@tonic-gate 35580Sstevel@tonic-gate add_amd_cache(devi, l1_dcache_str, 35590Sstevel@tonic-gate BITX(cp->cp_ecx, 31, 24), BITX(cp->cp_ecx, 23, 16), 35600Sstevel@tonic-gate BITX(cp->cp_ecx, 15, 8), BITX(cp->cp_ecx, 7, 0)); 35610Sstevel@tonic-gate 35620Sstevel@tonic-gate /* 35630Sstevel@tonic-gate * code L1 cache configuration 35640Sstevel@tonic-gate */ 35650Sstevel@tonic-gate 35660Sstevel@tonic-gate add_amd_cache(devi, l1_icache_str, 35670Sstevel@tonic-gate BITX(cp->cp_edx, 31, 24), BITX(cp->cp_edx, 23, 16), 35680Sstevel@tonic-gate BITX(cp->cp_edx, 15, 8), BITX(cp->cp_edx, 7, 0)); 35690Sstevel@tonic-gate 35700Sstevel@tonic-gate if (cpi->cpi_xmaxeax < 0x80000006) 35710Sstevel@tonic-gate return; 35720Sstevel@tonic-gate cp = &cpi->cpi_extd[6]; 35730Sstevel@tonic-gate 35740Sstevel@tonic-gate /* Check for a unified L2 TLB for large pages */ 35750Sstevel@tonic-gate 35760Sstevel@tonic-gate if (BITX(cp->cp_eax, 31, 16) == 0) 35770Sstevel@tonic-gate add_amd_l2_tlb(devi, "l2-tlb-2M", 35780Sstevel@tonic-gate BITX(cp->cp_eax, 15, 12), BITX(cp->cp_eax, 11, 0)); 35790Sstevel@tonic-gate else { 35800Sstevel@tonic-gate add_amd_l2_tlb(devi, "l2-dtlb-2M", 35810Sstevel@tonic-gate BITX(cp->cp_eax, 31, 28), BITX(cp->cp_eax, 27, 16)); 35820Sstevel@tonic-gate add_amd_l2_tlb(devi, "l2-itlb-2M", 35830Sstevel@tonic-gate BITX(cp->cp_eax, 15, 12), BITX(cp->cp_eax, 11, 0)); 35840Sstevel@tonic-gate } 35850Sstevel@tonic-gate 35860Sstevel@tonic-gate /* Check for a unified L2 TLB for 4K pages */ 35870Sstevel@tonic-gate 35880Sstevel@tonic-gate if (BITX(cp->cp_ebx, 31, 16) == 0) { 35890Sstevel@tonic-gate add_amd_l2_tlb(devi, "l2-tlb-4K", 35900Sstevel@tonic-gate BITX(cp->cp_eax, 15, 12), BITX(cp->cp_eax, 11, 0)); 35910Sstevel@tonic-gate } else { 35920Sstevel@tonic-gate add_amd_l2_tlb(devi, "l2-dtlb-4K", 35930Sstevel@tonic-gate BITX(cp->cp_eax, 31, 28), BITX(cp->cp_eax, 27, 16)); 35940Sstevel@tonic-gate add_amd_l2_tlb(devi, "l2-itlb-4K", 35950Sstevel@tonic-gate BITX(cp->cp_eax, 15, 12), BITX(cp->cp_eax, 11, 0)); 35960Sstevel@tonic-gate } 35970Sstevel@tonic-gate 35980Sstevel@tonic-gate add_amd_l2_cache(devi, l2_cache_str, 35990Sstevel@tonic-gate BITX(cp->cp_ecx, 31, 16), BITX(cp->cp_ecx, 15, 12), 36000Sstevel@tonic-gate BITX(cp->cp_ecx, 11, 8), BITX(cp->cp_ecx, 7, 0)); 36010Sstevel@tonic-gate } 36020Sstevel@tonic-gate 36030Sstevel@tonic-gate /* 36040Sstevel@tonic-gate * There are two basic ways that the x86 world describes it cache 36050Sstevel@tonic-gate * and tlb architecture - Intel's way and AMD's way. 36060Sstevel@tonic-gate * 36070Sstevel@tonic-gate * Return which flavor of cache architecture we should use 36080Sstevel@tonic-gate */ 36090Sstevel@tonic-gate static int 36100Sstevel@tonic-gate x86_which_cacheinfo(struct cpuid_info *cpi) 36110Sstevel@tonic-gate { 36120Sstevel@tonic-gate switch (cpi->cpi_vendor) { 36130Sstevel@tonic-gate case X86_VENDOR_Intel: 36140Sstevel@tonic-gate if (cpi->cpi_maxeax >= 2) 36150Sstevel@tonic-gate return (X86_VENDOR_Intel); 36160Sstevel@tonic-gate break; 36170Sstevel@tonic-gate case X86_VENDOR_AMD: 36180Sstevel@tonic-gate /* 36190Sstevel@tonic-gate * The K5 model 1 was the first part from AMD that reported 36200Sstevel@tonic-gate * cache sizes via extended cpuid functions. 36210Sstevel@tonic-gate */ 36220Sstevel@tonic-gate if (cpi->cpi_family > 5 || 36230Sstevel@tonic-gate (cpi->cpi_family == 5 && cpi->cpi_model >= 1)) 36240Sstevel@tonic-gate return (X86_VENDOR_AMD); 36250Sstevel@tonic-gate break; 36260Sstevel@tonic-gate case X86_VENDOR_TM: 36270Sstevel@tonic-gate if (cpi->cpi_family >= 5) 36280Sstevel@tonic-gate return (X86_VENDOR_AMD); 36290Sstevel@tonic-gate /*FALLTHROUGH*/ 36300Sstevel@tonic-gate default: 36310Sstevel@tonic-gate /* 36320Sstevel@tonic-gate * If they have extended CPU data for 0x80000005 36330Sstevel@tonic-gate * then we assume they have AMD-format cache 36340Sstevel@tonic-gate * information. 36350Sstevel@tonic-gate * 36360Sstevel@tonic-gate * If not, and the vendor happens to be Cyrix, 36370Sstevel@tonic-gate * then try our-Cyrix specific handler. 36380Sstevel@tonic-gate * 36390Sstevel@tonic-gate * If we're not Cyrix, then assume we're using Intel's 36400Sstevel@tonic-gate * table-driven format instead. 36410Sstevel@tonic-gate */ 36420Sstevel@tonic-gate if (cpi->cpi_xmaxeax >= 0x80000005) 36430Sstevel@tonic-gate return (X86_VENDOR_AMD); 36440Sstevel@tonic-gate else if (cpi->cpi_vendor == X86_VENDOR_Cyrix) 36450Sstevel@tonic-gate return (X86_VENDOR_Cyrix); 36460Sstevel@tonic-gate else if (cpi->cpi_maxeax >= 2) 36470Sstevel@tonic-gate return (X86_VENDOR_Intel); 36480Sstevel@tonic-gate break; 36490Sstevel@tonic-gate } 36500Sstevel@tonic-gate return (-1); 36510Sstevel@tonic-gate } 36520Sstevel@tonic-gate 36530Sstevel@tonic-gate void 36549652SMichael.Corcoran@Sun.COM cpuid_set_cpu_properties(void *dip, processorid_t cpu_id, 36559652SMichael.Corcoran@Sun.COM struct cpuid_info *cpi) 36560Sstevel@tonic-gate { 36570Sstevel@tonic-gate dev_info_t *cpu_devi; 36580Sstevel@tonic-gate int create; 36590Sstevel@tonic-gate 36609652SMichael.Corcoran@Sun.COM cpu_devi = (dev_info_t *)dip; 36610Sstevel@tonic-gate 36620Sstevel@tonic-gate /* device_type */ 36630Sstevel@tonic-gate (void) ndi_prop_update_string(DDI_DEV_T_NONE, cpu_devi, 36640Sstevel@tonic-gate "device_type", "cpu"); 36650Sstevel@tonic-gate 36660Sstevel@tonic-gate /* reg */ 36670Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 36680Sstevel@tonic-gate "reg", cpu_id); 36690Sstevel@tonic-gate 36700Sstevel@tonic-gate /* cpu-mhz, and clock-frequency */ 36710Sstevel@tonic-gate if (cpu_freq > 0) { 36720Sstevel@tonic-gate long long mul; 36730Sstevel@tonic-gate 36740Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 36750Sstevel@tonic-gate "cpu-mhz", cpu_freq); 36760Sstevel@tonic-gate if ((mul = cpu_freq * 1000000LL) <= INT_MAX) 36770Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 36780Sstevel@tonic-gate "clock-frequency", (int)mul); 36790Sstevel@tonic-gate } 36800Sstevel@tonic-gate 36810Sstevel@tonic-gate if ((x86_feature & X86_CPUID) == 0) { 36820Sstevel@tonic-gate return; 36830Sstevel@tonic-gate } 36840Sstevel@tonic-gate 36850Sstevel@tonic-gate /* vendor-id */ 36860Sstevel@tonic-gate (void) ndi_prop_update_string(DDI_DEV_T_NONE, cpu_devi, 36874481Sbholler "vendor-id", cpi->cpi_vendorstr); 36880Sstevel@tonic-gate 36890Sstevel@tonic-gate if (cpi->cpi_maxeax == 0) { 36900Sstevel@tonic-gate return; 36910Sstevel@tonic-gate } 36920Sstevel@tonic-gate 36930Sstevel@tonic-gate /* 36940Sstevel@tonic-gate * family, model, and step 36950Sstevel@tonic-gate */ 36960Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 36974481Sbholler "family", CPI_FAMILY(cpi)); 36980Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 36994481Sbholler "cpu-model", CPI_MODEL(cpi)); 37000Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 37014481Sbholler "stepping-id", CPI_STEP(cpi)); 37020Sstevel@tonic-gate 37030Sstevel@tonic-gate /* type */ 37040Sstevel@tonic-gate switch (cpi->cpi_vendor) { 37050Sstevel@tonic-gate case X86_VENDOR_Intel: 37060Sstevel@tonic-gate create = 1; 37070Sstevel@tonic-gate break; 37080Sstevel@tonic-gate default: 37090Sstevel@tonic-gate create = 0; 37100Sstevel@tonic-gate break; 37110Sstevel@tonic-gate } 37120Sstevel@tonic-gate if (create) 37130Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 37144481Sbholler "type", CPI_TYPE(cpi)); 37150Sstevel@tonic-gate 37160Sstevel@tonic-gate /* ext-family */ 37170Sstevel@tonic-gate switch (cpi->cpi_vendor) { 37180Sstevel@tonic-gate case X86_VENDOR_Intel: 37190Sstevel@tonic-gate case X86_VENDOR_AMD: 37200Sstevel@tonic-gate create = cpi->cpi_family >= 0xf; 37210Sstevel@tonic-gate break; 37220Sstevel@tonic-gate default: 37230Sstevel@tonic-gate create = 0; 37240Sstevel@tonic-gate break; 37250Sstevel@tonic-gate } 37260Sstevel@tonic-gate if (create) 37270Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 37280Sstevel@tonic-gate "ext-family", CPI_FAMILY_XTD(cpi)); 37290Sstevel@tonic-gate 37300Sstevel@tonic-gate /* ext-model */ 37310Sstevel@tonic-gate switch (cpi->cpi_vendor) { 37320Sstevel@tonic-gate case X86_VENDOR_Intel: 37336317Skk208521 create = IS_EXTENDED_MODEL_INTEL(cpi); 37342001Sdmick break; 37350Sstevel@tonic-gate case X86_VENDOR_AMD: 37361582Skchow create = CPI_FAMILY(cpi) == 0xf; 37370Sstevel@tonic-gate break; 37380Sstevel@tonic-gate default: 37390Sstevel@tonic-gate create = 0; 37400Sstevel@tonic-gate break; 37410Sstevel@tonic-gate } 37420Sstevel@tonic-gate if (create) 37430Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 37444481Sbholler "ext-model", CPI_MODEL_XTD(cpi)); 37450Sstevel@tonic-gate 37460Sstevel@tonic-gate /* generation */ 37470Sstevel@tonic-gate switch (cpi->cpi_vendor) { 37480Sstevel@tonic-gate case X86_VENDOR_AMD: 37490Sstevel@tonic-gate /* 37500Sstevel@tonic-gate * AMD K5 model 1 was the first part to support this 37510Sstevel@tonic-gate */ 37520Sstevel@tonic-gate create = cpi->cpi_xmaxeax >= 0x80000001; 37530Sstevel@tonic-gate break; 37540Sstevel@tonic-gate default: 37550Sstevel@tonic-gate create = 0; 37560Sstevel@tonic-gate break; 37570Sstevel@tonic-gate } 37580Sstevel@tonic-gate if (create) 37590Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 37600Sstevel@tonic-gate "generation", BITX((cpi)->cpi_extd[1].cp_eax, 11, 8)); 37610Sstevel@tonic-gate 37620Sstevel@tonic-gate /* brand-id */ 37630Sstevel@tonic-gate switch (cpi->cpi_vendor) { 37640Sstevel@tonic-gate case X86_VENDOR_Intel: 37650Sstevel@tonic-gate /* 37660Sstevel@tonic-gate * brand id first appeared on Pentium III Xeon model 8, 37670Sstevel@tonic-gate * and Celeron model 8 processors and Opteron 37680Sstevel@tonic-gate */ 37690Sstevel@tonic-gate create = cpi->cpi_family > 6 || 37700Sstevel@tonic-gate (cpi->cpi_family == 6 && cpi->cpi_model >= 8); 37710Sstevel@tonic-gate break; 37720Sstevel@tonic-gate case X86_VENDOR_AMD: 37730Sstevel@tonic-gate create = cpi->cpi_family >= 0xf; 37740Sstevel@tonic-gate break; 37750Sstevel@tonic-gate default: 37760Sstevel@tonic-gate create = 0; 37770Sstevel@tonic-gate break; 37780Sstevel@tonic-gate } 37790Sstevel@tonic-gate if (create && cpi->cpi_brandid != 0) { 37800Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 37810Sstevel@tonic-gate "brand-id", cpi->cpi_brandid); 37820Sstevel@tonic-gate } 37830Sstevel@tonic-gate 37840Sstevel@tonic-gate /* chunks, and apic-id */ 37850Sstevel@tonic-gate switch (cpi->cpi_vendor) { 37860Sstevel@tonic-gate /* 37870Sstevel@tonic-gate * first available on Pentium IV and Opteron (K8) 37880Sstevel@tonic-gate */ 37891975Sdmick case X86_VENDOR_Intel: 37901975Sdmick create = IS_NEW_F6(cpi) || cpi->cpi_family >= 0xf; 37911975Sdmick break; 37921975Sdmick case X86_VENDOR_AMD: 37930Sstevel@tonic-gate create = cpi->cpi_family >= 0xf; 37940Sstevel@tonic-gate break; 37950Sstevel@tonic-gate default: 37960Sstevel@tonic-gate create = 0; 37970Sstevel@tonic-gate break; 37980Sstevel@tonic-gate } 37990Sstevel@tonic-gate if (create) { 38000Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 38014481Sbholler "chunks", CPI_CHUNKS(cpi)); 38020Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 38037282Smishra "apic-id", cpi->cpi_apicid); 38041414Scindi if (cpi->cpi_chipid >= 0) { 38050Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 38060Sstevel@tonic-gate "chip#", cpi->cpi_chipid); 38071414Scindi (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 38081414Scindi "clog#", cpi->cpi_clogid); 38091414Scindi } 38100Sstevel@tonic-gate } 38110Sstevel@tonic-gate 38120Sstevel@tonic-gate /* cpuid-features */ 38130Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 38140Sstevel@tonic-gate "cpuid-features", CPI_FEATURES_EDX(cpi)); 38150Sstevel@tonic-gate 38160Sstevel@tonic-gate 38170Sstevel@tonic-gate /* cpuid-features-ecx */ 38180Sstevel@tonic-gate switch (cpi->cpi_vendor) { 38190Sstevel@tonic-gate case X86_VENDOR_Intel: 38201975Sdmick create = IS_NEW_F6(cpi) || cpi->cpi_family >= 0xf; 38210Sstevel@tonic-gate break; 38220Sstevel@tonic-gate default: 38230Sstevel@tonic-gate create = 0; 38240Sstevel@tonic-gate break; 38250Sstevel@tonic-gate } 38260Sstevel@tonic-gate if (create) 38270Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 38280Sstevel@tonic-gate "cpuid-features-ecx", CPI_FEATURES_ECX(cpi)); 38290Sstevel@tonic-gate 38300Sstevel@tonic-gate /* ext-cpuid-features */ 38310Sstevel@tonic-gate switch (cpi->cpi_vendor) { 38321975Sdmick case X86_VENDOR_Intel: 38330Sstevel@tonic-gate case X86_VENDOR_AMD: 38340Sstevel@tonic-gate case X86_VENDOR_Cyrix: 38350Sstevel@tonic-gate case X86_VENDOR_TM: 38360Sstevel@tonic-gate case X86_VENDOR_Centaur: 38370Sstevel@tonic-gate create = cpi->cpi_xmaxeax >= 0x80000001; 38380Sstevel@tonic-gate break; 38390Sstevel@tonic-gate default: 38400Sstevel@tonic-gate create = 0; 38410Sstevel@tonic-gate break; 38420Sstevel@tonic-gate } 38431975Sdmick if (create) { 38440Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 38454481Sbholler "ext-cpuid-features", CPI_FEATURES_XTD_EDX(cpi)); 38461975Sdmick (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 38474481Sbholler "ext-cpuid-features-ecx", CPI_FEATURES_XTD_ECX(cpi)); 38481975Sdmick } 38490Sstevel@tonic-gate 38500Sstevel@tonic-gate /* 38510Sstevel@tonic-gate * Brand String first appeared in Intel Pentium IV, AMD K5 38520Sstevel@tonic-gate * model 1, and Cyrix GXm. On earlier models we try and 38530Sstevel@tonic-gate * simulate something similar .. so this string should always 38540Sstevel@tonic-gate * same -something- about the processor, however lame. 38550Sstevel@tonic-gate */ 38560Sstevel@tonic-gate (void) ndi_prop_update_string(DDI_DEV_T_NONE, cpu_devi, 38570Sstevel@tonic-gate "brand-string", cpi->cpi_brandstr); 38580Sstevel@tonic-gate 38590Sstevel@tonic-gate /* 38600Sstevel@tonic-gate * Finally, cache and tlb information 38610Sstevel@tonic-gate */ 38620Sstevel@tonic-gate switch (x86_which_cacheinfo(cpi)) { 38630Sstevel@tonic-gate case X86_VENDOR_Intel: 38640Sstevel@tonic-gate intel_walk_cacheinfo(cpi, cpu_devi, add_cacheent_props); 38650Sstevel@tonic-gate break; 38660Sstevel@tonic-gate case X86_VENDOR_Cyrix: 38670Sstevel@tonic-gate cyrix_walk_cacheinfo(cpi, cpu_devi, add_cacheent_props); 38680Sstevel@tonic-gate break; 38690Sstevel@tonic-gate case X86_VENDOR_AMD: 38700Sstevel@tonic-gate amd_cache_info(cpi, cpu_devi); 38710Sstevel@tonic-gate break; 38720Sstevel@tonic-gate default: 38730Sstevel@tonic-gate break; 38740Sstevel@tonic-gate } 38750Sstevel@tonic-gate } 38760Sstevel@tonic-gate 38770Sstevel@tonic-gate struct l2info { 38780Sstevel@tonic-gate int *l2i_csz; 38790Sstevel@tonic-gate int *l2i_lsz; 38800Sstevel@tonic-gate int *l2i_assoc; 38810Sstevel@tonic-gate int l2i_ret; 38820Sstevel@tonic-gate }; 38830Sstevel@tonic-gate 38840Sstevel@tonic-gate /* 38850Sstevel@tonic-gate * A cacheinfo walker that fetches the size, line-size and associativity 38860Sstevel@tonic-gate * of the L2 cache 38870Sstevel@tonic-gate */ 38880Sstevel@tonic-gate static int 38890Sstevel@tonic-gate intel_l2cinfo(void *arg, const struct cachetab *ct) 38900Sstevel@tonic-gate { 38910Sstevel@tonic-gate struct l2info *l2i = arg; 38920Sstevel@tonic-gate int *ip; 38930Sstevel@tonic-gate 38940Sstevel@tonic-gate if (ct->ct_label != l2_cache_str && 38950Sstevel@tonic-gate ct->ct_label != sl2_cache_str) 38960Sstevel@tonic-gate return (0); /* not an L2 -- keep walking */ 38970Sstevel@tonic-gate 38980Sstevel@tonic-gate if ((ip = l2i->l2i_csz) != NULL) 38990Sstevel@tonic-gate *ip = ct->ct_size; 39000Sstevel@tonic-gate if ((ip = l2i->l2i_lsz) != NULL) 39010Sstevel@tonic-gate *ip = ct->ct_line_size; 39020Sstevel@tonic-gate if ((ip = l2i->l2i_assoc) != NULL) 39030Sstevel@tonic-gate *ip = ct->ct_assoc; 39040Sstevel@tonic-gate l2i->l2i_ret = ct->ct_size; 39050Sstevel@tonic-gate return (1); /* was an L2 -- terminate walk */ 39060Sstevel@tonic-gate } 39070Sstevel@tonic-gate 39085070Skchow /* 39095070Skchow * AMD L2/L3 Cache and TLB Associativity Field Definition: 39105070Skchow * 39115070Skchow * Unlike the associativity for the L1 cache and tlb where the 8 bit 39125070Skchow * value is the associativity, the associativity for the L2 cache and 39135070Skchow * tlb is encoded in the following table. The 4 bit L2 value serves as 39145070Skchow * an index into the amd_afd[] array to determine the associativity. 39155070Skchow * -1 is undefined. 0 is fully associative. 39165070Skchow */ 39175070Skchow 39185070Skchow static int amd_afd[] = 39195070Skchow {-1, 1, 2, -1, 4, -1, 8, -1, 16, -1, 32, 48, 64, 96, 128, 0}; 39205070Skchow 39210Sstevel@tonic-gate static void 39220Sstevel@tonic-gate amd_l2cacheinfo(struct cpuid_info *cpi, struct l2info *l2i) 39230Sstevel@tonic-gate { 39241228Sandrei struct cpuid_regs *cp; 39250Sstevel@tonic-gate uint_t size, assoc; 39265070Skchow int i; 39270Sstevel@tonic-gate int *ip; 39280Sstevel@tonic-gate 39290Sstevel@tonic-gate if (cpi->cpi_xmaxeax < 0x80000006) 39300Sstevel@tonic-gate return; 39310Sstevel@tonic-gate cp = &cpi->cpi_extd[6]; 39320Sstevel@tonic-gate 39335070Skchow if ((i = BITX(cp->cp_ecx, 15, 12)) != 0 && 39340Sstevel@tonic-gate (size = BITX(cp->cp_ecx, 31, 16)) != 0) { 39350Sstevel@tonic-gate uint_t cachesz = size * 1024; 39365070Skchow assoc = amd_afd[i]; 39375070Skchow 39385070Skchow ASSERT(assoc != -1); 39390Sstevel@tonic-gate 39400Sstevel@tonic-gate if ((ip = l2i->l2i_csz) != NULL) 39410Sstevel@tonic-gate *ip = cachesz; 39420Sstevel@tonic-gate if ((ip = l2i->l2i_lsz) != NULL) 39430Sstevel@tonic-gate *ip = BITX(cp->cp_ecx, 7, 0); 39440Sstevel@tonic-gate if ((ip = l2i->l2i_assoc) != NULL) 39450Sstevel@tonic-gate *ip = assoc; 39460Sstevel@tonic-gate l2i->l2i_ret = cachesz; 39470Sstevel@tonic-gate } 39480Sstevel@tonic-gate } 39490Sstevel@tonic-gate 39500Sstevel@tonic-gate int 39510Sstevel@tonic-gate getl2cacheinfo(cpu_t *cpu, int *csz, int *lsz, int *assoc) 39520Sstevel@tonic-gate { 39530Sstevel@tonic-gate struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 39540Sstevel@tonic-gate struct l2info __l2info, *l2i = &__l2info; 39550Sstevel@tonic-gate 39560Sstevel@tonic-gate l2i->l2i_csz = csz; 39570Sstevel@tonic-gate l2i->l2i_lsz = lsz; 39580Sstevel@tonic-gate l2i->l2i_assoc = assoc; 39590Sstevel@tonic-gate l2i->l2i_ret = -1; 39600Sstevel@tonic-gate 39610Sstevel@tonic-gate switch (x86_which_cacheinfo(cpi)) { 39620Sstevel@tonic-gate case X86_VENDOR_Intel: 39630Sstevel@tonic-gate intel_walk_cacheinfo(cpi, l2i, intel_l2cinfo); 39640Sstevel@tonic-gate break; 39650Sstevel@tonic-gate case X86_VENDOR_Cyrix: 39660Sstevel@tonic-gate cyrix_walk_cacheinfo(cpi, l2i, intel_l2cinfo); 39670Sstevel@tonic-gate break; 39680Sstevel@tonic-gate case X86_VENDOR_AMD: 39690Sstevel@tonic-gate amd_l2cacheinfo(cpi, l2i); 39700Sstevel@tonic-gate break; 39710Sstevel@tonic-gate default: 39720Sstevel@tonic-gate break; 39730Sstevel@tonic-gate } 39740Sstevel@tonic-gate return (l2i->l2i_ret); 39750Sstevel@tonic-gate } 39764481Sbholler 39775084Sjohnlev #if !defined(__xpv) 39785084Sjohnlev 39795045Sbholler uint32_t * 39805045Sbholler cpuid_mwait_alloc(cpu_t *cpu) 39815045Sbholler { 39825045Sbholler uint32_t *ret; 39835045Sbholler size_t mwait_size; 39845045Sbholler 39855045Sbholler ASSERT(cpuid_checkpass(cpu, 2)); 39865045Sbholler 39875045Sbholler mwait_size = cpu->cpu_m.mcpu_cpi->cpi_mwait.mon_max; 39885045Sbholler if (mwait_size == 0) 39895045Sbholler return (NULL); 39905045Sbholler 39915045Sbholler /* 39925045Sbholler * kmem_alloc() returns cache line size aligned data for mwait_size 39935045Sbholler * allocations. mwait_size is currently cache line sized. Neither 39945045Sbholler * of these implementation details are guarantied to be true in the 39955045Sbholler * future. 39965045Sbholler * 39975045Sbholler * First try allocating mwait_size as kmem_alloc() currently returns 39985045Sbholler * correctly aligned memory. If kmem_alloc() does not return 39995045Sbholler * mwait_size aligned memory, then use mwait_size ROUNDUP. 40005045Sbholler * 40015045Sbholler * Set cpi_mwait.buf_actual and cpi_mwait.size_actual in case we 40025045Sbholler * decide to free this memory. 40035045Sbholler */ 40045045Sbholler ret = kmem_zalloc(mwait_size, KM_SLEEP); 40055045Sbholler if (ret == (uint32_t *)P2ROUNDUP((uintptr_t)ret, mwait_size)) { 40065045Sbholler cpu->cpu_m.mcpu_cpi->cpi_mwait.buf_actual = ret; 40075045Sbholler cpu->cpu_m.mcpu_cpi->cpi_mwait.size_actual = mwait_size; 40085045Sbholler *ret = MWAIT_RUNNING; 40095045Sbholler return (ret); 40105045Sbholler } else { 40115045Sbholler kmem_free(ret, mwait_size); 40125045Sbholler ret = kmem_zalloc(mwait_size * 2, KM_SLEEP); 40135045Sbholler cpu->cpu_m.mcpu_cpi->cpi_mwait.buf_actual = ret; 40145045Sbholler cpu->cpu_m.mcpu_cpi->cpi_mwait.size_actual = mwait_size * 2; 40155045Sbholler ret = (uint32_t *)P2ROUNDUP((uintptr_t)ret, mwait_size); 40165045Sbholler *ret = MWAIT_RUNNING; 40175045Sbholler return (ret); 40185045Sbholler } 40195045Sbholler } 40205045Sbholler 40215045Sbholler void 40225045Sbholler cpuid_mwait_free(cpu_t *cpu) 40234481Sbholler { 40244481Sbholler ASSERT(cpuid_checkpass(cpu, 2)); 40255045Sbholler 40265045Sbholler if (cpu->cpu_m.mcpu_cpi->cpi_mwait.buf_actual != NULL && 40275045Sbholler cpu->cpu_m.mcpu_cpi->cpi_mwait.size_actual > 0) { 40285045Sbholler kmem_free(cpu->cpu_m.mcpu_cpi->cpi_mwait.buf_actual, 40295045Sbholler cpu->cpu_m.mcpu_cpi->cpi_mwait.size_actual); 40305045Sbholler } 40315045Sbholler 40325045Sbholler cpu->cpu_m.mcpu_cpi->cpi_mwait.buf_actual = NULL; 40335045Sbholler cpu->cpu_m.mcpu_cpi->cpi_mwait.size_actual = 0; 40344481Sbholler } 40355084Sjohnlev 40365322Ssudheer void 40375322Ssudheer patch_tsc_read(int flag) 40385322Ssudheer { 40395322Ssudheer size_t cnt; 40407532SSean.Ye@Sun.COM 40415322Ssudheer switch (flag) { 40425322Ssudheer case X86_NO_TSC: 40435322Ssudheer cnt = &_no_rdtsc_end - &_no_rdtsc_start; 40445338Ssudheer (void) memcpy((void *)tsc_read, (void *)&_no_rdtsc_start, cnt); 40455322Ssudheer break; 40465322Ssudheer case X86_HAVE_TSCP: 40475322Ssudheer cnt = &_tscp_end - &_tscp_start; 40485338Ssudheer (void) memcpy((void *)tsc_read, (void *)&_tscp_start, cnt); 40495322Ssudheer break; 40505322Ssudheer case X86_TSC_MFENCE: 40515322Ssudheer cnt = &_tsc_mfence_end - &_tsc_mfence_start; 40525338Ssudheer (void) memcpy((void *)tsc_read, 40535338Ssudheer (void *)&_tsc_mfence_start, cnt); 40545322Ssudheer break; 40556642Ssudheer case X86_TSC_LFENCE: 40566642Ssudheer cnt = &_tsc_lfence_end - &_tsc_lfence_start; 40576642Ssudheer (void) memcpy((void *)tsc_read, 40586642Ssudheer (void *)&_tsc_lfence_start, cnt); 40596642Ssudheer break; 40605322Ssudheer default: 40615322Ssudheer break; 40625322Ssudheer } 40635322Ssudheer } 40645322Ssudheer 40658906SEric.Saxe@Sun.COM int 40668906SEric.Saxe@Sun.COM cpuid_deep_cstates_supported(void) 40678906SEric.Saxe@Sun.COM { 40688906SEric.Saxe@Sun.COM struct cpuid_info *cpi; 40698906SEric.Saxe@Sun.COM struct cpuid_regs regs; 40708906SEric.Saxe@Sun.COM 40718906SEric.Saxe@Sun.COM ASSERT(cpuid_checkpass(CPU, 1)); 40728906SEric.Saxe@Sun.COM 40738906SEric.Saxe@Sun.COM cpi = CPU->cpu_m.mcpu_cpi; 40748906SEric.Saxe@Sun.COM 40758906SEric.Saxe@Sun.COM if (!(x86_feature & X86_CPUID)) 40768906SEric.Saxe@Sun.COM return (0); 40778906SEric.Saxe@Sun.COM 40788906SEric.Saxe@Sun.COM switch (cpi->cpi_vendor) { 40798906SEric.Saxe@Sun.COM case X86_VENDOR_Intel: 40808906SEric.Saxe@Sun.COM if (cpi->cpi_xmaxeax < 0x80000007) 40818906SEric.Saxe@Sun.COM return (0); 40828906SEric.Saxe@Sun.COM 40838906SEric.Saxe@Sun.COM /* 40848906SEric.Saxe@Sun.COM * TSC run at a constant rate in all ACPI C-states? 40858906SEric.Saxe@Sun.COM */ 40868906SEric.Saxe@Sun.COM regs.cp_eax = 0x80000007; 40878906SEric.Saxe@Sun.COM (void) __cpuid_insn(®s); 40888906SEric.Saxe@Sun.COM return (regs.cp_edx & CPUID_TSC_CSTATE_INVARIANCE); 40898906SEric.Saxe@Sun.COM 40908906SEric.Saxe@Sun.COM default: 40918906SEric.Saxe@Sun.COM return (0); 40928906SEric.Saxe@Sun.COM } 40938906SEric.Saxe@Sun.COM } 40948906SEric.Saxe@Sun.COM 40958930SBill.Holler@Sun.COM #endif /* !__xpv */ 40968930SBill.Holler@Sun.COM 40978930SBill.Holler@Sun.COM void 40988930SBill.Holler@Sun.COM post_startup_cpu_fixups(void) 40998930SBill.Holler@Sun.COM { 41008930SBill.Holler@Sun.COM #ifndef __xpv 41018930SBill.Holler@Sun.COM /* 41028930SBill.Holler@Sun.COM * Some AMD processors support C1E state. Entering this state will 41038930SBill.Holler@Sun.COM * cause the local APIC timer to stop, which we can't deal with at 41048930SBill.Holler@Sun.COM * this time. 41058930SBill.Holler@Sun.COM */ 41068930SBill.Holler@Sun.COM if (cpuid_getvendor(CPU) == X86_VENDOR_AMD) { 41078930SBill.Holler@Sun.COM on_trap_data_t otd; 41088930SBill.Holler@Sun.COM uint64_t reg; 41098930SBill.Holler@Sun.COM 41108930SBill.Holler@Sun.COM if (!on_trap(&otd, OT_DATA_ACCESS)) { 41118930SBill.Holler@Sun.COM reg = rdmsr(MSR_AMD_INT_PENDING_CMP_HALT); 41128930SBill.Holler@Sun.COM /* Disable C1E state if it is enabled by BIOS */ 41138930SBill.Holler@Sun.COM if ((reg >> AMD_ACTONCMPHALT_SHIFT) & 41148930SBill.Holler@Sun.COM AMD_ACTONCMPHALT_MASK) { 41158930SBill.Holler@Sun.COM reg &= ~(AMD_ACTONCMPHALT_MASK << 41168930SBill.Holler@Sun.COM AMD_ACTONCMPHALT_SHIFT); 41178930SBill.Holler@Sun.COM wrmsr(MSR_AMD_INT_PENDING_CMP_HALT, reg); 41188930SBill.Holler@Sun.COM } 41198930SBill.Holler@Sun.COM } 41208930SBill.Holler@Sun.COM no_trap(); 41218930SBill.Holler@Sun.COM } 41228930SBill.Holler@Sun.COM #endif /* !__xpv */ 41238930SBill.Holler@Sun.COM } 41248930SBill.Holler@Sun.COM 41259283SBill.Holler@Sun.COM /* 41269283SBill.Holler@Sun.COM * Starting with the Westmere processor the local 41279283SBill.Holler@Sun.COM * APIC timer will continue running in all C-states, 41289283SBill.Holler@Sun.COM * including the deepest C-states. 41299283SBill.Holler@Sun.COM */ 41309283SBill.Holler@Sun.COM int 41319283SBill.Holler@Sun.COM cpuid_arat_supported(void) 41329283SBill.Holler@Sun.COM { 41339283SBill.Holler@Sun.COM struct cpuid_info *cpi; 41349283SBill.Holler@Sun.COM struct cpuid_regs regs; 41359283SBill.Holler@Sun.COM 41369283SBill.Holler@Sun.COM ASSERT(cpuid_checkpass(CPU, 1)); 41379283SBill.Holler@Sun.COM ASSERT(x86_feature & X86_CPUID); 41389283SBill.Holler@Sun.COM 41399283SBill.Holler@Sun.COM cpi = CPU->cpu_m.mcpu_cpi; 41409283SBill.Holler@Sun.COM 41419283SBill.Holler@Sun.COM switch (cpi->cpi_vendor) { 41429283SBill.Holler@Sun.COM case X86_VENDOR_Intel: 41439283SBill.Holler@Sun.COM /* 41449283SBill.Holler@Sun.COM * Always-running Local APIC Timer is 41459283SBill.Holler@Sun.COM * indicated by CPUID.6.EAX[2]. 41469283SBill.Holler@Sun.COM */ 41479283SBill.Holler@Sun.COM if (cpi->cpi_maxeax >= 6) { 41489283SBill.Holler@Sun.COM regs.cp_eax = 6; 41499283SBill.Holler@Sun.COM (void) cpuid_insn(NULL, ®s); 41509283SBill.Holler@Sun.COM return (regs.cp_eax & CPUID_CSTATE_ARAT); 41519283SBill.Holler@Sun.COM } else { 41529283SBill.Holler@Sun.COM return (0); 41539283SBill.Holler@Sun.COM } 41549283SBill.Holler@Sun.COM default: 41559283SBill.Holler@Sun.COM return (0); 41569283SBill.Holler@Sun.COM } 41579283SBill.Holler@Sun.COM } 41589283SBill.Holler@Sun.COM 415910992Saubrey.li@intel.com /* 416010992Saubrey.li@intel.com * Check support for Intel ENERGY_PERF_BIAS feature 416110992Saubrey.li@intel.com */ 416210992Saubrey.li@intel.com int 416310992Saubrey.li@intel.com cpuid_iepb_supported(struct cpu *cp) 416410992Saubrey.li@intel.com { 416510992Saubrey.li@intel.com struct cpuid_info *cpi = cp->cpu_m.mcpu_cpi; 416610992Saubrey.li@intel.com struct cpuid_regs regs; 416710992Saubrey.li@intel.com 416810992Saubrey.li@intel.com ASSERT(cpuid_checkpass(cp, 1)); 416910992Saubrey.li@intel.com 417010992Saubrey.li@intel.com if (!(x86_feature & X86_CPUID) || !(x86_feature & X86_MSR)) { 417110992Saubrey.li@intel.com return (0); 417210992Saubrey.li@intel.com } 417310992Saubrey.li@intel.com 417410992Saubrey.li@intel.com /* 417510992Saubrey.li@intel.com * Intel ENERGY_PERF_BIAS MSR is indicated by 417610992Saubrey.li@intel.com * capability bit CPUID.6.ECX.3 417710992Saubrey.li@intel.com */ 417810992Saubrey.li@intel.com if ((cpi->cpi_vendor != X86_VENDOR_Intel) || (cpi->cpi_maxeax < 6)) 417910992Saubrey.li@intel.com return (0); 418010992Saubrey.li@intel.com 418110992Saubrey.li@intel.com regs.cp_eax = 0x6; 418210992Saubrey.li@intel.com (void) cpuid_insn(NULL, ®s); 418310992Saubrey.li@intel.com return (regs.cp_ecx & CPUID_EPB_SUPPORT); 418410992Saubrey.li@intel.com } 418510992Saubrey.li@intel.com 41868377SBill.Holler@Sun.COM #if defined(__amd64) && !defined(__xpv) 41878377SBill.Holler@Sun.COM /* 41888377SBill.Holler@Sun.COM * Patch in versions of bcopy for high performance Intel Nhm processors 41898377SBill.Holler@Sun.COM * and later... 41908377SBill.Holler@Sun.COM */ 41918377SBill.Holler@Sun.COM void 41928377SBill.Holler@Sun.COM patch_memops(uint_t vendor) 41938377SBill.Holler@Sun.COM { 41948377SBill.Holler@Sun.COM size_t cnt, i; 41958377SBill.Holler@Sun.COM caddr_t to, from; 41968377SBill.Holler@Sun.COM 41978377SBill.Holler@Sun.COM if ((vendor == X86_VENDOR_Intel) && ((x86_feature & X86_SSE4_2) != 0)) { 41988377SBill.Holler@Sun.COM cnt = &bcopy_patch_end - &bcopy_patch_start; 41998377SBill.Holler@Sun.COM to = &bcopy_ck_size; 42008377SBill.Holler@Sun.COM from = &bcopy_patch_start; 42018377SBill.Holler@Sun.COM for (i = 0; i < cnt; i++) { 42028377SBill.Holler@Sun.COM *to++ = *from++; 42038377SBill.Holler@Sun.COM } 42048377SBill.Holler@Sun.COM } 42058377SBill.Holler@Sun.COM } 42068377SBill.Holler@Sun.COM #endif /* __amd64 && !__xpv */ 4207