2 * xchg/cmpxchg operations for the Hexagon architecture
4 * Copyright (c) 2010-2011, The Linux Foundation. All rights reserved.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 and
9 * only version 2 as published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 #ifndef _ASM_CMPXCHG_H
23 #define _ASM_CMPXCHG_H
26 * __xchg - atomically exchange a register and a memory location
28 * @ptr: pointer to memory
29 * @size: size of the value
31 * Only 4 bytes supported currently.
33 * Note: there was an errata for V2 about .new's and memw_locked.
36 static inline unsigned long __xchg(unsigned long x
, volatile void *ptr
,
41 /* Can't seem to use printk or panic here, so just stop */
42 if (size
!= 4) do { asm volatile("brkpt;\n"); } while (1);
44 __asm__
__volatile__ (
45 "1: %0 = memw_locked(%1);\n" /* load into retval */
46 " memw_locked(%1,P0) = %2;\n" /* store into memory */
56 * Atomically swap the contents of a register with memory. Should be atomic
57 * between multiple CPU's and within interrupts on the same CPU.
59 #define xchg(ptr, v) ((__typeof__(*(ptr)))__xchg((unsigned long)(v), (ptr), \
63 * see rt-mutex-design.txt; cmpxchg supposedly checks if *ptr == A and swaps.
64 * looks just like atomic_cmpxchg on our arch currently with a bunch of
67 #define __HAVE_ARCH_CMPXCHG 1
69 #define cmpxchg(ptr, old, new) \
71 __typeof__(ptr) __ptr = (ptr); \
72 __typeof__(*(ptr)) __old = (old); \
73 __typeof__(*(ptr)) __new = (new); \
74 __typeof__(*(ptr)) __oldval = 0; \
77 "1: %0 = memw_locked(%1);\n" \
78 " { P0 = cmp.eq(%0,%2);\n" \
79 " if (!P0.new) jump:nt 2f; }\n" \
80 " memw_locked(%1,p0) = %3;\n" \
81 " if (!P0) jump 1b;\n" \
84 : "r" (__ptr), "r" (__old), "r" (__new) \
90 #endif /* _ASM_CMPXCHG_H */