Module Name: src Committed By: riastradh Date: Sun Dec 19 11:03:01 UTC 2021
Modified Files: src/sys/external/bsd/common/include/linux: bitops.h src/sys/external/bsd/drm2/include/linux: atomic.h Log Message: Move Linux atomic bitops from linux/atomic.h to linux/bitops.h. To generate a diff of this commit: cvs rdiff -u -r1.15 -r1.16 src/sys/external/bsd/common/include/linux/bitops.h cvs rdiff -u -r1.33 -r1.34 src/sys/external/bsd/drm2/include/linux/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/external/bsd/common/include/linux/bitops.h diff -u src/sys/external/bsd/common/include/linux/bitops.h:1.15 src/sys/external/bsd/common/include/linux/bitops.h:1.16 --- src/sys/external/bsd/common/include/linux/bitops.h:1.15 Sun Dec 19 09:49:47 2021 +++ src/sys/external/bsd/common/include/linux/bitops.h Sun Dec 19 11:03:01 2021 @@ -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 @@ find_first_zero_bit(const unsigned long (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_ */ Index: src/sys/external/bsd/drm2/include/linux/atomic.h diff -u src/sys/external/bsd/drm2/include/linux/atomic.h:1.33 src/sys/external/bsd/drm2/include/linux/atomic.h:1.34 --- src/sys/external/bsd/drm2/include/linux/atomic.h:1.33 Sun Dec 19 11:02:46 2021 +++ src/sys/external/bsd/drm2/include/linux/atomic.h Sun Dec 19 11:03:01 2021 @@ -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 @@ atomic_long_cmpxchg(struct atomic_long * 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_ */