: bitops cleanup and fixes
Subsystems (2)
v3 cover : bitops cleanup and fixes
Hi yet again!
This patch series is an update to "[PATCH 0/4]: bitops cleanup and fixes":
http://article.gmane.org/gmane.comp.boot-loaders.u-boot/66184
and contains the patches which were not accepted. The patches are:
0001-Move-__set-clear_bit-from-ubifs.h-to-bitops.h.patch
- Code style updates. I chose to not create asm-generic/include/bitops/ (Jean-Christophes comment) since I feel that should go together with a larger restructuring.
- Updated to put BIT_MASK above the include of asm/bitops.h
- More generic code (comment from Mike Frysinger)
0002-Make-arm-bitops-endianness-independent.patch
- New patch which takes on the endianeess issue in arm bitops
0003-Define-ffs-fls-for-all-architectures.patch
- Code style updates (Wolfgangs comment).
- More generic code (comment from Mike Frysinger)
0004-Define-test_and_set_bit-and-test_and_clear-bit-for-A.patch
- Defines test_and_set_bit etc for ARM. Uses the non-atomic __test_and_set_bit.
remove-dupliace-cr.patch was accepted into the u-boot-arm tree, so I'm not reposting it.
Tested on ARM (OpenRD base), and compile tested on PowerPC.
// Simon
PATCH v3 1/4 : Move __set/clear_bit from ubifs.h to bitops.h
Move __set/clear_bit from ubifs.h to bitops.h
__set_bit and __clear_bit are defined in ubifs.h as well as in asm/include/bitops.h for some architectures. This patch moves the generic implementation to include/linux/bitops.h and uses that unless it's defined by the architecture.
v2: Unify code style (newline between __set_bit and __clear_bit)
v3: Move BIT_MASK and BIT_WORD above the include of asm/bitops.h
v4: Move the definition to generic code (Mike Frysinger)
--- fs/ubifs/ubifs.h | 32 -------------------------------- include/asm-arm/bitops.h | 2 ++ include/asm-blackfin/bitops.h | 1 + include/asm-microblaze/bitops.h | 1 + include/asm-mips/bitops.h | 1 + include/linux/bitops.h | 38 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 43 insertions(+), 32 deletions(-)
fs/ubifs/ubifs.h +0 -32
@@ -449,38 +449,6 @@ static inline ino_t parent_ino(struct dentry *dentry)return res; } -/* linux/include/linux/bitops.h */ - -#define BIT_MASK (nr) (1UL << ((nr) % BITS_PER_LONG)) -#define BIT_WORD (nr) ((nr) / BITS_PER_LONG) - -/* linux/include/asm-generic/bitops/non-atomic.h */ - -/** -* __set_bit - Set a bit in memory -* @nr: the bit to set -* @addr: the address to start counting from -* -* Unlike set_bit(), this function is non-atomic and may be reordered. -* If it's called on the same region of memory simultaneously, the effect -* may be that only one operation succeeds. -*/ -static inline void __set_bit (int nr,volatile unsigned long *addr) -{ -unsigned long mask =BIT_MASK (nr); -unsigned long *p = ((unsigned long *)addr) +BIT_WORD (nr); - - *p |= mask; -} - -static inline void __clear_bit (int nr,volatile unsigned long *addr) -{ -unsigned long mask =BIT_MASK (nr); -unsigned long *p = ((unsigned long *)addr) +BIT_WORD (nr); - - *p &= ~mask; -} -/* debug.c */ #define DEFINE_SPINLOCK (...)
include/asm-arm/bitops.h +2 -0
@@ -29,6 +29,7 @@ static inline void __set_bit(int nr, volatile void *addr) { ((unsigned char *) addr)[nr >>3 ] |= (1U << (nr &7 )); } +#define __set_bitextern void clear_bit (int nr,volatile void * addr);
@@ -36,6 +37,7 @@ static inline void __clear_bit(int nr, volatile void *addr) { ((unsigned char *) addr)[nr >>3 ] &= ~(1U << (nr &7 )); } +#define __clear_bitextern void change_bit (int nr,volatile void * addr);
include/asm-blackfin/bitops.h +1 -0
@@ -79,6 +79,7 @@ static __inline__ void __set_bit(int nr, volatile void *addr) mask =1 << (nr &0x1f ); *a |= mask; } +#define __set_bit/* * clear_bit() doesn't provide any barrier for the compiler.
include/asm-microblaze/bitops.h +1 -0
@@ -75,6 +75,7 @@ extern __inline__ void __set_bit(int nr, volatile void * addr) mask =1 << (nr &0x1f ); *a |= mask; } +#define __set_bit/* * clear_bit() doesn't provide any barrier for the compiler.
include/asm-mips/bitops.h +1 -0
@@ -90,6 +90,7 @@ static __inline__ void __set_bit(int nr, volatile void * addr) *m |=1UL << (nr &31 ); } +#define __set_bit/* * clear_bit - Clears a bit in memory
include/linux/bitops.h +38 -0
@@ -1,6 +1,7 @@#ifndef _LINUX_BITOPS_H#define _LINUX_BITOPS_H +#include <asm/types.h> /* * ffs: find first bit set. This is defined the same way as
@@ -66,7 +67,44 @@ static inline unsigned int generic_hweight8(unsigned int w)return (res &0x0F ) + ((res >>4 ) &0x0F ); } +#define BIT_MASK (nr) (1UL << ((nr) % BITS_PER_LONG)) +#define BIT_WORD (nr) ((nr) / BITS_PER_LONG) +#include <asm/bitops.h> +/* linux/include/asm-generic/bitops/non-atomic.h */ + +#ifndef __set_bit +# define __set_bit generic_set_bit +#endif + +#ifndef __clear_bit +# define __clear_bit generic_clear_bit +#endif + +/** +* __set_bit - Set a bit in memory +* @nr: the bit to set +* @addr: the address to start counting from +* +* Unlike set_bit(), this function is non-atomic and may be reordered. +* If it's called on the same region of memory simultaneously, the effect +* may be that only one operation succeeds. +*/ +static inline void generic_set_bit (int nr,volatile unsigned long *addr) +{ +unsigned long mask =BIT_MASK (nr); +unsigned long *p = ((unsigned long *)addr) +BIT_WORD (nr); + + *p |= mask; +} + +static inline void generic_clear_bit (int nr,volatile unsigned long *addr) +{ +unsigned long mask =BIT_MASK (nr); +unsigned long *p = ((unsigned long *)addr) +BIT_WORD (nr); + + *p &= ~mask; +}#endif
Signature · 1 line
1.6.0.4
PATCH v3 2/4 : arm: Make arm bitops endianness-independent
In reply to Simon Kagstromarm: Make arm bitops endianness-independent
Bring over the bitop implementations from the Linux include/asm-generic/bitops/non-atomic.h to provide endianness-independence.
v2: Use generic __set_bit and __clear_bit for ARM
--- include/asm-arm/bitops.h | 47 ++++++++++++++++++--------------------------- 1 files changed, 19 insertions(+), 28 deletions(-)
include/asm-arm/bitops.h +19 -28
@@ -25,61 +25,52 @@*/ extern void set_bit (int nr,volatile void * addr); -static inline void __set_bit (int nr,volatile void *addr) -{ - ((unsigned char *) addr)[nr >>3 ] |= (1U << (nr &7 )); -} -#define __set_bit -extern void clear_bit (int nr,volatile void * addr); -static inline void __clear_bit (int nr,volatile void *addr) -{ - ((unsigned char *) addr)[nr >>3 ] &= ~(1U << (nr &7 )); -} -#define __clear_bit -extern void change_bit (int nr,volatile void * addr);static inline void __change_bit (int nr,volatile void *addr) { - ((unsigned char *) addr)[nr >>3 ] ^= (1U << (nr &7 )); +unsigned long mask =BIT_MASK (nr); +unsigned long *p = ((unsigned long *)addr) +BIT_WORD (nr); + + *p ^= mask; }extern int test_and_set_bit (int nr,volatile void * addr);static inline int __test_and_set_bit (int nr,volatile void *addr) { -unsigned int mask =1 << (nr &7 ); -unsigned int oldval; +unsigned long mask =BIT_MASK (nr); +unsigned long *p = ((unsigned long *)addr) +BIT_WORD (nr); +unsigned long old = *p; - oldval = ((unsigned char *) addr)[nr >>3 ]; - ((unsigned char *) addr)[nr >>3 ] = oldval | mask; -return oldval & mask; + *p = old | mask; +return (old & mask) !=0 ; }extern int test_and_clear_bit (int nr,volatile void * addr);static inline int __test_and_clear_bit (int nr,volatile void *addr) { -unsigned int mask =1 << (nr &7 ); -unsigned int oldval; +unsigned long mask =BIT_MASK (nr); +unsigned long *p = ((unsigned long *)addr) +BIT_WORD (nr); +unsigned long old = *p; - oldval = ((unsigned char *) addr)[nr >>3 ]; - ((unsigned char *) addr)[nr >>3 ] = oldval & ~mask; -return oldval & mask; + *p = old & ~mask; +return (old & mask) !=0 ; }extern int test_and_change_bit (int nr,volatile void * addr);static inline int __test_and_change_bit (int nr,volatile void *addr) { -unsigned int mask =1 << (nr &7 ); -unsigned int oldval; +unsigned long mask =BIT_MASK (nr); +unsigned long *p = ((unsigned long *)addr) +BIT_WORD (nr); +unsigned long old = *p; - oldval = ((unsigned char *) addr)[nr >>3 ]; - ((unsigned char *) addr)[nr >>3 ] = oldval ^ mask; -return oldval & mask; + *p = old ^ mask; +return (old & mask) !=0 ; }extern int find_first_zero_bit (void * addr,unsigned size);
Signature · 1 line
1.6.0.4
PATCH v3 3/4 : Define ffs/fls for all architectures
In reply to Simon Kagstromarm: Define ffs/fls for all architectures
UBIFS requires fls(), which is not defined for arm (and some other architectures) and this patch adds it. The implementation is taken from Linux and is generic. ffs() is also defined for those that miss it.
v2: Unify code style (empty line between ffs/fls)
v3: Move the definition to generic code (Mike Frysinger)
--- include/asm-i386/bitops.h | 1 + include/asm-m68k/bitops.h | 1 + include/asm-nios/bitops.h | 1 + include/asm-nios2/bitops.h | 1 + include/asm-ppc/bitops.h | 2 + include/asm-sh/bitops.h | 2 + include/linux/bitops.h | 45 ++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 53 insertions(+), 0 deletions(-)
include/asm-i386/bitops.h +1 -0
@@ -349,6 +349,7 @@ static __inline__ int ffs(int x) "1:" : "=r" (r) : "g" (x)); return r+1 ; } +#define ffs/** * hweightN - returns the hamming weight of a N-bit word
include/asm-m68k/bitops.h +1 -0
@@ -51,6 +51,7 @@ extern __inline__ int ffs(int x) return r; }#define __ffs (x) (ffs(x) - 1) +#define ffs#endif /* __KERNEL__ */
include/asm-nios/bitops.h +1 -0
@@ -33,5 +33,6 @@ extern int test_and_set_bit(int nr, volatile void * a);extern int test_and_change_bit (int nr,volatile void * addr);extern int test_bit (int nr,volatile void * a);extern int ffs (int i); +#define ffs#endif /* _ASM_NIOS_BITOPS_H */
include/asm-nios2/bitops.h +1 -0
@@ -33,5 +33,6 @@ extern int test_and_set_bit(int nr, volatile void * a);extern int test_and_change_bit (int nr,volatile void * addr);extern int test_bit (int nr,volatile void * a);extern int ffs (int i); +#define ffs#endif /* __ASM_NIOS2_BITOPS_H */
include/asm-ppc/bitops.h +2 -0
@@ -178,6 +178,7 @@ static __inline__ int fls(unsigned int x) {return __ilog2 (x) +1 ; } +#define fls/** * fls64 - find last set bit in a 64-bit word
@@ -230,6 +231,7 @@ extern __inline__ int ffs(int x) {return __ilog2 (x & -x) +1 ; } +#define ffs/* * hweightN: returns the hamming weight (i.e. the number
include/asm-sh/bitops.h +2 -0
@@ -146,6 +146,8 @@ static inline int ffs (int x) }return r; } +#define ffs +#endif /* __KERNEL__ */ #endif /* __ASM_SH_BITOPS_H */
include/linux/bitops.h +45 -0
57 lines not on this page · raw message
Signature · 1 line
1.6.0.4
PATCH v3 4/4 : arm: Define test_and_set_bit and test_and_clear bit for ARM
In reply to Simon Kagstromarm: Define test_and_set_bit and test_and_clear bit for ARM
Needed for (e.g.) ubifs support to work.
--- include/asm-arm/bitops.h | 28 +++++++++++++++++++++++++--- 1 files changed, 25 insertions(+), 3 deletions(-)
include/asm-arm/bitops.h +25 -3
@@ -17,6 +17,8 @@#ifdef __KERNEL__ +#include <asm/proc/system.h> +#define smp_mb__before_clear_bit () do { } while (0)#define smp_mb__after_clear_bit () do { } while (0)
@@ -37,8 +39,6 @@ static inline void __change_bit(int nr, volatile void *addr) *p ^= mask; } -extern int test_and_set_bit (int nr,volatile void * addr); -static inline int __test_and_set_bit (int nr,volatile void *addr) {unsigned long mask =BIT_MASK (nr);
@@ -49,7 +49,17 @@ static inline int __test_and_set_bit(int nr, volatile void *addr)return (old & mask) !=0 ; } -extern int test_and_clear_bit (int nr,volatile void * addr); +static inline int test_and_set_bit (int nr,volatile void * addr) +{ +unsigned long flags; +int out; + +local_irq_save (flags); + out =__test_and_set_bit (nr, addr); +local_irq_restore (flags); + +return out; +}static inline int __test_and_clear_bit (int nr,volatile void *addr) {
@@ -61,6 +71,18 @@ static inline int __test_and_clear_bit(int nr, volatile void *addr)return (old & mask) !=0 ; } +static inline int test_and_clear_bit (int nr,volatile void * addr) +{ +unsigned long flags; +int out; + +local_irq_save (flags); + out =__test_and_clear_bit (nr, addr); +local_irq_restore (flags); + +return out; +} +extern int test_and_change_bit (int nr,volatile void * addr);static inline int __test_and_change_bit (int nr,volatile void *addr)
Signature · 1 line
1.6.0.4