hc
2024-05-10 9999e48639b3cecb08ffb37358bcba3b48161b29
kernel/arch/riscv/include/asm/switch_to.h
....@@ -1,35 +1,35 @@
1
+/* SPDX-License-Identifier: GPL-2.0-only */
12 /*
23 * Copyright (C) 2012 Regents of the University of California
3
- *
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.
7
- *
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.
124 */
135
146 #ifndef _ASM_RISCV_SWITCH_TO_H
157 #define _ASM_RISCV_SWITCH_TO_H
168
9
+#include <linux/sched/task_stack.h>
1710 #include <asm/processor.h>
1811 #include <asm/ptrace.h>
1912 #include <asm/csr.h>
2013
14
+#ifdef CONFIG_FPU
2115 extern void __fstate_save(struct task_struct *save_to);
2216 extern void __fstate_restore(struct task_struct *restore_from);
2317
2418 static inline void __fstate_clean(struct pt_regs *regs)
2519 {
26
- regs->sstatus = (regs->sstatus & ~SR_FS) | SR_FS_CLEAN;
20
+ regs->status = (regs->status & ~SR_FS) | SR_FS_CLEAN;
21
+}
22
+
23
+static inline void fstate_off(struct task_struct *task,
24
+ struct pt_regs *regs)
25
+{
26
+ regs->status = (regs->status & ~SR_FS) | SR_FS_OFF;
2727 }
2828
2929 static inline void fstate_save(struct task_struct *task,
3030 struct pt_regs *regs)
3131 {
32
- if ((regs->sstatus & SR_FS) == SR_FS_DIRTY) {
32
+ if ((regs->status & SR_FS) == SR_FS_DIRTY) {
3333 __fstate_save(task);
3434 __fstate_clean(regs);
3535 }
....@@ -38,7 +38,7 @@
3838 static inline void fstate_restore(struct task_struct *task,
3939 struct pt_regs *regs)
4040 {
41
- if ((regs->sstatus & SR_FS) != SR_FS_OFF) {
41
+ if ((regs->status & SR_FS) != SR_FS_OFF) {
4242 __fstate_restore(task);
4343 __fstate_clean(regs);
4444 }
....@@ -50,10 +50,18 @@
5050 struct pt_regs *regs;
5151
5252 regs = task_pt_regs(prev);
53
- if (unlikely(regs->sstatus & SR_SD))
53
+ if (unlikely(regs->status & SR_SD))
5454 fstate_save(prev, regs);
5555 fstate_restore(next, task_pt_regs(next));
5656 }
57
+
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
5765
5866 extern struct task_struct *__switch_to(struct task_struct *,
5967 struct task_struct *);
....@@ -62,7 +70,8 @@
6270 do { \
6371 struct task_struct *__prev = (prev); \
6472 struct task_struct *__next = (next); \
65
- __switch_to_aux(__prev, __next); \
73
+ if (has_fpu) \
74
+ __switch_to_aux(__prev, __next); \
6675 ((last) = __switch_to(__prev, __next)); \
6776 } while (0)
6877