aboutsummaryrefslogtreecommitdiffstats
path: root/include/asm-sparc64/rwsem.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/asm-sparc64/rwsem.h')
-rw-r--r--include/asm-sparc64/rwsem.h47
1 files changed, 4 insertions, 43 deletions
diff --git a/include/asm-sparc64/rwsem.h b/include/asm-sparc64/rwsem.h
index bf2ae90ed3df..4568ee4022df 100644
--- a/include/asm-sparc64/rwsem.h
+++ b/include/asm-sparc64/rwsem.h
@@ -46,53 +46,14 @@ extern void __up_read(struct rw_semaphore *sem);
46extern void __up_write(struct rw_semaphore *sem); 46extern void __up_write(struct rw_semaphore *sem);
47extern void __downgrade_write(struct rw_semaphore *sem); 47extern void __downgrade_write(struct rw_semaphore *sem);
48 48
49static __inline__ int rwsem_atomic_update(int delta, struct rw_semaphore *sem) 49static inline int rwsem_atomic_update(int delta, struct rw_semaphore *sem)
50{ 50{
51 int tmp = delta; 51 return atomic_add_return(delta, (atomic_t *)(&sem->count));
52
53 __asm__ __volatile__(
54 "1:\tlduw [%2], %%g1\n\t"
55 "add %%g1, %1, %%g7\n\t"
56 "cas [%2], %%g1, %%g7\n\t"
57 "cmp %%g1, %%g7\n\t"
58 "bne,pn %%icc, 1b\n\t"
59 " membar #StoreLoad | #StoreStore\n\t"
60 "mov %%g7, %0\n\t"
61 : "=&r" (tmp)
62 : "0" (tmp), "r" (sem)
63 : "g1", "g7", "memory", "cc");
64
65 return tmp + delta;
66}
67
68#define rwsem_atomic_add rwsem_atomic_update
69
70static __inline__ __u16 rwsem_cmpxchgw(struct rw_semaphore *sem, __u16 __old, __u16 __new)
71{
72 u32 old = (sem->count & 0xffff0000) | (u32) __old;
73 u32 new = (old & 0xffff0000) | (u32) __new;
74 u32 prev;
75
76again:
77 __asm__ __volatile__("cas [%2], %3, %0\n\t"
78 "membar #StoreLoad | #StoreStore"
79 : "=&r" (prev)
80 : "0" (new), "r" (sem), "r" (old)
81 : "memory");
82
83 /* To give the same semantics as x86 cmpxchgw, keep trying
84 * if only the upper 16-bits changed.
85 */
86 if (prev != old &&
87 ((prev & 0xffff) == (old & 0xffff)))
88 goto again;
89
90 return prev & 0xffff;
91} 52}
92 53
93static __inline__ signed long rwsem_cmpxchg(struct rw_semaphore *sem, signed long old, signed long new) 54static inline void rwsem_atomic_add(int delta, struct rw_semaphore *sem)
94{ 55{
95 return cmpxchg(&sem->count,old,new); 56 atomic_add(delta, (atomic_t *)(&sem->count));
96} 57}
97 58
98#endif /* __KERNEL__ */ 59#endif /* __KERNEL__ */