~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/sparc/include/asm/cmpxchg_32.h

Version: ~ [ linux-6.11-rc3 ] ~ [ linux-6.10.4 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.45 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.104 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.164 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.223 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.281 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.319 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /* SPDX-License-Identifier: GPL-2.0 */
  2 /* 32-bit atomic xchg() and cmpxchg() definitions.
  3  *
  4  * Copyright (C) 1996 David S. Miller (davem@davemloft.net)
  5  * Copyright (C) 2000 Anton Blanchard (anton@linuxcare.com.au)
  6  * Copyright (C) 2007 Kyle McMartin (kyle@parisc-linux.org)
  7  *
  8  * Additions by Keith M Wesolowski (wesolows@foobazco.org) based
  9  * on asm-parisc/atomic.h Copyright (C) 2000 Philipp Rumpf <prumpf@tux.org>.
 10  */
 11 
 12 #ifndef __ARCH_SPARC_CMPXCHG__
 13 #define __ARCH_SPARC_CMPXCHG__
 14 
 15 unsigned long __xchg_u32(volatile u32 *m, u32 new);
 16 void __xchg_called_with_bad_pointer(void);
 17 
 18 static __always_inline unsigned long __arch_xchg(unsigned long x, __volatile__ void * ptr, int size)
 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)))__arch_xchg((unsigned long)(x),(ptr),sizeof(*(ptr)));})
 29 
 30 /* Emulate cmpxchg() the same way we emulate atomics,
 31  * by hashing the object address and indexing into an array
 32  * of spinlocks to get a bit of performance...
 33  *
 34  * See arch/sparc/lib/atomic32.c for implementation.
 35  *
 36  * Cribbed from <asm-parisc/atomic.h>
 37  */
 38 
 39 /* bug catcher for when unsupported size is used - won't link */
 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, u16 new_);
 43 u32 __cmpxchg_u32(volatile u32 *m, u32 old, u32 new_);
 44 
 45 /* don't worry...optimizer will get rid of most of this */
 46 static inline unsigned long
 47 __cmpxchg(volatile void *ptr, unsigned long old, unsigned long new_, int size)
 48 {
 49         return
 50                 size == 1 ? __cmpxchg_u8(ptr, old, new_) :
 51                 size == 2 ? __cmpxchg_u16(ptr, old, new_) :
 52                 size == 4 ? __cmpxchg_u32(ptr, old, new_) :
 53                         (__cmpxchg_called_with_bad_pointer(), old);
 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), (unsigned long)_o_,       \
 61                         (unsigned long)_n_, sizeof(*(ptr)));            \
 62 })
 63 
 64 u64 __cmpxchg_u64(volatile u64 *ptr, u64 old, u64 new);
 65 #define arch_cmpxchg64(ptr, old, new)   __cmpxchg_u64(ptr, old, new)
 66 
 67 #include <asm-generic/cmpxchg-local.h>
 68 
 69 /*
 70  * cmpxchg_local and cmpxchg64_local are atomic wrt current CPU. Always make
 71  * them available.
 72  */
 73 #define arch_cmpxchg_local(ptr, o, n)                                          \
 74         ((__typeof__(*(ptr)))__generic_cmpxchg_local((ptr), (unsigned long)(o),\
 75                         (unsigned long)(n), sizeof(*(ptr))))
 76 #define arch_cmpxchg64_local(ptr, o, n) __generic_cmpxchg64_local((ptr), (o), (n))
 77 
 78 #endif /* __ARCH_SPARC_CMPXCHG__ */
 79 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php