lock.h revision 1.4
1/* $NetBSD: lock.h,v 1.4 1999/12/03 01:11:34 thorpej Exp $ */ 2 3/*- 4 * Copyright (c) 1998, 1999 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, 9 * NASA Ames Research Center. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 3. All advertising materials mentioning features or use of this software 20 * must display the following acknowledgement: 21 * This product includes software developed by the NetBSD 22 * Foundation, Inc. and its contributors. 23 * 4. Neither the name of The NetBSD Foundation nor the names of its 24 * contributors may be used to endorse or promote products derived 25 * from this software without specific prior written permission. 26 * 27 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 28 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 29 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 30 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 31 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 37 * POSSIBILITY OF SUCH DAMAGE. 38 */ 39 40/* 41 * Machine-dependent spin lock operations. 42 * 43 * NOTE: We assume that SIMPLELOCK_UNLOCKED == 0, so we can simply 44 * store `zero' to release a lock. 45 */ 46 47#ifndef _ALPHA_LOCK_H_ 48#define _ALPHA_LOCK_H_ 49 50static __inline void cpu_simple_lock_init __P((__volatile struct simplelock *)) 51 __attribute__((__unused__)); 52static __inline void cpu_simple_lock __P((__volatile struct simplelock *)) 53 __attribute__((__unused__)); 54static __inline int cpu_simple_lock_try __P((__volatile struct simplelock *)) 55 __attribute__((__unused__)); 56static __inline void cpu_simple_unlock __P((__volatile struct simplelock *)) 57 __attribute__((__unused__)); 58 59static __inline void 60cpu_simple_lock_init(alp) 61 __volatile struct simplelock *alp; 62{ 63 64 __asm __volatile( 65 "# BEGIN cpu_simple_lock_init\n" 66 " stl $31, %0 \n" 67 " mb \n" 68 " # END cpu_simple_lock_init" 69 : "=m" (alp->lock_data)); 70} 71 72static __inline void 73cpu_simple_lock(alp) 74 __volatile struct simplelock *alp; 75{ 76 unsigned long t0; 77 78 /* 79 * Note, if we detect that the lock is held when 80 * we do the initial load-locked, we spin using 81 * a non-locked load to save the coherency logic 82 * some work. 83 */ 84 85 __asm __volatile( 86 "# BEGIN cpu_simple_lock\n" 87 "1: ldl_l %0, %3 \n" 88 " bne %0, 2f \n" 89 " bis $31, %2, %0 \n" 90 " stl_c %0, %1 \n" 91 " beq %0, 3f \n" 92 " mb \n" 93 " br 4f \n" 94 "2: ldl %0, %3 \n" 95 " beq %0, 1b \n" 96 " br 2b \n" 97 "3: br 1b \n" 98 "4: \n" 99 " # END cpu_simple_lock\n" 100 : "=r" (t0), "=m" (alp->lock_data) 101 : "i" (SIMPLELOCK_LOCKED), "1" (alp->lock_data)); 102} 103 104static __inline int 105cpu_simple_lock_try(alp) 106 __volatile struct simplelock *alp; 107{ 108 unsigned long t0, v0; 109 110 __asm __volatile( 111 "# BEGIN cpu_simple_lock_try\n" 112 "1: ldl_l %0, %4 \n" 113 " bne %0, 2f \n" 114 " bis $31, %3, %0 \n" 115 " stl_c %0, %2 \n" 116 " beq %0, 3f \n" 117 " mb \n" 118 " bis $31, 1, %1 \n" 119 " br 4f \n" 120 "2: bis $31, $31, %1 \n" 121 " br 4f \n" 122 "3: br 1b \n" 123 "4: \n" 124 " # END cpu_simple_lock_try" 125 : "=r" (t0), "=r" (v0), "=m" (alp->lock_data) 126 : "i" (SIMPLELOCK_LOCKED), "2" (alp->lock_data)); 127 128 return (v0); 129} 130 131static __inline void 132cpu_simple_unlock(alp) 133 __volatile struct simplelock *alp; 134{ 135 136 __asm __volatile( 137 "# BEGIN cpu_simple_unlock\n" 138 " stl $31, %0 \n" 139 " mb \n" 140 " # END cpu_simple_unlock" 141 : "=m" (alp->lock_data)); 142} 143 144#endif /* _ALPHA_LOCK_H_ */ 145