Merge git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
[sfrench/cifs-2.6.git] / include / asm-mips / processor.h
1 /*
2  * This file is subject to the terms and conditions of the GNU General Public
3  * License.  See the file "COPYING" in the main directory of this archive
4  * for more details.
5  *
6  * Copyright (C) 1994 Waldorf GMBH
7  * Copyright (C) 1995, 1996, 1997, 1998, 1999, 2001, 2002, 2003 Ralf Baechle
8  * Copyright (C) 1996 Paul M. Antoine
9  * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
10  */
11 #ifndef _ASM_PROCESSOR_H
12 #define _ASM_PROCESSOR_H
13
14 #include <linux/cpumask.h>
15 #include <linux/threads.h>
16
17 #include <asm/cachectl.h>
18 #include <asm/cpu.h>
19 #include <asm/cpu-info.h>
20 #include <asm/mipsregs.h>
21 #include <asm/prefetch.h>
22 #include <asm/system.h>
23
24 /*
25  * Return current * instruction pointer ("program counter").
26  */
27 #define current_text_addr() ({ __label__ _l; _l: &&_l;})
28
29 /*
30  * System setup and hardware flags..
31  */
32 extern void (*cpu_wait)(void);
33
34 extern unsigned int vced_count, vcei_count;
35
36 #ifdef CONFIG_32BIT
37 /*
38  * User space process size: 2GB. This is hardcoded into a few places,
39  * so don't change it unless you know what you are doing.
40  */
41 #define TASK_SIZE       0x7fff8000UL
42
43 /*
44  * This decides where the kernel will search for a free chunk of vm
45  * space during mmap's.
46  */
47 #define TASK_UNMAPPED_BASE      (PAGE_ALIGN(TASK_SIZE / 3))
48 #endif
49
50 #ifdef CONFIG_64BIT
51 /*
52  * User space process size: 1TB. This is hardcoded into a few places,
53  * so don't change it unless you know what you are doing.  TASK_SIZE
54  * is limited to 1TB by the R4000 architecture; R10000 and better can
55  * support 16TB; the architectural reserve for future expansion is
56  * 8192EB ...
57  */
58 #define TASK_SIZE32     0x7fff8000UL
59 #define TASK_SIZE       0x10000000000UL
60
61 /*
62  * This decides where the kernel will search for a free chunk of vm
63  * space during mmap's.
64  */
65 #define TASK_UNMAPPED_BASE      ((current->thread.mflags & MF_32BIT_ADDR) ? \
66         PAGE_ALIGN(TASK_SIZE32 / 3) : PAGE_ALIGN(TASK_SIZE / 3))
67 #endif
68
69 #define NUM_FPU_REGS    32
70
71 typedef __u64 fpureg_t;
72
73 struct mips_fpu_hard_struct {
74         fpureg_t        fpr[NUM_FPU_REGS];
75         unsigned int    fcr31;
76 };
77
78 /*
79  * It would be nice to add some more fields for emulator statistics, but there
80  * are a number of fixed offsets in offset.h and elsewhere that would have to
81  * be recalculated by hand.  So the additional information will be private to
82  * the FPU emulator for now.  See asm-mips/fpu_emulator.h.
83  */
84
85 struct mips_fpu_soft_struct {
86         fpureg_t        fpr[NUM_FPU_REGS];
87         unsigned int    fcr31;
88 };
89
90 union mips_fpu_union {
91         struct mips_fpu_hard_struct hard;
92         struct mips_fpu_soft_struct soft;
93 };
94
95 #define INIT_FPU { \
96         {{0,},} \
97 }
98
99 #define NUM_DSP_REGS   6
100
101 typedef __u32 dspreg_t;
102
103 struct mips_dsp_state {
104         dspreg_t        dspr[NUM_DSP_REGS];
105         unsigned int    dspcontrol;
106 };
107
108 #define INIT_DSP {{0,},}
109
110 #define INIT_CPUMASK { \
111         {0,} \
112 }
113
114 typedef struct {
115         unsigned long seg;
116 } mm_segment_t;
117
118 #define ARCH_MIN_TASKALIGN      8
119
120 struct mips_abi;
121
122 /*
123  * If you change thread_struct remember to change the #defines below too!
124  */
125 struct thread_struct {
126         /* Saved main processor registers. */
127         unsigned long reg16;
128         unsigned long reg17, reg18, reg19, reg20, reg21, reg22, reg23;
129         unsigned long reg29, reg30, reg31;
130
131         /* Saved cp0 stuff. */
132         unsigned long cp0_status;
133
134         /* Saved fpu/fpu emulator stuff. */
135         union mips_fpu_union fpu;
136 #ifdef CONFIG_MIPS_MT_FPAFF
137         /* Emulated instruction count */
138         unsigned long emulated_fp;
139         /* Saved per-thread scheduler affinity mask */
140         cpumask_t user_cpus_allowed;
141 #endif /* CONFIG_MIPS_MT_FPAFF */
142
143         /* Saved state of the DSP ASE, if available. */
144         struct mips_dsp_state dsp;
145
146         /* Other stuff associated with the thread. */
147         unsigned long cp0_badvaddr;     /* Last user fault */
148         unsigned long cp0_baduaddr;     /* Last kernel fault accessing USEG */
149         unsigned long error_code;
150         unsigned long trap_no;
151 #define MF_FIXADE       1               /* Fix address errors in software */
152 #define MF_LOGADE       2               /* Log address errors to syslog */
153 #define MF_32BIT_REGS   4               /* also implies 16/32 fprs */
154 #define MF_32BIT_ADDR   8               /* 32-bit address space (o32/n32) */
155 #define MF_FPUBOUND     0x10            /* thread bound to FPU-full CPU set */
156         unsigned long mflags;
157         unsigned long irix_trampoline;  /* Wheee... */
158         unsigned long irix_oldctx;
159         struct mips_abi *abi;
160 };
161
162 #define MF_ABI_MASK     (MF_32BIT_REGS | MF_32BIT_ADDR)
163 #define MF_O32          (MF_32BIT_REGS | MF_32BIT_ADDR)
164 #define MF_N32          MF_32BIT_ADDR
165 #define MF_N64          0
166
167 #ifdef CONFIG_MIPS_MT_FPAFF
168 #define FPAFF_INIT 0, INIT_CPUMASK,
169 #else
170 #define FPAFF_INIT
171 #endif /* CONFIG_MIPS_MT_FPAFF */
172
173 #define INIT_THREAD  { \
174         /* \
175          * saved main processor registers \
176          */ \
177         0, 0, 0, 0, 0, 0, 0, 0, \
178                        0, 0, 0, \
179         /* \
180          * saved cp0 stuff \
181          */ \
182         0, \
183         /* \
184          * saved fpu/fpu emulator stuff \
185          */ \
186         INIT_FPU, \
187         /* \
188          * fpu affinity state (null if not FPAFF) \
189          */ \
190         FPAFF_INIT \
191         /* \
192          * saved dsp/dsp emulator stuff \
193          */ \
194         INIT_DSP, \
195         /* \
196          * Other stuff associated with the process \
197          */ \
198         0, 0, 0, 0, \
199         /* \
200          * For now the default is to fix address errors \
201          */ \
202         MF_FIXADE, 0, 0 \
203 }
204
205 struct task_struct;
206
207 /* Free all resources held by a thread. */
208 #define release_thread(thread) do { } while(0)
209
210 /* Prepare to copy thread state - unlazy all lazy status */
211 #define prepare_to_copy(tsk)    do { } while (0)
212
213 extern long kernel_thread(int (*fn)(void *), void * arg, unsigned long flags);
214
215 extern unsigned long thread_saved_pc(struct task_struct *tsk);
216
217 /*
218  * Do necessary setup to start up a newly executed thread.
219  */
220 extern void start_thread(struct pt_regs * regs, unsigned long pc, unsigned long sp);
221
222 unsigned long get_wchan(struct task_struct *p);
223
224 #define __KSTK_TOS(tsk) ((unsigned long)task_stack_page(tsk) + THREAD_SIZE - 32)
225 #define task_pt_regs(tsk) ((struct pt_regs *)__KSTK_TOS(tsk) - 1)
226 #define KSTK_EIP(tsk) (task_pt_regs(tsk)->cp0_epc)
227 #define KSTK_ESP(tsk) (task_pt_regs(tsk)->regs[29])
228 #define KSTK_STATUS(tsk) (task_pt_regs(tsk)->cp0_status)
229
230 #define cpu_relax()     barrier()
231
232 /*
233  * Return_address is a replacement for __builtin_return_address(count)
234  * which on certain architectures cannot reasonably be implemented in GCC
235  * (MIPS, Alpha) or is unuseable with -fomit-frame-pointer (i386).
236  * Note that __builtin_return_address(x>=1) is forbidden because GCC
237  * aborts compilation on some CPUs.  It's simply not possible to unwind
238  * some CPU's stackframes.
239  *
240  * __builtin_return_address works only for non-leaf functions.  We avoid the
241  * overhead of a function call by forcing the compiler to save the return
242  * address register on the stack.
243  */
244 #define return_address() ({__asm__ __volatile__("":::"$31");__builtin_return_address(0);})
245
246 #ifdef CONFIG_CPU_HAS_PREFETCH
247
248 #define ARCH_HAS_PREFETCH
249
250 extern inline void prefetch(const void *addr)
251 {
252         __asm__ __volatile__(
253         "       .set    mips4           \n"
254         "       pref    %0, (%1)        \n"
255         "       .set    mips0           \n"
256         :
257         : "i" (Pref_Load), "r" (addr));
258 }
259
260 #endif
261
262 #endif /* _ASM_PROCESSOR_H */