1 /* $NetBSD: sparc64.c,v 1.2 2021/12/11 19:24:22 mrg Exp $ */ 2 3 /* 4 * Copyright (c) 2018 Matthew R. Green 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 */ 28 #include <sys/cdefs.h> 29 30 #ifndef lint 31 __RCSID("$NetBSD: sparc64.c,v 1.2 2021/12/11 19:24:22 mrg Exp $"); 32 #endif 33 34 #include <sys/types.h> 35 #include <sys/cpuio.h> 36 #include <sys/sysctl.h> 37 38 #include <machine/cpu.h> 39 #include <machine/psl.h> 40 41 #include <stdio.h> 42 #include <err.h> 43 44 #include "../cpuctl.h" 45 46 void 47 identifycpu(int fd, const char *cpuname) 48 { 49 char path[128]; 50 char *name; 51 const char *sep; 52 uint64_t ver; 53 uint64_t hz; 54 int cpu_arch, id; 55 struct cacheinfo cacheinfo; 56 size_t len; 57 58 len = sizeof(cpu_arch); 59 if (sysctlbyname("machdep.cpu_arch", &cpu_arch, &len, 0, 0) == -1) 60 err(1, "couldn't get machdep.cpu_arch"); 61 62 snprintf(path, sizeof path, "hw.%s.cacheinfo", cpuname); 63 len = sizeof(cacheinfo); 64 if (sysctlbyname(path, &cacheinfo, &len, 0, 0) == -1) 65 err(1, "couldn't get %s", path); 66 67 snprintf(path, sizeof path, "hw.%s.id", cpuname); 68 len = sizeof(id); 69 if (sysctlbyname(path, &id, &len, 0, 0) == -1) 70 err(1, "couldn't get %s", path); 71 72 snprintf(path, sizeof path, "hw.%s.ver", cpuname); 73 len = sizeof(ver); 74 if (sysctlbyname(path, &ver, &len, 0, 0) == -1) 75 err(1, "couldn't get %s", path); 76 77 snprintf(path, sizeof path, "hw.%s.clock_frequency", cpuname); 78 len = sizeof(hz); 79 if (sysctlbyname(path, &hz, &len, 0, 0) == -1) 80 err(1, "couldn't get %s", path); 81 snprintf(path, sizeof path, "hw.%s.name", cpuname); 82 name = asysctlbyname(path, &len); 83 84 printf("%s: %s @ %ld MHz, CPU id %d\n", cpuname, name, hz / 1000000, id); 85 printf("%s: manuf %x, impl %x, mask %x\n", cpuname, 86 (unsigned)((ver & VER_MASK) >> VER_MASK_SHIFT), 87 (unsigned)((ver & VER_IMPL) >> VER_IMPL_SHIFT), 88 (unsigned)((ver & VER_MANUF) >> VER_MANUF_SHIFT)); 89 printf("%s: ", cpuname); 90 91 sep = ""; 92 if (cacheinfo.c_itotalsize) { 93 printf("%s%ldK instruction (%ld b/l)", sep, 94 (long)cacheinfo.c_itotalsize/1024, 95 (long)cacheinfo.c_ilinesize); 96 sep = ", "; 97 } 98 if (cacheinfo.c_dtotalsize) { 99 printf("%s%ldK data (%ld b/l)", sep, 100 (long)cacheinfo.c_dtotalsize/1024, 101 (long)cacheinfo.c_dlinesize); 102 sep = ", "; 103 } 104 105 if (cacheinfo.c_etotalsize) { 106 printf("%s%ldK external (%ld b/l)", sep, 107 (long)cacheinfo.c_etotalsize/1024, 108 (long)cacheinfo.c_elinesize); 109 } 110 printf("\n"); 111 112 printf("%s: SPARC v%d\n", cpuname, cpu_arch); 113 } 114 115 bool 116 identifycpu_bind(void) 117 { 118 119 return false; 120 } 121 122 int 123 ucodeupdate_check(int fd, struct cpu_ucode *uc) 124 { 125 126 return 0; 127 } 128