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