(no subject)
Subsystems (2)
The following patch series is needed to build U-Boot for ARM platforms with CONFIG_CMD_UBIFS set. The UBIFS layer uses bit operation functions which are currently only implemented for PPC, and the ARM bit operation definitions are unused and wrong.
[PATCH 1/3] ARM: remove unused bit operations
[PATCH 2/3] Add generic bit operations
[PATCH 3/3] ARM: add unaligned macros
PATCH 1/3 ARM: remove unused bit operations
Remove include/asm-arm/bitops.h a bunch of 'external' marked functions from include/asm-arm/bitops.h. They are not implemented anywhere in the sources, so this forward declaration is wrong.
Also remove the functions __set_bit, __clear_bit, __change_bit, __test_and_set_bit, __test_and_clear_bit and __test_and_change_bit.
All these functions can be implemented in a generic fashion which will be done in the next patch.
--- include/asm-arm/bitops.h | 70 ---------------------------------------------- 1 files changed, 0 insertions(+), 70 deletions(-)
include/asm-arm/bitops.h +0 -70
@@ -20,76 +20,6 @@#define smp_mb__before_clear_bit () do { } while (0)#define smp_mb__after_clear_bit () do { } while (0) -/* -* Function prototypes to keep gcc -Wall happy. -*/ -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 )); -} - -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 )); -} - -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 )); -} - -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; - - oldval = ((unsigned char *) addr)[nr >>3 ]; - ((unsigned char *) addr)[nr >>3 ] = oldval | mask; -return oldval & mask; -} - -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; - - oldval = ((unsigned char *) addr)[nr >>3 ]; - ((unsigned char *) addr)[nr >>3 ] = oldval & ~mask; -return oldval & mask; -} - -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; - - oldval = ((unsigned char *) addr)[nr >>3 ]; - ((unsigned char *) addr)[nr >>3 ] = oldval ^ mask; -return oldval & mask; -} - -extern int find_first_zero_bit (void * addr,unsigned size); -extern int find_next_zero_bit (void * addr,int size,int offset); - -/* -* This routine doesn't need to be atomic. -*/ -static inline int test_bit (int nr,const void * addr) -{ -return ((unsigned char *) addr)[nr >>3 ] & (1U << (nr &7 )); -}/* * ffz = Find First Zero in word. Undefined if no zero exists,
Signature · 1 line
1.6.3.1
PATCH 2/3 Add generic bit operations
This adds generic bit operations for all platforms and enables includes the implementations from asm-arm.
Code taken from Linux kernel.
--- include/asm-arm/bitops.h | 2 + include/asm-generic/bitops.h | 151 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 153 insertions(+), 0 deletions(-) create mode 100644 include/asm-generic/bitops.h
include/asm-arm/bitops.h +2 -0
@@ -15,6 +15,8 @@#ifndef __ASM_ARM_BITOPS_H#define __ASM_ARM_BITOPS_H +#include "asm-generic/bitops.h" +#ifdef __KERNEL__#define smp_mb__before_clear_bit () do { } while (0)
include/asm-generic/bitops.h new file +151 -0
151 lines not on this page · raw message
Signature · 1 line
1.6.3.1
PATCH 3/3 ARM: add unaligned macros
--- include/asm-arm/unaligned.h | 14 ++++++++++++++ 1 files changed, 14 insertions(+), 0 deletions(-) create mode 100644 include/asm-arm/unaligned.h
include/asm-arm/unaligned.h new file +14 -0
@@ -0,0 +1,14 @@ +#ifndef _ASM_ARM_UNALIGNED_H +#define _ASM_ARM_UNALIGNED_H + +#ifdef __KERNEL__ + +#include <linux/unaligned/access_ok.h> +#include <linux/unaligned/generic.h> + +#define get_unaligned __get_unaligned_le +#define put_unaligned __put_unaligned_le + +#endif /* __KERNEL__ */ +#endif /* _ASM_ARM_UNALIGNED_H */ +
Signature · 1 line
1.6.3.1
PATCH 3/3 ARM: add unaligned macros
Quoted 4 lines · Daniel Mack
--- include/asm-arm/unaligned.h | 14 ++++++++++++++ 1 files changed, 14 insertions(+), 0 deletions(-) create mode 100644 include/asm-arm/unaligned.h
This one was too easy, updated patch below.
With that one applied, the lzo1x decompressor and the whole ubifs works fine on an ARM PXA3xx.
Daniel
PATCH 3/3 ARM: add unaligned macros
Dear Daniel Mack,
Quoted 5 lines · In message <[email protected]> you wrote:
(quoted diff) +4
-0+static inline u16 get_unaligned_le16(const void *p) +{ + return __get_unaligned_cpu16((const u8 *)p); +}
Review
Quoted 10 lines
(quoted diff) +10
-0+ +static inline u32 get_unaligned_le32(const void *p) +{ + return __get_unaligned_cpu32((const u8 *)p); +} + +static inline u64 get_unaligned_le64(const void *p) +{ + return __get_unaligned_cpu64((const u8 *)p); +}
Are these 3 really all "u8" pointers, or is this a copy & paste error?
Is there any guarantee that such macros are never used on device registers and the like?
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 "It is better to have tried and failed than to have failed to try, but the result's the same." - Mike Dennison
PATCH 3/3 ARM: add unaligned macros
Quoted 8 lines · Wolfgang Denk
Quoted 8 lines
(quoted diff) +8
-0+static inline u16 get_unaligned_le16(const void *p) +{ + return __get_unaligned_cpu16((const u8 *)p); +} + +static inline u32 get_unaligned_le32(const void *p) +{ + return __get_unaligned_cpu32((const u8 *)p);
Quoted 8 lines
Review
Quoted 6 lines
(quoted diff) +6
-0+} + +static inline u64 get_unaligned_le64(const void *p) +{ + return __get_unaligned_cpu64((const u8 *)p); +}Are these 3 really all "u8" pointers, or is this a copy & paste error?
Yes, this is how it came from the Linux kernel and my tests show that these access methods work well.
Quoted 2 lines
Is there any guarantee that such macros are never used on device registers and the like?
Well - how can I guarantee that? Anyway - the functions can be enhanced later to make them work with different types of memories. For now, they implement a working set of functions to allow ubifs (and probably other code as well) to be compiled and ran on ARMs.
Daniel
PATCH 3/3 ARM: add unaligned macros
Quoted 7 lines · On Thursday 04 June 2009 21:23:31 Daniel Mack wrote:
Quoted 2 lines
Is there any guarantee that such macros are never used on device registers and the like?
Well - how can I guarantee that? Anyway - the functions can be enhanced later to make them work with different types of memories. For now, they implement a working set of functions to allow ubifs (and probably other code as well) to be compiled and ran on ARMs.
Yes. I suggest that we just document that these functions (and the set_bit()... ones) don't implement any memory barriers/sync operations and therefore should be handled with care when used on IO registers etc (on platforms that need such barriers like PPC).
Best regards,
Stefan
=====================================================================
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-0 Fax: +49-8142-66989-80 Email: office at denx.de
=====================================================================
PATCH 2/3 Add generic bit operations
In reply to Daniel MackDear Daniel Mack,
Quoted 2 lines · In message <[email protected]> you wrote:
This adds generic bit operations for all platforms and enables includes the implementations from asm-arm.
Be careful. I am not sure if a generic definition is even possible. In any case, it is extremely risky to use in the wrong way.
It's nothing but faux ami.
My recommendation is NEVER to use any code based on bit numbers (even if this is what some chip documentation may refer to) but ONLY use appropriate masks instead.
Quoted 5 lines
new file mode 100644
index 0000000..088e5da
include/asm-generic/bitops.h line 10
Quoted 10 lines
include/asm-generic/bitops.h new file +10
-0@@ -0,0 +1,151 @@ +#ifndef _ASM_GENERIC_BITOPS_H_ +#define _ASM_GENERIC_BITOPS_H_ + +#include <asm/types.h> + +#define BIT (nr) (1UL << (nr)) +#define BIT_MASK (nr) (1UL << ((nr) % BITS_PER_LONG)) +#define BIT_WORD (nr) ((nr) / BITS_PER_LONG) +#define BITS_PER_BYTE 8 +#define BITS_TO_LONGS (nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long))
You see, this is plain wrong on PowerPC.
On PowerPC, bit number 0 is the most significant bit, not the least significant one as you assume here. So using this well-intended code on a PowerPC system will most likely get you in trouble.
[And you cannot even use a generic definition for PowerPC, as some- thing like "#define BIT(nr) (0x80000000 >> (nr))" will only work on 32 bit systems but be wrong on 64 bit ones.]
Let's get rid of this stuff, it is confusing.
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 "The one charm of marriage is that it makes a life of deception a neccessity." - Oscar Wilde
PATCH 2/3 Add generic bit operations
Quoted 11 lines · Wolfgang Denk
include/asm-generic/bitops.h line 10
Quoted 5 lines
include/asm-generic/bitops.h new file +5
-0+#define BIT (nr) (1UL << (nr)) +#define BIT_MASK (nr) (1UL << ((nr) % BITS_PER_LONG)) +#define BIT_WORD (nr) ((nr) / BITS_PER_LONG) +#define BITS_PER_BYTE 8 +#define BITS_TO_LONGS (nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long))You see, this is plain wrong on PowerPC.
On PowerPC, bit number 0 is the most significant bit, not the least significant one as you assume here. So using this well-intended code on a PowerPC system will most likely get you in trouble.
Well, the idea is to let those platforms use the generic operations that do not bring their owm ones. The code above is not on use by PPC, so it doesn't harm either.
Quoted 3 lines
[And you cannot even use a generic definition for PowerPC, as some- thing like "#define BIT(nr) (
0x80000000>> (nr))" will only work on 32 bit systems but be wrong on 64 bit ones.]
That is why PPC implements that in its own fashion. Fair enough.
Quoted 1 line
Let's get rid of this stuff, it is confusing.
Hmm, and how?
Daniel
PATCH 2/3 Add generic bit operations
Dear Daniel Mack,
Quoted 9 lines · In message <[email protected]> you wrote:
Quoted 9 lines
include/asm-generic/bitops.h line 10
Quoted 6 lines
include/asm-generic/bitops.h new file +5
-0+#define BIT (nr) (1UL << (nr)) +#define BIT_MASK (nr) (1UL << ((nr) % BITS_PER_LONG)) +#define BIT_WORD (nr) ((nr) / BITS_PER_LONG) +#define BITS_PER_BYTE 8 +#define BITS_TO_LONGS (nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long))You see, this is plain wrong on PowerPC.
Quoted 7 lines
Quoted 3 lines
On PowerPC, bit number 0 is the most significant bit, not the least significant one as you assume here. So using this well-intended code on a PowerPC system will most likely get you in trouble.
Well, the idea is to let those platforms use the generic operations that do not bring their owm ones. The code above is not on use by PPC, so it doesn't harm either.
But it is not a generic operation. The notion of "bit number" is a generic concept, but here we have a machine dependent implementation that sails under the name "asm-generic/bitops.h".
But it is NOT generic.
Quoted 3 lines
Quoted 1 line
Let's get rid of this stuff, it is confusing.
Hmm, and how?
Just don't use it. Use masks instead of bit numbers.
What's wrong with using 0x00008000 instead of BIT(15) (which would be 0x00010000 on 32 bit Power systems).
Best regards,
Wolfgang Denk
Signature · 6 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
Prof: So the American government went to IBM to come up with a
data encryption standard and they came up with ...
Student: EBCDIC!PATCH 2/3 Add generic bit operations
In reply to Daniel MackDear Daniel Mack,
Quoted 2 lines · In message <[email protected]> you wrote:
This adds generic bit operations for all platforms and enables includes the implementations from asm-arm.
I should have read the patch to end...
Quoted 5 lines
include/asm-generic/bitops.h new file +5
-0+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); +
include/asm-generic/bitops.h line 35
Quoted 10 lines
include/asm-generic/bitops.h new file +10
-0+ *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; +}
Such code has no chance of being accepted anyway.
It tries to be generic and does not care if you use it on memory or device addresses - but for device addresses, the use of proper I/O accessor functions is mandatory.
Full NAK.
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 I really hate this damned machine It never does quite what I want I wish that they would sell it. But only what I tell it.
PATCH 2/3 Add generic bit operations
Quoted 10 lines · Wolfgang Denk
include/asm-generic/bitops.h line 35
Quoted 7 lines
include/asm-generic/bitops.h new file +7
-0+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; +}Such code has no chance of being accepted anyway.
Quoted 3 lines
It tries to be generic and does not care if you use it on memory or device addresses - but for device addresses, the use of proper I/O accessor functions is mandatory.
And the functions I removed from asm-arm/bitops.h did that?
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH 2/3 Add generic bit operations
Quoted 5 lines · Wolfgang Denk
Quoted 1 line
And the functions I removed from
asm-arm/bitops.hdid that?No. Let's be happy that we have eliminated some poor code, and if we add a replacement, let's make sure not to repeat the mistakes of the past again.
Ok. I just saw ubifs implementing its own set_bit() functions and considered that the wrong place for such functions to live in. ext2 seems to do the same things, also minix. Platforms which want to enable support for these filesystems have to do an evil #define to map ext2_set_bit() to the platform specific version. Which is all bogus, you might agree. And because of that situation, ubifs can't currently build for anything else than ppc
(according to 'git grep -w fls include/asm*').
Hence I thought it might be a good idea (or at least a good start thereof) to put the functions where I believe they belong to - a 'generic' place.
Anyway - applying the first patch of this series would at least prevent others from being mislead by dead and wrong code.
Daniel
PATCH 2/3 Add generic bit operations
Quoted 7 lines · On Thursday 04 June 2009 20:00:42 Daniel Mack wrote:
Quoted 5 lines · Wolfgang Denk
Quoted 1 line
And the functions I removed from
asm-arm/bitops.hdid that?No. Let's be happy that we have eliminated some poor code, and if we add a replacement, let's make sure not to repeat the mistakes of the past again.
Quoted 6 lines
Ok. I just saw ubifs implementing its own
set_bit()functions and considered that the wrong place for such functions to live in. ext2 seems to do the same things, also minix. Platforms which want to enable support for these filesystems have to do an evil #define to mapext2_set_bit()to the platform specific version. Which is all bogus, you might agree.
Ack. It would a good thing to have those functions available for all architectures so that common code like UBIFS etc can use it. Please note that UBIFS uses these bit functions for memory operations only (not IO access). So we don't have to use accessor functions etc here. The "standard" Linux implementation should do.
Quoted 7 lines
And because of that situation, ubifs can't
currently build for anything else than ppc
(according to 'git grep -w flsinclude/asm*').Hence I thought it might be a good idea (or at least a good start thereof) to put the functions where I believe they belong to - a 'generic' place.
Yes, I do like this approach. And from my point of view, we should continue this way.
Best regards,
Stefan
=====================================================================
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-0 Fax: +49-8142-66989-80 Email: office at denx.de
=====================================================================
PATCH 2/3 Add generic bit operations
In reply to Daniel MackDear Daniel Mack,
Quoted 9 lines · In message <[email protected]> you wrote:
Ok. I just saw ubifs implementing its own
set_bit()functions and considered that the wrong place for such functions to live in. ext2 seems to do the same things, also minix. Platforms which want to enable support for these filesystems have to do an evil #define to mapext2_set_bit()to the platform specific version. Which is all bogus, you might agree. And because of that situation, ubifs can't currently build for anything else than ppc
(according to 'git grep -w flsinclude/asm*').
Yes, we have a mess here, and we need toclean this up ASAP.
I'm trying to find out if there is any agreement what a portable set of I/O and bit macro definitions should look like.
Quoted 2 lines
Anyway - applying the first patch of this series would at least prevent others from being mislead by dead and wrong code.
ACK on that.
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 There are three ways to get something done: do it yourself, hire someone, or forbid your kids to do it.
PATCH 2/3 Add generic bit operations
In reply to Daniel MackQuoted 5 lines · Daniel Mack
This adds generic bit operations for all platforms and enables includes the implementations from asm-arm.
Code taken from Linux kernel.
the __set_bit, __clear_bit, __change_bit & co generic is used on arm ok
but be aware that we use it in U-Boot so NACK
and please do not rename __xxx by xxx they do not mean the same think
the __xxx can be re-ordered and the xxx not
IMHO please keep the linux naming to simplify think in the futur and please specify which file it's import and which kernel version
Best Regards,
J.
PATCH 2/3 Add generic bit operations
Quoted 6 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 5 lines
This adds generic bit operations for all platforms and enables includes the implementations from asm-arm.
Code taken from Linux kernel.
the
__set_bit,__clear_bit,__change_bit& co generic is used on arm ok
Do you mean it worked before? Or are you referring to the version I posted which you think is ok?
Quoted 1 line
but be aware that we use it in U-Boot so NACK
You use what? The functions I removed? I doubt that. The functions marked 'external' have no implementation, and I also don't believe the static inlines did the right thing (note the shift operations).
Quoted 3 lines
and please do not rename
__xxxby xxx they do not mean the same thinkthe
__xxxcan be re-ordered and the xxx not
Sorry, I don't get it - what's your point about the status quo in the sources and about the patches?
Daniel