2 * Copyright 2011 Tilera Corporation. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
11 * NON INFRINGEMENT. See the GNU General Public License for
14 * Atomically access user memory, but use MMU to avoid propagating
18 #include <linux/linkage.h>
19 #include <asm/errno.h>
20 #include <asm/futex.h>
22 #include <asm/processor.h>
25 * Provide a set of atomic memory operations supporting <asm/futex.h>.
27 * r0: user address to manipulate
28 * r1: new value to write, or for cmpxchg, old value to compare against
29 * r2: (cmpxchg only) new value to write
31 * Return __get_user struct, r0 with value, r1 with error.
33 #define FUTEX_OP(name, ...) \
34 STD_ENTRY(futex_##name) \
40 STD_ENDPROC(futex_##name); \
41 .pushsection __ex_table,"a"; \
42 .quad 1b, get_user_fault; \
45 .pushsection .fixup,"ax"
47 { movei r1, -EFAULT; jrp lr }
48 ENDPROC(get_user_fault)
51 FUTEX_OP(cmpxchg, mtspr CMPEXCH_VALUE, r1; 1: cmpexch4 r0, r0, r2)
52 FUTEX_OP(set, 1: exch4 r0, r0, r1)
53 FUTEX_OP(add, 1: fetchadd4 r0, r0, r1)
54 FUTEX_OP(or, 1: fetchor4 r0, r0, r1)
55 FUTEX_OP(andn, nor r1, r1, zero; 1: fetchand4 r0, r0, r1)