Skip to content

Commit

Permalink
l2cc: Do not repeat disabling the cache when the cache is already dis…
Browse files Browse the repository at this point in the history
…abled

When l2cc is already in disable state, performing a disable operation
again will flush incorrect cache data to memory

Signed-off-by: zhangyuan21 <zhangyuan21@xiaomi.com>
  • Loading branch information
zyfeier committed Apr 19, 2023
1 parent 0747ee1 commit 71e9932
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
15 changes: 6 additions & 9 deletions arch/arm/src/armv7-a/arm_l2cc_pl310.c
Expand Up @@ -437,6 +437,12 @@ void l2cc_enable(void)
/* Invalidate and enable the cache (must be disabled to do this!) */

flags = enter_critical_section();

if ((getreg32(L2CC_CR) & L2CC_CR_L2CEN) != 0)
{
l2cc_disable();
}

l2cc_invalidate_all();
putreg32(L2CC_CR_L2CEN, L2CC_CR);
ARM_DSB();
Expand Down Expand Up @@ -520,17 +526,11 @@ void l2cc_sync(void)
void l2cc_invalidate_all(void)
{
irqstate_t flags;
uint32_t regval;

/* Invalidate all ways */

flags = enter_critical_section();

/* Disable the L2 cache while we invalidate it */

regval = getreg32(L2CC_CR);
l2cc_disable();

/* Invalidate all ways by writing the bit mask of ways to be invalidated
* the Invalidate Way Register (IWR).
*/
Expand All @@ -547,9 +547,6 @@ void l2cc_invalidate_all(void)

putreg32(0, L2CC_CSR);

/* Then re-enable the L2 cache if it was enabled before */

putreg32(regval, L2CC_CR);
leave_critical_section(flags);
}

Expand Down
15 changes: 6 additions & 9 deletions arch/arm/src/armv7-r/arm_l2cc_pl310.c
Expand Up @@ -437,6 +437,12 @@ void l2cc_enable(void)
/* Invalidate and enable the cache (must be disabled to do this!) */

flags = enter_critical_section();

if ((getreg32(L2CC_CR) & L2CC_CR_L2CEN) != 0)
{
l2cc_disable();
}

l2cc_invalidate_all();
putreg32(L2CC_CR_L2CEN, L2CC_CR);
ARM_DSB();
Expand Down Expand Up @@ -520,17 +526,11 @@ void l2cc_sync(void)
void l2cc_invalidate_all(void)
{
irqstate_t flags;
uint32_t regval;

/* Invalidate all ways */

flags = enter_critical_section();

/* Disable the L2 cache while we invalidate it */

regval = getreg32(L2CC_CR);
l2cc_disable();

/* Invalidate all ways by writing the bit mask of ways to be invalidated
* the Invalidate Way Register (IWR).
*/
Expand All @@ -547,9 +547,6 @@ void l2cc_invalidate_all(void)

putreg32(0, L2CC_CSR);

/* Then re-enable the L2 cache if it was enabled before */

putreg32(regval, L2CC_CR);
leave_critical_section(flags);
}

Expand Down

0 comments on commit 71e9932

Please sign in to comment.