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

drivers: cache: Cache driver for NXP XCACHE controller #83827

Merged
merged 3 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
10 changes: 2 additions & 8 deletions soc/nxp/imxrt/imxrt118x/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ config SOC_SERIES_IMXRT118X

config SOC_MIMXRT1189_CM33
select CPU_CORTEX_M33
select HAS_MCUX_XCACHE
select CACHE_MANAGEMENT
mmahadevan108 marked this conversation as resolved.
Show resolved Hide resolved

config SOC_MIMXRT1189_CM7
select CPU_CORTEX_M7
Expand Down Expand Up @@ -66,12 +68,4 @@ config S3MU_MCUX_S3MU
default y
bool "Use S3MU MCUX Driver"

config IMXRT118X_CM33_XCACHE_PS
bool "Use CM33 XCACHE_PS"
default y if SOC_MIMXRT1189_CM33
help
Use CM33 XCACHE_PS at boot. Please note XCACHE_PC have been
enabled in SystemInit function. If this Kconfig is cleared,
the XCACHE controller won't be enabled during SOC init

endif # SOC_SERIES_IMXRT118X
4 changes: 4 additions & 0 deletions soc/nxp/imxrt/imxrt118x/Kconfig.defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,8 @@ config NXP_IMXRT_BOOT_HEADER

endif # SECOND_CORE_MCUX

choice CACHE_TYPE
default EXTERNAL_CACHE if SOC_MIMXRT1189_CM33
endchoice

endif # SOC_SERIES_IMXRT118X
11 changes: 1 addition & 10 deletions soc/nxp/imxrt/imxrt118x/soc.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@
#include <soc.h>
#include <zephyr/linker/sections.h>
#include <zephyr/linker/linker-defs.h>
#if defined(CONFIG_SOC_MIMXRT1189_CM7)
#include <zephyr/cache.h>
#elif defined(CONFIG_IMXRT118X_CM33_XCACHE_PS)
#include <fsl_cache.h>
#endif
#include <fsl_clock.h>
#include <fsl_gpc.h>
#include <fsl_pmu.h>
Expand Down Expand Up @@ -631,13 +627,8 @@ void soc_early_init_hook(void)
trdc_enable_all_access();

/* Enable data cache */
mmahadevan108 marked this conversation as resolved.
Show resolved Hide resolved
#if defined(CONFIG_IMXRT118X_CM33_XCACHE_PS)
XCACHE_EnableCache(XCACHE_PC);
XCACHE_EnableCache(XCACHE_PS);
#elif defined(CONFIG_SOC_MIMXRT1189_CM7)
sys_cache_instr_enable();
sys_cache_data_enable();
#endif

__ISB();
__DSB();
}
Expand Down
2 changes: 1 addition & 1 deletion west.yml
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ manifest:
groups:
- hal
- name: hal_nxp
revision: 7d1c7954df3c7fe758ae6f7482bffde0d910921f
revision: c15dd51d7af27593e38b65b1443a350e9d2de64f
path: modules/hal/nxp
groups:
- hal
Expand Down
Loading