arch/riscv: Add CONFIG_ARCH_RV_ISA_ZICSR_ZIFENCEI for fence.i

The fence.i instruction is only available when the Zifencei extension
(CONFIG_ARCH_RV_ISA_ZICSR_ZIFENCEI) is supported by the hardware.

This commit adds a macro wrapper around fence.i usages to prevent
compilation errors on toolchains or targets where the Zifencei
extension is absent.

Signed-off-by: Chengdong Wang <wangcd91@gmail.com>
This commit is contained in:
Chengdong Wang 2026-06-27 23:31:33 +08:00 • committed by Xiang Xiao
parent 3f00e60c1f
commit 1924a96064
5 changed files with 13 additions and 3 deletions

View file

@ -39,6 +39,10 @@
/* UP_ISB() is used to synchronize the instruction and data streams */
#define UP_ISB() __asm__ __volatile__ ("fence.i" ::: "memory")
#ifdef CONFIG_ARCH_RV_ISA_ZICSR_ZIFENCEI
# define UP_ISB() __asm__ __volatile__ ("fence.i" ::: "memory")
#else
# define UP_ISB()
#endif
#endif /* __ARCH_RISCV_INCLUDE_BARRIERS_H */

View file

@ -72,8 +72,9 @@ riscv_fpuconfig:
csrs CSR_STATUS, a0
fscsr zero
#ifdef CONFIG_ARCH_RV_ISA_ZICSR_ZIFENCEI
fence.i
#endif
ret
/****************************************************************************

View file

@ -224,7 +224,9 @@ static inline void mmu_write_satp(uintptr_t reg)
"csrw satp, %0\n"
"sfence.vma x0, x0\n"
"fence rw, rw\n"
#ifdef CONFIG_ARCH_RV_ISA_ZICSR_ZIFENCEI
"fence.i\n"
#endif
:
: "rK" (reg)
: "memory"

View file

@ -70,8 +70,9 @@
riscv_vpuconfig:
li a0, MSTATUS_VS_INIT
csrs CSR_STATUS, a0
#ifdef CONFIG_ARCH_RV_ISA_ZICSR_ZIFENCEI
fence.i
#endif
ret
/****************************************************************************

View file

@ -172,7 +172,9 @@ __start:
csrw CSR_MIE, a2 /* Set MSIE bit to receive IPI */
/* flush the instruction cache */
#ifdef CONFIG_ARCH_RV_ISA_ZICSR_ZIFENCEI
fence.i
#endif
.wait_boot:
wfi