-
Notifications
You must be signed in to change notification settings - Fork 8.2k
arch: riscv: Add support for Xuantie CPUs and enable it on bl61x #95427
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
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| # RISC-V cores configuration options | ||
|
|
||
| # Copyright (c) 2025 MASSDRIVER EI (massdriver.space) | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| config XUANTIE | ||
| bool | ||
| help | ||
| This option signifies the use of a CPU of the XuanTie RISC-V family | ||
|
|
||
| rsource "xuantie/Kconfig" |
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,8 @@ | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| zephyr_syscall_header(${ZEPHYR_BASE}/include/zephyr/cache.h) | ||
|
|
||
| zephyr_library() | ||
|
|
||
| zephyr_library_sources_ifdef(CONFIG_CACHE_XTHEADCMO cache_xtheadcmo.c) | ||
| zephyr_library_sources_ifdef(CONFIG_CACHE_XTHEADCMO_E907 cache_xtheadcmo_e907.c) |
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,48 @@ | ||
| # Copyright (c) 2025 MASSDRIVER EI (massdriver.space) | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| config XUANTIE_E907 | ||
| bool | ||
| select XUANTIE | ||
| select GEN_IRQ_VECTOR_TABLE | ||
| select INCLUDE_RESET_VECTOR | ||
| select RISCV_HAS_CLIC | ||
| select RISCV_MACHINE_TIMER | ||
| select RISCV_PRIVILEGED | ||
| select RISCV_ISA_RV32I | ||
| select RISCV_ISA_EXT_M | ||
| select RISCV_ISA_EXT_A | ||
| select RISCV_ISA_EXT_C | ||
| select RISCV_ISA_EXT_ZICSR | ||
| select RISCV_ISA_EXT_ZIFENCEI | ||
| select RISCV_VECTORED_MODE | ||
|
|
||
| if XUANTIE | ||
|
|
||
| config CACHE_XTHEADCMO | ||
| bool | ||
| default y | ||
JarmouniA marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| select CACHE_MANAGEMENT | ||
| select CPU_HAS_ICACHE | ||
| help | ||
| This option enables cache support for XuanTie family of CPUs using the XTHeadCmo extension | ||
|
|
||
| if CACHE_XTHEADCMO | ||
|
|
||
| config DCACHE_LINE_SIZE | ||
| default 32 | ||
|
|
||
| config ICACHE_LINE_SIZE | ||
| default 32 | ||
JarmouniA marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| config CACHE_XTHEADCMO_E907 | ||
| bool | ||
| default y | ||
| depends on XUANTIE_E907 | ||
| select CPU_HAS_DCACHE | ||
| help | ||
| This option enables the additional XTHeadCmo cache functions for the E907 cores | ||
|
|
||
| endif # CACHE_XTHEADCMO | ||
|
|
||
| endif # XUANTIE | ||
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,203 @@ | ||
| /* | ||
| * Copyright (c) 2025 MASSDRIVER EI (massdriver.space) | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| #include <zephyr/init.h> | ||
| #include <zephyr/kernel.h> | ||
| #include <zephyr/cache.h> | ||
|
|
||
| int arch_dcache_invd_all(void) | ||
| { | ||
| __asm__ volatile ( | ||
| "fence\n" | ||
| /* th.dcache.iall */ | ||
| ".insn 0x20000B\n" | ||
| "fence\n" | ||
| ); | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| static void arch_cache_invalidate_dcache_line(uintptr_t address_in) | ||
| { | ||
| register uintptr_t address __asm__("a3") = address_in; | ||
|
|
||
| __asm__ volatile ( | ||
| /* th.dcache.ipa a3*/ | ||
| ".insn 0x2A6800B\n" | ||
| : | ||
| : "r"(address) | ||
| ); | ||
| } | ||
|
|
||
| int arch_dcache_invd_range(void *addr_in, size_t size) | ||
| { | ||
| uintptr_t addr = (uintptr_t)addr_in; | ||
|
|
||
| __asm__ volatile ( | ||
| "fence\n" | ||
| ); | ||
| for (uintptr_t i = addr; i < addr + size; i += CONFIG_DCACHE_LINE_SIZE) { | ||
| arch_cache_invalidate_dcache_line(i); | ||
| } | ||
| __asm__ volatile ( | ||
| "fence\n" | ||
| ); | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| int arch_icache_invd_all(void) | ||
| { | ||
| __asm__ volatile ( | ||
| "fence\n" | ||
| "fence.i\n" | ||
| /* th.icache.iall */ | ||
| ".insn 0x100000B\n" | ||
| "fence\n" | ||
| "fence.i\n" | ||
| ); | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| static void arch_cache_invalidate_icache_line(uintptr_t address_in) | ||
| { | ||
| register uintptr_t address __asm__("a3") = address_in; | ||
|
|
||
| __asm__ volatile ( | ||
| /* th.icache.ipa a3*/ | ||
| ".insn 0x386800B\n" | ||
| : | ||
| : "r"(address) | ||
| ); | ||
| } | ||
|
|
||
| int arch_icache_invd_range(void *addr_in, size_t size) | ||
| { | ||
| uintptr_t addr = (uintptr_t)addr_in; | ||
|
|
||
| __asm__ volatile ( | ||
| "fence\n" | ||
| "fence.i\n" | ||
| ); | ||
| for (uintptr_t i = addr; i < addr + size; i += CONFIG_ICACHE_LINE_SIZE) { | ||
| arch_cache_invalidate_icache_line(i); | ||
| } | ||
| __asm__ volatile ( | ||
| "fence\n" | ||
| "fence.i\n" | ||
| ); | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| int arch_dcache_flush_all(void) | ||
| { | ||
| __asm__ volatile ( | ||
| "fence\n" | ||
| /* th.dcache.call */ | ||
| ".insn 0x10000B\n" | ||
| "fence\n" | ||
| ); | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| static void arch_cache_clean_dcache_line(uintptr_t address_in) | ||
| { | ||
| register uintptr_t address __asm__("a3") = address_in; | ||
|
|
||
| __asm__ volatile ( | ||
| /* th.dcache.cpa a3*/ | ||
| ".insn 0x296800B\n" | ||
| : | ||
| : "r"(address) | ||
| ); | ||
| } | ||
|
|
||
| int arch_dcache_flush_range(void *addr_in, size_t size) | ||
| { | ||
| uintptr_t addr = (uintptr_t)addr_in; | ||
|
|
||
| __asm__ volatile ( | ||
| "fence\n" | ||
| ); | ||
| for (uintptr_t i = addr; i < addr + size; i += CONFIG_DCACHE_LINE_SIZE) { | ||
| arch_cache_clean_dcache_line(i); | ||
| } | ||
| __asm__ volatile ( | ||
| "fence\n" | ||
| ); | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| int arch_dcache_flush_and_invd_all(void) | ||
| { | ||
| __asm__ volatile ( | ||
| "fence\n" | ||
| /* th.dcache.ciall */ | ||
| ".insn 0x30000B\n" | ||
| "fence\n" | ||
| ); | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| static void arch_cache_clean_invalidate_dcache_line(uintptr_t address_in) | ||
| { | ||
| register uintptr_t address __asm__("a3") = address_in; | ||
|
|
||
| __asm__ volatile ( | ||
| /* th.dcache.cipa a3*/ | ||
| ".insn 0x2B6800B\n" | ||
| : | ||
| : "r"(address) | ||
| ); | ||
| } | ||
|
|
||
| int arch_dcache_flush_and_invd_range(void *addr_in, size_t size) | ||
| { | ||
| uintptr_t addr = (uintptr_t)addr_in; | ||
|
|
||
| __asm__ volatile ( | ||
| "fence\n" | ||
| ); | ||
| for (uintptr_t i = addr; i < addr + size; i += CONFIG_DCACHE_LINE_SIZE) { | ||
| arch_cache_clean_invalidate_dcache_line(i); | ||
| } | ||
| __asm__ volatile ( | ||
| "fence\n" | ||
| ); | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| int arch_icache_flush_all(void) | ||
| { | ||
| return -ENOTSUP; | ||
| } | ||
|
|
||
| int arch_icache_flush_and_invd_all(void) | ||
| { | ||
| return -ENOTSUP; | ||
| } | ||
|
|
||
| int arch_icache_flush_range(void *addr, size_t size) | ||
| { | ||
| ARG_UNUSED(addr); | ||
| ARG_UNUSED(size); | ||
|
|
||
| return -ENOTSUP; | ||
| } | ||
|
|
||
| int arch_icache_flush_and_invd_range(void *addr, size_t size) | ||
| { | ||
| ARG_UNUSED(addr); | ||
| ARG_UNUSED(size); | ||
|
|
||
| return -ENOTSUP; | ||
| } |
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,108 @@ | ||
| /* | ||
| * Copyright (c) 2025 MASSDRIVER EI (massdriver.space) | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| #include <zephyr/init.h> | ||
| #include <zephyr/kernel.h> | ||
| #include <zephyr/cache.h> | ||
|
|
||
| /* "a Hardware CSR" */ | ||
| #define THEAD_MHCR "0x7C1" | ||
|
|
||
| void arch_icache_enable(void) | ||
| { | ||
| uint32_t tmp; | ||
|
|
||
| __asm__ volatile ( | ||
| "fence\n" | ||
| "fence.i\n" | ||
| /* th.icache.iall */ | ||
| ".insn 0x100000B\n" | ||
| ); | ||
| __asm__ volatile( | ||
| "csrr %0, " THEAD_MHCR | ||
| : "=r"(tmp)); | ||
| tmp |= (1 << 0); | ||
| __asm__ volatile( | ||
| "csrw " THEAD_MHCR ", %0" | ||
| : | ||
| : "r"(tmp)); | ||
| __asm__ volatile ( | ||
| "fence\n" | ||
| "fence.i\n" | ||
| ); | ||
| } | ||
|
|
||
| void arch_dcache_enable(void) | ||
| { | ||
| uint32_t tmp; | ||
|
|
||
| __asm__ volatile ( | ||
| "fence\n" | ||
| "fence.i\n" | ||
| /* th.dcache.iall */ | ||
| ".insn 0x20000B\n" | ||
| ); | ||
| __asm__ volatile( | ||
| "csrr %0, " THEAD_MHCR | ||
| : "=r"(tmp)); | ||
| tmp |= (1 << 1) | (1 << 2) | (1 << 3) | (1 << 4); | ||
| __asm__ volatile( | ||
| "csrw " THEAD_MHCR ", %0" | ||
| : | ||
| : "r"(tmp)); | ||
| __asm__ volatile ( | ||
| "fence\n" | ||
| "fence.i\n" | ||
| ); | ||
| } | ||
|
|
||
| void arch_icache_disable(void) | ||
| { | ||
| uint32_t tmp; | ||
|
|
||
| __asm__ volatile ( | ||
| "fence\n" | ||
| "fence.i\n" | ||
| /* th.icache.iall */ | ||
| ".insn 0x100000B\n" | ||
| ); | ||
| __asm__ volatile( | ||
| "csrr %0, " THEAD_MHCR | ||
| : "=r"(tmp)); | ||
| tmp &= ~(1 << 0); | ||
| __asm__ volatile( | ||
| "csrw " THEAD_MHCR ", %0" | ||
| : | ||
| : "r"(tmp)); | ||
| __asm__ volatile ( | ||
| "fence\n" | ||
| "fence.i\n" | ||
| ); | ||
| } | ||
|
|
||
| void arch_dcache_disable(void) | ||
| { | ||
| uint32_t tmp; | ||
|
|
||
| __asm__ volatile ( | ||
| "fence\n" | ||
| "fence.i\n" | ||
| /* th.dcache.iall */ | ||
| ".insn 0x20000B\n" | ||
| ); | ||
| __asm__ volatile( | ||
| "csrr %0, " THEAD_MHCR | ||
| : "=r"(tmp)); | ||
| tmp &= ~((1 << 1) | (1 << 2) | (1 << 3) | (1 << 4)); | ||
| __asm__ volatile( | ||
| "csrw " THEAD_MHCR ", %0" | ||
| : | ||
| : "r"(tmp)); | ||
| __asm__ volatile ( | ||
| "fence\n" | ||
| "fence.i\n" | ||
| ); | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.