18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (C) 1999 Cort Dougan <cort@cs.nmt.edu>
48c2ecf20Sopenharmony_ci */
58c2ecf20Sopenharmony_ci#ifndef _ASM_POWERPC_SWITCH_TO_H
68c2ecf20Sopenharmony_ci#define _ASM_POWERPC_SWITCH_TO_H
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci#include <linux/sched.h>
98c2ecf20Sopenharmony_ci#include <asm/reg.h>
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_cistruct thread_struct;
128c2ecf20Sopenharmony_cistruct task_struct;
138c2ecf20Sopenharmony_cistruct pt_regs;
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ciextern struct task_struct *__switch_to(struct task_struct *,
168c2ecf20Sopenharmony_ci	struct task_struct *);
178c2ecf20Sopenharmony_ci#define switch_to(prev, next, last)	((last) = __switch_to((prev), (next)))
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ciextern struct task_struct *_switch(struct thread_struct *prev,
208c2ecf20Sopenharmony_ci				   struct thread_struct *next);
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ciextern void switch_booke_debug_regs(struct debug_reg *new_debug);
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ciextern int emulate_altivec(struct pt_regs *);
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci#ifdef CONFIG_PPC_BOOK3S_64
278c2ecf20Sopenharmony_civoid restore_math(struct pt_regs *regs);
288c2ecf20Sopenharmony_ci#else
298c2ecf20Sopenharmony_cistatic inline void restore_math(struct pt_regs *regs)
308c2ecf20Sopenharmony_ci{
318c2ecf20Sopenharmony_ci}
328c2ecf20Sopenharmony_ci#endif
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_civoid restore_tm_state(struct pt_regs *regs);
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ciextern void flush_all_to_thread(struct task_struct *);
378c2ecf20Sopenharmony_ciextern void giveup_all(struct task_struct *);
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci#ifdef CONFIG_PPC_FPU
408c2ecf20Sopenharmony_ciextern void enable_kernel_fp(void);
418c2ecf20Sopenharmony_ciextern void flush_fp_to_thread(struct task_struct *);
428c2ecf20Sopenharmony_ciextern void giveup_fpu(struct task_struct *);
438c2ecf20Sopenharmony_ciextern void save_fpu(struct task_struct *);
448c2ecf20Sopenharmony_cistatic inline void disable_kernel_fp(void)
458c2ecf20Sopenharmony_ci{
468c2ecf20Sopenharmony_ci	msr_check_and_clear(MSR_FP);
478c2ecf20Sopenharmony_ci}
488c2ecf20Sopenharmony_ci#else
498c2ecf20Sopenharmony_cistatic inline void save_fpu(struct task_struct *t) { }
508c2ecf20Sopenharmony_cistatic inline void flush_fp_to_thread(struct task_struct *t) { }
518c2ecf20Sopenharmony_ci#endif
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_ci#ifdef CONFIG_ALTIVEC
548c2ecf20Sopenharmony_ciextern void enable_kernel_altivec(void);
558c2ecf20Sopenharmony_ciextern void flush_altivec_to_thread(struct task_struct *);
568c2ecf20Sopenharmony_ciextern void giveup_altivec(struct task_struct *);
578c2ecf20Sopenharmony_ciextern void save_altivec(struct task_struct *);
588c2ecf20Sopenharmony_cistatic inline void disable_kernel_altivec(void)
598c2ecf20Sopenharmony_ci{
608c2ecf20Sopenharmony_ci	msr_check_and_clear(MSR_VEC);
618c2ecf20Sopenharmony_ci}
628c2ecf20Sopenharmony_ci#else
638c2ecf20Sopenharmony_cistatic inline void save_altivec(struct task_struct *t) { }
648c2ecf20Sopenharmony_cistatic inline void __giveup_altivec(struct task_struct *t) { }
658c2ecf20Sopenharmony_ci#endif
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ci#ifdef CONFIG_VSX
688c2ecf20Sopenharmony_ciextern void enable_kernel_vsx(void);
698c2ecf20Sopenharmony_ciextern void flush_vsx_to_thread(struct task_struct *);
708c2ecf20Sopenharmony_cistatic inline void disable_kernel_vsx(void)
718c2ecf20Sopenharmony_ci{
728c2ecf20Sopenharmony_ci	msr_check_and_clear(MSR_FP|MSR_VEC|MSR_VSX);
738c2ecf20Sopenharmony_ci}
748c2ecf20Sopenharmony_ci#else
758c2ecf20Sopenharmony_cistatic inline void enable_kernel_vsx(void)
768c2ecf20Sopenharmony_ci{
778c2ecf20Sopenharmony_ci	BUILD_BUG();
788c2ecf20Sopenharmony_ci}
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_cistatic inline void disable_kernel_vsx(void)
818c2ecf20Sopenharmony_ci{
828c2ecf20Sopenharmony_ci	BUILD_BUG();
838c2ecf20Sopenharmony_ci}
848c2ecf20Sopenharmony_ci#endif
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ci#ifdef CONFIG_SPE
878c2ecf20Sopenharmony_ciextern void enable_kernel_spe(void);
888c2ecf20Sopenharmony_ciextern void flush_spe_to_thread(struct task_struct *);
898c2ecf20Sopenharmony_ciextern void giveup_spe(struct task_struct *);
908c2ecf20Sopenharmony_ciextern void __giveup_spe(struct task_struct *);
918c2ecf20Sopenharmony_cistatic inline void disable_kernel_spe(void)
928c2ecf20Sopenharmony_ci{
938c2ecf20Sopenharmony_ci	msr_check_and_clear(MSR_SPE);
948c2ecf20Sopenharmony_ci}
958c2ecf20Sopenharmony_ci#else
968c2ecf20Sopenharmony_cistatic inline void __giveup_spe(struct task_struct *t) { }
978c2ecf20Sopenharmony_ci#endif
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_cistatic inline void clear_task_ebb(struct task_struct *t)
1008c2ecf20Sopenharmony_ci{
1018c2ecf20Sopenharmony_ci#ifdef CONFIG_PPC_BOOK3S_64
1028c2ecf20Sopenharmony_ci    /* EBB perf events are not inherited, so clear all EBB state. */
1038c2ecf20Sopenharmony_ci    t->thread.ebbrr = 0;
1048c2ecf20Sopenharmony_ci    t->thread.ebbhr = 0;
1058c2ecf20Sopenharmony_ci    t->thread.bescr = 0;
1068c2ecf20Sopenharmony_ci    t->thread.mmcr2 = 0;
1078c2ecf20Sopenharmony_ci    t->thread.mmcr0 = 0;
1088c2ecf20Sopenharmony_ci    t->thread.siar = 0;
1098c2ecf20Sopenharmony_ci    t->thread.sdar = 0;
1108c2ecf20Sopenharmony_ci    t->thread.sier = 0;
1118c2ecf20Sopenharmony_ci    t->thread.used_ebb = 0;
1128c2ecf20Sopenharmony_ci#endif
1138c2ecf20Sopenharmony_ci}
1148c2ecf20Sopenharmony_ci
1158c2ecf20Sopenharmony_ciextern int set_thread_tidr(struct task_struct *t);
1168c2ecf20Sopenharmony_ci
1178c2ecf20Sopenharmony_ci#endif /* _ASM_POWERPC_SWITCH_TO_H */
118