pata_bf54x: decrease count first.
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / include / asm-xtensa / system.h
blob62b1e8f3c13c38bb99e23bd457cc61e858628abe
1 /*
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
6 * for more details.
8 * Copyright (C) 2001 - 2005 Tensilica Inc.
9 */
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)
31 unsigned long flags;
32 __asm__ __volatile__ ("rsil %0, "__stringify(LOCKLEVEL)
33 : "=a" (flags) :: "memory");
35 static inline void local_irq_enable(void)
37 unsigned long flags;
38 __asm__ __volatile__ ("rsil %0, 0" : "=a" (flags) :: "memory");
42 static inline int irqs_disabled(void)
44 unsigned long flags;
45 local_save_flags(flags);
46 return flags & 0xf;
50 #define smp_read_barrier_depends() do { } while(0)
51 #define read_barrier_depends() do { } while(0)
53 #define mb() barrier()
54 #define rmb() mb()
55 #define wmb() mb()
57 #ifdef CONFIG_SMP
58 #error smp_* not defined
59 #else
60 #define smp_mb() barrier()
61 #define smp_rmb() barrier()
62 #define smp_wmb() barrier()
63 #endif
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) \
77 do { \
78 (last) = _switch_to(prev, next); \
79 } while(0)
82 * cmpxchg
85 static inline unsigned long
86 __cmpxchg_u32(volatile int *p, int old, int new)
88 __asm__ __volatile__("rsil a15, "__stringify(LOCKLEVEL)"\n\t"
89 "l32i %0, %1, 0 \n\t"
90 "bne %0, %2, 1f \n\t"
91 "s32i %3, %1, 0 \n\t"
92 "1: \n\t"
93 "wsr a15, "__stringify(PS)" \n\t"
94 "rsync \n\t"
95 : "=&a" (old)
96 : "a" (p), "a" (old), "r" (new)
97 : "a15", "memory");
98 return old;
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)
108 switch (size) {
109 case 4: return __cmpxchg_u32(ptr, old, new);
110 default: __cmpxchg_called_with_bad_pointer();
111 return old;
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,
125 unsigned long old,
126 unsigned long new, int size)
128 switch (size) {
129 case 4:
130 return __cmpxchg_u32(ptr, old, new);
131 default:
132 return __cmpxchg_local_generic(ptr, old, new, size);
135 return old;
139 * cmpxchg_local and cmpxchg64_local are atomic wrt current CPU. Always make
140 * them available.
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))
148 * xchg_u32
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)
159 unsigned long tmp;
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"
164 "rsync \n\t"
165 : "=&a" (tmp)
166 : "a" (m), "a" (val)
167 : "a15", "memory");
168 return tmp;
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
176 * be dead anyway.
179 extern void __xchg_called_with_bad_pointer(void);
181 static __inline__ unsigned long
182 __xchg(unsigned long x, volatile void * ptr, int size)
184 switch (size) {
185 case 4:
186 return xchg_u32(ptr, x);
188 __xchg_called_with_bad_pointer();
189 return x;
192 extern void set_except_vector(int n, void *addr);
194 static inline void spill_registers(void)
196 unsigned int a0, ps;
198 __asm__ __volatile__ (
199 "movi a14," __stringify (PS_EXCM_BIT) " | 1\n\t"
200 "mov a12, a0\n\t"
201 "rsr a13," __stringify(SAR) "\n\t"
202 "xsr a14," __stringify(PS) "\n\t"
203 "movi a0, _spill_registers\n\t"
204 "rsync\n\t"
205 "callx0 a0\n\t"
206 "mov a0, a12\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 */