summaryrefslogtreecommitdiff
path: root/sys/arch
diff options
context:
space:
mode:
authorJoel Sing <jsing@cvs.openbsd.org>2010-06-27 00:04:45 +0000
committerJoel Sing <jsing@cvs.openbsd.org>2010-06-27 00:04:45 +0000
commit6a677f4aafb5256874906506b8a707cf02a34919 (patch)
treed2043a53567e30c60513533b56b7c8573ef3cb2f /sys/arch
parentce20bdbb451ed64545ee2aba25137be08d93bbfa (diff)
Use a mutex to make atomic operations atomic on multiprocessor kernels.
ok kettenis@
Diffstat (limited to 'sys/arch')
-rw-r--r--sys/arch/hppa/hppa/machdep.c6
-rw-r--r--sys/arch/hppa/include/atomic.h21
2 files changed, 25 insertions, 2 deletions
diff --git a/sys/arch/hppa/hppa/machdep.c b/sys/arch/hppa/hppa/machdep.c
index 1553d32f735..c2a74de56ea 100644
--- a/sys/arch/hppa/hppa/machdep.c
+++ b/sys/arch/hppa/hppa/machdep.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: machdep.c,v 1.187 2010/06/10 17:54:13 deraadt Exp $ */
+/* $OpenBSD: machdep.c,v 1.188 2010/06/27 00:04:44 jsing Exp $ */
/*
* Copyright (c) 1999-2003 Michael Shalayeff
@@ -155,6 +155,10 @@ dev_t bootdev;
int physmem, resvmem, resvphysmem, esym;
paddr_t avail_end;
+#ifdef MULTIPROCESSOR
+struct mutex mtx_atomic = MUTEX_INITIALIZER(IPL_NONE);
+#endif
+
/*
* Things for MI glue to stick on.
*/
diff --git a/sys/arch/hppa/include/atomic.h b/sys/arch/hppa/include/atomic.h
index 16514db9153..ca98933c21d 100644
--- a/sys/arch/hppa/include/atomic.h
+++ b/sys/arch/hppa/include/atomic.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: atomic.h,v 1.3 2007/04/26 20:52:48 miod Exp $ */
+/* $OpenBSD: atomic.h,v 1.4 2010/06/27 00:04:44 jsing Exp $ */
/* Public Domain */
@@ -7,6 +7,17 @@
#if defined(_KERNEL)
+#include <sys/mutex.h>
+
+#ifdef MULTIPROCESSOR
+extern struct mutex mtx_atomic;
+#define ATOMIC_LOCK mtx_enter(&mtx_atomic)
+#define ATOMIC_UNLOCK mtx_leave(&mtx_atomic)
+#else
+#define ATOMIC_LOCK
+#define ATOMIC_UNLOCK
+#endif
+
static __inline void
atomic_setbits_int(__volatile unsigned int *uip, unsigned int v)
{
@@ -14,7 +25,9 @@ atomic_setbits_int(__volatile unsigned int *uip, unsigned int v)
__asm __volatile("mfctl %%cr15, %0": "=r" (eiem));
__asm __volatile("mtctl %r0, %cr15");
+ ATOMIC_LOCK;
*uip |= v;
+ ATOMIC_UNLOCK;
__asm __volatile("mtctl %0, %%cr15":: "r" (eiem));
}
@@ -25,7 +38,9 @@ atomic_clearbits_int(__volatile unsigned int *uip, unsigned int v)
__asm __volatile("mfctl %%cr15, %0": "=r" (eiem));
__asm __volatile("mtctl %r0, %cr15");
+ ATOMIC_LOCK;
*uip &= ~v;
+ ATOMIC_UNLOCK;
__asm __volatile("mtctl %0, %%cr15":: "r" (eiem));
}
@@ -36,7 +51,9 @@ atomic_setbits_long(__volatile unsigned long *uip, unsigned long v)
__asm __volatile("mfctl %%cr15, %0": "=r" (eiem));
__asm __volatile("mtctl %r0, %cr15");
+ ATOMIC_LOCK;
*uip |= v;
+ ATOMIC_UNLOCK;
__asm __volatile("mtctl %0, %%cr15":: "r" (eiem));
}
@@ -47,7 +64,9 @@ atomic_clearbits_long(__volatile unsigned long *uip, unsigned long v)
__asm __volatile("mfctl %%cr15, %0": "=r" (eiem));
__asm __volatile("mtctl %r0, %cr15");
+ ATOMIC_LOCK;
*uip &= ~v;
+ ATOMIC_UNLOCK;
__asm __volatile("mtctl %0, %%cr15":: "r" (eiem));
}