1 | From: Alistair Francis <alistair.francis@wdc.com> | 1 | The following changes since commit a51e5124a655b3dad80b36b18547cb1eca2c5eb2: |
---|---|---|---|
2 | 2 | ||
3 | The following changes since commit f22833602095b05733bceaddeb20f3edfced3c07: | 3 | Merge tag 'pull-omnibus-111023-1' of https://gitlab.com/stsquad/qemu into staging (2023-10-11 09:43:10 -0400) |
4 | |||
5 | Merge tag 'pull-target-arm-20220428' of https://git.linaro.org/people/pmaydell/qemu-arm into staging (2022-04-28 08:34:17 -0700) | ||
6 | 4 | ||
7 | are available in the Git repository at: | 5 | are available in the Git repository at: |
8 | 6 | ||
9 | git@github.com:alistair23/qemu.git tags/pull-riscv-to-apply-20220429 | 7 | https://github.com/alistair23/qemu.git tags/pull-riscv-to-apply-20231012-1 |
10 | 8 | ||
11 | for you to fetch changes up to 325b7c4e7582c229d28c47123c3b986ed948eb84: | 9 | for you to fetch changes up to 837570cef237b634eb4c245363470deebea7089d: |
12 | 10 | ||
13 | hw/riscv: Enable TPM backends (2022-04-29 10:48:48 +1000) | 11 | target/riscv: Fix vfwmaccbf16.vf (2023-10-12 12:50:13 +1000) |
14 | 12 | ||
15 | ---------------------------------------------------------------- | 13 | ---------------------------------------------------------------- |
16 | Second RISC-V PR for QEMU 7.1 | 14 | Second RISC-V PR for 8.2 |
17 | 15 | ||
18 | * Improve device tree generation | 16 | * Add support for the max CPU |
19 | * Support configuarable marchid, mvendorid, mipid CSR values | 17 | * Detect user choice in TCG |
20 | * Add support for the Zbkb, Zbkc, Zbkx, Zknd/Zkne, Zknh, Zksed/Zksh and Zkr extensions | 18 | * Clear CSR values at reset and sync MPSTATE with host |
21 | * Fix incorrect PTE merge in walk_pte | 19 | * Fix the typo of inverted order of pmpaddr13 and pmpaddr14 |
22 | * Add TPM support to the virt board | 20 | * Split TCG/KVM accelerators from cpu.c |
21 | * Add extension properties for all cpus | ||
22 | * Replace GDB exit calls with proper shutdown | ||
23 | * Support KVM_GET_REG_LIST | ||
24 | * Remove RVG warning | ||
25 | * Use env_archcpu for better performance | ||
26 | * Deprecate capital 'Z' CPU properties | ||
27 | * Fix vfwmaccbf16.vf | ||
23 | 28 | ||
24 | ---------------------------------------------------------------- | 29 | ---------------------------------------------------------------- |
25 | Alistair Francis (6): | 30 | Alvin Chang (1): |
26 | hw/riscv: virt: Add a machine done notifier | 31 | disas/riscv: Fix the typo of inverted order of pmpaddr13 and pmpaddr14 |
27 | hw/core: Move the ARM sysbus-fdt to core | ||
28 | hw/riscv: virt: Create a platform bus | ||
29 | hw/riscv: virt: Add support for generating platform FDT entries | ||
30 | hw/riscv: virt: Add device plug support | ||
31 | hw/riscv: Enable TPM backends | ||
32 | 32 | ||
33 | Bin Meng (2): | 33 | Clément Chigot (5): |
34 | hw/riscv: spike: Add '/chosen/stdout-path' in device tree unconditionally | 34 | softmmu: add means to pass an exit code when requesting a shutdown |
35 | hw/riscv: Don't add empty bootargs to device tree | 35 | softmmu: pass the main loop status to gdb "Wxx" packet |
36 | hw/misc/sifive_test.c: replace exit calls with proper shutdown | ||
37 | hw/char: riscv_htif: replace exit calls with proper shutdown | ||
38 | gdbstub: replace exit calls with proper shutdown for softmmu | ||
36 | 39 | ||
37 | Frank Chang (1): | 40 | Daniel Henrique Barboza (45): |
38 | target/riscv: Support configuarable marchid, mvendorid, mipid CSR values | 41 | target/riscv/cpu.c: split CPU options from riscv_cpu_extensions[] |
42 | target/riscv/cpu.c: skip 'bool' check when filtering KVM props | ||
43 | target/riscv/cpu.c: split kvm prop handling to its own helper | ||
44 | target/riscv: add DEFINE_PROP_END_OF_LIST() to riscv_cpu_options[] | ||
45 | target/riscv/cpu.c: split non-ratified exts from riscv_cpu_extensions[] | ||
46 | target/riscv/cpu.c: split vendor exts from riscv_cpu_extensions[] | ||
47 | target/riscv/cpu.c: add riscv_cpu_add_qdev_prop_array() | ||
48 | target/riscv/cpu.c: add riscv_cpu_add_kvm_unavail_prop_array() | ||
49 | target/riscv/cpu.c: limit cfg->vext_spec log message | ||
50 | target/riscv: add 'max' CPU type | ||
51 | avocado, risc-v: add tuxboot tests for 'max' CPU | ||
52 | target/riscv: deprecate the 'any' CPU type | ||
53 | target/riscv/cpu.c: use offset in isa_ext_is_enabled/update_enabled | ||
54 | target/riscv: make CPUCFG() macro public | ||
55 | target/riscv/cpu.c: introduce cpu_cfg_ext_auto_update() | ||
56 | target/riscv/cpu.c: use cpu_cfg_ext_auto_update() during realize() | ||
57 | target/riscv/cpu.c: introduce RISCVCPUMultiExtConfig | ||
58 | target/riscv: use isa_ext_update_enabled() in init_max_cpu_extensions() | ||
59 | target/riscv/cpu.c: honor user choice in cpu_cfg_ext_auto_update() | ||
60 | target/riscv/cpu.c: consider user option with RVG | ||
61 | target/riscv: introduce TCG AccelCPUClass | ||
62 | target/riscv: move riscv_cpu_realize_tcg() to TCG::cpu_realizefn() | ||
63 | target/riscv: move riscv_cpu_validate_set_extensions() to tcg-cpu.c | ||
64 | target/riscv: move riscv_tcg_ops to tcg-cpu.c | ||
65 | target/riscv/cpu.c: add .instance_post_init() | ||
66 | target/riscv: move 'host' CPU declaration to kvm.c | ||
67 | target/riscv/cpu.c: mark extensions arrays as 'const' | ||
68 | target/riscv: move riscv_cpu_add_kvm_properties() to kvm.c | ||
69 | target/riscv: make riscv_add_satp_mode_properties() public | ||
70 | target/riscv: remove kvm-stub.c | ||
71 | target/riscv: introduce KVM AccelCPUClass | ||
72 | target/riscv: move KVM only files to kvm subdir | ||
73 | target/riscv/kvm: do not use riscv_cpu_add_misa_properties() | ||
74 | target/riscv/cpu.c: export set_misa() | ||
75 | target/riscv/tcg: introduce tcg_cpu_instance_init() | ||
76 | target/riscv/cpu.c: make misa_ext_cfgs[] 'const' | ||
77 | target/riscv/tcg: move riscv_cpu_add_misa_properties() to tcg-cpu.c | ||
78 | target/riscv/cpu.c: export isa_edata_arr[] | ||
79 | target/riscv/cpu: move priv spec functions to tcg-cpu.c | ||
80 | target/riscv: add riscv_cpu_get_name() | ||
81 | target/riscv/tcg-cpu.c: add extension properties for all cpus | ||
82 | target/riscv/kvm: improve 'init_multiext_cfg' error msg | ||
83 | target/riscv/kvm: support KVM_GET_REG_LIST | ||
84 | target/riscv/tcg: remove RVG warning | ||
85 | target/riscv: deprecate capital 'Z' CPU properties | ||
39 | 86 | ||
40 | Ralf Ramsauer (1): | 87 | Max Chou (1): |
41 | target/riscv: Fix incorrect PTE merge in walk_pte | 88 | target/riscv: Fix vfwmaccbf16.vf |
42 | 89 | ||
43 | Weiwei Li (15): | 90 | Richard W.M. Jones (1): |
44 | target/riscv: rvk: add cfg properties for zbk* and zk* | 91 | target/riscv: Use env_archcpu for better performance |
45 | target/riscv: rvk: add support for zbkb extension | ||
46 | target/riscv: rvk: add support for zbkc extension | ||
47 | target/riscv: rvk: add support for zbkx extension | ||
48 | crypto: move sm4_sbox from target/arm | ||
49 | target/riscv: rvk: add support for zknd/zkne extension in RV32 | ||
50 | target/riscv: rvk: add support for zkne/zknd extension in RV64 | ||
51 | target/riscv: rvk: add support for sha256 related instructions in zknh extension | ||
52 | target/riscv: rvk: add support for sha512 related instructions for RV32 in zknh extension | ||
53 | target/riscv: rvk: add support for sha512 related instructions for RV64 in zknh extension | ||
54 | target/riscv: rvk: add support for zksed/zksh extension | ||
55 | target/riscv: rvk: add CSR support for Zkr | ||
56 | disas/riscv.c: rvk: add disas support for Zbk* and Zk* instructions | ||
57 | target/riscv: rvk: expose zbk* and zk* properties | ||
58 | target/riscv: add scalar crypto related extenstion strings to isa_string | ||
59 | 92 | ||
60 | docs/system/riscv/virt.rst | 20 ++ | 93 | liguang.zhang (1): |
61 | include/crypto/sm4.h | 6 + | 94 | target/riscv: Clear CSR values at reset and sync MPSTATE with host |
62 | include/hw/{arm => core}/sysbus-fdt.h | 0 | 95 | |
63 | include/hw/riscv/virt.h | 8 +- | 96 | docs/about/deprecated.rst | 35 ++ |
64 | target/riscv/cpu.h | 17 ++ | 97 | include/gdbstub/syscalls.h | 9 + |
65 | target/riscv/cpu_bits.h | 9 + | 98 | include/sysemu/runstate.h | 2 + |
66 | target/riscv/helper.h | 22 ++ | 99 | include/sysemu/sysemu.h | 2 +- |
67 | target/riscv/pmp.h | 8 +- | 100 | target/riscv/cpu-qom.h | 1 + |
68 | target/riscv/insn32.decode | 97 ++++++-- | 101 | target/riscv/cpu.h | 34 +- |
69 | crypto/sm4.c | 49 ++++ | 102 | target/riscv/{ => kvm}/kvm_riscv.h | 2 +- |
70 | disas/riscv.c | 173 +++++++++++++- | 103 | target/riscv/tcg/tcg-cpu.h | 27 + |
71 | hw/arm/virt.c | 2 +- | 104 | disas/riscv.c | 4 +- |
72 | hw/arm/xlnx-versal-virt.c | 1 - | 105 | gdbstub/gdbstub.c | 5 +- |
73 | hw/{arm => core}/sysbus-fdt.c | 2 +- | 106 | gdbstub/system.c | 6 + |
74 | hw/riscv/microchip_pfsoc.c | 2 +- | 107 | gdbstub/user.c | 6 + |
75 | hw/riscv/sifive_u.c | 2 +- | 108 | hw/char/riscv_htif.c | 5 +- |
76 | hw/riscv/spike.c | 7 +- | 109 | hw/intc/riscv_aplic.c | 2 +- |
77 | hw/riscv/virt.c | 319 +++++++++++++++++--------- | 110 | hw/misc/sifive_test.c | 9 +- |
78 | target/arm/crypto_helper.c | 36 +-- | 111 | hw/riscv/virt.c | 2 +- |
79 | target/riscv/bitmanip_helper.c | 80 +++++++ | 112 | system/main.c | 2 +- |
80 | target/riscv/cpu.c | 58 +++++ | 113 | system/runstate.c | 16 +- |
81 | target/riscv/crypto_helper.c | 302 ++++++++++++++++++++++++ | 114 | target/riscv/cpu.c | 1030 +++++++-------------------------- |
82 | target/riscv/csr.c | 118 +++++++++- | 115 | target/riscv/cpu_helper.c | 3 +- |
83 | target/riscv/monitor.c | 11 +- | 116 | target/riscv/csr.c | 1 + |
84 | target/riscv/op_helper.c | 9 + | 117 | target/riscv/kvm-stub.c | 30 - |
85 | target/riscv/translate.c | 8 + | 118 | target/riscv/{kvm.c => kvm/kvm-cpu.c} | 272 ++++++++- |
86 | target/riscv/insn_trans/trans_rvb.c.inc | 116 ++++++++-- | 119 | target/riscv/tcg/tcg-cpu.c | 949 ++++++++++++++++++++++++++++++ |
87 | target/riscv/insn_trans/trans_rvk.c.inc | 391 ++++++++++++++++++++++++++++++++ | 120 | target/riscv/vector_helper.c | 2 +- |
88 | crypto/meson.build | 1 + | 121 | target/riscv/kvm/meson.build | 1 + |
89 | hw/arm/meson.build | 1 - | 122 | target/riscv/meson.build | 4 +- |
90 | hw/core/meson.build | 1 + | 123 | target/riscv/tcg/meson.build | 2 + |
91 | hw/riscv/Kconfig | 2 + | 124 | tests/avocado/tuxrun_baselines.py | 32 + |
92 | target/riscv/meson.build | 3 +- | 125 | 29 files changed, 1604 insertions(+), 891 deletions(-) |
93 | 33 files changed, 1682 insertions(+), 199 deletions(-) | 126 | rename target/riscv/{ => kvm}/kvm_riscv.h (95%) |
94 | create mode 100644 include/crypto/sm4.h | 127 | create mode 100644 target/riscv/tcg/tcg-cpu.h |
95 | rename include/hw/{arm => core}/sysbus-fdt.h (100%) | 128 | delete mode 100644 target/riscv/kvm-stub.c |
96 | create mode 100644 crypto/sm4.c | 129 | rename target/riscv/{kvm.c => kvm/kvm-cpu.c} (81%) |
97 | rename hw/{arm => core}/sysbus-fdt.c (99%) | 130 | create mode 100644 target/riscv/tcg/tcg-cpu.c |
98 | create mode 100644 target/riscv/crypto_helper.c | 131 | create mode 100644 target/riscv/kvm/meson.build |
99 | create mode 100644 target/riscv/insn_trans/trans_rvk.c.inc | 132 | create mode 100644 target/riscv/tcg/meson.build |
133 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
1 | 2 | ||
3 | We'll add a new CPU type that will enable a considerable amount of | ||
4 | extensions. To make it easier for us we'll do a few cleanups in our | ||
5 | existing riscv_cpu_extensions[] array. | ||
6 | |||
7 | Start by splitting all CPU non-boolean options from it. Create a new | ||
8 | riscv_cpu_options[] array for them. Add all these properties in | ||
9 | riscv_cpu_add_user_properties() as it is already being done today. | ||
10 | |||
11 | 'mmu' and 'pmp' aren't really extensions in the usual way we think about | ||
12 | RISC-V extensions. These are closer to CPU features/options, so move | ||
13 | both to riscv_cpu_options[] too. In the near future we'll need to match | ||
14 | all extensions with all entries in isa_edata_arr[], and so it happens | ||
15 | that both 'mmu' and 'pmp' do not have a riscv,isa string (thus, no priv | ||
16 | spec version restriction). This further emphasizes the point that these | ||
17 | are more a CPU option than an extension. | ||
18 | |||
19 | No functional changes made. | ||
20 | |||
21 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
22 | Reviewed-by: Weiwei Li <liweiwei@iscas.ac.cn> | ||
23 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
24 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> | ||
25 | Message-ID: <20230912132423.268494-2-dbarboza@ventanamicro.com> | ||
26 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
27 | --- | ||
28 | target/riscv/cpu.c | 33 +++++++++++++++++++++++---------- | ||
29 | 1 file changed, 23 insertions(+), 10 deletions(-) | ||
30 | |||
31 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | ||
32 | index XXXXXXX..XXXXXXX 100644 | ||
33 | --- a/target/riscv/cpu.c | ||
34 | +++ b/target/riscv/cpu.c | ||
35 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_add_misa_properties(Object *cpu_obj) | ||
36 | |||
37 | static Property riscv_cpu_extensions[] = { | ||
38 | /* Defaults for standard extensions */ | ||
39 | - DEFINE_PROP_UINT8("pmu-num", RISCVCPU, cfg.pmu_num, 16), | ||
40 | DEFINE_PROP_BOOL("sscofpmf", RISCVCPU, cfg.ext_sscofpmf, false), | ||
41 | DEFINE_PROP_BOOL("Zifencei", RISCVCPU, cfg.ext_ifencei, true), | ||
42 | DEFINE_PROP_BOOL("Zicsr", RISCVCPU, cfg.ext_icsr, true), | ||
43 | @@ -XXX,XX +XXX,XX @@ static Property riscv_cpu_extensions[] = { | ||
44 | DEFINE_PROP_BOOL("Zve32f", RISCVCPU, cfg.ext_zve32f, false), | ||
45 | DEFINE_PROP_BOOL("Zve64f", RISCVCPU, cfg.ext_zve64f, false), | ||
46 | DEFINE_PROP_BOOL("Zve64d", RISCVCPU, cfg.ext_zve64d, false), | ||
47 | - DEFINE_PROP_BOOL("mmu", RISCVCPU, cfg.mmu, true), | ||
48 | - DEFINE_PROP_BOOL("pmp", RISCVCPU, cfg.pmp, true), | ||
49 | DEFINE_PROP_BOOL("sstc", RISCVCPU, cfg.ext_sstc, true), | ||
50 | |||
51 | - DEFINE_PROP_STRING("priv_spec", RISCVCPU, cfg.priv_spec), | ||
52 | - DEFINE_PROP_STRING("vext_spec", RISCVCPU, cfg.vext_spec), | ||
53 | - DEFINE_PROP_UINT16("vlen", RISCVCPU, cfg.vlen, 128), | ||
54 | - DEFINE_PROP_UINT16("elen", RISCVCPU, cfg.elen, 64), | ||
55 | - | ||
56 | DEFINE_PROP_BOOL("smstateen", RISCVCPU, cfg.ext_smstateen, false), | ||
57 | DEFINE_PROP_BOOL("svadu", RISCVCPU, cfg.ext_svadu, true), | ||
58 | DEFINE_PROP_BOOL("svinval", RISCVCPU, cfg.ext_svinval, false), | ||
59 | @@ -XXX,XX +XXX,XX @@ static Property riscv_cpu_extensions[] = { | ||
60 | DEFINE_PROP_BOOL("zhinxmin", RISCVCPU, cfg.ext_zhinxmin, false), | ||
61 | |||
62 | DEFINE_PROP_BOOL("zicbom", RISCVCPU, cfg.ext_icbom, true), | ||
63 | - DEFINE_PROP_UINT16("cbom_blocksize", RISCVCPU, cfg.cbom_blocksize, 64), | ||
64 | DEFINE_PROP_BOOL("zicboz", RISCVCPU, cfg.ext_icboz, true), | ||
65 | - DEFINE_PROP_UINT16("cboz_blocksize", RISCVCPU, cfg.cboz_blocksize, 64), | ||
66 | |||
67 | DEFINE_PROP_BOOL("zmmul", RISCVCPU, cfg.ext_zmmul, false), | ||
68 | |||
69 | @@ -XXX,XX +XXX,XX @@ static Property riscv_cpu_extensions[] = { | ||
70 | DEFINE_PROP_END_OF_LIST(), | ||
71 | }; | ||
72 | |||
73 | +static Property riscv_cpu_options[] = { | ||
74 | + DEFINE_PROP_UINT8("pmu-num", RISCVCPU, cfg.pmu_num, 16), | ||
75 | + | ||
76 | + DEFINE_PROP_BOOL("mmu", RISCVCPU, cfg.mmu, true), | ||
77 | + DEFINE_PROP_BOOL("pmp", RISCVCPU, cfg.pmp, true), | ||
78 | + | ||
79 | + DEFINE_PROP_STRING("priv_spec", RISCVCPU, cfg.priv_spec), | ||
80 | + DEFINE_PROP_STRING("vext_spec", RISCVCPU, cfg.vext_spec), | ||
81 | + | ||
82 | + DEFINE_PROP_UINT16("vlen", RISCVCPU, cfg.vlen, 128), | ||
83 | + DEFINE_PROP_UINT16("elen", RISCVCPU, cfg.elen, 64), | ||
84 | + | ||
85 | + DEFINE_PROP_UINT16("cbom_blocksize", RISCVCPU, cfg.cbom_blocksize, 64), | ||
86 | + DEFINE_PROP_UINT16("cboz_blocksize", RISCVCPU, cfg.cboz_blocksize, 64), | ||
87 | +}; | ||
88 | |||
89 | #ifndef CONFIG_USER_ONLY | ||
90 | static void cpu_set_cfg_unavailable(Object *obj, Visitor *v, | ||
91 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_add_user_properties(Object *obj) | ||
92 | #endif | ||
93 | qdev_property_add_static(dev, prop); | ||
94 | } | ||
95 | + | ||
96 | + for (int i = 0; i < ARRAY_SIZE(riscv_cpu_options); i++) { | ||
97 | + /* Check if KVM created the property already */ | ||
98 | + if (object_property_find(obj, riscv_cpu_options[i].name)) { | ||
99 | + continue; | ||
100 | + } | ||
101 | + qdev_property_add_static(dev, &riscv_cpu_options[i]); | ||
102 | + } | ||
103 | } | ||
104 | |||
105 | static Property riscv_cpu_properties[] = { | ||
106 | -- | ||
107 | 2.41.0 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
1 | 2 | ||
3 | After the introduction of riscv_cpu_options[] all properties in | ||
4 | riscv_cpu_extensions[] are booleans. This check is now obsolete. | ||
5 | |||
6 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
7 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
8 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> | ||
9 | Message-ID: <20230912132423.268494-3-dbarboza@ventanamicro.com> | ||
10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
11 | --- | ||
12 | target/riscv/cpu.c | 14 ++++---------- | ||
13 | 1 file changed, 4 insertions(+), 10 deletions(-) | ||
14 | |||
15 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | ||
16 | index XXXXXXX..XXXXXXX 100644 | ||
17 | --- a/target/riscv/cpu.c | ||
18 | +++ b/target/riscv/cpu.c | ||
19 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_add_user_properties(Object *obj) | ||
20 | * Set the default to disabled for every extension | ||
21 | * unknown to KVM and error out if the user attempts | ||
22 | * to enable any of them. | ||
23 | - * | ||
24 | - * We're giving a pass for non-bool properties since they're | ||
25 | - * not related to the availability of extensions and can be | ||
26 | - * safely ignored as is. | ||
27 | */ | ||
28 | - if (prop->info == &qdev_prop_bool) { | ||
29 | - object_property_add(obj, prop->name, "bool", | ||
30 | - NULL, cpu_set_cfg_unavailable, | ||
31 | - NULL, (void *)prop->name); | ||
32 | - continue; | ||
33 | - } | ||
34 | + object_property_add(obj, prop->name, "bool", | ||
35 | + NULL, cpu_set_cfg_unavailable, | ||
36 | + NULL, (void *)prop->name); | ||
37 | + continue; | ||
38 | } | ||
39 | #endif | ||
40 | qdev_property_add_static(dev, prop); | ||
41 | -- | ||
42 | 2.41.0 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
1 | 2 | ||
3 | Future patches will split the existing Property arrays even further, and | ||
4 | the existing code in riscv_cpu_add_user_properties() will start to scale | ||
5 | bad with it because it's dealing with KVM constraints mixed in with TCG | ||
6 | constraints. We're going to pay a high price to share a couple of common | ||
7 | lines of code between the two. | ||
8 | |||
9 | Create a new kvm_riscv_cpu_add_kvm_properties() helper that will be | ||
10 | forked from riscv_cpu_add_user_properties() if we're running KVM. The | ||
11 | helper includes all properties that a KVM CPU will add. The rest of | ||
12 | riscv_cpu_add_user_properties() body will then be relieved from having | ||
13 | to deal with KVM constraints. | ||
14 | |||
15 | The helper was declared in kvm_stubs.h, while being implemented in | ||
16 | cpu.c, to allow '--enable-debug' builds to work. The compiler won't | ||
17 | remove the kvm_riscv_cpu_add_kvm_properties() reference when | ||
18 | 'kvm_enabled()' is false if we end up with an unused function. Even | ||
19 | though being a KVM only helper we can't implement it in kvm.c due to its | ||
20 | many dependencies inside cpu.c, so make it public in kvm_riscv.h and | ||
21 | keep its implementation in cpu.c for now. We'll move it to kvm.c in the | ||
22 | near future. | ||
23 | |||
24 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
25 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> | ||
26 | Message-ID: <20230912132423.268494-4-dbarboza@ventanamicro.com> | ||
27 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
28 | --- | ||
29 | target/riscv/kvm_riscv.h | 3 ++ | ||
30 | target/riscv/cpu.c | 65 +++++++++++++++++++++++++--------------- | ||
31 | 2 files changed, 44 insertions(+), 24 deletions(-) | ||
32 | |||
33 | diff --git a/target/riscv/kvm_riscv.h b/target/riscv/kvm_riscv.h | ||
34 | index XXXXXXX..XXXXXXX 100644 | ||
35 | --- a/target/riscv/kvm_riscv.h | ||
36 | +++ b/target/riscv/kvm_riscv.h | ||
37 | @@ -XXX,XX +XXX,XX @@ | ||
38 | #ifndef QEMU_KVM_RISCV_H | ||
39 | #define QEMU_KVM_RISCV_H | ||
40 | |||
41 | +/* Temporarily implemented in cpu.c */ | ||
42 | +void kvm_riscv_cpu_add_kvm_properties(Object *obj); | ||
43 | + | ||
44 | void kvm_riscv_init_user_properties(Object *cpu_obj); | ||
45 | void kvm_riscv_reset_vcpu(RISCVCPU *cpu); | ||
46 | void kvm_riscv_set_irq(RISCVCPU *cpu, int irq, int level); | ||
47 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | ||
48 | index XXXXXXX..XXXXXXX 100644 | ||
49 | --- a/target/riscv/cpu.c | ||
50 | +++ b/target/riscv/cpu.c | ||
51 | @@ -XXX,XX +XXX,XX @@ static Property riscv_cpu_options[] = { | ||
52 | DEFINE_PROP_UINT16("cboz_blocksize", RISCVCPU, cfg.cboz_blocksize, 64), | ||
53 | }; | ||
54 | |||
55 | -#ifndef CONFIG_USER_ONLY | ||
56 | +#ifdef CONFIG_KVM | ||
57 | static void cpu_set_cfg_unavailable(Object *obj, Visitor *v, | ||
58 | const char *name, | ||
59 | void *opaque, Error **errp) | ||
60 | @@ -XXX,XX +XXX,XX @@ static void cpu_set_cfg_unavailable(Object *obj, Visitor *v, | ||
61 | propname); | ||
62 | } | ||
63 | } | ||
64 | + | ||
65 | +static void riscv_cpu_add_kvm_unavail_prop(Object *obj, const char *prop_name) | ||
66 | +{ | ||
67 | + /* Check if KVM created the property already */ | ||
68 | + if (object_property_find(obj, prop_name)) { | ||
69 | + return; | ||
70 | + } | ||
71 | + | ||
72 | + /* | ||
73 | + * Set the default to disabled for every extension | ||
74 | + * unknown to KVM and error out if the user attempts | ||
75 | + * to enable any of them. | ||
76 | + */ | ||
77 | + object_property_add(obj, prop_name, "bool", | ||
78 | + NULL, cpu_set_cfg_unavailable, | ||
79 | + NULL, (void *)prop_name); | ||
80 | +} | ||
81 | + | ||
82 | +void kvm_riscv_cpu_add_kvm_properties(Object *obj) | ||
83 | +{ | ||
84 | + Property *prop; | ||
85 | + DeviceState *dev = DEVICE(obj); | ||
86 | + | ||
87 | + kvm_riscv_init_user_properties(obj); | ||
88 | + riscv_cpu_add_misa_properties(obj); | ||
89 | + | ||
90 | + for (prop = riscv_cpu_extensions; prop && prop->name; prop++) { | ||
91 | + riscv_cpu_add_kvm_unavail_prop(obj, prop->name); | ||
92 | + } | ||
93 | + | ||
94 | + for (int i = 0; i < ARRAY_SIZE(riscv_cpu_options); i++) { | ||
95 | + /* Check if KVM created the property already */ | ||
96 | + if (object_property_find(obj, riscv_cpu_options[i].name)) { | ||
97 | + continue; | ||
98 | + } | ||
99 | + qdev_property_add_static(dev, &riscv_cpu_options[i]); | ||
100 | + } | ||
101 | +} | ||
102 | #endif | ||
103 | |||
104 | /* | ||
105 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_add_user_properties(Object *obj) | ||
106 | riscv_add_satp_mode_properties(obj); | ||
107 | |||
108 | if (kvm_enabled()) { | ||
109 | - kvm_riscv_init_user_properties(obj); | ||
110 | + kvm_riscv_cpu_add_kvm_properties(obj); | ||
111 | + return; | ||
112 | } | ||
113 | #endif | ||
114 | |||
115 | riscv_cpu_add_misa_properties(obj); | ||
116 | |||
117 | for (prop = riscv_cpu_extensions; prop && prop->name; prop++) { | ||
118 | -#ifndef CONFIG_USER_ONLY | ||
119 | - if (kvm_enabled()) { | ||
120 | - /* Check if KVM created the property already */ | ||
121 | - if (object_property_find(obj, prop->name)) { | ||
122 | - continue; | ||
123 | - } | ||
124 | - | ||
125 | - /* | ||
126 | - * Set the default to disabled for every extension | ||
127 | - * unknown to KVM and error out if the user attempts | ||
128 | - * to enable any of them. | ||
129 | - */ | ||
130 | - object_property_add(obj, prop->name, "bool", | ||
131 | - NULL, cpu_set_cfg_unavailable, | ||
132 | - NULL, (void *)prop->name); | ||
133 | - continue; | ||
134 | - } | ||
135 | -#endif | ||
136 | qdev_property_add_static(dev, prop); | ||
137 | } | ||
138 | |||
139 | for (int i = 0; i < ARRAY_SIZE(riscv_cpu_options); i++) { | ||
140 | - /* Check if KVM created the property already */ | ||
141 | - if (object_property_find(obj, riscv_cpu_options[i].name)) { | ||
142 | - continue; | ||
143 | - } | ||
144 | qdev_property_add_static(dev, &riscv_cpu_options[i]); | ||
145 | } | ||
146 | } | ||
147 | -- | ||
148 | 2.41.0 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
1 | 2 | ||
3 | Add DEFINE_PROP_END_OF_LIST() and eliminate the ARRAY_SIZE() usage when | ||
4 | iterating in the riscv_cpu_options[] array, making it similar to what | ||
5 | we already do when working with riscv_cpu_extensions[]. | ||
6 | |||
7 | We also have a more sophisticated motivation behind this change. In the | ||
8 | future we might need to export riscv_cpu_options[] to other files, and | ||
9 | ARRAY_LIST() doesn't work properly in that case because the array size | ||
10 | isn't exposed to the header file. Here's a future sight of what we would | ||
11 | deal with: | ||
12 | |||
13 | ./target/riscv/kvm.c:1057:5: error: nested extern declaration of 'riscv_cpu_add_misa_properties' [-Werror=nested-externs] | ||
14 | n file included from ../target/riscv/kvm.c:19: | ||
15 | home/danielhb/work/qemu/include/qemu/osdep.h:473:31: error: invalid application of 'sizeof' to incomplete type 'const RISCVCPUMultiExtConfig[]' | ||
16 | 473 | #define ARRAY_SIZE(x) ((sizeof(x) / sizeof((x)[0])) + \ | ||
17 | | ^ | ||
18 | ./target/riscv/kvm.c:1047:29: note: in expansion of macro 'ARRAY_SIZE' | ||
19 | 1047 | for (int i = 0; i < ARRAY_SIZE(_array); i++) { \ | ||
20 | | ^~~~~~~~~~ | ||
21 | ./target/riscv/kvm.c:1059:5: note: in expansion of macro 'ADD_UNAVAIL_KVM_PROP_ARRAY' | ||
22 | 1059 | ADD_UNAVAIL_KVM_PROP_ARRAY(obj, riscv_cpu_extensions); | ||
23 | | ^~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
24 | home/danielhb/work/qemu/include/qemu/osdep.h:473:31: error: invalid application of 'sizeof' to incomplete type 'const RISCVCPUMultiExtConfig[]' | ||
25 | 473 | #define ARRAY_SIZE(x) ((sizeof(x) / sizeof((x)[0])) + \ | ||
26 | | ^ | ||
27 | ./target/riscv/kvm.c:1047:29: note: in expansion of macro 'ARRAY_SIZE' | ||
28 | 1047 | for (int i = 0; i < ARRAY_SIZE(_array); i++) { \ | ||
29 | |||
30 | Homogenize the present and change the future by using | ||
31 | DEFINE_PROP_END_OF_LIST() in riscv_cpu_options[]. | ||
32 | |||
33 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
34 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> | ||
35 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
36 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | ||
37 | Message-ID: <20230912132423.268494-5-dbarboza@ventanamicro.com> | ||
38 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
39 | --- | ||
40 | target/riscv/cpu.c | 12 +++++++----- | ||
41 | 1 file changed, 7 insertions(+), 5 deletions(-) | ||
42 | |||
43 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | ||
44 | index XXXXXXX..XXXXXXX 100644 | ||
45 | --- a/target/riscv/cpu.c | ||
46 | +++ b/target/riscv/cpu.c | ||
47 | @@ -XXX,XX +XXX,XX @@ static Property riscv_cpu_options[] = { | ||
48 | |||
49 | DEFINE_PROP_UINT16("cbom_blocksize", RISCVCPU, cfg.cbom_blocksize, 64), | ||
50 | DEFINE_PROP_UINT16("cboz_blocksize", RISCVCPU, cfg.cboz_blocksize, 64), | ||
51 | + | ||
52 | + DEFINE_PROP_END_OF_LIST(), | ||
53 | }; | ||
54 | |||
55 | #ifdef CONFIG_KVM | ||
56 | @@ -XXX,XX +XXX,XX @@ void kvm_riscv_cpu_add_kvm_properties(Object *obj) | ||
57 | riscv_cpu_add_kvm_unavail_prop(obj, prop->name); | ||
58 | } | ||
59 | |||
60 | - for (int i = 0; i < ARRAY_SIZE(riscv_cpu_options); i++) { | ||
61 | + for (prop = riscv_cpu_options; prop && prop->name; prop++) { | ||
62 | /* Check if KVM created the property already */ | ||
63 | - if (object_property_find(obj, riscv_cpu_options[i].name)) { | ||
64 | + if (object_property_find(obj, prop->name)) { | ||
65 | continue; | ||
66 | } | ||
67 | - qdev_property_add_static(dev, &riscv_cpu_options[i]); | ||
68 | + qdev_property_add_static(dev, prop); | ||
69 | } | ||
70 | } | ||
71 | #endif | ||
72 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_add_user_properties(Object *obj) | ||
73 | qdev_property_add_static(dev, prop); | ||
74 | } | ||
75 | |||
76 | - for (int i = 0; i < ARRAY_SIZE(riscv_cpu_options); i++) { | ||
77 | - qdev_property_add_static(dev, &riscv_cpu_options[i]); | ||
78 | + for (prop = riscv_cpu_options; prop && prop->name; prop++) { | ||
79 | + qdev_property_add_static(dev, prop); | ||
80 | } | ||
81 | } | ||
82 | |||
83 | -- | ||
84 | 2.41.0 | ||
85 | |||
86 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
1 | 2 | ||
3 | Create a new riscv_cpu_experimental_exts[] to store the non-ratified | ||
4 | extensions properties. Once they are ratified we'll move them back to | ||
5 | riscv_cpu_extensions[]. | ||
6 | |||
7 | riscv_cpu_add_user_properties() and riscv_cpu_add_kvm_properties() are | ||
8 | changed to keep adding non-ratified properties to users. | ||
9 | |||
10 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
11 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
12 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> | ||
13 | Message-ID: <20230912132423.268494-6-dbarboza@ventanamicro.com> | ||
14 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
15 | --- | ||
16 | target/riscv/cpu.c | 13 ++++++++++++- | ||
17 | 1 file changed, 12 insertions(+), 1 deletion(-) | ||
18 | |||
19 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | ||
20 | index XXXXXXX..XXXXXXX 100644 | ||
21 | --- a/target/riscv/cpu.c | ||
22 | +++ b/target/riscv/cpu.c | ||
23 | @@ -XXX,XX +XXX,XX @@ static Property riscv_cpu_extensions[] = { | ||
24 | DEFINE_PROP_BOOL("xtheadsync", RISCVCPU, cfg.ext_xtheadsync, false), | ||
25 | DEFINE_PROP_BOOL("xventanacondops", RISCVCPU, cfg.ext_XVentanaCondOps, false), | ||
26 | |||
27 | - /* These are experimental so mark with 'x-' */ | ||
28 | + DEFINE_PROP_END_OF_LIST(), | ||
29 | +}; | ||
30 | |||
31 | +/* These are experimental so mark with 'x-' */ | ||
32 | +static Property riscv_cpu_experimental_exts[] = { | ||
33 | /* ePMP 0.9.3 */ | ||
34 | DEFINE_PROP_BOOL("x-epmp", RISCVCPU, cfg.epmp, false), | ||
35 | DEFINE_PROP_BOOL("x-smaia", RISCVCPU, cfg.ext_smaia, false), | ||
36 | @@ -XXX,XX +XXX,XX @@ void kvm_riscv_cpu_add_kvm_properties(Object *obj) | ||
37 | riscv_cpu_add_kvm_unavail_prop(obj, prop->name); | ||
38 | } | ||
39 | |||
40 | + for (prop = riscv_cpu_experimental_exts; prop && prop->name; prop++) { | ||
41 | + riscv_cpu_add_kvm_unavail_prop(obj, prop->name); | ||
42 | + } | ||
43 | + | ||
44 | for (prop = riscv_cpu_options; prop && prop->name; prop++) { | ||
45 | /* Check if KVM created the property already */ | ||
46 | if (object_property_find(obj, prop->name)) { | ||
47 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_add_user_properties(Object *obj) | ||
48 | for (prop = riscv_cpu_options; prop && prop->name; prop++) { | ||
49 | qdev_property_add_static(dev, prop); | ||
50 | } | ||
51 | + | ||
52 | + for (prop = riscv_cpu_experimental_exts; prop && prop->name; prop++) { | ||
53 | + qdev_property_add_static(dev, prop); | ||
54 | + } | ||
55 | } | ||
56 | |||
57 | static Property riscv_cpu_properties[] = { | ||
58 | -- | ||
59 | 2.41.0 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
1 | 2 | ||
3 | Our goal is to make riscv_cpu_extensions[] hold only ratified, | ||
4 | non-vendor extensions. | ||
5 | |||
6 | Create a new riscv_cpu_vendor_exts[] array for them, changing | ||
7 | riscv_cpu_add_user_properties() and riscv_cpu_add_kvm_properties() | ||
8 | accordingly. | ||
9 | |||
10 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
11 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
12 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> | ||
13 | Message-ID: <20230912132423.268494-7-dbarboza@ventanamicro.com> | ||
14 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
15 | --- | ||
16 | target/riscv/cpu.c | 13 ++++++++++++- | ||
17 | 1 file changed, 12 insertions(+), 1 deletion(-) | ||
18 | |||
19 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | ||
20 | index XXXXXXX..XXXXXXX 100644 | ||
21 | --- a/target/riscv/cpu.c | ||
22 | +++ b/target/riscv/cpu.c | ||
23 | @@ -XXX,XX +XXX,XX @@ static Property riscv_cpu_extensions[] = { | ||
24 | DEFINE_PROP_BOOL("zcmt", RISCVCPU, cfg.ext_zcmt, false), | ||
25 | DEFINE_PROP_BOOL("zicond", RISCVCPU, cfg.ext_zicond, false), | ||
26 | |||
27 | - /* Vendor-specific custom extensions */ | ||
28 | + DEFINE_PROP_END_OF_LIST(), | ||
29 | +}; | ||
30 | + | ||
31 | +static Property riscv_cpu_vendor_exts[] = { | ||
32 | DEFINE_PROP_BOOL("xtheadba", RISCVCPU, cfg.ext_xtheadba, false), | ||
33 | DEFINE_PROP_BOOL("xtheadbb", RISCVCPU, cfg.ext_xtheadbb, false), | ||
34 | DEFINE_PROP_BOOL("xtheadbs", RISCVCPU, cfg.ext_xtheadbs, false), | ||
35 | @@ -XXX,XX +XXX,XX @@ void kvm_riscv_cpu_add_kvm_properties(Object *obj) | ||
36 | riscv_cpu_add_kvm_unavail_prop(obj, prop->name); | ||
37 | } | ||
38 | |||
39 | + for (prop = riscv_cpu_vendor_exts; prop && prop->name; prop++) { | ||
40 | + riscv_cpu_add_kvm_unavail_prop(obj, prop->name); | ||
41 | + } | ||
42 | + | ||
43 | for (prop = riscv_cpu_experimental_exts; prop && prop->name; prop++) { | ||
44 | riscv_cpu_add_kvm_unavail_prop(obj, prop->name); | ||
45 | } | ||
46 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_add_user_properties(Object *obj) | ||
47 | qdev_property_add_static(dev, prop); | ||
48 | } | ||
49 | |||
50 | + for (prop = riscv_cpu_vendor_exts; prop && prop->name; prop++) { | ||
51 | + qdev_property_add_static(dev, prop); | ||
52 | + } | ||
53 | + | ||
54 | for (prop = riscv_cpu_experimental_exts; prop && prop->name; prop++) { | ||
55 | qdev_property_add_static(dev, prop); | ||
56 | } | ||
57 | -- | ||
58 | 2.41.0 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
1 | 2 | ||
3 | The code inside riscv_cpu_add_user_properties() became quite repetitive | ||
4 | after recent changes. Add a helper to hide the repetition away. | ||
5 | |||
6 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
7 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> | ||
8 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
9 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | ||
10 | Message-ID: <20230912132423.268494-8-dbarboza@ventanamicro.com> | ||
11 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
12 | --- | ||
13 | target/riscv/cpu.c | 29 +++++++++++++---------------- | ||
14 | 1 file changed, 13 insertions(+), 16 deletions(-) | ||
15 | |||
16 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | ||
17 | index XXXXXXX..XXXXXXX 100644 | ||
18 | --- a/target/riscv/cpu.c | ||
19 | +++ b/target/riscv/cpu.c | ||
20 | @@ -XXX,XX +XXX,XX @@ static Property riscv_cpu_options[] = { | ||
21 | DEFINE_PROP_END_OF_LIST(), | ||
22 | }; | ||
23 | |||
24 | +static void riscv_cpu_add_qdev_prop_array(DeviceState *dev, Property *array) | ||
25 | +{ | ||
26 | + g_assert(array); | ||
27 | + | ||
28 | + for (Property *prop = array; prop && prop->name; prop++) { | ||
29 | + qdev_property_add_static(dev, prop); | ||
30 | + } | ||
31 | +} | ||
32 | + | ||
33 | #ifdef CONFIG_KVM | ||
34 | static void cpu_set_cfg_unavailable(Object *obj, Visitor *v, | ||
35 | const char *name, | ||
36 | @@ -XXX,XX +XXX,XX @@ void kvm_riscv_cpu_add_kvm_properties(Object *obj) | ||
37 | */ | ||
38 | static void riscv_cpu_add_user_properties(Object *obj) | ||
39 | { | ||
40 | - Property *prop; | ||
41 | DeviceState *dev = DEVICE(obj); | ||
42 | |||
43 | #ifndef CONFIG_USER_ONLY | ||
44 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_add_user_properties(Object *obj) | ||
45 | |||
46 | riscv_cpu_add_misa_properties(obj); | ||
47 | |||
48 | - for (prop = riscv_cpu_extensions; prop && prop->name; prop++) { | ||
49 | - qdev_property_add_static(dev, prop); | ||
50 | - } | ||
51 | - | ||
52 | - for (prop = riscv_cpu_options; prop && prop->name; prop++) { | ||
53 | - qdev_property_add_static(dev, prop); | ||
54 | - } | ||
55 | - | ||
56 | - for (prop = riscv_cpu_vendor_exts; prop && prop->name; prop++) { | ||
57 | - qdev_property_add_static(dev, prop); | ||
58 | - } | ||
59 | - | ||
60 | - for (prop = riscv_cpu_experimental_exts; prop && prop->name; prop++) { | ||
61 | - qdev_property_add_static(dev, prop); | ||
62 | - } | ||
63 | + riscv_cpu_add_qdev_prop_array(dev, riscv_cpu_extensions); | ||
64 | + riscv_cpu_add_qdev_prop_array(dev, riscv_cpu_options); | ||
65 | + riscv_cpu_add_qdev_prop_array(dev, riscv_cpu_vendor_exts); | ||
66 | + riscv_cpu_add_qdev_prop_array(dev, riscv_cpu_experimental_exts); | ||
67 | } | ||
68 | |||
69 | static Property riscv_cpu_properties[] = { | ||
70 | -- | ||
71 | 2.41.0 | ||
72 | |||
73 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
1 | 2 | ||
3 | Use a helper in riscv_cpu_add_kvm_properties() to eliminate some of its | ||
4 | code repetition. | ||
5 | |||
6 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
7 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> | ||
8 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
9 | Message-ID: <20230912132423.268494-9-dbarboza@ventanamicro.com> | ||
10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
11 | --- | ||
12 | target/riscv/cpu.c | 24 +++++++++++++----------- | ||
13 | 1 file changed, 13 insertions(+), 11 deletions(-) | ||
14 | |||
15 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | ||
16 | index XXXXXXX..XXXXXXX 100644 | ||
17 | --- a/target/riscv/cpu.c | ||
18 | +++ b/target/riscv/cpu.c | ||
19 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_add_kvm_unavail_prop(Object *obj, const char *prop_name) | ||
20 | NULL, (void *)prop_name); | ||
21 | } | ||
22 | |||
23 | +static void riscv_cpu_add_kvm_unavail_prop_array(Object *obj, | ||
24 | + Property *array) | ||
25 | +{ | ||
26 | + g_assert(array); | ||
27 | + | ||
28 | + for (Property *prop = array; prop && prop->name; prop++) { | ||
29 | + riscv_cpu_add_kvm_unavail_prop(obj, prop->name); | ||
30 | + } | ||
31 | +} | ||
32 | + | ||
33 | void kvm_riscv_cpu_add_kvm_properties(Object *obj) | ||
34 | { | ||
35 | Property *prop; | ||
36 | @@ -XXX,XX +XXX,XX @@ void kvm_riscv_cpu_add_kvm_properties(Object *obj) | ||
37 | kvm_riscv_init_user_properties(obj); | ||
38 | riscv_cpu_add_misa_properties(obj); | ||
39 | |||
40 | - for (prop = riscv_cpu_extensions; prop && prop->name; prop++) { | ||
41 | - riscv_cpu_add_kvm_unavail_prop(obj, prop->name); | ||
42 | - } | ||
43 | - | ||
44 | - for (prop = riscv_cpu_vendor_exts; prop && prop->name; prop++) { | ||
45 | - riscv_cpu_add_kvm_unavail_prop(obj, prop->name); | ||
46 | - } | ||
47 | - | ||
48 | - for (prop = riscv_cpu_experimental_exts; prop && prop->name; prop++) { | ||
49 | - riscv_cpu_add_kvm_unavail_prop(obj, prop->name); | ||
50 | - } | ||
51 | + riscv_cpu_add_kvm_unavail_prop_array(obj, riscv_cpu_extensions); | ||
52 | + riscv_cpu_add_kvm_unavail_prop_array(obj, riscv_cpu_vendor_exts); | ||
53 | + riscv_cpu_add_kvm_unavail_prop_array(obj, riscv_cpu_experimental_exts); | ||
54 | |||
55 | for (prop = riscv_cpu_options; prop && prop->name; prop++) { | ||
56 | /* Check if KVM created the property already */ | ||
57 | -- | ||
58 | 2.41.0 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
1 | 2 | ||
3 | Inside riscv_cpu_validate_v() we're always throwing a log message if the | ||
4 | user didn't set a vector version via 'vext_spec'. | ||
5 | |||
6 | We're going to include one case with the 'max' CPU where env->vext_ver | ||
7 | will be set in the cpu_init(). But that alone will not stop the "vector | ||
8 | version is not specified" message from appearing. The usefulness of this | ||
9 | log message is debatable for the generic CPUs, but for a 'max' CPU type, | ||
10 | where we are supposed to deliver a CPU model with all features possible, | ||
11 | it's strange to force users to set 'vext_spec' to get rid of this | ||
12 | message. | ||
13 | |||
14 | Change riscv_cpu_validate_v() to not throw this log message if | ||
15 | env->vext_ver is already set. | ||
16 | |||
17 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
18 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
19 | Reviewed-by: Weiwei Li <liweiwei@iscas.ac.cn> | ||
20 | Message-ID: <20230912132423.268494-10-dbarboza@ventanamicro.com> | ||
21 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
22 | --- | ||
23 | target/riscv/cpu.c | 9 ++++----- | ||
24 | 1 file changed, 4 insertions(+), 5 deletions(-) | ||
25 | |||
26 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | ||
27 | index XXXXXXX..XXXXXXX 100644 | ||
28 | --- a/target/riscv/cpu.c | ||
29 | +++ b/target/riscv/cpu.c | ||
30 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_disas_set_info(CPUState *s, disassemble_info *info) | ||
31 | static void riscv_cpu_validate_v(CPURISCVState *env, RISCVCPUConfig *cfg, | ||
32 | Error **errp) | ||
33 | { | ||
34 | - int vext_version = VEXT_VERSION_1_00_0; | ||
35 | - | ||
36 | if (!is_power_of_2(cfg->vlen)) { | ||
37 | error_setg(errp, "Vector extension VLEN must be power of 2"); | ||
38 | return; | ||
39 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_validate_v(CPURISCVState *env, RISCVCPUConfig *cfg, | ||
40 | } | ||
41 | if (cfg->vext_spec) { | ||
42 | if (!g_strcmp0(cfg->vext_spec, "v1.0")) { | ||
43 | - vext_version = VEXT_VERSION_1_00_0; | ||
44 | + env->vext_ver = VEXT_VERSION_1_00_0; | ||
45 | } else { | ||
46 | error_setg(errp, "Unsupported vector spec version '%s'", | ||
47 | cfg->vext_spec); | ||
48 | return; | ||
49 | } | ||
50 | - } else { | ||
51 | + } else if (env->vext_ver == 0) { | ||
52 | qemu_log("vector version is not specified, " | ||
53 | "use the default value v1.0\n"); | ||
54 | + | ||
55 | + env->vext_ver = VEXT_VERSION_1_00_0; | ||
56 | } | ||
57 | - env->vext_ver = vext_version; | ||
58 | } | ||
59 | |||
60 | static void riscv_cpu_validate_priv_spec(RISCVCPU *cpu, Error **errp) | ||
61 | -- | ||
62 | 2.41.0 | diff view generated by jsdifflib |
1 | From: Alistair Francis <alistair.francis@wdc.com> | 1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
---|---|---|---|
2 | 2 | ||
3 | Create a platform bus to allow dynamic devices to be connected. This is | 3 | The 'max' CPU type is used by tooling to determine what's the most |
4 | based on the ARM implementation. | 4 | capable CPU a current QEMU version implements. Other archs such as ARM |
5 | implements this type. Let's add it to RISC-V. | ||
5 | 6 | ||
6 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 7 | What we consider "most capable CPU" in this context are related to |
7 | Reviewed-by: Edgar E. Iglesias <edgar.iglesias@amd.com> | 8 | ratified, non-vendor extensions. This means that we want the 'max' CPU |
8 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> | 9 | to enable all (possible) ratified extensions by default. The reasoning |
9 | Message-Id: <20220427234146.1130752-4-alistair.francis@opensource.wdc.com> | 10 | behind this design is (1) vendor extensions can conflict with each other |
11 | and we won't play favorities deciding which one is default or not and | ||
12 | (2) non-ratified extensions are always prone to changes, not being | ||
13 | stable enough to be enabled by default. | ||
14 | |||
15 | All this said, we're still not able to enable all ratified extensions | ||
16 | due to conflicts between them. Zfinx and all its dependencies aren't | ||
17 | enabled because of a conflict with RVF. zce, zcmp and zcmt are also | ||
18 | disabled due to RVD conflicts. When running with 64 bits we're also | ||
19 | disabling zcf. | ||
20 | |||
21 | MISA bits RVG, RVJ and RVV are also being set manually since they're | ||
22 | default disabled. | ||
23 | |||
24 | This is the resulting 'riscv,isa' DT for this new CPU: | ||
25 | |||
26 | rv64imafdcvh_zicbom_zicboz_zicsr_zifencei_zihintpause_zawrs_zfa_ | ||
27 | zfh_zfhmin_zca_zcb_zcd_zba_zbb_zbc_zbkb_zbkc_zbkx_zbs_zk_zkn_zknd_ | ||
28 | zkne_zknh_zkr_zks_zksed_zksh_zkt_zve32f_zve64f_zve64d_ | ||
29 | smstateen_sscofpmf_sstc_svadu_svinval_svnapot_svpbmt | ||
30 | |||
31 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
32 | Reviewed-by: Weiwei Li <liweiwei@iscas.ac.cn> | ||
33 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
34 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> | ||
35 | Message-ID: <20230912132423.268494-11-dbarboza@ventanamicro.com> | ||
10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 36 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
11 | --- | 37 | --- |
12 | include/hw/riscv/virt.h | 7 ++++- | 38 | target/riscv/cpu-qom.h | 1 + |
13 | hw/riscv/virt.c | 68 +++++++++++++++++++++++++++++------------ | 39 | target/riscv/cpu.c | 56 ++++++++++++++++++++++++++++++++++++++++++ |
14 | hw/riscv/Kconfig | 1 + | 40 | 2 files changed, 57 insertions(+) |
15 | 3 files changed, 56 insertions(+), 20 deletions(-) | ||
16 | 41 | ||
17 | diff --git a/include/hw/riscv/virt.h b/include/hw/riscv/virt.h | 42 | diff --git a/target/riscv/cpu-qom.h b/target/riscv/cpu-qom.h |
18 | index XXXXXXX..XXXXXXX 100644 | 43 | index XXXXXXX..XXXXXXX 100644 |
19 | --- a/include/hw/riscv/virt.h | 44 | --- a/target/riscv/cpu-qom.h |
20 | +++ b/include/hw/riscv/virt.h | 45 | +++ b/target/riscv/cpu-qom.h |
21 | @@ -XXX,XX +XXX,XX @@ struct RISCVVirtState { | 46 | @@ -XXX,XX +XXX,XX @@ |
22 | 47 | #define CPU_RESOLVING_TYPE TYPE_RISCV_CPU | |
23 | /*< public >*/ | 48 | |
24 | Notifier machine_done; | 49 | #define TYPE_RISCV_CPU_ANY RISCV_CPU_TYPE_NAME("any") |
25 | + DeviceState *platform_bus_dev; | 50 | +#define TYPE_RISCV_CPU_MAX RISCV_CPU_TYPE_NAME("max") |
26 | RISCVHartArrayState soc[VIRT_SOCKETS_MAX]; | 51 | #define TYPE_RISCV_CPU_BASE32 RISCV_CPU_TYPE_NAME("rv32") |
27 | DeviceState *irqchip[VIRT_SOCKETS_MAX]; | 52 | #define TYPE_RISCV_CPU_BASE64 RISCV_CPU_TYPE_NAME("rv64") |
28 | PFlashCFI01 *flash[2]; | 53 | #define TYPE_RISCV_CPU_BASE128 RISCV_CPU_TYPE_NAME("x-rv128") |
29 | @@ -XXX,XX +XXX,XX @@ enum { | 54 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c |
30 | VIRT_DRAM, | 55 | index XXXXXXX..XXXXXXX 100644 |
31 | VIRT_PCIE_MMIO, | 56 | --- a/target/riscv/cpu.c |
32 | VIRT_PCIE_PIO, | 57 | +++ b/target/riscv/cpu.c |
33 | + VIRT_PLATFORM_BUS, | 58 | @@ -XXX,XX +XXX,XX @@ static const char * const riscv_intr_names[] = { |
34 | VIRT_PCIE_ECAM | ||
35 | }; | 59 | }; |
36 | 60 | ||
37 | @@ -XXX,XX +XXX,XX @@ enum { | 61 | static void riscv_cpu_add_user_properties(Object *obj); |
38 | VIRTIO_IRQ = 1, /* 1 to 8 */ | 62 | +static void riscv_init_max_cpu_extensions(Object *obj); |
39 | VIRTIO_COUNT = 8, | 63 | |
40 | PCIE_IRQ = 0x20, /* 32 to 35 */ | 64 | const char *riscv_cpu_get_trap_name(target_ulong cause, bool async) |
41 | - VIRTIO_NDEV = 0x35 /* Arbitrary maximum number of interrupts */ | 65 | { |
42 | + VIRT_PLATFORM_BUS_IRQ = 64, /* 64 to 96 */ | 66 | @@ -XXX,XX +XXX,XX @@ static void riscv_any_cpu_init(Object *obj) |
43 | + VIRTIO_NDEV = 96 /* Arbitrary maximum number of interrupts */ | 67 | cpu->cfg.pmp = true; |
44 | }; | 68 | } |
45 | 69 | ||
46 | +#define VIRT_PLATFORM_BUS_NUM_IRQS 32 | 70 | +static void riscv_max_cpu_init(Object *obj) |
71 | +{ | ||
72 | + RISCVCPU *cpu = RISCV_CPU(obj); | ||
73 | + CPURISCVState *env = &cpu->env; | ||
74 | + RISCVMXL mlx = MXL_RV64; | ||
47 | + | 75 | + |
48 | #define VIRT_IRQCHIP_IPI_MSI 1 | 76 | +#ifdef TARGET_RISCV32 |
49 | #define VIRT_IRQCHIP_NUM_MSIS 255 | 77 | + mlx = MXL_RV32; |
50 | #define VIRT_IRQCHIP_NUM_SOURCES VIRTIO_NDEV | 78 | +#endif |
51 | diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c | 79 | + set_misa(env, mlx, 0); |
52 | index XXXXXXX..XXXXXXX 100644 | 80 | + riscv_cpu_add_user_properties(obj); |
53 | --- a/hw/riscv/virt.c | 81 | + riscv_init_max_cpu_extensions(obj); |
54 | +++ b/hw/riscv/virt.c | 82 | + env->priv_ver = PRIV_VERSION_LATEST; |
55 | @@ -XXX,XX +XXX,XX @@ | 83 | +#ifndef CONFIG_USER_ONLY |
56 | #include "hw/intc/riscv_imsic.h" | 84 | + set_satp_mode_max_supported(RISCV_CPU(obj), mlx == MXL_RV32 ? |
57 | #include "hw/intc/sifive_plic.h" | 85 | + VM_1_10_SV32 : VM_1_10_SV57); |
58 | #include "hw/misc/sifive_test.h" | 86 | +#endif |
59 | +#include "hw/platform-bus.h" | 87 | +} |
60 | #include "chardev/char.h" | 88 | + |
61 | #include "sysemu/device_tree.h" | 89 | #if defined(TARGET_RISCV64) |
62 | #include "sysemu/sysemu.h" | 90 | static void rv64_base_cpu_init(Object *obj) |
63 | @@ -XXX,XX +XXX,XX @@ | 91 | { |
64 | #endif | 92 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_add_user_properties(Object *obj) |
65 | 93 | riscv_cpu_add_qdev_prop_array(dev, riscv_cpu_experimental_exts); | |
66 | static const MemMapEntry virt_memmap[] = { | ||
67 | - [VIRT_DEBUG] = { 0x0, 0x100 }, | ||
68 | - [VIRT_MROM] = { 0x1000, 0xf000 }, | ||
69 | - [VIRT_TEST] = { 0x100000, 0x1000 }, | ||
70 | - [VIRT_RTC] = { 0x101000, 0x1000 }, | ||
71 | - [VIRT_CLINT] = { 0x2000000, 0x10000 }, | ||
72 | - [VIRT_ACLINT_SSWI] = { 0x2F00000, 0x4000 }, | ||
73 | - [VIRT_PCIE_PIO] = { 0x3000000, 0x10000 }, | ||
74 | - [VIRT_PLIC] = { 0xc000000, VIRT_PLIC_SIZE(VIRT_CPUS_MAX * 2) }, | ||
75 | - [VIRT_APLIC_M] = { 0xc000000, APLIC_SIZE(VIRT_CPUS_MAX) }, | ||
76 | - [VIRT_APLIC_S] = { 0xd000000, APLIC_SIZE(VIRT_CPUS_MAX) }, | ||
77 | - [VIRT_UART0] = { 0x10000000, 0x100 }, | ||
78 | - [VIRT_VIRTIO] = { 0x10001000, 0x1000 }, | ||
79 | - [VIRT_FW_CFG] = { 0x10100000, 0x18 }, | ||
80 | - [VIRT_FLASH] = { 0x20000000, 0x4000000 }, | ||
81 | - [VIRT_IMSIC_M] = { 0x24000000, VIRT_IMSIC_MAX_SIZE }, | ||
82 | - [VIRT_IMSIC_S] = { 0x28000000, VIRT_IMSIC_MAX_SIZE }, | ||
83 | - [VIRT_PCIE_ECAM] = { 0x30000000, 0x10000000 }, | ||
84 | - [VIRT_PCIE_MMIO] = { 0x40000000, 0x40000000 }, | ||
85 | - [VIRT_DRAM] = { 0x80000000, 0x0 }, | ||
86 | + [VIRT_DEBUG] = { 0x0, 0x100 }, | ||
87 | + [VIRT_MROM] = { 0x1000, 0xf000 }, | ||
88 | + [VIRT_TEST] = { 0x100000, 0x1000 }, | ||
89 | + [VIRT_RTC] = { 0x101000, 0x1000 }, | ||
90 | + [VIRT_CLINT] = { 0x2000000, 0x10000 }, | ||
91 | + [VIRT_ACLINT_SSWI] = { 0x2F00000, 0x4000 }, | ||
92 | + [VIRT_PCIE_PIO] = { 0x3000000, 0x10000 }, | ||
93 | + [VIRT_PLATFORM_BUS] = { 0x4000000, 0x2000000 }, | ||
94 | + [VIRT_PLIC] = { 0xc000000, VIRT_PLIC_SIZE(VIRT_CPUS_MAX * 2) }, | ||
95 | + [VIRT_APLIC_M] = { 0xc000000, APLIC_SIZE(VIRT_CPUS_MAX) }, | ||
96 | + [VIRT_APLIC_S] = { 0xd000000, APLIC_SIZE(VIRT_CPUS_MAX) }, | ||
97 | + [VIRT_UART0] = { 0x10000000, 0x100 }, | ||
98 | + [VIRT_VIRTIO] = { 0x10001000, 0x1000 }, | ||
99 | + [VIRT_FW_CFG] = { 0x10100000, 0x18 }, | ||
100 | + [VIRT_FLASH] = { 0x20000000, 0x4000000 }, | ||
101 | + [VIRT_IMSIC_M] = { 0x24000000, VIRT_IMSIC_MAX_SIZE }, | ||
102 | + [VIRT_IMSIC_S] = { 0x28000000, VIRT_IMSIC_MAX_SIZE }, | ||
103 | + [VIRT_PCIE_ECAM] = { 0x30000000, 0x10000000 }, | ||
104 | + [VIRT_PCIE_MMIO] = { 0x40000000, 0x40000000 }, | ||
105 | + [VIRT_DRAM] = { 0x80000000, 0x0 }, | ||
106 | }; | ||
107 | |||
108 | /* PCIe high mmio is fixed for RV32 */ | ||
109 | @@ -XXX,XX +XXX,XX @@ static DeviceState *virt_create_aia(RISCVVirtAIAType aia_type, int aia_guests, | ||
110 | return aplic_m; | ||
111 | } | 94 | } |
112 | 95 | ||
113 | +static void create_platform_bus(RISCVVirtState *s, DeviceState *irqchip) | 96 | +/* |
97 | + * The 'max' type CPU will have all possible ratified | ||
98 | + * non-vendor extensions enabled. | ||
99 | + */ | ||
100 | +static void riscv_init_max_cpu_extensions(Object *obj) | ||
114 | +{ | 101 | +{ |
115 | + DeviceState *dev; | 102 | + RISCVCPU *cpu = RISCV_CPU(obj); |
116 | + SysBusDevice *sysbus; | 103 | + CPURISCVState *env = &cpu->env; |
117 | + const MemMapEntry *memmap = virt_memmap; | 104 | + Property *prop; |
118 | + int i; | ||
119 | + MemoryRegion *sysmem = get_system_memory(); | ||
120 | + | 105 | + |
121 | + dev = qdev_new(TYPE_PLATFORM_BUS_DEVICE); | 106 | + /* Enable RVG, RVJ and RVV that are disabled by default */ |
122 | + dev->id = g_strdup(TYPE_PLATFORM_BUS_DEVICE); | 107 | + set_misa(env, env->misa_mxl, env->misa_ext | RVG | RVJ | RVV); |
123 | + qdev_prop_set_uint32(dev, "num_irqs", VIRT_PLATFORM_BUS_NUM_IRQS); | ||
124 | + qdev_prop_set_uint32(dev, "mmio_size", memmap[VIRT_PLATFORM_BUS].size); | ||
125 | + sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); | ||
126 | + s->platform_bus_dev = dev; | ||
127 | + | 108 | + |
128 | + sysbus = SYS_BUS_DEVICE(dev); | 109 | + for (prop = riscv_cpu_extensions; prop && prop->name; prop++) { |
129 | + for (i = 0; i < VIRT_PLATFORM_BUS_NUM_IRQS; i++) { | 110 | + object_property_set_bool(obj, prop->name, true, NULL); |
130 | + int irq = VIRT_PLATFORM_BUS_IRQ + i; | ||
131 | + sysbus_connect_irq(sysbus, i, qdev_get_gpio_in(irqchip, irq)); | ||
132 | + } | 111 | + } |
133 | + | 112 | + |
134 | + memory_region_add_subregion(sysmem, | 113 | + /* set vector version */ |
135 | + memmap[VIRT_PLATFORM_BUS].base, | 114 | + env->vext_ver = VEXT_VERSION_1_00_0; |
136 | + sysbus_mmio_get_region(sysbus, 0)); | 115 | + |
116 | + /* Zfinx is not compatible with F. Disable it */ | ||
117 | + object_property_set_bool(obj, "zfinx", false, NULL); | ||
118 | + object_property_set_bool(obj, "zdinx", false, NULL); | ||
119 | + object_property_set_bool(obj, "zhinx", false, NULL); | ||
120 | + object_property_set_bool(obj, "zhinxmin", false, NULL); | ||
121 | + | ||
122 | + object_property_set_bool(obj, "zce", false, NULL); | ||
123 | + object_property_set_bool(obj, "zcmp", false, NULL); | ||
124 | + object_property_set_bool(obj, "zcmt", false, NULL); | ||
125 | + | ||
126 | + if (env->misa_mxl != MXL_RV32) { | ||
127 | + object_property_set_bool(obj, "zcf", false, NULL); | ||
128 | + } | ||
137 | +} | 129 | +} |
138 | + | 130 | + |
139 | static void virt_machine_done(Notifier *notifier, void *data) | 131 | static Property riscv_cpu_properties[] = { |
140 | { | 132 | DEFINE_PROP_BOOL("debug", RISCVCPU, cfg.debug, true), |
141 | RISCVVirtState *s = container_of(notifier, RISCVVirtState, | 133 | |
142 | @@ -XXX,XX +XXX,XX @@ static void virt_machine_init(MachineState *machine) | 134 | @@ -XXX,XX +XXX,XX @@ static const TypeInfo riscv_cpu_type_infos[] = { |
143 | memmap[VIRT_PCIE_PIO].base, | 135 | .abstract = true, |
144 | DEVICE(pcie_irqchip)); | 136 | }, |
145 | 137 | DEFINE_DYNAMIC_CPU(TYPE_RISCV_CPU_ANY, riscv_any_cpu_init), | |
146 | + create_platform_bus(s, DEVICE(mmio_irqchip)); | 138 | + DEFINE_DYNAMIC_CPU(TYPE_RISCV_CPU_MAX, riscv_max_cpu_init), |
147 | + | 139 | #if defined(CONFIG_KVM) |
148 | serial_mm_init(system_memory, memmap[VIRT_UART0].base, | 140 | DEFINE_CPU(TYPE_RISCV_CPU_HOST, riscv_host_cpu_init), |
149 | 0, qdev_get_gpio_in(DEVICE(mmio_irqchip), UART0_IRQ), 399193, | 141 | #endif |
150 | serial_hd(0), DEVICE_LITTLE_ENDIAN); | ||
151 | diff --git a/hw/riscv/Kconfig b/hw/riscv/Kconfig | ||
152 | index XXXXXXX..XXXXXXX 100644 | ||
153 | --- a/hw/riscv/Kconfig | ||
154 | +++ b/hw/riscv/Kconfig | ||
155 | @@ -XXX,XX +XXX,XX @@ config RISCV_VIRT | ||
156 | select SIFIVE_TEST | ||
157 | select VIRTIO_MMIO | ||
158 | select FW_CFG_DMA | ||
159 | + select PLATFORM_BUS | ||
160 | |||
161 | config SIFIVE_E | ||
162 | bool | ||
163 | -- | 142 | -- |
164 | 2.35.1 | 143 | 2.41.0 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
1 | 2 | ||
3 | Add smoke tests to ensure that we'll not break the 'max' CPU type when | ||
4 | adding new frozen/ratified RISC-V extensions. | ||
5 | |||
6 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
7 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
8 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | ||
9 | Tested-by: Philippe Mathieu-Daudé <philmd@linaro.org> | ||
10 | Message-ID: <20230912132423.268494-12-dbarboza@ventanamicro.com> | ||
11 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
12 | --- | ||
13 | tests/avocado/tuxrun_baselines.py | 32 +++++++++++++++++++++++++++++++ | ||
14 | 1 file changed, 32 insertions(+) | ||
15 | |||
16 | diff --git a/tests/avocado/tuxrun_baselines.py b/tests/avocado/tuxrun_baselines.py | ||
17 | index XXXXXXX..XXXXXXX 100644 | ||
18 | --- a/tests/avocado/tuxrun_baselines.py | ||
19 | +++ b/tests/avocado/tuxrun_baselines.py | ||
20 | @@ -XXX,XX +XXX,XX @@ def test_riscv64(self): | ||
21 | |||
22 | self.common_tuxrun(csums=sums) | ||
23 | |||
24 | + def test_riscv32_maxcpu(self): | ||
25 | + """ | ||
26 | + :avocado: tags=arch:riscv32 | ||
27 | + :avocado: tags=machine:virt | ||
28 | + :avocado: tags=cpu:max | ||
29 | + :avocado: tags=tuxboot:riscv32 | ||
30 | + """ | ||
31 | + sums = { "Image" : | ||
32 | + "89599407d7334de629a40e7ad6503c73670359eb5f5ae9d686353a3d6deccbd5", | ||
33 | + "fw_jump.elf" : | ||
34 | + "f2ef28a0b77826f79d085d3e4aa686f1159b315eff9099a37046b18936676985", | ||
35 | + "rootfs.ext4.zst" : | ||
36 | + "7168d296d0283238ea73cd5a775b3dd608e55e04c7b92b76ecce31bb13108cba" } | ||
37 | + | ||
38 | + self.common_tuxrun(csums=sums) | ||
39 | + | ||
40 | + def test_riscv64_maxcpu(self): | ||
41 | + """ | ||
42 | + :avocado: tags=arch:riscv64 | ||
43 | + :avocado: tags=machine:virt | ||
44 | + :avocado: tags=cpu:max | ||
45 | + :avocado: tags=tuxboot:riscv64 | ||
46 | + """ | ||
47 | + sums = { "Image" : | ||
48 | + "cd634badc65e52fb63465ec99e309c0de0369f0841b7d9486f9729e119bac25e", | ||
49 | + "fw_jump.elf" : | ||
50 | + "6e3373abcab4305fe151b564a4c71110d833c21f2c0a1753b7935459e36aedcf", | ||
51 | + "rootfs.ext4.zst" : | ||
52 | + "b18e3a3bdf27be03da0b285e84cb71bf09eca071c3a087b42884b6982ed679eb" } | ||
53 | + | ||
54 | + self.common_tuxrun(csums=sums) | ||
55 | + | ||
56 | def test_s390(self): | ||
57 | """ | ||
58 | :avocado: tags=arch:s390x | ||
59 | -- | ||
60 | 2.41.0 | ||
61 | |||
62 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
1 | 2 | ||
3 | The 'any' CPU type was introduced in commit dc5bd18fa5725 ("RISC-V CPU | ||
4 | Core Definition"), being around since the beginning. It's not an easy | ||
5 | CPU to use: it's undocumented and its name doesn't tell users much about | ||
6 | what the CPU is supposed to bring. 'git log' doesn't help us either in | ||
7 | knowing what was the original design of this CPU type. | ||
8 | |||
9 | The closest we have is a comment from Alistair [1] where he recalls from | ||
10 | memory that the 'any' CPU is supposed to behave like the newly added | ||
11 | 'max' CPU. He also suggested that the 'any' CPU should be removed. | ||
12 | |||
13 | The default CPUs are rv32 and rv64, so removing the 'any' CPU will have | ||
14 | impact only on users that might have a script that uses '-cpu any'. | ||
15 | And those users are better off using the default CPUs or the new 'max' | ||
16 | CPU. | ||
17 | |||
18 | We would love to just remove the code and be done with it, but one does | ||
19 | not simply remove a feature in QEMU. We'll put the CPU in quarantine | ||
20 | first, letting users know that we have the intent of removing it in the | ||
21 | future. | ||
22 | |||
23 | [1] https://lists.gnu.org/archive/html/qemu-devel/2023-07/msg02891.html | ||
24 | |||
25 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
26 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
27 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> | ||
28 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | ||
29 | Tested-by: Philippe Mathieu-Daudé <philmd@linaro.org> | ||
30 | Message-ID: <20230912132423.268494-13-dbarboza@ventanamicro.com> | ||
31 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
32 | --- | ||
33 | docs/about/deprecated.rst | 12 ++++++++++++ | ||
34 | target/riscv/cpu.c | 5 +++++ | ||
35 | 2 files changed, 17 insertions(+) | ||
36 | |||
37 | diff --git a/docs/about/deprecated.rst b/docs/about/deprecated.rst | ||
38 | index XXXXXXX..XXXXXXX 100644 | ||
39 | --- a/docs/about/deprecated.rst | ||
40 | +++ b/docs/about/deprecated.rst | ||
41 | @@ -XXX,XX +XXX,XX @@ QEMU's ``vhost`` feature, which would eliminate the high latency costs under | ||
42 | which the 9p ``proxy`` backend currently suffers. However as of to date nobody | ||
43 | has indicated plans for such kind of reimplementation unfortunately. | ||
44 | |||
45 | +RISC-V 'any' CPU type ``-cpu any`` (since 8.2) | ||
46 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
47 | + | ||
48 | +The 'any' CPU type was introduced back in 2018 and has been around since the | ||
49 | +initial RISC-V QEMU port. Its usage has always been unclear: users don't know | ||
50 | +what to expect from a CPU called 'any', and in fact the CPU does not do anything | ||
51 | +special that isn't already done by the default CPUs rv32/rv64. | ||
52 | + | ||
53 | +After the introduction of the 'max' CPU type, RISC-V now has a good coverage | ||
54 | +of generic CPUs: rv32 and rv64 as default CPUs and 'max' as a feature complete | ||
55 | +CPU for both 32 and 64 bit builds. Users are then discouraged to use the 'any' | ||
56 | +CPU type starting in 8.2. | ||
57 | |||
58 | Block device options | ||
59 | '''''''''''''''''''' | ||
60 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | ||
61 | index XXXXXXX..XXXXXXX 100644 | ||
62 | --- a/target/riscv/cpu.c | ||
63 | +++ b/target/riscv/cpu.c | ||
64 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) | ||
65 | RISCVCPUClass *mcc = RISCV_CPU_GET_CLASS(dev); | ||
66 | Error *local_err = NULL; | ||
67 | |||
68 | + if (object_dynamic_cast(OBJECT(dev), TYPE_RISCV_CPU_ANY) != NULL) { | ||
69 | + warn_report("The 'any' CPU is deprecated and will be " | ||
70 | + "removed in the future."); | ||
71 | + } | ||
72 | + | ||
73 | cpu_exec_realizefn(cs, &local_err); | ||
74 | if (local_err != NULL) { | ||
75 | error_propagate(errp, local_err); | ||
76 | -- | ||
77 | 2.41.0 | ||
78 | |||
79 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
1 | 2 | ||
3 | We'll have future usage for a function where, given an offset of the | ||
4 | struct RISCVCPUConfig, the flag is updated to a certain val. | ||
5 | |||
6 | Change all existing callers to use edata->ext_enable_offset instead of | ||
7 | 'edata'. | ||
8 | |||
9 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
10 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
11 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> | ||
12 | Message-ID: <20230912132423.268494-14-dbarboza@ventanamicro.com> | ||
13 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
14 | --- | ||
15 | target/riscv/cpu.c | 18 +++++++++--------- | ||
16 | 1 file changed, 9 insertions(+), 9 deletions(-) | ||
17 | |||
18 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | ||
19 | index XXXXXXX..XXXXXXX 100644 | ||
20 | --- a/target/riscv/cpu.c | ||
21 | +++ b/target/riscv/cpu.c | ||
22 | @@ -XXX,XX +XXX,XX @@ static const struct isa_ext_data isa_edata_arr[] = { | ||
23 | ISA_EXT_DATA_ENTRY(xventanacondops, PRIV_VERSION_1_12_0, ext_XVentanaCondOps), | ||
24 | }; | ||
25 | |||
26 | -static bool isa_ext_is_enabled(RISCVCPU *cpu, | ||
27 | - const struct isa_ext_data *edata) | ||
28 | +static bool isa_ext_is_enabled(RISCVCPU *cpu, uint32_t ext_offset) | ||
29 | { | ||
30 | - bool *ext_enabled = (void *)&cpu->cfg + edata->ext_enable_offset; | ||
31 | + bool *ext_enabled = (void *)&cpu->cfg + ext_offset; | ||
32 | |||
33 | return *ext_enabled; | ||
34 | } | ||
35 | |||
36 | -static void isa_ext_update_enabled(RISCVCPU *cpu, | ||
37 | - const struct isa_ext_data *edata, bool en) | ||
38 | +static void isa_ext_update_enabled(RISCVCPU *cpu, uint32_t ext_offset, | ||
39 | + bool en) | ||
40 | { | ||
41 | - bool *ext_enabled = (void *)&cpu->cfg + edata->ext_enable_offset; | ||
42 | + bool *ext_enabled = (void *)&cpu->cfg + ext_offset; | ||
43 | |||
44 | *ext_enabled = en; | ||
45 | } | ||
46 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_disable_priv_spec_isa_exts(RISCVCPU *cpu) | ||
47 | |||
48 | /* Force disable extensions if priv spec version does not match */ | ||
49 | for (i = 0; i < ARRAY_SIZE(isa_edata_arr); i++) { | ||
50 | - if (isa_ext_is_enabled(cpu, &isa_edata_arr[i]) && | ||
51 | + if (isa_ext_is_enabled(cpu, isa_edata_arr[i].ext_enable_offset) && | ||
52 | (env->priv_ver < isa_edata_arr[i].min_version)) { | ||
53 | - isa_ext_update_enabled(cpu, &isa_edata_arr[i], false); | ||
54 | + isa_ext_update_enabled(cpu, isa_edata_arr[i].ext_enable_offset, | ||
55 | + false); | ||
56 | #ifndef CONFIG_USER_ONLY | ||
57 | warn_report("disabling %s extension for hart 0x" TARGET_FMT_lx | ||
58 | " because privilege spec version does not match", | ||
59 | @@ -XXX,XX +XXX,XX @@ static void riscv_isa_string_ext(RISCVCPU *cpu, char **isa_str, | ||
60 | int i; | ||
61 | |||
62 | for (i = 0; i < ARRAY_SIZE(isa_edata_arr); i++) { | ||
63 | - if (isa_ext_is_enabled(cpu, &isa_edata_arr[i])) { | ||
64 | + if (isa_ext_is_enabled(cpu, isa_edata_arr[i].ext_enable_offset)) { | ||
65 | new = g_strconcat(old, "_", isa_edata_arr[i].name, NULL); | ||
66 | g_free(old); | ||
67 | old = new; | ||
68 | -- | ||
69 | 2.41.0 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
1 | 2 | ||
3 | The RISC-V KVM driver uses a CPUCFG() macro that calculates the offset | ||
4 | of a certain field in the struct RISCVCPUConfig. We're going to use this | ||
5 | macro in target/riscv/cpu.c as well in the next patches. Make it public. | ||
6 | |||
7 | Rename it to CPU_CFG_OFFSET() for more clarity while we're at it. | ||
8 | |||
9 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
10 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
11 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> | ||
12 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | ||
13 | Message-ID: <20230912132423.268494-15-dbarboza@ventanamicro.com> | ||
14 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
15 | --- | ||
16 | target/riscv/cpu.h | 2 ++ | ||
17 | target/riscv/cpu.c | 2 +- | ||
18 | target/riscv/kvm.c | 8 +++----- | ||
19 | 3 files changed, 6 insertions(+), 6 deletions(-) | ||
20 | |||
21 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h | ||
22 | index XXXXXXX..XXXXXXX 100644 | ||
23 | --- a/target/riscv/cpu.h | ||
24 | +++ b/target/riscv/cpu.h | ||
25 | @@ -XXX,XX +XXX,XX @@ | ||
26 | const char *riscv_get_misa_ext_name(uint32_t bit); | ||
27 | const char *riscv_get_misa_ext_description(uint32_t bit); | ||
28 | |||
29 | +#define CPU_CFG_OFFSET(_prop) offsetof(struct RISCVCPUConfig, _prop) | ||
30 | + | ||
31 | /* Privileged specification version */ | ||
32 | enum { | ||
33 | PRIV_VERSION_1_10_0 = 0, | ||
34 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | ||
35 | index XXXXXXX..XXXXXXX 100644 | ||
36 | --- a/target/riscv/cpu.c | ||
37 | +++ b/target/riscv/cpu.c | ||
38 | @@ -XXX,XX +XXX,XX @@ struct isa_ext_data { | ||
39 | }; | ||
40 | |||
41 | #define ISA_EXT_DATA_ENTRY(_name, _min_ver, _prop) \ | ||
42 | - {#_name, _min_ver, offsetof(struct RISCVCPUConfig, _prop)} | ||
43 | + {#_name, _min_ver, CPU_CFG_OFFSET(_prop)} | ||
44 | |||
45 | /* | ||
46 | * From vector_helper.c | ||
47 | diff --git a/target/riscv/kvm.c b/target/riscv/kvm.c | ||
48 | index XXXXXXX..XXXXXXX 100644 | ||
49 | --- a/target/riscv/kvm.c | ||
50 | +++ b/target/riscv/kvm.c | ||
51 | @@ -XXX,XX +XXX,XX @@ static void kvm_riscv_update_cpu_misa_ext(RISCVCPU *cpu, CPUState *cs) | ||
52 | } | ||
53 | } | ||
54 | |||
55 | -#define CPUCFG(_prop) offsetof(struct RISCVCPUConfig, _prop) | ||
56 | - | ||
57 | #define KVM_EXT_CFG(_name, _prop, _reg_id) \ | ||
58 | - {.name = _name, .offset = CPUCFG(_prop), \ | ||
59 | + {.name = _name, .offset = CPU_CFG_OFFSET(_prop), \ | ||
60 | .kvm_reg_id = _reg_id} | ||
61 | |||
62 | static KVMCPUConfig kvm_multi_ext_cfgs[] = { | ||
63 | @@ -XXX,XX +XXX,XX @@ static void kvm_cpu_set_multi_ext_cfg(Object *obj, Visitor *v, | ||
64 | |||
65 | static KVMCPUConfig kvm_cbom_blocksize = { | ||
66 | .name = "cbom_blocksize", | ||
67 | - .offset = CPUCFG(cbom_blocksize), | ||
68 | + .offset = CPU_CFG_OFFSET(cbom_blocksize), | ||
69 | .kvm_reg_id = KVM_REG_RISCV_CONFIG_REG(zicbom_block_size) | ||
70 | }; | ||
71 | |||
72 | static KVMCPUConfig kvm_cboz_blocksize = { | ||
73 | .name = "cboz_blocksize", | ||
74 | - .offset = CPUCFG(cboz_blocksize), | ||
75 | + .offset = CPU_CFG_OFFSET(cboz_blocksize), | ||
76 | .kvm_reg_id = KVM_REG_RISCV_CONFIG_REG(zicboz_block_size) | ||
77 | }; | ||
78 | |||
79 | -- | ||
80 | 2.41.0 | ||
81 | |||
82 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
1 | 2 | ||
3 | During realize() time we're activating a lot of extensions based on some | ||
4 | criteria, e.g.: | ||
5 | |||
6 | if (cpu->cfg.ext_zk) { | ||
7 | cpu->cfg.ext_zkn = true; | ||
8 | cpu->cfg.ext_zkr = true; | ||
9 | cpu->cfg.ext_zkt = true; | ||
10 | } | ||
11 | |||
12 | This practice resulted in at least one case where we ended up enabling | ||
13 | something we shouldn't: RVC enabling zca/zcd/zcf when using a CPU that | ||
14 | has priv_spec older than 1.12.0. | ||
15 | |||
16 | We're also not considering user choice. There's no way of doing it now | ||
17 | but this is about to change in the next few patches. | ||
18 | |||
19 | cpu_cfg_ext_auto_update() will check for priv version mismatches before | ||
20 | enabling extensions. If we have a mismatch between the current priv | ||
21 | version and the extension we want to enable, do not enable it. In the | ||
22 | near future, this same function will also consider user choice when | ||
23 | deciding if we're going to enable/disable an extension or not. | ||
24 | |||
25 | For now let's use it to handle zca/zcd/zcf enablement if RVC is enabled. | ||
26 | |||
27 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
28 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
29 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> | ||
30 | Message-ID: <20230912132423.268494-16-dbarboza@ventanamicro.com> | ||
31 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
32 | --- | ||
33 | target/riscv/cpu.c | 43 ++++++++++++++++++++++++++++++++++++++++--- | ||
34 | 1 file changed, 40 insertions(+), 3 deletions(-) | ||
35 | |||
36 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | ||
37 | index XXXXXXX..XXXXXXX 100644 | ||
38 | --- a/target/riscv/cpu.c | ||
39 | +++ b/target/riscv/cpu.c | ||
40 | @@ -XXX,XX +XXX,XX @@ static void isa_ext_update_enabled(RISCVCPU *cpu, uint32_t ext_offset, | ||
41 | *ext_enabled = en; | ||
42 | } | ||
43 | |||
44 | +static int cpu_cfg_ext_get_min_version(uint32_t ext_offset) | ||
45 | +{ | ||
46 | + int i; | ||
47 | + | ||
48 | + for (i = 0; i < ARRAY_SIZE(isa_edata_arr); i++) { | ||
49 | + if (isa_edata_arr[i].ext_enable_offset != ext_offset) { | ||
50 | + continue; | ||
51 | + } | ||
52 | + | ||
53 | + return isa_edata_arr[i].min_version; | ||
54 | + } | ||
55 | + | ||
56 | + g_assert_not_reached(); | ||
57 | +} | ||
58 | + | ||
59 | +static void cpu_cfg_ext_auto_update(RISCVCPU *cpu, uint32_t ext_offset, | ||
60 | + bool value) | ||
61 | +{ | ||
62 | + CPURISCVState *env = &cpu->env; | ||
63 | + bool prev_val = isa_ext_is_enabled(cpu, ext_offset); | ||
64 | + int min_version; | ||
65 | + | ||
66 | + if (prev_val == value) { | ||
67 | + return; | ||
68 | + } | ||
69 | + | ||
70 | + if (value && env->priv_ver != PRIV_VERSION_LATEST) { | ||
71 | + /* Do not enable it if priv_ver is older than min_version */ | ||
72 | + min_version = cpu_cfg_ext_get_min_version(ext_offset); | ||
73 | + if (env->priv_ver < min_version) { | ||
74 | + return; | ||
75 | + } | ||
76 | + } | ||
77 | + | ||
78 | + isa_ext_update_enabled(cpu, ext_offset, value); | ||
79 | +} | ||
80 | + | ||
81 | const char * const riscv_int_regnames[] = { | ||
82 | "x0/zero", "x1/ra", "x2/sp", "x3/gp", "x4/tp", "x5/t0", "x6/t1", | ||
83 | "x7/t2", "x8/s0", "x9/s1", "x10/a0", "x11/a1", "x12/a2", "x13/a3", | ||
84 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp) | ||
85 | |||
86 | /* zca, zcd and zcf has a PRIV 1.12.0 restriction */ | ||
87 | if (riscv_has_ext(env, RVC) && env->priv_ver >= PRIV_VERSION_1_12_0) { | ||
88 | - cpu->cfg.ext_zca = true; | ||
89 | + cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zca), true); | ||
90 | if (riscv_has_ext(env, RVF) && env->misa_mxl_max == MXL_RV32) { | ||
91 | - cpu->cfg.ext_zcf = true; | ||
92 | + cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zcf), true); | ||
93 | } | ||
94 | if (riscv_has_ext(env, RVD)) { | ||
95 | - cpu->cfg.ext_zcd = true; | ||
96 | + cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zcd), true); | ||
97 | } | ||
98 | } | ||
99 | |||
100 | -- | ||
101 | 2.41.0 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
1 | 2 | ||
3 | Let's change the other instances in realize() where we're enabling an | ||
4 | extension based on a certain criteria (e.g. it's a dependency of another | ||
5 | extension). | ||
6 | |||
7 | We're leaving icsr and ifencei being enabled during RVG for later - | ||
8 | we'll want to error out in that case. Every other extension enablement | ||
9 | during realize is now done via cpu_cfg_ext_auto_update(). | ||
10 | |||
11 | The end goal is that only cpu init() functions will handle extension | ||
12 | flags directly via "cpu->cfg.ext_N = true|false". | ||
13 | |||
14 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
15 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
16 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> | ||
17 | Message-ID: <20230912132423.268494-17-dbarboza@ventanamicro.com> | ||
18 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
19 | --- | ||
20 | target/riscv/cpu.c | 50 +++++++++++++++++++++++----------------------- | ||
21 | 1 file changed, 25 insertions(+), 25 deletions(-) | ||
22 | |||
23 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | ||
24 | index XXXXXXX..XXXXXXX 100644 | ||
25 | --- a/target/riscv/cpu.c | ||
26 | +++ b/target/riscv/cpu.c | ||
27 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp) | ||
28 | } | ||
29 | |||
30 | if (cpu->cfg.ext_zfh) { | ||
31 | - cpu->cfg.ext_zfhmin = true; | ||
32 | + cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zfhmin), true); | ||
33 | } | ||
34 | |||
35 | if (cpu->cfg.ext_zfhmin && !riscv_has_ext(env, RVF)) { | ||
36 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp) | ||
37 | } | ||
38 | |||
39 | /* The V vector extension depends on the Zve64d extension */ | ||
40 | - cpu->cfg.ext_zve64d = true; | ||
41 | + cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zve64d), true); | ||
42 | } | ||
43 | |||
44 | /* The Zve64d extension depends on the Zve64f extension */ | ||
45 | if (cpu->cfg.ext_zve64d) { | ||
46 | - cpu->cfg.ext_zve64f = true; | ||
47 | + cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zve64f), true); | ||
48 | } | ||
49 | |||
50 | /* The Zve64f extension depends on the Zve32f extension */ | ||
51 | if (cpu->cfg.ext_zve64f) { | ||
52 | - cpu->cfg.ext_zve32f = true; | ||
53 | + cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zve32f), true); | ||
54 | } | ||
55 | |||
56 | if (cpu->cfg.ext_zve64d && !riscv_has_ext(env, RVD)) { | ||
57 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp) | ||
58 | } | ||
59 | |||
60 | if (cpu->cfg.ext_zvfh) { | ||
61 | - cpu->cfg.ext_zvfhmin = true; | ||
62 | + cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zvfhmin), true); | ||
63 | } | ||
64 | |||
65 | if (cpu->cfg.ext_zvfhmin && !cpu->cfg.ext_zve32f) { | ||
66 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp) | ||
67 | |||
68 | /* Set the ISA extensions, checks should have happened above */ | ||
69 | if (cpu->cfg.ext_zhinx) { | ||
70 | - cpu->cfg.ext_zhinxmin = true; | ||
71 | + cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zca), true); | ||
72 | } | ||
73 | |||
74 | if ((cpu->cfg.ext_zdinx || cpu->cfg.ext_zhinxmin) && !cpu->cfg.ext_zfinx) { | ||
75 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp) | ||
76 | } | ||
77 | |||
78 | if (cpu->cfg.ext_zce) { | ||
79 | - cpu->cfg.ext_zca = true; | ||
80 | - cpu->cfg.ext_zcb = true; | ||
81 | - cpu->cfg.ext_zcmp = true; | ||
82 | - cpu->cfg.ext_zcmt = true; | ||
83 | + cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zca), true); | ||
84 | + cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zcb), true); | ||
85 | + cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zcmp), true); | ||
86 | + cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zcmt), true); | ||
87 | if (riscv_has_ext(env, RVF) && env->misa_mxl_max == MXL_RV32) { | ||
88 | - cpu->cfg.ext_zcf = true; | ||
89 | + cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zcf), true); | ||
90 | } | ||
91 | } | ||
92 | |||
93 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp) | ||
94 | } | ||
95 | |||
96 | if (cpu->cfg.ext_zk) { | ||
97 | - cpu->cfg.ext_zkn = true; | ||
98 | - cpu->cfg.ext_zkr = true; | ||
99 | - cpu->cfg.ext_zkt = true; | ||
100 | + cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zkn), true); | ||
101 | + cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zkr), true); | ||
102 | + cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zkt), true); | ||
103 | } | ||
104 | |||
105 | if (cpu->cfg.ext_zkn) { | ||
106 | - cpu->cfg.ext_zbkb = true; | ||
107 | - cpu->cfg.ext_zbkc = true; | ||
108 | - cpu->cfg.ext_zbkx = true; | ||
109 | - cpu->cfg.ext_zkne = true; | ||
110 | - cpu->cfg.ext_zknd = true; | ||
111 | - cpu->cfg.ext_zknh = true; | ||
112 | + cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zbkb), true); | ||
113 | + cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zbkc), true); | ||
114 | + cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zbkx), true); | ||
115 | + cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zkne), true); | ||
116 | + cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zknd), true); | ||
117 | + cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zknh), true); | ||
118 | } | ||
119 | |||
120 | if (cpu->cfg.ext_zks) { | ||
121 | - cpu->cfg.ext_zbkb = true; | ||
122 | - cpu->cfg.ext_zbkc = true; | ||
123 | - cpu->cfg.ext_zbkx = true; | ||
124 | - cpu->cfg.ext_zksed = true; | ||
125 | - cpu->cfg.ext_zksh = true; | ||
126 | + cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zbkb), true); | ||
127 | + cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zbkc), true); | ||
128 | + cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zbkx), true); | ||
129 | + cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zksed), true); | ||
130 | + cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zksh), true); | ||
131 | } | ||
132 | |||
133 | /* | ||
134 | -- | ||
135 | 2.41.0 | diff view generated by jsdifflib |
1 | From: Bin Meng <bin.meng@windriver.com> | 1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
---|---|---|---|
2 | 2 | ||
3 | Commit 7c28f4da20e5 ("RISC-V: Don't add NULL bootargs to device-tree") | 3 | If we want to make better decisions when auto-enabling extensions during |
4 | tried to avoid adding *NULL* bootargs to device tree, but unfortunately | 4 | realize() we need a way to tell if an user set an extension manually. |
5 | the changes were entirely useless, due to MachineState::kernel_cmdline | 5 | The RISC-V KVM driver has its own solution via a KVMCPUConfig struct |
6 | can't be NULL at all as the default value is given as an empty string. | 6 | that has an 'user_set' flag that is set during the Property set() |
7 | (see hw/core/machine.c::machine_initfn()). | 7 | callback. The set() callback also does init() time validations based on |
8 | 8 | the current KVM driver capabilities. | |
9 | Note the wording of *NULL* bootargs is wrong. It can't be NULL otherwise | 9 | |
10 | a segfault had already been observed by dereferencing the NULL pointer. | 10 | For TCG we would want a 'user_set' mechanic too, but we would look |
11 | It should be worded as *empty" bootargs. | 11 | ad-hoc via cpu_cfg_ext_auto_update() if a certain extension was user set |
12 | 12 | or not. If we copy what was made in the KVM side we would look for | |
13 | Fixes: 7c28f4da20e5 ("RISC-V: Don't add NULL bootargs to device-tree") | 13 | 'user_set' for one into 60+ extension structs spreaded in 3 arrays |
14 | Signed-off-by: Bin Meng <bin.meng@windriver.com> | 14 | (riscv_cpu_extensions, riscv_cpu_experimental_exts, |
15 | riscv_cpu_vendor_exts). | ||
16 | |||
17 | We'll still need an extension struct but we won't be using the | ||
18 | 'user_set' flag: | ||
19 | |||
20 | - 'RISCVCPUMultiExtConfig' will be our specialized structure, similar to what | ||
21 | we're already doing with the MISA extensions in 'RISCVCPUMisaExtConfig'. | ||
22 | DEFINE_PROP_BOOL() for all 3 extensions arrays were replaced by | ||
23 | MULTI_EXT_CFG_BOOL(), a macro that will init our specialized struct; | ||
24 | |||
25 | - the 'multi_ext_user_opts' hash will be used to store the offset of each | ||
26 | extension that the user set via the set() callback, cpu_set_multi_ext_cfg(). | ||
27 | For now we're just initializing and populating it - next patch will use | ||
28 | it to determine if a certain extension was user set; | ||
29 | |||
30 | - cpu_add_multi_ext_prop() is a new helper that will replace the | ||
31 | qdev_property_add_static() calls that our macros are doing to populate | ||
32 | user properties. The macro was renamed to ADD_CPU_MULTIEXT_PROPS_ARRAY() | ||
33 | for clarity. Note that the non-extension properties in | ||
34 | riscv_cpu_options[] still need to be declared via qdev(). | ||
35 | |||
36 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
15 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 37 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
16 | Message-Id: <20220421055629.1177285-2-bmeng.cn@gmail.com> | 38 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> |
39 | Message-ID: <20230912132423.268494-18-dbarboza@ventanamicro.com> | ||
17 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 40 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
18 | --- | 41 | --- |
19 | hw/riscv/microchip_pfsoc.c | 2 +- | 42 | target/riscv/cpu.c | 258 ++++++++++++++++++++++++++++----------------- |
20 | hw/riscv/sifive_u.c | 2 +- | 43 | 1 file changed, 159 insertions(+), 99 deletions(-) |
21 | hw/riscv/spike.c | 2 +- | 44 | |
22 | hw/riscv/virt.c | 2 +- | 45 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c |
23 | 4 files changed, 4 insertions(+), 4 deletions(-) | ||
24 | |||
25 | diff --git a/hw/riscv/microchip_pfsoc.c b/hw/riscv/microchip_pfsoc.c | ||
26 | index XXXXXXX..XXXXXXX 100644 | 46 | index XXXXXXX..XXXXXXX 100644 |
27 | --- a/hw/riscv/microchip_pfsoc.c | 47 | --- a/target/riscv/cpu.c |
28 | +++ b/hw/riscv/microchip_pfsoc.c | 48 | +++ b/target/riscv/cpu.c |
29 | @@ -XXX,XX +XXX,XX @@ static void microchip_icicle_kit_machine_init(MachineState *machine) | 49 | @@ -XXX,XX +XXX,XX @@ static const struct isa_ext_data isa_edata_arr[] = { |
30 | "linux,initrd-end", end); | 50 | ISA_EXT_DATA_ENTRY(xventanacondops, PRIV_VERSION_1_12_0, ext_XVentanaCondOps), |
31 | } | 51 | }; |
32 | 52 | ||
33 | - if (machine->kernel_cmdline) { | 53 | +/* Hash that stores user set extensions */ |
34 | + if (machine->kernel_cmdline && *machine->kernel_cmdline) { | 54 | +static GHashTable *multi_ext_user_opts; |
35 | qemu_fdt_setprop_string(machine->fdt, "/chosen", | 55 | + |
36 | "bootargs", machine->kernel_cmdline); | 56 | static bool isa_ext_is_enabled(RISCVCPU *cpu, uint32_t ext_offset) |
37 | } | 57 | { |
38 | diff --git a/hw/riscv/sifive_u.c b/hw/riscv/sifive_u.c | 58 | bool *ext_enabled = (void *)&cpu->cfg + ext_offset; |
39 | index XXXXXXX..XXXXXXX 100644 | 59 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_init(Object *obj) |
40 | --- a/hw/riscv/sifive_u.c | 60 | qdev_init_gpio_in(DEVICE(obj), riscv_cpu_set_irq, |
41 | +++ b/hw/riscv/sifive_u.c | 61 | IRQ_LOCAL_MAX + IRQ_LOCAL_GUEST_MAX); |
42 | @@ -XXX,XX +XXX,XX @@ static void create_fdt(SiFiveUState *s, const MemMapEntry *memmap, | 62 | #endif /* CONFIG_USER_ONLY */ |
43 | g_free(nodename); | 63 | + |
44 | 64 | + multi_ext_user_opts = g_hash_table_new(NULL, g_direct_equal); | |
45 | update_bootargs: | 65 | } |
46 | - if (cmdline) { | 66 | |
47 | + if (cmdline && *cmdline) { | 67 | typedef struct RISCVCPUMisaExtConfig { |
48 | qemu_fdt_setprop_string(fdt, "/chosen", "bootargs", cmdline); | 68 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_add_misa_properties(Object *cpu_obj) |
49 | } | 69 | } |
50 | } | 70 | } |
51 | diff --git a/hw/riscv/spike.c b/hw/riscv/spike.c | 71 | |
52 | index XXXXXXX..XXXXXXX 100644 | 72 | -static Property riscv_cpu_extensions[] = { |
53 | --- a/hw/riscv/spike.c | 73 | +typedef struct RISCVCPUMultiExtConfig { |
54 | +++ b/hw/riscv/spike.c | 74 | + const char *name; |
55 | @@ -XXX,XX +XXX,XX @@ static void create_fdt(SpikeState *s, const MemMapEntry *memmap, | 75 | + uint32_t offset; |
56 | qemu_fdt_add_subnode(fdt, "/chosen"); | 76 | + bool enabled; |
57 | qemu_fdt_setprop_string(fdt, "/chosen", "stdout-path", "/htif"); | 77 | +} RISCVCPUMultiExtConfig; |
58 | 78 | + | |
59 | - if (cmdline) { | 79 | +#define MULTI_EXT_CFG_BOOL(_name, _prop, _defval) \ |
60 | + if (cmdline && *cmdline) { | 80 | + {.name = _name, .offset = CPU_CFG_OFFSET(_prop), \ |
61 | qemu_fdt_setprop_string(fdt, "/chosen", "bootargs", cmdline); | 81 | + .enabled = _defval} |
82 | + | ||
83 | +static RISCVCPUMultiExtConfig riscv_cpu_extensions[] = { | ||
84 | /* Defaults for standard extensions */ | ||
85 | - DEFINE_PROP_BOOL("sscofpmf", RISCVCPU, cfg.ext_sscofpmf, false), | ||
86 | - DEFINE_PROP_BOOL("Zifencei", RISCVCPU, cfg.ext_ifencei, true), | ||
87 | - DEFINE_PROP_BOOL("Zicsr", RISCVCPU, cfg.ext_icsr, true), | ||
88 | - DEFINE_PROP_BOOL("Zihintntl", RISCVCPU, cfg.ext_zihintntl, true), | ||
89 | - DEFINE_PROP_BOOL("Zihintpause", RISCVCPU, cfg.ext_zihintpause, true), | ||
90 | - DEFINE_PROP_BOOL("Zawrs", RISCVCPU, cfg.ext_zawrs, true), | ||
91 | - DEFINE_PROP_BOOL("Zfa", RISCVCPU, cfg.ext_zfa, true), | ||
92 | - DEFINE_PROP_BOOL("Zfh", RISCVCPU, cfg.ext_zfh, false), | ||
93 | - DEFINE_PROP_BOOL("Zfhmin", RISCVCPU, cfg.ext_zfhmin, false), | ||
94 | - DEFINE_PROP_BOOL("Zve32f", RISCVCPU, cfg.ext_zve32f, false), | ||
95 | - DEFINE_PROP_BOOL("Zve64f", RISCVCPU, cfg.ext_zve64f, false), | ||
96 | - DEFINE_PROP_BOOL("Zve64d", RISCVCPU, cfg.ext_zve64d, false), | ||
97 | - DEFINE_PROP_BOOL("sstc", RISCVCPU, cfg.ext_sstc, true), | ||
98 | - | ||
99 | - DEFINE_PROP_BOOL("smstateen", RISCVCPU, cfg.ext_smstateen, false), | ||
100 | - DEFINE_PROP_BOOL("svadu", RISCVCPU, cfg.ext_svadu, true), | ||
101 | - DEFINE_PROP_BOOL("svinval", RISCVCPU, cfg.ext_svinval, false), | ||
102 | - DEFINE_PROP_BOOL("svnapot", RISCVCPU, cfg.ext_svnapot, false), | ||
103 | - DEFINE_PROP_BOOL("svpbmt", RISCVCPU, cfg.ext_svpbmt, false), | ||
104 | - | ||
105 | - DEFINE_PROP_BOOL("zba", RISCVCPU, cfg.ext_zba, true), | ||
106 | - DEFINE_PROP_BOOL("zbb", RISCVCPU, cfg.ext_zbb, true), | ||
107 | - DEFINE_PROP_BOOL("zbc", RISCVCPU, cfg.ext_zbc, true), | ||
108 | - DEFINE_PROP_BOOL("zbkb", RISCVCPU, cfg.ext_zbkb, false), | ||
109 | - DEFINE_PROP_BOOL("zbkc", RISCVCPU, cfg.ext_zbkc, false), | ||
110 | - DEFINE_PROP_BOOL("zbkx", RISCVCPU, cfg.ext_zbkx, false), | ||
111 | - DEFINE_PROP_BOOL("zbs", RISCVCPU, cfg.ext_zbs, true), | ||
112 | - DEFINE_PROP_BOOL("zk", RISCVCPU, cfg.ext_zk, false), | ||
113 | - DEFINE_PROP_BOOL("zkn", RISCVCPU, cfg.ext_zkn, false), | ||
114 | - DEFINE_PROP_BOOL("zknd", RISCVCPU, cfg.ext_zknd, false), | ||
115 | - DEFINE_PROP_BOOL("zkne", RISCVCPU, cfg.ext_zkne, false), | ||
116 | - DEFINE_PROP_BOOL("zknh", RISCVCPU, cfg.ext_zknh, false), | ||
117 | - DEFINE_PROP_BOOL("zkr", RISCVCPU, cfg.ext_zkr, false), | ||
118 | - DEFINE_PROP_BOOL("zks", RISCVCPU, cfg.ext_zks, false), | ||
119 | - DEFINE_PROP_BOOL("zksed", RISCVCPU, cfg.ext_zksed, false), | ||
120 | - DEFINE_PROP_BOOL("zksh", RISCVCPU, cfg.ext_zksh, false), | ||
121 | - DEFINE_PROP_BOOL("zkt", RISCVCPU, cfg.ext_zkt, false), | ||
122 | - | ||
123 | - DEFINE_PROP_BOOL("zdinx", RISCVCPU, cfg.ext_zdinx, false), | ||
124 | - DEFINE_PROP_BOOL("zfinx", RISCVCPU, cfg.ext_zfinx, false), | ||
125 | - DEFINE_PROP_BOOL("zhinx", RISCVCPU, cfg.ext_zhinx, false), | ||
126 | - DEFINE_PROP_BOOL("zhinxmin", RISCVCPU, cfg.ext_zhinxmin, false), | ||
127 | - | ||
128 | - DEFINE_PROP_BOOL("zicbom", RISCVCPU, cfg.ext_icbom, true), | ||
129 | - DEFINE_PROP_BOOL("zicboz", RISCVCPU, cfg.ext_icboz, true), | ||
130 | - | ||
131 | - DEFINE_PROP_BOOL("zmmul", RISCVCPU, cfg.ext_zmmul, false), | ||
132 | - | ||
133 | - DEFINE_PROP_BOOL("zca", RISCVCPU, cfg.ext_zca, false), | ||
134 | - DEFINE_PROP_BOOL("zcb", RISCVCPU, cfg.ext_zcb, false), | ||
135 | - DEFINE_PROP_BOOL("zcd", RISCVCPU, cfg.ext_zcd, false), | ||
136 | - DEFINE_PROP_BOOL("zce", RISCVCPU, cfg.ext_zce, false), | ||
137 | - DEFINE_PROP_BOOL("zcf", RISCVCPU, cfg.ext_zcf, false), | ||
138 | - DEFINE_PROP_BOOL("zcmp", RISCVCPU, cfg.ext_zcmp, false), | ||
139 | - DEFINE_PROP_BOOL("zcmt", RISCVCPU, cfg.ext_zcmt, false), | ||
140 | - DEFINE_PROP_BOOL("zicond", RISCVCPU, cfg.ext_zicond, false), | ||
141 | + MULTI_EXT_CFG_BOOL("sscofpmf", ext_sscofpmf, false), | ||
142 | + MULTI_EXT_CFG_BOOL("Zifencei", ext_ifencei, true), | ||
143 | + MULTI_EXT_CFG_BOOL("Zicsr", ext_icsr, true), | ||
144 | + MULTI_EXT_CFG_BOOL("Zihintntl", ext_zihintntl, true), | ||
145 | + MULTI_EXT_CFG_BOOL("Zihintpause", ext_zihintpause, true), | ||
146 | + MULTI_EXT_CFG_BOOL("Zawrs", ext_zawrs, true), | ||
147 | + MULTI_EXT_CFG_BOOL("Zfa", ext_zfa, true), | ||
148 | + MULTI_EXT_CFG_BOOL("Zfh", ext_zfh, false), | ||
149 | + MULTI_EXT_CFG_BOOL("Zfhmin", ext_zfhmin, false), | ||
150 | + MULTI_EXT_CFG_BOOL("Zve32f", ext_zve32f, false), | ||
151 | + MULTI_EXT_CFG_BOOL("Zve64f", ext_zve64f, false), | ||
152 | + MULTI_EXT_CFG_BOOL("Zve64d", ext_zve64d, false), | ||
153 | + MULTI_EXT_CFG_BOOL("sstc", ext_sstc, true), | ||
154 | + | ||
155 | + MULTI_EXT_CFG_BOOL("smstateen", ext_smstateen, false), | ||
156 | + MULTI_EXT_CFG_BOOL("svadu", ext_svadu, true), | ||
157 | + MULTI_EXT_CFG_BOOL("svinval", ext_svinval, false), | ||
158 | + MULTI_EXT_CFG_BOOL("svnapot", ext_svnapot, false), | ||
159 | + MULTI_EXT_CFG_BOOL("svpbmt", ext_svpbmt, false), | ||
160 | + | ||
161 | + MULTI_EXT_CFG_BOOL("zba", ext_zba, true), | ||
162 | + MULTI_EXT_CFG_BOOL("zbb", ext_zbb, true), | ||
163 | + MULTI_EXT_CFG_BOOL("zbc", ext_zbc, true), | ||
164 | + MULTI_EXT_CFG_BOOL("zbkb", ext_zbkb, false), | ||
165 | + MULTI_EXT_CFG_BOOL("zbkc", ext_zbkc, false), | ||
166 | + MULTI_EXT_CFG_BOOL("zbkx", ext_zbkx, false), | ||
167 | + MULTI_EXT_CFG_BOOL("zbs", ext_zbs, true), | ||
168 | + MULTI_EXT_CFG_BOOL("zk", ext_zk, false), | ||
169 | + MULTI_EXT_CFG_BOOL("zkn", ext_zkn, false), | ||
170 | + MULTI_EXT_CFG_BOOL("zknd", ext_zknd, false), | ||
171 | + MULTI_EXT_CFG_BOOL("zkne", ext_zkne, false), | ||
172 | + MULTI_EXT_CFG_BOOL("zknh", ext_zknh, false), | ||
173 | + MULTI_EXT_CFG_BOOL("zkr", ext_zkr, false), | ||
174 | + MULTI_EXT_CFG_BOOL("zks", ext_zks, false), | ||
175 | + MULTI_EXT_CFG_BOOL("zksed", ext_zksed, false), | ||
176 | + MULTI_EXT_CFG_BOOL("zksh", ext_zksh, false), | ||
177 | + MULTI_EXT_CFG_BOOL("zkt", ext_zkt, false), | ||
178 | + | ||
179 | + MULTI_EXT_CFG_BOOL("zdinx", ext_zdinx, false), | ||
180 | + MULTI_EXT_CFG_BOOL("zfinx", ext_zfinx, false), | ||
181 | + MULTI_EXT_CFG_BOOL("zhinx", ext_zhinx, false), | ||
182 | + MULTI_EXT_CFG_BOOL("zhinxmin", ext_zhinxmin, false), | ||
183 | + | ||
184 | + MULTI_EXT_CFG_BOOL("zicbom", ext_icbom, true), | ||
185 | + MULTI_EXT_CFG_BOOL("zicboz", ext_icboz, true), | ||
186 | + | ||
187 | + MULTI_EXT_CFG_BOOL("zmmul", ext_zmmul, false), | ||
188 | + | ||
189 | + MULTI_EXT_CFG_BOOL("zca", ext_zca, false), | ||
190 | + MULTI_EXT_CFG_BOOL("zcb", ext_zcb, false), | ||
191 | + MULTI_EXT_CFG_BOOL("zcd", ext_zcd, false), | ||
192 | + MULTI_EXT_CFG_BOOL("zce", ext_zce, false), | ||
193 | + MULTI_EXT_CFG_BOOL("zcf", ext_zcf, false), | ||
194 | + MULTI_EXT_CFG_BOOL("zcmp", ext_zcmp, false), | ||
195 | + MULTI_EXT_CFG_BOOL("zcmt", ext_zcmt, false), | ||
196 | + MULTI_EXT_CFG_BOOL("zicond", ext_zicond, false), | ||
197 | |||
198 | DEFINE_PROP_END_OF_LIST(), | ||
199 | }; | ||
200 | |||
201 | -static Property riscv_cpu_vendor_exts[] = { | ||
202 | - DEFINE_PROP_BOOL("xtheadba", RISCVCPU, cfg.ext_xtheadba, false), | ||
203 | - DEFINE_PROP_BOOL("xtheadbb", RISCVCPU, cfg.ext_xtheadbb, false), | ||
204 | - DEFINE_PROP_BOOL("xtheadbs", RISCVCPU, cfg.ext_xtheadbs, false), | ||
205 | - DEFINE_PROP_BOOL("xtheadcmo", RISCVCPU, cfg.ext_xtheadcmo, false), | ||
206 | - DEFINE_PROP_BOOL("xtheadcondmov", RISCVCPU, cfg.ext_xtheadcondmov, false), | ||
207 | - DEFINE_PROP_BOOL("xtheadfmemidx", RISCVCPU, cfg.ext_xtheadfmemidx, false), | ||
208 | - DEFINE_PROP_BOOL("xtheadfmv", RISCVCPU, cfg.ext_xtheadfmv, false), | ||
209 | - DEFINE_PROP_BOOL("xtheadmac", RISCVCPU, cfg.ext_xtheadmac, false), | ||
210 | - DEFINE_PROP_BOOL("xtheadmemidx", RISCVCPU, cfg.ext_xtheadmemidx, false), | ||
211 | - DEFINE_PROP_BOOL("xtheadmempair", RISCVCPU, cfg.ext_xtheadmempair, false), | ||
212 | - DEFINE_PROP_BOOL("xtheadsync", RISCVCPU, cfg.ext_xtheadsync, false), | ||
213 | - DEFINE_PROP_BOOL("xventanacondops", RISCVCPU, cfg.ext_XVentanaCondOps, false), | ||
214 | +static RISCVCPUMultiExtConfig riscv_cpu_vendor_exts[] = { | ||
215 | + MULTI_EXT_CFG_BOOL("xtheadba", ext_xtheadba, false), | ||
216 | + MULTI_EXT_CFG_BOOL("xtheadbb", ext_xtheadbb, false), | ||
217 | + MULTI_EXT_CFG_BOOL("xtheadbs", ext_xtheadbs, false), | ||
218 | + MULTI_EXT_CFG_BOOL("xtheadcmo", ext_xtheadcmo, false), | ||
219 | + MULTI_EXT_CFG_BOOL("xtheadcondmov", ext_xtheadcondmov, false), | ||
220 | + MULTI_EXT_CFG_BOOL("xtheadfmemidx", ext_xtheadfmemidx, false), | ||
221 | + MULTI_EXT_CFG_BOOL("xtheadfmv", ext_xtheadfmv, false), | ||
222 | + MULTI_EXT_CFG_BOOL("xtheadmac", ext_xtheadmac, false), | ||
223 | + MULTI_EXT_CFG_BOOL("xtheadmemidx", ext_xtheadmemidx, false), | ||
224 | + MULTI_EXT_CFG_BOOL("xtheadmempair", ext_xtheadmempair, false), | ||
225 | + MULTI_EXT_CFG_BOOL("xtheadsync", ext_xtheadsync, false), | ||
226 | + MULTI_EXT_CFG_BOOL("xventanacondops", ext_XVentanaCondOps, false), | ||
227 | |||
228 | DEFINE_PROP_END_OF_LIST(), | ||
229 | }; | ||
230 | |||
231 | /* These are experimental so mark with 'x-' */ | ||
232 | -static Property riscv_cpu_experimental_exts[] = { | ||
233 | +static RISCVCPUMultiExtConfig riscv_cpu_experimental_exts[] = { | ||
234 | /* ePMP 0.9.3 */ | ||
235 | - DEFINE_PROP_BOOL("x-epmp", RISCVCPU, cfg.epmp, false), | ||
236 | - DEFINE_PROP_BOOL("x-smaia", RISCVCPU, cfg.ext_smaia, false), | ||
237 | - DEFINE_PROP_BOOL("x-ssaia", RISCVCPU, cfg.ext_ssaia, false), | ||
238 | + MULTI_EXT_CFG_BOOL("x-epmp", epmp, false), | ||
239 | + MULTI_EXT_CFG_BOOL("x-smaia", ext_smaia, false), | ||
240 | + MULTI_EXT_CFG_BOOL("x-ssaia", ext_ssaia, false), | ||
241 | |||
242 | - DEFINE_PROP_BOOL("x-zvfh", RISCVCPU, cfg.ext_zvfh, false), | ||
243 | - DEFINE_PROP_BOOL("x-zvfhmin", RISCVCPU, cfg.ext_zvfhmin, false), | ||
244 | + MULTI_EXT_CFG_BOOL("x-zvfh", ext_zvfh, false), | ||
245 | + MULTI_EXT_CFG_BOOL("x-zvfhmin", ext_zvfhmin, false), | ||
246 | |||
247 | - DEFINE_PROP_BOOL("x-zfbfmin", RISCVCPU, cfg.ext_zfbfmin, false), | ||
248 | - DEFINE_PROP_BOOL("x-zvfbfmin", RISCVCPU, cfg.ext_zvfbfmin, false), | ||
249 | - DEFINE_PROP_BOOL("x-zvfbfwma", RISCVCPU, cfg.ext_zvfbfwma, false), | ||
250 | + MULTI_EXT_CFG_BOOL("x-zfbfmin", ext_zfbfmin, false), | ||
251 | + MULTI_EXT_CFG_BOOL("x-zvfbfmin", ext_zvfbfmin, false), | ||
252 | + MULTI_EXT_CFG_BOOL("x-zvfbfwma", ext_zvfbfwma, false), | ||
253 | |||
254 | /* Vector cryptography extensions */ | ||
255 | - DEFINE_PROP_BOOL("x-zvbb", RISCVCPU, cfg.ext_zvbb, false), | ||
256 | - DEFINE_PROP_BOOL("x-zvbc", RISCVCPU, cfg.ext_zvbc, false), | ||
257 | - DEFINE_PROP_BOOL("x-zvkg", RISCVCPU, cfg.ext_zvkg, false), | ||
258 | - DEFINE_PROP_BOOL("x-zvkned", RISCVCPU, cfg.ext_zvkned, false), | ||
259 | - DEFINE_PROP_BOOL("x-zvknha", RISCVCPU, cfg.ext_zvknha, false), | ||
260 | - DEFINE_PROP_BOOL("x-zvknhb", RISCVCPU, cfg.ext_zvknhb, false), | ||
261 | - DEFINE_PROP_BOOL("x-zvksed", RISCVCPU, cfg.ext_zvksed, false), | ||
262 | - DEFINE_PROP_BOOL("x-zvksh", RISCVCPU, cfg.ext_zvksh, false), | ||
263 | + MULTI_EXT_CFG_BOOL("x-zvbb", ext_zvbb, false), | ||
264 | + MULTI_EXT_CFG_BOOL("x-zvbc", ext_zvbc, false), | ||
265 | + MULTI_EXT_CFG_BOOL("x-zvkg", ext_zvkg, false), | ||
266 | + MULTI_EXT_CFG_BOOL("x-zvkned", ext_zvkned, false), | ||
267 | + MULTI_EXT_CFG_BOOL("x-zvknha", ext_zvknha, false), | ||
268 | + MULTI_EXT_CFG_BOOL("x-zvknhb", ext_zvknhb, false), | ||
269 | + MULTI_EXT_CFG_BOOL("x-zvksed", ext_zvksed, false), | ||
270 | + MULTI_EXT_CFG_BOOL("x-zvksh", ext_zvksh, false), | ||
271 | |||
272 | DEFINE_PROP_END_OF_LIST(), | ||
273 | }; | ||
274 | @@ -XXX,XX +XXX,XX @@ static Property riscv_cpu_options[] = { | ||
275 | DEFINE_PROP_END_OF_LIST(), | ||
276 | }; | ||
277 | |||
278 | -static void riscv_cpu_add_qdev_prop_array(DeviceState *dev, Property *array) | ||
279 | +static void cpu_set_multi_ext_cfg(Object *obj, Visitor *v, const char *name, | ||
280 | + void *opaque, Error **errp) | ||
281 | +{ | ||
282 | + const RISCVCPUMultiExtConfig *multi_ext_cfg = opaque; | ||
283 | + bool value; | ||
284 | + | ||
285 | + if (!visit_type_bool(v, name, &value, errp)) { | ||
286 | + return; | ||
287 | + } | ||
288 | + | ||
289 | + isa_ext_update_enabled(RISCV_CPU(obj), multi_ext_cfg->offset, value); | ||
290 | + | ||
291 | + g_hash_table_insert(multi_ext_user_opts, | ||
292 | + GUINT_TO_POINTER(multi_ext_cfg->offset), | ||
293 | + (gpointer)value); | ||
294 | +} | ||
295 | + | ||
296 | +static void cpu_get_multi_ext_cfg(Object *obj, Visitor *v, const char *name, | ||
297 | + void *opaque, Error **errp) | ||
298 | +{ | ||
299 | + const RISCVCPUMultiExtConfig *multi_ext_cfg = opaque; | ||
300 | + bool value = isa_ext_is_enabled(RISCV_CPU(obj), multi_ext_cfg->offset); | ||
301 | + | ||
302 | + visit_type_bool(v, name, &value, errp); | ||
303 | +} | ||
304 | + | ||
305 | +static void cpu_add_multi_ext_prop(Object *cpu_obj, | ||
306 | + RISCVCPUMultiExtConfig *multi_cfg) | ||
307 | +{ | ||
308 | + object_property_add(cpu_obj, multi_cfg->name, "bool", | ||
309 | + cpu_get_multi_ext_cfg, | ||
310 | + cpu_set_multi_ext_cfg, | ||
311 | + NULL, (void *)multi_cfg); | ||
312 | + | ||
313 | + /* | ||
314 | + * Set def val directly instead of using | ||
315 | + * object_property_set_bool() to save the set() | ||
316 | + * callback hash for user inputs. | ||
317 | + */ | ||
318 | + isa_ext_update_enabled(RISCV_CPU(cpu_obj), multi_cfg->offset, | ||
319 | + multi_cfg->enabled); | ||
320 | +} | ||
321 | + | ||
322 | +static void riscv_cpu_add_multiext_prop_array(Object *obj, | ||
323 | + RISCVCPUMultiExtConfig *array) | ||
324 | { | ||
325 | g_assert(array); | ||
326 | |||
327 | - for (Property *prop = array; prop && prop->name; prop++) { | ||
328 | - qdev_property_add_static(dev, prop); | ||
329 | + for (RISCVCPUMultiExtConfig *prop = array; prop && prop->name; prop++) { | ||
330 | + cpu_add_multi_ext_prop(obj, prop); | ||
62 | } | 331 | } |
63 | } | 332 | } |
64 | diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c | 333 | |
65 | index XXXXXXX..XXXXXXX 100644 | 334 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_add_kvm_unavail_prop(Object *obj, const char *prop_name) |
66 | --- a/hw/riscv/virt.c | 335 | } |
67 | +++ b/hw/riscv/virt.c | 336 | |
68 | @@ -XXX,XX +XXX,XX @@ static void create_fdt(RISCVVirtState *s, const MemMapEntry *memmap, | 337 | static void riscv_cpu_add_kvm_unavail_prop_array(Object *obj, |
69 | create_fdt_flash(s, memmap); | 338 | - Property *array) |
70 | 339 | + RISCVCPUMultiExtConfig *array) | |
71 | update_bootargs: | 340 | { |
72 | - if (cmdline) { | 341 | g_assert(array); |
73 | + if (cmdline && *cmdline) { | 342 | |
74 | qemu_fdt_setprop_string(mc->fdt, "/chosen", "bootargs", cmdline); | 343 | - for (Property *prop = array; prop && prop->name; prop++) { |
344 | + for (RISCVCPUMultiExtConfig *prop = array; prop && prop->name; prop++) { | ||
345 | riscv_cpu_add_kvm_unavail_prop(obj, prop->name); | ||
75 | } | 346 | } |
76 | } | 347 | } |
348 | @@ -XXX,XX +XXX,XX @@ void kvm_riscv_cpu_add_kvm_properties(Object *obj) | ||
349 | */ | ||
350 | static void riscv_cpu_add_user_properties(Object *obj) | ||
351 | { | ||
352 | - DeviceState *dev = DEVICE(obj); | ||
353 | - | ||
354 | #ifndef CONFIG_USER_ONLY | ||
355 | riscv_add_satp_mode_properties(obj); | ||
356 | |||
357 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_add_user_properties(Object *obj) | ||
358 | |||
359 | riscv_cpu_add_misa_properties(obj); | ||
360 | |||
361 | - riscv_cpu_add_qdev_prop_array(dev, riscv_cpu_extensions); | ||
362 | - riscv_cpu_add_qdev_prop_array(dev, riscv_cpu_options); | ||
363 | - riscv_cpu_add_qdev_prop_array(dev, riscv_cpu_vendor_exts); | ||
364 | - riscv_cpu_add_qdev_prop_array(dev, riscv_cpu_experimental_exts); | ||
365 | + riscv_cpu_add_multiext_prop_array(obj, riscv_cpu_extensions); | ||
366 | + riscv_cpu_add_multiext_prop_array(obj, riscv_cpu_vendor_exts); | ||
367 | + riscv_cpu_add_multiext_prop_array(obj, riscv_cpu_experimental_exts); | ||
368 | + | ||
369 | + for (Property *prop = riscv_cpu_options; prop && prop->name; prop++) { | ||
370 | + qdev_property_add_static(DEVICE(obj), prop); | ||
371 | + } | ||
372 | } | ||
373 | |||
374 | /* | ||
375 | @@ -XXX,XX +XXX,XX @@ static void riscv_init_max_cpu_extensions(Object *obj) | ||
376 | { | ||
377 | RISCVCPU *cpu = RISCV_CPU(obj); | ||
378 | CPURISCVState *env = &cpu->env; | ||
379 | - Property *prop; | ||
380 | + RISCVCPUMultiExtConfig *prop; | ||
381 | |||
382 | /* Enable RVG, RVJ and RVV that are disabled by default */ | ||
383 | set_misa(env, env->misa_mxl, env->misa_ext | RVG | RVJ | RVV); | ||
77 | -- | 384 | -- |
78 | 2.35.1 | 385 | 2.41.0 | diff view generated by jsdifflib |
1 | From: Bin Meng <bin.meng@windriver.com> | 1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
---|---|---|---|
2 | 2 | ||
3 | At present the adding '/chosen/stdout-path' property in device tree | 3 | Before adding support to detect if an extension was user set we need to |
4 | is determined by whether a kernel command line is provided, which is | 4 | handle how we're enabling extensions in riscv_init_max_cpu_extensions(). |
5 | wrong. It should be added unconditionally. | 5 | object_property_set_bool() calls the set() callback for the property, |
6 | and we're going to use this callback to set the 'multi_ext_user_opts' | ||
7 | hash. | ||
6 | 8 | ||
7 | Fixes: 8d8897accb1c ("hw/riscv: spike: Allow using binary firmware as bios") | 9 | This means that, as is today, all extensions we're setting for the 'max' |
8 | Signed-off-by: Bin Meng <bin.meng@windriver.com> | 10 | CPU will be seen as user set in the future. Let's change set_bool() to |
11 | isa_ext_update_enabled() that will just enable/disable the flag on a | ||
12 | certain offset. | ||
13 | |||
14 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
9 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 15 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
10 | Message-Id: <20220421055629.1177285-1-bmeng.cn@gmail.com> | 16 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> |
17 | Message-ID: <20230912132423.268494-19-dbarboza@ventanamicro.com> | ||
11 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 18 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
12 | --- | 19 | --- |
13 | hw/riscv/spike.c | 5 +++-- | 20 | target/riscv/cpu.c | 18 +++++++++--------- |
14 | 1 file changed, 3 insertions(+), 2 deletions(-) | 21 | 1 file changed, 9 insertions(+), 9 deletions(-) |
15 | 22 | ||
16 | diff --git a/hw/riscv/spike.c b/hw/riscv/spike.c | 23 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c |
17 | index XXXXXXX..XXXXXXX 100644 | 24 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/hw/riscv/spike.c | 25 | --- a/target/riscv/cpu.c |
19 | +++ b/hw/riscv/spike.c | 26 | +++ b/target/riscv/cpu.c |
20 | @@ -XXX,XX +XXX,XX @@ static void create_fdt(SpikeState *s, const MemMapEntry *memmap, | 27 | @@ -XXX,XX +XXX,XX @@ static void riscv_init_max_cpu_extensions(Object *obj) |
21 | 28 | set_misa(env, env->misa_mxl, env->misa_ext | RVG | RVJ | RVV); | |
22 | riscv_socket_fdt_write_distance_matrix(mc, fdt); | 29 | |
23 | 30 | for (prop = riscv_cpu_extensions; prop && prop->name; prop++) { | |
24 | + qemu_fdt_add_subnode(fdt, "/chosen"); | 31 | - object_property_set_bool(obj, prop->name, true, NULL); |
25 | + qemu_fdt_setprop_string(fdt, "/chosen", "stdout-path", "/htif"); | 32 | + isa_ext_update_enabled(cpu, prop->offset, true); |
26 | + | 33 | } |
27 | if (cmdline) { | 34 | |
28 | - qemu_fdt_add_subnode(fdt, "/chosen"); | 35 | /* set vector version */ |
29 | qemu_fdt_setprop_string(fdt, "/chosen", "bootargs", cmdline); | 36 | env->vext_ver = VEXT_VERSION_1_00_0; |
30 | - qemu_fdt_setprop_string(fdt, "/chosen", "stdout-path", "/htif"); | 37 | |
38 | /* Zfinx is not compatible with F. Disable it */ | ||
39 | - object_property_set_bool(obj, "zfinx", false, NULL); | ||
40 | - object_property_set_bool(obj, "zdinx", false, NULL); | ||
41 | - object_property_set_bool(obj, "zhinx", false, NULL); | ||
42 | - object_property_set_bool(obj, "zhinxmin", false, NULL); | ||
43 | + isa_ext_update_enabled(cpu, CPU_CFG_OFFSET(ext_zfinx), false); | ||
44 | + isa_ext_update_enabled(cpu, CPU_CFG_OFFSET(ext_zdinx), false); | ||
45 | + isa_ext_update_enabled(cpu, CPU_CFG_OFFSET(ext_zhinx), false); | ||
46 | + isa_ext_update_enabled(cpu, CPU_CFG_OFFSET(ext_zhinxmin), false); | ||
47 | |||
48 | - object_property_set_bool(obj, "zce", false, NULL); | ||
49 | - object_property_set_bool(obj, "zcmp", false, NULL); | ||
50 | - object_property_set_bool(obj, "zcmt", false, NULL); | ||
51 | + isa_ext_update_enabled(cpu, CPU_CFG_OFFSET(ext_zce), false); | ||
52 | + isa_ext_update_enabled(cpu, CPU_CFG_OFFSET(ext_zcmp), false); | ||
53 | + isa_ext_update_enabled(cpu, CPU_CFG_OFFSET(ext_zcmt), false); | ||
54 | |||
55 | if (env->misa_mxl != MXL_RV32) { | ||
56 | - object_property_set_bool(obj, "zcf", false, NULL); | ||
57 | + isa_ext_update_enabled(cpu, CPU_CFG_OFFSET(ext_zcf), false); | ||
31 | } | 58 | } |
32 | } | 59 | } |
33 | 60 | ||
34 | -- | 61 | -- |
35 | 2.35.1 | 62 | 2.41.0 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
1 | 2 | ||
3 | Add a new cpu_cfg_ext_is_user_set() helper to check if an extension was | ||
4 | set by the user in the command line. Use it inside | ||
5 | cpu_cfg_ext_auto_update() to verify if the user set a certain extension | ||
6 | and, if that's the case, do not change its value. | ||
7 | |||
8 | This will make us honor user choice instead of overwriting the values. | ||
9 | Users will then be informed whether they're using an incompatible set of | ||
10 | extensions instead of QEMU setting a magic value that works. | ||
11 | |||
12 | The reason why we're not implementing user choice for MISA extensions | ||
13 | right now is because, today, we do not silently change any MISA bit | ||
14 | during realize() time (we do warn when enabling bits if RVG is enabled). | ||
15 | We do that - a lot - with multi-letter extensions though, so we're | ||
16 | handling the most immediate concern first. | ||
17 | |||
18 | After this patch, we'll now error out if the user explicitly set 'zce' to true | ||
19 | and 'zca' to false: | ||
20 | |||
21 | $ ./build/qemu-system-riscv64 -M virt -cpu rv64,zce=true,zca=false -nographic | ||
22 | qemu-system-riscv64: Zcf/Zcd/Zcb/Zcmp/Zcmt extensions require Zca extension | ||
23 | |||
24 | This didn't happen before because we were enabling 'zca' if 'zce' was enabled | ||
25 | regardless if the user set 'zca' to false. | ||
26 | |||
27 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
28 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
29 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> | ||
30 | Message-ID: <20230912132423.268494-20-dbarboza@ventanamicro.com> | ||
31 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
32 | --- | ||
33 | target/riscv/cpu.c | 16 ++++++++++++++++ | ||
34 | 1 file changed, 16 insertions(+) | ||
35 | |||
36 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | ||
37 | index XXXXXXX..XXXXXXX 100644 | ||
38 | --- a/target/riscv/cpu.c | ||
39 | +++ b/target/riscv/cpu.c | ||
40 | @@ -XXX,XX +XXX,XX @@ static int cpu_cfg_ext_get_min_version(uint32_t ext_offset) | ||
41 | g_assert_not_reached(); | ||
42 | } | ||
43 | |||
44 | +static bool cpu_cfg_ext_is_user_set(uint32_t ext_offset) | ||
45 | +{ | ||
46 | + return g_hash_table_contains(multi_ext_user_opts, | ||
47 | + GUINT_TO_POINTER(ext_offset)); | ||
48 | +} | ||
49 | + | ||
50 | static void cpu_cfg_ext_auto_update(RISCVCPU *cpu, uint32_t ext_offset, | ||
51 | bool value) | ||
52 | { | ||
53 | @@ -XXX,XX +XXX,XX @@ static void cpu_cfg_ext_auto_update(RISCVCPU *cpu, uint32_t ext_offset, | ||
54 | return; | ||
55 | } | ||
56 | |||
57 | + if (cpu_cfg_ext_is_user_set(ext_offset)) { | ||
58 | + return; | ||
59 | + } | ||
60 | + | ||
61 | if (value && env->priv_ver != PRIV_VERSION_LATEST) { | ||
62 | /* Do not enable it if priv_ver is older than min_version */ | ||
63 | min_version = cpu_cfg_ext_get_min_version(ext_offset); | ||
64 | @@ -XXX,XX +XXX,XX @@ static RISCVCPUMisaExtConfig misa_ext_cfgs[] = { | ||
65 | MISA_CFG(RVG, false), | ||
66 | }; | ||
67 | |||
68 | +/* | ||
69 | + * We do not support user choice tracking for MISA | ||
70 | + * extensions yet because, so far, we do not silently | ||
71 | + * change MISA bits during realize() (RVG enables MISA | ||
72 | + * bits but the user is warned about it). | ||
73 | + */ | ||
74 | static void riscv_cpu_add_misa_properties(Object *cpu_obj) | ||
75 | { | ||
76 | int i; | ||
77 | -- | ||
78 | 2.41.0 | diff view generated by jsdifflib |
1 | From: Weiwei Li <liweiwei@iscas.ac.cn> | 1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
---|---|---|---|
2 | 2 | ||
3 | - add zbk* and zk* strings to isa_edata_arr | 3 | Enabling RVG will enable a set of extensions that we're not checking if |
4 | the user was okay enabling or not. And in this case we want to error | ||
5 | out, instead of ignoring, otherwise we will be inconsistent enabling RVG | ||
6 | without all its extensions. | ||
4 | 7 | ||
5 | Signed-off-by: Weiwei Li <liweiwei@iscas.ac.cn> | 8 | After this patch, disabling ifencei or icsr while enabling RVG will |
6 | Signed-off-by: Junqiang Wang <wangjunqiang@iscas.ac.cn> | 9 | result in error: |
7 | Tested-by: Jiatai He <jiatai2021@iscas.ac.cn> | 10 | |
11 | $ ./build/qemu-system-riscv64 -M virt -cpu rv64,g=true,Zifencei=false --nographic | ||
12 | qemu-system-riscv64: RVG requires Zifencei but user set Zifencei to false | ||
13 | |||
14 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
8 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 15 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
9 | Message-Id: <20220426095204.24142-1-liweiwei@iscas.ac.cn> | 16 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> |
17 | Message-ID: <20230912132423.268494-21-dbarboza@ventanamicro.com> | ||
10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 18 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
11 | --- | 19 | --- |
12 | target/riscv/cpu.c | 13 +++++++++++++ | 20 | target/riscv/cpu.c | 18 ++++++++++++++++-- |
13 | 1 file changed, 13 insertions(+) | 21 | 1 file changed, 16 insertions(+), 2 deletions(-) |
14 | 22 | ||
15 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | 23 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c |
16 | index XXXXXXX..XXXXXXX 100644 | 24 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/target/riscv/cpu.c | 25 | --- a/target/riscv/cpu.c |
18 | +++ b/target/riscv/cpu.c | 26 | +++ b/target/riscv/cpu.c |
19 | @@ -XXX,XX +XXX,XX @@ static void riscv_isa_string_ext(RISCVCPU *cpu, char **isa_str, int max_str_len) | 27 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp) |
20 | ISA_EDATA_ENTRY(zba, ext_zba), | 28 | riscv_has_ext(env, RVA) && riscv_has_ext(env, RVF) && |
21 | ISA_EDATA_ENTRY(zbb, ext_zbb), | 29 | riscv_has_ext(env, RVD) && |
22 | ISA_EDATA_ENTRY(zbc, ext_zbc), | 30 | cpu->cfg.ext_icsr && cpu->cfg.ext_ifencei)) { |
23 | + ISA_EDATA_ENTRY(zbkb, ext_zbkb), | 31 | + |
24 | + ISA_EDATA_ENTRY(zbkc, ext_zbkc), | 32 | + if (cpu_cfg_ext_is_user_set(CPU_CFG_OFFSET(ext_icsr)) && |
25 | + ISA_EDATA_ENTRY(zbkx, ext_zbkx), | 33 | + !cpu->cfg.ext_icsr) { |
26 | ISA_EDATA_ENTRY(zbs, ext_zbs), | 34 | + error_setg(errp, "RVG requires Zicsr but user set Zicsr to false"); |
27 | + ISA_EDATA_ENTRY(zk, ext_zk), | 35 | + return; |
28 | + ISA_EDATA_ENTRY(zkn, ext_zkn), | 36 | + } |
29 | + ISA_EDATA_ENTRY(zknd, ext_zknd), | 37 | + |
30 | + ISA_EDATA_ENTRY(zkne, ext_zkne), | 38 | + if (cpu_cfg_ext_is_user_set(CPU_CFG_OFFSET(ext_ifencei)) && |
31 | + ISA_EDATA_ENTRY(zknh, ext_zknh), | 39 | + !cpu->cfg.ext_ifencei) { |
32 | + ISA_EDATA_ENTRY(zkr, ext_zkr), | 40 | + error_setg(errp, "RVG requires Zifencei but user set " |
33 | + ISA_EDATA_ENTRY(zks, ext_zks), | 41 | + "Zifencei to false"); |
34 | + ISA_EDATA_ENTRY(zksed, ext_zksed), | 42 | + return; |
35 | + ISA_EDATA_ENTRY(zksh, ext_zksh), | 43 | + } |
36 | + ISA_EDATA_ENTRY(zkt, ext_zkt), | 44 | + |
37 | ISA_EDATA_ENTRY(zve32f, ext_zve32f), | 45 | warn_report("Setting G will also set IMAFD_Zicsr_Zifencei"); |
38 | ISA_EDATA_ENTRY(zve64f, ext_zve64f), | 46 | - cpu->cfg.ext_icsr = true; |
39 | ISA_EDATA_ENTRY(svinval, ext_svinval), | 47 | - cpu->cfg.ext_ifencei = true; |
48 | + cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_icsr), true); | ||
49 | + cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_ifencei), true); | ||
50 | |||
51 | env->misa_ext |= RVI | RVM | RVA | RVF | RVD; | ||
52 | env->misa_ext_mask |= RVI | RVM | RVA | RVF | RVD; | ||
40 | -- | 53 | -- |
41 | 2.35.1 | 54 | 2.41.0 | diff view generated by jsdifflib |
1 | From: Weiwei Li <liweiwei@iscas.ac.cn> | 1 | From: "liguang.zhang" <liguang.zhang@hexintek.com> |
---|---|---|---|
2 | 2 | ||
3 | - add aes64dsm, aes64ds, aes64im, aes64es, aes64esm, aes64ks2, aes64ks1i instructions | 3 | This patch fixes guest reboot errors when using KVM. |
4 | 4 | ||
5 | Co-authored-by: Ruibo Lu <luruibo2000@163.com> | 5 | There are two issues when rebooting a guest using KVM |
6 | Co-authored-by: Zewen Ye <lustrew@foxmail.com> | 6 | 1. When the guest initiates a reboot the host is unable to stop the vcpu |
7 | Signed-off-by: Weiwei Li <liweiwei@iscas.ac.cn> | 7 | 2. When running a SMP guest the qemu monitor system_reset causes a vcpu crash |
8 | Signed-off-by: Junqiang Wang <wangjunqiang@iscas.ac.cn> | 8 | |
9 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 9 | This can be fixed by clearing the CSR values at reset and syncing the |
10 | Acked-by: Alistair Francis <alistair.francis@wdc.com> | 10 | MPSTATE with the host. |
11 | Message-Id: <20220423023510.30794-8-liweiwei@iscas.ac.cn> | 11 | |
12 | Signed-off-by: liguang.zhang <liguang.zhang@hexintek.com> | ||
13 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
14 | Message-ID: <20230913091332.17355-1-18622748025@163.com> | ||
15 | [ Changes by AF | ||
16 | - Fixup commit message | ||
17 | - Fixup patch style | ||
18 | ] | ||
12 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 19 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
13 | --- | 20 | --- |
14 | target/riscv/helper.h | 8 ++ | 21 | target/riscv/kvm_riscv.h | 1 + |
15 | target/riscv/insn32.decode | 12 ++ | 22 | target/riscv/kvm.c | 44 ++++++++++++++++++++++++++++++++++++++++ |
16 | target/riscv/crypto_helper.c | 169 ++++++++++++++++++++++++ | 23 | 2 files changed, 45 insertions(+) |
17 | target/riscv/insn_trans/trans_rvk.c.inc | 54 ++++++++ | ||
18 | 4 files changed, 243 insertions(+) | ||
19 | 24 | ||
20 | diff --git a/target/riscv/helper.h b/target/riscv/helper.h | 25 | diff --git a/target/riscv/kvm_riscv.h b/target/riscv/kvm_riscv.h |
21 | index XXXXXXX..XXXXXXX 100644 | 26 | index XXXXXXX..XXXXXXX 100644 |
22 | --- a/target/riscv/helper.h | 27 | --- a/target/riscv/kvm_riscv.h |
23 | +++ b/target/riscv/helper.h | 28 | +++ b/target/riscv/kvm_riscv.h |
24 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_3(aes32esmi, TCG_CALL_NO_RWG_SE, tl, tl, tl, tl) | 29 | @@ -XXX,XX +XXX,XX @@ void kvm_riscv_aia_create(MachineState *machine, uint64_t group_shift, |
25 | DEF_HELPER_FLAGS_3(aes32esi, TCG_CALL_NO_RWG_SE, tl, tl, tl, tl) | 30 | uint64_t aplic_base, uint64_t imsic_base, |
26 | DEF_HELPER_FLAGS_3(aes32dsmi, TCG_CALL_NO_RWG_SE, tl, tl, tl, tl) | 31 | uint64_t guest_num); |
27 | DEF_HELPER_FLAGS_3(aes32dsi, TCG_CALL_NO_RWG_SE, tl, tl, tl, tl) | 32 | void riscv_kvm_aplic_request(void *opaque, int irq, int level); |
33 | +int kvm_riscv_sync_mpstate_to_kvm(RISCVCPU *cpu, int state); | ||
34 | |||
35 | #endif | ||
36 | diff --git a/target/riscv/kvm.c b/target/riscv/kvm.c | ||
37 | index XXXXXXX..XXXXXXX 100644 | ||
38 | --- a/target/riscv/kvm.c | ||
39 | +++ b/target/riscv/kvm.c | ||
40 | @@ -XXX,XX +XXX,XX @@ void riscv_kvm_aplic_request(void *opaque, int irq, int level) | ||
41 | kvm_set_irq(kvm_state, irq, !!level); | ||
42 | } | ||
43 | |||
44 | +static bool cap_has_mp_state; | ||
28 | + | 45 | + |
29 | +DEF_HELPER_FLAGS_2(aes64esm, TCG_CALL_NO_RWG_SE, tl, tl, tl) | 46 | static uint64_t kvm_riscv_reg_id(CPURISCVState *env, uint64_t type, |
30 | +DEF_HELPER_FLAGS_2(aes64es, TCG_CALL_NO_RWG_SE, tl, tl, tl) | 47 | uint64_t idx) |
31 | +DEF_HELPER_FLAGS_2(aes64ds, TCG_CALL_NO_RWG_SE, tl, tl, tl) | ||
32 | +DEF_HELPER_FLAGS_2(aes64dsm, TCG_CALL_NO_RWG_SE, tl, tl, tl) | ||
33 | +DEF_HELPER_FLAGS_2(aes64ks2, TCG_CALL_NO_RWG_SE, tl, tl, tl) | ||
34 | +DEF_HELPER_FLAGS_2(aes64ks1i, TCG_CALL_NO_RWG_SE, tl, tl, tl) | ||
35 | +DEF_HELPER_FLAGS_1(aes64im, TCG_CALL_NO_RWG_SE, tl, tl) | ||
36 | diff --git a/target/riscv/insn32.decode b/target/riscv/insn32.decode | ||
37 | index XXXXXXX..XXXXXXX 100644 | ||
38 | --- a/target/riscv/insn32.decode | ||
39 | +++ b/target/riscv/insn32.decode | ||
40 | @@ -XXX,XX +XXX,XX @@ | ||
41 | %imm_j 31:s1 12:8 20:1 21:10 !function=ex_shift_1 | ||
42 | %imm_u 12:s20 !function=ex_shift_12 | ||
43 | %imm_bs 30:2 !function=ex_shift_3 | ||
44 | +%imm_rnum 20:4 | ||
45 | |||
46 | # Argument sets: | ||
47 | &empty | ||
48 | @@ -XXX,XX +XXX,XX @@ | ||
49 | @sfence_vm ....... ..... ..... ... ..... ....... %rs1 | ||
50 | |||
51 | @k_aes .. ..... ..... ..... ... ..... ....... &k_aes shamt=%imm_bs %rs2 %rs1 %rd | ||
52 | +@i_aes .. ..... ..... ..... ... ..... ....... &i imm=%imm_rnum %rs1 %rd | ||
53 | |||
54 | # Formats 64: | ||
55 | @sh5 ....... ..... ..... ... ..... ....... &shift shamt=%sh5 %rs1 %rd | ||
56 | @@ -XXX,XX +XXX,XX @@ hinval_gvma 0110011 ..... ..... 000 00000 1110011 @hfence_gvma | ||
57 | # *** RV32 Zknd Standard Extension *** | ||
58 | aes32dsmi .. 10111 ..... ..... 000 ..... 0110011 @k_aes | ||
59 | aes32dsi .. 10101 ..... ..... 000 ..... 0110011 @k_aes | ||
60 | +# *** RV64 Zknd Standard Extension *** | ||
61 | +aes64dsm 00 11111 ..... ..... 000 ..... 0110011 @r | ||
62 | +aes64ds 00 11101 ..... ..... 000 ..... 0110011 @r | ||
63 | +aes64im 00 11000 00000 ..... 001 ..... 0010011 @r2 | ||
64 | # *** RV32 Zkne Standard Extension *** | ||
65 | aes32esmi .. 10011 ..... ..... 000 ..... 0110011 @k_aes | ||
66 | aes32esi .. 10001 ..... ..... 000 ..... 0110011 @k_aes | ||
67 | +# *** RV64 Zkne Standard Extension *** | ||
68 | +aes64es 00 11001 ..... ..... 000 ..... 0110011 @r | ||
69 | +aes64esm 00 11011 ..... ..... 000 ..... 0110011 @r | ||
70 | +# *** RV64 Zkne/zknd Standard Extension *** | ||
71 | +aes64ks2 01 11111 ..... ..... 000 ..... 0110011 @r | ||
72 | +aes64ks1i 00 11000 1.... ..... 001 ..... 0010011 @i_aes | ||
73 | diff --git a/target/riscv/crypto_helper.c b/target/riscv/crypto_helper.c | ||
74 | index XXXXXXX..XXXXXXX 100644 | ||
75 | --- a/target/riscv/crypto_helper.c | ||
76 | +++ b/target/riscv/crypto_helper.c | ||
77 | @@ -XXX,XX +XXX,XX @@ target_ulong HELPER(aes32dsi)(target_ulong rs1, target_ulong rs2, | ||
78 | { | 48 | { |
79 | return aes32_operation(shamt, rs1, rs2, false, false); | 49 | @@ -XXX,XX +XXX,XX @@ int kvm_arch_get_registers(CPUState *cs) |
50 | return ret; | ||
80 | } | 51 | } |
52 | |||
53 | +int kvm_riscv_sync_mpstate_to_kvm(RISCVCPU *cpu, int state) | ||
54 | +{ | ||
55 | + if (cap_has_mp_state) { | ||
56 | + struct kvm_mp_state mp_state = { | ||
57 | + .mp_state = state | ||
58 | + }; | ||
81 | + | 59 | + |
82 | +#define BY(X, I) ((X >> (8 * I)) & 0xFF) | 60 | + int ret = kvm_vcpu_ioctl(CPU(cpu), KVM_SET_MP_STATE, &mp_state); |
83 | + | 61 | + if (ret) { |
84 | +#define AES_SHIFROWS_LO(RS1, RS2) ( \ | 62 | + fprintf(stderr, "%s: failed to sync MP_STATE %d/%s\n", |
85 | + (((RS1 >> 24) & 0xFF) << 56) | (((RS2 >> 48) & 0xFF) << 48) | \ | 63 | + __func__, ret, strerror(-ret)); |
86 | + (((RS2 >> 8) & 0xFF) << 40) | (((RS1 >> 32) & 0xFF) << 32) | \ | 64 | + return -1; |
87 | + (((RS2 >> 56) & 0xFF) << 24) | (((RS2 >> 16) & 0xFF) << 16) | \ | ||
88 | + (((RS1 >> 40) & 0xFF) << 8) | (((RS1 >> 0) & 0xFF) << 0)) | ||
89 | + | ||
90 | +#define AES_INVSHIFROWS_LO(RS1, RS2) ( \ | ||
91 | + (((RS2 >> 24) & 0xFF) << 56) | (((RS2 >> 48) & 0xFF) << 48) | \ | ||
92 | + (((RS1 >> 8) & 0xFF) << 40) | (((RS1 >> 32) & 0xFF) << 32) | \ | ||
93 | + (((RS1 >> 56) & 0xFF) << 24) | (((RS2 >> 16) & 0xFF) << 16) | \ | ||
94 | + (((RS2 >> 40) & 0xFF) << 8) | (((RS1 >> 0) & 0xFF) << 0)) | ||
95 | + | ||
96 | +#define AES_MIXBYTE(COL, B0, B1, B2, B3) ( \ | ||
97 | + BY(COL, B3) ^ BY(COL, B2) ^ AES_GFMUL(BY(COL, B1), 3) ^ \ | ||
98 | + AES_GFMUL(BY(COL, B0), 2)) | ||
99 | + | ||
100 | +#define AES_MIXCOLUMN(COL) ( \ | ||
101 | + AES_MIXBYTE(COL, 3, 0, 1, 2) << 24 | \ | ||
102 | + AES_MIXBYTE(COL, 2, 3, 0, 1) << 16 | \ | ||
103 | + AES_MIXBYTE(COL, 1, 2, 3, 0) << 8 | AES_MIXBYTE(COL, 0, 1, 2, 3) << 0) | ||
104 | + | ||
105 | +#define AES_INVMIXBYTE(COL, B0, B1, B2, B3) ( \ | ||
106 | + AES_GFMUL(BY(COL, B3), 0x9) ^ AES_GFMUL(BY(COL, B2), 0xd) ^ \ | ||
107 | + AES_GFMUL(BY(COL, B1), 0xb) ^ AES_GFMUL(BY(COL, B0), 0xe)) | ||
108 | + | ||
109 | +#define AES_INVMIXCOLUMN(COL) ( \ | ||
110 | + AES_INVMIXBYTE(COL, 3, 0, 1, 2) << 24 | \ | ||
111 | + AES_INVMIXBYTE(COL, 2, 3, 0, 1) << 16 | \ | ||
112 | + AES_INVMIXBYTE(COL, 1, 2, 3, 0) << 8 | \ | ||
113 | + AES_INVMIXBYTE(COL, 0, 1, 2, 3) << 0) | ||
114 | + | ||
115 | +static inline target_ulong aes64_operation(target_ulong rs1, target_ulong rs2, | ||
116 | + bool enc, bool mix) | ||
117 | +{ | ||
118 | + uint64_t RS1 = rs1; | ||
119 | + uint64_t RS2 = rs2; | ||
120 | + uint64_t result; | ||
121 | + uint64_t temp; | ||
122 | + uint32_t col_0; | ||
123 | + uint32_t col_1; | ||
124 | + | ||
125 | + if (enc) { | ||
126 | + temp = AES_SHIFROWS_LO(RS1, RS2); | ||
127 | + temp = (((uint64_t)AES_sbox[(temp >> 0) & 0xFF] << 0) | | ||
128 | + ((uint64_t)AES_sbox[(temp >> 8) & 0xFF] << 8) | | ||
129 | + ((uint64_t)AES_sbox[(temp >> 16) & 0xFF] << 16) | | ||
130 | + ((uint64_t)AES_sbox[(temp >> 24) & 0xFF] << 24) | | ||
131 | + ((uint64_t)AES_sbox[(temp >> 32) & 0xFF] << 32) | | ||
132 | + ((uint64_t)AES_sbox[(temp >> 40) & 0xFF] << 40) | | ||
133 | + ((uint64_t)AES_sbox[(temp >> 48) & 0xFF] << 48) | | ||
134 | + ((uint64_t)AES_sbox[(temp >> 56) & 0xFF] << 56)); | ||
135 | + if (mix) { | ||
136 | + col_0 = temp & 0xFFFFFFFF; | ||
137 | + col_1 = temp >> 32; | ||
138 | + | ||
139 | + col_0 = AES_MIXCOLUMN(col_0); | ||
140 | + col_1 = AES_MIXCOLUMN(col_1); | ||
141 | + | ||
142 | + result = ((uint64_t)col_1 << 32) | col_0; | ||
143 | + } else { | ||
144 | + result = temp; | ||
145 | + } | ||
146 | + } else { | ||
147 | + temp = AES_INVSHIFROWS_LO(RS1, RS2); | ||
148 | + temp = (((uint64_t)AES_isbox[(temp >> 0) & 0xFF] << 0) | | ||
149 | + ((uint64_t)AES_isbox[(temp >> 8) & 0xFF] << 8) | | ||
150 | + ((uint64_t)AES_isbox[(temp >> 16) & 0xFF] << 16) | | ||
151 | + ((uint64_t)AES_isbox[(temp >> 24) & 0xFF] << 24) | | ||
152 | + ((uint64_t)AES_isbox[(temp >> 32) & 0xFF] << 32) | | ||
153 | + ((uint64_t)AES_isbox[(temp >> 40) & 0xFF] << 40) | | ||
154 | + ((uint64_t)AES_isbox[(temp >> 48) & 0xFF] << 48) | | ||
155 | + ((uint64_t)AES_isbox[(temp >> 56) & 0xFF] << 56)); | ||
156 | + if (mix) { | ||
157 | + col_0 = temp & 0xFFFFFFFF; | ||
158 | + col_1 = temp >> 32; | ||
159 | + | ||
160 | + col_0 = AES_INVMIXCOLUMN(col_0); | ||
161 | + col_1 = AES_INVMIXCOLUMN(col_1); | ||
162 | + | ||
163 | + result = ((uint64_t)col_1 << 32) | col_0; | ||
164 | + } else { | ||
165 | + result = temp; | ||
166 | + } | 65 | + } |
167 | + } | 66 | + } |
168 | + | 67 | + |
169 | + return result; | 68 | + return 0; |
170 | +} | 69 | +} |
171 | + | 70 | + |
172 | +target_ulong HELPER(aes64esm)(target_ulong rs1, target_ulong rs2) | 71 | int kvm_arch_put_registers(CPUState *cs, int level) |
173 | +{ | 72 | { |
174 | + return aes64_operation(rs1, rs2, true, true); | 73 | int ret = 0; |
175 | +} | 74 | @@ -XXX,XX +XXX,XX @@ int kvm_arch_put_registers(CPUState *cs, int level) |
176 | + | 75 | return ret; |
177 | +target_ulong HELPER(aes64es)(target_ulong rs1, target_ulong rs2) | 76 | } |
178 | +{ | 77 | |
179 | + return aes64_operation(rs1, rs2, true, false); | 78 | + if (KVM_PUT_RESET_STATE == level) { |
180 | +} | 79 | + RISCVCPU *cpu = RISCV_CPU(cs); |
181 | + | 80 | + if (cs->cpu_index == 0) { |
182 | +target_ulong HELPER(aes64ds)(target_ulong rs1, target_ulong rs2) | 81 | + ret = kvm_riscv_sync_mpstate_to_kvm(cpu, KVM_MP_STATE_RUNNABLE); |
183 | +{ | 82 | + } else { |
184 | + return aes64_operation(rs1, rs2, false, false); | 83 | + ret = kvm_riscv_sync_mpstate_to_kvm(cpu, KVM_MP_STATE_STOPPED); |
185 | +} | 84 | + } |
186 | + | 85 | + if (ret) { |
187 | +target_ulong HELPER(aes64dsm)(target_ulong rs1, target_ulong rs2) | 86 | + return ret; |
188 | +{ | 87 | + } |
189 | + return aes64_operation(rs1, rs2, false, true); | ||
190 | +} | ||
191 | + | ||
192 | +target_ulong HELPER(aes64ks2)(target_ulong rs1, target_ulong rs2) | ||
193 | +{ | ||
194 | + uint64_t RS1 = rs1; | ||
195 | + uint64_t RS2 = rs2; | ||
196 | + uint32_t rs1_hi = RS1 >> 32; | ||
197 | + uint32_t rs2_lo = RS2; | ||
198 | + uint32_t rs2_hi = RS2 >> 32; | ||
199 | + | ||
200 | + uint32_t r_lo = (rs1_hi ^ rs2_lo); | ||
201 | + uint32_t r_hi = (rs1_hi ^ rs2_lo ^ rs2_hi); | ||
202 | + target_ulong result = ((uint64_t)r_hi << 32) | r_lo; | ||
203 | + | ||
204 | + return result; | ||
205 | +} | ||
206 | + | ||
207 | +target_ulong HELPER(aes64ks1i)(target_ulong rs1, target_ulong rnum) | ||
208 | +{ | ||
209 | + uint64_t RS1 = rs1; | ||
210 | + static const uint8_t round_consts[10] = { | ||
211 | + 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36 | ||
212 | + }; | ||
213 | + | ||
214 | + uint8_t enc_rnum = rnum; | ||
215 | + uint32_t temp = (RS1 >> 32) & 0xFFFFFFFF; | ||
216 | + uint8_t rcon_ = 0; | ||
217 | + target_ulong result; | ||
218 | + | ||
219 | + if (enc_rnum != 0xA) { | ||
220 | + temp = ror32(temp, 8); /* Rotate right by 8 */ | ||
221 | + rcon_ = round_consts[enc_rnum]; | ||
222 | + } | 88 | + } |
223 | + | 89 | + |
224 | + temp = ((uint32_t)AES_sbox[(temp >> 24) & 0xFF] << 24) | | 90 | return ret; |
225 | + ((uint32_t)AES_sbox[(temp >> 16) & 0xFF] << 16) | | ||
226 | + ((uint32_t)AES_sbox[(temp >> 8) & 0xFF] << 8) | | ||
227 | + ((uint32_t)AES_sbox[(temp >> 0) & 0xFF] << 0); | ||
228 | + | ||
229 | + temp ^= rcon_; | ||
230 | + | ||
231 | + result = ((uint64_t)temp << 32) | temp; | ||
232 | + | ||
233 | + return result; | ||
234 | +} | ||
235 | + | ||
236 | +target_ulong HELPER(aes64im)(target_ulong rs1) | ||
237 | +{ | ||
238 | + uint64_t RS1 = rs1; | ||
239 | + uint32_t col_0 = RS1 & 0xFFFFFFFF; | ||
240 | + uint32_t col_1 = RS1 >> 32; | ||
241 | + target_ulong result; | ||
242 | + | ||
243 | + col_0 = AES_INVMIXCOLUMN(col_0); | ||
244 | + col_1 = AES_INVMIXCOLUMN(col_1); | ||
245 | + | ||
246 | + result = ((uint64_t)col_1 << 32) | col_0; | ||
247 | + | ||
248 | + return result; | ||
249 | +} | ||
250 | #undef sext32_xlen | ||
251 | diff --git a/target/riscv/insn_trans/trans_rvk.c.inc b/target/riscv/insn_trans/trans_rvk.c.inc | ||
252 | index XXXXXXX..XXXXXXX 100644 | ||
253 | --- a/target/riscv/insn_trans/trans_rvk.c.inc | ||
254 | +++ b/target/riscv/insn_trans/trans_rvk.c.inc | ||
255 | @@ -XXX,XX +XXX,XX @@ static bool trans_aes32dsi(DisasContext *ctx, arg_aes32dsi *a) | ||
256 | REQUIRE_ZKND(ctx); | ||
257 | return gen_aes32_sm4(ctx, a, gen_helper_aes32dsi); | ||
258 | } | 91 | } |
259 | + | 92 | |
260 | +static bool trans_aes64es(DisasContext *ctx, arg_aes64es *a) | 93 | @@ -XXX,XX +XXX,XX @@ int kvm_arch_get_default_type(MachineState *ms) |
261 | +{ | 94 | |
262 | + REQUIRE_64BIT(ctx); | 95 | int kvm_arch_init(MachineState *ms, KVMState *s) |
263 | + REQUIRE_ZKNE(ctx); | 96 | { |
264 | + return gen_arith(ctx, a, EXT_NONE, gen_helper_aes64es, NULL); | 97 | + cap_has_mp_state = kvm_check_extension(s, KVM_CAP_MP_STATE); |
265 | +} | 98 | return 0; |
266 | + | 99 | } |
267 | +static bool trans_aes64esm(DisasContext *ctx, arg_aes64esm *a) | 100 | |
268 | +{ | 101 | @@ -XXX,XX +XXX,XX @@ int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run) |
269 | + REQUIRE_64BIT(ctx); | 102 | void kvm_riscv_reset_vcpu(RISCVCPU *cpu) |
270 | + REQUIRE_ZKNE(ctx); | 103 | { |
271 | + return gen_arith(ctx, a, EXT_NONE, gen_helper_aes64esm, NULL); | 104 | CPURISCVState *env = &cpu->env; |
272 | +} | 105 | + int i; |
273 | + | 106 | |
274 | +static bool trans_aes64ds(DisasContext *ctx, arg_aes64ds *a) | 107 | if (!kvm_enabled()) { |
275 | +{ | 108 | return; |
276 | + REQUIRE_64BIT(ctx); | 109 | } |
277 | + REQUIRE_ZKND(ctx); | 110 | + for (i = 0; i < 32; i++) { |
278 | + return gen_arith(ctx, a, EXT_NONE, gen_helper_aes64ds, NULL); | 111 | + env->gpr[i] = 0; |
279 | +} | ||
280 | + | ||
281 | +static bool trans_aes64dsm(DisasContext *ctx, arg_aes64dsm *a) | ||
282 | +{ | ||
283 | + REQUIRE_64BIT(ctx); | ||
284 | + REQUIRE_ZKND(ctx); | ||
285 | + return gen_arith(ctx, a, EXT_NONE, gen_helper_aes64dsm, NULL); | ||
286 | +} | ||
287 | + | ||
288 | +static bool trans_aes64ks2(DisasContext *ctx, arg_aes64ks2 *a) | ||
289 | +{ | ||
290 | + REQUIRE_64BIT(ctx); | ||
291 | + REQUIRE_EITHER_EXT(ctx, zknd, zkne); | ||
292 | + return gen_arith(ctx, a, EXT_NONE, gen_helper_aes64ks2, NULL); | ||
293 | +} | ||
294 | + | ||
295 | +static bool trans_aes64ks1i(DisasContext *ctx, arg_aes64ks1i *a) | ||
296 | +{ | ||
297 | + REQUIRE_64BIT(ctx); | ||
298 | + REQUIRE_EITHER_EXT(ctx, zknd, zkne); | ||
299 | + | ||
300 | + if (a->imm > 0xA) { | ||
301 | + return false; | ||
302 | + } | 112 | + } |
303 | + | 113 | env->pc = cpu->env.kernel_addr; |
304 | + return gen_arith_imm_tl(ctx, a, EXT_NONE, gen_helper_aes64ks1i, NULL); | 114 | env->gpr[10] = kvm_arch_vcpu_id(CPU(cpu)); /* a0 */ |
305 | +} | 115 | env->gpr[11] = cpu->env.fdt_addr; /* a1 */ |
306 | + | 116 | env->satp = 0; |
307 | +static bool trans_aes64im(DisasContext *ctx, arg_aes64im *a) | 117 | + env->mie = 0; |
308 | +{ | 118 | + env->stvec = 0; |
309 | + REQUIRE_64BIT(ctx); | 119 | + env->sscratch = 0; |
310 | + REQUIRE_ZKND(ctx); | 120 | + env->sepc = 0; |
311 | + return gen_unary(ctx, a, EXT_NONE, gen_helper_aes64im); | 121 | + env->scause = 0; |
312 | +} | 122 | + env->stval = 0; |
123 | + env->mip = 0; | ||
124 | } | ||
125 | |||
126 | void kvm_riscv_set_irq(RISCVCPU *cpu, int irq, int level) | ||
313 | -- | 127 | -- |
314 | 2.35.1 | 128 | 2.41.0 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Alvin Chang <vivahavey@gmail.com> | ||
1 | 2 | ||
3 | Fix the inverted order of pmpaddr13 and pmpaddr14 in csr_name(). | ||
4 | |||
5 | Signed-off-by: Alvin Chang <alvinga@andestech.com> | ||
6 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
7 | Message-ID: <20230907084500.328-1-alvinga@andestech.com> | ||
8 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
9 | --- | ||
10 | disas/riscv.c | 4 ++-- | ||
11 | 1 file changed, 2 insertions(+), 2 deletions(-) | ||
12 | |||
13 | diff --git a/disas/riscv.c b/disas/riscv.c | ||
14 | index XXXXXXX..XXXXXXX 100644 | ||
15 | --- a/disas/riscv.c | ||
16 | +++ b/disas/riscv.c | ||
17 | @@ -XXX,XX +XXX,XX @@ static const char *csr_name(int csrno) | ||
18 | case 0x03ba: return "pmpaddr10"; | ||
19 | case 0x03bb: return "pmpaddr11"; | ||
20 | case 0x03bc: return "pmpaddr12"; | ||
21 | - case 0x03bd: return "pmpaddr14"; | ||
22 | - case 0x03be: return "pmpaddr13"; | ||
23 | + case 0x03bd: return "pmpaddr13"; | ||
24 | + case 0x03be: return "pmpaddr14"; | ||
25 | case 0x03bf: return "pmpaddr15"; | ||
26 | case 0x0780: return "mtohost"; | ||
27 | case 0x0781: return "mfromhost"; | ||
28 | -- | ||
29 | 2.41.0 | diff view generated by jsdifflib |
1 | From: Weiwei Li <liweiwei@iscas.ac.cn> | 1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
---|---|---|---|
2 | 2 | ||
3 | - add aes32esmi, aes32esi, aes32dsmi and aes32dsi instructions | 3 | target/riscv/cpu.c needs to handle all possible accelerators (TCG and |
4 | KVM at this moment) during both init() and realize() time. This forces | ||
5 | us to resort to a lot of "if tcg" and "if kvm" throughout the code, | ||
6 | which isn't wrong, but can get cluttered over time. Splitting | ||
7 | acceleration specific code from cpu.c to its own file will help to | ||
8 | declutter the existing code and it will also make it easier to support | ||
9 | KVM/TCG only builds in the future. | ||
4 | 10 | ||
5 | Co-authored-by: Zewen Ye <lustrew@foxmail.com> | 11 | We'll start by adding a new subdir called 'tcg' and a new file called |
6 | Signed-off-by: Weiwei Li <liweiwei@iscas.ac.cn> | 12 | 'tcg-cpu.c'. This file will be used to introduce a new accelerator class |
7 | Signed-off-by: Junqiang Wang <wangjunqiang@iscas.ac.cn> | 13 | for TCG acceleration in RISC-V, allowing us to center all TCG exclusive |
8 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 14 | code in its file instead of using 'cpu.c' for everything. This design is |
15 | inpired by the work Claudio Fontana did in x86 a few years ago in commit | ||
16 | f5cc5a5c1 ("i386: split cpu accelerators from cpu.c, using | ||
17 | AccelCPUClass"). | ||
18 | |||
19 | To avoid moving too much code at once we'll start by adding the new file | ||
20 | and TCG AccelCPUClass declaration. The 'class_init' from the accel class | ||
21 | will init 'tcg_ops', relieving the common riscv_cpu_class_init() from | ||
22 | doing it. | ||
23 | |||
24 | 'riscv_tcg_ops' is being exported from 'cpu.c' for now to avoid having | ||
25 | to deal with moving code and files around right now. We'll focus on | ||
26 | decoupling the realize() logic first. | ||
27 | |||
28 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
29 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> | ||
30 | Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com> | ||
9 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 31 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
10 | Message-Id: <20220423023510.30794-7-liweiwei@iscas.ac.cn> | 32 | Message-ID: <20230925175709.35696-2-dbarboza@ventanamicro.com> |
11 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 33 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
12 | --- | 34 | --- |
13 | target/riscv/helper.h | 6 ++ | 35 | target/riscv/cpu.h | 4 +++ |
14 | target/riscv/insn32.decode | 11 +++ | 36 | target/riscv/cpu.c | 5 +--- |
15 | target/riscv/crypto_helper.c | 105 ++++++++++++++++++++++++ | 37 | target/riscv/tcg/tcg-cpu.c | 58 ++++++++++++++++++++++++++++++++++++ |
16 | target/riscv/translate.c | 1 + | 38 | target/riscv/meson.build | 2 ++ |
17 | target/riscv/insn_trans/trans_rvk.c.inc | 71 ++++++++++++++++ | 39 | target/riscv/tcg/meson.build | 2 ++ |
18 | target/riscv/meson.build | 3 +- | 40 | 5 files changed, 67 insertions(+), 4 deletions(-) |
19 | 6 files changed, 196 insertions(+), 1 deletion(-) | 41 | create mode 100644 target/riscv/tcg/tcg-cpu.c |
20 | create mode 100644 target/riscv/crypto_helper.c | 42 | create mode 100644 target/riscv/tcg/meson.build |
21 | create mode 100644 target/riscv/insn_trans/trans_rvk.c.inc | ||
22 | 43 | ||
23 | diff --git a/target/riscv/helper.h b/target/riscv/helper.h | 44 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h |
24 | index XXXXXXX..XXXXXXX 100644 | 45 | index XXXXXXX..XXXXXXX 100644 |
25 | --- a/target/riscv/helper.h | 46 | --- a/target/riscv/cpu.h |
26 | +++ b/target/riscv/helper.h | 47 | +++ b/target/riscv/cpu.h |
27 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_5(divu_i128, tl, env, tl, tl, tl, tl) | 48 | @@ -XXX,XX +XXX,XX @@ enum riscv_pmu_event_idx { |
28 | DEF_HELPER_5(divs_i128, tl, env, tl, tl, tl, tl) | 49 | RISCV_PMU_EVENT_CACHE_ITLB_PREFETCH_MISS = 0x10021, |
29 | DEF_HELPER_5(remu_i128, tl, env, tl, tl, tl, tl) | 50 | }; |
30 | DEF_HELPER_5(rems_i128, tl, env, tl, tl, tl, tl) | 51 | |
52 | +/* Export tcg_ops until we move everything to tcg/tcg-cpu.c */ | ||
53 | +#include "hw/core/tcg-cpu-ops.h" | ||
54 | +extern const struct TCGCPUOps riscv_tcg_ops; | ||
31 | + | 55 | + |
32 | +/* Crypto functions */ | 56 | /* CSR function table */ |
33 | +DEF_HELPER_FLAGS_3(aes32esmi, TCG_CALL_NO_RWG_SE, tl, tl, tl, tl) | 57 | extern riscv_csr_operations csr_ops[CSR_TABLE_SIZE]; |
34 | +DEF_HELPER_FLAGS_3(aes32esi, TCG_CALL_NO_RWG_SE, tl, tl, tl, tl) | 58 | |
35 | +DEF_HELPER_FLAGS_3(aes32dsmi, TCG_CALL_NO_RWG_SE, tl, tl, tl, tl) | 59 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c |
36 | +DEF_HELPER_FLAGS_3(aes32dsi, TCG_CALL_NO_RWG_SE, tl, tl, tl, tl) | ||
37 | diff --git a/target/riscv/insn32.decode b/target/riscv/insn32.decode | ||
38 | index XXXXXXX..XXXXXXX 100644 | 60 | index XXXXXXX..XXXXXXX 100644 |
39 | --- a/target/riscv/insn32.decode | 61 | --- a/target/riscv/cpu.c |
40 | +++ b/target/riscv/insn32.decode | 62 | +++ b/target/riscv/cpu.c |
41 | @@ -XXX,XX +XXX,XX @@ | 63 | @@ -XXX,XX +XXX,XX @@ static const struct SysemuCPUOps riscv_sysemu_ops = { |
42 | %imm_b 31:s1 7:1 25:6 8:4 !function=ex_shift_1 | 64 | }; |
43 | %imm_j 31:s1 12:8 20:1 21:10 !function=ex_shift_1 | 65 | #endif |
44 | %imm_u 12:s20 !function=ex_shift_12 | 66 | |
45 | +%imm_bs 30:2 !function=ex_shift_3 | 67 | -#include "hw/core/tcg-cpu-ops.h" |
46 | 68 | - | |
47 | # Argument sets: | 69 | -static const struct TCGCPUOps riscv_tcg_ops = { |
48 | &empty | 70 | +const struct TCGCPUOps riscv_tcg_ops = { |
49 | @@ -XXX,XX +XXX,XX @@ | 71 | .initialize = riscv_translate_init, |
50 | &rmr vm rd rs2 | 72 | .synchronize_from_tb = riscv_cpu_synchronize_from_tb, |
51 | &r2nfvm vm rd rs1 nf | 73 | .restore_state_to_opc = riscv_restore_state_to_opc, |
52 | &rnfvm vm rd rs1 rs2 nf | 74 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_class_init(ObjectClass *c, void *data) |
53 | +&k_aes shamt rs2 rs1 rd | 75 | #endif |
54 | 76 | cc->gdb_arch_name = riscv_gdb_arch_name; | |
55 | # Formats 32: | 77 | cc->gdb_get_dynamic_xml = riscv_gdb_get_dynamic_xml; |
56 | @r ....... ..... ..... ... ..... ....... &r %rs2 %rs1 %rd | 78 | - cc->tcg_ops = &riscv_tcg_ops; |
57 | @@ -XXX,XX +XXX,XX @@ | 79 | |
58 | @sfence_vma ....... ..... ..... ... ..... ....... %rs2 %rs1 | 80 | object_class_property_add(c, "mvendorid", "uint32", cpu_get_mvendorid, |
59 | @sfence_vm ....... ..... ..... ... ..... ....... %rs1 | 81 | cpu_set_mvendorid, NULL, NULL); |
60 | 82 | diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c | |
61 | +@k_aes .. ..... ..... ..... ... ..... ....... &k_aes shamt=%imm_bs %rs2 %rs1 %rd | ||
62 | + | ||
63 | # Formats 64: | ||
64 | @sh5 ....... ..... ..... ... ..... ....... &shift shamt=%sh5 %rs1 %rd | ||
65 | |||
66 | @@ -XXX,XX +XXX,XX @@ sfence_w_inval 0001100 00000 00000 000 00000 1110011 | ||
67 | sfence_inval_ir 0001100 00001 00000 000 00000 1110011 | ||
68 | hinval_vvma 0010011 ..... ..... 000 00000 1110011 @hfence_vvma | ||
69 | hinval_gvma 0110011 ..... ..... 000 00000 1110011 @hfence_gvma | ||
70 | + | ||
71 | +# *** RV32 Zknd Standard Extension *** | ||
72 | +aes32dsmi .. 10111 ..... ..... 000 ..... 0110011 @k_aes | ||
73 | +aes32dsi .. 10101 ..... ..... 000 ..... 0110011 @k_aes | ||
74 | +# *** RV32 Zkne Standard Extension *** | ||
75 | +aes32esmi .. 10011 ..... ..... 000 ..... 0110011 @k_aes | ||
76 | +aes32esi .. 10001 ..... ..... 000 ..... 0110011 @k_aes | ||
77 | diff --git a/target/riscv/crypto_helper.c b/target/riscv/crypto_helper.c | ||
78 | new file mode 100644 | 83 | new file mode 100644 |
79 | index XXXXXXX..XXXXXXX | 84 | index XXXXXXX..XXXXXXX |
80 | --- /dev/null | 85 | --- /dev/null |
81 | +++ b/target/riscv/crypto_helper.c | 86 | +++ b/target/riscv/tcg/tcg-cpu.c |
82 | @@ -XXX,XX +XXX,XX @@ | 87 | @@ -XXX,XX +XXX,XX @@ |
83 | +/* | 88 | +/* |
84 | + * RISC-V Crypto Emulation Helpers for QEMU. | 89 | + * riscv TCG cpu class initialization |
85 | + * | 90 | + * |
86 | + * Copyright (c) 2021 Ruibo Lu, luruibo2000@163.com | 91 | + * Copyright (c) 2016-2017 Sagar Karandikar, sagark@eecs.berkeley.edu |
87 | + * Copyright (c) 2021 Zewen Ye, lustrew@foxmail.com | 92 | + * Copyright (c) 2017-2018 SiFive, Inc. |
88 | + * | 93 | + * |
89 | + * This program is free software; you can redistribute it and/or modify it | 94 | + * This program is free software; you can redistribute it and/or modify it |
90 | + * under the terms and conditions of the GNU General Public License, | 95 | + * under the terms and conditions of the GNU General Public License, |
91 | + * version 2 or later, as published by the Free Software Foundation. | 96 | + * version 2 or later, as published by the Free Software Foundation. |
92 | + * | 97 | + * |
... | ... | ||
99 | + * this program. If not, see <http://www.gnu.org/licenses/>. | 104 | + * this program. If not, see <http://www.gnu.org/licenses/>. |
100 | + */ | 105 | + */ |
101 | + | 106 | + |
102 | +#include "qemu/osdep.h" | 107 | +#include "qemu/osdep.h" |
103 | +#include "cpu.h" | 108 | +#include "cpu.h" |
104 | +#include "exec/exec-all.h" | 109 | +#include "qemu/accel.h" |
105 | +#include "exec/helper-proto.h" | 110 | +#include "hw/core/accel-cpu.h" |
106 | +#include "crypto/aes.h" | ||
107 | +#include "crypto/sm4.h" | ||
108 | + | 111 | + |
109 | +#define AES_XTIME(a) \ | 112 | +static void tcg_cpu_init_ops(AccelCPUClass *accel_cpu, CPUClass *cc) |
110 | + ((a << 1) ^ ((a & 0x80) ? 0x1b : 0)) | ||
111 | + | ||
112 | +#define AES_GFMUL(a, b) (( \ | ||
113 | + (((b) & 0x1) ? (a) : 0) ^ \ | ||
114 | + (((b) & 0x2) ? AES_XTIME(a) : 0) ^ \ | ||
115 | + (((b) & 0x4) ? AES_XTIME(AES_XTIME(a)) : 0) ^ \ | ||
116 | + (((b) & 0x8) ? AES_XTIME(AES_XTIME(AES_XTIME(a))) : 0)) & 0xFF) | ||
117 | + | ||
118 | +static inline uint32_t aes_mixcolumn_byte(uint8_t x, bool fwd) | ||
119 | +{ | 113 | +{ |
120 | + uint32_t u; | 114 | + /* |
121 | + | 115 | + * All cpus use the same set of operations. |
122 | + if (fwd) { | 116 | + * riscv_tcg_ops is being imported from cpu.c for now. |
123 | + u = (AES_GFMUL(x, 3) << 24) | (x << 16) | (x << 8) | | 117 | + */ |
124 | + (AES_GFMUL(x, 2) << 0); | 118 | + cc->tcg_ops = &riscv_tcg_ops; |
125 | + } else { | ||
126 | + u = (AES_GFMUL(x, 0xb) << 24) | (AES_GFMUL(x, 0xd) << 16) | | ||
127 | + (AES_GFMUL(x, 0x9) << 8) | (AES_GFMUL(x, 0xe) << 0); | ||
128 | + } | ||
129 | + return u; | ||
130 | +} | 119 | +} |
131 | + | 120 | + |
132 | +#define sext32_xlen(x) (target_ulong)(int32_t)(x) | 121 | +static void tcg_cpu_class_init(CPUClass *cc) |
133 | + | ||
134 | +static inline target_ulong aes32_operation(target_ulong shamt, | ||
135 | + target_ulong rs1, target_ulong rs2, | ||
136 | + bool enc, bool mix) | ||
137 | +{ | 122 | +{ |
138 | + uint8_t si = rs2 >> shamt; | 123 | + cc->init_accel_cpu = tcg_cpu_init_ops; |
139 | + uint8_t so; | ||
140 | + uint32_t mixed; | ||
141 | + target_ulong res; | ||
142 | + | ||
143 | + if (enc) { | ||
144 | + so = AES_sbox[si]; | ||
145 | + if (mix) { | ||
146 | + mixed = aes_mixcolumn_byte(so, true); | ||
147 | + } else { | ||
148 | + mixed = so; | ||
149 | + } | ||
150 | + } else { | ||
151 | + so = AES_isbox[si]; | ||
152 | + if (mix) { | ||
153 | + mixed = aes_mixcolumn_byte(so, false); | ||
154 | + } else { | ||
155 | + mixed = so; | ||
156 | + } | ||
157 | + } | ||
158 | + mixed = rol32(mixed, shamt); | ||
159 | + res = rs1 ^ mixed; | ||
160 | + | ||
161 | + return sext32_xlen(res); | ||
162 | +} | 124 | +} |
163 | + | 125 | + |
164 | +target_ulong HELPER(aes32esmi)(target_ulong rs1, target_ulong rs2, | 126 | +static void tcg_cpu_accel_class_init(ObjectClass *oc, void *data) |
165 | + target_ulong shamt) | ||
166 | +{ | 127 | +{ |
167 | + return aes32_operation(shamt, rs1, rs2, true, true); | 128 | + AccelCPUClass *acc = ACCEL_CPU_CLASS(oc); |
129 | + | ||
130 | + acc->cpu_class_init = tcg_cpu_class_init; | ||
168 | +} | 131 | +} |
169 | + | 132 | + |
170 | +target_ulong HELPER(aes32esi)(target_ulong rs1, target_ulong rs2, | 133 | +static const TypeInfo tcg_cpu_accel_type_info = { |
171 | + target_ulong shamt) | 134 | + .name = ACCEL_CPU_NAME("tcg"), |
135 | + | ||
136 | + .parent = TYPE_ACCEL_CPU, | ||
137 | + .class_init = tcg_cpu_accel_class_init, | ||
138 | + .abstract = true, | ||
139 | +}; | ||
140 | + | ||
141 | +static void tcg_cpu_accel_register_types(void) | ||
172 | +{ | 142 | +{ |
173 | + return aes32_operation(shamt, rs1, rs2, true, false); | 143 | + type_register_static(&tcg_cpu_accel_type_info); |
174 | +} | 144 | +} |
175 | + | 145 | +type_init(tcg_cpu_accel_register_types); |
176 | +target_ulong HELPER(aes32dsmi)(target_ulong rs1, target_ulong rs2, | ||
177 | + target_ulong shamt) | ||
178 | +{ | ||
179 | + return aes32_operation(shamt, rs1, rs2, false, true); | ||
180 | +} | ||
181 | + | ||
182 | +target_ulong HELPER(aes32dsi)(target_ulong rs1, target_ulong rs2, | ||
183 | + target_ulong shamt) | ||
184 | +{ | ||
185 | + return aes32_operation(shamt, rs1, rs2, false, false); | ||
186 | +} | ||
187 | +#undef sext32_xlen | ||
188 | diff --git a/target/riscv/translate.c b/target/riscv/translate.c | ||
189 | index XXXXXXX..XXXXXXX 100644 | ||
190 | --- a/target/riscv/translate.c | ||
191 | +++ b/target/riscv/translate.c | ||
192 | @@ -XXX,XX +XXX,XX @@ static uint32_t opcode_at(DisasContextBase *dcbase, target_ulong pc) | ||
193 | #include "insn_trans/trans_rvv.c.inc" | ||
194 | #include "insn_trans/trans_rvb.c.inc" | ||
195 | #include "insn_trans/trans_rvzfh.c.inc" | ||
196 | +#include "insn_trans/trans_rvk.c.inc" | ||
197 | #include "insn_trans/trans_privileged.c.inc" | ||
198 | #include "insn_trans/trans_svinval.c.inc" | ||
199 | #include "insn_trans/trans_xventanacondops.c.inc" | ||
200 | diff --git a/target/riscv/insn_trans/trans_rvk.c.inc b/target/riscv/insn_trans/trans_rvk.c.inc | ||
201 | new file mode 100644 | ||
202 | index XXXXXXX..XXXXXXX | ||
203 | --- /dev/null | ||
204 | +++ b/target/riscv/insn_trans/trans_rvk.c.inc | ||
205 | @@ -XXX,XX +XXX,XX @@ | ||
206 | +/* | ||
207 | + * RISC-V translation routines for the Zk[nd,ne,nh,sed,sh] Standard Extension. | ||
208 | + * | ||
209 | + * Copyright (c) 2021 Ruibo Lu, luruibo2000@163.com | ||
210 | + * Copyright (c) 2021 Zewen Ye, lustrew@foxmail.com | ||
211 | + * | ||
212 | + * This program is free software; you can redistribute it and/or modify it | ||
213 | + * under the terms and conditions of the GNU General Public License, | ||
214 | + * version 2 or later, as published by the Free Software Foundation. | ||
215 | + * | ||
216 | + * This program is distributed in the hope it will be useful, but WITHOUT | ||
217 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
218 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
219 | + * more details. | ||
220 | + * | ||
221 | + * You should have received a copy of the GNU General Public License along with | ||
222 | + * this program. If not, see <http://www.gnu.org/licenses/>. | ||
223 | + */ | ||
224 | + | ||
225 | +#define REQUIRE_ZKND(ctx) do { \ | ||
226 | + if (!ctx->cfg_ptr->ext_zknd) { \ | ||
227 | + return false; \ | ||
228 | + } \ | ||
229 | +} while (0) | ||
230 | + | ||
231 | +#define REQUIRE_ZKNE(ctx) do { \ | ||
232 | + if (!ctx->cfg_ptr->ext_zkne) { \ | ||
233 | + return false; \ | ||
234 | + } \ | ||
235 | +} while (0) | ||
236 | + | ||
237 | +static bool gen_aes32_sm4(DisasContext *ctx, arg_k_aes *a, | ||
238 | + void (*func)(TCGv, TCGv, TCGv, TCGv)) | ||
239 | +{ | ||
240 | + TCGv shamt = tcg_constant_tl(a->shamt); | ||
241 | + TCGv dest = dest_gpr(ctx, a->rd); | ||
242 | + TCGv src1 = get_gpr(ctx, a->rs1, EXT_NONE); | ||
243 | + TCGv src2 = get_gpr(ctx, a->rs2, EXT_NONE); | ||
244 | + | ||
245 | + func(dest, src1, src2, shamt); | ||
246 | + gen_set_gpr(ctx, a->rd, dest); | ||
247 | + return true; | ||
248 | +} | ||
249 | + | ||
250 | +static bool trans_aes32esmi(DisasContext *ctx, arg_aes32esmi *a) | ||
251 | +{ | ||
252 | + REQUIRE_32BIT(ctx); | ||
253 | + REQUIRE_ZKNE(ctx); | ||
254 | + return gen_aes32_sm4(ctx, a, gen_helper_aes32esmi); | ||
255 | +} | ||
256 | + | ||
257 | +static bool trans_aes32esi(DisasContext *ctx, arg_aes32esi *a) | ||
258 | +{ | ||
259 | + REQUIRE_32BIT(ctx); | ||
260 | + REQUIRE_ZKNE(ctx); | ||
261 | + return gen_aes32_sm4(ctx, a, gen_helper_aes32esi); | ||
262 | +} | ||
263 | + | ||
264 | +static bool trans_aes32dsmi(DisasContext *ctx, arg_aes32dsmi *a) | ||
265 | +{ | ||
266 | + REQUIRE_32BIT(ctx); | ||
267 | + REQUIRE_ZKND(ctx); | ||
268 | + return gen_aes32_sm4(ctx, a, gen_helper_aes32dsmi); | ||
269 | +} | ||
270 | + | ||
271 | +static bool trans_aes32dsi(DisasContext *ctx, arg_aes32dsi *a) | ||
272 | +{ | ||
273 | + REQUIRE_32BIT(ctx); | ||
274 | + REQUIRE_ZKND(ctx); | ||
275 | + return gen_aes32_sm4(ctx, a, gen_helper_aes32dsi); | ||
276 | +} | ||
277 | diff --git a/target/riscv/meson.build b/target/riscv/meson.build | 146 | diff --git a/target/riscv/meson.build b/target/riscv/meson.build |
278 | index XXXXXXX..XXXXXXX 100644 | 147 | index XXXXXXX..XXXXXXX 100644 |
279 | --- a/target/riscv/meson.build | 148 | --- a/target/riscv/meson.build |
280 | +++ b/target/riscv/meson.build | 149 | +++ b/target/riscv/meson.build |
281 | @@ -XXX,XX +XXX,XX @@ riscv_ss.add(files( | 150 | @@ -XXX,XX +XXX,XX @@ riscv_system_ss.add(files( |
282 | 'vector_helper.c', | 151 | 'riscv-qmp-cmds.c', |
283 | 'bitmanip_helper.c', | ||
284 | 'translate.c', | ||
285 | - 'm128_helper.c' | ||
286 | + 'm128_helper.c', | ||
287 | + 'crypto_helper.c' | ||
288 | )) | 152 | )) |
289 | riscv_ss.add(when: 'CONFIG_KVM', if_true: files('kvm.c'), if_false: files('kvm-stub.c')) | 153 | |
290 | 154 | +subdir('tcg') | |
155 | + | ||
156 | target_arch += {'riscv': riscv_ss} | ||
157 | target_system_arch += {'riscv': riscv_system_ss} | ||
158 | diff --git a/target/riscv/tcg/meson.build b/target/riscv/tcg/meson.build | ||
159 | new file mode 100644 | ||
160 | index XXXXXXX..XXXXXXX | ||
161 | --- /dev/null | ||
162 | +++ b/target/riscv/tcg/meson.build | ||
163 | @@ -XXX,XX +XXX,XX @@ | ||
164 | +riscv_ss.add(when: 'CONFIG_TCG', if_true: files( | ||
165 | + 'tcg-cpu.c')) | ||
291 | -- | 166 | -- |
292 | 2.35.1 | 167 | 2.41.0 | diff view generated by jsdifflib |
1 | From: Weiwei Li <liweiwei@iscas.ac.cn> | 1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
---|---|---|---|
2 | 2 | ||
3 | - add sm3p0, sm3p1, sm4ed and sm4ks instructions | 3 | riscv_cpu_realize_tcg() was added to allow TCG cpus to have a different |
4 | 4 | realize() path during the common riscv_cpu_realize(), making it a good | |
5 | Co-authored-by: Ruibo Lu <luruibo2000@163.com> | 5 | choice to start moving TCG exclusive code to tcg-cpu.c. |
6 | Signed-off-by: Weiwei Li <liweiwei@iscas.ac.cn> | 6 | |
7 | Signed-off-by: Junqiang Wang <wangjunqiang@iscas.ac.cn> | 7 | Rename it to tcg_cpu_realizefn() and assign it as a implementation of |
8 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 8 | accel::cpu_realizefn(). tcg_cpu_realizefn() will then be called during |
9 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 9 | riscv_cpu_realize() via cpu_exec_realizefn(). We'll use a similar |
10 | Message-Id: <20220423023510.30794-12-liweiwei@iscas.ac.cn> | 10 | approach with KVM in the near future. |
11 | |||
12 | riscv_cpu_validate_set_extensions() is too big and with too many | ||
13 | dependencies to be moved in this same patch. We'll do that next. | ||
14 | |||
15 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
16 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> | ||
17 | Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com> | ||
18 | Message-ID: <20230925175709.35696-3-dbarboza@ventanamicro.com> | ||
19 | [ Changes by AF: | ||
20 | - Renames to fix build failures after rebase | ||
21 | ] | ||
11 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 22 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
12 | --- | 23 | --- |
13 | target/riscv/helper.h | 3 ++ | 24 | target/riscv/cpu.c | 128 ----------------------------------- |
14 | target/riscv/insn32.decode | 6 +++ | 25 | target/riscv/tcg/tcg-cpu.c | 133 +++++++++++++++++++++++++++++++++++++ |
15 | target/riscv/crypto_helper.c | 28 ++++++++++++ | 26 | 2 files changed, 133 insertions(+), 128 deletions(-) |
16 | target/riscv/insn_trans/trans_rvk.c.inc | 58 +++++++++++++++++++++++++ | 27 | |
17 | 4 files changed, 95 insertions(+) | 28 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c |
18 | |||
19 | diff --git a/target/riscv/helper.h b/target/riscv/helper.h | ||
20 | index XXXXXXX..XXXXXXX 100644 | 29 | index XXXXXXX..XXXXXXX 100644 |
21 | --- a/target/riscv/helper.h | 30 | --- a/target/riscv/cpu.c |
22 | +++ b/target/riscv/helper.h | 31 | +++ b/target/riscv/cpu.c |
23 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_2(aes64dsm, TCG_CALL_NO_RWG_SE, tl, tl, tl) | 32 | @@ -XXX,XX +XXX,XX @@ |
24 | DEF_HELPER_FLAGS_2(aes64ks2, TCG_CALL_NO_RWG_SE, tl, tl, tl) | 33 | #include "qemu/log.h" |
25 | DEF_HELPER_FLAGS_2(aes64ks1i, TCG_CALL_NO_RWG_SE, tl, tl, tl) | 34 | #include "cpu.h" |
26 | DEF_HELPER_FLAGS_1(aes64im, TCG_CALL_NO_RWG_SE, tl, tl) | 35 | #include "cpu_vendorid.h" |
27 | + | 36 | -#include "pmu.h" |
28 | +DEF_HELPER_FLAGS_3(sm4ed, TCG_CALL_NO_RWG_SE, tl, tl, tl, tl) | 37 | #include "internals.h" |
29 | +DEF_HELPER_FLAGS_3(sm4ks, TCG_CALL_NO_RWG_SE, tl, tl, tl, tl) | 38 | -#include "time_helper.h" |
30 | diff --git a/target/riscv/insn32.decode b/target/riscv/insn32.decode | 39 | #include "exec/exec-all.h" |
40 | #include "qapi/error.h" | ||
41 | #include "qapi/visitor.h" | ||
42 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_validate_v(CPURISCVState *env, RISCVCPUConfig *cfg, | ||
43 | } | ||
44 | } | ||
45 | |||
46 | -static void riscv_cpu_validate_priv_spec(RISCVCPU *cpu, Error **errp) | ||
47 | -{ | ||
48 | - CPURISCVState *env = &cpu->env; | ||
49 | - int priv_version = -1; | ||
50 | - | ||
51 | - if (cpu->cfg.priv_spec) { | ||
52 | - if (!g_strcmp0(cpu->cfg.priv_spec, "v1.12.0")) { | ||
53 | - priv_version = PRIV_VERSION_1_12_0; | ||
54 | - } else if (!g_strcmp0(cpu->cfg.priv_spec, "v1.11.0")) { | ||
55 | - priv_version = PRIV_VERSION_1_11_0; | ||
56 | - } else if (!g_strcmp0(cpu->cfg.priv_spec, "v1.10.0")) { | ||
57 | - priv_version = PRIV_VERSION_1_10_0; | ||
58 | - } else { | ||
59 | - error_setg(errp, | ||
60 | - "Unsupported privilege spec version '%s'", | ||
61 | - cpu->cfg.priv_spec); | ||
62 | - return; | ||
63 | - } | ||
64 | - | ||
65 | - env->priv_ver = priv_version; | ||
66 | - } | ||
67 | -} | ||
68 | - | ||
69 | static void riscv_cpu_disable_priv_spec_isa_exts(RISCVCPU *cpu) | ||
70 | { | ||
71 | CPURISCVState *env = &cpu->env; | ||
72 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_disable_priv_spec_isa_exts(RISCVCPU *cpu) | ||
73 | } | ||
74 | } | ||
75 | |||
76 | -static void riscv_cpu_validate_misa_mxl(RISCVCPU *cpu, Error **errp) | ||
77 | -{ | ||
78 | - RISCVCPUClass *mcc = RISCV_CPU_GET_CLASS(cpu); | ||
79 | - CPUClass *cc = CPU_CLASS(mcc); | ||
80 | - CPURISCVState *env = &cpu->env; | ||
81 | - | ||
82 | - /* Validate that MISA_MXL is set properly. */ | ||
83 | - switch (env->misa_mxl_max) { | ||
84 | -#ifdef TARGET_RISCV64 | ||
85 | - case MXL_RV64: | ||
86 | - case MXL_RV128: | ||
87 | - cc->gdb_core_xml_file = "riscv-64bit-cpu.xml"; | ||
88 | - break; | ||
89 | -#endif | ||
90 | - case MXL_RV32: | ||
91 | - cc->gdb_core_xml_file = "riscv-32bit-cpu.xml"; | ||
92 | - break; | ||
93 | - default: | ||
94 | - g_assert_not_reached(); | ||
95 | - } | ||
96 | - | ||
97 | - if (env->misa_mxl_max != env->misa_mxl) { | ||
98 | - error_setg(errp, "misa_mxl_max must be equal to misa_mxl"); | ||
99 | - return; | ||
100 | - } | ||
101 | -} | ||
102 | - | ||
103 | /* | ||
104 | * Check consistency between chosen extensions while setting | ||
105 | * cpu->cfg accordingly. | ||
106 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_finalize_features(RISCVCPU *cpu, Error **errp) | ||
107 | #endif | ||
108 | } | ||
109 | |||
110 | -static void riscv_cpu_validate_misa_priv(CPURISCVState *env, Error **errp) | ||
111 | -{ | ||
112 | - if (riscv_has_ext(env, RVH) && env->priv_ver < PRIV_VERSION_1_12_0) { | ||
113 | - error_setg(errp, "H extension requires priv spec 1.12.0"); | ||
114 | - return; | ||
115 | - } | ||
116 | -} | ||
117 | - | ||
118 | -static void riscv_cpu_realize_tcg(DeviceState *dev, Error **errp) | ||
119 | -{ | ||
120 | - RISCVCPU *cpu = RISCV_CPU(dev); | ||
121 | - CPURISCVState *env = &cpu->env; | ||
122 | - Error *local_err = NULL; | ||
123 | - | ||
124 | - if (object_dynamic_cast(OBJECT(dev), TYPE_RISCV_CPU_HOST)) { | ||
125 | - error_setg(errp, "'host' CPU is not compatible with TCG acceleration"); | ||
126 | - return; | ||
127 | - } | ||
128 | - | ||
129 | - riscv_cpu_validate_misa_mxl(cpu, &local_err); | ||
130 | - if (local_err != NULL) { | ||
131 | - error_propagate(errp, local_err); | ||
132 | - return; | ||
133 | - } | ||
134 | - | ||
135 | - riscv_cpu_validate_priv_spec(cpu, &local_err); | ||
136 | - if (local_err != NULL) { | ||
137 | - error_propagate(errp, local_err); | ||
138 | - return; | ||
139 | - } | ||
140 | - | ||
141 | - riscv_cpu_validate_misa_priv(env, &local_err); | ||
142 | - if (local_err != NULL) { | ||
143 | - error_propagate(errp, local_err); | ||
144 | - return; | ||
145 | - } | ||
146 | - | ||
147 | - if (cpu->cfg.epmp && !cpu->cfg.pmp) { | ||
148 | - /* | ||
149 | - * Enhanced PMP should only be available | ||
150 | - * on harts with PMP support | ||
151 | - */ | ||
152 | - error_setg(errp, "Invalid configuration: EPMP requires PMP support"); | ||
153 | - return; | ||
154 | - } | ||
155 | - | ||
156 | - riscv_cpu_validate_set_extensions(cpu, &local_err); | ||
157 | - if (local_err != NULL) { | ||
158 | - error_propagate(errp, local_err); | ||
159 | - return; | ||
160 | - } | ||
161 | - | ||
162 | -#ifndef CONFIG_USER_ONLY | ||
163 | - CPU(dev)->tcg_cflags |= CF_PCREL; | ||
164 | - | ||
165 | - if (cpu->cfg.ext_sstc) { | ||
166 | - riscv_timer_init(cpu); | ||
167 | - } | ||
168 | - | ||
169 | - if (cpu->cfg.pmu_num) { | ||
170 | - if (!riscv_pmu_init(cpu, cpu->cfg.pmu_num) && cpu->cfg.ext_sscofpmf) { | ||
171 | - cpu->pmu_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, | ||
172 | - riscv_pmu_timer_cb, cpu); | ||
173 | - } | ||
174 | - } | ||
175 | -#endif | ||
176 | -} | ||
177 | - | ||
178 | static void riscv_cpu_realize(DeviceState *dev, Error **errp) | ||
179 | { | ||
180 | CPUState *cs = CPU(dev); | ||
181 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) | ||
182 | return; | ||
183 | } | ||
184 | |||
185 | - if (tcg_enabled()) { | ||
186 | - riscv_cpu_realize_tcg(dev, &local_err); | ||
187 | - if (local_err != NULL) { | ||
188 | - error_propagate(errp, local_err); | ||
189 | - return; | ||
190 | - } | ||
191 | - } | ||
192 | - | ||
193 | riscv_cpu_finalize_features(cpu, &local_err); | ||
194 | if (local_err != NULL) { | ||
195 | error_propagate(errp, local_err); | ||
196 | diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c | ||
31 | index XXXXXXX..XXXXXXX 100644 | 197 | index XXXXXXX..XXXXXXX 100644 |
32 | --- a/target/riscv/insn32.decode | 198 | --- a/target/riscv/tcg/tcg-cpu.c |
33 | +++ b/target/riscv/insn32.decode | 199 | +++ b/target/riscv/tcg/tcg-cpu.c |
34 | @@ -XXX,XX +XXX,XX @@ sha512sig0 00 01000 00110 ..... 001 ..... 0010011 @r2 | 200 | @@ -XXX,XX +XXX,XX @@ |
35 | sha512sig1 00 01000 00111 ..... 001 ..... 0010011 @r2 | 201 | */ |
36 | sha512sum0 00 01000 00100 ..... 001 ..... 0010011 @r2 | 202 | |
37 | sha512sum1 00 01000 00101 ..... 001 ..... 0010011 @r2 | 203 | #include "qemu/osdep.h" |
38 | +# *** RV32 Zksh Standard Extension *** | 204 | +#include "exec/exec-all.h" |
39 | +sm3p0 00 01000 01000 ..... 001 ..... 0010011 @r2 | 205 | #include "cpu.h" |
40 | +sm3p1 00 01000 01001 ..... 001 ..... 0010011 @r2 | 206 | +#include "pmu.h" |
41 | +# *** RV32 Zksed Standard Extension *** | 207 | +#include "time_helper.h" |
42 | +sm4ed .. 11000 ..... ..... 000 ..... 0110011 @k_aes | 208 | +#include "qapi/error.h" |
43 | +sm4ks .. 11010 ..... ..... 000 ..... 0110011 @k_aes | 209 | #include "qemu/accel.h" |
44 | diff --git a/target/riscv/crypto_helper.c b/target/riscv/crypto_helper.c | 210 | #include "hw/core/accel-cpu.h" |
45 | index XXXXXXX..XXXXXXX 100644 | 211 | |
46 | --- a/target/riscv/crypto_helper.c | 212 | + |
47 | +++ b/target/riscv/crypto_helper.c | 213 | +static void riscv_cpu_validate_misa_priv(CPURISCVState *env, Error **errp) |
48 | @@ -XXX,XX +XXX,XX @@ target_ulong HELPER(aes64im)(target_ulong rs1) | ||
49 | |||
50 | return result; | ||
51 | } | ||
52 | + | ||
53 | +target_ulong HELPER(sm4ed)(target_ulong rs1, target_ulong rs2, | ||
54 | + target_ulong shamt) | ||
55 | +{ | 214 | +{ |
56 | + uint32_t sb_in = (uint8_t)(rs2 >> shamt); | 215 | + if (riscv_has_ext(env, RVH) && env->priv_ver < PRIV_VERSION_1_12_0) { |
57 | + uint32_t sb_out = (uint32_t)sm4_sbox[sb_in]; | 216 | + error_setg(errp, "H extension requires priv spec 1.12.0"); |
58 | + | 217 | + return; |
59 | + uint32_t x = sb_out ^ (sb_out << 8) ^ (sb_out << 2) ^ (sb_out << 18) ^ | 218 | + } |
60 | + ((sb_out & 0x3f) << 26) ^ ((sb_out & 0xC0) << 10); | ||
61 | + | ||
62 | + uint32_t rotl = rol32(x, shamt); | ||
63 | + | ||
64 | + return sext32_xlen(rotl ^ (uint32_t)rs1); | ||
65 | +} | 219 | +} |
66 | + | 220 | + |
67 | +target_ulong HELPER(sm4ks)(target_ulong rs1, target_ulong rs2, | 221 | +static void riscv_cpu_validate_misa_mxl(RISCVCPU *cpu, Error **errp) |
68 | + target_ulong shamt) | ||
69 | +{ | 222 | +{ |
70 | + uint32_t sb_in = (uint8_t)(rs2 >> shamt); | 223 | + RISCVCPUClass *mcc = RISCV_CPU_GET_CLASS(cpu); |
71 | + uint32_t sb_out = sm4_sbox[sb_in]; | 224 | + CPUClass *cc = CPU_CLASS(mcc); |
72 | + | 225 | + CPURISCVState *env = &cpu->env; |
73 | + uint32_t x = sb_out ^ ((sb_out & 0x07) << 29) ^ ((sb_out & 0xFE) << 7) ^ | 226 | + |
74 | + ((sb_out & 0x01) << 23) ^ ((sb_out & 0xF8) << 13); | 227 | + /* Validate that MISA_MXL is set properly. */ |
75 | + | 228 | + switch (env->misa_mxl_max) { |
76 | + uint32_t rotl = rol32(x, shamt); | 229 | +#ifdef TARGET_RISCV64 |
77 | + | 230 | + case MXL_RV64: |
78 | + return sext32_xlen(rotl ^ (uint32_t)rs1); | 231 | + case MXL_RV128: |
232 | + cc->gdb_core_xml_file = "riscv-64bit-cpu.xml"; | ||
233 | + break; | ||
234 | +#endif | ||
235 | + case MXL_RV32: | ||
236 | + cc->gdb_core_xml_file = "riscv-32bit-cpu.xml"; | ||
237 | + break; | ||
238 | + default: | ||
239 | + g_assert_not_reached(); | ||
240 | + } | ||
241 | + | ||
242 | + if (env->misa_mxl_max != env->misa_mxl) { | ||
243 | + error_setg(errp, "misa_mxl_max must be equal to misa_mxl"); | ||
244 | + return; | ||
245 | + } | ||
79 | +} | 246 | +} |
80 | #undef sext32_xlen | 247 | + |
81 | diff --git a/target/riscv/insn_trans/trans_rvk.c.inc b/target/riscv/insn_trans/trans_rvk.c.inc | 248 | +static void riscv_cpu_validate_priv_spec(RISCVCPU *cpu, Error **errp) |
82 | index XXXXXXX..XXXXXXX 100644 | ||
83 | --- a/target/riscv/insn_trans/trans_rvk.c.inc | ||
84 | +++ b/target/riscv/insn_trans/trans_rvk.c.inc | ||
85 | @@ -XXX,XX +XXX,XX @@ | ||
86 | } \ | ||
87 | } while (0) | ||
88 | |||
89 | +#define REQUIRE_ZKSED(ctx) do { \ | ||
90 | + if (!ctx->cfg_ptr->ext_zksed) { \ | ||
91 | + return false; \ | ||
92 | + } \ | ||
93 | +} while (0) | ||
94 | + | ||
95 | +#define REQUIRE_ZKSH(ctx) do { \ | ||
96 | + if (!ctx->cfg_ptr->ext_zksh) { \ | ||
97 | + return false; \ | ||
98 | + } \ | ||
99 | +} while (0) | ||
100 | + | ||
101 | static bool gen_aes32_sm4(DisasContext *ctx, arg_k_aes *a, | ||
102 | void (*func)(TCGv, TCGv, TCGv, TCGv)) | ||
103 | { | ||
104 | @@ -XXX,XX +XXX,XX @@ static bool trans_sha512sum1(DisasContext *ctx, arg_sha512sum1 *a) | ||
105 | REQUIRE_ZKNH(ctx); | ||
106 | return gen_sha512_rv64(ctx, a, EXT_NONE, tcg_gen_rotri_i64, 14, 18, 41); | ||
107 | } | ||
108 | + | ||
109 | +/* SM3 */ | ||
110 | +static bool gen_sm3(DisasContext *ctx, arg_r2 *a, int32_t b, int32_t c) | ||
111 | +{ | 249 | +{ |
112 | + TCGv dest = dest_gpr(ctx, a->rd); | 250 | + CPURISCVState *env = &cpu->env; |
113 | + TCGv src1 = get_gpr(ctx, a->rs1, EXT_NONE); | 251 | + int priv_version = -1; |
114 | + TCGv_i32 t0 = tcg_temp_new_i32(); | 252 | + |
115 | + TCGv_i32 t1 = tcg_temp_new_i32(); | 253 | + if (cpu->cfg.priv_spec) { |
116 | + | 254 | + if (!g_strcmp0(cpu->cfg.priv_spec, "v1.12.0")) { |
117 | + tcg_gen_trunc_tl_i32(t0, src1); | 255 | + priv_version = PRIV_VERSION_1_12_0; |
118 | + tcg_gen_rotli_i32(t1, t0, b); | 256 | + } else if (!g_strcmp0(cpu->cfg.priv_spec, "v1.11.0")) { |
119 | + tcg_gen_xor_i32(t1, t0, t1); | 257 | + priv_version = PRIV_VERSION_1_11_0; |
120 | + tcg_gen_rotli_i32(t0, t0, c); | 258 | + } else if (!g_strcmp0(cpu->cfg.priv_spec, "v1.10.0")) { |
121 | + tcg_gen_xor_i32(t1, t1, t0); | 259 | + priv_version = PRIV_VERSION_1_10_0; |
122 | + tcg_gen_ext_i32_tl(dest, t1); | 260 | + } else { |
123 | + gen_set_gpr(ctx, a->rd, dest); | 261 | + error_setg(errp, |
124 | + | 262 | + "Unsupported privilege spec version '%s'", |
125 | + tcg_temp_free_i32(t0); | 263 | + cpu->cfg.priv_spec); |
126 | + tcg_temp_free_i32(t1); | 264 | + return; |
265 | + } | ||
266 | + | ||
267 | + env->priv_ver = priv_version; | ||
268 | + } | ||
269 | +} | ||
270 | + | ||
271 | +/* | ||
272 | + * We'll get here via the following path: | ||
273 | + * | ||
274 | + * riscv_cpu_realize() | ||
275 | + * -> cpu_exec_realizefn() | ||
276 | + * -> tcg_cpu_realize() (via accel_cpu_common_realize()) | ||
277 | + */ | ||
278 | +static bool tcg_cpu_realize(CPUState *cs, Error **errp) | ||
279 | +{ | ||
280 | + RISCVCPU *cpu = RISCV_CPU(cs); | ||
281 | + CPURISCVState *env = &cpu->env; | ||
282 | + Error *local_err = NULL; | ||
283 | + | ||
284 | + if (object_dynamic_cast(OBJECT(cpu), TYPE_RISCV_CPU_HOST)) { | ||
285 | + error_setg(errp, "'host' CPU is not compatible with TCG acceleration"); | ||
286 | + return false; | ||
287 | + } | ||
288 | + | ||
289 | + riscv_cpu_validate_misa_mxl(cpu, &local_err); | ||
290 | + if (local_err != NULL) { | ||
291 | + error_propagate(errp, local_err); | ||
292 | + return false; | ||
293 | + } | ||
294 | + | ||
295 | + riscv_cpu_validate_priv_spec(cpu, &local_err); | ||
296 | + if (local_err != NULL) { | ||
297 | + error_propagate(errp, local_err); | ||
298 | + return false; | ||
299 | + } | ||
300 | + | ||
301 | + riscv_cpu_validate_misa_priv(env, &local_err); | ||
302 | + if (local_err != NULL) { | ||
303 | + error_propagate(errp, local_err); | ||
304 | + return false; | ||
305 | + } | ||
306 | + | ||
307 | + if (cpu->cfg.epmp && !cpu->cfg.pmp) { | ||
308 | + /* | ||
309 | + * Enhanced PMP should only be available | ||
310 | + * on harts with PMP support | ||
311 | + */ | ||
312 | + error_setg(errp, "Invalid configuration: EPMP requires PMP support"); | ||
313 | + return false; | ||
314 | + } | ||
315 | + | ||
316 | + riscv_cpu_validate_set_extensions(cpu, &local_err); | ||
317 | + if (local_err != NULL) { | ||
318 | + error_propagate(errp, local_err); | ||
319 | + return false; | ||
320 | + } | ||
321 | + | ||
322 | +#ifndef CONFIG_USER_ONLY | ||
323 | + CPU(cs)->tcg_cflags |= CF_PCREL; | ||
324 | + | ||
325 | + if (cpu->cfg.ext_sstc) { | ||
326 | + riscv_timer_init(cpu); | ||
327 | + } | ||
328 | + | ||
329 | + if (cpu->cfg.pmu_num) { | ||
330 | + if (!riscv_pmu_init(cpu, cpu->cfg.pmu_num) && cpu->cfg.ext_sscofpmf) { | ||
331 | + cpu->pmu_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, | ||
332 | + riscv_pmu_timer_cb, cpu); | ||
333 | + } | ||
334 | + } | ||
335 | +#endif | ||
336 | + | ||
127 | + return true; | 337 | + return true; |
128 | +} | 338 | +} |
129 | + | 339 | + |
130 | +static bool trans_sm3p0(DisasContext *ctx, arg_sm3p0 *a) | 340 | static void tcg_cpu_init_ops(AccelCPUClass *accel_cpu, CPUClass *cc) |
131 | +{ | 341 | { |
132 | + REQUIRE_ZKSH(ctx); | 342 | /* |
133 | + return gen_sm3(ctx, a, 9, 17); | 343 | @@ -XXX,XX +XXX,XX @@ static void tcg_cpu_accel_class_init(ObjectClass *oc, void *data) |
134 | +} | 344 | AccelCPUClass *acc = ACCEL_CPU_CLASS(oc); |
135 | + | 345 | |
136 | +static bool trans_sm3p1(DisasContext *ctx, arg_sm3p1 *a) | 346 | acc->cpu_class_init = tcg_cpu_class_init; |
137 | +{ | 347 | + acc->cpu_target_realize = tcg_cpu_realize; |
138 | + REQUIRE_ZKSH(ctx); | 348 | } |
139 | + return gen_sm3(ctx, a, 15, 23); | 349 | |
140 | +} | 350 | static const TypeInfo tcg_cpu_accel_type_info = { |
141 | + | ||
142 | +/* SM4 */ | ||
143 | +static bool trans_sm4ed(DisasContext *ctx, arg_sm4ed *a) | ||
144 | +{ | ||
145 | + REQUIRE_ZKSED(ctx); | ||
146 | + return gen_aes32_sm4(ctx, a, gen_helper_sm4ed); | ||
147 | +} | ||
148 | + | ||
149 | +static bool trans_sm4ks(DisasContext *ctx, arg_sm4ks *a) | ||
150 | +{ | ||
151 | + REQUIRE_ZKSED(ctx); | ||
152 | + return gen_aes32_sm4(ctx, a, gen_helper_sm4ks); | ||
153 | +} | ||
154 | -- | 351 | -- |
155 | 2.35.1 | 352 | 2.41.0 | diff view generated by jsdifflib |
1 | From: Weiwei Li <liweiwei@iscas.ac.cn> | 1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
---|---|---|---|
2 | 2 | ||
3 | - share it between target/arm and target/riscv | 3 | This function is the core of the RISC-V validations for TCG CPUs, and it |
4 | has a lot going on. | ||
4 | 5 | ||
5 | Signed-off-by: Weiwei Li <liweiwei@iscas.ac.cn> | 6 | Functions in cpu.c were made public to allow them to be used by the KVM |
6 | Signed-off-by: Junqiang Wang <wangjunqiang@iscas.ac.cn> | 7 | accelerator class later on. 'cpu_cfg_ext_get_min_version()' is notably |
7 | Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> | 8 | hard to move it to another file due to its dependency with isa_edata_arr[] |
9 | array, thus make it public and use it as is for now. | ||
10 | |||
11 | riscv_cpu_validate_set_extensions() is kept public because it's used by | ||
12 | csr.c in write_misa(). | ||
13 | |||
14 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
15 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> | ||
16 | Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com> | ||
8 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 17 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
9 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 18 | Message-ID: <20230925175709.35696-4-dbarboza@ventanamicro.com> |
10 | Message-Id: <20220423023510.30794-6-liweiwei@iscas.ac.cn> | ||
11 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 19 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
12 | --- | 20 | --- |
13 | include/crypto/sm4.h | 6 +++++ | 21 | target/riscv/cpu.h | 8 +- |
14 | crypto/sm4.c | 49 ++++++++++++++++++++++++++++++++++++++ | 22 | target/riscv/tcg/tcg-cpu.h | 27 +++ |
15 | target/arm/crypto_helper.c | 36 +--------------------------- | 23 | target/riscv/cpu.c | 361 +------------------------------------ |
16 | crypto/meson.build | 1 + | 24 | target/riscv/csr.c | 1 + |
17 | 4 files changed, 57 insertions(+), 35 deletions(-) | 25 | target/riscv/tcg/tcg-cpu.c | 357 ++++++++++++++++++++++++++++++++++++ |
18 | create mode 100644 include/crypto/sm4.h | 26 | 5 files changed, 397 insertions(+), 357 deletions(-) |
19 | create mode 100644 crypto/sm4.c | 27 | create mode 100644 target/riscv/tcg/tcg-cpu.h |
20 | 28 | ||
21 | diff --git a/include/crypto/sm4.h b/include/crypto/sm4.h | 29 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h |
30 | index XXXXXXX..XXXXXXX 100644 | ||
31 | --- a/target/riscv/cpu.h | ||
32 | +++ b/target/riscv/cpu.h | ||
33 | @@ -XXX,XX +XXX,XX @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size, | ||
34 | bool probe, uintptr_t retaddr); | ||
35 | char *riscv_isa_string(RISCVCPU *cpu); | ||
36 | void riscv_cpu_list(void); | ||
37 | -void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp); | ||
38 | |||
39 | #define cpu_list riscv_cpu_list | ||
40 | #define cpu_mmu_index riscv_cpu_mmu_index | ||
41 | @@ -XXX,XX +XXX,XX @@ enum riscv_pmu_event_idx { | ||
42 | #include "hw/core/tcg-cpu-ops.h" | ||
43 | extern const struct TCGCPUOps riscv_tcg_ops; | ||
44 | |||
45 | +/* used by tcg/tcg-cpu.c*/ | ||
46 | +void isa_ext_update_enabled(RISCVCPU *cpu, uint32_t ext_offset, bool en); | ||
47 | +bool cpu_cfg_ext_is_user_set(uint32_t ext_offset); | ||
48 | +bool isa_ext_is_enabled(RISCVCPU *cpu, uint32_t ext_offset); | ||
49 | +int cpu_cfg_ext_get_min_version(uint32_t ext_offset); | ||
50 | +void riscv_cpu_disable_priv_spec_isa_exts(RISCVCPU *cpu); | ||
51 | + | ||
52 | /* CSR function table */ | ||
53 | extern riscv_csr_operations csr_ops[CSR_TABLE_SIZE]; | ||
54 | |||
55 | diff --git a/target/riscv/tcg/tcg-cpu.h b/target/riscv/tcg/tcg-cpu.h | ||
22 | new file mode 100644 | 56 | new file mode 100644 |
23 | index XXXXXXX..XXXXXXX | 57 | index XXXXXXX..XXXXXXX |
24 | --- /dev/null | 58 | --- /dev/null |
25 | +++ b/include/crypto/sm4.h | 59 | +++ b/target/riscv/tcg/tcg-cpu.h |
26 | @@ -XXX,XX +XXX,XX @@ | ||
27 | +#ifndef QEMU_SM4_H | ||
28 | +#define QEMU_SM4_H | ||
29 | + | ||
30 | +extern const uint8_t sm4_sbox[256]; | ||
31 | + | ||
32 | +#endif | ||
33 | diff --git a/crypto/sm4.c b/crypto/sm4.c | ||
34 | new file mode 100644 | ||
35 | index XXXXXXX..XXXXXXX | ||
36 | --- /dev/null | ||
37 | +++ b/crypto/sm4.c | ||
38 | @@ -XXX,XX +XXX,XX @@ | 60 | @@ -XXX,XX +XXX,XX @@ |
39 | +/* | 61 | +/* |
40 | + * QEMU crypto sm4 support | 62 | + * riscv TCG cpu class initialization |
41 | + * | 63 | + * |
42 | + * Copyright (C) 2013 - 2018 Linaro Ltd <ard.biesheuvel@linaro.org> | 64 | + * Copyright (c) 2023 Ventana Micro Systems Inc. |
43 | + * | 65 | + * |
44 | + * This library is free software; you can redistribute it and/or | 66 | + * This library is free software; you can redistribute it and/or |
45 | + * modify it under the terms of the GNU Lesser General Public | 67 | + * modify it under the terms of the GNU Lesser General Public |
46 | + * License as published by the Free Software Foundation; either | 68 | + * License as published by the Free Software Foundation; either |
47 | + * version 2.1 of the License, or (at your option) any later version. | 69 | + * version 2 of the License, or (at your option) any later version. |
70 | + * | ||
71 | + * This library is distributed in the hope that it will be useful, | ||
72 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
73 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
74 | + * Lesser General Public License for more details. | ||
75 | + * | ||
76 | + * You should have received a copy of the GNU Lesser General Public | ||
77 | + * License along with this library; if not, see <http://www.gnu.org/licenses/>. | ||
48 | + */ | 78 | + */ |
49 | + | 79 | + |
50 | +#include "qemu/osdep.h" | 80 | +#ifndef RISCV_TCG_CPU_H |
51 | +#include "crypto/sm4.h" | 81 | +#define RISCV_TCG_CPU_H |
52 | + | 82 | + |
53 | +uint8_t const sm4_sbox[] = { | 83 | +#include "cpu.h" |
54 | + 0xd6, 0x90, 0xe9, 0xfe, 0xcc, 0xe1, 0x3d, 0xb7, | 84 | + |
55 | + 0x16, 0xb6, 0x14, 0xc2, 0x28, 0xfb, 0x2c, 0x05, | 85 | +void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp); |
56 | + 0x2b, 0x67, 0x9a, 0x76, 0x2a, 0xbe, 0x04, 0xc3, | 86 | + |
57 | + 0xaa, 0x44, 0x13, 0x26, 0x49, 0x86, 0x06, 0x99, | 87 | +#endif |
58 | + 0x9c, 0x42, 0x50, 0xf4, 0x91, 0xef, 0x98, 0x7a, | 88 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c |
59 | + 0x33, 0x54, 0x0b, 0x43, 0xed, 0xcf, 0xac, 0x62, | ||
60 | + 0xe4, 0xb3, 0x1c, 0xa9, 0xc9, 0x08, 0xe8, 0x95, | ||
61 | + 0x80, 0xdf, 0x94, 0xfa, 0x75, 0x8f, 0x3f, 0xa6, | ||
62 | + 0x47, 0x07, 0xa7, 0xfc, 0xf3, 0x73, 0x17, 0xba, | ||
63 | + 0x83, 0x59, 0x3c, 0x19, 0xe6, 0x85, 0x4f, 0xa8, | ||
64 | + 0x68, 0x6b, 0x81, 0xb2, 0x71, 0x64, 0xda, 0x8b, | ||
65 | + 0xf8, 0xeb, 0x0f, 0x4b, 0x70, 0x56, 0x9d, 0x35, | ||
66 | + 0x1e, 0x24, 0x0e, 0x5e, 0x63, 0x58, 0xd1, 0xa2, | ||
67 | + 0x25, 0x22, 0x7c, 0x3b, 0x01, 0x21, 0x78, 0x87, | ||
68 | + 0xd4, 0x00, 0x46, 0x57, 0x9f, 0xd3, 0x27, 0x52, | ||
69 | + 0x4c, 0x36, 0x02, 0xe7, 0xa0, 0xc4, 0xc8, 0x9e, | ||
70 | + 0xea, 0xbf, 0x8a, 0xd2, 0x40, 0xc7, 0x38, 0xb5, | ||
71 | + 0xa3, 0xf7, 0xf2, 0xce, 0xf9, 0x61, 0x15, 0xa1, | ||
72 | + 0xe0, 0xae, 0x5d, 0xa4, 0x9b, 0x34, 0x1a, 0x55, | ||
73 | + 0xad, 0x93, 0x32, 0x30, 0xf5, 0x8c, 0xb1, 0xe3, | ||
74 | + 0x1d, 0xf6, 0xe2, 0x2e, 0x82, 0x66, 0xca, 0x60, | ||
75 | + 0xc0, 0x29, 0x23, 0xab, 0x0d, 0x53, 0x4e, 0x6f, | ||
76 | + 0xd5, 0xdb, 0x37, 0x45, 0xde, 0xfd, 0x8e, 0x2f, | ||
77 | + 0x03, 0xff, 0x6a, 0x72, 0x6d, 0x6c, 0x5b, 0x51, | ||
78 | + 0x8d, 0x1b, 0xaf, 0x92, 0xbb, 0xdd, 0xbc, 0x7f, | ||
79 | + 0x11, 0xd9, 0x5c, 0x41, 0x1f, 0x10, 0x5a, 0xd8, | ||
80 | + 0x0a, 0xc1, 0x31, 0x88, 0xa5, 0xcd, 0x7b, 0xbd, | ||
81 | + 0x2d, 0x74, 0xd0, 0x12, 0xb8, 0xe5, 0xb4, 0xb0, | ||
82 | + 0x89, 0x69, 0x97, 0x4a, 0x0c, 0x96, 0x77, 0x7e, | ||
83 | + 0x65, 0xb9, 0xf1, 0x09, 0xc5, 0x6e, 0xc6, 0x84, | ||
84 | + 0x18, 0xf0, 0x7d, 0xec, 0x3a, 0xdc, 0x4d, 0x20, | ||
85 | + 0x79, 0xee, 0x5f, 0x3e, 0xd7, 0xcb, 0x39, 0x48, | ||
86 | +}; | ||
87 | + | ||
88 | diff --git a/target/arm/crypto_helper.c b/target/arm/crypto_helper.c | ||
89 | index XXXXXXX..XXXXXXX 100644 | 89 | index XXXXXXX..XXXXXXX 100644 |
90 | --- a/target/arm/crypto_helper.c | 90 | --- a/target/riscv/cpu.c |
91 | +++ b/target/arm/crypto_helper.c | 91 | +++ b/target/riscv/cpu.c |
92 | @@ -XXX,XX +XXX,XX @@ static const struct isa_ext_data isa_edata_arr[] = { | ||
93 | /* Hash that stores user set extensions */ | ||
94 | static GHashTable *multi_ext_user_opts; | ||
95 | |||
96 | -static bool isa_ext_is_enabled(RISCVCPU *cpu, uint32_t ext_offset) | ||
97 | +bool isa_ext_is_enabled(RISCVCPU *cpu, uint32_t ext_offset) | ||
98 | { | ||
99 | bool *ext_enabled = (void *)&cpu->cfg + ext_offset; | ||
100 | |||
101 | return *ext_enabled; | ||
102 | } | ||
103 | |||
104 | -static void isa_ext_update_enabled(RISCVCPU *cpu, uint32_t ext_offset, | ||
105 | - bool en) | ||
106 | +void isa_ext_update_enabled(RISCVCPU *cpu, uint32_t ext_offset, bool en) | ||
107 | { | ||
108 | bool *ext_enabled = (void *)&cpu->cfg + ext_offset; | ||
109 | |||
110 | *ext_enabled = en; | ||
111 | } | ||
112 | |||
113 | -static int cpu_cfg_ext_get_min_version(uint32_t ext_offset) | ||
114 | +int cpu_cfg_ext_get_min_version(uint32_t ext_offset) | ||
115 | { | ||
116 | int i; | ||
117 | |||
118 | @@ -XXX,XX +XXX,XX @@ static int cpu_cfg_ext_get_min_version(uint32_t ext_offset) | ||
119 | g_assert_not_reached(); | ||
120 | } | ||
121 | |||
122 | -static bool cpu_cfg_ext_is_user_set(uint32_t ext_offset) | ||
123 | +bool cpu_cfg_ext_is_user_set(uint32_t ext_offset) | ||
124 | { | ||
125 | return g_hash_table_contains(multi_ext_user_opts, | ||
126 | GUINT_TO_POINTER(ext_offset)); | ||
127 | } | ||
128 | |||
129 | -static void cpu_cfg_ext_auto_update(RISCVCPU *cpu, uint32_t ext_offset, | ||
130 | - bool value) | ||
131 | -{ | ||
132 | - CPURISCVState *env = &cpu->env; | ||
133 | - bool prev_val = isa_ext_is_enabled(cpu, ext_offset); | ||
134 | - int min_version; | ||
135 | - | ||
136 | - if (prev_val == value) { | ||
137 | - return; | ||
138 | - } | ||
139 | - | ||
140 | - if (cpu_cfg_ext_is_user_set(ext_offset)) { | ||
141 | - return; | ||
142 | - } | ||
143 | - | ||
144 | - if (value && env->priv_ver != PRIV_VERSION_LATEST) { | ||
145 | - /* Do not enable it if priv_ver is older than min_version */ | ||
146 | - min_version = cpu_cfg_ext_get_min_version(ext_offset); | ||
147 | - if (env->priv_ver < min_version) { | ||
148 | - return; | ||
149 | - } | ||
150 | - } | ||
151 | - | ||
152 | - isa_ext_update_enabled(cpu, ext_offset, value); | ||
153 | -} | ||
154 | - | ||
155 | const char * const riscv_int_regnames[] = { | ||
156 | "x0/zero", "x1/ra", "x2/sp", "x3/gp", "x4/tp", "x5/t0", "x6/t1", | ||
157 | "x7/t2", "x8/s0", "x9/s1", "x10/a0", "x11/a1", "x12/a2", "x13/a3", | ||
158 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_disas_set_info(CPUState *s, disassemble_info *info) | ||
159 | } | ||
160 | } | ||
161 | |||
162 | -static void riscv_cpu_validate_v(CPURISCVState *env, RISCVCPUConfig *cfg, | ||
163 | - Error **errp) | ||
164 | -{ | ||
165 | - if (!is_power_of_2(cfg->vlen)) { | ||
166 | - error_setg(errp, "Vector extension VLEN must be power of 2"); | ||
167 | - return; | ||
168 | - } | ||
169 | - if (cfg->vlen > RV_VLEN_MAX || cfg->vlen < 128) { | ||
170 | - error_setg(errp, | ||
171 | - "Vector extension implementation only supports VLEN " | ||
172 | - "in the range [128, %d]", RV_VLEN_MAX); | ||
173 | - return; | ||
174 | - } | ||
175 | - if (!is_power_of_2(cfg->elen)) { | ||
176 | - error_setg(errp, "Vector extension ELEN must be power of 2"); | ||
177 | - return; | ||
178 | - } | ||
179 | - if (cfg->elen > 64 || cfg->elen < 8) { | ||
180 | - error_setg(errp, | ||
181 | - "Vector extension implementation only supports ELEN " | ||
182 | - "in the range [8, 64]"); | ||
183 | - return; | ||
184 | - } | ||
185 | - if (cfg->vext_spec) { | ||
186 | - if (!g_strcmp0(cfg->vext_spec, "v1.0")) { | ||
187 | - env->vext_ver = VEXT_VERSION_1_00_0; | ||
188 | - } else { | ||
189 | - error_setg(errp, "Unsupported vector spec version '%s'", | ||
190 | - cfg->vext_spec); | ||
191 | - return; | ||
192 | - } | ||
193 | - } else if (env->vext_ver == 0) { | ||
194 | - qemu_log("vector version is not specified, " | ||
195 | - "use the default value v1.0\n"); | ||
196 | - | ||
197 | - env->vext_ver = VEXT_VERSION_1_00_0; | ||
198 | - } | ||
199 | -} | ||
200 | - | ||
201 | -static void riscv_cpu_disable_priv_spec_isa_exts(RISCVCPU *cpu) | ||
202 | +void riscv_cpu_disable_priv_spec_isa_exts(RISCVCPU *cpu) | ||
203 | { | ||
204 | CPURISCVState *env = &cpu->env; | ||
205 | int i; | ||
206 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_disable_priv_spec_isa_exts(RISCVCPU *cpu) | ||
207 | } | ||
208 | } | ||
209 | |||
210 | -/* | ||
211 | - * Check consistency between chosen extensions while setting | ||
212 | - * cpu->cfg accordingly. | ||
213 | - */ | ||
214 | -void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp) | ||
215 | -{ | ||
216 | - CPURISCVState *env = &cpu->env; | ||
217 | - Error *local_err = NULL; | ||
218 | - | ||
219 | - /* Do some ISA extension error checking */ | ||
220 | - if (riscv_has_ext(env, RVG) && | ||
221 | - !(riscv_has_ext(env, RVI) && riscv_has_ext(env, RVM) && | ||
222 | - riscv_has_ext(env, RVA) && riscv_has_ext(env, RVF) && | ||
223 | - riscv_has_ext(env, RVD) && | ||
224 | - cpu->cfg.ext_icsr && cpu->cfg.ext_ifencei)) { | ||
225 | - | ||
226 | - if (cpu_cfg_ext_is_user_set(CPU_CFG_OFFSET(ext_icsr)) && | ||
227 | - !cpu->cfg.ext_icsr) { | ||
228 | - error_setg(errp, "RVG requires Zicsr but user set Zicsr to false"); | ||
229 | - return; | ||
230 | - } | ||
231 | - | ||
232 | - if (cpu_cfg_ext_is_user_set(CPU_CFG_OFFSET(ext_ifencei)) && | ||
233 | - !cpu->cfg.ext_ifencei) { | ||
234 | - error_setg(errp, "RVG requires Zifencei but user set " | ||
235 | - "Zifencei to false"); | ||
236 | - return; | ||
237 | - } | ||
238 | - | ||
239 | - warn_report("Setting G will also set IMAFD_Zicsr_Zifencei"); | ||
240 | - cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_icsr), true); | ||
241 | - cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_ifencei), true); | ||
242 | - | ||
243 | - env->misa_ext |= RVI | RVM | RVA | RVF | RVD; | ||
244 | - env->misa_ext_mask |= RVI | RVM | RVA | RVF | RVD; | ||
245 | - } | ||
246 | - | ||
247 | - if (riscv_has_ext(env, RVI) && riscv_has_ext(env, RVE)) { | ||
248 | - error_setg(errp, | ||
249 | - "I and E extensions are incompatible"); | ||
250 | - return; | ||
251 | - } | ||
252 | - | ||
253 | - if (!riscv_has_ext(env, RVI) && !riscv_has_ext(env, RVE)) { | ||
254 | - error_setg(errp, | ||
255 | - "Either I or E extension must be set"); | ||
256 | - return; | ||
257 | - } | ||
258 | - | ||
259 | - if (riscv_has_ext(env, RVS) && !riscv_has_ext(env, RVU)) { | ||
260 | - error_setg(errp, | ||
261 | - "Setting S extension without U extension is illegal"); | ||
262 | - return; | ||
263 | - } | ||
264 | - | ||
265 | - if (riscv_has_ext(env, RVH) && !riscv_has_ext(env, RVI)) { | ||
266 | - error_setg(errp, | ||
267 | - "H depends on an I base integer ISA with 32 x registers"); | ||
268 | - return; | ||
269 | - } | ||
270 | - | ||
271 | - if (riscv_has_ext(env, RVH) && !riscv_has_ext(env, RVS)) { | ||
272 | - error_setg(errp, "H extension implicitly requires S-mode"); | ||
273 | - return; | ||
274 | - } | ||
275 | - | ||
276 | - if (riscv_has_ext(env, RVF) && !cpu->cfg.ext_icsr) { | ||
277 | - error_setg(errp, "F extension requires Zicsr"); | ||
278 | - return; | ||
279 | - } | ||
280 | - | ||
281 | - if ((cpu->cfg.ext_zawrs) && !riscv_has_ext(env, RVA)) { | ||
282 | - error_setg(errp, "Zawrs extension requires A extension"); | ||
283 | - return; | ||
284 | - } | ||
285 | - | ||
286 | - if (cpu->cfg.ext_zfa && !riscv_has_ext(env, RVF)) { | ||
287 | - error_setg(errp, "Zfa extension requires F extension"); | ||
288 | - return; | ||
289 | - } | ||
290 | - | ||
291 | - if (cpu->cfg.ext_zfh) { | ||
292 | - cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zfhmin), true); | ||
293 | - } | ||
294 | - | ||
295 | - if (cpu->cfg.ext_zfhmin && !riscv_has_ext(env, RVF)) { | ||
296 | - error_setg(errp, "Zfh/Zfhmin extensions require F extension"); | ||
297 | - return; | ||
298 | - } | ||
299 | - | ||
300 | - if (cpu->cfg.ext_zfbfmin && !riscv_has_ext(env, RVF)) { | ||
301 | - error_setg(errp, "Zfbfmin extension depends on F extension"); | ||
302 | - return; | ||
303 | - } | ||
304 | - | ||
305 | - if (riscv_has_ext(env, RVD) && !riscv_has_ext(env, RVF)) { | ||
306 | - error_setg(errp, "D extension requires F extension"); | ||
307 | - return; | ||
308 | - } | ||
309 | - | ||
310 | - if (riscv_has_ext(env, RVV)) { | ||
311 | - riscv_cpu_validate_v(env, &cpu->cfg, &local_err); | ||
312 | - if (local_err != NULL) { | ||
313 | - error_propagate(errp, local_err); | ||
314 | - return; | ||
315 | - } | ||
316 | - | ||
317 | - /* The V vector extension depends on the Zve64d extension */ | ||
318 | - cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zve64d), true); | ||
319 | - } | ||
320 | - | ||
321 | - /* The Zve64d extension depends on the Zve64f extension */ | ||
322 | - if (cpu->cfg.ext_zve64d) { | ||
323 | - cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zve64f), true); | ||
324 | - } | ||
325 | - | ||
326 | - /* The Zve64f extension depends on the Zve32f extension */ | ||
327 | - if (cpu->cfg.ext_zve64f) { | ||
328 | - cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zve32f), true); | ||
329 | - } | ||
330 | - | ||
331 | - if (cpu->cfg.ext_zve64d && !riscv_has_ext(env, RVD)) { | ||
332 | - error_setg(errp, "Zve64d/V extensions require D extension"); | ||
333 | - return; | ||
334 | - } | ||
335 | - | ||
336 | - if (cpu->cfg.ext_zve32f && !riscv_has_ext(env, RVF)) { | ||
337 | - error_setg(errp, "Zve32f/Zve64f extensions require F extension"); | ||
338 | - return; | ||
339 | - } | ||
340 | - | ||
341 | - if (cpu->cfg.ext_zvfh) { | ||
342 | - cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zvfhmin), true); | ||
343 | - } | ||
344 | - | ||
345 | - if (cpu->cfg.ext_zvfhmin && !cpu->cfg.ext_zve32f) { | ||
346 | - error_setg(errp, "Zvfh/Zvfhmin extensions require Zve32f extension"); | ||
347 | - return; | ||
348 | - } | ||
349 | - | ||
350 | - if (cpu->cfg.ext_zvfh && !cpu->cfg.ext_zfhmin) { | ||
351 | - error_setg(errp, "Zvfh extensions requires Zfhmin extension"); | ||
352 | - return; | ||
353 | - } | ||
354 | - | ||
355 | - if (cpu->cfg.ext_zvfbfmin && !cpu->cfg.ext_zfbfmin) { | ||
356 | - error_setg(errp, "Zvfbfmin extension depends on Zfbfmin extension"); | ||
357 | - return; | ||
358 | - } | ||
359 | - | ||
360 | - if (cpu->cfg.ext_zvfbfmin && !cpu->cfg.ext_zve32f) { | ||
361 | - error_setg(errp, "Zvfbfmin extension depends on Zve32f extension"); | ||
362 | - return; | ||
363 | - } | ||
364 | - | ||
365 | - if (cpu->cfg.ext_zvfbfwma && !cpu->cfg.ext_zvfbfmin) { | ||
366 | - error_setg(errp, "Zvfbfwma extension depends on Zvfbfmin extension"); | ||
367 | - return; | ||
368 | - } | ||
369 | - | ||
370 | - /* Set the ISA extensions, checks should have happened above */ | ||
371 | - if (cpu->cfg.ext_zhinx) { | ||
372 | - cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zca), true); | ||
373 | - } | ||
374 | - | ||
375 | - if ((cpu->cfg.ext_zdinx || cpu->cfg.ext_zhinxmin) && !cpu->cfg.ext_zfinx) { | ||
376 | - error_setg(errp, "Zdinx/Zhinx/Zhinxmin extensions require Zfinx"); | ||
377 | - return; | ||
378 | - } | ||
379 | - | ||
380 | - if (cpu->cfg.ext_zfinx) { | ||
381 | - if (!cpu->cfg.ext_icsr) { | ||
382 | - error_setg(errp, "Zfinx extension requires Zicsr"); | ||
383 | - return; | ||
384 | - } | ||
385 | - if (riscv_has_ext(env, RVF)) { | ||
386 | - error_setg(errp, | ||
387 | - "Zfinx cannot be supported together with F extension"); | ||
388 | - return; | ||
389 | - } | ||
390 | - } | ||
391 | - | ||
392 | - if (cpu->cfg.ext_zce) { | ||
393 | - cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zca), true); | ||
394 | - cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zcb), true); | ||
395 | - cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zcmp), true); | ||
396 | - cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zcmt), true); | ||
397 | - if (riscv_has_ext(env, RVF) && env->misa_mxl_max == MXL_RV32) { | ||
398 | - cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zcf), true); | ||
399 | - } | ||
400 | - } | ||
401 | - | ||
402 | - /* zca, zcd and zcf has a PRIV 1.12.0 restriction */ | ||
403 | - if (riscv_has_ext(env, RVC) && env->priv_ver >= PRIV_VERSION_1_12_0) { | ||
404 | - cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zca), true); | ||
405 | - if (riscv_has_ext(env, RVF) && env->misa_mxl_max == MXL_RV32) { | ||
406 | - cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zcf), true); | ||
407 | - } | ||
408 | - if (riscv_has_ext(env, RVD)) { | ||
409 | - cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zcd), true); | ||
410 | - } | ||
411 | - } | ||
412 | - | ||
413 | - if (env->misa_mxl_max != MXL_RV32 && cpu->cfg.ext_zcf) { | ||
414 | - error_setg(errp, "Zcf extension is only relevant to RV32"); | ||
415 | - return; | ||
416 | - } | ||
417 | - | ||
418 | - if (!riscv_has_ext(env, RVF) && cpu->cfg.ext_zcf) { | ||
419 | - error_setg(errp, "Zcf extension requires F extension"); | ||
420 | - return; | ||
421 | - } | ||
422 | - | ||
423 | - if (!riscv_has_ext(env, RVD) && cpu->cfg.ext_zcd) { | ||
424 | - error_setg(errp, "Zcd extension requires D extension"); | ||
425 | - return; | ||
426 | - } | ||
427 | - | ||
428 | - if ((cpu->cfg.ext_zcf || cpu->cfg.ext_zcd || cpu->cfg.ext_zcb || | ||
429 | - cpu->cfg.ext_zcmp || cpu->cfg.ext_zcmt) && !cpu->cfg.ext_zca) { | ||
430 | - error_setg(errp, "Zcf/Zcd/Zcb/Zcmp/Zcmt extensions require Zca " | ||
431 | - "extension"); | ||
432 | - return; | ||
433 | - } | ||
434 | - | ||
435 | - if (cpu->cfg.ext_zcd && (cpu->cfg.ext_zcmp || cpu->cfg.ext_zcmt)) { | ||
436 | - error_setg(errp, "Zcmp/Zcmt extensions are incompatible with " | ||
437 | - "Zcd extension"); | ||
438 | - return; | ||
439 | - } | ||
440 | - | ||
441 | - if (cpu->cfg.ext_zcmt && !cpu->cfg.ext_icsr) { | ||
442 | - error_setg(errp, "Zcmt extension requires Zicsr extension"); | ||
443 | - return; | ||
444 | - } | ||
445 | - | ||
446 | - /* | ||
447 | - * In principle Zve*x would also suffice here, were they supported | ||
448 | - * in qemu | ||
449 | - */ | ||
450 | - if ((cpu->cfg.ext_zvbb || cpu->cfg.ext_zvkg || cpu->cfg.ext_zvkned || | ||
451 | - cpu->cfg.ext_zvknha || cpu->cfg.ext_zvksed || cpu->cfg.ext_zvksh) && | ||
452 | - !cpu->cfg.ext_zve32f) { | ||
453 | - error_setg(errp, | ||
454 | - "Vector crypto extensions require V or Zve* extensions"); | ||
455 | - return; | ||
456 | - } | ||
457 | - | ||
458 | - if ((cpu->cfg.ext_zvbc || cpu->cfg.ext_zvknhb) && !cpu->cfg.ext_zve64f) { | ||
459 | - error_setg( | ||
460 | - errp, | ||
461 | - "Zvbc and Zvknhb extensions require V or Zve64{f,d} extensions"); | ||
462 | - return; | ||
463 | - } | ||
464 | - | ||
465 | - if (cpu->cfg.ext_zk) { | ||
466 | - cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zkn), true); | ||
467 | - cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zkr), true); | ||
468 | - cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zkt), true); | ||
469 | - } | ||
470 | - | ||
471 | - if (cpu->cfg.ext_zkn) { | ||
472 | - cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zbkb), true); | ||
473 | - cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zbkc), true); | ||
474 | - cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zbkx), true); | ||
475 | - cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zkne), true); | ||
476 | - cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zknd), true); | ||
477 | - cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zknh), true); | ||
478 | - } | ||
479 | - | ||
480 | - if (cpu->cfg.ext_zks) { | ||
481 | - cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zbkb), true); | ||
482 | - cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zbkc), true); | ||
483 | - cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zbkx), true); | ||
484 | - cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zksed), true); | ||
485 | - cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zksh), true); | ||
486 | - } | ||
487 | - | ||
488 | - /* | ||
489 | - * Disable isa extensions based on priv spec after we | ||
490 | - * validated and set everything we need. | ||
491 | - */ | ||
492 | - riscv_cpu_disable_priv_spec_isa_exts(cpu); | ||
493 | -} | ||
494 | - | ||
495 | #ifndef CONFIG_USER_ONLY | ||
496 | static void riscv_cpu_satp_mode_finalize(RISCVCPU *cpu, Error **errp) | ||
497 | { | ||
498 | diff --git a/target/riscv/csr.c b/target/riscv/csr.c | ||
499 | index XXXXXXX..XXXXXXX 100644 | ||
500 | --- a/target/riscv/csr.c | ||
501 | +++ b/target/riscv/csr.c | ||
92 | @@ -XXX,XX +XXX,XX @@ | 502 | @@ -XXX,XX +XXX,XX @@ |
93 | #include "exec/helper-proto.h" | 503 | #include "qemu/log.h" |
94 | #include "tcg/tcg-gvec-desc.h" | 504 | #include "qemu/timer.h" |
95 | #include "crypto/aes.h" | 505 | #include "cpu.h" |
96 | +#include "crypto/sm4.h" | 506 | +#include "tcg/tcg-cpu.h" |
97 | #include "vec_internal.h" | 507 | #include "pmu.h" |
98 | 508 | #include "time_helper.h" | |
99 | union CRYPTO_STATE { | 509 | #include "exec/exec-all.h" |
100 | @@ -XXX,XX +XXX,XX @@ DO_SM3TT(crypto_sm3tt2b, 3) | 510 | diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c |
101 | 511 | index XXXXXXX..XXXXXXX 100644 | |
102 | #undef DO_SM3TT | 512 | --- a/target/riscv/tcg/tcg-cpu.c |
103 | 513 | +++ b/target/riscv/tcg/tcg-cpu.c | |
104 | -static uint8_t const sm4_sbox[] = { | 514 | @@ -XXX,XX +XXX,XX @@ |
105 | - 0xd6, 0x90, 0xe9, 0xfe, 0xcc, 0xe1, 0x3d, 0xb7, | 515 | |
106 | - 0x16, 0xb6, 0x14, 0xc2, 0x28, 0xfb, 0x2c, 0x05, | 516 | #include "qemu/osdep.h" |
107 | - 0x2b, 0x67, 0x9a, 0x76, 0x2a, 0xbe, 0x04, 0xc3, | 517 | #include "exec/exec-all.h" |
108 | - 0xaa, 0x44, 0x13, 0x26, 0x49, 0x86, 0x06, 0x99, | 518 | +#include "tcg-cpu.h" |
109 | - 0x9c, 0x42, 0x50, 0xf4, 0x91, 0xef, 0x98, 0x7a, | 519 | #include "cpu.h" |
110 | - 0x33, 0x54, 0x0b, 0x43, 0xed, 0xcf, 0xac, 0x62, | 520 | #include "pmu.h" |
111 | - 0xe4, 0xb3, 0x1c, 0xa9, 0xc9, 0x08, 0xe8, 0x95, | 521 | #include "time_helper.h" |
112 | - 0x80, 0xdf, 0x94, 0xfa, 0x75, 0x8f, 0x3f, 0xa6, | 522 | #include "qapi/error.h" |
113 | - 0x47, 0x07, 0xa7, 0xfc, 0xf3, 0x73, 0x17, 0xba, | 523 | #include "qemu/accel.h" |
114 | - 0x83, 0x59, 0x3c, 0x19, 0xe6, 0x85, 0x4f, 0xa8, | 524 | +#include "qemu/error-report.h" |
115 | - 0x68, 0x6b, 0x81, 0xb2, 0x71, 0x64, 0xda, 0x8b, | 525 | +#include "qemu/log.h" |
116 | - 0xf8, 0xeb, 0x0f, 0x4b, 0x70, 0x56, 0x9d, 0x35, | 526 | #include "hw/core/accel-cpu.h" |
117 | - 0x1e, 0x24, 0x0e, 0x5e, 0x63, 0x58, 0xd1, 0xa2, | 527 | |
118 | - 0x25, 0x22, 0x7c, 0x3b, 0x01, 0x21, 0x78, 0x87, | 528 | |
119 | - 0xd4, 0x00, 0x46, 0x57, 0x9f, 0xd3, 0x27, 0x52, | 529 | +static void cpu_cfg_ext_auto_update(RISCVCPU *cpu, uint32_t ext_offset, |
120 | - 0x4c, 0x36, 0x02, 0xe7, 0xa0, 0xc4, 0xc8, 0x9e, | 530 | + bool value) |
121 | - 0xea, 0xbf, 0x8a, 0xd2, 0x40, 0xc7, 0x38, 0xb5, | 531 | +{ |
122 | - 0xa3, 0xf7, 0xf2, 0xce, 0xf9, 0x61, 0x15, 0xa1, | 532 | + CPURISCVState *env = &cpu->env; |
123 | - 0xe0, 0xae, 0x5d, 0xa4, 0x9b, 0x34, 0x1a, 0x55, | 533 | + bool prev_val = isa_ext_is_enabled(cpu, ext_offset); |
124 | - 0xad, 0x93, 0x32, 0x30, 0xf5, 0x8c, 0xb1, 0xe3, | 534 | + int min_version; |
125 | - 0x1d, 0xf6, 0xe2, 0x2e, 0x82, 0x66, 0xca, 0x60, | 535 | + |
126 | - 0xc0, 0x29, 0x23, 0xab, 0x0d, 0x53, 0x4e, 0x6f, | 536 | + if (prev_val == value) { |
127 | - 0xd5, 0xdb, 0x37, 0x45, 0xde, 0xfd, 0x8e, 0x2f, | 537 | + return; |
128 | - 0x03, 0xff, 0x6a, 0x72, 0x6d, 0x6c, 0x5b, 0x51, | 538 | + } |
129 | - 0x8d, 0x1b, 0xaf, 0x92, 0xbb, 0xdd, 0xbc, 0x7f, | 539 | + |
130 | - 0x11, 0xd9, 0x5c, 0x41, 0x1f, 0x10, 0x5a, 0xd8, | 540 | + if (cpu_cfg_ext_is_user_set(ext_offset)) { |
131 | - 0x0a, 0xc1, 0x31, 0x88, 0xa5, 0xcd, 0x7b, 0xbd, | 541 | + return; |
132 | - 0x2d, 0x74, 0xd0, 0x12, 0xb8, 0xe5, 0xb4, 0xb0, | 542 | + } |
133 | - 0x89, 0x69, 0x97, 0x4a, 0x0c, 0x96, 0x77, 0x7e, | 543 | + |
134 | - 0x65, 0xb9, 0xf1, 0x09, 0xc5, 0x6e, 0xc6, 0x84, | 544 | + if (value && env->priv_ver != PRIV_VERSION_LATEST) { |
135 | - 0x18, 0xf0, 0x7d, 0xec, 0x3a, 0xdc, 0x4d, 0x20, | 545 | + /* Do not enable it if priv_ver is older than min_version */ |
136 | - 0x79, 0xee, 0x5f, 0x3e, 0xd7, 0xcb, 0x39, 0x48, | 546 | + min_version = cpu_cfg_ext_get_min_version(ext_offset); |
137 | -}; | 547 | + if (env->priv_ver < min_version) { |
138 | - | 548 | + return; |
139 | static void do_crypto_sm4e(uint64_t *rd, uint64_t *rn, uint64_t *rm) | 549 | + } |
550 | + } | ||
551 | + | ||
552 | + isa_ext_update_enabled(cpu, ext_offset, value); | ||
553 | +} | ||
554 | + | ||
555 | static void riscv_cpu_validate_misa_priv(CPURISCVState *env, Error **errp) | ||
140 | { | 556 | { |
141 | union CRYPTO_STATE d = { .l = { rn[0], rn[1] } }; | 557 | if (riscv_has_ext(env, RVH) && env->priv_ver < PRIV_VERSION_1_12_0) { |
142 | diff --git a/crypto/meson.build b/crypto/meson.build | 558 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_validate_priv_spec(RISCVCPU *cpu, Error **errp) |
143 | index XXXXXXX..XXXXXXX 100644 | 559 | } |
144 | --- a/crypto/meson.build | 560 | } |
145 | +++ b/crypto/meson.build | 561 | |
146 | @@ -XXX,XX +XXX,XX @@ if have_afalg | 562 | +static void riscv_cpu_validate_v(CPURISCVState *env, RISCVCPUConfig *cfg, |
147 | endif | 563 | + Error **errp) |
148 | crypto_ss.add(when: gnutls, if_true: files('tls-cipher-suites.c')) | 564 | +{ |
149 | 565 | + if (!is_power_of_2(cfg->vlen)) { | |
150 | +util_ss.add(files('sm4.c')) | 566 | + error_setg(errp, "Vector extension VLEN must be power of 2"); |
151 | util_ss.add(files('aes.c')) | 567 | + return; |
152 | util_ss.add(files('init.c')) | 568 | + } |
153 | if gnutls.found() | 569 | + |
570 | + if (cfg->vlen > RV_VLEN_MAX || cfg->vlen < 128) { | ||
571 | + error_setg(errp, | ||
572 | + "Vector extension implementation only supports VLEN " | ||
573 | + "in the range [128, %d]", RV_VLEN_MAX); | ||
574 | + return; | ||
575 | + } | ||
576 | + | ||
577 | + if (!is_power_of_2(cfg->elen)) { | ||
578 | + error_setg(errp, "Vector extension ELEN must be power of 2"); | ||
579 | + return; | ||
580 | + } | ||
581 | + | ||
582 | + if (cfg->elen > 64 || cfg->elen < 8) { | ||
583 | + error_setg(errp, | ||
584 | + "Vector extension implementation only supports ELEN " | ||
585 | + "in the range [8, 64]"); | ||
586 | + return; | ||
587 | + } | ||
588 | + | ||
589 | + if (cfg->vext_spec) { | ||
590 | + if (!g_strcmp0(cfg->vext_spec, "v1.0")) { | ||
591 | + env->vext_ver = VEXT_VERSION_1_00_0; | ||
592 | + } else { | ||
593 | + error_setg(errp, "Unsupported vector spec version '%s'", | ||
594 | + cfg->vext_spec); | ||
595 | + return; | ||
596 | + } | ||
597 | + } else if (env->vext_ver == 0) { | ||
598 | + qemu_log("vector version is not specified, " | ||
599 | + "use the default value v1.0\n"); | ||
600 | + | ||
601 | + env->vext_ver = VEXT_VERSION_1_00_0; | ||
602 | + } | ||
603 | +} | ||
604 | + | ||
605 | +/* | ||
606 | + * Check consistency between chosen extensions while setting | ||
607 | + * cpu->cfg accordingly. | ||
608 | + */ | ||
609 | +void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp) | ||
610 | +{ | ||
611 | + CPURISCVState *env = &cpu->env; | ||
612 | + Error *local_err = NULL; | ||
613 | + | ||
614 | + /* Do some ISA extension error checking */ | ||
615 | + if (riscv_has_ext(env, RVG) && | ||
616 | + !(riscv_has_ext(env, RVI) && riscv_has_ext(env, RVM) && | ||
617 | + riscv_has_ext(env, RVA) && riscv_has_ext(env, RVF) && | ||
618 | + riscv_has_ext(env, RVD) && | ||
619 | + cpu->cfg.ext_icsr && cpu->cfg.ext_ifencei)) { | ||
620 | + | ||
621 | + if (cpu_cfg_ext_is_user_set(CPU_CFG_OFFSET(ext_icsr)) && | ||
622 | + !cpu->cfg.ext_icsr) { | ||
623 | + error_setg(errp, "RVG requires Zicsr but user set Zicsr to false"); | ||
624 | + return; | ||
625 | + } | ||
626 | + | ||
627 | + if (cpu_cfg_ext_is_user_set(CPU_CFG_OFFSET(ext_ifencei)) && | ||
628 | + !cpu->cfg.ext_ifencei) { | ||
629 | + error_setg(errp, "RVG requires Zifencei but user set " | ||
630 | + "Zifencei to false"); | ||
631 | + return; | ||
632 | + } | ||
633 | + | ||
634 | + warn_report("Setting G will also set IMAFD_Zicsr_Zifencei"); | ||
635 | + cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_icsr), true); | ||
636 | + cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_ifencei), true); | ||
637 | + | ||
638 | + env->misa_ext |= RVI | RVM | RVA | RVF | RVD; | ||
639 | + env->misa_ext_mask |= RVI | RVM | RVA | RVF | RVD; | ||
640 | + } | ||
641 | + | ||
642 | + if (riscv_has_ext(env, RVI) && riscv_has_ext(env, RVE)) { | ||
643 | + error_setg(errp, | ||
644 | + "I and E extensions are incompatible"); | ||
645 | + return; | ||
646 | + } | ||
647 | + | ||
648 | + if (!riscv_has_ext(env, RVI) && !riscv_has_ext(env, RVE)) { | ||
649 | + error_setg(errp, | ||
650 | + "Either I or E extension must be set"); | ||
651 | + return; | ||
652 | + } | ||
653 | + | ||
654 | + if (riscv_has_ext(env, RVS) && !riscv_has_ext(env, RVU)) { | ||
655 | + error_setg(errp, | ||
656 | + "Setting S extension without U extension is illegal"); | ||
657 | + return; | ||
658 | + } | ||
659 | + | ||
660 | + if (riscv_has_ext(env, RVH) && !riscv_has_ext(env, RVI)) { | ||
661 | + error_setg(errp, | ||
662 | + "H depends on an I base integer ISA with 32 x registers"); | ||
663 | + return; | ||
664 | + } | ||
665 | + | ||
666 | + if (riscv_has_ext(env, RVH) && !riscv_has_ext(env, RVS)) { | ||
667 | + error_setg(errp, "H extension implicitly requires S-mode"); | ||
668 | + return; | ||
669 | + } | ||
670 | + | ||
671 | + if (riscv_has_ext(env, RVF) && !cpu->cfg.ext_icsr) { | ||
672 | + error_setg(errp, "F extension requires Zicsr"); | ||
673 | + return; | ||
674 | + } | ||
675 | + | ||
676 | + if ((cpu->cfg.ext_zawrs) && !riscv_has_ext(env, RVA)) { | ||
677 | + error_setg(errp, "Zawrs extension requires A extension"); | ||
678 | + return; | ||
679 | + } | ||
680 | + | ||
681 | + if (cpu->cfg.ext_zfa && !riscv_has_ext(env, RVF)) { | ||
682 | + error_setg(errp, "Zfa extension requires F extension"); | ||
683 | + return; | ||
684 | + } | ||
685 | + | ||
686 | + if (cpu->cfg.ext_zfh) { | ||
687 | + cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zfhmin), true); | ||
688 | + } | ||
689 | + | ||
690 | + if (cpu->cfg.ext_zfhmin && !riscv_has_ext(env, RVF)) { | ||
691 | + error_setg(errp, "Zfh/Zfhmin extensions require F extension"); | ||
692 | + return; | ||
693 | + } | ||
694 | + | ||
695 | + if (cpu->cfg.ext_zfbfmin && !riscv_has_ext(env, RVF)) { | ||
696 | + error_setg(errp, "Zfbfmin extension depends on F extension"); | ||
697 | + return; | ||
698 | + } | ||
699 | + | ||
700 | + if (riscv_has_ext(env, RVD) && !riscv_has_ext(env, RVF)) { | ||
701 | + error_setg(errp, "D extension requires F extension"); | ||
702 | + return; | ||
703 | + } | ||
704 | + | ||
705 | + if (riscv_has_ext(env, RVV)) { | ||
706 | + riscv_cpu_validate_v(env, &cpu->cfg, &local_err); | ||
707 | + if (local_err != NULL) { | ||
708 | + error_propagate(errp, local_err); | ||
709 | + return; | ||
710 | + } | ||
711 | + | ||
712 | + /* The V vector extension depends on the Zve64d extension */ | ||
713 | + cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zve64d), true); | ||
714 | + } | ||
715 | + | ||
716 | + /* The Zve64d extension depends on the Zve64f extension */ | ||
717 | + if (cpu->cfg.ext_zve64d) { | ||
718 | + cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zve64f), true); | ||
719 | + } | ||
720 | + | ||
721 | + /* The Zve64f extension depends on the Zve32f extension */ | ||
722 | + if (cpu->cfg.ext_zve64f) { | ||
723 | + cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zve32f), true); | ||
724 | + } | ||
725 | + | ||
726 | + if (cpu->cfg.ext_zve64d && !riscv_has_ext(env, RVD)) { | ||
727 | + error_setg(errp, "Zve64d/V extensions require D extension"); | ||
728 | + return; | ||
729 | + } | ||
730 | + | ||
731 | + if (cpu->cfg.ext_zve32f && !riscv_has_ext(env, RVF)) { | ||
732 | + error_setg(errp, "Zve32f/Zve64f extensions require F extension"); | ||
733 | + return; | ||
734 | + } | ||
735 | + | ||
736 | + if (cpu->cfg.ext_zvfh) { | ||
737 | + cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zvfhmin), true); | ||
738 | + } | ||
739 | + | ||
740 | + if (cpu->cfg.ext_zvfhmin && !cpu->cfg.ext_zve32f) { | ||
741 | + error_setg(errp, "Zvfh/Zvfhmin extensions require Zve32f extension"); | ||
742 | + return; | ||
743 | + } | ||
744 | + | ||
745 | + if (cpu->cfg.ext_zvfh && !cpu->cfg.ext_zfhmin) { | ||
746 | + error_setg(errp, "Zvfh extensions requires Zfhmin extension"); | ||
747 | + return; | ||
748 | + } | ||
749 | + | ||
750 | + if (cpu->cfg.ext_zvfbfmin && !cpu->cfg.ext_zfbfmin) { | ||
751 | + error_setg(errp, "Zvfbfmin extension depends on Zfbfmin extension"); | ||
752 | + return; | ||
753 | + } | ||
754 | + | ||
755 | + if (cpu->cfg.ext_zvfbfmin && !cpu->cfg.ext_zve32f) { | ||
756 | + error_setg(errp, "Zvfbfmin extension depends on Zve32f extension"); | ||
757 | + return; | ||
758 | + } | ||
759 | + | ||
760 | + if (cpu->cfg.ext_zvfbfwma && !cpu->cfg.ext_zvfbfmin) { | ||
761 | + error_setg(errp, "Zvfbfwma extension depends on Zvfbfmin extension"); | ||
762 | + return; | ||
763 | + } | ||
764 | + | ||
765 | + /* Set the ISA extensions, checks should have happened above */ | ||
766 | + if (cpu->cfg.ext_zhinx) { | ||
767 | + cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zca), true); | ||
768 | + } | ||
769 | + | ||
770 | + if ((cpu->cfg.ext_zdinx || cpu->cfg.ext_zhinxmin) && !cpu->cfg.ext_zfinx) { | ||
771 | + error_setg(errp, "Zdinx/Zhinx/Zhinxmin extensions require Zfinx"); | ||
772 | + return; | ||
773 | + } | ||
774 | + | ||
775 | + if (cpu->cfg.ext_zfinx) { | ||
776 | + if (!cpu->cfg.ext_icsr) { | ||
777 | + error_setg(errp, "Zfinx extension requires Zicsr"); | ||
778 | + return; | ||
779 | + } | ||
780 | + if (riscv_has_ext(env, RVF)) { | ||
781 | + error_setg(errp, | ||
782 | + "Zfinx cannot be supported together with F extension"); | ||
783 | + return; | ||
784 | + } | ||
785 | + } | ||
786 | + | ||
787 | + if (cpu->cfg.ext_zce) { | ||
788 | + cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zca), true); | ||
789 | + cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zcb), true); | ||
790 | + cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zcmp), true); | ||
791 | + cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zcmt), true); | ||
792 | + if (riscv_has_ext(env, RVF) && env->misa_mxl_max == MXL_RV32) { | ||
793 | + cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zcf), true); | ||
794 | + } | ||
795 | + } | ||
796 | + | ||
797 | + /* zca, zcd and zcf has a PRIV 1.12.0 restriction */ | ||
798 | + if (riscv_has_ext(env, RVC) && env->priv_ver >= PRIV_VERSION_1_12_0) { | ||
799 | + cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zca), true); | ||
800 | + if (riscv_has_ext(env, RVF) && env->misa_mxl_max == MXL_RV32) { | ||
801 | + cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zcf), true); | ||
802 | + } | ||
803 | + if (riscv_has_ext(env, RVD)) { | ||
804 | + cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zcd), true); | ||
805 | + } | ||
806 | + } | ||
807 | + | ||
808 | + if (env->misa_mxl_max != MXL_RV32 && cpu->cfg.ext_zcf) { | ||
809 | + error_setg(errp, "Zcf extension is only relevant to RV32"); | ||
810 | + return; | ||
811 | + } | ||
812 | + | ||
813 | + if (!riscv_has_ext(env, RVF) && cpu->cfg.ext_zcf) { | ||
814 | + error_setg(errp, "Zcf extension requires F extension"); | ||
815 | + return; | ||
816 | + } | ||
817 | + | ||
818 | + if (!riscv_has_ext(env, RVD) && cpu->cfg.ext_zcd) { | ||
819 | + error_setg(errp, "Zcd extension requires D extension"); | ||
820 | + return; | ||
821 | + } | ||
822 | + | ||
823 | + if ((cpu->cfg.ext_zcf || cpu->cfg.ext_zcd || cpu->cfg.ext_zcb || | ||
824 | + cpu->cfg.ext_zcmp || cpu->cfg.ext_zcmt) && !cpu->cfg.ext_zca) { | ||
825 | + error_setg(errp, "Zcf/Zcd/Zcb/Zcmp/Zcmt extensions require Zca " | ||
826 | + "extension"); | ||
827 | + return; | ||
828 | + } | ||
829 | + | ||
830 | + if (cpu->cfg.ext_zcd && (cpu->cfg.ext_zcmp || cpu->cfg.ext_zcmt)) { | ||
831 | + error_setg(errp, "Zcmp/Zcmt extensions are incompatible with " | ||
832 | + "Zcd extension"); | ||
833 | + return; | ||
834 | + } | ||
835 | + | ||
836 | + if (cpu->cfg.ext_zcmt && !cpu->cfg.ext_icsr) { | ||
837 | + error_setg(errp, "Zcmt extension requires Zicsr extension"); | ||
838 | + return; | ||
839 | + } | ||
840 | + | ||
841 | + /* | ||
842 | + * In principle Zve*x would also suffice here, were they supported | ||
843 | + * in qemu | ||
844 | + */ | ||
845 | + if ((cpu->cfg.ext_zvbb || cpu->cfg.ext_zvkg || cpu->cfg.ext_zvkned || | ||
846 | + cpu->cfg.ext_zvknha || cpu->cfg.ext_zvksed || cpu->cfg.ext_zvksh) && | ||
847 | + !cpu->cfg.ext_zve32f) { | ||
848 | + error_setg(errp, | ||
849 | + "Vector crypto extensions require V or Zve* extensions"); | ||
850 | + return; | ||
851 | + } | ||
852 | + | ||
853 | + if ((cpu->cfg.ext_zvbc || cpu->cfg.ext_zvknhb) && !cpu->cfg.ext_zve64f) { | ||
854 | + error_setg( | ||
855 | + errp, | ||
856 | + "Zvbc and Zvknhb extensions require V or Zve64{f,d} extensions"); | ||
857 | + return; | ||
858 | + } | ||
859 | + | ||
860 | + if (cpu->cfg.ext_zk) { | ||
861 | + cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zkn), true); | ||
862 | + cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zkr), true); | ||
863 | + cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zkt), true); | ||
864 | + } | ||
865 | + | ||
866 | + if (cpu->cfg.ext_zkn) { | ||
867 | + cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zbkb), true); | ||
868 | + cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zbkc), true); | ||
869 | + cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zbkx), true); | ||
870 | + cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zkne), true); | ||
871 | + cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zknd), true); | ||
872 | + cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zknh), true); | ||
873 | + } | ||
874 | + | ||
875 | + if (cpu->cfg.ext_zks) { | ||
876 | + cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zbkb), true); | ||
877 | + cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zbkc), true); | ||
878 | + cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zbkx), true); | ||
879 | + cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zksed), true); | ||
880 | + cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zksh), true); | ||
881 | + } | ||
882 | + | ||
883 | + /* | ||
884 | + * Disable isa extensions based on priv spec after we | ||
885 | + * validated and set everything we need. | ||
886 | + */ | ||
887 | + riscv_cpu_disable_priv_spec_isa_exts(cpu); | ||
888 | +} | ||
889 | + | ||
890 | /* | ||
891 | * We'll get here via the following path: | ||
892 | * | ||
154 | -- | 893 | -- |
155 | 2.35.1 | 894 | 2.41.0 | diff view generated by jsdifflib |
1 | From: Weiwei Li <liweiwei@iscas.ac.cn> | 1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
---|---|---|---|
2 | 2 | ||
3 | - add xperm4 and xperm8 instructions | 3 | Move the remaining of riscv_tcg_ops now that we have a working realize() |
4 | implementation. | ||
4 | 5 | ||
5 | Signed-off-by: Weiwei Li <liweiwei@iscas.ac.cn> | 6 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
6 | Signed-off-by: Junqiang Wang <wangjunqiang@iscas.ac.cn> | 7 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> |
7 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 8 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> |
8 | Acked-by: Alistair Francis <alistair.francis@wdc.com> | 9 | Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com> |
9 | Message-Id: <20220423023510.30794-5-liweiwei@iscas.ac.cn> | 10 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
11 | Message-ID: <20230925175709.35696-5-dbarboza@ventanamicro.com> | ||
10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 12 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
11 | --- | 13 | --- |
12 | target/riscv/helper.h | 2 ++ | 14 | target/riscv/cpu.h | 4 --- |
13 | target/riscv/insn32.decode | 4 ++++ | 15 | target/riscv/cpu.c | 58 ------------------------------------ |
14 | target/riscv/bitmanip_helper.c | 27 +++++++++++++++++++++++++ | 16 | target/riscv/tcg/tcg-cpu.c | 60 +++++++++++++++++++++++++++++++++++++- |
15 | target/riscv/insn_trans/trans_rvb.c.inc | 18 +++++++++++++++++ | 17 | 3 files changed, 59 insertions(+), 63 deletions(-) |
16 | 4 files changed, 51 insertions(+) | ||
17 | 18 | ||
18 | diff --git a/target/riscv/helper.h b/target/riscv/helper.h | 19 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h |
19 | index XXXXXXX..XXXXXXX 100644 | 20 | index XXXXXXX..XXXXXXX 100644 |
20 | --- a/target/riscv/helper.h | 21 | --- a/target/riscv/cpu.h |
21 | +++ b/target/riscv/helper.h | 22 | +++ b/target/riscv/cpu.h |
22 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_2(clmulr, TCG_CALL_NO_RWG_SE, tl, tl, tl) | 23 | @@ -XXX,XX +XXX,XX @@ enum riscv_pmu_event_idx { |
23 | DEF_HELPER_FLAGS_1(brev8, TCG_CALL_NO_RWG_SE, tl, tl) | 24 | RISCV_PMU_EVENT_CACHE_ITLB_PREFETCH_MISS = 0x10021, |
24 | DEF_HELPER_FLAGS_1(unzip, TCG_CALL_NO_RWG_SE, tl, tl) | 25 | }; |
25 | DEF_HELPER_FLAGS_1(zip, TCG_CALL_NO_RWG_SE, tl, tl) | 26 | |
26 | +DEF_HELPER_FLAGS_2(xperm4, TCG_CALL_NO_RWG_SE, tl, tl, tl) | 27 | -/* Export tcg_ops until we move everything to tcg/tcg-cpu.c */ |
27 | +DEF_HELPER_FLAGS_2(xperm8, TCG_CALL_NO_RWG_SE, tl, tl, tl) | 28 | -#include "hw/core/tcg-cpu-ops.h" |
28 | 29 | -extern const struct TCGCPUOps riscv_tcg_ops; | |
29 | /* Floating Point - Half Precision */ | 30 | - |
30 | DEF_HELPER_FLAGS_3(fadd_h, TCG_CALL_NO_RWG, i64, env, i64, i64) | 31 | /* used by tcg/tcg-cpu.c*/ |
31 | diff --git a/target/riscv/insn32.decode b/target/riscv/insn32.decode | 32 | void isa_ext_update_enabled(RISCVCPU *cpu, uint32_t ext_offset, bool en); |
33 | bool cpu_cfg_ext_is_user_set(uint32_t ext_offset); | ||
34 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | ||
32 | index XXXXXXX..XXXXXXX 100644 | 35 | index XXXXXXX..XXXXXXX 100644 |
33 | --- a/target/riscv/insn32.decode | 36 | --- a/target/riscv/cpu.c |
34 | +++ b/target/riscv/insn32.decode | 37 | +++ b/target/riscv/cpu.c |
35 | @@ -XXX,XX +XXX,XX @@ clmulh 0000101 .......... 011 ..... 0110011 @r | 38 | @@ -XXX,XX +XXX,XX @@ static vaddr riscv_cpu_get_pc(CPUState *cs) |
36 | # *** RV32 extra Zbc Standard Extension *** | 39 | return env->pc; |
37 | clmulr 0000101 .......... 010 ..... 0110011 @r | 40 | } |
38 | 41 | ||
39 | +# *** RV32 Zbkx Standard Extension *** | 42 | -static void riscv_cpu_synchronize_from_tb(CPUState *cs, |
40 | +xperm4 0010100 .......... 010 ..... 0110011 @r | 43 | - const TranslationBlock *tb) |
41 | +xperm8 0010100 .......... 100 ..... 0110011 @r | 44 | -{ |
45 | - if (!(tb_cflags(tb) & CF_PCREL)) { | ||
46 | - RISCVCPU *cpu = RISCV_CPU(cs); | ||
47 | - CPURISCVState *env = &cpu->env; | ||
48 | - RISCVMXL xl = FIELD_EX32(tb->flags, TB_FLAGS, XL); | ||
49 | - | ||
50 | - tcg_debug_assert(!(cs->tcg_cflags & CF_PCREL)); | ||
51 | - | ||
52 | - if (xl == MXL_RV32) { | ||
53 | - env->pc = (int32_t) tb->pc; | ||
54 | - } else { | ||
55 | - env->pc = tb->pc; | ||
56 | - } | ||
57 | - } | ||
58 | -} | ||
59 | - | ||
60 | static bool riscv_cpu_has_work(CPUState *cs) | ||
61 | { | ||
62 | #ifndef CONFIG_USER_ONLY | ||
63 | @@ -XXX,XX +XXX,XX @@ static bool riscv_cpu_has_work(CPUState *cs) | ||
64 | #endif | ||
65 | } | ||
66 | |||
67 | -static void riscv_restore_state_to_opc(CPUState *cs, | ||
68 | - const TranslationBlock *tb, | ||
69 | - const uint64_t *data) | ||
70 | -{ | ||
71 | - RISCVCPU *cpu = RISCV_CPU(cs); | ||
72 | - CPURISCVState *env = &cpu->env; | ||
73 | - RISCVMXL xl = FIELD_EX32(tb->flags, TB_FLAGS, XL); | ||
74 | - target_ulong pc; | ||
75 | - | ||
76 | - if (tb_cflags(tb) & CF_PCREL) { | ||
77 | - pc = (env->pc & TARGET_PAGE_MASK) | data[0]; | ||
78 | - } else { | ||
79 | - pc = data[0]; | ||
80 | - } | ||
81 | - | ||
82 | - if (xl == MXL_RV32) { | ||
83 | - env->pc = (int32_t)pc; | ||
84 | - } else { | ||
85 | - env->pc = pc; | ||
86 | - } | ||
87 | - env->bins = data[1]; | ||
88 | -} | ||
89 | - | ||
90 | static void riscv_cpu_reset_hold(Object *obj) | ||
91 | { | ||
92 | #ifndef CONFIG_USER_ONLY | ||
93 | @@ -XXX,XX +XXX,XX @@ static const struct SysemuCPUOps riscv_sysemu_ops = { | ||
94 | }; | ||
95 | #endif | ||
96 | |||
97 | -const struct TCGCPUOps riscv_tcg_ops = { | ||
98 | - .initialize = riscv_translate_init, | ||
99 | - .synchronize_from_tb = riscv_cpu_synchronize_from_tb, | ||
100 | - .restore_state_to_opc = riscv_restore_state_to_opc, | ||
101 | - | ||
102 | -#ifndef CONFIG_USER_ONLY | ||
103 | - .tlb_fill = riscv_cpu_tlb_fill, | ||
104 | - .cpu_exec_interrupt = riscv_cpu_exec_interrupt, | ||
105 | - .do_interrupt = riscv_cpu_do_interrupt, | ||
106 | - .do_transaction_failed = riscv_cpu_do_transaction_failed, | ||
107 | - .do_unaligned_access = riscv_cpu_do_unaligned_access, | ||
108 | - .debug_excp_handler = riscv_cpu_debug_excp_handler, | ||
109 | - .debug_check_breakpoint = riscv_cpu_debug_check_breakpoint, | ||
110 | - .debug_check_watchpoint = riscv_cpu_debug_check_watchpoint, | ||
111 | -#endif /* !CONFIG_USER_ONLY */ | ||
112 | -}; | ||
113 | - | ||
114 | static bool riscv_cpu_is_dynamic(Object *cpu_obj) | ||
115 | { | ||
116 | return object_dynamic_cast(cpu_obj, TYPE_RISCV_DYNAMIC_CPU) != NULL; | ||
117 | diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c | ||
118 | index XXXXXXX..XXXXXXX 100644 | ||
119 | --- a/target/riscv/tcg/tcg-cpu.c | ||
120 | +++ b/target/riscv/tcg/tcg-cpu.c | ||
121 | @@ -XXX,XX +XXX,XX @@ | ||
122 | #include "qemu/error-report.h" | ||
123 | #include "qemu/log.h" | ||
124 | #include "hw/core/accel-cpu.h" | ||
125 | +#include "hw/core/tcg-cpu-ops.h" | ||
126 | +#include "tcg/tcg.h" | ||
127 | |||
128 | +static void riscv_cpu_synchronize_from_tb(CPUState *cs, | ||
129 | + const TranslationBlock *tb) | ||
130 | +{ | ||
131 | + if (!(tb_cflags(tb) & CF_PCREL)) { | ||
132 | + RISCVCPU *cpu = RISCV_CPU(cs); | ||
133 | + CPURISCVState *env = &cpu->env; | ||
134 | + RISCVMXL xl = FIELD_EX32(tb->flags, TB_FLAGS, XL); | ||
42 | + | 135 | + |
43 | # *** RV32 Zbs Standard Extension *** | 136 | + tcg_debug_assert(!(cs->tcg_cflags & CF_PCREL)); |
44 | bclr 0100100 .......... 001 ..... 0110011 @r | ||
45 | bclri 01001. ........... 001 ..... 0010011 @sh | ||
46 | diff --git a/target/riscv/bitmanip_helper.c b/target/riscv/bitmanip_helper.c | ||
47 | index XXXXXXX..XXXXXXX 100644 | ||
48 | --- a/target/riscv/bitmanip_helper.c | ||
49 | +++ b/target/riscv/bitmanip_helper.c | ||
50 | @@ -XXX,XX +XXX,XX @@ target_ulong HELPER(zip)(target_ulong rs1) | ||
51 | x = do_shuf_stage(x, shuf_masks[0], shuf_masks[0] >> 1, 1); | ||
52 | return x; | ||
53 | } | ||
54 | + | 137 | + |
55 | +static inline target_ulong do_xperm(target_ulong rs1, target_ulong rs2, | 138 | + if (xl == MXL_RV32) { |
56 | + uint32_t sz_log2) | 139 | + env->pc = (int32_t) tb->pc; |
57 | +{ | 140 | + } else { |
58 | + target_ulong r = 0; | 141 | + env->pc = tb->pc; |
59 | + target_ulong sz = 1LL << sz_log2; | ||
60 | + target_ulong mask = (1LL << sz) - 1; | ||
61 | + target_ulong pos; | ||
62 | + | ||
63 | + for (int i = 0; i < TARGET_LONG_BITS; i += sz) { | ||
64 | + pos = ((rs2 >> i) & mask) << sz_log2; | ||
65 | + if (pos < sizeof(target_ulong) * 8) { | ||
66 | + r |= ((rs1 >> pos) & mask) << i; | ||
67 | + } | 142 | + } |
68 | + } | 143 | + } |
69 | + return r; | ||
70 | +} | 144 | +} |
71 | + | 145 | + |
72 | +target_ulong HELPER(xperm4)(target_ulong rs1, target_ulong rs2) | 146 | +static void riscv_restore_state_to_opc(CPUState *cs, |
147 | + const TranslationBlock *tb, | ||
148 | + const uint64_t *data) | ||
73 | +{ | 149 | +{ |
74 | + return do_xperm(rs1, rs2, 2); | 150 | + RISCVCPU *cpu = RISCV_CPU(cs); |
151 | + CPURISCVState *env = &cpu->env; | ||
152 | + RISCVMXL xl = FIELD_EX32(tb->flags, TB_FLAGS, XL); | ||
153 | + target_ulong pc; | ||
154 | + | ||
155 | + if (tb_cflags(tb) & CF_PCREL) { | ||
156 | + pc = (env->pc & TARGET_PAGE_MASK) | data[0]; | ||
157 | + } else { | ||
158 | + pc = data[0]; | ||
159 | + } | ||
160 | + | ||
161 | + if (xl == MXL_RV32) { | ||
162 | + env->pc = (int32_t)pc; | ||
163 | + } else { | ||
164 | + env->pc = pc; | ||
165 | + } | ||
166 | + env->bins = data[1]; | ||
75 | +} | 167 | +} |
76 | + | 168 | + |
77 | +target_ulong HELPER(xperm8)(target_ulong rs1, target_ulong rs2) | 169 | +static const struct TCGCPUOps riscv_tcg_ops = { |
78 | +{ | 170 | + .initialize = riscv_translate_init, |
79 | + return do_xperm(rs1, rs2, 3); | 171 | + .synchronize_from_tb = riscv_cpu_synchronize_from_tb, |
80 | +} | 172 | + .restore_state_to_opc = riscv_restore_state_to_opc, |
81 | diff --git a/target/riscv/insn_trans/trans_rvb.c.inc b/target/riscv/insn_trans/trans_rvb.c.inc | ||
82 | index XXXXXXX..XXXXXXX 100644 | ||
83 | --- a/target/riscv/insn_trans/trans_rvb.c.inc | ||
84 | +++ b/target/riscv/insn_trans/trans_rvb.c.inc | ||
85 | @@ -XXX,XX +XXX,XX @@ | ||
86 | } \ | ||
87 | } while (0) | ||
88 | |||
89 | +#define REQUIRE_ZBKX(ctx) do { \ | ||
90 | + if (!ctx->cfg_ptr->ext_zbkx) { \ | ||
91 | + return false; \ | ||
92 | + } \ | ||
93 | +} while (0) | ||
94 | + | 173 | + |
95 | static void gen_clz(TCGv ret, TCGv arg1) | 174 | +#ifndef CONFIG_USER_ONLY |
175 | + .tlb_fill = riscv_cpu_tlb_fill, | ||
176 | + .cpu_exec_interrupt = riscv_cpu_exec_interrupt, | ||
177 | + .do_interrupt = riscv_cpu_do_interrupt, | ||
178 | + .do_transaction_failed = riscv_cpu_do_transaction_failed, | ||
179 | + .do_unaligned_access = riscv_cpu_do_unaligned_access, | ||
180 | + .debug_excp_handler = riscv_cpu_debug_excp_handler, | ||
181 | + .debug_check_breakpoint = riscv_cpu_debug_check_breakpoint, | ||
182 | + .debug_check_watchpoint = riscv_cpu_debug_check_watchpoint, | ||
183 | +#endif /* !CONFIG_USER_ONLY */ | ||
184 | +}; | ||
185 | |||
186 | static void cpu_cfg_ext_auto_update(RISCVCPU *cpu, uint32_t ext_offset, | ||
187 | bool value) | ||
188 | @@ -XXX,XX +XXX,XX @@ static void tcg_cpu_init_ops(AccelCPUClass *accel_cpu, CPUClass *cc) | ||
96 | { | 189 | { |
97 | tcg_gen_clzi_tl(ret, arg1, TARGET_LONG_BITS); | 190 | /* |
98 | @@ -XXX,XX +XXX,XX @@ static bool trans_zip(DisasContext *ctx, arg_zip *a) | 191 | * All cpus use the same set of operations. |
99 | REQUIRE_ZBKB(ctx); | 192 | - * riscv_tcg_ops is being imported from cpu.c for now. |
100 | return gen_unary(ctx, a, EXT_NONE, gen_helper_zip); | 193 | */ |
194 | cc->tcg_ops = &riscv_tcg_ops; | ||
101 | } | 195 | } |
102 | + | ||
103 | +static bool trans_xperm4(DisasContext *ctx, arg_xperm4 *a) | ||
104 | +{ | ||
105 | + REQUIRE_ZBKX(ctx); | ||
106 | + return gen_arith(ctx, a, EXT_NONE, gen_helper_xperm4, NULL); | ||
107 | +} | ||
108 | + | ||
109 | +static bool trans_xperm8(DisasContext *ctx, arg_xperm8 *a) | ||
110 | +{ | ||
111 | + REQUIRE_ZBKX(ctx); | ||
112 | + return gen_arith(ctx, a, EXT_NONE, gen_helper_xperm8, NULL); | ||
113 | +} | ||
114 | -- | 196 | -- |
115 | 2.35.1 | 197 | 2.41.0 |
198 | |||
199 | diff view generated by jsdifflib |
1 | From: Weiwei Li <liweiwei@iscas.ac.cn> | 1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
---|---|---|---|
2 | 2 | ||
3 | - add sha512sum0r, sha512sig0l, sha512sum1r, sha512sig1l, sha512sig0h and sha512sig1h instructions | 3 | All generic CPUs call riscv_cpu_add_user_properties(). The 'max' CPU |
4 | calls riscv_init_max_cpu_extensions(). Both can be moved to a common | ||
5 | instance_post_init() callback, implemented in riscv_cpu_post_init(), | ||
6 | called by all CPUs. The call order then becomes: | ||
4 | 7 | ||
5 | Co-authored-by: Zewen Ye <lustrew@foxmail.com> | 8 | riscv_cpu_init() -> cpu_init() of each CPU -> .instance_post_init() |
6 | Signed-off-by: Weiwei Li <liweiwei@iscas.ac.cn> | 9 | |
7 | Signed-off-by: Junqiang Wang <wangjunqiang@iscas.ac.cn> | 10 | In the near future riscv_cpu_post_init() will call the init() function |
8 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 11 | of the current accelerator, providing a hook for KVM and TCG accel |
12 | classes to change the init() process of the CPU. | ||
13 | |||
14 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
15 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> | ||
9 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 16 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
10 | Message-Id: <20220423023510.30794-10-liweiwei@iscas.ac.cn> | 17 | Message-ID: <20230925175709.35696-6-dbarboza@ventanamicro.com> |
11 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 18 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
12 | --- | 19 | --- |
13 | target/riscv/insn32.decode | 6 ++ | 20 | target/riscv/cpu.c | 43 ++++++++++++++++++++++++++++++++----------- |
14 | target/riscv/insn_trans/trans_rvk.c.inc | 100 ++++++++++++++++++++++++ | 21 | 1 file changed, 32 insertions(+), 11 deletions(-) |
15 | 2 files changed, 106 insertions(+) | ||
16 | 22 | ||
17 | diff --git a/target/riscv/insn32.decode b/target/riscv/insn32.decode | 23 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c |
18 | index XXXXXXX..XXXXXXX 100644 | 24 | index XXXXXXX..XXXXXXX 100644 |
19 | --- a/target/riscv/insn32.decode | 25 | --- a/target/riscv/cpu.c |
20 | +++ b/target/riscv/insn32.decode | 26 | +++ b/target/riscv/cpu.c |
21 | @@ -XXX,XX +XXX,XX @@ sha256sig0 00 01000 00010 ..... 001 ..... 0010011 @r2 | 27 | @@ -XXX,XX +XXX,XX @@ static void riscv_max_cpu_init(Object *obj) |
22 | sha256sig1 00 01000 00011 ..... 001 ..... 0010011 @r2 | 28 | mlx = MXL_RV32; |
23 | sha256sum0 00 01000 00000 ..... 001 ..... 0010011 @r2 | 29 | #endif |
24 | sha256sum1 00 01000 00001 ..... 001 ..... 0010011 @r2 | 30 | set_misa(env, mlx, 0); |
25 | +sha512sum0r 01 01000 ..... ..... 000 ..... 0110011 @r | 31 | - riscv_cpu_add_user_properties(obj); |
26 | +sha512sum1r 01 01001 ..... ..... 000 ..... 0110011 @r | 32 | - riscv_init_max_cpu_extensions(obj); |
27 | +sha512sig0l 01 01010 ..... ..... 000 ..... 0110011 @r | 33 | env->priv_ver = PRIV_VERSION_LATEST; |
28 | +sha512sig0h 01 01110 ..... ..... 000 ..... 0110011 @r | 34 | #ifndef CONFIG_USER_ONLY |
29 | +sha512sig1l 01 01011 ..... ..... 000 ..... 0110011 @r | 35 | set_satp_mode_max_supported(RISCV_CPU(obj), mlx == MXL_RV32 ? |
30 | +sha512sig1h 01 01111 ..... ..... 000 ..... 0110011 @r | 36 | @@ -XXX,XX +XXX,XX @@ static void rv64_base_cpu_init(Object *obj) |
31 | diff --git a/target/riscv/insn_trans/trans_rvk.c.inc b/target/riscv/insn_trans/trans_rvk.c.inc | 37 | CPURISCVState *env = &RISCV_CPU(obj)->env; |
32 | index XXXXXXX..XXXXXXX 100644 | 38 | /* We set this in the realise function */ |
33 | --- a/target/riscv/insn_trans/trans_rvk.c.inc | 39 | set_misa(env, MXL_RV64, 0); |
34 | +++ b/target/riscv/insn_trans/trans_rvk.c.inc | 40 | - riscv_cpu_add_user_properties(obj); |
35 | @@ -XXX,XX +XXX,XX @@ static bool trans_sha256sum1(DisasContext *ctx, arg_sha256sum1 *a) | 41 | /* Set latest version of privileged specification */ |
36 | REQUIRE_ZKNH(ctx); | 42 | env->priv_ver = PRIV_VERSION_LATEST; |
37 | return gen_sha256(ctx, a, EXT_NONE, tcg_gen_rotri_i32, 6, 11, 25); | 43 | #ifndef CONFIG_USER_ONLY |
44 | @@ -XXX,XX +XXX,XX @@ static void rv128_base_cpu_init(Object *obj) | ||
45 | CPURISCVState *env = &RISCV_CPU(obj)->env; | ||
46 | /* We set this in the realise function */ | ||
47 | set_misa(env, MXL_RV128, 0); | ||
48 | - riscv_cpu_add_user_properties(obj); | ||
49 | /* Set latest version of privileged specification */ | ||
50 | env->priv_ver = PRIV_VERSION_LATEST; | ||
51 | #ifndef CONFIG_USER_ONLY | ||
52 | @@ -XXX,XX +XXX,XX @@ static void rv32_base_cpu_init(Object *obj) | ||
53 | CPURISCVState *env = &RISCV_CPU(obj)->env; | ||
54 | /* We set this in the realise function */ | ||
55 | set_misa(env, MXL_RV32, 0); | ||
56 | - riscv_cpu_add_user_properties(obj); | ||
57 | /* Set latest version of privileged specification */ | ||
58 | env->priv_ver = PRIV_VERSION_LATEST; | ||
59 | #ifndef CONFIG_USER_ONLY | ||
60 | @@ -XXX,XX +XXX,XX @@ static void riscv_host_cpu_init(Object *obj) | ||
61 | #elif defined(TARGET_RISCV64) | ||
62 | set_misa(env, MXL_RV64, 0); | ||
63 | #endif | ||
64 | - riscv_cpu_add_user_properties(obj); | ||
38 | } | 65 | } |
39 | + | 66 | #endif /* CONFIG_KVM */ |
40 | +static bool gen_sha512_rv32(DisasContext *ctx, arg_r *a, DisasExtend ext, | 67 | |
41 | + void (*func1)(TCGv_i64, TCGv_i64, int64_t), | 68 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_set_irq(void *opaque, int irq, int level) |
42 | + void (*func2)(TCGv_i64, TCGv_i64, int64_t), | 69 | } |
43 | + int64_t num1, int64_t num2, int64_t num3) | 70 | #endif /* CONFIG_USER_ONLY */ |
71 | |||
72 | +static bool riscv_cpu_is_dynamic(Object *cpu_obj) | ||
44 | +{ | 73 | +{ |
45 | + TCGv dest = dest_gpr(ctx, a->rd); | 74 | + return object_dynamic_cast(cpu_obj, TYPE_RISCV_DYNAMIC_CPU) != NULL; |
46 | + TCGv src1 = get_gpr(ctx, a->rs1, ext); | ||
47 | + TCGv src2 = get_gpr(ctx, a->rs2, ext); | ||
48 | + TCGv_i64 t0 = tcg_temp_new_i64(); | ||
49 | + TCGv_i64 t1 = tcg_temp_new_i64(); | ||
50 | + TCGv_i64 t2 = tcg_temp_new_i64(); | ||
51 | + | ||
52 | + tcg_gen_concat_tl_i64(t0, src1, src2); | ||
53 | + func1(t1, t0, num1); | ||
54 | + func2(t2, t0, num2); | ||
55 | + tcg_gen_xor_i64(t1, t1, t2); | ||
56 | + tcg_gen_rotri_i64(t2, t0, num3); | ||
57 | + tcg_gen_xor_i64(t1, t1, t2); | ||
58 | + tcg_gen_trunc_i64_tl(dest, t1); | ||
59 | + | ||
60 | + gen_set_gpr(ctx, a->rd, dest); | ||
61 | + tcg_temp_free_i64(t0); | ||
62 | + tcg_temp_free_i64(t1); | ||
63 | + tcg_temp_free_i64(t2); | ||
64 | + return true; | ||
65 | +} | 75 | +} |
66 | + | 76 | + |
67 | +static bool trans_sha512sum0r(DisasContext *ctx, arg_sha512sum0r *a) | 77 | +static bool riscv_cpu_has_max_extensions(Object *cpu_obj) |
68 | +{ | 78 | +{ |
69 | + REQUIRE_32BIT(ctx); | 79 | + return object_dynamic_cast(cpu_obj, TYPE_RISCV_CPU_MAX) != NULL; |
70 | + REQUIRE_ZKNH(ctx); | ||
71 | + return gen_sha512_rv32(ctx, a, EXT_NONE, tcg_gen_rotli_i64, | ||
72 | + tcg_gen_rotli_i64, 25, 30, 28); | ||
73 | +} | 80 | +} |
74 | + | 81 | + |
75 | +static bool trans_sha512sum1r(DisasContext *ctx, arg_sha512sum1r *a) | 82 | +static bool riscv_cpu_has_user_properties(Object *cpu_obj) |
76 | +{ | 83 | +{ |
77 | + REQUIRE_32BIT(ctx); | 84 | + if (kvm_enabled() && |
78 | + REQUIRE_ZKNH(ctx); | 85 | + object_dynamic_cast(cpu_obj, TYPE_RISCV_CPU_HOST) != NULL) { |
79 | + return gen_sha512_rv32(ctx, a, EXT_NONE, tcg_gen_rotli_i64, | 86 | + return true; |
80 | + tcg_gen_rotri_i64, 23, 14, 18); | 87 | + } |
88 | + | ||
89 | + return riscv_cpu_is_dynamic(cpu_obj); | ||
81 | +} | 90 | +} |
82 | + | 91 | + |
83 | +static bool trans_sha512sig0l(DisasContext *ctx, arg_sha512sig0l *a) | 92 | +static void riscv_cpu_post_init(Object *obj) |
84 | +{ | 93 | +{ |
85 | + REQUIRE_32BIT(ctx); | 94 | + if (riscv_cpu_has_user_properties(obj)) { |
86 | + REQUIRE_ZKNH(ctx); | 95 | + riscv_cpu_add_user_properties(obj); |
87 | + return gen_sha512_rv32(ctx, a, EXT_NONE, tcg_gen_rotri_i64, | 96 | + } |
88 | + tcg_gen_rotri_i64, 1, 7, 8); | 97 | + |
98 | + if (riscv_cpu_has_max_extensions(obj)) { | ||
99 | + riscv_init_max_cpu_extensions(obj); | ||
100 | + } | ||
89 | +} | 101 | +} |
90 | + | 102 | + |
91 | +static bool trans_sha512sig1l(DisasContext *ctx, arg_sha512sig1l *a) | 103 | static void riscv_cpu_init(Object *obj) |
92 | +{ | 104 | { |
93 | + REQUIRE_32BIT(ctx); | 105 | #ifndef CONFIG_USER_ONLY |
94 | + REQUIRE_ZKNH(ctx); | 106 | @@ -XXX,XX +XXX,XX @@ static const struct SysemuCPUOps riscv_sysemu_ops = { |
95 | + return gen_sha512_rv32(ctx, a, EXT_NONE, tcg_gen_rotli_i64, | 107 | }; |
96 | + tcg_gen_rotri_i64, 3, 6, 19); | 108 | #endif |
97 | +} | 109 | |
98 | + | 110 | -static bool riscv_cpu_is_dynamic(Object *cpu_obj) |
99 | +static bool gen_sha512h_rv32(DisasContext *ctx, arg_r *a, DisasExtend ext, | 111 | -{ |
100 | + void (*func)(TCGv_i64, TCGv_i64, int64_t), | 112 | - return object_dynamic_cast(cpu_obj, TYPE_RISCV_DYNAMIC_CPU) != NULL; |
101 | + int64_t num1, int64_t num2, int64_t num3) | 113 | -} |
102 | +{ | 114 | - |
103 | + TCGv dest = dest_gpr(ctx, a->rd); | 115 | static void cpu_set_mvendorid(Object *obj, Visitor *v, const char *name, |
104 | + TCGv src1 = get_gpr(ctx, a->rs1, ext); | 116 | void *opaque, Error **errp) |
105 | + TCGv src2 = get_gpr(ctx, a->rs2, ext); | 117 | { |
106 | + TCGv_i64 t0 = tcg_temp_new_i64(); | 118 | @@ -XXX,XX +XXX,XX @@ static const TypeInfo riscv_cpu_type_infos[] = { |
107 | + TCGv_i64 t1 = tcg_temp_new_i64(); | 119 | .instance_size = sizeof(RISCVCPU), |
108 | + TCGv_i64 t2 = tcg_temp_new_i64(); | 120 | .instance_align = __alignof(RISCVCPU), |
109 | + | 121 | .instance_init = riscv_cpu_init, |
110 | + tcg_gen_concat_tl_i64(t0, src1, src2); | 122 | + .instance_post_init = riscv_cpu_post_init, |
111 | + func(t1, t0, num1); | 123 | .abstract = true, |
112 | + tcg_gen_ext32u_i64(t2, t0); | 124 | .class_size = sizeof(RISCVCPUClass), |
113 | + tcg_gen_shri_i64(t2, t2, num2); | 125 | .class_init = riscv_cpu_class_init, |
114 | + tcg_gen_xor_i64(t1, t1, t2); | ||
115 | + tcg_gen_rotri_i64(t2, t0, num3); | ||
116 | + tcg_gen_xor_i64(t1, t1, t2); | ||
117 | + tcg_gen_trunc_i64_tl(dest, t1); | ||
118 | + | ||
119 | + gen_set_gpr(ctx, a->rd, dest); | ||
120 | + tcg_temp_free_i64(t0); | ||
121 | + tcg_temp_free_i64(t1); | ||
122 | + tcg_temp_free_i64(t2); | ||
123 | + return true; | ||
124 | +} | ||
125 | + | ||
126 | +static bool trans_sha512sig0h(DisasContext *ctx, arg_sha512sig0h *a) | ||
127 | +{ | ||
128 | + REQUIRE_32BIT(ctx); | ||
129 | + REQUIRE_ZKNH(ctx); | ||
130 | + return gen_sha512h_rv32(ctx, a, EXT_NONE, tcg_gen_rotri_i64, 1, 7, 8); | ||
131 | +} | ||
132 | + | ||
133 | +static bool trans_sha512sig1h(DisasContext *ctx, arg_sha512sig1h *a) | ||
134 | +{ | ||
135 | + REQUIRE_32BIT(ctx); | ||
136 | + REQUIRE_ZKNH(ctx); | ||
137 | + return gen_sha512h_rv32(ctx, a, EXT_NONE, tcg_gen_rotli_i64, 3, 6, 19); | ||
138 | +} | ||
139 | -- | 126 | -- |
140 | 2.35.1 | 127 | 2.41.0 | diff view generated by jsdifflib |
1 | From: Weiwei Li <liweiwei@iscas.ac.cn> | 1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
---|---|---|---|
2 | 2 | ||
3 | - add SEED CSR which must be accessed with a read-write instruction: | 3 | This CPU only exists if we're compiling with KVM so move it to the kvm |
4 | A read-only instruction such as CSRRS/CSRRC with rs1=x0 or CSRRSI/CSRRCI | 4 | specific file. |
5 | with uimm=0 will raise an illegal instruction exception. | ||
6 | - add USEED, SSEED fields for MSECCFG CSR | ||
7 | 5 | ||
8 | Co-authored-by: Ruibo Lu <luruibo2000@163.com> | 6 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
9 | Co-authored-by: Zewen Ye <lustrew@foxmail.com> | 7 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> |
10 | Signed-off-by: Weiwei Li <liweiwei@iscas.ac.cn> | 8 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> |
11 | Signed-off-by: Junqiang Wang <wangjunqiang@iscas.ac.cn> | 9 | Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com> |
12 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 10 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
13 | Message-Id: <20220423023510.30794-13-liweiwei@iscas.ac.cn> | 11 | Message-ID: <20230925175709.35696-7-dbarboza@ventanamicro.com> |
14 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 12 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
15 | --- | 13 | --- |
16 | target/riscv/cpu_bits.h | 9 +++++ | 14 | target/riscv/cpu.c | 15 --------------- |
17 | target/riscv/pmp.h | 8 ++-- | 15 | target/riscv/kvm.c | 21 +++++++++++++++++++++ |
18 | target/riscv/csr.c | 80 ++++++++++++++++++++++++++++++++++++++++ | 16 | 2 files changed, 21 insertions(+), 15 deletions(-) |
19 | target/riscv/op_helper.c | 9 +++++ | ||
20 | 4 files changed, 103 insertions(+), 3 deletions(-) | ||
21 | 17 | ||
22 | diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h | 18 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c |
23 | index XXXXXXX..XXXXXXX 100644 | 19 | index XXXXXXX..XXXXXXX 100644 |
24 | --- a/target/riscv/cpu_bits.h | 20 | --- a/target/riscv/cpu.c |
25 | +++ b/target/riscv/cpu_bits.h | 21 | +++ b/target/riscv/cpu.c |
26 | @@ -XXX,XX +XXX,XX @@ | 22 | @@ -XXX,XX +XXX,XX @@ static void rv32_imafcu_nommu_cpu_init(Object *obj) |
27 | #define CSR_VSPMMASK 0x2c1 | ||
28 | #define CSR_VSPMBASE 0x2c2 | ||
29 | |||
30 | +/* Crypto Extension */ | ||
31 | +#define CSR_SEED 0x015 | ||
32 | + | ||
33 | /* mstatus CSR bits */ | ||
34 | #define MSTATUS_UIE 0x00000001 | ||
35 | #define MSTATUS_SIE 0x00000002 | ||
36 | @@ -XXX,XX +XXX,XX @@ typedef enum RISCVException { | ||
37 | #define HVICTL_VALID_MASK \ | ||
38 | (HVICTL_VTI | HVICTL_IID | HVICTL_IPRIOM | HVICTL_IPRIO) | ||
39 | |||
40 | +/* seed CSR bits */ | ||
41 | +#define SEED_OPST (0b11 << 30) | ||
42 | +#define SEED_OPST_BIST (0b00 << 30) | ||
43 | +#define SEED_OPST_WAIT (0b01 << 30) | ||
44 | +#define SEED_OPST_ES16 (0b10 << 30) | ||
45 | +#define SEED_OPST_DEAD (0b11 << 30) | ||
46 | #endif | ||
47 | diff --git a/target/riscv/pmp.h b/target/riscv/pmp.h | ||
48 | index XXXXXXX..XXXXXXX 100644 | ||
49 | --- a/target/riscv/pmp.h | ||
50 | +++ b/target/riscv/pmp.h | ||
51 | @@ -XXX,XX +XXX,XX @@ typedef enum { | ||
52 | } pmp_am_t; | ||
53 | |||
54 | typedef enum { | ||
55 | - MSECCFG_MML = 1 << 0, | ||
56 | - MSECCFG_MMWP = 1 << 1, | ||
57 | - MSECCFG_RLB = 1 << 2 | ||
58 | + MSECCFG_MML = 1 << 0, | ||
59 | + MSECCFG_MMWP = 1 << 1, | ||
60 | + MSECCFG_RLB = 1 << 2, | ||
61 | + MSECCFG_USEED = 1 << 8, | ||
62 | + MSECCFG_SSEED = 1 << 9 | ||
63 | } mseccfg_field_t; | ||
64 | |||
65 | typedef struct { | ||
66 | diff --git a/target/riscv/csr.c b/target/riscv/csr.c | ||
67 | index XXXXXXX..XXXXXXX 100644 | ||
68 | --- a/target/riscv/csr.c | ||
69 | +++ b/target/riscv/csr.c | ||
70 | @@ -XXX,XX +XXX,XX @@ | ||
71 | #include "qemu/main-loop.h" | ||
72 | #include "exec/exec-all.h" | ||
73 | #include "sysemu/cpu-timers.h" | ||
74 | +#include "qemu/guest-random.h" | ||
75 | +#include "qapi/error.h" | ||
76 | |||
77 | /* CSR function table public API */ | ||
78 | void riscv_get_csr_ops(int csrno, riscv_csr_operations *ops) | ||
79 | @@ -XXX,XX +XXX,XX @@ static RISCVException debug(CPURISCVState *env, int csrno) | ||
80 | } | 23 | } |
81 | #endif | 24 | #endif |
82 | 25 | ||
83 | +static RISCVException seed(CPURISCVState *env, int csrno) | 26 | -#if defined(CONFIG_KVM) |
27 | -static void riscv_host_cpu_init(Object *obj) | ||
28 | -{ | ||
29 | - CPURISCVState *env = &RISCV_CPU(obj)->env; | ||
30 | -#if defined(TARGET_RISCV32) | ||
31 | - set_misa(env, MXL_RV32, 0); | ||
32 | -#elif defined(TARGET_RISCV64) | ||
33 | - set_misa(env, MXL_RV64, 0); | ||
34 | -#endif | ||
35 | -} | ||
36 | -#endif /* CONFIG_KVM */ | ||
37 | - | ||
38 | static ObjectClass *riscv_cpu_class_by_name(const char *cpu_model) | ||
39 | { | ||
40 | ObjectClass *oc; | ||
41 | @@ -XXX,XX +XXX,XX @@ static const TypeInfo riscv_cpu_type_infos[] = { | ||
42 | }, | ||
43 | DEFINE_DYNAMIC_CPU(TYPE_RISCV_CPU_ANY, riscv_any_cpu_init), | ||
44 | DEFINE_DYNAMIC_CPU(TYPE_RISCV_CPU_MAX, riscv_max_cpu_init), | ||
45 | -#if defined(CONFIG_KVM) | ||
46 | - DEFINE_CPU(TYPE_RISCV_CPU_HOST, riscv_host_cpu_init), | ||
47 | -#endif | ||
48 | #if defined(TARGET_RISCV32) | ||
49 | DEFINE_DYNAMIC_CPU(TYPE_RISCV_CPU_BASE32, rv32_base_cpu_init), | ||
50 | DEFINE_CPU(TYPE_RISCV_CPU_IBEX, rv32_ibex_cpu_init), | ||
51 | diff --git a/target/riscv/kvm.c b/target/riscv/kvm.c | ||
52 | index XXXXXXX..XXXXXXX 100644 | ||
53 | --- a/target/riscv/kvm.c | ||
54 | +++ b/target/riscv/kvm.c | ||
55 | @@ -XXX,XX +XXX,XX @@ void kvm_riscv_aia_create(MachineState *machine, uint64_t group_shift, | ||
56 | |||
57 | kvm_msi_via_irqfd_allowed = kvm_irqfds_enabled(); | ||
58 | } | ||
59 | + | ||
60 | +static void riscv_host_cpu_init(Object *obj) | ||
84 | +{ | 61 | +{ |
85 | + RISCVCPU *cpu = env_archcpu(env); | 62 | + CPURISCVState *env = &RISCV_CPU(obj)->env; |
86 | + | 63 | + |
87 | + if (!cpu->cfg.ext_zkr) { | 64 | +#if defined(TARGET_RISCV32) |
88 | + return RISCV_EXCP_ILLEGAL_INST; | 65 | + env->misa_mxl_max = env->misa_mxl = MXL_RV32; |
89 | + } | 66 | +#elif defined(TARGET_RISCV64) |
90 | + | 67 | + env->misa_mxl_max = env->misa_mxl = MXL_RV64; |
91 | +#if !defined(CONFIG_USER_ONLY) | ||
92 | + /* | ||
93 | + * With a CSR read-write instruction: | ||
94 | + * 1) The seed CSR is always available in machine mode as normal. | ||
95 | + * 2) Attempted access to seed from virtual modes VS and VU always raises | ||
96 | + * an exception(virtual instruction exception only if mseccfg.sseed=1). | ||
97 | + * 3) Without the corresponding access control bit set to 1, any attempted | ||
98 | + * access to seed from U, S or HS modes will raise an illegal instruction | ||
99 | + * exception. | ||
100 | + */ | ||
101 | + if (env->priv == PRV_M) { | ||
102 | + return RISCV_EXCP_NONE; | ||
103 | + } else if (riscv_cpu_virt_enabled(env)) { | ||
104 | + if (env->mseccfg & MSECCFG_SSEED) { | ||
105 | + return RISCV_EXCP_VIRT_INSTRUCTION_FAULT; | ||
106 | + } else { | ||
107 | + return RISCV_EXCP_ILLEGAL_INST; | ||
108 | + } | ||
109 | + } else { | ||
110 | + if (env->priv == PRV_S && (env->mseccfg & MSECCFG_SSEED)) { | ||
111 | + return RISCV_EXCP_NONE; | ||
112 | + } else if (env->priv == PRV_U && (env->mseccfg & MSECCFG_USEED)) { | ||
113 | + return RISCV_EXCP_NONE; | ||
114 | + } else { | ||
115 | + return RISCV_EXCP_ILLEGAL_INST; | ||
116 | + } | ||
117 | + } | ||
118 | +#else | ||
119 | + return RISCV_EXCP_NONE; | ||
120 | +#endif | 68 | +#endif |
121 | +} | 69 | +} |
122 | + | 70 | + |
123 | /* User Floating-Point CSRs */ | 71 | +static const TypeInfo riscv_kvm_cpu_type_infos[] = { |
124 | static RISCVException read_fflags(CPURISCVState *env, int csrno, | 72 | + { |
125 | target_ulong *val) | 73 | + .name = TYPE_RISCV_CPU_HOST, |
126 | @@ -XXX,XX +XXX,XX @@ static RISCVException write_upmbase(CPURISCVState *env, int csrno, | 74 | + .parent = TYPE_RISCV_CPU, |
127 | 75 | + .instance_init = riscv_host_cpu_init, | |
128 | #endif | 76 | + } |
129 | 77 | +}; | |
130 | +/* Crypto Extension */ | ||
131 | +static RISCVException rmw_seed(CPURISCVState *env, int csrno, | ||
132 | + target_ulong *ret_value, | ||
133 | + target_ulong new_value, | ||
134 | + target_ulong write_mask) | ||
135 | +{ | ||
136 | + uint16_t random_v; | ||
137 | + Error *random_e = NULL; | ||
138 | + int random_r; | ||
139 | + target_ulong rval; | ||
140 | + | 78 | + |
141 | + random_r = qemu_guest_getrandom(&random_v, 2, &random_e); | 79 | +DEFINE_TYPES(riscv_kvm_cpu_type_infos) |
142 | + if (unlikely(random_r < 0)) { | ||
143 | + /* | ||
144 | + * Failed, for unknown reasons in the crypto subsystem. | ||
145 | + * The best we can do is log the reason and return a | ||
146 | + * failure indication to the guest. There is no reason | ||
147 | + * we know to expect the failure to be transitory, so | ||
148 | + * indicate DEAD to avoid having the guest spin on WAIT. | ||
149 | + */ | ||
150 | + qemu_log_mask(LOG_UNIMP, "%s: Crypto failure: %s", | ||
151 | + __func__, error_get_pretty(random_e)); | ||
152 | + error_free(random_e); | ||
153 | + rval = SEED_OPST_DEAD; | ||
154 | + } else { | ||
155 | + rval = random_v | SEED_OPST_ES16; | ||
156 | + } | ||
157 | + | ||
158 | + if (ret_value) { | ||
159 | + *ret_value = rval; | ||
160 | + } | ||
161 | + | ||
162 | + return RISCV_EXCP_NONE; | ||
163 | +} | ||
164 | + | ||
165 | /* | ||
166 | * riscv_csrrw - read and/or update control and status register | ||
167 | * | ||
168 | @@ -XXX,XX +XXX,XX @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = { | ||
169 | [CSR_TIME] = { "time", ctr, read_time }, | ||
170 | [CSR_TIMEH] = { "timeh", ctr32, read_timeh }, | ||
171 | |||
172 | + /* Crypto Extension */ | ||
173 | + [CSR_SEED] = { "seed", seed, NULL, NULL, rmw_seed }, | ||
174 | + | ||
175 | #if !defined(CONFIG_USER_ONLY) | ||
176 | /* Machine Timers and Counters */ | ||
177 | [CSR_MCYCLE] = { "mcycle", any, read_instret }, | ||
178 | diff --git a/target/riscv/op_helper.c b/target/riscv/op_helper.c | ||
179 | index XXXXXXX..XXXXXXX 100644 | ||
180 | --- a/target/riscv/op_helper.c | ||
181 | +++ b/target/riscv/op_helper.c | ||
182 | @@ -XXX,XX +XXX,XX @@ void helper_raise_exception(CPURISCVState *env, uint32_t exception) | ||
183 | |||
184 | target_ulong helper_csrr(CPURISCVState *env, int csr) | ||
185 | { | ||
186 | + /* | ||
187 | + * The seed CSR must be accessed with a read-write instruction. A | ||
188 | + * read-only instruction such as CSRRS/CSRRC with rs1=x0 or CSRRSI/ | ||
189 | + * CSRRCI with uimm=0 will raise an illegal instruction exception. | ||
190 | + */ | ||
191 | + if (csr == CSR_SEED) { | ||
192 | + riscv_raise_exception(env, RISCV_EXCP_ILLEGAL_INST, GETPC()); | ||
193 | + } | ||
194 | + | ||
195 | target_ulong val = 0; | ||
196 | RISCVException ret = riscv_csrrw(env, csr, &val, 0, 0); | ||
197 | |||
198 | -- | 80 | -- |
199 | 2.35.1 | 81 | 2.41.0 |
82 | |||
83 | diff view generated by jsdifflib |
1 | From: Weiwei Li <liweiwei@iscas.ac.cn> | 1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
---|---|---|---|
2 | 2 | ||
3 | Signed-off-by: Weiwei Li <liweiwei@iscas.ac.cn> | 3 | We'll need to export these arrays to the accelerator classes in the next |
4 | Signed-off-by: Junqiang Wang <wangjunqiang@iscas.ac.cn> | 4 | patches. Mark them as 'const' now because they should not be modified at |
5 | runtime. | ||
6 | |||
7 | Note that 'riscv_cpu_options' will also be exported, but can't be marked | ||
8 | as 'const', because the properties are changed via | ||
9 | qdev_property_add_static(). | ||
10 | |||
11 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
12 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> | ||
13 | Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com> | ||
5 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 14 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
6 | Message-Id: <20220423023510.30794-15-liweiwei@iscas.ac.cn> | 15 | Message-ID: <20230925175709.35696-8-dbarboza@ventanamicro.com> |
7 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 16 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
8 | --- | 17 | --- |
9 | target/riscv/cpu.c | 13 +++++++++++++ | 18 | target/riscv/cpu.c | 22 +++++++++++++--------- |
10 | 1 file changed, 13 insertions(+) | 19 | 1 file changed, 13 insertions(+), 9 deletions(-) |
11 | 20 | ||
12 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | 21 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c |
13 | index XXXXXXX..XXXXXXX 100644 | 22 | index XXXXXXX..XXXXXXX 100644 |
14 | --- a/target/riscv/cpu.c | 23 | --- a/target/riscv/cpu.c |
15 | +++ b/target/riscv/cpu.c | 24 | +++ b/target/riscv/cpu.c |
16 | @@ -XXX,XX +XXX,XX @@ static Property riscv_cpu_properties[] = { | 25 | @@ -XXX,XX +XXX,XX @@ typedef struct RISCVCPUMultiExtConfig { |
17 | DEFINE_PROP_BOOL("zba", RISCVCPU, cfg.ext_zba, true), | 26 | {.name = _name, .offset = CPU_CFG_OFFSET(_prop), \ |
18 | DEFINE_PROP_BOOL("zbb", RISCVCPU, cfg.ext_zbb, true), | 27 | .enabled = _defval} |
19 | DEFINE_PROP_BOOL("zbc", RISCVCPU, cfg.ext_zbc, true), | 28 | |
20 | + DEFINE_PROP_BOOL("zbkb", RISCVCPU, cfg.ext_zbkb, false), | 29 | -static RISCVCPUMultiExtConfig riscv_cpu_extensions[] = { |
21 | + DEFINE_PROP_BOOL("zbkc", RISCVCPU, cfg.ext_zbkc, false), | 30 | +static const RISCVCPUMultiExtConfig riscv_cpu_extensions[] = { |
22 | + DEFINE_PROP_BOOL("zbkx", RISCVCPU, cfg.ext_zbkx, false), | 31 | /* Defaults for standard extensions */ |
23 | DEFINE_PROP_BOOL("zbs", RISCVCPU, cfg.ext_zbs, true), | 32 | MULTI_EXT_CFG_BOOL("sscofpmf", ext_sscofpmf, false), |
24 | + DEFINE_PROP_BOOL("zk", RISCVCPU, cfg.ext_zk, false), | 33 | MULTI_EXT_CFG_BOOL("Zifencei", ext_ifencei, true), |
25 | + DEFINE_PROP_BOOL("zkn", RISCVCPU, cfg.ext_zkn, false), | 34 | @@ -XXX,XX +XXX,XX @@ static RISCVCPUMultiExtConfig riscv_cpu_extensions[] = { |
26 | + DEFINE_PROP_BOOL("zknd", RISCVCPU, cfg.ext_zknd, false), | 35 | DEFINE_PROP_END_OF_LIST(), |
27 | + DEFINE_PROP_BOOL("zkne", RISCVCPU, cfg.ext_zkne, false), | 36 | }; |
28 | + DEFINE_PROP_BOOL("zknh", RISCVCPU, cfg.ext_zknh, false), | 37 | |
29 | + DEFINE_PROP_BOOL("zkr", RISCVCPU, cfg.ext_zkr, false), | 38 | -static RISCVCPUMultiExtConfig riscv_cpu_vendor_exts[] = { |
30 | + DEFINE_PROP_BOOL("zks", RISCVCPU, cfg.ext_zks, false), | 39 | +static const RISCVCPUMultiExtConfig riscv_cpu_vendor_exts[] = { |
31 | + DEFINE_PROP_BOOL("zksed", RISCVCPU, cfg.ext_zksed, false), | 40 | MULTI_EXT_CFG_BOOL("xtheadba", ext_xtheadba, false), |
32 | + DEFINE_PROP_BOOL("zksh", RISCVCPU, cfg.ext_zksh, false), | 41 | MULTI_EXT_CFG_BOOL("xtheadbb", ext_xtheadbb, false), |
33 | + DEFINE_PROP_BOOL("zkt", RISCVCPU, cfg.ext_zkt, false), | 42 | MULTI_EXT_CFG_BOOL("xtheadbs", ext_xtheadbs, false), |
34 | 43 | @@ -XXX,XX +XXX,XX @@ static RISCVCPUMultiExtConfig riscv_cpu_vendor_exts[] = { | |
35 | DEFINE_PROP_BOOL("zdinx", RISCVCPU, cfg.ext_zdinx, false), | 44 | }; |
36 | DEFINE_PROP_BOOL("zfinx", RISCVCPU, cfg.ext_zfinx, false), | 45 | |
46 | /* These are experimental so mark with 'x-' */ | ||
47 | -static RISCVCPUMultiExtConfig riscv_cpu_experimental_exts[] = { | ||
48 | +static const RISCVCPUMultiExtConfig riscv_cpu_experimental_exts[] = { | ||
49 | /* ePMP 0.9.3 */ | ||
50 | MULTI_EXT_CFG_BOOL("x-epmp", epmp, false), | ||
51 | MULTI_EXT_CFG_BOOL("x-smaia", ext_smaia, false), | ||
52 | @@ -XXX,XX +XXX,XX @@ static void cpu_get_multi_ext_cfg(Object *obj, Visitor *v, const char *name, | ||
53 | } | ||
54 | |||
55 | static void cpu_add_multi_ext_prop(Object *cpu_obj, | ||
56 | - RISCVCPUMultiExtConfig *multi_cfg) | ||
57 | + const RISCVCPUMultiExtConfig *multi_cfg) | ||
58 | { | ||
59 | object_property_add(cpu_obj, multi_cfg->name, "bool", | ||
60 | cpu_get_multi_ext_cfg, | ||
61 | @@ -XXX,XX +XXX,XX @@ static void cpu_add_multi_ext_prop(Object *cpu_obj, | ||
62 | } | ||
63 | |||
64 | static void riscv_cpu_add_multiext_prop_array(Object *obj, | ||
65 | - RISCVCPUMultiExtConfig *array) | ||
66 | + const RISCVCPUMultiExtConfig *array) | ||
67 | { | ||
68 | + const RISCVCPUMultiExtConfig *prop; | ||
69 | + | ||
70 | g_assert(array); | ||
71 | |||
72 | - for (RISCVCPUMultiExtConfig *prop = array; prop && prop->name; prop++) { | ||
73 | + for (prop = array; prop && prop->name; prop++) { | ||
74 | cpu_add_multi_ext_prop(obj, prop); | ||
75 | } | ||
76 | } | ||
77 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_add_kvm_unavail_prop(Object *obj, const char *prop_name) | ||
78 | } | ||
79 | |||
80 | static void riscv_cpu_add_kvm_unavail_prop_array(Object *obj, | ||
81 | - RISCVCPUMultiExtConfig *array) | ||
82 | + const RISCVCPUMultiExtConfig *array) | ||
83 | { | ||
84 | + const RISCVCPUMultiExtConfig *prop; | ||
85 | + | ||
86 | g_assert(array); | ||
87 | |||
88 | - for (RISCVCPUMultiExtConfig *prop = array; prop && prop->name; prop++) { | ||
89 | + for (prop = array; prop && prop->name; prop++) { | ||
90 | riscv_cpu_add_kvm_unavail_prop(obj, prop->name); | ||
91 | } | ||
92 | } | ||
93 | @@ -XXX,XX +XXX,XX @@ static void riscv_init_max_cpu_extensions(Object *obj) | ||
94 | { | ||
95 | RISCVCPU *cpu = RISCV_CPU(obj); | ||
96 | CPURISCVState *env = &cpu->env; | ||
97 | - RISCVCPUMultiExtConfig *prop; | ||
98 | + const RISCVCPUMultiExtConfig *prop; | ||
99 | |||
100 | /* Enable RVG, RVJ and RVV that are disabled by default */ | ||
101 | set_misa(env, env->misa_mxl, env->misa_ext | RVG | RVJ | RVV); | ||
37 | -- | 102 | -- |
38 | 2.35.1 | 103 | 2.41.0 | diff view generated by jsdifflib |
1 | From: Weiwei Li <liweiwei@iscas.ac.cn> | 1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
---|---|---|---|
2 | 2 | ||
3 | - add sha256sig0, sha256sig1, sha256sum0 and sha256sum1 instructions | 3 | We'll introduce the KVM accelerator class with a 'cpu_instance_init' |
4 | 4 | implementation that is going to be invoked during the common | |
5 | Co-authored-by: Zewen Ye <lustrew@foxmail.com> | 5 | riscv_cpu_post_init() (via accel_cpu_instance_init()). This |
6 | Signed-off-by: Weiwei Li <liweiwei@iscas.ac.cn> | 6 | instance_init will execute KVM exclusive code that TCG doesn't care |
7 | Signed-off-by: Junqiang Wang <wangjunqiang@iscas.ac.cn> | 7 | about, such as adding KVM specific properties, initing registers using a |
8 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 8 | KVM scratch CPU and so on. |
9 | |||
10 | The core of the forementioned cpu_instance_init impl is the current | ||
11 | riscv_cpu_add_kvm_properties() that is being used by the common code via | ||
12 | riscv_cpu_add_user_properties() in cpu.c. Move it to kvm.c, together | ||
13 | will all the relevant artifacts, exporting and renaming it to | ||
14 | kvm_riscv_cpu_add_kvm_properties() so cpu.c can keep using it for now. | ||
15 | |||
16 | To make this work we'll need to export riscv_cpu_extensions, | ||
17 | riscv_cpu_vendor_exts and riscv_cpu_experimental_exts from cpu.c as | ||
18 | well. The TCG accelerator will also need to access those in the near | ||
19 | future so this export will benefit us in the long run. | ||
20 | |||
21 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
22 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> | ||
23 | Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com> | ||
9 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 24 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
10 | Message-Id: <20220423023510.30794-9-liweiwei@iscas.ac.cn> | 25 | Message-ID: <20230925175709.35696-9-dbarboza@ventanamicro.com> |
11 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 26 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
12 | --- | 27 | --- |
13 | target/riscv/insn32.decode | 5 +++ | 28 | target/riscv/cpu.h | 14 +++++++ |
14 | target/riscv/insn_trans/trans_rvk.c.inc | 55 +++++++++++++++++++++++++ | 29 | target/riscv/kvm_riscv.h | 3 -- |
15 | 2 files changed, 60 insertions(+) | 30 | target/riscv/cpu.c | 85 +++------------------------------------- |
16 | 31 | target/riscv/kvm.c | 68 +++++++++++++++++++++++++++++++- | |
17 | diff --git a/target/riscv/insn32.decode b/target/riscv/insn32.decode | 32 | 4 files changed, 86 insertions(+), 84 deletions(-) |
33 | |||
34 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h | ||
18 | index XXXXXXX..XXXXXXX 100644 | 35 | index XXXXXXX..XXXXXXX 100644 |
19 | --- a/target/riscv/insn32.decode | 36 | --- a/target/riscv/cpu.h |
20 | +++ b/target/riscv/insn32.decode | 37 | +++ b/target/riscv/cpu.h |
21 | @@ -XXX,XX +XXX,XX @@ aes64esm 00 11011 ..... ..... 000 ..... 0110011 @r | 38 | @@ -XXX,XX +XXX,XX @@ |
22 | # *** RV64 Zkne/zknd Standard Extension *** | 39 | |
23 | aes64ks2 01 11111 ..... ..... 000 ..... 0110011 @r | 40 | #include "hw/core/cpu.h" |
24 | aes64ks1i 00 11000 1.... ..... 001 ..... 0010011 @i_aes | 41 | #include "hw/registerfields.h" |
25 | +# *** RV32 Zknh Standard Extension *** | 42 | +#include "hw/qdev-properties.h" |
26 | +sha256sig0 00 01000 00010 ..... 001 ..... 0010011 @r2 | 43 | #include "exec/cpu-defs.h" |
27 | +sha256sig1 00 01000 00011 ..... 001 ..... 0010011 @r2 | 44 | #include "qemu/cpu-float.h" |
28 | +sha256sum0 00 01000 00000 ..... 001 ..... 0010011 @r2 | 45 | #include "qom/object.h" |
29 | +sha256sum1 00 01000 00001 ..... 001 ..... 0010011 @r2 | 46 | @@ -XXX,XX +XXX,XX @@ bool isa_ext_is_enabled(RISCVCPU *cpu, uint32_t ext_offset); |
30 | diff --git a/target/riscv/insn_trans/trans_rvk.c.inc b/target/riscv/insn_trans/trans_rvk.c.inc | 47 | int cpu_cfg_ext_get_min_version(uint32_t ext_offset); |
48 | void riscv_cpu_disable_priv_spec_isa_exts(RISCVCPU *cpu); | ||
49 | |||
50 | +typedef struct RISCVCPUMultiExtConfig { | ||
51 | + const char *name; | ||
52 | + uint32_t offset; | ||
53 | + bool enabled; | ||
54 | +} RISCVCPUMultiExtConfig; | ||
55 | + | ||
56 | +extern const RISCVCPUMultiExtConfig riscv_cpu_extensions[]; | ||
57 | +extern const RISCVCPUMultiExtConfig riscv_cpu_vendor_exts[]; | ||
58 | +extern const RISCVCPUMultiExtConfig riscv_cpu_experimental_exts[]; | ||
59 | +extern Property riscv_cpu_options[]; | ||
60 | + | ||
61 | +void riscv_cpu_add_misa_properties(Object *cpu_obj); | ||
62 | + | ||
63 | /* CSR function table */ | ||
64 | extern riscv_csr_operations csr_ops[CSR_TABLE_SIZE]; | ||
65 | |||
66 | diff --git a/target/riscv/kvm_riscv.h b/target/riscv/kvm_riscv.h | ||
31 | index XXXXXXX..XXXXXXX 100644 | 67 | index XXXXXXX..XXXXXXX 100644 |
32 | --- a/target/riscv/insn_trans/trans_rvk.c.inc | 68 | --- a/target/riscv/kvm_riscv.h |
33 | +++ b/target/riscv/insn_trans/trans_rvk.c.inc | 69 | +++ b/target/riscv/kvm_riscv.h |
34 | @@ -XXX,XX +XXX,XX @@ | 70 | @@ -XXX,XX +XXX,XX @@ |
35 | } \ | 71 | #ifndef QEMU_KVM_RISCV_H |
36 | } while (0) | 72 | #define QEMU_KVM_RISCV_H |
37 | 73 | ||
38 | +#define REQUIRE_ZKNH(ctx) do { \ | 74 | -/* Temporarily implemented in cpu.c */ |
39 | + if (!ctx->cfg_ptr->ext_zknh) { \ | 75 | void kvm_riscv_cpu_add_kvm_properties(Object *obj); |
40 | + return false; \ | 76 | - |
41 | + } \ | 77 | -void kvm_riscv_init_user_properties(Object *cpu_obj); |
42 | +} while (0) | 78 | void kvm_riscv_reset_vcpu(RISCVCPU *cpu); |
43 | + | 79 | void kvm_riscv_set_irq(RISCVCPU *cpu, int irq, int level); |
44 | static bool gen_aes32_sm4(DisasContext *ctx, arg_k_aes *a, | 80 | void kvm_riscv_aia_create(MachineState *machine, uint64_t group_shift, |
45 | void (*func)(TCGv, TCGv, TCGv, TCGv)) | 81 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c |
82 | index XXXXXXX..XXXXXXX 100644 | ||
83 | --- a/target/riscv/cpu.c | ||
84 | +++ b/target/riscv/cpu.c | ||
85 | @@ -XXX,XX +XXX,XX @@ static RISCVCPUMisaExtConfig misa_ext_cfgs[] = { | ||
86 | * change MISA bits during realize() (RVG enables MISA | ||
87 | * bits but the user is warned about it). | ||
88 | */ | ||
89 | -static void riscv_cpu_add_misa_properties(Object *cpu_obj) | ||
90 | +void riscv_cpu_add_misa_properties(Object *cpu_obj) | ||
46 | { | 91 | { |
47 | @@ -XXX,XX +XXX,XX @@ static bool trans_aes64im(DisasContext *ctx, arg_aes64im *a) | 92 | int i; |
48 | REQUIRE_ZKND(ctx); | 93 | |
49 | return gen_unary(ctx, a, EXT_NONE, gen_helper_aes64im); | 94 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_add_misa_properties(Object *cpu_obj) |
50 | } | 95 | } |
51 | + | 96 | } |
52 | +static bool gen_sha256(DisasContext *ctx, arg_r2 *a, DisasExtend ext, | 97 | |
53 | + void (*func)(TCGv_i32, TCGv_i32, int32_t), | 98 | -typedef struct RISCVCPUMultiExtConfig { |
54 | + int32_t num1, int32_t num2, int32_t num3) | 99 | - const char *name; |
100 | - uint32_t offset; | ||
101 | - bool enabled; | ||
102 | -} RISCVCPUMultiExtConfig; | ||
103 | - | ||
104 | #define MULTI_EXT_CFG_BOOL(_name, _prop, _defval) \ | ||
105 | {.name = _name, .offset = CPU_CFG_OFFSET(_prop), \ | ||
106 | .enabled = _defval} | ||
107 | |||
108 | -static const RISCVCPUMultiExtConfig riscv_cpu_extensions[] = { | ||
109 | +const RISCVCPUMultiExtConfig riscv_cpu_extensions[] = { | ||
110 | /* Defaults for standard extensions */ | ||
111 | MULTI_EXT_CFG_BOOL("sscofpmf", ext_sscofpmf, false), | ||
112 | MULTI_EXT_CFG_BOOL("Zifencei", ext_ifencei, true), | ||
113 | @@ -XXX,XX +XXX,XX @@ static const RISCVCPUMultiExtConfig riscv_cpu_extensions[] = { | ||
114 | DEFINE_PROP_END_OF_LIST(), | ||
115 | }; | ||
116 | |||
117 | -static const RISCVCPUMultiExtConfig riscv_cpu_vendor_exts[] = { | ||
118 | +const RISCVCPUMultiExtConfig riscv_cpu_vendor_exts[] = { | ||
119 | MULTI_EXT_CFG_BOOL("xtheadba", ext_xtheadba, false), | ||
120 | MULTI_EXT_CFG_BOOL("xtheadbb", ext_xtheadbb, false), | ||
121 | MULTI_EXT_CFG_BOOL("xtheadbs", ext_xtheadbs, false), | ||
122 | @@ -XXX,XX +XXX,XX @@ static const RISCVCPUMultiExtConfig riscv_cpu_vendor_exts[] = { | ||
123 | }; | ||
124 | |||
125 | /* These are experimental so mark with 'x-' */ | ||
126 | -static const RISCVCPUMultiExtConfig riscv_cpu_experimental_exts[] = { | ||
127 | +const RISCVCPUMultiExtConfig riscv_cpu_experimental_exts[] = { | ||
128 | /* ePMP 0.9.3 */ | ||
129 | MULTI_EXT_CFG_BOOL("x-epmp", epmp, false), | ||
130 | MULTI_EXT_CFG_BOOL("x-smaia", ext_smaia, false), | ||
131 | @@ -XXX,XX +XXX,XX @@ static const RISCVCPUMultiExtConfig riscv_cpu_experimental_exts[] = { | ||
132 | DEFINE_PROP_END_OF_LIST(), | ||
133 | }; | ||
134 | |||
135 | -static Property riscv_cpu_options[] = { | ||
136 | +Property riscv_cpu_options[] = { | ||
137 | DEFINE_PROP_UINT8("pmu-num", RISCVCPU, cfg.pmu_num, 16), | ||
138 | |||
139 | DEFINE_PROP_BOOL("mmu", RISCVCPU, cfg.mmu, true), | ||
140 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_add_multiext_prop_array(Object *obj, | ||
141 | } | ||
142 | } | ||
143 | |||
144 | -#ifdef CONFIG_KVM | ||
145 | -static void cpu_set_cfg_unavailable(Object *obj, Visitor *v, | ||
146 | - const char *name, | ||
147 | - void *opaque, Error **errp) | ||
148 | -{ | ||
149 | - const char *propname = opaque; | ||
150 | - bool value; | ||
151 | - | ||
152 | - if (!visit_type_bool(v, name, &value, errp)) { | ||
153 | - return; | ||
154 | - } | ||
155 | - | ||
156 | - if (value) { | ||
157 | - error_setg(errp, "extension %s is not available with KVM", | ||
158 | - propname); | ||
159 | - } | ||
160 | -} | ||
161 | - | ||
162 | -static void riscv_cpu_add_kvm_unavail_prop(Object *obj, const char *prop_name) | ||
163 | -{ | ||
164 | - /* Check if KVM created the property already */ | ||
165 | - if (object_property_find(obj, prop_name)) { | ||
166 | - return; | ||
167 | - } | ||
168 | - | ||
169 | - /* | ||
170 | - * Set the default to disabled for every extension | ||
171 | - * unknown to KVM and error out if the user attempts | ||
172 | - * to enable any of them. | ||
173 | - */ | ||
174 | - object_property_add(obj, prop_name, "bool", | ||
175 | - NULL, cpu_set_cfg_unavailable, | ||
176 | - NULL, (void *)prop_name); | ||
177 | -} | ||
178 | - | ||
179 | -static void riscv_cpu_add_kvm_unavail_prop_array(Object *obj, | ||
180 | - const RISCVCPUMultiExtConfig *array) | ||
181 | -{ | ||
182 | - const RISCVCPUMultiExtConfig *prop; | ||
183 | - | ||
184 | - g_assert(array); | ||
185 | - | ||
186 | - for (prop = array; prop && prop->name; prop++) { | ||
187 | - riscv_cpu_add_kvm_unavail_prop(obj, prop->name); | ||
188 | - } | ||
189 | -} | ||
190 | - | ||
191 | -void kvm_riscv_cpu_add_kvm_properties(Object *obj) | ||
192 | -{ | ||
193 | - Property *prop; | ||
194 | - DeviceState *dev = DEVICE(obj); | ||
195 | - | ||
196 | - kvm_riscv_init_user_properties(obj); | ||
197 | - riscv_cpu_add_misa_properties(obj); | ||
198 | - | ||
199 | - riscv_cpu_add_kvm_unavail_prop_array(obj, riscv_cpu_extensions); | ||
200 | - riscv_cpu_add_kvm_unavail_prop_array(obj, riscv_cpu_vendor_exts); | ||
201 | - riscv_cpu_add_kvm_unavail_prop_array(obj, riscv_cpu_experimental_exts); | ||
202 | - | ||
203 | - for (prop = riscv_cpu_options; prop && prop->name; prop++) { | ||
204 | - /* Check if KVM created the property already */ | ||
205 | - if (object_property_find(obj, prop->name)) { | ||
206 | - continue; | ||
207 | - } | ||
208 | - qdev_property_add_static(dev, prop); | ||
209 | - } | ||
210 | -} | ||
211 | -#endif | ||
212 | - | ||
213 | /* | ||
214 | * Add CPU properties with user-facing flags. | ||
215 | * | ||
216 | diff --git a/target/riscv/kvm.c b/target/riscv/kvm.c | ||
217 | index XXXXXXX..XXXXXXX 100644 | ||
218 | --- a/target/riscv/kvm.c | ||
219 | +++ b/target/riscv/kvm.c | ||
220 | @@ -XXX,XX +XXX,XX @@ static void kvm_riscv_update_cpu_cfg_isa_ext(RISCVCPU *cpu, CPUState *cs) | ||
221 | } | ||
222 | } | ||
223 | |||
224 | +static void cpu_set_cfg_unavailable(Object *obj, Visitor *v, | ||
225 | + const char *name, | ||
226 | + void *opaque, Error **errp) | ||
55 | +{ | 227 | +{ |
56 | + TCGv dest = dest_gpr(ctx, a->rd); | 228 | + const char *propname = opaque; |
57 | + TCGv src1 = get_gpr(ctx, a->rs1, ext); | 229 | + bool value; |
58 | + TCGv_i32 t0 = tcg_temp_new_i32(); | 230 | + |
59 | + TCGv_i32 t1 = tcg_temp_new_i32(); | 231 | + if (!visit_type_bool(v, name, &value, errp)) { |
60 | + TCGv_i32 t2 = tcg_temp_new_i32(); | 232 | + return; |
61 | + | 233 | + } |
62 | + tcg_gen_trunc_tl_i32(t0, src1); | 234 | + |
63 | + tcg_gen_rotri_i32(t1, t0, num1); | 235 | + if (value) { |
64 | + tcg_gen_rotri_i32(t2, t0, num2); | 236 | + error_setg(errp, "extension %s is not available with KVM", |
65 | + tcg_gen_xor_i32(t1, t1, t2); | 237 | + propname); |
66 | + func(t2, t0, num3); | 238 | + } |
67 | + tcg_gen_xor_i32(t1, t1, t2); | ||
68 | + tcg_gen_ext_i32_tl(dest, t1); | ||
69 | + | ||
70 | + gen_set_gpr(ctx, a->rd, dest); | ||
71 | + tcg_temp_free_i32(t0); | ||
72 | + tcg_temp_free_i32(t1); | ||
73 | + tcg_temp_free_i32(t2); | ||
74 | + return true; | ||
75 | +} | 239 | +} |
76 | + | 240 | + |
77 | +static bool trans_sha256sig0(DisasContext *ctx, arg_sha256sig0 *a) | 241 | +static void riscv_cpu_add_kvm_unavail_prop(Object *obj, const char *prop_name) |
78 | +{ | 242 | +{ |
79 | + REQUIRE_ZKNH(ctx); | 243 | + /* Check if KVM created the property already */ |
80 | + return gen_sha256(ctx, a, EXT_NONE, tcg_gen_shri_i32, 7, 18, 3); | 244 | + if (object_property_find(obj, prop_name)) { |
245 | + return; | ||
246 | + } | ||
247 | + | ||
248 | + /* | ||
249 | + * Set the default to disabled for every extension | ||
250 | + * unknown to KVM and error out if the user attempts | ||
251 | + * to enable any of them. | ||
252 | + */ | ||
253 | + object_property_add(obj, prop_name, "bool", | ||
254 | + NULL, cpu_set_cfg_unavailable, | ||
255 | + NULL, (void *)prop_name); | ||
81 | +} | 256 | +} |
82 | + | 257 | + |
83 | +static bool trans_sha256sig1(DisasContext *ctx, arg_sha256sig1 *a) | 258 | +static void riscv_cpu_add_kvm_unavail_prop_array(Object *obj, |
259 | + const RISCVCPUMultiExtConfig *array) | ||
84 | +{ | 260 | +{ |
85 | + REQUIRE_ZKNH(ctx); | 261 | + const RISCVCPUMultiExtConfig *prop; |
86 | + return gen_sha256(ctx, a, EXT_NONE, tcg_gen_shri_i32, 17, 19, 10); | 262 | + |
263 | + g_assert(array); | ||
264 | + | ||
265 | + for (prop = array; prop && prop->name; prop++) { | ||
266 | + riscv_cpu_add_kvm_unavail_prop(obj, prop->name); | ||
267 | + } | ||
87 | +} | 268 | +} |
88 | + | 269 | + |
89 | +static bool trans_sha256sum0(DisasContext *ctx, arg_sha256sum0 *a) | 270 | static void kvm_riscv_add_cpu_user_properties(Object *cpu_obj) |
271 | { | ||
272 | int i; | ||
273 | @@ -XXX,XX +XXX,XX @@ static void kvm_riscv_init_multiext_cfg(RISCVCPU *cpu, KVMScratchCPU *kvmcpu) | ||
274 | } | ||
275 | } | ||
276 | |||
277 | -void kvm_riscv_init_user_properties(Object *cpu_obj) | ||
278 | +static void riscv_init_user_properties(Object *cpu_obj) | ||
279 | { | ||
280 | RISCVCPU *cpu = RISCV_CPU(cpu_obj); | ||
281 | KVMScratchCPU kvmcpu; | ||
282 | @@ -XXX,XX +XXX,XX @@ void kvm_riscv_aia_create(MachineState *machine, uint64_t group_shift, | ||
283 | kvm_msi_via_irqfd_allowed = kvm_irqfds_enabled(); | ||
284 | } | ||
285 | |||
286 | +void kvm_riscv_cpu_add_kvm_properties(Object *obj) | ||
90 | +{ | 287 | +{ |
91 | + REQUIRE_ZKNH(ctx); | 288 | + DeviceState *dev = DEVICE(obj); |
92 | + return gen_sha256(ctx, a, EXT_NONE, tcg_gen_rotri_i32, 2, 13, 22); | 289 | + |
290 | + riscv_init_user_properties(obj); | ||
291 | + riscv_cpu_add_misa_properties(obj); | ||
292 | + | ||
293 | + riscv_cpu_add_kvm_unavail_prop_array(obj, riscv_cpu_extensions); | ||
294 | + riscv_cpu_add_kvm_unavail_prop_array(obj, riscv_cpu_vendor_exts); | ||
295 | + riscv_cpu_add_kvm_unavail_prop_array(obj, riscv_cpu_experimental_exts); | ||
296 | + | ||
297 | + for (Property *prop = riscv_cpu_options; prop && prop->name; prop++) { | ||
298 | + /* Check if KVM created the property already */ | ||
299 | + if (object_property_find(obj, prop->name)) { | ||
300 | + continue; | ||
301 | + } | ||
302 | + qdev_property_add_static(dev, prop); | ||
303 | + } | ||
93 | +} | 304 | +} |
94 | + | 305 | + |
95 | +static bool trans_sha256sum1(DisasContext *ctx, arg_sha256sum1 *a) | 306 | static void riscv_host_cpu_init(Object *obj) |
96 | +{ | 307 | { |
97 | + REQUIRE_ZKNH(ctx); | 308 | CPURISCVState *env = &RISCV_CPU(obj)->env; |
98 | + return gen_sha256(ctx, a, EXT_NONE, tcg_gen_rotri_i32, 6, 11, 25); | ||
99 | +} | ||
100 | -- | 309 | -- |
101 | 2.35.1 | 310 | 2.41.0 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
1 | 2 | ||
3 | This function is used for both accelerators. Make it public, and call it | ||
4 | from kvm_riscv_cpu_add_kvm_properties(). This will make it easier to | ||
5 | split KVM specific code for the KVM accelerator class in the next patch. | ||
6 | |||
7 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
8 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> | ||
9 | Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com> | ||
10 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
11 | Message-ID: <20230925175709.35696-10-dbarboza@ventanamicro.com> | ||
12 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
13 | --- | ||
14 | target/riscv/cpu.h | 1 + | ||
15 | target/riscv/cpu.c | 5 ++--- | ||
16 | target/riscv/kvm.c | 1 + | ||
17 | 3 files changed, 4 insertions(+), 3 deletions(-) | ||
18 | |||
19 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h | ||
20 | index XXXXXXX..XXXXXXX 100644 | ||
21 | --- a/target/riscv/cpu.h | ||
22 | +++ b/target/riscv/cpu.h | ||
23 | @@ -XXX,XX +XXX,XX @@ extern const RISCVCPUMultiExtConfig riscv_cpu_experimental_exts[]; | ||
24 | extern Property riscv_cpu_options[]; | ||
25 | |||
26 | void riscv_cpu_add_misa_properties(Object *cpu_obj); | ||
27 | +void riscv_add_satp_mode_properties(Object *obj); | ||
28 | |||
29 | /* CSR function table */ | ||
30 | extern riscv_csr_operations csr_ops[CSR_TABLE_SIZE]; | ||
31 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | ||
32 | index XXXXXXX..XXXXXXX 100644 | ||
33 | --- a/target/riscv/cpu.c | ||
34 | +++ b/target/riscv/cpu.c | ||
35 | @@ -XXX,XX +XXX,XX @@ static void cpu_riscv_set_satp(Object *obj, Visitor *v, const char *name, | ||
36 | satp_map->init |= 1 << satp; | ||
37 | } | ||
38 | |||
39 | -static void riscv_add_satp_mode_properties(Object *obj) | ||
40 | +void riscv_add_satp_mode_properties(Object *obj) | ||
41 | { | ||
42 | RISCVCPU *cpu = RISCV_CPU(obj); | ||
43 | |||
44 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_add_multiext_prop_array(Object *obj, | ||
45 | static void riscv_cpu_add_user_properties(Object *obj) | ||
46 | { | ||
47 | #ifndef CONFIG_USER_ONLY | ||
48 | - riscv_add_satp_mode_properties(obj); | ||
49 | - | ||
50 | if (kvm_enabled()) { | ||
51 | kvm_riscv_cpu_add_kvm_properties(obj); | ||
52 | return; | ||
53 | } | ||
54 | + riscv_add_satp_mode_properties(obj); | ||
55 | #endif | ||
56 | |||
57 | riscv_cpu_add_misa_properties(obj); | ||
58 | diff --git a/target/riscv/kvm.c b/target/riscv/kvm.c | ||
59 | index XXXXXXX..XXXXXXX 100644 | ||
60 | --- a/target/riscv/kvm.c | ||
61 | +++ b/target/riscv/kvm.c | ||
62 | @@ -XXX,XX +XXX,XX @@ void kvm_riscv_cpu_add_kvm_properties(Object *obj) | ||
63 | DeviceState *dev = DEVICE(obj); | ||
64 | |||
65 | riscv_init_user_properties(obj); | ||
66 | + riscv_add_satp_mode_properties(obj); | ||
67 | riscv_cpu_add_misa_properties(obj); | ||
68 | |||
69 | riscv_cpu_add_kvm_unavail_prop_array(obj, riscv_cpu_extensions); | ||
70 | -- | ||
71 | 2.41.0 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
1 | 2 | ||
3 | This file is not needed for some time now. Both kvm_riscv_reset_vcpu() | ||
4 | and kvm_riscv_set_irq() have public declarations in kvm_riscv.h and are | ||
5 | wrapped in 'if kvm_enabled()' blocks that the compiler will rip it out | ||
6 | in non-KVM builds. | ||
7 | |||
8 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
9 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
10 | Message-ID: <20230925175709.35696-11-dbarboza@ventanamicro.com> | ||
11 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
12 | --- | ||
13 | target/riscv/kvm-stub.c | 30 ------------------------------ | ||
14 | target/riscv/meson.build | 2 +- | ||
15 | 2 files changed, 1 insertion(+), 31 deletions(-) | ||
16 | delete mode 100644 target/riscv/kvm-stub.c | ||
17 | |||
18 | diff --git a/target/riscv/kvm-stub.c b/target/riscv/kvm-stub.c | ||
19 | deleted file mode 100644 | ||
20 | index XXXXXXX..XXXXXXX | ||
21 | --- a/target/riscv/kvm-stub.c | ||
22 | +++ /dev/null | ||
23 | @@ -XXX,XX +XXX,XX @@ | ||
24 | -/* | ||
25 | - * QEMU KVM RISC-V specific function stubs | ||
26 | - * | ||
27 | - * Copyright (c) 2020 Huawei Technologies Co., Ltd | ||
28 | - * | ||
29 | - * This program is free software; you can redistribute it and/or modify it | ||
30 | - * under the terms and conditions of the GNU General Public License, | ||
31 | - * version 2 or later, as published by the Free Software Foundation. | ||
32 | - * | ||
33 | - * This program is distributed in the hope it will be useful, but WITHOUT | ||
34 | - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
35 | - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
36 | - * more details. | ||
37 | - * | ||
38 | - * You should have received a copy of the GNU General Public License along with | ||
39 | - * this program. If not, see <http://www.gnu.org/licenses/>. | ||
40 | - */ | ||
41 | -#include "qemu/osdep.h" | ||
42 | -#include "cpu.h" | ||
43 | -#include "kvm_riscv.h" | ||
44 | - | ||
45 | -void kvm_riscv_reset_vcpu(RISCVCPU *cpu) | ||
46 | -{ | ||
47 | - abort(); | ||
48 | -} | ||
49 | - | ||
50 | -void kvm_riscv_set_irq(RISCVCPU *cpu, int irq, int level) | ||
51 | -{ | ||
52 | - abort(); | ||
53 | -} | ||
54 | diff --git a/target/riscv/meson.build b/target/riscv/meson.build | ||
55 | index XXXXXXX..XXXXXXX 100644 | ||
56 | --- a/target/riscv/meson.build | ||
57 | +++ b/target/riscv/meson.build | ||
58 | @@ -XXX,XX +XXX,XX @@ riscv_ss.add(files( | ||
59 | 'zce_helper.c', | ||
60 | 'vcrypto_helper.c' | ||
61 | )) | ||
62 | -riscv_ss.add(when: 'CONFIG_KVM', if_true: files('kvm.c'), if_false: files('kvm-stub.c')) | ||
63 | +riscv_ss.add(when: 'CONFIG_KVM', if_true: files('kvm.c')) | ||
64 | |||
65 | riscv_system_ss = ss.source_set() | ||
66 | riscv_system_ss.add(files( | ||
67 | -- | ||
68 | 2.41.0 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
1 | 2 | ||
3 | Add a KVM accelerator class like we did with TCG. The difference is | ||
4 | that, at least for now, we won't be using a realize() implementation for | ||
5 | this accelerator. | ||
6 | |||
7 | We'll start by assiging kvm_riscv_cpu_add_kvm_properties(), renamed to | ||
8 | kvm_cpu_instance_init(), as a 'cpu_instance_init' implementation. Change | ||
9 | riscv_cpu_post_init() to invoke accel_cpu_instance_init(), which will go | ||
10 | through the 'cpu_instance_init' impl of the current acceleration (if | ||
11 | available) and execute it. The end result is that the KVM initial setup, | ||
12 | i.e. starting registers and adding its specific properties, will be done | ||
13 | via this hook. | ||
14 | |||
15 | Add a 'tcg_enabled()' condition in riscv_cpu_post_init() to avoid | ||
16 | calling riscv_cpu_add_user_properties() when running KVM. We'll remove | ||
17 | this condition when the TCG accel class get its own 'cpu_instance_init' | ||
18 | implementation. | ||
19 | |||
20 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
21 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> | ||
22 | Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com> | ||
23 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
24 | Message-ID: <20230925175709.35696-12-dbarboza@ventanamicro.com> | ||
25 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
26 | --- | ||
27 | target/riscv/kvm_riscv.h | 1 - | ||
28 | target/riscv/cpu.c | 8 +++----- | ||
29 | target/riscv/kvm.c | 26 ++++++++++++++++++++++++-- | ||
30 | 3 files changed, 27 insertions(+), 8 deletions(-) | ||
31 | |||
32 | diff --git a/target/riscv/kvm_riscv.h b/target/riscv/kvm_riscv.h | ||
33 | index XXXXXXX..XXXXXXX 100644 | ||
34 | --- a/target/riscv/kvm_riscv.h | ||
35 | +++ b/target/riscv/kvm_riscv.h | ||
36 | @@ -XXX,XX +XXX,XX @@ | ||
37 | #ifndef QEMU_KVM_RISCV_H | ||
38 | #define QEMU_KVM_RISCV_H | ||
39 | |||
40 | -void kvm_riscv_cpu_add_kvm_properties(Object *obj); | ||
41 | void kvm_riscv_reset_vcpu(RISCVCPU *cpu); | ||
42 | void kvm_riscv_set_irq(RISCVCPU *cpu, int irq, int level); | ||
43 | void kvm_riscv_aia_create(MachineState *machine, uint64_t group_shift, | ||
44 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | ||
45 | index XXXXXXX..XXXXXXX 100644 | ||
46 | --- a/target/riscv/cpu.c | ||
47 | +++ b/target/riscv/cpu.c | ||
48 | @@ -XXX,XX +XXX,XX @@ static bool riscv_cpu_has_user_properties(Object *cpu_obj) | ||
49 | |||
50 | static void riscv_cpu_post_init(Object *obj) | ||
51 | { | ||
52 | - if (riscv_cpu_has_user_properties(obj)) { | ||
53 | + accel_cpu_instance_init(CPU(obj)); | ||
54 | + | ||
55 | + if (tcg_enabled() && riscv_cpu_has_user_properties(obj)) { | ||
56 | riscv_cpu_add_user_properties(obj); | ||
57 | } | ||
58 | |||
59 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_add_multiext_prop_array(Object *obj, | ||
60 | static void riscv_cpu_add_user_properties(Object *obj) | ||
61 | { | ||
62 | #ifndef CONFIG_USER_ONLY | ||
63 | - if (kvm_enabled()) { | ||
64 | - kvm_riscv_cpu_add_kvm_properties(obj); | ||
65 | - return; | ||
66 | - } | ||
67 | riscv_add_satp_mode_properties(obj); | ||
68 | #endif | ||
69 | |||
70 | diff --git a/target/riscv/kvm.c b/target/riscv/kvm.c | ||
71 | index XXXXXXX..XXXXXXX 100644 | ||
72 | --- a/target/riscv/kvm.c | ||
73 | +++ b/target/riscv/kvm.c | ||
74 | @@ -XXX,XX +XXX,XX @@ | ||
75 | #include "sysemu/kvm_int.h" | ||
76 | #include "cpu.h" | ||
77 | #include "trace.h" | ||
78 | +#include "hw/core/accel-cpu.h" | ||
79 | #include "hw/pci/pci.h" | ||
80 | #include "exec/memattrs.h" | ||
81 | #include "exec/address-spaces.h" | ||
82 | @@ -XXX,XX +XXX,XX @@ void kvm_riscv_aia_create(MachineState *machine, uint64_t group_shift, | ||
83 | kvm_msi_via_irqfd_allowed = kvm_irqfds_enabled(); | ||
84 | } | ||
85 | |||
86 | -void kvm_riscv_cpu_add_kvm_properties(Object *obj) | ||
87 | +static void kvm_cpu_instance_init(CPUState *cs) | ||
88 | { | ||
89 | + Object *obj = OBJECT(RISCV_CPU(cs)); | ||
90 | DeviceState *dev = DEVICE(obj); | ||
91 | |||
92 | riscv_init_user_properties(obj); | ||
93 | @@ -XXX,XX +XXX,XX @@ void kvm_riscv_cpu_add_kvm_properties(Object *obj) | ||
94 | riscv_cpu_add_kvm_unavail_prop_array(obj, riscv_cpu_experimental_exts); | ||
95 | |||
96 | for (Property *prop = riscv_cpu_options; prop && prop->name; prop++) { | ||
97 | - /* Check if KVM created the property already */ | ||
98 | + /* Check if we have a specific KVM handler for the option */ | ||
99 | if (object_property_find(obj, prop->name)) { | ||
100 | continue; | ||
101 | } | ||
102 | @@ -XXX,XX +XXX,XX @@ void kvm_riscv_cpu_add_kvm_properties(Object *obj) | ||
103 | } | ||
104 | } | ||
105 | |||
106 | +static void kvm_cpu_accel_class_init(ObjectClass *oc, void *data) | ||
107 | +{ | ||
108 | + AccelCPUClass *acc = ACCEL_CPU_CLASS(oc); | ||
109 | + | ||
110 | + acc->cpu_instance_init = kvm_cpu_instance_init; | ||
111 | +} | ||
112 | + | ||
113 | +static const TypeInfo kvm_cpu_accel_type_info = { | ||
114 | + .name = ACCEL_CPU_NAME("kvm"), | ||
115 | + | ||
116 | + .parent = TYPE_ACCEL_CPU, | ||
117 | + .class_init = kvm_cpu_accel_class_init, | ||
118 | + .abstract = true, | ||
119 | +}; | ||
120 | +static void kvm_cpu_accel_register_types(void) | ||
121 | +{ | ||
122 | + type_register_static(&kvm_cpu_accel_type_info); | ||
123 | +} | ||
124 | +type_init(kvm_cpu_accel_register_types); | ||
125 | + | ||
126 | static void riscv_host_cpu_init(Object *obj) | ||
127 | { | ||
128 | CPURISCVState *env = &RISCV_CPU(obj)->env; | ||
129 | -- | ||
130 | 2.41.0 | diff view generated by jsdifflib |
1 | From: Alistair Francis <alistair.francis@wdc.com> | 1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
---|---|---|---|
2 | 2 | ||
3 | Similar to the ARM virt machine add support for adding device tree | 3 | Move the files to a 'kvm' dir to promote more code separation between |
4 | entries for dynamically created devices. | 4 | accelerators and making our lives easier supporting build options such |
5 | as --disable-tcg. | ||
5 | 6 | ||
6 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 7 | Rename kvm.c to kvm-cpu.c to keep it in line with its TCG counterpart. |
7 | Reviewed-by: Edgar E. Iglesias <edgar.iglesias@amd.com> | 8 | |
8 | Message-Id: <20220427234146.1130752-5-alistair.francis@opensource.wdc.com> | 9 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
10 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> | ||
11 | Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com> | ||
12 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
13 | Message-ID: <20230925175709.35696-13-dbarboza@ventanamicro.com> | ||
9 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 14 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
10 | --- | 15 | --- |
11 | hw/riscv/virt.c | 19 +++++++++++++++++++ | 16 | target/riscv/{ => kvm}/kvm_riscv.h | 0 |
12 | 1 file changed, 19 insertions(+) | 17 | hw/intc/riscv_aplic.c | 2 +- |
18 | hw/riscv/virt.c | 2 +- | ||
19 | target/riscv/cpu.c | 2 +- | ||
20 | target/riscv/{kvm.c => kvm/kvm-cpu.c} | 0 | ||
21 | target/riscv/kvm/meson.build | 1 + | ||
22 | target/riscv/meson.build | 2 +- | ||
23 | 7 files changed, 5 insertions(+), 4 deletions(-) | ||
24 | rename target/riscv/{ => kvm}/kvm_riscv.h (100%) | ||
25 | rename target/riscv/{kvm.c => kvm/kvm-cpu.c} (100%) | ||
26 | create mode 100644 target/riscv/kvm/meson.build | ||
13 | 27 | ||
28 | diff --git a/target/riscv/kvm_riscv.h b/target/riscv/kvm/kvm_riscv.h | ||
29 | similarity index 100% | ||
30 | rename from target/riscv/kvm_riscv.h | ||
31 | rename to target/riscv/kvm/kvm_riscv.h | ||
32 | diff --git a/hw/intc/riscv_aplic.c b/hw/intc/riscv_aplic.c | ||
33 | index XXXXXXX..XXXXXXX 100644 | ||
34 | --- a/hw/intc/riscv_aplic.c | ||
35 | +++ b/hw/intc/riscv_aplic.c | ||
36 | @@ -XXX,XX +XXX,XX @@ | ||
37 | #include "target/riscv/cpu.h" | ||
38 | #include "sysemu/sysemu.h" | ||
39 | #include "sysemu/kvm.h" | ||
40 | -#include "kvm_riscv.h" | ||
41 | +#include "kvm/kvm_riscv.h" | ||
42 | #include "migration/vmstate.h" | ||
43 | |||
44 | #define APLIC_MAX_IDC (1UL << 14) | ||
14 | diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c | 45 | diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c |
15 | index XXXXXXX..XXXXXXX 100644 | 46 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/hw/riscv/virt.c | 47 | --- a/hw/riscv/virt.c |
17 | +++ b/hw/riscv/virt.c | 48 | +++ b/hw/riscv/virt.c |
18 | @@ -XXX,XX +XXX,XX @@ | 49 | @@ -XXX,XX +XXX,XX @@ |
19 | #include "hw/qdev-properties.h" | ||
20 | #include "hw/char/serial.h" | ||
21 | #include "target/riscv/cpu.h" | ||
22 | +#include "hw/core/sysbus-fdt.h" | ||
23 | #include "hw/riscv/riscv_hart.h" | ||
24 | #include "hw/riscv/virt.h" | 50 | #include "hw/riscv/virt.h" |
25 | #include "hw/riscv/boot.h" | 51 | #include "hw/riscv/boot.h" |
26 | @@ -XXX,XX +XXX,XX @@ static void create_fdt_socket_plic(RISCVVirtState *s, | 52 | #include "hw/riscv/numa.h" |
27 | riscv_socket_fdt_write_id(mc, mc->fdt, plic_name, socket); | 53 | -#include "kvm_riscv.h" |
28 | qemu_fdt_setprop_cell(mc->fdt, plic_name, "phandle", | 54 | +#include "kvm/kvm_riscv.h" |
29 | plic_phandles[socket]); | 55 | #include "hw/intc/riscv_aclint.h" |
30 | + | 56 | #include "hw/intc/riscv_aplic.h" |
31 | + platform_bus_add_all_fdt_nodes(mc->fdt, plic_name, | 57 | #include "hw/intc/riscv_imsic.h" |
32 | + memmap[VIRT_PLATFORM_BUS].base, | 58 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c |
33 | + memmap[VIRT_PLATFORM_BUS].size, | 59 | index XXXXXXX..XXXXXXX 100644 |
34 | + VIRT_PLATFORM_BUS_IRQ); | 60 | --- a/target/riscv/cpu.c |
35 | + | 61 | +++ b/target/riscv/cpu.c |
36 | g_free(plic_name); | 62 | @@ -XXX,XX +XXX,XX @@ |
37 | 63 | #include "fpu/softfloat-helpers.h" | |
38 | g_free(plic_cells); | 64 | #include "sysemu/kvm.h" |
39 | @@ -XXX,XX +XXX,XX @@ static void create_fdt_imsic(RISCVVirtState *s, const MemMapEntry *memmap, | 65 | #include "sysemu/tcg.h" |
40 | IMSIC_MMIO_GROUP_MIN_SHIFT); | 66 | -#include "kvm_riscv.h" |
41 | } | 67 | +#include "kvm/kvm_riscv.h" |
42 | qemu_fdt_setprop_cell(mc->fdt, imsic_name, "phandle", *msi_m_phandle); | 68 | #include "tcg/tcg.h" |
43 | + | 69 | |
44 | + platform_bus_add_all_fdt_nodes(mc->fdt, imsic_name, | 70 | /* RISC-V CPU definitions */ |
45 | + memmap[VIRT_PLATFORM_BUS].base, | 71 | diff --git a/target/riscv/kvm.c b/target/riscv/kvm/kvm-cpu.c |
46 | + memmap[VIRT_PLATFORM_BUS].size, | 72 | similarity index 100% |
47 | + VIRT_PLATFORM_BUS_IRQ); | 73 | rename from target/riscv/kvm.c |
48 | + | 74 | rename to target/riscv/kvm/kvm-cpu.c |
49 | g_free(imsic_name); | 75 | diff --git a/target/riscv/kvm/meson.build b/target/riscv/kvm/meson.build |
50 | 76 | new file mode 100644 | |
51 | /* S-level IMSIC node */ | 77 | index XXXXXXX..XXXXXXX |
52 | @@ -XXX,XX +XXX,XX @@ static void create_fdt_socket_aplic(RISCVVirtState *s, | 78 | --- /dev/null |
53 | VIRT_IRQCHIP_NUM_SOURCES); | 79 | +++ b/target/riscv/kvm/meson.build |
54 | riscv_socket_fdt_write_id(mc, mc->fdt, aplic_name, socket); | 80 | @@ -0,0 +1 @@ |
55 | qemu_fdt_setprop_cell(mc->fdt, aplic_name, "phandle", aplic_s_phandle); | 81 | +riscv_ss.add(when: 'CONFIG_KVM', if_true: files('kvm-cpu.c')) |
56 | + | 82 | diff --git a/target/riscv/meson.build b/target/riscv/meson.build |
57 | + platform_bus_add_all_fdt_nodes(mc->fdt, aplic_name, | 83 | index XXXXXXX..XXXXXXX 100644 |
58 | + memmap[VIRT_PLATFORM_BUS].base, | 84 | --- a/target/riscv/meson.build |
59 | + memmap[VIRT_PLATFORM_BUS].size, | 85 | +++ b/target/riscv/meson.build |
60 | + VIRT_PLATFORM_BUS_IRQ); | 86 | @@ -XXX,XX +XXX,XX @@ riscv_ss.add(files( |
61 | + | 87 | 'zce_helper.c', |
62 | g_free(aplic_name); | 88 | 'vcrypto_helper.c' |
63 | 89 | )) | |
64 | g_free(aplic_cells); | 90 | -riscv_ss.add(when: 'CONFIG_KVM', if_true: files('kvm.c')) |
91 | |||
92 | riscv_system_ss = ss.source_set() | ||
93 | riscv_system_ss.add(files( | ||
94 | @@ -XXX,XX +XXX,XX @@ riscv_system_ss.add(files( | ||
95 | )) | ||
96 | |||
97 | subdir('tcg') | ||
98 | +subdir('kvm') | ||
99 | |||
100 | target_arch += {'riscv': riscv_ss} | ||
101 | target_system_arch += {'riscv': riscv_system_ss} | ||
65 | -- | 102 | -- |
66 | 2.35.1 | 103 | 2.41.0 | diff view generated by jsdifflib |
1 | From: Frank Chang <frank.chang@sifive.com> | 1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
---|---|---|---|
2 | 2 | ||
3 | Allow user to set core's marchid, mvendorid, mipid CSRs through | 3 | riscv_cpu_add_misa_properties() is being used to fill the missing KVM |
4 | -cpu command line option. | 4 | MISA properties but it is a TCG helper that was adapted to do so. We'll |
5 | move it to tcg-cpu.c in the next patches, meaning that KVM needs to fill | ||
6 | the remaining MISA properties on its own. | ||
5 | 7 | ||
6 | The default values of marchid and mipid are built with QEMU's version | 8 | Do not use riscv_cpu_add_misa_properties(). Let's create a new array |
7 | numbers. | 9 | with all available MISA bits we support that can be read by KVM. The |
10 | array is zero terminate to allow us to iterate through it without | ||
11 | knowing its size. | ||
8 | 12 | ||
9 | Signed-off-by: Frank Chang <frank.chang@sifive.com> | 13 | Then, inside kvm_riscv_add_cpu_user_properties(), we'll create all KVM |
10 | Reviewed-by: Jim Shu <jim.shu@sifive.com> | 14 | MISA properties as usual and then use this array to add any missing MISA |
15 | properties with the riscv_cpu_add_kvm_unavail_prop() helper. | ||
16 | |||
17 | Note that we're creating misa_bits[], and not using the existing | ||
18 | 'riscv_single_letter_exts[]', because the latter is tuned for riscv,isa | ||
19 | related functions and it doesn't have all MISA bits we support. Commit | ||
20 | 0e2c377023 ("target/riscv: misa to ISA string conversion fix") has the | ||
21 | full context. | ||
22 | |||
23 | While we're at it, move both satp and the multi-letter extension | ||
24 | properties to kvm_riscv_add_cpu_user_properties() as well. | ||
25 | |||
26 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
27 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> | ||
11 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 28 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
12 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> | 29 | Message-ID: <20230925175709.35696-14-dbarboza@ventanamicro.com> |
13 | Message-Id: <20220422040436.2233-1-frank.chang@sifive.com> | ||
14 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 30 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
15 | --- | 31 | --- |
16 | target/riscv/cpu.h | 4 ++++ | 32 | target/riscv/cpu.h | 3 ++- |
17 | target/riscv/cpu.c | 9 +++++++++ | 33 | target/riscv/cpu.c | 2 ++ |
18 | target/riscv/csr.c | 38 ++++++++++++++++++++++++++++++++++---- | 34 | target/riscv/kvm/kvm-cpu.c | 22 ++++++++++++++-------- |
19 | 3 files changed, 47 insertions(+), 4 deletions(-) | 35 | 3 files changed, 18 insertions(+), 9 deletions(-) |
20 | 36 | ||
21 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h | 37 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h |
22 | index XXXXXXX..XXXXXXX 100644 | 38 | index XXXXXXX..XXXXXXX 100644 |
23 | --- a/target/riscv/cpu.h | 39 | --- a/target/riscv/cpu.h |
24 | +++ b/target/riscv/cpu.h | 40 | +++ b/target/riscv/cpu.h |
25 | @@ -XXX,XX +XXX,XX @@ struct RISCVCPUConfig { | 41 | @@ -XXX,XX +XXX,XX @@ |
26 | bool ext_zve32f; | 42 | #define RV(x) ((target_ulong)1 << (x - 'A')) |
27 | bool ext_zve64f; | 43 | |
28 | 44 | /* | |
29 | + uint32_t mvendorid; | 45 | - * Consider updating misa_ext_info_arr[] and misa_ext_cfgs[] |
30 | + uint64_t marchid; | 46 | + * Update misa_bits[], misa_ext_info_arr[] and misa_ext_cfgs[] |
31 | + uint64_t mipid; | 47 | * when adding new MISA bits here. |
32 | + | 48 | */ |
33 | /* Vendor-specific custom extensions */ | 49 | #define RVI RV('I') |
34 | bool ext_XVentanaCondOps; | 50 | @@ -XXX,XX +XXX,XX @@ |
51 | #define RVJ RV('J') | ||
52 | #define RVG RV('G') | ||
53 | |||
54 | +extern const uint32_t misa_bits[]; | ||
55 | const char *riscv_get_misa_ext_name(uint32_t bit); | ||
56 | const char *riscv_get_misa_ext_description(uint32_t bit); | ||
35 | 57 | ||
36 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | 58 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c |
37 | index XXXXXXX..XXXXXXX 100644 | 59 | index XXXXXXX..XXXXXXX 100644 |
38 | --- a/target/riscv/cpu.c | 60 | --- a/target/riscv/cpu.c |
39 | +++ b/target/riscv/cpu.c | 61 | +++ b/target/riscv/cpu.c |
40 | @@ -XXX,XX +XXX,XX @@ | 62 | @@ -XXX,XX +XXX,XX @@ |
41 | 63 | ||
42 | /* RISC-V CPU definitions */ | 64 | /* RISC-V CPU definitions */ |
43 | 65 | static const char riscv_single_letter_exts[] = "IEMAFDQCPVH"; | |
44 | +#define RISCV_CPU_MARCHID ((QEMU_VERSION_MAJOR << 16) | \ | 66 | +const uint32_t misa_bits[] = {RVI, RVE, RVM, RVA, RVF, RVD, RVV, |
45 | + (QEMU_VERSION_MINOR << 8) | \ | 67 | + RVC, RVS, RVU, RVH, RVJ, RVG, 0}; |
46 | + (QEMU_VERSION_MICRO)) | 68 | |
47 | +#define RISCV_CPU_MIPID RISCV_CPU_MARCHID | 69 | struct isa_ext_data { |
70 | const char *name; | ||
71 | diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c | ||
72 | index XXXXXXX..XXXXXXX 100644 | ||
73 | --- a/target/riscv/kvm/kvm-cpu.c | ||
74 | +++ b/target/riscv/kvm/kvm-cpu.c | ||
75 | @@ -XXX,XX +XXX,XX @@ static void kvm_riscv_add_cpu_user_properties(Object *cpu_obj) | ||
76 | { | ||
77 | int i; | ||
78 | |||
79 | + riscv_add_satp_mode_properties(cpu_obj); | ||
48 | + | 80 | + |
49 | static const char riscv_single_letter_exts[] = "IEMAFDQCPVH"; | 81 | for (i = 0; i < ARRAY_SIZE(kvm_misa_ext_cfgs); i++) { |
50 | 82 | KVMCPUConfig *misa_cfg = &kvm_misa_ext_cfgs[i]; | |
51 | struct isa_ext_data { | 83 | int bit = misa_cfg->offset; |
52 | @@ -XXX,XX +XXX,XX @@ static Property riscv_cpu_properties[] = { | 84 | @@ -XXX,XX +XXX,XX @@ static void kvm_riscv_add_cpu_user_properties(Object *cpu_obj) |
53 | DEFINE_PROP_UINT16("vlen", RISCVCPU, cfg.vlen, 128), | 85 | misa_cfg->description); |
54 | DEFINE_PROP_UINT16("elen", RISCVCPU, cfg.elen, 64), | 86 | } |
55 | 87 | ||
56 | + DEFINE_PROP_UINT32("mvendorid", RISCVCPU, cfg.mvendorid, 0), | 88 | + for (i = 0; misa_bits[i] != 0; i++) { |
57 | + DEFINE_PROP_UINT64("marchid", RISCVCPU, cfg.marchid, RISCV_CPU_MARCHID), | 89 | + const char *ext_name = riscv_get_misa_ext_name(misa_bits[i]); |
58 | + DEFINE_PROP_UINT64("mipid", RISCVCPU, cfg.mipid, RISCV_CPU_MIPID), | 90 | + riscv_cpu_add_kvm_unavail_prop(cpu_obj, ext_name); |
91 | + } | ||
59 | + | 92 | + |
60 | DEFINE_PROP_BOOL("svinval", RISCVCPU, cfg.ext_svinval, false), | 93 | for (i = 0; i < ARRAY_SIZE(kvm_multi_ext_cfgs); i++) { |
61 | DEFINE_PROP_BOOL("svnapot", RISCVCPU, cfg.ext_svnapot, false), | 94 | KVMCPUConfig *multi_cfg = &kvm_multi_ext_cfgs[i]; |
62 | DEFINE_PROP_BOOL("svpbmt", RISCVCPU, cfg.ext_svpbmt, false), | 95 | |
63 | diff --git a/target/riscv/csr.c b/target/riscv/csr.c | 96 | @@ -XXX,XX +XXX,XX @@ static void kvm_riscv_add_cpu_user_properties(Object *cpu_obj) |
64 | index XXXXXXX..XXXXXXX 100644 | 97 | object_property_add(cpu_obj, "cboz_blocksize", "uint16", |
65 | --- a/target/riscv/csr.c | 98 | NULL, kvm_cpu_set_cbomz_blksize, |
66 | +++ b/target/riscv/csr.c | 99 | NULL, &kvm_cboz_blocksize); |
67 | @@ -XXX,XX +XXX,XX @@ static RISCVException write_ignore(CPURISCVState *env, int csrno, | 100 | + |
68 | return RISCV_EXCP_NONE; | 101 | + riscv_cpu_add_kvm_unavail_prop_array(cpu_obj, riscv_cpu_extensions); |
102 | + riscv_cpu_add_kvm_unavail_prop_array(cpu_obj, riscv_cpu_vendor_exts); | ||
103 | + riscv_cpu_add_kvm_unavail_prop_array(cpu_obj, riscv_cpu_experimental_exts); | ||
69 | } | 104 | } |
70 | 105 | ||
71 | +static RISCVException read_mvendorid(CPURISCVState *env, int csrno, | 106 | static int kvm_riscv_get_regs_core(CPUState *cs) |
72 | + target_ulong *val) | 107 | @@ -XXX,XX +XXX,XX @@ static void kvm_riscv_init_multiext_cfg(RISCVCPU *cpu, KVMScratchCPU *kvmcpu) |
73 | +{ | 108 | } |
74 | + CPUState *cs = env_cpu(env); | 109 | } |
75 | + RISCVCPU *cpu = RISCV_CPU(cs); | 110 | |
76 | + | 111 | -static void riscv_init_user_properties(Object *cpu_obj) |
77 | + *val = cpu->cfg.mvendorid; | 112 | +static void riscv_init_kvm_registers(Object *cpu_obj) |
78 | + return RISCV_EXCP_NONE; | ||
79 | +} | ||
80 | + | ||
81 | +static RISCVException read_marchid(CPURISCVState *env, int csrno, | ||
82 | + target_ulong *val) | ||
83 | +{ | ||
84 | + CPUState *cs = env_cpu(env); | ||
85 | + RISCVCPU *cpu = RISCV_CPU(cs); | ||
86 | + | ||
87 | + *val = cpu->cfg.marchid; | ||
88 | + return RISCV_EXCP_NONE; | ||
89 | +} | ||
90 | + | ||
91 | +static RISCVException read_mipid(CPURISCVState *env, int csrno, | ||
92 | + target_ulong *val) | ||
93 | +{ | ||
94 | + CPUState *cs = env_cpu(env); | ||
95 | + RISCVCPU *cpu = RISCV_CPU(cs); | ||
96 | + | ||
97 | + *val = cpu->cfg.mipid; | ||
98 | + return RISCV_EXCP_NONE; | ||
99 | +} | ||
100 | + | ||
101 | static RISCVException read_mhartid(CPURISCVState *env, int csrno, | ||
102 | target_ulong *val) | ||
103 | { | 113 | { |
104 | @@ -XXX,XX +XXX,XX @@ riscv_csr_operations csr_ops[CSR_TABLE_SIZE] = { | 114 | RISCVCPU *cpu = RISCV_CPU(cpu_obj); |
105 | [CSR_MINSTRETH] = { "minstreth", any32, read_instreth }, | 115 | KVMScratchCPU kvmcpu; |
106 | 116 | @@ -XXX,XX +XXX,XX @@ static void riscv_init_user_properties(Object *cpu_obj) | |
107 | /* Machine Information Registers */ | 117 | return; |
108 | - [CSR_MVENDORID] = { "mvendorid", any, read_zero }, | 118 | } |
109 | - [CSR_MARCHID] = { "marchid", any, read_zero }, | 119 | |
110 | - [CSR_MIMPID] = { "mimpid", any, read_zero }, | 120 | - kvm_riscv_add_cpu_user_properties(cpu_obj); |
111 | - [CSR_MHARTID] = { "mhartid", any, read_mhartid }, | 121 | kvm_riscv_init_machine_ids(cpu, &kvmcpu); |
112 | + [CSR_MVENDORID] = { "mvendorid", any, read_mvendorid }, | 122 | kvm_riscv_init_misa_ext_mask(cpu, &kvmcpu); |
113 | + [CSR_MARCHID] = { "marchid", any, read_marchid }, | 123 | kvm_riscv_init_multiext_cfg(cpu, &kvmcpu); |
114 | + [CSR_MIMPID] = { "mimpid", any, read_mipid }, | 124 | @@ -XXX,XX +XXX,XX @@ static void kvm_cpu_instance_init(CPUState *cs) |
115 | + [CSR_MHARTID] = { "mhartid", any, read_mhartid }, | 125 | Object *obj = OBJECT(RISCV_CPU(cs)); |
116 | 126 | DeviceState *dev = DEVICE(obj); | |
117 | [CSR_MCONFIGPTR] = { "mconfigptr", any, read_zero, | 127 | |
118 | .min_priv_ver = PRIV_VERSION_1_12_0 }, | 128 | - riscv_init_user_properties(obj); |
129 | - riscv_add_satp_mode_properties(obj); | ||
130 | - riscv_cpu_add_misa_properties(obj); | ||
131 | + riscv_init_kvm_registers(obj); | ||
132 | |||
133 | - riscv_cpu_add_kvm_unavail_prop_array(obj, riscv_cpu_extensions); | ||
134 | - riscv_cpu_add_kvm_unavail_prop_array(obj, riscv_cpu_vendor_exts); | ||
135 | - riscv_cpu_add_kvm_unavail_prop_array(obj, riscv_cpu_experimental_exts); | ||
136 | + kvm_riscv_add_cpu_user_properties(obj); | ||
137 | |||
138 | for (Property *prop = riscv_cpu_options; prop && prop->name; prop++) { | ||
139 | /* Check if we have a specific KVM handler for the option */ | ||
119 | -- | 140 | -- |
120 | 2.35.1 | 141 | 2.41.0 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
1 | 2 | ||
3 | We'll move riscv_init_max_cpu_extensions() to tcg-cpu.c in the next | ||
4 | patch and set_misa() needs to be usable from there. | ||
5 | |||
6 | Rename it to riscv_cpu_set_misa() and make it public. | ||
7 | |||
8 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
9 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | ||
10 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> | ||
11 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
12 | Message-ID: <20230925175709.35696-15-dbarboza@ventanamicro.com> | ||
13 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
14 | --- | ||
15 | target/riscv/cpu.h | 1 + | ||
16 | target/riscv/cpu.c | 34 ++++++++++++++++++---------------- | ||
17 | 2 files changed, 19 insertions(+), 16 deletions(-) | ||
18 | |||
19 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h | ||
20 | index XXXXXXX..XXXXXXX 100644 | ||
21 | --- a/target/riscv/cpu.h | ||
22 | +++ b/target/riscv/cpu.h | ||
23 | @@ -XXX,XX +XXX,XX @@ void isa_ext_update_enabled(RISCVCPU *cpu, uint32_t ext_offset, bool en); | ||
24 | bool cpu_cfg_ext_is_user_set(uint32_t ext_offset); | ||
25 | bool isa_ext_is_enabled(RISCVCPU *cpu, uint32_t ext_offset); | ||
26 | int cpu_cfg_ext_get_min_version(uint32_t ext_offset); | ||
27 | +void riscv_cpu_set_misa(CPURISCVState *env, RISCVMXL mxl, uint32_t ext); | ||
28 | void riscv_cpu_disable_priv_spec_isa_exts(RISCVCPU *cpu); | ||
29 | |||
30 | typedef struct RISCVCPUMultiExtConfig { | ||
31 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | ||
32 | index XXXXXXX..XXXXXXX 100644 | ||
33 | --- a/target/riscv/cpu.c | ||
34 | +++ b/target/riscv/cpu.c | ||
35 | @@ -XXX,XX +XXX,XX @@ const char *riscv_cpu_get_trap_name(target_ulong cause, bool async) | ||
36 | } | ||
37 | } | ||
38 | |||
39 | -static void set_misa(CPURISCVState *env, RISCVMXL mxl, uint32_t ext) | ||
40 | +void riscv_cpu_set_misa(CPURISCVState *env, RISCVMXL mxl, uint32_t ext) | ||
41 | { | ||
42 | env->misa_mxl_max = env->misa_mxl = mxl; | ||
43 | env->misa_ext_mask = env->misa_ext = ext; | ||
44 | @@ -XXX,XX +XXX,XX @@ static void riscv_any_cpu_init(Object *obj) | ||
45 | RISCVCPU *cpu = RISCV_CPU(obj); | ||
46 | CPURISCVState *env = &cpu->env; | ||
47 | #if defined(TARGET_RISCV32) | ||
48 | - set_misa(env, MXL_RV32, RVI | RVM | RVA | RVF | RVD | RVC | RVU); | ||
49 | + riscv_cpu_set_misa(env, MXL_RV32, RVI | RVM | RVA | RVF | RVD | RVC | RVU); | ||
50 | #elif defined(TARGET_RISCV64) | ||
51 | - set_misa(env, MXL_RV64, RVI | RVM | RVA | RVF | RVD | RVC | RVU); | ||
52 | + riscv_cpu_set_misa(env, MXL_RV64, RVI | RVM | RVA | RVF | RVD | RVC | RVU); | ||
53 | #endif | ||
54 | |||
55 | #ifndef CONFIG_USER_ONLY | ||
56 | @@ -XXX,XX +XXX,XX @@ static void riscv_max_cpu_init(Object *obj) | ||
57 | #ifdef TARGET_RISCV32 | ||
58 | mlx = MXL_RV32; | ||
59 | #endif | ||
60 | - set_misa(env, mlx, 0); | ||
61 | + riscv_cpu_set_misa(env, mlx, 0); | ||
62 | env->priv_ver = PRIV_VERSION_LATEST; | ||
63 | #ifndef CONFIG_USER_ONLY | ||
64 | set_satp_mode_max_supported(RISCV_CPU(obj), mlx == MXL_RV32 ? | ||
65 | @@ -XXX,XX +XXX,XX @@ static void rv64_base_cpu_init(Object *obj) | ||
66 | { | ||
67 | CPURISCVState *env = &RISCV_CPU(obj)->env; | ||
68 | /* We set this in the realise function */ | ||
69 | - set_misa(env, MXL_RV64, 0); | ||
70 | + riscv_cpu_set_misa(env, MXL_RV64, 0); | ||
71 | /* Set latest version of privileged specification */ | ||
72 | env->priv_ver = PRIV_VERSION_LATEST; | ||
73 | #ifndef CONFIG_USER_ONLY | ||
74 | @@ -XXX,XX +XXX,XX @@ static void rv64_sifive_u_cpu_init(Object *obj) | ||
75 | { | ||
76 | RISCVCPU *cpu = RISCV_CPU(obj); | ||
77 | CPURISCVState *env = &cpu->env; | ||
78 | - set_misa(env, MXL_RV64, RVI | RVM | RVA | RVF | RVD | RVC | RVS | RVU); | ||
79 | + riscv_cpu_set_misa(env, MXL_RV64, | ||
80 | + RVI | RVM | RVA | RVF | RVD | RVC | RVS | RVU); | ||
81 | env->priv_ver = PRIV_VERSION_1_10_0; | ||
82 | #ifndef CONFIG_USER_ONLY | ||
83 | set_satp_mode_max_supported(RISCV_CPU(obj), VM_1_10_SV39); | ||
84 | @@ -XXX,XX +XXX,XX @@ static void rv64_sifive_e_cpu_init(Object *obj) | ||
85 | CPURISCVState *env = &RISCV_CPU(obj)->env; | ||
86 | RISCVCPU *cpu = RISCV_CPU(obj); | ||
87 | |||
88 | - set_misa(env, MXL_RV64, RVI | RVM | RVA | RVC | RVU); | ||
89 | + riscv_cpu_set_misa(env, MXL_RV64, RVI | RVM | RVA | RVC | RVU); | ||
90 | env->priv_ver = PRIV_VERSION_1_10_0; | ||
91 | #ifndef CONFIG_USER_ONLY | ||
92 | set_satp_mode_max_supported(cpu, VM_1_10_MBARE); | ||
93 | @@ -XXX,XX +XXX,XX @@ static void rv64_thead_c906_cpu_init(Object *obj) | ||
94 | CPURISCVState *env = &RISCV_CPU(obj)->env; | ||
95 | RISCVCPU *cpu = RISCV_CPU(obj); | ||
96 | |||
97 | - set_misa(env, MXL_RV64, RVG | RVC | RVS | RVU); | ||
98 | + riscv_cpu_set_misa(env, MXL_RV64, RVG | RVC | RVS | RVU); | ||
99 | env->priv_ver = PRIV_VERSION_1_11_0; | ||
100 | |||
101 | cpu->cfg.ext_zfa = true; | ||
102 | @@ -XXX,XX +XXX,XX @@ static void rv64_veyron_v1_cpu_init(Object *obj) | ||
103 | CPURISCVState *env = &RISCV_CPU(obj)->env; | ||
104 | RISCVCPU *cpu = RISCV_CPU(obj); | ||
105 | |||
106 | - set_misa(env, MXL_RV64, RVG | RVC | RVS | RVU | RVH); | ||
107 | + riscv_cpu_set_misa(env, MXL_RV64, RVG | RVC | RVS | RVU | RVH); | ||
108 | env->priv_ver = PRIV_VERSION_1_12_0; | ||
109 | |||
110 | /* Enable ISA extensions */ | ||
111 | @@ -XXX,XX +XXX,XX @@ static void rv128_base_cpu_init(Object *obj) | ||
112 | } | ||
113 | CPURISCVState *env = &RISCV_CPU(obj)->env; | ||
114 | /* We set this in the realise function */ | ||
115 | - set_misa(env, MXL_RV128, 0); | ||
116 | + riscv_cpu_set_misa(env, MXL_RV128, 0); | ||
117 | /* Set latest version of privileged specification */ | ||
118 | env->priv_ver = PRIV_VERSION_LATEST; | ||
119 | #ifndef CONFIG_USER_ONLY | ||
120 | @@ -XXX,XX +XXX,XX @@ static void rv32_base_cpu_init(Object *obj) | ||
121 | { | ||
122 | CPURISCVState *env = &RISCV_CPU(obj)->env; | ||
123 | /* We set this in the realise function */ | ||
124 | - set_misa(env, MXL_RV32, 0); | ||
125 | + riscv_cpu_set_misa(env, MXL_RV32, 0); | ||
126 | /* Set latest version of privileged specification */ | ||
127 | env->priv_ver = PRIV_VERSION_LATEST; | ||
128 | #ifndef CONFIG_USER_ONLY | ||
129 | @@ -XXX,XX +XXX,XX @@ static void rv32_sifive_u_cpu_init(Object *obj) | ||
130 | { | ||
131 | RISCVCPU *cpu = RISCV_CPU(obj); | ||
132 | CPURISCVState *env = &cpu->env; | ||
133 | - set_misa(env, MXL_RV32, RVI | RVM | RVA | RVF | RVD | RVC | RVS | RVU); | ||
134 | + riscv_cpu_set_misa(env, MXL_RV32, | ||
135 | + RVI | RVM | RVA | RVF | RVD | RVC | RVS | RVU); | ||
136 | env->priv_ver = PRIV_VERSION_1_10_0; | ||
137 | #ifndef CONFIG_USER_ONLY | ||
138 | set_satp_mode_max_supported(RISCV_CPU(obj), VM_1_10_SV32); | ||
139 | @@ -XXX,XX +XXX,XX @@ static void rv32_sifive_e_cpu_init(Object *obj) | ||
140 | CPURISCVState *env = &RISCV_CPU(obj)->env; | ||
141 | RISCVCPU *cpu = RISCV_CPU(obj); | ||
142 | |||
143 | - set_misa(env, MXL_RV32, RVI | RVM | RVA | RVC | RVU); | ||
144 | + riscv_cpu_set_misa(env, MXL_RV32, RVI | RVM | RVA | RVC | RVU); | ||
145 | env->priv_ver = PRIV_VERSION_1_10_0; | ||
146 | #ifndef CONFIG_USER_ONLY | ||
147 | set_satp_mode_max_supported(cpu, VM_1_10_MBARE); | ||
148 | @@ -XXX,XX +XXX,XX @@ static void rv32_ibex_cpu_init(Object *obj) | ||
149 | CPURISCVState *env = &RISCV_CPU(obj)->env; | ||
150 | RISCVCPU *cpu = RISCV_CPU(obj); | ||
151 | |||
152 | - set_misa(env, MXL_RV32, RVI | RVM | RVC | RVU); | ||
153 | + riscv_cpu_set_misa(env, MXL_RV32, RVI | RVM | RVC | RVU); | ||
154 | env->priv_ver = PRIV_VERSION_1_11_0; | ||
155 | #ifndef CONFIG_USER_ONLY | ||
156 | set_satp_mode_max_supported(cpu, VM_1_10_MBARE); | ||
157 | @@ -XXX,XX +XXX,XX @@ static void rv32_imafcu_nommu_cpu_init(Object *obj) | ||
158 | CPURISCVState *env = &RISCV_CPU(obj)->env; | ||
159 | RISCVCPU *cpu = RISCV_CPU(obj); | ||
160 | |||
161 | - set_misa(env, MXL_RV32, RVI | RVM | RVA | RVF | RVC | RVU); | ||
162 | + riscv_cpu_set_misa(env, MXL_RV32, RVI | RVM | RVA | RVF | RVC | RVU); | ||
163 | env->priv_ver = PRIV_VERSION_1_10_0; | ||
164 | #ifndef CONFIG_USER_ONLY | ||
165 | set_satp_mode_max_supported(cpu, VM_1_10_MBARE); | ||
166 | @@ -XXX,XX +XXX,XX @@ static void riscv_init_max_cpu_extensions(Object *obj) | ||
167 | const RISCVCPUMultiExtConfig *prop; | ||
168 | |||
169 | /* Enable RVG, RVJ and RVV that are disabled by default */ | ||
170 | - set_misa(env, env->misa_mxl, env->misa_ext | RVG | RVJ | RVV); | ||
171 | + riscv_cpu_set_misa(env, env->misa_mxl, env->misa_ext | RVG | RVJ | RVV); | ||
172 | |||
173 | for (prop = riscv_cpu_extensions; prop && prop->name; prop++) { | ||
174 | isa_ext_update_enabled(cpu, prop->offset, true); | ||
175 | -- | ||
176 | 2.41.0 | ||
177 | |||
178 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
1 | 2 | ||
3 | tcg_cpu_instance_init() will be the 'cpu_instance_init' impl for the TCG | ||
4 | accelerator. It'll be called from within riscv_cpu_post_init(), via | ||
5 | accel_cpu_instance_init(), similar to what happens with KVM. In fact, to | ||
6 | preserve behavior, the implementation will be similar to what | ||
7 | riscv_cpu_post_init() already does. | ||
8 | |||
9 | In this patch we'll move riscv_cpu_add_user_properties() and | ||
10 | riscv_init_max_cpu_extensions() and all their dependencies to tcg-cpu.c. | ||
11 | All multi-extension properties code was moved. The 'multi_ext_user_opts' | ||
12 | hash table was also moved to tcg-cpu.c since it's a TCG only structure, | ||
13 | meaning that we won't have to worry about initializing a TCG hash table | ||
14 | when running a KVM CPU anymore. | ||
15 | |||
16 | riscv_cpu_add_user_properties() will remain in cpu.c for now due to how | ||
17 | much code it requires to be moved at the same time. We'll do that in the | ||
18 | next patch. | ||
19 | |||
20 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
21 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> | ||
22 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
23 | Message-ID: <20230925175709.35696-16-dbarboza@ventanamicro.com> | ||
24 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
25 | --- | ||
26 | target/riscv/cpu.h | 1 - | ||
27 | target/riscv/cpu.c | 150 ------------------------------------- | ||
28 | target/riscv/tcg/tcg-cpu.c | 149 ++++++++++++++++++++++++++++++++++++ | ||
29 | 3 files changed, 149 insertions(+), 151 deletions(-) | ||
30 | |||
31 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h | ||
32 | index XXXXXXX..XXXXXXX 100644 | ||
33 | --- a/target/riscv/cpu.h | ||
34 | +++ b/target/riscv/cpu.h | ||
35 | @@ -XXX,XX +XXX,XX @@ enum riscv_pmu_event_idx { | ||
36 | |||
37 | /* used by tcg/tcg-cpu.c*/ | ||
38 | void isa_ext_update_enabled(RISCVCPU *cpu, uint32_t ext_offset, bool en); | ||
39 | -bool cpu_cfg_ext_is_user_set(uint32_t ext_offset); | ||
40 | bool isa_ext_is_enabled(RISCVCPU *cpu, uint32_t ext_offset); | ||
41 | int cpu_cfg_ext_get_min_version(uint32_t ext_offset); | ||
42 | void riscv_cpu_set_misa(CPURISCVState *env, RISCVMXL mxl, uint32_t ext); | ||
43 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | ||
44 | index XXXXXXX..XXXXXXX 100644 | ||
45 | --- a/target/riscv/cpu.c | ||
46 | +++ b/target/riscv/cpu.c | ||
47 | @@ -XXX,XX +XXX,XX @@ static const struct isa_ext_data isa_edata_arr[] = { | ||
48 | ISA_EXT_DATA_ENTRY(xventanacondops, PRIV_VERSION_1_12_0, ext_XVentanaCondOps), | ||
49 | }; | ||
50 | |||
51 | -/* Hash that stores user set extensions */ | ||
52 | -static GHashTable *multi_ext_user_opts; | ||
53 | - | ||
54 | bool isa_ext_is_enabled(RISCVCPU *cpu, uint32_t ext_offset) | ||
55 | { | ||
56 | bool *ext_enabled = (void *)&cpu->cfg + ext_offset; | ||
57 | @@ -XXX,XX +XXX,XX @@ int cpu_cfg_ext_get_min_version(uint32_t ext_offset) | ||
58 | g_assert_not_reached(); | ||
59 | } | ||
60 | |||
61 | -bool cpu_cfg_ext_is_user_set(uint32_t ext_offset) | ||
62 | -{ | ||
63 | - return g_hash_table_contains(multi_ext_user_opts, | ||
64 | - GUINT_TO_POINTER(ext_offset)); | ||
65 | -} | ||
66 | - | ||
67 | const char * const riscv_int_regnames[] = { | ||
68 | "x0/zero", "x1/ra", "x2/sp", "x3/gp", "x4/tp", "x5/t0", "x6/t1", | ||
69 | "x7/t2", "x8/s0", "x9/s1", "x10/a0", "x11/a1", "x12/a2", "x13/a3", | ||
70 | @@ -XXX,XX +XXX,XX @@ static const char * const riscv_intr_names[] = { | ||
71 | "reserved" | ||
72 | }; | ||
73 | |||
74 | -static void riscv_cpu_add_user_properties(Object *obj); | ||
75 | -static void riscv_init_max_cpu_extensions(Object *obj); | ||
76 | - | ||
77 | const char *riscv_cpu_get_trap_name(target_ulong cause, bool async) | ||
78 | { | ||
79 | if (async) { | ||
80 | @@ -XXX,XX +XXX,XX @@ static bool riscv_cpu_is_dynamic(Object *cpu_obj) | ||
81 | return object_dynamic_cast(cpu_obj, TYPE_RISCV_DYNAMIC_CPU) != NULL; | ||
82 | } | ||
83 | |||
84 | -static bool riscv_cpu_has_max_extensions(Object *cpu_obj) | ||
85 | -{ | ||
86 | - return object_dynamic_cast(cpu_obj, TYPE_RISCV_CPU_MAX) != NULL; | ||
87 | -} | ||
88 | - | ||
89 | -static bool riscv_cpu_has_user_properties(Object *cpu_obj) | ||
90 | -{ | ||
91 | - if (kvm_enabled() && | ||
92 | - object_dynamic_cast(cpu_obj, TYPE_RISCV_CPU_HOST) != NULL) { | ||
93 | - return true; | ||
94 | - } | ||
95 | - | ||
96 | - return riscv_cpu_is_dynamic(cpu_obj); | ||
97 | -} | ||
98 | - | ||
99 | static void riscv_cpu_post_init(Object *obj) | ||
100 | { | ||
101 | accel_cpu_instance_init(CPU(obj)); | ||
102 | - | ||
103 | - if (tcg_enabled() && riscv_cpu_has_user_properties(obj)) { | ||
104 | - riscv_cpu_add_user_properties(obj); | ||
105 | - } | ||
106 | - | ||
107 | - if (riscv_cpu_has_max_extensions(obj)) { | ||
108 | - riscv_init_max_cpu_extensions(obj); | ||
109 | - } | ||
110 | } | ||
111 | |||
112 | static void riscv_cpu_init(Object *obj) | ||
113 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_init(Object *obj) | ||
114 | qdev_init_gpio_in(DEVICE(obj), riscv_cpu_set_irq, | ||
115 | IRQ_LOCAL_MAX + IRQ_LOCAL_GUEST_MAX); | ||
116 | #endif /* CONFIG_USER_ONLY */ | ||
117 | - | ||
118 | - multi_ext_user_opts = g_hash_table_new(NULL, g_direct_equal); | ||
119 | } | ||
120 | |||
121 | typedef struct RISCVCPUMisaExtConfig { | ||
122 | @@ -XXX,XX +XXX,XX @@ Property riscv_cpu_options[] = { | ||
123 | DEFINE_PROP_END_OF_LIST(), | ||
124 | }; | ||
125 | |||
126 | -static void cpu_set_multi_ext_cfg(Object *obj, Visitor *v, const char *name, | ||
127 | - void *opaque, Error **errp) | ||
128 | -{ | ||
129 | - const RISCVCPUMultiExtConfig *multi_ext_cfg = opaque; | ||
130 | - bool value; | ||
131 | - | ||
132 | - if (!visit_type_bool(v, name, &value, errp)) { | ||
133 | - return; | ||
134 | - } | ||
135 | - | ||
136 | - isa_ext_update_enabled(RISCV_CPU(obj), multi_ext_cfg->offset, value); | ||
137 | - | ||
138 | - g_hash_table_insert(multi_ext_user_opts, | ||
139 | - GUINT_TO_POINTER(multi_ext_cfg->offset), | ||
140 | - (gpointer)value); | ||
141 | -} | ||
142 | - | ||
143 | -static void cpu_get_multi_ext_cfg(Object *obj, Visitor *v, const char *name, | ||
144 | - void *opaque, Error **errp) | ||
145 | -{ | ||
146 | - const RISCVCPUMultiExtConfig *multi_ext_cfg = opaque; | ||
147 | - bool value = isa_ext_is_enabled(RISCV_CPU(obj), multi_ext_cfg->offset); | ||
148 | - | ||
149 | - visit_type_bool(v, name, &value, errp); | ||
150 | -} | ||
151 | - | ||
152 | -static void cpu_add_multi_ext_prop(Object *cpu_obj, | ||
153 | - const RISCVCPUMultiExtConfig *multi_cfg) | ||
154 | -{ | ||
155 | - object_property_add(cpu_obj, multi_cfg->name, "bool", | ||
156 | - cpu_get_multi_ext_cfg, | ||
157 | - cpu_set_multi_ext_cfg, | ||
158 | - NULL, (void *)multi_cfg); | ||
159 | - | ||
160 | - /* | ||
161 | - * Set def val directly instead of using | ||
162 | - * object_property_set_bool() to save the set() | ||
163 | - * callback hash for user inputs. | ||
164 | - */ | ||
165 | - isa_ext_update_enabled(RISCV_CPU(cpu_obj), multi_cfg->offset, | ||
166 | - multi_cfg->enabled); | ||
167 | -} | ||
168 | - | ||
169 | -static void riscv_cpu_add_multiext_prop_array(Object *obj, | ||
170 | - const RISCVCPUMultiExtConfig *array) | ||
171 | -{ | ||
172 | - const RISCVCPUMultiExtConfig *prop; | ||
173 | - | ||
174 | - g_assert(array); | ||
175 | - | ||
176 | - for (prop = array; prop && prop->name; prop++) { | ||
177 | - cpu_add_multi_ext_prop(obj, prop); | ||
178 | - } | ||
179 | -} | ||
180 | - | ||
181 | -/* | ||
182 | - * Add CPU properties with user-facing flags. | ||
183 | - * | ||
184 | - * This will overwrite existing env->misa_ext values with the | ||
185 | - * defaults set via riscv_cpu_add_misa_properties(). | ||
186 | - */ | ||
187 | -static void riscv_cpu_add_user_properties(Object *obj) | ||
188 | -{ | ||
189 | -#ifndef CONFIG_USER_ONLY | ||
190 | - riscv_add_satp_mode_properties(obj); | ||
191 | -#endif | ||
192 | - | ||
193 | - riscv_cpu_add_misa_properties(obj); | ||
194 | - | ||
195 | - riscv_cpu_add_multiext_prop_array(obj, riscv_cpu_extensions); | ||
196 | - riscv_cpu_add_multiext_prop_array(obj, riscv_cpu_vendor_exts); | ||
197 | - riscv_cpu_add_multiext_prop_array(obj, riscv_cpu_experimental_exts); | ||
198 | - | ||
199 | - for (Property *prop = riscv_cpu_options; prop && prop->name; prop++) { | ||
200 | - qdev_property_add_static(DEVICE(obj), prop); | ||
201 | - } | ||
202 | -} | ||
203 | - | ||
204 | -/* | ||
205 | - * The 'max' type CPU will have all possible ratified | ||
206 | - * non-vendor extensions enabled. | ||
207 | - */ | ||
208 | -static void riscv_init_max_cpu_extensions(Object *obj) | ||
209 | -{ | ||
210 | - RISCVCPU *cpu = RISCV_CPU(obj); | ||
211 | - CPURISCVState *env = &cpu->env; | ||
212 | - const RISCVCPUMultiExtConfig *prop; | ||
213 | - | ||
214 | - /* Enable RVG, RVJ and RVV that are disabled by default */ | ||
215 | - riscv_cpu_set_misa(env, env->misa_mxl, env->misa_ext | RVG | RVJ | RVV); | ||
216 | - | ||
217 | - for (prop = riscv_cpu_extensions; prop && prop->name; prop++) { | ||
218 | - isa_ext_update_enabled(cpu, prop->offset, true); | ||
219 | - } | ||
220 | - | ||
221 | - /* set vector version */ | ||
222 | - env->vext_ver = VEXT_VERSION_1_00_0; | ||
223 | - | ||
224 | - /* Zfinx is not compatible with F. Disable it */ | ||
225 | - isa_ext_update_enabled(cpu, CPU_CFG_OFFSET(ext_zfinx), false); | ||
226 | - isa_ext_update_enabled(cpu, CPU_CFG_OFFSET(ext_zdinx), false); | ||
227 | - isa_ext_update_enabled(cpu, CPU_CFG_OFFSET(ext_zhinx), false); | ||
228 | - isa_ext_update_enabled(cpu, CPU_CFG_OFFSET(ext_zhinxmin), false); | ||
229 | - | ||
230 | - isa_ext_update_enabled(cpu, CPU_CFG_OFFSET(ext_zce), false); | ||
231 | - isa_ext_update_enabled(cpu, CPU_CFG_OFFSET(ext_zcmp), false); | ||
232 | - isa_ext_update_enabled(cpu, CPU_CFG_OFFSET(ext_zcmt), false); | ||
233 | - | ||
234 | - if (env->misa_mxl != MXL_RV32) { | ||
235 | - isa_ext_update_enabled(cpu, CPU_CFG_OFFSET(ext_zcf), false); | ||
236 | - } | ||
237 | -} | ||
238 | - | ||
239 | static Property riscv_cpu_properties[] = { | ||
240 | DEFINE_PROP_BOOL("debug", RISCVCPU, cfg.debug, true), | ||
241 | |||
242 | diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c | ||
243 | index XXXXXXX..XXXXXXX 100644 | ||
244 | --- a/target/riscv/tcg/tcg-cpu.c | ||
245 | +++ b/target/riscv/tcg/tcg-cpu.c | ||
246 | @@ -XXX,XX +XXX,XX @@ | ||
247 | #include "pmu.h" | ||
248 | #include "time_helper.h" | ||
249 | #include "qapi/error.h" | ||
250 | +#include "qapi/visitor.h" | ||
251 | #include "qemu/accel.h" | ||
252 | #include "qemu/error-report.h" | ||
253 | #include "qemu/log.h" | ||
254 | @@ -XXX,XX +XXX,XX @@ | ||
255 | #include "hw/core/tcg-cpu-ops.h" | ||
256 | #include "tcg/tcg.h" | ||
257 | |||
258 | +/* Hash that stores user set extensions */ | ||
259 | +static GHashTable *multi_ext_user_opts; | ||
260 | + | ||
261 | +static bool cpu_cfg_ext_is_user_set(uint32_t ext_offset) | ||
262 | +{ | ||
263 | + return g_hash_table_contains(multi_ext_user_opts, | ||
264 | + GUINT_TO_POINTER(ext_offset)); | ||
265 | +} | ||
266 | + | ||
267 | static void riscv_cpu_synchronize_from_tb(CPUState *cs, | ||
268 | const TranslationBlock *tb) | ||
269 | { | ||
270 | @@ -XXX,XX +XXX,XX @@ static bool tcg_cpu_realize(CPUState *cs, Error **errp) | ||
271 | return true; | ||
272 | } | ||
273 | |||
274 | +static void cpu_set_multi_ext_cfg(Object *obj, Visitor *v, const char *name, | ||
275 | + void *opaque, Error **errp) | ||
276 | +{ | ||
277 | + const RISCVCPUMultiExtConfig *multi_ext_cfg = opaque; | ||
278 | + bool value; | ||
279 | + | ||
280 | + if (!visit_type_bool(v, name, &value, errp)) { | ||
281 | + return; | ||
282 | + } | ||
283 | + | ||
284 | + isa_ext_update_enabled(RISCV_CPU(obj), multi_ext_cfg->offset, value); | ||
285 | + | ||
286 | + g_hash_table_insert(multi_ext_user_opts, | ||
287 | + GUINT_TO_POINTER(multi_ext_cfg->offset), | ||
288 | + (gpointer)value); | ||
289 | +} | ||
290 | + | ||
291 | +static void cpu_get_multi_ext_cfg(Object *obj, Visitor *v, const char *name, | ||
292 | + void *opaque, Error **errp) | ||
293 | +{ | ||
294 | + const RISCVCPUMultiExtConfig *multi_ext_cfg = opaque; | ||
295 | + bool value = isa_ext_is_enabled(RISCV_CPU(obj), multi_ext_cfg->offset); | ||
296 | + | ||
297 | + visit_type_bool(v, name, &value, errp); | ||
298 | +} | ||
299 | + | ||
300 | +static void cpu_add_multi_ext_prop(Object *cpu_obj, | ||
301 | + const RISCVCPUMultiExtConfig *multi_cfg) | ||
302 | +{ | ||
303 | + object_property_add(cpu_obj, multi_cfg->name, "bool", | ||
304 | + cpu_get_multi_ext_cfg, | ||
305 | + cpu_set_multi_ext_cfg, | ||
306 | + NULL, (void *)multi_cfg); | ||
307 | + | ||
308 | + /* | ||
309 | + * Set def val directly instead of using | ||
310 | + * object_property_set_bool() to save the set() | ||
311 | + * callback hash for user inputs. | ||
312 | + */ | ||
313 | + isa_ext_update_enabled(RISCV_CPU(cpu_obj), multi_cfg->offset, | ||
314 | + multi_cfg->enabled); | ||
315 | +} | ||
316 | + | ||
317 | +static void riscv_cpu_add_multiext_prop_array(Object *obj, | ||
318 | + const RISCVCPUMultiExtConfig *array) | ||
319 | +{ | ||
320 | + const RISCVCPUMultiExtConfig *prop; | ||
321 | + | ||
322 | + g_assert(array); | ||
323 | + | ||
324 | + for (prop = array; prop && prop->name; prop++) { | ||
325 | + cpu_add_multi_ext_prop(obj, prop); | ||
326 | + } | ||
327 | +} | ||
328 | + | ||
329 | +/* | ||
330 | + * Add CPU properties with user-facing flags. | ||
331 | + * | ||
332 | + * This will overwrite existing env->misa_ext values with the | ||
333 | + * defaults set via riscv_cpu_add_misa_properties(). | ||
334 | + */ | ||
335 | +static void riscv_cpu_add_user_properties(Object *obj) | ||
336 | +{ | ||
337 | +#ifndef CONFIG_USER_ONLY | ||
338 | + riscv_add_satp_mode_properties(obj); | ||
339 | +#endif | ||
340 | + | ||
341 | + riscv_cpu_add_misa_properties(obj); | ||
342 | + | ||
343 | + riscv_cpu_add_multiext_prop_array(obj, riscv_cpu_extensions); | ||
344 | + riscv_cpu_add_multiext_prop_array(obj, riscv_cpu_vendor_exts); | ||
345 | + riscv_cpu_add_multiext_prop_array(obj, riscv_cpu_experimental_exts); | ||
346 | + | ||
347 | + for (Property *prop = riscv_cpu_options; prop && prop->name; prop++) { | ||
348 | + qdev_property_add_static(DEVICE(obj), prop); | ||
349 | + } | ||
350 | +} | ||
351 | + | ||
352 | +/* | ||
353 | + * The 'max' type CPU will have all possible ratified | ||
354 | + * non-vendor extensions enabled. | ||
355 | + */ | ||
356 | +static void riscv_init_max_cpu_extensions(Object *obj) | ||
357 | +{ | ||
358 | + RISCVCPU *cpu = RISCV_CPU(obj); | ||
359 | + CPURISCVState *env = &cpu->env; | ||
360 | + const RISCVCPUMultiExtConfig *prop; | ||
361 | + | ||
362 | + /* Enable RVG, RVJ and RVV that are disabled by default */ | ||
363 | + riscv_cpu_set_misa(env, env->misa_mxl, env->misa_ext | RVG | RVJ | RVV); | ||
364 | + | ||
365 | + for (prop = riscv_cpu_extensions; prop && prop->name; prop++) { | ||
366 | + isa_ext_update_enabled(cpu, prop->offset, true); | ||
367 | + } | ||
368 | + | ||
369 | + /* set vector version */ | ||
370 | + env->vext_ver = VEXT_VERSION_1_00_0; | ||
371 | + | ||
372 | + /* Zfinx is not compatible with F. Disable it */ | ||
373 | + isa_ext_update_enabled(cpu, CPU_CFG_OFFSET(ext_zfinx), false); | ||
374 | + isa_ext_update_enabled(cpu, CPU_CFG_OFFSET(ext_zdinx), false); | ||
375 | + isa_ext_update_enabled(cpu, CPU_CFG_OFFSET(ext_zhinx), false); | ||
376 | + isa_ext_update_enabled(cpu, CPU_CFG_OFFSET(ext_zhinxmin), false); | ||
377 | + | ||
378 | + isa_ext_update_enabled(cpu, CPU_CFG_OFFSET(ext_zce), false); | ||
379 | + isa_ext_update_enabled(cpu, CPU_CFG_OFFSET(ext_zcmp), false); | ||
380 | + isa_ext_update_enabled(cpu, CPU_CFG_OFFSET(ext_zcmt), false); | ||
381 | + | ||
382 | + if (env->misa_mxl != MXL_RV32) { | ||
383 | + isa_ext_update_enabled(cpu, CPU_CFG_OFFSET(ext_zcf), false); | ||
384 | + } | ||
385 | +} | ||
386 | + | ||
387 | +static bool riscv_cpu_has_max_extensions(Object *cpu_obj) | ||
388 | +{ | ||
389 | + return object_dynamic_cast(cpu_obj, TYPE_RISCV_CPU_MAX) != NULL; | ||
390 | +} | ||
391 | + | ||
392 | +static bool riscv_cpu_has_user_properties(Object *cpu_obj) | ||
393 | +{ | ||
394 | + return object_dynamic_cast(cpu_obj, TYPE_RISCV_DYNAMIC_CPU) != NULL; | ||
395 | +} | ||
396 | + | ||
397 | +static void tcg_cpu_instance_init(CPUState *cs) | ||
398 | +{ | ||
399 | + RISCVCPU *cpu = RISCV_CPU(cs); | ||
400 | + Object *obj = OBJECT(cpu); | ||
401 | + | ||
402 | + if (riscv_cpu_has_user_properties(obj)) { | ||
403 | + multi_ext_user_opts = g_hash_table_new(NULL, g_direct_equal); | ||
404 | + riscv_cpu_add_user_properties(obj); | ||
405 | + } | ||
406 | + | ||
407 | + if (riscv_cpu_has_max_extensions(obj)) { | ||
408 | + riscv_init_max_cpu_extensions(obj); | ||
409 | + } | ||
410 | +} | ||
411 | + | ||
412 | static void tcg_cpu_init_ops(AccelCPUClass *accel_cpu, CPUClass *cc) | ||
413 | { | ||
414 | /* | ||
415 | @@ -XXX,XX +XXX,XX @@ static void tcg_cpu_accel_class_init(ObjectClass *oc, void *data) | ||
416 | AccelCPUClass *acc = ACCEL_CPU_CLASS(oc); | ||
417 | |||
418 | acc->cpu_class_init = tcg_cpu_class_init; | ||
419 | + acc->cpu_instance_init = tcg_cpu_instance_init; | ||
420 | acc->cpu_target_realize = tcg_cpu_realize; | ||
421 | } | ||
422 | |||
423 | -- | ||
424 | 2.41.0 | diff view generated by jsdifflib |
1 | From: Weiwei Li <liweiwei@iscas.ac.cn> | 1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
---|---|---|---|
2 | 2 | ||
3 | - reuse partial instructions of zbc extension, update extension check for them | 3 | The array isn't marked as 'const' because we're initializing their |
4 | elements in riscv_cpu_add_misa_properties(), 'name' and 'description' | ||
5 | fields. | ||
4 | 6 | ||
5 | Signed-off-by: Weiwei Li <liweiwei@iscas.ac.cn> | 7 | In a closer look we can see that we're not using these 2 fields after |
6 | Signed-off-by: Junqiang Wang <wangjunqiang@iscas.ac.cn> | 8 | creating the MISA properties. And we can create the properties by using |
9 | riscv_get_misa_ext_name() and riscv_get_misa_ext_description() | ||
10 | directly. | ||
11 | |||
12 | Remove the 'name' and 'description' fields from RISCVCPUMisaExtConfig | ||
13 | and make misa_ext_cfgs[] a const array. | ||
14 | |||
15 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
16 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> | ||
7 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 17 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
8 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 18 | Message-ID: <20230925175709.35696-17-dbarboza@ventanamicro.com> |
9 | Message-Id: <20220423023510.30794-4-liweiwei@iscas.ac.cn> | ||
10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 19 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
11 | --- | 20 | --- |
12 | target/riscv/insn32.decode | 3 ++- | 21 | target/riscv/cpu.c | 21 ++++++++------------- |
13 | target/riscv/insn_trans/trans_rvb.c.inc | 4 ++-- | 22 | 1 file changed, 8 insertions(+), 13 deletions(-) |
14 | 2 files changed, 4 insertions(+), 3 deletions(-) | ||
15 | 23 | ||
16 | diff --git a/target/riscv/insn32.decode b/target/riscv/insn32.decode | 24 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c |
17 | index XXXXXXX..XXXXXXX 100644 | 25 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/target/riscv/insn32.decode | 26 | --- a/target/riscv/cpu.c |
19 | +++ b/target/riscv/insn32.decode | 27 | +++ b/target/riscv/cpu.c |
20 | @@ -XXX,XX +XXX,XX @@ clzw 0110000 00000 ..... 001 ..... 0011011 @r2 | 28 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_init(Object *obj) |
21 | ctzw 0110000 00001 ..... 001 ..... 0011011 @r2 | ||
22 | cpopw 0110000 00010 ..... 001 ..... 0011011 @r2 | ||
23 | |||
24 | -# *** RV32 Zbc Standard Extension *** | ||
25 | +# *** RV32 Zbc/Zbkc Standard Extension *** | ||
26 | clmul 0000101 .......... 001 ..... 0110011 @r | ||
27 | clmulh 0000101 .......... 011 ..... 0110011 @r | ||
28 | +# *** RV32 extra Zbc Standard Extension *** | ||
29 | clmulr 0000101 .......... 010 ..... 0110011 @r | ||
30 | |||
31 | # *** RV32 Zbs Standard Extension *** | ||
32 | diff --git a/target/riscv/insn_trans/trans_rvb.c.inc b/target/riscv/insn_trans/trans_rvb.c.inc | ||
33 | index XXXXXXX..XXXXXXX 100644 | ||
34 | --- a/target/riscv/insn_trans/trans_rvb.c.inc | ||
35 | +++ b/target/riscv/insn_trans/trans_rvb.c.inc | ||
36 | @@ -XXX,XX +XXX,XX @@ static bool trans_slli_uw(DisasContext *ctx, arg_slli_uw *a) | ||
37 | |||
38 | static bool trans_clmul(DisasContext *ctx, arg_clmul *a) | ||
39 | { | ||
40 | - REQUIRE_ZBC(ctx); | ||
41 | + REQUIRE_EITHER_EXT(ctx, zbc, zbkc); | ||
42 | return gen_arith(ctx, a, EXT_NONE, gen_helper_clmul, NULL); | ||
43 | } | 29 | } |
44 | 30 | ||
45 | @@ -XXX,XX +XXX,XX @@ static void gen_clmulh(TCGv dst, TCGv src1, TCGv src2) | 31 | typedef struct RISCVCPUMisaExtConfig { |
46 | 32 | - const char *name; | |
47 | static bool trans_clmulh(DisasContext *ctx, arg_clmulr *a) | 33 | - const char *description; |
48 | { | 34 | target_ulong misa_bit; |
49 | - REQUIRE_ZBC(ctx); | 35 | bool enabled; |
50 | + REQUIRE_EITHER_EXT(ctx, zbc, zbkc); | 36 | } RISCVCPUMisaExtConfig; |
51 | return gen_arith(ctx, a, EXT_NONE, gen_clmulh, NULL); | 37 | @@ -XXX,XX +XXX,XX @@ const char *riscv_get_misa_ext_description(uint32_t bit) |
38 | #define MISA_CFG(_bit, _enabled) \ | ||
39 | {.misa_bit = _bit, .enabled = _enabled} | ||
40 | |||
41 | -static RISCVCPUMisaExtConfig misa_ext_cfgs[] = { | ||
42 | +static const RISCVCPUMisaExtConfig misa_ext_cfgs[] = { | ||
43 | MISA_CFG(RVA, true), | ||
44 | MISA_CFG(RVC, true), | ||
45 | MISA_CFG(RVD, true), | ||
46 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_add_misa_properties(Object *cpu_obj) | ||
47 | int i; | ||
48 | |||
49 | for (i = 0; i < ARRAY_SIZE(misa_ext_cfgs); i++) { | ||
50 | - RISCVCPUMisaExtConfig *misa_cfg = &misa_ext_cfgs[i]; | ||
51 | + const RISCVCPUMisaExtConfig *misa_cfg = &misa_ext_cfgs[i]; | ||
52 | int bit = misa_cfg->misa_bit; | ||
53 | - | ||
54 | - misa_cfg->name = riscv_get_misa_ext_name(bit); | ||
55 | - misa_cfg->description = riscv_get_misa_ext_description(bit); | ||
56 | + const char *name = riscv_get_misa_ext_name(bit); | ||
57 | + const char *desc = riscv_get_misa_ext_description(bit); | ||
58 | |||
59 | /* Check if KVM already created the property */ | ||
60 | - if (object_property_find(cpu_obj, misa_cfg->name)) { | ||
61 | + if (object_property_find(cpu_obj, name)) { | ||
62 | continue; | ||
63 | } | ||
64 | |||
65 | - object_property_add(cpu_obj, misa_cfg->name, "bool", | ||
66 | + object_property_add(cpu_obj, name, "bool", | ||
67 | cpu_get_misa_ext_cfg, | ||
68 | cpu_set_misa_ext_cfg, | ||
69 | NULL, (void *)misa_cfg); | ||
70 | - object_property_set_description(cpu_obj, misa_cfg->name, | ||
71 | - misa_cfg->description); | ||
72 | - object_property_set_bool(cpu_obj, misa_cfg->name, | ||
73 | - misa_cfg->enabled, NULL); | ||
74 | + object_property_set_description(cpu_obj, name, desc); | ||
75 | + object_property_set_bool(cpu_obj, name, misa_cfg->enabled, NULL); | ||
76 | } | ||
52 | } | 77 | } |
53 | 78 | ||
54 | -- | 79 | -- |
55 | 2.35.1 | 80 | 2.41.0 | diff view generated by jsdifflib |
1 | From: Weiwei Li <liweiwei@iscas.ac.cn> | 1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
---|---|---|---|
2 | 2 | ||
3 | - add sha512sum0, sha512sig0, sha512sum1 and sha512sig1 instructions | 3 | All code related to MISA TCG properties is also moved. |
4 | 4 | ||
5 | Co-authored-by: Zewen Ye <lustrew@foxmail.com> | 5 | At this point, all TCG properties handling is done in tcg-cpu.c, all KVM |
6 | Signed-off-by: Weiwei Li <liweiwei@iscas.ac.cn> | 6 | properties handling is done in kvm-cpu.c. |
7 | Signed-off-by: Junqiang Wang <wangjunqiang@iscas.ac.cn> | 7 | |
8 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 8 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
9 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> | ||
9 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 10 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
10 | Message-Id: <20220423023510.30794-11-liweiwei@iscas.ac.cn> | 11 | Message-ID: <20230925175709.35696-18-dbarboza@ventanamicro.com> |
11 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 12 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
12 | --- | 13 | --- |
13 | target/riscv/insn32.decode | 5 +++ | 14 | target/riscv/cpu.h | 1 - |
14 | target/riscv/insn_trans/trans_rvk.c.inc | 53 +++++++++++++++++++++++++ | 15 | target/riscv/cpu.c | 90 -------------------------------------- |
15 | 2 files changed, 58 insertions(+) | 16 | target/riscv/tcg/tcg-cpu.c | 90 ++++++++++++++++++++++++++++++++++++++ |
16 | 17 | 3 files changed, 90 insertions(+), 91 deletions(-) | |
17 | diff --git a/target/riscv/insn32.decode b/target/riscv/insn32.decode | 18 | |
19 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h | ||
18 | index XXXXXXX..XXXXXXX 100644 | 20 | index XXXXXXX..XXXXXXX 100644 |
19 | --- a/target/riscv/insn32.decode | 21 | --- a/target/riscv/cpu.h |
20 | +++ b/target/riscv/insn32.decode | 22 | +++ b/target/riscv/cpu.h |
21 | @@ -XXX,XX +XXX,XX @@ sha512sig0l 01 01010 ..... ..... 000 ..... 0110011 @r | 23 | @@ -XXX,XX +XXX,XX @@ extern const RISCVCPUMultiExtConfig riscv_cpu_vendor_exts[]; |
22 | sha512sig0h 01 01110 ..... ..... 000 ..... 0110011 @r | 24 | extern const RISCVCPUMultiExtConfig riscv_cpu_experimental_exts[]; |
23 | sha512sig1l 01 01011 ..... ..... 000 ..... 0110011 @r | 25 | extern Property riscv_cpu_options[]; |
24 | sha512sig1h 01 01111 ..... ..... 000 ..... 0110011 @r | 26 | |
25 | +# *** RV64 Zknh Standard Extension *** | 27 | -void riscv_cpu_add_misa_properties(Object *cpu_obj); |
26 | +sha512sig0 00 01000 00110 ..... 001 ..... 0010011 @r2 | 28 | void riscv_add_satp_mode_properties(Object *obj); |
27 | +sha512sig1 00 01000 00111 ..... 001 ..... 0010011 @r2 | 29 | |
28 | +sha512sum0 00 01000 00100 ..... 001 ..... 0010011 @r2 | 30 | /* CSR function table */ |
29 | +sha512sum1 00 01000 00101 ..... 001 ..... 0010011 @r2 | 31 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c |
30 | diff --git a/target/riscv/insn_trans/trans_rvk.c.inc b/target/riscv/insn_trans/trans_rvk.c.inc | ||
31 | index XXXXXXX..XXXXXXX 100644 | 32 | index XXXXXXX..XXXXXXX 100644 |
32 | --- a/target/riscv/insn_trans/trans_rvk.c.inc | 33 | --- a/target/riscv/cpu.c |
33 | +++ b/target/riscv/insn_trans/trans_rvk.c.inc | 34 | +++ b/target/riscv/cpu.c |
34 | @@ -XXX,XX +XXX,XX @@ static bool trans_sha512sig1h(DisasContext *ctx, arg_sha512sig1h *a) | 35 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_init(Object *obj) |
35 | REQUIRE_ZKNH(ctx); | 36 | #endif /* CONFIG_USER_ONLY */ |
36 | return gen_sha512h_rv32(ctx, a, EXT_NONE, tcg_gen_rotli_i64, 3, 6, 19); | ||
37 | } | 37 | } |
38 | + | 38 | |
39 | +static bool gen_sha512_rv64(DisasContext *ctx, arg_r2 *a, DisasExtend ext, | 39 | -typedef struct RISCVCPUMisaExtConfig { |
40 | + void (*func)(TCGv_i64, TCGv_i64, int64_t), | 40 | - target_ulong misa_bit; |
41 | + int64_t num1, int64_t num2, int64_t num3) | 41 | - bool enabled; |
42 | -} RISCVCPUMisaExtConfig; | ||
43 | - | ||
44 | -static void cpu_set_misa_ext_cfg(Object *obj, Visitor *v, const char *name, | ||
45 | - void *opaque, Error **errp) | ||
46 | -{ | ||
47 | - const RISCVCPUMisaExtConfig *misa_ext_cfg = opaque; | ||
48 | - target_ulong misa_bit = misa_ext_cfg->misa_bit; | ||
49 | - RISCVCPU *cpu = RISCV_CPU(obj); | ||
50 | - CPURISCVState *env = &cpu->env; | ||
51 | - bool value; | ||
52 | - | ||
53 | - if (!visit_type_bool(v, name, &value, errp)) { | ||
54 | - return; | ||
55 | - } | ||
56 | - | ||
57 | - if (value) { | ||
58 | - env->misa_ext |= misa_bit; | ||
59 | - env->misa_ext_mask |= misa_bit; | ||
60 | - } else { | ||
61 | - env->misa_ext &= ~misa_bit; | ||
62 | - env->misa_ext_mask &= ~misa_bit; | ||
63 | - } | ||
64 | -} | ||
65 | - | ||
66 | -static void cpu_get_misa_ext_cfg(Object *obj, Visitor *v, const char *name, | ||
67 | - void *opaque, Error **errp) | ||
68 | -{ | ||
69 | - const RISCVCPUMisaExtConfig *misa_ext_cfg = opaque; | ||
70 | - target_ulong misa_bit = misa_ext_cfg->misa_bit; | ||
71 | - RISCVCPU *cpu = RISCV_CPU(obj); | ||
72 | - CPURISCVState *env = &cpu->env; | ||
73 | - bool value; | ||
74 | - | ||
75 | - value = env->misa_ext & misa_bit; | ||
76 | - | ||
77 | - visit_type_bool(v, name, &value, errp); | ||
78 | -} | ||
79 | - | ||
80 | typedef struct misa_ext_info { | ||
81 | const char *name; | ||
82 | const char *description; | ||
83 | @@ -XXX,XX +XXX,XX @@ const char *riscv_get_misa_ext_description(uint32_t bit) | ||
84 | return val; | ||
85 | } | ||
86 | |||
87 | -#define MISA_CFG(_bit, _enabled) \ | ||
88 | - {.misa_bit = _bit, .enabled = _enabled} | ||
89 | - | ||
90 | -static const RISCVCPUMisaExtConfig misa_ext_cfgs[] = { | ||
91 | - MISA_CFG(RVA, true), | ||
92 | - MISA_CFG(RVC, true), | ||
93 | - MISA_CFG(RVD, true), | ||
94 | - MISA_CFG(RVF, true), | ||
95 | - MISA_CFG(RVI, true), | ||
96 | - MISA_CFG(RVE, false), | ||
97 | - MISA_CFG(RVM, true), | ||
98 | - MISA_CFG(RVS, true), | ||
99 | - MISA_CFG(RVU, true), | ||
100 | - MISA_CFG(RVH, true), | ||
101 | - MISA_CFG(RVJ, false), | ||
102 | - MISA_CFG(RVV, false), | ||
103 | - MISA_CFG(RVG, false), | ||
104 | -}; | ||
105 | - | ||
106 | -/* | ||
107 | - * We do not support user choice tracking for MISA | ||
108 | - * extensions yet because, so far, we do not silently | ||
109 | - * change MISA bits during realize() (RVG enables MISA | ||
110 | - * bits but the user is warned about it). | ||
111 | - */ | ||
112 | -void riscv_cpu_add_misa_properties(Object *cpu_obj) | ||
113 | -{ | ||
114 | - int i; | ||
115 | - | ||
116 | - for (i = 0; i < ARRAY_SIZE(misa_ext_cfgs); i++) { | ||
117 | - const RISCVCPUMisaExtConfig *misa_cfg = &misa_ext_cfgs[i]; | ||
118 | - int bit = misa_cfg->misa_bit; | ||
119 | - const char *name = riscv_get_misa_ext_name(bit); | ||
120 | - const char *desc = riscv_get_misa_ext_description(bit); | ||
121 | - | ||
122 | - /* Check if KVM already created the property */ | ||
123 | - if (object_property_find(cpu_obj, name)) { | ||
124 | - continue; | ||
125 | - } | ||
126 | - | ||
127 | - object_property_add(cpu_obj, name, "bool", | ||
128 | - cpu_get_misa_ext_cfg, | ||
129 | - cpu_set_misa_ext_cfg, | ||
130 | - NULL, (void *)misa_cfg); | ||
131 | - object_property_set_description(cpu_obj, name, desc); | ||
132 | - object_property_set_bool(cpu_obj, name, misa_cfg->enabled, NULL); | ||
133 | - } | ||
134 | -} | ||
135 | - | ||
136 | #define MULTI_EXT_CFG_BOOL(_name, _prop, _defval) \ | ||
137 | {.name = _name, .offset = CPU_CFG_OFFSET(_prop), \ | ||
138 | .enabled = _defval} | ||
139 | diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c | ||
140 | index XXXXXXX..XXXXXXX 100644 | ||
141 | --- a/target/riscv/tcg/tcg-cpu.c | ||
142 | +++ b/target/riscv/tcg/tcg-cpu.c | ||
143 | @@ -XXX,XX +XXX,XX @@ static bool tcg_cpu_realize(CPUState *cs, Error **errp) | ||
144 | return true; | ||
145 | } | ||
146 | |||
147 | +typedef struct RISCVCPUMisaExtConfig { | ||
148 | + target_ulong misa_bit; | ||
149 | + bool enabled; | ||
150 | +} RISCVCPUMisaExtConfig; | ||
151 | + | ||
152 | +static void cpu_set_misa_ext_cfg(Object *obj, Visitor *v, const char *name, | ||
153 | + void *opaque, Error **errp) | ||
42 | +{ | 154 | +{ |
43 | + TCGv dest = dest_gpr(ctx, a->rd); | 155 | + const RISCVCPUMisaExtConfig *misa_ext_cfg = opaque; |
44 | + TCGv src1 = get_gpr(ctx, a->rs1, ext); | 156 | + target_ulong misa_bit = misa_ext_cfg->misa_bit; |
45 | + TCGv_i64 t0 = tcg_temp_new_i64(); | 157 | + RISCVCPU *cpu = RISCV_CPU(obj); |
46 | + TCGv_i64 t1 = tcg_temp_new_i64(); | 158 | + CPURISCVState *env = &cpu->env; |
47 | + TCGv_i64 t2 = tcg_temp_new_i64(); | 159 | + bool value; |
48 | + | 160 | + |
49 | + tcg_gen_extu_tl_i64(t0, src1); | 161 | + if (!visit_type_bool(v, name, &value, errp)) { |
50 | + tcg_gen_rotri_i64(t1, t0, num1); | 162 | + return; |
51 | + tcg_gen_rotri_i64(t2, t0, num2); | 163 | + } |
52 | + tcg_gen_xor_i64(t1, t1, t2); | 164 | + |
53 | + func(t2, t0, num3); | 165 | + if (value) { |
54 | + tcg_gen_xor_i64(t1, t1, t2); | 166 | + env->misa_ext |= misa_bit; |
55 | + tcg_gen_trunc_i64_tl(dest, t1); | 167 | + env->misa_ext_mask |= misa_bit; |
56 | + | 168 | + } else { |
57 | + gen_set_gpr(ctx, a->rd, dest); | 169 | + env->misa_ext &= ~misa_bit; |
58 | + tcg_temp_free_i64(t0); | 170 | + env->misa_ext_mask &= ~misa_bit; |
59 | + tcg_temp_free_i64(t1); | 171 | + } |
60 | + tcg_temp_free_i64(t2); | ||
61 | + return true; | ||
62 | +} | 172 | +} |
63 | + | 173 | + |
64 | +static bool trans_sha512sig0(DisasContext *ctx, arg_sha512sig0 *a) | 174 | +static void cpu_get_misa_ext_cfg(Object *obj, Visitor *v, const char *name, |
175 | + void *opaque, Error **errp) | ||
65 | +{ | 176 | +{ |
66 | + REQUIRE_64BIT(ctx); | 177 | + const RISCVCPUMisaExtConfig *misa_ext_cfg = opaque; |
67 | + REQUIRE_ZKNH(ctx); | 178 | + target_ulong misa_bit = misa_ext_cfg->misa_bit; |
68 | + return gen_sha512_rv64(ctx, a, EXT_NONE, tcg_gen_shri_i64, 1, 8, 7); | 179 | + RISCVCPU *cpu = RISCV_CPU(obj); |
180 | + CPURISCVState *env = &cpu->env; | ||
181 | + bool value; | ||
182 | + | ||
183 | + value = env->misa_ext & misa_bit; | ||
184 | + | ||
185 | + visit_type_bool(v, name, &value, errp); | ||
69 | +} | 186 | +} |
70 | + | 187 | + |
71 | +static bool trans_sha512sig1(DisasContext *ctx, arg_sha512sig1 *a) | 188 | +#define MISA_CFG(_bit, _enabled) \ |
189 | + {.misa_bit = _bit, .enabled = _enabled} | ||
190 | + | ||
191 | +static const RISCVCPUMisaExtConfig misa_ext_cfgs[] = { | ||
192 | + MISA_CFG(RVA, true), | ||
193 | + MISA_CFG(RVC, true), | ||
194 | + MISA_CFG(RVD, true), | ||
195 | + MISA_CFG(RVF, true), | ||
196 | + MISA_CFG(RVI, true), | ||
197 | + MISA_CFG(RVE, false), | ||
198 | + MISA_CFG(RVM, true), | ||
199 | + MISA_CFG(RVS, true), | ||
200 | + MISA_CFG(RVU, true), | ||
201 | + MISA_CFG(RVH, true), | ||
202 | + MISA_CFG(RVJ, false), | ||
203 | + MISA_CFG(RVV, false), | ||
204 | + MISA_CFG(RVG, false), | ||
205 | +}; | ||
206 | + | ||
207 | +/* | ||
208 | + * We do not support user choice tracking for MISA | ||
209 | + * extensions yet because, so far, we do not silently | ||
210 | + * change MISA bits during realize() (RVG enables MISA | ||
211 | + * bits but the user is warned about it). | ||
212 | + */ | ||
213 | +static void riscv_cpu_add_misa_properties(Object *cpu_obj) | ||
72 | +{ | 214 | +{ |
73 | + REQUIRE_64BIT(ctx); | 215 | + int i; |
74 | + REQUIRE_ZKNH(ctx); | 216 | + |
75 | + return gen_sha512_rv64(ctx, a, EXT_NONE, tcg_gen_shri_i64, 19, 61, 6); | 217 | + for (i = 0; i < ARRAY_SIZE(misa_ext_cfgs); i++) { |
218 | + const RISCVCPUMisaExtConfig *misa_cfg = &misa_ext_cfgs[i]; | ||
219 | + int bit = misa_cfg->misa_bit; | ||
220 | + const char *name = riscv_get_misa_ext_name(bit); | ||
221 | + const char *desc = riscv_get_misa_ext_description(bit); | ||
222 | + | ||
223 | + /* Check if KVM already created the property */ | ||
224 | + if (object_property_find(cpu_obj, name)) { | ||
225 | + continue; | ||
226 | + } | ||
227 | + | ||
228 | + object_property_add(cpu_obj, name, "bool", | ||
229 | + cpu_get_misa_ext_cfg, | ||
230 | + cpu_set_misa_ext_cfg, | ||
231 | + NULL, (void *)misa_cfg); | ||
232 | + object_property_set_description(cpu_obj, name, desc); | ||
233 | + object_property_set_bool(cpu_obj, name, misa_cfg->enabled, NULL); | ||
234 | + } | ||
76 | +} | 235 | +} |
77 | + | 236 | + |
78 | +static bool trans_sha512sum0(DisasContext *ctx, arg_sha512sum0 *a) | 237 | static void cpu_set_multi_ext_cfg(Object *obj, Visitor *v, const char *name, |
79 | +{ | 238 | void *opaque, Error **errp) |
80 | + REQUIRE_64BIT(ctx); | 239 | { |
81 | + REQUIRE_ZKNH(ctx); | ||
82 | + return gen_sha512_rv64(ctx, a, EXT_NONE, tcg_gen_rotri_i64, 28, 34, 39); | ||
83 | +} | ||
84 | + | ||
85 | +static bool trans_sha512sum1(DisasContext *ctx, arg_sha512sum1 *a) | ||
86 | +{ | ||
87 | + REQUIRE_64BIT(ctx); | ||
88 | + REQUIRE_ZKNH(ctx); | ||
89 | + return gen_sha512_rv64(ctx, a, EXT_NONE, tcg_gen_rotri_i64, 14, 18, 41); | ||
90 | +} | ||
91 | -- | 240 | -- |
92 | 2.35.1 | 241 | 2.41.0 | diff view generated by jsdifflib |
1 | From: Weiwei Li <liweiwei@iscas.ac.cn> | 1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
---|---|---|---|
2 | 2 | ||
3 | Signed-off-by: Weiwei Li <liweiwei@iscas.ac.cn> | 3 | This array will be read by the TCG accel class, allowing it to handle |
4 | Signed-off-by: Junqiang Wang <wangjunqiang@iscas.ac.cn> | 4 | priv spec verifications on its own. The array will remain here in cpu.c |
5 | Acked-by: Alistair Francis <alistair.francis@wdc.com> | 5 | because it's also used by the riscv,isa string function. |
6 | Message-Id: <20220423023510.30794-2-liweiwei@iscas.ac.cn> | 6 | |
7 | To export it we'll finish it with an empty element since ARRAY_SIZE() | ||
8 | won't work outside of cpu.c. Get rid of its ARRAY_SIZE() usage now to | ||
9 | alleviate the changes for the next patch. | ||
10 | |||
11 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
12 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> | ||
13 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
14 | Message-ID: <20230925175709.35696-19-dbarboza@ventanamicro.com> | ||
7 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 15 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
8 | --- | 16 | --- |
9 | target/riscv/cpu.h | 13 +++++++++++++ | 17 | target/riscv/cpu.h | 7 +++++++ |
10 | target/riscv/cpu.c | 23 +++++++++++++++++++++++ | 18 | target/riscv/cpu.c | 47 +++++++++++++++++++++------------------------- |
11 | 2 files changed, 36 insertions(+) | 19 | 2 files changed, 28 insertions(+), 26 deletions(-) |
12 | 20 | ||
13 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h | 21 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h |
14 | index XXXXXXX..XXXXXXX 100644 | 22 | index XXXXXXX..XXXXXXX 100644 |
15 | --- a/target/riscv/cpu.h | 23 | --- a/target/riscv/cpu.h |
16 | +++ b/target/riscv/cpu.h | 24 | +++ b/target/riscv/cpu.h |
17 | @@ -XXX,XX +XXX,XX @@ struct RISCVCPUConfig { | 25 | @@ -XXX,XX +XXX,XX @@ extern const RISCVCPUMultiExtConfig riscv_cpu_vendor_exts[]; |
18 | bool ext_zba; | 26 | extern const RISCVCPUMultiExtConfig riscv_cpu_experimental_exts[]; |
19 | bool ext_zbb; | 27 | extern Property riscv_cpu_options[]; |
20 | bool ext_zbc; | 28 | |
21 | + bool ext_zbkb; | 29 | +typedef struct isa_ext_data { |
22 | + bool ext_zbkc; | 30 | + const char *name; |
23 | + bool ext_zbkx; | 31 | + int min_version; |
24 | bool ext_zbs; | 32 | + int ext_enable_offset; |
25 | + bool ext_zk; | 33 | +} RISCVIsaExtData; |
26 | + bool ext_zkn; | 34 | +extern const RISCVIsaExtData isa_edata_arr[]; |
27 | + bool ext_zknd; | 35 | + |
28 | + bool ext_zkne; | 36 | void riscv_add_satp_mode_properties(Object *obj); |
29 | + bool ext_zknh; | 37 | |
30 | + bool ext_zkr; | 38 | /* CSR function table */ |
31 | + bool ext_zks; | ||
32 | + bool ext_zksed; | ||
33 | + bool ext_zksh; | ||
34 | + bool ext_zkt; | ||
35 | bool ext_counters; | ||
36 | bool ext_ifencei; | ||
37 | bool ext_icsr; | ||
38 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | 39 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c |
39 | index XXXXXXX..XXXXXXX 100644 | 40 | index XXXXXXX..XXXXXXX 100644 |
40 | --- a/target/riscv/cpu.c | 41 | --- a/target/riscv/cpu.c |
41 | +++ b/target/riscv/cpu.c | 42 | +++ b/target/riscv/cpu.c |
42 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp) | 43 | @@ -XXX,XX +XXX,XX @@ static const char riscv_single_letter_exts[] = "IEMAFDQCPVH"; |
43 | cpu->cfg.ext_zfinx = true; | 44 | const uint32_t misa_bits[] = {RVI, RVE, RVM, RVA, RVF, RVD, RVV, |
45 | RVC, RVS, RVU, RVH, RVJ, RVG, 0}; | ||
46 | |||
47 | -struct isa_ext_data { | ||
48 | - const char *name; | ||
49 | - int min_version; | ||
50 | - int ext_enable_offset; | ||
51 | -}; | ||
52 | - | ||
53 | -#define ISA_EXT_DATA_ENTRY(_name, _min_ver, _prop) \ | ||
54 | - {#_name, _min_ver, CPU_CFG_OFFSET(_prop)} | ||
55 | - | ||
56 | /* | ||
57 | * From vector_helper.c | ||
58 | * Note that vector data is stored in host-endian 64-bit chunks, | ||
59 | @@ -XXX,XX +XXX,XX @@ struct isa_ext_data { | ||
60 | #define BYTE(x) (x) | ||
61 | #endif | ||
62 | |||
63 | +#define ISA_EXT_DATA_ENTRY(_name, _min_ver, _prop) \ | ||
64 | + {#_name, _min_ver, CPU_CFG_OFFSET(_prop)} | ||
65 | + | ||
66 | /* | ||
67 | * Here are the ordering rules of extension naming defined by RISC-V | ||
68 | * specification : | ||
69 | @@ -XXX,XX +XXX,XX @@ struct isa_ext_data { | ||
70 | * Single letter extensions are checked in riscv_cpu_validate_misa_priv() | ||
71 | * instead. | ||
72 | */ | ||
73 | -static const struct isa_ext_data isa_edata_arr[] = { | ||
74 | +const RISCVIsaExtData isa_edata_arr[] = { | ||
75 | ISA_EXT_DATA_ENTRY(zicbom, PRIV_VERSION_1_12_0, ext_icbom), | ||
76 | ISA_EXT_DATA_ENTRY(zicboz, PRIV_VERSION_1_12_0, ext_icboz), | ||
77 | ISA_EXT_DATA_ENTRY(zicond, PRIV_VERSION_1_12_0, ext_zicond), | ||
78 | @@ -XXX,XX +XXX,XX @@ static const struct isa_ext_data isa_edata_arr[] = { | ||
79 | ISA_EXT_DATA_ENTRY(xtheadmempair, PRIV_VERSION_1_11_0, ext_xtheadmempair), | ||
80 | ISA_EXT_DATA_ENTRY(xtheadsync, PRIV_VERSION_1_11_0, ext_xtheadsync), | ||
81 | ISA_EXT_DATA_ENTRY(xventanacondops, PRIV_VERSION_1_12_0, ext_XVentanaCondOps), | ||
82 | + | ||
83 | + DEFINE_PROP_END_OF_LIST(), | ||
84 | }; | ||
85 | |||
86 | bool isa_ext_is_enabled(RISCVCPU *cpu, uint32_t ext_offset) | ||
87 | @@ -XXX,XX +XXX,XX @@ void isa_ext_update_enabled(RISCVCPU *cpu, uint32_t ext_offset, bool en) | ||
88 | |||
89 | int cpu_cfg_ext_get_min_version(uint32_t ext_offset) | ||
90 | { | ||
91 | - int i; | ||
92 | + const RISCVIsaExtData *edata; | ||
93 | |||
94 | - for (i = 0; i < ARRAY_SIZE(isa_edata_arr); i++) { | ||
95 | - if (isa_edata_arr[i].ext_enable_offset != ext_offset) { | ||
96 | + for (edata = isa_edata_arr; edata && edata->name; edata++) { | ||
97 | + if (edata->ext_enable_offset != ext_offset) { | ||
98 | continue; | ||
44 | } | 99 | } |
45 | 100 | ||
46 | + if (cpu->cfg.ext_zk) { | 101 | - return isa_edata_arr[i].min_version; |
47 | + cpu->cfg.ext_zkn = true; | 102 | + return edata->min_version; |
48 | + cpu->cfg.ext_zkr = true; | 103 | } |
49 | + cpu->cfg.ext_zkt = true; | 104 | |
50 | + } | 105 | g_assert_not_reached(); |
51 | + | 106 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_disas_set_info(CPUState *s, disassemble_info *info) |
52 | + if (cpu->cfg.ext_zkn) { | 107 | void riscv_cpu_disable_priv_spec_isa_exts(RISCVCPU *cpu) |
53 | + cpu->cfg.ext_zbkb = true; | 108 | { |
54 | + cpu->cfg.ext_zbkc = true; | 109 | CPURISCVState *env = &cpu->env; |
55 | + cpu->cfg.ext_zbkx = true; | 110 | - int i; |
56 | + cpu->cfg.ext_zkne = true; | 111 | + const RISCVIsaExtData *edata; |
57 | + cpu->cfg.ext_zknd = true; | 112 | |
58 | + cpu->cfg.ext_zknh = true; | 113 | /* Force disable extensions if priv spec version does not match */ |
59 | + } | 114 | - for (i = 0; i < ARRAY_SIZE(isa_edata_arr); i++) { |
60 | + | 115 | - if (isa_ext_is_enabled(cpu, isa_edata_arr[i].ext_enable_offset) && |
61 | + if (cpu->cfg.ext_zks) { | 116 | - (env->priv_ver < isa_edata_arr[i].min_version)) { |
62 | + cpu->cfg.ext_zbkb = true; | 117 | - isa_ext_update_enabled(cpu, isa_edata_arr[i].ext_enable_offset, |
63 | + cpu->cfg.ext_zbkc = true; | 118 | - false); |
64 | + cpu->cfg.ext_zbkx = true; | 119 | + for (edata = isa_edata_arr; edata && edata->name; edata++) { |
65 | + cpu->cfg.ext_zksed = true; | 120 | + if (isa_ext_is_enabled(cpu, edata->ext_enable_offset) && |
66 | + cpu->cfg.ext_zksh = true; | 121 | + (env->priv_ver < edata->min_version)) { |
67 | + } | 122 | + isa_ext_update_enabled(cpu, edata->ext_enable_offset, false); |
68 | + | 123 | #ifndef CONFIG_USER_ONLY |
69 | /* Set the ISA extensions, checks should have happened above */ | 124 | warn_report("disabling %s extension for hart 0x" TARGET_FMT_lx |
70 | if (cpu->cfg.ext_i) { | 125 | " because privilege spec version does not match", |
71 | ext |= RVI; | 126 | - isa_edata_arr[i].name, env->mhartid); |
127 | + edata->name, env->mhartid); | ||
128 | #else | ||
129 | warn_report("disabling %s extension because " | ||
130 | "privilege spec version does not match", | ||
131 | - isa_edata_arr[i].name); | ||
132 | + edata->name); | ||
133 | #endif | ||
134 | } | ||
135 | } | ||
136 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_class_init(ObjectClass *c, void *data) | ||
137 | static void riscv_isa_string_ext(RISCVCPU *cpu, char **isa_str, | ||
138 | int max_str_len) | ||
139 | { | ||
140 | + const RISCVIsaExtData *edata; | ||
141 | char *old = *isa_str; | ||
142 | char *new = *isa_str; | ||
143 | - int i; | ||
144 | |||
145 | - for (i = 0; i < ARRAY_SIZE(isa_edata_arr); i++) { | ||
146 | - if (isa_ext_is_enabled(cpu, isa_edata_arr[i].ext_enable_offset)) { | ||
147 | - new = g_strconcat(old, "_", isa_edata_arr[i].name, NULL); | ||
148 | + for (edata = isa_edata_arr; edata && edata->name; edata++) { | ||
149 | + if (isa_ext_is_enabled(cpu, edata->ext_enable_offset)) { | ||
150 | + new = g_strconcat(old, "_", edata->name, NULL); | ||
151 | g_free(old); | ||
152 | old = new; | ||
153 | } | ||
72 | -- | 154 | -- |
73 | 2.35.1 | 155 | 2.41.0 | diff view generated by jsdifflib |
1 | From: Alistair Francis <alistair.francis@wdc.com> | 1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
---|---|---|---|
2 | 2 | ||
3 | Add support for plugging in devices, this was tested with the TPM | 3 | Priv spec validation is TCG specific. Move it to the TCG accel class. |
4 | device. | ||
5 | 4 | ||
6 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 5 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
7 | Reviewed-by: Edgar E. Iglesias <edgar.iglesias@amd.com> | 6 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> |
8 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> | 7 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
9 | Message-Id: <20220427234146.1130752-6-alistair.francis@opensource.wdc.com> | 8 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> |
9 | Message-ID: <20230925175709.35696-20-dbarboza@ventanamicro.com> | ||
10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
11 | --- | 11 | --- |
12 | hw/riscv/virt.c | 35 +++++++++++++++++++++++++++++++++++ | 12 | target/riscv/cpu.h | 2 -- |
13 | 1 file changed, 35 insertions(+) | 13 | target/riscv/cpu.c | 38 -------------------------------------- |
14 | target/riscv/tcg/tcg-cpu.c | 38 ++++++++++++++++++++++++++++++++++++++ | ||
15 | 3 files changed, 38 insertions(+), 40 deletions(-) | ||
14 | 16 | ||
15 | diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c | 17 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h |
16 | index XXXXXXX..XXXXXXX 100644 | 18 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/hw/riscv/virt.c | 19 | --- a/target/riscv/cpu.h |
18 | +++ b/hw/riscv/virt.c | 20 | +++ b/target/riscv/cpu.h |
19 | @@ -XXX,XX +XXX,XX @@ static void virt_set_aclint(Object *obj, bool value, Error **errp) | 21 | @@ -XXX,XX +XXX,XX @@ enum riscv_pmu_event_idx { |
20 | s->have_aclint = value; | 22 | /* used by tcg/tcg-cpu.c*/ |
23 | void isa_ext_update_enabled(RISCVCPU *cpu, uint32_t ext_offset, bool en); | ||
24 | bool isa_ext_is_enabled(RISCVCPU *cpu, uint32_t ext_offset); | ||
25 | -int cpu_cfg_ext_get_min_version(uint32_t ext_offset); | ||
26 | void riscv_cpu_set_misa(CPURISCVState *env, RISCVMXL mxl, uint32_t ext); | ||
27 | -void riscv_cpu_disable_priv_spec_isa_exts(RISCVCPU *cpu); | ||
28 | |||
29 | typedef struct RISCVCPUMultiExtConfig { | ||
30 | const char *name; | ||
31 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | ||
32 | index XXXXXXX..XXXXXXX 100644 | ||
33 | --- a/target/riscv/cpu.c | ||
34 | +++ b/target/riscv/cpu.c | ||
35 | @@ -XXX,XX +XXX,XX @@ void isa_ext_update_enabled(RISCVCPU *cpu, uint32_t ext_offset, bool en) | ||
36 | *ext_enabled = en; | ||
21 | } | 37 | } |
22 | 38 | ||
23 | +static HotplugHandler *virt_machine_get_hotplug_handler(MachineState *machine, | 39 | -int cpu_cfg_ext_get_min_version(uint32_t ext_offset) |
24 | + DeviceState *dev) | 40 | -{ |
41 | - const RISCVIsaExtData *edata; | ||
42 | - | ||
43 | - for (edata = isa_edata_arr; edata && edata->name; edata++) { | ||
44 | - if (edata->ext_enable_offset != ext_offset) { | ||
45 | - continue; | ||
46 | - } | ||
47 | - | ||
48 | - return edata->min_version; | ||
49 | - } | ||
50 | - | ||
51 | - g_assert_not_reached(); | ||
52 | -} | ||
53 | - | ||
54 | const char * const riscv_int_regnames[] = { | ||
55 | "x0/zero", "x1/ra", "x2/sp", "x3/gp", "x4/tp", "x5/t0", "x6/t1", | ||
56 | "x7/t2", "x8/s0", "x9/s1", "x10/a0", "x11/a1", "x12/a2", "x13/a3", | ||
57 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_disas_set_info(CPUState *s, disassemble_info *info) | ||
58 | } | ||
59 | } | ||
60 | |||
61 | -void riscv_cpu_disable_priv_spec_isa_exts(RISCVCPU *cpu) | ||
62 | -{ | ||
63 | - CPURISCVState *env = &cpu->env; | ||
64 | - const RISCVIsaExtData *edata; | ||
65 | - | ||
66 | - /* Force disable extensions if priv spec version does not match */ | ||
67 | - for (edata = isa_edata_arr; edata && edata->name; edata++) { | ||
68 | - if (isa_ext_is_enabled(cpu, edata->ext_enable_offset) && | ||
69 | - (env->priv_ver < edata->min_version)) { | ||
70 | - isa_ext_update_enabled(cpu, edata->ext_enable_offset, false); | ||
71 | -#ifndef CONFIG_USER_ONLY | ||
72 | - warn_report("disabling %s extension for hart 0x" TARGET_FMT_lx | ||
73 | - " because privilege spec version does not match", | ||
74 | - edata->name, env->mhartid); | ||
75 | -#else | ||
76 | - warn_report("disabling %s extension because " | ||
77 | - "privilege spec version does not match", | ||
78 | - edata->name); | ||
79 | -#endif | ||
80 | - } | ||
81 | - } | ||
82 | -} | ||
83 | - | ||
84 | #ifndef CONFIG_USER_ONLY | ||
85 | static void riscv_cpu_satp_mode_finalize(RISCVCPU *cpu, Error **errp) | ||
86 | { | ||
87 | diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c | ||
88 | index XXXXXXX..XXXXXXX 100644 | ||
89 | --- a/target/riscv/tcg/tcg-cpu.c | ||
90 | +++ b/target/riscv/tcg/tcg-cpu.c | ||
91 | @@ -XXX,XX +XXX,XX @@ static const struct TCGCPUOps riscv_tcg_ops = { | ||
92 | #endif /* !CONFIG_USER_ONLY */ | ||
93 | }; | ||
94 | |||
95 | +static int cpu_cfg_ext_get_min_version(uint32_t ext_offset) | ||
25 | +{ | 96 | +{ |
26 | + MachineClass *mc = MACHINE_GET_CLASS(machine); | 97 | + const RISCVIsaExtData *edata; |
27 | + | 98 | + |
28 | + if (device_is_dynamic_sysbus(mc, dev)) { | 99 | + for (edata = isa_edata_arr; edata && edata->name; edata++) { |
29 | + return HOTPLUG_HANDLER(machine); | 100 | + if (edata->ext_enable_offset != ext_offset) { |
101 | + continue; | ||
102 | + } | ||
103 | + | ||
104 | + return edata->min_version; | ||
30 | + } | 105 | + } |
31 | + return NULL; | 106 | + |
107 | + g_assert_not_reached(); | ||
32 | +} | 108 | +} |
33 | + | 109 | + |
34 | +static void virt_machine_device_plug_cb(HotplugHandler *hotplug_dev, | 110 | static void cpu_cfg_ext_auto_update(RISCVCPU *cpu, uint32_t ext_offset, |
35 | + DeviceState *dev, Error **errp) | 111 | bool value) |
112 | { | ||
113 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_validate_v(CPURISCVState *env, RISCVCPUConfig *cfg, | ||
114 | } | ||
115 | } | ||
116 | |||
117 | +static void riscv_cpu_disable_priv_spec_isa_exts(RISCVCPU *cpu) | ||
36 | +{ | 118 | +{ |
37 | + RISCVVirtState *s = RISCV_VIRT_MACHINE(hotplug_dev); | 119 | + CPURISCVState *env = &cpu->env; |
120 | + const RISCVIsaExtData *edata; | ||
38 | + | 121 | + |
39 | + if (s->platform_bus_dev) { | 122 | + /* Force disable extensions if priv spec version does not match */ |
40 | + MachineClass *mc = MACHINE_GET_CLASS(s); | 123 | + for (edata = isa_edata_arr; edata && edata->name; edata++) { |
41 | + | 124 | + if (isa_ext_is_enabled(cpu, edata->ext_enable_offset) && |
42 | + if (device_is_dynamic_sysbus(mc, dev)) { | 125 | + (env->priv_ver < edata->min_version)) { |
43 | + platform_bus_link_device(PLATFORM_BUS_DEVICE(s->platform_bus_dev), | 126 | + isa_ext_update_enabled(cpu, edata->ext_enable_offset, false); |
44 | + SYS_BUS_DEVICE(dev)); | 127 | +#ifndef CONFIG_USER_ONLY |
128 | + warn_report("disabling %s extension for hart 0x" TARGET_FMT_lx | ||
129 | + " because privilege spec version does not match", | ||
130 | + edata->name, env->mhartid); | ||
131 | +#else | ||
132 | + warn_report("disabling %s extension because " | ||
133 | + "privilege spec version does not match", | ||
134 | + edata->name); | ||
135 | +#endif | ||
45 | + } | 136 | + } |
46 | + } | 137 | + } |
47 | +} | 138 | +} |
48 | + | 139 | + |
49 | static void virt_machine_class_init(ObjectClass *oc, void *data) | 140 | /* |
50 | { | 141 | * Check consistency between chosen extensions while setting |
51 | char str[128]; | 142 | * cpu->cfg accordingly. |
52 | MachineClass *mc = MACHINE_CLASS(oc); | ||
53 | + HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(oc); | ||
54 | |||
55 | mc->desc = "RISC-V VirtIO board"; | ||
56 | mc->init = virt_machine_init; | ||
57 | @@ -XXX,XX +XXX,XX @@ static void virt_machine_class_init(ObjectClass *oc, void *data) | ||
58 | mc->get_default_cpu_node_id = riscv_numa_get_default_cpu_node_id; | ||
59 | mc->numa_mem_supported = true; | ||
60 | mc->default_ram_id = "riscv_virt_board.ram"; | ||
61 | + assert(!mc->get_hotplug_handler); | ||
62 | + mc->get_hotplug_handler = virt_machine_get_hotplug_handler; | ||
63 | + | ||
64 | + hc->plug = virt_machine_device_plug_cb; | ||
65 | |||
66 | machine_class_allow_dynamic_sysbus_dev(mc, TYPE_RAMFB_DEVICE); | ||
67 | |||
68 | @@ -XXX,XX +XXX,XX @@ static const TypeInfo virt_machine_typeinfo = { | ||
69 | .class_init = virt_machine_class_init, | ||
70 | .instance_init = virt_machine_instance_init, | ||
71 | .instance_size = sizeof(RISCVVirtState), | ||
72 | + .interfaces = (InterfaceInfo[]) { | ||
73 | + { TYPE_HOTPLUG_HANDLER }, | ||
74 | + { } | ||
75 | + }, | ||
76 | }; | ||
77 | |||
78 | static void virt_machine_init_register_types(void) | ||
79 | -- | 143 | -- |
80 | 2.35.1 | 144 | 2.41.0 |
145 | |||
146 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
1 | 2 | ||
3 | We'll introduce generic errors that will output a CPU type name via its | ||
4 | RISCVCPU pointer. Create a helper for that. | ||
5 | |||
6 | Use the helper in tcg_cpu_realizefn() instead of hardcoding the 'host' | ||
7 | CPU name. | ||
8 | |||
9 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
10 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
11 | Message-ID: <20230926183109.165878-2-dbarboza@ventanamicro.com> | ||
12 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
13 | --- | ||
14 | target/riscv/cpu.h | 1 + | ||
15 | target/riscv/cpu.c | 11 +++++++++++ | ||
16 | target/riscv/tcg/tcg-cpu.c | 4 +++- | ||
17 | 3 files changed, 15 insertions(+), 1 deletion(-) | ||
18 | |||
19 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h | ||
20 | index XXXXXXX..XXXXXXX 100644 | ||
21 | --- a/target/riscv/cpu.h | ||
22 | +++ b/target/riscv/cpu.h | ||
23 | @@ -XXX,XX +XXX,XX @@ typedef struct isa_ext_data { | ||
24 | int ext_enable_offset; | ||
25 | } RISCVIsaExtData; | ||
26 | extern const RISCVIsaExtData isa_edata_arr[]; | ||
27 | +char *riscv_cpu_get_name(RISCVCPU *cpu); | ||
28 | |||
29 | void riscv_add_satp_mode_properties(Object *obj); | ||
30 | |||
31 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | ||
32 | index XXXXXXX..XXXXXXX 100644 | ||
33 | --- a/target/riscv/cpu.c | ||
34 | +++ b/target/riscv/cpu.c | ||
35 | @@ -XXX,XX +XXX,XX @@ static ObjectClass *riscv_cpu_class_by_name(const char *cpu_model) | ||
36 | return oc; | ||
37 | } | ||
38 | |||
39 | +char *riscv_cpu_get_name(RISCVCPU *cpu) | ||
40 | +{ | ||
41 | + RISCVCPUClass *rcc = RISCV_CPU_GET_CLASS(cpu); | ||
42 | + const char *typename = object_class_get_name(OBJECT_CLASS(rcc)); | ||
43 | + | ||
44 | + g_assert(g_str_has_suffix(typename, RISCV_CPU_TYPE_SUFFIX)); | ||
45 | + | ||
46 | + return g_strndup(typename, | ||
47 | + strlen(typename) - strlen(RISCV_CPU_TYPE_SUFFIX)); | ||
48 | +} | ||
49 | + | ||
50 | static void riscv_cpu_dump_state(CPUState *cs, FILE *f, int flags) | ||
51 | { | ||
52 | RISCVCPU *cpu = RISCV_CPU(cs); | ||
53 | diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c | ||
54 | index XXXXXXX..XXXXXXX 100644 | ||
55 | --- a/target/riscv/tcg/tcg-cpu.c | ||
56 | +++ b/target/riscv/tcg/tcg-cpu.c | ||
57 | @@ -XXX,XX +XXX,XX @@ static bool tcg_cpu_realize(CPUState *cs, Error **errp) | ||
58 | Error *local_err = NULL; | ||
59 | |||
60 | if (object_dynamic_cast(OBJECT(cpu), TYPE_RISCV_CPU_HOST)) { | ||
61 | - error_setg(errp, "'host' CPU is not compatible with TCG acceleration"); | ||
62 | + g_autofree char *name = riscv_cpu_get_name(cpu); | ||
63 | + error_setg(errp, "'%s' CPU is not compatible with TCG acceleration", | ||
64 | + name); | ||
65 | return false; | ||
66 | } | ||
67 | |||
68 | -- | ||
69 | 2.41.0 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
1 | 2 | ||
3 | At this moment we do not expose extension properties for vendor CPUs | ||
4 | because that would allow users to change them via command line. The | ||
5 | drawback is that if we were to add an API that shows all CPU properties, | ||
6 | e.g. qmp-query-cpu-model-expansion, we won't be able to show extensions | ||
7 | state of vendor CPUs. | ||
8 | |||
9 | We have the required machinery to create extension properties for vendor | ||
10 | CPUs while not allowing users to enable extensions. Disabling existing | ||
11 | extensions is allowed since it can be useful for debugging. | ||
12 | |||
13 | Change the set() callback cpu_set_multi_ext_cfg() to allow enabling | ||
14 | extensions only for generic CPUs. In cpu_add_multi_ext_prop() let's not | ||
15 | set the default values for the properties if we're not dealing with | ||
16 | generic CPUs, otherwise the values set in cpu_init() of vendor CPUs will | ||
17 | be overwritten. And finally, in tcg_cpu_instance_init(), add cpu user | ||
18 | properties for all CPUs. | ||
19 | |||
20 | For the veyron-v1 CPU, we're now able to disable existing extensions | ||
21 | like smstateen: | ||
22 | |||
23 | $ ./build/qemu-system-riscv64 --nographic -M virt \ | ||
24 | -cpu veyron-v1,smstateen=false | ||
25 | |||
26 | But setting extensions that the CPU didn't set during cpu_init(), like | ||
27 | V, is not allowed: | ||
28 | |||
29 | $ ./build/qemu-system-riscv64 --nographic -M virt \ | ||
30 | -cpu veyron-v1,v=true | ||
31 | qemu-system-riscv64: can't apply global veyron-v1-riscv-cpu.v=true: | ||
32 | 'veyron-v1' CPU does not allow enabling extensions | ||
33 | |||
34 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
35 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
36 | Message-ID: <20230926183109.165878-3-dbarboza@ventanamicro.com> | ||
37 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
38 | --- | ||
39 | target/riscv/tcg/tcg-cpu.c | 64 +++++++++++++++++++++++++++++--------- | ||
40 | 1 file changed, 50 insertions(+), 14 deletions(-) | ||
41 | |||
42 | diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c | ||
43 | index XXXXXXX..XXXXXXX 100644 | ||
44 | --- a/target/riscv/tcg/tcg-cpu.c | ||
45 | +++ b/target/riscv/tcg/tcg-cpu.c | ||
46 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp) | ||
47 | riscv_cpu_disable_priv_spec_isa_exts(cpu); | ||
48 | } | ||
49 | |||
50 | +static bool riscv_cpu_is_generic(Object *cpu_obj) | ||
51 | +{ | ||
52 | + return object_dynamic_cast(cpu_obj, TYPE_RISCV_DYNAMIC_CPU) != NULL; | ||
53 | +} | ||
54 | + | ||
55 | /* | ||
56 | * We'll get here via the following path: | ||
57 | * | ||
58 | @@ -XXX,XX +XXX,XX @@ static void cpu_set_misa_ext_cfg(Object *obj, Visitor *v, const char *name, | ||
59 | target_ulong misa_bit = misa_ext_cfg->misa_bit; | ||
60 | RISCVCPU *cpu = RISCV_CPU(obj); | ||
61 | CPURISCVState *env = &cpu->env; | ||
62 | - bool value; | ||
63 | + bool generic_cpu = riscv_cpu_is_generic(obj); | ||
64 | + bool prev_val, value; | ||
65 | |||
66 | if (!visit_type_bool(v, name, &value, errp)) { | ||
67 | return; | ||
68 | } | ||
69 | |||
70 | + prev_val = env->misa_ext & misa_bit; | ||
71 | + | ||
72 | + if (value == prev_val) { | ||
73 | + return; | ||
74 | + } | ||
75 | + | ||
76 | if (value) { | ||
77 | + if (!generic_cpu) { | ||
78 | + g_autofree char *cpuname = riscv_cpu_get_name(cpu); | ||
79 | + error_setg(errp, "'%s' CPU does not allow enabling extensions", | ||
80 | + cpuname); | ||
81 | + return; | ||
82 | + } | ||
83 | + | ||
84 | env->misa_ext |= misa_bit; | ||
85 | env->misa_ext_mask |= misa_bit; | ||
86 | } else { | ||
87 | @@ -XXX,XX +XXX,XX @@ static const RISCVCPUMisaExtConfig misa_ext_cfgs[] = { | ||
88 | */ | ||
89 | static void riscv_cpu_add_misa_properties(Object *cpu_obj) | ||
90 | { | ||
91 | + bool use_def_vals = riscv_cpu_is_generic(cpu_obj); | ||
92 | int i; | ||
93 | |||
94 | for (i = 0; i < ARRAY_SIZE(misa_ext_cfgs); i++) { | ||
95 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_add_misa_properties(Object *cpu_obj) | ||
96 | cpu_set_misa_ext_cfg, | ||
97 | NULL, (void *)misa_cfg); | ||
98 | object_property_set_description(cpu_obj, name, desc); | ||
99 | - object_property_set_bool(cpu_obj, name, misa_cfg->enabled, NULL); | ||
100 | + if (use_def_vals) { | ||
101 | + object_property_set_bool(cpu_obj, name, misa_cfg->enabled, NULL); | ||
102 | + } | ||
103 | } | ||
104 | } | ||
105 | |||
106 | @@ -XXX,XX +XXX,XX @@ static void cpu_set_multi_ext_cfg(Object *obj, Visitor *v, const char *name, | ||
107 | void *opaque, Error **errp) | ||
108 | { | ||
109 | const RISCVCPUMultiExtConfig *multi_ext_cfg = opaque; | ||
110 | - bool value; | ||
111 | + RISCVCPU *cpu = RISCV_CPU(obj); | ||
112 | + bool generic_cpu = riscv_cpu_is_generic(obj); | ||
113 | + bool prev_val, value; | ||
114 | |||
115 | if (!visit_type_bool(v, name, &value, errp)) { | ||
116 | return; | ||
117 | } | ||
118 | |||
119 | - isa_ext_update_enabled(RISCV_CPU(obj), multi_ext_cfg->offset, value); | ||
120 | - | ||
121 | g_hash_table_insert(multi_ext_user_opts, | ||
122 | GUINT_TO_POINTER(multi_ext_cfg->offset), | ||
123 | (gpointer)value); | ||
124 | + | ||
125 | + prev_val = isa_ext_is_enabled(cpu, multi_ext_cfg->offset); | ||
126 | + | ||
127 | + if (value == prev_val) { | ||
128 | + return; | ||
129 | + } | ||
130 | + | ||
131 | + if (value && !generic_cpu) { | ||
132 | + g_autofree char *cpuname = riscv_cpu_get_name(cpu); | ||
133 | + error_setg(errp, "'%s' CPU does not allow enabling extensions", | ||
134 | + cpuname); | ||
135 | + return; | ||
136 | + } | ||
137 | + | ||
138 | + isa_ext_update_enabled(cpu, multi_ext_cfg->offset, value); | ||
139 | } | ||
140 | |||
141 | static void cpu_get_multi_ext_cfg(Object *obj, Visitor *v, const char *name, | ||
142 | @@ -XXX,XX +XXX,XX @@ static void cpu_get_multi_ext_cfg(Object *obj, Visitor *v, const char *name, | ||
143 | static void cpu_add_multi_ext_prop(Object *cpu_obj, | ||
144 | const RISCVCPUMultiExtConfig *multi_cfg) | ||
145 | { | ||
146 | + bool generic_cpu = riscv_cpu_is_generic(cpu_obj); | ||
147 | + | ||
148 | object_property_add(cpu_obj, multi_cfg->name, "bool", | ||
149 | cpu_get_multi_ext_cfg, | ||
150 | cpu_set_multi_ext_cfg, | ||
151 | NULL, (void *)multi_cfg); | ||
152 | |||
153 | + if (!generic_cpu) { | ||
154 | + return; | ||
155 | + } | ||
156 | + | ||
157 | /* | ||
158 | * Set def val directly instead of using | ||
159 | * object_property_set_bool() to save the set() | ||
160 | @@ -XXX,XX +XXX,XX @@ static bool riscv_cpu_has_max_extensions(Object *cpu_obj) | ||
161 | return object_dynamic_cast(cpu_obj, TYPE_RISCV_CPU_MAX) != NULL; | ||
162 | } | ||
163 | |||
164 | -static bool riscv_cpu_has_user_properties(Object *cpu_obj) | ||
165 | -{ | ||
166 | - return object_dynamic_cast(cpu_obj, TYPE_RISCV_DYNAMIC_CPU) != NULL; | ||
167 | -} | ||
168 | - | ||
169 | static void tcg_cpu_instance_init(CPUState *cs) | ||
170 | { | ||
171 | RISCVCPU *cpu = RISCV_CPU(cs); | ||
172 | Object *obj = OBJECT(cpu); | ||
173 | |||
174 | - if (riscv_cpu_has_user_properties(obj)) { | ||
175 | - multi_ext_user_opts = g_hash_table_new(NULL, g_direct_equal); | ||
176 | - riscv_cpu_add_user_properties(obj); | ||
177 | - } | ||
178 | + multi_ext_user_opts = g_hash_table_new(NULL, g_direct_equal); | ||
179 | + riscv_cpu_add_user_properties(obj); | ||
180 | |||
181 | if (riscv_cpu_has_max_extensions(obj)) { | ||
182 | riscv_init_max_cpu_extensions(obj); | ||
183 | -- | ||
184 | 2.41.0 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Clément Chigot <chigot@adacore.com> | ||
1 | 2 | ||
3 | As of now, the exit code was either EXIT_FAILURE when a panic shutdown | ||
4 | was requested or EXIT_SUCCESS otherwise. | ||
5 | However, some hardware could want to pass more complex exit codes. Thus, | ||
6 | introduce a new shutdown request function allowing that. | ||
7 | |||
8 | Signed-off-by: Clément Chigot <chigot@adacore.com> | ||
9 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
10 | Message-ID: <20231003071427.188697-2-chigot@adacore.com> | ||
11 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
12 | --- | ||
13 | include/sysemu/runstate.h | 2 ++ | ||
14 | system/runstate.c | 12 +++++++++++- | ||
15 | 2 files changed, 13 insertions(+), 1 deletion(-) | ||
16 | |||
17 | diff --git a/include/sysemu/runstate.h b/include/sysemu/runstate.h | ||
18 | index XXXXXXX..XXXXXXX 100644 | ||
19 | --- a/include/sysemu/runstate.h | ||
20 | +++ b/include/sysemu/runstate.h | ||
21 | @@ -XXX,XX +XXX,XX @@ void qemu_system_wakeup_request(WakeupReason reason, Error **errp); | ||
22 | void qemu_system_wakeup_enable(WakeupReason reason, bool enabled); | ||
23 | void qemu_register_wakeup_notifier(Notifier *notifier); | ||
24 | void qemu_register_wakeup_support(void); | ||
25 | +void qemu_system_shutdown_request_with_code(ShutdownCause reason, | ||
26 | + int exit_code); | ||
27 | void qemu_system_shutdown_request(ShutdownCause reason); | ||
28 | void qemu_system_powerdown_request(void); | ||
29 | void qemu_register_powerdown_notifier(Notifier *notifier); | ||
30 | diff --git a/system/runstate.c b/system/runstate.c | ||
31 | index XXXXXXX..XXXXXXX 100644 | ||
32 | --- a/system/runstate.c | ||
33 | +++ b/system/runstate.c | ||
34 | @@ -XXX,XX +XXX,XX @@ void vm_state_notify(bool running, RunState state) | ||
35 | |||
36 | static ShutdownCause reset_requested; | ||
37 | static ShutdownCause shutdown_requested; | ||
38 | +static int shutdown_exit_code = EXIT_SUCCESS; | ||
39 | static int shutdown_signal; | ||
40 | static pid_t shutdown_pid; | ||
41 | static int powerdown_requested; | ||
42 | @@ -XXX,XX +XXX,XX @@ void qemu_system_killed(int signal, pid_t pid) | ||
43 | qemu_notify_event(); | ||
44 | } | ||
45 | |||
46 | +void qemu_system_shutdown_request_with_code(ShutdownCause reason, | ||
47 | + int exit_code) | ||
48 | +{ | ||
49 | + shutdown_exit_code = exit_code; | ||
50 | + qemu_system_shutdown_request(reason); | ||
51 | +} | ||
52 | + | ||
53 | void qemu_system_shutdown_request(ShutdownCause reason) | ||
54 | { | ||
55 | trace_qemu_system_shutdown_request(reason); | ||
56 | @@ -XXX,XX +XXX,XX @@ static bool main_loop_should_exit(int *status) | ||
57 | if (shutdown_action == SHUTDOWN_ACTION_PAUSE) { | ||
58 | vm_stop(RUN_STATE_SHUTDOWN); | ||
59 | } else { | ||
60 | - if (request == SHUTDOWN_CAUSE_GUEST_PANIC && | ||
61 | + if (shutdown_exit_code != EXIT_SUCCESS) { | ||
62 | + *status = shutdown_exit_code; | ||
63 | + } else if (request == SHUTDOWN_CAUSE_GUEST_PANIC && | ||
64 | panic_action == PANIC_ACTION_EXIT_FAILURE) { | ||
65 | *status = EXIT_FAILURE; | ||
66 | } | ||
67 | -- | ||
68 | 2.41.0 | ||
69 | |||
70 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Clément Chigot <chigot@adacore.com> | ||
1 | 2 | ||
3 | gdb_exit function aims to close gdb sessions and sends the exit code of | ||
4 | the current execution. It's being called by qemu_cleanup once the main | ||
5 | loop is over. | ||
6 | Until now, the exit code sent was always 0. Now that hardware can | ||
7 | shutdown this main loop with custom exit codes, these codes must be | ||
8 | transfered to gdb as well. | ||
9 | |||
10 | Signed-off-by: Clément Chigot <chigot@adacore.com> | ||
11 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
12 | Message-ID: <20231003071427.188697-3-chigot@adacore.com> | ||
13 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
14 | --- | ||
15 | include/sysemu/sysemu.h | 2 +- | ||
16 | system/main.c | 2 +- | ||
17 | system/runstate.c | 4 ++-- | ||
18 | 3 files changed, 4 insertions(+), 4 deletions(-) | ||
19 | |||
20 | diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h | ||
21 | index XXXXXXX..XXXXXXX 100644 | ||
22 | --- a/include/sysemu/sysemu.h | ||
23 | +++ b/include/sysemu/sysemu.h | ||
24 | @@ -XXX,XX +XXX,XX @@ bool defaults_enabled(void); | ||
25 | |||
26 | void qemu_init(int argc, char **argv); | ||
27 | int qemu_main_loop(void); | ||
28 | -void qemu_cleanup(void); | ||
29 | +void qemu_cleanup(int); | ||
30 | |||
31 | extern QemuOptsList qemu_legacy_drive_opts; | ||
32 | extern QemuOptsList qemu_common_drive_opts; | ||
33 | diff --git a/system/main.c b/system/main.c | ||
34 | index XXXXXXX..XXXXXXX 100644 | ||
35 | --- a/system/main.c | ||
36 | +++ b/system/main.c | ||
37 | @@ -XXX,XX +XXX,XX @@ int qemu_default_main(void) | ||
38 | int status; | ||
39 | |||
40 | status = qemu_main_loop(); | ||
41 | - qemu_cleanup(); | ||
42 | + qemu_cleanup(status); | ||
43 | |||
44 | return status; | ||
45 | } | ||
46 | diff --git a/system/runstate.c b/system/runstate.c | ||
47 | index XXXXXXX..XXXXXXX 100644 | ||
48 | --- a/system/runstate.c | ||
49 | +++ b/system/runstate.c | ||
50 | @@ -XXX,XX +XXX,XX @@ void qemu_init_subsystems(void) | ||
51 | } | ||
52 | |||
53 | |||
54 | -void qemu_cleanup(void) | ||
55 | +void qemu_cleanup(int status) | ||
56 | { | ||
57 | - gdb_exit(0); | ||
58 | + gdb_exit(status); | ||
59 | |||
60 | /* | ||
61 | * cleaning up the migration object cancels any existing migration | ||
62 | -- | ||
63 | 2.41.0 | ||
64 | |||
65 | diff view generated by jsdifflib |
1 | From: Alistair Francis <alistair.francis@wdc.com> | 1 | From: Clément Chigot <chigot@adacore.com> |
---|---|---|---|
2 | 2 | ||
3 | The ARM virt machine currently uses sysbus-fdt to create device tree | 3 | This replaces the exit calls by shutdown requests, ensuring a proper |
4 | entries for dynamically created MMIO devices. | 4 | cleanup of Qemu. Otherwise, some connections like gdb could be broken |
5 | before its final packet ("Wxx") is being sent. This part, being done | ||
6 | inside qemu_cleanup function, can be reached only when the main loop | ||
7 | exits after a shutdown request. | ||
5 | 8 | ||
6 | The RISC-V virt machine can also benefit from this, so move the code to | 9 | Signed-off-by: Clément Chigot <chigot@adacore.com> |
7 | the core directory. | 10 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
8 | 11 | Message-ID: <20231003071427.188697-4-chigot@adacore.com> | |
9 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
10 | Reviewed-by: Edgar E. Iglesias <edgar.iglesias@amd.com> | ||
11 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> | ||
12 | Message-Id: <20220427234146.1130752-3-alistair.francis@opensource.wdc.com> | ||
13 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 12 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
14 | --- | 13 | --- |
15 | include/hw/{arm => core}/sysbus-fdt.h | 0 | 14 | hw/misc/sifive_test.c | 9 +++++++-- |
16 | hw/arm/virt.c | 2 +- | 15 | 1 file changed, 7 insertions(+), 2 deletions(-) |
17 | hw/arm/xlnx-versal-virt.c | 1 - | ||
18 | hw/{arm => core}/sysbus-fdt.c | 2 +- | ||
19 | hw/arm/meson.build | 1 - | ||
20 | hw/core/meson.build | 1 + | ||
21 | 6 files changed, 3 insertions(+), 4 deletions(-) | ||
22 | rename include/hw/{arm => core}/sysbus-fdt.h (100%) | ||
23 | rename hw/{arm => core}/sysbus-fdt.c (99%) | ||
24 | 16 | ||
25 | diff --git a/include/hw/arm/sysbus-fdt.h b/include/hw/core/sysbus-fdt.h | 17 | diff --git a/hw/misc/sifive_test.c b/hw/misc/sifive_test.c |
26 | similarity index 100% | ||
27 | rename from include/hw/arm/sysbus-fdt.h | ||
28 | rename to include/hw/core/sysbus-fdt.h | ||
29 | diff --git a/hw/arm/virt.c b/hw/arm/virt.c | ||
30 | index XXXXXXX..XXXXXXX 100644 | 18 | index XXXXXXX..XXXXXXX 100644 |
31 | --- a/hw/arm/virt.c | 19 | --- a/hw/misc/sifive_test.c |
32 | +++ b/hw/arm/virt.c | 20 | +++ b/hw/misc/sifive_test.c |
33 | @@ -XXX,XX +XXX,XX @@ | 21 | @@ -XXX,XX +XXX,XX @@ |
34 | #include "qemu/module.h" | 22 | #include "qemu/module.h" |
35 | #include "hw/pci-host/gpex.h" | 23 | #include "sysemu/runstate.h" |
36 | #include "hw/virtio/virtio-pci.h" | 24 | #include "hw/misc/sifive_test.h" |
37 | -#include "hw/arm/sysbus-fdt.h" | 25 | +#include "sysemu/sysemu.h" |
38 | +#include "hw/core/sysbus-fdt.h" | 26 | |
39 | #include "hw/platform-bus.h" | 27 | static uint64_t sifive_test_read(void *opaque, hwaddr addr, unsigned int size) |
40 | #include "hw/qdev-properties.h" | 28 | { |
41 | #include "hw/arm/fdt.h" | 29 | @@ -XXX,XX +XXX,XX @@ static void sifive_test_write(void *opaque, hwaddr addr, |
42 | diff --git a/hw/arm/xlnx-versal-virt.c b/hw/arm/xlnx-versal-virt.c | 30 | int code = (val64 >> 16) & 0xffff; |
43 | index XXXXXXX..XXXXXXX 100644 | 31 | switch (status) { |
44 | --- a/hw/arm/xlnx-versal-virt.c | 32 | case FINISHER_FAIL: |
45 | +++ b/hw/arm/xlnx-versal-virt.c | 33 | - exit(code); |
46 | @@ -XXX,XX +XXX,XX @@ | 34 | + qemu_system_shutdown_request_with_code( |
47 | #include "sysemu/device_tree.h" | 35 | + SHUTDOWN_CAUSE_GUEST_PANIC, code); |
48 | #include "hw/boards.h" | 36 | + return; |
49 | #include "hw/sysbus.h" | 37 | case FINISHER_PASS: |
50 | -#include "hw/arm/sysbus-fdt.h" | 38 | - exit(0); |
51 | #include "hw/arm/fdt.h" | 39 | + qemu_system_shutdown_request_with_code( |
52 | #include "cpu.h" | 40 | + SHUTDOWN_CAUSE_GUEST_SHUTDOWN, code); |
53 | #include "hw/qdev-properties.h" | 41 | + return; |
54 | diff --git a/hw/arm/sysbus-fdt.c b/hw/core/sysbus-fdt.c | 42 | case FINISHER_RESET: |
55 | similarity index 99% | 43 | qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET); |
56 | rename from hw/arm/sysbus-fdt.c | 44 | return; |
57 | rename to hw/core/sysbus-fdt.c | ||
58 | index XXXXXXX..XXXXXXX 100644 | ||
59 | --- a/hw/arm/sysbus-fdt.c | ||
60 | +++ b/hw/core/sysbus-fdt.c | ||
61 | @@ -XXX,XX +XXX,XX @@ | ||
62 | #ifdef CONFIG_LINUX | ||
63 | #include <linux/vfio.h> | ||
64 | #endif | ||
65 | -#include "hw/arm/sysbus-fdt.h" | ||
66 | +#include "hw/core/sysbus-fdt.h" | ||
67 | #include "qemu/error-report.h" | ||
68 | #include "sysemu/device_tree.h" | ||
69 | #include "sysemu/tpm.h" | ||
70 | diff --git a/hw/arm/meson.build b/hw/arm/meson.build | ||
71 | index XXXXXXX..XXXXXXX 100644 | ||
72 | --- a/hw/arm/meson.build | ||
73 | +++ b/hw/arm/meson.build | ||
74 | @@ -XXX,XX +XXX,XX @@ | ||
75 | arm_ss = ss.source_set() | ||
76 | arm_ss.add(files('boot.c'), fdt) | ||
77 | -arm_ss.add(when: 'CONFIG_PLATFORM_BUS', if_true: files('sysbus-fdt.c')) | ||
78 | arm_ss.add(when: 'CONFIG_ARM_VIRT', if_true: files('virt.c')) | ||
79 | arm_ss.add(when: 'CONFIG_ACPI', if_true: files('virt-acpi-build.c')) | ||
80 | arm_ss.add(when: 'CONFIG_DIGIC', if_true: files('digic_boards.c')) | ||
81 | diff --git a/hw/core/meson.build b/hw/core/meson.build | ||
82 | index XXXXXXX..XXXXXXX 100644 | ||
83 | --- a/hw/core/meson.build | ||
84 | +++ b/hw/core/meson.build | ||
85 | @@ -XXX,XX +XXX,XX @@ softmmu_ss.add(when: 'CONFIG_PTIMER', if_true: files('ptimer.c')) | ||
86 | softmmu_ss.add(when: 'CONFIG_REGISTER', if_true: files('register.c')) | ||
87 | softmmu_ss.add(when: 'CONFIG_SPLIT_IRQ', if_true: files('split-irq.c')) | ||
88 | softmmu_ss.add(when: 'CONFIG_XILINX_AXI', if_true: files('stream.c')) | ||
89 | +softmmu_ss.add(when: 'CONFIG_PLATFORM_BUS', if_true: files('sysbus-fdt.c')) | ||
90 | |||
91 | softmmu_ss.add(files( | ||
92 | 'cpu-sysemu.c', | ||
93 | -- | 45 | -- |
94 | 2.35.1 | 46 | 2.41.0 |
47 | |||
48 | diff view generated by jsdifflib |
1 | From: Ralf Ramsauer <ralf.ramsauer@oth-regensburg.de> | 1 | From: Clément Chigot <chigot@adacore.com> |
---|---|---|---|
2 | 2 | ||
3 | Two non-subsequent PTEs can be mapped to subsequent paddrs. In this | 3 | This replaces the exit calls by shutdown requests, ensuring a proper |
4 | case, walk_pte will erroneously merge them. | 4 | cleanup of Qemu. Otherwise, some connections like gdb could be broken |
5 | before its final packet ("Wxx") is being sent. This part, being done | ||
6 | inside qemu_cleanup function, can be reached only when the main loop | ||
7 | exits after a shutdown request. | ||
5 | 8 | ||
6 | Enforce the split up, by tracking the virtual base address. | 9 | Signed-off-by: Clément Chigot <chigot@adacore.com> |
7 | |||
8 | Let's say we have the mapping: | ||
9 | 0x81200000 -> 0x89623000 (4K) | ||
10 | 0x8120f000 -> 0x89624000 (4K) | ||
11 | |||
12 | Before, walk_pte would have shown: | ||
13 | |||
14 | vaddr paddr size attr | ||
15 | ---------------- ---------------- ---------------- ------- | ||
16 | 0000000081200000 0000000089623000 0000000000002000 rwxu-ad | ||
17 | |||
18 | as it only checks for subsequent paddrs. With this patch, it becomes: | ||
19 | |||
20 | vaddr paddr size attr | ||
21 | ---------------- ---------------- ---------------- ------- | ||
22 | 0000000081200000 0000000089623000 0000000000001000 rwxu-ad | ||
23 | 000000008120f000 0000000089624000 0000000000001000 rwxu-ad | ||
24 | |||
25 | Signed-off-by: Ralf Ramsauer <ralf.ramsauer@oth-regensburg.de> | ||
26 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> | ||
27 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 10 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
28 | Message-Id: <20220423215907.673663-1-ralf.ramsauer@oth-regensburg.de> | 11 | Message-ID: <20231003071427.188697-5-chigot@adacore.com> |
29 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 12 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
30 | --- | 13 | --- |
31 | target/riscv/monitor.c | 11 +++++++---- | 14 | hw/char/riscv_htif.c | 5 ++++- |
32 | 1 file changed, 7 insertions(+), 4 deletions(-) | 15 | 1 file changed, 4 insertions(+), 1 deletion(-) |
33 | 16 | ||
34 | diff --git a/target/riscv/monitor.c b/target/riscv/monitor.c | 17 | diff --git a/hw/char/riscv_htif.c b/hw/char/riscv_htif.c |
35 | index XXXXXXX..XXXXXXX 100644 | 18 | index XXXXXXX..XXXXXXX 100644 |
36 | --- a/target/riscv/monitor.c | 19 | --- a/hw/char/riscv_htif.c |
37 | +++ b/target/riscv/monitor.c | 20 | +++ b/hw/char/riscv_htif.c |
38 | @@ -XXX,XX +XXX,XX @@ static void walk_pte(Monitor *mon, hwaddr base, target_ulong start, | 21 | @@ -XXX,XX +XXX,XX @@ |
39 | { | 22 | #include "exec/address-spaces.h" |
40 | hwaddr pte_addr; | 23 | #include "exec/tswap.h" |
41 | hwaddr paddr; | 24 | #include "sysemu/dma.h" |
42 | + target_ulong last_start = -1; | 25 | +#include "sysemu/runstate.h" |
43 | target_ulong pgsize; | 26 | |
44 | target_ulong pte; | 27 | #define RISCV_DEBUG_HTIF 0 |
45 | int ptshift; | 28 | #define HTIF_DEBUG(fmt, ...) \ |
46 | @@ -XXX,XX +XXX,XX @@ static void walk_pte(Monitor *mon, hwaddr base, target_ulong start, | 29 | @@ -XXX,XX +XXX,XX @@ static void htif_handle_tohost_write(HTIFState *s, uint64_t val_written) |
47 | * A leaf PTE has been found | 30 | g_free(sig_data); |
48 | * | ||
49 | * If current PTE's permission bits differ from the last one, | ||
50 | - * or current PTE's ppn does not make a contiguous physical | ||
51 | - * address block together with the last one, print out the last | ||
52 | - * contiguous mapped block details. | ||
53 | + * or the current PTE breaks up a contiguous virtual or | ||
54 | + * physical mapping, address block together with the last one, | ||
55 | + * print out the last contiguous mapped block details. | ||
56 | */ | ||
57 | if ((*last_attr != attr) || | ||
58 | - (*last_paddr + *last_size != paddr)) { | ||
59 | + (*last_paddr + *last_size != paddr) || | ||
60 | + (last_start + *last_size != start)) { | ||
61 | print_pte(mon, va_bits, *vbase, *pbase, | ||
62 | *last_paddr + *last_size - *pbase, *last_attr); | ||
63 | |||
64 | @@ -XXX,XX +XXX,XX @@ static void walk_pte(Monitor *mon, hwaddr base, target_ulong start, | ||
65 | *last_attr = attr; | ||
66 | } | 31 | } |
67 | 32 | ||
68 | + last_start = start; | 33 | - exit(exit_code); |
69 | *last_paddr = paddr; | 34 | + qemu_system_shutdown_request_with_code( |
70 | *last_size = pgsize; | 35 | + SHUTDOWN_CAUSE_GUEST_SHUTDOWN, exit_code); |
36 | + return; | ||
71 | } else { | 37 | } else { |
38 | uint64_t syscall[8]; | ||
39 | cpu_physical_memory_read(payload, syscall, sizeof(syscall)); | ||
72 | -- | 40 | -- |
73 | 2.35.1 | 41 | 2.41.0 |
42 | |||
43 | diff view generated by jsdifflib |
1 | From: Weiwei Li <liweiwei@iscas.ac.cn> | 1 | From: Clément Chigot <chigot@adacore.com> |
---|---|---|---|
2 | 2 | ||
3 | - reuse partial instructions of zbb extension, update extension check for them | 3 | This replaces the exit calls by shutdown requests, ensuring a proper |
4 | - add brev8, pack, packh, packw, unzip, zip instructions | 4 | cleanup of Qemu. Features like net/vhost-vdpa.c are expecting |
5 | qemu_cleanup to be called to remove their last residuals. | ||
5 | 6 | ||
6 | Signed-off-by: Weiwei Li <liweiwei@iscas.ac.cn> | 7 | Signed-off-by: Clément Chigot <chigot@adacore.com> |
7 | Signed-off-by: Junqiang Wang <wangjunqiang@iscas.ac.cn> | 8 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
8 | Acked-by: Alistair Francis <alistair.francis@wdc.com> | 9 | Message-ID: <20231003071427.188697-6-chigot@adacore.com> |
9 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
10 | Message-Id: <20220423023510.30794-3-liweiwei@iscas.ac.cn> | ||
11 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
12 | --- | 11 | --- |
13 | target/riscv/helper.h | 3 + | 12 | include/gdbstub/syscalls.h | 9 +++++++++ |
14 | target/riscv/insn32.decode | 45 +++++++----- | 13 | gdbstub/gdbstub.c | 5 +++-- |
15 | target/riscv/bitmanip_helper.c | 53 ++++++++++++++ | 14 | gdbstub/system.c | 6 ++++++ |
16 | target/riscv/translate.c | 7 ++ | 15 | gdbstub/user.c | 6 ++++++ |
17 | target/riscv/insn_trans/trans_rvb.c.inc | 94 +++++++++++++++++++++---- | 16 | 4 files changed, 24 insertions(+), 2 deletions(-) |
18 | 5 files changed, 174 insertions(+), 28 deletions(-) | ||
19 | 17 | ||
20 | diff --git a/target/riscv/helper.h b/target/riscv/helper.h | 18 | diff --git a/include/gdbstub/syscalls.h b/include/gdbstub/syscalls.h |
21 | index XXXXXXX..XXXXXXX 100644 | 19 | index XXXXXXX..XXXXXXX 100644 |
22 | --- a/target/riscv/helper.h | 20 | --- a/include/gdbstub/syscalls.h |
23 | +++ b/target/riscv/helper.h | 21 | +++ b/include/gdbstub/syscalls.h |
24 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_1(fclass_d, TCG_CALL_NO_RWG_SE, tl, i64) | 22 | @@ -XXX,XX +XXX,XX @@ int use_gdb_syscalls(void); |
25 | /* Bitmanip */ | 23 | */ |
26 | DEF_HELPER_FLAGS_2(clmul, TCG_CALL_NO_RWG_SE, tl, tl, tl) | 24 | void gdb_exit(int code); |
27 | DEF_HELPER_FLAGS_2(clmulr, TCG_CALL_NO_RWG_SE, tl, tl, tl) | 25 | |
28 | +DEF_HELPER_FLAGS_1(brev8, TCG_CALL_NO_RWG_SE, tl, tl) | 26 | +/** |
29 | +DEF_HELPER_FLAGS_1(unzip, TCG_CALL_NO_RWG_SE, tl, tl) | 27 | + * gdb_qemu_exit: ask qemu to exit |
30 | +DEF_HELPER_FLAGS_1(zip, TCG_CALL_NO_RWG_SE, tl, tl) | 28 | + * @code: exit code reported |
31 | 29 | + * | |
32 | /* Floating Point - Half Precision */ | 30 | + * This requests qemu to exit. This function is allowed to return as |
33 | DEF_HELPER_FLAGS_3(fadd_h, TCG_CALL_NO_RWG, i64, env, i64, i64) | 31 | + * the exit request might be processed asynchronously by qemu backend. |
34 | diff --git a/target/riscv/insn32.decode b/target/riscv/insn32.decode | 32 | + */ |
33 | +void gdb_qemu_exit(int code); | ||
34 | + | ||
35 | #endif /* _SYSCALLS_H_ */ | ||
36 | diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c | ||
35 | index XXXXXXX..XXXXXXX 100644 | 37 | index XXXXXXX..XXXXXXX 100644 |
36 | --- a/target/riscv/insn32.decode | 38 | --- a/gdbstub/gdbstub.c |
37 | +++ b/target/riscv/insn32.decode | 39 | +++ b/gdbstub/gdbstub.c |
38 | @@ -XXX,XX +XXX,XX @@ sh2add_uw 0010000 .......... 100 ..... 0111011 @r | 40 | @@ -XXX,XX +XXX,XX @@ static void handle_v_kill(GArray *params, void *user_ctx) |
39 | sh3add_uw 0010000 .......... 110 ..... 0111011 @r | 41 | gdb_put_packet("OK"); |
40 | slli_uw 00001 ............ 001 ..... 0011011 @sh | 42 | error_report("QEMU: Terminated via GDBstub"); |
41 | 43 | gdb_exit(0); | |
42 | -# *** RV32 Zbb Standard Extension *** | 44 | - exit(0); |
43 | +# *** RV32 Zbb/Zbkb Standard Extension *** | 45 | + gdb_qemu_exit(0); |
44 | andn 0100000 .......... 111 ..... 0110011 @r | 46 | } |
45 | +rol 0110000 .......... 001 ..... 0110011 @r | 47 | |
46 | +ror 0110000 .......... 101 ..... 0110011 @r | 48 | static const GdbCmdParseEntry gdb_v_commands_table[] = { |
47 | +rori 01100 ............ 101 ..... 0010011 @sh | 49 | @@ -XXX,XX +XXX,XX @@ static int gdb_handle_packet(const char *line_buf) |
48 | +# The encoding for rev8 differs between RV32 and RV64. | 50 | /* Kill the target */ |
49 | +# rev8_32 denotes the RV32 variant. | 51 | error_report("QEMU: Terminated via GDBstub"); |
50 | +rev8_32 011010 011000 ..... 101 ..... 0010011 @r2 | 52 | gdb_exit(0); |
51 | +# The encoding for zext.h differs between RV32 and RV64. | 53 | - exit(0); |
52 | +# zext_h_32 denotes the RV32 variant. | 54 | + gdb_qemu_exit(0); |
55 | + break; | ||
56 | case 'D': | ||
57 | { | ||
58 | static const GdbCmdParseEntry detach_cmd_desc = { | ||
59 | diff --git a/gdbstub/system.c b/gdbstub/system.c | ||
60 | index XXXXXXX..XXXXXXX 100644 | ||
61 | --- a/gdbstub/system.c | ||
62 | +++ b/gdbstub/system.c | ||
63 | @@ -XXX,XX +XXX,XX @@ void gdb_exit(int code) | ||
64 | qemu_chr_fe_deinit(&gdbserver_system_state.chr, true); | ||
65 | } | ||
66 | |||
67 | +void gdb_qemu_exit(int code) | ||
53 | +{ | 68 | +{ |
54 | + zext_h_32 0000100 00000 ..... 100 ..... 0110011 @r2 | 69 | + qemu_system_shutdown_request_with_code(SHUTDOWN_CAUSE_GUEST_SHUTDOWN, |
55 | + pack 0000100 ..... ..... 100 ..... 0110011 @r | 70 | + code); |
56 | +} | ||
57 | +xnor 0100000 .......... 100 ..... 0110011 @r | ||
58 | +# *** RV32 extra Zbb Standard Extension *** | ||
59 | clz 011000 000000 ..... 001 ..... 0010011 @r2 | ||
60 | cpop 011000 000010 ..... 001 ..... 0010011 @r2 | ||
61 | ctz 011000 000001 ..... 001 ..... 0010011 @r2 | ||
62 | @@ -XXX,XX +XXX,XX @@ min 0000101 .......... 100 ..... 0110011 @r | ||
63 | minu 0000101 .......... 101 ..... 0110011 @r | ||
64 | orc_b 001010 000111 ..... 101 ..... 0010011 @r2 | ||
65 | orn 0100000 .......... 110 ..... 0110011 @r | ||
66 | -# The encoding for rev8 differs between RV32 and RV64. | ||
67 | -# rev8_32 denotes the RV32 variant. | ||
68 | -rev8_32 011010 011000 ..... 101 ..... 0010011 @r2 | ||
69 | -rol 0110000 .......... 001 ..... 0110011 @r | ||
70 | -ror 0110000 .......... 101 ..... 0110011 @r | ||
71 | -rori 01100 ............ 101 ..... 0010011 @sh | ||
72 | sext_b 011000 000100 ..... 001 ..... 0010011 @r2 | ||
73 | sext_h 011000 000101 ..... 001 ..... 0010011 @r2 | ||
74 | -xnor 0100000 .......... 100 ..... 0110011 @r | ||
75 | -# The encoding for zext.h differs between RV32 and RV64. | ||
76 | -# zext_h_32 denotes the RV32 variant. | ||
77 | -zext_h_32 0000100 00000 ..... 100 ..... 0110011 @r2 | ||
78 | +# *** RV32 extra Zbkb Standard Extension *** | ||
79 | +brev8 0110100 00111 ..... 101 ..... 0010011 @r2 #grevi | ||
80 | +packh 0000100 .......... 111 ..... 0110011 @r | ||
81 | +unzip 0000100 01111 ..... 101 ..... 0010011 @r2 #unshfl | ||
82 | +zip 0000100 01111 ..... 001 ..... 0010011 @r2 #shfl | ||
83 | |||
84 | -# *** RV64 Zbb Standard Extension (in addition to RV32 Zbb) *** | ||
85 | -clzw 0110000 00000 ..... 001 ..... 0011011 @r2 | ||
86 | -ctzw 0110000 00001 ..... 001 ..... 0011011 @r2 | ||
87 | -cpopw 0110000 00010 ..... 001 ..... 0011011 @r2 | ||
88 | +# *** RV64 Zbb/Zbkb Standard Extension (in addition to RV32 Zbb/Zbkb) *** | ||
89 | # The encoding for rev8 differs between RV32 and RV64. | ||
90 | # When executing on RV64, the encoding used in RV32 is an illegal | ||
91 | # instruction, so we use different handler functions to differentiate. | ||
92 | @@ -XXX,XX +XXX,XX @@ rorw 0110000 .......... 101 ..... 0111011 @r | ||
93 | # The encoding for zext.h differs between RV32 and RV64. | ||
94 | # When executing on RV64, the encoding used in RV32 is an illegal | ||
95 | # instruction, so we use different handler functions to differentiate. | ||
96 | -zext_h_64 0000100 00000 ..... 100 ..... 0111011 @r2 | ||
97 | +{ | ||
98 | + zext_h_64 0000100 00000 ..... 100 ..... 0111011 @r2 | ||
99 | + packw 0000100 ..... ..... 100 ..... 0111011 @r | ||
100 | +} | ||
101 | +# *** RV64 extra Zbb Standard Extension (in addition to RV32 Zbb) *** | ||
102 | +clzw 0110000 00000 ..... 001 ..... 0011011 @r2 | ||
103 | +ctzw 0110000 00001 ..... 001 ..... 0011011 @r2 | ||
104 | +cpopw 0110000 00010 ..... 001 ..... 0011011 @r2 | ||
105 | |||
106 | # *** RV32 Zbc Standard Extension *** | ||
107 | clmul 0000101 .......... 001 ..... 0110011 @r | ||
108 | diff --git a/target/riscv/bitmanip_helper.c b/target/riscv/bitmanip_helper.c | ||
109 | index XXXXXXX..XXXXXXX 100644 | ||
110 | --- a/target/riscv/bitmanip_helper.c | ||
111 | +++ b/target/riscv/bitmanip_helper.c | ||
112 | @@ -XXX,XX +XXX,XX @@ target_ulong HELPER(clmulr)(target_ulong rs1, target_ulong rs2) | ||
113 | |||
114 | return result; | ||
115 | } | ||
116 | + | ||
117 | +static inline target_ulong do_swap(target_ulong x, uint64_t mask, int shift) | ||
118 | +{ | ||
119 | + return ((x & mask) << shift) | ((x & ~mask) >> shift); | ||
120 | +} | 71 | +} |
121 | + | 72 | + |
122 | +target_ulong HELPER(brev8)(target_ulong rs1) | 73 | /* |
123 | +{ | 74 | * Memory access |
124 | + target_ulong x = rs1; | 75 | */ |
76 | diff --git a/gdbstub/user.c b/gdbstub/user.c | ||
77 | index XXXXXXX..XXXXXXX 100644 | ||
78 | --- a/gdbstub/user.c | ||
79 | +++ b/gdbstub/user.c | ||
80 | @@ -XXX,XX +XXX,XX @@ void gdb_exit(int code) | ||
81 | gdb_put_packet(buf); | ||
82 | gdbserver_state.allow_stop_reply = false; | ||
83 | } | ||
125 | + | 84 | + |
126 | + x = do_swap(x, 0x5555555555555555ull, 1); | ||
127 | + x = do_swap(x, 0x3333333333333333ull, 2); | ||
128 | + x = do_swap(x, 0x0f0f0f0f0f0f0f0full, 4); | ||
129 | + return x; | ||
130 | +} | 85 | +} |
131 | + | 86 | + |
132 | +static const uint64_t shuf_masks[] = { | 87 | +void gdb_qemu_exit(int code) |
133 | + dup_const(MO_8, 0x44), | ||
134 | + dup_const(MO_8, 0x30), | ||
135 | + dup_const(MO_16, 0x0f00), | ||
136 | + dup_const(MO_32, 0xff0000) | ||
137 | +}; | ||
138 | + | ||
139 | +static inline target_ulong do_shuf_stage(target_ulong src, uint64_t maskL, | ||
140 | + uint64_t maskR, int shift) | ||
141 | +{ | 88 | +{ |
142 | + target_ulong x = src & ~(maskL | maskR); | 89 | + exit(code); |
143 | + | ||
144 | + x |= ((src << shift) & maskL) | ((src >> shift) & maskR); | ||
145 | + return x; | ||
146 | +} | ||
147 | + | ||
148 | +target_ulong HELPER(unzip)(target_ulong rs1) | ||
149 | +{ | ||
150 | + target_ulong x = rs1; | ||
151 | + | ||
152 | + x = do_shuf_stage(x, shuf_masks[0], shuf_masks[0] >> 1, 1); | ||
153 | + x = do_shuf_stage(x, shuf_masks[1], shuf_masks[1] >> 2, 2); | ||
154 | + x = do_shuf_stage(x, shuf_masks[2], shuf_masks[2] >> 4, 4); | ||
155 | + x = do_shuf_stage(x, shuf_masks[3], shuf_masks[3] >> 8, 8); | ||
156 | + return x; | ||
157 | +} | ||
158 | + | ||
159 | +target_ulong HELPER(zip)(target_ulong rs1) | ||
160 | +{ | ||
161 | + target_ulong x = rs1; | ||
162 | + | ||
163 | + x = do_shuf_stage(x, shuf_masks[3], shuf_masks[3] >> 8, 8); | ||
164 | + x = do_shuf_stage(x, shuf_masks[2], shuf_masks[2] >> 4, 4); | ||
165 | + x = do_shuf_stage(x, shuf_masks[1], shuf_masks[1] >> 2, 2); | ||
166 | + x = do_shuf_stage(x, shuf_masks[0], shuf_masks[0] >> 1, 1); | ||
167 | + return x; | ||
168 | +} | ||
169 | diff --git a/target/riscv/translate.c b/target/riscv/translate.c | ||
170 | index XXXXXXX..XXXXXXX 100644 | ||
171 | --- a/target/riscv/translate.c | ||
172 | +++ b/target/riscv/translate.c | ||
173 | @@ -XXX,XX +XXX,XX @@ EX_SH(12) | ||
174 | } \ | ||
175 | } while (0) | ||
176 | |||
177 | +#define REQUIRE_EITHER_EXT(ctx, A, B) do { \ | ||
178 | + if (!ctx->cfg_ptr->ext_##A && \ | ||
179 | + !ctx->cfg_ptr->ext_##B) { \ | ||
180 | + return false; \ | ||
181 | + } \ | ||
182 | +} while (0) | ||
183 | + | ||
184 | static int ex_rvc_register(DisasContext *ctx, int reg) | ||
185 | { | ||
186 | return 8 + reg; | ||
187 | diff --git a/target/riscv/insn_trans/trans_rvb.c.inc b/target/riscv/insn_trans/trans_rvb.c.inc | ||
188 | index XXXXXXX..XXXXXXX 100644 | ||
189 | --- a/target/riscv/insn_trans/trans_rvb.c.inc | ||
190 | +++ b/target/riscv/insn_trans/trans_rvb.c.inc | ||
191 | @@ -XXX,XX +XXX,XX @@ | ||
192 | /* | ||
193 | - * RISC-V translation routines for the Zb[abcs] Standard Extension. | ||
194 | + * RISC-V translation routines for the Zb[abcs] and Zbk[bcx] Standard Extension. | ||
195 | * | ||
196 | * Copyright (c) 2020 Kito Cheng, kito.cheng@sifive.com | ||
197 | * Copyright (c) 2020 Frank Chang, frank.chang@sifive.com | ||
198 | @@ -XXX,XX +XXX,XX @@ | ||
199 | } \ | ||
200 | } while (0) | ||
201 | |||
202 | +#define REQUIRE_ZBKB(ctx) do { \ | ||
203 | + if (!ctx->cfg_ptr->ext_zbkb) { \ | ||
204 | + return false; \ | ||
205 | + } \ | ||
206 | +} while (0) | ||
207 | + | ||
208 | static void gen_clz(TCGv ret, TCGv arg1) | ||
209 | { | ||
210 | tcg_gen_clzi_tl(ret, arg1, TARGET_LONG_BITS); | ||
211 | @@ -XXX,XX +XXX,XX @@ static bool trans_cpop(DisasContext *ctx, arg_cpop *a) | ||
212 | |||
213 | static bool trans_andn(DisasContext *ctx, arg_andn *a) | ||
214 | { | ||
215 | - REQUIRE_ZBB(ctx); | ||
216 | + REQUIRE_EITHER_EXT(ctx, zbb, zbkb); | ||
217 | return gen_logic(ctx, a, tcg_gen_andc_tl); | ||
218 | } | 90 | } |
219 | 91 | ||
220 | static bool trans_orn(DisasContext *ctx, arg_orn *a) | 92 | int gdb_handlesig(CPUState *cpu, int sig) |
221 | { | ||
222 | - REQUIRE_ZBB(ctx); | ||
223 | + REQUIRE_EITHER_EXT(ctx, zbb, zbkb); | ||
224 | return gen_logic(ctx, a, tcg_gen_orc_tl); | ||
225 | } | ||
226 | |||
227 | static bool trans_xnor(DisasContext *ctx, arg_xnor *a) | ||
228 | { | ||
229 | - REQUIRE_ZBB(ctx); | ||
230 | + REQUIRE_EITHER_EXT(ctx, zbb, zbkb); | ||
231 | return gen_logic(ctx, a, tcg_gen_eqv_tl); | ||
232 | } | ||
233 | |||
234 | @@ -XXX,XX +XXX,XX @@ static void gen_rorw(TCGv ret, TCGv arg1, TCGv arg2) | ||
235 | |||
236 | static bool trans_ror(DisasContext *ctx, arg_ror *a) | ||
237 | { | ||
238 | - REQUIRE_ZBB(ctx); | ||
239 | + REQUIRE_EITHER_EXT(ctx, zbb, zbkb); | ||
240 | return gen_shift_per_ol(ctx, a, EXT_NONE, tcg_gen_rotr_tl, gen_rorw, NULL); | ||
241 | } | ||
242 | |||
243 | @@ -XXX,XX +XXX,XX @@ static void gen_roriw(TCGv ret, TCGv arg1, target_long shamt) | ||
244 | |||
245 | static bool trans_rori(DisasContext *ctx, arg_rori *a) | ||
246 | { | ||
247 | - REQUIRE_ZBB(ctx); | ||
248 | + REQUIRE_EITHER_EXT(ctx, zbb, zbkb); | ||
249 | return gen_shift_imm_fn_per_ol(ctx, a, EXT_NONE, | ||
250 | tcg_gen_rotri_tl, gen_roriw, NULL); | ||
251 | } | ||
252 | @@ -XXX,XX +XXX,XX @@ static void gen_rolw(TCGv ret, TCGv arg1, TCGv arg2) | ||
253 | |||
254 | static bool trans_rol(DisasContext *ctx, arg_rol *a) | ||
255 | { | ||
256 | - REQUIRE_ZBB(ctx); | ||
257 | + REQUIRE_EITHER_EXT(ctx, zbb, zbkb); | ||
258 | return gen_shift_per_ol(ctx, a, EXT_NONE, tcg_gen_rotl_tl, gen_rolw, NULL); | ||
259 | } | ||
260 | |||
261 | @@ -XXX,XX +XXX,XX @@ static void gen_rev8_32(TCGv ret, TCGv src1) | ||
262 | static bool trans_rev8_32(DisasContext *ctx, arg_rev8_32 *a) | ||
263 | { | ||
264 | REQUIRE_32BIT(ctx); | ||
265 | - REQUIRE_ZBB(ctx); | ||
266 | + REQUIRE_EITHER_EXT(ctx, zbb, zbkb); | ||
267 | return gen_unary(ctx, a, EXT_NONE, gen_rev8_32); | ||
268 | } | ||
269 | |||
270 | static bool trans_rev8_64(DisasContext *ctx, arg_rev8_64 *a) | ||
271 | { | ||
272 | REQUIRE_64BIT(ctx); | ||
273 | - REQUIRE_ZBB(ctx); | ||
274 | + REQUIRE_EITHER_EXT(ctx, zbb, zbkb); | ||
275 | return gen_unary(ctx, a, EXT_NONE, tcg_gen_bswap_tl); | ||
276 | } | ||
277 | |||
278 | @@ -XXX,XX +XXX,XX @@ static bool trans_cpopw(DisasContext *ctx, arg_cpopw *a) | ||
279 | static bool trans_rorw(DisasContext *ctx, arg_rorw *a) | ||
280 | { | ||
281 | REQUIRE_64BIT(ctx); | ||
282 | - REQUIRE_ZBB(ctx); | ||
283 | + REQUIRE_EITHER_EXT(ctx, zbb, zbkb); | ||
284 | ctx->ol = MXL_RV32; | ||
285 | return gen_shift(ctx, a, EXT_NONE, gen_rorw, NULL); | ||
286 | } | ||
287 | @@ -XXX,XX +XXX,XX @@ static bool trans_rorw(DisasContext *ctx, arg_rorw *a) | ||
288 | static bool trans_roriw(DisasContext *ctx, arg_roriw *a) | ||
289 | { | ||
290 | REQUIRE_64BIT(ctx); | ||
291 | - REQUIRE_ZBB(ctx); | ||
292 | + REQUIRE_EITHER_EXT(ctx, zbb, zbkb); | ||
293 | ctx->ol = MXL_RV32; | ||
294 | return gen_shift_imm_fn(ctx, a, EXT_NONE, gen_roriw, NULL); | ||
295 | } | ||
296 | @@ -XXX,XX +XXX,XX @@ static bool trans_roriw(DisasContext *ctx, arg_roriw *a) | ||
297 | static bool trans_rolw(DisasContext *ctx, arg_rolw *a) | ||
298 | { | ||
299 | REQUIRE_64BIT(ctx); | ||
300 | - REQUIRE_ZBB(ctx); | ||
301 | + REQUIRE_EITHER_EXT(ctx, zbb, zbkb); | ||
302 | ctx->ol = MXL_RV32; | ||
303 | return gen_shift(ctx, a, EXT_NONE, gen_rolw, NULL); | ||
304 | } | ||
305 | @@ -XXX,XX +XXX,XX @@ static bool trans_clmulr(DisasContext *ctx, arg_clmulh *a) | ||
306 | REQUIRE_ZBC(ctx); | ||
307 | return gen_arith(ctx, a, EXT_NONE, gen_helper_clmulr, NULL); | ||
308 | } | ||
309 | + | ||
310 | +static void gen_pack(TCGv ret, TCGv src1, TCGv src2) | ||
311 | +{ | ||
312 | + tcg_gen_deposit_tl(ret, src1, src2, | ||
313 | + TARGET_LONG_BITS / 2, | ||
314 | + TARGET_LONG_BITS / 2); | ||
315 | +} | ||
316 | + | ||
317 | +static void gen_packh(TCGv ret, TCGv src1, TCGv src2) | ||
318 | +{ | ||
319 | + TCGv t = tcg_temp_new(); | ||
320 | + | ||
321 | + tcg_gen_ext8u_tl(t, src2); | ||
322 | + tcg_gen_deposit_tl(ret, src1, t, 8, TARGET_LONG_BITS - 8); | ||
323 | + tcg_temp_free(t); | ||
324 | +} | ||
325 | + | ||
326 | +static void gen_packw(TCGv ret, TCGv src1, TCGv src2) | ||
327 | +{ | ||
328 | + TCGv t = tcg_temp_new(); | ||
329 | + | ||
330 | + tcg_gen_ext16s_tl(t, src2); | ||
331 | + tcg_gen_deposit_tl(ret, src1, t, 16, TARGET_LONG_BITS - 16); | ||
332 | + tcg_temp_free(t); | ||
333 | +} | ||
334 | + | ||
335 | +static bool trans_brev8(DisasContext *ctx, arg_brev8 *a) | ||
336 | +{ | ||
337 | + REQUIRE_ZBKB(ctx); | ||
338 | + return gen_unary(ctx, a, EXT_NONE, gen_helper_brev8); | ||
339 | +} | ||
340 | + | ||
341 | +static bool trans_pack(DisasContext *ctx, arg_pack *a) | ||
342 | +{ | ||
343 | + REQUIRE_ZBKB(ctx); | ||
344 | + return gen_arith(ctx, a, EXT_NONE, gen_pack, NULL); | ||
345 | +} | ||
346 | + | ||
347 | +static bool trans_packh(DisasContext *ctx, arg_packh *a) | ||
348 | +{ | ||
349 | + REQUIRE_ZBKB(ctx); | ||
350 | + return gen_arith(ctx, a, EXT_NONE, gen_packh, NULL); | ||
351 | +} | ||
352 | + | ||
353 | +static bool trans_packw(DisasContext *ctx, arg_packw *a) | ||
354 | +{ | ||
355 | + REQUIRE_64BIT(ctx); | ||
356 | + REQUIRE_ZBKB(ctx); | ||
357 | + return gen_arith(ctx, a, EXT_NONE, gen_packw, NULL); | ||
358 | +} | ||
359 | + | ||
360 | +static bool trans_unzip(DisasContext *ctx, arg_unzip *a) | ||
361 | +{ | ||
362 | + REQUIRE_32BIT(ctx); | ||
363 | + REQUIRE_ZBKB(ctx); | ||
364 | + return gen_unary(ctx, a, EXT_NONE, gen_helper_unzip); | ||
365 | +} | ||
366 | + | ||
367 | +static bool trans_zip(DisasContext *ctx, arg_zip *a) | ||
368 | +{ | ||
369 | + REQUIRE_32BIT(ctx); | ||
370 | + REQUIRE_ZBKB(ctx); | ||
371 | + return gen_unary(ctx, a, EXT_NONE, gen_helper_zip); | ||
372 | +} | ||
373 | -- | 93 | -- |
374 | 2.35.1 | 94 | 2.41.0 |
95 | |||
96 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
1 | 2 | ||
3 | Our error message is returning the value of 'ret', which will be always | ||
4 | -1 in case of error, and will not be that useful: | ||
5 | |||
6 | qemu-system-riscv64: Unable to read ISA_EXT KVM register ssaia, error -1 | ||
7 | |||
8 | Improve the error message by outputting 'errno' instead of 'ret'. Use | ||
9 | strerrorname_np() to output the error name instead of the error code. | ||
10 | This will give us what we need to know right away: | ||
11 | |||
12 | qemu-system-riscv64: Unable to read ISA_EXT KVM register ssaia, error code: ENOENT | ||
13 | |||
14 | Given that we're going to exit(1) in this condition instead of | ||
15 | attempting to recover, remove the 'kvm_riscv_destroy_scratch_vcpu()' | ||
16 | call. | ||
17 | |||
18 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
19 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
20 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> | ||
21 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | ||
22 | Message-ID: <20231003132148.797921-2-dbarboza@ventanamicro.com> | ||
23 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
24 | --- | ||
25 | target/riscv/kvm/kvm-cpu.c | 4 ++-- | ||
26 | 1 file changed, 2 insertions(+), 2 deletions(-) | ||
27 | |||
28 | diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c | ||
29 | index XXXXXXX..XXXXXXX 100644 | ||
30 | --- a/target/riscv/kvm/kvm-cpu.c | ||
31 | +++ b/target/riscv/kvm/kvm-cpu.c | ||
32 | @@ -XXX,XX +XXX,XX @@ static void kvm_riscv_init_multiext_cfg(RISCVCPU *cpu, KVMScratchCPU *kvmcpu) | ||
33 | val = false; | ||
34 | } else { | ||
35 | error_report("Unable to read ISA_EXT KVM register %s, " | ||
36 | - "error %d", multi_ext_cfg->name, ret); | ||
37 | - kvm_riscv_destroy_scratch_vcpu(kvmcpu); | ||
38 | + "error code: %s", multi_ext_cfg->name, | ||
39 | + strerrorname_np(errno)); | ||
40 | exit(EXIT_FAILURE); | ||
41 | } | ||
42 | } else { | ||
43 | -- | ||
44 | 2.41.0 | ||
45 | |||
46 | diff view generated by jsdifflib |
1 | From: Alistair Francis <alistair.francis@wdc.com> | 1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
---|---|---|---|
2 | 2 | ||
3 | Move the binary and device tree loading code to the machine done | 3 | KVM for RISC-V started supporting KVM_GET_REG_LIST in Linux 6.6. It |
4 | notifier. This allows us to prepare for editing the device tree as part | 4 | consists of a KVM ioctl() that retrieves a list of all available regs |
5 | of the notifier. | 5 | for get_one_reg/set_one_reg. Regs that aren't present in the list aren't |
6 | supported in the host. | ||
6 | 7 | ||
7 | This is based on similar code in the ARM virt machine. | 8 | This simplifies our lives when initing the KVM regs since we don't have |
9 | to always attempt a KVM_GET_ONE_REG for all regs QEMU knows. We'll only | ||
10 | attempt a get_one_reg() if we're sure the reg is supported, i.e. it was | ||
11 | retrieved by KVM_GET_REG_LIST. Any error in get_one_reg() will then | ||
12 | always considered fatal, instead of having to handle special error codes | ||
13 | that might indicate a non-fatal failure. | ||
8 | 14 | ||
9 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 15 | Start by moving the current kvm_riscv_init_multiext_cfg() logic into a |
10 | Reviewed-by: Edgar E. Iglesias <edgar.iglesias@amd.com> | 16 | new kvm_riscv_read_multiext_legacy() helper. We'll prioritize using |
11 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> | 17 | KVM_GET_REG_LIST, so check if we have it available and, in case we |
12 | Message-Id: <20220427234146.1130752-2-alistair.francis@opensource.wdc.com> | 18 | don't, use the legacy() logic. |
19 | |||
20 | Otherwise, retrieve the available reg list and use it to check if the | ||
21 | host supports our known KVM regs, doing the usual get_one_reg() for | ||
22 | the supported regs and setting cpu->cfg accordingly. | ||
23 | |||
24 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
25 | Acked-by: Alistair Francis <alistair.francis@wdc.com> | ||
26 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> | ||
27 | Message-ID: <20231003132148.797921-3-dbarboza@ventanamicro.com> | ||
13 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 28 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
14 | --- | 29 | --- |
15 | include/hw/riscv/virt.h | 1 + | 30 | target/riscv/kvm/kvm-cpu.c | 96 +++++++++++++++++++++++++++++++++++++- |
16 | hw/riscv/virt.c | 191 +++++++++++++++++++++------------------- | 31 | 1 file changed, 95 insertions(+), 1 deletion(-) |
17 | 2 files changed, 102 insertions(+), 90 deletions(-) | ||
18 | 32 | ||
19 | diff --git a/include/hw/riscv/virt.h b/include/hw/riscv/virt.h | 33 | diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c |
20 | index XXXXXXX..XXXXXXX 100644 | 34 | index XXXXXXX..XXXXXXX 100644 |
21 | --- a/include/hw/riscv/virt.h | 35 | --- a/target/riscv/kvm/kvm-cpu.c |
22 | +++ b/include/hw/riscv/virt.h | 36 | +++ b/target/riscv/kvm/kvm-cpu.c |
23 | @@ -XXX,XX +XXX,XX @@ struct RISCVVirtState { | 37 | @@ -XXX,XX +XXX,XX @@ static void kvm_riscv_read_cbomz_blksize(RISCVCPU *cpu, KVMScratchCPU *kvmcpu, |
24 | MachineState parent; | 38 | } |
25 | |||
26 | /*< public >*/ | ||
27 | + Notifier machine_done; | ||
28 | RISCVHartArrayState soc[VIRT_SOCKETS_MAX]; | ||
29 | DeviceState *irqchip[VIRT_SOCKETS_MAX]; | ||
30 | PFlashCFI01 *flash[2]; | ||
31 | diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c | ||
32 | index XXXXXXX..XXXXXXX 100644 | ||
33 | --- a/hw/riscv/virt.c | ||
34 | +++ b/hw/riscv/virt.c | ||
35 | @@ -XXX,XX +XXX,XX @@ static DeviceState *virt_create_aia(RISCVVirtAIAType aia_type, int aia_guests, | ||
36 | return aplic_m; | ||
37 | } | 39 | } |
38 | 40 | ||
39 | +static void virt_machine_done(Notifier *notifier, void *data) | 41 | -static void kvm_riscv_init_multiext_cfg(RISCVCPU *cpu, KVMScratchCPU *kvmcpu) |
42 | +static void kvm_riscv_read_multiext_legacy(RISCVCPU *cpu, | ||
43 | + KVMScratchCPU *kvmcpu) | ||
44 | { | ||
45 | CPURISCVState *env = &cpu->env; | ||
46 | uint64_t val; | ||
47 | @@ -XXX,XX +XXX,XX @@ static void kvm_riscv_init_multiext_cfg(RISCVCPU *cpu, KVMScratchCPU *kvmcpu) | ||
48 | } | ||
49 | } | ||
50 | |||
51 | +static int uint64_cmp(const void *a, const void *b) | ||
40 | +{ | 52 | +{ |
41 | + RISCVVirtState *s = container_of(notifier, RISCVVirtState, | 53 | + uint64_t val1 = *(const uint64_t *)a; |
42 | + machine_done); | 54 | + uint64_t val2 = *(const uint64_t *)b; |
43 | + const MemMapEntry *memmap = virt_memmap; | 55 | + |
44 | + MachineState *machine = MACHINE(s); | 56 | + if (val1 < val2) { |
45 | + target_ulong start_addr = memmap[VIRT_DRAM].base; | 57 | + return -1; |
46 | + target_ulong firmware_end_addr, kernel_start_addr; | 58 | + } |
47 | + uint32_t fdt_load_addr; | 59 | + |
48 | + uint64_t kernel_entry; | 60 | + if (val1 > val2) { |
61 | + return 1; | ||
62 | + } | ||
63 | + | ||
64 | + return 0; | ||
65 | +} | ||
66 | + | ||
67 | +static void kvm_riscv_init_multiext_cfg(RISCVCPU *cpu, KVMScratchCPU *kvmcpu) | ||
68 | +{ | ||
69 | + KVMCPUConfig *multi_ext_cfg; | ||
70 | + struct kvm_one_reg reg; | ||
71 | + struct kvm_reg_list rl_struct; | ||
72 | + struct kvm_reg_list *reglist; | ||
73 | + uint64_t val, reg_id, *reg_search; | ||
74 | + int i, ret; | ||
75 | + | ||
76 | + rl_struct.n = 0; | ||
77 | + ret = ioctl(kvmcpu->cpufd, KVM_GET_REG_LIST, &rl_struct); | ||
49 | + | 78 | + |
50 | + /* | 79 | + /* |
51 | + * Only direct boot kernel is currently supported for KVM VM, | 80 | + * If KVM_GET_REG_LIST isn't supported we'll get errno 22 |
52 | + * so the "-bios" parameter is not supported when KVM is enabled. | 81 | + * (EINVAL). Use read_legacy() in this case. |
53 | + */ | 82 | + */ |
54 | + if (kvm_enabled()) { | 83 | + if (errno == EINVAL) { |
55 | + if (machine->firmware) { | 84 | + return kvm_riscv_read_multiext_legacy(cpu, kvmcpu); |
56 | + if (strcmp(machine->firmware, "none")) { | 85 | + } else if (errno != E2BIG) { |
57 | + error_report("Machine mode firmware is not supported in " | 86 | + /* |
58 | + "combination with KVM."); | 87 | + * E2BIG is an expected error message for the API since we |
59 | + exit(1); | 88 | + * don't know the number of registers. The right amount will |
60 | + } | 89 | + * be written in rl_struct.n. |
61 | + } else { | 90 | + * |
62 | + machine->firmware = g_strdup("none"); | 91 | + * Error out if we get any other errno. |
63 | + } | 92 | + */ |
93 | + error_report("Error when accessing get-reg-list, code: %s", | ||
94 | + strerrorname_np(errno)); | ||
95 | + exit(EXIT_FAILURE); | ||
64 | + } | 96 | + } |
65 | + | 97 | + |
66 | + if (riscv_is_32bit(&s->soc[0])) { | 98 | + reglist = g_malloc(sizeof(struct kvm_reg_list) + |
67 | + firmware_end_addr = riscv_find_and_load_firmware(machine, | 99 | + rl_struct.n * sizeof(uint64_t)); |
68 | + RISCV32_BIOS_BIN, start_addr, NULL); | 100 | + reglist->n = rl_struct.n; |
69 | + } else { | 101 | + ret = ioctl(kvmcpu->cpufd, KVM_GET_REG_LIST, reglist); |
70 | + firmware_end_addr = riscv_find_and_load_firmware(machine, | 102 | + if (ret) { |
71 | + RISCV64_BIOS_BIN, start_addr, NULL); | 103 | + error_report("Error when reading KVM_GET_REG_LIST, code %s ", |
104 | + strerrorname_np(errno)); | ||
105 | + exit(EXIT_FAILURE); | ||
72 | + } | 106 | + } |
73 | + | 107 | + |
74 | + if (machine->kernel_filename) { | 108 | + /* sort reglist to use bsearch() */ |
75 | + kernel_start_addr = riscv_calc_kernel_start_addr(&s->soc[0], | 109 | + qsort(®list->reg, reglist->n, sizeof(uint64_t), uint64_cmp); |
76 | + firmware_end_addr); | ||
77 | + | 110 | + |
78 | + kernel_entry = riscv_load_kernel(machine->kernel_filename, | 111 | + for (i = 0; i < ARRAY_SIZE(kvm_multi_ext_cfgs); i++) { |
79 | + kernel_start_addr, NULL); | 112 | + multi_ext_cfg = &kvm_multi_ext_cfgs[i]; |
113 | + reg_id = kvm_riscv_reg_id(&cpu->env, KVM_REG_RISCV_ISA_EXT, | ||
114 | + multi_ext_cfg->kvm_reg_id); | ||
115 | + reg_search = bsearch(®_id, reglist->reg, reglist->n, | ||
116 | + sizeof(uint64_t), uint64_cmp); | ||
117 | + if (!reg_search) { | ||
118 | + continue; | ||
119 | + } | ||
80 | + | 120 | + |
81 | + if (machine->initrd_filename) { | 121 | + reg.id = reg_id; |
82 | + hwaddr start; | 122 | + reg.addr = (uint64_t)&val; |
83 | + hwaddr end = riscv_load_initrd(machine->initrd_filename, | 123 | + ret = ioctl(kvmcpu->cpufd, KVM_GET_ONE_REG, ®); |
84 | + machine->ram_size, kernel_entry, | 124 | + if (ret != 0) { |
85 | + &start); | 125 | + error_report("Unable to read ISA_EXT KVM register %s, " |
86 | + qemu_fdt_setprop_cell(machine->fdt, "/chosen", | 126 | + "error code: %s", multi_ext_cfg->name, |
87 | + "linux,initrd-start", start); | 127 | + strerrorname_np(errno)); |
88 | + qemu_fdt_setprop_cell(machine->fdt, "/chosen", "linux,initrd-end", | 128 | + exit(EXIT_FAILURE); |
89 | + end); | ||
90 | + } | 129 | + } |
91 | + } else { | 130 | + |
92 | + /* | 131 | + multi_ext_cfg->supported = true; |
93 | + * If dynamic firmware is used, it doesn't know where is the next mode | 132 | + kvm_cpu_cfg_set(cpu, multi_ext_cfg, val); |
94 | + * if kernel argument is not set. | ||
95 | + */ | ||
96 | + kernel_entry = 0; | ||
97 | + } | 133 | + } |
98 | + | 134 | + |
99 | + if (drive_get(IF_PFLASH, 0, 0)) { | 135 | + if (cpu->cfg.ext_icbom) { |
100 | + /* | 136 | + kvm_riscv_read_cbomz_blksize(cpu, kvmcpu, &kvm_cbom_blocksize); |
101 | + * Pflash was supplied, let's overwrite the address we jump to after | ||
102 | + * reset to the base of the flash. | ||
103 | + */ | ||
104 | + start_addr = virt_memmap[VIRT_FLASH].base; | ||
105 | + } | 137 | + } |
106 | + | 138 | + |
107 | + /* | 139 | + if (cpu->cfg.ext_icboz) { |
108 | + * Init fw_cfg. Must be done before riscv_load_fdt, otherwise the device | 140 | + kvm_riscv_read_cbomz_blksize(cpu, kvmcpu, &kvm_cboz_blocksize); |
109 | + * tree cannot be altered and we get FDT_ERR_NOSPACE. | ||
110 | + */ | ||
111 | + s->fw_cfg = create_fw_cfg(machine); | ||
112 | + rom_set_fw(s->fw_cfg); | ||
113 | + | ||
114 | + /* Compute the fdt load address in dram */ | ||
115 | + fdt_load_addr = riscv_load_fdt(memmap[VIRT_DRAM].base, | ||
116 | + machine->ram_size, machine->fdt); | ||
117 | + /* load the reset vector */ | ||
118 | + riscv_setup_rom_reset_vec(machine, &s->soc[0], start_addr, | ||
119 | + virt_memmap[VIRT_MROM].base, | ||
120 | + virt_memmap[VIRT_MROM].size, kernel_entry, | ||
121 | + fdt_load_addr, machine->fdt); | ||
122 | + | ||
123 | + /* | ||
124 | + * Only direct boot kernel is currently supported for KVM VM, | ||
125 | + * So here setup kernel start address and fdt address. | ||
126 | + * TODO:Support firmware loading and integrate to TCG start | ||
127 | + */ | ||
128 | + if (kvm_enabled()) { | ||
129 | + riscv_setup_direct_kernel(kernel_entry, fdt_load_addr); | ||
130 | + } | 141 | + } |
131 | +} | 142 | +} |
132 | + | 143 | + |
133 | static void virt_machine_init(MachineState *machine) | 144 | static void riscv_init_kvm_registers(Object *cpu_obj) |
134 | { | 145 | { |
135 | const MemMapEntry *memmap = virt_memmap; | 146 | RISCVCPU *cpu = RISCV_CPU(cpu_obj); |
136 | @@ -XXX,XX +XXX,XX @@ static void virt_machine_init(MachineState *machine) | ||
137 | MemoryRegion *system_memory = get_system_memory(); | ||
138 | MemoryRegion *mask_rom = g_new(MemoryRegion, 1); | ||
139 | char *soc_name; | ||
140 | - target_ulong start_addr = memmap[VIRT_DRAM].base; | ||
141 | - target_ulong firmware_end_addr, kernel_start_addr; | ||
142 | - uint32_t fdt_load_addr; | ||
143 | - uint64_t kernel_entry; | ||
144 | DeviceState *mmio_irqchip, *virtio_irqchip, *pcie_irqchip; | ||
145 | int i, base_hartid, hart_count; | ||
146 | |||
147 | @@ -XXX,XX +XXX,XX @@ static void virt_machine_init(MachineState *machine) | ||
148 | memory_region_add_subregion(system_memory, memmap[VIRT_DRAM].base, | ||
149 | machine->ram); | ||
150 | |||
151 | - /* create device tree */ | ||
152 | - create_fdt(s, memmap, machine->ram_size, machine->kernel_cmdline, | ||
153 | - riscv_is_32bit(&s->soc[0])); | ||
154 | - | ||
155 | /* boot rom */ | ||
156 | memory_region_init_rom(mask_rom, NULL, "riscv_virt_board.mrom", | ||
157 | memmap[VIRT_MROM].size, &error_fatal); | ||
158 | memory_region_add_subregion(system_memory, memmap[VIRT_MROM].base, | ||
159 | mask_rom); | ||
160 | |||
161 | - /* | ||
162 | - * Only direct boot kernel is currently supported for KVM VM, | ||
163 | - * so the "-bios" parameter is not supported when KVM is enabled. | ||
164 | - */ | ||
165 | - if (kvm_enabled()) { | ||
166 | - if (machine->firmware) { | ||
167 | - if (strcmp(machine->firmware, "none")) { | ||
168 | - error_report("Machine mode firmware is not supported in " | ||
169 | - "combination with KVM."); | ||
170 | - exit(1); | ||
171 | - } | ||
172 | - } else { | ||
173 | - machine->firmware = g_strdup("none"); | ||
174 | - } | ||
175 | - } | ||
176 | - | ||
177 | - if (riscv_is_32bit(&s->soc[0])) { | ||
178 | - firmware_end_addr = riscv_find_and_load_firmware(machine, | ||
179 | - RISCV32_BIOS_BIN, start_addr, NULL); | ||
180 | - } else { | ||
181 | - firmware_end_addr = riscv_find_and_load_firmware(machine, | ||
182 | - RISCV64_BIOS_BIN, start_addr, NULL); | ||
183 | - } | ||
184 | - | ||
185 | - if (machine->kernel_filename) { | ||
186 | - kernel_start_addr = riscv_calc_kernel_start_addr(&s->soc[0], | ||
187 | - firmware_end_addr); | ||
188 | - | ||
189 | - kernel_entry = riscv_load_kernel(machine->kernel_filename, | ||
190 | - kernel_start_addr, NULL); | ||
191 | - | ||
192 | - if (machine->initrd_filename) { | ||
193 | - hwaddr start; | ||
194 | - hwaddr end = riscv_load_initrd(machine->initrd_filename, | ||
195 | - machine->ram_size, kernel_entry, | ||
196 | - &start); | ||
197 | - qemu_fdt_setprop_cell(machine->fdt, "/chosen", | ||
198 | - "linux,initrd-start", start); | ||
199 | - qemu_fdt_setprop_cell(machine->fdt, "/chosen", "linux,initrd-end", | ||
200 | - end); | ||
201 | - } | ||
202 | - } else { | ||
203 | - /* | ||
204 | - * If dynamic firmware is used, it doesn't know where is the next mode | ||
205 | - * if kernel argument is not set. | ||
206 | - */ | ||
207 | - kernel_entry = 0; | ||
208 | - } | ||
209 | - | ||
210 | - if (drive_get(IF_PFLASH, 0, 0)) { | ||
211 | - /* | ||
212 | - * Pflash was supplied, let's overwrite the address we jump to after | ||
213 | - * reset to the base of the flash. | ||
214 | - */ | ||
215 | - start_addr = virt_memmap[VIRT_FLASH].base; | ||
216 | - } | ||
217 | - | ||
218 | - /* | ||
219 | - * Init fw_cfg. Must be done before riscv_load_fdt, otherwise the device | ||
220 | - * tree cannot be altered and we get FDT_ERR_NOSPACE. | ||
221 | - */ | ||
222 | - s->fw_cfg = create_fw_cfg(machine); | ||
223 | - rom_set_fw(s->fw_cfg); | ||
224 | - | ||
225 | - /* Compute the fdt load address in dram */ | ||
226 | - fdt_load_addr = riscv_load_fdt(memmap[VIRT_DRAM].base, | ||
227 | - machine->ram_size, machine->fdt); | ||
228 | - /* load the reset vector */ | ||
229 | - riscv_setup_rom_reset_vec(machine, &s->soc[0], start_addr, | ||
230 | - virt_memmap[VIRT_MROM].base, | ||
231 | - virt_memmap[VIRT_MROM].size, kernel_entry, | ||
232 | - fdt_load_addr, machine->fdt); | ||
233 | - | ||
234 | - /* | ||
235 | - * Only direct boot kernel is currently supported for KVM VM, | ||
236 | - * So here setup kernel start address and fdt address. | ||
237 | - * TODO:Support firmware loading and integrate to TCG start | ||
238 | - */ | ||
239 | - if (kvm_enabled()) { | ||
240 | - riscv_setup_direct_kernel(kernel_entry, fdt_load_addr); | ||
241 | - } | ||
242 | - | ||
243 | /* SiFive Test MMIO device */ | ||
244 | sifive_test_create(memmap[VIRT_TEST].base); | ||
245 | |||
246 | @@ -XXX,XX +XXX,XX @@ static void virt_machine_init(MachineState *machine) | ||
247 | drive_get(IF_PFLASH, 0, i)); | ||
248 | } | ||
249 | virt_flash_map(s, system_memory); | ||
250 | + | ||
251 | + /* create device tree */ | ||
252 | + create_fdt(s, memmap, machine->ram_size, machine->kernel_cmdline, | ||
253 | + riscv_is_32bit(&s->soc[0])); | ||
254 | + | ||
255 | + s->machine_done.notify = virt_machine_done; | ||
256 | + qemu_add_machine_init_done_notifier(&s->machine_done); | ||
257 | } | ||
258 | |||
259 | static void virt_machine_instance_init(Object *obj) | ||
260 | -- | 147 | -- |
261 | 2.35.1 | 148 | 2.41.0 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
1 | 2 | ||
3 | Vendor CPUs that set RVG are displaying user warnings about other | ||
4 | extensions that RVG must enable, one warning per CPU. E.g.: | ||
5 | |||
6 | $ ./build/qemu-system-riscv64 -smp 8 -M virt -cpu veyron-v1 -nographic | ||
7 | qemu-system-riscv64: warning: Setting G will also set IMAFD_Zicsr_Zifencei | ||
8 | qemu-system-riscv64: warning: Setting G will also set IMAFD_Zicsr_Zifencei | ||
9 | qemu-system-riscv64: warning: Setting G will also set IMAFD_Zicsr_Zifencei | ||
10 | qemu-system-riscv64: warning: Setting G will also set IMAFD_Zicsr_Zifencei | ||
11 | qemu-system-riscv64: warning: Setting G will also set IMAFD_Zicsr_Zifencei | ||
12 | qemu-system-riscv64: warning: Setting G will also set IMAFD_Zicsr_Zifencei | ||
13 | qemu-system-riscv64: warning: Setting G will also set IMAFD_Zicsr_Zifencei | ||
14 | qemu-system-riscv64: warning: Setting G will also set IMAFD_Zicsr_Zifencei | ||
15 | |||
16 | This happens because we decided a while ago that, for simplicity, vendor | ||
17 | CPUs could set RVG instead of setting each G extension individually in | ||
18 | their cpu_init(). Our warning isn't taking that into account, and we're | ||
19 | bugging users with a warning that we're causing ourselves. | ||
20 | |||
21 | In a closer look we conclude that this warning is not warranted in any | ||
22 | other circumstance since we're just following the ISA [1], which states | ||
23 | in chapter 24: | ||
24 | |||
25 | "One goal of the RISC-V project is that it be used as a stable software | ||
26 | development target. For this purpose, we define a combination of a base | ||
27 | ISA (RV32I or RV64I) plus selected standard extensions (IMAFD, Zicsr, | ||
28 | Zifencei) as a 'general-purpose' ISA, and we use the abbreviation G for | ||
29 | the IMAFDZicsr Zifencei combination of instruction-set extensions." | ||
30 | |||
31 | With this in mind, enabling IMAFD_Zicsr_Zifencei if the user explicitly | ||
32 | enables 'G' is an expected behavior and the warning is unneeded. Any | ||
33 | user caught by surprise should refer to the ISA. | ||
34 | |||
35 | Remove the warning when handling RVG. | ||
36 | |||
37 | [1] https://github.com/riscv/riscv-isa-manual/releases/download/Ratified-IMAFDQC/riscv-spec-20191213.pdf | ||
38 | |||
39 | Reported-by: Paul A. Clarke <pclarke@ventanamicro.com> | ||
40 | Suggested-by: Andrew Jones <ajones@ventanamicro.com> | ||
41 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
42 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
43 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> | ||
44 | Message-ID: <20231003122539.775932-1-dbarboza@ventanamicro.com> | ||
45 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
46 | --- | ||
47 | target/riscv/tcg/tcg-cpu.c | 1 - | ||
48 | 1 file changed, 1 deletion(-) | ||
49 | |||
50 | diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c | ||
51 | index XXXXXXX..XXXXXXX 100644 | ||
52 | --- a/target/riscv/tcg/tcg-cpu.c | ||
53 | +++ b/target/riscv/tcg/tcg-cpu.c | ||
54 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp) | ||
55 | return; | ||
56 | } | ||
57 | |||
58 | - warn_report("Setting G will also set IMAFD_Zicsr_Zifencei"); | ||
59 | cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_icsr), true); | ||
60 | cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_ifencei), true); | ||
61 | |||
62 | -- | ||
63 | 2.41.0 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: "Richard W.M. Jones" <rjones@redhat.com> | ||
1 | 2 | ||
3 | RISCV_CPU(cs) uses a checked cast. When QOM cast debugging is enabled | ||
4 | this adds about 5% total overhead when emulating RV64 on x86-64 host. | ||
5 | |||
6 | Using a RISC-V guest with 16 vCPUs, 16 GB of guest RAM, virtio-blk | ||
7 | disk. The guest has a copy of the qemu source tree. The test | ||
8 | involves compiling the qemu source tree with 'make clean; time make -j16'. | ||
9 | |||
10 | Before making this change the compile step took 449 & 447 seconds over | ||
11 | two consecutive runs. | ||
12 | |||
13 | After making this change: 428 & 421 seconds. | ||
14 | |||
15 | The saving is over 5%. | ||
16 | |||
17 | Thanks: Paolo Bonzini | ||
18 | Thanks: Philippe Mathieu-Daudé | ||
19 | Signed-off-by: Richard W.M. Jones <rjones@redhat.com> | ||
20 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
21 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | ||
22 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
23 | Message-ID: <20231009124859.3373696-2-rjones@redhat.com> | ||
24 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
25 | --- | ||
26 | target/riscv/cpu_helper.c | 3 +-- | ||
27 | 1 file changed, 1 insertion(+), 2 deletions(-) | ||
28 | |||
29 | diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c | ||
30 | index XXXXXXX..XXXXXXX 100644 | ||
31 | --- a/target/riscv/cpu_helper.c | ||
32 | +++ b/target/riscv/cpu_helper.c | ||
33 | @@ -XXX,XX +XXX,XX @@ int riscv_cpu_mmu_index(CPURISCVState *env, bool ifetch) | ||
34 | void cpu_get_tb_cpu_state(CPURISCVState *env, vaddr *pc, | ||
35 | uint64_t *cs_base, uint32_t *pflags) | ||
36 | { | ||
37 | - CPUState *cs = env_cpu(env); | ||
38 | - RISCVCPU *cpu = RISCV_CPU(cs); | ||
39 | + RISCVCPU *cpu = env_archcpu(env); | ||
40 | RISCVExtStatus fs, vs; | ||
41 | uint32_t flags = 0; | ||
42 | |||
43 | -- | ||
44 | 2.41.0 | ||
45 | |||
46 | diff view generated by jsdifflib |
1 | From: Weiwei Li <liweiwei@iscas.ac.cn> | 1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
---|---|---|---|
2 | 2 | ||
3 | Co-authored-by: Ruibo Lu <luruibo2000@163.com> | 3 | At this moment there are eleven CPU extension properties that starts |
4 | Co-authored-by: Zewen Ye <lustrew@foxmail.com> | 4 | with capital 'Z': Zifencei, Zicsr, Zihintntl, Zihintpause, Zawrs, Zfa, |
5 | Signed-off-by: Weiwei Li <liweiwei@iscas.ac.cn> | 5 | Zfh, Zfhmin, Zve32f, Zve64f and Zve64d. All other extensions are named |
6 | Signed-off-by: Junqiang Wang <wangjunqiang@iscas.ac.cn> | 6 | with lower-case letters. |
7 | |||
8 | We want all properties to be named with lower-case letters since it's | ||
9 | consistent with the riscv-isa string that we create in the FDT. Having | ||
10 | these 11 properties to be exceptions can be confusing. | ||
11 | |||
12 | Deprecate all of them. Create their lower-case counterpart to be used as | ||
13 | maintained CPU properties. When trying to use any deprecated property a | ||
14 | warning message will be displayed, recommending users to switch to the | ||
15 | lower-case variant: | ||
16 | |||
17 | ./build/qemu-system-riscv64 -M virt -cpu rv64,Zifencei=true --nographic | ||
18 | qemu-system-riscv64: warning: CPU property 'Zifencei' is deprecated. Please use 'zifencei' instead | ||
19 | |||
20 | This will give users some time to change their scripts before we remove | ||
21 | the capital 'Z' properties entirely. | ||
22 | |||
23 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
7 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 24 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
8 | Message-Id: <20220423023510.30794-14-liweiwei@iscas.ac.cn> | 25 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> |
26 | Message-ID: <20231009112817.8896-2-dbarboza@ventanamicro.com> | ||
9 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 27 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
10 | --- | 28 | --- |
11 | disas/riscv.c | 173 +++++++++++++++++++++++++++++++++++++++++++++++++- | 29 | docs/about/deprecated.rst | 23 ++++++++++++++++++++++ |
12 | 1 file changed, 172 insertions(+), 1 deletion(-) | 30 | target/riscv/cpu.h | 1 + |
13 | 31 | target/riscv/cpu.c | 39 +++++++++++++++++++++++++++----------- | |
14 | diff --git a/disas/riscv.c b/disas/riscv.c | 32 | target/riscv/tcg/tcg-cpu.c | 31 +++++++++++++++++++++++++++++- |
15 | index XXXXXXX..XXXXXXX 100644 | 33 | 4 files changed, 82 insertions(+), 12 deletions(-) |
16 | --- a/disas/riscv.c | 34 | |
17 | +++ b/disas/riscv.c | 35 | diff --git a/docs/about/deprecated.rst b/docs/about/deprecated.rst |
18 | @@ -XXX,XX +XXX,XX @@ typedef enum { | 36 | index XXXXXXX..XXXXXXX 100644 |
19 | rv_codec_css_swsp, | 37 | --- a/docs/about/deprecated.rst |
20 | rv_codec_css_sdsp, | 38 | +++ b/docs/about/deprecated.rst |
21 | rv_codec_css_sqsp, | 39 | @@ -XXX,XX +XXX,XX @@ of generic CPUs: rv32 and rv64 as default CPUs and 'max' as a feature complete |
22 | + rv_codec_k_bs, | 40 | CPU for both 32 and 64 bit builds. Users are then discouraged to use the 'any' |
23 | + rv_codec_k_rnum, | 41 | CPU type starting in 8.2. |
24 | } rv_codec; | 42 | |
25 | 43 | +RISC-V CPU properties which start with capital 'Z' (since 8.2) | |
26 | typedef enum { | 44 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
27 | @@ -XXX,XX +XXX,XX @@ typedef enum { | 45 | + |
28 | rv_op_bclr = 359, | 46 | +All RISC-V CPU properties which start with capital 'Z' are being deprecated |
29 | rv_op_binv = 360, | 47 | +starting in 8.2. The reason is that they were wrongly added with capital 'Z' |
30 | rv_op_bext = 361, | 48 | +in the past. CPU properties were later added with lower-case names, which |
31 | + rv_op_aes32esmi = 362, | 49 | +is the format we want to use from now on. |
32 | + rv_op_aes32esi = 363, | 50 | + |
33 | + rv_op_aes32dsmi = 364, | 51 | +Users which try to use these deprecated properties will receive a warning |
34 | + rv_op_aes32dsi = 365, | 52 | +recommending to switch to their stable counterparts: |
35 | + rv_op_aes64ks1i = 366, | 53 | + |
36 | + rv_op_aes64ks2 = 367, | 54 | +- "Zifencei" should be replaced with "zifencei" |
37 | + rv_op_aes64im = 368, | 55 | +- "Zicsr" should be replaced with "zicsr" |
38 | + rv_op_aes64esm = 369, | 56 | +- "Zihintntl" should be replaced with "zihintntl" |
39 | + rv_op_aes64es = 370, | 57 | +- "Zihintpause" should be replaced with "zihintpause" |
40 | + rv_op_aes64dsm = 371, | 58 | +- "Zawrs" should be replaced with "zawrs" |
41 | + rv_op_aes64ds = 372, | 59 | +- "Zfa" should be replaced with "zfa" |
42 | + rv_op_sha256sig0 = 373, | 60 | +- "Zfh" should be replaced with "zfh" |
43 | + rv_op_sha256sig1 = 374, | 61 | +- "Zfhmin" should be replaced with "zfhmin" |
44 | + rv_op_sha256sum0 = 375, | 62 | +- "Zve32f" should be replaced with "zve32f" |
45 | + rv_op_sha256sum1 = 376, | 63 | +- "Zve64f" should be replaced with "zve64f" |
46 | + rv_op_sha512sig0 = 377, | 64 | +- "Zve64d" should be replaced with "zve64d" |
47 | + rv_op_sha512sig1 = 378, | 65 | + |
48 | + rv_op_sha512sum0 = 379, | 66 | Block device options |
49 | + rv_op_sha512sum1 = 380, | 67 | '''''''''''''''''''' |
50 | + rv_op_sha512sum0r = 381, | 68 | |
51 | + rv_op_sha512sum1r = 382, | 69 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h |
52 | + rv_op_sha512sig0l = 383, | 70 | index XXXXXXX..XXXXXXX 100644 |
53 | + rv_op_sha512sig0h = 384, | 71 | --- a/target/riscv/cpu.h |
54 | + rv_op_sha512sig1l = 385, | 72 | +++ b/target/riscv/cpu.h |
55 | + rv_op_sha512sig1h = 386, | 73 | @@ -XXX,XX +XXX,XX @@ typedef struct RISCVCPUMultiExtConfig { |
56 | + rv_op_sm3p0 = 387, | 74 | extern const RISCVCPUMultiExtConfig riscv_cpu_extensions[]; |
57 | + rv_op_sm3p1 = 388, | 75 | extern const RISCVCPUMultiExtConfig riscv_cpu_vendor_exts[]; |
58 | + rv_op_sm4ed = 389, | 76 | extern const RISCVCPUMultiExtConfig riscv_cpu_experimental_exts[]; |
59 | + rv_op_sm4ks = 390, | 77 | +extern const RISCVCPUMultiExtConfig riscv_cpu_deprecated_exts[]; |
60 | + rv_op_brev8 = 391, | 78 | extern Property riscv_cpu_options[]; |
61 | + rv_op_pack = 392, | 79 | |
62 | + rv_op_packh = 393, | 80 | typedef struct isa_ext_data { |
63 | + rv_op_packw = 394, | 81 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c |
64 | + rv_op_unzip = 395, | 82 | index XXXXXXX..XXXXXXX 100644 |
65 | + rv_op_zip = 396, | 83 | --- a/target/riscv/cpu.c |
66 | + rv_op_xperm4 = 397, | 84 | +++ b/target/riscv/cpu.c |
67 | + rv_op_xperm8 = 398, | 85 | @@ -XXX,XX +XXX,XX @@ const char *riscv_get_misa_ext_description(uint32_t bit) |
68 | } rv_op; | 86 | const RISCVCPUMultiExtConfig riscv_cpu_extensions[] = { |
69 | 87 | /* Defaults for standard extensions */ | |
70 | /* structures */ | 88 | MULTI_EXT_CFG_BOOL("sscofpmf", ext_sscofpmf, false), |
71 | @@ -XXX,XX +XXX,XX @@ typedef struct { | 89 | - MULTI_EXT_CFG_BOOL("Zifencei", ext_ifencei, true), |
72 | uint8_t succ; | 90 | - MULTI_EXT_CFG_BOOL("Zicsr", ext_icsr, true), |
73 | uint8_t aq; | 91 | - MULTI_EXT_CFG_BOOL("Zihintntl", ext_zihintntl, true), |
74 | uint8_t rl; | 92 | - MULTI_EXT_CFG_BOOL("Zihintpause", ext_zihintpause, true), |
75 | + uint8_t bs; | 93 | - MULTI_EXT_CFG_BOOL("Zawrs", ext_zawrs, true), |
76 | + uint8_t rnum; | 94 | - MULTI_EXT_CFG_BOOL("Zfa", ext_zfa, true), |
77 | } rv_decode; | 95 | - MULTI_EXT_CFG_BOOL("Zfh", ext_zfh, false), |
78 | 96 | - MULTI_EXT_CFG_BOOL("Zfhmin", ext_zfhmin, false), | |
79 | typedef struct { | 97 | - MULTI_EXT_CFG_BOOL("Zve32f", ext_zve32f, false), |
80 | @@ -XXX,XX +XXX,XX @@ static const char rv_freg_name_sym[32][5] = { | 98 | - MULTI_EXT_CFG_BOOL("Zve64f", ext_zve64f, false), |
81 | #define rv_fmt_rd_rs2 "O\t0,2" | 99 | - MULTI_EXT_CFG_BOOL("Zve64d", ext_zve64d, false), |
82 | #define rv_fmt_rs1_offset "O\t1,o" | 100 | + MULTI_EXT_CFG_BOOL("zifencei", ext_ifencei, true), |
83 | #define rv_fmt_rs2_offset "O\t2,o" | 101 | + MULTI_EXT_CFG_BOOL("zicsr", ext_icsr, true), |
84 | +#define rv_fmt_rs1_rs2_bs "O\t1,2,b" | 102 | + MULTI_EXT_CFG_BOOL("zihintntl", ext_zihintntl, true), |
85 | +#define rv_fmt_rd_rs1_rnum "O\t0,1,n" | 103 | + MULTI_EXT_CFG_BOOL("zihintpause", ext_zihintpause, true), |
86 | 104 | + MULTI_EXT_CFG_BOOL("zawrs", ext_zawrs, true), | |
87 | /* pseudo-instruction constraints */ | 105 | + MULTI_EXT_CFG_BOOL("zfa", ext_zfa, true), |
88 | 106 | + MULTI_EXT_CFG_BOOL("zfh", ext_zfh, false), | |
89 | @@ -XXX,XX +XXX,XX @@ static const rv_comp_data rvcp_csrrw[] = { | 107 | + MULTI_EXT_CFG_BOOL("zfhmin", ext_zfhmin, false), |
90 | { rv_op_illegal, NULL } | 108 | + MULTI_EXT_CFG_BOOL("zve32f", ext_zve32f, false), |
109 | + MULTI_EXT_CFG_BOOL("zve64f", ext_zve64f, false), | ||
110 | + MULTI_EXT_CFG_BOOL("zve64d", ext_zve64d, false), | ||
111 | MULTI_EXT_CFG_BOOL("sstc", ext_sstc, true), | ||
112 | |||
113 | MULTI_EXT_CFG_BOOL("smstateen", ext_smstateen, false), | ||
114 | @@ -XXX,XX +XXX,XX @@ const RISCVCPUMultiExtConfig riscv_cpu_experimental_exts[] = { | ||
115 | DEFINE_PROP_END_OF_LIST(), | ||
91 | }; | 116 | }; |
92 | 117 | ||
93 | + | 118 | +/* Deprecated entries marked for future removal */ |
94 | static const rv_comp_data rvcp_csrrs[] = { | 119 | +const RISCVCPUMultiExtConfig riscv_cpu_deprecated_exts[] = { |
95 | { rv_op_rdcycle, rvcc_rdcycle }, | 120 | + MULTI_EXT_CFG_BOOL("Zifencei", ext_ifencei, true), |
96 | { rv_op_rdtime, rvcc_rdtime }, | 121 | + MULTI_EXT_CFG_BOOL("Zicsr", ext_icsr, true), |
97 | @@ -XXX,XX +XXX,XX @@ const rv_opcode_data opcode_data[] = { | 122 | + MULTI_EXT_CFG_BOOL("Zihintntl", ext_zihintntl, true), |
98 | { "bclr", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, | 123 | + MULTI_EXT_CFG_BOOL("Zihintpause", ext_zihintpause, true), |
99 | { "binv", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, | 124 | + MULTI_EXT_CFG_BOOL("Zawrs", ext_zawrs, true), |
100 | { "bext", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, | 125 | + MULTI_EXT_CFG_BOOL("Zfa", ext_zfa, true), |
101 | + { "aes32esmi", rv_codec_k_bs, rv_fmt_rs1_rs2_bs, NULL, 0, 0, 0 }, | 126 | + MULTI_EXT_CFG_BOOL("Zfh", ext_zfh, false), |
102 | + { "aes32esi", rv_codec_k_bs, rv_fmt_rs1_rs2_bs, NULL, 0, 0, 0 }, | 127 | + MULTI_EXT_CFG_BOOL("Zfhmin", ext_zfhmin, false), |
103 | + { "aes32dsmi", rv_codec_k_bs, rv_fmt_rs1_rs2_bs, NULL, 0, 0, 0 }, | 128 | + MULTI_EXT_CFG_BOOL("Zve32f", ext_zve32f, false), |
104 | + { "aes32dsi", rv_codec_k_bs, rv_fmt_rs1_rs2_bs, NULL, 0, 0, 0 }, | 129 | + MULTI_EXT_CFG_BOOL("Zve64f", ext_zve64f, false), |
105 | + { "aes64ks1i", rv_codec_k_rnum, rv_fmt_rd_rs1_rnum, NULL, 0, 0, 0 }, | 130 | + MULTI_EXT_CFG_BOOL("Zve64d", ext_zve64d, false), |
106 | + { "aes64ks2", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, | 131 | + |
107 | + { "aes64im", rv_codec_r, rv_fmt_rd_rs1, NULL, 0, 0 }, | 132 | + DEFINE_PROP_END_OF_LIST(), |
108 | + { "aes64esm", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, | 133 | +}; |
109 | + { "aes64es", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, | 134 | + |
110 | + { "aes64dsm", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, | 135 | Property riscv_cpu_options[] = { |
111 | + { "aes64ds", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, | 136 | DEFINE_PROP_UINT8("pmu-num", RISCVCPU, cfg.pmu_num, 16), |
112 | + { "sha256sig0", rv_codec_r, rv_fmt_rd_rs1, NULL, 0, 0 }, | 137 | |
113 | + { "sha256sig1", rv_codec_r, rv_fmt_rd_rs1, NULL, 0, 0 }, | 138 | diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c |
114 | + { "sha256sum0", rv_codec_r, rv_fmt_rd_rs1, NULL, 0, 0 }, | 139 | index XXXXXXX..XXXXXXX 100644 |
115 | + { "sha256sum1", rv_codec_r, rv_fmt_rd_rs1, NULL, 0, 0 }, | 140 | --- a/target/riscv/tcg/tcg-cpu.c |
116 | + { "sha512sig0", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, | 141 | +++ b/target/riscv/tcg/tcg-cpu.c |
117 | + { "sha512sig1", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, | 142 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_add_misa_properties(Object *cpu_obj) |
118 | + { "sha512sum0", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, | 143 | } |
119 | + { "sha512sum1", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, | ||
120 | + { "sha512sum0r", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, | ||
121 | + { "sha512sum1r", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, | ||
122 | + { "sha512sig0l", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, | ||
123 | + { "sha512sig0h", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, | ||
124 | + { "sha512sig1l", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, | ||
125 | + { "sha512sig1h", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, | ||
126 | + { "sm3p0", rv_codec_r, rv_fmt_rd_rs1, NULL, 0, 0 }, | ||
127 | + { "sm3p1", rv_codec_r, rv_fmt_rd_rs1, NULL, 0, 0 }, | ||
128 | + { "sm4ed", rv_codec_k_bs, rv_fmt_rs1_rs2_bs, NULL, 0, 0, 0 }, | ||
129 | + { "sm4ks", rv_codec_k_bs, rv_fmt_rs1_rs2_bs, NULL, 0, 0, 0 }, | ||
130 | + { "brev8", rv_codec_r, rv_fmt_rd_rs1, NULL, 0, 0, 0 }, | ||
131 | + { "pack", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, | ||
132 | + { "packh", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, | ||
133 | + { "packw", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, | ||
134 | + { "unzip", rv_codec_r, rv_fmt_rd_rs1, NULL, 0, 0, 0 }, | ||
135 | + { "zip", rv_codec_r, rv_fmt_rd_rs1, NULL, 0, 0, 0 }, | ||
136 | + { "xperm4", rv_codec_r, rv_fmt_rd_rs1_rs2, NULL, 0, 0, 0 }, | ||
137 | + { "xperm8", rv_codec_r, rv_fmt_rd_rs1, NULL, 0, 0, 0 } | ||
138 | }; | ||
139 | |||
140 | /* CSR names */ | ||
141 | @@ -XXX,XX +XXX,XX @@ static const char *csr_name(int csrno) | ||
142 | case 0x0003: return "fcsr"; | ||
143 | case 0x0004: return "uie"; | ||
144 | case 0x0005: return "utvec"; | ||
145 | + case 0x0015: return "seed"; | ||
146 | case 0x0040: return "uscratch"; | ||
147 | case 0x0041: return "uepc"; | ||
148 | case 0x0042: return "ucause"; | ||
149 | @@ -XXX,XX +XXX,XX @@ static void decode_inst_opcode(rv_decode *dec, rv_isa isa) | ||
150 | case 1: | ||
151 | switch (((inst >> 27) & 0b11111)) { | ||
152 | case 0b00000: op = rv_op_slli; break; | ||
153 | + case 0b00001: | ||
154 | + switch (((inst >> 20) & 0b1111111)) { | ||
155 | + case 0b0001111: op = rv_op_zip; break; | ||
156 | + } | ||
157 | + break; | ||
158 | + case 0b00010: | ||
159 | + switch (((inst >> 20) & 0b1111111)) { | ||
160 | + case 0b0000000: op = rv_op_sha256sum0; break; | ||
161 | + case 0b0000001: op = rv_op_sha256sum1; break; | ||
162 | + case 0b0000010: op = rv_op_sha256sig0; break; | ||
163 | + case 0b0000011: op = rv_op_sha256sig1; break; | ||
164 | + case 0b0000100: op = rv_op_sha512sum0; break; | ||
165 | + case 0b0000101: op = rv_op_sha512sum1; break; | ||
166 | + case 0b0000110: op = rv_op_sha512sig0; break; | ||
167 | + case 0b0000111: op = rv_op_sha512sig1; break; | ||
168 | + case 0b0001000: op = rv_op_sm3p0; break; | ||
169 | + case 0b0001001: op = rv_op_sm3p1; break; | ||
170 | + } | ||
171 | + break; | ||
172 | case 0b00101: op = rv_op_bseti; break; | ||
173 | + case 0b00110: | ||
174 | + switch (((inst >> 20) & 0b1111111)) { | ||
175 | + case 0b0000000: op = rv_op_aes64im; break; | ||
176 | + default: | ||
177 | + if (((inst >> 24) & 0b0111) == 0b001) { | ||
178 | + op = rv_op_aes64ks1i; | ||
179 | + } | ||
180 | + break; | ||
181 | + } | ||
182 | + break; | ||
183 | case 0b01001: op = rv_op_bclri; break; | ||
184 | case 0b01101: op = rv_op_binvi; break; | ||
185 | case 0b01100: | ||
186 | @@ -XXX,XX +XXX,XX @@ static void decode_inst_opcode(rv_decode *dec, rv_isa isa) | ||
187 | case 5: | ||
188 | switch (((inst >> 27) & 0b11111)) { | ||
189 | case 0b00000: op = rv_op_srli; break; | ||
190 | + case 0b00001: | ||
191 | + switch (((inst >> 20) & 0b1111111)) { | ||
192 | + case 0b0001111: op = rv_op_unzip; break; | ||
193 | + } | ||
194 | + break; | ||
195 | case 0b00101: op = rv_op_orc_b; break; | ||
196 | case 0b01000: op = rv_op_srai; break; | ||
197 | case 0b01001: op = rv_op_bexti; break; | ||
198 | case 0b01100: op = rv_op_rori; break; | ||
199 | case 0b01101: | ||
200 | switch ((inst >> 20) & 0b1111111) { | ||
201 | + case 0b0011000: op = rv_op_rev8; break; | ||
202 | case 0b0111000: op = rv_op_rev8; break; | ||
203 | + case 0b0000111: op = rv_op_brev8; break; | ||
204 | } | ||
205 | break; | ||
206 | } | ||
207 | @@ -XXX,XX +XXX,XX @@ static void decode_inst_opcode(rv_decode *dec, rv_isa isa) | ||
208 | case 36: | ||
209 | switch ((inst >> 20) & 0b11111) { | ||
210 | case 0: op = rv_op_zext_h; break; | ||
211 | + default: op = rv_op_pack; break; | ||
212 | } | ||
213 | break; | ||
214 | + case 39: op = rv_op_packh; break; | ||
215 | + | ||
216 | case 41: op = rv_op_clmul; break; | ||
217 | case 42: op = rv_op_clmulr; break; | ||
218 | case 43: op = rv_op_clmulh; break; | ||
219 | @@ -XXX,XX +XXX,XX @@ static void decode_inst_opcode(rv_decode *dec, rv_isa isa) | ||
220 | case 132: op = rv_op_sh2add; break; | ||
221 | case 134: op = rv_op_sh3add; break; | ||
222 | case 161: op = rv_op_bset; break; | ||
223 | + case 162: op = rv_op_xperm4; break; | ||
224 | + case 164: op = rv_op_xperm8; break; | ||
225 | + case 200: op = rv_op_aes64es; break; | ||
226 | + case 216: op = rv_op_aes64esm; break; | ||
227 | + case 232: op = rv_op_aes64ds; break; | ||
228 | + case 248: op = rv_op_aes64dsm; break; | ||
229 | case 256: op = rv_op_sub; break; | ||
230 | case 260: op = rv_op_xnor; break; | ||
231 | case 261: op = rv_op_sra; break; | ||
232 | @@ -XXX,XX +XXX,XX @@ static void decode_inst_opcode(rv_decode *dec, rv_isa isa) | ||
233 | case 263: op = rv_op_andn; break; | ||
234 | case 289: op = rv_op_bclr; break; | ||
235 | case 293: op = rv_op_bext; break; | ||
236 | + case 320: op = rv_op_sha512sum0r; break; | ||
237 | + case 328: op = rv_op_sha512sum1r; break; | ||
238 | + case 336: op = rv_op_sha512sig0l; break; | ||
239 | + case 344: op = rv_op_sha512sig1l; break; | ||
240 | + case 368: op = rv_op_sha512sig0h; break; | ||
241 | + case 376: op = rv_op_sha512sig1h; break; | ||
242 | case 385: op = rv_op_rol; break; | ||
243 | - case 386: op = rv_op_ror; break; | ||
244 | + case 389: op = rv_op_ror; break; | ||
245 | case 417: op = rv_op_binv; break; | ||
246 | + case 504: op = rv_op_aes64ks2; break; | ||
247 | + } | ||
248 | + switch ((inst >> 25) & 0b0011111) { | ||
249 | + case 17: op = rv_op_aes32esi; break; | ||
250 | + case 19: op = rv_op_aes32esmi; break; | ||
251 | + case 21: op = rv_op_aes32dsi; break; | ||
252 | + case 23: op = rv_op_aes32dsmi; break; | ||
253 | + case 24: op = rv_op_sm4ed; break; | ||
254 | + case 26: op = rv_op_sm4ks; break; | ||
255 | } | ||
256 | break; | ||
257 | case 13: op = rv_op_lui; break; | ||
258 | @@ -XXX,XX +XXX,XX @@ static void decode_inst_opcode(rv_decode *dec, rv_isa isa) | ||
259 | case 36: | ||
260 | switch ((inst >> 20) & 0b11111) { | ||
261 | case 0: op = rv_op_zext_h; break; | ||
262 | + default: op = rv_op_packw; break; | ||
263 | } | ||
264 | break; | ||
265 | case 130: op = rv_op_sh1add_uw; break; | ||
266 | @@ -XXX,XX +XXX,XX @@ static uint32_t operand_cimmq(rv_inst inst) | ||
267 | ((inst << 57) >> 62) << 6; | ||
268 | } | 144 | } |
269 | 145 | ||
270 | +static uint32_t operand_bs(rv_inst inst) | 146 | +static bool cpu_ext_is_deprecated(const char *ext_name) |
271 | +{ | 147 | +{ |
272 | + return (inst << 32) >> 62; | 148 | + return isupper(ext_name[0]); |
273 | +} | 149 | +} |
274 | + | 150 | + |
275 | +static uint32_t operand_rnum(rv_inst inst) | 151 | +/* |
152 | + * String will be allocated in the heap. Caller is responsible | ||
153 | + * for freeing it. | ||
154 | + */ | ||
155 | +static char *cpu_ext_to_lower(const char *ext_name) | ||
276 | +{ | 156 | +{ |
277 | + return (inst << 40) >> 60; | 157 | + char *ret = g_malloc0(strlen(ext_name) + 1); |
158 | + | ||
159 | + strcpy(ret, ext_name); | ||
160 | + ret[0] = tolower(ret[0]); | ||
161 | + | ||
162 | + return ret; | ||
278 | +} | 163 | +} |
279 | + | 164 | + |
280 | /* decode operands */ | 165 | static void cpu_set_multi_ext_cfg(Object *obj, Visitor *v, const char *name, |
281 | 166 | void *opaque, Error **errp) | |
282 | static void decode_inst_operands(rv_decode *dec) | 167 | { |
283 | @@ -XXX,XX +XXX,XX @@ static void decode_inst_operands(rv_decode *dec) | 168 | @@ -XXX,XX +XXX,XX @@ static void cpu_set_multi_ext_cfg(Object *obj, Visitor *v, const char *name, |
284 | dec->rs2 = operand_crs2(inst); | 169 | return; |
285 | dec->imm = operand_cimmsqsp(inst); | 170 | } |
286 | break; | 171 | |
287 | + case rv_codec_k_bs: | 172 | + if (cpu_ext_is_deprecated(multi_ext_cfg->name)) { |
288 | + dec->rs1 = operand_rs1(inst); | 173 | + g_autofree char *lower = cpu_ext_to_lower(multi_ext_cfg->name); |
289 | + dec->rs2 = operand_rs2(inst); | 174 | + |
290 | + dec->bs = operand_bs(inst); | 175 | + warn_report("CPU property '%s' is deprecated. Please use '%s' instead", |
291 | + break; | 176 | + multi_ext_cfg->name, lower); |
292 | + case rv_codec_k_rnum: | 177 | + } |
293 | + dec->rd = operand_rd(inst); | 178 | + |
294 | + dec->rs1 = operand_rs1(inst); | 179 | g_hash_table_insert(multi_ext_user_opts, |
295 | + dec->rnum = operand_rnum(inst); | 180 | GUINT_TO_POINTER(multi_ext_cfg->offset), |
296 | + break; | 181 | (gpointer)value); |
297 | }; | 182 | @@ -XXX,XX +XXX,XX @@ static void cpu_add_multi_ext_prop(Object *cpu_obj, |
298 | } | 183 | const RISCVCPUMultiExtConfig *multi_cfg) |
299 | 184 | { | |
300 | @@ -XXX,XX +XXX,XX @@ static void format_inst(char *buf, size_t buflen, size_t tab, rv_decode *dec) | 185 | bool generic_cpu = riscv_cpu_is_generic(cpu_obj); |
301 | case ')': | 186 | + bool deprecated_ext = cpu_ext_is_deprecated(multi_cfg->name); |
302 | append(buf, ")", buflen); | 187 | |
303 | break; | 188 | object_property_add(cpu_obj, multi_cfg->name, "bool", |
304 | + case 'b': | 189 | cpu_get_multi_ext_cfg, |
305 | + snprintf(tmp, sizeof(tmp), "%d", dec->bs); | 190 | cpu_set_multi_ext_cfg, |
306 | + append(buf, tmp, buflen); | 191 | NULL, (void *)multi_cfg); |
307 | + break; | 192 | |
308 | + case 'n': | 193 | - if (!generic_cpu) { |
309 | + snprintf(tmp, sizeof(tmp), "%d", dec->rnum); | 194 | + if (!generic_cpu || deprecated_ext) { |
310 | + append(buf, tmp, buflen); | 195 | return; |
311 | + break; | 196 | } |
312 | case '0': | 197 | |
313 | append(buf, rv_ireg_name_sym[dec->rd], buflen); | 198 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_add_user_properties(Object *obj) |
314 | break; | 199 | riscv_cpu_add_multiext_prop_array(obj, riscv_cpu_vendor_exts); |
200 | riscv_cpu_add_multiext_prop_array(obj, riscv_cpu_experimental_exts); | ||
201 | |||
202 | + riscv_cpu_add_multiext_prop_array(obj, riscv_cpu_deprecated_exts); | ||
203 | + | ||
204 | for (Property *prop = riscv_cpu_options; prop && prop->name; prop++) { | ||
205 | qdev_property_add_static(DEVICE(obj), prop); | ||
206 | } | ||
315 | -- | 207 | -- |
316 | 2.35.1 | 208 | 2.41.0 | diff view generated by jsdifflib |
1 | From: Alistair Francis <alistair.francis@wdc.com> | 1 | From: Max Chou <max.chou@sifive.com> |
---|---|---|---|
2 | 2 | ||
3 | Imply the TPM sysbus devices. This allows users to add TPM devices to | 3 | The operator (fwmacc16) of vfwmaccbf16.vf helper function should be |
4 | the RISC-V virt board. | 4 | replaced by fwmaccbf16. |
5 | 5 | ||
6 | This was tested by first creating an emulated TPM device: | 6 | Fixes: adf772b0f7 ("target/riscv: Add support for Zvfbfwma extension") |
7 | 7 | Signed-off-by: Max Chou <max.chou@sifive.com> | |
8 | swtpm socket --tpm2 -t -d --tpmstate dir=/tmp/tpm \ | 8 | Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com> |
9 | --ctrl type=unixio,path=swtpm-sock | 9 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> |
10 | 10 | Message-ID: <20231005095734.567575-1-max.chou@sifive.com> | |
11 | Then launching QEMU with: | ||
12 | |||
13 | -chardev socket,id=chrtpm,path=swtpm-sock \ | ||
14 | -tpmdev emulator,id=tpm0,chardev=chrtpm \ | ||
15 | -device tpm-tis-device,tpmdev=tpm0 | ||
16 | |||
17 | The TPM device can be seen in the memory tree and the generated device | ||
18 | tree. | ||
19 | |||
20 | Resolves: https://gitlab.com/qemu-project/qemu/-/issues/942 | ||
21 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
22 | Reviewed-by: Edgar E. Iglesias <edgar.iglesias@amd.com> | ||
23 | Reviewed-by: Bin Meng <bmeng.cn@gmail.com> | ||
24 | Message-Id: <20220427234146.1130752-7-alistair.francis@opensource.wdc.com> | ||
25 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 11 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
26 | --- | 12 | --- |
27 | docs/system/riscv/virt.rst | 20 ++++++++++++++++++++ | 13 | target/riscv/vector_helper.c | 2 +- |
28 | hw/riscv/virt.c | 4 ++++ | 14 | 1 file changed, 1 insertion(+), 1 deletion(-) |
29 | hw/riscv/Kconfig | 1 + | ||
30 | 3 files changed, 25 insertions(+) | ||
31 | 15 | ||
32 | diff --git a/docs/system/riscv/virt.rst b/docs/system/riscv/virt.rst | 16 | diff --git a/target/riscv/vector_helper.c b/target/riscv/vector_helper.c |
33 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
34 | --- a/docs/system/riscv/virt.rst | 18 | --- a/target/riscv/vector_helper.c |
35 | +++ b/docs/system/riscv/virt.rst | 19 | +++ b/target/riscv/vector_helper.c |
36 | @@ -XXX,XX +XXX,XX @@ The minimal QEMU commands to run U-Boot SPL are: | 20 | @@ -XXX,XX +XXX,XX @@ static uint32_t fwmaccbf16(uint16_t a, uint16_t b, uint32_t d, float_status *s) |
37 | To test 32-bit U-Boot images, switch to use qemu-riscv32_smode_defconfig and | 21 | |
38 | riscv32_spl_defconfig builds, and replace ``qemu-system-riscv64`` with | 22 | RVVCALL(OPFVV3, vfwmaccbf16_vv, WOP_UUU_H, H4, H2, H2, fwmaccbf16) |
39 | ``qemu-system-riscv32`` in the command lines above to boot the 32-bit U-Boot. | 23 | GEN_VEXT_VV_ENV(vfwmaccbf16_vv, 4) |
40 | + | 24 | -RVVCALL(OPFVF3, vfwmaccbf16_vf, WOP_UUU_H, H4, H2, fwmacc16) |
41 | +Enabling TPM | 25 | +RVVCALL(OPFVF3, vfwmaccbf16_vf, WOP_UUU_H, H4, H2, fwmaccbf16) |
42 | +------------ | 26 | GEN_VEXT_VF(vfwmaccbf16_vf, 4) |
43 | + | 27 | |
44 | +A TPM device can be connected to the virt board by following the steps below. | 28 | static uint32_t fwnmacc16(uint16_t a, uint16_t b, uint32_t d, float_status *s) |
45 | + | ||
46 | +First launch the TPM emulator | ||
47 | + | ||
48 | + swtpm socket --tpm2 -t -d --tpmstate dir=/tmp/tpm \ | ||
49 | + --ctrl type=unixio,path=swtpm-sock | ||
50 | + | ||
51 | +Then launch QEMU with: | ||
52 | + | ||
53 | + ... | ||
54 | + -chardev socket,id=chrtpm,path=swtpm-sock \ | ||
55 | + -tpmdev emulator,id=tpm0,chardev=chrtpm \ | ||
56 | + -device tpm-tis-device,tpmdev=tpm0 | ||
57 | + | ||
58 | +The TPM device can be seen in the memory tree and the generated device | ||
59 | +tree and should be accessible from the guest software. | ||
60 | diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c | ||
61 | index XXXXXXX..XXXXXXX 100644 | ||
62 | --- a/hw/riscv/virt.c | ||
63 | +++ b/hw/riscv/virt.c | ||
64 | @@ -XXX,XX +XXX,XX @@ | ||
65 | #include "sysemu/device_tree.h" | ||
66 | #include "sysemu/sysemu.h" | ||
67 | #include "sysemu/kvm.h" | ||
68 | +#include "sysemu/tpm.h" | ||
69 | #include "hw/pci/pci.h" | ||
70 | #include "hw/pci-host/gpex.h" | ||
71 | #include "hw/display/ramfb.h" | ||
72 | @@ -XXX,XX +XXX,XX @@ static void virt_machine_class_init(ObjectClass *oc, void *data) | ||
73 | hc->plug = virt_machine_device_plug_cb; | ||
74 | |||
75 | machine_class_allow_dynamic_sysbus_dev(mc, TYPE_RAMFB_DEVICE); | ||
76 | +#ifdef CONFIG_TPM | ||
77 | + machine_class_allow_dynamic_sysbus_dev(mc, TYPE_TPM_TIS_SYSBUS); | ||
78 | +#endif | ||
79 | |||
80 | object_class_property_add_bool(oc, "aclint", virt_get_aclint, | ||
81 | virt_set_aclint); | ||
82 | diff --git a/hw/riscv/Kconfig b/hw/riscv/Kconfig | ||
83 | index XXXXXXX..XXXXXXX 100644 | ||
84 | --- a/hw/riscv/Kconfig | ||
85 | +++ b/hw/riscv/Kconfig | ||
86 | @@ -XXX,XX +XXX,XX @@ config RISCV_VIRT | ||
87 | imply PCI_DEVICES | ||
88 | imply VIRTIO_VGA | ||
89 | imply TEST_DEVICES | ||
90 | + imply TPM_TIS_SYSBUS | ||
91 | select RISCV_NUMA | ||
92 | select GOLDFISH_RTC | ||
93 | select MSI_NONBROKEN | ||
94 | -- | 29 | -- |
95 | 2.35.1 | 30 | 2.41.0 |
31 | |||
32 | diff view generated by jsdifflib |