11.10Sriastrad/* $NetBSD: lock.h,v 1.10 2022/02/13 13:41:26 riastradh 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.9Spooka#include <sys/param.h> 361.9Spooka 371.2Sbjh21#ifdef _KERNEL_OPT 381.2Sbjh21#include "opt_multiprocessor.h" 391.2Sbjh21#endif 401.2Sbjh21 411.9Spooka#if defined(_HARDKERNEL) && defined(MULTIPROCESSOR) 421.2Sbjh21 431.2Sbjh21#include <arm/cpufunc.h> 441.2Sbjh21 451.6Sperrystatic __inline int 461.8Spooka__swp(int __val, volatile unsigned char *__ptr) 471.2Sbjh21{ 481.2Sbjh21 491.8Spooka __asm volatile("swpb %0, %1, [%2]" 501.2Sbjh21 : "=r" (__val) : "r" (__val), "r" (__ptr) : "memory"); 511.2Sbjh21 return __val; 521.2Sbjh21} 531.2Sbjh21 541.6Sperrystatic __inline void __attribute__((__unused__)) 551.2Sbjh21__cpu_simple_lock_init(__cpu_simple_lock_t *alp) 561.2Sbjh21{ 571.2Sbjh21 581.2Sbjh21 *alp = __SIMPLELOCK_UNLOCKED; 591.2Sbjh21} 601.2Sbjh21 611.6Sperrystatic __inline void __attribute__((__unused__)) 621.2Sbjh21__cpu_simple_lock(__cpu_simple_lock_t *alp) 631.2Sbjh21{ 641.2Sbjh21 651.2Sbjh21 while (__swp(__SIMPLELOCK_LOCKED, alp) != __SIMPLELOCK_UNLOCKED) 661.2Sbjh21 continue; 671.2Sbjh21 cpu_idcache_wbinv_all(); 681.2Sbjh21} 691.2Sbjh21 701.6Sperrystatic __inline int __attribute__((__unused__)) 711.2Sbjh21__cpu_simple_lock_try(__cpu_simple_lock_t *alp) 721.2Sbjh21{ 731.2Sbjh21 int __result; 741.2Sbjh21 751.2Sbjh21 __result = __swp(__SIMPLELOCK_LOCKED, alp) == __SIMPLELOCK_UNLOCKED; 761.2Sbjh21 if (__result) 771.2Sbjh21 cpu_idcache_wbinv_all(); 781.2Sbjh21 return __result; 791.2Sbjh21} 801.2Sbjh21 811.6Sperrystatic __inline void __attribute__((__unused__)) 821.2Sbjh21__cpu_simple_unlock(__cpu_simple_lock_t *alp) 831.2Sbjh21{ 841.2Sbjh21 851.10Sriastrad __insn_barrier(); 861.2Sbjh21 *alp = __SIMPLELOCK_UNLOCKED; 871.2Sbjh21} 881.2Sbjh21 891.9Spooka#else /* !(_HARDKERNEL && MULTIPROCESSOR) */ 901.1Sreinoud#include <arm/lock.h> 911.9Spooka#endif /* !(_HARDKERNEL && MULTIPROCESSOR) */ 921.2Sbjh21#endif 93