1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright (C) 2012 Regents of the University of California
6 #ifndef _ASM_RISCV_SWITCH_TO_H
7 #define _ASM_RISCV_SWITCH_TO_H
9 #include <linux/jump_label.h>
10 #include <linux/sched/task_stack.h>
11 #include <asm/hwcap.h>
12 #include <asm/processor.h>
13 #include <asm/ptrace.h>
17 extern void __fstate_save(struct task_struct *save_to);
18 extern void __fstate_restore(struct task_struct *restore_from);
20 static inline void __fstate_clean(struct pt_regs *regs)
22 regs->status = (regs->status & ~SR_FS) | SR_FS_CLEAN;
25 static inline void fstate_off(struct task_struct *task,
28 regs->status = (regs->status & ~SR_FS) | SR_FS_OFF;
31 static inline void fstate_save(struct task_struct *task,
34 if ((regs->status & SR_FS) == SR_FS_DIRTY) {
40 static inline void fstate_restore(struct task_struct *task,
43 if ((regs->status & SR_FS) != SR_FS_OFF) {
44 __fstate_restore(task);
49 static inline void __switch_to_aux(struct task_struct *prev,
50 struct task_struct *next)
54 regs = task_pt_regs(prev);
55 if (unlikely(regs->status & SR_SD))
56 fstate_save(prev, regs);
57 fstate_restore(next, task_pt_regs(next));
60 static __always_inline bool has_fpu(void)
62 return riscv_has_extension_likely(RISCV_ISA_EXT_f) ||
63 riscv_has_extension_likely(RISCV_ISA_EXT_d);
66 static __always_inline bool has_fpu(void) { return false; }
67 #define fstate_save(task, regs) do { } while (0)
68 #define fstate_restore(task, regs) do { } while (0)
69 #define __switch_to_aux(__prev, __next) do { } while (0)
72 extern struct task_struct *__switch_to(struct task_struct *,
73 struct task_struct *);
75 #define switch_to(prev, next, last) \
77 struct task_struct *__prev = (prev); \
78 struct task_struct *__next = (next); \
80 __switch_to_aux(__prev, __next); \
81 ((last) = __switch_to(__prev, __next)); \
84 #endif /* _ASM_RISCV_SWITCH_TO_H */