lock.h revision 1.6
11.6Sperry/* $NetBSD: lock.h,v 1.6 2005/12/28 19:09:29 perry Exp $ */ 21.1Sreinoud 31.2Sbjh21/*- 41.2Sbjh21 * Copyright (c) 2000, 2001 The NetBSD Foundation, Inc. 51.2Sbjh21 * All rights reserved. 61.2Sbjh21 * 71.2Sbjh21 * This code is derived from software contributed to The NetBSD Foundation 81.2Sbjh21 * by Jason R. Thorpe. 91.2Sbjh21 * 101.2Sbjh21 * Redistribution and use in source and binary forms, with or without 111.2Sbjh21 * modification, are permitted provided that the following conditions 121.2Sbjh21 * are met: 131.2Sbjh21 * 1. Redistributions of source code must retain the above copyright 141.2Sbjh21 * notice, this list of conditions and the following disclaimer. 151.2Sbjh21 * 2. Redistributions in binary form must reproduce the above copyright 161.2Sbjh21 * notice, this list of conditions and the following disclaimer in the 171.2Sbjh21 * documentation and/or other materials provided with the distribution. 181.2Sbjh21 * 3. All advertising materials mentioning features or use of this software 191.2Sbjh21 * must display the following acknowledgement: 201.2Sbjh21 * This product includes software developed by the NetBSD 211.2Sbjh21 * Foundation, Inc. and its contributors. 221.2Sbjh21 * 4. Neither the name of The NetBSD Foundation nor the names of its 231.2Sbjh21 * contributors may be used to endorse or promote products derived 241.2Sbjh21 * from this software without specific prior written permission. 251.2Sbjh21 * 261.2Sbjh21 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 271.2Sbjh21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 281.2Sbjh21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 291.2Sbjh21 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 301.2Sbjh21 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 311.2Sbjh21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 321.2Sbjh21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 331.2Sbjh21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 341.2Sbjh21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 351.2Sbjh21 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 361.2Sbjh21 * POSSIBILITY OF SUCH DAMAGE. 371.2Sbjh21 */ 381.2Sbjh21 391.2Sbjh21#ifndef _ACORN32_LOCK_H_ 401.2Sbjh21#define _ACORN32_LOCK_H_ 411.2Sbjh21 421.2Sbjh21#ifdef _KERNEL_OPT 431.2Sbjh21#include "opt_multiprocessor.h" 441.2Sbjh21#endif 451.2Sbjh21 461.2Sbjh21#if defined(_KERNEL) && defined(MULTIPROCESSOR) 471.2Sbjh21 481.2Sbjh21#include <arm/cpufunc.h> 491.2Sbjh21 501.6Sperrystatic __inline int 511.5Sperry__swp(int __val, volatile int *__ptr) 521.2Sbjh21{ 531.2Sbjh21 541.5Sperry __asm volatile("swp %0, %1, [%2]" 551.2Sbjh21 : "=r" (__val) : "r" (__val), "r" (__ptr) : "memory"); 561.2Sbjh21 return __val; 571.2Sbjh21} 581.2Sbjh21 591.6Sperrystatic __inline void __attribute__((__unused__)) 601.2Sbjh21__cpu_simple_lock_init(__cpu_simple_lock_t *alp) 611.2Sbjh21{ 621.2Sbjh21 631.2Sbjh21 *alp = __SIMPLELOCK_UNLOCKED; 641.2Sbjh21} 651.2Sbjh21 661.6Sperrystatic __inline void __attribute__((__unused__)) 671.2Sbjh21__cpu_simple_lock(__cpu_simple_lock_t *alp) 681.2Sbjh21{ 691.2Sbjh21 701.2Sbjh21 while (__swp(__SIMPLELOCK_LOCKED, alp) != __SIMPLELOCK_UNLOCKED) 711.2Sbjh21 continue; 721.2Sbjh21 cpu_idcache_wbinv_all(); 731.2Sbjh21} 741.2Sbjh21 751.6Sperrystatic __inline int __attribute__((__unused__)) 761.2Sbjh21__cpu_simple_lock_try(__cpu_simple_lock_t *alp) 771.2Sbjh21{ 781.2Sbjh21 int __result; 791.2Sbjh21 801.2Sbjh21 __result = __swp(__SIMPLELOCK_LOCKED, alp) == __SIMPLELOCK_UNLOCKED; 811.2Sbjh21 if (__result) 821.2Sbjh21 cpu_idcache_wbinv_all(); 831.2Sbjh21 return __result; 841.2Sbjh21} 851.2Sbjh21 861.6Sperrystatic __inline void __attribute__((__unused__)) 871.2Sbjh21__cpu_simple_unlock(__cpu_simple_lock_t *alp) 881.2Sbjh21{ 891.2Sbjh21 901.2Sbjh21 *alp = __SIMPLELOCK_UNLOCKED; 911.2Sbjh21} 921.2Sbjh21 931.2Sbjh21#else /* !(_KERNEL && MULTIPROCESSOR) */ 941.1Sreinoud#include <arm/lock.h> 951.2Sbjh21#endif /* !(_KERNEL && MULTIPROCESSOR) */ 961.2Sbjh21#endif 97