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-ppc.c
Move the code from tcg/. Fix a bug in that PPC_FEATURE2_ARCH_3_10 is actually spelled PPC_FEATURE2_ARCH_3_1. Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com> Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
- Loading branch information
Showing
6 changed files
with
97 additions
and
51 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,29 @@ | ||
| /* | ||
| * SPDX-License-Identifier: GPL-2.0-or-later | ||
| * Host specific cpu indentification for ppc. | ||
| */ | ||
|
|
||
| #ifndef HOST_CPUINFO_H | ||
| #define HOST_CPUINFO_H | ||
|
|
||
| /* Digested version of <cpuid.h> */ | ||
|
|
||
| #define CPUINFO_ALWAYS (1u << 0) /* so cpuinfo is nonzero */ | ||
| #define CPUINFO_V2_06 (1u << 1) | ||
| #define CPUINFO_V2_07 (1u << 2) | ||
| #define CPUINFO_V3_0 (1u << 3) | ||
| #define CPUINFO_V3_1 (1u << 4) | ||
| #define CPUINFO_ISEL (1u << 5) | ||
| #define CPUINFO_ALTIVEC (1u << 6) | ||
| #define CPUINFO_VSX (1u << 7) | ||
|
|
||
| /* 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| #include "host/include/ppc/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,56 @@ | ||
| /* | ||
| * SPDX-License-Identifier: GPL-2.0-or-later | ||
| * Host specific cpu indentification for ppc. | ||
| */ | ||
|
|
||
| #include "qemu/osdep.h" | ||
| #include "host/cpuinfo.h" | ||
|
|
||
| #ifdef CONFIG_GETAUXVAL | ||
| # include <sys/auxv.h> | ||
| #else | ||
| # include <asm/cputable.h> | ||
| # include "elf.h" | ||
| #endif | ||
|
|
||
| unsigned cpuinfo; | ||
|
|
||
| /* Called both as constructor and (possibly) via other constructors. */ | ||
| unsigned __attribute__((constructor)) cpuinfo_init(void) | ||
| { | ||
| unsigned info = cpuinfo; | ||
| unsigned long hwcap, hwcap2; | ||
|
|
||
| if (info) { | ||
| return info; | ||
| } | ||
|
|
||
| hwcap = qemu_getauxval(AT_HWCAP); | ||
| hwcap2 = qemu_getauxval(AT_HWCAP2); | ||
| info = CPUINFO_ALWAYS; | ||
|
|
||
| /* Version numbers are monotonic, and so imply all lower versions. */ | ||
| if (hwcap2 & PPC_FEATURE2_ARCH_3_1) { | ||
| info |= CPUINFO_V3_1 | CPUINFO_V3_0 | CPUINFO_V2_07 | CPUINFO_V2_06; | ||
| } else if (hwcap2 & PPC_FEATURE2_ARCH_3_00) { | ||
| info |= CPUINFO_V3_0 | CPUINFO_V2_07 | CPUINFO_V2_06; | ||
| } else if (hwcap2 & PPC_FEATURE2_ARCH_2_07) { | ||
| info |= CPUINFO_V2_07 | CPUINFO_V2_06; | ||
| } else if (hwcap & PPC_FEATURE_ARCH_2_06) { | ||
| info |= CPUINFO_V2_06; | ||
| } | ||
|
|
||
| if (hwcap2 & PPC_FEATURE2_HAS_ISEL) { | ||
| info |= CPUINFO_ISEL; | ||
| } | ||
| if (hwcap & PPC_FEATURE_HAS_ALTIVEC) { | ||
| info |= CPUINFO_ALTIVEC; | ||
| /* We only care about the portion of VSX that overlaps Altivec. */ | ||
| if (hwcap & PPC_FEATURE_HAS_VSX) { | ||
| info |= CPUINFO_VSX; | ||
| } | ||
| } | ||
|
|
||
| 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