xref: /titanic_52/usr/src/uts/i86pc/os/cpuid.c (revision b6917abefc343244b784f0cc34bc65b01469c3bf)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5ee88d2b9Skchow  * Common Development and Distribution License (the "License").
6ee88d2b9Skchow  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
2210569901Sgavinm  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate /*
297c478bd9Sstevel@tonic-gate  * Various routines to handle identification
307c478bd9Sstevel@tonic-gate  * and classification of x86 processors.
317c478bd9Sstevel@tonic-gate  */
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #include <sys/types.h>
347c478bd9Sstevel@tonic-gate #include <sys/archsystm.h>
357c478bd9Sstevel@tonic-gate #include <sys/x86_archext.h>
367c478bd9Sstevel@tonic-gate #include <sys/kmem.h>
377c478bd9Sstevel@tonic-gate #include <sys/systm.h>
387c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h>
397c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
407c478bd9Sstevel@tonic-gate #include <sys/sunndi.h>
417c478bd9Sstevel@tonic-gate #include <sys/cpuvar.h>
427c478bd9Sstevel@tonic-gate #include <sys/processor.h>
435b8a6efeSbholler #include <sys/sysmacros.h>
44fb2f18f8Sesaxe #include <sys/pg.h>
457c478bd9Sstevel@tonic-gate #include <sys/fp.h>
467c478bd9Sstevel@tonic-gate #include <sys/controlregs.h>
477c478bd9Sstevel@tonic-gate #include <sys/auxv_386.h>
487c478bd9Sstevel@tonic-gate #include <sys/bitmap.h>
497c478bd9Sstevel@tonic-gate #include <sys/memnode.h>
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate /*
527c478bd9Sstevel@tonic-gate  * Pass 0 of cpuid feature analysis happens in locore. It contains special code
537c478bd9Sstevel@tonic-gate  * to recognize Cyrix processors that are not cpuid-compliant, and to deal with
547c478bd9Sstevel@tonic-gate  * them accordingly. For most modern processors, feature detection occurs here
557c478bd9Sstevel@tonic-gate  * in pass 1.
567c478bd9Sstevel@tonic-gate  *
577c478bd9Sstevel@tonic-gate  * Pass 1 of cpuid feature analysis happens just at the beginning of mlsetup()
587c478bd9Sstevel@tonic-gate  * for the boot CPU and does the basic analysis that the early kernel needs.
597c478bd9Sstevel@tonic-gate  * x86_feature is set based on the return value of cpuid_pass1() of the boot
607c478bd9Sstevel@tonic-gate  * CPU.
617c478bd9Sstevel@tonic-gate  *
627c478bd9Sstevel@tonic-gate  * Pass 1 includes:
637c478bd9Sstevel@tonic-gate  *
647c478bd9Sstevel@tonic-gate  *	o Determining vendor/model/family/stepping and setting x86_type and
657c478bd9Sstevel@tonic-gate  *	  x86_vendor accordingly.
667c478bd9Sstevel@tonic-gate  *	o Processing the feature flags returned by the cpuid instruction while
677c478bd9Sstevel@tonic-gate  *	  applying any workarounds or tricks for the specific processor.
687c478bd9Sstevel@tonic-gate  *	o Mapping the feature flags into Solaris feature bits (X86_*).
697c478bd9Sstevel@tonic-gate  *	o Processing extended feature flags if supported by the processor,
707c478bd9Sstevel@tonic-gate  *	  again while applying specific processor knowledge.
717c478bd9Sstevel@tonic-gate  *	o Determining the CMT characteristics of the system.
727c478bd9Sstevel@tonic-gate  *
737c478bd9Sstevel@tonic-gate  * Pass 1 is done on non-boot CPUs during their initialization and the results
747c478bd9Sstevel@tonic-gate  * are used only as a meager attempt at ensuring that all processors within the
757c478bd9Sstevel@tonic-gate  * system support the same features.
767c478bd9Sstevel@tonic-gate  *
777c478bd9Sstevel@tonic-gate  * Pass 2 of cpuid feature analysis happens just at the beginning
787c478bd9Sstevel@tonic-gate  * of startup().  It just copies in and corrects the remainder
797c478bd9Sstevel@tonic-gate  * of the cpuid data we depend on: standard cpuid functions that we didn't
807c478bd9Sstevel@tonic-gate  * need for pass1 feature analysis, and extended cpuid functions beyond the
817c478bd9Sstevel@tonic-gate  * simple feature processing done in pass1.
827c478bd9Sstevel@tonic-gate  *
837c478bd9Sstevel@tonic-gate  * Pass 3 of cpuid analysis is invoked after basic kernel services; in
847c478bd9Sstevel@tonic-gate  * particular kernel memory allocation has been made available. It creates a
857c478bd9Sstevel@tonic-gate  * readable brand string based on the data collected in the first two passes.
867c478bd9Sstevel@tonic-gate  *
877c478bd9Sstevel@tonic-gate  * Pass 4 of cpuid analysis is invoked after post_startup() when all
887c478bd9Sstevel@tonic-gate  * the support infrastructure for various hardware features has been
897c478bd9Sstevel@tonic-gate  * initialized. It determines which processor features will be reported
907c478bd9Sstevel@tonic-gate  * to userland via the aux vector.
917c478bd9Sstevel@tonic-gate  *
927c478bd9Sstevel@tonic-gate  * All passes are executed on all CPUs, but only the boot CPU determines what
937c478bd9Sstevel@tonic-gate  * features the kernel will use.
947c478bd9Sstevel@tonic-gate  *
957c478bd9Sstevel@tonic-gate  * Much of the worst junk in this file is for the support of processors
967c478bd9Sstevel@tonic-gate  * that didn't really implement the cpuid instruction properly.
977c478bd9Sstevel@tonic-gate  *
987c478bd9Sstevel@tonic-gate  * NOTE: The accessor functions (cpuid_get*) are aware of, and ASSERT upon,
997c478bd9Sstevel@tonic-gate  * the pass numbers.  Accordingly, changes to the pass code may require changes
1007c478bd9Sstevel@tonic-gate  * to the accessor code.
1017c478bd9Sstevel@tonic-gate  */
1027c478bd9Sstevel@tonic-gate 
1037c478bd9Sstevel@tonic-gate uint_t x86_feature = 0;
1047c478bd9Sstevel@tonic-gate uint_t x86_vendor = X86_VENDOR_IntelClone;
1057c478bd9Sstevel@tonic-gate uint_t x86_type = X86_TYPE_OTHER;
1067c478bd9Sstevel@tonic-gate 
1077c478bd9Sstevel@tonic-gate uint_t pentiumpro_bug4046376;
1087c478bd9Sstevel@tonic-gate uint_t pentiumpro_bug4064495;
1097c478bd9Sstevel@tonic-gate 
1107c478bd9Sstevel@tonic-gate uint_t enable486;
1117c478bd9Sstevel@tonic-gate 
1127c478bd9Sstevel@tonic-gate /*
1137c478bd9Sstevel@tonic-gate  * This set of strings are for processors rumored to support the cpuid
1147c478bd9Sstevel@tonic-gate  * instruction, and is used by locore.s to figure out how to set x86_vendor
1157c478bd9Sstevel@tonic-gate  */
1167c478bd9Sstevel@tonic-gate const char CyrixInstead[] = "CyrixInstead";
1177c478bd9Sstevel@tonic-gate 
1187c478bd9Sstevel@tonic-gate /*
119f98fbcecSbholler  * monitor/mwait info.
1205b8a6efeSbholler  *
1215b8a6efeSbholler  * size_actual and buf_actual are the real address and size allocated to get
1225b8a6efeSbholler  * proper mwait_buf alignement.  buf_actual and size_actual should be passed
1235b8a6efeSbholler  * to kmem_free().  Currently kmem_alloc() and mwait happen to both use
1245b8a6efeSbholler  * processor cache-line alignment, but this is not guarantied in the furture.
125f98fbcecSbholler  */
126f98fbcecSbholler struct mwait_info {
127f98fbcecSbholler 	size_t		mon_min;	/* min size to avoid missed wakeups */
128f98fbcecSbholler 	size_t		mon_max;	/* size to avoid false wakeups */
1295b8a6efeSbholler 	size_t		size_actual;	/* size actually allocated */
1305b8a6efeSbholler 	void		*buf_actual;	/* memory actually allocated */
131f98fbcecSbholler 	uint32_t	support;	/* processor support of monitor/mwait */
132f98fbcecSbholler };
133f98fbcecSbholler 
134f98fbcecSbholler /*
1357c478bd9Sstevel@tonic-gate  * These constants determine how many of the elements of the
1367c478bd9Sstevel@tonic-gate  * cpuid we cache in the cpuid_info data structure; the
1377c478bd9Sstevel@tonic-gate  * remaining elements are accessible via the cpuid instruction.
1387c478bd9Sstevel@tonic-gate  */
1397c478bd9Sstevel@tonic-gate 
1407c478bd9Sstevel@tonic-gate #define	NMAX_CPI_STD	6		/* eax = 0 .. 5 */
1417c478bd9Sstevel@tonic-gate #define	NMAX_CPI_EXTD	9		/* eax = 0x80000000 .. 0x80000008 */
1427c478bd9Sstevel@tonic-gate 
1437c478bd9Sstevel@tonic-gate struct cpuid_info {
1447c478bd9Sstevel@tonic-gate 	uint_t cpi_pass;		/* last pass completed */
1457c478bd9Sstevel@tonic-gate 	/*
1467c478bd9Sstevel@tonic-gate 	 * standard function information
1477c478bd9Sstevel@tonic-gate 	 */
1487c478bd9Sstevel@tonic-gate 	uint_t cpi_maxeax;		/* fn 0: %eax */
1497c478bd9Sstevel@tonic-gate 	char cpi_vendorstr[13];		/* fn 0: %ebx:%ecx:%edx */
1507c478bd9Sstevel@tonic-gate 	uint_t cpi_vendor;		/* enum of cpi_vendorstr */
1517c478bd9Sstevel@tonic-gate 
1527c478bd9Sstevel@tonic-gate 	uint_t cpi_family;		/* fn 1: extended family */
1537c478bd9Sstevel@tonic-gate 	uint_t cpi_model;		/* fn 1: extended model */
1547c478bd9Sstevel@tonic-gate 	uint_t cpi_step;		/* fn 1: stepping */
1557c478bd9Sstevel@tonic-gate 	chipid_t cpi_chipid;		/* fn 1: %ebx: chip # on ht cpus */
1567c478bd9Sstevel@tonic-gate 	uint_t cpi_brandid;		/* fn 1: %ebx: brand ID */
1577c478bd9Sstevel@tonic-gate 	int cpi_clogid;			/* fn 1: %ebx: thread # */
1588949bcd6Sandrei 	uint_t cpi_ncpu_per_chip;	/* fn 1: %ebx: logical cpu count */
1597c478bd9Sstevel@tonic-gate 	uint8_t cpi_cacheinfo[16];	/* fn 2: intel-style cache desc */
1607c478bd9Sstevel@tonic-gate 	uint_t cpi_ncache;		/* fn 2: number of elements */
161d129bde2Sesaxe 	uint_t cpi_ncpu_shr_last_cache;	/* fn 4: %eax: ncpus sharing cache */
162d129bde2Sesaxe 	id_t cpi_last_lvl_cacheid;	/* fn 4: %eax: derived cache id */
163d129bde2Sesaxe 	uint_t cpi_std_4_size;		/* fn 4: number of fn 4 elements */
164d129bde2Sesaxe 	struct cpuid_regs **cpi_std_4;	/* fn 4: %ecx == 0 .. fn4_size */
1658949bcd6Sandrei 	struct cpuid_regs cpi_std[NMAX_CPI_STD];	/* 0 .. 5 */
1667c478bd9Sstevel@tonic-gate 	/*
1677c478bd9Sstevel@tonic-gate 	 * extended function information
1687c478bd9Sstevel@tonic-gate 	 */
1697c478bd9Sstevel@tonic-gate 	uint_t cpi_xmaxeax;		/* fn 0x80000000: %eax */
1707c478bd9Sstevel@tonic-gate 	char cpi_brandstr[49];		/* fn 0x8000000[234] */
1717c478bd9Sstevel@tonic-gate 	uint8_t cpi_pabits;		/* fn 0x80000006: %eax */
1727c478bd9Sstevel@tonic-gate 	uint8_t cpi_vabits;		/* fn 0x80000006: %eax */
1738949bcd6Sandrei 	struct cpuid_regs cpi_extd[NMAX_CPI_EXTD]; /* 0x8000000[0-8] */
17410569901Sgavinm 	id_t cpi_coreid;		/* same coreid => strands share core */
17510569901Sgavinm 	int cpi_pkgcoreid;		/* core number within single package */
1768949bcd6Sandrei 	uint_t cpi_ncore_per_chip;	/* AMD: fn 0x80000008: %ecx[7-0] */
1778949bcd6Sandrei 					/* Intel: fn 4: %eax[31-26] */
1787c478bd9Sstevel@tonic-gate 	/*
1797c478bd9Sstevel@tonic-gate 	 * supported feature information
1807c478bd9Sstevel@tonic-gate 	 */
181ae115bc7Smrj 	uint32_t cpi_support[5];
1827c478bd9Sstevel@tonic-gate #define	STD_EDX_FEATURES	0
1837c478bd9Sstevel@tonic-gate #define	AMD_EDX_FEATURES	1
1847c478bd9Sstevel@tonic-gate #define	TM_EDX_FEATURES		2
1857c478bd9Sstevel@tonic-gate #define	STD_ECX_FEATURES	3
186ae115bc7Smrj #define	AMD_ECX_FEATURES	4
1878a40a695Sgavinm 	/*
1888a40a695Sgavinm 	 * Synthesized information, where known.
1898a40a695Sgavinm 	 */
1908a40a695Sgavinm 	uint32_t cpi_chiprev;		/* See X86_CHIPREV_* in x86_archext.h */
1918a40a695Sgavinm 	const char *cpi_chiprevstr;	/* May be NULL if chiprev unknown */
1928a40a695Sgavinm 	uint32_t cpi_socket;		/* Chip package/socket type */
193f98fbcecSbholler 
194f98fbcecSbholler 	struct mwait_info cpi_mwait;	/* fn 5: monitor/mwait info */
195*b6917abeSmishra 	uint32_t cpi_apicid;
1967c478bd9Sstevel@tonic-gate };
1977c478bd9Sstevel@tonic-gate 
1987c478bd9Sstevel@tonic-gate 
1997c478bd9Sstevel@tonic-gate static struct cpuid_info cpuid_info0;
2007c478bd9Sstevel@tonic-gate 
2017c478bd9Sstevel@tonic-gate /*
2027c478bd9Sstevel@tonic-gate  * These bit fields are defined by the Intel Application Note AP-485
2037c478bd9Sstevel@tonic-gate  * "Intel Processor Identification and the CPUID Instruction"
2047c478bd9Sstevel@tonic-gate  */
2057c478bd9Sstevel@tonic-gate #define	CPI_FAMILY_XTD(cpi)	BITX((cpi)->cpi_std[1].cp_eax, 27, 20)
2067c478bd9Sstevel@tonic-gate #define	CPI_MODEL_XTD(cpi)	BITX((cpi)->cpi_std[1].cp_eax, 19, 16)
2077c478bd9Sstevel@tonic-gate #define	CPI_TYPE(cpi)		BITX((cpi)->cpi_std[1].cp_eax, 13, 12)
2087c478bd9Sstevel@tonic-gate #define	CPI_FAMILY(cpi)		BITX((cpi)->cpi_std[1].cp_eax, 11, 8)
2097c478bd9Sstevel@tonic-gate #define	CPI_STEP(cpi)		BITX((cpi)->cpi_std[1].cp_eax, 3, 0)
2107c478bd9Sstevel@tonic-gate #define	CPI_MODEL(cpi)		BITX((cpi)->cpi_std[1].cp_eax, 7, 4)
2117c478bd9Sstevel@tonic-gate 
2127c478bd9Sstevel@tonic-gate #define	CPI_FEATURES_EDX(cpi)		((cpi)->cpi_std[1].cp_edx)
2137c478bd9Sstevel@tonic-gate #define	CPI_FEATURES_ECX(cpi)		((cpi)->cpi_std[1].cp_ecx)
2147c478bd9Sstevel@tonic-gate #define	CPI_FEATURES_XTD_EDX(cpi)	((cpi)->cpi_extd[1].cp_edx)
2157c478bd9Sstevel@tonic-gate #define	CPI_FEATURES_XTD_ECX(cpi)	((cpi)->cpi_extd[1].cp_ecx)
2167c478bd9Sstevel@tonic-gate 
2177c478bd9Sstevel@tonic-gate #define	CPI_BRANDID(cpi)	BITX((cpi)->cpi_std[1].cp_ebx, 7, 0)
2187c478bd9Sstevel@tonic-gate #define	CPI_CHUNKS(cpi)		BITX((cpi)->cpi_std[1].cp_ebx, 15, 7)
2197c478bd9Sstevel@tonic-gate #define	CPI_CPU_COUNT(cpi)	BITX((cpi)->cpi_std[1].cp_ebx, 23, 16)
2207c478bd9Sstevel@tonic-gate #define	CPI_APIC_ID(cpi)	BITX((cpi)->cpi_std[1].cp_ebx, 31, 24)
2217c478bd9Sstevel@tonic-gate 
2227c478bd9Sstevel@tonic-gate #define	CPI_MAXEAX_MAX		0x100		/* sanity control */
2237c478bd9Sstevel@tonic-gate #define	CPI_XMAXEAX_MAX		0x80000100
224d129bde2Sesaxe #define	CPI_FN4_ECX_MAX		0x20		/* sanity: max fn 4 levels */
225*b6917abeSmishra #define	CPI_FNB_ECX_MAX		0x20		/* sanity: max fn B levels */
226d129bde2Sesaxe 
227d129bde2Sesaxe /*
228d129bde2Sesaxe  * Function 4 (Deterministic Cache Parameters) macros
229d129bde2Sesaxe  * Defined by Intel Application Note AP-485
230d129bde2Sesaxe  */
231d129bde2Sesaxe #define	CPI_NUM_CORES(regs)		BITX((regs)->cp_eax, 31, 26)
232d129bde2Sesaxe #define	CPI_NTHR_SHR_CACHE(regs)	BITX((regs)->cp_eax, 25, 14)
233d129bde2Sesaxe #define	CPI_FULL_ASSOC_CACHE(regs)	BITX((regs)->cp_eax, 9, 9)
234d129bde2Sesaxe #define	CPI_SELF_INIT_CACHE(regs)	BITX((regs)->cp_eax, 8, 8)
235d129bde2Sesaxe #define	CPI_CACHE_LVL(regs)		BITX((regs)->cp_eax, 7, 5)
236d129bde2Sesaxe #define	CPI_CACHE_TYPE(regs)		BITX((regs)->cp_eax, 4, 0)
237*b6917abeSmishra #define	CPI_CPU_LEVEL_TYPE(regs)	BITX((regs)->cp_ecx, 15, 8)
238d129bde2Sesaxe 
239d129bde2Sesaxe #define	CPI_CACHE_WAYS(regs)		BITX((regs)->cp_ebx, 31, 22)
240d129bde2Sesaxe #define	CPI_CACHE_PARTS(regs)		BITX((regs)->cp_ebx, 21, 12)
241d129bde2Sesaxe #define	CPI_CACHE_COH_LN_SZ(regs)	BITX((regs)->cp_ebx, 11, 0)
242d129bde2Sesaxe 
243d129bde2Sesaxe #define	CPI_CACHE_SETS(regs)		BITX((regs)->cp_ecx, 31, 0)
244d129bde2Sesaxe 
245d129bde2Sesaxe #define	CPI_PREFCH_STRIDE(regs)		BITX((regs)->cp_edx, 9, 0)
246d129bde2Sesaxe 
2477c478bd9Sstevel@tonic-gate 
2487c478bd9Sstevel@tonic-gate /*
2495ff02082Sdmick  * A couple of shorthand macros to identify "later" P6-family chips
2505ff02082Sdmick  * like the Pentium M and Core.  First, the "older" P6-based stuff
2515ff02082Sdmick  * (loosely defined as "pre-Pentium-4"):
2525ff02082Sdmick  * P6, PII, Mobile PII, PII Xeon, PIII, Mobile PIII, PIII Xeon
2535ff02082Sdmick  */
2545ff02082Sdmick 
2555ff02082Sdmick #define	IS_LEGACY_P6(cpi) (			\
2565ff02082Sdmick 	cpi->cpi_family == 6 && 		\
2575ff02082Sdmick 		(cpi->cpi_model == 1 ||		\
2585ff02082Sdmick 		cpi->cpi_model == 3 ||		\
2595ff02082Sdmick 		cpi->cpi_model == 5 ||		\
2605ff02082Sdmick 		cpi->cpi_model == 6 ||		\
2615ff02082Sdmick 		cpi->cpi_model == 7 ||		\
2625ff02082Sdmick 		cpi->cpi_model == 8 ||		\
2635ff02082Sdmick 		cpi->cpi_model == 0xA ||	\
2645ff02082Sdmick 		cpi->cpi_model == 0xB)		\
2655ff02082Sdmick )
2665ff02082Sdmick 
2675ff02082Sdmick /* A "new F6" is everything with family 6 that's not the above */
2685ff02082Sdmick #define	IS_NEW_F6(cpi) ((cpi->cpi_family == 6) && !IS_LEGACY_P6(cpi))
2695ff02082Sdmick 
270bf91205bSksadhukh /* Extended family/model support */
271bf91205bSksadhukh #define	IS_EXTENDED_MODEL_INTEL(cpi) (cpi->cpi_family == 0x6 || \
272bf91205bSksadhukh 	cpi->cpi_family >= 0xf)
273bf91205bSksadhukh 
2745ff02082Sdmick /*
27531725658Sksadhukh  * AMD family 0xf and family 0x10 socket types.
27631725658Sksadhukh  * First index :
27731725658Sksadhukh  *		0 for family 0xf, revs B thru E
27831725658Sksadhukh  *		1 for family 0xf, revs F and G
27931725658Sksadhukh  *		2 for family 0x10, rev B
2808a40a695Sgavinm  * Second index by (model & 0x3)
2818a40a695Sgavinm  */
28231725658Sksadhukh static uint32_t amd_skts[3][4] = {
28320c794b3Sgavinm 	/*
28420c794b3Sgavinm 	 * Family 0xf revisions B through E
28520c794b3Sgavinm 	 */
28620c794b3Sgavinm #define	A_SKTS_0			0
2878a40a695Sgavinm 	{
2888a40a695Sgavinm 		X86_SOCKET_754,		/* 0b00 */
2898a40a695Sgavinm 		X86_SOCKET_940,		/* 0b01 */
2908a40a695Sgavinm 		X86_SOCKET_754,		/* 0b10 */
2918a40a695Sgavinm 		X86_SOCKET_939		/* 0b11 */
2928a40a695Sgavinm 	},
29320c794b3Sgavinm 	/*
29420c794b3Sgavinm 	 * Family 0xf revisions F and G
29520c794b3Sgavinm 	 */
29620c794b3Sgavinm #define	A_SKTS_1			1
2978a40a695Sgavinm 	{
2988a40a695Sgavinm 		X86_SOCKET_S1g1,	/* 0b00 */
2998a40a695Sgavinm 		X86_SOCKET_F1207,	/* 0b01 */
3008a40a695Sgavinm 		X86_SOCKET_UNKNOWN,	/* 0b10 */
3018a40a695Sgavinm 		X86_SOCKET_AM2		/* 0b11 */
30231725658Sksadhukh 	},
30320c794b3Sgavinm 	/*
30420c794b3Sgavinm 	 * Family 0x10 revisions A and B
30520c794b3Sgavinm 	 * It is not clear whether, as new sockets release, that
30620c794b3Sgavinm 	 * model & 0x3 will id socket for this family
30720c794b3Sgavinm 	 */
30820c794b3Sgavinm #define	A_SKTS_2			2
30931725658Sksadhukh 	{
31031725658Sksadhukh 		X86_SOCKET_F1207,	/* 0b00 */
31131725658Sksadhukh 		X86_SOCKET_F1207,	/* 0b01 */
31231725658Sksadhukh 		X86_SOCKET_F1207,	/* 0b10 */
31320c794b3Sgavinm 		X86_SOCKET_F1207,	/* 0b11 */
3148a40a695Sgavinm 	}
3158a40a695Sgavinm };
3168a40a695Sgavinm 
3178a40a695Sgavinm /*
31831725658Sksadhukh  * Table for mapping AMD Family 0xf and AMD Family 0x10 model/stepping
31931725658Sksadhukh  * combination to chip "revision" and socket type.
3208a40a695Sgavinm  *
3218a40a695Sgavinm  * The first member of this array that matches a given family, extended model
3228a40a695Sgavinm  * plus model range, and stepping range will be considered a match.
3238a40a695Sgavinm  */
3248a40a695Sgavinm static const struct amd_rev_mapent {
3258a40a695Sgavinm 	uint_t rm_family;
3268a40a695Sgavinm 	uint_t rm_modello;
3278a40a695Sgavinm 	uint_t rm_modelhi;
3288a40a695Sgavinm 	uint_t rm_steplo;
3298a40a695Sgavinm 	uint_t rm_stephi;
3308a40a695Sgavinm 	uint32_t rm_chiprev;
3318a40a695Sgavinm 	const char *rm_chiprevstr;
3328a40a695Sgavinm 	int rm_sktidx;
3338a40a695Sgavinm } amd_revmap[] = {
3348a40a695Sgavinm 	/*
33520c794b3Sgavinm 	 * =============== AuthenticAMD Family 0xf ===============
33620c794b3Sgavinm 	 */
33720c794b3Sgavinm 
33820c794b3Sgavinm 	/*
3398a40a695Sgavinm 	 * Rev B includes model 0x4 stepping 0 and model 0x5 stepping 0 and 1.
3408a40a695Sgavinm 	 */
34120c794b3Sgavinm 	{ 0xf, 0x04, 0x04, 0x0, 0x0, X86_CHIPREV_AMD_F_REV_B, "B", A_SKTS_0 },
34220c794b3Sgavinm 	{ 0xf, 0x05, 0x05, 0x0, 0x1, X86_CHIPREV_AMD_F_REV_B, "B", A_SKTS_0 },
3438a40a695Sgavinm 	/*
3448a40a695Sgavinm 	 * Rev C0 includes model 0x4 stepping 8 and model 0x5 stepping 8
3458a40a695Sgavinm 	 */
34620c794b3Sgavinm 	{ 0xf, 0x04, 0x05, 0x8, 0x8, X86_CHIPREV_AMD_F_REV_C0, "C0", A_SKTS_0 },
3478a40a695Sgavinm 	/*
3488a40a695Sgavinm 	 * Rev CG is the rest of extended model 0x0 - i.e., everything
3498a40a695Sgavinm 	 * but the rev B and C0 combinations covered above.
3508a40a695Sgavinm 	 */
35120c794b3Sgavinm 	{ 0xf, 0x00, 0x0f, 0x0, 0xf, X86_CHIPREV_AMD_F_REV_CG, "CG", A_SKTS_0 },
3528a40a695Sgavinm 	/*
3538a40a695Sgavinm 	 * Rev D has extended model 0x1.
3548a40a695Sgavinm 	 */
35520c794b3Sgavinm 	{ 0xf, 0x10, 0x1f, 0x0, 0xf, X86_CHIPREV_AMD_F_REV_D, "D", A_SKTS_0 },
3568a40a695Sgavinm 	/*
3578a40a695Sgavinm 	 * Rev E has extended model 0x2.
3588a40a695Sgavinm 	 * Extended model 0x3 is unused but available to grow into.
3598a40a695Sgavinm 	 */
36020c794b3Sgavinm 	{ 0xf, 0x20, 0x3f, 0x0, 0xf, X86_CHIPREV_AMD_F_REV_E, "E", A_SKTS_0 },
3618a40a695Sgavinm 	/*
3628a40a695Sgavinm 	 * Rev F has extended models 0x4 and 0x5.
3638a40a695Sgavinm 	 */
36420c794b3Sgavinm 	{ 0xf, 0x40, 0x5f, 0x0, 0xf, X86_CHIPREV_AMD_F_REV_F, "F", A_SKTS_1 },
3658a40a695Sgavinm 	/*
3668a40a695Sgavinm 	 * Rev G has extended model 0x6.
3678a40a695Sgavinm 	 */
36820c794b3Sgavinm 	{ 0xf, 0x60, 0x6f, 0x0, 0xf, X86_CHIPREV_AMD_F_REV_G, "G", A_SKTS_1 },
36920c794b3Sgavinm 
37031725658Sksadhukh 	/*
37120c794b3Sgavinm 	 * =============== AuthenticAMD Family 0x10 ===============
37231725658Sksadhukh 	 */
37320c794b3Sgavinm 
37420c794b3Sgavinm 	/*
37520c794b3Sgavinm 	 * Rev A has model 0 and stepping 0/1/2 for DR-{A0,A1,A2}.
37620c794b3Sgavinm 	 * Give all of model 0 stepping range to rev A.
37720c794b3Sgavinm 	 */
37820c794b3Sgavinm 	{ 0x10, 0x00, 0x00, 0x0, 0x2, X86_CHIPREV_AMD_10_REV_A, "A", A_SKTS_2 },
37920c794b3Sgavinm 
38020c794b3Sgavinm 	/*
38120c794b3Sgavinm 	 * Rev B has model 2 and steppings 0/1/0xa/2 for DR-{B0,B1,BA,B2}.
38220c794b3Sgavinm 	 * Give all of model 2 stepping range to rev B.
38320c794b3Sgavinm 	 */
38420c794b3Sgavinm 	{ 0x10, 0x02, 0x02, 0x0, 0xf, X86_CHIPREV_AMD_10_REV_B, "B", A_SKTS_2 },
3858a40a695Sgavinm };
3868a40a695Sgavinm 
387f98fbcecSbholler /*
388f98fbcecSbholler  * Info for monitor/mwait idle loop.
389f98fbcecSbholler  *
390f98fbcecSbholler  * See cpuid section of "Intel 64 and IA-32 Architectures Software Developer's
391f98fbcecSbholler  * Manual Volume 2A: Instruction Set Reference, A-M" #25366-022US, November
392f98fbcecSbholler  * 2006.
393f98fbcecSbholler  * See MONITOR/MWAIT section of "AMD64 Architecture Programmer's Manual
394f98fbcecSbholler  * Documentation Updates" #33633, Rev 2.05, December 2006.
395f98fbcecSbholler  */
396f98fbcecSbholler #define	MWAIT_SUPPORT		(0x00000001)	/* mwait supported */
397f98fbcecSbholler #define	MWAIT_EXTENSIONS	(0x00000002)	/* extenstion supported */
398f98fbcecSbholler #define	MWAIT_ECX_INT_ENABLE	(0x00000004)	/* ecx 1 extension supported */
399f98fbcecSbholler #define	MWAIT_SUPPORTED(cpi)	((cpi)->cpi_std[1].cp_ecx & CPUID_INTC_ECX_MON)
400f98fbcecSbholler #define	MWAIT_INT_ENABLE(cpi)	((cpi)->cpi_std[5].cp_ecx & 0x2)
401f98fbcecSbholler #define	MWAIT_EXTENSION(cpi)	((cpi)->cpi_std[5].cp_ecx & 0x1)
402f98fbcecSbholler #define	MWAIT_SIZE_MIN(cpi)	BITX((cpi)->cpi_std[5].cp_eax, 15, 0)
403f98fbcecSbholler #define	MWAIT_SIZE_MAX(cpi)	BITX((cpi)->cpi_std[5].cp_ebx, 15, 0)
404f98fbcecSbholler /*
405f98fbcecSbholler  * Number of sub-cstates for a given c-state.
406f98fbcecSbholler  */
407f98fbcecSbholler #define	MWAIT_NUM_SUBC_STATES(cpi, c_state)			\
408f98fbcecSbholler 	BITX((cpi)->cpi_std[5].cp_edx, c_state + 3, c_state)
409f98fbcecSbholler 
4108a40a695Sgavinm static void
4118a40a695Sgavinm synth_amd_info(struct cpuid_info *cpi)
4128a40a695Sgavinm {
4138a40a695Sgavinm 	const struct amd_rev_mapent *rmp;
4148a40a695Sgavinm 	uint_t family, model, step;
4158a40a695Sgavinm 	int i;
4168a40a695Sgavinm 
4178a40a695Sgavinm 	/*
41831725658Sksadhukh 	 * Currently only AMD family 0xf and family 0x10 use these fields.
4198a40a695Sgavinm 	 */
42031725658Sksadhukh 	if (cpi->cpi_family != 0xf && cpi->cpi_family != 0x10)
4218a40a695Sgavinm 		return;
4228a40a695Sgavinm 
4238a40a695Sgavinm 	family = cpi->cpi_family;
4248a40a695Sgavinm 	model = cpi->cpi_model;
4258a40a695Sgavinm 	step = cpi->cpi_step;
4268a40a695Sgavinm 
4278a40a695Sgavinm 	for (i = 0, rmp = amd_revmap; i < sizeof (amd_revmap) / sizeof (*rmp);
4288a40a695Sgavinm 	    i++, rmp++) {
4298a40a695Sgavinm 		if (family == rmp->rm_family &&
4308a40a695Sgavinm 		    model >= rmp->rm_modello && model <= rmp->rm_modelhi &&
4318a40a695Sgavinm 		    step >= rmp->rm_steplo && step <= rmp->rm_stephi) {
4328a40a695Sgavinm 			cpi->cpi_chiprev = rmp->rm_chiprev;
4338a40a695Sgavinm 			cpi->cpi_chiprevstr = rmp->rm_chiprevstr;
4348a40a695Sgavinm 			cpi->cpi_socket = amd_skts[rmp->rm_sktidx][model & 0x3];
4358a40a695Sgavinm 			return;
4368a40a695Sgavinm 		}
4378a40a695Sgavinm 	}
4388a40a695Sgavinm }
4398a40a695Sgavinm 
4408a40a695Sgavinm static void
4418a40a695Sgavinm synth_info(struct cpuid_info *cpi)
4428a40a695Sgavinm {
4438a40a695Sgavinm 	cpi->cpi_chiprev = X86_CHIPREV_UNKNOWN;
4448a40a695Sgavinm 	cpi->cpi_chiprevstr = "Unknown";
4458a40a695Sgavinm 	cpi->cpi_socket = X86_SOCKET_UNKNOWN;
4468a40a695Sgavinm 
4478a40a695Sgavinm 	switch (cpi->cpi_vendor) {
4488a40a695Sgavinm 	case X86_VENDOR_AMD:
4498a40a695Sgavinm 		synth_amd_info(cpi);
4508a40a695Sgavinm 		break;
4518a40a695Sgavinm 
4528a40a695Sgavinm 	default:
4538a40a695Sgavinm 		break;
4548a40a695Sgavinm 
4558a40a695Sgavinm 	}
4568a40a695Sgavinm }
4578a40a695Sgavinm 
4588a40a695Sgavinm /*
459ae115bc7Smrj  * Apply up various platform-dependent restrictions where the
460ae115bc7Smrj  * underlying platform restrictions mean the CPU can be marked
461ae115bc7Smrj  * as less capable than its cpuid instruction would imply.
462ae115bc7Smrj  */
463843e1988Sjohnlev #if defined(__xpv)
464843e1988Sjohnlev static void
465843e1988Sjohnlev platform_cpuid_mangle(uint_t vendor, uint32_t eax, struct cpuid_regs *cp)
466843e1988Sjohnlev {
467843e1988Sjohnlev 	switch (eax) {
468843e1988Sjohnlev 	case 1:
469843e1988Sjohnlev 		cp->cp_edx &=
470843e1988Sjohnlev 		    ~(CPUID_INTC_EDX_PSE |
471843e1988Sjohnlev 		    CPUID_INTC_EDX_VME | CPUID_INTC_EDX_DE |
472843e1988Sjohnlev 		    CPUID_INTC_EDX_MCA |	/* XXPV true on dom0? */
473843e1988Sjohnlev 		    CPUID_INTC_EDX_SEP | CPUID_INTC_EDX_MTRR |
474843e1988Sjohnlev 		    CPUID_INTC_EDX_PGE | CPUID_INTC_EDX_PAT |
475843e1988Sjohnlev 		    CPUID_AMD_EDX_SYSC | CPUID_INTC_EDX_SEP |
476843e1988Sjohnlev 		    CPUID_INTC_EDX_PSE36 | CPUID_INTC_EDX_HTT);
477843e1988Sjohnlev 		break;
478ae115bc7Smrj 
479843e1988Sjohnlev 	case 0x80000001:
480843e1988Sjohnlev 		cp->cp_edx &=
481843e1988Sjohnlev 		    ~(CPUID_AMD_EDX_PSE |
482843e1988Sjohnlev 		    CPUID_INTC_EDX_VME | CPUID_INTC_EDX_DE |
483843e1988Sjohnlev 		    CPUID_AMD_EDX_MTRR | CPUID_AMD_EDX_PGE |
484843e1988Sjohnlev 		    CPUID_AMD_EDX_PAT | CPUID_AMD_EDX_PSE36 |
485843e1988Sjohnlev 		    CPUID_AMD_EDX_SYSC | CPUID_INTC_EDX_SEP |
486843e1988Sjohnlev 		    CPUID_AMD_EDX_TSCP);
487843e1988Sjohnlev 		cp->cp_ecx &= ~CPUID_AMD_ECX_CMP_LGCY;
488843e1988Sjohnlev 		break;
489843e1988Sjohnlev 	default:
490843e1988Sjohnlev 		break;
491843e1988Sjohnlev 	}
492843e1988Sjohnlev 
493843e1988Sjohnlev 	switch (vendor) {
494843e1988Sjohnlev 	case X86_VENDOR_Intel:
495843e1988Sjohnlev 		switch (eax) {
496843e1988Sjohnlev 		case 4:
497843e1988Sjohnlev 			/*
498843e1988Sjohnlev 			 * Zero out the (ncores-per-chip - 1) field
499843e1988Sjohnlev 			 */
500843e1988Sjohnlev 			cp->cp_eax &= 0x03fffffff;
501843e1988Sjohnlev 			break;
502843e1988Sjohnlev 		default:
503843e1988Sjohnlev 			break;
504843e1988Sjohnlev 		}
505843e1988Sjohnlev 		break;
506843e1988Sjohnlev 	case X86_VENDOR_AMD:
507843e1988Sjohnlev 		switch (eax) {
508843e1988Sjohnlev 		case 0x80000008:
509843e1988Sjohnlev 			/*
510843e1988Sjohnlev 			 * Zero out the (ncores-per-chip - 1) field
511843e1988Sjohnlev 			 */
512843e1988Sjohnlev 			cp->cp_ecx &= 0xffffff00;
513843e1988Sjohnlev 			break;
514843e1988Sjohnlev 		default:
515843e1988Sjohnlev 			break;
516843e1988Sjohnlev 		}
517843e1988Sjohnlev 		break;
518843e1988Sjohnlev 	default:
519843e1988Sjohnlev 		break;
520843e1988Sjohnlev 	}
521843e1988Sjohnlev }
522843e1988Sjohnlev #else
523ae115bc7Smrj #define	platform_cpuid_mangle(vendor, eax, cp)	/* nothing */
524843e1988Sjohnlev #endif
525ae115bc7Smrj 
526ae115bc7Smrj /*
5277c478bd9Sstevel@tonic-gate  *  Some undocumented ways of patching the results of the cpuid
5287c478bd9Sstevel@tonic-gate  *  instruction to permit running Solaris 10 on future cpus that
5297c478bd9Sstevel@tonic-gate  *  we don't currently support.  Could be set to non-zero values
5307c478bd9Sstevel@tonic-gate  *  via settings in eeprom.
5317c478bd9Sstevel@tonic-gate  */
5327c478bd9Sstevel@tonic-gate 
5337c478bd9Sstevel@tonic-gate uint32_t cpuid_feature_ecx_include;
5347c478bd9Sstevel@tonic-gate uint32_t cpuid_feature_ecx_exclude;
5357c478bd9Sstevel@tonic-gate uint32_t cpuid_feature_edx_include;
5367c478bd9Sstevel@tonic-gate uint32_t cpuid_feature_edx_exclude;
5377c478bd9Sstevel@tonic-gate 
538ae115bc7Smrj void
539ae115bc7Smrj cpuid_alloc_space(cpu_t *cpu)
540ae115bc7Smrj {
541ae115bc7Smrj 	/*
542ae115bc7Smrj 	 * By convention, cpu0 is the boot cpu, which is set up
543ae115bc7Smrj 	 * before memory allocation is available.  All other cpus get
544ae115bc7Smrj 	 * their cpuid_info struct allocated here.
545ae115bc7Smrj 	 */
546ae115bc7Smrj 	ASSERT(cpu->cpu_id != 0);
547ae115bc7Smrj 	cpu->cpu_m.mcpu_cpi =
548ae115bc7Smrj 	    kmem_zalloc(sizeof (*cpu->cpu_m.mcpu_cpi), KM_SLEEP);
549ae115bc7Smrj }
550ae115bc7Smrj 
551ae115bc7Smrj void
552ae115bc7Smrj cpuid_free_space(cpu_t *cpu)
553ae115bc7Smrj {
554d129bde2Sesaxe 	struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi;
555d129bde2Sesaxe 	int i;
556d129bde2Sesaxe 
557ae115bc7Smrj 	ASSERT(cpu->cpu_id != 0);
558d129bde2Sesaxe 
559d129bde2Sesaxe 	/*
560d129bde2Sesaxe 	 * Free up any function 4 related dynamic storage
561d129bde2Sesaxe 	 */
562d129bde2Sesaxe 	for (i = 1; i < cpi->cpi_std_4_size; i++)
563d129bde2Sesaxe 		kmem_free(cpi->cpi_std_4[i], sizeof (struct cpuid_regs));
564d129bde2Sesaxe 	if (cpi->cpi_std_4_size > 0)
565d129bde2Sesaxe 		kmem_free(cpi->cpi_std_4,
566d129bde2Sesaxe 		    cpi->cpi_std_4_size * sizeof (struct cpuid_regs *));
567d129bde2Sesaxe 
568ae115bc7Smrj 	kmem_free(cpu->cpu_m.mcpu_cpi, sizeof (*cpu->cpu_m.mcpu_cpi));
569ae115bc7Smrj }
570ae115bc7Smrj 
571551bc2a6Smrj #if !defined(__xpv)
572551bc2a6Smrj 
573551bc2a6Smrj static void
574551bc2a6Smrj check_for_hvm()
575551bc2a6Smrj {
576551bc2a6Smrj 	struct cpuid_regs cp;
577551bc2a6Smrj 	char *xen_str;
578551bc2a6Smrj 	uint32_t xen_signature[4];
579551bc2a6Smrj 	extern int xpv_is_hvm;
580551bc2a6Smrj 
581551bc2a6Smrj 	/*
582551bc2a6Smrj 	 * In a fully virtualized domain, Xen's pseudo-cpuid function
583551bc2a6Smrj 	 * 0x40000000 returns a string representing the Xen signature in
584551bc2a6Smrj 	 * %ebx, %ecx, and %edx.  %eax contains the maximum supported cpuid
585551bc2a6Smrj 	 * function.
586551bc2a6Smrj 	 */
587551bc2a6Smrj 	cp.cp_eax = 0x40000000;
588551bc2a6Smrj 	(void) __cpuid_insn(&cp);
589551bc2a6Smrj 	xen_signature[0] = cp.cp_ebx;
590551bc2a6Smrj 	xen_signature[1] = cp.cp_ecx;
591551bc2a6Smrj 	xen_signature[2] = cp.cp_edx;
592551bc2a6Smrj 	xen_signature[3] = 0;
593551bc2a6Smrj 	xen_str = (char *)xen_signature;
594551bc2a6Smrj 	if (strcmp("XenVMMXenVMM", xen_str) == 0 && cp.cp_eax <= 0x40000002)
595551bc2a6Smrj 		xpv_is_hvm = 1;
596551bc2a6Smrj }
597551bc2a6Smrj #endif	/* __xpv */
598551bc2a6Smrj 
5997c478bd9Sstevel@tonic-gate uint_t
6007c478bd9Sstevel@tonic-gate cpuid_pass1(cpu_t *cpu)
6017c478bd9Sstevel@tonic-gate {
6027c478bd9Sstevel@tonic-gate 	uint32_t mask_ecx, mask_edx;
6037c478bd9Sstevel@tonic-gate 	uint_t feature = X86_CPUID;
6047c478bd9Sstevel@tonic-gate 	struct cpuid_info *cpi;
6058949bcd6Sandrei 	struct cpuid_regs *cp;
6067c478bd9Sstevel@tonic-gate 	int xcpuid;
607843e1988Sjohnlev #if !defined(__xpv)
6085b8a6efeSbholler 	extern int idle_cpu_prefer_mwait;
609843e1988Sjohnlev #endif
610ae115bc7Smrj 
6117c478bd9Sstevel@tonic-gate 	/*
612ae115bc7Smrj 	 * Space statically allocated for cpu0, ensure pointer is set
6137c478bd9Sstevel@tonic-gate 	 */
6147c478bd9Sstevel@tonic-gate 	if (cpu->cpu_id == 0)
615ae115bc7Smrj 		cpu->cpu_m.mcpu_cpi = &cpuid_info0;
616ae115bc7Smrj 	cpi = cpu->cpu_m.mcpu_cpi;
617ae115bc7Smrj 	ASSERT(cpi != NULL);
6187c478bd9Sstevel@tonic-gate 	cp = &cpi->cpi_std[0];
6198949bcd6Sandrei 	cp->cp_eax = 0;
6208949bcd6Sandrei 	cpi->cpi_maxeax = __cpuid_insn(cp);
6217c478bd9Sstevel@tonic-gate 	{
6227c478bd9Sstevel@tonic-gate 		uint32_t *iptr = (uint32_t *)cpi->cpi_vendorstr;
6237c478bd9Sstevel@tonic-gate 		*iptr++ = cp->cp_ebx;
6247c478bd9Sstevel@tonic-gate 		*iptr++ = cp->cp_edx;
6257c478bd9Sstevel@tonic-gate 		*iptr++ = cp->cp_ecx;
6267c478bd9Sstevel@tonic-gate 		*(char *)&cpi->cpi_vendorstr[12] = '\0';
6277c478bd9Sstevel@tonic-gate 	}
6287c478bd9Sstevel@tonic-gate 
6297c478bd9Sstevel@tonic-gate 	/*
6307c478bd9Sstevel@tonic-gate 	 * Map the vendor string to a type code
6317c478bd9Sstevel@tonic-gate 	 */
6327c478bd9Sstevel@tonic-gate 	if (strcmp(cpi->cpi_vendorstr, "GenuineIntel") == 0)
6337c478bd9Sstevel@tonic-gate 		cpi->cpi_vendor = X86_VENDOR_Intel;
6347c478bd9Sstevel@tonic-gate 	else if (strcmp(cpi->cpi_vendorstr, "AuthenticAMD") == 0)
6357c478bd9Sstevel@tonic-gate 		cpi->cpi_vendor = X86_VENDOR_AMD;
6367c478bd9Sstevel@tonic-gate 	else if (strcmp(cpi->cpi_vendorstr, "GenuineTMx86") == 0)
6377c478bd9Sstevel@tonic-gate 		cpi->cpi_vendor = X86_VENDOR_TM;
6387c478bd9Sstevel@tonic-gate 	else if (strcmp(cpi->cpi_vendorstr, CyrixInstead) == 0)
6397c478bd9Sstevel@tonic-gate 		/*
6407c478bd9Sstevel@tonic-gate 		 * CyrixInstead is a variable used by the Cyrix detection code
6417c478bd9Sstevel@tonic-gate 		 * in locore.
6427c478bd9Sstevel@tonic-gate 		 */
6437c478bd9Sstevel@tonic-gate 		cpi->cpi_vendor = X86_VENDOR_Cyrix;
6447c478bd9Sstevel@tonic-gate 	else if (strcmp(cpi->cpi_vendorstr, "UMC UMC UMC ") == 0)
6457c478bd9Sstevel@tonic-gate 		cpi->cpi_vendor = X86_VENDOR_UMC;
6467c478bd9Sstevel@tonic-gate 	else if (strcmp(cpi->cpi_vendorstr, "NexGenDriven") == 0)
6477c478bd9Sstevel@tonic-gate 		cpi->cpi_vendor = X86_VENDOR_NexGen;
6487c478bd9Sstevel@tonic-gate 	else if (strcmp(cpi->cpi_vendorstr, "CentaurHauls") == 0)
6497c478bd9Sstevel@tonic-gate 		cpi->cpi_vendor = X86_VENDOR_Centaur;
6507c478bd9Sstevel@tonic-gate 	else if (strcmp(cpi->cpi_vendorstr, "RiseRiseRise") == 0)
6517c478bd9Sstevel@tonic-gate 		cpi->cpi_vendor = X86_VENDOR_Rise;
6527c478bd9Sstevel@tonic-gate 	else if (strcmp(cpi->cpi_vendorstr, "SiS SiS SiS ") == 0)
6537c478bd9Sstevel@tonic-gate 		cpi->cpi_vendor = X86_VENDOR_SiS;
6547c478bd9Sstevel@tonic-gate 	else if (strcmp(cpi->cpi_vendorstr, "Geode by NSC") == 0)
6557c478bd9Sstevel@tonic-gate 		cpi->cpi_vendor = X86_VENDOR_NSC;
6567c478bd9Sstevel@tonic-gate 	else
6577c478bd9Sstevel@tonic-gate 		cpi->cpi_vendor = X86_VENDOR_IntelClone;
6587c478bd9Sstevel@tonic-gate 
6597c478bd9Sstevel@tonic-gate 	x86_vendor = cpi->cpi_vendor; /* for compatibility */
6607c478bd9Sstevel@tonic-gate 
6617c478bd9Sstevel@tonic-gate 	/*
6627c478bd9Sstevel@tonic-gate 	 * Limit the range in case of weird hardware
6637c478bd9Sstevel@tonic-gate 	 */
6647c478bd9Sstevel@tonic-gate 	if (cpi->cpi_maxeax > CPI_MAXEAX_MAX)
6657c478bd9Sstevel@tonic-gate 		cpi->cpi_maxeax = CPI_MAXEAX_MAX;
6667c478bd9Sstevel@tonic-gate 	if (cpi->cpi_maxeax < 1)
6677c478bd9Sstevel@tonic-gate 		goto pass1_done;
6687c478bd9Sstevel@tonic-gate 
6697c478bd9Sstevel@tonic-gate 	cp = &cpi->cpi_std[1];
6708949bcd6Sandrei 	cp->cp_eax = 1;
6718949bcd6Sandrei 	(void) __cpuid_insn(cp);
6727c478bd9Sstevel@tonic-gate 
6737c478bd9Sstevel@tonic-gate 	/*
6747c478bd9Sstevel@tonic-gate 	 * Extract identifying constants for easy access.
6757c478bd9Sstevel@tonic-gate 	 */
6767c478bd9Sstevel@tonic-gate 	cpi->cpi_model = CPI_MODEL(cpi);
6777c478bd9Sstevel@tonic-gate 	cpi->cpi_family = CPI_FAMILY(cpi);
6787c478bd9Sstevel@tonic-gate 
6795ff02082Sdmick 	if (cpi->cpi_family == 0xf)
6807c478bd9Sstevel@tonic-gate 		cpi->cpi_family += CPI_FAMILY_XTD(cpi);
6815ff02082Sdmick 
68268c91426Sdmick 	/*
683875b116eSkchow 	 * Beware: AMD uses "extended model" iff base *FAMILY* == 0xf.
68468c91426Sdmick 	 * Intel, and presumably everyone else, uses model == 0xf, as
68568c91426Sdmick 	 * one would expect (max value means possible overflow).  Sigh.
68668c91426Sdmick 	 */
68768c91426Sdmick 
68868c91426Sdmick 	switch (cpi->cpi_vendor) {
689bf91205bSksadhukh 	case X86_VENDOR_Intel:
690bf91205bSksadhukh 		if (IS_EXTENDED_MODEL_INTEL(cpi))
691bf91205bSksadhukh 			cpi->cpi_model += CPI_MODEL_XTD(cpi) << 4;
692447af253Sksadhukh 		break;
69368c91426Sdmick 	case X86_VENDOR_AMD:
694875b116eSkchow 		if (CPI_FAMILY(cpi) == 0xf)
69568c91426Sdmick 			cpi->cpi_model += CPI_MODEL_XTD(cpi) << 4;
69668c91426Sdmick 		break;
69768c91426Sdmick 	default:
6985ff02082Sdmick 		if (cpi->cpi_model == 0xf)
6997c478bd9Sstevel@tonic-gate 			cpi->cpi_model += CPI_MODEL_XTD(cpi) << 4;
70068c91426Sdmick 		break;
70168c91426Sdmick 	}
7027c478bd9Sstevel@tonic-gate 
7037c478bd9Sstevel@tonic-gate 	cpi->cpi_step = CPI_STEP(cpi);
7047c478bd9Sstevel@tonic-gate 	cpi->cpi_brandid = CPI_BRANDID(cpi);
7057c478bd9Sstevel@tonic-gate 
7067c478bd9Sstevel@tonic-gate 	/*
7077c478bd9Sstevel@tonic-gate 	 * *default* assumptions:
7087c478bd9Sstevel@tonic-gate 	 * - believe %edx feature word
7097c478bd9Sstevel@tonic-gate 	 * - ignore %ecx feature word
7107c478bd9Sstevel@tonic-gate 	 * - 32-bit virtual and physical addressing
7117c478bd9Sstevel@tonic-gate 	 */
7127c478bd9Sstevel@tonic-gate 	mask_edx = 0xffffffff;
7137c478bd9Sstevel@tonic-gate 	mask_ecx = 0;
7147c478bd9Sstevel@tonic-gate 
7157c478bd9Sstevel@tonic-gate 	cpi->cpi_pabits = cpi->cpi_vabits = 32;
7167c478bd9Sstevel@tonic-gate 
7177c478bd9Sstevel@tonic-gate 	switch (cpi->cpi_vendor) {
7187c478bd9Sstevel@tonic-gate 	case X86_VENDOR_Intel:
7197c478bd9Sstevel@tonic-gate 		if (cpi->cpi_family == 5)
7207c478bd9Sstevel@tonic-gate 			x86_type = X86_TYPE_P5;
7215ff02082Sdmick 		else if (IS_LEGACY_P6(cpi)) {
7227c478bd9Sstevel@tonic-gate 			x86_type = X86_TYPE_P6;
7237c478bd9Sstevel@tonic-gate 			pentiumpro_bug4046376 = 1;
7247c478bd9Sstevel@tonic-gate 			pentiumpro_bug4064495 = 1;
7257c478bd9Sstevel@tonic-gate 			/*
7267c478bd9Sstevel@tonic-gate 			 * Clear the SEP bit when it was set erroneously
7277c478bd9Sstevel@tonic-gate 			 */
7287c478bd9Sstevel@tonic-gate 			if (cpi->cpi_model < 3 && cpi->cpi_step < 3)
7297c478bd9Sstevel@tonic-gate 				cp->cp_edx &= ~CPUID_INTC_EDX_SEP;
7305ff02082Sdmick 		} else if (IS_NEW_F6(cpi) || cpi->cpi_family == 0xf) {
7317c478bd9Sstevel@tonic-gate 			x86_type = X86_TYPE_P4;
7327c478bd9Sstevel@tonic-gate 			/*
7337c478bd9Sstevel@tonic-gate 			 * We don't currently depend on any of the %ecx
7347c478bd9Sstevel@tonic-gate 			 * features until Prescott, so we'll only check
7357c478bd9Sstevel@tonic-gate 			 * this from P4 onwards.  We might want to revisit
7367c478bd9Sstevel@tonic-gate 			 * that idea later.
7377c478bd9Sstevel@tonic-gate 			 */
7387c478bd9Sstevel@tonic-gate 			mask_ecx = 0xffffffff;
7397c478bd9Sstevel@tonic-gate 		} else if (cpi->cpi_family > 0xf)
7407c478bd9Sstevel@tonic-gate 			mask_ecx = 0xffffffff;
7417c622d23Sbholler 		/*
7427c622d23Sbholler 		 * We don't support MONITOR/MWAIT if leaf 5 is not available
7437c622d23Sbholler 		 * to obtain the monitor linesize.
7447c622d23Sbholler 		 */
7457c622d23Sbholler 		if (cpi->cpi_maxeax < 5)
7467c622d23Sbholler 			mask_ecx &= ~CPUID_INTC_ECX_MON;
7477c478bd9Sstevel@tonic-gate 		break;
7487c478bd9Sstevel@tonic-gate 	case X86_VENDOR_IntelClone:
7497c478bd9Sstevel@tonic-gate 	default:
7507c478bd9Sstevel@tonic-gate 		break;
7517c478bd9Sstevel@tonic-gate 	case X86_VENDOR_AMD:
7527c478bd9Sstevel@tonic-gate #if defined(OPTERON_ERRATUM_108)
7537c478bd9Sstevel@tonic-gate 		if (cpi->cpi_family == 0xf && cpi->cpi_model == 0xe) {
7547c478bd9Sstevel@tonic-gate 			cp->cp_eax = (0xf0f & cp->cp_eax) | 0xc0;
7557c478bd9Sstevel@tonic-gate 			cpi->cpi_model = 0xc;
7567c478bd9Sstevel@tonic-gate 		} else
7577c478bd9Sstevel@tonic-gate #endif
7587c478bd9Sstevel@tonic-gate 		if (cpi->cpi_family == 5) {
7597c478bd9Sstevel@tonic-gate 			/*
7607c478bd9Sstevel@tonic-gate 			 * AMD K5 and K6
7617c478bd9Sstevel@tonic-gate 			 *
7627c478bd9Sstevel@tonic-gate 			 * These CPUs have an incomplete implementation
7637c478bd9Sstevel@tonic-gate 			 * of MCA/MCE which we mask away.
7647c478bd9Sstevel@tonic-gate 			 */
7658949bcd6Sandrei 			mask_edx &= ~(CPUID_INTC_EDX_MCE | CPUID_INTC_EDX_MCA);
7668949bcd6Sandrei 
7677c478bd9Sstevel@tonic-gate 			/*
7687c478bd9Sstevel@tonic-gate 			 * Model 0 uses the wrong (APIC) bit
7697c478bd9Sstevel@tonic-gate 			 * to indicate PGE.  Fix it here.
7707c478bd9Sstevel@tonic-gate 			 */
7718949bcd6Sandrei 			if (cpi->cpi_model == 0) {
7727c478bd9Sstevel@tonic-gate 				if (cp->cp_edx & 0x200) {
7737c478bd9Sstevel@tonic-gate 					cp->cp_edx &= ~0x200;
7747c478bd9Sstevel@tonic-gate 					cp->cp_edx |= CPUID_INTC_EDX_PGE;
7757c478bd9Sstevel@tonic-gate 				}
7767c478bd9Sstevel@tonic-gate 			}
7778949bcd6Sandrei 
7788949bcd6Sandrei 			/*
7798949bcd6Sandrei 			 * Early models had problems w/ MMX; disable.
7808949bcd6Sandrei 			 */
7818949bcd6Sandrei 			if (cpi->cpi_model < 6)
7828949bcd6Sandrei 				mask_edx &= ~CPUID_INTC_EDX_MMX;
7838949bcd6Sandrei 		}
7848949bcd6Sandrei 
7858949bcd6Sandrei 		/*
7868949bcd6Sandrei 		 * For newer families, SSE3 and CX16, at least, are valid;
7878949bcd6Sandrei 		 * enable all
7888949bcd6Sandrei 		 */
7898949bcd6Sandrei 		if (cpi->cpi_family >= 0xf)
7908949bcd6Sandrei 			mask_ecx = 0xffffffff;
7917c622d23Sbholler 		/*
7927c622d23Sbholler 		 * We don't support MONITOR/MWAIT if leaf 5 is not available
7937c622d23Sbholler 		 * to obtain the monitor linesize.
7947c622d23Sbholler 		 */
7957c622d23Sbholler 		if (cpi->cpi_maxeax < 5)
7967c622d23Sbholler 			mask_ecx &= ~CPUID_INTC_ECX_MON;
7975b8a6efeSbholler 
798843e1988Sjohnlev #if !defined(__xpv)
7995b8a6efeSbholler 		/*
8005b8a6efeSbholler 		 * Do not use MONITOR/MWAIT to halt in the idle loop on any AMD
8015b8a6efeSbholler 		 * processors.  AMD does not intend MWAIT to be used in the cpu
8025b8a6efeSbholler 		 * idle loop on current and future processors.  10h and future
8035b8a6efeSbholler 		 * AMD processors use more power in MWAIT than HLT.
8045b8a6efeSbholler 		 * Pre-family-10h Opterons do not have the MWAIT instruction.
8055b8a6efeSbholler 		 */
8065b8a6efeSbholler 		idle_cpu_prefer_mwait = 0;
807843e1988Sjohnlev #endif
8085b8a6efeSbholler 
8097c478bd9Sstevel@tonic-gate 		break;
8107c478bd9Sstevel@tonic-gate 	case X86_VENDOR_TM:
8117c478bd9Sstevel@tonic-gate 		/*
8127c478bd9Sstevel@tonic-gate 		 * workaround the NT workaround in CMS 4.1
8137c478bd9Sstevel@tonic-gate 		 */
8147c478bd9Sstevel@tonic-gate 		if (cpi->cpi_family == 5 && cpi->cpi_model == 4 &&
8157c478bd9Sstevel@tonic-gate 		    (cpi->cpi_step == 2 || cpi->cpi_step == 3))
8167c478bd9Sstevel@tonic-gate 			cp->cp_edx |= CPUID_INTC_EDX_CX8;
8177c478bd9Sstevel@tonic-gate 		break;
8187c478bd9Sstevel@tonic-gate 	case X86_VENDOR_Centaur:
8197c478bd9Sstevel@tonic-gate 		/*
8207c478bd9Sstevel@tonic-gate 		 * workaround the NT workarounds again
8217c478bd9Sstevel@tonic-gate 		 */
8227c478bd9Sstevel@tonic-gate 		if (cpi->cpi_family == 6)
8237c478bd9Sstevel@tonic-gate 			cp->cp_edx |= CPUID_INTC_EDX_CX8;
8247c478bd9Sstevel@tonic-gate 		break;
8257c478bd9Sstevel@tonic-gate 	case X86_VENDOR_Cyrix:
8267c478bd9Sstevel@tonic-gate 		/*
8277c478bd9Sstevel@tonic-gate 		 * We rely heavily on the probing in locore
8287c478bd9Sstevel@tonic-gate 		 * to actually figure out what parts, if any,
8297c478bd9Sstevel@tonic-gate 		 * of the Cyrix cpuid instruction to believe.
8307c478bd9Sstevel@tonic-gate 		 */
8317c478bd9Sstevel@tonic-gate 		switch (x86_type) {
8327c478bd9Sstevel@tonic-gate 		case X86_TYPE_CYRIX_486:
8337c478bd9Sstevel@tonic-gate 			mask_edx = 0;
8347c478bd9Sstevel@tonic-gate 			break;
8357c478bd9Sstevel@tonic-gate 		case X86_TYPE_CYRIX_6x86:
8367c478bd9Sstevel@tonic-gate 			mask_edx = 0;
8377c478bd9Sstevel@tonic-gate 			break;
8387c478bd9Sstevel@tonic-gate 		case X86_TYPE_CYRIX_6x86L:
8397c478bd9Sstevel@tonic-gate 			mask_edx =
8407c478bd9Sstevel@tonic-gate 			    CPUID_INTC_EDX_DE |
8417c478bd9Sstevel@tonic-gate 			    CPUID_INTC_EDX_CX8;
8427c478bd9Sstevel@tonic-gate 			break;
8437c478bd9Sstevel@tonic-gate 		case X86_TYPE_CYRIX_6x86MX:
8447c478bd9Sstevel@tonic-gate 			mask_edx =
8457c478bd9Sstevel@tonic-gate 			    CPUID_INTC_EDX_DE |
8467c478bd9Sstevel@tonic-gate 			    CPUID_INTC_EDX_MSR |
8477c478bd9Sstevel@tonic-gate 			    CPUID_INTC_EDX_CX8 |
8487c478bd9Sstevel@tonic-gate 			    CPUID_INTC_EDX_PGE |
8497c478bd9Sstevel@tonic-gate 			    CPUID_INTC_EDX_CMOV |
8507c478bd9Sstevel@tonic-gate 			    CPUID_INTC_EDX_MMX;
8517c478bd9Sstevel@tonic-gate 			break;
8527c478bd9Sstevel@tonic-gate 		case X86_TYPE_CYRIX_GXm:
8537c478bd9Sstevel@tonic-gate 			mask_edx =
8547c478bd9Sstevel@tonic-gate 			    CPUID_INTC_EDX_MSR |
8557c478bd9Sstevel@tonic-gate 			    CPUID_INTC_EDX_CX8 |
8567c478bd9Sstevel@tonic-gate 			    CPUID_INTC_EDX_CMOV |
8577c478bd9Sstevel@tonic-gate 			    CPUID_INTC_EDX_MMX;
8587c478bd9Sstevel@tonic-gate 			break;
8597c478bd9Sstevel@tonic-gate 		case X86_TYPE_CYRIX_MediaGX:
8607c478bd9Sstevel@tonic-gate 			break;
8617c478bd9Sstevel@tonic-gate 		case X86_TYPE_CYRIX_MII:
8627c478bd9Sstevel@tonic-gate 		case X86_TYPE_VIA_CYRIX_III:
8637c478bd9Sstevel@tonic-gate 			mask_edx =
8647c478bd9Sstevel@tonic-gate 			    CPUID_INTC_EDX_DE |
8657c478bd9Sstevel@tonic-gate 			    CPUID_INTC_EDX_TSC |
8667c478bd9Sstevel@tonic-gate 			    CPUID_INTC_EDX_MSR |
8677c478bd9Sstevel@tonic-gate 			    CPUID_INTC_EDX_CX8 |
8687c478bd9Sstevel@tonic-gate 			    CPUID_INTC_EDX_PGE |
8697c478bd9Sstevel@tonic-gate 			    CPUID_INTC_EDX_CMOV |
8707c478bd9Sstevel@tonic-gate 			    CPUID_INTC_EDX_MMX;
8717c478bd9Sstevel@tonic-gate 			break;
8727c478bd9Sstevel@tonic-gate 		default:
8737c478bd9Sstevel@tonic-gate 			break;
8747c478bd9Sstevel@tonic-gate 		}
8757c478bd9Sstevel@tonic-gate 		break;
8767c478bd9Sstevel@tonic-gate 	}
8777c478bd9Sstevel@tonic-gate 
878843e1988Sjohnlev #if defined(__xpv)
879843e1988Sjohnlev 	/*
880843e1988Sjohnlev 	 * Do not support MONITOR/MWAIT under a hypervisor
881843e1988Sjohnlev 	 */
882843e1988Sjohnlev 	mask_ecx &= ~CPUID_INTC_ECX_MON;
883843e1988Sjohnlev #endif	/* __xpv */
884843e1988Sjohnlev 
8857c478bd9Sstevel@tonic-gate 	/*
8867c478bd9Sstevel@tonic-gate 	 * Now we've figured out the masks that determine
8877c478bd9Sstevel@tonic-gate 	 * which bits we choose to believe, apply the masks
8887c478bd9Sstevel@tonic-gate 	 * to the feature words, then map the kernel's view
8897c478bd9Sstevel@tonic-gate 	 * of these feature words into its feature word.
8907c478bd9Sstevel@tonic-gate 	 */
8917c478bd9Sstevel@tonic-gate 	cp->cp_edx &= mask_edx;
8927c478bd9Sstevel@tonic-gate 	cp->cp_ecx &= mask_ecx;
8937c478bd9Sstevel@tonic-gate 
8947c478bd9Sstevel@tonic-gate 	/*
895ae115bc7Smrj 	 * apply any platform restrictions (we don't call this
896ae115bc7Smrj 	 * immediately after __cpuid_insn here, because we need the
897ae115bc7Smrj 	 * workarounds applied above first)
8987c478bd9Sstevel@tonic-gate 	 */
899ae115bc7Smrj 	platform_cpuid_mangle(cpi->cpi_vendor, 1, cp);
9007c478bd9Sstevel@tonic-gate 
901ae115bc7Smrj 	/*
902ae115bc7Smrj 	 * fold in overrides from the "eeprom" mechanism
903ae115bc7Smrj 	 */
9047c478bd9Sstevel@tonic-gate 	cp->cp_edx |= cpuid_feature_edx_include;
9057c478bd9Sstevel@tonic-gate 	cp->cp_edx &= ~cpuid_feature_edx_exclude;
9067c478bd9Sstevel@tonic-gate 
9077c478bd9Sstevel@tonic-gate 	cp->cp_ecx |= cpuid_feature_ecx_include;
9087c478bd9Sstevel@tonic-gate 	cp->cp_ecx &= ~cpuid_feature_ecx_exclude;
9097c478bd9Sstevel@tonic-gate 
9107c478bd9Sstevel@tonic-gate 	if (cp->cp_edx & CPUID_INTC_EDX_PSE)
9117c478bd9Sstevel@tonic-gate 		feature |= X86_LARGEPAGE;
9127c478bd9Sstevel@tonic-gate 	if (cp->cp_edx & CPUID_INTC_EDX_TSC)
9137c478bd9Sstevel@tonic-gate 		feature |= X86_TSC;
9147c478bd9Sstevel@tonic-gate 	if (cp->cp_edx & CPUID_INTC_EDX_MSR)
9157c478bd9Sstevel@tonic-gate 		feature |= X86_MSR;
9167c478bd9Sstevel@tonic-gate 	if (cp->cp_edx & CPUID_INTC_EDX_MTRR)
9177c478bd9Sstevel@tonic-gate 		feature |= X86_MTRR;
9187c478bd9Sstevel@tonic-gate 	if (cp->cp_edx & CPUID_INTC_EDX_PGE)
9197c478bd9Sstevel@tonic-gate 		feature |= X86_PGE;
9207c478bd9Sstevel@tonic-gate 	if (cp->cp_edx & CPUID_INTC_EDX_CMOV)
9217c478bd9Sstevel@tonic-gate 		feature |= X86_CMOV;
9227c478bd9Sstevel@tonic-gate 	if (cp->cp_edx & CPUID_INTC_EDX_MMX)
9237c478bd9Sstevel@tonic-gate 		feature |= X86_MMX;
9247c478bd9Sstevel@tonic-gate 	if ((cp->cp_edx & CPUID_INTC_EDX_MCE) != 0 &&
9257c478bd9Sstevel@tonic-gate 	    (cp->cp_edx & CPUID_INTC_EDX_MCA) != 0)
9267c478bd9Sstevel@tonic-gate 		feature |= X86_MCA;
9277c478bd9Sstevel@tonic-gate 	if (cp->cp_edx & CPUID_INTC_EDX_PAE)
9287c478bd9Sstevel@tonic-gate 		feature |= X86_PAE;
9297c478bd9Sstevel@tonic-gate 	if (cp->cp_edx & CPUID_INTC_EDX_CX8)
9307c478bd9Sstevel@tonic-gate 		feature |= X86_CX8;
9317c478bd9Sstevel@tonic-gate 	if (cp->cp_ecx & CPUID_INTC_ECX_CX16)
9327c478bd9Sstevel@tonic-gate 		feature |= X86_CX16;
9337c478bd9Sstevel@tonic-gate 	if (cp->cp_edx & CPUID_INTC_EDX_PAT)
9347c478bd9Sstevel@tonic-gate 		feature |= X86_PAT;
9357c478bd9Sstevel@tonic-gate 	if (cp->cp_edx & CPUID_INTC_EDX_SEP)
9367c478bd9Sstevel@tonic-gate 		feature |= X86_SEP;
9377c478bd9Sstevel@tonic-gate 	if (cp->cp_edx & CPUID_INTC_EDX_FXSR) {
9387c478bd9Sstevel@tonic-gate 		/*
9397c478bd9Sstevel@tonic-gate 		 * In our implementation, fxsave/fxrstor
9407c478bd9Sstevel@tonic-gate 		 * are prerequisites before we'll even
9417c478bd9Sstevel@tonic-gate 		 * try and do SSE things.
9427c478bd9Sstevel@tonic-gate 		 */
9437c478bd9Sstevel@tonic-gate 		if (cp->cp_edx & CPUID_INTC_EDX_SSE)
9447c478bd9Sstevel@tonic-gate 			feature |= X86_SSE;
9457c478bd9Sstevel@tonic-gate 		if (cp->cp_edx & CPUID_INTC_EDX_SSE2)
9467c478bd9Sstevel@tonic-gate 			feature |= X86_SSE2;
9477c478bd9Sstevel@tonic-gate 		if (cp->cp_ecx & CPUID_INTC_ECX_SSE3)
9487c478bd9Sstevel@tonic-gate 			feature |= X86_SSE3;
949d0f8ff6eSkk208521 		if (cpi->cpi_vendor == X86_VENDOR_Intel) {
950d0f8ff6eSkk208521 			if (cp->cp_ecx & CPUID_INTC_ECX_SSSE3)
951d0f8ff6eSkk208521 				feature |= X86_SSSE3;
952d0f8ff6eSkk208521 			if (cp->cp_ecx & CPUID_INTC_ECX_SSE4_1)
953d0f8ff6eSkk208521 				feature |= X86_SSE4_1;
954d0f8ff6eSkk208521 			if (cp->cp_ecx & CPUID_INTC_ECX_SSE4_2)
955d0f8ff6eSkk208521 				feature |= X86_SSE4_2;
956d0f8ff6eSkk208521 		}
9577c478bd9Sstevel@tonic-gate 	}
9587c478bd9Sstevel@tonic-gate 	if (cp->cp_edx & CPUID_INTC_EDX_DE)
959ae115bc7Smrj 		feature |= X86_DE;
960f98fbcecSbholler 	if (cp->cp_ecx & CPUID_INTC_ECX_MON) {
961f98fbcecSbholler 		cpi->cpi_mwait.support |= MWAIT_SUPPORT;
962f98fbcecSbholler 		feature |= X86_MWAIT;
963f98fbcecSbholler 	}
9647c478bd9Sstevel@tonic-gate 
9657c478bd9Sstevel@tonic-gate 	if (feature & X86_PAE)
9667c478bd9Sstevel@tonic-gate 		cpi->cpi_pabits = 36;
9677c478bd9Sstevel@tonic-gate 
9687c478bd9Sstevel@tonic-gate 	/*
9697c478bd9Sstevel@tonic-gate 	 * Hyperthreading configuration is slightly tricky on Intel
9707c478bd9Sstevel@tonic-gate 	 * and pure clones, and even trickier on AMD.
9717c478bd9Sstevel@tonic-gate 	 *
9727c478bd9Sstevel@tonic-gate 	 * (AMD chose to set the HTT bit on their CMP processors,
9737c478bd9Sstevel@tonic-gate 	 * even though they're not actually hyperthreaded.  Thus it
9747c478bd9Sstevel@tonic-gate 	 * takes a bit more work to figure out what's really going
975ae115bc7Smrj 	 * on ... see the handling of the CMP_LGCY bit below)
9767c478bd9Sstevel@tonic-gate 	 */
9777c478bd9Sstevel@tonic-gate 	if (cp->cp_edx & CPUID_INTC_EDX_HTT) {
9787c478bd9Sstevel@tonic-gate 		cpi->cpi_ncpu_per_chip = CPI_CPU_COUNT(cpi);
9797c478bd9Sstevel@tonic-gate 		if (cpi->cpi_ncpu_per_chip > 1)
9807c478bd9Sstevel@tonic-gate 			feature |= X86_HTT;
9818949bcd6Sandrei 	} else {
9828949bcd6Sandrei 		cpi->cpi_ncpu_per_chip = 1;
9837c478bd9Sstevel@tonic-gate 	}
9847c478bd9Sstevel@tonic-gate 
9857c478bd9Sstevel@tonic-gate 	/*
9867c478bd9Sstevel@tonic-gate 	 * Work on the "extended" feature information, doing
9877c478bd9Sstevel@tonic-gate 	 * some basic initialization for cpuid_pass2()
9887c478bd9Sstevel@tonic-gate 	 */
9897c478bd9Sstevel@tonic-gate 	xcpuid = 0;
9907c478bd9Sstevel@tonic-gate 	switch (cpi->cpi_vendor) {
9917c478bd9Sstevel@tonic-gate 	case X86_VENDOR_Intel:
9925ff02082Sdmick 		if (IS_NEW_F6(cpi) || cpi->cpi_family >= 0xf)
9937c478bd9Sstevel@tonic-gate 			xcpuid++;
9947c478bd9Sstevel@tonic-gate 		break;
9957c478bd9Sstevel@tonic-gate 	case X86_VENDOR_AMD:
9967c478bd9Sstevel@tonic-gate 		if (cpi->cpi_family > 5 ||
9977c478bd9Sstevel@tonic-gate 		    (cpi->cpi_family == 5 && cpi->cpi_model >= 1))
9987c478bd9Sstevel@tonic-gate 			xcpuid++;
9997c478bd9Sstevel@tonic-gate 		break;
10007c478bd9Sstevel@tonic-gate 	case X86_VENDOR_Cyrix:
10017c478bd9Sstevel@tonic-gate 		/*
10027c478bd9Sstevel@tonic-gate 		 * Only these Cyrix CPUs are -known- to support
10037c478bd9Sstevel@tonic-gate 		 * extended cpuid operations.
10047c478bd9Sstevel@tonic-gate 		 */
10057c478bd9Sstevel@tonic-gate 		if (x86_type == X86_TYPE_VIA_CYRIX_III ||
10067c478bd9Sstevel@tonic-gate 		    x86_type == X86_TYPE_CYRIX_GXm)
10077c478bd9Sstevel@tonic-gate 			xcpuid++;
10087c478bd9Sstevel@tonic-gate 		break;
10097c478bd9Sstevel@tonic-gate 	case X86_VENDOR_Centaur:
10107c478bd9Sstevel@tonic-gate 	case X86_VENDOR_TM:
10117c478bd9Sstevel@tonic-gate 	default:
10127c478bd9Sstevel@tonic-gate 		xcpuid++;
10137c478bd9Sstevel@tonic-gate 		break;
10147c478bd9Sstevel@tonic-gate 	}
10157c478bd9Sstevel@tonic-gate 
10167c478bd9Sstevel@tonic-gate 	if (xcpuid) {
10177c478bd9Sstevel@tonic-gate 		cp = &cpi->cpi_extd[0];
10188949bcd6Sandrei 		cp->cp_eax = 0x80000000;
10198949bcd6Sandrei 		cpi->cpi_xmaxeax = __cpuid_insn(cp);
10207c478bd9Sstevel@tonic-gate 	}
10217c478bd9Sstevel@tonic-gate 
10227c478bd9Sstevel@tonic-gate 	if (cpi->cpi_xmaxeax & 0x80000000) {
10237c478bd9Sstevel@tonic-gate 
10247c478bd9Sstevel@tonic-gate 		if (cpi->cpi_xmaxeax > CPI_XMAXEAX_MAX)
10257c478bd9Sstevel@tonic-gate 			cpi->cpi_xmaxeax = CPI_XMAXEAX_MAX;
10267c478bd9Sstevel@tonic-gate 
10277c478bd9Sstevel@tonic-gate 		switch (cpi->cpi_vendor) {
10287c478bd9Sstevel@tonic-gate 		case X86_VENDOR_Intel:
10297c478bd9Sstevel@tonic-gate 		case X86_VENDOR_AMD:
10307c478bd9Sstevel@tonic-gate 			if (cpi->cpi_xmaxeax < 0x80000001)
10317c478bd9Sstevel@tonic-gate 				break;
10327c478bd9Sstevel@tonic-gate 			cp = &cpi->cpi_extd[1];
10338949bcd6Sandrei 			cp->cp_eax = 0x80000001;
10348949bcd6Sandrei 			(void) __cpuid_insn(cp);
1035ae115bc7Smrj 
10367c478bd9Sstevel@tonic-gate 			if (cpi->cpi_vendor == X86_VENDOR_AMD &&
10377c478bd9Sstevel@tonic-gate 			    cpi->cpi_family == 5 &&
10387c478bd9Sstevel@tonic-gate 			    cpi->cpi_model == 6 &&
10397c478bd9Sstevel@tonic-gate 			    cpi->cpi_step == 6) {
10407c478bd9Sstevel@tonic-gate 				/*
10417c478bd9Sstevel@tonic-gate 				 * K6 model 6 uses bit 10 to indicate SYSC
10427c478bd9Sstevel@tonic-gate 				 * Later models use bit 11. Fix it here.
10437c478bd9Sstevel@tonic-gate 				 */
10447c478bd9Sstevel@tonic-gate 				if (cp->cp_edx & 0x400) {
10457c478bd9Sstevel@tonic-gate 					cp->cp_edx &= ~0x400;
10467c478bd9Sstevel@tonic-gate 					cp->cp_edx |= CPUID_AMD_EDX_SYSC;
10477c478bd9Sstevel@tonic-gate 				}
10487c478bd9Sstevel@tonic-gate 			}
10497c478bd9Sstevel@tonic-gate 
1050ae115bc7Smrj 			platform_cpuid_mangle(cpi->cpi_vendor, 0x80000001, cp);
1051ae115bc7Smrj 
10527c478bd9Sstevel@tonic-gate 			/*
10537c478bd9Sstevel@tonic-gate 			 * Compute the additions to the kernel's feature word.
10547c478bd9Sstevel@tonic-gate 			 */
10557c478bd9Sstevel@tonic-gate 			if (cp->cp_edx & CPUID_AMD_EDX_NX)
10567c478bd9Sstevel@tonic-gate 				feature |= X86_NX;
10577c478bd9Sstevel@tonic-gate 
105802bc52beSkchow #if defined(__amd64)
105902bc52beSkchow 			/* 1 GB large page - enable only for 64 bit kernel */
106002bc52beSkchow 			if (cp->cp_edx & CPUID_AMD_EDX_1GPG)
106102bc52beSkchow 				feature |= X86_1GPG;
106202bc52beSkchow #endif
106302bc52beSkchow 
1064f8801251Skk208521 			if ((cpi->cpi_vendor == X86_VENDOR_AMD) &&
1065f8801251Skk208521 			    (cpi->cpi_std[1].cp_edx & CPUID_INTC_EDX_FXSR) &&
1066f8801251Skk208521 			    (cp->cp_ecx & CPUID_AMD_ECX_SSE4A))
1067f8801251Skk208521 				feature |= X86_SSE4A;
1068f8801251Skk208521 
10697c478bd9Sstevel@tonic-gate 			/*
1070ae115bc7Smrj 			 * If both the HTT and CMP_LGCY bits are set,
10718949bcd6Sandrei 			 * then we're not actually HyperThreaded.  Read
10728949bcd6Sandrei 			 * "AMD CPUID Specification" for more details.
10737c478bd9Sstevel@tonic-gate 			 */
10747c478bd9Sstevel@tonic-gate 			if (cpi->cpi_vendor == X86_VENDOR_AMD &&
10758949bcd6Sandrei 			    (feature & X86_HTT) &&
1076ae115bc7Smrj 			    (cp->cp_ecx & CPUID_AMD_ECX_CMP_LGCY)) {
10777c478bd9Sstevel@tonic-gate 				feature &= ~X86_HTT;
10788949bcd6Sandrei 				feature |= X86_CMP;
10798949bcd6Sandrei 			}
1080ae115bc7Smrj #if defined(__amd64)
10817c478bd9Sstevel@tonic-gate 			/*
10827c478bd9Sstevel@tonic-gate 			 * It's really tricky to support syscall/sysret in
10837c478bd9Sstevel@tonic-gate 			 * the i386 kernel; we rely on sysenter/sysexit
10847c478bd9Sstevel@tonic-gate 			 * instead.  In the amd64 kernel, things are -way-
10857c478bd9Sstevel@tonic-gate 			 * better.
10867c478bd9Sstevel@tonic-gate 			 */
10877c478bd9Sstevel@tonic-gate 			if (cp->cp_edx & CPUID_AMD_EDX_SYSC)
10887c478bd9Sstevel@tonic-gate 				feature |= X86_ASYSC;
10897c478bd9Sstevel@tonic-gate 
10907c478bd9Sstevel@tonic-gate 			/*
10917c478bd9Sstevel@tonic-gate 			 * While we're thinking about system calls, note
10927c478bd9Sstevel@tonic-gate 			 * that AMD processors don't support sysenter
10937c478bd9Sstevel@tonic-gate 			 * in long mode at all, so don't try to program them.
10947c478bd9Sstevel@tonic-gate 			 */
10957c478bd9Sstevel@tonic-gate 			if (x86_vendor == X86_VENDOR_AMD)
10967c478bd9Sstevel@tonic-gate 				feature &= ~X86_SEP;
10977c478bd9Sstevel@tonic-gate #endif
1098d36ea5d8Ssudheer 			if (cp->cp_edx & CPUID_AMD_EDX_TSCP)
1099ae115bc7Smrj 				feature |= X86_TSCP;
11007c478bd9Sstevel@tonic-gate 			break;
11017c478bd9Sstevel@tonic-gate 		default:
11027c478bd9Sstevel@tonic-gate 			break;
11037c478bd9Sstevel@tonic-gate 		}
11047c478bd9Sstevel@tonic-gate 
11058949bcd6Sandrei 		/*
11068949bcd6Sandrei 		 * Get CPUID data about processor cores and hyperthreads.
11078949bcd6Sandrei 		 */
11087c478bd9Sstevel@tonic-gate 		switch (cpi->cpi_vendor) {
11097c478bd9Sstevel@tonic-gate 		case X86_VENDOR_Intel:
11108949bcd6Sandrei 			if (cpi->cpi_maxeax >= 4) {
11118949bcd6Sandrei 				cp = &cpi->cpi_std[4];
11128949bcd6Sandrei 				cp->cp_eax = 4;
11138949bcd6Sandrei 				cp->cp_ecx = 0;
11148949bcd6Sandrei 				(void) __cpuid_insn(cp);
1115ae115bc7Smrj 				platform_cpuid_mangle(cpi->cpi_vendor, 4, cp);
11168949bcd6Sandrei 			}
11178949bcd6Sandrei 			/*FALLTHROUGH*/
11187c478bd9Sstevel@tonic-gate 		case X86_VENDOR_AMD:
11197c478bd9Sstevel@tonic-gate 			if (cpi->cpi_xmaxeax < 0x80000008)
11207c478bd9Sstevel@tonic-gate 				break;
11217c478bd9Sstevel@tonic-gate 			cp = &cpi->cpi_extd[8];
11228949bcd6Sandrei 			cp->cp_eax = 0x80000008;
11238949bcd6Sandrei 			(void) __cpuid_insn(cp);
1124ae115bc7Smrj 			platform_cpuid_mangle(cpi->cpi_vendor, 0x80000008, cp);
1125ae115bc7Smrj 
11267c478bd9Sstevel@tonic-gate 			/*
11277c478bd9Sstevel@tonic-gate 			 * Virtual and physical address limits from
11287c478bd9Sstevel@tonic-gate 			 * cpuid override previously guessed values.
11297c478bd9Sstevel@tonic-gate 			 */
11307c478bd9Sstevel@tonic-gate 			cpi->cpi_pabits = BITX(cp->cp_eax, 7, 0);
11317c478bd9Sstevel@tonic-gate 			cpi->cpi_vabits = BITX(cp->cp_eax, 15, 8);
11327c478bd9Sstevel@tonic-gate 			break;
11337c478bd9Sstevel@tonic-gate 		default:
11347c478bd9Sstevel@tonic-gate 			break;
11357c478bd9Sstevel@tonic-gate 		}
11368949bcd6Sandrei 
1137d129bde2Sesaxe 		/*
1138d129bde2Sesaxe 		 * Derive the number of cores per chip
1139d129bde2Sesaxe 		 */
11408949bcd6Sandrei 		switch (cpi->cpi_vendor) {
11418949bcd6Sandrei 		case X86_VENDOR_Intel:
11428949bcd6Sandrei 			if (cpi->cpi_maxeax < 4) {
11438949bcd6Sandrei 				cpi->cpi_ncore_per_chip = 1;
11448949bcd6Sandrei 				break;
11458949bcd6Sandrei 			} else {
11468949bcd6Sandrei 				cpi->cpi_ncore_per_chip =
11478949bcd6Sandrei 				    BITX((cpi)->cpi_std[4].cp_eax, 31, 26) + 1;
11488949bcd6Sandrei 			}
11498949bcd6Sandrei 			break;
11508949bcd6Sandrei 		case X86_VENDOR_AMD:
11518949bcd6Sandrei 			if (cpi->cpi_xmaxeax < 0x80000008) {
11528949bcd6Sandrei 				cpi->cpi_ncore_per_chip = 1;
11538949bcd6Sandrei 				break;
11548949bcd6Sandrei 			} else {
115510569901Sgavinm 				/*
115610569901Sgavinm 				 * On family 0xf cpuid fn 2 ECX[7:0] "NC" is
115710569901Sgavinm 				 * 1 less than the number of physical cores on
115810569901Sgavinm 				 * the chip.  In family 0x10 this value can
115910569901Sgavinm 				 * be affected by "downcoring" - it reflects
116010569901Sgavinm 				 * 1 less than the number of cores actually
116110569901Sgavinm 				 * enabled on this node.
116210569901Sgavinm 				 */
11638949bcd6Sandrei 				cpi->cpi_ncore_per_chip =
11648949bcd6Sandrei 				    BITX((cpi)->cpi_extd[8].cp_ecx, 7, 0) + 1;
11658949bcd6Sandrei 			}
11668949bcd6Sandrei 			break;
11678949bcd6Sandrei 		default:
11688949bcd6Sandrei 			cpi->cpi_ncore_per_chip = 1;
11698949bcd6Sandrei 			break;
11707c478bd9Sstevel@tonic-gate 		}
1171fa2e767eSgavinm 	} else {
1172fa2e767eSgavinm 		cpi->cpi_ncore_per_chip = 1;
11738949bcd6Sandrei 	}
11748949bcd6Sandrei 
11758949bcd6Sandrei 	/*
11768949bcd6Sandrei 	 * If more than one core, then this processor is CMP.
11778949bcd6Sandrei 	 */
11788949bcd6Sandrei 	if (cpi->cpi_ncore_per_chip > 1)
11798949bcd6Sandrei 		feature |= X86_CMP;
1180ae115bc7Smrj 
11818949bcd6Sandrei 	/*
11828949bcd6Sandrei 	 * If the number of cores is the same as the number
11838949bcd6Sandrei 	 * of CPUs, then we cannot have HyperThreading.
11848949bcd6Sandrei 	 */
11858949bcd6Sandrei 	if (cpi->cpi_ncpu_per_chip == cpi->cpi_ncore_per_chip)
11868949bcd6Sandrei 		feature &= ~X86_HTT;
11878949bcd6Sandrei 
11887c478bd9Sstevel@tonic-gate 	if ((feature & (X86_HTT | X86_CMP)) == 0) {
11898949bcd6Sandrei 		/*
11908949bcd6Sandrei 		 * Single-core single-threaded processors.
11918949bcd6Sandrei 		 */
11927c478bd9Sstevel@tonic-gate 		cpi->cpi_chipid = -1;
11937c478bd9Sstevel@tonic-gate 		cpi->cpi_clogid = 0;
11948949bcd6Sandrei 		cpi->cpi_coreid = cpu->cpu_id;
119510569901Sgavinm 		cpi->cpi_pkgcoreid = 0;
11967c478bd9Sstevel@tonic-gate 	} else if (cpi->cpi_ncpu_per_chip > 1) {
11978949bcd6Sandrei 		uint_t i;
11988949bcd6Sandrei 		uint_t chipid_shift = 0;
11998949bcd6Sandrei 		uint_t coreid_shift = 0;
12008949bcd6Sandrei 		uint_t apic_id = CPI_APIC_ID(cpi);
12017c478bd9Sstevel@tonic-gate 
12028949bcd6Sandrei 		for (i = 1; i < cpi->cpi_ncpu_per_chip; i <<= 1)
12038949bcd6Sandrei 			chipid_shift++;
12048949bcd6Sandrei 		cpi->cpi_chipid = apic_id >> chipid_shift;
12058949bcd6Sandrei 		cpi->cpi_clogid = apic_id & ((1 << chipid_shift) - 1);
12068949bcd6Sandrei 
12078949bcd6Sandrei 		if (cpi->cpi_vendor == X86_VENDOR_Intel) {
12088949bcd6Sandrei 			if (feature & X86_CMP) {
12098949bcd6Sandrei 				/*
12108949bcd6Sandrei 				 * Multi-core (and possibly multi-threaded)
12118949bcd6Sandrei 				 * processors.
12128949bcd6Sandrei 				 */
12138949bcd6Sandrei 				uint_t ncpu_per_core;
12148949bcd6Sandrei 				if (cpi->cpi_ncore_per_chip == 1)
12158949bcd6Sandrei 					ncpu_per_core = cpi->cpi_ncpu_per_chip;
12168949bcd6Sandrei 				else if (cpi->cpi_ncore_per_chip > 1)
12178949bcd6Sandrei 					ncpu_per_core = cpi->cpi_ncpu_per_chip /
12188949bcd6Sandrei 					    cpi->cpi_ncore_per_chip;
12198949bcd6Sandrei 				/*
12208949bcd6Sandrei 				 * 8bit APIC IDs on dual core Pentiums
12218949bcd6Sandrei 				 * look like this:
12228949bcd6Sandrei 				 *
12238949bcd6Sandrei 				 * +-----------------------+------+------+
12248949bcd6Sandrei 				 * | Physical Package ID   |  MC  |  HT  |
12258949bcd6Sandrei 				 * +-----------------------+------+------+
12268949bcd6Sandrei 				 * <------- chipid -------->
12278949bcd6Sandrei 				 * <------- coreid --------------->
12288949bcd6Sandrei 				 *			   <--- clogid -->
122910569901Sgavinm 				 *			   <------>
123010569901Sgavinm 				 *			   pkgcoreid
12318949bcd6Sandrei 				 *
12328949bcd6Sandrei 				 * Where the number of bits necessary to
12338949bcd6Sandrei 				 * represent MC and HT fields together equals
12348949bcd6Sandrei 				 * to the minimum number of bits necessary to
12358949bcd6Sandrei 				 * store the value of cpi->cpi_ncpu_per_chip.
12368949bcd6Sandrei 				 * Of those bits, the MC part uses the number
12378949bcd6Sandrei 				 * of bits necessary to store the value of
12388949bcd6Sandrei 				 * cpi->cpi_ncore_per_chip.
12398949bcd6Sandrei 				 */
12408949bcd6Sandrei 				for (i = 1; i < ncpu_per_core; i <<= 1)
12418949bcd6Sandrei 					coreid_shift++;
12423090b9a9Sandrei 				cpi->cpi_coreid = apic_id >> coreid_shift;
124310569901Sgavinm 				cpi->cpi_pkgcoreid = cpi->cpi_clogid >>
124410569901Sgavinm 				    coreid_shift;
12458949bcd6Sandrei 			} else if (feature & X86_HTT) {
12468949bcd6Sandrei 				/*
12478949bcd6Sandrei 				 * Single-core multi-threaded processors.
12488949bcd6Sandrei 				 */
12498949bcd6Sandrei 				cpi->cpi_coreid = cpi->cpi_chipid;
125010569901Sgavinm 				cpi->cpi_pkgcoreid = 0;
12518949bcd6Sandrei 			}
12528949bcd6Sandrei 		} else if (cpi->cpi_vendor == X86_VENDOR_AMD) {
12538949bcd6Sandrei 			/*
125410569901Sgavinm 			 * AMD CMP chips currently have a single thread per
125510569901Sgavinm 			 * core, with 2 cores on family 0xf and 2, 3 or 4
125610569901Sgavinm 			 * cores on family 0x10.
125710569901Sgavinm 			 *
125810569901Sgavinm 			 * Since no two cpus share a core we must assign a
125910569901Sgavinm 			 * distinct coreid per cpu, and we do this by using
126010569901Sgavinm 			 * the cpu_id.  This scheme does not, however,
126110569901Sgavinm 			 * guarantee that sibling cores of a chip will have
126210569901Sgavinm 			 * sequential coreids starting at a multiple of the
126310569901Sgavinm 			 * number of cores per chip - that is usually the
126410569901Sgavinm 			 * case, but if the ACPI MADT table is presented
126510569901Sgavinm 			 * in a different order then we need to perform a
126610569901Sgavinm 			 * few more gymnastics for the pkgcoreid.
126710569901Sgavinm 			 *
126810569901Sgavinm 			 * In family 0xf CMPs there are 2 cores on all nodes
126910569901Sgavinm 			 * present - no mixing of single and dual core parts.
127010569901Sgavinm 			 *
127110569901Sgavinm 			 * In family 0x10 CMPs cpuid fn 2 ECX[15:12]
127210569901Sgavinm 			 * "ApicIdCoreIdSize[3:0]" tells us how
127310569901Sgavinm 			 * many least-significant bits in the ApicId
127410569901Sgavinm 			 * are used to represent the core number
127510569901Sgavinm 			 * within the node.  Cores are always
127610569901Sgavinm 			 * numbered sequentially from 0 regardless
127710569901Sgavinm 			 * of how many or which are disabled, and
127810569901Sgavinm 			 * there seems to be no way to discover the
127910569901Sgavinm 			 * real core id when some are disabled.
12808949bcd6Sandrei 			 */
12818949bcd6Sandrei 			cpi->cpi_coreid = cpu->cpu_id;
128210569901Sgavinm 
128310569901Sgavinm 			if (cpi->cpi_family == 0x10 &&
128410569901Sgavinm 			    cpi->cpi_xmaxeax >= 0x80000008) {
128510569901Sgavinm 				int coreidsz =
128610569901Sgavinm 				    BITX((cpi)->cpi_extd[8].cp_ecx, 15, 12);
128710569901Sgavinm 
128810569901Sgavinm 				cpi->cpi_pkgcoreid =
128910569901Sgavinm 				    apic_id & ((1 << coreidsz) - 1);
129010569901Sgavinm 			} else {
129110569901Sgavinm 				cpi->cpi_pkgcoreid = cpi->cpi_clogid;
129210569901Sgavinm 			}
12938949bcd6Sandrei 		} else {
12948949bcd6Sandrei 			/*
12958949bcd6Sandrei 			 * All other processors are currently
12968949bcd6Sandrei 			 * assumed to have single cores.
12978949bcd6Sandrei 			 */
12988949bcd6Sandrei 			cpi->cpi_coreid = cpi->cpi_chipid;
129910569901Sgavinm 			cpi->cpi_pkgcoreid = 0;
13008949bcd6Sandrei 		}
13017c478bd9Sstevel@tonic-gate 	}
13027c478bd9Sstevel@tonic-gate 
1303*b6917abeSmishra 	cpi->cpi_apicid = CPI_APIC_ID(cpi);
1304*b6917abeSmishra 
13058a40a695Sgavinm 	/*
13068a40a695Sgavinm 	 * Synthesize chip "revision" and socket type
13078a40a695Sgavinm 	 */
13088a40a695Sgavinm 	synth_info(cpi);
13098a40a695Sgavinm 
13107c478bd9Sstevel@tonic-gate pass1_done:
1311551bc2a6Smrj #if !defined(__xpv)
1312551bc2a6Smrj 	check_for_hvm();
1313551bc2a6Smrj #endif
13147c478bd9Sstevel@tonic-gate 	cpi->cpi_pass = 1;
13157c478bd9Sstevel@tonic-gate 	return (feature);
13167c478bd9Sstevel@tonic-gate }
13177c478bd9Sstevel@tonic-gate 
13187c478bd9Sstevel@tonic-gate /*
13197c478bd9Sstevel@tonic-gate  * Make copies of the cpuid table entries we depend on, in
13207c478bd9Sstevel@tonic-gate  * part for ease of parsing now, in part so that we have only
13217c478bd9Sstevel@tonic-gate  * one place to correct any of it, in part for ease of
13227c478bd9Sstevel@tonic-gate  * later export to userland, and in part so we can look at
13237c478bd9Sstevel@tonic-gate  * this stuff in a crash dump.
13247c478bd9Sstevel@tonic-gate  */
13257c478bd9Sstevel@tonic-gate 
13267c478bd9Sstevel@tonic-gate /*ARGSUSED*/
13277c478bd9Sstevel@tonic-gate void
13287c478bd9Sstevel@tonic-gate cpuid_pass2(cpu_t *cpu)
13297c478bd9Sstevel@tonic-gate {
13307c478bd9Sstevel@tonic-gate 	uint_t n, nmax;
13317c478bd9Sstevel@tonic-gate 	int i;
13328949bcd6Sandrei 	struct cpuid_regs *cp;
13337c478bd9Sstevel@tonic-gate 	uint8_t *dp;
13347c478bd9Sstevel@tonic-gate 	uint32_t *iptr;
13357c478bd9Sstevel@tonic-gate 	struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi;
13367c478bd9Sstevel@tonic-gate 
13377c478bd9Sstevel@tonic-gate 	ASSERT(cpi->cpi_pass == 1);
13387c478bd9Sstevel@tonic-gate 
13397c478bd9Sstevel@tonic-gate 	if (cpi->cpi_maxeax < 1)
13407c478bd9Sstevel@tonic-gate 		goto pass2_done;
13417c478bd9Sstevel@tonic-gate 
13427c478bd9Sstevel@tonic-gate 	if ((nmax = cpi->cpi_maxeax + 1) > NMAX_CPI_STD)
13437c478bd9Sstevel@tonic-gate 		nmax = NMAX_CPI_STD;
13447c478bd9Sstevel@tonic-gate 	/*
13457c478bd9Sstevel@tonic-gate 	 * (We already handled n == 0 and n == 1 in pass 1)
13467c478bd9Sstevel@tonic-gate 	 */
13477c478bd9Sstevel@tonic-gate 	for (n = 2, cp = &cpi->cpi_std[2]; n < nmax; n++, cp++) {
13488949bcd6Sandrei 		cp->cp_eax = n;
1349d129bde2Sesaxe 
1350d129bde2Sesaxe 		/*
1351d129bde2Sesaxe 		 * CPUID function 4 expects %ecx to be initialized
1352d129bde2Sesaxe 		 * with an index which indicates which cache to return
1353d129bde2Sesaxe 		 * information about. The OS is expected to call function 4
1354d129bde2Sesaxe 		 * with %ecx set to 0, 1, 2, ... until it returns with
1355d129bde2Sesaxe 		 * EAX[4:0] set to 0, which indicates there are no more
1356d129bde2Sesaxe 		 * caches.
1357d129bde2Sesaxe 		 *
1358d129bde2Sesaxe 		 * Here, populate cpi_std[4] with the information returned by
1359d129bde2Sesaxe 		 * function 4 when %ecx == 0, and do the rest in cpuid_pass3()
1360d129bde2Sesaxe 		 * when dynamic memory allocation becomes available.
1361d129bde2Sesaxe 		 *
1362d129bde2Sesaxe 		 * Note: we need to explicitly initialize %ecx here, since
1363d129bde2Sesaxe 		 * function 4 may have been previously invoked.
1364d129bde2Sesaxe 		 */
1365d129bde2Sesaxe 		if (n == 4)
1366d129bde2Sesaxe 			cp->cp_ecx = 0;
1367d129bde2Sesaxe 
13688949bcd6Sandrei 		(void) __cpuid_insn(cp);
1369ae115bc7Smrj 		platform_cpuid_mangle(cpi->cpi_vendor, n, cp);
13707c478bd9Sstevel@tonic-gate 		switch (n) {
13717c478bd9Sstevel@tonic-gate 		case 2:
13727c478bd9Sstevel@tonic-gate 			/*
13737c478bd9Sstevel@tonic-gate 			 * "the lower 8 bits of the %eax register
13747c478bd9Sstevel@tonic-gate 			 * contain a value that identifies the number
13757c478bd9Sstevel@tonic-gate 			 * of times the cpuid [instruction] has to be
13767c478bd9Sstevel@tonic-gate 			 * executed to obtain a complete image of the
13777c478bd9Sstevel@tonic-gate 			 * processor's caching systems."
13787c478bd9Sstevel@tonic-gate 			 *
13797c478bd9Sstevel@tonic-gate 			 * How *do* they make this stuff up?
13807c478bd9Sstevel@tonic-gate 			 */
13817c478bd9Sstevel@tonic-gate 			cpi->cpi_ncache = sizeof (*cp) *
13827c478bd9Sstevel@tonic-gate 			    BITX(cp->cp_eax, 7, 0);
13837c478bd9Sstevel@tonic-gate 			if (cpi->cpi_ncache == 0)
13847c478bd9Sstevel@tonic-gate 				break;
13857c478bd9Sstevel@tonic-gate 			cpi->cpi_ncache--;	/* skip count byte */
13867c478bd9Sstevel@tonic-gate 
13877c478bd9Sstevel@tonic-gate 			/*
13887c478bd9Sstevel@tonic-gate 			 * Well, for now, rather than attempt to implement
13897c478bd9Sstevel@tonic-gate 			 * this slightly dubious algorithm, we just look
13907c478bd9Sstevel@tonic-gate 			 * at the first 15 ..
13917c478bd9Sstevel@tonic-gate 			 */
13927c478bd9Sstevel@tonic-gate 			if (cpi->cpi_ncache > (sizeof (*cp) - 1))
13937c478bd9Sstevel@tonic-gate 				cpi->cpi_ncache = sizeof (*cp) - 1;
13947c478bd9Sstevel@tonic-gate 
13957c478bd9Sstevel@tonic-gate 			dp = cpi->cpi_cacheinfo;
13967c478bd9Sstevel@tonic-gate 			if (BITX(cp->cp_eax, 31, 31) == 0) {
13977c478bd9Sstevel@tonic-gate 				uint8_t *p = (void *)&cp->cp_eax;
139863d3f7dfSkk208521 				for (i = 1; i < 4; i++)
13997c478bd9Sstevel@tonic-gate 					if (p[i] != 0)
14007c478bd9Sstevel@tonic-gate 						*dp++ = p[i];
14017c478bd9Sstevel@tonic-gate 			}
14027c478bd9Sstevel@tonic-gate 			if (BITX(cp->cp_ebx, 31, 31) == 0) {
14037c478bd9Sstevel@tonic-gate 				uint8_t *p = (void *)&cp->cp_ebx;
14047c478bd9Sstevel@tonic-gate 				for (i = 0; i < 4; i++)
14057c478bd9Sstevel@tonic-gate 					if (p[i] != 0)
14067c478bd9Sstevel@tonic-gate 						*dp++ = p[i];
14077c478bd9Sstevel@tonic-gate 			}
14087c478bd9Sstevel@tonic-gate 			if (BITX(cp->cp_ecx, 31, 31) == 0) {
14097c478bd9Sstevel@tonic-gate 				uint8_t *p = (void *)&cp->cp_ecx;
14107c478bd9Sstevel@tonic-gate 				for (i = 0; i < 4; i++)
14117c478bd9Sstevel@tonic-gate 					if (p[i] != 0)
14127c478bd9Sstevel@tonic-gate 						*dp++ = p[i];
14137c478bd9Sstevel@tonic-gate 			}
14147c478bd9Sstevel@tonic-gate 			if (BITX(cp->cp_edx, 31, 31) == 0) {
14157c478bd9Sstevel@tonic-gate 				uint8_t *p = (void *)&cp->cp_edx;
14167c478bd9Sstevel@tonic-gate 				for (i = 0; i < 4; i++)
14177c478bd9Sstevel@tonic-gate 					if (p[i] != 0)
14187c478bd9Sstevel@tonic-gate 						*dp++ = p[i];
14197c478bd9Sstevel@tonic-gate 			}
14207c478bd9Sstevel@tonic-gate 			break;
1421f98fbcecSbholler 
14227c478bd9Sstevel@tonic-gate 		case 3:	/* Processor serial number, if PSN supported */
1423f98fbcecSbholler 			break;
1424f98fbcecSbholler 
14257c478bd9Sstevel@tonic-gate 		case 4:	/* Deterministic cache parameters */
1426f98fbcecSbholler 			break;
1427f98fbcecSbholler 
14287c478bd9Sstevel@tonic-gate 		case 5:	/* Monitor/Mwait parameters */
14295b8a6efeSbholler 		{
14305b8a6efeSbholler 			size_t mwait_size;
1431f98fbcecSbholler 
1432f98fbcecSbholler 			/*
1433f98fbcecSbholler 			 * check cpi_mwait.support which was set in cpuid_pass1
1434f98fbcecSbholler 			 */
1435f98fbcecSbholler 			if (!(cpi->cpi_mwait.support & MWAIT_SUPPORT))
1436f98fbcecSbholler 				break;
1437f98fbcecSbholler 
14385b8a6efeSbholler 			/*
14395b8a6efeSbholler 			 * Protect ourself from insane mwait line size.
14405b8a6efeSbholler 			 * Workaround for incomplete hardware emulator(s).
14415b8a6efeSbholler 			 */
14425b8a6efeSbholler 			mwait_size = (size_t)MWAIT_SIZE_MAX(cpi);
14435b8a6efeSbholler 			if (mwait_size < sizeof (uint32_t) ||
14445b8a6efeSbholler 			    !ISP2(mwait_size)) {
14455b8a6efeSbholler #if DEBUG
14465b8a6efeSbholler 				cmn_err(CE_NOTE, "Cannot handle cpu %d mwait "
14475b8a6efeSbholler 				    "size %ld",
14485b8a6efeSbholler 				    cpu->cpu_id, (long)mwait_size);
14495b8a6efeSbholler #endif
14505b8a6efeSbholler 				break;
14515b8a6efeSbholler 			}
14525b8a6efeSbholler 
1453f98fbcecSbholler 			cpi->cpi_mwait.mon_min = (size_t)MWAIT_SIZE_MIN(cpi);
14545b8a6efeSbholler 			cpi->cpi_mwait.mon_max = mwait_size;
1455f98fbcecSbholler 			if (MWAIT_EXTENSION(cpi)) {
1456f98fbcecSbholler 				cpi->cpi_mwait.support |= MWAIT_EXTENSIONS;
1457f98fbcecSbholler 				if (MWAIT_INT_ENABLE(cpi))
1458f98fbcecSbholler 					cpi->cpi_mwait.support |=
1459f98fbcecSbholler 					    MWAIT_ECX_INT_ENABLE;
1460f98fbcecSbholler 			}
1461f98fbcecSbholler 			break;
14625b8a6efeSbholler 		}
14637c478bd9Sstevel@tonic-gate 		default:
14647c478bd9Sstevel@tonic-gate 			break;
14657c478bd9Sstevel@tonic-gate 		}
14667c478bd9Sstevel@tonic-gate 	}
14677c478bd9Sstevel@tonic-gate 
1468*b6917abeSmishra 	if (cpi->cpi_maxeax >= 0xB && cpi->cpi_vendor == X86_VENDOR_Intel) {
1469*b6917abeSmishra 		cp->cp_eax = 0xB;
1470*b6917abeSmishra 		cp->cp_ecx = 0;
1471*b6917abeSmishra 
1472*b6917abeSmishra 		(void) __cpuid_insn(cp);
1473*b6917abeSmishra 
1474*b6917abeSmishra 		/*
1475*b6917abeSmishra 		 * Check CPUID.EAX=0BH, ECX=0H:EBX is non-zero, which
1476*b6917abeSmishra 		 * indicates that the extended topology enumeration leaf is
1477*b6917abeSmishra 		 * available.
1478*b6917abeSmishra 		 */
1479*b6917abeSmishra 		if (cp->cp_ebx) {
1480*b6917abeSmishra 			uint32_t x2apic_id;
1481*b6917abeSmishra 			uint_t coreid_shift = 0;
1482*b6917abeSmishra 			uint_t ncpu_per_core = 1;
1483*b6917abeSmishra 			uint_t chipid_shift = 0;
1484*b6917abeSmishra 			uint_t ncpu_per_chip = 1;
1485*b6917abeSmishra 			uint_t i;
1486*b6917abeSmishra 			uint_t level;
1487*b6917abeSmishra 
1488*b6917abeSmishra 			for (i = 0; i < CPI_FNB_ECX_MAX; i++) {
1489*b6917abeSmishra 				cp->cp_eax = 0xB;
1490*b6917abeSmishra 				cp->cp_ecx = i;
1491*b6917abeSmishra 
1492*b6917abeSmishra 				(void) __cpuid_insn(cp);
1493*b6917abeSmishra 				level = CPI_CPU_LEVEL_TYPE(cp);
1494*b6917abeSmishra 
1495*b6917abeSmishra 				if (level == 1) {
1496*b6917abeSmishra 					x2apic_id = cp->cp_edx;
1497*b6917abeSmishra 					coreid_shift = BITX(cp->cp_eax, 4, 0);
1498*b6917abeSmishra 					ncpu_per_core = BITX(cp->cp_ebx, 15, 0);
1499*b6917abeSmishra 				} else if (level == 2) {
1500*b6917abeSmishra 					x2apic_id = cp->cp_edx;
1501*b6917abeSmishra 					chipid_shift = BITX(cp->cp_eax, 4, 0);
1502*b6917abeSmishra 					ncpu_per_chip = BITX(cp->cp_ebx, 15, 0);
1503*b6917abeSmishra 				}
1504*b6917abeSmishra 			}
1505*b6917abeSmishra 
1506*b6917abeSmishra 			cpi->cpi_apicid = x2apic_id;
1507*b6917abeSmishra 			cpi->cpi_ncpu_per_chip = ncpu_per_chip;
1508*b6917abeSmishra 			cpi->cpi_ncore_per_chip = ncpu_per_chip /
1509*b6917abeSmishra 			    ncpu_per_core;
1510*b6917abeSmishra 			cpi->cpi_chipid = x2apic_id >> chipid_shift;
1511*b6917abeSmishra 			cpi->cpi_clogid = x2apic_id & ((1 << chipid_shift) - 1);
1512*b6917abeSmishra 			cpi->cpi_coreid = x2apic_id >> coreid_shift;
1513*b6917abeSmishra 			cpi->cpi_pkgcoreid = cpi->cpi_clogid >> coreid_shift;
1514*b6917abeSmishra 		}
1515*b6917abeSmishra 	}
1516*b6917abeSmishra 
15177c478bd9Sstevel@tonic-gate 	if ((cpi->cpi_xmaxeax & 0x80000000) == 0)
15187c478bd9Sstevel@tonic-gate 		goto pass2_done;
15197c478bd9Sstevel@tonic-gate 
15207c478bd9Sstevel@tonic-gate 	if ((nmax = cpi->cpi_xmaxeax - 0x80000000 + 1) > NMAX_CPI_EXTD)
15217c478bd9Sstevel@tonic-gate 		nmax = NMAX_CPI_EXTD;
15227c478bd9Sstevel@tonic-gate 	/*
15237c478bd9Sstevel@tonic-gate 	 * Copy the extended properties, fixing them as we go.
15247c478bd9Sstevel@tonic-gate 	 * (We already handled n == 0 and n == 1 in pass 1)
15257c478bd9Sstevel@tonic-gate 	 */
15267c478bd9Sstevel@tonic-gate 	iptr = (void *)cpi->cpi_brandstr;
15277c478bd9Sstevel@tonic-gate 	for (n = 2, cp = &cpi->cpi_extd[2]; n < nmax; cp++, n++) {
15288949bcd6Sandrei 		cp->cp_eax = 0x80000000 + n;
15298949bcd6Sandrei 		(void) __cpuid_insn(cp);
1530ae115bc7Smrj 		platform_cpuid_mangle(cpi->cpi_vendor, 0x80000000 + n, cp);
15317c478bd9Sstevel@tonic-gate 		switch (n) {
15327c478bd9Sstevel@tonic-gate 		case 2:
15337c478bd9Sstevel@tonic-gate 		case 3:
15347c478bd9Sstevel@tonic-gate 		case 4:
15357c478bd9Sstevel@tonic-gate 			/*
15367c478bd9Sstevel@tonic-gate 			 * Extract the brand string
15377c478bd9Sstevel@tonic-gate 			 */
15387c478bd9Sstevel@tonic-gate 			*iptr++ = cp->cp_eax;
15397c478bd9Sstevel@tonic-gate 			*iptr++ = cp->cp_ebx;
15407c478bd9Sstevel@tonic-gate 			*iptr++ = cp->cp_ecx;
15417c478bd9Sstevel@tonic-gate 			*iptr++ = cp->cp_edx;
15427c478bd9Sstevel@tonic-gate 			break;
15437c478bd9Sstevel@tonic-gate 		case 5:
15447c478bd9Sstevel@tonic-gate 			switch (cpi->cpi_vendor) {
15457c478bd9Sstevel@tonic-gate 			case X86_VENDOR_AMD:
15467c478bd9Sstevel@tonic-gate 				/*
15477c478bd9Sstevel@tonic-gate 				 * The Athlon and Duron were the first
15487c478bd9Sstevel@tonic-gate 				 * parts to report the sizes of the
15497c478bd9Sstevel@tonic-gate 				 * TLB for large pages. Before then,
15507c478bd9Sstevel@tonic-gate 				 * we don't trust the data.
15517c478bd9Sstevel@tonic-gate 				 */
15527c478bd9Sstevel@tonic-gate 				if (cpi->cpi_family < 6 ||
15537c478bd9Sstevel@tonic-gate 				    (cpi->cpi_family == 6 &&
15547c478bd9Sstevel@tonic-gate 				    cpi->cpi_model < 1))
15557c478bd9Sstevel@tonic-gate 					cp->cp_eax = 0;
15567c478bd9Sstevel@tonic-gate 				break;
15577c478bd9Sstevel@tonic-gate 			default:
15587c478bd9Sstevel@tonic-gate 				break;
15597c478bd9Sstevel@tonic-gate 			}
15607c478bd9Sstevel@tonic-gate 			break;
15617c478bd9Sstevel@tonic-gate 		case 6:
15627c478bd9Sstevel@tonic-gate 			switch (cpi->cpi_vendor) {
15637c478bd9Sstevel@tonic-gate 			case X86_VENDOR_AMD:
15647c478bd9Sstevel@tonic-gate 				/*
15657c478bd9Sstevel@tonic-gate 				 * The Athlon and Duron were the first
15667c478bd9Sstevel@tonic-gate 				 * AMD parts with L2 TLB's.
15677c478bd9Sstevel@tonic-gate 				 * Before then, don't trust the data.
15687c478bd9Sstevel@tonic-gate 				 */
15697c478bd9Sstevel@tonic-gate 				if (cpi->cpi_family < 6 ||
15707c478bd9Sstevel@tonic-gate 				    cpi->cpi_family == 6 &&
15717c478bd9Sstevel@tonic-gate 				    cpi->cpi_model < 1)
15727c478bd9Sstevel@tonic-gate 					cp->cp_eax = cp->cp_ebx = 0;
15737c478bd9Sstevel@tonic-gate 				/*
15747c478bd9Sstevel@tonic-gate 				 * AMD Duron rev A0 reports L2
15757c478bd9Sstevel@tonic-gate 				 * cache size incorrectly as 1K
15767c478bd9Sstevel@tonic-gate 				 * when it is really 64K
15777c478bd9Sstevel@tonic-gate 				 */
15787c478bd9Sstevel@tonic-gate 				if (cpi->cpi_family == 6 &&
15797c478bd9Sstevel@tonic-gate 				    cpi->cpi_model == 3 &&
15807c478bd9Sstevel@tonic-gate 				    cpi->cpi_step == 0) {
15817c478bd9Sstevel@tonic-gate 					cp->cp_ecx &= 0xffff;
15827c478bd9Sstevel@tonic-gate 					cp->cp_ecx |= 0x400000;
15837c478bd9Sstevel@tonic-gate 				}
15847c478bd9Sstevel@tonic-gate 				break;
15857c478bd9Sstevel@tonic-gate 			case X86_VENDOR_Cyrix:	/* VIA C3 */
15867c478bd9Sstevel@tonic-gate 				/*
15877c478bd9Sstevel@tonic-gate 				 * VIA C3 processors are a bit messed
15887c478bd9Sstevel@tonic-gate 				 * up w.r.t. encoding cache sizes in %ecx
15897c478bd9Sstevel@tonic-gate 				 */
15907c478bd9Sstevel@tonic-gate 				if (cpi->cpi_family != 6)
15917c478bd9Sstevel@tonic-gate 					break;
15927c478bd9Sstevel@tonic-gate 				/*
15937c478bd9Sstevel@tonic-gate 				 * model 7 and 8 were incorrectly encoded
15947c478bd9Sstevel@tonic-gate 				 *
15957c478bd9Sstevel@tonic-gate 				 * xxx is model 8 really broken?
15967c478bd9Sstevel@tonic-gate 				 */
15977c478bd9Sstevel@tonic-gate 				if (cpi->cpi_model == 7 ||
15987c478bd9Sstevel@tonic-gate 				    cpi->cpi_model == 8)
15997c478bd9Sstevel@tonic-gate 					cp->cp_ecx =
16007c478bd9Sstevel@tonic-gate 					    BITX(cp->cp_ecx, 31, 24) << 16 |
16017c478bd9Sstevel@tonic-gate 					    BITX(cp->cp_ecx, 23, 16) << 12 |
16027c478bd9Sstevel@tonic-gate 					    BITX(cp->cp_ecx, 15, 8) << 8 |
16037c478bd9Sstevel@tonic-gate 					    BITX(cp->cp_ecx, 7, 0);
16047c478bd9Sstevel@tonic-gate 				/*
16057c478bd9Sstevel@tonic-gate 				 * model 9 stepping 1 has wrong associativity
16067c478bd9Sstevel@tonic-gate 				 */
16077c478bd9Sstevel@tonic-gate 				if (cpi->cpi_model == 9 && cpi->cpi_step == 1)
16087c478bd9Sstevel@tonic-gate 					cp->cp_ecx |= 8 << 12;
16097c478bd9Sstevel@tonic-gate 				break;
16107c478bd9Sstevel@tonic-gate 			case X86_VENDOR_Intel:
16117c478bd9Sstevel@tonic-gate 				/*
16127c478bd9Sstevel@tonic-gate 				 * Extended L2 Cache features function.
16137c478bd9Sstevel@tonic-gate 				 * First appeared on Prescott.
16147c478bd9Sstevel@tonic-gate 				 */
16157c478bd9Sstevel@tonic-gate 			default:
16167c478bd9Sstevel@tonic-gate 				break;
16177c478bd9Sstevel@tonic-gate 			}
16187c478bd9Sstevel@tonic-gate 			break;
16197c478bd9Sstevel@tonic-gate 		default:
16207c478bd9Sstevel@tonic-gate 			break;
16217c478bd9Sstevel@tonic-gate 		}
16227c478bd9Sstevel@tonic-gate 	}
16237c478bd9Sstevel@tonic-gate 
16247c478bd9Sstevel@tonic-gate pass2_done:
16257c478bd9Sstevel@tonic-gate 	cpi->cpi_pass = 2;
16267c478bd9Sstevel@tonic-gate }
16277c478bd9Sstevel@tonic-gate 
16287c478bd9Sstevel@tonic-gate static const char *
16297c478bd9Sstevel@tonic-gate intel_cpubrand(const struct cpuid_info *cpi)
16307c478bd9Sstevel@tonic-gate {
16317c478bd9Sstevel@tonic-gate 	int i;
16327c478bd9Sstevel@tonic-gate 
16337c478bd9Sstevel@tonic-gate 	if ((x86_feature & X86_CPUID) == 0 ||
16347c478bd9Sstevel@tonic-gate 	    cpi->cpi_maxeax < 1 || cpi->cpi_family < 5)
16357c478bd9Sstevel@tonic-gate 		return ("i486");
16367c478bd9Sstevel@tonic-gate 
16377c478bd9Sstevel@tonic-gate 	switch (cpi->cpi_family) {
16387c478bd9Sstevel@tonic-gate 	case 5:
16397c478bd9Sstevel@tonic-gate 		return ("Intel Pentium(r)");
16407c478bd9Sstevel@tonic-gate 	case 6:
16417c478bd9Sstevel@tonic-gate 		switch (cpi->cpi_model) {
16427c478bd9Sstevel@tonic-gate 			uint_t celeron, xeon;
16438949bcd6Sandrei 			const struct cpuid_regs *cp;
16447c478bd9Sstevel@tonic-gate 		case 0:
16457c478bd9Sstevel@tonic-gate 		case 1:
16467c478bd9Sstevel@tonic-gate 		case 2:
16477c478bd9Sstevel@tonic-gate 			return ("Intel Pentium(r) Pro");
16487c478bd9Sstevel@tonic-gate 		case 3:
16497c478bd9Sstevel@tonic-gate 		case 4:
16507c478bd9Sstevel@tonic-gate 			return ("Intel Pentium(r) II");
16517c478bd9Sstevel@tonic-gate 		case 6:
16527c478bd9Sstevel@tonic-gate 			return ("Intel Celeron(r)");
16537c478bd9Sstevel@tonic-gate 		case 5:
16547c478bd9Sstevel@tonic-gate 		case 7:
16557c478bd9Sstevel@tonic-gate 			celeron = xeon = 0;
16567c478bd9Sstevel@tonic-gate 			cp = &cpi->cpi_std[2];	/* cache info */
16577c478bd9Sstevel@tonic-gate 
165863d3f7dfSkk208521 			for (i = 1; i < 4; i++) {
16597c478bd9Sstevel@tonic-gate 				uint_t tmp;
16607c478bd9Sstevel@tonic-gate 
16617c478bd9Sstevel@tonic-gate 				tmp = (cp->cp_eax >> (8 * i)) & 0xff;
16627c478bd9Sstevel@tonic-gate 				if (tmp == 0x40)
16637c478bd9Sstevel@tonic-gate 					celeron++;
16647c478bd9Sstevel@tonic-gate 				if (tmp >= 0x44 && tmp <= 0x45)
16657c478bd9Sstevel@tonic-gate 					xeon++;
16667c478bd9Sstevel@tonic-gate 			}
16677c478bd9Sstevel@tonic-gate 
16687c478bd9Sstevel@tonic-gate 			for (i = 0; i < 2; i++) {
16697c478bd9Sstevel@tonic-gate 				uint_t tmp;
16707c478bd9Sstevel@tonic-gate 
16717c478bd9Sstevel@tonic-gate 				tmp = (cp->cp_ebx >> (8 * i)) & 0xff;
16727c478bd9Sstevel@tonic-gate 				if (tmp == 0x40)
16737c478bd9Sstevel@tonic-gate 					celeron++;
16747c478bd9Sstevel@tonic-gate 				else if (tmp >= 0x44 && tmp <= 0x45)
16757c478bd9Sstevel@tonic-gate 					xeon++;
16767c478bd9Sstevel@tonic-gate 			}
16777c478bd9Sstevel@tonic-gate 
16787c478bd9Sstevel@tonic-gate 			for (i = 0; i < 4; i++) {
16797c478bd9Sstevel@tonic-gate 				uint_t tmp;
16807c478bd9Sstevel@tonic-gate 
16817c478bd9Sstevel@tonic-gate 				tmp = (cp->cp_ecx >> (8 * i)) & 0xff;
16827c478bd9Sstevel@tonic-gate 				if (tmp == 0x40)
16837c478bd9Sstevel@tonic-gate 					celeron++;
16847c478bd9Sstevel@tonic-gate 				else if (tmp >= 0x44 && tmp <= 0x45)
16857c478bd9Sstevel@tonic-gate 					xeon++;
16867c478bd9Sstevel@tonic-gate 			}
16877c478bd9Sstevel@tonic-gate 
16887c478bd9Sstevel@tonic-gate 			for (i = 0; i < 4; i++) {
16897c478bd9Sstevel@tonic-gate 				uint_t tmp;
16907c478bd9Sstevel@tonic-gate 
16917c478bd9Sstevel@tonic-gate 				tmp = (cp->cp_edx >> (8 * i)) & 0xff;
16927c478bd9Sstevel@tonic-gate 				if (tmp == 0x40)
16937c478bd9Sstevel@tonic-gate 					celeron++;
16947c478bd9Sstevel@tonic-gate 				else if (tmp >= 0x44 && tmp <= 0x45)
16957c478bd9Sstevel@tonic-gate 					xeon++;
16967c478bd9Sstevel@tonic-gate 			}
16977c478bd9Sstevel@tonic-gate 
16987c478bd9Sstevel@tonic-gate 			if (celeron)
16997c478bd9Sstevel@tonic-gate 				return ("Intel Celeron(r)");
17007c478bd9Sstevel@tonic-gate 			if (xeon)
17017c478bd9Sstevel@tonic-gate 				return (cpi->cpi_model == 5 ?
17027c478bd9Sstevel@tonic-gate 				    "Intel Pentium(r) II Xeon(tm)" :
17037c478bd9Sstevel@tonic-gate 				    "Intel Pentium(r) III Xeon(tm)");
17047c478bd9Sstevel@tonic-gate 			return (cpi->cpi_model == 5 ?
17057c478bd9Sstevel@tonic-gate 			    "Intel Pentium(r) II or Pentium(r) II Xeon(tm)" :
17067c478bd9Sstevel@tonic-gate 			    "Intel Pentium(r) III or Pentium(r) III Xeon(tm)");
17077c478bd9Sstevel@tonic-gate 		default:
17087c478bd9Sstevel@tonic-gate 			break;
17097c478bd9Sstevel@tonic-gate 		}
17107c478bd9Sstevel@tonic-gate 	default:
17117c478bd9Sstevel@tonic-gate 		break;
17127c478bd9Sstevel@tonic-gate 	}
17137c478bd9Sstevel@tonic-gate 
17145ff02082Sdmick 	/* BrandID is present if the field is nonzero */
17155ff02082Sdmick 	if (cpi->cpi_brandid != 0) {
17167c478bd9Sstevel@tonic-gate 		static const struct {
17177c478bd9Sstevel@tonic-gate 			uint_t bt_bid;
17187c478bd9Sstevel@tonic-gate 			const char *bt_str;
17197c478bd9Sstevel@tonic-gate 		} brand_tbl[] = {
17207c478bd9Sstevel@tonic-gate 			{ 0x1,	"Intel(r) Celeron(r)" },
17217c478bd9Sstevel@tonic-gate 			{ 0x2,	"Intel(r) Pentium(r) III" },
17227c478bd9Sstevel@tonic-gate 			{ 0x3,	"Intel(r) Pentium(r) III Xeon(tm)" },
17237c478bd9Sstevel@tonic-gate 			{ 0x4,	"Intel(r) Pentium(r) III" },
17247c478bd9Sstevel@tonic-gate 			{ 0x6,	"Mobile Intel(r) Pentium(r) III" },
17257c478bd9Sstevel@tonic-gate 			{ 0x7,	"Mobile Intel(r) Celeron(r)" },
17267c478bd9Sstevel@tonic-gate 			{ 0x8,	"Intel(r) Pentium(r) 4" },
17277c478bd9Sstevel@tonic-gate 			{ 0x9,	"Intel(r) Pentium(r) 4" },
17287c478bd9Sstevel@tonic-gate 			{ 0xa,	"Intel(r) Celeron(r)" },
17297c478bd9Sstevel@tonic-gate 			{ 0xb,	"Intel(r) Xeon(tm)" },
17307c478bd9Sstevel@tonic-gate 			{ 0xc,	"Intel(r) Xeon(tm) MP" },
17317c478bd9Sstevel@tonic-gate 			{ 0xe,	"Mobile Intel(r) Pentium(r) 4" },
17325ff02082Sdmick 			{ 0xf,	"Mobile Intel(r) Celeron(r)" },
17335ff02082Sdmick 			{ 0x11, "Mobile Genuine Intel(r)" },
17345ff02082Sdmick 			{ 0x12, "Intel(r) Celeron(r) M" },
17355ff02082Sdmick 			{ 0x13, "Mobile Intel(r) Celeron(r)" },
17365ff02082Sdmick 			{ 0x14, "Intel(r) Celeron(r)" },
17375ff02082Sdmick 			{ 0x15, "Mobile Genuine Intel(r)" },
17385ff02082Sdmick 			{ 0x16,	"Intel(r) Pentium(r) M" },
17395ff02082Sdmick 			{ 0x17, "Mobile Intel(r) Celeron(r)" }
17407c478bd9Sstevel@tonic-gate 		};
17417c478bd9Sstevel@tonic-gate 		uint_t btblmax = sizeof (brand_tbl) / sizeof (brand_tbl[0]);
17427c478bd9Sstevel@tonic-gate 		uint_t sgn;
17437c478bd9Sstevel@tonic-gate 
17447c478bd9Sstevel@tonic-gate 		sgn = (cpi->cpi_family << 8) |
17457c478bd9Sstevel@tonic-gate 		    (cpi->cpi_model << 4) | cpi->cpi_step;
17467c478bd9Sstevel@tonic-gate 
17477c478bd9Sstevel@tonic-gate 		for (i = 0; i < btblmax; i++)
17487c478bd9Sstevel@tonic-gate 			if (brand_tbl[i].bt_bid == cpi->cpi_brandid)
17497c478bd9Sstevel@tonic-gate 				break;
17507c478bd9Sstevel@tonic-gate 		if (i < btblmax) {
17517c478bd9Sstevel@tonic-gate 			if (sgn == 0x6b1 && cpi->cpi_brandid == 3)
17527c478bd9Sstevel@tonic-gate 				return ("Intel(r) Celeron(r)");
17537c478bd9Sstevel@tonic-gate 			if (sgn < 0xf13 && cpi->cpi_brandid == 0xb)
17547c478bd9Sstevel@tonic-gate 				return ("Intel(r) Xeon(tm) MP");
17557c478bd9Sstevel@tonic-gate 			if (sgn < 0xf13 && cpi->cpi_brandid == 0xe)
17567c478bd9Sstevel@tonic-gate 				return ("Intel(r) Xeon(tm)");
17577c478bd9Sstevel@tonic-gate 			return (brand_tbl[i].bt_str);
17587c478bd9Sstevel@tonic-gate 		}
17597c478bd9Sstevel@tonic-gate 	}
17607c478bd9Sstevel@tonic-gate 
17617c478bd9Sstevel@tonic-gate 	return (NULL);
17627c478bd9Sstevel@tonic-gate }
17637c478bd9Sstevel@tonic-gate 
17647c478bd9Sstevel@tonic-gate static const char *
17657c478bd9Sstevel@tonic-gate amd_cpubrand(const struct cpuid_info *cpi)
17667c478bd9Sstevel@tonic-gate {
17677c478bd9Sstevel@tonic-gate 	if ((x86_feature & X86_CPUID) == 0 ||
17687c478bd9Sstevel@tonic-gate 	    cpi->cpi_maxeax < 1 || cpi->cpi_family < 5)
17697c478bd9Sstevel@tonic-gate 		return ("i486 compatible");
17707c478bd9Sstevel@tonic-gate 
17717c478bd9Sstevel@tonic-gate 	switch (cpi->cpi_family) {
17727c478bd9Sstevel@tonic-gate 	case 5:
17737c478bd9Sstevel@tonic-gate 		switch (cpi->cpi_model) {
17747c478bd9Sstevel@tonic-gate 		case 0:
17757c478bd9Sstevel@tonic-gate 		case 1:
17767c478bd9Sstevel@tonic-gate 		case 2:
17777c478bd9Sstevel@tonic-gate 		case 3:
17787c478bd9Sstevel@tonic-gate 		case 4:
17797c478bd9Sstevel@tonic-gate 		case 5:
17807c478bd9Sstevel@tonic-gate 			return ("AMD-K5(r)");
17817c478bd9Sstevel@tonic-gate 		case 6:
17827c478bd9Sstevel@tonic-gate 		case 7:
17837c478bd9Sstevel@tonic-gate 			return ("AMD-K6(r)");
17847c478bd9Sstevel@tonic-gate 		case 8:
17857c478bd9Sstevel@tonic-gate 			return ("AMD-K6(r)-2");
17867c478bd9Sstevel@tonic-gate 		case 9:
17877c478bd9Sstevel@tonic-gate 			return ("AMD-K6(r)-III");
17887c478bd9Sstevel@tonic-gate 		default:
17897c478bd9Sstevel@tonic-gate 			return ("AMD (family 5)");
17907c478bd9Sstevel@tonic-gate 		}
17917c478bd9Sstevel@tonic-gate 	case 6:
17927c478bd9Sstevel@tonic-gate 		switch (cpi->cpi_model) {
17937c478bd9Sstevel@tonic-gate 		case 1:
17947c478bd9Sstevel@tonic-gate 			return ("AMD-K7(tm)");
17957c478bd9Sstevel@tonic-gate 		case 0:
17967c478bd9Sstevel@tonic-gate 		case 2:
17977c478bd9Sstevel@tonic-gate 		case 4:
17987c478bd9Sstevel@tonic-gate 			return ("AMD Athlon(tm)");
17997c478bd9Sstevel@tonic-gate 		case 3:
18007c478bd9Sstevel@tonic-gate 		case 7:
18017c478bd9Sstevel@tonic-gate 			return ("AMD Duron(tm)");
18027c478bd9Sstevel@tonic-gate 		case 6:
18037c478bd9Sstevel@tonic-gate 		case 8:
18047c478bd9Sstevel@tonic-gate 		case 10:
18057c478bd9Sstevel@tonic-gate 			/*
18067c478bd9Sstevel@tonic-gate 			 * Use the L2 cache size to distinguish
18077c478bd9Sstevel@tonic-gate 			 */
18087c478bd9Sstevel@tonic-gate 			return ((cpi->cpi_extd[6].cp_ecx >> 16) >= 256 ?
18097c478bd9Sstevel@tonic-gate 			    "AMD Athlon(tm)" : "AMD Duron(tm)");
18107c478bd9Sstevel@tonic-gate 		default:
18117c478bd9Sstevel@tonic-gate 			return ("AMD (family 6)");
18127c478bd9Sstevel@tonic-gate 		}
18137c478bd9Sstevel@tonic-gate 	default:
18147c478bd9Sstevel@tonic-gate 		break;
18157c478bd9Sstevel@tonic-gate 	}
18167c478bd9Sstevel@tonic-gate 
18177c478bd9Sstevel@tonic-gate 	if (cpi->cpi_family == 0xf && cpi->cpi_model == 5 &&
18187c478bd9Sstevel@tonic-gate 	    cpi->cpi_brandid != 0) {
18197c478bd9Sstevel@tonic-gate 		switch (BITX(cpi->cpi_brandid, 7, 5)) {
18207c478bd9Sstevel@tonic-gate 		case 3:
18217c478bd9Sstevel@tonic-gate 			return ("AMD Opteron(tm) UP 1xx");
18227c478bd9Sstevel@tonic-gate 		case 4:
18237c478bd9Sstevel@tonic-gate 			return ("AMD Opteron(tm) DP 2xx");
18247c478bd9Sstevel@tonic-gate 		case 5:
18257c478bd9Sstevel@tonic-gate 			return ("AMD Opteron(tm) MP 8xx");
18267c478bd9Sstevel@tonic-gate 		default:
18277c478bd9Sstevel@tonic-gate 			return ("AMD Opteron(tm)");
18287c478bd9Sstevel@tonic-gate 		}
18297c478bd9Sstevel@tonic-gate 	}
18307c478bd9Sstevel@tonic-gate 
18317c478bd9Sstevel@tonic-gate 	return (NULL);
18327c478bd9Sstevel@tonic-gate }
18337c478bd9Sstevel@tonic-gate 
18347c478bd9Sstevel@tonic-gate static const char *
18357c478bd9Sstevel@tonic-gate cyrix_cpubrand(struct cpuid_info *cpi, uint_t type)
18367c478bd9Sstevel@tonic-gate {
18377c478bd9Sstevel@tonic-gate 	if ((x86_feature & X86_CPUID) == 0 ||
18387c478bd9Sstevel@tonic-gate 	    cpi->cpi_maxeax < 1 || cpi->cpi_family < 5 ||
18397c478bd9Sstevel@tonic-gate 	    type == X86_TYPE_CYRIX_486)
18407c478bd9Sstevel@tonic-gate 		return ("i486 compatible");
18417c478bd9Sstevel@tonic-gate 
18427c478bd9Sstevel@tonic-gate 	switch (type) {
18437c478bd9Sstevel@tonic-gate 	case X86_TYPE_CYRIX_6x86:
18447c478bd9Sstevel@tonic-gate 		return ("Cyrix 6x86");
18457c478bd9Sstevel@tonic-gate 	case X86_TYPE_CYRIX_6x86L:
18467c478bd9Sstevel@tonic-gate 		return ("Cyrix 6x86L");
18477c478bd9Sstevel@tonic-gate 	case X86_TYPE_CYRIX_6x86MX:
18487c478bd9Sstevel@tonic-gate 		return ("Cyrix 6x86MX");
18497c478bd9Sstevel@tonic-gate 	case X86_TYPE_CYRIX_GXm:
18507c478bd9Sstevel@tonic-gate 		return ("Cyrix GXm");
18517c478bd9Sstevel@tonic-gate 	case X86_TYPE_CYRIX_MediaGX:
18527c478bd9Sstevel@tonic-gate 		return ("Cyrix MediaGX");
18537c478bd9Sstevel@tonic-gate 	case X86_TYPE_CYRIX_MII:
18547c478bd9Sstevel@tonic-gate 		return ("Cyrix M2");
18557c478bd9Sstevel@tonic-gate 	case X86_TYPE_VIA_CYRIX_III:
18567c478bd9Sstevel@tonic-gate 		return ("VIA Cyrix M3");
18577c478bd9Sstevel@tonic-gate 	default:
18587c478bd9Sstevel@tonic-gate 		/*
18597c478bd9Sstevel@tonic-gate 		 * Have another wild guess ..
18607c478bd9Sstevel@tonic-gate 		 */
18617c478bd9Sstevel@tonic-gate 		if (cpi->cpi_family == 4 && cpi->cpi_model == 9)
18627c478bd9Sstevel@tonic-gate 			return ("Cyrix 5x86");
18637c478bd9Sstevel@tonic-gate 		else if (cpi->cpi_family == 5) {
18647c478bd9Sstevel@tonic-gate 			switch (cpi->cpi_model) {
18657c478bd9Sstevel@tonic-gate 			case 2:
18667c478bd9Sstevel@tonic-gate 				return ("Cyrix 6x86");	/* Cyrix M1 */
18677c478bd9Sstevel@tonic-gate 			case 4:
18687c478bd9Sstevel@tonic-gate 				return ("Cyrix MediaGX");
18697c478bd9Sstevel@tonic-gate 			default:
18707c478bd9Sstevel@tonic-gate 				break;
18717c478bd9Sstevel@tonic-gate 			}
18727c478bd9Sstevel@tonic-gate 		} else if (cpi->cpi_family == 6) {
18737c478bd9Sstevel@tonic-gate 			switch (cpi->cpi_model) {
18747c478bd9Sstevel@tonic-gate 			case 0:
18757c478bd9Sstevel@tonic-gate 				return ("Cyrix 6x86MX"); /* Cyrix M2? */
18767c478bd9Sstevel@tonic-gate 			case 5:
18777c478bd9Sstevel@tonic-gate 			case 6:
18787c478bd9Sstevel@tonic-gate 			case 7:
18797c478bd9Sstevel@tonic-gate 			case 8:
18807c478bd9Sstevel@tonic-gate 			case 9:
18817c478bd9Sstevel@tonic-gate 				return ("VIA C3");
18827c478bd9Sstevel@tonic-gate 			default:
18837c478bd9Sstevel@tonic-gate 				break;
18847c478bd9Sstevel@tonic-gate 			}
18857c478bd9Sstevel@tonic-gate 		}
18867c478bd9Sstevel@tonic-gate 		break;
18877c478bd9Sstevel@tonic-gate 	}
18887c478bd9Sstevel@tonic-gate 	return (NULL);
18897c478bd9Sstevel@tonic-gate }
18907c478bd9Sstevel@tonic-gate 
18917c478bd9Sstevel@tonic-gate /*
18927c478bd9Sstevel@tonic-gate  * This only gets called in the case that the CPU extended
18937c478bd9Sstevel@tonic-gate  * feature brand string (0x80000002, 0x80000003, 0x80000004)
18947c478bd9Sstevel@tonic-gate  * aren't available, or contain null bytes for some reason.
18957c478bd9Sstevel@tonic-gate  */
18967c478bd9Sstevel@tonic-gate static void
18977c478bd9Sstevel@tonic-gate fabricate_brandstr(struct cpuid_info *cpi)
18987c478bd9Sstevel@tonic-gate {
18997c478bd9Sstevel@tonic-gate 	const char *brand = NULL;
19007c478bd9Sstevel@tonic-gate 
19017c478bd9Sstevel@tonic-gate 	switch (cpi->cpi_vendor) {
19027c478bd9Sstevel@tonic-gate 	case X86_VENDOR_Intel:
19037c478bd9Sstevel@tonic-gate 		brand = intel_cpubrand(cpi);
19047c478bd9Sstevel@tonic-gate 		break;
19057c478bd9Sstevel@tonic-gate 	case X86_VENDOR_AMD:
19067c478bd9Sstevel@tonic-gate 		brand = amd_cpubrand(cpi);
19077c478bd9Sstevel@tonic-gate 		break;
19087c478bd9Sstevel@tonic-gate 	case X86_VENDOR_Cyrix:
19097c478bd9Sstevel@tonic-gate 		brand = cyrix_cpubrand(cpi, x86_type);
19107c478bd9Sstevel@tonic-gate 		break;
19117c478bd9Sstevel@tonic-gate 	case X86_VENDOR_NexGen:
19127c478bd9Sstevel@tonic-gate 		if (cpi->cpi_family == 5 && cpi->cpi_model == 0)
19137c478bd9Sstevel@tonic-gate 			brand = "NexGen Nx586";
19147c478bd9Sstevel@tonic-gate 		break;
19157c478bd9Sstevel@tonic-gate 	case X86_VENDOR_Centaur:
19167c478bd9Sstevel@tonic-gate 		if (cpi->cpi_family == 5)
19177c478bd9Sstevel@tonic-gate 			switch (cpi->cpi_model) {
19187c478bd9Sstevel@tonic-gate 			case 4:
19197c478bd9Sstevel@tonic-gate 				brand = "Centaur C6";
19207c478bd9Sstevel@tonic-gate 				break;
19217c478bd9Sstevel@tonic-gate 			case 8:
19227c478bd9Sstevel@tonic-gate 				brand = "Centaur C2";
19237c478bd9Sstevel@tonic-gate 				break;
19247c478bd9Sstevel@tonic-gate 			case 9:
19257c478bd9Sstevel@tonic-gate 				brand = "Centaur C3";
19267c478bd9Sstevel@tonic-gate 				break;
19277c478bd9Sstevel@tonic-gate 			default:
19287c478bd9Sstevel@tonic-gate 				break;
19297c478bd9Sstevel@tonic-gate 			}
19307c478bd9Sstevel@tonic-gate 		break;
19317c478bd9Sstevel@tonic-gate 	case X86_VENDOR_Rise:
19327c478bd9Sstevel@tonic-gate 		if (cpi->cpi_family == 5 &&
19337c478bd9Sstevel@tonic-gate 		    (cpi->cpi_model == 0 || cpi->cpi_model == 2))
19347c478bd9Sstevel@tonic-gate 			brand = "Rise mP6";
19357c478bd9Sstevel@tonic-gate 		break;
19367c478bd9Sstevel@tonic-gate 	case X86_VENDOR_SiS:
19377c478bd9Sstevel@tonic-gate 		if (cpi->cpi_family == 5 && cpi->cpi_model == 0)
19387c478bd9Sstevel@tonic-gate 			brand = "SiS 55x";
19397c478bd9Sstevel@tonic-gate 		break;
19407c478bd9Sstevel@tonic-gate 	case X86_VENDOR_TM:
19417c478bd9Sstevel@tonic-gate 		if (cpi->cpi_family == 5 && cpi->cpi_model == 4)
19427c478bd9Sstevel@tonic-gate 			brand = "Transmeta Crusoe TM3x00 or TM5x00";
19437c478bd9Sstevel@tonic-gate 		break;
19447c478bd9Sstevel@tonic-gate 	case X86_VENDOR_NSC:
19457c478bd9Sstevel@tonic-gate 	case X86_VENDOR_UMC:
19467c478bd9Sstevel@tonic-gate 	default:
19477c478bd9Sstevel@tonic-gate 		break;
19487c478bd9Sstevel@tonic-gate 	}
19497c478bd9Sstevel@tonic-gate 	if (brand) {
19507c478bd9Sstevel@tonic-gate 		(void) strcpy((char *)cpi->cpi_brandstr, brand);
19517c478bd9Sstevel@tonic-gate 		return;
19527c478bd9Sstevel@tonic-gate 	}
19537c478bd9Sstevel@tonic-gate 
19547c478bd9Sstevel@tonic-gate 	/*
19557c478bd9Sstevel@tonic-gate 	 * If all else fails ...
19567c478bd9Sstevel@tonic-gate 	 */
19577c478bd9Sstevel@tonic-gate 	(void) snprintf(cpi->cpi_brandstr, sizeof (cpi->cpi_brandstr),
19587c478bd9Sstevel@tonic-gate 	    "%s %d.%d.%d", cpi->cpi_vendorstr, cpi->cpi_family,
19597c478bd9Sstevel@tonic-gate 	    cpi->cpi_model, cpi->cpi_step);
19607c478bd9Sstevel@tonic-gate }
19617c478bd9Sstevel@tonic-gate 
19627c478bd9Sstevel@tonic-gate /*
19637c478bd9Sstevel@tonic-gate  * This routine is called just after kernel memory allocation
19647c478bd9Sstevel@tonic-gate  * becomes available on cpu0, and as part of mp_startup() on
19657c478bd9Sstevel@tonic-gate  * the other cpus.
19667c478bd9Sstevel@tonic-gate  *
1967d129bde2Sesaxe  * Fixup the brand string, and collect any information from cpuid
1968d129bde2Sesaxe  * that requires dynamicically allocated storage to represent.
19697c478bd9Sstevel@tonic-gate  */
19707c478bd9Sstevel@tonic-gate /*ARGSUSED*/
19717c478bd9Sstevel@tonic-gate void
19727c478bd9Sstevel@tonic-gate cpuid_pass3(cpu_t *cpu)
19737c478bd9Sstevel@tonic-gate {
1974d129bde2Sesaxe 	int	i, max, shft, level, size;
1975d129bde2Sesaxe 	struct cpuid_regs regs;
1976d129bde2Sesaxe 	struct cpuid_regs *cp;
19777c478bd9Sstevel@tonic-gate 	struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi;
19787c478bd9Sstevel@tonic-gate 
19797c478bd9Sstevel@tonic-gate 	ASSERT(cpi->cpi_pass == 2);
19807c478bd9Sstevel@tonic-gate 
1981d129bde2Sesaxe 	/*
1982d129bde2Sesaxe 	 * Function 4: Deterministic cache parameters
1983d129bde2Sesaxe 	 *
1984d129bde2Sesaxe 	 * Take this opportunity to detect the number of threads
1985d129bde2Sesaxe 	 * sharing the last level cache, and construct a corresponding
1986d129bde2Sesaxe 	 * cache id. The respective cpuid_info members are initialized
1987d129bde2Sesaxe 	 * to the default case of "no last level cache sharing".
1988d129bde2Sesaxe 	 */
1989d129bde2Sesaxe 	cpi->cpi_ncpu_shr_last_cache = 1;
1990d129bde2Sesaxe 	cpi->cpi_last_lvl_cacheid = cpu->cpu_id;
1991d129bde2Sesaxe 
1992d129bde2Sesaxe 	if (cpi->cpi_maxeax >= 4 && cpi->cpi_vendor == X86_VENDOR_Intel) {
1993d129bde2Sesaxe 
1994d129bde2Sesaxe 		/*
1995d129bde2Sesaxe 		 * Find the # of elements (size) returned by fn 4, and along
1996d129bde2Sesaxe 		 * the way detect last level cache sharing details.
1997d129bde2Sesaxe 		 */
1998d129bde2Sesaxe 		bzero(&regs, sizeof (regs));
1999d129bde2Sesaxe 		cp = &regs;
2000d129bde2Sesaxe 		for (i = 0, max = 0; i < CPI_FN4_ECX_MAX; i++) {
2001d129bde2Sesaxe 			cp->cp_eax = 4;
2002d129bde2Sesaxe 			cp->cp_ecx = i;
2003d129bde2Sesaxe 
2004d129bde2Sesaxe 			(void) __cpuid_insn(cp);
2005d129bde2Sesaxe 
2006d129bde2Sesaxe 			if (CPI_CACHE_TYPE(cp) == 0)
2007d129bde2Sesaxe 				break;
2008d129bde2Sesaxe 			level = CPI_CACHE_LVL(cp);
2009d129bde2Sesaxe 			if (level > max) {
2010d129bde2Sesaxe 				max = level;
2011d129bde2Sesaxe 				cpi->cpi_ncpu_shr_last_cache =
2012d129bde2Sesaxe 				    CPI_NTHR_SHR_CACHE(cp) + 1;
2013d129bde2Sesaxe 			}
2014d129bde2Sesaxe 		}
2015d129bde2Sesaxe 		cpi->cpi_std_4_size = size = i;
2016d129bde2Sesaxe 
2017d129bde2Sesaxe 		/*
2018d129bde2Sesaxe 		 * Allocate the cpi_std_4 array. The first element
2019d129bde2Sesaxe 		 * references the regs for fn 4, %ecx == 0, which
2020d129bde2Sesaxe 		 * cpuid_pass2() stashed in cpi->cpi_std[4].
2021d129bde2Sesaxe 		 */
2022d129bde2Sesaxe 		if (size > 0) {
2023d129bde2Sesaxe 			cpi->cpi_std_4 =
2024d129bde2Sesaxe 			    kmem_alloc(size * sizeof (cp), KM_SLEEP);
2025d129bde2Sesaxe 			cpi->cpi_std_4[0] = &cpi->cpi_std[4];
2026d129bde2Sesaxe 
2027d129bde2Sesaxe 			/*
2028d129bde2Sesaxe 			 * Allocate storage to hold the additional regs
2029d129bde2Sesaxe 			 * for function 4, %ecx == 1 .. cpi_std_4_size.
2030d129bde2Sesaxe 			 *
2031d129bde2Sesaxe 			 * The regs for fn 4, %ecx == 0 has already
2032d129bde2Sesaxe 			 * been allocated as indicated above.
2033d129bde2Sesaxe 			 */
2034d129bde2Sesaxe 			for (i = 1; i < size; i++) {
2035d129bde2Sesaxe 				cp = cpi->cpi_std_4[i] =
2036d129bde2Sesaxe 				    kmem_zalloc(sizeof (regs), KM_SLEEP);
2037d129bde2Sesaxe 				cp->cp_eax = 4;
2038d129bde2Sesaxe 				cp->cp_ecx = i;
2039d129bde2Sesaxe 
2040d129bde2Sesaxe 				(void) __cpuid_insn(cp);
2041d129bde2Sesaxe 			}
2042d129bde2Sesaxe 		}
2043d129bde2Sesaxe 		/*
2044d129bde2Sesaxe 		 * Determine the number of bits needed to represent
2045d129bde2Sesaxe 		 * the number of CPUs sharing the last level cache.
2046d129bde2Sesaxe 		 *
2047d129bde2Sesaxe 		 * Shift off that number of bits from the APIC id to
2048d129bde2Sesaxe 		 * derive the cache id.
2049d129bde2Sesaxe 		 */
2050d129bde2Sesaxe 		shft = 0;
2051d129bde2Sesaxe 		for (i = 1; i < cpi->cpi_ncpu_shr_last_cache; i <<= 1)
2052d129bde2Sesaxe 			shft++;
2053*b6917abeSmishra 		cpi->cpi_last_lvl_cacheid = cpi->cpi_apicid >> shft;
2054d129bde2Sesaxe 	}
2055d129bde2Sesaxe 
2056d129bde2Sesaxe 	/*
2057d129bde2Sesaxe 	 * Now fixup the brand string
2058d129bde2Sesaxe 	 */
20597c478bd9Sstevel@tonic-gate 	if ((cpi->cpi_xmaxeax & 0x80000000) == 0) {
20607c478bd9Sstevel@tonic-gate 		fabricate_brandstr(cpi);
2061d129bde2Sesaxe 	} else {
20627c478bd9Sstevel@tonic-gate 
20637c478bd9Sstevel@tonic-gate 		/*
20647c478bd9Sstevel@tonic-gate 		 * If we successfully extracted a brand string from the cpuid
20657c478bd9Sstevel@tonic-gate 		 * instruction, clean it up by removing leading spaces and
20667c478bd9Sstevel@tonic-gate 		 * similar junk.
20677c478bd9Sstevel@tonic-gate 		 */
20687c478bd9Sstevel@tonic-gate 		if (cpi->cpi_brandstr[0]) {
20697c478bd9Sstevel@tonic-gate 			size_t maxlen = sizeof (cpi->cpi_brandstr);
20707c478bd9Sstevel@tonic-gate 			char *src, *dst;
20717c478bd9Sstevel@tonic-gate 
20727c478bd9Sstevel@tonic-gate 			dst = src = (char *)cpi->cpi_brandstr;
20737c478bd9Sstevel@tonic-gate 			src[maxlen - 1] = '\0';
20747c478bd9Sstevel@tonic-gate 			/*
20757c478bd9Sstevel@tonic-gate 			 * strip leading spaces
20767c478bd9Sstevel@tonic-gate 			 */
20777c478bd9Sstevel@tonic-gate 			while (*src == ' ')
20787c478bd9Sstevel@tonic-gate 				src++;
20797c478bd9Sstevel@tonic-gate 			/*
20807c478bd9Sstevel@tonic-gate 			 * Remove any 'Genuine' or "Authentic" prefixes
20817c478bd9Sstevel@tonic-gate 			 */
20827c478bd9Sstevel@tonic-gate 			if (strncmp(src, "Genuine ", 8) == 0)
20837c478bd9Sstevel@tonic-gate 				src += 8;
20847c478bd9Sstevel@tonic-gate 			if (strncmp(src, "Authentic ", 10) == 0)
20857c478bd9Sstevel@tonic-gate 				src += 10;
20867c478bd9Sstevel@tonic-gate 
20877c478bd9Sstevel@tonic-gate 			/*
20887c478bd9Sstevel@tonic-gate 			 * Now do an in-place copy.
20897c478bd9Sstevel@tonic-gate 			 * Map (R) to (r) and (TM) to (tm).
20907c478bd9Sstevel@tonic-gate 			 * The era of teletypes is long gone, and there's
20917c478bd9Sstevel@tonic-gate 			 * -really- no need to shout.
20927c478bd9Sstevel@tonic-gate 			 */
20937c478bd9Sstevel@tonic-gate 			while (*src != '\0') {
20947c478bd9Sstevel@tonic-gate 				if (src[0] == '(') {
20957c478bd9Sstevel@tonic-gate 					if (strncmp(src + 1, "R)", 2) == 0) {
20967c478bd9Sstevel@tonic-gate 						(void) strncpy(dst, "(r)", 3);
20977c478bd9Sstevel@tonic-gate 						src += 3;
20987c478bd9Sstevel@tonic-gate 						dst += 3;
20997c478bd9Sstevel@tonic-gate 						continue;
21007c478bd9Sstevel@tonic-gate 					}
21017c478bd9Sstevel@tonic-gate 					if (strncmp(src + 1, "TM)", 3) == 0) {
21027c478bd9Sstevel@tonic-gate 						(void) strncpy(dst, "(tm)", 4);
21037c478bd9Sstevel@tonic-gate 						src += 4;
21047c478bd9Sstevel@tonic-gate 						dst += 4;
21057c478bd9Sstevel@tonic-gate 						continue;
21067c478bd9Sstevel@tonic-gate 					}
21077c478bd9Sstevel@tonic-gate 				}
21087c478bd9Sstevel@tonic-gate 				*dst++ = *src++;
21097c478bd9Sstevel@tonic-gate 			}
21107c478bd9Sstevel@tonic-gate 			*dst = '\0';
21117c478bd9Sstevel@tonic-gate 
21127c478bd9Sstevel@tonic-gate 			/*
21137c478bd9Sstevel@tonic-gate 			 * Finally, remove any trailing spaces
21147c478bd9Sstevel@tonic-gate 			 */
21157c478bd9Sstevel@tonic-gate 			while (--dst > cpi->cpi_brandstr)
21167c478bd9Sstevel@tonic-gate 				if (*dst == ' ')
21177c478bd9Sstevel@tonic-gate 					*dst = '\0';
21187c478bd9Sstevel@tonic-gate 				else
21197c478bd9Sstevel@tonic-gate 					break;
21207c478bd9Sstevel@tonic-gate 		} else
21217c478bd9Sstevel@tonic-gate 			fabricate_brandstr(cpi);
2122d129bde2Sesaxe 	}
21237c478bd9Sstevel@tonic-gate 	cpi->cpi_pass = 3;
21247c478bd9Sstevel@tonic-gate }
21257c478bd9Sstevel@tonic-gate 
21267c478bd9Sstevel@tonic-gate /*
21277c478bd9Sstevel@tonic-gate  * This routine is called out of bind_hwcap() much later in the life
21287c478bd9Sstevel@tonic-gate  * of the kernel (post_startup()).  The job of this routine is to resolve
21297c478bd9Sstevel@tonic-gate  * the hardware feature support and kernel support for those features into
21307c478bd9Sstevel@tonic-gate  * what we're actually going to tell applications via the aux vector.
21317c478bd9Sstevel@tonic-gate  */
21327c478bd9Sstevel@tonic-gate uint_t
21337c478bd9Sstevel@tonic-gate cpuid_pass4(cpu_t *cpu)
21347c478bd9Sstevel@tonic-gate {
21357c478bd9Sstevel@tonic-gate 	struct cpuid_info *cpi;
21367c478bd9Sstevel@tonic-gate 	uint_t hwcap_flags = 0;
21377c478bd9Sstevel@tonic-gate 
21387c478bd9Sstevel@tonic-gate 	if (cpu == NULL)
21397c478bd9Sstevel@tonic-gate 		cpu = CPU;
21407c478bd9Sstevel@tonic-gate 	cpi = cpu->cpu_m.mcpu_cpi;
21417c478bd9Sstevel@tonic-gate 
21427c478bd9Sstevel@tonic-gate 	ASSERT(cpi->cpi_pass == 3);
21437c478bd9Sstevel@tonic-gate 
21447c478bd9Sstevel@tonic-gate 	if (cpi->cpi_maxeax >= 1) {
21457c478bd9Sstevel@tonic-gate 		uint32_t *edx = &cpi->cpi_support[STD_EDX_FEATURES];
21467c478bd9Sstevel@tonic-gate 		uint32_t *ecx = &cpi->cpi_support[STD_ECX_FEATURES];
21477c478bd9Sstevel@tonic-gate 
21487c478bd9Sstevel@tonic-gate 		*edx = CPI_FEATURES_EDX(cpi);
21497c478bd9Sstevel@tonic-gate 		*ecx = CPI_FEATURES_ECX(cpi);
21507c478bd9Sstevel@tonic-gate 
21517c478bd9Sstevel@tonic-gate 		/*
21527c478bd9Sstevel@tonic-gate 		 * [these require explicit kernel support]
21537c478bd9Sstevel@tonic-gate 		 */
21547c478bd9Sstevel@tonic-gate 		if ((x86_feature & X86_SEP) == 0)
21557c478bd9Sstevel@tonic-gate 			*edx &= ~CPUID_INTC_EDX_SEP;
21567c478bd9Sstevel@tonic-gate 
21577c478bd9Sstevel@tonic-gate 		if ((x86_feature & X86_SSE) == 0)
21587c478bd9Sstevel@tonic-gate 			*edx &= ~(CPUID_INTC_EDX_FXSR|CPUID_INTC_EDX_SSE);
21597c478bd9Sstevel@tonic-gate 		if ((x86_feature & X86_SSE2) == 0)
21607c478bd9Sstevel@tonic-gate 			*edx &= ~CPUID_INTC_EDX_SSE2;
21617c478bd9Sstevel@tonic-gate 
21627c478bd9Sstevel@tonic-gate 		if ((x86_feature & X86_HTT) == 0)
21637c478bd9Sstevel@tonic-gate 			*edx &= ~CPUID_INTC_EDX_HTT;
21647c478bd9Sstevel@tonic-gate 
21657c478bd9Sstevel@tonic-gate 		if ((x86_feature & X86_SSE3) == 0)
21667c478bd9Sstevel@tonic-gate 			*ecx &= ~CPUID_INTC_ECX_SSE3;
21677c478bd9Sstevel@tonic-gate 
2168d0f8ff6eSkk208521 		if (cpi->cpi_vendor == X86_VENDOR_Intel) {
2169d0f8ff6eSkk208521 			if ((x86_feature & X86_SSSE3) == 0)
2170d0f8ff6eSkk208521 				*ecx &= ~CPUID_INTC_ECX_SSSE3;
2171d0f8ff6eSkk208521 			if ((x86_feature & X86_SSE4_1) == 0)
2172d0f8ff6eSkk208521 				*ecx &= ~CPUID_INTC_ECX_SSE4_1;
2173d0f8ff6eSkk208521 			if ((x86_feature & X86_SSE4_2) == 0)
2174d0f8ff6eSkk208521 				*ecx &= ~CPUID_INTC_ECX_SSE4_2;
2175d0f8ff6eSkk208521 		}
2176d0f8ff6eSkk208521 
21777c478bd9Sstevel@tonic-gate 		/*
21787c478bd9Sstevel@tonic-gate 		 * [no explicit support required beyond x87 fp context]
21797c478bd9Sstevel@tonic-gate 		 */
21807c478bd9Sstevel@tonic-gate 		if (!fpu_exists)
21817c478bd9Sstevel@tonic-gate 			*edx &= ~(CPUID_INTC_EDX_FPU | CPUID_INTC_EDX_MMX);
21827c478bd9Sstevel@tonic-gate 
21837c478bd9Sstevel@tonic-gate 		/*
21847c478bd9Sstevel@tonic-gate 		 * Now map the supported feature vector to things that we
21857c478bd9Sstevel@tonic-gate 		 * think userland will care about.
21867c478bd9Sstevel@tonic-gate 		 */
21877c478bd9Sstevel@tonic-gate 		if (*edx & CPUID_INTC_EDX_SEP)
21887c478bd9Sstevel@tonic-gate 			hwcap_flags |= AV_386_SEP;
21897c478bd9Sstevel@tonic-gate 		if (*edx & CPUID_INTC_EDX_SSE)
21907c478bd9Sstevel@tonic-gate 			hwcap_flags |= AV_386_FXSR | AV_386_SSE;
21917c478bd9Sstevel@tonic-gate 		if (*edx & CPUID_INTC_EDX_SSE2)
21927c478bd9Sstevel@tonic-gate 			hwcap_flags |= AV_386_SSE2;
21937c478bd9Sstevel@tonic-gate 		if (*ecx & CPUID_INTC_ECX_SSE3)
21947c478bd9Sstevel@tonic-gate 			hwcap_flags |= AV_386_SSE3;
2195d0f8ff6eSkk208521 		if (cpi->cpi_vendor == X86_VENDOR_Intel) {
2196d0f8ff6eSkk208521 			if (*ecx & CPUID_INTC_ECX_SSSE3)
2197d0f8ff6eSkk208521 				hwcap_flags |= AV_386_SSSE3;
2198d0f8ff6eSkk208521 			if (*ecx & CPUID_INTC_ECX_SSE4_1)
2199d0f8ff6eSkk208521 				hwcap_flags |= AV_386_SSE4_1;
2200d0f8ff6eSkk208521 			if (*ecx & CPUID_INTC_ECX_SSE4_2)
2201d0f8ff6eSkk208521 				hwcap_flags |= AV_386_SSE4_2;
2202d0f8ff6eSkk208521 		}
2203f8801251Skk208521 		if (*ecx & CPUID_INTC_ECX_POPCNT)
2204f8801251Skk208521 			hwcap_flags |= AV_386_POPCNT;
22057c478bd9Sstevel@tonic-gate 		if (*edx & CPUID_INTC_EDX_FPU)
22067c478bd9Sstevel@tonic-gate 			hwcap_flags |= AV_386_FPU;
22077c478bd9Sstevel@tonic-gate 		if (*edx & CPUID_INTC_EDX_MMX)
22087c478bd9Sstevel@tonic-gate 			hwcap_flags |= AV_386_MMX;
22097c478bd9Sstevel@tonic-gate 
22107c478bd9Sstevel@tonic-gate 		if (*edx & CPUID_INTC_EDX_TSC)
22117c478bd9Sstevel@tonic-gate 			hwcap_flags |= AV_386_TSC;
22127c478bd9Sstevel@tonic-gate 		if (*edx & CPUID_INTC_EDX_CX8)
22137c478bd9Sstevel@tonic-gate 			hwcap_flags |= AV_386_CX8;
22147c478bd9Sstevel@tonic-gate 		if (*edx & CPUID_INTC_EDX_CMOV)
22157c478bd9Sstevel@tonic-gate 			hwcap_flags |= AV_386_CMOV;
22167c478bd9Sstevel@tonic-gate 		if (*ecx & CPUID_INTC_ECX_MON)
22177c478bd9Sstevel@tonic-gate 			hwcap_flags |= AV_386_MON;
22187c478bd9Sstevel@tonic-gate 		if (*ecx & CPUID_INTC_ECX_CX16)
22197c478bd9Sstevel@tonic-gate 			hwcap_flags |= AV_386_CX16;
22207c478bd9Sstevel@tonic-gate 	}
22217c478bd9Sstevel@tonic-gate 
22228949bcd6Sandrei 	if (x86_feature & X86_HTT)
22237c478bd9Sstevel@tonic-gate 		hwcap_flags |= AV_386_PAUSE;
22247c478bd9Sstevel@tonic-gate 
22257c478bd9Sstevel@tonic-gate 	if (cpi->cpi_xmaxeax < 0x80000001)
22267c478bd9Sstevel@tonic-gate 		goto pass4_done;
22277c478bd9Sstevel@tonic-gate 
22287c478bd9Sstevel@tonic-gate 	switch (cpi->cpi_vendor) {
22298949bcd6Sandrei 		struct cpuid_regs cp;
2230ae115bc7Smrj 		uint32_t *edx, *ecx;
22317c478bd9Sstevel@tonic-gate 
2232ae115bc7Smrj 	case X86_VENDOR_Intel:
2233ae115bc7Smrj 		/*
2234ae115bc7Smrj 		 * Seems like Intel duplicated what we necessary
2235ae115bc7Smrj 		 * here to make the initial crop of 64-bit OS's work.
2236ae115bc7Smrj 		 * Hopefully, those are the only "extended" bits
2237ae115bc7Smrj 		 * they'll add.
2238ae115bc7Smrj 		 */
2239ae115bc7Smrj 		/*FALLTHROUGH*/
2240ae115bc7Smrj 
22417c478bd9Sstevel@tonic-gate 	case X86_VENDOR_AMD:
22427c478bd9Sstevel@tonic-gate 		edx = &cpi->cpi_support[AMD_EDX_FEATURES];
2243ae115bc7Smrj 		ecx = &cpi->cpi_support[AMD_ECX_FEATURES];
22447c478bd9Sstevel@tonic-gate 
22457c478bd9Sstevel@tonic-gate 		*edx = CPI_FEATURES_XTD_EDX(cpi);
2246ae115bc7Smrj 		*ecx = CPI_FEATURES_XTD_ECX(cpi);
2247ae115bc7Smrj 
2248ae115bc7Smrj 		/*
2249ae115bc7Smrj 		 * [these features require explicit kernel support]
2250ae115bc7Smrj 		 */
2251ae115bc7Smrj 		switch (cpi->cpi_vendor) {
2252ae115bc7Smrj 		case X86_VENDOR_Intel:
2253d36ea5d8Ssudheer 			if ((x86_feature & X86_TSCP) == 0)
2254d36ea5d8Ssudheer 				*edx &= ~CPUID_AMD_EDX_TSCP;
2255ae115bc7Smrj 			break;
2256ae115bc7Smrj 
2257ae115bc7Smrj 		case X86_VENDOR_AMD:
2258ae115bc7Smrj 			if ((x86_feature & X86_TSCP) == 0)
2259ae115bc7Smrj 				*edx &= ~CPUID_AMD_EDX_TSCP;
2260f8801251Skk208521 			if ((x86_feature & X86_SSE4A) == 0)
2261f8801251Skk208521 				*ecx &= ~CPUID_AMD_ECX_SSE4A;
2262ae115bc7Smrj 			break;
2263ae115bc7Smrj 
2264ae115bc7Smrj 		default:
2265ae115bc7Smrj 			break;
2266ae115bc7Smrj 		}
22677c478bd9Sstevel@tonic-gate 
22687c478bd9Sstevel@tonic-gate 		/*
22697c478bd9Sstevel@tonic-gate 		 * [no explicit support required beyond
22707c478bd9Sstevel@tonic-gate 		 * x87 fp context and exception handlers]
22717c478bd9Sstevel@tonic-gate 		 */
22727c478bd9Sstevel@tonic-gate 		if (!fpu_exists)
22737c478bd9Sstevel@tonic-gate 			*edx &= ~(CPUID_AMD_EDX_MMXamd |
22747c478bd9Sstevel@tonic-gate 			    CPUID_AMD_EDX_3DNow | CPUID_AMD_EDX_3DNowx);
22757c478bd9Sstevel@tonic-gate 
22767c478bd9Sstevel@tonic-gate 		if ((x86_feature & X86_NX) == 0)
22777c478bd9Sstevel@tonic-gate 			*edx &= ~CPUID_AMD_EDX_NX;
2278ae115bc7Smrj #if !defined(__amd64)
22797c478bd9Sstevel@tonic-gate 		*edx &= ~CPUID_AMD_EDX_LM;
22807c478bd9Sstevel@tonic-gate #endif
22817c478bd9Sstevel@tonic-gate 		/*
22827c478bd9Sstevel@tonic-gate 		 * Now map the supported feature vector to
22837c478bd9Sstevel@tonic-gate 		 * things that we think userland will care about.
22847c478bd9Sstevel@tonic-gate 		 */
2285ae115bc7Smrj #if defined(__amd64)
22867c478bd9Sstevel@tonic-gate 		if (*edx & CPUID_AMD_EDX_SYSC)
22877c478bd9Sstevel@tonic-gate 			hwcap_flags |= AV_386_AMD_SYSC;
2288ae115bc7Smrj #endif
22897c478bd9Sstevel@tonic-gate 		if (*edx & CPUID_AMD_EDX_MMXamd)
22907c478bd9Sstevel@tonic-gate 			hwcap_flags |= AV_386_AMD_MMX;
22917c478bd9Sstevel@tonic-gate 		if (*edx & CPUID_AMD_EDX_3DNow)
22927c478bd9Sstevel@tonic-gate 			hwcap_flags |= AV_386_AMD_3DNow;
22937c478bd9Sstevel@tonic-gate 		if (*edx & CPUID_AMD_EDX_3DNowx)
22947c478bd9Sstevel@tonic-gate 			hwcap_flags |= AV_386_AMD_3DNowx;
2295ae115bc7Smrj 
2296ae115bc7Smrj 		switch (cpi->cpi_vendor) {
2297ae115bc7Smrj 		case X86_VENDOR_AMD:
2298ae115bc7Smrj 			if (*edx & CPUID_AMD_EDX_TSCP)
2299ae115bc7Smrj 				hwcap_flags |= AV_386_TSCP;
2300ae115bc7Smrj 			if (*ecx & CPUID_AMD_ECX_AHF64)
2301ae115bc7Smrj 				hwcap_flags |= AV_386_AHF;
2302f8801251Skk208521 			if (*ecx & CPUID_AMD_ECX_SSE4A)
2303f8801251Skk208521 				hwcap_flags |= AV_386_AMD_SSE4A;
2304f8801251Skk208521 			if (*ecx & CPUID_AMD_ECX_LZCNT)
2305f8801251Skk208521 				hwcap_flags |= AV_386_AMD_LZCNT;
2306ae115bc7Smrj 			break;
2307ae115bc7Smrj 
2308ae115bc7Smrj 		case X86_VENDOR_Intel:
2309d36ea5d8Ssudheer 			if (*edx & CPUID_AMD_EDX_TSCP)
2310d36ea5d8Ssudheer 				hwcap_flags |= AV_386_TSCP;
2311ae115bc7Smrj 			/*
2312ae115bc7Smrj 			 * Aarrgh.
2313ae115bc7Smrj 			 * Intel uses a different bit in the same word.
2314ae115bc7Smrj 			 */
2315ae115bc7Smrj 			if (*ecx & CPUID_INTC_ECX_AHF64)
2316ae115bc7Smrj 				hwcap_flags |= AV_386_AHF;
2317ae115bc7Smrj 			break;
2318ae115bc7Smrj 
2319ae115bc7Smrj 		default:
2320ae115bc7Smrj 			break;
2321ae115bc7Smrj 		}
23227c478bd9Sstevel@tonic-gate 		break;
23237c478bd9Sstevel@tonic-gate 
23247c478bd9Sstevel@tonic-gate 	case X86_VENDOR_TM:
23258949bcd6Sandrei 		cp.cp_eax = 0x80860001;
23268949bcd6Sandrei 		(void) __cpuid_insn(&cp);
23278949bcd6Sandrei 		cpi->cpi_support[TM_EDX_FEATURES] = cp.cp_edx;
23287c478bd9Sstevel@tonic-gate 		break;
23297c478bd9Sstevel@tonic-gate 
23307c478bd9Sstevel@tonic-gate 	default:
23317c478bd9Sstevel@tonic-gate 		break;
23327c478bd9Sstevel@tonic-gate 	}
23337c478bd9Sstevel@tonic-gate 
23347c478bd9Sstevel@tonic-gate pass4_done:
23357c478bd9Sstevel@tonic-gate 	cpi->cpi_pass = 4;
23367c478bd9Sstevel@tonic-gate 	return (hwcap_flags);
23377c478bd9Sstevel@tonic-gate }
23387c478bd9Sstevel@tonic-gate 
23397c478bd9Sstevel@tonic-gate 
23407c478bd9Sstevel@tonic-gate /*
23417c478bd9Sstevel@tonic-gate  * Simulate the cpuid instruction using the data we previously
23427c478bd9Sstevel@tonic-gate  * captured about this CPU.  We try our best to return the truth
23437c478bd9Sstevel@tonic-gate  * about the hardware, independently of kernel support.
23447c478bd9Sstevel@tonic-gate  */
23457c478bd9Sstevel@tonic-gate uint32_t
23468949bcd6Sandrei cpuid_insn(cpu_t *cpu, struct cpuid_regs *cp)
23477c478bd9Sstevel@tonic-gate {
23487c478bd9Sstevel@tonic-gate 	struct cpuid_info *cpi;
23498949bcd6Sandrei 	struct cpuid_regs *xcp;
23507c478bd9Sstevel@tonic-gate 
23517c478bd9Sstevel@tonic-gate 	if (cpu == NULL)
23527c478bd9Sstevel@tonic-gate 		cpu = CPU;
23537c478bd9Sstevel@tonic-gate 	cpi = cpu->cpu_m.mcpu_cpi;
23547c478bd9Sstevel@tonic-gate 
23557c478bd9Sstevel@tonic-gate 	ASSERT(cpuid_checkpass(cpu, 3));
23567c478bd9Sstevel@tonic-gate 
23577c478bd9Sstevel@tonic-gate 	/*
23587c478bd9Sstevel@tonic-gate 	 * CPUID data is cached in two separate places: cpi_std for standard
23597c478bd9Sstevel@tonic-gate 	 * CPUID functions, and cpi_extd for extended CPUID functions.
23607c478bd9Sstevel@tonic-gate 	 */
23618949bcd6Sandrei 	if (cp->cp_eax <= cpi->cpi_maxeax && cp->cp_eax < NMAX_CPI_STD)
23628949bcd6Sandrei 		xcp = &cpi->cpi_std[cp->cp_eax];
23638949bcd6Sandrei 	else if (cp->cp_eax >= 0x80000000 && cp->cp_eax <= cpi->cpi_xmaxeax &&
23648949bcd6Sandrei 	    cp->cp_eax < 0x80000000 + NMAX_CPI_EXTD)
23658949bcd6Sandrei 		xcp = &cpi->cpi_extd[cp->cp_eax - 0x80000000];
23667c478bd9Sstevel@tonic-gate 	else
23677c478bd9Sstevel@tonic-gate 		/*
23687c478bd9Sstevel@tonic-gate 		 * The caller is asking for data from an input parameter which
23697c478bd9Sstevel@tonic-gate 		 * the kernel has not cached.  In this case we go fetch from
23707c478bd9Sstevel@tonic-gate 		 * the hardware and return the data directly to the user.
23717c478bd9Sstevel@tonic-gate 		 */
23728949bcd6Sandrei 		return (__cpuid_insn(cp));
23738949bcd6Sandrei 
23748949bcd6Sandrei 	cp->cp_eax = xcp->cp_eax;
23758949bcd6Sandrei 	cp->cp_ebx = xcp->cp_ebx;
23768949bcd6Sandrei 	cp->cp_ecx = xcp->cp_ecx;
23778949bcd6Sandrei 	cp->cp_edx = xcp->cp_edx;
23787c478bd9Sstevel@tonic-gate 	return (cp->cp_eax);
23797c478bd9Sstevel@tonic-gate }
23807c478bd9Sstevel@tonic-gate 
23817c478bd9Sstevel@tonic-gate int
23827c478bd9Sstevel@tonic-gate cpuid_checkpass(cpu_t *cpu, int pass)
23837c478bd9Sstevel@tonic-gate {
23847c478bd9Sstevel@tonic-gate 	return (cpu != NULL && cpu->cpu_m.mcpu_cpi != NULL &&
23857c478bd9Sstevel@tonic-gate 	    cpu->cpu_m.mcpu_cpi->cpi_pass >= pass);
23867c478bd9Sstevel@tonic-gate }
23877c478bd9Sstevel@tonic-gate 
23887c478bd9Sstevel@tonic-gate int
23897c478bd9Sstevel@tonic-gate cpuid_getbrandstr(cpu_t *cpu, char *s, size_t n)
23907c478bd9Sstevel@tonic-gate {
23917c478bd9Sstevel@tonic-gate 	ASSERT(cpuid_checkpass(cpu, 3));
23927c478bd9Sstevel@tonic-gate 
23937c478bd9Sstevel@tonic-gate 	return (snprintf(s, n, "%s", cpu->cpu_m.mcpu_cpi->cpi_brandstr));
23947c478bd9Sstevel@tonic-gate }
23957c478bd9Sstevel@tonic-gate 
23967c478bd9Sstevel@tonic-gate int
23978949bcd6Sandrei cpuid_is_cmt(cpu_t *cpu)
23987c478bd9Sstevel@tonic-gate {
23997c478bd9Sstevel@tonic-gate 	if (cpu == NULL)
24007c478bd9Sstevel@tonic-gate 		cpu = CPU;
24017c478bd9Sstevel@tonic-gate 
24027c478bd9Sstevel@tonic-gate 	ASSERT(cpuid_checkpass(cpu, 1));
24037c478bd9Sstevel@tonic-gate 
24047c478bd9Sstevel@tonic-gate 	return (cpu->cpu_m.mcpu_cpi->cpi_chipid >= 0);
24057c478bd9Sstevel@tonic-gate }
24067c478bd9Sstevel@tonic-gate 
24077c478bd9Sstevel@tonic-gate /*
24087c478bd9Sstevel@tonic-gate  * AMD and Intel both implement the 64-bit variant of the syscall
24097c478bd9Sstevel@tonic-gate  * instruction (syscallq), so if there's -any- support for syscall,
24107c478bd9Sstevel@tonic-gate  * cpuid currently says "yes, we support this".
24117c478bd9Sstevel@tonic-gate  *
24127c478bd9Sstevel@tonic-gate  * However, Intel decided to -not- implement the 32-bit variant of the
24137c478bd9Sstevel@tonic-gate  * syscall instruction, so we provide a predicate to allow our caller
24147c478bd9Sstevel@tonic-gate  * to test that subtlety here.
2415843e1988Sjohnlev  *
2416843e1988Sjohnlev  * XXPV	Currently, 32-bit syscall instructions don't work via the hypervisor,
2417843e1988Sjohnlev  *	even in the case where the hardware would in fact support it.
24187c478bd9Sstevel@tonic-gate  */
24197c478bd9Sstevel@tonic-gate /*ARGSUSED*/
24207c478bd9Sstevel@tonic-gate int
24217c478bd9Sstevel@tonic-gate cpuid_syscall32_insn(cpu_t *cpu)
24227c478bd9Sstevel@tonic-gate {
24237c478bd9Sstevel@tonic-gate 	ASSERT(cpuid_checkpass((cpu == NULL ? CPU : cpu), 1));
24247c478bd9Sstevel@tonic-gate 
2425843e1988Sjohnlev #if !defined(__xpv)
2426ae115bc7Smrj 	if (cpu == NULL)
2427ae115bc7Smrj 		cpu = CPU;
2428ae115bc7Smrj 
2429ae115bc7Smrj 	/*CSTYLED*/
2430ae115bc7Smrj 	{
2431ae115bc7Smrj 		struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi;
2432ae115bc7Smrj 
2433ae115bc7Smrj 		if (cpi->cpi_vendor == X86_VENDOR_AMD &&
2434ae115bc7Smrj 		    cpi->cpi_xmaxeax >= 0x80000001 &&
2435ae115bc7Smrj 		    (CPI_FEATURES_XTD_EDX(cpi) & CPUID_AMD_EDX_SYSC))
2436ae115bc7Smrj 			return (1);
2437ae115bc7Smrj 	}
2438843e1988Sjohnlev #endif
24397c478bd9Sstevel@tonic-gate 	return (0);
24407c478bd9Sstevel@tonic-gate }
24417c478bd9Sstevel@tonic-gate 
24427c478bd9Sstevel@tonic-gate int
24437c478bd9Sstevel@tonic-gate cpuid_getidstr(cpu_t *cpu, char *s, size_t n)
24447c478bd9Sstevel@tonic-gate {
24457c478bd9Sstevel@tonic-gate 	struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi;
24467c478bd9Sstevel@tonic-gate 
24477c478bd9Sstevel@tonic-gate 	static const char fmt[] =
2448ecfa43a5Sdmick 	    "x86 (%s %X family %d model %d step %d clock %d MHz)";
24497c478bd9Sstevel@tonic-gate 	static const char fmt_ht[] =
2450ecfa43a5Sdmick 	    "x86 (chipid 0x%x %s %X family %d model %d step %d clock %d MHz)";
24517c478bd9Sstevel@tonic-gate 
24527c478bd9Sstevel@tonic-gate 	ASSERT(cpuid_checkpass(cpu, 1));
24537c478bd9Sstevel@tonic-gate 
24548949bcd6Sandrei 	if (cpuid_is_cmt(cpu))
24557c478bd9Sstevel@tonic-gate 		return (snprintf(s, n, fmt_ht, cpi->cpi_chipid,
2456ecfa43a5Sdmick 		    cpi->cpi_vendorstr, cpi->cpi_std[1].cp_eax,
2457ecfa43a5Sdmick 		    cpi->cpi_family, cpi->cpi_model,
24587c478bd9Sstevel@tonic-gate 		    cpi->cpi_step, cpu->cpu_type_info.pi_clock));
24597c478bd9Sstevel@tonic-gate 	return (snprintf(s, n, fmt,
2460ecfa43a5Sdmick 	    cpi->cpi_vendorstr, cpi->cpi_std[1].cp_eax,
2461ecfa43a5Sdmick 	    cpi->cpi_family, cpi->cpi_model,
24627c478bd9Sstevel@tonic-gate 	    cpi->cpi_step, cpu->cpu_type_info.pi_clock));
24637c478bd9Sstevel@tonic-gate }
24647c478bd9Sstevel@tonic-gate 
24657c478bd9Sstevel@tonic-gate const char *
24667c478bd9Sstevel@tonic-gate cpuid_getvendorstr(cpu_t *cpu)
24677c478bd9Sstevel@tonic-gate {
24687c478bd9Sstevel@tonic-gate 	ASSERT(cpuid_checkpass(cpu, 1));
24697c478bd9Sstevel@tonic-gate 	return ((const char *)cpu->cpu_m.mcpu_cpi->cpi_vendorstr);
24707c478bd9Sstevel@tonic-gate }
24717c478bd9Sstevel@tonic-gate 
24727c478bd9Sstevel@tonic-gate uint_t
24737c478bd9Sstevel@tonic-gate cpuid_getvendor(cpu_t *cpu)
24747c478bd9Sstevel@tonic-gate {
24757c478bd9Sstevel@tonic-gate 	ASSERT(cpuid_checkpass(cpu, 1));
24767c478bd9Sstevel@tonic-gate 	return (cpu->cpu_m.mcpu_cpi->cpi_vendor);
24777c478bd9Sstevel@tonic-gate }
24787c478bd9Sstevel@tonic-gate 
24797c478bd9Sstevel@tonic-gate uint_t
24807c478bd9Sstevel@tonic-gate cpuid_getfamily(cpu_t *cpu)
24817c478bd9Sstevel@tonic-gate {
24827c478bd9Sstevel@tonic-gate 	ASSERT(cpuid_checkpass(cpu, 1));
24837c478bd9Sstevel@tonic-gate 	return (cpu->cpu_m.mcpu_cpi->cpi_family);
24847c478bd9Sstevel@tonic-gate }
24857c478bd9Sstevel@tonic-gate 
24867c478bd9Sstevel@tonic-gate uint_t
24877c478bd9Sstevel@tonic-gate cpuid_getmodel(cpu_t *cpu)
24887c478bd9Sstevel@tonic-gate {
24897c478bd9Sstevel@tonic-gate 	ASSERT(cpuid_checkpass(cpu, 1));
24907c478bd9Sstevel@tonic-gate 	return (cpu->cpu_m.mcpu_cpi->cpi_model);
24917c478bd9Sstevel@tonic-gate }
24927c478bd9Sstevel@tonic-gate 
24937c478bd9Sstevel@tonic-gate uint_t
24947c478bd9Sstevel@tonic-gate cpuid_get_ncpu_per_chip(cpu_t *cpu)
24957c478bd9Sstevel@tonic-gate {
24967c478bd9Sstevel@tonic-gate 	ASSERT(cpuid_checkpass(cpu, 1));
24977c478bd9Sstevel@tonic-gate 	return (cpu->cpu_m.mcpu_cpi->cpi_ncpu_per_chip);
24987c478bd9Sstevel@tonic-gate }
24997c478bd9Sstevel@tonic-gate 
25007c478bd9Sstevel@tonic-gate uint_t
25018949bcd6Sandrei cpuid_get_ncore_per_chip(cpu_t *cpu)
25028949bcd6Sandrei {
25038949bcd6Sandrei 	ASSERT(cpuid_checkpass(cpu, 1));
25048949bcd6Sandrei 	return (cpu->cpu_m.mcpu_cpi->cpi_ncore_per_chip);
25058949bcd6Sandrei }
25068949bcd6Sandrei 
25078949bcd6Sandrei uint_t
2508d129bde2Sesaxe cpuid_get_ncpu_sharing_last_cache(cpu_t *cpu)
2509d129bde2Sesaxe {
2510d129bde2Sesaxe 	ASSERT(cpuid_checkpass(cpu, 2));
2511d129bde2Sesaxe 	return (cpu->cpu_m.mcpu_cpi->cpi_ncpu_shr_last_cache);
2512d129bde2Sesaxe }
2513d129bde2Sesaxe 
2514d129bde2Sesaxe id_t
2515d129bde2Sesaxe cpuid_get_last_lvl_cacheid(cpu_t *cpu)
2516d129bde2Sesaxe {
2517d129bde2Sesaxe 	ASSERT(cpuid_checkpass(cpu, 2));
2518d129bde2Sesaxe 	return (cpu->cpu_m.mcpu_cpi->cpi_last_lvl_cacheid);
2519d129bde2Sesaxe }
2520d129bde2Sesaxe 
2521d129bde2Sesaxe uint_t
25227c478bd9Sstevel@tonic-gate cpuid_getstep(cpu_t *cpu)
25237c478bd9Sstevel@tonic-gate {
25247c478bd9Sstevel@tonic-gate 	ASSERT(cpuid_checkpass(cpu, 1));
25257c478bd9Sstevel@tonic-gate 	return (cpu->cpu_m.mcpu_cpi->cpi_step);
25267c478bd9Sstevel@tonic-gate }
25277c478bd9Sstevel@tonic-gate 
25282449e17fSsherrym uint_t
25292449e17fSsherrym cpuid_getsig(struct cpu *cpu)
25302449e17fSsherrym {
25312449e17fSsherrym 	ASSERT(cpuid_checkpass(cpu, 1));
25322449e17fSsherrym 	return (cpu->cpu_m.mcpu_cpi->cpi_std[1].cp_eax);
25332449e17fSsherrym }
25342449e17fSsherrym 
25358a40a695Sgavinm uint32_t
25368a40a695Sgavinm cpuid_getchiprev(struct cpu *cpu)
25378a40a695Sgavinm {
25388a40a695Sgavinm 	ASSERT(cpuid_checkpass(cpu, 1));
25398a40a695Sgavinm 	return (cpu->cpu_m.mcpu_cpi->cpi_chiprev);
25408a40a695Sgavinm }
25418a40a695Sgavinm 
25428a40a695Sgavinm const char *
25438a40a695Sgavinm cpuid_getchiprevstr(struct cpu *cpu)
25448a40a695Sgavinm {
25458a40a695Sgavinm 	ASSERT(cpuid_checkpass(cpu, 1));
25468a40a695Sgavinm 	return (cpu->cpu_m.mcpu_cpi->cpi_chiprevstr);
25478a40a695Sgavinm }
25488a40a695Sgavinm 
25498a40a695Sgavinm uint32_t
25508a40a695Sgavinm cpuid_getsockettype(struct cpu *cpu)
25518a40a695Sgavinm {
25528a40a695Sgavinm 	ASSERT(cpuid_checkpass(cpu, 1));
25538a40a695Sgavinm 	return (cpu->cpu_m.mcpu_cpi->cpi_socket);
25548a40a695Sgavinm }
25558a40a695Sgavinm 
2556fb2f18f8Sesaxe int
2557fb2f18f8Sesaxe cpuid_get_chipid(cpu_t *cpu)
25587c478bd9Sstevel@tonic-gate {
25597c478bd9Sstevel@tonic-gate 	ASSERT(cpuid_checkpass(cpu, 1));
25607c478bd9Sstevel@tonic-gate 
25618949bcd6Sandrei 	if (cpuid_is_cmt(cpu))
25627c478bd9Sstevel@tonic-gate 		return (cpu->cpu_m.mcpu_cpi->cpi_chipid);
25637c478bd9Sstevel@tonic-gate 	return (cpu->cpu_id);
25647c478bd9Sstevel@tonic-gate }
25657c478bd9Sstevel@tonic-gate 
25668949bcd6Sandrei id_t
2567fb2f18f8Sesaxe cpuid_get_coreid(cpu_t *cpu)
25688949bcd6Sandrei {
25698949bcd6Sandrei 	ASSERT(cpuid_checkpass(cpu, 1));
25708949bcd6Sandrei 	return (cpu->cpu_m.mcpu_cpi->cpi_coreid);
25718949bcd6Sandrei }
25728949bcd6Sandrei 
25737c478bd9Sstevel@tonic-gate int
257410569901Sgavinm cpuid_get_pkgcoreid(cpu_t *cpu)
257510569901Sgavinm {
257610569901Sgavinm 	ASSERT(cpuid_checkpass(cpu, 1));
257710569901Sgavinm 	return (cpu->cpu_m.mcpu_cpi->cpi_pkgcoreid);
257810569901Sgavinm }
257910569901Sgavinm 
258010569901Sgavinm int
2581fb2f18f8Sesaxe cpuid_get_clogid(cpu_t *cpu)
25827c478bd9Sstevel@tonic-gate {
25837c478bd9Sstevel@tonic-gate 	ASSERT(cpuid_checkpass(cpu, 1));
25847c478bd9Sstevel@tonic-gate 	return (cpu->cpu_m.mcpu_cpi->cpi_clogid);
25857c478bd9Sstevel@tonic-gate }
25867c478bd9Sstevel@tonic-gate 
25877c478bd9Sstevel@tonic-gate void
25887c478bd9Sstevel@tonic-gate cpuid_get_addrsize(cpu_t *cpu, uint_t *pabits, uint_t *vabits)
25897c478bd9Sstevel@tonic-gate {
25907c478bd9Sstevel@tonic-gate 	struct cpuid_info *cpi;
25917c478bd9Sstevel@tonic-gate 
25927c478bd9Sstevel@tonic-gate 	if (cpu == NULL)
25937c478bd9Sstevel@tonic-gate 		cpu = CPU;
25947c478bd9Sstevel@tonic-gate 	cpi = cpu->cpu_m.mcpu_cpi;
25957c478bd9Sstevel@tonic-gate 
25967c478bd9Sstevel@tonic-gate 	ASSERT(cpuid_checkpass(cpu, 1));
25977c478bd9Sstevel@tonic-gate 
25987c478bd9Sstevel@tonic-gate 	if (pabits)
25997c478bd9Sstevel@tonic-gate 		*pabits = cpi->cpi_pabits;
26007c478bd9Sstevel@tonic-gate 	if (vabits)
26017c478bd9Sstevel@tonic-gate 		*vabits = cpi->cpi_vabits;
26027c478bd9Sstevel@tonic-gate }
26037c478bd9Sstevel@tonic-gate 
26047c478bd9Sstevel@tonic-gate /*
26057c478bd9Sstevel@tonic-gate  * Returns the number of data TLB entries for a corresponding
26067c478bd9Sstevel@tonic-gate  * pagesize.  If it can't be computed, or isn't known, the
26077c478bd9Sstevel@tonic-gate  * routine returns zero.  If you ask about an architecturally
26087c478bd9Sstevel@tonic-gate  * impossible pagesize, the routine will panic (so that the
26097c478bd9Sstevel@tonic-gate  * hat implementor knows that things are inconsistent.)
26107c478bd9Sstevel@tonic-gate  */
26117c478bd9Sstevel@tonic-gate uint_t
26127c478bd9Sstevel@tonic-gate cpuid_get_dtlb_nent(cpu_t *cpu, size_t pagesize)
26137c478bd9Sstevel@tonic-gate {
26147c478bd9Sstevel@tonic-gate 	struct cpuid_info *cpi;
26157c478bd9Sstevel@tonic-gate 	uint_t dtlb_nent = 0;
26167c478bd9Sstevel@tonic-gate 
26177c478bd9Sstevel@tonic-gate 	if (cpu == NULL)
26187c478bd9Sstevel@tonic-gate 		cpu = CPU;
26197c478bd9Sstevel@tonic-gate 	cpi = cpu->cpu_m.mcpu_cpi;
26207c478bd9Sstevel@tonic-gate 
26217c478bd9Sstevel@tonic-gate 	ASSERT(cpuid_checkpass(cpu, 1));
26227c478bd9Sstevel@tonic-gate 
26237c478bd9Sstevel@tonic-gate 	/*
26247c478bd9Sstevel@tonic-gate 	 * Check the L2 TLB info
26257c478bd9Sstevel@tonic-gate 	 */
26267c478bd9Sstevel@tonic-gate 	if (cpi->cpi_xmaxeax >= 0x80000006) {
26278949bcd6Sandrei 		struct cpuid_regs *cp = &cpi->cpi_extd[6];
26287c478bd9Sstevel@tonic-gate 
26297c478bd9Sstevel@tonic-gate 		switch (pagesize) {
26307c478bd9Sstevel@tonic-gate 
26317c478bd9Sstevel@tonic-gate 		case 4 * 1024:
26327c478bd9Sstevel@tonic-gate 			/*
26337c478bd9Sstevel@tonic-gate 			 * All zero in the top 16 bits of the register
26347c478bd9Sstevel@tonic-gate 			 * indicates a unified TLB. Size is in low 16 bits.
26357c478bd9Sstevel@tonic-gate 			 */
26367c478bd9Sstevel@tonic-gate 			if ((cp->cp_ebx & 0xffff0000) == 0)
26377c478bd9Sstevel@tonic-gate 				dtlb_nent = cp->cp_ebx & 0x0000ffff;
26387c478bd9Sstevel@tonic-gate 			else
26397c478bd9Sstevel@tonic-gate 				dtlb_nent = BITX(cp->cp_ebx, 27, 16);
26407c478bd9Sstevel@tonic-gate 			break;
26417c478bd9Sstevel@tonic-gate 
26427c478bd9Sstevel@tonic-gate 		case 2 * 1024 * 1024:
26437c478bd9Sstevel@tonic-gate 			if ((cp->cp_eax & 0xffff0000) == 0)
26447c478bd9Sstevel@tonic-gate 				dtlb_nent = cp->cp_eax & 0x0000ffff;
26457c478bd9Sstevel@tonic-gate 			else
26467c478bd9Sstevel@tonic-gate 				dtlb_nent = BITX(cp->cp_eax, 27, 16);
26477c478bd9Sstevel@tonic-gate 			break;
26487c478bd9Sstevel@tonic-gate 
26497c478bd9Sstevel@tonic-gate 		default:
26507c478bd9Sstevel@tonic-gate 			panic("unknown L2 pagesize");
26517c478bd9Sstevel@tonic-gate 			/*NOTREACHED*/
26527c478bd9Sstevel@tonic-gate 		}
26537c478bd9Sstevel@tonic-gate 	}
26547c478bd9Sstevel@tonic-gate 
26557c478bd9Sstevel@tonic-gate 	if (dtlb_nent != 0)
26567c478bd9Sstevel@tonic-gate 		return (dtlb_nent);
26577c478bd9Sstevel@tonic-gate 
26587c478bd9Sstevel@tonic-gate 	/*
26597c478bd9Sstevel@tonic-gate 	 * No L2 TLB support for this size, try L1.
26607c478bd9Sstevel@tonic-gate 	 */
26617c478bd9Sstevel@tonic-gate 	if (cpi->cpi_xmaxeax >= 0x80000005) {
26628949bcd6Sandrei 		struct cpuid_regs *cp = &cpi->cpi_extd[5];
26637c478bd9Sstevel@tonic-gate 
26647c478bd9Sstevel@tonic-gate 		switch (pagesize) {
26657c478bd9Sstevel@tonic-gate 		case 4 * 1024:
26667c478bd9Sstevel@tonic-gate 			dtlb_nent = BITX(cp->cp_ebx, 23, 16);
26677c478bd9Sstevel@tonic-gate 			break;
26687c478bd9Sstevel@tonic-gate 		case 2 * 1024 * 1024:
26697c478bd9Sstevel@tonic-gate 			dtlb_nent = BITX(cp->cp_eax, 23, 16);
26707c478bd9Sstevel@tonic-gate 			break;
26717c478bd9Sstevel@tonic-gate 		default:
26727c478bd9Sstevel@tonic-gate 			panic("unknown L1 d-TLB pagesize");
26737c478bd9Sstevel@tonic-gate 			/*NOTREACHED*/
26747c478bd9Sstevel@tonic-gate 		}
26757c478bd9Sstevel@tonic-gate 	}
26767c478bd9Sstevel@tonic-gate 
26777c478bd9Sstevel@tonic-gate 	return (dtlb_nent);
26787c478bd9Sstevel@tonic-gate }
26797c478bd9Sstevel@tonic-gate 
26807c478bd9Sstevel@tonic-gate /*
26817c478bd9Sstevel@tonic-gate  * Return 0 if the erratum is not present or not applicable, positive
26827c478bd9Sstevel@tonic-gate  * if it is, and negative if the status of the erratum is unknown.
26837c478bd9Sstevel@tonic-gate  *
26847c478bd9Sstevel@tonic-gate  * See "Revision Guide for AMD Athlon(tm) 64 and AMD Opteron(tm)
26852201b277Skucharsk  * Processors" #25759, Rev 3.57, August 2005
26867c478bd9Sstevel@tonic-gate  */
26877c478bd9Sstevel@tonic-gate int
26887c478bd9Sstevel@tonic-gate cpuid_opteron_erratum(cpu_t *cpu, uint_t erratum)
26897c478bd9Sstevel@tonic-gate {
26907c478bd9Sstevel@tonic-gate 	struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi;
26918949bcd6Sandrei 	uint_t eax;
26927c478bd9Sstevel@tonic-gate 
2693ea99987eSsethg 	/*
2694ea99987eSsethg 	 * Bail out if this CPU isn't an AMD CPU, or if it's
2695ea99987eSsethg 	 * a legacy (32-bit) AMD CPU.
2696ea99987eSsethg 	 */
2697ea99987eSsethg 	if (cpi->cpi_vendor != X86_VENDOR_AMD ||
2698875b116eSkchow 	    cpi->cpi_family == 4 || cpi->cpi_family == 5 ||
2699875b116eSkchow 	    cpi->cpi_family == 6)
27008a40a695Sgavinm 
27017c478bd9Sstevel@tonic-gate 		return (0);
27027c478bd9Sstevel@tonic-gate 
27037c478bd9Sstevel@tonic-gate 	eax = cpi->cpi_std[1].cp_eax;
27047c478bd9Sstevel@tonic-gate 
27057c478bd9Sstevel@tonic-gate #define	SH_B0(eax)	(eax == 0xf40 || eax == 0xf50)
27067c478bd9Sstevel@tonic-gate #define	SH_B3(eax) 	(eax == 0xf51)
2707ee88d2b9Skchow #define	B(eax)		(SH_B0(eax) || SH_B3(eax))
27087c478bd9Sstevel@tonic-gate 
27097c478bd9Sstevel@tonic-gate #define	SH_C0(eax)	(eax == 0xf48 || eax == 0xf58)
27107c478bd9Sstevel@tonic-gate 
27117c478bd9Sstevel@tonic-gate #define	SH_CG(eax)	(eax == 0xf4a || eax == 0xf5a || eax == 0xf7a)
27127c478bd9Sstevel@tonic-gate #define	DH_CG(eax)	(eax == 0xfc0 || eax == 0xfe0 || eax == 0xff0)
27137c478bd9Sstevel@tonic-gate #define	CH_CG(eax)	(eax == 0xf82 || eax == 0xfb2)
2714ee88d2b9Skchow #define	CG(eax)		(SH_CG(eax) || DH_CG(eax) || CH_CG(eax))
27157c478bd9Sstevel@tonic-gate 
27167c478bd9Sstevel@tonic-gate #define	SH_D0(eax)	(eax == 0x10f40 || eax == 0x10f50 || eax == 0x10f70)
27177c478bd9Sstevel@tonic-gate #define	DH_D0(eax)	(eax == 0x10fc0 || eax == 0x10ff0)
27187c478bd9Sstevel@tonic-gate #define	CH_D0(eax)	(eax == 0x10f80 || eax == 0x10fb0)
2719ee88d2b9Skchow #define	D0(eax)		(SH_D0(eax) || DH_D0(eax) || CH_D0(eax))
27207c478bd9Sstevel@tonic-gate 
27217c478bd9Sstevel@tonic-gate #define	SH_E0(eax)	(eax == 0x20f50 || eax == 0x20f40 || eax == 0x20f70)
27227c478bd9Sstevel@tonic-gate #define	JH_E1(eax)	(eax == 0x20f10)	/* JH8_E0 had 0x20f30 */
27237c478bd9Sstevel@tonic-gate #define	DH_E3(eax)	(eax == 0x20fc0 || eax == 0x20ff0)
27247c478bd9Sstevel@tonic-gate #define	SH_E4(eax)	(eax == 0x20f51 || eax == 0x20f71)
27257c478bd9Sstevel@tonic-gate #define	BH_E4(eax)	(eax == 0x20fb1)
27267c478bd9Sstevel@tonic-gate #define	SH_E5(eax)	(eax == 0x20f42)
27277c478bd9Sstevel@tonic-gate #define	DH_E6(eax)	(eax == 0x20ff2 || eax == 0x20fc2)
27287c478bd9Sstevel@tonic-gate #define	JH_E6(eax)	(eax == 0x20f12 || eax == 0x20f32)
2729ee88d2b9Skchow #define	EX(eax)		(SH_E0(eax) || JH_E1(eax) || DH_E3(eax) || \
2730ee88d2b9Skchow 			    SH_E4(eax) || BH_E4(eax) || SH_E5(eax) || \
2731ee88d2b9Skchow 			    DH_E6(eax) || JH_E6(eax))
27327c478bd9Sstevel@tonic-gate 
2733512cf780Skchow #define	DR_AX(eax)	(eax == 0x100f00 || eax == 0x100f01 || eax == 0x100f02)
2734512cf780Skchow #define	DR_B0(eax)	(eax == 0x100f20)
2735512cf780Skchow #define	DR_B1(eax)	(eax == 0x100f21)
2736512cf780Skchow #define	DR_BA(eax)	(eax == 0x100f2a)
2737512cf780Skchow #define	DR_B2(eax)	(eax == 0x100f22)
2738512cf780Skchow #define	DR_B3(eax)	(eax == 0x100f23)
2739512cf780Skchow #define	RB_C0(eax)	(eax == 0x100f40)
2740512cf780Skchow 
27417c478bd9Sstevel@tonic-gate 	switch (erratum) {
27427c478bd9Sstevel@tonic-gate 	case 1:
2743875b116eSkchow 		return (cpi->cpi_family < 0x10);
27447c478bd9Sstevel@tonic-gate 	case 51:	/* what does the asterisk mean? */
27457c478bd9Sstevel@tonic-gate 		return (B(eax) || SH_C0(eax) || CG(eax));
27467c478bd9Sstevel@tonic-gate 	case 52:
27477c478bd9Sstevel@tonic-gate 		return (B(eax));
27487c478bd9Sstevel@tonic-gate 	case 57:
2749512cf780Skchow 		return (cpi->cpi_family <= 0x11);
27507c478bd9Sstevel@tonic-gate 	case 58:
27517c478bd9Sstevel@tonic-gate 		return (B(eax));
27527c478bd9Sstevel@tonic-gate 	case 60:
2753512cf780Skchow 		return (cpi->cpi_family <= 0x11);
27547c478bd9Sstevel@tonic-gate 	case 61:
27557c478bd9Sstevel@tonic-gate 	case 62:
27567c478bd9Sstevel@tonic-gate 	case 63:
27577c478bd9Sstevel@tonic-gate 	case 64:
27587c478bd9Sstevel@tonic-gate 	case 65:
27597c478bd9Sstevel@tonic-gate 	case 66:
27607c478bd9Sstevel@tonic-gate 	case 68:
27617c478bd9Sstevel@tonic-gate 	case 69:
27627c478bd9Sstevel@tonic-gate 	case 70:
27637c478bd9Sstevel@tonic-gate 	case 71:
27647c478bd9Sstevel@tonic-gate 		return (B(eax));
27657c478bd9Sstevel@tonic-gate 	case 72:
27667c478bd9Sstevel@tonic-gate 		return (SH_B0(eax));
27677c478bd9Sstevel@tonic-gate 	case 74:
27687c478bd9Sstevel@tonic-gate 		return (B(eax));
27697c478bd9Sstevel@tonic-gate 	case 75:
2770875b116eSkchow 		return (cpi->cpi_family < 0x10);
27717c478bd9Sstevel@tonic-gate 	case 76:
27727c478bd9Sstevel@tonic-gate 		return (B(eax));
27737c478bd9Sstevel@tonic-gate 	case 77:
2774512cf780Skchow 		return (cpi->cpi_family <= 0x11);
27757c478bd9Sstevel@tonic-gate 	case 78:
27767c478bd9Sstevel@tonic-gate 		return (B(eax) || SH_C0(eax));
27777c478bd9Sstevel@tonic-gate 	case 79:
27787c478bd9Sstevel@tonic-gate 		return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax) || EX(eax));
27797c478bd9Sstevel@tonic-gate 	case 80:
27807c478bd9Sstevel@tonic-gate 	case 81:
27817c478bd9Sstevel@tonic-gate 	case 82:
27827c478bd9Sstevel@tonic-gate 		return (B(eax));
27837c478bd9Sstevel@tonic-gate 	case 83:
27847c478bd9Sstevel@tonic-gate 		return (B(eax) || SH_C0(eax) || CG(eax));
27857c478bd9Sstevel@tonic-gate 	case 85:
2786875b116eSkchow 		return (cpi->cpi_family < 0x10);
27877c478bd9Sstevel@tonic-gate 	case 86:
27887c478bd9Sstevel@tonic-gate 		return (SH_C0(eax) || CG(eax));
27897c478bd9Sstevel@tonic-gate 	case 88:
27907c478bd9Sstevel@tonic-gate #if !defined(__amd64)
27917c478bd9Sstevel@tonic-gate 		return (0);
27927c478bd9Sstevel@tonic-gate #else
27937c478bd9Sstevel@tonic-gate 		return (B(eax) || SH_C0(eax));
27947c478bd9Sstevel@tonic-gate #endif
27957c478bd9Sstevel@tonic-gate 	case 89:
2796875b116eSkchow 		return (cpi->cpi_family < 0x10);
27977c478bd9Sstevel@tonic-gate 	case 90:
27987c478bd9Sstevel@tonic-gate 		return (B(eax) || SH_C0(eax) || CG(eax));
27997c478bd9Sstevel@tonic-gate 	case 91:
28007c478bd9Sstevel@tonic-gate 	case 92:
28017c478bd9Sstevel@tonic-gate 		return (B(eax) || SH_C0(eax));
28027c478bd9Sstevel@tonic-gate 	case 93:
28037c478bd9Sstevel@tonic-gate 		return (SH_C0(eax));
28047c478bd9Sstevel@tonic-gate 	case 94:
28057c478bd9Sstevel@tonic-gate 		return (B(eax) || SH_C0(eax) || CG(eax));
28067c478bd9Sstevel@tonic-gate 	case 95:
28077c478bd9Sstevel@tonic-gate #if !defined(__amd64)
28087c478bd9Sstevel@tonic-gate 		return (0);
28097c478bd9Sstevel@tonic-gate #else
28107c478bd9Sstevel@tonic-gate 		return (B(eax) || SH_C0(eax));
28117c478bd9Sstevel@tonic-gate #endif
28127c478bd9Sstevel@tonic-gate 	case 96:
28137c478bd9Sstevel@tonic-gate 		return (B(eax) || SH_C0(eax) || CG(eax));
28147c478bd9Sstevel@tonic-gate 	case 97:
28157c478bd9Sstevel@tonic-gate 	case 98:
28167c478bd9Sstevel@tonic-gate 		return (SH_C0(eax) || CG(eax));
28177c478bd9Sstevel@tonic-gate 	case 99:
28187c478bd9Sstevel@tonic-gate 		return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax));
28197c478bd9Sstevel@tonic-gate 	case 100:
28207c478bd9Sstevel@tonic-gate 		return (B(eax) || SH_C0(eax));
28217c478bd9Sstevel@tonic-gate 	case 101:
28227c478bd9Sstevel@tonic-gate 	case 103:
28237c478bd9Sstevel@tonic-gate 		return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax));
28247c478bd9Sstevel@tonic-gate 	case 104:
28257c478bd9Sstevel@tonic-gate 		return (SH_C0(eax) || CG(eax) || D0(eax));
28267c478bd9Sstevel@tonic-gate 	case 105:
28277c478bd9Sstevel@tonic-gate 	case 106:
28287c478bd9Sstevel@tonic-gate 	case 107:
28297c478bd9Sstevel@tonic-gate 		return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax));
28307c478bd9Sstevel@tonic-gate 	case 108:
28317c478bd9Sstevel@tonic-gate 		return (DH_CG(eax));
28327c478bd9Sstevel@tonic-gate 	case 109:
28337c478bd9Sstevel@tonic-gate 		return (SH_C0(eax) || CG(eax) || D0(eax));
28347c478bd9Sstevel@tonic-gate 	case 110:
28357c478bd9Sstevel@tonic-gate 		return (D0(eax) || EX(eax));
28367c478bd9Sstevel@tonic-gate 	case 111:
28377c478bd9Sstevel@tonic-gate 		return (CG(eax));
28387c478bd9Sstevel@tonic-gate 	case 112:
28397c478bd9Sstevel@tonic-gate 		return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax) || EX(eax));
28407c478bd9Sstevel@tonic-gate 	case 113:
28417c478bd9Sstevel@tonic-gate 		return (eax == 0x20fc0);
28427c478bd9Sstevel@tonic-gate 	case 114:
28437c478bd9Sstevel@tonic-gate 		return (SH_E0(eax) || JH_E1(eax) || DH_E3(eax));
28447c478bd9Sstevel@tonic-gate 	case 115:
28457c478bd9Sstevel@tonic-gate 		return (SH_E0(eax) || JH_E1(eax));
28467c478bd9Sstevel@tonic-gate 	case 116:
28477c478bd9Sstevel@tonic-gate 		return (SH_E0(eax) || JH_E1(eax) || DH_E3(eax));
28487c478bd9Sstevel@tonic-gate 	case 117:
28497c478bd9Sstevel@tonic-gate 		return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax));
28507c478bd9Sstevel@tonic-gate 	case 118:
28517c478bd9Sstevel@tonic-gate 		return (SH_E0(eax) || JH_E1(eax) || SH_E4(eax) || BH_E4(eax) ||
28527c478bd9Sstevel@tonic-gate 		    JH_E6(eax));
28537c478bd9Sstevel@tonic-gate 	case 121:
28547c478bd9Sstevel@tonic-gate 		return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax) || EX(eax));
28557c478bd9Sstevel@tonic-gate 	case 122:
2856512cf780Skchow 		return (cpi->cpi_family < 0x10 || cpi->cpi_family == 0x11);
28577c478bd9Sstevel@tonic-gate 	case 123:
28587c478bd9Sstevel@tonic-gate 		return (JH_E1(eax) || BH_E4(eax) || JH_E6(eax));
28592201b277Skucharsk 	case 131:
2860875b116eSkchow 		return (cpi->cpi_family < 0x10);
2861ef50d8c0Sesaxe 	case 6336786:
2862ef50d8c0Sesaxe 		/*
2863ef50d8c0Sesaxe 		 * Test for AdvPowerMgmtInfo.TscPStateInvariant
2864875b116eSkchow 		 * if this is a K8 family or newer processor
2865ef50d8c0Sesaxe 		 */
2866ef50d8c0Sesaxe 		if (CPI_FAMILY(cpi) == 0xf) {
28678949bcd6Sandrei 			struct cpuid_regs regs;
28688949bcd6Sandrei 			regs.cp_eax = 0x80000007;
28698949bcd6Sandrei 			(void) __cpuid_insn(&regs);
28708949bcd6Sandrei 			return (!(regs.cp_edx & 0x100));
2871ef50d8c0Sesaxe 		}
2872ef50d8c0Sesaxe 		return (0);
2873ee88d2b9Skchow 	case 6323525:
2874ee88d2b9Skchow 		return (((((eax >> 12) & 0xff00) + (eax & 0xf00)) |
2875ee88d2b9Skchow 		    (((eax >> 4) & 0xf) | ((eax >> 12) & 0xf0))) < 0xf40);
2876ee88d2b9Skchow 
2877512cf780Skchow 	case 6671130:
2878512cf780Skchow 		/*
2879512cf780Skchow 		 * check for processors (pre-Shanghai) that do not provide
2880512cf780Skchow 		 * optimal management of 1gb ptes in its tlb.
2881512cf780Skchow 		 */
2882512cf780Skchow 		return (cpi->cpi_family == 0x10 && cpi->cpi_model < 4);
2883512cf780Skchow 
2884512cf780Skchow 	case 298:
2885512cf780Skchow 		return (DR_AX(eax) || DR_B0(eax) || DR_B1(eax) || DR_BA(eax) ||
2886512cf780Skchow 		    DR_B2(eax) || RB_C0(eax));
2887512cf780Skchow 
2888512cf780Skchow 	default:
2889512cf780Skchow 		return (-1);
2890512cf780Skchow 
2891512cf780Skchow 	}
2892512cf780Skchow }
2893512cf780Skchow 
2894512cf780Skchow /*
2895512cf780Skchow  * Determine if specified erratum is present via OSVW (OS Visible Workaround).
2896512cf780Skchow  * Return 1 if erratum is present, 0 if not present and -1 if indeterminate.
2897512cf780Skchow  */
2898512cf780Skchow int
2899512cf780Skchow osvw_opteron_erratum(cpu_t *cpu, uint_t erratum)
2900512cf780Skchow {
2901512cf780Skchow 	struct cpuid_info	*cpi;
2902512cf780Skchow 	uint_t			osvwid;
2903512cf780Skchow 	static int		osvwfeature = -1;
2904512cf780Skchow 	uint64_t		osvwlength;
2905512cf780Skchow 
2906512cf780Skchow 
2907512cf780Skchow 	cpi = cpu->cpu_m.mcpu_cpi;
2908512cf780Skchow 
2909512cf780Skchow 	/* confirm OSVW supported */
2910512cf780Skchow 	if (osvwfeature == -1) {
2911512cf780Skchow 		osvwfeature = cpi->cpi_extd[1].cp_ecx & CPUID_AMD_ECX_OSVW;
2912512cf780Skchow 	} else {
2913512cf780Skchow 		/* assert that osvw feature setting is consistent on all cpus */
2914512cf780Skchow 		ASSERT(osvwfeature ==
2915512cf780Skchow 		    (cpi->cpi_extd[1].cp_ecx & CPUID_AMD_ECX_OSVW));
2916512cf780Skchow 	}
2917512cf780Skchow 	if (!osvwfeature)
2918512cf780Skchow 		return (-1);
2919512cf780Skchow 
2920512cf780Skchow 	osvwlength = rdmsr(MSR_AMD_OSVW_ID_LEN) & OSVW_ID_LEN_MASK;
2921512cf780Skchow 
2922512cf780Skchow 	switch (erratum) {
2923512cf780Skchow 	case 298:	/* osvwid is 0 */
2924512cf780Skchow 		osvwid = 0;
2925512cf780Skchow 		if (osvwlength <= (uint64_t)osvwid) {
2926512cf780Skchow 			/* osvwid 0 is unknown */
2927512cf780Skchow 			return (-1);
2928512cf780Skchow 		}
2929512cf780Skchow 
2930512cf780Skchow 		/*
2931512cf780Skchow 		 * Check the OSVW STATUS MSR to determine the state
2932512cf780Skchow 		 * of the erratum where:
2933512cf780Skchow 		 *   0 - fixed by HW
2934512cf780Skchow 		 *   1 - BIOS has applied the workaround when BIOS
2935512cf780Skchow 		 *   workaround is available. (Or for other errata,
2936512cf780Skchow 		 *   OS workaround is required.)
2937512cf780Skchow 		 * For a value of 1, caller will confirm that the
2938512cf780Skchow 		 * erratum 298 workaround has indeed been applied by BIOS.
2939512cf780Skchow 		 *
2940512cf780Skchow 		 * A 1 may be set in cpus that have a HW fix
2941512cf780Skchow 		 * in a mixed cpu system. Regarding erratum 298:
2942512cf780Skchow 		 *   In a multiprocessor platform, the workaround above
2943512cf780Skchow 		 *   should be applied to all processors regardless of
2944512cf780Skchow 		 *   silicon revision when an affected processor is
2945512cf780Skchow 		 *   present.
2946512cf780Skchow 		 */
2947512cf780Skchow 
2948512cf780Skchow 		return (rdmsr(MSR_AMD_OSVW_STATUS +
2949512cf780Skchow 		    (osvwid / OSVW_ID_CNT_PER_MSR)) &
2950512cf780Skchow 		    (1ULL << (osvwid % OSVW_ID_CNT_PER_MSR)));
2951512cf780Skchow 
29527c478bd9Sstevel@tonic-gate 	default:
29537c478bd9Sstevel@tonic-gate 		return (-1);
29547c478bd9Sstevel@tonic-gate 	}
29557c478bd9Sstevel@tonic-gate }
29567c478bd9Sstevel@tonic-gate 
29577c478bd9Sstevel@tonic-gate static const char assoc_str[] = "associativity";
29587c478bd9Sstevel@tonic-gate static const char line_str[] = "line-size";
29597c478bd9Sstevel@tonic-gate static const char size_str[] = "size";
29607c478bd9Sstevel@tonic-gate 
29617c478bd9Sstevel@tonic-gate static void
29627c478bd9Sstevel@tonic-gate add_cache_prop(dev_info_t *devi, const char *label, const char *type,
29637c478bd9Sstevel@tonic-gate     uint32_t val)
29647c478bd9Sstevel@tonic-gate {
29657c478bd9Sstevel@tonic-gate 	char buf[128];
29667c478bd9Sstevel@tonic-gate 
29677c478bd9Sstevel@tonic-gate 	/*
29687c478bd9Sstevel@tonic-gate 	 * ndi_prop_update_int() is used because it is desirable for
29697c478bd9Sstevel@tonic-gate 	 * DDI_PROP_HW_DEF and DDI_PROP_DONTSLEEP to be set.
29707c478bd9Sstevel@tonic-gate 	 */
29717c478bd9Sstevel@tonic-gate 	if (snprintf(buf, sizeof (buf), "%s-%s", label, type) < sizeof (buf))
29727c478bd9Sstevel@tonic-gate 		(void) ndi_prop_update_int(DDI_DEV_T_NONE, devi, buf, val);
29737c478bd9Sstevel@tonic-gate }
29747c478bd9Sstevel@tonic-gate 
29757c478bd9Sstevel@tonic-gate /*
29767c478bd9Sstevel@tonic-gate  * Intel-style cache/tlb description
29777c478bd9Sstevel@tonic-gate  *
29787c478bd9Sstevel@tonic-gate  * Standard cpuid level 2 gives a randomly ordered
29797c478bd9Sstevel@tonic-gate  * selection of tags that index into a table that describes
29807c478bd9Sstevel@tonic-gate  * cache and tlb properties.
29817c478bd9Sstevel@tonic-gate  */
29827c478bd9Sstevel@tonic-gate 
29837c478bd9Sstevel@tonic-gate static const char l1_icache_str[] = "l1-icache";
29847c478bd9Sstevel@tonic-gate static const char l1_dcache_str[] = "l1-dcache";
29857c478bd9Sstevel@tonic-gate static const char l2_cache_str[] = "l2-cache";
2986ae115bc7Smrj static const char l3_cache_str[] = "l3-cache";
29877c478bd9Sstevel@tonic-gate static const char itlb4k_str[] = "itlb-4K";
29887c478bd9Sstevel@tonic-gate static const char dtlb4k_str[] = "dtlb-4K";
2989824e4fecSvd224797 static const char itlb2M_str[] = "itlb-2M";
29907c478bd9Sstevel@tonic-gate static const char itlb4M_str[] = "itlb-4M";
29917c478bd9Sstevel@tonic-gate static const char dtlb4M_str[] = "dtlb-4M";
299225dfb062Sksadhukh static const char dtlb24_str[] = "dtlb0-2M-4M";
29937c478bd9Sstevel@tonic-gate static const char itlb424_str[] = "itlb-4K-2M-4M";
299425dfb062Sksadhukh static const char itlb24_str[] = "itlb-2M-4M";
29957c478bd9Sstevel@tonic-gate static const char dtlb44_str[] = "dtlb-4K-4M";
29967c478bd9Sstevel@tonic-gate static const char sl1_dcache_str[] = "sectored-l1-dcache";
29977c478bd9Sstevel@tonic-gate static const char sl2_cache_str[] = "sectored-l2-cache";
29987c478bd9Sstevel@tonic-gate static const char itrace_str[] = "itrace-cache";
29997c478bd9Sstevel@tonic-gate static const char sl3_cache_str[] = "sectored-l3-cache";
300025dfb062Sksadhukh static const char sh_l2_tlb4k_str[] = "shared-l2-tlb-4k";
30017c478bd9Sstevel@tonic-gate 
30027c478bd9Sstevel@tonic-gate static const struct cachetab {
30037c478bd9Sstevel@tonic-gate 	uint8_t 	ct_code;
30047c478bd9Sstevel@tonic-gate 	uint8_t		ct_assoc;
30057c478bd9Sstevel@tonic-gate 	uint16_t 	ct_line_size;
30067c478bd9Sstevel@tonic-gate 	size_t		ct_size;
30077c478bd9Sstevel@tonic-gate 	const char	*ct_label;
30087c478bd9Sstevel@tonic-gate } intel_ctab[] = {
3009824e4fecSvd224797 	/*
3010824e4fecSvd224797 	 * maintain descending order!
3011824e4fecSvd224797 	 *
3012824e4fecSvd224797 	 * Codes ignored - Reason
3013824e4fecSvd224797 	 * ----------------------
3014824e4fecSvd224797 	 * 40H - intel_cpuid_4_cache_info() disambiguates l2/l3 cache
3015824e4fecSvd224797 	 * f0H/f1H - Currently we do not interpret prefetch size by design
3016824e4fecSvd224797 	 */
301725dfb062Sksadhukh 	{ 0xe4, 16, 64, 8*1024*1024, l3_cache_str},
301825dfb062Sksadhukh 	{ 0xe3, 16, 64, 4*1024*1024, l3_cache_str},
301925dfb062Sksadhukh 	{ 0xe2, 16, 64, 2*1024*1024, l3_cache_str},
302025dfb062Sksadhukh 	{ 0xde, 12, 64, 6*1024*1024, l3_cache_str},
302125dfb062Sksadhukh 	{ 0xdd, 12, 64, 3*1024*1024, l3_cache_str},
302225dfb062Sksadhukh 	{ 0xdc, 12, 64, ((1*1024*1024)+(512*1024)), l3_cache_str},
302325dfb062Sksadhukh 	{ 0xd8, 8, 64, 4*1024*1024, l3_cache_str},
302425dfb062Sksadhukh 	{ 0xd7, 8, 64, 2*1024*1024, l3_cache_str},
302525dfb062Sksadhukh 	{ 0xd6, 8, 64, 1*1024*1024, l3_cache_str},
302625dfb062Sksadhukh 	{ 0xd2, 4, 64, 2*1024*1024, l3_cache_str},
302725dfb062Sksadhukh 	{ 0xd1, 4, 64, 1*1024*1024, l3_cache_str},
302825dfb062Sksadhukh 	{ 0xd0, 4, 64, 512*1024, l3_cache_str},
302925dfb062Sksadhukh 	{ 0xca, 4, 0, 512, sh_l2_tlb4k_str},
3030824e4fecSvd224797 	{ 0xc0, 4, 0, 8, dtlb44_str },
3031824e4fecSvd224797 	{ 0xba, 4, 0, 64, dtlb4k_str },
3032ae115bc7Smrj 	{ 0xb4, 4, 0, 256, dtlb4k_str },
30337c478bd9Sstevel@tonic-gate 	{ 0xb3, 4, 0, 128, dtlb4k_str },
303425dfb062Sksadhukh 	{ 0xb2, 4, 0, 64, itlb4k_str },
30357c478bd9Sstevel@tonic-gate 	{ 0xb0, 4, 0, 128, itlb4k_str },
30367c478bd9Sstevel@tonic-gate 	{ 0x87, 8, 64, 1024*1024, l2_cache_str},
30377c478bd9Sstevel@tonic-gate 	{ 0x86, 4, 64, 512*1024, l2_cache_str},
30387c478bd9Sstevel@tonic-gate 	{ 0x85, 8, 32, 2*1024*1024, l2_cache_str},
30397c478bd9Sstevel@tonic-gate 	{ 0x84, 8, 32, 1024*1024, l2_cache_str},
30407c478bd9Sstevel@tonic-gate 	{ 0x83, 8, 32, 512*1024, l2_cache_str},
30417c478bd9Sstevel@tonic-gate 	{ 0x82, 8, 32, 256*1024, l2_cache_str},
3042824e4fecSvd224797 	{ 0x80, 8, 64, 512*1024, l2_cache_str},
30437c478bd9Sstevel@tonic-gate 	{ 0x7f, 2, 64, 512*1024, l2_cache_str},
30447c478bd9Sstevel@tonic-gate 	{ 0x7d, 8, 64, 2*1024*1024, sl2_cache_str},
30457c478bd9Sstevel@tonic-gate 	{ 0x7c, 8, 64, 1024*1024, sl2_cache_str},
30467c478bd9Sstevel@tonic-gate 	{ 0x7b, 8, 64, 512*1024, sl2_cache_str},
30477c478bd9Sstevel@tonic-gate 	{ 0x7a, 8, 64, 256*1024, sl2_cache_str},
30487c478bd9Sstevel@tonic-gate 	{ 0x79, 8, 64, 128*1024, sl2_cache_str},
30497c478bd9Sstevel@tonic-gate 	{ 0x78, 8, 64, 1024*1024, l2_cache_str},
3050ae115bc7Smrj 	{ 0x73, 8, 0, 64*1024, itrace_str},
30517c478bd9Sstevel@tonic-gate 	{ 0x72, 8, 0, 32*1024, itrace_str},
30527c478bd9Sstevel@tonic-gate 	{ 0x71, 8, 0, 16*1024, itrace_str},
30537c478bd9Sstevel@tonic-gate 	{ 0x70, 8, 0, 12*1024, itrace_str},
30547c478bd9Sstevel@tonic-gate 	{ 0x68, 4, 64, 32*1024, sl1_dcache_str},
30557c478bd9Sstevel@tonic-gate 	{ 0x67, 4, 64, 16*1024, sl1_dcache_str},
30567c478bd9Sstevel@tonic-gate 	{ 0x66, 4, 64, 8*1024, sl1_dcache_str},
30577c478bd9Sstevel@tonic-gate 	{ 0x60, 8, 64, 16*1024, sl1_dcache_str},
30587c478bd9Sstevel@tonic-gate 	{ 0x5d, 0, 0, 256, dtlb44_str},
30597c478bd9Sstevel@tonic-gate 	{ 0x5c, 0, 0, 128, dtlb44_str},
30607c478bd9Sstevel@tonic-gate 	{ 0x5b, 0, 0, 64, dtlb44_str},
306125dfb062Sksadhukh 	{ 0x5a, 4, 0, 32, dtlb24_str},
3062824e4fecSvd224797 	{ 0x59, 0, 0, 16, dtlb4k_str},
3063824e4fecSvd224797 	{ 0x57, 4, 0, 16, dtlb4k_str},
3064824e4fecSvd224797 	{ 0x56, 4, 0, 16, dtlb4M_str},
306525dfb062Sksadhukh 	{ 0x55, 0, 0, 7, itlb24_str},
30667c478bd9Sstevel@tonic-gate 	{ 0x52, 0, 0, 256, itlb424_str},
30677c478bd9Sstevel@tonic-gate 	{ 0x51, 0, 0, 128, itlb424_str},
30687c478bd9Sstevel@tonic-gate 	{ 0x50, 0, 0, 64, itlb424_str},
3069824e4fecSvd224797 	{ 0x4f, 0, 0, 32, itlb4k_str},
3070824e4fecSvd224797 	{ 0x4e, 24, 64, 6*1024*1024, l2_cache_str},
3071ae115bc7Smrj 	{ 0x4d, 16, 64, 16*1024*1024, l3_cache_str},
3072ae115bc7Smrj 	{ 0x4c, 12, 64, 12*1024*1024, l3_cache_str},
3073ae115bc7Smrj 	{ 0x4b, 16, 64, 8*1024*1024, l3_cache_str},
3074ae115bc7Smrj 	{ 0x4a, 12, 64, 6*1024*1024, l3_cache_str},
3075ae115bc7Smrj 	{ 0x49, 16, 64, 4*1024*1024, l3_cache_str},
3076824e4fecSvd224797 	{ 0x48, 12, 64, 3*1024*1024, l2_cache_str},
3077ae115bc7Smrj 	{ 0x47, 8, 64, 8*1024*1024, l3_cache_str},
3078ae115bc7Smrj 	{ 0x46, 4, 64, 4*1024*1024, l3_cache_str},
30797c478bd9Sstevel@tonic-gate 	{ 0x45, 4, 32, 2*1024*1024, l2_cache_str},
30807c478bd9Sstevel@tonic-gate 	{ 0x44, 4, 32, 1024*1024, l2_cache_str},
30817c478bd9Sstevel@tonic-gate 	{ 0x43, 4, 32, 512*1024, l2_cache_str},
30827c478bd9Sstevel@tonic-gate 	{ 0x42, 4, 32, 256*1024, l2_cache_str},
30837c478bd9Sstevel@tonic-gate 	{ 0x41, 4, 32, 128*1024, l2_cache_str},
3084ae115bc7Smrj 	{ 0x3e, 4, 64, 512*1024, sl2_cache_str},
3085ae115bc7Smrj 	{ 0x3d, 6, 64, 384*1024, sl2_cache_str},
30867c478bd9Sstevel@tonic-gate 	{ 0x3c, 4, 64, 256*1024, sl2_cache_str},
30877c478bd9Sstevel@tonic-gate 	{ 0x3b, 2, 64, 128*1024, sl2_cache_str},
3088ae115bc7Smrj 	{ 0x3a, 6, 64, 192*1024, sl2_cache_str},
30897c478bd9Sstevel@tonic-gate 	{ 0x39, 4, 64, 128*1024, sl2_cache_str},
30907c478bd9Sstevel@tonic-gate 	{ 0x30, 8, 64, 32*1024, l1_icache_str},
30917c478bd9Sstevel@tonic-gate 	{ 0x2c, 8, 64, 32*1024, l1_dcache_str},
30927c478bd9Sstevel@tonic-gate 	{ 0x29, 8, 64, 4096*1024, sl3_cache_str},
30937c478bd9Sstevel@tonic-gate 	{ 0x25, 8, 64, 2048*1024, sl3_cache_str},
30947c478bd9Sstevel@tonic-gate 	{ 0x23, 8, 64, 1024*1024, sl3_cache_str},
30957c478bd9Sstevel@tonic-gate 	{ 0x22, 4, 64, 512*1024, sl3_cache_str},
3096824e4fecSvd224797 	{ 0x0e, 6, 64, 24*1024, l1_dcache_str},
309725dfb062Sksadhukh 	{ 0x0d, 4, 32, 16*1024, l1_dcache_str},
30987c478bd9Sstevel@tonic-gate 	{ 0x0c, 4, 32, 16*1024, l1_dcache_str},
3099ae115bc7Smrj 	{ 0x0b, 4, 0, 4, itlb4M_str},
31007c478bd9Sstevel@tonic-gate 	{ 0x0a, 2, 32, 8*1024, l1_dcache_str},
31017c478bd9Sstevel@tonic-gate 	{ 0x08, 4, 32, 16*1024, l1_icache_str},
31027c478bd9Sstevel@tonic-gate 	{ 0x06, 4, 32, 8*1024, l1_icache_str},
3103824e4fecSvd224797 	{ 0x05, 4, 0, 32, dtlb4M_str},
31047c478bd9Sstevel@tonic-gate 	{ 0x04, 4, 0, 8, dtlb4M_str},
31057c478bd9Sstevel@tonic-gate 	{ 0x03, 4, 0, 64, dtlb4k_str},
31067c478bd9Sstevel@tonic-gate 	{ 0x02, 4, 0, 2, itlb4M_str},
31077c478bd9Sstevel@tonic-gate 	{ 0x01, 4, 0, 32, itlb4k_str},
31087c478bd9Sstevel@tonic-gate 	{ 0 }
31097c478bd9Sstevel@tonic-gate };
31107c478bd9Sstevel@tonic-gate 
31117c478bd9Sstevel@tonic-gate static const struct cachetab cyrix_ctab[] = {
31127c478bd9Sstevel@tonic-gate 	{ 0x70, 4, 0, 32, "tlb-4K" },
31137c478bd9Sstevel@tonic-gate 	{ 0x80, 4, 16, 16*1024, "l1-cache" },
31147c478bd9Sstevel@tonic-gate 	{ 0 }
31157c478bd9Sstevel@tonic-gate };
31167c478bd9Sstevel@tonic-gate 
31177c478bd9Sstevel@tonic-gate /*
31187c478bd9Sstevel@tonic-gate  * Search a cache table for a matching entry
31197c478bd9Sstevel@tonic-gate  */
31207c478bd9Sstevel@tonic-gate static const struct cachetab *
31217c478bd9Sstevel@tonic-gate find_cacheent(const struct cachetab *ct, uint_t code)
31227c478bd9Sstevel@tonic-gate {
31237c478bd9Sstevel@tonic-gate 	if (code != 0) {
31247c478bd9Sstevel@tonic-gate 		for (; ct->ct_code != 0; ct++)
31257c478bd9Sstevel@tonic-gate 			if (ct->ct_code <= code)
31267c478bd9Sstevel@tonic-gate 				break;
31277c478bd9Sstevel@tonic-gate 		if (ct->ct_code == code)
31287c478bd9Sstevel@tonic-gate 			return (ct);
31297c478bd9Sstevel@tonic-gate 	}
31307c478bd9Sstevel@tonic-gate 	return (NULL);
31317c478bd9Sstevel@tonic-gate }
31327c478bd9Sstevel@tonic-gate 
31337c478bd9Sstevel@tonic-gate /*
31347dee861bSksadhukh  * Populate cachetab entry with L2 or L3 cache-information using
31357dee861bSksadhukh  * cpuid function 4. This function is called from intel_walk_cacheinfo()
31367dee861bSksadhukh  * when descriptor 0x49 is encountered. It returns 0 if no such cache
31377dee861bSksadhukh  * information is found.
31387dee861bSksadhukh  */
31397dee861bSksadhukh static int
31407dee861bSksadhukh intel_cpuid_4_cache_info(struct cachetab *ct, struct cpuid_info *cpi)
31417dee861bSksadhukh {
31427dee861bSksadhukh 	uint32_t level, i;
31437dee861bSksadhukh 	int ret = 0;
31447dee861bSksadhukh 
31457dee861bSksadhukh 	for (i = 0; i < cpi->cpi_std_4_size; i++) {
31467dee861bSksadhukh 		level = CPI_CACHE_LVL(cpi->cpi_std_4[i]);
31477dee861bSksadhukh 
31487dee861bSksadhukh 		if (level == 2 || level == 3) {
31497dee861bSksadhukh 			ct->ct_assoc = CPI_CACHE_WAYS(cpi->cpi_std_4[i]) + 1;
31507dee861bSksadhukh 			ct->ct_line_size =
31517dee861bSksadhukh 			    CPI_CACHE_COH_LN_SZ(cpi->cpi_std_4[i]) + 1;
31527dee861bSksadhukh 			ct->ct_size = ct->ct_assoc *
31537dee861bSksadhukh 			    (CPI_CACHE_PARTS(cpi->cpi_std_4[i]) + 1) *
31547dee861bSksadhukh 			    ct->ct_line_size *
31557dee861bSksadhukh 			    (cpi->cpi_std_4[i]->cp_ecx + 1);
31567dee861bSksadhukh 
31577dee861bSksadhukh 			if (level == 2) {
31587dee861bSksadhukh 				ct->ct_label = l2_cache_str;
31597dee861bSksadhukh 			} else if (level == 3) {
31607dee861bSksadhukh 				ct->ct_label = l3_cache_str;
31617dee861bSksadhukh 			}
31627dee861bSksadhukh 			ret = 1;
31637dee861bSksadhukh 		}
31647dee861bSksadhukh 	}
31657dee861bSksadhukh 
31667dee861bSksadhukh 	return (ret);
31677dee861bSksadhukh }
31687dee861bSksadhukh 
31697dee861bSksadhukh /*
31707c478bd9Sstevel@tonic-gate  * Walk the cacheinfo descriptor, applying 'func' to every valid element
31717c478bd9Sstevel@tonic-gate  * The walk is terminated if the walker returns non-zero.
31727c478bd9Sstevel@tonic-gate  */
31737c478bd9Sstevel@tonic-gate static void
31747c478bd9Sstevel@tonic-gate intel_walk_cacheinfo(struct cpuid_info *cpi,
31757c478bd9Sstevel@tonic-gate     void *arg, int (*func)(void *, const struct cachetab *))
31767c478bd9Sstevel@tonic-gate {
31777c478bd9Sstevel@tonic-gate 	const struct cachetab *ct;
3178824e4fecSvd224797 	struct cachetab des_49_ct, des_b1_ct;
31797c478bd9Sstevel@tonic-gate 	uint8_t *dp;
31807c478bd9Sstevel@tonic-gate 	int i;
31817c478bd9Sstevel@tonic-gate 
31827c478bd9Sstevel@tonic-gate 	if ((dp = cpi->cpi_cacheinfo) == NULL)
31837c478bd9Sstevel@tonic-gate 		return;
3184f1d742a9Sksadhukh 	for (i = 0; i < cpi->cpi_ncache; i++, dp++) {
3185f1d742a9Sksadhukh 		/*
3186f1d742a9Sksadhukh 		 * For overloaded descriptor 0x49 we use cpuid function 4
31877dee861bSksadhukh 		 * if supported by the current processor, to create
3188f1d742a9Sksadhukh 		 * cache information.
3189824e4fecSvd224797 		 * For overloaded descriptor 0xb1 we use X86_PAE flag
3190824e4fecSvd224797 		 * to disambiguate the cache information.
3191f1d742a9Sksadhukh 		 */
31927dee861bSksadhukh 		if (*dp == 0x49 && cpi->cpi_maxeax >= 0x4 &&
31937dee861bSksadhukh 		    intel_cpuid_4_cache_info(&des_49_ct, cpi) == 1) {
31947dee861bSksadhukh 				ct = &des_49_ct;
3195824e4fecSvd224797 		} else if (*dp == 0xb1) {
3196824e4fecSvd224797 			des_b1_ct.ct_code = 0xb1;
3197824e4fecSvd224797 			des_b1_ct.ct_assoc = 4;
3198824e4fecSvd224797 			des_b1_ct.ct_line_size = 0;
3199824e4fecSvd224797 			if (x86_feature & X86_PAE) {
3200824e4fecSvd224797 				des_b1_ct.ct_size = 8;
3201824e4fecSvd224797 				des_b1_ct.ct_label = itlb2M_str;
3202824e4fecSvd224797 			} else {
3203824e4fecSvd224797 				des_b1_ct.ct_size = 4;
3204824e4fecSvd224797 				des_b1_ct.ct_label = itlb4M_str;
3205824e4fecSvd224797 			}
3206824e4fecSvd224797 			ct = &des_b1_ct;
32077dee861bSksadhukh 		} else {
32087dee861bSksadhukh 			if ((ct = find_cacheent(intel_ctab, *dp)) == NULL) {
3209f1d742a9Sksadhukh 				continue;
3210f1d742a9Sksadhukh 			}
32117dee861bSksadhukh 		}
3212f1d742a9Sksadhukh 
32137dee861bSksadhukh 		if (func(arg, ct) != 0) {
32147c478bd9Sstevel@tonic-gate 			break;
32157c478bd9Sstevel@tonic-gate 		}
32167c478bd9Sstevel@tonic-gate 	}
3217f1d742a9Sksadhukh }
32187c478bd9Sstevel@tonic-gate 
32197c478bd9Sstevel@tonic-gate /*
32207c478bd9Sstevel@tonic-gate  * (Like the Intel one, except for Cyrix CPUs)
32217c478bd9Sstevel@tonic-gate  */
32227c478bd9Sstevel@tonic-gate static void
32237c478bd9Sstevel@tonic-gate cyrix_walk_cacheinfo(struct cpuid_info *cpi,
32247c478bd9Sstevel@tonic-gate     void *arg, int (*func)(void *, const struct cachetab *))
32257c478bd9Sstevel@tonic-gate {
32267c478bd9Sstevel@tonic-gate 	const struct cachetab *ct;
32277c478bd9Sstevel@tonic-gate 	uint8_t *dp;
32287c478bd9Sstevel@tonic-gate 	int i;
32297c478bd9Sstevel@tonic-gate 
32307c478bd9Sstevel@tonic-gate 	if ((dp = cpi->cpi_cacheinfo) == NULL)
32317c478bd9Sstevel@tonic-gate 		return;
32327c478bd9Sstevel@tonic-gate 	for (i = 0; i < cpi->cpi_ncache; i++, dp++) {
32337c478bd9Sstevel@tonic-gate 		/*
32347c478bd9Sstevel@tonic-gate 		 * Search Cyrix-specific descriptor table first ..
32357c478bd9Sstevel@tonic-gate 		 */
32367c478bd9Sstevel@tonic-gate 		if ((ct = find_cacheent(cyrix_ctab, *dp)) != NULL) {
32377c478bd9Sstevel@tonic-gate 			if (func(arg, ct) != 0)
32387c478bd9Sstevel@tonic-gate 				break;
32397c478bd9Sstevel@tonic-gate 			continue;
32407c478bd9Sstevel@tonic-gate 		}
32417c478bd9Sstevel@tonic-gate 		/*
32427c478bd9Sstevel@tonic-gate 		 * .. else fall back to the Intel one
32437c478bd9Sstevel@tonic-gate 		 */
32447c478bd9Sstevel@tonic-gate 		if ((ct = find_cacheent(intel_ctab, *dp)) != NULL) {
32457c478bd9Sstevel@tonic-gate 			if (func(arg, ct) != 0)
32467c478bd9Sstevel@tonic-gate 				break;
32477c478bd9Sstevel@tonic-gate 			continue;
32487c478bd9Sstevel@tonic-gate 		}
32497c478bd9Sstevel@tonic-gate 	}
32507c478bd9Sstevel@tonic-gate }
32517c478bd9Sstevel@tonic-gate 
32527c478bd9Sstevel@tonic-gate /*
32537c478bd9Sstevel@tonic-gate  * A cacheinfo walker that adds associativity, line-size, and size properties
32547c478bd9Sstevel@tonic-gate  * to the devinfo node it is passed as an argument.
32557c478bd9Sstevel@tonic-gate  */
32567c478bd9Sstevel@tonic-gate static int
32577c478bd9Sstevel@tonic-gate add_cacheent_props(void *arg, const struct cachetab *ct)
32587c478bd9Sstevel@tonic-gate {
32597c478bd9Sstevel@tonic-gate 	dev_info_t *devi = arg;
32607c478bd9Sstevel@tonic-gate 
32617c478bd9Sstevel@tonic-gate 	add_cache_prop(devi, ct->ct_label, assoc_str, ct->ct_assoc);
32627c478bd9Sstevel@tonic-gate 	if (ct->ct_line_size != 0)
32637c478bd9Sstevel@tonic-gate 		add_cache_prop(devi, ct->ct_label, line_str,
32647c478bd9Sstevel@tonic-gate 		    ct->ct_line_size);
32657c478bd9Sstevel@tonic-gate 	add_cache_prop(devi, ct->ct_label, size_str, ct->ct_size);
32667c478bd9Sstevel@tonic-gate 	return (0);
32677c478bd9Sstevel@tonic-gate }
32687c478bd9Sstevel@tonic-gate 
3269f1d742a9Sksadhukh 
32707c478bd9Sstevel@tonic-gate static const char fully_assoc[] = "fully-associative?";
32717c478bd9Sstevel@tonic-gate 
32727c478bd9Sstevel@tonic-gate /*
32737c478bd9Sstevel@tonic-gate  * AMD style cache/tlb description
32747c478bd9Sstevel@tonic-gate  *
32757c478bd9Sstevel@tonic-gate  * Extended functions 5 and 6 directly describe properties of
32767c478bd9Sstevel@tonic-gate  * tlbs and various cache levels.
32777c478bd9Sstevel@tonic-gate  */
32787c478bd9Sstevel@tonic-gate static void
32797c478bd9Sstevel@tonic-gate add_amd_assoc(dev_info_t *devi, const char *label, uint_t assoc)
32807c478bd9Sstevel@tonic-gate {
32817c478bd9Sstevel@tonic-gate 	switch (assoc) {
32827c478bd9Sstevel@tonic-gate 	case 0:	/* reserved; ignore */
32837c478bd9Sstevel@tonic-gate 		break;
32847c478bd9Sstevel@tonic-gate 	default:
32857c478bd9Sstevel@tonic-gate 		add_cache_prop(devi, label, assoc_str, assoc);
32867c478bd9Sstevel@tonic-gate 		break;
32877c478bd9Sstevel@tonic-gate 	case 0xff:
32887c478bd9Sstevel@tonic-gate 		add_cache_prop(devi, label, fully_assoc, 1);
32897c478bd9Sstevel@tonic-gate 		break;
32907c478bd9Sstevel@tonic-gate 	}
32917c478bd9Sstevel@tonic-gate }
32927c478bd9Sstevel@tonic-gate 
32937c478bd9Sstevel@tonic-gate static void
32947c478bd9Sstevel@tonic-gate add_amd_tlb(dev_info_t *devi, const char *label, uint_t assoc, uint_t size)
32957c478bd9Sstevel@tonic-gate {
32967c478bd9Sstevel@tonic-gate 	if (size == 0)
32977c478bd9Sstevel@tonic-gate 		return;
32987c478bd9Sstevel@tonic-gate 	add_cache_prop(devi, label, size_str, size);
32997c478bd9Sstevel@tonic-gate 	add_amd_assoc(devi, label, assoc);
33007c478bd9Sstevel@tonic-gate }
33017c478bd9Sstevel@tonic-gate 
33027c478bd9Sstevel@tonic-gate static void
33037c478bd9Sstevel@tonic-gate add_amd_cache(dev_info_t *devi, const char *label,
33047c478bd9Sstevel@tonic-gate     uint_t size, uint_t assoc, uint_t lines_per_tag, uint_t line_size)
33057c478bd9Sstevel@tonic-gate {
33067c478bd9Sstevel@tonic-gate 	if (size == 0 || line_size == 0)
33077c478bd9Sstevel@tonic-gate 		return;
33087c478bd9Sstevel@tonic-gate 	add_amd_assoc(devi, label, assoc);
33097c478bd9Sstevel@tonic-gate 	/*
33107c478bd9Sstevel@tonic-gate 	 * Most AMD parts have a sectored cache. Multiple cache lines are
33117c478bd9Sstevel@tonic-gate 	 * associated with each tag. A sector consists of all cache lines
33127c478bd9Sstevel@tonic-gate 	 * associated with a tag. For example, the AMD K6-III has a sector
33137c478bd9Sstevel@tonic-gate 	 * size of 2 cache lines per tag.
33147c478bd9Sstevel@tonic-gate 	 */
33157c478bd9Sstevel@tonic-gate 	if (lines_per_tag != 0)
33167c478bd9Sstevel@tonic-gate 		add_cache_prop(devi, label, "lines-per-tag", lines_per_tag);
33177c478bd9Sstevel@tonic-gate 	add_cache_prop(devi, label, line_str, line_size);
33187c478bd9Sstevel@tonic-gate 	add_cache_prop(devi, label, size_str, size * 1024);
33197c478bd9Sstevel@tonic-gate }
33207c478bd9Sstevel@tonic-gate 
33217c478bd9Sstevel@tonic-gate static void
33227c478bd9Sstevel@tonic-gate add_amd_l2_assoc(dev_info_t *devi, const char *label, uint_t assoc)
33237c478bd9Sstevel@tonic-gate {
33247c478bd9Sstevel@tonic-gate 	switch (assoc) {
33257c478bd9Sstevel@tonic-gate 	case 0:	/* off */
33267c478bd9Sstevel@tonic-gate 		break;
33277c478bd9Sstevel@tonic-gate 	case 1:
33287c478bd9Sstevel@tonic-gate 	case 2:
33297c478bd9Sstevel@tonic-gate 	case 4:
33307c478bd9Sstevel@tonic-gate 		add_cache_prop(devi, label, assoc_str, assoc);
33317c478bd9Sstevel@tonic-gate 		break;
33327c478bd9Sstevel@tonic-gate 	case 6:
33337c478bd9Sstevel@tonic-gate 		add_cache_prop(devi, label, assoc_str, 8);
33347c478bd9Sstevel@tonic-gate 		break;
33357c478bd9Sstevel@tonic-gate 	case 8:
33367c478bd9Sstevel@tonic-gate 		add_cache_prop(devi, label, assoc_str, 16);
33377c478bd9Sstevel@tonic-gate 		break;
33387c478bd9Sstevel@tonic-gate 	case 0xf:
33397c478bd9Sstevel@tonic-gate 		add_cache_prop(devi, label, fully_assoc, 1);
33407c478bd9Sstevel@tonic-gate 		break;
33417c478bd9Sstevel@tonic-gate 	default: /* reserved; ignore */
33427c478bd9Sstevel@tonic-gate 		break;
33437c478bd9Sstevel@tonic-gate 	}
33447c478bd9Sstevel@tonic-gate }
33457c478bd9Sstevel@tonic-gate 
33467c478bd9Sstevel@tonic-gate static void
33477c478bd9Sstevel@tonic-gate add_amd_l2_tlb(dev_info_t *devi, const char *label, uint_t assoc, uint_t size)
33487c478bd9Sstevel@tonic-gate {
33497c478bd9Sstevel@tonic-gate 	if (size == 0 || assoc == 0)
33507c478bd9Sstevel@tonic-gate 		return;
33517c478bd9Sstevel@tonic-gate 	add_amd_l2_assoc(devi, label, assoc);
33527c478bd9Sstevel@tonic-gate 	add_cache_prop(devi, label, size_str, size);
33537c478bd9Sstevel@tonic-gate }
33547c478bd9Sstevel@tonic-gate 
33557c478bd9Sstevel@tonic-gate static void
33567c478bd9Sstevel@tonic-gate add_amd_l2_cache(dev_info_t *devi, const char *label,
33577c478bd9Sstevel@tonic-gate     uint_t size, uint_t assoc, uint_t lines_per_tag, uint_t line_size)
33587c478bd9Sstevel@tonic-gate {
33597c478bd9Sstevel@tonic-gate 	if (size == 0 || assoc == 0 || line_size == 0)
33607c478bd9Sstevel@tonic-gate 		return;
33617c478bd9Sstevel@tonic-gate 	add_amd_l2_assoc(devi, label, assoc);
33627c478bd9Sstevel@tonic-gate 	if (lines_per_tag != 0)
33637c478bd9Sstevel@tonic-gate 		add_cache_prop(devi, label, "lines-per-tag", lines_per_tag);
33647c478bd9Sstevel@tonic-gate 	add_cache_prop(devi, label, line_str, line_size);
33657c478bd9Sstevel@tonic-gate 	add_cache_prop(devi, label, size_str, size * 1024);
33667c478bd9Sstevel@tonic-gate }
33677c478bd9Sstevel@tonic-gate 
33687c478bd9Sstevel@tonic-gate static void
33697c478bd9Sstevel@tonic-gate amd_cache_info(struct cpuid_info *cpi, dev_info_t *devi)
33707c478bd9Sstevel@tonic-gate {
33718949bcd6Sandrei 	struct cpuid_regs *cp;
33727c478bd9Sstevel@tonic-gate 
33737c478bd9Sstevel@tonic-gate 	if (cpi->cpi_xmaxeax < 0x80000005)
33747c478bd9Sstevel@tonic-gate 		return;
33757c478bd9Sstevel@tonic-gate 	cp = &cpi->cpi_extd[5];
33767c478bd9Sstevel@tonic-gate 
33777c478bd9Sstevel@tonic-gate 	/*
33787c478bd9Sstevel@tonic-gate 	 * 4M/2M L1 TLB configuration
33797c478bd9Sstevel@tonic-gate 	 *
33807c478bd9Sstevel@tonic-gate 	 * We report the size for 2M pages because AMD uses two
33817c478bd9Sstevel@tonic-gate 	 * TLB entries for one 4M page.
33827c478bd9Sstevel@tonic-gate 	 */
33837c478bd9Sstevel@tonic-gate 	add_amd_tlb(devi, "dtlb-2M",
33847c478bd9Sstevel@tonic-gate 	    BITX(cp->cp_eax, 31, 24), BITX(cp->cp_eax, 23, 16));
33857c478bd9Sstevel@tonic-gate 	add_amd_tlb(devi, "itlb-2M",
33867c478bd9Sstevel@tonic-gate 	    BITX(cp->cp_eax, 15, 8), BITX(cp->cp_eax, 7, 0));
33877c478bd9Sstevel@tonic-gate 
33887c478bd9Sstevel@tonic-gate 	/*
33897c478bd9Sstevel@tonic-gate 	 * 4K L1 TLB configuration
33907c478bd9Sstevel@tonic-gate 	 */
33917c478bd9Sstevel@tonic-gate 
33927c478bd9Sstevel@tonic-gate 	switch (cpi->cpi_vendor) {
33937c478bd9Sstevel@tonic-gate 		uint_t nentries;
33947c478bd9Sstevel@tonic-gate 	case X86_VENDOR_TM:
33957c478bd9Sstevel@tonic-gate 		if (cpi->cpi_family >= 5) {
33967c478bd9Sstevel@tonic-gate 			/*
33977c478bd9Sstevel@tonic-gate 			 * Crusoe processors have 256 TLB entries, but
33987c478bd9Sstevel@tonic-gate 			 * cpuid data format constrains them to only
33997c478bd9Sstevel@tonic-gate 			 * reporting 255 of them.
34007c478bd9Sstevel@tonic-gate 			 */
34017c478bd9Sstevel@tonic-gate 			if ((nentries = BITX(cp->cp_ebx, 23, 16)) == 255)
34027c478bd9Sstevel@tonic-gate 				nentries = 256;
34037c478bd9Sstevel@tonic-gate 			/*
34047c478bd9Sstevel@tonic-gate 			 * Crusoe processors also have a unified TLB
34057c478bd9Sstevel@tonic-gate 			 */
34067c478bd9Sstevel@tonic-gate 			add_amd_tlb(devi, "tlb-4K", BITX(cp->cp_ebx, 31, 24),
34077c478bd9Sstevel@tonic-gate 			    nentries);
34087c478bd9Sstevel@tonic-gate 			break;
34097c478bd9Sstevel@tonic-gate 		}
34107c478bd9Sstevel@tonic-gate 		/*FALLTHROUGH*/
34117c478bd9Sstevel@tonic-gate 	default:
34127c478bd9Sstevel@tonic-gate 		add_amd_tlb(devi, itlb4k_str,
34137c478bd9Sstevel@tonic-gate 		    BITX(cp->cp_ebx, 31, 24), BITX(cp->cp_ebx, 23, 16));
34147c478bd9Sstevel@tonic-gate 		add_amd_tlb(devi, dtlb4k_str,
34157c478bd9Sstevel@tonic-gate 		    BITX(cp->cp_ebx, 15, 8), BITX(cp->cp_ebx, 7, 0));
34167c478bd9Sstevel@tonic-gate 		break;
34177c478bd9Sstevel@tonic-gate 	}
34187c478bd9Sstevel@tonic-gate 
34197c478bd9Sstevel@tonic-gate 	/*
34207c478bd9Sstevel@tonic-gate 	 * data L1 cache configuration
34217c478bd9Sstevel@tonic-gate 	 */
34227c478bd9Sstevel@tonic-gate 
34237c478bd9Sstevel@tonic-gate 	add_amd_cache(devi, l1_dcache_str,
34247c478bd9Sstevel@tonic-gate 	    BITX(cp->cp_ecx, 31, 24), BITX(cp->cp_ecx, 23, 16),
34257c478bd9Sstevel@tonic-gate 	    BITX(cp->cp_ecx, 15, 8), BITX(cp->cp_ecx, 7, 0));
34267c478bd9Sstevel@tonic-gate 
34277c478bd9Sstevel@tonic-gate 	/*
34287c478bd9Sstevel@tonic-gate 	 * code L1 cache configuration
34297c478bd9Sstevel@tonic-gate 	 */
34307c478bd9Sstevel@tonic-gate 
34317c478bd9Sstevel@tonic-gate 	add_amd_cache(devi, l1_icache_str,
34327c478bd9Sstevel@tonic-gate 	    BITX(cp->cp_edx, 31, 24), BITX(cp->cp_edx, 23, 16),
34337c478bd9Sstevel@tonic-gate 	    BITX(cp->cp_edx, 15, 8), BITX(cp->cp_edx, 7, 0));
34347c478bd9Sstevel@tonic-gate 
34357c478bd9Sstevel@tonic-gate 	if (cpi->cpi_xmaxeax < 0x80000006)
34367c478bd9Sstevel@tonic-gate 		return;
34377c478bd9Sstevel@tonic-gate 	cp = &cpi->cpi_extd[6];
34387c478bd9Sstevel@tonic-gate 
34397c478bd9Sstevel@tonic-gate 	/* Check for a unified L2 TLB for large pages */
34407c478bd9Sstevel@tonic-gate 
34417c478bd9Sstevel@tonic-gate 	if (BITX(cp->cp_eax, 31, 16) == 0)
34427c478bd9Sstevel@tonic-gate 		add_amd_l2_tlb(devi, "l2-tlb-2M",
34437c478bd9Sstevel@tonic-gate 		    BITX(cp->cp_eax, 15, 12), BITX(cp->cp_eax, 11, 0));
34447c478bd9Sstevel@tonic-gate 	else {
34457c478bd9Sstevel@tonic-gate 		add_amd_l2_tlb(devi, "l2-dtlb-2M",
34467c478bd9Sstevel@tonic-gate 		    BITX(cp->cp_eax, 31, 28), BITX(cp->cp_eax, 27, 16));
34477c478bd9Sstevel@tonic-gate 		add_amd_l2_tlb(devi, "l2-itlb-2M",
34487c478bd9Sstevel@tonic-gate 		    BITX(cp->cp_eax, 15, 12), BITX(cp->cp_eax, 11, 0));
34497c478bd9Sstevel@tonic-gate 	}
34507c478bd9Sstevel@tonic-gate 
34517c478bd9Sstevel@tonic-gate 	/* Check for a unified L2 TLB for 4K pages */
34527c478bd9Sstevel@tonic-gate 
34537c478bd9Sstevel@tonic-gate 	if (BITX(cp->cp_ebx, 31, 16) == 0) {
34547c478bd9Sstevel@tonic-gate 		add_amd_l2_tlb(devi, "l2-tlb-4K",
34557c478bd9Sstevel@tonic-gate 		    BITX(cp->cp_eax, 15, 12), BITX(cp->cp_eax, 11, 0));
34567c478bd9Sstevel@tonic-gate 	} else {
34577c478bd9Sstevel@tonic-gate 		add_amd_l2_tlb(devi, "l2-dtlb-4K",
34587c478bd9Sstevel@tonic-gate 		    BITX(cp->cp_eax, 31, 28), BITX(cp->cp_eax, 27, 16));
34597c478bd9Sstevel@tonic-gate 		add_amd_l2_tlb(devi, "l2-itlb-4K",
34607c478bd9Sstevel@tonic-gate 		    BITX(cp->cp_eax, 15, 12), BITX(cp->cp_eax, 11, 0));
34617c478bd9Sstevel@tonic-gate 	}
34627c478bd9Sstevel@tonic-gate 
34637c478bd9Sstevel@tonic-gate 	add_amd_l2_cache(devi, l2_cache_str,
34647c478bd9Sstevel@tonic-gate 	    BITX(cp->cp_ecx, 31, 16), BITX(cp->cp_ecx, 15, 12),
34657c478bd9Sstevel@tonic-gate 	    BITX(cp->cp_ecx, 11, 8), BITX(cp->cp_ecx, 7, 0));
34667c478bd9Sstevel@tonic-gate }
34677c478bd9Sstevel@tonic-gate 
34687c478bd9Sstevel@tonic-gate /*
34697c478bd9Sstevel@tonic-gate  * There are two basic ways that the x86 world describes it cache
34707c478bd9Sstevel@tonic-gate  * and tlb architecture - Intel's way and AMD's way.
34717c478bd9Sstevel@tonic-gate  *
34727c478bd9Sstevel@tonic-gate  * Return which flavor of cache architecture we should use
34737c478bd9Sstevel@tonic-gate  */
34747c478bd9Sstevel@tonic-gate static int
34757c478bd9Sstevel@tonic-gate x86_which_cacheinfo(struct cpuid_info *cpi)
34767c478bd9Sstevel@tonic-gate {
34777c478bd9Sstevel@tonic-gate 	switch (cpi->cpi_vendor) {
34787c478bd9Sstevel@tonic-gate 	case X86_VENDOR_Intel:
34797c478bd9Sstevel@tonic-gate 		if (cpi->cpi_maxeax >= 2)
34807c478bd9Sstevel@tonic-gate 			return (X86_VENDOR_Intel);
34817c478bd9Sstevel@tonic-gate 		break;
34827c478bd9Sstevel@tonic-gate 	case X86_VENDOR_AMD:
34837c478bd9Sstevel@tonic-gate 		/*
34847c478bd9Sstevel@tonic-gate 		 * The K5 model 1 was the first part from AMD that reported
34857c478bd9Sstevel@tonic-gate 		 * cache sizes via extended cpuid functions.
34867c478bd9Sstevel@tonic-gate 		 */
34877c478bd9Sstevel@tonic-gate 		if (cpi->cpi_family > 5 ||
34887c478bd9Sstevel@tonic-gate 		    (cpi->cpi_family == 5 && cpi->cpi_model >= 1))
34897c478bd9Sstevel@tonic-gate 			return (X86_VENDOR_AMD);
34907c478bd9Sstevel@tonic-gate 		break;
34917c478bd9Sstevel@tonic-gate 	case X86_VENDOR_TM:
34927c478bd9Sstevel@tonic-gate 		if (cpi->cpi_family >= 5)
34937c478bd9Sstevel@tonic-gate 			return (X86_VENDOR_AMD);
34947c478bd9Sstevel@tonic-gate 		/*FALLTHROUGH*/
34957c478bd9Sstevel@tonic-gate 	default:
34967c478bd9Sstevel@tonic-gate 		/*
34977c478bd9Sstevel@tonic-gate 		 * If they have extended CPU data for 0x80000005
34987c478bd9Sstevel@tonic-gate 		 * then we assume they have AMD-format cache
34997c478bd9Sstevel@tonic-gate 		 * information.
35007c478bd9Sstevel@tonic-gate 		 *
35017c478bd9Sstevel@tonic-gate 		 * If not, and the vendor happens to be Cyrix,
35027c478bd9Sstevel@tonic-gate 		 * then try our-Cyrix specific handler.
35037c478bd9Sstevel@tonic-gate 		 *
35047c478bd9Sstevel@tonic-gate 		 * If we're not Cyrix, then assume we're using Intel's
35057c478bd9Sstevel@tonic-gate 		 * table-driven format instead.
35067c478bd9Sstevel@tonic-gate 		 */
35077c478bd9Sstevel@tonic-gate 		if (cpi->cpi_xmaxeax >= 0x80000005)
35087c478bd9Sstevel@tonic-gate 			return (X86_VENDOR_AMD);
35097c478bd9Sstevel@tonic-gate 		else if (cpi->cpi_vendor == X86_VENDOR_Cyrix)
35107c478bd9Sstevel@tonic-gate 			return (X86_VENDOR_Cyrix);
35117c478bd9Sstevel@tonic-gate 		else if (cpi->cpi_maxeax >= 2)
35127c478bd9Sstevel@tonic-gate 			return (X86_VENDOR_Intel);
35137c478bd9Sstevel@tonic-gate 		break;
35147c478bd9Sstevel@tonic-gate 	}
35157c478bd9Sstevel@tonic-gate 	return (-1);
35167c478bd9Sstevel@tonic-gate }
35177c478bd9Sstevel@tonic-gate 
35187c478bd9Sstevel@tonic-gate /*
35197c478bd9Sstevel@tonic-gate  * create a node for the given cpu under the prom root node.
35207c478bd9Sstevel@tonic-gate  * Also, create a cpu node in the device tree.
35217c478bd9Sstevel@tonic-gate  */
35227c478bd9Sstevel@tonic-gate static dev_info_t *cpu_nex_devi = NULL;
35237c478bd9Sstevel@tonic-gate static kmutex_t cpu_node_lock;
35247c478bd9Sstevel@tonic-gate 
35257c478bd9Sstevel@tonic-gate /*
35267c478bd9Sstevel@tonic-gate  * Called from post_startup() and mp_startup()
35277c478bd9Sstevel@tonic-gate  */
35287c478bd9Sstevel@tonic-gate void
35297c478bd9Sstevel@tonic-gate add_cpunode2devtree(processorid_t cpu_id, struct cpuid_info *cpi)
35307c478bd9Sstevel@tonic-gate {
35317c478bd9Sstevel@tonic-gate 	dev_info_t *cpu_devi;
35327c478bd9Sstevel@tonic-gate 	int create;
35337c478bd9Sstevel@tonic-gate 
35347c478bd9Sstevel@tonic-gate 	mutex_enter(&cpu_node_lock);
35357c478bd9Sstevel@tonic-gate 
35367c478bd9Sstevel@tonic-gate 	/*
35377c478bd9Sstevel@tonic-gate 	 * create a nexus node for all cpus identified as 'cpu_id' under
35387c478bd9Sstevel@tonic-gate 	 * the root node.
35397c478bd9Sstevel@tonic-gate 	 */
35407c478bd9Sstevel@tonic-gate 	if (cpu_nex_devi == NULL) {
35417c478bd9Sstevel@tonic-gate 		if (ndi_devi_alloc(ddi_root_node(), "cpus",
3542fa9e4066Sahrens 		    (pnode_t)DEVI_SID_NODEID, &cpu_nex_devi) != NDI_SUCCESS) {
35437c478bd9Sstevel@tonic-gate 			mutex_exit(&cpu_node_lock);
35447c478bd9Sstevel@tonic-gate 			return;
35457c478bd9Sstevel@tonic-gate 		}
35467c478bd9Sstevel@tonic-gate 		(void) ndi_devi_online(cpu_nex_devi, 0);
35477c478bd9Sstevel@tonic-gate 	}
35487c478bd9Sstevel@tonic-gate 
35497c478bd9Sstevel@tonic-gate 	/*
35507c478bd9Sstevel@tonic-gate 	 * create a child node for cpu identified as 'cpu_id'
35517c478bd9Sstevel@tonic-gate 	 */
35527c478bd9Sstevel@tonic-gate 	cpu_devi = ddi_add_child(cpu_nex_devi, "cpu", DEVI_SID_NODEID,
35537c478bd9Sstevel@tonic-gate 	    cpu_id);
35547c478bd9Sstevel@tonic-gate 	if (cpu_devi == NULL) {
35557c478bd9Sstevel@tonic-gate 		mutex_exit(&cpu_node_lock);
35567c478bd9Sstevel@tonic-gate 		return;
35577c478bd9Sstevel@tonic-gate 	}
35587c478bd9Sstevel@tonic-gate 
35597c478bd9Sstevel@tonic-gate 	/* device_type */
35607c478bd9Sstevel@tonic-gate 
35617c478bd9Sstevel@tonic-gate 	(void) ndi_prop_update_string(DDI_DEV_T_NONE, cpu_devi,
35627c478bd9Sstevel@tonic-gate 	    "device_type", "cpu");
35637c478bd9Sstevel@tonic-gate 
35647c478bd9Sstevel@tonic-gate 	/* reg */
35657c478bd9Sstevel@tonic-gate 
35667c478bd9Sstevel@tonic-gate 	(void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi,
35677c478bd9Sstevel@tonic-gate 	    "reg", cpu_id);
35687c478bd9Sstevel@tonic-gate 
35697c478bd9Sstevel@tonic-gate 	/* cpu-mhz, and clock-frequency */
35707c478bd9Sstevel@tonic-gate 
35717c478bd9Sstevel@tonic-gate 	if (cpu_freq > 0) {
35727c478bd9Sstevel@tonic-gate 		long long mul;
35737c478bd9Sstevel@tonic-gate 
35747c478bd9Sstevel@tonic-gate 		(void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi,
35757c478bd9Sstevel@tonic-gate 		    "cpu-mhz", cpu_freq);
35767c478bd9Sstevel@tonic-gate 
35777c478bd9Sstevel@tonic-gate 		if ((mul = cpu_freq * 1000000LL) <= INT_MAX)
35787c478bd9Sstevel@tonic-gate 			(void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi,
35797c478bd9Sstevel@tonic-gate 			    "clock-frequency", (int)mul);
35807c478bd9Sstevel@tonic-gate 	}
35817c478bd9Sstevel@tonic-gate 
35827c478bd9Sstevel@tonic-gate 	(void) ndi_devi_online(cpu_devi, 0);
35837c478bd9Sstevel@tonic-gate 
35847c478bd9Sstevel@tonic-gate 	if ((x86_feature & X86_CPUID) == 0) {
35857c478bd9Sstevel@tonic-gate 		mutex_exit(&cpu_node_lock);
35867c478bd9Sstevel@tonic-gate 		return;
35877c478bd9Sstevel@tonic-gate 	}
35887c478bd9Sstevel@tonic-gate 
35897c478bd9Sstevel@tonic-gate 	/* vendor-id */
35907c478bd9Sstevel@tonic-gate 
35917c478bd9Sstevel@tonic-gate 	(void) ndi_prop_update_string(DDI_DEV_T_NONE, cpu_devi,
35927c478bd9Sstevel@tonic-gate 	    "vendor-id", cpi->cpi_vendorstr);
35937c478bd9Sstevel@tonic-gate 
35947c478bd9Sstevel@tonic-gate 	if (cpi->cpi_maxeax == 0) {
35957c478bd9Sstevel@tonic-gate 		mutex_exit(&cpu_node_lock);
35967c478bd9Sstevel@tonic-gate 		return;
35977c478bd9Sstevel@tonic-gate 	}
35987c478bd9Sstevel@tonic-gate 
35997c478bd9Sstevel@tonic-gate 	/*
36007c478bd9Sstevel@tonic-gate 	 * family, model, and step
36017c478bd9Sstevel@tonic-gate 	 */
36027c478bd9Sstevel@tonic-gate 	(void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi,
36037c478bd9Sstevel@tonic-gate 	    "family", CPI_FAMILY(cpi));
36047c478bd9Sstevel@tonic-gate 	(void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi,
36057c478bd9Sstevel@tonic-gate 	    "cpu-model", CPI_MODEL(cpi));
36067c478bd9Sstevel@tonic-gate 	(void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi,
36077c478bd9Sstevel@tonic-gate 	    "stepping-id", CPI_STEP(cpi));
36087c478bd9Sstevel@tonic-gate 
36097c478bd9Sstevel@tonic-gate 	/* type */
36107c478bd9Sstevel@tonic-gate 
36117c478bd9Sstevel@tonic-gate 	switch (cpi->cpi_vendor) {
36127c478bd9Sstevel@tonic-gate 	case X86_VENDOR_Intel:
36137c478bd9Sstevel@tonic-gate 		create = 1;
36147c478bd9Sstevel@tonic-gate 		break;
36157c478bd9Sstevel@tonic-gate 	default:
36167c478bd9Sstevel@tonic-gate 		create = 0;
36177c478bd9Sstevel@tonic-gate 		break;
36187c478bd9Sstevel@tonic-gate 	}
36197c478bd9Sstevel@tonic-gate 	if (create)
36207c478bd9Sstevel@tonic-gate 		(void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi,
36217c478bd9Sstevel@tonic-gate 		    "type", CPI_TYPE(cpi));
36227c478bd9Sstevel@tonic-gate 
36237c478bd9Sstevel@tonic-gate 	/* ext-family */
36247c478bd9Sstevel@tonic-gate 
36257c478bd9Sstevel@tonic-gate 	switch (cpi->cpi_vendor) {
36267c478bd9Sstevel@tonic-gate 	case X86_VENDOR_Intel:
36277c478bd9Sstevel@tonic-gate 	case X86_VENDOR_AMD:
36287c478bd9Sstevel@tonic-gate 		create = cpi->cpi_family >= 0xf;
36297c478bd9Sstevel@tonic-gate 		break;
36307c478bd9Sstevel@tonic-gate 	default:
36317c478bd9Sstevel@tonic-gate 		create = 0;
36327c478bd9Sstevel@tonic-gate 		break;
36337c478bd9Sstevel@tonic-gate 	}
36347c478bd9Sstevel@tonic-gate 	if (create)
36357c478bd9Sstevel@tonic-gate 		(void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi,
36367c478bd9Sstevel@tonic-gate 		    "ext-family", CPI_FAMILY_XTD(cpi));
36377c478bd9Sstevel@tonic-gate 
36387c478bd9Sstevel@tonic-gate 	/* ext-model */
36397c478bd9Sstevel@tonic-gate 
36407c478bd9Sstevel@tonic-gate 	switch (cpi->cpi_vendor) {
36417c478bd9Sstevel@tonic-gate 	case X86_VENDOR_Intel:
364263d3f7dfSkk208521 		create = IS_EXTENDED_MODEL_INTEL(cpi);
364368c91426Sdmick 		break;
36447c478bd9Sstevel@tonic-gate 	case X86_VENDOR_AMD:
3645ee88d2b9Skchow 		create = CPI_FAMILY(cpi) == 0xf;
36467c478bd9Sstevel@tonic-gate 		break;
36477c478bd9Sstevel@tonic-gate 	default:
36487c478bd9Sstevel@tonic-gate 		create = 0;
36497c478bd9Sstevel@tonic-gate 		break;
36507c478bd9Sstevel@tonic-gate 	}
36517c478bd9Sstevel@tonic-gate 	if (create)
36527c478bd9Sstevel@tonic-gate 		(void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi,
36537c478bd9Sstevel@tonic-gate 		    "ext-model", CPI_MODEL_XTD(cpi));
36547c478bd9Sstevel@tonic-gate 
36557c478bd9Sstevel@tonic-gate 	/* generation */
36567c478bd9Sstevel@tonic-gate 
36577c478bd9Sstevel@tonic-gate 	switch (cpi->cpi_vendor) {
36587c478bd9Sstevel@tonic-gate 	case X86_VENDOR_AMD:
36597c478bd9Sstevel@tonic-gate 		/*
36607c478bd9Sstevel@tonic-gate 		 * AMD K5 model 1 was the first part to support this
36617c478bd9Sstevel@tonic-gate 		 */
36627c478bd9Sstevel@tonic-gate 		create = cpi->cpi_xmaxeax >= 0x80000001;
36637c478bd9Sstevel@tonic-gate 		break;
36647c478bd9Sstevel@tonic-gate 	default:
36657c478bd9Sstevel@tonic-gate 		create = 0;
36667c478bd9Sstevel@tonic-gate 		break;
36677c478bd9Sstevel@tonic-gate 	}
36687c478bd9Sstevel@tonic-gate 	if (create)
36697c478bd9Sstevel@tonic-gate 		(void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi,
36707c478bd9Sstevel@tonic-gate 		    "generation", BITX((cpi)->cpi_extd[1].cp_eax, 11, 8));
36717c478bd9Sstevel@tonic-gate 
36727c478bd9Sstevel@tonic-gate 	/* brand-id */
36737c478bd9Sstevel@tonic-gate 
36747c478bd9Sstevel@tonic-gate 	switch (cpi->cpi_vendor) {
36757c478bd9Sstevel@tonic-gate 	case X86_VENDOR_Intel:
36767c478bd9Sstevel@tonic-gate 		/*
36777c478bd9Sstevel@tonic-gate 		 * brand id first appeared on Pentium III Xeon model 8,
36787c478bd9Sstevel@tonic-gate 		 * and Celeron model 8 processors and Opteron
36797c478bd9Sstevel@tonic-gate 		 */
36807c478bd9Sstevel@tonic-gate 		create = cpi->cpi_family > 6 ||
36817c478bd9Sstevel@tonic-gate 		    (cpi->cpi_family == 6 && cpi->cpi_model >= 8);
36827c478bd9Sstevel@tonic-gate 		break;
36837c478bd9Sstevel@tonic-gate 	case X86_VENDOR_AMD:
36847c478bd9Sstevel@tonic-gate 		create = cpi->cpi_family >= 0xf;
36857c478bd9Sstevel@tonic-gate 		break;
36867c478bd9Sstevel@tonic-gate 	default:
36877c478bd9Sstevel@tonic-gate 		create = 0;
36887c478bd9Sstevel@tonic-gate 		break;
36897c478bd9Sstevel@tonic-gate 	}
36907c478bd9Sstevel@tonic-gate 	if (create && cpi->cpi_brandid != 0) {
36917c478bd9Sstevel@tonic-gate 		(void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi,
36927c478bd9Sstevel@tonic-gate 		    "brand-id", cpi->cpi_brandid);
36937c478bd9Sstevel@tonic-gate 	}
36947c478bd9Sstevel@tonic-gate 
36957c478bd9Sstevel@tonic-gate 	/* chunks, and apic-id */
36967c478bd9Sstevel@tonic-gate 
36977c478bd9Sstevel@tonic-gate 	switch (cpi->cpi_vendor) {
36987c478bd9Sstevel@tonic-gate 		/*
36997c478bd9Sstevel@tonic-gate 		 * first available on Pentium IV and Opteron (K8)
37007c478bd9Sstevel@tonic-gate 		 */
37015ff02082Sdmick 	case X86_VENDOR_Intel:
37025ff02082Sdmick 		create = IS_NEW_F6(cpi) || cpi->cpi_family >= 0xf;
37035ff02082Sdmick 		break;
37045ff02082Sdmick 	case X86_VENDOR_AMD:
37057c478bd9Sstevel@tonic-gate 		create = cpi->cpi_family >= 0xf;
37067c478bd9Sstevel@tonic-gate 		break;
37077c478bd9Sstevel@tonic-gate 	default:
37087c478bd9Sstevel@tonic-gate 		create = 0;
37097c478bd9Sstevel@tonic-gate 		break;
37107c478bd9Sstevel@tonic-gate 	}
37117c478bd9Sstevel@tonic-gate 	if (create) {
37127c478bd9Sstevel@tonic-gate 		(void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi,
37137c478bd9Sstevel@tonic-gate 		    "chunks", CPI_CHUNKS(cpi));
37147c478bd9Sstevel@tonic-gate 		(void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi,
3715*b6917abeSmishra 		    "apic-id", cpi->cpi_apicid);
37167aec1d6eScindi 		if (cpi->cpi_chipid >= 0) {
37177c478bd9Sstevel@tonic-gate 			(void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi,
37187c478bd9Sstevel@tonic-gate 			    "chip#", cpi->cpi_chipid);
37197aec1d6eScindi 			(void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi,
37207aec1d6eScindi 			    "clog#", cpi->cpi_clogid);
37217aec1d6eScindi 		}
37227c478bd9Sstevel@tonic-gate 	}
37237c478bd9Sstevel@tonic-gate 
37247c478bd9Sstevel@tonic-gate 	/* cpuid-features */
37257c478bd9Sstevel@tonic-gate 
37267c478bd9Sstevel@tonic-gate 	(void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi,
37277c478bd9Sstevel@tonic-gate 	    "cpuid-features", CPI_FEATURES_EDX(cpi));
37287c478bd9Sstevel@tonic-gate 
37297c478bd9Sstevel@tonic-gate 
37307c478bd9Sstevel@tonic-gate 	/* cpuid-features-ecx */
37317c478bd9Sstevel@tonic-gate 
37327c478bd9Sstevel@tonic-gate 	switch (cpi->cpi_vendor) {
37337c478bd9Sstevel@tonic-gate 	case X86_VENDOR_Intel:
37345ff02082Sdmick 		create = IS_NEW_F6(cpi) || cpi->cpi_family >= 0xf;
37357c478bd9Sstevel@tonic-gate 		break;
37367c478bd9Sstevel@tonic-gate 	default:
37377c478bd9Sstevel@tonic-gate 		create = 0;
37387c478bd9Sstevel@tonic-gate 		break;
37397c478bd9Sstevel@tonic-gate 	}
37407c478bd9Sstevel@tonic-gate 	if (create)
37417c478bd9Sstevel@tonic-gate 		(void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi,
37427c478bd9Sstevel@tonic-gate 		    "cpuid-features-ecx", CPI_FEATURES_ECX(cpi));
37437c478bd9Sstevel@tonic-gate 
37447c478bd9Sstevel@tonic-gate 	/* ext-cpuid-features */
37457c478bd9Sstevel@tonic-gate 
37467c478bd9Sstevel@tonic-gate 	switch (cpi->cpi_vendor) {
37475ff02082Sdmick 	case X86_VENDOR_Intel:
37487c478bd9Sstevel@tonic-gate 	case X86_VENDOR_AMD:
37497c478bd9Sstevel@tonic-gate 	case X86_VENDOR_Cyrix:
37507c478bd9Sstevel@tonic-gate 	case X86_VENDOR_TM:
37517c478bd9Sstevel@tonic-gate 	case X86_VENDOR_Centaur:
37527c478bd9Sstevel@tonic-gate 		create = cpi->cpi_xmaxeax >= 0x80000001;
37537c478bd9Sstevel@tonic-gate 		break;
37547c478bd9Sstevel@tonic-gate 	default:
37557c478bd9Sstevel@tonic-gate 		create = 0;
37567c478bd9Sstevel@tonic-gate 		break;
37577c478bd9Sstevel@tonic-gate 	}
37585ff02082Sdmick 	if (create) {
37597c478bd9Sstevel@tonic-gate 		(void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi,
37607c478bd9Sstevel@tonic-gate 		    "ext-cpuid-features", CPI_FEATURES_XTD_EDX(cpi));
37615ff02082Sdmick 		(void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi,
37625ff02082Sdmick 		    "ext-cpuid-features-ecx", CPI_FEATURES_XTD_ECX(cpi));
37635ff02082Sdmick 	}
37647c478bd9Sstevel@tonic-gate 
37657c478bd9Sstevel@tonic-gate 	/*
37667c478bd9Sstevel@tonic-gate 	 * Brand String first appeared in Intel Pentium IV, AMD K5
37677c478bd9Sstevel@tonic-gate 	 * model 1, and Cyrix GXm.  On earlier models we try and
37687c478bd9Sstevel@tonic-gate 	 * simulate something similar .. so this string should always
37697c478bd9Sstevel@tonic-gate 	 * same -something- about the processor, however lame.
37707c478bd9Sstevel@tonic-gate 	 */
37717c478bd9Sstevel@tonic-gate 	(void) ndi_prop_update_string(DDI_DEV_T_NONE, cpu_devi,
37727c478bd9Sstevel@tonic-gate 	    "brand-string", cpi->cpi_brandstr);
37737c478bd9Sstevel@tonic-gate 
37747c478bd9Sstevel@tonic-gate 	/*
37757c478bd9Sstevel@tonic-gate 	 * Finally, cache and tlb information
37767c478bd9Sstevel@tonic-gate 	 */
37777c478bd9Sstevel@tonic-gate 	switch (x86_which_cacheinfo(cpi)) {
37787c478bd9Sstevel@tonic-gate 	case X86_VENDOR_Intel:
37797c478bd9Sstevel@tonic-gate 		intel_walk_cacheinfo(cpi, cpu_devi, add_cacheent_props);
37807c478bd9Sstevel@tonic-gate 		break;
37817c478bd9Sstevel@tonic-gate 	case X86_VENDOR_Cyrix:
37827c478bd9Sstevel@tonic-gate 		cyrix_walk_cacheinfo(cpi, cpu_devi, add_cacheent_props);
37837c478bd9Sstevel@tonic-gate 		break;
37847c478bd9Sstevel@tonic-gate 	case X86_VENDOR_AMD:
37857c478bd9Sstevel@tonic-gate 		amd_cache_info(cpi, cpu_devi);
37867c478bd9Sstevel@tonic-gate 		break;
37877c478bd9Sstevel@tonic-gate 	default:
37887c478bd9Sstevel@tonic-gate 		break;
37897c478bd9Sstevel@tonic-gate 	}
37907c478bd9Sstevel@tonic-gate 
37917c478bd9Sstevel@tonic-gate 	mutex_exit(&cpu_node_lock);
37927c478bd9Sstevel@tonic-gate }
37937c478bd9Sstevel@tonic-gate 
37947c478bd9Sstevel@tonic-gate struct l2info {
37957c478bd9Sstevel@tonic-gate 	int *l2i_csz;
37967c478bd9Sstevel@tonic-gate 	int *l2i_lsz;
37977c478bd9Sstevel@tonic-gate 	int *l2i_assoc;
37987c478bd9Sstevel@tonic-gate 	int l2i_ret;
37997c478bd9Sstevel@tonic-gate };
38007c478bd9Sstevel@tonic-gate 
38017c478bd9Sstevel@tonic-gate /*
38027c478bd9Sstevel@tonic-gate  * A cacheinfo walker that fetches the size, line-size and associativity
38037c478bd9Sstevel@tonic-gate  * of the L2 cache
38047c478bd9Sstevel@tonic-gate  */
38057c478bd9Sstevel@tonic-gate static int
38067c478bd9Sstevel@tonic-gate intel_l2cinfo(void *arg, const struct cachetab *ct)
38077c478bd9Sstevel@tonic-gate {
38087c478bd9Sstevel@tonic-gate 	struct l2info *l2i = arg;
38097c478bd9Sstevel@tonic-gate 	int *ip;
38107c478bd9Sstevel@tonic-gate 
38117c478bd9Sstevel@tonic-gate 	if (ct->ct_label != l2_cache_str &&
38127c478bd9Sstevel@tonic-gate 	    ct->ct_label != sl2_cache_str)
38137c478bd9Sstevel@tonic-gate 		return (0);	/* not an L2 -- keep walking */
38147c478bd9Sstevel@tonic-gate 
38157c478bd9Sstevel@tonic-gate 	if ((ip = l2i->l2i_csz) != NULL)
38167c478bd9Sstevel@tonic-gate 		*ip = ct->ct_size;
38177c478bd9Sstevel@tonic-gate 	if ((ip = l2i->l2i_lsz) != NULL)
38187c478bd9Sstevel@tonic-gate 		*ip = ct->ct_line_size;
38197c478bd9Sstevel@tonic-gate 	if ((ip = l2i->l2i_assoc) != NULL)
38207c478bd9Sstevel@tonic-gate 		*ip = ct->ct_assoc;
38217c478bd9Sstevel@tonic-gate 	l2i->l2i_ret = ct->ct_size;
38227c478bd9Sstevel@tonic-gate 	return (1);		/* was an L2 -- terminate walk */
38237c478bd9Sstevel@tonic-gate }
38247c478bd9Sstevel@tonic-gate 
3825606303c9Skchow /*
3826606303c9Skchow  * AMD L2/L3 Cache and TLB Associativity Field Definition:
3827606303c9Skchow  *
3828606303c9Skchow  *	Unlike the associativity for the L1 cache and tlb where the 8 bit
3829606303c9Skchow  *	value is the associativity, the associativity for the L2 cache and
3830606303c9Skchow  *	tlb is encoded in the following table. The 4 bit L2 value serves as
3831606303c9Skchow  *	an index into the amd_afd[] array to determine the associativity.
3832606303c9Skchow  *	-1 is undefined. 0 is fully associative.
3833606303c9Skchow  */
3834606303c9Skchow 
3835606303c9Skchow static int amd_afd[] =
3836606303c9Skchow 	{-1, 1, 2, -1, 4, -1, 8, -1, 16, -1, 32, 48, 64, 96, 128, 0};
3837606303c9Skchow 
38387c478bd9Sstevel@tonic-gate static void
38397c478bd9Sstevel@tonic-gate amd_l2cacheinfo(struct cpuid_info *cpi, struct l2info *l2i)
38407c478bd9Sstevel@tonic-gate {
38418949bcd6Sandrei 	struct cpuid_regs *cp;
38427c478bd9Sstevel@tonic-gate 	uint_t size, assoc;
3843606303c9Skchow 	int i;
38447c478bd9Sstevel@tonic-gate 	int *ip;
38457c478bd9Sstevel@tonic-gate 
38467c478bd9Sstevel@tonic-gate 	if (cpi->cpi_xmaxeax < 0x80000006)
38477c478bd9Sstevel@tonic-gate 		return;
38487c478bd9Sstevel@tonic-gate 	cp = &cpi->cpi_extd[6];
38497c478bd9Sstevel@tonic-gate 
3850606303c9Skchow 	if ((i = BITX(cp->cp_ecx, 15, 12)) != 0 &&
38517c478bd9Sstevel@tonic-gate 	    (size = BITX(cp->cp_ecx, 31, 16)) != 0) {
38527c478bd9Sstevel@tonic-gate 		uint_t cachesz = size * 1024;
3853606303c9Skchow 		assoc = amd_afd[i];
38547c478bd9Sstevel@tonic-gate 
3855606303c9Skchow 		ASSERT(assoc != -1);
38567c478bd9Sstevel@tonic-gate 
38577c478bd9Sstevel@tonic-gate 		if ((ip = l2i->l2i_csz) != NULL)
38587c478bd9Sstevel@tonic-gate 			*ip = cachesz;
38597c478bd9Sstevel@tonic-gate 		if ((ip = l2i->l2i_lsz) != NULL)
38607c478bd9Sstevel@tonic-gate 			*ip = BITX(cp->cp_ecx, 7, 0);
38617c478bd9Sstevel@tonic-gate 		if ((ip = l2i->l2i_assoc) != NULL)
38627c478bd9Sstevel@tonic-gate 			*ip = assoc;
38637c478bd9Sstevel@tonic-gate 		l2i->l2i_ret = cachesz;
38647c478bd9Sstevel@tonic-gate 	}
38657c478bd9Sstevel@tonic-gate }
38667c478bd9Sstevel@tonic-gate 
38677c478bd9Sstevel@tonic-gate int
38687c478bd9Sstevel@tonic-gate getl2cacheinfo(cpu_t *cpu, int *csz, int *lsz, int *assoc)
38697c478bd9Sstevel@tonic-gate {
38707c478bd9Sstevel@tonic-gate 	struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi;
38717c478bd9Sstevel@tonic-gate 	struct l2info __l2info, *l2i = &__l2info;
38727c478bd9Sstevel@tonic-gate 
38737c478bd9Sstevel@tonic-gate 	l2i->l2i_csz = csz;
38747c478bd9Sstevel@tonic-gate 	l2i->l2i_lsz = lsz;
38757c478bd9Sstevel@tonic-gate 	l2i->l2i_assoc = assoc;
38767c478bd9Sstevel@tonic-gate 	l2i->l2i_ret = -1;
38777c478bd9Sstevel@tonic-gate 
38787c478bd9Sstevel@tonic-gate 	switch (x86_which_cacheinfo(cpi)) {
38797c478bd9Sstevel@tonic-gate 	case X86_VENDOR_Intel:
38807c478bd9Sstevel@tonic-gate 		intel_walk_cacheinfo(cpi, l2i, intel_l2cinfo);
38817c478bd9Sstevel@tonic-gate 		break;
38827c478bd9Sstevel@tonic-gate 	case X86_VENDOR_Cyrix:
38837c478bd9Sstevel@tonic-gate 		cyrix_walk_cacheinfo(cpi, l2i, intel_l2cinfo);
38847c478bd9Sstevel@tonic-gate 		break;
38857c478bd9Sstevel@tonic-gate 	case X86_VENDOR_AMD:
38867c478bd9Sstevel@tonic-gate 		amd_l2cacheinfo(cpi, l2i);
38877c478bd9Sstevel@tonic-gate 		break;
38887c478bd9Sstevel@tonic-gate 	default:
38897c478bd9Sstevel@tonic-gate 		break;
38907c478bd9Sstevel@tonic-gate 	}
38917c478bd9Sstevel@tonic-gate 	return (l2i->l2i_ret);
38927c478bd9Sstevel@tonic-gate }
3893f98fbcecSbholler 
3894843e1988Sjohnlev #if !defined(__xpv)
3895843e1988Sjohnlev 
38965b8a6efeSbholler uint32_t *
38975b8a6efeSbholler cpuid_mwait_alloc(cpu_t *cpu)
38985b8a6efeSbholler {
38995b8a6efeSbholler 	uint32_t	*ret;
39005b8a6efeSbholler 	size_t		mwait_size;
39015b8a6efeSbholler 
39025b8a6efeSbholler 	ASSERT(cpuid_checkpass(cpu, 2));
39035b8a6efeSbholler 
39045b8a6efeSbholler 	mwait_size = cpu->cpu_m.mcpu_cpi->cpi_mwait.mon_max;
39055b8a6efeSbholler 	if (mwait_size == 0)
39065b8a6efeSbholler 		return (NULL);
39075b8a6efeSbholler 
39085b8a6efeSbholler 	/*
39095b8a6efeSbholler 	 * kmem_alloc() returns cache line size aligned data for mwait_size
39105b8a6efeSbholler 	 * allocations.  mwait_size is currently cache line sized.  Neither
39115b8a6efeSbholler 	 * of these implementation details are guarantied to be true in the
39125b8a6efeSbholler 	 * future.
39135b8a6efeSbholler 	 *
39145b8a6efeSbholler 	 * First try allocating mwait_size as kmem_alloc() currently returns
39155b8a6efeSbholler 	 * correctly aligned memory.  If kmem_alloc() does not return
39165b8a6efeSbholler 	 * mwait_size aligned memory, then use mwait_size ROUNDUP.
39175b8a6efeSbholler 	 *
39185b8a6efeSbholler 	 * Set cpi_mwait.buf_actual and cpi_mwait.size_actual in case we
39195b8a6efeSbholler 	 * decide to free this memory.
39205b8a6efeSbholler 	 */
39215b8a6efeSbholler 	ret = kmem_zalloc(mwait_size, KM_SLEEP);
39225b8a6efeSbholler 	if (ret == (uint32_t *)P2ROUNDUP((uintptr_t)ret, mwait_size)) {
39235b8a6efeSbholler 		cpu->cpu_m.mcpu_cpi->cpi_mwait.buf_actual = ret;
39245b8a6efeSbholler 		cpu->cpu_m.mcpu_cpi->cpi_mwait.size_actual = mwait_size;
39255b8a6efeSbholler 		*ret = MWAIT_RUNNING;
39265b8a6efeSbholler 		return (ret);
39275b8a6efeSbholler 	} else {
39285b8a6efeSbholler 		kmem_free(ret, mwait_size);
39295b8a6efeSbholler 		ret = kmem_zalloc(mwait_size * 2, KM_SLEEP);
39305b8a6efeSbholler 		cpu->cpu_m.mcpu_cpi->cpi_mwait.buf_actual = ret;
39315b8a6efeSbholler 		cpu->cpu_m.mcpu_cpi->cpi_mwait.size_actual = mwait_size * 2;
39325b8a6efeSbholler 		ret = (uint32_t *)P2ROUNDUP((uintptr_t)ret, mwait_size);
39335b8a6efeSbholler 		*ret = MWAIT_RUNNING;
39345b8a6efeSbholler 		return (ret);
39355b8a6efeSbholler 	}
39365b8a6efeSbholler }
39375b8a6efeSbholler 
39385b8a6efeSbholler void
39395b8a6efeSbholler cpuid_mwait_free(cpu_t *cpu)
3940f98fbcecSbholler {
3941f98fbcecSbholler 	ASSERT(cpuid_checkpass(cpu, 2));
39425b8a6efeSbholler 
39435b8a6efeSbholler 	if (cpu->cpu_m.mcpu_cpi->cpi_mwait.buf_actual != NULL &&
39445b8a6efeSbholler 	    cpu->cpu_m.mcpu_cpi->cpi_mwait.size_actual > 0) {
39455b8a6efeSbholler 		kmem_free(cpu->cpu_m.mcpu_cpi->cpi_mwait.buf_actual,
39465b8a6efeSbholler 		    cpu->cpu_m.mcpu_cpi->cpi_mwait.size_actual);
39475b8a6efeSbholler 	}
39485b8a6efeSbholler 
39495b8a6efeSbholler 	cpu->cpu_m.mcpu_cpi->cpi_mwait.buf_actual = NULL;
39505b8a6efeSbholler 	cpu->cpu_m.mcpu_cpi->cpi_mwait.size_actual = 0;
3951f98fbcecSbholler }
3952843e1988Sjohnlev 
3953247dbb3dSsudheer void
3954247dbb3dSsudheer patch_tsc_read(int flag)
3955247dbb3dSsudheer {
3956247dbb3dSsudheer 	size_t cnt;
3957247dbb3dSsudheer 	switch (flag) {
3958247dbb3dSsudheer 	case X86_NO_TSC:
3959247dbb3dSsudheer 		cnt = &_no_rdtsc_end - &_no_rdtsc_start;
39602b0bcb26Ssudheer 		(void) memcpy((void *)tsc_read, (void *)&_no_rdtsc_start, cnt);
3961247dbb3dSsudheer 		break;
3962247dbb3dSsudheer 	case X86_HAVE_TSCP:
3963247dbb3dSsudheer 		cnt = &_tscp_end - &_tscp_start;
39642b0bcb26Ssudheer 		(void) memcpy((void *)tsc_read, (void *)&_tscp_start, cnt);
3965247dbb3dSsudheer 		break;
3966247dbb3dSsudheer 	case X86_TSC_MFENCE:
3967247dbb3dSsudheer 		cnt = &_tsc_mfence_end - &_tsc_mfence_start;
39682b0bcb26Ssudheer 		(void) memcpy((void *)tsc_read,
39692b0bcb26Ssudheer 		    (void *)&_tsc_mfence_start, cnt);
3970247dbb3dSsudheer 		break;
397115363b27Ssudheer 	case X86_TSC_LFENCE:
397215363b27Ssudheer 		cnt = &_tsc_lfence_end - &_tsc_lfence_start;
397315363b27Ssudheer 		(void) memcpy((void *)tsc_read,
397415363b27Ssudheer 		    (void *)&_tsc_lfence_start, cnt);
397515363b27Ssudheer 		break;
3976247dbb3dSsudheer 	default:
3977247dbb3dSsudheer 		break;
3978247dbb3dSsudheer 	}
3979247dbb3dSsudheer }
3980247dbb3dSsudheer 
3981843e1988Sjohnlev #endif	/* !__xpv */
3982