[U-Boot] [PATCH] mmc:dcache: Cache line size aligned internal MMC buffers

Anton Staaf
2011-08-24T17:27:05Z

On Wed, Aug 24, 2011 at 6:25 AM, Wolfgang Denk <wd@denx.de> wrote:
> Dear Lukasz Majewski,
>
> In message <20110824120744.097ba2c5@lmajewski.digital.local> you wrote:
>>
>> After reading dcache related threads I'd like to sum them up:
>>
>> 1. alloca() -> not acceptable to u-boot mainline by Wolfgang. I agree
>> that alloca is NOT the way to go.
>>
>> 2. malloc/memalign -> avoidable to use
>>
>> 3. Mike's DMA_DECLARE_BUFFER(<buffer type>, <variable name>,
>> <size in bytes>)
>> solution looks OK for me, at least for the stack allocated data (e.g.
>> ext_csd).
>> However this proposed implementation has been NAK'ed by Wolfgang.
>>
>> I'm curious how this macro should look like? Is it only matter of code
>> reordering or other approach shall be found?
>
> I think I'd like to see a macro that can be used like this:
>
> ? ? ? ?void *dma_buffer_pointer = DMA_BUFFER(size_in_bytes);
>
>
>> 4. get_dcache_line_size() can be simply defined as
>> #define get_dcache_line_size() CONFIG_SYS_CACHE_LINE_SIZE if we
>> _really_ want to save a few bytes.
>
> Actually I fail to understand why we would ever need
> get_dcache_line_size() in a boot loader.

It is required so that we can correctly allocate buffers that will be
used by DMA engines to read or write data. The reason that these
buffers need to be cache line size aligned is because unaligned cache
invalidates are not possible to do in a safe way. The problem is that
invalidating a partial cache line requires invalidating the entire
line. And the other part of the line can contain nearby variables
(especially if the buffer is stack allocated), so we have to first
flush the cache line to be safe. However, that flush will clobber the
values that the DMA engine wrote to main memory that are not reflected
in the cache.

Thanks,
Anton

> Best regards,
>
> Wolfgang Denk
>
> --
> 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
> "You know, after a woman's raised a family and so on, ?she ?wants ?to
> start living her own life." ? "Whose life she's _been_ living, then?"
> ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?- Terry Pratchett, _Witches Abroad_
>