lib: sbi: Add RISC-V vector context save/restore support

Eager context switch: Add support for saving and restoring RISC-V vector
extension state in OpenSBI. This introduces a per-hart vector context
structure and helper routines to perform full context save and restore.

The vector context includes vcsr CSRs along with storage for all 32 vector
registers. The register state is saved and restored using byte-wise vector
load/store instructions (vs8r/vl8r).

The implementation follows an eager context switching model where the entire
vector state is saved and restored on every context switch. This provides a
simple and deterministic mechanism without requiring lazy trap-based
management.

Signed-off-by: Dave Patel <dave.patel@riscstar.com>
Signed-off-by: Anup Patel <anup.patel@oss.qualcomm.com>
Link: https://lore.kernel.org/r/20260518083023.997323-2-anup.patel@oss.qualcomm.com
Signed-off-by: Anup Patel <anup@brainfault.org>
This commit is contained in:
Dave Patel
2026-05-18 14:00:21 +05:30
committed by Anup Patel
parent 79e63bc834
commit 21461156da
3 changed files with 135 additions and 0 deletions
+40
View File
@@ -0,0 +1,40 @@
/*
* SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2026 RISCstar Solutions.
*
* Authors:
* Dave Patel <dave.patel@riscstar.com>
*/
#ifndef __SBI_VECTOR_H__
#define __SBI_VECTOR_H__
#include <sbi/sbi_types.h>
struct sbi_vector_context {
unsigned long vcsr;
unsigned long vstart;
/* size depends on VLEN */
uint8_t vregs[];
};
#ifdef OPENSBI_CC_SUPPORT_VECTOR
void sbi_vector_save(struct sbi_vector_context *dst);
void sbi_vector_restore(const struct sbi_vector_context *src);
size_t sbi_vector_context_size(void);
#else
static inline void sbi_vector_save(struct sbi_vector_context *dst)
{
}
static inline void sbi_vector_restore(const struct sbi_vector_context *src)
{
}
static inline size_t sbi_vector_context_size(void)
{
return 0;
}
#endif /* OPENSBI_CC_SUPPORT_VECTOR */
#endif /* __SBI_VECTOR_H__ */