[U-Boot] [PATCH] nios2: convert cache flush to use dm cpu data

Thomas Chou
2015-10-12T13:12:18Z

Hi Marek,

On 10/12/2015 06:30 PM, Marek Vasut wrote:
> There are also DEFINE_CACHE_ALIGN_BUFFER() and ALLOC_CACHE_ALIGN_BUFFER()
> macros which can be used to allocate such stuff on stack. And you sometimes
> do want to allocate things on stack instead of using malloc().

Thanks for sharing this.

> Sometimes you might want to allocate DMA buffers on stack, for example if
> you don't have mallocator running yet or if it's more convenient for some
> reason. So forcing everyone to allocate DMA buffers using malloc is not
> gonna slide I'm afraid.

The same rule can be applied to buffer allocated on stack, with the
macro you mentioned above. In all, cache line aware allocation on heap
or on stack must be used for DMA buffer.

> The cache flush ops is the best place to scream death and murder if someone
> tries such unaligned cache operation, so maybe you should even do a printf()
> there to weed such crappy drivers out for the 2016.01 release.
>
> I agree it's the responsibility of the driver, so if the driver doesn't do
> things right, it's a bug and the behavior of cache ops is undefined, which
> might as well be that we do the safer thing here and flush nothing.

It won't be safer to flush nothing. Sooner or later the cache will be
flushed due to data access, even if the cache flush ops is skip.

To solve problem like this, the only solution is to enforce the rule to
allocate DMA buffer. It is wrong to skip the flush.

Best regards,
Thomas