Skip to content

Commit df513ed

Browse files
Heiko Stuebnerpalmer-dabbelt
authored andcommitted
RISC-V: add helper function to read the vector VLEN
VLEN describes the length of each vector register and some instructions need specific minimal VLENs to work correctly. The vector code already includes a variable riscv_v_vsize that contains the value of "32 vector registers with vlenb length" that gets filled during boot. vlenb is the value contained in the CSR_VLENB register and the value represents "VLEN / 8". So add riscv_vector_vlen() to return the actual VLEN value for in-kernel users when they need to check the available VLEN. Signed-off-by: Heiko Stuebner <[email protected]> Reviewed-by: Eric Biggers <[email protected]> Signed-off-by: Jerry Shih <[email protected]> Signed-off-by: Eric Biggers <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 6613476 commit df513ed

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

arch/riscv/include/asm/vector.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,4 +284,15 @@ static inline bool riscv_v_vstate_ctrl_user_allowed(void) { return false; }
284284

285285
#endif /* CONFIG_RISCV_ISA_V */
286286

287+
/*
288+
* Return the implementation's vlen value.
289+
*
290+
* riscv_v_vsize contains the value of "32 vector registers with vlenb length"
291+
* so rebuild the vlen value in bits from it.
292+
*/
293+
static inline int riscv_vector_vlen(void)
294+
{
295+
return riscv_v_vsize / 32 * 8;
296+
}
297+
287298
#endif /* ! __ASM_RISCV_VECTOR_H */

0 commit comments

Comments
 (0)