Merge branch 'linus' into core/iommu
[linux-2.6] / arch / blackfin / include / asm / processor.h
1 #ifndef __ASM_BFIN_PROCESSOR_H
2 #define __ASM_BFIN_PROCESSOR_H
3
4 /*
5  * Default implementation of macro that returns current
6  * instruction pointer ("program counter").
7  */
8 #define current_text_addr() ({ __label__ _l; _l: &&_l;})
9
10 #include <asm/blackfin.h>
11 #include <asm/segment.h>
12 #include <linux/compiler.h>
13
14 static inline unsigned long rdusp(void)
15 {
16         unsigned long usp;
17
18         __asm__ __volatile__("%0 = usp;\n\t":"=da"(usp));
19         return usp;
20 }
21
22 static inline void wrusp(unsigned long usp)
23 {
24         __asm__ __volatile__("usp = %0;\n\t"::"da"(usp));
25 }
26
27 static inline unsigned long __get_SP(void)
28 {
29         unsigned long sp;
30
31         __asm__ __volatile__("%0 = sp;\n\t" : "=da"(sp));
32         return sp;
33 }
34
35 /*
36  * User space process size: 1st byte beyond user address space.
37  * Fairly meaningless on nommu.  Parts of user programs can be scattered
38  * in a lot of places, so just disable this by setting it to 0xFFFFFFFF.
39  */
40 #define TASK_SIZE       0xFFFFFFFF
41
42 #ifdef __KERNEL__
43 #define STACK_TOP       TASK_SIZE
44 #endif
45
46 #define TASK_UNMAPPED_BASE      0
47
48 struct thread_struct {
49         unsigned long ksp;      /* kernel stack pointer */
50         unsigned long usp;      /* user stack pointer */
51         unsigned short seqstat; /* saved status register */
52         unsigned long esp0;     /* points to SR of stack frame pt_regs */
53         unsigned long pc;       /* instruction pointer */
54         void *        debuggerinfo;
55 };
56
57 #define INIT_THREAD  {                                          \
58         sizeof(init_stack) + (unsigned long) init_stack, 0,     \
59         PS_S, 0, 0                                              \
60 }
61
62 /*
63  * Do necessary setup to start up a newly executed thread.
64  *
65  * pass the data segment into user programs if it exists,
66  * it can't hurt anything as far as I can tell
67  */
68 #ifndef CONFIG_SMP
69 #define start_thread(_regs, _pc, _usp)                                  \
70 do {                                                                    \
71         set_fs(USER_DS);                                                \
72         (_regs)->pc = (_pc);                                            \
73         if (current->mm)                                                \
74                 (_regs)->p5 = current->mm->start_data;                  \
75         task_thread_info(current)->l1_task_info.stack_start             \
76                 = (void *)current->mm->context.stack_start;             \
77         task_thread_info(current)->l1_task_info.lowest_sp = (void *)(_usp); \
78         memcpy(L1_SCRATCH_TASK_INFO, &task_thread_info(current)->l1_task_info, \
79                 sizeof(*L1_SCRATCH_TASK_INFO));                         \
80         wrusp(_usp);                                                    \
81 } while(0)
82 #else
83 #define start_thread(_regs, _pc, _usp)                                  \
84 do {                                                                    \
85         set_fs(USER_DS);                                                \
86         (_regs)->pc = (_pc);                                            \
87         if (current->mm)                                                \
88                 (_regs)->p5 = current->mm->start_data;                  \
89         wrusp(_usp);                                                    \
90 } while (0)
91 #endif
92
93 /* Forward declaration, a strange C thing */
94 struct task_struct;
95
96 /* Free all resources held by a thread. */
97 static inline void release_thread(struct task_struct *dead_task)
98 {
99 }
100
101 #define prepare_to_copy(tsk)    do { } while (0)
102
103 extern int kernel_thread(int (*fn) (void *), void *arg, unsigned long flags);
104
105 /*
106  * Free current thread data structures etc..
107  */
108 static inline void exit_thread(void)
109 {
110 }
111
112 /*
113  * Return saved PC of a blocked thread.
114  */
115 #define thread_saved_pc(tsk)    (tsk->thread.pc)
116
117 unsigned long get_wchan(struct task_struct *p);
118
119 #define KSTK_EIP(tsk)                                                   \
120     ({                                                                  \
121         unsigned long eip = 0;                                          \
122         if ((tsk)->thread.esp0 > PAGE_SIZE &&                           \
123             MAP_NR((tsk)->thread.esp0) < max_mapnr)                     \
124               eip = ((struct pt_regs *) (tsk)->thread.esp0)->pc;        \
125         eip; })
126 #define KSTK_ESP(tsk)   ((tsk) == current ? rdusp() : (tsk)->thread.usp)
127
128 #define cpu_relax()     smp_mb()
129
130
131 /* Get the Silicon Revision of the chip */
132 static inline uint32_t __pure bfin_revid(void)
133 {
134         /* stored in the upper 4 bits */
135         uint32_t revid = bfin_read_CHIPID() >> 28;
136
137 #ifdef CONFIG_BF52x
138         /* ANOMALY_05000357
139          * Incorrect Revision Number in DSPID Register
140          */
141         if (revid == 0)
142                 switch (bfin_read16(_BOOTROM_GET_DXE_ADDRESS_TWI)) {
143                 case 0x0010:
144                         revid = 0;
145                         break;
146                 case 0x2796:
147                         revid = 1;
148                         break;
149                 default:
150                         revid = 0xFFFF;
151                         break;
152                 }
153 #endif
154         return revid;
155 }
156
157 static inline uint16_t __pure bfin_cpuid(void)
158 {
159         return (bfin_read_CHIPID() & CHIPID_FAMILY) >> 12;
160 }
161
162 static inline uint32_t __pure bfin_dspid(void)
163 {
164         return bfin_read_DSPID();
165 }
166
167 static inline uint32_t __pure bfin_compiled_revid(void)
168 {
169 #if defined(CONFIG_BF_REV_0_0)
170         return 0;
171 #elif defined(CONFIG_BF_REV_0_1)
172         return 1;
173 #elif defined(CONFIG_BF_REV_0_2)
174         return 2;
175 #elif defined(CONFIG_BF_REV_0_3)
176         return 3;
177 #elif defined(CONFIG_BF_REV_0_4)
178         return 4;
179 #elif defined(CONFIG_BF_REV_0_5)
180         return 5;
181 #elif defined(CONFIG_BF_REV_0_6)
182         return 6;
183 #elif defined(CONFIG_BF_REV_ANY)
184         return 0xffff;
185 #else
186         return -1;
187 #endif
188 }
189
190 #endif