Skip to content

Commit

Permalink
use small lock to protect register, involving the following files:
Browse files Browse the repository at this point in the history
arch/arm/src/armv7-a/arm_l2cc_pl310.c
arch/arm/src/armv7-r/arm_l2cc_pl310.c
arch/arm/src/armv8-r/arm_l2cc_pl310.c
arch/arm/src/common/arm_initialize.c
arch/arm/src/common/arm_internal.h

Signed-off-by: wangzhi16 <[email protected]>
  • Loading branch information
wangzhi-art committed Jan 6, 2025
1 parent 3e66498 commit 2088ab3
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 78 deletions.
52 changes: 26 additions & 26 deletions arch/arm/src/armv7-a/arm_l2cc_pl310.c
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ void l2cc_enable(void)

/* Invalidate and enable the cache (must be disabled to do this!) */

flags = enter_critical_section();
flags = spin_lock_irqsave(&g_reg32_lock);

if ((getreg32(L2CC_CR) & L2CC_CR_L2CEN) != 0)
{
Expand All @@ -468,7 +468,7 @@ void l2cc_enable(void)
putreg32(L2CC_CR_L2CEN, L2CC_CR);
ARM_DSB();
ARM_ISB();
leave_critical_section(flags);
spin_unlock_irqrestore(&g_reg32_lock, flags);
}

/****************************************************************************
Expand All @@ -491,15 +491,15 @@ void l2cc_disable(void)

/* Flush all ways using the Clean Invalidate Way Register (CIWR). */

flags = enter_critical_section();
flags = spin_lock_irqsave(&g_reg32_lock);
pl310_flush_all();

/* Disable the L2CC-P310 L2 cache by clearing the Control Register (CR) */

putreg32(0, L2CC_CR);
ARM_DSB();
ARM_ISB();
leave_critical_section(flags);
spin_unlock_irqrestore(&g_reg32_lock, flags);
}

/****************************************************************************
Expand All @@ -525,9 +525,9 @@ void l2cc_sync(void)
* EB, are empty.
*/

flags = enter_critical_section();
flags = spin_lock_irqsave(&g_reg32_lock);
putreg32(0, L2CC_CSR);
leave_critical_section(flags);
spin_unlock_irqrestore(&g_reg32_lock, flags);
}

/****************************************************************************
Expand All @@ -550,7 +550,7 @@ void l2cc_invalidate_all(void)

/* Invalidate all ways */

flags = enter_critical_section();
flags = spin_lock_irqsave(&g_reg32_lock);

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

putreg32(0, L2CC_CSR);

leave_critical_section(flags);
spin_unlock_irqrestore(&g_reg32_lock, flags);
}

/****************************************************************************
Expand All @@ -595,7 +595,7 @@ void l2cc_invalidate(uintptr_t startaddr, uintptr_t endaddr)

/* Check if the start address is aligned with a cacheline */

flags = enter_critical_section();
flags = spin_lock_irqsave(&g_reg32_lock);
if ((startaddr & PL310_CACHE_LINE_MASK) != 0)
{
/* No.. align down and flush the cache line by writing the address to
Expand All @@ -622,7 +622,7 @@ void l2cc_invalidate(uintptr_t startaddr, uintptr_t endaddr)
putreg32(endaddr, L2CC_CIPALR);
}

leave_critical_section(flags);
spin_unlock_irqrestore(&g_reg32_lock, flags);

/* Loop, invalidated the address range by cache line. Interrupts are re-
* enabled momentarily every PL310_GULP_SIZE bytes.
Expand All @@ -640,7 +640,7 @@ void l2cc_invalidate(uintptr_t startaddr, uintptr_t endaddr)

/* Disable interrupts and invalidate the gulp */

flags = enter_critical_section();
flags = spin_lock_irqsave(&g_reg32_lock);
while (startaddr < gulpend)
{
/* Invalidate the cache line by writing the address to the
Expand All @@ -656,16 +656,16 @@ void l2cc_invalidate(uintptr_t startaddr, uintptr_t endaddr)

/* Enable interrupts momentarily */

leave_critical_section(flags);
spin_unlock_irqrestore(&g_reg32_lock, flags);
}

/* Drain the STB. Operation complete when all buffers, LRB, LFB, STB, and
* EB, are empty.
*/

flags = enter_critical_section();
flags = spin_lock_irqsave(&g_reg32_lock);
putreg32(0, L2CC_CSR);
leave_critical_section(flags);
spin_unlock_irqrestore(&g_reg32_lock, flags);
}

/****************************************************************************
Expand All @@ -690,7 +690,7 @@ void l2cc_clean_all(void)
* Ways Register (CWR).
*/

flags = enter_critical_section();
flags = spin_lock_irqsave(&g_reg32_lock);
putreg32(PL310_WAY_MASK, L2CC_CWR);

/* Wait for cache operation by way to complete */
Expand All @@ -702,7 +702,7 @@ void l2cc_clean_all(void)
*/

putreg32(0, L2CC_CSR);
leave_critical_section(flags);
spin_unlock_irqrestore(&g_reg32_lock, flags);
}

/****************************************************************************
Expand Down Expand Up @@ -758,7 +758,7 @@ void l2cc_clean(uintptr_t startaddr, uintptr_t endaddr)

/* Disable interrupts and clean the gulp */

flags = enter_critical_section();
flags = spin_lock_irqsave(&g_reg32_lock);
while (startaddr < gulpend)
{
/* Clean the cache line by writing the address to the Clean
Expand All @@ -774,16 +774,16 @@ void l2cc_clean(uintptr_t startaddr, uintptr_t endaddr)

/* Enable interrupts momentarily */

leave_critical_section(flags);
spin_unlock_irqrestore(&g_reg32_lock, flags);
}

/* Drain the STB. Operation complete when all buffers, LRB, LFB, STB, and
* EB, are empty.
*/

flags = enter_critical_section();
flags = spin_lock_irqsave(&g_reg32_lock);
putreg32(0, L2CC_CSR);
leave_critical_section(flags);
spin_unlock_irqrestore(&g_reg32_lock, flags);
}

/****************************************************************************
Expand All @@ -806,9 +806,9 @@ void l2cc_flush_all(void)

/* Flush all ways using the Clean Invalidate Way Register (CIWR). */

flags = enter_critical_section();
flags = spin_lock_irqsave(&g_reg32_lock);
pl310_flush_all();
leave_critical_section(flags);
spin_unlock_irqrestore(&g_reg32_lock, flags);
}

/****************************************************************************
Expand Down Expand Up @@ -864,7 +864,7 @@ void l2cc_flush(uint32_t startaddr, uint32_t endaddr)

/* Disable interrupts and flush the gulp */

flags = enter_critical_section();
flags = spin_lock_irqsave(&g_reg32_lock);
while (startaddr < gulpend)
{
/* Flush the cache line by writing the address to the Clean
Expand All @@ -880,16 +880,16 @@ void l2cc_flush(uint32_t startaddr, uint32_t endaddr)

/* Enable interrupts momentarily */

leave_critical_section(flags);
spin_unlock_irqrestore(&g_reg32_lock, flags);
}

/* Drain the STB. Operation complete when all buffers, LRB, LFB, STB, and
* EB, are empty.
*/

flags = enter_critical_section();
flags = spin_lock_irqsave(&g_reg32_lock);
putreg32(0, L2CC_CSR);
leave_critical_section(flags);
spin_unlock_irqrestore(&g_reg32_lock, flags);
}

#endif /* CONFIG_ARMV7A_L2CC_PL310 */
Loading

0 comments on commit 2088ab3

Please sign in to comment.