1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2023 Loongson Technology Corporation Limited
7 #include <linux/init.h>
11 static DEFINE_PER_CPU(bool, in_kernel_fpu);
13 void kernel_fpu_begin(void)
17 WARN_ON(this_cpu_read(in_kernel_fpu));
19 this_cpu_write(in_kernel_fpu, true);
24 _save_fp(¤t->thread.fpu);
26 write_fcsr(LOONGARCH_FCSR0, 0);
28 EXPORT_SYMBOL_GPL(kernel_fpu_begin);
30 void kernel_fpu_end(void)
32 WARN_ON(!this_cpu_read(in_kernel_fpu));
37 _restore_fp(¤t->thread.fpu);
39 this_cpu_write(in_kernel_fpu, false);
43 EXPORT_SYMBOL_GPL(kernel_fpu_end);