lock.h revision 1.15
11.15Schristos/* $NetBSD: lock.h,v 1.15 2017/09/17 00:01:07 christos 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.3Sthorpej : "=m" (*alp)); 791.3Sthorpej} 801.3Sthorpej 811.10Schristosstatic __inline int 821.3Sthorpej__cpu_simple_lock_try(__cpu_simple_lock_t *alp) 831.3Sthorpej{ 841.4Sthorpej int __rv; 851.3Sthorpej 861.8Sperry __asm volatile( 871.4Sthorpej " moveq #1, %1 \n" 881.3Sthorpej " tas %0 \n" 891.3Sthorpej " jeq 1f \n" 901.3Sthorpej " moveq #0, %1 \n" 911.3Sthorpej "1: \n" 921.3Sthorpej : "=m" (*alp), "=d" (__rv)); 931.3Sthorpej 941.3Sthorpej return (__rv); 951.3Sthorpej} 961.3Sthorpej 971.10Schristosstatic __inline void 981.3Sthorpej__cpu_simple_unlock(__cpu_simple_lock_t *alp) 991.3Sthorpej{ 1001.3Sthorpej 1011.3Sthorpej *alp = __SIMPLELOCK_UNLOCKED; 1021.3Sthorpej} 1031.1Sthorpej 1041.11Sadstatic __inline void 1051.11Sadmb_read(void) 1061.11Sad{ 1071.11Sad __asm volatile("" : : : "memory"); 1081.11Sad} 1091.11Sad 1101.11Sadstatic __inline void 1111.11Sadmb_write(void) 1121.11Sad{ 1131.11Sad __asm volatile("" : : : "memory"); 1141.11Sad} 1151.11Sad 1161.11Sadstatic __inline void 1171.11Sadmb_memory(void) 1181.11Sad{ 1191.11Sad __asm volatile("" : : : "memory"); 1201.11Sad} 1211.11Sad 1221.1Sthorpej#endif /* _M68K_LOCK_H_ */ 123