blob: 1c64a211cf191fe29626daacda7e55d8b297c510 [file] [log] [blame]
Paul Mackerras9f04b9e2005-10-10 14:19:43 +10001#ifndef _ASM_POWERPC_PROCESSOR_H
2#define _ASM_POWERPC_PROCESSOR_H
3
4/*
5 * Copyright (C) 2001 PPC 64 Team, IBM Corp
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version
10 * 2 of the License, or (at your option) any later version.
11 */
12
Paul Mackerras9f04b9e2005-10-10 14:19:43 +100013#include <asm/reg.h>
14
15#ifndef __ASSEMBLY__
16#include <linux/compiler.h>
17#include <asm/ptrace.h>
18#include <asm/types.h>
Paul Mackerras9f04b9e2005-10-10 14:19:43 +100019
Paul Mackerras799d6042005-11-10 13:37:51 +110020/* We do _not_ want to define new machine types at all, those must die
21 * in favor of using the device-tree
22 * -- BenH.
Paul Mackerras9f04b9e2005-10-10 14:19:43 +100023 */
Paul Mackerras9f04b9e2005-10-10 14:19:43 +100024
Paul Mackerras799d6042005-11-10 13:37:51 +110025/* Platforms codes (to be obsoleted) */
26#define PLATFORM_PSERIES 0x0100
27#define PLATFORM_PSERIES_LPAR 0x0101
28#define PLATFORM_ISERIES_LPAR 0x0201
29#define PLATFORM_LPAR 0x0001
30#define PLATFORM_POWERMAC 0x0400
31#define PLATFORM_MAPLE 0x0500
32#define PLATFORM_PREP 0x0600
33#define PLATFORM_CHRP 0x0700
34#define PLATFORM_CELL 0x1000
35
36/* Compat platform codes for 32 bits */
37#define _MACH_prep PLATFORM_PREP
38#define _MACH_Pmac PLATFORM_POWERMAC
39#define _MACH_chrp PLATFORM_CHRP
40
41/* PREP sub-platform types see residual.h for these */
Paul Mackerras9f04b9e2005-10-10 14:19:43 +100042#define _PREP_Motorola 0x01 /* motorola prep */
43#define _PREP_Firm 0x02 /* firmworks prep */
44#define _PREP_IBM 0x00 /* ibm prep */
45#define _PREP_Bull 0x03 /* bull prep */
46
Paul Mackerras799d6042005-11-10 13:37:51 +110047/* CHRP sub-platform types. These are arbitrary */
Paul Mackerras9f04b9e2005-10-10 14:19:43 +100048#define _CHRP_Motorola 0x04 /* motorola chrp, the cobra */
49#define _CHRP_IBM 0x05 /* IBM chrp, the longtrail and longtrail 2 */
50#define _CHRP_Pegasos 0x06 /* Genesi/bplan's Pegasos and Pegasos2 */
51
Arnd Bergmann88ced032005-12-16 22:43:46 +010052#ifdef __KERNEL__
Paul Mackerras799d6042005-11-10 13:37:51 +110053#define platform_is_pseries() (_machine == PLATFORM_PSERIES || \
54 _machine == PLATFORM_PSERIES_LPAR)
Paul Mackerras799d6042005-11-10 13:37:51 +110055
56#if defined(CONFIG_PPC_MULTIPLATFORM)
Paul Mackerras9f04b9e2005-10-10 14:19:43 +100057extern int _machine;
58
Paul Mackerras799d6042005-11-10 13:37:51 +110059#ifdef CONFIG_PPC32
60
Paul Mackerras9f04b9e2005-10-10 14:19:43 +100061/* what kind of prep workstation we are */
62extern int _prep_type;
63extern int _chrp_type;
64
65/*
66 * This is used to identify the board type from a given PReP board
Paul Mackerras799d6042005-11-10 13:37:51 +110067 * vendor. Board revision is also made available. This will be moved
68 * elsewhere soon
Paul Mackerras9f04b9e2005-10-10 14:19:43 +100069 */
Paul Mackerras9f04b9e2005-10-10 14:19:43 +100070extern unsigned char ucBoardRev;
71extern unsigned char ucBoardRevMaj, ucBoardRevMin;
Paul Mackerras799d6042005-11-10 13:37:51 +110072
73#endif /* CONFIG_PPC32 */
74
75#elif defined(CONFIG_PPC_ISERIES)
76/*
77 * iSeries is soon to become MULTIPLATFORM hopefully ...
78 */
Paul Mackerras3db9aaa2005-11-10 14:23:18 +110079#define _machine PLATFORM_ISERIES_LPAR
Paul Mackerras9f04b9e2005-10-10 14:19:43 +100080#else
81#define _machine 0
82#endif /* CONFIG_PPC_MULTIPLATFORM */
Arnd Bergmann88ced032005-12-16 22:43:46 +010083#endif /* __KERNEL__ */
Paul Mackerras9f04b9e2005-10-10 14:19:43 +100084/*
85 * Default implementation of macro that returns current
86 * instruction pointer ("program counter").
87 */
88#define current_text_addr() ({ __label__ _l; _l: &&_l;})
89
90/* Macros for adjusting thread priority (hardware multi-threading) */
91#define HMT_very_low() asm volatile("or 31,31,31 # very low priority")
92#define HMT_low() asm volatile("or 1,1,1 # low priority")
93#define HMT_medium_low() asm volatile("or 6,6,6 # medium low priority")
94#define HMT_medium() asm volatile("or 2,2,2 # medium priority")
95#define HMT_medium_high() asm volatile("or 5,5,5 # medium high priority")
96#define HMT_high() asm volatile("or 3,3,3 # high priority")
97
98#ifdef __KERNEL__
99
100extern int have_of;
101
102struct task_struct;
103void start_thread(struct pt_regs *regs, unsigned long fdptr, unsigned long sp);
104void release_thread(struct task_struct *);
105
106/* Prepare to copy thread state - unlazy all lazy status */
107extern void prepare_to_copy(struct task_struct *tsk);
108
109/* Create a new kernel thread. */
110extern long kernel_thread(int (*fn)(void *), void *arg, unsigned long flags);
111
112/* Lazy FPU handling on uni-processor */
113extern struct task_struct *last_task_used_math;
114extern struct task_struct *last_task_used_altivec;
115extern struct task_struct *last_task_used_spe;
116
117#ifdef CONFIG_PPC32
118#define TASK_SIZE (CONFIG_TASK_SIZE)
119
120/* This decides where the kernel will search for a free chunk of vm
121 * space during mmap's.
122 */
123#define TASK_UNMAPPED_BASE (TASK_SIZE / 8 * 3)
124#endif
125
126#ifdef CONFIG_PPC64
127/* 64-bit user address space is 44-bits (16TB user VM) */
128#define TASK_SIZE_USER64 (0x0000100000000000UL)
129
130/*
131 * 32-bit user address space is 4GB - 1 page
132 * (this 1 page is needed so referencing of 0xFFFFFFFF generates EFAULT
133 */
134#define TASK_SIZE_USER32 (0x0000000100000000UL - (1*PAGE_SIZE))
135
136#define TASK_SIZE (test_thread_flag(TIF_32BIT) ? \
137 TASK_SIZE_USER32 : TASK_SIZE_USER64)
138
139/* This decides where the kernel will search for a free chunk of vm
140 * space during mmap's.
141 */
142#define TASK_UNMAPPED_BASE_USER32 (PAGE_ALIGN(TASK_SIZE_USER32 / 4))
143#define TASK_UNMAPPED_BASE_USER64 (PAGE_ALIGN(TASK_SIZE_USER64 / 4))
144
145#define TASK_UNMAPPED_BASE ((test_thread_flag(TIF_32BIT)) ? \
146 TASK_UNMAPPED_BASE_USER32 : TASK_UNMAPPED_BASE_USER64 )
147#endif
148
149typedef struct {
150 unsigned long seg;
151} mm_segment_t;
152
153struct thread_struct {
154 unsigned long ksp; /* Kernel stack pointer */
155#ifdef CONFIG_PPC64
156 unsigned long ksp_vsid;
157#endif
158 struct pt_regs *regs; /* Pointer to saved register state */
159 mm_segment_t fs; /* for get_fs() validation */
160#ifdef CONFIG_PPC32
161 void *pgdir; /* root of page-table tree */
162 signed long last_syscall;
163#endif
164#if defined(CONFIG_4xx) || defined (CONFIG_BOOKE)
165 unsigned long dbcr0; /* debug control register values */
166 unsigned long dbcr1;
167#endif
168 double fpr[32]; /* Complete floating point set */
David Gibson25c8a782005-10-27 16:27:25 +1000169 struct { /* fpr ... fpscr must be contiguous */
170
171 unsigned int pad;
172 unsigned int val; /* Floating point status */
173 } fpscr;
Paul Mackerras9f04b9e2005-10-10 14:19:43 +1000174 int fpexc_mode; /* floating-point exception mode */
175#ifdef CONFIG_PPC64
176 unsigned long start_tb; /* Start purr when proc switched in */
177 unsigned long accum_tb; /* Total accumilated purr for process */
Paul Mackerras9f04b9e2005-10-10 14:19:43 +1000178#endif
Benjamin Herrenschmidta7f290d2005-11-11 21:15:21 +1100179 unsigned long vdso_base; /* base of the vDSO library */
Paul Mackerras9f04b9e2005-10-10 14:19:43 +1000180 unsigned long dabr; /* Data address breakpoint register */
181#ifdef CONFIG_ALTIVEC
182 /* Complete AltiVec register set */
183 vector128 vr[32] __attribute((aligned(16)));
184 /* AltiVec status */
185 vector128 vscr __attribute((aligned(16)));
186 unsigned long vrsave;
187 int used_vr; /* set if process has used altivec */
188#endif /* CONFIG_ALTIVEC */
189#ifdef CONFIG_SPE
190 unsigned long evr[32]; /* upper 32-bits of SPE regs */
191 u64 acc; /* Accumulator */
192 unsigned long spefscr; /* SPE & eFP status */
193 int used_spe; /* set if process has used spe */
194#endif /* CONFIG_SPE */
195};
196
197#define ARCH_MIN_TASKALIGN 16
198
199#define INIT_SP (sizeof(init_stack) + (unsigned long) &init_stack)
200
201
202#ifdef CONFIG_PPC32
203#define INIT_THREAD { \
204 .ksp = INIT_SP, \
205 .fs = KERNEL_DS, \
206 .pgdir = swapper_pg_dir, \
207 .fpexc_mode = MSR_FE0 | MSR_FE1, \
208}
209#else
210#define INIT_THREAD { \
211 .ksp = INIT_SP, \
212 .regs = (struct pt_regs *)INIT_SP - 1, /* XXX bogus, I think */ \
213 .fs = KERNEL_DS, \
214 .fpr = {0}, \
David Gibson25c8a782005-10-27 16:27:25 +1000215 .fpscr = { .val = 0, }, \
Paul Mackerras9f04b9e2005-10-10 14:19:43 +1000216 .fpexc_mode = MSR_FE0|MSR_FE1, \
217}
218#endif
219
220/*
221 * Return saved PC of a blocked thread. For now, this is the "user" PC
222 */
223#define thread_saved_pc(tsk) \
224 ((tsk)->thread.regs? (tsk)->thread.regs->nip: 0)
225
226unsigned long get_wchan(struct task_struct *p);
227
228#define KSTK_EIP(tsk) ((tsk)->thread.regs? (tsk)->thread.regs->nip: 0)
229#define KSTK_ESP(tsk) ((tsk)->thread.regs? (tsk)->thread.regs->gpr[1]: 0)
230
231/* Get/set floating-point exception mode */
232#define GET_FPEXC_CTL(tsk, adr) get_fpexc_mode((tsk), (adr))
233#define SET_FPEXC_CTL(tsk, val) set_fpexc_mode((tsk), (val))
234
235extern int get_fpexc_mode(struct task_struct *tsk, unsigned long adr);
236extern int set_fpexc_mode(struct task_struct *tsk, unsigned int val);
237
238static inline unsigned int __unpack_fe01(unsigned long msr_bits)
239{
240 return ((msr_bits & MSR_FE0) >> 10) | ((msr_bits & MSR_FE1) >> 8);
241}
242
243static inline unsigned long __pack_fe01(unsigned int fpmode)
244{
245 return ((fpmode << 10) & MSR_FE0) | ((fpmode << 8) & MSR_FE1);
246}
247
248#ifdef CONFIG_PPC64
249#define cpu_relax() do { HMT_low(); HMT_medium(); barrier(); } while (0)
250#else
251#define cpu_relax() barrier()
252#endif
253
254/*
255 * Prefetch macros.
256 */
257#define ARCH_HAS_PREFETCH
258#define ARCH_HAS_PREFETCHW
259#define ARCH_HAS_SPINLOCK_PREFETCH
260
261static inline void prefetch(const void *x)
262{
263 if (unlikely(!x))
264 return;
265
266 __asm__ __volatile__ ("dcbt 0,%0" : : "r" (x));
267}
268
269static inline void prefetchw(const void *x)
270{
271 if (unlikely(!x))
272 return;
273
274 __asm__ __volatile__ ("dcbtst 0,%0" : : "r" (x));
275}
276
277#define spin_lock_prefetch(x) prefetchw(x)
278
279#ifdef CONFIG_PPC64
280#define HAVE_ARCH_PICK_MMAP_LAYOUT
281#endif
282
283#endif /* __KERNEL__ */
284#endif /* __ASSEMBLY__ */
285#endif /* _ASM_POWERPC_PROCESSOR_H */