summaryrefslogtreecommitdiff
path: root/sys/arch/sgi
diff options
context:
space:
mode:
Diffstat (limited to 'sys/arch/sgi')
-rw-r--r--sys/arch/sgi/conf/files.sgi3
-rw-r--r--sys/arch/sgi/include/_types.h4
-rw-r--r--sys/arch/sgi/include/mutex.h59
-rw-r--r--sys/arch/sgi/sgi/mutex.c68
4 files changed, 132 insertions, 2 deletions
diff --git a/sys/arch/sgi/conf/files.sgi b/sys/arch/sgi/conf/files.sgi
index ee476b97502..9c9e343ff0c 100644
--- a/sys/arch/sgi/conf/files.sgi
+++ b/sys/arch/sgi/conf/files.sgi
@@ -1,4 +1,4 @@
-# $OpenBSD: files.sgi,v 1.10 2005/05/01 21:36:57 brad Exp $
+# $OpenBSD: files.sgi,v 1.11 2007/05/01 18:59:40 miod Exp $
#
# maxpartitions must be first item in files.${ARCH}
#
@@ -11,6 +11,7 @@ maxusers 2 8 64
file arch/sgi/sgi/autoconf.c
file arch/sgi/sgi/conf.c
file arch/sgi/sgi/machdep.c
+file arch/sgi/sgi/mutex.c
file arch/sgi/sgi/sginode.c tgt_origin200 | tgt_origin2000
file arch/sgi/dev/wscons_machdep.c wsdisplay
diff --git a/sys/arch/sgi/include/_types.h b/sys/arch/sgi/include/_types.h
index 0e704df4446..cb7a8cf8164 100644
--- a/sys/arch/sgi/include/_types.h
+++ b/sys/arch/sgi/include/_types.h
@@ -1,4 +1,6 @@
-/* $OpenBSD: _types.h,v 1.1 2006/01/06 18:50:09 millert Exp $ */
+/* $OpenBSD: _types.h,v 1.2 2007/05/01 18:59:40 miod Exp $ */
/* public domain */
#include <mips64/_types.h>
+
+#define __HAVE_MUTEX
diff --git a/sys/arch/sgi/include/mutex.h b/sys/arch/sgi/include/mutex.h
new file mode 100644
index 00000000000..2c5d340d309
--- /dev/null
+++ b/sys/arch/sgi/include/mutex.h
@@ -0,0 +1,59 @@
+/* $OpenBSD: mutex.h,v 1.1 2007/05/01 18:59:40 miod Exp $ */
+
+/*
+ * Copyright (c) 2004 Artur Grabowski <art@openbsd.org>
+ * 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_oldcpl;
+};
+
+void mtx_init(struct mutex *, int);
+
+#define MUTEX_INITIALIZER(ipl) { 0, (ipl), 0 }
+
+#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
+
+#endif
diff --git a/sys/arch/sgi/sgi/mutex.c b/sys/arch/sgi/sgi/mutex.c
new file mode 100644
index 00000000000..bfaf0550d6a
--- /dev/null
+++ b/sys/arch/sgi/sgi/mutex.c
@@ -0,0 +1,68 @@
+/* $OpenBSD: mutex.c,v 1.1 2007/05/01 18:59:40 miod Exp $ */
+
+/*
+ * Copyright (c) 2004 Artur Grabowski <art@openbsd.org>
+ * 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 <sys/param.h>
+#include <sys/mutex.h>
+#include <sys/systm.h>
+
+#include <machine/intr.h>
+
+#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;
+ /* We can't access imask[] here, since MUTEX_INITIALIZER can't. */
+ mtx->mtx_wantipl = wantipl;
+ mtx->mtx_oldcpl = 0;
+}
+
+void
+mtx_enter(struct mutex *mtx)
+{
+ if (mtx->mtx_wantipl != IPL_NONE)
+ mtx->mtx_oldcpl = splraise(imask[mtx->mtx_wantipl]);
+
+ MUTEX_ASSERT_UNLOCKED(mtx);
+ mtx->mtx_lock = 1;
+}
+
+void
+mtx_leave(struct mutex *mtx)
+{
+ MUTEX_ASSERT_LOCKED(mtx);
+ mtx->mtx_lock = 0;
+ if (mtx->mtx_wantipl != 0)
+ splx(mtx->mtx_oldcpl);
+}