Home | History | Annotate | Line # | Download | only in arch
i386.c revision 1.84
      1 /*	$NetBSD: i386.c,v 1.84 2018/03/30 09:24:40 msaitoh Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1999, 2000, 2001, 2006, 2007, 2008 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Frank van der Linden,  and by Jason R. Thorpe.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  * POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 /*-
     33  * Copyright (c)2008 YAMAMOTO Takashi,
     34  * All rights reserved.
     35  *
     36  * Redistribution and use in source and binary forms, with or without
     37  * modification, are permitted provided that the following conditions
     38  * are met:
     39  * 1. Redistributions of source code must retain the above copyright
     40  *    notice, this list of conditions and the following disclaimer.
     41  * 2. Redistributions in binary form must reproduce the above copyright
     42  *    notice, this list of conditions and the following disclaimer in the
     43  *    documentation and/or other materials provided with the distribution.
     44  *
     45  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     46  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     47  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     48  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     49  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     50  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     51  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     52  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     53  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     54  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     55  * SUCH DAMAGE.
     56  */
     57 
     58 #include <sys/cdefs.h>
     59 #ifndef lint
     60 __RCSID("$NetBSD: i386.c,v 1.84 2018/03/30 09:24:40 msaitoh Exp $");
     61 #endif /* not lint */
     62 
     63 #include <sys/types.h>
     64 #include <sys/param.h>
     65 #include <sys/bitops.h>
     66 #include <sys/sysctl.h>
     67 #include <sys/ioctl.h>
     68 #include <sys/cpuio.h>
     69 
     70 #include <errno.h>
     71 #include <string.h>
     72 #include <stdio.h>
     73 #include <stdlib.h>
     74 #include <err.h>
     75 #include <assert.h>
     76 #include <math.h>
     77 #include <util.h>
     78 
     79 #include <machine/specialreg.h>
     80 #include <machine/cpu.h>
     81 
     82 #include <x86/cpuvar.h>
     83 #include <x86/cputypes.h>
     84 #include <x86/cacheinfo.h>
     85 #include <x86/cpu_ucode.h>
     86 
     87 #include "../cpuctl.h"
     88 #include "cpuctl_i386.h"
     89 
     90 /* Size of buffer for printing humanized numbers */
     91 #define HUMAN_BUFSIZE sizeof("999KB")
     92 
     93 struct cpu_info {
     94 	const char	*ci_dev;
     95 	int32_t		ci_cpu_type;     /* for cpu's without cpuid */
     96 	int32_t		ci_cpuid_level;	 /* highest cpuid supported */
     97 	uint32_t	ci_cpuid_extlevel; /* highest cpuid extended func lv */
     98 	uint32_t	ci_signature;	 /* X86 cpuid type */
     99 	uint32_t	ci_family;	 /* from ci_signature */
    100 	uint32_t	ci_model;	 /* from ci_signature */
    101 	uint32_t	ci_feat_val[9];	 /* X86 CPUID feature bits
    102 					  *	[0] basic features %edx
    103 					  *	[1] basic features %ecx
    104 					  *	[2] extended features %edx
    105 					  *	[3] extended features %ecx
    106 					  *	[4] VIA padlock features
    107 					  *	[5] structure ext. feat. %ebx
    108 					  *	[6] structure ext. feat. %ecx
    109 					  *	[7] XCR0 bits (d:0 %eax)
    110 					  *	[8] xsave flags (d:1 %eax)
    111 					  */
    112 	uint32_t	ci_cpu_class;	 /* CPU class */
    113 	uint32_t	ci_brand_id;	 /* Intel brand id */
    114 	uint32_t	ci_vendor[4];	 /* vendor string */
    115 	uint32_t	ci_cpu_serial[3]; /* PIII serial number */
    116 	uint64_t	ci_tsc_freq;	 /* cpu cycles/second */
    117 	uint8_t		ci_packageid;
    118 	uint8_t		ci_coreid;
    119 	uint8_t		ci_smtid;
    120 	uint32_t	ci_initapicid;
    121 
    122 	uint32_t	ci_cur_xsave;
    123 	uint32_t	ci_max_xsave;
    124 
    125 	struct x86_cache_info ci_cinfo[CAI_COUNT];
    126 	void		(*ci_info)(struct cpu_info *);
    127 };
    128 
    129 struct cpu_nocpuid_nameclass {
    130 	int cpu_vendor;
    131 	const char *cpu_vendorname;
    132 	const char *cpu_name;
    133 	int cpu_class;
    134 	void (*cpu_setup)(struct cpu_info *);
    135 	void (*cpu_cacheinfo)(struct cpu_info *);
    136 	void (*cpu_info)(struct cpu_info *);
    137 };
    138 
    139 struct cpu_cpuid_nameclass {
    140 	const char *cpu_id;
    141 	int cpu_vendor;
    142 	const char *cpu_vendorname;
    143 	struct cpu_cpuid_family {
    144 		int cpu_class;
    145 		const char *cpu_models[256];
    146 		const char *cpu_model_default;
    147 		void (*cpu_setup)(struct cpu_info *);
    148 		void (*cpu_probe)(struct cpu_info *);
    149 		void (*cpu_info)(struct cpu_info *);
    150 	} cpu_family[CPU_MAXFAMILY - CPU_MINFAMILY + 1];
    151 };
    152 
    153 static const struct x86_cache_info intel_cpuid_cache_info[] = INTEL_CACHE_INFO;
    154 
    155 /*
    156  * Map Brand ID from cpuid instruction to brand name.
    157  * Source: Table 3-24, Mapping of Brand Indices; and Intel 64 and IA-32
    158  * Processor Brand Strings, Chapter 3 in "Intel (R) 64 and IA-32
    159  * Architectures Software Developer's Manual, Volume 2A".
    160  */
    161 static const char * const i386_intel_brand[] = {
    162 	"",		    /* Unsupported */
    163 	"Celeron",	    /* Intel (R) Celeron (TM) processor */
    164 	"Pentium III",      /* Intel (R) Pentium (R) III processor */
    165 	"Pentium III Xeon", /* Intel (R) Pentium (R) III Xeon (TM) processor */
    166 	"Pentium III",      /* Intel (R) Pentium (R) III processor */
    167 	"",		    /* 0x05: Reserved */
    168 	"Mobile Pentium III",/* Mobile Intel (R) Pentium (R) III processor-M */
    169 	"Mobile Celeron",   /* Mobile Intel (R) Celeron (R) processor */
    170 	"Pentium 4",	    /* Intel (R) Pentium (R) 4 processor */
    171 	"Pentium 4",	    /* Intel (R) Pentium (R) 4 processor */
    172 	"Celeron",	    /* Intel (R) Celeron (TM) processor */
    173 	"Xeon",		    /* Intel (R) Xeon (TM) processor */
    174 	"Xeon MP",	    /* Intel (R) Xeon (TM) processor MP */
    175 	"",		    /* 0x0d: Reserved */
    176 	"Mobile Pentium 4", /* Mobile Intel (R) Pentium (R) 4 processor-M */
    177 	"Mobile Celeron",   /* Mobile Intel (R) Celeron (R) processor */
    178 	"",		    /* 0x10: Reserved */
    179 	"Mobile Genuine",   /* Moblie Genuine Intel (R) processor */
    180 	"Celeron M",        /* Intel (R) Celeron (R) M processor */
    181 	"Mobile Celeron",   /* Mobile Intel (R) Celeron (R) processor */
    182 	"Celeron",          /* Intel (R) Celeron (R) processor */
    183 	"Mobile Genuine",   /* Moblie Genuine Intel (R) processor */
    184 	"Pentium M",        /* Intel (R) Pentium (R) M processor */
    185 	"Mobile Celeron",   /* Mobile Intel (R) Celeron (R) processor */
    186 };
    187 
    188 /*
    189  * AMD processors don't have Brand IDs, so we need these names for probe.
    190  */
    191 static const char * const amd_brand[] = {
    192 	"",
    193 	"Duron",	/* AMD Duron(tm) */
    194 	"MP",		/* AMD Athlon(tm) MP */
    195 	"XP",		/* AMD Athlon(tm) XP */
    196 	"4"		/* AMD Athlon(tm) 4 */
    197 };
    198 
    199 static int cpu_vendor;
    200 static char cpu_brand_string[49];
    201 static char amd_brand_name[48];
    202 static int use_pae, largepagesize;
    203 
    204 /* Setup functions */
    205 static void	disable_tsc(struct cpu_info *);
    206 static void	amd_family5_setup(struct cpu_info *);
    207 static void	cyrix6x86_cpu_setup(struct cpu_info *);
    208 static void	winchip_cpu_setup(struct cpu_info *);
    209 /* Brand/Model name functions */
    210 static const char *intel_family6_name(struct cpu_info *);
    211 static const char *amd_amd64_name(struct cpu_info *);
    212 /* Probe functions */
    213 static void	amd_family6_probe(struct cpu_info *);
    214 static void	powernow_probe(struct cpu_info *);
    215 static void	intel_family_new_probe(struct cpu_info *);
    216 static void	via_cpu_probe(struct cpu_info *);
    217 /* (Cache) Info functions */
    218 static void 	intel_cpu_cacheinfo(struct cpu_info *);
    219 static void 	amd_cpu_cacheinfo(struct cpu_info *);
    220 static void	via_cpu_cacheinfo(struct cpu_info *);
    221 static void	tmx86_get_longrun_status(u_int *, u_int *, u_int *);
    222 static void	transmeta_cpu_info(struct cpu_info *);
    223 /* Common functions */
    224 static void	cpu_probe_base_features(struct cpu_info *, const char *);
    225 static void	cpu_probe_hv_features(struct cpu_info *, const char *);
    226 static void	cpu_probe_features(struct cpu_info *);
    227 static void	print_bits(const char *, const char *, const char *, uint32_t);
    228 static void	identifycpu_cpuids(struct cpu_info *);
    229 static const struct x86_cache_info *cache_info_lookup(
    230     const struct x86_cache_info *, uint8_t);
    231 static const char *print_cache_config(struct cpu_info *, int, const char *,
    232     const char *);
    233 static const char *print_tlb_config(struct cpu_info *, int, const char *,
    234     const char *);
    235 static void	x86_print_cache_and_tlb_info(struct cpu_info *);
    236 
    237 /*
    238  * Note: these are just the ones that may not have a cpuid instruction.
    239  * We deal with the rest in a different way.
    240  */
    241 const struct cpu_nocpuid_nameclass i386_nocpuid_cpus[] = {
    242 	{ CPUVENDOR_INTEL, "Intel", "386SX",	CPUCLASS_386,
    243 	  NULL, NULL, NULL },			/* CPU_386SX */
    244 	{ CPUVENDOR_INTEL, "Intel", "386DX",	CPUCLASS_386,
    245 	  NULL, NULL, NULL },			/* CPU_386   */
    246 	{ CPUVENDOR_INTEL, "Intel", "486SX",	CPUCLASS_486,
    247 	  NULL, NULL, NULL },			/* CPU_486SX */
    248 	{ CPUVENDOR_INTEL, "Intel", "486DX",	CPUCLASS_486,
    249 	  NULL, NULL, NULL },			/* CPU_486   */
    250 	{ CPUVENDOR_CYRIX, "Cyrix", "486DLC",	CPUCLASS_486,
    251 	  NULL, NULL, NULL },			/* CPU_486DLC */
    252 	{ CPUVENDOR_CYRIX, "Cyrix", "6x86",	CPUCLASS_486,
    253 	  NULL, NULL, NULL },		/* CPU_6x86 */
    254 	{ CPUVENDOR_NEXGEN,"NexGen","586",      CPUCLASS_386,
    255 	  NULL, NULL, NULL },			/* CPU_NX586 */
    256 };
    257 
    258 const char *classnames[] = {
    259 	"386",
    260 	"486",
    261 	"586",
    262 	"686"
    263 };
    264 
    265 const char *modifiers[] = {
    266 	"",
    267 	"OverDrive",
    268 	"Dual",
    269 	""
    270 };
    271 
    272 const struct cpu_cpuid_nameclass i386_cpuid_cpus[] = {
    273 	{
    274 		/*
    275 		 * For Intel processors, check Chapter 35Model-specific
    276 		 * registers (MSRS), in "Intel (R) 64 and IA-32 Architectures
    277 		 * Software Developer's Manual, Volume 3C".
    278 		 */
    279 		"GenuineIntel",
    280 		CPUVENDOR_INTEL,
    281 		"Intel",
    282 		/* Family 4 */
    283 		{ {
    284 			CPUCLASS_486,
    285 			{
    286 				"486DX", "486DX", "486SX", "486DX2", "486SL",
    287 				"486SX2", 0, "486DX2 W/B Enhanced",
    288 				"486DX4", 0, 0, 0, 0, 0, 0, 0,
    289 			},
    290 			"486",		/* Default */
    291 			NULL,
    292 			NULL,
    293 			intel_cpu_cacheinfo,
    294 		},
    295 		/* Family 5 */
    296 		{
    297 			CPUCLASS_586,
    298 			{
    299 				"Pentium (P5 A-step)", "Pentium (P5)",
    300 				"Pentium (P54C)", "Pentium (P24T)",
    301 				"Pentium/MMX", "Pentium", 0,
    302 				"Pentium (P54C)", "Pentium/MMX (Tillamook)",
    303 				"Quark X1000", 0, 0, 0, 0, 0, 0,
    304 			},
    305 			"Pentium",	/* Default */
    306 			NULL,
    307 			NULL,
    308 			intel_cpu_cacheinfo,
    309 		},
    310 		/* Family 6 */
    311 		{
    312 			CPUCLASS_686,
    313 			{
    314 				[0x00] = "Pentium Pro (A-step)",
    315 				[0x01] = "Pentium Pro",
    316 				[0x03] = "Pentium II (Klamath)",
    317 				[0x04] = "Pentium Pro",
    318 				[0x05] = "Pentium II/Celeron (Deschutes)",
    319 				[0x06] = "Celeron (Mendocino)",
    320 				[0x07] = "Pentium III (Katmai)",
    321 				[0x08] = "Pentium III (Coppermine)",
    322 				[0x09] = "Pentium M (Banias)",
    323 				[0x0a] = "Pentium III Xeon (Cascades)",
    324 				[0x0b] = "Pentium III (Tualatin)",
    325 				[0x0d] = "Pentium M (Dothan)",
    326 				[0x0e] = "Pentium Core Duo, Core solo",
    327 				[0x0f] = "Xeon 30xx, 32xx, 51xx, 53xx, 73xx, "
    328 					 "Core 2 Quad 6xxx, "
    329 					 "Core 2 Extreme 6xxx, "
    330 					 "Core 2 Duo 4xxx, 5xxx, 6xxx, 7xxx "
    331 					 "and Pentium DC",
    332 				[0x15] = "EP80579 Integrated Processor",
    333 				[0x16] = "Celeron (45nm)",
    334 				[0x17] = "Xeon 31xx, 33xx, 52xx, 54xx, "
    335 					 "Core 2 Quad 8xxx and 9xxx",
    336 				[0x1a] = "Core i7, Xeon 34xx, 35xx and 55xx "
    337 					 "(Nehalem)",
    338 				[0x1c] = "45nm Atom Family",
    339 				[0x1d] = "XeonMP 74xx (Nehalem)",
    340 				[0x1e] = "Core i7 and i5",
    341 				[0x1f] = "Core i7 and i5",
    342 				[0x25] = "Xeon 36xx & 56xx, i7, i5 and i3",
    343 				[0x26] = "Atom Family",
    344 				[0x27] = "Atom Family",
    345 				[0x2a] = "Xeon E3-12xx, 2nd gen i7, i5, "
    346 					 "i3 2xxx",
    347 				[0x2c] = "Xeon 36xx & 56xx, i7, i5 and i3",
    348 				[0x2d] = "Xeon E5 Sandy Bridge family, "
    349 					 "Core i7-39xx Extreme",
    350 				[0x2e] = "Xeon 75xx & 65xx",
    351 				[0x2f] = "Xeon E7 family",
    352 				[0x35] = "Atom Family",
    353 				[0x36] = "Atom S1000",
    354 				[0x37] = "Atom E3000, Z3[67]00",
    355 				[0x3a] = "Xeon E3-1200v2 and 3rd gen core, "
    356 					 "Ivy Bridge",
    357 				[0x3c] = "4th gen Core, Xeon E3-12xx v3 "
    358 					 "(Haswell)",
    359 				[0x3d] = "Core M-5xxx, 5th gen Core (Broadwell)",
    360 				[0x3e] = "Xeon E5/E7 v2 (Ivy Bridge-E), "
    361 					 "Core i7-49xx Extreme",
    362 				[0x3f] = "Xeon E5-4600/2600/1600 v3, Xeon E7 v3 (Haswell-E), "
    363 					 "Core i7-59xx Extreme",
    364 				[0x45] = "4th gen Core, Xeon E3-12xx v3 "
    365 					 "(Haswell)",
    366 				[0x46] = "4th gen Core, Xeon E3-12xx v3 "
    367 					 "(Haswell)",
    368 				[0x47] = "5th gen Core, Xeon E3-1200 v4 (Broadwell)",
    369 				[0x4a] = "Atom Z3400",
    370 				[0x4c] = "Atom X[57]-Z8000 (Airmont)",
    371 				[0x4d] = "Atom C2000",
    372 				[0x4e] = "6th gen Core, Xeon E3-1[25]00 v5 (Skylake)",
    373 				[0x4f] = "Xeon E[57] v4 (Broadwell), Core i7-69xx Extreme",
    374 				[0x55] = "Xeon Scalable (Skylake)",
    375 				[0x56] = "Xeon D-1500 (Broadwell)",
    376 				[0x57] = "Xeon Phi [357]200 (Knights Landing)",
    377 				[0x5a] = "Atom E3500",
    378 				[0x5c] = "Atom (Goldmont)",
    379 				[0x5d] = "Atom X3-C3000 (Silvermont)",
    380 				[0x5e] = "6th gen Core, Xeon E3-1[25]00 v5 (Skylake)",
    381 				[0x5f] = "Atom (Goldmont, Denverton)",
    382 				[0x66] = "Future Core (Cannon Lake)",
    383 				[0x7a] = "Atom (Goldmont Plus)",
    384 				[0x85] = "Xeon Phi 7215, 7285, 7295 (Knights Mill)",
    385 				[0x8e] = "7th or 8th gen Core (Kaby Lake, Coffee Lake)",
    386 				[0x9e] = "7th or 8th gen Core (Kaby Lake, Coffee Lake)",
    387 			},
    388 			"Pentium Pro, II or III",	/* Default */
    389 			NULL,
    390 			intel_family_new_probe,
    391 			intel_cpu_cacheinfo,
    392 		},
    393 		/* Family > 6 */
    394 		{
    395 			CPUCLASS_686,
    396 			{
    397 				0, 0, 0, 0, 0, 0, 0, 0,
    398 				0, 0, 0, 0, 0, 0, 0, 0,
    399 			},
    400 			"Pentium 4",	/* Default */
    401 			NULL,
    402 			intel_family_new_probe,
    403 			intel_cpu_cacheinfo,
    404 		} }
    405 	},
    406 	{
    407 		"AuthenticAMD",
    408 		CPUVENDOR_AMD,
    409 		"AMD",
    410 		/* Family 4 */
    411 		{ {
    412 			CPUCLASS_486,
    413 			{
    414 				0, 0, 0, "Am486DX2 W/T",
    415 				0, 0, 0, "Am486DX2 W/B",
    416 				"Am486DX4 W/T or Am5x86 W/T 150",
    417 				"Am486DX4 W/B or Am5x86 W/B 150", 0, 0,
    418 				0, 0, "Am5x86 W/T 133/160",
    419 				"Am5x86 W/B 133/160",
    420 			},
    421 			"Am486 or Am5x86",	/* Default */
    422 			NULL,
    423 			NULL,
    424 			NULL,
    425 		},
    426 		/* Family 5 */
    427 		{
    428 			CPUCLASS_586,
    429 			{
    430 				"K5", "K5", "K5", "K5", 0, 0, "K6",
    431 				"K6", "K6-2", "K6-III", "Geode LX", 0, 0,
    432 				"K6-2+/III+", 0, 0,
    433 			},
    434 			"K5 or K6",		/* Default */
    435 			amd_family5_setup,
    436 			NULL,
    437 			amd_cpu_cacheinfo,
    438 		},
    439 		/* Family 6 */
    440 		{
    441 			CPUCLASS_686,
    442 			{
    443 				0, "Athlon Model 1", "Athlon Model 2",
    444 				"Duron", "Athlon Model 4 (Thunderbird)",
    445 				0, "Athlon", "Duron", "Athlon", 0,
    446 				"Athlon", 0, 0, 0, 0, 0,
    447 			},
    448 			"K7 (Athlon)",	/* Default */
    449 			NULL,
    450 			amd_family6_probe,
    451 			amd_cpu_cacheinfo,
    452 		},
    453 		/* Family > 6 */
    454 		{
    455 			CPUCLASS_686,
    456 			{
    457 				0, 0, 0, 0, 0, 0, 0, 0,
    458 				0, 0, 0, 0, 0, 0, 0, 0,
    459 			},
    460 			"Unknown K8 (Athlon)",	/* Default */
    461 			NULL,
    462 			amd_family6_probe,
    463 			amd_cpu_cacheinfo,
    464 		} }
    465 	},
    466 	{
    467 		"CyrixInstead",
    468 		CPUVENDOR_CYRIX,
    469 		"Cyrix",
    470 		/* Family 4 */
    471 		{ {
    472 			CPUCLASS_486,
    473 			{
    474 				0, 0, 0,
    475 				"MediaGX",
    476 				0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    477 			},
    478 			"486",		/* Default */
    479 			cyrix6x86_cpu_setup, /* XXX ?? */
    480 			NULL,
    481 			NULL,
    482 		},
    483 		/* Family 5 */
    484 		{
    485 			CPUCLASS_586,
    486 			{
    487 				0, 0, "6x86", 0,
    488 				"MMX-enhanced MediaGX (GXm)", /* or Geode? */
    489 				0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    490 			},
    491 			"6x86",		/* Default */
    492 			cyrix6x86_cpu_setup,
    493 			NULL,
    494 			NULL,
    495 		},
    496 		/* Family 6 */
    497 		{
    498 			CPUCLASS_686,
    499 			{
    500 				"6x86MX", 0, 0, 0, 0, 0, 0, 0,
    501 				0, 0, 0, 0, 0, 0, 0, 0,
    502 			},
    503 			"6x86MX",		/* Default */
    504 			cyrix6x86_cpu_setup,
    505 			NULL,
    506 			NULL,
    507 		},
    508 		/* Family > 6 */
    509 		{
    510 			CPUCLASS_686,
    511 			{
    512 				0, 0, 0, 0, 0, 0, 0, 0,
    513 				0, 0, 0, 0, 0, 0, 0, 0,
    514 			},
    515 			"Unknown 6x86MX",		/* Default */
    516 			NULL,
    517 			NULL,
    518 			NULL,
    519 		} }
    520 	},
    521 	{	/* MediaGX is now owned by National Semiconductor */
    522 		"Geode by NSC",
    523 		CPUVENDOR_CYRIX, /* XXX */
    524 		"National Semiconductor",
    525 		/* Family 4, NSC never had any of these */
    526 		{ {
    527 			CPUCLASS_486,
    528 			{
    529 				0, 0, 0, 0, 0, 0, 0, 0,
    530 				0, 0, 0, 0, 0, 0, 0, 0,
    531 			},
    532 			"486 compatible",	/* Default */
    533 			NULL,
    534 			NULL,
    535 			NULL,
    536 		},
    537 		/* Family 5: Geode family, formerly MediaGX */
    538 		{
    539 			CPUCLASS_586,
    540 			{
    541 				0, 0, 0, 0,
    542 				"Geode GX1",
    543 				0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    544 			},
    545 			"Geode",		/* Default */
    546 			cyrix6x86_cpu_setup,
    547 			NULL,
    548 			amd_cpu_cacheinfo,
    549 		},
    550 		/* Family 6, not yet available from NSC */
    551 		{
    552 			CPUCLASS_686,
    553 			{
    554 				0, 0, 0, 0, 0, 0, 0, 0,
    555 				0, 0, 0, 0, 0, 0, 0, 0,
    556 			},
    557 			"Pentium Pro compatible", /* Default */
    558 			NULL,
    559 			NULL,
    560 			NULL,
    561 		},
    562 		/* Family > 6, not yet available from NSC */
    563 		{
    564 			CPUCLASS_686,
    565 			{
    566 				0, 0, 0, 0, 0, 0, 0, 0,
    567 				0, 0, 0, 0, 0, 0, 0, 0,
    568 			},
    569 			"Pentium Pro compatible",	/* Default */
    570 			NULL,
    571 			NULL,
    572 			NULL,
    573 		} }
    574 	},
    575 	{
    576 		"CentaurHauls",
    577 		CPUVENDOR_IDT,
    578 		"IDT",
    579 		/* Family 4, IDT never had any of these */
    580 		{ {
    581 			CPUCLASS_486,
    582 			{
    583 				0, 0, 0, 0, 0, 0, 0, 0,
    584 				0, 0, 0, 0, 0, 0, 0, 0,
    585 			},
    586 			"486 compatible",	/* Default */
    587 			NULL,
    588 			NULL,
    589 			NULL,
    590 		},
    591 		/* Family 5 */
    592 		{
    593 			CPUCLASS_586,
    594 			{
    595 				0, 0, 0, 0, "WinChip C6", 0, 0, 0,
    596 				"WinChip 2", "WinChip 3", 0, 0, 0, 0, 0, 0,
    597 			},
    598 			"WinChip",		/* Default */
    599 			winchip_cpu_setup,
    600 			NULL,
    601 			NULL,
    602 		},
    603 		/* Family 6, VIA acquired IDT Centaur design subsidiary */
    604 		{
    605 			CPUCLASS_686,
    606 			{
    607 				0, 0, 0, 0, 0, 0, "C3 Samuel",
    608 				"C3 Samuel 2/Ezra", "C3 Ezra-T",
    609 				"C3 Nehemiah", "C7 Esther", 0, 0, "C7 Esther",
    610 				0, "VIA Nano",
    611 			},
    612 			"Unknown VIA/IDT",	/* Default */
    613 			NULL,
    614 			via_cpu_probe,
    615 			via_cpu_cacheinfo,
    616 		},
    617 		/* Family > 6, not yet available from VIA */
    618 		{
    619 			CPUCLASS_686,
    620 			{
    621 				0, 0, 0, 0, 0, 0, 0, 0,
    622 				0, 0, 0, 0, 0, 0, 0, 0,
    623 			},
    624 			"Pentium Pro compatible",	/* Default */
    625 			NULL,
    626 			NULL,
    627 			NULL,
    628 		} }
    629 	},
    630 	{
    631 		"GenuineTMx86",
    632 		CPUVENDOR_TRANSMETA,
    633 		"Transmeta",
    634 		/* Family 4, Transmeta never had any of these */
    635 		{ {
    636 			CPUCLASS_486,
    637 			{
    638 				0, 0, 0, 0, 0, 0, 0, 0,
    639 				0, 0, 0, 0, 0, 0, 0, 0,
    640 			},
    641 			"486 compatible",	/* Default */
    642 			NULL,
    643 			NULL,
    644 			NULL,
    645 		},
    646 		/* Family 5 */
    647 		{
    648 			CPUCLASS_586,
    649 			{
    650 				0, 0, 0, 0, 0, 0, 0, 0,
    651 				0, 0, 0, 0, 0, 0, 0, 0,
    652 			},
    653 			"Crusoe",		/* Default */
    654 			NULL,
    655 			NULL,
    656 			transmeta_cpu_info,
    657 		},
    658 		/* Family 6, not yet available from Transmeta */
    659 		{
    660 			CPUCLASS_686,
    661 			{
    662 				0, 0, 0, 0, 0, 0, 0, 0,
    663 				0, 0, 0, 0, 0, 0, 0, 0,
    664 			},
    665 			"Pentium Pro compatible",	/* Default */
    666 			NULL,
    667 			NULL,
    668 			NULL,
    669 		},
    670 		/* Family > 6, not yet available from Transmeta */
    671 		{
    672 			CPUCLASS_686,
    673 			{
    674 				0, 0, 0, 0, 0, 0, 0, 0,
    675 				0, 0, 0, 0, 0, 0, 0, 0,
    676 			},
    677 			"Pentium Pro compatible",	/* Default */
    678 			NULL,
    679 			NULL,
    680 			NULL,
    681 		} }
    682 	}
    683 };
    684 
    685 /*
    686  * disable the TSC such that we don't use the TSC in microtime(9)
    687  * because some CPUs got the implementation wrong.
    688  */
    689 static void
    690 disable_tsc(struct cpu_info *ci)
    691 {
    692 	if (ci->ci_feat_val[0] & CPUID_TSC) {
    693 		ci->ci_feat_val[0] &= ~CPUID_TSC;
    694 		aprint_error("WARNING: broken TSC disabled\n");
    695 	}
    696 }
    697 
    698 static void
    699 amd_family5_setup(struct cpu_info *ci)
    700 {
    701 
    702 	switch (ci->ci_model) {
    703 	case 0:		/* AMD-K5 Model 0 */
    704 		/*
    705 		 * According to the AMD Processor Recognition App Note,
    706 		 * the AMD-K5 Model 0 uses the wrong bit to indicate
    707 		 * support for global PTEs, instead using bit 9 (APIC)
    708 		 * rather than bit 13 (i.e. "0x200" vs. 0x2000".  Oops!).
    709 		 */
    710 		if (ci->ci_feat_val[0] & CPUID_APIC)
    711 			ci->ci_feat_val[0] =
    712 			    (ci->ci_feat_val[0] & ~CPUID_APIC) | CPUID_PGE;
    713 		/*
    714 		 * XXX But pmap_pg_g is already initialized -- need to kick
    715 		 * XXX the pmap somehow.  How does the MP branch do this?
    716 		 */
    717 		break;
    718 	}
    719 }
    720 
    721 static void
    722 cyrix6x86_cpu_setup(struct cpu_info *ci)
    723 {
    724 
    725 	/*
    726 	 * Do not disable the TSC on the Geode GX, it's reported to
    727 	 * work fine.
    728 	 */
    729 	if (ci->ci_signature != 0x552)
    730 		disable_tsc(ci);
    731 }
    732 
    733 static void
    734 winchip_cpu_setup(struct cpu_info *ci)
    735 {
    736 	switch (ci->ci_model) {
    737 	case 4:	/* WinChip C6 */
    738 		disable_tsc(ci);
    739 	}
    740 }
    741 
    742 
    743 static const char *
    744 intel_family6_name(struct cpu_info *ci)
    745 {
    746 	const char *ret = NULL;
    747 	u_int l2cache = ci->ci_cinfo[CAI_L2CACHE].cai_totalsize;
    748 
    749 	if (ci->ci_model == 5) {
    750 		switch (l2cache) {
    751 		case 0:
    752 		case 128 * 1024:
    753 			ret = "Celeron (Covington)";
    754 			break;
    755 		case 256 * 1024:
    756 			ret = "Mobile Pentium II (Dixon)";
    757 			break;
    758 		case 512 * 1024:
    759 			ret = "Pentium II";
    760 			break;
    761 		case 1 * 1024 * 1024:
    762 		case 2 * 1024 * 1024:
    763 			ret = "Pentium II Xeon";
    764 			break;
    765 		}
    766 	} else if (ci->ci_model == 6) {
    767 		switch (l2cache) {
    768 		case 256 * 1024:
    769 		case 512 * 1024:
    770 			ret = "Mobile Pentium II";
    771 			break;
    772 		}
    773 	} else if (ci->ci_model == 7) {
    774 		switch (l2cache) {
    775 		case 512 * 1024:
    776 			ret = "Pentium III";
    777 			break;
    778 		case 1 * 1024 * 1024:
    779 		case 2 * 1024 * 1024:
    780 			ret = "Pentium III Xeon";
    781 			break;
    782 		}
    783 	} else if (ci->ci_model >= 8) {
    784 		if (ci->ci_brand_id && ci->ci_brand_id < 0x10) {
    785 			switch (ci->ci_brand_id) {
    786 			case 0x3:
    787 				if (ci->ci_signature == 0x6B1)
    788 					ret = "Celeron";
    789 				break;
    790 			case 0x8:
    791 				if (ci->ci_signature >= 0xF13)
    792 					ret = "genuine processor";
    793 				break;
    794 			case 0xB:
    795 				if (ci->ci_signature >= 0xF13)
    796 					ret = "Xeon MP";
    797 				break;
    798 			case 0xE:
    799 				if (ci->ci_signature < 0xF13)
    800 					ret = "Xeon";
    801 				break;
    802 			}
    803 			if (ret == NULL)
    804 				ret = i386_intel_brand[ci->ci_brand_id];
    805 		}
    806 	}
    807 
    808 	return ret;
    809 }
    810 
    811 /*
    812  * Identify AMD64 CPU names from cpuid.
    813  *
    814  * Based on:
    815  * "Revision Guide for AMD Athlon 64 and AMD Opteron Processors"
    816  * http://www.amd.com/us-en/assets/content_type/white_papers_and_tech_docs/25759.pdf
    817  * "Revision Guide for AMD NPT Family 0Fh Processors"
    818  * http://www.amd.com/us-en/assets/content_type/white_papers_and_tech_docs/33610.pdf
    819  * and other miscellaneous reports.
    820  *
    821  * This is all rather pointless, these are cross 'brand' since the raw
    822  * silicon is shared.
    823  */
    824 static const char *
    825 amd_amd64_name(struct cpu_info *ci)
    826 {
    827 	static char family_str[32];
    828 
    829 	/* Only called if family >= 15 */
    830 
    831 	switch (ci->ci_family) {
    832 	case 15:
    833 		switch (ci->ci_model) {
    834 		case 0x21:	/* rev JH-E1/E6 */
    835 		case 0x41:	/* rev JH-F2 */
    836 			return "Dual-Core Opteron";
    837 		case 0x23:	/* rev JH-E6 (Toledo) */
    838 			return "Dual-Core Opteron or Athlon 64 X2";
    839 		case 0x43:	/* rev JH-F2 (Windsor) */
    840 			return "Athlon 64 FX or Athlon 64 X2";
    841 		case 0x24:	/* rev SH-E5 (Lancaster?) */
    842 			return "Mobile Athlon 64 or Turion 64";
    843 		case 0x05:	/* rev SH-B0/B3/C0/CG (SledgeHammer?) */
    844 			return "Opteron or Athlon 64 FX";
    845 		case 0x15:	/* rev SH-D0 */
    846 		case 0x25:	/* rev SH-E4 */
    847 			return "Opteron";
    848 		case 0x27:	/* rev DH-E4, SH-E4 */
    849 			return "Athlon 64 or Athlon 64 FX or Opteron";
    850 		case 0x48:	/* rev BH-F2 */
    851 			return "Turion 64 X2";
    852 		case 0x04:	/* rev SH-B0/C0/CG (ClawHammer) */
    853 		case 0x07:	/* rev SH-CG (ClawHammer) */
    854 		case 0x0b:	/* rev CH-CG */
    855 		case 0x14:	/* rev SH-D0 */
    856 		case 0x17:	/* rev SH-D0 */
    857 		case 0x1b:	/* rev CH-D0 */
    858 			return "Athlon 64";
    859 		case 0x2b:	/* rev BH-E4 (Manchester) */
    860 		case 0x4b:	/* rev BH-F2 (Windsor) */
    861 			return "Athlon 64 X2";
    862 		case 0x6b:	/* rev BH-G1 (Brisbane) */
    863 			return "Athlon X2 or Athlon 64 X2";
    864 		case 0x08:	/* rev CH-CG */
    865 		case 0x0c:	/* rev DH-CG (Newcastle) */
    866 		case 0x0e:	/* rev DH-CG (Newcastle?) */
    867 		case 0x0f:	/* rev DH-CG (Newcastle/Paris) */
    868 		case 0x18:	/* rev CH-D0 */
    869 		case 0x1c:	/* rev DH-D0 (Winchester) */
    870 		case 0x1f:	/* rev DH-D0 (Winchester/Victoria) */
    871 		case 0x2c:	/* rev DH-E3/E6 */
    872 		case 0x2f:	/* rev DH-E3/E6 (Venice/Palermo) */
    873 		case 0x4f:	/* rev DH-F2 (Orleans/Manila) */
    874 		case 0x5f:	/* rev DH-F2 (Orleans/Manila) */
    875 		case 0x6f:	/* rev DH-G1 */
    876 			return "Athlon 64 or Sempron";
    877 		default:
    878 			break;
    879 		}
    880 		return "Unknown AMD64 CPU";
    881 
    882 #if 0
    883 	case 16:
    884 		return "Family 10h";
    885 	case 17:
    886 		return "Family 11h";
    887 	case 18:
    888 		return "Family 12h";
    889 	case 19:
    890 		return "Family 14h";
    891 	case 20:
    892 		return "Family 15h";
    893 #endif
    894 
    895 	default:
    896 		break;
    897 	}
    898 
    899 	snprintf(family_str, sizeof family_str, "Family %xh", ci->ci_family);
    900 	return family_str;
    901 }
    902 
    903 static void
    904 intel_family_new_probe(struct cpu_info *ci)
    905 {
    906 	uint32_t descs[4];
    907 
    908 	x86_cpuid(0x80000000, descs);
    909 
    910 	/*
    911 	 * Determine extended feature flags.
    912 	 */
    913 	if (descs[0] >= 0x80000001) {
    914 		x86_cpuid(0x80000001, descs);
    915 		ci->ci_feat_val[2] |= descs[3];
    916 		ci->ci_feat_val[3] |= descs[2];
    917 	}
    918 }
    919 
    920 static void
    921 via_cpu_probe(struct cpu_info *ci)
    922 {
    923 	u_int stepping = CPUID_TO_STEPPING(ci->ci_signature);
    924 	u_int descs[4];
    925 	u_int lfunc;
    926 
    927 	/*
    928 	 * Determine the largest extended function value.
    929 	 */
    930 	x86_cpuid(0x80000000, descs);
    931 	lfunc = descs[0];
    932 
    933 	/*
    934 	 * Determine the extended feature flags.
    935 	 */
    936 	if (lfunc >= 0x80000001) {
    937 		x86_cpuid(0x80000001, descs);
    938 		ci->ci_feat_val[2] |= descs[3];
    939 	}
    940 
    941 	if (ci->ci_model < 0x9 || (ci->ci_model == 0x9 && stepping < 3))
    942 		return;
    943 
    944 	/* Nehemiah or Esther */
    945 	x86_cpuid(0xc0000000, descs);
    946 	lfunc = descs[0];
    947 	if (lfunc < 0xc0000001)	/* no ACE, no RNG */
    948 		return;
    949 
    950 	x86_cpuid(0xc0000001, descs);
    951 	lfunc = descs[3];
    952 	ci->ci_feat_val[4] = lfunc;
    953 }
    954 
    955 static void
    956 amd_family6_probe(struct cpu_info *ci)
    957 {
    958 	uint32_t descs[4];
    959 	char *p;
    960 	size_t i;
    961 
    962 	x86_cpuid(0x80000000, descs);
    963 
    964 	/*
    965 	 * Determine the extended feature flags.
    966 	 */
    967 	if (descs[0] >= 0x80000001) {
    968 		x86_cpuid(0x80000001, descs);
    969 		ci->ci_feat_val[2] |= descs[3]; /* %edx */
    970 		ci->ci_feat_val[3] = descs[2]; /* %ecx */
    971 	}
    972 
    973 	if (*cpu_brand_string == '\0')
    974 		return;
    975 
    976 	for (i = 1; i < __arraycount(amd_brand); i++)
    977 		if ((p = strstr(cpu_brand_string, amd_brand[i])) != NULL) {
    978 			ci->ci_brand_id = i;
    979 			strlcpy(amd_brand_name, p, sizeof(amd_brand_name));
    980 			break;
    981 		}
    982 }
    983 
    984 static void
    985 intel_cpu_cacheinfo(struct cpu_info *ci)
    986 {
    987 	const struct x86_cache_info *cai;
    988 	u_int descs[4];
    989 	int iterations, i, j;
    990 	int type, level;
    991 	int ways, partitions, linesize, sets;
    992 	int caitype = -1;
    993 	int totalsize;
    994 	uint8_t desc;
    995 
    996 	/* Return if the cpu is old pre-cpuid instruction cpu */
    997 	if (ci->ci_cpu_type >= 0)
    998 		return;
    999 
   1000 	if (ci->ci_cpuid_level < 2)
   1001 		return;
   1002 
   1003 	/*
   1004 	 * Parse the cache info from `cpuid leaf 2', if we have it.
   1005 	 * XXX This is kinda ugly, but hey, so is the architecture...
   1006 	 */
   1007 	x86_cpuid(2, descs);
   1008 	iterations = descs[0] & 0xff;
   1009 	while (iterations-- > 0) {
   1010 		for (i = 0; i < 4; i++) {
   1011 			if (descs[i] & 0x80000000)
   1012 				continue;
   1013 			for (j = 0; j < 4; j++) {
   1014 				/*
   1015 				 * The least significant byte in EAX
   1016 				 * ((desc[0] >> 0) & 0xff) is always 0x01 and
   1017 				 * it should be ignored.
   1018 				 */
   1019 				if (i == 0 && j == 0)
   1020 					continue;
   1021 				desc = (descs[i] >> (j * 8)) & 0xff;
   1022 				if (desc == 0)
   1023 					continue;
   1024 				cai = cache_info_lookup(intel_cpuid_cache_info,
   1025 				    desc);
   1026 				if (cai != NULL)
   1027 					ci->ci_cinfo[cai->cai_index] = *cai;
   1028 				else if ((verbose != 0) && (desc != 0xff)
   1029 				    && (desc != 0xfe))
   1030 					aprint_error_dev(ci->ci_dev, "error:"
   1031 					    " Unknown cacheinfo desc %02x\n",
   1032 					    desc);
   1033 			}
   1034 		}
   1035 		x86_cpuid(2, descs);
   1036 	}
   1037 
   1038 	if (ci->ci_cpuid_level < 4)
   1039 		return;
   1040 
   1041 	/* Parse the cache info from `cpuid leaf 4', if we have it. */
   1042 	for (i = 0; ; i++) {
   1043 		x86_cpuid2(4, i, descs);
   1044 		type = __SHIFTOUT(descs[0], CPUID_DCP_CACHETYPE);
   1045 		if (type == CPUID_DCP_CACHETYPE_N)
   1046 			break;
   1047 		level = __SHIFTOUT(descs[0], CPUID_DCP_CACHELEVEL);
   1048 		switch (level) {
   1049 		case 1:
   1050 			if (type == CPUID_DCP_CACHETYPE_I)
   1051 				caitype = CAI_ICACHE;
   1052 			else if (type == CPUID_DCP_CACHETYPE_D)
   1053 				caitype = CAI_DCACHE;
   1054 			else
   1055 				caitype = -1;
   1056 			break;
   1057 		case 2:
   1058 			if (type == CPUID_DCP_CACHETYPE_U)
   1059 				caitype = CAI_L2CACHE;
   1060 			else
   1061 				caitype = -1;
   1062 			break;
   1063 		case 3:
   1064 			if (type == CPUID_DCP_CACHETYPE_U)
   1065 				caitype = CAI_L3CACHE;
   1066 			else
   1067 				caitype = -1;
   1068 			break;
   1069 		default:
   1070 			caitype = -1;
   1071 			break;
   1072 		}
   1073 		if (caitype == -1) {
   1074 			aprint_error_dev(ci->ci_dev,
   1075 			    "error: unknown cache level&type (%d & %d)\n",
   1076 			    level, type);
   1077 			continue;
   1078 		}
   1079 		ways = __SHIFTOUT(descs[1], CPUID_DCP_WAYS) + 1;
   1080 		partitions =__SHIFTOUT(descs[1], CPUID_DCP_PARTITIONS)
   1081 		    + 1;
   1082 		linesize = __SHIFTOUT(descs[1], CPUID_DCP_LINESIZE)
   1083 		    + 1;
   1084 		sets = descs[2] + 1;
   1085 		totalsize = ways * partitions * linesize * sets;
   1086 		ci->ci_cinfo[caitype].cai_totalsize = totalsize;
   1087 		ci->ci_cinfo[caitype].cai_associativity = ways;
   1088 		ci->ci_cinfo[caitype].cai_linesize = linesize;
   1089 	}
   1090 
   1091 	if (ci->ci_cpuid_level < 0x18)
   1092 		return;
   1093 	/* Parse the TLB info from `cpuid leaf 18H', if we have it. */
   1094 	x86_cpuid(0x18, descs);
   1095 	iterations = descs[0];
   1096 	for (i = 0; i <= iterations; i++) {
   1097 		uint32_t pgsize;
   1098 		bool full;
   1099 
   1100 		x86_cpuid2(0x18, i, descs);
   1101 		type = __SHIFTOUT(descs[3], CPUID_DATP_TCTYPE);
   1102 		if (type == CPUID_DATP_TCTYPE_N)
   1103 			continue;
   1104 		level = __SHIFTOUT(descs[3], CPUID_DATP_TCLEVEL);
   1105 		pgsize = __SHIFTOUT(descs[1], CPUID_DATP_PGSIZE);
   1106 		switch (level) {
   1107 		case 1:
   1108 			if (type == CPUID_DATP_TCTYPE_I) {
   1109 				switch (pgsize) {
   1110 				case CPUID_DATP_PGSIZE_4KB:
   1111 					caitype = CAI_ITLB;
   1112 					break;
   1113 				case CPUID_DATP_PGSIZE_2MB
   1114 				    | CPUID_DATP_PGSIZE_4MB:
   1115 					caitype = CAI_ITLB2;
   1116 					break;
   1117 				case CPUID_DATP_PGSIZE_1GB:
   1118 					caitype = CAI_L1_1GBITLB;
   1119 					break;
   1120 				default:
   1121 					aprint_error_dev(ci->ci_dev,
   1122 					    "error: unknown ITLB size (%d)\n",
   1123 					    pgsize);
   1124 					caitype = CAI_ITLB;
   1125 					break;
   1126 				}
   1127 			} else if (type == CPUID_DATP_TCTYPE_D) {
   1128 				switch (pgsize) {
   1129 				case CPUID_DATP_PGSIZE_4KB:
   1130 					caitype = CAI_DTLB;
   1131 					break;
   1132 				case CPUID_DATP_PGSIZE_2MB
   1133 				    | CPUID_DATP_PGSIZE_4MB:
   1134 					caitype = CAI_DTLB2;
   1135 					break;
   1136 				case CPUID_DATP_PGSIZE_1GB:
   1137 					caitype = CAI_L1_1GBDTLB;
   1138 					break;
   1139 				default:
   1140 					aprint_error_dev(ci->ci_dev,
   1141 					    "error: unknown DTLB size (%d)\n",
   1142 					    pgsize);
   1143 					caitype = CAI_DTLB;
   1144 					break;
   1145 				}
   1146 			} else
   1147 				caitype = -1;
   1148 			break;
   1149 		case 2:
   1150 			if (type == CPUID_DATP_TCTYPE_I)
   1151 				caitype = CAI_L2_ITLB;
   1152 			else if (type == CPUID_DATP_TCTYPE_D)
   1153 				caitype = CAI_L2_DTLB;
   1154 			else if (type == CPUID_DATP_TCTYPE_U) {
   1155 				switch (pgsize) {
   1156 				case CPUID_DATP_PGSIZE_4KB:
   1157 					caitype = CAI_L2_STLB;
   1158 					break;
   1159 				case CPUID_DATP_PGSIZE_4KB
   1160 				    | CPUID_DATP_PGSIZE_2MB:
   1161 					caitype = CAI_L2_STLB2;
   1162 					break;
   1163 				case CPUID_DATP_PGSIZE_2MB
   1164 				    | CPUID_DATP_PGSIZE_4MB:
   1165 					caitype = CAI_L2_STLB3;
   1166 					break;
   1167 				default:
   1168 					aprint_error_dev(ci->ci_dev,
   1169 					    "error: unknown L2 STLB size (%d)\n",
   1170 					    pgsize);
   1171 					caitype = CAI_DTLB;
   1172 					break;
   1173 				}
   1174 			} else
   1175 				caitype = -1;
   1176 			break;
   1177 		case 3:
   1178 			/* XXX need work for L3 TLB */
   1179 			caitype = CAI_L3CACHE;
   1180 			break;
   1181 		default:
   1182 			caitype = -1;
   1183 			break;
   1184 		}
   1185 		if (caitype == -1) {
   1186 			aprint_error_dev(ci->ci_dev,
   1187 			    "error: unknown TLB level&type (%d & %d)\n",
   1188 			    level, type);
   1189 			continue;
   1190 		}
   1191 		switch (pgsize) {
   1192 		case CPUID_DATP_PGSIZE_4KB:
   1193 			linesize = 4 * 1024;
   1194 			break;
   1195 		case CPUID_DATP_PGSIZE_2MB:
   1196 			linesize = 2 * 1024 * 1024;
   1197 			break;
   1198 		case CPUID_DATP_PGSIZE_4MB:
   1199 			linesize = 4 * 1024 * 1024;
   1200 			break;
   1201 		case CPUID_DATP_PGSIZE_1GB:
   1202 			linesize = 1024 * 1024 * 1024;
   1203 			break;
   1204 		case CPUID_DATP_PGSIZE_2MB | CPUID_DATP_PGSIZE_4MB:
   1205 			aprint_error_dev(ci->ci_dev,
   1206 			    "WARINING: Currently 2M/4M info can't print correctly\n");
   1207 			linesize = 4 * 1024 * 1024;
   1208 			break;
   1209 		default:
   1210 			aprint_error_dev(ci->ci_dev,
   1211 			    "error: Unknown size combination\n");
   1212 			linesize = 4 * 1024;
   1213 			break;
   1214 		}
   1215 		ways = __SHIFTOUT(descs[1], CPUID_DATP_WAYS);
   1216 		sets = descs[2];
   1217 		full = descs[3] & CPUID_DATP_FULLASSOC;
   1218 		ci->ci_cinfo[caitype].cai_totalsize
   1219 		    = ways * sets; /* entries */
   1220 		ci->ci_cinfo[caitype].cai_associativity
   1221 		    = full ? 0xff : ways;
   1222 		ci->ci_cinfo[caitype].cai_linesize = linesize; /* pg size */
   1223 	}
   1224 }
   1225 
   1226 static const struct x86_cache_info amd_cpuid_l2cache_assoc_info[] =
   1227     AMD_L2CACHE_INFO;
   1228 
   1229 static const struct x86_cache_info amd_cpuid_l3cache_assoc_info[] =
   1230     AMD_L3CACHE_INFO;
   1231 
   1232 static void
   1233 amd_cpu_cacheinfo(struct cpu_info *ci)
   1234 {
   1235 	const struct x86_cache_info *cp;
   1236 	struct x86_cache_info *cai;
   1237 	u_int descs[4];
   1238 	u_int lfunc;
   1239 
   1240 	/*
   1241 	 * K5 model 0 has none of this info.
   1242 	 */
   1243 	if (ci->ci_family == 5 && ci->ci_model == 0)
   1244 		return;
   1245 
   1246 	/*
   1247 	 * Determine the largest extended function value.
   1248 	 */
   1249 	x86_cpuid(0x80000000, descs);
   1250 	lfunc = descs[0];
   1251 
   1252 	/*
   1253 	 * Determine L1 cache/TLB info.
   1254 	 */
   1255 	if (lfunc < 0x80000005) {
   1256 		/* No L1 cache info available. */
   1257 		return;
   1258 	}
   1259 
   1260 	x86_cpuid(0x80000005, descs);
   1261 
   1262 	/*
   1263 	 * K6-III and higher have large page TLBs.
   1264 	 */
   1265 	if ((ci->ci_family == 5 && ci->ci_model >= 9) || ci->ci_family >= 6) {
   1266 		cai = &ci->ci_cinfo[CAI_ITLB2];
   1267 		cai->cai_totalsize = AMD_L1_EAX_ITLB_ENTRIES(descs[0]);
   1268 		cai->cai_associativity = AMD_L1_EAX_ITLB_ASSOC(descs[0]);
   1269 		cai->cai_linesize = largepagesize;
   1270 
   1271 		cai = &ci->ci_cinfo[CAI_DTLB2];
   1272 		cai->cai_totalsize = AMD_L1_EAX_DTLB_ENTRIES(descs[0]);
   1273 		cai->cai_associativity = AMD_L1_EAX_DTLB_ASSOC(descs[0]);
   1274 		cai->cai_linesize = largepagesize;
   1275 	}
   1276 
   1277 	cai = &ci->ci_cinfo[CAI_ITLB];
   1278 	cai->cai_totalsize = AMD_L1_EBX_ITLB_ENTRIES(descs[1]);
   1279 	cai->cai_associativity = AMD_L1_EBX_ITLB_ASSOC(descs[1]);
   1280 	cai->cai_linesize = (4 * 1024);
   1281 
   1282 	cai = &ci->ci_cinfo[CAI_DTLB];
   1283 	cai->cai_totalsize = AMD_L1_EBX_DTLB_ENTRIES(descs[1]);
   1284 	cai->cai_associativity = AMD_L1_EBX_DTLB_ASSOC(descs[1]);
   1285 	cai->cai_linesize = (4 * 1024);
   1286 
   1287 	cai = &ci->ci_cinfo[CAI_DCACHE];
   1288 	cai->cai_totalsize = AMD_L1_ECX_DC_SIZE(descs[2]);
   1289 	cai->cai_associativity = AMD_L1_ECX_DC_ASSOC(descs[2]);
   1290 	cai->cai_linesize = AMD_L1_ECX_DC_LS(descs[2]);
   1291 
   1292 	cai = &ci->ci_cinfo[CAI_ICACHE];
   1293 	cai->cai_totalsize = AMD_L1_EDX_IC_SIZE(descs[3]);
   1294 	cai->cai_associativity = AMD_L1_EDX_IC_ASSOC(descs[3]);
   1295 	cai->cai_linesize = AMD_L1_EDX_IC_LS(descs[3]);
   1296 
   1297 	/*
   1298 	 * Determine L2 cache/TLB info.
   1299 	 */
   1300 	if (lfunc < 0x80000006) {
   1301 		/* No L2 cache info available. */
   1302 		return;
   1303 	}
   1304 
   1305 	x86_cpuid(0x80000006, descs);
   1306 
   1307 	cai = &ci->ci_cinfo[CAI_L2_ITLB];
   1308 	cai->cai_totalsize = AMD_L2_EBX_IUTLB_ENTRIES(descs[1]);
   1309 	cai->cai_associativity = AMD_L2_EBX_IUTLB_ASSOC(descs[1]);
   1310 	cai->cai_linesize = (4 * 1024);
   1311 	cp = cache_info_lookup(amd_cpuid_l2cache_assoc_info,
   1312 	    cai->cai_associativity);
   1313 	if (cp != NULL)
   1314 		cai->cai_associativity = cp->cai_associativity;
   1315 	else
   1316 		cai->cai_associativity = 0;	/* XXX Unknown/reserved */
   1317 
   1318 	cai = &ci->ci_cinfo[CAI_L2_ITLB2];
   1319 	cai->cai_totalsize = AMD_L2_EAX_IUTLB_ENTRIES(descs[0]);
   1320 	cai->cai_associativity = AMD_L2_EAX_IUTLB_ASSOC(descs[0]);
   1321 	cai->cai_linesize = largepagesize;
   1322 	cp = cache_info_lookup(amd_cpuid_l2cache_assoc_info,
   1323 	    cai->cai_associativity);
   1324 	if (cp != NULL)
   1325 		cai->cai_associativity = cp->cai_associativity;
   1326 	else
   1327 		cai->cai_associativity = 0;	/* XXX Unknown/reserved */
   1328 
   1329 	cai = &ci->ci_cinfo[CAI_L2_DTLB];
   1330 	cai->cai_totalsize = AMD_L2_EBX_DTLB_ENTRIES(descs[1]);
   1331 	cai->cai_associativity = AMD_L2_EBX_DTLB_ASSOC(descs[1]);
   1332 	cai->cai_linesize = (4 * 1024);
   1333 	cp = cache_info_lookup(amd_cpuid_l2cache_assoc_info,
   1334 	    cai->cai_associativity);
   1335 	if (cp != NULL)
   1336 		cai->cai_associativity = cp->cai_associativity;
   1337 	else
   1338 		cai->cai_associativity = 0;	/* XXX Unknown/reserved */
   1339 
   1340 	cai = &ci->ci_cinfo[CAI_L2_DTLB2];
   1341 	cai->cai_totalsize = AMD_L2_EAX_DTLB_ENTRIES(descs[0]);
   1342 	cai->cai_associativity = AMD_L2_EAX_DTLB_ASSOC(descs[0]);
   1343 	cai->cai_linesize = largepagesize;
   1344 	cp = cache_info_lookup(amd_cpuid_l2cache_assoc_info,
   1345 	    cai->cai_associativity);
   1346 	if (cp != NULL)
   1347 		cai->cai_associativity = cp->cai_associativity;
   1348 	else
   1349 		cai->cai_associativity = 0;	/* XXX Unknown/reserved */
   1350 
   1351 	cai = &ci->ci_cinfo[CAI_L2CACHE];
   1352 	cai->cai_totalsize = AMD_L2_ECX_C_SIZE(descs[2]);
   1353 	cai->cai_associativity = AMD_L2_ECX_C_ASSOC(descs[2]);
   1354 	cai->cai_linesize = AMD_L2_ECX_C_LS(descs[2]);
   1355 
   1356 	cp = cache_info_lookup(amd_cpuid_l2cache_assoc_info,
   1357 	    cai->cai_associativity);
   1358 	if (cp != NULL)
   1359 		cai->cai_associativity = cp->cai_associativity;
   1360 	else
   1361 		cai->cai_associativity = 0;	/* XXX Unknown/reserved */
   1362 
   1363 	/*
   1364 	 * Determine L3 cache info on AMD Family 10h and newer processors
   1365 	 */
   1366 	if (ci->ci_family >= 0x10) {
   1367 		cai = &ci->ci_cinfo[CAI_L3CACHE];
   1368 		cai->cai_totalsize = AMD_L3_EDX_C_SIZE(descs[3]);
   1369 		cai->cai_associativity = AMD_L3_EDX_C_ASSOC(descs[3]);
   1370 		cai->cai_linesize = AMD_L3_EDX_C_LS(descs[3]);
   1371 
   1372 		cp = cache_info_lookup(amd_cpuid_l3cache_assoc_info,
   1373 		    cai->cai_associativity);
   1374 		if (cp != NULL)
   1375 			cai->cai_associativity = cp->cai_associativity;
   1376 		else
   1377 			cai->cai_associativity = 0;	/* XXX Unkn/Rsvd */
   1378 	}
   1379 
   1380 	/*
   1381 	 * Determine 1GB TLB info.
   1382 	 */
   1383 	if (lfunc < 0x80000019) {
   1384 		/* No 1GB TLB info available. */
   1385 		return;
   1386 	}
   1387 
   1388 	x86_cpuid(0x80000019, descs);
   1389 
   1390 	cai = &ci->ci_cinfo[CAI_L1_1GBITLB];
   1391 	cai->cai_totalsize = AMD_L1_1GB_EAX_IUTLB_ENTRIES(descs[0]);
   1392 	cai->cai_associativity = AMD_L1_1GB_EAX_IUTLB_ASSOC(descs[0]);
   1393 	cai->cai_linesize = (1024 * 1024 * 1024);
   1394 	cp = cache_info_lookup(amd_cpuid_l2cache_assoc_info,
   1395 	    cai->cai_associativity);
   1396 	if (cp != NULL)
   1397 		cai->cai_associativity = cp->cai_associativity;
   1398 	else
   1399 		cai->cai_associativity = 0;	/* XXX Unknown/reserved */
   1400 
   1401 	cai = &ci->ci_cinfo[CAI_L1_1GBDTLB];
   1402 	cai->cai_totalsize = AMD_L1_1GB_EAX_DTLB_ENTRIES(descs[0]);
   1403 	cai->cai_associativity = AMD_L1_1GB_EAX_DTLB_ASSOC(descs[0]);
   1404 	cai->cai_linesize = (1024 * 1024 * 1024);
   1405 	cp = cache_info_lookup(amd_cpuid_l2cache_assoc_info,
   1406 	    cai->cai_associativity);
   1407 	if (cp != NULL)
   1408 		cai->cai_associativity = cp->cai_associativity;
   1409 	else
   1410 		cai->cai_associativity = 0;	/* XXX Unknown/reserved */
   1411 
   1412 	cai = &ci->ci_cinfo[CAI_L2_1GBITLB];
   1413 	cai->cai_totalsize = AMD_L2_1GB_EBX_IUTLB_ENTRIES(descs[1]);
   1414 	cai->cai_associativity = AMD_L2_1GB_EBX_IUTLB_ASSOC(descs[1]);
   1415 	cai->cai_linesize = (1024 * 1024 * 1024);
   1416 	cp = cache_info_lookup(amd_cpuid_l2cache_assoc_info,
   1417 	    cai->cai_associativity);
   1418 	if (cp != NULL)
   1419 		cai->cai_associativity = cp->cai_associativity;
   1420 	else
   1421 		cai->cai_associativity = 0;	/* XXX Unknown/reserved */
   1422 
   1423 	cai = &ci->ci_cinfo[CAI_L2_1GBDTLB];
   1424 	cai->cai_totalsize = AMD_L2_1GB_EBX_DUTLB_ENTRIES(descs[1]);
   1425 	cai->cai_associativity = AMD_L2_1GB_EBX_DUTLB_ASSOC(descs[1]);
   1426 	cai->cai_linesize = (1024 * 1024 * 1024);
   1427 	cp = cache_info_lookup(amd_cpuid_l2cache_assoc_info,
   1428 	    cai->cai_associativity);
   1429 	if (cp != NULL)
   1430 		cai->cai_associativity = cp->cai_associativity;
   1431 	else
   1432 		cai->cai_associativity = 0;	/* XXX Unknown/reserved */
   1433 }
   1434 
   1435 static void
   1436 via_cpu_cacheinfo(struct cpu_info *ci)
   1437 {
   1438 	struct x86_cache_info *cai;
   1439 	int stepping;
   1440 	u_int descs[4];
   1441 	u_int lfunc;
   1442 
   1443 	stepping = CPUID_TO_STEPPING(ci->ci_signature);
   1444 
   1445 	/*
   1446 	 * Determine the largest extended function value.
   1447 	 */
   1448 	x86_cpuid(0x80000000, descs);
   1449 	lfunc = descs[0];
   1450 
   1451 	/*
   1452 	 * Determine L1 cache/TLB info.
   1453 	 */
   1454 	if (lfunc < 0x80000005) {
   1455 		/* No L1 cache info available. */
   1456 		return;
   1457 	}
   1458 
   1459 	x86_cpuid(0x80000005, descs);
   1460 
   1461 	cai = &ci->ci_cinfo[CAI_ITLB];
   1462 	cai->cai_totalsize = VIA_L1_EBX_ITLB_ENTRIES(descs[1]);
   1463 	cai->cai_associativity = VIA_L1_EBX_ITLB_ASSOC(descs[1]);
   1464 	cai->cai_linesize = (4 * 1024);
   1465 
   1466 	cai = &ci->ci_cinfo[CAI_DTLB];
   1467 	cai->cai_totalsize = VIA_L1_EBX_DTLB_ENTRIES(descs[1]);
   1468 	cai->cai_associativity = VIA_L1_EBX_DTLB_ASSOC(descs[1]);
   1469 	cai->cai_linesize = (4 * 1024);
   1470 
   1471 	cai = &ci->ci_cinfo[CAI_DCACHE];
   1472 	cai->cai_totalsize = VIA_L1_ECX_DC_SIZE(descs[2]);
   1473 	cai->cai_associativity = VIA_L1_ECX_DC_ASSOC(descs[2]);
   1474 	cai->cai_linesize = VIA_L1_EDX_IC_LS(descs[2]);
   1475 	if (ci->ci_model == 9 && stepping == 8) {
   1476 		/* Erratum: stepping 8 reports 4 when it should be 2 */
   1477 		cai->cai_associativity = 2;
   1478 	}
   1479 
   1480 	cai = &ci->ci_cinfo[CAI_ICACHE];
   1481 	cai->cai_totalsize = VIA_L1_EDX_IC_SIZE(descs[3]);
   1482 	cai->cai_associativity = VIA_L1_EDX_IC_ASSOC(descs[3]);
   1483 	cai->cai_linesize = VIA_L1_EDX_IC_LS(descs[3]);
   1484 	if (ci->ci_model == 9 && stepping == 8) {
   1485 		/* Erratum: stepping 8 reports 4 when it should be 2 */
   1486 		cai->cai_associativity = 2;
   1487 	}
   1488 
   1489 	/*
   1490 	 * Determine L2 cache/TLB info.
   1491 	 */
   1492 	if (lfunc < 0x80000006) {
   1493 		/* No L2 cache info available. */
   1494 		return;
   1495 	}
   1496 
   1497 	x86_cpuid(0x80000006, descs);
   1498 
   1499 	cai = &ci->ci_cinfo[CAI_L2CACHE];
   1500 	if (ci->ci_model >= 9) {
   1501 		cai->cai_totalsize = VIA_L2N_ECX_C_SIZE(descs[2]);
   1502 		cai->cai_associativity = VIA_L2N_ECX_C_ASSOC(descs[2]);
   1503 		cai->cai_linesize = VIA_L2N_ECX_C_LS(descs[2]);
   1504 	} else {
   1505 		cai->cai_totalsize = VIA_L2_ECX_C_SIZE(descs[2]);
   1506 		cai->cai_associativity = VIA_L2_ECX_C_ASSOC(descs[2]);
   1507 		cai->cai_linesize = VIA_L2_ECX_C_LS(descs[2]);
   1508 	}
   1509 }
   1510 
   1511 static void
   1512 tmx86_get_longrun_status(u_int *frequency, u_int *voltage, u_int *percentage)
   1513 {
   1514 	u_int descs[4];
   1515 
   1516 	x86_cpuid(0x80860007, descs);
   1517 	*frequency = descs[0];
   1518 	*voltage = descs[1];
   1519 	*percentage = descs[2];
   1520 }
   1521 
   1522 static void
   1523 transmeta_cpu_info(struct cpu_info *ci)
   1524 {
   1525 	u_int descs[4], nreg;
   1526 	u_int frequency, voltage, percentage;
   1527 
   1528 	x86_cpuid(0x80860000, descs);
   1529 	nreg = descs[0];
   1530 	if (nreg >= 0x80860001) {
   1531 		x86_cpuid(0x80860001, descs);
   1532 		aprint_verbose_dev(ci->ci_dev, "Processor revision %u.%u.%u.%u\n",
   1533 		    (descs[1] >> 24) & 0xff,
   1534 		    (descs[1] >> 16) & 0xff,
   1535 		    (descs[1] >> 8) & 0xff,
   1536 		    descs[1] & 0xff);
   1537 	}
   1538 	if (nreg >= 0x80860002) {
   1539 		x86_cpuid(0x80860002, descs);
   1540 		aprint_verbose_dev(ci->ci_dev, "Code Morphing Software Rev: %u.%u.%u-%u-%u\n",
   1541 		    (descs[1] >> 24) & 0xff,
   1542 		    (descs[1] >> 16) & 0xff,
   1543 		    (descs[1] >> 8) & 0xff,
   1544 		    descs[1] & 0xff,
   1545 		    descs[2]);
   1546 	}
   1547 	if (nreg >= 0x80860006) {
   1548 		union {
   1549 			char text[65];
   1550 			u_int descs[4][4];
   1551 		} info;
   1552 		int i;
   1553 
   1554 		for (i=0; i<4; i++) {
   1555 			x86_cpuid(0x80860003 + i, info.descs[i]);
   1556 		}
   1557 		info.text[64] = '\0';
   1558 		aprint_verbose_dev(ci->ci_dev, "%s\n", info.text);
   1559 	}
   1560 
   1561 	if (nreg >= 0x80860007) {
   1562 		tmx86_get_longrun_status(&frequency,
   1563 		    &voltage, &percentage);
   1564 		aprint_verbose_dev(ci->ci_dev, "LongRun <%dMHz %dmV %d%%>\n",
   1565 		    frequency, voltage, percentage);
   1566 	}
   1567 }
   1568 
   1569 static void
   1570 cpu_probe_base_features(struct cpu_info *ci, const char *cpuname)
   1571 {
   1572 	u_int descs[4];
   1573 	int i;
   1574 	uint32_t brand[12];
   1575 
   1576 	memset(ci, 0, sizeof(*ci));
   1577 	ci->ci_dev = cpuname;
   1578 
   1579 	ci->ci_cpu_type = x86_identify();
   1580 	if (ci->ci_cpu_type >= 0) {
   1581 		/* Old pre-cpuid instruction cpu */
   1582 		ci->ci_cpuid_level = -1;
   1583 		return;
   1584 	}
   1585 
   1586 	/*
   1587 	 * This CPU supports cpuid instruction, so we can call x86_cpuid()
   1588 	 * function.
   1589 	 */
   1590 
   1591 	/*
   1592 	 * Fn0000_0000:
   1593 	 * - Save cpuid max level.
   1594 	 * - Save vendor string.
   1595 	 */
   1596 	x86_cpuid(0, descs);
   1597 	ci->ci_cpuid_level = descs[0];
   1598 	/* Save vendor string */
   1599 	ci->ci_vendor[0] = descs[1];
   1600 	ci->ci_vendor[2] = descs[2];
   1601 	ci->ci_vendor[1] = descs[3];
   1602 	ci->ci_vendor[3] = 0;
   1603 
   1604 	/*
   1605 	 * Fn8000_0000:
   1606 	 * - Get cpuid extended function's max level.
   1607 	 */
   1608 	x86_cpuid(0x80000000, descs);
   1609 	if (descs[0] >= 0x80000000)
   1610 		ci->ci_cpuid_extlevel = descs[0];
   1611 	else {
   1612 		/* Set lower value than 0x80000000 */
   1613 		ci->ci_cpuid_extlevel = 0;
   1614 	}
   1615 
   1616 	/*
   1617 	 * Fn8000_000[2-4]:
   1618 	 * - Save brand string.
   1619 	 */
   1620 	if (ci->ci_cpuid_extlevel >= 0x80000004) {
   1621 		x86_cpuid(0x80000002, brand);
   1622 		x86_cpuid(0x80000003, brand + 4);
   1623 		x86_cpuid(0x80000004, brand + 8);
   1624 		for (i = 0; i < 48; i++)
   1625 			if (((char *) brand)[i] != ' ')
   1626 				break;
   1627 		memcpy(cpu_brand_string, ((char *) brand) + i, 48 - i);
   1628 	}
   1629 
   1630 	if (ci->ci_cpuid_level < 1)
   1631 		return;
   1632 
   1633 	/*
   1634 	 * Fn0000_0001:
   1635 	 * - Get CPU family, model and stepping (from eax).
   1636 	 * - Initial local APIC ID and brand ID (from ebx)
   1637 	 * - CPUID2 (from ecx)
   1638 	 * - CPUID (from edx)
   1639 	 */
   1640 	x86_cpuid(1, descs);
   1641 	ci->ci_signature = descs[0];
   1642 
   1643 	/* Extract full family/model values */
   1644 	ci->ci_family = CPUID_TO_FAMILY(ci->ci_signature);
   1645 	ci->ci_model = CPUID_TO_MODEL(ci->ci_signature);
   1646 
   1647 	/* Brand is low order 8 bits of ebx */
   1648 	ci->ci_brand_id = __SHIFTOUT(descs[1], CPUID_BRAND_INDEX);
   1649 	/* Initial local APIC ID */
   1650 	ci->ci_initapicid = __SHIFTOUT(descs[1], CPUID_LOCAL_APIC_ID);
   1651 
   1652 	ci->ci_feat_val[1] = descs[2];
   1653 	ci->ci_feat_val[0] = descs[3];
   1654 
   1655 	if (ci->ci_cpuid_level < 3)
   1656 		return;
   1657 
   1658 	/*
   1659 	 * If the processor serial number misfeature is present and supported,
   1660 	 * extract it here.
   1661 	 */
   1662 	if ((ci->ci_feat_val[0] & CPUID_PN) != 0) {
   1663 		ci->ci_cpu_serial[0] = ci->ci_signature;
   1664 		x86_cpuid(3, descs);
   1665 		ci->ci_cpu_serial[2] = descs[2];
   1666 		ci->ci_cpu_serial[1] = descs[3];
   1667 	}
   1668 
   1669 	if (ci->ci_cpuid_level < 0x7)
   1670 		return;
   1671 
   1672 	x86_cpuid(7, descs);
   1673 	ci->ci_feat_val[5] = descs[1];
   1674 	ci->ci_feat_val[6] = descs[2];
   1675 
   1676 	if (ci->ci_cpuid_level < 0xd)
   1677 		return;
   1678 
   1679 	/* Get support XCR0 bits */
   1680 	x86_cpuid2(0xd, 0, descs);
   1681 	ci->ci_feat_val[7] = descs[0];	/* Actually 64 bits */
   1682 	ci->ci_cur_xsave = descs[1];
   1683 	ci->ci_max_xsave = descs[2];
   1684 
   1685 	/* Additional flags (eg xsaveopt support) */
   1686 	x86_cpuid2(0xd, 1, descs);
   1687 	ci->ci_feat_val[8] = descs[0];   /* Actually 64 bits */
   1688 }
   1689 
   1690 static void
   1691 cpu_probe_hv_features(struct cpu_info *ci, const char *cpuname)
   1692 {
   1693 	uint32_t descs[4];
   1694 	char hv_sig[13];
   1695 	char *p;
   1696 	const char *hv_name;
   1697 	int i;
   1698 
   1699 	/*
   1700 	 * [RFC] CPUID usage for interaction between Hypervisors and Linux.
   1701 	 * http://lkml.org/lkml/2008/10/1/246
   1702 	 *
   1703 	 * KB1009458: Mechanisms to determine if software is running in
   1704 	 * a VMware virtual machine
   1705 	 * http://kb.vmware.com/kb/1009458
   1706 	 */
   1707 	if ((ci->ci_feat_val[1] & CPUID2_RAZ) != 0) {
   1708 		x86_cpuid(0x40000000, descs);
   1709 		for (i = 1, p = hv_sig; i < 4; i++, p += sizeof(descs) / 4)
   1710 			memcpy(p, &descs[i], sizeof(descs[i]));
   1711 		*p = '\0';
   1712 		/*
   1713 		 * HV vendor	ID string
   1714 		 * ------------+--------------
   1715 		 * KVM		"KVMKVMKVM"
   1716 		 * Microsoft	"Microsoft Hv"
   1717 		 * VMware	"VMwareVMware"
   1718 		 * Xen		"XenVMMXenVMM"
   1719 		 */
   1720 		if (strncmp(hv_sig, "KVMKVMKVM", 9) == 0)
   1721 			hv_name = "KVM";
   1722 		else if (strncmp(hv_sig, "Microsoft Hv", 12) == 0)
   1723 			hv_name = "Hyper-V";
   1724 		else if (strncmp(hv_sig, "VMwareVMware", 12) == 0)
   1725 			hv_name = "VMware";
   1726 		else if (strncmp(hv_sig, "XenVMMXenVMM", 12) == 0)
   1727 			hv_name = "Xen";
   1728 		else
   1729 			hv_name = "unknown";
   1730 
   1731 		printf("%s: Running on hypervisor: %s\n", cpuname, hv_name);
   1732 	}
   1733 }
   1734 
   1735 static void
   1736 cpu_probe_features(struct cpu_info *ci)
   1737 {
   1738 	const struct cpu_cpuid_nameclass *cpup = NULL;
   1739 	unsigned int i;
   1740 
   1741 	if (ci->ci_cpuid_level < 1)
   1742 		return;
   1743 
   1744 	for (i = 0; i < __arraycount(i386_cpuid_cpus); i++) {
   1745 		if (!strncmp((char *)ci->ci_vendor,
   1746 		    i386_cpuid_cpus[i].cpu_id, 12)) {
   1747 			cpup = &i386_cpuid_cpus[i];
   1748 			break;
   1749 		}
   1750 	}
   1751 
   1752 	if (cpup == NULL)
   1753 		return;
   1754 
   1755 	i = ci->ci_family - CPU_MINFAMILY;
   1756 
   1757 	if (i >= __arraycount(cpup->cpu_family))
   1758 		i = __arraycount(cpup->cpu_family) - 1;
   1759 
   1760 	if (cpup->cpu_family[i].cpu_probe == NULL)
   1761 		return;
   1762 
   1763 	(*cpup->cpu_family[i].cpu_probe)(ci);
   1764 }
   1765 
   1766 static void
   1767 print_bits(const char *cpuname, const char *hdr, const char *fmt, uint32_t val)
   1768 {
   1769 	char buf[32 * 16];
   1770 	char *bp;
   1771 
   1772 #define	MAX_LINE_LEN	79	/* get from command arg or 'stty cols' ? */
   1773 
   1774 	if (val == 0 || fmt == NULL)
   1775 		return;
   1776 
   1777 	snprintb_m(buf, sizeof(buf), fmt, val,
   1778 	    MAX_LINE_LEN - strlen(cpuname) - 2 - strlen(hdr) - 1);
   1779 	bp = buf;
   1780 	while (*bp != '\0') {
   1781 		aprint_verbose("%s: %s %s\n", cpuname, hdr, bp);
   1782 		bp += strlen(bp) + 1;
   1783 	}
   1784 }
   1785 
   1786 static void
   1787 identifycpu_cpuids(struct cpu_info *ci)
   1788 {
   1789 	const char *cpuname = ci->ci_dev;
   1790 	u_int lp_max = 1;	/* logical processors per package */
   1791 	u_int smt_max;		/* smt per core */
   1792 	u_int core_max = 1;	/* core per package */
   1793 	u_int smt_bits, core_bits;
   1794 	uint32_t descs[4];
   1795 
   1796 	aprint_verbose("%s: Initial APIC ID %u\n", cpuname, ci->ci_initapicid);
   1797 	ci->ci_packageid = ci->ci_initapicid;
   1798 	ci->ci_coreid = 0;
   1799 	ci->ci_smtid = 0;
   1800 	if (cpu_vendor != CPUVENDOR_INTEL) {
   1801 		return;
   1802 	}
   1803 
   1804 	/*
   1805 	 * 253668.pdf 7.10.2
   1806 	 */
   1807 
   1808 	if ((ci->ci_feat_val[0] & CPUID_HTT) != 0) {
   1809 		x86_cpuid(1, descs);
   1810 		lp_max = __SHIFTOUT(descs[1], CPUID_HTT_CORES);
   1811 	}
   1812 	if (ci->ci_cpuid_level >= 4) {
   1813 		x86_cpuid2(4, 0, descs);
   1814 		core_max = (descs[0] >> 26) + 1;
   1815 	}
   1816 	assert(lp_max >= core_max);
   1817 	smt_max = lp_max / core_max;
   1818 	smt_bits = ilog2(smt_max - 1) + 1;
   1819 	core_bits = ilog2(core_max - 1) + 1;
   1820 	if (smt_bits + core_bits) {
   1821 		ci->ci_packageid = ci->ci_initapicid >> (smt_bits + core_bits);
   1822 	}
   1823 	aprint_verbose("%s: Cluster/Package ID %u\n", cpuname,
   1824 	    ci->ci_packageid);
   1825 	if (core_bits) {
   1826 		u_int core_mask = __BITS(smt_bits, smt_bits + core_bits - 1);
   1827 
   1828 		ci->ci_coreid =
   1829 		    __SHIFTOUT(ci->ci_initapicid, core_mask);
   1830 		aprint_verbose("%s: Core ID %u\n", cpuname, ci->ci_coreid);
   1831 	}
   1832 	if (smt_bits) {
   1833 		u_int smt_mask = __BITS((int)0, (int)(smt_bits - 1));
   1834 
   1835 		ci->ci_smtid = __SHIFTOUT(ci->ci_initapicid, smt_mask);
   1836 		aprint_verbose("%s: SMT ID %u\n", cpuname, ci->ci_smtid);
   1837 	}
   1838 }
   1839 
   1840 void
   1841 identifycpu(int fd, const char *cpuname)
   1842 {
   1843 	const char *name = "", *modifier, *vendorname, *brand = "";
   1844 	int class = CPUCLASS_386;
   1845 	unsigned int i;
   1846 	int modif, family;
   1847 	const struct cpu_cpuid_nameclass *cpup = NULL;
   1848 	const struct cpu_cpuid_family *cpufam;
   1849 	struct cpu_info *ci, cistore;
   1850 	u_int descs[4];
   1851 	size_t sz;
   1852 	struct cpu_ucode_version ucode;
   1853 	union {
   1854 		struct cpu_ucode_version_amd amd;
   1855 		struct cpu_ucode_version_intel1 intel1;
   1856 	} ucvers;
   1857 
   1858 	ci = &cistore;
   1859 	cpu_probe_base_features(ci, cpuname);
   1860 	aprint_verbose("%s: highest basic info %08x\n", cpuname,
   1861 	    ci->ci_cpuid_level);
   1862 	if (verbose) {
   1863 		int bf;
   1864 
   1865 		for (bf = 0; bf <= ci->ci_cpuid_level; bf++) {
   1866 			x86_cpuid(bf, descs);
   1867 			printf("%s: %08x: %08x %08x %08x %08x\n", cpuname,
   1868 			    bf, descs[0], descs[1], descs[2], descs[3]);
   1869 		}
   1870 	}
   1871 	if (ci->ci_cpuid_extlevel >=  0x80000000)
   1872 		aprint_verbose("%s: highest extended info %08x\n", cpuname,
   1873 		    ci->ci_cpuid_extlevel);
   1874 	if (verbose) {
   1875 		unsigned int ef;
   1876 
   1877 		for (ef = 0x80000000; ef <= ci->ci_cpuid_extlevel; ef++) {
   1878 			x86_cpuid(ef, descs);
   1879 			printf("%s: %08x: %08x %08x %08x %08x\n", cpuname,
   1880 			    ef, descs[0], descs[1], descs[2], descs[3]);
   1881 		}
   1882 	}
   1883 
   1884 	cpu_probe_hv_features(ci, cpuname);
   1885 	cpu_probe_features(ci);
   1886 
   1887 	if (ci->ci_cpu_type >= 0) {
   1888 		/* Old pre-cpuid instruction cpu */
   1889 		if (ci->ci_cpu_type >= (int)__arraycount(i386_nocpuid_cpus))
   1890 			errx(1, "unknown cpu type %d", ci->ci_cpu_type);
   1891 		name = i386_nocpuid_cpus[ci->ci_cpu_type].cpu_name;
   1892 		cpu_vendor = i386_nocpuid_cpus[ci->ci_cpu_type].cpu_vendor;
   1893 		vendorname = i386_nocpuid_cpus[ci->ci_cpu_type].cpu_vendorname;
   1894 		class = i386_nocpuid_cpus[ci->ci_cpu_type].cpu_class;
   1895 		ci->ci_info = i386_nocpuid_cpus[ci->ci_cpu_type].cpu_info;
   1896 		modifier = "";
   1897 	} else {
   1898 		/* CPU which support cpuid instruction */
   1899 		modif = (ci->ci_signature >> 12) & 0x3;
   1900 		family = ci->ci_family;
   1901 		if (family < CPU_MINFAMILY)
   1902 			errx(1, "identifycpu: strange family value");
   1903 		if (family > CPU_MAXFAMILY)
   1904 			family = CPU_MAXFAMILY;
   1905 
   1906 		for (i = 0; i < __arraycount(i386_cpuid_cpus); i++) {
   1907 			if (!strncmp((char *)ci->ci_vendor,
   1908 			    i386_cpuid_cpus[i].cpu_id, 12)) {
   1909 				cpup = &i386_cpuid_cpus[i];
   1910 				break;
   1911 			}
   1912 		}
   1913 
   1914 		if (cpup == NULL) {
   1915 			cpu_vendor = CPUVENDOR_UNKNOWN;
   1916 			if (ci->ci_vendor[0] != '\0')
   1917 				vendorname = (char *)&ci->ci_vendor[0];
   1918 			else
   1919 				vendorname = "Unknown";
   1920 			class = family - 3;
   1921 			modifier = "";
   1922 			name = "";
   1923 			ci->ci_info = NULL;
   1924 		} else {
   1925 			cpu_vendor = cpup->cpu_vendor;
   1926 			vendorname = cpup->cpu_vendorname;
   1927 			modifier = modifiers[modif];
   1928 			cpufam = &cpup->cpu_family[family - CPU_MINFAMILY];
   1929 			name = cpufam->cpu_models[ci->ci_model];
   1930 			if (name == NULL || *name == '\0')
   1931 			    name = cpufam->cpu_model_default;
   1932 			class = cpufam->cpu_class;
   1933 			ci->ci_info = cpufam->cpu_info;
   1934 
   1935 			if (cpu_vendor == CPUVENDOR_INTEL) {
   1936 				if (ci->ci_family == 6 && ci->ci_model >= 5) {
   1937 					const char *tmp;
   1938 					tmp = intel_family6_name(ci);
   1939 					if (tmp != NULL)
   1940 						name = tmp;
   1941 				}
   1942 				if (ci->ci_family == 15 &&
   1943 				    ci->ci_brand_id <
   1944 				    __arraycount(i386_intel_brand) &&
   1945 				    i386_intel_brand[ci->ci_brand_id])
   1946 					name =
   1947 					     i386_intel_brand[ci->ci_brand_id];
   1948 			}
   1949 
   1950 			if (cpu_vendor == CPUVENDOR_AMD) {
   1951 				if (ci->ci_family == 6 && ci->ci_model >= 6) {
   1952 					if (ci->ci_brand_id == 1)
   1953 						/*
   1954 						 * It's Duron. We override the
   1955 						 * name, since it might have
   1956 						 * been misidentified as Athlon.
   1957 						 */
   1958 						name =
   1959 						    amd_brand[ci->ci_brand_id];
   1960 					else
   1961 						brand = amd_brand_name;
   1962 				}
   1963 				if (CPUID_TO_BASEFAMILY(ci->ci_signature)
   1964 				    == 0xf) {
   1965 					/* Identify AMD64 CPU names.  */
   1966 					const char *tmp;
   1967 					tmp = amd_amd64_name(ci);
   1968 					if (tmp != NULL)
   1969 						name = tmp;
   1970 				}
   1971 			}
   1972 
   1973 			if (cpu_vendor == CPUVENDOR_IDT && ci->ci_family >= 6)
   1974 				vendorname = "VIA";
   1975 		}
   1976 	}
   1977 
   1978 	ci->ci_cpu_class = class;
   1979 
   1980 	sz = sizeof(ci->ci_tsc_freq);
   1981 	(void)sysctlbyname("machdep.tsc_freq", &ci->ci_tsc_freq, &sz, NULL, 0);
   1982 	sz = sizeof(use_pae);
   1983 	(void)sysctlbyname("machdep.pae", &use_pae, &sz, NULL, 0);
   1984 	largepagesize = (use_pae ? 2 * 1024 * 1024 : 4 * 1024 * 1024);
   1985 
   1986 	/*
   1987 	 * The 'cpu_brand_string' is much more useful than the 'cpu_model'
   1988 	 * we try to determine from the family/model values.
   1989 	 */
   1990 	if (*cpu_brand_string != '\0')
   1991 		aprint_normal("%s: \"%s\"\n", cpuname, cpu_brand_string);
   1992 
   1993 	aprint_normal("%s: %s", cpuname, vendorname);
   1994 	if (*modifier)
   1995 		aprint_normal(" %s", modifier);
   1996 	if (*name)
   1997 		aprint_normal(" %s", name);
   1998 	if (*brand)
   1999 		aprint_normal(" %s", brand);
   2000 	aprint_normal(" (%s-class)", classnames[class]);
   2001 
   2002 	if (ci->ci_tsc_freq != 0)
   2003 		aprint_normal(", %ju.%02ju MHz",
   2004 		    ((uintmax_t)ci->ci_tsc_freq + 4999) / 1000000,
   2005 		    (((uintmax_t)ci->ci_tsc_freq + 4999) / 10000) % 100);
   2006 	aprint_normal("\n");
   2007 
   2008 	aprint_normal_dev(ci->ci_dev, "family %#x model %#x stepping %#x",
   2009 	    ci->ci_family, ci->ci_model, CPUID_TO_STEPPING(ci->ci_signature));
   2010 	if (ci->ci_signature != 0)
   2011 		aprint_normal(" (id %#x)", ci->ci_signature);
   2012 	aprint_normal("\n");
   2013 
   2014 	if (ci->ci_info)
   2015 		(*ci->ci_info)(ci);
   2016 
   2017 	/*
   2018 	 * display CPU feature flags
   2019 	 */
   2020 
   2021 	print_bits(cpuname, "features", CPUID_FLAGS1, ci->ci_feat_val[0]);
   2022 	print_bits(cpuname, "features1", CPUID2_FLAGS1, ci->ci_feat_val[1]);
   2023 
   2024 	/* These next two are actually common definitions! */
   2025 	print_bits(cpuname, "features2",
   2026 	    cpu_vendor == CPUVENDOR_INTEL ? CPUID_INTEL_EXT_FLAGS
   2027 		: CPUID_EXT_FLAGS, ci->ci_feat_val[2]);
   2028 	print_bits(cpuname, "features3",
   2029 	    cpu_vendor == CPUVENDOR_INTEL ? CPUID_INTEL_FLAGS4
   2030 		: CPUID_AMD_FLAGS4, ci->ci_feat_val[3]);
   2031 
   2032 	print_bits(cpuname, "padloack features", CPUID_FLAGS_PADLOCK,
   2033 	    ci->ci_feat_val[4]);
   2034 	if ((cpu_vendor == CPUVENDOR_INTEL) || (cpu_vendor == CPUVENDOR_AMD))
   2035 		print_bits(cpuname, "features5", CPUID_SEF_FLAGS,
   2036 		    ci->ci_feat_val[5]);
   2037 	if (cpu_vendor == CPUVENDOR_INTEL)
   2038 		print_bits(cpuname, "features6", CPUID_SEF_FLAGS1,
   2039 		    ci->ci_feat_val[6]);
   2040 
   2041 	if ((cpu_vendor == CPUVENDOR_INTEL) && (ci->ci_cpuid_level >= 7)) {
   2042 		x86_cpuid(7, descs);
   2043 		print_bits(cpuname, "SEF edx", CPUID_SEF_FLAGS2, descs[3]);
   2044 	}
   2045 
   2046 	print_bits(cpuname, "xsave features", XCR0_FLAGS1, ci->ci_feat_val[7]);
   2047 	print_bits(cpuname, "xsave instructions", CPUID_PES1_FLAGS,
   2048 	    ci->ci_feat_val[8]);
   2049 
   2050 	if (ci->ci_max_xsave != 0) {
   2051 		aprint_normal("%s: xsave area size: current %d, maximum %d",
   2052 			cpuname, ci->ci_cur_xsave, ci->ci_max_xsave);
   2053 		aprint_normal(", xgetbv %sabled\n",
   2054 		    ci->ci_feat_val[1] & CPUID2_OSXSAVE ? "en" : "dis");
   2055 		if (ci->ci_feat_val[1] & CPUID2_OSXSAVE)
   2056 			print_bits(cpuname, "enabled xsave", XCR0_FLAGS1,
   2057 			    x86_xgetbv());
   2058 	}
   2059 
   2060 	x86_print_cache_and_tlb_info(ci);
   2061 
   2062 	if (ci->ci_cpuid_level >= 3 && (ci->ci_feat_val[0] & CPUID_PN)) {
   2063 		aprint_verbose("%s: serial number %04X-%04X-%04X-%04X-%04X-%04X\n",
   2064 		    cpuname,
   2065 		    ci->ci_cpu_serial[0] / 65536, ci->ci_cpu_serial[0] % 65536,
   2066 		    ci->ci_cpu_serial[1] / 65536, ci->ci_cpu_serial[1] % 65536,
   2067 		    ci->ci_cpu_serial[2] / 65536, ci->ci_cpu_serial[2] % 65536);
   2068 	}
   2069 
   2070 	if (ci->ci_cpu_class == CPUCLASS_386)
   2071 		errx(1, "NetBSD requires an 80486 or later processor");
   2072 
   2073 	if (ci->ci_cpu_type == CPU_486DLC) {
   2074 #ifndef CYRIX_CACHE_WORKS
   2075 		aprint_error("WARNING: CYRIX 486DLC CACHE UNCHANGED.\n");
   2076 #else
   2077 #ifndef CYRIX_CACHE_REALLY_WORKS
   2078 		aprint_error("WARNING: CYRIX 486DLC CACHE ENABLED IN HOLD-FLUSH MODE.\n");
   2079 #else
   2080 		aprint_error("WARNING: CYRIX 486DLC CACHE ENABLED.\n");
   2081 #endif
   2082 #endif
   2083 	}
   2084 
   2085 	/*
   2086 	 * Everything past this point requires a Pentium or later.
   2087 	 */
   2088 	if (ci->ci_cpuid_level < 0)
   2089 		return;
   2090 
   2091 	identifycpu_cpuids(ci);
   2092 
   2093 #ifdef INTEL_CORETEMP
   2094 	if (cpu_vendor == CPUVENDOR_INTEL && ci->ci_cpuid_level >= 0x06)
   2095 		coretemp_register(ci);
   2096 #endif
   2097 
   2098 	if (cpu_vendor == CPUVENDOR_AMD) {
   2099 		uint32_t data[4];
   2100 
   2101 		x86_cpuid(0x80000000, data);
   2102 		if (data[0] >= 0x80000007)
   2103 			powernow_probe(ci);
   2104 
   2105 		if ((data[0] >= 0x8000000a)
   2106 		   && (ci->ci_feat_val[3] & CPUID_SVM) != 0) {
   2107 			x86_cpuid(0x8000000a, data);
   2108 			aprint_verbose("%s: SVM Rev. %d\n", cpuname,
   2109 			    data[0] & 0xf);
   2110 			aprint_verbose("%s: SVM NASID %d\n", cpuname, data[1]);
   2111 			print_bits(cpuname, "SVM features", CPUID_AMD_SVM_FLAGS,
   2112 				   data[3]);
   2113 		}
   2114 	} else if (cpu_vendor == CPUVENDOR_INTEL) {
   2115 		uint32_t data[4];
   2116 		int32_t bi_index;
   2117 
   2118 		for (bi_index = 1; bi_index <= ci->ci_cpuid_level; bi_index++) {
   2119 			x86_cpuid(bi_index, data);
   2120 			switch (bi_index) {
   2121 			case 6:
   2122 				print_bits(cpuname, "DSPM-eax",
   2123 				    CPUID_DSPM_FLAGS, data[0]);
   2124 				print_bits(cpuname, "DSPM-ecx",
   2125 				    CPUID_DSPM_FLAGS1, data[2]);
   2126 				break;
   2127 			case 7:
   2128 				aprint_verbose("%s: SEF highest subleaf %08x\n",
   2129 				    cpuname, data[0]);
   2130 				break;
   2131 #if 0
   2132 			default:
   2133 				aprint_verbose("%s: basic %08x-eax %08x\n",
   2134 				    cpuname, bi_index, data[0]);
   2135 				aprint_verbose("%s: basic %08x-ebx %08x\n",
   2136 				    cpuname, bi_index, data[1]);
   2137 				aprint_verbose("%s: basic %08x-ecx %08x\n",
   2138 				    cpuname, bi_index, data[2]);
   2139 				aprint_verbose("%s: basic %08x-edx %08x\n",
   2140 				    cpuname, bi_index, data[3]);
   2141 				break;
   2142 #endif
   2143 			}
   2144 		}
   2145 	}
   2146 
   2147 #ifdef INTEL_ONDEMAND_CLOCKMOD
   2148 	clockmod_init();
   2149 #endif
   2150 
   2151 	if (cpu_vendor == CPUVENDOR_AMD)
   2152 		ucode.loader_version = CPU_UCODE_LOADER_AMD;
   2153 	else if (cpu_vendor == CPUVENDOR_INTEL)
   2154 		ucode.loader_version = CPU_UCODE_LOADER_INTEL1;
   2155 	else
   2156 		return;
   2157 
   2158 	ucode.data = &ucvers;
   2159 	if (ioctl(fd, IOC_CPU_UCODE_GET_VERSION, &ucode) < 0) {
   2160 #ifdef __i386__
   2161 		struct cpu_ucode_version_64 ucode_64;
   2162 		if (errno != ENOTTY)
   2163 			return;
   2164 		/* Try the 64 bit ioctl */
   2165 		memset(&ucode_64, 0, sizeof ucode_64);
   2166 		ucode_64.data = &ucvers;
   2167 		ucode_64.loader_version = ucode.loader_version;
   2168 		if (ioctl(fd, IOC_CPU_UCODE_GET_VERSION_64, &ucode_64) < 0)
   2169 			return;
   2170 #else
   2171 		return;
   2172 #endif
   2173 	}
   2174 
   2175 	if (cpu_vendor == CPUVENDOR_AMD)
   2176 		printf("%s: UCode version: 0x%"PRIx64"\n", cpuname, ucvers.amd.version);
   2177 	else if (cpu_vendor == CPUVENDOR_INTEL)
   2178 		printf("%s: microcode version 0x%x, platform ID %d\n", cpuname,
   2179 		       ucvers.intel1.ucodeversion, ucvers.intel1.platformid);
   2180 }
   2181 
   2182 static const struct x86_cache_info *
   2183 cache_info_lookup(const struct x86_cache_info *cai, uint8_t desc)
   2184 {
   2185 	int i;
   2186 
   2187 	for (i = 0; cai[i].cai_desc != 0; i++) {
   2188 		if (cai[i].cai_desc == desc)
   2189 			return (&cai[i]);
   2190 	}
   2191 
   2192 	return (NULL);
   2193 }
   2194 
   2195 static const char *
   2196 print_cache_config(struct cpu_info *ci, int cache_tag, const char *name,
   2197     const char *sep)
   2198 {
   2199 	struct x86_cache_info *cai = &ci->ci_cinfo[cache_tag];
   2200 	char human_num[HUMAN_BUFSIZE];
   2201 
   2202 	if (cai->cai_totalsize == 0)
   2203 		return sep;
   2204 
   2205 	if (sep == NULL)
   2206 		aprint_verbose_dev(ci->ci_dev, "");
   2207 	else
   2208 		aprint_verbose("%s", sep);
   2209 	if (name != NULL)
   2210 		aprint_verbose("%s ", name);
   2211 
   2212 	if (cai->cai_string != NULL) {
   2213 		aprint_verbose("%s ", cai->cai_string);
   2214 	} else {
   2215 		(void)humanize_number(human_num, sizeof(human_num),
   2216 			cai->cai_totalsize, "B", HN_AUTOSCALE, HN_NOSPACE);
   2217 		aprint_verbose("%s %dB/line ", human_num, cai->cai_linesize);
   2218 	}
   2219 	switch (cai->cai_associativity) {
   2220 	case    0:
   2221 		aprint_verbose("disabled");
   2222 		break;
   2223 	case    1:
   2224 		aprint_verbose("direct-mapped");
   2225 		break;
   2226 	case 0xff:
   2227 		aprint_verbose("fully associative");
   2228 		break;
   2229 	default:
   2230 		aprint_verbose("%d-way", cai->cai_associativity);
   2231 		break;
   2232 	}
   2233 	return ", ";
   2234 }
   2235 
   2236 static const char *
   2237 print_tlb_config(struct cpu_info *ci, int cache_tag, const char *name,
   2238     const char *sep)
   2239 {
   2240 	struct x86_cache_info *cai = &ci->ci_cinfo[cache_tag];
   2241 	char human_num[HUMAN_BUFSIZE];
   2242 
   2243 	if (cai->cai_totalsize == 0)
   2244 		return sep;
   2245 
   2246 	if (sep == NULL)
   2247 		aprint_verbose_dev(ci->ci_dev, "");
   2248 	else
   2249 		aprint_verbose("%s", sep);
   2250 	if (name != NULL)
   2251 		aprint_verbose("%s ", name);
   2252 
   2253 	if (cai->cai_string != NULL) {
   2254 		aprint_verbose("%s", cai->cai_string);
   2255 	} else {
   2256 		(void)humanize_number(human_num, sizeof(human_num),
   2257 			cai->cai_linesize, "B", HN_AUTOSCALE, HN_NOSPACE);
   2258 		aprint_verbose("%d %s entries ", cai->cai_totalsize,
   2259 		    human_num);
   2260 		switch (cai->cai_associativity) {
   2261 		case 0:
   2262 			aprint_verbose("disabled");
   2263 			break;
   2264 		case 1:
   2265 			aprint_verbose("direct-mapped");
   2266 			break;
   2267 		case 0xff:
   2268 			aprint_verbose("fully associative");
   2269 			break;
   2270 		default:
   2271 			aprint_verbose("%d-way", cai->cai_associativity);
   2272 			break;
   2273 		}
   2274 	}
   2275 	return ", ";
   2276 }
   2277 
   2278 static void
   2279 x86_print_cache_and_tlb_info(struct cpu_info *ci)
   2280 {
   2281 	const char *sep = NULL;
   2282 
   2283 	if (ci->ci_cinfo[CAI_ICACHE].cai_totalsize != 0 ||
   2284 	    ci->ci_cinfo[CAI_DCACHE].cai_totalsize != 0) {
   2285 		sep = print_cache_config(ci, CAI_ICACHE, "I-cache", NULL);
   2286 		sep = print_cache_config(ci, CAI_DCACHE, "D-cache", sep);
   2287 		if (sep != NULL)
   2288 			aprint_verbose("\n");
   2289 	}
   2290 	if (ci->ci_cinfo[CAI_L2CACHE].cai_totalsize != 0) {
   2291 		sep = print_cache_config(ci, CAI_L2CACHE, "L2 cache", NULL);
   2292 		if (sep != NULL)
   2293 			aprint_verbose("\n");
   2294 	}
   2295 	if (ci->ci_cinfo[CAI_L3CACHE].cai_totalsize != 0) {
   2296 		sep = print_cache_config(ci, CAI_L3CACHE, "L3 cache", NULL);
   2297 		if (sep != NULL)
   2298 			aprint_verbose("\n");
   2299 	}
   2300 	if (ci->ci_cinfo[CAI_PREFETCH].cai_linesize != 0) {
   2301 		aprint_verbose_dev(ci->ci_dev, "%dB prefetching",
   2302 			ci->ci_cinfo[CAI_PREFETCH].cai_linesize);
   2303 		if (sep != NULL)
   2304 			aprint_verbose("\n");
   2305 	}
   2306 	if (ci->ci_cinfo[CAI_ITLB].cai_totalsize != 0) {
   2307 		sep = print_tlb_config(ci, CAI_ITLB, "ITLB", NULL);
   2308 		sep = print_tlb_config(ci, CAI_ITLB2, NULL, sep);
   2309 		if (sep != NULL)
   2310 			aprint_verbose("\n");
   2311 	}
   2312 	if (ci->ci_cinfo[CAI_DTLB].cai_totalsize != 0) {
   2313 		sep = print_tlb_config(ci, CAI_DTLB, "DTLB", NULL);
   2314 		sep = print_tlb_config(ci, CAI_DTLB2, NULL, sep);
   2315 		if (sep != NULL)
   2316 			aprint_verbose("\n");
   2317 	}
   2318 	if (ci->ci_cinfo[CAI_L2_ITLB].cai_totalsize != 0) {
   2319 		sep = print_tlb_config(ci, CAI_L2_ITLB, "L2 ITLB", NULL);
   2320 		sep = print_tlb_config(ci, CAI_L2_ITLB2, NULL, sep);
   2321 		if (sep != NULL)
   2322 			aprint_verbose("\n");
   2323 	}
   2324 	if (ci->ci_cinfo[CAI_L2_DTLB].cai_totalsize != 0) {
   2325 		sep = print_tlb_config(ci, CAI_L2_DTLB, "L2 DTLB", NULL);
   2326 		sep = print_tlb_config(ci, CAI_L2_DTLB2, NULL, sep);
   2327 		if (sep != NULL)
   2328 			aprint_verbose("\n");
   2329 	}
   2330 	if (ci->ci_cinfo[CAI_L2_STLB].cai_totalsize != 0) {
   2331 		sep = print_tlb_config(ci, CAI_L2_STLB, "L2 STLB", NULL);
   2332 		sep = print_tlb_config(ci, CAI_L2_STLB2, NULL, sep);
   2333 		sep = print_tlb_config(ci, CAI_L2_STLB3, NULL, sep);
   2334 		if (sep != NULL)
   2335 			aprint_verbose("\n");
   2336 	}
   2337 	if (ci->ci_cinfo[CAI_L1_1GBITLB].cai_totalsize != 0) {
   2338 		sep = print_tlb_config(ci, CAI_L1_1GBITLB, "L1 1GB page ITLB",
   2339 		    NULL);
   2340 		if (sep != NULL)
   2341 			aprint_verbose("\n");
   2342 	}
   2343 	if (ci->ci_cinfo[CAI_L1_1GBDTLB].cai_totalsize != 0) {
   2344 		sep = print_tlb_config(ci, CAI_L1_1GBDTLB, "L1 1GB page DTLB",
   2345 		    NULL);
   2346 		if (sep != NULL)
   2347 			aprint_verbose("\n");
   2348 	}
   2349 	if (ci->ci_cinfo[CAI_L2_1GBITLB].cai_totalsize != 0) {
   2350 		sep = print_tlb_config(ci, CAI_L2_1GBITLB, "L2 1GB page ITLB",
   2351 		    NULL);
   2352 		if (sep != NULL)
   2353 			aprint_verbose("\n");
   2354 	}
   2355 	if (ci->ci_cinfo[CAI_L2_1GBDTLB].cai_totalsize != 0) {
   2356 		sep = print_tlb_config(ci, CAI_L2_1GBDTLB, "L2 1GB page DTLB",
   2357 		    NULL);
   2358 		if (sep != NULL)
   2359 			aprint_verbose("\n");
   2360 	}
   2361 }
   2362 
   2363 static void
   2364 powernow_probe(struct cpu_info *ci)
   2365 {
   2366 	uint32_t regs[4];
   2367 	char buf[256];
   2368 
   2369 	x86_cpuid(0x80000007, regs);
   2370 
   2371 	snprintb(buf, sizeof(buf), CPUID_APM_FLAGS, regs[3]);
   2372 	aprint_normal_dev(ci->ci_dev, "AMD Power Management features: %s\n",
   2373 	    buf);
   2374 }
   2375 
   2376 bool
   2377 identifycpu_bind(void)
   2378 {
   2379 
   2380 	return true;
   2381 }
   2382 
   2383 int
   2384 ucodeupdate_check(int fd, struct cpu_ucode *uc)
   2385 {
   2386 	struct cpu_info ci;
   2387 	int loader_version, res;
   2388 	struct cpu_ucode_version versreq;
   2389 
   2390 	cpu_probe_base_features(&ci, "unknown");
   2391 
   2392 	if (!strcmp((char *)ci.ci_vendor, "AuthenticAMD"))
   2393 		loader_version = CPU_UCODE_LOADER_AMD;
   2394 	else if (!strcmp((char *)ci.ci_vendor, "GenuineIntel"))
   2395 		loader_version = CPU_UCODE_LOADER_INTEL1;
   2396 	else
   2397 		return -1;
   2398 
   2399 	/* check whether the kernel understands this loader version */
   2400 	versreq.loader_version = loader_version;
   2401 	versreq.data = 0;
   2402 	res = ioctl(fd, IOC_CPU_UCODE_GET_VERSION, &versreq);
   2403 	if (res)
   2404 		return -1;
   2405 
   2406 	switch (loader_version) {
   2407 	case CPU_UCODE_LOADER_AMD:
   2408 		if (uc->cpu_nr != -1) {
   2409 			/* printf? */
   2410 			return -1;
   2411 		}
   2412 		uc->cpu_nr = CPU_UCODE_ALL_CPUS;
   2413 		break;
   2414 	case CPU_UCODE_LOADER_INTEL1:
   2415 		if (uc->cpu_nr == -1)
   2416 			uc->cpu_nr = CPU_UCODE_ALL_CPUS; /* for Xen */
   2417 		else
   2418 			uc->cpu_nr = CPU_UCODE_CURRENT_CPU;
   2419 		break;
   2420 	default: /* can't happen */
   2421 		return -1;
   2422 	}
   2423 	uc->loader_version = loader_version;
   2424 	return 0;
   2425 }
   2426