mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 02:30:34 +02:00 
			
		
		
		
	This patch adds task switch support for vector. It also supports all lengths of vlen. Suggested-by: Andrew Waterman <andrew@sifive.com> Co-developed-by: Nick Knight <nick.knight@sifive.com> Signed-off-by: Nick Knight <nick.knight@sifive.com> Co-developed-by: Guo Ren <guoren@linux.alibaba.com> Signed-off-by: Guo Ren <guoren@linux.alibaba.com> Co-developed-by: Vincent Chen <vincent.chen@sifive.com> Signed-off-by: Vincent Chen <vincent.chen@sifive.com> Co-developed-by: Ruinland Tsai <ruinland.tsai@sifive.com> Signed-off-by: Ruinland Tsai <ruinland.tsai@sifive.com> Signed-off-by: Greentime Hu <greentime.hu@sifive.com> Signed-off-by: Vineet Gupta <vineetg@rivosinc.com> Signed-off-by: Andy Chiu <andy.chiu@sifive.com> Reviewed-by: Conor Dooley <conor.dooley@microchip.com> Reviewed-by: Björn Töpel <bjorn@rivosinc.com> Reviewed-by: Heiko Stuebner <heiko.stuebner@vrull.eu> Tested-by: Heiko Stuebner <heiko.stuebner@vrull.eu> Link: https://lore.kernel.org/r/20230605110724.21391-11-andy.chiu@sifive.com Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
		
			
				
	
	
		
			87 lines
		
	
	
	
		
			2.2 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			87 lines
		
	
	
	
		
			2.2 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
/* SPDX-License-Identifier: GPL-2.0-only */
 | 
						|
/*
 | 
						|
 * Copyright (C) 2012 Regents of the University of California
 | 
						|
 */
 | 
						|
 | 
						|
#ifndef _ASM_RISCV_SWITCH_TO_H
 | 
						|
#define _ASM_RISCV_SWITCH_TO_H
 | 
						|
 | 
						|
#include <linux/jump_label.h>
 | 
						|
#include <linux/sched/task_stack.h>
 | 
						|
#include <asm/vector.h>
 | 
						|
#include <asm/hwcap.h>
 | 
						|
#include <asm/processor.h>
 | 
						|
#include <asm/ptrace.h>
 | 
						|
#include <asm/csr.h>
 | 
						|
 | 
						|
#ifdef CONFIG_FPU
 | 
						|
extern void __fstate_save(struct task_struct *save_to);
 | 
						|
extern void __fstate_restore(struct task_struct *restore_from);
 | 
						|
 | 
						|
static inline void __fstate_clean(struct pt_regs *regs)
 | 
						|
{
 | 
						|
	regs->status = (regs->status & ~SR_FS) | SR_FS_CLEAN;
 | 
						|
}
 | 
						|
 | 
						|
static inline void fstate_off(struct task_struct *task,
 | 
						|
			      struct pt_regs *regs)
 | 
						|
{
 | 
						|
	regs->status = (regs->status & ~SR_FS) | SR_FS_OFF;
 | 
						|
}
 | 
						|
 | 
						|
static inline void fstate_save(struct task_struct *task,
 | 
						|
			       struct pt_regs *regs)
 | 
						|
{
 | 
						|
	if ((regs->status & SR_FS) == SR_FS_DIRTY) {
 | 
						|
		__fstate_save(task);
 | 
						|
		__fstate_clean(regs);
 | 
						|
	}
 | 
						|
}
 | 
						|
 | 
						|
static inline void fstate_restore(struct task_struct *task,
 | 
						|
				  struct pt_regs *regs)
 | 
						|
{
 | 
						|
	if ((regs->status & SR_FS) != SR_FS_OFF) {
 | 
						|
		__fstate_restore(task);
 | 
						|
		__fstate_clean(regs);
 | 
						|
	}
 | 
						|
}
 | 
						|
 | 
						|
static inline void __switch_to_fpu(struct task_struct *prev,
 | 
						|
				   struct task_struct *next)
 | 
						|
{
 | 
						|
	struct pt_regs *regs;
 | 
						|
 | 
						|
	regs = task_pt_regs(prev);
 | 
						|
	if (unlikely(regs->status & SR_SD))
 | 
						|
		fstate_save(prev, regs);
 | 
						|
	fstate_restore(next, task_pt_regs(next));
 | 
						|
}
 | 
						|
 | 
						|
static __always_inline bool has_fpu(void)
 | 
						|
{
 | 
						|
	return riscv_has_extension_likely(RISCV_ISA_EXT_f) ||
 | 
						|
		riscv_has_extension_likely(RISCV_ISA_EXT_d);
 | 
						|
}
 | 
						|
#else
 | 
						|
static __always_inline bool has_fpu(void) { return false; }
 | 
						|
#define fstate_save(task, regs) do { } while (0)
 | 
						|
#define fstate_restore(task, regs) do { } while (0)
 | 
						|
#define __switch_to_fpu(__prev, __next) do { } while (0)
 | 
						|
#endif
 | 
						|
 | 
						|
extern struct task_struct *__switch_to(struct task_struct *,
 | 
						|
				       struct task_struct *);
 | 
						|
 | 
						|
#define switch_to(prev, next, last)			\
 | 
						|
do {							\
 | 
						|
	struct task_struct *__prev = (prev);		\
 | 
						|
	struct task_struct *__next = (next);		\
 | 
						|
	if (has_fpu())					\
 | 
						|
		__switch_to_fpu(__prev, __next);	\
 | 
						|
	if (has_vector())					\
 | 
						|
		__switch_to_vector(__prev, __next);	\
 | 
						|
	((last) = __switch_to(__prev, __next));		\
 | 
						|
} while (0)
 | 
						|
 | 
						|
#endif /* _ASM_RISCV_SWITCH_TO_H */
 |