^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0-only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) #include <linux/linkage.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) #include <asm/percpu.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) .text
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Inputs:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * %rsi : memory location to compare
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * %rax : low 64 bits of old value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * %rdx : high 64 bits of old value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * %rbx : low 64 bits of new value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * %rcx : high 64 bits of new value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * %al : Operation successful
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) SYM_FUNC_START(this_cpu_cmpxchg16b_emu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) # Emulate 'cmpxchg16b %gs:(%rsi)' except we return the result in %al not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) # via the ZF. Caller will access %al to get result.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) # Note that this is only useful for a cpuops operation. Meaning that we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) # do *not* have a fully atomic operation but just an operation that is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) # *atomic* on a single cpu (as provided by the this_cpu_xx class of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) # macros).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) pushfq
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) cli
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) cmpq PER_CPU_VAR((%rsi)), %rax
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) jne .Lnot_same
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) cmpq PER_CPU_VAR(8(%rsi)), %rdx
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) jne .Lnot_same
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) movq %rbx, PER_CPU_VAR((%rsi))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) movq %rcx, PER_CPU_VAR(8(%rsi))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) popfq
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) mov $1, %al
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) ret
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) .Lnot_same:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) popfq
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) xor %al,%al
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) ret
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) SYM_FUNC_END(this_cpu_cmpxchg16b_emu)