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 /* 1180Sstevel@tonic-gate * These constants determine how many of the elements of the 1190Sstevel@tonic-gate * cpuid we cache in the cpuid_info data structure; the 1200Sstevel@tonic-gate * remaining elements are accessible via the cpuid instruction. 1210Sstevel@tonic-gate */ 1220Sstevel@tonic-gate 1230Sstevel@tonic-gate #define NMAX_CPI_STD 6 /* eax = 0 .. 5 */ 1240Sstevel@tonic-gate #define NMAX_CPI_EXTD 9 /* eax = 0x80000000 .. 0x80000008 */ 1250Sstevel@tonic-gate 1260Sstevel@tonic-gate struct cpuid_info { 1270Sstevel@tonic-gate uint_t cpi_pass; /* last pass completed */ 1280Sstevel@tonic-gate /* 1290Sstevel@tonic-gate * standard function information 1300Sstevel@tonic-gate */ 1310Sstevel@tonic-gate uint_t cpi_maxeax; /* fn 0: %eax */ 1320Sstevel@tonic-gate char cpi_vendorstr[13]; /* fn 0: %ebx:%ecx:%edx */ 1330Sstevel@tonic-gate uint_t cpi_vendor; /* enum of cpi_vendorstr */ 1340Sstevel@tonic-gate 1350Sstevel@tonic-gate uint_t cpi_family; /* fn 1: extended family */ 1360Sstevel@tonic-gate uint_t cpi_model; /* fn 1: extended model */ 1370Sstevel@tonic-gate uint_t cpi_step; /* fn 1: stepping */ 1380Sstevel@tonic-gate chipid_t cpi_chipid; /* fn 1: %ebx: chip # on ht cpus */ 1390Sstevel@tonic-gate uint_t cpi_brandid; /* fn 1: %ebx: brand ID */ 1400Sstevel@tonic-gate int cpi_clogid; /* fn 1: %ebx: thread # */ 1411228Sandrei uint_t cpi_ncpu_per_chip; /* fn 1: %ebx: logical cpu count */ 1420Sstevel@tonic-gate uint8_t cpi_cacheinfo[16]; /* fn 2: intel-style cache desc */ 1430Sstevel@tonic-gate uint_t cpi_ncache; /* fn 2: number of elements */ 1441228Sandrei struct cpuid_regs cpi_std[NMAX_CPI_STD]; /* 0 .. 5 */ 1450Sstevel@tonic-gate /* 1460Sstevel@tonic-gate * extended function information 1470Sstevel@tonic-gate */ 1480Sstevel@tonic-gate uint_t cpi_xmaxeax; /* fn 0x80000000: %eax */ 1490Sstevel@tonic-gate char cpi_brandstr[49]; /* fn 0x8000000[234] */ 1500Sstevel@tonic-gate uint8_t cpi_pabits; /* fn 0x80000006: %eax */ 1510Sstevel@tonic-gate uint8_t cpi_vabits; /* fn 0x80000006: %eax */ 1521228Sandrei struct cpuid_regs cpi_extd[NMAX_CPI_EXTD]; /* 0x8000000[0-8] */ 1531228Sandrei id_t cpi_coreid; 1541228Sandrei uint_t cpi_ncore_per_chip; /* AMD: fn 0x80000008: %ecx[7-0] */ 1551228Sandrei /* Intel: fn 4: %eax[31-26] */ 1560Sstevel@tonic-gate /* 1570Sstevel@tonic-gate * supported feature information 1580Sstevel@tonic-gate */ 1593446Smrj uint32_t cpi_support[5]; 1600Sstevel@tonic-gate #define STD_EDX_FEATURES 0 1610Sstevel@tonic-gate #define AMD_EDX_FEATURES 1 1620Sstevel@tonic-gate #define TM_EDX_FEATURES 2 1630Sstevel@tonic-gate #define STD_ECX_FEATURES 3 1643446Smrj #define AMD_ECX_FEATURES 4 1652869Sgavinm /* 1662869Sgavinm * Synthesized information, where known. 1672869Sgavinm */ 1682869Sgavinm uint32_t cpi_chiprev; /* See X86_CHIPREV_* in x86_archext.h */ 1692869Sgavinm const char *cpi_chiprevstr; /* May be NULL if chiprev unknown */ 1702869Sgavinm uint32_t cpi_socket; /* Chip package/socket type */ 1710Sstevel@tonic-gate }; 1720Sstevel@tonic-gate 1730Sstevel@tonic-gate 1740Sstevel@tonic-gate static struct cpuid_info cpuid_info0; 1750Sstevel@tonic-gate 1760Sstevel@tonic-gate /* 1770Sstevel@tonic-gate * These bit fields are defined by the Intel Application Note AP-485 1780Sstevel@tonic-gate * "Intel Processor Identification and the CPUID Instruction" 1790Sstevel@tonic-gate */ 1800Sstevel@tonic-gate #define CPI_FAMILY_XTD(cpi) BITX((cpi)->cpi_std[1].cp_eax, 27, 20) 1810Sstevel@tonic-gate #define CPI_MODEL_XTD(cpi) BITX((cpi)->cpi_std[1].cp_eax, 19, 16) 1820Sstevel@tonic-gate #define CPI_TYPE(cpi) BITX((cpi)->cpi_std[1].cp_eax, 13, 12) 1830Sstevel@tonic-gate #define CPI_FAMILY(cpi) BITX((cpi)->cpi_std[1].cp_eax, 11, 8) 1840Sstevel@tonic-gate #define CPI_STEP(cpi) BITX((cpi)->cpi_std[1].cp_eax, 3, 0) 1850Sstevel@tonic-gate #define CPI_MODEL(cpi) BITX((cpi)->cpi_std[1].cp_eax, 7, 4) 1860Sstevel@tonic-gate 1870Sstevel@tonic-gate #define CPI_FEATURES_EDX(cpi) ((cpi)->cpi_std[1].cp_edx) 1880Sstevel@tonic-gate #define CPI_FEATURES_ECX(cpi) ((cpi)->cpi_std[1].cp_ecx) 1890Sstevel@tonic-gate #define CPI_FEATURES_XTD_EDX(cpi) ((cpi)->cpi_extd[1].cp_edx) 1900Sstevel@tonic-gate #define CPI_FEATURES_XTD_ECX(cpi) ((cpi)->cpi_extd[1].cp_ecx) 1910Sstevel@tonic-gate 1920Sstevel@tonic-gate #define CPI_BRANDID(cpi) BITX((cpi)->cpi_std[1].cp_ebx, 7, 0) 1930Sstevel@tonic-gate #define CPI_CHUNKS(cpi) BITX((cpi)->cpi_std[1].cp_ebx, 15, 7) 1940Sstevel@tonic-gate #define CPI_CPU_COUNT(cpi) BITX((cpi)->cpi_std[1].cp_ebx, 23, 16) 1950Sstevel@tonic-gate #define CPI_APIC_ID(cpi) BITX((cpi)->cpi_std[1].cp_ebx, 31, 24) 1960Sstevel@tonic-gate 1970Sstevel@tonic-gate #define CPI_MAXEAX_MAX 0x100 /* sanity control */ 1980Sstevel@tonic-gate #define CPI_XMAXEAX_MAX 0x80000100 1990Sstevel@tonic-gate 2000Sstevel@tonic-gate /* 2011975Sdmick * A couple of shorthand macros to identify "later" P6-family chips 2021975Sdmick * like the Pentium M and Core. First, the "older" P6-based stuff 2031975Sdmick * (loosely defined as "pre-Pentium-4"): 2041975Sdmick * P6, PII, Mobile PII, PII Xeon, PIII, Mobile PIII, PIII Xeon 2051975Sdmick */ 2061975Sdmick 2071975Sdmick #define IS_LEGACY_P6(cpi) ( \ 2081975Sdmick cpi->cpi_family == 6 && \ 2091975Sdmick (cpi->cpi_model == 1 || \ 2101975Sdmick cpi->cpi_model == 3 || \ 2111975Sdmick cpi->cpi_model == 5 || \ 2121975Sdmick cpi->cpi_model == 6 || \ 2131975Sdmick cpi->cpi_model == 7 || \ 2141975Sdmick cpi->cpi_model == 8 || \ 2151975Sdmick cpi->cpi_model == 0xA || \ 2161975Sdmick cpi->cpi_model == 0xB) \ 2171975Sdmick ) 2181975Sdmick 2191975Sdmick /* A "new F6" is everything with family 6 that's not the above */ 2201975Sdmick #define IS_NEW_F6(cpi) ((cpi->cpi_family == 6) && !IS_LEGACY_P6(cpi)) 2211975Sdmick 2221975Sdmick /* 2232869Sgavinm * AMD family 0xf socket types. 2242869Sgavinm * First index is 0 for revs B thru E, 1 for F and G. 2252869Sgavinm * Second index by (model & 0x3) 2262869Sgavinm */ 2272869Sgavinm static uint32_t amd_skts[2][4] = { 2282869Sgavinm { 2292869Sgavinm X86_SOCKET_754, /* 0b00 */ 2302869Sgavinm X86_SOCKET_940, /* 0b01 */ 2312869Sgavinm X86_SOCKET_754, /* 0b10 */ 2322869Sgavinm X86_SOCKET_939 /* 0b11 */ 2332869Sgavinm }, 2342869Sgavinm { 2352869Sgavinm X86_SOCKET_S1g1, /* 0b00 */ 2362869Sgavinm X86_SOCKET_F1207, /* 0b01 */ 2372869Sgavinm X86_SOCKET_UNKNOWN, /* 0b10 */ 2382869Sgavinm X86_SOCKET_AM2 /* 0b11 */ 2392869Sgavinm } 2402869Sgavinm }; 2412869Sgavinm 2422869Sgavinm /* 2432869Sgavinm * Table for mapping AMD Family 0xf model/stepping combination to 2442869Sgavinm * chip "revision" and socket type. Only rm_family 0xf is used at the 2452869Sgavinm * moment, but AMD family 0x10 will extend the exsiting revision names 2462869Sgavinm * so will likely also use this table. 2472869Sgavinm * 2482869Sgavinm * The first member of this array that matches a given family, extended model 2492869Sgavinm * plus model range, and stepping range will be considered a match. 2502869Sgavinm */ 2512869Sgavinm static const struct amd_rev_mapent { 2522869Sgavinm uint_t rm_family; 2532869Sgavinm uint_t rm_modello; 2542869Sgavinm uint_t rm_modelhi; 2552869Sgavinm uint_t rm_steplo; 2562869Sgavinm uint_t rm_stephi; 2572869Sgavinm uint32_t rm_chiprev; 2582869Sgavinm const char *rm_chiprevstr; 2592869Sgavinm int rm_sktidx; 2602869Sgavinm } amd_revmap[] = { 2612869Sgavinm /* 2622869Sgavinm * Rev B includes model 0x4 stepping 0 and model 0x5 stepping 0 and 1. 2632869Sgavinm */ 2642869Sgavinm { 0xf, 0x04, 0x04, 0x0, 0x0, X86_CHIPREV_AMD_F_REV_B, "B", 0 }, 2652869Sgavinm { 0xf, 0x05, 0x05, 0x0, 0x1, X86_CHIPREV_AMD_F_REV_B, "B", 0 }, 2662869Sgavinm /* 2672869Sgavinm * Rev C0 includes model 0x4 stepping 8 and model 0x5 stepping 8 2682869Sgavinm */ 2692869Sgavinm { 0xf, 0x04, 0x05, 0x8, 0x8, X86_CHIPREV_AMD_F_REV_C0, "C0", 0 }, 2702869Sgavinm /* 2712869Sgavinm * Rev CG is the rest of extended model 0x0 - i.e., everything 2722869Sgavinm * but the rev B and C0 combinations covered above. 2732869Sgavinm */ 2742869Sgavinm { 0xf, 0x00, 0x0f, 0x0, 0xf, X86_CHIPREV_AMD_F_REV_CG, "CG", 0 }, 2752869Sgavinm /* 2762869Sgavinm * Rev D has extended model 0x1. 2772869Sgavinm */ 2782869Sgavinm { 0xf, 0x10, 0x1f, 0x0, 0xf, X86_CHIPREV_AMD_F_REV_D, "D", 0 }, 2792869Sgavinm /* 2802869Sgavinm * Rev E has extended model 0x2. 2812869Sgavinm * Extended model 0x3 is unused but available to grow into. 2822869Sgavinm */ 2832869Sgavinm { 0xf, 0x20, 0x3f, 0x0, 0xf, X86_CHIPREV_AMD_F_REV_E, "E", 0 }, 2842869Sgavinm /* 2852869Sgavinm * Rev F has extended models 0x4 and 0x5. 2862869Sgavinm */ 2872869Sgavinm { 0xf, 0x40, 0x5f, 0x0, 0xf, X86_CHIPREV_AMD_F_REV_F, "F", 1 }, 2882869Sgavinm /* 2892869Sgavinm * Rev G has extended model 0x6. 2902869Sgavinm */ 2912869Sgavinm { 0xf, 0x60, 0x6f, 0x0, 0xf, X86_CHIPREV_AMD_F_REV_G, "G", 1 }, 2922869Sgavinm }; 2932869Sgavinm 2942869Sgavinm static void 2952869Sgavinm synth_amd_info(struct cpuid_info *cpi) 2962869Sgavinm { 2972869Sgavinm const struct amd_rev_mapent *rmp; 2982869Sgavinm uint_t family, model, step; 2992869Sgavinm int i; 3002869Sgavinm 3012869Sgavinm /* 3022869Sgavinm * Currently only AMD family 0xf uses these fields. 3032869Sgavinm */ 3042869Sgavinm if (cpi->cpi_family != 0xf) 3052869Sgavinm return; 3062869Sgavinm 3072869Sgavinm family = cpi->cpi_family; 3082869Sgavinm model = cpi->cpi_model; 3092869Sgavinm step = cpi->cpi_step; 3102869Sgavinm 3112869Sgavinm for (i = 0, rmp = amd_revmap; i < sizeof (amd_revmap) / sizeof (*rmp); 3122869Sgavinm i++, rmp++) { 3132869Sgavinm if (family == rmp->rm_family && 3142869Sgavinm model >= rmp->rm_modello && model <= rmp->rm_modelhi && 3152869Sgavinm step >= rmp->rm_steplo && step <= rmp->rm_stephi) { 3162869Sgavinm cpi->cpi_chiprev = rmp->rm_chiprev; 3172869Sgavinm cpi->cpi_chiprevstr = rmp->rm_chiprevstr; 3182869Sgavinm cpi->cpi_socket = amd_skts[rmp->rm_sktidx][model & 0x3]; 3192869Sgavinm return; 3202869Sgavinm } 3212869Sgavinm } 3222869Sgavinm } 3232869Sgavinm 3242869Sgavinm static void 3252869Sgavinm synth_info(struct cpuid_info *cpi) 3262869Sgavinm { 3272869Sgavinm cpi->cpi_chiprev = X86_CHIPREV_UNKNOWN; 3282869Sgavinm cpi->cpi_chiprevstr = "Unknown"; 3292869Sgavinm cpi->cpi_socket = X86_SOCKET_UNKNOWN; 3302869Sgavinm 3312869Sgavinm switch (cpi->cpi_vendor) { 3322869Sgavinm case X86_VENDOR_AMD: 3332869Sgavinm synth_amd_info(cpi); 3342869Sgavinm break; 3352869Sgavinm 3362869Sgavinm default: 3372869Sgavinm break; 3382869Sgavinm 3392869Sgavinm } 3402869Sgavinm } 3412869Sgavinm 3422869Sgavinm /* 3433446Smrj * Apply up various platform-dependent restrictions where the 3443446Smrj * underlying platform restrictions mean the CPU can be marked 3453446Smrj * as less capable than its cpuid instruction would imply. 3463446Smrj */ 3473446Smrj 3483446Smrj #define platform_cpuid_mangle(vendor, eax, cp) /* nothing */ 3493446Smrj 3503446Smrj /* 3510Sstevel@tonic-gate * Some undocumented ways of patching the results of the cpuid 3520Sstevel@tonic-gate * instruction to permit running Solaris 10 on future cpus that 3530Sstevel@tonic-gate * we don't currently support. Could be set to non-zero values 3540Sstevel@tonic-gate * via settings in eeprom. 3550Sstevel@tonic-gate */ 3560Sstevel@tonic-gate 3570Sstevel@tonic-gate uint32_t cpuid_feature_ecx_include; 3580Sstevel@tonic-gate uint32_t cpuid_feature_ecx_exclude; 3590Sstevel@tonic-gate uint32_t cpuid_feature_edx_include; 3600Sstevel@tonic-gate uint32_t cpuid_feature_edx_exclude; 3610Sstevel@tonic-gate 3623446Smrj void 3633446Smrj cpuid_alloc_space(cpu_t *cpu) 3643446Smrj { 3653446Smrj /* 3663446Smrj * By convention, cpu0 is the boot cpu, which is set up 3673446Smrj * before memory allocation is available. All other cpus get 3683446Smrj * their cpuid_info struct allocated here. 3693446Smrj */ 3703446Smrj ASSERT(cpu->cpu_id != 0); 3713446Smrj cpu->cpu_m.mcpu_cpi = 3723446Smrj kmem_zalloc(sizeof (*cpu->cpu_m.mcpu_cpi), KM_SLEEP); 3733446Smrj } 3743446Smrj 3753446Smrj void 3763446Smrj cpuid_free_space(cpu_t *cpu) 3773446Smrj { 3783446Smrj ASSERT(cpu->cpu_id != 0); 3793446Smrj kmem_free(cpu->cpu_m.mcpu_cpi, sizeof (*cpu->cpu_m.mcpu_cpi)); 3803446Smrj } 3813446Smrj 3820Sstevel@tonic-gate uint_t 3830Sstevel@tonic-gate cpuid_pass1(cpu_t *cpu) 3840Sstevel@tonic-gate { 3850Sstevel@tonic-gate uint32_t mask_ecx, mask_edx; 3860Sstevel@tonic-gate uint_t feature = X86_CPUID; 3870Sstevel@tonic-gate struct cpuid_info *cpi; 3881228Sandrei struct cpuid_regs *cp; 3890Sstevel@tonic-gate int xcpuid; 3900Sstevel@tonic-gate 3913446Smrj 3920Sstevel@tonic-gate /* 3933446Smrj * Space statically allocated for cpu0, ensure pointer is set 3940Sstevel@tonic-gate */ 3950Sstevel@tonic-gate if (cpu->cpu_id == 0) 3963446Smrj cpu->cpu_m.mcpu_cpi = &cpuid_info0; 3973446Smrj cpi = cpu->cpu_m.mcpu_cpi; 3983446Smrj ASSERT(cpi != NULL); 3990Sstevel@tonic-gate cp = &cpi->cpi_std[0]; 4001228Sandrei cp->cp_eax = 0; 4011228Sandrei cpi->cpi_maxeax = __cpuid_insn(cp); 4020Sstevel@tonic-gate { 4030Sstevel@tonic-gate uint32_t *iptr = (uint32_t *)cpi->cpi_vendorstr; 4040Sstevel@tonic-gate *iptr++ = cp->cp_ebx; 4050Sstevel@tonic-gate *iptr++ = cp->cp_edx; 4060Sstevel@tonic-gate *iptr++ = cp->cp_ecx; 4070Sstevel@tonic-gate *(char *)&cpi->cpi_vendorstr[12] = '\0'; 4080Sstevel@tonic-gate } 4090Sstevel@tonic-gate 4100Sstevel@tonic-gate /* 4110Sstevel@tonic-gate * Map the vendor string to a type code 4120Sstevel@tonic-gate */ 4130Sstevel@tonic-gate if (strcmp(cpi->cpi_vendorstr, "GenuineIntel") == 0) 4140Sstevel@tonic-gate cpi->cpi_vendor = X86_VENDOR_Intel; 4150Sstevel@tonic-gate else if (strcmp(cpi->cpi_vendorstr, "AuthenticAMD") == 0) 4160Sstevel@tonic-gate cpi->cpi_vendor = X86_VENDOR_AMD; 4170Sstevel@tonic-gate else if (strcmp(cpi->cpi_vendorstr, "GenuineTMx86") == 0) 4180Sstevel@tonic-gate cpi->cpi_vendor = X86_VENDOR_TM; 4190Sstevel@tonic-gate else if (strcmp(cpi->cpi_vendorstr, CyrixInstead) == 0) 4200Sstevel@tonic-gate /* 4210Sstevel@tonic-gate * CyrixInstead is a variable used by the Cyrix detection code 4220Sstevel@tonic-gate * in locore. 4230Sstevel@tonic-gate */ 4240Sstevel@tonic-gate cpi->cpi_vendor = X86_VENDOR_Cyrix; 4250Sstevel@tonic-gate else if (strcmp(cpi->cpi_vendorstr, "UMC UMC UMC ") == 0) 4260Sstevel@tonic-gate cpi->cpi_vendor = X86_VENDOR_UMC; 4270Sstevel@tonic-gate else if (strcmp(cpi->cpi_vendorstr, "NexGenDriven") == 0) 4280Sstevel@tonic-gate cpi->cpi_vendor = X86_VENDOR_NexGen; 4290Sstevel@tonic-gate else if (strcmp(cpi->cpi_vendorstr, "CentaurHauls") == 0) 4300Sstevel@tonic-gate cpi->cpi_vendor = X86_VENDOR_Centaur; 4310Sstevel@tonic-gate else if (strcmp(cpi->cpi_vendorstr, "RiseRiseRise") == 0) 4320Sstevel@tonic-gate cpi->cpi_vendor = X86_VENDOR_Rise; 4330Sstevel@tonic-gate else if (strcmp(cpi->cpi_vendorstr, "SiS SiS SiS ") == 0) 4340Sstevel@tonic-gate cpi->cpi_vendor = X86_VENDOR_SiS; 4350Sstevel@tonic-gate else if (strcmp(cpi->cpi_vendorstr, "Geode by NSC") == 0) 4360Sstevel@tonic-gate cpi->cpi_vendor = X86_VENDOR_NSC; 4370Sstevel@tonic-gate else 4380Sstevel@tonic-gate cpi->cpi_vendor = X86_VENDOR_IntelClone; 4390Sstevel@tonic-gate 4400Sstevel@tonic-gate x86_vendor = cpi->cpi_vendor; /* for compatibility */ 4410Sstevel@tonic-gate 4420Sstevel@tonic-gate /* 4430Sstevel@tonic-gate * Limit the range in case of weird hardware 4440Sstevel@tonic-gate */ 4450Sstevel@tonic-gate if (cpi->cpi_maxeax > CPI_MAXEAX_MAX) 4460Sstevel@tonic-gate cpi->cpi_maxeax = CPI_MAXEAX_MAX; 4470Sstevel@tonic-gate if (cpi->cpi_maxeax < 1) 4480Sstevel@tonic-gate goto pass1_done; 4490Sstevel@tonic-gate 4500Sstevel@tonic-gate cp = &cpi->cpi_std[1]; 4511228Sandrei cp->cp_eax = 1; 4521228Sandrei (void) __cpuid_insn(cp); 4530Sstevel@tonic-gate 4540Sstevel@tonic-gate /* 4550Sstevel@tonic-gate * Extract identifying constants for easy access. 4560Sstevel@tonic-gate */ 4570Sstevel@tonic-gate cpi->cpi_model = CPI_MODEL(cpi); 4580Sstevel@tonic-gate cpi->cpi_family = CPI_FAMILY(cpi); 4590Sstevel@tonic-gate 4601975Sdmick if (cpi->cpi_family == 0xf) 4610Sstevel@tonic-gate cpi->cpi_family += CPI_FAMILY_XTD(cpi); 4621975Sdmick 4632001Sdmick /* 4642001Sdmick * Beware: AMD uses "extended model" iff *FAMILY* == 0xf. 4652001Sdmick * Intel, and presumably everyone else, uses model == 0xf, as 4662001Sdmick * one would expect (max value means possible overflow). Sigh. 4672001Sdmick */ 4682001Sdmick 4692001Sdmick switch (cpi->cpi_vendor) { 4702001Sdmick case X86_VENDOR_AMD: 4712001Sdmick if (cpi->cpi_family == 0xf) 4722001Sdmick cpi->cpi_model += CPI_MODEL_XTD(cpi) << 4; 4732001Sdmick break; 4742001Sdmick default: 4752001Sdmick if (cpi->cpi_model == 0xf) 4762001Sdmick cpi->cpi_model += CPI_MODEL_XTD(cpi) << 4; 4772001Sdmick break; 4782001Sdmick } 4790Sstevel@tonic-gate 4800Sstevel@tonic-gate cpi->cpi_step = CPI_STEP(cpi); 4810Sstevel@tonic-gate cpi->cpi_brandid = CPI_BRANDID(cpi); 4820Sstevel@tonic-gate 4830Sstevel@tonic-gate /* 4840Sstevel@tonic-gate * *default* assumptions: 4850Sstevel@tonic-gate * - believe %edx feature word 4860Sstevel@tonic-gate * - ignore %ecx feature word 4870Sstevel@tonic-gate * - 32-bit virtual and physical addressing 4880Sstevel@tonic-gate */ 4890Sstevel@tonic-gate mask_edx = 0xffffffff; 4900Sstevel@tonic-gate mask_ecx = 0; 4910Sstevel@tonic-gate 4920Sstevel@tonic-gate cpi->cpi_pabits = cpi->cpi_vabits = 32; 4930Sstevel@tonic-gate 4940Sstevel@tonic-gate switch (cpi->cpi_vendor) { 4950Sstevel@tonic-gate case X86_VENDOR_Intel: 4960Sstevel@tonic-gate if (cpi->cpi_family == 5) 4970Sstevel@tonic-gate x86_type = X86_TYPE_P5; 4981975Sdmick else if (IS_LEGACY_P6(cpi)) { 4990Sstevel@tonic-gate x86_type = X86_TYPE_P6; 5000Sstevel@tonic-gate pentiumpro_bug4046376 = 1; 5010Sstevel@tonic-gate pentiumpro_bug4064495 = 1; 5020Sstevel@tonic-gate /* 5030Sstevel@tonic-gate * Clear the SEP bit when it was set erroneously 5040Sstevel@tonic-gate */ 5050Sstevel@tonic-gate if (cpi->cpi_model < 3 && cpi->cpi_step < 3) 5060Sstevel@tonic-gate cp->cp_edx &= ~CPUID_INTC_EDX_SEP; 5071975Sdmick } else if (IS_NEW_F6(cpi) || cpi->cpi_family == 0xf) { 5080Sstevel@tonic-gate x86_type = X86_TYPE_P4; 5090Sstevel@tonic-gate /* 5100Sstevel@tonic-gate * We don't currently depend on any of the %ecx 5110Sstevel@tonic-gate * features until Prescott, so we'll only check 5120Sstevel@tonic-gate * this from P4 onwards. We might want to revisit 5130Sstevel@tonic-gate * that idea later. 5140Sstevel@tonic-gate */ 5150Sstevel@tonic-gate mask_ecx = 0xffffffff; 5160Sstevel@tonic-gate } else if (cpi->cpi_family > 0xf) 5170Sstevel@tonic-gate mask_ecx = 0xffffffff; 5180Sstevel@tonic-gate break; 5190Sstevel@tonic-gate case X86_VENDOR_IntelClone: 5200Sstevel@tonic-gate default: 5210Sstevel@tonic-gate break; 5220Sstevel@tonic-gate case X86_VENDOR_AMD: 5230Sstevel@tonic-gate #if defined(OPTERON_ERRATUM_108) 5240Sstevel@tonic-gate if (cpi->cpi_family == 0xf && cpi->cpi_model == 0xe) { 5250Sstevel@tonic-gate cp->cp_eax = (0xf0f & cp->cp_eax) | 0xc0; 5260Sstevel@tonic-gate cpi->cpi_model = 0xc; 5270Sstevel@tonic-gate } else 5280Sstevel@tonic-gate #endif 5290Sstevel@tonic-gate if (cpi->cpi_family == 5) { 5300Sstevel@tonic-gate /* 5310Sstevel@tonic-gate * AMD K5 and K6 5320Sstevel@tonic-gate * 5330Sstevel@tonic-gate * These CPUs have an incomplete implementation 5340Sstevel@tonic-gate * of MCA/MCE which we mask away. 5350Sstevel@tonic-gate */ 5361228Sandrei mask_edx &= ~(CPUID_INTC_EDX_MCE | CPUID_INTC_EDX_MCA); 5371228Sandrei 5381228Sandrei /* 5391228Sandrei * Model 0 uses the wrong (APIC) bit 5401228Sandrei * to indicate PGE. Fix it here. 5411228Sandrei */ 5420Sstevel@tonic-gate if (cpi->cpi_model == 0) { 5430Sstevel@tonic-gate if (cp->cp_edx & 0x200) { 5440Sstevel@tonic-gate cp->cp_edx &= ~0x200; 5450Sstevel@tonic-gate cp->cp_edx |= CPUID_INTC_EDX_PGE; 5460Sstevel@tonic-gate } 5471228Sandrei } 5481228Sandrei 5491228Sandrei /* 5501228Sandrei * Early models had problems w/ MMX; disable. 5511228Sandrei */ 5521228Sandrei if (cpi->cpi_model < 6) 5531228Sandrei mask_edx &= ~CPUID_INTC_EDX_MMX; 5541228Sandrei } 5551228Sandrei 5561228Sandrei /* 5571228Sandrei * For newer families, SSE3 and CX16, at least, are valid; 5581228Sandrei * enable all 5591228Sandrei */ 5601228Sandrei if (cpi->cpi_family >= 0xf) 561771Sdmick mask_ecx = 0xffffffff; 5620Sstevel@tonic-gate break; 5630Sstevel@tonic-gate case X86_VENDOR_TM: 5640Sstevel@tonic-gate /* 5650Sstevel@tonic-gate * workaround the NT workaround in CMS 4.1 5660Sstevel@tonic-gate */ 5670Sstevel@tonic-gate if (cpi->cpi_family == 5 && cpi->cpi_model == 4 && 5680Sstevel@tonic-gate (cpi->cpi_step == 2 || cpi->cpi_step == 3)) 5690Sstevel@tonic-gate cp->cp_edx |= CPUID_INTC_EDX_CX8; 5700Sstevel@tonic-gate break; 5710Sstevel@tonic-gate case X86_VENDOR_Centaur: 5720Sstevel@tonic-gate /* 5730Sstevel@tonic-gate * workaround the NT workarounds again 5740Sstevel@tonic-gate */ 5750Sstevel@tonic-gate if (cpi->cpi_family == 6) 5760Sstevel@tonic-gate cp->cp_edx |= CPUID_INTC_EDX_CX8; 5770Sstevel@tonic-gate break; 5780Sstevel@tonic-gate case X86_VENDOR_Cyrix: 5790Sstevel@tonic-gate /* 5800Sstevel@tonic-gate * We rely heavily on the probing in locore 5810Sstevel@tonic-gate * to actually figure out what parts, if any, 5820Sstevel@tonic-gate * of the Cyrix cpuid instruction to believe. 5830Sstevel@tonic-gate */ 5840Sstevel@tonic-gate switch (x86_type) { 5850Sstevel@tonic-gate case X86_TYPE_CYRIX_486: 5860Sstevel@tonic-gate mask_edx = 0; 5870Sstevel@tonic-gate break; 5880Sstevel@tonic-gate case X86_TYPE_CYRIX_6x86: 5890Sstevel@tonic-gate mask_edx = 0; 5900Sstevel@tonic-gate break; 5910Sstevel@tonic-gate case X86_TYPE_CYRIX_6x86L: 5920Sstevel@tonic-gate mask_edx = 5930Sstevel@tonic-gate CPUID_INTC_EDX_DE | 5940Sstevel@tonic-gate CPUID_INTC_EDX_CX8; 5950Sstevel@tonic-gate break; 5960Sstevel@tonic-gate case X86_TYPE_CYRIX_6x86MX: 5970Sstevel@tonic-gate mask_edx = 5980Sstevel@tonic-gate CPUID_INTC_EDX_DE | 5990Sstevel@tonic-gate CPUID_INTC_EDX_MSR | 6000Sstevel@tonic-gate CPUID_INTC_EDX_CX8 | 6010Sstevel@tonic-gate CPUID_INTC_EDX_PGE | 6020Sstevel@tonic-gate CPUID_INTC_EDX_CMOV | 6030Sstevel@tonic-gate CPUID_INTC_EDX_MMX; 6040Sstevel@tonic-gate break; 6050Sstevel@tonic-gate case X86_TYPE_CYRIX_GXm: 6060Sstevel@tonic-gate mask_edx = 6070Sstevel@tonic-gate CPUID_INTC_EDX_MSR | 6080Sstevel@tonic-gate CPUID_INTC_EDX_CX8 | 6090Sstevel@tonic-gate CPUID_INTC_EDX_CMOV | 6100Sstevel@tonic-gate CPUID_INTC_EDX_MMX; 6110Sstevel@tonic-gate break; 6120Sstevel@tonic-gate case X86_TYPE_CYRIX_MediaGX: 6130Sstevel@tonic-gate break; 6140Sstevel@tonic-gate case X86_TYPE_CYRIX_MII: 6150Sstevel@tonic-gate case X86_TYPE_VIA_CYRIX_III: 6160Sstevel@tonic-gate mask_edx = 6170Sstevel@tonic-gate CPUID_INTC_EDX_DE | 6180Sstevel@tonic-gate CPUID_INTC_EDX_TSC | 6190Sstevel@tonic-gate CPUID_INTC_EDX_MSR | 6200Sstevel@tonic-gate CPUID_INTC_EDX_CX8 | 6210Sstevel@tonic-gate CPUID_INTC_EDX_PGE | 6220Sstevel@tonic-gate CPUID_INTC_EDX_CMOV | 6230Sstevel@tonic-gate CPUID_INTC_EDX_MMX; 6240Sstevel@tonic-gate break; 6250Sstevel@tonic-gate default: 6260Sstevel@tonic-gate break; 6270Sstevel@tonic-gate } 6280Sstevel@tonic-gate break; 6290Sstevel@tonic-gate } 6300Sstevel@tonic-gate 6310Sstevel@tonic-gate /* 6320Sstevel@tonic-gate * Now we've figured out the masks that determine 6330Sstevel@tonic-gate * which bits we choose to believe, apply the masks 6340Sstevel@tonic-gate * to the feature words, then map the kernel's view 6350Sstevel@tonic-gate * of these feature words into its feature word. 6360Sstevel@tonic-gate */ 6370Sstevel@tonic-gate cp->cp_edx &= mask_edx; 6380Sstevel@tonic-gate cp->cp_ecx &= mask_ecx; 6390Sstevel@tonic-gate 6400Sstevel@tonic-gate /* 6413446Smrj * apply any platform restrictions (we don't call this 6423446Smrj * immediately after __cpuid_insn here, because we need the 6433446Smrj * workarounds applied above first) 6440Sstevel@tonic-gate */ 6453446Smrj platform_cpuid_mangle(cpi->cpi_vendor, 1, cp); 6460Sstevel@tonic-gate 6473446Smrj /* 6483446Smrj * fold in overrides from the "eeprom" mechanism 6493446Smrj */ 6500Sstevel@tonic-gate cp->cp_edx |= cpuid_feature_edx_include; 6510Sstevel@tonic-gate cp->cp_edx &= ~cpuid_feature_edx_exclude; 6520Sstevel@tonic-gate 6530Sstevel@tonic-gate cp->cp_ecx |= cpuid_feature_ecx_include; 6540Sstevel@tonic-gate cp->cp_ecx &= ~cpuid_feature_ecx_exclude; 6550Sstevel@tonic-gate 6560Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_PSE) 6570Sstevel@tonic-gate feature |= X86_LARGEPAGE; 6580Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_TSC) 6590Sstevel@tonic-gate feature |= X86_TSC; 6600Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_MSR) 6610Sstevel@tonic-gate feature |= X86_MSR; 6620Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_MTRR) 6630Sstevel@tonic-gate feature |= X86_MTRR; 6640Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_PGE) 6650Sstevel@tonic-gate feature |= X86_PGE; 6660Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_CMOV) 6670Sstevel@tonic-gate feature |= X86_CMOV; 6680Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_MMX) 6690Sstevel@tonic-gate feature |= X86_MMX; 6700Sstevel@tonic-gate if ((cp->cp_edx & CPUID_INTC_EDX_MCE) != 0 && 6710Sstevel@tonic-gate (cp->cp_edx & CPUID_INTC_EDX_MCA) != 0) 6720Sstevel@tonic-gate feature |= X86_MCA; 6730Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_PAE) 6740Sstevel@tonic-gate feature |= X86_PAE; 6750Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_CX8) 6760Sstevel@tonic-gate feature |= X86_CX8; 6770Sstevel@tonic-gate if (cp->cp_ecx & CPUID_INTC_ECX_CX16) 6780Sstevel@tonic-gate feature |= X86_CX16; 6790Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_PAT) 6800Sstevel@tonic-gate feature |= X86_PAT; 6810Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_SEP) 6820Sstevel@tonic-gate feature |= X86_SEP; 6830Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_FXSR) { 6840Sstevel@tonic-gate /* 6850Sstevel@tonic-gate * In our implementation, fxsave/fxrstor 6860Sstevel@tonic-gate * are prerequisites before we'll even 6870Sstevel@tonic-gate * try and do SSE things. 6880Sstevel@tonic-gate */ 6890Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_SSE) 6900Sstevel@tonic-gate feature |= X86_SSE; 6910Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_SSE2) 6920Sstevel@tonic-gate feature |= X86_SSE2; 6930Sstevel@tonic-gate if (cp->cp_ecx & CPUID_INTC_ECX_SSE3) 6940Sstevel@tonic-gate feature |= X86_SSE3; 6950Sstevel@tonic-gate } 6960Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_DE) 6973446Smrj feature |= X86_DE; 6980Sstevel@tonic-gate 6990Sstevel@tonic-gate if (feature & X86_PAE) 7000Sstevel@tonic-gate cpi->cpi_pabits = 36; 7010Sstevel@tonic-gate 7020Sstevel@tonic-gate /* 7030Sstevel@tonic-gate * Hyperthreading configuration is slightly tricky on Intel 7040Sstevel@tonic-gate * and pure clones, and even trickier on AMD. 7050Sstevel@tonic-gate * 7060Sstevel@tonic-gate * (AMD chose to set the HTT bit on their CMP processors, 7070Sstevel@tonic-gate * even though they're not actually hyperthreaded. Thus it 7080Sstevel@tonic-gate * takes a bit more work to figure out what's really going 7093446Smrj * on ... see the handling of the CMP_LGCY bit below) 7100Sstevel@tonic-gate */ 7110Sstevel@tonic-gate if (cp->cp_edx & CPUID_INTC_EDX_HTT) { 7120Sstevel@tonic-gate cpi->cpi_ncpu_per_chip = CPI_CPU_COUNT(cpi); 7130Sstevel@tonic-gate if (cpi->cpi_ncpu_per_chip > 1) 7140Sstevel@tonic-gate feature |= X86_HTT; 7151228Sandrei } else { 7161228Sandrei cpi->cpi_ncpu_per_chip = 1; 7170Sstevel@tonic-gate } 7180Sstevel@tonic-gate 7190Sstevel@tonic-gate /* 7200Sstevel@tonic-gate * Work on the "extended" feature information, doing 7210Sstevel@tonic-gate * some basic initialization for cpuid_pass2() 7220Sstevel@tonic-gate */ 7230Sstevel@tonic-gate xcpuid = 0; 7240Sstevel@tonic-gate switch (cpi->cpi_vendor) { 7250Sstevel@tonic-gate case X86_VENDOR_Intel: 7261975Sdmick if (IS_NEW_F6(cpi) || cpi->cpi_family >= 0xf) 7270Sstevel@tonic-gate xcpuid++; 7280Sstevel@tonic-gate break; 7290Sstevel@tonic-gate case X86_VENDOR_AMD: 7300Sstevel@tonic-gate if (cpi->cpi_family > 5 || 7310Sstevel@tonic-gate (cpi->cpi_family == 5 && cpi->cpi_model >= 1)) 7320Sstevel@tonic-gate xcpuid++; 7330Sstevel@tonic-gate break; 7340Sstevel@tonic-gate case X86_VENDOR_Cyrix: 7350Sstevel@tonic-gate /* 7360Sstevel@tonic-gate * Only these Cyrix CPUs are -known- to support 7370Sstevel@tonic-gate * extended cpuid operations. 7380Sstevel@tonic-gate */ 7390Sstevel@tonic-gate if (x86_type == X86_TYPE_VIA_CYRIX_III || 7400Sstevel@tonic-gate x86_type == X86_TYPE_CYRIX_GXm) 7410Sstevel@tonic-gate xcpuid++; 7420Sstevel@tonic-gate break; 7430Sstevel@tonic-gate case X86_VENDOR_Centaur: 7440Sstevel@tonic-gate case X86_VENDOR_TM: 7450Sstevel@tonic-gate default: 7460Sstevel@tonic-gate xcpuid++; 7470Sstevel@tonic-gate break; 7480Sstevel@tonic-gate } 7490Sstevel@tonic-gate 7500Sstevel@tonic-gate if (xcpuid) { 7510Sstevel@tonic-gate cp = &cpi->cpi_extd[0]; 7521228Sandrei cp->cp_eax = 0x80000000; 7531228Sandrei cpi->cpi_xmaxeax = __cpuid_insn(cp); 7540Sstevel@tonic-gate } 7550Sstevel@tonic-gate 7560Sstevel@tonic-gate if (cpi->cpi_xmaxeax & 0x80000000) { 7570Sstevel@tonic-gate 7580Sstevel@tonic-gate if (cpi->cpi_xmaxeax > CPI_XMAXEAX_MAX) 7590Sstevel@tonic-gate cpi->cpi_xmaxeax = CPI_XMAXEAX_MAX; 7600Sstevel@tonic-gate 7610Sstevel@tonic-gate switch (cpi->cpi_vendor) { 7620Sstevel@tonic-gate case X86_VENDOR_Intel: 7630Sstevel@tonic-gate case X86_VENDOR_AMD: 7640Sstevel@tonic-gate if (cpi->cpi_xmaxeax < 0x80000001) 7650Sstevel@tonic-gate break; 7660Sstevel@tonic-gate cp = &cpi->cpi_extd[1]; 7671228Sandrei cp->cp_eax = 0x80000001; 7681228Sandrei (void) __cpuid_insn(cp); 7693446Smrj 7700Sstevel@tonic-gate if (cpi->cpi_vendor == X86_VENDOR_AMD && 7710Sstevel@tonic-gate cpi->cpi_family == 5 && 7720Sstevel@tonic-gate cpi->cpi_model == 6 && 7730Sstevel@tonic-gate cpi->cpi_step == 6) { 7740Sstevel@tonic-gate /* 7750Sstevel@tonic-gate * K6 model 6 uses bit 10 to indicate SYSC 7760Sstevel@tonic-gate * Later models use bit 11. Fix it here. 7770Sstevel@tonic-gate */ 7780Sstevel@tonic-gate if (cp->cp_edx & 0x400) { 7790Sstevel@tonic-gate cp->cp_edx &= ~0x400; 7800Sstevel@tonic-gate cp->cp_edx |= CPUID_AMD_EDX_SYSC; 7810Sstevel@tonic-gate } 7820Sstevel@tonic-gate } 7830Sstevel@tonic-gate 7843446Smrj platform_cpuid_mangle(cpi->cpi_vendor, 0x80000001, cp); 7853446Smrj 7860Sstevel@tonic-gate /* 7870Sstevel@tonic-gate * Compute the additions to the kernel's feature word. 7880Sstevel@tonic-gate */ 7890Sstevel@tonic-gate if (cp->cp_edx & CPUID_AMD_EDX_NX) 7900Sstevel@tonic-gate feature |= X86_NX; 7910Sstevel@tonic-gate 7920Sstevel@tonic-gate /* 7933446Smrj * If both the HTT and CMP_LGCY bits are set, 7941228Sandrei * then we're not actually HyperThreaded. Read 7951228Sandrei * "AMD CPUID Specification" for more details. 7960Sstevel@tonic-gate */ 7970Sstevel@tonic-gate if (cpi->cpi_vendor == X86_VENDOR_AMD && 7981228Sandrei (feature & X86_HTT) && 7993446Smrj (cp->cp_ecx & CPUID_AMD_ECX_CMP_LGCY)) { 8000Sstevel@tonic-gate feature &= ~X86_HTT; 8011228Sandrei feature |= X86_CMP; 8021228Sandrei } 8033446Smrj #if defined(__amd64) 8040Sstevel@tonic-gate /* 8050Sstevel@tonic-gate * It's really tricky to support syscall/sysret in 8060Sstevel@tonic-gate * the i386 kernel; we rely on sysenter/sysexit 8070Sstevel@tonic-gate * instead. In the amd64 kernel, things are -way- 8080Sstevel@tonic-gate * better. 8090Sstevel@tonic-gate */ 8100Sstevel@tonic-gate if (cp->cp_edx & CPUID_AMD_EDX_SYSC) 8110Sstevel@tonic-gate feature |= X86_ASYSC; 8120Sstevel@tonic-gate 8130Sstevel@tonic-gate /* 8140Sstevel@tonic-gate * While we're thinking about system calls, note 8150Sstevel@tonic-gate * that AMD processors don't support sysenter 8160Sstevel@tonic-gate * in long mode at all, so don't try to program them. 8170Sstevel@tonic-gate */ 8180Sstevel@tonic-gate if (x86_vendor == X86_VENDOR_AMD) 8190Sstevel@tonic-gate feature &= ~X86_SEP; 8200Sstevel@tonic-gate #endif 8213446Smrj if (cp->cp_edx & CPUID_AMD_EDX_TSCP) 8223446Smrj feature |= X86_TSCP; 8230Sstevel@tonic-gate break; 8240Sstevel@tonic-gate default: 8250Sstevel@tonic-gate break; 8260Sstevel@tonic-gate } 8270Sstevel@tonic-gate 8281228Sandrei /* 8291228Sandrei * Get CPUID data about processor cores and hyperthreads. 8301228Sandrei */ 8310Sstevel@tonic-gate switch (cpi->cpi_vendor) { 8320Sstevel@tonic-gate case X86_VENDOR_Intel: 8331228Sandrei if (cpi->cpi_maxeax >= 4) { 8341228Sandrei cp = &cpi->cpi_std[4]; 8351228Sandrei cp->cp_eax = 4; 8361228Sandrei cp->cp_ecx = 0; 8371228Sandrei (void) __cpuid_insn(cp); 8383446Smrj platform_cpuid_mangle(cpi->cpi_vendor, 4, cp); 8391228Sandrei } 8401228Sandrei /*FALLTHROUGH*/ 8410Sstevel@tonic-gate case X86_VENDOR_AMD: 8420Sstevel@tonic-gate if (cpi->cpi_xmaxeax < 0x80000008) 8430Sstevel@tonic-gate break; 8440Sstevel@tonic-gate cp = &cpi->cpi_extd[8]; 8451228Sandrei cp->cp_eax = 0x80000008; 8461228Sandrei (void) __cpuid_insn(cp); 8473446Smrj platform_cpuid_mangle(cpi->cpi_vendor, 0x80000008, cp); 8483446Smrj 8490Sstevel@tonic-gate /* 8500Sstevel@tonic-gate * Virtual and physical address limits from 8510Sstevel@tonic-gate * cpuid override previously guessed values. 8520Sstevel@tonic-gate */ 8530Sstevel@tonic-gate cpi->cpi_pabits = BITX(cp->cp_eax, 7, 0); 8540Sstevel@tonic-gate cpi->cpi_vabits = BITX(cp->cp_eax, 15, 8); 8550Sstevel@tonic-gate break; 8560Sstevel@tonic-gate default: 8570Sstevel@tonic-gate break; 8580Sstevel@tonic-gate } 8591228Sandrei 8601228Sandrei switch (cpi->cpi_vendor) { 8611228Sandrei case X86_VENDOR_Intel: 8621228Sandrei if (cpi->cpi_maxeax < 4) { 8631228Sandrei cpi->cpi_ncore_per_chip = 1; 8641228Sandrei break; 8651228Sandrei } else { 8661228Sandrei cpi->cpi_ncore_per_chip = 8671228Sandrei BITX((cpi)->cpi_std[4].cp_eax, 31, 26) + 1; 8681228Sandrei } 8691228Sandrei break; 8701228Sandrei case X86_VENDOR_AMD: 8711228Sandrei if (cpi->cpi_xmaxeax < 0x80000008) { 8721228Sandrei cpi->cpi_ncore_per_chip = 1; 8731228Sandrei break; 8741228Sandrei } else { 8751228Sandrei cpi->cpi_ncore_per_chip = 8761228Sandrei BITX((cpi)->cpi_extd[8].cp_ecx, 7, 0) + 1; 8771228Sandrei } 8781228Sandrei break; 8791228Sandrei default: 8801228Sandrei cpi->cpi_ncore_per_chip = 1; 8811228Sandrei break; 8821228Sandrei } 8830Sstevel@tonic-gate } 8840Sstevel@tonic-gate 8851228Sandrei /* 8861228Sandrei * If more than one core, then this processor is CMP. 8871228Sandrei */ 8881228Sandrei if (cpi->cpi_ncore_per_chip > 1) 8891228Sandrei feature |= X86_CMP; 8903446Smrj 8911228Sandrei /* 8921228Sandrei * If the number of cores is the same as the number 8931228Sandrei * of CPUs, then we cannot have HyperThreading. 8941228Sandrei */ 8951228Sandrei if (cpi->cpi_ncpu_per_chip == cpi->cpi_ncore_per_chip) 8961228Sandrei feature &= ~X86_HTT; 8971228Sandrei 8980Sstevel@tonic-gate if ((feature & (X86_HTT | X86_CMP)) == 0) { 8991228Sandrei /* 9001228Sandrei * Single-core single-threaded processors. 9011228Sandrei */ 9020Sstevel@tonic-gate cpi->cpi_chipid = -1; 9030Sstevel@tonic-gate cpi->cpi_clogid = 0; 9041228Sandrei cpi->cpi_coreid = cpu->cpu_id; 9050Sstevel@tonic-gate } else if (cpi->cpi_ncpu_per_chip > 1) { 9061228Sandrei uint_t i; 9071228Sandrei uint_t chipid_shift = 0; 9081228Sandrei uint_t coreid_shift = 0; 9091228Sandrei uint_t apic_id = CPI_APIC_ID(cpi); 9101228Sandrei 9111228Sandrei for (i = 1; i < cpi->cpi_ncpu_per_chip; i <<= 1) 9121228Sandrei chipid_shift++; 9131228Sandrei cpi->cpi_chipid = apic_id >> chipid_shift; 9141228Sandrei cpi->cpi_clogid = apic_id & ((1 << chipid_shift) - 1); 9150Sstevel@tonic-gate 9161228Sandrei if (cpi->cpi_vendor == X86_VENDOR_Intel) { 9171228Sandrei if (feature & X86_CMP) { 9181228Sandrei /* 9191228Sandrei * Multi-core (and possibly multi-threaded) 9201228Sandrei * processors. 9211228Sandrei */ 9221228Sandrei uint_t ncpu_per_core; 9231228Sandrei if (cpi->cpi_ncore_per_chip == 1) 9241228Sandrei ncpu_per_core = cpi->cpi_ncpu_per_chip; 9251228Sandrei else if (cpi->cpi_ncore_per_chip > 1) 9261228Sandrei ncpu_per_core = cpi->cpi_ncpu_per_chip / 9271228Sandrei cpi->cpi_ncore_per_chip; 9281228Sandrei /* 9291228Sandrei * 8bit APIC IDs on dual core Pentiums 9301228Sandrei * look like this: 9311228Sandrei * 9321228Sandrei * +-----------------------+------+------+ 9331228Sandrei * | Physical Package ID | MC | HT | 9341228Sandrei * +-----------------------+------+------+ 9351228Sandrei * <------- chipid --------> 9361228Sandrei * <------- coreid ---------------> 9371228Sandrei * <--- clogid --> 9381228Sandrei * 9391228Sandrei * Where the number of bits necessary to 9401228Sandrei * represent MC and HT fields together equals 9411228Sandrei * to the minimum number of bits necessary to 9421228Sandrei * store the value of cpi->cpi_ncpu_per_chip. 9431228Sandrei * Of those bits, the MC part uses the number 9441228Sandrei * of bits necessary to store the value of 9451228Sandrei * cpi->cpi_ncore_per_chip. 9461228Sandrei */ 9471228Sandrei for (i = 1; i < ncpu_per_core; i <<= 1) 9481228Sandrei coreid_shift++; 9491727Sandrei cpi->cpi_coreid = apic_id >> coreid_shift; 9501228Sandrei } else if (feature & X86_HTT) { 9511228Sandrei /* 9521228Sandrei * Single-core multi-threaded processors. 9531228Sandrei */ 9541228Sandrei cpi->cpi_coreid = cpi->cpi_chipid; 9551228Sandrei } 9561228Sandrei } else if (cpi->cpi_vendor == X86_VENDOR_AMD) { 9571228Sandrei /* 9581228Sandrei * AMD currently only has dual-core processors with 9591228Sandrei * single-threaded cores. If they ever release 9601228Sandrei * multi-threaded processors, then this code 9611228Sandrei * will have to be updated. 9621228Sandrei */ 9631228Sandrei cpi->cpi_coreid = cpu->cpu_id; 9641228Sandrei } else { 9651228Sandrei /* 9661228Sandrei * All other processors are currently 9671228Sandrei * assumed to have single cores. 9681228Sandrei */ 9691228Sandrei cpi->cpi_coreid = cpi->cpi_chipid; 9701228Sandrei } 9710Sstevel@tonic-gate } 9720Sstevel@tonic-gate 9732869Sgavinm /* 9742869Sgavinm * Synthesize chip "revision" and socket type 9752869Sgavinm */ 9762869Sgavinm synth_info(cpi); 9772869Sgavinm 9780Sstevel@tonic-gate pass1_done: 9790Sstevel@tonic-gate cpi->cpi_pass = 1; 9800Sstevel@tonic-gate return (feature); 9810Sstevel@tonic-gate } 9820Sstevel@tonic-gate 9830Sstevel@tonic-gate /* 9840Sstevel@tonic-gate * Make copies of the cpuid table entries we depend on, in 9850Sstevel@tonic-gate * part for ease of parsing now, in part so that we have only 9860Sstevel@tonic-gate * one place to correct any of it, in part for ease of 9870Sstevel@tonic-gate * later export to userland, and in part so we can look at 9880Sstevel@tonic-gate * this stuff in a crash dump. 9890Sstevel@tonic-gate */ 9900Sstevel@tonic-gate 9910Sstevel@tonic-gate /*ARGSUSED*/ 9920Sstevel@tonic-gate void 9930Sstevel@tonic-gate cpuid_pass2(cpu_t *cpu) 9940Sstevel@tonic-gate { 9950Sstevel@tonic-gate uint_t n, nmax; 9960Sstevel@tonic-gate int i; 9971228Sandrei struct cpuid_regs *cp; 9980Sstevel@tonic-gate uint8_t *dp; 9990Sstevel@tonic-gate uint32_t *iptr; 10000Sstevel@tonic-gate struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 10010Sstevel@tonic-gate 10020Sstevel@tonic-gate ASSERT(cpi->cpi_pass == 1); 10030Sstevel@tonic-gate 10040Sstevel@tonic-gate if (cpi->cpi_maxeax < 1) 10050Sstevel@tonic-gate goto pass2_done; 10060Sstevel@tonic-gate 10070Sstevel@tonic-gate if ((nmax = cpi->cpi_maxeax + 1) > NMAX_CPI_STD) 10080Sstevel@tonic-gate nmax = NMAX_CPI_STD; 10090Sstevel@tonic-gate /* 10100Sstevel@tonic-gate * (We already handled n == 0 and n == 1 in pass 1) 10110Sstevel@tonic-gate */ 10120Sstevel@tonic-gate for (n = 2, cp = &cpi->cpi_std[2]; n < nmax; n++, cp++) { 10131228Sandrei cp->cp_eax = n; 10141228Sandrei (void) __cpuid_insn(cp); 10153446Smrj platform_cpuid_mangle(cpi->cpi_vendor, n, cp); 10160Sstevel@tonic-gate switch (n) { 10170Sstevel@tonic-gate case 2: 10180Sstevel@tonic-gate /* 10190Sstevel@tonic-gate * "the lower 8 bits of the %eax register 10200Sstevel@tonic-gate * contain a value that identifies the number 10210Sstevel@tonic-gate * of times the cpuid [instruction] has to be 10220Sstevel@tonic-gate * executed to obtain a complete image of the 10230Sstevel@tonic-gate * processor's caching systems." 10240Sstevel@tonic-gate * 10250Sstevel@tonic-gate * How *do* they make this stuff up? 10260Sstevel@tonic-gate */ 10270Sstevel@tonic-gate cpi->cpi_ncache = sizeof (*cp) * 10280Sstevel@tonic-gate BITX(cp->cp_eax, 7, 0); 10290Sstevel@tonic-gate if (cpi->cpi_ncache == 0) 10300Sstevel@tonic-gate break; 10310Sstevel@tonic-gate cpi->cpi_ncache--; /* skip count byte */ 10320Sstevel@tonic-gate 10330Sstevel@tonic-gate /* 10340Sstevel@tonic-gate * Well, for now, rather than attempt to implement 10350Sstevel@tonic-gate * this slightly dubious algorithm, we just look 10360Sstevel@tonic-gate * at the first 15 .. 10370Sstevel@tonic-gate */ 10380Sstevel@tonic-gate if (cpi->cpi_ncache > (sizeof (*cp) - 1)) 10390Sstevel@tonic-gate cpi->cpi_ncache = sizeof (*cp) - 1; 10400Sstevel@tonic-gate 10410Sstevel@tonic-gate dp = cpi->cpi_cacheinfo; 10420Sstevel@tonic-gate if (BITX(cp->cp_eax, 31, 31) == 0) { 10430Sstevel@tonic-gate uint8_t *p = (void *)&cp->cp_eax; 10440Sstevel@tonic-gate for (i = 1; i < 3; i++) 10450Sstevel@tonic-gate if (p[i] != 0) 10460Sstevel@tonic-gate *dp++ = p[i]; 10470Sstevel@tonic-gate } 10480Sstevel@tonic-gate if (BITX(cp->cp_ebx, 31, 31) == 0) { 10490Sstevel@tonic-gate uint8_t *p = (void *)&cp->cp_ebx; 10500Sstevel@tonic-gate for (i = 0; i < 4; i++) 10510Sstevel@tonic-gate if (p[i] != 0) 10520Sstevel@tonic-gate *dp++ = p[i]; 10530Sstevel@tonic-gate } 10540Sstevel@tonic-gate if (BITX(cp->cp_ecx, 31, 31) == 0) { 10550Sstevel@tonic-gate uint8_t *p = (void *)&cp->cp_ecx; 10560Sstevel@tonic-gate for (i = 0; i < 4; i++) 10570Sstevel@tonic-gate if (p[i] != 0) 10580Sstevel@tonic-gate *dp++ = p[i]; 10590Sstevel@tonic-gate } 10600Sstevel@tonic-gate if (BITX(cp->cp_edx, 31, 31) == 0) { 10610Sstevel@tonic-gate uint8_t *p = (void *)&cp->cp_edx; 10620Sstevel@tonic-gate for (i = 0; i < 4; i++) 10630Sstevel@tonic-gate if (p[i] != 0) 10640Sstevel@tonic-gate *dp++ = p[i]; 10650Sstevel@tonic-gate } 10660Sstevel@tonic-gate break; 10670Sstevel@tonic-gate case 3: /* Processor serial number, if PSN supported */ 10680Sstevel@tonic-gate case 4: /* Deterministic cache parameters */ 10690Sstevel@tonic-gate case 5: /* Monitor/Mwait parameters */ 10700Sstevel@tonic-gate default: 10710Sstevel@tonic-gate break; 10720Sstevel@tonic-gate } 10730Sstevel@tonic-gate } 10740Sstevel@tonic-gate 10750Sstevel@tonic-gate if ((cpi->cpi_xmaxeax & 0x80000000) == 0) 10760Sstevel@tonic-gate goto pass2_done; 10770Sstevel@tonic-gate 10780Sstevel@tonic-gate if ((nmax = cpi->cpi_xmaxeax - 0x80000000 + 1) > NMAX_CPI_EXTD) 10790Sstevel@tonic-gate nmax = NMAX_CPI_EXTD; 10800Sstevel@tonic-gate /* 10810Sstevel@tonic-gate * Copy the extended properties, fixing them as we go. 10820Sstevel@tonic-gate * (We already handled n == 0 and n == 1 in pass 1) 10830Sstevel@tonic-gate */ 10840Sstevel@tonic-gate iptr = (void *)cpi->cpi_brandstr; 10850Sstevel@tonic-gate for (n = 2, cp = &cpi->cpi_extd[2]; n < nmax; cp++, n++) { 10861228Sandrei cp->cp_eax = 0x80000000 + n; 10871228Sandrei (void) __cpuid_insn(cp); 10883446Smrj platform_cpuid_mangle(cpi->cpi_vendor, 0x80000000 + n, cp); 10890Sstevel@tonic-gate switch (n) { 10900Sstevel@tonic-gate case 2: 10910Sstevel@tonic-gate case 3: 10920Sstevel@tonic-gate case 4: 10930Sstevel@tonic-gate /* 10940Sstevel@tonic-gate * Extract the brand string 10950Sstevel@tonic-gate */ 10960Sstevel@tonic-gate *iptr++ = cp->cp_eax; 10970Sstevel@tonic-gate *iptr++ = cp->cp_ebx; 10980Sstevel@tonic-gate *iptr++ = cp->cp_ecx; 10990Sstevel@tonic-gate *iptr++ = cp->cp_edx; 11000Sstevel@tonic-gate break; 11010Sstevel@tonic-gate case 5: 11020Sstevel@tonic-gate switch (cpi->cpi_vendor) { 11030Sstevel@tonic-gate case X86_VENDOR_AMD: 11040Sstevel@tonic-gate /* 11050Sstevel@tonic-gate * The Athlon and Duron were the first 11060Sstevel@tonic-gate * parts to report the sizes of the 11070Sstevel@tonic-gate * TLB for large pages. Before then, 11080Sstevel@tonic-gate * we don't trust the data. 11090Sstevel@tonic-gate */ 11100Sstevel@tonic-gate if (cpi->cpi_family < 6 || 11110Sstevel@tonic-gate (cpi->cpi_family == 6 && 11120Sstevel@tonic-gate cpi->cpi_model < 1)) 11130Sstevel@tonic-gate cp->cp_eax = 0; 11140Sstevel@tonic-gate break; 11150Sstevel@tonic-gate default: 11160Sstevel@tonic-gate break; 11170Sstevel@tonic-gate } 11180Sstevel@tonic-gate break; 11190Sstevel@tonic-gate case 6: 11200Sstevel@tonic-gate switch (cpi->cpi_vendor) { 11210Sstevel@tonic-gate case X86_VENDOR_AMD: 11220Sstevel@tonic-gate /* 11230Sstevel@tonic-gate * The Athlon and Duron were the first 11240Sstevel@tonic-gate * AMD parts with L2 TLB's. 11250Sstevel@tonic-gate * Before then, don't trust the data. 11260Sstevel@tonic-gate */ 11270Sstevel@tonic-gate if (cpi->cpi_family < 6 || 11280Sstevel@tonic-gate cpi->cpi_family == 6 && 11290Sstevel@tonic-gate cpi->cpi_model < 1) 11300Sstevel@tonic-gate cp->cp_eax = cp->cp_ebx = 0; 11310Sstevel@tonic-gate /* 11320Sstevel@tonic-gate * AMD Duron rev A0 reports L2 11330Sstevel@tonic-gate * cache size incorrectly as 1K 11340Sstevel@tonic-gate * when it is really 64K 11350Sstevel@tonic-gate */ 11360Sstevel@tonic-gate if (cpi->cpi_family == 6 && 11370Sstevel@tonic-gate cpi->cpi_model == 3 && 11380Sstevel@tonic-gate cpi->cpi_step == 0) { 11390Sstevel@tonic-gate cp->cp_ecx &= 0xffff; 11400Sstevel@tonic-gate cp->cp_ecx |= 0x400000; 11410Sstevel@tonic-gate } 11420Sstevel@tonic-gate break; 11430Sstevel@tonic-gate case X86_VENDOR_Cyrix: /* VIA C3 */ 11440Sstevel@tonic-gate /* 11450Sstevel@tonic-gate * VIA C3 processors are a bit messed 11460Sstevel@tonic-gate * up w.r.t. encoding cache sizes in %ecx 11470Sstevel@tonic-gate */ 11480Sstevel@tonic-gate if (cpi->cpi_family != 6) 11490Sstevel@tonic-gate break; 11500Sstevel@tonic-gate /* 11510Sstevel@tonic-gate * model 7 and 8 were incorrectly encoded 11520Sstevel@tonic-gate * 11530Sstevel@tonic-gate * xxx is model 8 really broken? 11540Sstevel@tonic-gate */ 11550Sstevel@tonic-gate if (cpi->cpi_model == 7 || 11560Sstevel@tonic-gate cpi->cpi_model == 8) 11570Sstevel@tonic-gate cp->cp_ecx = 11580Sstevel@tonic-gate BITX(cp->cp_ecx, 31, 24) << 16 | 11590Sstevel@tonic-gate BITX(cp->cp_ecx, 23, 16) << 12 | 11600Sstevel@tonic-gate BITX(cp->cp_ecx, 15, 8) << 8 | 11610Sstevel@tonic-gate BITX(cp->cp_ecx, 7, 0); 11620Sstevel@tonic-gate /* 11630Sstevel@tonic-gate * model 9 stepping 1 has wrong associativity 11640Sstevel@tonic-gate */ 11650Sstevel@tonic-gate if (cpi->cpi_model == 9 && cpi->cpi_step == 1) 11660Sstevel@tonic-gate cp->cp_ecx |= 8 << 12; 11670Sstevel@tonic-gate break; 11680Sstevel@tonic-gate case X86_VENDOR_Intel: 11690Sstevel@tonic-gate /* 11700Sstevel@tonic-gate * Extended L2 Cache features function. 11710Sstevel@tonic-gate * First appeared on Prescott. 11720Sstevel@tonic-gate */ 11730Sstevel@tonic-gate default: 11740Sstevel@tonic-gate break; 11750Sstevel@tonic-gate } 11760Sstevel@tonic-gate break; 11770Sstevel@tonic-gate default: 11780Sstevel@tonic-gate break; 11790Sstevel@tonic-gate } 11800Sstevel@tonic-gate } 11810Sstevel@tonic-gate 11820Sstevel@tonic-gate pass2_done: 11830Sstevel@tonic-gate cpi->cpi_pass = 2; 11840Sstevel@tonic-gate } 11850Sstevel@tonic-gate 11860Sstevel@tonic-gate static const char * 11870Sstevel@tonic-gate intel_cpubrand(const struct cpuid_info *cpi) 11880Sstevel@tonic-gate { 11890Sstevel@tonic-gate int i; 11900Sstevel@tonic-gate 11910Sstevel@tonic-gate if ((x86_feature & X86_CPUID) == 0 || 11920Sstevel@tonic-gate cpi->cpi_maxeax < 1 || cpi->cpi_family < 5) 11930Sstevel@tonic-gate return ("i486"); 11940Sstevel@tonic-gate 11950Sstevel@tonic-gate switch (cpi->cpi_family) { 11960Sstevel@tonic-gate case 5: 11970Sstevel@tonic-gate return ("Intel Pentium(r)"); 11980Sstevel@tonic-gate case 6: 11990Sstevel@tonic-gate switch (cpi->cpi_model) { 12000Sstevel@tonic-gate uint_t celeron, xeon; 12011228Sandrei const struct cpuid_regs *cp; 12020Sstevel@tonic-gate case 0: 12030Sstevel@tonic-gate case 1: 12040Sstevel@tonic-gate case 2: 12050Sstevel@tonic-gate return ("Intel Pentium(r) Pro"); 12060Sstevel@tonic-gate case 3: 12070Sstevel@tonic-gate case 4: 12080Sstevel@tonic-gate return ("Intel Pentium(r) II"); 12090Sstevel@tonic-gate case 6: 12100Sstevel@tonic-gate return ("Intel Celeron(r)"); 12110Sstevel@tonic-gate case 5: 12120Sstevel@tonic-gate case 7: 12130Sstevel@tonic-gate celeron = xeon = 0; 12140Sstevel@tonic-gate cp = &cpi->cpi_std[2]; /* cache info */ 12150Sstevel@tonic-gate 12160Sstevel@tonic-gate for (i = 1; i < 3; i++) { 12170Sstevel@tonic-gate uint_t tmp; 12180Sstevel@tonic-gate 12190Sstevel@tonic-gate tmp = (cp->cp_eax >> (8 * i)) & 0xff; 12200Sstevel@tonic-gate if (tmp == 0x40) 12210Sstevel@tonic-gate celeron++; 12220Sstevel@tonic-gate if (tmp >= 0x44 && tmp <= 0x45) 12230Sstevel@tonic-gate xeon++; 12240Sstevel@tonic-gate } 12250Sstevel@tonic-gate 12260Sstevel@tonic-gate for (i = 0; i < 2; i++) { 12270Sstevel@tonic-gate uint_t tmp; 12280Sstevel@tonic-gate 12290Sstevel@tonic-gate tmp = (cp->cp_ebx >> (8 * i)) & 0xff; 12300Sstevel@tonic-gate if (tmp == 0x40) 12310Sstevel@tonic-gate celeron++; 12320Sstevel@tonic-gate else if (tmp >= 0x44 && tmp <= 0x45) 12330Sstevel@tonic-gate xeon++; 12340Sstevel@tonic-gate } 12350Sstevel@tonic-gate 12360Sstevel@tonic-gate for (i = 0; i < 4; i++) { 12370Sstevel@tonic-gate uint_t tmp; 12380Sstevel@tonic-gate 12390Sstevel@tonic-gate tmp = (cp->cp_ecx >> (8 * i)) & 0xff; 12400Sstevel@tonic-gate if (tmp == 0x40) 12410Sstevel@tonic-gate celeron++; 12420Sstevel@tonic-gate else if (tmp >= 0x44 && tmp <= 0x45) 12430Sstevel@tonic-gate xeon++; 12440Sstevel@tonic-gate } 12450Sstevel@tonic-gate 12460Sstevel@tonic-gate for (i = 0; i < 4; i++) { 12470Sstevel@tonic-gate uint_t tmp; 12480Sstevel@tonic-gate 12490Sstevel@tonic-gate tmp = (cp->cp_edx >> (8 * i)) & 0xff; 12500Sstevel@tonic-gate if (tmp == 0x40) 12510Sstevel@tonic-gate celeron++; 12520Sstevel@tonic-gate else if (tmp >= 0x44 && tmp <= 0x45) 12530Sstevel@tonic-gate xeon++; 12540Sstevel@tonic-gate } 12550Sstevel@tonic-gate 12560Sstevel@tonic-gate if (celeron) 12570Sstevel@tonic-gate return ("Intel Celeron(r)"); 12580Sstevel@tonic-gate if (xeon) 12590Sstevel@tonic-gate return (cpi->cpi_model == 5 ? 12600Sstevel@tonic-gate "Intel Pentium(r) II Xeon(tm)" : 12610Sstevel@tonic-gate "Intel Pentium(r) III Xeon(tm)"); 12620Sstevel@tonic-gate return (cpi->cpi_model == 5 ? 12630Sstevel@tonic-gate "Intel Pentium(r) II or Pentium(r) II Xeon(tm)" : 12640Sstevel@tonic-gate "Intel Pentium(r) III or Pentium(r) III Xeon(tm)"); 12650Sstevel@tonic-gate default: 12660Sstevel@tonic-gate break; 12670Sstevel@tonic-gate } 12680Sstevel@tonic-gate default: 12690Sstevel@tonic-gate break; 12700Sstevel@tonic-gate } 12710Sstevel@tonic-gate 12721975Sdmick /* BrandID is present if the field is nonzero */ 12731975Sdmick if (cpi->cpi_brandid != 0) { 12740Sstevel@tonic-gate static const struct { 12750Sstevel@tonic-gate uint_t bt_bid; 12760Sstevel@tonic-gate const char *bt_str; 12770Sstevel@tonic-gate } brand_tbl[] = { 12780Sstevel@tonic-gate { 0x1, "Intel(r) Celeron(r)" }, 12790Sstevel@tonic-gate { 0x2, "Intel(r) Pentium(r) III" }, 12800Sstevel@tonic-gate { 0x3, "Intel(r) Pentium(r) III Xeon(tm)" }, 12810Sstevel@tonic-gate { 0x4, "Intel(r) Pentium(r) III" }, 12820Sstevel@tonic-gate { 0x6, "Mobile Intel(r) Pentium(r) III" }, 12830Sstevel@tonic-gate { 0x7, "Mobile Intel(r) Celeron(r)" }, 12840Sstevel@tonic-gate { 0x8, "Intel(r) Pentium(r) 4" }, 12850Sstevel@tonic-gate { 0x9, "Intel(r) Pentium(r) 4" }, 12860Sstevel@tonic-gate { 0xa, "Intel(r) Celeron(r)" }, 12870Sstevel@tonic-gate { 0xb, "Intel(r) Xeon(tm)" }, 12880Sstevel@tonic-gate { 0xc, "Intel(r) Xeon(tm) MP" }, 12890Sstevel@tonic-gate { 0xe, "Mobile Intel(r) Pentium(r) 4" }, 12901975Sdmick { 0xf, "Mobile Intel(r) Celeron(r)" }, 12911975Sdmick { 0x11, "Mobile Genuine Intel(r)" }, 12921975Sdmick { 0x12, "Intel(r) Celeron(r) M" }, 12931975Sdmick { 0x13, "Mobile Intel(r) Celeron(r)" }, 12941975Sdmick { 0x14, "Intel(r) Celeron(r)" }, 12951975Sdmick { 0x15, "Mobile Genuine Intel(r)" }, 12961975Sdmick { 0x16, "Intel(r) Pentium(r) M" }, 12971975Sdmick { 0x17, "Mobile Intel(r) Celeron(r)" } 12980Sstevel@tonic-gate }; 12990Sstevel@tonic-gate uint_t btblmax = sizeof (brand_tbl) / sizeof (brand_tbl[0]); 13000Sstevel@tonic-gate uint_t sgn; 13010Sstevel@tonic-gate 13020Sstevel@tonic-gate sgn = (cpi->cpi_family << 8) | 13030Sstevel@tonic-gate (cpi->cpi_model << 4) | cpi->cpi_step; 13040Sstevel@tonic-gate 13050Sstevel@tonic-gate for (i = 0; i < btblmax; i++) 13060Sstevel@tonic-gate if (brand_tbl[i].bt_bid == cpi->cpi_brandid) 13070Sstevel@tonic-gate break; 13080Sstevel@tonic-gate if (i < btblmax) { 13090Sstevel@tonic-gate if (sgn == 0x6b1 && cpi->cpi_brandid == 3) 13100Sstevel@tonic-gate return ("Intel(r) Celeron(r)"); 13110Sstevel@tonic-gate if (sgn < 0xf13 && cpi->cpi_brandid == 0xb) 13120Sstevel@tonic-gate return ("Intel(r) Xeon(tm) MP"); 13130Sstevel@tonic-gate if (sgn < 0xf13 && cpi->cpi_brandid == 0xe) 13140Sstevel@tonic-gate return ("Intel(r) Xeon(tm)"); 13150Sstevel@tonic-gate return (brand_tbl[i].bt_str); 13160Sstevel@tonic-gate } 13170Sstevel@tonic-gate } 13180Sstevel@tonic-gate 13190Sstevel@tonic-gate return (NULL); 13200Sstevel@tonic-gate } 13210Sstevel@tonic-gate 13220Sstevel@tonic-gate static const char * 13230Sstevel@tonic-gate amd_cpubrand(const struct cpuid_info *cpi) 13240Sstevel@tonic-gate { 13250Sstevel@tonic-gate if ((x86_feature & X86_CPUID) == 0 || 13260Sstevel@tonic-gate cpi->cpi_maxeax < 1 || cpi->cpi_family < 5) 13270Sstevel@tonic-gate return ("i486 compatible"); 13280Sstevel@tonic-gate 13290Sstevel@tonic-gate switch (cpi->cpi_family) { 13300Sstevel@tonic-gate case 5: 13310Sstevel@tonic-gate switch (cpi->cpi_model) { 13320Sstevel@tonic-gate case 0: 13330Sstevel@tonic-gate case 1: 13340Sstevel@tonic-gate case 2: 13350Sstevel@tonic-gate case 3: 13360Sstevel@tonic-gate case 4: 13370Sstevel@tonic-gate case 5: 13380Sstevel@tonic-gate return ("AMD-K5(r)"); 13390Sstevel@tonic-gate case 6: 13400Sstevel@tonic-gate case 7: 13410Sstevel@tonic-gate return ("AMD-K6(r)"); 13420Sstevel@tonic-gate case 8: 13430Sstevel@tonic-gate return ("AMD-K6(r)-2"); 13440Sstevel@tonic-gate case 9: 13450Sstevel@tonic-gate return ("AMD-K6(r)-III"); 13460Sstevel@tonic-gate default: 13470Sstevel@tonic-gate return ("AMD (family 5)"); 13480Sstevel@tonic-gate } 13490Sstevel@tonic-gate case 6: 13500Sstevel@tonic-gate switch (cpi->cpi_model) { 13510Sstevel@tonic-gate case 1: 13520Sstevel@tonic-gate return ("AMD-K7(tm)"); 13530Sstevel@tonic-gate case 0: 13540Sstevel@tonic-gate case 2: 13550Sstevel@tonic-gate case 4: 13560Sstevel@tonic-gate return ("AMD Athlon(tm)"); 13570Sstevel@tonic-gate case 3: 13580Sstevel@tonic-gate case 7: 13590Sstevel@tonic-gate return ("AMD Duron(tm)"); 13600Sstevel@tonic-gate case 6: 13610Sstevel@tonic-gate case 8: 13620Sstevel@tonic-gate case 10: 13630Sstevel@tonic-gate /* 13640Sstevel@tonic-gate * Use the L2 cache size to distinguish 13650Sstevel@tonic-gate */ 13660Sstevel@tonic-gate return ((cpi->cpi_extd[6].cp_ecx >> 16) >= 256 ? 13670Sstevel@tonic-gate "AMD Athlon(tm)" : "AMD Duron(tm)"); 13680Sstevel@tonic-gate default: 13690Sstevel@tonic-gate return ("AMD (family 6)"); 13700Sstevel@tonic-gate } 13710Sstevel@tonic-gate default: 13720Sstevel@tonic-gate break; 13730Sstevel@tonic-gate } 13740Sstevel@tonic-gate 13750Sstevel@tonic-gate if (cpi->cpi_family == 0xf && cpi->cpi_model == 5 && 13760Sstevel@tonic-gate cpi->cpi_brandid != 0) { 13770Sstevel@tonic-gate switch (BITX(cpi->cpi_brandid, 7, 5)) { 13780Sstevel@tonic-gate case 3: 13790Sstevel@tonic-gate return ("AMD Opteron(tm) UP 1xx"); 13800Sstevel@tonic-gate case 4: 13810Sstevel@tonic-gate return ("AMD Opteron(tm) DP 2xx"); 13820Sstevel@tonic-gate case 5: 13830Sstevel@tonic-gate return ("AMD Opteron(tm) MP 8xx"); 13840Sstevel@tonic-gate default: 13850Sstevel@tonic-gate return ("AMD Opteron(tm)"); 13860Sstevel@tonic-gate } 13870Sstevel@tonic-gate } 13880Sstevel@tonic-gate 13890Sstevel@tonic-gate return (NULL); 13900Sstevel@tonic-gate } 13910Sstevel@tonic-gate 13920Sstevel@tonic-gate static const char * 13930Sstevel@tonic-gate cyrix_cpubrand(struct cpuid_info *cpi, uint_t type) 13940Sstevel@tonic-gate { 13950Sstevel@tonic-gate if ((x86_feature & X86_CPUID) == 0 || 13960Sstevel@tonic-gate cpi->cpi_maxeax < 1 || cpi->cpi_family < 5 || 13970Sstevel@tonic-gate type == X86_TYPE_CYRIX_486) 13980Sstevel@tonic-gate return ("i486 compatible"); 13990Sstevel@tonic-gate 14000Sstevel@tonic-gate switch (type) { 14010Sstevel@tonic-gate case X86_TYPE_CYRIX_6x86: 14020Sstevel@tonic-gate return ("Cyrix 6x86"); 14030Sstevel@tonic-gate case X86_TYPE_CYRIX_6x86L: 14040Sstevel@tonic-gate return ("Cyrix 6x86L"); 14050Sstevel@tonic-gate case X86_TYPE_CYRIX_6x86MX: 14060Sstevel@tonic-gate return ("Cyrix 6x86MX"); 14070Sstevel@tonic-gate case X86_TYPE_CYRIX_GXm: 14080Sstevel@tonic-gate return ("Cyrix GXm"); 14090Sstevel@tonic-gate case X86_TYPE_CYRIX_MediaGX: 14100Sstevel@tonic-gate return ("Cyrix MediaGX"); 14110Sstevel@tonic-gate case X86_TYPE_CYRIX_MII: 14120Sstevel@tonic-gate return ("Cyrix M2"); 14130Sstevel@tonic-gate case X86_TYPE_VIA_CYRIX_III: 14140Sstevel@tonic-gate return ("VIA Cyrix M3"); 14150Sstevel@tonic-gate default: 14160Sstevel@tonic-gate /* 14170Sstevel@tonic-gate * Have another wild guess .. 14180Sstevel@tonic-gate */ 14190Sstevel@tonic-gate if (cpi->cpi_family == 4 && cpi->cpi_model == 9) 14200Sstevel@tonic-gate return ("Cyrix 5x86"); 14210Sstevel@tonic-gate else if (cpi->cpi_family == 5) { 14220Sstevel@tonic-gate switch (cpi->cpi_model) { 14230Sstevel@tonic-gate case 2: 14240Sstevel@tonic-gate return ("Cyrix 6x86"); /* Cyrix M1 */ 14250Sstevel@tonic-gate case 4: 14260Sstevel@tonic-gate return ("Cyrix MediaGX"); 14270Sstevel@tonic-gate default: 14280Sstevel@tonic-gate break; 14290Sstevel@tonic-gate } 14300Sstevel@tonic-gate } else if (cpi->cpi_family == 6) { 14310Sstevel@tonic-gate switch (cpi->cpi_model) { 14320Sstevel@tonic-gate case 0: 14330Sstevel@tonic-gate return ("Cyrix 6x86MX"); /* Cyrix M2? */ 14340Sstevel@tonic-gate case 5: 14350Sstevel@tonic-gate case 6: 14360Sstevel@tonic-gate case 7: 14370Sstevel@tonic-gate case 8: 14380Sstevel@tonic-gate case 9: 14390Sstevel@tonic-gate return ("VIA C3"); 14400Sstevel@tonic-gate default: 14410Sstevel@tonic-gate break; 14420Sstevel@tonic-gate } 14430Sstevel@tonic-gate } 14440Sstevel@tonic-gate break; 14450Sstevel@tonic-gate } 14460Sstevel@tonic-gate return (NULL); 14470Sstevel@tonic-gate } 14480Sstevel@tonic-gate 14490Sstevel@tonic-gate /* 14500Sstevel@tonic-gate * This only gets called in the case that the CPU extended 14510Sstevel@tonic-gate * feature brand string (0x80000002, 0x80000003, 0x80000004) 14520Sstevel@tonic-gate * aren't available, or contain null bytes for some reason. 14530Sstevel@tonic-gate */ 14540Sstevel@tonic-gate static void 14550Sstevel@tonic-gate fabricate_brandstr(struct cpuid_info *cpi) 14560Sstevel@tonic-gate { 14570Sstevel@tonic-gate const char *brand = NULL; 14580Sstevel@tonic-gate 14590Sstevel@tonic-gate switch (cpi->cpi_vendor) { 14600Sstevel@tonic-gate case X86_VENDOR_Intel: 14610Sstevel@tonic-gate brand = intel_cpubrand(cpi); 14620Sstevel@tonic-gate break; 14630Sstevel@tonic-gate case X86_VENDOR_AMD: 14640Sstevel@tonic-gate brand = amd_cpubrand(cpi); 14650Sstevel@tonic-gate break; 14660Sstevel@tonic-gate case X86_VENDOR_Cyrix: 14670Sstevel@tonic-gate brand = cyrix_cpubrand(cpi, x86_type); 14680Sstevel@tonic-gate break; 14690Sstevel@tonic-gate case X86_VENDOR_NexGen: 14700Sstevel@tonic-gate if (cpi->cpi_family == 5 && cpi->cpi_model == 0) 14710Sstevel@tonic-gate brand = "NexGen Nx586"; 14720Sstevel@tonic-gate break; 14730Sstevel@tonic-gate case X86_VENDOR_Centaur: 14740Sstevel@tonic-gate if (cpi->cpi_family == 5) 14750Sstevel@tonic-gate switch (cpi->cpi_model) { 14760Sstevel@tonic-gate case 4: 14770Sstevel@tonic-gate brand = "Centaur C6"; 14780Sstevel@tonic-gate break; 14790Sstevel@tonic-gate case 8: 14800Sstevel@tonic-gate brand = "Centaur C2"; 14810Sstevel@tonic-gate break; 14820Sstevel@tonic-gate case 9: 14830Sstevel@tonic-gate brand = "Centaur C3"; 14840Sstevel@tonic-gate break; 14850Sstevel@tonic-gate default: 14860Sstevel@tonic-gate break; 14870Sstevel@tonic-gate } 14880Sstevel@tonic-gate break; 14890Sstevel@tonic-gate case X86_VENDOR_Rise: 14900Sstevel@tonic-gate if (cpi->cpi_family == 5 && 14910Sstevel@tonic-gate (cpi->cpi_model == 0 || cpi->cpi_model == 2)) 14920Sstevel@tonic-gate brand = "Rise mP6"; 14930Sstevel@tonic-gate break; 14940Sstevel@tonic-gate case X86_VENDOR_SiS: 14950Sstevel@tonic-gate if (cpi->cpi_family == 5 && cpi->cpi_model == 0) 14960Sstevel@tonic-gate brand = "SiS 55x"; 14970Sstevel@tonic-gate break; 14980Sstevel@tonic-gate case X86_VENDOR_TM: 14990Sstevel@tonic-gate if (cpi->cpi_family == 5 && cpi->cpi_model == 4) 15000Sstevel@tonic-gate brand = "Transmeta Crusoe TM3x00 or TM5x00"; 15010Sstevel@tonic-gate break; 15020Sstevel@tonic-gate case X86_VENDOR_NSC: 15030Sstevel@tonic-gate case X86_VENDOR_UMC: 15040Sstevel@tonic-gate default: 15050Sstevel@tonic-gate break; 15060Sstevel@tonic-gate } 15070Sstevel@tonic-gate if (brand) { 15080Sstevel@tonic-gate (void) strcpy((char *)cpi->cpi_brandstr, brand); 15090Sstevel@tonic-gate return; 15100Sstevel@tonic-gate } 15110Sstevel@tonic-gate 15120Sstevel@tonic-gate /* 15130Sstevel@tonic-gate * If all else fails ... 15140Sstevel@tonic-gate */ 15150Sstevel@tonic-gate (void) snprintf(cpi->cpi_brandstr, sizeof (cpi->cpi_brandstr), 15160Sstevel@tonic-gate "%s %d.%d.%d", cpi->cpi_vendorstr, cpi->cpi_family, 15170Sstevel@tonic-gate cpi->cpi_model, cpi->cpi_step); 15180Sstevel@tonic-gate } 15190Sstevel@tonic-gate 15200Sstevel@tonic-gate /* 15210Sstevel@tonic-gate * This routine is called just after kernel memory allocation 15220Sstevel@tonic-gate * becomes available on cpu0, and as part of mp_startup() on 15230Sstevel@tonic-gate * the other cpus. 15240Sstevel@tonic-gate * 15250Sstevel@tonic-gate * Fixup the brand string. 15260Sstevel@tonic-gate */ 15270Sstevel@tonic-gate /*ARGSUSED*/ 15280Sstevel@tonic-gate void 15290Sstevel@tonic-gate cpuid_pass3(cpu_t *cpu) 15300Sstevel@tonic-gate { 15310Sstevel@tonic-gate struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 15320Sstevel@tonic-gate 15330Sstevel@tonic-gate ASSERT(cpi->cpi_pass == 2); 15340Sstevel@tonic-gate 15350Sstevel@tonic-gate if ((cpi->cpi_xmaxeax & 0x80000000) == 0) { 15360Sstevel@tonic-gate fabricate_brandstr(cpi); 15370Sstevel@tonic-gate goto pass3_done; 15380Sstevel@tonic-gate } 15390Sstevel@tonic-gate 15400Sstevel@tonic-gate /* 15410Sstevel@tonic-gate * If we successfully extracted a brand string from the cpuid 15420Sstevel@tonic-gate * instruction, clean it up by removing leading spaces and 15430Sstevel@tonic-gate * similar junk. 15440Sstevel@tonic-gate */ 15450Sstevel@tonic-gate if (cpi->cpi_brandstr[0]) { 15460Sstevel@tonic-gate size_t maxlen = sizeof (cpi->cpi_brandstr); 15470Sstevel@tonic-gate char *src, *dst; 15480Sstevel@tonic-gate 15490Sstevel@tonic-gate dst = src = (char *)cpi->cpi_brandstr; 15500Sstevel@tonic-gate src[maxlen - 1] = '\0'; 15510Sstevel@tonic-gate /* 15520Sstevel@tonic-gate * strip leading spaces 15530Sstevel@tonic-gate */ 15540Sstevel@tonic-gate while (*src == ' ') 15550Sstevel@tonic-gate src++; 15560Sstevel@tonic-gate /* 15570Sstevel@tonic-gate * Remove any 'Genuine' or "Authentic" prefixes 15580Sstevel@tonic-gate */ 15590Sstevel@tonic-gate if (strncmp(src, "Genuine ", 8) == 0) 15600Sstevel@tonic-gate src += 8; 15610Sstevel@tonic-gate if (strncmp(src, "Authentic ", 10) == 0) 15620Sstevel@tonic-gate src += 10; 15630Sstevel@tonic-gate 15640Sstevel@tonic-gate /* 15650Sstevel@tonic-gate * Now do an in-place copy. 15660Sstevel@tonic-gate * Map (R) to (r) and (TM) to (tm). 15670Sstevel@tonic-gate * The era of teletypes is long gone, and there's 15680Sstevel@tonic-gate * -really- no need to shout. 15690Sstevel@tonic-gate */ 15700Sstevel@tonic-gate while (*src != '\0') { 15710Sstevel@tonic-gate if (src[0] == '(') { 15720Sstevel@tonic-gate if (strncmp(src + 1, "R)", 2) == 0) { 15730Sstevel@tonic-gate (void) strncpy(dst, "(r)", 3); 15740Sstevel@tonic-gate src += 3; 15750Sstevel@tonic-gate dst += 3; 15760Sstevel@tonic-gate continue; 15770Sstevel@tonic-gate } 15780Sstevel@tonic-gate if (strncmp(src + 1, "TM)", 3) == 0) { 15790Sstevel@tonic-gate (void) strncpy(dst, "(tm)", 4); 15800Sstevel@tonic-gate src += 4; 15810Sstevel@tonic-gate dst += 4; 15820Sstevel@tonic-gate continue; 15830Sstevel@tonic-gate } 15840Sstevel@tonic-gate } 15850Sstevel@tonic-gate *dst++ = *src++; 15860Sstevel@tonic-gate } 15870Sstevel@tonic-gate *dst = '\0'; 15880Sstevel@tonic-gate 15890Sstevel@tonic-gate /* 15900Sstevel@tonic-gate * Finally, remove any trailing spaces 15910Sstevel@tonic-gate */ 15920Sstevel@tonic-gate while (--dst > cpi->cpi_brandstr) 15930Sstevel@tonic-gate if (*dst == ' ') 15940Sstevel@tonic-gate *dst = '\0'; 15950Sstevel@tonic-gate else 15960Sstevel@tonic-gate break; 15970Sstevel@tonic-gate } else 15980Sstevel@tonic-gate fabricate_brandstr(cpi); 15990Sstevel@tonic-gate 16000Sstevel@tonic-gate pass3_done: 16010Sstevel@tonic-gate cpi->cpi_pass = 3; 16020Sstevel@tonic-gate } 16030Sstevel@tonic-gate 16040Sstevel@tonic-gate /* 16050Sstevel@tonic-gate * This routine is called out of bind_hwcap() much later in the life 16060Sstevel@tonic-gate * of the kernel (post_startup()). The job of this routine is to resolve 16070Sstevel@tonic-gate * the hardware feature support and kernel support for those features into 16080Sstevel@tonic-gate * what we're actually going to tell applications via the aux vector. 16090Sstevel@tonic-gate */ 16100Sstevel@tonic-gate uint_t 16110Sstevel@tonic-gate cpuid_pass4(cpu_t *cpu) 16120Sstevel@tonic-gate { 16130Sstevel@tonic-gate struct cpuid_info *cpi; 16140Sstevel@tonic-gate uint_t hwcap_flags = 0; 16150Sstevel@tonic-gate 16160Sstevel@tonic-gate if (cpu == NULL) 16170Sstevel@tonic-gate cpu = CPU; 16180Sstevel@tonic-gate cpi = cpu->cpu_m.mcpu_cpi; 16190Sstevel@tonic-gate 16200Sstevel@tonic-gate ASSERT(cpi->cpi_pass == 3); 16210Sstevel@tonic-gate 16220Sstevel@tonic-gate if (cpi->cpi_maxeax >= 1) { 16230Sstevel@tonic-gate uint32_t *edx = &cpi->cpi_support[STD_EDX_FEATURES]; 16240Sstevel@tonic-gate uint32_t *ecx = &cpi->cpi_support[STD_ECX_FEATURES]; 16250Sstevel@tonic-gate 16260Sstevel@tonic-gate *edx = CPI_FEATURES_EDX(cpi); 16270Sstevel@tonic-gate *ecx = CPI_FEATURES_ECX(cpi); 16280Sstevel@tonic-gate 16290Sstevel@tonic-gate /* 16300Sstevel@tonic-gate * [these require explicit kernel support] 16310Sstevel@tonic-gate */ 16320Sstevel@tonic-gate if ((x86_feature & X86_SEP) == 0) 16330Sstevel@tonic-gate *edx &= ~CPUID_INTC_EDX_SEP; 16340Sstevel@tonic-gate 16350Sstevel@tonic-gate if ((x86_feature & X86_SSE) == 0) 16360Sstevel@tonic-gate *edx &= ~(CPUID_INTC_EDX_FXSR|CPUID_INTC_EDX_SSE); 16370Sstevel@tonic-gate if ((x86_feature & X86_SSE2) == 0) 16380Sstevel@tonic-gate *edx &= ~CPUID_INTC_EDX_SSE2; 16390Sstevel@tonic-gate 16400Sstevel@tonic-gate if ((x86_feature & X86_HTT) == 0) 16410Sstevel@tonic-gate *edx &= ~CPUID_INTC_EDX_HTT; 16420Sstevel@tonic-gate 16430Sstevel@tonic-gate if ((x86_feature & X86_SSE3) == 0) 16440Sstevel@tonic-gate *ecx &= ~CPUID_INTC_ECX_SSE3; 16450Sstevel@tonic-gate 16460Sstevel@tonic-gate /* 16470Sstevel@tonic-gate * [no explicit support required beyond x87 fp context] 16480Sstevel@tonic-gate */ 16490Sstevel@tonic-gate if (!fpu_exists) 16500Sstevel@tonic-gate *edx &= ~(CPUID_INTC_EDX_FPU | CPUID_INTC_EDX_MMX); 16510Sstevel@tonic-gate 16520Sstevel@tonic-gate /* 16530Sstevel@tonic-gate * Now map the supported feature vector to things that we 16540Sstevel@tonic-gate * think userland will care about. 16550Sstevel@tonic-gate */ 16560Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_SEP) 16570Sstevel@tonic-gate hwcap_flags |= AV_386_SEP; 16580Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_SSE) 16590Sstevel@tonic-gate hwcap_flags |= AV_386_FXSR | AV_386_SSE; 16600Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_SSE2) 16610Sstevel@tonic-gate hwcap_flags |= AV_386_SSE2; 16620Sstevel@tonic-gate if (*ecx & CPUID_INTC_ECX_SSE3) 16630Sstevel@tonic-gate hwcap_flags |= AV_386_SSE3; 16640Sstevel@tonic-gate 16650Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_FPU) 16660Sstevel@tonic-gate hwcap_flags |= AV_386_FPU; 16670Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_MMX) 16680Sstevel@tonic-gate hwcap_flags |= AV_386_MMX; 16690Sstevel@tonic-gate 16700Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_TSC) 16710Sstevel@tonic-gate hwcap_flags |= AV_386_TSC; 16720Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_CX8) 16730Sstevel@tonic-gate hwcap_flags |= AV_386_CX8; 16740Sstevel@tonic-gate if (*edx & CPUID_INTC_EDX_CMOV) 16750Sstevel@tonic-gate hwcap_flags |= AV_386_CMOV; 16760Sstevel@tonic-gate if (*ecx & CPUID_INTC_ECX_MON) 16770Sstevel@tonic-gate hwcap_flags |= AV_386_MON; 16780Sstevel@tonic-gate if (*ecx & CPUID_INTC_ECX_CX16) 16790Sstevel@tonic-gate hwcap_flags |= AV_386_CX16; 16800Sstevel@tonic-gate } 16810Sstevel@tonic-gate 16821228Sandrei if (x86_feature & X86_HTT) 16830Sstevel@tonic-gate hwcap_flags |= AV_386_PAUSE; 16840Sstevel@tonic-gate 16850Sstevel@tonic-gate if (cpi->cpi_xmaxeax < 0x80000001) 16860Sstevel@tonic-gate goto pass4_done; 16870Sstevel@tonic-gate 16880Sstevel@tonic-gate switch (cpi->cpi_vendor) { 16891228Sandrei struct cpuid_regs cp; 16903446Smrj uint32_t *edx, *ecx; 16910Sstevel@tonic-gate 16923446Smrj case X86_VENDOR_Intel: 16933446Smrj /* 16943446Smrj * Seems like Intel duplicated what we necessary 16953446Smrj * here to make the initial crop of 64-bit OS's work. 16963446Smrj * Hopefully, those are the only "extended" bits 16973446Smrj * they'll add. 16983446Smrj */ 16993446Smrj /*FALLTHROUGH*/ 17003446Smrj 17010Sstevel@tonic-gate case X86_VENDOR_AMD: 17020Sstevel@tonic-gate edx = &cpi->cpi_support[AMD_EDX_FEATURES]; 17033446Smrj ecx = &cpi->cpi_support[AMD_ECX_FEATURES]; 17040Sstevel@tonic-gate 17050Sstevel@tonic-gate *edx = CPI_FEATURES_XTD_EDX(cpi); 17063446Smrj *ecx = CPI_FEATURES_XTD_ECX(cpi); 17073446Smrj 17083446Smrj /* 17093446Smrj * [these features require explicit kernel support] 17103446Smrj */ 17113446Smrj switch (cpi->cpi_vendor) { 17123446Smrj case X86_VENDOR_Intel: 17133446Smrj break; 17143446Smrj 17153446Smrj case X86_VENDOR_AMD: 17163446Smrj if ((x86_feature & X86_TSCP) == 0) 17173446Smrj *edx &= ~CPUID_AMD_EDX_TSCP; 17183446Smrj break; 17193446Smrj 17203446Smrj default: 17213446Smrj break; 17223446Smrj } 17230Sstevel@tonic-gate 17240Sstevel@tonic-gate /* 17250Sstevel@tonic-gate * [no explicit support required beyond 17260Sstevel@tonic-gate * x87 fp context and exception handlers] 17270Sstevel@tonic-gate */ 17280Sstevel@tonic-gate if (!fpu_exists) 17290Sstevel@tonic-gate *edx &= ~(CPUID_AMD_EDX_MMXamd | 17300Sstevel@tonic-gate CPUID_AMD_EDX_3DNow | CPUID_AMD_EDX_3DNowx); 17310Sstevel@tonic-gate 17320Sstevel@tonic-gate if ((x86_feature & X86_NX) == 0) 17330Sstevel@tonic-gate *edx &= ~CPUID_AMD_EDX_NX; 17343446Smrj #if !defined(__amd64) 17350Sstevel@tonic-gate *edx &= ~CPUID_AMD_EDX_LM; 17360Sstevel@tonic-gate #endif 17370Sstevel@tonic-gate /* 17380Sstevel@tonic-gate * Now map the supported feature vector to 17390Sstevel@tonic-gate * things that we think userland will care about. 17400Sstevel@tonic-gate */ 17413446Smrj #if defined(__amd64) 17420Sstevel@tonic-gate if (*edx & CPUID_AMD_EDX_SYSC) 17430Sstevel@tonic-gate hwcap_flags |= AV_386_AMD_SYSC; 17443446Smrj #endif 17450Sstevel@tonic-gate if (*edx & CPUID_AMD_EDX_MMXamd) 17460Sstevel@tonic-gate hwcap_flags |= AV_386_AMD_MMX; 17470Sstevel@tonic-gate if (*edx & CPUID_AMD_EDX_3DNow) 17480Sstevel@tonic-gate hwcap_flags |= AV_386_AMD_3DNow; 17490Sstevel@tonic-gate if (*edx & CPUID_AMD_EDX_3DNowx) 17500Sstevel@tonic-gate hwcap_flags |= AV_386_AMD_3DNowx; 17513446Smrj 17523446Smrj switch (cpi->cpi_vendor) { 17533446Smrj case X86_VENDOR_AMD: 17543446Smrj if (*edx & CPUID_AMD_EDX_TSCP) 17553446Smrj hwcap_flags |= AV_386_TSCP; 17563446Smrj if (*ecx & CPUID_AMD_ECX_AHF64) 17573446Smrj hwcap_flags |= AV_386_AHF; 17583446Smrj break; 17593446Smrj 17603446Smrj case X86_VENDOR_Intel: 17613446Smrj /* 17623446Smrj * Aarrgh. 17633446Smrj * Intel uses a different bit in the same word. 17643446Smrj */ 17653446Smrj if (*ecx & CPUID_INTC_ECX_AHF64) 17663446Smrj hwcap_flags |= AV_386_AHF; 17673446Smrj break; 17683446Smrj 17693446Smrj default: 17703446Smrj break; 17713446Smrj } 17720Sstevel@tonic-gate break; 17730Sstevel@tonic-gate 17740Sstevel@tonic-gate case X86_VENDOR_TM: 17751228Sandrei cp.cp_eax = 0x80860001; 17761228Sandrei (void) __cpuid_insn(&cp); 17771228Sandrei cpi->cpi_support[TM_EDX_FEATURES] = cp.cp_edx; 17780Sstevel@tonic-gate break; 17790Sstevel@tonic-gate 17800Sstevel@tonic-gate default: 17810Sstevel@tonic-gate break; 17820Sstevel@tonic-gate } 17830Sstevel@tonic-gate 17840Sstevel@tonic-gate pass4_done: 17850Sstevel@tonic-gate cpi->cpi_pass = 4; 17860Sstevel@tonic-gate return (hwcap_flags); 17870Sstevel@tonic-gate } 17880Sstevel@tonic-gate 17890Sstevel@tonic-gate 17900Sstevel@tonic-gate /* 17910Sstevel@tonic-gate * Simulate the cpuid instruction using the data we previously 17920Sstevel@tonic-gate * captured about this CPU. We try our best to return the truth 17930Sstevel@tonic-gate * about the hardware, independently of kernel support. 17940Sstevel@tonic-gate */ 17950Sstevel@tonic-gate uint32_t 17961228Sandrei cpuid_insn(cpu_t *cpu, struct cpuid_regs *cp) 17970Sstevel@tonic-gate { 17980Sstevel@tonic-gate struct cpuid_info *cpi; 17991228Sandrei struct cpuid_regs *xcp; 18000Sstevel@tonic-gate 18010Sstevel@tonic-gate if (cpu == NULL) 18020Sstevel@tonic-gate cpu = CPU; 18030Sstevel@tonic-gate cpi = cpu->cpu_m.mcpu_cpi; 18040Sstevel@tonic-gate 18050Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 3)); 18060Sstevel@tonic-gate 18070Sstevel@tonic-gate /* 18080Sstevel@tonic-gate * CPUID data is cached in two separate places: cpi_std for standard 18090Sstevel@tonic-gate * CPUID functions, and cpi_extd for extended CPUID functions. 18100Sstevel@tonic-gate */ 18111228Sandrei if (cp->cp_eax <= cpi->cpi_maxeax && cp->cp_eax < NMAX_CPI_STD) 18121228Sandrei xcp = &cpi->cpi_std[cp->cp_eax]; 18131228Sandrei else if (cp->cp_eax >= 0x80000000 && cp->cp_eax <= cpi->cpi_xmaxeax && 18141228Sandrei cp->cp_eax < 0x80000000 + NMAX_CPI_EXTD) 18151228Sandrei xcp = &cpi->cpi_extd[cp->cp_eax - 0x80000000]; 18160Sstevel@tonic-gate else 18170Sstevel@tonic-gate /* 18180Sstevel@tonic-gate * The caller is asking for data from an input parameter which 18190Sstevel@tonic-gate * the kernel has not cached. In this case we go fetch from 18200Sstevel@tonic-gate * the hardware and return the data directly to the user. 18210Sstevel@tonic-gate */ 18221228Sandrei return (__cpuid_insn(cp)); 18231228Sandrei 18241228Sandrei cp->cp_eax = xcp->cp_eax; 18251228Sandrei cp->cp_ebx = xcp->cp_ebx; 18261228Sandrei cp->cp_ecx = xcp->cp_ecx; 18271228Sandrei cp->cp_edx = xcp->cp_edx; 18280Sstevel@tonic-gate return (cp->cp_eax); 18290Sstevel@tonic-gate } 18300Sstevel@tonic-gate 18310Sstevel@tonic-gate int 18320Sstevel@tonic-gate cpuid_checkpass(cpu_t *cpu, int pass) 18330Sstevel@tonic-gate { 18340Sstevel@tonic-gate return (cpu != NULL && cpu->cpu_m.mcpu_cpi != NULL && 18350Sstevel@tonic-gate cpu->cpu_m.mcpu_cpi->cpi_pass >= pass); 18360Sstevel@tonic-gate } 18370Sstevel@tonic-gate 18380Sstevel@tonic-gate int 18390Sstevel@tonic-gate cpuid_getbrandstr(cpu_t *cpu, char *s, size_t n) 18400Sstevel@tonic-gate { 18410Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 3)); 18420Sstevel@tonic-gate 18430Sstevel@tonic-gate return (snprintf(s, n, "%s", cpu->cpu_m.mcpu_cpi->cpi_brandstr)); 18440Sstevel@tonic-gate } 18450Sstevel@tonic-gate 18460Sstevel@tonic-gate int 18471228Sandrei cpuid_is_cmt(cpu_t *cpu) 18480Sstevel@tonic-gate { 18490Sstevel@tonic-gate if (cpu == NULL) 18500Sstevel@tonic-gate cpu = CPU; 18510Sstevel@tonic-gate 18520Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 18530Sstevel@tonic-gate 18540Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_chipid >= 0); 18550Sstevel@tonic-gate } 18560Sstevel@tonic-gate 18570Sstevel@tonic-gate /* 18580Sstevel@tonic-gate * AMD and Intel both implement the 64-bit variant of the syscall 18590Sstevel@tonic-gate * instruction (syscallq), so if there's -any- support for syscall, 18600Sstevel@tonic-gate * cpuid currently says "yes, we support this". 18610Sstevel@tonic-gate * 18620Sstevel@tonic-gate * However, Intel decided to -not- implement the 32-bit variant of the 18630Sstevel@tonic-gate * syscall instruction, so we provide a predicate to allow our caller 18640Sstevel@tonic-gate * to test that subtlety here. 18650Sstevel@tonic-gate */ 18660Sstevel@tonic-gate /*ARGSUSED*/ 18670Sstevel@tonic-gate int 18680Sstevel@tonic-gate cpuid_syscall32_insn(cpu_t *cpu) 18690Sstevel@tonic-gate { 18700Sstevel@tonic-gate ASSERT(cpuid_checkpass((cpu == NULL ? CPU : cpu), 1)); 18710Sstevel@tonic-gate 18723446Smrj if (cpu == NULL) 18733446Smrj cpu = CPU; 18743446Smrj 18753446Smrj /*CSTYLED*/ 18763446Smrj { 18773446Smrj struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 18783446Smrj 18793446Smrj if (cpi->cpi_vendor == X86_VENDOR_AMD && 18803446Smrj cpi->cpi_xmaxeax >= 0x80000001 && 18813446Smrj (CPI_FEATURES_XTD_EDX(cpi) & CPUID_AMD_EDX_SYSC)) 18823446Smrj return (1); 18833446Smrj } 18840Sstevel@tonic-gate return (0); 18850Sstevel@tonic-gate } 18860Sstevel@tonic-gate 18870Sstevel@tonic-gate int 18880Sstevel@tonic-gate cpuid_getidstr(cpu_t *cpu, char *s, size_t n) 18890Sstevel@tonic-gate { 18900Sstevel@tonic-gate struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 18910Sstevel@tonic-gate 18920Sstevel@tonic-gate static const char fmt[] = 1893*3779Sdmick "x86 (%s %X family %d model %d step %d clock %d MHz)"; 18940Sstevel@tonic-gate static const char fmt_ht[] = 1895*3779Sdmick "x86 (chipid 0x%x %s %X family %d model %d step %d clock %d MHz)"; 18960Sstevel@tonic-gate 18970Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 18980Sstevel@tonic-gate 18991228Sandrei if (cpuid_is_cmt(cpu)) 19000Sstevel@tonic-gate return (snprintf(s, n, fmt_ht, cpi->cpi_chipid, 1901*3779Sdmick cpi->cpi_vendorstr, cpi->cpi_std[1].cp_eax, 1902*3779Sdmick cpi->cpi_family, cpi->cpi_model, 19030Sstevel@tonic-gate cpi->cpi_step, cpu->cpu_type_info.pi_clock)); 19040Sstevel@tonic-gate return (snprintf(s, n, fmt, 1905*3779Sdmick cpi->cpi_vendorstr, cpi->cpi_std[1].cp_eax, 1906*3779Sdmick cpi->cpi_family, cpi->cpi_model, 19070Sstevel@tonic-gate cpi->cpi_step, cpu->cpu_type_info.pi_clock)); 19080Sstevel@tonic-gate } 19090Sstevel@tonic-gate 19100Sstevel@tonic-gate const char * 19110Sstevel@tonic-gate cpuid_getvendorstr(cpu_t *cpu) 19120Sstevel@tonic-gate { 19130Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 19140Sstevel@tonic-gate return ((const char *)cpu->cpu_m.mcpu_cpi->cpi_vendorstr); 19150Sstevel@tonic-gate } 19160Sstevel@tonic-gate 19170Sstevel@tonic-gate uint_t 19180Sstevel@tonic-gate cpuid_getvendor(cpu_t *cpu) 19190Sstevel@tonic-gate { 19200Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 19210Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_vendor); 19220Sstevel@tonic-gate } 19230Sstevel@tonic-gate 19240Sstevel@tonic-gate uint_t 19250Sstevel@tonic-gate cpuid_getfamily(cpu_t *cpu) 19260Sstevel@tonic-gate { 19270Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 19280Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_family); 19290Sstevel@tonic-gate } 19300Sstevel@tonic-gate 19310Sstevel@tonic-gate uint_t 19320Sstevel@tonic-gate cpuid_getmodel(cpu_t *cpu) 19330Sstevel@tonic-gate { 19340Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 19350Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_model); 19360Sstevel@tonic-gate } 19370Sstevel@tonic-gate 19380Sstevel@tonic-gate uint_t 19390Sstevel@tonic-gate cpuid_get_ncpu_per_chip(cpu_t *cpu) 19400Sstevel@tonic-gate { 19410Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 19420Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_ncpu_per_chip); 19430Sstevel@tonic-gate } 19440Sstevel@tonic-gate 19450Sstevel@tonic-gate uint_t 19461228Sandrei cpuid_get_ncore_per_chip(cpu_t *cpu) 19471228Sandrei { 19481228Sandrei ASSERT(cpuid_checkpass(cpu, 1)); 19491228Sandrei return (cpu->cpu_m.mcpu_cpi->cpi_ncore_per_chip); 19501228Sandrei } 19511228Sandrei 19521228Sandrei uint_t 19530Sstevel@tonic-gate cpuid_getstep(cpu_t *cpu) 19540Sstevel@tonic-gate { 19550Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 19560Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_step); 19570Sstevel@tonic-gate } 19580Sstevel@tonic-gate 19592869Sgavinm uint32_t 19602869Sgavinm cpuid_getchiprev(struct cpu *cpu) 19612869Sgavinm { 19622869Sgavinm ASSERT(cpuid_checkpass(cpu, 1)); 19632869Sgavinm return (cpu->cpu_m.mcpu_cpi->cpi_chiprev); 19642869Sgavinm } 19652869Sgavinm 19662869Sgavinm const char * 19672869Sgavinm cpuid_getchiprevstr(struct cpu *cpu) 19682869Sgavinm { 19692869Sgavinm ASSERT(cpuid_checkpass(cpu, 1)); 19702869Sgavinm return (cpu->cpu_m.mcpu_cpi->cpi_chiprevstr); 19712869Sgavinm } 19722869Sgavinm 19732869Sgavinm uint32_t 19742869Sgavinm cpuid_getsockettype(struct cpu *cpu) 19752869Sgavinm { 19762869Sgavinm ASSERT(cpuid_checkpass(cpu, 1)); 19772869Sgavinm return (cpu->cpu_m.mcpu_cpi->cpi_socket); 19782869Sgavinm } 19792869Sgavinm 19803434Sesaxe int 19813434Sesaxe cpuid_get_chipid(cpu_t *cpu) 19820Sstevel@tonic-gate { 19830Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 19840Sstevel@tonic-gate 19851228Sandrei if (cpuid_is_cmt(cpu)) 19860Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_chipid); 19870Sstevel@tonic-gate return (cpu->cpu_id); 19880Sstevel@tonic-gate } 19890Sstevel@tonic-gate 19901228Sandrei id_t 19913434Sesaxe cpuid_get_coreid(cpu_t *cpu) 19921228Sandrei { 19931228Sandrei ASSERT(cpuid_checkpass(cpu, 1)); 19941228Sandrei return (cpu->cpu_m.mcpu_cpi->cpi_coreid); 19951228Sandrei } 19961228Sandrei 19970Sstevel@tonic-gate int 19983434Sesaxe cpuid_get_clogid(cpu_t *cpu) 19990Sstevel@tonic-gate { 20000Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 20010Sstevel@tonic-gate return (cpu->cpu_m.mcpu_cpi->cpi_clogid); 20020Sstevel@tonic-gate } 20030Sstevel@tonic-gate 20040Sstevel@tonic-gate void 20050Sstevel@tonic-gate cpuid_get_addrsize(cpu_t *cpu, uint_t *pabits, uint_t *vabits) 20060Sstevel@tonic-gate { 20070Sstevel@tonic-gate struct cpuid_info *cpi; 20080Sstevel@tonic-gate 20090Sstevel@tonic-gate if (cpu == NULL) 20100Sstevel@tonic-gate cpu = CPU; 20110Sstevel@tonic-gate cpi = cpu->cpu_m.mcpu_cpi; 20120Sstevel@tonic-gate 20130Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 20140Sstevel@tonic-gate 20150Sstevel@tonic-gate if (pabits) 20160Sstevel@tonic-gate *pabits = cpi->cpi_pabits; 20170Sstevel@tonic-gate if (vabits) 20180Sstevel@tonic-gate *vabits = cpi->cpi_vabits; 20190Sstevel@tonic-gate } 20200Sstevel@tonic-gate 20210Sstevel@tonic-gate /* 20220Sstevel@tonic-gate * Returns the number of data TLB entries for a corresponding 20230Sstevel@tonic-gate * pagesize. If it can't be computed, or isn't known, the 20240Sstevel@tonic-gate * routine returns zero. If you ask about an architecturally 20250Sstevel@tonic-gate * impossible pagesize, the routine will panic (so that the 20260Sstevel@tonic-gate * hat implementor knows that things are inconsistent.) 20270Sstevel@tonic-gate */ 20280Sstevel@tonic-gate uint_t 20290Sstevel@tonic-gate cpuid_get_dtlb_nent(cpu_t *cpu, size_t pagesize) 20300Sstevel@tonic-gate { 20310Sstevel@tonic-gate struct cpuid_info *cpi; 20320Sstevel@tonic-gate uint_t dtlb_nent = 0; 20330Sstevel@tonic-gate 20340Sstevel@tonic-gate if (cpu == NULL) 20350Sstevel@tonic-gate cpu = CPU; 20360Sstevel@tonic-gate cpi = cpu->cpu_m.mcpu_cpi; 20370Sstevel@tonic-gate 20380Sstevel@tonic-gate ASSERT(cpuid_checkpass(cpu, 1)); 20390Sstevel@tonic-gate 20400Sstevel@tonic-gate /* 20410Sstevel@tonic-gate * Check the L2 TLB info 20420Sstevel@tonic-gate */ 20430Sstevel@tonic-gate if (cpi->cpi_xmaxeax >= 0x80000006) { 20441228Sandrei struct cpuid_regs *cp = &cpi->cpi_extd[6]; 20450Sstevel@tonic-gate 20460Sstevel@tonic-gate switch (pagesize) { 20470Sstevel@tonic-gate 20480Sstevel@tonic-gate case 4 * 1024: 20490Sstevel@tonic-gate /* 20500Sstevel@tonic-gate * All zero in the top 16 bits of the register 20510Sstevel@tonic-gate * indicates a unified TLB. Size is in low 16 bits. 20520Sstevel@tonic-gate */ 20530Sstevel@tonic-gate if ((cp->cp_ebx & 0xffff0000) == 0) 20540Sstevel@tonic-gate dtlb_nent = cp->cp_ebx & 0x0000ffff; 20550Sstevel@tonic-gate else 20560Sstevel@tonic-gate dtlb_nent = BITX(cp->cp_ebx, 27, 16); 20570Sstevel@tonic-gate break; 20580Sstevel@tonic-gate 20590Sstevel@tonic-gate case 2 * 1024 * 1024: 20600Sstevel@tonic-gate if ((cp->cp_eax & 0xffff0000) == 0) 20610Sstevel@tonic-gate dtlb_nent = cp->cp_eax & 0x0000ffff; 20620Sstevel@tonic-gate else 20630Sstevel@tonic-gate dtlb_nent = BITX(cp->cp_eax, 27, 16); 20640Sstevel@tonic-gate break; 20650Sstevel@tonic-gate 20660Sstevel@tonic-gate default: 20670Sstevel@tonic-gate panic("unknown L2 pagesize"); 20680Sstevel@tonic-gate /*NOTREACHED*/ 20690Sstevel@tonic-gate } 20700Sstevel@tonic-gate } 20710Sstevel@tonic-gate 20720Sstevel@tonic-gate if (dtlb_nent != 0) 20730Sstevel@tonic-gate return (dtlb_nent); 20740Sstevel@tonic-gate 20750Sstevel@tonic-gate /* 20760Sstevel@tonic-gate * No L2 TLB support for this size, try L1. 20770Sstevel@tonic-gate */ 20780Sstevel@tonic-gate if (cpi->cpi_xmaxeax >= 0x80000005) { 20791228Sandrei struct cpuid_regs *cp = &cpi->cpi_extd[5]; 20800Sstevel@tonic-gate 20810Sstevel@tonic-gate switch (pagesize) { 20820Sstevel@tonic-gate case 4 * 1024: 20830Sstevel@tonic-gate dtlb_nent = BITX(cp->cp_ebx, 23, 16); 20840Sstevel@tonic-gate break; 20850Sstevel@tonic-gate case 2 * 1024 * 1024: 20860Sstevel@tonic-gate dtlb_nent = BITX(cp->cp_eax, 23, 16); 20870Sstevel@tonic-gate break; 20880Sstevel@tonic-gate default: 20890Sstevel@tonic-gate panic("unknown L1 d-TLB pagesize"); 20900Sstevel@tonic-gate /*NOTREACHED*/ 20910Sstevel@tonic-gate } 20920Sstevel@tonic-gate } 20930Sstevel@tonic-gate 20940Sstevel@tonic-gate return (dtlb_nent); 20950Sstevel@tonic-gate } 20960Sstevel@tonic-gate 20970Sstevel@tonic-gate /* 20980Sstevel@tonic-gate * Return 0 if the erratum is not present or not applicable, positive 20990Sstevel@tonic-gate * if it is, and negative if the status of the erratum is unknown. 21000Sstevel@tonic-gate * 21010Sstevel@tonic-gate * See "Revision Guide for AMD Athlon(tm) 64 and AMD Opteron(tm) 2102359Skucharsk * Processors" #25759, Rev 3.57, August 2005 21030Sstevel@tonic-gate */ 21040Sstevel@tonic-gate int 21050Sstevel@tonic-gate cpuid_opteron_erratum(cpu_t *cpu, uint_t erratum) 21060Sstevel@tonic-gate { 21070Sstevel@tonic-gate struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 21081228Sandrei uint_t eax; 21090Sstevel@tonic-gate 21102584Ssethg /* 21112584Ssethg * Bail out if this CPU isn't an AMD CPU, or if it's 21122584Ssethg * a legacy (32-bit) AMD CPU. 21132584Ssethg */ 21142584Ssethg if (cpi->cpi_vendor != X86_VENDOR_AMD || 21152584Ssethg CPI_FAMILY(cpi) == 4 || CPI_FAMILY(cpi) == 5 || 21162584Ssethg CPI_FAMILY(cpi) == 6) 21172869Sgavinm 21180Sstevel@tonic-gate return (0); 21190Sstevel@tonic-gate 21200Sstevel@tonic-gate eax = cpi->cpi_std[1].cp_eax; 21210Sstevel@tonic-gate 21220Sstevel@tonic-gate #define SH_B0(eax) (eax == 0xf40 || eax == 0xf50) 21230Sstevel@tonic-gate #define SH_B3(eax) (eax == 0xf51) 21241582Skchow #define B(eax) (SH_B0(eax) || SH_B3(eax)) 21250Sstevel@tonic-gate 21260Sstevel@tonic-gate #define SH_C0(eax) (eax == 0xf48 || eax == 0xf58) 21270Sstevel@tonic-gate 21280Sstevel@tonic-gate #define SH_CG(eax) (eax == 0xf4a || eax == 0xf5a || eax == 0xf7a) 21290Sstevel@tonic-gate #define DH_CG(eax) (eax == 0xfc0 || eax == 0xfe0 || eax == 0xff0) 21300Sstevel@tonic-gate #define CH_CG(eax) (eax == 0xf82 || eax == 0xfb2) 21311582Skchow #define CG(eax) (SH_CG(eax) || DH_CG(eax) || CH_CG(eax)) 21320Sstevel@tonic-gate 21330Sstevel@tonic-gate #define SH_D0(eax) (eax == 0x10f40 || eax == 0x10f50 || eax == 0x10f70) 21340Sstevel@tonic-gate #define DH_D0(eax) (eax == 0x10fc0 || eax == 0x10ff0) 21350Sstevel@tonic-gate #define CH_D0(eax) (eax == 0x10f80 || eax == 0x10fb0) 21361582Skchow #define D0(eax) (SH_D0(eax) || DH_D0(eax) || CH_D0(eax)) 21370Sstevel@tonic-gate 21380Sstevel@tonic-gate #define SH_E0(eax) (eax == 0x20f50 || eax == 0x20f40 || eax == 0x20f70) 21390Sstevel@tonic-gate #define JH_E1(eax) (eax == 0x20f10) /* JH8_E0 had 0x20f30 */ 21400Sstevel@tonic-gate #define DH_E3(eax) (eax == 0x20fc0 || eax == 0x20ff0) 21410Sstevel@tonic-gate #define SH_E4(eax) (eax == 0x20f51 || eax == 0x20f71) 21420Sstevel@tonic-gate #define BH_E4(eax) (eax == 0x20fb1) 21430Sstevel@tonic-gate #define SH_E5(eax) (eax == 0x20f42) 21440Sstevel@tonic-gate #define DH_E6(eax) (eax == 0x20ff2 || eax == 0x20fc2) 21450Sstevel@tonic-gate #define JH_E6(eax) (eax == 0x20f12 || eax == 0x20f32) 21461582Skchow #define EX(eax) (SH_E0(eax) || JH_E1(eax) || DH_E3(eax) || \ 21471582Skchow SH_E4(eax) || BH_E4(eax) || SH_E5(eax) || \ 21481582Skchow DH_E6(eax) || JH_E6(eax)) 21490Sstevel@tonic-gate 21500Sstevel@tonic-gate switch (erratum) { 21510Sstevel@tonic-gate case 1: 21520Sstevel@tonic-gate return (1); 21530Sstevel@tonic-gate case 51: /* what does the asterisk mean? */ 21540Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax)); 21550Sstevel@tonic-gate case 52: 21560Sstevel@tonic-gate return (B(eax)); 21570Sstevel@tonic-gate case 57: 21580Sstevel@tonic-gate return (1); 21590Sstevel@tonic-gate case 58: 21600Sstevel@tonic-gate return (B(eax)); 21610Sstevel@tonic-gate case 60: 21620Sstevel@tonic-gate return (1); 21630Sstevel@tonic-gate case 61: 21640Sstevel@tonic-gate case 62: 21650Sstevel@tonic-gate case 63: 21660Sstevel@tonic-gate case 64: 21670Sstevel@tonic-gate case 65: 21680Sstevel@tonic-gate case 66: 21690Sstevel@tonic-gate case 68: 21700Sstevel@tonic-gate case 69: 21710Sstevel@tonic-gate case 70: 21720Sstevel@tonic-gate case 71: 21730Sstevel@tonic-gate return (B(eax)); 21740Sstevel@tonic-gate case 72: 21750Sstevel@tonic-gate return (SH_B0(eax)); 21760Sstevel@tonic-gate case 74: 21770Sstevel@tonic-gate return (B(eax)); 21780Sstevel@tonic-gate case 75: 21790Sstevel@tonic-gate return (1); 21800Sstevel@tonic-gate case 76: 21810Sstevel@tonic-gate return (B(eax)); 21820Sstevel@tonic-gate case 77: 21830Sstevel@tonic-gate return (1); 21840Sstevel@tonic-gate case 78: 21850Sstevel@tonic-gate return (B(eax) || SH_C0(eax)); 21860Sstevel@tonic-gate case 79: 21870Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax) || EX(eax)); 21880Sstevel@tonic-gate case 80: 21890Sstevel@tonic-gate case 81: 21900Sstevel@tonic-gate case 82: 21910Sstevel@tonic-gate return (B(eax)); 21920Sstevel@tonic-gate case 83: 21930Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax)); 21940Sstevel@tonic-gate case 85: 21950Sstevel@tonic-gate return (1); 21960Sstevel@tonic-gate case 86: 21970Sstevel@tonic-gate return (SH_C0(eax) || CG(eax)); 21980Sstevel@tonic-gate case 88: 21990Sstevel@tonic-gate #if !defined(__amd64) 22000Sstevel@tonic-gate return (0); 22010Sstevel@tonic-gate #else 22020Sstevel@tonic-gate return (B(eax) || SH_C0(eax)); 22030Sstevel@tonic-gate #endif 22040Sstevel@tonic-gate case 89: 22050Sstevel@tonic-gate return (1); 22060Sstevel@tonic-gate case 90: 22070Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax)); 22080Sstevel@tonic-gate case 91: 22090Sstevel@tonic-gate case 92: 22100Sstevel@tonic-gate return (B(eax) || SH_C0(eax)); 22110Sstevel@tonic-gate case 93: 22120Sstevel@tonic-gate return (SH_C0(eax)); 22130Sstevel@tonic-gate case 94: 22140Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax)); 22150Sstevel@tonic-gate case 95: 22160Sstevel@tonic-gate #if !defined(__amd64) 22170Sstevel@tonic-gate return (0); 22180Sstevel@tonic-gate #else 22190Sstevel@tonic-gate return (B(eax) || SH_C0(eax)); 22200Sstevel@tonic-gate #endif 22210Sstevel@tonic-gate case 96: 22220Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax)); 22230Sstevel@tonic-gate case 97: 22240Sstevel@tonic-gate case 98: 22250Sstevel@tonic-gate return (SH_C0(eax) || CG(eax)); 22260Sstevel@tonic-gate case 99: 22270Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax)); 22280Sstevel@tonic-gate case 100: 22290Sstevel@tonic-gate return (B(eax) || SH_C0(eax)); 22300Sstevel@tonic-gate case 101: 22310Sstevel@tonic-gate case 103: 22320Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax)); 22330Sstevel@tonic-gate case 104: 22340Sstevel@tonic-gate return (SH_C0(eax) || CG(eax) || D0(eax)); 22350Sstevel@tonic-gate case 105: 22360Sstevel@tonic-gate case 106: 22370Sstevel@tonic-gate case 107: 22380Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax)); 22390Sstevel@tonic-gate case 108: 22400Sstevel@tonic-gate return (DH_CG(eax)); 22410Sstevel@tonic-gate case 109: 22420Sstevel@tonic-gate return (SH_C0(eax) || CG(eax) || D0(eax)); 22430Sstevel@tonic-gate case 110: 22440Sstevel@tonic-gate return (D0(eax) || EX(eax)); 22450Sstevel@tonic-gate case 111: 22460Sstevel@tonic-gate return (CG(eax)); 22470Sstevel@tonic-gate case 112: 22480Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax) || EX(eax)); 22490Sstevel@tonic-gate case 113: 22500Sstevel@tonic-gate return (eax == 0x20fc0); 22510Sstevel@tonic-gate case 114: 22520Sstevel@tonic-gate return (SH_E0(eax) || JH_E1(eax) || DH_E3(eax)); 22530Sstevel@tonic-gate case 115: 22540Sstevel@tonic-gate return (SH_E0(eax) || JH_E1(eax)); 22550Sstevel@tonic-gate case 116: 22560Sstevel@tonic-gate return (SH_E0(eax) || JH_E1(eax) || DH_E3(eax)); 22570Sstevel@tonic-gate case 117: 22580Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax)); 22590Sstevel@tonic-gate case 118: 22600Sstevel@tonic-gate return (SH_E0(eax) || JH_E1(eax) || SH_E4(eax) || BH_E4(eax) || 22610Sstevel@tonic-gate JH_E6(eax)); 22620Sstevel@tonic-gate case 121: 22630Sstevel@tonic-gate return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax) || EX(eax)); 22640Sstevel@tonic-gate case 122: 22652519Skchow return (1); 22660Sstevel@tonic-gate case 123: 22670Sstevel@tonic-gate return (JH_E1(eax) || BH_E4(eax) || JH_E6(eax)); 2268359Skucharsk case 131: 2269359Skucharsk return (1); 2270938Sesaxe case 6336786: 2271938Sesaxe /* 2272938Sesaxe * Test for AdvPowerMgmtInfo.TscPStateInvariant 2273938Sesaxe * if this is a K8 family processor 2274938Sesaxe */ 2275938Sesaxe if (CPI_FAMILY(cpi) == 0xf) { 22761228Sandrei struct cpuid_regs regs; 22771228Sandrei regs.cp_eax = 0x80000007; 22781228Sandrei (void) __cpuid_insn(®s); 22791228Sandrei return (!(regs.cp_edx & 0x100)); 2280938Sesaxe } 2281938Sesaxe return (0); 22821582Skchow case 6323525: 22831582Skchow return (((((eax >> 12) & 0xff00) + (eax & 0xf00)) | 22841582Skchow (((eax >> 4) & 0xf) | ((eax >> 12) & 0xf0))) < 0xf40); 22851582Skchow 22860Sstevel@tonic-gate default: 22870Sstevel@tonic-gate return (-1); 22880Sstevel@tonic-gate } 22890Sstevel@tonic-gate } 22900Sstevel@tonic-gate 22910Sstevel@tonic-gate static const char assoc_str[] = "associativity"; 22920Sstevel@tonic-gate static const char line_str[] = "line-size"; 22930Sstevel@tonic-gate static const char size_str[] = "size"; 22940Sstevel@tonic-gate 22950Sstevel@tonic-gate static void 22960Sstevel@tonic-gate add_cache_prop(dev_info_t *devi, const char *label, const char *type, 22970Sstevel@tonic-gate uint32_t val) 22980Sstevel@tonic-gate { 22990Sstevel@tonic-gate char buf[128]; 23000Sstevel@tonic-gate 23010Sstevel@tonic-gate /* 23020Sstevel@tonic-gate * ndi_prop_update_int() is used because it is desirable for 23030Sstevel@tonic-gate * DDI_PROP_HW_DEF and DDI_PROP_DONTSLEEP to be set. 23040Sstevel@tonic-gate */ 23050Sstevel@tonic-gate if (snprintf(buf, sizeof (buf), "%s-%s", label, type) < sizeof (buf)) 23060Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, devi, buf, val); 23070Sstevel@tonic-gate } 23080Sstevel@tonic-gate 23090Sstevel@tonic-gate /* 23100Sstevel@tonic-gate * Intel-style cache/tlb description 23110Sstevel@tonic-gate * 23120Sstevel@tonic-gate * Standard cpuid level 2 gives a randomly ordered 23130Sstevel@tonic-gate * selection of tags that index into a table that describes 23140Sstevel@tonic-gate * cache and tlb properties. 23150Sstevel@tonic-gate */ 23160Sstevel@tonic-gate 23170Sstevel@tonic-gate static const char l1_icache_str[] = "l1-icache"; 23180Sstevel@tonic-gate static const char l1_dcache_str[] = "l1-dcache"; 23190Sstevel@tonic-gate static const char l2_cache_str[] = "l2-cache"; 23203446Smrj static const char l3_cache_str[] = "l3-cache"; 23210Sstevel@tonic-gate static const char itlb4k_str[] = "itlb-4K"; 23220Sstevel@tonic-gate static const char dtlb4k_str[] = "dtlb-4K"; 23230Sstevel@tonic-gate static const char itlb4M_str[] = "itlb-4M"; 23240Sstevel@tonic-gate static const char dtlb4M_str[] = "dtlb-4M"; 23250Sstevel@tonic-gate static const char itlb424_str[] = "itlb-4K-2M-4M"; 23260Sstevel@tonic-gate static const char dtlb44_str[] = "dtlb-4K-4M"; 23270Sstevel@tonic-gate static const char sl1_dcache_str[] = "sectored-l1-dcache"; 23280Sstevel@tonic-gate static const char sl2_cache_str[] = "sectored-l2-cache"; 23290Sstevel@tonic-gate static const char itrace_str[] = "itrace-cache"; 23300Sstevel@tonic-gate static const char sl3_cache_str[] = "sectored-l3-cache"; 23310Sstevel@tonic-gate 23320Sstevel@tonic-gate static const struct cachetab { 23330Sstevel@tonic-gate uint8_t ct_code; 23340Sstevel@tonic-gate uint8_t ct_assoc; 23350Sstevel@tonic-gate uint16_t ct_line_size; 23360Sstevel@tonic-gate size_t ct_size; 23370Sstevel@tonic-gate const char *ct_label; 23380Sstevel@tonic-gate } intel_ctab[] = { 23390Sstevel@tonic-gate /* maintain descending order! */ 23403446Smrj { 0xb4, 4, 0, 256, dtlb4k_str }, 23410Sstevel@tonic-gate { 0xb3, 4, 0, 128, dtlb4k_str }, 23420Sstevel@tonic-gate { 0xb0, 4, 0, 128, itlb4k_str }, 23430Sstevel@tonic-gate { 0x87, 8, 64, 1024*1024, l2_cache_str}, 23440Sstevel@tonic-gate { 0x86, 4, 64, 512*1024, l2_cache_str}, 23450Sstevel@tonic-gate { 0x85, 8, 32, 2*1024*1024, l2_cache_str}, 23460Sstevel@tonic-gate { 0x84, 8, 32, 1024*1024, l2_cache_str}, 23470Sstevel@tonic-gate { 0x83, 8, 32, 512*1024, l2_cache_str}, 23480Sstevel@tonic-gate { 0x82, 8, 32, 256*1024, l2_cache_str}, 23490Sstevel@tonic-gate { 0x7f, 2, 64, 512*1024, l2_cache_str}, 23500Sstevel@tonic-gate { 0x7d, 8, 64, 2*1024*1024, sl2_cache_str}, 23510Sstevel@tonic-gate { 0x7c, 8, 64, 1024*1024, sl2_cache_str}, 23520Sstevel@tonic-gate { 0x7b, 8, 64, 512*1024, sl2_cache_str}, 23530Sstevel@tonic-gate { 0x7a, 8, 64, 256*1024, sl2_cache_str}, 23540Sstevel@tonic-gate { 0x79, 8, 64, 128*1024, sl2_cache_str}, 23550Sstevel@tonic-gate { 0x78, 8, 64, 1024*1024, l2_cache_str}, 23563446Smrj { 0x73, 8, 0, 64*1024, itrace_str}, 23570Sstevel@tonic-gate { 0x72, 8, 0, 32*1024, itrace_str}, 23580Sstevel@tonic-gate { 0x71, 8, 0, 16*1024, itrace_str}, 23590Sstevel@tonic-gate { 0x70, 8, 0, 12*1024, itrace_str}, 23600Sstevel@tonic-gate { 0x68, 4, 64, 32*1024, sl1_dcache_str}, 23610Sstevel@tonic-gate { 0x67, 4, 64, 16*1024, sl1_dcache_str}, 23620Sstevel@tonic-gate { 0x66, 4, 64, 8*1024, sl1_dcache_str}, 23630Sstevel@tonic-gate { 0x60, 8, 64, 16*1024, sl1_dcache_str}, 23640Sstevel@tonic-gate { 0x5d, 0, 0, 256, dtlb44_str}, 23650Sstevel@tonic-gate { 0x5c, 0, 0, 128, dtlb44_str}, 23660Sstevel@tonic-gate { 0x5b, 0, 0, 64, dtlb44_str}, 23670Sstevel@tonic-gate { 0x52, 0, 0, 256, itlb424_str}, 23680Sstevel@tonic-gate { 0x51, 0, 0, 128, itlb424_str}, 23690Sstevel@tonic-gate { 0x50, 0, 0, 64, itlb424_str}, 23703446Smrj { 0x4d, 16, 64, 16*1024*1024, l3_cache_str}, 23713446Smrj { 0x4c, 12, 64, 12*1024*1024, l3_cache_str}, 23723446Smrj { 0x4b, 16, 64, 8*1024*1024, l3_cache_str}, 23733446Smrj { 0x4a, 12, 64, 6*1024*1024, l3_cache_str}, 23743446Smrj { 0x49, 16, 64, 4*1024*1024, l3_cache_str}, 23753446Smrj { 0x47, 8, 64, 8*1024*1024, l3_cache_str}, 23763446Smrj { 0x46, 4, 64, 4*1024*1024, l3_cache_str}, 23770Sstevel@tonic-gate { 0x45, 4, 32, 2*1024*1024, l2_cache_str}, 23780Sstevel@tonic-gate { 0x44, 4, 32, 1024*1024, l2_cache_str}, 23790Sstevel@tonic-gate { 0x43, 4, 32, 512*1024, l2_cache_str}, 23800Sstevel@tonic-gate { 0x42, 4, 32, 256*1024, l2_cache_str}, 23810Sstevel@tonic-gate { 0x41, 4, 32, 128*1024, l2_cache_str}, 23823446Smrj { 0x3e, 4, 64, 512*1024, sl2_cache_str}, 23833446Smrj { 0x3d, 6, 64, 384*1024, sl2_cache_str}, 23840Sstevel@tonic-gate { 0x3c, 4, 64, 256*1024, sl2_cache_str}, 23850Sstevel@tonic-gate { 0x3b, 2, 64, 128*1024, sl2_cache_str}, 23863446Smrj { 0x3a, 6, 64, 192*1024, sl2_cache_str}, 23870Sstevel@tonic-gate { 0x39, 4, 64, 128*1024, sl2_cache_str}, 23880Sstevel@tonic-gate { 0x30, 8, 64, 32*1024, l1_icache_str}, 23890Sstevel@tonic-gate { 0x2c, 8, 64, 32*1024, l1_dcache_str}, 23900Sstevel@tonic-gate { 0x29, 8, 64, 4096*1024, sl3_cache_str}, 23910Sstevel@tonic-gate { 0x25, 8, 64, 2048*1024, sl3_cache_str}, 23920Sstevel@tonic-gate { 0x23, 8, 64, 1024*1024, sl3_cache_str}, 23930Sstevel@tonic-gate { 0x22, 4, 64, 512*1024, sl3_cache_str}, 23940Sstevel@tonic-gate { 0x0c, 4, 32, 16*1024, l1_dcache_str}, 23953446Smrj { 0x0b, 4, 0, 4, itlb4M_str}, 23960Sstevel@tonic-gate { 0x0a, 2, 32, 8*1024, l1_dcache_str}, 23970Sstevel@tonic-gate { 0x08, 4, 32, 16*1024, l1_icache_str}, 23980Sstevel@tonic-gate { 0x06, 4, 32, 8*1024, l1_icache_str}, 23990Sstevel@tonic-gate { 0x04, 4, 0, 8, dtlb4M_str}, 24000Sstevel@tonic-gate { 0x03, 4, 0, 64, dtlb4k_str}, 24010Sstevel@tonic-gate { 0x02, 4, 0, 2, itlb4M_str}, 24020Sstevel@tonic-gate { 0x01, 4, 0, 32, itlb4k_str}, 24030Sstevel@tonic-gate { 0 } 24040Sstevel@tonic-gate }; 24050Sstevel@tonic-gate 24060Sstevel@tonic-gate static const struct cachetab cyrix_ctab[] = { 24070Sstevel@tonic-gate { 0x70, 4, 0, 32, "tlb-4K" }, 24080Sstevel@tonic-gate { 0x80, 4, 16, 16*1024, "l1-cache" }, 24090Sstevel@tonic-gate { 0 } 24100Sstevel@tonic-gate }; 24110Sstevel@tonic-gate 24120Sstevel@tonic-gate /* 24130Sstevel@tonic-gate * Search a cache table for a matching entry 24140Sstevel@tonic-gate */ 24150Sstevel@tonic-gate static const struct cachetab * 24160Sstevel@tonic-gate find_cacheent(const struct cachetab *ct, uint_t code) 24170Sstevel@tonic-gate { 24180Sstevel@tonic-gate if (code != 0) { 24190Sstevel@tonic-gate for (; ct->ct_code != 0; ct++) 24200Sstevel@tonic-gate if (ct->ct_code <= code) 24210Sstevel@tonic-gate break; 24220Sstevel@tonic-gate if (ct->ct_code == code) 24230Sstevel@tonic-gate return (ct); 24240Sstevel@tonic-gate } 24250Sstevel@tonic-gate return (NULL); 24260Sstevel@tonic-gate } 24270Sstevel@tonic-gate 24280Sstevel@tonic-gate /* 24290Sstevel@tonic-gate * Walk the cacheinfo descriptor, applying 'func' to every valid element 24300Sstevel@tonic-gate * The walk is terminated if the walker returns non-zero. 24310Sstevel@tonic-gate */ 24320Sstevel@tonic-gate static void 24330Sstevel@tonic-gate intel_walk_cacheinfo(struct cpuid_info *cpi, 24340Sstevel@tonic-gate void *arg, int (*func)(void *, const struct cachetab *)) 24350Sstevel@tonic-gate { 24360Sstevel@tonic-gate const struct cachetab *ct; 24370Sstevel@tonic-gate uint8_t *dp; 24380Sstevel@tonic-gate int i; 24390Sstevel@tonic-gate 24400Sstevel@tonic-gate if ((dp = cpi->cpi_cacheinfo) == NULL) 24410Sstevel@tonic-gate return; 24420Sstevel@tonic-gate for (i = 0; i < cpi->cpi_ncache; i++, dp++) 24430Sstevel@tonic-gate if ((ct = find_cacheent(intel_ctab, *dp)) != NULL) { 24440Sstevel@tonic-gate if (func(arg, ct) != 0) 24450Sstevel@tonic-gate break; 24460Sstevel@tonic-gate } 24470Sstevel@tonic-gate } 24480Sstevel@tonic-gate 24490Sstevel@tonic-gate /* 24500Sstevel@tonic-gate * (Like the Intel one, except for Cyrix CPUs) 24510Sstevel@tonic-gate */ 24520Sstevel@tonic-gate static void 24530Sstevel@tonic-gate cyrix_walk_cacheinfo(struct cpuid_info *cpi, 24540Sstevel@tonic-gate void *arg, int (*func)(void *, const struct cachetab *)) 24550Sstevel@tonic-gate { 24560Sstevel@tonic-gate const struct cachetab *ct; 24570Sstevel@tonic-gate uint8_t *dp; 24580Sstevel@tonic-gate int i; 24590Sstevel@tonic-gate 24600Sstevel@tonic-gate if ((dp = cpi->cpi_cacheinfo) == NULL) 24610Sstevel@tonic-gate return; 24620Sstevel@tonic-gate for (i = 0; i < cpi->cpi_ncache; i++, dp++) { 24630Sstevel@tonic-gate /* 24640Sstevel@tonic-gate * Search Cyrix-specific descriptor table first .. 24650Sstevel@tonic-gate */ 24660Sstevel@tonic-gate if ((ct = find_cacheent(cyrix_ctab, *dp)) != NULL) { 24670Sstevel@tonic-gate if (func(arg, ct) != 0) 24680Sstevel@tonic-gate break; 24690Sstevel@tonic-gate continue; 24700Sstevel@tonic-gate } 24710Sstevel@tonic-gate /* 24720Sstevel@tonic-gate * .. else fall back to the Intel one 24730Sstevel@tonic-gate */ 24740Sstevel@tonic-gate if ((ct = find_cacheent(intel_ctab, *dp)) != NULL) { 24750Sstevel@tonic-gate if (func(arg, ct) != 0) 24760Sstevel@tonic-gate break; 24770Sstevel@tonic-gate continue; 24780Sstevel@tonic-gate } 24790Sstevel@tonic-gate } 24800Sstevel@tonic-gate } 24810Sstevel@tonic-gate 24820Sstevel@tonic-gate /* 24830Sstevel@tonic-gate * A cacheinfo walker that adds associativity, line-size, and size properties 24840Sstevel@tonic-gate * to the devinfo node it is passed as an argument. 24850Sstevel@tonic-gate */ 24860Sstevel@tonic-gate static int 24870Sstevel@tonic-gate add_cacheent_props(void *arg, const struct cachetab *ct) 24880Sstevel@tonic-gate { 24890Sstevel@tonic-gate dev_info_t *devi = arg; 24900Sstevel@tonic-gate 24910Sstevel@tonic-gate add_cache_prop(devi, ct->ct_label, assoc_str, ct->ct_assoc); 24920Sstevel@tonic-gate if (ct->ct_line_size != 0) 24930Sstevel@tonic-gate add_cache_prop(devi, ct->ct_label, line_str, 24940Sstevel@tonic-gate ct->ct_line_size); 24950Sstevel@tonic-gate add_cache_prop(devi, ct->ct_label, size_str, ct->ct_size); 24960Sstevel@tonic-gate return (0); 24970Sstevel@tonic-gate } 24980Sstevel@tonic-gate 24990Sstevel@tonic-gate static const char fully_assoc[] = "fully-associative?"; 25000Sstevel@tonic-gate 25010Sstevel@tonic-gate /* 25020Sstevel@tonic-gate * AMD style cache/tlb description 25030Sstevel@tonic-gate * 25040Sstevel@tonic-gate * Extended functions 5 and 6 directly describe properties of 25050Sstevel@tonic-gate * tlbs and various cache levels. 25060Sstevel@tonic-gate */ 25070Sstevel@tonic-gate static void 25080Sstevel@tonic-gate add_amd_assoc(dev_info_t *devi, const char *label, uint_t assoc) 25090Sstevel@tonic-gate { 25100Sstevel@tonic-gate switch (assoc) { 25110Sstevel@tonic-gate case 0: /* reserved; ignore */ 25120Sstevel@tonic-gate break; 25130Sstevel@tonic-gate default: 25140Sstevel@tonic-gate add_cache_prop(devi, label, assoc_str, assoc); 25150Sstevel@tonic-gate break; 25160Sstevel@tonic-gate case 0xff: 25170Sstevel@tonic-gate add_cache_prop(devi, label, fully_assoc, 1); 25180Sstevel@tonic-gate break; 25190Sstevel@tonic-gate } 25200Sstevel@tonic-gate } 25210Sstevel@tonic-gate 25220Sstevel@tonic-gate static void 25230Sstevel@tonic-gate add_amd_tlb(dev_info_t *devi, const char *label, uint_t assoc, uint_t size) 25240Sstevel@tonic-gate { 25250Sstevel@tonic-gate if (size == 0) 25260Sstevel@tonic-gate return; 25270Sstevel@tonic-gate add_cache_prop(devi, label, size_str, size); 25280Sstevel@tonic-gate add_amd_assoc(devi, label, assoc); 25290Sstevel@tonic-gate } 25300Sstevel@tonic-gate 25310Sstevel@tonic-gate static void 25320Sstevel@tonic-gate add_amd_cache(dev_info_t *devi, const char *label, 25330Sstevel@tonic-gate uint_t size, uint_t assoc, uint_t lines_per_tag, uint_t line_size) 25340Sstevel@tonic-gate { 25350Sstevel@tonic-gate if (size == 0 || line_size == 0) 25360Sstevel@tonic-gate return; 25370Sstevel@tonic-gate add_amd_assoc(devi, label, assoc); 25380Sstevel@tonic-gate /* 25390Sstevel@tonic-gate * Most AMD parts have a sectored cache. Multiple cache lines are 25400Sstevel@tonic-gate * associated with each tag. A sector consists of all cache lines 25410Sstevel@tonic-gate * associated with a tag. For example, the AMD K6-III has a sector 25420Sstevel@tonic-gate * size of 2 cache lines per tag. 25430Sstevel@tonic-gate */ 25440Sstevel@tonic-gate if (lines_per_tag != 0) 25450Sstevel@tonic-gate add_cache_prop(devi, label, "lines-per-tag", lines_per_tag); 25460Sstevel@tonic-gate add_cache_prop(devi, label, line_str, line_size); 25470Sstevel@tonic-gate add_cache_prop(devi, label, size_str, size * 1024); 25480Sstevel@tonic-gate } 25490Sstevel@tonic-gate 25500Sstevel@tonic-gate static void 25510Sstevel@tonic-gate add_amd_l2_assoc(dev_info_t *devi, const char *label, uint_t assoc) 25520Sstevel@tonic-gate { 25530Sstevel@tonic-gate switch (assoc) { 25540Sstevel@tonic-gate case 0: /* off */ 25550Sstevel@tonic-gate break; 25560Sstevel@tonic-gate case 1: 25570Sstevel@tonic-gate case 2: 25580Sstevel@tonic-gate case 4: 25590Sstevel@tonic-gate add_cache_prop(devi, label, assoc_str, assoc); 25600Sstevel@tonic-gate break; 25610Sstevel@tonic-gate case 6: 25620Sstevel@tonic-gate add_cache_prop(devi, label, assoc_str, 8); 25630Sstevel@tonic-gate break; 25640Sstevel@tonic-gate case 8: 25650Sstevel@tonic-gate add_cache_prop(devi, label, assoc_str, 16); 25660Sstevel@tonic-gate break; 25670Sstevel@tonic-gate case 0xf: 25680Sstevel@tonic-gate add_cache_prop(devi, label, fully_assoc, 1); 25690Sstevel@tonic-gate break; 25700Sstevel@tonic-gate default: /* reserved; ignore */ 25710Sstevel@tonic-gate break; 25720Sstevel@tonic-gate } 25730Sstevel@tonic-gate } 25740Sstevel@tonic-gate 25750Sstevel@tonic-gate static void 25760Sstevel@tonic-gate add_amd_l2_tlb(dev_info_t *devi, const char *label, uint_t assoc, uint_t size) 25770Sstevel@tonic-gate { 25780Sstevel@tonic-gate if (size == 0 || assoc == 0) 25790Sstevel@tonic-gate return; 25800Sstevel@tonic-gate add_amd_l2_assoc(devi, label, assoc); 25810Sstevel@tonic-gate add_cache_prop(devi, label, size_str, size); 25820Sstevel@tonic-gate } 25830Sstevel@tonic-gate 25840Sstevel@tonic-gate static void 25850Sstevel@tonic-gate add_amd_l2_cache(dev_info_t *devi, const char *label, 25860Sstevel@tonic-gate uint_t size, uint_t assoc, uint_t lines_per_tag, uint_t line_size) 25870Sstevel@tonic-gate { 25880Sstevel@tonic-gate if (size == 0 || assoc == 0 || line_size == 0) 25890Sstevel@tonic-gate return; 25900Sstevel@tonic-gate add_amd_l2_assoc(devi, label, assoc); 25910Sstevel@tonic-gate if (lines_per_tag != 0) 25920Sstevel@tonic-gate add_cache_prop(devi, label, "lines-per-tag", lines_per_tag); 25930Sstevel@tonic-gate add_cache_prop(devi, label, line_str, line_size); 25940Sstevel@tonic-gate add_cache_prop(devi, label, size_str, size * 1024); 25950Sstevel@tonic-gate } 25960Sstevel@tonic-gate 25970Sstevel@tonic-gate static void 25980Sstevel@tonic-gate amd_cache_info(struct cpuid_info *cpi, dev_info_t *devi) 25990Sstevel@tonic-gate { 26001228Sandrei struct cpuid_regs *cp; 26010Sstevel@tonic-gate 26020Sstevel@tonic-gate if (cpi->cpi_xmaxeax < 0x80000005) 26030Sstevel@tonic-gate return; 26040Sstevel@tonic-gate cp = &cpi->cpi_extd[5]; 26050Sstevel@tonic-gate 26060Sstevel@tonic-gate /* 26070Sstevel@tonic-gate * 4M/2M L1 TLB configuration 26080Sstevel@tonic-gate * 26090Sstevel@tonic-gate * We report the size for 2M pages because AMD uses two 26100Sstevel@tonic-gate * TLB entries for one 4M page. 26110Sstevel@tonic-gate */ 26120Sstevel@tonic-gate add_amd_tlb(devi, "dtlb-2M", 26130Sstevel@tonic-gate BITX(cp->cp_eax, 31, 24), BITX(cp->cp_eax, 23, 16)); 26140Sstevel@tonic-gate add_amd_tlb(devi, "itlb-2M", 26150Sstevel@tonic-gate BITX(cp->cp_eax, 15, 8), BITX(cp->cp_eax, 7, 0)); 26160Sstevel@tonic-gate 26170Sstevel@tonic-gate /* 26180Sstevel@tonic-gate * 4K L1 TLB configuration 26190Sstevel@tonic-gate */ 26200Sstevel@tonic-gate 26210Sstevel@tonic-gate switch (cpi->cpi_vendor) { 26220Sstevel@tonic-gate uint_t nentries; 26230Sstevel@tonic-gate case X86_VENDOR_TM: 26240Sstevel@tonic-gate if (cpi->cpi_family >= 5) { 26250Sstevel@tonic-gate /* 26260Sstevel@tonic-gate * Crusoe processors have 256 TLB entries, but 26270Sstevel@tonic-gate * cpuid data format constrains them to only 26280Sstevel@tonic-gate * reporting 255 of them. 26290Sstevel@tonic-gate */ 26300Sstevel@tonic-gate if ((nentries = BITX(cp->cp_ebx, 23, 16)) == 255) 26310Sstevel@tonic-gate nentries = 256; 26320Sstevel@tonic-gate /* 26330Sstevel@tonic-gate * Crusoe processors also have a unified TLB 26340Sstevel@tonic-gate */ 26350Sstevel@tonic-gate add_amd_tlb(devi, "tlb-4K", BITX(cp->cp_ebx, 31, 24), 26360Sstevel@tonic-gate nentries); 26370Sstevel@tonic-gate break; 26380Sstevel@tonic-gate } 26390Sstevel@tonic-gate /*FALLTHROUGH*/ 26400Sstevel@tonic-gate default: 26410Sstevel@tonic-gate add_amd_tlb(devi, itlb4k_str, 26420Sstevel@tonic-gate BITX(cp->cp_ebx, 31, 24), BITX(cp->cp_ebx, 23, 16)); 26430Sstevel@tonic-gate add_amd_tlb(devi, dtlb4k_str, 26440Sstevel@tonic-gate BITX(cp->cp_ebx, 15, 8), BITX(cp->cp_ebx, 7, 0)); 26450Sstevel@tonic-gate break; 26460Sstevel@tonic-gate } 26470Sstevel@tonic-gate 26480Sstevel@tonic-gate /* 26490Sstevel@tonic-gate * data L1 cache configuration 26500Sstevel@tonic-gate */ 26510Sstevel@tonic-gate 26520Sstevel@tonic-gate add_amd_cache(devi, l1_dcache_str, 26530Sstevel@tonic-gate BITX(cp->cp_ecx, 31, 24), BITX(cp->cp_ecx, 23, 16), 26540Sstevel@tonic-gate BITX(cp->cp_ecx, 15, 8), BITX(cp->cp_ecx, 7, 0)); 26550Sstevel@tonic-gate 26560Sstevel@tonic-gate /* 26570Sstevel@tonic-gate * code L1 cache configuration 26580Sstevel@tonic-gate */ 26590Sstevel@tonic-gate 26600Sstevel@tonic-gate add_amd_cache(devi, l1_icache_str, 26610Sstevel@tonic-gate BITX(cp->cp_edx, 31, 24), BITX(cp->cp_edx, 23, 16), 26620Sstevel@tonic-gate BITX(cp->cp_edx, 15, 8), BITX(cp->cp_edx, 7, 0)); 26630Sstevel@tonic-gate 26640Sstevel@tonic-gate if (cpi->cpi_xmaxeax < 0x80000006) 26650Sstevel@tonic-gate return; 26660Sstevel@tonic-gate cp = &cpi->cpi_extd[6]; 26670Sstevel@tonic-gate 26680Sstevel@tonic-gate /* Check for a unified L2 TLB for large pages */ 26690Sstevel@tonic-gate 26700Sstevel@tonic-gate if (BITX(cp->cp_eax, 31, 16) == 0) 26710Sstevel@tonic-gate add_amd_l2_tlb(devi, "l2-tlb-2M", 26720Sstevel@tonic-gate BITX(cp->cp_eax, 15, 12), BITX(cp->cp_eax, 11, 0)); 26730Sstevel@tonic-gate else { 26740Sstevel@tonic-gate add_amd_l2_tlb(devi, "l2-dtlb-2M", 26750Sstevel@tonic-gate BITX(cp->cp_eax, 31, 28), BITX(cp->cp_eax, 27, 16)); 26760Sstevel@tonic-gate add_amd_l2_tlb(devi, "l2-itlb-2M", 26770Sstevel@tonic-gate BITX(cp->cp_eax, 15, 12), BITX(cp->cp_eax, 11, 0)); 26780Sstevel@tonic-gate } 26790Sstevel@tonic-gate 26800Sstevel@tonic-gate /* Check for a unified L2 TLB for 4K pages */ 26810Sstevel@tonic-gate 26820Sstevel@tonic-gate if (BITX(cp->cp_ebx, 31, 16) == 0) { 26830Sstevel@tonic-gate add_amd_l2_tlb(devi, "l2-tlb-4K", 26840Sstevel@tonic-gate BITX(cp->cp_eax, 15, 12), BITX(cp->cp_eax, 11, 0)); 26850Sstevel@tonic-gate } else { 26860Sstevel@tonic-gate add_amd_l2_tlb(devi, "l2-dtlb-4K", 26870Sstevel@tonic-gate BITX(cp->cp_eax, 31, 28), BITX(cp->cp_eax, 27, 16)); 26880Sstevel@tonic-gate add_amd_l2_tlb(devi, "l2-itlb-4K", 26890Sstevel@tonic-gate BITX(cp->cp_eax, 15, 12), BITX(cp->cp_eax, 11, 0)); 26900Sstevel@tonic-gate } 26910Sstevel@tonic-gate 26920Sstevel@tonic-gate add_amd_l2_cache(devi, l2_cache_str, 26930Sstevel@tonic-gate BITX(cp->cp_ecx, 31, 16), BITX(cp->cp_ecx, 15, 12), 26940Sstevel@tonic-gate BITX(cp->cp_ecx, 11, 8), BITX(cp->cp_ecx, 7, 0)); 26950Sstevel@tonic-gate } 26960Sstevel@tonic-gate 26970Sstevel@tonic-gate /* 26980Sstevel@tonic-gate * There are two basic ways that the x86 world describes it cache 26990Sstevel@tonic-gate * and tlb architecture - Intel's way and AMD's way. 27000Sstevel@tonic-gate * 27010Sstevel@tonic-gate * Return which flavor of cache architecture we should use 27020Sstevel@tonic-gate */ 27030Sstevel@tonic-gate static int 27040Sstevel@tonic-gate x86_which_cacheinfo(struct cpuid_info *cpi) 27050Sstevel@tonic-gate { 27060Sstevel@tonic-gate switch (cpi->cpi_vendor) { 27070Sstevel@tonic-gate case X86_VENDOR_Intel: 27080Sstevel@tonic-gate if (cpi->cpi_maxeax >= 2) 27090Sstevel@tonic-gate return (X86_VENDOR_Intel); 27100Sstevel@tonic-gate break; 27110Sstevel@tonic-gate case X86_VENDOR_AMD: 27120Sstevel@tonic-gate /* 27130Sstevel@tonic-gate * The K5 model 1 was the first part from AMD that reported 27140Sstevel@tonic-gate * cache sizes via extended cpuid functions. 27150Sstevel@tonic-gate */ 27160Sstevel@tonic-gate if (cpi->cpi_family > 5 || 27170Sstevel@tonic-gate (cpi->cpi_family == 5 && cpi->cpi_model >= 1)) 27180Sstevel@tonic-gate return (X86_VENDOR_AMD); 27190Sstevel@tonic-gate break; 27200Sstevel@tonic-gate case X86_VENDOR_TM: 27210Sstevel@tonic-gate if (cpi->cpi_family >= 5) 27220Sstevel@tonic-gate return (X86_VENDOR_AMD); 27230Sstevel@tonic-gate /*FALLTHROUGH*/ 27240Sstevel@tonic-gate default: 27250Sstevel@tonic-gate /* 27260Sstevel@tonic-gate * If they have extended CPU data for 0x80000005 27270Sstevel@tonic-gate * then we assume they have AMD-format cache 27280Sstevel@tonic-gate * information. 27290Sstevel@tonic-gate * 27300Sstevel@tonic-gate * If not, and the vendor happens to be Cyrix, 27310Sstevel@tonic-gate * then try our-Cyrix specific handler. 27320Sstevel@tonic-gate * 27330Sstevel@tonic-gate * If we're not Cyrix, then assume we're using Intel's 27340Sstevel@tonic-gate * table-driven format instead. 27350Sstevel@tonic-gate */ 27360Sstevel@tonic-gate if (cpi->cpi_xmaxeax >= 0x80000005) 27370Sstevel@tonic-gate return (X86_VENDOR_AMD); 27380Sstevel@tonic-gate else if (cpi->cpi_vendor == X86_VENDOR_Cyrix) 27390Sstevel@tonic-gate return (X86_VENDOR_Cyrix); 27400Sstevel@tonic-gate else if (cpi->cpi_maxeax >= 2) 27410Sstevel@tonic-gate return (X86_VENDOR_Intel); 27420Sstevel@tonic-gate break; 27430Sstevel@tonic-gate } 27440Sstevel@tonic-gate return (-1); 27450Sstevel@tonic-gate } 27460Sstevel@tonic-gate 27470Sstevel@tonic-gate /* 27480Sstevel@tonic-gate * create a node for the given cpu under the prom root node. 27490Sstevel@tonic-gate * Also, create a cpu node in the device tree. 27500Sstevel@tonic-gate */ 27510Sstevel@tonic-gate static dev_info_t *cpu_nex_devi = NULL; 27520Sstevel@tonic-gate static kmutex_t cpu_node_lock; 27530Sstevel@tonic-gate 27540Sstevel@tonic-gate /* 27550Sstevel@tonic-gate * Called from post_startup() and mp_startup() 27560Sstevel@tonic-gate */ 27570Sstevel@tonic-gate void 27580Sstevel@tonic-gate add_cpunode2devtree(processorid_t cpu_id, struct cpuid_info *cpi) 27590Sstevel@tonic-gate { 27600Sstevel@tonic-gate dev_info_t *cpu_devi; 27610Sstevel@tonic-gate int create; 27620Sstevel@tonic-gate 27630Sstevel@tonic-gate mutex_enter(&cpu_node_lock); 27640Sstevel@tonic-gate 27650Sstevel@tonic-gate /* 27660Sstevel@tonic-gate * create a nexus node for all cpus identified as 'cpu_id' under 27670Sstevel@tonic-gate * the root node. 27680Sstevel@tonic-gate */ 27690Sstevel@tonic-gate if (cpu_nex_devi == NULL) { 27700Sstevel@tonic-gate if (ndi_devi_alloc(ddi_root_node(), "cpus", 2771789Sahrens (pnode_t)DEVI_SID_NODEID, &cpu_nex_devi) != NDI_SUCCESS) { 27720Sstevel@tonic-gate mutex_exit(&cpu_node_lock); 27730Sstevel@tonic-gate return; 27740Sstevel@tonic-gate } 27750Sstevel@tonic-gate (void) ndi_devi_online(cpu_nex_devi, 0); 27760Sstevel@tonic-gate } 27770Sstevel@tonic-gate 27780Sstevel@tonic-gate /* 27790Sstevel@tonic-gate * create a child node for cpu identified as 'cpu_id' 27800Sstevel@tonic-gate */ 27810Sstevel@tonic-gate cpu_devi = ddi_add_child(cpu_nex_devi, "cpu", DEVI_SID_NODEID, 27820Sstevel@tonic-gate cpu_id); 27830Sstevel@tonic-gate if (cpu_devi == NULL) { 27840Sstevel@tonic-gate mutex_exit(&cpu_node_lock); 27850Sstevel@tonic-gate return; 27860Sstevel@tonic-gate } 27870Sstevel@tonic-gate 27880Sstevel@tonic-gate /* device_type */ 27890Sstevel@tonic-gate 27900Sstevel@tonic-gate (void) ndi_prop_update_string(DDI_DEV_T_NONE, cpu_devi, 27910Sstevel@tonic-gate "device_type", "cpu"); 27920Sstevel@tonic-gate 27930Sstevel@tonic-gate /* reg */ 27940Sstevel@tonic-gate 27950Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 27960Sstevel@tonic-gate "reg", cpu_id); 27970Sstevel@tonic-gate 27980Sstevel@tonic-gate /* cpu-mhz, and clock-frequency */ 27990Sstevel@tonic-gate 28000Sstevel@tonic-gate if (cpu_freq > 0) { 28010Sstevel@tonic-gate long long mul; 28020Sstevel@tonic-gate 28030Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 28040Sstevel@tonic-gate "cpu-mhz", cpu_freq); 28050Sstevel@tonic-gate 28060Sstevel@tonic-gate if ((mul = cpu_freq * 1000000LL) <= INT_MAX) 28070Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 28080Sstevel@tonic-gate "clock-frequency", (int)mul); 28090Sstevel@tonic-gate } 28100Sstevel@tonic-gate 28110Sstevel@tonic-gate (void) ndi_devi_online(cpu_devi, 0); 28120Sstevel@tonic-gate 28130Sstevel@tonic-gate if ((x86_feature & X86_CPUID) == 0) { 28140Sstevel@tonic-gate mutex_exit(&cpu_node_lock); 28150Sstevel@tonic-gate return; 28160Sstevel@tonic-gate } 28170Sstevel@tonic-gate 28180Sstevel@tonic-gate /* vendor-id */ 28190Sstevel@tonic-gate 28200Sstevel@tonic-gate (void) ndi_prop_update_string(DDI_DEV_T_NONE, cpu_devi, 28210Sstevel@tonic-gate "vendor-id", cpi->cpi_vendorstr); 28220Sstevel@tonic-gate 28230Sstevel@tonic-gate if (cpi->cpi_maxeax == 0) { 28240Sstevel@tonic-gate mutex_exit(&cpu_node_lock); 28250Sstevel@tonic-gate return; 28260Sstevel@tonic-gate } 28270Sstevel@tonic-gate 28280Sstevel@tonic-gate /* 28290Sstevel@tonic-gate * family, model, and step 28300Sstevel@tonic-gate */ 28310Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 28320Sstevel@tonic-gate "family", CPI_FAMILY(cpi)); 28330Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 28340Sstevel@tonic-gate "cpu-model", CPI_MODEL(cpi)); 28350Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 28360Sstevel@tonic-gate "stepping-id", CPI_STEP(cpi)); 28370Sstevel@tonic-gate 28380Sstevel@tonic-gate /* type */ 28390Sstevel@tonic-gate 28400Sstevel@tonic-gate switch (cpi->cpi_vendor) { 28410Sstevel@tonic-gate case X86_VENDOR_Intel: 28420Sstevel@tonic-gate create = 1; 28430Sstevel@tonic-gate break; 28440Sstevel@tonic-gate default: 28450Sstevel@tonic-gate create = 0; 28460Sstevel@tonic-gate break; 28470Sstevel@tonic-gate } 28480Sstevel@tonic-gate if (create) 28490Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 28500Sstevel@tonic-gate "type", CPI_TYPE(cpi)); 28510Sstevel@tonic-gate 28520Sstevel@tonic-gate /* ext-family */ 28530Sstevel@tonic-gate 28540Sstevel@tonic-gate switch (cpi->cpi_vendor) { 28550Sstevel@tonic-gate case X86_VENDOR_Intel: 28560Sstevel@tonic-gate case X86_VENDOR_AMD: 28570Sstevel@tonic-gate create = cpi->cpi_family >= 0xf; 28580Sstevel@tonic-gate break; 28590Sstevel@tonic-gate default: 28600Sstevel@tonic-gate create = 0; 28610Sstevel@tonic-gate break; 28620Sstevel@tonic-gate } 28630Sstevel@tonic-gate if (create) 28640Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 28650Sstevel@tonic-gate "ext-family", CPI_FAMILY_XTD(cpi)); 28660Sstevel@tonic-gate 28670Sstevel@tonic-gate /* ext-model */ 28680Sstevel@tonic-gate 28690Sstevel@tonic-gate switch (cpi->cpi_vendor) { 28700Sstevel@tonic-gate case X86_VENDOR_Intel: 28712001Sdmick create = CPI_MODEL(cpi) == 0xf; 28722001Sdmick break; 28730Sstevel@tonic-gate case X86_VENDOR_AMD: 28741582Skchow create = CPI_FAMILY(cpi) == 0xf; 28750Sstevel@tonic-gate break; 28760Sstevel@tonic-gate default: 28770Sstevel@tonic-gate create = 0; 28780Sstevel@tonic-gate break; 28790Sstevel@tonic-gate } 28800Sstevel@tonic-gate if (create) 28810Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 28820Sstevel@tonic-gate "ext-model", CPI_MODEL_XTD(cpi)); 28830Sstevel@tonic-gate 28840Sstevel@tonic-gate /* generation */ 28850Sstevel@tonic-gate 28860Sstevel@tonic-gate switch (cpi->cpi_vendor) { 28870Sstevel@tonic-gate case X86_VENDOR_AMD: 28880Sstevel@tonic-gate /* 28890Sstevel@tonic-gate * AMD K5 model 1 was the first part to support this 28900Sstevel@tonic-gate */ 28910Sstevel@tonic-gate create = cpi->cpi_xmaxeax >= 0x80000001; 28920Sstevel@tonic-gate break; 28930Sstevel@tonic-gate default: 28940Sstevel@tonic-gate create = 0; 28950Sstevel@tonic-gate break; 28960Sstevel@tonic-gate } 28970Sstevel@tonic-gate if (create) 28980Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 28990Sstevel@tonic-gate "generation", BITX((cpi)->cpi_extd[1].cp_eax, 11, 8)); 29000Sstevel@tonic-gate 29010Sstevel@tonic-gate /* brand-id */ 29020Sstevel@tonic-gate 29030Sstevel@tonic-gate switch (cpi->cpi_vendor) { 29040Sstevel@tonic-gate case X86_VENDOR_Intel: 29050Sstevel@tonic-gate /* 29060Sstevel@tonic-gate * brand id first appeared on Pentium III Xeon model 8, 29070Sstevel@tonic-gate * and Celeron model 8 processors and Opteron 29080Sstevel@tonic-gate */ 29090Sstevel@tonic-gate create = cpi->cpi_family > 6 || 29100Sstevel@tonic-gate (cpi->cpi_family == 6 && cpi->cpi_model >= 8); 29110Sstevel@tonic-gate break; 29120Sstevel@tonic-gate case X86_VENDOR_AMD: 29130Sstevel@tonic-gate create = cpi->cpi_family >= 0xf; 29140Sstevel@tonic-gate break; 29150Sstevel@tonic-gate default: 29160Sstevel@tonic-gate create = 0; 29170Sstevel@tonic-gate break; 29180Sstevel@tonic-gate } 29190Sstevel@tonic-gate if (create && cpi->cpi_brandid != 0) { 29200Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 29210Sstevel@tonic-gate "brand-id", cpi->cpi_brandid); 29220Sstevel@tonic-gate } 29230Sstevel@tonic-gate 29240Sstevel@tonic-gate /* chunks, and apic-id */ 29250Sstevel@tonic-gate 29260Sstevel@tonic-gate switch (cpi->cpi_vendor) { 29270Sstevel@tonic-gate /* 29280Sstevel@tonic-gate * first available on Pentium IV and Opteron (K8) 29290Sstevel@tonic-gate */ 29301975Sdmick case X86_VENDOR_Intel: 29311975Sdmick create = IS_NEW_F6(cpi) || cpi->cpi_family >= 0xf; 29321975Sdmick break; 29331975Sdmick case X86_VENDOR_AMD: 29340Sstevel@tonic-gate create = cpi->cpi_family >= 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, 29420Sstevel@tonic-gate "chunks", CPI_CHUNKS(cpi)); 29430Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 29440Sstevel@tonic-gate "apic-id", CPI_APIC_ID(cpi)); 29451414Scindi if (cpi->cpi_chipid >= 0) { 29460Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 29470Sstevel@tonic-gate "chip#", cpi->cpi_chipid); 29481414Scindi (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 29491414Scindi "clog#", cpi->cpi_clogid); 29501414Scindi } 29510Sstevel@tonic-gate } 29520Sstevel@tonic-gate 29530Sstevel@tonic-gate /* cpuid-features */ 29540Sstevel@tonic-gate 29550Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 29560Sstevel@tonic-gate "cpuid-features", CPI_FEATURES_EDX(cpi)); 29570Sstevel@tonic-gate 29580Sstevel@tonic-gate 29590Sstevel@tonic-gate /* cpuid-features-ecx */ 29600Sstevel@tonic-gate 29610Sstevel@tonic-gate switch (cpi->cpi_vendor) { 29620Sstevel@tonic-gate case X86_VENDOR_Intel: 29631975Sdmick create = IS_NEW_F6(cpi) || cpi->cpi_family >= 0xf; 29640Sstevel@tonic-gate break; 29650Sstevel@tonic-gate default: 29660Sstevel@tonic-gate create = 0; 29670Sstevel@tonic-gate break; 29680Sstevel@tonic-gate } 29690Sstevel@tonic-gate if (create) 29700Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 29710Sstevel@tonic-gate "cpuid-features-ecx", CPI_FEATURES_ECX(cpi)); 29720Sstevel@tonic-gate 29730Sstevel@tonic-gate /* ext-cpuid-features */ 29740Sstevel@tonic-gate 29750Sstevel@tonic-gate switch (cpi->cpi_vendor) { 29761975Sdmick case X86_VENDOR_Intel: 29770Sstevel@tonic-gate case X86_VENDOR_AMD: 29780Sstevel@tonic-gate case X86_VENDOR_Cyrix: 29790Sstevel@tonic-gate case X86_VENDOR_TM: 29800Sstevel@tonic-gate case X86_VENDOR_Centaur: 29810Sstevel@tonic-gate create = cpi->cpi_xmaxeax >= 0x80000001; 29820Sstevel@tonic-gate break; 29830Sstevel@tonic-gate default: 29840Sstevel@tonic-gate create = 0; 29850Sstevel@tonic-gate break; 29860Sstevel@tonic-gate } 29871975Sdmick if (create) { 29880Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 29890Sstevel@tonic-gate "ext-cpuid-features", CPI_FEATURES_XTD_EDX(cpi)); 29901975Sdmick (void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi, 29911975Sdmick "ext-cpuid-features-ecx", CPI_FEATURES_XTD_ECX(cpi)); 29921975Sdmick } 29930Sstevel@tonic-gate 29940Sstevel@tonic-gate /* 29950Sstevel@tonic-gate * Brand String first appeared in Intel Pentium IV, AMD K5 29960Sstevel@tonic-gate * model 1, and Cyrix GXm. On earlier models we try and 29970Sstevel@tonic-gate * simulate something similar .. so this string should always 29980Sstevel@tonic-gate * same -something- about the processor, however lame. 29990Sstevel@tonic-gate */ 30000Sstevel@tonic-gate (void) ndi_prop_update_string(DDI_DEV_T_NONE, cpu_devi, 30010Sstevel@tonic-gate "brand-string", cpi->cpi_brandstr); 30020Sstevel@tonic-gate 30030Sstevel@tonic-gate /* 30040Sstevel@tonic-gate * Finally, cache and tlb information 30050Sstevel@tonic-gate */ 30060Sstevel@tonic-gate switch (x86_which_cacheinfo(cpi)) { 30070Sstevel@tonic-gate case X86_VENDOR_Intel: 30080Sstevel@tonic-gate intel_walk_cacheinfo(cpi, cpu_devi, add_cacheent_props); 30090Sstevel@tonic-gate break; 30100Sstevel@tonic-gate case X86_VENDOR_Cyrix: 30110Sstevel@tonic-gate cyrix_walk_cacheinfo(cpi, cpu_devi, add_cacheent_props); 30120Sstevel@tonic-gate break; 30130Sstevel@tonic-gate case X86_VENDOR_AMD: 30140Sstevel@tonic-gate amd_cache_info(cpi, cpu_devi); 30150Sstevel@tonic-gate break; 30160Sstevel@tonic-gate default: 30170Sstevel@tonic-gate break; 30180Sstevel@tonic-gate } 30190Sstevel@tonic-gate 30200Sstevel@tonic-gate mutex_exit(&cpu_node_lock); 30210Sstevel@tonic-gate } 30220Sstevel@tonic-gate 30230Sstevel@tonic-gate struct l2info { 30240Sstevel@tonic-gate int *l2i_csz; 30250Sstevel@tonic-gate int *l2i_lsz; 30260Sstevel@tonic-gate int *l2i_assoc; 30270Sstevel@tonic-gate int l2i_ret; 30280Sstevel@tonic-gate }; 30290Sstevel@tonic-gate 30300Sstevel@tonic-gate /* 30310Sstevel@tonic-gate * A cacheinfo walker that fetches the size, line-size and associativity 30320Sstevel@tonic-gate * of the L2 cache 30330Sstevel@tonic-gate */ 30340Sstevel@tonic-gate static int 30350Sstevel@tonic-gate intel_l2cinfo(void *arg, const struct cachetab *ct) 30360Sstevel@tonic-gate { 30370Sstevel@tonic-gate struct l2info *l2i = arg; 30380Sstevel@tonic-gate int *ip; 30390Sstevel@tonic-gate 30400Sstevel@tonic-gate if (ct->ct_label != l2_cache_str && 30410Sstevel@tonic-gate ct->ct_label != sl2_cache_str) 30420Sstevel@tonic-gate return (0); /* not an L2 -- keep walking */ 30430Sstevel@tonic-gate 30440Sstevel@tonic-gate if ((ip = l2i->l2i_csz) != NULL) 30450Sstevel@tonic-gate *ip = ct->ct_size; 30460Sstevel@tonic-gate if ((ip = l2i->l2i_lsz) != NULL) 30470Sstevel@tonic-gate *ip = ct->ct_line_size; 30480Sstevel@tonic-gate if ((ip = l2i->l2i_assoc) != NULL) 30490Sstevel@tonic-gate *ip = ct->ct_assoc; 30500Sstevel@tonic-gate l2i->l2i_ret = ct->ct_size; 30510Sstevel@tonic-gate return (1); /* was an L2 -- terminate walk */ 30520Sstevel@tonic-gate } 30530Sstevel@tonic-gate 30540Sstevel@tonic-gate static void 30550Sstevel@tonic-gate amd_l2cacheinfo(struct cpuid_info *cpi, struct l2info *l2i) 30560Sstevel@tonic-gate { 30571228Sandrei struct cpuid_regs *cp; 30580Sstevel@tonic-gate uint_t size, assoc; 30590Sstevel@tonic-gate int *ip; 30600Sstevel@tonic-gate 30610Sstevel@tonic-gate if (cpi->cpi_xmaxeax < 0x80000006) 30620Sstevel@tonic-gate return; 30630Sstevel@tonic-gate cp = &cpi->cpi_extd[6]; 30640Sstevel@tonic-gate 30650Sstevel@tonic-gate if ((assoc = BITX(cp->cp_ecx, 15, 12)) != 0 && 30660Sstevel@tonic-gate (size = BITX(cp->cp_ecx, 31, 16)) != 0) { 30670Sstevel@tonic-gate uint_t cachesz = size * 1024; 30680Sstevel@tonic-gate 30690Sstevel@tonic-gate 30700Sstevel@tonic-gate if ((ip = l2i->l2i_csz) != NULL) 30710Sstevel@tonic-gate *ip = cachesz; 30720Sstevel@tonic-gate if ((ip = l2i->l2i_lsz) != NULL) 30730Sstevel@tonic-gate *ip = BITX(cp->cp_ecx, 7, 0); 30740Sstevel@tonic-gate if ((ip = l2i->l2i_assoc) != NULL) 30750Sstevel@tonic-gate *ip = assoc; 30760Sstevel@tonic-gate l2i->l2i_ret = cachesz; 30770Sstevel@tonic-gate } 30780Sstevel@tonic-gate } 30790Sstevel@tonic-gate 30800Sstevel@tonic-gate int 30810Sstevel@tonic-gate getl2cacheinfo(cpu_t *cpu, int *csz, int *lsz, int *assoc) 30820Sstevel@tonic-gate { 30830Sstevel@tonic-gate struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi; 30840Sstevel@tonic-gate struct l2info __l2info, *l2i = &__l2info; 30850Sstevel@tonic-gate 30860Sstevel@tonic-gate l2i->l2i_csz = csz; 30870Sstevel@tonic-gate l2i->l2i_lsz = lsz; 30880Sstevel@tonic-gate l2i->l2i_assoc = assoc; 30890Sstevel@tonic-gate l2i->l2i_ret = -1; 30900Sstevel@tonic-gate 30910Sstevel@tonic-gate switch (x86_which_cacheinfo(cpi)) { 30920Sstevel@tonic-gate case X86_VENDOR_Intel: 30930Sstevel@tonic-gate intel_walk_cacheinfo(cpi, l2i, intel_l2cinfo); 30940Sstevel@tonic-gate break; 30950Sstevel@tonic-gate case X86_VENDOR_Cyrix: 30960Sstevel@tonic-gate cyrix_walk_cacheinfo(cpi, l2i, intel_l2cinfo); 30970Sstevel@tonic-gate break; 30980Sstevel@tonic-gate case X86_VENDOR_AMD: 30990Sstevel@tonic-gate amd_l2cacheinfo(cpi, l2i); 31000Sstevel@tonic-gate break; 31010Sstevel@tonic-gate default: 31020Sstevel@tonic-gate break; 31030Sstevel@tonic-gate } 31040Sstevel@tonic-gate return (l2i->l2i_ret); 31050Sstevel@tonic-gate } 3106