Skip to content
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 arch/riscv/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# SPDX-License-Identifier: Apache-2.0

add_subdirectory(core)
add_subdirectory(custom)

zephyr_syscall_header(${ZEPHYR_BASE}/include/zephyr/arch/riscv/error.h)

Expand Down
3 changes: 2 additions & 1 deletion arch/riscv/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,7 @@ config RISCV_NO_MTVAL_ON_FP_TRAP
to handle FP exceptions.

rsource "Kconfig.isa"
rsource "core/Kconfig"

rsource "custom/Kconfig"

endmenu
2 changes: 0 additions & 2 deletions arch/riscv/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,3 @@ if(CONFIG_GEN_SW_ISR_TABLE)
zephyr_linker_sources(RODATA swi_tables.ld)
endif()
endif()

add_subdirectory_ifdef(CONFIG_XUANTIE xuantie)
11 changes: 0 additions & 11 deletions arch/riscv/core/Kconfig

This file was deleted.

8 changes: 0 additions & 8 deletions arch/riscv/core/xuantie/CMakeLists.txt

This file was deleted.

48 changes: 0 additions & 48 deletions arch/riscv/core/xuantie/Kconfig

This file was deleted.

9 changes: 9 additions & 0 deletions arch/riscv/custom/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright (c) 2025 Andes Technology Corporation
# SPDX-License-Identifier: Apache-2.0

add_subdirectory_ifdef(CONFIG_DT_HAS_ANDESTECH_ANDESCORE_V5_ENABLED andes)
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_XUANTIE_E907_ENABLED thead)
15 changes: 15 additions & 0 deletions arch/riscv/custom/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright (c) 2025 Andes Technology Corporation
# SPDX-License-Identifier: Apache-2.0

if DT_HAS_ANDESTECH_ANDESCORE_V5_ENABLED

rsource "andes/Kconfig"
Copy link
Member

Choose a reason for hiding this comment

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

This line is ahead of its time - the file is only available in the next commit?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed it, thanks.


endif # DT_HAS_ANDESTECH_ANDESCORE_V5_ENABLED

if DT_HAS_XUANTIE_E907_ENABLED

rsource "thead/Kconfig"
rsource "thead/Kconfig.core"

endif # DT_HAS_XUANTIE_E907_ENABLED
10 changes: 10 additions & 0 deletions arch/riscv/custom/andes/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copyright (c) 2025 Andes Technology Corporation
# SPDX-License-Identifier: Apache-2.0

zephyr_include_directories(.)

zephyr_sources_ifdef(CONFIG_RISCV_CUSTOM_CSR_ANDES_PMA pma.c)
zephyr_sources_ifndef(CONFIG_INCLUDE_RESET_VECTOR reset.S)
zephyr_linker_sources_ifdef(CONFIG_RISCV_CUSTOM_CSR_ANDES_EXECIT RODATA SORT_KEY 0x0 execit.ld)
zephyr_linker_sources_ifdef(CONFIG_RISCV_CUSTOM_CSR_ANDES_PMA RAM_SECTIONS SORT_KEY 0x0 pma_align_start.ld)
zephyr_linker_sources_ifdef(CONFIG_RISCV_CUSTOM_CSR_ANDES_PMA RAM_SECTIONS SORT_KEY z_end pma_align_end.ld)
73 changes: 73 additions & 0 deletions arch/riscv/custom/andes/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Copyright (c) 2025 Andes Technology Corporation
# SPDX-License-Identifier: Apache-2.0

config CPU_HAS_ANDES_EXECIT
bool
help
The AndesCore supports EXEC.IT instruction.

config RISCV_CUSTOM_CSR_ANDES_EXECIT
bool "Andes V5 EXEC.IT extension"
depends on CPU_HAS_ANDES_EXECIT
depends on RISCV_ISA_EXT_C
depends on !RISCV_GENERIC_TOOLCHAIN
depends on !LINKER_USE_NO_RELAX
help
The EXEC.IT extension (Execution on Instruction Table) generate
a look-up table and replaces suitable 32-bit instructions with
the 16-bit "exec.it <INDEX>".

config RISCV_CUSTOM_CSR_ANDES_NEXECIT
bool "Andes V5 New EXEC.IT opcode encoding"
depends on RISCV_CUSTOM_CSR_ANDES_EXECIT
help
The New EXEC.IT instruction is an alias of EXEC.IT with different
opcode encoding.

config CPU_HAS_ANDES_HWDSP
bool
help
The AndesCore supports hardware DSP extension.

config RISCV_CUSTOM_CSR_ANDES_HWDSP
bool "AndeStar V5 DSP ISA"
depends on CPU_HAS_ANDES_HWDSP
depends on !RISCV_GENERIC_TOOLCHAIN
help
This option enables the AndeStar v5 hardware DSP, in order to
support using the DSP instructions.

config CPU_HAS_ANDES_PFT
bool
help
The AndesCore supports PowerBrake extension.

config RISCV_CUSTOM_CSR_ANDES_PFT
bool "Andes V5 PowerBrake extension"
depends on CPU_HAS_ANDES_PFT
help
The PowerBrake extension throttles performance by reducing instruction
executing rate.

config CPU_HAS_ANDES_PMA
bool
help
The AndesCore supports Programmable PMA.

config RISCV_CUSTOM_CSR_ANDES_PMA
bool "Andes V5 Physical Memory Attribute (PMA)"
depends on CPU_HAS_ANDES_PMA
select ARCH_HAS_NOCACHE_MEMORY_SUPPORT
help
This option enables the Andes V5 PMA, in order to support SW to
configure physical memory attribute by PMA CSRs. The address
matching of Andes V5 PMA is like RISC-V PMP NAPOT mode
(power-of-two alignment).

config RISCV_CUSTOM_CSR_ANDES_PMA_NAPOT_GRANULARITY
int
depends on RISCV_CUSTOM_CSR_ANDES_PMA
default 4096
help
Minimum size (and alignment) of an PMA region. Use this symbol
to guarantee minimum size and alignment of PMA regions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
/*
* Copyright (c) 2021 Andes Technology Corporation
*
* Copyright (c) 2025 Andes Technology Corporation
* SPDX-License-Identifier: Apache-2.0
*/

#ifndef __RISCV_ANDES_V5_SOC_V5_H_
#define __RISCV_ANDES_V5_SOC_V5_H_
#ifndef ZEPHYR_ARCH_RISCV_CUSTOM_ANDES_CSR_H_
#define ZEPHYR_ARCH_RISCV_CUSTOM_ANDES_CSR_H_

#ifdef __cplusplus
extern "C" {
#endif

/* Control and Status Registers (CSRs) available for Andes V5 SoCs */
#define NDS_MMISC_CTL 0x7D0
Expand Down Expand Up @@ -46,4 +49,8 @@
#define NDS_PMAADDR14 0xBDE
#define NDS_PMAADDR15 0xBDF

#endif /* __RISCV_ANDES_V5_SOC_V5_H_ */
#ifdef __cplusplus
}
#endif

#endif /* ZEPHYR_ARCH_RISCV_CUSTOM_ANDES_CSR_H_ */
44 changes: 44 additions & 0 deletions arch/riscv/custom/andes/csr_context.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (c) 2025 Andes Technology Corporation
* SPDX-License-Identifier: Apache-2.0
*/

/*
* Extra definitions required for CONFIG_RISCV_SOC_CONTEXT_SAVE.
*/

#ifndef ZEPHYR_ARCH_RISCV_CUSTOM_ANDES_CSR_CONTEXT_H_
#define ZEPHYR_ARCH_RISCV_CUSTOM_ANDES_CSR_CONTEXT_H_

#ifdef CONFIG_RISCV_SOC_CONTEXT_SAVE

/* Andes V5 specific registers. */
#if defined(CONFIG_RISCV_CUSTOM_CSR_ANDES_PFT) && \
defined(CONFIG_RISCV_CUSTOM_CSR_ANDES_HWDSP)
#define CUSTOM_CSR_ESF_MEMBERS \
uint32_t mxstatus; \
uint32_t ucode \

#define CUSTOM_CSR_ESF_INIT \
0, \
0

#elif defined(CONFIG_RISCV_CUSTOM_CSR_ANDES_PFT)
#define CUSTOM_CSR_ESF_MEMBERS \
uint32_t mxstatus

#define CUSTOM_CSR_ESF_INIT \
0

#elif defined(CONFIG_RISCV_CUSTOM_CSR_ANDES_HWDSP)
#define CUSTOM_CSR_ESF_MEMBERS \
uint32_t ucode

#define CUSTOM_CSR_ESF_INIT \
0

#endif

#endif /* CONFIG_RISCV_SOC_CONTEXT_SAVE */

#endif /* ZEPHYR_ARCH_RISCV_CUSTOM_ANDES_CSR_CONTEXT_H_ */
63 changes: 63 additions & 0 deletions arch/riscv/custom/andes/csr_irq.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* Copyright (c) 2025 Andes Technology Corporation
* SPDX-License-Identifier: Apache-2.0
*/

#include <zephyr/offsets.h>
#include <zephyr/toolchain.h>
#include <andes_csr.h>

#ifdef CONFIG_64BIT
/* register-wide load/store based on ld/sd (XLEN = 64) */

.macro lr, rd, mem
ld \rd, \mem
.endm

.macro sr, rs, mem
sd \rs, \mem
.endm

#else
/* register-wide load/store based on lw/sw (XLEN = 32) */

.macro lr, rd, mem
lw \rd, \mem
.endm

.macro sr, rs, mem
sw \rs, \mem
.endm

#endif

#ifdef CONFIG_RISCV_SOC_CONTEXT_SAVE

.macro __custom_csr_save_context __soc_esf_reg reg

#ifdef CONFIG_RISCV_CUSTOM_CSR_ANDES_PFT
csrr \reg, NDS_MXSTATUS
sr \reg, __soc_esf_t_mxstatus_OFFSET(\__soc_esf_reg)
#endif

#ifdef CONFIG_RISCV_CUSTOM_CSR_ANDES_HWDSP
csrr \reg, NDS_UCODE
sr \reg, __soc_esf_t_ucode_OFFSET(\__soc_esf_reg)
#endif

.endm

.macro __custom_csr_restore_context __soc_esf_reg reg

#ifdef CONFIG_RISCV_CUSTOM_CSR_ANDES_PFT
lr \reg, __soc_esf_t_mxstatus_OFFSET(\__soc_esf_reg)
csrw NDS_MXSTATUS, \reg
#endif
#ifdef CONFIG_RISCV_CUSTOM_CSR_ANDES_HWDSP
lr \reg, __soc_esf_t_ucode_OFFSET(\__soc_esf_reg)
csrw NDS_UCODE, \reg
#endif

.endm

#endif /* CONFIG_RISCV_SOC_CONTEXT_SAVE */
34 changes: 34 additions & 0 deletions arch/riscv/custom/andes/csr_offsets.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (c) 2025 Andes Technology Corporation
* SPDX-License-Identifier: Apache-2.0
*/

/*
* Extra definitions required for CONFIG_RISCV_SOC_OFFSETS.
*/

#ifndef ZEPHYR_ARCH_RISCV_CUSTOM_ANDES_CSR_OFFSETS_H_
#define ZEPHYR_ARCH_RISCV_CUSTOM_ANDES_CSR_OFFSETS_H_

#ifdef CONFIG_RISCV_SOC_OFFSETS

/* Andes V5 specific registers. */
#if defined(CONFIG_RISCV_CUSTOM_CSR_ANDES_PFT) && \
defined(CONFIG_RISCV_CUSTOM_CSR_ANDES_HWDSP)
#define GEN_CUSTOM_CSR_OFFSET_SYMS() \
GEN_OFFSET_SYM(soc_esf_t, mxstatus); \
GEN_OFFSET_SYM(soc_esf_t, ucode)

#elif defined(CONFIG_RISCV_CUSTOM_CSR_ANDES_PFT)
#define GEN_CUSTOM_CSR_OFFSET_SYMS() \
GEN_OFFSET_SYM(soc_esf_t, mxstatus)

#elif defined(CONFIG_RISCV_CUSTOM_CSR_ANDES_HWDSP)
#define GEN_CUSTOM_CSR_OFFSET_SYMS() \
GEN_OFFSET_SYM(soc_esf_t, ucode)

#endif

#endif /* CONFIG_RISCV_SOC_OFFSETS */

#endif /* ZEPHYR_ARCH_RISCV_CUSTOM_ANDES_CSR_OFFSETS_H_ */
Loading