[RFC PATCH 1/3] riscv: sbi: Add FWFT get helper
From: Xie Bo
Date: Tue Jul 21 2026 - 04:01:10 EST
The SBI FWFT extension supports querying a feature's value on the local
hart, but the RISC-V SBI wrapper currently only exposes SET operations.
Add a generic GET helper which maps SBI errors to Linux errno values and
only updates the caller's output on success.
Signed-off-by: Xie Bo <xb@xxxxxxxxxxxxx>
---
arch/riscv/include/asm/sbi.h | 1 +
arch/riscv/kernel/sbi.c | 29 +++++++++++++++++++++++++++++
2 files changed, 30 insertions(+)
diff --git a/arch/riscv/include/asm/sbi.h b/arch/riscv/include/asm/sbi.h
index 5725e0c..b1773b1 100644
--- a/arch/riscv/include/asm/sbi.h
+++ b/arch/riscv/include/asm/sbi.h
@@ -607,6 +607,7 @@ int sbi_remote_hfence_vvma_asid(const struct cpumask *cpu_mask,
unsigned long asid);
long sbi_probe_extension(int ext);
+int sbi_fwft_get(u32 feature, unsigned long *value);
int sbi_fwft_set(u32 feature, unsigned long value, unsigned long flags);
int sbi_fwft_set_cpumask(const cpumask_t *mask, u32 feature,
unsigned long value, unsigned long flags);
diff --git a/arch/riscv/kernel/sbi.c b/arch/riscv/kernel/sbi.c
index c443337..51e0c58 100644
--- a/arch/riscv/kernel/sbi.c
+++ b/arch/riscv/kernel/sbi.c
@@ -318,6 +318,35 @@ static void cpu_sbi_fwft_set(void *arg)
atomic_set(&req->error, ret);
}
+/**
+ * sbi_fwft_get() - Get a feature value on the local hart
+ * @feature: The feature ID to get
+ * @value: Where to store the feature value
+ *
+ * Return: 0 on success, appropriate Linux error code otherwise.
+ */
+int sbi_fwft_get(u32 feature, unsigned long *value)
+{
+ struct sbiret ret;
+ int error;
+
+ if (!sbi_fwft_supported)
+ return -EOPNOTSUPP;
+
+ if (!value)
+ return -EINVAL;
+
+ ret = sbi_ecall(SBI_EXT_FWFT, SBI_EXT_FWFT_GET,
+ feature, 0, 0, 0, 0, 0);
+ error = sbi_err_map_linux_errno(ret.error);
+ if (error)
+ return error;
+
+ *value = ret.value;
+
+ return 0;
+}
+
/**
* sbi_fwft_set() - Set a feature on the local hart
* @feature: The feature ID to be set
--
2.17.1