MIPS: Clear instruction hazards in flush_cache()

When writing code, for example during relocation, we ensure that the
icache has a coherent view of the new instructions with a call to
flush_cache(). This handles the bulk of the work to ensure the new
instructions will execute as expected, however it does not ensure that
the CPU pipeline doesn't already contain instructions taken from a stale
view of the affected memory. This could theoretically be a problem for
relocation, but in practice typically isn't because we sync caches for
enough code after the entry point of the newly written code that by the
time the CPU pipeline might possibly fetch any of it we'll have long ago
written it back & invalidated any stale icache entries. This is however
a problem for shorter regions of code.

In preparation for later patches which write shorter segments of code,
ensure any instruction hazards are cleared by flush_cache() by
introducing & using a new instruction_hazard_barrier() function which
makes use of the jr.hb instruction to clear the hazard.

Signed-off-by: Paul Burton <paul.burton@mips.com>
Cc: Daniel Schwierzeck <daniel.schwierzeck@gmail.com>
Cc: u-boot@lists.denx.de
This commit is contained in:
Paul Burton 2017-11-21 11:18:38 -08:00 committed by Daniel Schwierzeck
parent 219c2db384
commit d8b326976a
2 changed files with 17 additions and 0 deletions

View file

@ -14,8 +14,10 @@
#ifndef _ASM_SYSTEM_H
#define _ASM_SYSTEM_H
#include <asm/asm.h>
#include <asm/sgidefs.h>
#include <asm/ptrace.h>
#include <linux/stringify.h>
#if 0
#include <linux/kernel.h>
#endif
@ -270,4 +272,15 @@ static inline void execution_hazard_barrier(void)
".set reorder");
}
static inline void instruction_hazard_barrier(void)
{
unsigned long tmp;
asm volatile(
__stringify(PTR_LA) "\t%0, 1f\n"
" jr.hb %0\n"
"1: .insn"
: "=&r"(tmp));
}
#endif /* _ASM_SYSTEM_H */

View file

@ -12,6 +12,7 @@
#endif
#include <asm/io.h>
#include <asm/mipsregs.h>
#include <asm/system.h>
DECLARE_GLOBAL_DATA_PTR;
@ -134,6 +135,9 @@ void flush_cache(ulong start_addr, ulong size)
ops_done:
/* ensure cache ops complete before any further memory accesses */
sync();
/* ensure the pipeline doesn't contain now-invalid instructions */
instruction_hazard_barrier();
}
void flush_dcache_range(ulong start_addr, ulong stop)