Index: mips64/conf/files.mips64 =================================================================== RCS file: /cvs/src/sys/arch/mips64/conf/files.mips64,v retrieving revision 1.22 diff -u -p -r1.22 files.mips64 --- mips64/conf/files.mips64 22 Mar 2014 00:01:04 -0000 1.22 +++ mips64/conf/files.mips64 2 Jul 2015 09:42:49 -0000 @@ -13,6 +13,7 @@ file arch/mips64/mips64/softintr.c file arch/mips64/mips64/sys_machdep.c file arch/mips64/mips64/trap.c file arch/mips64/mips64/vm_machdep.c +file arch/mips64/mips64/mutex.c file arch/mips64/mips64/cache_loongson2.c cpu_loongson2 file arch/mips64/mips64/cache_octeon.c cpu_octeon Index: mips64/include/mutex.h =================================================================== RCS file: mips64/include/mutex.h diff -N mips64/include/mutex.h --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ mips64/include/mutex.h 2 Jul 2015 09:42:49 -0000 @@ -0,0 +1,73 @@ +/* $OpenBSD: mutex.h,v 1.8 2015/04/21 01:31:51 dlg Exp $ */ + +/* + * Copyright (c) 2004 Artur Grabowski + * 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. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED ``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_MUTEX_H_ +#define _MACHINE_MUTEX_H_ + +struct mutex { + void *mtx_owner; + int mtx_wantipl; + int mtx_oldipl; +}; + +/* + * To prevent lock ordering problems with the kernel lock, we need to + * make sure we block all interrupts that can grab the kernel lock. + * The simplest way to achieve this is to make sure mutexes always + * raise the interrupt priority level to the highest level that has + * interrupts that grab the kernel lock. + */ +#ifdef MULTIPROCESSOR +#define __MUTEX_IPL(ipl) \ + (((ipl) > IPL_NONE && (ipl) < IPL_MPLFLOOR) ? IPL_MPLFLOOR : (ipl)) +#else +#define __MUTEX_IPL(ipl) (ipl) +#endif + +#define MUTEX_INITIALIZER(ipl) { NULL, __MUTEX_IPL((ipl)), IPL_NONE } + +void __mtx_init(struct mutex *, int); +#define mtx_init(mtx, ipl) __mtx_init((mtx), __MUTEX_IPL((ipl))) + +#ifdef DIAGNOSTIC +#define MUTEX_ASSERT_LOCKED(mtx) do { \ + if ((mtx)->mtx_owner != curcpu()) \ + panic("mutex %p not held in %s", (mtx), __func__); \ +} while (0) + +#define MUTEX_ASSERT_UNLOCKED(mtx) do { \ + if ((mtx)->mtx_owner == curcpu()) \ + panic("mutex %p held in %s", (mtx), __func__); \ +} while (0) +#else +#define MUTEX_ASSERT_LOCKED(mtx) do { } while (0) +#define MUTEX_ASSERT_UNLOCKED(mtx) do { } while (0) +#endif + +#define MUTEX_OLDIPL(mtx) (mtx)->mtx_oldipl + +#endif Index: mips64/mips64/mutex.c =================================================================== RCS file: mips64/mips64/mutex.c diff -N mips64/mips64/mutex.c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ mips64/mips64/mutex.c 2 Jul 2015 09:42:49 -0000 @@ -0,0 +1,128 @@ +/* $OpenBSD: mutex.c,v 1.15 2015/04/21 01:31:51 dlg Exp $ */ + +/* + * Copyright (c) 2004 Artur Grabowski + * 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. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED ``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. + */ + +#include +#include +#include +#include + +#include + + +void +__mtx_init(struct mutex *mtx, int wantipl) +{ + mtx->mtx_owner = NULL; + mtx->mtx_wantipl = wantipl; + mtx->mtx_oldipl = IPL_NONE; +} + +#ifdef MULTIPROCESSOR +void +mtx_enter(struct mutex *mtx) +{ + while (mtx_enter_try(mtx) == 0) + ; +} + +int +mtx_enter_try(struct mutex *mtx) +{ + struct cpu_info *owner, *ci = curcpu(); + int s; + + if (mtx->mtx_wantipl != IPL_NONE) + s = splraise(mtx->mtx_wantipl); + + owner = atomic_cas_ptr(&mtx->mtx_owner, NULL, ci); +#ifdef DIAGNOSTIC + if (__predict_false(owner == ci)) + panic("mtx %p: locking against myself", mtx); +#endif + if (owner == NULL) { + if (mtx->mtx_wantipl != IPL_NONE) + mtx->mtx_oldipl = s; +#ifdef DIAGNOSTIC + ci->ci_mutex_level++; +#endif + membar_enter(); + return (1); + } + + if (mtx->mtx_wantipl != IPL_NONE) + splx(s); + + return (0); +} +#else +void +mtx_enter(struct mutex *mtx) +{ + struct cpu_info *ci = curcpu(); + +#ifdef DIAGNOSTIC + if (__predict_false(mtx->mtx_owner == ci)) + panic("mtx %p: locking against myself", mtx); +#endif + + if (mtx->mtx_wantipl != IPL_NONE) + mtx->mtx_oldipl = splraise(mtx->mtx_wantipl); + + mtx->mtx_owner = ci; + +#ifdef DIAGNOSTIC + ci->ci_mutex_level++; +#endif +} + +int +mtx_enter_try(struct mutex *mtx) +{ + mtx_enter(mtx); + return (1); +} +#endif + +void +mtx_leave(struct mutex *mtx) +{ + int s; + + MUTEX_ASSERT_LOCKED(mtx); + +#ifdef MULTIPROCESSOR + membar_exit(); +#endif +#ifdef DIAGNOSTIC + curcpu()->ci_mutex_level--; +#endif + + s = mtx->mtx_oldipl; + mtx->mtx_owner = NULL; + if (mtx->mtx_wantipl != IPL_NONE) + splx(s); +} Index: sgi/conf/files.sgi =================================================================== RCS file: /cvs/src/sys/arch/sgi/conf/files.sgi,v retrieving revision 1.52 diff -u -p -r1.52 files.sgi --- sgi/conf/files.sgi 4 Nov 2013 14:07:16 -0000 1.52 +++ sgi/conf/files.sgi 2 Jul 2015 09:42:49 -0000 @@ -23,7 +23,6 @@ file arch/sgi/sgi/ip32_machdep.c tgt_o2 file arch/sgi/sgi/l1.c tgt_origin file arch/sgi/sgi/machdep.c file arch/sgi/sgi/mainbus.c -file arch/sgi/sgi/mutex.c file arch/sgi/sgi/sginode.c tgt_origin file arch/sgi/sgi/wscons_machdep.c wsdisplay Index: sgi/include/intr.h =================================================================== RCS file: /cvs/src/sys/arch/sgi/include/intr.h,v retrieving revision 1.43 diff -u -p -r1.43 intr.h --- sgi/include/intr.h 17 May 2013 19:38:52 -0000 1.43 +++ sgi/include/intr.h 2 Jul 2015 09:42:49 -0000 @@ -59,6 +59,8 @@ #define IPL_IPI 8 /* interprocessor interrupt */ #define NIPLS 9 /* Number of levels */ +#define IPL_MPFLOOR IPL_TTY + /* Interrupt priority 'flags'. */ #define IPL_MPSAFE 0 /* no "mpsafe" interrupts */ Index: sgi/include/mutex.h =================================================================== RCS file: /cvs/src/sys/arch/sgi/include/mutex.h,v retrieving revision 1.8 diff -u -p -r1.8 mutex.h --- sgi/include/mutex.h 21 Apr 2015 01:31:51 -0000 1.8 +++ sgi/include/mutex.h 2 Jul 2015 09:42:49 -0000 @@ -1,73 +1,3 @@ /* $OpenBSD: mutex.h,v 1.8 2015/04/21 01:31:51 dlg Exp $ */ -/* - * Copyright (c) 2004 Artur Grabowski - * 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. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED ``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_MUTEX_H_ -#define _MACHINE_MUTEX_H_ - -struct mutex { - void *mtx_owner; - int mtx_wantipl; - int mtx_oldipl; -}; - -/* - * To prevent lock ordering problems with the kernel lock, we need to - * make sure we block all interrupts that can grab the kernel lock. - * The simplest way to achieve this is to make sure mutexes always - * raise the interrupt priority level to the highest level that has - * interrupts that grab the kernel lock. - */ -#ifdef MULTIPROCESSOR -#define __MUTEX_IPL(ipl) \ - (((ipl) > IPL_NONE && (ipl) < IPL_TTY) ? IPL_TTY : (ipl)) -#else -#define __MUTEX_IPL(ipl) (ipl) -#endif - -#define MUTEX_INITIALIZER(ipl) { NULL, __MUTEX_IPL((ipl)), IPL_NONE } - -void __mtx_init(struct mutex *, int); -#define mtx_init(mtx, ipl) __mtx_init((mtx), __MUTEX_IPL((ipl))) - -#ifdef DIAGNOSTIC -#define MUTEX_ASSERT_LOCKED(mtx) do { \ - if ((mtx)->mtx_owner != curcpu()) \ - panic("mutex %p not held in %s", (mtx), __func__); \ -} while (0) - -#define MUTEX_ASSERT_UNLOCKED(mtx) do { \ - if ((mtx)->mtx_owner == curcpu()) \ - panic("mutex %p held in %s", (mtx), __func__); \ -} while (0) -#else -#define MUTEX_ASSERT_LOCKED(mtx) do { } while (0) -#define MUTEX_ASSERT_UNLOCKED(mtx) do { } while (0) -#endif - -#define MUTEX_OLDIPL(mtx) (mtx)->mtx_oldipl - -#endif +#include Index: sgi/sgi/mutex.c =================================================================== RCS file: sgi/sgi/mutex.c diff -N sgi/sgi/mutex.c --- sgi/sgi/mutex.c 21 Apr 2015 01:31:51 -0000 1.15 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,128 +0,0 @@ -/* $OpenBSD: mutex.c,v 1.15 2015/04/21 01:31:51 dlg Exp $ */ - -/* - * Copyright (c) 2004 Artur Grabowski - * 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. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED ``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. - */ - -#include -#include -#include -#include - -#include - - -void -__mtx_init(struct mutex *mtx, int wantipl) -{ - mtx->mtx_owner = NULL; - mtx->mtx_wantipl = wantipl; - mtx->mtx_oldipl = IPL_NONE; -} - -#ifdef MULTIPROCESSOR -void -mtx_enter(struct mutex *mtx) -{ - while (mtx_enter_try(mtx) == 0) - ; -} - -int -mtx_enter_try(struct mutex *mtx) -{ - struct cpu_info *owner, *ci = curcpu(); - int s; - - if (mtx->mtx_wantipl != IPL_NONE) - s = splraise(mtx->mtx_wantipl); - - owner = atomic_cas_ptr(&mtx->mtx_owner, NULL, ci); -#ifdef DIAGNOSTIC - if (__predict_false(owner == ci)) - panic("mtx %p: locking against myself", mtx); -#endif - if (owner == NULL) { - if (mtx->mtx_wantipl != IPL_NONE) - mtx->mtx_oldipl = s; -#ifdef DIAGNOSTIC - ci->ci_mutex_level++; -#endif - membar_enter(); - return (1); - } - - if (mtx->mtx_wantipl != IPL_NONE) - splx(s); - - return (0); -} -#else -void -mtx_enter(struct mutex *mtx) -{ - struct cpu_info *ci = curcpu(); - -#ifdef DIAGNOSTIC - if (__predict_false(mtx->mtx_owner == ci)) - panic("mtx %p: locking against myself", mtx); -#endif - - if (mtx->mtx_wantipl != IPL_NONE) - mtx->mtx_oldipl = splraise(mtx->mtx_wantipl); - - mtx->mtx_owner = ci; - -#ifdef DIAGNOSTIC - ci->ci_mutex_level++; -#endif -} - -int -mtx_enter_try(struct mutex *mtx) -{ - mtx_enter(mtx); - return (1); -} -#endif - -void -mtx_leave(struct mutex *mtx) -{ - int s; - - MUTEX_ASSERT_LOCKED(mtx); - -#ifdef MULTIPROCESSOR - membar_exit(); -#endif -#ifdef DIAGNOSTIC - curcpu()->ci_mutex_level--; -#endif - - s = mtx->mtx_oldipl; - mtx->mtx_owner = NULL; - if (mtx->mtx_wantipl != IPL_NONE) - splx(s); -} Index: octeon/conf/files.octeon =================================================================== RCS file: /cvs/src/sys/arch/octeon/conf/files.octeon,v retrieving revision 1.20 diff -u -p -r1.20 files.octeon --- octeon/conf/files.octeon 11 Feb 2015 00:15:41 -0000 1.20 +++ octeon/conf/files.octeon 2 Jul 2015 09:42:49 -0000 @@ -19,7 +19,6 @@ file arch/octeon/octeon/disksubr.c disk file arch/octeon/octeon/lock_machdep.c multiprocessor file arch/octeon/octeon/machdep.c file arch/mips64/mips64/mips64r2.S -file arch/octeon/octeon/mutex.c include "dev/ata/files.ata" include "dev/atapiscsi/files.atapiscsi" Index: octeon/include/intr.h =================================================================== RCS file: /cvs/src/sys/arch/octeon/include/intr.h,v retrieving revision 1.3 diff -u -p -r1.3 intr.h --- octeon/include/intr.h 17 May 2013 19:38:52 -0000 1.3 +++ octeon/include/intr.h 2 Jul 2015 09:42:49 -0000 @@ -59,6 +59,8 @@ #define IPL_IPI 8 /* interprocessor interrupt */ #define NIPLS 9 /* Number of levels */ +#define IPL_MPFLOOR IPL_TTY + /* Interrupt priority 'flags'. */ #define IPL_MPSAFE 0 /* no "mpsafe" interrupts */ Index: octeon/include/mutex.h =================================================================== RCS file: /cvs/src/sys/arch/octeon/include/mutex.h,v retrieving revision 1.2 diff -u -p -r1.2 mutex.h --- octeon/include/mutex.h 14 Jul 2014 10:23:58 -0000 1.2 +++ octeon/include/mutex.h 2 Jul 2015 09:42:49 -0000 @@ -1,59 +1,3 @@ /* $OpenBSD: mutex.h,v 1.2 2014/07/14 10:23:58 jasper Exp $ */ -/* - * Copyright (c) 2004 Artur Grabowski - * 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. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED ``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_MUTEX_H_ -#define _MACHINE_MUTEX_H_ - -struct mutex { - int mtx_lock; - int mtx_wantipl; - int mtx_oldipl; - void *mtx_owner; -}; - -void mtx_init(struct mutex *, int); - -#define MUTEX_INITIALIZER(ipl) { 0, (ipl), IPL_NONE } - -#ifdef DIAGNOSTIC -#define MUTEX_ASSERT_LOCKED(mtx) do { \ - if ((mtx)->mtx_lock == 0) \ - panic("mutex %p not held in %s", (mtx), __func__); \ -} while (0) - -#define MUTEX_ASSERT_UNLOCKED(mtx) do { \ - if ((mtx)->mtx_lock != 0) \ - panic("mutex %p held in %s", (mtx), __func__); \ -} while (0) -#else -#define MUTEX_ASSERT_LOCKED(mtx) do { } while (0) -#define MUTEX_ASSERT_UNLOCKED(mtx) do { } while (0) -#endif - -#define MUTEX_OLDIPL(mtx) (mtx)->mtx_oldipl - -#endif +#include Index: octeon/octeon/mutex.c =================================================================== RCS file: octeon/octeon/mutex.c diff -N octeon/octeon/mutex.c --- octeon/octeon/mutex.c 26 Dec 2013 21:02:37 -0000 1.6 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,129 +0,0 @@ -/* $OpenBSD: mutex.c,v 1.6 2013/12/26 21:02:37 miod Exp $ */ - -/* - * Copyright (c) 2004 Artur Grabowski - * 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. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED ``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. - */ - -#include -#include -#include - -#include - -static inline int -try_lock(struct mutex *mtx) -{ -#ifdef MULTIPROCESSOR - int tmp, ret = 0; - - asm volatile ( - ".set noreorder\n" - "1:\n" - "ll %0, %2\n" /* tmp = mtx->mtx_lock */ - "bnez %0, 2f\n" - " li %1, 0\n" /* ret = 0 */ - "li %1, 1\n" /* ret = 1 */ - "sc %1, %2\n" /* mtx->mtx_lock = 1 */ - "beqz %1, 1b\n" /* update failed */ - " nop\n" - "2:\n" - ".set reorder\n" - : "+r"(tmp), "+r"(ret) - : "m"(mtx->mtx_lock)); - - return ret; -#else /* MULTIPROCESSOR */ - mtx->mtx_lock = 1; - return 1; -#endif /* MULTIPROCESSOR */ -} - -void -mtx_init(struct mutex *mtx, int wantipl) -{ - mtx->mtx_lock = 0; - mtx->mtx_wantipl = wantipl; - mtx->mtx_oldipl = IPL_NONE; -} - -void -mtx_enter(struct mutex *mtx) -{ - int s; - int i = 10000000; - for (;;) { - if (mtx->mtx_wantipl != IPL_NONE) - s = splraise(mtx->mtx_wantipl); - if (try_lock(mtx)) { - if (mtx->mtx_wantipl != IPL_NONE) - mtx->mtx_oldipl = s; - mtx->mtx_owner = curcpu(); -#ifdef DIAGNOSTIC - curcpu()->ci_mutex_level++; -#endif - return; - } - if (mtx->mtx_wantipl != IPL_NONE) - splx(s); - if(i-- <= 0) - panic("mtx_enter timed out\n"); - } -} - -int -mtx_enter_try(struct mutex *mtx) -{ - int s; - - if (mtx->mtx_wantipl != IPL_NONE) - s = splraise(mtx->mtx_wantipl); - if (try_lock(mtx)) { - if (mtx->mtx_wantipl != IPL_NONE) - mtx->mtx_oldipl = s; - mtx->mtx_owner = curcpu(); -#ifdef DIAGNOSTIC - curcpu()->ci_mutex_level++; -#endif - return 1; - } - if (mtx->mtx_wantipl != IPL_NONE) - splx(s); - return 0; -} - -void -mtx_leave(struct mutex *mtx) -{ - int s; - - MUTEX_ASSERT_LOCKED(mtx); -#ifdef DIAGNOSTIC - curcpu()->ci_mutex_level--; -#endif - s = mtx->mtx_oldipl; - mtx->mtx_owner = NULL; - mtx->mtx_lock = 0; - if (mtx->mtx_wantipl != IPL_NONE) - splx(s); -} Index: loongson/conf/files.loongson =================================================================== RCS file: /cvs/src/sys/arch/loongson/conf/files.loongson,v retrieving revision 1.18 diff -u -p -r1.18 files.loongson --- loongson/conf/files.loongson 11 Jul 2014 21:54:37 -0000 1.18 +++ loongson/conf/files.loongson 2 Jul 2015 09:42:49 -0000 @@ -23,7 +23,6 @@ file arch/loongson/loongson/isa_machdep. file arch/loongson/loongson/loongson2_machdep.c file arch/loongson/loongson/machdep.c file arch/loongson/loongson/hibernate_machdep.c hibernate -file arch/loongson/loongson/mutex.c file arch/loongson/loongson/pciide_machdep.c pciide file arch/loongson/loongson/pmon.c file arch/loongson/loongson/pmon32.S Index: loongson/include/intr.h =================================================================== RCS file: /cvs/src/sys/arch/loongson/include/intr.h,v retrieving revision 1.5 diff -u -p -r1.5 intr.h --- loongson/include/intr.h 17 May 2013 19:38:52 -0000 1.5 +++ loongson/include/intr.h 2 Jul 2015 09:42:49 -0000 @@ -59,6 +59,8 @@ #define IPL_HIGH 7 /* everything */ #define NIPLS 8 /* Number of levels */ +#define IPL_MPFLOOR IPL_TTY + /* Interrupt priority 'flags'. */ #define IPL_MPSAFE 0 /* no "mpsafe" interrupts */ Index: loongson/include/mutex.h =================================================================== RCS file: /cvs/src/sys/arch/loongson/include/mutex.h,v retrieving revision 1.1.1.1 diff -u -p -r1.1.1.1 mutex.h --- loongson/include/mutex.h 19 Nov 2009 19:04:26 -0000 1.1.1.1 +++ loongson/include/mutex.h 2 Jul 2015 09:42:49 -0000 @@ -1,61 +1,3 @@ /* $OpenBSD: mutex.h,v 1.1.1.1 2009/11/19 19:04:26 miod Exp $ */ -/* - * Copyright (c) 2004 Artur Grabowski - * 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. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED ``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_MUTEX_H_ -#define _MACHINE_MUTEX_H_ - -/* - * Simple non-mp implementation. - */ -struct mutex { - int mtx_lock; - int mtx_wantipl; - int mtx_oldipl; -}; - -void mtx_init(struct mutex *, int); - -#define MUTEX_INITIALIZER(ipl) { 0, (ipl), IPL_NONE } - -#ifdef DIAGNOSTIC -#define MUTEX_ASSERT_LOCKED(mtx) do { \ - if ((mtx)->mtx_lock == 0) \ - panic("mutex %p not held in %s", (mtx), __func__); \ -} while (0) - -#define MUTEX_ASSERT_UNLOCKED(mtx) do { \ - if ((mtx)->mtx_lock != 0) \ - panic("mutex %p held in %s", (mtx), __func__); \ -} while (0) -#else -#define MUTEX_ASSERT_LOCKED(mtx) do { } while (0) -#define MUTEX_ASSERT_UNLOCKED(mtx) do { } while (0) -#endif - -#define MUTEX_OLDIPL(mtx) (mtx)->mtx_oldipl - -#endif +#include Index: loongson/loongson/mutex.c =================================================================== RCS file: loongson/loongson/mutex.c diff -N loongson/loongson/mutex.c --- loongson/loongson/mutex.c 21 Apr 2011 04:34:12 -0000 1.4 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,88 +0,0 @@ -/* $OpenBSD: mutex.c,v 1.4 2011/04/21 04:34:12 miod Exp $ */ - -/* - * Copyright (c) 2004 Artur Grabowski - * 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. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED ``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. - */ - -#include -#include -#include - -#include - -#ifdef MULTIPROCESSOR -#error This code needs more work -#endif - -/* - * Single processor systems don't need any mutexes, but they need the spl - * raising semantics of the mutexes. - */ -void -mtx_init(struct mutex *mtx, int wantipl) -{ - mtx->mtx_lock = 0; - mtx->mtx_wantipl = wantipl; - mtx->mtx_oldipl = IPL_NONE; -} - -void -mtx_enter(struct mutex *mtx) -{ - if (mtx->mtx_wantipl != IPL_NONE) - mtx->mtx_oldipl = splraise(mtx->mtx_wantipl); - - MUTEX_ASSERT_UNLOCKED(mtx); - mtx->mtx_lock = 1; -#ifdef DIAGNOSTIC - curcpu()->ci_mutex_level++; -#endif -} - -int -mtx_enter_try(struct mutex *mtx) -{ - if (mtx->mtx_wantipl != IPL_NONE) - mtx->mtx_oldipl = splraise(mtx->mtx_wantipl); - - MUTEX_ASSERT_UNLOCKED(mtx); - mtx->mtx_lock = 1; -#ifdef DIAGNOSTIC - curcpu()->ci_mutex_level++; -#endif - - return 1; -} - -void -mtx_leave(struct mutex *mtx) -{ - MUTEX_ASSERT_LOCKED(mtx); -#ifdef DIAGNOSTIC - curcpu()->ci_mutex_level--; -#endif - mtx->mtx_lock = 0; - if (mtx->mtx_wantipl != IPL_NONE) - splx(mtx->mtx_oldipl); -}