lock.h revision 1.8
11.8Spooka/* $NetBSD: lock.h,v 1.8 2008/10/12 20:52:56 pooka 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 * 191.2Sbjh21 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 201.2Sbjh21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 211.2Sbjh21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 221.2Sbjh21 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 231.2Sbjh21 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 241.2Sbjh21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 251.2Sbjh21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 261.2Sbjh21 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 271.2Sbjh21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 281.2Sbjh21 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 291.2Sbjh21 * POSSIBILITY OF SUCH DAMAGE. 301.2Sbjh21 */ 311.2Sbjh21 321.2Sbjh21#ifndef _ACORN32_LOCK_H_ 331.2Sbjh21#define _ACORN32_LOCK_H_ 341.2Sbjh21 351.2Sbjh21#ifdef _KERNEL_OPT 361.2Sbjh21#include "opt_multiprocessor.h" 371.2Sbjh21#endif 381.2Sbjh21 391.2Sbjh21#if defined(_KERNEL) && defined(MULTIPROCESSOR) 401.2Sbjh21 411.2Sbjh21#include <arm/cpufunc.h> 421.2Sbjh21 431.6Sperrystatic __inline int 441.8Spooka__swp(int __val, volatile unsigned char *__ptr) 451.2Sbjh21{ 461.2Sbjh21 471.8Spooka __asm volatile("swpb %0, %1, [%2]" 481.2Sbjh21 : "=r" (__val) : "r" (__val), "r" (__ptr) : "memory"); 491.2Sbjh21 return __val; 501.2Sbjh21} 511.2Sbjh21 521.6Sperrystatic __inline void __attribute__((__unused__)) 531.2Sbjh21__cpu_simple_lock_init(__cpu_simple_lock_t *alp) 541.2Sbjh21{ 551.2Sbjh21 561.2Sbjh21 *alp = __SIMPLELOCK_UNLOCKED; 571.2Sbjh21} 581.2Sbjh21 591.6Sperrystatic __inline void __attribute__((__unused__)) 601.2Sbjh21__cpu_simple_lock(__cpu_simple_lock_t *alp) 611.2Sbjh21{ 621.2Sbjh21 631.2Sbjh21 while (__swp(__SIMPLELOCK_LOCKED, alp) != __SIMPLELOCK_UNLOCKED) 641.2Sbjh21 continue; 651.2Sbjh21 cpu_idcache_wbinv_all(); 661.2Sbjh21} 671.2Sbjh21 681.6Sperrystatic __inline int __attribute__((__unused__)) 691.2Sbjh21__cpu_simple_lock_try(__cpu_simple_lock_t *alp) 701.2Sbjh21{ 711.2Sbjh21 int __result; 721.2Sbjh21 731.2Sbjh21 __result = __swp(__SIMPLELOCK_LOCKED, alp) == __SIMPLELOCK_UNLOCKED; 741.2Sbjh21 if (__result) 751.2Sbjh21 cpu_idcache_wbinv_all(); 761.2Sbjh21 return __result; 771.2Sbjh21} 781.2Sbjh21 791.6Sperrystatic __inline void __attribute__((__unused__)) 801.2Sbjh21__cpu_simple_unlock(__cpu_simple_lock_t *alp) 811.2Sbjh21{ 821.2Sbjh21 831.2Sbjh21 *alp = __SIMPLELOCK_UNLOCKED; 841.2Sbjh21} 851.2Sbjh21 861.2Sbjh21#else /* !(_KERNEL && MULTIPROCESSOR) */ 871.1Sreinoud#include <arm/lock.h> 881.2Sbjh21#endif /* !(_KERNEL && MULTIPROCESSOR) */ 891.2Sbjh21#endif 90