1// SPDX-License-Identifier: BSD-2-Clause 2/* 3 * Copyright 2022 NXP 4 */ 5 6#include <asm.S> 7#include <kernel/spinlock.h> 8#include <riscv.h> 9 10/* void __cpu_spin_lock(unsigned int *lock) */ 11FUNC __cpu_spin_lock , : 12 addi sp, sp, -(RISCV_XLEN_BYTES * 2) 13 STR s0, 0(sp) 14 STR ra, 8(sp) 15 mv s0, a0 161: 17 mv a0, s0 18 jal __cpu_spin_trylock 19 addiw a0, a0, 0 20 bnez a0, 1b 21 LDR ra, 8(sp) 22 LDR s0, 0(sp) 23 addi sp, sp, (RISCV_XLEN_BYTES * 2) 24 ret 25END_FUNC __cpu_spin_lock 26 27 28/* void __cpu_spin_unlock(unsigned int *lock)*/ 29FUNC __cpu_spin_unlock , : 30 fence rw, w 31 amoswap.w x0, x0, 0(a0) 32 ret 33END_FUNC __cpu_spin_unlock 34 35/* unsigned int __cpu_spin_trylock(unsigned int *lock) */ 36FUNC __cpu_spin_trylock , : 37 li t0, SPINLOCK_LOCK 38 amoswap.w a0, t0, 0(a0) 39 fence r,rw 40 ret 41END_FUNC __cpu_spin_trylock 42 43