2 # SPDX-License-Identifier: GPL-2.0
4 ATOMICDIR=$(dirname $0)
6 . ${ATOMICDIR}/atomic-tbl.sh
8 #gen_template_fallback(template, meta, pfx, name, sfx, order, atomic, int, args...)
9 gen_template_fallback()
11 local template="$1"; shift
12 local meta="$1"; shift
14 local name="$1"; shift
16 local order="$1"; shift
17 local atomic="$1"; shift
20 local atomicname="arch_${atomic}_${pfx}${name}${sfx}${order}"
22 local ret="$(gen_ret_type "${meta}" "${int}")"
23 local retstmt="$(gen_ret_stmt "${meta}")"
24 local params="$(gen_params "${int}" "${atomic}" "$@")"
25 local args="$(gen_args "$@")"
27 if [ ! -z "${template}" ]; then
28 printf "#ifndef ${atomicname}\n"
30 printf "#define ${atomicname} ${atomicname}\n"
35 #gen_proto_fallback(meta, pfx, name, sfx, order, atomic, int, args...)
38 local meta="$1"; shift
40 local name="$1"; shift
42 local order="$1"; shift
44 local tmpl="$(find_fallback_template "${pfx}" "${name}" "${sfx}" "${order}")"
45 gen_template_fallback "${tmpl}" "${meta}" "${pfx}" "${name}" "${sfx}" "${order}" "$@"
48 #gen_basic_fallbacks(basename)
51 local basename="$1"; shift
53 #define ${basename}_acquire ${basename}
54 #define ${basename}_release ${basename}
55 #define ${basename}_relaxed ${basename}
59 gen_proto_order_variant()
61 local meta="$1"; shift
63 local name="$1"; shift
65 local order="$1"; shift
68 local basename="arch_${atomic}_${pfx}${name}${sfx}"
70 printf "#define ${basename}${order} ${basename}${order}\n"
73 #gen_proto_order_variants(meta, pfx, name, sfx, atomic, int, args...)
74 gen_proto_order_variants()
76 local meta="$1"; shift
78 local name="$1"; shift
82 local basename="arch_${atomic}_${pfx}${name}${sfx}"
84 local template="$(find_fallback_template "${pfx}" "${name}" "${sfx}" "${order}")"
86 # If we don't have relaxed atomics, then we don't bother with ordering fallbacks
87 # read_acquire and set_release need to be templated, though
88 if ! meta_has_relaxed "${meta}"; then
89 gen_proto_fallback "${meta}" "${pfx}" "${name}" "${sfx}" "" "$@"
91 if meta_has_acquire "${meta}"; then
92 gen_proto_fallback "${meta}" "${pfx}" "${name}" "${sfx}" "_acquire" "$@"
95 if meta_has_release "${meta}"; then
96 gen_proto_fallback "${meta}" "${pfx}" "${name}" "${sfx}" "_release" "$@"
102 printf "#ifndef ${basename}_relaxed\n"
104 if [ ! -z "${template}" ]; then
105 printf "#ifdef ${basename}\n"
108 gen_basic_fallbacks "${basename}"
110 if [ ! -z "${template}" ]; then
111 printf "#endif /* ${basename} */\n\n"
112 gen_proto_fallback "${meta}" "${pfx}" "${name}" "${sfx}" "" "$@"
113 gen_proto_fallback "${meta}" "${pfx}" "${name}" "${sfx}" "_acquire" "$@"
114 gen_proto_fallback "${meta}" "${pfx}" "${name}" "${sfx}" "_release" "$@"
115 gen_proto_fallback "${meta}" "${pfx}" "${name}" "${sfx}" "_relaxed" "$@"
118 printf "#else /* ${basename}_relaxed */\n\n"
120 gen_template_fallback "${ATOMICDIR}/fallbacks/acquire" "${meta}" "${pfx}" "${name}" "${sfx}" "_acquire" "$@"
121 gen_template_fallback "${ATOMICDIR}/fallbacks/release" "${meta}" "${pfx}" "${name}" "${sfx}" "_release" "$@"
122 gen_template_fallback "${ATOMICDIR}/fallbacks/fence" "${meta}" "${pfx}" "${name}" "${sfx}" "" "$@"
124 printf "#endif /* ${basename}_relaxed */\n\n"
127 gen_order_fallbacks()
129 local xchg="$1"; shift
133 #ifndef ${xchg}_acquire
134 #define ${xchg}_acquire(...) \\
135 __atomic_op_acquire(${xchg}, __VA_ARGS__)
138 #ifndef ${xchg}_release
139 #define ${xchg}_release(...) \\
140 __atomic_op_release(${xchg}, __VA_ARGS__)
144 #define ${xchg}(...) \\
145 __atomic_op_fence(${xchg}, __VA_ARGS__)
153 local xchg="$1"; shift
154 printf "#ifndef ${xchg}_relaxed\n"
156 gen_basic_fallbacks ${xchg}
158 printf "#else /* ${xchg}_relaxed */\n"
160 gen_order_fallbacks ${xchg}
162 printf "#endif /* ${xchg}_relaxed */\n\n"
165 gen_try_cmpxchg_fallback()
167 local cmpxchg="$1"; shift;
168 local order="$1"; shift;
171 #ifndef arch_try_${cmpxchg}${order}
172 #define arch_try_${cmpxchg}${order}(_ptr, _oldp, _new) \\
174 typeof(*(_ptr)) *___op = (_oldp), ___o = *___op, ___r; \\
175 ___r = arch_${cmpxchg}${order}((_ptr), ___o, (_new)); \\
176 if (unlikely(___r != ___o)) \\
178 likely(___r == ___o); \\
180 #endif /* arch_try_${cmpxchg}${order} */
185 gen_try_cmpxchg_fallbacks()
187 local cmpxchg="$1"; shift;
189 printf "#ifndef arch_try_${cmpxchg}_relaxed\n"
190 printf "#ifdef arch_try_${cmpxchg}\n"
192 gen_basic_fallbacks "arch_try_${cmpxchg}"
194 printf "#endif /* arch_try_${cmpxchg} */\n\n"
196 for order in "" "_acquire" "_release" "_relaxed"; do
197 gen_try_cmpxchg_fallback "${cmpxchg}" "${order}"
200 printf "#else /* arch_try_${cmpxchg}_relaxed */\n"
202 gen_order_fallbacks "arch_try_${cmpxchg}"
204 printf "#endif /* arch_try_${cmpxchg}_relaxed */\n\n"
208 // SPDX-License-Identifier: GPL-2.0
211 // DO NOT MODIFY THIS FILE DIRECTLY
213 #ifndef _LINUX_ATOMIC_FALLBACK_H
214 #define _LINUX_ATOMIC_FALLBACK_H
216 #include <linux/compiler.h>
220 for xchg in "arch_xchg" "arch_cmpxchg" "arch_cmpxchg64"; do
221 gen_xchg_fallbacks "${xchg}"
224 for cmpxchg in "cmpxchg" "cmpxchg64"; do
225 gen_try_cmpxchg_fallbacks "${cmpxchg}"
228 for cmpxchg in "cmpxchg_local" "cmpxchg64_local"; do
229 gen_try_cmpxchg_fallback "${cmpxchg}" ""
232 grep '^[a-z]' "$1" | while read name meta args; do
233 gen_proto "${meta}" "${name}" "atomic" "int" ${args}
237 #ifdef CONFIG_GENERIC_ATOMIC64
238 #include <asm-generic/atomic64.h>
243 grep '^[a-z]' "$1" | while read name meta args; do
244 gen_proto "${meta}" "${name}" "atomic64" "s64" ${args}
248 #endif /* _LINUX_ATOMIC_FALLBACK_H */