Skip to content
Open
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 arch/riscv/custom/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ add_subdirectory_ifdef(CONFIG_DT_HAS_OPENHWGROUP_CVA6_ENABLED openhwgroup/cva6)
add_subdirectory_ifdef(CONFIG_DT_HAS_NUCLEI_BUMBLEBEE_ENABLED nuclei)
add_subdirectory_ifdef(CONFIG_DT_HAS_OPENISA_RI5CY_ENABLED openisa/ri5cy)
add_subdirectory_ifdef(CONFIG_DT_HAS_OPENISA_ZERO_RI5CY_ENABLED openisa/zero_riscy)
add_subdirectory_ifdef(CONFIG_DT_HAS_SPINALHDL_VEXRISCV_ENABLED vexriscv)
add_subdirectory_ifdef(CONFIG_DT_HAS_XUANTIE_E907_ENABLED thead)
6 changes: 6 additions & 0 deletions arch/riscv/custom/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ rsource "andes/Kconfig"

endif # DT_HAS_ANDESTECH_ANDESCORE_V5_ENABLED

if DT_HAS_SPINALHDL_VEXRISCV_ENABLED

rsource "vexriscv/Kconfig"

endif # DT_HAS_SPINALHDL_VEXRISCV_ENABLED

if DT_HAS_XUANTIE_E907_ENABLED

rsource "thead/Kconfig"
Expand Down
4 changes: 4 additions & 0 deletions arch/riscv/custom/vexriscv/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# SPDX-FileCopyrightText: Copyright The Zephyr Project Contributors
# SPDX-License-Identifier: Apache-2.0

zephyr_library_sources_ifdef(CONFIG_RISCV_CUSTOM_CSR_VEXRISCV_CACHE cache_vexriscv.c)
9 changes: 9 additions & 0 deletions arch/riscv/custom/vexriscv/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# SPDX-FileCopyrightText: Copyright The Zephyr Project Contributors
# SPDX-License-Identifier: Apache-2.0

config RISCV_CUSTOM_CSR_VEXRISCV_CACHE
bool
default y
depends on ARCH_CACHE
help
This option enables cache support for VexRiscv family of CPUs.
122 changes: 122 additions & 0 deletions arch/riscv/custom/vexriscv/cache_vexriscv.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/*
* SPDX-FileCopyrightText: Copyright The Zephyr Project Contributors
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <zephyr/kernel.h>
#include <zephyr/cache.h>

#ifdef CONFIG_DCACHE
void arch_dcache_enable(void)
{
/* Nothing */
}

void arch_dcache_disable(void)
{
/* Nothing */
}

int arch_dcache_invd_all(void)
{
/* Invalidate whole data cache instruction: 0x500F
* https://github.com/SpinalHDL/VexRiscv?tab=readme-ov-file#dbuscachedplugin
*/
__asm__ volatile(".insn 0x500F\n");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I'd maybe add a small comment here that this instruction is for invalidating the whole cache, and maybe this link: https://github.com/SpinalHDL/VexRiscv?tab=readme-ov-file#dbuscachedplugin

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added


return 0;
}

int arch_dcache_invd_range(void *addr, size_t size)
{
/* Invalidate cache line instruction: 0x500f | (rs1 << 15)
* https://github.com/SpinalHDL/VexRiscv?tab=readme-ov-file#dbuscachedplugin
*/
__asm__ volatile(
"mv a0, %1\n"
"j 2f\n"
"3:\n"
".insn 0x5500F\n" /* 0x500f | (a0 << 15) */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto: add a comment about the address range we're invalidating here

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

"add a0, a0, %0\n"
"2:\n"
"bltu a0, %2, 3b\n"
: : "r"(CONFIG_DCACHE_LINE_SIZE),
"r"((unsigned int)(addr) & ~((CONFIG_DCACHE_LINE_SIZE) - 1UL)),
"r"((unsigned int)(addr) + (size))
: "a0");

return 0;
}


int arch_dcache_flush_all(void)
{
/* VexRiscv cache is write-through */
return 0;
}

int arch_dcache_flush_range(void *addr __unused, size_t size __unused)
{
return 0;
}

int arch_dcache_flush_and_invd_all(void)
{
return arch_dcache_invd_all();
}

int arch_dcache_flush_and_invd_range(void *addr, size_t size)
{
return arch_dcache_invd_range(addr, size);
}
#endif /* CONFIG_DCACHE */

#ifdef CONFIG_ICACHE
void arch_icache_enable(void)
{
/* Nothing */
}

void arch_icache_disable(void)
{
/* Nothing */
}

int arch_icache_flush_all(void)
{
__asm__ volatile("fence.i\n");

return 0;
}

int arch_icache_invd_all(void)
{
return arch_icache_flush_all();
}

int arch_icache_invd_range(void *addr_in __unused, size_t size __unused)
{
return arch_icache_flush_all();
}

int arch_icache_flush_and_invd_all(void)
{
return arch_icache_flush_all();
}

int arch_icache_flush_range(void *addr __unused, size_t size __unused)
{
return arch_icache_flush_all();
}

int arch_icache_flush_and_invd_range(void *addr __unused, size_t size __unused)
{
return arch_icache_flush_all();
}
#endif /* CONFIG_ICACHE */

void arch_cache_init(void)
{
/* Nothing */
}
8 changes: 7 additions & 1 deletion dts/bindings/cpu/litex,vexriscv-standard.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,10 @@ description: VexRiscv core with the standard configuration as used by LiteX

compatible: "litex,vexriscv-standard"

include: riscv,cpus.yaml
include: spinalhdl,vexriscv.yaml

properties:
i-cache-line-size:
default: 32
d-cache-line-size:
default: 32
8 changes: 8 additions & 0 deletions dts/bindings/cpu/spinalhdl,vexriscv.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# SPDX-FileCopyrightText: Copyright The Zephyr Project Contributors
# SPDX-License-Identifier: Apache-2.0

description: VexRiscv core

compatible: "spinalhdl,vexriscv"

include: riscv,cpus.yaml
1 change: 1 addition & 0 deletions dts/bindings/vendor-prefixes.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Device tree binding vendor prefix registry. Keep this list in

Check warning on line 1 in dts/bindings/vendor-prefixes.txt

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

Copyright missing

dts/bindings/vendor-prefixes.txt:1 File has no SPDX-FileCopyrightText header, consider adding one.

Check warning on line 1 in dts/bindings/vendor-prefixes.txt

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

License missing

dts/bindings/vendor-prefixes.txt:1 File has no SPDX-License-Identifier header, consider adding one.
# alphabetical order.
#
# This isn't an exhaustive list, but you should add new prefixes to it
Expand Down Expand Up @@ -657,6 +657,7 @@
sony Sony Corporation
spansion Spansion Inc.
sparkfun SparkFun Electronics
spinalhdl SpinalHDL
sprd Spreadtrum Communications Inc.
sqn Sequans Communications
sst Silicon Storage Technology, Inc.
Expand Down
2 changes: 1 addition & 1 deletion dts/riscv/riscv32-litex-vexriscv.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

cpu0: cpu@0 {
clock-frequency = <100000000>;
compatible = "litex,vexriscv-standard", "riscv";
compatible = "litex,vexriscv-standard", "spinalhdl,vexriscv", "riscv";
device_type = "cpu";
reg = <0>;
riscv,isa = "rv32im_zicsr_zifencei";
Expand Down
3 changes: 3 additions & 0 deletions soc/litex/litex_vexriscv/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ config SOC_LITEX_VEXRISCV
select RISCV_ISA_EXT_M
select RISCV_ISA_EXT_ZICSR
select RISCV_ISA_EXT_ZIFENCEI
# There are varriants of the Vexriscv without cache, be able to set it
select CPU_HAS_ICACHE if $(dt_node_int_prop_int,/cpus/cpu@0,i-cache-line-size) > 0
select CPU_HAS_DCACHE if $(dt_node_int_prop_int,/cpus/cpu@0,d-cache-line-size) > 0
imply XIP

if SOC_LITEX_VEXRISCV
Expand Down
Loading