-
Notifications
You must be signed in to change notification settings - Fork 8k
arch: riscv: introduce common layer for RISC-V custom CSRs #93697
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
926880c
arch: riscv: introduce RISC-V custom CSR common layer
jimmyzhe 612627b
arch: riscv: custom: add Andes CSR support
jimmyzhe aeccc62
soc: telink: tlsr951x: use RISC-V custom CSR common code
jimmyzhe 0330f78
soc: egis: et171: add support for Andes custom CSRs
jimmyzhe 8c62f34
arch: riscv: : custom: add Nuclei CSR support
jimmyzhe 352a844
arch: riscv: custom: add OpenHW Group CVA6 CSR support
jimmyzhe 8b9fcce
arch: riscv: custom: add OpenISA RI5CY and Zero-RISCY CSR support
jimmyzhe de100db
arch: riscv: custom: add T-Head Xuantie CSR support
jimmyzhe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
|
||
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_ */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_ */ |
File renamed without changes.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed it, thanks.