Skip to content

Conversation

jimmyzhe
Copy link
Contributor

@jimmyzhe jimmyzhe commented Jul 25, 2025

This PR is inspired by #91940.

RISC-V allows custom CSR implementation. Some SoCs from different SoC vendors may share the same core or the same custom CSR definitions and drivers.
For example, Andes AE350, Telink TLSR9518, and Egis ET171 all support Andes-specific CSRs.

This PR introduces soc/common/riscv-custom zephyr/arch/riscv/custom, which centralizes support for custom CSRs, allowing code reuse across SoCs that come from different vendors.

Currently supported these custom CSR:

  1. Andes
  2. Nuclei
  3. OpenHWGroup CVA6
  4. OpenISA RI5CY
  5. OpenISA Zero-riscy
  6. T-Head

config CPU_HAS_ANDES_EXECIT
bool
help
The AndesCore supports EXEC.IT instruction.
Copy link
Contributor

Choose a reason for hiding this comment

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

help text indent is 1x tab followed by 2x spaces

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.

The AndesCore supports EXEC.IT instruction.

config RISCV_CUSTOM_CSR_ANDES_EXECIT
bool "Andes V5 EXEC.IT extension"
Copy link
Contributor

Choose a reason for hiding this comment

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

why do any of these have prompts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This remains the original design from andestech/ae350 and telink/tlsr/tlsr951x.
The SoC selects Andes extensions through CPU_HAS_ANDES_XXX, while applications can decide whether to use them or not.

For example, a SoC may support the Andes HWDSP or PFT extension, but if the application doesn’t use them, the user can disable these features via these options.

@jimmyzhe
Copy link
Contributor Author

Removed old Kconfig option in adp_xc7k_ae350_clic_defconfig.

Hi @kevinwang821020 , there are some issues with the dma_andes_atcdmac300 driver check or the adp_xc7k_ae350.conf in tests/drivers/dma.
Could you help take a look?

@npitre
Copy link

npitre commented Jul 25, 2025

I wonder if zephyr/socscommon/ is the proper location for this...

Either this is vendor specific in which case this should be in
zephyr/soc/<vendor>/ or this is more architectural in which case it
might rather be in zephyr/arch/riscv/custom/.

@kevinwang821020
Copy link
Contributor

kevinwang821020 commented Jul 28, 2025

Removed old Kconfig option in adp_xc7k_ae350_clic_defconfig.

Hi @kevinwang821020 , there are some issues with the dma_andes_atcdmac300 driver check or the adp_xc7k_ae350.conf in tests/drivers/dma. Could you help take a look?

Based on the current atcdmac driver codebase, it need to do the cache operations(CONFIG_CACHE_MANAGEMENT) for chain_block when DCACHE is enabled, even CONFIG_NOCACHE_MEMORY is enable.

I have already prepared a previous PR ( PR #85272 ) which includes fixing this problem.

@jimmyzhe
Copy link
Contributor Author

Either this is vendor specific in which case this should be in zephyr/soc/<vendor>/ or this is more architectural in which case it might rather be in zephyr/arch/riscv/custom/.

Right, custom CSR is RISC-V feature, I think placing these in zephyr/arch/riscv/custom is more appropriate and simple to reuse.

Moved the custom CSR common code to zephyr/arch/riscv/custom and also fixed the help text indentation in zephyr/arch/riscv/custom/andes/Kconfig.

@jimmyzhe
Copy link
Contributor Author

jimmyzhe commented Oct 8, 2025

Rebased to main and enabled Andes custom CSR support for Egis ET171.

Andes specific toolchain options currently in ‎soc/egis/et171/CMakeLists.txt will be moved to cmake/compiler/andes in #96833.

ping @jackylee-go.


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.

ycsin
ycsin previously approved these changes Oct 8, 2025
Copy link
Member

@ycsin ycsin left a comment

Choose a reason for hiding this comment

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

LGTM otherwise

RISC-V allows custom CSR implementation. Some SoCs from different vendors
may share the same core or the same custom CSR definitions and drivers.

This patch introduces 'arch/riscv/custom', which centralizes support
for custom CSRs, allowing code reuse across SoCs that come from different
vendors. Currently supported thess custom CSR:
  1. Andes
  2. Nuclei
  3. OpenHWGroup CVA6
  4. OpenISA RI5CY
  5. OpenISA Zero-riscy
  6. T-Head Xuantie

Signed-off-by: Jimmy Zheng <[email protected]>
@jimmyzhe
Copy link
Contributor Author

jimmyzhe commented Oct 9, 2025

I add arch/riscv/custom for RISC-V custom CSR originally, while I think it also fit for RISC-V custom instruction.

Move arch/riscv/xuantie to arch/riscv/custom/thead.
And seperate T-Head Xuantie into

fkokosinski
fkokosinski previously approved these changes Oct 9, 2025
@JarmouniA JarmouniA requested a review from tejlmand October 10, 2025 10:55
if(CONFIG_SOC_SERIES_ANDES_AE350)
set(SOC_LINKER_SCRIPT ${CMAKE_CURRENT_SOURCE_DIR}/linker.ld CACHE INTERNAL "")
if(CONFIG_RISCV_CUSTOM_CSR_ANDES_NEXECIT)
zephyr_ld_options(-Wl,--mnexecitop)
Copy link
Contributor

Choose a reason for hiding this comment

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

no place for these in this file

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.


# Note: AndeStar V5 DSP needs custom Andes V5 toolchain
if(CONFIG_RISCV_CUSTOM_CSR_ANDES_HWDSP)
zephyr_cc_option(-mext-dsp)
Copy link
Contributor

Choose a reason for hiding this comment

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

or here

Rework Andes-specific CSR to use RISC-V custom CSR common code.
Move these stuff to 'arch/riscv/custom/andes':

1. Rename 'soc_v5.h' to 'andes_csr.h' for CSR definitions.
2. Replace '_start' with '__reset' hook for low-level CSR initialization.
3. Move CSR context to common macro '__custom_csr_save/restore_context'.
4. Move 'EXECIT' CSR support to common code.
5. Move PMA CSR driver to common code.
6. Use RISC-V common linker.ld instead of SoC-specific linker.ld.

Signed-off-by: Jimmy Zheng <[email protected]>
TLSR951x also supports Andes extended CSR. Reworks the following CSR
handling to use the RISC-V custom CSR common code:

1. Use common macros for HWDSP CSR context save/restore.
2. Use common macros for PFT CSR context save/restore.
3. Use common low-level CSR initialization via __reset hook.

Signed-off-by: Jimmy Zheng <[email protected]>
Egis ET171 implements Andes custom CSRs. Enable the following features:

1. Low level initialization of Andes CSRs
2. HWDSP and PowerBrake extensions with context save/restore
3. EXEC.IT extension

Signed-off-by: Jimmy Zheng <[email protected]>
GD32VF103 uses Nuclei-specific CSR. Move 'nuclei_csr.h' to
'arch/riscv/custom' to allow reuse across SoCs with the same Nuclei core.

Signed-off-by: Jimmy Zheng <[email protected]>
CVA6 supports custom CSR. Move 'cva6.h' to 'arch/riscv/custom/cva6_csr.h',
allowing other SoCs using the CVA6 core to reuse the same CSR definitions.

Signed-off-by: Jimmy Zheng <[email protected]>
Update OpenISA RI5CY and Zero-RISCY CSR handling to use RISC-V custom
CSR common code. Move these stuff to 'arch/riscv/custom/openisa':

1. Rename 'soc_ri5cy.h' to 'ri5cy_csr.h' for CSR definitions.
2. Rename 'soc_zero_riscy.h' to 'zero_riscy_csr.h' for CSR definitions.
3. Move CSR context to common macro '__custom_csr_save/restore_context'.
4. Move compiler option '-march=rv32imcxpulpv2' to common code.

Signed-off-by: Jimmy Zheng <[email protected]>
Move Xuantie supprot from arch/riscv/core/xuantie to the custom common
layer arch/riscv/custom/thead, with the following changes:

1. Rename Kconfig name
   CACHE_XTHEADCMO -> RISCV_CUSTOM_CSR_THEAD_CMO
2. Split the original arch/riscv/core/xuantie/Kconfig to
   a. arch/riscv/custom/thead/Kconfig: for T-Head extension
   b. arch/riscv/custom/thead/Kconfig.core: for T-Head CPU series
      (e.g. Xuantie E907)
3. Move cache line size defaults to SoC devicetree

Signed-off-by: Jimmy Zheng <[email protected]>
Copy link

@jimmyzhe
Copy link
Contributor Author

Remove the newly add Andes specific toolchain options in soc/egis/et171 and soc/andestech/ae350.
I will add these in the Andes toolchain file in #96833.

@cfriedt cfriedt merged commit 7edb310 into zephyrproject-rtos:main Oct 13, 2025
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.