From bcf2d16b3107f456c44385d3925c527f47699acb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20Fr=C3=B6schle?= Date: Mon, 12 Aug 2013 21:06:36 +0000 Subject: [PATCH] added code to selectively push areas of memory from the caches --- include/cache.h | 27 +++++++++++++++++ sources/cache.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 106 insertions(+) diff --git a/include/cache.h b/include/cache.h index 2839ae9..b9ef015 100644 --- a/include/cache.h +++ b/include/cache.h @@ -26,6 +26,7 @@ */ #include +#include /* * CACR Cache Control Register @@ -54,9 +55,35 @@ #define CF_CACR_IDSP (0x00000080) /* Ins default supervisor-protect */ #define CF_CACR_EUSP (0x00000020) /* Switch stacks in user mode */ +#define _DCACHE_SET_MASK ((DCACHE_SIZE/64-1)< end_set) { + /* from the begining to the lowest address */ + for (set = 0; set <= end_set; set += (0x10 - 3)) { + asm volatile("cpushl ic,(%0)\n\t" + "addq.l #1,%0\n\t" + "cpushl ic,(%0)\n\t" + "addq.l #1,%0\n\t" + "cpushl ic,(%0)\n\t" + "addq.l #1,%0\n\t" + "cpushl ic,(%0)" : "=a" (set) : "a" (set)); + } + /* next loop will finish the cache ie pass the hole */ + end_set = LAST_ICACHE_ADDR; + } + for (set = start_set; set <= end_set; set += (0x10 - 3)) { + asm volatile("cpushl ic,(%0)\n\t" + "addq.l #1,%0\n\t" + "cpushl ic,(%0)\n\t" + "addq%.l #1,%0\n\t" + "cpushl ic,(%0)\n\t" + "addq.l #1,%0\n\t" + "cpushl ic,(%0)" : "=a" (set) : "a" (set)); + } +} + + + +/* + * flush and invalidate a specific region from the data cache + */ +void flush_dcache_range(void *address, size_t size) +{ + unsigned long set; + unsigned long start_set; + unsigned long end_set; + void *endaddr; + + endaddr = address + size; + start_set = (uint32_t) address & _DCACHE_SET_MASK; + end_set = (uint32_t) endaddr & _DCACHE_SET_MASK; + + if (start_set > end_set) { + /* from the begining to the lowest address */ + for (set = 0; set <= end_set; set += (0x10 - 3)) { + asm volatile("cpushl dc,(%0)\n\t" + "addq.l #1,%0\n\t" + "cpushl dc,(%0)\n\t" + "addq.l #1,%0\n\t" + "cpushl dc,(%0)\n\t" + "addq.l #1,%0\n\t" + "cpushl dc,(%0)" : "=a" (set) : "a" (set)); + } + /* next loop will finish the cache ie pass the hole */ + end_set = LAST_DCACHE_ADDR; + } + for (set = start_set; set <= end_set; set += (0x10 - 3)) { + asm volatile("cpushl dc,(%0)\n\t" + "addq.l #1,%0\n\t" + "cpushl dc,(%0)\n\t" + "addq%.l #1,%0\n\t" + "cpushl dc,(%0)\n\t" + "addq.l #1,%0\n\t" + "cpushl dc,(%0)" : "=a" (set) : "a" (set)); + } +}