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