11.17Sriastrad/* $NetBSD: lock.h,v 1.17 2022/02/13 13:41:44 riastradh Exp $ */ 21.1Sthorpej 31.1Sthorpej/*- 41.1Sthorpej * Copyright (c) 2000 The NetBSD Foundation, Inc. 51.1Sthorpej * All rights reserved. 61.1Sthorpej * 71.1Sthorpej * This code is derived from software contributed to The NetBSD Foundation 81.1Sthorpej * by Jason R. Thorpe. 91.1Sthorpej * 101.1Sthorpej * Redistribution and use in source and binary forms, with or without 111.1Sthorpej * modification, are permitted provided that the following conditions 121.1Sthorpej * are met: 131.1Sthorpej * 1. Redistributions of source code must retain the above copyright 141.1Sthorpej * notice, this list of conditions and the following disclaimer. 151.1Sthorpej * 2. Redistributions in binary form must reproduce the above copyright 161.1Sthorpej * notice, this list of conditions and the following disclaimer in the 171.1Sthorpej * documentation and/or other materials provided with the distribution. 181.1Sthorpej * 191.1Sthorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 201.1Sthorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 211.1Sthorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 221.1Sthorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 231.1Sthorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 241.1Sthorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 251.1Sthorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 261.1Sthorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 271.1Sthorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 281.1Sthorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 291.1Sthorpej * POSSIBILITY OF SUCH DAMAGE. 301.1Sthorpej */ 311.1Sthorpej 321.1Sthorpej/* 331.1Sthorpej * Machine-dependent spin lock operations. 341.1Sthorpej */ 351.1Sthorpej 361.1Sthorpej#ifndef _M68K_LOCK_H_ 371.1Sthorpej#define _M68K_LOCK_H_ 381.3Sthorpej 391.12Sskrllstatic __inline int 401.15Schristos__SIMPLELOCK_LOCKED_P(const __cpu_simple_lock_t *__ptr) 411.12Sskrll{ 421.12Sskrll return *__ptr == __SIMPLELOCK_LOCKED; 431.12Sskrll} 441.12Sskrll 451.12Sskrllstatic __inline int 461.15Schristos__SIMPLELOCK_UNLOCKED_P(const __cpu_simple_lock_t *__ptr) 471.12Sskrll{ 481.12Sskrll return *__ptr == __SIMPLELOCK_UNLOCKED; 491.12Sskrll} 501.12Sskrll 511.10Schristosstatic __inline void 521.3Sthorpej__cpu_simple_lock_init(__cpu_simple_lock_t *alp) 531.3Sthorpej{ 541.3Sthorpej 551.3Sthorpej *alp = __SIMPLELOCK_UNLOCKED; 561.3Sthorpej} 571.3Sthorpej 581.12Sskrll 591.12Sskrllstatic __inline void 601.12Sskrll__cpu_simple_lock_clear(__cpu_simple_lock_t *__ptr) 611.12Sskrll{ 621.12Sskrll *__ptr = __SIMPLELOCK_UNLOCKED; 631.12Sskrll} 641.12Sskrll 651.12Sskrllstatic __inline void 661.12Sskrll__cpu_simple_lock_set(__cpu_simple_lock_t *__ptr) 671.12Sskrll{ 681.12Sskrll *__ptr = __SIMPLELOCK_LOCKED; 691.12Sskrll} 701.12Sskrll 711.10Schristosstatic __inline void 721.3Sthorpej__cpu_simple_lock(__cpu_simple_lock_t *alp) 731.3Sthorpej{ 741.3Sthorpej 751.8Sperry __asm volatile( 761.3Sthorpej "1: tas %0 \n" 771.3Sthorpej " jne 1b \n" 781.17Sriastrad : "=m" (*alp) 791.17Sriastrad : /* no inputs */ 801.17Sriastrad : "cc", "memory"); 811.3Sthorpej} 821.3Sthorpej 831.10Schristosstatic __inline int 841.3Sthorpej__cpu_simple_lock_try(__cpu_simple_lock_t *alp) 851.3Sthorpej{ 861.4Sthorpej int __rv; 871.3Sthorpej 881.8Sperry __asm volatile( 891.4Sthorpej " moveq #1, %1 \n" 901.3Sthorpej " tas %0 \n" 911.3Sthorpej " jeq 1f \n" 921.3Sthorpej " moveq #0, %1 \n" 931.3Sthorpej "1: \n" 941.17Sriastrad : "=m" (*alp), "=d" (__rv) 951.17Sriastrad : /* no inputs */ 961.17Sriastrad : "cc", "memory"); 971.3Sthorpej 981.3Sthorpej return (__rv); 991.3Sthorpej} 1001.3Sthorpej 1011.10Schristosstatic __inline void 1021.3Sthorpej__cpu_simple_unlock(__cpu_simple_lock_t *alp) 1031.3Sthorpej{ 1041.3Sthorpej 1051.17Sriastrad __insn_barrier(); 1061.3Sthorpej *alp = __SIMPLELOCK_UNLOCKED; 1071.3Sthorpej} 1081.1Sthorpej 1091.1Sthorpej#endif /* _M68K_LOCK_H_ */ 110