Merge branch 'parisc' from /home/kyle/repos/parisc-2.6.git
[pandora-kernel.git] / include / asm-parisc / processor.h
1 /*
2  * include/asm-parisc/processor.h
3  *
4  * Copyright (C) 1994 Linus Torvalds
5  * Copyright (C) 2001 Grant Grundler
6  */
7
8 #ifndef __ASM_PARISC_PROCESSOR_H
9 #define __ASM_PARISC_PROCESSOR_H
10
11 #ifndef __ASSEMBLY__
12 #include <asm/prefetch.h>       /* lockdep.h needs <linux/prefetch.h> */
13
14 #include <linux/threads.h>
15 #include <linux/spinlock_types.h>
16
17 #include <asm/hardware.h>
18 #include <asm/page.h>
19 #include <asm/pdc.h>
20 #include <asm/ptrace.h>
21 #include <asm/types.h>
22 #include <asm/system.h>
23 #endif /* __ASSEMBLY__ */
24
25 #define KERNEL_STACK_SIZE       (4*PAGE_SIZE)
26
27 /*
28  * Default implementation of macro that returns current
29  * instruction pointer ("program counter").
30  */
31 #ifdef CONFIG_PA20
32 #define current_ia(x)   __asm__("mfia %0" : "=r"(x))
33 #else /* mfia added in pa2.0 */
34 #define current_ia(x)   __asm__("blr 0,%0\n\tnop" : "=r"(x))
35 #endif
36 #define current_text_addr() ({ void *pc; current_ia(pc); pc; })
37
38 #define TASK_SIZE               (current->thread.task_size)
39 #define TASK_UNMAPPED_BASE      (current->thread.map_base)
40
41 #define DEFAULT_TASK_SIZE32     (0xFFF00000UL)
42 #define DEFAULT_MAP_BASE32      (0x40000000UL)
43
44 #ifdef __LP64__
45 #define DEFAULT_TASK_SIZE       (MAX_ADDRESS-0xf000000)
46 #define DEFAULT_MAP_BASE        (0x200000000UL)
47 #else
48 #define DEFAULT_TASK_SIZE       DEFAULT_TASK_SIZE32
49 #define DEFAULT_MAP_BASE        DEFAULT_MAP_BASE32
50 #endif
51
52 #ifndef __ASSEMBLY__
53
54 /*
55  * Data detected about CPUs at boot time which is the same for all CPU's.
56  * HP boxes are SMP - ie identical processors.
57  *
58  * FIXME: some CPU rev info may be processor specific...
59  */
60 struct system_cpuinfo_parisc {
61         unsigned int    cpu_count;
62         unsigned int    cpu_hz;
63         unsigned int    hversion;
64         unsigned int    sversion;
65         enum cpu_type   cpu_type;
66
67         struct {
68                 struct pdc_model model;
69                 unsigned long versions;
70                 unsigned long cpuid;
71                 unsigned long capabilities;
72                 char   sys_model_name[81]; /* PDC-ROM returnes this model name */
73         } pdc;
74
75         char            *cpu_name;      /* e.g. "PA7300LC (PCX-L2)" */
76         char            *family_name;   /* e.g. "1.1e" */
77 };
78
79
80 /* Per CPU data structure - ie varies per CPU.  */
81 struct cpuinfo_parisc {
82         unsigned long it_value;     /* Interval Timer at last timer Intr */
83         unsigned long it_delta;     /* Interval delta (tic_10ms / HZ * 100) */
84         unsigned long irq_count;    /* number of IRQ's since boot */
85         unsigned long irq_max_cr16; /* longest time to handle a single IRQ */
86         unsigned long cpuid;        /* aka slot_number or set to NO_PROC_ID */
87         unsigned long hpa;          /* Host Physical address */
88         unsigned long txn_addr;     /* MMIO addr of EIR or id_eid */
89 #ifdef CONFIG_SMP
90         unsigned long pending_ipi;  /* bitmap of type ipi_message_type */
91         unsigned long ipi_count;    /* number ipi Interrupts */
92 #endif
93         unsigned long bh_count;     /* number of times bh was invoked */
94         unsigned long prof_counter; /* per CPU profiling support */
95         unsigned long prof_multiplier;  /* per CPU profiling support */
96         unsigned long fp_rev;
97         unsigned long fp_model;
98         unsigned int state;
99         struct parisc_device *dev;
100         unsigned long loops_per_jiffy;
101 };
102
103 extern struct system_cpuinfo_parisc boot_cpu_data;
104 extern struct cpuinfo_parisc cpu_data[NR_CPUS];
105 #define current_cpu_data cpu_data[smp_processor_id()]
106
107 #define CPU_HVERSION ((boot_cpu_data.hversion >> 4) & 0x0FFF)
108
109 typedef struct {
110         int seg;  
111 } mm_segment_t;
112
113 #define ARCH_MIN_TASKALIGN      8
114
115 struct thread_struct {
116         struct pt_regs regs;
117         unsigned long  task_size;
118         unsigned long  map_base;
119         unsigned long  flags;
120 }; 
121
122 /* Thread struct flags. */
123 #define PARISC_UAC_NOPRINT      (1UL << 0)      /* see prctl and unaligned.c */
124 #define PARISC_UAC_SIGBUS       (1UL << 1)
125 #define PARISC_KERNEL_DEATH     (1UL << 31)     /* see die_if_kernel()... */
126
127 #define PARISC_UAC_SHIFT        0
128 #define PARISC_UAC_MASK         (PARISC_UAC_NOPRINT|PARISC_UAC_SIGBUS)
129
130 #define SET_UNALIGN_CTL(task,value)                                       \
131         ({                                                                \
132         (task)->thread.flags = (((task)->thread.flags & ~PARISC_UAC_MASK) \
133                                 | (((value) << PARISC_UAC_SHIFT) &        \
134                                    PARISC_UAC_MASK));                     \
135         0;                                                                \
136         })
137
138 #define GET_UNALIGN_CTL(task,addr)                                        \
139         ({                                                                \
140         put_user(((task)->thread.flags & PARISC_UAC_MASK)                 \
141                  >> PARISC_UAC_SHIFT, (int __user *) (addr));             \
142         })
143
144 #define INIT_THREAD { \
145         .regs = {       .gr     = { 0, }, \
146                         .fr     = { 0, }, \
147                         .sr     = { 0, }, \
148                         .iasq   = { 0, }, \
149                         .iaoq   = { 0, }, \
150                         .cr27   = 0, \
151                 }, \
152         .task_size      = DEFAULT_TASK_SIZE, \
153         .map_base       = DEFAULT_MAP_BASE, \
154         .flags          = 0 \
155         }
156
157 /*
158  * Return saved PC of a blocked thread.  This is used by ps mostly.
159  */
160
161 unsigned long thread_saved_pc(struct task_struct *t);
162 void show_trace(struct task_struct *task, unsigned long *stack);
163
164 /*
165  * Start user thread in another space.
166  *
167  * Note that we set both the iaoq and r31 to the new pc. When
168  * the kernel initially calls execve it will return through an
169  * rfi path that will use the values in the iaoq. The execve
170  * syscall path will return through the gateway page, and
171  * that uses r31 to branch to.
172  *
173  * For ELF we clear r23, because the dynamic linker uses it to pass
174  * the address of the finalizer function.
175  *
176  * We also initialize sr3 to an illegal value (illegal for our
177  * implementation, not for the architecture).
178  */
179 typedef unsigned int elf_caddr_t;
180
181 #define start_thread_som(regs, new_pc, new_sp) do {     \
182         unsigned long *sp = (unsigned long *)new_sp;    \
183         __u32 spaceid = (__u32)current->mm->context;    \
184         unsigned long pc = (unsigned long)new_pc;       \
185         /* offset pc for priv. level */                 \
186         pc |= 3;                                        \
187                                                         \
188         set_fs(USER_DS);                                \
189         regs->iasq[0] = spaceid;                        \
190         regs->iasq[1] = spaceid;                        \
191         regs->iaoq[0] = pc;                             \
192         regs->iaoq[1] = pc + 4;                         \
193         regs->sr[2] = LINUX_GATEWAY_SPACE;              \
194         regs->sr[3] = 0xffff;                           \
195         regs->sr[4] = spaceid;                          \
196         regs->sr[5] = spaceid;                          \
197         regs->sr[6] = spaceid;                          \
198         regs->sr[7] = spaceid;                          \
199         regs->gr[ 0] = USER_PSW;                        \
200         regs->gr[30] = ((new_sp)+63)&~63;               \
201         regs->gr[31] = pc;                              \
202                                                         \
203         get_user(regs->gr[26],&sp[0]);                  \
204         get_user(regs->gr[25],&sp[-1]);                 \
205         get_user(regs->gr[24],&sp[-2]);                 \
206         get_user(regs->gr[23],&sp[-3]);                 \
207 } while(0)
208
209 /* The ELF abi wants things done a "wee bit" differently than
210  * som does.  Supporting this behavior here avoids
211  * having our own version of create_elf_tables.
212  *
213  * Oh, and yes, that is not a typo, we are really passing argc in r25
214  * and argv in r24 (rather than r26 and r25).  This is because that's
215  * where __libc_start_main wants them.
216  *
217  * Duplicated from dl-machine.h for the benefit of readers:
218  *
219  *  Our initial stack layout is rather different from everyone else's
220  *  due to the unique PA-RISC ABI.  As far as I know it looks like
221  *  this:
222
223    -----------------------------------  (user startup code creates this frame)
224    |         32 bytes of magic       |
225    |---------------------------------|
226    | 32 bytes argument/sp save area  |
227    |---------------------------------| (bprm->p)
228    |        ELF auxiliary info       |
229    |         (up to 28 words)        |
230    |---------------------------------|
231    |               NULL              |
232    |---------------------------------|
233    |       Environment pointers      |
234    |---------------------------------|
235    |               NULL              |
236    |---------------------------------|
237    |        Argument pointers        |
238    |---------------------------------| <- argv
239    |          argc (1 word)          |
240    |---------------------------------| <- bprm->exec (HACK!)
241    |         N bytes of slack        |
242    |---------------------------------|
243    |    filename passed to execve    |
244    |---------------------------------| (mm->env_end)
245    |           env strings           |
246    |---------------------------------| (mm->env_start, mm->arg_end)
247    |           arg strings           |
248    |---------------------------------|
249    | additional faked arg strings if |
250    | we're invoked via binfmt_script |
251    |---------------------------------| (mm->arg_start)
252    stack base is at TASK_SIZE - rlim_max.
253
254 on downward growing arches, it looks like this:
255    stack base at TASK_SIZE
256    | filename passed to execve
257    | env strings
258    | arg strings
259    | faked arg strings
260    | slack
261    | ELF
262    | envps
263    | argvs
264    | argc
265
266  *  The pleasant part of this is that if we need to skip arguments we
267  *  can just decrement argc and move argv, because the stack pointer
268  *  is utterly unrelated to the location of the environment and
269  *  argument vectors.
270  *
271  * Note that the S/390 people took the easy way out and hacked their
272  * GCC to make the stack grow downwards.
273  *
274  * Final Note: For entry from syscall, the W (wide) bit of the PSW
275  * is stuffed into the lowest bit of the user sp (%r30), so we fill
276  * it in here from the current->personality
277  */
278
279 #ifdef __LP64__
280 #define USER_WIDE_MODE  (!test_thread_flag(TIF_32BIT))
281 #else
282 #define USER_WIDE_MODE  0
283 #endif
284
285 #define start_thread(regs, new_pc, new_sp) do {         \
286         elf_addr_t *sp = (elf_addr_t *)new_sp;          \
287         __u32 spaceid = (__u32)current->mm->context;    \
288         elf_addr_t pc = (elf_addr_t)new_pc | 3;         \
289         elf_caddr_t *argv = (elf_caddr_t *)bprm->exec + 1;      \
290                                                         \
291         set_fs(USER_DS);                                \
292         regs->iasq[0] = spaceid;                        \
293         regs->iasq[1] = spaceid;                        \
294         regs->iaoq[0] = pc;                             \
295         regs->iaoq[1] = pc + 4;                         \
296         regs->sr[2] = LINUX_GATEWAY_SPACE;              \
297         regs->sr[3] = 0xffff;                           \
298         regs->sr[4] = spaceid;                          \
299         regs->sr[5] = spaceid;                          \
300         regs->sr[6] = spaceid;                          \
301         regs->sr[7] = spaceid;                          \
302         regs->gr[ 0] = USER_PSW | (USER_WIDE_MODE ? PSW_W : 0); \
303         regs->fr[ 0] = 0LL;                             \
304         regs->fr[ 1] = 0LL;                             \
305         regs->fr[ 2] = 0LL;                             \
306         regs->fr[ 3] = 0LL;                             \
307         regs->gr[30] = (((unsigned long)sp + 63) &~ 63) | (USER_WIDE_MODE ? 1 : 0); \
308         regs->gr[31] = pc;                              \
309                                                         \
310         get_user(regs->gr[25], (argv - 1));             \
311         regs->gr[24] = (long) argv;                     \
312         regs->gr[23] = 0;                               \
313 } while(0)
314
315 struct task_struct;
316 struct mm_struct;
317
318 /* Free all resources held by a thread. */
319 extern void release_thread(struct task_struct *);
320 extern int kernel_thread(int (*fn)(void *), void * arg, unsigned long flags);
321
322 /* Prepare to copy thread state - unlazy all lazy status */
323 #define prepare_to_copy(tsk)    do { } while (0)
324
325 extern void map_hpux_gateway_page(struct task_struct *tsk, struct mm_struct *mm);
326
327 extern unsigned long get_wchan(struct task_struct *p);
328
329 #define KSTK_EIP(tsk)   ((tsk)->thread.regs.iaoq[0])
330 #define KSTK_ESP(tsk)   ((tsk)->thread.regs.gr[30])
331
332 #define cpu_relax()     barrier()
333
334 /* Used as a macro to identify the combined VIPT/PIPT cached
335  * CPUs which require a guarantee of coherency (no inequivalent
336  * aliases with different data, whether clean or not) to operate */
337 static inline int parisc_requires_coherency(void)
338 {
339 #ifdef CONFIG_PA8X00
340         /* FIXME: also pa8900 - when we see one */
341         return boot_cpu_data.cpu_type == mako;
342 #else
343         return 0;
344 #endif
345 }
346
347 #endif /* __ASSEMBLY__ */
348
349 #endif /* __ASM_PARISC_PROCESSOR_H */