Commit 1cd03890 authored by LEROY Christophe's avatar LEROY Christophe Committed by Michael Ellerman

powerpc32: memcpy: only use dcbz once cache is enabled

memcpy() uses instruction dcbz to speed up copy by not wasting time
loading cache line with data that will be overwritten.
Some platform like mpc52xx do no have cache active at startup and
can therefore not use memcpy(). Allthough no part of the code
explicitly uses memcpy(), GCC makes calls to it.

This patch modifies memcpy() such that at startup, memcpy()
unconditionally jumps to generic_memcpy() which doesn't use
the dcbz instruction.

Once the initial MMU is set up, in machine_init() we patch memcpy()
by replacing this inconditional jump by a NOP
Reported-by: default avatarMichal Sojka <sojkam1@fel.cvut.cz>
Tested-by: default avatarThomas Gleixner <tglx@linutronix.de>
Signed-off-by: default avatarChristophe Leroy <christophe.leroy@c-s.fr>
Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
parent 36b35d5d
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
#include <asm/udbg.h> #include <asm/udbg.h>
#include <asm/mmu_context.h> #include <asm/mmu_context.h>
#include <asm/epapr_hcalls.h> #include <asm/epapr_hcalls.h>
#include <asm/code-patching.h>
#define DBG(fmt...) #define DBG(fmt...)
...@@ -116,6 +117,8 @@ notrace void __init machine_init(u64 dt_ptr) ...@@ -116,6 +117,8 @@ notrace void __init machine_init(u64 dt_ptr)
/* Enable early debugging if any specified (see udbg.h) */ /* Enable early debugging if any specified (see udbg.h) */
udbg_early_init(); udbg_early_init();
patch_instruction((unsigned int *)&memcpy, PPC_INST_NOP);
/* Do some early initialization based on the flat device tree */ /* Do some early initialization based on the flat device tree */
early_init_devtree(__va(dt_ptr)); early_init_devtree(__va(dt_ptr));
......
...@@ -128,6 +128,10 @@ _GLOBAL(memset) ...@@ -128,6 +128,10 @@ _GLOBAL(memset)
* the destination area is cacheable. * the destination area is cacheable.
* We only use this version if the source and dest don't overlap. * We only use this version if the source and dest don't overlap.
* -- paulus. * -- paulus.
*
* During early init, cache might not be active yet, so dcbz cannot be used.
* We therefore jump to generic_memcpy which doesn't use dcbz. This jump is
* replaced by a nop once cache is active. This is done in machine_init()
*/ */
_GLOBAL(memmove) _GLOBAL(memmove)
cmplw 0,r3,r4 cmplw 0,r3,r4
...@@ -135,6 +139,7 @@ _GLOBAL(memmove) ...@@ -135,6 +139,7 @@ _GLOBAL(memmove)
/* fall through */ /* fall through */
_GLOBAL(memcpy) _GLOBAL(memcpy)
b generic_memcpy
add r7,r3,r5 /* test if the src & dst overlap */ add r7,r3,r5 /* test if the src & dst overlap */
add r8,r4,r5 add r8,r4,r5
cmplw 0,r4,r7 cmplw 0,r4,r7
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment