Skip to content

Commit

Permalink
drivers: cache: Cache driver for NXP XCACHE controller
Browse files Browse the repository at this point in the history
Some NXP SoC's have External cache that is managed by
the XCACHE cache controller.

Signed-off-by: Mahesh Mahadevan <mahesh.mahadevan@nxp.com>
  • Loading branch information
mmahadevan108 committed Jan 14, 2025
1 parent 00ab7a9 commit e7db2fa
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 0 deletions.
1 change: 1 addition & 0 deletions drivers/cache/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ zephyr_library_sources_ifdef(CONFIG_CACHE_ASPEED cache_aspeed.c)
zephyr_library_sources_ifdef(CONFIG_CACHE_ANDES cache_andes.c)
zephyr_library_sources_ifdef(CONFIG_USERSPACE cache_handlers.c)
zephyr_library_sources_ifdef(CONFIG_CACHE_NRF_CACHE cache_nrf.c)
zephyr_library_sources_ifdef(CONFIG_CACHE_NXP_XCACHE cache_nxp_xcache.c)
1 change: 1 addition & 0 deletions drivers/cache/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ comment "Device Drivers"
source "drivers/cache/Kconfig.aspeed"
source "drivers/cache/Kconfig.nrf"
source "drivers/cache/Kconfig.andes"
source "drivers/cache/Kconfig.nxp_xcache"

endif # CACHE
10 changes: 10 additions & 0 deletions drivers/cache/Kconfig.nxp_xcache
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copyright 2025 NXP
# SPDX-License-Identifier: Apache-2.0

config CACHE_NXP_XCACHE
bool "NXP external cache driver for xcache controller"
default y
select CACHE_HAS_DRIVER
depends on HAS_MCUX_XCACHE
help
This option enables the XCACHE driver for NXP SOC's.
125 changes: 125 additions & 0 deletions drivers/cache/cache_nxp_xcache.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/*
* Copyright 2025 NXP
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <zephyr/kernel.h>
#include <zephyr/drivers/cache.h>
#include <zephyr/logging/log.h>
#include <soc.h>
#include <fsl_cache.h>

LOG_MODULE_REGISTER(cache_nxp_xcache, CONFIG_CACHE_LOG_LEVEL);

#if !defined(NXP_XCACHE_INSTR)
#define NXP_XCACHE_INSTR XCACHE_PC
#endif

#if !defined(NXP_XCACHE_DATA)
#define NXP_XCACHE_DATA XCACHE_PS
#endif

void cache_data_enable(void)
{
XCACHE_EnableCache(NXP_XCACHE_DATA);
}

void cache_data_disable(void)
{
XCACHE_DisableCache(NXP_XCACHE_DATA);
}

int cache_data_flush_all(void)
{
XCACHE_CleanCache(NXP_XCACHE_DATA);

return 0;
}

int cache_data_invd_all(void)
{
XCACHE_InvalidateCache(NXP_XCACHE_DATA);

return 0;
}

int cache_data_flush_and_invd_all(void)
{
XCACHE_CleanInvalidateCache(NXP_XCACHE_DATA);

return 0;
}

int cache_data_flush_range(void *addr, size_t size)
{
XCACHE_CleanCacheByRange((uint32_t)addr, size);

return 0;
}

int cache_data_invd_range(void *addr, size_t size)
{
XCACHE_InvalidateCacheByRange((uint32_t)addr, size);

return 0;
}

int cache_data_flush_and_invd_range(void *addr, size_t size)
{
XCACHE_CleanInvalidateCacheByRange((uint32_t)addr, size);

return 0;
}

void cache_instr_enable(void)
{
XCACHE_EnableCache(NXP_XCACHE_INSTR);
}

void cache_instr_disable(void)
{
XCACHE_DisableCache(NXP_XCACHE_INSTR);
}

int cache_instr_flush_all(void)
{
XCACHE_CleanCache(NXP_XCACHE_INSTR);

return 0;
}

int cache_instr_invd_all(void)
{
XCACHE_InvalidateCache(NXP_XCACHE_INSTR);

return 0;
}

int cache_instr_flush_and_invd_all(void)
{
XCACHE_CleanInvalidateCache(NXP_XCACHE_INSTR);

return 0;
}

int cache_instr_flush_range(void *addr, size_t size)
{
XCACHE_CleanCacheByRange((uint32_t)addr, size);

return 0;
}

int cache_instr_invd_range(void *addr, size_t size)
{
XCACHE_InvalidateCacheByRange((uint32_t)addr, size);

return 0;
}

int cache_instr_flush_and_invd_range(void *addr, size_t size)
{
XCACHE_CleanInvalidateCacheByRange((uint32_t)addr, size);

return 0;
}
5 changes: 5 additions & 0 deletions modules/Kconfig.mcux
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,11 @@ config HAS_MCUX_XBARA
help
Set if the XBARA module is present on the SoC.

config HAS_MCUX_XCACHE
bool
help
Set if the XCACHE module is present on the SoC.

config HAS_NXP_MONOLITHIC_NBU
bool
help
Expand Down

0 comments on commit e7db2fa

Please sign in to comment.