arm.c revision 1.5 1 1.5 msaitoh /* $NetBSD: arm.c,v 1.5 2021/12/05 04:25:33 msaitoh Exp $ */
2 1.1 matt
3 1.1 matt /*-
4 1.1 matt * Copyright (c) 2013 The NetBSD Foundation, Inc.
5 1.1 matt * All rights reserved.
6 1.1 matt *
7 1.1 matt * This code is derived from software contributed to The NetBSD Foundation
8 1.1 matt * by Matt Thomas of 3am Software Foundry.
9 1.1 matt *
10 1.1 matt * Redistribution and use in source and binary forms, with or without
11 1.1 matt * modification, are permitted provided that the following conditions
12 1.1 matt * are met:
13 1.1 matt * 1. Redistributions of source code must retain the above copyright
14 1.1 matt * notice, this list of conditions and the following disclaimer.
15 1.1 matt * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 matt * notice, this list of conditions and the following disclaimer in the
17 1.1 matt * documentation and/or other materials provided with the distribution.
18 1.1 matt *
19 1.1 matt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.1 matt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1 matt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1 matt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.1 matt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1 matt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1 matt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1 matt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1 matt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1 matt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1 matt * POSSIBILITY OF SUCH DAMAGE.
30 1.1 matt */
31 1.1 matt
32 1.1 matt #include <sys/cdefs.h>
33 1.1 matt
34 1.1 matt #ifndef lint
35 1.5 msaitoh __RCSID("$NetBSD: arm.c,v 1.5 2021/12/05 04:25:33 msaitoh Exp $");
36 1.1 matt #endif /* not lint */
37 1.1 matt
38 1.1 matt #include <sys/types.h>
39 1.1 matt #include <sys/cpuio.h>
40 1.1 matt #include <sys/sysctl.h>
41 1.1 matt #include <stdio.h>
42 1.1 matt #include <stdbool.h>
43 1.1 matt #include <stdlib.h>
44 1.1 matt #include <string.h>
45 1.1 matt #include <inttypes.h>
46 1.1 matt #include <err.h>
47 1.1 matt
48 1.1 matt #include "../cpuctl.h"
49 1.1 matt
50 1.1 matt static const char * const id_isar_fieldnames[][8] = {
51 1.1 matt {
52 1.1 matt "Swap", "Bitcount", "Bitfield", "CmpBranch",
53 1.1 matt "Coproc", "Debug", "Divde", NULL
54 1.1 matt }, {
55 1.1 matt "Endian", "Except", "Except_AR", "Extend",
56 1.1 matt "IfThen", "Immediate", "Interwork", "Jazelle"
57 1.1 matt }, {
58 1.1 matt "LoadStore", "MemHint", "MultAccessInt", "Mult",
59 1.1 matt "MultS", "MultU", "PSR_AR", "Reversal"
60 1.1 matt }, {
61 1.1 matt "Saturate", "SIMD", "SVC", "SynchPrim",
62 1.1 matt "TabBranch", "ThumbCopy", "TrueNOP", "ThumbEE_Extn"
63 1.1 matt }, {
64 1.1 matt "Unpriv", "WithShifts", "Writeback", "SMC",
65 1.1 matt "Barrier", "SynchPrim_frac", "PSR_M", "SWP"
66 1.1 matt }
67 1.1 matt };
68 1.1 matt
69 1.1 matt static const uint8_t id_isar_boolean[] = {
70 1.1 matt 0x2f, 0xb7, 0x41, 0xf5, 0xfc
71 1.1 matt };
72 1.1 matt
73 1.1 matt static const char * const id_mmfr_fieldnames[][8] = {
74 1.1 matt {
75 1.1 matt "VMSA-Support",
76 1.1 matt "PMSA-Support",
77 1.1 matt "Outermost-Shareablity",
78 1.1 matt "Shareability-Levels",
79 1.1 matt "TCM-Support",
80 1.5 msaitoh "Auxiliary-Registers",
81 1.1 matt "FCSE-Support",
82 1.1 matt "Innermost-Shareability"
83 1.1 matt }, {
84 1.4 jmcneill "L1-Harvard-Cache-VA",
85 1.4 jmcneill "L1-Unified-Cache-VA",
86 1.4 jmcneill "L1-Harvard-Cache-Set/Way",
87 1.4 jmcneill "L1-Unified-Cache-Set/Way",
88 1.4 jmcneill "L1-Harvard-Cache",
89 1.4 jmcneill "L1-Unified-Cache",
90 1.4 jmcneill "L1-Cache-Test-and-Clean",
91 1.4 jmcneill "Branch-Predictor",
92 1.1 matt }, {
93 1.4 jmcneill "L1-Harvard-Foreground-Fetch",
94 1.4 jmcneill "L1-Unified-Background-Fetch",
95 1.4 jmcneill "L1-Harvard-Range",
96 1.1 matt "Harvard-TLB",
97 1.4 jmcneill "Unified-TLB",
98 1.4 jmcneill "Mem-Barrier",
99 1.4 jmcneill "WFI-Stall",
100 1.4 jmcneill "HW-Access",
101 1.1 matt }, {
102 1.4 jmcneill "Cache-Maintenance-MVA",
103 1.4 jmcneill "Cache-Maintenance-Set/Way",
104 1.4 jmcneill "BP-Maintenance",
105 1.1 matt "Maintenance-Broadcast",
106 1.1 matt NULL,
107 1.4 jmcneill "Coherent-Tablewalk",
108 1.4 jmcneill "Cached-Memory-Size",
109 1.4 jmcneill "Supersection-Support",
110 1.1 matt },
111 1.1 matt };
112 1.1 matt
113 1.1 matt static const uint8_t id_mmfr_present[] = {
114 1.1 matt 0x8c, 0x00, 0x00, 0x68
115 1.1 matt };
116 1.1 matt
117 1.1 matt static const char * const id_pfr_fieldnames[][8] = {
118 1.1 matt {
119 1.1 matt "ThumbEE",
120 1.1 matt "Jazelle",
121 1.1 matt "Thumb",
122 1.1 matt "ARM",
123 1.1 matt }, {
124 1.1 matt "Programmer",
125 1.1 matt "Security",
126 1.1 matt "M-profile",
127 1.1 matt "Virtualization",
128 1.1 matt "Generic-Timer",
129 1.1 matt },
130 1.1 matt };
131 1.1 matt
132 1.1 matt static const char * const id_mvfr_fieldnames[][8] = {
133 1.1 matt {
134 1.1 matt "ASIMD-Registers",
135 1.1 matt "Single-Precision",
136 1.1 matt "Double-Precision",
137 1.1 matt "VFP-Exception-Trapping",
138 1.1 matt "Divide",
139 1.1 matt "Square-Root",
140 1.1 matt "Short-Vectors",
141 1.1 matt "VFP-Rounding-Modes",
142 1.1 matt }, {
143 1.1 matt "Flush-To-Zero",
144 1.1 matt "Default-NaN",
145 1.1 matt "ASIMD-Load/Store",
146 1.1 matt "ASIMD-Integer",
147 1.1 matt "ASIMD-SPFP",
148 1.1 matt "ASIMD-HPFP",
149 1.1 matt "VFP-HPFP",
150 1.1 matt "ASIMD-FMAC",
151 1.1 matt },
152 1.1 matt };
153 1.1 matt
154 1.1 matt static const uint8_t id_mvfr_present[] = {
155 1.1 matt 0x80, 0x03,
156 1.1 matt };
157 1.1 matt
158 1.1 matt static void
159 1.1 matt print_features(const char *cpuname, const char *setname,
160 1.1 matt const int *id_data, size_t id_len, const char * const id_fieldnames[][8],
161 1.1 matt size_t id_nfieldnames, const uint8_t *id_boolean, const uint8_t *id_present)
162 1.1 matt {
163 1.1 matt char buf[81];
164 1.1 matt size_t len = 0;
165 1.1 matt const char *sep = "";
166 1.1 matt for (size_t i = 0; i < id_len / sizeof(id_data[0]); i++) {
167 1.1 matt int isar = id_data[i];
168 1.1 matt for (u_int j = 0; isar != 0 && j < 8; j++, isar >>= 4) {
169 1.1 matt const char *name = NULL;
170 1.1 matt const char *value = "";
171 1.3 mrg char namebuf[24], valuebuf[12], tmpbuf[30];
172 1.1 matt if ((isar & 0x0f) == 0
173 1.1 matt && (id_present == NULL
174 1.1 matt || (id_present[i] & (1 << j))) == 0) {
175 1.1 matt continue;
176 1.1 matt }
177 1.1 matt if (len == 0) {
178 1.1 matt len = snprintf(buf, sizeof(buf),
179 1.1 matt "%s: %s: ", cpuname, setname);
180 1.1 matt }
181 1.1 matt if (i < id_nfieldnames) {
182 1.1 matt name = id_fieldnames[i][j];
183 1.1 matt }
184 1.1 matt if (name == NULL) {
185 1.1 matt name = namebuf;
186 1.1 matt snprintf(namebuf, sizeof(namebuf),
187 1.1 matt "%zu[%u]", i, j);
188 1.1 matt }
189 1.1 matt if (id_boolean == NULL
190 1.1 matt || (id_boolean[i] & (1 << j)) == 0
191 1.1 matt || (isar & 0xe) != 0) {
192 1.1 matt value = valuebuf;
193 1.1 matt snprintf(valuebuf, sizeof(valuebuf),
194 1.1 matt "=%u", isar & 0x0f);
195 1.1 matt }
196 1.1 matt size_t tmplen = snprintf(tmpbuf, sizeof(tmpbuf),
197 1.4 jmcneill "%s%s%s", sep, name, value);
198 1.1 matt if (len + tmplen > 78) {
199 1.1 matt printf("%s\n", buf);
200 1.1 matt len = snprintf(buf, sizeof(buf),
201 1.1 matt "%s: %s: %s", cpuname, setname, tmpbuf + 2);
202 1.1 matt } else {
203 1.1 matt len = strlcat(buf, tmpbuf, sizeof(buf));
204 1.1 matt }
205 1.1 matt sep = ", ";
206 1.1 matt }
207 1.1 matt }
208 1.1 matt if (len > 0) {
209 1.1 matt printf("%s\n", buf);
210 1.1 matt }
211 1.1 matt }
212 1.1 matt
213 1.2 mrg bool
214 1.2 mrg identifycpu_bind(void)
215 1.2 mrg {
216 1.2 mrg
217 1.2 mrg return false;
218 1.2 mrg }
219 1.2 mrg
220 1.1 matt void
221 1.1 matt identifycpu(int fd, const char *cpuname)
222 1.1 matt {
223 1.1 matt int *id_data;
224 1.1 matt size_t id_isar_len = 0;
225 1.1 matt size_t id_mmfr_len = 0;
226 1.1 matt size_t id_pfr_len = 0;
227 1.1 matt size_t id_mvfr_len = 0;
228 1.1 matt
229 1.1 matt if (sysctlbyname("machdep.id_isar", NULL, &id_isar_len, NULL, 0) < 0
230 1.1 matt || sysctlbyname("machdep.id_mmfr", NULL, &id_mmfr_len, NULL, 0) < 0
231 1.1 matt || sysctlbyname("machdep.id_pfr", NULL, &id_pfr_len, NULL, 0) < 0
232 1.1 matt || sysctlbyname("machdep.id_mvfr", NULL, &id_mvfr_len, NULL, 0) < 0) {
233 1.1 matt warn("sysctlbyname");
234 1.1 matt return;
235 1.1 matt }
236 1.1 matt
237 1.1 matt id_data = malloc(id_isar_len);
238 1.1 matt
239 1.1 matt sysctlbyname("machdep.id_isar", id_data, &id_isar_len, NULL, 0);
240 1.1 matt print_features(cpuname, "isa features", id_data, id_isar_len,
241 1.1 matt id_isar_fieldnames, __arraycount(id_isar_fieldnames),
242 1.1 matt id_isar_boolean, NULL);
243 1.1 matt
244 1.1 matt free(id_data);
245 1.1 matt id_data = malloc(id_mmfr_len);
246 1.1 matt
247 1.1 matt sysctlbyname("machdep.id_mmfr", id_data, &id_mmfr_len, NULL, 0);
248 1.1 matt print_features(cpuname, "memory model", id_data, id_mmfr_len,
249 1.1 matt id_mmfr_fieldnames, __arraycount(id_mmfr_fieldnames),
250 1.1 matt NULL /*id_mmfr_boolean*/, id_mmfr_present);
251 1.1 matt
252 1.1 matt free(id_data);
253 1.1 matt id_data = malloc(id_pfr_len);
254 1.1 matt
255 1.1 matt sysctlbyname("machdep.id_pfr", id_data, &id_pfr_len, NULL, 0);
256 1.1 matt print_features(cpuname, "processor features", id_data, id_pfr_len,
257 1.1 matt id_pfr_fieldnames, __arraycount(id_pfr_fieldnames),
258 1.1 matt NULL /*id_pfr_boolean*/, NULL /*id_pfr_present*/);
259 1.1 matt
260 1.1 matt free(id_data);
261 1.1 matt id_data = malloc(id_mvfr_len);
262 1.1 matt
263 1.1 matt sysctlbyname("machdep.id_mvfr", id_data, &id_mvfr_len, NULL, 0);
264 1.1 matt print_features(cpuname, "media and VFP features", id_data, id_mvfr_len,
265 1.1 matt id_mvfr_fieldnames, __arraycount(id_mvfr_fieldnames),
266 1.1 matt NULL /*id_mvfr_boolean*/, id_mvfr_present);
267 1.1 matt
268 1.1 matt free(id_data);
269 1.1 matt }
270 1.1 matt
271 1.1 matt int
272 1.1 matt ucodeupdate_check(int fd, struct cpu_ucode *uc)
273 1.1 matt {
274 1.1 matt
275 1.1 matt return 0;
276 1.1 matt }
277