Mon Jan 26 14:02:40 2015 UTC ()
Pull up the following, requested by msaitoh in ticket #1241:

	sys/arch/x86/x86/identcpu.c			1.35-1.39

- Check cpuid leaf 4 for newer Intel CPU to know the cache information.
  This code might improve performance because it changes the number of
  page colors.
- Fix calculation of the cpu model (display model) in
  cpu_probe_amd_cache().
- CPUID leaf 2 and 4 are only for Intel processors.


(martin)
diff -r1.29.2.2 -r1.29.2.3 src/sys/arch/x86/x86/identcpu.c

cvs diff -r1.29.2.2 -r1.29.2.3 src/sys/arch/x86/x86/identcpu.c (expand / switch to unified diff)

--- src/sys/arch/x86/x86/identcpu.c 2012/05/07 16:37:19 1.29.2.2
+++ src/sys/arch/x86/x86/identcpu.c 2015/01/26 14:02:40 1.29.2.3
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: identcpu.c,v 1.29.2.2 2012/05/07 16:37:19 riz Exp $ */ 1/* $NetBSD: identcpu.c,v 1.29.2.3 2015/01/26 14:02:40 martin Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1999, 2000, 2001, 2006, 2007, 2008 The NetBSD Foundation, Inc. 4 * Copyright (c) 1999, 2000, 2001, 2006, 2007, 2008 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Frank van der Linden, and by Jason R. Thorpe. 8 * by Frank van der Linden, and by Jason R. Thorpe.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -20,27 +20,27 @@ @@ -20,27 +20,27 @@
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33__KERNEL_RCSID(0, "$NetBSD: identcpu.c,v 1.29.2.2 2012/05/07 16:37:19 riz Exp $"); 33__KERNEL_RCSID(0, "$NetBSD: identcpu.c,v 1.29.2.3 2015/01/26 14:02:40 martin Exp $");
34 34
35#include "opt_xen.h" 35#include "opt_xen.h"
36 36
37#include <sys/param.h> 37#include <sys/param.h>
38#include <sys/systm.h> 38#include <sys/systm.h>
39#include <sys/device.h> 39#include <sys/device.h>
40 40
41#include <uvm/uvm_extern.h> 41#include <uvm/uvm_extern.h>
42 42
43#include <machine/specialreg.h> 43#include <machine/specialreg.h>
44#include <machine/pio.h> 44#include <machine/pio.h>
45#include <machine/cpu.h> 45#include <machine/cpu.h>
46 46
@@ -87,54 +87,143 @@ static const char cpu_vendor_names[][10] @@ -87,54 +87,143 @@ static const char cpu_vendor_names[][10]
87static const struct x86_cache_info * 87static const struct x86_cache_info *
88cache_info_lookup(const struct x86_cache_info *cai, uint8_t desc) 88cache_info_lookup(const struct x86_cache_info *cai, uint8_t desc)
89{ 89{
90 int i; 90 int i;
91 91
92 for (i = 0; cai[i].cai_desc != 0; i++) { 92 for (i = 0; cai[i].cai_desc != 0; i++) {
93 if (cai[i].cai_desc == desc) 93 if (cai[i].cai_desc == desc)
94 return (&cai[i]); 94 return (&cai[i]);
95 } 95 }
96 96
97 return (NULL); 97 return (NULL);
98} 98}
99 99
 100static void
 101cpu_probe_intel_cache(struct cpu_info *ci)
 102{
 103 const struct x86_cache_info *cai;
 104 u_int descs[4];
 105 int iterations, i, j;
 106 uint8_t desc;
 107
 108 if (cpuid_level >= 2) {
 109 /* Parse the cache info from `cpuid leaf 2', if we have it. */
 110 x86_cpuid(2, descs);
 111 iterations = descs[0] & 0xff;
 112 while (iterations-- > 0) {
 113 for (i = 0; i < 4; i++) {
 114 if (descs[i] & 0x80000000)
 115 continue;
 116 for (j = 0; j < 4; j++) {
 117 if (i == 0 && j == 0)
 118 continue;
 119 desc = (descs[i] >> (j * 8)) & 0xff;
 120 if (desc == 0)
 121 continue;
 122 cai = cache_info_lookup(
 123 intel_cpuid_cache_info, desc);
 124 if (cai != NULL) {
 125 ci->ci_cinfo[cai->cai_index] =
 126 *cai;
 127 }
 128 }
 129 }
 130 }
 131 }
 132
 133 if (cpuid_level >= 4) {
 134 int type, level;
 135 int ways, partitions, linesize, sets;
 136 int caitype = -1;
 137 int totalsize;
 138
 139 /* Parse the cache info from `cpuid leaf 4', if we have it. */
 140 for (i = 0; ; i++) {
 141 x86_cpuid2(4, i, descs);
 142 type = __SHIFTOUT(descs[0], CPUID_DCP_CACHETYPE);
 143 if (type == CPUID_DCP_CACHETYPE_N)
 144 break;
 145 level = __SHIFTOUT(descs[0], CPUID_DCP_CACHELEVEL);
 146 switch (level) {
 147 case 1:
 148 if (type == CPUID_DCP_CACHETYPE_I)
 149 caitype = CAI_ICACHE;
 150 else if (type == CPUID_DCP_CACHETYPE_D)
 151 caitype = CAI_DCACHE;
 152 else
 153 caitype = -1;
 154 break;
 155 case 2:
 156 if (type == CPUID_DCP_CACHETYPE_U)
 157 caitype = CAI_L2CACHE;
 158 else
 159 caitype = -1;
 160 break;
 161 case 3:
 162 if (type == CPUID_DCP_CACHETYPE_U)
 163 caitype = CAI_L3CACHE;
 164 else
 165 caitype = -1;
 166 break;
 167 default:
 168 caitype = -1;
 169 break;
 170 }
 171 if (caitype == -1)
 172 continue;
 173
 174 ways = __SHIFTOUT(descs[1], CPUID_DCP_WAYS) + 1;
 175 partitions =__SHIFTOUT(descs[1], CPUID_DCP_PARTITIONS)
 176 + 1;
 177 linesize = __SHIFTOUT(descs[1], CPUID_DCP_LINESIZE)
 178 + 1;
 179 sets = descs[2] + 1;
 180 totalsize = ways * partitions * linesize * sets;
 181 ci->ci_cinfo[caitype].cai_totalsize = totalsize;
 182 ci->ci_cinfo[caitype].cai_associativity = ways;
 183 ci->ci_cinfo[caitype].cai_linesize = linesize;
 184 }
 185 }
 186}
 187
 188static void
 189cpu_probe_intel(struct cpu_info *ci)
 190{
 191
 192 if (cpu_vendor != CPUVENDOR_INTEL)
 193 return;
 194
 195 cpu_probe_intel_cache(ci);
 196}
100 197
101static void 198static void
102cpu_probe_amd_cache(struct cpu_info *ci) 199cpu_probe_amd_cache(struct cpu_info *ci)
103{ 200{
104 const struct x86_cache_info *cp; 201 const struct x86_cache_info *cp;
105 struct x86_cache_info *cai; 202 struct x86_cache_info *cai;
106 int family, model; 203 int family, model;
107 u_int descs[4]; 204 u_int descs[4];
108 u_int lfunc; 205 u_int lfunc;
109 206
110 family = CPUID2FAMILY(ci->ci_signature); 207 family = CPUID_TO_FAMILY(ci->ci_signature);
111 model = CPUID2MODEL(ci->ci_signature); 208 model = CPUID_TO_MODEL(ci->ci_signature);
112 209
113 /* 210 /*
114 * K5 model 0 has none of this info. 211 * K5 model 0 has none of this info.
115 */ 212 */
116 if (family == 5 && model == 0) 213 if (family == 5 && model == 0)
117 return; 214 return;
118 215
119 /* 216 /*
120 * Get extended values for K8 and up. 
121 */ 
122 if (family == 0xf) { 
123 family += CPUID2EXTFAMILY(ci->ci_signature); 
124 model += CPUID2EXTMODEL(ci->ci_signature); 
125 } 
126 
127 /* 
128 * Determine the largest extended function value. 217 * Determine the largest extended function value.
129 */ 218 */
130 x86_cpuid(0x80000000, descs); 219 x86_cpuid(0x80000000, descs);
131 lfunc = descs[0]; 220 lfunc = descs[0];
132 221
133 /* 222 /*
134 * Determine L1 cache/TLB info. 223 * Determine L1 cache/TLB info.
135 */ 224 */
136 if (lfunc < 0x80000005) { 225 if (lfunc < 0x80000005) {
137 /* No L1 cache info available. */ 226 /* No L1 cache info available. */
138 return; 227 return;
139 } 228 }
140 229
@@ -238,52 +327,52 @@ cpu_probe_amd_cache(struct cpu_info *ci) @@ -238,52 +327,52 @@ cpu_probe_amd_cache(struct cpu_info *ci)
238 327
239 cai = &ci->ci_cinfo[CAI_L2_1GBITLB]; 328 cai = &ci->ci_cinfo[CAI_L2_1GBITLB];
240 cai->cai_totalsize = AMD_L2_1GB_EBX_IUTLB_ENTRIES(descs[0]); 329 cai->cai_totalsize = AMD_L2_1GB_EBX_IUTLB_ENTRIES(descs[0]);
241 cai->cai_associativity = AMD_L2_1GB_EBX_IUTLB_ASSOC(descs[0]); 330 cai->cai_associativity = AMD_L2_1GB_EBX_IUTLB_ASSOC(descs[0]);
242 cai->cai_linesize = (1 * 1024); 331 cai->cai_linesize = (1 * 1024);
243} 332}
244 333
245static void 334static void
246cpu_probe_k5(struct cpu_info *ci) 335cpu_probe_k5(struct cpu_info *ci)
247{ 336{
248 int flag; 337 int flag;
249 338
250 if (cpu_vendor != CPUVENDOR_AMD || 339 if (cpu_vendor != CPUVENDOR_AMD ||
251 CPUID2FAMILY(ci->ci_signature) != 5) 340 CPUID_TO_FAMILY(ci->ci_signature) != 5)
252 return; 341 return;
253 342
254 if (CPUID2MODEL(ci->ci_signature) == 0) { 343 if (CPUID_TO_MODEL(ci->ci_signature) == 0) {
255 /* 344 /*
256 * According to the AMD Processor Recognition App Note, 345 * According to the AMD Processor Recognition App Note,
257 * the AMD-K5 Model 0 uses the wrong bit to indicate 346 * the AMD-K5 Model 0 uses the wrong bit to indicate
258 * support for global PTEs, instead using bit 9 (APIC) 347 * support for global PTEs, instead using bit 9 (APIC)
259 * rather than bit 13 (i.e. "0x200" vs. 0x2000". Oops!). 348 * rather than bit 13 (i.e. "0x200" vs. 0x2000". Oops!).
260 */ 349 */
261 flag = ci->ci_feat_val[0]; 350 flag = ci->ci_feat_val[0];
262 if ((flag & CPUID_APIC) != 0) 351 if ((flag & CPUID_APIC) != 0)
263 flag = (flag & ~CPUID_APIC) | CPUID_PGE; 352 flag = (flag & ~CPUID_APIC) | CPUID_PGE;
264 ci->ci_feat_val[0] = flag; 353 ci->ci_feat_val[0] = flag;
265 } 354 }
266 355
267 cpu_probe_amd_cache(ci); 356 cpu_probe_amd_cache(ci);
268} 357}
269 358
270static void 359static void
271cpu_probe_k678(struct cpu_info *ci) 360cpu_probe_k678(struct cpu_info *ci)
272{ 361{
273 uint32_t descs[4]; 362 uint32_t descs[4];
274 363
275 if (cpu_vendor != CPUVENDOR_AMD || 364 if (cpu_vendor != CPUVENDOR_AMD ||
276 CPUID2FAMILY(ci->ci_signature) < 6) 365 CPUID_TO_FAMILY(ci->ci_signature) < 6)
277 return; 366 return;
278 367
279 /* Determine the extended feature flags. */ 368 /* Determine the extended feature flags. */
280 x86_cpuid(0x80000000, descs); 369 x86_cpuid(0x80000000, descs);
281 if (descs[0] >= 0x80000001) { 370 if (descs[0] >= 0x80000001) {
282 x86_cpuid(0x80000001, descs); 371 x86_cpuid(0x80000001, descs);
283 ci->ci_feat_val[3] = descs[2]; /* %ecx */ 372 ci->ci_feat_val[3] = descs[2]; /* %ecx */
284 ci->ci_feat_val[2] = descs[3]; /* %edx */ 373 ci->ci_feat_val[2] = descs[3]; /* %edx */
285 } 374 }
286 375
287 cpu_probe_amd_cache(ci); 376 cpu_probe_amd_cache(ci);
288} 377}
289 378
@@ -359,44 +448,44 @@ cpu_probe_cyrix_cmn(struct cpu_info *ci) @@ -359,44 +448,44 @@ cpu_probe_cyrix_cmn(struct cpu_info *ci)
359 cyrix_write_reg(0x31, cyrix_read_reg(0x31) | 0xf8); 448 cyrix_write_reg(0x31, cyrix_read_reg(0x31) | 0xf8);
360 cyrix_write_reg(0x32, cyrix_read_reg(0x32) | 0x7f); 449 cyrix_write_reg(0x32, cyrix_read_reg(0x32) | 0x7f);
361 cyrix_write_reg(0x33, cyrix_read_reg(0x33) & ~0xff); 450 cyrix_write_reg(0x33, cyrix_read_reg(0x33) & ~0xff);
362 cyrix_write_reg(0x3c, cyrix_read_reg(0x3c) | 0x87); 451 cyrix_write_reg(0x3c, cyrix_read_reg(0x3c) | 0x87);
363 /* disable access to ccr4/ccr5 */ 452 /* disable access to ccr4/ccr5 */
364 cyrix_write_reg(0xC3, c3); 453 cyrix_write_reg(0xC3, c3);
365} 454}
366 455
367static void 456static void
368cpu_probe_cyrix(struct cpu_info *ci) 457cpu_probe_cyrix(struct cpu_info *ci)
369{ 458{
370 459
371 if (cpu_vendor != CPUVENDOR_CYRIX || 460 if (cpu_vendor != CPUVENDOR_CYRIX ||
372 CPUID2FAMILY(ci->ci_signature) < 4 || 461 CPUID_TO_FAMILY(ci->ci_signature) < 4 ||
373 CPUID2FAMILY(ci->ci_signature) > 6) 462 CPUID_TO_FAMILY(ci->ci_signature) > 6)
374 return; 463 return;
375 464
376 cpu_probe_cyrix_cmn(ci); 465 cpu_probe_cyrix_cmn(ci);
377} 466}
378 467
379static void 468static void
380cpu_probe_winchip(struct cpu_info *ci) 469cpu_probe_winchip(struct cpu_info *ci)
381{ 470{
382 471
383 if (cpu_vendor != CPUVENDOR_IDT) 472 if (cpu_vendor != CPUVENDOR_IDT)
384 return; 473 return;
385 474
386 switch (CPUID2FAMILY(ci->ci_signature)) { 475 switch (CPUID_TO_FAMILY(ci->ci_signature)) {
387 case 5: 476 case 5:
388 /* WinChip C6 */ 477 /* WinChip C6 */
389 if (CPUID2MODEL(ci->ci_signature) == 4) 478 if (CPUID_TO_MODEL(ci->ci_signature) == 4)
390 ci->ci_feat_val[0] &= ~CPUID_TSC; 479 ci->ci_feat_val[0] &= ~CPUID_TSC;
391 break; 480 break;
392 case 6: 481 case 6:
393 /* 482 /*
394 * VIA Eden ESP  483 * VIA Eden ESP
395 * 484 *
396 * Quoting from page 3-4 of: "VIA Eden ESP Processor Datasheet" 485 * Quoting from page 3-4 of: "VIA Eden ESP Processor Datasheet"
397 * http://www.via.com.tw/download/mainboards/6/14/Eden20v115.pdf 486 * http://www.via.com.tw/download/mainboards/6/14/Eden20v115.pdf
398 *  487 *
399 * 1. The CMPXCHG8B instruction is provided and always enabled, 488 * 1. The CMPXCHG8B instruction is provided and always enabled,
400 * however, it appears disabled in the corresponding CPUID 489 * however, it appears disabled in the corresponding CPUID
401 * function bit 0 to avoid a bug in an early version of 490 * function bit 0 to avoid a bug in an early version of
402 * Windows NT. However, this default can be changed via a 491 * Windows NT. However, this default can be changed via a
@@ -405,32 +494,32 @@ cpu_probe_winchip(struct cpu_info *ci) @@ -405,32 +494,32 @@ cpu_probe_winchip(struct cpu_info *ci)
405 ci->ci_feat_val[0] |= CPUID_CX8; 494 ci->ci_feat_val[0] |= CPUID_CX8;
406 wrmsr(MSR_VIA_FCR, rdmsr(MSR_VIA_FCR) | 0x00000001); 495 wrmsr(MSR_VIA_FCR, rdmsr(MSR_VIA_FCR) | 0x00000001);
407 break; 496 break;
408 } 497 }
409} 498}
410 499
411static void 500static void
412cpu_probe_c3(struct cpu_info *ci) 501cpu_probe_c3(struct cpu_info *ci)
413{ 502{
414 u_int family, model, stepping, descs[4], lfunc, msr; 503 u_int family, model, stepping, descs[4], lfunc, msr;
415 struct x86_cache_info *cai; 504 struct x86_cache_info *cai;
416 505
417 if (cpu_vendor != CPUVENDOR_IDT || 506 if (cpu_vendor != CPUVENDOR_IDT ||
418 CPUID2FAMILY(ci->ci_signature) < 6) 507 CPUID_TO_FAMILY(ci->ci_signature) < 6)
419 return; 508 return;
420 509
421 family = CPUID2FAMILY(ci->ci_signature); 510 family = CPUID_TO_FAMILY(ci->ci_signature);
422 model = CPUID2MODEL(ci->ci_signature); 511 model = CPUID_TO_MODEL(ci->ci_signature);
423 stepping = CPUID2STEPPING(ci->ci_signature); 512 stepping = CPUID_TO_STEPPING(ci->ci_signature);
424 513
425 /* Determine the largest extended function value. */ 514 /* Determine the largest extended function value. */
426 x86_cpuid(0x80000000, descs); 515 x86_cpuid(0x80000000, descs);
427 lfunc = descs[0]; 516 lfunc = descs[0];
428 517
429 /* Determine the extended feature flags. */ 518 /* Determine the extended feature flags. */
430 if (lfunc >= 0x80000001) { 519 if (lfunc >= 0x80000001) {
431 x86_cpuid(0x80000001, descs); 520 x86_cpuid(0x80000001, descs);
432 ci->ci_feat_val[2] = descs[3]; 521 ci->ci_feat_val[2] = descs[3];
433 } 522 }
434 523
435 if (family > 6 || model > 0x9 || (model == 0x9 && stepping >= 3)) { 524 if (family > 6 || model > 0x9 || (model == 0x9 && stepping >= 3)) {
436 /* Nehemiah or Esther */ 525 /* Nehemiah or Esther */
@@ -545,27 +634,27 @@ cpu_probe_c3(struct cpu_info *ci) @@ -545,27 +634,27 @@ cpu_probe_c3(struct cpu_info *ci)
545 cai->cai_linesize = VIA_L2N_ECX_C_LS(descs[2]); 634 cai->cai_linesize = VIA_L2N_ECX_C_LS(descs[2]);
546 } else { 635 } else {
547 cai->cai_totalsize = VIA_L2_ECX_C_SIZE(descs[2]); 636 cai->cai_totalsize = VIA_L2_ECX_C_SIZE(descs[2]);
548 cai->cai_associativity = VIA_L2_ECX_C_ASSOC(descs[2]); 637 cai->cai_associativity = VIA_L2_ECX_C_ASSOC(descs[2]);
549 cai->cai_linesize = VIA_L2_ECX_C_LS(descs[2]); 638 cai->cai_linesize = VIA_L2_ECX_C_LS(descs[2]);
550 } 639 }
551} 640}
552 641
553static void 642static void
554cpu_probe_geode(struct cpu_info *ci) 643cpu_probe_geode(struct cpu_info *ci)
555{ 644{
556 645
557 if (memcmp("Geode by NSC", ci->ci_vendor, 12) != 0 || 646 if (memcmp("Geode by NSC", ci->ci_vendor, 12) != 0 ||
558 CPUID2FAMILY(ci->ci_signature) != 5) 647 CPUID_TO_FAMILY(ci->ci_signature) != 5)
559 return; 648 return;
560 649
561 cpu_probe_cyrix_cmn(ci); 650 cpu_probe_cyrix_cmn(ci);
562 cpu_probe_amd_cache(ci); 651 cpu_probe_amd_cache(ci);
563} 652}
564 653
565static void 654static void
566cpu_probe_vortex86(struct cpu_info *ci) 655cpu_probe_vortex86(struct cpu_info *ci)
567{ 656{
568#define PCI_MODE1_ADDRESS_REG 0x0cf8 657#define PCI_MODE1_ADDRESS_REG 0x0cf8
569#define PCI_MODE1_DATA_REG 0x0cfc 658#define PCI_MODE1_DATA_REG 0x0cfc
570#define PCI_MODE1_ENABLE 0x80000000UL 659#define PCI_MODE1_ENABLE 0x80000000UL
571 660
@@ -596,30 +685,28 @@ cpu_probe_vortex86(struct cpu_info *ci) @@ -596,30 +685,28 @@ cpu_probe_vortex86(struct cpu_info *ci)
596 default: 685 default:
597 strcpy(cpu_brand_string, "Unknown Vortex86"); 686 strcpy(cpu_brand_string, "Unknown Vortex86");
598 break; 687 break;
599 } 688 }
600 689
601#undef PCI_MODE1_ENABLE 690#undef PCI_MODE1_ENABLE
602#undef PCI_MODE1_ADDRESS_REG 691#undef PCI_MODE1_ADDRESS_REG
603#undef PCI_MODE1_DATA_REG 692#undef PCI_MODE1_DATA_REG
604} 693}
605 694
606void 695void
607cpu_probe(struct cpu_info *ci) 696cpu_probe(struct cpu_info *ci)
608{ 697{
609 const struct x86_cache_info *cai; 
610 u_int descs[4]; 698 u_int descs[4];
611 int iterations, i, j; 699 int i;
612 uint8_t desc; 
613 uint32_t miscbytes; 700 uint32_t miscbytes;
614 uint32_t brand[12]; 701 uint32_t brand[12];
615 702
616 cpu_vendor = i386_nocpuid_cpus[cpu << 1]; 703 cpu_vendor = i386_nocpuid_cpus[cpu << 1];
617 cpu_class = i386_nocpuid_cpus[(cpu << 1) + 1]; 704 cpu_class = i386_nocpuid_cpus[(cpu << 1) + 1];
618 705
619 if (cpuid_level < 0) 706 if (cpuid_level < 0)
620 return; 707 return;
621 708
622 for (i = 0; i < __arraycount(ci->ci_feat_val); i++) { 709 for (i = 0; i < __arraycount(ci->ci_feat_val); i++) {
623 ci->ci_feat_val[i] = 0; 710 ci->ci_feat_val[i] = 0;
624 } 711 }
625 712
@@ -657,61 +744,38 @@ cpu_probe(struct cpu_info *ci) @@ -657,61 +744,38 @@ cpu_probe(struct cpu_info *ci)
657 break; 744 break;
658 } 745 }
659 memcpy(cpu_brand_string, ((char *) brand) + i, 48 - i); 746 memcpy(cpu_brand_string, ((char *) brand) + i, 48 - i);
660 } 747 }
661 748
662 if (cpuid_level >= 1) { 749 if (cpuid_level >= 1) {
663 x86_cpuid(1, descs); 750 x86_cpuid(1, descs);
664 ci->ci_signature = descs[0]; 751 ci->ci_signature = descs[0];
665 miscbytes = descs[1]; 752 miscbytes = descs[1];
666 ci->ci_feat_val[1] = descs[2]; 753 ci->ci_feat_val[1] = descs[2];
667 ci->ci_feat_val[0] = descs[3]; 754 ci->ci_feat_val[0] = descs[3];
668 755
669 /* Determine family + class. */ 756 /* Determine family + class. */
670 cpu_class = CPUID2FAMILY(ci->ci_signature) + (CPUCLASS_386 - 3); 757 cpu_class = CPUID_TO_FAMILY(ci->ci_signature)
 758 + (CPUCLASS_386 - 3);
671 if (cpu_class > CPUCLASS_686) 759 if (cpu_class > CPUCLASS_686)
672 cpu_class = CPUCLASS_686; 760 cpu_class = CPUCLASS_686;
673 761
674 /* CLFLUSH line size is next 8 bits */ 762 /* CLFLUSH line size is next 8 bits */
675 if (ci->ci_feat_val[0] & CPUID_CFLUSH) 763 if (ci->ci_feat_val[0] & CPUID_CFLUSH)
676 ci->ci_cflush_lsize = ((miscbytes >> 8) & 0xff) << 3; 764 ci->ci_cflush_lsize = ((miscbytes >> 8) & 0xff) << 3;
677 ci->ci_initapicid = (miscbytes >> 24) & 0xff; 765 ci->ci_initapicid = (miscbytes >> 24) & 0xff;
678 } 766 }
679 767
680 if (cpuid_level >= 2) {  768 cpu_probe_intel(ci);
681 /* Parse the cache info from `cpuid', if we have it. */ 
682 x86_cpuid(2, descs); 
683 iterations = descs[0] & 0xff; 
684 while (iterations-- > 0) { 
685 for (i = 0; i < 4; i++) { 
686 if (descs[i] & 0x80000000) 
687 continue; 
688 for (j = 0; j < 4; j++) { 
689 if (i == 0 && j == 0) 
690 continue; 
691 desc = (descs[i] >> (j * 8)) & 0xff; 
692 if (desc == 0) 
693 continue; 
694 cai = cache_info_lookup( 
695 intel_cpuid_cache_info, desc); 
696 if (cai != NULL) { 
697 ci->ci_cinfo[cai->cai_index] = 
698 *cai; 
699 } 
700 } 
701 } 
702 } 
703 } 
704 
705 cpu_probe_k5(ci); 769 cpu_probe_k5(ci);
706 cpu_probe_k678(ci); 770 cpu_probe_k678(ci);
707 cpu_probe_cyrix(ci); 771 cpu_probe_cyrix(ci);
708 cpu_probe_winchip(ci); 772 cpu_probe_winchip(ci);
709 cpu_probe_c3(ci); 773 cpu_probe_c3(ci);
710 cpu_probe_geode(ci); 774 cpu_probe_geode(ci);
711 cpu_probe_vortex86(ci); 775 cpu_probe_vortex86(ci);
712 776
713 x86_cpu_topology(ci); 777 x86_cpu_topology(ci);
714 778
715 if (cpu_vendor != CPUVENDOR_AMD && (ci->ci_feat_val[0] & CPUID_TM) && 779 if (cpu_vendor != CPUVENDOR_AMD && (ci->ci_feat_val[0] & CPUID_TM) &&
716 (rdmsr(MSR_MISC_ENABLE) & (1 << 3)) == 0) { 780 (rdmsr(MSR_MISC_ENABLE) & (1 << 3)) == 0) {
717 /* Enable thermal monitor 1. */ 781 /* Enable thermal monitor 1. */