sparc64.c revision 1.1 1 /* $NetBSD: sparc64.c,v 1.1 2018/01/16 08:23:18 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 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 */
30 #include <sys/cdefs.h>
31
32 #ifndef lint
33 __RCSID("$NetBSD: sparc64.c,v 1.1 2018/01/16 08:23:18 mrg Exp $");
34 #endif
35
36 #include <sys/types.h>
37 #include <sys/cpuio.h>
38 #include <sys/sysctl.h>
39
40 #include <machine/cpu.h>
41 #include <machine/psl.h>
42
43 #include <stdio.h>
44 #include <err.h>
45
46 #include "../cpuctl.h"
47
48 void
49 identifycpu(int fd, const char *cpuname)
50 {
51 char path[128];
52 char *name;
53 const char *sep;
54 uint64_t ver;
55 uint64_t hz;
56 int cpu_arch, id;
57 struct cacheinfo cacheinfo;
58 size_t len;
59
60 len = sizeof(cpu_arch);
61 if (sysctlbyname("machdep.cpu_arch", &cpu_arch, &len, 0, 0) == -1)
62 err(1, "couldn't get machdep.cpu_arch");
63
64 snprintf(path, sizeof path, "hw.%s.cacheinfo", cpuname);
65 len = sizeof(cacheinfo);
66 if (sysctlbyname(path, &cacheinfo, &len, 0, 0) == -1)
67 err(1, "couldn't get %s", path);
68
69 snprintf(path, sizeof path, "hw.%s.id", cpuname);
70 len = sizeof(id);
71 if (sysctlbyname(path, &id, &len, 0, 0) == -1)
72 err(1, "couldn't get %s", path);
73
74 snprintf(path, sizeof path, "hw.%s.ver", cpuname);
75 len = sizeof(ver);
76 if (sysctlbyname(path, &ver, &len, 0, 0) == -1)
77 err(1, "couldn't get %s", path);
78
79 snprintf(path, sizeof path, "hw.%s.clock_frequency", cpuname);
80 len = sizeof(hz);
81 if (sysctlbyname(path, &hz, &len, 0, 0) == -1)
82 err(1, "couldn't get %s", path);
83 snprintf(path, sizeof path, "hw.%s.name", cpuname);
84 name = asysctlbyname(path, &len);
85
86 printf("%s: %s @ %ld MHz, CPU id %d\n", cpuname, name, hz / 1000000, id);
87 printf("%s: manuf %x, impl %x, mask %x\n", cpuname,
88 (unsigned)((ver & VER_MASK) >> VER_MASK_SHIFT),
89 (unsigned)((ver & VER_IMPL) >> VER_IMPL_SHIFT),
90 (unsigned)((ver & VER_MANUF) >> VER_MANUF_SHIFT));
91 printf("%s: ", cpuname);
92
93 sep = "";
94 if (cacheinfo.c_itotalsize) {
95 printf("%s%ldK instruction (%ld b/l)", sep,
96 (long)cacheinfo.c_itotalsize/1024,
97 (long)cacheinfo.c_ilinesize);
98 sep = ", ";
99 }
100 if (cacheinfo.c_dtotalsize) {
101 printf("%s%ldK data (%ld b/l)", sep,
102 (long)cacheinfo.c_dtotalsize/1024,
103 (long)cacheinfo.c_dlinesize);
104 sep = ", ";
105 }
106
107 if (cacheinfo.c_etotalsize) {
108 printf("%s%ldK external (%ld b/l)", sep,
109 (long)cacheinfo.c_etotalsize/1024,
110 (long)cacheinfo.c_elinesize);
111 }
112 printf("\n");
113
114 printf("%s: SPARC v%d\n", cpuname, cpu_arch);
115 }
116
117 bool
118 identifycpu_bind(void)
119 {
120
121 return false;
122 }
123
124 int
125 ucodeupdate_check(int fd, struct cpu_ucode *uc)
126 {
127
128 return 0;
129 }
130