Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
[cris-mirror.git] / arch / riscv / include / asm / switch_to.h
blobdd6b05bff75b6fd41b3fd12239ace6edcf022bad
1 /*
2 * Copyright (C) 2012 Regents of the University of California
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
14 #ifndef _ASM_RISCV_SWITCH_TO_H
15 #define _ASM_RISCV_SWITCH_TO_H
17 #include <asm/processor.h>
18 #include <asm/ptrace.h>
19 #include <asm/csr.h>
21 extern void __fstate_save(struct task_struct *save_to);
22 extern void __fstate_restore(struct task_struct *restore_from);
24 static inline void __fstate_clean(struct pt_regs *regs)
26 regs->sstatus |= (regs->sstatus & ~(SR_FS)) | SR_FS_CLEAN;
29 static inline void fstate_save(struct task_struct *task,
30 struct pt_regs *regs)
32 if ((regs->sstatus & 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->sstatus & 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->sstatus & SR_SD))
54 fstate_save(prev, regs);
55 fstate_restore(next, task_pt_regs(next));
58 extern struct task_struct *__switch_to(struct task_struct *,
59 struct task_struct *);
61 #define switch_to(prev, next, last) \
62 do { \
63 struct task_struct *__prev = (prev); \
64 struct task_struct *__next = (next); \
65 __switch_to_aux(__prev, __next); \
66 ((last) = __switch_to(__prev, __next)); \
67 } while (0)
69 #endif /* _ASM_RISCV_SWITCH_TO_H */