xref: /onnv-gate/usr/src/uts/i86pc/os/cpuid.c (revision 4797:2ebe22df4dfc)
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 /*
1184481Sbholler  * monitor/mwait info.
1194481Sbholler  */
1204481Sbholler struct mwait_info {
1214481Sbholler 	size_t		mon_min;	/* min size to avoid missed wakeups */
1224481Sbholler 	size_t		mon_max;	/* size to avoid false wakeups */
1234481Sbholler 	uint32_t	support;	/* processor support of monitor/mwait */
1244481Sbholler };
1254481Sbholler 
1264481Sbholler /*
1270Sstevel@tonic-gate  * These constants determine how many of the elements of the
1280Sstevel@tonic-gate  * cpuid we cache in the cpuid_info data structure; the
1290Sstevel@tonic-gate  * remaining elements are accessible via the cpuid instruction.
1300Sstevel@tonic-gate  */
1310Sstevel@tonic-gate 
1320Sstevel@tonic-gate #define	NMAX_CPI_STD	6		/* eax = 0 .. 5 */
1330Sstevel@tonic-gate #define	NMAX_CPI_EXTD	9		/* eax = 0x80000000 .. 0x80000008 */
1340Sstevel@tonic-gate 
1350Sstevel@tonic-gate struct cpuid_info {
1360Sstevel@tonic-gate 	uint_t cpi_pass;		/* last pass completed */
1370Sstevel@tonic-gate 	/*
1380Sstevel@tonic-gate 	 * standard function information
1390Sstevel@tonic-gate 	 */
1400Sstevel@tonic-gate 	uint_t cpi_maxeax;		/* fn 0: %eax */
1410Sstevel@tonic-gate 	char cpi_vendorstr[13];		/* fn 0: %ebx:%ecx:%edx */
1420Sstevel@tonic-gate 	uint_t cpi_vendor;		/* enum of cpi_vendorstr */
1430Sstevel@tonic-gate 
1440Sstevel@tonic-gate 	uint_t cpi_family;		/* fn 1: extended family */
1450Sstevel@tonic-gate 	uint_t cpi_model;		/* fn 1: extended model */
1460Sstevel@tonic-gate 	uint_t cpi_step;		/* fn 1: stepping */
1470Sstevel@tonic-gate 	chipid_t cpi_chipid;		/* fn 1: %ebx: chip # on ht cpus */
1480Sstevel@tonic-gate 	uint_t cpi_brandid;		/* fn 1: %ebx: brand ID */
1490Sstevel@tonic-gate 	int cpi_clogid;			/* fn 1: %ebx: thread # */
1501228Sandrei 	uint_t cpi_ncpu_per_chip;	/* fn 1: %ebx: logical cpu count */
1510Sstevel@tonic-gate 	uint8_t cpi_cacheinfo[16];	/* fn 2: intel-style cache desc */
1520Sstevel@tonic-gate 	uint_t cpi_ncache;		/* fn 2: number of elements */
1534606Sesaxe 	uint_t cpi_ncpu_shr_last_cache;	/* fn 4: %eax: ncpus sharing cache */
1544606Sesaxe 	id_t cpi_last_lvl_cacheid;	/* fn 4: %eax: derived cache id */
1554606Sesaxe 	uint_t cpi_std_4_size;		/* fn 4: number of fn 4 elements */
1564606Sesaxe 	struct cpuid_regs **cpi_std_4;	/* fn 4: %ecx == 0 .. fn4_size */
1571228Sandrei 	struct cpuid_regs cpi_std[NMAX_CPI_STD];	/* 0 .. 5 */
1580Sstevel@tonic-gate 	/*
1590Sstevel@tonic-gate 	 * extended function information
1600Sstevel@tonic-gate 	 */
1610Sstevel@tonic-gate 	uint_t cpi_xmaxeax;		/* fn 0x80000000: %eax */
1620Sstevel@tonic-gate 	char cpi_brandstr[49];		/* fn 0x8000000[234] */
1630Sstevel@tonic-gate 	uint8_t cpi_pabits;		/* fn 0x80000006: %eax */
1640Sstevel@tonic-gate 	uint8_t cpi_vabits;		/* fn 0x80000006: %eax */
1651228Sandrei 	struct cpuid_regs cpi_extd[NMAX_CPI_EXTD]; /* 0x8000000[0-8] */
1661228Sandrei 	id_t cpi_coreid;
1671228Sandrei 	uint_t cpi_ncore_per_chip;	/* AMD: fn 0x80000008: %ecx[7-0] */
1681228Sandrei 					/* Intel: fn 4: %eax[31-26] */
1690Sstevel@tonic-gate 	/*
1700Sstevel@tonic-gate 	 * supported feature information
1710Sstevel@tonic-gate 	 */
1723446Smrj 	uint32_t cpi_support[5];
1730Sstevel@tonic-gate #define	STD_EDX_FEATURES	0
1740Sstevel@tonic-gate #define	AMD_EDX_FEATURES	1
1750Sstevel@tonic-gate #define	TM_EDX_FEATURES		2
1760Sstevel@tonic-gate #define	STD_ECX_FEATURES	3
1773446Smrj #define	AMD_ECX_FEATURES	4
1782869Sgavinm 	/*
1792869Sgavinm 	 * Synthesized information, where known.
1802869Sgavinm 	 */
1812869Sgavinm 	uint32_t cpi_chiprev;		/* See X86_CHIPREV_* in x86_archext.h */
1822869Sgavinm 	const char *cpi_chiprevstr;	/* May be NULL if chiprev unknown */
1832869Sgavinm 	uint32_t cpi_socket;		/* Chip package/socket type */
1844481Sbholler 
1854481Sbholler 	struct mwait_info cpi_mwait;	/* fn 5: monitor/mwait info */
1860Sstevel@tonic-gate };
1870Sstevel@tonic-gate 
1880Sstevel@tonic-gate 
1890Sstevel@tonic-gate static struct cpuid_info cpuid_info0;
1900Sstevel@tonic-gate 
1910Sstevel@tonic-gate /*
1920Sstevel@tonic-gate  * These bit fields are defined by the Intel Application Note AP-485
1930Sstevel@tonic-gate  * "Intel Processor Identification and the CPUID Instruction"
1940Sstevel@tonic-gate  */
1950Sstevel@tonic-gate #define	CPI_FAMILY_XTD(cpi)	BITX((cpi)->cpi_std[1].cp_eax, 27, 20)
1960Sstevel@tonic-gate #define	CPI_MODEL_XTD(cpi)	BITX((cpi)->cpi_std[1].cp_eax, 19, 16)
1970Sstevel@tonic-gate #define	CPI_TYPE(cpi)		BITX((cpi)->cpi_std[1].cp_eax, 13, 12)
1980Sstevel@tonic-gate #define	CPI_FAMILY(cpi)		BITX((cpi)->cpi_std[1].cp_eax, 11, 8)
1990Sstevel@tonic-gate #define	CPI_STEP(cpi)		BITX((cpi)->cpi_std[1].cp_eax, 3, 0)
2000Sstevel@tonic-gate #define	CPI_MODEL(cpi)		BITX((cpi)->cpi_std[1].cp_eax, 7, 4)
2010Sstevel@tonic-gate 
2020Sstevel@tonic-gate #define	CPI_FEATURES_EDX(cpi)		((cpi)->cpi_std[1].cp_edx)
2030Sstevel@tonic-gate #define	CPI_FEATURES_ECX(cpi)		((cpi)->cpi_std[1].cp_ecx)
2040Sstevel@tonic-gate #define	CPI_FEATURES_XTD_EDX(cpi)	((cpi)->cpi_extd[1].cp_edx)
2050Sstevel@tonic-gate #define	CPI_FEATURES_XTD_ECX(cpi)	((cpi)->cpi_extd[1].cp_ecx)
2060Sstevel@tonic-gate 
2070Sstevel@tonic-gate #define	CPI_BRANDID(cpi)	BITX((cpi)->cpi_std[1].cp_ebx, 7, 0)
2080Sstevel@tonic-gate #define	CPI_CHUNKS(cpi)		BITX((cpi)->cpi_std[1].cp_ebx, 15, 7)
2090Sstevel@tonic-gate #define	CPI_CPU_COUNT(cpi)	BITX((cpi)->cpi_std[1].cp_ebx, 23, 16)
2100Sstevel@tonic-gate #define	CPI_APIC_ID(cpi)	BITX((cpi)->cpi_std[1].cp_ebx, 31, 24)
2110Sstevel@tonic-gate 
2120Sstevel@tonic-gate #define	CPI_MAXEAX_MAX		0x100		/* sanity control */
2130Sstevel@tonic-gate #define	CPI_XMAXEAX_MAX		0x80000100
2144606Sesaxe #define	CPI_FN4_ECX_MAX		0x20		/* sanity: max fn 4 levels */
2154606Sesaxe 
2164606Sesaxe /*
2174606Sesaxe  * Function 4 (Deterministic Cache Parameters) macros
2184606Sesaxe  * Defined by Intel Application Note AP-485
2194606Sesaxe  */
2204606Sesaxe #define	CPI_NUM_CORES(regs)		BITX((regs)->cp_eax, 31, 26)
2214606Sesaxe #define	CPI_NTHR_SHR_CACHE(regs)	BITX((regs)->cp_eax, 25, 14)
2224606Sesaxe #define	CPI_FULL_ASSOC_CACHE(regs)	BITX((regs)->cp_eax, 9, 9)
2234606Sesaxe #define	CPI_SELF_INIT_CACHE(regs)	BITX((regs)->cp_eax, 8, 8)
2244606Sesaxe #define	CPI_CACHE_LVL(regs)		BITX((regs)->cp_eax, 7, 5)
2254606Sesaxe #define	CPI_CACHE_TYPE(regs)		BITX((regs)->cp_eax, 4, 0)
2264606Sesaxe 
2274606Sesaxe #define	CPI_CACHE_WAYS(regs)		BITX((regs)->cp_ebx, 31, 22)
2284606Sesaxe #define	CPI_CACHE_PARTS(regs)		BITX((regs)->cp_ebx, 21, 12)
2294606Sesaxe #define	CPI_CACHE_COH_LN_SZ(regs)	BITX((regs)->cp_ebx, 11, 0)
2304606Sesaxe 
2314606Sesaxe #define	CPI_CACHE_SETS(regs)		BITX((regs)->cp_ecx, 31, 0)
2324606Sesaxe 
2334606Sesaxe #define	CPI_PREFCH_STRIDE(regs)		BITX((regs)->cp_edx, 9, 0)
2344606Sesaxe 
2350Sstevel@tonic-gate 
2360Sstevel@tonic-gate /*
2371975Sdmick  * A couple of shorthand macros to identify "later" P6-family chips
2381975Sdmick  * like the Pentium M and Core.  First, the "older" P6-based stuff
2391975Sdmick  * (loosely defined as "pre-Pentium-4"):
2401975Sdmick  * P6, PII, Mobile PII, PII Xeon, PIII, Mobile PIII, PIII Xeon
2411975Sdmick  */
2421975Sdmick 
2431975Sdmick #define	IS_LEGACY_P6(cpi) (			\
2441975Sdmick 	cpi->cpi_family == 6 && 		\
2451975Sdmick 		(cpi->cpi_model == 1 ||		\
2461975Sdmick 		cpi->cpi_model == 3 ||		\
2471975Sdmick 		cpi->cpi_model == 5 ||		\
2481975Sdmick 		cpi->cpi_model == 6 ||		\
2491975Sdmick 		cpi->cpi_model == 7 ||		\
2501975Sdmick 		cpi->cpi_model == 8 ||		\
2511975Sdmick 		cpi->cpi_model == 0xA ||	\
2521975Sdmick 		cpi->cpi_model == 0xB)		\
2531975Sdmick )
2541975Sdmick 
2551975Sdmick /* A "new F6" is everything with family 6 that's not the above */
2561975Sdmick #define	IS_NEW_F6(cpi) ((cpi->cpi_family == 6) && !IS_LEGACY_P6(cpi))
2571975Sdmick 
2581975Sdmick /*
2592869Sgavinm  * AMD family 0xf socket types.
2602869Sgavinm  * First index is 0 for revs B thru E, 1 for F and G.
2612869Sgavinm  * Second index by (model & 0x3)
2622869Sgavinm  */
2632869Sgavinm static uint32_t amd_skts[2][4] = {
2642869Sgavinm 	{
2652869Sgavinm 		X86_SOCKET_754,		/* 0b00 */
2662869Sgavinm 		X86_SOCKET_940,		/* 0b01 */
2672869Sgavinm 		X86_SOCKET_754,		/* 0b10 */
2682869Sgavinm 		X86_SOCKET_939		/* 0b11 */
2692869Sgavinm 	},
2702869Sgavinm 	{
2712869Sgavinm 		X86_SOCKET_S1g1,	/* 0b00 */
2722869Sgavinm 		X86_SOCKET_F1207,	/* 0b01 */
2732869Sgavinm 		X86_SOCKET_UNKNOWN,	/* 0b10 */
2742869Sgavinm 		X86_SOCKET_AM2		/* 0b11 */
2752869Sgavinm 	}
2762869Sgavinm };
2772869Sgavinm 
2782869Sgavinm /*
2792869Sgavinm  * Table for mapping AMD Family 0xf model/stepping combination to
2802869Sgavinm  * chip "revision" and socket type.  Only rm_family 0xf is used at the
2812869Sgavinm  * moment, but AMD family 0x10 will extend the exsiting revision names
2822869Sgavinm  * so will likely also use this table.
2832869Sgavinm  *
2842869Sgavinm  * The first member of this array that matches a given family, extended model
2852869Sgavinm  * plus model range, and stepping range will be considered a match.
2862869Sgavinm  */
2872869Sgavinm static const struct amd_rev_mapent {
2882869Sgavinm 	uint_t rm_family;
2892869Sgavinm 	uint_t rm_modello;
2902869Sgavinm 	uint_t rm_modelhi;
2912869Sgavinm 	uint_t rm_steplo;
2922869Sgavinm 	uint_t rm_stephi;
2932869Sgavinm 	uint32_t rm_chiprev;
2942869Sgavinm 	const char *rm_chiprevstr;
2952869Sgavinm 	int rm_sktidx;
2962869Sgavinm } amd_revmap[] = {
2972869Sgavinm 	/*
2982869Sgavinm 	 * Rev B includes model 0x4 stepping 0 and model 0x5 stepping 0 and 1.
2992869Sgavinm 	 */
3002869Sgavinm 	{ 0xf, 0x04, 0x04, 0x0, 0x0, X86_CHIPREV_AMD_F_REV_B, "B", 0 },
3012869Sgavinm 	{ 0xf, 0x05, 0x05, 0x0, 0x1, X86_CHIPREV_AMD_F_REV_B, "B", 0 },
3022869Sgavinm 	/*
3032869Sgavinm 	 * Rev C0 includes model 0x4 stepping 8 and model 0x5 stepping 8
3042869Sgavinm 	 */
3052869Sgavinm 	{ 0xf, 0x04, 0x05, 0x8, 0x8, X86_CHIPREV_AMD_F_REV_C0, "C0", 0 },
3062869Sgavinm 	/*
3072869Sgavinm 	 * Rev CG is the rest of extended model 0x0 - i.e., everything
3082869Sgavinm 	 * but the rev B and C0 combinations covered above.
3092869Sgavinm 	 */
3102869Sgavinm 	{ 0xf, 0x00, 0x0f, 0x0, 0xf, X86_CHIPREV_AMD_F_REV_CG, "CG", 0 },
3112869Sgavinm 	/*
3122869Sgavinm 	 * Rev D has extended model 0x1.
3132869Sgavinm 	 */
3142869Sgavinm 	{ 0xf, 0x10, 0x1f, 0x0, 0xf, X86_CHIPREV_AMD_F_REV_D, "D", 0 },
3152869Sgavinm 	/*
3162869Sgavinm 	 * Rev E has extended model 0x2.
3172869Sgavinm 	 * Extended model 0x3 is unused but available to grow into.
3182869Sgavinm 	 */
3192869Sgavinm 	{ 0xf, 0x20, 0x3f, 0x0, 0xf, X86_CHIPREV_AMD_F_REV_E, "E", 0 },
3202869Sgavinm 	/*
3212869Sgavinm 	 * Rev F has extended models 0x4 and 0x5.
3222869Sgavinm 	 */
3232869Sgavinm 	{ 0xf, 0x40, 0x5f, 0x0, 0xf, X86_CHIPREV_AMD_F_REV_F, "F", 1 },
3242869Sgavinm 	/*
3252869Sgavinm 	 * Rev G has extended model 0x6.
3262869Sgavinm 	 */
3272869Sgavinm 	{ 0xf, 0x60, 0x6f, 0x0, 0xf, X86_CHIPREV_AMD_F_REV_G, "G", 1 },
3282869Sgavinm };
3292869Sgavinm 
3304481Sbholler /*
3314481Sbholler  * Info for monitor/mwait idle loop.
3324481Sbholler  *
3334481Sbholler  * See cpuid section of "Intel 64 and IA-32 Architectures Software Developer's
3344481Sbholler  * Manual Volume 2A: Instruction Set Reference, A-M" #25366-022US, November
3354481Sbholler  * 2006.
3364481Sbholler  * See MONITOR/MWAIT section of "AMD64 Architecture Programmer's Manual
3374481Sbholler  * Documentation Updates" #33633, Rev 2.05, December 2006.
3384481Sbholler  */
3394481Sbholler #define	MWAIT_SUPPORT		(0x00000001)	/* mwait supported */
3404481Sbholler #define	MWAIT_EXTENSIONS	(0x00000002)	/* extenstion supported */
3414481Sbholler #define	MWAIT_ECX_INT_ENABLE	(0x00000004)	/* ecx 1 extension supported */
3424481Sbholler #define	MWAIT_SUPPORTED(cpi)	((cpi)->cpi_std[1].cp_ecx & CPUID_INTC_ECX_MON)
3434481Sbholler #define	MWAIT_INT_ENABLE(cpi)	((cpi)->cpi_std[5].cp_ecx & 0x2)
3444481Sbholler #define	MWAIT_EXTENSION(cpi)	((cpi)->cpi_std[5].cp_ecx & 0x1)
3454481Sbholler #define	MWAIT_SIZE_MIN(cpi)	BITX((cpi)->cpi_std[5].cp_eax, 15, 0)
3464481Sbholler #define	MWAIT_SIZE_MAX(cpi)	BITX((cpi)->cpi_std[5].cp_ebx, 15, 0)
3474481Sbholler /*
3484481Sbholler  * Number of sub-cstates for a given c-state.
3494481Sbholler  */
3504481Sbholler #define	MWAIT_NUM_SUBC_STATES(cpi, c_state)			\
3514481Sbholler 	BITX((cpi)->cpi_std[5].cp_edx, c_state + 3, c_state)
3524481Sbholler 
353*4797Sksadhukh static void intel_cpuid_4_cache_info(void *, struct cpuid_info *);
354*4797Sksadhukh 
3552869Sgavinm static void
3562869Sgavinm synth_amd_info(struct cpuid_info *cpi)
3572869Sgavinm {
3582869Sgavinm 	const struct amd_rev_mapent *rmp;
3592869Sgavinm 	uint_t family, model, step;
3602869Sgavinm 	int i;
3612869Sgavinm 
3622869Sgavinm 	/*
3632869Sgavinm 	 * Currently only AMD family 0xf uses these fields.
3642869Sgavinm 	 */
3652869Sgavinm 	if (cpi->cpi_family != 0xf)
3662869Sgavinm 		return;
3672869Sgavinm 
3682869Sgavinm 	family = cpi->cpi_family;
3692869Sgavinm 	model = cpi->cpi_model;
3702869Sgavinm 	step = cpi->cpi_step;
3712869Sgavinm 
3722869Sgavinm 	for (i = 0, rmp = amd_revmap; i < sizeof (amd_revmap) / sizeof (*rmp);
3732869Sgavinm 	    i++, rmp++) {
3742869Sgavinm 		if (family == rmp->rm_family &&
3752869Sgavinm 		    model >= rmp->rm_modello && model <= rmp->rm_modelhi &&
3762869Sgavinm 		    step >= rmp->rm_steplo && step <= rmp->rm_stephi) {
3772869Sgavinm 			cpi->cpi_chiprev = rmp->rm_chiprev;
3782869Sgavinm 			cpi->cpi_chiprevstr = rmp->rm_chiprevstr;
3792869Sgavinm 			cpi->cpi_socket = amd_skts[rmp->rm_sktidx][model & 0x3];
3802869Sgavinm 			return;
3812869Sgavinm 		}
3822869Sgavinm 	}
3832869Sgavinm }
3842869Sgavinm 
3852869Sgavinm static void
3862869Sgavinm synth_info(struct cpuid_info *cpi)
3872869Sgavinm {
3882869Sgavinm 	cpi->cpi_chiprev = X86_CHIPREV_UNKNOWN;
3892869Sgavinm 	cpi->cpi_chiprevstr = "Unknown";
3902869Sgavinm 	cpi->cpi_socket = X86_SOCKET_UNKNOWN;
3912869Sgavinm 
3922869Sgavinm 	switch (cpi->cpi_vendor) {
3932869Sgavinm 	case X86_VENDOR_AMD:
3942869Sgavinm 		synth_amd_info(cpi);
3952869Sgavinm 		break;
3962869Sgavinm 
3972869Sgavinm 	default:
3982869Sgavinm 		break;
3992869Sgavinm 
4002869Sgavinm 	}
4012869Sgavinm }
4022869Sgavinm 
4032869Sgavinm /*
4043446Smrj  * Apply up various platform-dependent restrictions where the
4053446Smrj  * underlying platform restrictions mean the CPU can be marked
4063446Smrj  * as less capable than its cpuid instruction would imply.
4073446Smrj  */
4083446Smrj 
4093446Smrj #define	platform_cpuid_mangle(vendor, eax, cp)	/* nothing */
4103446Smrj 
4113446Smrj /*
4120Sstevel@tonic-gate  *  Some undocumented ways of patching the results of the cpuid
4130Sstevel@tonic-gate  *  instruction to permit running Solaris 10 on future cpus that
4140Sstevel@tonic-gate  *  we don't currently support.  Could be set to non-zero values
4150Sstevel@tonic-gate  *  via settings in eeprom.
4160Sstevel@tonic-gate  */
4170Sstevel@tonic-gate 
4180Sstevel@tonic-gate uint32_t cpuid_feature_ecx_include;
4190Sstevel@tonic-gate uint32_t cpuid_feature_ecx_exclude;
4200Sstevel@tonic-gate uint32_t cpuid_feature_edx_include;
4210Sstevel@tonic-gate uint32_t cpuid_feature_edx_exclude;
4220Sstevel@tonic-gate 
4233446Smrj void
4243446Smrj cpuid_alloc_space(cpu_t *cpu)
4253446Smrj {
4263446Smrj 	/*
4273446Smrj 	 * By convention, cpu0 is the boot cpu, which is set up
4283446Smrj 	 * before memory allocation is available.  All other cpus get
4293446Smrj 	 * their cpuid_info struct allocated here.
4303446Smrj 	 */
4313446Smrj 	ASSERT(cpu->cpu_id != 0);
4323446Smrj 	cpu->cpu_m.mcpu_cpi =
4333446Smrj 	    kmem_zalloc(sizeof (*cpu->cpu_m.mcpu_cpi), KM_SLEEP);
4343446Smrj }
4353446Smrj 
4363446Smrj void
4373446Smrj cpuid_free_space(cpu_t *cpu)
4383446Smrj {
4394606Sesaxe 	struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi;
4404606Sesaxe 	int i;
4414606Sesaxe 
4423446Smrj 	ASSERT(cpu->cpu_id != 0);
4434606Sesaxe 
4444606Sesaxe 	/*
4454606Sesaxe 	 * Free up any function 4 related dynamic storage
4464606Sesaxe 	 */
4474606Sesaxe 	for (i = 1; i < cpi->cpi_std_4_size; i++)
4484606Sesaxe 		kmem_free(cpi->cpi_std_4[i], sizeof (struct cpuid_regs));
4494606Sesaxe 	if (cpi->cpi_std_4_size > 0)
4504606Sesaxe 		kmem_free(cpi->cpi_std_4,
4514606Sesaxe 		    cpi->cpi_std_4_size * sizeof (struct cpuid_regs *));
4524606Sesaxe 
4533446Smrj 	kmem_free(cpu->cpu_m.mcpu_cpi, sizeof (*cpu->cpu_m.mcpu_cpi));
4543446Smrj }
4553446Smrj 
4560Sstevel@tonic-gate uint_t
4570Sstevel@tonic-gate cpuid_pass1(cpu_t *cpu)
4580Sstevel@tonic-gate {
4590Sstevel@tonic-gate 	uint32_t mask_ecx, mask_edx;
4600Sstevel@tonic-gate 	uint_t feature = X86_CPUID;
4610Sstevel@tonic-gate 	struct cpuid_info *cpi;
4621228Sandrei 	struct cpuid_regs *cp;
4630Sstevel@tonic-gate 	int xcpuid;
4640Sstevel@tonic-gate 
4653446Smrj 
4660Sstevel@tonic-gate 	/*
4673446Smrj 	 * Space statically allocated for cpu0, ensure pointer is set
4680Sstevel@tonic-gate 	 */
4690Sstevel@tonic-gate 	if (cpu->cpu_id == 0)
4703446Smrj 		cpu->cpu_m.mcpu_cpi = &cpuid_info0;
4713446Smrj 	cpi = cpu->cpu_m.mcpu_cpi;
4723446Smrj 	ASSERT(cpi != NULL);
4730Sstevel@tonic-gate 	cp = &cpi->cpi_std[0];
4741228Sandrei 	cp->cp_eax = 0;
4751228Sandrei 	cpi->cpi_maxeax = __cpuid_insn(cp);
4760Sstevel@tonic-gate 	{
4770Sstevel@tonic-gate 		uint32_t *iptr = (uint32_t *)cpi->cpi_vendorstr;
4780Sstevel@tonic-gate 		*iptr++ = cp->cp_ebx;
4790Sstevel@tonic-gate 		*iptr++ = cp->cp_edx;
4800Sstevel@tonic-gate 		*iptr++ = cp->cp_ecx;
4810Sstevel@tonic-gate 		*(char *)&cpi->cpi_vendorstr[12] = '\0';
4820Sstevel@tonic-gate 	}
4830Sstevel@tonic-gate 
4840Sstevel@tonic-gate 	/*
4850Sstevel@tonic-gate 	 * Map the vendor string to a type code
4860Sstevel@tonic-gate 	 */
4870Sstevel@tonic-gate 	if (strcmp(cpi->cpi_vendorstr, "GenuineIntel") == 0)
4880Sstevel@tonic-gate 		cpi->cpi_vendor = X86_VENDOR_Intel;
4890Sstevel@tonic-gate 	else if (strcmp(cpi->cpi_vendorstr, "AuthenticAMD") == 0)
4900Sstevel@tonic-gate 		cpi->cpi_vendor = X86_VENDOR_AMD;
4910Sstevel@tonic-gate 	else if (strcmp(cpi->cpi_vendorstr, "GenuineTMx86") == 0)
4920Sstevel@tonic-gate 		cpi->cpi_vendor = X86_VENDOR_TM;
4930Sstevel@tonic-gate 	else if (strcmp(cpi->cpi_vendorstr, CyrixInstead) == 0)
4940Sstevel@tonic-gate 		/*
4950Sstevel@tonic-gate 		 * CyrixInstead is a variable used by the Cyrix detection code
4960Sstevel@tonic-gate 		 * in locore.
4970Sstevel@tonic-gate 		 */
4980Sstevel@tonic-gate 		cpi->cpi_vendor = X86_VENDOR_Cyrix;
4990Sstevel@tonic-gate 	else if (strcmp(cpi->cpi_vendorstr, "UMC UMC UMC ") == 0)
5000Sstevel@tonic-gate 		cpi->cpi_vendor = X86_VENDOR_UMC;
5010Sstevel@tonic-gate 	else if (strcmp(cpi->cpi_vendorstr, "NexGenDriven") == 0)
5020Sstevel@tonic-gate 		cpi->cpi_vendor = X86_VENDOR_NexGen;
5030Sstevel@tonic-gate 	else if (strcmp(cpi->cpi_vendorstr, "CentaurHauls") == 0)
5040Sstevel@tonic-gate 		cpi->cpi_vendor = X86_VENDOR_Centaur;
5050Sstevel@tonic-gate 	else if (strcmp(cpi->cpi_vendorstr, "RiseRiseRise") == 0)
5060Sstevel@tonic-gate 		cpi->cpi_vendor = X86_VENDOR_Rise;
5070Sstevel@tonic-gate 	else if (strcmp(cpi->cpi_vendorstr, "SiS SiS SiS ") == 0)
5080Sstevel@tonic-gate 		cpi->cpi_vendor = X86_VENDOR_SiS;
5090Sstevel@tonic-gate 	else if (strcmp(cpi->cpi_vendorstr, "Geode by NSC") == 0)
5100Sstevel@tonic-gate 		cpi->cpi_vendor = X86_VENDOR_NSC;
5110Sstevel@tonic-gate 	else
5120Sstevel@tonic-gate 		cpi->cpi_vendor = X86_VENDOR_IntelClone;
5130Sstevel@tonic-gate 
5140Sstevel@tonic-gate 	x86_vendor = cpi->cpi_vendor; /* for compatibility */
5150Sstevel@tonic-gate 
5160Sstevel@tonic-gate 	/*
5170Sstevel@tonic-gate 	 * Limit the range in case of weird hardware
5180Sstevel@tonic-gate 	 */
5190Sstevel@tonic-gate 	if (cpi->cpi_maxeax > CPI_MAXEAX_MAX)
5200Sstevel@tonic-gate 		cpi->cpi_maxeax = CPI_MAXEAX_MAX;
5210Sstevel@tonic-gate 	if (cpi->cpi_maxeax < 1)
5220Sstevel@tonic-gate 		goto pass1_done;
5230Sstevel@tonic-gate 
5240Sstevel@tonic-gate 	cp = &cpi->cpi_std[1];
5251228Sandrei 	cp->cp_eax = 1;
5261228Sandrei 	(void) __cpuid_insn(cp);
5270Sstevel@tonic-gate 
5280Sstevel@tonic-gate 	/*
5290Sstevel@tonic-gate 	 * Extract identifying constants for easy access.
5300Sstevel@tonic-gate 	 */
5310Sstevel@tonic-gate 	cpi->cpi_model = CPI_MODEL(cpi);
5320Sstevel@tonic-gate 	cpi->cpi_family = CPI_FAMILY(cpi);
5330Sstevel@tonic-gate 
5341975Sdmick 	if (cpi->cpi_family == 0xf)
5350Sstevel@tonic-gate 		cpi->cpi_family += CPI_FAMILY_XTD(cpi);
5361975Sdmick 
5372001Sdmick 	/*
5384265Skchow 	 * Beware: AMD uses "extended model" iff base *FAMILY* == 0xf.
5392001Sdmick 	 * Intel, and presumably everyone else, uses model == 0xf, as
5402001Sdmick 	 * one would expect (max value means possible overflow).  Sigh.
5412001Sdmick 	 */
5422001Sdmick 
5432001Sdmick 	switch (cpi->cpi_vendor) {
5442001Sdmick 	case X86_VENDOR_AMD:
5454265Skchow 		if (CPI_FAMILY(cpi) == 0xf)
5462001Sdmick 			cpi->cpi_model += CPI_MODEL_XTD(cpi) << 4;
5472001Sdmick 		break;
5482001Sdmick 	default:
5492001Sdmick 		if (cpi->cpi_model == 0xf)
5502001Sdmick 			cpi->cpi_model += CPI_MODEL_XTD(cpi) << 4;
5512001Sdmick 		break;
5522001Sdmick 	}
5530Sstevel@tonic-gate 
5540Sstevel@tonic-gate 	cpi->cpi_step = CPI_STEP(cpi);
5550Sstevel@tonic-gate 	cpi->cpi_brandid = CPI_BRANDID(cpi);
5560Sstevel@tonic-gate 
5570Sstevel@tonic-gate 	/*
5580Sstevel@tonic-gate 	 * *default* assumptions:
5590Sstevel@tonic-gate 	 * - believe %edx feature word
5600Sstevel@tonic-gate 	 * - ignore %ecx feature word
5610Sstevel@tonic-gate 	 * - 32-bit virtual and physical addressing
5620Sstevel@tonic-gate 	 */
5630Sstevel@tonic-gate 	mask_edx = 0xffffffff;
5640Sstevel@tonic-gate 	mask_ecx = 0;
5650Sstevel@tonic-gate 
5660Sstevel@tonic-gate 	cpi->cpi_pabits = cpi->cpi_vabits = 32;
5670Sstevel@tonic-gate 
5680Sstevel@tonic-gate 	switch (cpi->cpi_vendor) {
5690Sstevel@tonic-gate 	case X86_VENDOR_Intel:
5700Sstevel@tonic-gate 		if (cpi->cpi_family == 5)
5710Sstevel@tonic-gate 			x86_type = X86_TYPE_P5;
5721975Sdmick 		else if (IS_LEGACY_P6(cpi)) {
5730Sstevel@tonic-gate 			x86_type = X86_TYPE_P6;
5740Sstevel@tonic-gate 			pentiumpro_bug4046376 = 1;
5750Sstevel@tonic-gate 			pentiumpro_bug4064495 = 1;
5760Sstevel@tonic-gate 			/*
5770Sstevel@tonic-gate 			 * Clear the SEP bit when it was set erroneously
5780Sstevel@tonic-gate 			 */
5790Sstevel@tonic-gate 			if (cpi->cpi_model < 3 && cpi->cpi_step < 3)
5800Sstevel@tonic-gate 				cp->cp_edx &= ~CPUID_INTC_EDX_SEP;
5811975Sdmick 		} else if (IS_NEW_F6(cpi) || cpi->cpi_family == 0xf) {
5820Sstevel@tonic-gate 			x86_type = X86_TYPE_P4;
5830Sstevel@tonic-gate 			/*
5840Sstevel@tonic-gate 			 * We don't currently depend on any of the %ecx
5850Sstevel@tonic-gate 			 * features until Prescott, so we'll only check
5860Sstevel@tonic-gate 			 * this from P4 onwards.  We might want to revisit
5870Sstevel@tonic-gate 			 * that idea later.
5880Sstevel@tonic-gate 			 */
5890Sstevel@tonic-gate 			mask_ecx = 0xffffffff;
5900Sstevel@tonic-gate 		} else if (cpi->cpi_family > 0xf)
5910Sstevel@tonic-gate 			mask_ecx = 0xffffffff;
5924636Sbholler 		/*
5934636Sbholler 		 * We don't support MONITOR/MWAIT if leaf 5 is not available
5944636Sbholler 		 * to obtain the monitor linesize.
5954636Sbholler 		 */
5964636Sbholler 		if (cpi->cpi_maxeax < 5)
5974636Sbholler 			mask_ecx &= ~CPUID_INTC_ECX_MON;
5980Sstevel@tonic-gate 		break;
5990Sstevel@tonic-gate 	case X86_VENDOR_IntelClone:
6000Sstevel@tonic-gate 	default:
6010Sstevel@tonic-gate 		break;
6020Sstevel@tonic-gate 	case X86_VENDOR_AMD:
6030Sstevel@tonic-gate #if defined(OPTERON_ERRATUM_108)
6040Sstevel@tonic-gate 		if (cpi->cpi_family == 0xf && cpi->cpi_model == 0xe) {
6050Sstevel@tonic-gate 			cp->cp_eax = (0xf0f & cp->cp_eax) | 0xc0;
6060Sstevel@tonic-gate 			cpi->cpi_model = 0xc;
6070Sstevel@tonic-gate 		} else
6080Sstevel@tonic-gate #endif
6090Sstevel@tonic-gate 		if (cpi->cpi_family == 5) {
6100Sstevel@tonic-gate 			/*
6110Sstevel@tonic-gate 			 * AMD K5 and K6
6120Sstevel@tonic-gate 			 *
6130Sstevel@tonic-gate 			 * These CPUs have an incomplete implementation
6140Sstevel@tonic-gate 			 * of MCA/MCE which we mask away.
6150Sstevel@tonic-gate 			 */
6161228Sandrei 			mask_edx &= ~(CPUID_INTC_EDX_MCE | CPUID_INTC_EDX_MCA);
6171228Sandrei 
6181228Sandrei 			/*
6191228Sandrei 			 * Model 0 uses the wrong (APIC) bit
6201228Sandrei 			 * to indicate PGE.  Fix it here.
6211228Sandrei 			 */
6220Sstevel@tonic-gate 			if (cpi->cpi_model == 0) {
6230Sstevel@tonic-gate 				if (cp->cp_edx & 0x200) {
6240Sstevel@tonic-gate 					cp->cp_edx &= ~0x200;
6250Sstevel@tonic-gate 					cp->cp_edx |= CPUID_INTC_EDX_PGE;
6260Sstevel@tonic-gate 				}
6271228Sandrei 			}
6281228Sandrei 
6291228Sandrei 			/*
6301228Sandrei 			 * Early models had problems w/ MMX; disable.
6311228Sandrei 			 */
6321228Sandrei 			if (cpi->cpi_model < 6)
6331228Sandrei 				mask_edx &= ~CPUID_INTC_EDX_MMX;
6341228Sandrei 		}
6351228Sandrei 
6361228Sandrei 		/*
6371228Sandrei 		 * For newer families, SSE3 and CX16, at least, are valid;
6381228Sandrei 		 * enable all
6391228Sandrei 		 */
6401228Sandrei 		if (cpi->cpi_family >= 0xf)
641771Sdmick 			mask_ecx = 0xffffffff;
6424636Sbholler 		/*
6434636Sbholler 		 * We don't support MONITOR/MWAIT if leaf 5 is not available
6444636Sbholler 		 * to obtain the monitor linesize.
6454636Sbholler 		 */
6464636Sbholler 		if (cpi->cpi_maxeax < 5)
6474636Sbholler 			mask_ecx &= ~CPUID_INTC_ECX_MON;
6480Sstevel@tonic-gate 		break;
6490Sstevel@tonic-gate 	case X86_VENDOR_TM:
6500Sstevel@tonic-gate 		/*
6510Sstevel@tonic-gate 		 * workaround the NT workaround in CMS 4.1
6520Sstevel@tonic-gate 		 */
6530Sstevel@tonic-gate 		if (cpi->cpi_family == 5 && cpi->cpi_model == 4 &&
6540Sstevel@tonic-gate 		    (cpi->cpi_step == 2 || cpi->cpi_step == 3))
6550Sstevel@tonic-gate 			cp->cp_edx |= CPUID_INTC_EDX_CX8;
6560Sstevel@tonic-gate 		break;
6570Sstevel@tonic-gate 	case X86_VENDOR_Centaur:
6580Sstevel@tonic-gate 		/*
6590Sstevel@tonic-gate 		 * workaround the NT workarounds again
6600Sstevel@tonic-gate 		 */
6610Sstevel@tonic-gate 		if (cpi->cpi_family == 6)
6620Sstevel@tonic-gate 			cp->cp_edx |= CPUID_INTC_EDX_CX8;
6630Sstevel@tonic-gate 		break;
6640Sstevel@tonic-gate 	case X86_VENDOR_Cyrix:
6650Sstevel@tonic-gate 		/*
6660Sstevel@tonic-gate 		 * We rely heavily on the probing in locore
6670Sstevel@tonic-gate 		 * to actually figure out what parts, if any,
6680Sstevel@tonic-gate 		 * of the Cyrix cpuid instruction to believe.
6690Sstevel@tonic-gate 		 */
6700Sstevel@tonic-gate 		switch (x86_type) {
6710Sstevel@tonic-gate 		case X86_TYPE_CYRIX_486:
6720Sstevel@tonic-gate 			mask_edx = 0;
6730Sstevel@tonic-gate 			break;
6740Sstevel@tonic-gate 		case X86_TYPE_CYRIX_6x86:
6750Sstevel@tonic-gate 			mask_edx = 0;
6760Sstevel@tonic-gate 			break;
6770Sstevel@tonic-gate 		case X86_TYPE_CYRIX_6x86L:
6780Sstevel@tonic-gate 			mask_edx =
6790Sstevel@tonic-gate 			    CPUID_INTC_EDX_DE |
6800Sstevel@tonic-gate 			    CPUID_INTC_EDX_CX8;
6810Sstevel@tonic-gate 			break;
6820Sstevel@tonic-gate 		case X86_TYPE_CYRIX_6x86MX:
6830Sstevel@tonic-gate 			mask_edx =
6840Sstevel@tonic-gate 			    CPUID_INTC_EDX_DE |
6850Sstevel@tonic-gate 			    CPUID_INTC_EDX_MSR |
6860Sstevel@tonic-gate 			    CPUID_INTC_EDX_CX8 |
6870Sstevel@tonic-gate 			    CPUID_INTC_EDX_PGE |
6880Sstevel@tonic-gate 			    CPUID_INTC_EDX_CMOV |
6890Sstevel@tonic-gate 			    CPUID_INTC_EDX_MMX;
6900Sstevel@tonic-gate 			break;
6910Sstevel@tonic-gate 		case X86_TYPE_CYRIX_GXm:
6920Sstevel@tonic-gate 			mask_edx =
6930Sstevel@tonic-gate 			    CPUID_INTC_EDX_MSR |
6940Sstevel@tonic-gate 			    CPUID_INTC_EDX_CX8 |
6950Sstevel@tonic-gate 			    CPUID_INTC_EDX_CMOV |
6960Sstevel@tonic-gate 			    CPUID_INTC_EDX_MMX;
6970Sstevel@tonic-gate 			break;
6980Sstevel@tonic-gate 		case X86_TYPE_CYRIX_MediaGX:
6990Sstevel@tonic-gate 			break;
7000Sstevel@tonic-gate 		case X86_TYPE_CYRIX_MII:
7010Sstevel@tonic-gate 		case X86_TYPE_VIA_CYRIX_III:
7020Sstevel@tonic-gate 			mask_edx =
7030Sstevel@tonic-gate 			    CPUID_INTC_EDX_DE |
7040Sstevel@tonic-gate 			    CPUID_INTC_EDX_TSC |
7050Sstevel@tonic-gate 			    CPUID_INTC_EDX_MSR |
7060Sstevel@tonic-gate 			    CPUID_INTC_EDX_CX8 |
7070Sstevel@tonic-gate 			    CPUID_INTC_EDX_PGE |
7080Sstevel@tonic-gate 			    CPUID_INTC_EDX_CMOV |
7090Sstevel@tonic-gate 			    CPUID_INTC_EDX_MMX;
7100Sstevel@tonic-gate 			break;
7110Sstevel@tonic-gate 		default:
7120Sstevel@tonic-gate 			break;
7130Sstevel@tonic-gate 		}
7140Sstevel@tonic-gate 		break;
7150Sstevel@tonic-gate 	}
7160Sstevel@tonic-gate 
7170Sstevel@tonic-gate 	/*
7180Sstevel@tonic-gate 	 * Now we've figured out the masks that determine
7190Sstevel@tonic-gate 	 * which bits we choose to believe, apply the masks
7200Sstevel@tonic-gate 	 * to the feature words, then map the kernel's view
7210Sstevel@tonic-gate 	 * of these feature words into its feature word.
7220Sstevel@tonic-gate 	 */
7230Sstevel@tonic-gate 	cp->cp_edx &= mask_edx;
7240Sstevel@tonic-gate 	cp->cp_ecx &= mask_ecx;
7250Sstevel@tonic-gate 
7260Sstevel@tonic-gate 	/*
7273446Smrj 	 * apply any platform restrictions (we don't call this
7283446Smrj 	 * immediately after __cpuid_insn here, because we need the
7293446Smrj 	 * workarounds applied above first)
7300Sstevel@tonic-gate 	 */
7313446Smrj 	platform_cpuid_mangle(cpi->cpi_vendor, 1, cp);
7320Sstevel@tonic-gate 
7333446Smrj 	/*
7343446Smrj 	 * fold in overrides from the "eeprom" mechanism
7353446Smrj 	 */
7360Sstevel@tonic-gate 	cp->cp_edx |= cpuid_feature_edx_include;
7370Sstevel@tonic-gate 	cp->cp_edx &= ~cpuid_feature_edx_exclude;
7380Sstevel@tonic-gate 
7390Sstevel@tonic-gate 	cp->cp_ecx |= cpuid_feature_ecx_include;
7400Sstevel@tonic-gate 	cp->cp_ecx &= ~cpuid_feature_ecx_exclude;
7410Sstevel@tonic-gate 
7420Sstevel@tonic-gate 	if (cp->cp_edx & CPUID_INTC_EDX_PSE)
7430Sstevel@tonic-gate 		feature |= X86_LARGEPAGE;
7440Sstevel@tonic-gate 	if (cp->cp_edx & CPUID_INTC_EDX_TSC)
7450Sstevel@tonic-gate 		feature |= X86_TSC;
7460Sstevel@tonic-gate 	if (cp->cp_edx & CPUID_INTC_EDX_MSR)
7470Sstevel@tonic-gate 		feature |= X86_MSR;
7480Sstevel@tonic-gate 	if (cp->cp_edx & CPUID_INTC_EDX_MTRR)
7490Sstevel@tonic-gate 		feature |= X86_MTRR;
7500Sstevel@tonic-gate 	if (cp->cp_edx & CPUID_INTC_EDX_PGE)
7510Sstevel@tonic-gate 		feature |= X86_PGE;
7520Sstevel@tonic-gate 	if (cp->cp_edx & CPUID_INTC_EDX_CMOV)
7530Sstevel@tonic-gate 		feature |= X86_CMOV;
7540Sstevel@tonic-gate 	if (cp->cp_edx & CPUID_INTC_EDX_MMX)
7550Sstevel@tonic-gate 		feature |= X86_MMX;
7560Sstevel@tonic-gate 	if ((cp->cp_edx & CPUID_INTC_EDX_MCE) != 0 &&
7570Sstevel@tonic-gate 	    (cp->cp_edx & CPUID_INTC_EDX_MCA) != 0)
7580Sstevel@tonic-gate 		feature |= X86_MCA;
7590Sstevel@tonic-gate 	if (cp->cp_edx & CPUID_INTC_EDX_PAE)
7600Sstevel@tonic-gate 		feature |= X86_PAE;
7610Sstevel@tonic-gate 	if (cp->cp_edx & CPUID_INTC_EDX_CX8)
7620Sstevel@tonic-gate 		feature |= X86_CX8;
7630Sstevel@tonic-gate 	if (cp->cp_ecx & CPUID_INTC_ECX_CX16)
7640Sstevel@tonic-gate 		feature |= X86_CX16;
7650Sstevel@tonic-gate 	if (cp->cp_edx & CPUID_INTC_EDX_PAT)
7660Sstevel@tonic-gate 		feature |= X86_PAT;
7670Sstevel@tonic-gate 	if (cp->cp_edx & CPUID_INTC_EDX_SEP)
7680Sstevel@tonic-gate 		feature |= X86_SEP;
7690Sstevel@tonic-gate 	if (cp->cp_edx & CPUID_INTC_EDX_FXSR) {
7700Sstevel@tonic-gate 		/*
7710Sstevel@tonic-gate 		 * In our implementation, fxsave/fxrstor
7720Sstevel@tonic-gate 		 * are prerequisites before we'll even
7730Sstevel@tonic-gate 		 * try and do SSE things.
7740Sstevel@tonic-gate 		 */
7750Sstevel@tonic-gate 		if (cp->cp_edx & CPUID_INTC_EDX_SSE)
7760Sstevel@tonic-gate 			feature |= X86_SSE;
7770Sstevel@tonic-gate 		if (cp->cp_edx & CPUID_INTC_EDX_SSE2)
7780Sstevel@tonic-gate 			feature |= X86_SSE2;
7790Sstevel@tonic-gate 		if (cp->cp_ecx & CPUID_INTC_ECX_SSE3)
7800Sstevel@tonic-gate 			feature |= X86_SSE3;
7810Sstevel@tonic-gate 	}
7820Sstevel@tonic-gate 	if (cp->cp_edx & CPUID_INTC_EDX_DE)
7833446Smrj 		feature |= X86_DE;
7844481Sbholler 	if (cp->cp_ecx & CPUID_INTC_ECX_MON) {
7854481Sbholler 		cpi->cpi_mwait.support |= MWAIT_SUPPORT;
7864481Sbholler 		feature |= X86_MWAIT;
7874481Sbholler 	}
7880Sstevel@tonic-gate 
7890Sstevel@tonic-gate 	if (feature & X86_PAE)
7900Sstevel@tonic-gate 		cpi->cpi_pabits = 36;
7910Sstevel@tonic-gate 
7920Sstevel@tonic-gate 	/*
7930Sstevel@tonic-gate 	 * Hyperthreading configuration is slightly tricky on Intel
7940Sstevel@tonic-gate 	 * and pure clones, and even trickier on AMD.
7950Sstevel@tonic-gate 	 *
7960Sstevel@tonic-gate 	 * (AMD chose to set the HTT bit on their CMP processors,
7970Sstevel@tonic-gate 	 * even though they're not actually hyperthreaded.  Thus it
7980Sstevel@tonic-gate 	 * takes a bit more work to figure out what's really going
7993446Smrj 	 * on ... see the handling of the CMP_LGCY bit below)
8000Sstevel@tonic-gate 	 */
8010Sstevel@tonic-gate 	if (cp->cp_edx & CPUID_INTC_EDX_HTT) {
8020Sstevel@tonic-gate 		cpi->cpi_ncpu_per_chip = CPI_CPU_COUNT(cpi);
8030Sstevel@tonic-gate 		if (cpi->cpi_ncpu_per_chip > 1)
8040Sstevel@tonic-gate 			feature |= X86_HTT;
8051228Sandrei 	} else {
8061228Sandrei 		cpi->cpi_ncpu_per_chip = 1;
8070Sstevel@tonic-gate 	}
8080Sstevel@tonic-gate 
8090Sstevel@tonic-gate 	/*
8100Sstevel@tonic-gate 	 * Work on the "extended" feature information, doing
8110Sstevel@tonic-gate 	 * some basic initialization for cpuid_pass2()
8120Sstevel@tonic-gate 	 */
8130Sstevel@tonic-gate 	xcpuid = 0;
8140Sstevel@tonic-gate 	switch (cpi->cpi_vendor) {
8150Sstevel@tonic-gate 	case X86_VENDOR_Intel:
8161975Sdmick 		if (IS_NEW_F6(cpi) || cpi->cpi_family >= 0xf)
8170Sstevel@tonic-gate 			xcpuid++;
8180Sstevel@tonic-gate 		break;
8190Sstevel@tonic-gate 	case X86_VENDOR_AMD:
8200Sstevel@tonic-gate 		if (cpi->cpi_family > 5 ||
8210Sstevel@tonic-gate 		    (cpi->cpi_family == 5 && cpi->cpi_model >= 1))
8220Sstevel@tonic-gate 			xcpuid++;
8230Sstevel@tonic-gate 		break;
8240Sstevel@tonic-gate 	case X86_VENDOR_Cyrix:
8250Sstevel@tonic-gate 		/*
8260Sstevel@tonic-gate 		 * Only these Cyrix CPUs are -known- to support
8270Sstevel@tonic-gate 		 * extended cpuid operations.
8280Sstevel@tonic-gate 		 */
8290Sstevel@tonic-gate 		if (x86_type == X86_TYPE_VIA_CYRIX_III ||
8300Sstevel@tonic-gate 		    x86_type == X86_TYPE_CYRIX_GXm)
8310Sstevel@tonic-gate 			xcpuid++;
8320Sstevel@tonic-gate 		break;
8330Sstevel@tonic-gate 	case X86_VENDOR_Centaur:
8340Sstevel@tonic-gate 	case X86_VENDOR_TM:
8350Sstevel@tonic-gate 	default:
8360Sstevel@tonic-gate 		xcpuid++;
8370Sstevel@tonic-gate 		break;
8380Sstevel@tonic-gate 	}
8390Sstevel@tonic-gate 
8400Sstevel@tonic-gate 	if (xcpuid) {
8410Sstevel@tonic-gate 		cp = &cpi->cpi_extd[0];
8421228Sandrei 		cp->cp_eax = 0x80000000;
8431228Sandrei 		cpi->cpi_xmaxeax = __cpuid_insn(cp);
8440Sstevel@tonic-gate 	}
8450Sstevel@tonic-gate 
8460Sstevel@tonic-gate 	if (cpi->cpi_xmaxeax & 0x80000000) {
8470Sstevel@tonic-gate 
8480Sstevel@tonic-gate 		if (cpi->cpi_xmaxeax > CPI_XMAXEAX_MAX)
8490Sstevel@tonic-gate 			cpi->cpi_xmaxeax = CPI_XMAXEAX_MAX;
8500Sstevel@tonic-gate 
8510Sstevel@tonic-gate 		switch (cpi->cpi_vendor) {
8520Sstevel@tonic-gate 		case X86_VENDOR_Intel:
8530Sstevel@tonic-gate 		case X86_VENDOR_AMD:
8540Sstevel@tonic-gate 			if (cpi->cpi_xmaxeax < 0x80000001)
8550Sstevel@tonic-gate 				break;
8560Sstevel@tonic-gate 			cp = &cpi->cpi_extd[1];
8571228Sandrei 			cp->cp_eax = 0x80000001;
8581228Sandrei 			(void) __cpuid_insn(cp);
8593446Smrj 
8600Sstevel@tonic-gate 			if (cpi->cpi_vendor == X86_VENDOR_AMD &&
8610Sstevel@tonic-gate 			    cpi->cpi_family == 5 &&
8620Sstevel@tonic-gate 			    cpi->cpi_model == 6 &&
8630Sstevel@tonic-gate 			    cpi->cpi_step == 6) {
8640Sstevel@tonic-gate 				/*
8650Sstevel@tonic-gate 				 * K6 model 6 uses bit 10 to indicate SYSC
8660Sstevel@tonic-gate 				 * Later models use bit 11. Fix it here.
8670Sstevel@tonic-gate 				 */
8680Sstevel@tonic-gate 				if (cp->cp_edx & 0x400) {
8690Sstevel@tonic-gate 					cp->cp_edx &= ~0x400;
8700Sstevel@tonic-gate 					cp->cp_edx |= CPUID_AMD_EDX_SYSC;
8710Sstevel@tonic-gate 				}
8720Sstevel@tonic-gate 			}
8730Sstevel@tonic-gate 
8743446Smrj 			platform_cpuid_mangle(cpi->cpi_vendor, 0x80000001, cp);
8753446Smrj 
8760Sstevel@tonic-gate 			/*
8770Sstevel@tonic-gate 			 * Compute the additions to the kernel's feature word.
8780Sstevel@tonic-gate 			 */
8790Sstevel@tonic-gate 			if (cp->cp_edx & CPUID_AMD_EDX_NX)
8800Sstevel@tonic-gate 				feature |= X86_NX;
8810Sstevel@tonic-gate 
8824628Skk208521 			if ((cpi->cpi_vendor == X86_VENDOR_AMD) &&
8834628Skk208521 			    (cpi->cpi_std[1].cp_edx & CPUID_INTC_EDX_FXSR) &&
8844628Skk208521 			    (cp->cp_ecx & CPUID_AMD_ECX_SSE4A))
8854628Skk208521 				feature |= X86_SSE4A;
8864628Skk208521 
8870Sstevel@tonic-gate 			/*
8883446Smrj 			 * If both the HTT and CMP_LGCY bits are set,
8891228Sandrei 			 * then we're not actually HyperThreaded.  Read
8901228Sandrei 			 * "AMD CPUID Specification" for more details.
8910Sstevel@tonic-gate 			 */
8920Sstevel@tonic-gate 			if (cpi->cpi_vendor == X86_VENDOR_AMD &&
8931228Sandrei 			    (feature & X86_HTT) &&
8943446Smrj 			    (cp->cp_ecx & CPUID_AMD_ECX_CMP_LGCY)) {
8950Sstevel@tonic-gate 				feature &= ~X86_HTT;
8961228Sandrei 				feature |= X86_CMP;
8971228Sandrei 			}
8983446Smrj #if defined(__amd64)
8990Sstevel@tonic-gate 			/*
9000Sstevel@tonic-gate 			 * It's really tricky to support syscall/sysret in
9010Sstevel@tonic-gate 			 * the i386 kernel; we rely on sysenter/sysexit
9020Sstevel@tonic-gate 			 * instead.  In the amd64 kernel, things are -way-
9030Sstevel@tonic-gate 			 * better.
9040Sstevel@tonic-gate 			 */
9050Sstevel@tonic-gate 			if (cp->cp_edx & CPUID_AMD_EDX_SYSC)
9060Sstevel@tonic-gate 				feature |= X86_ASYSC;
9070Sstevel@tonic-gate 
9080Sstevel@tonic-gate 			/*
9090Sstevel@tonic-gate 			 * While we're thinking about system calls, note
9100Sstevel@tonic-gate 			 * that AMD processors don't support sysenter
9110Sstevel@tonic-gate 			 * in long mode at all, so don't try to program them.
9120Sstevel@tonic-gate 			 */
9130Sstevel@tonic-gate 			if (x86_vendor == X86_VENDOR_AMD)
9140Sstevel@tonic-gate 				feature &= ~X86_SEP;
9150Sstevel@tonic-gate #endif
9163446Smrj 			if (cp->cp_edx & CPUID_AMD_EDX_TSCP)
9173446Smrj 				feature |= X86_TSCP;
9180Sstevel@tonic-gate 			break;
9190Sstevel@tonic-gate 		default:
9200Sstevel@tonic-gate 			break;
9210Sstevel@tonic-gate 		}
9220Sstevel@tonic-gate 
9231228Sandrei 		/*
9241228Sandrei 		 * Get CPUID data about processor cores and hyperthreads.
9251228Sandrei 		 */
9260Sstevel@tonic-gate 		switch (cpi->cpi_vendor) {
9270Sstevel@tonic-gate 		case X86_VENDOR_Intel:
9281228Sandrei 			if (cpi->cpi_maxeax >= 4) {
9291228Sandrei 				cp = &cpi->cpi_std[4];
9301228Sandrei 				cp->cp_eax = 4;
9311228Sandrei 				cp->cp_ecx = 0;
9321228Sandrei 				(void) __cpuid_insn(cp);
9333446Smrj 				platform_cpuid_mangle(cpi->cpi_vendor, 4, cp);
9341228Sandrei 			}
9351228Sandrei 			/*FALLTHROUGH*/
9360Sstevel@tonic-gate 		case X86_VENDOR_AMD:
9370Sstevel@tonic-gate 			if (cpi->cpi_xmaxeax < 0x80000008)
9380Sstevel@tonic-gate 				break;
9390Sstevel@tonic-gate 			cp = &cpi->cpi_extd[8];
9401228Sandrei 			cp->cp_eax = 0x80000008;
9411228Sandrei 			(void) __cpuid_insn(cp);
9423446Smrj 			platform_cpuid_mangle(cpi->cpi_vendor, 0x80000008, cp);
9433446Smrj 
9440Sstevel@tonic-gate 			/*
9450Sstevel@tonic-gate 			 * Virtual and physical address limits from
9460Sstevel@tonic-gate 			 * cpuid override previously guessed values.
9470Sstevel@tonic-gate 			 */
9480Sstevel@tonic-gate 			cpi->cpi_pabits = BITX(cp->cp_eax, 7, 0);
9490Sstevel@tonic-gate 			cpi->cpi_vabits = BITX(cp->cp_eax, 15, 8);
9500Sstevel@tonic-gate 			break;
9510Sstevel@tonic-gate 		default:
9520Sstevel@tonic-gate 			break;
9530Sstevel@tonic-gate 		}
9541228Sandrei 
9554606Sesaxe 		/*
9564606Sesaxe 		 * Derive the number of cores per chip
9574606Sesaxe 		 */
9581228Sandrei 		switch (cpi->cpi_vendor) {
9591228Sandrei 		case X86_VENDOR_Intel:
9601228Sandrei 			if (cpi->cpi_maxeax < 4) {
9611228Sandrei 				cpi->cpi_ncore_per_chip = 1;
9621228Sandrei 				break;
9631228Sandrei 			} else {
9641228Sandrei 				cpi->cpi_ncore_per_chip =
9651228Sandrei 				    BITX((cpi)->cpi_std[4].cp_eax, 31, 26) + 1;
9661228Sandrei 			}
9671228Sandrei 			break;
9681228Sandrei 		case X86_VENDOR_AMD:
9691228Sandrei 			if (cpi->cpi_xmaxeax < 0x80000008) {
9701228Sandrei 				cpi->cpi_ncore_per_chip = 1;
9711228Sandrei 				break;
9721228Sandrei 			} else {
9731228Sandrei 				cpi->cpi_ncore_per_chip =
9741228Sandrei 				    BITX((cpi)->cpi_extd[8].cp_ecx, 7, 0) + 1;
9751228Sandrei 			}
9761228Sandrei 			break;
9771228Sandrei 		default:
9781228Sandrei 			cpi->cpi_ncore_per_chip = 1;
9791228Sandrei 			break;
9801228Sandrei 		}
9810Sstevel@tonic-gate 	}
9820Sstevel@tonic-gate 
9831228Sandrei 	/*
9841228Sandrei 	 * If more than one core, then this processor is CMP.
9851228Sandrei 	 */
9861228Sandrei 	if (cpi->cpi_ncore_per_chip > 1)
9871228Sandrei 		feature |= X86_CMP;
9883446Smrj 
9891228Sandrei 	/*
9901228Sandrei 	 * If the number of cores is the same as the number
9911228Sandrei 	 * of CPUs, then we cannot have HyperThreading.
9921228Sandrei 	 */
9931228Sandrei 	if (cpi->cpi_ncpu_per_chip == cpi->cpi_ncore_per_chip)
9941228Sandrei 		feature &= ~X86_HTT;
9951228Sandrei 
9960Sstevel@tonic-gate 	if ((feature & (X86_HTT | X86_CMP)) == 0) {
9971228Sandrei 		/*
9981228Sandrei 		 * Single-core single-threaded processors.
9991228Sandrei 		 */
10000Sstevel@tonic-gate 		cpi->cpi_chipid = -1;
10010Sstevel@tonic-gate 		cpi->cpi_clogid = 0;
10021228Sandrei 		cpi->cpi_coreid = cpu->cpu_id;
10030Sstevel@tonic-gate 	} else if (cpi->cpi_ncpu_per_chip > 1) {
10041228Sandrei 		uint_t i;
10051228Sandrei 		uint_t chipid_shift = 0;
10061228Sandrei 		uint_t coreid_shift = 0;
10071228Sandrei 		uint_t apic_id = CPI_APIC_ID(cpi);
10081228Sandrei 
10091228Sandrei 		for (i = 1; i < cpi->cpi_ncpu_per_chip; i <<= 1)
10101228Sandrei 			chipid_shift++;
10111228Sandrei 		cpi->cpi_chipid = apic_id >> chipid_shift;
10121228Sandrei 		cpi->cpi_clogid = apic_id & ((1 << chipid_shift) - 1);
10130Sstevel@tonic-gate 
10141228Sandrei 		if (cpi->cpi_vendor == X86_VENDOR_Intel) {
10151228Sandrei 			if (feature & X86_CMP) {
10161228Sandrei 				/*
10171228Sandrei 				 * Multi-core (and possibly multi-threaded)
10181228Sandrei 				 * processors.
10191228Sandrei 				 */
10201228Sandrei 				uint_t ncpu_per_core;
10211228Sandrei 				if (cpi->cpi_ncore_per_chip == 1)
10221228Sandrei 					ncpu_per_core = cpi->cpi_ncpu_per_chip;
10231228Sandrei 				else if (cpi->cpi_ncore_per_chip > 1)
10241228Sandrei 					ncpu_per_core = cpi->cpi_ncpu_per_chip /
10251228Sandrei 					    cpi->cpi_ncore_per_chip;
10261228Sandrei 				/*
10271228Sandrei 				 * 8bit APIC IDs on dual core Pentiums
10281228Sandrei 				 * look like this:
10291228Sandrei 				 *
10301228Sandrei 				 * +-----------------------+------+------+
10311228Sandrei 				 * | Physical Package ID   |  MC  |  HT  |
10321228Sandrei 				 * +-----------------------+------+------+
10331228Sandrei 				 * <------- chipid -------->
10341228Sandrei 				 * <------- coreid --------------->
10351228Sandrei 				 *			   <--- clogid -->
10361228Sandrei 				 *
10371228Sandrei 				 * Where the number of bits necessary to
10381228Sandrei 				 * represent MC and HT fields together equals
10391228Sandrei 				 * to the minimum number of bits necessary to
10401228Sandrei 				 * store the value of cpi->cpi_ncpu_per_chip.
10411228Sandrei 				 * Of those bits, the MC part uses the number
10421228Sandrei 				 * of bits necessary to store the value of
10431228Sandrei 				 * cpi->cpi_ncore_per_chip.
10441228Sandrei 				 */
10451228Sandrei 				for (i = 1; i < ncpu_per_core; i <<= 1)
10461228Sandrei 					coreid_shift++;
10471727Sandrei 				cpi->cpi_coreid = apic_id >> coreid_shift;
10481228Sandrei 			} else if (feature & X86_HTT) {
10491228Sandrei 				/*
10501228Sandrei 				 * Single-core multi-threaded processors.
10511228Sandrei 				 */
10521228Sandrei 				cpi->cpi_coreid = cpi->cpi_chipid;
10531228Sandrei 			}
10541228Sandrei 		} else if (cpi->cpi_vendor == X86_VENDOR_AMD) {
10551228Sandrei 			/*
10561228Sandrei 			 * AMD currently only has dual-core processors with
10571228Sandrei 			 * single-threaded cores.  If they ever release
10581228Sandrei 			 * multi-threaded processors, then this code
10591228Sandrei 			 * will have to be updated.
10601228Sandrei 			 */
10611228Sandrei 			cpi->cpi_coreid = cpu->cpu_id;
10621228Sandrei 		} else {
10631228Sandrei 			/*
10641228Sandrei 			 * All other processors are currently
10651228Sandrei 			 * assumed to have single cores.
10661228Sandrei 			 */
10671228Sandrei 			cpi->cpi_coreid = cpi->cpi_chipid;
10681228Sandrei 		}
10690Sstevel@tonic-gate 	}
10700Sstevel@tonic-gate 
10712869Sgavinm 	/*
10722869Sgavinm 	 * Synthesize chip "revision" and socket type
10732869Sgavinm 	 */
10742869Sgavinm 	synth_info(cpi);
10752869Sgavinm 
10760Sstevel@tonic-gate pass1_done:
10770Sstevel@tonic-gate 	cpi->cpi_pass = 1;
10780Sstevel@tonic-gate 	return (feature);
10790Sstevel@tonic-gate }
10800Sstevel@tonic-gate 
10810Sstevel@tonic-gate /*
10820Sstevel@tonic-gate  * Make copies of the cpuid table entries we depend on, in
10830Sstevel@tonic-gate  * part for ease of parsing now, in part so that we have only
10840Sstevel@tonic-gate  * one place to correct any of it, in part for ease of
10850Sstevel@tonic-gate  * later export to userland, and in part so we can look at
10860Sstevel@tonic-gate  * this stuff in a crash dump.
10870Sstevel@tonic-gate  */
10880Sstevel@tonic-gate 
10890Sstevel@tonic-gate /*ARGSUSED*/
10900Sstevel@tonic-gate void
10910Sstevel@tonic-gate cpuid_pass2(cpu_t *cpu)
10920Sstevel@tonic-gate {
10930Sstevel@tonic-gate 	uint_t n, nmax;
10940Sstevel@tonic-gate 	int i;
10951228Sandrei 	struct cpuid_regs *cp;
10960Sstevel@tonic-gate 	uint8_t *dp;
10970Sstevel@tonic-gate 	uint32_t *iptr;
10980Sstevel@tonic-gate 	struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi;
10990Sstevel@tonic-gate 
11000Sstevel@tonic-gate 	ASSERT(cpi->cpi_pass == 1);
11010Sstevel@tonic-gate 
11020Sstevel@tonic-gate 	if (cpi->cpi_maxeax < 1)
11030Sstevel@tonic-gate 		goto pass2_done;
11040Sstevel@tonic-gate 
11050Sstevel@tonic-gate 	if ((nmax = cpi->cpi_maxeax + 1) > NMAX_CPI_STD)
11060Sstevel@tonic-gate 		nmax = NMAX_CPI_STD;
11070Sstevel@tonic-gate 	/*
11080Sstevel@tonic-gate 	 * (We already handled n == 0 and n == 1 in pass 1)
11090Sstevel@tonic-gate 	 */
11100Sstevel@tonic-gate 	for (n = 2, cp = &cpi->cpi_std[2]; n < nmax; n++, cp++) {
11111228Sandrei 		cp->cp_eax = n;
11124606Sesaxe 
11134606Sesaxe 		/*
11144606Sesaxe 		 * CPUID function 4 expects %ecx to be initialized
11154606Sesaxe 		 * with an index which indicates which cache to return
11164606Sesaxe 		 * information about. The OS is expected to call function 4
11174606Sesaxe 		 * with %ecx set to 0, 1, 2, ... until it returns with
11184606Sesaxe 		 * EAX[4:0] set to 0, which indicates there are no more
11194606Sesaxe 		 * caches.
11204606Sesaxe 		 *
11214606Sesaxe 		 * Here, populate cpi_std[4] with the information returned by
11224606Sesaxe 		 * function 4 when %ecx == 0, and do the rest in cpuid_pass3()
11234606Sesaxe 		 * when dynamic memory allocation becomes available.
11244606Sesaxe 		 *
11254606Sesaxe 		 * Note: we need to explicitly initialize %ecx here, since
11264606Sesaxe 		 * function 4 may have been previously invoked.
11274606Sesaxe 		 */
11284606Sesaxe 		if (n == 4)
11294606Sesaxe 			cp->cp_ecx = 0;
11304606Sesaxe 
11311228Sandrei 		(void) __cpuid_insn(cp);
11323446Smrj 		platform_cpuid_mangle(cpi->cpi_vendor, n, cp);
11330Sstevel@tonic-gate 		switch (n) {
11340Sstevel@tonic-gate 		case 2:
11350Sstevel@tonic-gate 			/*
11360Sstevel@tonic-gate 			 * "the lower 8 bits of the %eax register
11370Sstevel@tonic-gate 			 * contain a value that identifies the number
11380Sstevel@tonic-gate 			 * of times the cpuid [instruction] has to be
11390Sstevel@tonic-gate 			 * executed to obtain a complete image of the
11400Sstevel@tonic-gate 			 * processor's caching systems."
11410Sstevel@tonic-gate 			 *
11420Sstevel@tonic-gate 			 * How *do* they make this stuff up?
11430Sstevel@tonic-gate 			 */
11440Sstevel@tonic-gate 			cpi->cpi_ncache = sizeof (*cp) *
11450Sstevel@tonic-gate 			    BITX(cp->cp_eax, 7, 0);
11460Sstevel@tonic-gate 			if (cpi->cpi_ncache == 0)
11470Sstevel@tonic-gate 				break;
11480Sstevel@tonic-gate 			cpi->cpi_ncache--;	/* skip count byte */
11490Sstevel@tonic-gate 
11500Sstevel@tonic-gate 			/*
11510Sstevel@tonic-gate 			 * Well, for now, rather than attempt to implement
11520Sstevel@tonic-gate 			 * this slightly dubious algorithm, we just look
11530Sstevel@tonic-gate 			 * at the first 15 ..
11540Sstevel@tonic-gate 			 */
11550Sstevel@tonic-gate 			if (cpi->cpi_ncache > (sizeof (*cp) - 1))
11560Sstevel@tonic-gate 				cpi->cpi_ncache = sizeof (*cp) - 1;
11570Sstevel@tonic-gate 
11580Sstevel@tonic-gate 			dp = cpi->cpi_cacheinfo;
11590Sstevel@tonic-gate 			if (BITX(cp->cp_eax, 31, 31) == 0) {
11600Sstevel@tonic-gate 				uint8_t *p = (void *)&cp->cp_eax;
11610Sstevel@tonic-gate 				for (i = 1; i < 3; i++)
11620Sstevel@tonic-gate 					if (p[i] != 0)
11630Sstevel@tonic-gate 						*dp++ = p[i];
11640Sstevel@tonic-gate 			}
11650Sstevel@tonic-gate 			if (BITX(cp->cp_ebx, 31, 31) == 0) {
11660Sstevel@tonic-gate 				uint8_t *p = (void *)&cp->cp_ebx;
11670Sstevel@tonic-gate 				for (i = 0; i < 4; i++)
11680Sstevel@tonic-gate 					if (p[i] != 0)
11690Sstevel@tonic-gate 						*dp++ = p[i];
11700Sstevel@tonic-gate 			}
11710Sstevel@tonic-gate 			if (BITX(cp->cp_ecx, 31, 31) == 0) {
11720Sstevel@tonic-gate 				uint8_t *p = (void *)&cp->cp_ecx;
11730Sstevel@tonic-gate 				for (i = 0; i < 4; i++)
11740Sstevel@tonic-gate 					if (p[i] != 0)
11750Sstevel@tonic-gate 						*dp++ = p[i];
11760Sstevel@tonic-gate 			}
11770Sstevel@tonic-gate 			if (BITX(cp->cp_edx, 31, 31) == 0) {
11780Sstevel@tonic-gate 				uint8_t *p = (void *)&cp->cp_edx;
11790Sstevel@tonic-gate 				for (i = 0; i < 4; i++)
11800Sstevel@tonic-gate 					if (p[i] != 0)
11810Sstevel@tonic-gate 						*dp++ = p[i];
11820Sstevel@tonic-gate 			}
11830Sstevel@tonic-gate 			break;
11844481Sbholler 
11850Sstevel@tonic-gate 		case 3:	/* Processor serial number, if PSN supported */
11864481Sbholler 			break;
11874481Sbholler 
11880Sstevel@tonic-gate 		case 4:	/* Deterministic cache parameters */
11894481Sbholler 			break;
11904481Sbholler 
11910Sstevel@tonic-gate 		case 5:	/* Monitor/Mwait parameters */
11924481Sbholler 
11934481Sbholler 			/*
11944481Sbholler 			 * check cpi_mwait.support which was set in cpuid_pass1
11954481Sbholler 			 */
11964481Sbholler 			if (!(cpi->cpi_mwait.support & MWAIT_SUPPORT))
11974481Sbholler 				break;
11984481Sbholler 
11994481Sbholler 			cpi->cpi_mwait.mon_min = (size_t)MWAIT_SIZE_MIN(cpi);
12004481Sbholler 			cpi->cpi_mwait.mon_max = (size_t)MWAIT_SIZE_MAX(cpi);
12014481Sbholler 			if (MWAIT_EXTENSION(cpi)) {
12024481Sbholler 				cpi->cpi_mwait.support |= MWAIT_EXTENSIONS;
12034481Sbholler 				if (MWAIT_INT_ENABLE(cpi))
12044481Sbholler 					cpi->cpi_mwait.support |=
12054481Sbholler 					    MWAIT_ECX_INT_ENABLE;
12064481Sbholler 			}
12074481Sbholler 			break;
12080Sstevel@tonic-gate 		default:
12090Sstevel@tonic-gate 			break;
12100Sstevel@tonic-gate 		}
12110Sstevel@tonic-gate 	}
12120Sstevel@tonic-gate 
12130Sstevel@tonic-gate 	if ((cpi->cpi_xmaxeax & 0x80000000) == 0)
12140Sstevel@tonic-gate 		goto pass2_done;
12150Sstevel@tonic-gate 
12160Sstevel@tonic-gate 	if ((nmax = cpi->cpi_xmaxeax - 0x80000000 + 1) > NMAX_CPI_EXTD)
12170Sstevel@tonic-gate 		nmax = NMAX_CPI_EXTD;
12180Sstevel@tonic-gate 	/*
12190Sstevel@tonic-gate 	 * Copy the extended properties, fixing them as we go.
12200Sstevel@tonic-gate 	 * (We already handled n == 0 and n == 1 in pass 1)
12210Sstevel@tonic-gate 	 */
12220Sstevel@tonic-gate 	iptr = (void *)cpi->cpi_brandstr;
12230Sstevel@tonic-gate 	for (n = 2, cp = &cpi->cpi_extd[2]; n < nmax; cp++, n++) {
12241228Sandrei 		cp->cp_eax = 0x80000000 + n;
12251228Sandrei 		(void) __cpuid_insn(cp);
12263446Smrj 		platform_cpuid_mangle(cpi->cpi_vendor, 0x80000000 + n, cp);
12270Sstevel@tonic-gate 		switch (n) {
12280Sstevel@tonic-gate 		case 2:
12290Sstevel@tonic-gate 		case 3:
12300Sstevel@tonic-gate 		case 4:
12310Sstevel@tonic-gate 			/*
12320Sstevel@tonic-gate 			 * Extract the brand string
12330Sstevel@tonic-gate 			 */
12340Sstevel@tonic-gate 			*iptr++ = cp->cp_eax;
12350Sstevel@tonic-gate 			*iptr++ = cp->cp_ebx;
12360Sstevel@tonic-gate 			*iptr++ = cp->cp_ecx;
12370Sstevel@tonic-gate 			*iptr++ = cp->cp_edx;
12380Sstevel@tonic-gate 			break;
12390Sstevel@tonic-gate 		case 5:
12400Sstevel@tonic-gate 			switch (cpi->cpi_vendor) {
12410Sstevel@tonic-gate 			case X86_VENDOR_AMD:
12420Sstevel@tonic-gate 				/*
12430Sstevel@tonic-gate 				 * The Athlon and Duron were the first
12440Sstevel@tonic-gate 				 * parts to report the sizes of the
12450Sstevel@tonic-gate 				 * TLB for large pages. Before then,
12460Sstevel@tonic-gate 				 * we don't trust the data.
12470Sstevel@tonic-gate 				 */
12480Sstevel@tonic-gate 				if (cpi->cpi_family < 6 ||
12490Sstevel@tonic-gate 				    (cpi->cpi_family == 6 &&
12500Sstevel@tonic-gate 				    cpi->cpi_model < 1))
12510Sstevel@tonic-gate 					cp->cp_eax = 0;
12520Sstevel@tonic-gate 				break;
12530Sstevel@tonic-gate 			default:
12540Sstevel@tonic-gate 				break;
12550Sstevel@tonic-gate 			}
12560Sstevel@tonic-gate 			break;
12570Sstevel@tonic-gate 		case 6:
12580Sstevel@tonic-gate 			switch (cpi->cpi_vendor) {
12590Sstevel@tonic-gate 			case X86_VENDOR_AMD:
12600Sstevel@tonic-gate 				/*
12610Sstevel@tonic-gate 				 * The Athlon and Duron were the first
12620Sstevel@tonic-gate 				 * AMD parts with L2 TLB's.
12630Sstevel@tonic-gate 				 * Before then, don't trust the data.
12640Sstevel@tonic-gate 				 */
12650Sstevel@tonic-gate 				if (cpi->cpi_family < 6 ||
12660Sstevel@tonic-gate 				    cpi->cpi_family == 6 &&
12670Sstevel@tonic-gate 				    cpi->cpi_model < 1)
12680Sstevel@tonic-gate 					cp->cp_eax = cp->cp_ebx = 0;
12690Sstevel@tonic-gate 				/*
12700Sstevel@tonic-gate 				 * AMD Duron rev A0 reports L2
12710Sstevel@tonic-gate 				 * cache size incorrectly as 1K
12720Sstevel@tonic-gate 				 * when it is really 64K
12730Sstevel@tonic-gate 				 */
12740Sstevel@tonic-gate 				if (cpi->cpi_family == 6 &&
12750Sstevel@tonic-gate 				    cpi->cpi_model == 3 &&
12760Sstevel@tonic-gate 				    cpi->cpi_step == 0) {
12770Sstevel@tonic-gate 					cp->cp_ecx &= 0xffff;
12780Sstevel@tonic-gate 					cp->cp_ecx |= 0x400000;
12790Sstevel@tonic-gate 				}
12800Sstevel@tonic-gate 				break;
12810Sstevel@tonic-gate 			case X86_VENDOR_Cyrix:	/* VIA C3 */
12820Sstevel@tonic-gate 				/*
12830Sstevel@tonic-gate 				 * VIA C3 processors are a bit messed
12840Sstevel@tonic-gate 				 * up w.r.t. encoding cache sizes in %ecx
12850Sstevel@tonic-gate 				 */
12860Sstevel@tonic-gate 				if (cpi->cpi_family != 6)
12870Sstevel@tonic-gate 					break;
12880Sstevel@tonic-gate 				/*
12890Sstevel@tonic-gate 				 * model 7 and 8 were incorrectly encoded
12900Sstevel@tonic-gate 				 *
12910Sstevel@tonic-gate 				 * xxx is model 8 really broken?
12920Sstevel@tonic-gate 				 */
12930Sstevel@tonic-gate 				if (cpi->cpi_model == 7 ||
12940Sstevel@tonic-gate 				    cpi->cpi_model == 8)
12950Sstevel@tonic-gate 					cp->cp_ecx =
12960Sstevel@tonic-gate 					    BITX(cp->cp_ecx, 31, 24) << 16 |
12970Sstevel@tonic-gate 					    BITX(cp->cp_ecx, 23, 16) << 12 |
12980Sstevel@tonic-gate 					    BITX(cp->cp_ecx, 15, 8) << 8 |
12990Sstevel@tonic-gate 					    BITX(cp->cp_ecx, 7, 0);
13000Sstevel@tonic-gate 				/*
13010Sstevel@tonic-gate 				 * model 9 stepping 1 has wrong associativity
13020Sstevel@tonic-gate 				 */
13030Sstevel@tonic-gate 				if (cpi->cpi_model == 9 && cpi->cpi_step == 1)
13040Sstevel@tonic-gate 					cp->cp_ecx |= 8 << 12;
13050Sstevel@tonic-gate 				break;
13060Sstevel@tonic-gate 			case X86_VENDOR_Intel:
13070Sstevel@tonic-gate 				/*
13080Sstevel@tonic-gate 				 * Extended L2 Cache features function.
13090Sstevel@tonic-gate 				 * First appeared on Prescott.
13100Sstevel@tonic-gate 				 */
13110Sstevel@tonic-gate 			default:
13120Sstevel@tonic-gate 				break;
13130Sstevel@tonic-gate 			}
13140Sstevel@tonic-gate 			break;
13150Sstevel@tonic-gate 		default:
13160Sstevel@tonic-gate 			break;
13170Sstevel@tonic-gate 		}
13180Sstevel@tonic-gate 	}
13190Sstevel@tonic-gate 
13200Sstevel@tonic-gate pass2_done:
13210Sstevel@tonic-gate 	cpi->cpi_pass = 2;
13220Sstevel@tonic-gate }
13230Sstevel@tonic-gate 
13240Sstevel@tonic-gate static const char *
13250Sstevel@tonic-gate intel_cpubrand(const struct cpuid_info *cpi)
13260Sstevel@tonic-gate {
13270Sstevel@tonic-gate 	int i;
13280Sstevel@tonic-gate 
13290Sstevel@tonic-gate 	if ((x86_feature & X86_CPUID) == 0 ||
13300Sstevel@tonic-gate 	    cpi->cpi_maxeax < 1 || cpi->cpi_family < 5)
13310Sstevel@tonic-gate 		return ("i486");
13320Sstevel@tonic-gate 
13330Sstevel@tonic-gate 	switch (cpi->cpi_family) {
13340Sstevel@tonic-gate 	case 5:
13350Sstevel@tonic-gate 		return ("Intel Pentium(r)");
13360Sstevel@tonic-gate 	case 6:
13370Sstevel@tonic-gate 		switch (cpi->cpi_model) {
13380Sstevel@tonic-gate 			uint_t celeron, xeon;
13391228Sandrei 			const struct cpuid_regs *cp;
13400Sstevel@tonic-gate 		case 0:
13410Sstevel@tonic-gate 		case 1:
13420Sstevel@tonic-gate 		case 2:
13430Sstevel@tonic-gate 			return ("Intel Pentium(r) Pro");
13440Sstevel@tonic-gate 		case 3:
13450Sstevel@tonic-gate 		case 4:
13460Sstevel@tonic-gate 			return ("Intel Pentium(r) II");
13470Sstevel@tonic-gate 		case 6:
13480Sstevel@tonic-gate 			return ("Intel Celeron(r)");
13490Sstevel@tonic-gate 		case 5:
13500Sstevel@tonic-gate 		case 7:
13510Sstevel@tonic-gate 			celeron = xeon = 0;
13520Sstevel@tonic-gate 			cp = &cpi->cpi_std[2];	/* cache info */
13530Sstevel@tonic-gate 
13540Sstevel@tonic-gate 			for (i = 1; i < 3; i++) {
13550Sstevel@tonic-gate 				uint_t tmp;
13560Sstevel@tonic-gate 
13570Sstevel@tonic-gate 				tmp = (cp->cp_eax >> (8 * i)) & 0xff;
13580Sstevel@tonic-gate 				if (tmp == 0x40)
13590Sstevel@tonic-gate 					celeron++;
13600Sstevel@tonic-gate 				if (tmp >= 0x44 && tmp <= 0x45)
13610Sstevel@tonic-gate 					xeon++;
13620Sstevel@tonic-gate 			}
13630Sstevel@tonic-gate 
13640Sstevel@tonic-gate 			for (i = 0; i < 2; i++) {
13650Sstevel@tonic-gate 				uint_t tmp;
13660Sstevel@tonic-gate 
13670Sstevel@tonic-gate 				tmp = (cp->cp_ebx >> (8 * i)) & 0xff;
13680Sstevel@tonic-gate 				if (tmp == 0x40)
13690Sstevel@tonic-gate 					celeron++;
13700Sstevel@tonic-gate 				else if (tmp >= 0x44 && tmp <= 0x45)
13710Sstevel@tonic-gate 					xeon++;
13720Sstevel@tonic-gate 			}
13730Sstevel@tonic-gate 
13740Sstevel@tonic-gate 			for (i = 0; i < 4; i++) {
13750Sstevel@tonic-gate 				uint_t tmp;
13760Sstevel@tonic-gate 
13770Sstevel@tonic-gate 				tmp = (cp->cp_ecx >> (8 * i)) & 0xff;
13780Sstevel@tonic-gate 				if (tmp == 0x40)
13790Sstevel@tonic-gate 					celeron++;
13800Sstevel@tonic-gate 				else if (tmp >= 0x44 && tmp <= 0x45)
13810Sstevel@tonic-gate 					xeon++;
13820Sstevel@tonic-gate 			}
13830Sstevel@tonic-gate 
13840Sstevel@tonic-gate 			for (i = 0; i < 4; i++) {
13850Sstevel@tonic-gate 				uint_t tmp;
13860Sstevel@tonic-gate 
13870Sstevel@tonic-gate 				tmp = (cp->cp_edx >> (8 * i)) & 0xff;
13880Sstevel@tonic-gate 				if (tmp == 0x40)
13890Sstevel@tonic-gate 					celeron++;
13900Sstevel@tonic-gate 				else if (tmp >= 0x44 && tmp <= 0x45)
13910Sstevel@tonic-gate 					xeon++;
13920Sstevel@tonic-gate 			}
13930Sstevel@tonic-gate 
13940Sstevel@tonic-gate 			if (celeron)
13950Sstevel@tonic-gate 				return ("Intel Celeron(r)");
13960Sstevel@tonic-gate 			if (xeon)
13970Sstevel@tonic-gate 				return (cpi->cpi_model == 5 ?
13980Sstevel@tonic-gate 				    "Intel Pentium(r) II Xeon(tm)" :
13990Sstevel@tonic-gate 				    "Intel Pentium(r) III Xeon(tm)");
14000Sstevel@tonic-gate 			return (cpi->cpi_model == 5 ?
14010Sstevel@tonic-gate 			    "Intel Pentium(r) II or Pentium(r) II Xeon(tm)" :
14020Sstevel@tonic-gate 			    "Intel Pentium(r) III or Pentium(r) III Xeon(tm)");
14030Sstevel@tonic-gate 		default:
14040Sstevel@tonic-gate 			break;
14050Sstevel@tonic-gate 		}
14060Sstevel@tonic-gate 	default:
14070Sstevel@tonic-gate 		break;
14080Sstevel@tonic-gate 	}
14090Sstevel@tonic-gate 
14101975Sdmick 	/* BrandID is present if the field is nonzero */
14111975Sdmick 	if (cpi->cpi_brandid != 0) {
14120Sstevel@tonic-gate 		static const struct {
14130Sstevel@tonic-gate 			uint_t bt_bid;
14140Sstevel@tonic-gate 			const char *bt_str;
14150Sstevel@tonic-gate 		} brand_tbl[] = {
14160Sstevel@tonic-gate 			{ 0x1,	"Intel(r) Celeron(r)" },
14170Sstevel@tonic-gate 			{ 0x2,	"Intel(r) Pentium(r) III" },
14180Sstevel@tonic-gate 			{ 0x3,	"Intel(r) Pentium(r) III Xeon(tm)" },
14190Sstevel@tonic-gate 			{ 0x4,	"Intel(r) Pentium(r) III" },
14200Sstevel@tonic-gate 			{ 0x6,	"Mobile Intel(r) Pentium(r) III" },
14210Sstevel@tonic-gate 			{ 0x7,	"Mobile Intel(r) Celeron(r)" },
14220Sstevel@tonic-gate 			{ 0x8,	"Intel(r) Pentium(r) 4" },
14230Sstevel@tonic-gate 			{ 0x9,	"Intel(r) Pentium(r) 4" },
14240Sstevel@tonic-gate 			{ 0xa,	"Intel(r) Celeron(r)" },
14250Sstevel@tonic-gate 			{ 0xb,	"Intel(r) Xeon(tm)" },
14260Sstevel@tonic-gate 			{ 0xc,	"Intel(r) Xeon(tm) MP" },
14270Sstevel@tonic-gate 			{ 0xe,	"Mobile Intel(r) Pentium(r) 4" },
14281975Sdmick 			{ 0xf,	"Mobile Intel(r) Celeron(r)" },
14291975Sdmick 			{ 0x11, "Mobile Genuine Intel(r)" },
14301975Sdmick 			{ 0x12, "Intel(r) Celeron(r) M" },
14311975Sdmick 			{ 0x13, "Mobile Intel(r) Celeron(r)" },
14321975Sdmick 			{ 0x14, "Intel(r) Celeron(r)" },
14331975Sdmick 			{ 0x15, "Mobile Genuine Intel(r)" },
14341975Sdmick 			{ 0x16,	"Intel(r) Pentium(r) M" },
14351975Sdmick 			{ 0x17, "Mobile Intel(r) Celeron(r)" }
14360Sstevel@tonic-gate 		};
14370Sstevel@tonic-gate 		uint_t btblmax = sizeof (brand_tbl) / sizeof (brand_tbl[0]);
14380Sstevel@tonic-gate 		uint_t sgn;
14390Sstevel@tonic-gate 
14400Sstevel@tonic-gate 		sgn = (cpi->cpi_family << 8) |
14410Sstevel@tonic-gate 		    (cpi->cpi_model << 4) | cpi->cpi_step;
14420Sstevel@tonic-gate 
14430Sstevel@tonic-gate 		for (i = 0; i < btblmax; i++)
14440Sstevel@tonic-gate 			if (brand_tbl[i].bt_bid == cpi->cpi_brandid)
14450Sstevel@tonic-gate 				break;
14460Sstevel@tonic-gate 		if (i < btblmax) {
14470Sstevel@tonic-gate 			if (sgn == 0x6b1 && cpi->cpi_brandid == 3)
14480Sstevel@tonic-gate 				return ("Intel(r) Celeron(r)");
14490Sstevel@tonic-gate 			if (sgn < 0xf13 && cpi->cpi_brandid == 0xb)
14500Sstevel@tonic-gate 				return ("Intel(r) Xeon(tm) MP");
14510Sstevel@tonic-gate 			if (sgn < 0xf13 && cpi->cpi_brandid == 0xe)
14520Sstevel@tonic-gate 				return ("Intel(r) Xeon(tm)");
14530Sstevel@tonic-gate 			return (brand_tbl[i].bt_str);
14540Sstevel@tonic-gate 		}
14550Sstevel@tonic-gate 	}
14560Sstevel@tonic-gate 
14570Sstevel@tonic-gate 	return (NULL);
14580Sstevel@tonic-gate }
14590Sstevel@tonic-gate 
14600Sstevel@tonic-gate static const char *
14610Sstevel@tonic-gate amd_cpubrand(const struct cpuid_info *cpi)
14620Sstevel@tonic-gate {
14630Sstevel@tonic-gate 	if ((x86_feature & X86_CPUID) == 0 ||
14640Sstevel@tonic-gate 	    cpi->cpi_maxeax < 1 || cpi->cpi_family < 5)
14650Sstevel@tonic-gate 		return ("i486 compatible");
14660Sstevel@tonic-gate 
14670Sstevel@tonic-gate 	switch (cpi->cpi_family) {
14680Sstevel@tonic-gate 	case 5:
14690Sstevel@tonic-gate 		switch (cpi->cpi_model) {
14700Sstevel@tonic-gate 		case 0:
14710Sstevel@tonic-gate 		case 1:
14720Sstevel@tonic-gate 		case 2:
14730Sstevel@tonic-gate 		case 3:
14740Sstevel@tonic-gate 		case 4:
14750Sstevel@tonic-gate 		case 5:
14760Sstevel@tonic-gate 			return ("AMD-K5(r)");
14770Sstevel@tonic-gate 		case 6:
14780Sstevel@tonic-gate 		case 7:
14790Sstevel@tonic-gate 			return ("AMD-K6(r)");
14800Sstevel@tonic-gate 		case 8:
14810Sstevel@tonic-gate 			return ("AMD-K6(r)-2");
14820Sstevel@tonic-gate 		case 9:
14830Sstevel@tonic-gate 			return ("AMD-K6(r)-III");
14840Sstevel@tonic-gate 		default:
14850Sstevel@tonic-gate 			return ("AMD (family 5)");
14860Sstevel@tonic-gate 		}
14870Sstevel@tonic-gate 	case 6:
14880Sstevel@tonic-gate 		switch (cpi->cpi_model) {
14890Sstevel@tonic-gate 		case 1:
14900Sstevel@tonic-gate 			return ("AMD-K7(tm)");
14910Sstevel@tonic-gate 		case 0:
14920Sstevel@tonic-gate 		case 2:
14930Sstevel@tonic-gate 		case 4:
14940Sstevel@tonic-gate 			return ("AMD Athlon(tm)");
14950Sstevel@tonic-gate 		case 3:
14960Sstevel@tonic-gate 		case 7:
14970Sstevel@tonic-gate 			return ("AMD Duron(tm)");
14980Sstevel@tonic-gate 		case 6:
14990Sstevel@tonic-gate 		case 8:
15000Sstevel@tonic-gate 		case 10:
15010Sstevel@tonic-gate 			/*
15020Sstevel@tonic-gate 			 * Use the L2 cache size to distinguish
15030Sstevel@tonic-gate 			 */
15040Sstevel@tonic-gate 			return ((cpi->cpi_extd[6].cp_ecx >> 16) >= 256 ?
15050Sstevel@tonic-gate 			    "AMD Athlon(tm)" : "AMD Duron(tm)");
15060Sstevel@tonic-gate 		default:
15070Sstevel@tonic-gate 			return ("AMD (family 6)");
15080Sstevel@tonic-gate 		}
15090Sstevel@tonic-gate 	default:
15100Sstevel@tonic-gate 		break;
15110Sstevel@tonic-gate 	}
15120Sstevel@tonic-gate 
15130Sstevel@tonic-gate 	if (cpi->cpi_family == 0xf && cpi->cpi_model == 5 &&
15140Sstevel@tonic-gate 	    cpi->cpi_brandid != 0) {
15150Sstevel@tonic-gate 		switch (BITX(cpi->cpi_brandid, 7, 5)) {
15160Sstevel@tonic-gate 		case 3:
15170Sstevel@tonic-gate 			return ("AMD Opteron(tm) UP 1xx");
15180Sstevel@tonic-gate 		case 4:
15190Sstevel@tonic-gate 			return ("AMD Opteron(tm) DP 2xx");
15200Sstevel@tonic-gate 		case 5:
15210Sstevel@tonic-gate 			return ("AMD Opteron(tm) MP 8xx");
15220Sstevel@tonic-gate 		default:
15230Sstevel@tonic-gate 			return ("AMD Opteron(tm)");
15240Sstevel@tonic-gate 		}
15250Sstevel@tonic-gate 	}
15260Sstevel@tonic-gate 
15270Sstevel@tonic-gate 	return (NULL);
15280Sstevel@tonic-gate }
15290Sstevel@tonic-gate 
15300Sstevel@tonic-gate static const char *
15310Sstevel@tonic-gate cyrix_cpubrand(struct cpuid_info *cpi, uint_t type)
15320Sstevel@tonic-gate {
15330Sstevel@tonic-gate 	if ((x86_feature & X86_CPUID) == 0 ||
15340Sstevel@tonic-gate 	    cpi->cpi_maxeax < 1 || cpi->cpi_family < 5 ||
15350Sstevel@tonic-gate 	    type == X86_TYPE_CYRIX_486)
15360Sstevel@tonic-gate 		return ("i486 compatible");
15370Sstevel@tonic-gate 
15380Sstevel@tonic-gate 	switch (type) {
15390Sstevel@tonic-gate 	case X86_TYPE_CYRIX_6x86:
15400Sstevel@tonic-gate 		return ("Cyrix 6x86");
15410Sstevel@tonic-gate 	case X86_TYPE_CYRIX_6x86L:
15420Sstevel@tonic-gate 		return ("Cyrix 6x86L");
15430Sstevel@tonic-gate 	case X86_TYPE_CYRIX_6x86MX:
15440Sstevel@tonic-gate 		return ("Cyrix 6x86MX");
15450Sstevel@tonic-gate 	case X86_TYPE_CYRIX_GXm:
15460Sstevel@tonic-gate 		return ("Cyrix GXm");
15470Sstevel@tonic-gate 	case X86_TYPE_CYRIX_MediaGX:
15480Sstevel@tonic-gate 		return ("Cyrix MediaGX");
15490Sstevel@tonic-gate 	case X86_TYPE_CYRIX_MII:
15500Sstevel@tonic-gate 		return ("Cyrix M2");
15510Sstevel@tonic-gate 	case X86_TYPE_VIA_CYRIX_III:
15520Sstevel@tonic-gate 		return ("VIA Cyrix M3");
15530Sstevel@tonic-gate 	default:
15540Sstevel@tonic-gate 		/*
15550Sstevel@tonic-gate 		 * Have another wild guess ..
15560Sstevel@tonic-gate 		 */
15570Sstevel@tonic-gate 		if (cpi->cpi_family == 4 && cpi->cpi_model == 9)
15580Sstevel@tonic-gate 			return ("Cyrix 5x86");
15590Sstevel@tonic-gate 		else if (cpi->cpi_family == 5) {
15600Sstevel@tonic-gate 			switch (cpi->cpi_model) {
15610Sstevel@tonic-gate 			case 2:
15620Sstevel@tonic-gate 				return ("Cyrix 6x86");	/* Cyrix M1 */
15630Sstevel@tonic-gate 			case 4:
15640Sstevel@tonic-gate 				return ("Cyrix MediaGX");
15650Sstevel@tonic-gate 			default:
15660Sstevel@tonic-gate 				break;
15670Sstevel@tonic-gate 			}
15680Sstevel@tonic-gate 		} else if (cpi->cpi_family == 6) {
15690Sstevel@tonic-gate 			switch (cpi->cpi_model) {
15700Sstevel@tonic-gate 			case 0:
15710Sstevel@tonic-gate 				return ("Cyrix 6x86MX"); /* Cyrix M2? */
15720Sstevel@tonic-gate 			case 5:
15730Sstevel@tonic-gate 			case 6:
15740Sstevel@tonic-gate 			case 7:
15750Sstevel@tonic-gate 			case 8:
15760Sstevel@tonic-gate 			case 9:
15770Sstevel@tonic-gate 				return ("VIA C3");
15780Sstevel@tonic-gate 			default:
15790Sstevel@tonic-gate 				break;
15800Sstevel@tonic-gate 			}
15810Sstevel@tonic-gate 		}
15820Sstevel@tonic-gate 		break;
15830Sstevel@tonic-gate 	}
15840Sstevel@tonic-gate 	return (NULL);
15850Sstevel@tonic-gate }
15860Sstevel@tonic-gate 
15870Sstevel@tonic-gate /*
15880Sstevel@tonic-gate  * This only gets called in the case that the CPU extended
15890Sstevel@tonic-gate  * feature brand string (0x80000002, 0x80000003, 0x80000004)
15900Sstevel@tonic-gate  * aren't available, or contain null bytes for some reason.
15910Sstevel@tonic-gate  */
15920Sstevel@tonic-gate static void
15930Sstevel@tonic-gate fabricate_brandstr(struct cpuid_info *cpi)
15940Sstevel@tonic-gate {
15950Sstevel@tonic-gate 	const char *brand = NULL;
15960Sstevel@tonic-gate 
15970Sstevel@tonic-gate 	switch (cpi->cpi_vendor) {
15980Sstevel@tonic-gate 	case X86_VENDOR_Intel:
15990Sstevel@tonic-gate 		brand = intel_cpubrand(cpi);
16000Sstevel@tonic-gate 		break;
16010Sstevel@tonic-gate 	case X86_VENDOR_AMD:
16020Sstevel@tonic-gate 		brand = amd_cpubrand(cpi);
16030Sstevel@tonic-gate 		break;
16040Sstevel@tonic-gate 	case X86_VENDOR_Cyrix:
16050Sstevel@tonic-gate 		brand = cyrix_cpubrand(cpi, x86_type);
16060Sstevel@tonic-gate 		break;
16070Sstevel@tonic-gate 	case X86_VENDOR_NexGen:
16080Sstevel@tonic-gate 		if (cpi->cpi_family == 5 && cpi->cpi_model == 0)
16090Sstevel@tonic-gate 			brand = "NexGen Nx586";
16100Sstevel@tonic-gate 		break;
16110Sstevel@tonic-gate 	case X86_VENDOR_Centaur:
16120Sstevel@tonic-gate 		if (cpi->cpi_family == 5)
16130Sstevel@tonic-gate 			switch (cpi->cpi_model) {
16140Sstevel@tonic-gate 			case 4:
16150Sstevel@tonic-gate 				brand = "Centaur C6";
16160Sstevel@tonic-gate 				break;
16170Sstevel@tonic-gate 			case 8:
16180Sstevel@tonic-gate 				brand = "Centaur C2";
16190Sstevel@tonic-gate 				break;
16200Sstevel@tonic-gate 			case 9:
16210Sstevel@tonic-gate 				brand = "Centaur C3";
16220Sstevel@tonic-gate 				break;
16230Sstevel@tonic-gate 			default:
16240Sstevel@tonic-gate 				break;
16250Sstevel@tonic-gate 			}
16260Sstevel@tonic-gate 		break;
16270Sstevel@tonic-gate 	case X86_VENDOR_Rise:
16280Sstevel@tonic-gate 		if (cpi->cpi_family == 5 &&
16290Sstevel@tonic-gate 		    (cpi->cpi_model == 0 || cpi->cpi_model == 2))
16300Sstevel@tonic-gate 			brand = "Rise mP6";
16310Sstevel@tonic-gate 		break;
16320Sstevel@tonic-gate 	case X86_VENDOR_SiS:
16330Sstevel@tonic-gate 		if (cpi->cpi_family == 5 && cpi->cpi_model == 0)
16340Sstevel@tonic-gate 			brand = "SiS 55x";
16350Sstevel@tonic-gate 		break;
16360Sstevel@tonic-gate 	case X86_VENDOR_TM:
16370Sstevel@tonic-gate 		if (cpi->cpi_family == 5 && cpi->cpi_model == 4)
16380Sstevel@tonic-gate 			brand = "Transmeta Crusoe TM3x00 or TM5x00";
16390Sstevel@tonic-gate 		break;
16400Sstevel@tonic-gate 	case X86_VENDOR_NSC:
16410Sstevel@tonic-gate 	case X86_VENDOR_UMC:
16420Sstevel@tonic-gate 	default:
16430Sstevel@tonic-gate 		break;
16440Sstevel@tonic-gate 	}
16450Sstevel@tonic-gate 	if (brand) {
16460Sstevel@tonic-gate 		(void) strcpy((char *)cpi->cpi_brandstr, brand);
16470Sstevel@tonic-gate 		return;
16480Sstevel@tonic-gate 	}
16490Sstevel@tonic-gate 
16500Sstevel@tonic-gate 	/*
16510Sstevel@tonic-gate 	 * If all else fails ...
16520Sstevel@tonic-gate 	 */
16530Sstevel@tonic-gate 	(void) snprintf(cpi->cpi_brandstr, sizeof (cpi->cpi_brandstr),
16540Sstevel@tonic-gate 	    "%s %d.%d.%d", cpi->cpi_vendorstr, cpi->cpi_family,
16550Sstevel@tonic-gate 	    cpi->cpi_model, cpi->cpi_step);
16560Sstevel@tonic-gate }
16570Sstevel@tonic-gate 
16580Sstevel@tonic-gate /*
16590Sstevel@tonic-gate  * This routine is called just after kernel memory allocation
16600Sstevel@tonic-gate  * becomes available on cpu0, and as part of mp_startup() on
16610Sstevel@tonic-gate  * the other cpus.
16620Sstevel@tonic-gate  *
16634606Sesaxe  * Fixup the brand string, and collect any information from cpuid
16644606Sesaxe  * that requires dynamicically allocated storage to represent.
16650Sstevel@tonic-gate  */
16660Sstevel@tonic-gate /*ARGSUSED*/
16670Sstevel@tonic-gate void
16680Sstevel@tonic-gate cpuid_pass3(cpu_t *cpu)
16690Sstevel@tonic-gate {
16704606Sesaxe 	int	i, max, shft, level, size;
16714606Sesaxe 	struct cpuid_regs regs;
16724606Sesaxe 	struct cpuid_regs *cp;
16730Sstevel@tonic-gate 	struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi;
16740Sstevel@tonic-gate 
16750Sstevel@tonic-gate 	ASSERT(cpi->cpi_pass == 2);
16760Sstevel@tonic-gate 
16774606Sesaxe 	/*
16784606Sesaxe 	 * Function 4: Deterministic cache parameters
16794606Sesaxe 	 *
16804606Sesaxe 	 * Take this opportunity to detect the number of threads
16814606Sesaxe 	 * sharing the last level cache, and construct a corresponding
16824606Sesaxe 	 * cache id. The respective cpuid_info members are initialized
16834606Sesaxe 	 * to the default case of "no last level cache sharing".
16844606Sesaxe 	 */
16854606Sesaxe 	cpi->cpi_ncpu_shr_last_cache = 1;
16864606Sesaxe 	cpi->cpi_last_lvl_cacheid = cpu->cpu_id;
16874606Sesaxe 
16884606Sesaxe 	if (cpi->cpi_maxeax >= 4 && cpi->cpi_vendor == X86_VENDOR_Intel) {
16894606Sesaxe 
16904606Sesaxe 		/*
16914606Sesaxe 		 * Find the # of elements (size) returned by fn 4, and along
16924606Sesaxe 		 * the way detect last level cache sharing details.
16934606Sesaxe 		 */
16944606Sesaxe 		bzero(&regs, sizeof (regs));
16954606Sesaxe 		cp = &regs;
16964606Sesaxe 		for (i = 0, max = 0; i < CPI_FN4_ECX_MAX; i++) {
16974606Sesaxe 			cp->cp_eax = 4;
16984606Sesaxe 			cp->cp_ecx = i;
16994606Sesaxe 
17004606Sesaxe 			(void) __cpuid_insn(cp);
17014606Sesaxe 
17024606Sesaxe 			if (CPI_CACHE_TYPE(cp) == 0)
17034606Sesaxe 				break;
17044606Sesaxe 			level = CPI_CACHE_LVL(cp);
17054606Sesaxe 			if (level > max) {
17064606Sesaxe 				max = level;
17074606Sesaxe 				cpi->cpi_ncpu_shr_last_cache =
17084606Sesaxe 				    CPI_NTHR_SHR_CACHE(cp) + 1;
17094606Sesaxe 			}
17104606Sesaxe 		}
17114606Sesaxe 		cpi->cpi_std_4_size = size = i;
17124606Sesaxe 
17134606Sesaxe 		/*
17144606Sesaxe 		 * Allocate the cpi_std_4 array. The first element
17154606Sesaxe 		 * references the regs for fn 4, %ecx == 0, which
17164606Sesaxe 		 * cpuid_pass2() stashed in cpi->cpi_std[4].
17174606Sesaxe 		 */
17184606Sesaxe 		if (size > 0) {
17194606Sesaxe 			cpi->cpi_std_4 =
17204606Sesaxe 			    kmem_alloc(size * sizeof (cp), KM_SLEEP);
17214606Sesaxe 			cpi->cpi_std_4[0] = &cpi->cpi_std[4];
17224606Sesaxe 
17234606Sesaxe 			/*
17244606Sesaxe 			 * Allocate storage to hold the additional regs
17254606Sesaxe 			 * for function 4, %ecx == 1 .. cpi_std_4_size.
17264606Sesaxe 			 *
17274606Sesaxe 			 * The regs for fn 4, %ecx == 0 has already
17284606Sesaxe 			 * been allocated as indicated above.
17294606Sesaxe 			 */
17304606Sesaxe 			for (i = 1; i < size; i++) {
17314606Sesaxe 				cp = cpi->cpi_std_4[i] =
17324606Sesaxe 				    kmem_zalloc(sizeof (regs), KM_SLEEP);
17334606Sesaxe 				cp->cp_eax = 4;
17344606Sesaxe 				cp->cp_ecx = i;
17354606Sesaxe 
17364606Sesaxe 				(void) __cpuid_insn(cp);
17374606Sesaxe 			}
17384606Sesaxe 		}
17394606Sesaxe 		/*
17404606Sesaxe 		 * Determine the number of bits needed to represent
17414606Sesaxe 		 * the number of CPUs sharing the last level cache.
17424606Sesaxe 		 *
17434606Sesaxe 		 * Shift off that number of bits from the APIC id to
17444606Sesaxe 		 * derive the cache id.
17454606Sesaxe 		 */
17464606Sesaxe 		shft = 0;
17474606Sesaxe 		for (i = 1; i < cpi->cpi_ncpu_shr_last_cache; i <<= 1)
17484606Sesaxe 			shft++;
17494606Sesaxe 		cpi->cpi_last_lvl_cacheid = CPI_APIC_ID(cpi) >> shft;
17500Sstevel@tonic-gate 	}
17510Sstevel@tonic-gate 
17520Sstevel@tonic-gate 	/*
17534606Sesaxe 	 * Now fixup the brand string
17540Sstevel@tonic-gate 	 */
17554606Sesaxe 	if ((cpi->cpi_xmaxeax & 0x80000000) == 0) {
17564606Sesaxe 		fabricate_brandstr(cpi);
17574606Sesaxe 	} else {
17580Sstevel@tonic-gate 
17590Sstevel@tonic-gate 		/*
17604606Sesaxe 		 * If we successfully extracted a brand string from the cpuid
17614606Sesaxe 		 * instruction, clean it up by removing leading spaces and
17624606Sesaxe 		 * similar junk.
17630Sstevel@tonic-gate 		 */
17644606Sesaxe 		if (cpi->cpi_brandstr[0]) {
17654606Sesaxe 			size_t maxlen = sizeof (cpi->cpi_brandstr);
17664606Sesaxe 			char *src, *dst;
17674606Sesaxe 
17684606Sesaxe 			dst = src = (char *)cpi->cpi_brandstr;
17694606Sesaxe 			src[maxlen - 1] = '\0';
17704606Sesaxe 			/*
17714606Sesaxe 			 * strip leading spaces
17724606Sesaxe 			 */
17734606Sesaxe 			while (*src == ' ')
17744606Sesaxe 				src++;
17754606Sesaxe 			/*
17764606Sesaxe 			 * Remove any 'Genuine' or "Authentic" prefixes
17774606Sesaxe 			 */
17784606Sesaxe 			if (strncmp(src, "Genuine ", 8) == 0)
17794606Sesaxe 				src += 8;
17804606Sesaxe 			if (strncmp(src, "Authentic ", 10) == 0)
17814606Sesaxe 				src += 10;
17824606Sesaxe 
17834606Sesaxe 			/*
17844606Sesaxe 			 * Now do an in-place copy.
17854606Sesaxe 			 * Map (R) to (r) and (TM) to (tm).
17864606Sesaxe 			 * The era of teletypes is long gone, and there's
17874606Sesaxe 			 * -really- no need to shout.
17884606Sesaxe 			 */
17894606Sesaxe 			while (*src != '\0') {
17904606Sesaxe 				if (src[0] == '(') {
17914606Sesaxe 					if (strncmp(src + 1, "R)", 2) == 0) {
17924606Sesaxe 						(void) strncpy(dst, "(r)", 3);
17934606Sesaxe 						src += 3;
17944606Sesaxe 						dst += 3;
17954606Sesaxe 						continue;
17964606Sesaxe 					}
17974606Sesaxe 					if (strncmp(src + 1, "TM)", 3) == 0) {
17984606Sesaxe 						(void) strncpy(dst, "(tm)", 4);
17994606Sesaxe 						src += 4;
18004606Sesaxe 						dst += 4;
18014606Sesaxe 						continue;
18024606Sesaxe 					}
18030Sstevel@tonic-gate 				}
18044606Sesaxe 				*dst++ = *src++;
18050Sstevel@tonic-gate 			}
18064606Sesaxe 			*dst = '\0';
18074606Sesaxe 
18084606Sesaxe 			/*
18094606Sesaxe 			 * Finally, remove any trailing spaces
18104606Sesaxe 			 */
18114606Sesaxe 			while (--dst > cpi->cpi_brandstr)
18124606Sesaxe 				if (*dst == ' ')
18134606Sesaxe 					*dst = '\0';
18144606Sesaxe 				else
18154606Sesaxe 					break;
18164606Sesaxe 		} else
18174606Sesaxe 			fabricate_brandstr(cpi);
18184606Sesaxe 	}
18190Sstevel@tonic-gate 	cpi->cpi_pass = 3;
18200Sstevel@tonic-gate }
18210Sstevel@tonic-gate 
18220Sstevel@tonic-gate /*
18230Sstevel@tonic-gate  * This routine is called out of bind_hwcap() much later in the life
18240Sstevel@tonic-gate  * of the kernel (post_startup()).  The job of this routine is to resolve
18250Sstevel@tonic-gate  * the hardware feature support and kernel support for those features into
18260Sstevel@tonic-gate  * what we're actually going to tell applications via the aux vector.
18270Sstevel@tonic-gate  */
18280Sstevel@tonic-gate uint_t
18290Sstevel@tonic-gate cpuid_pass4(cpu_t *cpu)
18300Sstevel@tonic-gate {
18310Sstevel@tonic-gate 	struct cpuid_info *cpi;
18320Sstevel@tonic-gate 	uint_t hwcap_flags = 0;
18330Sstevel@tonic-gate 
18340Sstevel@tonic-gate 	if (cpu == NULL)
18350Sstevel@tonic-gate 		cpu = CPU;
18360Sstevel@tonic-gate 	cpi = cpu->cpu_m.mcpu_cpi;
18370Sstevel@tonic-gate 
18380Sstevel@tonic-gate 	ASSERT(cpi->cpi_pass == 3);
18390Sstevel@tonic-gate 
18400Sstevel@tonic-gate 	if (cpi->cpi_maxeax >= 1) {
18410Sstevel@tonic-gate 		uint32_t *edx = &cpi->cpi_support[STD_EDX_FEATURES];
18420Sstevel@tonic-gate 		uint32_t *ecx = &cpi->cpi_support[STD_ECX_FEATURES];
18430Sstevel@tonic-gate 
18440Sstevel@tonic-gate 		*edx = CPI_FEATURES_EDX(cpi);
18450Sstevel@tonic-gate 		*ecx = CPI_FEATURES_ECX(cpi);
18460Sstevel@tonic-gate 
18470Sstevel@tonic-gate 		/*
18480Sstevel@tonic-gate 		 * [these require explicit kernel support]
18490Sstevel@tonic-gate 		 */
18500Sstevel@tonic-gate 		if ((x86_feature & X86_SEP) == 0)
18510Sstevel@tonic-gate 			*edx &= ~CPUID_INTC_EDX_SEP;
18520Sstevel@tonic-gate 
18530Sstevel@tonic-gate 		if ((x86_feature & X86_SSE) == 0)
18540Sstevel@tonic-gate 			*edx &= ~(CPUID_INTC_EDX_FXSR|CPUID_INTC_EDX_SSE);
18550Sstevel@tonic-gate 		if ((x86_feature & X86_SSE2) == 0)
18560Sstevel@tonic-gate 			*edx &= ~CPUID_INTC_EDX_SSE2;
18570Sstevel@tonic-gate 
18580Sstevel@tonic-gate 		if ((x86_feature & X86_HTT) == 0)
18590Sstevel@tonic-gate 			*edx &= ~CPUID_INTC_EDX_HTT;
18600Sstevel@tonic-gate 
18610Sstevel@tonic-gate 		if ((x86_feature & X86_SSE3) == 0)
18620Sstevel@tonic-gate 			*ecx &= ~CPUID_INTC_ECX_SSE3;
18630Sstevel@tonic-gate 
18640Sstevel@tonic-gate 		/*
18650Sstevel@tonic-gate 		 * [no explicit support required beyond x87 fp context]
18660Sstevel@tonic-gate 		 */
18670Sstevel@tonic-gate 		if (!fpu_exists)
18680Sstevel@tonic-gate 			*edx &= ~(CPUID_INTC_EDX_FPU | CPUID_INTC_EDX_MMX);
18690Sstevel@tonic-gate 
18700Sstevel@tonic-gate 		/*
18710Sstevel@tonic-gate 		 * Now map the supported feature vector to things that we
18720Sstevel@tonic-gate 		 * think userland will care about.
18730Sstevel@tonic-gate 		 */
18740Sstevel@tonic-gate 		if (*edx & CPUID_INTC_EDX_SEP)
18750Sstevel@tonic-gate 			hwcap_flags |= AV_386_SEP;
18760Sstevel@tonic-gate 		if (*edx & CPUID_INTC_EDX_SSE)
18770Sstevel@tonic-gate 			hwcap_flags |= AV_386_FXSR | AV_386_SSE;
18780Sstevel@tonic-gate 		if (*edx & CPUID_INTC_EDX_SSE2)
18790Sstevel@tonic-gate 			hwcap_flags |= AV_386_SSE2;
18800Sstevel@tonic-gate 		if (*ecx & CPUID_INTC_ECX_SSE3)
18810Sstevel@tonic-gate 			hwcap_flags |= AV_386_SSE3;
18824628Skk208521 		if (*ecx & CPUID_INTC_ECX_POPCNT)
18834628Skk208521 			hwcap_flags |= AV_386_POPCNT;
18840Sstevel@tonic-gate 		if (*edx & CPUID_INTC_EDX_FPU)
18850Sstevel@tonic-gate 			hwcap_flags |= AV_386_FPU;
18860Sstevel@tonic-gate 		if (*edx & CPUID_INTC_EDX_MMX)
18870Sstevel@tonic-gate 			hwcap_flags |= AV_386_MMX;
18880Sstevel@tonic-gate 
18890Sstevel@tonic-gate 		if (*edx & CPUID_INTC_EDX_TSC)
18900Sstevel@tonic-gate 			hwcap_flags |= AV_386_TSC;
18910Sstevel@tonic-gate 		if (*edx & CPUID_INTC_EDX_CX8)
18920Sstevel@tonic-gate 			hwcap_flags |= AV_386_CX8;
18930Sstevel@tonic-gate 		if (*edx & CPUID_INTC_EDX_CMOV)
18940Sstevel@tonic-gate 			hwcap_flags |= AV_386_CMOV;
18950Sstevel@tonic-gate 		if (*ecx & CPUID_INTC_ECX_MON)
18960Sstevel@tonic-gate 			hwcap_flags |= AV_386_MON;
18970Sstevel@tonic-gate 		if (*ecx & CPUID_INTC_ECX_CX16)
18980Sstevel@tonic-gate 			hwcap_flags |= AV_386_CX16;
18990Sstevel@tonic-gate 	}
19000Sstevel@tonic-gate 
19011228Sandrei 	if (x86_feature & X86_HTT)
19020Sstevel@tonic-gate 		hwcap_flags |= AV_386_PAUSE;
19030Sstevel@tonic-gate 
19040Sstevel@tonic-gate 	if (cpi->cpi_xmaxeax < 0x80000001)
19050Sstevel@tonic-gate 		goto pass4_done;
19060Sstevel@tonic-gate 
19070Sstevel@tonic-gate 	switch (cpi->cpi_vendor) {
19081228Sandrei 		struct cpuid_regs cp;
19093446Smrj 		uint32_t *edx, *ecx;
19100Sstevel@tonic-gate 
19113446Smrj 	case X86_VENDOR_Intel:
19123446Smrj 		/*
19133446Smrj 		 * Seems like Intel duplicated what we necessary
19143446Smrj 		 * here to make the initial crop of 64-bit OS's work.
19153446Smrj 		 * Hopefully, those are the only "extended" bits
19163446Smrj 		 * they'll add.
19173446Smrj 		 */
19183446Smrj 		/*FALLTHROUGH*/
19193446Smrj 
19200Sstevel@tonic-gate 	case X86_VENDOR_AMD:
19210Sstevel@tonic-gate 		edx = &cpi->cpi_support[AMD_EDX_FEATURES];
19223446Smrj 		ecx = &cpi->cpi_support[AMD_ECX_FEATURES];
19230Sstevel@tonic-gate 
19240Sstevel@tonic-gate 		*edx = CPI_FEATURES_XTD_EDX(cpi);
19253446Smrj 		*ecx = CPI_FEATURES_XTD_ECX(cpi);
19263446Smrj 
19273446Smrj 		/*
19283446Smrj 		 * [these features require explicit kernel support]
19293446Smrj 		 */
19303446Smrj 		switch (cpi->cpi_vendor) {
19313446Smrj 		case X86_VENDOR_Intel:
19323446Smrj 			break;
19333446Smrj 
19343446Smrj 		case X86_VENDOR_AMD:
19353446Smrj 			if ((x86_feature & X86_TSCP) == 0)
19363446Smrj 				*edx &= ~CPUID_AMD_EDX_TSCP;
19374628Skk208521 			if ((x86_feature & X86_SSE4A) == 0)
19384628Skk208521 				*ecx &= ~CPUID_AMD_ECX_SSE4A;
19393446Smrj 			break;
19403446Smrj 
19413446Smrj 		default:
19423446Smrj 			break;
19433446Smrj 		}
19440Sstevel@tonic-gate 
19450Sstevel@tonic-gate 		/*
19460Sstevel@tonic-gate 		 * [no explicit support required beyond
19470Sstevel@tonic-gate 		 * x87 fp context and exception handlers]
19480Sstevel@tonic-gate 		 */
19490Sstevel@tonic-gate 		if (!fpu_exists)
19500Sstevel@tonic-gate 			*edx &= ~(CPUID_AMD_EDX_MMXamd |
19510Sstevel@tonic-gate 			    CPUID_AMD_EDX_3DNow | CPUID_AMD_EDX_3DNowx);
19520Sstevel@tonic-gate 
19530Sstevel@tonic-gate 		if ((x86_feature & X86_NX) == 0)
19540Sstevel@tonic-gate 			*edx &= ~CPUID_AMD_EDX_NX;
19553446Smrj #if !defined(__amd64)
19560Sstevel@tonic-gate 		*edx &= ~CPUID_AMD_EDX_LM;
19570Sstevel@tonic-gate #endif
19580Sstevel@tonic-gate 		/*
19590Sstevel@tonic-gate 		 * Now map the supported feature vector to
19600Sstevel@tonic-gate 		 * things that we think userland will care about.
19610Sstevel@tonic-gate 		 */
19623446Smrj #if defined(__amd64)
19630Sstevel@tonic-gate 		if (*edx & CPUID_AMD_EDX_SYSC)
19640Sstevel@tonic-gate 			hwcap_flags |= AV_386_AMD_SYSC;
19653446Smrj #endif
19660Sstevel@tonic-gate 		if (*edx & CPUID_AMD_EDX_MMXamd)
19670Sstevel@tonic-gate 			hwcap_flags |= AV_386_AMD_MMX;
19680Sstevel@tonic-gate 		if (*edx & CPUID_AMD_EDX_3DNow)
19690Sstevel@tonic-gate 			hwcap_flags |= AV_386_AMD_3DNow;
19700Sstevel@tonic-gate 		if (*edx & CPUID_AMD_EDX_3DNowx)
19710Sstevel@tonic-gate 			hwcap_flags |= AV_386_AMD_3DNowx;
19723446Smrj 
19733446Smrj 		switch (cpi->cpi_vendor) {
19743446Smrj 		case X86_VENDOR_AMD:
19753446Smrj 			if (*edx & CPUID_AMD_EDX_TSCP)
19763446Smrj 				hwcap_flags |= AV_386_TSCP;
19773446Smrj 			if (*ecx & CPUID_AMD_ECX_AHF64)
19783446Smrj 				hwcap_flags |= AV_386_AHF;
19794628Skk208521 			if (*ecx & CPUID_AMD_ECX_SSE4A)
19804628Skk208521 				hwcap_flags |= AV_386_AMD_SSE4A;
19814628Skk208521 			if (*ecx & CPUID_AMD_ECX_LZCNT)
19824628Skk208521 				hwcap_flags |= AV_386_AMD_LZCNT;
19833446Smrj 			break;
19843446Smrj 
19853446Smrj 		case X86_VENDOR_Intel:
19863446Smrj 			/*
19873446Smrj 			 * Aarrgh.
19883446Smrj 			 * Intel uses a different bit in the same word.
19893446Smrj 			 */
19903446Smrj 			if (*ecx & CPUID_INTC_ECX_AHF64)
19913446Smrj 				hwcap_flags |= AV_386_AHF;
19923446Smrj 			break;
19933446Smrj 
19943446Smrj 		default:
19953446Smrj 			break;
19963446Smrj 		}
19970Sstevel@tonic-gate 		break;
19980Sstevel@tonic-gate 
19990Sstevel@tonic-gate 	case X86_VENDOR_TM:
20001228Sandrei 		cp.cp_eax = 0x80860001;
20011228Sandrei 		(void) __cpuid_insn(&cp);
20021228Sandrei 		cpi->cpi_support[TM_EDX_FEATURES] = cp.cp_edx;
20030Sstevel@tonic-gate 		break;
20040Sstevel@tonic-gate 
20050Sstevel@tonic-gate 	default:
20060Sstevel@tonic-gate 		break;
20070Sstevel@tonic-gate 	}
20080Sstevel@tonic-gate 
20090Sstevel@tonic-gate pass4_done:
20100Sstevel@tonic-gate 	cpi->cpi_pass = 4;
20110Sstevel@tonic-gate 	return (hwcap_flags);
20120Sstevel@tonic-gate }
20130Sstevel@tonic-gate 
20140Sstevel@tonic-gate 
20150Sstevel@tonic-gate /*
20160Sstevel@tonic-gate  * Simulate the cpuid instruction using the data we previously
20170Sstevel@tonic-gate  * captured about this CPU.  We try our best to return the truth
20180Sstevel@tonic-gate  * about the hardware, independently of kernel support.
20190Sstevel@tonic-gate  */
20200Sstevel@tonic-gate uint32_t
20211228Sandrei cpuid_insn(cpu_t *cpu, struct cpuid_regs *cp)
20220Sstevel@tonic-gate {
20230Sstevel@tonic-gate 	struct cpuid_info *cpi;
20241228Sandrei 	struct cpuid_regs *xcp;
20250Sstevel@tonic-gate 
20260Sstevel@tonic-gate 	if (cpu == NULL)
20270Sstevel@tonic-gate 		cpu = CPU;
20280Sstevel@tonic-gate 	cpi = cpu->cpu_m.mcpu_cpi;
20290Sstevel@tonic-gate 
20300Sstevel@tonic-gate 	ASSERT(cpuid_checkpass(cpu, 3));
20310Sstevel@tonic-gate 
20320Sstevel@tonic-gate 	/*
20330Sstevel@tonic-gate 	 * CPUID data is cached in two separate places: cpi_std for standard
20340Sstevel@tonic-gate 	 * CPUID functions, and cpi_extd for extended CPUID functions.
20350Sstevel@tonic-gate 	 */
20361228Sandrei 	if (cp->cp_eax <= cpi->cpi_maxeax && cp->cp_eax < NMAX_CPI_STD)
20371228Sandrei 		xcp = &cpi->cpi_std[cp->cp_eax];
20381228Sandrei 	else if (cp->cp_eax >= 0x80000000 && cp->cp_eax <= cpi->cpi_xmaxeax &&
20391228Sandrei 	    cp->cp_eax < 0x80000000 + NMAX_CPI_EXTD)
20401228Sandrei 		xcp = &cpi->cpi_extd[cp->cp_eax - 0x80000000];
20410Sstevel@tonic-gate 	else
20420Sstevel@tonic-gate 		/*
20430Sstevel@tonic-gate 		 * The caller is asking for data from an input parameter which
20440Sstevel@tonic-gate 		 * the kernel has not cached.  In this case we go fetch from
20450Sstevel@tonic-gate 		 * the hardware and return the data directly to the user.
20460Sstevel@tonic-gate 		 */
20471228Sandrei 		return (__cpuid_insn(cp));
20481228Sandrei 
20491228Sandrei 	cp->cp_eax = xcp->cp_eax;
20501228Sandrei 	cp->cp_ebx = xcp->cp_ebx;
20511228Sandrei 	cp->cp_ecx = xcp->cp_ecx;
20521228Sandrei 	cp->cp_edx = xcp->cp_edx;
20530Sstevel@tonic-gate 	return (cp->cp_eax);
20540Sstevel@tonic-gate }
20550Sstevel@tonic-gate 
20560Sstevel@tonic-gate int
20570Sstevel@tonic-gate cpuid_checkpass(cpu_t *cpu, int pass)
20580Sstevel@tonic-gate {
20590Sstevel@tonic-gate 	return (cpu != NULL && cpu->cpu_m.mcpu_cpi != NULL &&
20600Sstevel@tonic-gate 	    cpu->cpu_m.mcpu_cpi->cpi_pass >= pass);
20610Sstevel@tonic-gate }
20620Sstevel@tonic-gate 
20630Sstevel@tonic-gate int
20640Sstevel@tonic-gate cpuid_getbrandstr(cpu_t *cpu, char *s, size_t n)
20650Sstevel@tonic-gate {
20660Sstevel@tonic-gate 	ASSERT(cpuid_checkpass(cpu, 3));
20670Sstevel@tonic-gate 
20680Sstevel@tonic-gate 	return (snprintf(s, n, "%s", cpu->cpu_m.mcpu_cpi->cpi_brandstr));
20690Sstevel@tonic-gate }
20700Sstevel@tonic-gate 
20710Sstevel@tonic-gate int
20721228Sandrei cpuid_is_cmt(cpu_t *cpu)
20730Sstevel@tonic-gate {
20740Sstevel@tonic-gate 	if (cpu == NULL)
20750Sstevel@tonic-gate 		cpu = CPU;
20760Sstevel@tonic-gate 
20770Sstevel@tonic-gate 	ASSERT(cpuid_checkpass(cpu, 1));
20780Sstevel@tonic-gate 
20790Sstevel@tonic-gate 	return (cpu->cpu_m.mcpu_cpi->cpi_chipid >= 0);
20800Sstevel@tonic-gate }
20810Sstevel@tonic-gate 
20820Sstevel@tonic-gate /*
20830Sstevel@tonic-gate  * AMD and Intel both implement the 64-bit variant of the syscall
20840Sstevel@tonic-gate  * instruction (syscallq), so if there's -any- support for syscall,
20850Sstevel@tonic-gate  * cpuid currently says "yes, we support this".
20860Sstevel@tonic-gate  *
20870Sstevel@tonic-gate  * However, Intel decided to -not- implement the 32-bit variant of the
20880Sstevel@tonic-gate  * syscall instruction, so we provide a predicate to allow our caller
20890Sstevel@tonic-gate  * to test that subtlety here.
20900Sstevel@tonic-gate  */
20910Sstevel@tonic-gate /*ARGSUSED*/
20920Sstevel@tonic-gate int
20930Sstevel@tonic-gate cpuid_syscall32_insn(cpu_t *cpu)
20940Sstevel@tonic-gate {
20950Sstevel@tonic-gate 	ASSERT(cpuid_checkpass((cpu == NULL ? CPU : cpu), 1));
20960Sstevel@tonic-gate 
20973446Smrj 	if (cpu == NULL)
20983446Smrj 		cpu = CPU;
20993446Smrj 
21003446Smrj 	/*CSTYLED*/
21013446Smrj 	{
21023446Smrj 		struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi;
21033446Smrj 
21043446Smrj 		if (cpi->cpi_vendor == X86_VENDOR_AMD &&
21053446Smrj 		    cpi->cpi_xmaxeax >= 0x80000001 &&
21063446Smrj 		    (CPI_FEATURES_XTD_EDX(cpi) & CPUID_AMD_EDX_SYSC))
21073446Smrj 			return (1);
21083446Smrj 	}
21090Sstevel@tonic-gate 	return (0);
21100Sstevel@tonic-gate }
21110Sstevel@tonic-gate 
21120Sstevel@tonic-gate int
21130Sstevel@tonic-gate cpuid_getidstr(cpu_t *cpu, char *s, size_t n)
21140Sstevel@tonic-gate {
21150Sstevel@tonic-gate 	struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi;
21160Sstevel@tonic-gate 
21170Sstevel@tonic-gate 	static const char fmt[] =
21183779Sdmick 	    "x86 (%s %X family %d model %d step %d clock %d MHz)";
21190Sstevel@tonic-gate 	static const char fmt_ht[] =
21203779Sdmick 	    "x86 (chipid 0x%x %s %X family %d model %d step %d clock %d MHz)";
21210Sstevel@tonic-gate 
21220Sstevel@tonic-gate 	ASSERT(cpuid_checkpass(cpu, 1));
21230Sstevel@tonic-gate 
21241228Sandrei 	if (cpuid_is_cmt(cpu))
21250Sstevel@tonic-gate 		return (snprintf(s, n, fmt_ht, cpi->cpi_chipid,
21263779Sdmick 		    cpi->cpi_vendorstr, cpi->cpi_std[1].cp_eax,
21273779Sdmick 		    cpi->cpi_family, cpi->cpi_model,
21280Sstevel@tonic-gate 		    cpi->cpi_step, cpu->cpu_type_info.pi_clock));
21290Sstevel@tonic-gate 	return (snprintf(s, n, fmt,
21303779Sdmick 	    cpi->cpi_vendorstr, cpi->cpi_std[1].cp_eax,
21313779Sdmick 	    cpi->cpi_family, cpi->cpi_model,
21320Sstevel@tonic-gate 	    cpi->cpi_step, cpu->cpu_type_info.pi_clock));
21330Sstevel@tonic-gate }
21340Sstevel@tonic-gate 
21350Sstevel@tonic-gate const char *
21360Sstevel@tonic-gate cpuid_getvendorstr(cpu_t *cpu)
21370Sstevel@tonic-gate {
21380Sstevel@tonic-gate 	ASSERT(cpuid_checkpass(cpu, 1));
21390Sstevel@tonic-gate 	return ((const char *)cpu->cpu_m.mcpu_cpi->cpi_vendorstr);
21400Sstevel@tonic-gate }
21410Sstevel@tonic-gate 
21420Sstevel@tonic-gate uint_t
21430Sstevel@tonic-gate cpuid_getvendor(cpu_t *cpu)
21440Sstevel@tonic-gate {
21450Sstevel@tonic-gate 	ASSERT(cpuid_checkpass(cpu, 1));
21460Sstevel@tonic-gate 	return (cpu->cpu_m.mcpu_cpi->cpi_vendor);
21470Sstevel@tonic-gate }
21480Sstevel@tonic-gate 
21490Sstevel@tonic-gate uint_t
21500Sstevel@tonic-gate cpuid_getfamily(cpu_t *cpu)
21510Sstevel@tonic-gate {
21520Sstevel@tonic-gate 	ASSERT(cpuid_checkpass(cpu, 1));
21530Sstevel@tonic-gate 	return (cpu->cpu_m.mcpu_cpi->cpi_family);
21540Sstevel@tonic-gate }
21550Sstevel@tonic-gate 
21560Sstevel@tonic-gate uint_t
21570Sstevel@tonic-gate cpuid_getmodel(cpu_t *cpu)
21580Sstevel@tonic-gate {
21590Sstevel@tonic-gate 	ASSERT(cpuid_checkpass(cpu, 1));
21600Sstevel@tonic-gate 	return (cpu->cpu_m.mcpu_cpi->cpi_model);
21610Sstevel@tonic-gate }
21620Sstevel@tonic-gate 
21630Sstevel@tonic-gate uint_t
21640Sstevel@tonic-gate cpuid_get_ncpu_per_chip(cpu_t *cpu)
21650Sstevel@tonic-gate {
21660Sstevel@tonic-gate 	ASSERT(cpuid_checkpass(cpu, 1));
21670Sstevel@tonic-gate 	return (cpu->cpu_m.mcpu_cpi->cpi_ncpu_per_chip);
21680Sstevel@tonic-gate }
21690Sstevel@tonic-gate 
21700Sstevel@tonic-gate uint_t
21711228Sandrei cpuid_get_ncore_per_chip(cpu_t *cpu)
21721228Sandrei {
21731228Sandrei 	ASSERT(cpuid_checkpass(cpu, 1));
21741228Sandrei 	return (cpu->cpu_m.mcpu_cpi->cpi_ncore_per_chip);
21751228Sandrei }
21761228Sandrei 
21771228Sandrei uint_t
21784606Sesaxe cpuid_get_ncpu_sharing_last_cache(cpu_t *cpu)
21794606Sesaxe {
21804606Sesaxe 	ASSERT(cpuid_checkpass(cpu, 2));
21814606Sesaxe 	return (cpu->cpu_m.mcpu_cpi->cpi_ncpu_shr_last_cache);
21824606Sesaxe }
21834606Sesaxe 
21844606Sesaxe id_t
21854606Sesaxe cpuid_get_last_lvl_cacheid(cpu_t *cpu)
21864606Sesaxe {
21874606Sesaxe 	ASSERT(cpuid_checkpass(cpu, 2));
21884606Sesaxe 	return (cpu->cpu_m.mcpu_cpi->cpi_last_lvl_cacheid);
21894606Sesaxe }
21904606Sesaxe 
21914606Sesaxe uint_t
21920Sstevel@tonic-gate cpuid_getstep(cpu_t *cpu)
21930Sstevel@tonic-gate {
21940Sstevel@tonic-gate 	ASSERT(cpuid_checkpass(cpu, 1));
21950Sstevel@tonic-gate 	return (cpu->cpu_m.mcpu_cpi->cpi_step);
21960Sstevel@tonic-gate }
21970Sstevel@tonic-gate 
21984581Ssherrym uint_t
21994581Ssherrym cpuid_getsig(struct cpu *cpu)
22004581Ssherrym {
22014581Ssherrym 	ASSERT(cpuid_checkpass(cpu, 1));
22024581Ssherrym 	return (cpu->cpu_m.mcpu_cpi->cpi_std[1].cp_eax);
22034581Ssherrym }
22044581Ssherrym 
22052869Sgavinm uint32_t
22062869Sgavinm cpuid_getchiprev(struct cpu *cpu)
22072869Sgavinm {
22082869Sgavinm 	ASSERT(cpuid_checkpass(cpu, 1));
22092869Sgavinm 	return (cpu->cpu_m.mcpu_cpi->cpi_chiprev);
22102869Sgavinm }
22112869Sgavinm 
22122869Sgavinm const char *
22132869Sgavinm cpuid_getchiprevstr(struct cpu *cpu)
22142869Sgavinm {
22152869Sgavinm 	ASSERT(cpuid_checkpass(cpu, 1));
22162869Sgavinm 	return (cpu->cpu_m.mcpu_cpi->cpi_chiprevstr);
22172869Sgavinm }
22182869Sgavinm 
22192869Sgavinm uint32_t
22202869Sgavinm cpuid_getsockettype(struct cpu *cpu)
22212869Sgavinm {
22222869Sgavinm 	ASSERT(cpuid_checkpass(cpu, 1));
22232869Sgavinm 	return (cpu->cpu_m.mcpu_cpi->cpi_socket);
22242869Sgavinm }
22252869Sgavinm 
22263434Sesaxe int
22273434Sesaxe cpuid_get_chipid(cpu_t *cpu)
22280Sstevel@tonic-gate {
22290Sstevel@tonic-gate 	ASSERT(cpuid_checkpass(cpu, 1));
22300Sstevel@tonic-gate 
22311228Sandrei 	if (cpuid_is_cmt(cpu))
22320Sstevel@tonic-gate 		return (cpu->cpu_m.mcpu_cpi->cpi_chipid);
22330Sstevel@tonic-gate 	return (cpu->cpu_id);
22340Sstevel@tonic-gate }
22350Sstevel@tonic-gate 
22361228Sandrei id_t
22373434Sesaxe cpuid_get_coreid(cpu_t *cpu)
22381228Sandrei {
22391228Sandrei 	ASSERT(cpuid_checkpass(cpu, 1));
22401228Sandrei 	return (cpu->cpu_m.mcpu_cpi->cpi_coreid);
22411228Sandrei }
22421228Sandrei 
22430Sstevel@tonic-gate int
22443434Sesaxe cpuid_get_clogid(cpu_t *cpu)
22450Sstevel@tonic-gate {
22460Sstevel@tonic-gate 	ASSERT(cpuid_checkpass(cpu, 1));
22470Sstevel@tonic-gate 	return (cpu->cpu_m.mcpu_cpi->cpi_clogid);
22480Sstevel@tonic-gate }
22490Sstevel@tonic-gate 
22500Sstevel@tonic-gate void
22510Sstevel@tonic-gate cpuid_get_addrsize(cpu_t *cpu, uint_t *pabits, uint_t *vabits)
22520Sstevel@tonic-gate {
22530Sstevel@tonic-gate 	struct cpuid_info *cpi;
22540Sstevel@tonic-gate 
22550Sstevel@tonic-gate 	if (cpu == NULL)
22560Sstevel@tonic-gate 		cpu = CPU;
22570Sstevel@tonic-gate 	cpi = cpu->cpu_m.mcpu_cpi;
22580Sstevel@tonic-gate 
22590Sstevel@tonic-gate 	ASSERT(cpuid_checkpass(cpu, 1));
22600Sstevel@tonic-gate 
22610Sstevel@tonic-gate 	if (pabits)
22620Sstevel@tonic-gate 		*pabits = cpi->cpi_pabits;
22630Sstevel@tonic-gate 	if (vabits)
22640Sstevel@tonic-gate 		*vabits = cpi->cpi_vabits;
22650Sstevel@tonic-gate }
22660Sstevel@tonic-gate 
22670Sstevel@tonic-gate /*
22680Sstevel@tonic-gate  * Returns the number of data TLB entries for a corresponding
22690Sstevel@tonic-gate  * pagesize.  If it can't be computed, or isn't known, the
22700Sstevel@tonic-gate  * routine returns zero.  If you ask about an architecturally
22710Sstevel@tonic-gate  * impossible pagesize, the routine will panic (so that the
22720Sstevel@tonic-gate  * hat implementor knows that things are inconsistent.)
22730Sstevel@tonic-gate  */
22740Sstevel@tonic-gate uint_t
22750Sstevel@tonic-gate cpuid_get_dtlb_nent(cpu_t *cpu, size_t pagesize)
22760Sstevel@tonic-gate {
22770Sstevel@tonic-gate 	struct cpuid_info *cpi;
22780Sstevel@tonic-gate 	uint_t dtlb_nent = 0;
22790Sstevel@tonic-gate 
22800Sstevel@tonic-gate 	if (cpu == NULL)
22810Sstevel@tonic-gate 		cpu = CPU;
22820Sstevel@tonic-gate 	cpi = cpu->cpu_m.mcpu_cpi;
22830Sstevel@tonic-gate 
22840Sstevel@tonic-gate 	ASSERT(cpuid_checkpass(cpu, 1));
22850Sstevel@tonic-gate 
22860Sstevel@tonic-gate 	/*
22870Sstevel@tonic-gate 	 * Check the L2 TLB info
22880Sstevel@tonic-gate 	 */
22890Sstevel@tonic-gate 	if (cpi->cpi_xmaxeax >= 0x80000006) {
22901228Sandrei 		struct cpuid_regs *cp = &cpi->cpi_extd[6];
22910Sstevel@tonic-gate 
22920Sstevel@tonic-gate 		switch (pagesize) {
22930Sstevel@tonic-gate 
22940Sstevel@tonic-gate 		case 4 * 1024:
22950Sstevel@tonic-gate 			/*
22960Sstevel@tonic-gate 			 * All zero in the top 16 bits of the register
22970Sstevel@tonic-gate 			 * indicates a unified TLB. Size is in low 16 bits.
22980Sstevel@tonic-gate 			 */
22990Sstevel@tonic-gate 			if ((cp->cp_ebx & 0xffff0000) == 0)
23000Sstevel@tonic-gate 				dtlb_nent = cp->cp_ebx & 0x0000ffff;
23010Sstevel@tonic-gate 			else
23020Sstevel@tonic-gate 				dtlb_nent = BITX(cp->cp_ebx, 27, 16);
23030Sstevel@tonic-gate 			break;
23040Sstevel@tonic-gate 
23050Sstevel@tonic-gate 		case 2 * 1024 * 1024:
23060Sstevel@tonic-gate 			if ((cp->cp_eax & 0xffff0000) == 0)
23070Sstevel@tonic-gate 				dtlb_nent = cp->cp_eax & 0x0000ffff;
23080Sstevel@tonic-gate 			else
23090Sstevel@tonic-gate 				dtlb_nent = BITX(cp->cp_eax, 27, 16);
23100Sstevel@tonic-gate 			break;
23110Sstevel@tonic-gate 
23120Sstevel@tonic-gate 		default:
23130Sstevel@tonic-gate 			panic("unknown L2 pagesize");
23140Sstevel@tonic-gate 			/*NOTREACHED*/
23150Sstevel@tonic-gate 		}
23160Sstevel@tonic-gate 	}
23170Sstevel@tonic-gate 
23180Sstevel@tonic-gate 	if (dtlb_nent != 0)
23190Sstevel@tonic-gate 		return (dtlb_nent);
23200Sstevel@tonic-gate 
23210Sstevel@tonic-gate 	/*
23220Sstevel@tonic-gate 	 * No L2 TLB support for this size, try L1.
23230Sstevel@tonic-gate 	 */
23240Sstevel@tonic-gate 	if (cpi->cpi_xmaxeax >= 0x80000005) {
23251228Sandrei 		struct cpuid_regs *cp = &cpi->cpi_extd[5];
23260Sstevel@tonic-gate 
23270Sstevel@tonic-gate 		switch (pagesize) {
23280Sstevel@tonic-gate 		case 4 * 1024:
23290Sstevel@tonic-gate 			dtlb_nent = BITX(cp->cp_ebx, 23, 16);
23300Sstevel@tonic-gate 			break;
23310Sstevel@tonic-gate 		case 2 * 1024 * 1024:
23320Sstevel@tonic-gate 			dtlb_nent = BITX(cp->cp_eax, 23, 16);
23330Sstevel@tonic-gate 			break;
23340Sstevel@tonic-gate 		default:
23350Sstevel@tonic-gate 			panic("unknown L1 d-TLB pagesize");
23360Sstevel@tonic-gate 			/*NOTREACHED*/
23370Sstevel@tonic-gate 		}
23380Sstevel@tonic-gate 	}
23390Sstevel@tonic-gate 
23400Sstevel@tonic-gate 	return (dtlb_nent);
23410Sstevel@tonic-gate }
23420Sstevel@tonic-gate 
23430Sstevel@tonic-gate /*
23440Sstevel@tonic-gate  * Return 0 if the erratum is not present or not applicable, positive
23450Sstevel@tonic-gate  * if it is, and negative if the status of the erratum is unknown.
23460Sstevel@tonic-gate  *
23470Sstevel@tonic-gate  * See "Revision Guide for AMD Athlon(tm) 64 and AMD Opteron(tm)
2348359Skucharsk  * Processors" #25759, Rev 3.57, August 2005
23490Sstevel@tonic-gate  */
23500Sstevel@tonic-gate int
23510Sstevel@tonic-gate cpuid_opteron_erratum(cpu_t *cpu, uint_t erratum)
23520Sstevel@tonic-gate {
23530Sstevel@tonic-gate 	struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi;
23541228Sandrei 	uint_t eax;
23550Sstevel@tonic-gate 
23562584Ssethg 	/*
23572584Ssethg 	 * Bail out if this CPU isn't an AMD CPU, or if it's
23582584Ssethg 	 * a legacy (32-bit) AMD CPU.
23592584Ssethg 	 */
23602584Ssethg 	if (cpi->cpi_vendor != X86_VENDOR_AMD ||
23614265Skchow 	    cpi->cpi_family == 4 || cpi->cpi_family == 5 ||
23624265Skchow 	    cpi->cpi_family == 6)
23632869Sgavinm 
23640Sstevel@tonic-gate 		return (0);
23650Sstevel@tonic-gate 
23660Sstevel@tonic-gate 	eax = cpi->cpi_std[1].cp_eax;
23670Sstevel@tonic-gate 
23680Sstevel@tonic-gate #define	SH_B0(eax)	(eax == 0xf40 || eax == 0xf50)
23690Sstevel@tonic-gate #define	SH_B3(eax) 	(eax == 0xf51)
23701582Skchow #define	B(eax)		(SH_B0(eax) || SH_B3(eax))
23710Sstevel@tonic-gate 
23720Sstevel@tonic-gate #define	SH_C0(eax)	(eax == 0xf48 || eax == 0xf58)
23730Sstevel@tonic-gate 
23740Sstevel@tonic-gate #define	SH_CG(eax)	(eax == 0xf4a || eax == 0xf5a || eax == 0xf7a)
23750Sstevel@tonic-gate #define	DH_CG(eax)	(eax == 0xfc0 || eax == 0xfe0 || eax == 0xff0)
23760Sstevel@tonic-gate #define	CH_CG(eax)	(eax == 0xf82 || eax == 0xfb2)
23771582Skchow #define	CG(eax)		(SH_CG(eax) || DH_CG(eax) || CH_CG(eax))
23780Sstevel@tonic-gate 
23790Sstevel@tonic-gate #define	SH_D0(eax)	(eax == 0x10f40 || eax == 0x10f50 || eax == 0x10f70)
23800Sstevel@tonic-gate #define	DH_D0(eax)	(eax == 0x10fc0 || eax == 0x10ff0)
23810Sstevel@tonic-gate #define	CH_D0(eax)	(eax == 0x10f80 || eax == 0x10fb0)
23821582Skchow #define	D0(eax)		(SH_D0(eax) || DH_D0(eax) || CH_D0(eax))
23830Sstevel@tonic-gate 
23840Sstevel@tonic-gate #define	SH_E0(eax)	(eax == 0x20f50 || eax == 0x20f40 || eax == 0x20f70)
23850Sstevel@tonic-gate #define	JH_E1(eax)	(eax == 0x20f10)	/* JH8_E0 had 0x20f30 */
23860Sstevel@tonic-gate #define	DH_E3(eax)	(eax == 0x20fc0 || eax == 0x20ff0)
23870Sstevel@tonic-gate #define	SH_E4(eax)	(eax == 0x20f51 || eax == 0x20f71)
23880Sstevel@tonic-gate #define	BH_E4(eax)	(eax == 0x20fb1)
23890Sstevel@tonic-gate #define	SH_E5(eax)	(eax == 0x20f42)
23900Sstevel@tonic-gate #define	DH_E6(eax)	(eax == 0x20ff2 || eax == 0x20fc2)
23910Sstevel@tonic-gate #define	JH_E6(eax)	(eax == 0x20f12 || eax == 0x20f32)
23921582Skchow #define	EX(eax)		(SH_E0(eax) || JH_E1(eax) || DH_E3(eax) || \
23931582Skchow 			    SH_E4(eax) || BH_E4(eax) || SH_E5(eax) || \
23941582Skchow 			    DH_E6(eax) || JH_E6(eax))
23950Sstevel@tonic-gate 
23960Sstevel@tonic-gate 	switch (erratum) {
23970Sstevel@tonic-gate 	case 1:
23984265Skchow 		return (cpi->cpi_family < 0x10);
23990Sstevel@tonic-gate 	case 51:	/* what does the asterisk mean? */
24000Sstevel@tonic-gate 		return (B(eax) || SH_C0(eax) || CG(eax));
24010Sstevel@tonic-gate 	case 52:
24020Sstevel@tonic-gate 		return (B(eax));
24030Sstevel@tonic-gate 	case 57:
24044265Skchow 		return (cpi->cpi_family <= 0x10);
24050Sstevel@tonic-gate 	case 58:
24060Sstevel@tonic-gate 		return (B(eax));
24070Sstevel@tonic-gate 	case 60:
24084265Skchow 		return (cpi->cpi_family <= 0x10);
24090Sstevel@tonic-gate 	case 61:
24100Sstevel@tonic-gate 	case 62:
24110Sstevel@tonic-gate 	case 63:
24120Sstevel@tonic-gate 	case 64:
24130Sstevel@tonic-gate 	case 65:
24140Sstevel@tonic-gate 	case 66:
24150Sstevel@tonic-gate 	case 68:
24160Sstevel@tonic-gate 	case 69:
24170Sstevel@tonic-gate 	case 70:
24180Sstevel@tonic-gate 	case 71:
24190Sstevel@tonic-gate 		return (B(eax));
24200Sstevel@tonic-gate 	case 72:
24210Sstevel@tonic-gate 		return (SH_B0(eax));
24220Sstevel@tonic-gate 	case 74:
24230Sstevel@tonic-gate 		return (B(eax));
24240Sstevel@tonic-gate 	case 75:
24254265Skchow 		return (cpi->cpi_family < 0x10);
24260Sstevel@tonic-gate 	case 76:
24270Sstevel@tonic-gate 		return (B(eax));
24280Sstevel@tonic-gate 	case 77:
24294265Skchow 		return (cpi->cpi_family <= 0x10);
24300Sstevel@tonic-gate 	case 78:
24310Sstevel@tonic-gate 		return (B(eax) || SH_C0(eax));
24320Sstevel@tonic-gate 	case 79:
24330Sstevel@tonic-gate 		return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax) || EX(eax));
24340Sstevel@tonic-gate 	case 80:
24350Sstevel@tonic-gate 	case 81:
24360Sstevel@tonic-gate 	case 82:
24370Sstevel@tonic-gate 		return (B(eax));
24380Sstevel@tonic-gate 	case 83:
24390Sstevel@tonic-gate 		return (B(eax) || SH_C0(eax) || CG(eax));
24400Sstevel@tonic-gate 	case 85:
24414265Skchow 		return (cpi->cpi_family < 0x10);
24420Sstevel@tonic-gate 	case 86:
24430Sstevel@tonic-gate 		return (SH_C0(eax) || CG(eax));
24440Sstevel@tonic-gate 	case 88:
24450Sstevel@tonic-gate #if !defined(__amd64)
24460Sstevel@tonic-gate 		return (0);
24470Sstevel@tonic-gate #else
24480Sstevel@tonic-gate 		return (B(eax) || SH_C0(eax));
24490Sstevel@tonic-gate #endif
24500Sstevel@tonic-gate 	case 89:
24514265Skchow 		return (cpi->cpi_family < 0x10);
24520Sstevel@tonic-gate 	case 90:
24530Sstevel@tonic-gate 		return (B(eax) || SH_C0(eax) || CG(eax));
24540Sstevel@tonic-gate 	case 91:
24550Sstevel@tonic-gate 	case 92:
24560Sstevel@tonic-gate 		return (B(eax) || SH_C0(eax));
24570Sstevel@tonic-gate 	case 93:
24580Sstevel@tonic-gate 		return (SH_C0(eax));
24590Sstevel@tonic-gate 	case 94:
24600Sstevel@tonic-gate 		return (B(eax) || SH_C0(eax) || CG(eax));
24610Sstevel@tonic-gate 	case 95:
24620Sstevel@tonic-gate #if !defined(__amd64)
24630Sstevel@tonic-gate 		return (0);
24640Sstevel@tonic-gate #else
24650Sstevel@tonic-gate 		return (B(eax) || SH_C0(eax));
24660Sstevel@tonic-gate #endif
24670Sstevel@tonic-gate 	case 96:
24680Sstevel@tonic-gate 		return (B(eax) || SH_C0(eax) || CG(eax));
24690Sstevel@tonic-gate 	case 97:
24700Sstevel@tonic-gate 	case 98:
24710Sstevel@tonic-gate 		return (SH_C0(eax) || CG(eax));
24720Sstevel@tonic-gate 	case 99:
24730Sstevel@tonic-gate 		return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax));
24740Sstevel@tonic-gate 	case 100:
24750Sstevel@tonic-gate 		return (B(eax) || SH_C0(eax));
24760Sstevel@tonic-gate 	case 101:
24770Sstevel@tonic-gate 	case 103:
24780Sstevel@tonic-gate 		return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax));
24790Sstevel@tonic-gate 	case 104:
24800Sstevel@tonic-gate 		return (SH_C0(eax) || CG(eax) || D0(eax));
24810Sstevel@tonic-gate 	case 105:
24820Sstevel@tonic-gate 	case 106:
24830Sstevel@tonic-gate 	case 107:
24840Sstevel@tonic-gate 		return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax));
24850Sstevel@tonic-gate 	case 108:
24860Sstevel@tonic-gate 		return (DH_CG(eax));
24870Sstevel@tonic-gate 	case 109:
24880Sstevel@tonic-gate 		return (SH_C0(eax) || CG(eax) || D0(eax));
24890Sstevel@tonic-gate 	case 110:
24900Sstevel@tonic-gate 		return (D0(eax) || EX(eax));
24910Sstevel@tonic-gate 	case 111:
24920Sstevel@tonic-gate 		return (CG(eax));
24930Sstevel@tonic-gate 	case 112:
24940Sstevel@tonic-gate 		return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax) || EX(eax));
24950Sstevel@tonic-gate 	case 113:
24960Sstevel@tonic-gate 		return (eax == 0x20fc0);
24970Sstevel@tonic-gate 	case 114:
24980Sstevel@tonic-gate 		return (SH_E0(eax) || JH_E1(eax) || DH_E3(eax));
24990Sstevel@tonic-gate 	case 115:
25000Sstevel@tonic-gate 		return (SH_E0(eax) || JH_E1(eax));
25010Sstevel@tonic-gate 	case 116:
25020Sstevel@tonic-gate 		return (SH_E0(eax) || JH_E1(eax) || DH_E3(eax));
25030Sstevel@tonic-gate 	case 117:
25040Sstevel@tonic-gate 		return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax));
25050Sstevel@tonic-gate 	case 118:
25060Sstevel@tonic-gate 		return (SH_E0(eax) || JH_E1(eax) || SH_E4(eax) || BH_E4(eax) ||
25070Sstevel@tonic-gate 		    JH_E6(eax));
25080Sstevel@tonic-gate 	case 121:
25090Sstevel@tonic-gate 		return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax) || EX(eax));
25100Sstevel@tonic-gate 	case 122:
25114265Skchow 		return (cpi->cpi_family < 0x10);
25120Sstevel@tonic-gate 	case 123:
25130Sstevel@tonic-gate 		return (JH_E1(eax) || BH_E4(eax) || JH_E6(eax));
2514359Skucharsk 	case 131:
25154265Skchow 		return (cpi->cpi_family < 0x10);
2516938Sesaxe 	case 6336786:
2517938Sesaxe 		/*
2518938Sesaxe 		 * Test for AdvPowerMgmtInfo.TscPStateInvariant
25194265Skchow 		 * if this is a K8 family or newer processor
2520938Sesaxe 		 */
2521938Sesaxe 		if (CPI_FAMILY(cpi) == 0xf) {
25221228Sandrei 			struct cpuid_regs regs;
25231228Sandrei 			regs.cp_eax = 0x80000007;
25241228Sandrei 			(void) __cpuid_insn(&regs);
25251228Sandrei 			return (!(regs.cp_edx & 0x100));
2526938Sesaxe 		}
2527938Sesaxe 		return (0);
25281582Skchow 	case 6323525:
25291582Skchow 		return (((((eax >> 12) & 0xff00) + (eax & 0xf00)) |
25301582Skchow 		    (((eax >> 4) & 0xf) | ((eax >> 12) & 0xf0))) < 0xf40);
25311582Skchow 
25320Sstevel@tonic-gate 	default:
25330Sstevel@tonic-gate 		return (-1);
25340Sstevel@tonic-gate 	}
25350Sstevel@tonic-gate }
25360Sstevel@tonic-gate 
25370Sstevel@tonic-gate static const char assoc_str[] = "associativity";
25380Sstevel@tonic-gate static const char line_str[] = "line-size";
25390Sstevel@tonic-gate static const char size_str[] = "size";
25400Sstevel@tonic-gate 
25410Sstevel@tonic-gate static void
25420Sstevel@tonic-gate add_cache_prop(dev_info_t *devi, const char *label, const char *type,
25430Sstevel@tonic-gate     uint32_t val)
25440Sstevel@tonic-gate {
25450Sstevel@tonic-gate 	char buf[128];
25460Sstevel@tonic-gate 
25470Sstevel@tonic-gate 	/*
25480Sstevel@tonic-gate 	 * ndi_prop_update_int() is used because it is desirable for
25490Sstevel@tonic-gate 	 * DDI_PROP_HW_DEF and DDI_PROP_DONTSLEEP to be set.
25500Sstevel@tonic-gate 	 */
25510Sstevel@tonic-gate 	if (snprintf(buf, sizeof (buf), "%s-%s", label, type) < sizeof (buf))
25520Sstevel@tonic-gate 		(void) ndi_prop_update_int(DDI_DEV_T_NONE, devi, buf, val);
25530Sstevel@tonic-gate }
25540Sstevel@tonic-gate 
25550Sstevel@tonic-gate /*
25560Sstevel@tonic-gate  * Intel-style cache/tlb description
25570Sstevel@tonic-gate  *
25580Sstevel@tonic-gate  * Standard cpuid level 2 gives a randomly ordered
25590Sstevel@tonic-gate  * selection of tags that index into a table that describes
25600Sstevel@tonic-gate  * cache and tlb properties.
25610Sstevel@tonic-gate  */
25620Sstevel@tonic-gate 
25630Sstevel@tonic-gate static const char l1_icache_str[] = "l1-icache";
25640Sstevel@tonic-gate static const char l1_dcache_str[] = "l1-dcache";
25650Sstevel@tonic-gate static const char l2_cache_str[] = "l2-cache";
25663446Smrj static const char l3_cache_str[] = "l3-cache";
25670Sstevel@tonic-gate static const char itlb4k_str[] = "itlb-4K";
25680Sstevel@tonic-gate static const char dtlb4k_str[] = "dtlb-4K";
25690Sstevel@tonic-gate static const char itlb4M_str[] = "itlb-4M";
25700Sstevel@tonic-gate static const char dtlb4M_str[] = "dtlb-4M";
25710Sstevel@tonic-gate static const char itlb424_str[] = "itlb-4K-2M-4M";
25720Sstevel@tonic-gate static const char dtlb44_str[] = "dtlb-4K-4M";
25730Sstevel@tonic-gate static const char sl1_dcache_str[] = "sectored-l1-dcache";
25740Sstevel@tonic-gate static const char sl2_cache_str[] = "sectored-l2-cache";
25750Sstevel@tonic-gate static const char itrace_str[] = "itrace-cache";
25760Sstevel@tonic-gate static const char sl3_cache_str[] = "sectored-l3-cache";
25770Sstevel@tonic-gate 
25780Sstevel@tonic-gate static const struct cachetab {
25790Sstevel@tonic-gate 	uint8_t 	ct_code;
25800Sstevel@tonic-gate 	uint8_t		ct_assoc;
25810Sstevel@tonic-gate 	uint16_t 	ct_line_size;
25820Sstevel@tonic-gate 	size_t		ct_size;
25830Sstevel@tonic-gate 	const char	*ct_label;
25840Sstevel@tonic-gate } intel_ctab[] = {
25850Sstevel@tonic-gate 	/* maintain descending order! */
25863446Smrj 	{ 0xb4, 4, 0, 256, dtlb4k_str },
25870Sstevel@tonic-gate 	{ 0xb3, 4, 0, 128, dtlb4k_str },
25880Sstevel@tonic-gate 	{ 0xb0, 4, 0, 128, itlb4k_str },
25890Sstevel@tonic-gate 	{ 0x87, 8, 64, 1024*1024, l2_cache_str},
25900Sstevel@tonic-gate 	{ 0x86, 4, 64, 512*1024, l2_cache_str},
25910Sstevel@tonic-gate 	{ 0x85, 8, 32, 2*1024*1024, l2_cache_str},
25920Sstevel@tonic-gate 	{ 0x84, 8, 32, 1024*1024, l2_cache_str},
25930Sstevel@tonic-gate 	{ 0x83, 8, 32, 512*1024, l2_cache_str},
25940Sstevel@tonic-gate 	{ 0x82, 8, 32, 256*1024, l2_cache_str},
25950Sstevel@tonic-gate 	{ 0x7f, 2, 64, 512*1024, l2_cache_str},
25960Sstevel@tonic-gate 	{ 0x7d, 8, 64, 2*1024*1024, sl2_cache_str},
25970Sstevel@tonic-gate 	{ 0x7c, 8, 64, 1024*1024, sl2_cache_str},
25980Sstevel@tonic-gate 	{ 0x7b, 8, 64, 512*1024, sl2_cache_str},
25990Sstevel@tonic-gate 	{ 0x7a, 8, 64, 256*1024, sl2_cache_str},
26000Sstevel@tonic-gate 	{ 0x79, 8, 64, 128*1024, sl2_cache_str},
26010Sstevel@tonic-gate 	{ 0x78, 8, 64, 1024*1024, l2_cache_str},
26023446Smrj 	{ 0x73, 8, 0, 64*1024, itrace_str},
26030Sstevel@tonic-gate 	{ 0x72, 8, 0, 32*1024, itrace_str},
26040Sstevel@tonic-gate 	{ 0x71, 8, 0, 16*1024, itrace_str},
26050Sstevel@tonic-gate 	{ 0x70, 8, 0, 12*1024, itrace_str},
26060Sstevel@tonic-gate 	{ 0x68, 4, 64, 32*1024, sl1_dcache_str},
26070Sstevel@tonic-gate 	{ 0x67, 4, 64, 16*1024, sl1_dcache_str},
26080Sstevel@tonic-gate 	{ 0x66, 4, 64, 8*1024, sl1_dcache_str},
26090Sstevel@tonic-gate 	{ 0x60, 8, 64, 16*1024, sl1_dcache_str},
26100Sstevel@tonic-gate 	{ 0x5d, 0, 0, 256, dtlb44_str},
26110Sstevel@tonic-gate 	{ 0x5c, 0, 0, 128, dtlb44_str},
26120Sstevel@tonic-gate 	{ 0x5b, 0, 0, 64, dtlb44_str},
26130Sstevel@tonic-gate 	{ 0x52, 0, 0, 256, itlb424_str},
26140Sstevel@tonic-gate 	{ 0x51, 0, 0, 128, itlb424_str},
26150Sstevel@tonic-gate 	{ 0x50, 0, 0, 64, itlb424_str},
26163446Smrj 	{ 0x4d, 16, 64, 16*1024*1024, l3_cache_str},
26173446Smrj 	{ 0x4c, 12, 64, 12*1024*1024, l3_cache_str},
26183446Smrj 	{ 0x4b, 16, 64, 8*1024*1024, l3_cache_str},
26193446Smrj 	{ 0x4a, 12, 64, 6*1024*1024, l3_cache_str},
26203446Smrj 	{ 0x49, 16, 64, 4*1024*1024, l3_cache_str},
26213446Smrj 	{ 0x47, 8, 64, 8*1024*1024, l3_cache_str},
26223446Smrj 	{ 0x46, 4, 64, 4*1024*1024, l3_cache_str},
26230Sstevel@tonic-gate 	{ 0x45, 4, 32, 2*1024*1024, l2_cache_str},
26240Sstevel@tonic-gate 	{ 0x44, 4, 32, 1024*1024, l2_cache_str},
26250Sstevel@tonic-gate 	{ 0x43, 4, 32, 512*1024, l2_cache_str},
26260Sstevel@tonic-gate 	{ 0x42, 4, 32, 256*1024, l2_cache_str},
26270Sstevel@tonic-gate 	{ 0x41, 4, 32, 128*1024, l2_cache_str},
26283446Smrj 	{ 0x3e, 4, 64, 512*1024, sl2_cache_str},
26293446Smrj 	{ 0x3d, 6, 64, 384*1024, sl2_cache_str},
26300Sstevel@tonic-gate 	{ 0x3c, 4, 64, 256*1024, sl2_cache_str},
26310Sstevel@tonic-gate 	{ 0x3b, 2, 64, 128*1024, sl2_cache_str},
26323446Smrj 	{ 0x3a, 6, 64, 192*1024, sl2_cache_str},
26330Sstevel@tonic-gate 	{ 0x39, 4, 64, 128*1024, sl2_cache_str},
26340Sstevel@tonic-gate 	{ 0x30, 8, 64, 32*1024, l1_icache_str},
26350Sstevel@tonic-gate 	{ 0x2c, 8, 64, 32*1024, l1_dcache_str},
26360Sstevel@tonic-gate 	{ 0x29, 8, 64, 4096*1024, sl3_cache_str},
26370Sstevel@tonic-gate 	{ 0x25, 8, 64, 2048*1024, sl3_cache_str},
26380Sstevel@tonic-gate 	{ 0x23, 8, 64, 1024*1024, sl3_cache_str},
26390Sstevel@tonic-gate 	{ 0x22, 4, 64, 512*1024, sl3_cache_str},
26400Sstevel@tonic-gate 	{ 0x0c, 4, 32, 16*1024, l1_dcache_str},
26413446Smrj 	{ 0x0b, 4, 0, 4, itlb4M_str},
26420Sstevel@tonic-gate 	{ 0x0a, 2, 32, 8*1024, l1_dcache_str},
26430Sstevel@tonic-gate 	{ 0x08, 4, 32, 16*1024, l1_icache_str},
26440Sstevel@tonic-gate 	{ 0x06, 4, 32, 8*1024, l1_icache_str},
26450Sstevel@tonic-gate 	{ 0x04, 4, 0, 8, dtlb4M_str},
26460Sstevel@tonic-gate 	{ 0x03, 4, 0, 64, dtlb4k_str},
26470Sstevel@tonic-gate 	{ 0x02, 4, 0, 2, itlb4M_str},
26480Sstevel@tonic-gate 	{ 0x01, 4, 0, 32, itlb4k_str},
26490Sstevel@tonic-gate 	{ 0 }
26500Sstevel@tonic-gate };
26510Sstevel@tonic-gate 
26520Sstevel@tonic-gate static const struct cachetab cyrix_ctab[] = {
26530Sstevel@tonic-gate 	{ 0x70, 4, 0, 32, "tlb-4K" },
26540Sstevel@tonic-gate 	{ 0x80, 4, 16, 16*1024, "l1-cache" },
26550Sstevel@tonic-gate 	{ 0 }
26560Sstevel@tonic-gate };
26570Sstevel@tonic-gate 
26580Sstevel@tonic-gate /*
26590Sstevel@tonic-gate  * Search a cache table for a matching entry
26600Sstevel@tonic-gate  */
26610Sstevel@tonic-gate static const struct cachetab *
26620Sstevel@tonic-gate find_cacheent(const struct cachetab *ct, uint_t code)
26630Sstevel@tonic-gate {
26640Sstevel@tonic-gate 	if (code != 0) {
26650Sstevel@tonic-gate 		for (; ct->ct_code != 0; ct++)
26660Sstevel@tonic-gate 			if (ct->ct_code <= code)
26670Sstevel@tonic-gate 				break;
26680Sstevel@tonic-gate 		if (ct->ct_code == code)
26690Sstevel@tonic-gate 			return (ct);
26700Sstevel@tonic-gate 	}
26710Sstevel@tonic-gate 	return (NULL);
26720Sstevel@tonic-gate }
26730Sstevel@tonic-gate 
26740Sstevel@tonic-gate /*
26750Sstevel@tonic-gate  * Walk the cacheinfo descriptor, applying 'func' to every valid element
26760Sstevel@tonic-gate  * The walk is terminated if the walker returns non-zero.
26770Sstevel@tonic-gate  */
26780Sstevel@tonic-gate static void
26790Sstevel@tonic-gate intel_walk_cacheinfo(struct cpuid_info *cpi,
26800Sstevel@tonic-gate     void *arg, int (*func)(void *, const struct cachetab *))
26810Sstevel@tonic-gate {
26820Sstevel@tonic-gate 	const struct cachetab *ct;
26830Sstevel@tonic-gate 	uint8_t *dp;
26840Sstevel@tonic-gate 	int i;
26850Sstevel@tonic-gate 
26860Sstevel@tonic-gate 	if ((dp = cpi->cpi_cacheinfo) == NULL)
26870Sstevel@tonic-gate 		return;
2688*4797Sksadhukh 	for (i = 0; i < cpi->cpi_ncache; i++, dp++) {
2689*4797Sksadhukh 		/*
2690*4797Sksadhukh 		 * For overloaded descriptor 0x49 we use cpuid function 4
2691*4797Sksadhukh 		 * if supported by the current processor, to update
2692*4797Sksadhukh 		 * cache information.
2693*4797Sksadhukh 		 */
2694*4797Sksadhukh 		if (*dp == 0x49 && cpi->cpi_maxeax >= 0x4) {
2695*4797Sksadhukh 			intel_cpuid_4_cache_info(arg, cpi);
2696*4797Sksadhukh 			continue;
2697*4797Sksadhukh 		}
2698*4797Sksadhukh 
26990Sstevel@tonic-gate 		if ((ct = find_cacheent(intel_ctab, *dp)) != NULL) {
27000Sstevel@tonic-gate 			if (func(arg, ct) != 0)
27010Sstevel@tonic-gate 				break;
27020Sstevel@tonic-gate 		}
2703*4797Sksadhukh 	}
27040Sstevel@tonic-gate }
27050Sstevel@tonic-gate 
27060Sstevel@tonic-gate /*
27070Sstevel@tonic-gate  * (Like the Intel one, except for Cyrix CPUs)
27080Sstevel@tonic-gate  */
27090Sstevel@tonic-gate static void
27100Sstevel@tonic-gate cyrix_walk_cacheinfo(struct cpuid_info *cpi,
27110Sstevel@tonic-gate     void *arg, int (*func)(void *, const struct cachetab *))
27120Sstevel@tonic-gate {
27130Sstevel@tonic-gate 	const struct cachetab *ct;
27140Sstevel@tonic-gate 	uint8_t *dp;
27150Sstevel@tonic-gate 	int i;
27160Sstevel@tonic-gate 
27170Sstevel@tonic-gate 	if ((dp = cpi->cpi_cacheinfo) == NULL)
27180Sstevel@tonic-gate 		return;
27190Sstevel@tonic-gate 	for (i = 0; i < cpi->cpi_ncache; i++, dp++) {
27200Sstevel@tonic-gate 		/*
27210Sstevel@tonic-gate 		 * Search Cyrix-specific descriptor table first ..
27220Sstevel@tonic-gate 		 */
27230Sstevel@tonic-gate 		if ((ct = find_cacheent(cyrix_ctab, *dp)) != NULL) {
27240Sstevel@tonic-gate 			if (func(arg, ct) != 0)
27250Sstevel@tonic-gate 				break;
27260Sstevel@tonic-gate 			continue;
27270Sstevel@tonic-gate 		}
27280Sstevel@tonic-gate 		/*
27290Sstevel@tonic-gate 		 * .. else fall back to the Intel one
27300Sstevel@tonic-gate 		 */
27310Sstevel@tonic-gate 		if ((ct = find_cacheent(intel_ctab, *dp)) != NULL) {
27320Sstevel@tonic-gate 			if (func(arg, ct) != 0)
27330Sstevel@tonic-gate 				break;
27340Sstevel@tonic-gate 			continue;
27350Sstevel@tonic-gate 		}
27360Sstevel@tonic-gate 	}
27370Sstevel@tonic-gate }
27380Sstevel@tonic-gate 
27390Sstevel@tonic-gate /*
27400Sstevel@tonic-gate  * A cacheinfo walker that adds associativity, line-size, and size properties
27410Sstevel@tonic-gate  * to the devinfo node it is passed as an argument.
27420Sstevel@tonic-gate  */
27430Sstevel@tonic-gate static int
27440Sstevel@tonic-gate add_cacheent_props(void *arg, const struct cachetab *ct)
27450Sstevel@tonic-gate {
27460Sstevel@tonic-gate 	dev_info_t *devi = arg;
27470Sstevel@tonic-gate 
27480Sstevel@tonic-gate 	add_cache_prop(devi, ct->ct_label, assoc_str, ct->ct_assoc);
27490Sstevel@tonic-gate 	if (ct->ct_line_size != 0)
27500Sstevel@tonic-gate 		add_cache_prop(devi, ct->ct_label, line_str,
27510Sstevel@tonic-gate 		    ct->ct_line_size);
27520Sstevel@tonic-gate 	add_cache_prop(devi, ct->ct_label, size_str, ct->ct_size);
27530Sstevel@tonic-gate 	return (0);
27540Sstevel@tonic-gate }
27550Sstevel@tonic-gate 
2756*4797Sksadhukh /*
2757*4797Sksadhukh  * Add L2 or L3 cache-information using cpuid function 4. This
2758*4797Sksadhukh  * function is called from intel_walk_cacheinfo() when descriptor
2759*4797Sksadhukh  * 0x49 is encountered.
2760*4797Sksadhukh  */
2761*4797Sksadhukh static void
2762*4797Sksadhukh intel_cpuid_4_cache_info(void *arg, struct cpuid_info *cpi)
2763*4797Sksadhukh {
2764*4797Sksadhukh 	uint32_t level, i;
2765*4797Sksadhukh 
2766*4797Sksadhukh 	struct cachetab ct;
2767*4797Sksadhukh 
2768*4797Sksadhukh 	for (i = 0; i < cpi->cpi_std_4_size; i++) {
2769*4797Sksadhukh 		level = CPI_CACHE_LVL(cpi->cpi_std_4[i]);
2770*4797Sksadhukh 
2771*4797Sksadhukh 		if (level == 2 || level == 3) {
2772*4797Sksadhukh 			ct.ct_assoc = CPI_CACHE_WAYS(cpi->cpi_std_4[i]) + 1;
2773*4797Sksadhukh 			ct.ct_line_size =
2774*4797Sksadhukh 			    CPI_CACHE_COH_LN_SZ(cpi->cpi_std_4[i]) + 1;
2775*4797Sksadhukh 			ct.ct_size = ct.ct_assoc *
2776*4797Sksadhukh 			    (CPI_CACHE_PARTS(cpi->cpi_std_4[i]) + 1) *
2777*4797Sksadhukh 			    ct.ct_line_size *
2778*4797Sksadhukh 			    (cpi->cpi_std_4[i]->cp_ecx + 1);
2779*4797Sksadhukh 
2780*4797Sksadhukh 			if (level == 2) {
2781*4797Sksadhukh 				ct.ct_label = l2_cache_str;
2782*4797Sksadhukh 			} else if (level == 3) {
2783*4797Sksadhukh 				ct.ct_label = l3_cache_str;
2784*4797Sksadhukh 			}
2785*4797Sksadhukh 
2786*4797Sksadhukh 			(void) add_cacheent_props(arg,
2787*4797Sksadhukh 			    (const struct cachetab *) (&ct));
2788*4797Sksadhukh 		}
2789*4797Sksadhukh 	}
2790*4797Sksadhukh }
2791*4797Sksadhukh 
27920Sstevel@tonic-gate static const char fully_assoc[] = "fully-associative?";
27930Sstevel@tonic-gate 
27940Sstevel@tonic-gate /*
27950Sstevel@tonic-gate  * AMD style cache/tlb description
27960Sstevel@tonic-gate  *
27970Sstevel@tonic-gate  * Extended functions 5 and 6 directly describe properties of
27980Sstevel@tonic-gate  * tlbs and various cache levels.
27990Sstevel@tonic-gate  */
28000Sstevel@tonic-gate static void
28010Sstevel@tonic-gate add_amd_assoc(dev_info_t *devi, const char *label, uint_t assoc)
28020Sstevel@tonic-gate {
28030Sstevel@tonic-gate 	switch (assoc) {
28040Sstevel@tonic-gate 	case 0:	/* reserved; ignore */
28050Sstevel@tonic-gate 		break;
28060Sstevel@tonic-gate 	default:
28070Sstevel@tonic-gate 		add_cache_prop(devi, label, assoc_str, assoc);
28080Sstevel@tonic-gate 		break;
28090Sstevel@tonic-gate 	case 0xff:
28100Sstevel@tonic-gate 		add_cache_prop(devi, label, fully_assoc, 1);
28110Sstevel@tonic-gate 		break;
28120Sstevel@tonic-gate 	}
28130Sstevel@tonic-gate }
28140Sstevel@tonic-gate 
28150Sstevel@tonic-gate static void
28160Sstevel@tonic-gate add_amd_tlb(dev_info_t *devi, const char *label, uint_t assoc, uint_t size)
28170Sstevel@tonic-gate {
28180Sstevel@tonic-gate 	if (size == 0)
28190Sstevel@tonic-gate 		return;
28200Sstevel@tonic-gate 	add_cache_prop(devi, label, size_str, size);
28210Sstevel@tonic-gate 	add_amd_assoc(devi, label, assoc);
28220Sstevel@tonic-gate }
28230Sstevel@tonic-gate 
28240Sstevel@tonic-gate static void
28250Sstevel@tonic-gate add_amd_cache(dev_info_t *devi, const char *label,
28260Sstevel@tonic-gate     uint_t size, uint_t assoc, uint_t lines_per_tag, uint_t line_size)
28270Sstevel@tonic-gate {
28280Sstevel@tonic-gate 	if (size == 0 || line_size == 0)
28290Sstevel@tonic-gate 		return;
28300Sstevel@tonic-gate 	add_amd_assoc(devi, label, assoc);
28310Sstevel@tonic-gate 	/*
28320Sstevel@tonic-gate 	 * Most AMD parts have a sectored cache. Multiple cache lines are
28330Sstevel@tonic-gate 	 * associated with each tag. A sector consists of all cache lines
28340Sstevel@tonic-gate 	 * associated with a tag. For example, the AMD K6-III has a sector
28350Sstevel@tonic-gate 	 * size of 2 cache lines per tag.
28360Sstevel@tonic-gate 	 */
28370Sstevel@tonic-gate 	if (lines_per_tag != 0)
28380Sstevel@tonic-gate 		add_cache_prop(devi, label, "lines-per-tag", lines_per_tag);
28390Sstevel@tonic-gate 	add_cache_prop(devi, label, line_str, line_size);
28400Sstevel@tonic-gate 	add_cache_prop(devi, label, size_str, size * 1024);
28410Sstevel@tonic-gate }
28420Sstevel@tonic-gate 
28430Sstevel@tonic-gate static void
28440Sstevel@tonic-gate add_amd_l2_assoc(dev_info_t *devi, const char *label, uint_t assoc)
28450Sstevel@tonic-gate {
28460Sstevel@tonic-gate 	switch (assoc) {
28470Sstevel@tonic-gate 	case 0:	/* off */
28480Sstevel@tonic-gate 		break;
28490Sstevel@tonic-gate 	case 1:
28500Sstevel@tonic-gate 	case 2:
28510Sstevel@tonic-gate 	case 4:
28520Sstevel@tonic-gate 		add_cache_prop(devi, label, assoc_str, assoc);
28530Sstevel@tonic-gate 		break;
28540Sstevel@tonic-gate 	case 6:
28550Sstevel@tonic-gate 		add_cache_prop(devi, label, assoc_str, 8);
28560Sstevel@tonic-gate 		break;
28570Sstevel@tonic-gate 	case 8:
28580Sstevel@tonic-gate 		add_cache_prop(devi, label, assoc_str, 16);
28590Sstevel@tonic-gate 		break;
28600Sstevel@tonic-gate 	case 0xf:
28610Sstevel@tonic-gate 		add_cache_prop(devi, label, fully_assoc, 1);
28620Sstevel@tonic-gate 		break;
28630Sstevel@tonic-gate 	default: /* reserved; ignore */
28640Sstevel@tonic-gate 		break;
28650Sstevel@tonic-gate 	}
28660Sstevel@tonic-gate }
28670Sstevel@tonic-gate 
28680Sstevel@tonic-gate static void
28690Sstevel@tonic-gate add_amd_l2_tlb(dev_info_t *devi, const char *label, uint_t assoc, uint_t size)
28700Sstevel@tonic-gate {
28710Sstevel@tonic-gate 	if (size == 0 || assoc == 0)
28720Sstevel@tonic-gate 		return;
28730Sstevel@tonic-gate 	add_amd_l2_assoc(devi, label, assoc);
28740Sstevel@tonic-gate 	add_cache_prop(devi, label, size_str, size);
28750Sstevel@tonic-gate }
28760Sstevel@tonic-gate 
28770Sstevel@tonic-gate static void
28780Sstevel@tonic-gate add_amd_l2_cache(dev_info_t *devi, const char *label,
28790Sstevel@tonic-gate     uint_t size, uint_t assoc, uint_t lines_per_tag, uint_t line_size)
28800Sstevel@tonic-gate {
28810Sstevel@tonic-gate 	if (size == 0 || assoc == 0 || line_size == 0)
28820Sstevel@tonic-gate 		return;
28830Sstevel@tonic-gate 	add_amd_l2_assoc(devi, label, assoc);
28840Sstevel@tonic-gate 	if (lines_per_tag != 0)
28850Sstevel@tonic-gate 		add_cache_prop(devi, label, "lines-per-tag", lines_per_tag);
28860Sstevel@tonic-gate 	add_cache_prop(devi, label, line_str, line_size);
28870Sstevel@tonic-gate 	add_cache_prop(devi, label, size_str, size * 1024);
28880Sstevel@tonic-gate }
28890Sstevel@tonic-gate 
28900Sstevel@tonic-gate static void
28910Sstevel@tonic-gate amd_cache_info(struct cpuid_info *cpi, dev_info_t *devi)
28920Sstevel@tonic-gate {
28931228Sandrei 	struct cpuid_regs *cp;
28940Sstevel@tonic-gate 
28950Sstevel@tonic-gate 	if (cpi->cpi_xmaxeax < 0x80000005)
28960Sstevel@tonic-gate 		return;
28970Sstevel@tonic-gate 	cp = &cpi->cpi_extd[5];
28980Sstevel@tonic-gate 
28990Sstevel@tonic-gate 	/*
29000Sstevel@tonic-gate 	 * 4M/2M L1 TLB configuration
29010Sstevel@tonic-gate 	 *
29020Sstevel@tonic-gate 	 * We report the size for 2M pages because AMD uses two
29030Sstevel@tonic-gate 	 * TLB entries for one 4M page.
29040Sstevel@tonic-gate 	 */
29050Sstevel@tonic-gate 	add_amd_tlb(devi, "dtlb-2M",
29060Sstevel@tonic-gate 	    BITX(cp->cp_eax, 31, 24), BITX(cp->cp_eax, 23, 16));
29070Sstevel@tonic-gate 	add_amd_tlb(devi, "itlb-2M",
29080Sstevel@tonic-gate 	    BITX(cp->cp_eax, 15, 8), BITX(cp->cp_eax, 7, 0));
29090Sstevel@tonic-gate 
29100Sstevel@tonic-gate 	/*
29110Sstevel@tonic-gate 	 * 4K L1 TLB configuration
29120Sstevel@tonic-gate 	 */
29130Sstevel@tonic-gate 
29140Sstevel@tonic-gate 	switch (cpi->cpi_vendor) {
29150Sstevel@tonic-gate 		uint_t nentries;
29160Sstevel@tonic-gate 	case X86_VENDOR_TM:
29170Sstevel@tonic-gate 		if (cpi->cpi_family >= 5) {
29180Sstevel@tonic-gate 			/*
29190Sstevel@tonic-gate 			 * Crusoe processors have 256 TLB entries, but
29200Sstevel@tonic-gate 			 * cpuid data format constrains them to only
29210Sstevel@tonic-gate 			 * reporting 255 of them.
29220Sstevel@tonic-gate 			 */
29230Sstevel@tonic-gate 			if ((nentries = BITX(cp->cp_ebx, 23, 16)) == 255)
29240Sstevel@tonic-gate 				nentries = 256;
29250Sstevel@tonic-gate 			/*
29260Sstevel@tonic-gate 			 * Crusoe processors also have a unified TLB
29270Sstevel@tonic-gate 			 */
29280Sstevel@tonic-gate 			add_amd_tlb(devi, "tlb-4K", BITX(cp->cp_ebx, 31, 24),
29290Sstevel@tonic-gate 			    nentries);
29300Sstevel@tonic-gate 			break;
29310Sstevel@tonic-gate 		}
29320Sstevel@tonic-gate 		/*FALLTHROUGH*/
29330Sstevel@tonic-gate 	default:
29340Sstevel@tonic-gate 		add_amd_tlb(devi, itlb4k_str,
29350Sstevel@tonic-gate 		    BITX(cp->cp_ebx, 31, 24), BITX(cp->cp_ebx, 23, 16));
29360Sstevel@tonic-gate 		add_amd_tlb(devi, dtlb4k_str,
29370Sstevel@tonic-gate 		    BITX(cp->cp_ebx, 15, 8), BITX(cp->cp_ebx, 7, 0));
29380Sstevel@tonic-gate 		break;
29390Sstevel@tonic-gate 	}
29400Sstevel@tonic-gate 
29410Sstevel@tonic-gate 	/*
29420Sstevel@tonic-gate 	 * data L1 cache configuration
29430Sstevel@tonic-gate 	 */
29440Sstevel@tonic-gate 
29450Sstevel@tonic-gate 	add_amd_cache(devi, l1_dcache_str,
29460Sstevel@tonic-gate 	    BITX(cp->cp_ecx, 31, 24), BITX(cp->cp_ecx, 23, 16),
29470Sstevel@tonic-gate 	    BITX(cp->cp_ecx, 15, 8), BITX(cp->cp_ecx, 7, 0));
29480Sstevel@tonic-gate 
29490Sstevel@tonic-gate 	/*
29500Sstevel@tonic-gate 	 * code L1 cache configuration
29510Sstevel@tonic-gate 	 */
29520Sstevel@tonic-gate 
29530Sstevel@tonic-gate 	add_amd_cache(devi, l1_icache_str,
29540Sstevel@tonic-gate 	    BITX(cp->cp_edx, 31, 24), BITX(cp->cp_edx, 23, 16),
29550Sstevel@tonic-gate 	    BITX(cp->cp_edx, 15, 8), BITX(cp->cp_edx, 7, 0));
29560Sstevel@tonic-gate 
29570Sstevel@tonic-gate 	if (cpi->cpi_xmaxeax < 0x80000006)
29580Sstevel@tonic-gate 		return;
29590Sstevel@tonic-gate 	cp = &cpi->cpi_extd[6];
29600Sstevel@tonic-gate 
29610Sstevel@tonic-gate 	/* Check for a unified L2 TLB for large pages */
29620Sstevel@tonic-gate 
29630Sstevel@tonic-gate 	if (BITX(cp->cp_eax, 31, 16) == 0)
29640Sstevel@tonic-gate 		add_amd_l2_tlb(devi, "l2-tlb-2M",
29650Sstevel@tonic-gate 		    BITX(cp->cp_eax, 15, 12), BITX(cp->cp_eax, 11, 0));
29660Sstevel@tonic-gate 	else {
29670Sstevel@tonic-gate 		add_amd_l2_tlb(devi, "l2-dtlb-2M",
29680Sstevel@tonic-gate 		    BITX(cp->cp_eax, 31, 28), BITX(cp->cp_eax, 27, 16));
29690Sstevel@tonic-gate 		add_amd_l2_tlb(devi, "l2-itlb-2M",
29700Sstevel@tonic-gate 		    BITX(cp->cp_eax, 15, 12), BITX(cp->cp_eax, 11, 0));
29710Sstevel@tonic-gate 	}
29720Sstevel@tonic-gate 
29730Sstevel@tonic-gate 	/* Check for a unified L2 TLB for 4K pages */
29740Sstevel@tonic-gate 
29750Sstevel@tonic-gate 	if (BITX(cp->cp_ebx, 31, 16) == 0) {
29760Sstevel@tonic-gate 		add_amd_l2_tlb(devi, "l2-tlb-4K",
29770Sstevel@tonic-gate 		    BITX(cp->cp_eax, 15, 12), BITX(cp->cp_eax, 11, 0));
29780Sstevel@tonic-gate 	} else {
29790Sstevel@tonic-gate 		add_amd_l2_tlb(devi, "l2-dtlb-4K",
29800Sstevel@tonic-gate 		    BITX(cp->cp_eax, 31, 28), BITX(cp->cp_eax, 27, 16));
29810Sstevel@tonic-gate 		add_amd_l2_tlb(devi, "l2-itlb-4K",
29820Sstevel@tonic-gate 		    BITX(cp->cp_eax, 15, 12), BITX(cp->cp_eax, 11, 0));
29830Sstevel@tonic-gate 	}
29840Sstevel@tonic-gate 
29850Sstevel@tonic-gate 	add_amd_l2_cache(devi, l2_cache_str,
29860Sstevel@tonic-gate 	    BITX(cp->cp_ecx, 31, 16), BITX(cp->cp_ecx, 15, 12),
29870Sstevel@tonic-gate 	    BITX(cp->cp_ecx, 11, 8), BITX(cp->cp_ecx, 7, 0));
29880Sstevel@tonic-gate }
29890Sstevel@tonic-gate 
29900Sstevel@tonic-gate /*
29910Sstevel@tonic-gate  * There are two basic ways that the x86 world describes it cache
29920Sstevel@tonic-gate  * and tlb architecture - Intel's way and AMD's way.
29930Sstevel@tonic-gate  *
29940Sstevel@tonic-gate  * Return which flavor of cache architecture we should use
29950Sstevel@tonic-gate  */
29960Sstevel@tonic-gate static int
29970Sstevel@tonic-gate x86_which_cacheinfo(struct cpuid_info *cpi)
29980Sstevel@tonic-gate {
29990Sstevel@tonic-gate 	switch (cpi->cpi_vendor) {
30000Sstevel@tonic-gate 	case X86_VENDOR_Intel:
30010Sstevel@tonic-gate 		if (cpi->cpi_maxeax >= 2)
30020Sstevel@tonic-gate 			return (X86_VENDOR_Intel);
30030Sstevel@tonic-gate 		break;
30040Sstevel@tonic-gate 	case X86_VENDOR_AMD:
30050Sstevel@tonic-gate 		/*
30060Sstevel@tonic-gate 		 * The K5 model 1 was the first part from AMD that reported
30070Sstevel@tonic-gate 		 * cache sizes via extended cpuid functions.
30080Sstevel@tonic-gate 		 */
30090Sstevel@tonic-gate 		if (cpi->cpi_family > 5 ||
30100Sstevel@tonic-gate 		    (cpi->cpi_family == 5 && cpi->cpi_model >= 1))
30110Sstevel@tonic-gate 			return (X86_VENDOR_AMD);
30120Sstevel@tonic-gate 		break;
30130Sstevel@tonic-gate 	case X86_VENDOR_TM:
30140Sstevel@tonic-gate 		if (cpi->cpi_family >= 5)
30150Sstevel@tonic-gate 			return (X86_VENDOR_AMD);
30160Sstevel@tonic-gate 		/*FALLTHROUGH*/
30170Sstevel@tonic-gate 	default:
30180Sstevel@tonic-gate 		/*
30190Sstevel@tonic-gate 		 * If they have extended CPU data for 0x80000005
30200Sstevel@tonic-gate 		 * then we assume they have AMD-format cache
30210Sstevel@tonic-gate 		 * information.
30220Sstevel@tonic-gate 		 *
30230Sstevel@tonic-gate 		 * If not, and the vendor happens to be Cyrix,
30240Sstevel@tonic-gate 		 * then try our-Cyrix specific handler.
30250Sstevel@tonic-gate 		 *
30260Sstevel@tonic-gate 		 * If we're not Cyrix, then assume we're using Intel's
30270Sstevel@tonic-gate 		 * table-driven format instead.
30280Sstevel@tonic-gate 		 */
30290Sstevel@tonic-gate 		if (cpi->cpi_xmaxeax >= 0x80000005)
30300Sstevel@tonic-gate 			return (X86_VENDOR_AMD);
30310Sstevel@tonic-gate 		else if (cpi->cpi_vendor == X86_VENDOR_Cyrix)
30320Sstevel@tonic-gate 			return (X86_VENDOR_Cyrix);
30330Sstevel@tonic-gate 		else if (cpi->cpi_maxeax >= 2)
30340Sstevel@tonic-gate 			return (X86_VENDOR_Intel);
30350Sstevel@tonic-gate 		break;
30360Sstevel@tonic-gate 	}
30370Sstevel@tonic-gate 	return (-1);
30380Sstevel@tonic-gate }
30390Sstevel@tonic-gate 
30400Sstevel@tonic-gate /*
30410Sstevel@tonic-gate  * create a node for the given cpu under the prom root node.
30420Sstevel@tonic-gate  * Also, create a cpu node in the device tree.
30430Sstevel@tonic-gate  */
30440Sstevel@tonic-gate static dev_info_t *cpu_nex_devi = NULL;
30450Sstevel@tonic-gate static kmutex_t cpu_node_lock;
30460Sstevel@tonic-gate 
30470Sstevel@tonic-gate /*
30480Sstevel@tonic-gate  * Called from post_startup() and mp_startup()
30490Sstevel@tonic-gate  */
30500Sstevel@tonic-gate void
30510Sstevel@tonic-gate add_cpunode2devtree(processorid_t cpu_id, struct cpuid_info *cpi)
30520Sstevel@tonic-gate {
30530Sstevel@tonic-gate 	dev_info_t *cpu_devi;
30540Sstevel@tonic-gate 	int create;
30550Sstevel@tonic-gate 
30560Sstevel@tonic-gate 	mutex_enter(&cpu_node_lock);
30570Sstevel@tonic-gate 
30580Sstevel@tonic-gate 	/*
30590Sstevel@tonic-gate 	 * create a nexus node for all cpus identified as 'cpu_id' under
30600Sstevel@tonic-gate 	 * the root node.
30610Sstevel@tonic-gate 	 */
30620Sstevel@tonic-gate 	if (cpu_nex_devi == NULL) {
30630Sstevel@tonic-gate 		if (ndi_devi_alloc(ddi_root_node(), "cpus",
3064789Sahrens 		    (pnode_t)DEVI_SID_NODEID, &cpu_nex_devi) != NDI_SUCCESS) {
30650Sstevel@tonic-gate 			mutex_exit(&cpu_node_lock);
30660Sstevel@tonic-gate 			return;
30670Sstevel@tonic-gate 		}
30680Sstevel@tonic-gate 		(void) ndi_devi_online(cpu_nex_devi, 0);
30690Sstevel@tonic-gate 	}
30700Sstevel@tonic-gate 
30710Sstevel@tonic-gate 	/*
30720Sstevel@tonic-gate 	 * create a child node for cpu identified as 'cpu_id'
30730Sstevel@tonic-gate 	 */
30740Sstevel@tonic-gate 	cpu_devi = ddi_add_child(cpu_nex_devi, "cpu", DEVI_SID_NODEID,
30754481Sbholler 	    cpu_id);
30760Sstevel@tonic-gate 	if (cpu_devi == NULL) {
30770Sstevel@tonic-gate 		mutex_exit(&cpu_node_lock);
30780Sstevel@tonic-gate 		return;
30790Sstevel@tonic-gate 	}
30800Sstevel@tonic-gate 
30810Sstevel@tonic-gate 	/* device_type */
30820Sstevel@tonic-gate 
30830Sstevel@tonic-gate 	(void) ndi_prop_update_string(DDI_DEV_T_NONE, cpu_devi,
30840Sstevel@tonic-gate 	    "device_type", "cpu");
30850Sstevel@tonic-gate 
30860Sstevel@tonic-gate 	/* reg */
30870Sstevel@tonic-gate 
30880Sstevel@tonic-gate 	(void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi,
30890Sstevel@tonic-gate 	    "reg", cpu_id);
30900Sstevel@tonic-gate 
30910Sstevel@tonic-gate 	/* cpu-mhz, and clock-frequency */
30920Sstevel@tonic-gate 
30930Sstevel@tonic-gate 	if (cpu_freq > 0) {
30940Sstevel@tonic-gate 		long long mul;
30950Sstevel@tonic-gate 
30960Sstevel@tonic-gate 		(void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi,
30970Sstevel@tonic-gate 		    "cpu-mhz", cpu_freq);
30980Sstevel@tonic-gate 
30990Sstevel@tonic-gate 		if ((mul = cpu_freq * 1000000LL) <= INT_MAX)
31000Sstevel@tonic-gate 			(void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi,
31010Sstevel@tonic-gate 			    "clock-frequency", (int)mul);
31020Sstevel@tonic-gate 	}
31030Sstevel@tonic-gate 
31040Sstevel@tonic-gate 	(void) ndi_devi_online(cpu_devi, 0);
31050Sstevel@tonic-gate 
31060Sstevel@tonic-gate 	if ((x86_feature & X86_CPUID) == 0) {
31070Sstevel@tonic-gate 		mutex_exit(&cpu_node_lock);
31080Sstevel@tonic-gate 		return;
31090Sstevel@tonic-gate 	}
31100Sstevel@tonic-gate 
31110Sstevel@tonic-gate 	/* vendor-id */
31120Sstevel@tonic-gate 
31130Sstevel@tonic-gate 	(void) ndi_prop_update_string(DDI_DEV_T_NONE, cpu_devi,
31144481Sbholler 	    "vendor-id", cpi->cpi_vendorstr);
31150Sstevel@tonic-gate 
31160Sstevel@tonic-gate 	if (cpi->cpi_maxeax == 0) {
31170Sstevel@tonic-gate 		mutex_exit(&cpu_node_lock);
31180Sstevel@tonic-gate 		return;
31190Sstevel@tonic-gate 	}
31200Sstevel@tonic-gate 
31210Sstevel@tonic-gate 	/*
31220Sstevel@tonic-gate 	 * family, model, and step
31230Sstevel@tonic-gate 	 */
31240Sstevel@tonic-gate 	(void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi,
31254481Sbholler 	    "family", CPI_FAMILY(cpi));
31260Sstevel@tonic-gate 	(void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi,
31274481Sbholler 	    "cpu-model", CPI_MODEL(cpi));
31280Sstevel@tonic-gate 	(void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi,
31294481Sbholler 	    "stepping-id", CPI_STEP(cpi));
31300Sstevel@tonic-gate 
31310Sstevel@tonic-gate 	/* type */
31320Sstevel@tonic-gate 
31330Sstevel@tonic-gate 	switch (cpi->cpi_vendor) {
31340Sstevel@tonic-gate 	case X86_VENDOR_Intel:
31350Sstevel@tonic-gate 		create = 1;
31360Sstevel@tonic-gate 		break;
31370Sstevel@tonic-gate 	default:
31380Sstevel@tonic-gate 		create = 0;
31390Sstevel@tonic-gate 		break;
31400Sstevel@tonic-gate 	}
31410Sstevel@tonic-gate 	if (create)
31420Sstevel@tonic-gate 		(void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi,
31434481Sbholler 		    "type", CPI_TYPE(cpi));
31440Sstevel@tonic-gate 
31450Sstevel@tonic-gate 	/* ext-family */
31460Sstevel@tonic-gate 
31470Sstevel@tonic-gate 	switch (cpi->cpi_vendor) {
31480Sstevel@tonic-gate 	case X86_VENDOR_Intel:
31490Sstevel@tonic-gate 	case X86_VENDOR_AMD:
31500Sstevel@tonic-gate 		create = cpi->cpi_family >= 0xf;
31510Sstevel@tonic-gate 		break;
31520Sstevel@tonic-gate 	default:
31530Sstevel@tonic-gate 		create = 0;
31540Sstevel@tonic-gate 		break;
31550Sstevel@tonic-gate 	}
31560Sstevel@tonic-gate 	if (create)
31570Sstevel@tonic-gate 		(void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi,
31580Sstevel@tonic-gate 		    "ext-family", CPI_FAMILY_XTD(cpi));
31590Sstevel@tonic-gate 
31600Sstevel@tonic-gate 	/* ext-model */
31610Sstevel@tonic-gate 
31620Sstevel@tonic-gate 	switch (cpi->cpi_vendor) {
31630Sstevel@tonic-gate 	case X86_VENDOR_Intel:
31642001Sdmick 		create = CPI_MODEL(cpi) == 0xf;
31652001Sdmick 		break;
31660Sstevel@tonic-gate 	case X86_VENDOR_AMD:
31671582Skchow 		create = CPI_FAMILY(cpi) == 0xf;
31680Sstevel@tonic-gate 		break;
31690Sstevel@tonic-gate 	default:
31700Sstevel@tonic-gate 		create = 0;
31710Sstevel@tonic-gate 		break;
31720Sstevel@tonic-gate 	}
31730Sstevel@tonic-gate 	if (create)
31740Sstevel@tonic-gate 		(void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi,
31754481Sbholler 		    "ext-model", CPI_MODEL_XTD(cpi));
31760Sstevel@tonic-gate 
31770Sstevel@tonic-gate 	/* generation */
31780Sstevel@tonic-gate 
31790Sstevel@tonic-gate 	switch (cpi->cpi_vendor) {
31800Sstevel@tonic-gate 	case X86_VENDOR_AMD:
31810Sstevel@tonic-gate 		/*
31820Sstevel@tonic-gate 		 * AMD K5 model 1 was the first part to support this
31830Sstevel@tonic-gate 		 */
31840Sstevel@tonic-gate 		create = cpi->cpi_xmaxeax >= 0x80000001;
31850Sstevel@tonic-gate 		break;
31860Sstevel@tonic-gate 	default:
31870Sstevel@tonic-gate 		create = 0;
31880Sstevel@tonic-gate 		break;
31890Sstevel@tonic-gate 	}
31900Sstevel@tonic-gate 	if (create)
31910Sstevel@tonic-gate 		(void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi,
31920Sstevel@tonic-gate 		    "generation", BITX((cpi)->cpi_extd[1].cp_eax, 11, 8));
31930Sstevel@tonic-gate 
31940Sstevel@tonic-gate 	/* brand-id */
31950Sstevel@tonic-gate 
31960Sstevel@tonic-gate 	switch (cpi->cpi_vendor) {
31970Sstevel@tonic-gate 	case X86_VENDOR_Intel:
31980Sstevel@tonic-gate 		/*
31990Sstevel@tonic-gate 		 * brand id first appeared on Pentium III Xeon model 8,
32000Sstevel@tonic-gate 		 * and Celeron model 8 processors and Opteron
32010Sstevel@tonic-gate 		 */
32020Sstevel@tonic-gate 		create = cpi->cpi_family > 6 ||
32030Sstevel@tonic-gate 		    (cpi->cpi_family == 6 && cpi->cpi_model >= 8);
32040Sstevel@tonic-gate 		break;
32050Sstevel@tonic-gate 	case X86_VENDOR_AMD:
32060Sstevel@tonic-gate 		create = cpi->cpi_family >= 0xf;
32070Sstevel@tonic-gate 		break;
32080Sstevel@tonic-gate 	default:
32090Sstevel@tonic-gate 		create = 0;
32100Sstevel@tonic-gate 		break;
32110Sstevel@tonic-gate 	}
32120Sstevel@tonic-gate 	if (create && cpi->cpi_brandid != 0) {
32130Sstevel@tonic-gate 		(void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi,
32140Sstevel@tonic-gate 		    "brand-id", cpi->cpi_brandid);
32150Sstevel@tonic-gate 	}
32160Sstevel@tonic-gate 
32170Sstevel@tonic-gate 	/* chunks, and apic-id */
32180Sstevel@tonic-gate 
32190Sstevel@tonic-gate 	switch (cpi->cpi_vendor) {
32200Sstevel@tonic-gate 		/*
32210Sstevel@tonic-gate 		 * first available on Pentium IV and Opteron (K8)
32220Sstevel@tonic-gate 		 */
32231975Sdmick 	case X86_VENDOR_Intel:
32241975Sdmick 		create = IS_NEW_F6(cpi) || cpi->cpi_family >= 0xf;
32251975Sdmick 		break;
32261975Sdmick 	case X86_VENDOR_AMD:
32270Sstevel@tonic-gate 		create = cpi->cpi_family >= 0xf;
32280Sstevel@tonic-gate 		break;
32290Sstevel@tonic-gate 	default:
32300Sstevel@tonic-gate 		create = 0;
32310Sstevel@tonic-gate 		break;
32320Sstevel@tonic-gate 	}
32330Sstevel@tonic-gate 	if (create) {
32340Sstevel@tonic-gate 		(void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi,
32354481Sbholler 		    "chunks", CPI_CHUNKS(cpi));
32360Sstevel@tonic-gate 		(void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi,
32374481Sbholler 		    "apic-id", CPI_APIC_ID(cpi));
32381414Scindi 		if (cpi->cpi_chipid >= 0) {
32390Sstevel@tonic-gate 			(void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi,
32400Sstevel@tonic-gate 			    "chip#", cpi->cpi_chipid);
32411414Scindi 			(void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi,
32421414Scindi 			    "clog#", cpi->cpi_clogid);
32431414Scindi 		}
32440Sstevel@tonic-gate 	}
32450Sstevel@tonic-gate 
32460Sstevel@tonic-gate 	/* cpuid-features */
32470Sstevel@tonic-gate 
32480Sstevel@tonic-gate 	(void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi,
32490Sstevel@tonic-gate 	    "cpuid-features", CPI_FEATURES_EDX(cpi));
32500Sstevel@tonic-gate 
32510Sstevel@tonic-gate 
32520Sstevel@tonic-gate 	/* cpuid-features-ecx */
32530Sstevel@tonic-gate 
32540Sstevel@tonic-gate 	switch (cpi->cpi_vendor) {
32550Sstevel@tonic-gate 	case X86_VENDOR_Intel:
32561975Sdmick 		create = IS_NEW_F6(cpi) || cpi->cpi_family >= 0xf;
32570Sstevel@tonic-gate 		break;
32580Sstevel@tonic-gate 	default:
32590Sstevel@tonic-gate 		create = 0;
32600Sstevel@tonic-gate 		break;
32610Sstevel@tonic-gate 	}
32620Sstevel@tonic-gate 	if (create)
32630Sstevel@tonic-gate 		(void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi,
32640Sstevel@tonic-gate 		    "cpuid-features-ecx", CPI_FEATURES_ECX(cpi));
32650Sstevel@tonic-gate 
32660Sstevel@tonic-gate 	/* ext-cpuid-features */
32670Sstevel@tonic-gate 
32680Sstevel@tonic-gate 	switch (cpi->cpi_vendor) {
32691975Sdmick 	case X86_VENDOR_Intel:
32700Sstevel@tonic-gate 	case X86_VENDOR_AMD:
32710Sstevel@tonic-gate 	case X86_VENDOR_Cyrix:
32720Sstevel@tonic-gate 	case X86_VENDOR_TM:
32730Sstevel@tonic-gate 	case X86_VENDOR_Centaur:
32740Sstevel@tonic-gate 		create = cpi->cpi_xmaxeax >= 0x80000001;
32750Sstevel@tonic-gate 		break;
32760Sstevel@tonic-gate 	default:
32770Sstevel@tonic-gate 		create = 0;
32780Sstevel@tonic-gate 		break;
32790Sstevel@tonic-gate 	}
32801975Sdmick 	if (create) {
32810Sstevel@tonic-gate 		(void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi,
32824481Sbholler 		    "ext-cpuid-features", CPI_FEATURES_XTD_EDX(cpi));
32831975Sdmick 		(void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi,
32844481Sbholler 		    "ext-cpuid-features-ecx", CPI_FEATURES_XTD_ECX(cpi));
32851975Sdmick 	}
32860Sstevel@tonic-gate 
32870Sstevel@tonic-gate 	/*
32880Sstevel@tonic-gate 	 * Brand String first appeared in Intel Pentium IV, AMD K5
32890Sstevel@tonic-gate 	 * model 1, and Cyrix GXm.  On earlier models we try and
32900Sstevel@tonic-gate 	 * simulate something similar .. so this string should always
32910Sstevel@tonic-gate 	 * same -something- about the processor, however lame.
32920Sstevel@tonic-gate 	 */
32930Sstevel@tonic-gate 	(void) ndi_prop_update_string(DDI_DEV_T_NONE, cpu_devi,
32940Sstevel@tonic-gate 	    "brand-string", cpi->cpi_brandstr);
32950Sstevel@tonic-gate 
32960Sstevel@tonic-gate 	/*
32970Sstevel@tonic-gate 	 * Finally, cache and tlb information
32980Sstevel@tonic-gate 	 */
32990Sstevel@tonic-gate 	switch (x86_which_cacheinfo(cpi)) {
33000Sstevel@tonic-gate 	case X86_VENDOR_Intel:
33010Sstevel@tonic-gate 		intel_walk_cacheinfo(cpi, cpu_devi, add_cacheent_props);
33020Sstevel@tonic-gate 		break;
33030Sstevel@tonic-gate 	case X86_VENDOR_Cyrix:
33040Sstevel@tonic-gate 		cyrix_walk_cacheinfo(cpi, cpu_devi, add_cacheent_props);
33050Sstevel@tonic-gate 		break;
33060Sstevel@tonic-gate 	case X86_VENDOR_AMD:
33070Sstevel@tonic-gate 		amd_cache_info(cpi, cpu_devi);
33080Sstevel@tonic-gate 		break;
33090Sstevel@tonic-gate 	default:
33100Sstevel@tonic-gate 		break;
33110Sstevel@tonic-gate 	}
33120Sstevel@tonic-gate 
33130Sstevel@tonic-gate 	mutex_exit(&cpu_node_lock);
33140Sstevel@tonic-gate }
33150Sstevel@tonic-gate 
33160Sstevel@tonic-gate struct l2info {
33170Sstevel@tonic-gate 	int *l2i_csz;
33180Sstevel@tonic-gate 	int *l2i_lsz;
33190Sstevel@tonic-gate 	int *l2i_assoc;
33200Sstevel@tonic-gate 	int l2i_ret;
33210Sstevel@tonic-gate };
33220Sstevel@tonic-gate 
33230Sstevel@tonic-gate /*
33240Sstevel@tonic-gate  * A cacheinfo walker that fetches the size, line-size and associativity
33250Sstevel@tonic-gate  * of the L2 cache
33260Sstevel@tonic-gate  */
33270Sstevel@tonic-gate static int
33280Sstevel@tonic-gate intel_l2cinfo(void *arg, const struct cachetab *ct)
33290Sstevel@tonic-gate {
33300Sstevel@tonic-gate 	struct l2info *l2i = arg;
33310Sstevel@tonic-gate 	int *ip;
33320Sstevel@tonic-gate 
33330Sstevel@tonic-gate 	if (ct->ct_label != l2_cache_str &&
33340Sstevel@tonic-gate 	    ct->ct_label != sl2_cache_str)
33350Sstevel@tonic-gate 		return (0);	/* not an L2 -- keep walking */
33360Sstevel@tonic-gate 
33370Sstevel@tonic-gate 	if ((ip = l2i->l2i_csz) != NULL)
33380Sstevel@tonic-gate 		*ip = ct->ct_size;
33390Sstevel@tonic-gate 	if ((ip = l2i->l2i_lsz) != NULL)
33400Sstevel@tonic-gate 		*ip = ct->ct_line_size;
33410Sstevel@tonic-gate 	if ((ip = l2i->l2i_assoc) != NULL)
33420Sstevel@tonic-gate 		*ip = ct->ct_assoc;
33430Sstevel@tonic-gate 	l2i->l2i_ret = ct->ct_size;
33440Sstevel@tonic-gate 	return (1);		/* was an L2 -- terminate walk */
33450Sstevel@tonic-gate }
33460Sstevel@tonic-gate 
33470Sstevel@tonic-gate static void
33480Sstevel@tonic-gate amd_l2cacheinfo(struct cpuid_info *cpi, struct l2info *l2i)
33490Sstevel@tonic-gate {
33501228Sandrei 	struct cpuid_regs *cp;
33510Sstevel@tonic-gate 	uint_t size, assoc;
33520Sstevel@tonic-gate 	int *ip;
33530Sstevel@tonic-gate 
33540Sstevel@tonic-gate 	if (cpi->cpi_xmaxeax < 0x80000006)
33550Sstevel@tonic-gate 		return;
33560Sstevel@tonic-gate 	cp = &cpi->cpi_extd[6];
33570Sstevel@tonic-gate 
33580Sstevel@tonic-gate 	if ((assoc = BITX(cp->cp_ecx, 15, 12)) != 0 &&
33590Sstevel@tonic-gate 	    (size = BITX(cp->cp_ecx, 31, 16)) != 0) {
33600Sstevel@tonic-gate 		uint_t cachesz = size * 1024;
33610Sstevel@tonic-gate 
33620Sstevel@tonic-gate 
33630Sstevel@tonic-gate 		if ((ip = l2i->l2i_csz) != NULL)
33640Sstevel@tonic-gate 			*ip = cachesz;
33650Sstevel@tonic-gate 		if ((ip = l2i->l2i_lsz) != NULL)
33660Sstevel@tonic-gate 			*ip = BITX(cp->cp_ecx, 7, 0);
33670Sstevel@tonic-gate 		if ((ip = l2i->l2i_assoc) != NULL)
33680Sstevel@tonic-gate 			*ip = assoc;
33690Sstevel@tonic-gate 		l2i->l2i_ret = cachesz;
33700Sstevel@tonic-gate 	}
33710Sstevel@tonic-gate }
33720Sstevel@tonic-gate 
33730Sstevel@tonic-gate int
33740Sstevel@tonic-gate getl2cacheinfo(cpu_t *cpu, int *csz, int *lsz, int *assoc)
33750Sstevel@tonic-gate {
33760Sstevel@tonic-gate 	struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi;
33770Sstevel@tonic-gate 	struct l2info __l2info, *l2i = &__l2info;
33780Sstevel@tonic-gate 
33790Sstevel@tonic-gate 	l2i->l2i_csz = csz;
33800Sstevel@tonic-gate 	l2i->l2i_lsz = lsz;
33810Sstevel@tonic-gate 	l2i->l2i_assoc = assoc;
33820Sstevel@tonic-gate 	l2i->l2i_ret = -1;
33830Sstevel@tonic-gate 
33840Sstevel@tonic-gate 	switch (x86_which_cacheinfo(cpi)) {
33850Sstevel@tonic-gate 	case X86_VENDOR_Intel:
33860Sstevel@tonic-gate 		intel_walk_cacheinfo(cpi, l2i, intel_l2cinfo);
33870Sstevel@tonic-gate 		break;
33880Sstevel@tonic-gate 	case X86_VENDOR_Cyrix:
33890Sstevel@tonic-gate 		cyrix_walk_cacheinfo(cpi, l2i, intel_l2cinfo);
33900Sstevel@tonic-gate 		break;
33910Sstevel@tonic-gate 	case X86_VENDOR_AMD:
33920Sstevel@tonic-gate 		amd_l2cacheinfo(cpi, l2i);
33930Sstevel@tonic-gate 		break;
33940Sstevel@tonic-gate 	default:
33950Sstevel@tonic-gate 		break;
33960Sstevel@tonic-gate 	}
33970Sstevel@tonic-gate 	return (l2i->l2i_ret);
33980Sstevel@tonic-gate }
33994481Sbholler 
34004481Sbholler size_t
34014481Sbholler cpuid_get_mwait_size(cpu_t *cpu)
34024481Sbholler {
34034481Sbholler 	ASSERT(cpuid_checkpass(cpu, 2));
34044481Sbholler 	return (cpu->cpu_m.mcpu_cpi->cpi_mwait.mon_max);
34054481Sbholler }
3406