: bitops cleanup and fixes
Subsystems (2)
cover : bitops cleanup and fixes
Hi again!
This patch series is an update to "[PATCH 0/8]: Fixes for ubifs build on ARM" sent in july:
http://lists.denx.de/pipermail/u-boot/2009-July/055594.html
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.
0002-Define-ffs-fls-for-all-architectures.patch
- Code style updates (Wolfgangs comment).
0003-Remove-duplicate-set_cr.patch
- New patch, removes a duplicate definition (also unused) that prevents compilation of the next patch
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. The endianness issue in __test_and_set_bit (Jean-Christophes comment) is a separate issue and should be handled in a separate patch I think.
// Simon
PATCH 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)
--- fs/ubifs/ubifs.h | 32 -------------------------------- include/asm-avr32/bitops.h | 4 ++++ include/asm-m68k/bitops.h | 4 ++++ include/asm-nios/bitops.h | 4 ++++ include/asm-nios2/bitops.h | 4 ++++ include/asm-ppc/bitops.h | 4 ++++ include/asm-sh/bitops.h | 5 +++++ include/asm-sparc/bitops.h | 4 ++++ include/linux/bitops.h | 30 ++++++++++++++++++++++++++++++ 9 files changed, 59 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-avr32/bitops.h +4 -0
@@ -22,4 +22,8 @@#ifndef __ASM_AVR32_BITOPS_H#define __ASM_AVR32_BITOPS_H +#define __set_bit (nr, addr) generic_set_bit(nr, addr) + +#define __clear_bit (nr, addr) generic_clear_bit(nr, addr) +#endif /* __ASM_AVR32_BITOPS_H */
include/asm-m68k/bitops.h +4 -0
@@ -15,6 +15,10 @@ extern int test_and_set_bit(int nr, volatile void *addr);extern int test_and_clear_bit (int nr,volatile void *addr);extern int test_and_change_bit (int nr,volatile void *addr); +#define __set_bit (nr, addr) generic_set_bit(nr, addr) + +#define __clear_bit (nr, addr) generic_clear_bit(nr, addr) +#ifdef __KERNEL__/*
include/asm-nios/bitops.h +4 -0
@@ -34,4 +34,8 @@ 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 __set_bit (nr, addr) generic_set_bit(nr, addr) + +#define __clear_bit (nr, addr) generic_clear_bit(nr, addr) +#endif /* _ASM_NIOS_BITOPS_H */
include/asm-nios2/bitops.h +4 -0
@@ -34,4 +34,8 @@ 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 __set_bit (nr, addr) generic_set_bit(nr, addr) + +#define __clear_bit (nr, addr) generic_clear_bit(nr, addr) +#endif /* __ASM_NIOS2_BITOPS_H */
include/asm-ppc/bitops.h +4 -0
@@ -144,6 +144,10 @@ extern __inline__ int test_and_change_bit(int nr, volatile void *addr) }#endif /* __INLINE_BITOPS */ +#define __set_bit (nr, addr) generic_set_bit(nr, addr) + +#define __clear_bit (nr, addr) generic_clear_bit(nr, addr) + extern __inline__ int test_bit(int nr, __const__ volatile void *addr) { __const__ unsigned int *p = (__const__ unsigned int *) addr;
include/asm-sh/bitops.h +5 -0
@@ -146,6 +146,11 @@ static inline int ffs (int x) }return r; } + +#define __set_bit (nr, addr) generic_set_bit(nr, addr) + +#define __clear_bit (nr, addr) generic_clear_bit(nr, addr) +#endif /* __KERNEL__ */ #endif /* __ASM_SH_BITOPS_H */
include/asm-sparc/bitops.h +4 -0
@@ -26,4 +26,8 @@#ifndef _SPARC_BITOPS_H#define _SPARC_BITOPS_H +#define __set_bit (nr, addr) generic_set_bit(nr, addr) + +#define __clear_bit (nr, addr) generic_clear_bit(nr, addr) +#endif /* _SPARC_BITOPS_H */
include/linux/bitops.h +30 -0
@@ -69,4 +69,34 @@ static inline unsigned int generic_hweight8(unsigned int w)#include <asm/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 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 1/4 : Move __set/clear_bit from ubifs.h to bitops.h
Quoted 8 lines · Simon Kagstrom
Move __set/clear_bit from
ubifs.htobitops.h
__set_bitand__clear_bitare defined inubifs.has well as inasm/include/bitops.hfor some architectures. This patch moves the generic implementation toinclude/linux/bitops.hand uses that unless it's defined by the architecture.v2: Unify code style (newline between
__set_bitand__clear_bit)
please this
Quoted 3 lines
Signed-off-by Simon Kagstrom <[email protected]>---
here
Quoted 11 lines
fs/ubifs/ubifs.h | 32 -------------------------------- include/asm-avr32/bitops.h | 4 ++++ include/asm-m68k/bitops.h | 4 ++++ include/asm-nios/bitops.h | 4 ++++ include/asm-nios2/bitops.h | 4 ++++ include/asm-ppc/bitops.h | 4 ++++ include/asm-sh/bitops.h | 5 +++++ include/asm-sparc/bitops.h | 4 ++++ include/linux/bitops.h | 30 ++++++++++++++++++++++++++++++ 9 files changed, 59 insertions(+), 32 deletions(-)
Best Regards,
J.
PATCH 2/4 : Define ffs/fls for all architectures
In reply to Simon KagstromDefine 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)
--- include/asm-arm/bitops.h | 4 ++++ include/asm-avr32/bitops.h | 4 ++++ include/asm-i386/bitops.h | 2 ++ include/asm-m68k/bitops.h | 2 ++ include/asm-microblaze/bitops.h | 2 ++ include/asm-mips/bitops.h | 2 ++ include/asm-nios/bitops.h | 5 ++++- include/asm-nios2/bitops.h | 5 ++++- include/asm-sh/bitops.h | 2 ++ include/asm-sparc/bitops.h | 4 ++++ include/linux/bitops.h | 37 +++++++++++++++++++++++++++++++++++++ 11 files changed, 67 insertions(+), 2 deletions(-)
include/asm-arm/bitops.h +4 -0
@@ -17,6 +17,8 @@#ifdef __KERNEL__ +#include <asm/types.h> +#define smp_mb__before_clear_bit () do { } while (0)#define smp_mb__after_clear_bit () do { } while (0)
@@ -117,6 +119,8 @@ static inline unsigned long ffz(unsigned long word)#define ffs (x) generic_ffs(x) +#define fls (x) generic_fls(x) +/* * hweightN: returns the hamming weight (i.e. the number * of bits set) of a N-bit word
include/asm-avr32/bitops.h +4 -0
@@ -26,4 +26,8 @@#define __clear_bit (nr, addr) generic_clear_bit(nr, addr) +#define ffs (x) generic_ffs(x) + +#define fls (x) generic_fls(x) +#endif /* __ASM_AVR32_BITOPS_H */
include/asm-i386/bitops.h +2 -0
@@ -350,6 +350,8 @@ static __inline__ int ffs(int x)return r+1 ; } +#define fls (x) generic_fls(x) +/** * hweightN - returns the hamming weight of a N-bit word * @x: the word to weigh
include/asm-m68k/bitops.h +2 -0
@@ -56,6 +56,8 @@ extern __inline__ int ffs(int x) }#define __ffs (x) (ffs(x) - 1) +#define fls (x) generic_fls(x) +#endif /* __KERNEL__ */ #endif /* _M68K_BITOPS_H */
include/asm-microblaze/bitops.h +2 -0
@@ -266,6 +266,8 @@ found_middle:#define ffs (x) generic_ffs(x) +#define fls (x) generic_fls(x) +/* * hweightN: returns the hamming weight (i.e. the number * of bits set) of a N-bit word
include/asm-mips/bitops.h +2 -0
@@ -716,6 +716,8 @@ static __inline__ unsigned long ffz(unsigned long word)#define ffs (x) generic_ffs(x) +#define fls (x) generic_fls(x) +/* * hweightN - returns the hamming weight of a N-bit word * @x: the word to weigh
include/asm-nios/bitops.h +4 -1
@@ -32,7 +32,10 @@ extern void change_bit(unsigned long nr, volatile void *addr);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 (x) generic_ffs(x) + +#define fls (x) generic_fls(x)#define __set_bit (nr, addr) generic_set_bit(nr, addr)
include/asm-nios2/bitops.h +4 -1
@@ -32,7 +32,10 @@ extern void change_bit(unsigned long nr, volatile void *addr);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 (x) generic_ffs(x) + +#define fls (x) generic_fls(x)#define __set_bit (nr, addr) generic_set_bit(nr, addr)
include/asm-sh/bitops.h +2 -0
@@ -147,6 +147,8 @@ static inline int ffs (int x)return r; } +#define fls (x) generic_fls(x) +#define __set_bit (nr, addr) generic_set_bit(nr, addr)#define __clear_bit (nr, addr) generic_clear_bit(nr, addr)
include/asm-sparc/bitops.h +4 -0
@@ -30,4 +30,8 @@#define __clear_bit (nr, addr) generic_clear_bit(nr, addr) +#define ffs (x) generic_ffs(x) + +#define fls (x) generic_fls(x) +#endif /* _SPARC_BITOPS_H */
include/linux/bitops.h +37 -0
@@ -37,6 +37,43 @@ static inline int generic_ffs(int x)return r; } +/** +* fls - find last (most-significant) bit set +* @x: the word to search +* +* This is defined the same way as ffs. +* Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32. +*/ +static inline int generic_fls (int x) +{ +int r =32 ; + +if (!x) +return 0 ; +if (!(x &0xffff0000u )) { + x <<=16 ; + r -=16 ; + } +if (!(x &0xff000000u )) { + x <<=8 ; + r -=8 ; + } +if (!(x &0xf0000000u )) { + x <<=4 ; + r -=4 ; + } +if (!(x &0xc0000000u )) { + x <<=2 ; + r -=2 ; + } +if (!(x &0x80000000u )) { + x <<=1 ; + r -=1 ; + } +return r; +} + +/* * hweightN: returns the hamming weight (i.e. the number * of bits set) of a N-bit word
Signature · 1 line
1.6.0.4
PATCH 2/4 : Define ffs/fls for all architectures
Quoted 7 lines · Simon Kagstrom
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)
please this
Quoted 3 lines
Signed-off-by Simon Kagstrom <[email protected]>---
here
Quoted 11 lines
include/asm-arm/bitops.h | 4 ++++ include/asm-avr32/bitops.h | 4 ++++ include/asm-i386/bitops.h | 2 ++ include/asm-m68k/bitops.h | 2 ++ include/asm-microblaze/bitops.h | 2 ++ include/asm-mips/bitops.h | 2 ++ include/asm-nios/bitops.h | 5 ++++- include/asm-nios2/bitops.h | 5 ++++- include/asm-sh/bitops.h | 2 ++ include/asm-sparc/bitops.h | 4 ++++ include/linux/bitops.h | 37 +++++++++++++++++++++++++++++++++++++
Best Regards,
J.
PATCH 2/4 : Define ffs/fls for all architectures
Quoted 7 lines · On Thu, 20 Aug 2009 01:11:09 +0200 Jean-Christophe PLAGNIOL-VILLARD…
Quoted 6 lines · Simon Kagstrom
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.
Quoted 6 lines
Quoted 1 line
v2: Unify code style (empty line between ffs/fls)
please this
Quoted 3 lines
Signed-off-by Simon Kagstrom <[email protected]>---
here
I didn't add that myself - it's git format-patch that put it there.
// Simon
PATCH 2/4 : Define ffs/fls for all architectures
Dear Simon Kagstrom,
Quoted 10 lines · In message <[email protected]> you wrote:
Quoted 7 lines · On Thu, 20 Aug 2009 01:11:09 +0200 Jean-Christophe PLAGNIOL-VILLARD…
Quoted 6 lines · Simon Kagstrom
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.
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
v2: Unify code style (empty line between ffs/fls)
please this
Quoted 3 lines
Signed-off-by Simon Kagstrom <[email protected]>---
here
I didn't add that myself - it's git format-patch that put it there.
What Jean-Christophe means is: Please don't put comments like "v2:
Unify code style ..." in the area where the commit message is, but move them into the comment section, i. e. below the "---" line.
Best regards,
Wolfgang Denk
Signature · 5 lines
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de To be sure of hitting the target, shoot first and, whatever you hit, call it the target.
PATCH 3/4 : Remove duplicate set_cr
In reply to Simon KagstromRemove duplicate set_cr
set_cr is defined in both asm-arm/proc-armv/system.h and include/asm-arm/system.h. This patch removes it (and some duplicate defines) from the former.
--- include/asm-arm/proc-armv/system.h | 30 ------------------------------ 1 files changed, 0 insertions(+), 30 deletions(-)
include/asm-arm/proc-armv/system.h +0 -30
@@ -12,36 +12,6 @@#include <linux/config.h> -#define set_cr (x) \ - __asm__ __volatile__( \ - "mcr p15, 0, %0, c1, c0 @ set CR" \ - : : "r" (x)) - -#define CR_M (1 << 0)/* MMU enable */ -#define CR_A (1 << 1)/* Alignment abort enable */ -#define CR_C (1 << 2)/* Dcache enable */ -#define CR_W (1 << 3)/* Write buffer enable */ -#define CR_P (1 << 4)/* 32-bit exception handler */ -#define CR_D (1 << 5)/* 32-bit data address range */ -#define CR_L (1 << 6)/* Implementation defined */ -#define CD_B (1 << 7)/* Big endian */ -#define CR_S (1 << 8)/* System MMU protection */ -#define CD_R (1 << 9)/* ROM MMU protection */ -#define CR_F (1 << 10)/* Implementation defined */ -#define CR_Z (1 << 11)/* Implementation defined */ -#define CR_I (1 << 12)/* Icache enable */ -#define CR_V (1 << 13)/* Vectors relocated to 0xffff0000 */ -#define CR_RR (1 << 14)/* Round Robin cache replacement */ - -extern unsigned long cr_no_alignment;/* defined in entry-armv.S */ -extern unsigned long cr_alignment;/* defined in entry-armv.S */ - -#if __LINUX_ARM_ARCH__ >=4 -#define vectors_base () ((cr_alignment & CR_V) ? 0xffff0000 : 0) -#else -#define vectors_base () (0) -#endif -/* * Save the current interrupt enable state & disable IRQs */
Signature · 1 line
1.6.0.4
PATCH 3/4 : Remove duplicate set_cr
Quoted 10 lines · Simon Kagstrom
Remove duplicate
set_cr
set_cris defined in bothasm-arm/proc-armv/system.handinclude/asm-arm/system.h. This patch removes it (and some duplicate defines) from the former.Signed-off-by Simon Kagstrom <[email protected]>--- include/asm-arm/proc-armv/system.h | 30 ------------------------------ 1 files changed, 0 insertions(+), 30 deletions(-)
apply to u-boot-arm
Best Regards,
J.
PATCH 4/4 : Define test_and_set_bit and test_and_clear bit for ARM
In reply to Simon KagstromDefine test_and_set_bit and test_and_clear bit for ARM
Needed for (e.g.) ubifs support to work.
--- include/asm-arm/bitops.h | 27 ++++++++++++++++++++++++--- 1 files changed, 24 insertions(+), 3 deletions(-)
include/asm-arm/bitops.h +24 -3
@@ -18,6 +18,7 @@#ifdef __KERNEL__#include <asm/types.h> +#include <asm/proc/system.h> #define smp_mb__before_clear_bit () do { } while (0)#define smp_mb__after_clear_bit () do { } while (0)
@@ -46,8 +47,6 @@ static inline void __change_bit(int nr, volatile void *addr) ((unsigned char *) addr)[nr >>3 ] ^= (1U << (nr &7 )); } -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 );
@@ -58,7 +57,17 @@ static inline int __test_and_set_bit(int nr, volatile void *addr)return oldval & mask; } -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) {
@@ -70,6 +79,18 @@ static inline int __test_and_clear_bit(int nr, volatile void *addr)return oldval & mask; } +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
PATCH 4/4 : Define test_and_set_bit and test_and_clear bit for ARM
Quoted 8 lines · Simon Kagstrom
Define
test_and_set_bitandtest_and_clearbit for ARMNeeded for (e.g.) ubifs support to work.
Signed-off-by Simon Kagstrom <[email protected]>--- include/asm-arm/bitops.h | 27 ++++++++++++++++++++++++--- 1 files changed, 24 insertions(+), 3 deletions(-)
this one NACK as it's must be endianness
for IXP as example
Best Regards,
J.
cover : bitops cleanup and fixes
In reply to Simon KagstromQuoted 21 lines · Simon Kagstrom
Hi again!
This patch series is an update to "[PATCH 0/8]: Fixes for ubifs build on ARM" sent in july:
http://lists.denx.de/pipermail/u-boot/2009-July/055594.html
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.0002-Define-ffs-fls-for-all-architectures.patch
- Code style updates (Wolfgangs comment).0003-Remove-duplicate-set_cr.patch
- New patch, removes a duplicate definition (also unused) that prevents compilation of the next patch
Quoted 5 lines
0004-Define-test_and_set_bit-and-test_and_clear-bit-for-A.patch
- Definestest_and_set_bitetc for ARM. Uses the non-atomic__test_and_set_bit. The endianness issue in__test_and_set_bit(Jean-Christophes comment) is a separate issue and should be handled in a separate patch I think.
but must be part of this cleanup otherwise it will never be done correctly and some arch as IXP will not work as there are not necessarely in little endian
Best Regards,
J.