12874c5fdSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */
2b8b572e1SStephen Rothwell #ifndef _ASM_POWERPC_PROCESSOR_H
3b8b572e1SStephen Rothwell #define _ASM_POWERPC_PROCESSOR_H
4b8b572e1SStephen Rothwell 
5b8b572e1SStephen Rothwell /*
6b8b572e1SStephen Rothwell  * Copyright (C) 2001 PPC 64 Team, IBM Corp
7b8b572e1SStephen Rothwell  */
8b8b572e1SStephen Rothwell 
98f8cffd9SChristophe Leroy #include <vdso/processor.h>
108f8cffd9SChristophe Leroy 
11b8b572e1SStephen Rothwell #include <asm/reg.h>
12b8b572e1SStephen Rothwell 
13b8b572e1SStephen Rothwell #ifdef CONFIG_VSX
14b8b572e1SStephen Rothwell #define TS_FPRWIDTH 2
15e156bd8aSAnton Blanchard 
16e156bd8aSAnton Blanchard #ifdef __BIG_ENDIAN__
17e156bd8aSAnton Blanchard #define TS_FPROFFSET 0
18e156bd8aSAnton Blanchard #define TS_VSRLOWOFFSET 1
19e156bd8aSAnton Blanchard #else
20e156bd8aSAnton Blanchard #define TS_FPROFFSET 1
21e156bd8aSAnton Blanchard #define TS_VSRLOWOFFSET 0
22e156bd8aSAnton Blanchard #endif
23e156bd8aSAnton Blanchard 
24b8b572e1SStephen Rothwell #else
25b8b572e1SStephen Rothwell #define TS_FPRWIDTH 1
26e156bd8aSAnton Blanchard #define TS_FPROFFSET 0
27b8b572e1SStephen Rothwell #endif
28b8b572e1SStephen Rothwell 
2992779245SHaren Myneni #ifdef CONFIG_PPC64
3092779245SHaren Myneni /* Default SMT priority is set to 3. Use 11- 13bits to save priority. */
3192779245SHaren Myneni #define PPR_PRIORITY 3
3292779245SHaren Myneni #ifdef __ASSEMBLY__
334c2de74cSNicholas Piggin #define DEFAULT_PPR (PPR_PRIORITY << 50)
3492779245SHaren Myneni #else
354c2de74cSNicholas Piggin #define DEFAULT_PPR ((u64)PPR_PRIORITY << 50)
3692779245SHaren Myneni #endif /* __ASSEMBLY__ */
3792779245SHaren Myneni #endif /* CONFIG_PPC64 */
3892779245SHaren Myneni 
39b8b572e1SStephen Rothwell #ifndef __ASSEMBLY__
4062b84265SChristophe Leroy #include <linux/types.h>
4137333040SChristophe Leroy #include <linux/thread_info.h>
42b8b572e1SStephen Rothwell #include <asm/ptrace.h>
439422de3eSMichael Neuling #include <asm/hw_breakpoint.h>
44b8b572e1SStephen Rothwell 
45b8b572e1SStephen Rothwell /* We do _not_ want to define new machine types at all, those must die
46b8b572e1SStephen Rothwell  * in favor of using the device-tree
47b8b572e1SStephen Rothwell  * -- BenH.
48b8b572e1SStephen Rothwell  */
49b8b572e1SStephen Rothwell 
50933ee711SPaul Bolle /* PREP sub-platform types. Unused */
51b8b572e1SStephen Rothwell #define _PREP_Motorola	0x01	/* motorola prep */
52b8b572e1SStephen Rothwell #define _PREP_Firm	0x02	/* firmworks prep */
53b8b572e1SStephen Rothwell #define _PREP_IBM	0x00	/* ibm prep */
54b8b572e1SStephen Rothwell #define _PREP_Bull	0x03	/* bull prep */
55b8b572e1SStephen Rothwell 
56b8b572e1SStephen Rothwell /* CHRP sub-platform types. These are arbitrary */
57b8b572e1SStephen Rothwell #define _CHRP_Motorola	0x04	/* motorola chrp, the cobra */
58b8b572e1SStephen Rothwell #define _CHRP_IBM	0x05	/* IBM chrp, the longtrail and longtrail 2 */
59b8b572e1SStephen Rothwell #define _CHRP_Pegasos	0x06	/* Genesi/bplan's Pegasos and Pegasos2 */
60b8b572e1SStephen Rothwell #define _CHRP_briq	0x07	/* TotalImpact's briQ */
61b8b572e1SStephen Rothwell 
62b8b572e1SStephen Rothwell #if defined(__KERNEL__) && defined(CONFIG_PPC32)
63b8b572e1SStephen Rothwell 
64b8b572e1SStephen Rothwell extern int _chrp_type;
65b8b572e1SStephen Rothwell 
66b8b572e1SStephen Rothwell #endif /* defined(__KERNEL__) && defined(CONFIG_PPC32) */
67b8b572e1SStephen Rothwell 
68b8b572e1SStephen Rothwell #ifdef __KERNEL__
69b8b572e1SStephen Rothwell 
7092ab45c5SChristophe Leroy #ifdef CONFIG_PPC64
7192ab45c5SChristophe Leroy #include <asm/task_size_64.h>
7292ab45c5SChristophe Leroy #else
7392ab45c5SChristophe Leroy #include <asm/task_size_32.h>
7492ab45c5SChristophe Leroy #endif
7592ab45c5SChristophe Leroy 
76b8b572e1SStephen Rothwell struct task_struct;
77b8b572e1SStephen Rothwell void start_thread(struct pt_regs *regs, unsigned long fdptr, unsigned long sp);
78b8b572e1SStephen Rothwell 
79de79f7b9SPaul Mackerras #define TS_FPR(i) fp_state.fpr[i][TS_FPROFFSET]
80000ec280SCyril Bur #define TS_CKFPR(i) ckfp_state.fpr[i][TS_FPROFFSET]
81de79f7b9SPaul Mackerras 
82de79f7b9SPaul Mackerras /* FP and VSX 0-31 register set */
83de79f7b9SPaul Mackerras struct thread_fp_state {
84de79f7b9SPaul Mackerras 	u64	fpr[32][TS_FPRWIDTH] __attribute__((aligned(16)));
85de79f7b9SPaul Mackerras 	u64	fpscr;		/* Floating point status */
86de79f7b9SPaul Mackerras };
87de79f7b9SPaul Mackerras 
88de79f7b9SPaul Mackerras /* Complete AltiVec register set including VSCR */
89de79f7b9SPaul Mackerras struct thread_vr_state {
90de79f7b9SPaul Mackerras 	vector128	vr[32] __attribute__((aligned(16)));
91de79f7b9SPaul Mackerras 	vector128	vscr __attribute__((aligned(16)));
92de79f7b9SPaul Mackerras };
93b8b572e1SStephen Rothwell 
9451ae8d4aSBharat Bhushan struct debug_reg {
9599396ac1SDave Kleikamp #ifdef CONFIG_PPC_ADV_DEBUG_REGS
9699396ac1SDave Kleikamp 	/*
9799396ac1SDave Kleikamp 	 * The following help to manage the use of Debug Control Registers
9899396ac1SDave Kleikamp 	 * om the BookE platforms.
9999396ac1SDave Kleikamp 	 */
100d8899bb2SBharat Bhushan 	uint32_t	dbcr0;
101d8899bb2SBharat Bhushan 	uint32_t	dbcr1;
10299396ac1SDave Kleikamp #ifdef CONFIG_BOOKE
103d8899bb2SBharat Bhushan 	uint32_t	dbcr2;
10499396ac1SDave Kleikamp #endif
10599396ac1SDave Kleikamp 	/*
10699396ac1SDave Kleikamp 	 * The stored value of the DBSR register will be the value at the
10799396ac1SDave Kleikamp 	 * last debug interrupt. This register can only be read from the
10899396ac1SDave Kleikamp 	 * user (will never be written to) and has value while helping to
10999396ac1SDave Kleikamp 	 * describe the reason for the last debug trap.  Torez
11099396ac1SDave Kleikamp 	 */
111d8899bb2SBharat Bhushan 	uint32_t	dbsr;
11299396ac1SDave Kleikamp 	/*
11399396ac1SDave Kleikamp 	 * The following will contain addresses used by debug applications
11499396ac1SDave Kleikamp 	 * to help trace and trap on particular address locations.
11599396ac1SDave Kleikamp 	 * The bits in the Debug Control Registers above help define which
11699396ac1SDave Kleikamp 	 * of the following registers will contain valid data and/or addresses.
11799396ac1SDave Kleikamp 	 */
11899396ac1SDave Kleikamp 	unsigned long	iac1;
11999396ac1SDave Kleikamp 	unsigned long	iac2;
12099396ac1SDave Kleikamp #if CONFIG_PPC_ADV_DEBUG_IACS > 2
12199396ac1SDave Kleikamp 	unsigned long	iac3;
12299396ac1SDave Kleikamp 	unsigned long	iac4;
12399396ac1SDave Kleikamp #endif
12499396ac1SDave Kleikamp 	unsigned long	dac1;
12599396ac1SDave Kleikamp 	unsigned long	dac2;
12699396ac1SDave Kleikamp #if CONFIG_PPC_ADV_DEBUG_DVCS > 0
12799396ac1SDave Kleikamp 	unsigned long	dvc1;
12899396ac1SDave Kleikamp 	unsigned long	dvc2;
12999396ac1SDave Kleikamp #endif
130b8b572e1SStephen Rothwell #endif
13151ae8d4aSBharat Bhushan };
13251ae8d4aSBharat Bhushan 
13351ae8d4aSBharat Bhushan struct thread_struct {
13451ae8d4aSBharat Bhushan 	unsigned long	ksp;		/* Kernel stack pointer */
13595791988SBharat Bhushan 
13651ae8d4aSBharat Bhushan #ifdef CONFIG_PPC64
13751ae8d4aSBharat Bhushan 	unsigned long	ksp_vsid;
13851ae8d4aSBharat Bhushan #endif
13951ae8d4aSBharat Bhushan 	struct pt_regs	*regs;		/* Pointer to saved register state */
14051ae8d4aSBharat Bhushan #ifdef CONFIG_BOOKE
14151ae8d4aSBharat Bhushan 	/* BookE base exception scratch space; align on cacheline */
14251ae8d4aSBharat Bhushan 	unsigned long	normsave[8] ____cacheline_aligned;
14351ae8d4aSBharat Bhushan #endif
14451ae8d4aSBharat Bhushan #ifdef CONFIG_PPC32
14551ae8d4aSBharat Bhushan 	void		*pgdir;		/* root of page-table tree */
1460df977eaSChristophe Leroy #ifdef CONFIG_PPC_RTAS
1470df977eaSChristophe Leroy 	unsigned long	rtas_sp;	/* stack pointer for when in RTAS */
1480df977eaSChristophe Leroy #endif
149a68c31fcSChristophe Leroy #if defined(CONFIG_PPC_BOOK3S_32) && defined(CONFIG_PPC_KUAP)
150a68c31fcSChristophe Leroy 	unsigned long	kuap;		/* opened segments for user access */
151a68c31fcSChristophe Leroy #endif
15202847487SChristophe Leroy 	unsigned long	srr0;
15302847487SChristophe Leroy 	unsigned long	srr1;
15402847487SChristophe Leroy 	unsigned long	dar;
15502847487SChristophe Leroy 	unsigned long	dsisr;
156232ca1eeSChristophe Leroy #ifdef CONFIG_PPC_BOOK3S_32
157232ca1eeSChristophe Leroy 	unsigned long	r0, r3, r4, r5, r6, r8, r9, r11;
158232ca1eeSChristophe Leroy 	unsigned long	lr, ctr;
15970428da9SChristophe Leroy 	unsigned long	sr0;
160232ca1eeSChristophe Leroy #endif
1617aa8dd67SChristophe Leroy #endif /* CONFIG_PPC32 */
162*002b27a5SMichael Ellerman #if defined(CONFIG_BOOKE) && defined(CONFIG_PPC_KUAP)
16343afcf8fSChristophe Leroy 	unsigned long	pid;	/* value written in PID reg. at interrupt exit */
16443afcf8fSChristophe Leroy #endif
16595791988SBharat Bhushan 	/* Debug Registers */
16651ae8d4aSBharat Bhushan 	struct debug_reg debug;
167b6254cedSChristophe Leroy #ifdef CONFIG_PPC_FPU_REGS
168de79f7b9SPaul Mackerras 	struct thread_fp_state	fp_state;
16918461960SPaul Mackerras 	struct thread_fp_state	*fp_save_area;
170b6254cedSChristophe Leroy #endif
171b8b572e1SStephen Rothwell 	int		fpexc_mode;	/* floating-point exception mode */
172b8b572e1SStephen Rothwell 	unsigned int	align_ctl;	/* alignment handling control */
1735aae8a53SK.Prasad #ifdef CONFIG_HAVE_HW_BREAKPOINT
174a6ba44e8SRavi Bangoria 	struct perf_event *ptrace_bps[HBP_NUM_MAX];
1755aae8a53SK.Prasad #endif /* CONFIG_HAVE_HW_BREAKPOINT */
176303e6a9dSRavi Bangoria 	struct arch_hw_breakpoint hw_brk[HBP_NUM_MAX]; /* hardware breakpoint info */
17741ab5266SAnanth N Mavinakayanahalli 	unsigned long	trap_nr;	/* last trap # on this thread */
1785434ae74SNicholas Piggin 	u8 load_slb;			/* Ages out SLB preload cache entries */
17970fe3d98SCyril Bur 	u8 load_fp;
180b8b572e1SStephen Rothwell #ifdef CONFIG_ALTIVEC
18170fe3d98SCyril Bur 	u8 load_vec;
182de79f7b9SPaul Mackerras 	struct thread_vr_state vr_state;
18318461960SPaul Mackerras 	struct thread_vr_state *vr_save_area;
184b8b572e1SStephen Rothwell 	unsigned long	vrsave;
185b8b572e1SStephen Rothwell 	int		used_vr;	/* set if process has used altivec */
186b8b572e1SStephen Rothwell #endif /* CONFIG_ALTIVEC */
187b8b572e1SStephen Rothwell #ifdef CONFIG_VSX
188b8b572e1SStephen Rothwell 	/* VSR status */
18971528d8bSSimon Guo 	int		used_vsr;	/* set if process has used VSX */
190b8b572e1SStephen Rothwell #endif /* CONFIG_VSX */
191b8b572e1SStephen Rothwell #ifdef CONFIG_SPE
19262ea67e3SKees Cook 	struct_group(spe,
193b8b572e1SStephen Rothwell 		unsigned long	evr[32];	/* upper 32-bits of SPE regs */
194b8b572e1SStephen Rothwell 		u64		acc;		/* Accumulator */
19562ea67e3SKees Cook 	);
196b8b572e1SStephen Rothwell 	unsigned long	spefscr;	/* SPE & eFP status */
197640e9225SJoseph Myers 	unsigned long	spefscr_last;	/* SPEFSCR value on last prctl
198640e9225SJoseph Myers 					   call or trap return */
199b8b572e1SStephen Rothwell 	int		used_spe;	/* set if process has used spe */
200b8b572e1SStephen Rothwell #endif /* CONFIG_SPE */
201f4c3aff2SMichael Neuling #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
2025d176f75SCyril Bur 	u8	load_tm;
203f4c3aff2SMichael Neuling 	u64		tm_tfhar;	/* Transaction fail handler addr */
204f4c3aff2SMichael Neuling 	u64		tm_texasr;	/* Transaction exception & summary */
205f4c3aff2SMichael Neuling 	u64		tm_tfiar;	/* Transaction fail instr address reg */
206f4c3aff2SMichael Neuling 	struct pt_regs	ckpt_regs;	/* Checkpointed registers */
207f4c3aff2SMichael Neuling 
20828e61cc4SMichael Neuling 	unsigned long	tm_tar;
20928e61cc4SMichael Neuling 	unsigned long	tm_ppr;
21028e61cc4SMichael Neuling 	unsigned long	tm_dscr;
211d0ffdee8SGustavo Romero 	unsigned long   tm_amr;
21228e61cc4SMichael Neuling 
213f4c3aff2SMichael Neuling 	/*
214dc310669SCyril Bur 	 * Checkpointed FP and VSX 0-31 register set.
215f4c3aff2SMichael Neuling 	 *
216f4c3aff2SMichael Neuling 	 * When a transaction is active/signalled/scheduled etc., *regs is the
217f4c3aff2SMichael Neuling 	 * most recent set of/speculated GPRs with ckpt_regs being the older
218f4c3aff2SMichael Neuling 	 * checkpointed regs to which we roll back if transaction aborts.
219f4c3aff2SMichael Neuling 	 *
220dc310669SCyril Bur 	 * These are analogous to how ckpt_regs and pt_regs work
221f4c3aff2SMichael Neuling 	 */
222000ec280SCyril Bur 	struct thread_fp_state ckfp_state; /* Checkpointed FP state */
223000ec280SCyril Bur 	struct thread_vr_state ckvr_state; /* Checkpointed VR state */
224000ec280SCyril Bur 	unsigned long	ckvrsave; /* Checkpointed VRSAVE */
225f4c3aff2SMichael Neuling #endif /* CONFIG_PPC_TRANSACTIONAL_MEM */
22697e49255SAlexander Graf #ifdef CONFIG_KVM_BOOK3S_32_HANDLER
22797e49255SAlexander Graf 	void*		kvm_shadow_vcpu; /* KVM internal data */
22897e49255SAlexander Graf #endif /* CONFIG_KVM_BOOK3S_32_HANDLER */
229d30f6e48SScott Wood #if defined(CONFIG_KVM) && defined(CONFIG_BOOKE)
230d30f6e48SScott Wood 	struct kvm_vcpu	*kvm_vcpu;
231d30f6e48SScott Wood #endif
232efcac658SAlexey Kardashevskiy #ifdef CONFIG_PPC64
233efcac658SAlexey Kardashevskiy 	unsigned long	dscr;
234152d523eSAnton Blanchard 	unsigned long	fscr;
235d3cb06e0SAnshuman Khandual 	/*
236d3cb06e0SAnshuman Khandual 	 * This member element dscr_inherit indicates that the process
237d3cb06e0SAnshuman Khandual 	 * has explicitly attempted and changed the DSCR register value
238d3cb06e0SAnshuman Khandual 	 * for itself. Hence kernel wont use the default CPU DSCR value
239d3cb06e0SAnshuman Khandual 	 * contained in the PACA structure anymore during process context
240d3cb06e0SAnshuman Khandual 	 * switch. Once this variable is set, this behaviour will also be
241d3cb06e0SAnshuman Khandual 	 * inherited to all the children of this process from that point
242d3cb06e0SAnshuman Khandual 	 * onwards.
243d3cb06e0SAnshuman Khandual 	 */
244efcac658SAlexey Kardashevskiy 	int		dscr_inherit;
245ec233edeSSukadev Bhattiprolu 	unsigned long	tidr;
246efcac658SAlexey Kardashevskiy #endif
2472468dcf6SIan Munsie #ifdef CONFIG_PPC_BOOK3S_64
2482468dcf6SIan Munsie 	unsigned long	tar;
2499353374bSMichael Ellerman 	unsigned long	ebbrr;
2509353374bSMichael Ellerman 	unsigned long	ebbhr;
2519353374bSMichael Ellerman 	unsigned long	bescr;
25259affcd3SMichael Ellerman 	unsigned long	siar;
25359affcd3SMichael Ellerman 	unsigned long	sdar;
25459affcd3SMichael Ellerman 	unsigned long	sier;
25559affcd3SMichael Ellerman 	unsigned long	mmcr2;
256330a1eb7SMichael Ellerman 	unsigned 	mmcr0;
2579d2a4d71SSukadev Bhattiprolu 
258330a1eb7SMichael Ellerman 	unsigned 	used_ebb;
259c718547eSMadhavan Srinivasan 	unsigned long   mmcr3;
260c718547eSMadhavan Srinivasan 	unsigned long   sier2;
261c718547eSMadhavan Srinivasan 	unsigned long   sier3;
262be98fcf7SBenjamin Gray 	unsigned long	hashkeyr;
26375171f06SBenjamin Gray 	unsigned long	dexcr;
264bbd99922SBenjamin Gray 	unsigned long	dexcr_onexec;	/* Reset value to load on exec */
2652468dcf6SIan Munsie #endif
266b8b572e1SStephen Rothwell };
267b8b572e1SStephen Rothwell 
268b8b572e1SStephen Rothwell #define ARCH_MIN_TASKALIGN 16
269b8b572e1SStephen Rothwell 
270b8b572e1SStephen Rothwell #define INIT_SP		(sizeof(init_stack) + (unsigned long) &init_stack)
271a7916a1dSChristophe Leroy #define INIT_SP_LIMIT	((unsigned long)&init_stack)
272b8b572e1SStephen Rothwell 
2736a800f36SLiu Yu #ifdef CONFIG_SPE
274640e9225SJoseph Myers #define SPEFSCR_INIT \
275640e9225SJoseph Myers 	.spefscr = SPEFSCR_FINVE | SPEFSCR_FDBZE | SPEFSCR_FUNFE | SPEFSCR_FOVFE, \
276640e9225SJoseph Myers 	.spefscr_last = SPEFSCR_FINVE | SPEFSCR_FDBZE | SPEFSCR_FUNFE | SPEFSCR_FOVFE,
2776a800f36SLiu Yu #else
2786a800f36SLiu Yu #define SPEFSCR_INIT
2796a800f36SLiu Yu #endif
280b8b572e1SStephen Rothwell 
28170428da9SChristophe Leroy #ifdef CONFIG_PPC_BOOK3S_32
28270428da9SChristophe Leroy #define SR0_INIT	.sr0 = IS_ENABLED(CONFIG_PPC_KUEP) ? SR_NX : 0,
28370428da9SChristophe Leroy #else
28470428da9SChristophe Leroy #define SR0_INIT
28570428da9SChristophe Leroy #endif
28670428da9SChristophe Leroy 
28716132529SChristophe Leroy #if defined(CONFIG_PPC_BOOK3S_32) && defined(CONFIG_PPC_KUAP)
28816132529SChristophe Leroy #define INIT_THREAD { \
28916132529SChristophe Leroy 	.ksp = INIT_SP, \
29016132529SChristophe Leroy 	.pgdir = swapper_pg_dir, \
29116132529SChristophe Leroy 	.kuap = ~0UL, /* KUAP_NONE */ \
29216132529SChristophe Leroy 	.fpexc_mode = MSR_FE0 | MSR_FE1, \
29316132529SChristophe Leroy 	SPEFSCR_INIT \
29470428da9SChristophe Leroy 	SR0_INIT \
29516132529SChristophe Leroy }
29616132529SChristophe Leroy #elif defined(CONFIG_PPC32)
297b8b572e1SStephen Rothwell #define INIT_THREAD { \
298b8b572e1SStephen Rothwell 	.ksp = INIT_SP, \
299b8b572e1SStephen Rothwell 	.pgdir = swapper_pg_dir, \
300b8b572e1SStephen Rothwell 	.fpexc_mode = MSR_FE0 | MSR_FE1, \
3016a800f36SLiu Yu 	SPEFSCR_INIT \
30270428da9SChristophe Leroy 	SR0_INIT \
303b8b572e1SStephen Rothwell }
304b8b572e1SStephen Rothwell #else
305b8b572e1SStephen Rothwell #define INIT_THREAD  { \
306b8b572e1SStephen Rothwell 	.ksp = INIT_SP, \
307b8b572e1SStephen Rothwell 	.fpexc_mode = 0, \
308b8b572e1SStephen Rothwell }
309b8b572e1SStephen Rothwell #endif
310b8b572e1SStephen Rothwell 
31124ac99e9SMichael Ellerman #define task_pt_regs(tsk)	((tsk)->thread.regs)
312b8b572e1SStephen Rothwell 
31342a20f86SKees Cook unsigned long __get_wchan(struct task_struct *p);
314b8b572e1SStephen Rothwell 
315b8b572e1SStephen Rothwell #define KSTK_EIP(tsk)  ((tsk)->thread.regs? (tsk)->thread.regs->nip: 0)
316b8b572e1SStephen Rothwell #define KSTK_ESP(tsk)  ((tsk)->thread.regs? (tsk)->thread.regs->gpr[1]: 0)
317b8b572e1SStephen Rothwell 
318b8b572e1SStephen Rothwell /* Get/set floating-point exception mode */
319b8b572e1SStephen Rothwell #define GET_FPEXC_CTL(tsk, adr) get_fpexc_mode((tsk), (adr))
320b8b572e1SStephen Rothwell #define SET_FPEXC_CTL(tsk, val) set_fpexc_mode((tsk), (val))
321b8b572e1SStephen Rothwell 
322b8b572e1SStephen Rothwell extern int get_fpexc_mode(struct task_struct *tsk, unsigned long adr);
323b8b572e1SStephen Rothwell extern int set_fpexc_mode(struct task_struct *tsk, unsigned int val);
324b8b572e1SStephen Rothwell 
325b8b572e1SStephen Rothwell #define GET_ENDIAN(tsk, adr) get_endian((tsk), (adr))
326b8b572e1SStephen Rothwell #define SET_ENDIAN(tsk, val) set_endian((tsk), (val))
327b8b572e1SStephen Rothwell 
328b8b572e1SStephen Rothwell extern int get_endian(struct task_struct *tsk, unsigned long adr);
329b8b572e1SStephen Rothwell extern int set_endian(struct task_struct *tsk, unsigned int val);
330b8b572e1SStephen Rothwell 
331b8b572e1SStephen Rothwell #define GET_UNALIGN_CTL(tsk, adr)	get_unalign_ctl((tsk), (adr))
332b8b572e1SStephen Rothwell #define SET_UNALIGN_CTL(tsk, val)	set_unalign_ctl((tsk), (val))
333b8b572e1SStephen Rothwell 
334b8b572e1SStephen Rothwell extern int get_unalign_ctl(struct task_struct *tsk, unsigned long adr);
335b8b572e1SStephen Rothwell extern int set_unalign_ctl(struct task_struct *tsk, unsigned int val);
336b8b572e1SStephen Rothwell 
337628d701fSBenjamin Gray #ifdef CONFIG_PPC_BOOK3S_64
338628d701fSBenjamin Gray 
339628d701fSBenjamin Gray #define PPC_GET_DEXCR_ASPECT(tsk, asp) get_dexcr_prctl((tsk), (asp))
340628d701fSBenjamin Gray #define PPC_SET_DEXCR_ASPECT(tsk, asp, val) set_dexcr_prctl((tsk), (asp), (val))
341628d701fSBenjamin Gray 
342628d701fSBenjamin Gray int get_dexcr_prctl(struct task_struct *tsk, unsigned long asp);
343628d701fSBenjamin Gray int set_dexcr_prctl(struct task_struct *tsk, unsigned long asp, unsigned long val);
344628d701fSBenjamin Gray 
345628d701fSBenjamin Gray #endif
346628d701fSBenjamin Gray 
34718461960SPaul Mackerras extern void load_fp_state(struct thread_fp_state *fp);
34818461960SPaul Mackerras extern void store_fp_state(struct thread_fp_state *fp);
34918461960SPaul Mackerras extern void load_vr_state(struct thread_vr_state *vr);
35018461960SPaul Mackerras extern void store_vr_state(struct thread_vr_state *vr);
35118461960SPaul Mackerras 
__unpack_fe01(unsigned long msr_bits)352b8b572e1SStephen Rothwell static inline unsigned int __unpack_fe01(unsigned long msr_bits)
353b8b572e1SStephen Rothwell {
354b8b572e1SStephen Rothwell 	return ((msr_bits & MSR_FE0) >> 10) | ((msr_bits & MSR_FE1) >> 8);
355b8b572e1SStephen Rothwell }
356b8b572e1SStephen Rothwell 
__pack_fe01(unsigned int fpmode)357b8b572e1SStephen Rothwell static inline unsigned long __pack_fe01(unsigned int fpmode)
358b8b572e1SStephen Rothwell {
359b8b572e1SStephen Rothwell 	return ((fpmode << 10) & MSR_FE0) | ((fpmode << 8) & MSR_FE1);
360b8b572e1SStephen Rothwell }
361b8b572e1SStephen Rothwell 
362b8b572e1SStephen Rothwell #ifdef CONFIG_PPC64
363ede8e2bbSNicholas Piggin 
3649c7bfc2dSNicholas Piggin #define spin_begin()							\
3659c7bfc2dSNicholas Piggin 	asm volatile(ASM_FTR_IFCLR(					\
3669c7bfc2dSNicholas Piggin 		"or 1,1,1", /* HMT_LOW */				\
3679c7bfc2dSNicholas Piggin 		"nop", /* v3.1 uses pause_short in cpu_relax instead */	\
3689c7bfc2dSNicholas Piggin 		%0) :: "i" (CPU_FTR_ARCH_31) : "memory")
369ede8e2bbSNicholas Piggin 
3709c7bfc2dSNicholas Piggin #define spin_cpu_relax()						\
3719c7bfc2dSNicholas Piggin 	asm volatile(ASM_FTR_IFCLR(					\
3729c7bfc2dSNicholas Piggin 		"nop", /* Before v3.1 use priority nops in spin_begin/end */ \
3739c7bfc2dSNicholas Piggin 		PPC_WAIT(2, 0),	/* aka pause_short */			\
3749c7bfc2dSNicholas Piggin 		%0) :: "i" (CPU_FTR_ARCH_31) : "memory")
375ede8e2bbSNicholas Piggin 
3769c7bfc2dSNicholas Piggin #define spin_end()							\
3779c7bfc2dSNicholas Piggin 	asm volatile(ASM_FTR_IFCLR(					\
3789c7bfc2dSNicholas Piggin 		"or 2,2,2", /* HMT_MEDIUM */				\
3799c7bfc2dSNicholas Piggin 		"nop",							\
3809c7bfc2dSNicholas Piggin 		%0) :: "i" (CPU_FTR_ARCH_31) : "memory")
381ede8e2bbSNicholas Piggin 
382b8b572e1SStephen Rothwell #endif
383b8b572e1SStephen Rothwell 
3844cefb0f6SNicholas Piggin /*
3854cefb0f6SNicholas Piggin  * Check that a certain kernel stack pointer is a valid (minimum sized)
3864cefb0f6SNicholas Piggin  * stack frame in task_struct p.
3874cefb0f6SNicholas Piggin  */
3884cefb0f6SNicholas Piggin int validate_sp(unsigned long sp, struct task_struct *p);
3894cefb0f6SNicholas Piggin 
3904cefb0f6SNicholas Piggin /*
3914cefb0f6SNicholas Piggin  * validate the stack frame of a particular minimum size, used for when we are
3924cefb0f6SNicholas Piggin  * looking at a certain object in the stack beyond the minimum.
3934cefb0f6SNicholas Piggin  */
3944cefb0f6SNicholas Piggin int validate_sp_size(unsigned long sp, struct task_struct *p,
395b8b572e1SStephen Rothwell 		     unsigned long nbytes);
396b8b572e1SStephen Rothwell 
397b8b572e1SStephen Rothwell /*
398b8b572e1SStephen Rothwell  * Prefetch macros.
399b8b572e1SStephen Rothwell  */
400b8b572e1SStephen Rothwell #define ARCH_HAS_PREFETCH
401b8b572e1SStephen Rothwell #define ARCH_HAS_PREFETCHW
402b8b572e1SStephen Rothwell 
prefetch(const void * x)403b8b572e1SStephen Rothwell static inline void prefetch(const void *x)
404b8b572e1SStephen Rothwell {
405b8b572e1SStephen Rothwell 	if (unlikely(!x))
406b8b572e1SStephen Rothwell 		return;
407b8b572e1SStephen Rothwell 
408b8b572e1SStephen Rothwell 	__asm__ __volatile__ ("dcbt 0,%0" : : "r" (x));
409b8b572e1SStephen Rothwell }
410b8b572e1SStephen Rothwell 
prefetchw(const void * x)411b8b572e1SStephen Rothwell static inline void prefetchw(const void *x)
412b8b572e1SStephen Rothwell {
413b8b572e1SStephen Rothwell 	if (unlikely(!x))
414b8b572e1SStephen Rothwell 		return;
415b8b572e1SStephen Rothwell 
416b8b572e1SStephen Rothwell 	__asm__ __volatile__ ("dcbtst 0,%0" : : "r" (x));
417b8b572e1SStephen Rothwell }
418b8b572e1SStephen Rothwell 
41910d91611SNicholas Piggin /* asm stubs */
42010d91611SNicholas Piggin extern unsigned long isa300_idle_stop_noloss(unsigned long psscr_val);
42110d91611SNicholas Piggin extern unsigned long isa300_idle_stop_mayloss(unsigned long psscr_val);
42210d91611SNicholas Piggin extern unsigned long isa206_idle_insn_mayloss(unsigned long type);
423ed0bc98fSNicholas Piggin #ifdef CONFIG_PPC_970_NAP
424ed0bc98fSNicholas Piggin extern void power4_idle_nap(void);
42598db179aSNicholas Piggin void power4_idle_nap_return(void);
426ed0bc98fSNicholas Piggin #endif
42710d91611SNicholas Piggin 
428e8bb3e00SDeepthi Dharwar extern unsigned long cpuidle_disable;
429771dae81SDeepthi Dharwar enum idle_boot_override {IDLE_NO_OVERRIDE = 0, IDLE_POWERSAVE_OFF};
430771dae81SDeepthi Dharwar 
431ae3a197eSDavid Howells extern int powersave_nap;	/* set if nap mode can be used in idle loop */
43210d91611SNicholas Piggin 
4332201f994SNicholas Piggin extern void power7_idle_type(unsigned long type);
434ffd2961bSNicholas Piggin extern void arch300_idle_type(unsigned long stop_psscr_val,
43509206b60SGautham R. Shenoy 			      unsigned long stop_psscr_mask);
43676222808SChristophe Leroy void pnv_power9_force_smt4_catch(void);
43776222808SChristophe Leroy void pnv_power9_force_smt4_release(void);
438bcef83a0SShreyas B. Prabhu 
439ae3a197eSDavid Howells extern int fix_alignment(struct pt_regs *);
440ae3a197eSDavid Howells 
441ae3a197eSDavid Howells #ifdef CONFIG_PPC64
442ae3a197eSDavid Howells /*
443ae3a197eSDavid Howells  * We handle most unaligned accesses in hardware. On the other hand
444ae3a197eSDavid Howells  * unaligned DMA can be very expensive on some ppc64 IO chips (it does
445ae3a197eSDavid Howells  * powers of 2 writes until it reaches sufficient alignment).
446ae3a197eSDavid Howells  *
447ae3a197eSDavid Howells  * Based on this we disable the IP header alignment in network drivers.
448ae3a197eSDavid Howells  */
449ae3a197eSDavid Howells #define NET_IP_ALIGN	0
450ae3a197eSDavid Howells #endif
451ae3a197eSDavid Howells 
452e448e1e7SChristophe Leroy int do_mathemu(struct pt_regs *regs);
45378c73c80SChristophe Leroy int do_spe_mathemu(struct pt_regs *regs);
45478c73c80SChristophe Leroy int speround_handler(struct pt_regs *regs);
455e448e1e7SChristophe Leroy 
45676222808SChristophe Leroy /* VMX copying */
45776222808SChristophe Leroy int enter_vmx_usercopy(void);
45876222808SChristophe Leroy int exit_vmx_usercopy(void);
45976222808SChristophe Leroy int enter_vmx_ops(void);
46076222808SChristophe Leroy void *exit_vmx_ops(void *dest);
46176222808SChristophe Leroy 
462b8b572e1SStephen Rothwell #endif /* __KERNEL__ */
463b8b572e1SStephen Rothwell #endif /* __ASSEMBLY__ */
464b8b572e1SStephen Rothwell #endif /* _ASM_POWERPC_PROCESSOR_H */
465