Merge branch 'for-linus' of git://git.kernel.dk/linux-2.6-block
[pandora-kernel.git] / 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/ptrace.h>
11 #include <asm/blackfin.h>
12
13 static inline unsigned long rdusp(void)
14 {
15         unsigned long usp;
16
17         __asm__ __volatile__("%0 = usp;\n\t":"=da"(usp));
18         return usp;
19 }
20
21 static inline void wrusp(unsigned long usp)
22 {
23         __asm__ __volatile__("usp = %0;\n\t"::"da"(usp));
24 }
25
26 static inline unsigned long __get_SP(void)
27 {
28         unsigned long sp;
29
30         __asm__ __volatile__("%0 = sp;\n\t" : "=da"(sp));
31         return sp;
32 }
33
34 /*
35  * User space process size: 1st byte beyond user address space.
36  * Fairly meaningless on nommu.  Parts of user programs can be scattered
37  * in a lot of places, so just disable this by setting it to 0xFFFFFFFF.
38  */
39 #define TASK_SIZE       0xFFFFFFFF
40
41 #ifdef __KERNEL__
42 #define STACK_TOP       TASK_SIZE
43 #endif
44
45 #define TASK_UNMAPPED_BASE      0
46
47 struct thread_struct {
48         unsigned long ksp;      /* kernel stack pointer */
49         unsigned long usp;      /* user stack pointer */
50         unsigned short seqstat; /* saved status register */
51         unsigned long esp0;     /* points to SR of stack frame pt_regs */
52         unsigned long pc;       /* instruction pointer */
53         void *        debuggerinfo;
54 };
55
56 #define INIT_THREAD  {                                          \
57         sizeof(init_stack) + (unsigned long) init_stack, 0,     \
58         PS_S, 0, 0                                              \
59 }
60
61 extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
62                                                unsigned long new_sp);
63
64 /* Forward declaration, a strange C thing */
65 struct task_struct;
66
67 /* Free all resources held by a thread. */
68 static inline void release_thread(struct task_struct *dead_task)
69 {
70 }
71
72 #define prepare_to_copy(tsk)    do { } while (0)
73
74 extern int kernel_thread(int (*fn) (void *), void *arg, unsigned long flags);
75
76 /*
77  * Free current thread data structures etc..
78  */
79 static inline void exit_thread(void)
80 {
81 }
82
83 /*
84  * Return saved PC of a blocked thread.
85  */
86 #define thread_saved_pc(tsk)    (tsk->thread.pc)
87
88 unsigned long get_wchan(struct task_struct *p);
89
90 #define KSTK_EIP(tsk)                                                   \
91     ({                                                                  \
92         unsigned long eip = 0;                                          \
93         if ((tsk)->thread.esp0 > PAGE_SIZE &&                           \
94             MAP_NR((tsk)->thread.esp0) < max_mapnr)                     \
95               eip = ((struct pt_regs *) (tsk)->thread.esp0)->pc;        \
96         eip; })
97 #define KSTK_ESP(tsk)   ((tsk) == current ? rdusp() : (tsk)->thread.usp)
98
99 #define cpu_relax()     smp_mb()
100
101
102 /* Get the Silicon Revision of the chip */
103 static inline uint32_t __pure bfin_revid(void)
104 {
105         /* Always use CHIPID, to work around ANOMALY_05000234 */
106         uint32_t revid = (bfin_read_CHIPID() & CHIPID_VERSION) >> 28;
107
108 #ifdef CONFIG_BF52x
109         /* ANOMALY_05000357
110          * Incorrect Revision Number in DSPID Register
111          */
112         if (revid == 0)
113                 switch (bfin_read16(_BOOTROM_GET_DXE_ADDRESS_TWI)) {
114                 case 0x0010:
115                         revid = 0;
116                         break;
117                 case 0x2796:
118                         revid = 1;
119                         break;
120                 default:
121                         revid = 0xFFFF;
122                         break;
123                 }
124 #endif
125         return revid;
126 }
127
128 static inline uint16_t __pure bfin_cpuid(void)
129 {
130         return (bfin_read_CHIPID() & CHIPID_FAMILY) >> 12;
131 }
132
133 static inline uint32_t __pure bfin_dspid(void)
134 {
135         return bfin_read_DSPID();
136 }
137
138 static inline uint32_t __pure bfin_compiled_revid(void)
139 {
140 #if defined(CONFIG_BF_REV_0_0)
141         return 0;
142 #elif defined(CONFIG_BF_REV_0_1)
143         return 1;
144 #elif defined(CONFIG_BF_REV_0_2)
145         return 2;
146 #elif defined(CONFIG_BF_REV_0_3)
147         return 3;
148 #elif defined(CONFIG_BF_REV_0_4)
149         return 4;
150 #elif defined(CONFIG_BF_REV_0_5)
151         return 5;
152 #elif defined(CONFIG_BF_REV_0_6)
153         return 6;
154 #elif defined(CONFIG_BF_REV_ANY)
155         return 0xffff;
156 #else
157         return -1;
158 #endif
159 }
160
161 #endif