blob: aea880274de7223f99c5049425c8c5a1b64b603a [file] [log] [blame]
Robin Getz96f10502009-09-24 14:11:24 +00001/*
2 * Copyright 2004-2009 Analog Devices Inc.
3 *
4 * Licensed under the GPL-2 or later.
5 */
6
Bryan Wu1394f032007-05-06 14:50:22 -07007#ifndef __ASM_BFIN_PROCESSOR_H
8#define __ASM_BFIN_PROCESSOR_H
9
10/*
11 * Default implementation of macro that returns current
12 * instruction pointer ("program counter").
13 */
14#define current_text_addr() ({ __label__ _l; _l: &&_l;})
15
Mike Frysingerd5ce5282009-06-13 11:32:34 -040016#include <asm/ptrace.h>
Bryan Wu1394f032007-05-06 14:50:22 -070017#include <asm/blackfin.h>
Bryan Wu1394f032007-05-06 14:50:22 -070018
19static inline unsigned long rdusp(void)
20{
21 unsigned long usp;
22
23 __asm__ __volatile__("%0 = usp;\n\t":"=da"(usp));
24 return usp;
25}
26
27static inline void wrusp(unsigned long usp)
28{
29 __asm__ __volatile__("usp = %0;\n\t"::"da"(usp));
30}
31
Robin Getza45d5752009-01-07 23:14:38 +080032static inline unsigned long __get_SP(void)
33{
34 unsigned long sp;
35
36 __asm__ __volatile__("%0 = sp;\n\t" : "=da"(sp));
37 return sp;
38}
39
Bryan Wu1394f032007-05-06 14:50:22 -070040/*
41 * User space process size: 1st byte beyond user address space.
Bernd Schmidtd5adb022008-04-24 03:06:15 +080042 * Fairly meaningless on nommu. Parts of user programs can be scattered
43 * in a lot of places, so just disable this by setting it to 0xFFFFFFFF.
Bryan Wu1394f032007-05-06 14:50:22 -070044 */
Bernd Schmidtd5adb022008-04-24 03:06:15 +080045#define TASK_SIZE 0xFFFFFFFF
Bryan Wu1394f032007-05-06 14:50:22 -070046
David Howells922a70d2008-02-08 04:19:26 -080047#ifdef __KERNEL__
48#define STACK_TOP TASK_SIZE
49#endif
50
Bryan Wu1394f032007-05-06 14:50:22 -070051#define TASK_UNMAPPED_BASE 0
52
53struct thread_struct {
54 unsigned long ksp; /* kernel stack pointer */
55 unsigned long usp; /* user stack pointer */
56 unsigned short seqstat; /* saved status register */
57 unsigned long esp0; /* points to SR of stack frame pt_regs */
58 unsigned long pc; /* instruction pointer */
59 void * debuggerinfo;
60};
61
62#define INIT_THREAD { \
63 sizeof(init_stack) + (unsigned long) init_stack, 0, \
64 PS_S, 0, 0 \
65}
66
Mike Frysingerd5ce5282009-06-13 11:32:34 -040067extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
68 unsigned long new_sp);
Bryan Wu1394f032007-05-06 14:50:22 -070069
70/* Forward declaration, a strange C thing */
71struct task_struct;
72
73/* Free all resources held by a thread. */
74static inline void release_thread(struct task_struct *dead_task)
75{
76}
77
78#define prepare_to_copy(tsk) do { } while (0)
79
80extern int kernel_thread(int (*fn) (void *), void *arg, unsigned long flags);
81
82/*
83 * Free current thread data structures etc..
84 */
85static inline void exit_thread(void)
86{
87}
88
89/*
90 * Return saved PC of a blocked thread.
91 */
92#define thread_saved_pc(tsk) (tsk->thread.pc)
93
94unsigned long get_wchan(struct task_struct *p);
95
96#define KSTK_EIP(tsk) \
97 ({ \
98 unsigned long eip = 0; \
99 if ((tsk)->thread.esp0 > PAGE_SIZE && \
100 MAP_NR((tsk)->thread.esp0) < max_mapnr) \
101 eip = ((struct pt_regs *) (tsk)->thread.esp0)->pc; \
102 eip; })
103#define KSTK_ESP(tsk) ((tsk) == current ? rdusp() : (tsk)->thread.usp)
104
Graf Yang6b3087c2009-01-07 23:14:39 +0800105#define cpu_relax() smp_mb()
106
Bryan Wu1394f032007-05-06 14:50:22 -0700107
108/* Get the Silicon Revision of the chip */
Ralf Baechlee8c44312007-10-18 03:07:07 -0700109static inline uint32_t __pure bfin_revid(void)
Bryan Wu1394f032007-05-06 14:50:22 -0700110{
Robin Getzbc4d6f32009-04-23 14:15:04 +0000111 /* Always use CHIPID, to work around ANOMALY_05000234 */
112 uint32_t revid = (bfin_read_CHIPID() & CHIPID_VERSION) >> 28;
Michael Hennerich0138da62008-07-19 16:56:53 +0800113
Graf Yang10a5ecd2009-07-01 04:08:01 +0000114#ifdef _BOOTROM_GET_DXE_ADDRESS_TWI
115 /*
116 * ANOMALY_05000364
Michael Hennerich0138da62008-07-19 16:56:53 +0800117 * Incorrect Revision Number in DSPID Register
118 */
Graf Yang10a5ecd2009-07-01 04:08:01 +0000119 if (ANOMALY_05000364 &&
120 bfin_read16(_BOOTROM_GET_DXE_ADDRESS_TWI) == 0x2796)
121 revid = 1;
Michael Hennerich0138da62008-07-19 16:56:53 +0800122#endif
Graf Yang10a5ecd2009-07-01 04:08:01 +0000123
Michael Hennerich0138da62008-07-19 16:56:53 +0800124 return revid;
Bryan Wu1394f032007-05-06 14:50:22 -0700125}
126
Robin Getze482cad2008-10-10 18:21:45 +0800127static inline uint16_t __pure bfin_cpuid(void)
128{
129 return (bfin_read_CHIPID() & CHIPID_FAMILY) >> 12;
Graf Yang6b3087c2009-01-07 23:14:39 +0800130}
Robin Getze482cad2008-10-10 18:21:45 +0800131
Graf Yang6b3087c2009-01-07 23:14:39 +0800132static inline uint32_t __pure bfin_dspid(void)
133{
134 return bfin_read_DSPID();
Robin Getze482cad2008-10-10 18:21:45 +0800135}
136
Ralf Baechlee8c44312007-10-18 03:07:07 -0700137static inline uint32_t __pure bfin_compiled_revid(void)
Bryan Wu1394f032007-05-06 14:50:22 -0700138{
139#if defined(CONFIG_BF_REV_0_0)
140 return 0;
141#elif defined(CONFIG_BF_REV_0_1)
142 return 1;
143#elif defined(CONFIG_BF_REV_0_2)
144 return 2;
145#elif defined(CONFIG_BF_REV_0_3)
146 return 3;
147#elif defined(CONFIG_BF_REV_0_4)
148 return 4;
149#elif defined(CONFIG_BF_REV_0_5)
150 return 5;
Bryan Wu2e8ca592008-11-18 17:48:22 +0800151#elif defined(CONFIG_BF_REV_0_6)
152 return 6;
Jie Zhangde3025f2007-06-25 18:04:12 +0800153#elif defined(CONFIG_BF_REV_ANY)
154 return 0xffff;
155#else
156 return -1;
Bryan Wu1394f032007-05-06 14:50:22 -0700157#endif
158}
159
160#endif