From 718e1d194f5a41c657dfe094392abdeb02356680 Mon Sep 17 00:00:00 2001 From: Dave Patel Date: Mon, 18 May 2026 14:00:22 +0530 Subject: lib: sbi: Add floating-point context save/restore support. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add support for saving and restoring RISC-V floating-point (F/D) extension state in OpenSBI. This introduces a floating-point context structure and helper routines to perform full context save and restore. The floating-point context includes storage for all 32 FPi registers (f0–f31) along with the fcsr control and status register. The register state is saved and restored using double-precision load/store instructions (fsd/fld), and single-precision load/store instructions (fsw/flw) on an RV64 system with F and D-extension support. The implementation follows an eager context switching model where the entire FP state is saved and restored on every context switch. This avoids the need for trap-based lazy management and keeps the design simple and deterministic. Signed-off-by: Dave Patel Signed-off-by: Anup Patel Link: https://lore.kernel.org/r/20260518083023.997323-3-anup.patel@oss.qualcomm.com Signed-off-by: Anup Patel --- include/sbi/sbi_fp.h | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 include/sbi/sbi_fp.h (limited to 'include') diff --git a/include/sbi/sbi_fp.h b/include/sbi/sbi_fp.h new file mode 100644 index 00000000..81998215 --- /dev/null +++ b/include/sbi/sbi_fp.h @@ -0,0 +1,35 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause + * + * Copyright (c) 2026 RISCstar Solutions. + * + * Authors: + * Dave Patel + */ +#ifndef __SBI_FP_H__ +#define __SBI_FP_H__ + +#include + +struct sbi_fp_context { +#if __riscv_d + uint64_t f[32]; +#else + uint32_t f[32]; +#endif + unsigned long fcsr; +}; + +#if defined(__riscv_f) || defined(__riscv_d) +void sbi_fp_save(struct sbi_fp_context *dst); +void sbi_fp_restore(const struct sbi_fp_context *src); +#else +static inline void sbi_fp_save(struct sbi_fp_context *dst) +{ +} +static inline void sbi_fp_restore(const struct sbi_fp_context *src) +{ +} +#endif /* __riscv_f || __riscv_d */ + +#endif /*__SBI_FP_H__ */ -- cgit v1.2.3