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/processor.h>
12 #include <asm/ptrace.h>
16 extern void __fstate_save(struct task_struct
*save_to
);
17 extern void __fstate_restore(struct task_struct
*restore_from
);
19 static inline void __fstate_clean(struct pt_regs
*regs
)
21 regs
->status
= (regs
->status
& ~SR_FS
) | SR_FS_CLEAN
;
24 static inline void fstate_off(struct task_struct
*task
,
27 regs
->status
= (regs
->status
& ~SR_FS
) | SR_FS_OFF
;
30 static inline void fstate_save(struct task_struct
*task
,
33 if ((regs
->status
& SR_FS
) == SR_FS_DIRTY
) {
39 static inline void fstate_restore(struct task_struct
*task
,
42 if ((regs
->status
& SR_FS
) != SR_FS_OFF
) {
43 __fstate_restore(task
);
48 static inline void __switch_to_aux(struct task_struct
*prev
,
49 struct task_struct
*next
)
53 regs
= task_pt_regs(prev
);
54 if (unlikely(regs
->status
& SR_SD
))
55 fstate_save(prev
, regs
);
56 fstate_restore(next
, task_pt_regs(next
));
59 extern struct static_key_false cpu_hwcap_fpu
;
60 static __always_inline
bool has_fpu(void)
62 return static_branch_likely(&cpu_hwcap_fpu
);
65 static __always_inline
bool has_fpu(void) { return false; }
66 #define fstate_save(task, regs) do { } while (0)
67 #define fstate_restore(task, regs) do { } while (0)
68 #define __switch_to_aux(__prev, __next) do { } while (0)
71 extern struct task_struct
*__switch_to(struct task_struct
*,
72 struct task_struct
*);
74 #define switch_to(prev, next, last) \
76 struct task_struct *__prev = (prev); \
77 struct task_struct *__next = (next); \
79 __switch_to_aux(__prev, __next); \
80 ((last) = __switch_to(__prev, __next)); \
83 #endif /* _ASM_RISCV_SWITCH_TO_H */