2 * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
8 * Vineetg: August 2010: From Android kernel work
14 #include <linux/futex.h>
15 #include <linux/preempt.h>
16 #include <linux/uaccess.h>
17 #include <asm/errno.h>
19 #ifdef CONFIG_ARC_HAS_LLSC
21 #define __futex_atomic_op(insn, ret, oldval, uaddr, oparg)\
24 __asm__ __volatile__( \
25 "1: llock %1, [%2] \n" \
27 "2: scond %0, [%2] \n" \
31 " .section .fixup,\"ax\" \n" \
36 " .section __ex_table,\"a\" \n" \
42 : "=&r" (ret), "=&r" (oldval) \
43 : "r" (uaddr), "r" (oparg), "ir" (-EFAULT) \
47 #else /* !CONFIG_ARC_HAS_LLSC */
49 #define __futex_atomic_op(insn, ret, oldval, uaddr, oparg)\
52 __asm__ __volatile__( \
58 " .section .fixup,\"ax\" \n" \
63 " .section __ex_table,\"a\" \n" \
69 : "=&r" (ret), "=&r" (oldval) \
70 : "r" (uaddr), "r" (oparg), "ir" (-EFAULT) \
76 static inline int arch_futex_atomic_op_inuser(int op
, int oparg
, int *oval
,
81 #ifndef CONFIG_ARC_HAS_LLSC
82 preempt_disable(); /* to guarantee atomic r-m-w of futex op */
88 __futex_atomic_op("mov %0, %3", ret
, oldval
, uaddr
, oparg
);
91 /* oldval = *uaddr; *uaddr += oparg ; ret = *uaddr */
92 __futex_atomic_op("add %0, %1, %3", ret
, oldval
, uaddr
, oparg
);
95 __futex_atomic_op("or %0, %1, %3", ret
, oldval
, uaddr
, oparg
);
98 __futex_atomic_op("bic %0, %1, %3", ret
, oldval
, uaddr
, oparg
);
101 __futex_atomic_op("xor %0, %1, %3", ret
, oldval
, uaddr
, oparg
);
108 #ifndef CONFIG_ARC_HAS_LLSC
119 * cmpxchg of futex (pagefaults disabled by caller)
120 * Return 0 for success, -EFAULT otherwise
123 futex_atomic_cmpxchg_inatomic(u32
*uval
, u32 __user
*uaddr
, u32 expval
,
129 if (!access_ok(uaddr
, sizeof(u32
)))
132 #ifndef CONFIG_ARC_HAS_LLSC
133 preempt_disable(); /* to guarantee atomic r-m-w of futex op */
137 __asm__
__volatile__(
138 #ifdef CONFIG_ARC_HAS_LLSC
139 "1: llock %1, [%4] \n"
140 " brne %1, %2, 3f \n"
141 "2: scond %3, [%4] \n"
145 " brne %1, %2, 3f \n"
149 " .section .fixup,\"ax\" \n"
153 " .section __ex_table,\"a\" \n"
158 : "+&r"(ret
), "=&r"(existval
)
159 : "r"(expval
), "r"(newval
), "r"(uaddr
), "ir"(-EFAULT
)
164 #ifndef CONFIG_ARC_HAS_LLSC