lock.h revision 1.7
11.7Sperry/* $NetBSD: lock.h,v 1.7 2005/12/24 20:07:19 perry Exp $ */ 21.1Sthorpej 31.1Sthorpej/*- 41.3Sgmcgarry * Copyright (c) 2001 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.3Sgmcgarry * by Wayne Knowles. 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 * 3. All advertising materials mentioning features or use of this software 191.1Sthorpej * must display the following acknowledgement: 201.1Sthorpej * This product includes software developed by the NetBSD 211.1Sthorpej * Foundation, Inc. and its contributors. 221.1Sthorpej * 4. Neither the name of The NetBSD Foundation nor the names of its 231.1Sthorpej * contributors may be used to endorse or promote products derived 241.1Sthorpej * from this software without specific prior written permission. 251.1Sthorpej * 261.1Sthorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 271.1Sthorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 281.1Sthorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 291.1Sthorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 301.1Sthorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 311.1Sthorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 321.1Sthorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 331.1Sthorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 341.1Sthorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 351.1Sthorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 361.1Sthorpej * POSSIBILITY OF SUCH DAMAGE. 371.1Sthorpej */ 381.1Sthorpej 391.1Sthorpej/* 401.3Sgmcgarry * Machine-dependent spin lock operations for MIPS R4000 Processors. 411.3Sgmcgarry * 421.3Sgmcgarry * Note: R3000 doesn't have any atomic update instructions 431.1Sthorpej */ 441.1Sthorpej 451.1Sthorpej#ifndef _MIPS_LOCK_H_ 461.1Sthorpej#define _MIPS_LOCK_H_ 471.3Sgmcgarry 481.7Sperrystatic inline void 491.3Sgmcgarry__cpu_simple_lock_init(__cpu_simple_lock_t *lp) 501.3Sgmcgarry{ 511.3Sgmcgarry 521.7Sperry __asm volatile( 531.3Sgmcgarry "# -- BEGIN __cpu_simple_lock_init\n" 541.3Sgmcgarry " .set push \n" 551.3Sgmcgarry " .set mips2 \n" 561.3Sgmcgarry " sw $0, %0 \n" 571.3Sgmcgarry " sync \n" 581.3Sgmcgarry " .set pop \n" 591.3Sgmcgarry "# -- END __cpu_simple_lock_init\n" 601.3Sgmcgarry : "=m" (*lp)); 611.3Sgmcgarry} 621.3Sgmcgarry 631.7Sperrystatic inline void 641.3Sgmcgarry__cpu_simple_lock(__cpu_simple_lock_t *lp) 651.3Sgmcgarry{ 661.3Sgmcgarry unsigned long t0; 671.3Sgmcgarry 681.3Sgmcgarry /* 691.3Sgmcgarry * Note, if we detect that the lock is held when 701.3Sgmcgarry * we do the initial load-locked, we spin using 711.3Sgmcgarry * a non-locked load to save the coherency logic 721.3Sgmcgarry * some work. 731.3Sgmcgarry */ 741.3Sgmcgarry 751.7Sperry __asm volatile( 761.3Sgmcgarry "# -- BEGIN __cpu_simple_lock \n" 771.3Sgmcgarry " .set push \n" 781.3Sgmcgarry " .set mips2 \n" 791.3Sgmcgarry "1: ll %0, %3 \n" 801.3Sgmcgarry " bnez %0, 2f \n" 811.3Sgmcgarry " nop # BDslot \n" 821.3Sgmcgarry " li %0, %2 \n" 831.3Sgmcgarry " sc %0, %1 \n" 841.3Sgmcgarry " beqz %0, 1b \n" 851.3Sgmcgarry " nop # BDslot \n" 861.3Sgmcgarry " nop \n" 871.3Sgmcgarry " sync \n" 881.3Sgmcgarry " j 3f \n" 891.3Sgmcgarry " nop \n" 901.3Sgmcgarry " nop \n" 911.3Sgmcgarry "2: lw %0, %3 \n" 921.3Sgmcgarry " bnez %0, 2b \n" 931.3Sgmcgarry " nop # BDslot \n" 941.3Sgmcgarry " j 1b \n" 951.3Sgmcgarry " nop \n" 961.3Sgmcgarry "3: \n" 971.3Sgmcgarry " .set pop \n" 981.3Sgmcgarry "# -- END __cpu_simple_lock \n" 991.3Sgmcgarry : "=r" (t0), "+m" (*lp) 1001.3Sgmcgarry : "i" (__SIMPLELOCK_LOCKED), "1" (*lp)); 1011.3Sgmcgarry} 1021.3Sgmcgarry 1031.7Sperrystatic inline int 1041.3Sgmcgarry__cpu_simple_lock_try(__cpu_simple_lock_t *lp) 1051.3Sgmcgarry{ 1061.3Sgmcgarry unsigned long t0, v0; 1071.3Sgmcgarry 1081.7Sperry __asm volatile( 1091.3Sgmcgarry "# -- BEGIN __cpu_simple_lock_try\n" 1101.3Sgmcgarry " .set push \n" 1111.3Sgmcgarry " .set mips2 \n" 1121.3Sgmcgarry "1: ll %0, %4 \n" 1131.3Sgmcgarry " bnez %0, 2f \n" 1141.3Sgmcgarry " nop # BDslot \n" 1151.3Sgmcgarry " li %0, %3 \n" 1161.3Sgmcgarry " sc %0, %2 \n" 1171.3Sgmcgarry " beqz %0, 2f \n" 1181.3Sgmcgarry " nop # BDslot \n" 1191.3Sgmcgarry " li %1, 1 \n" 1201.3Sgmcgarry " sync \n" 1211.3Sgmcgarry " j 3f \n" 1221.3Sgmcgarry " nop \n" 1231.3Sgmcgarry " nop \n" 1241.3Sgmcgarry "2: li %1, 0 \n" 1251.3Sgmcgarry "3: \n" 1261.3Sgmcgarry " .set pop \n" 1271.3Sgmcgarry "# -- END __cpu_simple_lock_try \n" 1281.3Sgmcgarry : "=r" (t0), "=r" (v0), "+m" (*lp) 1291.3Sgmcgarry : "i" (__SIMPLELOCK_LOCKED), "2" (*lp)); 1301.3Sgmcgarry 1311.3Sgmcgarry return (v0 != 0); 1321.3Sgmcgarry} 1331.3Sgmcgarry 1341.7Sperrystatic inline void 1351.3Sgmcgarry__cpu_simple_unlock(__cpu_simple_lock_t *lp) 1361.3Sgmcgarry{ 1371.3Sgmcgarry 1381.7Sperry __asm volatile( 1391.3Sgmcgarry "# -- BEGIN __cpu_simple_unlock \n" 1401.3Sgmcgarry " .set push \n" 1411.3Sgmcgarry " .set mips2 \n" 1421.3Sgmcgarry " sync \n" 1431.3Sgmcgarry " sw $0, %0 \n" 1441.3Sgmcgarry " .set pop \n" 1451.3Sgmcgarry "# -- END __cpu_simple_unlock \n" 1461.3Sgmcgarry : "=m" (*lp)); 1471.3Sgmcgarry} 1481.1Sthorpej#endif /* _MIPS_LOCK_H_ */ 149