aboutsummaryrefslogtreecommitdiff
path: root/sys/compat/linuxkpi/common/include
diff options
context:
space:
mode:
authorMark Johnston <markj@FreeBSD.org>2017-03-22 17:33:57 +0000
committerMark Johnston <markj@FreeBSD.org>2017-03-22 17:33:57 +0000
commite5fe3ae2b48c9fa04813eac89978072a47439a37 (patch)
tree76db8d0cd7468756e7f85572d40d48a09d3ad55c /sys/compat/linuxkpi/common/include
parent3d6732549db0d00a5f2e678e0f3ee716412a519c (diff)
downloadsrc-e5fe3ae2b48c9fa04813eac89978072a47439a37.tar.gz
src-e5fe3ae2b48c9fa04813eac89978072a47439a37.zip
Extend cmpxchg() to support 8- and 16-bit values, and add xchg().
These are needed to support updated revisions of the DRM code. Reviewed by: hselasky (previous version) MFC after: 2 weeks
Notes
Notes: svn path=/head/; revision=315719
Diffstat (limited to 'sys/compat/linuxkpi/common/include')
-rw-r--r--sys/compat/linuxkpi/common/include/asm/atomic.h62
1 files changed, 40 insertions, 22 deletions
diff --git a/sys/compat/linuxkpi/common/include/asm/atomic.h b/sys/compat/linuxkpi/common/include/asm/atomic.h
index 5f07d0b2ad72..f2f1fa60a171 100644
--- a/sys/compat/linuxkpi/common/include/asm/atomic.h
+++ b/sys/compat/linuxkpi/common/include/asm/atomic.h
@@ -28,11 +28,13 @@
*
* $FreeBSD$
*/
-#ifndef _ASM_ATOMIC_H_
+
+#ifndef _ASM_ATOMIC_H_
#define _ASM_ATOMIC_H_
#include <sys/cdefs.h>
#include <sys/types.h>
+
#include <machine/atomic.h>
#define ATOMIC_INIT(x) { .counter = (x) }
@@ -158,31 +160,47 @@ atomic_cmpxchg(atomic_t *v, int old, int new)
}
#define cmpxchg(ptr, old, new) ({ \
- __typeof(*(ptr)) __ret = (old); \
- CTASSERT(sizeof(__ret) == 4 || sizeof(__ret) == 8); \
- for (;;) { \
- if (sizeof(__ret) == 4) { \
- if (atomic_cmpset_int((volatile int *) \
- (ptr), (old), (new))) \
- break; \
- __ret = atomic_load_acq_int( \
- (volatile int *)(ptr)); \
- if (__ret != (old)) \
- break; \
- } else { \
- if (atomic_cmpset_64( \
- (volatile int64_t *)(ptr), \
- (old), (new))) \
- break; \
- __ret = atomic_load_acq_64( \
- (volatile int64_t *)(ptr)); \
- if (__ret != (old)) \
- break; \
- } \
+ __typeof(*(ptr)) __ret; \
+ \
+ CTASSERT(sizeof(__ret) == 1 || sizeof(__ret) == 2 || \
+ sizeof(__ret) == 4 || sizeof(__ret) == 8); \
+ \
+ __ret = (old); \
+ switch (sizeof(__ret)) { \
+ case 1: \
+ while (!atomic_fcmpset_8((volatile int8_t *)(ptr), \
+ (int8_t *)&__ret, (new)) && __ret == (old)) \
+ ; \
+ break; \
+ case 2: \
+ while (!atomic_fcmpset_16((volatile int16_t *)(ptr), \
+ (int16_t *)&__ret, (new)) && __ret == (old)) \
+ ; \
+ break; \
+ case 4: \
+ while (!atomic_fcmpset_32((volatile int32_t *)(ptr), \
+ (int32_t *)&__ret, (new)) && __ret == (old)) \
+ ; \
+ break; \
+ case 8: \
+ while (!atomic_fcmpset_64((volatile int64_t *)(ptr), \
+ (int64_t *)&__ret, (new)) && __ret == (old)) \
+ ; \
+ break; \
} \
__ret; \
})
+#define cmpxchg_relaxed cmpxchg
+
+#define xchg(ptr, v) ({ \
+ __typeof(*(ptr)) __ret; \
+ \
+ __ret = *(ptr); \
+ *(ptr) = v; \
+ __ret; \
+})
+
#define LINUX_ATOMIC_OP(op, c_op) \
static inline void atomic_##op(int i, atomic_t *v) \
{ \