Skip to content

Commit

Permalink
zephyr: include: rtos: Switch to using Zephyr cache management API
Browse files Browse the repository at this point in the history
Thanks to PR [1], Zephyr cache management API can now be
used on xtensa-based SoCs. As a consequence to this, there's
no longer a need to use SOF's arch/ layer for cache management.
This commit forces all SoCs which support Zephyr to use
its native cache management API.

[1]: zephyrproject-rtos/zephyr#50136

Signed-off-by: Laurentiu Mihalcea <laurentiu.mihalcea@nxp.com>
  • Loading branch information
LaurentiuM1234 committed May 8, 2023
1 parent 54c65b9 commit 1d779d2
Showing 1 changed file with 49 additions and 2 deletions.
51 changes: 49 additions & 2 deletions zephyr/include/rtos/cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,61 @@
#ifndef __ZEPHYR_RTOS_CACHE_H__
#define __ZEPHYR_RTOS_CACHE_H__

/* TODO: align with Zephyr generic cache API when ready */
#define __SOF_LIB_CACHE_H__
#include <arch/lib/cache.h>

#include <zephyr/cache.h>

#if defined(CONFIG_XTENSA) && defined(CONFIG_INTEL)
#define SRAM_UNCACHED_ALIAS 0x20000000
#define is_cached(ptr) ((ptr) == arch_xtensa_cached_ptr(ptr))
#endif

/* writeback and invalidate data */
#define CACHE_WRITEBACK_INV 0

/* invalidate data */
#define CACHE_INVALIDATE 1

#if !defined(CONFIG_DCACHE_LINE_SIZE_DETECT) && \
(CONFIG_DCACHE_LINE_SIZE > 0)

#define DCACHE_LINE_SIZE CONFIG_DCACHE_LINE_SIZE

#else

/* If CONFIG_DCACHE_LINE_SIZE is not set appropriately then
* fallback to a default value. This ought to be alright
* since all platforms that support Zephyr use this value.
* This is better than forcing all vendors to set
* CONFIG_DCACHE_LINE_SIZE in order to avoid compilation
* errors.
*/
#define DCACHE_LINE_SIZE 128

#endif

static inline void dcache_writeback_region(void *addr, size_t size)
{
/* TODO: return value should probably be checked here */
sys_cache_data_flush_range(addr, size);
}

static inline void dcache_invalidate_region(void *addr, size_t size)
{
/* TODO: return value should probably be checked here */
sys_cache_data_invd_range(addr, size);
}

static inline void icache_invalidate_region(void *addr, size_t size)
{
/* TODO: return value should probably be checked here */
sys_cache_instr_invd_range(addr, size);
}

static inline void dcache_writeback_invalidate_region(void *addr, size_t size)
{
/* TODO: return value should probably be checked here */
sys_cache_data_flush_and_invd_range(addr, size);
}

#endif /* __ZEPHYR_RTOS_CACHE_H__ */

0 comments on commit 1d779d2

Please sign in to comment.