17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5ee88d2b9Skchow * Common Development and Distribution License (the "License"). 6ee88d2b9Skchow * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 226e5580c9SFrank Van Der Linden * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. 23cfe84b82SMatt Amdur * Copyright (c) 2011 by Delphix. All rights reserved. 2479ec9da8SYuri Pankov * Copyright 2013 Nexenta Systems, Inc. All rights reserved. 256eedf6a5SJosef 'Jeff' Sipek * Copyright 2014 Josef "Jeff" Sipek <jeffpc@josefsipek.net> 267c478bd9Sstevel@tonic-gate */ 27cef70d2cSBill Holler /* 2841afdfa7SKrishnendu Sadhukhan - Sun Microsystems * Copyright (c) 2010, Intel Corporation. 29cef70d2cSBill Holler * All rights reserved. 30cef70d2cSBill Holler */ 318031591dSSrihari Venkatesan /* 328031591dSSrihari Venkatesan * Portions Copyright 2009 Advanced Micro Devices, Inc. 338031591dSSrihari Venkatesan */ 34faa20166SBryan Cantrill /* 35*263f549eSPatrick Mooney * Copyright 2016 Joyent, Inc. 36faa20166SBryan Cantrill */ 377c478bd9Sstevel@tonic-gate /* 387c478bd9Sstevel@tonic-gate * Various routines to handle identification 397c478bd9Sstevel@tonic-gate * and classification of x86 processors. 407c478bd9Sstevel@tonic-gate */ 417c478bd9Sstevel@tonic-gate 427c478bd9Sstevel@tonic-gate #include <sys/types.h> 437c478bd9Sstevel@tonic-gate #include <sys/archsystm.h> 447c478bd9Sstevel@tonic-gate #include <sys/x86_archext.h> 457c478bd9Sstevel@tonic-gate #include <sys/kmem.h> 467c478bd9Sstevel@tonic-gate #include <sys/systm.h> 477c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h> 487c478bd9Sstevel@tonic-gate #include <sys/sunddi.h> 497c478bd9Sstevel@tonic-gate #include <sys/sunndi.h> 507c478bd9Sstevel@tonic-gate #include <sys/cpuvar.h> 517c478bd9Sstevel@tonic-gate #include <sys/processor.h> 525b8a6efeSbholler #include <sys/sysmacros.h> 53fb2f18f8Sesaxe #include <sys/pg.h> 547c478bd9Sstevel@tonic-gate #include <sys/fp.h> 557c478bd9Sstevel@tonic-gate #include <sys/controlregs.h> 567c478bd9Sstevel@tonic-gate #include <sys/bitmap.h> 57dfea898aSKuriakose Kuruvilla #include <sys/auxv_386.h> 587c478bd9Sstevel@tonic-gate #include <sys/memnode.h> 598031591dSSrihari Venkatesan #include <sys/pci_cfgspace.h> 60*263f549eSPatrick Mooney #include <sys/comm_page.h> 61*263f549eSPatrick Mooney #include <sys/tsc.h> 627c478bd9Sstevel@tonic-gate 63e4b86885SCheng Sean Ye #ifdef __xpv 64e4b86885SCheng Sean Ye #include <sys/hypervisor.h> 65e774b42bSBill Holler #else 66e774b42bSBill Holler #include <sys/ontrap.h> 67e4b86885SCheng Sean Ye #endif 68e4b86885SCheng Sean Ye 697c478bd9Sstevel@tonic-gate /* 707c478bd9Sstevel@tonic-gate * Pass 0 of cpuid feature analysis happens in locore. It contains special code 717c478bd9Sstevel@tonic-gate * to recognize Cyrix processors that are not cpuid-compliant, and to deal with 727c478bd9Sstevel@tonic-gate * them accordingly. For most modern processors, feature detection occurs here 737c478bd9Sstevel@tonic-gate * in pass 1. 747c478bd9Sstevel@tonic-gate * 757c478bd9Sstevel@tonic-gate * Pass 1 of cpuid feature analysis happens just at the beginning of mlsetup() 767c478bd9Sstevel@tonic-gate * for the boot CPU and does the basic analysis that the early kernel needs. 777417cfdeSKuriakose Kuruvilla * x86_featureset is set based on the return value of cpuid_pass1() of the boot 787c478bd9Sstevel@tonic-gate * CPU. 797c478bd9Sstevel@tonic-gate * 807c478bd9Sstevel@tonic-gate * Pass 1 includes: 817c478bd9Sstevel@tonic-gate * 827c478bd9Sstevel@tonic-gate * o Determining vendor/model/family/stepping and setting x86_type and 837c478bd9Sstevel@tonic-gate * x86_vendor accordingly. 847c478bd9Sstevel@tonic-gate * o Processing the feature flags returned by the cpuid instruction while 857c478bd9Sstevel@tonic-gate * applying any workarounds or tricks for the specific processor. 867c478bd9Sstevel@tonic-gate * o Mapping the feature flags into Solaris feature bits (X86_*). 877c478bd9Sstevel@tonic-gate * o Processing extended feature flags if supported by the processor, 887c478bd9Sstevel@tonic-gate * again while applying specific processor knowledge. 897c478bd9Sstevel@tonic-gate * o Determining the CMT characteristics of the system. 907c478bd9Sstevel@tonic-gate * 917c478bd9Sstevel@tonic-gate * Pass 1 is done on non-boot CPUs during their initialization and the results 927c478bd9Sstevel@tonic-gate * are used only as a meager attempt at ensuring that all processors within the 937c478bd9Sstevel@tonic-gate * system support the same features. 947c478bd9Sstevel@tonic-gate * 957c478bd9Sstevel@tonic-gate * Pass 2 of cpuid feature analysis happens just at the beginning 967c478bd9Sstevel@tonic-gate * of startup(). It just copies in and corrects the remainder 977c478bd9Sstevel@tonic-gate * of the cpuid data we depend on: standard cpuid functions that we didn't 987c478bd9Sstevel@tonic-gate * need for pass1 feature analysis, and extended cpuid functions beyond the 997c478bd9Sstevel@tonic-gate * simple feature processing done in pass1. 1007c478bd9Sstevel@tonic-gate * 1017c478bd9Sstevel@tonic-gate * Pass 3 of cpuid analysis is invoked after basic kernel services; in 1027c478bd9Sstevel@tonic-gate * particular kernel memory allocation has been made available. It creates a 1037c478bd9Sstevel@tonic-gate * readable brand string based on the data collected in the first two passes. 1047c478bd9Sstevel@tonic-gate * 1057c478bd9Sstevel@tonic-gate * Pass 4 of cpuid analysis is invoked after post_startup() when all 1067c478bd9Sstevel@tonic-gate * the support infrastructure for various hardware features has been 1077c478bd9Sstevel@tonic-gate * initialized. It determines which processor features will be reported 1087c478bd9Sstevel@tonic-gate * to userland via the aux vector. 1097c478bd9Sstevel@tonic-gate * 1107c478bd9Sstevel@tonic-gate * All passes are executed on all CPUs, but only the boot CPU determines what 1117c478bd9Sstevel@tonic-gate * features the kernel will use. 1127c478bd9Sstevel@tonic-gate * 1137c478bd9Sstevel@tonic-gate * Much of the worst junk in this file is for the support of processors 1147c478bd9Sstevel@tonic-gate * that didn't really implement the cpuid instruction properly. 1157c478bd9Sstevel@tonic-gate * 1167c478bd9Sstevel@tonic-gate * NOTE: The accessor functions (cpuid_get*) are aware of, and ASSERT upon, 1177c478bd9Sstevel@tonic-gate * the pass numbers. Accordingly, changes to the pass code may require changes 1187c478bd9Sstevel@tonic-gate * to the accessor code. 1197c478bd9Sstevel@tonic-gate */ 1207c478bd9Sstevel@tonic-gate 1217c478bd9Sstevel@tonic-gate uint_t x86_vendor = X86_VENDOR_IntelClone; 1227c478bd9Sstevel@tonic-gate uint_t x86_type = X86_TYPE_OTHER; 12386c1f4dcSVikram Hegde uint_t x86_clflush_size = 0; 1247c478bd9Sstevel@tonic-gate 1257c478bd9Sstevel@tonic-gate uint_t pentiumpro_bug4046376; 1267c478bd9Sstevel@tonic-gate 127dfea898aSKuriakose Kuruvilla uchar_t x86_featureset[BT_SIZEOFMAP(NUM_X86_FEATURES)]; 1287417cfdeSKuriakose Kuruvilla 129dfea898aSKuriakose Kuruvilla static char *x86_feature_names[NUM_X86_FEATURES] = { 1307417cfdeSKuriakose Kuruvilla "lgpg", 1317417cfdeSKuriakose Kuruvilla "tsc", 1327417cfdeSKuriakose Kuruvilla "msr", 1337417cfdeSKuriakose Kuruvilla "mtrr", 1347417cfdeSKuriakose Kuruvilla "pge", 1357417cfdeSKuriakose Kuruvilla "de", 1367417cfdeSKuriakose Kuruvilla "cmov", 1377417cfdeSKuriakose Kuruvilla "mmx", 1387417cfdeSKuriakose Kuruvilla "mca", 1397417cfdeSKuriakose Kuruvilla "pae", 1407417cfdeSKuriakose Kuruvilla "cv8", 1417417cfdeSKuriakose Kuruvilla "pat", 1427417cfdeSKuriakose Kuruvilla "sep", 1437417cfdeSKuriakose Kuruvilla "sse", 1447417cfdeSKuriakose Kuruvilla "sse2", 1457417cfdeSKuriakose Kuruvilla "htt", 1467417cfdeSKuriakose Kuruvilla "asysc", 1477417cfdeSKuriakose Kuruvilla "nx", 1487417cfdeSKuriakose Kuruvilla "sse3", 1497417cfdeSKuriakose Kuruvilla "cx16", 1507417cfdeSKuriakose Kuruvilla "cmp", 1517417cfdeSKuriakose Kuruvilla "tscp", 1527417cfdeSKuriakose Kuruvilla "mwait", 1537417cfdeSKuriakose Kuruvilla "sse4a", 1547417cfdeSKuriakose Kuruvilla "cpuid", 1557417cfdeSKuriakose Kuruvilla "ssse3", 1567417cfdeSKuriakose Kuruvilla "sse4_1", 1577417cfdeSKuriakose Kuruvilla "sse4_2", 1587417cfdeSKuriakose Kuruvilla "1gpg", 1597417cfdeSKuriakose Kuruvilla "clfsh", 1607417cfdeSKuriakose Kuruvilla "64", 1617417cfdeSKuriakose Kuruvilla "aes", 1627af88ac7SKuriakose Kuruvilla "pclmulqdq", 1637af88ac7SKuriakose Kuruvilla "xsave", 164faa20166SBryan Cantrill "avx", 165faa20166SBryan Cantrill "vmx", 1667660e73fSHans Rosenfeld "svm", 167ebb8ac07SRobert Mustacchi "topoext", 168ebb8ac07SRobert Mustacchi "f16c", 1696eedf6a5SJosef 'Jeff' Sipek "rdrand", 1706eedf6a5SJosef 'Jeff' Sipek "x2apic", 171245ac945SRobert Mustacchi "avx2", 172245ac945SRobert Mustacchi "bmi1", 173245ac945SRobert Mustacchi "bmi2", 174799823bbSRobert Mustacchi "fma", 175799823bbSRobert Mustacchi "smep" 176faa20166SBryan Cantrill }; 1777417cfdeSKuriakose Kuruvilla 1787417cfdeSKuriakose Kuruvilla boolean_t 1797417cfdeSKuriakose Kuruvilla is_x86_feature(void *featureset, uint_t feature) 1807417cfdeSKuriakose Kuruvilla { 1817417cfdeSKuriakose Kuruvilla ASSERT(feature < NUM_X86_FEATURES); 1827417cfdeSKuriakose Kuruvilla return (BT_TEST((ulong_t *)featureset, feature)); 1837417cfdeSKuriakose Kuruvilla } 1847417cfdeSKuriakose Kuruvilla 1857417cfdeSKuriakose Kuruvilla void 1867417cfdeSKuriakose Kuruvilla add_x86_feature(void *featureset, uint_t feature) 1877417cfdeSKuriakose Kuruvilla { 1887417cfdeSKuriakose Kuruvilla ASSERT(feature < NUM_X86_FEATURES); 1897417cfdeSKuriakose Kuruvilla BT_SET((ulong_t *)featureset, feature); 1907417cfdeSKuriakose Kuruvilla } 1917417cfdeSKuriakose Kuruvilla 1927417cfdeSKuriakose Kuruvilla void 1937417cfdeSKuriakose Kuruvilla remove_x86_feature(void *featureset, uint_t feature) 1947417cfdeSKuriakose Kuruvilla { 1957417cfdeSKuriakose Kuruvilla ASSERT(feature < NUM_X86_FEATURES); 1967417cfdeSKuriakose Kuruvilla BT_CLEAR((ulong_t *)featureset, feature); 1977417cfdeSKuriakose Kuruvilla } 1987417cfdeSKuriakose Kuruvilla 1997417cfdeSKuriakose Kuruvilla boolean_t 2007417cfdeSKuriakose Kuruvilla compare_x86_featureset(void *setA, void *setB) 2017417cfdeSKuriakose Kuruvilla { 2027417cfdeSKuriakose Kuruvilla /* 2037417cfdeSKuriakose Kuruvilla * We assume that the unused bits of the bitmap are always zero. 2047417cfdeSKuriakose Kuruvilla */ 2057417cfdeSKuriakose Kuruvilla if (memcmp(setA, setB, BT_SIZEOFMAP(NUM_X86_FEATURES)) == 0) { 2067417cfdeSKuriakose Kuruvilla return (B_TRUE); 2077417cfdeSKuriakose Kuruvilla } else { 2087417cfdeSKuriakose Kuruvilla return (B_FALSE); 2097417cfdeSKuriakose Kuruvilla } 2107417cfdeSKuriakose Kuruvilla } 2117417cfdeSKuriakose Kuruvilla 2127417cfdeSKuriakose Kuruvilla void 2137417cfdeSKuriakose Kuruvilla print_x86_featureset(void *featureset) 2147417cfdeSKuriakose Kuruvilla { 2157417cfdeSKuriakose Kuruvilla uint_t i; 2167417cfdeSKuriakose Kuruvilla 2177417cfdeSKuriakose Kuruvilla for (i = 0; i < NUM_X86_FEATURES; i++) { 2187417cfdeSKuriakose Kuruvilla if (is_x86_feature(featureset, i)) { 2197417cfdeSKuriakose Kuruvilla cmn_err(CE_CONT, "?x86_feature: %s\n", 2207417cfdeSKuriakose Kuruvilla x86_feature_names[i]); 2217417cfdeSKuriakose Kuruvilla } 2227417cfdeSKuriakose Kuruvilla } 2237417cfdeSKuriakose Kuruvilla } 2247417cfdeSKuriakose Kuruvilla 2257af88ac7SKuriakose Kuruvilla static size_t xsave_state_size = 0; 2267af88ac7SKuriakose Kuruvilla uint64_t xsave_bv_all = (XFEATURE_LEGACY_FP | XFEATURE_SSE); 2277af88ac7SKuriakose Kuruvilla boolean_t xsave_force_disable = B_FALSE; 2287af88ac7SKuriakose Kuruvilla 2297997e108SSurya Prakki /* 23079ec9da8SYuri Pankov * This is set to platform type we are running on. 2317997e108SSurya Prakki */ 232349b53ddSStuart Maybee static int platform_type = -1; 233349b53ddSStuart Maybee 234349b53ddSStuart Maybee #if !defined(__xpv) 235349b53ddSStuart Maybee /* 236349b53ddSStuart Maybee * Variable to patch if hypervisor platform detection needs to be 237349b53ddSStuart Maybee * disabled (e.g. platform_type will always be HW_NATIVE if this is 0). 238349b53ddSStuart Maybee */ 239349b53ddSStuart Maybee int enable_platform_detection = 1; 240349b53ddSStuart Maybee #endif 2417c478bd9Sstevel@tonic-gate 2427c478bd9Sstevel@tonic-gate /* 243f98fbcecSbholler * monitor/mwait info. 2445b8a6efeSbholler * 2455b8a6efeSbholler * size_actual and buf_actual are the real address and size allocated to get 2465b8a6efeSbholler * proper mwait_buf alignement. buf_actual and size_actual should be passed 2475b8a6efeSbholler * to kmem_free(). Currently kmem_alloc() and mwait happen to both use 2485b8a6efeSbholler * processor cache-line alignment, but this is not guarantied in the furture. 249f98fbcecSbholler */ 250f98fbcecSbholler struct mwait_info { 251f98fbcecSbholler size_t mon_min; /* min size to avoid missed wakeups */ 252f98fbcecSbholler size_t mon_max; /* size to avoid false wakeups */ 2535b8a6efeSbholler size_t size_actual; /* size actually allocated */ 2545b8a6efeSbholler void *buf_actual; /* memory actually allocated */ 255f98fbcecSbholler uint32_t support; /* processor support of monitor/mwait */ 256f98fbcecSbholler }; 257f98fbcecSbholler 258f98fbcecSbholler /* 2597af88ac7SKuriakose Kuruvilla * xsave/xrestor info. 2607af88ac7SKuriakose Kuruvilla * 2617af88ac7SKuriakose Kuruvilla * This structure contains HW feature bits and size of the xsave save area. 2627af88ac7SKuriakose Kuruvilla * Note: the kernel will use the maximum size required for all hardware 2637af88ac7SKuriakose Kuruvilla * features. It is not optimize for potential memory savings if features at 2647af88ac7SKuriakose Kuruvilla * the end of the save area are not enabled. 2657af88ac7SKuriakose Kuruvilla */ 2667af88ac7SKuriakose Kuruvilla struct xsave_info { 2677af88ac7SKuriakose Kuruvilla uint32_t xsav_hw_features_low; /* Supported HW features */ 2687af88ac7SKuriakose Kuruvilla uint32_t xsav_hw_features_high; /* Supported HW features */ 2697af88ac7SKuriakose Kuruvilla size_t xsav_max_size; /* max size save area for HW features */ 2707af88ac7SKuriakose Kuruvilla size_t ymm_size; /* AVX: size of ymm save area */ 2717af88ac7SKuriakose Kuruvilla size_t ymm_offset; /* AVX: offset for ymm save area */ 2727af88ac7SKuriakose Kuruvilla }; 2737af88ac7SKuriakose Kuruvilla 2747af88ac7SKuriakose Kuruvilla 2757af88ac7SKuriakose Kuruvilla /* 2767c478bd9Sstevel@tonic-gate * These constants determine how many of the elements of the 2777c478bd9Sstevel@tonic-gate * cpuid we cache in the cpuid_info data structure; the 2787c478bd9Sstevel@tonic-gate * remaining elements are accessible via the cpuid instruction. 2797c478bd9Sstevel@tonic-gate */ 2807c478bd9Sstevel@tonic-gate 281245ac945SRobert Mustacchi #define NMAX_CPI_STD 8 /* eax = 0 .. 7 */ 2827660e73fSHans Rosenfeld #define NMAX_CPI_EXTD 0x1f /* eax = 0x80000000 .. 0x8000001e */ 2838031591dSSrihari Venkatesan 2848031591dSSrihari Venkatesan /* 2858031591dSSrihari Venkatesan * Some terminology needs to be explained: 2868031591dSSrihari Venkatesan * - Socket: Something that can be plugged into a motherboard. 2878031591dSSrihari Venkatesan * - Package: Same as socket 2888031591dSSrihari Venkatesan * - Chip: Same as socket. Note that AMD's documentation uses term "chip" 2898031591dSSrihari Venkatesan * differently: there, chip is the same as processor node (below) 2908031591dSSrihari Venkatesan * - Processor node: Some AMD processors have more than one 2918031591dSSrihari Venkatesan * "subprocessor" embedded in a package. These subprocessors (nodes) 2928031591dSSrihari Venkatesan * are fully-functional processors themselves with cores, caches, 2938031591dSSrihari Venkatesan * memory controllers, PCI configuration spaces. They are connected 2948031591dSSrihari Venkatesan * inside the package with Hypertransport links. On single-node 2958031591dSSrihari Venkatesan * processors, processor node is equivalent to chip/socket/package. 2967660e73fSHans Rosenfeld * - Compute Unit: Some AMD processors pair cores in "compute units" that 2977660e73fSHans Rosenfeld * share the FPU and the I$ and L2 caches. 2988031591dSSrihari Venkatesan */ 2997c478bd9Sstevel@tonic-gate 3007c478bd9Sstevel@tonic-gate struct cpuid_info { 3017c478bd9Sstevel@tonic-gate uint_t cpi_pass; /* last pass completed */ 3027c478bd9Sstevel@tonic-gate /* 3037c478bd9Sstevel@tonic-gate * standard function information 3047c478bd9Sstevel@tonic-gate */ 3057c478bd9Sstevel@tonic-gate uint_t cpi_maxeax; /* fn 0: %eax */ 3067c478bd9Sstevel@tonic-gate char cpi_vendorstr[13]; /* fn 0: %ebx:%ecx:%edx */ 3077c478bd9Sstevel@tonic-gate uint_t cpi_vendor; /* enum of cpi_vendorstr */ 3087c478bd9Sstevel@tonic-gate 3097c478bd9Sstevel@tonic-gate uint_t cpi_family; /* fn 1: extended family */ 3107c478bd9Sstevel@tonic-gate uint_t cpi_model; /* fn 1: extended model */ 3117c478bd9Sstevel@tonic-gate uint_t cpi_step; /* fn 1: stepping */ 3128031591dSSrihari Venkatesan chipid_t cpi_chipid; /* fn 1: %ebx: Intel: chip # */ 3138031591dSSrihari Venkatesan /* AMD: package/socket # */ 3147c478bd9Sstevel@tonic-gate uint_t cpi_brandid; /* fn 1: %ebx: brand ID */ 3157c478bd9Sstevel@tonic-gate int cpi_clogid; /* fn 1: %ebx: thread # */ 3168949bcd6Sandrei uint_t cpi_ncpu_per_chip; /* fn 1: %ebx: logical cpu count */ 3177c478bd9Sstevel@tonic-gate uint8_t cpi_cacheinfo[16]; /* fn 2: intel-style cache desc */ 3187c478bd9Sstevel@tonic-gate uint_t cpi_ncache; /* fn 2: number of elements */ 319d129bde2Sesaxe uint_t cpi_ncpu_shr_last_cache; /* fn 4: %eax: ncpus sharing cache */ 320d129bde2Sesaxe id_t cpi_last_lvl_cacheid; /* fn 4: %eax: derived cache id */ 321d129bde2Sesaxe uint_t cpi_std_4_size; /* fn 4: number of fn 4 elements */ 322d129bde2Sesaxe struct cpuid_regs **cpi_std_4; /* fn 4: %ecx == 0 .. fn4_size */ 323245ac945SRobert Mustacchi struct cpuid_regs cpi_std[NMAX_CPI_STD]; /* 0 .. 7 */ 3247c478bd9Sstevel@tonic-gate /* 3257c478bd9Sstevel@tonic-gate * extended function information 3267c478bd9Sstevel@tonic-gate */ 3277c478bd9Sstevel@tonic-gate uint_t cpi_xmaxeax; /* fn 0x80000000: %eax */ 3287c478bd9Sstevel@tonic-gate char cpi_brandstr[49]; /* fn 0x8000000[234] */ 3297c478bd9Sstevel@tonic-gate uint8_t cpi_pabits; /* fn 0x80000006: %eax */ 3307c478bd9Sstevel@tonic-gate uint8_t cpi_vabits; /* fn 0x80000006: %eax */ 3318031591dSSrihari Venkatesan struct cpuid_regs cpi_extd[NMAX_CPI_EXTD]; /* 0x800000XX */ 3328031591dSSrihari Venkatesan 33310569901Sgavinm id_t cpi_coreid; /* same coreid => strands share core */ 33410569901Sgavinm int cpi_pkgcoreid; /* core number within single package */ 3358949bcd6Sandrei uint_t cpi_ncore_per_chip; /* AMD: fn 0x80000008: %ecx[7-0] */ 3368949bcd6Sandrei /* Intel: fn 4: %eax[31-26] */ 3377c478bd9Sstevel@tonic-gate /* 3387c478bd9Sstevel@tonic-gate * supported feature information 3397c478bd9Sstevel@tonic-gate */ 340245ac945SRobert Mustacchi uint32_t cpi_support[6]; 3417c478bd9Sstevel@tonic-gate #define STD_EDX_FEATURES 0 3427c478bd9Sstevel@tonic-gate #define AMD_EDX_FEATURES 1 3437c478bd9Sstevel@tonic-gate #define TM_EDX_FEATURES 2 3447c478bd9Sstevel@tonic-gate #define STD_ECX_FEATURES 3 345ae115bc7Smrj #define AMD_ECX_FEATURES 4 346245ac945SRobert Mustacchi #define STD_EBX_FEATURES 5 3478a40a695Sgavinm /* 3488a40a695Sgavinm * Synthesized information, where known. 3498a40a695Sgavinm */ 3508a40a695Sgavinm uint32_t cpi_chiprev; /* See X86_CHIPREV_* in x86_archext.h */ 3518a40a695Sgavinm const char *cpi_chiprevstr; /* May be NULL if chiprev unknown */ 3528a40a695Sgavinm uint32_t cpi_socket; /* Chip package/socket type */ 353f98fbcecSbholler 354f98fbcecSbholler struct mwait_info cpi_mwait; /* fn 5: monitor/mwait info */ 355b6917abeSmishra uint32_t cpi_apicid; 3568031591dSSrihari Venkatesan uint_t cpi_procnodeid; /* AMD: nodeID on HT, Intel: chipid */ 3578031591dSSrihari Venkatesan uint_t cpi_procnodes_per_pkg; /* AMD: # of nodes in the package */ 3588031591dSSrihari Venkatesan /* Intel: 1 */ 3597660e73fSHans Rosenfeld uint_t cpi_compunitid; /* AMD: ComputeUnit ID, Intel: coreid */ 3607660e73fSHans Rosenfeld uint_t cpi_cores_per_compunit; /* AMD: # of cores in the ComputeUnit */ 3617af88ac7SKuriakose Kuruvilla 3627af88ac7SKuriakose Kuruvilla struct xsave_info cpi_xsave; /* fn D: xsave/xrestor info */ 3637c478bd9Sstevel@tonic-gate }; 3647c478bd9Sstevel@tonic-gate 3657c478bd9Sstevel@tonic-gate 3667c478bd9Sstevel@tonic-gate static struct cpuid_info cpuid_info0; 3677c478bd9Sstevel@tonic-gate 3687c478bd9Sstevel@tonic-gate /* 3697c478bd9Sstevel@tonic-gate * These bit fields are defined by the Intel Application Note AP-485 3707c478bd9Sstevel@tonic-gate * "Intel Processor Identification and the CPUID Instruction" 3717c478bd9Sstevel@tonic-gate */ 3727c478bd9Sstevel@tonic-gate #define CPI_FAMILY_XTD(cpi) BITX((cpi)->cpi_std[1].cp_eax, 27, 20) 3737c478bd9Sstevel@tonic-gate #define CPI_MODEL_XTD(cpi) BITX((cpi)->cpi_std[1].cp_eax, 19, 16) 3747c478bd9Sstevel@tonic-gate #define CPI_TYPE(cpi) BITX((cpi)->cpi_std[1].cp_eax, 13, 12) 3757c478bd9Sstevel@tonic-gate #define CPI_FAMILY(cpi) BITX((cpi)->cpi_std[1].cp_eax, 11, 8) 3767c478bd9Sstevel@tonic-gate #define CPI_STEP(cpi) BITX((cpi)->cpi_std[1].cp_eax, 3, 0) 3777c478bd9Sstevel@tonic-gate #define CPI_MODEL(cpi) BITX((cpi)->cpi_std[1].cp_eax, 7, 4) 3787c478bd9Sstevel@tonic-gate 3797c478bd9Sstevel@tonic-gate #define CPI_FEATURES_EDX(cpi) ((cpi)->cpi_std[1].cp_edx) 3807c478bd9Sstevel@tonic-gate #define CPI_FEATURES_ECX(cpi) ((cpi)->cpi_std[1].cp_ecx) 3817c478bd9Sstevel@tonic-gate #define CPI_FEATURES_XTD_EDX(cpi) ((cpi)->cpi_extd[1].cp_edx) 3827c478bd9Sstevel@tonic-gate #define CPI_FEATURES_XTD_ECX(cpi) ((cpi)->cpi_extd[1].cp_ecx) 383245ac945SRobert Mustacchi #define CPI_FEATURES_7_0_EBX(cpi) ((cpi)->cpi_std[7].cp_ebx) 3847c478bd9Sstevel@tonic-gate 3857c478bd9Sstevel@tonic-gate #define CPI_BRANDID(cpi) BITX((cpi)->cpi_std[1].cp_ebx, 7, 0) 3867c478bd9Sstevel@tonic-gate #define CPI_CHUNKS(cpi) BITX((cpi)->cpi_std[1].cp_ebx, 15, 7) 3877c478bd9Sstevel@tonic-gate #define CPI_CPU_COUNT(cpi) BITX((cpi)->cpi_std[1].cp_ebx, 23, 16) 3887c478bd9Sstevel@tonic-gate #define CPI_APIC_ID(cpi) BITX((cpi)->cpi_std[1].cp_ebx, 31, 24) 3897c478bd9Sstevel@tonic-gate 3907c478bd9Sstevel@tonic-gate #define CPI_MAXEAX_MAX 0x100 /* sanity control */ 3917c478bd9Sstevel@tonic-gate #define CPI_XMAXEAX_MAX 0x80000100 392d129bde2Sesaxe #define CPI_FN4_ECX_MAX 0x20 /* sanity: max fn 4 levels */ 393b6917abeSmishra #define CPI_FNB_ECX_MAX 0x20 /* sanity: max fn B levels */ 394d129bde2Sesaxe 395d129bde2Sesaxe /* 396d129bde2Sesaxe * Function 4 (Deterministic Cache Parameters) macros 397d129bde2Sesaxe * Defined by Intel Application Note AP-485 398d129bde2Sesaxe */ 399d129bde2Sesaxe #define CPI_NUM_CORES(regs) BITX((regs)->cp_eax, 31, 26) 400d129bde2Sesaxe #define CPI_NTHR_SHR_CACHE(regs) BITX((regs)->cp_eax, 25, 14) 401d129bde2Sesaxe #define CPI_FULL_ASSOC_CACHE(regs) BITX((regs)->cp_eax, 9, 9) 402d129bde2Sesaxe #define CPI_SELF_INIT_CACHE(regs) BITX((regs)->cp_eax, 8, 8) 403d129bde2Sesaxe #define CPI_CACHE_LVL(regs) BITX((regs)->cp_eax, 7, 5) 404d129bde2Sesaxe #define CPI_CACHE_TYPE(regs) BITX((regs)->cp_eax, 4, 0) 405b6917abeSmishra #define CPI_CPU_LEVEL_TYPE(regs) BITX((regs)->cp_ecx, 15, 8) 406d129bde2Sesaxe 407d129bde2Sesaxe #define CPI_CACHE_WAYS(regs) BITX((regs)->cp_ebx, 31, 22) 408d129bde2Sesaxe #define CPI_CACHE_PARTS(regs) BITX((regs)->cp_ebx, 21, 12) 409d129bde2Sesaxe #define CPI_CACHE_COH_LN_SZ(regs) BITX((regs)->cp_ebx, 11, 0) 410d129bde2Sesaxe 411d129bde2Sesaxe #define CPI_CACHE_SETS(regs) BITX((regs)->cp_ecx, 31, 0) 412d129bde2Sesaxe 413d129bde2Sesaxe #define CPI_PREFCH_STRIDE(regs) BITX((regs)->cp_edx, 9, 0) 414d129bde2Sesaxe 4157c478bd9Sstevel@tonic-gate 4167c478bd9Sstevel@tonic-gate /* 4175ff02082Sdmick * A couple of shorthand macros to identify "later" P6-family chips 4185ff02082Sdmick * like the Pentium M and Core. First, the "older" P6-based stuff 4195ff02082Sdmick * (loosely defined as "pre-Pentium-4"): 4205ff02082Sdmick * P6, PII, Mobile PII, PII Xeon, PIII, Mobile PIII, PIII Xeon 4215ff02082Sdmick */ 4225ff02082Sdmick 4235ff02082Sdmick #define IS_LEGACY_P6(cpi) ( \ 4245ff02082Sdmick cpi->cpi_family == 6 && \ 4255ff02082Sdmick (cpi->cpi_model == 1 || \ 4265ff02082Sdmick cpi->cpi_model == 3 || \ 4275ff02082Sdmick cpi->cpi_model == 5 || \ 4285ff02082Sdmick cpi->cpi_model == 6 || \ 4295ff02082Sdmick cpi->cpi_model == 7 || \ 4305ff02082Sdmick cpi->cpi_model == 8 || \ 4315ff02082Sdmick cpi->cpi_model == 0xA || \ 4325ff02082Sdmick cpi->cpi_model == 0xB) \ 4335ff02082Sdmick ) 4345ff02082Sdmick 4355ff02082Sdmick /* A "new F6" is everything with family 6 that's not the above */ 4365ff02082Sdmick #define IS_NEW_F6(cpi) ((cpi->cpi_family == 6) && !IS_LEGACY_P6(cpi)) 4375ff02082Sdmick 438bf91205bSksadhukh /* Extended family/model support */ 439bf91205bSksadhukh #define IS_EXTENDED_MODEL_INTEL(cpi) (cpi->cpi_family == 0x6 || \ 440bf91205bSksadhukh cpi->cpi_family >= 0xf) 441bf91205bSksadhukh 4425ff02082Sdmick /* 443f98fbcecSbholler * Info for monitor/mwait idle loop. 444f98fbcecSbholler * 445f98fbcecSbholler * See cpuid section of "Intel 64 and IA-32 Architectures Software Developer's 446f98fbcecSbholler * Manual Volume 2A: Instruction Set Reference, A-M" #25366-022US, November 447f98fbcecSbholler * 2006. 448f98fbcecSbholler * See MONITOR/MWAIT section of "AMD64 Architecture Programmer's Manual 449f98fbcecSbholler * Documentation Updates" #33633, Rev 2.05, December 2006. 450f98fbcecSbholler */ 451f98fbcecSbholler #define MWAIT_SUPPORT (0x00000001) /* mwait supported */ 452f98fbcecSbholler #define MWAIT_EXTENSIONS (0x00000002) /* extenstion supported */ 453f98fbcecSbholler #define MWAIT_ECX_INT_ENABLE (0x00000004) /* ecx 1 extension supported */ 454f98fbcecSbholler #define MWAIT_SUPPORTED(cpi) ((cpi)->cpi_std[1].cp_ecx & CPUID_INTC_ECX_MON) 455f98fbcecSbholler #define MWAIT_INT_ENABLE(cpi) ((cpi)->cpi_std[5].cp_ecx & 0x2) 456f98fbcecSbholler #define MWAIT_EXTENSION(cpi) ((cpi)->cpi_std[5].cp_ecx & 0x1) 457f98fbcecSbholler #define MWAIT_SIZE_MIN(cpi) BITX((cpi)->cpi_std[5].cp_eax, 15, 0) 458f98fbcecSbholler #define MWAIT_SIZE_MAX(cpi) BITX((cpi)->cpi_std[5].cp_ebx, 15, 0) 459f98fbcecSbholler /* 460f98fbcecSbholler * Number of sub-cstates for a given c-state. 461f98fbcecSbholler */ 462f98fbcecSbholler #define MWAIT_NUM_SUBC_STATES(cpi, c_state) \ 463f98fbcecSbholler BITX((cpi)->cpi_std[5].cp_edx, c_state + 3, c_state) 464f98fbcecSbholler 4658a40a695Sgavinm /* 4667af88ac7SKuriakose Kuruvilla * XSAVE leaf 0xD enumeration 4677af88ac7SKuriakose Kuruvilla */ 4687af88ac7SKuriakose Kuruvilla #define CPUID_LEAFD_2_YMM_OFFSET 576 4697af88ac7SKuriakose Kuruvilla #define CPUID_LEAFD_2_YMM_SIZE 256 4707af88ac7SKuriakose Kuruvilla 4717af88ac7SKuriakose Kuruvilla /* 472e4b86885SCheng Sean Ye * Functions we consune from cpuid_subr.c; don't publish these in a header 473e4b86885SCheng Sean Ye * file to try and keep people using the expected cpuid_* interfaces. 4748a40a695Sgavinm */ 475e4b86885SCheng Sean Ye extern uint32_t _cpuid_skt(uint_t, uint_t, uint_t, uint_t); 47689e921d5SKuriakose Kuruvilla extern const char *_cpuid_sktstr(uint_t, uint_t, uint_t, uint_t); 477e4b86885SCheng Sean Ye extern uint32_t _cpuid_chiprev(uint_t, uint_t, uint_t, uint_t); 478e4b86885SCheng Sean Ye extern const char *_cpuid_chiprevstr(uint_t, uint_t, uint_t, uint_t); 479e4b86885SCheng Sean Ye extern uint_t _cpuid_vendorstr_to_vendorcode(char *); 4808a40a695Sgavinm 4818a40a695Sgavinm /* 482ae115bc7Smrj * Apply up various platform-dependent restrictions where the 483ae115bc7Smrj * underlying platform restrictions mean the CPU can be marked 484ae115bc7Smrj * as less capable than its cpuid instruction would imply. 485ae115bc7Smrj */ 486843e1988Sjohnlev #if defined(__xpv) 487843e1988Sjohnlev static void 488843e1988Sjohnlev platform_cpuid_mangle(uint_t vendor, uint32_t eax, struct cpuid_regs *cp) 489843e1988Sjohnlev { 490843e1988Sjohnlev switch (eax) { 491e4b86885SCheng Sean Ye case 1: { 492e4b86885SCheng Sean Ye uint32_t mcamask = DOMAIN_IS_INITDOMAIN(xen_info) ? 493e4b86885SCheng Sean Ye 0 : CPUID_INTC_EDX_MCA; 494843e1988Sjohnlev cp->cp_edx &= 495e4b86885SCheng Sean Ye ~(mcamask | 496e4b86885SCheng Sean Ye CPUID_INTC_EDX_PSE | 497843e1988Sjohnlev CPUID_INTC_EDX_VME | CPUID_INTC_EDX_DE | 498843e1988Sjohnlev CPUID_INTC_EDX_SEP | CPUID_INTC_EDX_MTRR | 499843e1988Sjohnlev CPUID_INTC_EDX_PGE | CPUID_INTC_EDX_PAT | 500843e1988Sjohnlev CPUID_AMD_EDX_SYSC | CPUID_INTC_EDX_SEP | 501843e1988Sjohnlev CPUID_INTC_EDX_PSE36 | CPUID_INTC_EDX_HTT); 502843e1988Sjohnlev break; 503e4b86885SCheng Sean Ye } 504ae115bc7Smrj 505843e1988Sjohnlev case 0x80000001: 506843e1988Sjohnlev cp->cp_edx &= 507843e1988Sjohnlev ~(CPUID_AMD_EDX_PSE | 508843e1988Sjohnlev CPUID_INTC_EDX_VME | CPUID_INTC_EDX_DE | 509843e1988Sjohnlev CPUID_AMD_EDX_MTRR | CPUID_AMD_EDX_PGE | 510843e1988Sjohnlev CPUID_AMD_EDX_PAT | CPUID_AMD_EDX_PSE36 | 511843e1988Sjohnlev CPUID_AMD_EDX_SYSC | CPUID_INTC_EDX_SEP | 512843e1988Sjohnlev CPUID_AMD_EDX_TSCP); 513843e1988Sjohnlev cp->cp_ecx &= ~CPUID_AMD_ECX_CMP_LGCY; 514843e1988Sjohnlev break; 515843e1988Sjohnlev default: 516843e1988Sjohnlev break; 517843e1988Sjohnlev } 518843e1988Sjohnlev 519843e1988Sjohnlev switch (vendor) { 520843e1988Sjohnlev case X86_VENDOR_Intel: 521843e1988Sjohnlev switch (eax) { 522843e1988Sjohnlev case 4: 523843e1988Sjohnlev /* 524843e1988Sjohnlev * Zero out the (ncores-per-chip - 1) field 525843e1988Sjohnlev */ 526843e1988Sjohnlev cp->cp_eax &= 0x03fffffff; 527843e1988Sjohnlev break; 528843e1988Sjohnlev default: 529843e1988Sjohnlev break; 530843e1988Sjohnlev } 531843e1988Sjohnlev break; 532843e1988Sjohnlev case X86_VENDOR_AMD: 533843e1988Sjohnlev switch (eax) { 5342ef50f01SJoe Bonasera 5352ef50f01SJoe Bonasera case 0x80000001: 5362ef50f01SJoe Bonasera cp->cp_ecx &= ~CPUID_AMD_ECX_CR8D; 5372ef50f01SJoe Bonasera break; 5382ef50f01SJoe Bonasera 539843e1988Sjohnlev case 0x80000008: 540843e1988Sjohnlev /* 541843e1988Sjohnlev * Zero out the (ncores-per-chip - 1) field 542843e1988Sjohnlev */ 543843e1988Sjohnlev cp->cp_ecx &= 0xffffff00; 544843e1988Sjohnlev break; 545843e1988Sjohnlev default: 546843e1988Sjohnlev break; 547843e1988Sjohnlev } 548843e1988Sjohnlev break; 549843e1988Sjohnlev default: 550843e1988Sjohnlev break; 551843e1988Sjohnlev } 552843e1988Sjohnlev } 553843e1988Sjohnlev #else 554ae115bc7Smrj #define platform_cpuid_mangle(vendor, eax, cp) /* nothing */ 555843e1988Sjohnlev #endif 556ae115bc7Smrj 557ae115bc7Smrj /* 5587c478bd9Sstevel@tonic-gate * Some undocumented ways of patching the results of the cpuid 5597c478bd9Sstevel@tonic-gate * instruction to permit running Solaris 10 on future cpus that 5607c478bd9Sstevel@tonic-gate * we don't currently support. Could be set to non-zero values 5617c478bd9Sstevel@tonic-gate * via settings in eeprom. 5627c478bd9Sstevel@tonic-gate */ 5637c478bd9Sstevel@tonic-gate 5647c478bd9Sstevel@tonic-gate uint32_t cpuid_feature_ecx_include; 5657c478bd9Sstevel@tonic-gate uint32_t cpuid_feature_ecx_exclude; 5667c478bd9Sstevel@tonic-gate uint32_t cpuid_feature_edx_include; 5677c478bd9Sstevel@tonic-gate uint32_t cpuid_feature_edx_exclude; 5687c478bd9Sstevel@tonic-gate 569a3114836SGerry Liu /* 570a3114836SGerry Liu * Allocate space for mcpu_cpi in the machcpu structure for all non-boot CPUs. 571a3114836SGerry Liu */ 572ae115bc7Smrj void 573ae115bc7Smrj cpuid_alloc_space(cpu_t *cpu) 574ae115bc7Smrj { 575ae115bc7Smrj /* 576ae115bc7Smrj * By convention, cpu0 is the boot cpu, which is set up 577ae115bc7Smrj * before memory allocation is available. All other cpus get 578ae115bc7Smrj * their cpuid_info struct allocated here. 579ae115bc7Smrj */ 580ae115bc7Smrj ASSERT(cpu->cpu_id != 0); 581a3114836SGerry Liu ASSERT(cpu->cpu_m.mcpu_cpi == NULL); 582ae115bc7Smrj cpu->cpu_m.mcpu_cpi = 583ae115bc7Smrj kmem_zalloc(sizeof (*cpu->cpu_m.mcpu_cpi), KM_SLEEP); 584ae115bc7Smrj } 585ae115bc7Smrj 586ae115bc7Smrj void 587ae115bc7Smrj cpuid_free_space(cpu_t *cpu) 588ae115bc7Smrj { 589d129bde2Sesaxe struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 590d129bde2Sesaxe int i; 591d129bde2Sesaxe 592a3114836SGerry Liu ASSERT(cpi != NULL); 593a3114836SGerry Liu ASSERT(cpi != &cpuid_info0); 594d129bde2Sesaxe 595d129bde2Sesaxe /* 596d129bde2Sesaxe * Free up any function 4 related dynamic storage 597d129bde2Sesaxe */ 598d129bde2Sesaxe for (i = 1; i < cpi->cpi_std_4_size; i++) 599d129bde2Sesaxe kmem_free(cpi->cpi_std_4[i], sizeof (struct cpuid_regs)); 600d129bde2Sesaxe if (cpi->cpi_std_4_size > 0) 601d129bde2Sesaxe kmem_free(cpi->cpi_std_4, 602d129bde2Sesaxe cpi->cpi_std_4_size * sizeof (struct cpuid_regs *)); 603d129bde2Sesaxe 604a3114836SGerry Liu kmem_free(cpi, sizeof (*cpi)); 605a3114836SGerry Liu cpu->cpu_m.mcpu_cpi = NULL; 606ae115bc7Smrj } 607ae115bc7Smrj 608551bc2a6Smrj #if !defined(__xpv) 609cfe84b82SMatt Amdur /* 610cfe84b82SMatt Amdur * Determine the type of the underlying platform. This is used to customize 611cfe84b82SMatt Amdur * initialization of various subsystems (e.g. TSC). determine_platform() must 612cfe84b82SMatt Amdur * only ever be called once to prevent two processors from seeing different 61379ec9da8SYuri Pankov * values of platform_type. Must be called before cpuid_pass1(), the earliest 61479ec9da8SYuri Pankov * consumer to execute (uses _cpuid_chiprev --> synth_amd_info --> get_hwenv). 615cfe84b82SMatt Amdur */ 616cfe84b82SMatt Amdur void 617cfe84b82SMatt Amdur determine_platform(void) 618551bc2a6Smrj { 619551bc2a6Smrj struct cpuid_regs cp; 62079ec9da8SYuri Pankov uint32_t base; 62179ec9da8SYuri Pankov uint32_t regs[4]; 62279ec9da8SYuri Pankov char *hvstr = (char *)regs; 623551bc2a6Smrj 624cfe84b82SMatt Amdur ASSERT(platform_type == -1); 625cfe84b82SMatt Amdur 626349b53ddSStuart Maybee platform_type = HW_NATIVE; 627349b53ddSStuart Maybee 628349b53ddSStuart Maybee if (!enable_platform_detection) 629349b53ddSStuart Maybee return; 630349b53ddSStuart Maybee 631551bc2a6Smrj /* 63279ec9da8SYuri Pankov * If Hypervisor CPUID bit is set, try to determine hypervisor 63379ec9da8SYuri Pankov * vendor signature, and set platform type accordingly. 63479ec9da8SYuri Pankov * 63579ec9da8SYuri Pankov * References: 63679ec9da8SYuri Pankov * http://lkml.org/lkml/2008/10/1/246 63779ec9da8SYuri Pankov * http://kb.vmware.com/kb/1009458 638551bc2a6Smrj */ 63979ec9da8SYuri Pankov cp.cp_eax = 0x1; 640551bc2a6Smrj (void) __cpuid_insn(&cp); 64179ec9da8SYuri Pankov if ((cp.cp_ecx & CPUID_INTC_ECX_HV) != 0) { 64279ec9da8SYuri Pankov cp.cp_eax = 0x40000000; 64379ec9da8SYuri Pankov (void) __cpuid_insn(&cp); 64479ec9da8SYuri Pankov regs[0] = cp.cp_ebx; 64579ec9da8SYuri Pankov regs[1] = cp.cp_ecx; 64679ec9da8SYuri Pankov regs[2] = cp.cp_edx; 64779ec9da8SYuri Pankov regs[3] = 0; 64879ec9da8SYuri Pankov if (strcmp(hvstr, HVSIG_XEN_HVM) == 0) { 649b9bfdccdSStuart Maybee platform_type = HW_XEN_HVM; 6506e5580c9SFrank Van Der Linden return; 651551bc2a6Smrj } 65279ec9da8SYuri Pankov if (strcmp(hvstr, HVSIG_VMWARE) == 0) { 65379ec9da8SYuri Pankov platform_type = HW_VMWARE; 65479ec9da8SYuri Pankov return; 65579ec9da8SYuri Pankov } 65679ec9da8SYuri Pankov if (strcmp(hvstr, HVSIG_KVM) == 0) { 65779ec9da8SYuri Pankov platform_type = HW_KVM; 65879ec9da8SYuri Pankov return; 65979ec9da8SYuri Pankov } 66079ec9da8SYuri Pankov if (strcmp(hvstr, HVSIG_MICROSOFT) == 0) 66179ec9da8SYuri Pankov platform_type = HW_MICROSOFT; 66279ec9da8SYuri Pankov } else { 66379ec9da8SYuri Pankov /* 66479ec9da8SYuri Pankov * Check older VMware hardware versions. VMware hypervisor is 66579ec9da8SYuri Pankov * detected by performing an IN operation to VMware hypervisor 66679ec9da8SYuri Pankov * port and checking that value returned in %ebx is VMware 66779ec9da8SYuri Pankov * hypervisor magic value. 66879ec9da8SYuri Pankov * 66979ec9da8SYuri Pankov * References: http://kb.vmware.com/kb/1009458 67079ec9da8SYuri Pankov */ 67179ec9da8SYuri Pankov vmware_port(VMWARE_HVCMD_GETVERSION, regs); 67279ec9da8SYuri Pankov if (regs[1] == VMWARE_HVMAGIC) { 67379ec9da8SYuri Pankov platform_type = HW_VMWARE; 67479ec9da8SYuri Pankov return; 67579ec9da8SYuri Pankov } 676b9bfdccdSStuart Maybee } 677b9bfdccdSStuart Maybee 67879ec9da8SYuri Pankov /* 67979ec9da8SYuri Pankov * Check Xen hypervisor. In a fully virtualized domain, 68079ec9da8SYuri Pankov * Xen's pseudo-cpuid function returns a string representing the 68179ec9da8SYuri Pankov * Xen signature in %ebx, %ecx, and %edx. %eax contains the maximum 68279ec9da8SYuri Pankov * supported cpuid function. We need at least a (base + 2) leaf value 68379ec9da8SYuri Pankov * to do what we want to do. Try different base values, since the 68479ec9da8SYuri Pankov * hypervisor might use a different one depending on whether Hyper-V 68579ec9da8SYuri Pankov * emulation is switched on by default or not. 68679ec9da8SYuri Pankov */ 68779ec9da8SYuri Pankov for (base = 0x40000000; base < 0x40010000; base += 0x100) { 68879ec9da8SYuri Pankov cp.cp_eax = base; 68979ec9da8SYuri Pankov (void) __cpuid_insn(&cp); 69079ec9da8SYuri Pankov regs[0] = cp.cp_ebx; 69179ec9da8SYuri Pankov regs[1] = cp.cp_ecx; 69279ec9da8SYuri Pankov regs[2] = cp.cp_edx; 69379ec9da8SYuri Pankov regs[3] = 0; 69479ec9da8SYuri Pankov if (strcmp(hvstr, HVSIG_XEN_HVM) == 0 && 69579ec9da8SYuri Pankov cp.cp_eax >= (base + 2)) { 69679ec9da8SYuri Pankov platform_type &= ~HW_NATIVE; 69779ec9da8SYuri Pankov platform_type |= HW_XEN_HVM; 69879ec9da8SYuri Pankov return; 69979ec9da8SYuri Pankov } 70079ec9da8SYuri Pankov } 7016e5580c9SFrank Van Der Linden } 7026e5580c9SFrank Van Der Linden 703b9bfdccdSStuart Maybee int 704b9bfdccdSStuart Maybee get_hwenv(void) 705b9bfdccdSStuart Maybee { 706cfe84b82SMatt Amdur ASSERT(platform_type != -1); 707b9bfdccdSStuart Maybee return (platform_type); 708b9bfdccdSStuart Maybee } 709b9bfdccdSStuart Maybee 710b9bfdccdSStuart Maybee int 711b9bfdccdSStuart Maybee is_controldom(void) 712b9bfdccdSStuart Maybee { 713b9bfdccdSStuart Maybee return (0); 714b9bfdccdSStuart Maybee } 715b9bfdccdSStuart Maybee 716b9bfdccdSStuart Maybee #else 717b9bfdccdSStuart Maybee 718b9bfdccdSStuart Maybee int 719b9bfdccdSStuart Maybee get_hwenv(void) 720b9bfdccdSStuart Maybee { 721b9bfdccdSStuart Maybee return (HW_XEN_PV); 722b9bfdccdSStuart Maybee } 723b9bfdccdSStuart Maybee 724b9bfdccdSStuart Maybee int 725b9bfdccdSStuart Maybee is_controldom(void) 726b9bfdccdSStuart Maybee { 727b9bfdccdSStuart Maybee return (DOMAIN_IS_INITDOMAIN(xen_info)); 728b9bfdccdSStuart Maybee } 729b9bfdccdSStuart Maybee 730551bc2a6Smrj #endif /* __xpv */ 731551bc2a6Smrj 7328031591dSSrihari Venkatesan static void 7337417cfdeSKuriakose Kuruvilla cpuid_intel_getids(cpu_t *cpu, void *feature) 7348031591dSSrihari Venkatesan { 7358031591dSSrihari Venkatesan uint_t i; 7368031591dSSrihari Venkatesan uint_t chipid_shift = 0; 7378031591dSSrihari Venkatesan uint_t coreid_shift = 0; 7388031591dSSrihari Venkatesan struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 7398031591dSSrihari Venkatesan 7408031591dSSrihari Venkatesan for (i = 1; i < cpi->cpi_ncpu_per_chip; i <<= 1) 7418031591dSSrihari Venkatesan chipid_shift++; 7428031591dSSrihari Venkatesan 7438031591dSSrihari Venkatesan cpi->cpi_chipid = cpi->cpi_apicid >> chipid_shift; 7448031591dSSrihari Venkatesan cpi->cpi_clogid = cpi->cpi_apicid & ((1 << chipid_shift) - 1); 7458031591dSSrihari Venkatesan 7467417cfdeSKuriakose Kuruvilla if (is_x86_feature(feature, X86FSET_CMP)) { 7478031591dSSrihari Venkatesan /* 7488031591dSSrihari Venkatesan * Multi-core (and possibly multi-threaded) 7498031591dSSrihari Venkatesan * processors. 7508031591dSSrihari Venkatesan */ 7518031591dSSrihari Venkatesan uint_t ncpu_per_core; 7528031591dSSrihari Venkatesan if (cpi->cpi_ncore_per_chip == 1) 7538031591dSSrihari Venkatesan ncpu_per_core = cpi->cpi_ncpu_per_chip; 7548031591dSSrihari Venkatesan else if (cpi->cpi_ncore_per_chip > 1) 7558031591dSSrihari Venkatesan ncpu_per_core = cpi->cpi_ncpu_per_chip / 7568031591dSSrihari Venkatesan cpi->cpi_ncore_per_chip; 7578031591dSSrihari Venkatesan /* 7588031591dSSrihari Venkatesan * 8bit APIC IDs on dual core Pentiums 7598031591dSSrihari Venkatesan * look like this: 7608031591dSSrihari Venkatesan * 7618031591dSSrihari Venkatesan * +-----------------------+------+------+ 7628031591dSSrihari Venkatesan * | Physical Package ID | MC | HT | 7638031591dSSrihari Venkatesan * +-----------------------+------+------+ 7648031591dSSrihari Venkatesan * <------- chipid --------> 7658031591dSSrihari Venkatesan * <------- coreid ---------------> 7668031591dSSrihari Venkatesan * <--- clogid --> 7678031591dSSrihari Venkatesan * <------> 7688031591dSSrihari Venkatesan * pkgcoreid 7698031591dSSrihari Venkatesan * 7708031591dSSrihari Venkatesan * Where the number of bits necessary to 7718031591dSSrihari Venkatesan * represent MC and HT fields together equals 7728031591dSSrihari Venkatesan * to the minimum number of bits necessary to 7738031591dSSrihari Venkatesan * store the value of cpi->cpi_ncpu_per_chip. 7748031591dSSrihari Venkatesan * Of those bits, the MC part uses the number 7758031591dSSrihari Venkatesan * of bits necessary to store the value of 7768031591dSSrihari Venkatesan * cpi->cpi_ncore_per_chip. 7778031591dSSrihari Venkatesan */ 7788031591dSSrihari Venkatesan for (i = 1; i < ncpu_per_core; i <<= 1) 7798031591dSSrihari Venkatesan coreid_shift++; 7808031591dSSrihari Venkatesan cpi->cpi_coreid = cpi->cpi_apicid >> coreid_shift; 7818031591dSSrihari Venkatesan cpi->cpi_pkgcoreid = cpi->cpi_clogid >> coreid_shift; 7827417cfdeSKuriakose Kuruvilla } else if (is_x86_feature(feature, X86FSET_HTT)) { 7838031591dSSrihari Venkatesan /* 7848031591dSSrihari Venkatesan * Single-core multi-threaded processors. 7858031591dSSrihari Venkatesan */ 7868031591dSSrihari Venkatesan cpi->cpi_coreid = cpi->cpi_chipid; 7878031591dSSrihari Venkatesan cpi->cpi_pkgcoreid = 0; 7888031591dSSrihari Venkatesan } 7898031591dSSrihari Venkatesan cpi->cpi_procnodeid = cpi->cpi_chipid; 7907660e73fSHans Rosenfeld cpi->cpi_compunitid = cpi->cpi_coreid; 7918031591dSSrihari Venkatesan } 7928031591dSSrihari Venkatesan 7938031591dSSrihari Venkatesan static void 7948031591dSSrihari Venkatesan cpuid_amd_getids(cpu_t *cpu) 7958031591dSSrihari Venkatesan { 7961fbe4a4fSSrihari Venkatesan int i, first_half, coreidsz; 7978031591dSSrihari Venkatesan uint32_t nb_caps_reg; 7988031591dSSrihari Venkatesan uint_t node2_1; 7998031591dSSrihari Venkatesan struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 8007660e73fSHans Rosenfeld struct cpuid_regs *cp; 8018031591dSSrihari Venkatesan 8028031591dSSrihari Venkatesan /* 8038031591dSSrihari Venkatesan * AMD CMP chips currently have a single thread per core. 8048031591dSSrihari Venkatesan * 8058031591dSSrihari Venkatesan * Since no two cpus share a core we must assign a distinct coreid 8068031591dSSrihari Venkatesan * per cpu, and we do this by using the cpu_id. This scheme does not, 8078031591dSSrihari Venkatesan * however, guarantee that sibling cores of a chip will have sequential 8088031591dSSrihari Venkatesan * coreids starting at a multiple of the number of cores per chip - 8098031591dSSrihari Venkatesan * that is usually the case, but if the ACPI MADT table is presented 8108031591dSSrihari Venkatesan * in a different order then we need to perform a few more gymnastics 8118031591dSSrihari Venkatesan * for the pkgcoreid. 8128031591dSSrihari Venkatesan * 8138031591dSSrihari Venkatesan * All processors in the system have the same number of enabled 8148031591dSSrihari Venkatesan * cores. Cores within a processor are always numbered sequentially 8158031591dSSrihari Venkatesan * from 0 regardless of how many or which are disabled, and there 8168031591dSSrihari Venkatesan * is no way for operating system to discover the real core id when some 8178031591dSSrihari Venkatesan * are disabled. 8187660e73fSHans Rosenfeld * 8197660e73fSHans Rosenfeld * In family 0x15, the cores come in pairs called compute units. They 8207660e73fSHans Rosenfeld * share I$ and L2 caches and the FPU. Enumeration of this feature is 8217660e73fSHans Rosenfeld * simplified by the new topology extensions CPUID leaf, indicated by 8227660e73fSHans Rosenfeld * the X86 feature X86FSET_TOPOEXT. 8238031591dSSrihari Venkatesan */ 8248031591dSSrihari Venkatesan 8258031591dSSrihari Venkatesan cpi->cpi_coreid = cpu->cpu_id; 8267660e73fSHans Rosenfeld cpi->cpi_compunitid = cpu->cpu_id; 8278031591dSSrihari Venkatesan 8288031591dSSrihari Venkatesan if (cpi->cpi_xmaxeax >= 0x80000008) { 8298031591dSSrihari Venkatesan 8308031591dSSrihari Venkatesan coreidsz = BITX((cpi)->cpi_extd[8].cp_ecx, 15, 12); 8318031591dSSrihari Venkatesan 8328031591dSSrihari Venkatesan /* 8338031591dSSrihari Venkatesan * In AMD parlance chip is really a node while Solaris 8348031591dSSrihari Venkatesan * sees chip as equivalent to socket/package. 8358031591dSSrihari Venkatesan */ 8368031591dSSrihari Venkatesan cpi->cpi_ncore_per_chip = 8378031591dSSrihari Venkatesan BITX((cpi)->cpi_extd[8].cp_ecx, 7, 0) + 1; 8381fbe4a4fSSrihari Venkatesan if (coreidsz == 0) { 8398031591dSSrihari Venkatesan /* Use legacy method */ 8401fbe4a4fSSrihari Venkatesan for (i = 1; i < cpi->cpi_ncore_per_chip; i <<= 1) 8411fbe4a4fSSrihari Venkatesan coreidsz++; 8421fbe4a4fSSrihari Venkatesan if (coreidsz == 0) 8431fbe4a4fSSrihari Venkatesan coreidsz = 1; 8441fbe4a4fSSrihari Venkatesan } 8458031591dSSrihari Venkatesan } else { 8468031591dSSrihari Venkatesan /* Assume single-core part */ 8471fbe4a4fSSrihari Venkatesan cpi->cpi_ncore_per_chip = 1; 84872b70389SJakub Jermar coreidsz = 1; 8498031591dSSrihari Venkatesan } 8508031591dSSrihari Venkatesan 8511fbe4a4fSSrihari Venkatesan cpi->cpi_clogid = cpi->cpi_pkgcoreid = 8521fbe4a4fSSrihari Venkatesan cpi->cpi_apicid & ((1<<coreidsz) - 1); 8538031591dSSrihari Venkatesan cpi->cpi_ncpu_per_chip = cpi->cpi_ncore_per_chip; 8548031591dSSrihari Venkatesan 8557660e73fSHans Rosenfeld /* Get node ID, compute unit ID */ 8567660e73fSHans Rosenfeld if (is_x86_feature(x86_featureset, X86FSET_TOPOEXT) && 8577660e73fSHans Rosenfeld cpi->cpi_xmaxeax >= 0x8000001e) { 8587660e73fSHans Rosenfeld cp = &cpi->cpi_extd[0x1e]; 8597660e73fSHans Rosenfeld cp->cp_eax = 0x8000001e; 8607660e73fSHans Rosenfeld (void) __cpuid_insn(cp); 8617660e73fSHans Rosenfeld 8627660e73fSHans Rosenfeld cpi->cpi_procnodes_per_pkg = BITX(cp->cp_ecx, 10, 8) + 1; 8637660e73fSHans Rosenfeld cpi->cpi_procnodeid = BITX(cp->cp_ecx, 7, 0); 8647660e73fSHans Rosenfeld cpi->cpi_cores_per_compunit = BITX(cp->cp_ebx, 15, 8) + 1; 8657660e73fSHans Rosenfeld cpi->cpi_compunitid = BITX(cp->cp_ebx, 7, 0) 8667660e73fSHans Rosenfeld + (cpi->cpi_ncore_per_chip / cpi->cpi_cores_per_compunit) 8677660e73fSHans Rosenfeld * (cpi->cpi_procnodeid / cpi->cpi_procnodes_per_pkg); 8687660e73fSHans Rosenfeld } else if (cpi->cpi_family == 0xf || cpi->cpi_family >= 0x11) { 8691fbe4a4fSSrihari Venkatesan cpi->cpi_procnodeid = (cpi->cpi_apicid >> coreidsz) & 7; 8708031591dSSrihari Venkatesan } else if (cpi->cpi_family == 0x10) { 8718031591dSSrihari Venkatesan /* 8728031591dSSrihari Venkatesan * See if we are a multi-node processor. 8738031591dSSrihari Venkatesan * All processors in the system have the same number of nodes 8748031591dSSrihari Venkatesan */ 8758031591dSSrihari Venkatesan nb_caps_reg = pci_getl_func(0, 24, 3, 0xe8); 8768031591dSSrihari Venkatesan if ((cpi->cpi_model < 8) || BITX(nb_caps_reg, 29, 29) == 0) { 8778031591dSSrihari Venkatesan /* Single-node */ 8781fbe4a4fSSrihari Venkatesan cpi->cpi_procnodeid = BITX(cpi->cpi_apicid, 5, 8791fbe4a4fSSrihari Venkatesan coreidsz); 8808031591dSSrihari Venkatesan } else { 8818031591dSSrihari Venkatesan 8828031591dSSrihari Venkatesan /* 8838031591dSSrihari Venkatesan * Multi-node revision D (2 nodes per package 8848031591dSSrihari Venkatesan * are supported) 8858031591dSSrihari Venkatesan */ 8868031591dSSrihari Venkatesan cpi->cpi_procnodes_per_pkg = 2; 8878031591dSSrihari Venkatesan 8888031591dSSrihari Venkatesan first_half = (cpi->cpi_pkgcoreid <= 8898031591dSSrihari Venkatesan (cpi->cpi_ncore_per_chip/2 - 1)); 8908031591dSSrihari Venkatesan 8918031591dSSrihari Venkatesan if (cpi->cpi_apicid == cpi->cpi_pkgcoreid) { 8928031591dSSrihari Venkatesan /* We are BSP */ 8938031591dSSrihari Venkatesan cpi->cpi_procnodeid = (first_half ? 0 : 1); 8948031591dSSrihari Venkatesan } else { 8958031591dSSrihari Venkatesan 8968031591dSSrihari Venkatesan /* We are AP */ 8978031591dSSrihari Venkatesan /* NodeId[2:1] bits to use for reading F3xe8 */ 8988031591dSSrihari Venkatesan node2_1 = BITX(cpi->cpi_apicid, 5, 4) << 1; 8998031591dSSrihari Venkatesan 9008031591dSSrihari Venkatesan nb_caps_reg = 9018031591dSSrihari Venkatesan pci_getl_func(0, 24 + node2_1, 3, 0xe8); 9028031591dSSrihari Venkatesan 9038031591dSSrihari Venkatesan /* 9048031591dSSrihari Venkatesan * Check IntNodeNum bit (31:30, but bit 31 is 9058031591dSSrihari Venkatesan * always 0 on dual-node processors) 9068031591dSSrihari Venkatesan */ 9078031591dSSrihari Venkatesan if (BITX(nb_caps_reg, 30, 30) == 0) 9088031591dSSrihari Venkatesan cpi->cpi_procnodeid = node2_1 + 9098031591dSSrihari Venkatesan !first_half; 9108031591dSSrihari Venkatesan else 9118031591dSSrihari Venkatesan cpi->cpi_procnodeid = node2_1 + 9128031591dSSrihari Venkatesan first_half; 9138031591dSSrihari Venkatesan } 9148031591dSSrihari Venkatesan } 9158031591dSSrihari Venkatesan } else { 9168031591dSSrihari Venkatesan cpi->cpi_procnodeid = 0; 9178031591dSSrihari Venkatesan } 9187660e73fSHans Rosenfeld 9197660e73fSHans Rosenfeld cpi->cpi_chipid = 9207660e73fSHans Rosenfeld cpi->cpi_procnodeid / cpi->cpi_procnodes_per_pkg; 9218031591dSSrihari Venkatesan } 9228031591dSSrihari Venkatesan 9237af88ac7SKuriakose Kuruvilla /* 9247af88ac7SKuriakose Kuruvilla * Setup XFeature_Enabled_Mask register. Required by xsave feature. 9257af88ac7SKuriakose Kuruvilla */ 9267af88ac7SKuriakose Kuruvilla void 9277af88ac7SKuriakose Kuruvilla setup_xfem(void) 9287af88ac7SKuriakose Kuruvilla { 9297af88ac7SKuriakose Kuruvilla uint64_t flags = XFEATURE_LEGACY_FP; 9307af88ac7SKuriakose Kuruvilla 9317af88ac7SKuriakose Kuruvilla ASSERT(is_x86_feature(x86_featureset, X86FSET_XSAVE)); 9327af88ac7SKuriakose Kuruvilla 9337af88ac7SKuriakose Kuruvilla if (is_x86_feature(x86_featureset, X86FSET_SSE)) 9347af88ac7SKuriakose Kuruvilla flags |= XFEATURE_SSE; 9357af88ac7SKuriakose Kuruvilla 9367af88ac7SKuriakose Kuruvilla if (is_x86_feature(x86_featureset, X86FSET_AVX)) 9377af88ac7SKuriakose Kuruvilla flags |= XFEATURE_AVX; 9387af88ac7SKuriakose Kuruvilla 9397af88ac7SKuriakose Kuruvilla set_xcr(XFEATURE_ENABLED_MASK, flags); 9407af88ac7SKuriakose Kuruvilla 9417af88ac7SKuriakose Kuruvilla xsave_bv_all = flags; 9427af88ac7SKuriakose Kuruvilla } 9437af88ac7SKuriakose Kuruvilla 944dfea898aSKuriakose Kuruvilla void 945dfea898aSKuriakose Kuruvilla cpuid_pass1(cpu_t *cpu, uchar_t *featureset) 9467c478bd9Sstevel@tonic-gate { 9477c478bd9Sstevel@tonic-gate uint32_t mask_ecx, mask_edx; 9487c478bd9Sstevel@tonic-gate struct cpuid_info *cpi; 9498949bcd6Sandrei struct cpuid_regs *cp; 9507c478bd9Sstevel@tonic-gate int xcpuid; 951843e1988Sjohnlev #if !defined(__xpv) 9525b8a6efeSbholler extern int idle_cpu_prefer_mwait; 953843e1988Sjohnlev #endif 954ae115bc7Smrj 9557c478bd9Sstevel@tonic-gate /* 956a3114836SGerry Liu * Space statically allocated for BSP, ensure pointer is set 9577c478bd9Sstevel@tonic-gate */ 9587417cfdeSKuriakose Kuruvilla if (cpu->cpu_id == 0) { 9597417cfdeSKuriakose Kuruvilla if (cpu->cpu_m.mcpu_cpi == NULL) 960ae115bc7Smrj cpu->cpu_m.mcpu_cpi = &cpuid_info0; 9617417cfdeSKuriakose Kuruvilla } 9627417cfdeSKuriakose Kuruvilla 9637417cfdeSKuriakose Kuruvilla add_x86_feature(featureset, X86FSET_CPUID); 9647417cfdeSKuriakose Kuruvilla 965ae115bc7Smrj cpi = cpu->cpu_m.mcpu_cpi; 966ae115bc7Smrj ASSERT(cpi != NULL); 9677c478bd9Sstevel@tonic-gate cp = &cpi->cpi_std[0]; 9688949bcd6Sandrei cp->cp_eax = 0; 9698949bcd6Sandrei cpi->cpi_maxeax = __cpuid_insn(cp); 9707c478bd9Sstevel@tonic-gate { 9717c478bd9Sstevel@tonic-gate uint32_t *iptr = (uint32_t *)cpi->cpi_vendorstr; 9727c478bd9Sstevel@tonic-gate *iptr++ = cp->cp_ebx; 9737c478bd9Sstevel@tonic-gate *iptr++ = cp->cp_edx; 9747c478bd9Sstevel@tonic-gate *iptr++ = cp->cp_ecx; 9757c478bd9Sstevel@tonic-gate *(char *)&cpi->cpi_vendorstr[12] = '\0'; 9767c478bd9Sstevel@tonic-gate } 9777c478bd9Sstevel@tonic-gate 978e4b86885SCheng Sean Ye cpi->cpi_vendor = _cpuid_vendorstr_to_vendorcode(cpi->cpi_vendorstr); 9797c478bd9Sstevel@tonic-gate x86_vendor = cpi->cpi_vendor; /* for compatibility */ 9807c478bd9Sstevel@tonic-gate 9817c478bd9Sstevel@tonic-gate /* 9827c478bd9Sstevel@tonic-gate * Limit the range in case of weird hardware 9837c478bd9Sstevel@tonic-gate */ 9847c478bd9Sstevel@tonic-gate if (cpi->cpi_maxeax > CPI_MAXEAX_MAX) 9857c478bd9Sstevel@tonic-gate cpi->cpi_maxeax = CPI_MAXEAX_MAX; 9867c478bd9Sstevel@tonic-gate if (cpi->cpi_maxeax < 1) 9877c478bd9Sstevel@tonic-gate goto pass1_done; 9887c478bd9Sstevel@tonic-gate 9897c478bd9Sstevel@tonic-gate cp = &cpi->cpi_std[1]; 9908949bcd6Sandrei cp->cp_eax = 1; 9918949bcd6Sandrei (void) __cpuid_insn(cp); 9927c478bd9Sstevel@tonic-gate 9937c478bd9Sstevel@tonic-gate /* 9947c478bd9Sstevel@tonic-gate * Extract identifying constants for easy access. 9957c478bd9Sstevel@tonic-gate */ 9967c478bd9Sstevel@tonic-gate cpi->cpi_model = CPI_MODEL(cpi); 9977c478bd9Sstevel@tonic-gate cpi->cpi_family = CPI_FAMILY(cpi); 9987c478bd9Sstevel@tonic-gate 9995ff02082Sdmick if (cpi->cpi_family == 0xf) 10007c478bd9Sstevel@tonic-gate cpi->cpi_family += CPI_FAMILY_XTD(cpi); 10015ff02082Sdmick 100268c91426Sdmick /* 1003875b116eSkchow * Beware: AMD uses "extended model" iff base *FAMILY* == 0xf. 100468c91426Sdmick * Intel, and presumably everyone else, uses model == 0xf, as 100568c91426Sdmick * one would expect (max value means possible overflow). Sigh. 100668c91426Sdmick */ 100768c91426Sdmick 100868c91426Sdmick switch (cpi->cpi_vendor) { 1009bf91205bSksadhukh case X86_VENDOR_Intel: 1010bf91205bSksadhukh if (IS_EXTENDED_MODEL_INTEL(cpi)) 1011bf91205bSksadhukh cpi->cpi_model += CPI_MODEL_XTD(cpi) << 4; 1012447af253Sksadhukh break; 101368c91426Sdmick case X86_VENDOR_AMD: 1014875b116eSkchow if (CPI_FAMILY(cpi) == 0xf) 101568c91426Sdmick cpi->cpi_model += CPI_MODEL_XTD(cpi) << 4; 101668c91426Sdmick break; 101768c91426Sdmick default: 10185ff02082Sdmick if (cpi->cpi_model == 0xf) 10197c478bd9Sstevel@tonic-gate cpi->cpi_model += CPI_MODEL_XTD(cpi) << 4; 102068c91426Sdmick break; 102168c91426Sdmick } 10227c478bd9Sstevel@tonic-gate 10237c478bd9Sstevel@tonic-gate cpi->cpi_step = CPI_STEP(cpi); 10247c478bd9Sstevel@tonic-gate cpi->cpi_brandid = CPI_BRANDID(cpi); 10257c478bd9Sstevel@tonic-gate 10267c478bd9Sstevel@tonic-gate /* 10277c478bd9Sstevel@tonic-gate * *default* assumptions: 10287c478bd9Sstevel@tonic-gate * - believe %edx feature word 10297c478bd9Sstevel@tonic-gate * - ignore %ecx feature word 10307c478bd9Sstevel@tonic-gate * - 32-bit virtual and physical addressing 10317c478bd9Sstevel@tonic-gate */ 10327c478bd9Sstevel@tonic-gate mask_edx = 0xffffffff; 10337c478bd9Sstevel@tonic-gate mask_ecx = 0; 10347c478bd9Sstevel@tonic-gate 10357c478bd9Sstevel@tonic-gate cpi->cpi_pabits = cpi->cpi_vabits = 32; 10367c478bd9Sstevel@tonic-gate 10377c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 10387c478bd9Sstevel@tonic-gate case X86_VENDOR_Intel: 10397c478bd9Sstevel@tonic-gate if (cpi->cpi_family == 5) 10407c478bd9Sstevel@tonic-gate x86_type = X86_TYPE_P5; 10415ff02082Sdmick else if (IS_LEGACY_P6(cpi)) { 10427c478bd9Sstevel@tonic-gate x86_type = X86_TYPE_P6; 10437c478bd9Sstevel@tonic-gate pentiumpro_bug4046376 = 1; 10447c478bd9Sstevel@tonic-gate /* 10457c478bd9Sstevel@tonic-gate * Clear the SEP bit when it was set erroneously 10467c478bd9Sstevel@tonic-gate */ 10477c478bd9Sstevel@tonic-gate if (cpi->cpi_model < 3 && cpi->cpi_step < 3) 10487c478bd9Sstevel@tonic-gate cp->cp_edx &= ~CPUID_INTC_EDX_SEP; 10495ff02082Sdmick } else if (IS_NEW_F6(cpi) || cpi->cpi_family == 0xf) { 10507c478bd9Sstevel@tonic-gate x86_type = X86_TYPE_P4; 10517c478bd9Sstevel@tonic-gate /* 10527c478bd9Sstevel@tonic-gate * We don't currently depend on any of the %ecx 10537c478bd9Sstevel@tonic-gate * features until Prescott, so we'll only check 10547c478bd9Sstevel@tonic-gate * this from P4 onwards. We might want to revisit 10557c478bd9Sstevel@tonic-gate * that idea later. 10567c478bd9Sstevel@tonic-gate */ 10577c478bd9Sstevel@tonic-gate mask_ecx = 0xffffffff; 10587c478bd9Sstevel@tonic-gate } else if (cpi->cpi_family > 0xf) 10597c478bd9Sstevel@tonic-gate mask_ecx = 0xffffffff; 10607c622d23Sbholler /* 10617c622d23Sbholler * We don't support MONITOR/MWAIT if leaf 5 is not available 10627c622d23Sbholler * to obtain the monitor linesize. 10637c622d23Sbholler */ 10647c622d23Sbholler if (cpi->cpi_maxeax < 5) 10657c622d23Sbholler mask_ecx &= ~CPUID_INTC_ECX_MON; 10667c478bd9Sstevel@tonic-gate break; 10677c478bd9Sstevel@tonic-gate case X86_VENDOR_IntelClone: 10687c478bd9Sstevel@tonic-gate default: 10697c478bd9Sstevel@tonic-gate break; 10707c478bd9Sstevel@tonic-gate case X86_VENDOR_AMD: 10717c478bd9Sstevel@tonic-gate #if defined(OPTERON_ERRATUM_108) 10727c478bd9Sstevel@tonic-gate if (cpi->cpi_family == 0xf && cpi->cpi_model == 0xe) { 10737c478bd9Sstevel@tonic-gate cp->cp_eax = (0xf0f & cp->cp_eax) | 0xc0; 10747c478bd9Sstevel@tonic-gate cpi->cpi_model = 0xc; 10757c478bd9Sstevel@tonic-gate } else 10767c478bd9Sstevel@tonic-gate #endif 10777c478bd9Sstevel@tonic-gate if (cpi->cpi_family == 5) { 10787c478bd9Sstevel@tonic-gate /* 10797c478bd9Sstevel@tonic-gate * AMD K5 and K6 10807c478bd9Sstevel@tonic-gate * 10817c478bd9Sstevel@tonic-gate * These CPUs have an incomplete implementation 10827c478bd9Sstevel@tonic-gate * of MCA/MCE which we mask away. 10837c478bd9Sstevel@tonic-gate */ 10848949bcd6Sandrei mask_edx &= ~(CPUID_INTC_EDX_MCE | CPUID_INTC_EDX_MCA); 10858949bcd6Sandrei 10867c478bd9Sstevel@tonic-gate /* 10877c478bd9Sstevel@tonic-gate * Model 0 uses the wrong (APIC) bit 10887c478bd9Sstevel@tonic-gate * to indicate PGE. Fix it here. 10897c478bd9Sstevel@tonic-gate */ 10908949bcd6Sandrei if (cpi->cpi_model == 0) { 10917c478bd9Sstevel@tonic-gate if (cp->cp_edx & 0x200) { 10927c478bd9Sstevel@tonic-gate cp->cp_edx &= ~0x200; 10937c478bd9Sstevel@tonic-gate cp->cp_edx |= CPUID_INTC_EDX_PGE; 10947c478bd9Sstevel@tonic-gate } 10957c478bd9Sstevel@tonic-gate } 10968949bcd6Sandrei 10978949bcd6Sandrei /* 10988949bcd6Sandrei * Early models had problems w/ MMX; disable. 10998949bcd6Sandrei */ 11008949bcd6Sandrei if (cpi->cpi_model < 6) 11018949bcd6Sandrei mask_edx &= ~CPUID_INTC_EDX_MMX; 11028949bcd6Sandrei } 11038949bcd6Sandrei 11048949bcd6Sandrei /* 11058949bcd6Sandrei * For newer families, SSE3 and CX16, at least, are valid; 11068949bcd6Sandrei * enable all 11078949bcd6Sandrei */ 11088949bcd6Sandrei if (cpi->cpi_family >= 0xf) 11098949bcd6Sandrei mask_ecx = 0xffffffff; 11107c622d23Sbholler /* 11117c622d23Sbholler * We don't support MONITOR/MWAIT if leaf 5 is not available 11127c622d23Sbholler * to obtain the monitor linesize. 11137c622d23Sbholler */ 11147c622d23Sbholler if (cpi->cpi_maxeax < 5) 11157c622d23Sbholler mask_ecx &= ~CPUID_INTC_ECX_MON; 11165b8a6efeSbholler 1117843e1988Sjohnlev #if !defined(__xpv) 11185b8a6efeSbholler /* 11195b8a6efeSbholler * Do not use MONITOR/MWAIT to halt in the idle loop on any AMD 11205b8a6efeSbholler * processors. AMD does not intend MWAIT to be used in the cpu 11215b8a6efeSbholler * idle loop on current and future processors. 10h and future 11225b8a6efeSbholler * AMD processors use more power in MWAIT than HLT. 11235b8a6efeSbholler * Pre-family-10h Opterons do not have the MWAIT instruction. 11245b8a6efeSbholler */ 11255b8a6efeSbholler idle_cpu_prefer_mwait = 0; 1126843e1988Sjohnlev #endif 11275b8a6efeSbholler 11287c478bd9Sstevel@tonic-gate break; 11297c478bd9Sstevel@tonic-gate case X86_VENDOR_TM: 11307c478bd9Sstevel@tonic-gate /* 11317c478bd9Sstevel@tonic-gate * workaround the NT workaround in CMS 4.1 11327c478bd9Sstevel@tonic-gate */ 11337c478bd9Sstevel@tonic-gate if (cpi->cpi_family == 5 && cpi->cpi_model == 4 && 11347c478bd9Sstevel@tonic-gate (cpi->cpi_step == 2 || cpi->cpi_step == 3)) 11357c478bd9Sstevel@tonic-gate cp->cp_edx |= CPUID_INTC_EDX_CX8; 11367c478bd9Sstevel@tonic-gate break; 11377c478bd9Sstevel@tonic-gate case X86_VENDOR_Centaur: 11387c478bd9Sstevel@tonic-gate /* 11397c478bd9Sstevel@tonic-gate * workaround the NT workarounds again 11407c478bd9Sstevel@tonic-gate */ 11417c478bd9Sstevel@tonic-gate if (cpi->cpi_family == 6) 11427c478bd9Sstevel@tonic-gate cp->cp_edx |= CPUID_INTC_EDX_CX8; 11437c478bd9Sstevel@tonic-gate break; 11447c478bd9Sstevel@tonic-gate case X86_VENDOR_Cyrix: 11457c478bd9Sstevel@tonic-gate /* 11467c478bd9Sstevel@tonic-gate * We rely heavily on the probing in locore 11477c478bd9Sstevel@tonic-gate * to actually figure out what parts, if any, 11487c478bd9Sstevel@tonic-gate * of the Cyrix cpuid instruction to believe. 11497c478bd9Sstevel@tonic-gate */ 11507c478bd9Sstevel@tonic-gate switch (x86_type) { 11517c478bd9Sstevel@tonic-gate case X86_TYPE_CYRIX_486: 11527c478bd9Sstevel@tonic-gate mask_edx = 0; 11537c478bd9Sstevel@tonic-gate break; 11547c478bd9Sstevel@tonic-gate case X86_TYPE_CYRIX_6x86: 11557c478bd9Sstevel@tonic-gate mask_edx = 0; 11567c478bd9Sstevel@tonic-gate break; 11577c478bd9Sstevel@tonic-gate case X86_TYPE_CYRIX_6x86L: 11587c478bd9Sstevel@tonic-gate mask_edx = 11597c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_DE | 11607c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_CX8; 11617c478bd9Sstevel@tonic-gate break; 11627c478bd9Sstevel@tonic-gate case X86_TYPE_CYRIX_6x86MX: 11637c478bd9Sstevel@tonic-gate mask_edx = 11647c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_DE | 11657c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_MSR | 11667c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_CX8 | 11677c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_PGE | 11687c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_CMOV | 11697c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_MMX; 11707c478bd9Sstevel@tonic-gate break; 11717c478bd9Sstevel@tonic-gate case X86_TYPE_CYRIX_GXm: 11727c478bd9Sstevel@tonic-gate mask_edx = 11737c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_MSR | 11747c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_CX8 | 11757c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_CMOV | 11767c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_MMX; 11777c478bd9Sstevel@tonic-gate break; 11787c478bd9Sstevel@tonic-gate case X86_TYPE_CYRIX_MediaGX: 11797c478bd9Sstevel@tonic-gate break; 11807c478bd9Sstevel@tonic-gate case X86_TYPE_CYRIX_MII: 11817c478bd9Sstevel@tonic-gate case X86_TYPE_VIA_CYRIX_III: 11827c478bd9Sstevel@tonic-gate mask_edx = 11837c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_DE | 11847c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_TSC | 11857c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_MSR | 11867c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_CX8 | 11877c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_PGE | 11887c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_CMOV | 11897c478bd9Sstevel@tonic-gate CPUID_INTC_EDX_MMX; 11907c478bd9Sstevel@tonic-gate break; 11917c478bd9Sstevel@tonic-gate default: 11927c478bd9Sstevel@tonic-gate break; 11937c478bd9Sstevel@tonic-gate } 11947c478bd9Sstevel@tonic-gate break; 11957c478bd9Sstevel@tonic-gate } 11967c478bd9Sstevel@tonic-gate 1197843e1988Sjohnlev #if defined(__xpv) 1198843e1988Sjohnlev /* 1199843e1988Sjohnlev * Do not support MONITOR/MWAIT under a hypervisor 1200843e1988Sjohnlev */ 1201843e1988Sjohnlev mask_ecx &= ~CPUID_INTC_ECX_MON; 12027af88ac7SKuriakose Kuruvilla /* 12037af88ac7SKuriakose Kuruvilla * Do not support XSAVE under a hypervisor for now 12047af88ac7SKuriakose Kuruvilla */ 12057af88ac7SKuriakose Kuruvilla xsave_force_disable = B_TRUE; 12067af88ac7SKuriakose Kuruvilla 1207843e1988Sjohnlev #endif /* __xpv */ 1208843e1988Sjohnlev 12097af88ac7SKuriakose Kuruvilla if (xsave_force_disable) { 12107af88ac7SKuriakose Kuruvilla mask_ecx &= ~CPUID_INTC_ECX_XSAVE; 12117af88ac7SKuriakose Kuruvilla mask_ecx &= ~CPUID_INTC_ECX_AVX; 1212ebb8ac07SRobert Mustacchi mask_ecx &= ~CPUID_INTC_ECX_F16C; 1213245ac945SRobert Mustacchi mask_ecx &= ~CPUID_INTC_ECX_FMA; 12147af88ac7SKuriakose Kuruvilla } 12157af88ac7SKuriakose Kuruvilla 12167c478bd9Sstevel@tonic-gate /* 12177c478bd9Sstevel@tonic-gate * Now we've figured out the masks that determine 12187c478bd9Sstevel@tonic-gate * which bits we choose to believe, apply the masks 12197c478bd9Sstevel@tonic-gate * to the feature words, then map the kernel's view 12207c478bd9Sstevel@tonic-gate * of these feature words into its feature word. 12217c478bd9Sstevel@tonic-gate */ 12227c478bd9Sstevel@tonic-gate cp->cp_edx &= mask_edx; 12237c478bd9Sstevel@tonic-gate cp->cp_ecx &= mask_ecx; 12247c478bd9Sstevel@tonic-gate 12257c478bd9Sstevel@tonic-gate /* 1226ae115bc7Smrj * apply any platform restrictions (we don't call this 1227ae115bc7Smrj * immediately after __cpuid_insn here, because we need the 1228ae115bc7Smrj * workarounds applied above first) 12297c478bd9Sstevel@tonic-gate */ 1230ae115bc7Smrj platform_cpuid_mangle(cpi->cpi_vendor, 1, cp); 12317c478bd9Sstevel@tonic-gate 1232ae115bc7Smrj /* 1233245ac945SRobert Mustacchi * In addition to ecx and edx, Intel is storing a bunch of instruction 1234245ac945SRobert Mustacchi * set extensions in leaf 7's ebx. 1235245ac945SRobert Mustacchi */ 1236245ac945SRobert Mustacchi if (cpi->cpi_vendor == X86_VENDOR_Intel && cpi->cpi_maxeax >= 7) { 1237245ac945SRobert Mustacchi struct cpuid_regs *ecp; 1238245ac945SRobert Mustacchi ecp = &cpi->cpi_std[7]; 1239245ac945SRobert Mustacchi ecp->cp_eax = 7; 1240245ac945SRobert Mustacchi ecp->cp_ecx = 0; 1241245ac945SRobert Mustacchi (void) __cpuid_insn(ecp); 1242245ac945SRobert Mustacchi /* 1243245ac945SRobert Mustacchi * If XSAVE has been disabled, just ignore all of the AVX 1244245ac945SRobert Mustacchi * dependent flags here. 1245245ac945SRobert Mustacchi */ 1246245ac945SRobert Mustacchi if (xsave_force_disable) { 1247245ac945SRobert Mustacchi ecp->cp_ebx &= ~CPUID_INTC_EBX_7_0_BMI1; 1248245ac945SRobert Mustacchi ecp->cp_ebx &= ~CPUID_INTC_EBX_7_0_BMI2; 1249245ac945SRobert Mustacchi ecp->cp_ebx &= ~CPUID_INTC_EBX_7_0_AVX2; 1250245ac945SRobert Mustacchi } 1251799823bbSRobert Mustacchi 1252799823bbSRobert Mustacchi if (ecp->cp_ebx & CPUID_INTC_EBX_7_0_SMEP) 1253799823bbSRobert Mustacchi add_x86_feature(featureset, X86FSET_SMEP); 1254245ac945SRobert Mustacchi } 1255245ac945SRobert Mustacchi 1256245ac945SRobert Mustacchi /* 1257ae115bc7Smrj * fold in overrides from the "eeprom" mechanism 1258ae115bc7Smrj */ 12597c478bd9Sstevel@tonic-gate cp->cp_edx |= cpuid_feature_edx_include; 12607c478bd9Sstevel@tonic-gate cp->cp_edx &= ~cpuid_feature_edx_exclude; 12617c478bd9Sstevel@tonic-gate 12627c478bd9Sstevel@tonic-gate cp->cp_ecx |= cpuid_feature_ecx_include; 12637c478bd9Sstevel@tonic-gate cp->cp_ecx &= ~cpuid_feature_ecx_exclude; 12647c478bd9Sstevel@tonic-gate 12657417cfdeSKuriakose Kuruvilla if (cp->cp_edx & CPUID_INTC_EDX_PSE) { 12667417cfdeSKuriakose Kuruvilla add_x86_feature(featureset, X86FSET_LARGEPAGE); 12677417cfdeSKuriakose Kuruvilla } 12687417cfdeSKuriakose Kuruvilla if (cp->cp_edx & CPUID_INTC_EDX_TSC) { 12697417cfdeSKuriakose Kuruvilla add_x86_feature(featureset, X86FSET_TSC); 12707417cfdeSKuriakose Kuruvilla } 12717417cfdeSKuriakose Kuruvilla if (cp->cp_edx & CPUID_INTC_EDX_MSR) { 12727417cfdeSKuriakose Kuruvilla add_x86_feature(featureset, X86FSET_MSR); 12737417cfdeSKuriakose Kuruvilla } 12747417cfdeSKuriakose Kuruvilla if (cp->cp_edx & CPUID_INTC_EDX_MTRR) { 12757417cfdeSKuriakose Kuruvilla add_x86_feature(featureset, X86FSET_MTRR); 12767417cfdeSKuriakose Kuruvilla } 12777417cfdeSKuriakose Kuruvilla if (cp->cp_edx & CPUID_INTC_EDX_PGE) { 12787417cfdeSKuriakose Kuruvilla add_x86_feature(featureset, X86FSET_PGE); 12797417cfdeSKuriakose Kuruvilla } 12807417cfdeSKuriakose Kuruvilla if (cp->cp_edx & CPUID_INTC_EDX_CMOV) { 12817417cfdeSKuriakose Kuruvilla add_x86_feature(featureset, X86FSET_CMOV); 12827417cfdeSKuriakose Kuruvilla } 12837417cfdeSKuriakose Kuruvilla if (cp->cp_edx & CPUID_INTC_EDX_MMX) { 12847417cfdeSKuriakose Kuruvilla add_x86_feature(featureset, X86FSET_MMX); 12857417cfdeSKuriakose Kuruvilla } 12867c478bd9Sstevel@tonic-gate if ((cp->cp_edx & CPUID_INTC_EDX_MCE) != 0 && 12877417cfdeSKuriakose Kuruvilla (cp->cp_edx & CPUID_INTC_EDX_MCA) != 0) { 12887417cfdeSKuriakose Kuruvilla add_x86_feature(featureset, X86FSET_MCA); 12897417cfdeSKuriakose Kuruvilla } 12907417cfdeSKuriakose Kuruvilla if (cp->cp_edx & CPUID_INTC_EDX_PAE) { 12917417cfdeSKuriakose Kuruvilla add_x86_feature(featureset, X86FSET_PAE); 12927417cfdeSKuriakose Kuruvilla } 12937417cfdeSKuriakose Kuruvilla if (cp->cp_edx & CPUID_INTC_EDX_CX8) { 12947417cfdeSKuriakose Kuruvilla add_x86_feature(featureset, X86FSET_CX8); 12957417cfdeSKuriakose Kuruvilla } 12967417cfdeSKuriakose Kuruvilla if (cp->cp_ecx & CPUID_INTC_ECX_CX16) { 12977417cfdeSKuriakose Kuruvilla add_x86_feature(featureset, X86FSET_CX16); 12987417cfdeSKuriakose Kuruvilla } 12997417cfdeSKuriakose Kuruvilla if (cp->cp_edx & CPUID_INTC_EDX_PAT) { 13007417cfdeSKuriakose Kuruvilla add_x86_feature(featureset, X86FSET_PAT); 13017417cfdeSKuriakose Kuruvilla } 13027417cfdeSKuriakose Kuruvilla if (cp->cp_edx & CPUID_INTC_EDX_SEP) { 13037417cfdeSKuriakose Kuruvilla add_x86_feature(featureset, X86FSET_SEP); 13047417cfdeSKuriakose Kuruvilla } 13057c478bd9Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_FXSR) { 13067c478bd9Sstevel@tonic-gate /* 13077c478bd9Sstevel@tonic-gate * In our implementation, fxsave/fxrstor 13087c478bd9Sstevel@tonic-gate * are prerequisites before we'll even 13097c478bd9Sstevel@tonic-gate * try and do SSE things. 13107c478bd9Sstevel@tonic-gate */ 13117417cfdeSKuriakose Kuruvilla if (cp->cp_edx & CPUID_INTC_EDX_SSE) { 13127417cfdeSKuriakose Kuruvilla add_x86_feature(featureset, X86FSET_SSE); 13137417cfdeSKuriakose Kuruvilla } 13147417cfdeSKuriakose Kuruvilla if (cp->cp_edx & CPUID_INTC_EDX_SSE2) { 13157417cfdeSKuriakose Kuruvilla add_x86_feature(featureset, X86FSET_SSE2); 13167417cfdeSKuriakose Kuruvilla } 13177417cfdeSKuriakose Kuruvilla if (cp->cp_ecx & CPUID_INTC_ECX_SSE3) { 13187417cfdeSKuriakose Kuruvilla add_x86_feature(featureset, X86FSET_SSE3); 13197417cfdeSKuriakose Kuruvilla } 13207417cfdeSKuriakose Kuruvilla if (cp->cp_ecx & CPUID_INTC_ECX_SSSE3) { 13217417cfdeSKuriakose Kuruvilla add_x86_feature(featureset, X86FSET_SSSE3); 13227417cfdeSKuriakose Kuruvilla } 13237417cfdeSKuriakose Kuruvilla if (cp->cp_ecx & CPUID_INTC_ECX_SSE4_1) { 13247417cfdeSKuriakose Kuruvilla add_x86_feature(featureset, X86FSET_SSE4_1); 13257417cfdeSKuriakose Kuruvilla } 13267417cfdeSKuriakose Kuruvilla if (cp->cp_ecx & CPUID_INTC_ECX_SSE4_2) { 13277417cfdeSKuriakose Kuruvilla add_x86_feature(featureset, X86FSET_SSE4_2); 13287417cfdeSKuriakose Kuruvilla } 13297417cfdeSKuriakose Kuruvilla if (cp->cp_ecx & CPUID_INTC_ECX_AES) { 13307417cfdeSKuriakose Kuruvilla add_x86_feature(featureset, X86FSET_AES); 13317417cfdeSKuriakose Kuruvilla } 13327417cfdeSKuriakose Kuruvilla if (cp->cp_ecx & CPUID_INTC_ECX_PCLMULQDQ) { 13337417cfdeSKuriakose Kuruvilla add_x86_feature(featureset, X86FSET_PCLMULQDQ); 1334d0f8ff6eSkk208521 } 13357af88ac7SKuriakose Kuruvilla 13367af88ac7SKuriakose Kuruvilla if (cp->cp_ecx & CPUID_INTC_ECX_XSAVE) { 13377af88ac7SKuriakose Kuruvilla add_x86_feature(featureset, X86FSET_XSAVE); 1338ebb8ac07SRobert Mustacchi 13397af88ac7SKuriakose Kuruvilla /* We only test AVX when there is XSAVE */ 13407af88ac7SKuriakose Kuruvilla if (cp->cp_ecx & CPUID_INTC_ECX_AVX) { 13417af88ac7SKuriakose Kuruvilla add_x86_feature(featureset, 13427af88ac7SKuriakose Kuruvilla X86FSET_AVX); 1343ebb8ac07SRobert Mustacchi 1344245ac945SRobert Mustacchi /* 1345245ac945SRobert Mustacchi * Intel says we can't check these without also 1346245ac945SRobert Mustacchi * checking AVX. 1347245ac945SRobert Mustacchi */ 1348ebb8ac07SRobert Mustacchi if (cp->cp_ecx & CPUID_INTC_ECX_F16C) 1349ebb8ac07SRobert Mustacchi add_x86_feature(featureset, 1350ebb8ac07SRobert Mustacchi X86FSET_F16C); 1351245ac945SRobert Mustacchi 1352245ac945SRobert Mustacchi if (cp->cp_ecx & CPUID_INTC_ECX_FMA) 1353245ac945SRobert Mustacchi add_x86_feature(featureset, 1354245ac945SRobert Mustacchi X86FSET_FMA); 1355245ac945SRobert Mustacchi 1356245ac945SRobert Mustacchi if (cpi->cpi_std[7].cp_ebx & 1357245ac945SRobert Mustacchi CPUID_INTC_EBX_7_0_BMI1) 1358245ac945SRobert Mustacchi add_x86_feature(featureset, 1359245ac945SRobert Mustacchi X86FSET_BMI1); 1360245ac945SRobert Mustacchi 1361245ac945SRobert Mustacchi if (cpi->cpi_std[7].cp_ebx & 1362245ac945SRobert Mustacchi CPUID_INTC_EBX_7_0_BMI2) 1363245ac945SRobert Mustacchi add_x86_feature(featureset, 1364245ac945SRobert Mustacchi X86FSET_BMI2); 1365245ac945SRobert Mustacchi 1366245ac945SRobert Mustacchi if (cpi->cpi_std[7].cp_ebx & 1367245ac945SRobert Mustacchi CPUID_INTC_EBX_7_0_AVX2) 1368245ac945SRobert Mustacchi add_x86_feature(featureset, 1369245ac945SRobert Mustacchi X86FSET_AVX2); 13707af88ac7SKuriakose Kuruvilla } 13717af88ac7SKuriakose Kuruvilla } 13727c478bd9Sstevel@tonic-gate } 13736eedf6a5SJosef 'Jeff' Sipek if (cp->cp_ecx & CPUID_INTC_ECX_X2APIC) { 13746eedf6a5SJosef 'Jeff' Sipek add_x86_feature(featureset, X86FSET_X2APIC); 13756eedf6a5SJosef 'Jeff' Sipek } 13767417cfdeSKuriakose Kuruvilla if (cp->cp_edx & CPUID_INTC_EDX_DE) { 13777417cfdeSKuriakose Kuruvilla add_x86_feature(featureset, X86FSET_DE); 13787417cfdeSKuriakose Kuruvilla } 13791d1a3942SBill Holler #if !defined(__xpv) 1380f98fbcecSbholler if (cp->cp_ecx & CPUID_INTC_ECX_MON) { 13811d1a3942SBill Holler 13821d1a3942SBill Holler /* 13831d1a3942SBill Holler * We require the CLFLUSH instruction for erratum workaround 13841d1a3942SBill Holler * to use MONITOR/MWAIT. 13851d1a3942SBill Holler */ 13861d1a3942SBill Holler if (cp->cp_edx & CPUID_INTC_EDX_CLFSH) { 1387f98fbcecSbholler cpi->cpi_mwait.support |= MWAIT_SUPPORT; 13887417cfdeSKuriakose Kuruvilla add_x86_feature(featureset, X86FSET_MWAIT); 13891d1a3942SBill Holler } else { 13901d1a3942SBill Holler extern int idle_cpu_assert_cflush_monitor; 13911d1a3942SBill Holler 13921d1a3942SBill Holler /* 13931d1a3942SBill Holler * All processors we are aware of which have 13941d1a3942SBill Holler * MONITOR/MWAIT also have CLFLUSH. 13951d1a3942SBill Holler */ 13961d1a3942SBill Holler if (idle_cpu_assert_cflush_monitor) { 13971d1a3942SBill Holler ASSERT((cp->cp_ecx & CPUID_INTC_ECX_MON) && 13981d1a3942SBill Holler (cp->cp_edx & CPUID_INTC_EDX_CLFSH)); 1399f98fbcecSbholler } 14001d1a3942SBill Holler } 14011d1a3942SBill Holler } 14021d1a3942SBill Holler #endif /* __xpv */ 14037c478bd9Sstevel@tonic-gate 1404faa20166SBryan Cantrill if (cp->cp_ecx & CPUID_INTC_ECX_VMX) { 1405faa20166SBryan Cantrill add_x86_feature(featureset, X86FSET_VMX); 1406faa20166SBryan Cantrill } 1407faa20166SBryan Cantrill 1408ebb8ac07SRobert Mustacchi if (cp->cp_ecx & CPUID_INTC_ECX_RDRAND) 1409ebb8ac07SRobert Mustacchi add_x86_feature(featureset, X86FSET_RDRAND); 1410ebb8ac07SRobert Mustacchi 141186c1f4dcSVikram Hegde /* 1412faa20166SBryan Cantrill * Only need it first time, rest of the cpus would follow suit. 141386c1f4dcSVikram Hegde * we only capture this for the bootcpu. 141486c1f4dcSVikram Hegde */ 141586c1f4dcSVikram Hegde if (cp->cp_edx & CPUID_INTC_EDX_CLFSH) { 14167417cfdeSKuriakose Kuruvilla add_x86_feature(featureset, X86FSET_CLFSH); 141786c1f4dcSVikram Hegde x86_clflush_size = (BITX(cp->cp_ebx, 15, 8) * 8); 141886c1f4dcSVikram Hegde } 14197417cfdeSKuriakose Kuruvilla if (is_x86_feature(featureset, X86FSET_PAE)) 14207c478bd9Sstevel@tonic-gate cpi->cpi_pabits = 36; 14217c478bd9Sstevel@tonic-gate 14227c478bd9Sstevel@tonic-gate /* 14237c478bd9Sstevel@tonic-gate * Hyperthreading configuration is slightly tricky on Intel 14247c478bd9Sstevel@tonic-gate * and pure clones, and even trickier on AMD. 14257c478bd9Sstevel@tonic-gate * 14267c478bd9Sstevel@tonic-gate * (AMD chose to set the HTT bit on their CMP processors, 14277c478bd9Sstevel@tonic-gate * even though they're not actually hyperthreaded. Thus it 14287c478bd9Sstevel@tonic-gate * takes a bit more work to figure out what's really going 1429ae115bc7Smrj * on ... see the handling of the CMP_LGCY bit below) 14307c478bd9Sstevel@tonic-gate */ 14317c478bd9Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_HTT) { 14327c478bd9Sstevel@tonic-gate cpi->cpi_ncpu_per_chip = CPI_CPU_COUNT(cpi); 14337c478bd9Sstevel@tonic-gate if (cpi->cpi_ncpu_per_chip > 1) 14347417cfdeSKuriakose Kuruvilla add_x86_feature(featureset, X86FSET_HTT); 14358949bcd6Sandrei } else { 14368949bcd6Sandrei cpi->cpi_ncpu_per_chip = 1; 14377c478bd9Sstevel@tonic-gate } 14387c478bd9Sstevel@tonic-gate 14397c478bd9Sstevel@tonic-gate /* 14407c478bd9Sstevel@tonic-gate * Work on the "extended" feature information, doing 14417c478bd9Sstevel@tonic-gate * some basic initialization for cpuid_pass2() 14427c478bd9Sstevel@tonic-gate */ 14437c478bd9Sstevel@tonic-gate xcpuid = 0; 14447c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 14457c478bd9Sstevel@tonic-gate case X86_VENDOR_Intel: 14465ff02082Sdmick if (IS_NEW_F6(cpi) || cpi->cpi_family >= 0xf) 14477c478bd9Sstevel@tonic-gate xcpuid++; 14487c478bd9Sstevel@tonic-gate break; 14497c478bd9Sstevel@tonic-gate case X86_VENDOR_AMD: 14507c478bd9Sstevel@tonic-gate if (cpi->cpi_family > 5 || 14517c478bd9Sstevel@tonic-gate (cpi->cpi_family == 5 && cpi->cpi_model >= 1)) 14527c478bd9Sstevel@tonic-gate xcpuid++; 14537c478bd9Sstevel@tonic-gate break; 14547c478bd9Sstevel@tonic-gate case X86_VENDOR_Cyrix: 14557c478bd9Sstevel@tonic-gate /* 14567c478bd9Sstevel@tonic-gate * Only these Cyrix CPUs are -known- to support 14577c478bd9Sstevel@tonic-gate * extended cpuid operations. 14587c478bd9Sstevel@tonic-gate */ 14597c478bd9Sstevel@tonic-gate if (x86_type == X86_TYPE_VIA_CYRIX_III || 14607c478bd9Sstevel@tonic-gate x86_type == X86_TYPE_CYRIX_GXm) 14617c478bd9Sstevel@tonic-gate xcpuid++; 14627c478bd9Sstevel@tonic-gate break; 14637c478bd9Sstevel@tonic-gate case X86_VENDOR_Centaur: 14647c478bd9Sstevel@tonic-gate case X86_VENDOR_TM: 14657c478bd9Sstevel@tonic-gate default: 14667c478bd9Sstevel@tonic-gate xcpuid++; 14677c478bd9Sstevel@tonic-gate break; 14687c478bd9Sstevel@tonic-gate } 14697c478bd9Sstevel@tonic-gate 14707c478bd9Sstevel@tonic-gate if (xcpuid) { 14717c478bd9Sstevel@tonic-gate cp = &cpi->cpi_extd[0]; 14728949bcd6Sandrei cp->cp_eax = 0x80000000; 14738949bcd6Sandrei cpi->cpi_xmaxeax = __cpuid_insn(cp); 14747c478bd9Sstevel@tonic-gate } 14757c478bd9Sstevel@tonic-gate 14767c478bd9Sstevel@tonic-gate if (cpi->cpi_xmaxeax & 0x80000000) { 14777c478bd9Sstevel@tonic-gate 14787c478bd9Sstevel@tonic-gate if (cpi->cpi_xmaxeax > CPI_XMAXEAX_MAX) 14797c478bd9Sstevel@tonic-gate cpi->cpi_xmaxeax = CPI_XMAXEAX_MAX; 14807c478bd9Sstevel@tonic-gate 14817c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 14827c478bd9Sstevel@tonic-gate case X86_VENDOR_Intel: 14837c478bd9Sstevel@tonic-gate case X86_VENDOR_AMD: 14847c478bd9Sstevel@tonic-gate if (cpi->cpi_xmaxeax < 0x80000001) 14857c478bd9Sstevel@tonic-gate break; 14867c478bd9Sstevel@tonic-gate cp = &cpi->cpi_extd[1]; 14878949bcd6Sandrei cp->cp_eax = 0x80000001; 14888949bcd6Sandrei (void) __cpuid_insn(cp); 1489ae115bc7Smrj 14907c478bd9Sstevel@tonic-gate if (cpi->cpi_vendor == X86_VENDOR_AMD && 14917c478bd9Sstevel@tonic-gate cpi->cpi_family == 5 && 14927c478bd9Sstevel@tonic-gate cpi->cpi_model == 6 && 14937c478bd9Sstevel@tonic-gate cpi->cpi_step == 6) { 14947c478bd9Sstevel@tonic-gate /* 14957c478bd9Sstevel@tonic-gate * K6 model 6 uses bit 10 to indicate SYSC 14967c478bd9Sstevel@tonic-gate * Later models use bit 11. Fix it here. 14977c478bd9Sstevel@tonic-gate */ 14987c478bd9Sstevel@tonic-gate if (cp->cp_edx & 0x400) { 14997c478bd9Sstevel@tonic-gate cp->cp_edx &= ~0x400; 15007c478bd9Sstevel@tonic-gate cp->cp_edx |= CPUID_AMD_EDX_SYSC; 15017c478bd9Sstevel@tonic-gate } 15027c478bd9Sstevel@tonic-gate } 15037c478bd9Sstevel@tonic-gate 1504ae115bc7Smrj platform_cpuid_mangle(cpi->cpi_vendor, 0x80000001, cp); 1505ae115bc7Smrj 15067c478bd9Sstevel@tonic-gate /* 15077c478bd9Sstevel@tonic-gate * Compute the additions to the kernel's feature word. 15087c478bd9Sstevel@tonic-gate */ 15097417cfdeSKuriakose Kuruvilla if (cp->cp_edx & CPUID_AMD_EDX_NX) { 15107417cfdeSKuriakose Kuruvilla add_x86_feature(featureset, X86FSET_NX); 15117417cfdeSKuriakose Kuruvilla } 15127c478bd9Sstevel@tonic-gate 151319397407SSherry Moore /* 151419397407SSherry Moore * Regardless whether or not we boot 64-bit, 151519397407SSherry Moore * we should have a way to identify whether 151619397407SSherry Moore * the CPU is capable of running 64-bit. 151719397407SSherry Moore */ 15187417cfdeSKuriakose Kuruvilla if (cp->cp_edx & CPUID_AMD_EDX_LM) { 15197417cfdeSKuriakose Kuruvilla add_x86_feature(featureset, X86FSET_64); 15207417cfdeSKuriakose Kuruvilla } 152119397407SSherry Moore 152202bc52beSkchow #if defined(__amd64) 152302bc52beSkchow /* 1 GB large page - enable only for 64 bit kernel */ 15247417cfdeSKuriakose Kuruvilla if (cp->cp_edx & CPUID_AMD_EDX_1GPG) { 15257417cfdeSKuriakose Kuruvilla add_x86_feature(featureset, X86FSET_1GPG); 15267417cfdeSKuriakose Kuruvilla } 152702bc52beSkchow #endif 152802bc52beSkchow 1529f8801251Skk208521 if ((cpi->cpi_vendor == X86_VENDOR_AMD) && 1530f8801251Skk208521 (cpi->cpi_std[1].cp_edx & CPUID_INTC_EDX_FXSR) && 15317417cfdeSKuriakose Kuruvilla (cp->cp_ecx & CPUID_AMD_ECX_SSE4A)) { 15327417cfdeSKuriakose Kuruvilla add_x86_feature(featureset, X86FSET_SSE4A); 15337417cfdeSKuriakose Kuruvilla } 1534f8801251Skk208521 15357c478bd9Sstevel@tonic-gate /* 1536ae115bc7Smrj * If both the HTT and CMP_LGCY bits are set, 15378949bcd6Sandrei * then we're not actually HyperThreaded. Read 15388949bcd6Sandrei * "AMD CPUID Specification" for more details. 15397c478bd9Sstevel@tonic-gate */ 15407c478bd9Sstevel@tonic-gate if (cpi->cpi_vendor == X86_VENDOR_AMD && 15417417cfdeSKuriakose Kuruvilla is_x86_feature(featureset, X86FSET_HTT) && 1542ae115bc7Smrj (cp->cp_ecx & CPUID_AMD_ECX_CMP_LGCY)) { 15437417cfdeSKuriakose Kuruvilla remove_x86_feature(featureset, X86FSET_HTT); 15447417cfdeSKuriakose Kuruvilla add_x86_feature(featureset, X86FSET_CMP); 15458949bcd6Sandrei } 1546ae115bc7Smrj #if defined(__amd64) 15477c478bd9Sstevel@tonic-gate /* 15487c478bd9Sstevel@tonic-gate * It's really tricky to support syscall/sysret in 15497c478bd9Sstevel@tonic-gate * the i386 kernel; we rely on sysenter/sysexit 15507c478bd9Sstevel@tonic-gate * instead. In the amd64 kernel, things are -way- 15517c478bd9Sstevel@tonic-gate * better. 15527c478bd9Sstevel@tonic-gate */ 15537417cfdeSKuriakose Kuruvilla if (cp->cp_edx & CPUID_AMD_EDX_SYSC) { 15547417cfdeSKuriakose Kuruvilla add_x86_feature(featureset, X86FSET_ASYSC); 15557417cfdeSKuriakose Kuruvilla } 15567c478bd9Sstevel@tonic-gate 15577c478bd9Sstevel@tonic-gate /* 15587c478bd9Sstevel@tonic-gate * While we're thinking about system calls, note 15597c478bd9Sstevel@tonic-gate * that AMD processors don't support sysenter 15607c478bd9Sstevel@tonic-gate * in long mode at all, so don't try to program them. 15617c478bd9Sstevel@tonic-gate */ 15627417cfdeSKuriakose Kuruvilla if (x86_vendor == X86_VENDOR_AMD) { 15637417cfdeSKuriakose Kuruvilla remove_x86_feature(featureset, X86FSET_SEP); 15647417cfdeSKuriakose Kuruvilla } 15657c478bd9Sstevel@tonic-gate #endif 15667417cfdeSKuriakose Kuruvilla if (cp->cp_edx & CPUID_AMD_EDX_TSCP) { 15677417cfdeSKuriakose Kuruvilla add_x86_feature(featureset, X86FSET_TSCP); 15687417cfdeSKuriakose Kuruvilla } 1569faa20166SBryan Cantrill 1570faa20166SBryan Cantrill if (cp->cp_ecx & CPUID_AMD_ECX_SVM) { 1571faa20166SBryan Cantrill add_x86_feature(featureset, X86FSET_SVM); 1572faa20166SBryan Cantrill } 15737660e73fSHans Rosenfeld 15747660e73fSHans Rosenfeld if (cp->cp_ecx & CPUID_AMD_ECX_TOPOEXT) { 15757660e73fSHans Rosenfeld add_x86_feature(featureset, X86FSET_TOPOEXT); 15767660e73fSHans Rosenfeld } 15777c478bd9Sstevel@tonic-gate break; 15787c478bd9Sstevel@tonic-gate default: 15797c478bd9Sstevel@tonic-gate break; 15807c478bd9Sstevel@tonic-gate } 15817c478bd9Sstevel@tonic-gate 15828949bcd6Sandrei /* 15838949bcd6Sandrei * Get CPUID data about processor cores and hyperthreads. 15848949bcd6Sandrei */ 15857c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 15867c478bd9Sstevel@tonic-gate case X86_VENDOR_Intel: 15878949bcd6Sandrei if (cpi->cpi_maxeax >= 4) { 15888949bcd6Sandrei cp = &cpi->cpi_std[4]; 15898949bcd6Sandrei cp->cp_eax = 4; 15908949bcd6Sandrei cp->cp_ecx = 0; 15918949bcd6Sandrei (void) __cpuid_insn(cp); 1592ae115bc7Smrj platform_cpuid_mangle(cpi->cpi_vendor, 4, cp); 15938949bcd6Sandrei } 15948949bcd6Sandrei /*FALLTHROUGH*/ 15957c478bd9Sstevel@tonic-gate case X86_VENDOR_AMD: 15967c478bd9Sstevel@tonic-gate if (cpi->cpi_xmaxeax < 0x80000008) 15977c478bd9Sstevel@tonic-gate break; 15987c478bd9Sstevel@tonic-gate cp = &cpi->cpi_extd[8]; 15998949bcd6Sandrei cp->cp_eax = 0x80000008; 16008949bcd6Sandrei (void) __cpuid_insn(cp); 1601ae115bc7Smrj platform_cpuid_mangle(cpi->cpi_vendor, 0x80000008, cp); 1602ae115bc7Smrj 16037c478bd9Sstevel@tonic-gate /* 16047c478bd9Sstevel@tonic-gate * Virtual and physical address limits from 16057c478bd9Sstevel@tonic-gate * cpuid override previously guessed values. 16067c478bd9Sstevel@tonic-gate */ 16077c478bd9Sstevel@tonic-gate cpi->cpi_pabits = BITX(cp->cp_eax, 7, 0); 16087c478bd9Sstevel@tonic-gate cpi->cpi_vabits = BITX(cp->cp_eax, 15, 8); 16097c478bd9Sstevel@tonic-gate break; 16107c478bd9Sstevel@tonic-gate default: 16117c478bd9Sstevel@tonic-gate break; 16127c478bd9Sstevel@tonic-gate } 16138949bcd6Sandrei 1614d129bde2Sesaxe /* 1615d129bde2Sesaxe * Derive the number of cores per chip 1616d129bde2Sesaxe */ 16178949bcd6Sandrei switch (cpi->cpi_vendor) { 16188949bcd6Sandrei case X86_VENDOR_Intel: 16198949bcd6Sandrei if (cpi->cpi_maxeax < 4) { 16208949bcd6Sandrei cpi->cpi_ncore_per_chip = 1; 16218949bcd6Sandrei break; 16228949bcd6Sandrei } else { 16238949bcd6Sandrei cpi->cpi_ncore_per_chip = 16248949bcd6Sandrei BITX((cpi)->cpi_std[4].cp_eax, 31, 26) + 1; 16258949bcd6Sandrei } 16268949bcd6Sandrei break; 16278949bcd6Sandrei case X86_VENDOR_AMD: 16288949bcd6Sandrei if (cpi->cpi_xmaxeax < 0x80000008) { 16298949bcd6Sandrei cpi->cpi_ncore_per_chip = 1; 16308949bcd6Sandrei break; 16318949bcd6Sandrei } else { 163210569901Sgavinm /* 163310569901Sgavinm * On family 0xf cpuid fn 2 ECX[7:0] "NC" is 163410569901Sgavinm * 1 less than the number of physical cores on 163510569901Sgavinm * the chip. In family 0x10 this value can 163610569901Sgavinm * be affected by "downcoring" - it reflects 163710569901Sgavinm * 1 less than the number of cores actually 163810569901Sgavinm * enabled on this node. 163910569901Sgavinm */ 16408949bcd6Sandrei cpi->cpi_ncore_per_chip = 16418949bcd6Sandrei BITX((cpi)->cpi_extd[8].cp_ecx, 7, 0) + 1; 16428949bcd6Sandrei } 16438949bcd6Sandrei break; 16448949bcd6Sandrei default: 16458949bcd6Sandrei cpi->cpi_ncore_per_chip = 1; 16468949bcd6Sandrei break; 16477c478bd9Sstevel@tonic-gate } 16480e751525SEric Saxe 16490e751525SEric Saxe /* 16500e751525SEric Saxe * Get CPUID data about TSC Invariance in Deep C-State. 16510e751525SEric Saxe */ 16520e751525SEric Saxe switch (cpi->cpi_vendor) { 16530e751525SEric Saxe case X86_VENDOR_Intel: 16540e751525SEric Saxe if (cpi->cpi_maxeax >= 7) { 16550e751525SEric Saxe cp = &cpi->cpi_extd[7]; 16560e751525SEric Saxe cp->cp_eax = 0x80000007; 16570e751525SEric Saxe cp->cp_ecx = 0; 16580e751525SEric Saxe (void) __cpuid_insn(cp); 16590e751525SEric Saxe } 16600e751525SEric Saxe break; 16610e751525SEric Saxe default: 16620e751525SEric Saxe break; 16630e751525SEric Saxe } 1664fa2e767eSgavinm } else { 1665fa2e767eSgavinm cpi->cpi_ncore_per_chip = 1; 16668949bcd6Sandrei } 16678949bcd6Sandrei 16688949bcd6Sandrei /* 16698949bcd6Sandrei * If more than one core, then this processor is CMP. 16708949bcd6Sandrei */ 16717417cfdeSKuriakose Kuruvilla if (cpi->cpi_ncore_per_chip > 1) { 16727417cfdeSKuriakose Kuruvilla add_x86_feature(featureset, X86FSET_CMP); 16737417cfdeSKuriakose Kuruvilla } 1674ae115bc7Smrj 16758949bcd6Sandrei /* 16768949bcd6Sandrei * If the number of cores is the same as the number 16778949bcd6Sandrei * of CPUs, then we cannot have HyperThreading. 16788949bcd6Sandrei */ 16797417cfdeSKuriakose Kuruvilla if (cpi->cpi_ncpu_per_chip == cpi->cpi_ncore_per_chip) { 16807417cfdeSKuriakose Kuruvilla remove_x86_feature(featureset, X86FSET_HTT); 16817417cfdeSKuriakose Kuruvilla } 16828949bcd6Sandrei 16838031591dSSrihari Venkatesan cpi->cpi_apicid = CPI_APIC_ID(cpi); 16848031591dSSrihari Venkatesan cpi->cpi_procnodes_per_pkg = 1; 16857660e73fSHans Rosenfeld cpi->cpi_cores_per_compunit = 1; 16867417cfdeSKuriakose Kuruvilla if (is_x86_feature(featureset, X86FSET_HTT) == B_FALSE && 16877417cfdeSKuriakose Kuruvilla is_x86_feature(featureset, X86FSET_CMP) == B_FALSE) { 16888949bcd6Sandrei /* 16898949bcd6Sandrei * Single-core single-threaded processors. 16908949bcd6Sandrei */ 16917c478bd9Sstevel@tonic-gate cpi->cpi_chipid = -1; 16927c478bd9Sstevel@tonic-gate cpi->cpi_clogid = 0; 16938949bcd6Sandrei cpi->cpi_coreid = cpu->cpu_id; 169410569901Sgavinm cpi->cpi_pkgcoreid = 0; 16958031591dSSrihari Venkatesan if (cpi->cpi_vendor == X86_VENDOR_AMD) 16968031591dSSrihari Venkatesan cpi->cpi_procnodeid = BITX(cpi->cpi_apicid, 3, 0); 16978031591dSSrihari Venkatesan else 16988031591dSSrihari Venkatesan cpi->cpi_procnodeid = cpi->cpi_chipid; 16997c478bd9Sstevel@tonic-gate } else if (cpi->cpi_ncpu_per_chip > 1) { 17008031591dSSrihari Venkatesan if (cpi->cpi_vendor == X86_VENDOR_Intel) 17017417cfdeSKuriakose Kuruvilla cpuid_intel_getids(cpu, featureset); 17028031591dSSrihari Venkatesan else if (cpi->cpi_vendor == X86_VENDOR_AMD) 17038031591dSSrihari Venkatesan cpuid_amd_getids(cpu); 17048031591dSSrihari Venkatesan else { 17058949bcd6Sandrei /* 17068949bcd6Sandrei * All other processors are currently 17078949bcd6Sandrei * assumed to have single cores. 17088949bcd6Sandrei */ 17098949bcd6Sandrei cpi->cpi_coreid = cpi->cpi_chipid; 171010569901Sgavinm cpi->cpi_pkgcoreid = 0; 17118031591dSSrihari Venkatesan cpi->cpi_procnodeid = cpi->cpi_chipid; 17127660e73fSHans Rosenfeld cpi->cpi_compunitid = cpi->cpi_chipid; 17138949bcd6Sandrei } 17147c478bd9Sstevel@tonic-gate } 17157c478bd9Sstevel@tonic-gate 17168a40a695Sgavinm /* 17178a40a695Sgavinm * Synthesize chip "revision" and socket type 17188a40a695Sgavinm */ 1719e4b86885SCheng Sean Ye cpi->cpi_chiprev = _cpuid_chiprev(cpi->cpi_vendor, cpi->cpi_family, 1720e4b86885SCheng Sean Ye cpi->cpi_model, cpi->cpi_step); 1721e4b86885SCheng Sean Ye cpi->cpi_chiprevstr = _cpuid_chiprevstr(cpi->cpi_vendor, 1722e4b86885SCheng Sean Ye cpi->cpi_family, cpi->cpi_model, cpi->cpi_step); 1723e4b86885SCheng Sean Ye cpi->cpi_socket = _cpuid_skt(cpi->cpi_vendor, cpi->cpi_family, 1724e4b86885SCheng Sean Ye cpi->cpi_model, cpi->cpi_step); 17258a40a695Sgavinm 17267c478bd9Sstevel@tonic-gate pass1_done: 17277c478bd9Sstevel@tonic-gate cpi->cpi_pass = 1; 17287c478bd9Sstevel@tonic-gate } 17297c478bd9Sstevel@tonic-gate 17307c478bd9Sstevel@tonic-gate /* 17317c478bd9Sstevel@tonic-gate * Make copies of the cpuid table entries we depend on, in 17327c478bd9Sstevel@tonic-gate * part for ease of parsing now, in part so that we have only 17337c478bd9Sstevel@tonic-gate * one place to correct any of it, in part for ease of 17347c478bd9Sstevel@tonic-gate * later export to userland, and in part so we can look at 17357c478bd9Sstevel@tonic-gate * this stuff in a crash dump. 17367c478bd9Sstevel@tonic-gate */ 17377c478bd9Sstevel@tonic-gate 17387c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 17397c478bd9Sstevel@tonic-gate void 17407c478bd9Sstevel@tonic-gate cpuid_pass2(cpu_t *cpu) 17417c478bd9Sstevel@tonic-gate { 17427c478bd9Sstevel@tonic-gate uint_t n, nmax; 17437c478bd9Sstevel@tonic-gate int i; 17448949bcd6Sandrei struct cpuid_regs *cp; 17457c478bd9Sstevel@tonic-gate uint8_t *dp; 17467c478bd9Sstevel@tonic-gate uint32_t *iptr; 17477c478bd9Sstevel@tonic-gate struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 17487c478bd9Sstevel@tonic-gate 17497c478bd9Sstevel@tonic-gate ASSERT(cpi->cpi_pass == 1); 17507c478bd9Sstevel@tonic-gate 17517c478bd9Sstevel@tonic-gate if (cpi->cpi_maxeax < 1) 17527c478bd9Sstevel@tonic-gate goto pass2_done; 17537c478bd9Sstevel@tonic-gate 17547c478bd9Sstevel@tonic-gate if ((nmax = cpi->cpi_maxeax + 1) > NMAX_CPI_STD) 17557c478bd9Sstevel@tonic-gate nmax = NMAX_CPI_STD; 17567c478bd9Sstevel@tonic-gate /* 17577c478bd9Sstevel@tonic-gate * (We already handled n == 0 and n == 1 in pass 1) 17587c478bd9Sstevel@tonic-gate */ 17597c478bd9Sstevel@tonic-gate for (n = 2, cp = &cpi->cpi_std[2]; n < nmax; n++, cp++) { 17608949bcd6Sandrei cp->cp_eax = n; 1761d129bde2Sesaxe 1762d129bde2Sesaxe /* 1763d129bde2Sesaxe * CPUID function 4 expects %ecx to be initialized 1764d129bde2Sesaxe * with an index which indicates which cache to return 1765d129bde2Sesaxe * information about. The OS is expected to call function 4 1766d129bde2Sesaxe * with %ecx set to 0, 1, 2, ... until it returns with 1767d129bde2Sesaxe * EAX[4:0] set to 0, which indicates there are no more 1768d129bde2Sesaxe * caches. 1769d129bde2Sesaxe * 1770d129bde2Sesaxe * Here, populate cpi_std[4] with the information returned by 1771d129bde2Sesaxe * function 4 when %ecx == 0, and do the rest in cpuid_pass3() 1772d129bde2Sesaxe * when dynamic memory allocation becomes available. 1773d129bde2Sesaxe * 1774d129bde2Sesaxe * Note: we need to explicitly initialize %ecx here, since 1775d129bde2Sesaxe * function 4 may have been previously invoked. 1776d129bde2Sesaxe */ 1777d129bde2Sesaxe if (n == 4) 1778d129bde2Sesaxe cp->cp_ecx = 0; 1779d129bde2Sesaxe 17808949bcd6Sandrei (void) __cpuid_insn(cp); 1781ae115bc7Smrj platform_cpuid_mangle(cpi->cpi_vendor, n, cp); 17827c478bd9Sstevel@tonic-gate switch (n) { 17837c478bd9Sstevel@tonic-gate case 2: 17847c478bd9Sstevel@tonic-gate /* 17857c478bd9Sstevel@tonic-gate * "the lower 8 bits of the %eax register 17867c478bd9Sstevel@tonic-gate * contain a value that identifies the number 17877c478bd9Sstevel@tonic-gate * of times the cpuid [instruction] has to be 17887c478bd9Sstevel@tonic-gate * executed to obtain a complete image of the 17897c478bd9Sstevel@tonic-gate * processor's caching systems." 17907c478bd9Sstevel@tonic-gate * 17917c478bd9Sstevel@tonic-gate * How *do* they make this stuff up? 17927c478bd9Sstevel@tonic-gate */ 17937c478bd9Sstevel@tonic-gate cpi->cpi_ncache = sizeof (*cp) * 17947c478bd9Sstevel@tonic-gate BITX(cp->cp_eax, 7, 0); 17957c478bd9Sstevel@tonic-gate if (cpi->cpi_ncache == 0) 17967c478bd9Sstevel@tonic-gate break; 17977c478bd9Sstevel@tonic-gate cpi->cpi_ncache--; /* skip count byte */ 17987c478bd9Sstevel@tonic-gate 17997c478bd9Sstevel@tonic-gate /* 18007c478bd9Sstevel@tonic-gate * Well, for now, rather than attempt to implement 18017c478bd9Sstevel@tonic-gate * this slightly dubious algorithm, we just look 18027c478bd9Sstevel@tonic-gate * at the first 15 .. 18037c478bd9Sstevel@tonic-gate */ 18047c478bd9Sstevel@tonic-gate if (cpi->cpi_ncache > (sizeof (*cp) - 1)) 18057c478bd9Sstevel@tonic-gate cpi->cpi_ncache = sizeof (*cp) - 1; 18067c478bd9Sstevel@tonic-gate 18077c478bd9Sstevel@tonic-gate dp = cpi->cpi_cacheinfo; 18087c478bd9Sstevel@tonic-gate if (BITX(cp->cp_eax, 31, 31) == 0) { 18097c478bd9Sstevel@tonic-gate uint8_t *p = (void *)&cp->cp_eax; 181063d3f7dfSkk208521 for (i = 1; i < 4; i++) 18117c478bd9Sstevel@tonic-gate if (p[i] != 0) 18127c478bd9Sstevel@tonic-gate *dp++ = p[i]; 18137c478bd9Sstevel@tonic-gate } 18147c478bd9Sstevel@tonic-gate if (BITX(cp->cp_ebx, 31, 31) == 0) { 18157c478bd9Sstevel@tonic-gate uint8_t *p = (void *)&cp->cp_ebx; 18167c478bd9Sstevel@tonic-gate for (i = 0; i < 4; i++) 18177c478bd9Sstevel@tonic-gate if (p[i] != 0) 18187c478bd9Sstevel@tonic-gate *dp++ = p[i]; 18197c478bd9Sstevel@tonic-gate } 18207c478bd9Sstevel@tonic-gate if (BITX(cp->cp_ecx, 31, 31) == 0) { 18217c478bd9Sstevel@tonic-gate uint8_t *p = (void *)&cp->cp_ecx; 18227c478bd9Sstevel@tonic-gate for (i = 0; i < 4; i++) 18237c478bd9Sstevel@tonic-gate if (p[i] != 0) 18247c478bd9Sstevel@tonic-gate *dp++ = p[i]; 18257c478bd9Sstevel@tonic-gate } 18267c478bd9Sstevel@tonic-gate if (BITX(cp->cp_edx, 31, 31) == 0) { 18277c478bd9Sstevel@tonic-gate uint8_t *p = (void *)&cp->cp_edx; 18287c478bd9Sstevel@tonic-gate for (i = 0; i < 4; i++) 18297c478bd9Sstevel@tonic-gate if (p[i] != 0) 18307c478bd9Sstevel@tonic-gate *dp++ = p[i]; 18317c478bd9Sstevel@tonic-gate } 18327c478bd9Sstevel@tonic-gate break; 1833f98fbcecSbholler 18347c478bd9Sstevel@tonic-gate case 3: /* Processor serial number, if PSN supported */ 1835f98fbcecSbholler break; 1836f98fbcecSbholler 18377c478bd9Sstevel@tonic-gate case 4: /* Deterministic cache parameters */ 1838f98fbcecSbholler break; 1839f98fbcecSbholler 18407c478bd9Sstevel@tonic-gate case 5: /* Monitor/Mwait parameters */ 18415b8a6efeSbholler { 18425b8a6efeSbholler size_t mwait_size; 1843f98fbcecSbholler 1844f98fbcecSbholler /* 1845f98fbcecSbholler * check cpi_mwait.support which was set in cpuid_pass1 1846f98fbcecSbholler */ 1847f98fbcecSbholler if (!(cpi->cpi_mwait.support & MWAIT_SUPPORT)) 1848f98fbcecSbholler break; 1849f98fbcecSbholler 18505b8a6efeSbholler /* 18515b8a6efeSbholler * Protect ourself from insane mwait line size. 18525b8a6efeSbholler * Workaround for incomplete hardware emulator(s). 18535b8a6efeSbholler */ 18545b8a6efeSbholler mwait_size = (size_t)MWAIT_SIZE_MAX(cpi); 18555b8a6efeSbholler if (mwait_size < sizeof (uint32_t) || 18565b8a6efeSbholler !ISP2(mwait_size)) { 18575b8a6efeSbholler #if DEBUG 18585b8a6efeSbholler cmn_err(CE_NOTE, "Cannot handle cpu %d mwait " 18595d8efbbcSSaurabh Misra "size %ld", cpu->cpu_id, (long)mwait_size); 18605b8a6efeSbholler #endif 18615b8a6efeSbholler break; 18625b8a6efeSbholler } 18635b8a6efeSbholler 1864f98fbcecSbholler cpi->cpi_mwait.mon_min = (size_t)MWAIT_SIZE_MIN(cpi); 18655b8a6efeSbholler cpi->cpi_mwait.mon_max = mwait_size; 1866f98fbcecSbholler if (MWAIT_EXTENSION(cpi)) { 1867f98fbcecSbholler cpi->cpi_mwait.support |= MWAIT_EXTENSIONS; 1868f98fbcecSbholler if (MWAIT_INT_ENABLE(cpi)) 1869f98fbcecSbholler cpi->cpi_mwait.support |= 1870f98fbcecSbholler MWAIT_ECX_INT_ENABLE; 1871f98fbcecSbholler } 1872f98fbcecSbholler break; 18735b8a6efeSbholler } 18747c478bd9Sstevel@tonic-gate default: 18757c478bd9Sstevel@tonic-gate break; 18767c478bd9Sstevel@tonic-gate } 18777c478bd9Sstevel@tonic-gate } 18787c478bd9Sstevel@tonic-gate 1879b6917abeSmishra if (cpi->cpi_maxeax >= 0xB && cpi->cpi_vendor == X86_VENDOR_Intel) { 18805d8efbbcSSaurabh Misra struct cpuid_regs regs; 18815d8efbbcSSaurabh Misra 18825d8efbbcSSaurabh Misra cp = ®s; 1883b6917abeSmishra cp->cp_eax = 0xB; 18845d8efbbcSSaurabh Misra cp->cp_edx = cp->cp_ebx = cp->cp_ecx = 0; 1885b6917abeSmishra 1886b6917abeSmishra (void) __cpuid_insn(cp); 1887b6917abeSmishra 1888b6917abeSmishra /* 1889b6917abeSmishra * Check CPUID.EAX=0BH, ECX=0H:EBX is non-zero, which 1890b6917abeSmishra * indicates that the extended topology enumeration leaf is 1891b6917abeSmishra * available. 1892b6917abeSmishra */ 1893b6917abeSmishra if (cp->cp_ebx) { 1894b6917abeSmishra uint32_t x2apic_id; 1895b6917abeSmishra uint_t coreid_shift = 0; 1896b6917abeSmishra uint_t ncpu_per_core = 1; 1897b6917abeSmishra uint_t chipid_shift = 0; 1898b6917abeSmishra uint_t ncpu_per_chip = 1; 1899b6917abeSmishra uint_t i; 1900b6917abeSmishra uint_t level; 1901b6917abeSmishra 1902b6917abeSmishra for (i = 0; i < CPI_FNB_ECX_MAX; i++) { 1903b6917abeSmishra cp->cp_eax = 0xB; 1904b6917abeSmishra cp->cp_ecx = i; 1905b6917abeSmishra 1906b6917abeSmishra (void) __cpuid_insn(cp); 1907b6917abeSmishra level = CPI_CPU_LEVEL_TYPE(cp); 1908b6917abeSmishra 1909b6917abeSmishra if (level == 1) { 1910b6917abeSmishra x2apic_id = cp->cp_edx; 1911b6917abeSmishra coreid_shift = BITX(cp->cp_eax, 4, 0); 1912b6917abeSmishra ncpu_per_core = BITX(cp->cp_ebx, 15, 0); 1913b6917abeSmishra } else if (level == 2) { 1914b6917abeSmishra x2apic_id = cp->cp_edx; 1915b6917abeSmishra chipid_shift = BITX(cp->cp_eax, 4, 0); 1916b6917abeSmishra ncpu_per_chip = BITX(cp->cp_ebx, 15, 0); 1917b6917abeSmishra } 1918b6917abeSmishra } 1919b6917abeSmishra 1920b6917abeSmishra cpi->cpi_apicid = x2apic_id; 1921b6917abeSmishra cpi->cpi_ncpu_per_chip = ncpu_per_chip; 1922b6917abeSmishra cpi->cpi_ncore_per_chip = ncpu_per_chip / 1923b6917abeSmishra ncpu_per_core; 1924b6917abeSmishra cpi->cpi_chipid = x2apic_id >> chipid_shift; 1925b6917abeSmishra cpi->cpi_clogid = x2apic_id & ((1 << chipid_shift) - 1); 1926b6917abeSmishra cpi->cpi_coreid = x2apic_id >> coreid_shift; 1927b6917abeSmishra cpi->cpi_pkgcoreid = cpi->cpi_clogid >> coreid_shift; 1928b6917abeSmishra } 19295d8efbbcSSaurabh Misra 19305d8efbbcSSaurabh Misra /* Make cp NULL so that we don't stumble on others */ 19315d8efbbcSSaurabh Misra cp = NULL; 1932b6917abeSmishra } 1933b6917abeSmishra 19347af88ac7SKuriakose Kuruvilla /* 19357af88ac7SKuriakose Kuruvilla * XSAVE enumeration 19367af88ac7SKuriakose Kuruvilla */ 193763408480SHans Rosenfeld if (cpi->cpi_maxeax >= 0xD) { 19387af88ac7SKuriakose Kuruvilla struct cpuid_regs regs; 19397af88ac7SKuriakose Kuruvilla boolean_t cpuid_d_valid = B_TRUE; 19407af88ac7SKuriakose Kuruvilla 19417af88ac7SKuriakose Kuruvilla cp = ®s; 19427af88ac7SKuriakose Kuruvilla cp->cp_eax = 0xD; 19437af88ac7SKuriakose Kuruvilla cp->cp_edx = cp->cp_ebx = cp->cp_ecx = 0; 19447af88ac7SKuriakose Kuruvilla 19457af88ac7SKuriakose Kuruvilla (void) __cpuid_insn(cp); 19467af88ac7SKuriakose Kuruvilla 19477af88ac7SKuriakose Kuruvilla /* 19487af88ac7SKuriakose Kuruvilla * Sanity checks for debug 19497af88ac7SKuriakose Kuruvilla */ 19507af88ac7SKuriakose Kuruvilla if ((cp->cp_eax & XFEATURE_LEGACY_FP) == 0 || 19517af88ac7SKuriakose Kuruvilla (cp->cp_eax & XFEATURE_SSE) == 0) { 19527af88ac7SKuriakose Kuruvilla cpuid_d_valid = B_FALSE; 19537af88ac7SKuriakose Kuruvilla } 19547af88ac7SKuriakose Kuruvilla 19557af88ac7SKuriakose Kuruvilla cpi->cpi_xsave.xsav_hw_features_low = cp->cp_eax; 19567af88ac7SKuriakose Kuruvilla cpi->cpi_xsave.xsav_hw_features_high = cp->cp_edx; 19577af88ac7SKuriakose Kuruvilla cpi->cpi_xsave.xsav_max_size = cp->cp_ecx; 19587af88ac7SKuriakose Kuruvilla 19597af88ac7SKuriakose Kuruvilla /* 19607af88ac7SKuriakose Kuruvilla * If the hw supports AVX, get the size and offset in the save 19617af88ac7SKuriakose Kuruvilla * area for the ymm state. 19627af88ac7SKuriakose Kuruvilla */ 19637af88ac7SKuriakose Kuruvilla if (cpi->cpi_xsave.xsav_hw_features_low & XFEATURE_AVX) { 19647af88ac7SKuriakose Kuruvilla cp->cp_eax = 0xD; 19657af88ac7SKuriakose Kuruvilla cp->cp_ecx = 2; 19667af88ac7SKuriakose Kuruvilla cp->cp_edx = cp->cp_ebx = 0; 19677af88ac7SKuriakose Kuruvilla 19687af88ac7SKuriakose Kuruvilla (void) __cpuid_insn(cp); 19697af88ac7SKuriakose Kuruvilla 19707af88ac7SKuriakose Kuruvilla if (cp->cp_ebx != CPUID_LEAFD_2_YMM_OFFSET || 19717af88ac7SKuriakose Kuruvilla cp->cp_eax != CPUID_LEAFD_2_YMM_SIZE) { 19727af88ac7SKuriakose Kuruvilla cpuid_d_valid = B_FALSE; 19737af88ac7SKuriakose Kuruvilla } 19747af88ac7SKuriakose Kuruvilla 19757af88ac7SKuriakose Kuruvilla cpi->cpi_xsave.ymm_size = cp->cp_eax; 19767af88ac7SKuriakose Kuruvilla cpi->cpi_xsave.ymm_offset = cp->cp_ebx; 19777af88ac7SKuriakose Kuruvilla } 19787af88ac7SKuriakose Kuruvilla 19797af88ac7SKuriakose Kuruvilla if (is_x86_feature(x86_featureset, X86FSET_XSAVE)) { 19807af88ac7SKuriakose Kuruvilla xsave_state_size = 0; 19817af88ac7SKuriakose Kuruvilla } else if (cpuid_d_valid) { 19827af88ac7SKuriakose Kuruvilla xsave_state_size = cpi->cpi_xsave.xsav_max_size; 19837af88ac7SKuriakose Kuruvilla } else { 19847af88ac7SKuriakose Kuruvilla /* Broken CPUID 0xD, probably in HVM */ 19857af88ac7SKuriakose Kuruvilla cmn_err(CE_WARN, "cpu%d: CPUID.0xD returns invalid " 19867af88ac7SKuriakose Kuruvilla "value: hw_low = %d, hw_high = %d, xsave_size = %d" 19877af88ac7SKuriakose Kuruvilla ", ymm_size = %d, ymm_offset = %d\n", 19887af88ac7SKuriakose Kuruvilla cpu->cpu_id, cpi->cpi_xsave.xsav_hw_features_low, 19897af88ac7SKuriakose Kuruvilla cpi->cpi_xsave.xsav_hw_features_high, 19907af88ac7SKuriakose Kuruvilla (int)cpi->cpi_xsave.xsav_max_size, 19917af88ac7SKuriakose Kuruvilla (int)cpi->cpi_xsave.ymm_size, 19927af88ac7SKuriakose Kuruvilla (int)cpi->cpi_xsave.ymm_offset); 19937af88ac7SKuriakose Kuruvilla 19947af88ac7SKuriakose Kuruvilla if (xsave_state_size != 0) { 19957af88ac7SKuriakose Kuruvilla /* 19967af88ac7SKuriakose Kuruvilla * This must be a non-boot CPU. We cannot 19977af88ac7SKuriakose Kuruvilla * continue, because boot cpu has already 19987af88ac7SKuriakose Kuruvilla * enabled XSAVE. 19997af88ac7SKuriakose Kuruvilla */ 20007af88ac7SKuriakose Kuruvilla ASSERT(cpu->cpu_id != 0); 20017af88ac7SKuriakose Kuruvilla cmn_err(CE_PANIC, "cpu%d: we have already " 20027af88ac7SKuriakose Kuruvilla "enabled XSAVE on boot cpu, cannot " 20037af88ac7SKuriakose Kuruvilla "continue.", cpu->cpu_id); 20047af88ac7SKuriakose Kuruvilla } else { 20057af88ac7SKuriakose Kuruvilla /* 2006dcf050afSRobert Mustacchi * If we reached here on the boot CPU, it's also 2007dcf050afSRobert Mustacchi * almost certain that we'll reach here on the 2008dcf050afSRobert Mustacchi * non-boot CPUs. When we're here on a boot CPU 2009dcf050afSRobert Mustacchi * we should disable the feature, on a non-boot 2010dcf050afSRobert Mustacchi * CPU we need to confirm that we have. 20117af88ac7SKuriakose Kuruvilla */ 2012dcf050afSRobert Mustacchi if (cpu->cpu_id == 0) { 20137af88ac7SKuriakose Kuruvilla remove_x86_feature(x86_featureset, 20147af88ac7SKuriakose Kuruvilla X86FSET_XSAVE); 2015dcf050afSRobert Mustacchi remove_x86_feature(x86_featureset, 2016dcf050afSRobert Mustacchi X86FSET_AVX); 2017245ac945SRobert Mustacchi remove_x86_feature(x86_featureset, 2018245ac945SRobert Mustacchi X86FSET_F16C); 2019245ac945SRobert Mustacchi remove_x86_feature(x86_featureset, 2020245ac945SRobert Mustacchi X86FSET_BMI1); 2021245ac945SRobert Mustacchi remove_x86_feature(x86_featureset, 2022245ac945SRobert Mustacchi X86FSET_BMI2); 2023245ac945SRobert Mustacchi remove_x86_feature(x86_featureset, 2024245ac945SRobert Mustacchi X86FSET_FMA); 2025245ac945SRobert Mustacchi remove_x86_feature(x86_featureset, 2026245ac945SRobert Mustacchi X86FSET_AVX2); 2027dcf050afSRobert Mustacchi CPI_FEATURES_ECX(cpi) &= 2028dcf050afSRobert Mustacchi ~CPUID_INTC_ECX_XSAVE; 2029dcf050afSRobert Mustacchi CPI_FEATURES_ECX(cpi) &= 2030dcf050afSRobert Mustacchi ~CPUID_INTC_ECX_AVX; 2031dcf050afSRobert Mustacchi CPI_FEATURES_ECX(cpi) &= 2032dcf050afSRobert Mustacchi ~CPUID_INTC_ECX_F16C; 2033245ac945SRobert Mustacchi CPI_FEATURES_ECX(cpi) &= 2034245ac945SRobert Mustacchi ~CPUID_INTC_ECX_FMA; 2035245ac945SRobert Mustacchi CPI_FEATURES_7_0_EBX(cpi) &= 2036245ac945SRobert Mustacchi ~CPUID_INTC_EBX_7_0_BMI1; 2037245ac945SRobert Mustacchi CPI_FEATURES_7_0_EBX(cpi) &= 2038245ac945SRobert Mustacchi ~CPUID_INTC_EBX_7_0_BMI2; 2039245ac945SRobert Mustacchi CPI_FEATURES_7_0_EBX(cpi) &= 2040245ac945SRobert Mustacchi ~CPUID_INTC_EBX_7_0_AVX2; 20417af88ac7SKuriakose Kuruvilla xsave_force_disable = B_TRUE; 2042dcf050afSRobert Mustacchi } else { 2043dcf050afSRobert Mustacchi VERIFY(is_x86_feature(x86_featureset, 2044dcf050afSRobert Mustacchi X86FSET_XSAVE) == B_FALSE); 2045dcf050afSRobert Mustacchi } 20467af88ac7SKuriakose Kuruvilla } 20477af88ac7SKuriakose Kuruvilla } 20487af88ac7SKuriakose Kuruvilla } 20497af88ac7SKuriakose Kuruvilla 20507af88ac7SKuriakose Kuruvilla 20517c478bd9Sstevel@tonic-gate if ((cpi->cpi_xmaxeax & 0x80000000) == 0) 20527c478bd9Sstevel@tonic-gate goto pass2_done; 20537c478bd9Sstevel@tonic-gate 20547c478bd9Sstevel@tonic-gate if ((nmax = cpi->cpi_xmaxeax - 0x80000000 + 1) > NMAX_CPI_EXTD) 20557c478bd9Sstevel@tonic-gate nmax = NMAX_CPI_EXTD; 20567c478bd9Sstevel@tonic-gate /* 20577c478bd9Sstevel@tonic-gate * Copy the extended properties, fixing them as we go. 20587c478bd9Sstevel@tonic-gate * (We already handled n == 0 and n == 1 in pass 1) 20597c478bd9Sstevel@tonic-gate */ 20607c478bd9Sstevel@tonic-gate iptr = (void *)cpi->cpi_brandstr; 20617c478bd9Sstevel@tonic-gate for (n = 2, cp = &cpi->cpi_extd[2]; n < nmax; cp++, n++) { 20628949bcd6Sandrei cp->cp_eax = 0x80000000 + n; 20638949bcd6Sandrei (void) __cpuid_insn(cp); 2064ae115bc7Smrj platform_cpuid_mangle(cpi->cpi_vendor, 0x80000000 + n, cp); 20657c478bd9Sstevel@tonic-gate switch (n) { 20667c478bd9Sstevel@tonic-gate case 2: 20677c478bd9Sstevel@tonic-gate case 3: 20687c478bd9Sstevel@tonic-gate case 4: 20697c478bd9Sstevel@tonic-gate /* 20707c478bd9Sstevel@tonic-gate * Extract the brand string 20717c478bd9Sstevel@tonic-gate */ 20727c478bd9Sstevel@tonic-gate *iptr++ = cp->cp_eax; 20737c478bd9Sstevel@tonic-gate *iptr++ = cp->cp_ebx; 20747c478bd9Sstevel@tonic-gate *iptr++ = cp->cp_ecx; 20757c478bd9Sstevel@tonic-gate *iptr++ = cp->cp_edx; 20767c478bd9Sstevel@tonic-gate break; 20777c478bd9Sstevel@tonic-gate case 5: 20787c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 20797c478bd9Sstevel@tonic-gate case X86_VENDOR_AMD: 20807c478bd9Sstevel@tonic-gate /* 20817c478bd9Sstevel@tonic-gate * The Athlon and Duron were the first 20827c478bd9Sstevel@tonic-gate * parts to report the sizes of the 20837c478bd9Sstevel@tonic-gate * TLB for large pages. Before then, 20847c478bd9Sstevel@tonic-gate * we don't trust the data. 20857c478bd9Sstevel@tonic-gate */ 20867c478bd9Sstevel@tonic-gate if (cpi->cpi_family < 6 || 20877c478bd9Sstevel@tonic-gate (cpi->cpi_family == 6 && 20887c478bd9Sstevel@tonic-gate cpi->cpi_model < 1)) 20897c478bd9Sstevel@tonic-gate cp->cp_eax = 0; 20907c478bd9Sstevel@tonic-gate break; 20917c478bd9Sstevel@tonic-gate default: 20927c478bd9Sstevel@tonic-gate break; 20937c478bd9Sstevel@tonic-gate } 20947c478bd9Sstevel@tonic-gate break; 20957c478bd9Sstevel@tonic-gate case 6: 20967c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 20977c478bd9Sstevel@tonic-gate case X86_VENDOR_AMD: 20987c478bd9Sstevel@tonic-gate /* 20997c478bd9Sstevel@tonic-gate * The Athlon and Duron were the first 21007c478bd9Sstevel@tonic-gate * AMD parts with L2 TLB's. 21017c478bd9Sstevel@tonic-gate * Before then, don't trust the data. 21027c478bd9Sstevel@tonic-gate */ 21037c478bd9Sstevel@tonic-gate if (cpi->cpi_family < 6 || 21047c478bd9Sstevel@tonic-gate cpi->cpi_family == 6 && 21057c478bd9Sstevel@tonic-gate cpi->cpi_model < 1) 21067c478bd9Sstevel@tonic-gate cp->cp_eax = cp->cp_ebx = 0; 21077c478bd9Sstevel@tonic-gate /* 21087c478bd9Sstevel@tonic-gate * AMD Duron rev A0 reports L2 21097c478bd9Sstevel@tonic-gate * cache size incorrectly as 1K 21107c478bd9Sstevel@tonic-gate * when it is really 64K 21117c478bd9Sstevel@tonic-gate */ 21127c478bd9Sstevel@tonic-gate if (cpi->cpi_family == 6 && 21137c478bd9Sstevel@tonic-gate cpi->cpi_model == 3 && 21147c478bd9Sstevel@tonic-gate cpi->cpi_step == 0) { 21157c478bd9Sstevel@tonic-gate cp->cp_ecx &= 0xffff; 21167c478bd9Sstevel@tonic-gate cp->cp_ecx |= 0x400000; 21177c478bd9Sstevel@tonic-gate } 21187c478bd9Sstevel@tonic-gate break; 21197c478bd9Sstevel@tonic-gate case X86_VENDOR_Cyrix: /* VIA C3 */ 21207c478bd9Sstevel@tonic-gate /* 21217c478bd9Sstevel@tonic-gate * VIA C3 processors are a bit messed 21227c478bd9Sstevel@tonic-gate * up w.r.t. encoding cache sizes in %ecx 21237c478bd9Sstevel@tonic-gate */ 21247c478bd9Sstevel@tonic-gate if (cpi->cpi_family != 6) 21257c478bd9Sstevel@tonic-gate break; 21267c478bd9Sstevel@tonic-gate /* 21277c478bd9Sstevel@tonic-gate * model 7 and 8 were incorrectly encoded 21287c478bd9Sstevel@tonic-gate * 21297c478bd9Sstevel@tonic-gate * xxx is model 8 really broken? 21307c478bd9Sstevel@tonic-gate */ 21317c478bd9Sstevel@tonic-gate if (cpi->cpi_model == 7 || 21327c478bd9Sstevel@tonic-gate cpi->cpi_model == 8) 21337c478bd9Sstevel@tonic-gate cp->cp_ecx = 21347c478bd9Sstevel@tonic-gate BITX(cp->cp_ecx, 31, 24) << 16 | 21357c478bd9Sstevel@tonic-gate BITX(cp->cp_ecx, 23, 16) << 12 | 21367c478bd9Sstevel@tonic-gate BITX(cp->cp_ecx, 15, 8) << 8 | 21377c478bd9Sstevel@tonic-gate BITX(cp->cp_ecx, 7, 0); 21387c478bd9Sstevel@tonic-gate /* 21397c478bd9Sstevel@tonic-gate * model 9 stepping 1 has wrong associativity 21407c478bd9Sstevel@tonic-gate */ 21417c478bd9Sstevel@tonic-gate if (cpi->cpi_model == 9 && cpi->cpi_step == 1) 21427c478bd9Sstevel@tonic-gate cp->cp_ecx |= 8 << 12; 21437c478bd9Sstevel@tonic-gate break; 21447c478bd9Sstevel@tonic-gate case X86_VENDOR_Intel: 21457c478bd9Sstevel@tonic-gate /* 21467c478bd9Sstevel@tonic-gate * Extended L2 Cache features function. 21477c478bd9Sstevel@tonic-gate * First appeared on Prescott. 21487c478bd9Sstevel@tonic-gate */ 21497c478bd9Sstevel@tonic-gate default: 21507c478bd9Sstevel@tonic-gate break; 21517c478bd9Sstevel@tonic-gate } 21527c478bd9Sstevel@tonic-gate break; 21537c478bd9Sstevel@tonic-gate default: 21547c478bd9Sstevel@tonic-gate break; 21557c478bd9Sstevel@tonic-gate } 21567c478bd9Sstevel@tonic-gate } 21577c478bd9Sstevel@tonic-gate 21587c478bd9Sstevel@tonic-gate pass2_done: 21597c478bd9Sstevel@tonic-gate cpi->cpi_pass = 2; 21607c478bd9Sstevel@tonic-gate } 21617c478bd9Sstevel@tonic-gate 21627c478bd9Sstevel@tonic-gate static const char * 21637c478bd9Sstevel@tonic-gate intel_cpubrand(const struct cpuid_info *cpi) 21647c478bd9Sstevel@tonic-gate { 21657c478bd9Sstevel@tonic-gate int i; 21667c478bd9Sstevel@tonic-gate 21677417cfdeSKuriakose Kuruvilla if (!is_x86_feature(x86_featureset, X86FSET_CPUID) || 21687c478bd9Sstevel@tonic-gate cpi->cpi_maxeax < 1 || cpi->cpi_family < 5) 21697c478bd9Sstevel@tonic-gate return ("i486"); 21707c478bd9Sstevel@tonic-gate 21717c478bd9Sstevel@tonic-gate switch (cpi->cpi_family) { 21727c478bd9Sstevel@tonic-gate case 5: 21737c478bd9Sstevel@tonic-gate return ("Intel Pentium(r)"); 21747c478bd9Sstevel@tonic-gate case 6: 21757c478bd9Sstevel@tonic-gate switch (cpi->cpi_model) { 21767c478bd9Sstevel@tonic-gate uint_t celeron, xeon; 21778949bcd6Sandrei const struct cpuid_regs *cp; 21787c478bd9Sstevel@tonic-gate case 0: 21797c478bd9Sstevel@tonic-gate case 1: 21807c478bd9Sstevel@tonic-gate case 2: 21817c478bd9Sstevel@tonic-gate return ("Intel Pentium(r) Pro"); 21827c478bd9Sstevel@tonic-gate case 3: 21837c478bd9Sstevel@tonic-gate case 4: 21847c478bd9Sstevel@tonic-gate return ("Intel Pentium(r) II"); 21857c478bd9Sstevel@tonic-gate case 6: 21867c478bd9Sstevel@tonic-gate return ("Intel Celeron(r)"); 21877c478bd9Sstevel@tonic-gate case 5: 21887c478bd9Sstevel@tonic-gate case 7: 21897c478bd9Sstevel@tonic-gate celeron = xeon = 0; 21907c478bd9Sstevel@tonic-gate cp = &cpi->cpi_std[2]; /* cache info */ 21917c478bd9Sstevel@tonic-gate 219263d3f7dfSkk208521 for (i = 1; i < 4; i++) { 21937c478bd9Sstevel@tonic-gate uint_t tmp; 21947c478bd9Sstevel@tonic-gate 21957c478bd9Sstevel@tonic-gate tmp = (cp->cp_eax >> (8 * i)) & 0xff; 21967c478bd9Sstevel@tonic-gate if (tmp == 0x40) 21977c478bd9Sstevel@tonic-gate celeron++; 21987c478bd9Sstevel@tonic-gate if (tmp >= 0x44 && tmp <= 0x45) 21997c478bd9Sstevel@tonic-gate xeon++; 22007c478bd9Sstevel@tonic-gate } 22017c478bd9Sstevel@tonic-gate 22027c478bd9Sstevel@tonic-gate for (i = 0; i < 2; i++) { 22037c478bd9Sstevel@tonic-gate uint_t tmp; 22047c478bd9Sstevel@tonic-gate 22057c478bd9Sstevel@tonic-gate tmp = (cp->cp_ebx >> (8 * i)) & 0xff; 22067c478bd9Sstevel@tonic-gate if (tmp == 0x40) 22077c478bd9Sstevel@tonic-gate celeron++; 22087c478bd9Sstevel@tonic-gate else if (tmp >= 0x44 && tmp <= 0x45) 22097c478bd9Sstevel@tonic-gate xeon++; 22107c478bd9Sstevel@tonic-gate } 22117c478bd9Sstevel@tonic-gate 22127c478bd9Sstevel@tonic-gate for (i = 0; i < 4; i++) { 22137c478bd9Sstevel@tonic-gate uint_t tmp; 22147c478bd9Sstevel@tonic-gate 22157c478bd9Sstevel@tonic-gate tmp = (cp->cp_ecx >> (8 * i)) & 0xff; 22167c478bd9Sstevel@tonic-gate if (tmp == 0x40) 22177c478bd9Sstevel@tonic-gate celeron++; 22187c478bd9Sstevel@tonic-gate else if (tmp >= 0x44 && tmp <= 0x45) 22197c478bd9Sstevel@tonic-gate xeon++; 22207c478bd9Sstevel@tonic-gate } 22217c478bd9Sstevel@tonic-gate 22227c478bd9Sstevel@tonic-gate for (i = 0; i < 4; i++) { 22237c478bd9Sstevel@tonic-gate uint_t tmp; 22247c478bd9Sstevel@tonic-gate 22257c478bd9Sstevel@tonic-gate tmp = (cp->cp_edx >> (8 * i)) & 0xff; 22267c478bd9Sstevel@tonic-gate if (tmp == 0x40) 22277c478bd9Sstevel@tonic-gate celeron++; 22287c478bd9Sstevel@tonic-gate else if (tmp >= 0x44 && tmp <= 0x45) 22297c478bd9Sstevel@tonic-gate xeon++; 22307c478bd9Sstevel@tonic-gate } 22317c478bd9Sstevel@tonic-gate 22327c478bd9Sstevel@tonic-gate if (celeron) 22337c478bd9Sstevel@tonic-gate return ("Intel Celeron(r)"); 22347c478bd9Sstevel@tonic-gate if (xeon) 22357c478bd9Sstevel@tonic-gate return (cpi->cpi_model == 5 ? 22367c478bd9Sstevel@tonic-gate "Intel Pentium(r) II Xeon(tm)" : 22377c478bd9Sstevel@tonic-gate "Intel Pentium(r) III Xeon(tm)"); 22387c478bd9Sstevel@tonic-gate return (cpi->cpi_model == 5 ? 22397c478bd9Sstevel@tonic-gate "Intel Pentium(r) II or Pentium(r) II Xeon(tm)" : 22407c478bd9Sstevel@tonic-gate "Intel Pentium(r) III or Pentium(r) III Xeon(tm)"); 22417c478bd9Sstevel@tonic-gate default: 22427c478bd9Sstevel@tonic-gate break; 22437c478bd9Sstevel@tonic-gate } 22447c478bd9Sstevel@tonic-gate default: 22457c478bd9Sstevel@tonic-gate break; 22467c478bd9Sstevel@tonic-gate } 22477c478bd9Sstevel@tonic-gate 22485ff02082Sdmick /* BrandID is present if the field is nonzero */ 22495ff02082Sdmick if (cpi->cpi_brandid != 0) { 22507c478bd9Sstevel@tonic-gate static const struct { 22517c478bd9Sstevel@tonic-gate uint_t bt_bid; 22527c478bd9Sstevel@tonic-gate const char *bt_str; 22537c478bd9Sstevel@tonic-gate } brand_tbl[] = { 22547c478bd9Sstevel@tonic-gate { 0x1, "Intel(r) Celeron(r)" }, 22557c478bd9Sstevel@tonic-gate { 0x2, "Intel(r) Pentium(r) III" }, 22567c478bd9Sstevel@tonic-gate { 0x3, "Intel(r) Pentium(r) III Xeon(tm)" }, 22577c478bd9Sstevel@tonic-gate { 0x4, "Intel(r) Pentium(r) III" }, 22587c478bd9Sstevel@tonic-gate { 0x6, "Mobile Intel(r) Pentium(r) III" }, 22597c478bd9Sstevel@tonic-gate { 0x7, "Mobile Intel(r) Celeron(r)" }, 22607c478bd9Sstevel@tonic-gate { 0x8, "Intel(r) Pentium(r) 4" }, 22617c478bd9Sstevel@tonic-gate { 0x9, "Intel(r) Pentium(r) 4" }, 22627c478bd9Sstevel@tonic-gate { 0xa, "Intel(r) Celeron(r)" }, 22637c478bd9Sstevel@tonic-gate { 0xb, "Intel(r) Xeon(tm)" }, 22647c478bd9Sstevel@tonic-gate { 0xc, "Intel(r) Xeon(tm) MP" }, 22657c478bd9Sstevel@tonic-gate { 0xe, "Mobile Intel(r) Pentium(r) 4" }, 22665ff02082Sdmick { 0xf, "Mobile Intel(r) Celeron(r)" }, 22675ff02082Sdmick { 0x11, "Mobile Genuine Intel(r)" }, 22685ff02082Sdmick { 0x12, "Intel(r) Celeron(r) M" }, 22695ff02082Sdmick { 0x13, "Mobile Intel(r) Celeron(r)" }, 22705ff02082Sdmick { 0x14, "Intel(r) Celeron(r)" }, 22715ff02082Sdmick { 0x15, "Mobile Genuine Intel(r)" }, 22725ff02082Sdmick { 0x16, "Intel(r) Pentium(r) M" }, 22735ff02082Sdmick { 0x17, "Mobile Intel(r) Celeron(r)" } 22747c478bd9Sstevel@tonic-gate }; 22757c478bd9Sstevel@tonic-gate uint_t btblmax = sizeof (brand_tbl) / sizeof (brand_tbl[0]); 22767c478bd9Sstevel@tonic-gate uint_t sgn; 22777c478bd9Sstevel@tonic-gate 22787c478bd9Sstevel@tonic-gate sgn = (cpi->cpi_family << 8) | 22797c478bd9Sstevel@tonic-gate (cpi->cpi_model << 4) | cpi->cpi_step; 22807c478bd9Sstevel@tonic-gate 22817c478bd9Sstevel@tonic-gate for (i = 0; i < btblmax; i++) 22827c478bd9Sstevel@tonic-gate if (brand_tbl[i].bt_bid == cpi->cpi_brandid) 22837c478bd9Sstevel@tonic-gate break; 22847c478bd9Sstevel@tonic-gate if (i < btblmax) { 22857c478bd9Sstevel@tonic-gate if (sgn == 0x6b1 && cpi->cpi_brandid == 3) 22867c478bd9Sstevel@tonic-gate return ("Intel(r) Celeron(r)"); 22877c478bd9Sstevel@tonic-gate if (sgn < 0xf13 && cpi->cpi_brandid == 0xb) 22887c478bd9Sstevel@tonic-gate return ("Intel(r) Xeon(tm) MP"); 22897c478bd9Sstevel@tonic-gate if (sgn < 0xf13 && cpi->cpi_brandid == 0xe) 22907c478bd9Sstevel@tonic-gate return ("Intel(r) Xeon(tm)"); 22917c478bd9Sstevel@tonic-gate return (brand_tbl[i].bt_str); 22927c478bd9Sstevel@tonic-gate } 22937c478bd9Sstevel@tonic-gate } 22947c478bd9Sstevel@tonic-gate 22957c478bd9Sstevel@tonic-gate return (NULL); 22967c478bd9Sstevel@tonic-gate } 22977c478bd9Sstevel@tonic-gate 22987c478bd9Sstevel@tonic-gate static const char * 22997c478bd9Sstevel@tonic-gate amd_cpubrand(const struct cpuid_info *cpi) 23007c478bd9Sstevel@tonic-gate { 23017417cfdeSKuriakose Kuruvilla if (!is_x86_feature(x86_featureset, X86FSET_CPUID) || 23027c478bd9Sstevel@tonic-gate cpi->cpi_maxeax < 1 || cpi->cpi_family < 5) 23037c478bd9Sstevel@tonic-gate return ("i486 compatible"); 23047c478bd9Sstevel@tonic-gate 23057c478bd9Sstevel@tonic-gate switch (cpi->cpi_family) { 23067c478bd9Sstevel@tonic-gate case 5: 23077c478bd9Sstevel@tonic-gate switch (cpi->cpi_model) { 23087c478bd9Sstevel@tonic-gate case 0: 23097c478bd9Sstevel@tonic-gate case 1: 23107c478bd9Sstevel@tonic-gate case 2: 23117c478bd9Sstevel@tonic-gate case 3: 23127c478bd9Sstevel@tonic-gate case 4: 23137c478bd9Sstevel@tonic-gate case 5: 23147c478bd9Sstevel@tonic-gate return ("AMD-K5(r)"); 23157c478bd9Sstevel@tonic-gate case 6: 23167c478bd9Sstevel@tonic-gate case 7: 23177c478bd9Sstevel@tonic-gate return ("AMD-K6(r)"); 23187c478bd9Sstevel@tonic-gate case 8: 23197c478bd9Sstevel@tonic-gate return ("AMD-K6(r)-2"); 23207c478bd9Sstevel@tonic-gate case 9: 23217c478bd9Sstevel@tonic-gate return ("AMD-K6(r)-III"); 23227c478bd9Sstevel@tonic-gate default: 23237c478bd9Sstevel@tonic-gate return ("AMD (family 5)"); 23247c478bd9Sstevel@tonic-gate } 23257c478bd9Sstevel@tonic-gate case 6: 23267c478bd9Sstevel@tonic-gate switch (cpi->cpi_model) { 23277c478bd9Sstevel@tonic-gate case 1: 23287c478bd9Sstevel@tonic-gate return ("AMD-K7(tm)"); 23297c478bd9Sstevel@tonic-gate case 0: 23307c478bd9Sstevel@tonic-gate case 2: 23317c478bd9Sstevel@tonic-gate case 4: 23327c478bd9Sstevel@tonic-gate return ("AMD Athlon(tm)"); 23337c478bd9Sstevel@tonic-gate case 3: 23347c478bd9Sstevel@tonic-gate case 7: 23357c478bd9Sstevel@tonic-gate return ("AMD Duron(tm)"); 23367c478bd9Sstevel@tonic-gate case 6: 23377c478bd9Sstevel@tonic-gate case 8: 23387c478bd9Sstevel@tonic-gate case 10: 23397c478bd9Sstevel@tonic-gate /* 23407c478bd9Sstevel@tonic-gate * Use the L2 cache size to distinguish 23417c478bd9Sstevel@tonic-gate */ 23427c478bd9Sstevel@tonic-gate return ((cpi->cpi_extd[6].cp_ecx >> 16) >= 256 ? 23437c478bd9Sstevel@tonic-gate "AMD Athlon(tm)" : "AMD Duron(tm)"); 23447c478bd9Sstevel@tonic-gate default: 23457c478bd9Sstevel@tonic-gate return ("AMD (family 6)"); 23467c478bd9Sstevel@tonic-gate } 23477c478bd9Sstevel@tonic-gate default: 23487c478bd9Sstevel@tonic-gate break; 23497c478bd9Sstevel@tonic-gate } 23507c478bd9Sstevel@tonic-gate 23517c478bd9Sstevel@tonic-gate if (cpi->cpi_family == 0xf && cpi->cpi_model == 5 && 23527c478bd9Sstevel@tonic-gate cpi->cpi_brandid != 0) { 23537c478bd9Sstevel@tonic-gate switch (BITX(cpi->cpi_brandid, 7, 5)) { 23547c478bd9Sstevel@tonic-gate case 3: 23557c478bd9Sstevel@tonic-gate return ("AMD Opteron(tm) UP 1xx"); 23567c478bd9Sstevel@tonic-gate case 4: 23577c478bd9Sstevel@tonic-gate return ("AMD Opteron(tm) DP 2xx"); 23587c478bd9Sstevel@tonic-gate case 5: 23597c478bd9Sstevel@tonic-gate return ("AMD Opteron(tm) MP 8xx"); 23607c478bd9Sstevel@tonic-gate default: 23617c478bd9Sstevel@tonic-gate return ("AMD Opteron(tm)"); 23627c478bd9Sstevel@tonic-gate } 23637c478bd9Sstevel@tonic-gate } 23647c478bd9Sstevel@tonic-gate 23657c478bd9Sstevel@tonic-gate return (NULL); 23667c478bd9Sstevel@tonic-gate } 23677c478bd9Sstevel@tonic-gate 23687c478bd9Sstevel@tonic-gate static const char * 23697c478bd9Sstevel@tonic-gate cyrix_cpubrand(struct cpuid_info *cpi, uint_t type) 23707c478bd9Sstevel@tonic-gate { 23717417cfdeSKuriakose Kuruvilla if (!is_x86_feature(x86_featureset, X86FSET_CPUID) || 23727c478bd9Sstevel@tonic-gate cpi->cpi_maxeax < 1 || cpi->cpi_family < 5 || 23737c478bd9Sstevel@tonic-gate type == X86_TYPE_CYRIX_486) 23747c478bd9Sstevel@tonic-gate return ("i486 compatible"); 23757c478bd9Sstevel@tonic-gate 23767c478bd9Sstevel@tonic-gate switch (type) { 23777c478bd9Sstevel@tonic-gate case X86_TYPE_CYRIX_6x86: 23787c478bd9Sstevel@tonic-gate return ("Cyrix 6x86"); 23797c478bd9Sstevel@tonic-gate case X86_TYPE_CYRIX_6x86L: 23807c478bd9Sstevel@tonic-gate return ("Cyrix 6x86L"); 23817c478bd9Sstevel@tonic-gate case X86_TYPE_CYRIX_6x86MX: 23827c478bd9Sstevel@tonic-gate return ("Cyrix 6x86MX"); 23837c478bd9Sstevel@tonic-gate case X86_TYPE_CYRIX_GXm: 23847c478bd9Sstevel@tonic-gate return ("Cyrix GXm"); 23857c478bd9Sstevel@tonic-gate case X86_TYPE_CYRIX_MediaGX: 23867c478bd9Sstevel@tonic-gate return ("Cyrix MediaGX"); 23877c478bd9Sstevel@tonic-gate case X86_TYPE_CYRIX_MII: 23887c478bd9Sstevel@tonic-gate return ("Cyrix M2"); 23897c478bd9Sstevel@tonic-gate case X86_TYPE_VIA_CYRIX_III: 23907c478bd9Sstevel@tonic-gate return ("VIA Cyrix M3"); 23917c478bd9Sstevel@tonic-gate default: 23927c478bd9Sstevel@tonic-gate /* 23937c478bd9Sstevel@tonic-gate * Have another wild guess .. 23947c478bd9Sstevel@tonic-gate */ 23957c478bd9Sstevel@tonic-gate if (cpi->cpi_family == 4 && cpi->cpi_model == 9) 23967c478bd9Sstevel@tonic-gate return ("Cyrix 5x86"); 23977c478bd9Sstevel@tonic-gate else if (cpi->cpi_family == 5) { 23987c478bd9Sstevel@tonic-gate switch (cpi->cpi_model) { 23997c478bd9Sstevel@tonic-gate case 2: 24007c478bd9Sstevel@tonic-gate return ("Cyrix 6x86"); /* Cyrix M1 */ 24017c478bd9Sstevel@tonic-gate case 4: 24027c478bd9Sstevel@tonic-gate return ("Cyrix MediaGX"); 24037c478bd9Sstevel@tonic-gate default: 24047c478bd9Sstevel@tonic-gate break; 24057c478bd9Sstevel@tonic-gate } 24067c478bd9Sstevel@tonic-gate } else if (cpi->cpi_family == 6) { 24077c478bd9Sstevel@tonic-gate switch (cpi->cpi_model) { 24087c478bd9Sstevel@tonic-gate case 0: 24097c478bd9Sstevel@tonic-gate return ("Cyrix 6x86MX"); /* Cyrix M2? */ 24107c478bd9Sstevel@tonic-gate case 5: 24117c478bd9Sstevel@tonic-gate case 6: 24127c478bd9Sstevel@tonic-gate case 7: 24137c478bd9Sstevel@tonic-gate case 8: 24147c478bd9Sstevel@tonic-gate case 9: 24157c478bd9Sstevel@tonic-gate return ("VIA C3"); 24167c478bd9Sstevel@tonic-gate default: 24177c478bd9Sstevel@tonic-gate break; 24187c478bd9Sstevel@tonic-gate } 24197c478bd9Sstevel@tonic-gate } 24207c478bd9Sstevel@tonic-gate break; 24217c478bd9Sstevel@tonic-gate } 24227c478bd9Sstevel@tonic-gate return (NULL); 24237c478bd9Sstevel@tonic-gate } 24247c478bd9Sstevel@tonic-gate 24257c478bd9Sstevel@tonic-gate /* 24267c478bd9Sstevel@tonic-gate * This only gets called in the case that the CPU extended 24277c478bd9Sstevel@tonic-gate * feature brand string (0x80000002, 0x80000003, 0x80000004) 24287c478bd9Sstevel@tonic-gate * aren't available, or contain null bytes for some reason. 24297c478bd9Sstevel@tonic-gate */ 24307c478bd9Sstevel@tonic-gate static void 24317c478bd9Sstevel@tonic-gate fabricate_brandstr(struct cpuid_info *cpi) 24327c478bd9Sstevel@tonic-gate { 24337c478bd9Sstevel@tonic-gate const char *brand = NULL; 24347c478bd9Sstevel@tonic-gate 24357c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 24367c478bd9Sstevel@tonic-gate case X86_VENDOR_Intel: 24377c478bd9Sstevel@tonic-gate brand = intel_cpubrand(cpi); 24387c478bd9Sstevel@tonic-gate break; 24397c478bd9Sstevel@tonic-gate case X86_VENDOR_AMD: 24407c478bd9Sstevel@tonic-gate brand = amd_cpubrand(cpi); 24417c478bd9Sstevel@tonic-gate break; 24427c478bd9Sstevel@tonic-gate case X86_VENDOR_Cyrix: 24437c478bd9Sstevel@tonic-gate brand = cyrix_cpubrand(cpi, x86_type); 24447c478bd9Sstevel@tonic-gate break; 24457c478bd9Sstevel@tonic-gate case X86_VENDOR_NexGen: 24467c478bd9Sstevel@tonic-gate if (cpi->cpi_family == 5 && cpi->cpi_model == 0) 24477c478bd9Sstevel@tonic-gate brand = "NexGen Nx586"; 24487c478bd9Sstevel@tonic-gate break; 24497c478bd9Sstevel@tonic-gate case X86_VENDOR_Centaur: 24507c478bd9Sstevel@tonic-gate if (cpi->cpi_family == 5) 24517c478bd9Sstevel@tonic-gate switch (cpi->cpi_model) { 24527c478bd9Sstevel@tonic-gate case 4: 24537c478bd9Sstevel@tonic-gate brand = "Centaur C6"; 24547c478bd9Sstevel@tonic-gate break; 24557c478bd9Sstevel@tonic-gate case 8: 24567c478bd9Sstevel@tonic-gate brand = "Centaur C2"; 24577c478bd9Sstevel@tonic-gate break; 24587c478bd9Sstevel@tonic-gate case 9: 24597c478bd9Sstevel@tonic-gate brand = "Centaur C3"; 24607c478bd9Sstevel@tonic-gate break; 24617c478bd9Sstevel@tonic-gate default: 24627c478bd9Sstevel@tonic-gate break; 24637c478bd9Sstevel@tonic-gate } 24647c478bd9Sstevel@tonic-gate break; 24657c478bd9Sstevel@tonic-gate case X86_VENDOR_Rise: 24667c478bd9Sstevel@tonic-gate if (cpi->cpi_family == 5 && 24677c478bd9Sstevel@tonic-gate (cpi->cpi_model == 0 || cpi->cpi_model == 2)) 24687c478bd9Sstevel@tonic-gate brand = "Rise mP6"; 24697c478bd9Sstevel@tonic-gate break; 24707c478bd9Sstevel@tonic-gate case X86_VENDOR_SiS: 24717c478bd9Sstevel@tonic-gate if (cpi->cpi_family == 5 && cpi->cpi_model == 0) 24727c478bd9Sstevel@tonic-gate brand = "SiS 55x"; 24737c478bd9Sstevel@tonic-gate break; 24747c478bd9Sstevel@tonic-gate case X86_VENDOR_TM: 24757c478bd9Sstevel@tonic-gate if (cpi->cpi_family == 5 && cpi->cpi_model == 4) 24767c478bd9Sstevel@tonic-gate brand = "Transmeta Crusoe TM3x00 or TM5x00"; 24777c478bd9Sstevel@tonic-gate break; 24787c478bd9Sstevel@tonic-gate case X86_VENDOR_NSC: 24797c478bd9Sstevel@tonic-gate case X86_VENDOR_UMC: 24807c478bd9Sstevel@tonic-gate default: 24817c478bd9Sstevel@tonic-gate break; 24827c478bd9Sstevel@tonic-gate } 24837c478bd9Sstevel@tonic-gate if (brand) { 24847c478bd9Sstevel@tonic-gate (void) strcpy((char *)cpi->cpi_brandstr, brand); 24857c478bd9Sstevel@tonic-gate return; 24867c478bd9Sstevel@tonic-gate } 24877c478bd9Sstevel@tonic-gate 24887c478bd9Sstevel@tonic-gate /* 24897c478bd9Sstevel@tonic-gate * If all else fails ... 24907c478bd9Sstevel@tonic-gate */ 24917c478bd9Sstevel@tonic-gate (void) snprintf(cpi->cpi_brandstr, sizeof (cpi->cpi_brandstr), 24927c478bd9Sstevel@tonic-gate "%s %d.%d.%d", cpi->cpi_vendorstr, cpi->cpi_family, 24937c478bd9Sstevel@tonic-gate cpi->cpi_model, cpi->cpi_step); 24947c478bd9Sstevel@tonic-gate } 24957c478bd9Sstevel@tonic-gate 24967c478bd9Sstevel@tonic-gate /* 24977c478bd9Sstevel@tonic-gate * This routine is called just after kernel memory allocation 24987c478bd9Sstevel@tonic-gate * becomes available on cpu0, and as part of mp_startup() on 24997c478bd9Sstevel@tonic-gate * the other cpus. 25007c478bd9Sstevel@tonic-gate * 2501d129bde2Sesaxe * Fixup the brand string, and collect any information from cpuid 250279ec9da8SYuri Pankov * that requires dynamically allocated storage to represent. 25037c478bd9Sstevel@tonic-gate */ 25047c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 25057c478bd9Sstevel@tonic-gate void 25067c478bd9Sstevel@tonic-gate cpuid_pass3(cpu_t *cpu) 25077c478bd9Sstevel@tonic-gate { 2508d129bde2Sesaxe int i, max, shft, level, size; 2509d129bde2Sesaxe struct cpuid_regs regs; 2510d129bde2Sesaxe struct cpuid_regs *cp; 25117c478bd9Sstevel@tonic-gate struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 25127c478bd9Sstevel@tonic-gate 25137c478bd9Sstevel@tonic-gate ASSERT(cpi->cpi_pass == 2); 25147c478bd9Sstevel@tonic-gate 2515d129bde2Sesaxe /* 2516d129bde2Sesaxe * Function 4: Deterministic cache parameters 2517d129bde2Sesaxe * 2518d129bde2Sesaxe * Take this opportunity to detect the number of threads 2519d129bde2Sesaxe * sharing the last level cache, and construct a corresponding 2520d129bde2Sesaxe * cache id. The respective cpuid_info members are initialized 2521d129bde2Sesaxe * to the default case of "no last level cache sharing". 2522d129bde2Sesaxe */ 2523d129bde2Sesaxe cpi->cpi_ncpu_shr_last_cache = 1; 2524d129bde2Sesaxe cpi->cpi_last_lvl_cacheid = cpu->cpu_id; 2525d129bde2Sesaxe 2526d129bde2Sesaxe if (cpi->cpi_maxeax >= 4 && cpi->cpi_vendor == X86_VENDOR_Intel) { 2527d129bde2Sesaxe 2528d129bde2Sesaxe /* 2529d129bde2Sesaxe * Find the # of elements (size) returned by fn 4, and along 2530d129bde2Sesaxe * the way detect last level cache sharing details. 2531d129bde2Sesaxe */ 2532d129bde2Sesaxe bzero(®s, sizeof (regs)); 2533d129bde2Sesaxe cp = ®s; 2534d129bde2Sesaxe for (i = 0, max = 0; i < CPI_FN4_ECX_MAX; i++) { 2535d129bde2Sesaxe cp->cp_eax = 4; 2536d129bde2Sesaxe cp->cp_ecx = i; 2537d129bde2Sesaxe 2538d129bde2Sesaxe (void) __cpuid_insn(cp); 2539d129bde2Sesaxe 2540d129bde2Sesaxe if (CPI_CACHE_TYPE(cp) == 0) 2541d129bde2Sesaxe break; 2542d129bde2Sesaxe level = CPI_CACHE_LVL(cp); 2543d129bde2Sesaxe if (level > max) { 2544d129bde2Sesaxe max = level; 2545d129bde2Sesaxe cpi->cpi_ncpu_shr_last_cache = 2546d129bde2Sesaxe CPI_NTHR_SHR_CACHE(cp) + 1; 2547d129bde2Sesaxe } 2548d129bde2Sesaxe } 2549d129bde2Sesaxe cpi->cpi_std_4_size = size = i; 2550d129bde2Sesaxe 2551d129bde2Sesaxe /* 2552d129bde2Sesaxe * Allocate the cpi_std_4 array. The first element 2553d129bde2Sesaxe * references the regs for fn 4, %ecx == 0, which 2554d129bde2Sesaxe * cpuid_pass2() stashed in cpi->cpi_std[4]. 2555d129bde2Sesaxe */ 2556d129bde2Sesaxe if (size > 0) { 2557d129bde2Sesaxe cpi->cpi_std_4 = 2558d129bde2Sesaxe kmem_alloc(size * sizeof (cp), KM_SLEEP); 2559d129bde2Sesaxe cpi->cpi_std_4[0] = &cpi->cpi_std[4]; 2560d129bde2Sesaxe 2561d129bde2Sesaxe /* 2562d129bde2Sesaxe * Allocate storage to hold the additional regs 2563d129bde2Sesaxe * for function 4, %ecx == 1 .. cpi_std_4_size. 2564d129bde2Sesaxe * 2565d129bde2Sesaxe * The regs for fn 4, %ecx == 0 has already 2566d129bde2Sesaxe * been allocated as indicated above. 2567d129bde2Sesaxe */ 2568d129bde2Sesaxe for (i = 1; i < size; i++) { 2569d129bde2Sesaxe cp = cpi->cpi_std_4[i] = 2570d129bde2Sesaxe kmem_zalloc(sizeof (regs), KM_SLEEP); 2571d129bde2Sesaxe cp->cp_eax = 4; 2572d129bde2Sesaxe cp->cp_ecx = i; 2573d129bde2Sesaxe 2574d129bde2Sesaxe (void) __cpuid_insn(cp); 2575d129bde2Sesaxe } 2576d129bde2Sesaxe } 2577d129bde2Sesaxe /* 2578d129bde2Sesaxe * Determine the number of bits needed to represent 2579d129bde2Sesaxe * the number of CPUs sharing the last level cache. 2580d129bde2Sesaxe * 2581d129bde2Sesaxe * Shift off that number of bits from the APIC id to 2582d129bde2Sesaxe * derive the cache id. 2583d129bde2Sesaxe */ 2584d129bde2Sesaxe shft = 0; 2585d129bde2Sesaxe for (i = 1; i < cpi->cpi_ncpu_shr_last_cache; i <<= 1) 2586d129bde2Sesaxe shft++; 2587b6917abeSmishra cpi->cpi_last_lvl_cacheid = cpi->cpi_apicid >> shft; 2588d129bde2Sesaxe } 2589d129bde2Sesaxe 2590d129bde2Sesaxe /* 2591d129bde2Sesaxe * Now fixup the brand string 2592d129bde2Sesaxe */ 25937c478bd9Sstevel@tonic-gate if ((cpi->cpi_xmaxeax & 0x80000000) == 0) { 25947c478bd9Sstevel@tonic-gate fabricate_brandstr(cpi); 2595d129bde2Sesaxe } else { 25967c478bd9Sstevel@tonic-gate 25977c478bd9Sstevel@tonic-gate /* 25987c478bd9Sstevel@tonic-gate * If we successfully extracted a brand string from the cpuid 25997c478bd9Sstevel@tonic-gate * instruction, clean it up by removing leading spaces and 26007c478bd9Sstevel@tonic-gate * similar junk. 26017c478bd9Sstevel@tonic-gate */ 26027c478bd9Sstevel@tonic-gate if (cpi->cpi_brandstr[0]) { 26037c478bd9Sstevel@tonic-gate size_t maxlen = sizeof (cpi->cpi_brandstr); 26047c478bd9Sstevel@tonic-gate char *src, *dst; 26057c478bd9Sstevel@tonic-gate 26067c478bd9Sstevel@tonic-gate dst = src = (char *)cpi->cpi_brandstr; 26077c478bd9Sstevel@tonic-gate src[maxlen - 1] = '\0'; 26087c478bd9Sstevel@tonic-gate /* 26097c478bd9Sstevel@tonic-gate * strip leading spaces 26107c478bd9Sstevel@tonic-gate */ 26117c478bd9Sstevel@tonic-gate while (*src == ' ') 26127c478bd9Sstevel@tonic-gate src++; 26137c478bd9Sstevel@tonic-gate /* 26147c478bd9Sstevel@tonic-gate * Remove any 'Genuine' or "Authentic" prefixes 26157c478bd9Sstevel@tonic-gate */ 26167c478bd9Sstevel@tonic-gate if (strncmp(src, "Genuine ", 8) == 0) 26177c478bd9Sstevel@tonic-gate src += 8; 26187c478bd9Sstevel@tonic-gate if (strncmp(src, "Authentic ", 10) == 0) 26197c478bd9Sstevel@tonic-gate src += 10; 26207c478bd9Sstevel@tonic-gate 26217c478bd9Sstevel@tonic-gate /* 26227c478bd9Sstevel@tonic-gate * Now do an in-place copy. 26237c478bd9Sstevel@tonic-gate * Map (R) to (r) and (TM) to (tm). 26247c478bd9Sstevel@tonic-gate * The era of teletypes is long gone, and there's 26257c478bd9Sstevel@tonic-gate * -really- no need to shout. 26267c478bd9Sstevel@tonic-gate */ 26277c478bd9Sstevel@tonic-gate while (*src != '\0') { 26287c478bd9Sstevel@tonic-gate if (src[0] == '(') { 26297c478bd9Sstevel@tonic-gate if (strncmp(src + 1, "R)", 2) == 0) { 26307c478bd9Sstevel@tonic-gate (void) strncpy(dst, "(r)", 3); 26317c478bd9Sstevel@tonic-gate src += 3; 26327c478bd9Sstevel@tonic-gate dst += 3; 26337c478bd9Sstevel@tonic-gate continue; 26347c478bd9Sstevel@tonic-gate } 26357c478bd9Sstevel@tonic-gate if (strncmp(src + 1, "TM)", 3) == 0) { 26367c478bd9Sstevel@tonic-gate (void) strncpy(dst, "(tm)", 4); 26377c478bd9Sstevel@tonic-gate src += 4; 26387c478bd9Sstevel@tonic-gate dst += 4; 26397c478bd9Sstevel@tonic-gate continue; 26407c478bd9Sstevel@tonic-gate } 26417c478bd9Sstevel@tonic-gate } 26427c478bd9Sstevel@tonic-gate *dst++ = *src++; 26437c478bd9Sstevel@tonic-gate } 26447c478bd9Sstevel@tonic-gate *dst = '\0'; 26457c478bd9Sstevel@tonic-gate 26467c478bd9Sstevel@tonic-gate /* 26477c478bd9Sstevel@tonic-gate * Finally, remove any trailing spaces 26487c478bd9Sstevel@tonic-gate */ 26497c478bd9Sstevel@tonic-gate while (--dst > cpi->cpi_brandstr) 26507c478bd9Sstevel@tonic-gate if (*dst == ' ') 26517c478bd9Sstevel@tonic-gate *dst = '\0'; 26527c478bd9Sstevel@tonic-gate else 26537c478bd9Sstevel@tonic-gate break; 26547c478bd9Sstevel@tonic-gate } else 26557c478bd9Sstevel@tonic-gate fabricate_brandstr(cpi); 2656d129bde2Sesaxe } 26577c478bd9Sstevel@tonic-gate cpi->cpi_pass = 3; 26587c478bd9Sstevel@tonic-gate } 26597c478bd9Sstevel@tonic-gate 26607c478bd9Sstevel@tonic-gate /* 26617c478bd9Sstevel@tonic-gate * This routine is called out of bind_hwcap() much later in the life 26627c478bd9Sstevel@tonic-gate * of the kernel (post_startup()). The job of this routine is to resolve 26637c478bd9Sstevel@tonic-gate * the hardware feature support and kernel support for those features into 26647c478bd9Sstevel@tonic-gate * what we're actually going to tell applications via the aux vector. 26657c478bd9Sstevel@tonic-gate */ 2666ebb8ac07SRobert Mustacchi void 2667ebb8ac07SRobert Mustacchi cpuid_pass4(cpu_t *cpu, uint_t *hwcap_out) 26687c478bd9Sstevel@tonic-gate { 26697c478bd9Sstevel@tonic-gate struct cpuid_info *cpi; 2670ebb8ac07SRobert Mustacchi uint_t hwcap_flags = 0, hwcap_flags_2 = 0; 26717c478bd9Sstevel@tonic-gate 26727c478bd9Sstevel@tonic-gate if (cpu == NULL) 26737c478bd9Sstevel@tonic-gate cpu = CPU; 26747c478bd9Sstevel@tonic-gate cpi = cpu->cpu_m.mcpu_cpi; 26757c478bd9Sstevel@tonic-gate 26767c478bd9Sstevel@tonic-gate ASSERT(cpi->cpi_pass == 3); 26777c478bd9Sstevel@tonic-gate 26787c478bd9Sstevel@tonic-gate if (cpi->cpi_maxeax >= 1) { 26797c478bd9Sstevel@tonic-gate uint32_t *edx = &cpi->cpi_support[STD_EDX_FEATURES]; 26807c478bd9Sstevel@tonic-gate uint32_t *ecx = &cpi->cpi_support[STD_ECX_FEATURES]; 2681245ac945SRobert Mustacchi uint32_t *ebx = &cpi->cpi_support[STD_EBX_FEATURES]; 26827c478bd9Sstevel@tonic-gate 26837c478bd9Sstevel@tonic-gate *edx = CPI_FEATURES_EDX(cpi); 26847c478bd9Sstevel@tonic-gate *ecx = CPI_FEATURES_ECX(cpi); 2685245ac945SRobert Mustacchi *ebx = CPI_FEATURES_7_0_EBX(cpi); 26867c478bd9Sstevel@tonic-gate 26877c478bd9Sstevel@tonic-gate /* 26887c478bd9Sstevel@tonic-gate * [these require explicit kernel support] 26897c478bd9Sstevel@tonic-gate */ 26907417cfdeSKuriakose Kuruvilla if (!is_x86_feature(x86_featureset, X86FSET_SEP)) 26917c478bd9Sstevel@tonic-gate *edx &= ~CPUID_INTC_EDX_SEP; 26927c478bd9Sstevel@tonic-gate 26937417cfdeSKuriakose Kuruvilla if (!is_x86_feature(x86_featureset, X86FSET_SSE)) 26947c478bd9Sstevel@tonic-gate *edx &= ~(CPUID_INTC_EDX_FXSR|CPUID_INTC_EDX_SSE); 26957417cfdeSKuriakose Kuruvilla if (!is_x86_feature(x86_featureset, X86FSET_SSE2)) 26967c478bd9Sstevel@tonic-gate *edx &= ~CPUID_INTC_EDX_SSE2; 26977c478bd9Sstevel@tonic-gate 26987417cfdeSKuriakose Kuruvilla if (!is_x86_feature(x86_featureset, X86FSET_HTT)) 26997c478bd9Sstevel@tonic-gate *edx &= ~CPUID_INTC_EDX_HTT; 27007c478bd9Sstevel@tonic-gate 27017417cfdeSKuriakose Kuruvilla if (!is_x86_feature(x86_featureset, X86FSET_SSE3)) 27027c478bd9Sstevel@tonic-gate *ecx &= ~CPUID_INTC_ECX_SSE3; 27037c478bd9Sstevel@tonic-gate 27047417cfdeSKuriakose Kuruvilla if (!is_x86_feature(x86_featureset, X86FSET_SSSE3)) 2705d0f8ff6eSkk208521 *ecx &= ~CPUID_INTC_ECX_SSSE3; 27067417cfdeSKuriakose Kuruvilla if (!is_x86_feature(x86_featureset, X86FSET_SSE4_1)) 2707d0f8ff6eSkk208521 *ecx &= ~CPUID_INTC_ECX_SSE4_1; 27087417cfdeSKuriakose Kuruvilla if (!is_x86_feature(x86_featureset, X86FSET_SSE4_2)) 2709d0f8ff6eSkk208521 *ecx &= ~CPUID_INTC_ECX_SSE4_2; 27107417cfdeSKuriakose Kuruvilla if (!is_x86_feature(x86_featureset, X86FSET_AES)) 2711a50a8b93SKuriakose Kuruvilla *ecx &= ~CPUID_INTC_ECX_AES; 27127417cfdeSKuriakose Kuruvilla if (!is_x86_feature(x86_featureset, X86FSET_PCLMULQDQ)) 27137417cfdeSKuriakose Kuruvilla *ecx &= ~CPUID_INTC_ECX_PCLMULQDQ; 27147af88ac7SKuriakose Kuruvilla if (!is_x86_feature(x86_featureset, X86FSET_XSAVE)) 27157af88ac7SKuriakose Kuruvilla *ecx &= ~(CPUID_INTC_ECX_XSAVE | 27167af88ac7SKuriakose Kuruvilla CPUID_INTC_ECX_OSXSAVE); 27177af88ac7SKuriakose Kuruvilla if (!is_x86_feature(x86_featureset, X86FSET_AVX)) 27187af88ac7SKuriakose Kuruvilla *ecx &= ~CPUID_INTC_ECX_AVX; 2719ebb8ac07SRobert Mustacchi if (!is_x86_feature(x86_featureset, X86FSET_F16C)) 2720ebb8ac07SRobert Mustacchi *ecx &= ~CPUID_INTC_ECX_F16C; 2721245ac945SRobert Mustacchi if (!is_x86_feature(x86_featureset, X86FSET_FMA)) 2722245ac945SRobert Mustacchi *ecx &= ~CPUID_INTC_ECX_FMA; 2723245ac945SRobert Mustacchi if (!is_x86_feature(x86_featureset, X86FSET_BMI1)) 2724245ac945SRobert Mustacchi *ebx &= ~CPUID_INTC_EBX_7_0_BMI1; 2725245ac945SRobert Mustacchi if (!is_x86_feature(x86_featureset, X86FSET_BMI2)) 2726245ac945SRobert Mustacchi *ebx &= ~CPUID_INTC_EBX_7_0_BMI2; 2727245ac945SRobert Mustacchi if (!is_x86_feature(x86_featureset, X86FSET_AVX2)) 2728245ac945SRobert Mustacchi *ebx &= ~CPUID_INTC_EBX_7_0_AVX2; 2729d0f8ff6eSkk208521 27307c478bd9Sstevel@tonic-gate /* 27317c478bd9Sstevel@tonic-gate * [no explicit support required beyond x87 fp context] 27327c478bd9Sstevel@tonic-gate */ 27337c478bd9Sstevel@tonic-gate if (!fpu_exists) 27347c478bd9Sstevel@tonic-gate *edx &= ~(CPUID_INTC_EDX_FPU | CPUID_INTC_EDX_MMX); 27357c478bd9Sstevel@tonic-gate 27367c478bd9Sstevel@tonic-gate /* 27377c478bd9Sstevel@tonic-gate * Now map the supported feature vector to things that we 27387c478bd9Sstevel@tonic-gate * think userland will care about. 27397c478bd9Sstevel@tonic-gate */ 27407c478bd9Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_SEP) 27417c478bd9Sstevel@tonic-gate hwcap_flags |= AV_386_SEP; 27427c478bd9Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_SSE) 27437c478bd9Sstevel@tonic-gate hwcap_flags |= AV_386_FXSR | AV_386_SSE; 27447c478bd9Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_SSE2) 27457c478bd9Sstevel@tonic-gate hwcap_flags |= AV_386_SSE2; 27467c478bd9Sstevel@tonic-gate if (*ecx & CPUID_INTC_ECX_SSE3) 27477c478bd9Sstevel@tonic-gate hwcap_flags |= AV_386_SSE3; 2748d0f8ff6eSkk208521 if (*ecx & CPUID_INTC_ECX_SSSE3) 2749d0f8ff6eSkk208521 hwcap_flags |= AV_386_SSSE3; 2750d0f8ff6eSkk208521 if (*ecx & CPUID_INTC_ECX_SSE4_1) 2751d0f8ff6eSkk208521 hwcap_flags |= AV_386_SSE4_1; 2752d0f8ff6eSkk208521 if (*ecx & CPUID_INTC_ECX_SSE4_2) 2753d0f8ff6eSkk208521 hwcap_flags |= AV_386_SSE4_2; 27545087e485SKrishnendu Sadhukhan - Sun Microsystems if (*ecx & CPUID_INTC_ECX_MOVBE) 27555087e485SKrishnendu Sadhukhan - Sun Microsystems hwcap_flags |= AV_386_MOVBE; 2756a50a8b93SKuriakose Kuruvilla if (*ecx & CPUID_INTC_ECX_AES) 2757a50a8b93SKuriakose Kuruvilla hwcap_flags |= AV_386_AES; 2758a50a8b93SKuriakose Kuruvilla if (*ecx & CPUID_INTC_ECX_PCLMULQDQ) 2759a50a8b93SKuriakose Kuruvilla hwcap_flags |= AV_386_PCLMULQDQ; 27607af88ac7SKuriakose Kuruvilla if ((*ecx & CPUID_INTC_ECX_XSAVE) && 2761f3390f39SRobert Mustacchi (*ecx & CPUID_INTC_ECX_OSXSAVE)) { 27627af88ac7SKuriakose Kuruvilla hwcap_flags |= AV_386_XSAVE; 2763f3390f39SRobert Mustacchi 2764ebb8ac07SRobert Mustacchi if (*ecx & CPUID_INTC_ECX_AVX) { 2765f3390f39SRobert Mustacchi hwcap_flags |= AV_386_AVX; 2766ebb8ac07SRobert Mustacchi if (*ecx & CPUID_INTC_ECX_F16C) 2767ebb8ac07SRobert Mustacchi hwcap_flags_2 |= AV_386_2_F16C; 2768245ac945SRobert Mustacchi if (*ecx & CPUID_INTC_ECX_FMA) 2769245ac945SRobert Mustacchi hwcap_flags_2 |= AV_386_2_FMA; 2770245ac945SRobert Mustacchi if (*ebx & CPUID_INTC_EBX_7_0_BMI1) 2771245ac945SRobert Mustacchi hwcap_flags_2 |= AV_386_2_BMI1; 2772245ac945SRobert Mustacchi if (*ebx & CPUID_INTC_EBX_7_0_BMI2) 2773245ac945SRobert Mustacchi hwcap_flags_2 |= AV_386_2_BMI2; 2774245ac945SRobert Mustacchi if (*ebx & CPUID_INTC_EBX_7_0_AVX2) 2775245ac945SRobert Mustacchi hwcap_flags_2 |= AV_386_2_AVX2; 2776ebb8ac07SRobert Mustacchi } 2777f3390f39SRobert Mustacchi } 2778faa20166SBryan Cantrill if (*ecx & CPUID_INTC_ECX_VMX) 2779faa20166SBryan Cantrill hwcap_flags |= AV_386_VMX; 2780f8801251Skk208521 if (*ecx & CPUID_INTC_ECX_POPCNT) 2781f8801251Skk208521 hwcap_flags |= AV_386_POPCNT; 27827c478bd9Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_FPU) 27837c478bd9Sstevel@tonic-gate hwcap_flags |= AV_386_FPU; 27847c478bd9Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_MMX) 27857c478bd9Sstevel@tonic-gate hwcap_flags |= AV_386_MMX; 27867c478bd9Sstevel@tonic-gate 27877c478bd9Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_TSC) 27887c478bd9Sstevel@tonic-gate hwcap_flags |= AV_386_TSC; 27897c478bd9Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_CX8) 27907c478bd9Sstevel@tonic-gate hwcap_flags |= AV_386_CX8; 27917c478bd9Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_CMOV) 27927c478bd9Sstevel@tonic-gate hwcap_flags |= AV_386_CMOV; 27937c478bd9Sstevel@tonic-gate if (*ecx & CPUID_INTC_ECX_CX16) 27947c478bd9Sstevel@tonic-gate hwcap_flags |= AV_386_CX16; 2795ebb8ac07SRobert Mustacchi 2796ebb8ac07SRobert Mustacchi if (*ecx & CPUID_INTC_ECX_RDRAND) 2797ebb8ac07SRobert Mustacchi hwcap_flags_2 |= AV_386_2_RDRAND; 27987c478bd9Sstevel@tonic-gate } 27997c478bd9Sstevel@tonic-gate 28007c478bd9Sstevel@tonic-gate if (cpi->cpi_xmaxeax < 0x80000001) 28017c478bd9Sstevel@tonic-gate goto pass4_done; 28027c478bd9Sstevel@tonic-gate 28037c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 28048949bcd6Sandrei struct cpuid_regs cp; 2805ae115bc7Smrj uint32_t *edx, *ecx; 28067c478bd9Sstevel@tonic-gate 2807ae115bc7Smrj case X86_VENDOR_Intel: 2808ae115bc7Smrj /* 2809ae115bc7Smrj * Seems like Intel duplicated what we necessary 2810ae115bc7Smrj * here to make the initial crop of 64-bit OS's work. 2811ae115bc7Smrj * Hopefully, those are the only "extended" bits 2812ae115bc7Smrj * they'll add. 2813ae115bc7Smrj */ 2814ae115bc7Smrj /*FALLTHROUGH*/ 2815ae115bc7Smrj 28167c478bd9Sstevel@tonic-gate case X86_VENDOR_AMD: 28177c478bd9Sstevel@tonic-gate edx = &cpi->cpi_support[AMD_EDX_FEATURES]; 2818ae115bc7Smrj ecx = &cpi->cpi_support[AMD_ECX_FEATURES]; 28197c478bd9Sstevel@tonic-gate 28207c478bd9Sstevel@tonic-gate *edx = CPI_FEATURES_XTD_EDX(cpi); 2821ae115bc7Smrj *ecx = CPI_FEATURES_XTD_ECX(cpi); 2822ae115bc7Smrj 2823ae115bc7Smrj /* 2824ae115bc7Smrj * [these features require explicit kernel support] 2825ae115bc7Smrj */ 2826ae115bc7Smrj switch (cpi->cpi_vendor) { 2827ae115bc7Smrj case X86_VENDOR_Intel: 28287417cfdeSKuriakose Kuruvilla if (!is_x86_feature(x86_featureset, X86FSET_TSCP)) 2829d36ea5d8Ssudheer *edx &= ~CPUID_AMD_EDX_TSCP; 2830ae115bc7Smrj break; 2831ae115bc7Smrj 2832ae115bc7Smrj case X86_VENDOR_AMD: 28337417cfdeSKuriakose Kuruvilla if (!is_x86_feature(x86_featureset, X86FSET_TSCP)) 2834ae115bc7Smrj *edx &= ~CPUID_AMD_EDX_TSCP; 28357417cfdeSKuriakose Kuruvilla if (!is_x86_feature(x86_featureset, X86FSET_SSE4A)) 2836f8801251Skk208521 *ecx &= ~CPUID_AMD_ECX_SSE4A; 2837ae115bc7Smrj break; 2838ae115bc7Smrj 2839ae115bc7Smrj default: 2840ae115bc7Smrj break; 2841ae115bc7Smrj } 28427c478bd9Sstevel@tonic-gate 28437c478bd9Sstevel@tonic-gate /* 28447c478bd9Sstevel@tonic-gate * [no explicit support required beyond 28457c478bd9Sstevel@tonic-gate * x87 fp context and exception handlers] 28467c478bd9Sstevel@tonic-gate */ 28477c478bd9Sstevel@tonic-gate if (!fpu_exists) 28487c478bd9Sstevel@tonic-gate *edx &= ~(CPUID_AMD_EDX_MMXamd | 28497c478bd9Sstevel@tonic-gate CPUID_AMD_EDX_3DNow | CPUID_AMD_EDX_3DNowx); 28507c478bd9Sstevel@tonic-gate 28517417cfdeSKuriakose Kuruvilla if (!is_x86_feature(x86_featureset, X86FSET_NX)) 28527c478bd9Sstevel@tonic-gate *edx &= ~CPUID_AMD_EDX_NX; 2853ae115bc7Smrj #if !defined(__amd64) 28547c478bd9Sstevel@tonic-gate *edx &= ~CPUID_AMD_EDX_LM; 28557c478bd9Sstevel@tonic-gate #endif 28567c478bd9Sstevel@tonic-gate /* 28577c478bd9Sstevel@tonic-gate * Now map the supported feature vector to 28587c478bd9Sstevel@tonic-gate * things that we think userland will care about. 28597c478bd9Sstevel@tonic-gate */ 2860ae115bc7Smrj #if defined(__amd64) 28617c478bd9Sstevel@tonic-gate if (*edx & CPUID_AMD_EDX_SYSC) 28627c478bd9Sstevel@tonic-gate hwcap_flags |= AV_386_AMD_SYSC; 2863ae115bc7Smrj #endif 28647c478bd9Sstevel@tonic-gate if (*edx & CPUID_AMD_EDX_MMXamd) 28657c478bd9Sstevel@tonic-gate hwcap_flags |= AV_386_AMD_MMX; 28667c478bd9Sstevel@tonic-gate if (*edx & CPUID_AMD_EDX_3DNow) 28677c478bd9Sstevel@tonic-gate hwcap_flags |= AV_386_AMD_3DNow; 28687c478bd9Sstevel@tonic-gate if (*edx & CPUID_AMD_EDX_3DNowx) 28697c478bd9Sstevel@tonic-gate hwcap_flags |= AV_386_AMD_3DNowx; 2870faa20166SBryan Cantrill if (*ecx & CPUID_AMD_ECX_SVM) 2871faa20166SBryan Cantrill hwcap_flags |= AV_386_AMD_SVM; 2872ae115bc7Smrj 2873ae115bc7Smrj switch (cpi->cpi_vendor) { 2874ae115bc7Smrj case X86_VENDOR_AMD: 2875ae115bc7Smrj if (*edx & CPUID_AMD_EDX_TSCP) 2876ae115bc7Smrj hwcap_flags |= AV_386_TSCP; 2877ae115bc7Smrj if (*ecx & CPUID_AMD_ECX_AHF64) 2878ae115bc7Smrj hwcap_flags |= AV_386_AHF; 2879f8801251Skk208521 if (*ecx & CPUID_AMD_ECX_SSE4A) 2880f8801251Skk208521 hwcap_flags |= AV_386_AMD_SSE4A; 2881f8801251Skk208521 if (*ecx & CPUID_AMD_ECX_LZCNT) 2882f8801251Skk208521 hwcap_flags |= AV_386_AMD_LZCNT; 2883ae115bc7Smrj break; 2884ae115bc7Smrj 2885ae115bc7Smrj case X86_VENDOR_Intel: 2886d36ea5d8Ssudheer if (*edx & CPUID_AMD_EDX_TSCP) 2887d36ea5d8Ssudheer hwcap_flags |= AV_386_TSCP; 2888ae115bc7Smrj /* 2889ae115bc7Smrj * Aarrgh. 2890ae115bc7Smrj * Intel uses a different bit in the same word. 2891ae115bc7Smrj */ 2892ae115bc7Smrj if (*ecx & CPUID_INTC_ECX_AHF64) 2893ae115bc7Smrj hwcap_flags |= AV_386_AHF; 2894ae115bc7Smrj break; 2895ae115bc7Smrj 2896ae115bc7Smrj default: 2897ae115bc7Smrj break; 2898ae115bc7Smrj } 28997c478bd9Sstevel@tonic-gate break; 29007c478bd9Sstevel@tonic-gate 29017c478bd9Sstevel@tonic-gate case X86_VENDOR_TM: 29028949bcd6Sandrei cp.cp_eax = 0x80860001; 29038949bcd6Sandrei (void) __cpuid_insn(&cp); 29048949bcd6Sandrei cpi->cpi_support[TM_EDX_FEATURES] = cp.cp_edx; 29057c478bd9Sstevel@tonic-gate break; 29067c478bd9Sstevel@tonic-gate 29077c478bd9Sstevel@tonic-gate default: 29087c478bd9Sstevel@tonic-gate break; 29097c478bd9Sstevel@tonic-gate } 29107c478bd9Sstevel@tonic-gate 29117c478bd9Sstevel@tonic-gate pass4_done: 29127c478bd9Sstevel@tonic-gate cpi->cpi_pass = 4; 2913ebb8ac07SRobert Mustacchi if (hwcap_out != NULL) { 2914ebb8ac07SRobert Mustacchi hwcap_out[0] = hwcap_flags; 2915ebb8ac07SRobert Mustacchi hwcap_out[1] = hwcap_flags_2; 2916ebb8ac07SRobert Mustacchi } 29177c478bd9Sstevel@tonic-gate } 29187c478bd9Sstevel@tonic-gate 29197c478bd9Sstevel@tonic-gate 29207c478bd9Sstevel@tonic-gate /* 29217c478bd9Sstevel@tonic-gate * Simulate the cpuid instruction using the data we previously 29227c478bd9Sstevel@tonic-gate * captured about this CPU. We try our best to return the truth 29237c478bd9Sstevel@tonic-gate * about the hardware, independently of kernel support. 29247c478bd9Sstevel@tonic-gate */ 29257c478bd9Sstevel@tonic-gate uint32_t 29268949bcd6Sandrei cpuid_insn(cpu_t *cpu, struct cpuid_regs *cp) 29277c478bd9Sstevel@tonic-gate { 29287c478bd9Sstevel@tonic-gate struct cpuid_info *cpi; 29298949bcd6Sandrei struct cpuid_regs *xcp; 29307c478bd9Sstevel@tonic-gate 29317c478bd9Sstevel@tonic-gate if (cpu == NULL) 29327c478bd9Sstevel@tonic-gate cpu = CPU; 29337c478bd9Sstevel@tonic-gate cpi = cpu->cpu_m.mcpu_cpi; 29347c478bd9Sstevel@tonic-gate 29357c478bd9Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 3)); 29367c478bd9Sstevel@tonic-gate 29377c478bd9Sstevel@tonic-gate /* 29387c478bd9Sstevel@tonic-gate * CPUID data is cached in two separate places: cpi_std for standard 29397c478bd9Sstevel@tonic-gate * CPUID functions, and cpi_extd for extended CPUID functions. 29407c478bd9Sstevel@tonic-gate */ 29418949bcd6Sandrei if (cp->cp_eax <= cpi->cpi_maxeax && cp->cp_eax < NMAX_CPI_STD) 29428949bcd6Sandrei xcp = &cpi->cpi_std[cp->cp_eax]; 29438949bcd6Sandrei else if (cp->cp_eax >= 0x80000000 && cp->cp_eax <= cpi->cpi_xmaxeax && 29448949bcd6Sandrei cp->cp_eax < 0x80000000 + NMAX_CPI_EXTD) 29458949bcd6Sandrei xcp = &cpi->cpi_extd[cp->cp_eax - 0x80000000]; 29467c478bd9Sstevel@tonic-gate else 29477c478bd9Sstevel@tonic-gate /* 29487c478bd9Sstevel@tonic-gate * The caller is asking for data from an input parameter which 29497c478bd9Sstevel@tonic-gate * the kernel has not cached. In this case we go fetch from 29507c478bd9Sstevel@tonic-gate * the hardware and return the data directly to the user. 29517c478bd9Sstevel@tonic-gate */ 29528949bcd6Sandrei return (__cpuid_insn(cp)); 29538949bcd6Sandrei 29548949bcd6Sandrei cp->cp_eax = xcp->cp_eax; 29558949bcd6Sandrei cp->cp_ebx = xcp->cp_ebx; 29568949bcd6Sandrei cp->cp_ecx = xcp->cp_ecx; 29578949bcd6Sandrei cp->cp_edx = xcp->cp_edx; 29587c478bd9Sstevel@tonic-gate return (cp->cp_eax); 29597c478bd9Sstevel@tonic-gate } 29607c478bd9Sstevel@tonic-gate 29617c478bd9Sstevel@tonic-gate int 29627c478bd9Sstevel@tonic-gate cpuid_checkpass(cpu_t *cpu, int pass) 29637c478bd9Sstevel@tonic-gate { 29647c478bd9Sstevel@tonic-gate return (cpu != NULL && cpu->cpu_m.mcpu_cpi != NULL && 29657c478bd9Sstevel@tonic-gate cpu->cpu_m.mcpu_cpi->cpi_pass >= pass); 29667c478bd9Sstevel@tonic-gate } 29677c478bd9Sstevel@tonic-gate 29687c478bd9Sstevel@tonic-gate int 29697c478bd9Sstevel@tonic-gate cpuid_getbrandstr(cpu_t *cpu, char *s, size_t n) 29707c478bd9Sstevel@tonic-gate { 29717c478bd9Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 3)); 29727c478bd9Sstevel@tonic-gate 29737c478bd9Sstevel@tonic-gate return (snprintf(s, n, "%s", cpu->cpu_m.mcpu_cpi->cpi_brandstr)); 29747c478bd9Sstevel@tonic-gate } 29757c478bd9Sstevel@tonic-gate 29767c478bd9Sstevel@tonic-gate int 29778949bcd6Sandrei cpuid_is_cmt(cpu_t *cpu) 29787c478bd9Sstevel@tonic-gate { 29797c478bd9Sstevel@tonic-gate if (cpu == NULL) 29807c478bd9Sstevel@tonic-gate cpu = CPU; 29817c478bd9Sstevel@tonic-gate 29827c478bd9Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 29837c478bd9Sstevel@tonic-gate 29847c478bd9Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_chipid >= 0); 29857c478bd9Sstevel@tonic-gate } 29867c478bd9Sstevel@tonic-gate 29877c478bd9Sstevel@tonic-gate /* 29887c478bd9Sstevel@tonic-gate * AMD and Intel both implement the 64-bit variant of the syscall 29897c478bd9Sstevel@tonic-gate * instruction (syscallq), so if there's -any- support for syscall, 29907c478bd9Sstevel@tonic-gate * cpuid currently says "yes, we support this". 29917c478bd9Sstevel@tonic-gate * 29927c478bd9Sstevel@tonic-gate * However, Intel decided to -not- implement the 32-bit variant of the 29937c478bd9Sstevel@tonic-gate * syscall instruction, so we provide a predicate to allow our caller 29947c478bd9Sstevel@tonic-gate * to test that subtlety here. 2995843e1988Sjohnlev * 2996843e1988Sjohnlev * XXPV Currently, 32-bit syscall instructions don't work via the hypervisor, 2997843e1988Sjohnlev * even in the case where the hardware would in fact support it. 29987c478bd9Sstevel@tonic-gate */ 29997c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 30007c478bd9Sstevel@tonic-gate int 30017c478bd9Sstevel@tonic-gate cpuid_syscall32_insn(cpu_t *cpu) 30027c478bd9Sstevel@tonic-gate { 30037c478bd9Sstevel@tonic-gate ASSERT(cpuid_checkpass((cpu == NULL ? CPU : cpu), 1)); 30047c478bd9Sstevel@tonic-gate 3005843e1988Sjohnlev #if !defined(__xpv) 3006ae115bc7Smrj if (cpu == NULL) 3007ae115bc7Smrj cpu = CPU; 3008ae115bc7Smrj 3009ae115bc7Smrj /*CSTYLED*/ 3010ae115bc7Smrj { 3011ae115bc7Smrj struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 3012ae115bc7Smrj 3013ae115bc7Smrj if (cpi->cpi_vendor == X86_VENDOR_AMD && 3014ae115bc7Smrj cpi->cpi_xmaxeax >= 0x80000001 && 3015ae115bc7Smrj (CPI_FEATURES_XTD_EDX(cpi) & CPUID_AMD_EDX_SYSC)) 3016ae115bc7Smrj return (1); 3017ae115bc7Smrj } 3018843e1988Sjohnlev #endif 30197c478bd9Sstevel@tonic-gate return (0); 30207c478bd9Sstevel@tonic-gate } 30217c478bd9Sstevel@tonic-gate 30227c478bd9Sstevel@tonic-gate int 30237c478bd9Sstevel@tonic-gate cpuid_getidstr(cpu_t *cpu, char *s, size_t n) 30247c478bd9Sstevel@tonic-gate { 30257c478bd9Sstevel@tonic-gate struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 30267c478bd9Sstevel@tonic-gate 30277c478bd9Sstevel@tonic-gate static const char fmt[] = 3028ecfa43a5Sdmick "x86 (%s %X family %d model %d step %d clock %d MHz)"; 30297c478bd9Sstevel@tonic-gate static const char fmt_ht[] = 3030ecfa43a5Sdmick "x86 (chipid 0x%x %s %X family %d model %d step %d clock %d MHz)"; 30317c478bd9Sstevel@tonic-gate 30327c478bd9Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 30337c478bd9Sstevel@tonic-gate 30348949bcd6Sandrei if (cpuid_is_cmt(cpu)) 30357c478bd9Sstevel@tonic-gate return (snprintf(s, n, fmt_ht, cpi->cpi_chipid, 3036ecfa43a5Sdmick cpi->cpi_vendorstr, cpi->cpi_std[1].cp_eax, 3037ecfa43a5Sdmick cpi->cpi_family, cpi->cpi_model, 30387c478bd9Sstevel@tonic-gate cpi->cpi_step, cpu->cpu_type_info.pi_clock)); 30397c478bd9Sstevel@tonic-gate return (snprintf(s, n, fmt, 3040ecfa43a5Sdmick cpi->cpi_vendorstr, cpi->cpi_std[1].cp_eax, 3041ecfa43a5Sdmick cpi->cpi_family, cpi->cpi_model, 30427c478bd9Sstevel@tonic-gate cpi->cpi_step, cpu->cpu_type_info.pi_clock)); 30437c478bd9Sstevel@tonic-gate } 30447c478bd9Sstevel@tonic-gate 30457c478bd9Sstevel@tonic-gate const char * 30467c478bd9Sstevel@tonic-gate cpuid_getvendorstr(cpu_t *cpu) 30477c478bd9Sstevel@tonic-gate { 30487c478bd9Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 30497c478bd9Sstevel@tonic-gate return ((const char *)cpu->cpu_m.mcpu_cpi->cpi_vendorstr); 30507c478bd9Sstevel@tonic-gate } 30517c478bd9Sstevel@tonic-gate 30527c478bd9Sstevel@tonic-gate uint_t 30537c478bd9Sstevel@tonic-gate cpuid_getvendor(cpu_t *cpu) 30547c478bd9Sstevel@tonic-gate { 30557c478bd9Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 30567c478bd9Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_vendor); 30577c478bd9Sstevel@tonic-gate } 30587c478bd9Sstevel@tonic-gate 30597c478bd9Sstevel@tonic-gate uint_t 30607c478bd9Sstevel@tonic-gate cpuid_getfamily(cpu_t *cpu) 30617c478bd9Sstevel@tonic-gate { 30627c478bd9Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 30637c478bd9Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_family); 30647c478bd9Sstevel@tonic-gate } 30657c478bd9Sstevel@tonic-gate 30667c478bd9Sstevel@tonic-gate uint_t 30677c478bd9Sstevel@tonic-gate cpuid_getmodel(cpu_t *cpu) 30687c478bd9Sstevel@tonic-gate { 30697c478bd9Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 30707c478bd9Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_model); 30717c478bd9Sstevel@tonic-gate } 30727c478bd9Sstevel@tonic-gate 30737c478bd9Sstevel@tonic-gate uint_t 30747c478bd9Sstevel@tonic-gate cpuid_get_ncpu_per_chip(cpu_t *cpu) 30757c478bd9Sstevel@tonic-gate { 30767c478bd9Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 30777c478bd9Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_ncpu_per_chip); 30787c478bd9Sstevel@tonic-gate } 30797c478bd9Sstevel@tonic-gate 30807c478bd9Sstevel@tonic-gate uint_t 30818949bcd6Sandrei cpuid_get_ncore_per_chip(cpu_t *cpu) 30828949bcd6Sandrei { 30838949bcd6Sandrei ASSERT(cpuid_checkpass(cpu, 1)); 30848949bcd6Sandrei return (cpu->cpu_m.mcpu_cpi->cpi_ncore_per_chip); 30858949bcd6Sandrei } 30868949bcd6Sandrei 30878949bcd6Sandrei uint_t 3088d129bde2Sesaxe cpuid_get_ncpu_sharing_last_cache(cpu_t *cpu) 3089d129bde2Sesaxe { 3090d129bde2Sesaxe ASSERT(cpuid_checkpass(cpu, 2)); 3091d129bde2Sesaxe return (cpu->cpu_m.mcpu_cpi->cpi_ncpu_shr_last_cache); 3092d129bde2Sesaxe } 3093d129bde2Sesaxe 3094d129bde2Sesaxe id_t 3095d129bde2Sesaxe cpuid_get_last_lvl_cacheid(cpu_t *cpu) 3096d129bde2Sesaxe { 3097d129bde2Sesaxe ASSERT(cpuid_checkpass(cpu, 2)); 3098d129bde2Sesaxe return (cpu->cpu_m.mcpu_cpi->cpi_last_lvl_cacheid); 3099d129bde2Sesaxe } 3100d129bde2Sesaxe 3101d129bde2Sesaxe uint_t 31027c478bd9Sstevel@tonic-gate cpuid_getstep(cpu_t *cpu) 31037c478bd9Sstevel@tonic-gate { 31047c478bd9Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 31057c478bd9Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_step); 31067c478bd9Sstevel@tonic-gate } 31077c478bd9Sstevel@tonic-gate 31082449e17fSsherrym uint_t 31092449e17fSsherrym cpuid_getsig(struct cpu *cpu) 31102449e17fSsherrym { 31112449e17fSsherrym ASSERT(cpuid_checkpass(cpu, 1)); 31122449e17fSsherrym return (cpu->cpu_m.mcpu_cpi->cpi_std[1].cp_eax); 31132449e17fSsherrym } 31142449e17fSsherrym 31158a40a695Sgavinm uint32_t 31168a40a695Sgavinm cpuid_getchiprev(struct cpu *cpu) 31178a40a695Sgavinm { 31188a40a695Sgavinm ASSERT(cpuid_checkpass(cpu, 1)); 31198a40a695Sgavinm return (cpu->cpu_m.mcpu_cpi->cpi_chiprev); 31208a40a695Sgavinm } 31218a40a695Sgavinm 31228a40a695Sgavinm const char * 31238a40a695Sgavinm cpuid_getchiprevstr(struct cpu *cpu) 31248a40a695Sgavinm { 31258a40a695Sgavinm ASSERT(cpuid_checkpass(cpu, 1)); 31268a40a695Sgavinm return (cpu->cpu_m.mcpu_cpi->cpi_chiprevstr); 31278a40a695Sgavinm } 31288a40a695Sgavinm 31298a40a695Sgavinm uint32_t 31308a40a695Sgavinm cpuid_getsockettype(struct cpu *cpu) 31318a40a695Sgavinm { 31328a40a695Sgavinm ASSERT(cpuid_checkpass(cpu, 1)); 31338a40a695Sgavinm return (cpu->cpu_m.mcpu_cpi->cpi_socket); 31348a40a695Sgavinm } 31358a40a695Sgavinm 313689e921d5SKuriakose Kuruvilla const char * 313789e921d5SKuriakose Kuruvilla cpuid_getsocketstr(cpu_t *cpu) 313889e921d5SKuriakose Kuruvilla { 313989e921d5SKuriakose Kuruvilla static const char *socketstr = NULL; 314089e921d5SKuriakose Kuruvilla struct cpuid_info *cpi; 314189e921d5SKuriakose Kuruvilla 314289e921d5SKuriakose Kuruvilla ASSERT(cpuid_checkpass(cpu, 1)); 314389e921d5SKuriakose Kuruvilla cpi = cpu->cpu_m.mcpu_cpi; 314489e921d5SKuriakose Kuruvilla 314589e921d5SKuriakose Kuruvilla /* Assume that socket types are the same across the system */ 314689e921d5SKuriakose Kuruvilla if (socketstr == NULL) 314789e921d5SKuriakose Kuruvilla socketstr = _cpuid_sktstr(cpi->cpi_vendor, cpi->cpi_family, 314889e921d5SKuriakose Kuruvilla cpi->cpi_model, cpi->cpi_step); 314989e921d5SKuriakose Kuruvilla 315089e921d5SKuriakose Kuruvilla 315189e921d5SKuriakose Kuruvilla return (socketstr); 315289e921d5SKuriakose Kuruvilla } 315389e921d5SKuriakose Kuruvilla 3154fb2f18f8Sesaxe int 3155fb2f18f8Sesaxe cpuid_get_chipid(cpu_t *cpu) 31567c478bd9Sstevel@tonic-gate { 31577c478bd9Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 31587c478bd9Sstevel@tonic-gate 31598949bcd6Sandrei if (cpuid_is_cmt(cpu)) 31607c478bd9Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_chipid); 31617c478bd9Sstevel@tonic-gate return (cpu->cpu_id); 31627c478bd9Sstevel@tonic-gate } 31637c478bd9Sstevel@tonic-gate 31648949bcd6Sandrei id_t 3165fb2f18f8Sesaxe cpuid_get_coreid(cpu_t *cpu) 31668949bcd6Sandrei { 31678949bcd6Sandrei ASSERT(cpuid_checkpass(cpu, 1)); 31688949bcd6Sandrei return (cpu->cpu_m.mcpu_cpi->cpi_coreid); 31698949bcd6Sandrei } 31708949bcd6Sandrei 31717c478bd9Sstevel@tonic-gate int 317210569901Sgavinm cpuid_get_pkgcoreid(cpu_t *cpu) 317310569901Sgavinm { 317410569901Sgavinm ASSERT(cpuid_checkpass(cpu, 1)); 317510569901Sgavinm return (cpu->cpu_m.mcpu_cpi->cpi_pkgcoreid); 317610569901Sgavinm } 317710569901Sgavinm 317810569901Sgavinm int 3179fb2f18f8Sesaxe cpuid_get_clogid(cpu_t *cpu) 31807c478bd9Sstevel@tonic-gate { 31817c478bd9Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 31827c478bd9Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_clogid); 31837c478bd9Sstevel@tonic-gate } 31847c478bd9Sstevel@tonic-gate 3185b885580bSAlexander Kolbasov int 3186b885580bSAlexander Kolbasov cpuid_get_cacheid(cpu_t *cpu) 3187b885580bSAlexander Kolbasov { 3188b885580bSAlexander Kolbasov ASSERT(cpuid_checkpass(cpu, 1)); 3189b885580bSAlexander Kolbasov return (cpu->cpu_m.mcpu_cpi->cpi_last_lvl_cacheid); 3190b885580bSAlexander Kolbasov } 3191b885580bSAlexander Kolbasov 31928031591dSSrihari Venkatesan uint_t 31938031591dSSrihari Venkatesan cpuid_get_procnodeid(cpu_t *cpu) 31948031591dSSrihari Venkatesan { 31958031591dSSrihari Venkatesan ASSERT(cpuid_checkpass(cpu, 1)); 31968031591dSSrihari Venkatesan return (cpu->cpu_m.mcpu_cpi->cpi_procnodeid); 31978031591dSSrihari Venkatesan } 31988031591dSSrihari Venkatesan 31998031591dSSrihari Venkatesan uint_t 32008031591dSSrihari Venkatesan cpuid_get_procnodes_per_pkg(cpu_t *cpu) 32018031591dSSrihari Venkatesan { 32028031591dSSrihari Venkatesan ASSERT(cpuid_checkpass(cpu, 1)); 32038031591dSSrihari Venkatesan return (cpu->cpu_m.mcpu_cpi->cpi_procnodes_per_pkg); 32048031591dSSrihari Venkatesan } 32058031591dSSrihari Venkatesan 32067660e73fSHans Rosenfeld uint_t 32077660e73fSHans Rosenfeld cpuid_get_compunitid(cpu_t *cpu) 32087660e73fSHans Rosenfeld { 32097660e73fSHans Rosenfeld ASSERT(cpuid_checkpass(cpu, 1)); 32107660e73fSHans Rosenfeld return (cpu->cpu_m.mcpu_cpi->cpi_compunitid); 32117660e73fSHans Rosenfeld } 32127660e73fSHans Rosenfeld 32137660e73fSHans Rosenfeld uint_t 32147660e73fSHans Rosenfeld cpuid_get_cores_per_compunit(cpu_t *cpu) 32157660e73fSHans Rosenfeld { 32167660e73fSHans Rosenfeld ASSERT(cpuid_checkpass(cpu, 1)); 32177660e73fSHans Rosenfeld return (cpu->cpu_m.mcpu_cpi->cpi_cores_per_compunit); 32187660e73fSHans Rosenfeld } 32197660e73fSHans Rosenfeld 32202ef50f01SJoe Bonasera /*ARGSUSED*/ 32212ef50f01SJoe Bonasera int 32222ef50f01SJoe Bonasera cpuid_have_cr8access(cpu_t *cpu) 32232ef50f01SJoe Bonasera { 32242ef50f01SJoe Bonasera #if defined(__amd64) 32252ef50f01SJoe Bonasera return (1); 32262ef50f01SJoe Bonasera #else 32272ef50f01SJoe Bonasera struct cpuid_info *cpi; 32282ef50f01SJoe Bonasera 32292ef50f01SJoe Bonasera ASSERT(cpu != NULL); 32302ef50f01SJoe Bonasera cpi = cpu->cpu_m.mcpu_cpi; 32312ef50f01SJoe Bonasera if (cpi->cpi_vendor == X86_VENDOR_AMD && cpi->cpi_maxeax >= 1 && 32322ef50f01SJoe Bonasera (CPI_FEATURES_XTD_ECX(cpi) & CPUID_AMD_ECX_CR8D) != 0) 32332ef50f01SJoe Bonasera return (1); 32342ef50f01SJoe Bonasera return (0); 32352ef50f01SJoe Bonasera #endif 32362ef50f01SJoe Bonasera } 32372ef50f01SJoe Bonasera 3238fa96bd91SMichael Corcoran uint32_t 3239fa96bd91SMichael Corcoran cpuid_get_apicid(cpu_t *cpu) 3240fa96bd91SMichael Corcoran { 3241fa96bd91SMichael Corcoran ASSERT(cpuid_checkpass(cpu, 1)); 3242fa96bd91SMichael Corcoran if (cpu->cpu_m.mcpu_cpi->cpi_maxeax < 1) { 3243fa96bd91SMichael Corcoran return (UINT32_MAX); 3244fa96bd91SMichael Corcoran } else { 3245fa96bd91SMichael Corcoran return (cpu->cpu_m.mcpu_cpi->cpi_apicid); 3246fa96bd91SMichael Corcoran } 3247fa96bd91SMichael Corcoran } 3248fa96bd91SMichael Corcoran 32497c478bd9Sstevel@tonic-gate void 32507c478bd9Sstevel@tonic-gate cpuid_get_addrsize(cpu_t *cpu, uint_t *pabits, uint_t *vabits) 32517c478bd9Sstevel@tonic-gate { 32527c478bd9Sstevel@tonic-gate struct cpuid_info *cpi; 32537c478bd9Sstevel@tonic-gate 32547c478bd9Sstevel@tonic-gate if (cpu == NULL) 32557c478bd9Sstevel@tonic-gate cpu = CPU; 32567c478bd9Sstevel@tonic-gate cpi = cpu->cpu_m.mcpu_cpi; 32577c478bd9Sstevel@tonic-gate 32587c478bd9Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 32597c478bd9Sstevel@tonic-gate 32607c478bd9Sstevel@tonic-gate if (pabits) 32617c478bd9Sstevel@tonic-gate *pabits = cpi->cpi_pabits; 32627c478bd9Sstevel@tonic-gate if (vabits) 32637c478bd9Sstevel@tonic-gate *vabits = cpi->cpi_vabits; 32647c478bd9Sstevel@tonic-gate } 32657c478bd9Sstevel@tonic-gate 32667c478bd9Sstevel@tonic-gate /* 32677c478bd9Sstevel@tonic-gate * Returns the number of data TLB entries for a corresponding 32687c478bd9Sstevel@tonic-gate * pagesize. If it can't be computed, or isn't known, the 32697c478bd9Sstevel@tonic-gate * routine returns zero. If you ask about an architecturally 32707c478bd9Sstevel@tonic-gate * impossible pagesize, the routine will panic (so that the 32717c478bd9Sstevel@tonic-gate * hat implementor knows that things are inconsistent.) 32727c478bd9Sstevel@tonic-gate */ 32737c478bd9Sstevel@tonic-gate uint_t 32747c478bd9Sstevel@tonic-gate cpuid_get_dtlb_nent(cpu_t *cpu, size_t pagesize) 32757c478bd9Sstevel@tonic-gate { 32767c478bd9Sstevel@tonic-gate struct cpuid_info *cpi; 32777c478bd9Sstevel@tonic-gate uint_t dtlb_nent = 0; 32787c478bd9Sstevel@tonic-gate 32797c478bd9Sstevel@tonic-gate if (cpu == NULL) 32807c478bd9Sstevel@tonic-gate cpu = CPU; 32817c478bd9Sstevel@tonic-gate cpi = cpu->cpu_m.mcpu_cpi; 32827c478bd9Sstevel@tonic-gate 32837c478bd9Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 32847c478bd9Sstevel@tonic-gate 32857c478bd9Sstevel@tonic-gate /* 32867c478bd9Sstevel@tonic-gate * Check the L2 TLB info 32877c478bd9Sstevel@tonic-gate */ 32887c478bd9Sstevel@tonic-gate if (cpi->cpi_xmaxeax >= 0x80000006) { 32898949bcd6Sandrei struct cpuid_regs *cp = &cpi->cpi_extd[6]; 32907c478bd9Sstevel@tonic-gate 32917c478bd9Sstevel@tonic-gate switch (pagesize) { 32927c478bd9Sstevel@tonic-gate 32937c478bd9Sstevel@tonic-gate case 4 * 1024: 32947c478bd9Sstevel@tonic-gate /* 32957c478bd9Sstevel@tonic-gate * All zero in the top 16 bits of the register 32967c478bd9Sstevel@tonic-gate * indicates a unified TLB. Size is in low 16 bits. 32977c478bd9Sstevel@tonic-gate */ 32987c478bd9Sstevel@tonic-gate if ((cp->cp_ebx & 0xffff0000) == 0) 32997c478bd9Sstevel@tonic-gate dtlb_nent = cp->cp_ebx & 0x0000ffff; 33007c478bd9Sstevel@tonic-gate else 33017c478bd9Sstevel@tonic-gate dtlb_nent = BITX(cp->cp_ebx, 27, 16); 33027c478bd9Sstevel@tonic-gate break; 33037c478bd9Sstevel@tonic-gate 33047c478bd9Sstevel@tonic-gate case 2 * 1024 * 1024: 33057c478bd9Sstevel@tonic-gate if ((cp->cp_eax & 0xffff0000) == 0) 33067c478bd9Sstevel@tonic-gate dtlb_nent = cp->cp_eax & 0x0000ffff; 33077c478bd9Sstevel@tonic-gate else 33087c478bd9Sstevel@tonic-gate dtlb_nent = BITX(cp->cp_eax, 27, 16); 33097c478bd9Sstevel@tonic-gate break; 33107c478bd9Sstevel@tonic-gate 33117c478bd9Sstevel@tonic-gate default: 33127c478bd9Sstevel@tonic-gate panic("unknown L2 pagesize"); 33137c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 33147c478bd9Sstevel@tonic-gate } 33157c478bd9Sstevel@tonic-gate } 33167c478bd9Sstevel@tonic-gate 33177c478bd9Sstevel@tonic-gate if (dtlb_nent != 0) 33187c478bd9Sstevel@tonic-gate return (dtlb_nent); 33197c478bd9Sstevel@tonic-gate 33207c478bd9Sstevel@tonic-gate /* 33217c478bd9Sstevel@tonic-gate * No L2 TLB support for this size, try L1. 33227c478bd9Sstevel@tonic-gate */ 33237c478bd9Sstevel@tonic-gate if (cpi->cpi_xmaxeax >= 0x80000005) { 33248949bcd6Sandrei struct cpuid_regs *cp = &cpi->cpi_extd[5]; 33257c478bd9Sstevel@tonic-gate 33267c478bd9Sstevel@tonic-gate switch (pagesize) { 33277c478bd9Sstevel@tonic-gate case 4 * 1024: 33287c478bd9Sstevel@tonic-gate dtlb_nent = BITX(cp->cp_ebx, 23, 16); 33297c478bd9Sstevel@tonic-gate break; 33307c478bd9Sstevel@tonic-gate case 2 * 1024 * 1024: 33317c478bd9Sstevel@tonic-gate dtlb_nent = BITX(cp->cp_eax, 23, 16); 33327c478bd9Sstevel@tonic-gate break; 33337c478bd9Sstevel@tonic-gate default: 33347c478bd9Sstevel@tonic-gate panic("unknown L1 d-TLB pagesize"); 33357c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 33367c478bd9Sstevel@tonic-gate } 33377c478bd9Sstevel@tonic-gate } 33387c478bd9Sstevel@tonic-gate 33397c478bd9Sstevel@tonic-gate return (dtlb_nent); 33407c478bd9Sstevel@tonic-gate } 33417c478bd9Sstevel@tonic-gate 33427c478bd9Sstevel@tonic-gate /* 33437c478bd9Sstevel@tonic-gate * Return 0 if the erratum is not present or not applicable, positive 33447c478bd9Sstevel@tonic-gate * if it is, and negative if the status of the erratum is unknown. 33457c478bd9Sstevel@tonic-gate * 33467c478bd9Sstevel@tonic-gate * See "Revision Guide for AMD Athlon(tm) 64 and AMD Opteron(tm) 33472201b277Skucharsk * Processors" #25759, Rev 3.57, August 2005 33487c478bd9Sstevel@tonic-gate */ 33497c478bd9Sstevel@tonic-gate int 33507c478bd9Sstevel@tonic-gate cpuid_opteron_erratum(cpu_t *cpu, uint_t erratum) 33517c478bd9Sstevel@tonic-gate { 33527c478bd9Sstevel@tonic-gate struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 33538949bcd6Sandrei uint_t eax; 33547c478bd9Sstevel@tonic-gate 3355ea99987eSsethg /* 3356ea99987eSsethg * Bail out if this CPU isn't an AMD CPU, or if it's 3357ea99987eSsethg * a legacy (32-bit) AMD CPU. 3358ea99987eSsethg */ 3359ea99987eSsethg if (cpi->cpi_vendor != X86_VENDOR_AMD || 3360875b116eSkchow cpi->cpi_family == 4 || cpi->cpi_family == 5 || 3361875b116eSkchow cpi->cpi_family == 6) 33628a40a695Sgavinm 33637c478bd9Sstevel@tonic-gate return (0); 33647c478bd9Sstevel@tonic-gate 33657c478bd9Sstevel@tonic-gate eax = cpi->cpi_std[1].cp_eax; 33667c478bd9Sstevel@tonic-gate 33677c478bd9Sstevel@tonic-gate #define SH_B0(eax) (eax == 0xf40 || eax == 0xf50) 33687c478bd9Sstevel@tonic-gate #define SH_B3(eax) (eax == 0xf51) 3369ee88d2b9Skchow #define B(eax) (SH_B0(eax) || SH_B3(eax)) 33707c478bd9Sstevel@tonic-gate 33717c478bd9Sstevel@tonic-gate #define SH_C0(eax) (eax == 0xf48 || eax == 0xf58) 33727c478bd9Sstevel@tonic-gate 33737c478bd9Sstevel@tonic-gate #define SH_CG(eax) (eax == 0xf4a || eax == 0xf5a || eax == 0xf7a) 33747c478bd9Sstevel@tonic-gate #define DH_CG(eax) (eax == 0xfc0 || eax == 0xfe0 || eax == 0xff0) 33757c478bd9Sstevel@tonic-gate #define CH_CG(eax) (eax == 0xf82 || eax == 0xfb2) 3376ee88d2b9Skchow #define CG(eax) (SH_CG(eax) || DH_CG(eax) || CH_CG(eax)) 33777c478bd9Sstevel@tonic-gate 33787c478bd9Sstevel@tonic-gate #define SH_D0(eax) (eax == 0x10f40 || eax == 0x10f50 || eax == 0x10f70) 33797c478bd9Sstevel@tonic-gate #define DH_D0(eax) (eax == 0x10fc0 || eax == 0x10ff0) 33807c478bd9Sstevel@tonic-gate #define CH_D0(eax) (eax == 0x10f80 || eax == 0x10fb0) 3381ee88d2b9Skchow #define D0(eax) (SH_D0(eax) || DH_D0(eax) || CH_D0(eax)) 33827c478bd9Sstevel@tonic-gate 33837c478bd9Sstevel@tonic-gate #define SH_E0(eax) (eax == 0x20f50 || eax == 0x20f40 || eax == 0x20f70) 33847c478bd9Sstevel@tonic-gate #define JH_E1(eax) (eax == 0x20f10) /* JH8_E0 had 0x20f30 */ 33857c478bd9Sstevel@tonic-gate #define DH_E3(eax) (eax == 0x20fc0 || eax == 0x20ff0) 33867c478bd9Sstevel@tonic-gate #define SH_E4(eax) (eax == 0x20f51 || eax == 0x20f71) 33877c478bd9Sstevel@tonic-gate #define BH_E4(eax) (eax == 0x20fb1) 33887c478bd9Sstevel@tonic-gate #define SH_E5(eax) (eax == 0x20f42) 33897c478bd9Sstevel@tonic-gate #define DH_E6(eax) (eax == 0x20ff2 || eax == 0x20fc2) 33907c478bd9Sstevel@tonic-gate #define JH_E6(eax) (eax == 0x20f12 || eax == 0x20f32) 3391ee88d2b9Skchow #define EX(eax) (SH_E0(eax) || JH_E1(eax) || DH_E3(eax) || \ 3392ee88d2b9Skchow SH_E4(eax) || BH_E4(eax) || SH_E5(eax) || \ 3393ee88d2b9Skchow DH_E6(eax) || JH_E6(eax)) 33947c478bd9Sstevel@tonic-gate 3395512cf780Skchow #define DR_AX(eax) (eax == 0x100f00 || eax == 0x100f01 || eax == 0x100f02) 3396512cf780Skchow #define DR_B0(eax) (eax == 0x100f20) 3397512cf780Skchow #define DR_B1(eax) (eax == 0x100f21) 3398512cf780Skchow #define DR_BA(eax) (eax == 0x100f2a) 3399512cf780Skchow #define DR_B2(eax) (eax == 0x100f22) 3400512cf780Skchow #define DR_B3(eax) (eax == 0x100f23) 3401512cf780Skchow #define RB_C0(eax) (eax == 0x100f40) 3402512cf780Skchow 34037c478bd9Sstevel@tonic-gate switch (erratum) { 34047c478bd9Sstevel@tonic-gate case 1: 3405875b116eSkchow return (cpi->cpi_family < 0x10); 34067c478bd9Sstevel@tonic-gate case 51: /* what does the asterisk mean? */ 34077c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax)); 34087c478bd9Sstevel@tonic-gate case 52: 34097c478bd9Sstevel@tonic-gate return (B(eax)); 34107c478bd9Sstevel@tonic-gate case 57: 3411512cf780Skchow return (cpi->cpi_family <= 0x11); 34127c478bd9Sstevel@tonic-gate case 58: 34137c478bd9Sstevel@tonic-gate return (B(eax)); 34147c478bd9Sstevel@tonic-gate case 60: 3415512cf780Skchow return (cpi->cpi_family <= 0x11); 34167c478bd9Sstevel@tonic-gate case 61: 34177c478bd9Sstevel@tonic-gate case 62: 34187c478bd9Sstevel@tonic-gate case 63: 34197c478bd9Sstevel@tonic-gate case 64: 34207c478bd9Sstevel@tonic-gate case 65: 34217c478bd9Sstevel@tonic-gate case 66: 34227c478bd9Sstevel@tonic-gate case 68: 34237c478bd9Sstevel@tonic-gate case 69: 34247c478bd9Sstevel@tonic-gate case 70: 34257c478bd9Sstevel@tonic-gate case 71: 34267c478bd9Sstevel@tonic-gate return (B(eax)); 34277c478bd9Sstevel@tonic-gate case 72: 34287c478bd9Sstevel@tonic-gate return (SH_B0(eax)); 34297c478bd9Sstevel@tonic-gate case 74: 34307c478bd9Sstevel@tonic-gate return (B(eax)); 34317c478bd9Sstevel@tonic-gate case 75: 3432875b116eSkchow return (cpi->cpi_family < 0x10); 34337c478bd9Sstevel@tonic-gate case 76: 34347c478bd9Sstevel@tonic-gate return (B(eax)); 34357c478bd9Sstevel@tonic-gate case 77: 3436512cf780Skchow return (cpi->cpi_family <= 0x11); 34377c478bd9Sstevel@tonic-gate case 78: 34387c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax)); 34397c478bd9Sstevel@tonic-gate case 79: 34407c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax) || EX(eax)); 34417c478bd9Sstevel@tonic-gate case 80: 34427c478bd9Sstevel@tonic-gate case 81: 34437c478bd9Sstevel@tonic-gate case 82: 34447c478bd9Sstevel@tonic-gate return (B(eax)); 34457c478bd9Sstevel@tonic-gate case 83: 34467c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax)); 34477c478bd9Sstevel@tonic-gate case 85: 3448875b116eSkchow return (cpi->cpi_family < 0x10); 34497c478bd9Sstevel@tonic-gate case 86: 34507c478bd9Sstevel@tonic-gate return (SH_C0(eax) || CG(eax)); 34517c478bd9Sstevel@tonic-gate case 88: 34527c478bd9Sstevel@tonic-gate #if !defined(__amd64) 34537c478bd9Sstevel@tonic-gate return (0); 34547c478bd9Sstevel@tonic-gate #else 34557c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax)); 34567c478bd9Sstevel@tonic-gate #endif 34577c478bd9Sstevel@tonic-gate case 89: 3458875b116eSkchow return (cpi->cpi_family < 0x10); 34597c478bd9Sstevel@tonic-gate case 90: 34607c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax)); 34617c478bd9Sstevel@tonic-gate case 91: 34627c478bd9Sstevel@tonic-gate case 92: 34637c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax)); 34647c478bd9Sstevel@tonic-gate case 93: 34657c478bd9Sstevel@tonic-gate return (SH_C0(eax)); 34667c478bd9Sstevel@tonic-gate case 94: 34677c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax)); 34687c478bd9Sstevel@tonic-gate case 95: 34697c478bd9Sstevel@tonic-gate #if !defined(__amd64) 34707c478bd9Sstevel@tonic-gate return (0); 34717c478bd9Sstevel@tonic-gate #else 34727c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax)); 34737c478bd9Sstevel@tonic-gate #endif 34747c478bd9Sstevel@tonic-gate case 96: 34757c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax)); 34767c478bd9Sstevel@tonic-gate case 97: 34777c478bd9Sstevel@tonic-gate case 98: 34787c478bd9Sstevel@tonic-gate return (SH_C0(eax) || CG(eax)); 34797c478bd9Sstevel@tonic-gate case 99: 34807c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax)); 34817c478bd9Sstevel@tonic-gate case 100: 34827c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax)); 34837c478bd9Sstevel@tonic-gate case 101: 34847c478bd9Sstevel@tonic-gate case 103: 34857c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax)); 34867c478bd9Sstevel@tonic-gate case 104: 34877c478bd9Sstevel@tonic-gate return (SH_C0(eax) || CG(eax) || D0(eax)); 34887c478bd9Sstevel@tonic-gate case 105: 34897c478bd9Sstevel@tonic-gate case 106: 34907c478bd9Sstevel@tonic-gate case 107: 34917c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax)); 34927c478bd9Sstevel@tonic-gate case 108: 34937c478bd9Sstevel@tonic-gate return (DH_CG(eax)); 34947c478bd9Sstevel@tonic-gate case 109: 34957c478bd9Sstevel@tonic-gate return (SH_C0(eax) || CG(eax) || D0(eax)); 34967c478bd9Sstevel@tonic-gate case 110: 34977c478bd9Sstevel@tonic-gate return (D0(eax) || EX(eax)); 34987c478bd9Sstevel@tonic-gate case 111: 34997c478bd9Sstevel@tonic-gate return (CG(eax)); 35007c478bd9Sstevel@tonic-gate case 112: 35017c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax) || EX(eax)); 35027c478bd9Sstevel@tonic-gate case 113: 35037c478bd9Sstevel@tonic-gate return (eax == 0x20fc0); 35047c478bd9Sstevel@tonic-gate case 114: 35057c478bd9Sstevel@tonic-gate return (SH_E0(eax) || JH_E1(eax) || DH_E3(eax)); 35067c478bd9Sstevel@tonic-gate case 115: 35077c478bd9Sstevel@tonic-gate return (SH_E0(eax) || JH_E1(eax)); 35087c478bd9Sstevel@tonic-gate case 116: 35097c478bd9Sstevel@tonic-gate return (SH_E0(eax) || JH_E1(eax) || DH_E3(eax)); 35107c478bd9Sstevel@tonic-gate case 117: 35117c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax)); 35127c478bd9Sstevel@tonic-gate case 118: 35137c478bd9Sstevel@tonic-gate return (SH_E0(eax) || JH_E1(eax) || SH_E4(eax) || BH_E4(eax) || 35147c478bd9Sstevel@tonic-gate JH_E6(eax)); 35157c478bd9Sstevel@tonic-gate case 121: 35167c478bd9Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax) || EX(eax)); 35177c478bd9Sstevel@tonic-gate case 122: 3518512cf780Skchow return (cpi->cpi_family < 0x10 || cpi->cpi_family == 0x11); 35197c478bd9Sstevel@tonic-gate case 123: 35207c478bd9Sstevel@tonic-gate return (JH_E1(eax) || BH_E4(eax) || JH_E6(eax)); 35212201b277Skucharsk case 131: 3522875b116eSkchow return (cpi->cpi_family < 0x10); 3523ef50d8c0Sesaxe case 6336786: 3524ef50d8c0Sesaxe /* 3525ef50d8c0Sesaxe * Test for AdvPowerMgmtInfo.TscPStateInvariant 3526875b116eSkchow * if this is a K8 family or newer processor 3527ef50d8c0Sesaxe */ 3528ef50d8c0Sesaxe if (CPI_FAMILY(cpi) == 0xf) { 35298949bcd6Sandrei struct cpuid_regs regs; 35308949bcd6Sandrei regs.cp_eax = 0x80000007; 35318949bcd6Sandrei (void) __cpuid_insn(®s); 35328949bcd6Sandrei return (!(regs.cp_edx & 0x100)); 3533ef50d8c0Sesaxe } 3534ef50d8c0Sesaxe return (0); 3535ee88d2b9Skchow case 6323525: 3536ee88d2b9Skchow return (((((eax >> 12) & 0xff00) + (eax & 0xf00)) | 3537ee88d2b9Skchow (((eax >> 4) & 0xf) | ((eax >> 12) & 0xf0))) < 0xf40); 3538ee88d2b9Skchow 3539512cf780Skchow case 6671130: 3540512cf780Skchow /* 3541512cf780Skchow * check for processors (pre-Shanghai) that do not provide 3542512cf780Skchow * optimal management of 1gb ptes in its tlb. 3543512cf780Skchow */ 3544512cf780Skchow return (cpi->cpi_family == 0x10 && cpi->cpi_model < 4); 3545512cf780Skchow 3546512cf780Skchow case 298: 3547512cf780Skchow return (DR_AX(eax) || DR_B0(eax) || DR_B1(eax) || DR_BA(eax) || 3548512cf780Skchow DR_B2(eax) || RB_C0(eax)); 3549512cf780Skchow 35505e54b56dSHans Rosenfeld case 721: 35515e54b56dSHans Rosenfeld #if defined(__amd64) 35525e54b56dSHans Rosenfeld return (cpi->cpi_family == 0x10 || cpi->cpi_family == 0x12); 35535e54b56dSHans Rosenfeld #else 35545e54b56dSHans Rosenfeld return (0); 35555e54b56dSHans Rosenfeld #endif 35565e54b56dSHans Rosenfeld 3557512cf780Skchow default: 3558512cf780Skchow return (-1); 3559512cf780Skchow 3560512cf780Skchow } 3561512cf780Skchow } 3562512cf780Skchow 3563512cf780Skchow /* 3564512cf780Skchow * Determine if specified erratum is present via OSVW (OS Visible Workaround). 3565512cf780Skchow * Return 1 if erratum is present, 0 if not present and -1 if indeterminate. 3566512cf780Skchow */ 3567512cf780Skchow int 3568512cf780Skchow osvw_opteron_erratum(cpu_t *cpu, uint_t erratum) 3569512cf780Skchow { 3570512cf780Skchow struct cpuid_info *cpi; 3571512cf780Skchow uint_t osvwid; 3572512cf780Skchow static int osvwfeature = -1; 3573512cf780Skchow uint64_t osvwlength; 3574512cf780Skchow 3575512cf780Skchow 3576512cf780Skchow cpi = cpu->cpu_m.mcpu_cpi; 3577512cf780Skchow 3578512cf780Skchow /* confirm OSVW supported */ 3579512cf780Skchow if (osvwfeature == -1) { 3580512cf780Skchow osvwfeature = cpi->cpi_extd[1].cp_ecx & CPUID_AMD_ECX_OSVW; 3581512cf780Skchow } else { 3582512cf780Skchow /* assert that osvw feature setting is consistent on all cpus */ 3583512cf780Skchow ASSERT(osvwfeature == 3584512cf780Skchow (cpi->cpi_extd[1].cp_ecx & CPUID_AMD_ECX_OSVW)); 3585512cf780Skchow } 3586512cf780Skchow if (!osvwfeature) 3587512cf780Skchow return (-1); 3588512cf780Skchow 3589512cf780Skchow osvwlength = rdmsr(MSR_AMD_OSVW_ID_LEN) & OSVW_ID_LEN_MASK; 3590512cf780Skchow 3591512cf780Skchow switch (erratum) { 3592512cf780Skchow case 298: /* osvwid is 0 */ 3593512cf780Skchow osvwid = 0; 3594512cf780Skchow if (osvwlength <= (uint64_t)osvwid) { 3595512cf780Skchow /* osvwid 0 is unknown */ 3596512cf780Skchow return (-1); 3597512cf780Skchow } 3598512cf780Skchow 3599512cf780Skchow /* 3600512cf780Skchow * Check the OSVW STATUS MSR to determine the state 3601512cf780Skchow * of the erratum where: 3602512cf780Skchow * 0 - fixed by HW 3603512cf780Skchow * 1 - BIOS has applied the workaround when BIOS 3604512cf780Skchow * workaround is available. (Or for other errata, 3605512cf780Skchow * OS workaround is required.) 3606512cf780Skchow * For a value of 1, caller will confirm that the 3607512cf780Skchow * erratum 298 workaround has indeed been applied by BIOS. 3608512cf780Skchow * 3609512cf780Skchow * A 1 may be set in cpus that have a HW fix 3610512cf780Skchow * in a mixed cpu system. Regarding erratum 298: 3611512cf780Skchow * In a multiprocessor platform, the workaround above 3612512cf780Skchow * should be applied to all processors regardless of 3613512cf780Skchow * silicon revision when an affected processor is 3614512cf780Skchow * present. 3615512cf780Skchow */ 3616512cf780Skchow 3617512cf780Skchow return (rdmsr(MSR_AMD_OSVW_STATUS + 3618512cf780Skchow (osvwid / OSVW_ID_CNT_PER_MSR)) & 3619512cf780Skchow (1ULL << (osvwid % OSVW_ID_CNT_PER_MSR))); 3620512cf780Skchow 36217c478bd9Sstevel@tonic-gate default: 36227c478bd9Sstevel@tonic-gate return (-1); 36237c478bd9Sstevel@tonic-gate } 36247c478bd9Sstevel@tonic-gate } 36257c478bd9Sstevel@tonic-gate 36267c478bd9Sstevel@tonic-gate static const char assoc_str[] = "associativity"; 36277c478bd9Sstevel@tonic-gate static const char line_str[] = "line-size"; 36287c478bd9Sstevel@tonic-gate static const char size_str[] = "size"; 36297c478bd9Sstevel@tonic-gate 36307c478bd9Sstevel@tonic-gate static void 36317c478bd9Sstevel@tonic-gate add_cache_prop(dev_info_t *devi, const char *label, const char *type, 36327c478bd9Sstevel@tonic-gate uint32_t val) 36337c478bd9Sstevel@tonic-gate { 36347c478bd9Sstevel@tonic-gate char buf[128]; 36357c478bd9Sstevel@tonic-gate 36367c478bd9Sstevel@tonic-gate /* 36377c478bd9Sstevel@tonic-gate * ndi_prop_update_int() is used because it is desirable for 36387c478bd9Sstevel@tonic-gate * DDI_PROP_HW_DEF and DDI_PROP_DONTSLEEP to be set. 36397c478bd9Sstevel@tonic-gate */ 36407c478bd9Sstevel@tonic-gate if (snprintf(buf, sizeof (buf), "%s-%s", label, type) < sizeof (buf)) 36417c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, devi, buf, val); 36427c478bd9Sstevel@tonic-gate } 36437c478bd9Sstevel@tonic-gate 36447c478bd9Sstevel@tonic-gate /* 36457c478bd9Sstevel@tonic-gate * Intel-style cache/tlb description 36467c478bd9Sstevel@tonic-gate * 36477c478bd9Sstevel@tonic-gate * Standard cpuid level 2 gives a randomly ordered 36487c478bd9Sstevel@tonic-gate * selection of tags that index into a table that describes 36497c478bd9Sstevel@tonic-gate * cache and tlb properties. 36507c478bd9Sstevel@tonic-gate */ 36517c478bd9Sstevel@tonic-gate 36527c478bd9Sstevel@tonic-gate static const char l1_icache_str[] = "l1-icache"; 36537c478bd9Sstevel@tonic-gate static const char l1_dcache_str[] = "l1-dcache"; 36547c478bd9Sstevel@tonic-gate static const char l2_cache_str[] = "l2-cache"; 3655ae115bc7Smrj static const char l3_cache_str[] = "l3-cache"; 36567c478bd9Sstevel@tonic-gate static const char itlb4k_str[] = "itlb-4K"; 36577c478bd9Sstevel@tonic-gate static const char dtlb4k_str[] = "dtlb-4K"; 3658824e4fecSvd224797 static const char itlb2M_str[] = "itlb-2M"; 36597c478bd9Sstevel@tonic-gate static const char itlb4M_str[] = "itlb-4M"; 36607c478bd9Sstevel@tonic-gate static const char dtlb4M_str[] = "dtlb-4M"; 366125dfb062Sksadhukh static const char dtlb24_str[] = "dtlb0-2M-4M"; 36627c478bd9Sstevel@tonic-gate static const char itlb424_str[] = "itlb-4K-2M-4M"; 366325dfb062Sksadhukh static const char itlb24_str[] = "itlb-2M-4M"; 36647c478bd9Sstevel@tonic-gate static const char dtlb44_str[] = "dtlb-4K-4M"; 36657c478bd9Sstevel@tonic-gate static const char sl1_dcache_str[] = "sectored-l1-dcache"; 36667c478bd9Sstevel@tonic-gate static const char sl2_cache_str[] = "sectored-l2-cache"; 36677c478bd9Sstevel@tonic-gate static const char itrace_str[] = "itrace-cache"; 36687c478bd9Sstevel@tonic-gate static const char sl3_cache_str[] = "sectored-l3-cache"; 366925dfb062Sksadhukh static const char sh_l2_tlb4k_str[] = "shared-l2-tlb-4k"; 36707c478bd9Sstevel@tonic-gate 36717c478bd9Sstevel@tonic-gate static const struct cachetab { 36727c478bd9Sstevel@tonic-gate uint8_t ct_code; 36737c478bd9Sstevel@tonic-gate uint8_t ct_assoc; 36747c478bd9Sstevel@tonic-gate uint16_t ct_line_size; 36757c478bd9Sstevel@tonic-gate size_t ct_size; 36767c478bd9Sstevel@tonic-gate const char *ct_label; 36777c478bd9Sstevel@tonic-gate } intel_ctab[] = { 3678824e4fecSvd224797 /* 3679824e4fecSvd224797 * maintain descending order! 3680824e4fecSvd224797 * 3681824e4fecSvd224797 * Codes ignored - Reason 3682824e4fecSvd224797 * ---------------------- 3683824e4fecSvd224797 * 40H - intel_cpuid_4_cache_info() disambiguates l2/l3 cache 3684824e4fecSvd224797 * f0H/f1H - Currently we do not interpret prefetch size by design 3685824e4fecSvd224797 */ 368625dfb062Sksadhukh { 0xe4, 16, 64, 8*1024*1024, l3_cache_str}, 368725dfb062Sksadhukh { 0xe3, 16, 64, 4*1024*1024, l3_cache_str}, 368825dfb062Sksadhukh { 0xe2, 16, 64, 2*1024*1024, l3_cache_str}, 368925dfb062Sksadhukh { 0xde, 12, 64, 6*1024*1024, l3_cache_str}, 369025dfb062Sksadhukh { 0xdd, 12, 64, 3*1024*1024, l3_cache_str}, 369125dfb062Sksadhukh { 0xdc, 12, 64, ((1*1024*1024)+(512*1024)), l3_cache_str}, 369225dfb062Sksadhukh { 0xd8, 8, 64, 4*1024*1024, l3_cache_str}, 369325dfb062Sksadhukh { 0xd7, 8, 64, 2*1024*1024, l3_cache_str}, 369425dfb062Sksadhukh { 0xd6, 8, 64, 1*1024*1024, l3_cache_str}, 369525dfb062Sksadhukh { 0xd2, 4, 64, 2*1024*1024, l3_cache_str}, 369625dfb062Sksadhukh { 0xd1, 4, 64, 1*1024*1024, l3_cache_str}, 369725dfb062Sksadhukh { 0xd0, 4, 64, 512*1024, l3_cache_str}, 369825dfb062Sksadhukh { 0xca, 4, 0, 512, sh_l2_tlb4k_str}, 3699824e4fecSvd224797 { 0xc0, 4, 0, 8, dtlb44_str }, 3700824e4fecSvd224797 { 0xba, 4, 0, 64, dtlb4k_str }, 3701ae115bc7Smrj { 0xb4, 4, 0, 256, dtlb4k_str }, 37027c478bd9Sstevel@tonic-gate { 0xb3, 4, 0, 128, dtlb4k_str }, 370325dfb062Sksadhukh { 0xb2, 4, 0, 64, itlb4k_str }, 37047c478bd9Sstevel@tonic-gate { 0xb0, 4, 0, 128, itlb4k_str }, 37057c478bd9Sstevel@tonic-gate { 0x87, 8, 64, 1024*1024, l2_cache_str}, 37067c478bd9Sstevel@tonic-gate { 0x86, 4, 64, 512*1024, l2_cache_str}, 37077c478bd9Sstevel@tonic-gate { 0x85, 8, 32, 2*1024*1024, l2_cache_str}, 37087c478bd9Sstevel@tonic-gate { 0x84, 8, 32, 1024*1024, l2_cache_str}, 37097c478bd9Sstevel@tonic-gate { 0x83, 8, 32, 512*1024, l2_cache_str}, 37107c478bd9Sstevel@tonic-gate { 0x82, 8, 32, 256*1024, l2_cache_str}, 3711824e4fecSvd224797 { 0x80, 8, 64, 512*1024, l2_cache_str}, 37127c478bd9Sstevel@tonic-gate { 0x7f, 2, 64, 512*1024, l2_cache_str}, 37137c478bd9Sstevel@tonic-gate { 0x7d, 8, 64, 2*1024*1024, sl2_cache_str}, 37147c478bd9Sstevel@tonic-gate { 0x7c, 8, 64, 1024*1024, sl2_cache_str}, 37157c478bd9Sstevel@tonic-gate { 0x7b, 8, 64, 512*1024, sl2_cache_str}, 37167c478bd9Sstevel@tonic-gate { 0x7a, 8, 64, 256*1024, sl2_cache_str}, 37177c478bd9Sstevel@tonic-gate { 0x79, 8, 64, 128*1024, sl2_cache_str}, 37187c478bd9Sstevel@tonic-gate { 0x78, 8, 64, 1024*1024, l2_cache_str}, 3719ae115bc7Smrj { 0x73, 8, 0, 64*1024, itrace_str}, 37207c478bd9Sstevel@tonic-gate { 0x72, 8, 0, 32*1024, itrace_str}, 37217c478bd9Sstevel@tonic-gate { 0x71, 8, 0, 16*1024, itrace_str}, 37227c478bd9Sstevel@tonic-gate { 0x70, 8, 0, 12*1024, itrace_str}, 37237c478bd9Sstevel@tonic-gate { 0x68, 4, 64, 32*1024, sl1_dcache_str}, 37247c478bd9Sstevel@tonic-gate { 0x67, 4, 64, 16*1024, sl1_dcache_str}, 37257c478bd9Sstevel@tonic-gate { 0x66, 4, 64, 8*1024, sl1_dcache_str}, 37267c478bd9Sstevel@tonic-gate { 0x60, 8, 64, 16*1024, sl1_dcache_str}, 37277c478bd9Sstevel@tonic-gate { 0x5d, 0, 0, 256, dtlb44_str}, 37287c478bd9Sstevel@tonic-gate { 0x5c, 0, 0, 128, dtlb44_str}, 37297c478bd9Sstevel@tonic-gate { 0x5b, 0, 0, 64, dtlb44_str}, 373025dfb062Sksadhukh { 0x5a, 4, 0, 32, dtlb24_str}, 3731824e4fecSvd224797 { 0x59, 0, 0, 16, dtlb4k_str}, 3732824e4fecSvd224797 { 0x57, 4, 0, 16, dtlb4k_str}, 3733824e4fecSvd224797 { 0x56, 4, 0, 16, dtlb4M_str}, 373425dfb062Sksadhukh { 0x55, 0, 0, 7, itlb24_str}, 37357c478bd9Sstevel@tonic-gate { 0x52, 0, 0, 256, itlb424_str}, 37367c478bd9Sstevel@tonic-gate { 0x51, 0, 0, 128, itlb424_str}, 37377c478bd9Sstevel@tonic-gate { 0x50, 0, 0, 64, itlb424_str}, 3738824e4fecSvd224797 { 0x4f, 0, 0, 32, itlb4k_str}, 3739824e4fecSvd224797 { 0x4e, 24, 64, 6*1024*1024, l2_cache_str}, 3740ae115bc7Smrj { 0x4d, 16, 64, 16*1024*1024, l3_cache_str}, 3741ae115bc7Smrj { 0x4c, 12, 64, 12*1024*1024, l3_cache_str}, 3742ae115bc7Smrj { 0x4b, 16, 64, 8*1024*1024, l3_cache_str}, 3743ae115bc7Smrj { 0x4a, 12, 64, 6*1024*1024, l3_cache_str}, 3744ae115bc7Smrj { 0x49, 16, 64, 4*1024*1024, l3_cache_str}, 3745824e4fecSvd224797 { 0x48, 12, 64, 3*1024*1024, l2_cache_str}, 3746ae115bc7Smrj { 0x47, 8, 64, 8*1024*1024, l3_cache_str}, 3747ae115bc7Smrj { 0x46, 4, 64, 4*1024*1024, l3_cache_str}, 37487c478bd9Sstevel@tonic-gate { 0x45, 4, 32, 2*1024*1024, l2_cache_str}, 37497c478bd9Sstevel@tonic-gate { 0x44, 4, 32, 1024*1024, l2_cache_str}, 37507c478bd9Sstevel@tonic-gate { 0x43, 4, 32, 512*1024, l2_cache_str}, 37517c478bd9Sstevel@tonic-gate { 0x42, 4, 32, 256*1024, l2_cache_str}, 37527c478bd9Sstevel@tonic-gate { 0x41, 4, 32, 128*1024, l2_cache_str}, 3753ae115bc7Smrj { 0x3e, 4, 64, 512*1024, sl2_cache_str}, 3754ae115bc7Smrj { 0x3d, 6, 64, 384*1024, sl2_cache_str}, 37557c478bd9Sstevel@tonic-gate { 0x3c, 4, 64, 256*1024, sl2_cache_str}, 37567c478bd9Sstevel@tonic-gate { 0x3b, 2, 64, 128*1024, sl2_cache_str}, 3757ae115bc7Smrj { 0x3a, 6, 64, 192*1024, sl2_cache_str}, 37587c478bd9Sstevel@tonic-gate { 0x39, 4, 64, 128*1024, sl2_cache_str}, 37597c478bd9Sstevel@tonic-gate { 0x30, 8, 64, 32*1024, l1_icache_str}, 37607c478bd9Sstevel@tonic-gate { 0x2c, 8, 64, 32*1024, l1_dcache_str}, 37617c478bd9Sstevel@tonic-gate { 0x29, 8, 64, 4096*1024, sl3_cache_str}, 37627c478bd9Sstevel@tonic-gate { 0x25, 8, 64, 2048*1024, sl3_cache_str}, 37637c478bd9Sstevel@tonic-gate { 0x23, 8, 64, 1024*1024, sl3_cache_str}, 37647c478bd9Sstevel@tonic-gate { 0x22, 4, 64, 512*1024, sl3_cache_str}, 3765824e4fecSvd224797 { 0x0e, 6, 64, 24*1024, l1_dcache_str}, 376625dfb062Sksadhukh { 0x0d, 4, 32, 16*1024, l1_dcache_str}, 37677c478bd9Sstevel@tonic-gate { 0x0c, 4, 32, 16*1024, l1_dcache_str}, 3768ae115bc7Smrj { 0x0b, 4, 0, 4, itlb4M_str}, 37697c478bd9Sstevel@tonic-gate { 0x0a, 2, 32, 8*1024, l1_dcache_str}, 37707c478bd9Sstevel@tonic-gate { 0x08, 4, 32, 16*1024, l1_icache_str}, 37717c478bd9Sstevel@tonic-gate { 0x06, 4, 32, 8*1024, l1_icache_str}, 3772824e4fecSvd224797 { 0x05, 4, 0, 32, dtlb4M_str}, 37737c478bd9Sstevel@tonic-gate { 0x04, 4, 0, 8, dtlb4M_str}, 37747c478bd9Sstevel@tonic-gate { 0x03, 4, 0, 64, dtlb4k_str}, 37757c478bd9Sstevel@tonic-gate { 0x02, 4, 0, 2, itlb4M_str}, 37767c478bd9Sstevel@tonic-gate { 0x01, 4, 0, 32, itlb4k_str}, 37777c478bd9Sstevel@tonic-gate { 0 } 37787c478bd9Sstevel@tonic-gate }; 37797c478bd9Sstevel@tonic-gate 37807c478bd9Sstevel@tonic-gate static const struct cachetab cyrix_ctab[] = { 37817c478bd9Sstevel@tonic-gate { 0x70, 4, 0, 32, "tlb-4K" }, 37827c478bd9Sstevel@tonic-gate { 0x80, 4, 16, 16*1024, "l1-cache" }, 37837c478bd9Sstevel@tonic-gate { 0 } 37847c478bd9Sstevel@tonic-gate }; 37857c478bd9Sstevel@tonic-gate 37867c478bd9Sstevel@tonic-gate /* 37877c478bd9Sstevel@tonic-gate * Search a cache table for a matching entry 37887c478bd9Sstevel@tonic-gate */ 37897c478bd9Sstevel@tonic-gate static const struct cachetab * 37907c478bd9Sstevel@tonic-gate find_cacheent(const struct cachetab *ct, uint_t code) 37917c478bd9Sstevel@tonic-gate { 37927c478bd9Sstevel@tonic-gate if (code != 0) { 37937c478bd9Sstevel@tonic-gate for (; ct->ct_code != 0; ct++) 37947c478bd9Sstevel@tonic-gate if (ct->ct_code <= code) 37957c478bd9Sstevel@tonic-gate break; 37967c478bd9Sstevel@tonic-gate if (ct->ct_code == code) 37977c478bd9Sstevel@tonic-gate return (ct); 37987c478bd9Sstevel@tonic-gate } 37997c478bd9Sstevel@tonic-gate return (NULL); 38007c478bd9Sstevel@tonic-gate } 38017c478bd9Sstevel@tonic-gate 38027c478bd9Sstevel@tonic-gate /* 38037dee861bSksadhukh * Populate cachetab entry with L2 or L3 cache-information using 38047dee861bSksadhukh * cpuid function 4. This function is called from intel_walk_cacheinfo() 38057dee861bSksadhukh * when descriptor 0x49 is encountered. It returns 0 if no such cache 38067dee861bSksadhukh * information is found. 38077dee861bSksadhukh */ 38087dee861bSksadhukh static int 38097dee861bSksadhukh intel_cpuid_4_cache_info(struct cachetab *ct, struct cpuid_info *cpi) 38107dee861bSksadhukh { 38117dee861bSksadhukh uint32_t level, i; 38127dee861bSksadhukh int ret = 0; 38137dee861bSksadhukh 38147dee861bSksadhukh for (i = 0; i < cpi->cpi_std_4_size; i++) { 38157dee861bSksadhukh level = CPI_CACHE_LVL(cpi->cpi_std_4[i]); 38167dee861bSksadhukh 38177dee861bSksadhukh if (level == 2 || level == 3) { 38187dee861bSksadhukh ct->ct_assoc = CPI_CACHE_WAYS(cpi->cpi_std_4[i]) + 1; 38197dee861bSksadhukh ct->ct_line_size = 38207dee861bSksadhukh CPI_CACHE_COH_LN_SZ(cpi->cpi_std_4[i]) + 1; 38217dee861bSksadhukh ct->ct_size = ct->ct_assoc * 38227dee861bSksadhukh (CPI_CACHE_PARTS(cpi->cpi_std_4[i]) + 1) * 38237dee861bSksadhukh ct->ct_line_size * 38247dee861bSksadhukh (cpi->cpi_std_4[i]->cp_ecx + 1); 38257dee861bSksadhukh 38267dee861bSksadhukh if (level == 2) { 38277dee861bSksadhukh ct->ct_label = l2_cache_str; 38287dee861bSksadhukh } else if (level == 3) { 38297dee861bSksadhukh ct->ct_label = l3_cache_str; 38307dee861bSksadhukh } 38317dee861bSksadhukh ret = 1; 38327dee861bSksadhukh } 38337dee861bSksadhukh } 38347dee861bSksadhukh 38357dee861bSksadhukh return (ret); 38367dee861bSksadhukh } 38377dee861bSksadhukh 38387dee861bSksadhukh /* 38397c478bd9Sstevel@tonic-gate * Walk the cacheinfo descriptor, applying 'func' to every valid element 38407c478bd9Sstevel@tonic-gate * The walk is terminated if the walker returns non-zero. 38417c478bd9Sstevel@tonic-gate */ 38427c478bd9Sstevel@tonic-gate static void 38437c478bd9Sstevel@tonic-gate intel_walk_cacheinfo(struct cpuid_info *cpi, 38447c478bd9Sstevel@tonic-gate void *arg, int (*func)(void *, const struct cachetab *)) 38457c478bd9Sstevel@tonic-gate { 38467c478bd9Sstevel@tonic-gate const struct cachetab *ct; 3847824e4fecSvd224797 struct cachetab des_49_ct, des_b1_ct; 38487c478bd9Sstevel@tonic-gate uint8_t *dp; 38497c478bd9Sstevel@tonic-gate int i; 38507c478bd9Sstevel@tonic-gate 38517c478bd9Sstevel@tonic-gate if ((dp = cpi->cpi_cacheinfo) == NULL) 38527c478bd9Sstevel@tonic-gate return; 3853f1d742a9Sksadhukh for (i = 0; i < cpi->cpi_ncache; i++, dp++) { 3854f1d742a9Sksadhukh /* 3855f1d742a9Sksadhukh * For overloaded descriptor 0x49 we use cpuid function 4 38567dee861bSksadhukh * if supported by the current processor, to create 3857f1d742a9Sksadhukh * cache information. 3858824e4fecSvd224797 * For overloaded descriptor 0xb1 we use X86_PAE flag 3859824e4fecSvd224797 * to disambiguate the cache information. 3860f1d742a9Sksadhukh */ 38617dee861bSksadhukh if (*dp == 0x49 && cpi->cpi_maxeax >= 0x4 && 38627dee861bSksadhukh intel_cpuid_4_cache_info(&des_49_ct, cpi) == 1) { 38637dee861bSksadhukh ct = &des_49_ct; 3864824e4fecSvd224797 } else if (*dp == 0xb1) { 3865824e4fecSvd224797 des_b1_ct.ct_code = 0xb1; 3866824e4fecSvd224797 des_b1_ct.ct_assoc = 4; 3867824e4fecSvd224797 des_b1_ct.ct_line_size = 0; 38687417cfdeSKuriakose Kuruvilla if (is_x86_feature(x86_featureset, X86FSET_PAE)) { 3869824e4fecSvd224797 des_b1_ct.ct_size = 8; 3870824e4fecSvd224797 des_b1_ct.ct_label = itlb2M_str; 3871824e4fecSvd224797 } else { 3872824e4fecSvd224797 des_b1_ct.ct_size = 4; 3873824e4fecSvd224797 des_b1_ct.ct_label = itlb4M_str; 3874824e4fecSvd224797 } 3875824e4fecSvd224797 ct = &des_b1_ct; 38767dee861bSksadhukh } else { 38777dee861bSksadhukh if ((ct = find_cacheent(intel_ctab, *dp)) == NULL) { 3878f1d742a9Sksadhukh continue; 3879f1d742a9Sksadhukh } 38807dee861bSksadhukh } 3881f1d742a9Sksadhukh 38827dee861bSksadhukh if (func(arg, ct) != 0) { 38837c478bd9Sstevel@tonic-gate break; 38847c478bd9Sstevel@tonic-gate } 38857c478bd9Sstevel@tonic-gate } 3886f1d742a9Sksadhukh } 38877c478bd9Sstevel@tonic-gate 38887c478bd9Sstevel@tonic-gate /* 38897c478bd9Sstevel@tonic-gate * (Like the Intel one, except for Cyrix CPUs) 38907c478bd9Sstevel@tonic-gate */ 38917c478bd9Sstevel@tonic-gate static void 38927c478bd9Sstevel@tonic-gate cyrix_walk_cacheinfo(struct cpuid_info *cpi, 38937c478bd9Sstevel@tonic-gate void *arg, int (*func)(void *, const struct cachetab *)) 38947c478bd9Sstevel@tonic-gate { 38957c478bd9Sstevel@tonic-gate const struct cachetab *ct; 38967c478bd9Sstevel@tonic-gate uint8_t *dp; 38977c478bd9Sstevel@tonic-gate int i; 38987c478bd9Sstevel@tonic-gate 38997c478bd9Sstevel@tonic-gate if ((dp = cpi->cpi_cacheinfo) == NULL) 39007c478bd9Sstevel@tonic-gate return; 39017c478bd9Sstevel@tonic-gate for (i = 0; i < cpi->cpi_ncache; i++, dp++) { 39027c478bd9Sstevel@tonic-gate /* 39037c478bd9Sstevel@tonic-gate * Search Cyrix-specific descriptor table first .. 39047c478bd9Sstevel@tonic-gate */ 39057c478bd9Sstevel@tonic-gate if ((ct = find_cacheent(cyrix_ctab, *dp)) != NULL) { 39067c478bd9Sstevel@tonic-gate if (func(arg, ct) != 0) 39077c478bd9Sstevel@tonic-gate break; 39087c478bd9Sstevel@tonic-gate continue; 39097c478bd9Sstevel@tonic-gate } 39107c478bd9Sstevel@tonic-gate /* 39117c478bd9Sstevel@tonic-gate * .. else fall back to the Intel one 39127c478bd9Sstevel@tonic-gate */ 39137c478bd9Sstevel@tonic-gate if ((ct = find_cacheent(intel_ctab, *dp)) != NULL) { 39147c478bd9Sstevel@tonic-gate if (func(arg, ct) != 0) 39157c478bd9Sstevel@tonic-gate break; 39167c478bd9Sstevel@tonic-gate continue; 39177c478bd9Sstevel@tonic-gate } 39187c478bd9Sstevel@tonic-gate } 39197c478bd9Sstevel@tonic-gate } 39207c478bd9Sstevel@tonic-gate 39217c478bd9Sstevel@tonic-gate /* 39227c478bd9Sstevel@tonic-gate * A cacheinfo walker that adds associativity, line-size, and size properties 39237c478bd9Sstevel@tonic-gate * to the devinfo node it is passed as an argument. 39247c478bd9Sstevel@tonic-gate */ 39257c478bd9Sstevel@tonic-gate static int 39267c478bd9Sstevel@tonic-gate add_cacheent_props(void *arg, const struct cachetab *ct) 39277c478bd9Sstevel@tonic-gate { 39287c478bd9Sstevel@tonic-gate dev_info_t *devi = arg; 39297c478bd9Sstevel@tonic-gate 39307c478bd9Sstevel@tonic-gate add_cache_prop(devi, ct->ct_label, assoc_str, ct->ct_assoc); 39317c478bd9Sstevel@tonic-gate if (ct->ct_line_size != 0) 39327c478bd9Sstevel@tonic-gate add_cache_prop(devi, ct->ct_label, line_str, 39337c478bd9Sstevel@tonic-gate ct->ct_line_size); 39347c478bd9Sstevel@tonic-gate add_cache_prop(devi, ct->ct_label, size_str, ct->ct_size); 39357c478bd9Sstevel@tonic-gate return (0); 39367c478bd9Sstevel@tonic-gate } 39377c478bd9Sstevel@tonic-gate 3938f1d742a9Sksadhukh 39397c478bd9Sstevel@tonic-gate static const char fully_assoc[] = "fully-associative?"; 39407c478bd9Sstevel@tonic-gate 39417c478bd9Sstevel@tonic-gate /* 39427c478bd9Sstevel@tonic-gate * AMD style cache/tlb description 39437c478bd9Sstevel@tonic-gate * 39447c478bd9Sstevel@tonic-gate * Extended functions 5 and 6 directly describe properties of 39457c478bd9Sstevel@tonic-gate * tlbs and various cache levels. 39467c478bd9Sstevel@tonic-gate */ 39477c478bd9Sstevel@tonic-gate static void 39487c478bd9Sstevel@tonic-gate add_amd_assoc(dev_info_t *devi, const char *label, uint_t assoc) 39497c478bd9Sstevel@tonic-gate { 39507c478bd9Sstevel@tonic-gate switch (assoc) { 39517c478bd9Sstevel@tonic-gate case 0: /* reserved; ignore */ 39527c478bd9Sstevel@tonic-gate break; 39537c478bd9Sstevel@tonic-gate default: 39547c478bd9Sstevel@tonic-gate add_cache_prop(devi, label, assoc_str, assoc); 39557c478bd9Sstevel@tonic-gate break; 39567c478bd9Sstevel@tonic-gate case 0xff: 39577c478bd9Sstevel@tonic-gate add_cache_prop(devi, label, fully_assoc, 1); 39587c478bd9Sstevel@tonic-gate break; 39597c478bd9Sstevel@tonic-gate } 39607c478bd9Sstevel@tonic-gate } 39617c478bd9Sstevel@tonic-gate 39627c478bd9Sstevel@tonic-gate static void 39637c478bd9Sstevel@tonic-gate add_amd_tlb(dev_info_t *devi, const char *label, uint_t assoc, uint_t size) 39647c478bd9Sstevel@tonic-gate { 39657c478bd9Sstevel@tonic-gate if (size == 0) 39667c478bd9Sstevel@tonic-gate return; 39677c478bd9Sstevel@tonic-gate add_cache_prop(devi, label, size_str, size); 39687c478bd9Sstevel@tonic-gate add_amd_assoc(devi, label, assoc); 39697c478bd9Sstevel@tonic-gate } 39707c478bd9Sstevel@tonic-gate 39717c478bd9Sstevel@tonic-gate static void 39727c478bd9Sstevel@tonic-gate add_amd_cache(dev_info_t *devi, const char *label, 39737c478bd9Sstevel@tonic-gate uint_t size, uint_t assoc, uint_t lines_per_tag, uint_t line_size) 39747c478bd9Sstevel@tonic-gate { 39757c478bd9Sstevel@tonic-gate if (size == 0 || line_size == 0) 39767c478bd9Sstevel@tonic-gate return; 39777c478bd9Sstevel@tonic-gate add_amd_assoc(devi, label, assoc); 39787c478bd9Sstevel@tonic-gate /* 39797c478bd9Sstevel@tonic-gate * Most AMD parts have a sectored cache. Multiple cache lines are 39807c478bd9Sstevel@tonic-gate * associated with each tag. A sector consists of all cache lines 39817c478bd9Sstevel@tonic-gate * associated with a tag. For example, the AMD K6-III has a sector 39827c478bd9Sstevel@tonic-gate * size of 2 cache lines per tag. 39837c478bd9Sstevel@tonic-gate */ 39847c478bd9Sstevel@tonic-gate if (lines_per_tag != 0) 39857c478bd9Sstevel@tonic-gate add_cache_prop(devi, label, "lines-per-tag", lines_per_tag); 39867c478bd9Sstevel@tonic-gate add_cache_prop(devi, label, line_str, line_size); 39877c478bd9Sstevel@tonic-gate add_cache_prop(devi, label, size_str, size * 1024); 39887c478bd9Sstevel@tonic-gate } 39897c478bd9Sstevel@tonic-gate 39907c478bd9Sstevel@tonic-gate static void 39917c478bd9Sstevel@tonic-gate add_amd_l2_assoc(dev_info_t *devi, const char *label, uint_t assoc) 39927c478bd9Sstevel@tonic-gate { 39937c478bd9Sstevel@tonic-gate switch (assoc) { 39947c478bd9Sstevel@tonic-gate case 0: /* off */ 39957c478bd9Sstevel@tonic-gate break; 39967c478bd9Sstevel@tonic-gate case 1: 39977c478bd9Sstevel@tonic-gate case 2: 39987c478bd9Sstevel@tonic-gate case 4: 39997c478bd9Sstevel@tonic-gate add_cache_prop(devi, label, assoc_str, assoc); 40007c478bd9Sstevel@tonic-gate break; 40017c478bd9Sstevel@tonic-gate case 6: 40027c478bd9Sstevel@tonic-gate add_cache_prop(devi, label, assoc_str, 8); 40037c478bd9Sstevel@tonic-gate break; 40047c478bd9Sstevel@tonic-gate case 8: 40057c478bd9Sstevel@tonic-gate add_cache_prop(devi, label, assoc_str, 16); 40067c478bd9Sstevel@tonic-gate break; 40077c478bd9Sstevel@tonic-gate case 0xf: 40087c478bd9Sstevel@tonic-gate add_cache_prop(devi, label, fully_assoc, 1); 40097c478bd9Sstevel@tonic-gate break; 40107c478bd9Sstevel@tonic-gate default: /* reserved; ignore */ 40117c478bd9Sstevel@tonic-gate break; 40127c478bd9Sstevel@tonic-gate } 40137c478bd9Sstevel@tonic-gate } 40147c478bd9Sstevel@tonic-gate 40157c478bd9Sstevel@tonic-gate static void 40167c478bd9Sstevel@tonic-gate add_amd_l2_tlb(dev_info_t *devi, const char *label, uint_t assoc, uint_t size) 40177c478bd9Sstevel@tonic-gate { 40187c478bd9Sstevel@tonic-gate if (size == 0 || assoc == 0) 40197c478bd9Sstevel@tonic-gate return; 40207c478bd9Sstevel@tonic-gate add_amd_l2_assoc(devi, label, assoc); 40217c478bd9Sstevel@tonic-gate add_cache_prop(devi, label, size_str, size); 40227c478bd9Sstevel@tonic-gate } 40237c478bd9Sstevel@tonic-gate 40247c478bd9Sstevel@tonic-gate static void 40257c478bd9Sstevel@tonic-gate add_amd_l2_cache(dev_info_t *devi, const char *label, 40267c478bd9Sstevel@tonic-gate uint_t size, uint_t assoc, uint_t lines_per_tag, uint_t line_size) 40277c478bd9Sstevel@tonic-gate { 40287c478bd9Sstevel@tonic-gate if (size == 0 || assoc == 0 || line_size == 0) 40297c478bd9Sstevel@tonic-gate return; 40307c478bd9Sstevel@tonic-gate add_amd_l2_assoc(devi, label, assoc); 40317c478bd9Sstevel@tonic-gate if (lines_per_tag != 0) 40327c478bd9Sstevel@tonic-gate add_cache_prop(devi, label, "lines-per-tag", lines_per_tag); 40337c478bd9Sstevel@tonic-gate add_cache_prop(devi, label, line_str, line_size); 40347c478bd9Sstevel@tonic-gate add_cache_prop(devi, label, size_str, size * 1024); 40357c478bd9Sstevel@tonic-gate } 40367c478bd9Sstevel@tonic-gate 40377c478bd9Sstevel@tonic-gate static void 40387c478bd9Sstevel@tonic-gate amd_cache_info(struct cpuid_info *cpi, dev_info_t *devi) 40397c478bd9Sstevel@tonic-gate { 40408949bcd6Sandrei struct cpuid_regs *cp; 40417c478bd9Sstevel@tonic-gate 40427c478bd9Sstevel@tonic-gate if (cpi->cpi_xmaxeax < 0x80000005) 40437c478bd9Sstevel@tonic-gate return; 40447c478bd9Sstevel@tonic-gate cp = &cpi->cpi_extd[5]; 40457c478bd9Sstevel@tonic-gate 40467c478bd9Sstevel@tonic-gate /* 40477c478bd9Sstevel@tonic-gate * 4M/2M L1 TLB configuration 40487c478bd9Sstevel@tonic-gate * 40497c478bd9Sstevel@tonic-gate * We report the size for 2M pages because AMD uses two 40507c478bd9Sstevel@tonic-gate * TLB entries for one 4M page. 40517c478bd9Sstevel@tonic-gate */ 40527c478bd9Sstevel@tonic-gate add_amd_tlb(devi, "dtlb-2M", 40537c478bd9Sstevel@tonic-gate BITX(cp->cp_eax, 31, 24), BITX(cp->cp_eax, 23, 16)); 40547c478bd9Sstevel@tonic-gate add_amd_tlb(devi, "itlb-2M", 40557c478bd9Sstevel@tonic-gate BITX(cp->cp_eax, 15, 8), BITX(cp->cp_eax, 7, 0)); 40567c478bd9Sstevel@tonic-gate 40577c478bd9Sstevel@tonic-gate /* 40587c478bd9Sstevel@tonic-gate * 4K L1 TLB configuration 40597c478bd9Sstevel@tonic-gate */ 40607c478bd9Sstevel@tonic-gate 40617c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 40627c478bd9Sstevel@tonic-gate uint_t nentries; 40637c478bd9Sstevel@tonic-gate case X86_VENDOR_TM: 40647c478bd9Sstevel@tonic-gate if (cpi->cpi_family >= 5) { 40657c478bd9Sstevel@tonic-gate /* 40667c478bd9Sstevel@tonic-gate * Crusoe processors have 256 TLB entries, but 40677c478bd9Sstevel@tonic-gate * cpuid data format constrains them to only 40687c478bd9Sstevel@tonic-gate * reporting 255 of them. 40697c478bd9Sstevel@tonic-gate */ 40707c478bd9Sstevel@tonic-gate if ((nentries = BITX(cp->cp_ebx, 23, 16)) == 255) 40717c478bd9Sstevel@tonic-gate nentries = 256; 40727c478bd9Sstevel@tonic-gate /* 40737c478bd9Sstevel@tonic-gate * Crusoe processors also have a unified TLB 40747c478bd9Sstevel@tonic-gate */ 40757c478bd9Sstevel@tonic-gate add_amd_tlb(devi, "tlb-4K", BITX(cp->cp_ebx, 31, 24), 40767c478bd9Sstevel@tonic-gate nentries); 40777c478bd9Sstevel@tonic-gate break; 40787c478bd9Sstevel@tonic-gate } 40797c478bd9Sstevel@tonic-gate /*FALLTHROUGH*/ 40807c478bd9Sstevel@tonic-gate default: 40817c478bd9Sstevel@tonic-gate add_amd_tlb(devi, itlb4k_str, 40827c478bd9Sstevel@tonic-gate BITX(cp->cp_ebx, 31, 24), BITX(cp->cp_ebx, 23, 16)); 40837c478bd9Sstevel@tonic-gate add_amd_tlb(devi, dtlb4k_str, 40847c478bd9Sstevel@tonic-gate BITX(cp->cp_ebx, 15, 8), BITX(cp->cp_ebx, 7, 0)); 40857c478bd9Sstevel@tonic-gate break; 40867c478bd9Sstevel@tonic-gate } 40877c478bd9Sstevel@tonic-gate 40887c478bd9Sstevel@tonic-gate /* 40897c478bd9Sstevel@tonic-gate * data L1 cache configuration 40907c478bd9Sstevel@tonic-gate */ 40917c478bd9Sstevel@tonic-gate 40927c478bd9Sstevel@tonic-gate add_amd_cache(devi, l1_dcache_str, 40937c478bd9Sstevel@tonic-gate BITX(cp->cp_ecx, 31, 24), BITX(cp->cp_ecx, 23, 16), 40947c478bd9Sstevel@tonic-gate BITX(cp->cp_ecx, 15, 8), BITX(cp->cp_ecx, 7, 0)); 40957c478bd9Sstevel@tonic-gate 40967c478bd9Sstevel@tonic-gate /* 40977c478bd9Sstevel@tonic-gate * code L1 cache configuration 40987c478bd9Sstevel@tonic-gate */ 40997c478bd9Sstevel@tonic-gate 41007c478bd9Sstevel@tonic-gate add_amd_cache(devi, l1_icache_str, 41017c478bd9Sstevel@tonic-gate BITX(cp->cp_edx, 31, 24), BITX(cp->cp_edx, 23, 16), 41027c478bd9Sstevel@tonic-gate BITX(cp->cp_edx, 15, 8), BITX(cp->cp_edx, 7, 0)); 41037c478bd9Sstevel@tonic-gate 41047c478bd9Sstevel@tonic-gate if (cpi->cpi_xmaxeax < 0x80000006) 41057c478bd9Sstevel@tonic-gate return; 41067c478bd9Sstevel@tonic-gate cp = &cpi->cpi_extd[6]; 41077c478bd9Sstevel@tonic-gate 41087c478bd9Sstevel@tonic-gate /* Check for a unified L2 TLB for large pages */ 41097c478bd9Sstevel@tonic-gate 41107c478bd9Sstevel@tonic-gate if (BITX(cp->cp_eax, 31, 16) == 0) 41117c478bd9Sstevel@tonic-gate add_amd_l2_tlb(devi, "l2-tlb-2M", 41127c478bd9Sstevel@tonic-gate BITX(cp->cp_eax, 15, 12), BITX(cp->cp_eax, 11, 0)); 41137c478bd9Sstevel@tonic-gate else { 41147c478bd9Sstevel@tonic-gate add_amd_l2_tlb(devi, "l2-dtlb-2M", 41157c478bd9Sstevel@tonic-gate BITX(cp->cp_eax, 31, 28), BITX(cp->cp_eax, 27, 16)); 41167c478bd9Sstevel@tonic-gate add_amd_l2_tlb(devi, "l2-itlb-2M", 41177c478bd9Sstevel@tonic-gate BITX(cp->cp_eax, 15, 12), BITX(cp->cp_eax, 11, 0)); 41187c478bd9Sstevel@tonic-gate } 41197c478bd9Sstevel@tonic-gate 41207c478bd9Sstevel@tonic-gate /* Check for a unified L2 TLB for 4K pages */ 41217c478bd9Sstevel@tonic-gate 41227c478bd9Sstevel@tonic-gate if (BITX(cp->cp_ebx, 31, 16) == 0) { 41237c478bd9Sstevel@tonic-gate add_amd_l2_tlb(devi, "l2-tlb-4K", 41247c478bd9Sstevel@tonic-gate BITX(cp->cp_eax, 15, 12), BITX(cp->cp_eax, 11, 0)); 41257c478bd9Sstevel@tonic-gate } else { 41267c478bd9Sstevel@tonic-gate add_amd_l2_tlb(devi, "l2-dtlb-4K", 41277c478bd9Sstevel@tonic-gate BITX(cp->cp_eax, 31, 28), BITX(cp->cp_eax, 27, 16)); 41287c478bd9Sstevel@tonic-gate add_amd_l2_tlb(devi, "l2-itlb-4K", 41297c478bd9Sstevel@tonic-gate BITX(cp->cp_eax, 15, 12), BITX(cp->cp_eax, 11, 0)); 41307c478bd9Sstevel@tonic-gate } 41317c478bd9Sstevel@tonic-gate 41327c478bd9Sstevel@tonic-gate add_amd_l2_cache(devi, l2_cache_str, 41337c478bd9Sstevel@tonic-gate BITX(cp->cp_ecx, 31, 16), BITX(cp->cp_ecx, 15, 12), 41347c478bd9Sstevel@tonic-gate BITX(cp->cp_ecx, 11, 8), BITX(cp->cp_ecx, 7, 0)); 41357c478bd9Sstevel@tonic-gate } 41367c478bd9Sstevel@tonic-gate 41377c478bd9Sstevel@tonic-gate /* 41387c478bd9Sstevel@tonic-gate * There are two basic ways that the x86 world describes it cache 41397c478bd9Sstevel@tonic-gate * and tlb architecture - Intel's way and AMD's way. 41407c478bd9Sstevel@tonic-gate * 41417c478bd9Sstevel@tonic-gate * Return which flavor of cache architecture we should use 41427c478bd9Sstevel@tonic-gate */ 41437c478bd9Sstevel@tonic-gate static int 41447c478bd9Sstevel@tonic-gate x86_which_cacheinfo(struct cpuid_info *cpi) 41457c478bd9Sstevel@tonic-gate { 41467c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 41477c478bd9Sstevel@tonic-gate case X86_VENDOR_Intel: 41487c478bd9Sstevel@tonic-gate if (cpi->cpi_maxeax >= 2) 41497c478bd9Sstevel@tonic-gate return (X86_VENDOR_Intel); 41507c478bd9Sstevel@tonic-gate break; 41517c478bd9Sstevel@tonic-gate case X86_VENDOR_AMD: 41527c478bd9Sstevel@tonic-gate /* 41537c478bd9Sstevel@tonic-gate * The K5 model 1 was the first part from AMD that reported 41547c478bd9Sstevel@tonic-gate * cache sizes via extended cpuid functions. 41557c478bd9Sstevel@tonic-gate */ 41567c478bd9Sstevel@tonic-gate if (cpi->cpi_family > 5 || 41577c478bd9Sstevel@tonic-gate (cpi->cpi_family == 5 && cpi->cpi_model >= 1)) 41587c478bd9Sstevel@tonic-gate return (X86_VENDOR_AMD); 41597c478bd9Sstevel@tonic-gate break; 41607c478bd9Sstevel@tonic-gate case X86_VENDOR_TM: 41617c478bd9Sstevel@tonic-gate if (cpi->cpi_family >= 5) 41627c478bd9Sstevel@tonic-gate return (X86_VENDOR_AMD); 41637c478bd9Sstevel@tonic-gate /*FALLTHROUGH*/ 41647c478bd9Sstevel@tonic-gate default: 41657c478bd9Sstevel@tonic-gate /* 41667c478bd9Sstevel@tonic-gate * If they have extended CPU data for 0x80000005 41677c478bd9Sstevel@tonic-gate * then we assume they have AMD-format cache 41687c478bd9Sstevel@tonic-gate * information. 41697c478bd9Sstevel@tonic-gate * 41707c478bd9Sstevel@tonic-gate * If not, and the vendor happens to be Cyrix, 41717c478bd9Sstevel@tonic-gate * then try our-Cyrix specific handler. 41727c478bd9Sstevel@tonic-gate * 41737c478bd9Sstevel@tonic-gate * If we're not Cyrix, then assume we're using Intel's 41747c478bd9Sstevel@tonic-gate * table-driven format instead. 41757c478bd9Sstevel@tonic-gate */ 41767c478bd9Sstevel@tonic-gate if (cpi->cpi_xmaxeax >= 0x80000005) 41777c478bd9Sstevel@tonic-gate return (X86_VENDOR_AMD); 41787c478bd9Sstevel@tonic-gate else if (cpi->cpi_vendor == X86_VENDOR_Cyrix) 41797c478bd9Sstevel@tonic-gate return (X86_VENDOR_Cyrix); 41807c478bd9Sstevel@tonic-gate else if (cpi->cpi_maxeax >= 2) 41817c478bd9Sstevel@tonic-gate return (X86_VENDOR_Intel); 41827c478bd9Sstevel@tonic-gate break; 41837c478bd9Sstevel@tonic-gate } 41847c478bd9Sstevel@tonic-gate return (-1); 41857c478bd9Sstevel@tonic-gate } 41867c478bd9Sstevel@tonic-gate 41877c478bd9Sstevel@tonic-gate void 4188fa96bd91SMichael Corcoran cpuid_set_cpu_properties(void *dip, processorid_t cpu_id, 4189fa96bd91SMichael Corcoran struct cpuid_info *cpi) 41907c478bd9Sstevel@tonic-gate { 41917c478bd9Sstevel@tonic-gate dev_info_t *cpu_devi; 41927c478bd9Sstevel@tonic-gate int create; 41937c478bd9Sstevel@tonic-gate 4194fa96bd91SMichael Corcoran cpu_devi = (dev_info_t *)dip; 41957c478bd9Sstevel@tonic-gate 41967c478bd9Sstevel@tonic-gate /* device_type */ 41977c478bd9Sstevel@tonic-gate (void) ndi_prop_update_string(DDI_DEV_T_NONE, cpu_devi, 41987c478bd9Sstevel@tonic-gate "device_type", "cpu"); 41997c478bd9Sstevel@tonic-gate 42007c478bd9Sstevel@tonic-gate /* reg */ 42017c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 42027c478bd9Sstevel@tonic-gate "reg", cpu_id); 42037c478bd9Sstevel@tonic-gate 42047c478bd9Sstevel@tonic-gate /* cpu-mhz, and clock-frequency */ 42057c478bd9Sstevel@tonic-gate if (cpu_freq > 0) { 42067c478bd9Sstevel@tonic-gate long long mul; 42077c478bd9Sstevel@tonic-gate 42087c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 42097c478bd9Sstevel@tonic-gate "cpu-mhz", cpu_freq); 42107c478bd9Sstevel@tonic-gate if ((mul = cpu_freq * 1000000LL) <= INT_MAX) 42117c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 42127c478bd9Sstevel@tonic-gate "clock-frequency", (int)mul); 42137c478bd9Sstevel@tonic-gate } 42147c478bd9Sstevel@tonic-gate 42157417cfdeSKuriakose Kuruvilla if (!is_x86_feature(x86_featureset, X86FSET_CPUID)) { 42167c478bd9Sstevel@tonic-gate return; 42177c478bd9Sstevel@tonic-gate } 42187c478bd9Sstevel@tonic-gate 42197c478bd9Sstevel@tonic-gate /* vendor-id */ 42207c478bd9Sstevel@tonic-gate (void) ndi_prop_update_string(DDI_DEV_T_NONE, cpu_devi, 42217c478bd9Sstevel@tonic-gate "vendor-id", cpi->cpi_vendorstr); 42227c478bd9Sstevel@tonic-gate 42237c478bd9Sstevel@tonic-gate if (cpi->cpi_maxeax == 0) { 42247c478bd9Sstevel@tonic-gate return; 42257c478bd9Sstevel@tonic-gate } 42267c478bd9Sstevel@tonic-gate 42277c478bd9Sstevel@tonic-gate /* 42287c478bd9Sstevel@tonic-gate * family, model, and step 42297c478bd9Sstevel@tonic-gate */ 42307c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 42317c478bd9Sstevel@tonic-gate "family", CPI_FAMILY(cpi)); 42327c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 42337c478bd9Sstevel@tonic-gate "cpu-model", CPI_MODEL(cpi)); 42347c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 42357c478bd9Sstevel@tonic-gate "stepping-id", CPI_STEP(cpi)); 42367c478bd9Sstevel@tonic-gate 42377c478bd9Sstevel@tonic-gate /* type */ 42387c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 42397c478bd9Sstevel@tonic-gate case X86_VENDOR_Intel: 42407c478bd9Sstevel@tonic-gate create = 1; 42417c478bd9Sstevel@tonic-gate break; 42427c478bd9Sstevel@tonic-gate default: 42437c478bd9Sstevel@tonic-gate create = 0; 42447c478bd9Sstevel@tonic-gate break; 42457c478bd9Sstevel@tonic-gate } 42467c478bd9Sstevel@tonic-gate if (create) 42477c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 42487c478bd9Sstevel@tonic-gate "type", CPI_TYPE(cpi)); 42497c478bd9Sstevel@tonic-gate 42507c478bd9Sstevel@tonic-gate /* ext-family */ 42517c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 42527c478bd9Sstevel@tonic-gate case X86_VENDOR_Intel: 42537c478bd9Sstevel@tonic-gate case X86_VENDOR_AMD: 42547c478bd9Sstevel@tonic-gate create = cpi->cpi_family >= 0xf; 42557c478bd9Sstevel@tonic-gate break; 42567c478bd9Sstevel@tonic-gate default: 42577c478bd9Sstevel@tonic-gate create = 0; 42587c478bd9Sstevel@tonic-gate break; 42597c478bd9Sstevel@tonic-gate } 42607c478bd9Sstevel@tonic-gate if (create) 42617c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 42627c478bd9Sstevel@tonic-gate "ext-family", CPI_FAMILY_XTD(cpi)); 42637c478bd9Sstevel@tonic-gate 42647c478bd9Sstevel@tonic-gate /* ext-model */ 42657c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 42667c478bd9Sstevel@tonic-gate case X86_VENDOR_Intel: 426763d3f7dfSkk208521 create = IS_EXTENDED_MODEL_INTEL(cpi); 426868c91426Sdmick break; 42697c478bd9Sstevel@tonic-gate case X86_VENDOR_AMD: 4270ee88d2b9Skchow create = CPI_FAMILY(cpi) == 0xf; 42717c478bd9Sstevel@tonic-gate break; 42727c478bd9Sstevel@tonic-gate default: 42737c478bd9Sstevel@tonic-gate create = 0; 42747c478bd9Sstevel@tonic-gate break; 42757c478bd9Sstevel@tonic-gate } 42767c478bd9Sstevel@tonic-gate if (create) 42777c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 42787c478bd9Sstevel@tonic-gate "ext-model", CPI_MODEL_XTD(cpi)); 42797c478bd9Sstevel@tonic-gate 42807c478bd9Sstevel@tonic-gate /* generation */ 42817c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 42827c478bd9Sstevel@tonic-gate case X86_VENDOR_AMD: 42837c478bd9Sstevel@tonic-gate /* 42847c478bd9Sstevel@tonic-gate * AMD K5 model 1 was the first part to support this 42857c478bd9Sstevel@tonic-gate */ 42867c478bd9Sstevel@tonic-gate create = cpi->cpi_xmaxeax >= 0x80000001; 42877c478bd9Sstevel@tonic-gate break; 42887c478bd9Sstevel@tonic-gate default: 42897c478bd9Sstevel@tonic-gate create = 0; 42907c478bd9Sstevel@tonic-gate break; 42917c478bd9Sstevel@tonic-gate } 42927c478bd9Sstevel@tonic-gate if (create) 42937c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 42947c478bd9Sstevel@tonic-gate "generation", BITX((cpi)->cpi_extd[1].cp_eax, 11, 8)); 42957c478bd9Sstevel@tonic-gate 42967c478bd9Sstevel@tonic-gate /* brand-id */ 42977c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 42987c478bd9Sstevel@tonic-gate case X86_VENDOR_Intel: 42997c478bd9Sstevel@tonic-gate /* 43007c478bd9Sstevel@tonic-gate * brand id first appeared on Pentium III Xeon model 8, 43017c478bd9Sstevel@tonic-gate * and Celeron model 8 processors and Opteron 43027c478bd9Sstevel@tonic-gate */ 43037c478bd9Sstevel@tonic-gate create = cpi->cpi_family > 6 || 43047c478bd9Sstevel@tonic-gate (cpi->cpi_family == 6 && cpi->cpi_model >= 8); 43057c478bd9Sstevel@tonic-gate break; 43067c478bd9Sstevel@tonic-gate case X86_VENDOR_AMD: 43077c478bd9Sstevel@tonic-gate create = cpi->cpi_family >= 0xf; 43087c478bd9Sstevel@tonic-gate break; 43097c478bd9Sstevel@tonic-gate default: 43107c478bd9Sstevel@tonic-gate create = 0; 43117c478bd9Sstevel@tonic-gate break; 43127c478bd9Sstevel@tonic-gate } 43137c478bd9Sstevel@tonic-gate if (create && cpi->cpi_brandid != 0) { 43147c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 43157c478bd9Sstevel@tonic-gate "brand-id", cpi->cpi_brandid); 43167c478bd9Sstevel@tonic-gate } 43177c478bd9Sstevel@tonic-gate 43187c478bd9Sstevel@tonic-gate /* chunks, and apic-id */ 43197c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 43207c478bd9Sstevel@tonic-gate /* 43217c478bd9Sstevel@tonic-gate * first available on Pentium IV and Opteron (K8) 43227c478bd9Sstevel@tonic-gate */ 43235ff02082Sdmick case X86_VENDOR_Intel: 43245ff02082Sdmick create = IS_NEW_F6(cpi) || cpi->cpi_family >= 0xf; 43255ff02082Sdmick break; 43265ff02082Sdmick case X86_VENDOR_AMD: 43277c478bd9Sstevel@tonic-gate create = cpi->cpi_family >= 0xf; 43287c478bd9Sstevel@tonic-gate break; 43297c478bd9Sstevel@tonic-gate default: 43307c478bd9Sstevel@tonic-gate create = 0; 43317c478bd9Sstevel@tonic-gate break; 43327c478bd9Sstevel@tonic-gate } 43337c478bd9Sstevel@tonic-gate if (create) { 43347c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 43357c478bd9Sstevel@tonic-gate "chunks", CPI_CHUNKS(cpi)); 43367c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 4337b6917abeSmishra "apic-id", cpi->cpi_apicid); 43387aec1d6eScindi if (cpi->cpi_chipid >= 0) { 43397c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 43407c478bd9Sstevel@tonic-gate "chip#", cpi->cpi_chipid); 43417aec1d6eScindi (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 43427aec1d6eScindi "clog#", cpi->cpi_clogid); 43437aec1d6eScindi } 43447c478bd9Sstevel@tonic-gate } 43457c478bd9Sstevel@tonic-gate 43467c478bd9Sstevel@tonic-gate /* cpuid-features */ 43477c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 43487c478bd9Sstevel@tonic-gate "cpuid-features", CPI_FEATURES_EDX(cpi)); 43497c478bd9Sstevel@tonic-gate 43507c478bd9Sstevel@tonic-gate 43517c478bd9Sstevel@tonic-gate /* cpuid-features-ecx */ 43527c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 43537c478bd9Sstevel@tonic-gate case X86_VENDOR_Intel: 43545ff02082Sdmick create = IS_NEW_F6(cpi) || cpi->cpi_family >= 0xf; 43557c478bd9Sstevel@tonic-gate break; 435663408480SHans Rosenfeld case X86_VENDOR_AMD: 435763408480SHans Rosenfeld create = cpi->cpi_family >= 0xf; 435863408480SHans Rosenfeld break; 43597c478bd9Sstevel@tonic-gate default: 43607c478bd9Sstevel@tonic-gate create = 0; 43617c478bd9Sstevel@tonic-gate break; 43627c478bd9Sstevel@tonic-gate } 43637c478bd9Sstevel@tonic-gate if (create) 43647c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 43657c478bd9Sstevel@tonic-gate "cpuid-features-ecx", CPI_FEATURES_ECX(cpi)); 43667c478bd9Sstevel@tonic-gate 43677c478bd9Sstevel@tonic-gate /* ext-cpuid-features */ 43687c478bd9Sstevel@tonic-gate switch (cpi->cpi_vendor) { 43695ff02082Sdmick case X86_VENDOR_Intel: 43707c478bd9Sstevel@tonic-gate case X86_VENDOR_AMD: 43717c478bd9Sstevel@tonic-gate case X86_VENDOR_Cyrix: 43727c478bd9Sstevel@tonic-gate case X86_VENDOR_TM: 43737c478bd9Sstevel@tonic-gate case X86_VENDOR_Centaur: 43747c478bd9Sstevel@tonic-gate create = cpi->cpi_xmaxeax >= 0x80000001; 43757c478bd9Sstevel@tonic-gate break; 43767c478bd9Sstevel@tonic-gate default: 43777c478bd9Sstevel@tonic-gate create = 0; 43787c478bd9Sstevel@tonic-gate break; 43797c478bd9Sstevel@tonic-gate } 43805ff02082Sdmick if (create) { 43817c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 43827c478bd9Sstevel@tonic-gate "ext-cpuid-features", CPI_FEATURES_XTD_EDX(cpi)); 43835ff02082Sdmick (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 43845ff02082Sdmick "ext-cpuid-features-ecx", CPI_FEATURES_XTD_ECX(cpi)); 43855ff02082Sdmick } 43867c478bd9Sstevel@tonic-gate 43877c478bd9Sstevel@tonic-gate /* 43887c478bd9Sstevel@tonic-gate * Brand String first appeared in Intel Pentium IV, AMD K5 43897c478bd9Sstevel@tonic-gate * model 1, and Cyrix GXm. On earlier models we try and 43907c478bd9Sstevel@tonic-gate * simulate something similar .. so this string should always 43917c478bd9Sstevel@tonic-gate * same -something- about the processor, however lame. 43927c478bd9Sstevel@tonic-gate */ 43937c478bd9Sstevel@tonic-gate (void) ndi_prop_update_string(DDI_DEV_T_NONE, cpu_devi, 43947c478bd9Sstevel@tonic-gate "brand-string", cpi->cpi_brandstr); 43957c478bd9Sstevel@tonic-gate 43967c478bd9Sstevel@tonic-gate /* 43977c478bd9Sstevel@tonic-gate * Finally, cache and tlb information 43987c478bd9Sstevel@tonic-gate */ 43997c478bd9Sstevel@tonic-gate switch (x86_which_cacheinfo(cpi)) { 44007c478bd9Sstevel@tonic-gate case X86_VENDOR_Intel: 44017c478bd9Sstevel@tonic-gate intel_walk_cacheinfo(cpi, cpu_devi, add_cacheent_props); 44027c478bd9Sstevel@tonic-gate break; 44037c478bd9Sstevel@tonic-gate case X86_VENDOR_Cyrix: 44047c478bd9Sstevel@tonic-gate cyrix_walk_cacheinfo(cpi, cpu_devi, add_cacheent_props); 44057c478bd9Sstevel@tonic-gate break; 44067c478bd9Sstevel@tonic-gate case X86_VENDOR_AMD: 44077c478bd9Sstevel@tonic-gate amd_cache_info(cpi, cpu_devi); 44087c478bd9Sstevel@tonic-gate break; 44097c478bd9Sstevel@tonic-gate default: 44107c478bd9Sstevel@tonic-gate break; 44117c478bd9Sstevel@tonic-gate } 44127c478bd9Sstevel@tonic-gate } 44137c478bd9Sstevel@tonic-gate 44147c478bd9Sstevel@tonic-gate struct l2info { 44157c478bd9Sstevel@tonic-gate int *l2i_csz; 44167c478bd9Sstevel@tonic-gate int *l2i_lsz; 44177c478bd9Sstevel@tonic-gate int *l2i_assoc; 44187c478bd9Sstevel@tonic-gate int l2i_ret; 44197c478bd9Sstevel@tonic-gate }; 44207c478bd9Sstevel@tonic-gate 44217c478bd9Sstevel@tonic-gate /* 44227c478bd9Sstevel@tonic-gate * A cacheinfo walker that fetches the size, line-size and associativity 44237c478bd9Sstevel@tonic-gate * of the L2 cache 44247c478bd9Sstevel@tonic-gate */ 44257c478bd9Sstevel@tonic-gate static int 44267c478bd9Sstevel@tonic-gate intel_l2cinfo(void *arg, const struct cachetab *ct) 44277c478bd9Sstevel@tonic-gate { 44287c478bd9Sstevel@tonic-gate struct l2info *l2i = arg; 44297c478bd9Sstevel@tonic-gate int *ip; 44307c478bd9Sstevel@tonic-gate 44317c478bd9Sstevel@tonic-gate if (ct->ct_label != l2_cache_str && 44327c478bd9Sstevel@tonic-gate ct->ct_label != sl2_cache_str) 44337c478bd9Sstevel@tonic-gate return (0); /* not an L2 -- keep walking */ 44347c478bd9Sstevel@tonic-gate 44357c478bd9Sstevel@tonic-gate if ((ip = l2i->l2i_csz) != NULL) 44367c478bd9Sstevel@tonic-gate *ip = ct->ct_size; 44377c478bd9Sstevel@tonic-gate if ((ip = l2i->l2i_lsz) != NULL) 44387c478bd9Sstevel@tonic-gate *ip = ct->ct_line_size; 44397c478bd9Sstevel@tonic-gate if ((ip = l2i->l2i_assoc) != NULL) 44407c478bd9Sstevel@tonic-gate *ip = ct->ct_assoc; 44417c478bd9Sstevel@tonic-gate l2i->l2i_ret = ct->ct_size; 44427c478bd9Sstevel@tonic-gate return (1); /* was an L2 -- terminate walk */ 44437c478bd9Sstevel@tonic-gate } 44447c478bd9Sstevel@tonic-gate 4445606303c9Skchow /* 4446606303c9Skchow * AMD L2/L3 Cache and TLB Associativity Field Definition: 4447606303c9Skchow * 4448606303c9Skchow * Unlike the associativity for the L1 cache and tlb where the 8 bit 4449606303c9Skchow * value is the associativity, the associativity for the L2 cache and 4450606303c9Skchow * tlb is encoded in the following table. The 4 bit L2 value serves as 4451606303c9Skchow * an index into the amd_afd[] array to determine the associativity. 4452606303c9Skchow * -1 is undefined. 0 is fully associative. 4453606303c9Skchow */ 4454606303c9Skchow 4455606303c9Skchow static int amd_afd[] = 4456606303c9Skchow {-1, 1, 2, -1, 4, -1, 8, -1, 16, -1, 32, 48, 64, 96, 128, 0}; 4457606303c9Skchow 44587c478bd9Sstevel@tonic-gate static void 44597c478bd9Sstevel@tonic-gate amd_l2cacheinfo(struct cpuid_info *cpi, struct l2info *l2i) 44607c478bd9Sstevel@tonic-gate { 44618949bcd6Sandrei struct cpuid_regs *cp; 44627c478bd9Sstevel@tonic-gate uint_t size, assoc; 4463606303c9Skchow int i; 44647c478bd9Sstevel@tonic-gate int *ip; 44657c478bd9Sstevel@tonic-gate 44667c478bd9Sstevel@tonic-gate if (cpi->cpi_xmaxeax < 0x80000006) 44677c478bd9Sstevel@tonic-gate return; 44687c478bd9Sstevel@tonic-gate cp = &cpi->cpi_extd[6]; 44697c478bd9Sstevel@tonic-gate 4470606303c9Skchow if ((i = BITX(cp->cp_ecx, 15, 12)) != 0 && 44717c478bd9Sstevel@tonic-gate (size = BITX(cp->cp_ecx, 31, 16)) != 0) { 44727c478bd9Sstevel@tonic-gate uint_t cachesz = size * 1024; 4473606303c9Skchow assoc = amd_afd[i]; 44747c478bd9Sstevel@tonic-gate 4475606303c9Skchow ASSERT(assoc != -1); 44767c478bd9Sstevel@tonic-gate 44777c478bd9Sstevel@tonic-gate if ((ip = l2i->l2i_csz) != NULL) 44787c478bd9Sstevel@tonic-gate *ip = cachesz; 44797c478bd9Sstevel@tonic-gate if ((ip = l2i->l2i_lsz) != NULL) 44807c478bd9Sstevel@tonic-gate *ip = BITX(cp->cp_ecx, 7, 0); 44817c478bd9Sstevel@tonic-gate if ((ip = l2i->l2i_assoc) != NULL) 44827c478bd9Sstevel@tonic-gate *ip = assoc; 44837c478bd9Sstevel@tonic-gate l2i->l2i_ret = cachesz; 44847c478bd9Sstevel@tonic-gate } 44857c478bd9Sstevel@tonic-gate } 44867c478bd9Sstevel@tonic-gate 44877c478bd9Sstevel@tonic-gate int 44887c478bd9Sstevel@tonic-gate getl2cacheinfo(cpu_t *cpu, int *csz, int *lsz, int *assoc) 44897c478bd9Sstevel@tonic-gate { 44907c478bd9Sstevel@tonic-gate struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 44917c478bd9Sstevel@tonic-gate struct l2info __l2info, *l2i = &__l2info; 44927c478bd9Sstevel@tonic-gate 44937c478bd9Sstevel@tonic-gate l2i->l2i_csz = csz; 44947c478bd9Sstevel@tonic-gate l2i->l2i_lsz = lsz; 44957c478bd9Sstevel@tonic-gate l2i->l2i_assoc = assoc; 44967c478bd9Sstevel@tonic-gate l2i->l2i_ret = -1; 44977c478bd9Sstevel@tonic-gate 44987c478bd9Sstevel@tonic-gate switch (x86_which_cacheinfo(cpi)) { 44997c478bd9Sstevel@tonic-gate case X86_VENDOR_Intel: 45007c478bd9Sstevel@tonic-gate intel_walk_cacheinfo(cpi, l2i, intel_l2cinfo); 45017c478bd9Sstevel@tonic-gate break; 45027c478bd9Sstevel@tonic-gate case X86_VENDOR_Cyrix: 45037c478bd9Sstevel@tonic-gate cyrix_walk_cacheinfo(cpi, l2i, intel_l2cinfo); 45047c478bd9Sstevel@tonic-gate break; 45057c478bd9Sstevel@tonic-gate case X86_VENDOR_AMD: 45067c478bd9Sstevel@tonic-gate amd_l2cacheinfo(cpi, l2i); 45077c478bd9Sstevel@tonic-gate break; 45087c478bd9Sstevel@tonic-gate default: 45097c478bd9Sstevel@tonic-gate break; 45107c478bd9Sstevel@tonic-gate } 45117c478bd9Sstevel@tonic-gate return (l2i->l2i_ret); 45127c478bd9Sstevel@tonic-gate } 4513f98fbcecSbholler 4514843e1988Sjohnlev #if !defined(__xpv) 4515843e1988Sjohnlev 45165b8a6efeSbholler uint32_t * 45175b8a6efeSbholler cpuid_mwait_alloc(cpu_t *cpu) 45185b8a6efeSbholler { 45195b8a6efeSbholler uint32_t *ret; 45205b8a6efeSbholler size_t mwait_size; 45215b8a6efeSbholler 4522a3114836SGerry Liu ASSERT(cpuid_checkpass(CPU, 2)); 45235b8a6efeSbholler 4524a3114836SGerry Liu mwait_size = CPU->cpu_m.mcpu_cpi->cpi_mwait.mon_max; 45255b8a6efeSbholler if (mwait_size == 0) 45265b8a6efeSbholler return (NULL); 45275b8a6efeSbholler 45285b8a6efeSbholler /* 45295b8a6efeSbholler * kmem_alloc() returns cache line size aligned data for mwait_size 45305b8a6efeSbholler * allocations. mwait_size is currently cache line sized. Neither 45315b8a6efeSbholler * of these implementation details are guarantied to be true in the 45325b8a6efeSbholler * future. 45335b8a6efeSbholler * 45345b8a6efeSbholler * First try allocating mwait_size as kmem_alloc() currently returns 45355b8a6efeSbholler * correctly aligned memory. If kmem_alloc() does not return 45365b8a6efeSbholler * mwait_size aligned memory, then use mwait_size ROUNDUP. 45375b8a6efeSbholler * 45385b8a6efeSbholler * Set cpi_mwait.buf_actual and cpi_mwait.size_actual in case we 45395b8a6efeSbholler * decide to free this memory. 45405b8a6efeSbholler */ 45415b8a6efeSbholler ret = kmem_zalloc(mwait_size, KM_SLEEP); 45425b8a6efeSbholler if (ret == (uint32_t *)P2ROUNDUP((uintptr_t)ret, mwait_size)) { 45435b8a6efeSbholler cpu->cpu_m.mcpu_cpi->cpi_mwait.buf_actual = ret; 45445b8a6efeSbholler cpu->cpu_m.mcpu_cpi->cpi_mwait.size_actual = mwait_size; 45455b8a6efeSbholler *ret = MWAIT_RUNNING; 45465b8a6efeSbholler return (ret); 45475b8a6efeSbholler } else { 45485b8a6efeSbholler kmem_free(ret, mwait_size); 45495b8a6efeSbholler ret = kmem_zalloc(mwait_size * 2, KM_SLEEP); 45505b8a6efeSbholler cpu->cpu_m.mcpu_cpi->cpi_mwait.buf_actual = ret; 45515b8a6efeSbholler cpu->cpu_m.mcpu_cpi->cpi_mwait.size_actual = mwait_size * 2; 45525b8a6efeSbholler ret = (uint32_t *)P2ROUNDUP((uintptr_t)ret, mwait_size); 45535b8a6efeSbholler *ret = MWAIT_RUNNING; 45545b8a6efeSbholler return (ret); 45555b8a6efeSbholler } 45565b8a6efeSbholler } 45575b8a6efeSbholler 45585b8a6efeSbholler void 45595b8a6efeSbholler cpuid_mwait_free(cpu_t *cpu) 4560f98fbcecSbholler { 4561a3114836SGerry Liu if (cpu->cpu_m.mcpu_cpi == NULL) { 4562a3114836SGerry Liu return; 4563a3114836SGerry Liu } 45645b8a6efeSbholler 45655b8a6efeSbholler if (cpu->cpu_m.mcpu_cpi->cpi_mwait.buf_actual != NULL && 45665b8a6efeSbholler cpu->cpu_m.mcpu_cpi->cpi_mwait.size_actual > 0) { 45675b8a6efeSbholler kmem_free(cpu->cpu_m.mcpu_cpi->cpi_mwait.buf_actual, 45685b8a6efeSbholler cpu->cpu_m.mcpu_cpi->cpi_mwait.size_actual); 45695b8a6efeSbholler } 45705b8a6efeSbholler 45715b8a6efeSbholler cpu->cpu_m.mcpu_cpi->cpi_mwait.buf_actual = NULL; 45725b8a6efeSbholler cpu->cpu_m.mcpu_cpi->cpi_mwait.size_actual = 0; 4573f98fbcecSbholler } 4574843e1988Sjohnlev 4575247dbb3dSsudheer void 4576247dbb3dSsudheer patch_tsc_read(int flag) 4577247dbb3dSsudheer { 4578247dbb3dSsudheer size_t cnt; 4579e4b86885SCheng Sean Ye 4580247dbb3dSsudheer switch (flag) { 4581*263f549eSPatrick Mooney case TSC_NONE: 4582247dbb3dSsudheer cnt = &_no_rdtsc_end - &_no_rdtsc_start; 45832b0bcb26Ssudheer (void) memcpy((void *)tsc_read, (void *)&_no_rdtsc_start, cnt); 4584247dbb3dSsudheer break; 4585*263f549eSPatrick Mooney case TSC_RDTSC_MFENCE: 4586247dbb3dSsudheer cnt = &_tsc_mfence_end - &_tsc_mfence_start; 45872b0bcb26Ssudheer (void) memcpy((void *)tsc_read, 45882b0bcb26Ssudheer (void *)&_tsc_mfence_start, cnt); 4589247dbb3dSsudheer break; 4590*263f549eSPatrick Mooney case TSC_RDTSC_LFENCE: 459115363b27Ssudheer cnt = &_tsc_lfence_end - &_tsc_lfence_start; 459215363b27Ssudheer (void) memcpy((void *)tsc_read, 459315363b27Ssudheer (void *)&_tsc_lfence_start, cnt); 459415363b27Ssudheer break; 4595*263f549eSPatrick Mooney case TSC_TSCP: 4596*263f549eSPatrick Mooney cnt = &_tscp_end - &_tscp_start; 4597*263f549eSPatrick Mooney (void) memcpy((void *)tsc_read, (void *)&_tscp_start, cnt); 4598*263f549eSPatrick Mooney break; 4599247dbb3dSsudheer default: 4600*263f549eSPatrick Mooney /* Bail for unexpected TSC types. (TSC_NONE covers 0) */ 4601*263f549eSPatrick Mooney cmn_err(CE_PANIC, "Unrecogized TSC type: %d", flag); 4602247dbb3dSsudheer break; 4603247dbb3dSsudheer } 4604*263f549eSPatrick Mooney tsc_type = flag; 4605247dbb3dSsudheer } 4606247dbb3dSsudheer 46070e751525SEric Saxe int 46080e751525SEric Saxe cpuid_deep_cstates_supported(void) 46090e751525SEric Saxe { 46100e751525SEric Saxe struct cpuid_info *cpi; 46110e751525SEric Saxe struct cpuid_regs regs; 46120e751525SEric Saxe 46130e751525SEric Saxe ASSERT(cpuid_checkpass(CPU, 1)); 46140e751525SEric Saxe 46150e751525SEric Saxe cpi = CPU->cpu_m.mcpu_cpi; 46160e751525SEric Saxe 46177417cfdeSKuriakose Kuruvilla if (!is_x86_feature(x86_featureset, X86FSET_CPUID)) 46180e751525SEric Saxe return (0); 46190e751525SEric Saxe 46200e751525SEric Saxe switch (cpi->cpi_vendor) { 46210e751525SEric Saxe case X86_VENDOR_Intel: 46220e751525SEric Saxe if (cpi->cpi_xmaxeax < 0x80000007) 46230e751525SEric Saxe return (0); 46240e751525SEric Saxe 46250e751525SEric Saxe /* 46260e751525SEric Saxe * TSC run at a constant rate in all ACPI C-states? 46270e751525SEric Saxe */ 46280e751525SEric Saxe regs.cp_eax = 0x80000007; 46290e751525SEric Saxe (void) __cpuid_insn(®s); 46300e751525SEric Saxe return (regs.cp_edx & CPUID_TSC_CSTATE_INVARIANCE); 46310e751525SEric Saxe 46320e751525SEric Saxe default: 46330e751525SEric Saxe return (0); 46340e751525SEric Saxe } 46350e751525SEric Saxe } 46360e751525SEric Saxe 4637e774b42bSBill Holler #endif /* !__xpv */ 4638e774b42bSBill Holler 4639e774b42bSBill Holler void 4640e774b42bSBill Holler post_startup_cpu_fixups(void) 4641e774b42bSBill Holler { 4642e774b42bSBill Holler #ifndef __xpv 4643e774b42bSBill Holler /* 4644e774b42bSBill Holler * Some AMD processors support C1E state. Entering this state will 4645e774b42bSBill Holler * cause the local APIC timer to stop, which we can't deal with at 4646e774b42bSBill Holler * this time. 4647e774b42bSBill Holler */ 4648e774b42bSBill Holler if (cpuid_getvendor(CPU) == X86_VENDOR_AMD) { 4649e774b42bSBill Holler on_trap_data_t otd; 4650e774b42bSBill Holler uint64_t reg; 4651e774b42bSBill Holler 4652e774b42bSBill Holler if (!on_trap(&otd, OT_DATA_ACCESS)) { 4653e774b42bSBill Holler reg = rdmsr(MSR_AMD_INT_PENDING_CMP_HALT); 4654e774b42bSBill Holler /* Disable C1E state if it is enabled by BIOS */ 4655e774b42bSBill Holler if ((reg >> AMD_ACTONCMPHALT_SHIFT) & 4656e774b42bSBill Holler AMD_ACTONCMPHALT_MASK) { 4657e774b42bSBill Holler reg &= ~(AMD_ACTONCMPHALT_MASK << 4658e774b42bSBill Holler AMD_ACTONCMPHALT_SHIFT); 4659e774b42bSBill Holler wrmsr(MSR_AMD_INT_PENDING_CMP_HALT, reg); 4660e774b42bSBill Holler } 4661e774b42bSBill Holler } 4662e774b42bSBill Holler no_trap(); 4663e774b42bSBill Holler } 4664e774b42bSBill Holler #endif /* !__xpv */ 4665e774b42bSBill Holler } 4666e774b42bSBill Holler 4667cef70d2cSBill Holler /* 46687af88ac7SKuriakose Kuruvilla * Setup necessary registers to enable XSAVE feature on this processor. 46697af88ac7SKuriakose Kuruvilla * This function needs to be called early enough, so that no xsave/xrstor 46707af88ac7SKuriakose Kuruvilla * ops will execute on the processor before the MSRs are properly set up. 46717af88ac7SKuriakose Kuruvilla * 46727af88ac7SKuriakose Kuruvilla * Current implementation has the following assumption: 46737af88ac7SKuriakose Kuruvilla * - cpuid_pass1() is done, so that X86 features are known. 46747af88ac7SKuriakose Kuruvilla * - fpu_probe() is done, so that fp_save_mech is chosen. 46757af88ac7SKuriakose Kuruvilla */ 46767af88ac7SKuriakose Kuruvilla void 46777af88ac7SKuriakose Kuruvilla xsave_setup_msr(cpu_t *cpu) 46787af88ac7SKuriakose Kuruvilla { 46797af88ac7SKuriakose Kuruvilla ASSERT(fp_save_mech == FP_XSAVE); 46807af88ac7SKuriakose Kuruvilla ASSERT(is_x86_feature(x86_featureset, X86FSET_XSAVE)); 46817af88ac7SKuriakose Kuruvilla 46827af88ac7SKuriakose Kuruvilla /* Enable OSXSAVE in CR4. */ 46837af88ac7SKuriakose Kuruvilla setcr4(getcr4() | CR4_OSXSAVE); 46847af88ac7SKuriakose Kuruvilla /* 46857af88ac7SKuriakose Kuruvilla * Update SW copy of ECX, so that /dev/cpu/self/cpuid will report 46867af88ac7SKuriakose Kuruvilla * correct value. 46877af88ac7SKuriakose Kuruvilla */ 46887af88ac7SKuriakose Kuruvilla cpu->cpu_m.mcpu_cpi->cpi_std[1].cp_ecx |= CPUID_INTC_ECX_OSXSAVE; 46897af88ac7SKuriakose Kuruvilla setup_xfem(); 46907af88ac7SKuriakose Kuruvilla } 46917af88ac7SKuriakose Kuruvilla 46927af88ac7SKuriakose Kuruvilla /* 4693cef70d2cSBill Holler * Starting with the Westmere processor the local 4694cef70d2cSBill Holler * APIC timer will continue running in all C-states, 4695cef70d2cSBill Holler * including the deepest C-states. 4696cef70d2cSBill Holler */ 4697cef70d2cSBill Holler int 4698cef70d2cSBill Holler cpuid_arat_supported(void) 4699cef70d2cSBill Holler { 4700cef70d2cSBill Holler struct cpuid_info *cpi; 4701cef70d2cSBill Holler struct cpuid_regs regs; 4702cef70d2cSBill Holler 4703cef70d2cSBill Holler ASSERT(cpuid_checkpass(CPU, 1)); 47047417cfdeSKuriakose Kuruvilla ASSERT(is_x86_feature(x86_featureset, X86FSET_CPUID)); 4705cef70d2cSBill Holler 4706cef70d2cSBill Holler cpi = CPU->cpu_m.mcpu_cpi; 4707cef70d2cSBill Holler 4708cef70d2cSBill Holler switch (cpi->cpi_vendor) { 4709cef70d2cSBill Holler case X86_VENDOR_Intel: 4710cef70d2cSBill Holler /* 4711cef70d2cSBill Holler * Always-running Local APIC Timer is 4712cef70d2cSBill Holler * indicated by CPUID.6.EAX[2]. 4713cef70d2cSBill Holler */ 4714cef70d2cSBill Holler if (cpi->cpi_maxeax >= 6) { 4715cef70d2cSBill Holler regs.cp_eax = 6; 4716cef70d2cSBill Holler (void) cpuid_insn(NULL, ®s); 4717cef70d2cSBill Holler return (regs.cp_eax & CPUID_CSTATE_ARAT); 4718cef70d2cSBill Holler } else { 4719cef70d2cSBill Holler return (0); 4720cef70d2cSBill Holler } 4721cef70d2cSBill Holler default: 4722cef70d2cSBill Holler return (0); 4723cef70d2cSBill Holler } 4724cef70d2cSBill Holler } 4725cef70d2cSBill Holler 4726f21ed392Saubrey.li@intel.com /* 4727f21ed392Saubrey.li@intel.com * Check support for Intel ENERGY_PERF_BIAS feature 4728f21ed392Saubrey.li@intel.com */ 4729f21ed392Saubrey.li@intel.com int 4730f21ed392Saubrey.li@intel.com cpuid_iepb_supported(struct cpu *cp) 4731f21ed392Saubrey.li@intel.com { 4732f21ed392Saubrey.li@intel.com struct cpuid_info *cpi = cp->cpu_m.mcpu_cpi; 4733f21ed392Saubrey.li@intel.com struct cpuid_regs regs; 4734f21ed392Saubrey.li@intel.com 4735f21ed392Saubrey.li@intel.com ASSERT(cpuid_checkpass(cp, 1)); 4736f21ed392Saubrey.li@intel.com 47377417cfdeSKuriakose Kuruvilla if (!(is_x86_feature(x86_featureset, X86FSET_CPUID)) || 47387417cfdeSKuriakose Kuruvilla !(is_x86_feature(x86_featureset, X86FSET_MSR))) { 4739f21ed392Saubrey.li@intel.com return (0); 4740f21ed392Saubrey.li@intel.com } 4741f21ed392Saubrey.li@intel.com 4742f21ed392Saubrey.li@intel.com /* 4743f21ed392Saubrey.li@intel.com * Intel ENERGY_PERF_BIAS MSR is indicated by 4744f21ed392Saubrey.li@intel.com * capability bit CPUID.6.ECX.3 4745f21ed392Saubrey.li@intel.com */ 4746f21ed392Saubrey.li@intel.com if ((cpi->cpi_vendor != X86_VENDOR_Intel) || (cpi->cpi_maxeax < 6)) 4747f21ed392Saubrey.li@intel.com return (0); 4748f21ed392Saubrey.li@intel.com 4749f21ed392Saubrey.li@intel.com regs.cp_eax = 0x6; 4750f21ed392Saubrey.li@intel.com (void) cpuid_insn(NULL, ®s); 4751f21ed392Saubrey.li@intel.com return (regs.cp_ecx & CPUID_EPB_SUPPORT); 4752f21ed392Saubrey.li@intel.com } 4753f21ed392Saubrey.li@intel.com 475441afdfa7SKrishnendu Sadhukhan - Sun Microsystems /* 475541afdfa7SKrishnendu Sadhukhan - Sun Microsystems * Check support for TSC deadline timer 475641afdfa7SKrishnendu Sadhukhan - Sun Microsystems * 475741afdfa7SKrishnendu Sadhukhan - Sun Microsystems * TSC deadline timer provides a superior software programming 475841afdfa7SKrishnendu Sadhukhan - Sun Microsystems * model over local APIC timer that eliminates "time drifts". 475941afdfa7SKrishnendu Sadhukhan - Sun Microsystems * Instead of specifying a relative time, software specifies an 476041afdfa7SKrishnendu Sadhukhan - Sun Microsystems * absolute time as the target at which the processor should 476141afdfa7SKrishnendu Sadhukhan - Sun Microsystems * generate a timer event. 476241afdfa7SKrishnendu Sadhukhan - Sun Microsystems */ 476341afdfa7SKrishnendu Sadhukhan - Sun Microsystems int 476441afdfa7SKrishnendu Sadhukhan - Sun Microsystems cpuid_deadline_tsc_supported(void) 476541afdfa7SKrishnendu Sadhukhan - Sun Microsystems { 476641afdfa7SKrishnendu Sadhukhan - Sun Microsystems struct cpuid_info *cpi = CPU->cpu_m.mcpu_cpi; 476741afdfa7SKrishnendu Sadhukhan - Sun Microsystems struct cpuid_regs regs; 476841afdfa7SKrishnendu Sadhukhan - Sun Microsystems 476941afdfa7SKrishnendu Sadhukhan - Sun Microsystems ASSERT(cpuid_checkpass(CPU, 1)); 477041afdfa7SKrishnendu Sadhukhan - Sun Microsystems ASSERT(is_x86_feature(x86_featureset, X86FSET_CPUID)); 477141afdfa7SKrishnendu Sadhukhan - Sun Microsystems 477241afdfa7SKrishnendu Sadhukhan - Sun Microsystems switch (cpi->cpi_vendor) { 477341afdfa7SKrishnendu Sadhukhan - Sun Microsystems case X86_VENDOR_Intel: 477441afdfa7SKrishnendu Sadhukhan - Sun Microsystems if (cpi->cpi_maxeax >= 1) { 477541afdfa7SKrishnendu Sadhukhan - Sun Microsystems regs.cp_eax = 1; 477641afdfa7SKrishnendu Sadhukhan - Sun Microsystems (void) cpuid_insn(NULL, ®s); 477741afdfa7SKrishnendu Sadhukhan - Sun Microsystems return (regs.cp_ecx & CPUID_DEADLINE_TSC); 477841afdfa7SKrishnendu Sadhukhan - Sun Microsystems } else { 477941afdfa7SKrishnendu Sadhukhan - Sun Microsystems return (0); 478041afdfa7SKrishnendu Sadhukhan - Sun Microsystems } 478141afdfa7SKrishnendu Sadhukhan - Sun Microsystems default: 478241afdfa7SKrishnendu Sadhukhan - Sun Microsystems return (0); 478341afdfa7SKrishnendu Sadhukhan - Sun Microsystems } 478441afdfa7SKrishnendu Sadhukhan - Sun Microsystems } 478541afdfa7SKrishnendu Sadhukhan - Sun Microsystems 478622cc0e45SBill Holler #if defined(__amd64) && !defined(__xpv) 478722cc0e45SBill Holler /* 478822cc0e45SBill Holler * Patch in versions of bcopy for high performance Intel Nhm processors 478922cc0e45SBill Holler * and later... 479022cc0e45SBill Holler */ 479122cc0e45SBill Holler void 479222cc0e45SBill Holler patch_memops(uint_t vendor) 479322cc0e45SBill Holler { 479422cc0e45SBill Holler size_t cnt, i; 479522cc0e45SBill Holler caddr_t to, from; 479622cc0e45SBill Holler 47977417cfdeSKuriakose Kuruvilla if ((vendor == X86_VENDOR_Intel) && 47987417cfdeSKuriakose Kuruvilla is_x86_feature(x86_featureset, X86FSET_SSE4_2)) { 479922cc0e45SBill Holler cnt = &bcopy_patch_end - &bcopy_patch_start; 480022cc0e45SBill Holler to = &bcopy_ck_size; 480122cc0e45SBill Holler from = &bcopy_patch_start; 480222cc0e45SBill Holler for (i = 0; i < cnt; i++) { 480322cc0e45SBill Holler *to++ = *from++; 480422cc0e45SBill Holler } 480522cc0e45SBill Holler } 480622cc0e45SBill Holler } 480722cc0e45SBill Holler #endif /* __amd64 && !__xpv */ 48082d2efdc6SVuong Nguyen 48092d2efdc6SVuong Nguyen /* 48102d2efdc6SVuong Nguyen * This function finds the number of bits to represent the number of cores per 48112d2efdc6SVuong Nguyen * chip and the number of strands per core for the Intel platforms. 48122d2efdc6SVuong Nguyen * It re-uses the x2APIC cpuid code of the cpuid_pass2(). 48132d2efdc6SVuong Nguyen */ 48142d2efdc6SVuong Nguyen void 48152d2efdc6SVuong Nguyen cpuid_get_ext_topo(uint_t vendor, uint_t *core_nbits, uint_t *strand_nbits) 48162d2efdc6SVuong Nguyen { 48172d2efdc6SVuong Nguyen struct cpuid_regs regs; 48182d2efdc6SVuong Nguyen struct cpuid_regs *cp = ®s; 48192d2efdc6SVuong Nguyen 48202d2efdc6SVuong Nguyen if (vendor != X86_VENDOR_Intel) { 48212d2efdc6SVuong Nguyen return; 48222d2efdc6SVuong Nguyen } 48232d2efdc6SVuong Nguyen 48242d2efdc6SVuong Nguyen /* if the cpuid level is 0xB, extended topo is available. */ 48252d2efdc6SVuong Nguyen cp->cp_eax = 0; 48262d2efdc6SVuong Nguyen if (__cpuid_insn(cp) >= 0xB) { 48272d2efdc6SVuong Nguyen 48282d2efdc6SVuong Nguyen cp->cp_eax = 0xB; 48292d2efdc6SVuong Nguyen cp->cp_edx = cp->cp_ebx = cp->cp_ecx = 0; 48302d2efdc6SVuong Nguyen (void) __cpuid_insn(cp); 48312d2efdc6SVuong Nguyen 48322d2efdc6SVuong Nguyen /* 48332d2efdc6SVuong Nguyen * Check CPUID.EAX=0BH, ECX=0H:EBX is non-zero, which 48342d2efdc6SVuong Nguyen * indicates that the extended topology enumeration leaf is 48352d2efdc6SVuong Nguyen * available. 48362d2efdc6SVuong Nguyen */ 48372d2efdc6SVuong Nguyen if (cp->cp_ebx) { 48382d2efdc6SVuong Nguyen uint_t coreid_shift = 0; 48392d2efdc6SVuong Nguyen uint_t chipid_shift = 0; 48402d2efdc6SVuong Nguyen uint_t i; 48412d2efdc6SVuong Nguyen uint_t level; 48422d2efdc6SVuong Nguyen 48432d2efdc6SVuong Nguyen for (i = 0; i < CPI_FNB_ECX_MAX; i++) { 48442d2efdc6SVuong Nguyen cp->cp_eax = 0xB; 48452d2efdc6SVuong Nguyen cp->cp_ecx = i; 48462d2efdc6SVuong Nguyen 48472d2efdc6SVuong Nguyen (void) __cpuid_insn(cp); 48482d2efdc6SVuong Nguyen level = CPI_CPU_LEVEL_TYPE(cp); 48492d2efdc6SVuong Nguyen 48502d2efdc6SVuong Nguyen if (level == 1) { 48512d2efdc6SVuong Nguyen /* 48522d2efdc6SVuong Nguyen * Thread level processor topology 48532d2efdc6SVuong Nguyen * Number of bits shift right APIC ID 48542d2efdc6SVuong Nguyen * to get the coreid. 48552d2efdc6SVuong Nguyen */ 48562d2efdc6SVuong Nguyen coreid_shift = BITX(cp->cp_eax, 4, 0); 48572d2efdc6SVuong Nguyen } else if (level == 2) { 48582d2efdc6SVuong Nguyen /* 48592d2efdc6SVuong Nguyen * Core level processor topology 48602d2efdc6SVuong Nguyen * Number of bits shift right APIC ID 48612d2efdc6SVuong Nguyen * to get the chipid. 48622d2efdc6SVuong Nguyen */ 48632d2efdc6SVuong Nguyen chipid_shift = BITX(cp->cp_eax, 4, 0); 48642d2efdc6SVuong Nguyen } 48652d2efdc6SVuong Nguyen } 48662d2efdc6SVuong Nguyen 48672d2efdc6SVuong Nguyen if (coreid_shift > 0 && chipid_shift > coreid_shift) { 48682d2efdc6SVuong Nguyen *strand_nbits = coreid_shift; 48692d2efdc6SVuong Nguyen *core_nbits = chipid_shift - coreid_shift; 48702d2efdc6SVuong Nguyen } 48712d2efdc6SVuong Nguyen } 48722d2efdc6SVuong Nguyen } 48732d2efdc6SVuong Nguyen } 4874