2 * include/asm-xtensa/system.h
4 * This file is subject to the terms and conditions of the GNU General Public
5 * License. See the file "COPYING" in the main directory of this archive
8 * Copyright (C) 2001 - 2005 Tensilica Inc.
11 #ifndef _XTENSA_SYSTEM_H
12 #define _XTENSA_SYSTEM_H
14 #include <linux/stringify.h>
16 #include <asm/processor.h>
18 /* interrupt control */
20 #define local_save_flags(x) \
21 __asm__ __volatile__ ("rsr %0,"__stringify(PS) : "=a" (x));
22 #define local_irq_restore(x) do { \
23 __asm__ __volatile__ ("wsr %0, "__stringify(PS)" ; rsync" \
24 :: "a" (x) : "memory"); } while(0);
25 #define local_irq_save(x) do { \
26 __asm__ __volatile__ ("rsil %0, "__stringify(LOCKLEVEL) \
27 : "=a" (x) :: "memory");} while(0);
29 static inline void local_irq_disable(void)
32 __asm__ __volatile__ ("rsil %0, "__stringify(LOCKLEVEL)
33 : "=a" (flags) :: "memory");
35 static inline void local_irq_enable(void)
38 __asm__ __volatile__ ("rsil %0, 0" : "=a" (flags) :: "memory");
42 static inline int irqs_disabled(void)
45 local_save_flags(flags);
50 #define smp_read_barrier_depends() do { } while(0)
51 #define read_barrier_depends() do { } while(0)
53 #define mb() barrier()
58 #error smp_* not defined
60 #define smp_mb() barrier()
61 #define smp_rmb() barrier()
62 #define smp_wmb() barrier()
65 #define set_mb(var, value) do { var = value; mb(); } while (0)
67 #if !defined (__ASSEMBLY__)
69 /* * switch_to(n) should switch tasks to task nr n, first
70 * checking that n isn't the current task, in which case it does nothing.
72 extern void *_switch_to(void *last, void *next);
74 #endif /* __ASSEMBLY__ */
76 #define switch_to(prev,next,last) \
78 (last) = _switch_to(prev, next); \
85 static inline unsigned long
86 __cmpxchg_u32(volatile int *p, int old, int new)
88 __asm__ __volatile__("rsil a15, "__stringify(LOCKLEVEL)"\n\t"
93 "wsr a15, "__stringify(PS)" \n\t"
96 : "a" (p), "a" (old), "r" (new)
100 /* This function doesn't exist, so you'll get a linker error
101 * if something tries to do an invalid cmpxchg(). */
103 extern void __cmpxchg_called_with_bad_pointer(void);
105 static __inline__ unsigned long
106 __cmpxchg(volatile void *ptr, unsigned long old, unsigned long new, int size)
109 case 4: return __cmpxchg_u32(ptr, old, new);
110 default: __cmpxchg_called_with_bad_pointer();
115 #define cmpxchg(ptr,o,n) \
116 ({ __typeof__(*(ptr)) _o_ = (o); \
117 __typeof__(*(ptr)) _n_ = (n); \
118 (__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_, \
119 (unsigned long)_n_, sizeof (*(ptr))); \
122 #include <asm-generic/cmpxchg-local.h>
124 static inline unsigned long __cmpxchg_local(volatile void *ptr,
126 unsigned long new, int size)
130 return __cmpxchg_u32(ptr, old, new);
132 return __cmpxchg_local_generic(ptr, old, new, size);
139 * cmpxchg_local and cmpxchg64_local are atomic wrt current CPU. Always make
142 #define cmpxchg_local(ptr, o, n) \
143 ((__typeof__(*(ptr)))__cmpxchg_local_generic((ptr), (unsigned long)(o),\
144 (unsigned long)(n), sizeof(*(ptr))))
145 #define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
150 * Note that a15 is used here because the register allocation
151 * done by the compiler is not guaranteed and a window overflow
152 * may not occur between the rsil and wsr instructions. By using
153 * a15 in the rsil, the machine is guaranteed to be in a state
154 * where no register reference will cause an overflow.
157 static inline unsigned long xchg_u32(volatile int * m, unsigned long val)
160 __asm__ __volatile__("rsil a15, "__stringify(LOCKLEVEL)"\n\t"
161 "l32i %0, %1, 0 \n\t"
162 "s32i %2, %1, 0 \n\t"
163 "wsr a15, "__stringify(PS)" \n\t"
171 #define xchg(ptr,x) ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
174 * This only works if the compiler isn't horribly bad at optimizing.
175 * gcc-2.5.8 reportedly can't handle this, but I define that one to
179 extern void __xchg_called_with_bad_pointer(void);
181 static __inline__ unsigned long
182 __xchg(unsigned long x, volatile void * ptr, int size)
186 return xchg_u32(ptr, x);
188 __xchg_called_with_bad_pointer();
192 extern void set_except_vector(int n, void *addr);
194 static inline void spill_registers(void)
198 __asm__ __volatile__ (
199 "movi a14," __stringify (PS_EXCM_BIT) " | 1\n\t"
201 "rsr a13," __stringify(SAR) "\n\t"
202 "xsr a14," __stringify(PS) "\n\t"
203 "movi a0, _spill_registers\n\t"
207 "wsr a13," __stringify(SAR) "\n\t"
208 "wsr a14," __stringify(PS) "\n\t"
209 :: "a" (&a0), "a" (&ps)
210 : "a2", "a3", "a4", "a7", "a11", "a12", "a13", "a14", "a15", "memory");
213 #define arch_align_stack(x) (x)
215 #endif /* _XTENSA_SYSTEM_H */