Module Name: src Committed By: scole Date: Mon Aug 8 17:44:24 UTC 2016
Modified Files: src/sys/arch/ia64/include: atomic.h Log Message: Import later FreeBSD version, add note about atomic.S which contains similar functions. To generate a diff of this commit: cvs rdiff -u -r1.1 -r1.2 src/sys/arch/ia64/include/atomic.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/arch/ia64/include/atomic.h diff -u src/sys/arch/ia64/include/atomic.h:1.1 src/sys/arch/ia64/include/atomic.h:1.2 --- src/sys/arch/ia64/include/atomic.h:1.1 Fri Apr 7 14:21:18 2006 +++ src/sys/arch/ia64/include/atomic.h Mon Aug 8 17:44:24 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: atomic.h,v 1.1 2006/04/07 14:21:18 cherry Exp $ */ +/* $NetBSD: atomic.h,v 1.2 2016/08/08 17:44:24 scole Exp $ */ /*- * Copyright (c) 1998 Doug Rabson @@ -25,12 +25,18 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/sys/ia64/include/atomic.h,v 1.10 2005/09/27 17:39:10 jhb Exp $ + * $FreeBSD: releng/10.1/sys/ia64/include/atomic.h 262004 2014-02-16 23:08:21Z marcel $ */ #ifndef _MACHINE_ATOMIC_H_ #define _MACHINE_ATOMIC_H_ +/* XXX need these? +#define mb() __asm __volatile("mf") +#define wmb() mb() +#define rmb() mb() +*/ + /* * Various simple arithmetic on memory which is atomic in the presence * of interrupts and SMP safe. @@ -44,7 +50,7 @@ "mov ar.ccv=%2;;\n\t" \ "cmpxchg" #sz "." #sem " %0=%4,%3,ar.ccv\n\t" \ : "=r" (ret), "=m" (*p) \ - : "r" (cmpval), "r" (newval), "m" (*p) \ + : "r" ((uint64_t)cmpval), "r" (newval), "m" (*p) \ : "memory") /* @@ -140,8 +146,11 @@ ATOMIC_STORE_LOAD(long, 64, "8") #undef ATOMIC_STORE_LOAD -#define atomic_load_acq_ptr atomic_load_acq_64 -#define atomic_store_rel_ptr atomic_store_rel_64 +#define atomic_load_acq_ptr(p) \ + ((void *)atomic_load_acq_64((volatile uint64_t *)p)) + +#define atomic_store_rel_ptr(p, v) \ + atomic_store_rel_64((volatile uint64_t *)p, (uint64_t)v) #define IA64_ATOMIC(sz, type, name, width, op) \ static __inline type \ @@ -260,6 +269,7 @@ IA64_ATOMIC(8, uint64_t, subtract, 64, - #define atomic_add_rel_long atomic_add_rel_64 #define atomic_subtract_rel_long atomic_subtract_rel_64 +/* XXX Needs casting. */ #define atomic_set_ptr atomic_set_64 #define atomic_clear_ptr atomic_clear_64 #define atomic_add_ptr atomic_add_64 @@ -313,13 +323,18 @@ atomic_cmpset_rel_64(volatile uint64_t* #define atomic_cmpset_64 atomic_cmpset_acq_64 #define atomic_cmpset_int atomic_cmpset_32 #define atomic_cmpset_long atomic_cmpset_64 -#define atomic_cmpset_ptr atomic_cmpset_64 #define atomic_cmpset_acq_int atomic_cmpset_acq_32 #define atomic_cmpset_rel_int atomic_cmpset_rel_32 #define atomic_cmpset_acq_long atomic_cmpset_acq_64 #define atomic_cmpset_rel_long atomic_cmpset_rel_64 -#define atomic_cmpset_acq_ptr atomic_cmpset_acq_64 -#define atomic_cmpset_rel_ptr atomic_cmpset_rel_64 + +#define atomic_cmpset_acq_ptr(p, o, n) \ + (atomic_cmpset_acq_64((volatile uint64_t *)p, (uint64_t)o, (uint64_t)n)) + +#define atomic_cmpset_ptr atomic_cmpset_acq_ptr + +#define atomic_cmpset_rel_ptr(p, o, n) \ + (atomic_cmpset_rel_64((volatile uint64_t *)p, (uint64_t)o, (uint64_t)n)) static __inline uint32_t atomic_readandclear_32(volatile uint32_t* p) @@ -343,6 +358,7 @@ atomic_readandclear_64(volatile uint64_t #define atomic_readandclear_int atomic_readandclear_32 #define atomic_readandclear_long atomic_readandclear_64 +#define atomic_readandclear_ptr atomic_readandclear_64 /* * Atomically add the value of v to the integer pointed to by p and return @@ -363,4 +379,53 @@ atomic_fetchadd_32(volatile uint32_t *p, #define atomic_fetchadd_int atomic_fetchadd_32 +static __inline u_long +atomic_fetchadd_long(volatile u_long *p, u_long v) +{ + u_long value; + + do { + value = *p; + } while (!atomic_cmpset_64(p, value, value + v)); + return (value); +} + +/* + * XXX already defined in + * src/common/lib/libc/arch/ia64/atomic/atomic.S. Need to sort out + * what to do with this file and atomic.S. atomic.S version comments + * (from 2008) say it is not tested at all, but if it works we may not + * need anything in this file? + */ +#if 0 + +/* + * <type> atomic_swap_<type>(volatile <type> *p, <type> v); + */ + +static __inline uint32_t +atomic_swap_32(volatile uint32_t *p, uint32_t v) +{ + uint32_t r; + + __asm __volatile ("xchg4 %0 = %3, %2;;" : "=r"(r), "=m"(*p) : + "r"(v), "m"(*p) : "memory"); + return (r); +} + +static __inline uint64_t +atomic_swap_64(volatile uint64_t *p, uint64_t v) +{ + uint64_t r; + + __asm __volatile ("xchg8 %0 = %3, %2;;" : "=r"(r), "=m"(*p) : + "r"(v), "m"(*p) : "memory"); + return (r); +} +#endif + +#define atomic_swap_int atomic_swap_32 +#define atomic_swap_long atomic_swap_64 +#define atomic_swap_ptr atomic_swap_64 + #endif /* ! _MACHINE_ATOMIC_H_ */