2 # SPDX-License-Identifier: GPL-2.0
4 ATOMICDIR
=$
(dirname $0)
7 .
${ATOMICDIR}/atomic-tbl.sh
9 #gen_template_fallback(template, meta, pfx, name, sfx, order, arch, atomic, int, args...)
10 gen_template_fallback
()
12 local template
="$1"; shift
13 local meta
="$1"; shift
15 local name
="$1"; shift
17 local order
="$1"; shift
18 local arch
="$1"; shift
19 local atomic
="$1"; shift
22 local atomicname
="${arch}${atomic}_${pfx}${name}${sfx}${order}"
24 local ret
="$(gen_ret_type "${meta}" "${int}")"
25 local retstmt
="$(gen_ret_stmt "${meta}")"
26 local params
="$(gen_params "${int}" "${atomic}" "$@
")"
27 local args
="$(gen_args "$@
")"
29 if [ ! -z "${template}" ]; then
30 printf "#ifndef ${atomicname}\n"
32 printf "#define ${atomicname} ${atomicname}\n"
37 #gen_proto_fallback(meta, pfx, name, sfx, order, arch, atomic, int, args...)
40 local meta
="$1"; shift
42 local name
="$1"; shift
44 local order
="$1"; shift
46 local tmpl
="$(find_fallback_template "${pfx}" "${name}" "${sfx}" "${order}")"
47 gen_template_fallback
"${tmpl}" "${meta}" "${pfx}" "${name}" "${sfx}" "${order}" "$@"
50 #gen_basic_fallbacks(basename)
53 local basename="$1"; shift
55 #define ${basename}_acquire ${basename}
56 #define ${basename}_release ${basename}
57 #define ${basename}_relaxed ${basename}
61 gen_proto_order_variant
()
63 local meta
="$1"; shift
65 local name
="$1"; shift
67 local order
="$1"; shift
71 local basename="${arch}${atomic}_${pfx}${name}${sfx}"
73 printf "#define arch_${basename}${order} ${basename}${order}\n"
76 #gen_proto_order_variants(meta, pfx, name, sfx, arch, atomic, int, args...)
77 gen_proto_order_variants
()
79 local meta
="$1"; shift
81 local name
="$1"; shift
86 local basename="${arch}${atomic}_${pfx}${name}${sfx}"
88 local template
="$(find_fallback_template "${pfx}" "${name}" "${sfx}" "${order}")"
90 if [ -z "$arch" ]; then
91 gen_proto_order_variant
"${meta}" "${pfx}" "${name}" "${sfx}" "" "$@"
93 if meta_has_acquire
"${meta}"; then
94 gen_proto_order_variant
"${meta}" "${pfx}" "${name}" "${sfx}" "_acquire" "$@"
96 if meta_has_release
"${meta}"; then
97 gen_proto_order_variant
"${meta}" "${pfx}" "${name}" "${sfx}" "_release" "$@"
99 if meta_has_relaxed
"${meta}"; then
100 gen_proto_order_variant
"${meta}" "${pfx}" "${name}" "${sfx}" "_relaxed" "$@"
106 # If we don't have relaxed atomics, then we don't bother with ordering fallbacks
107 # read_acquire and set_release need to be templated, though
108 if ! meta_has_relaxed
"${meta}"; then
109 gen_proto_fallback
"${meta}" "${pfx}" "${name}" "${sfx}" "" "$@"
111 if meta_has_acquire
"${meta}"; then
112 gen_proto_fallback
"${meta}" "${pfx}" "${name}" "${sfx}" "_acquire" "$@"
115 if meta_has_release
"${meta}"; then
116 gen_proto_fallback
"${meta}" "${pfx}" "${name}" "${sfx}" "_release" "$@"
122 printf "#ifndef ${basename}_relaxed\n"
124 if [ ! -z "${template}" ]; then
125 printf "#ifdef ${basename}\n"
128 gen_basic_fallbacks
"${basename}"
130 if [ ! -z "${template}" ]; then
131 printf "#endif /* ${arch}${atomic}_${pfx}${name}${sfx} */\n\n"
132 gen_proto_fallback
"${meta}" "${pfx}" "${name}" "${sfx}" "" "$@"
133 gen_proto_fallback
"${meta}" "${pfx}" "${name}" "${sfx}" "_acquire" "$@"
134 gen_proto_fallback
"${meta}" "${pfx}" "${name}" "${sfx}" "_release" "$@"
135 gen_proto_fallback
"${meta}" "${pfx}" "${name}" "${sfx}" "_relaxed" "$@"
138 printf "#else /* ${basename}_relaxed */\n\n"
140 gen_template_fallback
"${ATOMICDIR}/fallbacks/acquire" "${meta}" "${pfx}" "${name}" "${sfx}" "_acquire" "$@"
141 gen_template_fallback
"${ATOMICDIR}/fallbacks/release" "${meta}" "${pfx}" "${name}" "${sfx}" "_release" "$@"
142 gen_template_fallback
"${ATOMICDIR}/fallbacks/fence" "${meta}" "${pfx}" "${name}" "${sfx}" "" "$@"
144 printf "#endif /* ${basename}_relaxed */\n\n"
147 gen_order_fallbacks
()
149 local xchg
="$1"; shift
153 #ifndef ${xchg}_acquire
154 #define ${xchg}_acquire(...) \\
155 __atomic_op_acquire(${xchg}, __VA_ARGS__)
158 #ifndef ${xchg}_release
159 #define ${xchg}_release(...) \\
160 __atomic_op_release(${xchg}, __VA_ARGS__)
164 #define ${xchg}(...) \\
165 __atomic_op_fence(${xchg}, __VA_ARGS__)
173 local xchg
="$1"; shift
174 printf "#ifndef ${xchg}_relaxed\n"
176 gen_basic_fallbacks
${xchg}
178 printf "#else /* ${xchg}_relaxed */\n"
180 gen_order_fallbacks
${xchg}
182 printf "#endif /* ${xchg}_relaxed */\n\n"
185 gen_try_cmpxchg_fallback
()
187 local order
="$1"; shift;
190 #ifndef ${ARCH}try_cmpxchg${order}
191 #define ${ARCH}try_cmpxchg${order}(_ptr, _oldp, _new) \\
193 typeof(*(_ptr)) *___op = (_oldp), ___o = *___op, ___r; \\
194 ___r = ${ARCH}cmpxchg${order}((_ptr), ___o, (_new)); \\
195 if (unlikely(___r != ___o)) \\
197 likely(___r == ___o); \\
199 #endif /* ${ARCH}try_cmpxchg${order} */
204 gen_try_cmpxchg_fallbacks
()
206 printf "#ifndef ${ARCH}try_cmpxchg_relaxed\n"
207 printf "#ifdef ${ARCH}try_cmpxchg\n"
209 gen_basic_fallbacks
"${ARCH}try_cmpxchg"
211 printf "#endif /* ${ARCH}try_cmpxchg */\n\n"
213 for order
in "" "_acquire" "_release" "_relaxed"; do
214 gen_try_cmpxchg_fallback
"${order}"
217 printf "#else /* ${ARCH}try_cmpxchg_relaxed */\n"
219 gen_order_fallbacks
"${ARCH}try_cmpxchg"
221 printf "#endif /* ${ARCH}try_cmpxchg_relaxed */\n\n"
225 // SPDX-License-Identifier: GPL-2.0
228 // DO NOT MODIFY THIS FILE DIRECTLY
230 #ifndef _LINUX_ATOMIC_FALLBACK_H
231 #define _LINUX_ATOMIC_FALLBACK_H
233 #include <linux/compiler.h>
237 for xchg
in "${ARCH}xchg" "${ARCH}cmpxchg" "${ARCH}cmpxchg64"; do
238 gen_xchg_fallbacks
"${xchg}"
241 gen_try_cmpxchg_fallbacks
243 grep '^[a-z]' "$1" |
while read name meta args
; do
244 gen_proto
"${meta}" "${name}" "${ARCH}" "atomic" "int" ${args}
248 #ifdef CONFIG_GENERIC_ATOMIC64
249 #include <asm-generic/atomic64.h>
254 grep '^[a-z]' "$1" | while read name meta args; do
255 gen_proto "${meta}" "${name}" "${ARCH}" "atomic64" "s64" ${args}
259 #endif /* _LINUX_ATOMIC_FALLBACK_H */