Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
util: Add cpuinfo-aarch64.c
Move the code from tcg/. The only use of these bits so far is with respect to the atomicity of tcg operations. Reviewed-by: Alex Bennée <alex.bennee@linaro.org> Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
- Loading branch information
Showing
5 changed files
with
96 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| /* | ||
| * SPDX-License-Identifier: GPL-2.0-or-later | ||
| * Host specific cpu indentification for AArch64. | ||
| */ | ||
|
|
||
| #ifndef HOST_CPUINFO_H | ||
| #define HOST_CPUINFO_H | ||
|
|
||
| #define CPUINFO_ALWAYS (1u << 0) /* so cpuinfo is nonzero */ | ||
| #define CPUINFO_LSE (1u << 1) | ||
| #define CPUINFO_LSE2 (1u << 2) | ||
|
|
||
| /* Initialized with a constructor. */ | ||
| extern unsigned cpuinfo; | ||
|
|
||
| /* | ||
| * We cannot rely on constructor ordering, so other constructors must | ||
| * use the function interface rather than the variable above. | ||
| */ | ||
| unsigned cpuinfo_init(void); | ||
|
|
||
| #endif /* HOST_CPUINFO_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| /* | ||
| * SPDX-License-Identifier: GPL-2.0-or-later | ||
| * Host specific cpu indentification for AArch64. | ||
| */ | ||
|
|
||
| #include "qemu/osdep.h" | ||
| #include "host/cpuinfo.h" | ||
|
|
||
| #ifdef CONFIG_LINUX | ||
| # ifdef CONFIG_GETAUXVAL | ||
| # include <sys/auxv.h> | ||
| # else | ||
| # include <asm/hwcap.h> | ||
| # include "elf.h" | ||
| # endif | ||
| #endif | ||
| #ifdef CONFIG_DARWIN | ||
| # include <sys/sysctl.h> | ||
| #endif | ||
|
|
||
| unsigned cpuinfo; | ||
|
|
||
| #ifdef CONFIG_DARWIN | ||
| static bool sysctl_for_bool(const char *name) | ||
| { | ||
| int val = 0; | ||
| size_t len = sizeof(val); | ||
|
|
||
| if (sysctlbyname(name, &val, &len, NULL, 0) == 0) { | ||
| return val != 0; | ||
| } | ||
|
|
||
| /* | ||
| * We might in the future ask for properties not present in older kernels, | ||
| * but we're only asking about static properties, all of which should be | ||
| * 'int'. So we shouln't see ENOMEM (val too small), or any of the other | ||
| * more exotic errors. | ||
| */ | ||
| assert(errno == ENOENT); | ||
| return false; | ||
| } | ||
| #endif | ||
|
|
||
| /* Called both as constructor and (possibly) via other constructors. */ | ||
| unsigned __attribute__((constructor)) cpuinfo_init(void) | ||
| { | ||
| unsigned info = cpuinfo; | ||
|
|
||
| if (info) { | ||
| return info; | ||
| } | ||
|
|
||
| info = CPUINFO_ALWAYS; | ||
|
|
||
| #ifdef CONFIG_LINUX | ||
| unsigned long hwcap = qemu_getauxval(AT_HWCAP); | ||
| info |= (hwcap & HWCAP_ATOMICS ? CPUINFO_LSE : 0); | ||
| info |= (hwcap & HWCAP_USCAT ? CPUINFO_LSE2 : 0); | ||
| #endif | ||
| #ifdef CONFIG_DARWIN | ||
| info |= sysctl_for_bool("hw.optional.arm.FEAT_LSE") * CPUINFO_LSE; | ||
| info |= sysctl_for_bool("hw.optional.arm.FEAT_LSE2") * CPUINFO_LSE2; | ||
| #endif | ||
|
|
||
| cpuinfo = info; | ||
| return info; | ||
| } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters