2 * File: include/asm/system.h
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
12 * Modified: 22Sep2006 - Robin Getz
13 * - move include blackfin.h down, so I can get access to
14 * irq functions in other include files.
16 * Bugs: Enter bugs at http://blackfin.uclinux.org/
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)
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.
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.
34 #ifndef _BLACKFIN_SYSTEM_H
35 #define _BLACKFIN_SYSTEM_H
37 #include <linux/linkage.h>
38 #include <linux/compiler.h>
41 * Interrupt configuring macros.
44 extern unsigned long irq_flags;
46 #define local_irq_enable() do { \
47 __asm__ __volatile__ ( \
52 #define local_irq_disable() do { \
54 __asm__ __volatile__ ( \
56 :"=d" (_tmp_dummy):); \
59 #if defined(ANOMALY_05000244) && defined (CONFIG_BLKFIN_CACHE)
60 #define idle_with_irq_disabled() do { \
61 __asm__ __volatile__ ( \
68 #define idle_with_irq_disabled() do { \
69 __asm__ __volatile__ ( \
76 #ifdef CONFIG_DEBUG_HWERR
77 #define __save_and_cli(x) do { \
78 __asm__ __volatile__ ( \
79 "cli %0;\n\tsti %1;" \
80 :"=&d"(x): "d" (0x3F)); \
83 #define __save_and_cli(x) do { \
84 __asm__ __volatile__ ( \
90 #define local_save_flags(x) asm volatile ("cli %0;" \
94 #ifdef CONFIG_DEBUG_HWERR
95 #define irqs_enabled_from_flags(x) (((x) & ~0x3f) != 0)
97 #define irqs_enabled_from_flags(x) ((x) != 0x1f)
100 #define local_irq_restore(x) do { \
101 if (irqs_enabled_from_flags(x)) \
102 local_irq_enable (); \
105 /* For spinlocks etc */
106 #define local_irq_save(x) __save_and_cli(x)
108 #define irqs_disabled() \
110 unsigned long flags; \
111 local_save_flags(flags); \
112 !irqs_enabled_from_flags(flags); \
116 * Force strict CPU ordering.
118 #define nop() asm volatile ("nop;\n\t"::)
119 #define mb() asm volatile ("" : : :"memory")
120 #define rmb() asm volatile ("" : : :"memory")
121 #define wmb() asm volatile ("" : : :"memory")
122 #define set_rmb(var, value) do { (void) xchg(&var, value); } while (0)
123 #define set_mb(var, value) set_rmb(var, value)
124 #define set_wmb(var, value) do { var = value; wmb(); } while (0)
126 #define read_barrier_depends() do { } while(0)
129 #define smp_mb() mb()
130 #define smp_rmb() rmb()
131 #define smp_wmb() wmb()
132 #define smp_read_barrier_depends() read_barrier_depends()
134 #define smp_mb() barrier()
135 #define smp_rmb() barrier()
136 #define smp_wmb() barrier()
137 #define smp_read_barrier_depends() do { } while(0)
140 #define xchg(ptr,x) ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
141 #define tas(ptr) ((void)xchg((ptr),1))
143 struct __xchg_dummy {
144 unsigned long a[100];
146 #define __xg(x) ((volatile struct __xchg_dummy *)(x))
148 static inline unsigned long __xchg(unsigned long x, volatile void *ptr,
151 unsigned long tmp = 0;
152 unsigned long flags = 0;
154 local_irq_save(flags);
161 : "=&d" (tmp) : "d" (x), "m" (*__xg(ptr)) : "memory");
167 : "=&d" (tmp) : "d" (x), "m" (*__xg(ptr)) : "memory");
173 : "=&d" (tmp) : "d" (x), "m" (*__xg(ptr)) : "memory");
176 local_irq_restore(flags);
181 * Atomic compare and exchange. Compare OLD with MEM, if identical,
182 * store NEW in MEM. Return the initial value in MEM. Success is
183 * indicated by comparing RETURN with OLD.
185 static inline unsigned long __cmpxchg(volatile void *ptr, unsigned long old,
186 unsigned long new, int size)
188 unsigned long tmp = 0;
189 unsigned long flags = 0;
191 local_irq_save(flags);
198 "IF !CC JUMP 1f;\n\t"
201 : "=&d" (tmp) : "d" (old), "d" (new), "m" (*__xg(ptr)) : "memory");
207 "IF !CC JUMP 1f;\n\t"
210 : "=&d" (tmp) : "d" (old), "d" (new), "m" (*__xg(ptr)) : "memory");
216 "IF !CC JUMP 1f;\n\t"
219 : "=&d" (tmp) : "d" (old), "d" (new), "m" (*__xg(ptr)) : "memory");
222 local_irq_restore(flags);
226 #define cmpxchg(ptr,o,n)\
227 ((__typeof__(*(ptr)))__cmpxchg((ptr),(unsigned long)(o),\
228 (unsigned long)(n),sizeof(*(ptr))))
230 #define prepare_to_switch() do { } while(0)
233 * switch_to(n) should switch tasks to task ptr, first checking that
234 * ptr isn't the current task, in which case it does nothing.
237 #include <asm/blackfin.h>
239 asmlinkage struct task_struct *resume(struct task_struct *prev, struct task_struct *next);
241 #define switch_to(prev,next,last) \
243 memcpy (&prev->thread_info->l1_task_info, L1_SCRATCH_TASK_INFO, \
244 sizeof *L1_SCRATCH_TASK_INFO); \
245 memcpy (L1_SCRATCH_TASK_INFO, &next->thread_info->l1_task_info, \
246 sizeof *L1_SCRATCH_TASK_INFO); \
247 (last) = resume (prev, next); \
250 #endif /* _BLACKFIN_SYSTEM_H */