diff options
Diffstat (limited to 'arch/x86/include/asm/rwsem.h')
-rw-r--r-- | arch/x86/include/asm/rwsem.h | 80 |
1 files changed, 9 insertions, 71 deletions
diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h index d1e41b0f9b60..df4cd32b4cc6 100644 --- a/arch/x86/include/asm/rwsem.h +++ b/arch/x86/include/asm/rwsem.h | |||
@@ -37,26 +37,9 @@ | |||
37 | #endif | 37 | #endif |
38 | 38 | ||
39 | #ifdef __KERNEL__ | 39 | #ifdef __KERNEL__ |
40 | |||
41 | #include <linux/list.h> | ||
42 | #include <linux/spinlock.h> | ||
43 | #include <linux/lockdep.h> | ||
44 | #include <asm/asm.h> | 40 | #include <asm/asm.h> |
45 | 41 | ||
46 | struct rwsem_waiter; | ||
47 | |||
48 | extern asmregparm struct rw_semaphore * | ||
49 | rwsem_down_read_failed(struct rw_semaphore *sem); | ||
50 | extern asmregparm struct rw_semaphore * | ||
51 | rwsem_down_write_failed(struct rw_semaphore *sem); | ||
52 | extern asmregparm struct rw_semaphore * | ||
53 | rwsem_wake(struct rw_semaphore *); | ||
54 | extern asmregparm struct rw_semaphore * | ||
55 | rwsem_downgrade_wake(struct rw_semaphore *sem); | ||
56 | |||
57 | /* | 42 | /* |
58 | * the semaphore definition | ||
59 | * | ||
60 | * The bias values and the counter type limits the number of | 43 | * The bias values and the counter type limits the number of |
61 | * potential readers/writers to 32767 for 32 bits and 2147483647 | 44 | * potential readers/writers to 32767 for 32 bits and 2147483647 |
62 | * for 64 bits. | 45 | * for 64 bits. |
@@ -74,43 +57,6 @@ extern asmregparm struct rw_semaphore * | |||
74 | #define RWSEM_ACTIVE_READ_BIAS RWSEM_ACTIVE_BIAS | 57 | #define RWSEM_ACTIVE_READ_BIAS RWSEM_ACTIVE_BIAS |
75 | #define RWSEM_ACTIVE_WRITE_BIAS (RWSEM_WAITING_BIAS + RWSEM_ACTIVE_BIAS) | 58 | #define RWSEM_ACTIVE_WRITE_BIAS (RWSEM_WAITING_BIAS + RWSEM_ACTIVE_BIAS) |
76 | 59 | ||
77 | typedef signed long rwsem_count_t; | ||
78 | |||
79 | struct rw_semaphore { | ||
80 | rwsem_count_t count; | ||
81 | spinlock_t wait_lock; | ||
82 | struct list_head wait_list; | ||
83 | #ifdef CONFIG_DEBUG_LOCK_ALLOC | ||
84 | struct lockdep_map dep_map; | ||
85 | #endif | ||
86 | }; | ||
87 | |||
88 | #ifdef CONFIG_DEBUG_LOCK_ALLOC | ||
89 | # define __RWSEM_DEP_MAP_INIT(lockname) , .dep_map = { .name = #lockname } | ||
90 | #else | ||
91 | # define __RWSEM_DEP_MAP_INIT(lockname) | ||
92 | #endif | ||
93 | |||
94 | |||
95 | #define __RWSEM_INITIALIZER(name) \ | ||
96 | { \ | ||
97 | RWSEM_UNLOCKED_VALUE, __SPIN_LOCK_UNLOCKED((name).wait_lock), \ | ||
98 | LIST_HEAD_INIT((name).wait_list) __RWSEM_DEP_MAP_INIT(name) \ | ||
99 | } | ||
100 | |||
101 | #define DECLARE_RWSEM(name) \ | ||
102 | struct rw_semaphore name = __RWSEM_INITIALIZER(name) | ||
103 | |||
104 | extern void __init_rwsem(struct rw_semaphore *sem, const char *name, | ||
105 | struct lock_class_key *key); | ||
106 | |||
107 | #define init_rwsem(sem) \ | ||
108 | do { \ | ||
109 | static struct lock_class_key __key; \ | ||
110 | \ | ||
111 | __init_rwsem((sem), #sem, &__key); \ | ||
112 | } while (0) | ||
113 | |||
114 | /* | 60 | /* |
115 | * lock for reading | 61 | * lock for reading |
116 | */ | 62 | */ |
@@ -133,7 +79,7 @@ static inline void __down_read(struct rw_semaphore *sem) | |||
133 | */ | 79 | */ |
134 | static inline int __down_read_trylock(struct rw_semaphore *sem) | 80 | static inline int __down_read_trylock(struct rw_semaphore *sem) |
135 | { | 81 | { |
136 | rwsem_count_t result, tmp; | 82 | long result, tmp; |
137 | asm volatile("# beginning __down_read_trylock\n\t" | 83 | asm volatile("# beginning __down_read_trylock\n\t" |
138 | " mov %0,%1\n\t" | 84 | " mov %0,%1\n\t" |
139 | "1:\n\t" | 85 | "1:\n\t" |
@@ -155,7 +101,7 @@ static inline int __down_read_trylock(struct rw_semaphore *sem) | |||
155 | */ | 101 | */ |
156 | static inline void __down_write_nested(struct rw_semaphore *sem, int subclass) | 102 | static inline void __down_write_nested(struct rw_semaphore *sem, int subclass) |
157 | { | 103 | { |
158 | rwsem_count_t tmp; | 104 | long tmp; |
159 | asm volatile("# beginning down_write\n\t" | 105 | asm volatile("# beginning down_write\n\t" |
160 | LOCK_PREFIX " xadd %1,(%2)\n\t" | 106 | LOCK_PREFIX " xadd %1,(%2)\n\t" |
161 | /* adds 0xffff0001, returns the old value */ | 107 | /* adds 0xffff0001, returns the old value */ |
@@ -180,9 +126,8 @@ static inline void __down_write(struct rw_semaphore *sem) | |||
180 | */ | 126 | */ |
181 | static inline int __down_write_trylock(struct rw_semaphore *sem) | 127 | static inline int __down_write_trylock(struct rw_semaphore *sem) |
182 | { | 128 | { |
183 | rwsem_count_t ret = cmpxchg(&sem->count, | 129 | long ret = cmpxchg(&sem->count, RWSEM_UNLOCKED_VALUE, |
184 | RWSEM_UNLOCKED_VALUE, | 130 | RWSEM_ACTIVE_WRITE_BIAS); |
185 | RWSEM_ACTIVE_WRITE_BIAS); | ||
186 | if (ret == RWSEM_UNLOCKED_VALUE) | 131 | if (ret == RWSEM_UNLOCKED_VALUE) |
187 | return 1; | 132 | return 1; |
188 | return 0; | 133 | return 0; |
@@ -193,7 +138,7 @@ static inline int __down_write_trylock(struct rw_semaphore *sem) | |||
193 | */ | 138 | */ |
194 | static inline void __up_read(struct rw_semaphore *sem) | 139 | static inline void __up_read(struct rw_semaphore *sem) |
195 | { | 140 | { |
196 | rwsem_count_t tmp; | 141 | long tmp; |
197 | asm volatile("# beginning __up_read\n\t" | 142 | asm volatile("# beginning __up_read\n\t" |
198 | LOCK_PREFIX " xadd %1,(%2)\n\t" | 143 | LOCK_PREFIX " xadd %1,(%2)\n\t" |
199 | /* subtracts 1, returns the old value */ | 144 | /* subtracts 1, returns the old value */ |
@@ -211,7 +156,7 @@ static inline void __up_read(struct rw_semaphore *sem) | |||
211 | */ | 156 | */ |
212 | static inline void __up_write(struct rw_semaphore *sem) | 157 | static inline void __up_write(struct rw_semaphore *sem) |
213 | { | 158 | { |
214 | rwsem_count_t tmp; | 159 | long tmp; |
215 | asm volatile("# beginning __up_write\n\t" | 160 | asm volatile("# beginning __up_write\n\t" |
216 | LOCK_PREFIX " xadd %1,(%2)\n\t" | 161 | LOCK_PREFIX " xadd %1,(%2)\n\t" |
217 | /* subtracts 0xffff0001, returns the old value */ | 162 | /* subtracts 0xffff0001, returns the old value */ |
@@ -247,8 +192,7 @@ static inline void __downgrade_write(struct rw_semaphore *sem) | |||
247 | /* | 192 | /* |
248 | * implement atomic add functionality | 193 | * implement atomic add functionality |
249 | */ | 194 | */ |
250 | static inline void rwsem_atomic_add(rwsem_count_t delta, | 195 | static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem) |
251 | struct rw_semaphore *sem) | ||
252 | { | 196 | { |
253 | asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0" | 197 | asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0" |
254 | : "+m" (sem->count) | 198 | : "+m" (sem->count) |
@@ -258,10 +202,9 @@ static inline void rwsem_atomic_add(rwsem_count_t delta, | |||
258 | /* | 202 | /* |
259 | * implement exchange and add functionality | 203 | * implement exchange and add functionality |
260 | */ | 204 | */ |
261 | static inline rwsem_count_t rwsem_atomic_update(rwsem_count_t delta, | 205 | static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem) |
262 | struct rw_semaphore *sem) | ||
263 | { | 206 | { |
264 | rwsem_count_t tmp = delta; | 207 | long tmp = delta; |
265 | 208 | ||
266 | asm volatile(LOCK_PREFIX "xadd %0,%1" | 209 | asm volatile(LOCK_PREFIX "xadd %0,%1" |
267 | : "+r" (tmp), "+m" (sem->count) | 210 | : "+r" (tmp), "+m" (sem->count) |
@@ -270,10 +213,5 @@ static inline rwsem_count_t rwsem_atomic_update(rwsem_count_t delta, | |||
270 | return tmp + delta; | 213 | return tmp + delta; |
271 | } | 214 | } |
272 | 215 | ||
273 | static inline int rwsem_is_locked(struct rw_semaphore *sem) | ||
274 | { | ||
275 | return (sem->count != 0); | ||
276 | } | ||
277 | |||
278 | #endif /* __KERNEL__ */ | 216 | #endif /* __KERNEL__ */ |
279 | #endif /* _ASM_X86_RWSEM_H */ | 217 | #endif /* _ASM_X86_RWSEM_H */ |