1*a8845456Sriastradh /* $NetBSD: mutex.h,v 1.13 2023/07/12 12:50:13 riastradh Exp $ */ 2b07ec3fcSad 3b07ec3fcSad /*- 471eb6505Sad * Copyright (c) 2002, 2006 The NetBSD Foundation, Inc. 5b07ec3fcSad * All rights reserved. 6b07ec3fcSad * 7b07ec3fcSad * This code is derived from software contributed to The NetBSD Foundation 8b07ec3fcSad * by Jason R. Thorpe and Andrew Doran. 9b07ec3fcSad * 10b07ec3fcSad * Redistribution and use in source and binary forms, with or without 11b07ec3fcSad * modification, are permitted provided that the following conditions 12b07ec3fcSad * are met: 13b07ec3fcSad * 1. Redistributions of source code must retain the above copyright 14b07ec3fcSad * notice, this list of conditions and the following disclaimer. 15b07ec3fcSad * 2. Redistributions in binary form must reproduce the above copyright 16b07ec3fcSad * notice, this list of conditions and the following disclaimer in the 17b07ec3fcSad * documentation and/or other materials provided with the distribution. 18b07ec3fcSad * 19b07ec3fcSad * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20b07ec3fcSad * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21b07ec3fcSad * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22b07ec3fcSad * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23b07ec3fcSad * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24b07ec3fcSad * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25b07ec3fcSad * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26b07ec3fcSad * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27b07ec3fcSad * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28b07ec3fcSad * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29b07ec3fcSad * POSSIBILITY OF SUCH DAMAGE. 30b07ec3fcSad */ 31b07ec3fcSad 32b07ec3fcSad #ifndef _SPARC_MUTEX_H_ 33b07ec3fcSad #define _SPARC_MUTEX_H_ 34b07ec3fcSad 35*a8845456Sriastradh #include <sys/types.h> 36*a8845456Sriastradh 373a3709e6Smartin #ifdef __MUTEX_PRIVATE 3878272616Sriastradh #include <machine/intr.h> 3978272616Sriastradh 403a3709e6Smartin #include "psl.h" 413a3709e6Smartin #endif 423a3709e6Smartin 43b07ec3fcSad struct kmutex { 44b07ec3fcSad union { 4571eb6505Sad volatile uintptr_t mtxa_owner; 4671eb6505Sad #ifdef __MUTEX_PRIVATE 47b07ec3fcSad struct { 4871eb6505Sad volatile uint8_t mtxs_dummy; 4971eb6505Sad ipl_cookie_t mtxs_ipl; 5071eb6505Sad __cpu_simple_lock_t mtxs_lock; 5171eb6505Sad volatile uint8_t mtxs_unused; 52b07ec3fcSad } s; 5371eb6505Sad #endif 54b07ec3fcSad } u; 55b07ec3fcSad }; 56b07ec3fcSad 5771eb6505Sad #ifdef __MUTEX_PRIVATE 58b07ec3fcSad 5971eb6505Sad #define mtx_owner u.mtxa_owner 60b07ec3fcSad #define mtx_ipl u.s.mtxs_ipl 6171eb6505Sad #define mtx_lock u.s.mtxs_lock 62b07ec3fcSad 6371eb6505Sad #define __HAVE_SIMPLE_MUTEXES 1 64b07ec3fcSad 6571eb6505Sad #define MUTEX_CAS(p, o, n) \ 6671eb6505Sad (_atomic_cas_ulong((volatile unsigned long *)(p), (o), (n)) == (o)) 67b07ec3fcSad 6871eb6505Sad unsigned long _atomic_cas_ulong(volatile unsigned long *, 6971eb6505Sad unsigned long, unsigned long); 70def3fb26Sad 71b07ec3fcSad #endif /* __MUTEX_PRIVATE */ 72b07ec3fcSad 73b07ec3fcSad #endif /* _SPARC_MUTEX_H_ */ 74