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 */ 29*10947SSrihari.Venkatesan@Sun.COM /* 30*10947SSrihari.Venkatesan@Sun.COM * Portions Copyright 2009 Advanced Micro Devices, Inc. 31*10947SSrihari.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> 55*10947SSrihari.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 */ 160*10947SSrihari.Venkatesan@Sun.COM #define NMAX_CPI_EXTD 0x1c /* eax = 0x80000000 .. 0x8000001b */ 161*10947SSrihari.Venkatesan@Sun.COM 162*10947SSrihari.Venkatesan@Sun.COM /* 163*10947SSrihari.Venkatesan@Sun.COM * Some terminology needs to be explained: 164*10947SSrihari.Venkatesan@Sun.COM * - Socket: Something that can be plugged into a motherboard. 165*10947SSrihari.Venkatesan@Sun.COM * - Package: Same as socket 166*10947SSrihari.Venkatesan@Sun.COM * - Chip: Same as socket. Note that AMD's documentation uses term "chip" 167*10947SSrihari.Venkatesan@Sun.COM * differently: there, chip is the same as processor node (below) 168*10947SSrihari.Venkatesan@Sun.COM * - Processor node: Some AMD processors have more than one 169*10947SSrihari.Venkatesan@Sun.COM * "subprocessor" embedded in a package. These subprocessors (nodes) 170*10947SSrihari.Venkatesan@Sun.COM * are fully-functional processors themselves with cores, caches, 171*10947SSrihari.Venkatesan@Sun.COM * memory controllers, PCI configuration spaces. They are connected 172*10947SSrihari.Venkatesan@Sun.COM * inside the package with Hypertransport links. On single-node 173*10947SSrihari.Venkatesan@Sun.COM * processors, processor node is equivalent to chip/socket/package. 174*10947SSrihari.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 */ 188*10947SSrihari.Venkatesan@Sun.COM chipid_t cpi_chipid; /* fn 1: %ebx: Intel: chip # */ 189*10947SSrihari.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 */ 206*10947SSrihari.Venkatesan@Sun.COM uint8_t cpi_vabits; /* fn 0x80000006: %eax */ 207*10947SSrihari.Venkatesan@Sun.COM struct cpuid_regs cpi_extd[NMAX_CPI_EXTD]; /* 0x800000XX */ 208*10947SSrihari.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; 231*10947SSrihari.Venkatesan@Sun.COM uint_t cpi_procnodeid; /* AMD: nodeID on HT, Intel: chipid */ 232*10947SSrihari.Venkatesan@Sun.COM uint_t cpi_procnodes_per_pkg; /* AMD: # of nodes in the package */ 233*10947SSrihari.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 531*10947SSrihari.Venkatesan@Sun.COM static void 532*10947SSrihari.Venkatesan@Sun.COM cpuid_intel_getids(cpu_t *cpu, uint_t feature) 533*10947SSrihari.Venkatesan@Sun.COM { 534*10947SSrihari.Venkatesan@Sun.COM uint_t i; 535*10947SSrihari.Venkatesan@Sun.COM uint_t chipid_shift = 0; 536*10947SSrihari.Venkatesan@Sun.COM uint_t coreid_shift = 0; 537*10947SSrihari.Venkatesan@Sun.COM struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 538*10947SSrihari.Venkatesan@Sun.COM 539*10947SSrihari.Venkatesan@Sun.COM for (i = 1; i < cpi->cpi_ncpu_per_chip; i <<= 1) 540*10947SSrihari.Venkatesan@Sun.COM chipid_shift++; 541*10947SSrihari.Venkatesan@Sun.COM 542*10947SSrihari.Venkatesan@Sun.COM cpi->cpi_chipid = cpi->cpi_apicid >> chipid_shift; 543*10947SSrihari.Venkatesan@Sun.COM cpi->cpi_clogid = cpi->cpi_apicid & ((1 << chipid_shift) - 1); 544*10947SSrihari.Venkatesan@Sun.COM 545*10947SSrihari.Venkatesan@Sun.COM if (feature & X86_CMP) { 546*10947SSrihari.Venkatesan@Sun.COM /* 547*10947SSrihari.Venkatesan@Sun.COM * Multi-core (and possibly multi-threaded) 548*10947SSrihari.Venkatesan@Sun.COM * processors. 549*10947SSrihari.Venkatesan@Sun.COM */ 550*10947SSrihari.Venkatesan@Sun.COM uint_t ncpu_per_core; 551*10947SSrihari.Venkatesan@Sun.COM if (cpi->cpi_ncore_per_chip == 1) 552*10947SSrihari.Venkatesan@Sun.COM ncpu_per_core = cpi->cpi_ncpu_per_chip; 553*10947SSrihari.Venkatesan@Sun.COM else if (cpi->cpi_ncore_per_chip > 1) 554*10947SSrihari.Venkatesan@Sun.COM ncpu_per_core = cpi->cpi_ncpu_per_chip / 555*10947SSrihari.Venkatesan@Sun.COM cpi->cpi_ncore_per_chip; 556*10947SSrihari.Venkatesan@Sun.COM /* 557*10947SSrihari.Venkatesan@Sun.COM * 8bit APIC IDs on dual core Pentiums 558*10947SSrihari.Venkatesan@Sun.COM * look like this: 559*10947SSrihari.Venkatesan@Sun.COM * 560*10947SSrihari.Venkatesan@Sun.COM * +-----------------------+------+------+ 561*10947SSrihari.Venkatesan@Sun.COM * | Physical Package ID | MC | HT | 562*10947SSrihari.Venkatesan@Sun.COM * +-----------------------+------+------+ 563*10947SSrihari.Venkatesan@Sun.COM * <------- chipid --------> 564*10947SSrihari.Venkatesan@Sun.COM * <------- coreid ---------------> 565*10947SSrihari.Venkatesan@Sun.COM * <--- clogid --> 566*10947SSrihari.Venkatesan@Sun.COM * <------> 567*10947SSrihari.Venkatesan@Sun.COM * pkgcoreid 568*10947SSrihari.Venkatesan@Sun.COM * 569*10947SSrihari.Venkatesan@Sun.COM * Where the number of bits necessary to 570*10947SSrihari.Venkatesan@Sun.COM * represent MC and HT fields together equals 571*10947SSrihari.Venkatesan@Sun.COM * to the minimum number of bits necessary to 572*10947SSrihari.Venkatesan@Sun.COM * store the value of cpi->cpi_ncpu_per_chip. 573*10947SSrihari.Venkatesan@Sun.COM * Of those bits, the MC part uses the number 574*10947SSrihari.Venkatesan@Sun.COM * of bits necessary to store the value of 575*10947SSrihari.Venkatesan@Sun.COM * cpi->cpi_ncore_per_chip. 576*10947SSrihari.Venkatesan@Sun.COM */ 577*10947SSrihari.Venkatesan@Sun.COM for (i = 1; i < ncpu_per_core; i <<= 1) 578*10947SSrihari.Venkatesan@Sun.COM coreid_shift++; 579*10947SSrihari.Venkatesan@Sun.COM cpi->cpi_coreid = cpi->cpi_apicid >> coreid_shift; 580*10947SSrihari.Venkatesan@Sun.COM cpi->cpi_pkgcoreid = cpi->cpi_clogid >> coreid_shift; 581*10947SSrihari.Venkatesan@Sun.COM } else if (feature & X86_HTT) { 582*10947SSrihari.Venkatesan@Sun.COM /* 583*10947SSrihari.Venkatesan@Sun.COM * Single-core multi-threaded processors. 584*10947SSrihari.Venkatesan@Sun.COM */ 585*10947SSrihari.Venkatesan@Sun.COM cpi->cpi_coreid = cpi->cpi_chipid; 586*10947SSrihari.Venkatesan@Sun.COM cpi->cpi_pkgcoreid = 0; 587*10947SSrihari.Venkatesan@Sun.COM } 588*10947SSrihari.Venkatesan@Sun.COM cpi->cpi_procnodeid = cpi->cpi_chipid; 589*10947SSrihari.Venkatesan@Sun.COM } 590*10947SSrihari.Venkatesan@Sun.COM 591*10947SSrihari.Venkatesan@Sun.COM static void 592*10947SSrihari.Venkatesan@Sun.COM cpuid_amd_getids(cpu_t *cpu) 593*10947SSrihari.Venkatesan@Sun.COM { 594*10947SSrihari.Venkatesan@Sun.COM int first_half, mnc, coreidsz; 595*10947SSrihari.Venkatesan@Sun.COM uint32_t nb_caps_reg; 596*10947SSrihari.Venkatesan@Sun.COM uint_t node2_1; 597*10947SSrihari.Venkatesan@Sun.COM struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 598*10947SSrihari.Venkatesan@Sun.COM 599*10947SSrihari.Venkatesan@Sun.COM /* 600*10947SSrihari.Venkatesan@Sun.COM * AMD CMP chips currently have a single thread per core. 601*10947SSrihari.Venkatesan@Sun.COM * 602*10947SSrihari.Venkatesan@Sun.COM * Since no two cpus share a core we must assign a distinct coreid 603*10947SSrihari.Venkatesan@Sun.COM * per cpu, and we do this by using the cpu_id. This scheme does not, 604*10947SSrihari.Venkatesan@Sun.COM * however, guarantee that sibling cores of a chip will have sequential 605*10947SSrihari.Venkatesan@Sun.COM * coreids starting at a multiple of the number of cores per chip - 606*10947SSrihari.Venkatesan@Sun.COM * that is usually the case, but if the ACPI MADT table is presented 607*10947SSrihari.Venkatesan@Sun.COM * in a different order then we need to perform a few more gymnastics 608*10947SSrihari.Venkatesan@Sun.COM * for the pkgcoreid. 609*10947SSrihari.Venkatesan@Sun.COM * 610*10947SSrihari.Venkatesan@Sun.COM * All processors in the system have the same number of enabled 611*10947SSrihari.Venkatesan@Sun.COM * cores. Cores within a processor are always numbered sequentially 612*10947SSrihari.Venkatesan@Sun.COM * from 0 regardless of how many or which are disabled, and there 613*10947SSrihari.Venkatesan@Sun.COM * is no way for operating system to discover the real core id when some 614*10947SSrihari.Venkatesan@Sun.COM * are disabled. 615*10947SSrihari.Venkatesan@Sun.COM */ 616*10947SSrihari.Venkatesan@Sun.COM 617*10947SSrihari.Venkatesan@Sun.COM cpi->cpi_coreid = cpu->cpu_id; 618*10947SSrihari.Venkatesan@Sun.COM 619*10947SSrihari.Venkatesan@Sun.COM if (cpi->cpi_xmaxeax >= 0x80000008) { 620*10947SSrihari.Venkatesan@Sun.COM 621*10947SSrihari.Venkatesan@Sun.COM coreidsz = BITX((cpi)->cpi_extd[8].cp_ecx, 15, 12); 622*10947SSrihari.Venkatesan@Sun.COM 623*10947SSrihari.Venkatesan@Sun.COM /* 624*10947SSrihari.Venkatesan@Sun.COM * In AMD parlance chip is really a node while Solaris 625*10947SSrihari.Venkatesan@Sun.COM * sees chip as equivalent to socket/package. 626*10947SSrihari.Venkatesan@Sun.COM */ 627*10947SSrihari.Venkatesan@Sun.COM cpi->cpi_ncore_per_chip = 628*10947SSrihari.Venkatesan@Sun.COM BITX((cpi)->cpi_extd[8].cp_ecx, 7, 0) + 1; 629*10947SSrihari.Venkatesan@Sun.COM if (coreidsz == 0) 630*10947SSrihari.Venkatesan@Sun.COM /* Use legacy method */ 631*10947SSrihari.Venkatesan@Sun.COM mnc = cpi->cpi_ncore_per_chip; 632*10947SSrihari.Venkatesan@Sun.COM else 633*10947SSrihari.Venkatesan@Sun.COM mnc = (1 << coreidsz); 634*10947SSrihari.Venkatesan@Sun.COM } else { 635*10947SSrihari.Venkatesan@Sun.COM /* Assume single-core part */ 636*10947SSrihari.Venkatesan@Sun.COM cpi->cpi_ncore_per_chip = mnc = 1; 637*10947SSrihari.Venkatesan@Sun.COM } 638*10947SSrihari.Venkatesan@Sun.COM 639*10947SSrihari.Venkatesan@Sun.COM cpi->cpi_clogid = cpi->cpi_pkgcoreid = cpi->cpi_apicid & (mnc - 1); 640*10947SSrihari.Venkatesan@Sun.COM cpi->cpi_ncpu_per_chip = cpi->cpi_ncore_per_chip; 641*10947SSrihari.Venkatesan@Sun.COM 642*10947SSrihari.Venkatesan@Sun.COM /* Get nodeID */ 643*10947SSrihari.Venkatesan@Sun.COM if (cpi->cpi_family == 0xf) { 644*10947SSrihari.Venkatesan@Sun.COM cpi->cpi_procnodeid = BITX(cpi->cpi_apicid, 3, mnc-1); 645*10947SSrihari.Venkatesan@Sun.COM cpi->cpi_chipid = cpi->cpi_procnodeid; 646*10947SSrihari.Venkatesan@Sun.COM } else if (cpi->cpi_family == 0x10) { 647*10947SSrihari.Venkatesan@Sun.COM /* 648*10947SSrihari.Venkatesan@Sun.COM * See if we are a multi-node processor. 649*10947SSrihari.Venkatesan@Sun.COM * All processors in the system have the same number of nodes 650*10947SSrihari.Venkatesan@Sun.COM */ 651*10947SSrihari.Venkatesan@Sun.COM nb_caps_reg = pci_getl_func(0, 24, 3, 0xe8); 652*10947SSrihari.Venkatesan@Sun.COM if ((cpi->cpi_model < 8) || BITX(nb_caps_reg, 29, 29) == 0) { 653*10947SSrihari.Venkatesan@Sun.COM /* Single-node */ 654*10947SSrihari.Venkatesan@Sun.COM cpi->cpi_procnodeid = BITX(cpi->cpi_apicid, 5, 3); 655*10947SSrihari.Venkatesan@Sun.COM cpi->cpi_chipid = cpi->cpi_procnodeid; 656*10947SSrihari.Venkatesan@Sun.COM } else { 657*10947SSrihari.Venkatesan@Sun.COM 658*10947SSrihari.Venkatesan@Sun.COM /* 659*10947SSrihari.Venkatesan@Sun.COM * Multi-node revision D (2 nodes per package 660*10947SSrihari.Venkatesan@Sun.COM * are supported) 661*10947SSrihari.Venkatesan@Sun.COM */ 662*10947SSrihari.Venkatesan@Sun.COM cpi->cpi_procnodes_per_pkg = 2; 663*10947SSrihari.Venkatesan@Sun.COM 664*10947SSrihari.Venkatesan@Sun.COM first_half = (cpi->cpi_pkgcoreid <= 665*10947SSrihari.Venkatesan@Sun.COM (cpi->cpi_ncore_per_chip/2 - 1)); 666*10947SSrihari.Venkatesan@Sun.COM 667*10947SSrihari.Venkatesan@Sun.COM if (cpi->cpi_apicid == cpi->cpi_pkgcoreid) { 668*10947SSrihari.Venkatesan@Sun.COM /* We are BSP */ 669*10947SSrihari.Venkatesan@Sun.COM cpi->cpi_procnodeid = (first_half ? 0 : 1); 670*10947SSrihari.Venkatesan@Sun.COM cpi->cpi_chipid = cpi->cpi_procnodeid >> 1; 671*10947SSrihari.Venkatesan@Sun.COM } else { 672*10947SSrihari.Venkatesan@Sun.COM 673*10947SSrihari.Venkatesan@Sun.COM /* We are AP */ 674*10947SSrihari.Venkatesan@Sun.COM /* NodeId[2:1] bits to use for reading F3xe8 */ 675*10947SSrihari.Venkatesan@Sun.COM node2_1 = BITX(cpi->cpi_apicid, 5, 4) << 1; 676*10947SSrihari.Venkatesan@Sun.COM 677*10947SSrihari.Venkatesan@Sun.COM nb_caps_reg = 678*10947SSrihari.Venkatesan@Sun.COM pci_getl_func(0, 24 + node2_1, 3, 0xe8); 679*10947SSrihari.Venkatesan@Sun.COM 680*10947SSrihari.Venkatesan@Sun.COM /* 681*10947SSrihari.Venkatesan@Sun.COM * Check IntNodeNum bit (31:30, but bit 31 is 682*10947SSrihari.Venkatesan@Sun.COM * always 0 on dual-node processors) 683*10947SSrihari.Venkatesan@Sun.COM */ 684*10947SSrihari.Venkatesan@Sun.COM if (BITX(nb_caps_reg, 30, 30) == 0) 685*10947SSrihari.Venkatesan@Sun.COM cpi->cpi_procnodeid = node2_1 + 686*10947SSrihari.Venkatesan@Sun.COM !first_half; 687*10947SSrihari.Venkatesan@Sun.COM else 688*10947SSrihari.Venkatesan@Sun.COM cpi->cpi_procnodeid = node2_1 + 689*10947SSrihari.Venkatesan@Sun.COM first_half; 690*10947SSrihari.Venkatesan@Sun.COM 691*10947SSrihari.Venkatesan@Sun.COM cpi->cpi_chipid = cpi->cpi_procnodeid >> 1; 692*10947SSrihari.Venkatesan@Sun.COM } 693*10947SSrihari.Venkatesan@Sun.COM } 694*10947SSrihari.Venkatesan@Sun.COM } else if (cpi->cpi_family >= 0x11) { 695*10947SSrihari.Venkatesan@Sun.COM cpi->cpi_procnodeid = (cpi->cpi_apicid >> coreidsz) & 7; 696*10947SSrihari.Venkatesan@Sun.COM cpi->cpi_chipid = cpi->cpi_procnodeid; 697*10947SSrihari.Venkatesan@Sun.COM } else { 698*10947SSrihari.Venkatesan@Sun.COM cpi->cpi_procnodeid = 0; 699*10947SSrihari.Venkatesan@Sun.COM cpi->cpi_chipid = cpi->cpi_procnodeid; 700*10947SSrihari.Venkatesan@Sun.COM } 701*10947SSrihari.Venkatesan@Sun.COM } 702*10947SSrihari.Venkatesan@Sun.COM 7030Sstevel@tonic-gate uint_t 7040Sstevel@tonic-gate cpuid_pass1(cpu_t *cpu) 7050Sstevel@tonic-gate { 7060Sstevel@tonic-gate uint32_t mask_ecx, mask_edx; 7070Sstevel@tonic-gate uint_t feature = X86_CPUID; 7080Sstevel@tonic-gate struct cpuid_info *cpi; 7091228Sandrei struct cpuid_regs *cp; 7100Sstevel@tonic-gate int xcpuid; 7115084Sjohnlev #if !defined(__xpv) 7125045Sbholler extern int idle_cpu_prefer_mwait; 7135084Sjohnlev #endif 7143446Smrj 7159482SKuriakose.Kuruvilla@Sun.COM 7169482SKuriakose.Kuruvilla@Sun.COM #if !defined(__xpv) 7179482SKuriakose.Kuruvilla@Sun.COM determine_platform(); 7189482SKuriakose.Kuruvilla@Sun.COM #endif 7190Sstevel@tonic-gate /* 7203446Smrj * Space statically allocated for cpu0, ensure pointer is set 7210Sstevel@tonic-gate */ 7220Sstevel@tonic-gate if (cpu->cpu_id == 0) 7233446Smrj cpu->cpu_m.mcpu_cpi = &cpuid_info0; 7243446Smrj cpi = cpu->cpu_m.mcpu_cpi; 7253446Smrj ASSERT(cpi != NULL); 7260Sstevel@tonic-gate cp = &cpi->cpi_std[0]; 7271228Sandrei cp->cp_eax = 0; 7281228Sandrei cpi->cpi_maxeax = __cpuid_insn(cp); 7290Sstevel@tonic-gate { 7300Sstevel@tonic-gate uint32_t *iptr = (uint32_t *)cpi->cpi_vendorstr; 7310Sstevel@tonic-gate *iptr++ = cp->cp_ebx; 7320Sstevel@tonic-gate *iptr++ = cp->cp_edx; 7330Sstevel@tonic-gate *iptr++ = cp->cp_ecx; 7340Sstevel@tonic-gate *(char *)&cpi->cpi_vendorstr[12] = '\0'; 7350Sstevel@tonic-gate } 7360Sstevel@tonic-gate 7377532SSean.Ye@Sun.COM cpi->cpi_vendor = _cpuid_vendorstr_to_vendorcode(cpi->cpi_vendorstr); 7380Sstevel@tonic-gate x86_vendor = cpi->cpi_vendor; /* for compatibility */ 7390Sstevel@tonic-gate 7400Sstevel@tonic-gate /* 7410Sstevel@tonic-gate * Limit the range in case of weird hardware 7420Sstevel@tonic-gate */ 7430Sstevel@tonic-gate if (cpi->cpi_maxeax > CPI_MAXEAX_MAX) 7440Sstevel@tonic-gate cpi->cpi_maxeax = CPI_MAXEAX_MAX; 7450Sstevel@tonic-gate if (cpi->cpi_maxeax < 1) 7460Sstevel@tonic-gate goto pass1_done; 7470Sstevel@tonic-gate 7480Sstevel@tonic-gate cp = &cpi->cpi_std[1]; 7491228Sandrei cp->cp_eax = 1; 7501228Sandrei (void) __cpuid_insn(cp); 7510Sstevel@tonic-gate 7520Sstevel@tonic-gate /* 7530Sstevel@tonic-gate * Extract identifying constants for easy access. 7540Sstevel@tonic-gate */ 7550Sstevel@tonic-gate cpi->cpi_model = CPI_MODEL(cpi); 7560Sstevel@tonic-gate cpi->cpi_family = CPI_FAMILY(cpi); 7570Sstevel@tonic-gate 7581975Sdmick if (cpi->cpi_family == 0xf) 7590Sstevel@tonic-gate cpi->cpi_family += CPI_FAMILY_XTD(cpi); 7601975Sdmick 7612001Sdmick /* 7624265Skchow * Beware: AMD uses "extended model" iff base *FAMILY* == 0xf. 7632001Sdmick * Intel, and presumably everyone else, uses model == 0xf, as 7642001Sdmick * one would expect (max value means possible overflow). Sigh. 7652001Sdmick */ 7662001Sdmick 7672001Sdmick switch (cpi->cpi_vendor) { 7684855Sksadhukh case X86_VENDOR_Intel: 7694855Sksadhukh if (IS_EXTENDED_MODEL_INTEL(cpi)) 7704855Sksadhukh cpi->cpi_model += CPI_MODEL_XTD(cpi) << 4; 7714858Sksadhukh break; 7722001Sdmick case X86_VENDOR_AMD: 7734265Skchow if (CPI_FAMILY(cpi) == 0xf) 7742001Sdmick cpi->cpi_model += CPI_MODEL_XTD(cpi) << 4; 7752001Sdmick break; 7762001Sdmick default: 7772001Sdmick if (cpi->cpi_model == 0xf) 7782001Sdmick cpi->cpi_model += CPI_MODEL_XTD(cpi) << 4; 7792001Sdmick break; 7802001Sdmick } 7810Sstevel@tonic-gate 7820Sstevel@tonic-gate cpi->cpi_step = CPI_STEP(cpi); 7830Sstevel@tonic-gate cpi->cpi_brandid = CPI_BRANDID(cpi); 7840Sstevel@tonic-gate 7850Sstevel@tonic-gate /* 7860Sstevel@tonic-gate * *default* assumptions: 7870Sstevel@tonic-gate * - believe %edx feature word 7880Sstevel@tonic-gate * - ignore %ecx feature word 7890Sstevel@tonic-gate * - 32-bit virtual and physical addressing 7900Sstevel@tonic-gate */ 7910Sstevel@tonic-gate mask_edx = 0xffffffff; 7920Sstevel@tonic-gate mask_ecx = 0; 7930Sstevel@tonic-gate 7940Sstevel@tonic-gate cpi->cpi_pabits = cpi->cpi_vabits = 32; 7950Sstevel@tonic-gate 7960Sstevel@tonic-gate switch (cpi->cpi_vendor) { 7970Sstevel@tonic-gate case X86_VENDOR_Intel: 7980Sstevel@tonic-gate if (cpi->cpi_family == 5) 7990Sstevel@tonic-gate x86_type = X86_TYPE_P5; 8001975Sdmick else if (IS_LEGACY_P6(cpi)) { 8010Sstevel@tonic-gate x86_type = X86_TYPE_P6; 8020Sstevel@tonic-gate pentiumpro_bug4046376 = 1; 8030Sstevel@tonic-gate pentiumpro_bug4064495 = 1; 8040Sstevel@tonic-gate /* 8050Sstevel@tonic-gate * Clear the SEP bit when it was set erroneously 8060Sstevel@tonic-gate */ 8070Sstevel@tonic-gate if (cpi->cpi_model < 3 && cpi->cpi_step < 3) 8080Sstevel@tonic-gate cp->cp_edx &= ~CPUID_INTC_EDX_SEP; 8091975Sdmick } else if (IS_NEW_F6(cpi) || cpi->cpi_family == 0xf) { 8100Sstevel@tonic-gate x86_type = X86_TYPE_P4; 8110Sstevel@tonic-gate /* 8120Sstevel@tonic-gate * We don't currently depend on any of the %ecx 8130Sstevel@tonic-gate * features until Prescott, so we'll only check 8140Sstevel@tonic-gate * this from P4 onwards. We might want to revisit 8150Sstevel@tonic-gate * that idea later. 8160Sstevel@tonic-gate */ 8170Sstevel@tonic-gate mask_ecx = 0xffffffff; 8180Sstevel@tonic-gate } else if (cpi->cpi_family > 0xf) 8190Sstevel@tonic-gate mask_ecx = 0xffffffff; 8204636Sbholler /* 8214636Sbholler * We don't support MONITOR/MWAIT if leaf 5 is not available 8224636Sbholler * to obtain the monitor linesize. 8234636Sbholler */ 8244636Sbholler if (cpi->cpi_maxeax < 5) 8254636Sbholler mask_ecx &= ~CPUID_INTC_ECX_MON; 8260Sstevel@tonic-gate break; 8270Sstevel@tonic-gate case X86_VENDOR_IntelClone: 8280Sstevel@tonic-gate default: 8290Sstevel@tonic-gate break; 8300Sstevel@tonic-gate case X86_VENDOR_AMD: 8310Sstevel@tonic-gate #if defined(OPTERON_ERRATUM_108) 8320Sstevel@tonic-gate if (cpi->cpi_family == 0xf && cpi->cpi_model == 0xe) { 8330Sstevel@tonic-gate cp->cp_eax = (0xf0f & cp->cp_eax) | 0xc0; 8340Sstevel@tonic-gate cpi->cpi_model = 0xc; 8350Sstevel@tonic-gate } else 8360Sstevel@tonic-gate #endif 8370Sstevel@tonic-gate if (cpi->cpi_family == 5) { 8380Sstevel@tonic-gate /* 8390Sstevel@tonic-gate * AMD K5 and K6 8400Sstevel@tonic-gate * 8410Sstevel@tonic-gate * These CPUs have an incomplete implementation 8420Sstevel@tonic-gate * of MCA/MCE which we mask away. 8430Sstevel@tonic-gate */ 8441228Sandrei mask_edx &= ~(CPUID_INTC_EDX_MCE | CPUID_INTC_EDX_MCA); 8451228Sandrei 8461228Sandrei /* 8471228Sandrei * Model 0 uses the wrong (APIC) bit 8481228Sandrei * to indicate PGE. Fix it here. 8491228Sandrei */ 8500Sstevel@tonic-gate if (cpi->cpi_model == 0) { 8510Sstevel@tonic-gate if (cp->cp_edx & 0x200) { 8520Sstevel@tonic-gate cp->cp_edx &= ~0x200; 8530Sstevel@tonic-gate cp->cp_edx |= CPUID_INTC_EDX_PGE; 8540Sstevel@tonic-gate } 8551228Sandrei } 8561228Sandrei 8571228Sandrei /* 8581228Sandrei * Early models had problems w/ MMX; disable. 8591228Sandrei */ 8601228Sandrei if (cpi->cpi_model < 6) 8611228Sandrei mask_edx &= ~CPUID_INTC_EDX_MMX; 8621228Sandrei } 8631228Sandrei 8641228Sandrei /* 8651228Sandrei * For newer families, SSE3 and CX16, at least, are valid; 8661228Sandrei * enable all 8671228Sandrei */ 8681228Sandrei if (cpi->cpi_family >= 0xf) 869771Sdmick mask_ecx = 0xffffffff; 8704636Sbholler /* 8714636Sbholler * We don't support MONITOR/MWAIT if leaf 5 is not available 8724636Sbholler * to obtain the monitor linesize. 8734636Sbholler */ 8744636Sbholler if (cpi->cpi_maxeax < 5) 8754636Sbholler mask_ecx &= ~CPUID_INTC_ECX_MON; 8765045Sbholler 8775084Sjohnlev #if !defined(__xpv) 8785045Sbholler /* 8795045Sbholler * Do not use MONITOR/MWAIT to halt in the idle loop on any AMD 8805045Sbholler * processors. AMD does not intend MWAIT to be used in the cpu 8815045Sbholler * idle loop on current and future processors. 10h and future 8825045Sbholler * AMD processors use more power in MWAIT than HLT. 8835045Sbholler * Pre-family-10h Opterons do not have the MWAIT instruction. 8845045Sbholler */ 8855045Sbholler idle_cpu_prefer_mwait = 0; 8865084Sjohnlev #endif 8875045Sbholler 8880Sstevel@tonic-gate break; 8890Sstevel@tonic-gate case X86_VENDOR_TM: 8900Sstevel@tonic-gate /* 8910Sstevel@tonic-gate * workaround the NT workaround in CMS 4.1 8920Sstevel@tonic-gate */ 8930Sstevel@tonic-gate if (cpi->cpi_family == 5 && cpi->cpi_model == 4 && 8940Sstevel@tonic-gate (cpi->cpi_step == 2 || cpi->cpi_step == 3)) 8950Sstevel@tonic-gate cp->cp_edx |= CPUID_INTC_EDX_CX8; 8960Sstevel@tonic-gate break; 8970Sstevel@tonic-gate case X86_VENDOR_Centaur: 8980Sstevel@tonic-gate /* 8990Sstevel@tonic-gate * workaround the NT workarounds again 9000Sstevel@tonic-gate */ 9010Sstevel@tonic-gate if (cpi->cpi_family == 6) 9020Sstevel@tonic-gate cp->cp_edx |= CPUID_INTC_EDX_CX8; 9030Sstevel@tonic-gate break; 9040Sstevel@tonic-gate case X86_VENDOR_Cyrix: 9050Sstevel@tonic-gate /* 9060Sstevel@tonic-gate * We rely heavily on the probing in locore 9070Sstevel@tonic-gate * to actually figure out what parts, if any, 9080Sstevel@tonic-gate * of the Cyrix cpuid instruction to believe. 9090Sstevel@tonic-gate */ 9100Sstevel@tonic-gate switch (x86_type) { 9110Sstevel@tonic-gate case X86_TYPE_CYRIX_486: 9120Sstevel@tonic-gate mask_edx = 0; 9130Sstevel@tonic-gate break; 9140Sstevel@tonic-gate case X86_TYPE_CYRIX_6x86: 9150Sstevel@tonic-gate mask_edx = 0; 9160Sstevel@tonic-gate break; 9170Sstevel@tonic-gate case X86_TYPE_CYRIX_6x86L: 9180Sstevel@tonic-gate mask_edx = 9190Sstevel@tonic-gate CPUID_INTC_EDX_DE | 9200Sstevel@tonic-gate CPUID_INTC_EDX_CX8; 9210Sstevel@tonic-gate break; 9220Sstevel@tonic-gate case X86_TYPE_CYRIX_6x86MX: 9230Sstevel@tonic-gate mask_edx = 9240Sstevel@tonic-gate CPUID_INTC_EDX_DE | 9250Sstevel@tonic-gate CPUID_INTC_EDX_MSR | 9260Sstevel@tonic-gate CPUID_INTC_EDX_CX8 | 9270Sstevel@tonic-gate CPUID_INTC_EDX_PGE | 9280Sstevel@tonic-gate CPUID_INTC_EDX_CMOV | 9290Sstevel@tonic-gate CPUID_INTC_EDX_MMX; 9300Sstevel@tonic-gate break; 9310Sstevel@tonic-gate case X86_TYPE_CYRIX_GXm: 9320Sstevel@tonic-gate mask_edx = 9330Sstevel@tonic-gate CPUID_INTC_EDX_MSR | 9340Sstevel@tonic-gate CPUID_INTC_EDX_CX8 | 9350Sstevel@tonic-gate CPUID_INTC_EDX_CMOV | 9360Sstevel@tonic-gate CPUID_INTC_EDX_MMX; 9370Sstevel@tonic-gate break; 9380Sstevel@tonic-gate case X86_TYPE_CYRIX_MediaGX: 9390Sstevel@tonic-gate break; 9400Sstevel@tonic-gate case X86_TYPE_CYRIX_MII: 9410Sstevel@tonic-gate case X86_TYPE_VIA_CYRIX_III: 9420Sstevel@tonic-gate mask_edx = 9430Sstevel@tonic-gate CPUID_INTC_EDX_DE | 9440Sstevel@tonic-gate CPUID_INTC_EDX_TSC | 9450Sstevel@tonic-gate CPUID_INTC_EDX_MSR | 9460Sstevel@tonic-gate CPUID_INTC_EDX_CX8 | 9470Sstevel@tonic-gate CPUID_INTC_EDX_PGE | 9480Sstevel@tonic-gate CPUID_INTC_EDX_CMOV | 9490Sstevel@tonic-gate CPUID_INTC_EDX_MMX; 9500Sstevel@tonic-gate break; 9510Sstevel@tonic-gate default: 9520Sstevel@tonic-gate break; 9530Sstevel@tonic-gate } 9540Sstevel@tonic-gate break; 9550Sstevel@tonic-gate } 9560Sstevel@tonic-gate 9575084Sjohnlev #if defined(__xpv) 9585084Sjohnlev /* 9595084Sjohnlev * Do not support MONITOR/MWAIT under a hypervisor 9605084Sjohnlev */ 9615084Sjohnlev mask_ecx &= ~CPUID_INTC_ECX_MON; 9625084Sjohnlev #endif /* __xpv */ 9635084Sjohnlev 9640Sstevel@tonic-gate /* 9650Sstevel@tonic-gate * Now we've figured out the masks that determine 9660Sstevel@tonic-gate * which bits we choose to believe, apply the masks 9670Sstevel@tonic-gate * to the feature words, then map the kernel's view 9680Sstevel@tonic-gate * of these feature words into its feature word. 9690Sstevel@tonic-gate */ 9700Sstevel@tonic-gate cp->cp_edx &= mask_edx; 9710Sstevel@tonic-gate cp->cp_ecx &= mask_ecx; 9720Sstevel@tonic-gate 9730Sstevel@tonic-gate /* 9743446Smrj * apply any platform restrictions (we don't call this 9753446Smrj * immediately after __cpuid_insn here, because we need the 9763446Smrj * workarounds applied above first) 9770Sstevel@tonic-gate */ 9783446Smrj platform_cpuid_mangle(cpi->cpi_vendor, 1, cp); 9790Sstevel@tonic-gate 9803446Smrj /* 9813446Smrj * fold in overrides from the "eeprom" mechanism 9823446Smrj */ 9830Sstevel@tonic-gate cp->cp_edx |= cpuid_feature_edx_include; 9840Sstevel@tonic-gate cp->cp_edx &= ~cpuid_feature_edx_exclude; 9850Sstevel@tonic-gate 9860Sstevel@tonic-gate cp->cp_ecx |= cpuid_feature_ecx_include; 9870Sstevel@tonic-gate cp->cp_ecx &= ~cpuid_feature_ecx_exclude; 9880Sstevel@tonic-gate 9890Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_PSE) 9900Sstevel@tonic-gate feature |= X86_LARGEPAGE; 9910Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_TSC) 9920Sstevel@tonic-gate feature |= X86_TSC; 9930Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_MSR) 9940Sstevel@tonic-gate feature |= X86_MSR; 9950Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_MTRR) 9960Sstevel@tonic-gate feature |= X86_MTRR; 9970Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_PGE) 9980Sstevel@tonic-gate feature |= X86_PGE; 9990Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_CMOV) 10000Sstevel@tonic-gate feature |= X86_CMOV; 10010Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_MMX) 10020Sstevel@tonic-gate feature |= X86_MMX; 10030Sstevel@tonic-gate if ((cp->cp_edx & CPUID_INTC_EDX_MCE) != 0 && 10040Sstevel@tonic-gate (cp->cp_edx & CPUID_INTC_EDX_MCA) != 0) 10050Sstevel@tonic-gate feature |= X86_MCA; 10060Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_PAE) 10070Sstevel@tonic-gate feature |= X86_PAE; 10080Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_CX8) 10090Sstevel@tonic-gate feature |= X86_CX8; 10100Sstevel@tonic-gate if (cp->cp_ecx & CPUID_INTC_ECX_CX16) 10110Sstevel@tonic-gate feature |= X86_CX16; 10120Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_PAT) 10130Sstevel@tonic-gate feature |= X86_PAT; 10140Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_SEP) 10150Sstevel@tonic-gate feature |= X86_SEP; 10160Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_FXSR) { 10170Sstevel@tonic-gate /* 10180Sstevel@tonic-gate * In our implementation, fxsave/fxrstor 10190Sstevel@tonic-gate * are prerequisites before we'll even 10200Sstevel@tonic-gate * try and do SSE things. 10210Sstevel@tonic-gate */ 10220Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_SSE) 10230Sstevel@tonic-gate feature |= X86_SSE; 10240Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_SSE2) 10250Sstevel@tonic-gate feature |= X86_SSE2; 10260Sstevel@tonic-gate if (cp->cp_ecx & CPUID_INTC_ECX_SSE3) 10270Sstevel@tonic-gate feature |= X86_SSE3; 10285269Skk208521 if (cpi->cpi_vendor == X86_VENDOR_Intel) { 10295269Skk208521 if (cp->cp_ecx & CPUID_INTC_ECX_SSSE3) 10305269Skk208521 feature |= X86_SSSE3; 10315269Skk208521 if (cp->cp_ecx & CPUID_INTC_ECX_SSE4_1) 10325269Skk208521 feature |= X86_SSE4_1; 10335269Skk208521 if (cp->cp_ecx & CPUID_INTC_ECX_SSE4_2) 10345269Skk208521 feature |= X86_SSE4_2; 10359370SKuriakose.Kuruvilla@Sun.COM if (cp->cp_ecx & CPUID_INTC_ECX_AES) 10369370SKuriakose.Kuruvilla@Sun.COM feature |= X86_AES; 10375269Skk208521 } 10380Sstevel@tonic-gate } 10390Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_DE) 10403446Smrj feature |= X86_DE; 10417716SBill.Holler@Sun.COM #if !defined(__xpv) 10424481Sbholler if (cp->cp_ecx & CPUID_INTC_ECX_MON) { 10437716SBill.Holler@Sun.COM 10447716SBill.Holler@Sun.COM /* 10457716SBill.Holler@Sun.COM * We require the CLFLUSH instruction for erratum workaround 10467716SBill.Holler@Sun.COM * to use MONITOR/MWAIT. 10477716SBill.Holler@Sun.COM */ 10487716SBill.Holler@Sun.COM if (cp->cp_edx & CPUID_INTC_EDX_CLFSH) { 10497716SBill.Holler@Sun.COM cpi->cpi_mwait.support |= MWAIT_SUPPORT; 10507716SBill.Holler@Sun.COM feature |= X86_MWAIT; 10517716SBill.Holler@Sun.COM } else { 10527716SBill.Holler@Sun.COM extern int idle_cpu_assert_cflush_monitor; 10537716SBill.Holler@Sun.COM 10547716SBill.Holler@Sun.COM /* 10557716SBill.Holler@Sun.COM * All processors we are aware of which have 10567716SBill.Holler@Sun.COM * MONITOR/MWAIT also have CLFLUSH. 10577716SBill.Holler@Sun.COM */ 10587716SBill.Holler@Sun.COM if (idle_cpu_assert_cflush_monitor) { 10597716SBill.Holler@Sun.COM ASSERT((cp->cp_ecx & CPUID_INTC_ECX_MON) && 10607716SBill.Holler@Sun.COM (cp->cp_edx & CPUID_INTC_EDX_CLFSH)); 10617716SBill.Holler@Sun.COM } 10627716SBill.Holler@Sun.COM } 10634481Sbholler } 10647716SBill.Holler@Sun.COM #endif /* __xpv */ 10650Sstevel@tonic-gate 10667589SVikram.Hegde@Sun.COM /* 10677589SVikram.Hegde@Sun.COM * Only need it first time, rest of the cpus would follow suite. 10687589SVikram.Hegde@Sun.COM * we only capture this for the bootcpu. 10697589SVikram.Hegde@Sun.COM */ 10707589SVikram.Hegde@Sun.COM if (cp->cp_edx & CPUID_INTC_EDX_CLFSH) { 10717589SVikram.Hegde@Sun.COM feature |= X86_CLFSH; 10727589SVikram.Hegde@Sun.COM x86_clflush_size = (BITX(cp->cp_ebx, 15, 8) * 8); 10737589SVikram.Hegde@Sun.COM } 10747589SVikram.Hegde@Sun.COM 10750Sstevel@tonic-gate if (feature & X86_PAE) 10760Sstevel@tonic-gate cpi->cpi_pabits = 36; 10770Sstevel@tonic-gate 10780Sstevel@tonic-gate /* 10790Sstevel@tonic-gate * Hyperthreading configuration is slightly tricky on Intel 10800Sstevel@tonic-gate * and pure clones, and even trickier on AMD. 10810Sstevel@tonic-gate * 10820Sstevel@tonic-gate * (AMD chose to set the HTT bit on their CMP processors, 10830Sstevel@tonic-gate * even though they're not actually hyperthreaded. Thus it 10840Sstevel@tonic-gate * takes a bit more work to figure out what's really going 10853446Smrj * on ... see the handling of the CMP_LGCY bit below) 10860Sstevel@tonic-gate */ 10870Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_HTT) { 10880Sstevel@tonic-gate cpi->cpi_ncpu_per_chip = CPI_CPU_COUNT(cpi); 10890Sstevel@tonic-gate if (cpi->cpi_ncpu_per_chip > 1) 10900Sstevel@tonic-gate feature |= X86_HTT; 10911228Sandrei } else { 10921228Sandrei cpi->cpi_ncpu_per_chip = 1; 10930Sstevel@tonic-gate } 10940Sstevel@tonic-gate 10950Sstevel@tonic-gate /* 10960Sstevel@tonic-gate * Work on the "extended" feature information, doing 10970Sstevel@tonic-gate * some basic initialization for cpuid_pass2() 10980Sstevel@tonic-gate */ 10990Sstevel@tonic-gate xcpuid = 0; 11000Sstevel@tonic-gate switch (cpi->cpi_vendor) { 11010Sstevel@tonic-gate case X86_VENDOR_Intel: 11021975Sdmick if (IS_NEW_F6(cpi) || cpi->cpi_family >= 0xf) 11030Sstevel@tonic-gate xcpuid++; 11040Sstevel@tonic-gate break; 11050Sstevel@tonic-gate case X86_VENDOR_AMD: 11060Sstevel@tonic-gate if (cpi->cpi_family > 5 || 11070Sstevel@tonic-gate (cpi->cpi_family == 5 && cpi->cpi_model >= 1)) 11080Sstevel@tonic-gate xcpuid++; 11090Sstevel@tonic-gate break; 11100Sstevel@tonic-gate case X86_VENDOR_Cyrix: 11110Sstevel@tonic-gate /* 11120Sstevel@tonic-gate * Only these Cyrix CPUs are -known- to support 11130Sstevel@tonic-gate * extended cpuid operations. 11140Sstevel@tonic-gate */ 11150Sstevel@tonic-gate if (x86_type == X86_TYPE_VIA_CYRIX_III || 11160Sstevel@tonic-gate x86_type == X86_TYPE_CYRIX_GXm) 11170Sstevel@tonic-gate xcpuid++; 11180Sstevel@tonic-gate break; 11190Sstevel@tonic-gate case X86_VENDOR_Centaur: 11200Sstevel@tonic-gate case X86_VENDOR_TM: 11210Sstevel@tonic-gate default: 11220Sstevel@tonic-gate xcpuid++; 11230Sstevel@tonic-gate break; 11240Sstevel@tonic-gate } 11250Sstevel@tonic-gate 11260Sstevel@tonic-gate if (xcpuid) { 11270Sstevel@tonic-gate cp = &cpi->cpi_extd[0]; 11281228Sandrei cp->cp_eax = 0x80000000; 11291228Sandrei cpi->cpi_xmaxeax = __cpuid_insn(cp); 11300Sstevel@tonic-gate } 11310Sstevel@tonic-gate 11320Sstevel@tonic-gate if (cpi->cpi_xmaxeax & 0x80000000) { 11330Sstevel@tonic-gate 11340Sstevel@tonic-gate if (cpi->cpi_xmaxeax > CPI_XMAXEAX_MAX) 11350Sstevel@tonic-gate cpi->cpi_xmaxeax = CPI_XMAXEAX_MAX; 11360Sstevel@tonic-gate 11370Sstevel@tonic-gate switch (cpi->cpi_vendor) { 11380Sstevel@tonic-gate case X86_VENDOR_Intel: 11390Sstevel@tonic-gate case X86_VENDOR_AMD: 11400Sstevel@tonic-gate if (cpi->cpi_xmaxeax < 0x80000001) 11410Sstevel@tonic-gate break; 11420Sstevel@tonic-gate cp = &cpi->cpi_extd[1]; 11431228Sandrei cp->cp_eax = 0x80000001; 11441228Sandrei (void) __cpuid_insn(cp); 11453446Smrj 11460Sstevel@tonic-gate if (cpi->cpi_vendor == X86_VENDOR_AMD && 11470Sstevel@tonic-gate cpi->cpi_family == 5 && 11480Sstevel@tonic-gate cpi->cpi_model == 6 && 11490Sstevel@tonic-gate cpi->cpi_step == 6) { 11500Sstevel@tonic-gate /* 11510Sstevel@tonic-gate * K6 model 6 uses bit 10 to indicate SYSC 11520Sstevel@tonic-gate * Later models use bit 11. Fix it here. 11530Sstevel@tonic-gate */ 11540Sstevel@tonic-gate if (cp->cp_edx & 0x400) { 11550Sstevel@tonic-gate cp->cp_edx &= ~0x400; 11560Sstevel@tonic-gate cp->cp_edx |= CPUID_AMD_EDX_SYSC; 11570Sstevel@tonic-gate } 11580Sstevel@tonic-gate } 11590Sstevel@tonic-gate 11603446Smrj platform_cpuid_mangle(cpi->cpi_vendor, 0x80000001, cp); 11613446Smrj 11620Sstevel@tonic-gate /* 11630Sstevel@tonic-gate * Compute the additions to the kernel's feature word. 11640Sstevel@tonic-gate */ 11650Sstevel@tonic-gate if (cp->cp_edx & CPUID_AMD_EDX_NX) 11660Sstevel@tonic-gate feature |= X86_NX; 11670Sstevel@tonic-gate 11687656SSherry.Moore@Sun.COM /* 11697656SSherry.Moore@Sun.COM * Regardless whether or not we boot 64-bit, 11707656SSherry.Moore@Sun.COM * we should have a way to identify whether 11717656SSherry.Moore@Sun.COM * the CPU is capable of running 64-bit. 11727656SSherry.Moore@Sun.COM */ 11737656SSherry.Moore@Sun.COM if (cp->cp_edx & CPUID_AMD_EDX_LM) 11747656SSherry.Moore@Sun.COM feature |= X86_64; 11757656SSherry.Moore@Sun.COM 11765349Skchow #if defined(__amd64) 11775349Skchow /* 1 GB large page - enable only for 64 bit kernel */ 11785349Skchow if (cp->cp_edx & CPUID_AMD_EDX_1GPG) 11795349Skchow feature |= X86_1GPG; 11805349Skchow #endif 11815349Skchow 11824628Skk208521 if ((cpi->cpi_vendor == X86_VENDOR_AMD) && 11834628Skk208521 (cpi->cpi_std[1].cp_edx & CPUID_INTC_EDX_FXSR) && 11844628Skk208521 (cp->cp_ecx & CPUID_AMD_ECX_SSE4A)) 11854628Skk208521 feature |= X86_SSE4A; 11864628Skk208521 11870Sstevel@tonic-gate /* 11883446Smrj * If both the HTT and CMP_LGCY bits are set, 11891228Sandrei * then we're not actually HyperThreaded. Read 11901228Sandrei * "AMD CPUID Specification" for more details. 11910Sstevel@tonic-gate */ 11920Sstevel@tonic-gate if (cpi->cpi_vendor == X86_VENDOR_AMD && 11931228Sandrei (feature & X86_HTT) && 11943446Smrj (cp->cp_ecx & CPUID_AMD_ECX_CMP_LGCY)) { 11950Sstevel@tonic-gate feature &= ~X86_HTT; 11961228Sandrei feature |= X86_CMP; 11971228Sandrei } 11983446Smrj #if defined(__amd64) 11990Sstevel@tonic-gate /* 12000Sstevel@tonic-gate * It's really tricky to support syscall/sysret in 12010Sstevel@tonic-gate * the i386 kernel; we rely on sysenter/sysexit 12020Sstevel@tonic-gate * instead. In the amd64 kernel, things are -way- 12030Sstevel@tonic-gate * better. 12040Sstevel@tonic-gate */ 12050Sstevel@tonic-gate if (cp->cp_edx & CPUID_AMD_EDX_SYSC) 12060Sstevel@tonic-gate feature |= X86_ASYSC; 12070Sstevel@tonic-gate 12080Sstevel@tonic-gate /* 12090Sstevel@tonic-gate * While we're thinking about system calls, note 12100Sstevel@tonic-gate * that AMD processors don't support sysenter 12110Sstevel@tonic-gate * in long mode at all, so don't try to program them. 12120Sstevel@tonic-gate */ 12130Sstevel@tonic-gate if (x86_vendor == X86_VENDOR_AMD) 12140Sstevel@tonic-gate feature &= ~X86_SEP; 12150Sstevel@tonic-gate #endif 12166657Ssudheer if (cp->cp_edx & CPUID_AMD_EDX_TSCP) 12173446Smrj feature |= X86_TSCP; 12180Sstevel@tonic-gate break; 12190Sstevel@tonic-gate default: 12200Sstevel@tonic-gate break; 12210Sstevel@tonic-gate } 12220Sstevel@tonic-gate 12231228Sandrei /* 12241228Sandrei * Get CPUID data about processor cores and hyperthreads. 12251228Sandrei */ 12260Sstevel@tonic-gate switch (cpi->cpi_vendor) { 12270Sstevel@tonic-gate case X86_VENDOR_Intel: 12281228Sandrei if (cpi->cpi_maxeax >= 4) { 12291228Sandrei cp = &cpi->cpi_std[4]; 12301228Sandrei cp->cp_eax = 4; 12311228Sandrei cp->cp_ecx = 0; 12321228Sandrei (void) __cpuid_insn(cp); 12333446Smrj platform_cpuid_mangle(cpi->cpi_vendor, 4, cp); 12341228Sandrei } 12351228Sandrei /*FALLTHROUGH*/ 12360Sstevel@tonic-gate case X86_VENDOR_AMD: 12370Sstevel@tonic-gate if (cpi->cpi_xmaxeax < 0x80000008) 12380Sstevel@tonic-gate break; 12390Sstevel@tonic-gate cp = &cpi->cpi_extd[8]; 12401228Sandrei cp->cp_eax = 0x80000008; 12411228Sandrei (void) __cpuid_insn(cp); 12423446Smrj platform_cpuid_mangle(cpi->cpi_vendor, 0x80000008, cp); 12433446Smrj 12440Sstevel@tonic-gate /* 12450Sstevel@tonic-gate * Virtual and physical address limits from 12460Sstevel@tonic-gate * cpuid override previously guessed values. 12470Sstevel@tonic-gate */ 12480Sstevel@tonic-gate cpi->cpi_pabits = BITX(cp->cp_eax, 7, 0); 12490Sstevel@tonic-gate cpi->cpi_vabits = BITX(cp->cp_eax, 15, 8); 12500Sstevel@tonic-gate break; 12510Sstevel@tonic-gate default: 12520Sstevel@tonic-gate break; 12530Sstevel@tonic-gate } 12541228Sandrei 12554606Sesaxe /* 12564606Sesaxe * Derive the number of cores per chip 12574606Sesaxe */ 12581228Sandrei switch (cpi->cpi_vendor) { 12591228Sandrei case X86_VENDOR_Intel: 12601228Sandrei if (cpi->cpi_maxeax < 4) { 12611228Sandrei cpi->cpi_ncore_per_chip = 1; 12621228Sandrei break; 12631228Sandrei } else { 12641228Sandrei cpi->cpi_ncore_per_chip = 12651228Sandrei BITX((cpi)->cpi_std[4].cp_eax, 31, 26) + 1; 12661228Sandrei } 12671228Sandrei break; 12681228Sandrei case X86_VENDOR_AMD: 12691228Sandrei if (cpi->cpi_xmaxeax < 0x80000008) { 12701228Sandrei cpi->cpi_ncore_per_chip = 1; 12711228Sandrei break; 12721228Sandrei } else { 12735870Sgavinm /* 12745870Sgavinm * On family 0xf cpuid fn 2 ECX[7:0] "NC" is 12755870Sgavinm * 1 less than the number of physical cores on 12765870Sgavinm * the chip. In family 0x10 this value can 12775870Sgavinm * be affected by "downcoring" - it reflects 12785870Sgavinm * 1 less than the number of cores actually 12795870Sgavinm * enabled on this node. 12805870Sgavinm */ 12811228Sandrei cpi->cpi_ncore_per_chip = 12821228Sandrei BITX((cpi)->cpi_extd[8].cp_ecx, 7, 0) + 1; 12831228Sandrei } 12841228Sandrei break; 12851228Sandrei default: 12861228Sandrei cpi->cpi_ncore_per_chip = 1; 12871228Sandrei break; 12881228Sandrei } 12898906SEric.Saxe@Sun.COM 12908906SEric.Saxe@Sun.COM /* 12918906SEric.Saxe@Sun.COM * Get CPUID data about TSC Invariance in Deep C-State. 12928906SEric.Saxe@Sun.COM */ 12938906SEric.Saxe@Sun.COM switch (cpi->cpi_vendor) { 12948906SEric.Saxe@Sun.COM case X86_VENDOR_Intel: 12958906SEric.Saxe@Sun.COM if (cpi->cpi_maxeax >= 7) { 12968906SEric.Saxe@Sun.COM cp = &cpi->cpi_extd[7]; 12978906SEric.Saxe@Sun.COM cp->cp_eax = 0x80000007; 12988906SEric.Saxe@Sun.COM cp->cp_ecx = 0; 12998906SEric.Saxe@Sun.COM (void) __cpuid_insn(cp); 13008906SEric.Saxe@Sun.COM } 13018906SEric.Saxe@Sun.COM break; 13028906SEric.Saxe@Sun.COM default: 13038906SEric.Saxe@Sun.COM break; 13048906SEric.Saxe@Sun.COM } 13055284Sgavinm } else { 13065284Sgavinm cpi->cpi_ncore_per_chip = 1; 13070Sstevel@tonic-gate } 13080Sstevel@tonic-gate 13091228Sandrei /* 13101228Sandrei * If more than one core, then this processor is CMP. 13111228Sandrei */ 13121228Sandrei if (cpi->cpi_ncore_per_chip > 1) 13131228Sandrei feature |= X86_CMP; 13143446Smrj 13151228Sandrei /* 13161228Sandrei * If the number of cores is the same as the number 13171228Sandrei * of CPUs, then we cannot have HyperThreading. 13181228Sandrei */ 13191228Sandrei if (cpi->cpi_ncpu_per_chip == cpi->cpi_ncore_per_chip) 13201228Sandrei feature &= ~X86_HTT; 13211228Sandrei 1322*10947SSrihari.Venkatesan@Sun.COM cpi->cpi_apicid = CPI_APIC_ID(cpi); 1323*10947SSrihari.Venkatesan@Sun.COM cpi->cpi_procnodes_per_pkg = 1; 1324*10947SSrihari.Venkatesan@Sun.COM 13250Sstevel@tonic-gate if ((feature & (X86_HTT | X86_CMP)) == 0) { 13261228Sandrei /* 13271228Sandrei * Single-core single-threaded processors. 13281228Sandrei */ 13290Sstevel@tonic-gate cpi->cpi_chipid = -1; 13300Sstevel@tonic-gate cpi->cpi_clogid = 0; 13311228Sandrei cpi->cpi_coreid = cpu->cpu_id; 13325870Sgavinm cpi->cpi_pkgcoreid = 0; 1333*10947SSrihari.Venkatesan@Sun.COM if (cpi->cpi_vendor == X86_VENDOR_AMD) 1334*10947SSrihari.Venkatesan@Sun.COM cpi->cpi_procnodeid = BITX(cpi->cpi_apicid, 3, 0); 1335*10947SSrihari.Venkatesan@Sun.COM else 1336*10947SSrihari.Venkatesan@Sun.COM cpi->cpi_procnodeid = cpi->cpi_chipid; 13370Sstevel@tonic-gate } else if (cpi->cpi_ncpu_per_chip > 1) { 1338*10947SSrihari.Venkatesan@Sun.COM if (cpi->cpi_vendor == X86_VENDOR_Intel) 1339*10947SSrihari.Venkatesan@Sun.COM cpuid_intel_getids(cpu, feature); 1340*10947SSrihari.Venkatesan@Sun.COM else if (cpi->cpi_vendor == X86_VENDOR_AMD) 1341*10947SSrihari.Venkatesan@Sun.COM cpuid_amd_getids(cpu); 1342*10947SSrihari.Venkatesan@Sun.COM else { 13431228Sandrei /* 13441228Sandrei * All other processors are currently 13451228Sandrei * assumed to have single cores. 13461228Sandrei */ 13471228Sandrei cpi->cpi_coreid = cpi->cpi_chipid; 13485870Sgavinm cpi->cpi_pkgcoreid = 0; 1349*10947SSrihari.Venkatesan@Sun.COM cpi->cpi_procnodeid = cpi->cpi_chipid; 13501228Sandrei } 13510Sstevel@tonic-gate } 13520Sstevel@tonic-gate 13532869Sgavinm /* 13542869Sgavinm * Synthesize chip "revision" and socket type 13552869Sgavinm */ 13567532SSean.Ye@Sun.COM cpi->cpi_chiprev = _cpuid_chiprev(cpi->cpi_vendor, cpi->cpi_family, 13577532SSean.Ye@Sun.COM cpi->cpi_model, cpi->cpi_step); 13587532SSean.Ye@Sun.COM cpi->cpi_chiprevstr = _cpuid_chiprevstr(cpi->cpi_vendor, 13597532SSean.Ye@Sun.COM cpi->cpi_family, cpi->cpi_model, cpi->cpi_step); 13607532SSean.Ye@Sun.COM cpi->cpi_socket = _cpuid_skt(cpi->cpi_vendor, cpi->cpi_family, 13617532SSean.Ye@Sun.COM cpi->cpi_model, cpi->cpi_step); 13622869Sgavinm 13630Sstevel@tonic-gate pass1_done: 13640Sstevel@tonic-gate cpi->cpi_pass = 1; 13650Sstevel@tonic-gate return (feature); 13660Sstevel@tonic-gate } 13670Sstevel@tonic-gate 13680Sstevel@tonic-gate /* 13690Sstevel@tonic-gate * Make copies of the cpuid table entries we depend on, in 13700Sstevel@tonic-gate * part for ease of parsing now, in part so that we have only 13710Sstevel@tonic-gate * one place to correct any of it, in part for ease of 13720Sstevel@tonic-gate * later export to userland, and in part so we can look at 13730Sstevel@tonic-gate * this stuff in a crash dump. 13740Sstevel@tonic-gate */ 13750Sstevel@tonic-gate 13760Sstevel@tonic-gate /*ARGSUSED*/ 13770Sstevel@tonic-gate void 13780Sstevel@tonic-gate cpuid_pass2(cpu_t *cpu) 13790Sstevel@tonic-gate { 13800Sstevel@tonic-gate uint_t n, nmax; 13810Sstevel@tonic-gate int i; 13821228Sandrei struct cpuid_regs *cp; 13830Sstevel@tonic-gate uint8_t *dp; 13840Sstevel@tonic-gate uint32_t *iptr; 13850Sstevel@tonic-gate struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 13860Sstevel@tonic-gate 13870Sstevel@tonic-gate ASSERT(cpi->cpi_pass == 1); 13880Sstevel@tonic-gate 13890Sstevel@tonic-gate if (cpi->cpi_maxeax < 1) 13900Sstevel@tonic-gate goto pass2_done; 13910Sstevel@tonic-gate 13920Sstevel@tonic-gate if ((nmax = cpi->cpi_maxeax + 1) > NMAX_CPI_STD) 13930Sstevel@tonic-gate nmax = NMAX_CPI_STD; 13940Sstevel@tonic-gate /* 13950Sstevel@tonic-gate * (We already handled n == 0 and n == 1 in pass 1) 13960Sstevel@tonic-gate */ 13970Sstevel@tonic-gate for (n = 2, cp = &cpi->cpi_std[2]; n < nmax; n++, cp++) { 13981228Sandrei cp->cp_eax = n; 13994606Sesaxe 14004606Sesaxe /* 14014606Sesaxe * CPUID function 4 expects %ecx to be initialized 14024606Sesaxe * with an index which indicates which cache to return 14034606Sesaxe * information about. The OS is expected to call function 4 14044606Sesaxe * with %ecx set to 0, 1, 2, ... until it returns with 14054606Sesaxe * EAX[4:0] set to 0, which indicates there are no more 14064606Sesaxe * caches. 14074606Sesaxe * 14084606Sesaxe * Here, populate cpi_std[4] with the information returned by 14094606Sesaxe * function 4 when %ecx == 0, and do the rest in cpuid_pass3() 14104606Sesaxe * when dynamic memory allocation becomes available. 14114606Sesaxe * 14124606Sesaxe * Note: we need to explicitly initialize %ecx here, since 14134606Sesaxe * function 4 may have been previously invoked. 14144606Sesaxe */ 14154606Sesaxe if (n == 4) 14164606Sesaxe cp->cp_ecx = 0; 14174606Sesaxe 14181228Sandrei (void) __cpuid_insn(cp); 14193446Smrj platform_cpuid_mangle(cpi->cpi_vendor, n, cp); 14200Sstevel@tonic-gate switch (n) { 14210Sstevel@tonic-gate case 2: 14220Sstevel@tonic-gate /* 14230Sstevel@tonic-gate * "the lower 8 bits of the %eax register 14240Sstevel@tonic-gate * contain a value that identifies the number 14250Sstevel@tonic-gate * of times the cpuid [instruction] has to be 14260Sstevel@tonic-gate * executed to obtain a complete image of the 14270Sstevel@tonic-gate * processor's caching systems." 14280Sstevel@tonic-gate * 14290Sstevel@tonic-gate * How *do* they make this stuff up? 14300Sstevel@tonic-gate */ 14310Sstevel@tonic-gate cpi->cpi_ncache = sizeof (*cp) * 14320Sstevel@tonic-gate BITX(cp->cp_eax, 7, 0); 14330Sstevel@tonic-gate if (cpi->cpi_ncache == 0) 14340Sstevel@tonic-gate break; 14350Sstevel@tonic-gate cpi->cpi_ncache--; /* skip count byte */ 14360Sstevel@tonic-gate 14370Sstevel@tonic-gate /* 14380Sstevel@tonic-gate * Well, for now, rather than attempt to implement 14390Sstevel@tonic-gate * this slightly dubious algorithm, we just look 14400Sstevel@tonic-gate * at the first 15 .. 14410Sstevel@tonic-gate */ 14420Sstevel@tonic-gate if (cpi->cpi_ncache > (sizeof (*cp) - 1)) 14430Sstevel@tonic-gate cpi->cpi_ncache = sizeof (*cp) - 1; 14440Sstevel@tonic-gate 14450Sstevel@tonic-gate dp = cpi->cpi_cacheinfo; 14460Sstevel@tonic-gate if (BITX(cp->cp_eax, 31, 31) == 0) { 14470Sstevel@tonic-gate uint8_t *p = (void *)&cp->cp_eax; 14486317Skk208521 for (i = 1; i < 4; i++) 14490Sstevel@tonic-gate if (p[i] != 0) 14500Sstevel@tonic-gate *dp++ = p[i]; 14510Sstevel@tonic-gate } 14520Sstevel@tonic-gate if (BITX(cp->cp_ebx, 31, 31) == 0) { 14530Sstevel@tonic-gate uint8_t *p = (void *)&cp->cp_ebx; 14540Sstevel@tonic-gate for (i = 0; i < 4; i++) 14550Sstevel@tonic-gate if (p[i] != 0) 14560Sstevel@tonic-gate *dp++ = p[i]; 14570Sstevel@tonic-gate } 14580Sstevel@tonic-gate if (BITX(cp->cp_ecx, 31, 31) == 0) { 14590Sstevel@tonic-gate uint8_t *p = (void *)&cp->cp_ecx; 14600Sstevel@tonic-gate for (i = 0; i < 4; i++) 14610Sstevel@tonic-gate if (p[i] != 0) 14620Sstevel@tonic-gate *dp++ = p[i]; 14630Sstevel@tonic-gate } 14640Sstevel@tonic-gate if (BITX(cp->cp_edx, 31, 31) == 0) { 14650Sstevel@tonic-gate uint8_t *p = (void *)&cp->cp_edx; 14660Sstevel@tonic-gate for (i = 0; i < 4; i++) 14670Sstevel@tonic-gate if (p[i] != 0) 14680Sstevel@tonic-gate *dp++ = p[i]; 14690Sstevel@tonic-gate } 14700Sstevel@tonic-gate break; 14714481Sbholler 14720Sstevel@tonic-gate case 3: /* Processor serial number, if PSN supported */ 14734481Sbholler break; 14744481Sbholler 14750Sstevel@tonic-gate case 4: /* Deterministic cache parameters */ 14764481Sbholler break; 14774481Sbholler 14780Sstevel@tonic-gate case 5: /* Monitor/Mwait parameters */ 14795045Sbholler { 14805045Sbholler size_t mwait_size; 14814481Sbholler 14824481Sbholler /* 14834481Sbholler * check cpi_mwait.support which was set in cpuid_pass1 14844481Sbholler */ 14854481Sbholler if (!(cpi->cpi_mwait.support & MWAIT_SUPPORT)) 14864481Sbholler break; 14874481Sbholler 14885045Sbholler /* 14895045Sbholler * Protect ourself from insane mwait line size. 14905045Sbholler * Workaround for incomplete hardware emulator(s). 14915045Sbholler */ 14925045Sbholler mwait_size = (size_t)MWAIT_SIZE_MAX(cpi); 14935045Sbholler if (mwait_size < sizeof (uint32_t) || 14945045Sbholler !ISP2(mwait_size)) { 14955045Sbholler #if DEBUG 14965045Sbholler cmn_err(CE_NOTE, "Cannot handle cpu %d mwait " 14977798SSaurabh.Mishra@Sun.COM "size %ld", cpu->cpu_id, (long)mwait_size); 14985045Sbholler #endif 14995045Sbholler break; 15005045Sbholler } 15015045Sbholler 15024481Sbholler cpi->cpi_mwait.mon_min = (size_t)MWAIT_SIZE_MIN(cpi); 15035045Sbholler cpi->cpi_mwait.mon_max = mwait_size; 15044481Sbholler if (MWAIT_EXTENSION(cpi)) { 15054481Sbholler cpi->cpi_mwait.support |= MWAIT_EXTENSIONS; 15064481Sbholler if (MWAIT_INT_ENABLE(cpi)) 15074481Sbholler cpi->cpi_mwait.support |= 15084481Sbholler MWAIT_ECX_INT_ENABLE; 15094481Sbholler } 15104481Sbholler break; 15115045Sbholler } 15120Sstevel@tonic-gate default: 15130Sstevel@tonic-gate break; 15140Sstevel@tonic-gate } 15150Sstevel@tonic-gate } 15160Sstevel@tonic-gate 15177282Smishra if (cpi->cpi_maxeax >= 0xB && cpi->cpi_vendor == X86_VENDOR_Intel) { 15187798SSaurabh.Mishra@Sun.COM struct cpuid_regs regs; 15197798SSaurabh.Mishra@Sun.COM 15207798SSaurabh.Mishra@Sun.COM cp = ®s; 15217282Smishra cp->cp_eax = 0xB; 15227798SSaurabh.Mishra@Sun.COM cp->cp_edx = cp->cp_ebx = cp->cp_ecx = 0; 15237282Smishra 15247282Smishra (void) __cpuid_insn(cp); 15257282Smishra 15267282Smishra /* 15277282Smishra * Check CPUID.EAX=0BH, ECX=0H:EBX is non-zero, which 15287282Smishra * indicates that the extended topology enumeration leaf is 15297282Smishra * available. 15307282Smishra */ 15317282Smishra if (cp->cp_ebx) { 15327282Smishra uint32_t x2apic_id; 15337282Smishra uint_t coreid_shift = 0; 15347282Smishra uint_t ncpu_per_core = 1; 15357282Smishra uint_t chipid_shift = 0; 15367282Smishra uint_t ncpu_per_chip = 1; 15377282Smishra uint_t i; 15387282Smishra uint_t level; 15397282Smishra 15407282Smishra for (i = 0; i < CPI_FNB_ECX_MAX; i++) { 15417282Smishra cp->cp_eax = 0xB; 15427282Smishra cp->cp_ecx = i; 15437282Smishra 15447282Smishra (void) __cpuid_insn(cp); 15457282Smishra level = CPI_CPU_LEVEL_TYPE(cp); 15467282Smishra 15477282Smishra if (level == 1) { 15487282Smishra x2apic_id = cp->cp_edx; 15497282Smishra coreid_shift = BITX(cp->cp_eax, 4, 0); 15507282Smishra ncpu_per_core = BITX(cp->cp_ebx, 15, 0); 15517282Smishra } else if (level == 2) { 15527282Smishra x2apic_id = cp->cp_edx; 15537282Smishra chipid_shift = BITX(cp->cp_eax, 4, 0); 15547282Smishra ncpu_per_chip = BITX(cp->cp_ebx, 15, 0); 15557282Smishra } 15567282Smishra } 15577282Smishra 15587282Smishra cpi->cpi_apicid = x2apic_id; 15597282Smishra cpi->cpi_ncpu_per_chip = ncpu_per_chip; 15607282Smishra cpi->cpi_ncore_per_chip = ncpu_per_chip / 15617282Smishra ncpu_per_core; 15627282Smishra cpi->cpi_chipid = x2apic_id >> chipid_shift; 15637282Smishra cpi->cpi_clogid = x2apic_id & ((1 << chipid_shift) - 1); 15647282Smishra cpi->cpi_coreid = x2apic_id >> coreid_shift; 15657282Smishra cpi->cpi_pkgcoreid = cpi->cpi_clogid >> coreid_shift; 15667282Smishra } 15677798SSaurabh.Mishra@Sun.COM 15687798SSaurabh.Mishra@Sun.COM /* Make cp NULL so that we don't stumble on others */ 15697798SSaurabh.Mishra@Sun.COM cp = NULL; 15707282Smishra } 15717282Smishra 15720Sstevel@tonic-gate if ((cpi->cpi_xmaxeax & 0x80000000) == 0) 15730Sstevel@tonic-gate goto pass2_done; 15740Sstevel@tonic-gate 15750Sstevel@tonic-gate if ((nmax = cpi->cpi_xmaxeax - 0x80000000 + 1) > NMAX_CPI_EXTD) 15760Sstevel@tonic-gate nmax = NMAX_CPI_EXTD; 15770Sstevel@tonic-gate /* 15780Sstevel@tonic-gate * Copy the extended properties, fixing them as we go. 15790Sstevel@tonic-gate * (We already handled n == 0 and n == 1 in pass 1) 15800Sstevel@tonic-gate */ 15810Sstevel@tonic-gate iptr = (void *)cpi->cpi_brandstr; 15820Sstevel@tonic-gate for (n = 2, cp = &cpi->cpi_extd[2]; n < nmax; cp++, n++) { 15831228Sandrei cp->cp_eax = 0x80000000 + n; 15841228Sandrei (void) __cpuid_insn(cp); 15853446Smrj platform_cpuid_mangle(cpi->cpi_vendor, 0x80000000 + n, cp); 15860Sstevel@tonic-gate switch (n) { 15870Sstevel@tonic-gate case 2: 15880Sstevel@tonic-gate case 3: 15890Sstevel@tonic-gate case 4: 15900Sstevel@tonic-gate /* 15910Sstevel@tonic-gate * Extract the brand string 15920Sstevel@tonic-gate */ 15930Sstevel@tonic-gate *iptr++ = cp->cp_eax; 15940Sstevel@tonic-gate *iptr++ = cp->cp_ebx; 15950Sstevel@tonic-gate *iptr++ = cp->cp_ecx; 15960Sstevel@tonic-gate *iptr++ = cp->cp_edx; 15970Sstevel@tonic-gate break; 15980Sstevel@tonic-gate case 5: 15990Sstevel@tonic-gate switch (cpi->cpi_vendor) { 16000Sstevel@tonic-gate case X86_VENDOR_AMD: 16010Sstevel@tonic-gate /* 16020Sstevel@tonic-gate * The Athlon and Duron were the first 16030Sstevel@tonic-gate * parts to report the sizes of the 16040Sstevel@tonic-gate * TLB for large pages. Before then, 16050Sstevel@tonic-gate * we don't trust the data. 16060Sstevel@tonic-gate */ 16070Sstevel@tonic-gate if (cpi->cpi_family < 6 || 16080Sstevel@tonic-gate (cpi->cpi_family == 6 && 16090Sstevel@tonic-gate cpi->cpi_model < 1)) 16100Sstevel@tonic-gate cp->cp_eax = 0; 16110Sstevel@tonic-gate break; 16120Sstevel@tonic-gate default: 16130Sstevel@tonic-gate break; 16140Sstevel@tonic-gate } 16150Sstevel@tonic-gate break; 16160Sstevel@tonic-gate case 6: 16170Sstevel@tonic-gate switch (cpi->cpi_vendor) { 16180Sstevel@tonic-gate case X86_VENDOR_AMD: 16190Sstevel@tonic-gate /* 16200Sstevel@tonic-gate * The Athlon and Duron were the first 16210Sstevel@tonic-gate * AMD parts with L2 TLB's. 16220Sstevel@tonic-gate * Before then, don't trust the data. 16230Sstevel@tonic-gate */ 16240Sstevel@tonic-gate if (cpi->cpi_family < 6 || 16250Sstevel@tonic-gate cpi->cpi_family == 6 && 16260Sstevel@tonic-gate cpi->cpi_model < 1) 16270Sstevel@tonic-gate cp->cp_eax = cp->cp_ebx = 0; 16280Sstevel@tonic-gate /* 16290Sstevel@tonic-gate * AMD Duron rev A0 reports L2 16300Sstevel@tonic-gate * cache size incorrectly as 1K 16310Sstevel@tonic-gate * when it is really 64K 16320Sstevel@tonic-gate */ 16330Sstevel@tonic-gate if (cpi->cpi_family == 6 && 16340Sstevel@tonic-gate cpi->cpi_model == 3 && 16350Sstevel@tonic-gate cpi->cpi_step == 0) { 16360Sstevel@tonic-gate cp->cp_ecx &= 0xffff; 16370Sstevel@tonic-gate cp->cp_ecx |= 0x400000; 16380Sstevel@tonic-gate } 16390Sstevel@tonic-gate break; 16400Sstevel@tonic-gate case X86_VENDOR_Cyrix: /* VIA C3 */ 16410Sstevel@tonic-gate /* 16420Sstevel@tonic-gate * VIA C3 processors are a bit messed 16430Sstevel@tonic-gate * up w.r.t. encoding cache sizes in %ecx 16440Sstevel@tonic-gate */ 16450Sstevel@tonic-gate if (cpi->cpi_family != 6) 16460Sstevel@tonic-gate break; 16470Sstevel@tonic-gate /* 16480Sstevel@tonic-gate * model 7 and 8 were incorrectly encoded 16490Sstevel@tonic-gate * 16500Sstevel@tonic-gate * xxx is model 8 really broken? 16510Sstevel@tonic-gate */ 16520Sstevel@tonic-gate if (cpi->cpi_model == 7 || 16530Sstevel@tonic-gate cpi->cpi_model == 8) 16540Sstevel@tonic-gate cp->cp_ecx = 16550Sstevel@tonic-gate BITX(cp->cp_ecx, 31, 24) << 16 | 16560Sstevel@tonic-gate BITX(cp->cp_ecx, 23, 16) << 12 | 16570Sstevel@tonic-gate BITX(cp->cp_ecx, 15, 8) << 8 | 16580Sstevel@tonic-gate BITX(cp->cp_ecx, 7, 0); 16590Sstevel@tonic-gate /* 16600Sstevel@tonic-gate * model 9 stepping 1 has wrong associativity 16610Sstevel@tonic-gate */ 16620Sstevel@tonic-gate if (cpi->cpi_model == 9 && cpi->cpi_step == 1) 16630Sstevel@tonic-gate cp->cp_ecx |= 8 << 12; 16640Sstevel@tonic-gate break; 16650Sstevel@tonic-gate case X86_VENDOR_Intel: 16660Sstevel@tonic-gate /* 16670Sstevel@tonic-gate * Extended L2 Cache features function. 16680Sstevel@tonic-gate * First appeared on Prescott. 16690Sstevel@tonic-gate */ 16700Sstevel@tonic-gate default: 16710Sstevel@tonic-gate break; 16720Sstevel@tonic-gate } 16730Sstevel@tonic-gate break; 16740Sstevel@tonic-gate default: 16750Sstevel@tonic-gate break; 16760Sstevel@tonic-gate } 16770Sstevel@tonic-gate } 16780Sstevel@tonic-gate 16790Sstevel@tonic-gate pass2_done: 16800Sstevel@tonic-gate cpi->cpi_pass = 2; 16810Sstevel@tonic-gate } 16820Sstevel@tonic-gate 16830Sstevel@tonic-gate static const char * 16840Sstevel@tonic-gate intel_cpubrand(const struct cpuid_info *cpi) 16850Sstevel@tonic-gate { 16860Sstevel@tonic-gate int i; 16870Sstevel@tonic-gate 16880Sstevel@tonic-gate if ((x86_feature & X86_CPUID) == 0 || 16890Sstevel@tonic-gate cpi->cpi_maxeax < 1 || cpi->cpi_family < 5) 16900Sstevel@tonic-gate return ("i486"); 16910Sstevel@tonic-gate 16920Sstevel@tonic-gate switch (cpi->cpi_family) { 16930Sstevel@tonic-gate case 5: 16940Sstevel@tonic-gate return ("Intel Pentium(r)"); 16950Sstevel@tonic-gate case 6: 16960Sstevel@tonic-gate switch (cpi->cpi_model) { 16970Sstevel@tonic-gate uint_t celeron, xeon; 16981228Sandrei const struct cpuid_regs *cp; 16990Sstevel@tonic-gate case 0: 17000Sstevel@tonic-gate case 1: 17010Sstevel@tonic-gate case 2: 17020Sstevel@tonic-gate return ("Intel Pentium(r) Pro"); 17030Sstevel@tonic-gate case 3: 17040Sstevel@tonic-gate case 4: 17050Sstevel@tonic-gate return ("Intel Pentium(r) II"); 17060Sstevel@tonic-gate case 6: 17070Sstevel@tonic-gate return ("Intel Celeron(r)"); 17080Sstevel@tonic-gate case 5: 17090Sstevel@tonic-gate case 7: 17100Sstevel@tonic-gate celeron = xeon = 0; 17110Sstevel@tonic-gate cp = &cpi->cpi_std[2]; /* cache info */ 17120Sstevel@tonic-gate 17136317Skk208521 for (i = 1; i < 4; i++) { 17140Sstevel@tonic-gate uint_t tmp; 17150Sstevel@tonic-gate 17160Sstevel@tonic-gate tmp = (cp->cp_eax >> (8 * i)) & 0xff; 17170Sstevel@tonic-gate if (tmp == 0x40) 17180Sstevel@tonic-gate celeron++; 17190Sstevel@tonic-gate if (tmp >= 0x44 && tmp <= 0x45) 17200Sstevel@tonic-gate xeon++; 17210Sstevel@tonic-gate } 17220Sstevel@tonic-gate 17230Sstevel@tonic-gate for (i = 0; i < 2; i++) { 17240Sstevel@tonic-gate uint_t tmp; 17250Sstevel@tonic-gate 17260Sstevel@tonic-gate tmp = (cp->cp_ebx >> (8 * i)) & 0xff; 17270Sstevel@tonic-gate if (tmp == 0x40) 17280Sstevel@tonic-gate celeron++; 17290Sstevel@tonic-gate else if (tmp >= 0x44 && tmp <= 0x45) 17300Sstevel@tonic-gate xeon++; 17310Sstevel@tonic-gate } 17320Sstevel@tonic-gate 17330Sstevel@tonic-gate for (i = 0; i < 4; i++) { 17340Sstevel@tonic-gate uint_t tmp; 17350Sstevel@tonic-gate 17360Sstevel@tonic-gate tmp = (cp->cp_ecx >> (8 * i)) & 0xff; 17370Sstevel@tonic-gate if (tmp == 0x40) 17380Sstevel@tonic-gate celeron++; 17390Sstevel@tonic-gate else if (tmp >= 0x44 && tmp <= 0x45) 17400Sstevel@tonic-gate xeon++; 17410Sstevel@tonic-gate } 17420Sstevel@tonic-gate 17430Sstevel@tonic-gate for (i = 0; i < 4; i++) { 17440Sstevel@tonic-gate uint_t tmp; 17450Sstevel@tonic-gate 17460Sstevel@tonic-gate tmp = (cp->cp_edx >> (8 * i)) & 0xff; 17470Sstevel@tonic-gate if (tmp == 0x40) 17480Sstevel@tonic-gate celeron++; 17490Sstevel@tonic-gate else if (tmp >= 0x44 && tmp <= 0x45) 17500Sstevel@tonic-gate xeon++; 17510Sstevel@tonic-gate } 17520Sstevel@tonic-gate 17530Sstevel@tonic-gate if (celeron) 17540Sstevel@tonic-gate return ("Intel Celeron(r)"); 17550Sstevel@tonic-gate if (xeon) 17560Sstevel@tonic-gate return (cpi->cpi_model == 5 ? 17570Sstevel@tonic-gate "Intel Pentium(r) II Xeon(tm)" : 17580Sstevel@tonic-gate "Intel Pentium(r) III Xeon(tm)"); 17590Sstevel@tonic-gate return (cpi->cpi_model == 5 ? 17600Sstevel@tonic-gate "Intel Pentium(r) II or Pentium(r) II Xeon(tm)" : 17610Sstevel@tonic-gate "Intel Pentium(r) III or Pentium(r) III Xeon(tm)"); 17620Sstevel@tonic-gate default: 17630Sstevel@tonic-gate break; 17640Sstevel@tonic-gate } 17650Sstevel@tonic-gate default: 17660Sstevel@tonic-gate break; 17670Sstevel@tonic-gate } 17680Sstevel@tonic-gate 17691975Sdmick /* BrandID is present if the field is nonzero */ 17701975Sdmick if (cpi->cpi_brandid != 0) { 17710Sstevel@tonic-gate static const struct { 17720Sstevel@tonic-gate uint_t bt_bid; 17730Sstevel@tonic-gate const char *bt_str; 17740Sstevel@tonic-gate } brand_tbl[] = { 17750Sstevel@tonic-gate { 0x1, "Intel(r) Celeron(r)" }, 17760Sstevel@tonic-gate { 0x2, "Intel(r) Pentium(r) III" }, 17770Sstevel@tonic-gate { 0x3, "Intel(r) Pentium(r) III Xeon(tm)" }, 17780Sstevel@tonic-gate { 0x4, "Intel(r) Pentium(r) III" }, 17790Sstevel@tonic-gate { 0x6, "Mobile Intel(r) Pentium(r) III" }, 17800Sstevel@tonic-gate { 0x7, "Mobile Intel(r) Celeron(r)" }, 17810Sstevel@tonic-gate { 0x8, "Intel(r) Pentium(r) 4" }, 17820Sstevel@tonic-gate { 0x9, "Intel(r) Pentium(r) 4" }, 17830Sstevel@tonic-gate { 0xa, "Intel(r) Celeron(r)" }, 17840Sstevel@tonic-gate { 0xb, "Intel(r) Xeon(tm)" }, 17850Sstevel@tonic-gate { 0xc, "Intel(r) Xeon(tm) MP" }, 17860Sstevel@tonic-gate { 0xe, "Mobile Intel(r) Pentium(r) 4" }, 17871975Sdmick { 0xf, "Mobile Intel(r) Celeron(r)" }, 17881975Sdmick { 0x11, "Mobile Genuine Intel(r)" }, 17891975Sdmick { 0x12, "Intel(r) Celeron(r) M" }, 17901975Sdmick { 0x13, "Mobile Intel(r) Celeron(r)" }, 17911975Sdmick { 0x14, "Intel(r) Celeron(r)" }, 17921975Sdmick { 0x15, "Mobile Genuine Intel(r)" }, 17931975Sdmick { 0x16, "Intel(r) Pentium(r) M" }, 17941975Sdmick { 0x17, "Mobile Intel(r) Celeron(r)" } 17950Sstevel@tonic-gate }; 17960Sstevel@tonic-gate uint_t btblmax = sizeof (brand_tbl) / sizeof (brand_tbl[0]); 17970Sstevel@tonic-gate uint_t sgn; 17980Sstevel@tonic-gate 17990Sstevel@tonic-gate sgn = (cpi->cpi_family << 8) | 18000Sstevel@tonic-gate (cpi->cpi_model << 4) | cpi->cpi_step; 18010Sstevel@tonic-gate 18020Sstevel@tonic-gate for (i = 0; i < btblmax; i++) 18030Sstevel@tonic-gate if (brand_tbl[i].bt_bid == cpi->cpi_brandid) 18040Sstevel@tonic-gate break; 18050Sstevel@tonic-gate if (i < btblmax) { 18060Sstevel@tonic-gate if (sgn == 0x6b1 && cpi->cpi_brandid == 3) 18070Sstevel@tonic-gate return ("Intel(r) Celeron(r)"); 18080Sstevel@tonic-gate if (sgn < 0xf13 && cpi->cpi_brandid == 0xb) 18090Sstevel@tonic-gate return ("Intel(r) Xeon(tm) MP"); 18100Sstevel@tonic-gate if (sgn < 0xf13 && cpi->cpi_brandid == 0xe) 18110Sstevel@tonic-gate return ("Intel(r) Xeon(tm)"); 18120Sstevel@tonic-gate return (brand_tbl[i].bt_str); 18130Sstevel@tonic-gate } 18140Sstevel@tonic-gate } 18150Sstevel@tonic-gate 18160Sstevel@tonic-gate return (NULL); 18170Sstevel@tonic-gate } 18180Sstevel@tonic-gate 18190Sstevel@tonic-gate static const char * 18200Sstevel@tonic-gate amd_cpubrand(const struct cpuid_info *cpi) 18210Sstevel@tonic-gate { 18220Sstevel@tonic-gate if ((x86_feature & X86_CPUID) == 0 || 18230Sstevel@tonic-gate cpi->cpi_maxeax < 1 || cpi->cpi_family < 5) 18240Sstevel@tonic-gate return ("i486 compatible"); 18250Sstevel@tonic-gate 18260Sstevel@tonic-gate switch (cpi->cpi_family) { 18270Sstevel@tonic-gate case 5: 18280Sstevel@tonic-gate switch (cpi->cpi_model) { 18290Sstevel@tonic-gate case 0: 18300Sstevel@tonic-gate case 1: 18310Sstevel@tonic-gate case 2: 18320Sstevel@tonic-gate case 3: 18330Sstevel@tonic-gate case 4: 18340Sstevel@tonic-gate case 5: 18350Sstevel@tonic-gate return ("AMD-K5(r)"); 18360Sstevel@tonic-gate case 6: 18370Sstevel@tonic-gate case 7: 18380Sstevel@tonic-gate return ("AMD-K6(r)"); 18390Sstevel@tonic-gate case 8: 18400Sstevel@tonic-gate return ("AMD-K6(r)-2"); 18410Sstevel@tonic-gate case 9: 18420Sstevel@tonic-gate return ("AMD-K6(r)-III"); 18430Sstevel@tonic-gate default: 18440Sstevel@tonic-gate return ("AMD (family 5)"); 18450Sstevel@tonic-gate } 18460Sstevel@tonic-gate case 6: 18470Sstevel@tonic-gate switch (cpi->cpi_model) { 18480Sstevel@tonic-gate case 1: 18490Sstevel@tonic-gate return ("AMD-K7(tm)"); 18500Sstevel@tonic-gate case 0: 18510Sstevel@tonic-gate case 2: 18520Sstevel@tonic-gate case 4: 18530Sstevel@tonic-gate return ("AMD Athlon(tm)"); 18540Sstevel@tonic-gate case 3: 18550Sstevel@tonic-gate case 7: 18560Sstevel@tonic-gate return ("AMD Duron(tm)"); 18570Sstevel@tonic-gate case 6: 18580Sstevel@tonic-gate case 8: 18590Sstevel@tonic-gate case 10: 18600Sstevel@tonic-gate /* 18610Sstevel@tonic-gate * Use the L2 cache size to distinguish 18620Sstevel@tonic-gate */ 18630Sstevel@tonic-gate return ((cpi->cpi_extd[6].cp_ecx >> 16) >= 256 ? 18640Sstevel@tonic-gate "AMD Athlon(tm)" : "AMD Duron(tm)"); 18650Sstevel@tonic-gate default: 18660Sstevel@tonic-gate return ("AMD (family 6)"); 18670Sstevel@tonic-gate } 18680Sstevel@tonic-gate default: 18690Sstevel@tonic-gate break; 18700Sstevel@tonic-gate } 18710Sstevel@tonic-gate 18720Sstevel@tonic-gate if (cpi->cpi_family == 0xf && cpi->cpi_model == 5 && 18730Sstevel@tonic-gate cpi->cpi_brandid != 0) { 18740Sstevel@tonic-gate switch (BITX(cpi->cpi_brandid, 7, 5)) { 18750Sstevel@tonic-gate case 3: 18760Sstevel@tonic-gate return ("AMD Opteron(tm) UP 1xx"); 18770Sstevel@tonic-gate case 4: 18780Sstevel@tonic-gate return ("AMD Opteron(tm) DP 2xx"); 18790Sstevel@tonic-gate case 5: 18800Sstevel@tonic-gate return ("AMD Opteron(tm) MP 8xx"); 18810Sstevel@tonic-gate default: 18820Sstevel@tonic-gate return ("AMD Opteron(tm)"); 18830Sstevel@tonic-gate } 18840Sstevel@tonic-gate } 18850Sstevel@tonic-gate 18860Sstevel@tonic-gate return (NULL); 18870Sstevel@tonic-gate } 18880Sstevel@tonic-gate 18890Sstevel@tonic-gate static const char * 18900Sstevel@tonic-gate cyrix_cpubrand(struct cpuid_info *cpi, uint_t type) 18910Sstevel@tonic-gate { 18920Sstevel@tonic-gate if ((x86_feature & X86_CPUID) == 0 || 18930Sstevel@tonic-gate cpi->cpi_maxeax < 1 || cpi->cpi_family < 5 || 18940Sstevel@tonic-gate type == X86_TYPE_CYRIX_486) 18950Sstevel@tonic-gate return ("i486 compatible"); 18960Sstevel@tonic-gate 18970Sstevel@tonic-gate switch (type) { 18980Sstevel@tonic-gate case X86_TYPE_CYRIX_6x86: 18990Sstevel@tonic-gate return ("Cyrix 6x86"); 19000Sstevel@tonic-gate case X86_TYPE_CYRIX_6x86L: 19010Sstevel@tonic-gate return ("Cyrix 6x86L"); 19020Sstevel@tonic-gate case X86_TYPE_CYRIX_6x86MX: 19030Sstevel@tonic-gate return ("Cyrix 6x86MX"); 19040Sstevel@tonic-gate case X86_TYPE_CYRIX_GXm: 19050Sstevel@tonic-gate return ("Cyrix GXm"); 19060Sstevel@tonic-gate case X86_TYPE_CYRIX_MediaGX: 19070Sstevel@tonic-gate return ("Cyrix MediaGX"); 19080Sstevel@tonic-gate case X86_TYPE_CYRIX_MII: 19090Sstevel@tonic-gate return ("Cyrix M2"); 19100Sstevel@tonic-gate case X86_TYPE_VIA_CYRIX_III: 19110Sstevel@tonic-gate return ("VIA Cyrix M3"); 19120Sstevel@tonic-gate default: 19130Sstevel@tonic-gate /* 19140Sstevel@tonic-gate * Have another wild guess .. 19150Sstevel@tonic-gate */ 19160Sstevel@tonic-gate if (cpi->cpi_family == 4 && cpi->cpi_model == 9) 19170Sstevel@tonic-gate return ("Cyrix 5x86"); 19180Sstevel@tonic-gate else if (cpi->cpi_family == 5) { 19190Sstevel@tonic-gate switch (cpi->cpi_model) { 19200Sstevel@tonic-gate case 2: 19210Sstevel@tonic-gate return ("Cyrix 6x86"); /* Cyrix M1 */ 19220Sstevel@tonic-gate case 4: 19230Sstevel@tonic-gate return ("Cyrix MediaGX"); 19240Sstevel@tonic-gate default: 19250Sstevel@tonic-gate break; 19260Sstevel@tonic-gate } 19270Sstevel@tonic-gate } else if (cpi->cpi_family == 6) { 19280Sstevel@tonic-gate switch (cpi->cpi_model) { 19290Sstevel@tonic-gate case 0: 19300Sstevel@tonic-gate return ("Cyrix 6x86MX"); /* Cyrix M2? */ 19310Sstevel@tonic-gate case 5: 19320Sstevel@tonic-gate case 6: 19330Sstevel@tonic-gate case 7: 19340Sstevel@tonic-gate case 8: 19350Sstevel@tonic-gate case 9: 19360Sstevel@tonic-gate return ("VIA C3"); 19370Sstevel@tonic-gate default: 19380Sstevel@tonic-gate break; 19390Sstevel@tonic-gate } 19400Sstevel@tonic-gate } 19410Sstevel@tonic-gate break; 19420Sstevel@tonic-gate } 19430Sstevel@tonic-gate return (NULL); 19440Sstevel@tonic-gate } 19450Sstevel@tonic-gate 19460Sstevel@tonic-gate /* 19470Sstevel@tonic-gate * This only gets called in the case that the CPU extended 19480Sstevel@tonic-gate * feature brand string (0x80000002, 0x80000003, 0x80000004) 19490Sstevel@tonic-gate * aren't available, or contain null bytes for some reason. 19500Sstevel@tonic-gate */ 19510Sstevel@tonic-gate static void 19520Sstevel@tonic-gate fabricate_brandstr(struct cpuid_info *cpi) 19530Sstevel@tonic-gate { 19540Sstevel@tonic-gate const char *brand = NULL; 19550Sstevel@tonic-gate 19560Sstevel@tonic-gate switch (cpi->cpi_vendor) { 19570Sstevel@tonic-gate case X86_VENDOR_Intel: 19580Sstevel@tonic-gate brand = intel_cpubrand(cpi); 19590Sstevel@tonic-gate break; 19600Sstevel@tonic-gate case X86_VENDOR_AMD: 19610Sstevel@tonic-gate brand = amd_cpubrand(cpi); 19620Sstevel@tonic-gate break; 19630Sstevel@tonic-gate case X86_VENDOR_Cyrix: 19640Sstevel@tonic-gate brand = cyrix_cpubrand(cpi, x86_type); 19650Sstevel@tonic-gate break; 19660Sstevel@tonic-gate case X86_VENDOR_NexGen: 19670Sstevel@tonic-gate if (cpi->cpi_family == 5 && cpi->cpi_model == 0) 19680Sstevel@tonic-gate brand = "NexGen Nx586"; 19690Sstevel@tonic-gate break; 19700Sstevel@tonic-gate case X86_VENDOR_Centaur: 19710Sstevel@tonic-gate if (cpi->cpi_family == 5) 19720Sstevel@tonic-gate switch (cpi->cpi_model) { 19730Sstevel@tonic-gate case 4: 19740Sstevel@tonic-gate brand = "Centaur C6"; 19750Sstevel@tonic-gate break; 19760Sstevel@tonic-gate case 8: 19770Sstevel@tonic-gate brand = "Centaur C2"; 19780Sstevel@tonic-gate break; 19790Sstevel@tonic-gate case 9: 19800Sstevel@tonic-gate brand = "Centaur C3"; 19810Sstevel@tonic-gate break; 19820Sstevel@tonic-gate default: 19830Sstevel@tonic-gate break; 19840Sstevel@tonic-gate } 19850Sstevel@tonic-gate break; 19860Sstevel@tonic-gate case X86_VENDOR_Rise: 19870Sstevel@tonic-gate if (cpi->cpi_family == 5 && 19880Sstevel@tonic-gate (cpi->cpi_model == 0 || cpi->cpi_model == 2)) 19890Sstevel@tonic-gate brand = "Rise mP6"; 19900Sstevel@tonic-gate break; 19910Sstevel@tonic-gate case X86_VENDOR_SiS: 19920Sstevel@tonic-gate if (cpi->cpi_family == 5 && cpi->cpi_model == 0) 19930Sstevel@tonic-gate brand = "SiS 55x"; 19940Sstevel@tonic-gate break; 19950Sstevel@tonic-gate case X86_VENDOR_TM: 19960Sstevel@tonic-gate if (cpi->cpi_family == 5 && cpi->cpi_model == 4) 19970Sstevel@tonic-gate brand = "Transmeta Crusoe TM3x00 or TM5x00"; 19980Sstevel@tonic-gate break; 19990Sstevel@tonic-gate case X86_VENDOR_NSC: 20000Sstevel@tonic-gate case X86_VENDOR_UMC: 20010Sstevel@tonic-gate default: 20020Sstevel@tonic-gate break; 20030Sstevel@tonic-gate } 20040Sstevel@tonic-gate if (brand) { 20050Sstevel@tonic-gate (void) strcpy((char *)cpi->cpi_brandstr, brand); 20060Sstevel@tonic-gate return; 20070Sstevel@tonic-gate } 20080Sstevel@tonic-gate 20090Sstevel@tonic-gate /* 20100Sstevel@tonic-gate * If all else fails ... 20110Sstevel@tonic-gate */ 20120Sstevel@tonic-gate (void) snprintf(cpi->cpi_brandstr, sizeof (cpi->cpi_brandstr), 20130Sstevel@tonic-gate "%s %d.%d.%d", cpi->cpi_vendorstr, cpi->cpi_family, 20140Sstevel@tonic-gate cpi->cpi_model, cpi->cpi_step); 20150Sstevel@tonic-gate } 20160Sstevel@tonic-gate 20170Sstevel@tonic-gate /* 20180Sstevel@tonic-gate * This routine is called just after kernel memory allocation 20190Sstevel@tonic-gate * becomes available on cpu0, and as part of mp_startup() on 20200Sstevel@tonic-gate * the other cpus. 20210Sstevel@tonic-gate * 20224606Sesaxe * Fixup the brand string, and collect any information from cpuid 20234606Sesaxe * that requires dynamicically allocated storage to represent. 20240Sstevel@tonic-gate */ 20250Sstevel@tonic-gate /*ARGSUSED*/ 20260Sstevel@tonic-gate void 20270Sstevel@tonic-gate cpuid_pass3(cpu_t *cpu) 20280Sstevel@tonic-gate { 20294606Sesaxe int i, max, shft, level, size; 20304606Sesaxe struct cpuid_regs regs; 20314606Sesaxe struct cpuid_regs *cp; 20320Sstevel@tonic-gate struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 20330Sstevel@tonic-gate 20340Sstevel@tonic-gate ASSERT(cpi->cpi_pass == 2); 20350Sstevel@tonic-gate 20364606Sesaxe /* 20374606Sesaxe * Function 4: Deterministic cache parameters 20384606Sesaxe * 20394606Sesaxe * Take this opportunity to detect the number of threads 20404606Sesaxe * sharing the last level cache, and construct a corresponding 20414606Sesaxe * cache id. The respective cpuid_info members are initialized 20424606Sesaxe * to the default case of "no last level cache sharing". 20434606Sesaxe */ 20444606Sesaxe cpi->cpi_ncpu_shr_last_cache = 1; 20454606Sesaxe cpi->cpi_last_lvl_cacheid = cpu->cpu_id; 20464606Sesaxe 20474606Sesaxe if (cpi->cpi_maxeax >= 4 && cpi->cpi_vendor == X86_VENDOR_Intel) { 20484606Sesaxe 20494606Sesaxe /* 20504606Sesaxe * Find the # of elements (size) returned by fn 4, and along 20514606Sesaxe * the way detect last level cache sharing details. 20524606Sesaxe */ 20534606Sesaxe bzero(®s, sizeof (regs)); 20544606Sesaxe cp = ®s; 20554606Sesaxe for (i = 0, max = 0; i < CPI_FN4_ECX_MAX; i++) { 20564606Sesaxe cp->cp_eax = 4; 20574606Sesaxe cp->cp_ecx = i; 20584606Sesaxe 20594606Sesaxe (void) __cpuid_insn(cp); 20604606Sesaxe 20614606Sesaxe if (CPI_CACHE_TYPE(cp) == 0) 20624606Sesaxe break; 20634606Sesaxe level = CPI_CACHE_LVL(cp); 20644606Sesaxe if (level > max) { 20654606Sesaxe max = level; 20664606Sesaxe cpi->cpi_ncpu_shr_last_cache = 20674606Sesaxe CPI_NTHR_SHR_CACHE(cp) + 1; 20684606Sesaxe } 20694606Sesaxe } 20704606Sesaxe cpi->cpi_std_4_size = size = i; 20714606Sesaxe 20724606Sesaxe /* 20734606Sesaxe * Allocate the cpi_std_4 array. The first element 20744606Sesaxe * references the regs for fn 4, %ecx == 0, which 20754606Sesaxe * cpuid_pass2() stashed in cpi->cpi_std[4]. 20764606Sesaxe */ 20774606Sesaxe if (size > 0) { 20784606Sesaxe cpi->cpi_std_4 = 20794606Sesaxe kmem_alloc(size * sizeof (cp), KM_SLEEP); 20804606Sesaxe cpi->cpi_std_4[0] = &cpi->cpi_std[4]; 20814606Sesaxe 20824606Sesaxe /* 20834606Sesaxe * Allocate storage to hold the additional regs 20844606Sesaxe * for function 4, %ecx == 1 .. cpi_std_4_size. 20854606Sesaxe * 20864606Sesaxe * The regs for fn 4, %ecx == 0 has already 20874606Sesaxe * been allocated as indicated above. 20884606Sesaxe */ 20894606Sesaxe for (i = 1; i < size; i++) { 20904606Sesaxe cp = cpi->cpi_std_4[i] = 20914606Sesaxe kmem_zalloc(sizeof (regs), KM_SLEEP); 20924606Sesaxe cp->cp_eax = 4; 20934606Sesaxe cp->cp_ecx = i; 20944606Sesaxe 20954606Sesaxe (void) __cpuid_insn(cp); 20964606Sesaxe } 20974606Sesaxe } 20984606Sesaxe /* 20994606Sesaxe * Determine the number of bits needed to represent 21004606Sesaxe * the number of CPUs sharing the last level cache. 21014606Sesaxe * 21024606Sesaxe * Shift off that number of bits from the APIC id to 21034606Sesaxe * derive the cache id. 21044606Sesaxe */ 21054606Sesaxe shft = 0; 21064606Sesaxe for (i = 1; i < cpi->cpi_ncpu_shr_last_cache; i <<= 1) 21074606Sesaxe shft++; 21087282Smishra cpi->cpi_last_lvl_cacheid = cpi->cpi_apicid >> shft; 21090Sstevel@tonic-gate } 21100Sstevel@tonic-gate 21110Sstevel@tonic-gate /* 21124606Sesaxe * Now fixup the brand string 21130Sstevel@tonic-gate */ 21144606Sesaxe if ((cpi->cpi_xmaxeax & 0x80000000) == 0) { 21154606Sesaxe fabricate_brandstr(cpi); 21164606Sesaxe } else { 21170Sstevel@tonic-gate 21180Sstevel@tonic-gate /* 21194606Sesaxe * If we successfully extracted a brand string from the cpuid 21204606Sesaxe * instruction, clean it up by removing leading spaces and 21214606Sesaxe * similar junk. 21220Sstevel@tonic-gate */ 21234606Sesaxe if (cpi->cpi_brandstr[0]) { 21244606Sesaxe size_t maxlen = sizeof (cpi->cpi_brandstr); 21254606Sesaxe char *src, *dst; 21264606Sesaxe 21274606Sesaxe dst = src = (char *)cpi->cpi_brandstr; 21284606Sesaxe src[maxlen - 1] = '\0'; 21294606Sesaxe /* 21304606Sesaxe * strip leading spaces 21314606Sesaxe */ 21324606Sesaxe while (*src == ' ') 21334606Sesaxe src++; 21344606Sesaxe /* 21354606Sesaxe * Remove any 'Genuine' or "Authentic" prefixes 21364606Sesaxe */ 21374606Sesaxe if (strncmp(src, "Genuine ", 8) == 0) 21384606Sesaxe src += 8; 21394606Sesaxe if (strncmp(src, "Authentic ", 10) == 0) 21404606Sesaxe src += 10; 21414606Sesaxe 21424606Sesaxe /* 21434606Sesaxe * Now do an in-place copy. 21444606Sesaxe * Map (R) to (r) and (TM) to (tm). 21454606Sesaxe * The era of teletypes is long gone, and there's 21464606Sesaxe * -really- no need to shout. 21474606Sesaxe */ 21484606Sesaxe while (*src != '\0') { 21494606Sesaxe if (src[0] == '(') { 21504606Sesaxe if (strncmp(src + 1, "R)", 2) == 0) { 21514606Sesaxe (void) strncpy(dst, "(r)", 3); 21524606Sesaxe src += 3; 21534606Sesaxe dst += 3; 21544606Sesaxe continue; 21554606Sesaxe } 21564606Sesaxe if (strncmp(src + 1, "TM)", 3) == 0) { 21574606Sesaxe (void) strncpy(dst, "(tm)", 4); 21584606Sesaxe src += 4; 21594606Sesaxe dst += 4; 21604606Sesaxe continue; 21614606Sesaxe } 21620Sstevel@tonic-gate } 21634606Sesaxe *dst++ = *src++; 21640Sstevel@tonic-gate } 21654606Sesaxe *dst = '\0'; 21664606Sesaxe 21674606Sesaxe /* 21684606Sesaxe * Finally, remove any trailing spaces 21694606Sesaxe */ 21704606Sesaxe while (--dst > cpi->cpi_brandstr) 21714606Sesaxe if (*dst == ' ') 21724606Sesaxe *dst = '\0'; 21734606Sesaxe else 21744606Sesaxe break; 21754606Sesaxe } else 21764606Sesaxe fabricate_brandstr(cpi); 21774606Sesaxe } 21780Sstevel@tonic-gate cpi->cpi_pass = 3; 21790Sstevel@tonic-gate } 21800Sstevel@tonic-gate 21810Sstevel@tonic-gate /* 21820Sstevel@tonic-gate * This routine is called out of bind_hwcap() much later in the life 21830Sstevel@tonic-gate * of the kernel (post_startup()). The job of this routine is to resolve 21840Sstevel@tonic-gate * the hardware feature support and kernel support for those features into 21850Sstevel@tonic-gate * what we're actually going to tell applications via the aux vector. 21860Sstevel@tonic-gate */ 21870Sstevel@tonic-gate uint_t 21880Sstevel@tonic-gate cpuid_pass4(cpu_t *cpu) 21890Sstevel@tonic-gate { 21900Sstevel@tonic-gate struct cpuid_info *cpi; 21910Sstevel@tonic-gate uint_t hwcap_flags = 0; 21920Sstevel@tonic-gate 21930Sstevel@tonic-gate if (cpu == NULL) 21940Sstevel@tonic-gate cpu = CPU; 21950Sstevel@tonic-gate cpi = cpu->cpu_m.mcpu_cpi; 21960Sstevel@tonic-gate 21970Sstevel@tonic-gate ASSERT(cpi->cpi_pass == 3); 21980Sstevel@tonic-gate 21990Sstevel@tonic-gate if (cpi->cpi_maxeax >= 1) { 22000Sstevel@tonic-gate uint32_t *edx = &cpi->cpi_support[STD_EDX_FEATURES]; 22010Sstevel@tonic-gate uint32_t *ecx = &cpi->cpi_support[STD_ECX_FEATURES]; 22020Sstevel@tonic-gate 22030Sstevel@tonic-gate *edx = CPI_FEATURES_EDX(cpi); 22040Sstevel@tonic-gate *ecx = CPI_FEATURES_ECX(cpi); 22050Sstevel@tonic-gate 22060Sstevel@tonic-gate /* 22070Sstevel@tonic-gate * [these require explicit kernel support] 22080Sstevel@tonic-gate */ 22090Sstevel@tonic-gate if ((x86_feature & X86_SEP) == 0) 22100Sstevel@tonic-gate *edx &= ~CPUID_INTC_EDX_SEP; 22110Sstevel@tonic-gate 22120Sstevel@tonic-gate if ((x86_feature & X86_SSE) == 0) 22130Sstevel@tonic-gate *edx &= ~(CPUID_INTC_EDX_FXSR|CPUID_INTC_EDX_SSE); 22140Sstevel@tonic-gate if ((x86_feature & X86_SSE2) == 0) 22150Sstevel@tonic-gate *edx &= ~CPUID_INTC_EDX_SSE2; 22160Sstevel@tonic-gate 22170Sstevel@tonic-gate if ((x86_feature & X86_HTT) == 0) 22180Sstevel@tonic-gate *edx &= ~CPUID_INTC_EDX_HTT; 22190Sstevel@tonic-gate 22200Sstevel@tonic-gate if ((x86_feature & X86_SSE3) == 0) 22210Sstevel@tonic-gate *ecx &= ~CPUID_INTC_ECX_SSE3; 22220Sstevel@tonic-gate 22235269Skk208521 if (cpi->cpi_vendor == X86_VENDOR_Intel) { 22245269Skk208521 if ((x86_feature & X86_SSSE3) == 0) 22255269Skk208521 *ecx &= ~CPUID_INTC_ECX_SSSE3; 22265269Skk208521 if ((x86_feature & X86_SSE4_1) == 0) 22275269Skk208521 *ecx &= ~CPUID_INTC_ECX_SSE4_1; 22285269Skk208521 if ((x86_feature & X86_SSE4_2) == 0) 22295269Skk208521 *ecx &= ~CPUID_INTC_ECX_SSE4_2; 22309370SKuriakose.Kuruvilla@Sun.COM if ((x86_feature & X86_AES) == 0) 22319370SKuriakose.Kuruvilla@Sun.COM *ecx &= ~CPUID_INTC_ECX_AES; 22325269Skk208521 } 22335269Skk208521 22340Sstevel@tonic-gate /* 22350Sstevel@tonic-gate * [no explicit support required beyond x87 fp context] 22360Sstevel@tonic-gate */ 22370Sstevel@tonic-gate if (!fpu_exists) 22380Sstevel@tonic-gate *edx &= ~(CPUID_INTC_EDX_FPU | CPUID_INTC_EDX_MMX); 22390Sstevel@tonic-gate 22400Sstevel@tonic-gate /* 22410Sstevel@tonic-gate * Now map the supported feature vector to things that we 22420Sstevel@tonic-gate * think userland will care about. 22430Sstevel@tonic-gate */ 22440Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_SEP) 22450Sstevel@tonic-gate hwcap_flags |= AV_386_SEP; 22460Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_SSE) 22470Sstevel@tonic-gate hwcap_flags |= AV_386_FXSR | AV_386_SSE; 22480Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_SSE2) 22490Sstevel@tonic-gate hwcap_flags |= AV_386_SSE2; 22500Sstevel@tonic-gate if (*ecx & CPUID_INTC_ECX_SSE3) 22510Sstevel@tonic-gate hwcap_flags |= AV_386_SSE3; 22525269Skk208521 if (cpi->cpi_vendor == X86_VENDOR_Intel) { 22535269Skk208521 if (*ecx & CPUID_INTC_ECX_SSSE3) 22545269Skk208521 hwcap_flags |= AV_386_SSSE3; 22555269Skk208521 if (*ecx & CPUID_INTC_ECX_SSE4_1) 22565269Skk208521 hwcap_flags |= AV_386_SSE4_1; 22575269Skk208521 if (*ecx & CPUID_INTC_ECX_SSE4_2) 22585269Skk208521 hwcap_flags |= AV_386_SSE4_2; 22598418SKrishnendu.Sadhukhan@Sun.COM if (*ecx & CPUID_INTC_ECX_MOVBE) 22608418SKrishnendu.Sadhukhan@Sun.COM hwcap_flags |= AV_386_MOVBE; 22619370SKuriakose.Kuruvilla@Sun.COM if (*ecx & CPUID_INTC_ECX_AES) 22629370SKuriakose.Kuruvilla@Sun.COM hwcap_flags |= AV_386_AES; 22639370SKuriakose.Kuruvilla@Sun.COM if (*ecx & CPUID_INTC_ECX_PCLMULQDQ) 22649370SKuriakose.Kuruvilla@Sun.COM hwcap_flags |= AV_386_PCLMULQDQ; 22655269Skk208521 } 22664628Skk208521 if (*ecx & CPUID_INTC_ECX_POPCNT) 22674628Skk208521 hwcap_flags |= AV_386_POPCNT; 22680Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_FPU) 22690Sstevel@tonic-gate hwcap_flags |= AV_386_FPU; 22700Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_MMX) 22710Sstevel@tonic-gate hwcap_flags |= AV_386_MMX; 22720Sstevel@tonic-gate 22730Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_TSC) 22740Sstevel@tonic-gate hwcap_flags |= AV_386_TSC; 22750Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_CX8) 22760Sstevel@tonic-gate hwcap_flags |= AV_386_CX8; 22770Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_CMOV) 22780Sstevel@tonic-gate hwcap_flags |= AV_386_CMOV; 22790Sstevel@tonic-gate if (*ecx & CPUID_INTC_ECX_MON) 22800Sstevel@tonic-gate hwcap_flags |= AV_386_MON; 22810Sstevel@tonic-gate if (*ecx & CPUID_INTC_ECX_CX16) 22820Sstevel@tonic-gate hwcap_flags |= AV_386_CX16; 22830Sstevel@tonic-gate } 22840Sstevel@tonic-gate 22851228Sandrei if (x86_feature & X86_HTT) 22860Sstevel@tonic-gate hwcap_flags |= AV_386_PAUSE; 22870Sstevel@tonic-gate 22880Sstevel@tonic-gate if (cpi->cpi_xmaxeax < 0x80000001) 22890Sstevel@tonic-gate goto pass4_done; 22900Sstevel@tonic-gate 22910Sstevel@tonic-gate switch (cpi->cpi_vendor) { 22921228Sandrei struct cpuid_regs cp; 22933446Smrj uint32_t *edx, *ecx; 22940Sstevel@tonic-gate 22953446Smrj case X86_VENDOR_Intel: 22963446Smrj /* 22973446Smrj * Seems like Intel duplicated what we necessary 22983446Smrj * here to make the initial crop of 64-bit OS's work. 22993446Smrj * Hopefully, those are the only "extended" bits 23003446Smrj * they'll add. 23013446Smrj */ 23023446Smrj /*FALLTHROUGH*/ 23033446Smrj 23040Sstevel@tonic-gate case X86_VENDOR_AMD: 23050Sstevel@tonic-gate edx = &cpi->cpi_support[AMD_EDX_FEATURES]; 23063446Smrj ecx = &cpi->cpi_support[AMD_ECX_FEATURES]; 23070Sstevel@tonic-gate 23080Sstevel@tonic-gate *edx = CPI_FEATURES_XTD_EDX(cpi); 23093446Smrj *ecx = CPI_FEATURES_XTD_ECX(cpi); 23103446Smrj 23113446Smrj /* 23123446Smrj * [these features require explicit kernel support] 23133446Smrj */ 23143446Smrj switch (cpi->cpi_vendor) { 23153446Smrj case X86_VENDOR_Intel: 23166657Ssudheer if ((x86_feature & X86_TSCP) == 0) 23176657Ssudheer *edx &= ~CPUID_AMD_EDX_TSCP; 23183446Smrj break; 23193446Smrj 23203446Smrj case X86_VENDOR_AMD: 23213446Smrj if ((x86_feature & X86_TSCP) == 0) 23223446Smrj *edx &= ~CPUID_AMD_EDX_TSCP; 23234628Skk208521 if ((x86_feature & X86_SSE4A) == 0) 23244628Skk208521 *ecx &= ~CPUID_AMD_ECX_SSE4A; 23253446Smrj break; 23263446Smrj 23273446Smrj default: 23283446Smrj break; 23293446Smrj } 23300Sstevel@tonic-gate 23310Sstevel@tonic-gate /* 23320Sstevel@tonic-gate * [no explicit support required beyond 23330Sstevel@tonic-gate * x87 fp context and exception handlers] 23340Sstevel@tonic-gate */ 23350Sstevel@tonic-gate if (!fpu_exists) 23360Sstevel@tonic-gate *edx &= ~(CPUID_AMD_EDX_MMXamd | 23370Sstevel@tonic-gate CPUID_AMD_EDX_3DNow | CPUID_AMD_EDX_3DNowx); 23380Sstevel@tonic-gate 23390Sstevel@tonic-gate if ((x86_feature & X86_NX) == 0) 23400Sstevel@tonic-gate *edx &= ~CPUID_AMD_EDX_NX; 23413446Smrj #if !defined(__amd64) 23420Sstevel@tonic-gate *edx &= ~CPUID_AMD_EDX_LM; 23430Sstevel@tonic-gate #endif 23440Sstevel@tonic-gate /* 23450Sstevel@tonic-gate * Now map the supported feature vector to 23460Sstevel@tonic-gate * things that we think userland will care about. 23470Sstevel@tonic-gate */ 23483446Smrj #if defined(__amd64) 23490Sstevel@tonic-gate if (*edx & CPUID_AMD_EDX_SYSC) 23500Sstevel@tonic-gate hwcap_flags |= AV_386_AMD_SYSC; 23513446Smrj #endif 23520Sstevel@tonic-gate if (*edx & CPUID_AMD_EDX_MMXamd) 23530Sstevel@tonic-gate hwcap_flags |= AV_386_AMD_MMX; 23540Sstevel@tonic-gate if (*edx & CPUID_AMD_EDX_3DNow) 23550Sstevel@tonic-gate hwcap_flags |= AV_386_AMD_3DNow; 23560Sstevel@tonic-gate if (*edx & CPUID_AMD_EDX_3DNowx) 23570Sstevel@tonic-gate hwcap_flags |= AV_386_AMD_3DNowx; 23583446Smrj 23593446Smrj switch (cpi->cpi_vendor) { 23603446Smrj case X86_VENDOR_AMD: 23613446Smrj if (*edx & CPUID_AMD_EDX_TSCP) 23623446Smrj hwcap_flags |= AV_386_TSCP; 23633446Smrj if (*ecx & CPUID_AMD_ECX_AHF64) 23643446Smrj hwcap_flags |= AV_386_AHF; 23654628Skk208521 if (*ecx & CPUID_AMD_ECX_SSE4A) 23664628Skk208521 hwcap_flags |= AV_386_AMD_SSE4A; 23674628Skk208521 if (*ecx & CPUID_AMD_ECX_LZCNT) 23684628Skk208521 hwcap_flags |= AV_386_AMD_LZCNT; 23693446Smrj break; 23703446Smrj 23713446Smrj case X86_VENDOR_Intel: 23726657Ssudheer if (*edx & CPUID_AMD_EDX_TSCP) 23736657Ssudheer hwcap_flags |= AV_386_TSCP; 23743446Smrj /* 23753446Smrj * Aarrgh. 23763446Smrj * Intel uses a different bit in the same word. 23773446Smrj */ 23783446Smrj if (*ecx & CPUID_INTC_ECX_AHF64) 23793446Smrj hwcap_flags |= AV_386_AHF; 23803446Smrj break; 23813446Smrj 23823446Smrj default: 23833446Smrj break; 23843446Smrj } 23850Sstevel@tonic-gate break; 23860Sstevel@tonic-gate 23870Sstevel@tonic-gate case X86_VENDOR_TM: 23881228Sandrei cp.cp_eax = 0x80860001; 23891228Sandrei (void) __cpuid_insn(&cp); 23901228Sandrei cpi->cpi_support[TM_EDX_FEATURES] = cp.cp_edx; 23910Sstevel@tonic-gate break; 23920Sstevel@tonic-gate 23930Sstevel@tonic-gate default: 23940Sstevel@tonic-gate break; 23950Sstevel@tonic-gate } 23960Sstevel@tonic-gate 23970Sstevel@tonic-gate pass4_done: 23980Sstevel@tonic-gate cpi->cpi_pass = 4; 23990Sstevel@tonic-gate return (hwcap_flags); 24000Sstevel@tonic-gate } 24010Sstevel@tonic-gate 24020Sstevel@tonic-gate 24030Sstevel@tonic-gate /* 24040Sstevel@tonic-gate * Simulate the cpuid instruction using the data we previously 24050Sstevel@tonic-gate * captured about this CPU. We try our best to return the truth 24060Sstevel@tonic-gate * about the hardware, independently of kernel support. 24070Sstevel@tonic-gate */ 24080Sstevel@tonic-gate uint32_t 24091228Sandrei cpuid_insn(cpu_t *cpu, struct cpuid_regs *cp) 24100Sstevel@tonic-gate { 24110Sstevel@tonic-gate struct cpuid_info *cpi; 24121228Sandrei struct cpuid_regs *xcp; 24130Sstevel@tonic-gate 24140Sstevel@tonic-gate if (cpu == NULL) 24150Sstevel@tonic-gate cpu = CPU; 24160Sstevel@tonic-gate cpi = cpu->cpu_m.mcpu_cpi; 24170Sstevel@tonic-gate 24180Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 3)); 24190Sstevel@tonic-gate 24200Sstevel@tonic-gate /* 24210Sstevel@tonic-gate * CPUID data is cached in two separate places: cpi_std for standard 24220Sstevel@tonic-gate * CPUID functions, and cpi_extd for extended CPUID functions. 24230Sstevel@tonic-gate */ 24241228Sandrei if (cp->cp_eax <= cpi->cpi_maxeax && cp->cp_eax < NMAX_CPI_STD) 24251228Sandrei xcp = &cpi->cpi_std[cp->cp_eax]; 24261228Sandrei else if (cp->cp_eax >= 0x80000000 && cp->cp_eax <= cpi->cpi_xmaxeax && 24271228Sandrei cp->cp_eax < 0x80000000 + NMAX_CPI_EXTD) 24281228Sandrei xcp = &cpi->cpi_extd[cp->cp_eax - 0x80000000]; 24290Sstevel@tonic-gate else 24300Sstevel@tonic-gate /* 24310Sstevel@tonic-gate * The caller is asking for data from an input parameter which 24320Sstevel@tonic-gate * the kernel has not cached. In this case we go fetch from 24330Sstevel@tonic-gate * the hardware and return the data directly to the user. 24340Sstevel@tonic-gate */ 24351228Sandrei return (__cpuid_insn(cp)); 24361228Sandrei 24371228Sandrei cp->cp_eax = xcp->cp_eax; 24381228Sandrei cp->cp_ebx = xcp->cp_ebx; 24391228Sandrei cp->cp_ecx = xcp->cp_ecx; 24401228Sandrei cp->cp_edx = xcp->cp_edx; 24410Sstevel@tonic-gate return (cp->cp_eax); 24420Sstevel@tonic-gate } 24430Sstevel@tonic-gate 24440Sstevel@tonic-gate int 24450Sstevel@tonic-gate cpuid_checkpass(cpu_t *cpu, int pass) 24460Sstevel@tonic-gate { 24470Sstevel@tonic-gate return (cpu != NULL && cpu->cpu_m.mcpu_cpi != NULL && 24480Sstevel@tonic-gate cpu->cpu_m.mcpu_cpi->cpi_pass >= pass); 24490Sstevel@tonic-gate } 24500Sstevel@tonic-gate 24510Sstevel@tonic-gate int 24520Sstevel@tonic-gate cpuid_getbrandstr(cpu_t *cpu, char *s, size_t n) 24530Sstevel@tonic-gate { 24540Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 3)); 24550Sstevel@tonic-gate 24560Sstevel@tonic-gate return (snprintf(s, n, "%s", cpu->cpu_m.mcpu_cpi->cpi_brandstr)); 24570Sstevel@tonic-gate } 24580Sstevel@tonic-gate 24590Sstevel@tonic-gate int 24601228Sandrei cpuid_is_cmt(cpu_t *cpu) 24610Sstevel@tonic-gate { 24620Sstevel@tonic-gate if (cpu == NULL) 24630Sstevel@tonic-gate cpu = CPU; 24640Sstevel@tonic-gate 24650Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 24660Sstevel@tonic-gate 24670Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_chipid >= 0); 24680Sstevel@tonic-gate } 24690Sstevel@tonic-gate 24700Sstevel@tonic-gate /* 24710Sstevel@tonic-gate * AMD and Intel both implement the 64-bit variant of the syscall 24720Sstevel@tonic-gate * instruction (syscallq), so if there's -any- support for syscall, 24730Sstevel@tonic-gate * cpuid currently says "yes, we support this". 24740Sstevel@tonic-gate * 24750Sstevel@tonic-gate * However, Intel decided to -not- implement the 32-bit variant of the 24760Sstevel@tonic-gate * syscall instruction, so we provide a predicate to allow our caller 24770Sstevel@tonic-gate * to test that subtlety here. 24785084Sjohnlev * 24795084Sjohnlev * XXPV Currently, 32-bit syscall instructions don't work via the hypervisor, 24805084Sjohnlev * even in the case where the hardware would in fact support it. 24810Sstevel@tonic-gate */ 24820Sstevel@tonic-gate /*ARGSUSED*/ 24830Sstevel@tonic-gate int 24840Sstevel@tonic-gate cpuid_syscall32_insn(cpu_t *cpu) 24850Sstevel@tonic-gate { 24860Sstevel@tonic-gate ASSERT(cpuid_checkpass((cpu == NULL ? CPU : cpu), 1)); 24870Sstevel@tonic-gate 24885084Sjohnlev #if !defined(__xpv) 24893446Smrj if (cpu == NULL) 24903446Smrj cpu = CPU; 24913446Smrj 24923446Smrj /*CSTYLED*/ 24933446Smrj { 24943446Smrj struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 24953446Smrj 24963446Smrj if (cpi->cpi_vendor == X86_VENDOR_AMD && 24973446Smrj cpi->cpi_xmaxeax >= 0x80000001 && 24983446Smrj (CPI_FEATURES_XTD_EDX(cpi) & CPUID_AMD_EDX_SYSC)) 24993446Smrj return (1); 25003446Smrj } 25015084Sjohnlev #endif 25020Sstevel@tonic-gate return (0); 25030Sstevel@tonic-gate } 25040Sstevel@tonic-gate 25050Sstevel@tonic-gate int 25060Sstevel@tonic-gate cpuid_getidstr(cpu_t *cpu, char *s, size_t n) 25070Sstevel@tonic-gate { 25080Sstevel@tonic-gate struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 25090Sstevel@tonic-gate 25100Sstevel@tonic-gate static const char fmt[] = 25113779Sdmick "x86 (%s %X family %d model %d step %d clock %d MHz)"; 25120Sstevel@tonic-gate static const char fmt_ht[] = 25133779Sdmick "x86 (chipid 0x%x %s %X family %d model %d step %d clock %d MHz)"; 25140Sstevel@tonic-gate 25150Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 25160Sstevel@tonic-gate 25171228Sandrei if (cpuid_is_cmt(cpu)) 25180Sstevel@tonic-gate return (snprintf(s, n, fmt_ht, cpi->cpi_chipid, 25193779Sdmick cpi->cpi_vendorstr, cpi->cpi_std[1].cp_eax, 25203779Sdmick cpi->cpi_family, cpi->cpi_model, 25210Sstevel@tonic-gate cpi->cpi_step, cpu->cpu_type_info.pi_clock)); 25220Sstevel@tonic-gate return (snprintf(s, n, fmt, 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 } 25270Sstevel@tonic-gate 25280Sstevel@tonic-gate const char * 25290Sstevel@tonic-gate cpuid_getvendorstr(cpu_t *cpu) 25300Sstevel@tonic-gate { 25310Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 25320Sstevel@tonic-gate return ((const char *)cpu->cpu_m.mcpu_cpi->cpi_vendorstr); 25330Sstevel@tonic-gate } 25340Sstevel@tonic-gate 25350Sstevel@tonic-gate uint_t 25360Sstevel@tonic-gate cpuid_getvendor(cpu_t *cpu) 25370Sstevel@tonic-gate { 25380Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 25390Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_vendor); 25400Sstevel@tonic-gate } 25410Sstevel@tonic-gate 25420Sstevel@tonic-gate uint_t 25430Sstevel@tonic-gate cpuid_getfamily(cpu_t *cpu) 25440Sstevel@tonic-gate { 25450Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 25460Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_family); 25470Sstevel@tonic-gate } 25480Sstevel@tonic-gate 25490Sstevel@tonic-gate uint_t 25500Sstevel@tonic-gate cpuid_getmodel(cpu_t *cpu) 25510Sstevel@tonic-gate { 25520Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 25530Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_model); 25540Sstevel@tonic-gate } 25550Sstevel@tonic-gate 25560Sstevel@tonic-gate uint_t 25570Sstevel@tonic-gate cpuid_get_ncpu_per_chip(cpu_t *cpu) 25580Sstevel@tonic-gate { 25590Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 25600Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_ncpu_per_chip); 25610Sstevel@tonic-gate } 25620Sstevel@tonic-gate 25630Sstevel@tonic-gate uint_t 25641228Sandrei cpuid_get_ncore_per_chip(cpu_t *cpu) 25651228Sandrei { 25661228Sandrei ASSERT(cpuid_checkpass(cpu, 1)); 25671228Sandrei return (cpu->cpu_m.mcpu_cpi->cpi_ncore_per_chip); 25681228Sandrei } 25691228Sandrei 25701228Sandrei uint_t 25714606Sesaxe cpuid_get_ncpu_sharing_last_cache(cpu_t *cpu) 25724606Sesaxe { 25734606Sesaxe ASSERT(cpuid_checkpass(cpu, 2)); 25744606Sesaxe return (cpu->cpu_m.mcpu_cpi->cpi_ncpu_shr_last_cache); 25754606Sesaxe } 25764606Sesaxe 25774606Sesaxe id_t 25784606Sesaxe cpuid_get_last_lvl_cacheid(cpu_t *cpu) 25794606Sesaxe { 25804606Sesaxe ASSERT(cpuid_checkpass(cpu, 2)); 25814606Sesaxe return (cpu->cpu_m.mcpu_cpi->cpi_last_lvl_cacheid); 25824606Sesaxe } 25834606Sesaxe 25844606Sesaxe uint_t 25850Sstevel@tonic-gate cpuid_getstep(cpu_t *cpu) 25860Sstevel@tonic-gate { 25870Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 25880Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_step); 25890Sstevel@tonic-gate } 25900Sstevel@tonic-gate 25914581Ssherrym uint_t 25924581Ssherrym cpuid_getsig(struct cpu *cpu) 25934581Ssherrym { 25944581Ssherrym ASSERT(cpuid_checkpass(cpu, 1)); 25954581Ssherrym return (cpu->cpu_m.mcpu_cpi->cpi_std[1].cp_eax); 25964581Ssherrym } 25974581Ssherrym 25982869Sgavinm uint32_t 25992869Sgavinm cpuid_getchiprev(struct cpu *cpu) 26002869Sgavinm { 26012869Sgavinm ASSERT(cpuid_checkpass(cpu, 1)); 26022869Sgavinm return (cpu->cpu_m.mcpu_cpi->cpi_chiprev); 26032869Sgavinm } 26042869Sgavinm 26052869Sgavinm const char * 26062869Sgavinm cpuid_getchiprevstr(struct cpu *cpu) 26072869Sgavinm { 26082869Sgavinm ASSERT(cpuid_checkpass(cpu, 1)); 26092869Sgavinm return (cpu->cpu_m.mcpu_cpi->cpi_chiprevstr); 26102869Sgavinm } 26112869Sgavinm 26122869Sgavinm uint32_t 26132869Sgavinm cpuid_getsockettype(struct cpu *cpu) 26142869Sgavinm { 26152869Sgavinm ASSERT(cpuid_checkpass(cpu, 1)); 26162869Sgavinm return (cpu->cpu_m.mcpu_cpi->cpi_socket); 26172869Sgavinm } 26182869Sgavinm 26199482SKuriakose.Kuruvilla@Sun.COM const char * 26209482SKuriakose.Kuruvilla@Sun.COM cpuid_getsocketstr(cpu_t *cpu) 26219482SKuriakose.Kuruvilla@Sun.COM { 26229482SKuriakose.Kuruvilla@Sun.COM static const char *socketstr = NULL; 26239482SKuriakose.Kuruvilla@Sun.COM struct cpuid_info *cpi; 26249482SKuriakose.Kuruvilla@Sun.COM 26259482SKuriakose.Kuruvilla@Sun.COM ASSERT(cpuid_checkpass(cpu, 1)); 26269482SKuriakose.Kuruvilla@Sun.COM cpi = cpu->cpu_m.mcpu_cpi; 26279482SKuriakose.Kuruvilla@Sun.COM 26289482SKuriakose.Kuruvilla@Sun.COM /* Assume that socket types are the same across the system */ 26299482SKuriakose.Kuruvilla@Sun.COM if (socketstr == NULL) 26309482SKuriakose.Kuruvilla@Sun.COM socketstr = _cpuid_sktstr(cpi->cpi_vendor, cpi->cpi_family, 26319482SKuriakose.Kuruvilla@Sun.COM cpi->cpi_model, cpi->cpi_step); 26329482SKuriakose.Kuruvilla@Sun.COM 26339482SKuriakose.Kuruvilla@Sun.COM 26349482SKuriakose.Kuruvilla@Sun.COM return (socketstr); 26359482SKuriakose.Kuruvilla@Sun.COM } 26369482SKuriakose.Kuruvilla@Sun.COM 26373434Sesaxe int 26383434Sesaxe cpuid_get_chipid(cpu_t *cpu) 26390Sstevel@tonic-gate { 26400Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 26410Sstevel@tonic-gate 26421228Sandrei if (cpuid_is_cmt(cpu)) 26430Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_chipid); 26440Sstevel@tonic-gate return (cpu->cpu_id); 26450Sstevel@tonic-gate } 26460Sstevel@tonic-gate 26471228Sandrei id_t 26483434Sesaxe cpuid_get_coreid(cpu_t *cpu) 26491228Sandrei { 26501228Sandrei ASSERT(cpuid_checkpass(cpu, 1)); 26511228Sandrei return (cpu->cpu_m.mcpu_cpi->cpi_coreid); 26521228Sandrei } 26531228Sandrei 26540Sstevel@tonic-gate int 26555870Sgavinm cpuid_get_pkgcoreid(cpu_t *cpu) 26565870Sgavinm { 26575870Sgavinm ASSERT(cpuid_checkpass(cpu, 1)); 26585870Sgavinm return (cpu->cpu_m.mcpu_cpi->cpi_pkgcoreid); 26595870Sgavinm } 26605870Sgavinm 26615870Sgavinm int 26623434Sesaxe cpuid_get_clogid(cpu_t *cpu) 26630Sstevel@tonic-gate { 26640Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 26650Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_clogid); 26660Sstevel@tonic-gate } 26670Sstevel@tonic-gate 2668*10947SSrihari.Venkatesan@Sun.COM uint_t 2669*10947SSrihari.Venkatesan@Sun.COM cpuid_get_procnodeid(cpu_t *cpu) 2670*10947SSrihari.Venkatesan@Sun.COM { 2671*10947SSrihari.Venkatesan@Sun.COM ASSERT(cpuid_checkpass(cpu, 1)); 2672*10947SSrihari.Venkatesan@Sun.COM return (cpu->cpu_m.mcpu_cpi->cpi_procnodeid); 2673*10947SSrihari.Venkatesan@Sun.COM } 2674*10947SSrihari.Venkatesan@Sun.COM 2675*10947SSrihari.Venkatesan@Sun.COM uint_t 2676*10947SSrihari.Venkatesan@Sun.COM cpuid_get_procnodes_per_pkg(cpu_t *cpu) 2677*10947SSrihari.Venkatesan@Sun.COM { 2678*10947SSrihari.Venkatesan@Sun.COM ASSERT(cpuid_checkpass(cpu, 1)); 2679*10947SSrihari.Venkatesan@Sun.COM return (cpu->cpu_m.mcpu_cpi->cpi_procnodes_per_pkg); 2680*10947SSrihari.Venkatesan@Sun.COM } 2681*10947SSrihari.Venkatesan@Sun.COM 268210080SJoe.Bonasera@sun.com /*ARGSUSED*/ 268310080SJoe.Bonasera@sun.com int 268410080SJoe.Bonasera@sun.com cpuid_have_cr8access(cpu_t *cpu) 268510080SJoe.Bonasera@sun.com { 268610080SJoe.Bonasera@sun.com #if defined(__amd64) 268710080SJoe.Bonasera@sun.com return (1); 268810080SJoe.Bonasera@sun.com #else 268910080SJoe.Bonasera@sun.com struct cpuid_info *cpi; 269010080SJoe.Bonasera@sun.com 269110080SJoe.Bonasera@sun.com ASSERT(cpu != NULL); 269210080SJoe.Bonasera@sun.com cpi = cpu->cpu_m.mcpu_cpi; 269310080SJoe.Bonasera@sun.com if (cpi->cpi_vendor == X86_VENDOR_AMD && cpi->cpi_maxeax >= 1 && 269410080SJoe.Bonasera@sun.com (CPI_FEATURES_XTD_ECX(cpi) & CPUID_AMD_ECX_CR8D) != 0) 269510080SJoe.Bonasera@sun.com return (1); 269610080SJoe.Bonasera@sun.com return (0); 269710080SJoe.Bonasera@sun.com #endif 269810080SJoe.Bonasera@sun.com } 269910080SJoe.Bonasera@sun.com 27009652SMichael.Corcoran@Sun.COM uint32_t 27019652SMichael.Corcoran@Sun.COM cpuid_get_apicid(cpu_t *cpu) 27029652SMichael.Corcoran@Sun.COM { 27039652SMichael.Corcoran@Sun.COM ASSERT(cpuid_checkpass(cpu, 1)); 27049652SMichael.Corcoran@Sun.COM if (cpu->cpu_m.mcpu_cpi->cpi_maxeax < 1) { 27059652SMichael.Corcoran@Sun.COM return (UINT32_MAX); 27069652SMichael.Corcoran@Sun.COM } else { 27079652SMichael.Corcoran@Sun.COM return (cpu->cpu_m.mcpu_cpi->cpi_apicid); 27089652SMichael.Corcoran@Sun.COM } 27099652SMichael.Corcoran@Sun.COM } 27109652SMichael.Corcoran@Sun.COM 27110Sstevel@tonic-gate void 27120Sstevel@tonic-gate cpuid_get_addrsize(cpu_t *cpu, uint_t *pabits, uint_t *vabits) 27130Sstevel@tonic-gate { 27140Sstevel@tonic-gate struct cpuid_info *cpi; 27150Sstevel@tonic-gate 27160Sstevel@tonic-gate if (cpu == NULL) 27170Sstevel@tonic-gate cpu = CPU; 27180Sstevel@tonic-gate cpi = cpu->cpu_m.mcpu_cpi; 27190Sstevel@tonic-gate 27200Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 27210Sstevel@tonic-gate 27220Sstevel@tonic-gate if (pabits) 27230Sstevel@tonic-gate *pabits = cpi->cpi_pabits; 27240Sstevel@tonic-gate if (vabits) 27250Sstevel@tonic-gate *vabits = cpi->cpi_vabits; 27260Sstevel@tonic-gate } 27270Sstevel@tonic-gate 27280Sstevel@tonic-gate /* 27290Sstevel@tonic-gate * Returns the number of data TLB entries for a corresponding 27300Sstevel@tonic-gate * pagesize. If it can't be computed, or isn't known, the 27310Sstevel@tonic-gate * routine returns zero. If you ask about an architecturally 27320Sstevel@tonic-gate * impossible pagesize, the routine will panic (so that the 27330Sstevel@tonic-gate * hat implementor knows that things are inconsistent.) 27340Sstevel@tonic-gate */ 27350Sstevel@tonic-gate uint_t 27360Sstevel@tonic-gate cpuid_get_dtlb_nent(cpu_t *cpu, size_t pagesize) 27370Sstevel@tonic-gate { 27380Sstevel@tonic-gate struct cpuid_info *cpi; 27390Sstevel@tonic-gate uint_t dtlb_nent = 0; 27400Sstevel@tonic-gate 27410Sstevel@tonic-gate if (cpu == NULL) 27420Sstevel@tonic-gate cpu = CPU; 27430Sstevel@tonic-gate cpi = cpu->cpu_m.mcpu_cpi; 27440Sstevel@tonic-gate 27450Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 27460Sstevel@tonic-gate 27470Sstevel@tonic-gate /* 27480Sstevel@tonic-gate * Check the L2 TLB info 27490Sstevel@tonic-gate */ 27500Sstevel@tonic-gate if (cpi->cpi_xmaxeax >= 0x80000006) { 27511228Sandrei struct cpuid_regs *cp = &cpi->cpi_extd[6]; 27520Sstevel@tonic-gate 27530Sstevel@tonic-gate switch (pagesize) { 27540Sstevel@tonic-gate 27550Sstevel@tonic-gate case 4 * 1024: 27560Sstevel@tonic-gate /* 27570Sstevel@tonic-gate * All zero in the top 16 bits of the register 27580Sstevel@tonic-gate * indicates a unified TLB. Size is in low 16 bits. 27590Sstevel@tonic-gate */ 27600Sstevel@tonic-gate if ((cp->cp_ebx & 0xffff0000) == 0) 27610Sstevel@tonic-gate dtlb_nent = cp->cp_ebx & 0x0000ffff; 27620Sstevel@tonic-gate else 27630Sstevel@tonic-gate dtlb_nent = BITX(cp->cp_ebx, 27, 16); 27640Sstevel@tonic-gate break; 27650Sstevel@tonic-gate 27660Sstevel@tonic-gate case 2 * 1024 * 1024: 27670Sstevel@tonic-gate if ((cp->cp_eax & 0xffff0000) == 0) 27680Sstevel@tonic-gate dtlb_nent = cp->cp_eax & 0x0000ffff; 27690Sstevel@tonic-gate else 27700Sstevel@tonic-gate dtlb_nent = BITX(cp->cp_eax, 27, 16); 27710Sstevel@tonic-gate break; 27720Sstevel@tonic-gate 27730Sstevel@tonic-gate default: 27740Sstevel@tonic-gate panic("unknown L2 pagesize"); 27750Sstevel@tonic-gate /*NOTREACHED*/ 27760Sstevel@tonic-gate } 27770Sstevel@tonic-gate } 27780Sstevel@tonic-gate 27790Sstevel@tonic-gate if (dtlb_nent != 0) 27800Sstevel@tonic-gate return (dtlb_nent); 27810Sstevel@tonic-gate 27820Sstevel@tonic-gate /* 27830Sstevel@tonic-gate * No L2 TLB support for this size, try L1. 27840Sstevel@tonic-gate */ 27850Sstevel@tonic-gate if (cpi->cpi_xmaxeax >= 0x80000005) { 27861228Sandrei struct cpuid_regs *cp = &cpi->cpi_extd[5]; 27870Sstevel@tonic-gate 27880Sstevel@tonic-gate switch (pagesize) { 27890Sstevel@tonic-gate case 4 * 1024: 27900Sstevel@tonic-gate dtlb_nent = BITX(cp->cp_ebx, 23, 16); 27910Sstevel@tonic-gate break; 27920Sstevel@tonic-gate case 2 * 1024 * 1024: 27930Sstevel@tonic-gate dtlb_nent = BITX(cp->cp_eax, 23, 16); 27940Sstevel@tonic-gate break; 27950Sstevel@tonic-gate default: 27960Sstevel@tonic-gate panic("unknown L1 d-TLB pagesize"); 27970Sstevel@tonic-gate /*NOTREACHED*/ 27980Sstevel@tonic-gate } 27990Sstevel@tonic-gate } 28000Sstevel@tonic-gate 28010Sstevel@tonic-gate return (dtlb_nent); 28020Sstevel@tonic-gate } 28030Sstevel@tonic-gate 28040Sstevel@tonic-gate /* 28050Sstevel@tonic-gate * Return 0 if the erratum is not present or not applicable, positive 28060Sstevel@tonic-gate * if it is, and negative if the status of the erratum is unknown. 28070Sstevel@tonic-gate * 28080Sstevel@tonic-gate * See "Revision Guide for AMD Athlon(tm) 64 and AMD Opteron(tm) 2809359Skucharsk * Processors" #25759, Rev 3.57, August 2005 28100Sstevel@tonic-gate */ 28110Sstevel@tonic-gate int 28120Sstevel@tonic-gate cpuid_opteron_erratum(cpu_t *cpu, uint_t erratum) 28130Sstevel@tonic-gate { 28140Sstevel@tonic-gate struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 28151228Sandrei uint_t eax; 28160Sstevel@tonic-gate 28172584Ssethg /* 28182584Ssethg * Bail out if this CPU isn't an AMD CPU, or if it's 28192584Ssethg * a legacy (32-bit) AMD CPU. 28202584Ssethg */ 28212584Ssethg if (cpi->cpi_vendor != X86_VENDOR_AMD || 28224265Skchow cpi->cpi_family == 4 || cpi->cpi_family == 5 || 28234265Skchow cpi->cpi_family == 6) 28242869Sgavinm 28250Sstevel@tonic-gate return (0); 28260Sstevel@tonic-gate 28270Sstevel@tonic-gate eax = cpi->cpi_std[1].cp_eax; 28280Sstevel@tonic-gate 28290Sstevel@tonic-gate #define SH_B0(eax) (eax == 0xf40 || eax == 0xf50) 28300Sstevel@tonic-gate #define SH_B3(eax) (eax == 0xf51) 28311582Skchow #define B(eax) (SH_B0(eax) || SH_B3(eax)) 28320Sstevel@tonic-gate 28330Sstevel@tonic-gate #define SH_C0(eax) (eax == 0xf48 || eax == 0xf58) 28340Sstevel@tonic-gate 28350Sstevel@tonic-gate #define SH_CG(eax) (eax == 0xf4a || eax == 0xf5a || eax == 0xf7a) 28360Sstevel@tonic-gate #define DH_CG(eax) (eax == 0xfc0 || eax == 0xfe0 || eax == 0xff0) 28370Sstevel@tonic-gate #define CH_CG(eax) (eax == 0xf82 || eax == 0xfb2) 28381582Skchow #define CG(eax) (SH_CG(eax) || DH_CG(eax) || CH_CG(eax)) 28390Sstevel@tonic-gate 28400Sstevel@tonic-gate #define SH_D0(eax) (eax == 0x10f40 || eax == 0x10f50 || eax == 0x10f70) 28410Sstevel@tonic-gate #define DH_D0(eax) (eax == 0x10fc0 || eax == 0x10ff0) 28420Sstevel@tonic-gate #define CH_D0(eax) (eax == 0x10f80 || eax == 0x10fb0) 28431582Skchow #define D0(eax) (SH_D0(eax) || DH_D0(eax) || CH_D0(eax)) 28440Sstevel@tonic-gate 28450Sstevel@tonic-gate #define SH_E0(eax) (eax == 0x20f50 || eax == 0x20f40 || eax == 0x20f70) 28460Sstevel@tonic-gate #define JH_E1(eax) (eax == 0x20f10) /* JH8_E0 had 0x20f30 */ 28470Sstevel@tonic-gate #define DH_E3(eax) (eax == 0x20fc0 || eax == 0x20ff0) 28480Sstevel@tonic-gate #define SH_E4(eax) (eax == 0x20f51 || eax == 0x20f71) 28490Sstevel@tonic-gate #define BH_E4(eax) (eax == 0x20fb1) 28500Sstevel@tonic-gate #define SH_E5(eax) (eax == 0x20f42) 28510Sstevel@tonic-gate #define DH_E6(eax) (eax == 0x20ff2 || eax == 0x20fc2) 28520Sstevel@tonic-gate #define JH_E6(eax) (eax == 0x20f12 || eax == 0x20f32) 28531582Skchow #define EX(eax) (SH_E0(eax) || JH_E1(eax) || DH_E3(eax) || \ 28541582Skchow SH_E4(eax) || BH_E4(eax) || SH_E5(eax) || \ 28551582Skchow DH_E6(eax) || JH_E6(eax)) 28560Sstevel@tonic-gate 28576691Skchow #define DR_AX(eax) (eax == 0x100f00 || eax == 0x100f01 || eax == 0x100f02) 28586691Skchow #define DR_B0(eax) (eax == 0x100f20) 28596691Skchow #define DR_B1(eax) (eax == 0x100f21) 28606691Skchow #define DR_BA(eax) (eax == 0x100f2a) 28616691Skchow #define DR_B2(eax) (eax == 0x100f22) 28626691Skchow #define DR_B3(eax) (eax == 0x100f23) 28636691Skchow #define RB_C0(eax) (eax == 0x100f40) 28646691Skchow 28650Sstevel@tonic-gate switch (erratum) { 28660Sstevel@tonic-gate case 1: 28674265Skchow return (cpi->cpi_family < 0x10); 28680Sstevel@tonic-gate case 51: /* what does the asterisk mean? */ 28690Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax)); 28700Sstevel@tonic-gate case 52: 28710Sstevel@tonic-gate return (B(eax)); 28720Sstevel@tonic-gate case 57: 28736691Skchow return (cpi->cpi_family <= 0x11); 28740Sstevel@tonic-gate case 58: 28750Sstevel@tonic-gate return (B(eax)); 28760Sstevel@tonic-gate case 60: 28776691Skchow return (cpi->cpi_family <= 0x11); 28780Sstevel@tonic-gate case 61: 28790Sstevel@tonic-gate case 62: 28800Sstevel@tonic-gate case 63: 28810Sstevel@tonic-gate case 64: 28820Sstevel@tonic-gate case 65: 28830Sstevel@tonic-gate case 66: 28840Sstevel@tonic-gate case 68: 28850Sstevel@tonic-gate case 69: 28860Sstevel@tonic-gate case 70: 28870Sstevel@tonic-gate case 71: 28880Sstevel@tonic-gate return (B(eax)); 28890Sstevel@tonic-gate case 72: 28900Sstevel@tonic-gate return (SH_B0(eax)); 28910Sstevel@tonic-gate case 74: 28920Sstevel@tonic-gate return (B(eax)); 28930Sstevel@tonic-gate case 75: 28944265Skchow return (cpi->cpi_family < 0x10); 28950Sstevel@tonic-gate case 76: 28960Sstevel@tonic-gate return (B(eax)); 28970Sstevel@tonic-gate case 77: 28986691Skchow return (cpi->cpi_family <= 0x11); 28990Sstevel@tonic-gate case 78: 29000Sstevel@tonic-gate return (B(eax) || SH_C0(eax)); 29010Sstevel@tonic-gate case 79: 29020Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax) || EX(eax)); 29030Sstevel@tonic-gate case 80: 29040Sstevel@tonic-gate case 81: 29050Sstevel@tonic-gate case 82: 29060Sstevel@tonic-gate return (B(eax)); 29070Sstevel@tonic-gate case 83: 29080Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax)); 29090Sstevel@tonic-gate case 85: 29104265Skchow return (cpi->cpi_family < 0x10); 29110Sstevel@tonic-gate case 86: 29120Sstevel@tonic-gate return (SH_C0(eax) || CG(eax)); 29130Sstevel@tonic-gate case 88: 29140Sstevel@tonic-gate #if !defined(__amd64) 29150Sstevel@tonic-gate return (0); 29160Sstevel@tonic-gate #else 29170Sstevel@tonic-gate return (B(eax) || SH_C0(eax)); 29180Sstevel@tonic-gate #endif 29190Sstevel@tonic-gate case 89: 29204265Skchow return (cpi->cpi_family < 0x10); 29210Sstevel@tonic-gate case 90: 29220Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax)); 29230Sstevel@tonic-gate case 91: 29240Sstevel@tonic-gate case 92: 29250Sstevel@tonic-gate return (B(eax) || SH_C0(eax)); 29260Sstevel@tonic-gate case 93: 29270Sstevel@tonic-gate return (SH_C0(eax)); 29280Sstevel@tonic-gate case 94: 29290Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax)); 29300Sstevel@tonic-gate case 95: 29310Sstevel@tonic-gate #if !defined(__amd64) 29320Sstevel@tonic-gate return (0); 29330Sstevel@tonic-gate #else 29340Sstevel@tonic-gate return (B(eax) || SH_C0(eax)); 29350Sstevel@tonic-gate #endif 29360Sstevel@tonic-gate case 96: 29370Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax)); 29380Sstevel@tonic-gate case 97: 29390Sstevel@tonic-gate case 98: 29400Sstevel@tonic-gate return (SH_C0(eax) || CG(eax)); 29410Sstevel@tonic-gate case 99: 29420Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax)); 29430Sstevel@tonic-gate case 100: 29440Sstevel@tonic-gate return (B(eax) || SH_C0(eax)); 29450Sstevel@tonic-gate case 101: 29460Sstevel@tonic-gate case 103: 29470Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax)); 29480Sstevel@tonic-gate case 104: 29490Sstevel@tonic-gate return (SH_C0(eax) || CG(eax) || D0(eax)); 29500Sstevel@tonic-gate case 105: 29510Sstevel@tonic-gate case 106: 29520Sstevel@tonic-gate case 107: 29530Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax)); 29540Sstevel@tonic-gate case 108: 29550Sstevel@tonic-gate return (DH_CG(eax)); 29560Sstevel@tonic-gate case 109: 29570Sstevel@tonic-gate return (SH_C0(eax) || CG(eax) || D0(eax)); 29580Sstevel@tonic-gate case 110: 29590Sstevel@tonic-gate return (D0(eax) || EX(eax)); 29600Sstevel@tonic-gate case 111: 29610Sstevel@tonic-gate return (CG(eax)); 29620Sstevel@tonic-gate case 112: 29630Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax) || EX(eax)); 29640Sstevel@tonic-gate case 113: 29650Sstevel@tonic-gate return (eax == 0x20fc0); 29660Sstevel@tonic-gate case 114: 29670Sstevel@tonic-gate return (SH_E0(eax) || JH_E1(eax) || DH_E3(eax)); 29680Sstevel@tonic-gate case 115: 29690Sstevel@tonic-gate return (SH_E0(eax) || JH_E1(eax)); 29700Sstevel@tonic-gate case 116: 29710Sstevel@tonic-gate return (SH_E0(eax) || JH_E1(eax) || DH_E3(eax)); 29720Sstevel@tonic-gate case 117: 29730Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax)); 29740Sstevel@tonic-gate case 118: 29750Sstevel@tonic-gate return (SH_E0(eax) || JH_E1(eax) || SH_E4(eax) || BH_E4(eax) || 29760Sstevel@tonic-gate JH_E6(eax)); 29770Sstevel@tonic-gate case 121: 29780Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax) || EX(eax)); 29790Sstevel@tonic-gate case 122: 29806691Skchow return (cpi->cpi_family < 0x10 || cpi->cpi_family == 0x11); 29810Sstevel@tonic-gate case 123: 29820Sstevel@tonic-gate return (JH_E1(eax) || BH_E4(eax) || JH_E6(eax)); 2983359Skucharsk case 131: 29844265Skchow return (cpi->cpi_family < 0x10); 2985938Sesaxe case 6336786: 2986938Sesaxe /* 2987938Sesaxe * Test for AdvPowerMgmtInfo.TscPStateInvariant 29884265Skchow * if this is a K8 family or newer processor 2989938Sesaxe */ 2990938Sesaxe if (CPI_FAMILY(cpi) == 0xf) { 29911228Sandrei struct cpuid_regs regs; 29921228Sandrei regs.cp_eax = 0x80000007; 29931228Sandrei (void) __cpuid_insn(®s); 29941228Sandrei return (!(regs.cp_edx & 0x100)); 2995938Sesaxe } 2996938Sesaxe return (0); 29971582Skchow case 6323525: 29981582Skchow return (((((eax >> 12) & 0xff00) + (eax & 0xf00)) | 29991582Skchow (((eax >> 4) & 0xf) | ((eax >> 12) & 0xf0))) < 0xf40); 30001582Skchow 30016691Skchow case 6671130: 30026691Skchow /* 30036691Skchow * check for processors (pre-Shanghai) that do not provide 30046691Skchow * optimal management of 1gb ptes in its tlb. 30056691Skchow */ 30066691Skchow return (cpi->cpi_family == 0x10 && cpi->cpi_model < 4); 30076691Skchow 30086691Skchow case 298: 30096691Skchow return (DR_AX(eax) || DR_B0(eax) || DR_B1(eax) || DR_BA(eax) || 30106691Skchow DR_B2(eax) || RB_C0(eax)); 30116691Skchow 30126691Skchow default: 30136691Skchow return (-1); 30146691Skchow 30156691Skchow } 30166691Skchow } 30176691Skchow 30186691Skchow /* 30196691Skchow * Determine if specified erratum is present via OSVW (OS Visible Workaround). 30206691Skchow * Return 1 if erratum is present, 0 if not present and -1 if indeterminate. 30216691Skchow */ 30226691Skchow int 30236691Skchow osvw_opteron_erratum(cpu_t *cpu, uint_t erratum) 30246691Skchow { 30256691Skchow struct cpuid_info *cpi; 30266691Skchow uint_t osvwid; 30276691Skchow static int osvwfeature = -1; 30286691Skchow uint64_t osvwlength; 30296691Skchow 30306691Skchow 30316691Skchow cpi = cpu->cpu_m.mcpu_cpi; 30326691Skchow 30336691Skchow /* confirm OSVW supported */ 30346691Skchow if (osvwfeature == -1) { 30356691Skchow osvwfeature = cpi->cpi_extd[1].cp_ecx & CPUID_AMD_ECX_OSVW; 30366691Skchow } else { 30376691Skchow /* assert that osvw feature setting is consistent on all cpus */ 30386691Skchow ASSERT(osvwfeature == 30396691Skchow (cpi->cpi_extd[1].cp_ecx & CPUID_AMD_ECX_OSVW)); 30406691Skchow } 30416691Skchow if (!osvwfeature) 30426691Skchow return (-1); 30436691Skchow 30446691Skchow osvwlength = rdmsr(MSR_AMD_OSVW_ID_LEN) & OSVW_ID_LEN_MASK; 30456691Skchow 30466691Skchow switch (erratum) { 30476691Skchow case 298: /* osvwid is 0 */ 30486691Skchow osvwid = 0; 30496691Skchow if (osvwlength <= (uint64_t)osvwid) { 30506691Skchow /* osvwid 0 is unknown */ 30516691Skchow return (-1); 30526691Skchow } 30536691Skchow 30546691Skchow /* 30556691Skchow * Check the OSVW STATUS MSR to determine the state 30566691Skchow * of the erratum where: 30576691Skchow * 0 - fixed by HW 30586691Skchow * 1 - BIOS has applied the workaround when BIOS 30596691Skchow * workaround is available. (Or for other errata, 30606691Skchow * OS workaround is required.) 30616691Skchow * For a value of 1, caller will confirm that the 30626691Skchow * erratum 298 workaround has indeed been applied by BIOS. 30636691Skchow * 30646691Skchow * A 1 may be set in cpus that have a HW fix 30656691Skchow * in a mixed cpu system. Regarding erratum 298: 30666691Skchow * In a multiprocessor platform, the workaround above 30676691Skchow * should be applied to all processors regardless of 30686691Skchow * silicon revision when an affected processor is 30696691Skchow * present. 30706691Skchow */ 30716691Skchow 30726691Skchow return (rdmsr(MSR_AMD_OSVW_STATUS + 30736691Skchow (osvwid / OSVW_ID_CNT_PER_MSR)) & 30746691Skchow (1ULL << (osvwid % OSVW_ID_CNT_PER_MSR))); 30756691Skchow 30760Sstevel@tonic-gate default: 30770Sstevel@tonic-gate return (-1); 30780Sstevel@tonic-gate } 30790Sstevel@tonic-gate } 30800Sstevel@tonic-gate 30810Sstevel@tonic-gate static const char assoc_str[] = "associativity"; 30820Sstevel@tonic-gate static const char line_str[] = "line-size"; 30830Sstevel@tonic-gate static const char size_str[] = "size"; 30840Sstevel@tonic-gate 30850Sstevel@tonic-gate static void 30860Sstevel@tonic-gate add_cache_prop(dev_info_t *devi, const char *label, const char *type, 30870Sstevel@tonic-gate uint32_t val) 30880Sstevel@tonic-gate { 30890Sstevel@tonic-gate char buf[128]; 30900Sstevel@tonic-gate 30910Sstevel@tonic-gate /* 30920Sstevel@tonic-gate * ndi_prop_update_int() is used because it is desirable for 30930Sstevel@tonic-gate * DDI_PROP_HW_DEF and DDI_PROP_DONTSLEEP to be set. 30940Sstevel@tonic-gate */ 30950Sstevel@tonic-gate if (snprintf(buf, sizeof (buf), "%s-%s", label, type) < sizeof (buf)) 30960Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, devi, buf, val); 30970Sstevel@tonic-gate } 30980Sstevel@tonic-gate 30990Sstevel@tonic-gate /* 31000Sstevel@tonic-gate * Intel-style cache/tlb description 31010Sstevel@tonic-gate * 31020Sstevel@tonic-gate * Standard cpuid level 2 gives a randomly ordered 31030Sstevel@tonic-gate * selection of tags that index into a table that describes 31040Sstevel@tonic-gate * cache and tlb properties. 31050Sstevel@tonic-gate */ 31060Sstevel@tonic-gate 31070Sstevel@tonic-gate static const char l1_icache_str[] = "l1-icache"; 31080Sstevel@tonic-gate static const char l1_dcache_str[] = "l1-dcache"; 31090Sstevel@tonic-gate static const char l2_cache_str[] = "l2-cache"; 31103446Smrj static const char l3_cache_str[] = "l3-cache"; 31110Sstevel@tonic-gate static const char itlb4k_str[] = "itlb-4K"; 31120Sstevel@tonic-gate static const char dtlb4k_str[] = "dtlb-4K"; 31136964Svd224797 static const char itlb2M_str[] = "itlb-2M"; 31140Sstevel@tonic-gate static const char itlb4M_str[] = "itlb-4M"; 31150Sstevel@tonic-gate static const char dtlb4M_str[] = "dtlb-4M"; 31166334Sksadhukh static const char dtlb24_str[] = "dtlb0-2M-4M"; 31170Sstevel@tonic-gate static const char itlb424_str[] = "itlb-4K-2M-4M"; 31186334Sksadhukh static const char itlb24_str[] = "itlb-2M-4M"; 31190Sstevel@tonic-gate static const char dtlb44_str[] = "dtlb-4K-4M"; 31200Sstevel@tonic-gate static const char sl1_dcache_str[] = "sectored-l1-dcache"; 31210Sstevel@tonic-gate static const char sl2_cache_str[] = "sectored-l2-cache"; 31220Sstevel@tonic-gate static const char itrace_str[] = "itrace-cache"; 31230Sstevel@tonic-gate static const char sl3_cache_str[] = "sectored-l3-cache"; 31246334Sksadhukh static const char sh_l2_tlb4k_str[] = "shared-l2-tlb-4k"; 31250Sstevel@tonic-gate 31260Sstevel@tonic-gate static const struct cachetab { 31270Sstevel@tonic-gate uint8_t ct_code; 31280Sstevel@tonic-gate uint8_t ct_assoc; 31290Sstevel@tonic-gate uint16_t ct_line_size; 31300Sstevel@tonic-gate size_t ct_size; 31310Sstevel@tonic-gate const char *ct_label; 31320Sstevel@tonic-gate } intel_ctab[] = { 31336964Svd224797 /* 31346964Svd224797 * maintain descending order! 31356964Svd224797 * 31366964Svd224797 * Codes ignored - Reason 31376964Svd224797 * ---------------------- 31386964Svd224797 * 40H - intel_cpuid_4_cache_info() disambiguates l2/l3 cache 31396964Svd224797 * f0H/f1H - Currently we do not interpret prefetch size by design 31406964Svd224797 */ 31416334Sksadhukh { 0xe4, 16, 64, 8*1024*1024, l3_cache_str}, 31426334Sksadhukh { 0xe3, 16, 64, 4*1024*1024, l3_cache_str}, 31436334Sksadhukh { 0xe2, 16, 64, 2*1024*1024, l3_cache_str}, 31446334Sksadhukh { 0xde, 12, 64, 6*1024*1024, l3_cache_str}, 31456334Sksadhukh { 0xdd, 12, 64, 3*1024*1024, l3_cache_str}, 31466334Sksadhukh { 0xdc, 12, 64, ((1*1024*1024)+(512*1024)), l3_cache_str}, 31476334Sksadhukh { 0xd8, 8, 64, 4*1024*1024, l3_cache_str}, 31486334Sksadhukh { 0xd7, 8, 64, 2*1024*1024, l3_cache_str}, 31496334Sksadhukh { 0xd6, 8, 64, 1*1024*1024, l3_cache_str}, 31506334Sksadhukh { 0xd2, 4, 64, 2*1024*1024, l3_cache_str}, 31516334Sksadhukh { 0xd1, 4, 64, 1*1024*1024, l3_cache_str}, 31526334Sksadhukh { 0xd0, 4, 64, 512*1024, l3_cache_str}, 31536334Sksadhukh { 0xca, 4, 0, 512, sh_l2_tlb4k_str}, 31546964Svd224797 { 0xc0, 4, 0, 8, dtlb44_str }, 31556964Svd224797 { 0xba, 4, 0, 64, dtlb4k_str }, 31563446Smrj { 0xb4, 4, 0, 256, dtlb4k_str }, 31570Sstevel@tonic-gate { 0xb3, 4, 0, 128, dtlb4k_str }, 31586334Sksadhukh { 0xb2, 4, 0, 64, itlb4k_str }, 31590Sstevel@tonic-gate { 0xb0, 4, 0, 128, itlb4k_str }, 31600Sstevel@tonic-gate { 0x87, 8, 64, 1024*1024, l2_cache_str}, 31610Sstevel@tonic-gate { 0x86, 4, 64, 512*1024, l2_cache_str}, 31620Sstevel@tonic-gate { 0x85, 8, 32, 2*1024*1024, l2_cache_str}, 31630Sstevel@tonic-gate { 0x84, 8, 32, 1024*1024, l2_cache_str}, 31640Sstevel@tonic-gate { 0x83, 8, 32, 512*1024, l2_cache_str}, 31650Sstevel@tonic-gate { 0x82, 8, 32, 256*1024, l2_cache_str}, 31666964Svd224797 { 0x80, 8, 64, 512*1024, l2_cache_str}, 31670Sstevel@tonic-gate { 0x7f, 2, 64, 512*1024, l2_cache_str}, 31680Sstevel@tonic-gate { 0x7d, 8, 64, 2*1024*1024, sl2_cache_str}, 31690Sstevel@tonic-gate { 0x7c, 8, 64, 1024*1024, sl2_cache_str}, 31700Sstevel@tonic-gate { 0x7b, 8, 64, 512*1024, sl2_cache_str}, 31710Sstevel@tonic-gate { 0x7a, 8, 64, 256*1024, sl2_cache_str}, 31720Sstevel@tonic-gate { 0x79, 8, 64, 128*1024, sl2_cache_str}, 31730Sstevel@tonic-gate { 0x78, 8, 64, 1024*1024, l2_cache_str}, 31743446Smrj { 0x73, 8, 0, 64*1024, itrace_str}, 31750Sstevel@tonic-gate { 0x72, 8, 0, 32*1024, itrace_str}, 31760Sstevel@tonic-gate { 0x71, 8, 0, 16*1024, itrace_str}, 31770Sstevel@tonic-gate { 0x70, 8, 0, 12*1024, itrace_str}, 31780Sstevel@tonic-gate { 0x68, 4, 64, 32*1024, sl1_dcache_str}, 31790Sstevel@tonic-gate { 0x67, 4, 64, 16*1024, sl1_dcache_str}, 31800Sstevel@tonic-gate { 0x66, 4, 64, 8*1024, sl1_dcache_str}, 31810Sstevel@tonic-gate { 0x60, 8, 64, 16*1024, sl1_dcache_str}, 31820Sstevel@tonic-gate { 0x5d, 0, 0, 256, dtlb44_str}, 31830Sstevel@tonic-gate { 0x5c, 0, 0, 128, dtlb44_str}, 31840Sstevel@tonic-gate { 0x5b, 0, 0, 64, dtlb44_str}, 31856334Sksadhukh { 0x5a, 4, 0, 32, dtlb24_str}, 31866964Svd224797 { 0x59, 0, 0, 16, dtlb4k_str}, 31876964Svd224797 { 0x57, 4, 0, 16, dtlb4k_str}, 31886964Svd224797 { 0x56, 4, 0, 16, dtlb4M_str}, 31896334Sksadhukh { 0x55, 0, 0, 7, itlb24_str}, 31900Sstevel@tonic-gate { 0x52, 0, 0, 256, itlb424_str}, 31910Sstevel@tonic-gate { 0x51, 0, 0, 128, itlb424_str}, 31920Sstevel@tonic-gate { 0x50, 0, 0, 64, itlb424_str}, 31936964Svd224797 { 0x4f, 0, 0, 32, itlb4k_str}, 31946964Svd224797 { 0x4e, 24, 64, 6*1024*1024, l2_cache_str}, 31953446Smrj { 0x4d, 16, 64, 16*1024*1024, l3_cache_str}, 31963446Smrj { 0x4c, 12, 64, 12*1024*1024, l3_cache_str}, 31973446Smrj { 0x4b, 16, 64, 8*1024*1024, l3_cache_str}, 31983446Smrj { 0x4a, 12, 64, 6*1024*1024, l3_cache_str}, 31993446Smrj { 0x49, 16, 64, 4*1024*1024, l3_cache_str}, 32006964Svd224797 { 0x48, 12, 64, 3*1024*1024, l2_cache_str}, 32013446Smrj { 0x47, 8, 64, 8*1024*1024, l3_cache_str}, 32023446Smrj { 0x46, 4, 64, 4*1024*1024, l3_cache_str}, 32030Sstevel@tonic-gate { 0x45, 4, 32, 2*1024*1024, l2_cache_str}, 32040Sstevel@tonic-gate { 0x44, 4, 32, 1024*1024, l2_cache_str}, 32050Sstevel@tonic-gate { 0x43, 4, 32, 512*1024, l2_cache_str}, 32060Sstevel@tonic-gate { 0x42, 4, 32, 256*1024, l2_cache_str}, 32070Sstevel@tonic-gate { 0x41, 4, 32, 128*1024, l2_cache_str}, 32083446Smrj { 0x3e, 4, 64, 512*1024, sl2_cache_str}, 32093446Smrj { 0x3d, 6, 64, 384*1024, sl2_cache_str}, 32100Sstevel@tonic-gate { 0x3c, 4, 64, 256*1024, sl2_cache_str}, 32110Sstevel@tonic-gate { 0x3b, 2, 64, 128*1024, sl2_cache_str}, 32123446Smrj { 0x3a, 6, 64, 192*1024, sl2_cache_str}, 32130Sstevel@tonic-gate { 0x39, 4, 64, 128*1024, sl2_cache_str}, 32140Sstevel@tonic-gate { 0x30, 8, 64, 32*1024, l1_icache_str}, 32150Sstevel@tonic-gate { 0x2c, 8, 64, 32*1024, l1_dcache_str}, 32160Sstevel@tonic-gate { 0x29, 8, 64, 4096*1024, sl3_cache_str}, 32170Sstevel@tonic-gate { 0x25, 8, 64, 2048*1024, sl3_cache_str}, 32180Sstevel@tonic-gate { 0x23, 8, 64, 1024*1024, sl3_cache_str}, 32190Sstevel@tonic-gate { 0x22, 4, 64, 512*1024, sl3_cache_str}, 32206964Svd224797 { 0x0e, 6, 64, 24*1024, l1_dcache_str}, 32216334Sksadhukh { 0x0d, 4, 32, 16*1024, l1_dcache_str}, 32220Sstevel@tonic-gate { 0x0c, 4, 32, 16*1024, l1_dcache_str}, 32233446Smrj { 0x0b, 4, 0, 4, itlb4M_str}, 32240Sstevel@tonic-gate { 0x0a, 2, 32, 8*1024, l1_dcache_str}, 32250Sstevel@tonic-gate { 0x08, 4, 32, 16*1024, l1_icache_str}, 32260Sstevel@tonic-gate { 0x06, 4, 32, 8*1024, l1_icache_str}, 32276964Svd224797 { 0x05, 4, 0, 32, dtlb4M_str}, 32280Sstevel@tonic-gate { 0x04, 4, 0, 8, dtlb4M_str}, 32290Sstevel@tonic-gate { 0x03, 4, 0, 64, dtlb4k_str}, 32300Sstevel@tonic-gate { 0x02, 4, 0, 2, itlb4M_str}, 32310Sstevel@tonic-gate { 0x01, 4, 0, 32, itlb4k_str}, 32320Sstevel@tonic-gate { 0 } 32330Sstevel@tonic-gate }; 32340Sstevel@tonic-gate 32350Sstevel@tonic-gate static const struct cachetab cyrix_ctab[] = { 32360Sstevel@tonic-gate { 0x70, 4, 0, 32, "tlb-4K" }, 32370Sstevel@tonic-gate { 0x80, 4, 16, 16*1024, "l1-cache" }, 32380Sstevel@tonic-gate { 0 } 32390Sstevel@tonic-gate }; 32400Sstevel@tonic-gate 32410Sstevel@tonic-gate /* 32420Sstevel@tonic-gate * Search a cache table for a matching entry 32430Sstevel@tonic-gate */ 32440Sstevel@tonic-gate static const struct cachetab * 32450Sstevel@tonic-gate find_cacheent(const struct cachetab *ct, uint_t code) 32460Sstevel@tonic-gate { 32470Sstevel@tonic-gate if (code != 0) { 32480Sstevel@tonic-gate for (; ct->ct_code != 0; ct++) 32490Sstevel@tonic-gate if (ct->ct_code <= code) 32500Sstevel@tonic-gate break; 32510Sstevel@tonic-gate if (ct->ct_code == code) 32520Sstevel@tonic-gate return (ct); 32530Sstevel@tonic-gate } 32540Sstevel@tonic-gate return (NULL); 32550Sstevel@tonic-gate } 32560Sstevel@tonic-gate 32570Sstevel@tonic-gate /* 32585438Sksadhukh * Populate cachetab entry with L2 or L3 cache-information using 32595438Sksadhukh * cpuid function 4. This function is called from intel_walk_cacheinfo() 32605438Sksadhukh * when descriptor 0x49 is encountered. It returns 0 if no such cache 32615438Sksadhukh * information is found. 32625438Sksadhukh */ 32635438Sksadhukh static int 32645438Sksadhukh intel_cpuid_4_cache_info(struct cachetab *ct, struct cpuid_info *cpi) 32655438Sksadhukh { 32665438Sksadhukh uint32_t level, i; 32675438Sksadhukh int ret = 0; 32685438Sksadhukh 32695438Sksadhukh for (i = 0; i < cpi->cpi_std_4_size; i++) { 32705438Sksadhukh level = CPI_CACHE_LVL(cpi->cpi_std_4[i]); 32715438Sksadhukh 32725438Sksadhukh if (level == 2 || level == 3) { 32735438Sksadhukh ct->ct_assoc = CPI_CACHE_WAYS(cpi->cpi_std_4[i]) + 1; 32745438Sksadhukh ct->ct_line_size = 32755438Sksadhukh CPI_CACHE_COH_LN_SZ(cpi->cpi_std_4[i]) + 1; 32765438Sksadhukh ct->ct_size = ct->ct_assoc * 32775438Sksadhukh (CPI_CACHE_PARTS(cpi->cpi_std_4[i]) + 1) * 32785438Sksadhukh ct->ct_line_size * 32795438Sksadhukh (cpi->cpi_std_4[i]->cp_ecx + 1); 32805438Sksadhukh 32815438Sksadhukh if (level == 2) { 32825438Sksadhukh ct->ct_label = l2_cache_str; 32835438Sksadhukh } else if (level == 3) { 32845438Sksadhukh ct->ct_label = l3_cache_str; 32855438Sksadhukh } 32865438Sksadhukh ret = 1; 32875438Sksadhukh } 32885438Sksadhukh } 32895438Sksadhukh 32905438Sksadhukh return (ret); 32915438Sksadhukh } 32925438Sksadhukh 32935438Sksadhukh /* 32940Sstevel@tonic-gate * Walk the cacheinfo descriptor, applying 'func' to every valid element 32950Sstevel@tonic-gate * The walk is terminated if the walker returns non-zero. 32960Sstevel@tonic-gate */ 32970Sstevel@tonic-gate static void 32980Sstevel@tonic-gate intel_walk_cacheinfo(struct cpuid_info *cpi, 32990Sstevel@tonic-gate void *arg, int (*func)(void *, const struct cachetab *)) 33000Sstevel@tonic-gate { 33010Sstevel@tonic-gate const struct cachetab *ct; 33026964Svd224797 struct cachetab des_49_ct, des_b1_ct; 33030Sstevel@tonic-gate uint8_t *dp; 33040Sstevel@tonic-gate int i; 33050Sstevel@tonic-gate 33060Sstevel@tonic-gate if ((dp = cpi->cpi_cacheinfo) == NULL) 33070Sstevel@tonic-gate return; 33084797Sksadhukh for (i = 0; i < cpi->cpi_ncache; i++, dp++) { 33094797Sksadhukh /* 33104797Sksadhukh * For overloaded descriptor 0x49 we use cpuid function 4 33115438Sksadhukh * if supported by the current processor, to create 33124797Sksadhukh * cache information. 33136964Svd224797 * For overloaded descriptor 0xb1 we use X86_PAE flag 33146964Svd224797 * to disambiguate the cache information. 33154797Sksadhukh */ 33165438Sksadhukh if (*dp == 0x49 && cpi->cpi_maxeax >= 0x4 && 33175438Sksadhukh intel_cpuid_4_cache_info(&des_49_ct, cpi) == 1) { 33185438Sksadhukh ct = &des_49_ct; 33196964Svd224797 } else if (*dp == 0xb1) { 33206964Svd224797 des_b1_ct.ct_code = 0xb1; 33216964Svd224797 des_b1_ct.ct_assoc = 4; 33226964Svd224797 des_b1_ct.ct_line_size = 0; 33236964Svd224797 if (x86_feature & X86_PAE) { 33246964Svd224797 des_b1_ct.ct_size = 8; 33256964Svd224797 des_b1_ct.ct_label = itlb2M_str; 33266964Svd224797 } else { 33276964Svd224797 des_b1_ct.ct_size = 4; 33286964Svd224797 des_b1_ct.ct_label = itlb4M_str; 33296964Svd224797 } 33306964Svd224797 ct = &des_b1_ct; 33315438Sksadhukh } else { 33325438Sksadhukh if ((ct = find_cacheent(intel_ctab, *dp)) == NULL) { 33335438Sksadhukh continue; 33345438Sksadhukh } 33354797Sksadhukh } 33364797Sksadhukh 33375438Sksadhukh if (func(arg, ct) != 0) { 33385438Sksadhukh break; 33390Sstevel@tonic-gate } 33404797Sksadhukh } 33410Sstevel@tonic-gate } 33420Sstevel@tonic-gate 33430Sstevel@tonic-gate /* 33440Sstevel@tonic-gate * (Like the Intel one, except for Cyrix CPUs) 33450Sstevel@tonic-gate */ 33460Sstevel@tonic-gate static void 33470Sstevel@tonic-gate cyrix_walk_cacheinfo(struct cpuid_info *cpi, 33480Sstevel@tonic-gate void *arg, int (*func)(void *, const struct cachetab *)) 33490Sstevel@tonic-gate { 33500Sstevel@tonic-gate const struct cachetab *ct; 33510Sstevel@tonic-gate uint8_t *dp; 33520Sstevel@tonic-gate int i; 33530Sstevel@tonic-gate 33540Sstevel@tonic-gate if ((dp = cpi->cpi_cacheinfo) == NULL) 33550Sstevel@tonic-gate return; 33560Sstevel@tonic-gate for (i = 0; i < cpi->cpi_ncache; i++, dp++) { 33570Sstevel@tonic-gate /* 33580Sstevel@tonic-gate * Search Cyrix-specific descriptor table first .. 33590Sstevel@tonic-gate */ 33600Sstevel@tonic-gate if ((ct = find_cacheent(cyrix_ctab, *dp)) != NULL) { 33610Sstevel@tonic-gate if (func(arg, ct) != 0) 33620Sstevel@tonic-gate break; 33630Sstevel@tonic-gate continue; 33640Sstevel@tonic-gate } 33650Sstevel@tonic-gate /* 33660Sstevel@tonic-gate * .. else fall back to the Intel one 33670Sstevel@tonic-gate */ 33680Sstevel@tonic-gate if ((ct = find_cacheent(intel_ctab, *dp)) != NULL) { 33690Sstevel@tonic-gate if (func(arg, ct) != 0) 33700Sstevel@tonic-gate break; 33710Sstevel@tonic-gate continue; 33720Sstevel@tonic-gate } 33730Sstevel@tonic-gate } 33740Sstevel@tonic-gate } 33750Sstevel@tonic-gate 33760Sstevel@tonic-gate /* 33770Sstevel@tonic-gate * A cacheinfo walker that adds associativity, line-size, and size properties 33780Sstevel@tonic-gate * to the devinfo node it is passed as an argument. 33790Sstevel@tonic-gate */ 33800Sstevel@tonic-gate static int 33810Sstevel@tonic-gate add_cacheent_props(void *arg, const struct cachetab *ct) 33820Sstevel@tonic-gate { 33830Sstevel@tonic-gate dev_info_t *devi = arg; 33840Sstevel@tonic-gate 33850Sstevel@tonic-gate add_cache_prop(devi, ct->ct_label, assoc_str, ct->ct_assoc); 33860Sstevel@tonic-gate if (ct->ct_line_size != 0) 33870Sstevel@tonic-gate add_cache_prop(devi, ct->ct_label, line_str, 33880Sstevel@tonic-gate ct->ct_line_size); 33890Sstevel@tonic-gate add_cache_prop(devi, ct->ct_label, size_str, ct->ct_size); 33900Sstevel@tonic-gate return (0); 33910Sstevel@tonic-gate } 33920Sstevel@tonic-gate 33934797Sksadhukh 33940Sstevel@tonic-gate static const char fully_assoc[] = "fully-associative?"; 33950Sstevel@tonic-gate 33960Sstevel@tonic-gate /* 33970Sstevel@tonic-gate * AMD style cache/tlb description 33980Sstevel@tonic-gate * 33990Sstevel@tonic-gate * Extended functions 5 and 6 directly describe properties of 34000Sstevel@tonic-gate * tlbs and various cache levels. 34010Sstevel@tonic-gate */ 34020Sstevel@tonic-gate static void 34030Sstevel@tonic-gate add_amd_assoc(dev_info_t *devi, const char *label, uint_t assoc) 34040Sstevel@tonic-gate { 34050Sstevel@tonic-gate switch (assoc) { 34060Sstevel@tonic-gate case 0: /* reserved; ignore */ 34070Sstevel@tonic-gate break; 34080Sstevel@tonic-gate default: 34090Sstevel@tonic-gate add_cache_prop(devi, label, assoc_str, assoc); 34100Sstevel@tonic-gate break; 34110Sstevel@tonic-gate case 0xff: 34120Sstevel@tonic-gate add_cache_prop(devi, label, fully_assoc, 1); 34130Sstevel@tonic-gate break; 34140Sstevel@tonic-gate } 34150Sstevel@tonic-gate } 34160Sstevel@tonic-gate 34170Sstevel@tonic-gate static void 34180Sstevel@tonic-gate add_amd_tlb(dev_info_t *devi, const char *label, uint_t assoc, uint_t size) 34190Sstevel@tonic-gate { 34200Sstevel@tonic-gate if (size == 0) 34210Sstevel@tonic-gate return; 34220Sstevel@tonic-gate add_cache_prop(devi, label, size_str, size); 34230Sstevel@tonic-gate add_amd_assoc(devi, label, assoc); 34240Sstevel@tonic-gate } 34250Sstevel@tonic-gate 34260Sstevel@tonic-gate static void 34270Sstevel@tonic-gate add_amd_cache(dev_info_t *devi, const char *label, 34280Sstevel@tonic-gate uint_t size, uint_t assoc, uint_t lines_per_tag, uint_t line_size) 34290Sstevel@tonic-gate { 34300Sstevel@tonic-gate if (size == 0 || line_size == 0) 34310Sstevel@tonic-gate return; 34320Sstevel@tonic-gate add_amd_assoc(devi, label, assoc); 34330Sstevel@tonic-gate /* 34340Sstevel@tonic-gate * Most AMD parts have a sectored cache. Multiple cache lines are 34350Sstevel@tonic-gate * associated with each tag. A sector consists of all cache lines 34360Sstevel@tonic-gate * associated with a tag. For example, the AMD K6-III has a sector 34370Sstevel@tonic-gate * size of 2 cache lines per tag. 34380Sstevel@tonic-gate */ 34390Sstevel@tonic-gate if (lines_per_tag != 0) 34400Sstevel@tonic-gate add_cache_prop(devi, label, "lines-per-tag", lines_per_tag); 34410Sstevel@tonic-gate add_cache_prop(devi, label, line_str, line_size); 34420Sstevel@tonic-gate add_cache_prop(devi, label, size_str, size * 1024); 34430Sstevel@tonic-gate } 34440Sstevel@tonic-gate 34450Sstevel@tonic-gate static void 34460Sstevel@tonic-gate add_amd_l2_assoc(dev_info_t *devi, const char *label, uint_t assoc) 34470Sstevel@tonic-gate { 34480Sstevel@tonic-gate switch (assoc) { 34490Sstevel@tonic-gate case 0: /* off */ 34500Sstevel@tonic-gate break; 34510Sstevel@tonic-gate case 1: 34520Sstevel@tonic-gate case 2: 34530Sstevel@tonic-gate case 4: 34540Sstevel@tonic-gate add_cache_prop(devi, label, assoc_str, assoc); 34550Sstevel@tonic-gate break; 34560Sstevel@tonic-gate case 6: 34570Sstevel@tonic-gate add_cache_prop(devi, label, assoc_str, 8); 34580Sstevel@tonic-gate break; 34590Sstevel@tonic-gate case 8: 34600Sstevel@tonic-gate add_cache_prop(devi, label, assoc_str, 16); 34610Sstevel@tonic-gate break; 34620Sstevel@tonic-gate case 0xf: 34630Sstevel@tonic-gate add_cache_prop(devi, label, fully_assoc, 1); 34640Sstevel@tonic-gate break; 34650Sstevel@tonic-gate default: /* reserved; ignore */ 34660Sstevel@tonic-gate break; 34670Sstevel@tonic-gate } 34680Sstevel@tonic-gate } 34690Sstevel@tonic-gate 34700Sstevel@tonic-gate static void 34710Sstevel@tonic-gate add_amd_l2_tlb(dev_info_t *devi, const char *label, uint_t assoc, uint_t size) 34720Sstevel@tonic-gate { 34730Sstevel@tonic-gate if (size == 0 || assoc == 0) 34740Sstevel@tonic-gate return; 34750Sstevel@tonic-gate add_amd_l2_assoc(devi, label, assoc); 34760Sstevel@tonic-gate add_cache_prop(devi, label, size_str, size); 34770Sstevel@tonic-gate } 34780Sstevel@tonic-gate 34790Sstevel@tonic-gate static void 34800Sstevel@tonic-gate add_amd_l2_cache(dev_info_t *devi, const char *label, 34810Sstevel@tonic-gate uint_t size, uint_t assoc, uint_t lines_per_tag, uint_t line_size) 34820Sstevel@tonic-gate { 34830Sstevel@tonic-gate if (size == 0 || assoc == 0 || line_size == 0) 34840Sstevel@tonic-gate return; 34850Sstevel@tonic-gate add_amd_l2_assoc(devi, label, assoc); 34860Sstevel@tonic-gate if (lines_per_tag != 0) 34870Sstevel@tonic-gate add_cache_prop(devi, label, "lines-per-tag", lines_per_tag); 34880Sstevel@tonic-gate add_cache_prop(devi, label, line_str, line_size); 34890Sstevel@tonic-gate add_cache_prop(devi, label, size_str, size * 1024); 34900Sstevel@tonic-gate } 34910Sstevel@tonic-gate 34920Sstevel@tonic-gate static void 34930Sstevel@tonic-gate amd_cache_info(struct cpuid_info *cpi, dev_info_t *devi) 34940Sstevel@tonic-gate { 34951228Sandrei struct cpuid_regs *cp; 34960Sstevel@tonic-gate 34970Sstevel@tonic-gate if (cpi->cpi_xmaxeax < 0x80000005) 34980Sstevel@tonic-gate return; 34990Sstevel@tonic-gate cp = &cpi->cpi_extd[5]; 35000Sstevel@tonic-gate 35010Sstevel@tonic-gate /* 35020Sstevel@tonic-gate * 4M/2M L1 TLB configuration 35030Sstevel@tonic-gate * 35040Sstevel@tonic-gate * We report the size for 2M pages because AMD uses two 35050Sstevel@tonic-gate * TLB entries for one 4M page. 35060Sstevel@tonic-gate */ 35070Sstevel@tonic-gate add_amd_tlb(devi, "dtlb-2M", 35080Sstevel@tonic-gate BITX(cp->cp_eax, 31, 24), BITX(cp->cp_eax, 23, 16)); 35090Sstevel@tonic-gate add_amd_tlb(devi, "itlb-2M", 35100Sstevel@tonic-gate BITX(cp->cp_eax, 15, 8), BITX(cp->cp_eax, 7, 0)); 35110Sstevel@tonic-gate 35120Sstevel@tonic-gate /* 35130Sstevel@tonic-gate * 4K L1 TLB configuration 35140Sstevel@tonic-gate */ 35150Sstevel@tonic-gate 35160Sstevel@tonic-gate switch (cpi->cpi_vendor) { 35170Sstevel@tonic-gate uint_t nentries; 35180Sstevel@tonic-gate case X86_VENDOR_TM: 35190Sstevel@tonic-gate if (cpi->cpi_family >= 5) { 35200Sstevel@tonic-gate /* 35210Sstevel@tonic-gate * Crusoe processors have 256 TLB entries, but 35220Sstevel@tonic-gate * cpuid data format constrains them to only 35230Sstevel@tonic-gate * reporting 255 of them. 35240Sstevel@tonic-gate */ 35250Sstevel@tonic-gate if ((nentries = BITX(cp->cp_ebx, 23, 16)) == 255) 35260Sstevel@tonic-gate nentries = 256; 35270Sstevel@tonic-gate /* 35280Sstevel@tonic-gate * Crusoe processors also have a unified TLB 35290Sstevel@tonic-gate */ 35300Sstevel@tonic-gate add_amd_tlb(devi, "tlb-4K", BITX(cp->cp_ebx, 31, 24), 35310Sstevel@tonic-gate nentries); 35320Sstevel@tonic-gate break; 35330Sstevel@tonic-gate } 35340Sstevel@tonic-gate /*FALLTHROUGH*/ 35350Sstevel@tonic-gate default: 35360Sstevel@tonic-gate add_amd_tlb(devi, itlb4k_str, 35370Sstevel@tonic-gate BITX(cp->cp_ebx, 31, 24), BITX(cp->cp_ebx, 23, 16)); 35380Sstevel@tonic-gate add_amd_tlb(devi, dtlb4k_str, 35390Sstevel@tonic-gate BITX(cp->cp_ebx, 15, 8), BITX(cp->cp_ebx, 7, 0)); 35400Sstevel@tonic-gate break; 35410Sstevel@tonic-gate } 35420Sstevel@tonic-gate 35430Sstevel@tonic-gate /* 35440Sstevel@tonic-gate * data L1 cache configuration 35450Sstevel@tonic-gate */ 35460Sstevel@tonic-gate 35470Sstevel@tonic-gate add_amd_cache(devi, l1_dcache_str, 35480Sstevel@tonic-gate BITX(cp->cp_ecx, 31, 24), BITX(cp->cp_ecx, 23, 16), 35490Sstevel@tonic-gate BITX(cp->cp_ecx, 15, 8), BITX(cp->cp_ecx, 7, 0)); 35500Sstevel@tonic-gate 35510Sstevel@tonic-gate /* 35520Sstevel@tonic-gate * code L1 cache configuration 35530Sstevel@tonic-gate */ 35540Sstevel@tonic-gate 35550Sstevel@tonic-gate add_amd_cache(devi, l1_icache_str, 35560Sstevel@tonic-gate BITX(cp->cp_edx, 31, 24), BITX(cp->cp_edx, 23, 16), 35570Sstevel@tonic-gate BITX(cp->cp_edx, 15, 8), BITX(cp->cp_edx, 7, 0)); 35580Sstevel@tonic-gate 35590Sstevel@tonic-gate if (cpi->cpi_xmaxeax < 0x80000006) 35600Sstevel@tonic-gate return; 35610Sstevel@tonic-gate cp = &cpi->cpi_extd[6]; 35620Sstevel@tonic-gate 35630Sstevel@tonic-gate /* Check for a unified L2 TLB for large pages */ 35640Sstevel@tonic-gate 35650Sstevel@tonic-gate if (BITX(cp->cp_eax, 31, 16) == 0) 35660Sstevel@tonic-gate add_amd_l2_tlb(devi, "l2-tlb-2M", 35670Sstevel@tonic-gate BITX(cp->cp_eax, 15, 12), BITX(cp->cp_eax, 11, 0)); 35680Sstevel@tonic-gate else { 35690Sstevel@tonic-gate add_amd_l2_tlb(devi, "l2-dtlb-2M", 35700Sstevel@tonic-gate BITX(cp->cp_eax, 31, 28), BITX(cp->cp_eax, 27, 16)); 35710Sstevel@tonic-gate add_amd_l2_tlb(devi, "l2-itlb-2M", 35720Sstevel@tonic-gate BITX(cp->cp_eax, 15, 12), BITX(cp->cp_eax, 11, 0)); 35730Sstevel@tonic-gate } 35740Sstevel@tonic-gate 35750Sstevel@tonic-gate /* Check for a unified L2 TLB for 4K pages */ 35760Sstevel@tonic-gate 35770Sstevel@tonic-gate if (BITX(cp->cp_ebx, 31, 16) == 0) { 35780Sstevel@tonic-gate add_amd_l2_tlb(devi, "l2-tlb-4K", 35790Sstevel@tonic-gate BITX(cp->cp_eax, 15, 12), BITX(cp->cp_eax, 11, 0)); 35800Sstevel@tonic-gate } else { 35810Sstevel@tonic-gate add_amd_l2_tlb(devi, "l2-dtlb-4K", 35820Sstevel@tonic-gate BITX(cp->cp_eax, 31, 28), BITX(cp->cp_eax, 27, 16)); 35830Sstevel@tonic-gate add_amd_l2_tlb(devi, "l2-itlb-4K", 35840Sstevel@tonic-gate BITX(cp->cp_eax, 15, 12), BITX(cp->cp_eax, 11, 0)); 35850Sstevel@tonic-gate } 35860Sstevel@tonic-gate 35870Sstevel@tonic-gate add_amd_l2_cache(devi, l2_cache_str, 35880Sstevel@tonic-gate BITX(cp->cp_ecx, 31, 16), BITX(cp->cp_ecx, 15, 12), 35890Sstevel@tonic-gate BITX(cp->cp_ecx, 11, 8), BITX(cp->cp_ecx, 7, 0)); 35900Sstevel@tonic-gate } 35910Sstevel@tonic-gate 35920Sstevel@tonic-gate /* 35930Sstevel@tonic-gate * There are two basic ways that the x86 world describes it cache 35940Sstevel@tonic-gate * and tlb architecture - Intel's way and AMD's way. 35950Sstevel@tonic-gate * 35960Sstevel@tonic-gate * Return which flavor of cache architecture we should use 35970Sstevel@tonic-gate */ 35980Sstevel@tonic-gate static int 35990Sstevel@tonic-gate x86_which_cacheinfo(struct cpuid_info *cpi) 36000Sstevel@tonic-gate { 36010Sstevel@tonic-gate switch (cpi->cpi_vendor) { 36020Sstevel@tonic-gate case X86_VENDOR_Intel: 36030Sstevel@tonic-gate if (cpi->cpi_maxeax >= 2) 36040Sstevel@tonic-gate return (X86_VENDOR_Intel); 36050Sstevel@tonic-gate break; 36060Sstevel@tonic-gate case X86_VENDOR_AMD: 36070Sstevel@tonic-gate /* 36080Sstevel@tonic-gate * The K5 model 1 was the first part from AMD that reported 36090Sstevel@tonic-gate * cache sizes via extended cpuid functions. 36100Sstevel@tonic-gate */ 36110Sstevel@tonic-gate if (cpi->cpi_family > 5 || 36120Sstevel@tonic-gate (cpi->cpi_family == 5 && cpi->cpi_model >= 1)) 36130Sstevel@tonic-gate return (X86_VENDOR_AMD); 36140Sstevel@tonic-gate break; 36150Sstevel@tonic-gate case X86_VENDOR_TM: 36160Sstevel@tonic-gate if (cpi->cpi_family >= 5) 36170Sstevel@tonic-gate return (X86_VENDOR_AMD); 36180Sstevel@tonic-gate /*FALLTHROUGH*/ 36190Sstevel@tonic-gate default: 36200Sstevel@tonic-gate /* 36210Sstevel@tonic-gate * If they have extended CPU data for 0x80000005 36220Sstevel@tonic-gate * then we assume they have AMD-format cache 36230Sstevel@tonic-gate * information. 36240Sstevel@tonic-gate * 36250Sstevel@tonic-gate * If not, and the vendor happens to be Cyrix, 36260Sstevel@tonic-gate * then try our-Cyrix specific handler. 36270Sstevel@tonic-gate * 36280Sstevel@tonic-gate * If we're not Cyrix, then assume we're using Intel's 36290Sstevel@tonic-gate * table-driven format instead. 36300Sstevel@tonic-gate */ 36310Sstevel@tonic-gate if (cpi->cpi_xmaxeax >= 0x80000005) 36320Sstevel@tonic-gate return (X86_VENDOR_AMD); 36330Sstevel@tonic-gate else if (cpi->cpi_vendor == X86_VENDOR_Cyrix) 36340Sstevel@tonic-gate return (X86_VENDOR_Cyrix); 36350Sstevel@tonic-gate else if (cpi->cpi_maxeax >= 2) 36360Sstevel@tonic-gate return (X86_VENDOR_Intel); 36370Sstevel@tonic-gate break; 36380Sstevel@tonic-gate } 36390Sstevel@tonic-gate return (-1); 36400Sstevel@tonic-gate } 36410Sstevel@tonic-gate 36420Sstevel@tonic-gate void 36439652SMichael.Corcoran@Sun.COM cpuid_set_cpu_properties(void *dip, processorid_t cpu_id, 36449652SMichael.Corcoran@Sun.COM struct cpuid_info *cpi) 36450Sstevel@tonic-gate { 36460Sstevel@tonic-gate dev_info_t *cpu_devi; 36470Sstevel@tonic-gate int create; 36480Sstevel@tonic-gate 36499652SMichael.Corcoran@Sun.COM cpu_devi = (dev_info_t *)dip; 36500Sstevel@tonic-gate 36510Sstevel@tonic-gate /* device_type */ 36520Sstevel@tonic-gate (void) ndi_prop_update_string(DDI_DEV_T_NONE, cpu_devi, 36530Sstevel@tonic-gate "device_type", "cpu"); 36540Sstevel@tonic-gate 36550Sstevel@tonic-gate /* reg */ 36560Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 36570Sstevel@tonic-gate "reg", cpu_id); 36580Sstevel@tonic-gate 36590Sstevel@tonic-gate /* cpu-mhz, and clock-frequency */ 36600Sstevel@tonic-gate if (cpu_freq > 0) { 36610Sstevel@tonic-gate long long mul; 36620Sstevel@tonic-gate 36630Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 36640Sstevel@tonic-gate "cpu-mhz", cpu_freq); 36650Sstevel@tonic-gate if ((mul = cpu_freq * 1000000LL) <= INT_MAX) 36660Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 36670Sstevel@tonic-gate "clock-frequency", (int)mul); 36680Sstevel@tonic-gate } 36690Sstevel@tonic-gate 36700Sstevel@tonic-gate if ((x86_feature & X86_CPUID) == 0) { 36710Sstevel@tonic-gate return; 36720Sstevel@tonic-gate } 36730Sstevel@tonic-gate 36740Sstevel@tonic-gate /* vendor-id */ 36750Sstevel@tonic-gate (void) ndi_prop_update_string(DDI_DEV_T_NONE, cpu_devi, 36764481Sbholler "vendor-id", cpi->cpi_vendorstr); 36770Sstevel@tonic-gate 36780Sstevel@tonic-gate if (cpi->cpi_maxeax == 0) { 36790Sstevel@tonic-gate return; 36800Sstevel@tonic-gate } 36810Sstevel@tonic-gate 36820Sstevel@tonic-gate /* 36830Sstevel@tonic-gate * family, model, and step 36840Sstevel@tonic-gate */ 36850Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 36864481Sbholler "family", CPI_FAMILY(cpi)); 36870Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 36884481Sbholler "cpu-model", CPI_MODEL(cpi)); 36890Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 36904481Sbholler "stepping-id", CPI_STEP(cpi)); 36910Sstevel@tonic-gate 36920Sstevel@tonic-gate /* type */ 36930Sstevel@tonic-gate switch (cpi->cpi_vendor) { 36940Sstevel@tonic-gate case X86_VENDOR_Intel: 36950Sstevel@tonic-gate create = 1; 36960Sstevel@tonic-gate break; 36970Sstevel@tonic-gate default: 36980Sstevel@tonic-gate create = 0; 36990Sstevel@tonic-gate break; 37000Sstevel@tonic-gate } 37010Sstevel@tonic-gate if (create) 37020Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 37034481Sbholler "type", CPI_TYPE(cpi)); 37040Sstevel@tonic-gate 37050Sstevel@tonic-gate /* ext-family */ 37060Sstevel@tonic-gate switch (cpi->cpi_vendor) { 37070Sstevel@tonic-gate case X86_VENDOR_Intel: 37080Sstevel@tonic-gate case X86_VENDOR_AMD: 37090Sstevel@tonic-gate create = cpi->cpi_family >= 0xf; 37100Sstevel@tonic-gate break; 37110Sstevel@tonic-gate default: 37120Sstevel@tonic-gate create = 0; 37130Sstevel@tonic-gate break; 37140Sstevel@tonic-gate } 37150Sstevel@tonic-gate if (create) 37160Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 37170Sstevel@tonic-gate "ext-family", CPI_FAMILY_XTD(cpi)); 37180Sstevel@tonic-gate 37190Sstevel@tonic-gate /* ext-model */ 37200Sstevel@tonic-gate switch (cpi->cpi_vendor) { 37210Sstevel@tonic-gate case X86_VENDOR_Intel: 37226317Skk208521 create = IS_EXTENDED_MODEL_INTEL(cpi); 37232001Sdmick break; 37240Sstevel@tonic-gate case X86_VENDOR_AMD: 37251582Skchow create = CPI_FAMILY(cpi) == 0xf; 37260Sstevel@tonic-gate break; 37270Sstevel@tonic-gate default: 37280Sstevel@tonic-gate create = 0; 37290Sstevel@tonic-gate break; 37300Sstevel@tonic-gate } 37310Sstevel@tonic-gate if (create) 37320Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 37334481Sbholler "ext-model", CPI_MODEL_XTD(cpi)); 37340Sstevel@tonic-gate 37350Sstevel@tonic-gate /* generation */ 37360Sstevel@tonic-gate switch (cpi->cpi_vendor) { 37370Sstevel@tonic-gate case X86_VENDOR_AMD: 37380Sstevel@tonic-gate /* 37390Sstevel@tonic-gate * AMD K5 model 1 was the first part to support this 37400Sstevel@tonic-gate */ 37410Sstevel@tonic-gate create = cpi->cpi_xmaxeax >= 0x80000001; 37420Sstevel@tonic-gate break; 37430Sstevel@tonic-gate default: 37440Sstevel@tonic-gate create = 0; 37450Sstevel@tonic-gate break; 37460Sstevel@tonic-gate } 37470Sstevel@tonic-gate if (create) 37480Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 37490Sstevel@tonic-gate "generation", BITX((cpi)->cpi_extd[1].cp_eax, 11, 8)); 37500Sstevel@tonic-gate 37510Sstevel@tonic-gate /* brand-id */ 37520Sstevel@tonic-gate switch (cpi->cpi_vendor) { 37530Sstevel@tonic-gate case X86_VENDOR_Intel: 37540Sstevel@tonic-gate /* 37550Sstevel@tonic-gate * brand id first appeared on Pentium III Xeon model 8, 37560Sstevel@tonic-gate * and Celeron model 8 processors and Opteron 37570Sstevel@tonic-gate */ 37580Sstevel@tonic-gate create = cpi->cpi_family > 6 || 37590Sstevel@tonic-gate (cpi->cpi_family == 6 && cpi->cpi_model >= 8); 37600Sstevel@tonic-gate break; 37610Sstevel@tonic-gate case X86_VENDOR_AMD: 37620Sstevel@tonic-gate create = cpi->cpi_family >= 0xf; 37630Sstevel@tonic-gate break; 37640Sstevel@tonic-gate default: 37650Sstevel@tonic-gate create = 0; 37660Sstevel@tonic-gate break; 37670Sstevel@tonic-gate } 37680Sstevel@tonic-gate if (create && cpi->cpi_brandid != 0) { 37690Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 37700Sstevel@tonic-gate "brand-id", cpi->cpi_brandid); 37710Sstevel@tonic-gate } 37720Sstevel@tonic-gate 37730Sstevel@tonic-gate /* chunks, and apic-id */ 37740Sstevel@tonic-gate switch (cpi->cpi_vendor) { 37750Sstevel@tonic-gate /* 37760Sstevel@tonic-gate * first available on Pentium IV and Opteron (K8) 37770Sstevel@tonic-gate */ 37781975Sdmick case X86_VENDOR_Intel: 37791975Sdmick create = IS_NEW_F6(cpi) || cpi->cpi_family >= 0xf; 37801975Sdmick break; 37811975Sdmick case X86_VENDOR_AMD: 37820Sstevel@tonic-gate create = cpi->cpi_family >= 0xf; 37830Sstevel@tonic-gate break; 37840Sstevel@tonic-gate default: 37850Sstevel@tonic-gate create = 0; 37860Sstevel@tonic-gate break; 37870Sstevel@tonic-gate } 37880Sstevel@tonic-gate if (create) { 37890Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 37904481Sbholler "chunks", CPI_CHUNKS(cpi)); 37910Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 37927282Smishra "apic-id", cpi->cpi_apicid); 37931414Scindi if (cpi->cpi_chipid >= 0) { 37940Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 37950Sstevel@tonic-gate "chip#", cpi->cpi_chipid); 37961414Scindi (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 37971414Scindi "clog#", cpi->cpi_clogid); 37981414Scindi } 37990Sstevel@tonic-gate } 38000Sstevel@tonic-gate 38010Sstevel@tonic-gate /* cpuid-features */ 38020Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 38030Sstevel@tonic-gate "cpuid-features", CPI_FEATURES_EDX(cpi)); 38040Sstevel@tonic-gate 38050Sstevel@tonic-gate 38060Sstevel@tonic-gate /* cpuid-features-ecx */ 38070Sstevel@tonic-gate switch (cpi->cpi_vendor) { 38080Sstevel@tonic-gate case X86_VENDOR_Intel: 38091975Sdmick create = IS_NEW_F6(cpi) || cpi->cpi_family >= 0xf; 38100Sstevel@tonic-gate break; 38110Sstevel@tonic-gate default: 38120Sstevel@tonic-gate create = 0; 38130Sstevel@tonic-gate break; 38140Sstevel@tonic-gate } 38150Sstevel@tonic-gate if (create) 38160Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 38170Sstevel@tonic-gate "cpuid-features-ecx", CPI_FEATURES_ECX(cpi)); 38180Sstevel@tonic-gate 38190Sstevel@tonic-gate /* ext-cpuid-features */ 38200Sstevel@tonic-gate switch (cpi->cpi_vendor) { 38211975Sdmick case X86_VENDOR_Intel: 38220Sstevel@tonic-gate case X86_VENDOR_AMD: 38230Sstevel@tonic-gate case X86_VENDOR_Cyrix: 38240Sstevel@tonic-gate case X86_VENDOR_TM: 38250Sstevel@tonic-gate case X86_VENDOR_Centaur: 38260Sstevel@tonic-gate create = cpi->cpi_xmaxeax >= 0x80000001; 38270Sstevel@tonic-gate break; 38280Sstevel@tonic-gate default: 38290Sstevel@tonic-gate create = 0; 38300Sstevel@tonic-gate break; 38310Sstevel@tonic-gate } 38321975Sdmick if (create) { 38330Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 38344481Sbholler "ext-cpuid-features", CPI_FEATURES_XTD_EDX(cpi)); 38351975Sdmick (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 38364481Sbholler "ext-cpuid-features-ecx", CPI_FEATURES_XTD_ECX(cpi)); 38371975Sdmick } 38380Sstevel@tonic-gate 38390Sstevel@tonic-gate /* 38400Sstevel@tonic-gate * Brand String first appeared in Intel Pentium IV, AMD K5 38410Sstevel@tonic-gate * model 1, and Cyrix GXm. On earlier models we try and 38420Sstevel@tonic-gate * simulate something similar .. so this string should always 38430Sstevel@tonic-gate * same -something- about the processor, however lame. 38440Sstevel@tonic-gate */ 38450Sstevel@tonic-gate (void) ndi_prop_update_string(DDI_DEV_T_NONE, cpu_devi, 38460Sstevel@tonic-gate "brand-string", cpi->cpi_brandstr); 38470Sstevel@tonic-gate 38480Sstevel@tonic-gate /* 38490Sstevel@tonic-gate * Finally, cache and tlb information 38500Sstevel@tonic-gate */ 38510Sstevel@tonic-gate switch (x86_which_cacheinfo(cpi)) { 38520Sstevel@tonic-gate case X86_VENDOR_Intel: 38530Sstevel@tonic-gate intel_walk_cacheinfo(cpi, cpu_devi, add_cacheent_props); 38540Sstevel@tonic-gate break; 38550Sstevel@tonic-gate case X86_VENDOR_Cyrix: 38560Sstevel@tonic-gate cyrix_walk_cacheinfo(cpi, cpu_devi, add_cacheent_props); 38570Sstevel@tonic-gate break; 38580Sstevel@tonic-gate case X86_VENDOR_AMD: 38590Sstevel@tonic-gate amd_cache_info(cpi, cpu_devi); 38600Sstevel@tonic-gate break; 38610Sstevel@tonic-gate default: 38620Sstevel@tonic-gate break; 38630Sstevel@tonic-gate } 38640Sstevel@tonic-gate } 38650Sstevel@tonic-gate 38660Sstevel@tonic-gate struct l2info { 38670Sstevel@tonic-gate int *l2i_csz; 38680Sstevel@tonic-gate int *l2i_lsz; 38690Sstevel@tonic-gate int *l2i_assoc; 38700Sstevel@tonic-gate int l2i_ret; 38710Sstevel@tonic-gate }; 38720Sstevel@tonic-gate 38730Sstevel@tonic-gate /* 38740Sstevel@tonic-gate * A cacheinfo walker that fetches the size, line-size and associativity 38750Sstevel@tonic-gate * of the L2 cache 38760Sstevel@tonic-gate */ 38770Sstevel@tonic-gate static int 38780Sstevel@tonic-gate intel_l2cinfo(void *arg, const struct cachetab *ct) 38790Sstevel@tonic-gate { 38800Sstevel@tonic-gate struct l2info *l2i = arg; 38810Sstevel@tonic-gate int *ip; 38820Sstevel@tonic-gate 38830Sstevel@tonic-gate if (ct->ct_label != l2_cache_str && 38840Sstevel@tonic-gate ct->ct_label != sl2_cache_str) 38850Sstevel@tonic-gate return (0); /* not an L2 -- keep walking */ 38860Sstevel@tonic-gate 38870Sstevel@tonic-gate if ((ip = l2i->l2i_csz) != NULL) 38880Sstevel@tonic-gate *ip = ct->ct_size; 38890Sstevel@tonic-gate if ((ip = l2i->l2i_lsz) != NULL) 38900Sstevel@tonic-gate *ip = ct->ct_line_size; 38910Sstevel@tonic-gate if ((ip = l2i->l2i_assoc) != NULL) 38920Sstevel@tonic-gate *ip = ct->ct_assoc; 38930Sstevel@tonic-gate l2i->l2i_ret = ct->ct_size; 38940Sstevel@tonic-gate return (1); /* was an L2 -- terminate walk */ 38950Sstevel@tonic-gate } 38960Sstevel@tonic-gate 38975070Skchow /* 38985070Skchow * AMD L2/L3 Cache and TLB Associativity Field Definition: 38995070Skchow * 39005070Skchow * Unlike the associativity for the L1 cache and tlb where the 8 bit 39015070Skchow * value is the associativity, the associativity for the L2 cache and 39025070Skchow * tlb is encoded in the following table. The 4 bit L2 value serves as 39035070Skchow * an index into the amd_afd[] array to determine the associativity. 39045070Skchow * -1 is undefined. 0 is fully associative. 39055070Skchow */ 39065070Skchow 39075070Skchow static int amd_afd[] = 39085070Skchow {-1, 1, 2, -1, 4, -1, 8, -1, 16, -1, 32, 48, 64, 96, 128, 0}; 39095070Skchow 39100Sstevel@tonic-gate static void 39110Sstevel@tonic-gate amd_l2cacheinfo(struct cpuid_info *cpi, struct l2info *l2i) 39120Sstevel@tonic-gate { 39131228Sandrei struct cpuid_regs *cp; 39140Sstevel@tonic-gate uint_t size, assoc; 39155070Skchow int i; 39160Sstevel@tonic-gate int *ip; 39170Sstevel@tonic-gate 39180Sstevel@tonic-gate if (cpi->cpi_xmaxeax < 0x80000006) 39190Sstevel@tonic-gate return; 39200Sstevel@tonic-gate cp = &cpi->cpi_extd[6]; 39210Sstevel@tonic-gate 39225070Skchow if ((i = BITX(cp->cp_ecx, 15, 12)) != 0 && 39230Sstevel@tonic-gate (size = BITX(cp->cp_ecx, 31, 16)) != 0) { 39240Sstevel@tonic-gate uint_t cachesz = size * 1024; 39255070Skchow assoc = amd_afd[i]; 39265070Skchow 39275070Skchow ASSERT(assoc != -1); 39280Sstevel@tonic-gate 39290Sstevel@tonic-gate if ((ip = l2i->l2i_csz) != NULL) 39300Sstevel@tonic-gate *ip = cachesz; 39310Sstevel@tonic-gate if ((ip = l2i->l2i_lsz) != NULL) 39320Sstevel@tonic-gate *ip = BITX(cp->cp_ecx, 7, 0); 39330Sstevel@tonic-gate if ((ip = l2i->l2i_assoc) != NULL) 39340Sstevel@tonic-gate *ip = assoc; 39350Sstevel@tonic-gate l2i->l2i_ret = cachesz; 39360Sstevel@tonic-gate } 39370Sstevel@tonic-gate } 39380Sstevel@tonic-gate 39390Sstevel@tonic-gate int 39400Sstevel@tonic-gate getl2cacheinfo(cpu_t *cpu, int *csz, int *lsz, int *assoc) 39410Sstevel@tonic-gate { 39420Sstevel@tonic-gate struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 39430Sstevel@tonic-gate struct l2info __l2info, *l2i = &__l2info; 39440Sstevel@tonic-gate 39450Sstevel@tonic-gate l2i->l2i_csz = csz; 39460Sstevel@tonic-gate l2i->l2i_lsz = lsz; 39470Sstevel@tonic-gate l2i->l2i_assoc = assoc; 39480Sstevel@tonic-gate l2i->l2i_ret = -1; 39490Sstevel@tonic-gate 39500Sstevel@tonic-gate switch (x86_which_cacheinfo(cpi)) { 39510Sstevel@tonic-gate case X86_VENDOR_Intel: 39520Sstevel@tonic-gate intel_walk_cacheinfo(cpi, l2i, intel_l2cinfo); 39530Sstevel@tonic-gate break; 39540Sstevel@tonic-gate case X86_VENDOR_Cyrix: 39550Sstevel@tonic-gate cyrix_walk_cacheinfo(cpi, l2i, intel_l2cinfo); 39560Sstevel@tonic-gate break; 39570Sstevel@tonic-gate case X86_VENDOR_AMD: 39580Sstevel@tonic-gate amd_l2cacheinfo(cpi, l2i); 39590Sstevel@tonic-gate break; 39600Sstevel@tonic-gate default: 39610Sstevel@tonic-gate break; 39620Sstevel@tonic-gate } 39630Sstevel@tonic-gate return (l2i->l2i_ret); 39640Sstevel@tonic-gate } 39654481Sbholler 39665084Sjohnlev #if !defined(__xpv) 39675084Sjohnlev 39685045Sbholler uint32_t * 39695045Sbholler cpuid_mwait_alloc(cpu_t *cpu) 39705045Sbholler { 39715045Sbholler uint32_t *ret; 39725045Sbholler size_t mwait_size; 39735045Sbholler 39745045Sbholler ASSERT(cpuid_checkpass(cpu, 2)); 39755045Sbholler 39765045Sbholler mwait_size = cpu->cpu_m.mcpu_cpi->cpi_mwait.mon_max; 39775045Sbholler if (mwait_size == 0) 39785045Sbholler return (NULL); 39795045Sbholler 39805045Sbholler /* 39815045Sbholler * kmem_alloc() returns cache line size aligned data for mwait_size 39825045Sbholler * allocations. mwait_size is currently cache line sized. Neither 39835045Sbholler * of these implementation details are guarantied to be true in the 39845045Sbholler * future. 39855045Sbholler * 39865045Sbholler * First try allocating mwait_size as kmem_alloc() currently returns 39875045Sbholler * correctly aligned memory. If kmem_alloc() does not return 39885045Sbholler * mwait_size aligned memory, then use mwait_size ROUNDUP. 39895045Sbholler * 39905045Sbholler * Set cpi_mwait.buf_actual and cpi_mwait.size_actual in case we 39915045Sbholler * decide to free this memory. 39925045Sbholler */ 39935045Sbholler ret = kmem_zalloc(mwait_size, KM_SLEEP); 39945045Sbholler if (ret == (uint32_t *)P2ROUNDUP((uintptr_t)ret, mwait_size)) { 39955045Sbholler cpu->cpu_m.mcpu_cpi->cpi_mwait.buf_actual = ret; 39965045Sbholler cpu->cpu_m.mcpu_cpi->cpi_mwait.size_actual = mwait_size; 39975045Sbholler *ret = MWAIT_RUNNING; 39985045Sbholler return (ret); 39995045Sbholler } else { 40005045Sbholler kmem_free(ret, mwait_size); 40015045Sbholler ret = kmem_zalloc(mwait_size * 2, KM_SLEEP); 40025045Sbholler cpu->cpu_m.mcpu_cpi->cpi_mwait.buf_actual = ret; 40035045Sbholler cpu->cpu_m.mcpu_cpi->cpi_mwait.size_actual = mwait_size * 2; 40045045Sbholler ret = (uint32_t *)P2ROUNDUP((uintptr_t)ret, mwait_size); 40055045Sbholler *ret = MWAIT_RUNNING; 40065045Sbholler return (ret); 40075045Sbholler } 40085045Sbholler } 40095045Sbholler 40105045Sbholler void 40115045Sbholler cpuid_mwait_free(cpu_t *cpu) 40124481Sbholler { 40134481Sbholler ASSERT(cpuid_checkpass(cpu, 2)); 40145045Sbholler 40155045Sbholler if (cpu->cpu_m.mcpu_cpi->cpi_mwait.buf_actual != NULL && 40165045Sbholler cpu->cpu_m.mcpu_cpi->cpi_mwait.size_actual > 0) { 40175045Sbholler kmem_free(cpu->cpu_m.mcpu_cpi->cpi_mwait.buf_actual, 40185045Sbholler cpu->cpu_m.mcpu_cpi->cpi_mwait.size_actual); 40195045Sbholler } 40205045Sbholler 40215045Sbholler cpu->cpu_m.mcpu_cpi->cpi_mwait.buf_actual = NULL; 40225045Sbholler cpu->cpu_m.mcpu_cpi->cpi_mwait.size_actual = 0; 40234481Sbholler } 40245084Sjohnlev 40255322Ssudheer void 40265322Ssudheer patch_tsc_read(int flag) 40275322Ssudheer { 40285322Ssudheer size_t cnt; 40297532SSean.Ye@Sun.COM 40305322Ssudheer switch (flag) { 40315322Ssudheer case X86_NO_TSC: 40325322Ssudheer cnt = &_no_rdtsc_end - &_no_rdtsc_start; 40335338Ssudheer (void) memcpy((void *)tsc_read, (void *)&_no_rdtsc_start, cnt); 40345322Ssudheer break; 40355322Ssudheer case X86_HAVE_TSCP: 40365322Ssudheer cnt = &_tscp_end - &_tscp_start; 40375338Ssudheer (void) memcpy((void *)tsc_read, (void *)&_tscp_start, cnt); 40385322Ssudheer break; 40395322Ssudheer case X86_TSC_MFENCE: 40405322Ssudheer cnt = &_tsc_mfence_end - &_tsc_mfence_start; 40415338Ssudheer (void) memcpy((void *)tsc_read, 40425338Ssudheer (void *)&_tsc_mfence_start, cnt); 40435322Ssudheer break; 40446642Ssudheer case X86_TSC_LFENCE: 40456642Ssudheer cnt = &_tsc_lfence_end - &_tsc_lfence_start; 40466642Ssudheer (void) memcpy((void *)tsc_read, 40476642Ssudheer (void *)&_tsc_lfence_start, cnt); 40486642Ssudheer break; 40495322Ssudheer default: 40505322Ssudheer break; 40515322Ssudheer } 40525322Ssudheer } 40535322Ssudheer 40548906SEric.Saxe@Sun.COM int 40558906SEric.Saxe@Sun.COM cpuid_deep_cstates_supported(void) 40568906SEric.Saxe@Sun.COM { 40578906SEric.Saxe@Sun.COM struct cpuid_info *cpi; 40588906SEric.Saxe@Sun.COM struct cpuid_regs regs; 40598906SEric.Saxe@Sun.COM 40608906SEric.Saxe@Sun.COM ASSERT(cpuid_checkpass(CPU, 1)); 40618906SEric.Saxe@Sun.COM 40628906SEric.Saxe@Sun.COM cpi = CPU->cpu_m.mcpu_cpi; 40638906SEric.Saxe@Sun.COM 40648906SEric.Saxe@Sun.COM if (!(x86_feature & X86_CPUID)) 40658906SEric.Saxe@Sun.COM return (0); 40668906SEric.Saxe@Sun.COM 40678906SEric.Saxe@Sun.COM switch (cpi->cpi_vendor) { 40688906SEric.Saxe@Sun.COM case X86_VENDOR_Intel: 40698906SEric.Saxe@Sun.COM if (cpi->cpi_xmaxeax < 0x80000007) 40708906SEric.Saxe@Sun.COM return (0); 40718906SEric.Saxe@Sun.COM 40728906SEric.Saxe@Sun.COM /* 40738906SEric.Saxe@Sun.COM * TSC run at a constant rate in all ACPI C-states? 40748906SEric.Saxe@Sun.COM */ 40758906SEric.Saxe@Sun.COM regs.cp_eax = 0x80000007; 40768906SEric.Saxe@Sun.COM (void) __cpuid_insn(®s); 40778906SEric.Saxe@Sun.COM return (regs.cp_edx & CPUID_TSC_CSTATE_INVARIANCE); 40788906SEric.Saxe@Sun.COM 40798906SEric.Saxe@Sun.COM default: 40808906SEric.Saxe@Sun.COM return (0); 40818906SEric.Saxe@Sun.COM } 40828906SEric.Saxe@Sun.COM } 40838906SEric.Saxe@Sun.COM 40848930SBill.Holler@Sun.COM #endif /* !__xpv */ 40858930SBill.Holler@Sun.COM 40868930SBill.Holler@Sun.COM void 40878930SBill.Holler@Sun.COM post_startup_cpu_fixups(void) 40888930SBill.Holler@Sun.COM { 40898930SBill.Holler@Sun.COM #ifndef __xpv 40908930SBill.Holler@Sun.COM /* 40918930SBill.Holler@Sun.COM * Some AMD processors support C1E state. Entering this state will 40928930SBill.Holler@Sun.COM * cause the local APIC timer to stop, which we can't deal with at 40938930SBill.Holler@Sun.COM * this time. 40948930SBill.Holler@Sun.COM */ 40958930SBill.Holler@Sun.COM if (cpuid_getvendor(CPU) == X86_VENDOR_AMD) { 40968930SBill.Holler@Sun.COM on_trap_data_t otd; 40978930SBill.Holler@Sun.COM uint64_t reg; 40988930SBill.Holler@Sun.COM 40998930SBill.Holler@Sun.COM if (!on_trap(&otd, OT_DATA_ACCESS)) { 41008930SBill.Holler@Sun.COM reg = rdmsr(MSR_AMD_INT_PENDING_CMP_HALT); 41018930SBill.Holler@Sun.COM /* Disable C1E state if it is enabled by BIOS */ 41028930SBill.Holler@Sun.COM if ((reg >> AMD_ACTONCMPHALT_SHIFT) & 41038930SBill.Holler@Sun.COM AMD_ACTONCMPHALT_MASK) { 41048930SBill.Holler@Sun.COM reg &= ~(AMD_ACTONCMPHALT_MASK << 41058930SBill.Holler@Sun.COM AMD_ACTONCMPHALT_SHIFT); 41068930SBill.Holler@Sun.COM wrmsr(MSR_AMD_INT_PENDING_CMP_HALT, reg); 41078930SBill.Holler@Sun.COM } 41088930SBill.Holler@Sun.COM } 41098930SBill.Holler@Sun.COM no_trap(); 41108930SBill.Holler@Sun.COM } 41118930SBill.Holler@Sun.COM #endif /* !__xpv */ 41128930SBill.Holler@Sun.COM } 41138930SBill.Holler@Sun.COM 41149283SBill.Holler@Sun.COM /* 41159283SBill.Holler@Sun.COM * Starting with the Westmere processor the local 41169283SBill.Holler@Sun.COM * APIC timer will continue running in all C-states, 41179283SBill.Holler@Sun.COM * including the deepest C-states. 41189283SBill.Holler@Sun.COM */ 41199283SBill.Holler@Sun.COM int 41209283SBill.Holler@Sun.COM cpuid_arat_supported(void) 41219283SBill.Holler@Sun.COM { 41229283SBill.Holler@Sun.COM struct cpuid_info *cpi; 41239283SBill.Holler@Sun.COM struct cpuid_regs regs; 41249283SBill.Holler@Sun.COM 41259283SBill.Holler@Sun.COM ASSERT(cpuid_checkpass(CPU, 1)); 41269283SBill.Holler@Sun.COM ASSERT(x86_feature & X86_CPUID); 41279283SBill.Holler@Sun.COM 41289283SBill.Holler@Sun.COM cpi = CPU->cpu_m.mcpu_cpi; 41299283SBill.Holler@Sun.COM 41309283SBill.Holler@Sun.COM switch (cpi->cpi_vendor) { 41319283SBill.Holler@Sun.COM case X86_VENDOR_Intel: 41329283SBill.Holler@Sun.COM /* 41339283SBill.Holler@Sun.COM * Always-running Local APIC Timer is 41349283SBill.Holler@Sun.COM * indicated by CPUID.6.EAX[2]. 41359283SBill.Holler@Sun.COM */ 41369283SBill.Holler@Sun.COM if (cpi->cpi_maxeax >= 6) { 41379283SBill.Holler@Sun.COM regs.cp_eax = 6; 41389283SBill.Holler@Sun.COM (void) cpuid_insn(NULL, ®s); 41399283SBill.Holler@Sun.COM return (regs.cp_eax & CPUID_CSTATE_ARAT); 41409283SBill.Holler@Sun.COM } else { 41419283SBill.Holler@Sun.COM return (0); 41429283SBill.Holler@Sun.COM } 41439283SBill.Holler@Sun.COM default: 41449283SBill.Holler@Sun.COM return (0); 41459283SBill.Holler@Sun.COM } 41469283SBill.Holler@Sun.COM } 41479283SBill.Holler@Sun.COM 41488377SBill.Holler@Sun.COM #if defined(__amd64) && !defined(__xpv) 41498377SBill.Holler@Sun.COM /* 41508377SBill.Holler@Sun.COM * Patch in versions of bcopy for high performance Intel Nhm processors 41518377SBill.Holler@Sun.COM * and later... 41528377SBill.Holler@Sun.COM */ 41538377SBill.Holler@Sun.COM void 41548377SBill.Holler@Sun.COM patch_memops(uint_t vendor) 41558377SBill.Holler@Sun.COM { 41568377SBill.Holler@Sun.COM size_t cnt, i; 41578377SBill.Holler@Sun.COM caddr_t to, from; 41588377SBill.Holler@Sun.COM 41598377SBill.Holler@Sun.COM if ((vendor == X86_VENDOR_Intel) && ((x86_feature & X86_SSE4_2) != 0)) { 41608377SBill.Holler@Sun.COM cnt = &bcopy_patch_end - &bcopy_patch_start; 41618377SBill.Holler@Sun.COM to = &bcopy_ck_size; 41628377SBill.Holler@Sun.COM from = &bcopy_patch_start; 41638377SBill.Holler@Sun.COM for (i = 0; i < cnt; i++) { 41648377SBill.Holler@Sun.COM *to++ = *from++; 41658377SBill.Holler@Sun.COM } 41668377SBill.Holler@Sun.COM } 41678377SBill.Holler@Sun.COM } 41688377SBill.Holler@Sun.COM #endif /* __amd64 && !__xpv */ 4169