From e639c026b9bbe2d2faab37d61d52f63bebcfce38 Mon Sep 17 00:00:00 2001 From: Martin Erik Werner Date: Fri, 25 Nov 2016 19:21:40 +0100 Subject: or1k: Add functions for entire cache operations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add functions for flushing and invalidating whole cache. Since we don't have system calls that can operate on anything more than a single cache line, these simply retrieves the cache size and iterates over the full size, invalidating each line. The current implementation assumes that there's only one level of cache. These changes were contributed by Antmicro under contract by ÅAC Microtec AB. Close #2602 --- c/src/lib/libcpu/or1k/shared/cache/cache.c | 45 ++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/c/src/lib/libcpu/or1k/shared/cache/cache.c b/c/src/lib/libcpu/or1k/shared/cache/cache.c index 54728e1e1d..88cda1a00e 100644 --- a/c/src/lib/libcpu/or1k/shared/cache/cache.c +++ b/c/src/lib/libcpu/or1k/shared/cache/cache.c @@ -1,4 +1,8 @@ /* + * COPYRIGHT (c) 2014 ÅAC Microtec AB + * Contributor(s): + * Karol Gugala + * * COPYRIGHT (c) 2014 Hesham ALMatary * * COPYRIGHT (c) 1989-2006 @@ -14,6 +18,7 @@ #include #include #include +#include static inline void _CPU_OR1K_Cache_enable_data(void) { @@ -206,17 +211,51 @@ void _CPU_cache_unfreeze_instruction(void) void _CPU_cache_flush_entire_data(void) { - + int addr; + + /* We have only 0 level cache so we do not need to invalidate others */ + for ( + addr = _CPU_cache_get_data_cache_size(0); + addr > 0; + addr -= CPU_DATA_CACHE_ALIGNMENT + ) { + _CPU_OR1K_Cache_data_block_flush((uintptr_t) addr); + } } void _CPU_cache_invalidate_entire_data(void) { - + int addr; + + /* We have only 0 level cache so we do not need to invalidate others */ + for ( + addr = _CPU_cache_get_data_cache_size(0); + addr > 0; + addr -= CPU_DATA_CACHE_ALIGNMENT + ) { + _CPU_cache_invalidate_1_data_line((uintptr_t) addr); + } } void _CPU_cache_invalidate_entire_instruction(void) { - + int addr; + + /* We have only 0 level cache so we do not need to invalidate others */ + for ( + addr = _CPU_cache_get_instruction_cache_size(0); + addr > 0; + addr -= CPU_INSTRUCTION_CACHE_ALIGNMENT + ) { + _CPU_cache_invalidate_1_instruction_line((uintptr_t) addr); + } + + /* Flush instructions out of instruction buffer */ + __asm__ volatile("l.nop"); + __asm__ volatile("l.nop"); + __asm__ volatile("l.nop"); + __asm__ volatile("l.nop"); + __asm__ volatile("l.nop"); } void _CPU_cache_enable_data(void) -- cgit v1.2.3