riscv-to-apply queue
Subsystems (4)
From: Alistair Francis <[email protected]>
The following changes since commit f22833602095b05733bceaddeb20f3edfced3c07:
Merge tag 'pull-target-arm-20220428' of https://git.linaro.org/people/pmaydell/qemu-arm into staging (2022-04-28 08:34:17 -0700)
are available in the Git repository at:
[email protected]:alistair23/qemu.git tags/pull-riscv-to-apply-20220429
for you to fetch changes up to 325b7c4e7582c229d28c47123c3b986ed948eb84:
hw/riscv: Enable TPM backends (2022-04-29 10:48:48 +1000)
----------------------------------------------------------------
Second RISC-V PR for QEMU 7.1
* Improve device tree generation
* Support configuarable marchid, mvendorid, mipid CSR values
* Add support for the Zbkb, Zbkc, Zbkx, Zknd/Zkne, Zknh, Zksed/Zksh and Zkr extensions
* Fix incorrect PTE merge in walk_pte
* Add TPM support to the virt board
----------------------------------------------------------------
Alistair Francis (6):
hw/riscv: virt: Add a machine done notifier
hw/core: Move the ARM sysbus-fdt to core
hw/riscv: virt: Create a platform bus
hw/riscv: virt: Add support for generating platform FDT entries hw/riscv: virt: Add device plug support
hw/riscv: Enable TPM backends
Bin Meng (2):
hw/riscv: spike: Add '/chosen/stdout-path' in device tree unconditionally hw/riscv: Don't add empty bootargs to device tree
Frank Chang (1):
target/riscv: Support configuarable marchid, mvendorid, mipid CSR values
Ralf Ramsauer (1):
target/riscv: Fix incorrect PTE merge in walk_pte
Weiwei Li (15):
target/riscv: rvk: add cfg properties for zbk* and zk*
target/riscv: rvk: add support for zbkb extension
target/riscv: rvk: add support for zbkc extension
target/riscv: rvk: add support for zbkx extension
crypto: move sm4_sbox from target/arm
target/riscv: rvk: add support for zknd/zkne extension in RV32 target/riscv: rvk: add support for zkne/zknd extension in RV64 target/riscv: rvk: add support for sha256 related instructions in zknh extension target/riscv: rvk: add support for sha512 related instructions for RV32 in zknh extension target/riscv: rvk: add support for sha512 related instructions for RV64 in zknh extension target/riscv: rvk: add support for zksed/zksh extension
target/riscv: rvk: add CSR support for Zkr
disas/riscv.c: rvk: add disas support for Zbk* and Zk* instructions target/riscv: rvk: expose zbk* and zk* properties
target/riscv: add scalar crypto related extenstion strings to isa_string
docs/system/riscv/virt.rst | 20 ++
include/crypto/sm4.h | 6 +
include/hw/{arm => core}/sysbus-fdt.h | 0
include/hw/riscv/virt.h | 8 +-
target/riscv/cpu.h | 17 ++
target/riscv/cpu_bits.h | 9 +
target/riscv/helper.h | 22 ++
target/riscv/pmp.h | 8 +-
target/riscv/insn32.decode | 97 ++++++--
crypto/sm4.c | 49 ++++
disas/riscv.c | 173 +++++++++++++-
hw/arm/virt.c | 2 +-
hw/arm/xlnx-versal-virt.c | 1 -
hw/{arm => core}/sysbus-fdt.c | 2 +-
hw/riscv/microchip_pfsoc.c | 2 +-
hw/riscv/sifive_u.c | 2 +-
hw/riscv/spike.c | 7 +-
hw/riscv/virt.c | 319 +++++++++++++++++---------
target/arm/crypto_helper.c | 36 +--
target/riscv/bitmanip_helper.c | 80 +++++++
target/riscv/cpu.c | 58 +++++
target/riscv/crypto_helper.c | 302 ++++++++++++++++++++++++
target/riscv/csr.c | 118 +++++++++-
target/riscv/monitor.c | 11 +-
target/riscv/op_helper.c | 9 +
target/riscv/translate.c | 8 +
target/riscv/insn_trans/trans_rvb.c.inc | 116 ++++++++--
target/riscv/insn_trans/trans_rvk.c.inc | 391 ++++++++++++++++++++++++++++++++
crypto/meson.build | 1 +
hw/arm/meson.build | 1 -
hw/core/meson.build | 1 +
hw/riscv/Kconfig | 2 +
target/riscv/meson.build | 3 +-
33 files changed, 1682 insertions(+), 199 deletions(-)
create mode 100644 include/crypto/sm4.h
rename include/hw/{arm => core}/sysbus-fdt.h (100%)
create mode 100644 crypto/sm4.c
rename hw/{arm => core}/sysbus-fdt.c (99%)
create mode 100644 target/riscv/crypto_helper.c
create mode 100644 target/riscv/insn_trans/trans_rvk.c.inc[PULL 01/25] hw/riscv: spike: Add '/chosen/stdout-path' in device tree unconditionally
From: Bin Meng <[email protected]>
At present the adding '/chosen/stdout-path' property in device tree is determined by whether a kernel command line is provided, which is wrong. It should be added unconditionally.
Message-Id: <[email protected]>
--- hw/riscv/spike.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
hw/riscv/spike.c +3 -2
@@ -174,10 +174,11 @@ static void create_fdt(SpikeState *s, const MemMapEntry *memmap,riscv_socket_fdt_write_distance_matrix (mc, fdt); +qemu_fdt_add_subnode (fdt,"/chosen" ); +qemu_fdt_setprop_string (fdt,"/chosen" ,"stdout-path" ,"/htif" ); +if (cmdline) { -qemu_fdt_add_subnode (fdt,"/chosen" );qemu_fdt_setprop_string (fdt,"/chosen" ,"bootargs" , cmdline); -qemu_fdt_setprop_string (fdt,"/chosen" ,"stdout-path" ,"/htif" ); } }
Signature · 1 line
2.35.1
[PULL 03/25] target/riscv: Support configuarable marchid, mvendorid, mipid CSR values
In reply to Alistair FrancisFrom: Frank Chang <[email protected]>
Allow user to set core's marchid, mvendorid, mipid CSRs through -cpu command line option.
The default values of marchid and mipid are built with QEMU's version numbers.
Message-Id: <[email protected]>
--- target/riscv/cpu.h | 4 ++++ target/riscv/cpu.c | 9 +++++++++ target/riscv/csr.c | 38 ++++++++++++++++++++++++++++++++++---- 3 files changed, 47 insertions(+), 4 deletions(-)
target/riscv/cpu.h +4 -0
@@ -393,6 +393,10 @@ struct RISCVCPUConfig {bool ext_zve32f;bool ext_zve64f; +uint32_t mvendorid; +uint64_t marchid; +uint64_t mipid; +/* Vendor-specific custom extensions */ bool ext_XVentanaCondOps;
target/riscv/cpu.c +9 -0
@@ -34,6 +34,11 @@/* RISC-V CPU definitions */ +#define RISCV_CPU_MARCHID ((QEMU_VERSION_MAJOR << 16) | \ + (QEMU_VERSION_MINOR << 8) | \ + (QEMU_VERSION_MICRO)) +#define RISCV_CPU_MIPID RISCV_CPU_MARCHID +static const char riscv_single_letter_exts[] ="IEMAFDQCPVH" ;struct isa_ext_data {
@@ -810,6 +815,10 @@ static Property riscv_cpu_properties[] = {DEFINE_PROP_UINT16 ("vlen" ,RISCVCPU , cfg.vlen,128 ),DEFINE_PROP_UINT16 ("elen" ,RISCVCPU , cfg.elen,64 ), +DEFINE_PROP_UINT32 ("mvendorid" ,RISCVCPU , cfg.mvendorid,0 ), +DEFINE_PROP_UINT64 ("marchid" ,RISCVCPU , cfg.marchid,RISCV_CPU_MARCHID ), +DEFINE_PROP_UINT64 ("mipid" ,RISCVCPU , cfg.mipid,RISCV_CPU_MIPID ), +DEFINE_PROP_BOOL ("svinval" ,RISCVCPU , cfg.ext_svinval, false),DEFINE_PROP_BOOL ("svnapot" ,RISCVCPU , cfg.ext_svnapot, false), DEFINE_PROP_BOOL("svpbmt", RISCVCPU, cfg.ext_svpbmt, false),
target/riscv/csr.c +34 -4
@@ -612,6 +612,36 @@ static RISCVException write_ignore(CPURISCVState *env, int csrno,return RISCV_EXCP_NONE ; } +static RISCVException read_mvendorid (CPURISCVState *env,int csrno, +target_ulong *val) +{ +CPUState *cs =env_cpu (env); +RISCVCPU *cpu =RISCV_CPU (cs); + + *val = cpu->cfg.mvendorid; +return RISCV_EXCP_NONE ; +} + +static RISCVException read_marchid (CPURISCVState *env,int csrno, +target_ulong *val) +{ +CPUState *cs =env_cpu (env); +RISCVCPU *cpu =RISCV_CPU (cs); + + *val = cpu->cfg.marchid; +return RISCV_EXCP_NONE ; +} + +static RISCVException read_mipid (CPURISCVState *env,int csrno, +target_ulong *val) +{ +CPUState *cs =env_cpu (env); +RISCVCPU *cpu =RISCV_CPU (cs); + + *val = cpu->cfg.mipid; +return RISCV_EXCP_NONE ; +} +static RISCVException read_mhartid (CPURISCVState *env,int csrno,target_ulong *val) {
@@ -3260,10 +3290,10 @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = { [CSR_MINSTRETH] = { "minstreth", any32, read_instreth }, /* Machine Information Registers */ - [CSR_MVENDORID] = { "mvendorid", any, read_zero }, - [CSR_MARCHID] = { "marchid", any, read_zero }, - [CSR_MIMPID] = { "mimpid", any, read_zero }, - [CSR_MHARTID] = { "mhartid", any, read_mhartid }, + [CSR_MVENDORID] = { "mvendorid", any, read_mvendorid }, + [CSR_MARCHID] = { "marchid", any, read_marchid }, + [CSR_MIMPID] = { "mimpid", any, read_mipid }, + [CSR_MHARTID] = { "mhartid", any, read_mhartid }, [CSR_MCONFIGPTR] = { "mconfigptr", any, read_zero, .min_priv_ver = PRIV_VERSION_1_12_0 },
Signature · 1 line
2.35.1
[PULL 04/25] target/riscv: rvk: add cfg properties for zbk* and zk*
In reply to Alistair FrancisFrom: Weiwei Li <[email protected]>
Message-Id: <[email protected]>
--- target/riscv/cpu.h | 13 +++++++++++++ target/riscv/cpu.c | 23 +++++++++++++++++++++++ 2 files changed, 36 insertions(+)
target/riscv/cpu.h +13 -0
@@ -377,7 +377,20 @@ struct RISCVCPUConfig {bool ext_zba;bool ext_zbb;bool ext_zbc; +bool ext_zbkb; +bool ext_zbkc; +bool ext_zbkx;bool ext_zbs; +bool ext_zk; +bool ext_zkn; +bool ext_zknd; +bool ext_zkne; +bool ext_zknh; +bool ext_zkr; +bool ext_zks; +bool ext_zksed; +bool ext_zksh; +bool ext_zkt;bool ext_counters;bool ext_ifencei;bool ext_icsr;
target/riscv/cpu.c +23 -0
@@ -612,6 +612,29 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) cpu->cfg.ext_zfinx = true; } +if (cpu->cfg.ext_zk) { + cpu->cfg.ext_zkn = true; + cpu->cfg.ext_zkr = true; + cpu->cfg.ext_zkt = true; + } + +if (cpu->cfg.ext_zkn) { + cpu->cfg.ext_zbkb = true; + cpu->cfg.ext_zbkc = true; + cpu->cfg.ext_zbkx = true; + cpu->cfg.ext_zkne = true; + cpu->cfg.ext_zknd = true; + cpu->cfg.ext_zknh = true; + } + +if (cpu->cfg.ext_zks) { + cpu->cfg.ext_zbkb = true; + cpu->cfg.ext_zbkc = true; + cpu->cfg.ext_zbkx = true; + cpu->cfg.ext_zksed = true; + cpu->cfg.ext_zksh = true; + } +/* Set the ISA extensions, checks should have happened above */ if (cpu->cfg.ext_i) { ext |=RVI ;
Signature · 1 line
2.35.1
[PULL 02/25] hw/riscv: Don't add empty bootargs to device tree
In reply to Alistair FrancisFrom: Bin Meng <[email protected]>
Commit 7c28f4da20e5 ("RISC-V: Don't add NULL bootargs to device-tree") tried to avoid adding *NULL* bootargs to device tree, but unfortunately the changes were entirely useless, due to MachineState::kernel_cmdline can't be NULL at all as the default value is given as an empty string. (see hw/core/machine.c::machine_initfn()).
Note the wording of *NULL* bootargs is wrong. It can't be NULL otherwise a segfault had already been observed by dereferencing the NULL pointer. It should be worded as *empty" bootargs.
Message-Id: <[email protected]>
--- hw/riscv/microchip_pfsoc.c | 2 +- hw/riscv/sifive_u.c | 2 +- hw/riscv/spike.c | 2 +- hw/riscv/virt.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-)
hw/riscv/microchip_pfsoc.c +1 -1
@@ -571,7 +571,7 @@ static void microchip_icicle_kit_machine_init(MachineState *machine) "linux,initrd-end", end); } -if (machine->kernel_cmdline) { +if (machine->kernel_cmdline && *machine->kernel_cmdline) {qemu_fdt_setprop_string (machine->fdt,"/chosen" ,"bootargs" , machine->kernel_cmdline); }
hw/riscv/sifive_u.c +1 -1
@@ -511,7 +511,7 @@ static void create_fdt(SiFiveUState *s, const MemMapEntry *memmap,g_free (nodename); update_bootargs: -if (cmdline) { +if (cmdline && *cmdline) {qemu_fdt_setprop_string (fdt,"/chosen" ,"bootargs" , cmdline); } }
hw/riscv/spike.c +1 -1
@@ -177,7 +177,7 @@ static void create_fdt(SpikeState *s, const MemMapEntry *memmap,qemu_fdt_add_subnode (fdt,"/chosen" );qemu_fdt_setprop_string (fdt,"/chosen" ,"stdout-path" ,"/htif" ); -if (cmdline) { +if (cmdline && *cmdline) {qemu_fdt_setprop_string (fdt,"/chosen" ,"bootargs" , cmdline); } }
hw/riscv/virt.c +1 -1
@@ -1004,7 +1004,7 @@ static void create_fdt(RISCVVirtState *s, const MemMapEntry *memmap,create_fdt_flash (s, memmap); update_bootargs: -if (cmdline) { +if (cmdline && *cmdline) {qemu_fdt_setprop_string (mc->fdt,"/chosen" ,"bootargs" , cmdline); } }
Signature · 1 line
2.35.1
[PULL 05/25] target/riscv: rvk: add support for zbkb extension
In reply to Alistair FrancisFrom: Weiwei Li <[email protected]>
- reuse partial instructions of zbb extension, update extension check for them
- add brev8, pack, packh, packw, unzip, zip instructions
Message-Id: <[email protected]>
--- target/riscv/helper.h | 3 + target/riscv/insn32.decode | 45 +++++++----- target/riscv/bitmanip_helper.c | 53 ++++++++++++++ target/riscv/translate.c | 7 ++ target/riscv/insn_trans/trans_rvb.c.inc | 94 +++++++++++++++++++++---- 5 files changed, 174 insertions(+), 28 deletions(-)
target/riscv/helper.h +3 -0
@@ -66,6 +66,9 @@ DEF_HELPER_FLAGS_1(fclass_d, TCG_CALL_NO_RWG_SE, tl, i64)/* Bitmanip */ DEF_HELPER_FLAGS_2(clmul, TCG_CALL_NO_RWG_SE, tl, tl, tl) DEF_HELPER_FLAGS_2(clmulr, TCG_CALL_NO_RWG_SE, tl, tl, tl) +DEF_HELPER_FLAGS_1(brev8, TCG_CALL_NO_RWG_SE, tl, tl) +DEF_HELPER_FLAGS_1(unzip, TCG_CALL_NO_RWG_SE, tl, tl) +DEF_HELPER_FLAGS_1 (zip,TCG_CALL_NO_RWG_SE , tl, tl) /* Floating Point - Half Precision */DEF_HELPER_FLAGS_3 (fadd_h,TCG_CALL_NO_RWG , i64, env, i64, i64)
target/riscv/insn32.decode +29 -16
67 lines not on this page · raw message
target/riscv/bitmanip_helper.c +53 -0
56 lines not on this page · raw message
target/riscv/translate.c +7 -0
@@ -688,6 +688,13 @@ EX_SH(12) } \ } while (0) +#define REQUIRE_EITHER_EXT (ctx,A ,B ) do { \ + if (!ctx->cfg_ptr->ext_##A && \ + !ctx->cfg_ptr->ext_##B) { \ + return false; \ + } \ +} while (0) +static int ex_rvc_register (DisasContext *ctx,int reg) {return 8 + reg;
target/riscv/insn_trans/trans_rvb.c.inc +82 -12
171 lines not on this page · raw message
Signature · 1 line
2.35.1
[PULL 06/25] target/riscv: rvk: add support for zbkc extension
In reply to Alistair FrancisFrom: Weiwei Li <[email protected]>
- reuse partial instructions of zbc extension, update extension check for them
Message-Id: <[email protected]>
--- target/riscv/insn32.decode | 3 ++- target/riscv/insn_trans/trans_rvb.c.inc | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-)
target/riscv/insn32.decode +2 -1
@@ -770,9 +770,10 @@ clzw 0110000 00000 ..... 001 ..... 0011011 @r2 ctzw 0110000 00001 ..... 001 ..... 0011011 @r2 cpopw 0110000 00010 ..... 001 ..... 0011011 @r2 -# *** RV32 Zbc Standard Extension *** +# *** RV32 Zbc/Zbkc Standard Extension *** clmul 0000101 .......... 001 ..... 0110011 @r clmulh 0000101 .......... 011 ..... 0110011 @r +# *** RV32 extra Zbc Standard Extension *** clmulr 0000101 .......... 010 ..... 0110011 @r # *** RV32 Zbs Standard Extension ***
target/riscv/insn_trans/trans_rvb.c.inc +2 -2
@@ -489,7 +489,7 @@ static bool trans_slli_uw(DisasContext *ctx, arg_slli_uw *a) static bool trans_clmul(DisasContext *ctx, arg_clmul *a) { - REQUIRE_ZBC(ctx); + REQUIRE_EITHER_EXT(ctx, zbc, zbkc); return gen_arith(ctx, a, EXT_NONE, gen_helper_clmul, NULL); }
@@ -501,7 +501,7 @@ static void gen_clmulh(TCGv dst, TCGv src1, TCGv src2) static bool trans_clmulh(DisasContext *ctx, arg_clmulr *a) { - REQUIRE_ZBC(ctx); + REQUIRE_EITHER_EXT(ctx, zbc, zbkc); return gen_arith(ctx, a, EXT_NONE, gen_clmulh, NULL); }
Signature · 1 line
2.35.1
[PULL 20/25] hw/riscv: virt: Add a machine done notifier
In reply to Alistair FrancisFrom: Alistair Francis <[email protected]>
Move the binary and device tree loading code to the machine done notifier. This allows us to prepare for editing the device tree as part of the notifier.
This is based on similar code in the ARM virt machine.
Message-Id: <[email protected]>
--- include/hw/riscv/virt.h | 1 + hw/riscv/virt.c | 191 +++++++++++++++++++++------------------- 2 files changed, 102 insertions(+), 90 deletions(-)
include/hw/riscv/virt.h +1 -0
@@ -45,6 +45,7 @@ struct RISCVVirtState {MachineState parent;/*< public >*/ +Notifier machine_done;RISCVHartArrayState soc[VIRT_SOCKETS_MAX ];DeviceState *irqchip[VIRT_SOCKETS_MAX ];PFlashCFI01 *flash[2 ];
hw/riscv/virt.c +101 -90
221 lines not on this page · raw message
Signature · 1 line
2.35.1
[PULL 09/25] target/riscv: rvk: add support for zknd/zkne extension in RV32
In reply to Alistair FrancisFrom: Weiwei Li <[email protected]>
- add aes32esmi, aes32esi, aes32dsmi and aes32dsi instructions
Message-Id: <[email protected]>
--- target/riscv/helper.h | 6 ++ target/riscv/insn32.decode | 11 +++ target/riscv/crypto_helper.c | 105 ++++++++++++++++++++++++ target/riscv/translate.c | 1 + target/riscv/insn_trans/trans_rvk.c.inc | 71 ++++++++++++++++ target/riscv/meson.build | 3 +- 6 files changed, 196 insertions(+), 1 deletion(-) create mode 100644 target/riscv/crypto_helper.c create mode 100644 target/riscv/insn_trans/trans_rvk.c.inc
target/riscv/helper.h +6 -0
@@ -1112,3 +1112,9 @@ DEF_HELPER_5(divu_i128, tl, env, tl, tl, tl, tl) DEF_HELPER_5(divs_i128, tl, env, tl, tl, tl, tl) DEF_HELPER_5(remu_i128, tl, env, tl, tl, tl, tl)DEF_HELPER_5 (rems_i128, tl, env, tl, tl, tl, tl) + +/* Crypto functions */ +DEF_HELPER_FLAGS_3(aes32esmi, TCG_CALL_NO_RWG_SE, tl, tl, tl, tl) +DEF_HELPER_FLAGS_3(aes32esi, TCG_CALL_NO_RWG_SE, tl, tl, tl, tl) +DEF_HELPER_FLAGS_3(aes32dsmi, TCG_CALL_NO_RWG_SE, tl, tl, tl, tl) +DEF_HELPER_FLAGS_3 (aes32dsi,TCG_CALL_NO_RWG_SE , tl, tl, tl, tl)
target/riscv/insn32.decode +11 -0
@@ -35,6 +35,7 @@ %imm_b 31:s1 7:1 25:6 8:4 !function=ex_shift_1 %imm_j 31:s1 12:8 20:1 21:10 !function=ex_shift_1 %imm_u 12:s20 !function=ex_shift_12 +%imm_bs 30:2 !function=ex_shift_3 # Argument sets: &empty
@@ -52,6 +53,7 @@ &rmr vm rd rs2 &r2nfvm vm rd rs1 nf &rnfvm vm rd rs1 rs2 nf +&k_aes shamt rs2 rs1 rd # Formats 32: @r ....... ..... ..... ... ..... ....... &r %rs2 %rs1 %rd
@@ -89,6 +91,8 @@ @sfence_vma ....... ..... ..... ... ..... ....... %rs2 %rs1 @sfence_vm ....... ..... ..... ... ..... ....... %rs1 +@k_aes .. ..... ..... ..... ... ..... ....... &k_aes shamt=%imm_bs %rs2 %rs1 %rd + # Formats 64: @sh5 ....... ..... ..... ... ..... ....... &shift shamt=%sh5 %rs1 %rd
@@ -834,3 +838,10 @@ sfence_w_inval 0001100 00000 00000 000 00000 1110011 sfence_inval_ir 0001100 00001 00000 000 00000 1110011 hinval_vvma 0010011 ..... ..... 000 00000 1110011 @hfence_vvma hinval_gvma 0110011 ..... ..... 000 00000 1110011 @hfence_gvma + +# *** RV32 Zknd Standard Extension *** +aes32dsmi .. 10111 ..... ..... 000 ..... 0110011 @k_aes +aes32dsi .. 10101 ..... ..... 000 ..... 0110011 @k_aes +# *** RV32 Zkne Standard Extension *** +aes32esmi .. 10011 ..... ..... 000 ..... 0110011 @k_aes +aes32esi .. 10001 ..... ..... 000 ..... 0110011 @k_aes
target/riscv/crypto_helper.c new file +105 -0
105 lines not on this page · raw message
target/riscv/translate.c +1 -0
@@ -1007,6 +1007,7 @@ static uint32_t opcode_at(DisasContextBase *dcbase, target_ulong pc)#include "insn_trans/trans_rvv.c.inc" #include "insn_trans/trans_rvb.c.inc" #include "insn_trans/trans_rvzfh.c.inc" +#include "insn_trans/trans_rvk.c.inc" #include "insn_trans/trans_privileged.c.inc" #include "insn_trans/trans_svinval.c.inc" #include "insn_trans/trans_xventanacondops.c.inc"
target/riscv/insn_trans/trans_rvk.c.inc new file +71 -0
71 lines not on this page · raw message
target/riscv/meson.build +2 -1
@@ -19,7 +19,8 @@ riscv_ss.add(files( 'vector_helper.c', 'bitmanip_helper.c', 'translate.c', - 'm128_helper.c' + 'm128_helper.c', + 'crypto_helper.c' )) riscv_ss.add(when: 'CONFIG_KVM', if_true: files('kvm.c'), if_false: files('kvm-stub.c'))
Signature · 1 line
2.35.1
[PULL 07/25] target/riscv: rvk: add support for zbkx extension
In reply to Alistair FrancisFrom: Weiwei Li <[email protected]>
- add xperm4 and xperm8 instructions
Message-Id: <[email protected]>
--- target/riscv/helper.h | 2 ++ target/riscv/insn32.decode | 4 ++++ target/riscv/bitmanip_helper.c | 27 +++++++++++++++++++++++++ target/riscv/insn_trans/trans_rvb.c.inc | 18 +++++++++++++++++ 4 files changed, 51 insertions(+)
target/riscv/helper.h +2 -0
@@ -69,6 +69,8 @@ DEF_HELPER_FLAGS_2(clmulr, TCG_CALL_NO_RWG_SE, tl, tl, tl) DEF_HELPER_FLAGS_1(brev8, TCG_CALL_NO_RWG_SE, tl, tl) DEF_HELPER_FLAGS_1(unzip, TCG_CALL_NO_RWG_SE, tl, tl) DEF_HELPER_FLAGS_1(zip, TCG_CALL_NO_RWG_SE, tl, tl) +DEF_HELPER_FLAGS_2(xperm4, TCG_CALL_NO_RWG_SE, tl, tl, tl) +DEF_HELPER_FLAGS_2 (xperm8,TCG_CALL_NO_RWG_SE , tl, tl, tl) /* Floating Point - Half Precision */DEF_HELPER_FLAGS_3 (fadd_h,TCG_CALL_NO_RWG , i64, env, i64, i64)
target/riscv/insn32.decode +4 -0
@@ -776,6 +776,10 @@ clmulh 0000101 .......... 011 ..... 0110011 @r # *** RV32 extra Zbc Standard Extension *** clmulr 0000101 .......... 010 ..... 0110011 @r +# *** RV32 Zbkx Standard Extension *** +xperm4 0010100 .......... 010 ..... 0110011 @r +xperm8 0010100 .......... 100 ..... 0110011 @r + # *** RV32 Zbs Standard Extension *** bclr 0100100 .......... 001 ..... 0110011 @r bclri 01001. ........... 001 ..... 0010011 @sh
target/riscv/bitmanip_helper.c +27 -0
@@ -102,3 +102,30 @@ target_ulong HELPER(zip)(target_ulong rs1) x =do_shuf_stage (x, shuf_masks[0 ], shuf_masks[0 ] >>1 ,1 );return x; } + +static inline target_ulong do_xperm (target_ulong rs1,target_ulong rs2, +uint32_t sz_log2) +{ +target_ulong r =0 ; +target_ulong sz =1LL << sz_log2; +target_ulong mask = (1LL << sz) -1 ; +target_ulong pos; + +for (int i =0 ; i <TARGET_LONG_BITS ; i += sz) { + pos = ((rs2 >> i) & mask) << sz_log2; +if (pos <sizeof (target_ulong) *8 ) { + r |= ((rs1 >> pos) & mask) << i; + } + } +return r; +} + +target_ulong HELPER (xperm4 )(target_ulong rs1,target_ulong rs2) +{ +return do_xperm (rs1, rs2,2 ); +} + +target_ulong HELPER (xperm8 )(target_ulong rs1,target_ulong rs2) +{ +return do_xperm (rs1, rs2,3 ); +}
target/riscv/insn_trans/trans_rvb.c.inc +18 -0
@@ -48,6 +48,12 @@ } \ } while (0) +#define REQUIRE_ZBKX(ctx) do { \ + if (!ctx->cfg_ptr->ext_zbkx) { \ + return false; \ + } \ +} while (0) + static void gen_clz(TCGv ret, TCGv arg1) { tcg_gen_clzi_tl(ret, arg1, TARGET_LONG_BITS);
@@ -574,3 +580,15 @@ static bool trans_zip(DisasContext *ctx, arg_zip *a) REQUIRE_ZBKB(ctx); return gen_unary(ctx, a, EXT_NONE, gen_helper_zip); } + +static bool trans_xperm4(DisasContext *ctx, arg_xperm4 *a) +{ + REQUIRE_ZBKX(ctx); + return gen_arith(ctx, a, EXT_NONE, gen_helper_xperm4, NULL); +} + +static bool trans_xperm8(DisasContext *ctx, arg_xperm8 *a) +{ + REQUIRE_ZBKX(ctx); + return gen_arith(ctx, a, EXT_NONE, gen_helper_xperm8, NULL); +}
Signature · 1 line
2.35.1
[PULL 11/25] target/riscv: rvk: add support for sha256 related instructions in zknh extension
In reply to Alistair FrancisFrom: Weiwei Li <[email protected]>
- add sha256sig0, sha256sig1, sha256sum0 and sha256sum1 instructions
Message-Id: <[email protected]>
--- target/riscv/insn32.decode | 5 +++ target/riscv/insn_trans/trans_rvk.c.inc | 55 +++++++++++++++++++++++++ 2 files changed, 60 insertions(+)
target/riscv/insn32.decode +5 -0
@@ -857,3 +857,8 @@ aes64esm 00 11011 ..... ..... 000 ..... 0110011 @r # *** RV64 Zkne/zknd Standard Extension *** aes64ks2 01 11111 ..... ..... 000 ..... 0110011 @r aes64ks1i 00 11000 1.... ..... 001 ..... 0010011 @i_aes +# *** RV32 Zknh Standard Extension *** +sha256sig0 00 01000 00010 ..... 001 ..... 0010011 @r2 +sha256sig1 00 01000 00011 ..... 001 ..... 0010011 @r2 +sha256sum0 00 01000 00000 ..... 001 ..... 0010011 @r2 +sha256sum1 00 01000 00001 ..... 001 ..... 0010011 @r2
target/riscv/insn_trans/trans_rvk.c.inc +55 -0
64 lines not on this page · raw message
Signature · 1 line
2.35.1
[PULL 10/25] target/riscv: rvk: add support for zkne/zknd extension in RV64
In reply to Alistair FrancisFrom: Weiwei Li <[email protected]>
- add aes64dsm, aes64ds, aes64im, aes64es, aes64esm, aes64ks2, aes64ks1i instructions
Message-Id: <[email protected]>
--- target/riscv/helper.h | 8 ++ target/riscv/insn32.decode | 12 ++ target/riscv/crypto_helper.c | 169 ++++++++++++++++++++++++ target/riscv/insn_trans/trans_rvk.c.inc | 54 ++++++++ 4 files changed, 243 insertions(+)
target/riscv/helper.h +8 -0
@@ -1118,3 +1118,11 @@ DEF_HELPER_FLAGS_3(aes32esmi, TCG_CALL_NO_RWG_SE, tl, tl, tl, tl) DEF_HELPER_FLAGS_3(aes32esi, TCG_CALL_NO_RWG_SE, tl, tl, tl, tl) DEF_HELPER_FLAGS_3(aes32dsmi, TCG_CALL_NO_RWG_SE, tl, tl, tl, tl) DEF_HELPER_FLAGS_3(aes32dsi, TCG_CALL_NO_RWG_SE, tl, tl, tl, tl) + +DEF_HELPER_FLAGS_2(aes64esm, TCG_CALL_NO_RWG_SE, tl, tl, tl) +DEF_HELPER_FLAGS_2(aes64es, TCG_CALL_NO_RWG_SE, tl, tl, tl) +DEF_HELPER_FLAGS_2(aes64ds, TCG_CALL_NO_RWG_SE, tl, tl, tl) +DEF_HELPER_FLAGS_2(aes64dsm, TCG_CALL_NO_RWG_SE, tl, tl, tl) +DEF_HELPER_FLAGS_2(aes64ks2, TCG_CALL_NO_RWG_SE, tl, tl, tl) +DEF_HELPER_FLAGS_2(aes64ks1i, TCG_CALL_NO_RWG_SE, tl, tl, tl) +DEF_HELPER_FLAGS_1 (aes64im,TCG_CALL_NO_RWG_SE , tl, tl)
target/riscv/insn32.decode +12 -0
@@ -36,6 +36,7 @@ %imm_j 31:s1 12:8 20:1 21:10 !function=ex_shift_1 %imm_u 12:s20 !function=ex_shift_12 %imm_bs 30:2 !function=ex_shift_3 +%imm_rnum 20:4 # Argument sets: &empty
@@ -92,6 +93,7 @@ @sfence_vm ....... ..... ..... ... ..... ....... %rs1 @k_aes .. ..... ..... ..... ... ..... ....... &k_aes shamt=%imm_bs %rs2 %rs1 %rd +@i_aes .. ..... ..... ..... ... ..... ....... &i imm=%imm_rnum %rs1 %rd # Formats 64: @sh5 ....... ..... ..... ... ..... ....... &shift shamt=%sh5 %rs1 %rd
@@ -842,6 +844,16 @@ hinval_gvma 0110011 ..... ..... 000 00000 1110011 @hfence_gvma # *** RV32 Zknd Standard Extension *** aes32dsmi .. 10111 ..... ..... 000 ..... 0110011 @k_aes aes32dsi .. 10101 ..... ..... 000 ..... 0110011 @k_aes +# *** RV64 Zknd Standard Extension *** +aes64dsm 00 11111 ..... ..... 000 ..... 0110011 @r +aes64ds 00 11101 ..... ..... 000 ..... 0110011 @r +aes64im 00 11000 00000 ..... 001 ..... 0010011 @r2 # *** RV32 Zkne Standard Extension *** aes32esmi .. 10011 ..... ..... 000 ..... 0110011 @k_aes aes32esi .. 10001 ..... ..... 000 ..... 0110011 @k_aes +# *** RV64 Zkne Standard Extension *** +aes64es 00 11001 ..... ..... 000 ..... 0110011 @r +aes64esm 00 11011 ..... ..... 000 ..... 0110011 @r +# *** RV64 Zkne/zknd Standard Extension *** +aes64ks2 01 11111 ..... ..... 000 ..... 0110011 @r +aes64ks1i 00 11000 1.... ..... 001 ..... 0010011 @i_aes
target/riscv/crypto_helper.c +169 -0
173 lines not on this page · raw message
target/riscv/insn_trans/trans_rvk.c.inc +54 -0
57 lines not on this page · raw message
Signature · 1 line
2.35.1
[PULL 08/25] crypto: move sm4_sbox from target/arm
In reply to Alistair FrancisFrom: Weiwei Li <[email protected]>
- share it between target/arm and target/riscv
Message-Id: <[email protected]>
--- include/crypto/sm4.h | 6 +++++ crypto/sm4.c | 49 ++++++++++++++++++++++++++++++++++++++ target/arm/crypto_helper.c | 36 +--------------------------- crypto/meson.build | 1 + 4 files changed, 57 insertions(+), 35 deletions(-) create mode 100644 include/crypto/sm4.h create mode 100644 crypto/sm4.c
include/crypto/sm4.h new file +6 -0
@@ -0,0 +1,6 @@ +#ifndef QEMU_SM4_H +#define QEMU_SM4_H + +extern const uint8_t sm4_sbox[256 ]; + +#endif
crypto/sm4.c new file +49 -0
49 lines not on this page · raw message
target/arm/crypto_helper.c +1 -35
@@ -15,6 +15,7 @@#include "exec/helper-proto.h" #include "tcg/tcg-gvec-desc.h" #include "crypto/aes.h" +#include "crypto/sm4.h" #include "vec_internal.h" union CRYPTO_STATE {
@@ -694,41 +695,6 @@ DO_SM3TT(crypto_sm3tt2b, 3)#undef DO_SM3TT -static uint8_t const sm4_sbox[] = { -0xd6 ,0x90 ,0xe9 ,0xfe ,0xcc ,0xe1 ,0x3d ,0xb7 , -0x16 ,0xb6 ,0x14 ,0xc2 ,0x28 ,0xfb ,0x2c ,0x05 , -0x2b ,0x67 ,0x9a ,0x76 ,0x2a ,0xbe ,0x04 ,0xc3 , -0xaa ,0x44 ,0x13 ,0x26 ,0x49 ,0x86 ,0x06 ,0x99 , -0x9c ,0x42 ,0x50 ,0xf4 ,0x91 ,0xef ,0x98 ,0x7a , -0x33 ,0x54 ,0x0b ,0x43 ,0xed ,0xcf ,0xac ,0x62 , -0xe4 ,0xb3 ,0x1c ,0xa9 ,0xc9 ,0x08 ,0xe8 ,0x95 , -0x80 ,0xdf ,0x94 ,0xfa ,0x75 ,0x8f ,0x3f ,0xa6 , -0x47 ,0x07 ,0xa7 ,0xfc ,0xf3 ,0x73 ,0x17 ,0xba , -0x83 ,0x59 ,0x3c ,0x19 ,0xe6 ,0x85 ,0x4f ,0xa8 , -0x68 ,0x6b ,0x81 ,0xb2 ,0x71 ,0x64 ,0xda ,0x8b , -0xf8 ,0xeb ,0x0f ,0x4b ,0x70 ,0x56 ,0x9d ,0x35 , -0x1e ,0x24 ,0x0e ,0x5e ,0x63 ,0x58 ,0xd1 ,0xa2 , -0x25 ,0x22 ,0x7c ,0x3b ,0x01 ,0x21 ,0x78 ,0x87 , -0xd4 ,0x00 ,0x46 ,0x57 ,0x9f ,0xd3 ,0x27 ,0x52 , -0x4c ,0x36 ,0x02 ,0xe7 ,0xa0 ,0xc4 ,0xc8 ,0x9e , -0xea ,0xbf ,0x8a ,0xd2 ,0x40 ,0xc7 ,0x38 ,0xb5 , -0xa3 ,0xf7 ,0xf2 ,0xce ,0xf9 ,0x61 ,0x15 ,0xa1 , -0xe0 ,0xae ,0x5d ,0xa4 ,0x9b ,0x34 ,0x1a ,0x55 , -0xad ,0x93 ,0x32 ,0x30 ,0xf5 ,0x8c ,0xb1 ,0xe3 , -0x1d ,0xf6 ,0xe2 ,0x2e ,0x82 ,0x66 ,0xca ,0x60 , -0xc0 ,0x29 ,0x23 ,0xab ,0x0d ,0x53 ,0x4e ,0x6f , -0xd5 ,0xdb ,0x37 ,0x45 ,0xde ,0xfd ,0x8e ,0x2f , -0x03 ,0xff ,0x6a ,0x72 ,0x6d ,0x6c ,0x5b ,0x51 , -0x8d ,0x1b ,0xaf ,0x92 ,0xbb ,0xdd ,0xbc ,0x7f , -0x11 ,0xd9 ,0x5c ,0x41 ,0x1f ,0x10 ,0x5a ,0xd8 , -0x0a ,0xc1 ,0x31 ,0x88 ,0xa5 ,0xcd ,0x7b ,0xbd , -0x2d ,0x74 ,0xd0 ,0x12 ,0xb8 ,0xe5 ,0xb4 ,0xb0 , -0x89 ,0x69 ,0x97 ,0x4a ,0x0c ,0x96 ,0x77 ,0x7e , -0x65 ,0xb9 ,0xf1 ,0x09 ,0xc5 ,0x6e ,0xc6 ,0x84 , -0x18 ,0xf0 ,0x7d ,0xec ,0x3a ,0xdc ,0x4d ,0x20 , -0x79 ,0xee ,0x5f ,0x3e ,0xd7 ,0xcb ,0x39 ,0x48 , -}; -static void do_crypto_sm4e (uint64_t *rd,uint64_t *rn,uint64_t *rm) {union CRYPTO_STATE d = { .l = { rn[0 ], rn[1 ] } };
crypto/meson.build +1 -0
@@ -42,6 +42,7 @@ if have_afalg endif crypto_ss.add(when: gnutls, if_true: files('tls-cipher-suites.c')) +util_ss.add(files('sm4.c')) util_ss.add(files('aes.c')) util_ss.add(files('init.c')) if gnutls.found()
Signature · 1 line
2.35.1
[PULL 13/25] target/riscv: rvk: add support for sha512 related instructions for RV64 in zknh extension
In reply to Alistair FrancisFrom: Weiwei Li <[email protected]>
- add sha512sum0, sha512sig0, sha512sum1 and sha512sig1 instructions
Message-Id: <[email protected]>
--- target/riscv/insn32.decode | 5 +++ target/riscv/insn_trans/trans_rvk.c.inc | 53 +++++++++++++++++++++++++ 2 files changed, 58 insertions(+)
target/riscv/insn32.decode +5 -0
@@ -868,3 +868,8 @@ sha512sig0l 01 01010 ..... ..... 000 ..... 0110011 @r sha512sig0h 01 01110 ..... ..... 000 ..... 0110011 @r sha512sig1l 01 01011 ..... ..... 000 ..... 0110011 @r sha512sig1h 01 01111 ..... ..... 000 ..... 0110011 @r +# *** RV64 Zknh Standard Extension *** +sha512sig0 00 01000 00110 ..... 001 ..... 0010011 @r2 +sha512sig1 00 01000 00111 ..... 001 ..... 0010011 @r2 +sha512sum0 00 01000 00100 ..... 001 ..... 0010011 @r2 +sha512sum1 00 01000 00101 ..... 001 ..... 0010011 @r2
target/riscv/insn_trans/trans_rvk.c.inc +53 -0
56 lines not on this page · raw message
Signature · 1 line
2.35.1
[PULL 14/25] target/riscv: rvk: add support for zksed/zksh extension
In reply to Alistair FrancisFrom: Weiwei Li <[email protected]>
- add sm3p0, sm3p1, sm4ed and sm4ks instructions
Message-Id: <[email protected]>
--- target/riscv/helper.h | 3 ++ target/riscv/insn32.decode | 6 +++ target/riscv/crypto_helper.c | 28 ++++++++++++ target/riscv/insn_trans/trans_rvk.c.inc | 58 +++++++++++++++++++++++++ 4 files changed, 95 insertions(+)
target/riscv/helper.h +3 -0
@@ -1126,3 +1126,6 @@ DEF_HELPER_FLAGS_2(aes64dsm, TCG_CALL_NO_RWG_SE, tl, tl, tl) DEF_HELPER_FLAGS_2(aes64ks2, TCG_CALL_NO_RWG_SE, tl, tl, tl) DEF_HELPER_FLAGS_2(aes64ks1i, TCG_CALL_NO_RWG_SE, tl, tl, tl) DEF_HELPER_FLAGS_1(aes64im, TCG_CALL_NO_RWG_SE, tl, tl) + +DEF_HELPER_FLAGS_3(sm4ed, TCG_CALL_NO_RWG_SE, tl, tl, tl, tl) +DEF_HELPER_FLAGS_3 (sm4ks,TCG_CALL_NO_RWG_SE , tl, tl, tl, tl)
target/riscv/insn32.decode +6 -0
@@ -873,3 +873,9 @@ sha512sig0 00 01000 00110 ..... 001 ..... 0010011 @r2 sha512sig1 00 01000 00111 ..... 001 ..... 0010011 @r2 sha512sum0 00 01000 00100 ..... 001 ..... 0010011 @r2 sha512sum1 00 01000 00101 ..... 001 ..... 0010011 @r2 +# *** RV32 Zksh Standard Extension *** +sm3p0 00 01000 01000 ..... 001 ..... 0010011 @r2 +sm3p1 00 01000 01001 ..... 001 ..... 0010011 @r2 +# *** RV32 Zksed Standard Extension *** +sm4ed .. 11000 ..... ..... 000 ..... 0110011 @k_aes +sm4ks .. 11010 ..... ..... 000 ..... 0110011 @k_aes
target/riscv/crypto_helper.c +28 -0
@@ -271,4 +271,32 @@ target_ulong HELPER(aes64im)(target_ulong rs1)return result; } + +target_ulong HELPER (sm4ed )(target_ulong rs1,target_ulong rs2, +target_ulong shamt) +{ +uint32_t sb_in = (uint8_t )(rs2 >> shamt); +uint32_t sb_out = (uint32_t )sm4_sbox[sb_in]; + +uint32_t x = sb_out ^ (sb_out <<8 ) ^ (sb_out <<2 ) ^ (sb_out <<18 ) ^ + ((sb_out &0x3f ) <<26 ) ^ ((sb_out &0xC0 ) <<10 ); + +uint32_t rotl =rol32 (x, shamt); + +return sext32_xlen (rotl ^ (uint32_t )rs1); +} + +target_ulong HELPER (sm4ks )(target_ulong rs1,target_ulong rs2, +target_ulong shamt) +{ +uint32_t sb_in = (uint8_t )(rs2 >> shamt); +uint32_t sb_out = sm4_sbox[sb_in]; + +uint32_t x = sb_out ^ ((sb_out &0x07 ) <<29 ) ^ ((sb_out &0xFE ) <<7 ) ^ + ((sb_out &0x01 ) <<23 ) ^ ((sb_out &0xF8 ) <<13 ); + +uint32_t rotl =rol32 (x, shamt); + +return sext32_xlen (rotl ^ (uint32_t )rs1); +}#undef sext32_xlen
target/riscv/insn_trans/trans_rvk.c.inc +58 -0
67 lines not on this page · raw message
Signature · 1 line
2.35.1
[PULL 12/25] target/riscv: rvk: add support for sha512 related instructions for RV32 in zknh extension
In reply to Alistair FrancisFrom: Weiwei Li <[email protected]>
- add sha512sum0r, sha512sig0l, sha512sum1r, sha512sig1l, sha512sig0h and sha512sig1h instructions
Message-Id: <[email protected]>
--- target/riscv/insn32.decode | 6 ++ target/riscv/insn_trans/trans_rvk.c.inc | 100 ++++++++++++++++++++++++ 2 files changed, 106 insertions(+)
target/riscv/insn32.decode +6 -0
@@ -862,3 +862,9 @@ sha256sig0 00 01000 00010 ..... 001 ..... 0010011 @r2 sha256sig1 00 01000 00011 ..... 001 ..... 0010011 @r2 sha256sum0 00 01000 00000 ..... 001 ..... 0010011 @r2 sha256sum1 00 01000 00001 ..... 001 ..... 0010011 @r2 +sha512sum0r 01 01000 ..... ..... 000 ..... 0110011 @r +sha512sum1r 01 01001 ..... ..... 000 ..... 0110011 @r +sha512sig0l 01 01010 ..... ..... 000 ..... 0110011 @r +sha512sig0h 01 01110 ..... ..... 000 ..... 0110011 @r +sha512sig1l 01 01011 ..... ..... 000 ..... 0110011 @r +sha512sig1h 01 01111 ..... ..... 000 ..... 0110011 @r
target/riscv/insn_trans/trans_rvk.c.inc +100 -0
103 lines not on this page · raw message
Signature · 1 line
2.35.1
[PULL 18/25] target/riscv: Fix incorrect PTE merge in walk_pte
In reply to Alistair FrancisFrom: Ralf Ramsauer <[email protected]>
Two non-subsequent PTEs can be mapped to subsequent paddrs. In this case, walk_pte will erroneously merge them.
Enforce the split up, by tracking the virtual base address.
Let's say we have the mapping:0x81200000 -> 0x89623000 (4K)0x8120f000 -> 0x89624000 (4K)
Before, walk_pte would have shown:
vaddr paddr size attr
---------------- ---------------- ---------------- ------- 0000000081200000 0000000089623000 0000000000002000 rwxu-ad
as it only checks for subsequent paddrs. With this patch, it becomes:
vaddr paddr size attr
---------------- ---------------- ---------------- ------- 0000000081200000 0000000089623000 0000000000001000 rwxu-ad 000000008120f000 0000000089624000 0000000000001000 rwxu-ad
Message-Id: <[email protected]>
--- target/riscv/monitor.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
target/riscv/monitor.c +7 -4
@@ -84,6 +84,7 @@ static void walk_pte(Monitor *mon, hwaddr base, target_ulong start, {hwaddr pte_addr;hwaddr paddr; +target_ulong last_start =-1 ;target_ulong pgsize;target_ulong pte;int ptshift;
@@ -111,12 +112,13 @@ static void walk_pte(Monitor *mon, hwaddr base, target_ulong start,* A leaf PTE has been found * * If current PTE's permission bits differ from the last one, -* or current PTE's ppn does not make a contiguous physical -* address block together with the last one, print out the last -* contiguous mapped block details. +* or the current PTE breaks up a contiguous virtual or +* physical mapping, address block together with the last one, +* print out the last contiguous mapped block details. */ if ((*last_attr != attr) || - (*last_paddr + *last_size != paddr)) { + (*last_paddr + *last_size != paddr) || + (last_start + *last_size != start)) {print_pte (mon, va_bits, *vbase, *pbase, *last_paddr + *last_size - *pbase, *last_attr);
@@ -125,6 +127,7 @@ static void walk_pte(Monitor *mon, hwaddr base, target_ulong start, *last_attr = attr; } + last_start = start; *last_paddr = paddr; *last_size = pgsize; }else {
Signature · 1 line
2.35.1
[PULL 15/25] target/riscv: rvk: add CSR support for Zkr
In reply to Alistair FrancisFrom: Weiwei Li <[email protected]>
- add SEED CSR which must be accessed with a read-write instruction:
A read-only instruction such as CSRRS/CSRRC with rs1=x0 or CSRRSI/CSRRCI
with uimm=0 will raise an illegal instruction exception.
- add USEED, SSEED fields for MSECCFG CSR
Message-Id: <[email protected]>
--- target/riscv/cpu_bits.h | 9 +++++ target/riscv/pmp.h | 8 ++-- target/riscv/csr.c | 80 ++++++++++++++++++++++++++++++++++++++++ target/riscv/op_helper.c | 9 +++++ 4 files changed, 103 insertions(+), 3 deletions(-)
target/riscv/cpu_bits.h +9 -0
@@ -458,6 +458,9 @@#define CSR_VSPMMASK 0x2c1#define CSR_VSPMBASE 0x2c2 +/* Crypto Extension */ +#define CSR_SEED 0x015 +/* mstatus CSR bits */ #define MSTATUS_UIE 0x00000001#define MSTATUS_SIE 0x00000002
@@ -800,4 +803,10 @@ typedef enum RISCVException {#define HVICTL_VALID_MASK \ (HVICTL_VTI | HVICTL_IID | HVICTL_IPRIOM | HVICTL_IPRIO) +/* seed CSR bits */ +#define SEED_OPST (0b11 << 30) +#define SEED_OPST_BIST (0b00 << 30) +#define SEED_OPST_WAIT (0b01 << 30) +#define SEED_OPST_ES16 (0b10 << 30) +#define SEED_OPST_DEAD (0b11 << 30)#endif
target/riscv/pmp.h +5 -3
@@ -39,9 +39,11 @@ typedef enum { } pmp_am_t;typedef enum { -MSECCFG_MML =1 <<0 , -MSECCFG_MMWP =1 <<1 , -MSECCFG_RLB =1 <<2 +MSECCFG_MML =1 <<0 , +MSECCFG_MMWP =1 <<1 , +MSECCFG_RLB =1 <<2 , +MSECCFG_USEED =1 <<8 , +MSECCFG_SSEED =1 <<9 }mseccfg_field_t ; typedef struct {
target/riscv/csr.c +80 -0
104 lines not on this page · raw message
target/riscv/op_helper.c +9 -0
@@ -39,6 +39,15 @@ void helper_raise_exception(CPURISCVState *env, uint32_t exception)target_ulong helper_csrr (CPURISCVState *env,int csr) { +/* +* The seed CSR must be accessed with a read-write instruction. A +* read-only instruction such as CSRRS/CSRRC with rs1=x0 or CSRRSI/ +* CSRRCI with uimm=0 will raise an illegal instruction exception. +*/ +if (csr ==CSR_SEED ) { +riscv_raise_exception (env,RISCV_EXCP_ILLEGAL_INST ,GETPC ()); + } +target_ulong val =0 ;RISCVException ret =riscv_csrrw (env, csr, &val,0 ,0 );
Signature · 1 line
2.35.1
[PULL 16/25] disas/riscv.c: rvk: add disas support for Zbk* and Zk* instructions
In reply to Alistair FrancisFrom: Weiwei Li <[email protected]>
Message-Id: <[email protected]>
--- disas/riscv.c | 173 +++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 172 insertions(+), 1 deletion(-)
disas/riscv.c +172 -1
@@ -156,6 +156,8 @@ typedef enum { rv_codec_css_swsp, rv_codec_css_sdsp, rv_codec_css_sqsp, + rv_codec_k_bs, + rv_codec_k_rnum, } rv_codec; typedef enum {
@@ -521,6 +523,43 @@ typedef enum { rv_op_bclr =359 , rv_op_binv =360 , rv_op_bext =361 , + rv_op_aes32esmi =362 , + rv_op_aes32esi =363 , + rv_op_aes32dsmi =364 , + rv_op_aes32dsi =365 , + rv_op_aes64ks1i =366 , + rv_op_aes64ks2 =367 , + rv_op_aes64im =368 , + rv_op_aes64esm =369 , + rv_op_aes64es =370 , + rv_op_aes64dsm =371 , + rv_op_aes64ds =372 , + rv_op_sha256sig0 =373 , + rv_op_sha256sig1 =374 , + rv_op_sha256sum0 =375 , + rv_op_sha256sum1 =376 , + rv_op_sha512sig0 =377 , + rv_op_sha512sig1 =378 , + rv_op_sha512sum0 =379 , + rv_op_sha512sum1 =380 , + rv_op_sha512sum0r =381 , + rv_op_sha512sum1r =382 , + rv_op_sha512sig0l =383 , + rv_op_sha512sig0h =384 , + rv_op_sha512sig1l =385 , + rv_op_sha512sig1h =386 , + rv_op_sm3p0 =387 , + rv_op_sm3p1 =388 , + rv_op_sm4ed =389 , + rv_op_sm4ks =390 , + rv_op_brev8 =391 , + rv_op_pack =392 , + rv_op_packh =393 , + rv_op_packw =394 , + rv_op_unzip =395 , + rv_op_zip =396 , + rv_op_xperm4 =397 , + rv_op_xperm8 =398 , } rv_op;/* structures */
@@ -540,6 +579,8 @@ typedef struct {uint8_t succ;uint8_t aq;uint8_t rl; +uint8_t bs; +uint8_t rnum; } rv_decode; typedef struct {
@@ -615,6 +656,8 @@ static const char rv_freg_name_sym[32][5] = {#define rv_fmt_rd_rs2 "O\t0,2"#define rv_fmt_rs1_offset "O\t1,o"#define rv_fmt_rs2_offset "O\t2,o" +#define rv_fmt_rs1_rs2_bs "O\t1,2,b" +#define rv_fmt_rd_rs1_rnum "O\t0,1,n"/* pseudo-instruction constraints */
@@ -766,6 +809,7 @@ static const rv_comp_data rvcp_csrrw[] = { { rv_op_illegal, NULL } }; +static const rv_comp_data rvcp_csrrs[] = { { rv_op_rdcycle, rvcc_rdcycle }, { rv_op_rdtime, rvcc_rdtime },
@@ -1203,6 +1247,43 @@ const rv_opcode_data opcode_data[] = { { "bclr", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, { "binv", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, { "bext", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, + { "aes32esmi", rv_codec_k_bs, rv_fmt_rs1_rs2_bs, NULL, 0, 0, 0 }, + { "aes32esi", rv_codec_k_bs, rv_fmt_rs1_rs2_bs, NULL, 0, 0, 0 }, + { "aes32dsmi", rv_codec_k_bs, rv_fmt_rs1_rs2_bs, NULL, 0, 0, 0 }, + { "aes32dsi", rv_codec_k_bs, rv_fmt_rs1_rs2_bs, NULL, 0, 0, 0 }, + { "aes64ks1i", rv_codec_k_rnum, rv_fmt_rd_rs1_rnum, NULL, 0, 0, 0 }, + { "aes64ks2", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, + { "aes64im", rv_codec_r, rv_fmt_rd_rs1, NULL, 0, 0 }, + { "aes64esm", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, + { "aes64es", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, + { "aes64dsm", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, + { "aes64ds", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, + { "sha256sig0", rv_codec_r, rv_fmt_rd_rs1, NULL, 0, 0 }, + { "sha256sig1", rv_codec_r, rv_fmt_rd_rs1, NULL, 0, 0 }, + { "sha256sum0", rv_codec_r, rv_fmt_rd_rs1, NULL, 0, 0 }, + { "sha256sum1", rv_codec_r, rv_fmt_rd_rs1, NULL, 0, 0 }, + { "sha512sig0", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, + { "sha512sig1", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, + { "sha512sum0", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, + { "sha512sum1", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, + { "sha512sum0r", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, + { "sha512sum1r", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, + { "sha512sig0l", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, + { "sha512sig0h", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, + { "sha512sig1l", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, + { "sha512sig1h", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, + { "sm3p0", rv_codec_r, rv_fmt_rd_rs1, NULL, 0, 0 }, + { "sm3p1", rv_codec_r, rv_fmt_rd_rs1, NULL, 0, 0 }, + { "sm4ed", rv_codec_k_bs, rv_fmt_rs1_rs2_bs, NULL, 0, 0, 0 }, + { "sm4ks", rv_codec_k_bs, rv_fmt_rs1_rs2_bs, NULL, 0, 0, 0 }, + { "brev8", rv_codec_r, rv_fmt_rd_rs1, NULL, 0, 0, 0 }, + { "pack", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, + { "packh", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, + { "packw", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, + { "unzip", rv_codec_r, rv_fmt_rd_rs1, NULL, 0, 0, 0 }, + { "zip", rv_codec_r, rv_fmt_rd_rs1, NULL, 0, 0, 0 }, + { "xperm4", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, + { "xperm8", rv_codec_r, rv_fmt_rd_rs1, NULL, 0, 0, 0 } };/* CSR names */
@@ -1216,6 +1297,7 @@ static const char *csr_name(int csrno)case 0x0003 :return "fcsr" ;case 0x0004 :return "uie" ;case 0x0005 :return "utvec" ; +case 0x0015 :return "seed" ;case 0x0040 :return "uscratch" ;case 0x0041 :return "uepc" ;case 0x0042 :return "ucause" ;
@@ -1594,7 +1676,36 @@ static void decode_inst_opcode(rv_decode *dec, rv_isa isa)case 1 :switch (((inst >>27 ) &0b11111 )) {case 0b00000 : op = rv_op_slli;break ; +case 0b00001 : +switch (((inst >>20 ) &0b1111111 )) { +case 0b0001111 : op = rv_op_zip;break ; + } +break ; +case 0b00010 : +switch (((inst >>20 ) &0b1111111 )) { +case 0b0000000 : op = rv_op_sha256sum0;break ; +case 0b0000001 : op = rv_op_sha256sum1;break ; +case 0b0000010 : op = rv_op_sha256sig0;break ; +case 0b0000011 : op = rv_op_sha256sig1;break ; +case 0b0000100 : op = rv_op_sha512sum0;break ; +case 0b0000101 : op = rv_op_sha512sum1;break ; +case 0b0000110 : op = rv_op_sha512sig0;break ; +case 0b0000111 : op = rv_op_sha512sig1;break ; +case 0b0001000 : op = rv_op_sm3p0;break ; +case 0b0001001 : op = rv_op_sm3p1;break ; + } +break ;case 0b00101 : op = rv_op_bseti;break ; +case 0b00110 : +switch (((inst >>20 ) &0b1111111 )) { +case 0b0000000 : op = rv_op_aes64im;break ; +default : +if (((inst >>24 ) &0b0111 ) ==0b001 ) { + op = rv_op_aes64ks1i; + } +break ; + } +break ;case 0b01001 : op = rv_op_bclri;break ;case 0b01101 : op = rv_op_binvi;break ;case 0b01100 :
@@ -1615,13 +1726,20 @@ static void decode_inst_opcode(rv_decode *dec, rv_isa isa)case 5 :switch (((inst >>27 ) &0b11111 )) {case 0b00000 : op = rv_op_srli;break ; +case 0b00001 : +switch (((inst >>20 ) &0b1111111 )) { +case 0b0001111 : op = rv_op_unzip;break ; + } +break ;case 0b00101 : op = rv_op_orc_b;break ;case 0b01000 : op = rv_op_srai;break ;case 0b01001 : op = rv_op_bexti;break ;case 0b01100 : op = rv_op_rori;break ;case 0b01101 :switch ((inst >>20 ) &0b1111111 ) { +case 0b0011000 : op = rv_op_rev8;break ;case 0b0111000 : op = rv_op_rev8;break ; +case 0b0000111 : op = rv_op_brev8;break ; }break ; }
@@ -1742,8 +1860,11 @@ static void decode_inst_opcode(rv_decode *dec, rv_isa isa)case 36 :switch ((inst >>20 ) &0b11111 ) {case 0 : op = rv_op_zext_h;break ; +default : op = rv_op_pack;break ; }break ; +case 39 : op = rv_op_packh;break ; +case 41 : op = rv_op_clmul;break ;case 42 : op = rv_op_clmulr;break ;case 43 : op = rv_op_clmulh;break ;
@@ -1755,6 +1876,12 @@ static void decode_inst_opcode(rv_decode *dec, rv_isa isa)case 132 : op = rv_op_sh2add;break ;case 134 : op = rv_op_sh3add;break ;case 161 : op = rv_op_bset;break ; +case 162 : op = rv_op_xperm4;break ; +case 164 : op = rv_op_xperm8;break ; +case 200 : op = rv_op_aes64es;break ; +case 216 : op = rv_op_aes64esm;break ; +case 232 : op = rv_op_aes64ds;break ; +case 248 : op = rv_op_aes64dsm;break ;case 256 : op = rv_op_sub;break ;case 260 : op = rv_op_xnor;break ;case 261 : op = rv_op_sra;break ;
@@ -1762,9 +1889,24 @@ static void decode_inst_opcode(rv_decode *dec, rv_isa isa)case 263 : op = rv_op_andn;break ;case 289 : op = rv_op_bclr;break ;case 293 : op = rv_op_bext;break ; +case 320 : op = rv_op_sha512sum0r;break ; +case 328 : op = rv_op_sha512sum1r;break ; +case 336 : op = rv_op_sha512sig0l;break ; +case 344 : op = rv_op_sha512sig1l;break ; +case 368 : op = rv_op_sha512sig0h;break ; +case 376 : op = rv_op_sha512sig1h;break ;case 385 : op = rv_op_rol;break ; -case 386 : op = rv_op_ror;break ; +case 389 : op = rv_op_ror;break ;case 417 : op = rv_op_binv;break ; +case 504 : op = rv_op_aes64ks2;break ; + } +switch ((inst >>25 ) &0b0011111 ) { +case 17 : op = rv_op_aes32esi;break ; +case 19 : op = rv_op_aes32esmi;break ; +case 21 : op = rv_op_aes32dsi;break ; +case 23 : op = rv_op_aes32dsmi;break ; +case 24 : op = rv_op_sm4ed;break ; +case 26 : op = rv_op_sm4ks;break ; }break ;case 13 : op = rv_op_lui;break ;
@@ -1782,6 +1924,7 @@ static void decode_inst_opcode(rv_decode *dec, rv_isa isa)case 36 :switch ((inst >>20 ) &0b11111 ) {case 0 : op = rv_op_zext_h;break ; +default : op = rv_op_packw;break ; }break ;case 130 : op = rv_op_sh1add_uw;break ;
@@ -2374,6 +2517,16 @@ static uint32_t operand_cimmq(rv_inst inst) ((inst <<57 ) >>62 ) <<6 ; } +static uint32_t operand_bs (rv_inst inst) +{ +return (inst <<32 ) >>62 ; +} + +static uint32_t operand_rnum (rv_inst inst) +{ +return (inst <<40 ) >>60 ; +} +/* decode operands */ static void decode_inst_operands (rv_decode *dec)
@@ -2653,6 +2806,16 @@ static void decode_inst_operands(rv_decode *dec) dec->rs2 =operand_crs2 (inst); dec->imm =operand_cimmsqsp (inst);break ; +case rv_codec_k_bs: + dec->rs1 =operand_rs1 (inst); + dec->rs2 =operand_rs2 (inst); + dec->bs =operand_bs (inst); +break ; +case rv_codec_k_rnum: + dec->rd =operand_rd (inst); + dec->rs1 =operand_rs1 (inst); + dec->rnum =operand_rnum (inst); +break ; }; }
@@ -2812,6 +2975,14 @@ static void format_inst(char *buf, size_t buflen, size_t tab, rv_decode *dec)case ')' :append (buf,")" , buflen);break ; +case 'b' : +snprintf (tmp,sizeof (tmp),"%d" , dec->bs); +append (buf, tmp, buflen); +break ; +case 'n' : +snprintf (tmp,sizeof (tmp),"%d" , dec->rnum); +append (buf, tmp, buflen); +break ;case '0' :append (buf, rv_ireg_name_sym[dec->rd], buflen);break ;
Signature · 1 line
2.35.1
[PULL 22/25] hw/riscv: virt: Create a platform bus
In reply to Alistair FrancisFrom: Alistair Francis <[email protected]>
Create a platform bus to allow dynamic devices to be connected. This is based on the ARM implementation.
Message-Id: <[email protected]>
--- include/hw/riscv/virt.h | 7 ++++- hw/riscv/virt.c | 68 +++++++++++++++++++++++++++++------------ hw/riscv/Kconfig | 1 + 3 files changed, 56 insertions(+), 20 deletions(-)
include/hw/riscv/virt.h +6 -1
@@ -46,6 +46,7 @@ struct RISCVVirtState {/*< public >*/ Notifier machine_done; +DeviceState *platform_bus_dev;RISCVHartArrayState soc[VIRT_SOCKETS_MAX ];DeviceState *irqchip[VIRT_SOCKETS_MAX ];PFlashCFI01 *flash[2 ];
@@ -76,6 +77,7 @@ enum {VIRT_DRAM ,VIRT_PCIE_MMIO ,VIRT_PCIE_PIO , +VIRT_PLATFORM_BUS , VIRT_PCIE_ECAM };
@@ -85,9 +87,12 @@ enum {VIRTIO_IRQ =1 ,/* 1 to 8 */ VIRTIO_COUNT =8 ,PCIE_IRQ =0x20 ,/* 32 to 35 */ - VIRTIO_NDEV = 0x35 /* Arbitrary maximum number of interrupts */ +VIRT_PLATFORM_BUS_IRQ =64 ,/* 64 to 96 */ + VIRTIO_NDEV = 96 /* Arbitrary maximum number of interrupts */ }; +#define VIRT_PLATFORM_BUS_NUM_IRQS 32 +#define VIRT_IRQCHIP_IPI_MSI 1#define VIRT_IRQCHIP_NUM_MSIS 255#define VIRT_IRQCHIP_NUM_SOURCES VIRTIO_NDEV
hw/riscv/virt.c +49 -19
92 lines not on this page · raw message
hw/riscv/Kconfig +1 -0
@@ -48,6 +48,7 @@ config RISCV_VIRT select SIFIVE_TEST select VIRTIO_MMIO select FW_CFG_DMA + select PLATFORM_BUS config SIFIVE_E bool
Signature · 1 line
2.35.1
[PULL 24/25] hw/riscv: virt: Add device plug support
In reply to Alistair FrancisFrom: Alistair Francis <[email protected]>
Add support for plugging in devices, this was tested with the TPM device.
Message-Id: <[email protected]>
--- hw/riscv/virt.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+)
hw/riscv/virt.c +35 -0
@@ -1569,10 +1569,37 @@ static void virt_set_aclint(Object *obj, bool value, Error **errp) s->have_aclint = value; } +static HotplugHandler *virt_machine_get_hotplug_handler (MachineState *machine, +DeviceState *dev) +{ +MachineClass *mc =MACHINE_GET_CLASS (machine); + +if (device_is_dynamic_sysbus (mc, dev)) { +return HOTPLUG_HANDLER (machine); + } +return NULL ; +} + +static void virt_machine_device_plug_cb (HotplugHandler *hotplug_dev, +DeviceState *dev,Error **errp) +{ +RISCVVirtState *s =RISCV_VIRT_MACHINE (hotplug_dev); + +if (s->platform_bus_dev) { +MachineClass *mc =MACHINE_GET_CLASS (s); + +if (device_is_dynamic_sysbus (mc, dev)) { +platform_bus_link_device (PLATFORM_BUS_DEVICE (s->platform_bus_dev), +SYS_BUS_DEVICE (dev)); + } + } +} +static void virt_machine_class_init (ObjectClass *oc,void *data) {char str[128 ];MachineClass *mc =MACHINE_CLASS (oc); +HotplugHandlerClass *hc =HOTPLUG_HANDLER_CLASS (oc); mc->desc ="RISC-V VirtIO board" ; mc->init = virt_machine_init;
@@ -1584,6 +1611,10 @@ static void virt_machine_class_init(ObjectClass *oc, void *data) mc->get_default_cpu_node_id = riscv_numa_get_default_cpu_node_id; mc->numa_mem_supported = true; mc->default_ram_id ="riscv_virt_board.ram" ; +assert (!mc->get_hotplug_handler); + mc->get_hotplug_handler = virt_machine_get_hotplug_handler; + + hc->plug = virt_machine_device_plug_cb;machine_class_allow_dynamic_sysbus_dev (mc,TYPE_RAMFB_DEVICE );
@@ -1614,6 +1645,10 @@ static const TypeInfo virt_machine_typeinfo = { .class_init = virt_machine_class_init, .instance_init = virt_machine_instance_init, .instance_size = sizeof(RISCVVirtState), + .interfaces = (InterfaceInfo []) { + {TYPE_HOTPLUG_HANDLER }, + { } + }, };static void virt_machine_init_register_types (void )
Signature · 1 line
2.35.1
[PULL 17/25] target/riscv: rvk: expose zbk* and zk* properties
In reply to Alistair FrancisFrom: Weiwei Li <[email protected]>
Message-Id: <[email protected]>
--- target/riscv/cpu.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
target/riscv/cpu.c +13 -0
@@ -849,7 +849,20 @@ static Property riscv_cpu_properties[] = {DEFINE_PROP_BOOL ("zba" ,RISCVCPU , cfg.ext_zba, true),DEFINE_PROP_BOOL ("zbb" ,RISCVCPU , cfg.ext_zbb, true),DEFINE_PROP_BOOL ("zbc" ,RISCVCPU , cfg.ext_zbc, true), +DEFINE_PROP_BOOL ("zbkb" ,RISCVCPU , cfg.ext_zbkb, false), +DEFINE_PROP_BOOL ("zbkc" ,RISCVCPU , cfg.ext_zbkc, false), +DEFINE_PROP_BOOL ("zbkx" ,RISCVCPU , cfg.ext_zbkx, false),DEFINE_PROP_BOOL ("zbs" ,RISCVCPU , cfg.ext_zbs, true), +DEFINE_PROP_BOOL ("zk" ,RISCVCPU , cfg.ext_zk, false), +DEFINE_PROP_BOOL ("zkn" ,RISCVCPU , cfg.ext_zkn, false), +DEFINE_PROP_BOOL ("zknd" ,RISCVCPU , cfg.ext_zknd, false), +DEFINE_PROP_BOOL ("zkne" ,RISCVCPU , cfg.ext_zkne, false), +DEFINE_PROP_BOOL ("zknh" ,RISCVCPU , cfg.ext_zknh, false), +DEFINE_PROP_BOOL ("zkr" ,RISCVCPU , cfg.ext_zkr, false), +DEFINE_PROP_BOOL ("zks" ,RISCVCPU , cfg.ext_zks, false), +DEFINE_PROP_BOOL ("zksed" ,RISCVCPU , cfg.ext_zksed, false), +DEFINE_PROP_BOOL ("zksh" ,RISCVCPU , cfg.ext_zksh, false), +DEFINE_PROP_BOOL ("zkt" ,RISCVCPU , cfg.ext_zkt, false),DEFINE_PROP_BOOL ("zdinx" ,RISCVCPU , cfg.ext_zdinx, false), DEFINE_PROP_BOOL("zfinx", RISCVCPU, cfg.ext_zfinx, false),
Signature · 1 line
2.35.1
[PULL 19/25] target/riscv: add scalar crypto related extenstion strings to isa_string
In reply to Alistair FrancisFrom: Weiwei Li <[email protected]>
- add zbk* and zk* strings to isa_edata_arr
Message-Id: <[email protected]>
--- target/riscv/cpu.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
target/riscv/cpu.c +13 -0
@@ -1005,7 +1005,20 @@ static void riscv_isa_string_ext(RISCVCPU *cpu, char **isa_str, int max_str_len)ISA_EDATA_ENTRY (zba, ext_zba),ISA_EDATA_ENTRY (zbb, ext_zbb),ISA_EDATA_ENTRY (zbc, ext_zbc), +ISA_EDATA_ENTRY (zbkb, ext_zbkb), +ISA_EDATA_ENTRY (zbkc, ext_zbkc), +ISA_EDATA_ENTRY (zbkx, ext_zbkx),ISA_EDATA_ENTRY (zbs, ext_zbs), +ISA_EDATA_ENTRY (zk, ext_zk), +ISA_EDATA_ENTRY (zkn, ext_zkn), +ISA_EDATA_ENTRY (zknd, ext_zknd), +ISA_EDATA_ENTRY (zkne, ext_zkne), +ISA_EDATA_ENTRY (zknh, ext_zknh), +ISA_EDATA_ENTRY (zkr, ext_zkr), +ISA_EDATA_ENTRY (zks, ext_zks), +ISA_EDATA_ENTRY (zksed, ext_zksed), +ISA_EDATA_ENTRY (zksh, ext_zksh), +ISA_EDATA_ENTRY (zkt, ext_zkt),ISA_EDATA_ENTRY (zve32f, ext_zve32f),ISA_EDATA_ENTRY (zve64f, ext_zve64f), ISA_EDATA_ENTRY(svinval, ext_svinval),
Signature · 1 line
2.35.1
[PULL 21/25] hw/core: Move the ARM sysbus-fdt to core
In reply to Alistair FrancisFrom: Alistair Francis <[email protected]>
The ARM virt machine currently uses sysbus-fdt to create device tree entries for dynamically created MMIO devices.
The RISC-V virt machine can also benefit from this, so move the code to the core directory.
Message-Id: <[email protected]>
---
include/hw/{arm => core}/sysbus-fdt.h | 0
hw/arm/virt.c | 2 +-
hw/arm/xlnx-versal-virt.c | 1 -
hw/{arm => core}/sysbus-fdt.c | 2 +-
hw/arm/meson.build | 1 -
hw/core/meson.build | 1 +
6 files changed, 3 insertions(+), 4 deletions(-)
rename include/hw/{arm => core}/sysbus-fdt.h (100%)
rename hw/{arm => core}/sysbus-fdt.c (99%)include/hw/core/sysbus-fdt.h renamed from include/hw/arm/sysbus-fdt.h +0 -0
hw/arm/virt.c +1 -1
@@ -56,7 +56,7 @@#include "qemu/module.h" #include "hw/pci-host/gpex.h" #include "hw/virtio/virtio-pci.h" -#include "hw/arm/sysbus-fdt.h" +#include "hw/core/sysbus-fdt.h" #include "hw/platform-bus.h" #include "hw/qdev-properties.h" #include "hw/arm/fdt.h"
hw/arm/xlnx-versal-virt.c +0 -1
@@ -15,7 +15,6 @@#include "sysemu/device_tree.h" #include "hw/boards.h" #include "hw/sysbus.h" -#include "hw/arm/sysbus-fdt.h" #include "hw/arm/fdt.h" #include "cpu.h" #include "hw/qdev-properties.h"
hw/core/sysbus-fdt.c renamed from hw/arm/sysbus-fdt.c +1 -1
@@ -27,7 +27,7 @@#ifdef CONFIG_LINUX #include <linux/vfio.h> #endif -#include "hw/arm/sysbus-fdt.h" +#include "hw/core/sysbus-fdt.h" #include "qemu/error-report.h" #include "sysemu/device_tree.h" #include "sysemu/tpm.h"
hw/arm/meson.build +0 -1
@@ -1,6 +1,5 @@ arm_ss = ss.source_set() arm_ss.add(files('boot.c'), fdt) -arm_ss.add(when: 'CONFIG_PLATFORM_BUS', if_true: files('sysbus-fdt.c')) arm_ss.add(when: 'CONFIG_ARM_VIRT', if_true: files('virt.c')) arm_ss.add(when: 'CONFIG_ACPI', if_true: files('virt-acpi-build.c')) arm_ss.add(when: 'CONFIG_DIGIC', if_true: files('digic_boards.c'))
hw/core/meson.build +1 -0
@@ -33,6 +33,7 @@ softmmu_ss.add(when: 'CONFIG_PTIMER', if_true: files('ptimer.c')) softmmu_ss.add(when: 'CONFIG_REGISTER', if_true: files('register.c')) softmmu_ss.add(when: 'CONFIG_SPLIT_IRQ', if_true: files('split-irq.c')) softmmu_ss.add(when: 'CONFIG_XILINX_AXI', if_true: files('stream.c')) +softmmu_ss.add(when: 'CONFIG_PLATFORM_BUS', if_true: files('sysbus-fdt.c')) softmmu_ss.add(files( 'cpu-sysemu.c',
Signature · 1 line
2.35.1
[PULL 23/25] hw/riscv: virt: Add support for generating platform FDT entries
In reply to Alistair FrancisFrom: Alistair Francis <[email protected]>
Similar to the ARM virt machine add support for adding device tree entries for dynamically created devices.
Message-Id: <[email protected]>
--- hw/riscv/virt.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
hw/riscv/virt.c +19 -0
@@ -28,6 +28,7 @@#include "hw/qdev-properties.h" #include "hw/char/serial.h" #include "target/riscv/cpu.h" +#include "hw/core/sysbus-fdt.h" #include "hw/riscv/riscv_hart.h" #include "hw/riscv/virt.h" #include "hw/riscv/boot.h"
@@ -475,6 +476,12 @@ static void create_fdt_socket_plic(RISCVVirtState *s,riscv_socket_fdt_write_id (mc, mc->fdt, plic_name, socket);qemu_fdt_setprop_cell (mc->fdt, plic_name,"phandle" , plic_phandles[socket]); + +platform_bus_add_all_fdt_nodes (mc->fdt, plic_name, + memmap[VIRT_PLATFORM_BUS ].base, + memmap[VIRT_PLATFORM_BUS ].size, +VIRT_PLATFORM_BUS_IRQ ); +g_free (plic_name);g_free (plic_cells);
@@ -552,6 +559,12 @@ static void create_fdt_imsic(RISCVVirtState *s, const MemMapEntry *memmap, IMSIC_MMIO_GROUP_MIN_SHIFT); }qemu_fdt_setprop_cell (mc->fdt, imsic_name,"phandle" , *msi_m_phandle); + +platform_bus_add_all_fdt_nodes (mc->fdt, imsic_name, + memmap[VIRT_PLATFORM_BUS ].base, + memmap[VIRT_PLATFORM_BUS ].size, +VIRT_PLATFORM_BUS_IRQ ); +g_free (imsic_name);/* S-level IMSIC node */
@@ -689,6 +702,12 @@ static void create_fdt_socket_aplic(RISCVVirtState *s, VIRT_IRQCHIP_NUM_SOURCES);riscv_socket_fdt_write_id (mc, mc->fdt, aplic_name, socket);qemu_fdt_setprop_cell (mc->fdt, aplic_name,"phandle" , aplic_s_phandle); + +platform_bus_add_all_fdt_nodes (mc->fdt, aplic_name, + memmap[VIRT_PLATFORM_BUS ].base, + memmap[VIRT_PLATFORM_BUS ].size, +VIRT_PLATFORM_BUS_IRQ ); +g_free (aplic_name);g_free (aplic_cells);
Signature · 1 line
2.35.1
[PULL 25/25] hw/riscv: Enable TPM backends
In reply to Alistair FrancisFrom: Alistair Francis <[email protected]>
Imply the TPM sysbus devices. This allows users to add TPM devices to the RISC-V virt board.
This was tested by first creating an emulated TPM device:
swtpm socket --tpm2 -t -d --tpmstate dir=/tmp/tpm \
--ctrl type=unixio,path=swtpm-sockThen launching QEMU with:
-chardev socket,id=chrtpm,path=swtpm-sock \
-tpmdev emulator,id=tpm0,chardev=chrtpm \
-device tpm-tis-device,tpmdev=tpm0The TPM device can be seen in the memory tree and the generated device tree.
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/942
Message-Id: <[email protected]>
--- docs/system/riscv/virt.rst | 20 ++++++++++++++++++++ hw/riscv/virt.c | 4 ++++ hw/riscv/Kconfig | 1 + 3 files changed, 25 insertions(+)
docs/system/riscv/virt.rst +20 -0
@@ -162,3 +162,23 @@ The minimal QEMU commands to run U-Boot SPL are: To test 32-bit U-Boot images, switch to use qemu-riscv32_smode_defconfig and riscv32_spl_defconfig builds, and replace ``qemu-system-riscv64`` with ``qemu-system-riscv32`` in the command lines above to boot the 32-bit U-Boot. + +Enabling TPM +------------ + +A TPM device can be connected to the virt board by following the steps below. + +First launch the TPM emulator + + swtpm socket --tpm2 -t -d --tpmstate dir=/tmp/tpm \ + --ctrl type=unixio,path=swtpm-sock + +Then launch QEMU with: + + ... + -chardev socket,id=chrtpm,path=swtpm-sock \ + -tpmdev emulator,id=tpm0,chardev=chrtpm \ + -device tpm-tis-device,tpmdev=tpm0 + +The TPM device can be seen in the memory tree and the generated device +tree and should be accessible from the guest software.
hw/riscv/virt.c +4 -0
@@ -43,6 +43,7 @@#include "sysemu/device_tree.h" #include "sysemu/sysemu.h" #include "sysemu/kvm.h" +#include "sysemu/tpm.h" #include "hw/pci/pci.h" #include "hw/pci-host/gpex.h" #include "hw/display/ramfb.h"
@@ -1617,6 +1618,9 @@ static void virt_machine_class_init(ObjectClass *oc, void *data) hc->plug = virt_machine_device_plug_cb;machine_class_allow_dynamic_sysbus_dev (mc,TYPE_RAMFB_DEVICE ); +#ifdef CONFIG_TPM +machine_class_allow_dynamic_sysbus_dev (mc,TYPE_TPM_TIS_SYSBUS ); +#endif object_class_property_add_bool (oc,"aclint" , virt_get_aclint, virt_set_aclint);
hw/riscv/Kconfig +1 -0
@@ -34,6 +34,7 @@ config RISCV_VIRT imply PCI_DEVICES imply VIRTIO_VGA imply TEST_DEVICES + imply TPM_TIS_SYSBUS select RISCV_NUMA select GOLDFISH_RTC select MSI_NONBROKEN
Signature · 1 line
2.35.1
Richard Henderson
AppliedQuoted 14 lines · Alistair Francis
From: Alistair Francis <[email protected]>
The following changes since commit
f22833602095b05733bceaddeb20f3edfced3c07:Merge tag 'pull-target-arm-20220428' of https://git.linaro.org/people/pmaydell/qemu-arm into staging (2022-04-28 08:34:17 -0700)are available in the Git repository at:
[email protected]:alistair23/qemu.git tags/pull-riscv-to-apply-20220429for you to fetch changes up to
325b7c4e7582c229d28c47123c3b986ed948eb84:hw/riscv: Enable TPM backends (2022-04-29 10:48:48 +1000)
Quoted 8 lines
----------------------------------------------------------------
Second RISC-V PR for QEMU 7.1* Improve device tree generation
* Support configuarable marchid, mvendorid, mipid CSR values
* Add support for the Zbkb, Zbkc, Zbkx, Zknd/Zkne, Zknh, Zksed/Zksh and Zkr extensions
* Fix incorrect PTE merge inwalk_pte
* Add TPM support to the virt board
Applied, thanks. Please update https://wiki.qemu.org/ChangeLog/7.1 as appropriate.
r~
Quoted 78 lines
----------------------------------------------------------------
Alistair Francis (6):
hw/riscv: virt: Add a machine done notifier
hw/core: Move the ARM sysbus-fdt to core
hw/riscv: virt: Create a platform bus
hw/riscv: virt: Add support for generating platform FDT entries hw/riscv: virt: Add device plug support
hw/riscv: Enable TPM backendsBin Meng (2):
hw/riscv: spike: Add '/chosen/stdout-path' in device tree unconditionally hw/riscv: Don't add empty bootargs to device treeFrank Chang (1):
target/riscv: Support configuarable marchid, mvendorid, mipid CSR valuesRalf Ramsauer (1):
target/riscv: Fix incorrect PTE merge inwalk_pteWeiwei Li (15):
target/riscv: rvk: add cfg properties for zbk* and zk*
target/riscv: rvk: add support for zbkb extension
target/riscv: rvk: add support for zbkc extension
target/riscv: rvk: add support for zbkx extension
crypto: movesm4_sboxfrom target/arm
target/riscv: rvk: add support for zknd/zkne extension in RV32 target/riscv: rvk: add support for zkne/zknd extension in RV64 target/riscv: rvk: add support for sha256 related instructions in zknh extension target/riscv: rvk: add support for sha512 related instructions for RV32 in zknh extension target/riscv: rvk: add support for sha512 related instructions for RV64 in zknh extension target/riscv: rvk: add support for zksed/zksh extension
target/riscv: rvk: add CSR support for Zkr
disas/riscv.c: rvk: add disas support for Zbk* and Zk* instructions target/riscv: rvk: expose zbk* and zk* properties
target/riscv: add scalar crypto related extenstion strings toisa_stringdocs/system/riscv/virt.rst | 20 ++ include/crypto/sm4.h | 6 + include/hw/{arm => core}/sysbus-fdt.h | 0 include/hw/riscv/virt.h | 8 +- target/riscv/cpu.h | 17 ++ target/riscv/cpu_bits.h | 9 + target/riscv/helper.h | 22 ++ target/riscv/pmp.h | 8 +- target/riscv/insn32.decode | 97 ++++++-- crypto/sm4.c | 49 ++++ disas/riscv.c | 173 +++++++++++++- hw/arm/virt.c | 2 +- hw/arm/xlnx-versal-virt.c | 1 - hw/{arm => core}/sysbus-fdt.c | 2 +- hw/riscv/microchip_pfsoc.c | 2 +- hw/riscv/sifive_u.c | 2 +- hw/riscv/spike.c | 7 +- hw/riscv/virt.c | 319 +++++++++++++++++--------- target/arm/crypto_helper.c | 36 +-- target/riscv/bitmanip_helper.c | 80 +++++++ target/riscv/cpu.c | 58 +++++ target/riscv/crypto_helper.c | 302 ++++++++++++++++++++++++ target/riscv/csr.c | 118 +++++++++- target/riscv/monitor.c | 11 +- target/riscv/op_helper.c | 9 + target/riscv/translate.c | 8 + target/riscv/insn_trans/trans_rvb.c.inc | 116 ++++++++-- target/riscv/insn_trans/trans_rvk.c.inc | 391 ++++++++++++++++++++++++++++++++ crypto/meson.build | 1 + hw/arm/meson.build | 1 - hw/core/meson.build | 1 + hw/riscv/Kconfig | 2 + target/riscv/meson.build | 3 +- 33 files changed, 1682 insertions(+), 199 deletions(-)create mode 100644
include/crypto/sm4.h
renameinclude/hw/{arm=>core}/sysbus-fdt.h(100%) create mode 100644crypto/sm4.c
rename hw/{arm =>core}/sysbus-fdt.c(99%) create mode 100644target/riscv/crypto_helper.ccreate mode 100644 target/riscv/insn_trans/trans_rvk.c.inc