processor.h 8.1 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

P
Paul Mackerras 已提交
15 16
#ifndef __ASSEMBLY__
#include <linux/compiler.h>
L
Linus Torvalds 已提交
17 18 19
#include <asm/ptrace.h>
#include <asm/types.h>

20 21 22
/* 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 已提交
23 24
 */

25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
/* Platforms codes (to be obsoleted) */
#define PLATFORM_PSERIES	0x0100
#define PLATFORM_PSERIES_LPAR	0x0101
#define PLATFORM_ISERIES_LPAR	0x0201
#define PLATFORM_LPAR		0x0001
#define PLATFORM_POWERMAC	0x0400
#define PLATFORM_MAPLE		0x0500
#define PLATFORM_PREP		0x0600
#define PLATFORM_CHRP		0x0700
#define PLATFORM_CELL		0x1000

/* Compat platform codes for 32 bits */
#define _MACH_prep	PLATFORM_PREP
#define _MACH_Pmac	PLATFORM_POWERMAC
#define _MACH_chrp	PLATFORM_CHRP

/* PREP sub-platform types see residual.h for these */
L
Linus Torvalds 已提交
42 43 44 45 46
#define _PREP_Motorola	0x01	/* motorola prep */
#define _PREP_Firm	0x02	/* firmworks prep */
#define _PREP_IBM	0x00	/* ibm prep */
#define _PREP_Bull	0x03	/* bull prep */

47
/* CHRP sub-platform types. These are arbitrary */
L
Linus Torvalds 已提交
48 49 50 51
#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 */

52
#ifdef __KERNEL__
53 54 55 56
#define platform_is_pseries()	(_machine == PLATFORM_PSERIES || \
				 _machine == PLATFORM_PSERIES_LPAR)

#if defined(CONFIG_PPC_MULTIPLATFORM)
L
Linus Torvalds 已提交
57 58
extern int _machine;

59 60
#ifdef CONFIG_PPC32

L
Linus Torvalds 已提交
61 62 63 64 65 66
/* what kind of prep workstation we are */
extern int _prep_type;
extern int _chrp_type;

/*
 * This is used to identify the board type from a given PReP board
67 68
 * vendor. Board revision is also made available. This will be moved
 * elsewhere soon
L
Linus Torvalds 已提交
69 70 71
 */
extern unsigned char ucBoardRev;
extern unsigned char ucBoardRevMaj, ucBoardRevMin;
72 73 74 75 76 77 78

#endif /* CONFIG_PPC32 */

#elif defined(CONFIG_PPC_ISERIES)
/*
 * iSeries is soon to become MULTIPLATFORM hopefully ...
 */
79
#define _machine PLATFORM_ISERIES_LPAR
L
Linus Torvalds 已提交
80 81 82
#else
#define _machine 0
#endif /* CONFIG_PPC_MULTIPLATFORM */
83
#endif /* __KERNEL__ */
P
Paul Mackerras 已提交
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
/*
 * 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__

extern int have_of;
L
Linus Torvalds 已提交
101 102

struct task_struct;
P
Paul Mackerras 已提交
103
void start_thread(struct pt_regs *regs, unsigned long fdptr, unsigned long sp);
L
Linus Torvalds 已提交
104 105 106 107 108
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 已提交
109
/* Create a new kernel thread. */
L
Linus Torvalds 已提交
110 111 112 113 114 115 116
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;
extern struct task_struct *last_task_used_spe;

P
Paul Mackerras 已提交
117 118 119
#ifdef CONFIG_PPC32
#define TASK_SIZE	(CONFIG_TASK_SIZE)

L
Linus Torvalds 已提交
120 121 122 123
/* 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 已提交
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
#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))

#define TASK_SIZE (test_thread_flag(TIF_32BIT) ? \
		TASK_SIZE_USER32 : TASK_SIZE_USER64)

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

#define TASK_UNMAPPED_BASE ((test_thread_flag(TIF_32BIT)) ? \
		TASK_UNMAPPED_BASE_USER32 : TASK_UNMAPPED_BASE_USER64 )
#endif
L
Linus Torvalds 已提交
148 149 150 151 152 153 154

typedef struct {
	unsigned long seg;
} mm_segment_t;

struct thread_struct {
	unsigned long	ksp;		/* Kernel stack pointer */
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 */
P
Paul Mackerras 已提交
160
#ifdef CONFIG_PPC32
L
Linus Torvalds 已提交
161 162
	void		*pgdir;		/* root of page-table tree */
	signed long	last_syscall;
P
Paul Mackerras 已提交
163
#endif
L
Linus Torvalds 已提交
164 165 166 167 168
#if defined(CONFIG_4xx) || defined (CONFIG_BOOKE)
	unsigned long	dbcr0;		/* debug control register values */
	unsigned long	dbcr1;
#endif
	double		fpr[32];	/* Complete floating point set */
169 170 171 172 173
	struct {			/* fpr ... fpscr must be contiguous */

		unsigned int pad;
		unsigned int val;	/* Floating point status */
	} fpscr;
P
Paul Mackerras 已提交
174 175 176 177 178
	int		fpexc_mode;	/* floating-point exception mode */
#ifdef CONFIG_PPC64
	unsigned long	start_tb;	/* Start purr when proc switched in */
	unsigned long	accum_tb;	/* Total accumilated purr for process */
#endif
179
	unsigned long	vdso_base;	/* base of the vDSO library */
P
Paul Mackerras 已提交
180
	unsigned long	dabr;		/* Data address breakpoint register */
L
Linus Torvalds 已提交
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
#ifdef CONFIG_ALTIVEC
	/* Complete AltiVec register set */
	vector128	vr[32] __attribute((aligned(16)));
	/* AltiVec status */
	vector128	vscr __attribute((aligned(16)));
	unsigned long	vrsave;
	int		used_vr;	/* set if process has used altivec */
#endif /* CONFIG_ALTIVEC */
#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 */
};

#define ARCH_MIN_TASKALIGN 16

#define INIT_SP		(sizeof(init_stack) + (unsigned long) &init_stack)

P
Paul Mackerras 已提交
201 202

#ifdef CONFIG_PPC32
L
Linus Torvalds 已提交
203 204 205 206 207 208
#define INIT_THREAD { \
	.ksp = INIT_SP, \
	.fs = KERNEL_DS, \
	.pgdir = swapper_pg_dir, \
	.fpexc_mode = MSR_FE0 | MSR_FE1, \
}
P
Paul Mackerras 已提交
209 210 211 212 213 214
#else
#define INIT_THREAD  { \
	.ksp = INIT_SP, \
	.regs = (struct pt_regs *)INIT_SP - 1, /* XXX bogus, I think */ \
	.fs = KERNEL_DS, \
	.fpr = {0}, \
215
	.fpscr = { .val = 0, }, \
P
Paul Mackerras 已提交
216 217 218
	.fpexc_mode = MSR_FE0|MSR_FE1, \
}
#endif
L
Linus Torvalds 已提交
219 220 221 222

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

unsigned long get_wchan(struct task_struct *p);

P
Paul Mackerras 已提交
228 229
#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 已提交
230 231

/* Get/set floating-point exception mode */
P
Paul Mackerras 已提交
232 233
#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 已提交
234 235 236 237

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

P
Paul Mackerras 已提交
238
static inline unsigned int __unpack_fe01(unsigned long msr_bits)
L
Linus Torvalds 已提交
239 240 241 242
{
	return ((msr_bits & MSR_FE0) >> 10) | ((msr_bits & MSR_FE1) >> 8);
}

P
Paul Mackerras 已提交
243
static inline unsigned long __pack_fe01(unsigned int fpmode)
L
Linus Torvalds 已提交
244 245 246 247
{
	return ((fpmode << 10) & MSR_FE0) | ((fpmode << 8) & MSR_FE1);
}

P
Paul Mackerras 已提交
248 249 250
#ifdef CONFIG_PPC64
#define cpu_relax()	do { HMT_low(); HMT_medium(); barrier(); } while (0)
#else
L
Linus Torvalds 已提交
251
#define cpu_relax()	barrier()
P
Paul Mackerras 已提交
252
#endif
L
Linus Torvalds 已提交
253 254 255 256 257 258 259 260

/*
 * Prefetch macros.
 */
#define ARCH_HAS_PREFETCH
#define ARCH_HAS_PREFETCHW
#define ARCH_HAS_SPINLOCK_PREFETCH

P
Paul Mackerras 已提交
261
static inline void prefetch(const void *x)
L
Linus Torvalds 已提交
262
{
P
Paul Mackerras 已提交
263 264 265 266
	if (unlikely(!x))
		return;

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

P
Paul Mackerras 已提交
269
static inline void prefetchw(const void *x)
L
Linus Torvalds 已提交
270
{
P
Paul Mackerras 已提交
271 272 273 274
	if (unlikely(!x))
		return;

	__asm__ __volatile__ ("dcbtst 0,%0" : : "r" (x));
L
Linus Torvalds 已提交
275 276 277 278
}

#define spin_lock_prefetch(x)	prefetchw(x)

P
Paul Mackerras 已提交
279 280 281
#ifdef CONFIG_PPC64
#define HAVE_ARCH_PICK_MMAP_LAYOUT
#endif
L
Linus Torvalds 已提交
282 283

#endif /* __KERNEL__ */
P
Paul Mackerras 已提交
284 285
#endif /* __ASSEMBLY__ */
#endif /* _ASM_POWERPC_PROCESSOR_H */