diff options
author | David Gwynne <dlg@cvs.openbsd.org> | 2015-01-06 00:38:33 +0000 |
---|---|---|
committer | David Gwynne <dlg@cvs.openbsd.org> | 2015-01-06 00:38:33 +0000 |
commit | bec32d11f8ef49df54451e98701d94a28dbf6bda (patch) | |
tree | 8c85073625e239fe572aa42ca57efed22402be35 /sys/arch | |
parent | 8579e5fc251891449b3073f331fcb4fd8110f47c (diff) |
implement atomic_swap_{uint,ulong,ptr) and some md variants. use these
to replace x86_atomic_testset_{u32,u64}.
help from guenther@ kettenis@
ok kettenis@
Diffstat (limited to 'sys/arch')
-rw-r--r-- | sys/arch/amd64/amd64/ipi.c | 4 | ||||
-rw-r--r-- | sys/arch/amd64/amd64/pmap.c | 4 | ||||
-rw-r--r-- | sys/arch/amd64/include/atomic.h | 62 |
3 files changed, 50 insertions, 20 deletions
diff --git a/sys/arch/amd64/amd64/ipi.c b/sys/arch/amd64/amd64/ipi.c index 6f568411e08..48090bb79da 100644 --- a/sys/arch/amd64/amd64/ipi.c +++ b/sys/arch/amd64/amd64/ipi.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ipi.c,v 1.11 2012/12/05 23:20:10 deraadt Exp $ */ +/* $OpenBSD: ipi.c,v 1.12 2015/01/06 00:38:32 dlg Exp $ */ /* $NetBSD: ipi.c,v 1.2 2003/03/01 13:05:37 fvdl Exp $ */ /*- @@ -103,7 +103,7 @@ x86_ipi_handler(void) u_int32_t pending; int bit; - pending = x86_atomic_testset_u32(&ci->ci_ipis, 0); + pending = atomic_swap_uint(&ci->ci_ipis, 0); for (bit = 0; bit < X86_NIPI && pending; bit++) { if (pending & (1<<bit)) { diff --git a/sys/arch/amd64/amd64/pmap.c b/sys/arch/amd64/amd64/pmap.c index da7b0e8e876..11a69b75e98 100644 --- a/sys/arch/amd64/amd64/pmap.c +++ b/sys/arch/amd64/amd64/pmap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pmap.c,v 1.83 2014/12/23 07:42:46 tedu Exp $ */ +/* $OpenBSD: pmap.c,v 1.84 2015/01/06 00:38:32 dlg Exp $ */ /* $NetBSD: pmap.c,v 1.3 2003/05/08 18:13:13 thorpej Exp $ */ /* @@ -216,7 +216,7 @@ pd_entry_t *normal_pdes[] = PDES_INITIALIZER; #define COUNT(x) /* nothing */ -#define pmap_pte_set(p, n) x86_atomic_testset_u64(p, n) +#define pmap_pte_set(p, n) atomic_swap_64(p, n) #define pmap_pte_clearbits(p, b) x86_atomic_clearbits_u64(p, b) #define pmap_pte_setbits(p, b) x86_atomic_setbits_u64(p, b) diff --git a/sys/arch/amd64/include/atomic.h b/sys/arch/amd64/include/atomic.h index ae85d5502be..4ec437c2c82 100644 --- a/sys/arch/amd64/include/atomic.h +++ b/sys/arch/amd64/include/atomic.h @@ -1,4 +1,4 @@ -/* $OpenBSD: atomic.h,v 1.16 2014/10/08 19:40:28 sf Exp $ */ +/* $OpenBSD: atomic.h,v 1.17 2015/01/06 00:38:32 dlg Exp $ */ /* $NetBSD: atomic.h,v 1.1 2003/04/26 18:39:37 fvdl Exp $ */ /* @@ -88,6 +88,51 @@ _atomic_cas_ptr(volatile void *p, void *e, void *n) } #define atomic_cas_ptr(_p, _e, _n) _atomic_cas_ptr((_p), (_e), (_n)) +static inline unsigned int +_atomic_swap_uint(volatile unsigned int *p, unsigned int n) +{ + __asm volatile("xchgl %0, %1" + : "=a" (n), "=m" (*p) + : "0" (n), "m" (*p)); + + return (n); +} +#define atomic_swap_uint(_p, _n) _atomic_swap_uint((_p), (_n)) +#define atomic_swap_32(_p, _n) _atomic_swap_uint((_p), (_n)) + +static inline unsigned long +_atomic_swap_ulong(volatile unsigned long *p, unsigned long n) +{ + __asm volatile("xchgq %0, %1" + : "=a" (n), "=m" (*p) + : "0" (n), "m" (*p)); + + return (n); +} +#define atomic_swap_ulong(_p, _n) _atomic_swap_ulong((_p), (_n)) + +static inline uint64_t +_atomic_swap_64(volatile uint64_t *p, uint64_t n) +{ + __asm volatile("xchgq %0, %1" + : "=a" (n), "=m" (*p) + : "0" (n), "m" (*p)); + + return (n); +} +#define atomic_swap_64(_p, _n) _atomic_swap_64((_p), (_n)) + +static inline void * +_atomic_swap_ptr(volatile void *p, void *n) +{ + __asm volatile("xchgq %0, %1" + : "=a" (n), "=m" (*(unsigned long *)p) + : "0" (n), "m" (*(unsigned long *)p)); + + return (n); +} +#define atomic_swap_ptr(_p, _n) _atomic_swap_ptr((_p), (_n)) + static inline void _atomic_inc_int(volatile unsigned int *p) { @@ -236,21 +281,6 @@ _atomic_sub_long_nv(volatile unsigned long *p, unsigned long v) #define virtio_membar_consumer() __membar("") #define virtio_membar_sync() __membar("mfence") -static __inline u_int64_t -x86_atomic_testset_u64(volatile u_int64_t *ptr, u_int64_t val) -{ - __asm__ volatile ("xchgq %0,(%2)" :"=r" (val):"0" (val),"r" (ptr)); - return val; -} - -static __inline u_int32_t -x86_atomic_testset_u32(volatile u_int32_t *ptr, u_int32_t val) -{ - __asm__ volatile ("xchgl %0,(%2)" :"=r" (val):"0" (val),"r" (ptr)); - return val; -} - - static __inline void x86_atomic_setbits_u32(volatile u_int32_t *ptr, u_int32_t bits) { |