blob: 9d1fbd8be1c74277ce69c3c095755659aa8a3340 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
David Howellsae3a1972012-03-28 18:30:02 +01002/*
3 * Copyright (C) 1999 Cort Dougan <cort@cs.nmt.edu>
4 */
5#ifndef _ASM_POWERPC_SWITCH_TO_H
6#define _ASM_POWERPC_SWITCH_TO_H
7
Nicholas Piggin68b34582020-02-26 03:35:34 +10008#include <linux/sched.h>
Anton Blanchard3eb5d582015-10-29 11:44:06 +11009#include <asm/reg.h>
10
David Howellsae3a1972012-03-28 18:30:02 +010011struct thread_struct;
12struct task_struct;
13struct pt_regs;
14
15extern struct task_struct *__switch_to(struct task_struct *,
16 struct task_struct *);
17#define switch_to(prev, next, last) ((last) = __switch_to((prev), (next)))
18
David Howellsae3a1972012-03-28 18:30:02 +010019extern struct task_struct *_switch(struct thread_struct *prev,
20 struct thread_struct *next);
21
Scott Woodf5f97212013-11-22 15:52:29 -060022extern void switch_booke_debug_regs(struct debug_reg *new_debug);
David Howellsae3a1972012-03-28 18:30:02 +010023
Anton Blanchardd1e1cf22015-10-29 11:44:11 +110024extern int emulate_altivec(struct pt_regs *);
25
Nicholas Piggin6cc0c162020-02-26 03:35:37 +100026#ifdef CONFIG_PPC_BOOK3S_64
Nicholas Piggin68b34582020-02-26 03:35:34 +100027void restore_math(struct pt_regs *regs);
Nicholas Piggin6cc0c162020-02-26 03:35:37 +100028#else
29static inline void restore_math(struct pt_regs *regs)
30{
31}
32#endif
Nicholas Piggin68b34582020-02-26 03:35:34 +100033
34void restore_tm_state(struct pt_regs *regs);
35
Anton Blanchardd1e1cf22015-10-29 11:44:11 +110036extern void flush_all_to_thread(struct task_struct *);
37extern void giveup_all(struct task_struct *);
38
Kevin Hao037f0ee2013-07-14 17:02:05 +080039#ifdef CONFIG_PPC_FPU
Anton Blanchardd1e1cf22015-10-29 11:44:11 +110040extern void enable_kernel_fp(void);
Kevin Hao037f0ee2013-07-14 17:02:05 +080041extern void flush_fp_to_thread(struct task_struct *);
Kevin Hao5f20be442013-07-14 17:02:06 +080042extern void giveup_fpu(struct task_struct *);
Cyril Bur87924682016-02-29 17:53:49 +110043extern void save_fpu(struct task_struct *);
Anton Blanchard3eb5d582015-10-29 11:44:06 +110044static inline void disable_kernel_fp(void)
45{
46 msr_check_and_clear(MSR_FP);
47}
Kevin Hao037f0ee2013-07-14 17:02:05 +080048#else
Cyril Bur87924682016-02-29 17:53:49 +110049static inline void save_fpu(struct task_struct *t) { }
Kevin Hao037f0ee2013-07-14 17:02:05 +080050static inline void flush_fp_to_thread(struct task_struct *t) { }
51#endif
52
David Howellsae3a1972012-03-28 18:30:02 +010053#ifdef CONFIG_ALTIVEC
Anton Blanchardd1e1cf22015-10-29 11:44:11 +110054extern void enable_kernel_altivec(void);
David Howellsae3a1972012-03-28 18:30:02 +010055extern void flush_altivec_to_thread(struct task_struct *);
Anton Blanchard8cd3c232012-04-15 20:54:59 +000056extern void giveup_altivec(struct task_struct *);
Cyril Bur6f515d82016-02-29 17:53:50 +110057extern void save_altivec(struct task_struct *);
Anton Blanchard3eb5d582015-10-29 11:44:06 +110058static inline void disable_kernel_altivec(void)
59{
60 msr_check_and_clear(MSR_VEC);
61}
Cyril Burde2a20a2016-02-29 17:53:48 +110062#else
Cyril Bur6f515d82016-02-29 17:53:50 +110063static inline void save_altivec(struct task_struct *t) { }
Cyril Burde2a20a2016-02-29 17:53:48 +110064static inline void __giveup_altivec(struct task_struct *t) { }
David Howellsae3a1972012-03-28 18:30:02 +010065#endif
66
67#ifdef CONFIG_VSX
Anton Blanchardd1e1cf22015-10-29 11:44:11 +110068extern void enable_kernel_vsx(void);
David Howellsae3a1972012-03-28 18:30:02 +010069extern void flush_vsx_to_thread(struct task_struct *);
Anton Blanchard3eb5d582015-10-29 11:44:06 +110070static inline void disable_kernel_vsx(void)
71{
72 msr_check_and_clear(MSR_FP|MSR_VEC|MSR_VSX);
73}
Christophe Leroybd737582021-03-09 08:39:39 +000074#else
75static inline void enable_kernel_vsx(void)
76{
77 BUILD_BUG();
78}
79
80static inline void disable_kernel_vsx(void)
81{
82 BUILD_BUG();
83}
David Howellsae3a1972012-03-28 18:30:02 +010084#endif
85
86#ifdef CONFIG_SPE
Anton Blanchardd1e1cf22015-10-29 11:44:11 +110087extern void enable_kernel_spe(void);
David Howellsae3a1972012-03-28 18:30:02 +010088extern void flush_spe_to_thread(struct task_struct *);
Anton Blanchard98da5812015-10-29 11:44:01 +110089extern void giveup_spe(struct task_struct *);
90extern void __giveup_spe(struct task_struct *);
Anton Blanchard3eb5d582015-10-29 11:44:06 +110091static inline void disable_kernel_spe(void)
92{
93 msr_check_and_clear(MSR_SPE);
94}
Cyril Burde2a20a2016-02-29 17:53:48 +110095#else
96static inline void __giveup_spe(struct task_struct *t) { }
David Howellsae3a1972012-03-28 18:30:02 +010097#endif
98
Michael Ellerman330a1eb2013-06-28 18:15:16 +100099static inline void clear_task_ebb(struct task_struct *t)
100{
101#ifdef CONFIG_PPC_BOOK3S_64
102 /* EBB perf events are not inherited, so clear all EBB state. */
Michael Ellerman3df48c92014-06-10 16:46:21 +1000103 t->thread.ebbrr = 0;
104 t->thread.ebbhr = 0;
Michael Ellerman330a1eb2013-06-28 18:15:16 +1000105 t->thread.bescr = 0;
106 t->thread.mmcr2 = 0;
107 t->thread.mmcr0 = 0;
108 t->thread.siar = 0;
109 t->thread.sdar = 0;
110 t->thread.sier = 0;
111 t->thread.used_ebb = 0;
112#endif
113}
114
Sukadev Bhattiproluec233ed2017-11-07 18:23:53 -0800115extern int set_thread_tidr(struct task_struct *t);
Sukadev Bhattiproluec233ed2017-11-07 18:23:53 -0800116
David Howellsae3a1972012-03-28 18:30:02 +0100117#endif /* _ASM_POWERPC_SWITCH_TO_H */