From: Albert ARIBAUD <albert.u.boot@aribaud.net>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] usb: do explicit unaligned accesses
Date: Fri, 31 Aug 2012 08:08:43 +0200 [thread overview]
Message-ID: <20120831080843.0215da82@lilith> (raw)
In-Reply-To: <201208310129.06184.marex@denx.de>
Hi Marek,
On Fri, 31 Aug 2012 01:29:05 +0200, Marek Vasut <marex@denx.de> wrote:
> Dear Lucas Stach,
>
> > usb_hub_descriptor has to be packed as it's used for
> > communication with the device. Member wHubCharacteristics
> > violates the natural alignment rules.
> >
> > Use explicit unaligned access functions for this member.
> > Fixes ARMv7 traping while using USB.
>
> Shouldn't a properly configured compiler prevent such behavior?
This has been discussed before. As a summary:
1. A properly configured compiler can pad a structure so that the
fields always start at an aligned address (assuming the structure base
address is itself aligned). But that alters the structure, and here
there must be no alterations to the structure.
2. A properly (and differently) configured compiler can automatically
generate native unaligned accesses to unaligned fields. This is
acceptable on armv6+ architectures, has a performance penalty on earlier
architectures, and does not necessarily work depending on the hardware
configuration.
3. A properly (and differently yet) configured compiler can
automatically generate non-native unaligned accesses to unaligned
fields. This is acceptable on all architectures, has a performance
penalty on pre-armV6 architectures for all misaligned accesses, whether
voluntary or not.
The conclusion of the discussion is as follows -- or to be more exact,
following this discussion, this is my stance as the U-Boot custodian:
i) All the code intended to run 'close to' U-Boot (i.e., U-Boot code
itself and application code) is controlled enough that we should be
able to know and limit which code requires misaligned access (such as
here for this USB structure field);
ii) On some ARM architectures, and possibly some non-ARM architectures
as well, native misaligned access incur a performance hit, and may
even simply be impossible or forbidden by a hardware or system design
decision.
iii) Thus, U-Boot should follow a strict policy of using native aligned
accesses only, possibly enforcing misaligned native access prevention in
hardware, and of explicitly emulating misaligned accesses when they
cannot be avoided.
Hope this clarifies.
Amicalement,
--
Albert.
next prev parent reply other threads:[~2012-08-31 6:08 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-08-30 23:13 [U-Boot] [PATCH] usb: do explicit unaligned accesses Lucas Stach
2012-08-30 23:29 ` Marek Vasut
2012-08-31 6:08 ` Albert ARIBAUD [this message]
2012-08-31 16:15 ` Marek Vasut
[not found] ` <20120831222008.3665fecb@lilith>
2012-08-31 22:16 ` Marek Vasut
2012-09-01 7:12 ` Albert ARIBAUD
[not found] ` <20120901084509.230c7385@lilith>
2012-09-01 14:34 ` Marek Vasut
[not found] ` <20120901170132.7f5cbfb1@lilith>
2012-09-01 15:12 ` Marek Vasut
2012-09-01 16:28 ` Albert ARIBAUD
2012-09-01 16:39 ` Wolfgang Denk
2012-09-01 17:14 ` Marek Vasut
[not found] ` <593AEF6C47F46446852B067021A273D660BA94A5@MUCSE039.lantiq.com>
2012-08-31 9:00 ` Lucas Stach
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=20120831080843.0215da82@lilith \
--to=albert.u.boot@aribaud.net \
--cc=u-boot@lists.denx.de \
/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