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