From: Viresh Kumar <viresh.kumar@linaro.org>
To: Rob Herring <robherring2@gmail.com>
Cc: grant.likely@secretlab.ca, spear-devel@list.st.com,
devicetree-discuss@lists.ozlabs.org,
linux-kernel@vger.kernel.org, andriy.shevchenko@intel.com
Subject: Re: [PATCH] dt: add helper function to read u8 & u16 variables & arrays
Date: Fri, 26 Oct 2012 09:47:24 +0530 [thread overview]
Message-ID: <CAKohponSbbusMjcsEwKczvxaN54YKJPL05vLELSjW6dnKO_6Dg@mail.gmail.com> (raw)
In-Reply-To: <CAKohpom5QmO5vbREsMgi4EefLpBxXsk=QWVaZwTwC_Knf72GVA@mail.gmail.com>
On 25 October 2012 19:48, Viresh Kumar <viresh.kumar@linaro.org> wrote:
> The problem i see here is:
>
> The data passed via DT comes as Little Endian in the kernel.
>
> For a little endian system, byte zero will contain the data and so
> (u8) val
>
> look to be the correct thing.
>
> For a big endian system, byte 3 will contain data as it is swapped by
> be32_to_cpup.
> So (u8) val would return value stored by byte 0 instead. ??
I feel above explanation was wrong. I didn't had a big endian system
to test this but this is what i derived theoretically. Consider following
sequence of commands:
u32 x = 0x01; //This will store off-0: 1, off-3:0 for LE system
// and will store off-0: 0, off-3:1
for BE system
u8 y = (u8) x; // For any architecture type, i.e. big or
little this must store
// 1 in y. This is ANCI C semantic
and should be architecture
// independent.
Which would mean, type cast will give off-0 on LE and off-3 on BE systems. Don't
confuse this with getting values using pointers, as we try to get data
out of specific
locations in those cases.
So, my initial code seems to be doing the right thing. be32_to_cpup()
will move the
LSB to off-3 and that is what we will get during the cast.
I will resend my original code to you.
--
viresh
next prev parent reply other threads:[~2012-10-26 4:17 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-12 18:01 [PATCH] dt: add helper function to read u8 & u16 variables & arrays Viresh Kumar
2012-10-15 7:56 ` Shevchenko, Andriy
2012-10-15 8:06 ` Viresh Kumar
2012-10-25 7:03 ` Viresh Kumar
2012-10-25 13:19 ` Rob Herring
2012-10-25 14:18 ` Viresh Kumar
2012-10-26 4:17 ` Viresh Kumar [this message]
-- strict thread matches above, loose matches on Subject: below --
2012-11-20 4:45 Viresh Kumar
2012-11-20 8:21 ` Shevchenko, Andriy
2012-11-20 8:25 ` Viresh Kumar
2012-11-20 17:21 ` Stephen Warren
[not found] ` <0ee5b74534a09d75c14b22c2d9330c4971ab30fb.1353386646.git.viresh.kumar-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2012-11-21 4:24 ` Rob Herring
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAKohponSbbusMjcsEwKczvxaN54YKJPL05vLELSjW6dnKO_6Dg@mail.gmail.com \
--to=viresh.kumar@linaro.org \
--cc=andriy.shevchenko@intel.com \
--cc=devicetree-discuss@lists.ozlabs.org \
--cc=grant.likely@secretlab.ca \
--cc=linux-kernel@vger.kernel.org \
--cc=robherring2@gmail.com \
--cc=spear-devel@list.st.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).