From: Scott Wood <scottwood@freescale.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] mmc:dcache: Cache line size aligned internal MMC buffers
Date: Mon, 29 Aug 2011 15:47:26 -0500 [thread overview]
Message-ID: <4E5BFADE.9000200@freescale.com> (raw)
In-Reply-To: <CAF6FioWhhqbVQWWPrusb69S2mpfBtoiazxc8x56bkogJmzXZ3g@mail.gmail.com>
On 08/29/2011 03:12 PM, Anton Staaf wrote:
> 1) Mikes's macro
>
> #define DMA_ALIGN_SIZE(size) \
> (((size) + CONFIG_SYS_CACHELINE_SIZE - 1)
>
> #define DMA_DECLARE_BUFFER(type, name, size) \
> void __##name[DMA_ALIGN_SIZE(size * sizeof(type))]; \
> type * name = __##name & ~(CONFIG_SYS_CACHELINE_SIZE - 1));
>
> DMA_DECLARE_BUFFER(int, buffer, 100);
This doesn't compile, and it tries to round the buffer down below its
starting point.
After fixing the more obvious issues, I get "error: initializer element
is not constant".
There might be no way to express and-by-constant as a relocation.
You could set the pointer at runtime, though, and remove some of the
macrification:
#define DMA_ALIGN_SIZE(size) \
((size) + CONFIG_SYS_CACHELINE_SIZE - 1)
#define DMA_ALIGN_ADDR(addr) \
(DMA_ALIGN_SIZE(addr) & (CONFIG_SYS_CACHELINE_SIZE - 1))
int buffer_unaligned[DMA_ALIGN_SIZE(100)];
int *buffer;
some_init_func()
{
buffer = (int *)(DMA_ALIGN_ADDR((uintptr_t)buffer_unaligned));
}
> 3) Use GCC specific alignment attribute:
>
> #define CACHLINE_ALIGNED __attribute__ ((aligned (CONFIG_SYS_CACHELINE_SIZE)))
>
> int buffer[100] CACHELINE_ALIGNED;
>
> Pros: The declaration of the buffer is even simpler and more obvious,
> no use of alloca at all.
>
> Cons: This doesn't work in any version of GCC before October 2010.
> Meaning that it probably doesn't work in whatever compiler you're
> using.
>
>
> It's really too bad that this isn't a usable solution. I suppose that
> we could switch to it at some point when we expect U-Boot to only be
> compiled by versions of GCC that support this. By the way, the
> failure mode here is pretty bad. If you compile the above code with
> an older GCC it will silently fail to align the variable. :(
If the decision is made to depend on newer compilers, U-Boot could check
for it and #error out if the compiler is too old (possibly just in the
files that depend on this feature).
-Scott
next prev parent reply other threads:[~2011-08-29 20:47 UTC|newest]
Thread overview: 55+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-08-19 9:25 [U-Boot] [PATCH] mmc:dcache: Cache line size aligned internal MMC buffers Lukasz Majewski
2011-08-19 13:57 ` Mike Frysinger
2011-08-19 15:28 ` Lukasz Majewski
2011-08-19 15:35 ` Mike Frysinger
2011-08-22 7:29 ` Lukasz Majewski
2011-08-22 16:08 ` Mike Frysinger
2011-08-22 16:42 ` Anton Staaf
2011-08-22 16:52 ` Marek Vasut
2011-08-22 17:17 ` Mike Frysinger
2011-08-22 18:15 ` Anton Staaf
2011-08-22 18:31 ` Mike Frysinger
2011-08-22 18:57 ` Anton Staaf
2011-08-23 9:19 ` Lukasz Majewski
2011-08-23 17:00 ` Anton Staaf
2011-08-23 17:30 ` Mike Frysinger
2011-08-23 18:12 ` Anton Staaf
2011-08-23 18:35 ` Mike Frysinger
2011-08-23 18:36 ` Mike Frysinger
2011-08-23 18:46 ` Anton Staaf
2011-08-23 20:12 ` Wolfgang Denk
2011-08-23 20:27 ` Anton Staaf
2011-08-23 20:37 ` Mike Frysinger
2011-08-23 21:06 ` Anton Staaf
2011-08-23 21:32 ` Mike Frysinger
2011-08-23 21:09 ` Wolfgang Denk
2011-08-23 21:32 ` Mike Frysinger
2011-08-23 21:48 ` Anton Staaf
2011-08-24 16:16 ` Mike Frysinger
2011-08-23 22:42 ` Wolfgang Denk
2011-08-24 3:00 ` Mike Frysinger
2011-08-24 10:07 ` Lukasz Majewski
2011-08-24 13:25 ` Wolfgang Denk
2011-08-24 14:31 ` Lukasz Majewski
2011-08-24 16:20 ` Mike Frysinger
2011-08-24 17:27 ` Anton Staaf
2011-08-24 18:06 ` Mike Frysinger
2011-08-24 18:12 ` Wolfgang Denk
2011-08-24 18:25 ` Anton Staaf
2011-08-24 19:04 ` Wolfgang Denk
2011-08-24 20:12 ` Anton Staaf
2011-08-24 19:18 ` Lukasz Majewski
2011-08-24 20:13 ` Anton Staaf
2011-08-29 20:12 ` Anton Staaf
2011-08-29 20:35 ` Wolfgang Denk
2011-08-29 21:08 ` Anton Staaf
2011-08-29 20:47 ` Scott Wood [this message]
2011-08-29 20:58 ` Anton Staaf
2011-08-29 21:23 ` Scott Wood
2011-08-29 21:54 ` Anton Staaf
2011-08-29 22:03 ` Scott Wood
2011-08-29 22:49 ` Anton Staaf
2011-08-29 23:01 ` Scott Wood
2011-08-29 23:05 ` Anton Staaf
2011-08-23 20:35 ` Mike Frysinger
2011-08-23 8:42 ` Lukasz Majewski
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=4E5BFADE.9000200@freescale.com \
--to=scottwood@freescale.com \
--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