blob: e8bcfa4ee5c0ef5426e5c16410fb94d5738dd08c [file] [log] [blame]
Bryan Wu1394f032007-05-06 14:50:22 -07001/*
2 * File: include/asm/system.h
3 * Based on:
4 * Author: Tony Kou (tonyko@lineo.ca)
5 * Copyright (c) 2002 Arcturus Networks Inc.
6 * (www.arcturusnetworks.com)
7 * Copyright (c) 2003 Metrowerks (www.metrowerks.com)
8 * Copyright (c) 2004 Analog Device Inc.
9 * Created: 25Jan2001 - Tony Kou
10 * Description: system.h include file
11 *
12 * Modified: 22Sep2006 - Robin Getz
13 * - move include blackfin.h down, so I can get access to
14 * irq functions in other include files.
15 *
16 * Bugs: Enter bugs at http://blackfin.uclinux.org/
17 *
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2, or (at your option)
21 * any later version.
22 *
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
27 *
28 * You should have received a copy of the GNU General Public License
29 * along with this program; see the file COPYING.
30 * If not, write to the Free Software Foundation,
31 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
32 */
33
34#ifndef _BLACKFIN_SYSTEM_H
35#define _BLACKFIN_SYSTEM_H
36
37#include <linux/linkage.h>
38#include <linux/compiler.h>
Bryan Wu639f6572008-08-27 10:51:02 +080039#include <mach/anomaly.h>
Graf Yang6b3087c2009-01-07 23:14:39 +080040#include <asm/pda.h>
41#include <asm/processor.h>
Mike Frysingerb6070572008-11-18 17:48:22 +080042#include <asm/irq.h>
Bryan Wu1394f032007-05-06 14:50:22 -070043
44/*
45 * Force strict CPU ordering.
46 */
47#define nop() asm volatile ("nop;\n\t"::)
48#define mb() asm volatile ("" : : :"memory")
49#define rmb() asm volatile ("" : : :"memory")
50#define wmb() asm volatile ("" : : :"memory")
Stefan Richterb2fff3f2007-10-20 02:30:47 +020051#define set_mb(var, value) do { (void) xchg(&var, value); } while (0)
Bryan Wu1394f032007-05-06 14:50:22 -070052#define read_barrier_depends() do { } while(0)
53
54#ifdef CONFIG_SMP
Graf Yang6b3087c2009-01-07 23:14:39 +080055asmlinkage unsigned long __raw_xchg_1_asm(volatile void *ptr, unsigned long value);
56asmlinkage unsigned long __raw_xchg_2_asm(volatile void *ptr, unsigned long value);
57asmlinkage unsigned long __raw_xchg_4_asm(volatile void *ptr, unsigned long value);
58asmlinkage unsigned long __raw_cmpxchg_1_asm(volatile void *ptr,
59 unsigned long new, unsigned long old);
60asmlinkage unsigned long __raw_cmpxchg_2_asm(volatile void *ptr,
61 unsigned long new, unsigned long old);
62asmlinkage unsigned long __raw_cmpxchg_4_asm(volatile void *ptr,
63 unsigned long new, unsigned long old);
64
65#ifdef __ARCH_SYNC_CORE_DCACHE
66# define smp_mb() do { barrier(); smp_check_barrier(); smp_mark_barrier(); } while (0)
67# define smp_rmb() do { barrier(); smp_check_barrier(); } while (0)
68# define smp_wmb() do { barrier(); smp_mark_barrier(); } while (0)
Bryan Wu1394f032007-05-06 14:50:22 -070069#else
Graf Yang6b3087c2009-01-07 23:14:39 +080070# define smp_mb() barrier()
71# define smp_rmb() barrier()
72# define smp_wmb() barrier()
73#endif
74
75static inline unsigned long __xchg(unsigned long x, volatile void *ptr,
76 int size)
77{
78 unsigned long tmp;
79
80 switch (size) {
81 case 1:
82 tmp = __raw_xchg_1_asm(ptr, x);
83 break;
84 case 2:
85 tmp = __raw_xchg_2_asm(ptr, x);
86 break;
87 case 4:
88 tmp = __raw_xchg_4_asm(ptr, x);
89 break;
90 }
91
92 return tmp;
93}
94
95/*
96 * Atomic compare and exchange. Compare OLD with MEM, if identical,
97 * store NEW in MEM. Return the initial value in MEM. Success is
98 * indicated by comparing RETURN with OLD.
99 */
100static inline unsigned long __cmpxchg(volatile void *ptr, unsigned long old,
101 unsigned long new, int size)
102{
103 unsigned long tmp;
104
105 switch (size) {
106 case 1:
107 tmp = __raw_cmpxchg_1_asm(ptr, new, old);
108 break;
109 case 2:
110 tmp = __raw_cmpxchg_2_asm(ptr, new, old);
111 break;
112 case 4:
113 tmp = __raw_cmpxchg_4_asm(ptr, new, old);
114 break;
115 }
116
117 return tmp;
118}
119#define cmpxchg(ptr, o, n) \
120 ((__typeof__(*(ptr)))__cmpxchg((ptr), (unsigned long)(o), \
121 (unsigned long)(n), sizeof(*(ptr))))
122
123#define smp_read_barrier_depends() smp_check_barrier()
124
125#else /* !CONFIG_SMP */
126
Bryan Wu1394f032007-05-06 14:50:22 -0700127#define smp_mb() barrier()
128#define smp_rmb() barrier()
129#define smp_wmb() barrier()
130#define smp_read_barrier_depends() do { } while(0)
Bryan Wu1394f032007-05-06 14:50:22 -0700131
132struct __xchg_dummy {
133 unsigned long a[100];
134};
135#define __xg(x) ((volatile struct __xchg_dummy *)(x))
136
137static inline unsigned long __xchg(unsigned long x, volatile void *ptr,
138 int size)
139{
140 unsigned long tmp = 0;
141 unsigned long flags = 0;
142
143 local_irq_save(flags);
144
145 switch (size) {
146 case 1:
147 __asm__ __volatile__
148 ("%0 = b%2 (z);\n\t"
149 "b%2 = %1;\n\t"
150 : "=&d" (tmp) : "d" (x), "m" (*__xg(ptr)) : "memory");
151 break;
152 case 2:
153 __asm__ __volatile__
154 ("%0 = w%2 (z);\n\t"
155 "w%2 = %1;\n\t"
156 : "=&d" (tmp) : "d" (x), "m" (*__xg(ptr)) : "memory");
157 break;
158 case 4:
159 __asm__ __volatile__
160 ("%0 = %2;\n\t"
161 "%2 = %1;\n\t"
162 : "=&d" (tmp) : "d" (x), "m" (*__xg(ptr)) : "memory");
163 break;
164 }
165 local_irq_restore(flags);
166 return tmp;
167}
168
Mathieu Desnoyers10b88272008-02-07 00:16:13 -0800169#include <asm-generic/cmpxchg-local.h>
170
Bryan Wu1394f032007-05-06 14:50:22 -0700171/*
Mathieu Desnoyers10b88272008-02-07 00:16:13 -0800172 * cmpxchg_local and cmpxchg64_local are atomic wrt current CPU. Always make
173 * them available.
Bryan Wu1394f032007-05-06 14:50:22 -0700174 */
Mathieu Desnoyers10b88272008-02-07 00:16:13 -0800175#define cmpxchg_local(ptr, o, n) \
176 ((__typeof__(*(ptr)))__cmpxchg_local_generic((ptr), (unsigned long)(o),\
177 (unsigned long)(n), sizeof(*(ptr))))
178#define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
Bryan Wu1394f032007-05-06 14:50:22 -0700179
Mathieu Desnoyers10b88272008-02-07 00:16:13 -0800180#include <asm-generic/cmpxchg.h>
Graf Yang6b3087c2009-01-07 23:14:39 +0800181
182#endif /* !CONFIG_SMP */
183
184#define xchg(ptr, x) ((__typeof__(*(ptr)))__xchg((unsigned long)(x), (ptr), sizeof(*(ptr))))
185#define tas(ptr) ((void)xchg((ptr), 1))
Bryan Wu1394f032007-05-06 14:50:22 -0700186
187#define prepare_to_switch() do { } while(0)
188
189/*
190 * switch_to(n) should switch tasks to task ptr, first checking that
191 * ptr isn't the current task, in which case it does nothing.
192 */
193
Mike Frysingerb6070572008-11-18 17:48:22 +0800194#include <asm/l1layout.h>
Bryan Wu1394f032007-05-06 14:50:22 -0700195
196asmlinkage struct task_struct *resume(struct task_struct *prev, struct task_struct *next);
197
198#define switch_to(prev,next,last) \
199do { \
Roman Zippelf7e42172007-05-09 02:35:17 -0700200 memcpy (&task_thread_info(prev)->l1_task_info, L1_SCRATCH_TASK_INFO, \
Bryan Wu1394f032007-05-06 14:50:22 -0700201 sizeof *L1_SCRATCH_TASK_INFO); \
Roman Zippelf7e42172007-05-09 02:35:17 -0700202 memcpy (L1_SCRATCH_TASK_INFO, &task_thread_info(next)->l1_task_info, \
Bryan Wu1394f032007-05-06 14:50:22 -0700203 sizeof *L1_SCRATCH_TASK_INFO); \
204 (last) = resume (prev, next); \
205} while (0)
206
Graf Yang6b3087c2009-01-07 23:14:39 +0800207#endif /* _BLACKFIN_SYSTEM_H */