ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-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/config.h>
15 #include <linux/cache.h>
16 #include <linux/threads.h>
17
18 #include <asm/cachectl.h>
19 #include <asm/cpu.h>
20 #include <asm/mipsregs.h>
21 #include <asm/prefetch.h>
22 #include <asm/system.h>
23
24 #ifdef CONFIG_SGI_IP27
25 #include <asm/sn/types.h>
26 #endif
27
28 /*
29  * Descriptor for a cache
30  */
31 struct cache_desc {
32         unsigned short linesz;  /* Size of line in bytes */
33         unsigned short ways;    /* Number of ways */
34         unsigned short sets;    /* Number of lines per set */
35         unsigned int waysize;   /* Bytes per way */
36         unsigned int waybit;    /* Bits to select in a cache set */
37         unsigned int flags;     /* Flags describing cache properties */
38 };
39
40 /*
41  * Flag definitions
42  */
43 #define MIPS_CACHE_NOT_PRESENT  0x00000001
44 #define MIPS_CACHE_VTAG         0x00000002      /* Virtually tagged cache */
45 #define MIPS_CACHE_ALIASES      0x00000004      /* Cache could have aliases */
46 #define MIPS_CACHE_IC_F_DC      0x00000008      /* Ic can refill from D-cache */
47
48 struct cpuinfo_mips {
49         unsigned long           udelay_val;
50         unsigned long           asid_cache;
51 #if defined(CONFIG_SGI_IP27)
52 //      cpuid_t         p_cpuid;        /* PROM assigned cpuid */
53         cnodeid_t       p_nodeid;       /* my node ID in compact-id-space */
54         nasid_t         p_nasid;        /* my node ID in numa-as-id-space */
55         unsigned char   p_slice;        /* Physical position on node board */
56 #endif
57 #if 0
58         unsigned long           loops_per_sec;
59         unsigned long           ipi_count;
60         unsigned long           irq_attempt[NR_IRQS];
61         unsigned long           smp_local_irq_count;
62         unsigned long           prof_multiplier;
63         unsigned long           prof_counter;
64 #endif
65
66         /*
67          * Capability and feature descriptor structure for MIPS CPU
68          */
69         unsigned long           options;
70         unsigned int            processor_id;
71         unsigned int            fpu_id;
72         unsigned int            cputype;
73         int                     isa_level;
74         int                     tlbsize;
75         struct cache_desc       icache; /* Primary I-cache */
76         struct cache_desc       dcache; /* Primary D or combined I/D cache */
77         struct cache_desc       scache; /* Secondary cache */
78         struct cache_desc       tcache; /* Tertiary/split secondary cache */
79         void                    *data;  /* Additional data */
80 } __attribute__((aligned(SMP_CACHE_BYTES)));
81
82 extern struct cpuinfo_mips cpu_data[];
83 #define current_cpu_data cpu_data[smp_processor_id()]
84
85 extern void cpu_probe(void);
86 extern void cpu_report(void);
87
88 /*
89  * Return current * instruction pointer ("program counter").
90  */
91 #define current_text_addr() ({ __label__ _l; _l: &&_l;})
92
93 /*
94  * System setup and hardware flags..
95  */
96 extern void (*cpu_wait)(void);
97
98 extern unsigned int vced_count, vcei_count;
99
100 /*
101  * Bus types (default is ISA, but people can check others with these..)
102  */
103 #define MCA_bus 0
104 #define MCA_bus__is_a_macro /* for versions in ksyms.c */
105
106 #ifdef CONFIG_MIPS32
107 /*
108  * User space process size: 2GB. This is hardcoded into a few places,
109  * so don't change it unless you know what you are doing.
110  */
111 #define TASK_SIZE       0x7fff8000UL
112
113 /*
114  * This decides where the kernel will search for a free chunk of vm
115  * space during mmap's.
116  */
117 #define TASK_UNMAPPED_BASE      (PAGE_ALIGN(TASK_SIZE / 3))
118 #endif
119
120 #ifdef CONFIG_MIPS64
121 /*
122  * User space process size: 1TB. This is hardcoded into a few places,
123  * so don't change it unless you know what you are doing.  TASK_SIZE
124  * is limited to 1TB by the R4000 architecture; R10000 and better can
125  * support 16TB; the architectural reserve for future expansion is
126  * 8192EB ...
127  */
128 #define TASK_SIZE32     0x7fff8000UL
129 #define TASK_SIZE       0x10000000000UL
130
131 /*
132  * This decides where the kernel will search for a free chunk of vm
133  * space during mmap's.
134  */
135 #define TASK_UNMAPPED_BASE      ((current->thread.mflags & MF_32BIT_ADDR) ? \
136         PAGE_ALIGN(TASK_SIZE32 / 3) : PAGE_ALIGN(TASK_SIZE / 3))
137 #endif
138
139 /*
140  * Size of io_bitmap in longwords: 32 is ports 0-0x3ff.
141  */
142 #define IO_BITMAP_SIZE  32
143
144 #define NUM_FPU_REGS    32
145
146 typedef u64 fpureg_t;
147
148 struct mips_fpu_hard_struct {
149         fpureg_t        fpr[NUM_FPU_REGS];
150         unsigned int    fcr31;
151 };
152
153 /*
154  * It would be nice to add some more fields for emulator statistics, but there
155  * are a number of fixed offsets in offset.h and elsewhere that would have to
156  * be recalculated by hand.  So the additional information will be private to
157  * the FPU emulator for now.  See asm-mips/fpu_emulator.h.
158  */
159
160 struct mips_fpu_soft_struct {
161         fpureg_t        fpr[NUM_FPU_REGS];
162         unsigned int    fcr31;
163 };
164
165 union mips_fpu_union {
166         struct mips_fpu_hard_struct hard;
167         struct mips_fpu_soft_struct soft;
168 };
169
170 #define INIT_FPU { \
171         {{0,},} \
172 }
173
174 typedef struct {
175         unsigned long seg;
176 } mm_segment_t;
177
178 /*
179  * If you change thread_struct remember to change the #defines below too!
180  */
181 struct thread_struct {
182         /* Saved main processor registers. */
183         unsigned long reg16;
184         unsigned long reg17, reg18, reg19, reg20, reg21, reg22, reg23;
185         unsigned long reg29, reg30, reg31;
186
187         /* Saved cp0 stuff. */
188         unsigned long cp0_status;
189
190         /* Saved fpu/fpu emulator stuff. */
191         union mips_fpu_union fpu;
192
193         /* Other stuff associated with the thread. */
194         unsigned long cp0_badvaddr;     /* Last user fault */
195         unsigned long cp0_baduaddr;     /* Last kernel fault accessing USEG */
196         unsigned long error_code;
197         unsigned long trap_no;
198 #define MF_FIXADE       1               /* Fix address errors in software */
199 #define MF_LOGADE       2               /* Log address errors to syslog */
200 #define MF_32BIT_REGS   4               /* also implies 16/32 fprs */
201 #define MF_32BIT_ADDR   8               /* 32-bit address space (o32/n32) */
202         unsigned long mflags;
203         unsigned long irix_trampoline;  /* Wheee... */
204         unsigned long irix_oldctx;
205 };
206
207 #define MF_ABI_MASK     (MF_32BIT_REGS | MF_32BIT_ADDR)
208 #define MF_O32          (MF_32BIT_REGS | MF_32BIT_ADDR)
209 #define MF_N32          MF_32BIT_ADDR
210 #define MF_N64          0
211
212 #define INIT_THREAD  { \
213         /* \
214          * saved main processor registers \
215          */ \
216         0, 0, 0, 0, 0, 0, 0, 0, \
217                        0, 0, 0, \
218         /* \
219          * saved cp0 stuff \
220          */ \
221         0, \
222         /* \
223          * saved fpu/fpu emulator stuff \
224          */ \
225         INIT_FPU, \
226         /* \
227          * Other stuff associated with the process \
228          */ \
229         0, 0, 0, 0, \
230         /* \
231          * For now the default is to fix address errors \
232          */ \
233         MF_FIXADE, 0, 0 \
234 }
235
236 #ifdef __KERNEL__
237
238 struct task_struct;
239
240 /* Free all resources held by a thread. */
241 #define release_thread(thread) do { } while(0)
242
243 /* Prepare to copy thread state - unlazy all lazy status */
244 #define prepare_to_copy(tsk)    do { } while (0)
245
246 extern long kernel_thread(int (*fn)(void *), void * arg, unsigned long flags);
247
248 extern unsigned long thread_saved_pc(struct task_struct *tsk);
249
250 /*
251  * Do necessary setup to start up a newly executed thread.
252  */
253 extern void start_thread(struct pt_regs * regs, unsigned long pc, unsigned long sp);
254
255 unsigned long get_wchan(struct task_struct *p);
256
257 #define __PT_REG(reg) ((long)&((struct pt_regs *)0)->reg - sizeof(struct pt_regs))
258 #define __KSTK_TOS(tsk) ((unsigned long)(tsk->thread_info) + THREAD_SIZE - 32)
259 #define KSTK_EIP(tsk) (*(unsigned long *)(__KSTK_TOS(tsk) + __PT_REG(cp0_epc)))
260 #define KSTK_ESP(tsk) (*(unsigned long *)(__KSTK_TOS(tsk) + __PT_REG(regs[29])))
261 #define KSTK_STATUS(tsk) (*(unsigned long *)(__KSTK_TOS(tsk) + __PT_REG(cp0_status)))
262
263 #define cpu_relax()     barrier()
264
265 #endif /* __KERNEL__ */
266
267 /*
268  * Return_address is a replacement for __builtin_return_address(count)
269  * which on certain architectures cannot reasonably be implemented in GCC
270  * (MIPS, Alpha) or is unuseable with -fomit-frame-pointer (i386).
271  * Note that __builtin_return_address(x>=1) is forbidden because GCC
272  * aborts compilation on some CPUs.  It's simply not possible to unwind
273  * some CPU's stackframes.
274  *
275  * __builtin_return_address works only for non-leaf functions.  We avoid the
276  * overhead of a function call by forcing the compiler to save the return
277  * address register on the stack.
278  */
279 #define return_address() ({__asm__ __volatile__("":::"$31");__builtin_return_address(0);})
280
281 /*
282  * For now.  The 32-bit cycle counter is screwed up so solving this nicely takes a little
283  * brainwork ...
284  */
285 static inline unsigned long long sched_clock(void)
286 {
287         return 0ULL;
288 }
289
290 #ifdef CONFIG_CPU_HAS_PREFETCH
291
292 #define ARCH_HAS_PREFETCH
293
294 extern inline void prefetch(const void *addr)
295 {
296         __asm__ __volatile__(
297         "       .set    mips4           \n"
298         "       pref    %0, (%1)        \n"
299         "       .set    mips0           \n"
300         :
301         : "i" (Pref_Load), "r" (addr));
302 }
303
304 #endif
305
306 #endif /* _ASM_PROCESSOR_H */