summaryrefslogtreecommitdiff
path: root/sys/arch/alpha
diff options
context:
space:
mode:
authorMartin Reindl <martin@cvs.openbsd.org>2007-05-05 21:05:44 +0000
committerMartin Reindl <martin@cvs.openbsd.org>2007-05-05 21:05:44 +0000
commitdf17b03c9304692118521e98563ea89a28cb0128 (patch)
tree88f92be88eac3006964a1073e26cf6be6a83e424 /sys/arch/alpha
parentf44e4657d9901268c3b181411d096d24edc87bd5 (diff)
simple single-processor only mutex implementation
ok miod@
Diffstat (limited to 'sys/arch/alpha')
-rw-r--r--sys/arch/alpha/alpha/mutex.c66
-rw-r--r--sys/arch/alpha/conf/files.alpha3
-rw-r--r--sys/arch/alpha/include/_types.h3
-rw-r--r--sys/arch/alpha/include/mutex.h59
4 files changed, 129 insertions, 2 deletions
diff --git a/sys/arch/alpha/alpha/mutex.c b/sys/arch/alpha/alpha/mutex.c
new file mode 100644
index 00000000000..6aa273d4838
--- /dev/null
+++ b/sys/arch/alpha/alpha/mutex.c
@@ -0,0 +1,66 @@
+/* $OpenBSD: mutex.c,v 1.1 2007/05/05 21:05:43 martin 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_oldipl = 0;
+ mtx->mtx_wantipl = wantipl;
+ mtx->mtx_lock = 0;
+}
+
+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;
+}
+
+void
+mtx_leave(struct mutex *mtx)
+{
+ MUTEX_ASSERT_LOCKED(mtx);
+ mtx->mtx_lock = 0;
+ if (mtx->mtx_wantipl != IPL_NONE)
+ splx(mtx->mtx_oldipl);
+}
diff --git a/sys/arch/alpha/conf/files.alpha b/sys/arch/alpha/conf/files.alpha
index a56f1413fcd..8d381894645 100644
--- a/sys/arch/alpha/conf/files.alpha
+++ b/sys/arch/alpha/conf/files.alpha
@@ -1,4 +1,4 @@
-# $OpenBSD: files.alpha,v 1.79 2007/04/13 08:31:50 martin Exp $
+# $OpenBSD: files.alpha,v 1.80 2007/05/05 21:05:43 martin Exp $
# $NetBSD: files.alpha,v 1.32 1996/11/25 04:03:21 cgd Exp $
#
# alpha-specific configuration info
@@ -305,6 +305,7 @@ file arch/alpha/alpha/fp_complete.c !no_ieee
file arch/alpha/alpha/vm_machdep.c
file arch/alpha/alpha/disksubr.c
file arch/alpha/dev/bus_dma.c
+file arch/alpha/alpha/mutex.c
#
# Network protocol checksum routines
diff --git a/sys/arch/alpha/include/_types.h b/sys/arch/alpha/include/_types.h
index 480e591a94a..8c9072e020a 100644
--- a/sys/arch/alpha/include/_types.h
+++ b/sys/arch/alpha/include/_types.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: _types.h,v 1.4 2007/04/23 10:07:43 art Exp $ */
+/* $OpenBSD: _types.h,v 1.5 2007/05/05 21:05:43 martin Exp $ */
/*-
* Copyright (c) 1990, 1993
@@ -123,5 +123,6 @@ typedef void * __wctype_t;
#define __HAVE_CPUINFO
#define __HAVE_GENERIC_SOFT_INTERRUPTS
#define __HAVE_TIMECOUNTER
+#define __HAVE_MUTEX */
#endif /* _ALPHA__TYPES_H_ */
diff --git a/sys/arch/alpha/include/mutex.h b/sys/arch/alpha/include/mutex.h
new file mode 100644
index 00000000000..5740ee0fab8
--- /dev/null
+++ b/sys/arch/alpha/include/mutex.h
@@ -0,0 +1,59 @@
+/* $OpenBSD: mutex.h,v 1.1 2007/05/05 21:05:43 martin 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 _ALPHA_MUTEX_H_
+#define _ALPHA_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), 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 /* _ALPHA_MUTEX_H_ */