1 /* atomic.S: These things are too big to do inline.
3 * Copyright (C) 1999, 2007 2012 David S. Miller (davem@davemloft.net)
6 #include <linux/linkage.h>
8 #include <asm/backoff.h>
9 #include <asm/export.h>
13 /* Three versions of the atomic routines, one that
14 * does not return a value and does not perform
15 * memory barriers, and a two which return
16 * a value, the new and old value resp. and does the
20 #define ATOMIC_OP(op) \
21 ENTRY(atomic_##op) /* %o0 = increment, %o1 = atomic_ptr */ \
25 cas [%o1], %g1, %g7; \
27 bne,pn %icc, BACKOFF_LABEL(2f, 1b); \
31 2: BACKOFF_SPIN(%o2, %o3, 1b); \
32 ENDPROC(atomic_##op); \
33 EXPORT_SYMBOL(atomic_##op);
35 #define ATOMIC_OP_RETURN(op) \
36 ENTRY(atomic_##op##_return) /* %o0 = increment, %o1 = atomic_ptr */ \
40 cas [%o1], %g1, %g7; \
42 bne,pn %icc, BACKOFF_LABEL(2f, 1b); \
46 2: BACKOFF_SPIN(%o2, %o3, 1b); \
47 ENDPROC(atomic_##op##_return); \
48 EXPORT_SYMBOL(atomic_##op##_return);
50 #define ATOMIC_FETCH_OP(op) \
51 ENTRY(atomic_fetch_##op) /* %o0 = increment, %o1 = atomic_ptr */ \
55 cas [%o1], %g1, %g7; \
57 bne,pn %icc, BACKOFF_LABEL(2f, 1b); \
61 2: BACKOFF_SPIN(%o2, %o3, 1b); \
62 ENDPROC(atomic_fetch_##op); \
63 EXPORT_SYMBOL(atomic_fetch_##op);
82 #undef ATOMIC_FETCH_OP
83 #undef ATOMIC_OP_RETURN
86 #define ATOMIC64_OP(op) \
87 ENTRY(atomic64_##op) /* %o0 = increment, %o1 = atomic_ptr */ \
91 casx [%o1], %g1, %g7; \
93 bne,pn %xcc, BACKOFF_LABEL(2f, 1b); \
97 2: BACKOFF_SPIN(%o2, %o3, 1b); \
98 ENDPROC(atomic64_##op); \
99 EXPORT_SYMBOL(atomic64_##op);
101 #define ATOMIC64_OP_RETURN(op) \
102 ENTRY(atomic64_##op##_return) /* %o0 = increment, %o1 = atomic_ptr */ \
103 BACKOFF_SETUP(%o2); \
106 casx [%o1], %g1, %g7; \
108 bne,pn %xcc, BACKOFF_LABEL(2f, 1b); \
112 2: BACKOFF_SPIN(%o2, %o3, 1b); \
113 ENDPROC(atomic64_##op##_return); \
114 EXPORT_SYMBOL(atomic64_##op##_return);
116 #define ATOMIC64_FETCH_OP(op) \
117 ENTRY(atomic64_fetch_##op) /* %o0 = increment, %o1 = atomic_ptr */ \
118 BACKOFF_SETUP(%o2); \
121 casx [%o1], %g1, %g7; \
123 bne,pn %xcc, BACKOFF_LABEL(2f, 1b); \
127 2: BACKOFF_SPIN(%o2, %o3, 1b); \
128 ENDPROC(atomic64_fetch_##op); \
129 EXPORT_SYMBOL(atomic64_fetch_##op);
132 ATOMIC64_OP_RETURN(add)
133 ATOMIC64_FETCH_OP(add)
136 ATOMIC64_OP_RETURN(sub)
137 ATOMIC64_FETCH_OP(sub)
140 ATOMIC64_FETCH_OP(and)
143 ATOMIC64_FETCH_OP(or)
146 ATOMIC64_FETCH_OP(xor)
148 #undef ATOMIC64_FETCH_OP
149 #undef ATOMIC64_OP_RETURN
152 ENTRY(atomic64_dec_if_positive) /* %o0 = atomic_ptr */
159 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
163 2: BACKOFF_SPIN(%o2, %o3, 1b)
164 ENDPROC(atomic64_dec_if_positive)
165 EXPORT_SYMBOL(atomic64_dec_if_positive)