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