Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/external/bsd Move Linux atomic bitops from linux/atomic....



details:   https://anonhg.NetBSD.org/src/rev/00d7f161989f
branches:  trunk
changeset: 1028436:00d7f161989f
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Sun Dec 19 11:03:01 2021 +0000

description:
Move Linux atomic bitops from linux/atomic.h to linux/bitops.h.

diffstat:

 sys/external/bsd/common/include/linux/bitops.h |  90 +++++++++++++++++++++++++-
 sys/external/bsd/drm2/include/linux/atomic.h   |  87 +------------------------
 2 files changed, 90 insertions(+), 87 deletions(-)

diffs (208 lines):

diff -r d3a6bbaf13ba -r 00d7f161989f sys/external/bsd/common/include/linux/bitops.h
--- a/sys/external/bsd/common/include/linux/bitops.h    Sun Dec 19 11:02:54 2021 +0000
+++ b/sys/external/bsd/common/include/linux/bitops.h    Sun Dec 19 11:03:01 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bitops.h,v 1.15 2021/12/19 09:49:47 riastradh Exp $    */
+/*     $NetBSD: bitops.h,v 1.16 2021/12/19 11:03:01 riastradh Exp $    */
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -41,6 +41,9 @@
 #include <machine/limits.h>
 
 #include <lib/libkern/libkern.h>
+
+#include <asm/barrier.h>
+
 #include <linux/bits.h>
 
 /*
@@ -283,4 +286,89 @@
             (BIT) < (NBITS);                                                 \
             (BIT) = find_next_zero_bit((PTR), (NBITS), (BIT) + 1))
 
+static inline void
+set_bit(unsigned int bit, volatile unsigned long *ptr)
+{
+       const unsigned int units = (sizeof(*ptr) * CHAR_BIT);
+
+       /* no memory barrier */
+       atomic_or_ulong(&ptr[bit / units], (1UL << (bit % units)));
+}
+
+static inline void
+clear_bit(unsigned int bit, volatile unsigned long *ptr)
+{
+       const unsigned int units = (sizeof(*ptr) * CHAR_BIT);
+
+       /* no memory barrier */
+       atomic_and_ulong(&ptr[bit / units], ~(1UL << (bit % units)));
+}
+
+static inline void
+clear_bit_unlock(unsigned int bit, volatile unsigned long *ptr)
+{
+       const unsigned int units = (sizeof(*ptr) * CHAR_BIT);
+
+       /* store-release */
+       smp_mb__before_atomic();
+       atomic_and_ulong(&ptr[bit / units], ~(1UL << (bit % units)));
+}
+
+static inline void
+change_bit(unsigned int bit, volatile unsigned long *ptr)
+{
+       const unsigned int units = (sizeof(*ptr) * CHAR_BIT);
+       volatile unsigned long *const p = &ptr[bit / units];
+       const unsigned long mask = (1UL << (bit % units));
+       unsigned long v;
+
+       /* no memory barrier */
+       do v = *p; while (atomic_cas_ulong(p, v, (v ^ mask)) != v);
+}
+
+static inline int
+test_and_set_bit(unsigned int bit, volatile unsigned long *ptr)
+{
+       const unsigned int units = (sizeof(*ptr) * CHAR_BIT);
+       volatile unsigned long *const p = &ptr[bit / units];
+       const unsigned long mask = (1UL << (bit % units));
+       unsigned long v;
+
+       smp_mb__before_atomic();
+       do v = *p; while (atomic_cas_ulong(p, v, (v | mask)) != v);
+       smp_mb__after_atomic();
+
+       return ((v & mask) != 0);
+}
+
+static inline int
+test_and_clear_bit(unsigned int bit, volatile unsigned long *ptr)
+{
+       const unsigned int units = (sizeof(*ptr) * CHAR_BIT);
+       volatile unsigned long *const p = &ptr[bit / units];
+       const unsigned long mask = (1UL << (bit % units));
+       unsigned long v;
+
+       smp_mb__before_atomic();
+       do v = *p; while (atomic_cas_ulong(p, v, (v & ~mask)) != v);
+       smp_mb__after_atomic();
+
+       return ((v & mask) != 0);
+}
+
+static inline int
+test_and_change_bit(unsigned int bit, volatile unsigned long *ptr)
+{
+       const unsigned int units = (sizeof(*ptr) * CHAR_BIT);
+       volatile unsigned long *const p = &ptr[bit / units];
+       const unsigned long mask = (1UL << (bit % units));
+       unsigned long v;
+
+       smp_mb__before_atomic();
+       do v = *p; while (atomic_cas_ulong(p, v, (v ^ mask)) != v);
+       smp_mb__after_atomic();
+
+       return ((v & mask) != 0);
+}
+
 #endif  /* _LINUX_BITOPS_H_ */
diff -r d3a6bbaf13ba -r 00d7f161989f sys/external/bsd/drm2/include/linux/atomic.h
--- a/sys/external/bsd/drm2/include/linux/atomic.h      Sun Dec 19 11:02:54 2021 +0000
+++ b/sys/external/bsd/drm2/include/linux/atomic.h      Sun Dec 19 11:03:01 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: atomic.h,v 1.33 2021/12/19 11:02:46 riastradh Exp $    */
+/*     $NetBSD: atomic.h,v 1.34 2021/12/19 11:03:01 riastradh Exp $    */
 
 /*-
  * Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -448,89 +448,4 @@
        return old;
 }
 
-static inline void
-set_bit(unsigned int bit, volatile unsigned long *ptr)
-{
-       const unsigned int units = (sizeof(*ptr) * CHAR_BIT);
-
-       /* no memory barrier */
-       atomic_or_ulong(&ptr[bit / units], (1UL << (bit % units)));
-}
-
-static inline void
-clear_bit(unsigned int bit, volatile unsigned long *ptr)
-{
-       const unsigned int units = (sizeof(*ptr) * CHAR_BIT);
-
-       /* no memory barrier */
-       atomic_and_ulong(&ptr[bit / units], ~(1UL << (bit % units)));
-}
-
-static inline void
-clear_bit_unlock(unsigned int bit, volatile unsigned long *ptr)
-{
-       const unsigned int units = (sizeof(*ptr) * CHAR_BIT);
-
-       /* store-release */
-       smp_mb__before_atomic();
-       atomic_and_ulong(&ptr[bit / units], ~(1UL << (bit % units)));
-}
-
-static inline void
-change_bit(unsigned int bit, volatile unsigned long *ptr)
-{
-       const unsigned int units = (sizeof(*ptr) * CHAR_BIT);
-       volatile unsigned long *const p = &ptr[bit / units];
-       const unsigned long mask = (1UL << (bit % units));
-       unsigned long v;
-
-       /* no memory barrier */
-       do v = *p; while (atomic_cas_ulong(p, v, (v ^ mask)) != v);
-}
-
-static inline int
-test_and_set_bit(unsigned int bit, volatile unsigned long *ptr)
-{
-       const unsigned int units = (sizeof(*ptr) * CHAR_BIT);
-       volatile unsigned long *const p = &ptr[bit / units];
-       const unsigned long mask = (1UL << (bit % units));
-       unsigned long v;
-
-       smp_mb__before_atomic();
-       do v = *p; while (atomic_cas_ulong(p, v, (v | mask)) != v);
-       smp_mb__after_atomic();
-
-       return ((v & mask) != 0);
-}
-
-static inline int
-test_and_clear_bit(unsigned int bit, volatile unsigned long *ptr)
-{
-       const unsigned int units = (sizeof(*ptr) * CHAR_BIT);
-       volatile unsigned long *const p = &ptr[bit / units];
-       const unsigned long mask = (1UL << (bit % units));
-       unsigned long v;
-
-       smp_mb__before_atomic();
-       do v = *p; while (atomic_cas_ulong(p, v, (v & ~mask)) != v);
-       smp_mb__after_atomic();
-
-       return ((v & mask) != 0);
-}
-
-static inline int
-test_and_change_bit(unsigned int bit, volatile unsigned long *ptr)
-{
-       const unsigned int units = (sizeof(*ptr) * CHAR_BIT);
-       volatile unsigned long *const p = &ptr[bit / units];
-       const unsigned long mask = (1UL << (bit % units));
-       unsigned long v;
-
-       smp_mb__before_atomic();
-       do v = *p; while (atomic_cas_ulong(p, v, (v ^ mask)) != v);
-       smp_mb__after_atomic();
-
-       return ((v & mask) != 0);
-}
-
 #endif  /* _LINUX_ATOMIC_H_ */



Home | Main Index | Thread Index | Old Index