1 #ifndef __ARCH_M68K_CMPXCHG__
2 #define __ARCH_M68K_CMPXCHG__
4 #include <linux/irqflags.h>
6 struct __xchg_dummy
{ unsigned long a
[100]; };
7 #define __xg(x) ((volatile struct __xchg_dummy *)(x))
9 extern unsigned long __invalid_xchg_size(unsigned long, volatile void *, int);
11 #ifndef CONFIG_RMW_INSNS
12 static inline unsigned long __xchg(unsigned long x
, volatile void * ptr
, int size
)
14 unsigned long flags
, tmp
;
16 local_irq_save(flags
);
35 tmp
= __invalid_xchg_size(x
, ptr
, size
);
39 local_irq_restore(flags
);
43 static inline unsigned long __xchg(unsigned long x
, volatile void * ptr
, int size
)
52 : "=&d" (x
) : "d" (x
), "m" (*__xg(ptr
)) : "memory");
60 : "=&d" (x
) : "d" (x
), "m" (*__xg(ptr
)) : "memory");
68 : "=&d" (x
) : "d" (x
), "m" (*__xg(ptr
)) : "memory");
71 x
= __invalid_xchg_size(x
, ptr
, size
);
78 #define xchg(ptr,x) ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
80 #include <asm-generic/cmpxchg-local.h>
82 #define cmpxchg64_local(ptr, o, n) __cmpxchg64_local_generic((ptr), (o), (n))
84 extern unsigned long __invalid_cmpxchg_size(volatile void *,
85 unsigned long, unsigned long, int);
88 * Atomic compare and exchange. Compare OLD with MEM, if identical,
89 * store NEW in MEM. Return the initial value in MEM. Success is
90 * indicated by comparing RETURN with OLD.
92 #ifdef CONFIG_RMW_INSNS
94 static inline unsigned long __cmpxchg(volatile void *p
, unsigned long old
,
95 unsigned long new, int size
)
99 __asm__
__volatile__ ("casb %0,%2,%1"
100 : "=d" (old
), "=m" (*(char *)p
)
101 : "d" (new), "0" (old
), "m" (*(char *)p
));
104 __asm__
__volatile__ ("casw %0,%2,%1"
105 : "=d" (old
), "=m" (*(short *)p
)
106 : "d" (new), "0" (old
), "m" (*(short *)p
));
109 __asm__
__volatile__ ("casl %0,%2,%1"
110 : "=d" (old
), "=m" (*(int *)p
)
111 : "d" (new), "0" (old
), "m" (*(int *)p
));
114 old
= __invalid_cmpxchg_size(p
, old
, new, size
);
120 #define cmpxchg(ptr, o, n) \
121 ((__typeof__(*(ptr)))__cmpxchg((ptr), (unsigned long)(o), \
122 (unsigned long)(n), sizeof(*(ptr))))
123 #define cmpxchg_local(ptr, o, n) \
124 ((__typeof__(*(ptr)))__cmpxchg((ptr), (unsigned long)(o), \
125 (unsigned long)(n), sizeof(*(ptr))))
127 #define cmpxchg64(ptr, o, n) cmpxchg64_local((ptr), (o), (n))
132 * cmpxchg_local and cmpxchg64_local are atomic wrt current CPU. Always make
135 #define cmpxchg_local(ptr, o, n) \
136 ((__typeof__(*(ptr)))__cmpxchg_local_generic((ptr), (unsigned long)(o),\
137 (unsigned long)(n), sizeof(*(ptr))))
139 #include <asm-generic/cmpxchg.h>
143 #endif /* __ARCH_M68K_CMPXCHG__ */