All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH v3 0/4]: bitops cleanup and fixes
@ 2009-08-21  8:24 Simon Kagstrom
  2009-08-21  8:28 ` [U-Boot] [PATCH v3 1/4]: Move __set/clear_bit from ubifs.h to bitops.h Simon Kagstrom
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Simon Kagstrom @ 2009-08-21  8:24 UTC (permalink / raw)
  To: u-boot

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [U-Boot] [PATCH v3 1/4]: Move __set/clear_bit from ubifs.h to bitops.h
  2009-08-21  8:24 [U-Boot] [PATCH v3 0/4]: bitops cleanup and fixes Simon Kagstrom
@ 2009-08-21  8:28 ` Simon Kagstrom
  2009-08-21  8:28 ` [U-Boot] [PATCH v3 2/4]: arm: Make arm bitops endianness-independent Simon Kagstrom
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Simon Kagstrom @ 2009-08-21  8:28 UTC (permalink / raw)
  To: u-boot

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)

Signed-off-by: Simon Kagstrom <simon.kagstrom@netinsight.net>
---
 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(-)

diff --git a/fs/ubifs/ubifs.h b/fs/ubifs/ubifs.h
index 43865aa..06772af 100644
--- a/fs/ubifs/ubifs.h
+++ b/fs/ubifs/ubifs.h
@@ -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(...)
diff --git a/include/asm-arm/bitops.h b/include/asm-arm/bitops.h
index 4b8bab2..1549da1 100644
--- a/include/asm-arm/bitops.h
+++ b/include/asm-arm/bitops.h
@@ -29,6 +29,7 @@ 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);
 
@@ -36,6 +37,7 @@ 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);
 
diff --git a/include/asm-blackfin/bitops.h b/include/asm-blackfin/bitops.h
index 2e55b6a..cc3685d 100644
--- a/include/asm-blackfin/bitops.h
+++ b/include/asm-blackfin/bitops.h
@@ -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.
diff --git a/include/asm-microblaze/bitops.h b/include/asm-microblaze/bitops.h
index 04ea020..aac9061 100644
--- a/include/asm-microblaze/bitops.h
+++ b/include/asm-microblaze/bitops.h
@@ -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.
diff --git a/include/asm-mips/bitops.h b/include/asm-mips/bitops.h
index 659ac9d..0c07b68 100644
--- a/include/asm-mips/bitops.h
+++ b/include/asm-mips/bitops.h
@@ -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
diff --git a/include/linux/bitops.h b/include/linux/bitops.h
index 7d41ae6..387a818 100644
--- a/include/linux/bitops.h
+++ b/include/linux/bitops.h
@@ -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
-- 
1.6.0.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [U-Boot] [PATCH v3 2/4]: arm: Make arm bitops endianness-independent
  2009-08-21  8:24 [U-Boot] [PATCH v3 0/4]: bitops cleanup and fixes Simon Kagstrom
  2009-08-21  8:28 ` [U-Boot] [PATCH v3 1/4]: Move __set/clear_bit from ubifs.h to bitops.h Simon Kagstrom
@ 2009-08-21  8:28 ` Simon Kagstrom
  2009-08-21  8:29 ` [U-Boot] [PATCH v3 3/4]: Define ffs/fls for all architectures Simon Kagstrom
  2009-08-21  8:29 ` [U-Boot] [PATCH v3 4/4]: arm: Define test_and_set_bit and test_and_clear bit for ARM Simon Kagstrom
  3 siblings, 0 replies; 5+ messages in thread
From: Simon Kagstrom @ 2009-08-21  8:28 UTC (permalink / raw)
  To: u-boot

arm: 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

Signed-off-by: Simon Kagstrom <simon.kagstrom@netinsight.net>
---
 include/asm-arm/bitops.h |   47 ++++++++++++++++++---------------------------
 1 files changed, 19 insertions(+), 28 deletions(-)

diff --git a/include/asm-arm/bitops.h b/include/asm-arm/bitops.h
index 1549da1..854e225 100644
--- a/include/asm-arm/bitops.h
+++ b/include/asm-arm/bitops.h
@@ -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);
-- 
1.6.0.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [U-Boot] [PATCH v3 3/4]: Define ffs/fls for all architectures
  2009-08-21  8:24 [U-Boot] [PATCH v3 0/4]: bitops cleanup and fixes Simon Kagstrom
  2009-08-21  8:28 ` [U-Boot] [PATCH v3 1/4]: Move __set/clear_bit from ubifs.h to bitops.h Simon Kagstrom
  2009-08-21  8:28 ` [U-Boot] [PATCH v3 2/4]: arm: Make arm bitops endianness-independent Simon Kagstrom
@ 2009-08-21  8:29 ` Simon Kagstrom
  2009-08-21  8:29 ` [U-Boot] [PATCH v3 4/4]: arm: Define test_and_set_bit and test_and_clear bit for ARM Simon Kagstrom
  3 siblings, 0 replies; 5+ messages in thread
From: Simon Kagstrom @ 2009-08-21  8:29 UTC (permalink / raw)
  To: u-boot

arm: 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)

Signed-off-by: Simon Kagstrom <simon.kagstrom@netinsight.net>
---
 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(-)

diff --git a/include/asm-i386/bitops.h b/include/asm-i386/bitops.h
index b768e20..ac6285a 100644
--- a/include/asm-i386/bitops.h
+++ b/include/asm-i386/bitops.h
@@ -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
diff --git a/include/asm-m68k/bitops.h b/include/asm-m68k/bitops.h
index 0f9e8ab..e0c35fa 100644
--- a/include/asm-m68k/bitops.h
+++ b/include/asm-m68k/bitops.h
@@ -51,6 +51,7 @@ extern __inline__ int ffs(int x)
 	return r;
 }
 #define __ffs(x) (ffs(x) - 1)
+#define ffs
 
 #endif /* __KERNEL__ */
 
diff --git a/include/asm-nios/bitops.h b/include/asm-nios/bitops.h
index 7744212..8315fb7 100644
--- a/include/asm-nios/bitops.h
+++ b/include/asm-nios/bitops.h
@@ -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 */
diff --git a/include/asm-nios2/bitops.h b/include/asm-nios2/bitops.h
index e6c1a85..b01a89d 100644
--- a/include/asm-nios2/bitops.h
+++ b/include/asm-nios2/bitops.h
@@ -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 */
diff --git a/include/asm-ppc/bitops.h b/include/asm-ppc/bitops.h
index daa66cf..9ed2f5d 100644
--- a/include/asm-ppc/bitops.h
+++ b/include/asm-ppc/bitops.h
@@ -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
diff --git a/include/asm-sh/bitops.h b/include/asm-sh/bitops.h
index 410fba4..95167bd 100644
--- a/include/asm-sh/bitops.h
+++ b/include/asm-sh/bitops.h
@@ -146,6 +146,8 @@ static inline int ffs (int x)
 	}
 	return r;
 }
+#define ffs
+
 #endif /* __KERNEL__ */
 
 #endif /* __ASM_SH_BITOPS_H */
diff --git a/include/linux/bitops.h b/include/linux/bitops.h
index 387a818..e14e6c7 100644
--- a/include/linux/bitops.h
+++ b/include/linux/bitops.h
@@ -38,6 +38,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
@@ -82,6 +119,14 @@ static inline unsigned int generic_hweight8(unsigned int w)
 # define __clear_bit generic_clear_bit
 #endif
 
+#ifndef ffs
+# define ffs generic_ffs
+#endif
+
+#ifndef fls
+# define fls generic_fls
+#endif
+
 /**
  * __set_bit - Set a bit in memory
  * @nr: the bit to set
-- 
1.6.0.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [U-Boot] [PATCH v3 4/4]: arm: Define test_and_set_bit and test_and_clear bit for ARM
  2009-08-21  8:24 [U-Boot] [PATCH v3 0/4]: bitops cleanup and fixes Simon Kagstrom
                   ` (2 preceding siblings ...)
  2009-08-21  8:29 ` [U-Boot] [PATCH v3 3/4]: Define ffs/fls for all architectures Simon Kagstrom
@ 2009-08-21  8:29 ` Simon Kagstrom
  3 siblings, 0 replies; 5+ messages in thread
From: Simon Kagstrom @ 2009-08-21  8:29 UTC (permalink / raw)
  To: u-boot

arm: Define test_and_set_bit and test_and_clear bit for ARM

Needed for (e.g.) ubifs support to work.

Signed-off-by: Simon Kagstrom <simon.kagstrom@netinsight.net>
---
 include/asm-arm/bitops.h |   28 +++++++++++++++++++++++++---
 1 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/include/asm-arm/bitops.h b/include/asm-arm/bitops.h
index 854e225..3c7b00c 100644
--- a/include/asm-arm/bitops.h
+++ b/include/asm-arm/bitops.h
@@ -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)
-- 
1.6.0.4

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2009-08-21  8:29 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-08-21  8:24 [U-Boot] [PATCH v3 0/4]: bitops cleanup and fixes Simon Kagstrom
2009-08-21  8:28 ` [U-Boot] [PATCH v3 1/4]: Move __set/clear_bit from ubifs.h to bitops.h Simon Kagstrom
2009-08-21  8:28 ` [U-Boot] [PATCH v3 2/4]: arm: Make arm bitops endianness-independent Simon Kagstrom
2009-08-21  8:29 ` [U-Boot] [PATCH v3 3/4]: Define ffs/fls for all architectures Simon Kagstrom
2009-08-21  8:29 ` [U-Boot] [PATCH v3 4/4]: arm: Define test_and_set_bit and test_and_clear bit for ARM Simon Kagstrom

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.