diff --git a/arch/nios2/core/cache.c b/arch/nios2/core/cache.c index 2584ea8c7b6..e6a59e9c392 100644 --- a/arch/nios2/core/cache.c +++ b/arch/nios2/core/cache.c @@ -60,3 +60,33 @@ void _nios2_dcache_flush_all(void) } } #endif + +/* + * _nios2_dcache_flush_no_writeback() is called to flush the data cache for a + * memory region of length "len" bytes, starting at address "start". + * + * Any dirty lines in the data cache are NOT written back to memory. + * Make sure you really want this behavior. If you aren't 100% sure, + * use the _nios2_dcache_flush() routine instead. + */ +#if ALT_CPU_DCACHE_SIZE > 0 +void _nios2_dcache_flush_no_writeback(void *start, u32_t len) +{ + u8_t *i; + u8_t *end = ((char *) start) + len; + + for (i = start; i < end; i += ALT_CPU_DCACHE_LINE_SIZE) { + __asm__ volatile ("initda (%0)" :: "r" (i)); + } + + /* + * For an unaligned flush request, we've got one more line left. + * Note that this is dependent on ALT_CPU_DCACHE_LINE_SIZE to be a + * multiple of 2 (which it always is). + */ + + if (((u32_t) start) & (ALT_CPU_DCACHE_LINE_SIZE - 1)) { + __asm__ volatile ("initda (%0)" :: "r" (i)); + } +} +#endif diff --git a/arch/nios2/include/kernel_arch_func.h b/arch/nios2/include/kernel_arch_func.h index d18d3218a34..8dbdbfc019f 100644 --- a/arch/nios2/include/kernel_arch_func.h +++ b/arch/nios2/include/kernel_arch_func.h @@ -60,8 +60,10 @@ void _nios2_icache_flush_all(void); #if ALT_CPU_DCACHE_SIZE > 0 void _nios2_dcache_flush_all(void); +void _nios2_dcache_flush_no_writeback(void *start, u32_t len); #else #define _nios2_dcache_flush_all() do { } while (0) +#define _nios2_dcache_flush_no_writeback(x, y) do { } while (0) #endif #endif /* _ASMLANGUAGE */