processor.h 10.8 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 17
#ifdef CONFIG_VSX
#define TS_FPRWIDTH 2
#else
18
#define TS_FPRWIDTH 1
19
#endif
20

P
Paul Mackerras 已提交
21 22
#ifndef __ASSEMBLY__
#include <linux/compiler.h>
23
#include <linux/cache.h>
L
Linus Torvalds 已提交
24 25 26
#include <asm/ptrace.h>
#include <asm/types.h>

27 28 29
/* 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 已提交
30 31
 */

32
/* PREP sub-platform types see residual.h for these */
L
Linus Torvalds 已提交
33 34 35 36 37
#define _PREP_Motorola	0x01	/* motorola prep */
#define _PREP_Firm	0x02	/* firmworks prep */
#define _PREP_IBM	0x00	/* ibm prep */
#define _PREP_Bull	0x03	/* bull prep */

38
/* CHRP sub-platform types. These are arbitrary */
L
Linus Torvalds 已提交
39 40 41
#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 */
42
#define _CHRP_briq	0x07	/* TotalImpact's briQ */
L
Linus Torvalds 已提交
43

44 45 46
#if defined(__KERNEL__) && defined(CONFIG_PPC32)

extern int _chrp_type;
47

48
#ifdef CONFIG_PPC_PREP
49

L
Linus Torvalds 已提交
50 51 52
/* what kind of prep workstation we are */
extern int _prep_type;

53 54
#endif /* CONFIG_PPC_PREP */

55 56
#endif /* defined(__KERNEL__) && defined(CONFIG_PPC32) */

P
Paul Mackerras 已提交
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
/*
 * 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 已提交
73
struct task_struct;
P
Paul Mackerras 已提交
74
void start_thread(struct pt_regs *regs, unsigned long fdptr, unsigned long sp);
L
Linus Torvalds 已提交
75 76 77 78 79
void release_thread(struct task_struct *);

/* Prepare to copy thread state - unlazy all lazy status */
extern void prepare_to_copy(struct task_struct *tsk);

P
Paul Mackerras 已提交
80
/* Create a new kernel thread. */
L
Linus Torvalds 已提交
81 82 83 84 85
extern long kernel_thread(int (*fn)(void *), void *arg, unsigned long flags);

/* Lazy FPU handling on uni-processor */
extern struct task_struct *last_task_used_math;
extern struct task_struct *last_task_used_altivec;
86
extern struct task_struct *last_task_used_vsx;
L
Linus Torvalds 已提交
87 88
extern struct task_struct *last_task_used_spe;

P
Paul Mackerras 已提交
89
#ifdef CONFIG_PPC32
90 91 92 93

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

L
Linus Torvalds 已提交
96 97 98 99
/* 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 已提交
100 101 102 103 104 105 106 107 108 109 110 111
#endif

#ifdef CONFIG_PPC64
/* 64-bit user address space is 44-bits (16TB user VM) */
#define TASK_SIZE_USER64 (0x0000100000000000UL)

/* 
 * 32-bit user address space is 4GB - 1 page 
 * (this 1 page is needed so referencing of 0xFFFFFFFF generates EFAULT
 */
#define TASK_SIZE_USER32 (0x0000000100000000UL - (1*PAGE_SIZE))

D
Dave Hansen 已提交
112
#define TASK_SIZE_OF(tsk) (test_tsk_thread_flag(tsk, TIF_32BIT) ? \
P
Paul Mackerras 已提交
113
		TASK_SIZE_USER32 : TASK_SIZE_USER64)
D
Dave Hansen 已提交
114
#define TASK_SIZE	  TASK_SIZE_OF(current)
P
Paul Mackerras 已提交
115 116 117 118 119 120 121

/* 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))
#define TASK_UNMAPPED_BASE_USER64 (PAGE_ALIGN(TASK_SIZE_USER64 / 4))

122
#define TASK_UNMAPPED_BASE ((is_32bit_task()) ? \
P
Paul Mackerras 已提交
123 124
		TASK_UNMAPPED_BASE_USER32 : TASK_UNMAPPED_BASE_USER64 )
#endif
L
Linus Torvalds 已提交
125

126 127 128 129 130
#ifdef __powerpc64__

#define STACK_TOP_USER64 TASK_SIZE_USER64
#define STACK_TOP_USER32 TASK_SIZE_USER32

131
#define STACK_TOP (is_32bit_task() ? \
132 133 134 135 136 137 138 139 140 141 142
		   STACK_TOP_USER32 : STACK_TOP_USER64)

#define STACK_TOP_MAX STACK_TOP_USER64

#else /* __powerpc64__ */

#define STACK_TOP TASK_SIZE
#define STACK_TOP_MAX	STACK_TOP

#endif /* __powerpc64__ */

L
Linus Torvalds 已提交
143 144 145 146
typedef struct {
	unsigned long seg;
} mm_segment_t;

147 148 149
#define TS_FPROFFSET 0
#define TS_VSRLOWOFFSET 1
#define TS_FPR(i) fpr[i][TS_FPROFFSET]
150

L
Linus Torvalds 已提交
151 152
struct thread_struct {
	unsigned long	ksp;		/* Kernel stack pointer */
153 154
	unsigned long	ksp_limit;	/* if ksp <= ksp_limit stack overflow */

P
Paul Mackerras 已提交
155 156 157
#ifdef CONFIG_PPC64
	unsigned long	ksp_vsid;
#endif
L
Linus Torvalds 已提交
158 159
	struct pt_regs	*regs;		/* Pointer to saved register state */
	mm_segment_t	fs;		/* for get_fs() validation */
160 161 162 163
#ifdef CONFIG_BOOKE
	/* BookE base exception scratch space; align on cacheline */
	unsigned long	normsave[8] ____cacheline_aligned;
#endif
P
Paul Mackerras 已提交
164
#ifdef CONFIG_PPC32
L
Linus Torvalds 已提交
165
	void		*pgdir;		/* root of page-table tree */
P
Paul Mackerras 已提交
166
#endif
167 168 169 170 171 172
#ifdef CONFIG_PPC_ADV_DEBUG_REGS
	/*
	 * The following help to manage the use of Debug Control Registers
	 * om the BookE platforms.
	 */
	unsigned long	dbcr0;
L
Linus Torvalds 已提交
173
	unsigned long	dbcr1;
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
#ifdef CONFIG_BOOKE
	unsigned long	dbcr2;
#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
	 */
	unsigned long	dbsr;
	/*
	 * 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 已提交
202
#endif
203 204 205
	/* FP and VSX 0-31 register set */
	double		fpr[32][TS_FPRWIDTH];
	struct {
206 207 208 209

		unsigned int pad;
		unsigned int val;	/* Floating point status */
	} fpscr;
P
Paul Mackerras 已提交
210
	int		fpexc_mode;	/* floating-point exception mode */
211
	unsigned int	align_ctl;	/* alignment handling control */
P
Paul Mackerras 已提交
212 213 214
#ifdef CONFIG_PPC64
	unsigned long	start_tb;	/* Start purr when proc switched in */
	unsigned long	accum_tb;	/* Total accumilated purr for process */
215 216 217 218 219 220 221 222
#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 */
P
Paul Mackerras 已提交
223 224
#endif
	unsigned long	dabr;		/* Data address breakpoint register */
L
Linus Torvalds 已提交
225 226
#ifdef CONFIG_ALTIVEC
	/* Complete AltiVec register set */
227
	vector128	vr[32] __attribute__((aligned(16)));
L
Linus Torvalds 已提交
228
	/* AltiVec status */
229
	vector128	vscr __attribute__((aligned(16)));
L
Linus Torvalds 已提交
230 231 232
	unsigned long	vrsave;
	int		used_vr;	/* set if process has used altivec */
#endif /* CONFIG_ALTIVEC */
233 234 235 236
#ifdef CONFIG_VSX
	/* VSR status */
	int		used_vsr;	/* set if process has used altivec */
#endif /* CONFIG_VSX */
L
Linus Torvalds 已提交
237 238 239 240 241 242
#ifdef CONFIG_SPE
	unsigned long	evr[32];	/* upper 32-bits of SPE regs */
	u64		acc;		/* Accumulator */
	unsigned long	spefscr;	/* SPE & eFP status */
	int		used_spe;	/* set if process has used spe */
#endif /* CONFIG_SPE */
243 244 245
#ifdef CONFIG_KVM_BOOK3S_32_HANDLER
	void*		kvm_shadow_vcpu; /* KVM internal data */
#endif /* CONFIG_KVM_BOOK3S_32_HANDLER */
246 247 248 249
#ifdef CONFIG_PPC64
	unsigned long	dscr;
	int		dscr_inherit;
#endif
L
Linus Torvalds 已提交
250 251 252 253 254
};

#define ARCH_MIN_TASKALIGN 16

#define INIT_SP		(sizeof(init_stack) + (unsigned long) &init_stack)
255 256
#define INIT_SP_LIMIT \
	(_ALIGN_UP(sizeof(init_thread_info), 16) + (unsigned long) &init_stack)
L
Linus Torvalds 已提交
257

258 259 260 261 262
#ifdef CONFIG_SPE
#define SPEFSCR_INIT .spefscr = SPEFSCR_FINVE | SPEFSCR_FDBZE | SPEFSCR_FUNFE | SPEFSCR_FOVFE,
#else
#define SPEFSCR_INIT
#endif
P
Paul Mackerras 已提交
263 264

#ifdef CONFIG_PPC32
L
Linus Torvalds 已提交
265 266
#define INIT_THREAD { \
	.ksp = INIT_SP, \
267
	.ksp_limit = INIT_SP_LIMIT, \
L
Linus Torvalds 已提交
268 269 270
	.fs = KERNEL_DS, \
	.pgdir = swapper_pg_dir, \
	.fpexc_mode = MSR_FE0 | MSR_FE1, \
271
	SPEFSCR_INIT \
L
Linus Torvalds 已提交
272
}
P
Paul Mackerras 已提交
273 274 275
#else
#define INIT_THREAD  { \
	.ksp = INIT_SP, \
276
	.ksp_limit = INIT_SP_LIMIT, \
P
Paul Mackerras 已提交
277 278
	.regs = (struct pt_regs *)INIT_SP - 1, /* XXX bogus, I think */ \
	.fs = KERNEL_DS, \
279
	.fpr = {{0}}, \
280
	.fpscr = { .val = 0, }, \
281
	.fpexc_mode = 0, \
P
Paul Mackerras 已提交
282 283
}
#endif
L
Linus Torvalds 已提交
284 285 286 287

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

291 292
#define task_pt_regs(tsk)	((struct pt_regs *)(tsk)->thread.regs)

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

P
Paul Mackerras 已提交
295 296
#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 已提交
297 298

/* Get/set floating-point exception mode */
P
Paul Mackerras 已提交
299 300
#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 已提交
301 302 303 304

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

305 306 307 308 309 310
#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);

311 312 313 314 315 316
#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);

P
Paul Mackerras 已提交
317
static inline unsigned int __unpack_fe01(unsigned long msr_bits)
L
Linus Torvalds 已提交
318 319 320 321
{
	return ((msr_bits & MSR_FE0) >> 10) | ((msr_bits & MSR_FE1) >> 8);
}

P
Paul Mackerras 已提交
322
static inline unsigned long __pack_fe01(unsigned int fpmode)
L
Linus Torvalds 已提交
323 324 325 326
{
	return ((fpmode << 10) & MSR_FE0) | ((fpmode << 8) & MSR_FE1);
}

P
Paul Mackerras 已提交
327 328 329
#ifdef CONFIG_PPC64
#define cpu_relax()	do { HMT_low(); HMT_medium(); barrier(); } while (0)
#else
L
Linus Torvalds 已提交
330
#define cpu_relax()	barrier()
P
Paul Mackerras 已提交
331
#endif
L
Linus Torvalds 已提交
332

333 334 335 336
/* 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 已提交
337 338 339 340 341 342 343
/*
 * Prefetch macros.
 */
#define ARCH_HAS_PREFETCH
#define ARCH_HAS_PREFETCHW
#define ARCH_HAS_SPINLOCK_PREFETCH

P
Paul Mackerras 已提交
344
static inline void prefetch(const void *x)
L
Linus Torvalds 已提交
345
{
P
Paul Mackerras 已提交
346 347 348 349
	if (unlikely(!x))
		return;

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

P
Paul Mackerras 已提交
352
static inline void prefetchw(const void *x)
L
Linus Torvalds 已提交
353
{
P
Paul Mackerras 已提交
354 355 356 357
	if (unlikely(!x))
		return;

	__asm__ __volatile__ ("dcbtst 0,%0" : : "r" (x));
L
Linus Torvalds 已提交
358 359 360 361
}

#define spin_lock_prefetch(x)	prefetchw(x)

P
Paul Mackerras 已提交
362 363 364
#ifdef CONFIG_PPC64
#define HAVE_ARCH_PICK_MMAP_LAYOUT
#endif
L
Linus Torvalds 已提交
365

366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384
#ifdef CONFIG_PPC64
static inline unsigned long get_clean_sp(struct pt_regs *regs, int is_32)
{
	unsigned long sp;

	if (is_32)
		sp = regs->gpr[1] & 0x0ffffffffUL;
	else
		sp = regs->gpr[1];

	return sp;
}
#else
static inline unsigned long get_clean_sp(struct pt_regs *regs, int is_32)
{
	return regs->gpr[1];
}
#endif

L
Linus Torvalds 已提交
385
#endif /* __KERNEL__ */
P
Paul Mackerras 已提交
386 387
#endif /* __ASSEMBLY__ */
#endif /* _ASM_POWERPC_PROCESSOR_H */