Linux 5.6.13
[linux/fpc-iii.git] / arch / riscv / include / asm / switch_to.h
blob407bcc96a7109395bc36d46947942d5b376e6c04
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3 * Copyright (C) 2012 Regents of the University of California
4 */
6 #ifndef _ASM_RISCV_SWITCH_TO_H
7 #define _ASM_RISCV_SWITCH_TO_H
9 #include <linux/sched/task_stack.h>
10 #include <asm/processor.h>
11 #include <asm/ptrace.h>
12 #include <asm/csr.h>
14 #ifdef CONFIG_FPU
15 extern void __fstate_save(struct task_struct *save_to);
16 extern void __fstate_restore(struct task_struct *restore_from);
18 static inline void __fstate_clean(struct pt_regs *regs)
20 regs->status = (regs->status & ~SR_FS) | SR_FS_CLEAN;
23 static inline void fstate_off(struct task_struct *task,
24 struct pt_regs *regs)
26 regs->status = (regs->status & ~SR_FS) | SR_FS_OFF;
29 static inline void fstate_save(struct task_struct *task,
30 struct pt_regs *regs)
32 if ((regs->status & SR_FS) == SR_FS_DIRTY) {
33 __fstate_save(task);
34 __fstate_clean(regs);
38 static inline void fstate_restore(struct task_struct *task,
39 struct pt_regs *regs)
41 if ((regs->status & SR_FS) != SR_FS_OFF) {
42 __fstate_restore(task);
43 __fstate_clean(regs);
47 static inline void __switch_to_aux(struct task_struct *prev,
48 struct task_struct *next)
50 struct pt_regs *regs;
52 regs = task_pt_regs(prev);
53 if (unlikely(regs->status & SR_SD))
54 fstate_save(prev, regs);
55 fstate_restore(next, task_pt_regs(next));
58 extern bool has_fpu;
59 #else
60 #define has_fpu false
61 #define fstate_save(task, regs) do { } while (0)
62 #define fstate_restore(task, regs) do { } while (0)
63 #define __switch_to_aux(__prev, __next) do { } while (0)
64 #endif
66 extern struct task_struct *__switch_to(struct task_struct *,
67 struct task_struct *);
69 #define switch_to(prev, next, last) \
70 do { \
71 struct task_struct *__prev = (prev); \
72 struct task_struct *__next = (next); \
73 if (has_fpu) \
74 __switch_to_aux(__prev, __next); \
75 ((last) = __switch_to(__prev, __next)); \
76 } while (0)
78 #endif /* _ASM_RISCV_SWITCH_TO_H */