Risc-V cache operations
v2 cover Risc-V cache operations
This patchset adds support for using the CBO instructions to perform the dcache flush/inval operations for the qemu-riscv board when those are enabled. The CBO instructions are defined in the Risc-V CMO specification which can be found at the link below:
https://github.com/riscv/riscv-CMOs/blob/master/specifications/cmobase-v1.0.pdf
Changes in v2:
- Use cache functions in generic cache code instead of board specific code
- Print the zicbom init status in case of a failure
Mayuresh Chitale (2):
riscv: Add support for defining instructions
riscv: cache: Add CBO instructions
arch/riscv/Kconfig | 4 ++ arch/riscv/include/asm/insn-def.h | 42 ++++++++++++++ arch/riscv/lib/cache.c | 96 +++++++++++++++++++++++++++++++ 3 files changed, 142 insertions(+) create mode 100644 arch/riscv/include/asm/insn-def.h
Signature · 1 line
2.34.1
PATCH v2 1/2 riscv: Add support for defining instructions
Add insn-def.h which is similar to that in linux and contains the macros to generate any instruction of type 'I' using the assembler's .insn directive.
--- arch/riscv/include/asm/insn-def.h | 42 +++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 arch/riscv/include/asm/insn-def.h
arch/riscv/include/asm/insn-def.h new file +42 -0
@@ -0,0 +1,42 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 2024 Ventana Micro Systems Ltd. +* +* Ported from linux insn-def.h. +*/ + +#ifndef _ASM_RISCV_BARRIER_H +#define _ASM_RISCV_BARRIER_H + +#define INSN_I_SIMM12_SHIFT 20 +#define INSN_I_RS1_SHIFT 15 +#define INSN_I_FUNC3_SHIFT 12 +#define INSN_I_RD_SHIFT 7 +#define INSN_I_OPCODE_SHIFT 0 + +#define RV_OPCODE (v) __ASM_STR(v) +#define RV_FUNC3 (v) __ASM_STR(v) +#define RV_FUNC7 (v) __ASM_STR(v) +#define RV_SIMM12 (v) __ASM_STR(v) +#define RV_RD (v) __ASM_STR(v) +#define RV_RS1 (v) __ASM_STR(v) +#define RV_RS2 (v) __ASM_STR(v) +#define __RV_REG (v) __ASM_STR(x ## v) +#define RV___RD (v) __RV_REG(v) +#define RV___RS1 (v) __RV_REG(v) +#define RV___RS2 (v) __RV_REG(v) + +#define RV_OPCODE_MISC_MEM RV_OPCODE(15) +#define RV_OPCODE_SYSTEM RV_OPCODE(115) + +#define RV_OPCODE_MISC_MEM RV_OPCODE(15) +#define RV_OPCODE_SYSTEM RV_OPCODE(115) + +#define __INSN_I (opcode, func3, rd, rs1, simm12) \ + ".insn i " opcode ", " func3 ", " rd ", " rs1 ", " simm12 "\n" + +#define INSN_I (opcode, func3, rd, rs1, simm12) \ + __INSN_I(RV_##opcode, RV_##func3, RV_##rd, \ + RV_##rs1, RV_##simm12) + +#endif /* _ASM_RISCV_BARRIER_H */
Signature · 1 line
2.34.1
PATCH v2 2/2 riscv: cache: Add CBO instructions
In reply to Mayuresh ChitaleDefine CBO inval and flush instructions and use those for the dcache inval and flush operations respectively.
--- arch/riscv/Kconfig | 4 ++ arch/riscv/lib/cache.c | 96 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+)
arch/riscv/Kconfig +4 -0
@@ -310,6 +310,10 @@ endmenu config RISCV_ISA_A def_bool y +config RISCV_ISA_ZICBOM + bool "Zicbom support" + depends on !SYS_DISABLE_DCACHE_OPS + config DMA_ADDR_T_64BIT bool default y if 64BIT
arch/riscv/lib/cache.c +96 -0
118 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [PATCH v2 1/2] riscv: Add support for defining instructions
In reply to Mayuresh ChitaleHi Mayuresh,
Quoted 39 lines · Mayuresh Chitale
Add
insn-def.hwhich is similar to that in linux and contains the macros to generate any instruction of type 'I' using the assembler's .insn directive.Signed-off-by Mayuresh Chitale <[email protected]>--- arch/riscv/include/asm/insn-def.h | 42 +++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 arch/riscv/include/asm/insn-def.harch/riscv/include/asm/insn-def.h new file +23
-0@@ -0,0 +1,42 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Copyright (C) 2024 Ventana Micro Systems Ltd. +* +* Ported from linux insn-def.h. +*/ + +#ifndef _ASM_RISCV_BARRIER_H +#define _ASM_RISCV_BARRIER_H + +#define INSN_I_SIMM12_SHIFT 20 +#define INSN_I_RS1_SHIFT 15 +#define INSN_I_FUNC3_SHIFT 12 +#define INSN_I_RD_SHIFT 7 +#define INSN_I_OPCODE_SHIFT 0 + +#define RV_OPCODE (v) __ASM_STR(v) +#define RV_FUNC3 (v) __ASM_STR(v) +#define RV_FUNC7 (v) __ASM_STR(v) +#define RV_SIMM12 (v) __ASM_STR(v) +#define RV_RD (v) __ASM_STR(v) +#define RV_RS1 (v) __ASM_STR(v) +#define RV_RS2 (v) __ASM_STR(v)
arch/riscv/include/asm/insn-def.h line 33
Quoted 10 lines
arch/riscv/include/asm/insn-def.h new file +10
-0+#define __RV_REG (v) __ASM_STR(x ## v) +#define RV___RD (v) __RV_REG(v) +#define RV___RS1 (v) __RV_REG(v) +#define RV___RS2 (v) __RV_REG(v) + +#define RV_OPCODE_MISC_MEM RV_OPCODE(15) +#define RV_OPCODE_SYSTEM RV_OPCODE(115) + +#define RV_OPCODE_MISC_MEM RV_OPCODE(15) +#define RV_OPCODE_SYSTEM RV_OPCODE(115)
These two lines are duplicated but I could fix this when merging the patch.
Quoted 9 lines
arch/riscv/include/asm/insn-def.h new file +9
-0+ +#define __INSN_I (opcode, func3, rd, rs1, simm12) \ + ".insn i " opcode ", " func3 ", " rd ", " rs1 ", " simm12 "\n" + +#define INSN_I (opcode, func3, rd, rs1, simm12) \ + __INSN_I(RV_##opcode, RV_##func3, RV_##rd, \ + RV_##rs1, RV_##simm12) + +#endif /* _ASM_RISCV_BARRIER_H */
Re: [PATCH v2 2/2] riscv: cache: Add CBO instructions
In reply to Mayuresh ChitaleQuoted 8 lines · Mayuresh Chitale
Define CBO inval and flush instructions and use those for the dcache inval and flush operations respectively.
Signed-off-by Mayuresh Chitale <[email protected]>--- arch/riscv/Kconfig | 4 ++ arch/riscv/lib/cache.c | 96 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+)