10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 51582Skchow * Common Development and Distribution License (the "License"). 61582Skchow * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 223434Sesaxe * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 270Sstevel@tonic-gate 280Sstevel@tonic-gate /* 290Sstevel@tonic-gate * Various routines to handle identification 300Sstevel@tonic-gate * and classification of x86 processors. 310Sstevel@tonic-gate */ 320Sstevel@tonic-gate 330Sstevel@tonic-gate #include <sys/types.h> 340Sstevel@tonic-gate #include <sys/archsystm.h> 350Sstevel@tonic-gate #include <sys/x86_archext.h> 360Sstevel@tonic-gate #include <sys/kmem.h> 370Sstevel@tonic-gate #include <sys/systm.h> 380Sstevel@tonic-gate #include <sys/cmn_err.h> 390Sstevel@tonic-gate #include <sys/sunddi.h> 400Sstevel@tonic-gate #include <sys/sunndi.h> 410Sstevel@tonic-gate #include <sys/cpuvar.h> 420Sstevel@tonic-gate #include <sys/processor.h> 433434Sesaxe #include <sys/pg.h> 440Sstevel@tonic-gate #include <sys/fp.h> 450Sstevel@tonic-gate #include <sys/controlregs.h> 460Sstevel@tonic-gate #include <sys/auxv_386.h> 470Sstevel@tonic-gate #include <sys/bitmap.h> 480Sstevel@tonic-gate #include <sys/memnode.h> 490Sstevel@tonic-gate 500Sstevel@tonic-gate /* 510Sstevel@tonic-gate * Pass 0 of cpuid feature analysis happens in locore. It contains special code 520Sstevel@tonic-gate * to recognize Cyrix processors that are not cpuid-compliant, and to deal with 530Sstevel@tonic-gate * them accordingly. For most modern processors, feature detection occurs here 540Sstevel@tonic-gate * in pass 1. 550Sstevel@tonic-gate * 560Sstevel@tonic-gate * Pass 1 of cpuid feature analysis happens just at the beginning of mlsetup() 570Sstevel@tonic-gate * for the boot CPU and does the basic analysis that the early kernel needs. 580Sstevel@tonic-gate * x86_feature is set based on the return value of cpuid_pass1() of the boot 590Sstevel@tonic-gate * CPU. 600Sstevel@tonic-gate * 610Sstevel@tonic-gate * Pass 1 includes: 620Sstevel@tonic-gate * 630Sstevel@tonic-gate * o Determining vendor/model/family/stepping and setting x86_type and 640Sstevel@tonic-gate * x86_vendor accordingly. 650Sstevel@tonic-gate * o Processing the feature flags returned by the cpuid instruction while 660Sstevel@tonic-gate * applying any workarounds or tricks for the specific processor. 670Sstevel@tonic-gate * o Mapping the feature flags into Solaris feature bits (X86_*). 680Sstevel@tonic-gate * o Processing extended feature flags if supported by the processor, 690Sstevel@tonic-gate * again while applying specific processor knowledge. 700Sstevel@tonic-gate * o Determining the CMT characteristics of the system. 710Sstevel@tonic-gate * 720Sstevel@tonic-gate * Pass 1 is done on non-boot CPUs during their initialization and the results 730Sstevel@tonic-gate * are used only as a meager attempt at ensuring that all processors within the 740Sstevel@tonic-gate * system support the same features. 750Sstevel@tonic-gate * 760Sstevel@tonic-gate * Pass 2 of cpuid feature analysis happens just at the beginning 770Sstevel@tonic-gate * of startup(). It just copies in and corrects the remainder 780Sstevel@tonic-gate * of the cpuid data we depend on: standard cpuid functions that we didn't 790Sstevel@tonic-gate * need for pass1 feature analysis, and extended cpuid functions beyond the 800Sstevel@tonic-gate * simple feature processing done in pass1. 810Sstevel@tonic-gate * 820Sstevel@tonic-gate * Pass 3 of cpuid analysis is invoked after basic kernel services; in 830Sstevel@tonic-gate * particular kernel memory allocation has been made available. It creates a 840Sstevel@tonic-gate * readable brand string based on the data collected in the first two passes. 850Sstevel@tonic-gate * 860Sstevel@tonic-gate * Pass 4 of cpuid analysis is invoked after post_startup() when all 870Sstevel@tonic-gate * the support infrastructure for various hardware features has been 880Sstevel@tonic-gate * initialized. It determines which processor features will be reported 890Sstevel@tonic-gate * to userland via the aux vector. 900Sstevel@tonic-gate * 910Sstevel@tonic-gate * All passes are executed on all CPUs, but only the boot CPU determines what 920Sstevel@tonic-gate * features the kernel will use. 930Sstevel@tonic-gate * 940Sstevel@tonic-gate * Much of the worst junk in this file is for the support of processors 950Sstevel@tonic-gate * that didn't really implement the cpuid instruction properly. 960Sstevel@tonic-gate * 970Sstevel@tonic-gate * NOTE: The accessor functions (cpuid_get*) are aware of, and ASSERT upon, 980Sstevel@tonic-gate * the pass numbers. Accordingly, changes to the pass code may require changes 990Sstevel@tonic-gate * to the accessor code. 1000Sstevel@tonic-gate */ 1010Sstevel@tonic-gate 1020Sstevel@tonic-gate uint_t x86_feature = 0; 1030Sstevel@tonic-gate uint_t x86_vendor = X86_VENDOR_IntelClone; 1040Sstevel@tonic-gate uint_t x86_type = X86_TYPE_OTHER; 1050Sstevel@tonic-gate 1060Sstevel@tonic-gate uint_t pentiumpro_bug4046376; 1070Sstevel@tonic-gate uint_t pentiumpro_bug4064495; 1080Sstevel@tonic-gate 1090Sstevel@tonic-gate uint_t enable486; 1100Sstevel@tonic-gate 1110Sstevel@tonic-gate /* 1120Sstevel@tonic-gate * This set of strings are for processors rumored to support the cpuid 1130Sstevel@tonic-gate * instruction, and is used by locore.s to figure out how to set x86_vendor 1140Sstevel@tonic-gate */ 1150Sstevel@tonic-gate const char CyrixInstead[] = "CyrixInstead"; 1160Sstevel@tonic-gate 1170Sstevel@tonic-gate /* 118*4481Sbholler * monitor/mwait info. 119*4481Sbholler */ 120*4481Sbholler struct mwait_info { 121*4481Sbholler size_t mon_min; /* min size to avoid missed wakeups */ 122*4481Sbholler size_t mon_max; /* size to avoid false wakeups */ 123*4481Sbholler uint32_t support; /* processor support of monitor/mwait */ 124*4481Sbholler }; 125*4481Sbholler 126*4481Sbholler /* 1270Sstevel@tonic-gate * These constants determine how many of the elements of the 1280Sstevel@tonic-gate * cpuid we cache in the cpuid_info data structure; the 1290Sstevel@tonic-gate * remaining elements are accessible via the cpuid instruction. 1300Sstevel@tonic-gate */ 1310Sstevel@tonic-gate 1320Sstevel@tonic-gate #define NMAX_CPI_STD 6 /* eax = 0 .. 5 */ 1330Sstevel@tonic-gate #define NMAX_CPI_EXTD 9 /* eax = 0x80000000 .. 0x80000008 */ 1340Sstevel@tonic-gate 1350Sstevel@tonic-gate struct cpuid_info { 1360Sstevel@tonic-gate uint_t cpi_pass; /* last pass completed */ 1370Sstevel@tonic-gate /* 1380Sstevel@tonic-gate * standard function information 1390Sstevel@tonic-gate */ 1400Sstevel@tonic-gate uint_t cpi_maxeax; /* fn 0: %eax */ 1410Sstevel@tonic-gate char cpi_vendorstr[13]; /* fn 0: %ebx:%ecx:%edx */ 1420Sstevel@tonic-gate uint_t cpi_vendor; /* enum of cpi_vendorstr */ 1430Sstevel@tonic-gate 1440Sstevel@tonic-gate uint_t cpi_family; /* fn 1: extended family */ 1450Sstevel@tonic-gate uint_t cpi_model; /* fn 1: extended model */ 1460Sstevel@tonic-gate uint_t cpi_step; /* fn 1: stepping */ 1470Sstevel@tonic-gate chipid_t cpi_chipid; /* fn 1: %ebx: chip # on ht cpus */ 1480Sstevel@tonic-gate uint_t cpi_brandid; /* fn 1: %ebx: brand ID */ 1490Sstevel@tonic-gate int cpi_clogid; /* fn 1: %ebx: thread # */ 1501228Sandrei uint_t cpi_ncpu_per_chip; /* fn 1: %ebx: logical cpu count */ 1510Sstevel@tonic-gate uint8_t cpi_cacheinfo[16]; /* fn 2: intel-style cache desc */ 1520Sstevel@tonic-gate uint_t cpi_ncache; /* fn 2: number of elements */ 1531228Sandrei struct cpuid_regs cpi_std[NMAX_CPI_STD]; /* 0 .. 5 */ 1540Sstevel@tonic-gate /* 1550Sstevel@tonic-gate * extended function information 1560Sstevel@tonic-gate */ 1570Sstevel@tonic-gate uint_t cpi_xmaxeax; /* fn 0x80000000: %eax */ 1580Sstevel@tonic-gate char cpi_brandstr[49]; /* fn 0x8000000[234] */ 1590Sstevel@tonic-gate uint8_t cpi_pabits; /* fn 0x80000006: %eax */ 1600Sstevel@tonic-gate uint8_t cpi_vabits; /* fn 0x80000006: %eax */ 1611228Sandrei struct cpuid_regs cpi_extd[NMAX_CPI_EXTD]; /* 0x8000000[0-8] */ 1621228Sandrei id_t cpi_coreid; 1631228Sandrei uint_t cpi_ncore_per_chip; /* AMD: fn 0x80000008: %ecx[7-0] */ 1641228Sandrei /* Intel: fn 4: %eax[31-26] */ 1650Sstevel@tonic-gate /* 1660Sstevel@tonic-gate * supported feature information 1670Sstevel@tonic-gate */ 1683446Smrj uint32_t cpi_support[5]; 1690Sstevel@tonic-gate #define STD_EDX_FEATURES 0 1700Sstevel@tonic-gate #define AMD_EDX_FEATURES 1 1710Sstevel@tonic-gate #define TM_EDX_FEATURES 2 1720Sstevel@tonic-gate #define STD_ECX_FEATURES 3 1733446Smrj #define AMD_ECX_FEATURES 4 1742869Sgavinm /* 1752869Sgavinm * Synthesized information, where known. 1762869Sgavinm */ 1772869Sgavinm uint32_t cpi_chiprev; /* See X86_CHIPREV_* in x86_archext.h */ 1782869Sgavinm const char *cpi_chiprevstr; /* May be NULL if chiprev unknown */ 1792869Sgavinm uint32_t cpi_socket; /* Chip package/socket type */ 180*4481Sbholler 181*4481Sbholler struct mwait_info cpi_mwait; /* fn 5: monitor/mwait info */ 1820Sstevel@tonic-gate }; 1830Sstevel@tonic-gate 1840Sstevel@tonic-gate 1850Sstevel@tonic-gate static struct cpuid_info cpuid_info0; 1860Sstevel@tonic-gate 1870Sstevel@tonic-gate /* 1880Sstevel@tonic-gate * These bit fields are defined by the Intel Application Note AP-485 1890Sstevel@tonic-gate * "Intel Processor Identification and the CPUID Instruction" 1900Sstevel@tonic-gate */ 1910Sstevel@tonic-gate #define CPI_FAMILY_XTD(cpi) BITX((cpi)->cpi_std[1].cp_eax, 27, 20) 1920Sstevel@tonic-gate #define CPI_MODEL_XTD(cpi) BITX((cpi)->cpi_std[1].cp_eax, 19, 16) 1930Sstevel@tonic-gate #define CPI_TYPE(cpi) BITX((cpi)->cpi_std[1].cp_eax, 13, 12) 1940Sstevel@tonic-gate #define CPI_FAMILY(cpi) BITX((cpi)->cpi_std[1].cp_eax, 11, 8) 1950Sstevel@tonic-gate #define CPI_STEP(cpi) BITX((cpi)->cpi_std[1].cp_eax, 3, 0) 1960Sstevel@tonic-gate #define CPI_MODEL(cpi) BITX((cpi)->cpi_std[1].cp_eax, 7, 4) 1970Sstevel@tonic-gate 1980Sstevel@tonic-gate #define CPI_FEATURES_EDX(cpi) ((cpi)->cpi_std[1].cp_edx) 1990Sstevel@tonic-gate #define CPI_FEATURES_ECX(cpi) ((cpi)->cpi_std[1].cp_ecx) 2000Sstevel@tonic-gate #define CPI_FEATURES_XTD_EDX(cpi) ((cpi)->cpi_extd[1].cp_edx) 2010Sstevel@tonic-gate #define CPI_FEATURES_XTD_ECX(cpi) ((cpi)->cpi_extd[1].cp_ecx) 2020Sstevel@tonic-gate 2030Sstevel@tonic-gate #define CPI_BRANDID(cpi) BITX((cpi)->cpi_std[1].cp_ebx, 7, 0) 2040Sstevel@tonic-gate #define CPI_CHUNKS(cpi) BITX((cpi)->cpi_std[1].cp_ebx, 15, 7) 2050Sstevel@tonic-gate #define CPI_CPU_COUNT(cpi) BITX((cpi)->cpi_std[1].cp_ebx, 23, 16) 2060Sstevel@tonic-gate #define CPI_APIC_ID(cpi) BITX((cpi)->cpi_std[1].cp_ebx, 31, 24) 2070Sstevel@tonic-gate 2080Sstevel@tonic-gate #define CPI_MAXEAX_MAX 0x100 /* sanity control */ 2090Sstevel@tonic-gate #define CPI_XMAXEAX_MAX 0x80000100 2100Sstevel@tonic-gate 2110Sstevel@tonic-gate /* 2121975Sdmick * A couple of shorthand macros to identify "later" P6-family chips 2131975Sdmick * like the Pentium M and Core. First, the "older" P6-based stuff 2141975Sdmick * (loosely defined as "pre-Pentium-4"): 2151975Sdmick * P6, PII, Mobile PII, PII Xeon, PIII, Mobile PIII, PIII Xeon 2161975Sdmick */ 2171975Sdmick 2181975Sdmick #define IS_LEGACY_P6(cpi) ( \ 2191975Sdmick cpi->cpi_family == 6 && \ 2201975Sdmick (cpi->cpi_model == 1 || \ 2211975Sdmick cpi->cpi_model == 3 || \ 2221975Sdmick cpi->cpi_model == 5 || \ 2231975Sdmick cpi->cpi_model == 6 || \ 2241975Sdmick cpi->cpi_model == 7 || \ 2251975Sdmick cpi->cpi_model == 8 || \ 2261975Sdmick cpi->cpi_model == 0xA || \ 2271975Sdmick cpi->cpi_model == 0xB) \ 2281975Sdmick ) 2291975Sdmick 2301975Sdmick /* A "new F6" is everything with family 6 that's not the above */ 2311975Sdmick #define IS_NEW_F6(cpi) ((cpi->cpi_family == 6) && !IS_LEGACY_P6(cpi)) 2321975Sdmick 2331975Sdmick /* 2342869Sgavinm * AMD family 0xf socket types. 2352869Sgavinm * First index is 0 for revs B thru E, 1 for F and G. 2362869Sgavinm * Second index by (model & 0x3) 2372869Sgavinm */ 2382869Sgavinm static uint32_t amd_skts[2][4] = { 2392869Sgavinm { 2402869Sgavinm X86_SOCKET_754, /* 0b00 */ 2412869Sgavinm X86_SOCKET_940, /* 0b01 */ 2422869Sgavinm X86_SOCKET_754, /* 0b10 */ 2432869Sgavinm X86_SOCKET_939 /* 0b11 */ 2442869Sgavinm }, 2452869Sgavinm { 2462869Sgavinm X86_SOCKET_S1g1, /* 0b00 */ 2472869Sgavinm X86_SOCKET_F1207, /* 0b01 */ 2482869Sgavinm X86_SOCKET_UNKNOWN, /* 0b10 */ 2492869Sgavinm X86_SOCKET_AM2 /* 0b11 */ 2502869Sgavinm } 2512869Sgavinm }; 2522869Sgavinm 2532869Sgavinm /* 2542869Sgavinm * Table for mapping AMD Family 0xf model/stepping combination to 2552869Sgavinm * chip "revision" and socket type. Only rm_family 0xf is used at the 2562869Sgavinm * moment, but AMD family 0x10 will extend the exsiting revision names 2572869Sgavinm * so will likely also use this table. 2582869Sgavinm * 2592869Sgavinm * The first member of this array that matches a given family, extended model 2602869Sgavinm * plus model range, and stepping range will be considered a match. 2612869Sgavinm */ 2622869Sgavinm static const struct amd_rev_mapent { 2632869Sgavinm uint_t rm_family; 2642869Sgavinm uint_t rm_modello; 2652869Sgavinm uint_t rm_modelhi; 2662869Sgavinm uint_t rm_steplo; 2672869Sgavinm uint_t rm_stephi; 2682869Sgavinm uint32_t rm_chiprev; 2692869Sgavinm const char *rm_chiprevstr; 2702869Sgavinm int rm_sktidx; 2712869Sgavinm } amd_revmap[] = { 2722869Sgavinm /* 2732869Sgavinm * Rev B includes model 0x4 stepping 0 and model 0x5 stepping 0 and 1. 2742869Sgavinm */ 2752869Sgavinm { 0xf, 0x04, 0x04, 0x0, 0x0, X86_CHIPREV_AMD_F_REV_B, "B", 0 }, 2762869Sgavinm { 0xf, 0x05, 0x05, 0x0, 0x1, X86_CHIPREV_AMD_F_REV_B, "B", 0 }, 2772869Sgavinm /* 2782869Sgavinm * Rev C0 includes model 0x4 stepping 8 and model 0x5 stepping 8 2792869Sgavinm */ 2802869Sgavinm { 0xf, 0x04, 0x05, 0x8, 0x8, X86_CHIPREV_AMD_F_REV_C0, "C0", 0 }, 2812869Sgavinm /* 2822869Sgavinm * Rev CG is the rest of extended model 0x0 - i.e., everything 2832869Sgavinm * but the rev B and C0 combinations covered above. 2842869Sgavinm */ 2852869Sgavinm { 0xf, 0x00, 0x0f, 0x0, 0xf, X86_CHIPREV_AMD_F_REV_CG, "CG", 0 }, 2862869Sgavinm /* 2872869Sgavinm * Rev D has extended model 0x1. 2882869Sgavinm */ 2892869Sgavinm { 0xf, 0x10, 0x1f, 0x0, 0xf, X86_CHIPREV_AMD_F_REV_D, "D", 0 }, 2902869Sgavinm /* 2912869Sgavinm * Rev E has extended model 0x2. 2922869Sgavinm * Extended model 0x3 is unused but available to grow into. 2932869Sgavinm */ 2942869Sgavinm { 0xf, 0x20, 0x3f, 0x0, 0xf, X86_CHIPREV_AMD_F_REV_E, "E", 0 }, 2952869Sgavinm /* 2962869Sgavinm * Rev F has extended models 0x4 and 0x5. 2972869Sgavinm */ 2982869Sgavinm { 0xf, 0x40, 0x5f, 0x0, 0xf, X86_CHIPREV_AMD_F_REV_F, "F", 1 }, 2992869Sgavinm /* 3002869Sgavinm * Rev G has extended model 0x6. 3012869Sgavinm */ 3022869Sgavinm { 0xf, 0x60, 0x6f, 0x0, 0xf, X86_CHIPREV_AMD_F_REV_G, "G", 1 }, 3032869Sgavinm }; 3042869Sgavinm 305*4481Sbholler /* 306*4481Sbholler * Info for monitor/mwait idle loop. 307*4481Sbholler * 308*4481Sbholler * See cpuid section of "Intel 64 and IA-32 Architectures Software Developer's 309*4481Sbholler * Manual Volume 2A: Instruction Set Reference, A-M" #25366-022US, November 310*4481Sbholler * 2006. 311*4481Sbholler * See MONITOR/MWAIT section of "AMD64 Architecture Programmer's Manual 312*4481Sbholler * Documentation Updates" #33633, Rev 2.05, December 2006. 313*4481Sbholler */ 314*4481Sbholler #define MWAIT_SUPPORT (0x00000001) /* mwait supported */ 315*4481Sbholler #define MWAIT_EXTENSIONS (0x00000002) /* extenstion supported */ 316*4481Sbholler #define MWAIT_ECX_INT_ENABLE (0x00000004) /* ecx 1 extension supported */ 317*4481Sbholler #define MWAIT_SUPPORTED(cpi) ((cpi)->cpi_std[1].cp_ecx & CPUID_INTC_ECX_MON) 318*4481Sbholler #define MWAIT_INT_ENABLE(cpi) ((cpi)->cpi_std[5].cp_ecx & 0x2) 319*4481Sbholler #define MWAIT_EXTENSION(cpi) ((cpi)->cpi_std[5].cp_ecx & 0x1) 320*4481Sbholler #define MWAIT_SIZE_MIN(cpi) BITX((cpi)->cpi_std[5].cp_eax, 15, 0) 321*4481Sbholler #define MWAIT_SIZE_MAX(cpi) BITX((cpi)->cpi_std[5].cp_ebx, 15, 0) 322*4481Sbholler /* 323*4481Sbholler * Number of sub-cstates for a given c-state. 324*4481Sbholler */ 325*4481Sbholler #define MWAIT_NUM_SUBC_STATES(cpi, c_state) \ 326*4481Sbholler BITX((cpi)->cpi_std[5].cp_edx, c_state + 3, c_state) 327*4481Sbholler 3282869Sgavinm static void 3292869Sgavinm synth_amd_info(struct cpuid_info *cpi) 3302869Sgavinm { 3312869Sgavinm const struct amd_rev_mapent *rmp; 3322869Sgavinm uint_t family, model, step; 3332869Sgavinm int i; 3342869Sgavinm 3352869Sgavinm /* 3362869Sgavinm * Currently only AMD family 0xf uses these fields. 3372869Sgavinm */ 3382869Sgavinm if (cpi->cpi_family != 0xf) 3392869Sgavinm return; 3402869Sgavinm 3412869Sgavinm family = cpi->cpi_family; 3422869Sgavinm model = cpi->cpi_model; 3432869Sgavinm step = cpi->cpi_step; 3442869Sgavinm 3452869Sgavinm for (i = 0, rmp = amd_revmap; i < sizeof (amd_revmap) / sizeof (*rmp); 3462869Sgavinm i++, rmp++) { 3472869Sgavinm if (family == rmp->rm_family && 3482869Sgavinm model >= rmp->rm_modello && model <= rmp->rm_modelhi && 3492869Sgavinm step >= rmp->rm_steplo && step <= rmp->rm_stephi) { 3502869Sgavinm cpi->cpi_chiprev = rmp->rm_chiprev; 3512869Sgavinm cpi->cpi_chiprevstr = rmp->rm_chiprevstr; 3522869Sgavinm cpi->cpi_socket = amd_skts[rmp->rm_sktidx][model & 0x3]; 3532869Sgavinm return; 3542869Sgavinm } 3552869Sgavinm } 3562869Sgavinm } 3572869Sgavinm 3582869Sgavinm static void 3592869Sgavinm synth_info(struct cpuid_info *cpi) 3602869Sgavinm { 3612869Sgavinm cpi->cpi_chiprev = X86_CHIPREV_UNKNOWN; 3622869Sgavinm cpi->cpi_chiprevstr = "Unknown"; 3632869Sgavinm cpi->cpi_socket = X86_SOCKET_UNKNOWN; 3642869Sgavinm 3652869Sgavinm switch (cpi->cpi_vendor) { 3662869Sgavinm case X86_VENDOR_AMD: 3672869Sgavinm synth_amd_info(cpi); 3682869Sgavinm break; 3692869Sgavinm 3702869Sgavinm default: 3712869Sgavinm break; 3722869Sgavinm 3732869Sgavinm } 3742869Sgavinm } 3752869Sgavinm 3762869Sgavinm /* 3773446Smrj * Apply up various platform-dependent restrictions where the 3783446Smrj * underlying platform restrictions mean the CPU can be marked 3793446Smrj * as less capable than its cpuid instruction would imply. 3803446Smrj */ 3813446Smrj 3823446Smrj #define platform_cpuid_mangle(vendor, eax, cp) /* nothing */ 3833446Smrj 3843446Smrj /* 3850Sstevel@tonic-gate * Some undocumented ways of patching the results of the cpuid 3860Sstevel@tonic-gate * instruction to permit running Solaris 10 on future cpus that 3870Sstevel@tonic-gate * we don't currently support. Could be set to non-zero values 3880Sstevel@tonic-gate * via settings in eeprom. 3890Sstevel@tonic-gate */ 3900Sstevel@tonic-gate 3910Sstevel@tonic-gate uint32_t cpuid_feature_ecx_include; 3920Sstevel@tonic-gate uint32_t cpuid_feature_ecx_exclude; 3930Sstevel@tonic-gate uint32_t cpuid_feature_edx_include; 3940Sstevel@tonic-gate uint32_t cpuid_feature_edx_exclude; 3950Sstevel@tonic-gate 3963446Smrj void 3973446Smrj cpuid_alloc_space(cpu_t *cpu) 3983446Smrj { 3993446Smrj /* 4003446Smrj * By convention, cpu0 is the boot cpu, which is set up 4013446Smrj * before memory allocation is available. All other cpus get 4023446Smrj * their cpuid_info struct allocated here. 4033446Smrj */ 4043446Smrj ASSERT(cpu->cpu_id != 0); 4053446Smrj cpu->cpu_m.mcpu_cpi = 4063446Smrj kmem_zalloc(sizeof (*cpu->cpu_m.mcpu_cpi), KM_SLEEP); 4073446Smrj } 4083446Smrj 4093446Smrj void 4103446Smrj cpuid_free_space(cpu_t *cpu) 4113446Smrj { 4123446Smrj ASSERT(cpu->cpu_id != 0); 4133446Smrj kmem_free(cpu->cpu_m.mcpu_cpi, sizeof (*cpu->cpu_m.mcpu_cpi)); 4143446Smrj } 4153446Smrj 4160Sstevel@tonic-gate uint_t 4170Sstevel@tonic-gate cpuid_pass1(cpu_t *cpu) 4180Sstevel@tonic-gate { 4190Sstevel@tonic-gate uint32_t mask_ecx, mask_edx; 4200Sstevel@tonic-gate uint_t feature = X86_CPUID; 4210Sstevel@tonic-gate struct cpuid_info *cpi; 4221228Sandrei struct cpuid_regs *cp; 4230Sstevel@tonic-gate int xcpuid; 4240Sstevel@tonic-gate 4253446Smrj 4260Sstevel@tonic-gate /* 4273446Smrj * Space statically allocated for cpu0, ensure pointer is set 4280Sstevel@tonic-gate */ 4290Sstevel@tonic-gate if (cpu->cpu_id == 0) 4303446Smrj cpu->cpu_m.mcpu_cpi = &cpuid_info0; 4313446Smrj cpi = cpu->cpu_m.mcpu_cpi; 4323446Smrj ASSERT(cpi != NULL); 4330Sstevel@tonic-gate cp = &cpi->cpi_std[0]; 4341228Sandrei cp->cp_eax = 0; 4351228Sandrei cpi->cpi_maxeax = __cpuid_insn(cp); 4360Sstevel@tonic-gate { 4370Sstevel@tonic-gate uint32_t *iptr = (uint32_t *)cpi->cpi_vendorstr; 4380Sstevel@tonic-gate *iptr++ = cp->cp_ebx; 4390Sstevel@tonic-gate *iptr++ = cp->cp_edx; 4400Sstevel@tonic-gate *iptr++ = cp->cp_ecx; 4410Sstevel@tonic-gate *(char *)&cpi->cpi_vendorstr[12] = '\0'; 4420Sstevel@tonic-gate } 4430Sstevel@tonic-gate 4440Sstevel@tonic-gate /* 4450Sstevel@tonic-gate * Map the vendor string to a type code 4460Sstevel@tonic-gate */ 4470Sstevel@tonic-gate if (strcmp(cpi->cpi_vendorstr, "GenuineIntel") == 0) 4480Sstevel@tonic-gate cpi->cpi_vendor = X86_VENDOR_Intel; 4490Sstevel@tonic-gate else if (strcmp(cpi->cpi_vendorstr, "AuthenticAMD") == 0) 4500Sstevel@tonic-gate cpi->cpi_vendor = X86_VENDOR_AMD; 4510Sstevel@tonic-gate else if (strcmp(cpi->cpi_vendorstr, "GenuineTMx86") == 0) 4520Sstevel@tonic-gate cpi->cpi_vendor = X86_VENDOR_TM; 4530Sstevel@tonic-gate else if (strcmp(cpi->cpi_vendorstr, CyrixInstead) == 0) 4540Sstevel@tonic-gate /* 4550Sstevel@tonic-gate * CyrixInstead is a variable used by the Cyrix detection code 4560Sstevel@tonic-gate * in locore. 4570Sstevel@tonic-gate */ 4580Sstevel@tonic-gate cpi->cpi_vendor = X86_VENDOR_Cyrix; 4590Sstevel@tonic-gate else if (strcmp(cpi->cpi_vendorstr, "UMC UMC UMC ") == 0) 4600Sstevel@tonic-gate cpi->cpi_vendor = X86_VENDOR_UMC; 4610Sstevel@tonic-gate else if (strcmp(cpi->cpi_vendorstr, "NexGenDriven") == 0) 4620Sstevel@tonic-gate cpi->cpi_vendor = X86_VENDOR_NexGen; 4630Sstevel@tonic-gate else if (strcmp(cpi->cpi_vendorstr, "CentaurHauls") == 0) 4640Sstevel@tonic-gate cpi->cpi_vendor = X86_VENDOR_Centaur; 4650Sstevel@tonic-gate else if (strcmp(cpi->cpi_vendorstr, "RiseRiseRise") == 0) 4660Sstevel@tonic-gate cpi->cpi_vendor = X86_VENDOR_Rise; 4670Sstevel@tonic-gate else if (strcmp(cpi->cpi_vendorstr, "SiS SiS SiS ") == 0) 4680Sstevel@tonic-gate cpi->cpi_vendor = X86_VENDOR_SiS; 4690Sstevel@tonic-gate else if (strcmp(cpi->cpi_vendorstr, "Geode by NSC") == 0) 4700Sstevel@tonic-gate cpi->cpi_vendor = X86_VENDOR_NSC; 4710Sstevel@tonic-gate else 4720Sstevel@tonic-gate cpi->cpi_vendor = X86_VENDOR_IntelClone; 4730Sstevel@tonic-gate 4740Sstevel@tonic-gate x86_vendor = cpi->cpi_vendor; /* for compatibility */ 4750Sstevel@tonic-gate 4760Sstevel@tonic-gate /* 4770Sstevel@tonic-gate * Limit the range in case of weird hardware 4780Sstevel@tonic-gate */ 4790Sstevel@tonic-gate if (cpi->cpi_maxeax > CPI_MAXEAX_MAX) 4800Sstevel@tonic-gate cpi->cpi_maxeax = CPI_MAXEAX_MAX; 4810Sstevel@tonic-gate if (cpi->cpi_maxeax < 1) 4820Sstevel@tonic-gate goto pass1_done; 4830Sstevel@tonic-gate 4840Sstevel@tonic-gate cp = &cpi->cpi_std[1]; 4851228Sandrei cp->cp_eax = 1; 4861228Sandrei (void) __cpuid_insn(cp); 4870Sstevel@tonic-gate 4880Sstevel@tonic-gate /* 4890Sstevel@tonic-gate * Extract identifying constants for easy access. 4900Sstevel@tonic-gate */ 4910Sstevel@tonic-gate cpi->cpi_model = CPI_MODEL(cpi); 4920Sstevel@tonic-gate cpi->cpi_family = CPI_FAMILY(cpi); 4930Sstevel@tonic-gate 4941975Sdmick if (cpi->cpi_family == 0xf) 4950Sstevel@tonic-gate cpi->cpi_family += CPI_FAMILY_XTD(cpi); 4961975Sdmick 4972001Sdmick /* 4984265Skchow * Beware: AMD uses "extended model" iff base *FAMILY* == 0xf. 4992001Sdmick * Intel, and presumably everyone else, uses model == 0xf, as 5002001Sdmick * one would expect (max value means possible overflow). Sigh. 5012001Sdmick */ 5022001Sdmick 5032001Sdmick switch (cpi->cpi_vendor) { 5042001Sdmick case X86_VENDOR_AMD: 5054265Skchow if (CPI_FAMILY(cpi) == 0xf) 5062001Sdmick cpi->cpi_model += CPI_MODEL_XTD(cpi) << 4; 5072001Sdmick break; 5082001Sdmick default: 5092001Sdmick if (cpi->cpi_model == 0xf) 5102001Sdmick cpi->cpi_model += CPI_MODEL_XTD(cpi) << 4; 5112001Sdmick break; 5122001Sdmick } 5130Sstevel@tonic-gate 5140Sstevel@tonic-gate cpi->cpi_step = CPI_STEP(cpi); 5150Sstevel@tonic-gate cpi->cpi_brandid = CPI_BRANDID(cpi); 5160Sstevel@tonic-gate 5170Sstevel@tonic-gate /* 5180Sstevel@tonic-gate * *default* assumptions: 5190Sstevel@tonic-gate * - believe %edx feature word 5200Sstevel@tonic-gate * - ignore %ecx feature word 5210Sstevel@tonic-gate * - 32-bit virtual and physical addressing 5220Sstevel@tonic-gate */ 5230Sstevel@tonic-gate mask_edx = 0xffffffff; 5240Sstevel@tonic-gate mask_ecx = 0; 5250Sstevel@tonic-gate 5260Sstevel@tonic-gate cpi->cpi_pabits = cpi->cpi_vabits = 32; 5270Sstevel@tonic-gate 5280Sstevel@tonic-gate switch (cpi->cpi_vendor) { 5290Sstevel@tonic-gate case X86_VENDOR_Intel: 5300Sstevel@tonic-gate if (cpi->cpi_family == 5) 5310Sstevel@tonic-gate x86_type = X86_TYPE_P5; 5321975Sdmick else if (IS_LEGACY_P6(cpi)) { 5330Sstevel@tonic-gate x86_type = X86_TYPE_P6; 5340Sstevel@tonic-gate pentiumpro_bug4046376 = 1; 5350Sstevel@tonic-gate pentiumpro_bug4064495 = 1; 5360Sstevel@tonic-gate /* 5370Sstevel@tonic-gate * Clear the SEP bit when it was set erroneously 5380Sstevel@tonic-gate */ 5390Sstevel@tonic-gate if (cpi->cpi_model < 3 && cpi->cpi_step < 3) 5400Sstevel@tonic-gate cp->cp_edx &= ~CPUID_INTC_EDX_SEP; 5411975Sdmick } else if (IS_NEW_F6(cpi) || cpi->cpi_family == 0xf) { 5420Sstevel@tonic-gate x86_type = X86_TYPE_P4; 5430Sstevel@tonic-gate /* 5440Sstevel@tonic-gate * We don't currently depend on any of the %ecx 5450Sstevel@tonic-gate * features until Prescott, so we'll only check 5460Sstevel@tonic-gate * this from P4 onwards. We might want to revisit 5470Sstevel@tonic-gate * that idea later. 5480Sstevel@tonic-gate */ 5490Sstevel@tonic-gate mask_ecx = 0xffffffff; 5500Sstevel@tonic-gate } else if (cpi->cpi_family > 0xf) 5510Sstevel@tonic-gate mask_ecx = 0xffffffff; 5520Sstevel@tonic-gate break; 5530Sstevel@tonic-gate case X86_VENDOR_IntelClone: 5540Sstevel@tonic-gate default: 5550Sstevel@tonic-gate break; 5560Sstevel@tonic-gate case X86_VENDOR_AMD: 5570Sstevel@tonic-gate #if defined(OPTERON_ERRATUM_108) 5580Sstevel@tonic-gate if (cpi->cpi_family == 0xf && cpi->cpi_model == 0xe) { 5590Sstevel@tonic-gate cp->cp_eax = (0xf0f & cp->cp_eax) | 0xc0; 5600Sstevel@tonic-gate cpi->cpi_model = 0xc; 5610Sstevel@tonic-gate } else 5620Sstevel@tonic-gate #endif 5630Sstevel@tonic-gate if (cpi->cpi_family == 5) { 5640Sstevel@tonic-gate /* 5650Sstevel@tonic-gate * AMD K5 and K6 5660Sstevel@tonic-gate * 5670Sstevel@tonic-gate * These CPUs have an incomplete implementation 5680Sstevel@tonic-gate * of MCA/MCE which we mask away. 5690Sstevel@tonic-gate */ 5701228Sandrei mask_edx &= ~(CPUID_INTC_EDX_MCE | CPUID_INTC_EDX_MCA); 5711228Sandrei 5721228Sandrei /* 5731228Sandrei * Model 0 uses the wrong (APIC) bit 5741228Sandrei * to indicate PGE. Fix it here. 5751228Sandrei */ 5760Sstevel@tonic-gate if (cpi->cpi_model == 0) { 5770Sstevel@tonic-gate if (cp->cp_edx & 0x200) { 5780Sstevel@tonic-gate cp->cp_edx &= ~0x200; 5790Sstevel@tonic-gate cp->cp_edx |= CPUID_INTC_EDX_PGE; 5800Sstevel@tonic-gate } 5811228Sandrei } 5821228Sandrei 5831228Sandrei /* 5841228Sandrei * Early models had problems w/ MMX; disable. 5851228Sandrei */ 5861228Sandrei if (cpi->cpi_model < 6) 5871228Sandrei mask_edx &= ~CPUID_INTC_EDX_MMX; 5881228Sandrei } 5891228Sandrei 5901228Sandrei /* 5911228Sandrei * For newer families, SSE3 and CX16, at least, are valid; 5921228Sandrei * enable all 5931228Sandrei */ 5941228Sandrei if (cpi->cpi_family >= 0xf) 595771Sdmick mask_ecx = 0xffffffff; 5960Sstevel@tonic-gate break; 5970Sstevel@tonic-gate case X86_VENDOR_TM: 5980Sstevel@tonic-gate /* 5990Sstevel@tonic-gate * workaround the NT workaround in CMS 4.1 6000Sstevel@tonic-gate */ 6010Sstevel@tonic-gate if (cpi->cpi_family == 5 && cpi->cpi_model == 4 && 6020Sstevel@tonic-gate (cpi->cpi_step == 2 || cpi->cpi_step == 3)) 6030Sstevel@tonic-gate cp->cp_edx |= CPUID_INTC_EDX_CX8; 6040Sstevel@tonic-gate break; 6050Sstevel@tonic-gate case X86_VENDOR_Centaur: 6060Sstevel@tonic-gate /* 6070Sstevel@tonic-gate * workaround the NT workarounds again 6080Sstevel@tonic-gate */ 6090Sstevel@tonic-gate if (cpi->cpi_family == 6) 6100Sstevel@tonic-gate cp->cp_edx |= CPUID_INTC_EDX_CX8; 6110Sstevel@tonic-gate break; 6120Sstevel@tonic-gate case X86_VENDOR_Cyrix: 6130Sstevel@tonic-gate /* 6140Sstevel@tonic-gate * We rely heavily on the probing in locore 6150Sstevel@tonic-gate * to actually figure out what parts, if any, 6160Sstevel@tonic-gate * of the Cyrix cpuid instruction to believe. 6170Sstevel@tonic-gate */ 6180Sstevel@tonic-gate switch (x86_type) { 6190Sstevel@tonic-gate case X86_TYPE_CYRIX_486: 6200Sstevel@tonic-gate mask_edx = 0; 6210Sstevel@tonic-gate break; 6220Sstevel@tonic-gate case X86_TYPE_CYRIX_6x86: 6230Sstevel@tonic-gate mask_edx = 0; 6240Sstevel@tonic-gate break; 6250Sstevel@tonic-gate case X86_TYPE_CYRIX_6x86L: 6260Sstevel@tonic-gate mask_edx = 6270Sstevel@tonic-gate CPUID_INTC_EDX_DE | 6280Sstevel@tonic-gate CPUID_INTC_EDX_CX8; 6290Sstevel@tonic-gate break; 6300Sstevel@tonic-gate case X86_TYPE_CYRIX_6x86MX: 6310Sstevel@tonic-gate mask_edx = 6320Sstevel@tonic-gate CPUID_INTC_EDX_DE | 6330Sstevel@tonic-gate CPUID_INTC_EDX_MSR | 6340Sstevel@tonic-gate CPUID_INTC_EDX_CX8 | 6350Sstevel@tonic-gate CPUID_INTC_EDX_PGE | 6360Sstevel@tonic-gate CPUID_INTC_EDX_CMOV | 6370Sstevel@tonic-gate CPUID_INTC_EDX_MMX; 6380Sstevel@tonic-gate break; 6390Sstevel@tonic-gate case X86_TYPE_CYRIX_GXm: 6400Sstevel@tonic-gate mask_edx = 6410Sstevel@tonic-gate CPUID_INTC_EDX_MSR | 6420Sstevel@tonic-gate CPUID_INTC_EDX_CX8 | 6430Sstevel@tonic-gate CPUID_INTC_EDX_CMOV | 6440Sstevel@tonic-gate CPUID_INTC_EDX_MMX; 6450Sstevel@tonic-gate break; 6460Sstevel@tonic-gate case X86_TYPE_CYRIX_MediaGX: 6470Sstevel@tonic-gate break; 6480Sstevel@tonic-gate case X86_TYPE_CYRIX_MII: 6490Sstevel@tonic-gate case X86_TYPE_VIA_CYRIX_III: 6500Sstevel@tonic-gate mask_edx = 6510Sstevel@tonic-gate CPUID_INTC_EDX_DE | 6520Sstevel@tonic-gate CPUID_INTC_EDX_TSC | 6530Sstevel@tonic-gate CPUID_INTC_EDX_MSR | 6540Sstevel@tonic-gate CPUID_INTC_EDX_CX8 | 6550Sstevel@tonic-gate CPUID_INTC_EDX_PGE | 6560Sstevel@tonic-gate CPUID_INTC_EDX_CMOV | 6570Sstevel@tonic-gate CPUID_INTC_EDX_MMX; 6580Sstevel@tonic-gate break; 6590Sstevel@tonic-gate default: 6600Sstevel@tonic-gate break; 6610Sstevel@tonic-gate } 6620Sstevel@tonic-gate break; 6630Sstevel@tonic-gate } 6640Sstevel@tonic-gate 6650Sstevel@tonic-gate /* 6660Sstevel@tonic-gate * Now we've figured out the masks that determine 6670Sstevel@tonic-gate * which bits we choose to believe, apply the masks 6680Sstevel@tonic-gate * to the feature words, then map the kernel's view 6690Sstevel@tonic-gate * of these feature words into its feature word. 6700Sstevel@tonic-gate */ 6710Sstevel@tonic-gate cp->cp_edx &= mask_edx; 6720Sstevel@tonic-gate cp->cp_ecx &= mask_ecx; 6730Sstevel@tonic-gate 6740Sstevel@tonic-gate /* 6753446Smrj * apply any platform restrictions (we don't call this 6763446Smrj * immediately after __cpuid_insn here, because we need the 6773446Smrj * workarounds applied above first) 6780Sstevel@tonic-gate */ 6793446Smrj platform_cpuid_mangle(cpi->cpi_vendor, 1, cp); 6800Sstevel@tonic-gate 6813446Smrj /* 6823446Smrj * fold in overrides from the "eeprom" mechanism 6833446Smrj */ 6840Sstevel@tonic-gate cp->cp_edx |= cpuid_feature_edx_include; 6850Sstevel@tonic-gate cp->cp_edx &= ~cpuid_feature_edx_exclude; 6860Sstevel@tonic-gate 6870Sstevel@tonic-gate cp->cp_ecx |= cpuid_feature_ecx_include; 6880Sstevel@tonic-gate cp->cp_ecx &= ~cpuid_feature_ecx_exclude; 6890Sstevel@tonic-gate 6900Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_PSE) 6910Sstevel@tonic-gate feature |= X86_LARGEPAGE; 6920Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_TSC) 6930Sstevel@tonic-gate feature |= X86_TSC; 6940Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_MSR) 6950Sstevel@tonic-gate feature |= X86_MSR; 6960Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_MTRR) 6970Sstevel@tonic-gate feature |= X86_MTRR; 6980Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_PGE) 6990Sstevel@tonic-gate feature |= X86_PGE; 7000Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_CMOV) 7010Sstevel@tonic-gate feature |= X86_CMOV; 7020Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_MMX) 7030Sstevel@tonic-gate feature |= X86_MMX; 7040Sstevel@tonic-gate if ((cp->cp_edx & CPUID_INTC_EDX_MCE) != 0 && 7050Sstevel@tonic-gate (cp->cp_edx & CPUID_INTC_EDX_MCA) != 0) 7060Sstevel@tonic-gate feature |= X86_MCA; 7070Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_PAE) 7080Sstevel@tonic-gate feature |= X86_PAE; 7090Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_CX8) 7100Sstevel@tonic-gate feature |= X86_CX8; 7110Sstevel@tonic-gate if (cp->cp_ecx & CPUID_INTC_ECX_CX16) 7120Sstevel@tonic-gate feature |= X86_CX16; 7130Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_PAT) 7140Sstevel@tonic-gate feature |= X86_PAT; 7150Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_SEP) 7160Sstevel@tonic-gate feature |= X86_SEP; 7170Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_FXSR) { 7180Sstevel@tonic-gate /* 7190Sstevel@tonic-gate * In our implementation, fxsave/fxrstor 7200Sstevel@tonic-gate * are prerequisites before we'll even 7210Sstevel@tonic-gate * try and do SSE things. 7220Sstevel@tonic-gate */ 7230Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_SSE) 7240Sstevel@tonic-gate feature |= X86_SSE; 7250Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_SSE2) 7260Sstevel@tonic-gate feature |= X86_SSE2; 7270Sstevel@tonic-gate if (cp->cp_ecx & CPUID_INTC_ECX_SSE3) 7280Sstevel@tonic-gate feature |= X86_SSE3; 7290Sstevel@tonic-gate } 7300Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_DE) 7313446Smrj feature |= X86_DE; 732*4481Sbholler if (cp->cp_ecx & CPUID_INTC_ECX_MON) { 733*4481Sbholler cpi->cpi_mwait.support |= MWAIT_SUPPORT; 734*4481Sbholler feature |= X86_MWAIT; 735*4481Sbholler } 7360Sstevel@tonic-gate 7370Sstevel@tonic-gate if (feature & X86_PAE) 7380Sstevel@tonic-gate cpi->cpi_pabits = 36; 7390Sstevel@tonic-gate 7400Sstevel@tonic-gate /* 7410Sstevel@tonic-gate * Hyperthreading configuration is slightly tricky on Intel 7420Sstevel@tonic-gate * and pure clones, and even trickier on AMD. 7430Sstevel@tonic-gate * 7440Sstevel@tonic-gate * (AMD chose to set the HTT bit on their CMP processors, 7450Sstevel@tonic-gate * even though they're not actually hyperthreaded. Thus it 7460Sstevel@tonic-gate * takes a bit more work to figure out what's really going 7473446Smrj * on ... see the handling of the CMP_LGCY bit below) 7480Sstevel@tonic-gate */ 7490Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_HTT) { 7500Sstevel@tonic-gate cpi->cpi_ncpu_per_chip = CPI_CPU_COUNT(cpi); 7510Sstevel@tonic-gate if (cpi->cpi_ncpu_per_chip > 1) 7520Sstevel@tonic-gate feature |= X86_HTT; 7531228Sandrei } else { 7541228Sandrei cpi->cpi_ncpu_per_chip = 1; 7550Sstevel@tonic-gate } 7560Sstevel@tonic-gate 7570Sstevel@tonic-gate /* 7580Sstevel@tonic-gate * Work on the "extended" feature information, doing 7590Sstevel@tonic-gate * some basic initialization for cpuid_pass2() 7600Sstevel@tonic-gate */ 7610Sstevel@tonic-gate xcpuid = 0; 7620Sstevel@tonic-gate switch (cpi->cpi_vendor) { 7630Sstevel@tonic-gate case X86_VENDOR_Intel: 7641975Sdmick if (IS_NEW_F6(cpi) || cpi->cpi_family >= 0xf) 7650Sstevel@tonic-gate xcpuid++; 7660Sstevel@tonic-gate break; 7670Sstevel@tonic-gate case X86_VENDOR_AMD: 7680Sstevel@tonic-gate if (cpi->cpi_family > 5 || 7690Sstevel@tonic-gate (cpi->cpi_family == 5 && cpi->cpi_model >= 1)) 7700Sstevel@tonic-gate xcpuid++; 7710Sstevel@tonic-gate break; 7720Sstevel@tonic-gate case X86_VENDOR_Cyrix: 7730Sstevel@tonic-gate /* 7740Sstevel@tonic-gate * Only these Cyrix CPUs are -known- to support 7750Sstevel@tonic-gate * extended cpuid operations. 7760Sstevel@tonic-gate */ 7770Sstevel@tonic-gate if (x86_type == X86_TYPE_VIA_CYRIX_III || 7780Sstevel@tonic-gate x86_type == X86_TYPE_CYRIX_GXm) 7790Sstevel@tonic-gate xcpuid++; 7800Sstevel@tonic-gate break; 7810Sstevel@tonic-gate case X86_VENDOR_Centaur: 7820Sstevel@tonic-gate case X86_VENDOR_TM: 7830Sstevel@tonic-gate default: 7840Sstevel@tonic-gate xcpuid++; 7850Sstevel@tonic-gate break; 7860Sstevel@tonic-gate } 7870Sstevel@tonic-gate 7880Sstevel@tonic-gate if (xcpuid) { 7890Sstevel@tonic-gate cp = &cpi->cpi_extd[0]; 7901228Sandrei cp->cp_eax = 0x80000000; 7911228Sandrei cpi->cpi_xmaxeax = __cpuid_insn(cp); 7920Sstevel@tonic-gate } 7930Sstevel@tonic-gate 7940Sstevel@tonic-gate if (cpi->cpi_xmaxeax & 0x80000000) { 7950Sstevel@tonic-gate 7960Sstevel@tonic-gate if (cpi->cpi_xmaxeax > CPI_XMAXEAX_MAX) 7970Sstevel@tonic-gate cpi->cpi_xmaxeax = CPI_XMAXEAX_MAX; 7980Sstevel@tonic-gate 7990Sstevel@tonic-gate switch (cpi->cpi_vendor) { 8000Sstevel@tonic-gate case X86_VENDOR_Intel: 8010Sstevel@tonic-gate case X86_VENDOR_AMD: 8020Sstevel@tonic-gate if (cpi->cpi_xmaxeax < 0x80000001) 8030Sstevel@tonic-gate break; 8040Sstevel@tonic-gate cp = &cpi->cpi_extd[1]; 8051228Sandrei cp->cp_eax = 0x80000001; 8061228Sandrei (void) __cpuid_insn(cp); 8073446Smrj 8080Sstevel@tonic-gate if (cpi->cpi_vendor == X86_VENDOR_AMD && 8090Sstevel@tonic-gate cpi->cpi_family == 5 && 8100Sstevel@tonic-gate cpi->cpi_model == 6 && 8110Sstevel@tonic-gate cpi->cpi_step == 6) { 8120Sstevel@tonic-gate /* 8130Sstevel@tonic-gate * K6 model 6 uses bit 10 to indicate SYSC 8140Sstevel@tonic-gate * Later models use bit 11. Fix it here. 8150Sstevel@tonic-gate */ 8160Sstevel@tonic-gate if (cp->cp_edx & 0x400) { 8170Sstevel@tonic-gate cp->cp_edx &= ~0x400; 8180Sstevel@tonic-gate cp->cp_edx |= CPUID_AMD_EDX_SYSC; 8190Sstevel@tonic-gate } 8200Sstevel@tonic-gate } 8210Sstevel@tonic-gate 8223446Smrj platform_cpuid_mangle(cpi->cpi_vendor, 0x80000001, cp); 8233446Smrj 8240Sstevel@tonic-gate /* 8250Sstevel@tonic-gate * Compute the additions to the kernel's feature word. 8260Sstevel@tonic-gate */ 8270Sstevel@tonic-gate if (cp->cp_edx & CPUID_AMD_EDX_NX) 8280Sstevel@tonic-gate feature |= X86_NX; 8290Sstevel@tonic-gate 8300Sstevel@tonic-gate /* 8313446Smrj * If both the HTT and CMP_LGCY bits are set, 8321228Sandrei * then we're not actually HyperThreaded. Read 8331228Sandrei * "AMD CPUID Specification" for more details. 8340Sstevel@tonic-gate */ 8350Sstevel@tonic-gate if (cpi->cpi_vendor == X86_VENDOR_AMD && 8361228Sandrei (feature & X86_HTT) && 8373446Smrj (cp->cp_ecx & CPUID_AMD_ECX_CMP_LGCY)) { 8380Sstevel@tonic-gate feature &= ~X86_HTT; 8391228Sandrei feature |= X86_CMP; 8401228Sandrei } 8413446Smrj #if defined(__amd64) 8420Sstevel@tonic-gate /* 8430Sstevel@tonic-gate * It's really tricky to support syscall/sysret in 8440Sstevel@tonic-gate * the i386 kernel; we rely on sysenter/sysexit 8450Sstevel@tonic-gate * instead. In the amd64 kernel, things are -way- 8460Sstevel@tonic-gate * better. 8470Sstevel@tonic-gate */ 8480Sstevel@tonic-gate if (cp->cp_edx & CPUID_AMD_EDX_SYSC) 8490Sstevel@tonic-gate feature |= X86_ASYSC; 8500Sstevel@tonic-gate 8510Sstevel@tonic-gate /* 8520Sstevel@tonic-gate * While we're thinking about system calls, note 8530Sstevel@tonic-gate * that AMD processors don't support sysenter 8540Sstevel@tonic-gate * in long mode at all, so don't try to program them. 8550Sstevel@tonic-gate */ 8560Sstevel@tonic-gate if (x86_vendor == X86_VENDOR_AMD) 8570Sstevel@tonic-gate feature &= ~X86_SEP; 8580Sstevel@tonic-gate #endif 8593446Smrj if (cp->cp_edx & CPUID_AMD_EDX_TSCP) 8603446Smrj feature |= X86_TSCP; 8610Sstevel@tonic-gate break; 8620Sstevel@tonic-gate default: 8630Sstevel@tonic-gate break; 8640Sstevel@tonic-gate } 8650Sstevel@tonic-gate 8661228Sandrei /* 8671228Sandrei * Get CPUID data about processor cores and hyperthreads. 8681228Sandrei */ 8690Sstevel@tonic-gate switch (cpi->cpi_vendor) { 8700Sstevel@tonic-gate case X86_VENDOR_Intel: 8711228Sandrei if (cpi->cpi_maxeax >= 4) { 8721228Sandrei cp = &cpi->cpi_std[4]; 8731228Sandrei cp->cp_eax = 4; 8741228Sandrei cp->cp_ecx = 0; 8751228Sandrei (void) __cpuid_insn(cp); 8763446Smrj platform_cpuid_mangle(cpi->cpi_vendor, 4, cp); 8771228Sandrei } 8781228Sandrei /*FALLTHROUGH*/ 8790Sstevel@tonic-gate case X86_VENDOR_AMD: 8800Sstevel@tonic-gate if (cpi->cpi_xmaxeax < 0x80000008) 8810Sstevel@tonic-gate break; 8820Sstevel@tonic-gate cp = &cpi->cpi_extd[8]; 8831228Sandrei cp->cp_eax = 0x80000008; 8841228Sandrei (void) __cpuid_insn(cp); 8853446Smrj platform_cpuid_mangle(cpi->cpi_vendor, 0x80000008, cp); 8863446Smrj 8870Sstevel@tonic-gate /* 8880Sstevel@tonic-gate * Virtual and physical address limits from 8890Sstevel@tonic-gate * cpuid override previously guessed values. 8900Sstevel@tonic-gate */ 8910Sstevel@tonic-gate cpi->cpi_pabits = BITX(cp->cp_eax, 7, 0); 8920Sstevel@tonic-gate cpi->cpi_vabits = BITX(cp->cp_eax, 15, 8); 8930Sstevel@tonic-gate break; 8940Sstevel@tonic-gate default: 8950Sstevel@tonic-gate break; 8960Sstevel@tonic-gate } 8971228Sandrei 8981228Sandrei switch (cpi->cpi_vendor) { 8991228Sandrei case X86_VENDOR_Intel: 9001228Sandrei if (cpi->cpi_maxeax < 4) { 9011228Sandrei cpi->cpi_ncore_per_chip = 1; 9021228Sandrei break; 9031228Sandrei } else { 9041228Sandrei cpi->cpi_ncore_per_chip = 9051228Sandrei BITX((cpi)->cpi_std[4].cp_eax, 31, 26) + 1; 9061228Sandrei } 9071228Sandrei break; 9081228Sandrei case X86_VENDOR_AMD: 9091228Sandrei if (cpi->cpi_xmaxeax < 0x80000008) { 9101228Sandrei cpi->cpi_ncore_per_chip = 1; 9111228Sandrei break; 9121228Sandrei } else { 9131228Sandrei cpi->cpi_ncore_per_chip = 9141228Sandrei BITX((cpi)->cpi_extd[8].cp_ecx, 7, 0) + 1; 9151228Sandrei } 9161228Sandrei break; 9171228Sandrei default: 9181228Sandrei cpi->cpi_ncore_per_chip = 1; 9191228Sandrei break; 9201228Sandrei } 9210Sstevel@tonic-gate } 9220Sstevel@tonic-gate 9231228Sandrei /* 9241228Sandrei * If more than one core, then this processor is CMP. 9251228Sandrei */ 9261228Sandrei if (cpi->cpi_ncore_per_chip > 1) 9271228Sandrei feature |= X86_CMP; 9283446Smrj 9291228Sandrei /* 9301228Sandrei * If the number of cores is the same as the number 9311228Sandrei * of CPUs, then we cannot have HyperThreading. 9321228Sandrei */ 9331228Sandrei if (cpi->cpi_ncpu_per_chip == cpi->cpi_ncore_per_chip) 9341228Sandrei feature &= ~X86_HTT; 9351228Sandrei 9360Sstevel@tonic-gate if ((feature & (X86_HTT | X86_CMP)) == 0) { 9371228Sandrei /* 9381228Sandrei * Single-core single-threaded processors. 9391228Sandrei */ 9400Sstevel@tonic-gate cpi->cpi_chipid = -1; 9410Sstevel@tonic-gate cpi->cpi_clogid = 0; 9421228Sandrei cpi->cpi_coreid = cpu->cpu_id; 9430Sstevel@tonic-gate } else if (cpi->cpi_ncpu_per_chip > 1) { 9441228Sandrei uint_t i; 9451228Sandrei uint_t chipid_shift = 0; 9461228Sandrei uint_t coreid_shift = 0; 9471228Sandrei uint_t apic_id = CPI_APIC_ID(cpi); 9481228Sandrei 9491228Sandrei for (i = 1; i < cpi->cpi_ncpu_per_chip; i <<= 1) 9501228Sandrei chipid_shift++; 9511228Sandrei cpi->cpi_chipid = apic_id >> chipid_shift; 9521228Sandrei cpi->cpi_clogid = apic_id & ((1 << chipid_shift) - 1); 9530Sstevel@tonic-gate 9541228Sandrei if (cpi->cpi_vendor == X86_VENDOR_Intel) { 9551228Sandrei if (feature & X86_CMP) { 9561228Sandrei /* 9571228Sandrei * Multi-core (and possibly multi-threaded) 9581228Sandrei * processors. 9591228Sandrei */ 9601228Sandrei uint_t ncpu_per_core; 9611228Sandrei if (cpi->cpi_ncore_per_chip == 1) 9621228Sandrei ncpu_per_core = cpi->cpi_ncpu_per_chip; 9631228Sandrei else if (cpi->cpi_ncore_per_chip > 1) 9641228Sandrei ncpu_per_core = cpi->cpi_ncpu_per_chip / 9651228Sandrei cpi->cpi_ncore_per_chip; 9661228Sandrei /* 9671228Sandrei * 8bit APIC IDs on dual core Pentiums 9681228Sandrei * look like this: 9691228Sandrei * 9701228Sandrei * +-----------------------+------+------+ 9711228Sandrei * | Physical Package ID | MC | HT | 9721228Sandrei * +-----------------------+------+------+ 9731228Sandrei * <------- chipid --------> 9741228Sandrei * <------- coreid ---------------> 9751228Sandrei * <--- clogid --> 9761228Sandrei * 9771228Sandrei * Where the number of bits necessary to 9781228Sandrei * represent MC and HT fields together equals 9791228Sandrei * to the minimum number of bits necessary to 9801228Sandrei * store the value of cpi->cpi_ncpu_per_chip. 9811228Sandrei * Of those bits, the MC part uses the number 9821228Sandrei * of bits necessary to store the value of 9831228Sandrei * cpi->cpi_ncore_per_chip. 9841228Sandrei */ 9851228Sandrei for (i = 1; i < ncpu_per_core; i <<= 1) 9861228Sandrei coreid_shift++; 9871727Sandrei cpi->cpi_coreid = apic_id >> coreid_shift; 9881228Sandrei } else if (feature & X86_HTT) { 9891228Sandrei /* 9901228Sandrei * Single-core multi-threaded processors. 9911228Sandrei */ 9921228Sandrei cpi->cpi_coreid = cpi->cpi_chipid; 9931228Sandrei } 9941228Sandrei } else if (cpi->cpi_vendor == X86_VENDOR_AMD) { 9951228Sandrei /* 9961228Sandrei * AMD currently only has dual-core processors with 9971228Sandrei * single-threaded cores. If they ever release 9981228Sandrei * multi-threaded processors, then this code 9991228Sandrei * will have to be updated. 10001228Sandrei */ 10011228Sandrei cpi->cpi_coreid = cpu->cpu_id; 10021228Sandrei } else { 10031228Sandrei /* 10041228Sandrei * All other processors are currently 10051228Sandrei * assumed to have single cores. 10061228Sandrei */ 10071228Sandrei cpi->cpi_coreid = cpi->cpi_chipid; 10081228Sandrei } 10090Sstevel@tonic-gate } 10100Sstevel@tonic-gate 10112869Sgavinm /* 10122869Sgavinm * Synthesize chip "revision" and socket type 10132869Sgavinm */ 10142869Sgavinm synth_info(cpi); 10152869Sgavinm 10160Sstevel@tonic-gate pass1_done: 10170Sstevel@tonic-gate cpi->cpi_pass = 1; 10180Sstevel@tonic-gate return (feature); 10190Sstevel@tonic-gate } 10200Sstevel@tonic-gate 10210Sstevel@tonic-gate /* 10220Sstevel@tonic-gate * Make copies of the cpuid table entries we depend on, in 10230Sstevel@tonic-gate * part for ease of parsing now, in part so that we have only 10240Sstevel@tonic-gate * one place to correct any of it, in part for ease of 10250Sstevel@tonic-gate * later export to userland, and in part so we can look at 10260Sstevel@tonic-gate * this stuff in a crash dump. 10270Sstevel@tonic-gate */ 10280Sstevel@tonic-gate 10290Sstevel@tonic-gate /*ARGSUSED*/ 10300Sstevel@tonic-gate void 10310Sstevel@tonic-gate cpuid_pass2(cpu_t *cpu) 10320Sstevel@tonic-gate { 10330Sstevel@tonic-gate uint_t n, nmax; 10340Sstevel@tonic-gate int i; 10351228Sandrei struct cpuid_regs *cp; 10360Sstevel@tonic-gate uint8_t *dp; 10370Sstevel@tonic-gate uint32_t *iptr; 10380Sstevel@tonic-gate struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 10390Sstevel@tonic-gate 10400Sstevel@tonic-gate ASSERT(cpi->cpi_pass == 1); 10410Sstevel@tonic-gate 10420Sstevel@tonic-gate if (cpi->cpi_maxeax < 1) 10430Sstevel@tonic-gate goto pass2_done; 10440Sstevel@tonic-gate 10450Sstevel@tonic-gate if ((nmax = cpi->cpi_maxeax + 1) > NMAX_CPI_STD) 10460Sstevel@tonic-gate nmax = NMAX_CPI_STD; 10470Sstevel@tonic-gate /* 10480Sstevel@tonic-gate * (We already handled n == 0 and n == 1 in pass 1) 10490Sstevel@tonic-gate */ 10500Sstevel@tonic-gate for (n = 2, cp = &cpi->cpi_std[2]; n < nmax; n++, cp++) { 10511228Sandrei cp->cp_eax = n; 10521228Sandrei (void) __cpuid_insn(cp); 10533446Smrj platform_cpuid_mangle(cpi->cpi_vendor, n, cp); 10540Sstevel@tonic-gate switch (n) { 10550Sstevel@tonic-gate case 2: 10560Sstevel@tonic-gate /* 10570Sstevel@tonic-gate * "the lower 8 bits of the %eax register 10580Sstevel@tonic-gate * contain a value that identifies the number 10590Sstevel@tonic-gate * of times the cpuid [instruction] has to be 10600Sstevel@tonic-gate * executed to obtain a complete image of the 10610Sstevel@tonic-gate * processor's caching systems." 10620Sstevel@tonic-gate * 10630Sstevel@tonic-gate * How *do* they make this stuff up? 10640Sstevel@tonic-gate */ 10650Sstevel@tonic-gate cpi->cpi_ncache = sizeof (*cp) * 10660Sstevel@tonic-gate BITX(cp->cp_eax, 7, 0); 10670Sstevel@tonic-gate if (cpi->cpi_ncache == 0) 10680Sstevel@tonic-gate break; 10690Sstevel@tonic-gate cpi->cpi_ncache--; /* skip count byte */ 10700Sstevel@tonic-gate 10710Sstevel@tonic-gate /* 10720Sstevel@tonic-gate * Well, for now, rather than attempt to implement 10730Sstevel@tonic-gate * this slightly dubious algorithm, we just look 10740Sstevel@tonic-gate * at the first 15 .. 10750Sstevel@tonic-gate */ 10760Sstevel@tonic-gate if (cpi->cpi_ncache > (sizeof (*cp) - 1)) 10770Sstevel@tonic-gate cpi->cpi_ncache = sizeof (*cp) - 1; 10780Sstevel@tonic-gate 10790Sstevel@tonic-gate dp = cpi->cpi_cacheinfo; 10800Sstevel@tonic-gate if (BITX(cp->cp_eax, 31, 31) == 0) { 10810Sstevel@tonic-gate uint8_t *p = (void *)&cp->cp_eax; 10820Sstevel@tonic-gate for (i = 1; i < 3; i++) 10830Sstevel@tonic-gate if (p[i] != 0) 10840Sstevel@tonic-gate *dp++ = p[i]; 10850Sstevel@tonic-gate } 10860Sstevel@tonic-gate if (BITX(cp->cp_ebx, 31, 31) == 0) { 10870Sstevel@tonic-gate uint8_t *p = (void *)&cp->cp_ebx; 10880Sstevel@tonic-gate for (i = 0; i < 4; i++) 10890Sstevel@tonic-gate if (p[i] != 0) 10900Sstevel@tonic-gate *dp++ = p[i]; 10910Sstevel@tonic-gate } 10920Sstevel@tonic-gate if (BITX(cp->cp_ecx, 31, 31) == 0) { 10930Sstevel@tonic-gate uint8_t *p = (void *)&cp->cp_ecx; 10940Sstevel@tonic-gate for (i = 0; i < 4; i++) 10950Sstevel@tonic-gate if (p[i] != 0) 10960Sstevel@tonic-gate *dp++ = p[i]; 10970Sstevel@tonic-gate } 10980Sstevel@tonic-gate if (BITX(cp->cp_edx, 31, 31) == 0) { 10990Sstevel@tonic-gate uint8_t *p = (void *)&cp->cp_edx; 11000Sstevel@tonic-gate for (i = 0; i < 4; i++) 11010Sstevel@tonic-gate if (p[i] != 0) 11020Sstevel@tonic-gate *dp++ = p[i]; 11030Sstevel@tonic-gate } 11040Sstevel@tonic-gate break; 1105*4481Sbholler 11060Sstevel@tonic-gate case 3: /* Processor serial number, if PSN supported */ 1107*4481Sbholler break; 1108*4481Sbholler 11090Sstevel@tonic-gate case 4: /* Deterministic cache parameters */ 1110*4481Sbholler break; 1111*4481Sbholler 11120Sstevel@tonic-gate case 5: /* Monitor/Mwait parameters */ 1113*4481Sbholler 1114*4481Sbholler /* 1115*4481Sbholler * check cpi_mwait.support which was set in cpuid_pass1 1116*4481Sbholler */ 1117*4481Sbholler if (!(cpi->cpi_mwait.support & MWAIT_SUPPORT)) 1118*4481Sbholler break; 1119*4481Sbholler 1120*4481Sbholler cpi->cpi_mwait.mon_min = (size_t)MWAIT_SIZE_MIN(cpi); 1121*4481Sbholler cpi->cpi_mwait.mon_max = (size_t)MWAIT_SIZE_MAX(cpi); 1122*4481Sbholler if (MWAIT_EXTENSION(cpi)) { 1123*4481Sbholler cpi->cpi_mwait.support |= MWAIT_EXTENSIONS; 1124*4481Sbholler if (MWAIT_INT_ENABLE(cpi)) 1125*4481Sbholler cpi->cpi_mwait.support |= 1126*4481Sbholler MWAIT_ECX_INT_ENABLE; 1127*4481Sbholler } 1128*4481Sbholler break; 1129*4481Sbholler 11300Sstevel@tonic-gate default: 11310Sstevel@tonic-gate break; 11320Sstevel@tonic-gate } 11330Sstevel@tonic-gate } 11340Sstevel@tonic-gate 11350Sstevel@tonic-gate if ((cpi->cpi_xmaxeax & 0x80000000) == 0) 11360Sstevel@tonic-gate goto pass2_done; 11370Sstevel@tonic-gate 11380Sstevel@tonic-gate if ((nmax = cpi->cpi_xmaxeax - 0x80000000 + 1) > NMAX_CPI_EXTD) 11390Sstevel@tonic-gate nmax = NMAX_CPI_EXTD; 11400Sstevel@tonic-gate /* 11410Sstevel@tonic-gate * Copy the extended properties, fixing them as we go. 11420Sstevel@tonic-gate * (We already handled n == 0 and n == 1 in pass 1) 11430Sstevel@tonic-gate */ 11440Sstevel@tonic-gate iptr = (void *)cpi->cpi_brandstr; 11450Sstevel@tonic-gate for (n = 2, cp = &cpi->cpi_extd[2]; n < nmax; cp++, n++) { 11461228Sandrei cp->cp_eax = 0x80000000 + n; 11471228Sandrei (void) __cpuid_insn(cp); 11483446Smrj platform_cpuid_mangle(cpi->cpi_vendor, 0x80000000 + n, cp); 11490Sstevel@tonic-gate switch (n) { 11500Sstevel@tonic-gate case 2: 11510Sstevel@tonic-gate case 3: 11520Sstevel@tonic-gate case 4: 11530Sstevel@tonic-gate /* 11540Sstevel@tonic-gate * Extract the brand string 11550Sstevel@tonic-gate */ 11560Sstevel@tonic-gate *iptr++ = cp->cp_eax; 11570Sstevel@tonic-gate *iptr++ = cp->cp_ebx; 11580Sstevel@tonic-gate *iptr++ = cp->cp_ecx; 11590Sstevel@tonic-gate *iptr++ = cp->cp_edx; 11600Sstevel@tonic-gate break; 11610Sstevel@tonic-gate case 5: 11620Sstevel@tonic-gate switch (cpi->cpi_vendor) { 11630Sstevel@tonic-gate case X86_VENDOR_AMD: 11640Sstevel@tonic-gate /* 11650Sstevel@tonic-gate * The Athlon and Duron were the first 11660Sstevel@tonic-gate * parts to report the sizes of the 11670Sstevel@tonic-gate * TLB for large pages. Before then, 11680Sstevel@tonic-gate * we don't trust the data. 11690Sstevel@tonic-gate */ 11700Sstevel@tonic-gate if (cpi->cpi_family < 6 || 11710Sstevel@tonic-gate (cpi->cpi_family == 6 && 11720Sstevel@tonic-gate cpi->cpi_model < 1)) 11730Sstevel@tonic-gate cp->cp_eax = 0; 11740Sstevel@tonic-gate break; 11750Sstevel@tonic-gate default: 11760Sstevel@tonic-gate break; 11770Sstevel@tonic-gate } 11780Sstevel@tonic-gate break; 11790Sstevel@tonic-gate case 6: 11800Sstevel@tonic-gate switch (cpi->cpi_vendor) { 11810Sstevel@tonic-gate case X86_VENDOR_AMD: 11820Sstevel@tonic-gate /* 11830Sstevel@tonic-gate * The Athlon and Duron were the first 11840Sstevel@tonic-gate * AMD parts with L2 TLB's. 11850Sstevel@tonic-gate * Before then, don't trust the data. 11860Sstevel@tonic-gate */ 11870Sstevel@tonic-gate if (cpi->cpi_family < 6 || 11880Sstevel@tonic-gate cpi->cpi_family == 6 && 11890Sstevel@tonic-gate cpi->cpi_model < 1) 11900Sstevel@tonic-gate cp->cp_eax = cp->cp_ebx = 0; 11910Sstevel@tonic-gate /* 11920Sstevel@tonic-gate * AMD Duron rev A0 reports L2 11930Sstevel@tonic-gate * cache size incorrectly as 1K 11940Sstevel@tonic-gate * when it is really 64K 11950Sstevel@tonic-gate */ 11960Sstevel@tonic-gate if (cpi->cpi_family == 6 && 11970Sstevel@tonic-gate cpi->cpi_model == 3 && 11980Sstevel@tonic-gate cpi->cpi_step == 0) { 11990Sstevel@tonic-gate cp->cp_ecx &= 0xffff; 12000Sstevel@tonic-gate cp->cp_ecx |= 0x400000; 12010Sstevel@tonic-gate } 12020Sstevel@tonic-gate break; 12030Sstevel@tonic-gate case X86_VENDOR_Cyrix: /* VIA C3 */ 12040Sstevel@tonic-gate /* 12050Sstevel@tonic-gate * VIA C3 processors are a bit messed 12060Sstevel@tonic-gate * up w.r.t. encoding cache sizes in %ecx 12070Sstevel@tonic-gate */ 12080Sstevel@tonic-gate if (cpi->cpi_family != 6) 12090Sstevel@tonic-gate break; 12100Sstevel@tonic-gate /* 12110Sstevel@tonic-gate * model 7 and 8 were incorrectly encoded 12120Sstevel@tonic-gate * 12130Sstevel@tonic-gate * xxx is model 8 really broken? 12140Sstevel@tonic-gate */ 12150Sstevel@tonic-gate if (cpi->cpi_model == 7 || 12160Sstevel@tonic-gate cpi->cpi_model == 8) 12170Sstevel@tonic-gate cp->cp_ecx = 12180Sstevel@tonic-gate BITX(cp->cp_ecx, 31, 24) << 16 | 12190Sstevel@tonic-gate BITX(cp->cp_ecx, 23, 16) << 12 | 12200Sstevel@tonic-gate BITX(cp->cp_ecx, 15, 8) << 8 | 12210Sstevel@tonic-gate BITX(cp->cp_ecx, 7, 0); 12220Sstevel@tonic-gate /* 12230Sstevel@tonic-gate * model 9 stepping 1 has wrong associativity 12240Sstevel@tonic-gate */ 12250Sstevel@tonic-gate if (cpi->cpi_model == 9 && cpi->cpi_step == 1) 12260Sstevel@tonic-gate cp->cp_ecx |= 8 << 12; 12270Sstevel@tonic-gate break; 12280Sstevel@tonic-gate case X86_VENDOR_Intel: 12290Sstevel@tonic-gate /* 12300Sstevel@tonic-gate * Extended L2 Cache features function. 12310Sstevel@tonic-gate * First appeared on Prescott. 12320Sstevel@tonic-gate */ 12330Sstevel@tonic-gate default: 12340Sstevel@tonic-gate break; 12350Sstevel@tonic-gate } 12360Sstevel@tonic-gate break; 12370Sstevel@tonic-gate default: 12380Sstevel@tonic-gate break; 12390Sstevel@tonic-gate } 12400Sstevel@tonic-gate } 12410Sstevel@tonic-gate 12420Sstevel@tonic-gate pass2_done: 12430Sstevel@tonic-gate cpi->cpi_pass = 2; 12440Sstevel@tonic-gate } 12450Sstevel@tonic-gate 12460Sstevel@tonic-gate static const char * 12470Sstevel@tonic-gate intel_cpubrand(const struct cpuid_info *cpi) 12480Sstevel@tonic-gate { 12490Sstevel@tonic-gate int i; 12500Sstevel@tonic-gate 12510Sstevel@tonic-gate if ((x86_feature & X86_CPUID) == 0 || 12520Sstevel@tonic-gate cpi->cpi_maxeax < 1 || cpi->cpi_family < 5) 12530Sstevel@tonic-gate return ("i486"); 12540Sstevel@tonic-gate 12550Sstevel@tonic-gate switch (cpi->cpi_family) { 12560Sstevel@tonic-gate case 5: 12570Sstevel@tonic-gate return ("Intel Pentium(r)"); 12580Sstevel@tonic-gate case 6: 12590Sstevel@tonic-gate switch (cpi->cpi_model) { 12600Sstevel@tonic-gate uint_t celeron, xeon; 12611228Sandrei const struct cpuid_regs *cp; 12620Sstevel@tonic-gate case 0: 12630Sstevel@tonic-gate case 1: 12640Sstevel@tonic-gate case 2: 12650Sstevel@tonic-gate return ("Intel Pentium(r) Pro"); 12660Sstevel@tonic-gate case 3: 12670Sstevel@tonic-gate case 4: 12680Sstevel@tonic-gate return ("Intel Pentium(r) II"); 12690Sstevel@tonic-gate case 6: 12700Sstevel@tonic-gate return ("Intel Celeron(r)"); 12710Sstevel@tonic-gate case 5: 12720Sstevel@tonic-gate case 7: 12730Sstevel@tonic-gate celeron = xeon = 0; 12740Sstevel@tonic-gate cp = &cpi->cpi_std[2]; /* cache info */ 12750Sstevel@tonic-gate 12760Sstevel@tonic-gate for (i = 1; i < 3; i++) { 12770Sstevel@tonic-gate uint_t tmp; 12780Sstevel@tonic-gate 12790Sstevel@tonic-gate tmp = (cp->cp_eax >> (8 * i)) & 0xff; 12800Sstevel@tonic-gate if (tmp == 0x40) 12810Sstevel@tonic-gate celeron++; 12820Sstevel@tonic-gate if (tmp >= 0x44 && tmp <= 0x45) 12830Sstevel@tonic-gate xeon++; 12840Sstevel@tonic-gate } 12850Sstevel@tonic-gate 12860Sstevel@tonic-gate for (i = 0; i < 2; i++) { 12870Sstevel@tonic-gate uint_t tmp; 12880Sstevel@tonic-gate 12890Sstevel@tonic-gate tmp = (cp->cp_ebx >> (8 * i)) & 0xff; 12900Sstevel@tonic-gate if (tmp == 0x40) 12910Sstevel@tonic-gate celeron++; 12920Sstevel@tonic-gate else if (tmp >= 0x44 && tmp <= 0x45) 12930Sstevel@tonic-gate xeon++; 12940Sstevel@tonic-gate } 12950Sstevel@tonic-gate 12960Sstevel@tonic-gate for (i = 0; i < 4; i++) { 12970Sstevel@tonic-gate uint_t tmp; 12980Sstevel@tonic-gate 12990Sstevel@tonic-gate tmp = (cp->cp_ecx >> (8 * i)) & 0xff; 13000Sstevel@tonic-gate if (tmp == 0x40) 13010Sstevel@tonic-gate celeron++; 13020Sstevel@tonic-gate else if (tmp >= 0x44 && tmp <= 0x45) 13030Sstevel@tonic-gate xeon++; 13040Sstevel@tonic-gate } 13050Sstevel@tonic-gate 13060Sstevel@tonic-gate for (i = 0; i < 4; i++) { 13070Sstevel@tonic-gate uint_t tmp; 13080Sstevel@tonic-gate 13090Sstevel@tonic-gate tmp = (cp->cp_edx >> (8 * i)) & 0xff; 13100Sstevel@tonic-gate if (tmp == 0x40) 13110Sstevel@tonic-gate celeron++; 13120Sstevel@tonic-gate else if (tmp >= 0x44 && tmp <= 0x45) 13130Sstevel@tonic-gate xeon++; 13140Sstevel@tonic-gate } 13150Sstevel@tonic-gate 13160Sstevel@tonic-gate if (celeron) 13170Sstevel@tonic-gate return ("Intel Celeron(r)"); 13180Sstevel@tonic-gate if (xeon) 13190Sstevel@tonic-gate return (cpi->cpi_model == 5 ? 13200Sstevel@tonic-gate "Intel Pentium(r) II Xeon(tm)" : 13210Sstevel@tonic-gate "Intel Pentium(r) III Xeon(tm)"); 13220Sstevel@tonic-gate return (cpi->cpi_model == 5 ? 13230Sstevel@tonic-gate "Intel Pentium(r) II or Pentium(r) II Xeon(tm)" : 13240Sstevel@tonic-gate "Intel Pentium(r) III or Pentium(r) III Xeon(tm)"); 13250Sstevel@tonic-gate default: 13260Sstevel@tonic-gate break; 13270Sstevel@tonic-gate } 13280Sstevel@tonic-gate default: 13290Sstevel@tonic-gate break; 13300Sstevel@tonic-gate } 13310Sstevel@tonic-gate 13321975Sdmick /* BrandID is present if the field is nonzero */ 13331975Sdmick if (cpi->cpi_brandid != 0) { 13340Sstevel@tonic-gate static const struct { 13350Sstevel@tonic-gate uint_t bt_bid; 13360Sstevel@tonic-gate const char *bt_str; 13370Sstevel@tonic-gate } brand_tbl[] = { 13380Sstevel@tonic-gate { 0x1, "Intel(r) Celeron(r)" }, 13390Sstevel@tonic-gate { 0x2, "Intel(r) Pentium(r) III" }, 13400Sstevel@tonic-gate { 0x3, "Intel(r) Pentium(r) III Xeon(tm)" }, 13410Sstevel@tonic-gate { 0x4, "Intel(r) Pentium(r) III" }, 13420Sstevel@tonic-gate { 0x6, "Mobile Intel(r) Pentium(r) III" }, 13430Sstevel@tonic-gate { 0x7, "Mobile Intel(r) Celeron(r)" }, 13440Sstevel@tonic-gate { 0x8, "Intel(r) Pentium(r) 4" }, 13450Sstevel@tonic-gate { 0x9, "Intel(r) Pentium(r) 4" }, 13460Sstevel@tonic-gate { 0xa, "Intel(r) Celeron(r)" }, 13470Sstevel@tonic-gate { 0xb, "Intel(r) Xeon(tm)" }, 13480Sstevel@tonic-gate { 0xc, "Intel(r) Xeon(tm) MP" }, 13490Sstevel@tonic-gate { 0xe, "Mobile Intel(r) Pentium(r) 4" }, 13501975Sdmick { 0xf, "Mobile Intel(r) Celeron(r)" }, 13511975Sdmick { 0x11, "Mobile Genuine Intel(r)" }, 13521975Sdmick { 0x12, "Intel(r) Celeron(r) M" }, 13531975Sdmick { 0x13, "Mobile Intel(r) Celeron(r)" }, 13541975Sdmick { 0x14, "Intel(r) Celeron(r)" }, 13551975Sdmick { 0x15, "Mobile Genuine Intel(r)" }, 13561975Sdmick { 0x16, "Intel(r) Pentium(r) M" }, 13571975Sdmick { 0x17, "Mobile Intel(r) Celeron(r)" } 13580Sstevel@tonic-gate }; 13590Sstevel@tonic-gate uint_t btblmax = sizeof (brand_tbl) / sizeof (brand_tbl[0]); 13600Sstevel@tonic-gate uint_t sgn; 13610Sstevel@tonic-gate 13620Sstevel@tonic-gate sgn = (cpi->cpi_family << 8) | 13630Sstevel@tonic-gate (cpi->cpi_model << 4) | cpi->cpi_step; 13640Sstevel@tonic-gate 13650Sstevel@tonic-gate for (i = 0; i < btblmax; i++) 13660Sstevel@tonic-gate if (brand_tbl[i].bt_bid == cpi->cpi_brandid) 13670Sstevel@tonic-gate break; 13680Sstevel@tonic-gate if (i < btblmax) { 13690Sstevel@tonic-gate if (sgn == 0x6b1 && cpi->cpi_brandid == 3) 13700Sstevel@tonic-gate return ("Intel(r) Celeron(r)"); 13710Sstevel@tonic-gate if (sgn < 0xf13 && cpi->cpi_brandid == 0xb) 13720Sstevel@tonic-gate return ("Intel(r) Xeon(tm) MP"); 13730Sstevel@tonic-gate if (sgn < 0xf13 && cpi->cpi_brandid == 0xe) 13740Sstevel@tonic-gate return ("Intel(r) Xeon(tm)"); 13750Sstevel@tonic-gate return (brand_tbl[i].bt_str); 13760Sstevel@tonic-gate } 13770Sstevel@tonic-gate } 13780Sstevel@tonic-gate 13790Sstevel@tonic-gate return (NULL); 13800Sstevel@tonic-gate } 13810Sstevel@tonic-gate 13820Sstevel@tonic-gate static const char * 13830Sstevel@tonic-gate amd_cpubrand(const struct cpuid_info *cpi) 13840Sstevel@tonic-gate { 13850Sstevel@tonic-gate if ((x86_feature & X86_CPUID) == 0 || 13860Sstevel@tonic-gate cpi->cpi_maxeax < 1 || cpi->cpi_family < 5) 13870Sstevel@tonic-gate return ("i486 compatible"); 13880Sstevel@tonic-gate 13890Sstevel@tonic-gate switch (cpi->cpi_family) { 13900Sstevel@tonic-gate case 5: 13910Sstevel@tonic-gate switch (cpi->cpi_model) { 13920Sstevel@tonic-gate case 0: 13930Sstevel@tonic-gate case 1: 13940Sstevel@tonic-gate case 2: 13950Sstevel@tonic-gate case 3: 13960Sstevel@tonic-gate case 4: 13970Sstevel@tonic-gate case 5: 13980Sstevel@tonic-gate return ("AMD-K5(r)"); 13990Sstevel@tonic-gate case 6: 14000Sstevel@tonic-gate case 7: 14010Sstevel@tonic-gate return ("AMD-K6(r)"); 14020Sstevel@tonic-gate case 8: 14030Sstevel@tonic-gate return ("AMD-K6(r)-2"); 14040Sstevel@tonic-gate case 9: 14050Sstevel@tonic-gate return ("AMD-K6(r)-III"); 14060Sstevel@tonic-gate default: 14070Sstevel@tonic-gate return ("AMD (family 5)"); 14080Sstevel@tonic-gate } 14090Sstevel@tonic-gate case 6: 14100Sstevel@tonic-gate switch (cpi->cpi_model) { 14110Sstevel@tonic-gate case 1: 14120Sstevel@tonic-gate return ("AMD-K7(tm)"); 14130Sstevel@tonic-gate case 0: 14140Sstevel@tonic-gate case 2: 14150Sstevel@tonic-gate case 4: 14160Sstevel@tonic-gate return ("AMD Athlon(tm)"); 14170Sstevel@tonic-gate case 3: 14180Sstevel@tonic-gate case 7: 14190Sstevel@tonic-gate return ("AMD Duron(tm)"); 14200Sstevel@tonic-gate case 6: 14210Sstevel@tonic-gate case 8: 14220Sstevel@tonic-gate case 10: 14230Sstevel@tonic-gate /* 14240Sstevel@tonic-gate * Use the L2 cache size to distinguish 14250Sstevel@tonic-gate */ 14260Sstevel@tonic-gate return ((cpi->cpi_extd[6].cp_ecx >> 16) >= 256 ? 14270Sstevel@tonic-gate "AMD Athlon(tm)" : "AMD Duron(tm)"); 14280Sstevel@tonic-gate default: 14290Sstevel@tonic-gate return ("AMD (family 6)"); 14300Sstevel@tonic-gate } 14310Sstevel@tonic-gate default: 14320Sstevel@tonic-gate break; 14330Sstevel@tonic-gate } 14340Sstevel@tonic-gate 14350Sstevel@tonic-gate if (cpi->cpi_family == 0xf && cpi->cpi_model == 5 && 14360Sstevel@tonic-gate cpi->cpi_brandid != 0) { 14370Sstevel@tonic-gate switch (BITX(cpi->cpi_brandid, 7, 5)) { 14380Sstevel@tonic-gate case 3: 14390Sstevel@tonic-gate return ("AMD Opteron(tm) UP 1xx"); 14400Sstevel@tonic-gate case 4: 14410Sstevel@tonic-gate return ("AMD Opteron(tm) DP 2xx"); 14420Sstevel@tonic-gate case 5: 14430Sstevel@tonic-gate return ("AMD Opteron(tm) MP 8xx"); 14440Sstevel@tonic-gate default: 14450Sstevel@tonic-gate return ("AMD Opteron(tm)"); 14460Sstevel@tonic-gate } 14470Sstevel@tonic-gate } 14480Sstevel@tonic-gate 14490Sstevel@tonic-gate return (NULL); 14500Sstevel@tonic-gate } 14510Sstevel@tonic-gate 14520Sstevel@tonic-gate static const char * 14530Sstevel@tonic-gate cyrix_cpubrand(struct cpuid_info *cpi, uint_t type) 14540Sstevel@tonic-gate { 14550Sstevel@tonic-gate if ((x86_feature & X86_CPUID) == 0 || 14560Sstevel@tonic-gate cpi->cpi_maxeax < 1 || cpi->cpi_family < 5 || 14570Sstevel@tonic-gate type == X86_TYPE_CYRIX_486) 14580Sstevel@tonic-gate return ("i486 compatible"); 14590Sstevel@tonic-gate 14600Sstevel@tonic-gate switch (type) { 14610Sstevel@tonic-gate case X86_TYPE_CYRIX_6x86: 14620Sstevel@tonic-gate return ("Cyrix 6x86"); 14630Sstevel@tonic-gate case X86_TYPE_CYRIX_6x86L: 14640Sstevel@tonic-gate return ("Cyrix 6x86L"); 14650Sstevel@tonic-gate case X86_TYPE_CYRIX_6x86MX: 14660Sstevel@tonic-gate return ("Cyrix 6x86MX"); 14670Sstevel@tonic-gate case X86_TYPE_CYRIX_GXm: 14680Sstevel@tonic-gate return ("Cyrix GXm"); 14690Sstevel@tonic-gate case X86_TYPE_CYRIX_MediaGX: 14700Sstevel@tonic-gate return ("Cyrix MediaGX"); 14710Sstevel@tonic-gate case X86_TYPE_CYRIX_MII: 14720Sstevel@tonic-gate return ("Cyrix M2"); 14730Sstevel@tonic-gate case X86_TYPE_VIA_CYRIX_III: 14740Sstevel@tonic-gate return ("VIA Cyrix M3"); 14750Sstevel@tonic-gate default: 14760Sstevel@tonic-gate /* 14770Sstevel@tonic-gate * Have another wild guess .. 14780Sstevel@tonic-gate */ 14790Sstevel@tonic-gate if (cpi->cpi_family == 4 && cpi->cpi_model == 9) 14800Sstevel@tonic-gate return ("Cyrix 5x86"); 14810Sstevel@tonic-gate else if (cpi->cpi_family == 5) { 14820Sstevel@tonic-gate switch (cpi->cpi_model) { 14830Sstevel@tonic-gate case 2: 14840Sstevel@tonic-gate return ("Cyrix 6x86"); /* Cyrix M1 */ 14850Sstevel@tonic-gate case 4: 14860Sstevel@tonic-gate return ("Cyrix MediaGX"); 14870Sstevel@tonic-gate default: 14880Sstevel@tonic-gate break; 14890Sstevel@tonic-gate } 14900Sstevel@tonic-gate } else if (cpi->cpi_family == 6) { 14910Sstevel@tonic-gate switch (cpi->cpi_model) { 14920Sstevel@tonic-gate case 0: 14930Sstevel@tonic-gate return ("Cyrix 6x86MX"); /* Cyrix M2? */ 14940Sstevel@tonic-gate case 5: 14950Sstevel@tonic-gate case 6: 14960Sstevel@tonic-gate case 7: 14970Sstevel@tonic-gate case 8: 14980Sstevel@tonic-gate case 9: 14990Sstevel@tonic-gate return ("VIA C3"); 15000Sstevel@tonic-gate default: 15010Sstevel@tonic-gate break; 15020Sstevel@tonic-gate } 15030Sstevel@tonic-gate } 15040Sstevel@tonic-gate break; 15050Sstevel@tonic-gate } 15060Sstevel@tonic-gate return (NULL); 15070Sstevel@tonic-gate } 15080Sstevel@tonic-gate 15090Sstevel@tonic-gate /* 15100Sstevel@tonic-gate * This only gets called in the case that the CPU extended 15110Sstevel@tonic-gate * feature brand string (0x80000002, 0x80000003, 0x80000004) 15120Sstevel@tonic-gate * aren't available, or contain null bytes for some reason. 15130Sstevel@tonic-gate */ 15140Sstevel@tonic-gate static void 15150Sstevel@tonic-gate fabricate_brandstr(struct cpuid_info *cpi) 15160Sstevel@tonic-gate { 15170Sstevel@tonic-gate const char *brand = NULL; 15180Sstevel@tonic-gate 15190Sstevel@tonic-gate switch (cpi->cpi_vendor) { 15200Sstevel@tonic-gate case X86_VENDOR_Intel: 15210Sstevel@tonic-gate brand = intel_cpubrand(cpi); 15220Sstevel@tonic-gate break; 15230Sstevel@tonic-gate case X86_VENDOR_AMD: 15240Sstevel@tonic-gate brand = amd_cpubrand(cpi); 15250Sstevel@tonic-gate break; 15260Sstevel@tonic-gate case X86_VENDOR_Cyrix: 15270Sstevel@tonic-gate brand = cyrix_cpubrand(cpi, x86_type); 15280Sstevel@tonic-gate break; 15290Sstevel@tonic-gate case X86_VENDOR_NexGen: 15300Sstevel@tonic-gate if (cpi->cpi_family == 5 && cpi->cpi_model == 0) 15310Sstevel@tonic-gate brand = "NexGen Nx586"; 15320Sstevel@tonic-gate break; 15330Sstevel@tonic-gate case X86_VENDOR_Centaur: 15340Sstevel@tonic-gate if (cpi->cpi_family == 5) 15350Sstevel@tonic-gate switch (cpi->cpi_model) { 15360Sstevel@tonic-gate case 4: 15370Sstevel@tonic-gate brand = "Centaur C6"; 15380Sstevel@tonic-gate break; 15390Sstevel@tonic-gate case 8: 15400Sstevel@tonic-gate brand = "Centaur C2"; 15410Sstevel@tonic-gate break; 15420Sstevel@tonic-gate case 9: 15430Sstevel@tonic-gate brand = "Centaur C3"; 15440Sstevel@tonic-gate break; 15450Sstevel@tonic-gate default: 15460Sstevel@tonic-gate break; 15470Sstevel@tonic-gate } 15480Sstevel@tonic-gate break; 15490Sstevel@tonic-gate case X86_VENDOR_Rise: 15500Sstevel@tonic-gate if (cpi->cpi_family == 5 && 15510Sstevel@tonic-gate (cpi->cpi_model == 0 || cpi->cpi_model == 2)) 15520Sstevel@tonic-gate brand = "Rise mP6"; 15530Sstevel@tonic-gate break; 15540Sstevel@tonic-gate case X86_VENDOR_SiS: 15550Sstevel@tonic-gate if (cpi->cpi_family == 5 && cpi->cpi_model == 0) 15560Sstevel@tonic-gate brand = "SiS 55x"; 15570Sstevel@tonic-gate break; 15580Sstevel@tonic-gate case X86_VENDOR_TM: 15590Sstevel@tonic-gate if (cpi->cpi_family == 5 && cpi->cpi_model == 4) 15600Sstevel@tonic-gate brand = "Transmeta Crusoe TM3x00 or TM5x00"; 15610Sstevel@tonic-gate break; 15620Sstevel@tonic-gate case X86_VENDOR_NSC: 15630Sstevel@tonic-gate case X86_VENDOR_UMC: 15640Sstevel@tonic-gate default: 15650Sstevel@tonic-gate break; 15660Sstevel@tonic-gate } 15670Sstevel@tonic-gate if (brand) { 15680Sstevel@tonic-gate (void) strcpy((char *)cpi->cpi_brandstr, brand); 15690Sstevel@tonic-gate return; 15700Sstevel@tonic-gate } 15710Sstevel@tonic-gate 15720Sstevel@tonic-gate /* 15730Sstevel@tonic-gate * If all else fails ... 15740Sstevel@tonic-gate */ 15750Sstevel@tonic-gate (void) snprintf(cpi->cpi_brandstr, sizeof (cpi->cpi_brandstr), 15760Sstevel@tonic-gate "%s %d.%d.%d", cpi->cpi_vendorstr, cpi->cpi_family, 15770Sstevel@tonic-gate cpi->cpi_model, cpi->cpi_step); 15780Sstevel@tonic-gate } 15790Sstevel@tonic-gate 15800Sstevel@tonic-gate /* 15810Sstevel@tonic-gate * This routine is called just after kernel memory allocation 15820Sstevel@tonic-gate * becomes available on cpu0, and as part of mp_startup() on 15830Sstevel@tonic-gate * the other cpus. 15840Sstevel@tonic-gate * 15850Sstevel@tonic-gate * Fixup the brand string. 15860Sstevel@tonic-gate */ 15870Sstevel@tonic-gate /*ARGSUSED*/ 15880Sstevel@tonic-gate void 15890Sstevel@tonic-gate cpuid_pass3(cpu_t *cpu) 15900Sstevel@tonic-gate { 15910Sstevel@tonic-gate struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 15920Sstevel@tonic-gate 15930Sstevel@tonic-gate ASSERT(cpi->cpi_pass == 2); 15940Sstevel@tonic-gate 15950Sstevel@tonic-gate if ((cpi->cpi_xmaxeax & 0x80000000) == 0) { 15960Sstevel@tonic-gate fabricate_brandstr(cpi); 15970Sstevel@tonic-gate goto pass3_done; 15980Sstevel@tonic-gate } 15990Sstevel@tonic-gate 16000Sstevel@tonic-gate /* 16010Sstevel@tonic-gate * If we successfully extracted a brand string from the cpuid 16020Sstevel@tonic-gate * instruction, clean it up by removing leading spaces and 16030Sstevel@tonic-gate * similar junk. 16040Sstevel@tonic-gate */ 16050Sstevel@tonic-gate if (cpi->cpi_brandstr[0]) { 16060Sstevel@tonic-gate size_t maxlen = sizeof (cpi->cpi_brandstr); 16070Sstevel@tonic-gate char *src, *dst; 16080Sstevel@tonic-gate 16090Sstevel@tonic-gate dst = src = (char *)cpi->cpi_brandstr; 16100Sstevel@tonic-gate src[maxlen - 1] = '\0'; 16110Sstevel@tonic-gate /* 16120Sstevel@tonic-gate * strip leading spaces 16130Sstevel@tonic-gate */ 16140Sstevel@tonic-gate while (*src == ' ') 16150Sstevel@tonic-gate src++; 16160Sstevel@tonic-gate /* 16170Sstevel@tonic-gate * Remove any 'Genuine' or "Authentic" prefixes 16180Sstevel@tonic-gate */ 16190Sstevel@tonic-gate if (strncmp(src, "Genuine ", 8) == 0) 16200Sstevel@tonic-gate src += 8; 16210Sstevel@tonic-gate if (strncmp(src, "Authentic ", 10) == 0) 16220Sstevel@tonic-gate src += 10; 16230Sstevel@tonic-gate 16240Sstevel@tonic-gate /* 16250Sstevel@tonic-gate * Now do an in-place copy. 16260Sstevel@tonic-gate * Map (R) to (r) and (TM) to (tm). 16270Sstevel@tonic-gate * The era of teletypes is long gone, and there's 16280Sstevel@tonic-gate * -really- no need to shout. 16290Sstevel@tonic-gate */ 16300Sstevel@tonic-gate while (*src != '\0') { 16310Sstevel@tonic-gate if (src[0] == '(') { 16320Sstevel@tonic-gate if (strncmp(src + 1, "R)", 2) == 0) { 16330Sstevel@tonic-gate (void) strncpy(dst, "(r)", 3); 16340Sstevel@tonic-gate src += 3; 16350Sstevel@tonic-gate dst += 3; 16360Sstevel@tonic-gate continue; 16370Sstevel@tonic-gate } 16380Sstevel@tonic-gate if (strncmp(src + 1, "TM)", 3) == 0) { 16390Sstevel@tonic-gate (void) strncpy(dst, "(tm)", 4); 16400Sstevel@tonic-gate src += 4; 16410Sstevel@tonic-gate dst += 4; 16420Sstevel@tonic-gate continue; 16430Sstevel@tonic-gate } 16440Sstevel@tonic-gate } 16450Sstevel@tonic-gate *dst++ = *src++; 16460Sstevel@tonic-gate } 16470Sstevel@tonic-gate *dst = '\0'; 16480Sstevel@tonic-gate 16490Sstevel@tonic-gate /* 16500Sstevel@tonic-gate * Finally, remove any trailing spaces 16510Sstevel@tonic-gate */ 16520Sstevel@tonic-gate while (--dst > cpi->cpi_brandstr) 16530Sstevel@tonic-gate if (*dst == ' ') 16540Sstevel@tonic-gate *dst = '\0'; 16550Sstevel@tonic-gate else 16560Sstevel@tonic-gate break; 16570Sstevel@tonic-gate } else 16580Sstevel@tonic-gate fabricate_brandstr(cpi); 16590Sstevel@tonic-gate 16600Sstevel@tonic-gate pass3_done: 16610Sstevel@tonic-gate cpi->cpi_pass = 3; 16620Sstevel@tonic-gate } 16630Sstevel@tonic-gate 16640Sstevel@tonic-gate /* 16650Sstevel@tonic-gate * This routine is called out of bind_hwcap() much later in the life 16660Sstevel@tonic-gate * of the kernel (post_startup()). The job of this routine is to resolve 16670Sstevel@tonic-gate * the hardware feature support and kernel support for those features into 16680Sstevel@tonic-gate * what we're actually going to tell applications via the aux vector. 16690Sstevel@tonic-gate */ 16700Sstevel@tonic-gate uint_t 16710Sstevel@tonic-gate cpuid_pass4(cpu_t *cpu) 16720Sstevel@tonic-gate { 16730Sstevel@tonic-gate struct cpuid_info *cpi; 16740Sstevel@tonic-gate uint_t hwcap_flags = 0; 16750Sstevel@tonic-gate 16760Sstevel@tonic-gate if (cpu == NULL) 16770Sstevel@tonic-gate cpu = CPU; 16780Sstevel@tonic-gate cpi = cpu->cpu_m.mcpu_cpi; 16790Sstevel@tonic-gate 16800Sstevel@tonic-gate ASSERT(cpi->cpi_pass == 3); 16810Sstevel@tonic-gate 16820Sstevel@tonic-gate if (cpi->cpi_maxeax >= 1) { 16830Sstevel@tonic-gate uint32_t *edx = &cpi->cpi_support[STD_EDX_FEATURES]; 16840Sstevel@tonic-gate uint32_t *ecx = &cpi->cpi_support[STD_ECX_FEATURES]; 16850Sstevel@tonic-gate 16860Sstevel@tonic-gate *edx = CPI_FEATURES_EDX(cpi); 16870Sstevel@tonic-gate *ecx = CPI_FEATURES_ECX(cpi); 16880Sstevel@tonic-gate 16890Sstevel@tonic-gate /* 16900Sstevel@tonic-gate * [these require explicit kernel support] 16910Sstevel@tonic-gate */ 16920Sstevel@tonic-gate if ((x86_feature & X86_SEP) == 0) 16930Sstevel@tonic-gate *edx &= ~CPUID_INTC_EDX_SEP; 16940Sstevel@tonic-gate 16950Sstevel@tonic-gate if ((x86_feature & X86_SSE) == 0) 16960Sstevel@tonic-gate *edx &= ~(CPUID_INTC_EDX_FXSR|CPUID_INTC_EDX_SSE); 16970Sstevel@tonic-gate if ((x86_feature & X86_SSE2) == 0) 16980Sstevel@tonic-gate *edx &= ~CPUID_INTC_EDX_SSE2; 16990Sstevel@tonic-gate 17000Sstevel@tonic-gate if ((x86_feature & X86_HTT) == 0) 17010Sstevel@tonic-gate *edx &= ~CPUID_INTC_EDX_HTT; 17020Sstevel@tonic-gate 17030Sstevel@tonic-gate if ((x86_feature & X86_SSE3) == 0) 17040Sstevel@tonic-gate *ecx &= ~CPUID_INTC_ECX_SSE3; 17050Sstevel@tonic-gate 17060Sstevel@tonic-gate /* 17070Sstevel@tonic-gate * [no explicit support required beyond x87 fp context] 17080Sstevel@tonic-gate */ 17090Sstevel@tonic-gate if (!fpu_exists) 17100Sstevel@tonic-gate *edx &= ~(CPUID_INTC_EDX_FPU | CPUID_INTC_EDX_MMX); 17110Sstevel@tonic-gate 17120Sstevel@tonic-gate /* 17130Sstevel@tonic-gate * Now map the supported feature vector to things that we 17140Sstevel@tonic-gate * think userland will care about. 17150Sstevel@tonic-gate */ 17160Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_SEP) 17170Sstevel@tonic-gate hwcap_flags |= AV_386_SEP; 17180Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_SSE) 17190Sstevel@tonic-gate hwcap_flags |= AV_386_FXSR | AV_386_SSE; 17200Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_SSE2) 17210Sstevel@tonic-gate hwcap_flags |= AV_386_SSE2; 17220Sstevel@tonic-gate if (*ecx & CPUID_INTC_ECX_SSE3) 17230Sstevel@tonic-gate hwcap_flags |= AV_386_SSE3; 17240Sstevel@tonic-gate 17250Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_FPU) 17260Sstevel@tonic-gate hwcap_flags |= AV_386_FPU; 17270Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_MMX) 17280Sstevel@tonic-gate hwcap_flags |= AV_386_MMX; 17290Sstevel@tonic-gate 17300Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_TSC) 17310Sstevel@tonic-gate hwcap_flags |= AV_386_TSC; 17320Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_CX8) 17330Sstevel@tonic-gate hwcap_flags |= AV_386_CX8; 17340Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_CMOV) 17350Sstevel@tonic-gate hwcap_flags |= AV_386_CMOV; 17360Sstevel@tonic-gate if (*ecx & CPUID_INTC_ECX_MON) 17370Sstevel@tonic-gate hwcap_flags |= AV_386_MON; 17380Sstevel@tonic-gate if (*ecx & CPUID_INTC_ECX_CX16) 17390Sstevel@tonic-gate hwcap_flags |= AV_386_CX16; 17400Sstevel@tonic-gate } 17410Sstevel@tonic-gate 17421228Sandrei if (x86_feature & X86_HTT) 17430Sstevel@tonic-gate hwcap_flags |= AV_386_PAUSE; 17440Sstevel@tonic-gate 17450Sstevel@tonic-gate if (cpi->cpi_xmaxeax < 0x80000001) 17460Sstevel@tonic-gate goto pass4_done; 17470Sstevel@tonic-gate 17480Sstevel@tonic-gate switch (cpi->cpi_vendor) { 17491228Sandrei struct cpuid_regs cp; 17503446Smrj uint32_t *edx, *ecx; 17510Sstevel@tonic-gate 17523446Smrj case X86_VENDOR_Intel: 17533446Smrj /* 17543446Smrj * Seems like Intel duplicated what we necessary 17553446Smrj * here to make the initial crop of 64-bit OS's work. 17563446Smrj * Hopefully, those are the only "extended" bits 17573446Smrj * they'll add. 17583446Smrj */ 17593446Smrj /*FALLTHROUGH*/ 17603446Smrj 17610Sstevel@tonic-gate case X86_VENDOR_AMD: 17620Sstevel@tonic-gate edx = &cpi->cpi_support[AMD_EDX_FEATURES]; 17633446Smrj ecx = &cpi->cpi_support[AMD_ECX_FEATURES]; 17640Sstevel@tonic-gate 17650Sstevel@tonic-gate *edx = CPI_FEATURES_XTD_EDX(cpi); 17663446Smrj *ecx = CPI_FEATURES_XTD_ECX(cpi); 17673446Smrj 17683446Smrj /* 17693446Smrj * [these features require explicit kernel support] 17703446Smrj */ 17713446Smrj switch (cpi->cpi_vendor) { 17723446Smrj case X86_VENDOR_Intel: 17733446Smrj break; 17743446Smrj 17753446Smrj case X86_VENDOR_AMD: 17763446Smrj if ((x86_feature & X86_TSCP) == 0) 17773446Smrj *edx &= ~CPUID_AMD_EDX_TSCP; 17783446Smrj break; 17793446Smrj 17803446Smrj default: 17813446Smrj break; 17823446Smrj } 17830Sstevel@tonic-gate 17840Sstevel@tonic-gate /* 17850Sstevel@tonic-gate * [no explicit support required beyond 17860Sstevel@tonic-gate * x87 fp context and exception handlers] 17870Sstevel@tonic-gate */ 17880Sstevel@tonic-gate if (!fpu_exists) 17890Sstevel@tonic-gate *edx &= ~(CPUID_AMD_EDX_MMXamd | 17900Sstevel@tonic-gate CPUID_AMD_EDX_3DNow | CPUID_AMD_EDX_3DNowx); 17910Sstevel@tonic-gate 17920Sstevel@tonic-gate if ((x86_feature & X86_NX) == 0) 17930Sstevel@tonic-gate *edx &= ~CPUID_AMD_EDX_NX; 17943446Smrj #if !defined(__amd64) 17950Sstevel@tonic-gate *edx &= ~CPUID_AMD_EDX_LM; 17960Sstevel@tonic-gate #endif 17970Sstevel@tonic-gate /* 17980Sstevel@tonic-gate * Now map the supported feature vector to 17990Sstevel@tonic-gate * things that we think userland will care about. 18000Sstevel@tonic-gate */ 18013446Smrj #if defined(__amd64) 18020Sstevel@tonic-gate if (*edx & CPUID_AMD_EDX_SYSC) 18030Sstevel@tonic-gate hwcap_flags |= AV_386_AMD_SYSC; 18043446Smrj #endif 18050Sstevel@tonic-gate if (*edx & CPUID_AMD_EDX_MMXamd) 18060Sstevel@tonic-gate hwcap_flags |= AV_386_AMD_MMX; 18070Sstevel@tonic-gate if (*edx & CPUID_AMD_EDX_3DNow) 18080Sstevel@tonic-gate hwcap_flags |= AV_386_AMD_3DNow; 18090Sstevel@tonic-gate if (*edx & CPUID_AMD_EDX_3DNowx) 18100Sstevel@tonic-gate hwcap_flags |= AV_386_AMD_3DNowx; 18113446Smrj 18123446Smrj switch (cpi->cpi_vendor) { 18133446Smrj case X86_VENDOR_AMD: 18143446Smrj if (*edx & CPUID_AMD_EDX_TSCP) 18153446Smrj hwcap_flags |= AV_386_TSCP; 18163446Smrj if (*ecx & CPUID_AMD_ECX_AHF64) 18173446Smrj hwcap_flags |= AV_386_AHF; 18183446Smrj break; 18193446Smrj 18203446Smrj case X86_VENDOR_Intel: 18213446Smrj /* 18223446Smrj * Aarrgh. 18233446Smrj * Intel uses a different bit in the same word. 18243446Smrj */ 18253446Smrj if (*ecx & CPUID_INTC_ECX_AHF64) 18263446Smrj hwcap_flags |= AV_386_AHF; 18273446Smrj break; 18283446Smrj 18293446Smrj default: 18303446Smrj break; 18313446Smrj } 18320Sstevel@tonic-gate break; 18330Sstevel@tonic-gate 18340Sstevel@tonic-gate case X86_VENDOR_TM: 18351228Sandrei cp.cp_eax = 0x80860001; 18361228Sandrei (void) __cpuid_insn(&cp); 18371228Sandrei cpi->cpi_support[TM_EDX_FEATURES] = cp.cp_edx; 18380Sstevel@tonic-gate break; 18390Sstevel@tonic-gate 18400Sstevel@tonic-gate default: 18410Sstevel@tonic-gate break; 18420Sstevel@tonic-gate } 18430Sstevel@tonic-gate 18440Sstevel@tonic-gate pass4_done: 18450Sstevel@tonic-gate cpi->cpi_pass = 4; 18460Sstevel@tonic-gate return (hwcap_flags); 18470Sstevel@tonic-gate } 18480Sstevel@tonic-gate 18490Sstevel@tonic-gate 18500Sstevel@tonic-gate /* 18510Sstevel@tonic-gate * Simulate the cpuid instruction using the data we previously 18520Sstevel@tonic-gate * captured about this CPU. We try our best to return the truth 18530Sstevel@tonic-gate * about the hardware, independently of kernel support. 18540Sstevel@tonic-gate */ 18550Sstevel@tonic-gate uint32_t 18561228Sandrei cpuid_insn(cpu_t *cpu, struct cpuid_regs *cp) 18570Sstevel@tonic-gate { 18580Sstevel@tonic-gate struct cpuid_info *cpi; 18591228Sandrei struct cpuid_regs *xcp; 18600Sstevel@tonic-gate 18610Sstevel@tonic-gate if (cpu == NULL) 18620Sstevel@tonic-gate cpu = CPU; 18630Sstevel@tonic-gate cpi = cpu->cpu_m.mcpu_cpi; 18640Sstevel@tonic-gate 18650Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 3)); 18660Sstevel@tonic-gate 18670Sstevel@tonic-gate /* 18680Sstevel@tonic-gate * CPUID data is cached in two separate places: cpi_std for standard 18690Sstevel@tonic-gate * CPUID functions, and cpi_extd for extended CPUID functions. 18700Sstevel@tonic-gate */ 18711228Sandrei if (cp->cp_eax <= cpi->cpi_maxeax && cp->cp_eax < NMAX_CPI_STD) 18721228Sandrei xcp = &cpi->cpi_std[cp->cp_eax]; 18731228Sandrei else if (cp->cp_eax >= 0x80000000 && cp->cp_eax <= cpi->cpi_xmaxeax && 18741228Sandrei cp->cp_eax < 0x80000000 + NMAX_CPI_EXTD) 18751228Sandrei xcp = &cpi->cpi_extd[cp->cp_eax - 0x80000000]; 18760Sstevel@tonic-gate else 18770Sstevel@tonic-gate /* 18780Sstevel@tonic-gate * The caller is asking for data from an input parameter which 18790Sstevel@tonic-gate * the kernel has not cached. In this case we go fetch from 18800Sstevel@tonic-gate * the hardware and return the data directly to the user. 18810Sstevel@tonic-gate */ 18821228Sandrei return (__cpuid_insn(cp)); 18831228Sandrei 18841228Sandrei cp->cp_eax = xcp->cp_eax; 18851228Sandrei cp->cp_ebx = xcp->cp_ebx; 18861228Sandrei cp->cp_ecx = xcp->cp_ecx; 18871228Sandrei cp->cp_edx = xcp->cp_edx; 18880Sstevel@tonic-gate return (cp->cp_eax); 18890Sstevel@tonic-gate } 18900Sstevel@tonic-gate 18910Sstevel@tonic-gate int 18920Sstevel@tonic-gate cpuid_checkpass(cpu_t *cpu, int pass) 18930Sstevel@tonic-gate { 18940Sstevel@tonic-gate return (cpu != NULL && cpu->cpu_m.mcpu_cpi != NULL && 18950Sstevel@tonic-gate cpu->cpu_m.mcpu_cpi->cpi_pass >= pass); 18960Sstevel@tonic-gate } 18970Sstevel@tonic-gate 18980Sstevel@tonic-gate int 18990Sstevel@tonic-gate cpuid_getbrandstr(cpu_t *cpu, char *s, size_t n) 19000Sstevel@tonic-gate { 19010Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 3)); 19020Sstevel@tonic-gate 19030Sstevel@tonic-gate return (snprintf(s, n, "%s", cpu->cpu_m.mcpu_cpi->cpi_brandstr)); 19040Sstevel@tonic-gate } 19050Sstevel@tonic-gate 19060Sstevel@tonic-gate int 19071228Sandrei cpuid_is_cmt(cpu_t *cpu) 19080Sstevel@tonic-gate { 19090Sstevel@tonic-gate if (cpu == NULL) 19100Sstevel@tonic-gate cpu = CPU; 19110Sstevel@tonic-gate 19120Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 19130Sstevel@tonic-gate 19140Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_chipid >= 0); 19150Sstevel@tonic-gate } 19160Sstevel@tonic-gate 19170Sstevel@tonic-gate /* 19180Sstevel@tonic-gate * AMD and Intel both implement the 64-bit variant of the syscall 19190Sstevel@tonic-gate * instruction (syscallq), so if there's -any- support for syscall, 19200Sstevel@tonic-gate * cpuid currently says "yes, we support this". 19210Sstevel@tonic-gate * 19220Sstevel@tonic-gate * However, Intel decided to -not- implement the 32-bit variant of the 19230Sstevel@tonic-gate * syscall instruction, so we provide a predicate to allow our caller 19240Sstevel@tonic-gate * to test that subtlety here. 19250Sstevel@tonic-gate */ 19260Sstevel@tonic-gate /*ARGSUSED*/ 19270Sstevel@tonic-gate int 19280Sstevel@tonic-gate cpuid_syscall32_insn(cpu_t *cpu) 19290Sstevel@tonic-gate { 19300Sstevel@tonic-gate ASSERT(cpuid_checkpass((cpu == NULL ? CPU : cpu), 1)); 19310Sstevel@tonic-gate 19323446Smrj if (cpu == NULL) 19333446Smrj cpu = CPU; 19343446Smrj 19353446Smrj /*CSTYLED*/ 19363446Smrj { 19373446Smrj struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 19383446Smrj 19393446Smrj if (cpi->cpi_vendor == X86_VENDOR_AMD && 19403446Smrj cpi->cpi_xmaxeax >= 0x80000001 && 19413446Smrj (CPI_FEATURES_XTD_EDX(cpi) & CPUID_AMD_EDX_SYSC)) 19423446Smrj return (1); 19433446Smrj } 19440Sstevel@tonic-gate return (0); 19450Sstevel@tonic-gate } 19460Sstevel@tonic-gate 19470Sstevel@tonic-gate int 19480Sstevel@tonic-gate cpuid_getidstr(cpu_t *cpu, char *s, size_t n) 19490Sstevel@tonic-gate { 19500Sstevel@tonic-gate struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 19510Sstevel@tonic-gate 19520Sstevel@tonic-gate static const char fmt[] = 19533779Sdmick "x86 (%s %X family %d model %d step %d clock %d MHz)"; 19540Sstevel@tonic-gate static const char fmt_ht[] = 19553779Sdmick "x86 (chipid 0x%x %s %X family %d model %d step %d clock %d MHz)"; 19560Sstevel@tonic-gate 19570Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 19580Sstevel@tonic-gate 19591228Sandrei if (cpuid_is_cmt(cpu)) 19600Sstevel@tonic-gate return (snprintf(s, n, fmt_ht, cpi->cpi_chipid, 19613779Sdmick cpi->cpi_vendorstr, cpi->cpi_std[1].cp_eax, 19623779Sdmick cpi->cpi_family, cpi->cpi_model, 19630Sstevel@tonic-gate cpi->cpi_step, cpu->cpu_type_info.pi_clock)); 19640Sstevel@tonic-gate return (snprintf(s, n, fmt, 19653779Sdmick cpi->cpi_vendorstr, cpi->cpi_std[1].cp_eax, 19663779Sdmick cpi->cpi_family, cpi->cpi_model, 19670Sstevel@tonic-gate cpi->cpi_step, cpu->cpu_type_info.pi_clock)); 19680Sstevel@tonic-gate } 19690Sstevel@tonic-gate 19700Sstevel@tonic-gate const char * 19710Sstevel@tonic-gate cpuid_getvendorstr(cpu_t *cpu) 19720Sstevel@tonic-gate { 19730Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 19740Sstevel@tonic-gate return ((const char *)cpu->cpu_m.mcpu_cpi->cpi_vendorstr); 19750Sstevel@tonic-gate } 19760Sstevel@tonic-gate 19770Sstevel@tonic-gate uint_t 19780Sstevel@tonic-gate cpuid_getvendor(cpu_t *cpu) 19790Sstevel@tonic-gate { 19800Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 19810Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_vendor); 19820Sstevel@tonic-gate } 19830Sstevel@tonic-gate 19840Sstevel@tonic-gate uint_t 19850Sstevel@tonic-gate cpuid_getfamily(cpu_t *cpu) 19860Sstevel@tonic-gate { 19870Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 19880Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_family); 19890Sstevel@tonic-gate } 19900Sstevel@tonic-gate 19910Sstevel@tonic-gate uint_t 19920Sstevel@tonic-gate cpuid_getmodel(cpu_t *cpu) 19930Sstevel@tonic-gate { 19940Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 19950Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_model); 19960Sstevel@tonic-gate } 19970Sstevel@tonic-gate 19980Sstevel@tonic-gate uint_t 19990Sstevel@tonic-gate cpuid_get_ncpu_per_chip(cpu_t *cpu) 20000Sstevel@tonic-gate { 20010Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 20020Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_ncpu_per_chip); 20030Sstevel@tonic-gate } 20040Sstevel@tonic-gate 20050Sstevel@tonic-gate uint_t 20061228Sandrei cpuid_get_ncore_per_chip(cpu_t *cpu) 20071228Sandrei { 20081228Sandrei ASSERT(cpuid_checkpass(cpu, 1)); 20091228Sandrei return (cpu->cpu_m.mcpu_cpi->cpi_ncore_per_chip); 20101228Sandrei } 20111228Sandrei 20121228Sandrei uint_t 20130Sstevel@tonic-gate cpuid_getstep(cpu_t *cpu) 20140Sstevel@tonic-gate { 20150Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 20160Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_step); 20170Sstevel@tonic-gate } 20180Sstevel@tonic-gate 20192869Sgavinm uint32_t 20202869Sgavinm cpuid_getchiprev(struct cpu *cpu) 20212869Sgavinm { 20222869Sgavinm ASSERT(cpuid_checkpass(cpu, 1)); 20232869Sgavinm return (cpu->cpu_m.mcpu_cpi->cpi_chiprev); 20242869Sgavinm } 20252869Sgavinm 20262869Sgavinm const char * 20272869Sgavinm cpuid_getchiprevstr(struct cpu *cpu) 20282869Sgavinm { 20292869Sgavinm ASSERT(cpuid_checkpass(cpu, 1)); 20302869Sgavinm return (cpu->cpu_m.mcpu_cpi->cpi_chiprevstr); 20312869Sgavinm } 20322869Sgavinm 20332869Sgavinm uint32_t 20342869Sgavinm cpuid_getsockettype(struct cpu *cpu) 20352869Sgavinm { 20362869Sgavinm ASSERT(cpuid_checkpass(cpu, 1)); 20372869Sgavinm return (cpu->cpu_m.mcpu_cpi->cpi_socket); 20382869Sgavinm } 20392869Sgavinm 20403434Sesaxe int 20413434Sesaxe cpuid_get_chipid(cpu_t *cpu) 20420Sstevel@tonic-gate { 20430Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 20440Sstevel@tonic-gate 20451228Sandrei if (cpuid_is_cmt(cpu)) 20460Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_chipid); 20470Sstevel@tonic-gate return (cpu->cpu_id); 20480Sstevel@tonic-gate } 20490Sstevel@tonic-gate 20501228Sandrei id_t 20513434Sesaxe cpuid_get_coreid(cpu_t *cpu) 20521228Sandrei { 20531228Sandrei ASSERT(cpuid_checkpass(cpu, 1)); 20541228Sandrei return (cpu->cpu_m.mcpu_cpi->cpi_coreid); 20551228Sandrei } 20561228Sandrei 20570Sstevel@tonic-gate int 20583434Sesaxe cpuid_get_clogid(cpu_t *cpu) 20590Sstevel@tonic-gate { 20600Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 20610Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_clogid); 20620Sstevel@tonic-gate } 20630Sstevel@tonic-gate 20640Sstevel@tonic-gate void 20650Sstevel@tonic-gate cpuid_get_addrsize(cpu_t *cpu, uint_t *pabits, uint_t *vabits) 20660Sstevel@tonic-gate { 20670Sstevel@tonic-gate struct cpuid_info *cpi; 20680Sstevel@tonic-gate 20690Sstevel@tonic-gate if (cpu == NULL) 20700Sstevel@tonic-gate cpu = CPU; 20710Sstevel@tonic-gate cpi = cpu->cpu_m.mcpu_cpi; 20720Sstevel@tonic-gate 20730Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 20740Sstevel@tonic-gate 20750Sstevel@tonic-gate if (pabits) 20760Sstevel@tonic-gate *pabits = cpi->cpi_pabits; 20770Sstevel@tonic-gate if (vabits) 20780Sstevel@tonic-gate *vabits = cpi->cpi_vabits; 20790Sstevel@tonic-gate } 20800Sstevel@tonic-gate 20810Sstevel@tonic-gate /* 20820Sstevel@tonic-gate * Returns the number of data TLB entries for a corresponding 20830Sstevel@tonic-gate * pagesize. If it can't be computed, or isn't known, the 20840Sstevel@tonic-gate * routine returns zero. If you ask about an architecturally 20850Sstevel@tonic-gate * impossible pagesize, the routine will panic (so that the 20860Sstevel@tonic-gate * hat implementor knows that things are inconsistent.) 20870Sstevel@tonic-gate */ 20880Sstevel@tonic-gate uint_t 20890Sstevel@tonic-gate cpuid_get_dtlb_nent(cpu_t *cpu, size_t pagesize) 20900Sstevel@tonic-gate { 20910Sstevel@tonic-gate struct cpuid_info *cpi; 20920Sstevel@tonic-gate uint_t dtlb_nent = 0; 20930Sstevel@tonic-gate 20940Sstevel@tonic-gate if (cpu == NULL) 20950Sstevel@tonic-gate cpu = CPU; 20960Sstevel@tonic-gate cpi = cpu->cpu_m.mcpu_cpi; 20970Sstevel@tonic-gate 20980Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 20990Sstevel@tonic-gate 21000Sstevel@tonic-gate /* 21010Sstevel@tonic-gate * Check the L2 TLB info 21020Sstevel@tonic-gate */ 21030Sstevel@tonic-gate if (cpi->cpi_xmaxeax >= 0x80000006) { 21041228Sandrei struct cpuid_regs *cp = &cpi->cpi_extd[6]; 21050Sstevel@tonic-gate 21060Sstevel@tonic-gate switch (pagesize) { 21070Sstevel@tonic-gate 21080Sstevel@tonic-gate case 4 * 1024: 21090Sstevel@tonic-gate /* 21100Sstevel@tonic-gate * All zero in the top 16 bits of the register 21110Sstevel@tonic-gate * indicates a unified TLB. Size is in low 16 bits. 21120Sstevel@tonic-gate */ 21130Sstevel@tonic-gate if ((cp->cp_ebx & 0xffff0000) == 0) 21140Sstevel@tonic-gate dtlb_nent = cp->cp_ebx & 0x0000ffff; 21150Sstevel@tonic-gate else 21160Sstevel@tonic-gate dtlb_nent = BITX(cp->cp_ebx, 27, 16); 21170Sstevel@tonic-gate break; 21180Sstevel@tonic-gate 21190Sstevel@tonic-gate case 2 * 1024 * 1024: 21200Sstevel@tonic-gate if ((cp->cp_eax & 0xffff0000) == 0) 21210Sstevel@tonic-gate dtlb_nent = cp->cp_eax & 0x0000ffff; 21220Sstevel@tonic-gate else 21230Sstevel@tonic-gate dtlb_nent = BITX(cp->cp_eax, 27, 16); 21240Sstevel@tonic-gate break; 21250Sstevel@tonic-gate 21260Sstevel@tonic-gate default: 21270Sstevel@tonic-gate panic("unknown L2 pagesize"); 21280Sstevel@tonic-gate /*NOTREACHED*/ 21290Sstevel@tonic-gate } 21300Sstevel@tonic-gate } 21310Sstevel@tonic-gate 21320Sstevel@tonic-gate if (dtlb_nent != 0) 21330Sstevel@tonic-gate return (dtlb_nent); 21340Sstevel@tonic-gate 21350Sstevel@tonic-gate /* 21360Sstevel@tonic-gate * No L2 TLB support for this size, try L1. 21370Sstevel@tonic-gate */ 21380Sstevel@tonic-gate if (cpi->cpi_xmaxeax >= 0x80000005) { 21391228Sandrei struct cpuid_regs *cp = &cpi->cpi_extd[5]; 21400Sstevel@tonic-gate 21410Sstevel@tonic-gate switch (pagesize) { 21420Sstevel@tonic-gate case 4 * 1024: 21430Sstevel@tonic-gate dtlb_nent = BITX(cp->cp_ebx, 23, 16); 21440Sstevel@tonic-gate break; 21450Sstevel@tonic-gate case 2 * 1024 * 1024: 21460Sstevel@tonic-gate dtlb_nent = BITX(cp->cp_eax, 23, 16); 21470Sstevel@tonic-gate break; 21480Sstevel@tonic-gate default: 21490Sstevel@tonic-gate panic("unknown L1 d-TLB pagesize"); 21500Sstevel@tonic-gate /*NOTREACHED*/ 21510Sstevel@tonic-gate } 21520Sstevel@tonic-gate } 21530Sstevel@tonic-gate 21540Sstevel@tonic-gate return (dtlb_nent); 21550Sstevel@tonic-gate } 21560Sstevel@tonic-gate 21570Sstevel@tonic-gate /* 21580Sstevel@tonic-gate * Return 0 if the erratum is not present or not applicable, positive 21590Sstevel@tonic-gate * if it is, and negative if the status of the erratum is unknown. 21600Sstevel@tonic-gate * 21610Sstevel@tonic-gate * See "Revision Guide for AMD Athlon(tm) 64 and AMD Opteron(tm) 2162359Skucharsk * Processors" #25759, Rev 3.57, August 2005 21630Sstevel@tonic-gate */ 21640Sstevel@tonic-gate int 21650Sstevel@tonic-gate cpuid_opteron_erratum(cpu_t *cpu, uint_t erratum) 21660Sstevel@tonic-gate { 21670Sstevel@tonic-gate struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 21681228Sandrei uint_t eax; 21690Sstevel@tonic-gate 21702584Ssethg /* 21712584Ssethg * Bail out if this CPU isn't an AMD CPU, or if it's 21722584Ssethg * a legacy (32-bit) AMD CPU. 21732584Ssethg */ 21742584Ssethg if (cpi->cpi_vendor != X86_VENDOR_AMD || 21754265Skchow cpi->cpi_family == 4 || cpi->cpi_family == 5 || 21764265Skchow cpi->cpi_family == 6) 21772869Sgavinm 21780Sstevel@tonic-gate return (0); 21790Sstevel@tonic-gate 21800Sstevel@tonic-gate eax = cpi->cpi_std[1].cp_eax; 21810Sstevel@tonic-gate 21820Sstevel@tonic-gate #define SH_B0(eax) (eax == 0xf40 || eax == 0xf50) 21830Sstevel@tonic-gate #define SH_B3(eax) (eax == 0xf51) 21841582Skchow #define B(eax) (SH_B0(eax) || SH_B3(eax)) 21850Sstevel@tonic-gate 21860Sstevel@tonic-gate #define SH_C0(eax) (eax == 0xf48 || eax == 0xf58) 21870Sstevel@tonic-gate 21880Sstevel@tonic-gate #define SH_CG(eax) (eax == 0xf4a || eax == 0xf5a || eax == 0xf7a) 21890Sstevel@tonic-gate #define DH_CG(eax) (eax == 0xfc0 || eax == 0xfe0 || eax == 0xff0) 21900Sstevel@tonic-gate #define CH_CG(eax) (eax == 0xf82 || eax == 0xfb2) 21911582Skchow #define CG(eax) (SH_CG(eax) || DH_CG(eax) || CH_CG(eax)) 21920Sstevel@tonic-gate 21930Sstevel@tonic-gate #define SH_D0(eax) (eax == 0x10f40 || eax == 0x10f50 || eax == 0x10f70) 21940Sstevel@tonic-gate #define DH_D0(eax) (eax == 0x10fc0 || eax == 0x10ff0) 21950Sstevel@tonic-gate #define CH_D0(eax) (eax == 0x10f80 || eax == 0x10fb0) 21961582Skchow #define D0(eax) (SH_D0(eax) || DH_D0(eax) || CH_D0(eax)) 21970Sstevel@tonic-gate 21980Sstevel@tonic-gate #define SH_E0(eax) (eax == 0x20f50 || eax == 0x20f40 || eax == 0x20f70) 21990Sstevel@tonic-gate #define JH_E1(eax) (eax == 0x20f10) /* JH8_E0 had 0x20f30 */ 22000Sstevel@tonic-gate #define DH_E3(eax) (eax == 0x20fc0 || eax == 0x20ff0) 22010Sstevel@tonic-gate #define SH_E4(eax) (eax == 0x20f51 || eax == 0x20f71) 22020Sstevel@tonic-gate #define BH_E4(eax) (eax == 0x20fb1) 22030Sstevel@tonic-gate #define SH_E5(eax) (eax == 0x20f42) 22040Sstevel@tonic-gate #define DH_E6(eax) (eax == 0x20ff2 || eax == 0x20fc2) 22050Sstevel@tonic-gate #define JH_E6(eax) (eax == 0x20f12 || eax == 0x20f32) 22061582Skchow #define EX(eax) (SH_E0(eax) || JH_E1(eax) || DH_E3(eax) || \ 22071582Skchow SH_E4(eax) || BH_E4(eax) || SH_E5(eax) || \ 22081582Skchow DH_E6(eax) || JH_E6(eax)) 22090Sstevel@tonic-gate 22100Sstevel@tonic-gate switch (erratum) { 22110Sstevel@tonic-gate case 1: 22124265Skchow return (cpi->cpi_family < 0x10); 22130Sstevel@tonic-gate case 51: /* what does the asterisk mean? */ 22140Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax)); 22150Sstevel@tonic-gate case 52: 22160Sstevel@tonic-gate return (B(eax)); 22170Sstevel@tonic-gate case 57: 22184265Skchow return (cpi->cpi_family <= 0x10); 22190Sstevel@tonic-gate case 58: 22200Sstevel@tonic-gate return (B(eax)); 22210Sstevel@tonic-gate case 60: 22224265Skchow return (cpi->cpi_family <= 0x10); 22230Sstevel@tonic-gate case 61: 22240Sstevel@tonic-gate case 62: 22250Sstevel@tonic-gate case 63: 22260Sstevel@tonic-gate case 64: 22270Sstevel@tonic-gate case 65: 22280Sstevel@tonic-gate case 66: 22290Sstevel@tonic-gate case 68: 22300Sstevel@tonic-gate case 69: 22310Sstevel@tonic-gate case 70: 22320Sstevel@tonic-gate case 71: 22330Sstevel@tonic-gate return (B(eax)); 22340Sstevel@tonic-gate case 72: 22350Sstevel@tonic-gate return (SH_B0(eax)); 22360Sstevel@tonic-gate case 74: 22370Sstevel@tonic-gate return (B(eax)); 22380Sstevel@tonic-gate case 75: 22394265Skchow return (cpi->cpi_family < 0x10); 22400Sstevel@tonic-gate case 76: 22410Sstevel@tonic-gate return (B(eax)); 22420Sstevel@tonic-gate case 77: 22434265Skchow return (cpi->cpi_family <= 0x10); 22440Sstevel@tonic-gate case 78: 22450Sstevel@tonic-gate return (B(eax) || SH_C0(eax)); 22460Sstevel@tonic-gate case 79: 22470Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax) || EX(eax)); 22480Sstevel@tonic-gate case 80: 22490Sstevel@tonic-gate case 81: 22500Sstevel@tonic-gate case 82: 22510Sstevel@tonic-gate return (B(eax)); 22520Sstevel@tonic-gate case 83: 22530Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax)); 22540Sstevel@tonic-gate case 85: 22554265Skchow return (cpi->cpi_family < 0x10); 22560Sstevel@tonic-gate case 86: 22570Sstevel@tonic-gate return (SH_C0(eax) || CG(eax)); 22580Sstevel@tonic-gate case 88: 22590Sstevel@tonic-gate #if !defined(__amd64) 22600Sstevel@tonic-gate return (0); 22610Sstevel@tonic-gate #else 22620Sstevel@tonic-gate return (B(eax) || SH_C0(eax)); 22630Sstevel@tonic-gate #endif 22640Sstevel@tonic-gate case 89: 22654265Skchow return (cpi->cpi_family < 0x10); 22660Sstevel@tonic-gate case 90: 22670Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax)); 22680Sstevel@tonic-gate case 91: 22690Sstevel@tonic-gate case 92: 22700Sstevel@tonic-gate return (B(eax) || SH_C0(eax)); 22710Sstevel@tonic-gate case 93: 22720Sstevel@tonic-gate return (SH_C0(eax)); 22730Sstevel@tonic-gate case 94: 22740Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax)); 22750Sstevel@tonic-gate case 95: 22760Sstevel@tonic-gate #if !defined(__amd64) 22770Sstevel@tonic-gate return (0); 22780Sstevel@tonic-gate #else 22790Sstevel@tonic-gate return (B(eax) || SH_C0(eax)); 22800Sstevel@tonic-gate #endif 22810Sstevel@tonic-gate case 96: 22820Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax)); 22830Sstevel@tonic-gate case 97: 22840Sstevel@tonic-gate case 98: 22850Sstevel@tonic-gate return (SH_C0(eax) || CG(eax)); 22860Sstevel@tonic-gate case 99: 22870Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax)); 22880Sstevel@tonic-gate case 100: 22890Sstevel@tonic-gate return (B(eax) || SH_C0(eax)); 22900Sstevel@tonic-gate case 101: 22910Sstevel@tonic-gate case 103: 22920Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax)); 22930Sstevel@tonic-gate case 104: 22940Sstevel@tonic-gate return (SH_C0(eax) || CG(eax) || D0(eax)); 22950Sstevel@tonic-gate case 105: 22960Sstevel@tonic-gate case 106: 22970Sstevel@tonic-gate case 107: 22980Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax)); 22990Sstevel@tonic-gate case 108: 23000Sstevel@tonic-gate return (DH_CG(eax)); 23010Sstevel@tonic-gate case 109: 23020Sstevel@tonic-gate return (SH_C0(eax) || CG(eax) || D0(eax)); 23030Sstevel@tonic-gate case 110: 23040Sstevel@tonic-gate return (D0(eax) || EX(eax)); 23050Sstevel@tonic-gate case 111: 23060Sstevel@tonic-gate return (CG(eax)); 23070Sstevel@tonic-gate case 112: 23080Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax) || EX(eax)); 23090Sstevel@tonic-gate case 113: 23100Sstevel@tonic-gate return (eax == 0x20fc0); 23110Sstevel@tonic-gate case 114: 23120Sstevel@tonic-gate return (SH_E0(eax) || JH_E1(eax) || DH_E3(eax)); 23130Sstevel@tonic-gate case 115: 23140Sstevel@tonic-gate return (SH_E0(eax) || JH_E1(eax)); 23150Sstevel@tonic-gate case 116: 23160Sstevel@tonic-gate return (SH_E0(eax) || JH_E1(eax) || DH_E3(eax)); 23170Sstevel@tonic-gate case 117: 23180Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax)); 23190Sstevel@tonic-gate case 118: 23200Sstevel@tonic-gate return (SH_E0(eax) || JH_E1(eax) || SH_E4(eax) || BH_E4(eax) || 23210Sstevel@tonic-gate JH_E6(eax)); 23220Sstevel@tonic-gate case 121: 23230Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax) || EX(eax)); 23240Sstevel@tonic-gate case 122: 23254265Skchow return (cpi->cpi_family < 0x10); 23260Sstevel@tonic-gate case 123: 23270Sstevel@tonic-gate return (JH_E1(eax) || BH_E4(eax) || JH_E6(eax)); 2328359Skucharsk case 131: 23294265Skchow return (cpi->cpi_family < 0x10); 2330938Sesaxe case 6336786: 2331938Sesaxe /* 2332938Sesaxe * Test for AdvPowerMgmtInfo.TscPStateInvariant 23334265Skchow * if this is a K8 family or newer processor 2334938Sesaxe */ 2335938Sesaxe if (CPI_FAMILY(cpi) == 0xf) { 23361228Sandrei struct cpuid_regs regs; 23371228Sandrei regs.cp_eax = 0x80000007; 23381228Sandrei (void) __cpuid_insn(®s); 23391228Sandrei return (!(regs.cp_edx & 0x100)); 2340938Sesaxe } 2341938Sesaxe return (0); 23421582Skchow case 6323525: 23431582Skchow return (((((eax >> 12) & 0xff00) + (eax & 0xf00)) | 23441582Skchow (((eax >> 4) & 0xf) | ((eax >> 12) & 0xf0))) < 0xf40); 23451582Skchow 23460Sstevel@tonic-gate default: 23470Sstevel@tonic-gate return (-1); 23480Sstevel@tonic-gate } 23490Sstevel@tonic-gate } 23500Sstevel@tonic-gate 23510Sstevel@tonic-gate static const char assoc_str[] = "associativity"; 23520Sstevel@tonic-gate static const char line_str[] = "line-size"; 23530Sstevel@tonic-gate static const char size_str[] = "size"; 23540Sstevel@tonic-gate 23550Sstevel@tonic-gate static void 23560Sstevel@tonic-gate add_cache_prop(dev_info_t *devi, const char *label, const char *type, 23570Sstevel@tonic-gate uint32_t val) 23580Sstevel@tonic-gate { 23590Sstevel@tonic-gate char buf[128]; 23600Sstevel@tonic-gate 23610Sstevel@tonic-gate /* 23620Sstevel@tonic-gate * ndi_prop_update_int() is used because it is desirable for 23630Sstevel@tonic-gate * DDI_PROP_HW_DEF and DDI_PROP_DONTSLEEP to be set. 23640Sstevel@tonic-gate */ 23650Sstevel@tonic-gate if (snprintf(buf, sizeof (buf), "%s-%s", label, type) < sizeof (buf)) 23660Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, devi, buf, val); 23670Sstevel@tonic-gate } 23680Sstevel@tonic-gate 23690Sstevel@tonic-gate /* 23700Sstevel@tonic-gate * Intel-style cache/tlb description 23710Sstevel@tonic-gate * 23720Sstevel@tonic-gate * Standard cpuid level 2 gives a randomly ordered 23730Sstevel@tonic-gate * selection of tags that index into a table that describes 23740Sstevel@tonic-gate * cache and tlb properties. 23750Sstevel@tonic-gate */ 23760Sstevel@tonic-gate 23770Sstevel@tonic-gate static const char l1_icache_str[] = "l1-icache"; 23780Sstevel@tonic-gate static const char l1_dcache_str[] = "l1-dcache"; 23790Sstevel@tonic-gate static const char l2_cache_str[] = "l2-cache"; 23803446Smrj static const char l3_cache_str[] = "l3-cache"; 23810Sstevel@tonic-gate static const char itlb4k_str[] = "itlb-4K"; 23820Sstevel@tonic-gate static const char dtlb4k_str[] = "dtlb-4K"; 23830Sstevel@tonic-gate static const char itlb4M_str[] = "itlb-4M"; 23840Sstevel@tonic-gate static const char dtlb4M_str[] = "dtlb-4M"; 23850Sstevel@tonic-gate static const char itlb424_str[] = "itlb-4K-2M-4M"; 23860Sstevel@tonic-gate static const char dtlb44_str[] = "dtlb-4K-4M"; 23870Sstevel@tonic-gate static const char sl1_dcache_str[] = "sectored-l1-dcache"; 23880Sstevel@tonic-gate static const char sl2_cache_str[] = "sectored-l2-cache"; 23890Sstevel@tonic-gate static const char itrace_str[] = "itrace-cache"; 23900Sstevel@tonic-gate static const char sl3_cache_str[] = "sectored-l3-cache"; 23910Sstevel@tonic-gate 23920Sstevel@tonic-gate static const struct cachetab { 23930Sstevel@tonic-gate uint8_t ct_code; 23940Sstevel@tonic-gate uint8_t ct_assoc; 23950Sstevel@tonic-gate uint16_t ct_line_size; 23960Sstevel@tonic-gate size_t ct_size; 23970Sstevel@tonic-gate const char *ct_label; 23980Sstevel@tonic-gate } intel_ctab[] = { 23990Sstevel@tonic-gate /* maintain descending order! */ 24003446Smrj { 0xb4, 4, 0, 256, dtlb4k_str }, 24010Sstevel@tonic-gate { 0xb3, 4, 0, 128, dtlb4k_str }, 24020Sstevel@tonic-gate { 0xb0, 4, 0, 128, itlb4k_str }, 24030Sstevel@tonic-gate { 0x87, 8, 64, 1024*1024, l2_cache_str}, 24040Sstevel@tonic-gate { 0x86, 4, 64, 512*1024, l2_cache_str}, 24050Sstevel@tonic-gate { 0x85, 8, 32, 2*1024*1024, l2_cache_str}, 24060Sstevel@tonic-gate { 0x84, 8, 32, 1024*1024, l2_cache_str}, 24070Sstevel@tonic-gate { 0x83, 8, 32, 512*1024, l2_cache_str}, 24080Sstevel@tonic-gate { 0x82, 8, 32, 256*1024, l2_cache_str}, 24090Sstevel@tonic-gate { 0x7f, 2, 64, 512*1024, l2_cache_str}, 24100Sstevel@tonic-gate { 0x7d, 8, 64, 2*1024*1024, sl2_cache_str}, 24110Sstevel@tonic-gate { 0x7c, 8, 64, 1024*1024, sl2_cache_str}, 24120Sstevel@tonic-gate { 0x7b, 8, 64, 512*1024, sl2_cache_str}, 24130Sstevel@tonic-gate { 0x7a, 8, 64, 256*1024, sl2_cache_str}, 24140Sstevel@tonic-gate { 0x79, 8, 64, 128*1024, sl2_cache_str}, 24150Sstevel@tonic-gate { 0x78, 8, 64, 1024*1024, l2_cache_str}, 24163446Smrj { 0x73, 8, 0, 64*1024, itrace_str}, 24170Sstevel@tonic-gate { 0x72, 8, 0, 32*1024, itrace_str}, 24180Sstevel@tonic-gate { 0x71, 8, 0, 16*1024, itrace_str}, 24190Sstevel@tonic-gate { 0x70, 8, 0, 12*1024, itrace_str}, 24200Sstevel@tonic-gate { 0x68, 4, 64, 32*1024, sl1_dcache_str}, 24210Sstevel@tonic-gate { 0x67, 4, 64, 16*1024, sl1_dcache_str}, 24220Sstevel@tonic-gate { 0x66, 4, 64, 8*1024, sl1_dcache_str}, 24230Sstevel@tonic-gate { 0x60, 8, 64, 16*1024, sl1_dcache_str}, 24240Sstevel@tonic-gate { 0x5d, 0, 0, 256, dtlb44_str}, 24250Sstevel@tonic-gate { 0x5c, 0, 0, 128, dtlb44_str}, 24260Sstevel@tonic-gate { 0x5b, 0, 0, 64, dtlb44_str}, 24270Sstevel@tonic-gate { 0x52, 0, 0, 256, itlb424_str}, 24280Sstevel@tonic-gate { 0x51, 0, 0, 128, itlb424_str}, 24290Sstevel@tonic-gate { 0x50, 0, 0, 64, itlb424_str}, 24303446Smrj { 0x4d, 16, 64, 16*1024*1024, l3_cache_str}, 24313446Smrj { 0x4c, 12, 64, 12*1024*1024, l3_cache_str}, 24323446Smrj { 0x4b, 16, 64, 8*1024*1024, l3_cache_str}, 24333446Smrj { 0x4a, 12, 64, 6*1024*1024, l3_cache_str}, 24343446Smrj { 0x49, 16, 64, 4*1024*1024, l3_cache_str}, 24353446Smrj { 0x47, 8, 64, 8*1024*1024, l3_cache_str}, 24363446Smrj { 0x46, 4, 64, 4*1024*1024, l3_cache_str}, 24370Sstevel@tonic-gate { 0x45, 4, 32, 2*1024*1024, l2_cache_str}, 24380Sstevel@tonic-gate { 0x44, 4, 32, 1024*1024, l2_cache_str}, 24390Sstevel@tonic-gate { 0x43, 4, 32, 512*1024, l2_cache_str}, 24400Sstevel@tonic-gate { 0x42, 4, 32, 256*1024, l2_cache_str}, 24410Sstevel@tonic-gate { 0x41, 4, 32, 128*1024, l2_cache_str}, 24423446Smrj { 0x3e, 4, 64, 512*1024, sl2_cache_str}, 24433446Smrj { 0x3d, 6, 64, 384*1024, sl2_cache_str}, 24440Sstevel@tonic-gate { 0x3c, 4, 64, 256*1024, sl2_cache_str}, 24450Sstevel@tonic-gate { 0x3b, 2, 64, 128*1024, sl2_cache_str}, 24463446Smrj { 0x3a, 6, 64, 192*1024, sl2_cache_str}, 24470Sstevel@tonic-gate { 0x39, 4, 64, 128*1024, sl2_cache_str}, 24480Sstevel@tonic-gate { 0x30, 8, 64, 32*1024, l1_icache_str}, 24490Sstevel@tonic-gate { 0x2c, 8, 64, 32*1024, l1_dcache_str}, 24500Sstevel@tonic-gate { 0x29, 8, 64, 4096*1024, sl3_cache_str}, 24510Sstevel@tonic-gate { 0x25, 8, 64, 2048*1024, sl3_cache_str}, 24520Sstevel@tonic-gate { 0x23, 8, 64, 1024*1024, sl3_cache_str}, 24530Sstevel@tonic-gate { 0x22, 4, 64, 512*1024, sl3_cache_str}, 24540Sstevel@tonic-gate { 0x0c, 4, 32, 16*1024, l1_dcache_str}, 24553446Smrj { 0x0b, 4, 0, 4, itlb4M_str}, 24560Sstevel@tonic-gate { 0x0a, 2, 32, 8*1024, l1_dcache_str}, 24570Sstevel@tonic-gate { 0x08, 4, 32, 16*1024, l1_icache_str}, 24580Sstevel@tonic-gate { 0x06, 4, 32, 8*1024, l1_icache_str}, 24590Sstevel@tonic-gate { 0x04, 4, 0, 8, dtlb4M_str}, 24600Sstevel@tonic-gate { 0x03, 4, 0, 64, dtlb4k_str}, 24610Sstevel@tonic-gate { 0x02, 4, 0, 2, itlb4M_str}, 24620Sstevel@tonic-gate { 0x01, 4, 0, 32, itlb4k_str}, 24630Sstevel@tonic-gate { 0 } 24640Sstevel@tonic-gate }; 24650Sstevel@tonic-gate 24660Sstevel@tonic-gate static const struct cachetab cyrix_ctab[] = { 24670Sstevel@tonic-gate { 0x70, 4, 0, 32, "tlb-4K" }, 24680Sstevel@tonic-gate { 0x80, 4, 16, 16*1024, "l1-cache" }, 24690Sstevel@tonic-gate { 0 } 24700Sstevel@tonic-gate }; 24710Sstevel@tonic-gate 24720Sstevel@tonic-gate /* 24730Sstevel@tonic-gate * Search a cache table for a matching entry 24740Sstevel@tonic-gate */ 24750Sstevel@tonic-gate static const struct cachetab * 24760Sstevel@tonic-gate find_cacheent(const struct cachetab *ct, uint_t code) 24770Sstevel@tonic-gate { 24780Sstevel@tonic-gate if (code != 0) { 24790Sstevel@tonic-gate for (; ct->ct_code != 0; ct++) 24800Sstevel@tonic-gate if (ct->ct_code <= code) 24810Sstevel@tonic-gate break; 24820Sstevel@tonic-gate if (ct->ct_code == code) 24830Sstevel@tonic-gate return (ct); 24840Sstevel@tonic-gate } 24850Sstevel@tonic-gate return (NULL); 24860Sstevel@tonic-gate } 24870Sstevel@tonic-gate 24880Sstevel@tonic-gate /* 24890Sstevel@tonic-gate * Walk the cacheinfo descriptor, applying 'func' to every valid element 24900Sstevel@tonic-gate * The walk is terminated if the walker returns non-zero. 24910Sstevel@tonic-gate */ 24920Sstevel@tonic-gate static void 24930Sstevel@tonic-gate intel_walk_cacheinfo(struct cpuid_info *cpi, 24940Sstevel@tonic-gate void *arg, int (*func)(void *, const struct cachetab *)) 24950Sstevel@tonic-gate { 24960Sstevel@tonic-gate const struct cachetab *ct; 24970Sstevel@tonic-gate uint8_t *dp; 24980Sstevel@tonic-gate int i; 24990Sstevel@tonic-gate 25000Sstevel@tonic-gate if ((dp = cpi->cpi_cacheinfo) == NULL) 25010Sstevel@tonic-gate return; 25020Sstevel@tonic-gate for (i = 0; i < cpi->cpi_ncache; i++, dp++) 25030Sstevel@tonic-gate if ((ct = find_cacheent(intel_ctab, *dp)) != NULL) { 25040Sstevel@tonic-gate if (func(arg, ct) != 0) 25050Sstevel@tonic-gate break; 25060Sstevel@tonic-gate } 25070Sstevel@tonic-gate } 25080Sstevel@tonic-gate 25090Sstevel@tonic-gate /* 25100Sstevel@tonic-gate * (Like the Intel one, except for Cyrix CPUs) 25110Sstevel@tonic-gate */ 25120Sstevel@tonic-gate static void 25130Sstevel@tonic-gate cyrix_walk_cacheinfo(struct cpuid_info *cpi, 25140Sstevel@tonic-gate void *arg, int (*func)(void *, const struct cachetab *)) 25150Sstevel@tonic-gate { 25160Sstevel@tonic-gate const struct cachetab *ct; 25170Sstevel@tonic-gate uint8_t *dp; 25180Sstevel@tonic-gate int i; 25190Sstevel@tonic-gate 25200Sstevel@tonic-gate if ((dp = cpi->cpi_cacheinfo) == NULL) 25210Sstevel@tonic-gate return; 25220Sstevel@tonic-gate for (i = 0; i < cpi->cpi_ncache; i++, dp++) { 25230Sstevel@tonic-gate /* 25240Sstevel@tonic-gate * Search Cyrix-specific descriptor table first .. 25250Sstevel@tonic-gate */ 25260Sstevel@tonic-gate if ((ct = find_cacheent(cyrix_ctab, *dp)) != NULL) { 25270Sstevel@tonic-gate if (func(arg, ct) != 0) 25280Sstevel@tonic-gate break; 25290Sstevel@tonic-gate continue; 25300Sstevel@tonic-gate } 25310Sstevel@tonic-gate /* 25320Sstevel@tonic-gate * .. else fall back to the Intel one 25330Sstevel@tonic-gate */ 25340Sstevel@tonic-gate if ((ct = find_cacheent(intel_ctab, *dp)) != NULL) { 25350Sstevel@tonic-gate if (func(arg, ct) != 0) 25360Sstevel@tonic-gate break; 25370Sstevel@tonic-gate continue; 25380Sstevel@tonic-gate } 25390Sstevel@tonic-gate } 25400Sstevel@tonic-gate } 25410Sstevel@tonic-gate 25420Sstevel@tonic-gate /* 25430Sstevel@tonic-gate * A cacheinfo walker that adds associativity, line-size, and size properties 25440Sstevel@tonic-gate * to the devinfo node it is passed as an argument. 25450Sstevel@tonic-gate */ 25460Sstevel@tonic-gate static int 25470Sstevel@tonic-gate add_cacheent_props(void *arg, const struct cachetab *ct) 25480Sstevel@tonic-gate { 25490Sstevel@tonic-gate dev_info_t *devi = arg; 25500Sstevel@tonic-gate 25510Sstevel@tonic-gate add_cache_prop(devi, ct->ct_label, assoc_str, ct->ct_assoc); 25520Sstevel@tonic-gate if (ct->ct_line_size != 0) 25530Sstevel@tonic-gate add_cache_prop(devi, ct->ct_label, line_str, 25540Sstevel@tonic-gate ct->ct_line_size); 25550Sstevel@tonic-gate add_cache_prop(devi, ct->ct_label, size_str, ct->ct_size); 25560Sstevel@tonic-gate return (0); 25570Sstevel@tonic-gate } 25580Sstevel@tonic-gate 25590Sstevel@tonic-gate static const char fully_assoc[] = "fully-associative?"; 25600Sstevel@tonic-gate 25610Sstevel@tonic-gate /* 25620Sstevel@tonic-gate * AMD style cache/tlb description 25630Sstevel@tonic-gate * 25640Sstevel@tonic-gate * Extended functions 5 and 6 directly describe properties of 25650Sstevel@tonic-gate * tlbs and various cache levels. 25660Sstevel@tonic-gate */ 25670Sstevel@tonic-gate static void 25680Sstevel@tonic-gate add_amd_assoc(dev_info_t *devi, const char *label, uint_t assoc) 25690Sstevel@tonic-gate { 25700Sstevel@tonic-gate switch (assoc) { 25710Sstevel@tonic-gate case 0: /* reserved; ignore */ 25720Sstevel@tonic-gate break; 25730Sstevel@tonic-gate default: 25740Sstevel@tonic-gate add_cache_prop(devi, label, assoc_str, assoc); 25750Sstevel@tonic-gate break; 25760Sstevel@tonic-gate case 0xff: 25770Sstevel@tonic-gate add_cache_prop(devi, label, fully_assoc, 1); 25780Sstevel@tonic-gate break; 25790Sstevel@tonic-gate } 25800Sstevel@tonic-gate } 25810Sstevel@tonic-gate 25820Sstevel@tonic-gate static void 25830Sstevel@tonic-gate add_amd_tlb(dev_info_t *devi, const char *label, uint_t assoc, uint_t size) 25840Sstevel@tonic-gate { 25850Sstevel@tonic-gate if (size == 0) 25860Sstevel@tonic-gate return; 25870Sstevel@tonic-gate add_cache_prop(devi, label, size_str, size); 25880Sstevel@tonic-gate add_amd_assoc(devi, label, assoc); 25890Sstevel@tonic-gate } 25900Sstevel@tonic-gate 25910Sstevel@tonic-gate static void 25920Sstevel@tonic-gate add_amd_cache(dev_info_t *devi, const char *label, 25930Sstevel@tonic-gate uint_t size, uint_t assoc, uint_t lines_per_tag, uint_t line_size) 25940Sstevel@tonic-gate { 25950Sstevel@tonic-gate if (size == 0 || line_size == 0) 25960Sstevel@tonic-gate return; 25970Sstevel@tonic-gate add_amd_assoc(devi, label, assoc); 25980Sstevel@tonic-gate /* 25990Sstevel@tonic-gate * Most AMD parts have a sectored cache. Multiple cache lines are 26000Sstevel@tonic-gate * associated with each tag. A sector consists of all cache lines 26010Sstevel@tonic-gate * associated with a tag. For example, the AMD K6-III has a sector 26020Sstevel@tonic-gate * size of 2 cache lines per tag. 26030Sstevel@tonic-gate */ 26040Sstevel@tonic-gate if (lines_per_tag != 0) 26050Sstevel@tonic-gate add_cache_prop(devi, label, "lines-per-tag", lines_per_tag); 26060Sstevel@tonic-gate add_cache_prop(devi, label, line_str, line_size); 26070Sstevel@tonic-gate add_cache_prop(devi, label, size_str, size * 1024); 26080Sstevel@tonic-gate } 26090Sstevel@tonic-gate 26100Sstevel@tonic-gate static void 26110Sstevel@tonic-gate add_amd_l2_assoc(dev_info_t *devi, const char *label, uint_t assoc) 26120Sstevel@tonic-gate { 26130Sstevel@tonic-gate switch (assoc) { 26140Sstevel@tonic-gate case 0: /* off */ 26150Sstevel@tonic-gate break; 26160Sstevel@tonic-gate case 1: 26170Sstevel@tonic-gate case 2: 26180Sstevel@tonic-gate case 4: 26190Sstevel@tonic-gate add_cache_prop(devi, label, assoc_str, assoc); 26200Sstevel@tonic-gate break; 26210Sstevel@tonic-gate case 6: 26220Sstevel@tonic-gate add_cache_prop(devi, label, assoc_str, 8); 26230Sstevel@tonic-gate break; 26240Sstevel@tonic-gate case 8: 26250Sstevel@tonic-gate add_cache_prop(devi, label, assoc_str, 16); 26260Sstevel@tonic-gate break; 26270Sstevel@tonic-gate case 0xf: 26280Sstevel@tonic-gate add_cache_prop(devi, label, fully_assoc, 1); 26290Sstevel@tonic-gate break; 26300Sstevel@tonic-gate default: /* reserved; ignore */ 26310Sstevel@tonic-gate break; 26320Sstevel@tonic-gate } 26330Sstevel@tonic-gate } 26340Sstevel@tonic-gate 26350Sstevel@tonic-gate static void 26360Sstevel@tonic-gate add_amd_l2_tlb(dev_info_t *devi, const char *label, uint_t assoc, uint_t size) 26370Sstevel@tonic-gate { 26380Sstevel@tonic-gate if (size == 0 || assoc == 0) 26390Sstevel@tonic-gate return; 26400Sstevel@tonic-gate add_amd_l2_assoc(devi, label, assoc); 26410Sstevel@tonic-gate add_cache_prop(devi, label, size_str, size); 26420Sstevel@tonic-gate } 26430Sstevel@tonic-gate 26440Sstevel@tonic-gate static void 26450Sstevel@tonic-gate add_amd_l2_cache(dev_info_t *devi, const char *label, 26460Sstevel@tonic-gate uint_t size, uint_t assoc, uint_t lines_per_tag, uint_t line_size) 26470Sstevel@tonic-gate { 26480Sstevel@tonic-gate if (size == 0 || assoc == 0 || line_size == 0) 26490Sstevel@tonic-gate return; 26500Sstevel@tonic-gate add_amd_l2_assoc(devi, label, assoc); 26510Sstevel@tonic-gate if (lines_per_tag != 0) 26520Sstevel@tonic-gate add_cache_prop(devi, label, "lines-per-tag", lines_per_tag); 26530Sstevel@tonic-gate add_cache_prop(devi, label, line_str, line_size); 26540Sstevel@tonic-gate add_cache_prop(devi, label, size_str, size * 1024); 26550Sstevel@tonic-gate } 26560Sstevel@tonic-gate 26570Sstevel@tonic-gate static void 26580Sstevel@tonic-gate amd_cache_info(struct cpuid_info *cpi, dev_info_t *devi) 26590Sstevel@tonic-gate { 26601228Sandrei struct cpuid_regs *cp; 26610Sstevel@tonic-gate 26620Sstevel@tonic-gate if (cpi->cpi_xmaxeax < 0x80000005) 26630Sstevel@tonic-gate return; 26640Sstevel@tonic-gate cp = &cpi->cpi_extd[5]; 26650Sstevel@tonic-gate 26660Sstevel@tonic-gate /* 26670Sstevel@tonic-gate * 4M/2M L1 TLB configuration 26680Sstevel@tonic-gate * 26690Sstevel@tonic-gate * We report the size for 2M pages because AMD uses two 26700Sstevel@tonic-gate * TLB entries for one 4M page. 26710Sstevel@tonic-gate */ 26720Sstevel@tonic-gate add_amd_tlb(devi, "dtlb-2M", 26730Sstevel@tonic-gate BITX(cp->cp_eax, 31, 24), BITX(cp->cp_eax, 23, 16)); 26740Sstevel@tonic-gate add_amd_tlb(devi, "itlb-2M", 26750Sstevel@tonic-gate BITX(cp->cp_eax, 15, 8), BITX(cp->cp_eax, 7, 0)); 26760Sstevel@tonic-gate 26770Sstevel@tonic-gate /* 26780Sstevel@tonic-gate * 4K L1 TLB configuration 26790Sstevel@tonic-gate */ 26800Sstevel@tonic-gate 26810Sstevel@tonic-gate switch (cpi->cpi_vendor) { 26820Sstevel@tonic-gate uint_t nentries; 26830Sstevel@tonic-gate case X86_VENDOR_TM: 26840Sstevel@tonic-gate if (cpi->cpi_family >= 5) { 26850Sstevel@tonic-gate /* 26860Sstevel@tonic-gate * Crusoe processors have 256 TLB entries, but 26870Sstevel@tonic-gate * cpuid data format constrains them to only 26880Sstevel@tonic-gate * reporting 255 of them. 26890Sstevel@tonic-gate */ 26900Sstevel@tonic-gate if ((nentries = BITX(cp->cp_ebx, 23, 16)) == 255) 26910Sstevel@tonic-gate nentries = 256; 26920Sstevel@tonic-gate /* 26930Sstevel@tonic-gate * Crusoe processors also have a unified TLB 26940Sstevel@tonic-gate */ 26950Sstevel@tonic-gate add_amd_tlb(devi, "tlb-4K", BITX(cp->cp_ebx, 31, 24), 26960Sstevel@tonic-gate nentries); 26970Sstevel@tonic-gate break; 26980Sstevel@tonic-gate } 26990Sstevel@tonic-gate /*FALLTHROUGH*/ 27000Sstevel@tonic-gate default: 27010Sstevel@tonic-gate add_amd_tlb(devi, itlb4k_str, 27020Sstevel@tonic-gate BITX(cp->cp_ebx, 31, 24), BITX(cp->cp_ebx, 23, 16)); 27030Sstevel@tonic-gate add_amd_tlb(devi, dtlb4k_str, 27040Sstevel@tonic-gate BITX(cp->cp_ebx, 15, 8), BITX(cp->cp_ebx, 7, 0)); 27050Sstevel@tonic-gate break; 27060Sstevel@tonic-gate } 27070Sstevel@tonic-gate 27080Sstevel@tonic-gate /* 27090Sstevel@tonic-gate * data L1 cache configuration 27100Sstevel@tonic-gate */ 27110Sstevel@tonic-gate 27120Sstevel@tonic-gate add_amd_cache(devi, l1_dcache_str, 27130Sstevel@tonic-gate BITX(cp->cp_ecx, 31, 24), BITX(cp->cp_ecx, 23, 16), 27140Sstevel@tonic-gate BITX(cp->cp_ecx, 15, 8), BITX(cp->cp_ecx, 7, 0)); 27150Sstevel@tonic-gate 27160Sstevel@tonic-gate /* 27170Sstevel@tonic-gate * code L1 cache configuration 27180Sstevel@tonic-gate */ 27190Sstevel@tonic-gate 27200Sstevel@tonic-gate add_amd_cache(devi, l1_icache_str, 27210Sstevel@tonic-gate BITX(cp->cp_edx, 31, 24), BITX(cp->cp_edx, 23, 16), 27220Sstevel@tonic-gate BITX(cp->cp_edx, 15, 8), BITX(cp->cp_edx, 7, 0)); 27230Sstevel@tonic-gate 27240Sstevel@tonic-gate if (cpi->cpi_xmaxeax < 0x80000006) 27250Sstevel@tonic-gate return; 27260Sstevel@tonic-gate cp = &cpi->cpi_extd[6]; 27270Sstevel@tonic-gate 27280Sstevel@tonic-gate /* Check for a unified L2 TLB for large pages */ 27290Sstevel@tonic-gate 27300Sstevel@tonic-gate if (BITX(cp->cp_eax, 31, 16) == 0) 27310Sstevel@tonic-gate add_amd_l2_tlb(devi, "l2-tlb-2M", 27320Sstevel@tonic-gate BITX(cp->cp_eax, 15, 12), BITX(cp->cp_eax, 11, 0)); 27330Sstevel@tonic-gate else { 27340Sstevel@tonic-gate add_amd_l2_tlb(devi, "l2-dtlb-2M", 27350Sstevel@tonic-gate BITX(cp->cp_eax, 31, 28), BITX(cp->cp_eax, 27, 16)); 27360Sstevel@tonic-gate add_amd_l2_tlb(devi, "l2-itlb-2M", 27370Sstevel@tonic-gate BITX(cp->cp_eax, 15, 12), BITX(cp->cp_eax, 11, 0)); 27380Sstevel@tonic-gate } 27390Sstevel@tonic-gate 27400Sstevel@tonic-gate /* Check for a unified L2 TLB for 4K pages */ 27410Sstevel@tonic-gate 27420Sstevel@tonic-gate if (BITX(cp->cp_ebx, 31, 16) == 0) { 27430Sstevel@tonic-gate add_amd_l2_tlb(devi, "l2-tlb-4K", 27440Sstevel@tonic-gate BITX(cp->cp_eax, 15, 12), BITX(cp->cp_eax, 11, 0)); 27450Sstevel@tonic-gate } else { 27460Sstevel@tonic-gate add_amd_l2_tlb(devi, "l2-dtlb-4K", 27470Sstevel@tonic-gate BITX(cp->cp_eax, 31, 28), BITX(cp->cp_eax, 27, 16)); 27480Sstevel@tonic-gate add_amd_l2_tlb(devi, "l2-itlb-4K", 27490Sstevel@tonic-gate BITX(cp->cp_eax, 15, 12), BITX(cp->cp_eax, 11, 0)); 27500Sstevel@tonic-gate } 27510Sstevel@tonic-gate 27520Sstevel@tonic-gate add_amd_l2_cache(devi, l2_cache_str, 27530Sstevel@tonic-gate BITX(cp->cp_ecx, 31, 16), BITX(cp->cp_ecx, 15, 12), 27540Sstevel@tonic-gate BITX(cp->cp_ecx, 11, 8), BITX(cp->cp_ecx, 7, 0)); 27550Sstevel@tonic-gate } 27560Sstevel@tonic-gate 27570Sstevel@tonic-gate /* 27580Sstevel@tonic-gate * There are two basic ways that the x86 world describes it cache 27590Sstevel@tonic-gate * and tlb architecture - Intel's way and AMD's way. 27600Sstevel@tonic-gate * 27610Sstevel@tonic-gate * Return which flavor of cache architecture we should use 27620Sstevel@tonic-gate */ 27630Sstevel@tonic-gate static int 27640Sstevel@tonic-gate x86_which_cacheinfo(struct cpuid_info *cpi) 27650Sstevel@tonic-gate { 27660Sstevel@tonic-gate switch (cpi->cpi_vendor) { 27670Sstevel@tonic-gate case X86_VENDOR_Intel: 27680Sstevel@tonic-gate if (cpi->cpi_maxeax >= 2) 27690Sstevel@tonic-gate return (X86_VENDOR_Intel); 27700Sstevel@tonic-gate break; 27710Sstevel@tonic-gate case X86_VENDOR_AMD: 27720Sstevel@tonic-gate /* 27730Sstevel@tonic-gate * The K5 model 1 was the first part from AMD that reported 27740Sstevel@tonic-gate * cache sizes via extended cpuid functions. 27750Sstevel@tonic-gate */ 27760Sstevel@tonic-gate if (cpi->cpi_family > 5 || 27770Sstevel@tonic-gate (cpi->cpi_family == 5 && cpi->cpi_model >= 1)) 27780Sstevel@tonic-gate return (X86_VENDOR_AMD); 27790Sstevel@tonic-gate break; 27800Sstevel@tonic-gate case X86_VENDOR_TM: 27810Sstevel@tonic-gate if (cpi->cpi_family >= 5) 27820Sstevel@tonic-gate return (X86_VENDOR_AMD); 27830Sstevel@tonic-gate /*FALLTHROUGH*/ 27840Sstevel@tonic-gate default: 27850Sstevel@tonic-gate /* 27860Sstevel@tonic-gate * If they have extended CPU data for 0x80000005 27870Sstevel@tonic-gate * then we assume they have AMD-format cache 27880Sstevel@tonic-gate * information. 27890Sstevel@tonic-gate * 27900Sstevel@tonic-gate * If not, and the vendor happens to be Cyrix, 27910Sstevel@tonic-gate * then try our-Cyrix specific handler. 27920Sstevel@tonic-gate * 27930Sstevel@tonic-gate * If we're not Cyrix, then assume we're using Intel's 27940Sstevel@tonic-gate * table-driven format instead. 27950Sstevel@tonic-gate */ 27960Sstevel@tonic-gate if (cpi->cpi_xmaxeax >= 0x80000005) 27970Sstevel@tonic-gate return (X86_VENDOR_AMD); 27980Sstevel@tonic-gate else if (cpi->cpi_vendor == X86_VENDOR_Cyrix) 27990Sstevel@tonic-gate return (X86_VENDOR_Cyrix); 28000Sstevel@tonic-gate else if (cpi->cpi_maxeax >= 2) 28010Sstevel@tonic-gate return (X86_VENDOR_Intel); 28020Sstevel@tonic-gate break; 28030Sstevel@tonic-gate } 28040Sstevel@tonic-gate return (-1); 28050Sstevel@tonic-gate } 28060Sstevel@tonic-gate 28070Sstevel@tonic-gate /* 28080Sstevel@tonic-gate * create a node for the given cpu under the prom root node. 28090Sstevel@tonic-gate * Also, create a cpu node in the device tree. 28100Sstevel@tonic-gate */ 28110Sstevel@tonic-gate static dev_info_t *cpu_nex_devi = NULL; 28120Sstevel@tonic-gate static kmutex_t cpu_node_lock; 28130Sstevel@tonic-gate 28140Sstevel@tonic-gate /* 28150Sstevel@tonic-gate * Called from post_startup() and mp_startup() 28160Sstevel@tonic-gate */ 28170Sstevel@tonic-gate void 28180Sstevel@tonic-gate add_cpunode2devtree(processorid_t cpu_id, struct cpuid_info *cpi) 28190Sstevel@tonic-gate { 28200Sstevel@tonic-gate dev_info_t *cpu_devi; 28210Sstevel@tonic-gate int create; 28220Sstevel@tonic-gate 28230Sstevel@tonic-gate mutex_enter(&cpu_node_lock); 28240Sstevel@tonic-gate 28250Sstevel@tonic-gate /* 28260Sstevel@tonic-gate * create a nexus node for all cpus identified as 'cpu_id' under 28270Sstevel@tonic-gate * the root node. 28280Sstevel@tonic-gate */ 28290Sstevel@tonic-gate if (cpu_nex_devi == NULL) { 28300Sstevel@tonic-gate if (ndi_devi_alloc(ddi_root_node(), "cpus", 2831789Sahrens (pnode_t)DEVI_SID_NODEID, &cpu_nex_devi) != NDI_SUCCESS) { 28320Sstevel@tonic-gate mutex_exit(&cpu_node_lock); 28330Sstevel@tonic-gate return; 28340Sstevel@tonic-gate } 28350Sstevel@tonic-gate (void) ndi_devi_online(cpu_nex_devi, 0); 28360Sstevel@tonic-gate } 28370Sstevel@tonic-gate 28380Sstevel@tonic-gate /* 28390Sstevel@tonic-gate * create a child node for cpu identified as 'cpu_id' 28400Sstevel@tonic-gate */ 28410Sstevel@tonic-gate cpu_devi = ddi_add_child(cpu_nex_devi, "cpu", DEVI_SID_NODEID, 2842*4481Sbholler cpu_id); 28430Sstevel@tonic-gate if (cpu_devi == NULL) { 28440Sstevel@tonic-gate mutex_exit(&cpu_node_lock); 28450Sstevel@tonic-gate return; 28460Sstevel@tonic-gate } 28470Sstevel@tonic-gate 28480Sstevel@tonic-gate /* device_type */ 28490Sstevel@tonic-gate 28500Sstevel@tonic-gate (void) ndi_prop_update_string(DDI_DEV_T_NONE, cpu_devi, 28510Sstevel@tonic-gate "device_type", "cpu"); 28520Sstevel@tonic-gate 28530Sstevel@tonic-gate /* reg */ 28540Sstevel@tonic-gate 28550Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 28560Sstevel@tonic-gate "reg", cpu_id); 28570Sstevel@tonic-gate 28580Sstevel@tonic-gate /* cpu-mhz, and clock-frequency */ 28590Sstevel@tonic-gate 28600Sstevel@tonic-gate if (cpu_freq > 0) { 28610Sstevel@tonic-gate long long mul; 28620Sstevel@tonic-gate 28630Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 28640Sstevel@tonic-gate "cpu-mhz", cpu_freq); 28650Sstevel@tonic-gate 28660Sstevel@tonic-gate if ((mul = cpu_freq * 1000000LL) <= INT_MAX) 28670Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 28680Sstevel@tonic-gate "clock-frequency", (int)mul); 28690Sstevel@tonic-gate } 28700Sstevel@tonic-gate 28710Sstevel@tonic-gate (void) ndi_devi_online(cpu_devi, 0); 28720Sstevel@tonic-gate 28730Sstevel@tonic-gate if ((x86_feature & X86_CPUID) == 0) { 28740Sstevel@tonic-gate mutex_exit(&cpu_node_lock); 28750Sstevel@tonic-gate return; 28760Sstevel@tonic-gate } 28770Sstevel@tonic-gate 28780Sstevel@tonic-gate /* vendor-id */ 28790Sstevel@tonic-gate 28800Sstevel@tonic-gate (void) ndi_prop_update_string(DDI_DEV_T_NONE, cpu_devi, 2881*4481Sbholler "vendor-id", cpi->cpi_vendorstr); 28820Sstevel@tonic-gate 28830Sstevel@tonic-gate if (cpi->cpi_maxeax == 0) { 28840Sstevel@tonic-gate mutex_exit(&cpu_node_lock); 28850Sstevel@tonic-gate return; 28860Sstevel@tonic-gate } 28870Sstevel@tonic-gate 28880Sstevel@tonic-gate /* 28890Sstevel@tonic-gate * family, model, and step 28900Sstevel@tonic-gate */ 28910Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 2892*4481Sbholler "family", CPI_FAMILY(cpi)); 28930Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 2894*4481Sbholler "cpu-model", CPI_MODEL(cpi)); 28950Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 2896*4481Sbholler "stepping-id", CPI_STEP(cpi)); 28970Sstevel@tonic-gate 28980Sstevel@tonic-gate /* type */ 28990Sstevel@tonic-gate 29000Sstevel@tonic-gate switch (cpi->cpi_vendor) { 29010Sstevel@tonic-gate case X86_VENDOR_Intel: 29020Sstevel@tonic-gate create = 1; 29030Sstevel@tonic-gate break; 29040Sstevel@tonic-gate default: 29050Sstevel@tonic-gate create = 0; 29060Sstevel@tonic-gate break; 29070Sstevel@tonic-gate } 29080Sstevel@tonic-gate if (create) 29090Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 2910*4481Sbholler "type", CPI_TYPE(cpi)); 29110Sstevel@tonic-gate 29120Sstevel@tonic-gate /* ext-family */ 29130Sstevel@tonic-gate 29140Sstevel@tonic-gate switch (cpi->cpi_vendor) { 29150Sstevel@tonic-gate case X86_VENDOR_Intel: 29160Sstevel@tonic-gate case X86_VENDOR_AMD: 29170Sstevel@tonic-gate create = cpi->cpi_family >= 0xf; 29180Sstevel@tonic-gate break; 29190Sstevel@tonic-gate default: 29200Sstevel@tonic-gate create = 0; 29210Sstevel@tonic-gate break; 29220Sstevel@tonic-gate } 29230Sstevel@tonic-gate if (create) 29240Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 29250Sstevel@tonic-gate "ext-family", CPI_FAMILY_XTD(cpi)); 29260Sstevel@tonic-gate 29270Sstevel@tonic-gate /* ext-model */ 29280Sstevel@tonic-gate 29290Sstevel@tonic-gate switch (cpi->cpi_vendor) { 29300Sstevel@tonic-gate case X86_VENDOR_Intel: 29312001Sdmick create = CPI_MODEL(cpi) == 0xf; 29322001Sdmick break; 29330Sstevel@tonic-gate case X86_VENDOR_AMD: 29341582Skchow create = CPI_FAMILY(cpi) == 0xf; 29350Sstevel@tonic-gate break; 29360Sstevel@tonic-gate default: 29370Sstevel@tonic-gate create = 0; 29380Sstevel@tonic-gate break; 29390Sstevel@tonic-gate } 29400Sstevel@tonic-gate if (create) 29410Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 2942*4481Sbholler "ext-model", CPI_MODEL_XTD(cpi)); 29430Sstevel@tonic-gate 29440Sstevel@tonic-gate /* generation */ 29450Sstevel@tonic-gate 29460Sstevel@tonic-gate switch (cpi->cpi_vendor) { 29470Sstevel@tonic-gate case X86_VENDOR_AMD: 29480Sstevel@tonic-gate /* 29490Sstevel@tonic-gate * AMD K5 model 1 was the first part to support this 29500Sstevel@tonic-gate */ 29510Sstevel@tonic-gate create = cpi->cpi_xmaxeax >= 0x80000001; 29520Sstevel@tonic-gate break; 29530Sstevel@tonic-gate default: 29540Sstevel@tonic-gate create = 0; 29550Sstevel@tonic-gate break; 29560Sstevel@tonic-gate } 29570Sstevel@tonic-gate if (create) 29580Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 29590Sstevel@tonic-gate "generation", BITX((cpi)->cpi_extd[1].cp_eax, 11, 8)); 29600Sstevel@tonic-gate 29610Sstevel@tonic-gate /* brand-id */ 29620Sstevel@tonic-gate 29630Sstevel@tonic-gate switch (cpi->cpi_vendor) { 29640Sstevel@tonic-gate case X86_VENDOR_Intel: 29650Sstevel@tonic-gate /* 29660Sstevel@tonic-gate * brand id first appeared on Pentium III Xeon model 8, 29670Sstevel@tonic-gate * and Celeron model 8 processors and Opteron 29680Sstevel@tonic-gate */ 29690Sstevel@tonic-gate create = cpi->cpi_family > 6 || 29700Sstevel@tonic-gate (cpi->cpi_family == 6 && cpi->cpi_model >= 8); 29710Sstevel@tonic-gate break; 29720Sstevel@tonic-gate case X86_VENDOR_AMD: 29730Sstevel@tonic-gate create = cpi->cpi_family >= 0xf; 29740Sstevel@tonic-gate break; 29750Sstevel@tonic-gate default: 29760Sstevel@tonic-gate create = 0; 29770Sstevel@tonic-gate break; 29780Sstevel@tonic-gate } 29790Sstevel@tonic-gate if (create && cpi->cpi_brandid != 0) { 29800Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 29810Sstevel@tonic-gate "brand-id", cpi->cpi_brandid); 29820Sstevel@tonic-gate } 29830Sstevel@tonic-gate 29840Sstevel@tonic-gate /* chunks, and apic-id */ 29850Sstevel@tonic-gate 29860Sstevel@tonic-gate switch (cpi->cpi_vendor) { 29870Sstevel@tonic-gate /* 29880Sstevel@tonic-gate * first available on Pentium IV and Opteron (K8) 29890Sstevel@tonic-gate */ 29901975Sdmick case X86_VENDOR_Intel: 29911975Sdmick create = IS_NEW_F6(cpi) || cpi->cpi_family >= 0xf; 29921975Sdmick break; 29931975Sdmick case X86_VENDOR_AMD: 29940Sstevel@tonic-gate create = cpi->cpi_family >= 0xf; 29950Sstevel@tonic-gate break; 29960Sstevel@tonic-gate default: 29970Sstevel@tonic-gate create = 0; 29980Sstevel@tonic-gate break; 29990Sstevel@tonic-gate } 30000Sstevel@tonic-gate if (create) { 30010Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 3002*4481Sbholler "chunks", CPI_CHUNKS(cpi)); 30030Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 3004*4481Sbholler "apic-id", CPI_APIC_ID(cpi)); 30051414Scindi if (cpi->cpi_chipid >= 0) { 30060Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 30070Sstevel@tonic-gate "chip#", cpi->cpi_chipid); 30081414Scindi (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 30091414Scindi "clog#", cpi->cpi_clogid); 30101414Scindi } 30110Sstevel@tonic-gate } 30120Sstevel@tonic-gate 30130Sstevel@tonic-gate /* cpuid-features */ 30140Sstevel@tonic-gate 30150Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 30160Sstevel@tonic-gate "cpuid-features", CPI_FEATURES_EDX(cpi)); 30170Sstevel@tonic-gate 30180Sstevel@tonic-gate 30190Sstevel@tonic-gate /* cpuid-features-ecx */ 30200Sstevel@tonic-gate 30210Sstevel@tonic-gate switch (cpi->cpi_vendor) { 30220Sstevel@tonic-gate case X86_VENDOR_Intel: 30231975Sdmick create = IS_NEW_F6(cpi) || cpi->cpi_family >= 0xf; 30240Sstevel@tonic-gate break; 30250Sstevel@tonic-gate default: 30260Sstevel@tonic-gate create = 0; 30270Sstevel@tonic-gate break; 30280Sstevel@tonic-gate } 30290Sstevel@tonic-gate if (create) 30300Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 30310Sstevel@tonic-gate "cpuid-features-ecx", CPI_FEATURES_ECX(cpi)); 30320Sstevel@tonic-gate 30330Sstevel@tonic-gate /* ext-cpuid-features */ 30340Sstevel@tonic-gate 30350Sstevel@tonic-gate switch (cpi->cpi_vendor) { 30361975Sdmick case X86_VENDOR_Intel: 30370Sstevel@tonic-gate case X86_VENDOR_AMD: 30380Sstevel@tonic-gate case X86_VENDOR_Cyrix: 30390Sstevel@tonic-gate case X86_VENDOR_TM: 30400Sstevel@tonic-gate case X86_VENDOR_Centaur: 30410Sstevel@tonic-gate create = cpi->cpi_xmaxeax >= 0x80000001; 30420Sstevel@tonic-gate break; 30430Sstevel@tonic-gate default: 30440Sstevel@tonic-gate create = 0; 30450Sstevel@tonic-gate break; 30460Sstevel@tonic-gate } 30471975Sdmick if (create) { 30480Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 3049*4481Sbholler "ext-cpuid-features", CPI_FEATURES_XTD_EDX(cpi)); 30501975Sdmick (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 3051*4481Sbholler "ext-cpuid-features-ecx", CPI_FEATURES_XTD_ECX(cpi)); 30521975Sdmick } 30530Sstevel@tonic-gate 30540Sstevel@tonic-gate /* 30550Sstevel@tonic-gate * Brand String first appeared in Intel Pentium IV, AMD K5 30560Sstevel@tonic-gate * model 1, and Cyrix GXm. On earlier models we try and 30570Sstevel@tonic-gate * simulate something similar .. so this string should always 30580Sstevel@tonic-gate * same -something- about the processor, however lame. 30590Sstevel@tonic-gate */ 30600Sstevel@tonic-gate (void) ndi_prop_update_string(DDI_DEV_T_NONE, cpu_devi, 30610Sstevel@tonic-gate "brand-string", cpi->cpi_brandstr); 30620Sstevel@tonic-gate 30630Sstevel@tonic-gate /* 30640Sstevel@tonic-gate * Finally, cache and tlb information 30650Sstevel@tonic-gate */ 30660Sstevel@tonic-gate switch (x86_which_cacheinfo(cpi)) { 30670Sstevel@tonic-gate case X86_VENDOR_Intel: 30680Sstevel@tonic-gate intel_walk_cacheinfo(cpi, cpu_devi, add_cacheent_props); 30690Sstevel@tonic-gate break; 30700Sstevel@tonic-gate case X86_VENDOR_Cyrix: 30710Sstevel@tonic-gate cyrix_walk_cacheinfo(cpi, cpu_devi, add_cacheent_props); 30720Sstevel@tonic-gate break; 30730Sstevel@tonic-gate case X86_VENDOR_AMD: 30740Sstevel@tonic-gate amd_cache_info(cpi, cpu_devi); 30750Sstevel@tonic-gate break; 30760Sstevel@tonic-gate default: 30770Sstevel@tonic-gate break; 30780Sstevel@tonic-gate } 30790Sstevel@tonic-gate 30800Sstevel@tonic-gate mutex_exit(&cpu_node_lock); 30810Sstevel@tonic-gate } 30820Sstevel@tonic-gate 30830Sstevel@tonic-gate struct l2info { 30840Sstevel@tonic-gate int *l2i_csz; 30850Sstevel@tonic-gate int *l2i_lsz; 30860Sstevel@tonic-gate int *l2i_assoc; 30870Sstevel@tonic-gate int l2i_ret; 30880Sstevel@tonic-gate }; 30890Sstevel@tonic-gate 30900Sstevel@tonic-gate /* 30910Sstevel@tonic-gate * A cacheinfo walker that fetches the size, line-size and associativity 30920Sstevel@tonic-gate * of the L2 cache 30930Sstevel@tonic-gate */ 30940Sstevel@tonic-gate static int 30950Sstevel@tonic-gate intel_l2cinfo(void *arg, const struct cachetab *ct) 30960Sstevel@tonic-gate { 30970Sstevel@tonic-gate struct l2info *l2i = arg; 30980Sstevel@tonic-gate int *ip; 30990Sstevel@tonic-gate 31000Sstevel@tonic-gate if (ct->ct_label != l2_cache_str && 31010Sstevel@tonic-gate ct->ct_label != sl2_cache_str) 31020Sstevel@tonic-gate return (0); /* not an L2 -- keep walking */ 31030Sstevel@tonic-gate 31040Sstevel@tonic-gate if ((ip = l2i->l2i_csz) != NULL) 31050Sstevel@tonic-gate *ip = ct->ct_size; 31060Sstevel@tonic-gate if ((ip = l2i->l2i_lsz) != NULL) 31070Sstevel@tonic-gate *ip = ct->ct_line_size; 31080Sstevel@tonic-gate if ((ip = l2i->l2i_assoc) != NULL) 31090Sstevel@tonic-gate *ip = ct->ct_assoc; 31100Sstevel@tonic-gate l2i->l2i_ret = ct->ct_size; 31110Sstevel@tonic-gate return (1); /* was an L2 -- terminate walk */ 31120Sstevel@tonic-gate } 31130Sstevel@tonic-gate 31140Sstevel@tonic-gate static void 31150Sstevel@tonic-gate amd_l2cacheinfo(struct cpuid_info *cpi, struct l2info *l2i) 31160Sstevel@tonic-gate { 31171228Sandrei struct cpuid_regs *cp; 31180Sstevel@tonic-gate uint_t size, assoc; 31190Sstevel@tonic-gate int *ip; 31200Sstevel@tonic-gate 31210Sstevel@tonic-gate if (cpi->cpi_xmaxeax < 0x80000006) 31220Sstevel@tonic-gate return; 31230Sstevel@tonic-gate cp = &cpi->cpi_extd[6]; 31240Sstevel@tonic-gate 31250Sstevel@tonic-gate if ((assoc = BITX(cp->cp_ecx, 15, 12)) != 0 && 31260Sstevel@tonic-gate (size = BITX(cp->cp_ecx, 31, 16)) != 0) { 31270Sstevel@tonic-gate uint_t cachesz = size * 1024; 31280Sstevel@tonic-gate 31290Sstevel@tonic-gate 31300Sstevel@tonic-gate if ((ip = l2i->l2i_csz) != NULL) 31310Sstevel@tonic-gate *ip = cachesz; 31320Sstevel@tonic-gate if ((ip = l2i->l2i_lsz) != NULL) 31330Sstevel@tonic-gate *ip = BITX(cp->cp_ecx, 7, 0); 31340Sstevel@tonic-gate if ((ip = l2i->l2i_assoc) != NULL) 31350Sstevel@tonic-gate *ip = assoc; 31360Sstevel@tonic-gate l2i->l2i_ret = cachesz; 31370Sstevel@tonic-gate } 31380Sstevel@tonic-gate } 31390Sstevel@tonic-gate 31400Sstevel@tonic-gate int 31410Sstevel@tonic-gate getl2cacheinfo(cpu_t *cpu, int *csz, int *lsz, int *assoc) 31420Sstevel@tonic-gate { 31430Sstevel@tonic-gate struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 31440Sstevel@tonic-gate struct l2info __l2info, *l2i = &__l2info; 31450Sstevel@tonic-gate 31460Sstevel@tonic-gate l2i->l2i_csz = csz; 31470Sstevel@tonic-gate l2i->l2i_lsz = lsz; 31480Sstevel@tonic-gate l2i->l2i_assoc = assoc; 31490Sstevel@tonic-gate l2i->l2i_ret = -1; 31500Sstevel@tonic-gate 31510Sstevel@tonic-gate switch (x86_which_cacheinfo(cpi)) { 31520Sstevel@tonic-gate case X86_VENDOR_Intel: 31530Sstevel@tonic-gate intel_walk_cacheinfo(cpi, l2i, intel_l2cinfo); 31540Sstevel@tonic-gate break; 31550Sstevel@tonic-gate case X86_VENDOR_Cyrix: 31560Sstevel@tonic-gate cyrix_walk_cacheinfo(cpi, l2i, intel_l2cinfo); 31570Sstevel@tonic-gate break; 31580Sstevel@tonic-gate case X86_VENDOR_AMD: 31590Sstevel@tonic-gate amd_l2cacheinfo(cpi, l2i); 31600Sstevel@tonic-gate break; 31610Sstevel@tonic-gate default: 31620Sstevel@tonic-gate break; 31630Sstevel@tonic-gate } 31640Sstevel@tonic-gate return (l2i->l2i_ret); 31650Sstevel@tonic-gate } 3166*4481Sbholler 3167*4481Sbholler size_t 3168*4481Sbholler cpuid_get_mwait_size(cpu_t *cpu) 3169*4481Sbholler { 3170*4481Sbholler ASSERT(cpuid_checkpass(cpu, 2)); 3171*4481Sbholler return (cpu->cpu_m.mcpu_cpi->cpi_mwait.mon_max); 3172*4481Sbholler } 3173