Skip to content

Commit 6ba7691

Browse files
WorldofJARcraftkartben
authored andcommitted
soc: cva6: Implement missing cache management APIs
In hardware, cva6 currently only provides global disable/enable functions for the Dcache and Icache. Disabling and re-enabling them also has the effect of flushing and invalidating the cache. Future cva6 SoCs will add support RISC-V's standardized cache management operations. This commit provides a default implementation for all methods currently part of the cache API. These implementations can be overwritten at board or SoC level, as they use weak linking. Signed-off-by: Eric Ackermann <eric.ackermann@cispa.de>
1 parent e367e1d commit 6ba7691

File tree

3 files changed

+87
-4
lines changed

3 files changed

+87
-4
lines changed

soc/openhwgroup/cva6/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33

44
add_subdirectory(${SOC_SERIES})
55

6-
zephyr_library_sources_ifdef(CONFIG_SOC_FAMILY_CVA6_PROVIDE_NONSTANDARD_CACHE_OPTIONS soc_cache_management.c)
6+
zephyr_library_sources_ifdef(CONFIG_CACHE_MANAGEMENT soc_cache_management.c)
77

88
set(SOC_LINKER_SCRIPT ${ZEPHYR_BASE}/include/zephyr/arch/riscv/common/linker.ld CACHE INTERNAL "")

soc/openhwgroup/cva6/Kconfig

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33

44
if SOC_FAMILY_OPENHWGROUP_CVA6
55

6-
config SOC_FAMILY_CVA6_PROVIDE_NONSTANDARD_CACHE_OPTIONS
7-
bool "Include non-standard cache management operations (currently global cache disable)"
8-
96
rsource "*/Kconfig"
107

118
endif # SOC_FAMILY_OPENHWGROUP_CVA6

soc/openhwgroup/cva6/soc_cache_management.c

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,49 @@ void __weak arch_dcache_disable(void)
2121
csr_write(SOC_CVA6_CUSTOM_CSR_DCACHE, SOC_CVA6_CUSTOM_CSR_DCACHE_DISABLE);
2222
}
2323

24+
int __weak arch_dcache_flush_all(void)
25+
{
26+
arch_dcache_disable();
27+
arch_dcache_enable();
28+
29+
return 0;
30+
}
31+
32+
int __weak arch_dcache_invd_all(void)
33+
{
34+
return arch_dcache_flush_all();
35+
}
36+
37+
int __weak arch_dcache_flush_and_invd_all(void)
38+
{
39+
return arch_dcache_flush_all();
40+
}
41+
42+
/* FIXME currently not supported by all CVA6 - overwrite at board or SoC level */
43+
int __weak arch_dcache_flush_range(void *addr, size_t size)
44+
{
45+
ARG_UNUSED(addr);
46+
ARG_UNUSED(size);
47+
48+
return arch_dcache_flush_all();
49+
}
50+
51+
int __weak arch_dcache_invd_range(void *addr, size_t size)
52+
{
53+
ARG_UNUSED(addr);
54+
ARG_UNUSED(size);
55+
56+
return arch_dcache_flush_all();
57+
}
58+
59+
int __weak arch_dcache_flush_and_invd_range(void *addr, size_t size)
60+
{
61+
ARG_UNUSED(addr);
62+
ARG_UNUSED(size);
63+
64+
return arch_dcache_flush_all();
65+
}
66+
2467
void __weak arch_icache_enable(void)
2568
{
2669
csr_write(SOC_CVA6_CUSTOM_CSR_ICACHE, SOC_CVA6_CUSTOM_CSR_ICACHE_ENABLE);
@@ -31,6 +74,49 @@ void __weak arch_icache_disable(void)
3174
csr_write(SOC_CVA6_CUSTOM_CSR_ICACHE, SOC_CVA6_CUSTOM_CSR_ICACHE_DISABLE);
3275
}
3376

77+
int __weak arch_icache_flush_all(void)
78+
{
79+
arch_icache_disable();
80+
arch_icache_enable();
81+
82+
return 0;
83+
}
84+
85+
int __weak arch_icache_invd_all(void)
86+
{
87+
return arch_icache_flush_all();
88+
}
89+
90+
int __weak arch_icache_flush_and_invd_all(void)
91+
{
92+
return arch_icache_flush_all();
93+
}
94+
95+
/* FIXME currently not supported by all CVA6 - overwrite at board or SoC level */
96+
int __weak arch_icache_flush_range(void *addr, size_t size)
97+
{
98+
ARG_UNUSED(addr);
99+
ARG_UNUSED(size);
100+
101+
return arch_icache_flush_all();
102+
}
103+
104+
int __weak arch_icache_invd_range(void *addr, size_t size)
105+
{
106+
ARG_UNUSED(addr);
107+
ARG_UNUSED(size);
108+
109+
return arch_icache_flush_all();
110+
}
111+
112+
int __weak arch_icache_flush_and_invd_range(void *addr, size_t size)
113+
{
114+
ARG_UNUSED(addr);
115+
ARG_UNUSED(size);
116+
117+
return arch_icache_flush_all();
118+
}
119+
34120
/* FIXME there is no common implementation for RISC-V, so we provide a SoC-level definition */
35121
/* this prevents a linker error when the function is not defined */
36122
void __weak arch_cache_init(void)

0 commit comments

Comments
 (0)