summaryrefslogtreecommitdiff
path: root/arch/sh/include/asm/cmpxchg-grb.h
diff options
context:
space:
mode:
authorMichael S. Tsirkin <mst@redhat.com>2016-01-07 17:54:54 +0200
committerMichael S. Tsirkin <mst@redhat.com>2016-01-12 20:47:01 +0200
commit3226aad81aa670015a59e51458a0deb2d3bcb600 (patch)
tree0cc2ab0abf363ad3f851fdcb14c0f7c1386e89de /arch/sh/include/asm/cmpxchg-grb.h
parenta65961272e1ebdb60804bbe2bb440481fcbd1c76 (diff)
sh: support 1 and 2 byte xchg
This completes the xchg implementation for sh architecture. Note: The llsc variant is tricky since this only supports 4 byte atomics, the existing implementation of 1 byte xchg is wrong: we need to do a 4 byte cmpxchg and retry if any bytes changed meanwhile. Write this in C for clarity. Suggested-by: Rich Felker <dalias@libc.org> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Diffstat (limited to 'arch/sh/include/asm/cmpxchg-grb.h')
-rw-r--r--arch/sh/include/asm/cmpxchg-grb.h22
1 files changed, 22 insertions, 0 deletions
diff --git a/arch/sh/include/asm/cmpxchg-grb.h b/arch/sh/include/asm/cmpxchg-grb.h
index f848dec9e483..2ed557b31bd9 100644
--- a/arch/sh/include/asm/cmpxchg-grb.h
+++ b/arch/sh/include/asm/cmpxchg-grb.h
@@ -23,6 +23,28 @@ static inline unsigned long xchg_u32(volatile u32 *m, unsigned long val)
return retval;
}
+static inline unsigned long xchg_u16(volatile u16 *m, unsigned long val)
+{
+ unsigned long retval;
+
+ __asm__ __volatile__ (
+ " .align 2 \n\t"
+ " mova 1f, r0 \n\t" /* r0 = end point */
+ " mov r15, r1 \n\t" /* r1 = saved sp */
+ " mov #-6, r15 \n\t" /* LOGIN */
+ " mov.w @%1, %0 \n\t" /* load old value */
+ " extu.w %0, %0 \n\t" /* extend as unsigned */
+ " mov.w %2, @%1 \n\t" /* store new value */
+ "1: mov r1, r15 \n\t" /* LOGOUT */
+ : "=&r" (retval),
+ "+r" (m),
+ "+r" (val) /* inhibit r15 overloading */
+ :
+ : "memory" , "r0", "r1");
+
+ return retval;
+}
+
static inline unsigned long xchg_u8(volatile u8 *m, unsigned long val)
{
unsigned long retval;