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