processor.h 12.9 KB
Newer Older
1
/* SPDX-License-Identifier: GPL-2.0-or-later */
P
Paul Mackerras 已提交
2 3
#ifndef _ASM_POWERPC_PROCESSOR_H
#define _ASM_POWERPC_PROCESSOR_H
L
Linus Torvalds 已提交
4 5

/*
P
Paul Mackerras 已提交
6
 * Copyright (C) 2001 PPC 64 Team, IBM Corp
L
Linus Torvalds 已提交
7 8
 */

P
Paul Mackerras 已提交
9
#include <asm/reg.h>
L
Linus Torvalds 已提交
10

11 12
#ifdef CONFIG_VSX
#define TS_FPRWIDTH 2
13 14 15 16 17 18 19 20 21

#ifdef __BIG_ENDIAN__
#define TS_FPROFFSET 0
#define TS_VSRLOWOFFSET 1
#else
#define TS_FPROFFSET 1
#define TS_VSRLOWOFFSET 0
#endif

22
#else
23
#define TS_FPRWIDTH 1
24
#define TS_FPROFFSET 0
25
#endif
26

27 28 29 30
#ifdef CONFIG_PPC64
/* Default SMT priority is set to 3. Use 11- 13bits to save priority. */
#define PPR_PRIORITY 3
#ifdef __ASSEMBLY__
31
#define DEFAULT_PPR (PPR_PRIORITY << 50)
32
#else
33
#define DEFAULT_PPR ((u64)PPR_PRIORITY << 50)
34 35 36
#endif /* __ASSEMBLY__ */
#endif /* CONFIG_PPC64 */

P
Paul Mackerras 已提交
37
#ifndef __ASSEMBLY__
38
#include <linux/types.h>
39
#include <linux/thread_info.h>
L
Linus Torvalds 已提交
40
#include <asm/ptrace.h>
41
#include <asm/hw_breakpoint.h>
L
Linus Torvalds 已提交
42

43 44 45
/* We do _not_ want to define new machine types at all, those must die
 * in favor of using the device-tree
 * -- BenH.
L
Linus Torvalds 已提交
46 47
 */

P
Paul Bolle 已提交
48
/* PREP sub-platform types. Unused */
L
Linus Torvalds 已提交
49 50 51 52 53
#define _PREP_Motorola	0x01	/* motorola prep */
#define _PREP_Firm	0x02	/* firmworks prep */
#define _PREP_IBM	0x00	/* ibm prep */
#define _PREP_Bull	0x03	/* bull prep */

54
/* CHRP sub-platform types. These are arbitrary */
L
Linus Torvalds 已提交
55 56 57
#define _CHRP_Motorola	0x04	/* motorola chrp, the cobra */
#define _CHRP_IBM	0x05	/* IBM chrp, the longtrail and longtrail 2 */
#define _CHRP_Pegasos	0x06	/* Genesi/bplan's Pegasos and Pegasos2 */
58
#define _CHRP_briq	0x07	/* TotalImpact's briQ */
L
Linus Torvalds 已提交
59

60 61 62
#if defined(__KERNEL__) && defined(CONFIG_PPC32)

extern int _chrp_type;
63

64 65
#endif /* defined(__KERNEL__) && defined(CONFIG_PPC32) */

P
Paul Mackerras 已提交
66 67 68 69 70 71 72 73 74 75 76
/* Macros for adjusting thread priority (hardware multi-threading) */
#define HMT_very_low()   asm volatile("or 31,31,31   # very low priority")
#define HMT_low()	 asm volatile("or 1,1,1	     # low priority")
#define HMT_medium_low() asm volatile("or 6,6,6      # medium low priority")
#define HMT_medium()	 asm volatile("or 2,2,2	     # medium priority")
#define HMT_medium_high() asm volatile("or 5,5,5      # medium high priority")
#define HMT_high()	 asm volatile("or 3,3,3	     # high priority")

#ifdef __KERNEL__

#ifdef CONFIG_PPC64
77
#include <asm/task_size_64.h>
78
#else
79
#include <asm/task_size_32.h>
80 81
#endif

82 83 84
struct task_struct;
void start_thread(struct pt_regs *regs, unsigned long fdptr, unsigned long sp);
void release_thread(struct task_struct *);
85

L
Linus Torvalds 已提交
86 87 88 89
typedef struct {
	unsigned long seg;
} mm_segment_t;

90
#define TS_FPR(i) fp_state.fpr[i][TS_FPROFFSET]
91
#define TS_CKFPR(i) ckfp_state.fpr[i][TS_FPROFFSET]
92 93 94 95 96 97 98 99 100 101 102 103

/* FP and VSX 0-31 register set */
struct thread_fp_state {
	u64	fpr[32][TS_FPRWIDTH] __attribute__((aligned(16)));
	u64	fpscr;		/* Floating point status */
};

/* Complete AltiVec register set including VSCR */
struct thread_vr_state {
	vector128	vr[32] __attribute__((aligned(16)));
	vector128	vscr __attribute__((aligned(16)));
};
104

105
struct debug_reg {
106 107 108 109 110
#ifdef CONFIG_PPC_ADV_DEBUG_REGS
	/*
	 * The following help to manage the use of Debug Control Registers
	 * om the BookE platforms.
	 */
111 112
	uint32_t	dbcr0;
	uint32_t	dbcr1;
113
#ifdef CONFIG_BOOKE
114
	uint32_t	dbcr2;
115 116 117 118 119 120 121
#endif
	/*
	 * The stored value of the DBSR register will be the value at the
	 * last debug interrupt. This register can only be read from the
	 * user (will never be written to) and has value while helping to
	 * describe the reason for the last debug trap.  Torez
	 */
122
	uint32_t	dbsr;
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
	/*
	 * The following will contain addresses used by debug applications
	 * to help trace and trap on particular address locations.
	 * The bits in the Debug Control Registers above help define which
	 * of the following registers will contain valid data and/or addresses.
	 */
	unsigned long	iac1;
	unsigned long	iac2;
#if CONFIG_PPC_ADV_DEBUG_IACS > 2
	unsigned long	iac3;
	unsigned long	iac4;
#endif
	unsigned long	dac1;
	unsigned long	dac2;
#if CONFIG_PPC_ADV_DEBUG_DVCS > 0
	unsigned long	dvc1;
	unsigned long	dvc2;
#endif
L
Linus Torvalds 已提交
141
#endif
142 143 144 145
};

struct thread_struct {
	unsigned long	ksp;		/* Kernel stack pointer */
146

147 148 149 150
#ifdef CONFIG_PPC64
	unsigned long	ksp_vsid;
#endif
	struct pt_regs	*regs;		/* Pointer to saved register state */
151
	mm_segment_t	addr_limit;	/* for get_fs() validation */
152 153 154 155 156 157 158
#ifdef CONFIG_BOOKE
	/* BookE base exception scratch space; align on cacheline */
	unsigned long	normsave[8] ____cacheline_aligned;
#endif
#ifdef CONFIG_PPC32
	void		*pgdir;		/* root of page-table tree */
	unsigned long	ksp_limit;	/* if ksp <= ksp_limit stack overflow */
159 160 161
#ifdef CONFIG_PPC_RTAS
	unsigned long	rtas_sp;	/* stack pointer for when in RTAS */
#endif
162 163 164
#endif
#if defined(CONFIG_PPC_BOOK3S_32) && defined(CONFIG_PPC_KUAP)
	unsigned long	kuap;		/* opened segments for user access */
165 166 167 168 169 170
#endif
#ifdef CONFIG_VMAP_STACK
	unsigned long	srr0;
	unsigned long	srr1;
	unsigned long	dar;
	unsigned long	dsisr;
171
#endif
172
	/* Debug Registers */
173
	struct debug_reg debug;
174
	struct thread_fp_state	fp_state;
175
	struct thread_fp_state	*fp_save_area;
P
Paul Mackerras 已提交
176
	int		fpexc_mode;	/* floating-point exception mode */
177
	unsigned int	align_ctl;	/* alignment handling control */
178 179 180 181 182 183 184 185
#ifdef CONFIG_HAVE_HW_BREAKPOINT
	struct perf_event *ptrace_bps[HBP_NUM];
	/*
	 * Helps identify source of single-step exception and subsequent
	 * hw-breakpoint enablement
	 */
	struct perf_event *last_hit_ubp;
#endif /* CONFIG_HAVE_HW_BREAKPOINT */
186
	struct arch_hw_breakpoint hw_brk; /* info on the hardware breakpoint */
187
	unsigned long	trap_nr;	/* last trap # on this thread */
188
	u8 load_slb;			/* Ages out SLB preload cache entries */
189
	u8 load_fp;
L
Linus Torvalds 已提交
190
#ifdef CONFIG_ALTIVEC
191
	u8 load_vec;
192
	struct thread_vr_state vr_state;
193
	struct thread_vr_state *vr_save_area;
L
Linus Torvalds 已提交
194 195 196
	unsigned long	vrsave;
	int		used_vr;	/* set if process has used altivec */
#endif /* CONFIG_ALTIVEC */
197 198
#ifdef CONFIG_VSX
	/* VSR status */
S
Simon Guo 已提交
199
	int		used_vsr;	/* set if process has used VSX */
200
#endif /* CONFIG_VSX */
L
Linus Torvalds 已提交
201 202 203 204
#ifdef CONFIG_SPE
	unsigned long	evr[32];	/* upper 32-bits of SPE regs */
	u64		acc;		/* Accumulator */
	unsigned long	spefscr;	/* SPE & eFP status */
205 206
	unsigned long	spefscr_last;	/* SPEFSCR value on last prctl
					   call or trap return */
L
Linus Torvalds 已提交
207 208
	int		used_spe;	/* set if process has used spe */
#endif /* CONFIG_SPE */
209
#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
210
	u8	load_tm;
211 212 213 214 215
	u64		tm_tfhar;	/* Transaction fail handler addr */
	u64		tm_texasr;	/* Transaction exception & summary */
	u64		tm_tfiar;	/* Transaction fail instr address reg */
	struct pt_regs	ckpt_regs;	/* Checkpointed registers */

216 217 218 219
	unsigned long	tm_tar;
	unsigned long	tm_ppr;
	unsigned long	tm_dscr;

220
	/*
221
	 * Checkpointed FP and VSX 0-31 register set.
222 223 224 225 226
	 *
	 * When a transaction is active/signalled/scheduled etc., *regs is the
	 * most recent set of/speculated GPRs with ckpt_regs being the older
	 * checkpointed regs to which we roll back if transaction aborts.
	 *
227
	 * These are analogous to how ckpt_regs and pt_regs work
228
	 */
229 230 231
	struct thread_fp_state ckfp_state; /* Checkpointed FP state */
	struct thread_vr_state ckvr_state; /* Checkpointed VR state */
	unsigned long	ckvrsave; /* Checkpointed VRSAVE */
232
#endif /* CONFIG_PPC_TRANSACTIONAL_MEM */
233 234 235 236 237
#ifdef CONFIG_PPC_MEM_KEYS
	unsigned long	amr;
	unsigned long	iamr;
	unsigned long	uamor;
#endif
238 239 240
#ifdef CONFIG_KVM_BOOK3S_32_HANDLER
	void*		kvm_shadow_vcpu; /* KVM internal data */
#endif /* CONFIG_KVM_BOOK3S_32_HANDLER */
241 242 243
#if defined(CONFIG_KVM) && defined(CONFIG_BOOKE)
	struct kvm_vcpu	*kvm_vcpu;
#endif
244 245
#ifdef CONFIG_PPC64
	unsigned long	dscr;
246
	unsigned long	fscr;
247 248 249 250 251 252 253 254 255
	/*
	 * This member element dscr_inherit indicates that the process
	 * has explicitly attempted and changed the DSCR register value
	 * for itself. Hence kernel wont use the default CPU DSCR value
	 * contained in the PACA structure anymore during process context
	 * switch. Once this variable is set, this behaviour will also be
	 * inherited to all the children of this process from that point
	 * onwards.
	 */
256
	int		dscr_inherit;
257
	unsigned long	tidr;
258
#endif
259 260
#ifdef CONFIG_PPC_BOOK3S_64
	unsigned long	tar;
261 262 263
	unsigned long	ebbrr;
	unsigned long	ebbhr;
	unsigned long	bescr;
264 265 266 267
	unsigned long	siar;
	unsigned long	sdar;
	unsigned long	sier;
	unsigned long	mmcr2;
268
	unsigned 	mmcr0;
269

270
	unsigned 	used_ebb;
271
	unsigned int	used_vas;
272
#endif
L
Linus Torvalds 已提交
273 274 275 276 277
};

#define ARCH_MIN_TASKALIGN 16

#define INIT_SP		(sizeof(init_stack) + (unsigned long) &init_stack)
278
#define INIT_SP_LIMIT	((unsigned long)&init_stack)
L
Linus Torvalds 已提交
279

280
#ifdef CONFIG_SPE
281 282 283
#define SPEFSCR_INIT \
	.spefscr = SPEFSCR_FINVE | SPEFSCR_FDBZE | SPEFSCR_FUNFE | SPEFSCR_FOVFE, \
	.spefscr_last = SPEFSCR_FINVE | SPEFSCR_FDBZE | SPEFSCR_FUNFE | SPEFSCR_FOVFE,
284 285 286
#else
#define SPEFSCR_INIT
#endif
P
Paul Mackerras 已提交
287 288

#ifdef CONFIG_PPC32
L
Linus Torvalds 已提交
289 290
#define INIT_THREAD { \
	.ksp = INIT_SP, \
291
	.ksp_limit = INIT_SP_LIMIT, \
292
	.addr_limit = KERNEL_DS, \
L
Linus Torvalds 已提交
293 294
	.pgdir = swapper_pg_dir, \
	.fpexc_mode = MSR_FE0 | MSR_FE1, \
295
	SPEFSCR_INIT \
L
Linus Torvalds 已提交
296
}
P
Paul Mackerras 已提交
297 298 299 300
#else
#define INIT_THREAD  { \
	.ksp = INIT_SP, \
	.regs = (struct pt_regs *)INIT_SP - 1, /* XXX bogus, I think */ \
301
	.addr_limit = KERNEL_DS, \
302
	.fpexc_mode = 0, \
303
	.fscr = FSCR_TAR | FSCR_EBB \
P
Paul Mackerras 已提交
304 305
}
#endif
L
Linus Torvalds 已提交
306

307 308
#define task_pt_regs(tsk)	((struct pt_regs *)(tsk)->thread.regs)

L
Linus Torvalds 已提交
309 310
unsigned long get_wchan(struct task_struct *p);

P
Paul Mackerras 已提交
311 312
#define KSTK_EIP(tsk)  ((tsk)->thread.regs? (tsk)->thread.regs->nip: 0)
#define KSTK_ESP(tsk)  ((tsk)->thread.regs? (tsk)->thread.regs->gpr[1]: 0)
L
Linus Torvalds 已提交
313 314

/* Get/set floating-point exception mode */
P
Paul Mackerras 已提交
315 316
#define GET_FPEXC_CTL(tsk, adr) get_fpexc_mode((tsk), (adr))
#define SET_FPEXC_CTL(tsk, val) set_fpexc_mode((tsk), (val))
L
Linus Torvalds 已提交
317 318 319 320

extern int get_fpexc_mode(struct task_struct *tsk, unsigned long adr);
extern int set_fpexc_mode(struct task_struct *tsk, unsigned int val);

321 322 323 324 325 326
#define GET_ENDIAN(tsk, adr) get_endian((tsk), (adr))
#define SET_ENDIAN(tsk, val) set_endian((tsk), (val))

extern int get_endian(struct task_struct *tsk, unsigned long adr);
extern int set_endian(struct task_struct *tsk, unsigned int val);

327 328 329 330 331 332
#define GET_UNALIGN_CTL(tsk, adr)	get_unalign_ctl((tsk), (adr))
#define SET_UNALIGN_CTL(tsk, val)	set_unalign_ctl((tsk), (val))

extern int get_unalign_ctl(struct task_struct *tsk, unsigned long adr);
extern int set_unalign_ctl(struct task_struct *tsk, unsigned int val);

333 334 335 336 337
extern void load_fp_state(struct thread_fp_state *fp);
extern void store_fp_state(struct thread_fp_state *fp);
extern void load_vr_state(struct thread_vr_state *vr);
extern void store_vr_state(struct thread_vr_state *vr);

P
Paul Mackerras 已提交
338
static inline unsigned int __unpack_fe01(unsigned long msr_bits)
L
Linus Torvalds 已提交
339 340 341 342
{
	return ((msr_bits & MSR_FE0) >> 10) | ((msr_bits & MSR_FE1) >> 8);
}

P
Paul Mackerras 已提交
343
static inline unsigned long __pack_fe01(unsigned int fpmode)
L
Linus Torvalds 已提交
344 345 346 347
{
	return ((fpmode << 10) & MSR_FE0) | ((fpmode << 8) & MSR_FE1);
}

P
Paul Mackerras 已提交
348 349
#ifdef CONFIG_PPC64
#define cpu_relax()	do { HMT_low(); HMT_medium(); barrier(); } while (0)
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367

#define spin_begin()	HMT_low()

#define spin_cpu_relax()	barrier()

#define spin_end()	HMT_medium()

#define spin_until_cond(cond)					\
do {								\
	if (unlikely(!(cond))) {				\
		spin_begin();					\
		do {						\
			spin_cpu_relax();			\
		} while (!(cond));				\
		spin_end();					\
	}							\
} while (0)

P
Paul Mackerras 已提交
368
#else
L
Linus Torvalds 已提交
369
#define cpu_relax()	barrier()
P
Paul Mackerras 已提交
370
#endif
L
Linus Torvalds 已提交
371

372 373 374 375
/* Check that a certain kernel stack pointer is valid in task_struct p */
int validate_sp(unsigned long sp, struct task_struct *p,
                       unsigned long nbytes);

L
Linus Torvalds 已提交
376 377 378 379 380 381 382
/*
 * Prefetch macros.
 */
#define ARCH_HAS_PREFETCH
#define ARCH_HAS_PREFETCHW
#define ARCH_HAS_SPINLOCK_PREFETCH

P
Paul Mackerras 已提交
383
static inline void prefetch(const void *x)
L
Linus Torvalds 已提交
384
{
P
Paul Mackerras 已提交
385 386 387 388
	if (unlikely(!x))
		return;

	__asm__ __volatile__ ("dcbt 0,%0" : : "r" (x));
L
Linus Torvalds 已提交
389 390
}

P
Paul Mackerras 已提交
391
static inline void prefetchw(const void *x)
L
Linus Torvalds 已提交
392
{
P
Paul Mackerras 已提交
393 394 395 396
	if (unlikely(!x))
		return;

	__asm__ __volatile__ ("dcbtst 0,%0" : : "r" (x));
L
Linus Torvalds 已提交
397 398 399 400
}

#define spin_lock_prefetch(x)	prefetchw(x)

P
Paul Mackerras 已提交
401
#define HAVE_ARCH_PICK_MMAP_LAYOUT
L
Linus Torvalds 已提交
402

403
#ifdef CONFIG_PPC64
404
static inline unsigned long get_clean_sp(unsigned long sp, int is_32)
405 406
{
	if (is_32)
407
		return sp & 0x0ffffffffUL;
408 409 410
	return sp;
}
#else
411
static inline unsigned long get_clean_sp(unsigned long sp, int is_32)
412
{
413
	return sp;
414 415 416
}
#endif

417 418 419 420
/* asm stubs */
extern unsigned long isa300_idle_stop_noloss(unsigned long psscr_val);
extern unsigned long isa300_idle_stop_mayloss(unsigned long psscr_val);
extern unsigned long isa206_idle_insn_mayloss(unsigned long type);
421 422 423
#ifdef CONFIG_PPC_970_NAP
extern void power4_idle_nap(void);
#endif
424

425
extern unsigned long cpuidle_disable;
426 427
enum idle_boot_override {IDLE_NO_OVERRIDE = 0, IDLE_POWERSAVE_OFF};

428
extern int powersave_nap;	/* set if nap mode can be used in idle loop */
429

430 431 432
extern void power7_idle_type(unsigned long type);
extern void power9_idle_type(unsigned long stop_psscr_val,
			      unsigned long stop_psscr_mask);
433

434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452
extern void flush_instruction_cache(void);
extern void hard_reset_now(void);
extern void poweroff_now(void);
extern int fix_alignment(struct pt_regs *);
extern void cvt_fd(float *from, double *to);
extern void cvt_df(double *from, float *to);
extern void _nmask_and_or_msr(unsigned long nmask, unsigned long or_val);

#ifdef CONFIG_PPC64
/*
 * We handle most unaligned accesses in hardware. On the other hand 
 * unaligned DMA can be very expensive on some ppc64 IO chips (it does
 * powers of 2 writes until it reaches sufficient alignment).
 *
 * Based on this we disable the IP header alignment in network drivers.
 */
#define NET_IP_ALIGN	0
#endif

L
Linus Torvalds 已提交
453
#endif /* __KERNEL__ */
P
Paul Mackerras 已提交
454 455
#endif /* __ASSEMBLY__ */
#endif /* _ASM_POWERPC_PROCESSOR_H */