]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
lib_ppc: rework the flush_cache
authorDave Liu <daveliu@freescale.com>
Fri, 5 Dec 2008 07:36:14 +0000 (15:36 +0800)
committerWolfgang Denk <wd@denx.de>
Mon, 15 Dec 2008 21:31:39 +0000 (22:31 +0100)
- It is possible to miss flush/invalidate the last
  cache line, we fix it at here.
- add the volatile and memory clobber.

They are pointed by Scott Wood.

Signed-off-by: Dave Liu <daveliu@freescale.com>
lib_ppc/cache.c

index 72c838e4181dd7c7a8be6e864d5de26aebc6135f..1292b71e6ef206321b0ecb36d7c3fc5d2a408548 100644 (file)
 #include <asm/cache.h>
 #include <watchdog.h>
 
-void flush_cache (ulong start_addr, ulong size)
+void flush_cache(ulong start_addr, ulong size)
 {
 #ifndef CONFIG_5xx
-       ulong addr, end_addr = start_addr + size;
+       ulong addr, start, end;
 
-       if (CONFIG_SYS_CACHELINE_SIZE) {
-               addr = start_addr & (CONFIG_SYS_CACHELINE_SIZE - 1);
-               for (addr = start_addr;
-                    addr < end_addr;
-                    addr += CONFIG_SYS_CACHELINE_SIZE) {
-                       asm ("dcbst 0,%0": :"r" (addr));
-                       WATCHDOG_RESET();
-               }
-               asm ("sync");   /* Wait for all dcbst to complete on bus */
+       start = start_addr & ~(CONFIG_SYS_CACHELINE_SIZE - 1);
+       end = start_addr + size - 1;
 
-               for (addr = start_addr;
-                    addr < end_addr;
-                    addr += CONFIG_SYS_CACHELINE_SIZE) {
-                       asm ("icbi 0,%0": :"r" (addr));
-                       WATCHDOG_RESET();
-               }
+       for (addr = start; addr <= end; addr += CONFIG_SYS_CACHELINE_SIZE) {
+               asm volatile("dcbst 0,%0" : : "r" (addr) : "memory");
+               WATCHDOG_RESET();
        }
-       asm ("sync");           /* Always flush prefetch queue in any case */
-       asm ("isync");
+       /* wait for all dcbst to complete on bus */
+       asm volatile("sync" : : : "memory");
+
+       for (addr = start; addr <= end; addr += CONFIG_SYS_CACHELINE_SIZE) {
+               asm volatile("icbi 0,%0" : : "r" (addr) : "memory");
+               WATCHDOG_RESET();
+       }
+       asm volatile("sync" : : : "memory");
+       /* flush prefetch queue */
+       asm volatile("isync" : : : "memory");
 #endif
 }