diff mbox

[09/17] ARM: add atag32_to_cpu() function

Message ID 1360365467-25056-10-git-send-email-ben.dooks@codethink.co.uk (mailing list archive)
State New, archived
Headers show

Commit Message

Ben Dooks Feb. 8, 2013, 11:17 p.m. UTC
Add atag32_to_cpu() function to allow code manipulating ATAGs to deal
with the case where the boot-loader was in little-endian and Linux is
running big-endian.

Signed-off-by: Ben Dooks <ben.dooks@codethink.co.uk>
---
 arch/arm/include/uapi/asm/setup.h |    9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

Comments

Nicolas Pitre Feb. 9, 2013, 3:57 a.m. UTC | #1
On Fri, 8 Feb 2013, Ben Dooks wrote:

> Add atag32_to_cpu() function to allow code manipulating ATAGs to deal
> with the case where the boot-loader was in little-endian and Linux is
> running big-endian.
> 
> Signed-off-by: Ben Dooks <ben.dooks@codethink.co.uk>

Acked-by: Nicolas Pitre <nico@linaro.org>

> ---
>  arch/arm/include/uapi/asm/setup.h |    9 +++++++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/arm/include/uapi/asm/setup.h b/arch/arm/include/uapi/asm/setup.h
> index 979ff40..d74a417 100644
> --- a/arch/arm/include/uapi/asm/setup.h
> +++ b/arch/arm/include/uapi/asm/setup.h
> @@ -175,13 +175,18 @@ struct tagtable {
>  
>  #define tag_member_present(tag,member)				\
>  	((unsigned long)(&((struct tag *)0L)->member + 1)	\
> -		<= (tag)->hdr.size * 4)
> +		<= atag32_to_cpu((tag)->hdr.size) * 4)
>  
> -#define tag_next(t)	((struct tag *)((__u32 *)(t) + (t)->hdr.size))
> +#define tag_next(t)	((struct tag *)((__u32 *)(t) + atag32_to_cpu((t)->hdr.size)))
>  #define tag_size(type)	((sizeof(struct tag_header) + sizeof(struct type)) >> 2)
>  
>  #define for_each_tag(t,base)		\
>  	for (t = base; t->hdr.size; t = tag_next(t))
>  
> +#ifdef CONFIG_CPU_BE8_BOOT_LE
> +#define atag32_to_cpu(x)	le32_to_cpu(x)
> +#else
> +#define atag32_to_cpu(x)	x
> +#endif
>  
>  #endif /* _UAPI__ASMARM_SETUP_H */
> -- 
> 1.7.10.4
> 
> 
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
>
Russell King - ARM Linux Feb. 9, 2013, 12:03 p.m. UTC | #2
On Fri, Feb 08, 2013 at 11:17:39PM +0000, Ben Dooks wrote:
> Add atag32_to_cpu() function to allow code manipulating ATAGs to deal
> with the case where the boot-loader was in little-endian and Linux is
> running big-endian.
...
> +#ifdef CONFIG_CPU_BE8_BOOT_LE
> +#define atag32_to_cpu(x)	le32_to_cpu(x)
> +#else
> +#define atag32_to_cpu(x)	x
> +#endif

Actually, with a LE kernel, le32_to_cpu() ends up being a no-op too.  So
I'm wondering if we should do this a different way...

Also, this will cause sparse to complain - le32_to_cpu() takes a le32
type not a u32 type.

This brings up a whole load of difficulties though: what format are the
ATAGs on older BE hardware - I bet it's CPU-endian format there.  So,
I'm wondering if we should do this:

1. define all tags using a new __atagXX, etc types.
2. always use atagXX_to_cpu() to read these.
3. Implement:

#if defined(CONFIG_ATAG_LE)
typedef __le32 __atag32;
...
#define atag32_to_cpu(x) le32_to_cpu(x)
...
#elif defined(CONFIG_ATAG_BE)
typedef __be32 __atag32;
...
#define atag32_to_cpu(x) be32_to_cpu(x)
...
#elif defined(CONFIG_ATAG_NE)
typedef __u32 __atag32;
...
#define atag32_to_cpu(x) x
...
#endif

and select the appropriate definition.  Obviously, this is a fundamental
configuration just like the overall BE/LE configuration of the kernel.
Ben Dooks Feb. 11, 2013, 7:15 p.m. UTC | #3
On 09/02/13 12:03, Russell King - ARM Linux wrote:
> On Fri, Feb 08, 2013 at 11:17:39PM +0000, Ben Dooks wrote:
>> Add atag32_to_cpu() function to allow code manipulating ATAGs to deal
>> with the case where the boot-loader was in little-endian and Linux is
>> running big-endian.
> ...
>> +#ifdef CONFIG_CPU_BE8_BOOT_LE
>> +#define atag32_to_cpu(x)	le32_to_cpu(x)
>> +#else
>> +#define atag32_to_cpu(x)	x
>> +#endif
>
> Actually, with a LE kernel, le32_to_cpu() ends up being a no-op too.  So
> I'm wondering if we should do this a different way...
>
> Also, this will cause sparse to complain - le32_to_cpu() takes a le32
> type not a u32 type.

Yes, you're right on that.

> This brings up a whole load of difficulties though: what format are the
> ATAGs on older BE hardware - I bet it's CPU-endian format there.  So,
> I'm wondering if we should do this:

It isn't defined, and I have failed to find any information on
it online. I have no idea if the IXP devices ran their boot-loader
in big-endian or little-endian format?

Input welcome from anyone who can remember.

> 1. define all tags using a new __atagXX, etc types.
> 2. always use atagXX_to_cpu() to read these.
> 3. Implement:
>
> #if defined(CONFIG_ATAG_LE)
> typedef __le32 __atag32;
> ...
> #define atag32_to_cpu(x) le32_to_cpu(x)
> ...
> #elif defined(CONFIG_ATAG_BE)
> typedef __be32 __atag32;
> ...
> #define atag32_to_cpu(x) be32_to_cpu(x)
> ...
> #elif defined(CONFIG_ATAG_NE)
> typedef __u32 __atag32;
> ...
> #define atag32_to_cpu(x) x
> ...
> #endif
>
> and select the appropriate definition.  Obviously, this is a fundamental
> configuration just like the overall BE/LE configuration of the kernel.

Ok, should I sort out doing that for the next round of patches?

Should the ATAG_xx configurations go into arch/arm/Kconfig or
is there somewhere better for them to go?
Russell King - ARM Linux Feb. 11, 2013, 7:30 p.m. UTC | #4
On Mon, Feb 11, 2013 at 07:15:19PM +0000, Ben Dooks wrote:
> It isn't defined, and I have failed to find any information on
> it online. I have no idea if the IXP devices ran their boot-loader
> in big-endian or little-endian format?

It will be native endian, because that's the format which we've supported
up to now.

>> 1. define all tags using a new __atagXX, etc types.
>> 2. always use atagXX_to_cpu() to read these.
>> 3. Implement:
>>
>> #if defined(CONFIG_ATAG_LE)
>> typedef __le32 __atag32;
>> ...
>> #define atag32_to_cpu(x) le32_to_cpu(x)
>> ...
>> #elif defined(CONFIG_ATAG_BE)
>> typedef __be32 __atag32;
>> ...
>> #define atag32_to_cpu(x) be32_to_cpu(x)
>> ...
>> #elif defined(CONFIG_ATAG_NE)
>> typedef __u32 __atag32;
>> ...
>> #define atag32_to_cpu(x) x
>> ...
>> #endif
>>
>> and select the appropriate definition.  Obviously, this is a fundamental
>> configuration just like the overall BE/LE configuration of the kernel.
>
> Ok, should I sort out doing that for the next round of patches?

Yes please.

> Should the ATAG_xx configurations go into arch/arm/Kconfig or
> is there somewhere better for them to go?

arch/arm/Kconfig for the time being.  I've debated about moving some
config options to arch/arm/boot/Kconfig
Jean-Christophe PLAGNIOL-VILLARD Feb. 12, 2013, 6:46 p.m. UTC | #5
On 19:15 Mon 11 Feb     , Ben Dooks wrote:
> On 09/02/13 12:03, Russell King - ARM Linux wrote:
> >On Fri, Feb 08, 2013 at 11:17:39PM +0000, Ben Dooks wrote:
> >>Add atag32_to_cpu() function to allow code manipulating ATAGs to deal
> >>with the case where the boot-loader was in little-endian and Linux is
> >>running big-endian.
> >...
> >>+#ifdef CONFIG_CPU_BE8_BOOT_LE
> >>+#define atag32_to_cpu(x)	le32_to_cpu(x)
> >>+#else
> >>+#define atag32_to_cpu(x)	x
> >>+#endif
> >
> >Actually, with a LE kernel, le32_to_cpu() ends up being a no-op too.  So
> >I'm wondering if we should do this a different way...
> >
> >Also, this will cause sparse to complain - le32_to_cpu() takes a le32
> >type not a u32 type.
> 
> Yes, you're right on that.
> 
> >This brings up a whole load of difficulties though: what format are the
> >ATAGs on older BE hardware - I bet it's CPU-endian format there.  So,
> >I'm wondering if we should do this:
> 
> It isn't defined, and I have failed to find any information on
> it online. I have no idea if the IXP devices ran their boot-loader
> in big-endian or little-endian format?
> 
> Input welcome from anyone who can remember.
I run the ixp in be

and pass the atag in be

Best Regards,
J.
> 
> >1. define all tags using a new __atagXX, etc types.
> >2. always use atagXX_to_cpu() to read these.
> >3. Implement:
> >
> >#if defined(CONFIG_ATAG_LE)
> >typedef __le32 __atag32;
> >...
> >#define atag32_to_cpu(x) le32_to_cpu(x)
> >...
> >#elif defined(CONFIG_ATAG_BE)
> >typedef __be32 __atag32;
> >...
> >#define atag32_to_cpu(x) be32_to_cpu(x)
> >...
> >#elif defined(CONFIG_ATAG_NE)
> >typedef __u32 __atag32;
> >...
> >#define atag32_to_cpu(x) x
> >...
> >#endif
> >
> >and select the appropriate definition.  Obviously, this is a fundamental
> >configuration just like the overall BE/LE configuration of the kernel.
> 
> Ok, should I sort out doing that for the next round of patches?
> 
> Should the ATAG_xx configurations go into arch/arm/Kconfig or
> is there somewhere better for them to go?
> 
> -- 
> Ben Dooks				http://www.codethink.co.uk/
> Senior Engineer				Codethink - Providing Genius
> 
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Russell King - ARM Linux Feb. 12, 2013, 8:34 p.m. UTC | #6
On Tue, Feb 12, 2013 at 07:46:36PM +0100, Jean-Christophe PLAGNIOL-VILLARD wrote:
> I run the ixp in be
> 
> and pass the atag in be

So that would be "native endian" then.
diff mbox

Patch

diff --git a/arch/arm/include/uapi/asm/setup.h b/arch/arm/include/uapi/asm/setup.h
index 979ff40..d74a417 100644
--- a/arch/arm/include/uapi/asm/setup.h
+++ b/arch/arm/include/uapi/asm/setup.h
@@ -175,13 +175,18 @@  struct tagtable {
 
 #define tag_member_present(tag,member)				\
 	((unsigned long)(&((struct tag *)0L)->member + 1)	\
-		<= (tag)->hdr.size * 4)
+		<= atag32_to_cpu((tag)->hdr.size) * 4)
 
-#define tag_next(t)	((struct tag *)((__u32 *)(t) + (t)->hdr.size))
+#define tag_next(t)	((struct tag *)((__u32 *)(t) + atag32_to_cpu((t)->hdr.size)))
 #define tag_size(type)	((sizeof(struct tag_header) + sizeof(struct type)) >> 2)
 
 #define for_each_tag(t,base)		\
 	for (t = base; t->hdr.size; t = tag_next(t))
 
+#ifdef CONFIG_CPU_BE8_BOOT_LE
+#define atag32_to_cpu(x)	le32_to_cpu(x)
+#else
+#define atag32_to_cpu(x)	x
+#endif
 
 #endif /* _UAPI__ASMARM_SETUP_H */