Index: macppc/conf/files.macppc =================================================================== RCS file: /cvs/src/sys/arch/macppc/conf/files.macppc,v retrieving revision 1.82 diff -u -p -r1.82 files.macppc --- macppc/conf/files.macppc 2 Jun 2015 13:53:43 -0000 1.82 +++ macppc/conf/files.macppc 26 Jun 2015 06:10:11 -0000 @@ -11,7 +11,6 @@ file arch/macppc/macppc/autoconf.c file arch/macppc/macppc/clock.c file arch/macppc/macppc/conf.c file arch/macppc/macppc/disksubr.c disk -file arch/macppc/macppc/lock_machdep.c multiprocessor file arch/macppc/macppc/machdep.c file arch/macppc/macppc/wscons_machdep.c file arch/macppc/macppc/mem.c Index: macppc/include/mplock.h =================================================================== RCS file: /cvs/src/sys/arch/macppc/include/mplock.h,v retrieving revision 1.2 diff -u -p -r1.2 mplock.h --- macppc/include/mplock.h 7 Sep 2009 19:29:33 -0000 1.2 +++ macppc/include/mplock.h 26 Jun 2015 06:10:11 -0000 @@ -1,52 +1,3 @@ /* $OpenBSD: mplock.h,v 1.2 2009/09/07 19:29:33 miod Exp $ */ -/* - * Copyright (c) 2004 Niklas Hallqvist. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef _MACHINE_MPLOCK_H_ -#define _MACHINE_MPLOCK_H_ - -/* - * Really simple spinlock implementation with recursive capabilities. - * Correctness is paramount, no fancyness allowed. - */ - -struct __mp_lock { - volatile struct cpu_info *mpl_cpu; - volatile long mpl_count; -}; - -#ifndef _LOCORE - -void __mp_lock_init(struct __mp_lock *); -void __mp_lock(struct __mp_lock *); -void __mp_unlock(struct __mp_lock *); -int __mp_release_all(struct __mp_lock *); -int __mp_release_all_but_one(struct __mp_lock *); -void __mp_acquire_count(struct __mp_lock *, int); -int __mp_lock_held(struct __mp_lock *); - -#endif - -#endif /* !_MACHINE_MPLOCK_H */ +#include Index: macppc/macppc/lock_machdep.c =================================================================== RCS file: macppc/macppc/lock_machdep.c diff -N macppc/macppc/lock_machdep.c --- macppc/macppc/lock_machdep.c 7 Apr 2015 09:52:27 -0000 1.6 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,172 +0,0 @@ -/* $OpenBSD: lock_machdep.c,v 1.6 2015/04/07 09:52:27 mpi Exp $ */ - -/* - * Copyright (c) 2007 Artur Grabowski - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ - - -#include -#include -#include - -#include -#include - -#include - -void -__mp_lock_init(struct __mp_lock *lock) -{ - lock->mpl_cpu = NULL; - lock->mpl_count = 0; -} - -#if defined(MP_LOCKDEBUG) -#ifndef DDB -#error "MP_LOCKDEBUG requires DDB" -#endif - -/* CPU-dependent timing, needs this to be settable from ddb. */ -extern int __mp_lock_spinout; -#endif - -#define SPINLOCK_SPIN_HOOK /**/ - -static __inline void -__mp_lock_spin(struct __mp_lock *mpl) -{ -#ifndef MP_LOCKDEBUG - while (mpl->mpl_count != 0) - SPINLOCK_SPIN_HOOK; -#else - int ticks = __mp_lock_spinout; - - while (mpl->mpl_count != 0 && --ticks > 0) - SPINLOCK_SPIN_HOOK; - - if (ticks == 0) { - db_printf("__mp_lock(%p): lock spun out", mpl); - Debugger(); - } -#endif -} - -void -__mp_lock(struct __mp_lock *mpl) -{ - /* - * Please notice that mpl_count gets incremented twice for the - * first lock. This is on purpose. The way we release the lock - * in mp_unlock is to decrement the mpl_count and then check if - * the lock should be released. Since mpl_count is what we're - * spinning on, decrementing it in mpl_unlock to 0 means that - * we can't clear mpl_cpu, because we're no longer holding the - * lock. In theory mpl_cpu doesn't need to be cleared, but it's - * safer to clear it and besides, setting mpl_count to 2 on the - * first lock makes most of this code much simpler. - */ - - while (1) { - int s; - - s = ppc_intr_disable(); - if (__cpu_cas(&mpl->mpl_count, 0, 1) == 0) { - membar_enter(); - mpl->mpl_cpu = curcpu(); - } - - if (mpl->mpl_cpu == curcpu()) { - mpl->mpl_count++; - ppc_intr_enable(s); - break; - } - ppc_intr_enable(s); - - __mp_lock_spin(mpl); - } -} - -void -__mp_unlock(struct __mp_lock *mpl) -{ - int s; - -#ifdef MP_LOCKDEBUG - if (mpl->mpl_cpu != curcpu()) { - db_printf("__mp_unlock(%p): not held lock\n", mpl); - Debugger(); - } -#endif - - s = ppc_intr_disable(); - if (--mpl->mpl_count == 1) { - mpl->mpl_cpu = NULL; - membar_exit(); - mpl->mpl_count = 0; - } - ppc_intr_enable(s); -} - -int -__mp_release_all(struct __mp_lock *mpl) -{ - int rv = mpl->mpl_count - 1; - int s; - -#ifdef MP_LOCKDEBUG - if (mpl->mpl_cpu != curcpu()) { - db_printf("__mp_release_all(%p): not held lock\n", mpl); - Debugger(); - } -#endif - - s = ppc_intr_disable(); - mpl->mpl_cpu = NULL; - membar_exit(); - mpl->mpl_count = 0; - ppc_intr_enable(s); - - return (rv); -} - -int -__mp_release_all_but_one(struct __mp_lock *mpl) -{ - int rv = mpl->mpl_count - 2; - -#ifdef MP_LOCKDEBUG - if (mpl->mpl_cpu != curcpu()) { - db_printf("__mp_release_all_but_one(%p): not held lock\n", mpl); - Debugger(); - } -#endif - - mpl->mpl_count = 2; - - return (rv); -} - -void -__mp_acquire_count(struct __mp_lock *mpl, int count) -{ - while (count--) - __mp_lock(mpl); -} - -int -__mp_lock_held(struct __mp_lock *mpl) -{ - return mpl->mpl_cpu == curcpu(); -} Index: powerpc/conf/files.powerpc =================================================================== RCS file: /cvs/src/sys/arch/powerpc/conf/files.powerpc,v retrieving revision 1.50 diff -u -p -r1.50 files.powerpc --- powerpc/conf/files.powerpc 20 Jan 2015 18:34:00 -0000 1.50 +++ powerpc/conf/files.powerpc 26 Jun 2015 06:10:11 -0000 @@ -13,6 +13,7 @@ file arch/powerpc/powerpc/process_machde file arch/powerpc/powerpc/sys_machdep.c file arch/powerpc/powerpc/trap.c file arch/powerpc/powerpc/vm_machdep.c +file arch/powerpc/powerpc/lock_machdep.c multiprocessor file arch/powerpc/powerpc/mutex.S file arch/powerpc/powerpc/intr.c file arch/powerpc/powerpc/softintr.c Index: powerpc/include/mplock.h =================================================================== RCS file: powerpc/include/mplock.h diff -N powerpc/include/mplock.h --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ powerpc/include/mplock.h 26 Jun 2015 06:10:11 -0000 @@ -0,0 +1,52 @@ +/* $OpenBSD: mplock.h,v 1.2 2009/09/07 19:29:33 miod Exp $ */ + +/* + * Copyright (c) 2004 Niklas Hallqvist. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _MACHINE_MPLOCK_H_ +#define _MACHINE_MPLOCK_H_ + +/* + * Really simple spinlock implementation with recursive capabilities. + * Correctness is paramount, no fancyness allowed. + */ + +struct __mp_lock { + volatile struct cpu_info *mpl_cpu; + volatile long mpl_count; +}; + +#ifndef _LOCORE + +void __mp_lock_init(struct __mp_lock *); +void __mp_lock(struct __mp_lock *); +void __mp_unlock(struct __mp_lock *); +int __mp_release_all(struct __mp_lock *); +int __mp_release_all_but_one(struct __mp_lock *); +void __mp_acquire_count(struct __mp_lock *, int); +int __mp_lock_held(struct __mp_lock *); + +#endif + +#endif /* !_MACHINE_MPLOCK_H */ Index: powerpc/powerpc/lock_machdep.c =================================================================== RCS file: powerpc/powerpc/lock_machdep.c diff -N powerpc/powerpc/lock_machdep.c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ powerpc/powerpc/lock_machdep.c 26 Jun 2015 06:10:11 -0000 @@ -0,0 +1,172 @@ +/* $OpenBSD: lock_machdep.c,v 1.6 2015/04/07 09:52:27 mpi Exp $ */ + +/* + * Copyright (c) 2007 Artur Grabowski + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + + +#include +#include +#include + +#include +#include + +#include + +void +__mp_lock_init(struct __mp_lock *lock) +{ + lock->mpl_cpu = NULL; + lock->mpl_count = 0; +} + +#if defined(MP_LOCKDEBUG) +#ifndef DDB +#error "MP_LOCKDEBUG requires DDB" +#endif + +/* CPU-dependent timing, needs this to be settable from ddb. */ +extern int __mp_lock_spinout; +#endif + +#define SPINLOCK_SPIN_HOOK /**/ + +static __inline void +__mp_lock_spin(struct __mp_lock *mpl) +{ +#ifndef MP_LOCKDEBUG + while (mpl->mpl_count != 0) + SPINLOCK_SPIN_HOOK; +#else + int ticks = __mp_lock_spinout; + + while (mpl->mpl_count != 0 && --ticks > 0) + SPINLOCK_SPIN_HOOK; + + if (ticks == 0) { + db_printf("__mp_lock(%p): lock spun out", mpl); + Debugger(); + } +#endif +} + +void +__mp_lock(struct __mp_lock *mpl) +{ + /* + * Please notice that mpl_count gets incremented twice for the + * first lock. This is on purpose. The way we release the lock + * in mp_unlock is to decrement the mpl_count and then check if + * the lock should be released. Since mpl_count is what we're + * spinning on, decrementing it in mpl_unlock to 0 means that + * we can't clear mpl_cpu, because we're no longer holding the + * lock. In theory mpl_cpu doesn't need to be cleared, but it's + * safer to clear it and besides, setting mpl_count to 2 on the + * first lock makes most of this code much simpler. + */ + + while (1) { + int s; + + s = ppc_intr_disable(); + if (__cpu_cas(&mpl->mpl_count, 0, 1) == 0) { + membar_enter(); + mpl->mpl_cpu = curcpu(); + } + + if (mpl->mpl_cpu == curcpu()) { + mpl->mpl_count++; + ppc_intr_enable(s); + break; + } + ppc_intr_enable(s); + + __mp_lock_spin(mpl); + } +} + +void +__mp_unlock(struct __mp_lock *mpl) +{ + int s; + +#ifdef MP_LOCKDEBUG + if (mpl->mpl_cpu != curcpu()) { + db_printf("__mp_unlock(%p): not held lock\n", mpl); + Debugger(); + } +#endif + + s = ppc_intr_disable(); + if (--mpl->mpl_count == 1) { + mpl->mpl_cpu = NULL; + membar_exit(); + mpl->mpl_count = 0; + } + ppc_intr_enable(s); +} + +int +__mp_release_all(struct __mp_lock *mpl) +{ + int rv = mpl->mpl_count - 1; + int s; + +#ifdef MP_LOCKDEBUG + if (mpl->mpl_cpu != curcpu()) { + db_printf("__mp_release_all(%p): not held lock\n", mpl); + Debugger(); + } +#endif + + s = ppc_intr_disable(); + mpl->mpl_cpu = NULL; + membar_exit(); + mpl->mpl_count = 0; + ppc_intr_enable(s); + + return (rv); +} + +int +__mp_release_all_but_one(struct __mp_lock *mpl) +{ + int rv = mpl->mpl_count - 2; + +#ifdef MP_LOCKDEBUG + if (mpl->mpl_cpu != curcpu()) { + db_printf("__mp_release_all_but_one(%p): not held lock\n", mpl); + Debugger(); + } +#endif + + mpl->mpl_count = 2; + + return (rv); +} + +void +__mp_acquire_count(struct __mp_lock *mpl, int count) +{ + while (count--) + __mp_lock(mpl); +} + +int +__mp_lock_held(struct __mp_lock *mpl) +{ + return mpl->mpl_cpu == curcpu(); +}