2 * SPDX-License-Identifier: GPL-2.0-or-later
3 * Host specific cpu indentification 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>
18 # include <sys/sysctl.h>
24 static bool sysctl_for_bool(const char *name
)
27 size_t len
= sizeof(val
);
29 if (sysctlbyname(name
, &val
, &len
, NULL
, 0) == 0) {
34 * We might in the future ask for properties not present in older kernels,
35 * but we're only asking about static properties, all of which should be
36 * 'int'. So we shouln't see ENOMEM (val too small), or any of the other
39 assert(errno
== ENOENT
);
44 /* Called both as constructor and (possibly) via other constructors. */
45 unsigned __attribute__((constructor
)) cpuinfo_init(void)
47 unsigned info
= cpuinfo
;
53 info
= CPUINFO_ALWAYS
;
56 unsigned long hwcap
= qemu_getauxval(AT_HWCAP
);
57 info
|= (hwcap
& HWCAP_ATOMICS
? CPUINFO_LSE
: 0);
58 info
|= (hwcap
& HWCAP_USCAT
? CPUINFO_LSE2
: 0);
59 info
|= (hwcap
& HWCAP_AES
? CPUINFO_AES
: 0);
62 info
|= sysctl_for_bool("hw.optional.arm.FEAT_LSE") * CPUINFO_LSE
;
63 info
|= sysctl_for_bool("hw.optional.arm.FEAT_LSE2") * CPUINFO_LSE2
;
64 info
|= sysctl_for_bool("hw.optional.arm.FEAT_AES") * CPUINFO_AES
;