-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
riscv: Support XUANTIE extended CSR save/restore during task switching
This patch focuses on two XUANTIE extended CSRs: - FXCR[31]: Process 16-bit floating point numbers according to the BFloat 16 format. - UTNMODE: FP8 output can be ovf or sat mode. Introduced by XUANTIE C908X. When using, first enable CONFIG_XUANTIE_CSR_EXT, then set the 'riscv,isa' fields of dts to dynamically control whether to save/restore the corresponding CSR. For example, for FXCR, you need to add 'xtheadfxcr', and for UTNMODE, you need to add 'xtheadutnmode'. Signed-off-by: Chen Pei <[email protected]>
- Loading branch information
Showing
7 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* SPDX-License-Identifier: GPL-2.0 */ | ||
#ifndef _ASM_XUANTIE_CSR_EXT_H | ||
#define _ASM_XUANTIE_CSR_EXT_H | ||
|
||
#ifdef CONFIG_XUANTIE_CSR_EXT | ||
|
||
#include <asm/csr.h> | ||
#include <asm/hwcap.h> | ||
#include <linux/sched.h> | ||
|
||
static __always_inline bool has_xuantie_csr_ext(void) | ||
{ | ||
return riscv_has_extension_unlikely(RISCV_ISA_EXT_XTHEADFXCR) | | ||
riscv_has_extension_unlikely(RISCV_ISA_EXT_XTHEADUTNMODE); | ||
} | ||
|
||
static inline void __switch_to_xuantie_csr_ext(struct task_struct *prev, | ||
struct task_struct *next) | ||
{ | ||
if (riscv_has_extension_likely(RISCV_ISA_EXT_XTHEADFXCR)) { | ||
csr_set(CSR_STATUS, SR_FS); | ||
prev->thread.fxcr = csr_read(CSR_FXCR); | ||
csr_write(CSR_FXCR, next->thread.fxcr); | ||
csr_clear(CSR_STATUS, SR_FS); | ||
} | ||
|
||
if (riscv_has_extension_likely(RISCV_ISA_EXT_XTHEADUTNMODE)) { | ||
prev->thread.utnmode = csr_read(CSR_UTNMODE); | ||
csr_write(CSR_UTNMODE, next->thread.utnmode); | ||
} | ||
} | ||
#else | ||
|
||
static __always_inline bool has_xuantie_csr_ext(void) { return false; } | ||
#define __switch_to_xuantie_csr_ext(__prev, __next) do {} while (0) | ||
|
||
#endif /* CONFIG_XUANTIE_CSR_EXT */ | ||
#endif /* _ASM_XUANTIE_CSR_EXT_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters