Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

soc: nordic: nrf54h: Remove redundant ICACHE Kconfig and add enabling DCACHE #1624

Merged
merged 7 commits into from
May 10, 2024
6 changes: 6 additions & 0 deletions drivers/cache/Kconfig.nrf
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,9 @@ config CACHE_NRF_CACHE
depends on HAS_NRFX && CACHE_MANAGEMENT
help
Enable support for the nRF cache driver.

config CACHE_NRF_PATCH_LINEADDR
bool "Patch lineaddr"
default y if SOC_NRF54H20
help
Manually set 28th bit in the LINEADDR in Trustzone Secure build.
86 changes: 40 additions & 46 deletions drivers/cache/cache_nrf.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ LOG_MODULE_REGISTER(cache_nrfx, CONFIG_CACHE_LOG_LEVEL);
#define NRF_ICACHE NRF_CACHE
#endif

#define CACHE_LINE_SIZE 32
#define CACHE_BUSY_RETRY_INTERVAL_US 10

static struct k_spinlock lock;

enum k_nrf_cache_op {
/*
Expand Down Expand Up @@ -55,7 +53,6 @@ static inline bool is_cache_busy(NRF_CACHE_Type *cache)
static inline void wait_for_cache(NRF_CACHE_Type *cache)
{
while (is_cache_busy(cache)) {
k_busy_wait(CACHE_BUSY_RETRY_INTERVAL_US);
}
}

Expand All @@ -68,14 +65,6 @@ static inline int _cache_all(NRF_CACHE_Type *cache, enum k_nrf_cache_op op)
return -ENOTSUP;
}

k_spinlock_key_t key = k_spin_lock(&lock);

/*
* Invalidating the whole cache is dangerous. For good measure
* disable the cache.
*/
nrf_cache_disable(cache);

wait_for_cache(cache);

switch (op) {
Expand All @@ -102,66 +91,68 @@ static inline int _cache_all(NRF_CACHE_Type *cache, enum k_nrf_cache_op op)

wait_for_cache(cache);

nrf_cache_enable(cache);

k_spin_unlock(&lock, key);

return 0;
}

static inline void _cache_line(NRF_CACHE_Type *cache, enum k_nrf_cache_op op, uintptr_t line_addr)
{
wait_for_cache(cache);
do {
wait_for_cache(cache);

nrf_cache_lineaddr_set(cache, line_addr);
nrf_cache_lineaddr_set(cache, line_addr);

switch (op) {
switch (op) {

#if NRF_CACHE_HAS_TASK_CLEAN
case K_NRF_CACHE_CLEAN:
nrf_cache_task_trigger(cache, NRF_CACHE_TASK_CLEANLINE);
break;
case K_NRF_CACHE_CLEAN:
nrf_cache_task_trigger(cache, NRF_CACHE_TASK_CLEANLINE);
break;
#endif

case K_NRF_CACHE_INVD:
nrf_cache_task_trigger(cache, NRF_CACHE_TASK_INVALIDATELINE);
break;
case K_NRF_CACHE_INVD:
nrf_cache_task_trigger(cache, NRF_CACHE_TASK_INVALIDATELINE);
break;

#if NRF_CACHE_HAS_TASK_FLUSH
case K_NRF_CACHE_FLUSH:
nrf_cache_task_trigger(cache, NRF_CACHE_TASK_FLUSHLINE);
break;
case K_NRF_CACHE_FLUSH:
nrf_cache_task_trigger(cache, NRF_CACHE_TASK_FLUSHLINE);
break;
#endif

default:
break;
}

wait_for_cache(cache);
default:
break;
}
} while (nrf_cache_lineaddr_get(cache) != line_addr);
}

static inline int _cache_range(NRF_CACHE_Type *cache, enum k_nrf_cache_op op, void *addr,
size_t size)
{
uintptr_t line_addr = (uintptr_t)addr;
uintptr_t end_addr = line_addr + size;
uintptr_t end_addr;

/* Some SOCs has a bug that requires to set 28th bit in the address on
* Trustzone secure builds.
*/
if (IS_ENABLED(CONFIG_CACHE_NRF_PATCH_LINEADDR) &&
!IS_ENABLED(CONFIG_TRUSTED_EXECUTION_NONSECURE)) {
line_addr |= BIT(28);
}

end_addr = line_addr + size;

/*
* Align address to line size
*/
line_addr &= ~(CACHE_LINE_SIZE - 1);
line_addr &= ~(CONFIG_DCACHE_LINE_SIZE - 1);

do {
k_spinlock_key_t key = k_spin_lock(&lock);

_cache_line(cache, op, line_addr);

k_spin_unlock(&lock, key);

line_addr += CACHE_LINE_SIZE;

line_addr += CONFIG_DCACHE_LINE_SIZE;
} while (line_addr < end_addr);

wait_for_cache(cache);

return 0;
}

Expand Down Expand Up @@ -192,11 +183,6 @@ void cache_data_enable(void)
nrf_cache_enable(NRF_DCACHE);
}

void cache_data_disable(void)
{
nrf_cache_disable(NRF_DCACHE);
}

int cache_data_flush_all(void)
{
#if NRF_CACHE_HAS_TASK_CLEAN
Expand All @@ -206,6 +192,14 @@ int cache_data_flush_all(void)
#endif
}

void cache_data_disable(void)
{
if (nrf_cache_enable_check(NRF_DCACHE)) {
(void)cache_data_flush_all();
}
nrf_cache_disable(NRF_DCACHE);
}

int cache_data_invd_all(void)
{
return _cache_checks(NRF_DCACHE, K_NRF_CACHE_INVD, NULL, 0, false);
Expand Down
8 changes: 0 additions & 8 deletions soc/nordic/nrf54h/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,3 @@ config SOC_NRF54H20_CPURAD

config SOC_NRF54H20_CPUPPR
depends on RISCV_CORE_NORDIC_VPR

if SOC_NRF54H20

config NRF_ENABLE_ICACHE
bool "Instruction cache (I-Cache)"
default y

endif # SOC_NRF54H20
3 changes: 1 addition & 2 deletions soc/nordic/nrf54h/soc.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,8 @@ static int trim_hsfll(void)

static int nordicsemi_nrf54h_init(void)
{
#if defined(CONFIG_NRF_ENABLE_ICACHE)
sys_cache_instr_enable();
#endif
sys_cache_data_enable();

power_domain_init();

Expand Down
2 changes: 1 addition & 1 deletion west.yml
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ manifest:
groups:
- hal
- name: hal_nordic
revision: f8e4d73a78316ea9ef85f09f24a3a229e40c1a80
revision: bdef8b66d5f59d95c09889918a04ddaecce322c8
path: modules/hal/nordic
groups:
- hal
Expand Down
Loading