1 /* Atomic instructions for userspace.
3 * The actual implementations can be found in the kernel.
5 * Copyright (c) 2008 Analog Devices, Inc.
7 * Licensed under the LGPL v2.1.
10 #ifndef __BFIN_FIXED_CODE_H__
11 #define __BFIN_FIXED_CODE_H__
15 #include <asm/fixed_code.h>
20 uint32_t bfin_atomic_xchg32(uint32_t *__bfin_ptr, uint32_t __bfin_newval)
23 /* Input: P0: memory address to use
25 * Output: R0: old contents of the memory address
28 "CALL (%[__bfin_func])"
29 : "=q0" (__bfin_ret), "=m" (*__bfin_ptr)
30 : [__bfin_func] "a" (ATOMIC_XCHG32), "q1" (__bfin_newval),
31 "qA" (__bfin_ptr), "m" (*__bfin_ptr)
38 uint32_t bfin_atomic_cas32(uint32_t *__bfin_ptr, uint32_t __bfin_exp, uint32_t __bfin_newval)
41 /* Input: P0: memory address to use
43 * R2: new value to store
44 * Output: R0: old contents of the memory address
47 "CALL (%[__bfin_func])"
48 : "=q0" (__bfin_ret), "=m" (*__bfin_ptr)
49 : [__bfin_func] "a" (ATOMIC_CAS32), "q1" (__bfin_exp), "q2" (__bfin_newval),
50 "qA" (__bfin_ptr), "m" (*__bfin_ptr)
57 uint32_t bfin_atomic_add32(uint32_t *__bfin_ptr, uint32_t __bfin_inc)
60 /* Input: P0: memory address to use
62 * Output: R0: new contents of the memory address
63 * R1: previous contents of the memory address
66 "CALL (%[__bfin_func])"
67 : "=q0" (__bfin_ret), "=m" (*__bfin_ptr)
68 : [__bfin_func] "a" (ATOMIC_ADD32), "q0" (__bfin_inc),
69 "qA" (__bfin_ptr), "m" (*__bfin_ptr)
70 : "R1", "RETS", "memory"
74 #define bfin_atomic_inc32(ptr) bfin_atomic_add32(ptr, 1)
77 uint32_t bfin_atomic_sub32(uint32_t *__bfin_ptr, uint32_t __bfin_dec)
80 /* Input: P0: memory address to use
81 * R0: value to subtract
82 * Output: R0: new contents of the memory address
83 * R1: previous contents of the memory address
86 "CALL (%[__bfin_func])"
87 : "=q0" (__bfin_ret), "=m" (*__bfin_ptr)
88 : [__bfin_func] "a" (ATOMIC_SUB32), "q0" (__bfin_dec),
89 "qA" (__bfin_ptr), "m" (*__bfin_ptr)
90 : "R1", "RETS", "memory"
94 #define bfin_atomic_dec32(ptr) bfin_atomic_sub32(ptr, 1)
97 uint32_t bfin_atomic_ior32(uint32_t *__bfin_ptr, uint32_t __bfin_ior)
100 /* Input: P0: memory address to use
102 * Output: R0: new contents of the memory address
103 * R1: previous contents of the memory address
105 __asm__ __volatile__(
106 "CALL (%[__bfin_func])"
107 : "=q0" (__bfin_ret), "=m" (*__bfin_ptr)
108 : [__bfin_func] "a" (ATOMIC_IOR32), "q0" (__bfin_ior),
109 "qA" (__bfin_ptr), "m" (*__bfin_ptr)
110 : "R1", "RETS", "memory"
116 uint32_t bfin_atomic_and32(uint32_t *__bfin_ptr, uint32_t __bfin_and)
119 /* Input: P0: memory address to use
121 * Output: R0: new contents of the memory address
122 * R1: previous contents of the memory address
124 __asm__ __volatile__(
125 "CALL (%[__bfin_func])"
126 : "=q0" (__bfin_ret), "=m" (*__bfin_ptr)
127 : [__bfin_func] "a" (ATOMIC_AND32), "q0" (__bfin_and),
128 "qA" (__bfin_ptr), "m" (*__bfin_ptr)
129 : "R1", "RETS", "memory"
135 uint32_t bfin_atomic_xor32(uint32_t *__bfin_ptr, uint32_t __bfin_xor)
138 /* Input: P0: memory address to use
140 * Output: R0: new contents of the memory address
141 * R1: previous contents of the memory address
143 __asm__ __volatile__(
144 "CALL (%[__bfin_func])"
145 : "=q0" (__bfin_ret), "=m" (*__bfin_ptr)
146 : [__bfin_func] "a" (ATOMIC_XOR32), "q0" (__bfin_xor),
147 "qA" (__bfin_ptr), "m" (*__bfin_ptr)
148 : "R1", "RETS", "memory"