]> git.ipfire.org Git - people/ms/u-boot.git/commitdiff
MIPS: Ensure cache ops complete in cache maintenance functions
authorPaul Burton <paul.burton@mips.com>
Tue, 21 Nov 2017 19:18:37 +0000 (11:18 -0800)
committerDaniel Schwierzeck <daniel.schwierzeck@gmail.com>
Tue, 28 Nov 2017 20:59:30 +0000 (21:59 +0100)
A typical use of cache maintenance functions is to force writeback of
data which a device is about to read using DMA - for example a
descriptor or command structure. Such users of cache maintenance
functions require that operations on the cache have completed before
they proceed to instruct a device to read memory. This requires that we
place a completion barrier (ie. sync instruction) between the cache ops
and whatever write informs the device to perform DMA.

Whilst strictly speaking this isn't all users of the cache maintenance
functions & we could instead place the barriers in the drivers that
require them, it would be much more invasive to do so than to just have
the barrier be the default by placing it in the cache functions
themselves. The cost is low enough that it shouldn't matter to us in any
rare cases that we use the cache functions when not performing DMA.

Signed-off-by: Paul Burton <paul.burton@mips.com>
Cc: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
Cc: u-boot@lists.denx.de
arch/mips/lib/cache.c

index 91b037f87d7240c3a17bce4540564d9d6e29bc19..eba7fff316943dd2fd5467857c6ca85060b1502d 100644 (file)
@@ -10,6 +10,7 @@
 #ifdef CONFIG_MIPS_L2_CACHE
 #include <asm/cm.h>
 #endif
+#include <asm/io.h>
 #include <asm/mipsregs.h>
 
 DECLARE_GLOBAL_DATA_PTR;
@@ -116,7 +117,7 @@ void flush_cache(ulong start_addr, ulong size)
                /* flush I-cache & D-cache simultaneously */
                cache_loop(start_addr, start_addr + size, ilsize,
                           HIT_WRITEBACK_INV_D, HIT_INVALIDATE_I);
-               return;
+               goto ops_done;
        }
 
        /* flush D-cache */
@@ -129,6 +130,10 @@ void flush_cache(ulong start_addr, ulong size)
 
        /* flush I-cache */
        cache_loop(start_addr, start_addr + size, ilsize, HIT_INVALIDATE_I);
+
+ops_done:
+       /* ensure cache ops complete before any further memory accesses */
+       sync();
 }
 
 void flush_dcache_range(ulong start_addr, ulong stop)
@@ -145,6 +150,9 @@ void flush_dcache_range(ulong start_addr, ulong stop)
        /* flush L2 cache */
        if (slsize)
                cache_loop(start_addr, stop, slsize, HIT_WRITEBACK_INV_SD);
+
+       /* ensure cache ops complete before any further memory accesses */
+       sync();
 }
 
 void invalidate_dcache_range(ulong start_addr, ulong stop)
@@ -161,4 +169,7 @@ void invalidate_dcache_range(ulong start_addr, ulong stop)
                cache_loop(start_addr, stop, slsize, HIT_INVALIDATE_SD);
 
        cache_loop(start_addr, stop, lsize, HIT_INVALIDATE_D);
+
+       /* ensure cache ops complete before any further memory accesses */
+       sync();
 }