blob: 19e2c7c3e63ac41bf62f2e55a4db10d6bf97a13f [file] [log] [blame]
Bryan Wu1394f032007-05-06 14:50:22 -07001/*
Robin Getz96f10502009-09-24 14:11:24 +00002 * Copyright 2004-2009 Analog Devices Inc.
3 * Tony Kou (tonyko@lineo.ca)
Bryan Wu1394f032007-05-06 14:50:22 -07004 *
Robin Getz96f10502009-09-24 14:11:24 +00005 * Licensed under the GPL-2 or later
Bryan Wu1394f032007-05-06 14:50:22 -07006 */
7
8#ifndef _BLACKFIN_SYSTEM_H
9#define _BLACKFIN_SYSTEM_H
10
11#include <linux/linkage.h>
Mike Frysinger8f860012009-06-08 12:49:48 -040012#include <linux/irqflags.h>
Bryan Wu639f6572008-08-27 10:51:02 +080013#include <mach/anomaly.h>
Mike Frysinger8f860012009-06-08 12:49:48 -040014#include <asm/cache.h>
Graf Yang6b3087c2009-01-07 23:14:39 +080015#include <asm/pda.h>
Mike Frysingerb6070572008-11-18 17:48:22 +080016#include <asm/irq.h>
Bryan Wu1394f032007-05-06 14:50:22 -070017
18/*
19 * Force strict CPU ordering.
20 */
Robin Getz26fe19f2009-01-07 23:14:39 +080021#define nop() __asm__ __volatile__ ("nop;\n\t" : : )
22#define mb() __asm__ __volatile__ ("" : : : "memory")
23#define rmb() __asm__ __volatile__ ("" : : : "memory")
24#define wmb() __asm__ __volatile__ ("" : : : "memory")
Stefan Richterb2fff3f2007-10-20 02:30:47 +020025#define set_mb(var, value) do { (void) xchg(&var, value); } while (0)
Bryan Wu1394f032007-05-06 14:50:22 -070026#define read_barrier_depends() do { } while(0)
27
28#ifdef CONFIG_SMP
Graf Yang6b3087c2009-01-07 23:14:39 +080029asmlinkage unsigned long __raw_xchg_1_asm(volatile void *ptr, unsigned long value);
30asmlinkage unsigned long __raw_xchg_2_asm(volatile void *ptr, unsigned long value);
31asmlinkage unsigned long __raw_xchg_4_asm(volatile void *ptr, unsigned long value);
32asmlinkage unsigned long __raw_cmpxchg_1_asm(volatile void *ptr,
33 unsigned long new, unsigned long old);
34asmlinkage unsigned long __raw_cmpxchg_2_asm(volatile void *ptr,
35 unsigned long new, unsigned long old);
36asmlinkage unsigned long __raw_cmpxchg_4_asm(volatile void *ptr,
37 unsigned long new, unsigned long old);
38
39#ifdef __ARCH_SYNC_CORE_DCACHE
40# define smp_mb() do { barrier(); smp_check_barrier(); smp_mark_barrier(); } while (0)
41# define smp_rmb() do { barrier(); smp_check_barrier(); } while (0)
42# define smp_wmb() do { barrier(); smp_mark_barrier(); } while (0)
Graf Yangdbc895f2009-01-07 23:14:39 +080043#define smp_read_barrier_depends() do { barrier(); smp_check_barrier(); } while (0)
44
Bryan Wu1394f032007-05-06 14:50:22 -070045#else
Graf Yang6b3087c2009-01-07 23:14:39 +080046# define smp_mb() barrier()
47# define smp_rmb() barrier()
48# define smp_wmb() barrier()
Graf Yangdbc895f2009-01-07 23:14:39 +080049#define smp_read_barrier_depends() barrier()
Graf Yang6b3087c2009-01-07 23:14:39 +080050#endif
51
52static inline unsigned long __xchg(unsigned long x, volatile void *ptr,
53 int size)
54{
55 unsigned long tmp;
56
57 switch (size) {
58 case 1:
59 tmp = __raw_xchg_1_asm(ptr, x);
60 break;
61 case 2:
62 tmp = __raw_xchg_2_asm(ptr, x);
63 break;
64 case 4:
65 tmp = __raw_xchg_4_asm(ptr, x);
66 break;
67 }
68
69 return tmp;
70}
71
72/*
73 * Atomic compare and exchange. Compare OLD with MEM, if identical,
74 * store NEW in MEM. Return the initial value in MEM. Success is
75 * indicated by comparing RETURN with OLD.
76 */
77static inline unsigned long __cmpxchg(volatile void *ptr, unsigned long old,
78 unsigned long new, int size)
79{
80 unsigned long tmp;
81
82 switch (size) {
83 case 1:
84 tmp = __raw_cmpxchg_1_asm(ptr, new, old);
85 break;
86 case 2:
87 tmp = __raw_cmpxchg_2_asm(ptr, new, old);
88 break;
89 case 4:
90 tmp = __raw_cmpxchg_4_asm(ptr, new, old);
91 break;
92 }
93
94 return tmp;
95}
96#define cmpxchg(ptr, o, n) \
97 ((__typeof__(*(ptr)))__cmpxchg((ptr), (unsigned long)(o), \
98 (unsigned long)(n), sizeof(*(ptr))))
99
Graf Yang6b3087c2009-01-07 23:14:39 +0800100#else /* !CONFIG_SMP */
101
Bryan Wu1394f032007-05-06 14:50:22 -0700102#define smp_mb() barrier()
103#define smp_rmb() barrier()
104#define smp_wmb() barrier()
105#define smp_read_barrier_depends() do { } while(0)
Bryan Wu1394f032007-05-06 14:50:22 -0700106
107struct __xchg_dummy {
108 unsigned long a[100];
109};
110#define __xg(x) ((volatile struct __xchg_dummy *)(x))
111
Philippe Gerum06ecc192009-06-16 05:25:37 +0200112#include <mach/blackfin.h>
113
Bryan Wu1394f032007-05-06 14:50:22 -0700114static inline unsigned long __xchg(unsigned long x, volatile void *ptr,
115 int size)
116{
117 unsigned long tmp = 0;
Philippe Gerum06ecc192009-06-16 05:25:37 +0200118 unsigned long flags;
Bryan Wu1394f032007-05-06 14:50:22 -0700119
David Howells3b139cd2010-10-07 14:08:52 +0100120 flags = hard_local_irq_save();
Bryan Wu1394f032007-05-06 14:50:22 -0700121
122 switch (size) {
123 case 1:
124 __asm__ __volatile__
125 ("%0 = b%2 (z);\n\t"
126 "b%2 = %1;\n\t"
127 : "=&d" (tmp) : "d" (x), "m" (*__xg(ptr)) : "memory");
128 break;
129 case 2:
130 __asm__ __volatile__
131 ("%0 = w%2 (z);\n\t"
132 "w%2 = %1;\n\t"
133 : "=&d" (tmp) : "d" (x), "m" (*__xg(ptr)) : "memory");
134 break;
135 case 4:
136 __asm__ __volatile__
137 ("%0 = %2;\n\t"
138 "%2 = %1;\n\t"
139 : "=&d" (tmp) : "d" (x), "m" (*__xg(ptr)) : "memory");
140 break;
141 }
David Howells3b139cd2010-10-07 14:08:52 +0100142 hard_local_irq_restore(flags);
Bryan Wu1394f032007-05-06 14:50:22 -0700143 return tmp;
144}
145
Mathieu Desnoyers10b88272008-02-07 00:16:13 -0800146#include <asm-generic/cmpxchg-local.h>
147
Bryan Wu1394f032007-05-06 14:50:22 -0700148/*
Mathieu Desnoyers10b88272008-02-07 00:16:13 -0800149 * cmpxchg_local and cmpxchg64_local are atomic wrt current CPU. Always make
150 * them available.
Bryan Wu1394f032007-05-06 14:50:22 -0700151 */
Mathieu Desnoyers10b88272008-02-07 00:16:13 -0800152#define cmpxchg_local(ptr, o, n) \
153 ((__typeof__(*(ptr)))__cmpxchg_local_generic((ptr), (unsigned long)(o),\
154 (unsigned long)(n), sizeof(*(ptr))))
155#define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
Bryan Wu1394f032007-05-06 14:50:22 -0700156
Mathieu Desnoyers10b88272008-02-07 00:16:13 -0800157#include <asm-generic/cmpxchg.h>
Graf Yang6b3087c2009-01-07 23:14:39 +0800158
159#endif /* !CONFIG_SMP */
160
161#define xchg(ptr, x) ((__typeof__(*(ptr)))__xchg((unsigned long)(x), (ptr), sizeof(*(ptr))))
162#define tas(ptr) ((void)xchg((ptr), 1))
Bryan Wu1394f032007-05-06 14:50:22 -0700163
164#define prepare_to_switch() do { } while(0)
165
166/*
167 * switch_to(n) should switch tasks to task ptr, first checking that
168 * ptr isn't the current task, in which case it does nothing.
169 */
170
Mike Frysingerb6070572008-11-18 17:48:22 +0800171#include <asm/l1layout.h>
Graf Yangdbc895f2009-01-07 23:14:39 +0800172#include <asm/mem_map.h>
Bryan Wu1394f032007-05-06 14:50:22 -0700173
174asmlinkage struct task_struct *resume(struct task_struct *prev, struct task_struct *next);
175
Sonic Zhangcc92b872009-01-07 23:14:38 +0800176#ifndef CONFIG_SMP
Bryan Wu1394f032007-05-06 14:50:22 -0700177#define switch_to(prev,next,last) \
178do { \
Roman Zippelf7e42172007-05-09 02:35:17 -0700179 memcpy (&task_thread_info(prev)->l1_task_info, L1_SCRATCH_TASK_INFO, \
Bryan Wu1394f032007-05-06 14:50:22 -0700180 sizeof *L1_SCRATCH_TASK_INFO); \
Roman Zippelf7e42172007-05-09 02:35:17 -0700181 memcpy (L1_SCRATCH_TASK_INFO, &task_thread_info(next)->l1_task_info, \
Bryan Wu1394f032007-05-06 14:50:22 -0700182 sizeof *L1_SCRATCH_TASK_INFO); \
183 (last) = resume (prev, next); \
184} while (0)
Sonic Zhangcc92b872009-01-07 23:14:38 +0800185#else
186#define switch_to(prev, next, last) \
187do { \
188 (last) = resume(prev, next); \
189} while (0)
190#endif
Bryan Wu1394f032007-05-06 14:50:22 -0700191
Graf Yang6b3087c2009-01-07 23:14:39 +0800192#endif /* _BLACKFIN_SYSTEM_H */