drivers: cache: nrf: Fix case when driver may hang

Driver was disabling cache before full range operations and that
was causing hanging on polling for cache busy status since
state was never changing (because cache was disabled).

Additionally, added flushing to data cache disabling. If flushing
is not performed then execution fails since data in cache is lost.

Signed-off-by: Krzysztof Chruściński <krzysztof.chruscinski@nordicsemi.no>
This commit is contained in:
Krzysztof Chruściński 2024-04-15 11:41:15 +02:00 committed by Johan Hedberg
parent 73d4f58b98
commit b83a11281d

View file

@ -68,14 +68,6 @@ static inline int _cache_all(NRF_CACHE_Type *cache, enum k_nrf_cache_op op)
return -ENOTSUP; 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); wait_for_cache(cache);
switch (op) { switch (op) {
@ -102,10 +94,6 @@ static inline int _cache_all(NRF_CACHE_Type *cache, enum k_nrf_cache_op op)
wait_for_cache(cache); wait_for_cache(cache);
nrf_cache_enable(cache);
k_spin_unlock(&lock, key);
return 0; return 0;
} }
@ -202,11 +190,6 @@ void cache_data_enable(void)
nrf_cache_enable(NRF_DCACHE); nrf_cache_enable(NRF_DCACHE);
} }
void cache_data_disable(void)
{
nrf_cache_disable(NRF_DCACHE);
}
int cache_data_flush_all(void) int cache_data_flush_all(void)
{ {
#if NRF_CACHE_HAS_TASK_CLEAN #if NRF_CACHE_HAS_TASK_CLEAN
@ -216,6 +199,14 @@ int cache_data_flush_all(void)
#endif #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) int cache_data_invd_all(void)
{ {
return _cache_checks(NRF_DCACHE, K_NRF_CACHE_INVD, NULL, 0, false); return _cache_checks(NRF_DCACHE, K_NRF_CACHE_INVD, NULL, 0, false);