1/* $NetBSD: lock.h,v 1.15 2008/04/28 20:23:35 martin Exp $ */ 2 3/*- 4 * Copyright (c) 2002 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Gregory McGarry. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32/* 33 * Machine-dependent spin lock operations. 34 */ 35 36#ifndef _SH3_LOCK_H_ 37#define _SH3_LOCK_H_ 38 39static __inline void __cpu_simple_lock_init(__cpu_simple_lock_t *) 40 __attribute__((__unused__)); 41static __inline void __cpu_simple_lock(__cpu_simple_lock_t *) 42 __attribute__((__unused__)); 43static __inline int __cpu_simple_lock_try(__cpu_simple_lock_t *) 44 __attribute__((__unused__)); 45static __inline void __cpu_simple_unlock(__cpu_simple_lock_t *) 46 __attribute__((__unused__)); 47 48static __inline int 49__SIMPLELOCK_LOCKED_P(__cpu_simple_lock_t *__ptr) 50{ 51 return *__ptr == __SIMPLELOCK_LOCKED; 52} 53 54static __inline int 55__SIMPLELOCK_UNLOCKED_P(__cpu_simple_lock_t *__ptr) 56{ 57 return *__ptr == __SIMPLELOCK_UNLOCKED; 58} 59 60static __inline void 61__cpu_simple_lock_clear(__cpu_simple_lock_t *__ptr) 62{ 63 *__ptr = __SIMPLELOCK_UNLOCKED; 64} 65 66static __inline void 67__cpu_simple_lock_set(__cpu_simple_lock_t *__ptr) 68{ 69 *__ptr = __SIMPLELOCK_LOCKED; 70} 71 72static __inline void 73__cpu_simple_lock_init(__cpu_simple_lock_t *alp) 74{ 75 76 *alp = __SIMPLELOCK_UNLOCKED; 77} 78 79static __inline void 80__cpu_simple_lock(__cpu_simple_lock_t *alp) 81{ 82 83 __asm volatile( 84 "1: tas.b @%0 \n" 85 " bf 1b \n" 86 : /* no outputs */ 87 : "r" (alp) 88 : "cc", "memory"); 89} 90 91static __inline int 92__cpu_simple_lock_try(__cpu_simple_lock_t *alp) 93{ 94 int __rv; 95 96 __asm volatile( 97 " tas.b @%1 \n" 98 " movt %0 \n" 99 : "=r" (__rv) 100 : "r" (alp) 101 : "cc", "memory"); 102 103 return (__rv); 104} 105 106static __inline void 107__cpu_simple_unlock(__cpu_simple_lock_t *alp) 108{ 109 110 *alp = __SIMPLELOCK_UNLOCKED; 111} 112 113static __inline void 114mb_read(void) 115{ 116 __asm volatile("" : : : "memory"); 117} 118 119static __inline void 120mb_write(void) 121{ 122 __asm volatile("" : : : "memory"); 123} 124 125static __inline void 126mb_memory(void) 127{ 128 __asm volatile("" : : : "memory"); 129} 130 131#endif /* !_SH3_LOCK_H_ */ 132