Mon Apr 20 04:17:52 2020 UTC ()
Whitespace fix. No functional change.


(msaitoh)
diff -r1.105 -r1.106 src/sys/arch/x86/x86/identcpu.c

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

--- src/sys/arch/x86/x86/identcpu.c 2020/04/09 02:07:01 1.105
+++ src/sys/arch/x86/x86/identcpu.c 2020/04/20 04:17:51 1.106
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: identcpu.c,v 1.105 2020/04/09 02:07:01 christos Exp $ */ 1/* $NetBSD: identcpu.c,v 1.106 2020/04/20 04:17:51 msaitoh 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.105 2020/04/09 02:07:01 christos Exp $"); 33__KERNEL_RCSID(0, "$NetBSD: identcpu.c,v 1.106 2020/04/20 04:17:51 msaitoh 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#include <sys/cpu.h> 40#include <sys/cpu.h>
41 41
42#include <uvm/uvm_extern.h> 42#include <uvm/uvm_extern.h>
43 43
44#include <machine/specialreg.h> 44#include <machine/specialreg.h>
45#include <machine/pio.h> 45#include <machine/pio.h>
46#include <machine/cpu.h> 46#include <machine/cpu.h>
@@ -52,47 +52,47 @@ __KERNEL_RCSID(0, "$NetBSD: identcpu.c,v @@ -52,47 +52,47 @@ __KERNEL_RCSID(0, "$NetBSD: identcpu.c,v
52 52
53#include <x86/x86/vmtreg.h> /* for vmt_hvcall() */ 53#include <x86/x86/vmtreg.h> /* for vmt_hvcall() */
54#include <x86/x86/vmtvar.h> /* for vmt_hvcall() */ 54#include <x86/x86/vmtvar.h> /* for vmt_hvcall() */
55 55
56#ifndef XEN 56#ifndef XEN
57#include "hyperv.h" 57#include "hyperv.h"
58#if NHYPERV > 0 58#if NHYPERV > 0
59#include <x86/x86/hypervvar.h> 59#include <x86/x86/hypervvar.h>
60#endif 60#endif
61#endif 61#endif
62 62
63static const struct x86_cache_info intel_cpuid_cache_info[] = INTEL_CACHE_INFO; 63static const struct x86_cache_info intel_cpuid_cache_info[] = INTEL_CACHE_INFO;
64 64
65static const struct x86_cache_info amd_cpuid_l2l3cache_assoc_info[] =  65static const struct x86_cache_info amd_cpuid_l2l3cache_assoc_info[] =
66 AMD_L2L3CACHE_INFO; 66 AMD_L2L3CACHE_INFO;
67 67
68int cpu_vendor; 68int cpu_vendor;
69char cpu_brand_string[49]; 69char cpu_brand_string[49];
70 70
71int x86_fpu_save __read_mostly; 71int x86_fpu_save __read_mostly;
72unsigned int x86_fpu_save_size __read_mostly = sizeof(struct save87); 72unsigned int x86_fpu_save_size __read_mostly = sizeof(struct save87);
73uint64_t x86_xsave_features __read_mostly = 0; 73uint64_t x86_xsave_features __read_mostly = 0;
74size_t x86_xsave_offsets[XSAVE_MAX_COMPONENT+1] __read_mostly; 74size_t x86_xsave_offsets[XSAVE_MAX_COMPONENT+1] __read_mostly;
75size_t x86_xsave_sizes[XSAVE_MAX_COMPONENT+1] __read_mostly; 75size_t x86_xsave_sizes[XSAVE_MAX_COMPONENT+1] __read_mostly;
76 76
77/* 77/*
78 * Note: these are just the ones that may not have a cpuid instruction. 78 * Note: these are just the ones that may not have a cpuid instruction.
79 * We deal with the rest in a different way. 79 * We deal with the rest in a different way.
80 */ 80 */
81const int i386_nocpuid_cpus[] = { 81const int i386_nocpuid_cpus[] = {
82 CPUVENDOR_INTEL, CPUCLASS_386, /* CPU_386SX */ 82 CPUVENDOR_INTEL, CPUCLASS_386, /* CPU_386SX */
83 CPUVENDOR_INTEL, CPUCLASS_386, /* CPU_386 */ 83 CPUVENDOR_INTEL, CPUCLASS_386, /* CPU_386 */
84 CPUVENDOR_INTEL, CPUCLASS_486, /* CPU_486SX */ 84 CPUVENDOR_INTEL, CPUCLASS_486, /* CPU_486SX */
85 CPUVENDOR_INTEL, CPUCLASS_486, /* CPU_486 */ 85 CPUVENDOR_INTEL, CPUCLASS_486, /* CPU_486 */
86 CPUVENDOR_CYRIX, CPUCLASS_486, /* CPU_486DLC */ 86 CPUVENDOR_CYRIX, CPUCLASS_486, /* CPU_486DLC */
87 CPUVENDOR_CYRIX, CPUCLASS_486, /* CPU_6x86 */ 87 CPUVENDOR_CYRIX, CPUCLASS_486, /* CPU_6x86 */
88 CPUVENDOR_NEXGEN, CPUCLASS_386, /* CPU_NX586 */ 88 CPUVENDOR_NEXGEN, CPUCLASS_386, /* CPU_NX586 */
89}; 89};
90 90
91static const char cpu_vendor_names[][10] = { 91static const char cpu_vendor_names[][10] = {
92 "Unknown", "Intel", "NS/Cyrix", "NexGen", "AMD", "IDT/VIA", "Transmeta", 92 "Unknown", "Intel", "NS/Cyrix", "NexGen", "AMD", "IDT/VIA", "Transmeta",
93 "Vortex86" 93 "Vortex86"
94}; 94};
95 95
96static const struct x86_cache_info * 96static const struct x86_cache_info *
97cache_info_lookup(const struct x86_cache_info *cai, uint8_t desc) 97cache_info_lookup(const struct x86_cache_info *cai, uint8_t desc)
98{ 98{
@@ -164,27 +164,27 @@ cpu_dcp_cacheinfo(struct cpu_info *ci, u @@ -164,27 +164,27 @@ cpu_dcp_cacheinfo(struct cpu_info *ci, u
164 ci->ci_cinfo[caitype].cai_associativity = ways; 164 ci->ci_cinfo[caitype].cai_associativity = ways;
165 ci->ci_cinfo[caitype].cai_linesize = linesize; 165 ci->ci_cinfo[caitype].cai_linesize = linesize;
166 } 166 }
167} 167}
168 168
169static void 169static void
170cpu_probe_intel_cache(struct cpu_info *ci) 170cpu_probe_intel_cache(struct cpu_info *ci)
171{ 171{
172 const struct x86_cache_info *cai; 172 const struct x86_cache_info *cai;
173 u_int descs[4]; 173 u_int descs[4];
174 int iterations, i, j; 174 int iterations, i, j;
175 uint8_t desc; 175 uint8_t desc;
176 176
177 if (cpuid_level >= 2) {  177 if (cpuid_level >= 2) {
178 /* Parse the cache info from `cpuid leaf 2', if we have it. */ 178 /* Parse the cache info from `cpuid leaf 2', if we have it. */
179 x86_cpuid(2, descs); 179 x86_cpuid(2, descs);
180 iterations = descs[0] & 0xff; 180 iterations = descs[0] & 0xff;
181 while (iterations-- > 0) { 181 while (iterations-- > 0) {
182 for (i = 0; i < 4; i++) { 182 for (i = 0; i < 4; i++) {
183 if (descs[i] & 0x80000000) 183 if (descs[i] & 0x80000000)
184 continue; 184 continue;
185 for (j = 0; j < 4; j++) { 185 for (j = 0; j < 4; j++) {
186 if (i == 0 && j == 0) 186 if (i == 0 && j == 0)
187 continue; 187 continue;
188 desc = (descs[i] >> (j * 8)) & 0xff; 188 desc = (descs[i] >> (j * 8)) & 0xff;
189 if (desc == 0) 189 if (desc == 0)
190 continue; 190 continue;
@@ -478,27 +478,27 @@ cpu_probe_cyrix_cmn(struct cpu_info *ci) @@ -478,27 +478,27 @@ cpu_probe_cyrix_cmn(struct cpu_info *ci)
478 * When powersave mode is enabled, the TSC stops counting 478 * When powersave mode is enabled, the TSC stops counting
479 * while the CPU is halted in idle() waiting for an interrupt. 479 * while the CPU is halted in idle() waiting for an interrupt.
480 * This means we can't use the TSC for interval time in 480 * This means we can't use the TSC for interval time in
481 * microtime(9), and thus it is disabled here. 481 * microtime(9), and thus it is disabled here.
482 * 482 *
483 * It still makes a perfectly good cycle counter 483 * It still makes a perfectly good cycle counter
484 * for program profiling, so long as you remember you're 484 * for program profiling, so long as you remember you're
485 * counting cycles, and not time. Further, if you don't 485 * counting cycles, and not time. Further, if you don't
486 * mind not using powersave mode, the TSC works just fine, 486 * mind not using powersave mode, the TSC works just fine,
487 * so this should really be optional. XXX 487 * so this should really be optional. XXX
488 */ 488 */
489 cyrix_write_reg(0xc2, cyrix_read_reg(0xc2) | 0x08); 489 cyrix_write_reg(0xc2, cyrix_read_reg(0xc2) | 0x08);
490 490
491 /*  491 /*
492 * Do not disable the TSC on the Geode GX, it's reported to 492 * Do not disable the TSC on the Geode GX, it's reported to
493 * work fine. 493 * work fine.
494 */ 494 */
495 if (ci->ci_signature != 0x552) 495 if (ci->ci_signature != 0x552)
496 ci->ci_feat_val[0] &= ~CPUID_TSC; 496 ci->ci_feat_val[0] &= ~CPUID_TSC;
497 497
498 /* enable access to ccr4/ccr5 */ 498 /* enable access to ccr4/ccr5 */
499 c3 = cyrix_read_reg(0xC3); 499 c3 = cyrix_read_reg(0xC3);
500 cyrix_write_reg(0xC3, c3 | 0x10); 500 cyrix_write_reg(0xC3, c3 | 0x10);
501 /* cyrix's workaround for the "coma bug" */ 501 /* cyrix's workaround for the "coma bug" */
502 cyrix_write_reg(0x31, cyrix_read_reg(0x31) | 0xf8); 502 cyrix_write_reg(0x31, cyrix_read_reg(0x31) | 0xf8);
503 cyrix_write_reg(0x32, cyrix_read_reg(0x32) | 0x7f); 503 cyrix_write_reg(0x32, cyrix_read_reg(0x32) | 0x7f);
504 cyrix_write_reg(0x33, cyrix_read_reg(0x33) & ~0xff); 504 cyrix_write_reg(0x33, cyrix_read_reg(0x33) & ~0xff);
@@ -515,27 +515,27 @@ cpu_probe_cyrix(struct cpu_info *ci) @@ -515,27 +515,27 @@ cpu_probe_cyrix(struct cpu_info *ci)
515 CPUID_TO_FAMILY(ci->ci_signature) < 4 || 515 CPUID_TO_FAMILY(ci->ci_signature) < 4 ||
516 CPUID_TO_FAMILY(ci->ci_signature) > 6) 516 CPUID_TO_FAMILY(ci->ci_signature) > 6)
517 return; 517 return;
518 518
519 cpu_probe_cyrix_cmn(ci); 519 cpu_probe_cyrix_cmn(ci);
520} 520}
521 521
522static void 522static void
523cpu_probe_winchip(struct cpu_info *ci) 523cpu_probe_winchip(struct cpu_info *ci)
524{ 524{
525 525
526 if (cpu_vendor != CPUVENDOR_IDT || 526 if (cpu_vendor != CPUVENDOR_IDT ||
527 CPUID_TO_FAMILY(ci->ci_signature) != 5) 527 CPUID_TO_FAMILY(ci->ci_signature) != 5)
528 return; 528 return;
529 529
530 /* WinChip C6 */ 530 /* WinChip C6 */
531 if (CPUID_TO_MODEL(ci->ci_signature) == 4) 531 if (CPUID_TO_MODEL(ci->ci_signature) == 4)
532 ci->ci_feat_val[0] &= ~CPUID_TSC; 532 ci->ci_feat_val[0] &= ~CPUID_TSC;
533} 533}
534 534
535static void 535static void
536cpu_probe_c3(struct cpu_info *ci) 536cpu_probe_c3(struct cpu_info *ci)
537{ 537{
538 u_int family, model, stepping, descs[4], lfunc, msr; 538 u_int family, model, stepping, descs[4], lfunc, msr;
539 struct x86_cache_info *cai; 539 struct x86_cache_info *cai;
540 540
541 if (cpu_vendor != CPUVENDOR_IDT || 541 if (cpu_vendor != CPUVENDOR_IDT ||
@@ -546,27 +546,27 @@ cpu_probe_c3(struct cpu_info *ci) @@ -546,27 +546,27 @@ cpu_probe_c3(struct cpu_info *ci)
546 model = CPUID_TO_MODEL(ci->ci_signature); 546 model = CPUID_TO_MODEL(ci->ci_signature);
547 stepping = CPUID_TO_STEPPING(ci->ci_signature); 547 stepping = CPUID_TO_STEPPING(ci->ci_signature);
548 548
549 /* Determine the largest extended function value. */ 549 /* Determine the largest extended function value. */
550 x86_cpuid(0x80000000, descs); 550 x86_cpuid(0x80000000, descs);
551 lfunc = descs[0]; 551 lfunc = descs[0];
552 552
553 if (family == 6) { 553 if (family == 6) {
554 /* 554 /*
555 * VIA Eden ESP. 555 * VIA Eden ESP.
556 * 556 *
557 * Quoting from page 3-4 of: "VIA Eden ESP Processor Datasheet" 557 * Quoting from page 3-4 of: "VIA Eden ESP Processor Datasheet"
558 * http://www.via.com.tw/download/mainboards/6/14/Eden20v115.pdf 558 * http://www.via.com.tw/download/mainboards/6/14/Eden20v115.pdf
559 *  559 *
560 * 1. The CMPXCHG8B instruction is provided and always enabled, 560 * 1. The CMPXCHG8B instruction is provided and always enabled,
561 * however, it appears disabled in the corresponding CPUID 561 * however, it appears disabled in the corresponding CPUID
562 * function bit 0 to avoid a bug in an early version of 562 * function bit 0 to avoid a bug in an early version of
563 * Windows NT. However, this default can be changed via a 563 * Windows NT. However, this default can be changed via a
564 * bit in the FCR MSR. 564 * bit in the FCR MSR.
565 */ 565 */
566 ci->ci_feat_val[0] |= CPUID_CX8; 566 ci->ci_feat_val[0] |= CPUID_CX8;
567 wrmsr(MSR_VIA_FCR, rdmsr(MSR_VIA_FCR) | VIA_ACE_ECX8); 567 wrmsr(MSR_VIA_FCR, rdmsr(MSR_VIA_FCR) | VIA_ACE_ECX8);
568 } 568 }
569 569
570 if (family > 6 || model > 0x9 || (model == 0x9 && stepping >= 3)) { 570 if (family > 6 || model > 0x9 || (model == 0x9 && stepping >= 3)) {
571 /* VIA Nehemiah or Esther. */ 571 /* VIA Nehemiah or Esther. */
572 x86_cpuid(0xc0000000, descs); 572 x86_cpuid(0xc0000000, descs);
@@ -636,27 +636,27 @@ cpu_probe_c3(struct cpu_info *ci) @@ -636,27 +636,27 @@ cpu_probe_c3(struct cpu_info *ci)
636 } 636 }
637 637
638 if (ace_enable) { 638 if (ace_enable) {
639 msr = rdmsr(MSR_VIA_ACE); 639 msr = rdmsr(MSR_VIA_ACE);
640 wrmsr(MSR_VIA_ACE, msr | VIA_ACE_ENABLE); 640 wrmsr(MSR_VIA_ACE, msr | VIA_ACE_ENABLE);
641 } 641 }
642 } 642 }
643 } 643 }
644 644
645 /* Explicitly disable unsafe ALTINST mode. */ 645 /* Explicitly disable unsafe ALTINST mode. */
646 if (ci->ci_feat_val[4] & CPUID_VIA_DO_ACE) { 646 if (ci->ci_feat_val[4] & CPUID_VIA_DO_ACE) {
647 msr = rdmsr(MSR_VIA_ACE); 647 msr = rdmsr(MSR_VIA_ACE);
648 wrmsr(MSR_VIA_ACE, msr & ~VIA_ACE_ALTINST); 648 wrmsr(MSR_VIA_ACE, msr & ~VIA_ACE_ALTINST);
649 }  649 }
650 650
651 /* 651 /*
652 * Determine L1 cache/TLB info. 652 * Determine L1 cache/TLB info.
653 */ 653 */
654 if (lfunc < 0x80000005) { 654 if (lfunc < 0x80000005) {
655 /* No L1 cache info available. */ 655 /* No L1 cache info available. */
656 return; 656 return;
657 } 657 }
658 658
659 x86_cpuid(0x80000005, descs); 659 x86_cpuid(0x80000005, descs);
660 660
661 cai = &ci->ci_cinfo[CAI_ITLB]; 661 cai = &ci->ci_cinfo[CAI_ITLB];
662 cai->cai_totalsize = VIA_L1_EBX_ITLB_ENTRIES(descs[1]); 662 cai->cai_totalsize = VIA_L1_EBX_ITLB_ENTRIES(descs[1]);
@@ -704,27 +704,27 @@ cpu_probe_c3(struct cpu_info *ci) @@ -704,27 +704,27 @@ cpu_probe_c3(struct cpu_info *ci)
704 } else { 704 } else {
705 cai->cai_totalsize = VIA_L2_ECX_C_SIZE(descs[2]); 705 cai->cai_totalsize = VIA_L2_ECX_C_SIZE(descs[2]);
706 cai->cai_associativity = VIA_L2_ECX_C_ASSOC(descs[2]); 706 cai->cai_associativity = VIA_L2_ECX_C_ASSOC(descs[2]);
707 cai->cai_linesize = VIA_L2_ECX_C_LS(descs[2]); 707 cai->cai_linesize = VIA_L2_ECX_C_LS(descs[2]);
708 } 708 }
709} 709}
710 710
711static void 711static void
712cpu_probe_geode(struct cpu_info *ci) 712cpu_probe_geode(struct cpu_info *ci)
713{ 713{
714 714
715 if (memcmp("Geode by NSC", ci->ci_vendor, 12) != 0 || 715 if (memcmp("Geode by NSC", ci->ci_vendor, 12) != 0 ||
716 CPUID_TO_FAMILY(ci->ci_signature) != 5) 716 CPUID_TO_FAMILY(ci->ci_signature) != 5)
717 return; 717 return;
718 718
719 cpu_probe_cyrix_cmn(ci); 719 cpu_probe_cyrix_cmn(ci);
720 cpu_probe_amd_cache(ci); 720 cpu_probe_amd_cache(ci);
721} 721}
722 722
723static void 723static void
724cpu_probe_vortex86(struct cpu_info *ci) 724cpu_probe_vortex86(struct cpu_info *ci)
725{ 725{
726#define PCI_MODE1_ADDRESS_REG 0x0cf8 726#define PCI_MODE1_ADDRESS_REG 0x0cf8
727#define PCI_MODE1_DATA_REG 0x0cfc 727#define PCI_MODE1_DATA_REG 0x0cfc
728#define PCI_MODE1_ENABLE 0x80000000UL 728#define PCI_MODE1_ENABLE 0x80000000UL
729 729
730 uint32_t reg, idx; 730 uint32_t reg, idx;