Skip to content

Commit

Permalink
[arch][ops] define some global ARCH macros to be a bit more scoped
Browse files Browse the repository at this point in the history
Instead of ICACHE/DCACHE/UCACHE, add the ARCH_CACHE_FLAG_ prefix to be a
little cleaner and not collide with anything else.

No functional change.
  • Loading branch information
travisg committed May 10, 2024
1 parent 6a3db09 commit d3cd5be
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 29 deletions.
4 changes: 2 additions & 2 deletions arch/arm/arm-m/arch.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ void arch_early_init(void) {
#endif

#if ARM_WITH_CACHE
arch_enable_cache(UCACHE);
arch_enable_cache(ARCH_CACHE_FLAG_UCACHE);
#endif
}

Expand All @@ -111,7 +111,7 @@ void arch_init(void) {

void arch_quiesce(void) {
#if ARM_WITH_CACHE
arch_disable_cache(UCACHE);
arch_disable_cache(ARCH_CACHE_FLAG_UCACHE);
#endif
}

Expand Down
8 changes: 4 additions & 4 deletions arch/arm/arm-m/cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@
/* cache flushing routines for cortex-m cores that support it */

void arch_disable_cache(uint flags) {
if (flags & DCACHE)
if (flags & ARCH_CACHE_FLAG_DCACHE)
SCB_DisableDCache();

if (flags & ICACHE)
if (flags & ARCH_CACHE_FLAG_ICACHE)
SCB_DisableICache();
}

void arch_enable_cache(uint flags) {
if (flags & DCACHE)
if (flags & ARCH_CACHE_FLAG_DCACHE)
SCB_EnableDCache();

if (flags & ICACHE)
if (flags & ARCH_CACHE_FLAG_ICACHE)
SCB_EnableICache();
}

Expand Down
8 changes: 4 additions & 4 deletions arch/arm/arm/arch.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ volatile int secondaries_to_init = 0;

void arch_early_init(void) {
/* turn off the cache */
arch_disable_cache(UCACHE);
arch_disable_cache(ARCH_CACHE_FLAG_UCACHE);
#if WITH_DEV_CACHE_PL310
pl310_set_enable(false);
#endif
Expand All @@ -80,7 +80,7 @@ void arch_early_init(void) {
#if WITH_DEV_CACHE_PL310
pl310_set_enable(true);
#endif
arch_enable_cache(UCACHE);
arch_enable_cache(ARCH_CACHE_FLAG_UCACHE);
}

void arch_init(void) {
Expand Down Expand Up @@ -155,7 +155,7 @@ void arm_secondary_entry(uint asm_cpu_num) {
arm_basic_setup();

/* enable the local L1 cache */
//arch_enable_cache(UCACHE);
//arch_enable_cache(ARCH_CACHE_FLAG_UCACHE);

// XXX may not be safe, but just hard enable i and d cache here
// at the moment cannot rely on arch_enable_cache not dumping the L2
Expand Down Expand Up @@ -365,7 +365,7 @@ void arch_chain_load(void *entry, ulong arg0, ulong arg1, ulong arg2, ulong arg3
#endif

LTRACEF("disabling instruction/data cache\n");
arch_disable_cache(UCACHE);
arch_disable_cache(ARCH_CACHE_FLAG_UCACHE);
#if WITH_DEV_CACHE_PL310
pl310_set_enable(false);
#endif
Expand Down
16 changes: 8 additions & 8 deletions arch/arm/arm/cache-ops.S
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ FUNCTION(arch_disable_cache)
cpsid iaf // interrupts disabled

.Ldcache_disable:
tst r0, #DCACHE
tst r0, #ARCH_CACHE_FLAG_DCACHE
beq .Licache_disable
mrc p15, 0, r1, c1, c0, 0 // cr1
tst r1, #(1<<2) // is the dcache already disabled?
Expand All @@ -37,7 +37,7 @@ FUNCTION(arch_disable_cache)
mcr p15, 0, r0, c7, c10, 4 // data sync barrier (formerly drain write buffer)

.Licache_disable:
tst r0, #ICACHE
tst r0, #ARCH_CACHE_FLAG_ICACHE
beq .Ldone_disable

mrc p15, 0, r1, c1, c0, 0 // cr1
Expand All @@ -57,7 +57,7 @@ FUNCTION(arch_enable_cache)
cpsid iaf // interrupts disabled

.Ldcache_enable:
tst r0, #DCACHE
tst r0, #ARCH_CACHE_FLAG_DCACHE
beq .Licache_enable
mrc p15, 0, r1, c1, c0, 0 // cr1
tst r1, #(1<<2) // is the dcache already enabled?
Expand All @@ -69,7 +69,7 @@ FUNCTION(arch_enable_cache)
mcr p15, 0, r1, c1, c0, 0 // enable dcache

.Licache_enable:
tst r0, #ICACHE
tst r0, #ARCH_CACHE_FLAG_ICACHE
beq .Ldone_enable

mcr p15, 0, r12, c7, c5, 0 // invalidate icache
Expand All @@ -94,7 +94,7 @@ FUNCTION(arch_disable_cache)
cpsid iaf // interrupts disabled

.Ldcache_disable:
tst r7, #DCACHE
tst r7, #ARCH_CACHE_FLAG_DCACHE
beq .Licache_disable
mrc p15, 0, r0, c1, c0, 0 // cr1
tst r0, #(1<<2) // is the dcache already disabled?
Expand Down Expand Up @@ -124,7 +124,7 @@ FUNCTION(arch_disable_cache)
#endif

.Licache_disable:
tst r7, #ICACHE
tst r7, #ARCH_CACHE_FLAG_ICACHE
beq .Ldone_disable

mrc p15, 0, r0, c1, c0, 0 // cr1
Expand All @@ -149,7 +149,7 @@ FUNCTION(arch_enable_cache)
cpsid iaf // interrupts disabled

.Ldcache_enable:
tst r7, #DCACHE
tst r7, #ARCH_CACHE_FLAG_DCACHE
beq .Licache_enable
mrc p15, 0, r0, c1, c0, 0 // cr1
tst r0, #(1<<2) // is the dcache already enabled?
Expand All @@ -171,7 +171,7 @@ FUNCTION(arch_enable_cache)
mcr p15, 0, r0, c1, c0, 0 // enable dcache

.Licache_enable:
tst r7, #ICACHE
tst r7, #ARCH_CACHE_FLAG_ICACHE
beq .Ldone_enable

mov r0, #0
Expand Down
11 changes: 5 additions & 6 deletions arch/include/arch/ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,6 @@ static uint arch_curr_cpu_num(void);
/* Use to align structures on cache lines to avoid cpu aliasing. */
#define __CPU_ALIGN __ALIGNED(CACHE_LINE)

#endif // !ASSEMBLY
#define ICACHE 1
#define DCACHE 2
#define UCACHE (ICACHE|DCACHE)
#ifndef ASSEMBLY

void arch_disable_cache(uint flags);
void arch_enable_cache(uint flags);

Expand All @@ -49,5 +43,10 @@ __END_CDECLS

#endif // !ASSEMBLY

/* for the above arch enable/disable routines */
#define ARCH_CACHE_FLAG_ICACHE 1
#define ARCH_CACHE_FLAG_DCACHE 2
#define ARCH_CACHE_FLAG_UCACHE (ARCH_CACHE_FLAG_ICACHE|ARCH_CACHE_FLAG_DCACHE)

#include <arch/arch_ops.h>

8 changes: 4 additions & 4 deletions arch/or1k/cache-ops.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ void arch_invalidate_cache_all(void) {
void arch_disable_cache(uint flags) {
uint32_t sr = mfspr(OR1K_SPR_SYS_SR_ADDR);

if (flags & ICACHE)
if (flags & ARCH_CACHE_FLAG_ICACHE)
sr &= ~OR1K_SPR_SYS_SR_ICE_MASK;
if (flags & DCACHE)
if (flags & ARCH_CACHE_FLAG_DCACHE)
sr &= ~OR1K_SPR_SYS_SR_DCE_MASK;

mtspr(OR1K_SPR_SYS_SR_ADDR, sr);
Expand All @@ -63,9 +63,9 @@ void arch_disable_cache(uint flags) {
void arch_enable_cache(uint flags) {
uint32_t sr = mfspr(OR1K_SPR_SYS_SR_ADDR);

if (flags & ICACHE)
if (flags & ARCH_CACHE_FLAG_ICACHE)
sr |= OR1K_SPR_SYS_SR_ICE_MASK;
if (flags & DCACHE)
if (flags & ARCH_CACHE_FLAG_DCACHE)
sr |= OR1K_SPR_SYS_SR_DCE_MASK;

mtspr(OR1K_SPR_SYS_SR_ADDR, sr);
Expand Down
2 changes: 1 addition & 1 deletion arch/or1k/start.S
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ FUNCTION(start)
l.jal arch_invalidate_cache_all
l.nop
l.jal arch_enable_cache
l.ori r3, r0, UCACHE
l.ori r3, r0, ARCH_CACHE_FLAG_UCACHE

/* clear bss */
l.movhi r3, hi(__bss_start)
Expand Down

0 comments on commit d3cd5be

Please sign in to comment.