xref: /linux/arch/riscv/kernel/kernel_mode_fpu.c (revision c532de5a67a70f8533d495f8f2aaa9a0491c3ad0)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Copyright (C) 2023 SiFive
4  */
5 
6 #include <linux/export.h>
7 #include <linux/preempt.h>
8 
9 #include <asm/csr.h>
10 #include <asm/fpu.h>
11 #include <asm/processor.h>
12 #include <asm/switch_to.h>
13 
14 void kernel_fpu_begin(void)
15 {
16 	preempt_disable();
17 	fstate_save(current, task_pt_regs(current));
18 	csr_set(CSR_SSTATUS, SR_FS);
19 }
20 EXPORT_SYMBOL_GPL(kernel_fpu_begin);
21 
22 void kernel_fpu_end(void)
23 {
24 	csr_clear(CSR_SSTATUS, SR_FS);
25 	fstate_restore(current, task_pt_regs(current));
26 	preempt_enable();
27 }
28 EXPORT_SYMBOL_GPL(kernel_fpu_end);
29