diff options
author | David Gwynne <dlg@cvs.openbsd.org> | 2014-03-27 10:24:41 +0000 |
---|---|---|
committer | David Gwynne <dlg@cvs.openbsd.org> | 2014-03-27 10:24:41 +0000 |
commit | 4765a9879f097c62db1f6524a69875dbee6ee423 (patch) | |
tree | 07f763cda7374ad9af655b1f7b8a680613be811c /sys/arch/amd64 | |
parent | 978f5503e18817525bb661b9f8c39025db8c88e9 (diff) |
replace x86_atomic_cas_things with atomic_cas_foo equivalents.
ok kettenis@
Diffstat (limited to 'sys/arch/amd64')
-rw-r--r-- | sys/arch/amd64/amd64/acpi_machdep.c | 6 | ||||
-rw-r--r-- | sys/arch/amd64/amd64/pmap.c | 8 | ||||
-rw-r--r-- | sys/arch/amd64/include/atomic.h | 60 | ||||
-rw-r--r-- | sys/arch/amd64/include/lock.h | 4 |
4 files changed, 46 insertions, 32 deletions
diff --git a/sys/arch/amd64/amd64/acpi_machdep.c b/sys/arch/amd64/amd64/acpi_machdep.c index 76bd120b04a..ec4be74cfa7 100644 --- a/sys/arch/amd64/amd64/acpi_machdep.c +++ b/sys/arch/amd64/amd64/acpi_machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: acpi_machdep.c,v 1.58 2014/03/13 03:52:55 dlg Exp $ */ +/* $OpenBSD: acpi_machdep.c,v 1.59 2014/03/27 10:24:40 dlg Exp $ */ /* * Copyright (c) 2005 Thorsten Lockert <tholo@sigmasoft.com> * @@ -183,7 +183,7 @@ acpi_acquire_glk(uint32_t *lock) new = (old & ~GL_BIT_PENDING) | GL_BIT_OWNED; if ((old & GL_BIT_OWNED) != 0) new |= GL_BIT_PENDING; - } while (x86_atomic_cas_int32(lock, old, new) != old); + } while (atomic_cas_uint(lock, old, new) != old); return ((new & GL_BIT_PENDING) == 0); } @@ -201,7 +201,7 @@ acpi_release_glk(uint32_t *lock) do { old = *lock; new = old & ~(GL_BIT_PENDING | GL_BIT_OWNED); - } while (x86_atomic_cas_int32(lock, old, new) != old); + } while (atomic_cas_uint(lock, old, new) != old); return ((old & GL_BIT_PENDING) != 0); } diff --git a/sys/arch/amd64/amd64/pmap.c b/sys/arch/amd64/amd64/pmap.c index e5a2bbf3503..b35066d202f 100644 --- a/sys/arch/amd64/amd64/pmap.c +++ b/sys/arch/amd64/amd64/pmap.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pmap.c,v 1.68 2014/03/07 16:56:57 guenther Exp $ */ +/* $OpenBSD: pmap.c,v 1.69 2014/03/27 10:24:40 dlg Exp $ */ /* $NetBSD: pmap.c,v 1.3 2003/05/08 18:13:13 thorpej Exp $ */ /* @@ -2442,7 +2442,7 @@ pmap_tlb_shootpage(struct pmap *pm, vaddr_t va) if (wait > 0) { int s = splvm(); - while (x86_atomic_cas_ul(&tlb_shoot_wait, 0, wait) != 0) { + while (atomic_cas_ulong(&tlb_shoot_wait, 0, wait) != 0) { while (tlb_shoot_wait != 0) SPINLOCK_SPIN_HOOK; } @@ -2480,7 +2480,7 @@ pmap_tlb_shootrange(struct pmap *pm, vaddr_t sva, vaddr_t eva) if (wait > 0) { int s = splvm(); - while (x86_atomic_cas_ul(&tlb_shoot_wait, 0, wait) != 0) { + while (atomic_cas_ulong(&tlb_shoot_wait, 0, wait) != 0) { while (tlb_shoot_wait != 0) SPINLOCK_SPIN_HOOK; } @@ -2518,7 +2518,7 @@ pmap_tlb_shoottlb(void) if (wait) { int s = splvm(); - while (x86_atomic_cas_ul(&tlb_shoot_wait, 0, wait) != 0) { + while (atomic_cas_ulong(&tlb_shoot_wait, 0, wait) != 0) { while (tlb_shoot_wait != 0) SPINLOCK_SPIN_HOOK; } diff --git a/sys/arch/amd64/include/atomic.h b/sys/arch/amd64/include/atomic.h index 200d042f9c1..55360123f0c 100644 --- a/sys/arch/amd64/include/atomic.h +++ b/sys/arch/amd64/include/atomic.h @@ -1,4 +1,4 @@ -/* $OpenBSD: atomic.h,v 1.10 2014/02/17 10:01:32 dlg Exp $ */ +/* $OpenBSD: atomic.h,v 1.11 2014/03/27 10:24:40 dlg Exp $ */ /* $NetBSD: atomic.h,v 1.1 2003/04/26 18:39:37 fvdl Exp $ */ /* @@ -55,6 +55,42 @@ #define LOCK #endif +static inline unsigned int +_atomic_cas_uint(volatile unsigned int *p, unsigned int e, unsigned int n) +{ + __asm __volatile(LOCK " cmpxchgl %2, %1" + : "=a" (n), "=m" (*p) + : "r" (n), "a" (e), "m" (*p) + : "memory"); + + return (n); +} +#define atomic_cas_uint(_p, _e, _n) _atomic_cas_uint((_p), (_e), (_n)) + +static inline unsigned long +_atomic_cas_ulong(volatile unsigned long *p, unsigned long e, unsigned long n) +{ + __asm __volatile(LOCK " cmpxchgq %2, %1" + : "=a" (n), "=m" (*p) + : "r" (n), "a" (e), "m" (*p) + : "memory"); + + return (n); +} +#define atomic_cas_ulong(_p, _e, _n) _atomic_cas_ulong((_p), (_e), (_n)) + +static inline void * +_atomic_cas_ptr(volatile void **p, void *e, void *n) +{ + __asm __volatile(LOCK " cmpxchgq %2, %1" + : "=a" (n), "=m" (*p) + : "r" (n), "a" (e), "m" (*p) + : "memory"); + + return (n); +} +#define atomic_cas_ptr(_p, _e, _n) _atomic_cas_ptr((_p), (_e), (_n)) + static __inline u_int64_t x86_atomic_testset_u64(volatile u_int64_t *ptr, u_int64_t val) { @@ -82,28 +118,6 @@ x86_atomic_clearbits_u32(volatile u_int32_t *ptr, u_int32_t bits) __asm __volatile(LOCK " andl %1,%0" : "=m" (*ptr) : "ir" (~bits)); } -static __inline int -x86_atomic_cas_int32(volatile int32_t *ptr, int32_t expect, int32_t set) -{ - int res; - - __asm volatile(LOCK " cmpxchgl %2, %1" : "=a" (res), "=m" (*ptr) - : "r" (set), "a" (expect), "m" (*ptr) : "memory"); - - return (res); -} - -static __inline u_long -x86_atomic_cas_ul(volatile u_long *ptr, u_long expect, u_long set) -{ - u_long res; - - __asm volatile(LOCK " cmpxchgq %2, %1" : "=a" (res), "=m" (*ptr) - : "r" (set), "a" (expect), "m" (*ptr) : "memory"); - - return (res); -} - /* * XXX XXX XXX * theoretically 64bit cannot be used as diff --git a/sys/arch/amd64/include/lock.h b/sys/arch/amd64/include/lock.h index ec38788f12c..2f63ae4b833 100644 --- a/sys/arch/amd64/include/lock.h +++ b/sys/arch/amd64/include/lock.h @@ -1,4 +1,4 @@ -/* $OpenBSD: lock.h,v 1.7 2013/05/21 20:05:30 tedu Exp $ */ +/* $OpenBSD: lock.h,v 1.8 2014/03/27 10:24:40 dlg Exp $ */ /* $NetBSD: lock.h,v 1.1.2.2 2000/05/03 14:40:55 sommerfeld Exp $ */ /*- @@ -50,6 +50,6 @@ #include <machine/atomic.h> -#define rw_cas(p, o, n) (x86_atomic_cas_ul(p, o, n) != o) +#define rw_cas(p, o, n) (atomic_cas_ulong(p, o, n) != o) #endif /* _MACHINE_LOCK_H_ */ |