2016-06-30 02:29:51 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2016 Intel Corporation
|
|
|
|
*
|
2017-01-19 09:01:01 +08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2016-06-30 02:29:51 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <arch/cpu.h>
|
2019-06-26 22:33:39 +08:00
|
|
|
#include <sys/__assert.h>
|
2016-06-30 02:29:51 +08:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Flush the entire instruction cache and pipeline.
|
|
|
|
*
|
|
|
|
* You will need to call this function if the application writes new program
|
|
|
|
* text to memory, such as a boot copier or runtime synthesis of code. If the
|
|
|
|
* new text was written with instructions that do not bypass cache memories,
|
|
|
|
* this should immediately be followed by an invocation of
|
2019-03-14 23:20:46 +08:00
|
|
|
* z_nios2_dcache_flush_all() so that cached instruction data is committed to
|
2016-06-30 02:29:51 +08:00
|
|
|
* RAM.
|
|
|
|
*
|
|
|
|
* See Chapter 9 of the Nios II Gen 2 Software Developer's Handbook for more
|
|
|
|
* information on cache considerations.
|
|
|
|
*/
|
2016-07-12 03:42:02 +08:00
|
|
|
#if ALT_CPU_ICACHE_SIZE > 0
|
2019-03-14 23:20:46 +08:00
|
|
|
void z_nios2_icache_flush_all(void)
|
2016-06-30 02:29:51 +08:00
|
|
|
{
|
2017-04-21 02:30:33 +08:00
|
|
|
u32_t i;
|
2016-06-30 02:29:51 +08:00
|
|
|
|
2018-11-30 03:09:09 +08:00
|
|
|
for (i = 0U; i < ALT_CPU_ICACHE_SIZE; i += ALT_CPU_ICACHE_LINE_SIZE) {
|
2019-03-14 23:20:46 +08:00
|
|
|
z_nios2_icache_flush(i);
|
2016-06-30 02:29:51 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Get rid of any stale instructions in the pipeline */
|
2019-03-14 23:20:46 +08:00
|
|
|
z_nios2_pipeline_flush();
|
2016-06-30 02:29:51 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Flush the entire data cache.
|
|
|
|
*
|
|
|
|
* This will be typically needed after writing new program text to memory
|
|
|
|
* after flushing the instruction cache.
|
|
|
|
*
|
|
|
|
* The Nios II does not support hardware cache coherency for multi-master
|
|
|
|
* or multi-processor systems and software coherency must be implemented
|
|
|
|
* when communicating with shared memory. If support for this is introduced
|
|
|
|
* in Zephyr additional APIs for flushing ranges of the data cache will need
|
|
|
|
* to be implemented.
|
|
|
|
*
|
|
|
|
* See Chapter 9 of the Nios II Gen 2 Software Developer's Handbook for more
|
|
|
|
* information on cache considerations.
|
|
|
|
*/
|
2016-07-12 03:42:02 +08:00
|
|
|
#if ALT_CPU_DCACHE_SIZE > 0
|
2019-03-14 23:20:46 +08:00
|
|
|
void z_nios2_dcache_flush_all(void)
|
2016-06-30 02:29:51 +08:00
|
|
|
{
|
2017-04-21 02:30:33 +08:00
|
|
|
u32_t i;
|
2016-06-30 02:29:51 +08:00
|
|
|
|
2018-11-30 03:09:09 +08:00
|
|
|
for (i = 0U; i < ALT_CPU_DCACHE_SIZE; i += ALT_CPU_DCACHE_LINE_SIZE) {
|
2019-03-14 23:20:46 +08:00
|
|
|
z_nios2_dcache_flush(i);
|
2016-06-30 02:29:51 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2018-04-03 12:53:36 +08:00
|
|
|
|
|
|
|
/*
|
2019-03-14 23:20:46 +08:00
|
|
|
* z_nios2_dcache_flush_no_writeback() is called to flush the data cache for a
|
2018-04-03 12:53:36 +08:00
|
|
|
* 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,
|
2019-03-14 23:20:46 +08:00
|
|
|
* use the z_nios2_dcache_flush() routine instead.
|
2018-04-03 12:53:36 +08:00
|
|
|
*/
|
|
|
|
#if ALT_CPU_DCACHE_SIZE > 0
|
2019-03-14 23:20:46 +08:00
|
|
|
void z_nios2_dcache_flush_no_writeback(void *start, u32_t len)
|
2018-04-03 12:53:36 +08:00
|
|
|
{
|
|
|
|
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
|