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

TOMOYO Linux Cross Reference
Linux/arch/parisc/include/asm/cmpxchg.h

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ 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 /*
  3  * forked from parisc asm/atomic.h which was:
  4  *      Copyright (C) 2000 Philipp Rumpf <prumpf@tux.org>
  5  *      Copyright (C) 2006 Kyle McMartin <kyle@parisc-linux.org>
  6  */
  7 
  8 #ifndef _ASM_PARISC_CMPXCHG_H_
  9 #define _ASM_PARISC_CMPXCHG_H_
 10 
 11 /* This should get optimized out since it's never called.
 12 ** Or get a link error if xchg is used "wrong".
 13 */
 14 extern void __xchg_called_with_bad_pointer(void);
 15 
 16 /* __xchg32/64 defined in arch/parisc/lib/bitops.c */
 17 extern unsigned long __xchg8(char, volatile char *);
 18 extern unsigned long __xchg32(int, volatile int *);
 19 #ifdef CONFIG_64BIT
 20 extern unsigned long __xchg64(unsigned long, volatile unsigned long *);
 21 #endif
 22 
 23 /* optimizer better get rid of switch since size is a constant */
 24 static inline unsigned long
 25 __arch_xchg(unsigned long x, volatile void *ptr, int size)
 26 {
 27         switch (size) {
 28 #ifdef CONFIG_64BIT
 29         case 8: return __xchg64(x, (volatile unsigned long *) ptr);
 30 #endif
 31         case 4: return __xchg32((int) x, (volatile int *) ptr);
 32         case 1: return __xchg8((char) x, (volatile char *) ptr);
 33         }
 34         __xchg_called_with_bad_pointer();
 35         return x;
 36 }
 37 
 38 /*
 39 ** REVISIT - Abandoned use of LDCW in xchg() for now:
 40 ** o need to test sizeof(*ptr) to avoid clearing adjacent bytes
 41 ** o and while we are at it, could CONFIG_64BIT code use LDCD too?
 42 **
 43 **      if (__builtin_constant_p(x) && (x == NULL))
 44 **              if (((unsigned long)p & 0xf) == 0)
 45 **                      return __ldcw(p);
 46 */
 47 #define arch_xchg(ptr, x)                                               \
 48 ({                                                                      \
 49         __typeof__(*(ptr)) __ret;                                       \
 50         __typeof__(*(ptr)) _x_ = (x);                                   \
 51         __ret = (__typeof__(*(ptr)))                                    \
 52                 __arch_xchg((unsigned long)_x_, (ptr), sizeof(*(ptr))); \
 53         __ret;                                                          \
 54 })
 55 
 56 /* bug catcher for when unsupported size is used - won't link */
 57 extern void __cmpxchg_called_with_bad_pointer(void);
 58 
 59 /* __cmpxchg_u... defined in arch/parisc/lib/bitops.c */
 60 extern u8 __cmpxchg_u8(volatile u8 *ptr, u8 old, u8 new_);
 61 extern u16 __cmpxchg_u16(volatile u16 *ptr, u16 old, u16 new_);
 62 extern u32 __cmpxchg_u32(volatile u32 *m, u32 old, u32 new_);
 63 extern u64 __cmpxchg_u64(volatile u64 *ptr, u64 old, u64 new_);
 64 
 65 /* don't worry...optimizer will get rid of most of this */
 66 static inline unsigned long
 67 __cmpxchg(volatile void *ptr, unsigned long old, unsigned long new_, int size)
 68 {
 69         return
 70 #ifdef CONFIG_64BIT
 71                 size == 8 ? __cmpxchg_u64(ptr, old, new_) :
 72 #endif
 73                 size == 4 ? __cmpxchg_u32(ptr, old, new_) :
 74                 size == 2 ? __cmpxchg_u16(ptr, old, new_) :
 75                 size == 1 ? __cmpxchg_u8(ptr, old, new_) :
 76                         (__cmpxchg_called_with_bad_pointer(), old);
 77 }
 78 
 79 #define arch_cmpxchg(ptr, o, n)                                          \
 80 ({                                                                       \
 81         __typeof__(*(ptr)) _o_ = (o);                                    \
 82         __typeof__(*(ptr)) _n_ = (n);                                    \
 83         (__typeof__(*(ptr))) __cmpxchg((ptr), (unsigned long)_o_,        \
 84                                     (unsigned long)_n_, sizeof(*(ptr))); \
 85 })
 86 
 87 #include <asm-generic/cmpxchg-local.h>
 88 
 89 static inline unsigned long __cmpxchg_local(volatile void *ptr,
 90                                       unsigned long old,
 91                                       unsigned long new_, int size)
 92 {
 93         switch (size) {
 94 #ifdef CONFIG_64BIT
 95         case 8: return __cmpxchg_u64((u64 *)ptr, old, new_);
 96 #endif
 97         case 4: return __cmpxchg_u32(ptr, old, new_);
 98         default:
 99                 return __generic_cmpxchg_local(ptr, old, new_, size);
100         }
101 }
102 
103 /*
104  * cmpxchg_local and cmpxchg64_local are atomic wrt current CPU. Always make
105  * them available.
106  */
107 #define arch_cmpxchg_local(ptr, o, n)                                   \
108         ((__typeof__(*(ptr)))__cmpxchg_local((ptr), (unsigned long)(o), \
109                         (unsigned long)(n), sizeof(*(ptr))))
110 #ifdef CONFIG_64BIT
111 #define arch_cmpxchg64_local(ptr, o, n)                                 \
112 ({                                                                      \
113         BUILD_BUG_ON(sizeof(*(ptr)) != 8);                              \
114         cmpxchg_local((ptr), (o), (n));                                 \
115 })
116 #else
117 #define arch_cmpxchg64_local(ptr, o, n) __generic_cmpxchg64_local((ptr), (o), (n))
118 #endif
119 
120 #define arch_cmpxchg64(ptr, o, n) __cmpxchg_u64(ptr, o, n)
121 
122 #endif /* _ASM_PARISC_CMPXCHG_H_ */
123 

~ [ 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