xref: /titanic_52/usr/src/uts/i86pc/os/cpuid.c (revision 8949bcd619d78e849deef983cb8310bc3aa3e242)
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
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
23*8949bcd6Sandrei  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate /*
307c478bd9Sstevel@tonic-gate  * Various routines to handle identification
317c478bd9Sstevel@tonic-gate  * and classification of x86 processors.
327c478bd9Sstevel@tonic-gate  */
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate #include <sys/types.h>
357c478bd9Sstevel@tonic-gate #include <sys/archsystm.h>
367c478bd9Sstevel@tonic-gate #include <sys/x86_archext.h>
377c478bd9Sstevel@tonic-gate #include <sys/kmem.h>
387c478bd9Sstevel@tonic-gate #include <sys/systm.h>
397c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h>
407c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
417c478bd9Sstevel@tonic-gate #include <sys/sunndi.h>
427c478bd9Sstevel@tonic-gate #include <sys/cpuvar.h>
437c478bd9Sstevel@tonic-gate #include <sys/processor.h>
447c478bd9Sstevel@tonic-gate #include <sys/chip.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/controlregs.h>
507c478bd9Sstevel@tonic-gate #include <sys/memnode.h>
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate /*
537c478bd9Sstevel@tonic-gate  * Pass 0 of cpuid feature analysis happens in locore. It contains special code
547c478bd9Sstevel@tonic-gate  * to recognize Cyrix processors that are not cpuid-compliant, and to deal with
557c478bd9Sstevel@tonic-gate  * them accordingly. For most modern processors, feature detection occurs here
567c478bd9Sstevel@tonic-gate  * in pass 1.
577c478bd9Sstevel@tonic-gate  *
587c478bd9Sstevel@tonic-gate  * Pass 1 of cpuid feature analysis happens just at the beginning of mlsetup()
597c478bd9Sstevel@tonic-gate  * for the boot CPU and does the basic analysis that the early kernel needs.
607c478bd9Sstevel@tonic-gate  * x86_feature is set based on the return value of cpuid_pass1() of the boot
617c478bd9Sstevel@tonic-gate  * CPU.
627c478bd9Sstevel@tonic-gate  *
637c478bd9Sstevel@tonic-gate  * Pass 1 includes:
647c478bd9Sstevel@tonic-gate  *
657c478bd9Sstevel@tonic-gate  *	o Determining vendor/model/family/stepping and setting x86_type and
667c478bd9Sstevel@tonic-gate  *	  x86_vendor accordingly.
677c478bd9Sstevel@tonic-gate  *	o Processing the feature flags returned by the cpuid instruction while
687c478bd9Sstevel@tonic-gate  *	  applying any workarounds or tricks for the specific processor.
697c478bd9Sstevel@tonic-gate  *	o Mapping the feature flags into Solaris feature bits (X86_*).
707c478bd9Sstevel@tonic-gate  *	o Processing extended feature flags if supported by the processor,
717c478bd9Sstevel@tonic-gate  *	  again while applying specific processor knowledge.
727c478bd9Sstevel@tonic-gate  *	o Determining the CMT characteristics of the system.
737c478bd9Sstevel@tonic-gate  *
747c478bd9Sstevel@tonic-gate  * Pass 1 is done on non-boot CPUs during their initialization and the results
757c478bd9Sstevel@tonic-gate  * are used only as a meager attempt at ensuring that all processors within the
767c478bd9Sstevel@tonic-gate  * system support the same features.
777c478bd9Sstevel@tonic-gate  *
787c478bd9Sstevel@tonic-gate  * Pass 2 of cpuid feature analysis happens just at the beginning
797c478bd9Sstevel@tonic-gate  * of startup().  It just copies in and corrects the remainder
807c478bd9Sstevel@tonic-gate  * of the cpuid data we depend on: standard cpuid functions that we didn't
817c478bd9Sstevel@tonic-gate  * need for pass1 feature analysis, and extended cpuid functions beyond the
827c478bd9Sstevel@tonic-gate  * simple feature processing done in pass1.
837c478bd9Sstevel@tonic-gate  *
847c478bd9Sstevel@tonic-gate  * Pass 3 of cpuid analysis is invoked after basic kernel services; in
857c478bd9Sstevel@tonic-gate  * particular kernel memory allocation has been made available. It creates a
867c478bd9Sstevel@tonic-gate  * readable brand string based on the data collected in the first two passes.
877c478bd9Sstevel@tonic-gate  *
887c478bd9Sstevel@tonic-gate  * Pass 4 of cpuid analysis is invoked after post_startup() when all
897c478bd9Sstevel@tonic-gate  * the support infrastructure for various hardware features has been
907c478bd9Sstevel@tonic-gate  * initialized. It determines which processor features will be reported
917c478bd9Sstevel@tonic-gate  * to userland via the aux vector.
927c478bd9Sstevel@tonic-gate  *
937c478bd9Sstevel@tonic-gate  * All passes are executed on all CPUs, but only the boot CPU determines what
947c478bd9Sstevel@tonic-gate  * features the kernel will use.
957c478bd9Sstevel@tonic-gate  *
967c478bd9Sstevel@tonic-gate  * Much of the worst junk in this file is for the support of processors
977c478bd9Sstevel@tonic-gate  * that didn't really implement the cpuid instruction properly.
987c478bd9Sstevel@tonic-gate  *
997c478bd9Sstevel@tonic-gate  * NOTE: The accessor functions (cpuid_get*) are aware of, and ASSERT upon,
1007c478bd9Sstevel@tonic-gate  * the pass numbers.  Accordingly, changes to the pass code may require changes
1017c478bd9Sstevel@tonic-gate  * to the accessor code.
1027c478bd9Sstevel@tonic-gate  */
1037c478bd9Sstevel@tonic-gate 
1047c478bd9Sstevel@tonic-gate uint_t x86_feature = 0;
1057c478bd9Sstevel@tonic-gate uint_t x86_vendor = X86_VENDOR_IntelClone;
1067c478bd9Sstevel@tonic-gate uint_t x86_type = X86_TYPE_OTHER;
1077c478bd9Sstevel@tonic-gate 
1087c478bd9Sstevel@tonic-gate ulong_t cr4_value;
1097c478bd9Sstevel@tonic-gate uint_t pentiumpro_bug4046376;
1107c478bd9Sstevel@tonic-gate uint_t pentiumpro_bug4064495;
1117c478bd9Sstevel@tonic-gate 
1127c478bd9Sstevel@tonic-gate uint_t enable486;
1137c478bd9Sstevel@tonic-gate 
1147c478bd9Sstevel@tonic-gate /*
1157c478bd9Sstevel@tonic-gate  * This set of strings are for processors rumored to support the cpuid
1167c478bd9Sstevel@tonic-gate  * instruction, and is used by locore.s to figure out how to set x86_vendor
1177c478bd9Sstevel@tonic-gate  */
1187c478bd9Sstevel@tonic-gate const char CyrixInstead[] = "CyrixInstead";
1197c478bd9Sstevel@tonic-gate 
1207c478bd9Sstevel@tonic-gate /*
1217c478bd9Sstevel@tonic-gate  * These constants determine how many of the elements of the
1227c478bd9Sstevel@tonic-gate  * cpuid we cache in the cpuid_info data structure; the
1237c478bd9Sstevel@tonic-gate  * remaining elements are accessible via the cpuid instruction.
1247c478bd9Sstevel@tonic-gate  */
1257c478bd9Sstevel@tonic-gate 
1267c478bd9Sstevel@tonic-gate #define	NMAX_CPI_STD	6		/* eax = 0 .. 5 */
1277c478bd9Sstevel@tonic-gate #define	NMAX_CPI_EXTD	9		/* eax = 0x80000000 .. 0x80000008 */
1287c478bd9Sstevel@tonic-gate 
1297c478bd9Sstevel@tonic-gate struct cpuid_info {
1307c478bd9Sstevel@tonic-gate 	uint_t cpi_pass;		/* last pass completed */
1317c478bd9Sstevel@tonic-gate 	/*
1327c478bd9Sstevel@tonic-gate 	 * standard function information
1337c478bd9Sstevel@tonic-gate 	 */
1347c478bd9Sstevel@tonic-gate 	uint_t cpi_maxeax;		/* fn 0: %eax */
1357c478bd9Sstevel@tonic-gate 	char cpi_vendorstr[13];		/* fn 0: %ebx:%ecx:%edx */
1367c478bd9Sstevel@tonic-gate 	uint_t cpi_vendor;		/* enum of cpi_vendorstr */
1377c478bd9Sstevel@tonic-gate 
1387c478bd9Sstevel@tonic-gate 	uint_t cpi_family;		/* fn 1: extended family */
1397c478bd9Sstevel@tonic-gate 	uint_t cpi_model;		/* fn 1: extended model */
1407c478bd9Sstevel@tonic-gate 	uint_t cpi_step;		/* fn 1: stepping */
1417c478bd9Sstevel@tonic-gate 	chipid_t cpi_chipid;		/* fn 1: %ebx: chip # on ht cpus */
1427c478bd9Sstevel@tonic-gate 	uint_t cpi_brandid;		/* fn 1: %ebx: brand ID */
1437c478bd9Sstevel@tonic-gate 	int cpi_clogid;			/* fn 1: %ebx: thread # */
144*8949bcd6Sandrei 	uint_t cpi_ncpu_per_chip;	/* fn 1: %ebx: logical cpu count */
1457c478bd9Sstevel@tonic-gate 	uint8_t cpi_cacheinfo[16];	/* fn 2: intel-style cache desc */
1467c478bd9Sstevel@tonic-gate 	uint_t cpi_ncache;		/* fn 2: number of elements */
147*8949bcd6Sandrei 	struct cpuid_regs cpi_std[NMAX_CPI_STD];	/* 0 .. 5 */
1487c478bd9Sstevel@tonic-gate 	/*
1497c478bd9Sstevel@tonic-gate 	 * extended function information
1507c478bd9Sstevel@tonic-gate 	 */
1517c478bd9Sstevel@tonic-gate 	uint_t cpi_xmaxeax;		/* fn 0x80000000: %eax */
1527c478bd9Sstevel@tonic-gate 	char cpi_brandstr[49];		/* fn 0x8000000[234] */
1537c478bd9Sstevel@tonic-gate 	uint8_t cpi_pabits;		/* fn 0x80000006: %eax */
1547c478bd9Sstevel@tonic-gate 	uint8_t cpi_vabits;		/* fn 0x80000006: %eax */
155*8949bcd6Sandrei 	struct cpuid_regs cpi_extd[NMAX_CPI_EXTD]; /* 0x8000000[0-8] */
156*8949bcd6Sandrei 	id_t cpi_coreid;
157*8949bcd6Sandrei 	uint_t cpi_ncore_per_chip;	/* AMD: fn 0x80000008: %ecx[7-0] */
158*8949bcd6Sandrei 					/* Intel: fn 4: %eax[31-26] */
1597c478bd9Sstevel@tonic-gate 	/*
1607c478bd9Sstevel@tonic-gate 	 * supported feature information
1617c478bd9Sstevel@tonic-gate 	 */
1627c478bd9Sstevel@tonic-gate 	uint32_t cpi_support[4];
1637c478bd9Sstevel@tonic-gate #define	STD_EDX_FEATURES	0
1647c478bd9Sstevel@tonic-gate #define	AMD_EDX_FEATURES	1
1657c478bd9Sstevel@tonic-gate #define	TM_EDX_FEATURES		2
1667c478bd9Sstevel@tonic-gate #define	STD_ECX_FEATURES	3
1677c478bd9Sstevel@tonic-gate 
1687c478bd9Sstevel@tonic-gate };
1697c478bd9Sstevel@tonic-gate 
1707c478bd9Sstevel@tonic-gate 
1717c478bd9Sstevel@tonic-gate static struct cpuid_info cpuid_info0;
1727c478bd9Sstevel@tonic-gate 
1737c478bd9Sstevel@tonic-gate /*
1747c478bd9Sstevel@tonic-gate  * These bit fields are defined by the Intel Application Note AP-485
1757c478bd9Sstevel@tonic-gate  * "Intel Processor Identification and the CPUID Instruction"
1767c478bd9Sstevel@tonic-gate  */
1777c478bd9Sstevel@tonic-gate #define	CPI_FAMILY_XTD(cpi)	BITX((cpi)->cpi_std[1].cp_eax, 27, 20)
1787c478bd9Sstevel@tonic-gate #define	CPI_MODEL_XTD(cpi)	BITX((cpi)->cpi_std[1].cp_eax, 19, 16)
1797c478bd9Sstevel@tonic-gate #define	CPI_TYPE(cpi)		BITX((cpi)->cpi_std[1].cp_eax, 13, 12)
1807c478bd9Sstevel@tonic-gate #define	CPI_FAMILY(cpi)		BITX((cpi)->cpi_std[1].cp_eax, 11, 8)
1817c478bd9Sstevel@tonic-gate #define	CPI_STEP(cpi)		BITX((cpi)->cpi_std[1].cp_eax, 3, 0)
1827c478bd9Sstevel@tonic-gate #define	CPI_MODEL(cpi)		BITX((cpi)->cpi_std[1].cp_eax, 7, 4)
1837c478bd9Sstevel@tonic-gate 
1847c478bd9Sstevel@tonic-gate #define	CPI_FEATURES_EDX(cpi)		((cpi)->cpi_std[1].cp_edx)
1857c478bd9Sstevel@tonic-gate #define	CPI_FEATURES_ECX(cpi)		((cpi)->cpi_std[1].cp_ecx)
1867c478bd9Sstevel@tonic-gate #define	CPI_FEATURES_XTD_EDX(cpi)	((cpi)->cpi_extd[1].cp_edx)
1877c478bd9Sstevel@tonic-gate #define	CPI_FEATURES_XTD_ECX(cpi)	((cpi)->cpi_extd[1].cp_ecx)
1887c478bd9Sstevel@tonic-gate 
1897c478bd9Sstevel@tonic-gate #define	CPI_BRANDID(cpi)	BITX((cpi)->cpi_std[1].cp_ebx, 7, 0)
1907c478bd9Sstevel@tonic-gate #define	CPI_CHUNKS(cpi)		BITX((cpi)->cpi_std[1].cp_ebx, 15, 7)
1917c478bd9Sstevel@tonic-gate #define	CPI_CPU_COUNT(cpi)	BITX((cpi)->cpi_std[1].cp_ebx, 23, 16)
1927c478bd9Sstevel@tonic-gate #define	CPI_APIC_ID(cpi)	BITX((cpi)->cpi_std[1].cp_ebx, 31, 24)
1937c478bd9Sstevel@tonic-gate 
1947c478bd9Sstevel@tonic-gate #define	CPI_MAXEAX_MAX		0x100		/* sanity control */
1957c478bd9Sstevel@tonic-gate #define	CPI_XMAXEAX_MAX		0x80000100
1967c478bd9Sstevel@tonic-gate 
1977c478bd9Sstevel@tonic-gate /*
1987c478bd9Sstevel@tonic-gate  *  Some undocumented ways of patching the results of the cpuid
1997c478bd9Sstevel@tonic-gate  *  instruction to permit running Solaris 10 on future cpus that
2007c478bd9Sstevel@tonic-gate  *  we don't currently support.  Could be set to non-zero values
2017c478bd9Sstevel@tonic-gate  *  via settings in eeprom.
2027c478bd9Sstevel@tonic-gate  */
2037c478bd9Sstevel@tonic-gate 
2047c478bd9Sstevel@tonic-gate uint32_t cpuid_feature_ecx_include;
2057c478bd9Sstevel@tonic-gate uint32_t cpuid_feature_ecx_exclude;
2067c478bd9Sstevel@tonic-gate uint32_t cpuid_feature_edx_include;
2077c478bd9Sstevel@tonic-gate uint32_t cpuid_feature_edx_exclude;
2087c478bd9Sstevel@tonic-gate 
2097c478bd9Sstevel@tonic-gate uint_t
2107c478bd9Sstevel@tonic-gate cpuid_pass1(cpu_t *cpu)
2117c478bd9Sstevel@tonic-gate {
2127c478bd9Sstevel@tonic-gate 	uint32_t mask_ecx, mask_edx;
2137c478bd9Sstevel@tonic-gate 	uint_t feature = X86_CPUID;
2147c478bd9Sstevel@tonic-gate 	struct cpuid_info *cpi;
215*8949bcd6Sandrei 	struct cpuid_regs *cp;
2167c478bd9Sstevel@tonic-gate 	int xcpuid;
2177c478bd9Sstevel@tonic-gate 
2187c478bd9Sstevel@tonic-gate 	/*
2197c478bd9Sstevel@tonic-gate 	 * By convention, cpu0 is the boot cpu, which is called
2207c478bd9Sstevel@tonic-gate 	 * before memory allocation is available.  Other cpus are
2217c478bd9Sstevel@tonic-gate 	 * initialized when memory becomes available.
2227c478bd9Sstevel@tonic-gate 	 */
2237c478bd9Sstevel@tonic-gate 	if (cpu->cpu_id == 0)
2247c478bd9Sstevel@tonic-gate 		cpu->cpu_m.mcpu_cpi = cpi = &cpuid_info0;
2257c478bd9Sstevel@tonic-gate 	else
2267c478bd9Sstevel@tonic-gate 		cpu->cpu_m.mcpu_cpi = cpi =
2277c478bd9Sstevel@tonic-gate 		    kmem_zalloc(sizeof (*cpi), KM_SLEEP);
2287c478bd9Sstevel@tonic-gate 
2297c478bd9Sstevel@tonic-gate 	cp = &cpi->cpi_std[0];
230*8949bcd6Sandrei 	cp->cp_eax = 0;
231*8949bcd6Sandrei 	cpi->cpi_maxeax = __cpuid_insn(cp);
2327c478bd9Sstevel@tonic-gate 	{
2337c478bd9Sstevel@tonic-gate 		uint32_t *iptr = (uint32_t *)cpi->cpi_vendorstr;
2347c478bd9Sstevel@tonic-gate 		*iptr++ = cp->cp_ebx;
2357c478bd9Sstevel@tonic-gate 		*iptr++ = cp->cp_edx;
2367c478bd9Sstevel@tonic-gate 		*iptr++ = cp->cp_ecx;
2377c478bd9Sstevel@tonic-gate 		*(char *)&cpi->cpi_vendorstr[12] = '\0';
2387c478bd9Sstevel@tonic-gate 	}
2397c478bd9Sstevel@tonic-gate 
2407c478bd9Sstevel@tonic-gate 	/*
2417c478bd9Sstevel@tonic-gate 	 * Map the vendor string to a type code
2427c478bd9Sstevel@tonic-gate 	 */
2437c478bd9Sstevel@tonic-gate 	if (strcmp(cpi->cpi_vendorstr, "GenuineIntel") == 0)
2447c478bd9Sstevel@tonic-gate 		cpi->cpi_vendor = X86_VENDOR_Intel;
2457c478bd9Sstevel@tonic-gate 	else if (strcmp(cpi->cpi_vendorstr, "AuthenticAMD") == 0)
2467c478bd9Sstevel@tonic-gate 		cpi->cpi_vendor = X86_VENDOR_AMD;
2477c478bd9Sstevel@tonic-gate 	else if (strcmp(cpi->cpi_vendorstr, "GenuineTMx86") == 0)
2487c478bd9Sstevel@tonic-gate 		cpi->cpi_vendor = X86_VENDOR_TM;
2497c478bd9Sstevel@tonic-gate 	else if (strcmp(cpi->cpi_vendorstr, CyrixInstead) == 0)
2507c478bd9Sstevel@tonic-gate 		/*
2517c478bd9Sstevel@tonic-gate 		 * CyrixInstead is a variable used by the Cyrix detection code
2527c478bd9Sstevel@tonic-gate 		 * in locore.
2537c478bd9Sstevel@tonic-gate 		 */
2547c478bd9Sstevel@tonic-gate 		cpi->cpi_vendor = X86_VENDOR_Cyrix;
2557c478bd9Sstevel@tonic-gate 	else if (strcmp(cpi->cpi_vendorstr, "UMC UMC UMC ") == 0)
2567c478bd9Sstevel@tonic-gate 		cpi->cpi_vendor = X86_VENDOR_UMC;
2577c478bd9Sstevel@tonic-gate 	else if (strcmp(cpi->cpi_vendorstr, "NexGenDriven") == 0)
2587c478bd9Sstevel@tonic-gate 		cpi->cpi_vendor = X86_VENDOR_NexGen;
2597c478bd9Sstevel@tonic-gate 	else if (strcmp(cpi->cpi_vendorstr, "CentaurHauls") == 0)
2607c478bd9Sstevel@tonic-gate 		cpi->cpi_vendor = X86_VENDOR_Centaur;
2617c478bd9Sstevel@tonic-gate 	else if (strcmp(cpi->cpi_vendorstr, "RiseRiseRise") == 0)
2627c478bd9Sstevel@tonic-gate 		cpi->cpi_vendor = X86_VENDOR_Rise;
2637c478bd9Sstevel@tonic-gate 	else if (strcmp(cpi->cpi_vendorstr, "SiS SiS SiS ") == 0)
2647c478bd9Sstevel@tonic-gate 		cpi->cpi_vendor = X86_VENDOR_SiS;
2657c478bd9Sstevel@tonic-gate 	else if (strcmp(cpi->cpi_vendorstr, "Geode by NSC") == 0)
2667c478bd9Sstevel@tonic-gate 		cpi->cpi_vendor = X86_VENDOR_NSC;
2677c478bd9Sstevel@tonic-gate 	else
2687c478bd9Sstevel@tonic-gate 		cpi->cpi_vendor = X86_VENDOR_IntelClone;
2697c478bd9Sstevel@tonic-gate 
2707c478bd9Sstevel@tonic-gate 	x86_vendor = cpi->cpi_vendor; /* for compatibility */
2717c478bd9Sstevel@tonic-gate 
2727c478bd9Sstevel@tonic-gate 	/*
2737c478bd9Sstevel@tonic-gate 	 * Limit the range in case of weird hardware
2747c478bd9Sstevel@tonic-gate 	 */
2757c478bd9Sstevel@tonic-gate 	if (cpi->cpi_maxeax > CPI_MAXEAX_MAX)
2767c478bd9Sstevel@tonic-gate 		cpi->cpi_maxeax = CPI_MAXEAX_MAX;
2777c478bd9Sstevel@tonic-gate 	if (cpi->cpi_maxeax < 1)
2787c478bd9Sstevel@tonic-gate 		goto pass1_done;
2797c478bd9Sstevel@tonic-gate 
2807c478bd9Sstevel@tonic-gate 	cp = &cpi->cpi_std[1];
281*8949bcd6Sandrei 	cp->cp_eax = 1;
282*8949bcd6Sandrei 	(void) __cpuid_insn(cp);
2837c478bd9Sstevel@tonic-gate 
2847c478bd9Sstevel@tonic-gate 	/*
2857c478bd9Sstevel@tonic-gate 	 * Extract identifying constants for easy access.
2867c478bd9Sstevel@tonic-gate 	 */
2877c478bd9Sstevel@tonic-gate 	cpi->cpi_model = CPI_MODEL(cpi);
2887c478bd9Sstevel@tonic-gate 	cpi->cpi_family = CPI_FAMILY(cpi);
2897c478bd9Sstevel@tonic-gate 
2907c478bd9Sstevel@tonic-gate 	if (cpi->cpi_family == 0xf) {
2917c478bd9Sstevel@tonic-gate 		cpi->cpi_family += CPI_FAMILY_XTD(cpi);
2927c478bd9Sstevel@tonic-gate 		cpi->cpi_model += CPI_MODEL_XTD(cpi) << 4;
2937c478bd9Sstevel@tonic-gate 	}
2947c478bd9Sstevel@tonic-gate 
2957c478bd9Sstevel@tonic-gate 	cpi->cpi_step = CPI_STEP(cpi);
2967c478bd9Sstevel@tonic-gate 	cpi->cpi_brandid = CPI_BRANDID(cpi);
2977c478bd9Sstevel@tonic-gate 
2987c478bd9Sstevel@tonic-gate 	/*
2997c478bd9Sstevel@tonic-gate 	 * *default* assumptions:
3007c478bd9Sstevel@tonic-gate 	 * - believe %edx feature word
3017c478bd9Sstevel@tonic-gate 	 * - ignore %ecx feature word
3027c478bd9Sstevel@tonic-gate 	 * - 32-bit virtual and physical addressing
3037c478bd9Sstevel@tonic-gate 	 */
3047c478bd9Sstevel@tonic-gate 	mask_edx = 0xffffffff;
3057c478bd9Sstevel@tonic-gate 	mask_ecx = 0;
3067c478bd9Sstevel@tonic-gate 
3077c478bd9Sstevel@tonic-gate 	cpi->cpi_pabits = cpi->cpi_vabits = 32;
3087c478bd9Sstevel@tonic-gate 
3097c478bd9Sstevel@tonic-gate 	switch (cpi->cpi_vendor) {
3107c478bd9Sstevel@tonic-gate 	case X86_VENDOR_Intel:
3117c478bd9Sstevel@tonic-gate 		if (cpi->cpi_family == 5)
3127c478bd9Sstevel@tonic-gate 			x86_type = X86_TYPE_P5;
3137c478bd9Sstevel@tonic-gate 		else if (cpi->cpi_family == 6) {
3147c478bd9Sstevel@tonic-gate 			x86_type = X86_TYPE_P6;
3157c478bd9Sstevel@tonic-gate 			pentiumpro_bug4046376 = 1;
3167c478bd9Sstevel@tonic-gate 			pentiumpro_bug4064495 = 1;
3177c478bd9Sstevel@tonic-gate 			/*
3187c478bd9Sstevel@tonic-gate 			 * Clear the SEP bit when it was set erroneously
3197c478bd9Sstevel@tonic-gate 			 */
3207c478bd9Sstevel@tonic-gate 			if (cpi->cpi_model < 3 && cpi->cpi_step < 3)
3217c478bd9Sstevel@tonic-gate 				cp->cp_edx &= ~CPUID_INTC_EDX_SEP;
3227c478bd9Sstevel@tonic-gate 		} else if (cpi->cpi_family == 0xf) {
3237c478bd9Sstevel@tonic-gate 			x86_type = X86_TYPE_P4;
3247c478bd9Sstevel@tonic-gate 			/*
3257c478bd9Sstevel@tonic-gate 			 * We don't currently depend on any of the %ecx
3267c478bd9Sstevel@tonic-gate 			 * features until Prescott, so we'll only check
3277c478bd9Sstevel@tonic-gate 			 * this from P4 onwards.  We might want to revisit
3287c478bd9Sstevel@tonic-gate 			 * that idea later.
3297c478bd9Sstevel@tonic-gate 			 */
3307c478bd9Sstevel@tonic-gate 			mask_ecx = 0xffffffff;
3317c478bd9Sstevel@tonic-gate 		} else if (cpi->cpi_family > 0xf)
3327c478bd9Sstevel@tonic-gate 			mask_ecx = 0xffffffff;
3337c478bd9Sstevel@tonic-gate 		break;
3347c478bd9Sstevel@tonic-gate 	case X86_VENDOR_IntelClone:
3357c478bd9Sstevel@tonic-gate 	default:
3367c478bd9Sstevel@tonic-gate 		break;
3377c478bd9Sstevel@tonic-gate 	case X86_VENDOR_AMD:
3387c478bd9Sstevel@tonic-gate #if defined(OPTERON_ERRATUM_108)
3397c478bd9Sstevel@tonic-gate 		if (cpi->cpi_family == 0xf && cpi->cpi_model == 0xe) {
3407c478bd9Sstevel@tonic-gate 			cp->cp_eax = (0xf0f & cp->cp_eax) | 0xc0;
3417c478bd9Sstevel@tonic-gate 			cpi->cpi_model = 0xc;
3427c478bd9Sstevel@tonic-gate 		} else
3437c478bd9Sstevel@tonic-gate #endif
3447c478bd9Sstevel@tonic-gate 		if (cpi->cpi_family == 5) {
3457c478bd9Sstevel@tonic-gate 			/*
3467c478bd9Sstevel@tonic-gate 			 * AMD K5 and K6
3477c478bd9Sstevel@tonic-gate 			 *
3487c478bd9Sstevel@tonic-gate 			 * These CPUs have an incomplete implementation
3497c478bd9Sstevel@tonic-gate 			 * of MCA/MCE which we mask away.
3507c478bd9Sstevel@tonic-gate 			 */
351*8949bcd6Sandrei 			mask_edx &= ~(CPUID_INTC_EDX_MCE | CPUID_INTC_EDX_MCA);
352*8949bcd6Sandrei 
3537c478bd9Sstevel@tonic-gate 			/*
3547c478bd9Sstevel@tonic-gate 			 * Model 0 uses the wrong (APIC) bit
3557c478bd9Sstevel@tonic-gate 			 * to indicate PGE.  Fix it here.
3567c478bd9Sstevel@tonic-gate 			 */
357*8949bcd6Sandrei 			if (cpi->cpi_model == 0) {
3587c478bd9Sstevel@tonic-gate 				if (cp->cp_edx & 0x200) {
3597c478bd9Sstevel@tonic-gate 					cp->cp_edx &= ~0x200;
3607c478bd9Sstevel@tonic-gate 					cp->cp_edx |= CPUID_INTC_EDX_PGE;
3617c478bd9Sstevel@tonic-gate 				}
3627c478bd9Sstevel@tonic-gate 			}
363*8949bcd6Sandrei 
364*8949bcd6Sandrei 			/*
365*8949bcd6Sandrei 			 * Early models had problems w/ MMX; disable.
366*8949bcd6Sandrei 			 */
367*8949bcd6Sandrei 			if (cpi->cpi_model < 6)
368*8949bcd6Sandrei 				mask_edx &= ~CPUID_INTC_EDX_MMX;
369*8949bcd6Sandrei 		}
370*8949bcd6Sandrei 
371*8949bcd6Sandrei 		/*
372*8949bcd6Sandrei 		 * For newer families, SSE3 and CX16, at least, are valid;
373*8949bcd6Sandrei 		 * enable all
374*8949bcd6Sandrei 		 */
375*8949bcd6Sandrei 		if (cpi->cpi_family >= 0xf)
376*8949bcd6Sandrei 			mask_ecx = 0xffffffff;
3777c478bd9Sstevel@tonic-gate 		break;
3787c478bd9Sstevel@tonic-gate 	case X86_VENDOR_TM:
3797c478bd9Sstevel@tonic-gate 		/*
3807c478bd9Sstevel@tonic-gate 		 * workaround the NT workaround in CMS 4.1
3817c478bd9Sstevel@tonic-gate 		 */
3827c478bd9Sstevel@tonic-gate 		if (cpi->cpi_family == 5 && cpi->cpi_model == 4 &&
3837c478bd9Sstevel@tonic-gate 		    (cpi->cpi_step == 2 || cpi->cpi_step == 3))
3847c478bd9Sstevel@tonic-gate 			cp->cp_edx |= CPUID_INTC_EDX_CX8;
3857c478bd9Sstevel@tonic-gate 		break;
3867c478bd9Sstevel@tonic-gate 	case X86_VENDOR_Centaur:
3877c478bd9Sstevel@tonic-gate 		/*
3887c478bd9Sstevel@tonic-gate 		 * workaround the NT workarounds again
3897c478bd9Sstevel@tonic-gate 		 */
3907c478bd9Sstevel@tonic-gate 		if (cpi->cpi_family == 6)
3917c478bd9Sstevel@tonic-gate 			cp->cp_edx |= CPUID_INTC_EDX_CX8;
3927c478bd9Sstevel@tonic-gate 		break;
3937c478bd9Sstevel@tonic-gate 	case X86_VENDOR_Cyrix:
3947c478bd9Sstevel@tonic-gate 		/*
3957c478bd9Sstevel@tonic-gate 		 * We rely heavily on the probing in locore
3967c478bd9Sstevel@tonic-gate 		 * to actually figure out what parts, if any,
3977c478bd9Sstevel@tonic-gate 		 * of the Cyrix cpuid instruction to believe.
3987c478bd9Sstevel@tonic-gate 		 */
3997c478bd9Sstevel@tonic-gate 		switch (x86_type) {
4007c478bd9Sstevel@tonic-gate 		case X86_TYPE_CYRIX_486:
4017c478bd9Sstevel@tonic-gate 			mask_edx = 0;
4027c478bd9Sstevel@tonic-gate 			break;
4037c478bd9Sstevel@tonic-gate 		case X86_TYPE_CYRIX_6x86:
4047c478bd9Sstevel@tonic-gate 			mask_edx = 0;
4057c478bd9Sstevel@tonic-gate 			break;
4067c478bd9Sstevel@tonic-gate 		case X86_TYPE_CYRIX_6x86L:
4077c478bd9Sstevel@tonic-gate 			mask_edx =
4087c478bd9Sstevel@tonic-gate 			    CPUID_INTC_EDX_DE |
4097c478bd9Sstevel@tonic-gate 			    CPUID_INTC_EDX_CX8;
4107c478bd9Sstevel@tonic-gate 			break;
4117c478bd9Sstevel@tonic-gate 		case X86_TYPE_CYRIX_6x86MX:
4127c478bd9Sstevel@tonic-gate 			mask_edx =
4137c478bd9Sstevel@tonic-gate 			    CPUID_INTC_EDX_DE |
4147c478bd9Sstevel@tonic-gate 			    CPUID_INTC_EDX_MSR |
4157c478bd9Sstevel@tonic-gate 			    CPUID_INTC_EDX_CX8 |
4167c478bd9Sstevel@tonic-gate 			    CPUID_INTC_EDX_PGE |
4177c478bd9Sstevel@tonic-gate 			    CPUID_INTC_EDX_CMOV |
4187c478bd9Sstevel@tonic-gate 			    CPUID_INTC_EDX_MMX;
4197c478bd9Sstevel@tonic-gate 			break;
4207c478bd9Sstevel@tonic-gate 		case X86_TYPE_CYRIX_GXm:
4217c478bd9Sstevel@tonic-gate 			mask_edx =
4227c478bd9Sstevel@tonic-gate 			    CPUID_INTC_EDX_MSR |
4237c478bd9Sstevel@tonic-gate 			    CPUID_INTC_EDX_CX8 |
4247c478bd9Sstevel@tonic-gate 			    CPUID_INTC_EDX_CMOV |
4257c478bd9Sstevel@tonic-gate 			    CPUID_INTC_EDX_MMX;
4267c478bd9Sstevel@tonic-gate 			break;
4277c478bd9Sstevel@tonic-gate 		case X86_TYPE_CYRIX_MediaGX:
4287c478bd9Sstevel@tonic-gate 			break;
4297c478bd9Sstevel@tonic-gate 		case X86_TYPE_CYRIX_MII:
4307c478bd9Sstevel@tonic-gate 		case X86_TYPE_VIA_CYRIX_III:
4317c478bd9Sstevel@tonic-gate 			mask_edx =
4327c478bd9Sstevel@tonic-gate 			    CPUID_INTC_EDX_DE |
4337c478bd9Sstevel@tonic-gate 			    CPUID_INTC_EDX_TSC |
4347c478bd9Sstevel@tonic-gate 			    CPUID_INTC_EDX_MSR |
4357c478bd9Sstevel@tonic-gate 			    CPUID_INTC_EDX_CX8 |
4367c478bd9Sstevel@tonic-gate 			    CPUID_INTC_EDX_PGE |
4377c478bd9Sstevel@tonic-gate 			    CPUID_INTC_EDX_CMOV |
4387c478bd9Sstevel@tonic-gate 			    CPUID_INTC_EDX_MMX;
4397c478bd9Sstevel@tonic-gate 			break;
4407c478bd9Sstevel@tonic-gate 		default:
4417c478bd9Sstevel@tonic-gate 			break;
4427c478bd9Sstevel@tonic-gate 		}
4437c478bd9Sstevel@tonic-gate 		break;
4447c478bd9Sstevel@tonic-gate 	}
4457c478bd9Sstevel@tonic-gate 
4467c478bd9Sstevel@tonic-gate 	/*
4477c478bd9Sstevel@tonic-gate 	 * Now we've figured out the masks that determine
4487c478bd9Sstevel@tonic-gate 	 * which bits we choose to believe, apply the masks
4497c478bd9Sstevel@tonic-gate 	 * to the feature words, then map the kernel's view
4507c478bd9Sstevel@tonic-gate 	 * of these feature words into its feature word.
4517c478bd9Sstevel@tonic-gate 	 */
4527c478bd9Sstevel@tonic-gate 	cp->cp_edx &= mask_edx;
4537c478bd9Sstevel@tonic-gate 	cp->cp_ecx &= mask_ecx;
4547c478bd9Sstevel@tonic-gate 
4557c478bd9Sstevel@tonic-gate 	/*
4567c478bd9Sstevel@tonic-gate 	 * fold in fix ups
4577c478bd9Sstevel@tonic-gate 	 */
4587c478bd9Sstevel@tonic-gate 
4597c478bd9Sstevel@tonic-gate 	cp->cp_edx |= cpuid_feature_edx_include;
4607c478bd9Sstevel@tonic-gate 	cp->cp_edx &= ~cpuid_feature_edx_exclude;
4617c478bd9Sstevel@tonic-gate 
4627c478bd9Sstevel@tonic-gate 
4637c478bd9Sstevel@tonic-gate 	cp->cp_ecx |= cpuid_feature_ecx_include;
4647c478bd9Sstevel@tonic-gate 	cp->cp_ecx &= ~cpuid_feature_ecx_exclude;
4657c478bd9Sstevel@tonic-gate 
4667c478bd9Sstevel@tonic-gate 	if (cp->cp_edx & CPUID_INTC_EDX_PSE)
4677c478bd9Sstevel@tonic-gate 		feature |= X86_LARGEPAGE;
4687c478bd9Sstevel@tonic-gate 	if (cp->cp_edx & CPUID_INTC_EDX_TSC)
4697c478bd9Sstevel@tonic-gate 		feature |= X86_TSC;
4707c478bd9Sstevel@tonic-gate 	if (cp->cp_edx & CPUID_INTC_EDX_MSR)
4717c478bd9Sstevel@tonic-gate 		feature |= X86_MSR;
4727c478bd9Sstevel@tonic-gate 	if (cp->cp_edx & CPUID_INTC_EDX_MTRR)
4737c478bd9Sstevel@tonic-gate 		feature |= X86_MTRR;
4747c478bd9Sstevel@tonic-gate 	if (cp->cp_edx & CPUID_INTC_EDX_PGE)
4757c478bd9Sstevel@tonic-gate 		feature |= X86_PGE;
4767c478bd9Sstevel@tonic-gate 	if (cp->cp_edx & CPUID_INTC_EDX_CMOV)
4777c478bd9Sstevel@tonic-gate 		feature |= X86_CMOV;
4787c478bd9Sstevel@tonic-gate 	if (cp->cp_edx & CPUID_INTC_EDX_MMX)
4797c478bd9Sstevel@tonic-gate 		feature |= X86_MMX;
4807c478bd9Sstevel@tonic-gate 	if ((cp->cp_edx & CPUID_INTC_EDX_MCE) != 0 &&
4817c478bd9Sstevel@tonic-gate 	    (cp->cp_edx & CPUID_INTC_EDX_MCA) != 0)
4827c478bd9Sstevel@tonic-gate 		feature |= X86_MCA;
4837c478bd9Sstevel@tonic-gate 	if (cp->cp_edx & CPUID_INTC_EDX_PAE)
4847c478bd9Sstevel@tonic-gate 		feature |= X86_PAE;
4857c478bd9Sstevel@tonic-gate 	if (cp->cp_edx & CPUID_INTC_EDX_CX8)
4867c478bd9Sstevel@tonic-gate 		feature |= X86_CX8;
4877c478bd9Sstevel@tonic-gate 	/*
488ddea50bbSdmick 	 * Once this bit was thought questionable, but it looks like it's
489ddea50bbSdmick 	 * back, as of Application Note 485 March 2005 (24161829.pdf)
4907c478bd9Sstevel@tonic-gate 	 */
4917c478bd9Sstevel@tonic-gate 	if (cp->cp_ecx & CPUID_INTC_ECX_CX16)
4927c478bd9Sstevel@tonic-gate 		feature |= X86_CX16;
4937c478bd9Sstevel@tonic-gate 	if (cp->cp_edx & CPUID_INTC_EDX_PAT)
4947c478bd9Sstevel@tonic-gate 		feature |= X86_PAT;
4957c478bd9Sstevel@tonic-gate 	if (cp->cp_edx & CPUID_INTC_EDX_SEP)
4967c478bd9Sstevel@tonic-gate 		feature |= X86_SEP;
4977c478bd9Sstevel@tonic-gate 	if (cp->cp_edx & CPUID_INTC_EDX_FXSR) {
4987c478bd9Sstevel@tonic-gate 		/*
4997c478bd9Sstevel@tonic-gate 		 * In our implementation, fxsave/fxrstor
5007c478bd9Sstevel@tonic-gate 		 * are prerequisites before we'll even
5017c478bd9Sstevel@tonic-gate 		 * try and do SSE things.
5027c478bd9Sstevel@tonic-gate 		 */
5037c478bd9Sstevel@tonic-gate 		if (cp->cp_edx & CPUID_INTC_EDX_SSE)
5047c478bd9Sstevel@tonic-gate 			feature |= X86_SSE;
5057c478bd9Sstevel@tonic-gate 		if (cp->cp_edx & CPUID_INTC_EDX_SSE2)
5067c478bd9Sstevel@tonic-gate 			feature |= X86_SSE2;
5077c478bd9Sstevel@tonic-gate 		if (cp->cp_ecx & CPUID_INTC_ECX_SSE3)
5087c478bd9Sstevel@tonic-gate 			feature |= X86_SSE3;
5097c478bd9Sstevel@tonic-gate 	}
5107c478bd9Sstevel@tonic-gate 	if (cp->cp_edx & CPUID_INTC_EDX_DE)
5117c478bd9Sstevel@tonic-gate 		cr4_value |= CR4_DE;
5127c478bd9Sstevel@tonic-gate 
5137c478bd9Sstevel@tonic-gate 	if (feature & X86_PAE)
5147c478bd9Sstevel@tonic-gate 		cpi->cpi_pabits = 36;
5157c478bd9Sstevel@tonic-gate 
5167c478bd9Sstevel@tonic-gate 	/*
5177c478bd9Sstevel@tonic-gate 	 * Hyperthreading configuration is slightly tricky on Intel
5187c478bd9Sstevel@tonic-gate 	 * and pure clones, and even trickier on AMD.
5197c478bd9Sstevel@tonic-gate 	 *
5207c478bd9Sstevel@tonic-gate 	 * (AMD chose to set the HTT bit on their CMP processors,
5217c478bd9Sstevel@tonic-gate 	 * even though they're not actually hyperthreaded.  Thus it
5227c478bd9Sstevel@tonic-gate 	 * takes a bit more work to figure out what's really going
523*8949bcd6Sandrei 	 * on ... see the handling of the CMP_LEGACY bit below)
5247c478bd9Sstevel@tonic-gate 	 */
5257c478bd9Sstevel@tonic-gate 	if (cp->cp_edx & CPUID_INTC_EDX_HTT) {
5267c478bd9Sstevel@tonic-gate 		cpi->cpi_ncpu_per_chip = CPI_CPU_COUNT(cpi);
5277c478bd9Sstevel@tonic-gate 		if (cpi->cpi_ncpu_per_chip > 1)
5287c478bd9Sstevel@tonic-gate 			feature |= X86_HTT;
529*8949bcd6Sandrei 	} else {
530*8949bcd6Sandrei 		cpi->cpi_ncpu_per_chip = 1;
5317c478bd9Sstevel@tonic-gate 	}
5327c478bd9Sstevel@tonic-gate 
5337c478bd9Sstevel@tonic-gate 	/*
5347c478bd9Sstevel@tonic-gate 	 * Work on the "extended" feature information, doing
5357c478bd9Sstevel@tonic-gate 	 * some basic initialization for cpuid_pass2()
5367c478bd9Sstevel@tonic-gate 	 */
5377c478bd9Sstevel@tonic-gate 	xcpuid = 0;
5387c478bd9Sstevel@tonic-gate 	switch (cpi->cpi_vendor) {
5397c478bd9Sstevel@tonic-gate 	case X86_VENDOR_Intel:
5407c478bd9Sstevel@tonic-gate 		if (cpi->cpi_family >= 0xf)
5417c478bd9Sstevel@tonic-gate 			xcpuid++;
5427c478bd9Sstevel@tonic-gate 		break;
5437c478bd9Sstevel@tonic-gate 	case X86_VENDOR_AMD:
5447c478bd9Sstevel@tonic-gate 		if (cpi->cpi_family > 5 ||
5457c478bd9Sstevel@tonic-gate 		    (cpi->cpi_family == 5 && cpi->cpi_model >= 1))
5467c478bd9Sstevel@tonic-gate 			xcpuid++;
5477c478bd9Sstevel@tonic-gate 		break;
5487c478bd9Sstevel@tonic-gate 	case X86_VENDOR_Cyrix:
5497c478bd9Sstevel@tonic-gate 		/*
5507c478bd9Sstevel@tonic-gate 		 * Only these Cyrix CPUs are -known- to support
5517c478bd9Sstevel@tonic-gate 		 * extended cpuid operations.
5527c478bd9Sstevel@tonic-gate 		 */
5537c478bd9Sstevel@tonic-gate 		if (x86_type == X86_TYPE_VIA_CYRIX_III ||
5547c478bd9Sstevel@tonic-gate 		    x86_type == X86_TYPE_CYRIX_GXm)
5557c478bd9Sstevel@tonic-gate 			xcpuid++;
5567c478bd9Sstevel@tonic-gate 		break;
5577c478bd9Sstevel@tonic-gate 	case X86_VENDOR_Centaur:
5587c478bd9Sstevel@tonic-gate 	case X86_VENDOR_TM:
5597c478bd9Sstevel@tonic-gate 	default:
5607c478bd9Sstevel@tonic-gate 		xcpuid++;
5617c478bd9Sstevel@tonic-gate 		break;
5627c478bd9Sstevel@tonic-gate 	}
5637c478bd9Sstevel@tonic-gate 
5647c478bd9Sstevel@tonic-gate 	if (xcpuid) {
5657c478bd9Sstevel@tonic-gate 		cp = &cpi->cpi_extd[0];
566*8949bcd6Sandrei 		cp->cp_eax = 0x80000000;
567*8949bcd6Sandrei 		cpi->cpi_xmaxeax = __cpuid_insn(cp);
5687c478bd9Sstevel@tonic-gate 	}
5697c478bd9Sstevel@tonic-gate 
5707c478bd9Sstevel@tonic-gate 	if (cpi->cpi_xmaxeax & 0x80000000) {
5717c478bd9Sstevel@tonic-gate 
5727c478bd9Sstevel@tonic-gate 		if (cpi->cpi_xmaxeax > CPI_XMAXEAX_MAX)
5737c478bd9Sstevel@tonic-gate 			cpi->cpi_xmaxeax = CPI_XMAXEAX_MAX;
5747c478bd9Sstevel@tonic-gate 
5757c478bd9Sstevel@tonic-gate 		switch (cpi->cpi_vendor) {
5767c478bd9Sstevel@tonic-gate 		case X86_VENDOR_Intel:
5777c478bd9Sstevel@tonic-gate 		case X86_VENDOR_AMD:
5787c478bd9Sstevel@tonic-gate 			if (cpi->cpi_xmaxeax < 0x80000001)
5797c478bd9Sstevel@tonic-gate 				break;
5807c478bd9Sstevel@tonic-gate 			cp = &cpi->cpi_extd[1];
581*8949bcd6Sandrei 			cp->cp_eax = 0x80000001;
582*8949bcd6Sandrei 			(void) __cpuid_insn(cp);
5837c478bd9Sstevel@tonic-gate 			if (cpi->cpi_vendor == X86_VENDOR_AMD &&
5847c478bd9Sstevel@tonic-gate 			    cpi->cpi_family == 5 &&
5857c478bd9Sstevel@tonic-gate 			    cpi->cpi_model == 6 &&
5867c478bd9Sstevel@tonic-gate 			    cpi->cpi_step == 6) {
5877c478bd9Sstevel@tonic-gate 				/*
5887c478bd9Sstevel@tonic-gate 				 * K6 model 6 uses bit 10 to indicate SYSC
5897c478bd9Sstevel@tonic-gate 				 * Later models use bit 11. Fix it here.
5907c478bd9Sstevel@tonic-gate 				 */
5917c478bd9Sstevel@tonic-gate 				if (cp->cp_edx & 0x400) {
5927c478bd9Sstevel@tonic-gate 					cp->cp_edx &= ~0x400;
5937c478bd9Sstevel@tonic-gate 					cp->cp_edx |= CPUID_AMD_EDX_SYSC;
5947c478bd9Sstevel@tonic-gate 				}
5957c478bd9Sstevel@tonic-gate 			}
5967c478bd9Sstevel@tonic-gate 
5977c478bd9Sstevel@tonic-gate 			/*
5987c478bd9Sstevel@tonic-gate 			 * Compute the additions to the kernel's feature word.
5997c478bd9Sstevel@tonic-gate 			 */
6007c478bd9Sstevel@tonic-gate 			if (cp->cp_edx & CPUID_AMD_EDX_NX)
6017c478bd9Sstevel@tonic-gate 				feature |= X86_NX;
6027c478bd9Sstevel@tonic-gate 
6037c478bd9Sstevel@tonic-gate 			/*
604*8949bcd6Sandrei 			 * If both the HTT and CMP_LEGACY bits are set,
605*8949bcd6Sandrei 			 * then we're not actually HyperThreaded.  Read
606*8949bcd6Sandrei 			 * "AMD CPUID Specification" for more details.
6077c478bd9Sstevel@tonic-gate 			 */
6087c478bd9Sstevel@tonic-gate 			if (cpi->cpi_vendor == X86_VENDOR_AMD &&
609*8949bcd6Sandrei 			    (feature & X86_HTT) &&
610*8949bcd6Sandrei 			    (cp->cp_ecx & CPUID_AMD_ECX_CMP_LEGACY)) {
6117c478bd9Sstevel@tonic-gate 				feature &= ~X86_HTT;
612*8949bcd6Sandrei 				feature |= X86_CMP;
613*8949bcd6Sandrei 			}
6147c478bd9Sstevel@tonic-gate #if defined(_LP64)
6157c478bd9Sstevel@tonic-gate 			/*
6167c478bd9Sstevel@tonic-gate 			 * It's really tricky to support syscall/sysret in
6177c478bd9Sstevel@tonic-gate 			 * the i386 kernel; we rely on sysenter/sysexit
6187c478bd9Sstevel@tonic-gate 			 * instead.  In the amd64 kernel, things are -way-
6197c478bd9Sstevel@tonic-gate 			 * better.
6207c478bd9Sstevel@tonic-gate 			 */
6217c478bd9Sstevel@tonic-gate 			if (cp->cp_edx & CPUID_AMD_EDX_SYSC)
6227c478bd9Sstevel@tonic-gate 				feature |= X86_ASYSC;
6237c478bd9Sstevel@tonic-gate 
6247c478bd9Sstevel@tonic-gate 			/*
6257c478bd9Sstevel@tonic-gate 			 * While we're thinking about system calls, note
6267c478bd9Sstevel@tonic-gate 			 * that AMD processors don't support sysenter
6277c478bd9Sstevel@tonic-gate 			 * in long mode at all, so don't try to program them.
6287c478bd9Sstevel@tonic-gate 			 */
6297c478bd9Sstevel@tonic-gate 			if (x86_vendor == X86_VENDOR_AMD)
6307c478bd9Sstevel@tonic-gate 				feature &= ~X86_SEP;
6317c478bd9Sstevel@tonic-gate #endif
6327c478bd9Sstevel@tonic-gate 			break;
6337c478bd9Sstevel@tonic-gate 		default:
6347c478bd9Sstevel@tonic-gate 			break;
6357c478bd9Sstevel@tonic-gate 		}
6367c478bd9Sstevel@tonic-gate 
637*8949bcd6Sandrei 		/*
638*8949bcd6Sandrei 		 * Get CPUID data about processor cores and hyperthreads.
639*8949bcd6Sandrei 		 */
6407c478bd9Sstevel@tonic-gate 		switch (cpi->cpi_vendor) {
6417c478bd9Sstevel@tonic-gate 		case X86_VENDOR_Intel:
642*8949bcd6Sandrei 			if (cpi->cpi_maxeax >= 4) {
643*8949bcd6Sandrei 				cp = &cpi->cpi_std[4];
644*8949bcd6Sandrei 				cp->cp_eax = 4;
645*8949bcd6Sandrei 				cp->cp_ecx = 0;
646*8949bcd6Sandrei 				(void) __cpuid_insn(cp);
647*8949bcd6Sandrei 			}
648*8949bcd6Sandrei 			/*FALLTHROUGH*/
6497c478bd9Sstevel@tonic-gate 		case X86_VENDOR_AMD:
6507c478bd9Sstevel@tonic-gate 			if (cpi->cpi_xmaxeax < 0x80000008)
6517c478bd9Sstevel@tonic-gate 				break;
6527c478bd9Sstevel@tonic-gate 			cp = &cpi->cpi_extd[8];
653*8949bcd6Sandrei 			cp->cp_eax = 0x80000008;
654*8949bcd6Sandrei 			(void) __cpuid_insn(cp);
6557c478bd9Sstevel@tonic-gate 			/*
6567c478bd9Sstevel@tonic-gate 			 * Virtual and physical address limits from
6577c478bd9Sstevel@tonic-gate 			 * cpuid override previously guessed values.
6587c478bd9Sstevel@tonic-gate 			 */
6597c478bd9Sstevel@tonic-gate 			cpi->cpi_pabits = BITX(cp->cp_eax, 7, 0);
6607c478bd9Sstevel@tonic-gate 			cpi->cpi_vabits = BITX(cp->cp_eax, 15, 8);
6617c478bd9Sstevel@tonic-gate 			break;
6627c478bd9Sstevel@tonic-gate 		default:
6637c478bd9Sstevel@tonic-gate 			break;
6647c478bd9Sstevel@tonic-gate 		}
665*8949bcd6Sandrei 
666*8949bcd6Sandrei 		switch (cpi->cpi_vendor) {
667*8949bcd6Sandrei 		case X86_VENDOR_Intel:
668*8949bcd6Sandrei 			if (cpi->cpi_maxeax < 4) {
669*8949bcd6Sandrei 				cpi->cpi_ncore_per_chip = 1;
670*8949bcd6Sandrei 				break;
671*8949bcd6Sandrei 			} else {
672*8949bcd6Sandrei 				cpi->cpi_ncore_per_chip =
673*8949bcd6Sandrei 				    BITX((cpi)->cpi_std[4].cp_eax, 31, 26) + 1;
674*8949bcd6Sandrei 			}
675*8949bcd6Sandrei 			break;
676*8949bcd6Sandrei 		case X86_VENDOR_AMD:
677*8949bcd6Sandrei 			if (cpi->cpi_xmaxeax < 0x80000008) {
678*8949bcd6Sandrei 				cpi->cpi_ncore_per_chip = 1;
679*8949bcd6Sandrei 				break;
680*8949bcd6Sandrei 			} else {
681*8949bcd6Sandrei 				cpi->cpi_ncore_per_chip =
682*8949bcd6Sandrei 				    BITX((cpi)->cpi_extd[8].cp_ecx, 7, 0) + 1;
683*8949bcd6Sandrei 			}
684*8949bcd6Sandrei 			break;
685*8949bcd6Sandrei 		default:
686*8949bcd6Sandrei 			cpi->cpi_ncore_per_chip = 1;
687*8949bcd6Sandrei 			break;
6887c478bd9Sstevel@tonic-gate 		}
6897c478bd9Sstevel@tonic-gate 
690*8949bcd6Sandrei 	}
691*8949bcd6Sandrei 
692*8949bcd6Sandrei 	/*
693*8949bcd6Sandrei 	 * If more than one core, then this processor is CMP.
694*8949bcd6Sandrei 	 */
695*8949bcd6Sandrei 	if (cpi->cpi_ncore_per_chip > 1)
696*8949bcd6Sandrei 		feature |= X86_CMP;
697*8949bcd6Sandrei 	/*
698*8949bcd6Sandrei 	 * If the number of cores is the same as the number
699*8949bcd6Sandrei 	 * of CPUs, then we cannot have HyperThreading.
700*8949bcd6Sandrei 	 */
701*8949bcd6Sandrei 	if (cpi->cpi_ncpu_per_chip == cpi->cpi_ncore_per_chip)
702*8949bcd6Sandrei 		feature &= ~X86_HTT;
703*8949bcd6Sandrei 
7047c478bd9Sstevel@tonic-gate 	if ((feature & (X86_HTT | X86_CMP)) == 0) {
705*8949bcd6Sandrei 		/*
706*8949bcd6Sandrei 		 * Single-core single-threaded processors.
707*8949bcd6Sandrei 		 */
7087c478bd9Sstevel@tonic-gate 		cpi->cpi_chipid = -1;
7097c478bd9Sstevel@tonic-gate 		cpi->cpi_clogid = 0;
710*8949bcd6Sandrei 		cpi->cpi_coreid = cpu->cpu_id;
7117c478bd9Sstevel@tonic-gate 	} else if (cpi->cpi_ncpu_per_chip > 1) {
712*8949bcd6Sandrei 		uint_t i;
713*8949bcd6Sandrei 		uint_t chipid_shift = 0;
714*8949bcd6Sandrei 		uint_t coreid_shift = 0;
715*8949bcd6Sandrei 		uint_t apic_id = CPI_APIC_ID(cpi);
7167c478bd9Sstevel@tonic-gate 
717*8949bcd6Sandrei 		for (i = 1; i < cpi->cpi_ncpu_per_chip; i <<= 1)
718*8949bcd6Sandrei 			chipid_shift++;
719*8949bcd6Sandrei 		cpi->cpi_chipid = apic_id >> chipid_shift;
720*8949bcd6Sandrei 		cpi->cpi_clogid = apic_id & ((1 << chipid_shift) - 1);
721*8949bcd6Sandrei 
722*8949bcd6Sandrei 		if (cpi->cpi_vendor == X86_VENDOR_Intel) {
723*8949bcd6Sandrei 			if (feature & X86_CMP) {
724*8949bcd6Sandrei 				/*
725*8949bcd6Sandrei 				 * Multi-core (and possibly multi-threaded)
726*8949bcd6Sandrei 				 * processors.
727*8949bcd6Sandrei 				 */
728*8949bcd6Sandrei 				uint_t ncpu_per_core;
729*8949bcd6Sandrei 				if (cpi->cpi_ncore_per_chip == 1)
730*8949bcd6Sandrei 					ncpu_per_core = cpi->cpi_ncpu_per_chip;
731*8949bcd6Sandrei 				else if (cpi->cpi_ncore_per_chip > 1)
732*8949bcd6Sandrei 					ncpu_per_core = cpi->cpi_ncpu_per_chip /
733*8949bcd6Sandrei 					    cpi->cpi_ncore_per_chip;
734*8949bcd6Sandrei 				/*
735*8949bcd6Sandrei 				 * 8bit APIC IDs on dual core Pentiums
736*8949bcd6Sandrei 				 * look like this:
737*8949bcd6Sandrei 				 *
738*8949bcd6Sandrei 				 * +-----------------------+------+------+
739*8949bcd6Sandrei 				 * | Physical Package ID   |  MC  |  HT  |
740*8949bcd6Sandrei 				 * +-----------------------+------+------+
741*8949bcd6Sandrei 				 * <------- chipid -------->
742*8949bcd6Sandrei 				 * <------- coreid --------------->
743*8949bcd6Sandrei 				 *			   <--- clogid -->
744*8949bcd6Sandrei 				 *
745*8949bcd6Sandrei 				 * Where the number of bits necessary to
746*8949bcd6Sandrei 				 * represent MC and HT fields together equals
747*8949bcd6Sandrei 				 * to the minimum number of bits necessary to
748*8949bcd6Sandrei 				 * store the value of cpi->cpi_ncpu_per_chip.
749*8949bcd6Sandrei 				 * Of those bits, the MC part uses the number
750*8949bcd6Sandrei 				 * of bits necessary to store the value of
751*8949bcd6Sandrei 				 * cpi->cpi_ncore_per_chip.
752*8949bcd6Sandrei 				 */
753*8949bcd6Sandrei 				for (i = 1; i < ncpu_per_core; i <<= 1)
754*8949bcd6Sandrei 					coreid_shift++;
755*8949bcd6Sandrei 				cpi->cpi_coreid =
756*8949bcd6Sandrei 				    apic_id & ((1 << coreid_shift) - 1);
757*8949bcd6Sandrei 			} else if (feature & X86_HTT) {
758*8949bcd6Sandrei 				/*
759*8949bcd6Sandrei 				 * Single-core multi-threaded processors.
760*8949bcd6Sandrei 				 */
761*8949bcd6Sandrei 				cpi->cpi_coreid = cpi->cpi_chipid;
762*8949bcd6Sandrei 			}
763*8949bcd6Sandrei 		} else if (cpi->cpi_vendor == X86_VENDOR_AMD) {
764*8949bcd6Sandrei 			/*
765*8949bcd6Sandrei 			 * AMD currently only has dual-core processors with
766*8949bcd6Sandrei 			 * single-threaded cores.  If they ever release
767*8949bcd6Sandrei 			 * multi-threaded processors, then this code
768*8949bcd6Sandrei 			 * will have to be updated.
769*8949bcd6Sandrei 			 */
770*8949bcd6Sandrei 			cpi->cpi_coreid = cpu->cpu_id;
771*8949bcd6Sandrei 		} else {
772*8949bcd6Sandrei 			/*
773*8949bcd6Sandrei 			 * All other processors are currently
774*8949bcd6Sandrei 			 * assumed to have single cores.
775*8949bcd6Sandrei 			 */
776*8949bcd6Sandrei 			cpi->cpi_coreid = cpi->cpi_chipid;
777*8949bcd6Sandrei 		}
7787c478bd9Sstevel@tonic-gate 	}
7797c478bd9Sstevel@tonic-gate 
7807c478bd9Sstevel@tonic-gate pass1_done:
7817c478bd9Sstevel@tonic-gate 	cpi->cpi_pass = 1;
7827c478bd9Sstevel@tonic-gate 	return (feature);
7837c478bd9Sstevel@tonic-gate }
7847c478bd9Sstevel@tonic-gate 
7857c478bd9Sstevel@tonic-gate /*
7867c478bd9Sstevel@tonic-gate  * Make copies of the cpuid table entries we depend on, in
7877c478bd9Sstevel@tonic-gate  * part for ease of parsing now, in part so that we have only
7887c478bd9Sstevel@tonic-gate  * one place to correct any of it, in part for ease of
7897c478bd9Sstevel@tonic-gate  * later export to userland, and in part so we can look at
7907c478bd9Sstevel@tonic-gate  * this stuff in a crash dump.
7917c478bd9Sstevel@tonic-gate  */
7927c478bd9Sstevel@tonic-gate 
7937c478bd9Sstevel@tonic-gate /*ARGSUSED*/
7947c478bd9Sstevel@tonic-gate void
7957c478bd9Sstevel@tonic-gate cpuid_pass2(cpu_t *cpu)
7967c478bd9Sstevel@tonic-gate {
7977c478bd9Sstevel@tonic-gate 	uint_t n, nmax;
7987c478bd9Sstevel@tonic-gate 	int i;
799*8949bcd6Sandrei 	struct cpuid_regs *cp;
8007c478bd9Sstevel@tonic-gate 	uint8_t *dp;
8017c478bd9Sstevel@tonic-gate 	uint32_t *iptr;
8027c478bd9Sstevel@tonic-gate 	struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi;
8037c478bd9Sstevel@tonic-gate 
8047c478bd9Sstevel@tonic-gate 	ASSERT(cpi->cpi_pass == 1);
8057c478bd9Sstevel@tonic-gate 
8067c478bd9Sstevel@tonic-gate 	if (cpi->cpi_maxeax < 1)
8077c478bd9Sstevel@tonic-gate 		goto pass2_done;
8087c478bd9Sstevel@tonic-gate 
8097c478bd9Sstevel@tonic-gate 	if ((nmax = cpi->cpi_maxeax + 1) > NMAX_CPI_STD)
8107c478bd9Sstevel@tonic-gate 		nmax = NMAX_CPI_STD;
8117c478bd9Sstevel@tonic-gate 	/*
8127c478bd9Sstevel@tonic-gate 	 * (We already handled n == 0 and n == 1 in pass 1)
8137c478bd9Sstevel@tonic-gate 	 */
8147c478bd9Sstevel@tonic-gate 	for (n = 2, cp = &cpi->cpi_std[2]; n < nmax; n++, cp++) {
815*8949bcd6Sandrei 		cp->cp_eax = n;
816*8949bcd6Sandrei 		(void) __cpuid_insn(cp);
8177c478bd9Sstevel@tonic-gate 		switch (n) {
8187c478bd9Sstevel@tonic-gate 		case 2:
8197c478bd9Sstevel@tonic-gate 			/*
8207c478bd9Sstevel@tonic-gate 			 * "the lower 8 bits of the %eax register
8217c478bd9Sstevel@tonic-gate 			 * contain a value that identifies the number
8227c478bd9Sstevel@tonic-gate 			 * of times the cpuid [instruction] has to be
8237c478bd9Sstevel@tonic-gate 			 * executed to obtain a complete image of the
8247c478bd9Sstevel@tonic-gate 			 * processor's caching systems."
8257c478bd9Sstevel@tonic-gate 			 *
8267c478bd9Sstevel@tonic-gate 			 * How *do* they make this stuff up?
8277c478bd9Sstevel@tonic-gate 			 */
8287c478bd9Sstevel@tonic-gate 			cpi->cpi_ncache = sizeof (*cp) *
8297c478bd9Sstevel@tonic-gate 			    BITX(cp->cp_eax, 7, 0);
8307c478bd9Sstevel@tonic-gate 			if (cpi->cpi_ncache == 0)
8317c478bd9Sstevel@tonic-gate 				break;
8327c478bd9Sstevel@tonic-gate 			cpi->cpi_ncache--;	/* skip count byte */
8337c478bd9Sstevel@tonic-gate 
8347c478bd9Sstevel@tonic-gate 			/*
8357c478bd9Sstevel@tonic-gate 			 * Well, for now, rather than attempt to implement
8367c478bd9Sstevel@tonic-gate 			 * this slightly dubious algorithm, we just look
8377c478bd9Sstevel@tonic-gate 			 * at the first 15 ..
8387c478bd9Sstevel@tonic-gate 			 */
8397c478bd9Sstevel@tonic-gate 			if (cpi->cpi_ncache > (sizeof (*cp) - 1))
8407c478bd9Sstevel@tonic-gate 				cpi->cpi_ncache = sizeof (*cp) - 1;
8417c478bd9Sstevel@tonic-gate 
8427c478bd9Sstevel@tonic-gate 			dp = cpi->cpi_cacheinfo;
8437c478bd9Sstevel@tonic-gate 			if (BITX(cp->cp_eax, 31, 31) == 0) {
8447c478bd9Sstevel@tonic-gate 				uint8_t *p = (void *)&cp->cp_eax;
8457c478bd9Sstevel@tonic-gate 				for (i = 1; i < 3; i++)
8467c478bd9Sstevel@tonic-gate 					if (p[i] != 0)
8477c478bd9Sstevel@tonic-gate 						*dp++ = p[i];
8487c478bd9Sstevel@tonic-gate 			}
8497c478bd9Sstevel@tonic-gate 			if (BITX(cp->cp_ebx, 31, 31) == 0) {
8507c478bd9Sstevel@tonic-gate 				uint8_t *p = (void *)&cp->cp_ebx;
8517c478bd9Sstevel@tonic-gate 				for (i = 0; i < 4; i++)
8527c478bd9Sstevel@tonic-gate 					if (p[i] != 0)
8537c478bd9Sstevel@tonic-gate 						*dp++ = p[i];
8547c478bd9Sstevel@tonic-gate 			}
8557c478bd9Sstevel@tonic-gate 			if (BITX(cp->cp_ecx, 31, 31) == 0) {
8567c478bd9Sstevel@tonic-gate 				uint8_t *p = (void *)&cp->cp_ecx;
8577c478bd9Sstevel@tonic-gate 				for (i = 0; i < 4; i++)
8587c478bd9Sstevel@tonic-gate 					if (p[i] != 0)
8597c478bd9Sstevel@tonic-gate 						*dp++ = p[i];
8607c478bd9Sstevel@tonic-gate 			}
8617c478bd9Sstevel@tonic-gate 			if (BITX(cp->cp_edx, 31, 31) == 0) {
8627c478bd9Sstevel@tonic-gate 				uint8_t *p = (void *)&cp->cp_edx;
8637c478bd9Sstevel@tonic-gate 				for (i = 0; i < 4; i++)
8647c478bd9Sstevel@tonic-gate 					if (p[i] != 0)
8657c478bd9Sstevel@tonic-gate 						*dp++ = p[i];
8667c478bd9Sstevel@tonic-gate 			}
8677c478bd9Sstevel@tonic-gate 			break;
8687c478bd9Sstevel@tonic-gate 		case 3:	/* Processor serial number, if PSN supported */
8697c478bd9Sstevel@tonic-gate 		case 4:	/* Deterministic cache parameters */
8707c478bd9Sstevel@tonic-gate 		case 5:	/* Monitor/Mwait parameters */
8717c478bd9Sstevel@tonic-gate 		default:
8727c478bd9Sstevel@tonic-gate 			break;
8737c478bd9Sstevel@tonic-gate 		}
8747c478bd9Sstevel@tonic-gate 	}
8757c478bd9Sstevel@tonic-gate 
8767c478bd9Sstevel@tonic-gate 	if ((cpi->cpi_xmaxeax & 0x80000000) == 0)
8777c478bd9Sstevel@tonic-gate 		goto pass2_done;
8787c478bd9Sstevel@tonic-gate 
8797c478bd9Sstevel@tonic-gate 	if ((nmax = cpi->cpi_xmaxeax - 0x80000000 + 1) > NMAX_CPI_EXTD)
8807c478bd9Sstevel@tonic-gate 		nmax = NMAX_CPI_EXTD;
8817c478bd9Sstevel@tonic-gate 	/*
8827c478bd9Sstevel@tonic-gate 	 * Copy the extended properties, fixing them as we go.
8837c478bd9Sstevel@tonic-gate 	 * (We already handled n == 0 and n == 1 in pass 1)
8847c478bd9Sstevel@tonic-gate 	 */
8857c478bd9Sstevel@tonic-gate 	iptr = (void *)cpi->cpi_brandstr;
8867c478bd9Sstevel@tonic-gate 	for (n = 2, cp = &cpi->cpi_extd[2]; n < nmax; cp++, n++) {
887*8949bcd6Sandrei 		cp->cp_eax = 0x80000000 + n;
888*8949bcd6Sandrei 		(void) __cpuid_insn(cp);
8897c478bd9Sstevel@tonic-gate 		switch (n) {
8907c478bd9Sstevel@tonic-gate 		case 2:
8917c478bd9Sstevel@tonic-gate 		case 3:
8927c478bd9Sstevel@tonic-gate 		case 4:
8937c478bd9Sstevel@tonic-gate 			/*
8947c478bd9Sstevel@tonic-gate 			 * Extract the brand string
8957c478bd9Sstevel@tonic-gate 			 */
8967c478bd9Sstevel@tonic-gate 			*iptr++ = cp->cp_eax;
8977c478bd9Sstevel@tonic-gate 			*iptr++ = cp->cp_ebx;
8987c478bd9Sstevel@tonic-gate 			*iptr++ = cp->cp_ecx;
8997c478bd9Sstevel@tonic-gate 			*iptr++ = cp->cp_edx;
9007c478bd9Sstevel@tonic-gate 			break;
9017c478bd9Sstevel@tonic-gate 		case 5:
9027c478bd9Sstevel@tonic-gate 			switch (cpi->cpi_vendor) {
9037c478bd9Sstevel@tonic-gate 			case X86_VENDOR_AMD:
9047c478bd9Sstevel@tonic-gate 				/*
9057c478bd9Sstevel@tonic-gate 				 * The Athlon and Duron were the first
9067c478bd9Sstevel@tonic-gate 				 * parts to report the sizes of the
9077c478bd9Sstevel@tonic-gate 				 * TLB for large pages. Before then,
9087c478bd9Sstevel@tonic-gate 				 * we don't trust the data.
9097c478bd9Sstevel@tonic-gate 				 */
9107c478bd9Sstevel@tonic-gate 				if (cpi->cpi_family < 6 ||
9117c478bd9Sstevel@tonic-gate 				    (cpi->cpi_family == 6 &&
9127c478bd9Sstevel@tonic-gate 				    cpi->cpi_model < 1))
9137c478bd9Sstevel@tonic-gate 					cp->cp_eax = 0;
9147c478bd9Sstevel@tonic-gate 				break;
9157c478bd9Sstevel@tonic-gate 			default:
9167c478bd9Sstevel@tonic-gate 				break;
9177c478bd9Sstevel@tonic-gate 			}
9187c478bd9Sstevel@tonic-gate 			break;
9197c478bd9Sstevel@tonic-gate 		case 6:
9207c478bd9Sstevel@tonic-gate 			switch (cpi->cpi_vendor) {
9217c478bd9Sstevel@tonic-gate 			case X86_VENDOR_AMD:
9227c478bd9Sstevel@tonic-gate 				/*
9237c478bd9Sstevel@tonic-gate 				 * The Athlon and Duron were the first
9247c478bd9Sstevel@tonic-gate 				 * AMD parts with L2 TLB's.
9257c478bd9Sstevel@tonic-gate 				 * Before then, don't trust the data.
9267c478bd9Sstevel@tonic-gate 				 */
9277c478bd9Sstevel@tonic-gate 				if (cpi->cpi_family < 6 ||
9287c478bd9Sstevel@tonic-gate 				    cpi->cpi_family == 6 &&
9297c478bd9Sstevel@tonic-gate 				    cpi->cpi_model < 1)
9307c478bd9Sstevel@tonic-gate 					cp->cp_eax = cp->cp_ebx = 0;
9317c478bd9Sstevel@tonic-gate 				/*
9327c478bd9Sstevel@tonic-gate 				 * AMD Duron rev A0 reports L2
9337c478bd9Sstevel@tonic-gate 				 * cache size incorrectly as 1K
9347c478bd9Sstevel@tonic-gate 				 * when it is really 64K
9357c478bd9Sstevel@tonic-gate 				 */
9367c478bd9Sstevel@tonic-gate 				if (cpi->cpi_family == 6 &&
9377c478bd9Sstevel@tonic-gate 				    cpi->cpi_model == 3 &&
9387c478bd9Sstevel@tonic-gate 				    cpi->cpi_step == 0) {
9397c478bd9Sstevel@tonic-gate 					cp->cp_ecx &= 0xffff;
9407c478bd9Sstevel@tonic-gate 					cp->cp_ecx |= 0x400000;
9417c478bd9Sstevel@tonic-gate 				}
9427c478bd9Sstevel@tonic-gate 				break;
9437c478bd9Sstevel@tonic-gate 			case X86_VENDOR_Cyrix:	/* VIA C3 */
9447c478bd9Sstevel@tonic-gate 				/*
9457c478bd9Sstevel@tonic-gate 				 * VIA C3 processors are a bit messed
9467c478bd9Sstevel@tonic-gate 				 * up w.r.t. encoding cache sizes in %ecx
9477c478bd9Sstevel@tonic-gate 				 */
9487c478bd9Sstevel@tonic-gate 				if (cpi->cpi_family != 6)
9497c478bd9Sstevel@tonic-gate 					break;
9507c478bd9Sstevel@tonic-gate 				/*
9517c478bd9Sstevel@tonic-gate 				 * model 7 and 8 were incorrectly encoded
9527c478bd9Sstevel@tonic-gate 				 *
9537c478bd9Sstevel@tonic-gate 				 * xxx is model 8 really broken?
9547c478bd9Sstevel@tonic-gate 				 */
9557c478bd9Sstevel@tonic-gate 				if (cpi->cpi_model == 7 ||
9567c478bd9Sstevel@tonic-gate 				    cpi->cpi_model == 8)
9577c478bd9Sstevel@tonic-gate 					cp->cp_ecx =
9587c478bd9Sstevel@tonic-gate 					    BITX(cp->cp_ecx, 31, 24) << 16 |
9597c478bd9Sstevel@tonic-gate 					    BITX(cp->cp_ecx, 23, 16) << 12 |
9607c478bd9Sstevel@tonic-gate 					    BITX(cp->cp_ecx, 15, 8) << 8 |
9617c478bd9Sstevel@tonic-gate 					    BITX(cp->cp_ecx, 7, 0);
9627c478bd9Sstevel@tonic-gate 				/*
9637c478bd9Sstevel@tonic-gate 				 * model 9 stepping 1 has wrong associativity
9647c478bd9Sstevel@tonic-gate 				 */
9657c478bd9Sstevel@tonic-gate 				if (cpi->cpi_model == 9 && cpi->cpi_step == 1)
9667c478bd9Sstevel@tonic-gate 					cp->cp_ecx |= 8 << 12;
9677c478bd9Sstevel@tonic-gate 				break;
9687c478bd9Sstevel@tonic-gate 			case X86_VENDOR_Intel:
9697c478bd9Sstevel@tonic-gate 				/*
9707c478bd9Sstevel@tonic-gate 				 * Extended L2 Cache features function.
9717c478bd9Sstevel@tonic-gate 				 * First appeared on Prescott.
9727c478bd9Sstevel@tonic-gate 				 */
9737c478bd9Sstevel@tonic-gate 			default:
9747c478bd9Sstevel@tonic-gate 				break;
9757c478bd9Sstevel@tonic-gate 			}
9767c478bd9Sstevel@tonic-gate 			break;
9777c478bd9Sstevel@tonic-gate 		default:
9787c478bd9Sstevel@tonic-gate 			break;
9797c478bd9Sstevel@tonic-gate 		}
9807c478bd9Sstevel@tonic-gate 	}
9817c478bd9Sstevel@tonic-gate 
9827c478bd9Sstevel@tonic-gate pass2_done:
9837c478bd9Sstevel@tonic-gate 	cpi->cpi_pass = 2;
9847c478bd9Sstevel@tonic-gate }
9857c478bd9Sstevel@tonic-gate 
9867c478bd9Sstevel@tonic-gate static const char *
9877c478bd9Sstevel@tonic-gate intel_cpubrand(const struct cpuid_info *cpi)
9887c478bd9Sstevel@tonic-gate {
9897c478bd9Sstevel@tonic-gate 	int i;
9907c478bd9Sstevel@tonic-gate 
9917c478bd9Sstevel@tonic-gate 	if ((x86_feature & X86_CPUID) == 0 ||
9927c478bd9Sstevel@tonic-gate 	    cpi->cpi_maxeax < 1 || cpi->cpi_family < 5)
9937c478bd9Sstevel@tonic-gate 		return ("i486");
9947c478bd9Sstevel@tonic-gate 
9957c478bd9Sstevel@tonic-gate 	switch (cpi->cpi_family) {
9967c478bd9Sstevel@tonic-gate 	case 5:
9977c478bd9Sstevel@tonic-gate 		return ("Intel Pentium(r)");
9987c478bd9Sstevel@tonic-gate 	case 6:
9997c478bd9Sstevel@tonic-gate 		switch (cpi->cpi_model) {
10007c478bd9Sstevel@tonic-gate 			uint_t celeron, xeon;
1001*8949bcd6Sandrei 			const struct cpuid_regs *cp;
10027c478bd9Sstevel@tonic-gate 		case 0:
10037c478bd9Sstevel@tonic-gate 		case 1:
10047c478bd9Sstevel@tonic-gate 		case 2:
10057c478bd9Sstevel@tonic-gate 			return ("Intel Pentium(r) Pro");
10067c478bd9Sstevel@tonic-gate 		case 3:
10077c478bd9Sstevel@tonic-gate 		case 4:
10087c478bd9Sstevel@tonic-gate 			return ("Intel Pentium(r) II");
10097c478bd9Sstevel@tonic-gate 		case 6:
10107c478bd9Sstevel@tonic-gate 			return ("Intel Celeron(r)");
10117c478bd9Sstevel@tonic-gate 		case 5:
10127c478bd9Sstevel@tonic-gate 		case 7:
10137c478bd9Sstevel@tonic-gate 			celeron = xeon = 0;
10147c478bd9Sstevel@tonic-gate 			cp = &cpi->cpi_std[2];	/* cache info */
10157c478bd9Sstevel@tonic-gate 
10167c478bd9Sstevel@tonic-gate 			for (i = 1; i < 3; i++) {
10177c478bd9Sstevel@tonic-gate 				uint_t tmp;
10187c478bd9Sstevel@tonic-gate 
10197c478bd9Sstevel@tonic-gate 				tmp = (cp->cp_eax >> (8 * i)) & 0xff;
10207c478bd9Sstevel@tonic-gate 				if (tmp == 0x40)
10217c478bd9Sstevel@tonic-gate 					celeron++;
10227c478bd9Sstevel@tonic-gate 				if (tmp >= 0x44 && tmp <= 0x45)
10237c478bd9Sstevel@tonic-gate 					xeon++;
10247c478bd9Sstevel@tonic-gate 			}
10257c478bd9Sstevel@tonic-gate 
10267c478bd9Sstevel@tonic-gate 			for (i = 0; i < 2; i++) {
10277c478bd9Sstevel@tonic-gate 				uint_t tmp;
10287c478bd9Sstevel@tonic-gate 
10297c478bd9Sstevel@tonic-gate 				tmp = (cp->cp_ebx >> (8 * i)) & 0xff;
10307c478bd9Sstevel@tonic-gate 				if (tmp == 0x40)
10317c478bd9Sstevel@tonic-gate 					celeron++;
10327c478bd9Sstevel@tonic-gate 				else if (tmp >= 0x44 && tmp <= 0x45)
10337c478bd9Sstevel@tonic-gate 					xeon++;
10347c478bd9Sstevel@tonic-gate 			}
10357c478bd9Sstevel@tonic-gate 
10367c478bd9Sstevel@tonic-gate 			for (i = 0; i < 4; i++) {
10377c478bd9Sstevel@tonic-gate 				uint_t tmp;
10387c478bd9Sstevel@tonic-gate 
10397c478bd9Sstevel@tonic-gate 				tmp = (cp->cp_ecx >> (8 * i)) & 0xff;
10407c478bd9Sstevel@tonic-gate 				if (tmp == 0x40)
10417c478bd9Sstevel@tonic-gate 					celeron++;
10427c478bd9Sstevel@tonic-gate 				else if (tmp >= 0x44 && tmp <= 0x45)
10437c478bd9Sstevel@tonic-gate 					xeon++;
10447c478bd9Sstevel@tonic-gate 			}
10457c478bd9Sstevel@tonic-gate 
10467c478bd9Sstevel@tonic-gate 			for (i = 0; i < 4; i++) {
10477c478bd9Sstevel@tonic-gate 				uint_t tmp;
10487c478bd9Sstevel@tonic-gate 
10497c478bd9Sstevel@tonic-gate 				tmp = (cp->cp_edx >> (8 * i)) & 0xff;
10507c478bd9Sstevel@tonic-gate 				if (tmp == 0x40)
10517c478bd9Sstevel@tonic-gate 					celeron++;
10527c478bd9Sstevel@tonic-gate 				else if (tmp >= 0x44 && tmp <= 0x45)
10537c478bd9Sstevel@tonic-gate 					xeon++;
10547c478bd9Sstevel@tonic-gate 			}
10557c478bd9Sstevel@tonic-gate 
10567c478bd9Sstevel@tonic-gate 			if (celeron)
10577c478bd9Sstevel@tonic-gate 				return ("Intel Celeron(r)");
10587c478bd9Sstevel@tonic-gate 			if (xeon)
10597c478bd9Sstevel@tonic-gate 				return (cpi->cpi_model == 5 ?
10607c478bd9Sstevel@tonic-gate 				    "Intel Pentium(r) II Xeon(tm)" :
10617c478bd9Sstevel@tonic-gate 				    "Intel Pentium(r) III Xeon(tm)");
10627c478bd9Sstevel@tonic-gate 			return (cpi->cpi_model == 5 ?
10637c478bd9Sstevel@tonic-gate 			    "Intel Pentium(r) II or Pentium(r) II Xeon(tm)" :
10647c478bd9Sstevel@tonic-gate 			    "Intel Pentium(r) III or Pentium(r) III Xeon(tm)");
10657c478bd9Sstevel@tonic-gate 		default:
10667c478bd9Sstevel@tonic-gate 			break;
10677c478bd9Sstevel@tonic-gate 		}
10687c478bd9Sstevel@tonic-gate 	default:
10697c478bd9Sstevel@tonic-gate 		break;
10707c478bd9Sstevel@tonic-gate 	}
10717c478bd9Sstevel@tonic-gate 
10727c478bd9Sstevel@tonic-gate 	if (cpi->cpi_family <= 0xf && cpi->cpi_model <= 0xf &&
10737c478bd9Sstevel@tonic-gate 	    cpi->cpi_brandid != 0) {
10747c478bd9Sstevel@tonic-gate 		static const struct {
10757c478bd9Sstevel@tonic-gate 			uint_t bt_bid;
10767c478bd9Sstevel@tonic-gate 			const char *bt_str;
10777c478bd9Sstevel@tonic-gate 		} brand_tbl[] = {
10787c478bd9Sstevel@tonic-gate 			{ 0x1,	"Intel(r) Celeron(r)" },
10797c478bd9Sstevel@tonic-gate 			{ 0x2,	"Intel(r) Pentium(r) III" },
10807c478bd9Sstevel@tonic-gate 			{ 0x3,	"Intel(r) Pentium(r) III Xeon(tm)" },
10817c478bd9Sstevel@tonic-gate 			{ 0x4,	"Intel(r) Pentium(r) III" },
10827c478bd9Sstevel@tonic-gate 			{ 0x6,	"Mobile Intel(r) Pentium(r) III" },
10837c478bd9Sstevel@tonic-gate 			{ 0x7,	"Mobile Intel(r) Celeron(r)" },
10847c478bd9Sstevel@tonic-gate 			{ 0x8,	"Intel(r) Pentium(r) 4" },
10857c478bd9Sstevel@tonic-gate 			{ 0x9,	"Intel(r) Pentium(r) 4" },
10867c478bd9Sstevel@tonic-gate 			{ 0xa,	"Intel(r) Celeron(r)" },
10877c478bd9Sstevel@tonic-gate 			{ 0xb,	"Intel(r) Xeon(tm)" },
10887c478bd9Sstevel@tonic-gate 			{ 0xc,	"Intel(r) Xeon(tm) MP" },
10897c478bd9Sstevel@tonic-gate 			{ 0xe,	"Mobile Intel(r) Pentium(r) 4" },
10907c478bd9Sstevel@tonic-gate 			{ 0xf,	"Mobile Intel(r) Celeron(r)" }
10917c478bd9Sstevel@tonic-gate 		};
10927c478bd9Sstevel@tonic-gate 		uint_t btblmax = sizeof (brand_tbl) / sizeof (brand_tbl[0]);
10937c478bd9Sstevel@tonic-gate 		uint_t sgn;
10947c478bd9Sstevel@tonic-gate 
10957c478bd9Sstevel@tonic-gate 		sgn = (cpi->cpi_family << 8) |
10967c478bd9Sstevel@tonic-gate 		    (cpi->cpi_model << 4) | cpi->cpi_step;
10977c478bd9Sstevel@tonic-gate 
10987c478bd9Sstevel@tonic-gate 		for (i = 0; i < btblmax; i++)
10997c478bd9Sstevel@tonic-gate 			if (brand_tbl[i].bt_bid == cpi->cpi_brandid)
11007c478bd9Sstevel@tonic-gate 				break;
11017c478bd9Sstevel@tonic-gate 		if (i < btblmax) {
11027c478bd9Sstevel@tonic-gate 			if (sgn == 0x6b1 && cpi->cpi_brandid == 3)
11037c478bd9Sstevel@tonic-gate 				return ("Intel(r) Celeron(r)");
11047c478bd9Sstevel@tonic-gate 			if (sgn < 0xf13 && cpi->cpi_brandid == 0xb)
11057c478bd9Sstevel@tonic-gate 				return ("Intel(r) Xeon(tm) MP");
11067c478bd9Sstevel@tonic-gate 			if (sgn < 0xf13 && cpi->cpi_brandid == 0xe)
11077c478bd9Sstevel@tonic-gate 				return ("Intel(r) Xeon(tm)");
11087c478bd9Sstevel@tonic-gate 			return (brand_tbl[i].bt_str);
11097c478bd9Sstevel@tonic-gate 		}
11107c478bd9Sstevel@tonic-gate 	}
11117c478bd9Sstevel@tonic-gate 
11127c478bd9Sstevel@tonic-gate 	return (NULL);
11137c478bd9Sstevel@tonic-gate }
11147c478bd9Sstevel@tonic-gate 
11157c478bd9Sstevel@tonic-gate static const char *
11167c478bd9Sstevel@tonic-gate amd_cpubrand(const struct cpuid_info *cpi)
11177c478bd9Sstevel@tonic-gate {
11187c478bd9Sstevel@tonic-gate 	if ((x86_feature & X86_CPUID) == 0 ||
11197c478bd9Sstevel@tonic-gate 	    cpi->cpi_maxeax < 1 || cpi->cpi_family < 5)
11207c478bd9Sstevel@tonic-gate 		return ("i486 compatible");
11217c478bd9Sstevel@tonic-gate 
11227c478bd9Sstevel@tonic-gate 	switch (cpi->cpi_family) {
11237c478bd9Sstevel@tonic-gate 	case 5:
11247c478bd9Sstevel@tonic-gate 		switch (cpi->cpi_model) {
11257c478bd9Sstevel@tonic-gate 		case 0:
11267c478bd9Sstevel@tonic-gate 		case 1:
11277c478bd9Sstevel@tonic-gate 		case 2:
11287c478bd9Sstevel@tonic-gate 		case 3:
11297c478bd9Sstevel@tonic-gate 		case 4:
11307c478bd9Sstevel@tonic-gate 		case 5:
11317c478bd9Sstevel@tonic-gate 			return ("AMD-K5(r)");
11327c478bd9Sstevel@tonic-gate 		case 6:
11337c478bd9Sstevel@tonic-gate 		case 7:
11347c478bd9Sstevel@tonic-gate 			return ("AMD-K6(r)");
11357c478bd9Sstevel@tonic-gate 		case 8:
11367c478bd9Sstevel@tonic-gate 			return ("AMD-K6(r)-2");
11377c478bd9Sstevel@tonic-gate 		case 9:
11387c478bd9Sstevel@tonic-gate 			return ("AMD-K6(r)-III");
11397c478bd9Sstevel@tonic-gate 		default:
11407c478bd9Sstevel@tonic-gate 			return ("AMD (family 5)");
11417c478bd9Sstevel@tonic-gate 		}
11427c478bd9Sstevel@tonic-gate 	case 6:
11437c478bd9Sstevel@tonic-gate 		switch (cpi->cpi_model) {
11447c478bd9Sstevel@tonic-gate 		case 1:
11457c478bd9Sstevel@tonic-gate 			return ("AMD-K7(tm)");
11467c478bd9Sstevel@tonic-gate 		case 0:
11477c478bd9Sstevel@tonic-gate 		case 2:
11487c478bd9Sstevel@tonic-gate 		case 4:
11497c478bd9Sstevel@tonic-gate 			return ("AMD Athlon(tm)");
11507c478bd9Sstevel@tonic-gate 		case 3:
11517c478bd9Sstevel@tonic-gate 		case 7:
11527c478bd9Sstevel@tonic-gate 			return ("AMD Duron(tm)");
11537c478bd9Sstevel@tonic-gate 		case 6:
11547c478bd9Sstevel@tonic-gate 		case 8:
11557c478bd9Sstevel@tonic-gate 		case 10:
11567c478bd9Sstevel@tonic-gate 			/*
11577c478bd9Sstevel@tonic-gate 			 * Use the L2 cache size to distinguish
11587c478bd9Sstevel@tonic-gate 			 */
11597c478bd9Sstevel@tonic-gate 			return ((cpi->cpi_extd[6].cp_ecx >> 16) >= 256 ?
11607c478bd9Sstevel@tonic-gate 			    "AMD Athlon(tm)" : "AMD Duron(tm)");
11617c478bd9Sstevel@tonic-gate 		default:
11627c478bd9Sstevel@tonic-gate 			return ("AMD (family 6)");
11637c478bd9Sstevel@tonic-gate 		}
11647c478bd9Sstevel@tonic-gate 	default:
11657c478bd9Sstevel@tonic-gate 		break;
11667c478bd9Sstevel@tonic-gate 	}
11677c478bd9Sstevel@tonic-gate 
11687c478bd9Sstevel@tonic-gate 	if (cpi->cpi_family == 0xf && cpi->cpi_model == 5 &&
11697c478bd9Sstevel@tonic-gate 	    cpi->cpi_brandid != 0) {
11707c478bd9Sstevel@tonic-gate 		switch (BITX(cpi->cpi_brandid, 7, 5)) {
11717c478bd9Sstevel@tonic-gate 		case 3:
11727c478bd9Sstevel@tonic-gate 			return ("AMD Opteron(tm) UP 1xx");
11737c478bd9Sstevel@tonic-gate 		case 4:
11747c478bd9Sstevel@tonic-gate 			return ("AMD Opteron(tm) DP 2xx");
11757c478bd9Sstevel@tonic-gate 		case 5:
11767c478bd9Sstevel@tonic-gate 			return ("AMD Opteron(tm) MP 8xx");
11777c478bd9Sstevel@tonic-gate 		default:
11787c478bd9Sstevel@tonic-gate 			return ("AMD Opteron(tm)");
11797c478bd9Sstevel@tonic-gate 		}
11807c478bd9Sstevel@tonic-gate 	}
11817c478bd9Sstevel@tonic-gate 
11827c478bd9Sstevel@tonic-gate 	return (NULL);
11837c478bd9Sstevel@tonic-gate }
11847c478bd9Sstevel@tonic-gate 
11857c478bd9Sstevel@tonic-gate static const char *
11867c478bd9Sstevel@tonic-gate cyrix_cpubrand(struct cpuid_info *cpi, uint_t type)
11877c478bd9Sstevel@tonic-gate {
11887c478bd9Sstevel@tonic-gate 	if ((x86_feature & X86_CPUID) == 0 ||
11897c478bd9Sstevel@tonic-gate 	    cpi->cpi_maxeax < 1 || cpi->cpi_family < 5 ||
11907c478bd9Sstevel@tonic-gate 	    type == X86_TYPE_CYRIX_486)
11917c478bd9Sstevel@tonic-gate 		return ("i486 compatible");
11927c478bd9Sstevel@tonic-gate 
11937c478bd9Sstevel@tonic-gate 	switch (type) {
11947c478bd9Sstevel@tonic-gate 	case X86_TYPE_CYRIX_6x86:
11957c478bd9Sstevel@tonic-gate 		return ("Cyrix 6x86");
11967c478bd9Sstevel@tonic-gate 	case X86_TYPE_CYRIX_6x86L:
11977c478bd9Sstevel@tonic-gate 		return ("Cyrix 6x86L");
11987c478bd9Sstevel@tonic-gate 	case X86_TYPE_CYRIX_6x86MX:
11997c478bd9Sstevel@tonic-gate 		return ("Cyrix 6x86MX");
12007c478bd9Sstevel@tonic-gate 	case X86_TYPE_CYRIX_GXm:
12017c478bd9Sstevel@tonic-gate 		return ("Cyrix GXm");
12027c478bd9Sstevel@tonic-gate 	case X86_TYPE_CYRIX_MediaGX:
12037c478bd9Sstevel@tonic-gate 		return ("Cyrix MediaGX");
12047c478bd9Sstevel@tonic-gate 	case X86_TYPE_CYRIX_MII:
12057c478bd9Sstevel@tonic-gate 		return ("Cyrix M2");
12067c478bd9Sstevel@tonic-gate 	case X86_TYPE_VIA_CYRIX_III:
12077c478bd9Sstevel@tonic-gate 		return ("VIA Cyrix M3");
12087c478bd9Sstevel@tonic-gate 	default:
12097c478bd9Sstevel@tonic-gate 		/*
12107c478bd9Sstevel@tonic-gate 		 * Have another wild guess ..
12117c478bd9Sstevel@tonic-gate 		 */
12127c478bd9Sstevel@tonic-gate 		if (cpi->cpi_family == 4 && cpi->cpi_model == 9)
12137c478bd9Sstevel@tonic-gate 			return ("Cyrix 5x86");
12147c478bd9Sstevel@tonic-gate 		else if (cpi->cpi_family == 5) {
12157c478bd9Sstevel@tonic-gate 			switch (cpi->cpi_model) {
12167c478bd9Sstevel@tonic-gate 			case 2:
12177c478bd9Sstevel@tonic-gate 				return ("Cyrix 6x86");	/* Cyrix M1 */
12187c478bd9Sstevel@tonic-gate 			case 4:
12197c478bd9Sstevel@tonic-gate 				return ("Cyrix MediaGX");
12207c478bd9Sstevel@tonic-gate 			default:
12217c478bd9Sstevel@tonic-gate 				break;
12227c478bd9Sstevel@tonic-gate 			}
12237c478bd9Sstevel@tonic-gate 		} else if (cpi->cpi_family == 6) {
12247c478bd9Sstevel@tonic-gate 			switch (cpi->cpi_model) {
12257c478bd9Sstevel@tonic-gate 			case 0:
12267c478bd9Sstevel@tonic-gate 				return ("Cyrix 6x86MX"); /* Cyrix M2? */
12277c478bd9Sstevel@tonic-gate 			case 5:
12287c478bd9Sstevel@tonic-gate 			case 6:
12297c478bd9Sstevel@tonic-gate 			case 7:
12307c478bd9Sstevel@tonic-gate 			case 8:
12317c478bd9Sstevel@tonic-gate 			case 9:
12327c478bd9Sstevel@tonic-gate 				return ("VIA C3");
12337c478bd9Sstevel@tonic-gate 			default:
12347c478bd9Sstevel@tonic-gate 				break;
12357c478bd9Sstevel@tonic-gate 			}
12367c478bd9Sstevel@tonic-gate 		}
12377c478bd9Sstevel@tonic-gate 		break;
12387c478bd9Sstevel@tonic-gate 	}
12397c478bd9Sstevel@tonic-gate 	return (NULL);
12407c478bd9Sstevel@tonic-gate }
12417c478bd9Sstevel@tonic-gate 
12427c478bd9Sstevel@tonic-gate /*
12437c478bd9Sstevel@tonic-gate  * This only gets called in the case that the CPU extended
12447c478bd9Sstevel@tonic-gate  * feature brand string (0x80000002, 0x80000003, 0x80000004)
12457c478bd9Sstevel@tonic-gate  * aren't available, or contain null bytes for some reason.
12467c478bd9Sstevel@tonic-gate  */
12477c478bd9Sstevel@tonic-gate static void
12487c478bd9Sstevel@tonic-gate fabricate_brandstr(struct cpuid_info *cpi)
12497c478bd9Sstevel@tonic-gate {
12507c478bd9Sstevel@tonic-gate 	const char *brand = NULL;
12517c478bd9Sstevel@tonic-gate 
12527c478bd9Sstevel@tonic-gate 	switch (cpi->cpi_vendor) {
12537c478bd9Sstevel@tonic-gate 	case X86_VENDOR_Intel:
12547c478bd9Sstevel@tonic-gate 		brand = intel_cpubrand(cpi);
12557c478bd9Sstevel@tonic-gate 		break;
12567c478bd9Sstevel@tonic-gate 	case X86_VENDOR_AMD:
12577c478bd9Sstevel@tonic-gate 		brand = amd_cpubrand(cpi);
12587c478bd9Sstevel@tonic-gate 		break;
12597c478bd9Sstevel@tonic-gate 	case X86_VENDOR_Cyrix:
12607c478bd9Sstevel@tonic-gate 		brand = cyrix_cpubrand(cpi, x86_type);
12617c478bd9Sstevel@tonic-gate 		break;
12627c478bd9Sstevel@tonic-gate 	case X86_VENDOR_NexGen:
12637c478bd9Sstevel@tonic-gate 		if (cpi->cpi_family == 5 && cpi->cpi_model == 0)
12647c478bd9Sstevel@tonic-gate 			brand = "NexGen Nx586";
12657c478bd9Sstevel@tonic-gate 		break;
12667c478bd9Sstevel@tonic-gate 	case X86_VENDOR_Centaur:
12677c478bd9Sstevel@tonic-gate 		if (cpi->cpi_family == 5)
12687c478bd9Sstevel@tonic-gate 			switch (cpi->cpi_model) {
12697c478bd9Sstevel@tonic-gate 			case 4:
12707c478bd9Sstevel@tonic-gate 				brand = "Centaur C6";
12717c478bd9Sstevel@tonic-gate 				break;
12727c478bd9Sstevel@tonic-gate 			case 8:
12737c478bd9Sstevel@tonic-gate 				brand = "Centaur C2";
12747c478bd9Sstevel@tonic-gate 				break;
12757c478bd9Sstevel@tonic-gate 			case 9:
12767c478bd9Sstevel@tonic-gate 				brand = "Centaur C3";
12777c478bd9Sstevel@tonic-gate 				break;
12787c478bd9Sstevel@tonic-gate 			default:
12797c478bd9Sstevel@tonic-gate 				break;
12807c478bd9Sstevel@tonic-gate 			}
12817c478bd9Sstevel@tonic-gate 		break;
12827c478bd9Sstevel@tonic-gate 	case X86_VENDOR_Rise:
12837c478bd9Sstevel@tonic-gate 		if (cpi->cpi_family == 5 &&
12847c478bd9Sstevel@tonic-gate 		    (cpi->cpi_model == 0 || cpi->cpi_model == 2))
12857c478bd9Sstevel@tonic-gate 			brand = "Rise mP6";
12867c478bd9Sstevel@tonic-gate 		break;
12877c478bd9Sstevel@tonic-gate 	case X86_VENDOR_SiS:
12887c478bd9Sstevel@tonic-gate 		if (cpi->cpi_family == 5 && cpi->cpi_model == 0)
12897c478bd9Sstevel@tonic-gate 			brand = "SiS 55x";
12907c478bd9Sstevel@tonic-gate 		break;
12917c478bd9Sstevel@tonic-gate 	case X86_VENDOR_TM:
12927c478bd9Sstevel@tonic-gate 		if (cpi->cpi_family == 5 && cpi->cpi_model == 4)
12937c478bd9Sstevel@tonic-gate 			brand = "Transmeta Crusoe TM3x00 or TM5x00";
12947c478bd9Sstevel@tonic-gate 		break;
12957c478bd9Sstevel@tonic-gate 	case X86_VENDOR_NSC:
12967c478bd9Sstevel@tonic-gate 	case X86_VENDOR_UMC:
12977c478bd9Sstevel@tonic-gate 	default:
12987c478bd9Sstevel@tonic-gate 		break;
12997c478bd9Sstevel@tonic-gate 	}
13007c478bd9Sstevel@tonic-gate 	if (brand) {
13017c478bd9Sstevel@tonic-gate 		(void) strcpy((char *)cpi->cpi_brandstr, brand);
13027c478bd9Sstevel@tonic-gate 		return;
13037c478bd9Sstevel@tonic-gate 	}
13047c478bd9Sstevel@tonic-gate 
13057c478bd9Sstevel@tonic-gate 	/*
13067c478bd9Sstevel@tonic-gate 	 * If all else fails ...
13077c478bd9Sstevel@tonic-gate 	 */
13087c478bd9Sstevel@tonic-gate 	(void) snprintf(cpi->cpi_brandstr, sizeof (cpi->cpi_brandstr),
13097c478bd9Sstevel@tonic-gate 	    "%s %d.%d.%d", cpi->cpi_vendorstr, cpi->cpi_family,
13107c478bd9Sstevel@tonic-gate 	    cpi->cpi_model, cpi->cpi_step);
13117c478bd9Sstevel@tonic-gate }
13127c478bd9Sstevel@tonic-gate 
13137c478bd9Sstevel@tonic-gate /*
13147c478bd9Sstevel@tonic-gate  * This routine is called just after kernel memory allocation
13157c478bd9Sstevel@tonic-gate  * becomes available on cpu0, and as part of mp_startup() on
13167c478bd9Sstevel@tonic-gate  * the other cpus.
13177c478bd9Sstevel@tonic-gate  *
13187c478bd9Sstevel@tonic-gate  * Fixup the brand string.
13197c478bd9Sstevel@tonic-gate  */
13207c478bd9Sstevel@tonic-gate /*ARGSUSED*/
13217c478bd9Sstevel@tonic-gate void
13227c478bd9Sstevel@tonic-gate cpuid_pass3(cpu_t *cpu)
13237c478bd9Sstevel@tonic-gate {
13247c478bd9Sstevel@tonic-gate 	struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi;
13257c478bd9Sstevel@tonic-gate 
13267c478bd9Sstevel@tonic-gate 	ASSERT(cpi->cpi_pass == 2);
13277c478bd9Sstevel@tonic-gate 
13287c478bd9Sstevel@tonic-gate 	if ((cpi->cpi_xmaxeax & 0x80000000) == 0) {
13297c478bd9Sstevel@tonic-gate 		fabricate_brandstr(cpi);
13307c478bd9Sstevel@tonic-gate 		goto pass3_done;
13317c478bd9Sstevel@tonic-gate 	}
13327c478bd9Sstevel@tonic-gate 
13337c478bd9Sstevel@tonic-gate 	/*
13347c478bd9Sstevel@tonic-gate 	 * If we successfully extracted a brand string from the cpuid
13357c478bd9Sstevel@tonic-gate 	 * instruction, clean it up by removing leading spaces and
13367c478bd9Sstevel@tonic-gate 	 * similar junk.
13377c478bd9Sstevel@tonic-gate 	 */
13387c478bd9Sstevel@tonic-gate 	if (cpi->cpi_brandstr[0]) {
13397c478bd9Sstevel@tonic-gate 		size_t maxlen = sizeof (cpi->cpi_brandstr);
13407c478bd9Sstevel@tonic-gate 		char *src, *dst;
13417c478bd9Sstevel@tonic-gate 
13427c478bd9Sstevel@tonic-gate 		dst = src = (char *)cpi->cpi_brandstr;
13437c478bd9Sstevel@tonic-gate 		src[maxlen - 1] = '\0';
13447c478bd9Sstevel@tonic-gate 		/*
13457c478bd9Sstevel@tonic-gate 		 * strip leading spaces
13467c478bd9Sstevel@tonic-gate 		 */
13477c478bd9Sstevel@tonic-gate 		while (*src == ' ')
13487c478bd9Sstevel@tonic-gate 			src++;
13497c478bd9Sstevel@tonic-gate 		/*
13507c478bd9Sstevel@tonic-gate 		 * Remove any 'Genuine' or "Authentic" prefixes
13517c478bd9Sstevel@tonic-gate 		 */
13527c478bd9Sstevel@tonic-gate 		if (strncmp(src, "Genuine ", 8) == 0)
13537c478bd9Sstevel@tonic-gate 			src += 8;
13547c478bd9Sstevel@tonic-gate 		if (strncmp(src, "Authentic ", 10) == 0)
13557c478bd9Sstevel@tonic-gate 			src += 10;
13567c478bd9Sstevel@tonic-gate 
13577c478bd9Sstevel@tonic-gate 		/*
13587c478bd9Sstevel@tonic-gate 		 * Now do an in-place copy.
13597c478bd9Sstevel@tonic-gate 		 * Map (R) to (r) and (TM) to (tm).
13607c478bd9Sstevel@tonic-gate 		 * The era of teletypes is long gone, and there's
13617c478bd9Sstevel@tonic-gate 		 * -really- no need to shout.
13627c478bd9Sstevel@tonic-gate 		 */
13637c478bd9Sstevel@tonic-gate 		while (*src != '\0') {
13647c478bd9Sstevel@tonic-gate 			if (src[0] == '(') {
13657c478bd9Sstevel@tonic-gate 				if (strncmp(src + 1, "R)", 2) == 0) {
13667c478bd9Sstevel@tonic-gate 					(void) strncpy(dst, "(r)", 3);
13677c478bd9Sstevel@tonic-gate 					src += 3;
13687c478bd9Sstevel@tonic-gate 					dst += 3;
13697c478bd9Sstevel@tonic-gate 					continue;
13707c478bd9Sstevel@tonic-gate 				}
13717c478bd9Sstevel@tonic-gate 				if (strncmp(src + 1, "TM)", 3) == 0) {
13727c478bd9Sstevel@tonic-gate 					(void) strncpy(dst, "(tm)", 4);
13737c478bd9Sstevel@tonic-gate 					src += 4;
13747c478bd9Sstevel@tonic-gate 					dst += 4;
13757c478bd9Sstevel@tonic-gate 					continue;
13767c478bd9Sstevel@tonic-gate 				}
13777c478bd9Sstevel@tonic-gate 			}
13787c478bd9Sstevel@tonic-gate 			*dst++ = *src++;
13797c478bd9Sstevel@tonic-gate 		}
13807c478bd9Sstevel@tonic-gate 		*dst = '\0';
13817c478bd9Sstevel@tonic-gate 
13827c478bd9Sstevel@tonic-gate 		/*
13837c478bd9Sstevel@tonic-gate 		 * Finally, remove any trailing spaces
13847c478bd9Sstevel@tonic-gate 		 */
13857c478bd9Sstevel@tonic-gate 		while (--dst > cpi->cpi_brandstr)
13867c478bd9Sstevel@tonic-gate 			if (*dst == ' ')
13877c478bd9Sstevel@tonic-gate 				*dst = '\0';
13887c478bd9Sstevel@tonic-gate 			else
13897c478bd9Sstevel@tonic-gate 				break;
13907c478bd9Sstevel@tonic-gate 	} else
13917c478bd9Sstevel@tonic-gate 		fabricate_brandstr(cpi);
13927c478bd9Sstevel@tonic-gate 
13937c478bd9Sstevel@tonic-gate pass3_done:
13947c478bd9Sstevel@tonic-gate 	cpi->cpi_pass = 3;
13957c478bd9Sstevel@tonic-gate }
13967c478bd9Sstevel@tonic-gate 
13977c478bd9Sstevel@tonic-gate /*
13987c478bd9Sstevel@tonic-gate  * This routine is called out of bind_hwcap() much later in the life
13997c478bd9Sstevel@tonic-gate  * of the kernel (post_startup()).  The job of this routine is to resolve
14007c478bd9Sstevel@tonic-gate  * the hardware feature support and kernel support for those features into
14017c478bd9Sstevel@tonic-gate  * what we're actually going to tell applications via the aux vector.
14027c478bd9Sstevel@tonic-gate  */
14037c478bd9Sstevel@tonic-gate uint_t
14047c478bd9Sstevel@tonic-gate cpuid_pass4(cpu_t *cpu)
14057c478bd9Sstevel@tonic-gate {
14067c478bd9Sstevel@tonic-gate 	struct cpuid_info *cpi;
14077c478bd9Sstevel@tonic-gate 	uint_t hwcap_flags = 0;
14087c478bd9Sstevel@tonic-gate 
14097c478bd9Sstevel@tonic-gate 	if (cpu == NULL)
14107c478bd9Sstevel@tonic-gate 		cpu = CPU;
14117c478bd9Sstevel@tonic-gate 	cpi = cpu->cpu_m.mcpu_cpi;
14127c478bd9Sstevel@tonic-gate 
14137c478bd9Sstevel@tonic-gate 	ASSERT(cpi->cpi_pass == 3);
14147c478bd9Sstevel@tonic-gate 
14157c478bd9Sstevel@tonic-gate 	if (cpi->cpi_maxeax >= 1) {
14167c478bd9Sstevel@tonic-gate 		uint32_t *edx = &cpi->cpi_support[STD_EDX_FEATURES];
14177c478bd9Sstevel@tonic-gate 		uint32_t *ecx = &cpi->cpi_support[STD_ECX_FEATURES];
14187c478bd9Sstevel@tonic-gate 
14197c478bd9Sstevel@tonic-gate 		*edx = CPI_FEATURES_EDX(cpi);
14207c478bd9Sstevel@tonic-gate 		*ecx = CPI_FEATURES_ECX(cpi);
14217c478bd9Sstevel@tonic-gate 
14227c478bd9Sstevel@tonic-gate 		/*
14237c478bd9Sstevel@tonic-gate 		 * [these require explicit kernel support]
14247c478bd9Sstevel@tonic-gate 		 */
14257c478bd9Sstevel@tonic-gate 		if ((x86_feature & X86_SEP) == 0)
14267c478bd9Sstevel@tonic-gate 			*edx &= ~CPUID_INTC_EDX_SEP;
14277c478bd9Sstevel@tonic-gate 
14287c478bd9Sstevel@tonic-gate 		if ((x86_feature & X86_SSE) == 0)
14297c478bd9Sstevel@tonic-gate 			*edx &= ~(CPUID_INTC_EDX_FXSR|CPUID_INTC_EDX_SSE);
14307c478bd9Sstevel@tonic-gate 		if ((x86_feature & X86_SSE2) == 0)
14317c478bd9Sstevel@tonic-gate 			*edx &= ~CPUID_INTC_EDX_SSE2;
14327c478bd9Sstevel@tonic-gate 
14337c478bd9Sstevel@tonic-gate 		if ((x86_feature & X86_HTT) == 0)
14347c478bd9Sstevel@tonic-gate 			*edx &= ~CPUID_INTC_EDX_HTT;
14357c478bd9Sstevel@tonic-gate 
14367c478bd9Sstevel@tonic-gate 		if ((x86_feature & X86_SSE3) == 0)
14377c478bd9Sstevel@tonic-gate 			*ecx &= ~CPUID_INTC_ECX_SSE3;
14387c478bd9Sstevel@tonic-gate 
14397c478bd9Sstevel@tonic-gate 		/*
14407c478bd9Sstevel@tonic-gate 		 * [no explicit support required beyond x87 fp context]
14417c478bd9Sstevel@tonic-gate 		 */
14427c478bd9Sstevel@tonic-gate 		if (!fpu_exists)
14437c478bd9Sstevel@tonic-gate 			*edx &= ~(CPUID_INTC_EDX_FPU | CPUID_INTC_EDX_MMX);
14447c478bd9Sstevel@tonic-gate 
14457c478bd9Sstevel@tonic-gate 		/*
14467c478bd9Sstevel@tonic-gate 		 * Now map the supported feature vector to things that we
14477c478bd9Sstevel@tonic-gate 		 * think userland will care about.
14487c478bd9Sstevel@tonic-gate 		 */
14497c478bd9Sstevel@tonic-gate 		if (*edx & CPUID_INTC_EDX_SEP)
14507c478bd9Sstevel@tonic-gate 			hwcap_flags |= AV_386_SEP;
14517c478bd9Sstevel@tonic-gate 		if (*edx & CPUID_INTC_EDX_SSE)
14527c478bd9Sstevel@tonic-gate 			hwcap_flags |= AV_386_FXSR | AV_386_SSE;
14537c478bd9Sstevel@tonic-gate 		if (*edx & CPUID_INTC_EDX_SSE2)
14547c478bd9Sstevel@tonic-gate 			hwcap_flags |= AV_386_SSE2;
14557c478bd9Sstevel@tonic-gate 		if (*ecx & CPUID_INTC_ECX_SSE3)
14567c478bd9Sstevel@tonic-gate 			hwcap_flags |= AV_386_SSE3;
14577c478bd9Sstevel@tonic-gate 
14587c478bd9Sstevel@tonic-gate 		if (*edx & CPUID_INTC_EDX_FPU)
14597c478bd9Sstevel@tonic-gate 			hwcap_flags |= AV_386_FPU;
14607c478bd9Sstevel@tonic-gate 		if (*edx & CPUID_INTC_EDX_MMX)
14617c478bd9Sstevel@tonic-gate 			hwcap_flags |= AV_386_MMX;
14627c478bd9Sstevel@tonic-gate 
14637c478bd9Sstevel@tonic-gate 		if (*edx & CPUID_INTC_EDX_TSC)
14647c478bd9Sstevel@tonic-gate 			hwcap_flags |= AV_386_TSC;
14657c478bd9Sstevel@tonic-gate 		if (*edx & CPUID_INTC_EDX_CX8)
14667c478bd9Sstevel@tonic-gate 			hwcap_flags |= AV_386_CX8;
14677c478bd9Sstevel@tonic-gate 		if (*edx & CPUID_INTC_EDX_CMOV)
14687c478bd9Sstevel@tonic-gate 			hwcap_flags |= AV_386_CMOV;
14697c478bd9Sstevel@tonic-gate 		if (*ecx & CPUID_INTC_ECX_MON)
14707c478bd9Sstevel@tonic-gate 			hwcap_flags |= AV_386_MON;
14717c478bd9Sstevel@tonic-gate #if defined(CPUID_INTC_ECX_CX16)
14727c478bd9Sstevel@tonic-gate 		if (*ecx & CPUID_INTC_ECX_CX16)
14737c478bd9Sstevel@tonic-gate 			hwcap_flags |= AV_386_CX16;
14747c478bd9Sstevel@tonic-gate #endif
14757c478bd9Sstevel@tonic-gate 	}
14767c478bd9Sstevel@tonic-gate 
1477*8949bcd6Sandrei 	if (x86_feature & X86_HTT)
14787c478bd9Sstevel@tonic-gate 		hwcap_flags |= AV_386_PAUSE;
14797c478bd9Sstevel@tonic-gate 
14807c478bd9Sstevel@tonic-gate 	if (cpi->cpi_xmaxeax < 0x80000001)
14817c478bd9Sstevel@tonic-gate 		goto pass4_done;
14827c478bd9Sstevel@tonic-gate 
14837c478bd9Sstevel@tonic-gate 	switch (cpi->cpi_vendor) {
1484*8949bcd6Sandrei 		struct cpuid_regs cp;
1485*8949bcd6Sandrei 		uint32_t *edx;
14867c478bd9Sstevel@tonic-gate 
14877c478bd9Sstevel@tonic-gate 	case X86_VENDOR_Intel:	/* sigh */
14887c478bd9Sstevel@tonic-gate 	case X86_VENDOR_AMD:
14897c478bd9Sstevel@tonic-gate 		edx = &cpi->cpi_support[AMD_EDX_FEATURES];
14907c478bd9Sstevel@tonic-gate 
14917c478bd9Sstevel@tonic-gate 		*edx = CPI_FEATURES_XTD_EDX(cpi);
14927c478bd9Sstevel@tonic-gate 
14937c478bd9Sstevel@tonic-gate 		/*
14947c478bd9Sstevel@tonic-gate 		 * [no explicit support required beyond
14957c478bd9Sstevel@tonic-gate 		 * x87 fp context and exception handlers]
14967c478bd9Sstevel@tonic-gate 		 */
14977c478bd9Sstevel@tonic-gate 		if (!fpu_exists)
14987c478bd9Sstevel@tonic-gate 			*edx &= ~(CPUID_AMD_EDX_MMXamd |
14997c478bd9Sstevel@tonic-gate 			    CPUID_AMD_EDX_3DNow | CPUID_AMD_EDX_3DNowx);
15007c478bd9Sstevel@tonic-gate 
15017c478bd9Sstevel@tonic-gate 		if ((x86_feature & X86_ASYSC) == 0)
15027c478bd9Sstevel@tonic-gate 			*edx &= ~CPUID_AMD_EDX_SYSC;
15037c478bd9Sstevel@tonic-gate 		if ((x86_feature & X86_NX) == 0)
15047c478bd9Sstevel@tonic-gate 			*edx &= ~CPUID_AMD_EDX_NX;
15057c478bd9Sstevel@tonic-gate #if !defined(_LP64)
15067c478bd9Sstevel@tonic-gate 		*edx &= ~CPUID_AMD_EDX_LM;
15077c478bd9Sstevel@tonic-gate #endif
15087c478bd9Sstevel@tonic-gate 		/*
15097c478bd9Sstevel@tonic-gate 		 * Now map the supported feature vector to
15107c478bd9Sstevel@tonic-gate 		 * things that we think userland will care about.
15117c478bd9Sstevel@tonic-gate 		 */
15127c478bd9Sstevel@tonic-gate 		if (*edx & CPUID_AMD_EDX_SYSC)
15137c478bd9Sstevel@tonic-gate 			hwcap_flags |= AV_386_AMD_SYSC;
15147c478bd9Sstevel@tonic-gate 		if (*edx & CPUID_AMD_EDX_MMXamd)
15157c478bd9Sstevel@tonic-gate 			hwcap_flags |= AV_386_AMD_MMX;
15167c478bd9Sstevel@tonic-gate 		if (*edx & CPUID_AMD_EDX_3DNow)
15177c478bd9Sstevel@tonic-gate 			hwcap_flags |= AV_386_AMD_3DNow;
15187c478bd9Sstevel@tonic-gate 		if (*edx & CPUID_AMD_EDX_3DNowx)
15197c478bd9Sstevel@tonic-gate 			hwcap_flags |= AV_386_AMD_3DNowx;
15207c478bd9Sstevel@tonic-gate 		break;
15217c478bd9Sstevel@tonic-gate 
15227c478bd9Sstevel@tonic-gate 	case X86_VENDOR_TM:
1523*8949bcd6Sandrei 		cp.cp_eax = 0x80860001;
1524*8949bcd6Sandrei 		(void) __cpuid_insn(&cp);
1525*8949bcd6Sandrei 		cpi->cpi_support[TM_EDX_FEATURES] = cp.cp_edx;
15267c478bd9Sstevel@tonic-gate 		break;
15277c478bd9Sstevel@tonic-gate 
15287c478bd9Sstevel@tonic-gate 	default:
15297c478bd9Sstevel@tonic-gate 		break;
15307c478bd9Sstevel@tonic-gate 	}
15317c478bd9Sstevel@tonic-gate 
15327c478bd9Sstevel@tonic-gate pass4_done:
15337c478bd9Sstevel@tonic-gate 	cpi->cpi_pass = 4;
15347c478bd9Sstevel@tonic-gate 	return (hwcap_flags);
15357c478bd9Sstevel@tonic-gate }
15367c478bd9Sstevel@tonic-gate 
15377c478bd9Sstevel@tonic-gate 
15387c478bd9Sstevel@tonic-gate /*
15397c478bd9Sstevel@tonic-gate  * Simulate the cpuid instruction using the data we previously
15407c478bd9Sstevel@tonic-gate  * captured about this CPU.  We try our best to return the truth
15417c478bd9Sstevel@tonic-gate  * about the hardware, independently of kernel support.
15427c478bd9Sstevel@tonic-gate  */
15437c478bd9Sstevel@tonic-gate uint32_t
1544*8949bcd6Sandrei cpuid_insn(cpu_t *cpu, struct cpuid_regs *cp)
15457c478bd9Sstevel@tonic-gate {
15467c478bd9Sstevel@tonic-gate 	struct cpuid_info *cpi;
1547*8949bcd6Sandrei 	struct cpuid_regs *xcp;
15487c478bd9Sstevel@tonic-gate 
15497c478bd9Sstevel@tonic-gate 	if (cpu == NULL)
15507c478bd9Sstevel@tonic-gate 		cpu = CPU;
15517c478bd9Sstevel@tonic-gate 	cpi = cpu->cpu_m.mcpu_cpi;
15527c478bd9Sstevel@tonic-gate 
15537c478bd9Sstevel@tonic-gate 	ASSERT(cpuid_checkpass(cpu, 3));
15547c478bd9Sstevel@tonic-gate 
15557c478bd9Sstevel@tonic-gate 	/*
15567c478bd9Sstevel@tonic-gate 	 * CPUID data is cached in two separate places: cpi_std for standard
15577c478bd9Sstevel@tonic-gate 	 * CPUID functions, and cpi_extd for extended CPUID functions.
15587c478bd9Sstevel@tonic-gate 	 */
1559*8949bcd6Sandrei 	if (cp->cp_eax <= cpi->cpi_maxeax && cp->cp_eax < NMAX_CPI_STD)
1560*8949bcd6Sandrei 		xcp = &cpi->cpi_std[cp->cp_eax];
1561*8949bcd6Sandrei 	else if (cp->cp_eax >= 0x80000000 && cp->cp_eax <= cpi->cpi_xmaxeax &&
1562*8949bcd6Sandrei 	    cp->cp_eax < 0x80000000 + NMAX_CPI_EXTD)
1563*8949bcd6Sandrei 		xcp = &cpi->cpi_extd[cp->cp_eax - 0x80000000];
15647c478bd9Sstevel@tonic-gate 	else
15657c478bd9Sstevel@tonic-gate 		/*
15667c478bd9Sstevel@tonic-gate 		 * The caller is asking for data from an input parameter which
15677c478bd9Sstevel@tonic-gate 		 * the kernel has not cached.  In this case we go fetch from
15687c478bd9Sstevel@tonic-gate 		 * the hardware and return the data directly to the user.
15697c478bd9Sstevel@tonic-gate 		 */
1570*8949bcd6Sandrei 		return (__cpuid_insn(cp));
1571*8949bcd6Sandrei 
1572*8949bcd6Sandrei 	cp->cp_eax = xcp->cp_eax;
1573*8949bcd6Sandrei 	cp->cp_ebx = xcp->cp_ebx;
1574*8949bcd6Sandrei 	cp->cp_ecx = xcp->cp_ecx;
1575*8949bcd6Sandrei 	cp->cp_edx = xcp->cp_edx;
15767c478bd9Sstevel@tonic-gate 	return (cp->cp_eax);
15777c478bd9Sstevel@tonic-gate }
15787c478bd9Sstevel@tonic-gate 
15797c478bd9Sstevel@tonic-gate int
15807c478bd9Sstevel@tonic-gate cpuid_checkpass(cpu_t *cpu, int pass)
15817c478bd9Sstevel@tonic-gate {
15827c478bd9Sstevel@tonic-gate 	return (cpu != NULL && cpu->cpu_m.mcpu_cpi != NULL &&
15837c478bd9Sstevel@tonic-gate 	    cpu->cpu_m.mcpu_cpi->cpi_pass >= pass);
15847c478bd9Sstevel@tonic-gate }
15857c478bd9Sstevel@tonic-gate 
15867c478bd9Sstevel@tonic-gate int
15877c478bd9Sstevel@tonic-gate cpuid_getbrandstr(cpu_t *cpu, char *s, size_t n)
15887c478bd9Sstevel@tonic-gate {
15897c478bd9Sstevel@tonic-gate 	ASSERT(cpuid_checkpass(cpu, 3));
15907c478bd9Sstevel@tonic-gate 
15917c478bd9Sstevel@tonic-gate 	return (snprintf(s, n, "%s", cpu->cpu_m.mcpu_cpi->cpi_brandstr));
15927c478bd9Sstevel@tonic-gate }
15937c478bd9Sstevel@tonic-gate 
15947c478bd9Sstevel@tonic-gate int
1595*8949bcd6Sandrei cpuid_is_cmt(cpu_t *cpu)
15967c478bd9Sstevel@tonic-gate {
15977c478bd9Sstevel@tonic-gate 	if (cpu == NULL)
15987c478bd9Sstevel@tonic-gate 		cpu = CPU;
15997c478bd9Sstevel@tonic-gate 
16007c478bd9Sstevel@tonic-gate 	ASSERT(cpuid_checkpass(cpu, 1));
16017c478bd9Sstevel@tonic-gate 
16027c478bd9Sstevel@tonic-gate 	return (cpu->cpu_m.mcpu_cpi->cpi_chipid >= 0);
16037c478bd9Sstevel@tonic-gate }
16047c478bd9Sstevel@tonic-gate 
16057c478bd9Sstevel@tonic-gate /*
16067c478bd9Sstevel@tonic-gate  * AMD and Intel both implement the 64-bit variant of the syscall
16077c478bd9Sstevel@tonic-gate  * instruction (syscallq), so if there's -any- support for syscall,
16087c478bd9Sstevel@tonic-gate  * cpuid currently says "yes, we support this".
16097c478bd9Sstevel@tonic-gate  *
16107c478bd9Sstevel@tonic-gate  * However, Intel decided to -not- implement the 32-bit variant of the
16117c478bd9Sstevel@tonic-gate  * syscall instruction, so we provide a predicate to allow our caller
16127c478bd9Sstevel@tonic-gate  * to test that subtlety here.
16137c478bd9Sstevel@tonic-gate  */
16147c478bd9Sstevel@tonic-gate /*ARGSUSED*/
16157c478bd9Sstevel@tonic-gate int
16167c478bd9Sstevel@tonic-gate cpuid_syscall32_insn(cpu_t *cpu)
16177c478bd9Sstevel@tonic-gate {
16187c478bd9Sstevel@tonic-gate 	ASSERT(cpuid_checkpass((cpu == NULL ? CPU : cpu), 1));
16197c478bd9Sstevel@tonic-gate 
16207c478bd9Sstevel@tonic-gate 	if (x86_feature & X86_ASYSC)
16217c478bd9Sstevel@tonic-gate 		return (x86_vendor != X86_VENDOR_Intel);
16227c478bd9Sstevel@tonic-gate 	return (0);
16237c478bd9Sstevel@tonic-gate }
16247c478bd9Sstevel@tonic-gate 
16257c478bd9Sstevel@tonic-gate int
16267c478bd9Sstevel@tonic-gate cpuid_getidstr(cpu_t *cpu, char *s, size_t n)
16277c478bd9Sstevel@tonic-gate {
16287c478bd9Sstevel@tonic-gate 	struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi;
16297c478bd9Sstevel@tonic-gate 
16307c478bd9Sstevel@tonic-gate 	static const char fmt[] =
16317c478bd9Sstevel@tonic-gate 	    "x86 (%s family %d model %d step %d clock %d MHz)";
16327c478bd9Sstevel@tonic-gate 	static const char fmt_ht[] =
16337c478bd9Sstevel@tonic-gate 	    "x86 (chipid 0x%x %s family %d model %d step %d clock %d MHz)";
16347c478bd9Sstevel@tonic-gate 
16357c478bd9Sstevel@tonic-gate 	ASSERT(cpuid_checkpass(cpu, 1));
16367c478bd9Sstevel@tonic-gate 
1637*8949bcd6Sandrei 	if (cpuid_is_cmt(cpu))
16387c478bd9Sstevel@tonic-gate 		return (snprintf(s, n, fmt_ht, cpi->cpi_chipid,
16397c478bd9Sstevel@tonic-gate 		    cpi->cpi_vendorstr, cpi->cpi_family, cpi->cpi_model,
16407c478bd9Sstevel@tonic-gate 		    cpi->cpi_step, cpu->cpu_type_info.pi_clock));
16417c478bd9Sstevel@tonic-gate 	return (snprintf(s, n, fmt,
16427c478bd9Sstevel@tonic-gate 	    cpi->cpi_vendorstr, cpi->cpi_family, cpi->cpi_model,
16437c478bd9Sstevel@tonic-gate 	    cpi->cpi_step, cpu->cpu_type_info.pi_clock));
16447c478bd9Sstevel@tonic-gate }
16457c478bd9Sstevel@tonic-gate 
16467c478bd9Sstevel@tonic-gate const char *
16477c478bd9Sstevel@tonic-gate cpuid_getvendorstr(cpu_t *cpu)
16487c478bd9Sstevel@tonic-gate {
16497c478bd9Sstevel@tonic-gate 	ASSERT(cpuid_checkpass(cpu, 1));
16507c478bd9Sstevel@tonic-gate 	return ((const char *)cpu->cpu_m.mcpu_cpi->cpi_vendorstr);
16517c478bd9Sstevel@tonic-gate }
16527c478bd9Sstevel@tonic-gate 
16537c478bd9Sstevel@tonic-gate uint_t
16547c478bd9Sstevel@tonic-gate cpuid_getvendor(cpu_t *cpu)
16557c478bd9Sstevel@tonic-gate {
16567c478bd9Sstevel@tonic-gate 	ASSERT(cpuid_checkpass(cpu, 1));
16577c478bd9Sstevel@tonic-gate 	return (cpu->cpu_m.mcpu_cpi->cpi_vendor);
16587c478bd9Sstevel@tonic-gate }
16597c478bd9Sstevel@tonic-gate 
16607c478bd9Sstevel@tonic-gate uint_t
16617c478bd9Sstevel@tonic-gate cpuid_getfamily(cpu_t *cpu)
16627c478bd9Sstevel@tonic-gate {
16637c478bd9Sstevel@tonic-gate 	ASSERT(cpuid_checkpass(cpu, 1));
16647c478bd9Sstevel@tonic-gate 	return (cpu->cpu_m.mcpu_cpi->cpi_family);
16657c478bd9Sstevel@tonic-gate }
16667c478bd9Sstevel@tonic-gate 
16677c478bd9Sstevel@tonic-gate uint_t
16687c478bd9Sstevel@tonic-gate cpuid_getmodel(cpu_t *cpu)
16697c478bd9Sstevel@tonic-gate {
16707c478bd9Sstevel@tonic-gate 	ASSERT(cpuid_checkpass(cpu, 1));
16717c478bd9Sstevel@tonic-gate 	return (cpu->cpu_m.mcpu_cpi->cpi_model);
16727c478bd9Sstevel@tonic-gate }
16737c478bd9Sstevel@tonic-gate 
16747c478bd9Sstevel@tonic-gate uint_t
16757c478bd9Sstevel@tonic-gate cpuid_get_ncpu_per_chip(cpu_t *cpu)
16767c478bd9Sstevel@tonic-gate {
16777c478bd9Sstevel@tonic-gate 	ASSERT(cpuid_checkpass(cpu, 1));
16787c478bd9Sstevel@tonic-gate 	return (cpu->cpu_m.mcpu_cpi->cpi_ncpu_per_chip);
16797c478bd9Sstevel@tonic-gate }
16807c478bd9Sstevel@tonic-gate 
16817c478bd9Sstevel@tonic-gate uint_t
1682*8949bcd6Sandrei cpuid_get_ncore_per_chip(cpu_t *cpu)
1683*8949bcd6Sandrei {
1684*8949bcd6Sandrei 	ASSERT(cpuid_checkpass(cpu, 1));
1685*8949bcd6Sandrei 	return (cpu->cpu_m.mcpu_cpi->cpi_ncore_per_chip);
1686*8949bcd6Sandrei }
1687*8949bcd6Sandrei 
1688*8949bcd6Sandrei uint_t
16897c478bd9Sstevel@tonic-gate cpuid_getstep(cpu_t *cpu)
16907c478bd9Sstevel@tonic-gate {
16917c478bd9Sstevel@tonic-gate 	ASSERT(cpuid_checkpass(cpu, 1));
16927c478bd9Sstevel@tonic-gate 	return (cpu->cpu_m.mcpu_cpi->cpi_step);
16937c478bd9Sstevel@tonic-gate }
16947c478bd9Sstevel@tonic-gate 
16957c478bd9Sstevel@tonic-gate chipid_t
16967c478bd9Sstevel@tonic-gate chip_plat_get_chipid(cpu_t *cpu)
16977c478bd9Sstevel@tonic-gate {
16987c478bd9Sstevel@tonic-gate 	ASSERT(cpuid_checkpass(cpu, 1));
16997c478bd9Sstevel@tonic-gate 
1700*8949bcd6Sandrei 	if (cpuid_is_cmt(cpu))
17017c478bd9Sstevel@tonic-gate 		return (cpu->cpu_m.mcpu_cpi->cpi_chipid);
17027c478bd9Sstevel@tonic-gate 	return (cpu->cpu_id);
17037c478bd9Sstevel@tonic-gate }
17047c478bd9Sstevel@tonic-gate 
1705*8949bcd6Sandrei id_t
1706*8949bcd6Sandrei chip_plat_get_coreid(cpu_t *cpu)
1707*8949bcd6Sandrei {
1708*8949bcd6Sandrei 	ASSERT(cpuid_checkpass(cpu, 1));
1709*8949bcd6Sandrei 	return (cpu->cpu_m.mcpu_cpi->cpi_coreid);
1710*8949bcd6Sandrei }
1711*8949bcd6Sandrei 
17127c478bd9Sstevel@tonic-gate int
17137c478bd9Sstevel@tonic-gate chip_plat_get_clogid(cpu_t *cpu)
17147c478bd9Sstevel@tonic-gate {
17157c478bd9Sstevel@tonic-gate 	ASSERT(cpuid_checkpass(cpu, 1));
17167c478bd9Sstevel@tonic-gate 	return (cpu->cpu_m.mcpu_cpi->cpi_clogid);
17177c478bd9Sstevel@tonic-gate }
17187c478bd9Sstevel@tonic-gate 
17197c478bd9Sstevel@tonic-gate void
17207c478bd9Sstevel@tonic-gate cpuid_get_addrsize(cpu_t *cpu, uint_t *pabits, uint_t *vabits)
17217c478bd9Sstevel@tonic-gate {
17227c478bd9Sstevel@tonic-gate 	struct cpuid_info *cpi;
17237c478bd9Sstevel@tonic-gate 
17247c478bd9Sstevel@tonic-gate 	if (cpu == NULL)
17257c478bd9Sstevel@tonic-gate 		cpu = CPU;
17267c478bd9Sstevel@tonic-gate 	cpi = cpu->cpu_m.mcpu_cpi;
17277c478bd9Sstevel@tonic-gate 
17287c478bd9Sstevel@tonic-gate 	ASSERT(cpuid_checkpass(cpu, 1));
17297c478bd9Sstevel@tonic-gate 
17307c478bd9Sstevel@tonic-gate 	if (pabits)
17317c478bd9Sstevel@tonic-gate 		*pabits = cpi->cpi_pabits;
17327c478bd9Sstevel@tonic-gate 	if (vabits)
17337c478bd9Sstevel@tonic-gate 		*vabits = cpi->cpi_vabits;
17347c478bd9Sstevel@tonic-gate }
17357c478bd9Sstevel@tonic-gate 
17367c478bd9Sstevel@tonic-gate /*
17377c478bd9Sstevel@tonic-gate  * Returns the number of data TLB entries for a corresponding
17387c478bd9Sstevel@tonic-gate  * pagesize.  If it can't be computed, or isn't known, the
17397c478bd9Sstevel@tonic-gate  * routine returns zero.  If you ask about an architecturally
17407c478bd9Sstevel@tonic-gate  * impossible pagesize, the routine will panic (so that the
17417c478bd9Sstevel@tonic-gate  * hat implementor knows that things are inconsistent.)
17427c478bd9Sstevel@tonic-gate  */
17437c478bd9Sstevel@tonic-gate uint_t
17447c478bd9Sstevel@tonic-gate cpuid_get_dtlb_nent(cpu_t *cpu, size_t pagesize)
17457c478bd9Sstevel@tonic-gate {
17467c478bd9Sstevel@tonic-gate 	struct cpuid_info *cpi;
17477c478bd9Sstevel@tonic-gate 	uint_t dtlb_nent = 0;
17487c478bd9Sstevel@tonic-gate 
17497c478bd9Sstevel@tonic-gate 	if (cpu == NULL)
17507c478bd9Sstevel@tonic-gate 		cpu = CPU;
17517c478bd9Sstevel@tonic-gate 	cpi = cpu->cpu_m.mcpu_cpi;
17527c478bd9Sstevel@tonic-gate 
17537c478bd9Sstevel@tonic-gate 	ASSERT(cpuid_checkpass(cpu, 1));
17547c478bd9Sstevel@tonic-gate 
17557c478bd9Sstevel@tonic-gate 	/*
17567c478bd9Sstevel@tonic-gate 	 * Check the L2 TLB info
17577c478bd9Sstevel@tonic-gate 	 */
17587c478bd9Sstevel@tonic-gate 	if (cpi->cpi_xmaxeax >= 0x80000006) {
1759*8949bcd6Sandrei 		struct cpuid_regs *cp = &cpi->cpi_extd[6];
17607c478bd9Sstevel@tonic-gate 
17617c478bd9Sstevel@tonic-gate 		switch (pagesize) {
17627c478bd9Sstevel@tonic-gate 
17637c478bd9Sstevel@tonic-gate 		case 4 * 1024:
17647c478bd9Sstevel@tonic-gate 			/*
17657c478bd9Sstevel@tonic-gate 			 * All zero in the top 16 bits of the register
17667c478bd9Sstevel@tonic-gate 			 * indicates a unified TLB. Size is in low 16 bits.
17677c478bd9Sstevel@tonic-gate 			 */
17687c478bd9Sstevel@tonic-gate 			if ((cp->cp_ebx & 0xffff0000) == 0)
17697c478bd9Sstevel@tonic-gate 				dtlb_nent = cp->cp_ebx & 0x0000ffff;
17707c478bd9Sstevel@tonic-gate 			else
17717c478bd9Sstevel@tonic-gate 				dtlb_nent = BITX(cp->cp_ebx, 27, 16);
17727c478bd9Sstevel@tonic-gate 			break;
17737c478bd9Sstevel@tonic-gate 
17747c478bd9Sstevel@tonic-gate 		case 2 * 1024 * 1024:
17757c478bd9Sstevel@tonic-gate 			if ((cp->cp_eax & 0xffff0000) == 0)
17767c478bd9Sstevel@tonic-gate 				dtlb_nent = cp->cp_eax & 0x0000ffff;
17777c478bd9Sstevel@tonic-gate 			else
17787c478bd9Sstevel@tonic-gate 				dtlb_nent = BITX(cp->cp_eax, 27, 16);
17797c478bd9Sstevel@tonic-gate 			break;
17807c478bd9Sstevel@tonic-gate 
17817c478bd9Sstevel@tonic-gate 		default:
17827c478bd9Sstevel@tonic-gate 			panic("unknown L2 pagesize");
17837c478bd9Sstevel@tonic-gate 			/*NOTREACHED*/
17847c478bd9Sstevel@tonic-gate 		}
17857c478bd9Sstevel@tonic-gate 	}
17867c478bd9Sstevel@tonic-gate 
17877c478bd9Sstevel@tonic-gate 	if (dtlb_nent != 0)
17887c478bd9Sstevel@tonic-gate 		return (dtlb_nent);
17897c478bd9Sstevel@tonic-gate 
17907c478bd9Sstevel@tonic-gate 	/*
17917c478bd9Sstevel@tonic-gate 	 * No L2 TLB support for this size, try L1.
17927c478bd9Sstevel@tonic-gate 	 */
17937c478bd9Sstevel@tonic-gate 	if (cpi->cpi_xmaxeax >= 0x80000005) {
1794*8949bcd6Sandrei 		struct cpuid_regs *cp = &cpi->cpi_extd[5];
17957c478bd9Sstevel@tonic-gate 
17967c478bd9Sstevel@tonic-gate 		switch (pagesize) {
17977c478bd9Sstevel@tonic-gate 		case 4 * 1024:
17987c478bd9Sstevel@tonic-gate 			dtlb_nent = BITX(cp->cp_ebx, 23, 16);
17997c478bd9Sstevel@tonic-gate 			break;
18007c478bd9Sstevel@tonic-gate 		case 2 * 1024 * 1024:
18017c478bd9Sstevel@tonic-gate 			dtlb_nent = BITX(cp->cp_eax, 23, 16);
18027c478bd9Sstevel@tonic-gate 			break;
18037c478bd9Sstevel@tonic-gate 		default:
18047c478bd9Sstevel@tonic-gate 			panic("unknown L1 d-TLB pagesize");
18057c478bd9Sstevel@tonic-gate 			/*NOTREACHED*/
18067c478bd9Sstevel@tonic-gate 		}
18077c478bd9Sstevel@tonic-gate 	}
18087c478bd9Sstevel@tonic-gate 
18097c478bd9Sstevel@tonic-gate 	return (dtlb_nent);
18107c478bd9Sstevel@tonic-gate }
18117c478bd9Sstevel@tonic-gate 
18127c478bd9Sstevel@tonic-gate /*
18137c478bd9Sstevel@tonic-gate  * Return 0 if the erratum is not present or not applicable, positive
18147c478bd9Sstevel@tonic-gate  * if it is, and negative if the status of the erratum is unknown.
18157c478bd9Sstevel@tonic-gate  *
18167c478bd9Sstevel@tonic-gate  * See "Revision Guide for AMD Athlon(tm) 64 and AMD Opteron(tm)
18172201b277Skucharsk  * Processors" #25759, Rev 3.57, August 2005
18187c478bd9Sstevel@tonic-gate  */
18197c478bd9Sstevel@tonic-gate int
18207c478bd9Sstevel@tonic-gate cpuid_opteron_erratum(cpu_t *cpu, uint_t erratum)
18217c478bd9Sstevel@tonic-gate {
18227c478bd9Sstevel@tonic-gate 	struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi;
1823*8949bcd6Sandrei 	uint_t eax;
18247c478bd9Sstevel@tonic-gate 
18257c478bd9Sstevel@tonic-gate 	if (cpi->cpi_vendor != X86_VENDOR_AMD)
18267c478bd9Sstevel@tonic-gate 		return (0);
18277c478bd9Sstevel@tonic-gate 
18287c478bd9Sstevel@tonic-gate 	eax = cpi->cpi_std[1].cp_eax;
18297c478bd9Sstevel@tonic-gate 
18307c478bd9Sstevel@tonic-gate #define	SH_B0(eax)	(eax == 0xf40 || eax == 0xf50)
18317c478bd9Sstevel@tonic-gate #define	SH_B3(eax) 	(eax == 0xf51)
18327c478bd9Sstevel@tonic-gate #define	B(eax)		(SH_B0(eax) | SH_B3(eax))
18337c478bd9Sstevel@tonic-gate 
18347c478bd9Sstevel@tonic-gate #define	SH_C0(eax)	(eax == 0xf48 || eax == 0xf58)
18357c478bd9Sstevel@tonic-gate 
18367c478bd9Sstevel@tonic-gate #define	SH_CG(eax)	(eax == 0xf4a || eax == 0xf5a || eax == 0xf7a)
18377c478bd9Sstevel@tonic-gate #define	DH_CG(eax)	(eax == 0xfc0 || eax == 0xfe0 || eax == 0xff0)
18387c478bd9Sstevel@tonic-gate #define	CH_CG(eax)	(eax == 0xf82 || eax == 0xfb2)
18397c478bd9Sstevel@tonic-gate #define	CG(eax)		(SH_CG(eax) | DH_CG(eax) | CH_CG(eax))
18407c478bd9Sstevel@tonic-gate 
18417c478bd9Sstevel@tonic-gate #define	SH_D0(eax)	(eax == 0x10f40 || eax == 0x10f50 || eax == 0x10f70)
18427c478bd9Sstevel@tonic-gate #define	DH_D0(eax)	(eax == 0x10fc0 || eax == 0x10ff0)
18437c478bd9Sstevel@tonic-gate #define	CH_D0(eax)	(eax == 0x10f80 || eax == 0x10fb0)
18447c478bd9Sstevel@tonic-gate #define	D0(eax)		(SH_D0(eax) | DH_D0(eax) | CH_D0(eax))
18457c478bd9Sstevel@tonic-gate 
18467c478bd9Sstevel@tonic-gate #define	SH_E0(eax)	(eax == 0x20f50 || eax == 0x20f40 || eax == 0x20f70)
18477c478bd9Sstevel@tonic-gate #define	JH_E1(eax)	(eax == 0x20f10)	/* JH8_E0 had 0x20f30 */
18487c478bd9Sstevel@tonic-gate #define	DH_E3(eax)	(eax == 0x20fc0 || eax == 0x20ff0)
18497c478bd9Sstevel@tonic-gate #define	SH_E4(eax)	(eax == 0x20f51 || eax == 0x20f71)
18507c478bd9Sstevel@tonic-gate #define	BH_E4(eax)	(eax == 0x20fb1)
18517c478bd9Sstevel@tonic-gate #define	SH_E5(eax)	(eax == 0x20f42)
18527c478bd9Sstevel@tonic-gate #define	DH_E6(eax)	(eax == 0x20ff2 || eax == 0x20fc2)
18537c478bd9Sstevel@tonic-gate #define	JH_E6(eax)	(eax == 0x20f12 || eax == 0x20f32)
18547c478bd9Sstevel@tonic-gate #define	EX(eax)		(SH_E0(eax) | JH_E1(eax) | DH_E3(eax) | SH_E4(eax) | \
18557c478bd9Sstevel@tonic-gate 			    BH_E4(eax) | SH_E5(eax) | DH_E6(eax) | JH_E6(eax))
18567c478bd9Sstevel@tonic-gate 
18577c478bd9Sstevel@tonic-gate 	switch (erratum) {
18587c478bd9Sstevel@tonic-gate 	case 1:
18597c478bd9Sstevel@tonic-gate 		return (1);
18607c478bd9Sstevel@tonic-gate 	case 51:	/* what does the asterisk mean? */
18617c478bd9Sstevel@tonic-gate 		return (B(eax) || SH_C0(eax) || CG(eax));
18627c478bd9Sstevel@tonic-gate 	case 52:
18637c478bd9Sstevel@tonic-gate 		return (B(eax));
18647c478bd9Sstevel@tonic-gate 	case 57:
18657c478bd9Sstevel@tonic-gate 		return (1);
18667c478bd9Sstevel@tonic-gate 	case 58:
18677c478bd9Sstevel@tonic-gate 		return (B(eax));
18687c478bd9Sstevel@tonic-gate 	case 60:
18697c478bd9Sstevel@tonic-gate 		return (1);
18707c478bd9Sstevel@tonic-gate 	case 61:
18717c478bd9Sstevel@tonic-gate 	case 62:
18727c478bd9Sstevel@tonic-gate 	case 63:
18737c478bd9Sstevel@tonic-gate 	case 64:
18747c478bd9Sstevel@tonic-gate 	case 65:
18757c478bd9Sstevel@tonic-gate 	case 66:
18767c478bd9Sstevel@tonic-gate 	case 68:
18777c478bd9Sstevel@tonic-gate 	case 69:
18787c478bd9Sstevel@tonic-gate 	case 70:
18797c478bd9Sstevel@tonic-gate 	case 71:
18807c478bd9Sstevel@tonic-gate 		return (B(eax));
18817c478bd9Sstevel@tonic-gate 	case 72:
18827c478bd9Sstevel@tonic-gate 		return (SH_B0(eax));
18837c478bd9Sstevel@tonic-gate 	case 74:
18847c478bd9Sstevel@tonic-gate 		return (B(eax));
18857c478bd9Sstevel@tonic-gate 	case 75:
18867c478bd9Sstevel@tonic-gate 		return (1);
18877c478bd9Sstevel@tonic-gate 	case 76:
18887c478bd9Sstevel@tonic-gate 		return (B(eax));
18897c478bd9Sstevel@tonic-gate 	case 77:
18907c478bd9Sstevel@tonic-gate 		return (1);
18917c478bd9Sstevel@tonic-gate 	case 78:
18927c478bd9Sstevel@tonic-gate 		return (B(eax) || SH_C0(eax));
18937c478bd9Sstevel@tonic-gate 	case 79:
18947c478bd9Sstevel@tonic-gate 		return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax) || EX(eax));
18957c478bd9Sstevel@tonic-gate 	case 80:
18967c478bd9Sstevel@tonic-gate 	case 81:
18977c478bd9Sstevel@tonic-gate 	case 82:
18987c478bd9Sstevel@tonic-gate 		return (B(eax));
18997c478bd9Sstevel@tonic-gate 	case 83:
19007c478bd9Sstevel@tonic-gate 		return (B(eax) || SH_C0(eax) || CG(eax));
19017c478bd9Sstevel@tonic-gate 	case 85:
19027c478bd9Sstevel@tonic-gate 		return (1);
19037c478bd9Sstevel@tonic-gate 	case 86:
19047c478bd9Sstevel@tonic-gate 		return (SH_C0(eax) || CG(eax));
19057c478bd9Sstevel@tonic-gate 	case 88:
19067c478bd9Sstevel@tonic-gate #if !defined(__amd64)
19077c478bd9Sstevel@tonic-gate 		return (0);
19087c478bd9Sstevel@tonic-gate #else
19097c478bd9Sstevel@tonic-gate 		return (B(eax) || SH_C0(eax));
19107c478bd9Sstevel@tonic-gate #endif
19117c478bd9Sstevel@tonic-gate 	case 89:
19127c478bd9Sstevel@tonic-gate 		return (1);
19137c478bd9Sstevel@tonic-gate 	case 90:
19147c478bd9Sstevel@tonic-gate 		return (B(eax) || SH_C0(eax) || CG(eax));
19157c478bd9Sstevel@tonic-gate 	case 91:
19167c478bd9Sstevel@tonic-gate 	case 92:
19177c478bd9Sstevel@tonic-gate 		return (B(eax) || SH_C0(eax));
19187c478bd9Sstevel@tonic-gate 	case 93:
19197c478bd9Sstevel@tonic-gate 		return (SH_C0(eax));
19207c478bd9Sstevel@tonic-gate 	case 94:
19217c478bd9Sstevel@tonic-gate 		return (B(eax) || SH_C0(eax) || CG(eax));
19227c478bd9Sstevel@tonic-gate 	case 95:
19237c478bd9Sstevel@tonic-gate #if !defined(__amd64)
19247c478bd9Sstevel@tonic-gate 		return (0);
19257c478bd9Sstevel@tonic-gate #else
19267c478bd9Sstevel@tonic-gate 		return (B(eax) || SH_C0(eax));
19277c478bd9Sstevel@tonic-gate #endif
19287c478bd9Sstevel@tonic-gate 	case 96:
19297c478bd9Sstevel@tonic-gate 		return (B(eax) || SH_C0(eax) || CG(eax));
19307c478bd9Sstevel@tonic-gate 	case 97:
19317c478bd9Sstevel@tonic-gate 	case 98:
19327c478bd9Sstevel@tonic-gate 		return (SH_C0(eax) || CG(eax));
19337c478bd9Sstevel@tonic-gate 	case 99:
19347c478bd9Sstevel@tonic-gate 		return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax));
19357c478bd9Sstevel@tonic-gate 	case 100:
19367c478bd9Sstevel@tonic-gate 		return (B(eax) || SH_C0(eax));
19377c478bd9Sstevel@tonic-gate 	case 101:
19387c478bd9Sstevel@tonic-gate 	case 103:
19397c478bd9Sstevel@tonic-gate 		return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax));
19407c478bd9Sstevel@tonic-gate 	case 104:
19417c478bd9Sstevel@tonic-gate 		return (SH_C0(eax) || CG(eax) || D0(eax));
19427c478bd9Sstevel@tonic-gate 	case 105:
19437c478bd9Sstevel@tonic-gate 	case 106:
19447c478bd9Sstevel@tonic-gate 	case 107:
19457c478bd9Sstevel@tonic-gate 		return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax));
19467c478bd9Sstevel@tonic-gate 	case 108:
19477c478bd9Sstevel@tonic-gate 		return (DH_CG(eax));
19487c478bd9Sstevel@tonic-gate 	case 109:
19497c478bd9Sstevel@tonic-gate 		return (SH_C0(eax) || CG(eax) || D0(eax));
19507c478bd9Sstevel@tonic-gate 	case 110:
19517c478bd9Sstevel@tonic-gate 		return (D0(eax) || EX(eax));
19527c478bd9Sstevel@tonic-gate 	case 111:
19537c478bd9Sstevel@tonic-gate 		return (CG(eax));
19547c478bd9Sstevel@tonic-gate 	case 112:
19557c478bd9Sstevel@tonic-gate 		return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax) || EX(eax));
19567c478bd9Sstevel@tonic-gate 	case 113:
19577c478bd9Sstevel@tonic-gate 		return (eax == 0x20fc0);
19587c478bd9Sstevel@tonic-gate 	case 114:
19597c478bd9Sstevel@tonic-gate 		return (SH_E0(eax) || JH_E1(eax) || DH_E3(eax));
19607c478bd9Sstevel@tonic-gate 	case 115:
19617c478bd9Sstevel@tonic-gate 		return (SH_E0(eax) || JH_E1(eax));
19627c478bd9Sstevel@tonic-gate 	case 116:
19637c478bd9Sstevel@tonic-gate 		return (SH_E0(eax) || JH_E1(eax) || DH_E3(eax));
19647c478bd9Sstevel@tonic-gate 	case 117:
19657c478bd9Sstevel@tonic-gate 		return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax));
19667c478bd9Sstevel@tonic-gate 	case 118:
19677c478bd9Sstevel@tonic-gate 		return (SH_E0(eax) || JH_E1(eax) || SH_E4(eax) || BH_E4(eax) ||
19687c478bd9Sstevel@tonic-gate 		    JH_E6(eax));
19697c478bd9Sstevel@tonic-gate 	case 121:
19707c478bd9Sstevel@tonic-gate 		return (B(eax) || SH_C0(eax) || CG(eax) || D0(eax) || EX(eax));
19717c478bd9Sstevel@tonic-gate 	case 122:
19727c478bd9Sstevel@tonic-gate 		return (SH_C0(eax) || CG(eax) || D0(eax) || EX(eax));
19737c478bd9Sstevel@tonic-gate 	case 123:
19747c478bd9Sstevel@tonic-gate 		return (JH_E1(eax) || BH_E4(eax) || JH_E6(eax));
19752201b277Skucharsk 	case 131:
19762201b277Skucharsk 		return (1);
1977ef50d8c0Sesaxe 	case 6336786:
1978ef50d8c0Sesaxe 		/*
1979ef50d8c0Sesaxe 		 * Test for AdvPowerMgmtInfo.TscPStateInvariant
1980ef50d8c0Sesaxe 		 * if this is a K8 family processor
1981ef50d8c0Sesaxe 		 */
1982ef50d8c0Sesaxe 		if (CPI_FAMILY(cpi) == 0xf) {
1983*8949bcd6Sandrei 			struct cpuid_regs regs;
1984*8949bcd6Sandrei 			regs.cp_eax = 0x80000007;
1985*8949bcd6Sandrei 			(void) __cpuid_insn(&regs);
1986*8949bcd6Sandrei 			return (!(regs.cp_edx & 0x100));
1987ef50d8c0Sesaxe 		}
1988ef50d8c0Sesaxe 		return (0);
19897c478bd9Sstevel@tonic-gate 	default:
19907c478bd9Sstevel@tonic-gate 		return (-1);
19917c478bd9Sstevel@tonic-gate 	}
19927c478bd9Sstevel@tonic-gate }
19937c478bd9Sstevel@tonic-gate 
19947c478bd9Sstevel@tonic-gate static const char assoc_str[] = "associativity";
19957c478bd9Sstevel@tonic-gate static const char line_str[] = "line-size";
19967c478bd9Sstevel@tonic-gate static const char size_str[] = "size";
19977c478bd9Sstevel@tonic-gate 
19987c478bd9Sstevel@tonic-gate static void
19997c478bd9Sstevel@tonic-gate add_cache_prop(dev_info_t *devi, const char *label, const char *type,
20007c478bd9Sstevel@tonic-gate     uint32_t val)
20017c478bd9Sstevel@tonic-gate {
20027c478bd9Sstevel@tonic-gate 	char buf[128];
20037c478bd9Sstevel@tonic-gate 
20047c478bd9Sstevel@tonic-gate 	/*
20057c478bd9Sstevel@tonic-gate 	 * ndi_prop_update_int() is used because it is desirable for
20067c478bd9Sstevel@tonic-gate 	 * DDI_PROP_HW_DEF and DDI_PROP_DONTSLEEP to be set.
20077c478bd9Sstevel@tonic-gate 	 */
20087c478bd9Sstevel@tonic-gate 	if (snprintf(buf, sizeof (buf), "%s-%s", label, type) < sizeof (buf))
20097c478bd9Sstevel@tonic-gate 		(void) ndi_prop_update_int(DDI_DEV_T_NONE, devi, buf, val);
20107c478bd9Sstevel@tonic-gate }
20117c478bd9Sstevel@tonic-gate 
20127c478bd9Sstevel@tonic-gate /*
20137c478bd9Sstevel@tonic-gate  * Intel-style cache/tlb description
20147c478bd9Sstevel@tonic-gate  *
20157c478bd9Sstevel@tonic-gate  * Standard cpuid level 2 gives a randomly ordered
20167c478bd9Sstevel@tonic-gate  * selection of tags that index into a table that describes
20177c478bd9Sstevel@tonic-gate  * cache and tlb properties.
20187c478bd9Sstevel@tonic-gate  */
20197c478bd9Sstevel@tonic-gate 
20207c478bd9Sstevel@tonic-gate static const char l1_icache_str[] = "l1-icache";
20217c478bd9Sstevel@tonic-gate static const char l1_dcache_str[] = "l1-dcache";
20227c478bd9Sstevel@tonic-gate static const char l2_cache_str[] = "l2-cache";
20237c478bd9Sstevel@tonic-gate static const char itlb4k_str[] = "itlb-4K";
20247c478bd9Sstevel@tonic-gate static const char dtlb4k_str[] = "dtlb-4K";
20257c478bd9Sstevel@tonic-gate static const char itlb4M_str[] = "itlb-4M";
20267c478bd9Sstevel@tonic-gate static const char dtlb4M_str[] = "dtlb-4M";
20277c478bd9Sstevel@tonic-gate static const char itlb424_str[] = "itlb-4K-2M-4M";
20287c478bd9Sstevel@tonic-gate static const char dtlb44_str[] = "dtlb-4K-4M";
20297c478bd9Sstevel@tonic-gate static const char sl1_dcache_str[] = "sectored-l1-dcache";
20307c478bd9Sstevel@tonic-gate static const char sl2_cache_str[] = "sectored-l2-cache";
20317c478bd9Sstevel@tonic-gate static const char itrace_str[] = "itrace-cache";
20327c478bd9Sstevel@tonic-gate static const char sl3_cache_str[] = "sectored-l3-cache";
20337c478bd9Sstevel@tonic-gate 
20347c478bd9Sstevel@tonic-gate static const struct cachetab {
20357c478bd9Sstevel@tonic-gate 	uint8_t 	ct_code;
20367c478bd9Sstevel@tonic-gate 	uint8_t		ct_assoc;
20377c478bd9Sstevel@tonic-gate 	uint16_t 	ct_line_size;
20387c478bd9Sstevel@tonic-gate 	size_t		ct_size;
20397c478bd9Sstevel@tonic-gate 	const char	*ct_label;
20407c478bd9Sstevel@tonic-gate } intel_ctab[] = {
20417c478bd9Sstevel@tonic-gate 	/* maintain descending order! */
20427c478bd9Sstevel@tonic-gate 	{ 0xb3, 4, 0, 128, dtlb4k_str },
20437c478bd9Sstevel@tonic-gate 	{ 0xb0, 4, 0, 128, itlb4k_str },
20447c478bd9Sstevel@tonic-gate 	{ 0x87, 8, 64, 1024*1024, l2_cache_str},
20457c478bd9Sstevel@tonic-gate 	{ 0x86, 4, 64, 512*1024, l2_cache_str},
20467c478bd9Sstevel@tonic-gate 	{ 0x85, 8, 32, 2*1024*1024, l2_cache_str},
20477c478bd9Sstevel@tonic-gate 	{ 0x84, 8, 32, 1024*1024, l2_cache_str},
20487c478bd9Sstevel@tonic-gate 	{ 0x83, 8, 32, 512*1024, l2_cache_str},
20497c478bd9Sstevel@tonic-gate 	{ 0x82, 8, 32, 256*1024, l2_cache_str},
20507c478bd9Sstevel@tonic-gate 	{ 0x81, 8, 32, 128*1024, l2_cache_str},		/* suspect! */
20517c478bd9Sstevel@tonic-gate 	{ 0x7f, 2, 64, 512*1024, l2_cache_str},
20527c478bd9Sstevel@tonic-gate 	{ 0x7d, 8, 64, 2*1024*1024, sl2_cache_str},
20537c478bd9Sstevel@tonic-gate 	{ 0x7c, 8, 64, 1024*1024, sl2_cache_str},
20547c478bd9Sstevel@tonic-gate 	{ 0x7b, 8, 64, 512*1024, sl2_cache_str},
20557c478bd9Sstevel@tonic-gate 	{ 0x7a, 8, 64, 256*1024, sl2_cache_str},
20567c478bd9Sstevel@tonic-gate 	{ 0x79, 8, 64, 128*1024, sl2_cache_str},
20577c478bd9Sstevel@tonic-gate 	{ 0x78, 8, 64, 1024*1024, l2_cache_str},
20587c478bd9Sstevel@tonic-gate 	{ 0x72, 8, 0, 32*1024, itrace_str},
20597c478bd9Sstevel@tonic-gate 	{ 0x71, 8, 0, 16*1024, itrace_str},
20607c478bd9Sstevel@tonic-gate 	{ 0x70, 8, 0, 12*1024, itrace_str},
20617c478bd9Sstevel@tonic-gate 	{ 0x68, 4, 64, 32*1024, sl1_dcache_str},
20627c478bd9Sstevel@tonic-gate 	{ 0x67, 4, 64, 16*1024, sl1_dcache_str},
20637c478bd9Sstevel@tonic-gate 	{ 0x66, 4, 64, 8*1024, sl1_dcache_str},
20647c478bd9Sstevel@tonic-gate 	{ 0x60, 8, 64, 16*1024, sl1_dcache_str},
20657c478bd9Sstevel@tonic-gate 	{ 0x5d, 0, 0, 256, dtlb44_str},
20667c478bd9Sstevel@tonic-gate 	{ 0x5c, 0, 0, 128, dtlb44_str},
20677c478bd9Sstevel@tonic-gate 	{ 0x5b, 0, 0, 64, dtlb44_str},
20687c478bd9Sstevel@tonic-gate 	{ 0x52, 0, 0, 256, itlb424_str},
20697c478bd9Sstevel@tonic-gate 	{ 0x51, 0, 0, 128, itlb424_str},
20707c478bd9Sstevel@tonic-gate 	{ 0x50, 0, 0, 64, itlb424_str},
20717c478bd9Sstevel@tonic-gate 	{ 0x45, 4, 32, 2*1024*1024, l2_cache_str},
20727c478bd9Sstevel@tonic-gate 	{ 0x44, 4, 32, 1024*1024, l2_cache_str},
20737c478bd9Sstevel@tonic-gate 	{ 0x43, 4, 32, 512*1024, l2_cache_str},
20747c478bd9Sstevel@tonic-gate 	{ 0x42, 4, 32, 256*1024, l2_cache_str},
20757c478bd9Sstevel@tonic-gate 	{ 0x41, 4, 32, 128*1024, l2_cache_str},
20767c478bd9Sstevel@tonic-gate 	{ 0x3c, 4, 64, 256*1024, sl2_cache_str},
20777c478bd9Sstevel@tonic-gate 	{ 0x3b, 2, 64, 128*1024, sl2_cache_str},
20787c478bd9Sstevel@tonic-gate 	{ 0x39, 4, 64, 128*1024, sl2_cache_str},
20797c478bd9Sstevel@tonic-gate 	{ 0x30, 8, 64, 32*1024, l1_icache_str},
20807c478bd9Sstevel@tonic-gate 	{ 0x2c, 8, 64, 32*1024, l1_dcache_str},
20817c478bd9Sstevel@tonic-gate 	{ 0x29, 8, 64, 4096*1024, sl3_cache_str},
20827c478bd9Sstevel@tonic-gate 	{ 0x25, 8, 64, 2048*1024, sl3_cache_str},
20837c478bd9Sstevel@tonic-gate 	{ 0x23, 8, 64, 1024*1024, sl3_cache_str},
20847c478bd9Sstevel@tonic-gate 	{ 0x22, 4, 64, 512*1024, sl3_cache_str},
20857c478bd9Sstevel@tonic-gate 	{ 0x0c, 4, 32, 16*1024, l1_dcache_str},
20867c478bd9Sstevel@tonic-gate 	{ 0x0a, 2, 32, 8*1024, l1_dcache_str},
20877c478bd9Sstevel@tonic-gate 	{ 0x08, 4, 32, 16*1024, l1_icache_str},
20887c478bd9Sstevel@tonic-gate 	{ 0x06, 4, 32, 8*1024, l1_icache_str},
20897c478bd9Sstevel@tonic-gate 	{ 0x04, 4, 0, 8, dtlb4M_str},
20907c478bd9Sstevel@tonic-gate 	{ 0x03, 4, 0, 64, dtlb4k_str},
20917c478bd9Sstevel@tonic-gate 	{ 0x02, 4, 0, 2, itlb4M_str},
20927c478bd9Sstevel@tonic-gate 	{ 0x01, 4, 0, 32, itlb4k_str},
20937c478bd9Sstevel@tonic-gate 	{ 0 }
20947c478bd9Sstevel@tonic-gate };
20957c478bd9Sstevel@tonic-gate 
20967c478bd9Sstevel@tonic-gate static const struct cachetab cyrix_ctab[] = {
20977c478bd9Sstevel@tonic-gate 	{ 0x70, 4, 0, 32, "tlb-4K" },
20987c478bd9Sstevel@tonic-gate 	{ 0x80, 4, 16, 16*1024, "l1-cache" },
20997c478bd9Sstevel@tonic-gate 	{ 0 }
21007c478bd9Sstevel@tonic-gate };
21017c478bd9Sstevel@tonic-gate 
21027c478bd9Sstevel@tonic-gate /*
21037c478bd9Sstevel@tonic-gate  * Search a cache table for a matching entry
21047c478bd9Sstevel@tonic-gate  */
21057c478bd9Sstevel@tonic-gate static const struct cachetab *
21067c478bd9Sstevel@tonic-gate find_cacheent(const struct cachetab *ct, uint_t code)
21077c478bd9Sstevel@tonic-gate {
21087c478bd9Sstevel@tonic-gate 	if (code != 0) {
21097c478bd9Sstevel@tonic-gate 		for (; ct->ct_code != 0; ct++)
21107c478bd9Sstevel@tonic-gate 			if (ct->ct_code <= code)
21117c478bd9Sstevel@tonic-gate 				break;
21127c478bd9Sstevel@tonic-gate 		if (ct->ct_code == code)
21137c478bd9Sstevel@tonic-gate 			return (ct);
21147c478bd9Sstevel@tonic-gate 	}
21157c478bd9Sstevel@tonic-gate 	return (NULL);
21167c478bd9Sstevel@tonic-gate }
21177c478bd9Sstevel@tonic-gate 
21187c478bd9Sstevel@tonic-gate /*
21197c478bd9Sstevel@tonic-gate  * Walk the cacheinfo descriptor, applying 'func' to every valid element
21207c478bd9Sstevel@tonic-gate  * The walk is terminated if the walker returns non-zero.
21217c478bd9Sstevel@tonic-gate  */
21227c478bd9Sstevel@tonic-gate static void
21237c478bd9Sstevel@tonic-gate intel_walk_cacheinfo(struct cpuid_info *cpi,
21247c478bd9Sstevel@tonic-gate     void *arg, int (*func)(void *, const struct cachetab *))
21257c478bd9Sstevel@tonic-gate {
21267c478bd9Sstevel@tonic-gate 	const struct cachetab *ct;
21277c478bd9Sstevel@tonic-gate 	uint8_t *dp;
21287c478bd9Sstevel@tonic-gate 	int i;
21297c478bd9Sstevel@tonic-gate 
21307c478bd9Sstevel@tonic-gate 	if ((dp = cpi->cpi_cacheinfo) == NULL)
21317c478bd9Sstevel@tonic-gate 		return;
21327c478bd9Sstevel@tonic-gate 	for (i = 0; i < cpi->cpi_ncache; i++, dp++)
21337c478bd9Sstevel@tonic-gate 		if ((ct = find_cacheent(intel_ctab, *dp)) != NULL) {
21347c478bd9Sstevel@tonic-gate 			if (func(arg, ct) != 0)
21357c478bd9Sstevel@tonic-gate 				break;
21367c478bd9Sstevel@tonic-gate 		}
21377c478bd9Sstevel@tonic-gate }
21387c478bd9Sstevel@tonic-gate 
21397c478bd9Sstevel@tonic-gate /*
21407c478bd9Sstevel@tonic-gate  * (Like the Intel one, except for Cyrix CPUs)
21417c478bd9Sstevel@tonic-gate  */
21427c478bd9Sstevel@tonic-gate static void
21437c478bd9Sstevel@tonic-gate cyrix_walk_cacheinfo(struct cpuid_info *cpi,
21447c478bd9Sstevel@tonic-gate     void *arg, int (*func)(void *, const struct cachetab *))
21457c478bd9Sstevel@tonic-gate {
21467c478bd9Sstevel@tonic-gate 	const struct cachetab *ct;
21477c478bd9Sstevel@tonic-gate 	uint8_t *dp;
21487c478bd9Sstevel@tonic-gate 	int i;
21497c478bd9Sstevel@tonic-gate 
21507c478bd9Sstevel@tonic-gate 	if ((dp = cpi->cpi_cacheinfo) == NULL)
21517c478bd9Sstevel@tonic-gate 		return;
21527c478bd9Sstevel@tonic-gate 	for (i = 0; i < cpi->cpi_ncache; i++, dp++) {
21537c478bd9Sstevel@tonic-gate 		/*
21547c478bd9Sstevel@tonic-gate 		 * Search Cyrix-specific descriptor table first ..
21557c478bd9Sstevel@tonic-gate 		 */
21567c478bd9Sstevel@tonic-gate 		if ((ct = find_cacheent(cyrix_ctab, *dp)) != NULL) {
21577c478bd9Sstevel@tonic-gate 			if (func(arg, ct) != 0)
21587c478bd9Sstevel@tonic-gate 				break;
21597c478bd9Sstevel@tonic-gate 			continue;
21607c478bd9Sstevel@tonic-gate 		}
21617c478bd9Sstevel@tonic-gate 		/*
21627c478bd9Sstevel@tonic-gate 		 * .. else fall back to the Intel one
21637c478bd9Sstevel@tonic-gate 		 */
21647c478bd9Sstevel@tonic-gate 		if ((ct = find_cacheent(intel_ctab, *dp)) != NULL) {
21657c478bd9Sstevel@tonic-gate 			if (func(arg, ct) != 0)
21667c478bd9Sstevel@tonic-gate 				break;
21677c478bd9Sstevel@tonic-gate 			continue;
21687c478bd9Sstevel@tonic-gate 		}
21697c478bd9Sstevel@tonic-gate 	}
21707c478bd9Sstevel@tonic-gate }
21717c478bd9Sstevel@tonic-gate 
21727c478bd9Sstevel@tonic-gate /*
21737c478bd9Sstevel@tonic-gate  * A cacheinfo walker that adds associativity, line-size, and size properties
21747c478bd9Sstevel@tonic-gate  * to the devinfo node it is passed as an argument.
21757c478bd9Sstevel@tonic-gate  */
21767c478bd9Sstevel@tonic-gate static int
21777c478bd9Sstevel@tonic-gate add_cacheent_props(void *arg, const struct cachetab *ct)
21787c478bd9Sstevel@tonic-gate {
21797c478bd9Sstevel@tonic-gate 	dev_info_t *devi = arg;
21807c478bd9Sstevel@tonic-gate 
21817c478bd9Sstevel@tonic-gate 	add_cache_prop(devi, ct->ct_label, assoc_str, ct->ct_assoc);
21827c478bd9Sstevel@tonic-gate 	if (ct->ct_line_size != 0)
21837c478bd9Sstevel@tonic-gate 		add_cache_prop(devi, ct->ct_label, line_str,
21847c478bd9Sstevel@tonic-gate 		    ct->ct_line_size);
21857c478bd9Sstevel@tonic-gate 	add_cache_prop(devi, ct->ct_label, size_str, ct->ct_size);
21867c478bd9Sstevel@tonic-gate 	return (0);
21877c478bd9Sstevel@tonic-gate }
21887c478bd9Sstevel@tonic-gate 
21897c478bd9Sstevel@tonic-gate static const char fully_assoc[] = "fully-associative?";
21907c478bd9Sstevel@tonic-gate 
21917c478bd9Sstevel@tonic-gate /*
21927c478bd9Sstevel@tonic-gate  * AMD style cache/tlb description
21937c478bd9Sstevel@tonic-gate  *
21947c478bd9Sstevel@tonic-gate  * Extended functions 5 and 6 directly describe properties of
21957c478bd9Sstevel@tonic-gate  * tlbs and various cache levels.
21967c478bd9Sstevel@tonic-gate  */
21977c478bd9Sstevel@tonic-gate static void
21987c478bd9Sstevel@tonic-gate add_amd_assoc(dev_info_t *devi, const char *label, uint_t assoc)
21997c478bd9Sstevel@tonic-gate {
22007c478bd9Sstevel@tonic-gate 	switch (assoc) {
22017c478bd9Sstevel@tonic-gate 	case 0:	/* reserved; ignore */
22027c478bd9Sstevel@tonic-gate 		break;
22037c478bd9Sstevel@tonic-gate 	default:
22047c478bd9Sstevel@tonic-gate 		add_cache_prop(devi, label, assoc_str, assoc);
22057c478bd9Sstevel@tonic-gate 		break;
22067c478bd9Sstevel@tonic-gate 	case 0xff:
22077c478bd9Sstevel@tonic-gate 		add_cache_prop(devi, label, fully_assoc, 1);
22087c478bd9Sstevel@tonic-gate 		break;
22097c478bd9Sstevel@tonic-gate 	}
22107c478bd9Sstevel@tonic-gate }
22117c478bd9Sstevel@tonic-gate 
22127c478bd9Sstevel@tonic-gate static void
22137c478bd9Sstevel@tonic-gate add_amd_tlb(dev_info_t *devi, const char *label, uint_t assoc, uint_t size)
22147c478bd9Sstevel@tonic-gate {
22157c478bd9Sstevel@tonic-gate 	if (size == 0)
22167c478bd9Sstevel@tonic-gate 		return;
22177c478bd9Sstevel@tonic-gate 	add_cache_prop(devi, label, size_str, size);
22187c478bd9Sstevel@tonic-gate 	add_amd_assoc(devi, label, assoc);
22197c478bd9Sstevel@tonic-gate }
22207c478bd9Sstevel@tonic-gate 
22217c478bd9Sstevel@tonic-gate static void
22227c478bd9Sstevel@tonic-gate add_amd_cache(dev_info_t *devi, const char *label,
22237c478bd9Sstevel@tonic-gate     uint_t size, uint_t assoc, uint_t lines_per_tag, uint_t line_size)
22247c478bd9Sstevel@tonic-gate {
22257c478bd9Sstevel@tonic-gate 	if (size == 0 || line_size == 0)
22267c478bd9Sstevel@tonic-gate 		return;
22277c478bd9Sstevel@tonic-gate 	add_amd_assoc(devi, label, assoc);
22287c478bd9Sstevel@tonic-gate 	/*
22297c478bd9Sstevel@tonic-gate 	 * Most AMD parts have a sectored cache. Multiple cache lines are
22307c478bd9Sstevel@tonic-gate 	 * associated with each tag. A sector consists of all cache lines
22317c478bd9Sstevel@tonic-gate 	 * associated with a tag. For example, the AMD K6-III has a sector
22327c478bd9Sstevel@tonic-gate 	 * size of 2 cache lines per tag.
22337c478bd9Sstevel@tonic-gate 	 */
22347c478bd9Sstevel@tonic-gate 	if (lines_per_tag != 0)
22357c478bd9Sstevel@tonic-gate 		add_cache_prop(devi, label, "lines-per-tag", lines_per_tag);
22367c478bd9Sstevel@tonic-gate 	add_cache_prop(devi, label, line_str, line_size);
22377c478bd9Sstevel@tonic-gate 	add_cache_prop(devi, label, size_str, size * 1024);
22387c478bd9Sstevel@tonic-gate }
22397c478bd9Sstevel@tonic-gate 
22407c478bd9Sstevel@tonic-gate static void
22417c478bd9Sstevel@tonic-gate add_amd_l2_assoc(dev_info_t *devi, const char *label, uint_t assoc)
22427c478bd9Sstevel@tonic-gate {
22437c478bd9Sstevel@tonic-gate 	switch (assoc) {
22447c478bd9Sstevel@tonic-gate 	case 0:	/* off */
22457c478bd9Sstevel@tonic-gate 		break;
22467c478bd9Sstevel@tonic-gate 	case 1:
22477c478bd9Sstevel@tonic-gate 	case 2:
22487c478bd9Sstevel@tonic-gate 	case 4:
22497c478bd9Sstevel@tonic-gate 		add_cache_prop(devi, label, assoc_str, assoc);
22507c478bd9Sstevel@tonic-gate 		break;
22517c478bd9Sstevel@tonic-gate 	case 6:
22527c478bd9Sstevel@tonic-gate 		add_cache_prop(devi, label, assoc_str, 8);
22537c478bd9Sstevel@tonic-gate 		break;
22547c478bd9Sstevel@tonic-gate 	case 8:
22557c478bd9Sstevel@tonic-gate 		add_cache_prop(devi, label, assoc_str, 16);
22567c478bd9Sstevel@tonic-gate 		break;
22577c478bd9Sstevel@tonic-gate 	case 0xf:
22587c478bd9Sstevel@tonic-gate 		add_cache_prop(devi, label, fully_assoc, 1);
22597c478bd9Sstevel@tonic-gate 		break;
22607c478bd9Sstevel@tonic-gate 	default: /* reserved; ignore */
22617c478bd9Sstevel@tonic-gate 		break;
22627c478bd9Sstevel@tonic-gate 	}
22637c478bd9Sstevel@tonic-gate }
22647c478bd9Sstevel@tonic-gate 
22657c478bd9Sstevel@tonic-gate static void
22667c478bd9Sstevel@tonic-gate add_amd_l2_tlb(dev_info_t *devi, const char *label, uint_t assoc, uint_t size)
22677c478bd9Sstevel@tonic-gate {
22687c478bd9Sstevel@tonic-gate 	if (size == 0 || assoc == 0)
22697c478bd9Sstevel@tonic-gate 		return;
22707c478bd9Sstevel@tonic-gate 	add_amd_l2_assoc(devi, label, assoc);
22717c478bd9Sstevel@tonic-gate 	add_cache_prop(devi, label, size_str, size);
22727c478bd9Sstevel@tonic-gate }
22737c478bd9Sstevel@tonic-gate 
22747c478bd9Sstevel@tonic-gate static void
22757c478bd9Sstevel@tonic-gate add_amd_l2_cache(dev_info_t *devi, const char *label,
22767c478bd9Sstevel@tonic-gate     uint_t size, uint_t assoc, uint_t lines_per_tag, uint_t line_size)
22777c478bd9Sstevel@tonic-gate {
22787c478bd9Sstevel@tonic-gate 	if (size == 0 || assoc == 0 || line_size == 0)
22797c478bd9Sstevel@tonic-gate 		return;
22807c478bd9Sstevel@tonic-gate 	add_amd_l2_assoc(devi, label, assoc);
22817c478bd9Sstevel@tonic-gate 	if (lines_per_tag != 0)
22827c478bd9Sstevel@tonic-gate 		add_cache_prop(devi, label, "lines-per-tag", lines_per_tag);
22837c478bd9Sstevel@tonic-gate 	add_cache_prop(devi, label, line_str, line_size);
22847c478bd9Sstevel@tonic-gate 	add_cache_prop(devi, label, size_str, size * 1024);
22857c478bd9Sstevel@tonic-gate }
22867c478bd9Sstevel@tonic-gate 
22877c478bd9Sstevel@tonic-gate static void
22887c478bd9Sstevel@tonic-gate amd_cache_info(struct cpuid_info *cpi, dev_info_t *devi)
22897c478bd9Sstevel@tonic-gate {
2290*8949bcd6Sandrei 	struct cpuid_regs *cp;
22917c478bd9Sstevel@tonic-gate 
22927c478bd9Sstevel@tonic-gate 	if (cpi->cpi_xmaxeax < 0x80000005)
22937c478bd9Sstevel@tonic-gate 		return;
22947c478bd9Sstevel@tonic-gate 	cp = &cpi->cpi_extd[5];
22957c478bd9Sstevel@tonic-gate 
22967c478bd9Sstevel@tonic-gate 	/*
22977c478bd9Sstevel@tonic-gate 	 * 4M/2M L1 TLB configuration
22987c478bd9Sstevel@tonic-gate 	 *
22997c478bd9Sstevel@tonic-gate 	 * We report the size for 2M pages because AMD uses two
23007c478bd9Sstevel@tonic-gate 	 * TLB entries for one 4M page.
23017c478bd9Sstevel@tonic-gate 	 */
23027c478bd9Sstevel@tonic-gate 	add_amd_tlb(devi, "dtlb-2M",
23037c478bd9Sstevel@tonic-gate 	    BITX(cp->cp_eax, 31, 24), BITX(cp->cp_eax, 23, 16));
23047c478bd9Sstevel@tonic-gate 	add_amd_tlb(devi, "itlb-2M",
23057c478bd9Sstevel@tonic-gate 	    BITX(cp->cp_eax, 15, 8), BITX(cp->cp_eax, 7, 0));
23067c478bd9Sstevel@tonic-gate 
23077c478bd9Sstevel@tonic-gate 	/*
23087c478bd9Sstevel@tonic-gate 	 * 4K L1 TLB configuration
23097c478bd9Sstevel@tonic-gate 	 */
23107c478bd9Sstevel@tonic-gate 
23117c478bd9Sstevel@tonic-gate 	switch (cpi->cpi_vendor) {
23127c478bd9Sstevel@tonic-gate 		uint_t nentries;
23137c478bd9Sstevel@tonic-gate 	case X86_VENDOR_TM:
23147c478bd9Sstevel@tonic-gate 		if (cpi->cpi_family >= 5) {
23157c478bd9Sstevel@tonic-gate 			/*
23167c478bd9Sstevel@tonic-gate 			 * Crusoe processors have 256 TLB entries, but
23177c478bd9Sstevel@tonic-gate 			 * cpuid data format constrains them to only
23187c478bd9Sstevel@tonic-gate 			 * reporting 255 of them.
23197c478bd9Sstevel@tonic-gate 			 */
23207c478bd9Sstevel@tonic-gate 			if ((nentries = BITX(cp->cp_ebx, 23, 16)) == 255)
23217c478bd9Sstevel@tonic-gate 				nentries = 256;
23227c478bd9Sstevel@tonic-gate 			/*
23237c478bd9Sstevel@tonic-gate 			 * Crusoe processors also have a unified TLB
23247c478bd9Sstevel@tonic-gate 			 */
23257c478bd9Sstevel@tonic-gate 			add_amd_tlb(devi, "tlb-4K", BITX(cp->cp_ebx, 31, 24),
23267c478bd9Sstevel@tonic-gate 			    nentries);
23277c478bd9Sstevel@tonic-gate 			break;
23287c478bd9Sstevel@tonic-gate 		}
23297c478bd9Sstevel@tonic-gate 		/*FALLTHROUGH*/
23307c478bd9Sstevel@tonic-gate 	default:
23317c478bd9Sstevel@tonic-gate 		add_amd_tlb(devi, itlb4k_str,
23327c478bd9Sstevel@tonic-gate 		    BITX(cp->cp_ebx, 31, 24), BITX(cp->cp_ebx, 23, 16));
23337c478bd9Sstevel@tonic-gate 		add_amd_tlb(devi, dtlb4k_str,
23347c478bd9Sstevel@tonic-gate 		    BITX(cp->cp_ebx, 15, 8), BITX(cp->cp_ebx, 7, 0));
23357c478bd9Sstevel@tonic-gate 		break;
23367c478bd9Sstevel@tonic-gate 	}
23377c478bd9Sstevel@tonic-gate 
23387c478bd9Sstevel@tonic-gate 	/*
23397c478bd9Sstevel@tonic-gate 	 * data L1 cache configuration
23407c478bd9Sstevel@tonic-gate 	 */
23417c478bd9Sstevel@tonic-gate 
23427c478bd9Sstevel@tonic-gate 	add_amd_cache(devi, l1_dcache_str,
23437c478bd9Sstevel@tonic-gate 	    BITX(cp->cp_ecx, 31, 24), BITX(cp->cp_ecx, 23, 16),
23447c478bd9Sstevel@tonic-gate 	    BITX(cp->cp_ecx, 15, 8), BITX(cp->cp_ecx, 7, 0));
23457c478bd9Sstevel@tonic-gate 
23467c478bd9Sstevel@tonic-gate 	/*
23477c478bd9Sstevel@tonic-gate 	 * code L1 cache configuration
23487c478bd9Sstevel@tonic-gate 	 */
23497c478bd9Sstevel@tonic-gate 
23507c478bd9Sstevel@tonic-gate 	add_amd_cache(devi, l1_icache_str,
23517c478bd9Sstevel@tonic-gate 	    BITX(cp->cp_edx, 31, 24), BITX(cp->cp_edx, 23, 16),
23527c478bd9Sstevel@tonic-gate 	    BITX(cp->cp_edx, 15, 8), BITX(cp->cp_edx, 7, 0));
23537c478bd9Sstevel@tonic-gate 
23547c478bd9Sstevel@tonic-gate 	if (cpi->cpi_xmaxeax < 0x80000006)
23557c478bd9Sstevel@tonic-gate 		return;
23567c478bd9Sstevel@tonic-gate 	cp = &cpi->cpi_extd[6];
23577c478bd9Sstevel@tonic-gate 
23587c478bd9Sstevel@tonic-gate 	/* Check for a unified L2 TLB for large pages */
23597c478bd9Sstevel@tonic-gate 
23607c478bd9Sstevel@tonic-gate 	if (BITX(cp->cp_eax, 31, 16) == 0)
23617c478bd9Sstevel@tonic-gate 		add_amd_l2_tlb(devi, "l2-tlb-2M",
23627c478bd9Sstevel@tonic-gate 		    BITX(cp->cp_eax, 15, 12), BITX(cp->cp_eax, 11, 0));
23637c478bd9Sstevel@tonic-gate 	else {
23647c478bd9Sstevel@tonic-gate 		add_amd_l2_tlb(devi, "l2-dtlb-2M",
23657c478bd9Sstevel@tonic-gate 		    BITX(cp->cp_eax, 31, 28), BITX(cp->cp_eax, 27, 16));
23667c478bd9Sstevel@tonic-gate 		add_amd_l2_tlb(devi, "l2-itlb-2M",
23677c478bd9Sstevel@tonic-gate 		    BITX(cp->cp_eax, 15, 12), BITX(cp->cp_eax, 11, 0));
23687c478bd9Sstevel@tonic-gate 	}
23697c478bd9Sstevel@tonic-gate 
23707c478bd9Sstevel@tonic-gate 	/* Check for a unified L2 TLB for 4K pages */
23717c478bd9Sstevel@tonic-gate 
23727c478bd9Sstevel@tonic-gate 	if (BITX(cp->cp_ebx, 31, 16) == 0) {
23737c478bd9Sstevel@tonic-gate 		add_amd_l2_tlb(devi, "l2-tlb-4K",
23747c478bd9Sstevel@tonic-gate 		    BITX(cp->cp_eax, 15, 12), BITX(cp->cp_eax, 11, 0));
23757c478bd9Sstevel@tonic-gate 	} else {
23767c478bd9Sstevel@tonic-gate 		add_amd_l2_tlb(devi, "l2-dtlb-4K",
23777c478bd9Sstevel@tonic-gate 		    BITX(cp->cp_eax, 31, 28), BITX(cp->cp_eax, 27, 16));
23787c478bd9Sstevel@tonic-gate 		add_amd_l2_tlb(devi, "l2-itlb-4K",
23797c478bd9Sstevel@tonic-gate 		    BITX(cp->cp_eax, 15, 12), BITX(cp->cp_eax, 11, 0));
23807c478bd9Sstevel@tonic-gate 	}
23817c478bd9Sstevel@tonic-gate 
23827c478bd9Sstevel@tonic-gate 	add_amd_l2_cache(devi, l2_cache_str,
23837c478bd9Sstevel@tonic-gate 	    BITX(cp->cp_ecx, 31, 16), BITX(cp->cp_ecx, 15, 12),
23847c478bd9Sstevel@tonic-gate 	    BITX(cp->cp_ecx, 11, 8), BITX(cp->cp_ecx, 7, 0));
23857c478bd9Sstevel@tonic-gate }
23867c478bd9Sstevel@tonic-gate 
23877c478bd9Sstevel@tonic-gate /*
23887c478bd9Sstevel@tonic-gate  * There are two basic ways that the x86 world describes it cache
23897c478bd9Sstevel@tonic-gate  * and tlb architecture - Intel's way and AMD's way.
23907c478bd9Sstevel@tonic-gate  *
23917c478bd9Sstevel@tonic-gate  * Return which flavor of cache architecture we should use
23927c478bd9Sstevel@tonic-gate  */
23937c478bd9Sstevel@tonic-gate static int
23947c478bd9Sstevel@tonic-gate x86_which_cacheinfo(struct cpuid_info *cpi)
23957c478bd9Sstevel@tonic-gate {
23967c478bd9Sstevel@tonic-gate 	switch (cpi->cpi_vendor) {
23977c478bd9Sstevel@tonic-gate 	case X86_VENDOR_Intel:
23987c478bd9Sstevel@tonic-gate 		if (cpi->cpi_maxeax >= 2)
23997c478bd9Sstevel@tonic-gate 			return (X86_VENDOR_Intel);
24007c478bd9Sstevel@tonic-gate 		break;
24017c478bd9Sstevel@tonic-gate 	case X86_VENDOR_AMD:
24027c478bd9Sstevel@tonic-gate 		/*
24037c478bd9Sstevel@tonic-gate 		 * The K5 model 1 was the first part from AMD that reported
24047c478bd9Sstevel@tonic-gate 		 * cache sizes via extended cpuid functions.
24057c478bd9Sstevel@tonic-gate 		 */
24067c478bd9Sstevel@tonic-gate 		if (cpi->cpi_family > 5 ||
24077c478bd9Sstevel@tonic-gate 		    (cpi->cpi_family == 5 && cpi->cpi_model >= 1))
24087c478bd9Sstevel@tonic-gate 			return (X86_VENDOR_AMD);
24097c478bd9Sstevel@tonic-gate 		break;
24107c478bd9Sstevel@tonic-gate 	case X86_VENDOR_TM:
24117c478bd9Sstevel@tonic-gate 		if (cpi->cpi_family >= 5)
24127c478bd9Sstevel@tonic-gate 			return (X86_VENDOR_AMD);
24137c478bd9Sstevel@tonic-gate 		/*FALLTHROUGH*/
24147c478bd9Sstevel@tonic-gate 	default:
24157c478bd9Sstevel@tonic-gate 		/*
24167c478bd9Sstevel@tonic-gate 		 * If they have extended CPU data for 0x80000005
24177c478bd9Sstevel@tonic-gate 		 * then we assume they have AMD-format cache
24187c478bd9Sstevel@tonic-gate 		 * information.
24197c478bd9Sstevel@tonic-gate 		 *
24207c478bd9Sstevel@tonic-gate 		 * If not, and the vendor happens to be Cyrix,
24217c478bd9Sstevel@tonic-gate 		 * then try our-Cyrix specific handler.
24227c478bd9Sstevel@tonic-gate 		 *
24237c478bd9Sstevel@tonic-gate 		 * If we're not Cyrix, then assume we're using Intel's
24247c478bd9Sstevel@tonic-gate 		 * table-driven format instead.
24257c478bd9Sstevel@tonic-gate 		 */
24267c478bd9Sstevel@tonic-gate 		if (cpi->cpi_xmaxeax >= 0x80000005)
24277c478bd9Sstevel@tonic-gate 			return (X86_VENDOR_AMD);
24287c478bd9Sstevel@tonic-gate 		else if (cpi->cpi_vendor == X86_VENDOR_Cyrix)
24297c478bd9Sstevel@tonic-gate 			return (X86_VENDOR_Cyrix);
24307c478bd9Sstevel@tonic-gate 		else if (cpi->cpi_maxeax >= 2)
24317c478bd9Sstevel@tonic-gate 			return (X86_VENDOR_Intel);
24327c478bd9Sstevel@tonic-gate 		break;
24337c478bd9Sstevel@tonic-gate 	}
24347c478bd9Sstevel@tonic-gate 	return (-1);
24357c478bd9Sstevel@tonic-gate }
24367c478bd9Sstevel@tonic-gate 
24377c478bd9Sstevel@tonic-gate /*
24387c478bd9Sstevel@tonic-gate  * create a node for the given cpu under the prom root node.
24397c478bd9Sstevel@tonic-gate  * Also, create a cpu node in the device tree.
24407c478bd9Sstevel@tonic-gate  */
24417c478bd9Sstevel@tonic-gate static dev_info_t *cpu_nex_devi = NULL;
24427c478bd9Sstevel@tonic-gate static kmutex_t cpu_node_lock;
24437c478bd9Sstevel@tonic-gate 
24447c478bd9Sstevel@tonic-gate /*
24457c478bd9Sstevel@tonic-gate  * Called from post_startup() and mp_startup()
24467c478bd9Sstevel@tonic-gate  */
24477c478bd9Sstevel@tonic-gate void
24487c478bd9Sstevel@tonic-gate add_cpunode2devtree(processorid_t cpu_id, struct cpuid_info *cpi)
24497c478bd9Sstevel@tonic-gate {
24507c478bd9Sstevel@tonic-gate 	dev_info_t *cpu_devi;
24517c478bd9Sstevel@tonic-gate 	int create;
24527c478bd9Sstevel@tonic-gate 
24537c478bd9Sstevel@tonic-gate 	mutex_enter(&cpu_node_lock);
24547c478bd9Sstevel@tonic-gate 
24557c478bd9Sstevel@tonic-gate 	/*
24567c478bd9Sstevel@tonic-gate 	 * create a nexus node for all cpus identified as 'cpu_id' under
24577c478bd9Sstevel@tonic-gate 	 * the root node.
24587c478bd9Sstevel@tonic-gate 	 */
24597c478bd9Sstevel@tonic-gate 	if (cpu_nex_devi == NULL) {
24607c478bd9Sstevel@tonic-gate 		if (ndi_devi_alloc(ddi_root_node(), "cpus",
2461fa9e4066Sahrens 		    (pnode_t)DEVI_SID_NODEID, &cpu_nex_devi) != NDI_SUCCESS) {
24627c478bd9Sstevel@tonic-gate 			mutex_exit(&cpu_node_lock);
24637c478bd9Sstevel@tonic-gate 			return;
24647c478bd9Sstevel@tonic-gate 		}
24657c478bd9Sstevel@tonic-gate 		(void) ndi_devi_online(cpu_nex_devi, 0);
24667c478bd9Sstevel@tonic-gate 	}
24677c478bd9Sstevel@tonic-gate 
24687c478bd9Sstevel@tonic-gate 	/*
24697c478bd9Sstevel@tonic-gate 	 * create a child node for cpu identified as 'cpu_id'
24707c478bd9Sstevel@tonic-gate 	 */
24717c478bd9Sstevel@tonic-gate 	cpu_devi = ddi_add_child(cpu_nex_devi, "cpu", DEVI_SID_NODEID,
24727c478bd9Sstevel@tonic-gate 		cpu_id);
24737c478bd9Sstevel@tonic-gate 	if (cpu_devi == NULL) {
24747c478bd9Sstevel@tonic-gate 		mutex_exit(&cpu_node_lock);
24757c478bd9Sstevel@tonic-gate 		return;
24767c478bd9Sstevel@tonic-gate 	}
24777c478bd9Sstevel@tonic-gate 
24787c478bd9Sstevel@tonic-gate 	/* device_type */
24797c478bd9Sstevel@tonic-gate 
24807c478bd9Sstevel@tonic-gate 	(void) ndi_prop_update_string(DDI_DEV_T_NONE, cpu_devi,
24817c478bd9Sstevel@tonic-gate 	    "device_type", "cpu");
24827c478bd9Sstevel@tonic-gate 
24837c478bd9Sstevel@tonic-gate 	/* reg */
24847c478bd9Sstevel@tonic-gate 
24857c478bd9Sstevel@tonic-gate 	(void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi,
24867c478bd9Sstevel@tonic-gate 	    "reg", cpu_id);
24877c478bd9Sstevel@tonic-gate 
24887c478bd9Sstevel@tonic-gate 	/* cpu-mhz, and clock-frequency */
24897c478bd9Sstevel@tonic-gate 
24907c478bd9Sstevel@tonic-gate 	if (cpu_freq > 0) {
24917c478bd9Sstevel@tonic-gate 		long long mul;
24927c478bd9Sstevel@tonic-gate 
24937c478bd9Sstevel@tonic-gate 		(void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi,
24947c478bd9Sstevel@tonic-gate 		    "cpu-mhz", cpu_freq);
24957c478bd9Sstevel@tonic-gate 
24967c478bd9Sstevel@tonic-gate 		if ((mul = cpu_freq * 1000000LL) <= INT_MAX)
24977c478bd9Sstevel@tonic-gate 			(void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi,
24987c478bd9Sstevel@tonic-gate 			    "clock-frequency", (int)mul);
24997c478bd9Sstevel@tonic-gate 	}
25007c478bd9Sstevel@tonic-gate 
25017c478bd9Sstevel@tonic-gate 	(void) ndi_devi_online(cpu_devi, 0);
25027c478bd9Sstevel@tonic-gate 
25037c478bd9Sstevel@tonic-gate 	if ((x86_feature & X86_CPUID) == 0) {
25047c478bd9Sstevel@tonic-gate 		mutex_exit(&cpu_node_lock);
25057c478bd9Sstevel@tonic-gate 		return;
25067c478bd9Sstevel@tonic-gate 	}
25077c478bd9Sstevel@tonic-gate 
25087c478bd9Sstevel@tonic-gate 	/* vendor-id */
25097c478bd9Sstevel@tonic-gate 
25107c478bd9Sstevel@tonic-gate 	(void) ndi_prop_update_string(DDI_DEV_T_NONE, cpu_devi,
25117c478bd9Sstevel@tonic-gate 		"vendor-id", cpi->cpi_vendorstr);
25127c478bd9Sstevel@tonic-gate 
25137c478bd9Sstevel@tonic-gate 	if (cpi->cpi_maxeax == 0) {
25147c478bd9Sstevel@tonic-gate 		mutex_exit(&cpu_node_lock);
25157c478bd9Sstevel@tonic-gate 		return;
25167c478bd9Sstevel@tonic-gate 	}
25177c478bd9Sstevel@tonic-gate 
25187c478bd9Sstevel@tonic-gate 	/*
25197c478bd9Sstevel@tonic-gate 	 * family, model, and step
25207c478bd9Sstevel@tonic-gate 	 */
25217c478bd9Sstevel@tonic-gate 	(void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi,
25227c478bd9Sstevel@tonic-gate 		"family", CPI_FAMILY(cpi));
25237c478bd9Sstevel@tonic-gate 	(void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi,
25247c478bd9Sstevel@tonic-gate 		"cpu-model", CPI_MODEL(cpi));
25257c478bd9Sstevel@tonic-gate 	(void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi,
25267c478bd9Sstevel@tonic-gate 		"stepping-id", CPI_STEP(cpi));
25277c478bd9Sstevel@tonic-gate 
25287c478bd9Sstevel@tonic-gate 	/* type */
25297c478bd9Sstevel@tonic-gate 
25307c478bd9Sstevel@tonic-gate 	switch (cpi->cpi_vendor) {
25317c478bd9Sstevel@tonic-gate 	case X86_VENDOR_Intel:
25327c478bd9Sstevel@tonic-gate 		create = 1;
25337c478bd9Sstevel@tonic-gate 		break;
25347c478bd9Sstevel@tonic-gate 	default:
25357c478bd9Sstevel@tonic-gate 		create = 0;
25367c478bd9Sstevel@tonic-gate 		break;
25377c478bd9Sstevel@tonic-gate 	}
25387c478bd9Sstevel@tonic-gate 	if (create)
25397c478bd9Sstevel@tonic-gate 		(void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi,
25407c478bd9Sstevel@tonic-gate 			"type", CPI_TYPE(cpi));
25417c478bd9Sstevel@tonic-gate 
25427c478bd9Sstevel@tonic-gate 	/* ext-family */
25437c478bd9Sstevel@tonic-gate 
25447c478bd9Sstevel@tonic-gate 	switch (cpi->cpi_vendor) {
25457c478bd9Sstevel@tonic-gate 	case X86_VENDOR_Intel:
25467c478bd9Sstevel@tonic-gate 	case X86_VENDOR_AMD:
25477c478bd9Sstevel@tonic-gate 		create = cpi->cpi_family >= 0xf;
25487c478bd9Sstevel@tonic-gate 		break;
25497c478bd9Sstevel@tonic-gate 	default:
25507c478bd9Sstevel@tonic-gate 		create = 0;
25517c478bd9Sstevel@tonic-gate 		break;
25527c478bd9Sstevel@tonic-gate 	}
25537c478bd9Sstevel@tonic-gate 	if (create)
25547c478bd9Sstevel@tonic-gate 		(void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi,
25557c478bd9Sstevel@tonic-gate 		    "ext-family", CPI_FAMILY_XTD(cpi));
25567c478bd9Sstevel@tonic-gate 
25577c478bd9Sstevel@tonic-gate 	/* ext-model */
25587c478bd9Sstevel@tonic-gate 
25597c478bd9Sstevel@tonic-gate 	switch (cpi->cpi_vendor) {
25607c478bd9Sstevel@tonic-gate 	case X86_VENDOR_Intel:
25617c478bd9Sstevel@tonic-gate 	case X86_VENDOR_AMD:
25627c478bd9Sstevel@tonic-gate 		create = CPI_MODEL(cpi) == 0xf;
25637c478bd9Sstevel@tonic-gate 		break;
25647c478bd9Sstevel@tonic-gate 	default:
25657c478bd9Sstevel@tonic-gate 		create = 0;
25667c478bd9Sstevel@tonic-gate 		break;
25677c478bd9Sstevel@tonic-gate 	}
25687c478bd9Sstevel@tonic-gate 	if (create)
25697c478bd9Sstevel@tonic-gate 		(void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi,
25707c478bd9Sstevel@tonic-gate 			"ext-model", CPI_MODEL_XTD(cpi));
25717c478bd9Sstevel@tonic-gate 
25727c478bd9Sstevel@tonic-gate 	/* generation */
25737c478bd9Sstevel@tonic-gate 
25747c478bd9Sstevel@tonic-gate 	switch (cpi->cpi_vendor) {
25757c478bd9Sstevel@tonic-gate 	case X86_VENDOR_AMD:
25767c478bd9Sstevel@tonic-gate 		/*
25777c478bd9Sstevel@tonic-gate 		 * AMD K5 model 1 was the first part to support this
25787c478bd9Sstevel@tonic-gate 		 */
25797c478bd9Sstevel@tonic-gate 		create = cpi->cpi_xmaxeax >= 0x80000001;
25807c478bd9Sstevel@tonic-gate 		break;
25817c478bd9Sstevel@tonic-gate 	default:
25827c478bd9Sstevel@tonic-gate 		create = 0;
25837c478bd9Sstevel@tonic-gate 		break;
25847c478bd9Sstevel@tonic-gate 	}
25857c478bd9Sstevel@tonic-gate 	if (create)
25867c478bd9Sstevel@tonic-gate 		(void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi,
25877c478bd9Sstevel@tonic-gate 		    "generation", BITX((cpi)->cpi_extd[1].cp_eax, 11, 8));
25887c478bd9Sstevel@tonic-gate 
25897c478bd9Sstevel@tonic-gate 	/* brand-id */
25907c478bd9Sstevel@tonic-gate 
25917c478bd9Sstevel@tonic-gate 	switch (cpi->cpi_vendor) {
25927c478bd9Sstevel@tonic-gate 	case X86_VENDOR_Intel:
25937c478bd9Sstevel@tonic-gate 		/*
25947c478bd9Sstevel@tonic-gate 		 * brand id first appeared on Pentium III Xeon model 8,
25957c478bd9Sstevel@tonic-gate 		 * and Celeron model 8 processors and Opteron
25967c478bd9Sstevel@tonic-gate 		 */
25977c478bd9Sstevel@tonic-gate 		create = cpi->cpi_family > 6 ||
25987c478bd9Sstevel@tonic-gate 		    (cpi->cpi_family == 6 && cpi->cpi_model >= 8);
25997c478bd9Sstevel@tonic-gate 		break;
26007c478bd9Sstevel@tonic-gate 	case X86_VENDOR_AMD:
26017c478bd9Sstevel@tonic-gate 		create = cpi->cpi_family >= 0xf;
26027c478bd9Sstevel@tonic-gate 		break;
26037c478bd9Sstevel@tonic-gate 	default:
26047c478bd9Sstevel@tonic-gate 		create = 0;
26057c478bd9Sstevel@tonic-gate 		break;
26067c478bd9Sstevel@tonic-gate 	}
26077c478bd9Sstevel@tonic-gate 	if (create && cpi->cpi_brandid != 0) {
26087c478bd9Sstevel@tonic-gate 		(void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi,
26097c478bd9Sstevel@tonic-gate 		    "brand-id", cpi->cpi_brandid);
26107c478bd9Sstevel@tonic-gate 	}
26117c478bd9Sstevel@tonic-gate 
26127c478bd9Sstevel@tonic-gate 	/* chunks, and apic-id */
26137c478bd9Sstevel@tonic-gate 
26147c478bd9Sstevel@tonic-gate 	switch (cpi->cpi_vendor) {
26157c478bd9Sstevel@tonic-gate 	case X86_VENDOR_Intel:
26167c478bd9Sstevel@tonic-gate 	case X86_VENDOR_AMD:
26177c478bd9Sstevel@tonic-gate 		/*
26187c478bd9Sstevel@tonic-gate 		 * first available on Pentium IV and Opteron (K8)
26197c478bd9Sstevel@tonic-gate 		 */
26207c478bd9Sstevel@tonic-gate 		create = cpi->cpi_family >= 0xf;
26217c478bd9Sstevel@tonic-gate 		break;
26227c478bd9Sstevel@tonic-gate 	default:
26237c478bd9Sstevel@tonic-gate 		create = 0;
26247c478bd9Sstevel@tonic-gate 		break;
26257c478bd9Sstevel@tonic-gate 	}
26267c478bd9Sstevel@tonic-gate 	if (create) {
26277c478bd9Sstevel@tonic-gate 		(void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi,
26287c478bd9Sstevel@tonic-gate 			"chunks", CPI_CHUNKS(cpi));
26297c478bd9Sstevel@tonic-gate 		(void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi,
26307c478bd9Sstevel@tonic-gate 			"apic-id", CPI_APIC_ID(cpi));
26317c478bd9Sstevel@tonic-gate 		if (cpi->cpi_chipid >= 0)
26327c478bd9Sstevel@tonic-gate 			(void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi,
26337c478bd9Sstevel@tonic-gate 			    "chip#", cpi->cpi_chipid);
26347c478bd9Sstevel@tonic-gate 	}
26357c478bd9Sstevel@tonic-gate 
26367c478bd9Sstevel@tonic-gate 	/* cpuid-features */
26377c478bd9Sstevel@tonic-gate 
26387c478bd9Sstevel@tonic-gate 	(void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi,
26397c478bd9Sstevel@tonic-gate 	    "cpuid-features", CPI_FEATURES_EDX(cpi));
26407c478bd9Sstevel@tonic-gate 
26417c478bd9Sstevel@tonic-gate 
26427c478bd9Sstevel@tonic-gate 	/* cpuid-features-ecx */
26437c478bd9Sstevel@tonic-gate 
26447c478bd9Sstevel@tonic-gate 	switch (cpi->cpi_vendor) {
26457c478bd9Sstevel@tonic-gate 	case X86_VENDOR_Intel:
26467c478bd9Sstevel@tonic-gate 		create = cpi->cpi_family >= 0xf;
26477c478bd9Sstevel@tonic-gate 		break;
26487c478bd9Sstevel@tonic-gate 	default:
26497c478bd9Sstevel@tonic-gate 		create = 0;
26507c478bd9Sstevel@tonic-gate 		break;
26517c478bd9Sstevel@tonic-gate 	}
26527c478bd9Sstevel@tonic-gate 	if (create)
26537c478bd9Sstevel@tonic-gate 		(void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi,
26547c478bd9Sstevel@tonic-gate 		    "cpuid-features-ecx", CPI_FEATURES_ECX(cpi));
26557c478bd9Sstevel@tonic-gate 
26567c478bd9Sstevel@tonic-gate 	/* ext-cpuid-features */
26577c478bd9Sstevel@tonic-gate 
26587c478bd9Sstevel@tonic-gate 	switch (cpi->cpi_vendor) {
26597c478bd9Sstevel@tonic-gate 	case X86_VENDOR_AMD:
26607c478bd9Sstevel@tonic-gate 	case X86_VENDOR_Cyrix:
26617c478bd9Sstevel@tonic-gate 	case X86_VENDOR_TM:
26627c478bd9Sstevel@tonic-gate 	case X86_VENDOR_Centaur:
26637c478bd9Sstevel@tonic-gate 		/*
26647c478bd9Sstevel@tonic-gate 		 * The extended cpuid features are not relevant on
26657c478bd9Sstevel@tonic-gate 		 * Intel but are available from the AMD K5 model 1
26667c478bd9Sstevel@tonic-gate 		 * and most Cyrix GXm and later.
26677c478bd9Sstevel@tonic-gate 		 */
26687c478bd9Sstevel@tonic-gate 		create = cpi->cpi_xmaxeax >= 0x80000001;
26697c478bd9Sstevel@tonic-gate 		break;
26707c478bd9Sstevel@tonic-gate 	default:
26717c478bd9Sstevel@tonic-gate 		create = 0;
26727c478bd9Sstevel@tonic-gate 		break;
26737c478bd9Sstevel@tonic-gate 	}
26747c478bd9Sstevel@tonic-gate 	if (create)
26757c478bd9Sstevel@tonic-gate 		(void) ndi_prop_update_int(DDI_DEV_T_NONE, cpu_devi,
26767c478bd9Sstevel@tonic-gate 			"ext-cpuid-features", CPI_FEATURES_XTD_EDX(cpi));
26777c478bd9Sstevel@tonic-gate 
26787c478bd9Sstevel@tonic-gate 	/*
26797c478bd9Sstevel@tonic-gate 	 * Brand String first appeared in Intel Pentium IV, AMD K5
26807c478bd9Sstevel@tonic-gate 	 * model 1, and Cyrix GXm.  On earlier models we try and
26817c478bd9Sstevel@tonic-gate 	 * simulate something similar .. so this string should always
26827c478bd9Sstevel@tonic-gate 	 * same -something- about the processor, however lame.
26837c478bd9Sstevel@tonic-gate 	 */
26847c478bd9Sstevel@tonic-gate 	(void) ndi_prop_update_string(DDI_DEV_T_NONE, cpu_devi,
26857c478bd9Sstevel@tonic-gate 	    "brand-string", cpi->cpi_brandstr);
26867c478bd9Sstevel@tonic-gate 
26877c478bd9Sstevel@tonic-gate 	/*
26887c478bd9Sstevel@tonic-gate 	 * Finally, cache and tlb information
26897c478bd9Sstevel@tonic-gate 	 */
26907c478bd9Sstevel@tonic-gate 	switch (x86_which_cacheinfo(cpi)) {
26917c478bd9Sstevel@tonic-gate 	case X86_VENDOR_Intel:
26927c478bd9Sstevel@tonic-gate 		intel_walk_cacheinfo(cpi, cpu_devi, add_cacheent_props);
26937c478bd9Sstevel@tonic-gate 		break;
26947c478bd9Sstevel@tonic-gate 	case X86_VENDOR_Cyrix:
26957c478bd9Sstevel@tonic-gate 		cyrix_walk_cacheinfo(cpi, cpu_devi, add_cacheent_props);
26967c478bd9Sstevel@tonic-gate 		break;
26977c478bd9Sstevel@tonic-gate 	case X86_VENDOR_AMD:
26987c478bd9Sstevel@tonic-gate 		amd_cache_info(cpi, cpu_devi);
26997c478bd9Sstevel@tonic-gate 		break;
27007c478bd9Sstevel@tonic-gate 	default:
27017c478bd9Sstevel@tonic-gate 		break;
27027c478bd9Sstevel@tonic-gate 	}
27037c478bd9Sstevel@tonic-gate 
27047c478bd9Sstevel@tonic-gate 	mutex_exit(&cpu_node_lock);
27057c478bd9Sstevel@tonic-gate }
27067c478bd9Sstevel@tonic-gate 
27077c478bd9Sstevel@tonic-gate struct l2info {
27087c478bd9Sstevel@tonic-gate 	int *l2i_csz;
27097c478bd9Sstevel@tonic-gate 	int *l2i_lsz;
27107c478bd9Sstevel@tonic-gate 	int *l2i_assoc;
27117c478bd9Sstevel@tonic-gate 	int l2i_ret;
27127c478bd9Sstevel@tonic-gate };
27137c478bd9Sstevel@tonic-gate 
27147c478bd9Sstevel@tonic-gate /*
27157c478bd9Sstevel@tonic-gate  * A cacheinfo walker that fetches the size, line-size and associativity
27167c478bd9Sstevel@tonic-gate  * of the L2 cache
27177c478bd9Sstevel@tonic-gate  */
27187c478bd9Sstevel@tonic-gate static int
27197c478bd9Sstevel@tonic-gate intel_l2cinfo(void *arg, const struct cachetab *ct)
27207c478bd9Sstevel@tonic-gate {
27217c478bd9Sstevel@tonic-gate 	struct l2info *l2i = arg;
27227c478bd9Sstevel@tonic-gate 	int *ip;
27237c478bd9Sstevel@tonic-gate 
27247c478bd9Sstevel@tonic-gate 	if (ct->ct_label != l2_cache_str &&
27257c478bd9Sstevel@tonic-gate 	    ct->ct_label != sl2_cache_str)
27267c478bd9Sstevel@tonic-gate 		return (0);	/* not an L2 -- keep walking */
27277c478bd9Sstevel@tonic-gate 
27287c478bd9Sstevel@tonic-gate 	if ((ip = l2i->l2i_csz) != NULL)
27297c478bd9Sstevel@tonic-gate 		*ip = ct->ct_size;
27307c478bd9Sstevel@tonic-gate 	if ((ip = l2i->l2i_lsz) != NULL)
27317c478bd9Sstevel@tonic-gate 		*ip = ct->ct_line_size;
27327c478bd9Sstevel@tonic-gate 	if ((ip = l2i->l2i_assoc) != NULL)
27337c478bd9Sstevel@tonic-gate 		*ip = ct->ct_assoc;
27347c478bd9Sstevel@tonic-gate 	l2i->l2i_ret = ct->ct_size;
27357c478bd9Sstevel@tonic-gate 	return (1);		/* was an L2 -- terminate walk */
27367c478bd9Sstevel@tonic-gate }
27377c478bd9Sstevel@tonic-gate 
27387c478bd9Sstevel@tonic-gate static void
27397c478bd9Sstevel@tonic-gate amd_l2cacheinfo(struct cpuid_info *cpi, struct l2info *l2i)
27407c478bd9Sstevel@tonic-gate {
2741*8949bcd6Sandrei 	struct cpuid_regs *cp;
27427c478bd9Sstevel@tonic-gate 	uint_t size, assoc;
27437c478bd9Sstevel@tonic-gate 	int *ip;
27447c478bd9Sstevel@tonic-gate 
27457c478bd9Sstevel@tonic-gate 	if (cpi->cpi_xmaxeax < 0x80000006)
27467c478bd9Sstevel@tonic-gate 		return;
27477c478bd9Sstevel@tonic-gate 	cp = &cpi->cpi_extd[6];
27487c478bd9Sstevel@tonic-gate 
27497c478bd9Sstevel@tonic-gate 	if ((assoc = BITX(cp->cp_ecx, 15, 12)) != 0 &&
27507c478bd9Sstevel@tonic-gate 	    (size = BITX(cp->cp_ecx, 31, 16)) != 0) {
27517c478bd9Sstevel@tonic-gate 		uint_t cachesz = size * 1024;
27527c478bd9Sstevel@tonic-gate 
27537c478bd9Sstevel@tonic-gate 
27547c478bd9Sstevel@tonic-gate 		if ((ip = l2i->l2i_csz) != NULL)
27557c478bd9Sstevel@tonic-gate 			*ip = cachesz;
27567c478bd9Sstevel@tonic-gate 		if ((ip = l2i->l2i_lsz) != NULL)
27577c478bd9Sstevel@tonic-gate 			*ip = BITX(cp->cp_ecx, 7, 0);
27587c478bd9Sstevel@tonic-gate 		if ((ip = l2i->l2i_assoc) != NULL)
27597c478bd9Sstevel@tonic-gate 			*ip = assoc;
27607c478bd9Sstevel@tonic-gate 		l2i->l2i_ret = cachesz;
27617c478bd9Sstevel@tonic-gate 	}
27627c478bd9Sstevel@tonic-gate }
27637c478bd9Sstevel@tonic-gate 
27647c478bd9Sstevel@tonic-gate int
27657c478bd9Sstevel@tonic-gate getl2cacheinfo(cpu_t *cpu, int *csz, int *lsz, int *assoc)
27667c478bd9Sstevel@tonic-gate {
27677c478bd9Sstevel@tonic-gate 	struct cpuid_info *cpi = cpu->cpu_m.mcpu_cpi;
27687c478bd9Sstevel@tonic-gate 	struct l2info __l2info, *l2i = &__l2info;
27697c478bd9Sstevel@tonic-gate 
27707c478bd9Sstevel@tonic-gate 	l2i->l2i_csz = csz;
27717c478bd9Sstevel@tonic-gate 	l2i->l2i_lsz = lsz;
27727c478bd9Sstevel@tonic-gate 	l2i->l2i_assoc = assoc;
27737c478bd9Sstevel@tonic-gate 	l2i->l2i_ret = -1;
27747c478bd9Sstevel@tonic-gate 
27757c478bd9Sstevel@tonic-gate 	switch (x86_which_cacheinfo(cpi)) {
27767c478bd9Sstevel@tonic-gate 	case X86_VENDOR_Intel:
27777c478bd9Sstevel@tonic-gate 		intel_walk_cacheinfo(cpi, l2i, intel_l2cinfo);
27787c478bd9Sstevel@tonic-gate 		break;
27797c478bd9Sstevel@tonic-gate 	case X86_VENDOR_Cyrix:
27807c478bd9Sstevel@tonic-gate 		cyrix_walk_cacheinfo(cpi, l2i, intel_l2cinfo);
27817c478bd9Sstevel@tonic-gate 		break;
27827c478bd9Sstevel@tonic-gate 	case X86_VENDOR_AMD:
27837c478bd9Sstevel@tonic-gate 		amd_l2cacheinfo(cpi, l2i);
27847c478bd9Sstevel@tonic-gate 		break;
27857c478bd9Sstevel@tonic-gate 	default:
27867c478bd9Sstevel@tonic-gate 		break;
27877c478bd9Sstevel@tonic-gate 	}
27887c478bd9Sstevel@tonic-gate 	return (l2i->l2i_ret);
27897c478bd9Sstevel@tonic-gate }
2790