Home | History | Annotate | Line # | Download | only in arch
aarch64.c revision 1.15
      1 /*	$NetBSD: aarch64.c,v 1.15 2021/05/17 18:43:18 riastradh Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 2018 Ryo Shimizu <ryo (at) nerv.org>
      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
     18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     19  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
     20  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     22  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     24  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     25  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     26  * POSSIBILITY OF SUCH DAMAGE.
     27  */
     28 
     29 #include <sys/cdefs.h>
     30 
     31 #ifndef lint
     32 __RCSID("$NetBSD: aarch64.c,v 1.15 2021/05/17 18:43:18 riastradh Exp $");
     33 #endif /* no lint */
     34 
     35 #include <sys/types.h>
     36 #include <sys/cpuio.h>
     37 #include <sys/sysctl.h>
     38 #include <stdio.h>
     39 #include <stdbool.h>
     40 #include <stdlib.h>
     41 #include <string.h>
     42 #include <inttypes.h>
     43 #include <err.h>
     44 
     45 #include <arm/cputypes.h>
     46 #include <aarch64/armreg.h>
     47 
     48 #include "../cpuctl.h"
     49 
     50 struct cpuidtab {
     51 	uint32_t cpu_partnum;
     52 	const char *cpu_name;
     53 	const char *cpu_class;
     54 	const char *cpu_architecture;
     55 };
     56 
     57 struct impltab {
     58 	uint32_t impl_id;
     59 	const char *impl_name;
     60 };
     61 
     62 struct fieldinfo {
     63 	unsigned int flags;
     64 #define FIELDINFO_FLAGS_DEC	0x0001
     65 #define FIELDINFO_FLAGS_4LOG2	0x0002
     66 	unsigned char bitpos;
     67 	unsigned char bitwidth;
     68 	const char *name;
     69 	const char * const *info;
     70 };
     71 
     72 
     73 #define CPU_PARTMASK	(CPU_ID_IMPLEMENTOR_MASK | CPU_ID_PARTNO_MASK)
     74 const struct cpuidtab cpuids[] = {
     75 	{ CPU_ID_CORTEXA35R0 & CPU_PARTMASK, "Cortex-A35", "Arm", "v8-A" },
     76 	{ CPU_ID_CORTEXA53R0 & CPU_PARTMASK, "Cortex-A53", "Arm", "v8-A" },
     77 	{ CPU_ID_CORTEXA57R0 & CPU_PARTMASK, "Cortex-A57", "Arm", "v8-A" },
     78 	{ CPU_ID_CORTEXA55R1 & CPU_PARTMASK, "Cortex-A55", "Arm", "v8.2-A+" },
     79 	{ CPU_ID_CORTEXA65R0 & CPU_PARTMASK, "Cortex-A65", "Arm", "v8.2-A+" },
     80 	{ CPU_ID_CORTEXA72R0 & CPU_PARTMASK, "Cortex-A72", "Arm", "v8-A" },
     81 	{ CPU_ID_CORTEXA73R0 & CPU_PARTMASK, "Cortex-A73", "Arm", "v8-A" },
     82 	{ CPU_ID_CORTEXA75R2 & CPU_PARTMASK, "Cortex-A75", "Arm", "v8.2-A+" },
     83 	{ CPU_ID_CORTEXA76R3 & CPU_PARTMASK, "Cortex-A76", "Arm", "v8.2-A+" },
     84 	{ CPU_ID_CORTEXA76AER1 & CPU_PARTMASK, "Cortex-A76AE", "Arm", "v8.2-A+" },
     85 	{ CPU_ID_CORTEXA77R0 & CPU_PARTMASK, "Cortex-A77", "Arm", "v8.2-A+" },
     86 	{ CPU_ID_NVIDIADENVER2 & CPU_PARTMASK, "Denver2", "NVIDIA", "v8-A" },
     87 	{ CPU_ID_EMAG8180 & CPU_PARTMASK, "eMAG", "Ampere", "v8-A" },
     88 	{ CPU_ID_NEOVERSEE1R1 & CPU_PARTMASK, "Neoverse E1", "Arm", "v8.2-A+" },
     89 	{ CPU_ID_NEOVERSEN1R3 & CPU_PARTMASK, "Neoverse N1", "Arm", "v8.2-A+" },
     90 	{ CPU_ID_THUNDERXRX, "ThunderX", "Cavium", "v8-A" },
     91 	{ CPU_ID_THUNDERX81XXRX, "ThunderX CN81XX", "Cavium", "v8-A" },
     92 	{ CPU_ID_THUNDERX83XXRX, "ThunderX CN83XX", "Cavium", "v8-A" },
     93 	{ CPU_ID_THUNDERX2RX, "ThunderX2", "Marvell", "v8.1-A" },
     94 };
     95 
     96 const struct impltab implids[] = {
     97 	{ CPU_ID_ARM_LTD,	"ARM Limited"				},
     98 	{ CPU_ID_BROADCOM,	"Broadcom Corporation"			},
     99 	{ CPU_ID_CAVIUM,	"Cavium Inc."				},
    100 	{ CPU_ID_DEC,		"Digital Equipment Corporation"		},
    101 	{ CPU_ID_INFINEON,	"Infineon Technologies AG"		},
    102 	{ CPU_ID_MOTOROLA,	"Motorola or Freescale Semiconductor Inc." },
    103 	{ CPU_ID_NVIDIA,	"NVIDIA Corporation"			},
    104 	{ CPU_ID_APM,		"Applied Micro Circuits Corporation"	},
    105 	{ CPU_ID_QUALCOMM,	"Qualcomm Inc."				},
    106 	{ CPU_ID_SAMSUNG,	"SAMSUNG"				},
    107 	{ CPU_ID_TI,		"Texas Instruments"			},
    108 	{ CPU_ID_MARVELL,	"Marvell International Ltd."		},
    109 	{ CPU_ID_APPLE,		"Apple Inc."				},
    110 	{ CPU_ID_FARADAY,	"Faraday Technology Corporation"	},
    111 	{ CPU_ID_INTEL,		"Intel Corporation"			}
    112 };
    113 
    114 /* ID_AA64PFR0_EL1 - AArch64 Processor Feature Register 0 */
    115 struct fieldinfo id_aa64pfr0_fieldinfo[] = {
    116 	{
    117 		.bitpos = 0, .bitwidth = 4, .name = "EL0",
    118 		.info = (const char *[16]) { /* 16=4bit */
    119 			[0] = "No EL0",
    120 			[1] = "AArch64",
    121 			[2] = "AArch64/AArch32"
    122 		}
    123 	},
    124 	{
    125 		.bitpos = 4, .bitwidth = 4, .name = "EL1",
    126 		.info = (const char *[16]) { /* 16=4bit */
    127 			[0] = "No EL1",
    128 			[1] = "AArch64",
    129 			[2] = "AArch64/AArch32"
    130 		}
    131 	},
    132 	{
    133 		.bitpos = 8, .bitwidth = 4, .name = "EL2",
    134 		.info = (const char *[16]) { /* 16=4bit */
    135 			[0] = "No EL2",
    136 			[1] = "AArch64",
    137 			[2] = "AArch64/AArch32"
    138 		}
    139 	},
    140 	{
    141 		.bitpos = 12, .bitwidth = 4, .name = "EL3",
    142 		.info = (const char *[16]) { /* 16=4bit */
    143 			[0] = "No EL3",
    144 			[1] = "AArch64",
    145 			[2] = "AArch64/AArch32"
    146 		}
    147 	},
    148 	{
    149 		.bitpos = 16, .bitwidth = 4, .name = "FP",
    150 		.info = (const char *[16]) { /* 16=4bit */
    151 			[0] = "Floating Point",
    152 			[1] = "Floating Point including half-precision support",
    153 			[15] = "No Floating Point"
    154 		}
    155 	},
    156 	{
    157 		.bitpos = 20, .bitwidth = 4, .name = "AdvSIMD",
    158 		.info = (const char *[16]) { /* 16=4bit */
    159 			[0] = "Advanced SIMD",
    160 			[1] = "Advanced SIMD including half-precision support",
    161 			[15] = "No Advanced SIMD"
    162 		}
    163 	},
    164 	{
    165 		.bitpos = 24, .bitwidth = 4, .name = "GIC",
    166 		.info = (const char *[16]) { /* 16=4bit */
    167 			[0] = "GIC CPU interface sysregs not implemented",
    168 			[1] = "GIC CPU interface sysregs v3.0/4.0 supported",
    169 			[3] = "GIC CPU interface sysregs v4.1 supported"
    170 		}
    171 	},
    172 	{
    173 		.bitpos = 28, .bitwidth = 4, .name = "RAS",
    174 		.info = (const char *[16]) { /* 16=4bit */
    175 			[0] = "Reliability/Availability/Serviceability not supported",
    176 			[1] = "Reliability/Availability/Serviceability supported",
    177 			[2] = "Reliability/Availability/Serviceability ARMv8.4 supported",
    178 		},
    179 	},
    180 	{
    181 		.bitpos = 32, .bitwidth = 4, .name = "SVE",
    182 		.info = (const char *[16]) { /* 16=4bit */
    183 			[0] = "Scalable Vector Extensions not implemented",
    184 			[1] = "Scalable Vector Extensions implemented",
    185 		},
    186 	},
    187 	{
    188 		.bitpos = 36, .bitwidth = 4, .name = "SEL2",
    189 		.info = (const char *[16]) { /* 16=4bit */
    190 			[0] = "Secure EL2 not implemented",
    191 			[1] = "Secure EL2 implemented",
    192 		},
    193 	},
    194 	{
    195 		.bitpos = 40, .bitwidth = 4, .name = "MPAM",
    196 		.info = (const char *[16]) { /* 16=4bit */
    197 			[0] = "Memory Partitioning and Monitoring not implemented",
    198 			[1] = "Memory Partitioning and Monitoring implemented",
    199 		},
    200 	},
    201 	{
    202 		.bitpos = 44, .bitwidth = 4, .name = "AMU",
    203 		.info = (const char *[16]) { /* 16=4bit */
    204 			[0] = "Activity Monitors Extension not implemented",
    205 			[1] = "Activity Monitors Extension v1 ARMv8.4",
    206 			[2] = "Activity Monitors Extension v1 ARMv8.6",
    207 		},
    208 	},
    209 	{
    210 		.bitpos = 48, .bitwidth = 4, .name = "DIT",
    211 		.info = (const char *[16]) { /* 16=4bit */
    212 			[0] = "No Data-Independent Timing guarantees",
    213 			[1] = "Data-Independent Timing guaranteed by PSTATE.DIT",
    214 		},
    215 	},
    216 	{
    217 		.bitpos = 56, .bitwidth = 4, .name = "CSV2",
    218 		.info = (const char *[16]) { /* 16=4bit */
    219 			[0] = "Branch prediction might be Spectred",
    220 			[1] = "Branch prediction maybe not Spectred",
    221 			[2] = "Branch prediction probably not Spectred",
    222 		},
    223 	},
    224 	{
    225 		.bitpos = 60, .bitwidth = 4, .name = "CSV3",
    226 		.info = (const char *[16]) { /* 16=4bit */
    227 			[0] = "Faults might be Spectred",
    228 			[1] = "Faults maybe not Spectred",
    229 			[2] = "Faults probably not Spectred",
    230 		},
    231 	},
    232 	{ .bitwidth = 0 }	/* end of table */
    233 };
    234 
    235 /* ID_AA64PFR1_EL1 - AArch64 Processor Feature Register 1 */
    236 struct fieldinfo id_aa64pfr1_fieldinfo[] = {
    237 	{
    238 		.bitpos = 0, .bitwidth = 4, .name = "BT",
    239 		.info = (const char *[16]) { /* 16=4bit */
    240 			[0] = "Branch Target Identification not implemented",
    241 			[1] = "Branch Target Identification implemented",
    242 		}
    243 	},
    244 	{
    245 		.bitpos = 4, .bitwidth = 4, .name = "SSBS",
    246 		.info = (const char *[16]) { /* 16=4bit */
    247 			[0] = "Speculative Store Bypassing control not implemented",
    248 			[1] = "Speculative Store Bypassing control implemented",
    249 			[2] = "Speculative Store Bypassing control implemented, plus MSR/MRS"
    250 		}
    251 	},
    252 	{
    253 		.bitpos = 8, .bitwidth = 4, .name = "MTE",
    254 		.info = (const char *[16]) { /* 16=4bit */
    255 			[0] = "Tagged Memory Extension not implemented",
    256 			[1] = "Tagged Memory Extension implemented, EL0 only",
    257 			[2] = "Tagged Memory Extension implemented"
    258 		}
    259 	},
    260 	{
    261 		.bitpos = 12, .bitwidth = 4, .name = "RAS_frac",
    262 		.info = (const char *[16]) { /* 16=4bit */
    263 			[0] = "Regular RAS",
    264 			[1] = "RAS plus registers",
    265 		}
    266 	},
    267 	{ .bitwidth = 0 }	/* end of table */
    268 };
    269 
    270 /* ID_AA64ISAR0_EL1 - AArch64 Instruction Set Attribute Register 0 */
    271 struct fieldinfo id_aa64isar0_fieldinfo[] = {
    272 	{
    273 		.bitpos = 4, .bitwidth = 4, .name = "AES",
    274 		.info = (const char *[16]) { /* 16=4bit */
    275 			[0] = "No AES",
    276 			[1] = "AESE/AESD/AESMC/AESIMC",
    277 			[2] = "AESE/AESD/AESMC/AESIMC+PMULL/PMULL2"
    278 		}
    279 	},
    280 	{
    281 		.bitpos = 8, .bitwidth = 4, .name = "SHA1",
    282 		.info = (const char *[16]) { /* 16=4bit */
    283 			[0] = "No SHA1",
    284 			[1] = "SHA1C/SHA1P/SHA1M/SHA1H/SHA1SU0/SHA1SU1"
    285 		}
    286 	},
    287 	{
    288 		.bitpos = 12, .bitwidth = 4, .name = "SHA2",
    289 		.info = (const char *[16]) { /* 16=4bit */
    290 			[0] = "No SHA2",
    291 			[1] = "SHA256H/SHA256H2/SHA256SU0/SHA256U1"
    292 		}
    293 	},
    294 	{
    295 		.bitpos = 16, .bitwidth = 4, .name = "CRC32",
    296 		.info = (const char *[16]) { /* 16=4bit */
    297 			[0] = "No CRC32",
    298 			[1] = "CRC32B/CRC32H/CRC32W/CRC32X"
    299 			    "/CRC32CB/CRC32CH/CRC32CW/CRC32CX"
    300 		}
    301 	},
    302 	{
    303 		.bitpos = 20, .bitwidth = 4, .name = "Atomic",
    304 		.info = (const char *[16]) { /* 16=4bit */
    305 			[0] = "No Atomic",
    306 			[1] = "LDADD/LDCLR/LDEOR/LDSET/LDSMAX/LDSMIN"
    307 			    "/LDUMAX/LDUMIN/CAS/CASP/SWP",
    308 		}
    309 	},
    310 	{
    311 		.bitpos = 28, .bitwidth = 4, .name = "RDM",
    312 		.info = (const char *[16]) { /* 16=4bit */
    313 			[0] = "No RDMA",
    314 			[1] = "SQRDMLAH/SQRDMLSH",
    315 		}
    316 	},
    317 	{
    318 		.bitpos = 32, .bitwidth = 4, .name = "SHA3",
    319 		.info = (const char *[16]) { /* 16=4bit */
    320 			[0] = "No SHA3",
    321 			[1] = "EOR3/RAX1/XAR/BCAX",
    322 		}
    323 	},
    324 	{
    325 		.bitpos = 36, .bitwidth = 4, .name = "SM3",
    326 		.info = (const char *[16]) { /* 16=4bit */
    327 			[0] = "No SM3",
    328 			[1] = "SM3SS1/SM3TT1A/SM3TT1B/SM3TT2A/SM3TT2B"
    329 			    "/SM3PARTW1/SM3PARTW2",
    330 		}
    331 	},
    332 	{
    333 		.bitpos = 40, .bitwidth = 4, .name = "SM4",
    334 		.info = (const char *[16]) { /* 16=4bit */
    335 			[0] = "No SM4",
    336 			[1] = "SM4E/SM4EKEY",
    337 		}
    338 	},
    339 	{
    340 		.bitpos = 44, .bitwidth = 4, .name = "DP",
    341 		.info = (const char *[16]) { /* 16=4bit */
    342 			[0] = "No Dot Product",
    343 			[1] = "UDOT/SDOT",
    344 		}
    345 	},
    346 	{
    347 		.bitpos = 48, .bitwidth = 4, .name = "FHM",
    348 		.info = (const char *[16]) { /* 16=4bit */
    349 			[0] = "No FHM",
    350 			[1] = "FMLAL/FMLSL",
    351 		}
    352 	},
    353 	{
    354 		.bitpos = 52, .bitwidth = 4, .name = "TS",
    355 		.info = (const char *[16]) { /* 16=4bit */
    356 			[0] = "No TS",
    357 			[1] = "CFINV/RMIF/SETF16/SETF8",
    358 			[2] = "CFINV/RMIF/SETF16/SETF8/AXFLAG/XAFLAG",
    359 		}
    360 	},
    361 	{
    362 		.bitpos = 56, .bitwidth = 4, .name = "TLBI",
    363 		.info = (const char *[16]) { /* 16=4bit */
    364 			[0] = "No outer shareable and TLB range maintenance"
    365 			    " instructions",
    366 			[1] = "Outer shareable TLB maintenance instructions",
    367 			[2] = "Outer shareable and TLB range maintenance"
    368 			    " instructions",
    369 		}
    370 	},
    371 	{
    372 		.bitpos = 60, .bitwidth = 4, .name = "RNDR",
    373 		.info = (const char *[16]) { /* 16=4bit */
    374 			[0] = "No RNDR/RNDRRS",
    375 			[1] = "RNDR/RNDRRS",
    376 		},
    377 	},
    378 	{ .bitwidth = 0 }	/* end of table */
    379 };
    380 
    381 /* ID_AA64MMFR0_EL1 - AArch64 Memory Model Feature Register 0 */
    382 struct fieldinfo id_aa64mmfr0_fieldinfo[] = {
    383 	{
    384 		.bitpos = 0, .bitwidth = 4, .name = "PARange",
    385 		.info = (const char *[16]) { /* 16=4bit */
    386 			[0] = "32bits/4GB",
    387 			[1] = "36bits/64GB",
    388 			[2] = "40bits/1TB",
    389 			[3] = "42bits/4TB",
    390 			[4] = "44bits/16TB",
    391 			[5] = "48bits/256TB"
    392 		}
    393 	},
    394 	{
    395 		.bitpos = 4, .bitwidth = 4, .name = "ASIDBit",
    396 		.info = (const char *[16]) { /* 16=4bit */
    397 			[0] = "8bits",
    398 			[2] = "16bits"
    399 		}
    400 	},
    401 	{
    402 		.bitpos = 8, .bitwidth = 4, .name = "BigEnd",
    403 		.info = (const char *[16]) { /* 16=4bit */
    404 			[0] = "No mixed-endian",
    405 			[1] = "Mixed-endian"
    406 		}
    407 	},
    408 	{
    409 		.bitpos = 12, .bitwidth = 4, .name = "SNSMem",
    410 		.info = (const char *[16]) { /* 16=4bit */
    411 			[0] = "No distinction B/W Secure and Non-secure Memory",
    412 			[1] = "Distinction B/W Secure and Non-secure Memory"
    413 		}
    414 	},
    415 	{
    416 		.bitpos = 16, .bitwidth = 4, .name = "BigEndEL0",
    417 		.info = (const char *[16]) { /* 16=4bit */
    418 			[0] = "No mixed-endian at EL0",
    419 			[1] = "Mixed-endian at EL0"
    420 		}
    421 	},
    422 	{
    423 		.bitpos = 20, .bitwidth = 4, .name = "TGran16",
    424 		.info = (const char *[16]) { /* 16=4bit */
    425 			[0] = "No 16KB granule",
    426 			[1] = "16KB granule"
    427 		}
    428 	},
    429 	{
    430 		.bitpos = 24, .bitwidth = 4, .name = "TGran64",
    431 		.info = (const char *[16]) { /* 16=4bit */
    432 			[0] = "64KB granule",
    433 			[15] = "No 64KB granule"
    434 		}
    435 	},
    436 	{
    437 		.bitpos = 28, .bitwidth = 4, .name = "TGran4",
    438 		.info = (const char *[16]) { /* 16=4bit */
    439 			[0] = "4KB granule",
    440 			[15] = "No 4KB granule"
    441 		}
    442 	},
    443 	{ .bitwidth = 0 }	/* end of table */
    444 };
    445 
    446 /* ID_AA64MMFR1_EL1 - AArch64 Memory Model Feature Register 1 */
    447 struct fieldinfo id_aa64mmfr1_fieldinfo[] = {
    448 	{
    449 		.bitpos = 0, .bitwidth = 4, .name = "HAFDBS",
    450 		.info = (const char *[16]) { /* 16=4bit */
    451 			[0] = "Access and Dirty flags not supported",
    452 			[1] = "Access flag supported",
    453 			[2] = "Access and Dirty flags supported",
    454 		}
    455 	},
    456 	{
    457 		.bitpos = 4, .bitwidth = 4, .name = "VMIDBits",
    458 		.info = (const char *[16]) { /* 16=4bit */
    459 			[0] = "8bits",
    460 			[2] = "16bits"
    461 		}
    462 	},
    463 	{
    464 		.bitpos = 8, .bitwidth = 4, .name = "VH",
    465 		.info = (const char *[16]) { /* 16=4bit */
    466 			[0] = "Virtualization Host Extensions not supported",
    467 			[1] = "Virtualization Host Extensions supported",
    468 		}
    469 	},
    470 	{
    471 		.bitpos = 12, .bitwidth = 4, .name = "HPDS",
    472 		.info = (const char *[16]) { /* 16=4bit */
    473 			[0] = "Disabling of hierarchical controls not supported",
    474 			[1] = "Disabling of hierarchical controls supported",
    475 			[2] = "Disabling of hierarchical controls supported, plus PTD"
    476 		}
    477 	},
    478 	{
    479 		.bitpos = 16, .bitwidth = 4, .name = "LO",
    480 		.info = (const char *[16]) { /* 16=4bit */
    481 			[0] = "LORegions not supported",
    482 			[1] = "LORegions supported"
    483 		}
    484 	},
    485 	{
    486 		.bitpos = 20, .bitwidth = 4, .name = "PAN",
    487 		.info = (const char *[16]) { /* 16=4bit */
    488 			[0] = "PAN not supported",
    489 			[1] = "PAN supported",
    490 			[2] = "PAN supported, and instructions supported"
    491 		}
    492 	},
    493 	{
    494 		.bitpos = 24, .bitwidth = 4, .name = "SpecSEI",
    495 		.info = (const char *[16]) { /* 16=4bit */
    496 			[0] = "SError interrupt not supported",
    497 			[1] = "SError interrupt supported"
    498 		}
    499 	},
    500 	{
    501 		.bitpos = 28, .bitwidth = 4, .name = "XNX",
    502 		.info = (const char *[16]) { /* 16=4bit */
    503 			[0] = "Distinction between EL0 and EL1 XN control at stage 2 not supported",
    504 			[1] = "Distinction between EL0 and EL1 XN control at stage 2 supported"
    505 		}
    506 	},
    507 	{ .bitwidth = 0 }	/* end of table */
    508 };
    509 
    510 /* ID_AA64DFR0_EL1 - AArch64 Debug Feature Register 0 */
    511 struct fieldinfo id_aa64dfr0_fieldinfo[] = {
    512 	{
    513 		.bitpos = 0, .bitwidth = 4, .name = "DebugVer",
    514 		.info = (const char *[16]) { /* 16=4bit */
    515 			[6] = "v8-A debug architecture"
    516 		}
    517 	},
    518 	{
    519 		.bitpos = 4, .bitwidth = 4, .name = "TraceVer",
    520 		.info = (const char *[16]) { /* 16=4bit */
    521 			[0] = "Trace supported",
    522 			[1] = "Trace not supported"
    523 		}
    524 	},
    525 	{
    526 		.bitpos = 8, .bitwidth = 4, .name = "PMUVer",
    527 		.info = (const char *[16]) { /* 16=4bit */
    528 			[0] = "No Performance monitor",
    529 			[1] = "Performance monitor unit v3"
    530 		}
    531 	},
    532 	{ .bitwidth = 0 }	/* end of table */
    533 };
    534 
    535 
    536 /* MVFR0_EL1 - Media and VFP Feature Register 0 */
    537 struct fieldinfo mvfr0_fieldinfo[] = {
    538 	{
    539 		.bitpos = 0, .bitwidth = 4, .name = "SIMDreg",
    540 		.info = (const char *[16]) { /* 16=4bit */
    541 			[0] = "No SIMD",
    542 			[1] = "16x64-bit SIMD",
    543 			[2] = "32x64-bit SIMD"
    544 		}
    545 	},
    546 	{
    547 		.bitpos = 4, .bitwidth = 4, .name = "FPSP",
    548 		.info = (const char *[16]) { /* 16=4bit */
    549 			[0] = "No VFP support single precision",
    550 			[1] = "VFPv2 support single precision",
    551 			[2] = "VFPv2/VFPv3/VFPv4 support single precision"
    552 		}
    553 	},
    554 	{
    555 		.bitpos = 8, .bitwidth = 4, .name = "FPDP",
    556 		.info = (const char *[16]) { /* 16=4bit */
    557 			[0] = "No VFP support double precision",
    558 			[1] = "VFPv2 support double precision",
    559 			[2] = "VFPv2/VFPv3/VFPv4 support double precision"
    560 		}
    561 	},
    562 	{
    563 		.bitpos = 12, .bitwidth = 4, .name = "FPTrap",
    564 		.info = (const char *[16]) { /* 16=4bit */
    565 			[0] = "No floating point exception trapping support",
    566 			[1] = "VFPv2/VFPv3/VFPv4 support exception trapping"
    567 		}
    568 	},
    569 	{
    570 		.bitpos = 16, .bitwidth = 4, .name = "FPDivide",
    571 		.info = (const char *[16]) { /* 16=4bit */
    572 			[0] = "VDIV not supported",
    573 			[1] = "VDIV supported"
    574 		}
    575 	},
    576 	{
    577 		.bitpos = 20, .bitwidth = 4, .name = "FPSqrt",
    578 		.info = (const char *[16]) { /* 16=4bit */
    579 			[0] = "VSQRT not supported",
    580 			[1] = "VSQRT supported"
    581 		}
    582 	},
    583 	{
    584 		.bitpos = 24, .bitwidth = 4, .name = "FPShVec",
    585 		.info = (const char *[16]) { /* 16=4bit */
    586 			[0] = "Short Vectors not supported",
    587 			[1] = "Short Vectors supported"
    588 		}
    589 	},
    590 	{
    591 		.bitpos = 28, .bitwidth = 4, .name = "FPRound",
    592 		.info = (const char *[16]) { /* 16=4bit */
    593 			[0] = "Only Round to Nearest mode",
    594 			[1] = "All rounding modes"
    595 		}
    596 	},
    597 	{ .bitwidth = 0 }	/* end of table */
    598 };
    599 
    600 /* MVFR1_EL1 - Media and VFP Feature Register 1 */
    601 struct fieldinfo mvfr1_fieldinfo[] = {
    602 	{
    603 		.bitpos = 0, .bitwidth = 4, .name = "FPFtZ",
    604 		.info = (const char *[16]) { /* 16=4bit */
    605 			[0] = "only the Flush-to-Zero",
    606 			[1] = "full Denormalized number arithmetic"
    607 		}
    608 	},
    609 	{
    610 		.bitpos = 4, .bitwidth = 4, .name = "FPDNan",
    611 		.info = (const char *[16]) { /* 16=4bit */
    612 			[0] = "Default NaN",
    613 			[1] = "Propagation of NaN"
    614 		}
    615 	},
    616 	{
    617 		.bitpos = 8, .bitwidth = 4, .name = "SIMDLS",
    618 		.info = (const char *[16]) { /* 16=4bit */
    619 			[0] = "No Advanced SIMD Load/Store",
    620 			[1] = "Advanced SIMD Load/Store"
    621 		}
    622 	},
    623 	{
    624 		.bitpos = 12, .bitwidth = 4, .name = "SIMDInt",
    625 		.info = (const char *[16]) { /* 16=4bit */
    626 			[0] = "No Advanced SIMD Integer",
    627 			[1] = "Advanced SIMD Integer"
    628 		}
    629 	},
    630 	{
    631 		.bitpos = 16, .bitwidth = 4, .name = "SIMDSP",
    632 		.info = (const char *[16]) { /* 16=4bit */
    633 			[0] = "No Advanced SIMD single precision",
    634 			[1] = "Advanced SIMD single precision"
    635 		}
    636 	},
    637 	{
    638 		.bitpos = 20, .bitwidth = 4, .name = "SIMDHP",
    639 		.info = (const char *[16]) { /* 16=4bit */
    640 			[0] = "No Advanced SIMD half precision",
    641 			[1] = "Advanced SIMD half precision"
    642 		}
    643 	},
    644 	{
    645 		.bitpos = 24, .bitwidth = 4, .name = "FPHP",
    646 		.info = (const char *[16]) { /* 16=4bit */
    647 			[0] = "No half precision conversion",
    648 			[1] = "half/single precision conversion",
    649 			[2] = "half/single/double precision conversion"
    650 		}
    651 	},
    652 	{
    653 		.bitpos = 28, .bitwidth = 4, .name = "SIMDFMAC",
    654 		.info = (const char *[16]) { /* 16=4bit */
    655 			[0] = "No Fused Multiply-Accumulate",
    656 			[1] = "Fused Multiply-Accumulate"
    657 		}
    658 	},
    659 	{ .bitwidth = 0 }	/* end of table */
    660 };
    661 
    662 /* MVFR2_EL1 - Media and VFP Feature Register 2 */
    663 struct fieldinfo mvfr2_fieldinfo[] = {
    664 	{
    665 		.bitpos = 0, .bitwidth = 4, .name = "SIMDMisc",
    666 		.info = (const char *[16]) { /* 16=4bit */
    667 			[0] = "No miscellaneous features",
    668 			[1] = "Conversion to Integer w/Directed Rounding modes",
    669 			[2] = "Conversion to Integer w/Directed Rounding modes"
    670 			    ", Round to Integral floating point",
    671 			[3] = "Conversion to Integer w/Directed Rounding modes"
    672 			    ", Round to Integral floating point"
    673 			    ", MaxNum and MinNum"
    674 		}
    675 	},
    676 	{
    677 		.bitpos = 4, .bitwidth = 4, .name = "FPMisc",
    678 		.info = (const char *[16]) { /* 16=4bit */
    679 			[0] = "No miscellaneous features",
    680 			[1] = "Floating point selection",
    681 			[2] = "Floating point selection"
    682 			    ", Conversion to Integer w/Directed Rounding modes",
    683 			[3] = "Floating point selection"
    684 			    ", Conversion to Integer w/Directed Rounding modes"
    685 			    ", Round to Integral floating point",
    686 			[4] = "Floating point selection"
    687 			    ", Conversion to Integer w/Directed Rounding modes"
    688 			    ", Round to Integral floating point"
    689 			    ", MaxNum and MinNum"
    690 		}
    691 	},
    692 	{ .bitwidth = 0 }	/* end of table */
    693 };
    694 
    695 /* CLIDR_EL1 - Cache Level ID Register */
    696 const char * const clidr_cachetype[8] = { /* 8=3bit */
    697 	[0] = "None",
    698 	[1] = "Instruction cache",
    699 	[2] = "Data cache",
    700 	[3] = "Instruction and Data cache",
    701 	[4] = "Unified cache"
    702 };
    703 
    704 struct fieldinfo clidr_fieldinfo[] = {
    705 	{
    706 		.bitpos = 0, .bitwidth = 3, .name = "L1",
    707 		.info = clidr_cachetype
    708 	},
    709 	{
    710 		.bitpos = 3, .bitwidth = 3, .name = "L2",
    711 		.info = clidr_cachetype
    712 	},
    713 	{
    714 		.bitpos = 6, .bitwidth = 3, .name = "L3",
    715 		.info = clidr_cachetype
    716 	},
    717 	{
    718 		.bitpos = 9, .bitwidth = 3, .name = "L4",
    719 		.info = clidr_cachetype
    720 	},
    721 	{
    722 		.bitpos = 12, .bitwidth = 3, .name = "L5",
    723 		.info = clidr_cachetype
    724 	},
    725 	{
    726 		.bitpos = 15, .bitwidth = 3, .name = "L6",
    727 		.info = clidr_cachetype
    728 	},
    729 	{
    730 		.bitpos = 18, .bitwidth = 3, .name = "L7",
    731 		.info = clidr_cachetype
    732 	},
    733 	{
    734 		.bitpos = 21, .bitwidth = 3, .name = "LoUU",
    735 		.flags = FIELDINFO_FLAGS_DEC
    736 	},
    737 	{
    738 		.bitpos = 24, .bitwidth = 3, .name = "LoC",
    739 		.flags = FIELDINFO_FLAGS_DEC
    740 	},
    741 	{
    742 		.bitpos = 27, .bitwidth = 3, .name = "LoUIS",
    743 		.flags = FIELDINFO_FLAGS_DEC
    744 	},
    745 	{
    746 		.bitpos = 30, .bitwidth = 3, .name = "ICB",
    747 		.flags = FIELDINFO_FLAGS_DEC
    748 	},
    749 	{ .bitwidth = 0 }	/* end of table */
    750 };
    751 
    752 struct fieldinfo ctr_fieldinfo[] = {
    753 	{
    754 		.bitpos = 0, .bitwidth = 4, .name = "IminLine",
    755 		.flags = FIELDINFO_FLAGS_DEC | FIELDINFO_FLAGS_4LOG2
    756 	},
    757 	{
    758 		.bitpos = 16, .bitwidth = 4, .name = "DminLine",
    759 		.flags = FIELDINFO_FLAGS_DEC | FIELDINFO_FLAGS_4LOG2
    760 	},
    761 	{
    762 		.bitpos = 14, .bitwidth = 2, .name = "L1 Icache policy",
    763 		.info = (const char *[4]) { /* 4=2bit */
    764 			[0] = "VMID aware PIPT (VPIPT)",
    765 			[1] = "ASID-tagged VIVT (AIVIVT)",
    766 			[2] = "VIPT",
    767 			[3] = "PIPT"
    768 		},
    769 	},
    770 	{
    771 		.bitpos = 20, .bitwidth = 4, .name = "ERG",
    772 		.flags = FIELDINFO_FLAGS_DEC | FIELDINFO_FLAGS_4LOG2
    773 	},
    774 	{
    775 		.bitpos = 24, .bitwidth = 4, .name = "CWG",
    776 		.flags = FIELDINFO_FLAGS_DEC | FIELDINFO_FLAGS_4LOG2
    777 	},
    778 	{
    779 		.bitpos = 28, .bitwidth = 1, .name = "DIC",
    780 		.flags = FIELDINFO_FLAGS_DEC
    781 	},
    782 	{
    783 		.bitpos = 29, .bitwidth = 1, .name = "IDC",
    784 		.flags = FIELDINFO_FLAGS_DEC
    785 	},
    786 	{ .bitwidth = 0 }	/* end of table */
    787 };
    788 
    789 
    790 static void
    791 print_fieldinfo(const char *cpuname, const char *setname,
    792     struct fieldinfo *fieldinfo, uint64_t data)
    793 {
    794 	uint64_t v;
    795 	const char *info;
    796 	int i, flags;
    797 
    798 #define WIDTHMASK(w)	(0xffffffffffffffffULL >> (64 - (w)))
    799 
    800 	for (i = 0; fieldinfo[i].bitwidth != 0; i++) {
    801 		v = (data >> fieldinfo[i].bitpos) &
    802 		    WIDTHMASK(fieldinfo[i].bitwidth);
    803 
    804 		flags = fieldinfo[i].flags;
    805 		info = NULL;
    806 		if (fieldinfo[i].info != NULL)
    807 			info = fieldinfo[i].info[v];
    808 
    809 		printf("%s: %s: %s: ",
    810 		    cpuname, setname, fieldinfo[i].name);
    811 
    812 		if (info == NULL) {
    813 			if (flags & FIELDINFO_FLAGS_4LOG2)
    814 				v = 4 * (1 << v);
    815 			if (flags & FIELDINFO_FLAGS_DEC)
    816 				printf("%"PRIu64"\n", v);
    817 			else
    818 				printf("0x%"PRIx64"\n", v);
    819 		} else {
    820 			printf("%s\n", info);
    821 		}
    822 	}
    823 }
    824 
    825 /* MIDR_EL1 - Main ID Register */
    826 static void
    827 identify_midr(const char *cpuname, uint32_t cpuid)
    828 {
    829 	unsigned int i;
    830 	uint32_t implid, cpupart, variant, revision;
    831 	const char *implementer = NULL;
    832 	static char implbuf[128];
    833 
    834 	implid = cpuid & CPU_ID_IMPLEMENTOR_MASK;
    835 	cpupart = cpuid & CPU_PARTMASK;
    836 	variant = __SHIFTOUT(cpuid, CPU_ID_VARIANT_MASK);
    837 	revision = __SHIFTOUT(cpuid, CPU_ID_REVISION_MASK);
    838 
    839 	for (i = 0; i < __arraycount(implids); i++) {
    840 		if (implid == implids[i].impl_id) {
    841 			implementer = implids[i].impl_name;
    842 		}
    843 	}
    844 	if (implementer == NULL) {
    845 		snprintf(implbuf, sizeof(implbuf), "unknown implementer: 0x%02x",
    846 		    implid >> 24);
    847 		implementer = implbuf;
    848 	}
    849 
    850 	for (i = 0; i < __arraycount(cpuids); i++) {
    851 		if (cpupart == cpuids[i].cpu_partnum) {
    852 			printf("%s: %s, %s r%dp%d (%s %s core)\n",
    853 			    cpuname, implementer,
    854 			    cpuids[i].cpu_name, variant, revision,
    855 			    cpuids[i].cpu_class,
    856 			    cpuids[i].cpu_architecture);
    857 			return;
    858 		}
    859 	}
    860 	printf("%s: unknown CPU ID: 0x%08x\n", cpuname, cpuid);
    861 }
    862 
    863 /* REVIDR_EL1 - Revision ID Register */
    864 static void
    865 identify_revidr(const char *cpuname, uint32_t revidr)
    866 {
    867 	printf("%s: revision: 0x%08x\n", cpuname, revidr);
    868 }
    869 
    870 /* MPIDR_EL1 - Multiprocessor Affinity Register */
    871 static void
    872 identify_mpidr(const char *cpuname, uint32_t mpidr)
    873 {
    874 	const char *setname = "multiprocessor affinity";
    875 
    876 	printf("%s: %s: Affinity-Level: %"PRIu64"-%"PRIu64"-%"PRIu64"-%"PRIu64"\n",
    877 	    cpuname, setname,
    878 	    __SHIFTOUT(mpidr, MPIDR_AFF3),
    879 	    __SHIFTOUT(mpidr, MPIDR_AFF2),
    880 	    __SHIFTOUT(mpidr, MPIDR_AFF1),
    881 	    __SHIFTOUT(mpidr, MPIDR_AFF0));
    882 
    883 	if ((mpidr & MPIDR_U) == 0)
    884 		printf("%s: %s: Multiprocessor system\n", cpuname, setname);
    885 	else
    886 		printf("%s: %s: Uniprocessor system\n", cpuname, setname);
    887 
    888 	if ((mpidr & MPIDR_MT) == 0)
    889 		printf("%s: %s: Core Independent\n", cpuname, setname);
    890 	else
    891 		printf("%s: %s: Multi-Threading\n", cpuname, setname);
    892 
    893 }
    894 
    895 /* AA64DFR0 - Debug feature register 0 */
    896 static void
    897 identify_dfr0(const char *cpuname, uint64_t dfr0)
    898 {
    899 	const char *setname = "debug feature 0";
    900 
    901 	printf("%s: %s: CTX_CMPs: %lu context-aware breakpoints\n",
    902 	    cpuname, setname, __SHIFTOUT(dfr0, ID_AA64DFR0_EL1_CTX_CMPS) + 1);
    903 	printf("%s: %s: WRPs: %lu watchpoints\n",
    904 	    cpuname, setname, __SHIFTOUT(dfr0, ID_AA64DFR0_EL1_WRPS) + 1);
    905 	printf("%s: %s: BRPs: %lu breakpoints\n",
    906 	    cpuname, setname, __SHIFTOUT(dfr0, ID_AA64DFR0_EL1_BRPS) + 1);
    907 	print_fieldinfo(cpuname, setname,
    908 	    id_aa64dfr0_fieldinfo, dfr0);
    909 }
    910 
    911 void
    912 identifycpu(int fd, const char *cpuname)
    913 {
    914 	char path[128];
    915 	size_t len;
    916 #define SYSCTL_CPU_ID_MAXSIZE	64
    917 	uint64_t sysctlbuf[SYSCTL_CPU_ID_MAXSIZE];
    918 	struct aarch64_sysctl_cpu_id *id =
    919 	    (struct aarch64_sysctl_cpu_id *)sysctlbuf;
    920 
    921 	snprintf(path, sizeof path, "machdep.%s.cpu_id", cpuname);
    922 	len = sizeof(sysctlbuf);
    923 	memset(sysctlbuf, 0, len);
    924 	if (sysctlbyname(path, id, &len, 0, 0) == -1)
    925 		err(1, "couldn't get %s", path);
    926 	if (len != sizeof(struct aarch64_sysctl_cpu_id))
    927 		fprintf(stderr, "Warning: kernel version bumped?\n");
    928 
    929 	if (verbose) {
    930 		printf("%s: MIDR_EL1: 0x%08"PRIx64"\n",
    931 		    cpuname, id->ac_midr);
    932 		printf("%s: MPIDR_EL1: 0x%016"PRIx64"\n",
    933 		    cpuname, id->ac_mpidr);
    934 		printf("%s: ID_AA64DFR0_EL1: 0x%016"PRIx64"\n",
    935 		    cpuname, id->ac_aa64dfr0);
    936 		printf("%s: ID_AA64DFR1_EL1: 0x%016"PRIx64"\n",
    937 		    cpuname, id->ac_aa64dfr1);
    938 		printf("%s: ID_AA64ISAR0_EL1: 0x%016"PRIx64"\n",
    939 		    cpuname, id->ac_aa64isar0);
    940 		printf("%s: ID_AA64ISAR1_EL1: 0x%016"PRIx64"\n",
    941 		    cpuname, id->ac_aa64isar1);
    942 		printf("%s: ID_AA64MMFR0_EL1: 0x%016"PRIx64"\n",
    943 		    cpuname, id->ac_aa64mmfr0);
    944 		printf("%s: ID_AA64MMFR1_EL1: 0x%016"PRIx64"\n",
    945 		    cpuname, id->ac_aa64mmfr1);
    946 		printf("%s: ID_AA64MMFR2_EL1: 0x%016"PRIx64"\n",
    947 		    cpuname, id->ac_aa64mmfr2);
    948 		printf("%s: ID_AA64PFR0_EL1: 0x%08"PRIx64"\n",
    949 		    cpuname, id->ac_aa64pfr0);
    950 		printf("%s: ID_AA64PFR1_EL1: 0x%08"PRIx64"\n",
    951 		    cpuname, id->ac_aa64pfr1);
    952 		printf("%s: ID_AA64ZFR0_EL1: 0x%016"PRIx64"\n",
    953 		    cpuname, id->ac_aa64zfr0);
    954 		printf("%s: MVFR0_EL1: 0x%08"PRIx32"\n",
    955 		    cpuname, id->ac_mvfr0);
    956 		printf("%s: MVFR1_EL1: 0x%08"PRIx32"\n",
    957 		    cpuname, id->ac_mvfr1);
    958 		printf("%s: MVFR2_EL1: 0x%08"PRIx32"\n",
    959 		    cpuname, id->ac_mvfr2);
    960 		printf("%s: CLIDR_EL1: 0x%016"PRIx64"\n",
    961 		    cpuname, id->ac_clidr);
    962 		printf("%s: CTR_EL0: 0x%016"PRIx64"\n",
    963 		    cpuname, id->ac_ctr);
    964 	}
    965 
    966 	identify_midr(cpuname, id->ac_midr);
    967 	identify_revidr(cpuname, id->ac_revidr);
    968 	identify_mpidr(cpuname, id->ac_mpidr);
    969 	print_fieldinfo(cpuname, "isa features 0",
    970 	    id_aa64isar0_fieldinfo, id->ac_aa64isar0);
    971 	print_fieldinfo(cpuname, "memory model 0",
    972 	    id_aa64mmfr0_fieldinfo, id->ac_aa64mmfr0);
    973 	print_fieldinfo(cpuname, "memory model 1",
    974 	    id_aa64mmfr1_fieldinfo, id->ac_aa64mmfr1);
    975 	print_fieldinfo(cpuname, "processor feature 0",
    976 	    id_aa64pfr0_fieldinfo, id->ac_aa64pfr0);
    977 	print_fieldinfo(cpuname, "processor feature 1",
    978 	    id_aa64pfr1_fieldinfo, id->ac_aa64pfr1);
    979 	identify_dfr0(cpuname, id->ac_aa64dfr0);
    980 
    981 	print_fieldinfo(cpuname, "media and VFP features 0",
    982 	    mvfr0_fieldinfo, id->ac_mvfr0);
    983 	print_fieldinfo(cpuname, "media and VFP features 1",
    984 	    mvfr1_fieldinfo, id->ac_mvfr1);
    985 	print_fieldinfo(cpuname, "media and VFP features 2",
    986 	    mvfr2_fieldinfo, id->ac_mvfr2);
    987 
    988 	if (len <= offsetof(struct aarch64_sysctl_cpu_id, ac_clidr))
    989 		return;
    990 	print_fieldinfo(cpuname, "cache level",
    991 	    clidr_fieldinfo, id->ac_clidr);
    992 	print_fieldinfo(cpuname, "cache type",
    993 	    ctr_fieldinfo, id->ac_ctr);
    994 }
    995 
    996 bool
    997 identifycpu_bind(void)
    998 {
    999 	return false;
   1000 }
   1001 
   1002 int
   1003 ucodeupdate_check(int fd, struct cpu_ucode *uc)
   1004 {
   1005 	return 0;
   1006 }
   1007