2 * SPDX-License-Identifier: GPL-2.0-or-later
3 * Host specific cpu identification for AArch64.
6 #include "qemu/osdep.h"
7 #include "host/cpuinfo.h"
10 # ifdef CONFIG_GETAUXVAL
11 # include <sys/auxv.h>
13 # include <asm/hwcap.h>
17 # define HWCAP2_BTI 0 /* added in glibc 2.32 */
21 # include <sys/sysctl.h>
27 static bool sysctl_for_bool(const char *name
)
30 size_t len
= sizeof(val
);
32 if (sysctlbyname(name
, &val
, &len
, NULL
, 0) == 0) {
37 * We might in the future ask for properties not present in older kernels,
38 * but we're only asking about static properties, all of which should be
39 * 'int'. So we shouldn't see ENOMEM (val too small), or any of the other
42 assert(errno
== ENOENT
);
47 /* Called both as constructor and (possibly) via other constructors. */
48 unsigned __attribute__((constructor
)) cpuinfo_init(void)
50 unsigned info
= cpuinfo
;
56 info
= CPUINFO_ALWAYS
;
59 unsigned long hwcap
= qemu_getauxval(AT_HWCAP
);
60 info
|= (hwcap
& HWCAP_ATOMICS
? CPUINFO_LSE
: 0);
61 info
|= (hwcap
& HWCAP_USCAT
? CPUINFO_LSE2
: 0);
62 info
|= (hwcap
& HWCAP_AES
? CPUINFO_AES
: 0);
63 info
|= (hwcap
& HWCAP_PMULL
? CPUINFO_PMULL
: 0);
65 unsigned long hwcap2
= qemu_getauxval(AT_HWCAP2
);
66 info
|= (hwcap2
& HWCAP2_BTI
? CPUINFO_BTI
: 0);
69 info
|= sysctl_for_bool("hw.optional.arm.FEAT_LSE") * CPUINFO_LSE
;
70 info
|= sysctl_for_bool("hw.optional.arm.FEAT_LSE2") * CPUINFO_LSE2
;
71 info
|= sysctl_for_bool("hw.optional.arm.FEAT_AES") * CPUINFO_AES
;
72 info
|= sysctl_for_bool("hw.optional.arm.FEAT_PMULL") * CPUINFO_PMULL
;
73 info
|= sysctl_for_bool("hw.optional.arm.FEAT_BTI") * CPUINFO_BTI
;