summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIcenowy Zheng <uwu@icenowy.me>2025-11-11 22:47:55 +0800
committerHans Kristian Rosbach <hk-github@circlestorm.org>2025-11-13 23:16:17 +0100
commit29cf6242ebb56810c3516e3ce5b4ee8f27ad9b07 (patch)
tree6bcf9afcbab8cdbfdf9b38eeca4d66ee5e30b061
parent780838b040ccdd4c1fc68debfdeeaab8e6b51742 (diff)
downloadProject-Tick-29cf6242ebb56810c3516e3ce5b4ee8f27ad9b07.tar.gz
Project-Tick-29cf6242ebb56810c3516e3ce5b4ee8f27ad9b07.zip
riscv: features: test HWCAP regardless of kernel versions
The HWCAP facility comes at day 1 of Linux RISC-V support (date back to 4.15), only the V bit definition is added in 6.5 (because proper vector support is added in that version too). There should be no need to test kernel version number before accessing hwcap, only the V bit will never be present on kernel older than 6.5 (except dirty patched downstream ones). For Xtheadvector systems that bogusly announce V bit in HWCAP, the assembly code should be able to factor them out. This is tested on a Sophgo SG2042 machine with 6.1 kernel. Signed-off-by: Icenowy Zheng <uwu@icenowy.me>
-rw-r--r--arch/riscv/riscv_features.c37
1 files changed, 1 insertions, 36 deletions
diff --git a/arch/riscv/riscv_features.c b/arch/riscv/riscv_features.c
index 25aed5fd5d..7c04a0eec5 100644
--- a/arch/riscv/riscv_features.c
+++ b/arch/riscv/riscv_features.c
@@ -13,38 +13,6 @@
#define ISA_V_HWCAP (1 << ('v' - 'a'))
#define ISA_ZBC_HWCAP (1 << 29)
-int Z_INTERNAL is_kernel_version_greater_or_equal_to_6_5(void) {
- struct utsname buffer;
- if (uname(&buffer) == -1) {
- // uname failed
- return 0;
- }
-
- int major, minor;
- if (sscanf(buffer.release, "%d.%d", &major, &minor) != 2) {
- // Something bad with uname()
- return 0;
- }
-
- if (major > 6 || (major == 6 && minor >= 5))
- return 1;
- return 0;
-}
-
-void Z_INTERNAL riscv_check_features_compile_time(struct riscv_cpu_features *features) {
-#if defined(__riscv_v) && defined(__linux__)
- features->has_rvv = 1;
-#else
- features->has_rvv = 0;
-#endif
-
-#if defined(__riscv_zbc) && defined(__linux__)
- features->has_zbc = 1;
-#else
- features->has_zbc = 0;
-#endif
-}
-
void Z_INTERNAL riscv_check_features_runtime(struct riscv_cpu_features *features) {
#if defined(__linux__) && defined(HAVE_SYS_AUXV_H)
unsigned long hw_cap = getauxval(AT_HWCAP);
@@ -56,10 +24,7 @@ void Z_INTERNAL riscv_check_features_runtime(struct riscv_cpu_features *features
}
void Z_INTERNAL riscv_check_features(struct riscv_cpu_features *features) {
- if (is_kernel_version_greater_or_equal_to_6_5())
- riscv_check_features_runtime(features);
- else
- riscv_check_features_compile_time(features);
+ riscv_check_features_runtime(features);
#ifdef RISCV_RVV
if (features->has_rvv) {
size_t e8m1_vec_len;