1 /* SPDX-License-Identifier: GPL-2.0 */ 1 2 /* 32-bit atomic xchg() and cmpxchg() definiti 3 * 4 * Copyright (C) 1996 David S. Miller (davem@d 5 * Copyright (C) 2000 Anton Blanchard (anton@l 6 * Copyright (C) 2007 Kyle McMartin (kyle@pari 7 * 8 * Additions by Keith M Wesolowski (wesolows@f 9 * on asm-parisc/atomic.h Copyright (C) 2000 P 10 */ 11 12 #ifndef __ARCH_SPARC_CMPXCHG__ 13 #define __ARCH_SPARC_CMPXCHG__ 14 15 unsigned long __xchg_u32(volatile u32 *m, u32 16 void __xchg_called_with_bad_pointer(void); 17 18 static __always_inline unsigned long __arch_xc 19 { 20 switch (size) { 21 case 4: 22 return __xchg_u32(ptr, x); 23 } 24 __xchg_called_with_bad_pointer(); 25 return x; 26 } 27 28 #define arch_xchg(ptr,x) ({(__typeof__(*(ptr)) 29 30 /* Emulate cmpxchg() the same way we emulate a 31 * by hashing the object address and indexing 32 * of spinlocks to get a bit of performance... 33 * 34 * See arch/sparc/lib/atomic32.c for implement 35 * 36 * Cribbed from <asm-parisc/atomic.h> 37 */ 38 39 /* bug catcher for when unsupported size is us 40 void __cmpxchg_called_with_bad_pointer(void); 41 u8 __cmpxchg_u8(volatile u8 *m, u8 old, u8 new 42 u16 __cmpxchg_u16(volatile u16 *m, u16 old, u1 43 u32 __cmpxchg_u32(volatile u32 *m, u32 old, u3 44 45 /* don't worry...optimizer will get rid of mos 46 static inline unsigned long 47 __cmpxchg(volatile void *ptr, unsigned long ol 48 { 49 return 50 size == 1 ? __cmpxchg_u8(ptr, 51 size == 2 ? __cmpxchg_u16(ptr, 52 size == 4 ? __cmpxchg_u32(ptr, 53 (__cmpxchg_called_with 54 } 55 56 #define arch_cmpxchg(ptr, o, n) 57 ({ 58 __typeof__(*(ptr)) _o_ = (o); 59 __typeof__(*(ptr)) _n_ = (n); 60 (__typeof__(*(ptr))) __cmpxchg((ptr), 61 (unsigned long)_n_, si 62 }) 63 64 u64 __cmpxchg_u64(volatile u64 *ptr, u64 old, 65 #define arch_cmpxchg64(ptr, old, new) __cmpx 66 67 #include <asm-generic/cmpxchg-local.h> 68 69 /* 70 * cmpxchg_local and cmpxchg64_local are atomi 71 * them available. 72 */ 73 #define arch_cmpxchg_local(ptr, o, n) 74 ((__typeof__(*(ptr)))__generic_cmpxchg 75 (unsigned long)(n), si 76 #define arch_cmpxchg64_local(ptr, o, n) __gene 77 78 #endif /* __ARCH_SPARC_CMPXCHG__ */ 79
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.