1/* SPDX-License-Identifier: BSD-3-Clause */ 2/* 3 * Copyright (c) 2016, Linaro Limited 4 * Copyright (c) 2016, ARM Limited and Contributors. All rights reserved. 5 * Copyright (c) 2014, STMicroelectronics International N.V. 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions are met: 10 * 11 * 1. Redistributions of source code must retain the above copyright notice, 12 * this list of conditions and the following disclaimer. 13 * 14 * 2. Redistributions in binary form must reproduce the above copyright notice, 15 * this list of conditions and the following disclaimer in the documentation 16 * and/or other materials provided with the distribution. 17 * 18 * Neither the name of ARM nor the names of its contributors may be used 19 * to endorse or promote products derived from this software without specific 20 * prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 23 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 26 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 32 * POSSIBILITY OF SUCH DAMAGE. 33 */ 34 35#include <asm.S> 36#include <kernel/spinlock.h> 37 38/* void __cpu_spin_lock(unsigned int *lock) */ 39FUNC __cpu_spin_lock , : 40 mov r2, #SPINLOCK_LOCK 411: 42 ldrex r1, [r0] 43 cmp r1, #SPINLOCK_UNLOCK 44 wfene 45 strexeq r1, r2, [r0] 46 cmpeq r1, #0 47 bne 1b 48 dmb 49 bx lr 50END_FUNC __cpu_spin_lock 51 52/* int __cpu_spin_trylock(unsigned int *lock) - return 0 on success */ 53FUNC __cpu_spin_trylock , : 54 mov r2, #SPINLOCK_LOCK 55 mov r1, r0 561: 57 ldrex r0, [r1] 58 cmp r0, #0 59 bne 1f 60 strex r0, r2, [r1] 61 cmp r0, #0 62 bne 1b 63 dmb 64 bx lr 651: 66 clrex 67 dmb 68 bx lr 69END_FUNC __cpu_spin_trylock 70 71/* void __cpu_spin_unlock(unsigned int *lock) */ 72FUNC __cpu_spin_unlock , : 73 dmb 74 mov r1, #SPINLOCK_UNLOCK 75 str r1, [r0] 76 dsb 77 sev 78 bx lr 79END_FUNC __cpu_spin_unlock 80