| .. | .. |
|---|
| 1 | +/* SPDX-License-Identifier: GPL-2.0-only */ |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * 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. |
|---|
| 12 | 4 | */ |
|---|
| 13 | 5 | |
|---|
| 14 | 6 | #ifndef _ASM_RISCV_SWITCH_TO_H |
|---|
| 15 | 7 | #define _ASM_RISCV_SWITCH_TO_H |
|---|
| 16 | 8 | |
|---|
| 9 | +#include <linux/sched/task_stack.h> |
|---|
| 17 | 10 | #include <asm/processor.h> |
|---|
| 18 | 11 | #include <asm/ptrace.h> |
|---|
| 19 | 12 | #include <asm/csr.h> |
|---|
| 20 | 13 | |
|---|
| 14 | +#ifdef CONFIG_FPU |
|---|
| 21 | 15 | extern void __fstate_save(struct task_struct *save_to); |
|---|
| 22 | 16 | extern void __fstate_restore(struct task_struct *restore_from); |
|---|
| 23 | 17 | |
|---|
| 24 | 18 | static inline void __fstate_clean(struct pt_regs *regs) |
|---|
| 25 | 19 | { |
|---|
| 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; |
|---|
| 27 | 27 | } |
|---|
| 28 | 28 | |
|---|
| 29 | 29 | static inline void fstate_save(struct task_struct *task, |
|---|
| 30 | 30 | struct pt_regs *regs) |
|---|
| 31 | 31 | { |
|---|
| 32 | | - if ((regs->sstatus & SR_FS) == SR_FS_DIRTY) { |
|---|
| 32 | + if ((regs->status & SR_FS) == SR_FS_DIRTY) { |
|---|
| 33 | 33 | __fstate_save(task); |
|---|
| 34 | 34 | __fstate_clean(regs); |
|---|
| 35 | 35 | } |
|---|
| .. | .. |
|---|
| 38 | 38 | static inline void fstate_restore(struct task_struct *task, |
|---|
| 39 | 39 | struct pt_regs *regs) |
|---|
| 40 | 40 | { |
|---|
| 41 | | - if ((regs->sstatus & SR_FS) != SR_FS_OFF) { |
|---|
| 41 | + if ((regs->status & SR_FS) != SR_FS_OFF) { |
|---|
| 42 | 42 | __fstate_restore(task); |
|---|
| 43 | 43 | __fstate_clean(regs); |
|---|
| 44 | 44 | } |
|---|
| .. | .. |
|---|
| 50 | 50 | struct pt_regs *regs; |
|---|
| 51 | 51 | |
|---|
| 52 | 52 | regs = task_pt_regs(prev); |
|---|
| 53 | | - if (unlikely(regs->sstatus & SR_SD)) |
|---|
| 53 | + if (unlikely(regs->status & SR_SD)) |
|---|
| 54 | 54 | fstate_save(prev, regs); |
|---|
| 55 | 55 | fstate_restore(next, task_pt_regs(next)); |
|---|
| 56 | 56 | } |
|---|
| 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 |
|---|
| 57 | 65 | |
|---|
| 58 | 66 | extern struct task_struct *__switch_to(struct task_struct *, |
|---|
| 59 | 67 | struct task_struct *); |
|---|
| .. | .. |
|---|
| 62 | 70 | do { \ |
|---|
| 63 | 71 | struct task_struct *__prev = (prev); \ |
|---|
| 64 | 72 | struct task_struct *__next = (next); \ |
|---|
| 65 | | - __switch_to_aux(__prev, __next); \ |
|---|
| 73 | + if (has_fpu) \ |
|---|
| 74 | + __switch_to_aux(__prev, __next); \ |
|---|
| 66 | 75 | ((last) = __switch_to(__prev, __next)); \ |
|---|
| 67 | 76 | } while (0) |
|---|
| 68 | 77 | |
|---|