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

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

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ 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.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /* SPDX-License-Identifier: GPL-2.0-only */
  2 /*
  3  * xchg/cmpxchg operations for the Hexagon architecture
  4  *
  5  * Copyright (c) 2010-2011, The Linux Foundation. All rights reserved.
  6  */
  7 
  8 #ifndef _ASM_CMPXCHG_H
  9 #define _ASM_CMPXCHG_H
 10 
 11 /*
 12  * __arch_xchg - atomically exchange a register and a memory location
 13  * @x: value to swap
 14  * @ptr: pointer to memory
 15  * @size:  size of the value
 16  *
 17  * Only 4 bytes supported currently.
 18  *
 19  * Note:  there was an errata for V2 about .new's and memw_locked.
 20  *
 21  */
 22 static inline unsigned long
 23 __arch_xchg(unsigned long x, volatile void *ptr, int size)
 24 {
 25         unsigned long retval;
 26 
 27         /*  Can't seem to use printk or panic here, so just stop  */
 28         if (size != 4) do { asm volatile("brkpt;\n"); } while (1);
 29 
 30         __asm__ __volatile__ (
 31         "1:     %0 = memw_locked(%1);\n"    /*  load into retval */
 32         "       memw_locked(%1,P0) = %2;\n" /*  store into memory */
 33         "       if (!P0) jump 1b;\n"
 34         : "=&r" (retval)
 35         : "r" (ptr), "r" (x)
 36         : "memory", "p0"
 37         );
 38         return retval;
 39 }
 40 
 41 /*
 42  * Atomically swap the contents of a register with memory.  Should be atomic
 43  * between multiple CPU's and within interrupts on the same CPU.
 44  */
 45 #define arch_xchg(ptr, v) ((__typeof__(*(ptr)))__arch_xchg((unsigned long)(v), (ptr), \
 46                                                            sizeof(*(ptr))))
 47 
 48 /*
 49  *  see rt-mutex-design.txt; cmpxchg supposedly checks if *ptr == A and swaps.
 50  *  looks just like atomic_cmpxchg on our arch currently with a bunch of
 51  *  variable casting.
 52  */
 53 
 54 #define arch_cmpxchg(ptr, old, new)                             \
 55 ({                                                              \
 56         __typeof__(ptr) __ptr = (ptr);                          \
 57         __typeof__(*(ptr)) __old = (old);                       \
 58         __typeof__(*(ptr)) __new = (new);                       \
 59         __typeof__(*(ptr)) __oldval = 0;                        \
 60                                                                 \
 61         asm volatile(                                           \
 62                 "1:     %0 = memw_locked(%1);\n"                \
 63                 "       { P0 = cmp.eq(%0,%2);\n"                \
 64                 "         if (!P0.new) jump:nt 2f; }\n"         \
 65                 "       memw_locked(%1,p0) = %3;\n"             \
 66                 "       if (!P0) jump 1b;\n"                    \
 67                 "2:\n"                                          \
 68                 : "=&r" (__oldval)                              \
 69                 : "r" (__ptr), "r" (__old), "r" (__new)         \
 70                 : "memory", "p0"                                \
 71         );                                                      \
 72         __oldval;                                               \
 73 })
 74 
 75 #endif /* _ASM_CMPXCHG_H */
 76 

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