cache: do cache_invalidate_all before enable dcache

Signed-off-by: ligd <liguiding1@xiaomi.com>
This commit is contained in:
ligd 2024-08-08 22:20:01 +08:00 committed by Xiang Xiao
parent e8467a9bd5
commit ba3a55b445
11 changed files with 133 additions and 6 deletions

View file

@ -432,6 +432,15 @@ void up_flush_dcache_all(void)
void up_enable_dcache(void)
{
/* Check if the D-Cache is enabled */
if (cp15_dcache_is_enabled())
{
return;
}
up_invalidate_dcache_all();
cp15_enable_dcache();
l2cc_enable();
}

View file

@ -551,6 +551,25 @@
#ifndef __ASSEMBLY__
/****************************************************************************
* Name: cp15_dcache_is_enabled
*
* Description:
* Check if L1 D Cache is enabled
*
* Input Parameters:
* None
*
* Returned Value:
* true if L1 D Cache is enabled, false otherwise
*
****************************************************************************/
static inline int cp15_dcache_is_enabled(void)
{
return (CP15_GET(SCTLR) & SCTLR_C) != 0;
}
/****************************************************************************
* Name: cp15_enable_dcache
*
@ -1107,7 +1126,7 @@ void cp15_flush_dcache_all(void);
uint32_t cp15_icache_size(void);
/****************************************************************************
* Name: cp15_cache_size
* Name: cp15_dcache_size
*
* Description:
* Get cp15 dcache size in byte

View file

@ -496,12 +496,12 @@ void up_enable_dcache(void)
uint32_t sets;
uint32_t ways;
/* If dcache is already enabled, disable it first. */
/* If dcache is already enabled, return. */
ccr = getreg32(NVIC_CFGCON);
if ((ccr & NVIC_CFGCON_DC) != 0)
{
up_disable_dcache();
return;
}
/* Get the characteristics of the D-Cache */

View file

@ -432,6 +432,15 @@ void up_flush_dcache_all(void)
void up_enable_dcache(void)
{
/* Check if the D-Cache is enabled */
if (cp15_dcache_is_enabled())
{
return;
}
up_invalidate_dcache_all();
cp15_enable_dcache();
l2cc_enable();
}

View file

@ -558,6 +558,25 @@
#ifndef __ASSEMBLY__
/****************************************************************************
* Name: cp15_dcache_is_enabled
*
* Description:
* Check if L1 D Cache is enabled
*
* Input Parameters:
* None
*
* Returned Value:
* true if L1 D Cache is enabled, false otherwise
*
****************************************************************************/
static inline int cp15_dcache_is_enabled(void)
{
return (CP15_GET(SCTLR) & SCTLR_C) != 0;
}
/****************************************************************************
* Name: cp15_enable_dcache
*
@ -1114,7 +1133,7 @@ void cp15_flush_dcache_all(void);
uint32_t cp15_icache_size(void);
/****************************************************************************
* Name: cp15_cache_size
* Name: cp15_dcache_size
*
* Description:
* Get cp15 dcache size in byte

View file

@ -496,12 +496,12 @@ void up_enable_dcache(void)
uint32_t sets;
uint32_t ways;
/* If dcache is already enabled, disable it first. */
/* If dcache is already enabled, return. */
ccr = getreg32(NVIC_CFGCON);
if ((ccr & NVIC_CFGCON_DC) != 0)
{
up_disable_dcache();
return;
}
/* Get the characteristics of the D-Cache */

View file

@ -436,6 +436,15 @@ void up_flush_dcache_all(void)
void up_enable_dcache(void)
{
/* Check if the D-Cache is enabled */
if (cp15_dcache_is_enabled())
{
return;
}
up_invalidate_dcache_all();
cp15_enable_dcache();
l2cc_enable();
}

View file

@ -558,6 +558,25 @@
#ifndef __ASSEMBLY__
/****************************************************************************
* Name: cp15_dcache_is_enabled
*
* Description:
* Check if L1 D Cache is enabled
*
* Input Parameters:
* None
*
* Returned Value:
* true if L1 D Cache is enabled, false otherwise
*
****************************************************************************/
static inline int cp15_dcache_is_enabled(void)
{
return (CP15_GET(SCTLR) & SCTLR_C) != 0;
}
/****************************************************************************
* Name: cp15_enable_dcache
*

View file

@ -519,6 +519,17 @@ void up_clean_dcache_all(void)
void up_enable_dcache(void)
{
uint64_t value = read_sysreg(sctlr_el1);
/* Check if the D-Cache is enabled */
if ((value & SCTLR_C_BIT) != 0)
{
return;
}
up_invalidate_dcache_all();
value = read_sysreg(sctlr_el1);
write_sysreg((value | SCTLR_C_BIT), sctlr_el1);
ARM64_ISB();
}

View file

@ -116,6 +116,21 @@ static size_t x86_64_cache_size(int leaf)
(ecx + 1));
}
/****************************************************************************
* Name: x86_64_is_cache_enabled
****************************************************************************/
static int x86_64_is_cache_enabled(void)
{
unsigned long cr0;
asm volatile("\t mov %%cr0, %0\n"
: "=r" (cr0)
:: "memory");
return (cr0 & 0x60000000) == 0;
}
/****************************************************************************
* Name: x86_64_cache_enable
****************************************************************************/
@ -358,6 +373,14 @@ size_t up_get_dcache_size(void)
#ifdef CONFIG_ARCH_DCACHE
void up_enable_dcache(void)
{
/* Check if the D-Cache is enabled */
if (x86_64_is_cache_enabled())
{
return;
}
up_invalidate_dcache_all();
x86_64_cache_enable();
}
#endif /* CONFIG_ARCH_DCACHE */

View file

@ -346,6 +346,15 @@ void up_enable_dcache(void)
__asm__ __volatile__ ("rsr %0, memctl\n" : "=r"(memctl) :);
/* Check if the D-Cache is enabled */
if ((memctl & MEMCTL_INV_EN) != 0)
{
return;
}
up_invalidate_dcache_all();
/* set ways allocatable & ways use */
memctl = memctl & ~(MEMCTL_DCWA_MASK | MEMCTL_DCWU_MASK);