aarch64.c revision 1.9 1 1.9 riastrad /* $NetBSD: aarch64.c,v 1.9 2020/05/10 21:42:05 riastradh Exp $ */
2 1.1 ryo
3 1.1 ryo /*
4 1.1 ryo * Copyright (c) 2018 Ryo Shimizu <ryo (at) nerv.org>
5 1.1 ryo * All rights reserved.
6 1.1 ryo *
7 1.1 ryo * Redistribution and use in source and binary forms, with or without
8 1.1 ryo * modification, are permitted provided that the following conditions
9 1.1 ryo * are met:
10 1.1 ryo * 1. Redistributions of source code must retain the above copyright
11 1.1 ryo * notice, this list of conditions and the following disclaimer.
12 1.1 ryo * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 ryo * notice, this list of conditions and the following disclaimer in the
14 1.1 ryo * documentation and/or other materials provided with the distribution.
15 1.1 ryo *
16 1.1 ryo * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 1.1 ryo * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 1.1 ryo * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 1.1 ryo * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
20 1.1 ryo * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 1.1 ryo * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 1.1 ryo * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 1.1 ryo * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
24 1.1 ryo * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
25 1.1 ryo * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 1.1 ryo * POSSIBILITY OF SUCH DAMAGE.
27 1.1 ryo */
28 1.1 ryo
29 1.1 ryo #include <sys/cdefs.h>
30 1.1 ryo
31 1.1 ryo #ifndef lint
32 1.9 riastrad __RCSID("$NetBSD: aarch64.c,v 1.9 2020/05/10 21:42:05 riastradh Exp $");
33 1.1 ryo #endif /* no lint */
34 1.1 ryo
35 1.1 ryo #include <sys/types.h>
36 1.1 ryo #include <sys/cpuio.h>
37 1.1 ryo #include <sys/sysctl.h>
38 1.1 ryo #include <stdio.h>
39 1.1 ryo #include <stdbool.h>
40 1.1 ryo #include <stdlib.h>
41 1.1 ryo #include <string.h>
42 1.1 ryo #include <inttypes.h>
43 1.1 ryo #include <err.h>
44 1.1 ryo
45 1.1 ryo #include <arm/cputypes.h>
46 1.1 ryo #include <aarch64/armreg.h>
47 1.1 ryo
48 1.1 ryo #include "../cpuctl.h"
49 1.1 ryo
50 1.1 ryo struct cpuidtab {
51 1.1 ryo uint32_t cpu_partnum;
52 1.1 ryo const char *cpu_name;
53 1.1 ryo const char *cpu_class;
54 1.1 ryo const char *cpu_architecture;
55 1.1 ryo };
56 1.1 ryo
57 1.1 ryo struct impltab {
58 1.1 ryo uint32_t impl_id;
59 1.1 ryo const char *impl_name;
60 1.1 ryo };
61 1.1 ryo
62 1.1 ryo struct fieldinfo {
63 1.1 ryo int bitpos;
64 1.1 ryo int bitwidth;
65 1.1 ryo const char *name;
66 1.1 ryo const char * const *info;
67 1.1 ryo };
68 1.1 ryo
69 1.1 ryo
70 1.1 ryo #define CPU_PARTMASK (CPU_ID_IMPLEMENTOR_MASK | CPU_ID_PARTNO_MASK)
71 1.1 ryo const struct cpuidtab cpuids[] = {
72 1.1 ryo { CPU_ID_CORTEXA53R0 & CPU_PARTMASK, "Cortex-A53", "Cortex", "V8-A" },
73 1.1 ryo { CPU_ID_CORTEXA57R0 & CPU_PARTMASK, "Cortex-A57", "Cortex", "V8-A" },
74 1.1 ryo { CPU_ID_CORTEXA72R0 & CPU_PARTMASK, "Cortex-A72", "Cortex", "V8-A" },
75 1.1 ryo { CPU_ID_CORTEXA73R0 & CPU_PARTMASK, "Cortex-A73", "Cortex", "V8-A" },
76 1.1 ryo { CPU_ID_CORTEXA55R1 & CPU_PARTMASK, "Cortex-A55", "Cortex", "V8.2-A" },
77 1.4 ryo { CPU_ID_CORTEXA75R2 & CPU_PARTMASK, "Cortex-A75", "Cortex", "V8.2-A" },
78 1.7 mrg { CPU_ID_CORTEXA76R3 & CPU_PARTMASK, "Cortex-A76", "Cortex", "V8.2-A" },
79 1.4 ryo { CPU_ID_THUNDERXRX, "Cavium ThunderX", "Cavium", "V8-A" },
80 1.4 ryo { CPU_ID_THUNDERX81XXRX, "Cavium ThunderX CN81XX", "Cavium", "V8-A" },
81 1.4 ryo { CPU_ID_THUNDERX83XXRX, "Cavium ThunderX CN83XX", "Cavium", "V8-A" },
82 1.4 ryo { CPU_ID_THUNDERX2RX, "Cavium ThunderX2", "Cavium", "V8.1-A" },
83 1.1 ryo };
84 1.1 ryo
85 1.1 ryo const struct impltab implids[] = {
86 1.1 ryo { CPU_ID_ARM_LTD, "ARM Limited" },
87 1.1 ryo { CPU_ID_BROADCOM, "Broadcom Corporation" },
88 1.1 ryo { CPU_ID_CAVIUM, "Cavium Inc." },
89 1.1 ryo { CPU_ID_DEC, "Digital Equipment Corporation" },
90 1.1 ryo { CPU_ID_INFINEON, "Infineon Technologies AG" },
91 1.1 ryo { CPU_ID_MOTOROLA, "Motorola or Freescale Semiconductor Inc." },
92 1.1 ryo { CPU_ID_NVIDIA, "NVIDIA Corporation" },
93 1.1 ryo { CPU_ID_APM, "Applied Micro Circuits Corporation" },
94 1.1 ryo { CPU_ID_QUALCOMM, "Qualcomm Inc." },
95 1.1 ryo { CPU_ID_SAMSUNG, "SAMSUNG" },
96 1.1 ryo { CPU_ID_TI, "Texas Instruments" },
97 1.1 ryo { CPU_ID_MARVELL, "Marvell International Ltd." },
98 1.1 ryo { CPU_ID_APPLE, "Apple Inc." },
99 1.1 ryo { CPU_ID_FARADAY, "Faraday Technology Corporation" },
100 1.1 ryo { CPU_ID_INTEL, "Intel Corporation" }
101 1.1 ryo };
102 1.1 ryo
103 1.1 ryo /* ID_AA64PFR0_EL1 - AArch64 Processor Feature Register 0 */
104 1.1 ryo struct fieldinfo id_aa64pfr0_fieldinfo[] = {
105 1.1 ryo {
106 1.1 ryo .bitpos = 0, .bitwidth = 4, .name = "EL0",
107 1.1 ryo .info = (const char *[16]) { /* 16=4bit */
108 1.1 ryo [0] = "No EL0",
109 1.1 ryo [1] = "AArch64",
110 1.1 ryo [2] = "AArch64/AArch32"
111 1.1 ryo }
112 1.1 ryo },
113 1.1 ryo {
114 1.1 ryo .bitpos = 4, .bitwidth = 4, .name = "EL1",
115 1.1 ryo .info = (const char *[16]) { /* 16=4bit */
116 1.1 ryo [0] = "No EL1",
117 1.1 ryo [1] = "AArch64",
118 1.1 ryo [2] = "AArch64/AArch32"
119 1.1 ryo }
120 1.1 ryo },
121 1.1 ryo {
122 1.1 ryo .bitpos = 8, .bitwidth = 4, .name = "EL2",
123 1.1 ryo .info = (const char *[16]) { /* 16=4bit */
124 1.1 ryo [0] = "No EL2",
125 1.1 ryo [1] = "AArch64",
126 1.1 ryo [2] = "AArch64/AArch32"
127 1.1 ryo }
128 1.1 ryo },
129 1.1 ryo {
130 1.1 ryo .bitpos = 12, .bitwidth = 4, .name = "EL3",
131 1.1 ryo .info = (const char *[16]) { /* 16=4bit */
132 1.1 ryo [0] = "No EL3",
133 1.1 ryo [1] = "AArch64",
134 1.1 ryo [2] = "AArch64/AArch32"
135 1.1 ryo }
136 1.1 ryo },
137 1.1 ryo {
138 1.1 ryo .bitpos = 16, .bitwidth = 4, .name = "FP",
139 1.1 ryo .info = (const char *[16]) { /* 16=4bit */
140 1.1 ryo [0] = "Floating Point",
141 1.1 ryo [15] = "No Floating Point"
142 1.1 ryo }
143 1.1 ryo },
144 1.1 ryo {
145 1.1 ryo .bitpos = 20, .bitwidth = 4, .name = "AdvSIMD",
146 1.1 ryo .info = (const char *[16]) { /* 16=4bit */
147 1.1 ryo [0] = "Advanced SIMD",
148 1.1 ryo [15] = "No Advanced SIMD"
149 1.1 ryo }
150 1.1 ryo },
151 1.1 ryo {
152 1.1 ryo .bitpos = 24, .bitwidth = 4, .name = "GIC",
153 1.1 ryo .info = (const char *[16]) { /* 16=4bit */
154 1.1 ryo [0] = "No GIC",
155 1.1 ryo [1] = "GICv3"
156 1.1 ryo }
157 1.1 ryo },
158 1.1 ryo { .bitwidth = 0 } /* end of table */
159 1.1 ryo };
160 1.1 ryo
161 1.8 maxv /* ID_AA64PFR1_EL1 - AArch64 Processor Feature Register 1 */
162 1.8 maxv struct fieldinfo id_aa64pfr1_fieldinfo[] = {
163 1.8 maxv {
164 1.8 maxv .bitpos = 0, .bitwidth = 4, .name = "BT",
165 1.8 maxv .info = (const char *[16]) { /* 16=4bit */
166 1.8 maxv [0] = "Branch Target Identification not implemented",
167 1.8 maxv [1] = "Branch Target Identification implemented",
168 1.8 maxv }
169 1.8 maxv },
170 1.8 maxv {
171 1.8 maxv .bitpos = 4, .bitwidth = 4, .name = "SSBS",
172 1.8 maxv .info = (const char *[16]) { /* 16=4bit */
173 1.8 maxv [0] = "Speculative Store Bypassing control not implemented",
174 1.8 maxv [1] = "Speculative Store Bypassing control implemented",
175 1.8 maxv [2] = "Speculative Store Bypassing control implemented, plus MSR/MRS"
176 1.8 maxv }
177 1.8 maxv },
178 1.8 maxv {
179 1.8 maxv .bitpos = 8, .bitwidth = 4, .name = "MTE",
180 1.8 maxv .info = (const char *[16]) { /* 16=4bit */
181 1.8 maxv [0] = "Tagged Memory Extension not implemented",
182 1.8 maxv [1] = "Tagged Memory Extension implemented, EL0 only",
183 1.8 maxv [2] = "Tagged Memory Extension implemented"
184 1.8 maxv }
185 1.8 maxv },
186 1.8 maxv {
187 1.8 maxv .bitpos = 12, .bitwidth = 4, .name = "RAS_frac",
188 1.8 maxv .info = (const char *[16]) { /* 16=4bit */
189 1.8 maxv [0] = "Regular RAS",
190 1.8 maxv [1] = "RAS plus registers",
191 1.8 maxv }
192 1.8 maxv },
193 1.8 maxv { .bitwidth = 0 } /* end of table */
194 1.8 maxv };
195 1.8 maxv
196 1.1 ryo /* ID_AA64ISAR0_EL1 - AArch64 Instruction Set Attribute Register 0 */
197 1.1 ryo struct fieldinfo id_aa64isar0_fieldinfo[] = {
198 1.1 ryo {
199 1.1 ryo .bitpos = 4, .bitwidth = 4, .name = "AES",
200 1.1 ryo .info = (const char *[16]) { /* 16=4bit */
201 1.1 ryo [0] = "No AES",
202 1.1 ryo [1] = "AESE/AESD/AESMC/AESIMC",
203 1.1 ryo [2] = "AESE/AESD/AESMC/AESIMC+PMULL/PMULL2"
204 1.1 ryo }
205 1.1 ryo },
206 1.1 ryo {
207 1.1 ryo .bitpos = 8, .bitwidth = 4, .name = "SHA1",
208 1.1 ryo .info = (const char *[16]) { /* 16=4bit */
209 1.1 ryo [0] = "No SHA1",
210 1.1 ryo [1] = "SHA1C/SHA1P/SHA1M/SHA1H/SHA1SU0/SHA1SU1"
211 1.1 ryo }
212 1.1 ryo },
213 1.1 ryo {
214 1.1 ryo .bitpos = 12, .bitwidth = 4, .name = "SHA2",
215 1.1 ryo .info = (const char *[16]) { /* 16=4bit */
216 1.1 ryo [0] = "No SHA2",
217 1.1 ryo [1] = "SHA256H/SHA256H2/SHA256SU0/SHA256U1"
218 1.1 ryo }
219 1.1 ryo },
220 1.1 ryo {
221 1.1 ryo .bitpos = 16, .bitwidth = 4, .name = "CRC32",
222 1.1 ryo .info = (const char *[16]) { /* 16=4bit */
223 1.1 ryo [0] = "No CRC32",
224 1.1 ryo [1] = "CRC32B/CRC32H/CRC32W/CRC32X"
225 1.1 ryo "/CRC32CB/CRC32CH/CRC32CW/CRC32CX"
226 1.1 ryo }
227 1.1 ryo },
228 1.9 riastrad {
229 1.9 riastrad .bitpos = 60, .bitwidth = 4, .name = "RNDR",
230 1.9 riastrad .info = (const char *[16]) { /* 16=4bit */
231 1.9 riastrad [0] = "No RNDR/RNDRRS",
232 1.9 riastrad [1] = "RNDR/RNDRRS",
233 1.9 riastrad },
234 1.9 riastrad },
235 1.1 ryo { .bitwidth = 0 } /* end of table */
236 1.1 ryo };
237 1.1 ryo
238 1.1 ryo /* ID_AA64MMFR0_EL1 - AArch64 Memory Model Feature Register 0 */
239 1.1 ryo struct fieldinfo id_aa64mmfr0_fieldinfo[] = {
240 1.1 ryo {
241 1.1 ryo .bitpos = 0, .bitwidth = 4, .name = "PARange",
242 1.1 ryo .info = (const char *[16]) { /* 16=4bit */
243 1.1 ryo [0] = "32bits/4GB",
244 1.1 ryo [1] = "36bits/64GB",
245 1.1 ryo [2] = "40bits/1TB",
246 1.1 ryo [3] = "42bits/4TB",
247 1.1 ryo [4] = "44bits/16TB",
248 1.1 ryo [5] = "48bits/256TB"
249 1.1 ryo }
250 1.1 ryo },
251 1.1 ryo {
252 1.1 ryo .bitpos = 4, .bitwidth = 4, .name = "ASIDBit",
253 1.1 ryo .info = (const char *[16]) { /* 16=4bit */
254 1.1 ryo [0] = "8bits",
255 1.1 ryo [2] = "16bits"
256 1.1 ryo }
257 1.1 ryo },
258 1.1 ryo {
259 1.1 ryo .bitpos = 8, .bitwidth = 4, .name = "BigEnd",
260 1.1 ryo .info = (const char *[16]) { /* 16=4bit */
261 1.1 ryo [0] = "No mixed-endian",
262 1.1 ryo [1] = "Mixed-endian"
263 1.1 ryo }
264 1.1 ryo },
265 1.1 ryo {
266 1.1 ryo .bitpos = 12, .bitwidth = 4, .name = "SNSMem",
267 1.1 ryo .info = (const char *[16]) { /* 16=4bit */
268 1.1 ryo [0] = "No distinction B/W Secure and Non-secure Memory",
269 1.1 ryo [1] = "Distinction B/W Secure and Non-secure Memory"
270 1.1 ryo }
271 1.1 ryo },
272 1.1 ryo {
273 1.1 ryo .bitpos = 16, .bitwidth = 4, .name = "BigEndEL0",
274 1.1 ryo .info = (const char *[16]) { /* 16=4bit */
275 1.1 ryo [0] = "No mixed-endian at EL0",
276 1.1 ryo [1] = "Mixed-endian at EL0"
277 1.1 ryo }
278 1.1 ryo },
279 1.1 ryo {
280 1.1 ryo .bitpos = 20, .bitwidth = 4, .name = "TGran16",
281 1.1 ryo .info = (const char *[16]) { /* 16=4bit */
282 1.1 ryo [0] = "No 16KB granule",
283 1.1 ryo [1] = "16KB granule"
284 1.1 ryo }
285 1.1 ryo },
286 1.1 ryo {
287 1.1 ryo .bitpos = 24, .bitwidth = 4, .name = "TGran64",
288 1.1 ryo .info = (const char *[16]) { /* 16=4bit */
289 1.2 ryo [0] = "64KB granule",
290 1.2 ryo [15] = "No 64KB granule"
291 1.1 ryo }
292 1.1 ryo },
293 1.1 ryo {
294 1.1 ryo .bitpos = 28, .bitwidth = 4, .name = "TGran4",
295 1.1 ryo .info = (const char *[16]) { /* 16=4bit */
296 1.1 ryo [0] = "4KB granule",
297 1.1 ryo [15] = "No 4KB granule"
298 1.1 ryo }
299 1.1 ryo },
300 1.1 ryo { .bitwidth = 0 } /* end of table */
301 1.1 ryo };
302 1.1 ryo
303 1.8 maxv /* ID_AA64MMFR1_EL1 - AArch64 Memory Model Feature Register 1 */
304 1.8 maxv struct fieldinfo id_aa64mmfr1_fieldinfo[] = {
305 1.8 maxv {
306 1.8 maxv .bitpos = 0, .bitwidth = 4, .name = "HAFDBS",
307 1.8 maxv .info = (const char *[16]) { /* 16=4bit */
308 1.8 maxv [0] = "Access and Dirty flags not supported",
309 1.8 maxv [1] = "Access flag supported",
310 1.8 maxv [2] = "Access and Dirty flags supported",
311 1.8 maxv }
312 1.8 maxv },
313 1.8 maxv {
314 1.8 maxv .bitpos = 4, .bitwidth = 4, .name = "VMIDBits",
315 1.8 maxv .info = (const char *[16]) { /* 16=4bit */
316 1.8 maxv [0] = "8bits",
317 1.8 maxv [2] = "16bits"
318 1.8 maxv }
319 1.8 maxv },
320 1.8 maxv {
321 1.8 maxv .bitpos = 8, .bitwidth = 4, .name = "VH",
322 1.8 maxv .info = (const char *[16]) { /* 16=4bit */
323 1.8 maxv [0] = "Virtualization Host Extensions not supported",
324 1.8 maxv [1] = "Virtualization Host Extensions supported",
325 1.8 maxv }
326 1.8 maxv },
327 1.8 maxv {
328 1.8 maxv .bitpos = 12, .bitwidth = 4, .name = "HPDS",
329 1.8 maxv .info = (const char *[16]) { /* 16=4bit */
330 1.8 maxv [0] = "Disabling of hierarchical controls not supported",
331 1.8 maxv [1] = "Disabling of hierarchical controls supported",
332 1.8 maxv [2] = "Disabling of hierarchical controls supported, plus PTD"
333 1.8 maxv }
334 1.8 maxv },
335 1.8 maxv {
336 1.8 maxv .bitpos = 16, .bitwidth = 4, .name = "LO",
337 1.8 maxv .info = (const char *[16]) { /* 16=4bit */
338 1.8 maxv [0] = "LORegions not supported",
339 1.8 maxv [1] = "LORegions supported"
340 1.8 maxv }
341 1.8 maxv },
342 1.8 maxv {
343 1.8 maxv .bitpos = 20, .bitwidth = 4, .name = "PAN",
344 1.8 maxv .info = (const char *[16]) { /* 16=4bit */
345 1.8 maxv [0] = "PAN not supported",
346 1.8 maxv [1] = "PAN supported",
347 1.8 maxv [2] = "PAN supported, and instructions supported"
348 1.8 maxv }
349 1.8 maxv },
350 1.8 maxv {
351 1.8 maxv .bitpos = 24, .bitwidth = 4, .name = "SpecSEI",
352 1.8 maxv .info = (const char *[16]) { /* 16=4bit */
353 1.8 maxv [0] = "SError interrupt not supported",
354 1.8 maxv [1] = "SError interrupt supported"
355 1.8 maxv }
356 1.8 maxv },
357 1.8 maxv {
358 1.8 maxv .bitpos = 28, .bitwidth = 4, .name = "XNX",
359 1.8 maxv .info = (const char *[16]) { /* 16=4bit */
360 1.8 maxv [0] = "Distinction between EL0 and EL1 XN control at stage 2 not supported",
361 1.8 maxv [1] = "Distinction between EL0 and EL1 XN control at stage 2 supported"
362 1.8 maxv }
363 1.8 maxv },
364 1.8 maxv { .bitwidth = 0 } /* end of table */
365 1.8 maxv };
366 1.8 maxv
367 1.5 ryo /* ID_AA64DFR0_EL1 - AArch64 Debug Feature Register 0 */
368 1.5 ryo struct fieldinfo id_aa64dfr0_fieldinfo[] = {
369 1.5 ryo {
370 1.5 ryo .bitpos = 0, .bitwidth = 4, .name = "DebugVer",
371 1.5 ryo .info = (const char *[16]) { /* 16=4bit */
372 1.5 ryo [6] = "v8-A debug architecture"
373 1.5 ryo }
374 1.5 ryo },
375 1.5 ryo {
376 1.5 ryo .bitpos = 4, .bitwidth = 4, .name = "TraceVer",
377 1.5 ryo .info = (const char *[16]) { /* 16=4bit */
378 1.5 ryo [0] = "Trace supported",
379 1.5 ryo [1] = "Trace not supported"
380 1.5 ryo }
381 1.5 ryo },
382 1.5 ryo {
383 1.5 ryo .bitpos = 8, .bitwidth = 4, .name = "PMUVer",
384 1.5 ryo .info = (const char *[16]) { /* 16=4bit */
385 1.5 ryo [0] = "No Performance monitor",
386 1.5 ryo [1] = "Performance monitor unit v3"
387 1.5 ryo }
388 1.5 ryo },
389 1.5 ryo { .bitwidth = 0 } /* end of table */
390 1.5 ryo };
391 1.5 ryo
392 1.5 ryo
393 1.1 ryo /* MVFR0_EL1 - Media and VFP Feature Register 0 */
394 1.1 ryo struct fieldinfo mvfr0_fieldinfo[] = {
395 1.1 ryo {
396 1.1 ryo .bitpos = 0, .bitwidth = 4, .name = "SIMDreg",
397 1.1 ryo .info = (const char *[16]) { /* 16=4bit */
398 1.1 ryo [0] = "No SIMD",
399 1.1 ryo [1] = "16x64-bit SIMD",
400 1.1 ryo [2] = "32x64-bit SIMD"
401 1.1 ryo }
402 1.1 ryo },
403 1.1 ryo {
404 1.1 ryo .bitpos = 4, .bitwidth = 4, .name = "FPSP",
405 1.1 ryo .info = (const char *[16]) { /* 16=4bit */
406 1.1 ryo [0] = "No VFP support single precision",
407 1.1 ryo [1] = "VFPv2 support single precision",
408 1.1 ryo [2] = "VFPv2/VFPv3/VFPv4 support single precision"
409 1.1 ryo }
410 1.1 ryo },
411 1.1 ryo {
412 1.1 ryo .bitpos = 8, .bitwidth = 4, .name = "FPDP",
413 1.1 ryo .info = (const char *[16]) { /* 16=4bit */
414 1.1 ryo [0] = "No VFP support double precision",
415 1.1 ryo [1] = "VFPv2 support double precision",
416 1.1 ryo [2] = "VFPv2/VFPv3/VFPv4 support double precision"
417 1.1 ryo }
418 1.1 ryo },
419 1.1 ryo {
420 1.1 ryo .bitpos = 12, .bitwidth = 4, .name = "FPTrap",
421 1.1 ryo .info = (const char *[16]) { /* 16=4bit */
422 1.6 skrll [0] = "No floating point exception trapping support",
423 1.1 ryo [1] = "VFPv2/VFPv3/VFPv4 support exception trapping"
424 1.1 ryo }
425 1.1 ryo },
426 1.1 ryo {
427 1.1 ryo .bitpos = 16, .bitwidth = 4, .name = "FPDivide",
428 1.1 ryo .info = (const char *[16]) { /* 16=4bit */
429 1.1 ryo [0] = "VDIV not supported",
430 1.1 ryo [1] = "VDIV supported"
431 1.1 ryo }
432 1.1 ryo },
433 1.1 ryo {
434 1.1 ryo .bitpos = 20, .bitwidth = 4, .name = "FPSqrt",
435 1.1 ryo .info = (const char *[16]) { /* 16=4bit */
436 1.1 ryo [0] = "VSQRT not supported",
437 1.1 ryo [1] = "VSQRT supported"
438 1.1 ryo }
439 1.1 ryo },
440 1.1 ryo {
441 1.1 ryo .bitpos = 24, .bitwidth = 4, .name = "FPShVec",
442 1.1 ryo .info = (const char *[16]) { /* 16=4bit */
443 1.1 ryo [0] = "Short Vectors not supported",
444 1.1 ryo [1] = "Short Vectors supported"
445 1.1 ryo }
446 1.1 ryo },
447 1.1 ryo {
448 1.1 ryo .bitpos = 28, .bitwidth = 4, .name = "FPRound",
449 1.1 ryo .info = (const char *[16]) { /* 16=4bit */
450 1.1 ryo [0] = "Only Round to Nearest mode",
451 1.1 ryo [1] = "All rounding modes"
452 1.1 ryo }
453 1.1 ryo },
454 1.1 ryo { .bitwidth = 0 } /* end of table */
455 1.1 ryo };
456 1.1 ryo
457 1.1 ryo /* MVFR1_EL1 - Media and VFP Feature Register 1 */
458 1.1 ryo struct fieldinfo mvfr1_fieldinfo[] = {
459 1.1 ryo {
460 1.1 ryo .bitpos = 0, .bitwidth = 4, .name = "FPFtZ",
461 1.1 ryo .info = (const char *[16]) { /* 16=4bit */
462 1.1 ryo [0] = "only the Flush-to-Zero",
463 1.1 ryo [1] = "full Denormalized number arithmetic"
464 1.1 ryo }
465 1.1 ryo },
466 1.1 ryo {
467 1.1 ryo .bitpos = 4, .bitwidth = 4, .name = "FPDNan",
468 1.1 ryo .info = (const char *[16]) { /* 16=4bit */
469 1.1 ryo [0] = "Default NaN",
470 1.1 ryo [1] = "Propagation of NaN"
471 1.1 ryo }
472 1.1 ryo },
473 1.1 ryo {
474 1.1 ryo .bitpos = 8, .bitwidth = 4, .name = "SIMDLS",
475 1.1 ryo .info = (const char *[16]) { /* 16=4bit */
476 1.1 ryo [0] = "No Advanced SIMD Load/Store",
477 1.1 ryo [1] = "Advanced SIMD Load/Store"
478 1.1 ryo }
479 1.1 ryo },
480 1.1 ryo {
481 1.1 ryo .bitpos = 12, .bitwidth = 4, .name = "SIMDInt",
482 1.1 ryo .info = (const char *[16]) { /* 16=4bit */
483 1.1 ryo [0] = "No Advanced SIMD Integer",
484 1.1 ryo [1] = "Advanced SIMD Integer"
485 1.1 ryo }
486 1.1 ryo },
487 1.1 ryo {
488 1.1 ryo .bitpos = 16, .bitwidth = 4, .name = "SIMDSP",
489 1.1 ryo .info = (const char *[16]) { /* 16=4bit */
490 1.1 ryo [0] = "No Advanced SIMD single precision",
491 1.1 ryo [1] = "Advanced SIMD single precision"
492 1.1 ryo }
493 1.1 ryo },
494 1.1 ryo {
495 1.1 ryo .bitpos = 20, .bitwidth = 4, .name = "SIMDHP",
496 1.1 ryo .info = (const char *[16]) { /* 16=4bit */
497 1.1 ryo [0] = "No Advanced SIMD half precision",
498 1.1 ryo [1] = "Advanced SIMD half precision"
499 1.1 ryo }
500 1.1 ryo },
501 1.1 ryo {
502 1.1 ryo .bitpos = 24, .bitwidth = 4, .name = "FPHP",
503 1.1 ryo .info = (const char *[16]) { /* 16=4bit */
504 1.1 ryo [0] = "No half precision conversion",
505 1.1 ryo [1] = "half/single precision conversion",
506 1.1 ryo [2] = "half/single/double precision conversion"
507 1.1 ryo }
508 1.1 ryo },
509 1.1 ryo {
510 1.1 ryo .bitpos = 28, .bitwidth = 4, .name = "SIMDFMAC",
511 1.1 ryo .info = (const char *[16]) { /* 16=4bit */
512 1.1 ryo [0] = "No Fused Multiply-Accumulate",
513 1.1 ryo [1] = "Fused Multiply-Accumulate"
514 1.1 ryo }
515 1.1 ryo },
516 1.1 ryo { .bitwidth = 0 } /* end of table */
517 1.1 ryo };
518 1.1 ryo
519 1.1 ryo /* MVFR2_EL1 - Media and VFP Feature Register 2 */
520 1.1 ryo struct fieldinfo mvfr2_fieldinfo[] = {
521 1.1 ryo {
522 1.1 ryo .bitpos = 0, .bitwidth = 4, .name = "SIMDMisc",
523 1.1 ryo .info = (const char *[16]) { /* 16=4bit */
524 1.1 ryo [0] = "No miscellaneous features",
525 1.1 ryo [1] = "Conversion to Integer w/Directed Rounding modes",
526 1.1 ryo [2] = "Conversion to Integer w/Directed Rounding modes"
527 1.1 ryo ", Round to Integral floating point",
528 1.1 ryo [3] = "Conversion to Integer w/Directed Rounding modes"
529 1.1 ryo ", Round to Integral floating point"
530 1.1 ryo ", MaxNum and MinNum"
531 1.1 ryo }
532 1.1 ryo },
533 1.1 ryo {
534 1.1 ryo .bitpos = 4, .bitwidth = 4, .name = "FPMisc",
535 1.1 ryo .info = (const char *[16]) { /* 16=4bit */
536 1.1 ryo [0] = "No miscellaneous features",
537 1.1 ryo [1] = "Floating point selection",
538 1.1 ryo [2] = "Floating point selection"
539 1.1 ryo ", Conversion to Integer w/Directed Rounding modes",
540 1.1 ryo [3] = "Floating point selection"
541 1.1 ryo ", Conversion to Integer w/Directed Rounding modes"
542 1.1 ryo ", Round to Integral floating point",
543 1.1 ryo [4] = "Floating point selection"
544 1.1 ryo ", Conversion to Integer w/Directed Rounding modes"
545 1.1 ryo ", Round to Integral floating point"
546 1.1 ryo ", MaxNum and MinNum"
547 1.1 ryo }
548 1.1 ryo },
549 1.1 ryo { .bitwidth = 0 } /* end of table */
550 1.1 ryo };
551 1.1 ryo
552 1.1 ryo static void
553 1.1 ryo print_fieldinfo(const char *cpuname, const char *setname,
554 1.1 ryo struct fieldinfo *fieldinfo, uint64_t data)
555 1.1 ryo {
556 1.1 ryo uint64_t v;
557 1.1 ryo const char *info;
558 1.1 ryo int i;
559 1.1 ryo
560 1.1 ryo #define WIDTHMASK(w) (0xffffffffffffffffULL >> (64 - (w)))
561 1.1 ryo
562 1.1 ryo for (i = 0; fieldinfo[i].bitwidth != 0; i++) {
563 1.1 ryo v = (data >> fieldinfo[i].bitpos) &
564 1.1 ryo WIDTHMASK(fieldinfo[i].bitwidth);
565 1.1 ryo
566 1.1 ryo info = fieldinfo[i].info[v];
567 1.1 ryo if (info == NULL)
568 1.1 ryo printf("%s: %s: %s: 0x%"PRIx64"\n",
569 1.1 ryo cpuname, setname, fieldinfo[i].name, v);
570 1.1 ryo else
571 1.1 ryo printf("%s: %s: %s: %s\n",
572 1.1 ryo cpuname, setname, fieldinfo[i].name, info);
573 1.1 ryo }
574 1.1 ryo }
575 1.1 ryo
576 1.1 ryo /* MIDR_EL1 - Main ID Register */
577 1.1 ryo static void
578 1.1 ryo identify_midr(const char *cpuname, uint32_t cpuid)
579 1.1 ryo {
580 1.1 ryo unsigned int i;
581 1.1 ryo uint32_t implid, cpupart, variant, revision;
582 1.1 ryo const char *implementer = NULL;
583 1.1 ryo static char implbuf[128];
584 1.1 ryo
585 1.1 ryo implid = cpuid & CPU_ID_IMPLEMENTOR_MASK;
586 1.1 ryo cpupart = cpuid & CPU_PARTMASK;
587 1.1 ryo variant = __SHIFTOUT(cpuid, CPU_ID_VARIANT_MASK);
588 1.1 ryo revision = __SHIFTOUT(cpuid, CPU_ID_REVISION_MASK);
589 1.1 ryo
590 1.1 ryo for (i = 0; i < __arraycount(implids); i++) {
591 1.1 ryo if (implid == implids[i].impl_id) {
592 1.1 ryo implementer = implids[i].impl_name;
593 1.1 ryo }
594 1.1 ryo }
595 1.1 ryo if (implementer == NULL) {
596 1.1 ryo snprintf(implbuf, sizeof(implbuf), "unknown implementer: 0x%02x",
597 1.1 ryo implid >> 24);
598 1.1 ryo implementer = implbuf;
599 1.1 ryo }
600 1.1 ryo
601 1.1 ryo for (i = 0; i < __arraycount(cpuids); i++) {
602 1.1 ryo if (cpupart == cpuids[i].cpu_partnum) {
603 1.1 ryo printf("%s: %s, %s r%dp%d (%s %s core)\n",
604 1.1 ryo cpuname, implementer,
605 1.1 ryo cpuids[i].cpu_name, variant, revision,
606 1.1 ryo cpuids[i].cpu_class,
607 1.1 ryo cpuids[i].cpu_architecture);
608 1.1 ryo return;
609 1.1 ryo }
610 1.1 ryo }
611 1.1 ryo printf("%s: unknown CPU ID: 0x%08x\n", cpuname, cpuid);
612 1.1 ryo }
613 1.1 ryo
614 1.1 ryo /* REVIDR_EL1 - Revision ID Register */
615 1.1 ryo static void
616 1.1 ryo identify_revidr(const char *cpuname, uint32_t revidr)
617 1.1 ryo {
618 1.1 ryo printf("%s: revision: 0x%08x\n", cpuname, revidr);
619 1.1 ryo }
620 1.1 ryo
621 1.1 ryo /* MPIDR_EL1 - Multiprocessor Affinity Register */
622 1.1 ryo static void
623 1.1 ryo identify_mpidr(const char *cpuname, uint32_t mpidr)
624 1.1 ryo {
625 1.1 ryo const char *setname = "multiprocessor affinity";
626 1.1 ryo
627 1.1 ryo printf("%s: %s: Affinity-Level: %"PRIu64"-%"PRIu64"-%"PRIu64"-%"PRIu64"\n",
628 1.1 ryo cpuname, setname,
629 1.1 ryo __SHIFTOUT(mpidr, MPIDR_AFF3),
630 1.1 ryo __SHIFTOUT(mpidr, MPIDR_AFF2),
631 1.1 ryo __SHIFTOUT(mpidr, MPIDR_AFF1),
632 1.1 ryo __SHIFTOUT(mpidr, MPIDR_AFF0));
633 1.1 ryo
634 1.1 ryo if ((mpidr & MPIDR_U) == 0)
635 1.1 ryo printf("%s: %s: Multiprocessor system\n", cpuname, setname);
636 1.1 ryo else
637 1.1 ryo printf("%s: %s: Uniprocessor system\n", cpuname, setname);
638 1.1 ryo
639 1.1 ryo if ((mpidr & MPIDR_MT) == 0)
640 1.1 ryo printf("%s: %s: Core Independent\n", cpuname, setname);
641 1.1 ryo else
642 1.1 ryo printf("%s: %s: Multi-Threading\n", cpuname, setname);
643 1.1 ryo
644 1.1 ryo }
645 1.1 ryo
646 1.5 ryo /* AA64DFR0 - Debug feature register 0 */
647 1.5 ryo static void
648 1.5 ryo identify_dfr0(const char *cpuname, uint64_t dfr0)
649 1.5 ryo {
650 1.5 ryo const char *setname = "debug feature 0";
651 1.5 ryo
652 1.5 ryo printf("%s: %s: CTX_CMPs: %lu context-aware breakpoints\n",
653 1.5 ryo cpuname, setname, __SHIFTOUT(dfr0, ID_AA64DFR0_EL1_CTX_CMPS) + 1);
654 1.5 ryo printf("%s: %s: WRPs: %lu watchpoints\n",
655 1.5 ryo cpuname, setname, __SHIFTOUT(dfr0, ID_AA64DFR0_EL1_WRPS) + 1);
656 1.5 ryo printf("%s: %s: BRPs: %lu breakpoints\n",
657 1.5 ryo cpuname, setname, __SHIFTOUT(dfr0, ID_AA64DFR0_EL1_BRPS) + 1);
658 1.5 ryo print_fieldinfo(cpuname, setname,
659 1.5 ryo id_aa64dfr0_fieldinfo, dfr0);
660 1.5 ryo }
661 1.5 ryo
662 1.1 ryo void
663 1.1 ryo identifycpu(int fd, const char *cpuname)
664 1.1 ryo {
665 1.3 mrg char path[128];
666 1.1 ryo size_t len;
667 1.5 ryo #define SYSCTL_CPU_ID_MAXSIZE 64
668 1.5 ryo uint64_t sysctlbuf[SYSCTL_CPU_ID_MAXSIZE];
669 1.5 ryo struct aarch64_sysctl_cpu_id *id =
670 1.5 ryo (struct aarch64_sysctl_cpu_id *)sysctlbuf;
671 1.1 ryo
672 1.3 mrg snprintf(path, sizeof path, "machdep.%s.cpu_id", cpuname);
673 1.5 ryo len = sizeof(sysctlbuf);
674 1.5 ryo if (sysctlbyname(path, id, &len, 0, 0) == -1)
675 1.3 mrg err(1, "couldn't get %s", path);
676 1.5 ryo if (len != sizeof(struct aarch64_sysctl_cpu_id))
677 1.5 ryo fprintf(stderr, "Warning: kernel version bumped?\n");
678 1.5 ryo
679 1.5 ryo if (verbose) {
680 1.5 ryo printf("%s: MIDR_EL1: 0x%08"PRIx64"\n",
681 1.5 ryo cpuname, id->ac_midr);
682 1.5 ryo printf("%s: MPIDR_EL1: 0x%016"PRIx64"\n",
683 1.5 ryo cpuname, id->ac_mpidr);
684 1.5 ryo printf("%s: ID_AA64DFR0_EL1: 0x%016"PRIx64"\n",
685 1.5 ryo cpuname, id->ac_aa64dfr0);
686 1.5 ryo printf("%s: ID_AA64DFR1_EL1: 0x%016"PRIx64"\n",
687 1.5 ryo cpuname, id->ac_aa64dfr1);
688 1.5 ryo printf("%s: ID_AA64ISAR0_EL1: 0x%016"PRIx64"\n",
689 1.5 ryo cpuname, id->ac_aa64isar0);
690 1.5 ryo printf("%s: ID_AA64ISAR1_EL1: 0x%016"PRIx64"\n",
691 1.5 ryo cpuname, id->ac_aa64isar1);
692 1.5 ryo printf("%s: ID_AA64MMFR0_EL1: 0x%016"PRIx64"\n",
693 1.5 ryo cpuname, id->ac_aa64mmfr0);
694 1.5 ryo printf("%s: ID_AA64MMFR1_EL1: 0x%016"PRIx64"\n",
695 1.5 ryo cpuname, id->ac_aa64mmfr1);
696 1.5 ryo printf("%s: ID_AA64MMFR2_EL1: 0x%016"PRIx64"\n",
697 1.5 ryo cpuname, id->ac_aa64mmfr2);
698 1.5 ryo printf("%s: ID_AA64PFR0_EL1: 0x%08"PRIx64"\n",
699 1.5 ryo cpuname, id->ac_aa64pfr0);
700 1.5 ryo printf("%s: ID_AA64PFR1_EL1: 0x%08"PRIx64"\n",
701 1.5 ryo cpuname, id->ac_aa64pfr1);
702 1.5 ryo printf("%s: ID_AA64ZFR0_EL1: 0x%016"PRIx64"\n",
703 1.5 ryo cpuname, id->ac_aa64zfr0);
704 1.5 ryo printf("%s: MVFR0_EL1: 0x%08"PRIx32"\n",
705 1.5 ryo cpuname, id->ac_mvfr0);
706 1.5 ryo printf("%s: MVFR1_EL1: 0x%08"PRIx32"\n",
707 1.5 ryo cpuname, id->ac_mvfr1);
708 1.5 ryo printf("%s: MVFR2_EL1: 0x%08"PRIx32"\n",
709 1.5 ryo cpuname, id->ac_mvfr2);
710 1.5 ryo }
711 1.3 mrg
712 1.5 ryo identify_midr(cpuname, id->ac_midr);
713 1.5 ryo identify_revidr(cpuname, id->ac_revidr);
714 1.5 ryo identify_mpidr(cpuname, id->ac_mpidr);
715 1.3 mrg print_fieldinfo(cpuname, "isa features 0",
716 1.5 ryo id_aa64isar0_fieldinfo, id->ac_aa64isar0);
717 1.3 mrg print_fieldinfo(cpuname, "memory model 0",
718 1.5 ryo id_aa64mmfr0_fieldinfo, id->ac_aa64mmfr0);
719 1.8 maxv print_fieldinfo(cpuname, "memory model 1",
720 1.8 maxv id_aa64mmfr1_fieldinfo, id->ac_aa64mmfr1);
721 1.3 mrg print_fieldinfo(cpuname, "processor feature 0",
722 1.5 ryo id_aa64pfr0_fieldinfo, id->ac_aa64pfr0);
723 1.8 maxv print_fieldinfo(cpuname, "processor feature 1",
724 1.8 maxv id_aa64pfr1_fieldinfo, id->ac_aa64pfr1);
725 1.5 ryo identify_dfr0(cpuname, id->ac_aa64dfr0);
726 1.3 mrg
727 1.3 mrg print_fieldinfo(cpuname, "media and VFP features 0",
728 1.5 ryo mvfr0_fieldinfo, id->ac_mvfr0);
729 1.3 mrg print_fieldinfo(cpuname, "media and VFP features 1",
730 1.5 ryo mvfr1_fieldinfo, id->ac_mvfr1);
731 1.3 mrg print_fieldinfo(cpuname, "media and VFP features 2",
732 1.5 ryo mvfr2_fieldinfo, id->ac_mvfr2);
733 1.1 ryo }
734 1.1 ryo
735 1.1 ryo bool
736 1.1 ryo identifycpu_bind(void)
737 1.1 ryo {
738 1.3 mrg return false;
739 1.1 ryo }
740 1.1 ryo
741 1.1 ryo int
742 1.1 ryo ucodeupdate_check(int fd, struct cpu_ucode *uc)
743 1.1 ryo {
744 1.1 ryo return 0;
745 1.1 ryo }
746