processor.h 14.6 KB
Newer Older
P
Paul Mackerras 已提交
1 2
#ifndef _ASM_POWERPC_PROCESSOR_H
#define _ASM_POWERPC_PROCESSOR_H
L
Linus Torvalds 已提交
3 4

/*
P
Paul Mackerras 已提交
5 6 7 8 9 10
 * Copyright (C) 2001 PPC 64 Team, IBM Corp
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version
 * 2 of the License, or (at your option) any later version.
L
Linus Torvalds 已提交
11 12
 */

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

15 16
#ifdef CONFIG_VSX
#define TS_FPRWIDTH 2
17 18 19 20 21 22 23 24 25

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

26
#else
27
#define TS_FPRWIDTH 1
28
#define TS_FPROFFSET 0
29
#endif
30

31 32 33 34 35 36 37 38 39 40
#ifdef CONFIG_PPC64
/* Default SMT priority is set to 3. Use 11- 13bits to save priority. */
#define PPR_PRIORITY 3
#ifdef __ASSEMBLY__
#define INIT_PPR (PPR_PRIORITY << 50)
#else
#define INIT_PPR ((u64)PPR_PRIORITY << 50)
#endif /* __ASSEMBLY__ */
#endif /* CONFIG_PPC64 */

P
Paul Mackerras 已提交
41 42
#ifndef __ASSEMBLY__
#include <linux/compiler.h>
43
#include <linux/cache.h>
L
Linus Torvalds 已提交
44 45
#include <asm/ptrace.h>
#include <asm/types.h>
46
#include <asm/hw_breakpoint.h>
L
Linus Torvalds 已提交
47

48 49 50
/* 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 已提交
51 52
 */

P
Paul Bolle 已提交
53
/* PREP sub-platform types. Unused */
L
Linus Torvalds 已提交
54 55 56 57 58
#define _PREP_Motorola	0x01	/* motorola prep */
#define _PREP_Firm	0x02	/* firmworks prep */
#define _PREP_IBM	0x00	/* ibm prep */
#define _PREP_Bull	0x03	/* bull prep */

59
/* CHRP sub-platform types. These are arbitrary */
L
Linus Torvalds 已提交
60 61 62
#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 */
63
#define _CHRP_briq	0x07	/* TotalImpact's briQ */
L
Linus Torvalds 已提交
64

65 66 67
#if defined(__KERNEL__) && defined(CONFIG_PPC32)

extern int _chrp_type;
68

69 70
#endif /* defined(__KERNEL__) && defined(CONFIG_PPC32) */

P
Paul Mackerras 已提交
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
/*
 * Default implementation of macro that returns current
 * instruction pointer ("program counter").
 */
#define current_text_addr() ({ __label__ _l; _l: &&_l;})

/* 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__

L
Linus Torvalds 已提交
87
struct task_struct;
P
Paul Mackerras 已提交
88
void start_thread(struct pt_regs *regs, unsigned long fdptr, unsigned long sp);
L
Linus Torvalds 已提交
89 90
void release_thread(struct task_struct *);

P
Paul Mackerras 已提交
91
#ifdef CONFIG_PPC32
92 93 94 95

#if CONFIG_TASK_SIZE > CONFIG_KERNEL_START
#error User TASK_SIZE overlaps with KERNEL_START address
#endif
P
Paul Mackerras 已提交
96 97
#define TASK_SIZE	(CONFIG_TASK_SIZE)

L
Linus Torvalds 已提交
98 99 100 101
/* This decides where the kernel will search for a free chunk of vm
 * space during mmap's.
 */
#define TASK_UNMAPPED_BASE	(TASK_SIZE / 8 * 3)
P
Paul Mackerras 已提交
102 103 104
#endif

#ifdef CONFIG_PPC64
105 106 107 108 109 110 111 112 113 114 115 116
/*
 * 64-bit user address space can have multiple limits
 * For now supported values are:
 */
#define TASK_SIZE_64TB  (0x0000400000000000UL)
#define TASK_SIZE_128TB (0x0000800000000000UL)
#define TASK_SIZE_512TB (0x0002000000000000UL)

#ifdef CONFIG_PPC_BOOK3S_64
/*
 * Max value currently used:
 */
117
#define TASK_SIZE_USER64	TASK_SIZE_512TB
118
#else
119
#define TASK_SIZE_USER64	TASK_SIZE_64TB
120
#endif
P
Paul Mackerras 已提交
121

122 123
/*
 * 32-bit user address space is 4GB - 1 page
P
Paul Mackerras 已提交
124 125 126 127
 * (this 1 page is needed so referencing of 0xFFFFFFFF generates EFAULT
 */
#define TASK_SIZE_USER32 (0x0000000100000000UL - (1*PAGE_SIZE))

D
Dave Hansen 已提交
128
#define TASK_SIZE_OF(tsk) (test_tsk_thread_flag(tsk, TIF_32BIT) ? \
P
Paul Mackerras 已提交
129
		TASK_SIZE_USER32 : TASK_SIZE_USER64)
D
Dave Hansen 已提交
130
#define TASK_SIZE	  TASK_SIZE_OF(current)
P
Paul Mackerras 已提交
131 132 133 134
/* This decides where the kernel will search for a free chunk of vm
 * space during mmap's.
 */
#define TASK_UNMAPPED_BASE_USER32 (PAGE_ALIGN(TASK_SIZE_USER32 / 4))
135
#define TASK_UNMAPPED_BASE_USER64 (PAGE_ALIGN(TASK_SIZE_128TB / 4))
P
Paul Mackerras 已提交
136

137
#define TASK_UNMAPPED_BASE ((is_32bit_task()) ? \
P
Paul Mackerras 已提交
138 139
		TASK_UNMAPPED_BASE_USER32 : TASK_UNMAPPED_BASE_USER64 )
#endif
L
Linus Torvalds 已提交
140

141 142 143 144 145 146 147 148 149 150 151
/*
 * Initial task size value for user applications. For book3s 64 we start
 * with 128TB and conditionally enable upto 512TB
 */
#ifdef CONFIG_PPC_BOOK3S_64
#define DEFAULT_MAP_WINDOW	((is_32bit_task()) ? \
				 TASK_SIZE_USER32 : TASK_SIZE_128TB)
#else
#define DEFAULT_MAP_WINDOW	TASK_SIZE
#endif

152 153
#ifdef __powerpc64__

154 155
/* Limit stack to 128TB */
#define STACK_TOP_USER64 TASK_SIZE_128TB
156 157
#define STACK_TOP_USER32 TASK_SIZE_USER32

158
#define STACK_TOP (is_32bit_task() ? \
159 160
		   STACK_TOP_USER32 : STACK_TOP_USER64)

161
#define STACK_TOP_MAX TASK_SIZE_USER64
162 163 164 165 166 167 168 169

#else /* __powerpc64__ */

#define STACK_TOP TASK_SIZE
#define STACK_TOP_MAX	STACK_TOP

#endif /* __powerpc64__ */

L
Linus Torvalds 已提交
170 171 172 173
typedef struct {
	unsigned long seg;
} mm_segment_t;

174
#define TS_FPR(i) fp_state.fpr[i][TS_FPROFFSET]
175
#define TS_CKFPR(i) ckfp_state.fpr[i][TS_FPROFFSET]
176 177 178 179 180 181 182 183 184 185 186 187

/* 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)));
};
188

189
struct debug_reg {
190 191 192 193 194
#ifdef CONFIG_PPC_ADV_DEBUG_REGS
	/*
	 * The following help to manage the use of Debug Control Registers
	 * om the BookE platforms.
	 */
195 196
	uint32_t	dbcr0;
	uint32_t	dbcr1;
197
#ifdef CONFIG_BOOKE
198
	uint32_t	dbcr2;
199 200 201 202 203 204 205
#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
	 */
206
	uint32_t	dbsr;
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224
	/*
	 * 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 已提交
225
#endif
226 227 228 229
};

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

231 232 233 234 235 236 237 238 239 240 241 242 243
#ifdef CONFIG_PPC64
	unsigned long	ksp_vsid;
#endif
	struct pt_regs	*regs;		/* Pointer to saved register state */
	mm_segment_t	fs;		/* for get_fs() validation */
#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 */
#endif
244
	/* Debug Registers */
245
	struct debug_reg debug;
246
	struct thread_fp_state	fp_state;
247
	struct thread_fp_state	*fp_save_area;
P
Paul Mackerras 已提交
248
	int		fpexc_mode;	/* floating-point exception mode */
249
	unsigned int	align_ctl;	/* alignment handling control */
P
Paul Mackerras 已提交
250 251
#ifdef CONFIG_PPC64
	unsigned long	start_tb;	/* Start purr when proc switched in */
M
Michael Ellerman 已提交
252
	unsigned long	accum_tb;	/* Total accumulated purr for process */
253
#endif
254 255 256 257 258 259 260 261
#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 */
262
	struct arch_hw_breakpoint hw_brk; /* info on the hardware breakpoint */
263
	unsigned long	trap_nr;	/* last trap # on this thread */
264
	u8 load_fp;
L
Linus Torvalds 已提交
265
#ifdef CONFIG_ALTIVEC
266
	u8 load_vec;
267
	struct thread_vr_state vr_state;
268
	struct thread_vr_state *vr_save_area;
L
Linus Torvalds 已提交
269 270 271
	unsigned long	vrsave;
	int		used_vr;	/* set if process has used altivec */
#endif /* CONFIG_ALTIVEC */
272 273
#ifdef CONFIG_VSX
	/* VSR status */
S
Simon Guo 已提交
274
	int		used_vsr;	/* set if process has used VSX */
275
#endif /* CONFIG_VSX */
L
Linus Torvalds 已提交
276 277 278 279
#ifdef CONFIG_SPE
	unsigned long	evr[32];	/* upper 32-bits of SPE regs */
	u64		acc;		/* Accumulator */
	unsigned long	spefscr;	/* SPE & eFP status */
280 281
	unsigned long	spefscr_last;	/* SPEFSCR value on last prctl
					   call or trap return */
L
Linus Torvalds 已提交
282 283
	int		used_spe;	/* set if process has used spe */
#endif /* CONFIG_SPE */
284
#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
285
	u8	load_tm;
286 287 288 289 290
	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 */

291 292 293 294
	unsigned long	tm_tar;
	unsigned long	tm_ppr;
	unsigned long	tm_dscr;

295
	/*
296
	 * Checkpointed FP and VSX 0-31 register set.
297 298 299 300 301
	 *
	 * 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.
	 *
302
	 * These are analogous to how ckpt_regs and pt_regs work
303
	 */
304 305 306
	struct thread_fp_state ckfp_state; /* Checkpointed FP state */
	struct thread_vr_state ckvr_state; /* Checkpointed VR state */
	unsigned long	ckvrsave; /* Checkpointed VRSAVE */
307
#endif /* CONFIG_PPC_TRANSACTIONAL_MEM */
308 309 310
#ifdef CONFIG_KVM_BOOK3S_32_HANDLER
	void*		kvm_shadow_vcpu; /* KVM internal data */
#endif /* CONFIG_KVM_BOOK3S_32_HANDLER */
311 312 313
#if defined(CONFIG_KVM) && defined(CONFIG_BOOKE)
	struct kvm_vcpu	*kvm_vcpu;
#endif
314 315
#ifdef CONFIG_PPC64
	unsigned long	dscr;
316
	unsigned long	fscr;
317 318 319 320 321 322 323 324 325
	/*
	 * 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.
	 */
326
	int		dscr_inherit;
327
	unsigned long	ppr;	/* used to save/restore SMT priority */
328
#endif
329 330
#ifdef CONFIG_PPC_BOOK3S_64
	unsigned long	tar;
331 332 333
	unsigned long	ebbrr;
	unsigned long	ebbhr;
	unsigned long	bescr;
334 335 336 337
	unsigned long	siar;
	unsigned long	sdar;
	unsigned long	sier;
	unsigned long	mmcr2;
338 339
	unsigned 	mmcr0;
	unsigned 	used_ebb;
340
#endif
L
Linus Torvalds 已提交
341 342 343 344 345
};

#define ARCH_MIN_TASKALIGN 16

#define INIT_SP		(sizeof(init_stack) + (unsigned long) &init_stack)
346 347
#define INIT_SP_LIMIT \
	(_ALIGN_UP(sizeof(init_thread_info), 16) + (unsigned long) &init_stack)
L
Linus Torvalds 已提交
348

349
#ifdef CONFIG_SPE
350 351 352
#define SPEFSCR_INIT \
	.spefscr = SPEFSCR_FINVE | SPEFSCR_FDBZE | SPEFSCR_FUNFE | SPEFSCR_FOVFE, \
	.spefscr_last = SPEFSCR_FINVE | SPEFSCR_FDBZE | SPEFSCR_FUNFE | SPEFSCR_FOVFE,
353 354 355
#else
#define SPEFSCR_INIT
#endif
P
Paul Mackerras 已提交
356 357

#ifdef CONFIG_PPC32
L
Linus Torvalds 已提交
358 359
#define INIT_THREAD { \
	.ksp = INIT_SP, \
360
	.ksp_limit = INIT_SP_LIMIT, \
L
Linus Torvalds 已提交
361 362 363
	.fs = KERNEL_DS, \
	.pgdir = swapper_pg_dir, \
	.fpexc_mode = MSR_FE0 | MSR_FE1, \
364
	SPEFSCR_INIT \
L
Linus Torvalds 已提交
365
}
P
Paul Mackerras 已提交
366 367 368 369 370
#else
#define INIT_THREAD  { \
	.ksp = INIT_SP, \
	.regs = (struct pt_regs *)INIT_SP - 1, /* XXX bogus, I think */ \
	.fs = KERNEL_DS, \
371
	.fpexc_mode = 0, \
372
	.ppr = INIT_PPR, \
373
	.fscr = FSCR_TAR | FSCR_EBB \
P
Paul Mackerras 已提交
374 375
}
#endif
L
Linus Torvalds 已提交
376 377 378 379

/*
 * Return saved PC of a blocked thread. For now, this is the "user" PC
 */
P
Paul Mackerras 已提交
380 381
#define thread_saved_pc(tsk)    \
        ((tsk)->thread.regs? (tsk)->thread.regs->nip: 0)
L
Linus Torvalds 已提交
382

383 384
#define task_pt_regs(tsk)	((struct pt_regs *)(tsk)->thread.regs)

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

P
Paul Mackerras 已提交
387 388
#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 已提交
389 390

/* Get/set floating-point exception mode */
P
Paul Mackerras 已提交
391 392
#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 已提交
393 394 395 396

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

397 398 399 400 401 402
#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);

403 404 405 406 407 408
#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);

409 410 411 412 413
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 已提交
414
static inline unsigned int __unpack_fe01(unsigned long msr_bits)
L
Linus Torvalds 已提交
415 416 417 418
{
	return ((msr_bits & MSR_FE0) >> 10) | ((msr_bits & MSR_FE1) >> 8);
}

P
Paul Mackerras 已提交
419
static inline unsigned long __pack_fe01(unsigned int fpmode)
L
Linus Torvalds 已提交
420 421 422 423
{
	return ((fpmode << 10) & MSR_FE0) | ((fpmode << 8) & MSR_FE1);
}

P
Paul Mackerras 已提交
424 425 426
#ifdef CONFIG_PPC64
#define cpu_relax()	do { HMT_low(); HMT_medium(); barrier(); } while (0)
#else
L
Linus Torvalds 已提交
427
#define cpu_relax()	barrier()
P
Paul Mackerras 已提交
428
#endif
L
Linus Torvalds 已提交
429

430 431 432 433
/* 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 已提交
434 435 436 437 438 439 440
/*
 * Prefetch macros.
 */
#define ARCH_HAS_PREFETCH
#define ARCH_HAS_PREFETCHW
#define ARCH_HAS_SPINLOCK_PREFETCH

P
Paul Mackerras 已提交
441
static inline void prefetch(const void *x)
L
Linus Torvalds 已提交
442
{
P
Paul Mackerras 已提交
443 444 445 446
	if (unlikely(!x))
		return;

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

P
Paul Mackerras 已提交
449
static inline void prefetchw(const void *x)
L
Linus Torvalds 已提交
450
{
P
Paul Mackerras 已提交
451 452 453 454
	if (unlikely(!x))
		return;

	__asm__ __volatile__ ("dcbtst 0,%0" : : "r" (x));
L
Linus Torvalds 已提交
455 456 457 458
}

#define spin_lock_prefetch(x)	prefetchw(x)

P
Paul Mackerras 已提交
459
#define HAVE_ARCH_PICK_MMAP_LAYOUT
L
Linus Torvalds 已提交
460

461
#ifdef CONFIG_PPC64
462
static inline unsigned long get_clean_sp(unsigned long sp, int is_32)
463 464
{
	if (is_32)
465
		return sp & 0x0ffffffffUL;
466 467 468
	return sp;
}
#else
469
static inline unsigned long get_clean_sp(unsigned long sp, int is_32)
470
{
471
	return sp;
472 473 474
}
#endif

475
extern unsigned long cpuidle_disable;
476 477
enum idle_boot_override {IDLE_NO_OVERRIDE = 0, IDLE_POWERSAVE_OFF};

478
extern int powersave_nap;	/* set if nap mode can be used in idle loop */
479
extern unsigned long power7_nap(int check_irq);
480
extern unsigned long power7_sleep(void);
481
extern unsigned long power7_winkle(void);
482 483
extern unsigned long power9_idle_stop(unsigned long stop_psscr_val,
				      unsigned long stop_psscr_mask);
484

485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503
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 已提交
504
#endif /* __KERNEL__ */
P
Paul Mackerras 已提交
505 506
#endif /* __ASSEMBLY__ */
#endif /* _ASM_POWERPC_PROCESSOR_H */