1 | The following changes since commit a51e5124a655b3dad80b36b18547cb1eca2c5eb2: | 1 | The following changes since commit ad10b4badc1dd5b28305f9b9f1168cf0aa3ae946: |
---|---|---|---|
2 | 2 | ||
3 | Merge tag 'pull-omnibus-111023-1' of https://gitlab.com/stsquad/qemu into staging (2023-10-11 09:43:10 -0400) | 3 | Merge tag 'pull-error-2024-05-27' of https://repo.or.cz/qemu/armbru into staging (2024-05-27 06:40:42 -0700) |
4 | 4 | ||
5 | are available in the Git repository at: | 5 | are available in the Git repository at: |
6 | 6 | ||
7 | https://github.com/alistair23/qemu.git tags/pull-riscv-to-apply-20231012-1 | 7 | https://github.com/alistair23/qemu.git tags/pull-riscv-to-apply-20240528 |
8 | 8 | ||
9 | for you to fetch changes up to 837570cef237b634eb4c245363470deebea7089d: | 9 | for you to fetch changes up to 1806da76cb81088ea026ca3441551782b850e393: |
10 | 10 | ||
11 | target/riscv: Fix vfwmaccbf16.vf (2023-10-12 12:50:13 +1000) | 11 | target/riscv: raise an exception when CSRRS/CSRRC writes a read-only CSR (2024-05-28 12:20:27 +1000) |
12 | 12 | ||
13 | ---------------------------------------------------------------- | 13 | ---------------------------------------------------------------- |
14 | Second RISC-V PR for 8.2 | 14 | RISC-V PR for 9.1 |
15 | 15 | ||
16 | * Add support for the max CPU | 16 | * APLICs add child earlier than realize |
17 | * Detect user choice in TCG | 17 | * Fix exposure of Zkr |
18 | * Clear CSR values at reset and sync MPSTATE with host | 18 | * Raise exceptions on wrs.nto |
19 | * Fix the typo of inverted order of pmpaddr13 and pmpaddr14 | 19 | * Implement SBI debug console (DBCN) calls for KVM |
20 | * Split TCG/KVM accelerators from cpu.c | 20 | * Support 64-bit addresses for initrd |
21 | * Add extension properties for all cpus | 21 | * Change RISCV_EXCP_SEMIHOST exception number to 63 |
22 | * Replace GDB exit calls with proper shutdown | 22 | * Tolerate KVM disable ext errors |
23 | * Support KVM_GET_REG_LIST | 23 | * Set tval in breakpoints |
24 | * Remove RVG warning | 24 | * Add support for Zve32x extension |
25 | * Use env_archcpu for better performance | 25 | * Add support for Zve64x extension |
26 | * Deprecate capital 'Z' CPU properties | 26 | * Relax vector register check in RISCV gdbstub |
27 | * Fix vfwmaccbf16.vf | 27 | * Fix the element agnostic Vector function problem |
28 | * Fix Zvkb extension config | ||
29 | * Implement dynamic establishment of custom decoder | ||
30 | * Add th.sxstatus CSR emulation | ||
31 | * Fix Zvfhmin checking for vfwcvt.f.f.v and vfncvt.f.f.w instructions | ||
32 | * Check single width operator for vector fp widen instructions | ||
33 | * Check single width operator for vfncvt.rod.f.f.w | ||
34 | * Remove redudant SEW checking for vector fp narrow/widen instructions | ||
35 | * Prioritize pmp errors in raise_mmu_exception() | ||
36 | * Do not set mtval2 for non guest-page faults | ||
37 | * Remove experimental prefix from "B" extension | ||
38 | * Fixup CBO extension register calculation | ||
39 | * Fix the hart bit setting of AIA | ||
40 | * Fix reg_width in ricsv_gen_dynamic_vector_feature() | ||
41 | * Decode all of the pmpcfg and pmpaddr CSRs | ||
42 | * Raise an exception when CSRRS/CSRRC writes a read-only CSR | ||
28 | 43 | ||
29 | ---------------------------------------------------------------- | 44 | ---------------------------------------------------------------- |
30 | Alvin Chang (1): | 45 | Alexei Filippov (1): |
31 | disas/riscv: Fix the typo of inverted order of pmpaddr13 and pmpaddr14 | 46 | target/riscv: do not set mtval2 for non guest-page faults |
32 | 47 | ||
33 | Clément Chigot (5): | 48 | Alistair Francis (2): |
34 | softmmu: add means to pass an exit code when requesting a shutdown | 49 | target/riscv: rvzicbo: Fixup CBO extension register calculation |
35 | softmmu: pass the main loop status to gdb "Wxx" packet | 50 | disas/riscv: Decode all of the pmpcfg and pmpaddr CSRs |
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 | ||
39 | 51 | ||
40 | Daniel Henrique Barboza (45): | 52 | Andrew Jones (2): |
41 | target/riscv/cpu.c: split CPU options from riscv_cpu_extensions[] | 53 | target/riscv/kvm: Fix exposure of Zkr |
42 | target/riscv/cpu.c: skip 'bool' check when filtering KVM props | 54 | target/riscv: Raise exceptions on wrs.nto |
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 | ||
86 | 55 | ||
87 | Max Chou (1): | 56 | Cheng Yang (1): |
88 | target/riscv: Fix vfwmaccbf16.vf | 57 | hw/riscv/boot.c: Support 64-bit address for initrd |
89 | 58 | ||
90 | Richard W.M. Jones (1): | 59 | Christoph Müllner (1): |
91 | target/riscv: Use env_archcpu for better performance | 60 | riscv: thead: Add th.sxstatus CSR emulation |
92 | 61 | ||
93 | liguang.zhang (1): | 62 | Clément Léger (1): |
94 | target/riscv: Clear CSR values at reset and sync MPSTATE with host | 63 | target/riscv: change RISCV_EXCP_SEMIHOST exception number to 63 |
95 | 64 | ||
96 | docs/about/deprecated.rst | 35 ++ | 65 | Daniel Henrique Barboza (6): |
97 | include/gdbstub/syscalls.h | 9 + | 66 | target/riscv/kvm: implement SBI debug console (DBCN) calls |
98 | include/sysemu/runstate.h | 2 + | 67 | target/riscv/kvm: tolerate KVM disable ext errors |
99 | include/sysemu/sysemu.h | 2 +- | 68 | target/riscv/debug: set tval=pc in breakpoint exceptions |
100 | target/riscv/cpu-qom.h | 1 + | 69 | trans_privileged.c.inc: set (m|s)tval on ebreak breakpoint |
101 | target/riscv/cpu.h | 34 +- | 70 | target/riscv: prioritize pmp errors in raise_mmu_exception() |
102 | target/riscv/{ => kvm}/kvm_riscv.h | 2 +- | 71 | riscv, gdbstub.c: fix reg_width in ricsv_gen_dynamic_vector_feature() |
103 | target/riscv/tcg/tcg-cpu.h | 27 + | ||
104 | disas/riscv.c | 4 +- | ||
105 | gdbstub/gdbstub.c | 5 +- | ||
106 | gdbstub/system.c | 6 + | ||
107 | gdbstub/user.c | 6 + | ||
108 | hw/char/riscv_htif.c | 5 +- | ||
109 | hw/intc/riscv_aplic.c | 2 +- | ||
110 | hw/misc/sifive_test.c | 9 +- | ||
111 | hw/riscv/virt.c | 2 +- | ||
112 | system/main.c | 2 +- | ||
113 | system/runstate.c | 16 +- | ||
114 | target/riscv/cpu.c | 1030 +++++++-------------------------- | ||
115 | target/riscv/cpu_helper.c | 3 +- | ||
116 | target/riscv/csr.c | 1 + | ||
117 | target/riscv/kvm-stub.c | 30 - | ||
118 | target/riscv/{kvm.c => kvm/kvm-cpu.c} | 272 ++++++++- | ||
119 | target/riscv/tcg/tcg-cpu.c | 949 ++++++++++++++++++++++++++++++ | ||
120 | target/riscv/vector_helper.c | 2 +- | ||
121 | target/riscv/kvm/meson.build | 1 + | ||
122 | target/riscv/meson.build | 4 +- | ||
123 | target/riscv/tcg/meson.build | 2 + | ||
124 | tests/avocado/tuxrun_baselines.py | 32 + | ||
125 | 29 files changed, 1604 insertions(+), 891 deletions(-) | ||
126 | rename target/riscv/{ => kvm}/kvm_riscv.h (95%) | ||
127 | create mode 100644 target/riscv/tcg/tcg-cpu.h | ||
128 | delete mode 100644 target/riscv/kvm-stub.c | ||
129 | rename target/riscv/{kvm.c => kvm/kvm-cpu.c} (81%) | ||
130 | create mode 100644 target/riscv/tcg/tcg-cpu.c | ||
131 | create mode 100644 target/riscv/kvm/meson.build | ||
132 | create mode 100644 target/riscv/tcg/meson.build | ||
133 | 72 | ||
73 | Huang Tao (2): | ||
74 | target/riscv: Fix the element agnostic function problem | ||
75 | target/riscv: Implement dynamic establishment of custom decoder | ||
76 | |||
77 | Jason Chien (3): | ||
78 | target/riscv: Add support for Zve32x extension | ||
79 | target/riscv: Add support for Zve64x extension | ||
80 | target/riscv: Relax vector register check in RISCV gdbstub | ||
81 | |||
82 | Max Chou (4): | ||
83 | target/riscv: rvv: Fix Zvfhmin checking for vfwcvt.f.f.v and vfncvt.f.f.w instructions | ||
84 | target/riscv: rvv: Check single width operator for vector fp widen instructions | ||
85 | target/riscv: rvv: Check single width operator for vfncvt.rod.f.f.w | ||
86 | target/riscv: rvv: Remove redudant SEW checking for vector fp narrow/widen instructions | ||
87 | |||
88 | Rob Bradford (1): | ||
89 | target/riscv: Remove experimental prefix from "B" extension | ||
90 | |||
91 | Yangyu Chen (1): | ||
92 | target/riscv/cpu.c: fix Zvkb extension config | ||
93 | |||
94 | Yong-Xuan Wang (1): | ||
95 | target/riscv/kvm.c: Fix the hart bit setting of AIA | ||
96 | |||
97 | Yu-Ming Chang (1): | ||
98 | target/riscv: raise an exception when CSRRS/CSRRC writes a read-only CSR | ||
99 | |||
100 | yang.zhang (1): | ||
101 | hw/intc/riscv_aplic: APLICs should add child earlier than realize | ||
102 | |||
103 | MAINTAINERS | 1 + | ||
104 | target/riscv/cpu.h | 11 ++ | ||
105 | target/riscv/cpu_bits.h | 2 +- | ||
106 | target/riscv/cpu_cfg.h | 2 + | ||
107 | target/riscv/helper.h | 1 + | ||
108 | target/riscv/sbi_ecall_interface.h | 17 +++ | ||
109 | target/riscv/tcg/tcg-cpu.h | 15 +++ | ||
110 | disas/riscv.c | 65 +++++++++- | ||
111 | hw/intc/riscv_aplic.c | 8 +- | ||
112 | hw/riscv/boot.c | 4 +- | ||
113 | target/riscv/cpu.c | 10 +- | ||
114 | target/riscv/cpu_helper.c | 37 +++--- | ||
115 | target/riscv/csr.c | 71 +++++++++-- | ||
116 | target/riscv/debug.c | 3 + | ||
117 | target/riscv/gdbstub.c | 8 +- | ||
118 | target/riscv/kvm/kvm-cpu.c | 157 ++++++++++++++++++++++++- | ||
119 | target/riscv/op_helper.c | 17 ++- | ||
120 | target/riscv/tcg/tcg-cpu.c | 50 +++++--- | ||
121 | target/riscv/th_csr.c | 79 +++++++++++++ | ||
122 | target/riscv/translate.c | 31 +++-- | ||
123 | target/riscv/vector_internals.c | 22 ++++ | ||
124 | target/riscv/insn_trans/trans_privileged.c.inc | 2 + | ||
125 | target/riscv/insn_trans/trans_rvv.c.inc | 46 +++++--- | ||
126 | target/riscv/insn_trans/trans_rvzawrs.c.inc | 29 +++-- | ||
127 | target/riscv/insn_trans/trans_rvzicbo.c.inc | 16 ++- | ||
128 | target/riscv/meson.build | 1 + | ||
129 | 26 files changed, 596 insertions(+), 109 deletions(-) | ||
130 | create mode 100644 target/riscv/th_csr.c | ||
131 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
2 | 1 | ||
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 |
Deleted patch | |||
---|---|---|---|
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
2 | 1 | ||
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 |
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 1 | From: "yang.zhang" <yang.zhang@hexintek.com> |
---|---|---|---|
2 | 2 | ||
3 | Move the files to a 'kvm' dir to promote more code separation between | 3 | Since only root APLICs can have hw IRQ lines, aplic->parent should |
4 | accelerators and making our lives easier supporting build options such | 4 | be initialized first. |
5 | as --disable-tcg. | ||
6 | 5 | ||
7 | Rename kvm.c to kvm-cpu.c to keep it in line with its TCG counterpart. | 6 | Fixes: e8f79343cf ("hw/intc: Add RISC-V AIA APLIC device emulation") |
8 | 7 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | |
9 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 8 | Signed-off-by: yang.zhang <yang.zhang@hexintek.com> |
10 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> | 9 | Cc: qemu-stable <qemu-stable@nongnu.org> |
11 | Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com> | 10 | Message-ID: <20240409014445.278-1-gaoshanliukou@163.com> |
12 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
13 | Message-ID: <20230925175709.35696-13-dbarboza@ventanamicro.com> | ||
14 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 11 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
15 | --- | 12 | --- |
16 | target/riscv/{ => kvm}/kvm_riscv.h | 0 | 13 | hw/intc/riscv_aplic.c | 8 ++++---- |
17 | hw/intc/riscv_aplic.c | 2 +- | 14 | 1 file changed, 4 insertions(+), 4 deletions(-) |
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 | ||
27 | 15 | ||
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 | 16 | diff --git a/hw/intc/riscv_aplic.c b/hw/intc/riscv_aplic.c |
33 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
34 | --- a/hw/intc/riscv_aplic.c | 18 | --- a/hw/intc/riscv_aplic.c |
35 | +++ b/hw/intc/riscv_aplic.c | 19 | +++ b/hw/intc/riscv_aplic.c |
36 | @@ -XXX,XX +XXX,XX @@ | 20 | @@ -XXX,XX +XXX,XX @@ DeviceState *riscv_aplic_create(hwaddr addr, hwaddr size, |
37 | #include "target/riscv/cpu.h" | 21 | qdev_prop_set_bit(dev, "msimode", msimode); |
38 | #include "sysemu/sysemu.h" | 22 | qdev_prop_set_bit(dev, "mmode", mmode); |
39 | #include "sysemu/kvm.h" | 23 | |
40 | -#include "kvm_riscv.h" | 24 | + if (parent) { |
41 | +#include "kvm/kvm_riscv.h" | 25 | + riscv_aplic_add_child(parent, dev); |
42 | #include "migration/vmstate.h" | 26 | + } |
43 | 27 | + | |
44 | #define APLIC_MAX_IDC (1UL << 14) | 28 | sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); |
45 | diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c | 29 | |
46 | index XXXXXXX..XXXXXXX 100644 | 30 | if (!is_kvm_aia(msimode)) { |
47 | --- a/hw/riscv/virt.c | 31 | sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, addr); |
48 | +++ b/hw/riscv/virt.c | 32 | } |
49 | @@ -XXX,XX +XXX,XX @@ | 33 | |
50 | #include "hw/riscv/virt.h" | 34 | - if (parent) { |
51 | #include "hw/riscv/boot.h" | 35 | - riscv_aplic_add_child(parent, dev); |
52 | #include "hw/riscv/numa.h" | 36 | - } |
53 | -#include "kvm_riscv.h" | 37 | - |
54 | +#include "kvm/kvm_riscv.h" | 38 | if (!msimode) { |
55 | #include "hw/intc/riscv_aclint.h" | 39 | for (i = 0; i < num_harts; i++) { |
56 | #include "hw/intc/riscv_aplic.h" | 40 | CPUState *cpu = cpu_by_arch_id(hartid_base + i); |
57 | #include "hw/intc/riscv_imsic.h" | ||
58 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | ||
59 | index XXXXXXX..XXXXXXX 100644 | ||
60 | --- a/target/riscv/cpu.c | ||
61 | +++ b/target/riscv/cpu.c | ||
62 | @@ -XXX,XX +XXX,XX @@ | ||
63 | #include "fpu/softfloat-helpers.h" | ||
64 | #include "sysemu/kvm.h" | ||
65 | #include "sysemu/tcg.h" | ||
66 | -#include "kvm_riscv.h" | ||
67 | +#include "kvm/kvm_riscv.h" | ||
68 | #include "tcg/tcg.h" | ||
69 | |||
70 | /* RISC-V CPU definitions */ | ||
71 | diff --git a/target/riscv/kvm.c b/target/riscv/kvm/kvm-cpu.c | ||
72 | similarity index 100% | ||
73 | rename from target/riscv/kvm.c | ||
74 | rename to target/riscv/kvm/kvm-cpu.c | ||
75 | diff --git a/target/riscv/kvm/meson.build b/target/riscv/kvm/meson.build | ||
76 | new file mode 100644 | ||
77 | index XXXXXXX..XXXXXXX | ||
78 | --- /dev/null | ||
79 | +++ b/target/riscv/kvm/meson.build | ||
80 | @@ -0,0 +1 @@ | ||
81 | +riscv_ss.add(when: 'CONFIG_KVM', if_true: files('kvm-cpu.c')) | ||
82 | diff --git a/target/riscv/meson.build b/target/riscv/meson.build | ||
83 | index XXXXXXX..XXXXXXX 100644 | ||
84 | --- a/target/riscv/meson.build | ||
85 | +++ b/target/riscv/meson.build | ||
86 | @@ -XXX,XX +XXX,XX @@ riscv_ss.add(files( | ||
87 | 'zce_helper.c', | ||
88 | 'vcrypto_helper.c' | ||
89 | )) | ||
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} | ||
102 | -- | 41 | -- |
103 | 2.41.0 | 42 | 2.45.1 | diff view generated by jsdifflib |
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 1 | From: Andrew Jones <ajones@ventanamicro.com> |
---|---|---|---|
2 | 2 | ||
3 | tcg_cpu_instance_init() will be the 'cpu_instance_init' impl for the TCG | 3 | The Zkr extension may only be exposed to KVM guests if the VMM |
4 | accelerator. It'll be called from within riscv_cpu_post_init(), via | 4 | implements the SEED CSR. Use the same implementation as TCG. |
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 | 5 | ||
9 | In this patch we'll move riscv_cpu_add_user_properties() and | 6 | Without this patch, running with a KVM which does not forward the |
10 | riscv_init_max_cpu_extensions() and all their dependencies to tcg-cpu.c. | 7 | SEED CSR access to QEMU will result in an ILL exception being |
11 | All multi-extension properties code was moved. The 'multi_ext_user_opts' | 8 | injected into the guest (this results in Linux guests crashing on |
12 | hash table was also moved to tcg-cpu.c since it's a TCG only structure, | 9 | boot). And, when running with a KVM which does forward the access, |
13 | meaning that we won't have to worry about initializing a TCG hash table | 10 | QEMU will crash, since QEMU doesn't know what to do with the exit. |
14 | when running a KVM CPU anymore. | ||
15 | 11 | ||
16 | riscv_cpu_add_user_properties() will remain in cpu.c for now due to how | 12 | Fixes: 3108e2f1c69d ("target/riscv/kvm: update KVM exts to Linux 6.8") |
17 | much code it requires to be moved at the same time. We'll do that in the | 13 | Signed-off-by: Andrew Jones <ajones@ventanamicro.com> |
18 | next patch. | 14 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
19 | 15 | Cc: qemu-stable <qemu-stable@nongnu.org> | |
20 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 16 | Message-ID: <20240422134605.534207-2-ajones@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> | 17 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
25 | --- | 18 | --- |
26 | target/riscv/cpu.h | 1 - | 19 | target/riscv/cpu.h | 3 +++ |
27 | target/riscv/cpu.c | 150 ------------------------------------- | 20 | target/riscv/csr.c | 18 ++++++++++++++---- |
28 | target/riscv/tcg/tcg-cpu.c | 149 ++++++++++++++++++++++++++++++++++++ | 21 | target/riscv/kvm/kvm-cpu.c | 25 +++++++++++++++++++++++++ |
29 | 3 files changed, 149 insertions(+), 151 deletions(-) | 22 | 3 files changed, 42 insertions(+), 4 deletions(-) |
30 | 23 | ||
31 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h | 24 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h |
32 | index XXXXXXX..XXXXXXX 100644 | 25 | index XXXXXXX..XXXXXXX 100644 |
33 | --- a/target/riscv/cpu.h | 26 | --- a/target/riscv/cpu.h |
34 | +++ b/target/riscv/cpu.h | 27 | +++ b/target/riscv/cpu.h |
35 | @@ -XXX,XX +XXX,XX @@ enum riscv_pmu_event_idx { | 28 | @@ -XXX,XX +XXX,XX @@ void riscv_set_csr_ops(int csrno, riscv_csr_operations *ops); |
36 | 29 | ||
37 | /* used by tcg/tcg-cpu.c*/ | 30 | void riscv_cpu_register_gdb_regs_for_features(CPUState *cs); |
38 | void isa_ext_update_enabled(RISCVCPU *cpu, uint32_t ext_offset, bool en); | 31 | |
39 | -bool cpu_cfg_ext_is_user_set(uint32_t ext_offset); | 32 | +target_ulong riscv_new_csr_seed(target_ulong new_value, |
40 | bool isa_ext_is_enabled(RISCVCPU *cpu, uint32_t ext_offset); | 33 | + target_ulong write_mask); |
41 | int cpu_cfg_ext_get_min_version(uint32_t ext_offset); | 34 | + |
42 | void riscv_cpu_set_misa(CPURISCVState *env, RISCVMXL mxl, uint32_t ext); | 35 | uint8_t satp_mode_max_from_map(uint32_t map); |
43 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | 36 | const char *satp_mode_str(uint8_t satp_mode, bool is_32_bit); |
37 | |||
38 | diff --git a/target/riscv/csr.c b/target/riscv/csr.c | ||
44 | index XXXXXXX..XXXXXXX 100644 | 39 | index XXXXXXX..XXXXXXX 100644 |
45 | --- a/target/riscv/cpu.c | 40 | --- a/target/riscv/csr.c |
46 | +++ b/target/riscv/cpu.c | 41 | +++ b/target/riscv/csr.c |
47 | @@ -XXX,XX +XXX,XX @@ static const struct isa_ext_data isa_edata_arr[] = { | 42 | @@ -XXX,XX +XXX,XX @@ static RISCVException write_upmbase(CPURISCVState *env, int csrno, |
48 | ISA_EXT_DATA_ENTRY(xventanacondops, PRIV_VERSION_1_12_0, ext_XVentanaCondOps), | 43 | #endif |
49 | }; | 44 | |
50 | 45 | /* Crypto Extension */ | |
51 | -/* Hash that stores user set extensions */ | 46 | -static RISCVException rmw_seed(CPURISCVState *env, int csrno, |
52 | -static GHashTable *multi_ext_user_opts; | 47 | - target_ulong *ret_value, |
53 | - | 48 | - target_ulong new_value, |
54 | bool isa_ext_is_enabled(RISCVCPU *cpu, uint32_t ext_offset) | 49 | - target_ulong write_mask) |
50 | +target_ulong riscv_new_csr_seed(target_ulong new_value, | ||
51 | + target_ulong write_mask) | ||
55 | { | 52 | { |
56 | bool *ext_enabled = (void *)&cpu->cfg + ext_offset; | 53 | uint16_t random_v; |
57 | @@ -XXX,XX +XXX,XX @@ int cpu_cfg_ext_get_min_version(uint32_t ext_offset) | 54 | Error *random_e = NULL; |
58 | g_assert_not_reached(); | 55 | @@ -XXX,XX +XXX,XX @@ static RISCVException rmw_seed(CPURISCVState *env, int csrno, |
59 | } | 56 | rval = random_v | SEED_OPST_ES16; |
60 | 57 | } | |
61 | -bool cpu_cfg_ext_is_user_set(uint32_t ext_offset) | 58 | |
62 | -{ | 59 | + return rval; |
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 | +} | 60 | +} |
266 | + | 61 | + |
267 | static void riscv_cpu_synchronize_from_tb(CPUState *cs, | 62 | +static RISCVException rmw_seed(CPURISCVState *env, int csrno, |
268 | const TranslationBlock *tb) | 63 | + target_ulong *ret_value, |
269 | { | 64 | + target_ulong new_value, |
270 | @@ -XXX,XX +XXX,XX @@ static bool tcg_cpu_realize(CPUState *cs, Error **errp) | 65 | + target_ulong write_mask) |
271 | return true; | 66 | +{ |
67 | + target_ulong rval; | ||
68 | + | ||
69 | + rval = riscv_new_csr_seed(new_value, write_mask); | ||
70 | + | ||
71 | if (ret_value) { | ||
72 | *ret_value = rval; | ||
73 | } | ||
74 | diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c | ||
75 | index XXXXXXX..XXXXXXX 100644 | ||
76 | --- a/target/riscv/kvm/kvm-cpu.c | ||
77 | +++ b/target/riscv/kvm/kvm-cpu.c | ||
78 | @@ -XXX,XX +XXX,XX @@ static int kvm_riscv_handle_sbi(CPUState *cs, struct kvm_run *run) | ||
79 | return ret; | ||
272 | } | 80 | } |
273 | 81 | ||
274 | +static void cpu_set_multi_ext_cfg(Object *obj, Visitor *v, const char *name, | 82 | +static int kvm_riscv_handle_csr(CPUState *cs, struct kvm_run *run) |
275 | + void *opaque, Error **errp) | ||
276 | +{ | 83 | +{ |
277 | + const RISCVCPUMultiExtConfig *multi_ext_cfg = opaque; | 84 | + target_ulong csr_num = run->riscv_csr.csr_num; |
278 | + bool value; | 85 | + target_ulong new_value = run->riscv_csr.new_value; |
86 | + target_ulong write_mask = run->riscv_csr.write_mask; | ||
87 | + int ret = 0; | ||
279 | + | 88 | + |
280 | + if (!visit_type_bool(v, name, &value, errp)) { | 89 | + switch (csr_num) { |
281 | + return; | 90 | + case CSR_SEED: |
91 | + run->riscv_csr.ret_value = riscv_new_csr_seed(new_value, write_mask); | ||
92 | + break; | ||
93 | + default: | ||
94 | + qemu_log_mask(LOG_UNIMP, | ||
95 | + "%s: un-handled CSR EXIT for CSR %lx\n", | ||
96 | + __func__, csr_num); | ||
97 | + ret = -1; | ||
98 | + break; | ||
282 | + } | 99 | + } |
283 | + | 100 | + |
284 | + isa_ext_update_enabled(RISCV_CPU(obj), multi_ext_cfg->offset, value); | 101 | + return ret; |
285 | + | ||
286 | + g_hash_table_insert(multi_ext_user_opts, | ||
287 | + GUINT_TO_POINTER(multi_ext_cfg->offset), | ||
288 | + (gpointer)value); | ||
289 | +} | 102 | +} |
290 | + | 103 | + |
291 | +static void cpu_get_multi_ext_cfg(Object *obj, Visitor *v, const char *name, | 104 | int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run) |
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 | { | 105 | { |
414 | /* | 106 | int ret = 0; |
415 | @@ -XXX,XX +XXX,XX @@ static void tcg_cpu_accel_class_init(ObjectClass *oc, void *data) | 107 | @@ -XXX,XX +XXX,XX @@ int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run) |
416 | AccelCPUClass *acc = ACCEL_CPU_CLASS(oc); | 108 | case KVM_EXIT_RISCV_SBI: |
417 | 109 | ret = kvm_riscv_handle_sbi(cs, run); | |
418 | acc->cpu_class_init = tcg_cpu_class_init; | 110 | break; |
419 | + acc->cpu_instance_init = tcg_cpu_instance_init; | 111 | + case KVM_EXIT_RISCV_CSR: |
420 | acc->cpu_target_realize = tcg_cpu_realize; | 112 | + ret = kvm_riscv_handle_csr(cs, run); |
421 | } | 113 | + break; |
422 | 114 | default: | |
115 | qemu_log_mask(LOG_UNIMP, "%s: un-handled exit reason %d\n", | ||
116 | __func__, run->exit_reason); | ||
423 | -- | 117 | -- |
424 | 2.41.0 | 118 | 2.45.1 | diff view generated by jsdifflib |
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 1 | From: Andrew Jones <ajones@ventanamicro.com> |
---|---|---|---|
2 | 2 | ||
3 | riscv_cpu_realize_tcg() was added to allow TCG cpus to have a different | 3 | Implementing wrs.nto to always just return is consistent with the |
4 | realize() path during the common riscv_cpu_realize(), making it a good | 4 | specification, as the instruction is permitted to terminate the |
5 | choice to start moving TCG exclusive code to tcg-cpu.c. | 5 | stall for any reason, but it's not useful for virtualization, where |
6 | we'd like the guest to trap to the hypervisor in order to allow | ||
7 | scheduling of the lock holding VCPU. Change to always immediately | ||
8 | raise exceptions when the appropriate conditions are present, | ||
9 | otherwise continue to just return. Note, immediately raising | ||
10 | exceptions is also consistent with the specification since the | ||
11 | time limit that should expire prior to the exception is | ||
12 | implementation-specific. | ||
6 | 13 | ||
7 | Rename it to tcg_cpu_realizefn() and assign it as a implementation of | 14 | Signed-off-by: Andrew Jones <ajones@ventanamicro.com> |
8 | accel::cpu_realizefn(). tcg_cpu_realizefn() will then be called during | 15 | Reviewed-by: Christoph Müllner <christoph.muellner@vrull.eu> |
9 | riscv_cpu_realize() via cpu_exec_realizefn(). We'll use a similar | 16 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
10 | approach with KVM in the near future. | 17 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
11 | 18 | Message-ID: <20240424142808.62936-2-ajones@ventanamicro.com> | |
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 | ] | ||
22 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 19 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
23 | --- | 20 | --- |
24 | target/riscv/cpu.c | 128 ----------------------------------- | 21 | target/riscv/helper.h | 1 + |
25 | target/riscv/tcg/tcg-cpu.c | 133 +++++++++++++++++++++++++++++++++++++ | 22 | target/riscv/op_helper.c | 11 ++++++++ |
26 | 2 files changed, 133 insertions(+), 128 deletions(-) | 23 | target/riscv/insn_trans/trans_rvzawrs.c.inc | 29 ++++++++++++++------- |
24 | 3 files changed, 32 insertions(+), 9 deletions(-) | ||
27 | 25 | ||
28 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | 26 | diff --git a/target/riscv/helper.h b/target/riscv/helper.h |
29 | index XXXXXXX..XXXXXXX 100644 | 27 | index XXXXXXX..XXXXXXX 100644 |
30 | --- a/target/riscv/cpu.c | 28 | --- a/target/riscv/helper.h |
31 | +++ b/target/riscv/cpu.c | 29 | +++ b/target/riscv/helper.h |
32 | @@ -XXX,XX +XXX,XX @@ | 30 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_6(csrrw_i128, tl, env, int, tl, tl, tl, tl) |
33 | #include "qemu/log.h" | 31 | DEF_HELPER_1(sret, tl, env) |
34 | #include "cpu.h" | 32 | DEF_HELPER_1(mret, tl, env) |
35 | #include "cpu_vendorid.h" | 33 | DEF_HELPER_1(wfi, void, env) |
36 | -#include "pmu.h" | 34 | +DEF_HELPER_1(wrs_nto, void, env) |
37 | #include "internals.h" | 35 | DEF_HELPER_1(tlb_flush, void, env) |
38 | -#include "time_helper.h" | 36 | DEF_HELPER_1(tlb_flush_all, void, env) |
39 | #include "exec/exec-all.h" | 37 | /* Native Debug */ |
40 | #include "qapi/error.h" | 38 | diff --git a/target/riscv/op_helper.c b/target/riscv/op_helper.c |
41 | #include "qapi/visitor.h" | 39 | index XXXXXXX..XXXXXXX 100644 |
42 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_validate_v(CPURISCVState *env, RISCVCPUConfig *cfg, | 40 | --- a/target/riscv/op_helper.c |
41 | +++ b/target/riscv/op_helper.c | ||
42 | @@ -XXX,XX +XXX,XX @@ void helper_wfi(CPURISCVState *env) | ||
43 | } | 43 | } |
44 | } | 44 | } |
45 | 45 | ||
46 | -static void riscv_cpu_validate_priv_spec(RISCVCPU *cpu, Error **errp) | 46 | +void helper_wrs_nto(CPURISCVState *env) |
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 | ||
197 | index XXXXXXX..XXXXXXX 100644 | ||
198 | --- a/target/riscv/tcg/tcg-cpu.c | ||
199 | +++ b/target/riscv/tcg/tcg-cpu.c | ||
200 | @@ -XXX,XX +XXX,XX @@ | ||
201 | */ | ||
202 | |||
203 | #include "qemu/osdep.h" | ||
204 | +#include "exec/exec-all.h" | ||
205 | #include "cpu.h" | ||
206 | +#include "pmu.h" | ||
207 | +#include "time_helper.h" | ||
208 | +#include "qapi/error.h" | ||
209 | #include "qemu/accel.h" | ||
210 | #include "hw/core/accel-cpu.h" | ||
211 | |||
212 | + | ||
213 | +static void riscv_cpu_validate_misa_priv(CPURISCVState *env, Error **errp) | ||
214 | +{ | 47 | +{ |
215 | + if (riscv_has_ext(env, RVH) && env->priv_ver < PRIV_VERSION_1_12_0) { | 48 | + if (env->virt_enabled && (env->priv == PRV_S || env->priv == PRV_U) && |
216 | + error_setg(errp, "H extension requires priv spec 1.12.0"); | 49 | + get_field(env->hstatus, HSTATUS_VTW) && |
217 | + return; | 50 | + !get_field(env->mstatus, MSTATUS_TW)) { |
51 | + riscv_raise_exception(env, RISCV_EXCP_VIRT_INSTRUCTION_FAULT, GETPC()); | ||
52 | + } else if (env->priv != PRV_M && get_field(env->mstatus, MSTATUS_TW)) { | ||
53 | + riscv_raise_exception(env, RISCV_EXCP_ILLEGAL_INST, GETPC()); | ||
218 | + } | 54 | + } |
219 | +} | 55 | +} |
220 | + | 56 | + |
221 | +static void riscv_cpu_validate_misa_mxl(RISCVCPU *cpu, Error **errp) | 57 | void helper_tlb_flush(CPURISCVState *env) |
58 | { | ||
59 | CPUState *cs = env_cpu(env); | ||
60 | diff --git a/target/riscv/insn_trans/trans_rvzawrs.c.inc b/target/riscv/insn_trans/trans_rvzawrs.c.inc | ||
61 | index XXXXXXX..XXXXXXX 100644 | ||
62 | --- a/target/riscv/insn_trans/trans_rvzawrs.c.inc | ||
63 | +++ b/target/riscv/insn_trans/trans_rvzawrs.c.inc | ||
64 | @@ -XXX,XX +XXX,XX @@ | ||
65 | * this program. If not, see <http://www.gnu.org/licenses/>. | ||
66 | */ | ||
67 | |||
68 | -static bool trans_wrs(DisasContext *ctx) | ||
69 | +static bool trans_wrs_sto(DisasContext *ctx, arg_wrs_sto *a) | ||
70 | { | ||
71 | if (!ctx->cfg_ptr->ext_zawrs) { | ||
72 | return false; | ||
73 | @@ -XXX,XX +XXX,XX @@ static bool trans_wrs(DisasContext *ctx) | ||
74 | return true; | ||
75 | } | ||
76 | |||
77 | -#define GEN_TRANS_WRS(insn) \ | ||
78 | -static bool trans_ ## insn(DisasContext *ctx, arg_ ## insn *a) \ | ||
79 | -{ \ | ||
80 | - (void)a; \ | ||
81 | - return trans_wrs(ctx); \ | ||
82 | -} | ||
83 | +static bool trans_wrs_nto(DisasContext *ctx, arg_wrs_nto *a) | ||
222 | +{ | 84 | +{ |
223 | + RISCVCPUClass *mcc = RISCV_CPU_GET_CLASS(cpu); | 85 | + if (!ctx->cfg_ptr->ext_zawrs) { |
224 | + CPUClass *cc = CPU_CLASS(mcc); | ||
225 | + CPURISCVState *env = &cpu->env; | ||
226 | + | ||
227 | + /* Validate that MISA_MXL is set properly. */ | ||
228 | + switch (env->misa_mxl_max) { | ||
229 | +#ifdef TARGET_RISCV64 | ||
230 | + case MXL_RV64: | ||
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 | + } | ||
246 | +} | ||
247 | + | ||
248 | +static void riscv_cpu_validate_priv_spec(RISCVCPU *cpu, Error **errp) | ||
249 | +{ | ||
250 | + CPURISCVState *env = &cpu->env; | ||
251 | + int priv_version = -1; | ||
252 | + | ||
253 | + if (cpu->cfg.priv_spec) { | ||
254 | + if (!g_strcmp0(cpu->cfg.priv_spec, "v1.12.0")) { | ||
255 | + priv_version = PRIV_VERSION_1_12_0; | ||
256 | + } else if (!g_strcmp0(cpu->cfg.priv_spec, "v1.11.0")) { | ||
257 | + priv_version = PRIV_VERSION_1_11_0; | ||
258 | + } else if (!g_strcmp0(cpu->cfg.priv_spec, "v1.10.0")) { | ||
259 | + priv_version = PRIV_VERSION_1_10_0; | ||
260 | + } else { | ||
261 | + error_setg(errp, | ||
262 | + "Unsupported privilege spec version '%s'", | ||
263 | + cpu->cfg.priv_spec); | ||
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; | 86 | + return false; |
287 | + } | 87 | + } |
288 | + | 88 | |
289 | + riscv_cpu_validate_misa_mxl(cpu, &local_err); | 89 | -GEN_TRANS_WRS(wrs_nto) |
290 | + if (local_err != NULL) { | 90 | -GEN_TRANS_WRS(wrs_sto) |
291 | + error_propagate(errp, local_err); | 91 | + /* |
292 | + return false; | 92 | + * Depending on the mode of execution, mstatus.TW and hstatus.VTW, wrs.nto |
293 | + } | 93 | + * should raise an exception when the implementation-specific bounded time |
294 | + | 94 | + * limit has expired. Our time limit is zero, so we either return |
295 | + riscv_cpu_validate_priv_spec(cpu, &local_err); | 95 | + * immediately, as does our implementation of wrs.sto, or raise an |
296 | + if (local_err != NULL) { | 96 | + * exception, as handled by the wrs.nto helper. |
297 | + error_propagate(errp, local_err); | 97 | + */ |
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 | 98 | +#ifndef CONFIG_USER_ONLY |
323 | + CPU(cs)->tcg_cflags |= CF_PCREL; | 99 | + gen_helper_wrs_nto(tcg_env); |
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 | 100 | +#endif |
336 | + | 101 | + |
337 | + return true; | 102 | + /* We only get here when helper_wrs_nto() doesn't raise an exception. */ |
103 | + return trans_wrs_sto(ctx, NULL); | ||
338 | +} | 104 | +} |
339 | + | ||
340 | static void tcg_cpu_init_ops(AccelCPUClass *accel_cpu, CPUClass *cc) | ||
341 | { | ||
342 | /* | ||
343 | @@ -XXX,XX +XXX,XX @@ static void tcg_cpu_accel_class_init(ObjectClass *oc, void *data) | ||
344 | AccelCPUClass *acc = ACCEL_CPU_CLASS(oc); | ||
345 | |||
346 | acc->cpu_class_init = tcg_cpu_class_init; | ||
347 | + acc->cpu_target_realize = tcg_cpu_realize; | ||
348 | } | ||
349 | |||
350 | static const TypeInfo tcg_cpu_accel_type_info = { | ||
351 | -- | 105 | -- |
352 | 2.41.0 | 106 | 2.45.1 |
107 | |||
108 | diff view generated by jsdifflib |
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
---|---|---|---|
2 | 2 | ||
3 | We'll introduce the KVM accelerator class with a 'cpu_instance_init' | 3 | SBI defines a Debug Console extension "DBCN" that will, in time, replace |
4 | implementation that is going to be invoked during the common | 4 | the legacy console putchar and getchar SBI extensions. |
5 | riscv_cpu_post_init() (via accel_cpu_instance_init()). This | 5 | |
6 | instance_init will execute KVM exclusive code that TCG doesn't care | 6 | The appeal of the DBCN extension is that it allows multiple bytes to be |
7 | about, such as adding KVM specific properties, initing registers using a | 7 | read/written in the SBI console in a single SBI call. |
8 | KVM scratch CPU and so on. | 8 | |
9 | 9 | As far as KVM goes, the DBCN calls are forwarded by an in-kernel KVM | |
10 | The core of the forementioned cpu_instance_init impl is the current | 10 | module to userspace. But this will only happens if the KVM module |
11 | riscv_cpu_add_kvm_properties() that is being used by the common code via | 11 | actually supports this SBI extension and we activate it. |
12 | riscv_cpu_add_user_properties() in cpu.c. Move it to kvm.c, together | 12 | |
13 | will all the relevant artifacts, exporting and renaming it to | 13 | We'll check for DBCN support during init time, checking if get-reg-list |
14 | kvm_riscv_cpu_add_kvm_properties() so cpu.c can keep using it for now. | 14 | is advertising KVM_RISCV_SBI_EXT_DBCN. In that case, we'll enable it via |
15 | 15 | kvm_set_one_reg() during kvm_arch_init_vcpu(). | |
16 | To make this work we'll need to export riscv_cpu_extensions, | 16 | |
17 | riscv_cpu_vendor_exts and riscv_cpu_experimental_exts from cpu.c as | 17 | Finally, change kvm_riscv_handle_sbi() to handle the incoming calls for |
18 | well. The TCG accelerator will also need to access those in the near | 18 | SBI_EXT_DBCN, reading and writing as required. |
19 | future so this export will benefit us in the long run. | 19 | |
20 | A simple KVM guest with 'earlycon=sbi', running in an emulated RISC-V | ||
21 | host, takes around 20 seconds to boot without using DBCN. With this | ||
22 | patch we're taking around 14 seconds to boot due to the speed-up in the | ||
23 | terminal output. There's no change in boot time if the guest isn't | ||
24 | using earlycon. | ||
20 | 25 | ||
21 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 26 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
22 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> | 27 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> |
23 | Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com> | 28 | Message-ID: <20240425155012.581366-1-dbarboza@ventanamicro.com> |
24 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
25 | Message-ID: <20230925175709.35696-9-dbarboza@ventanamicro.com> | ||
26 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 29 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
27 | --- | 30 | --- |
28 | target/riscv/cpu.h | 14 +++++++ | 31 | target/riscv/sbi_ecall_interface.h | 17 +++++ |
29 | target/riscv/kvm_riscv.h | 3 -- | 32 | target/riscv/kvm/kvm-cpu.c | 111 +++++++++++++++++++++++++++++ |
30 | target/riscv/cpu.c | 85 +++------------------------------------- | 33 | 2 files changed, 128 insertions(+) |
31 | target/riscv/kvm.c | 68 +++++++++++++++++++++++++++++++- | 34 | |
32 | 4 files changed, 86 insertions(+), 84 deletions(-) | 35 | diff --git a/target/riscv/sbi_ecall_interface.h b/target/riscv/sbi_ecall_interface.h |
33 | |||
34 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h | ||
35 | index XXXXXXX..XXXXXXX 100644 | 36 | index XXXXXXX..XXXXXXX 100644 |
36 | --- a/target/riscv/cpu.h | 37 | --- a/target/riscv/sbi_ecall_interface.h |
37 | +++ b/target/riscv/cpu.h | 38 | +++ b/target/riscv/sbi_ecall_interface.h |
38 | @@ -XXX,XX +XXX,XX @@ | 39 | @@ -XXX,XX +XXX,XX @@ |
39 | 40 | ||
40 | #include "hw/core/cpu.h" | 41 | /* clang-format off */ |
41 | #include "hw/registerfields.h" | 42 | |
42 | +#include "hw/qdev-properties.h" | 43 | +#define SBI_SUCCESS 0 |
43 | #include "exec/cpu-defs.h" | 44 | +#define SBI_ERR_FAILED -1 |
44 | #include "qemu/cpu-float.h" | 45 | +#define SBI_ERR_NOT_SUPPORTED -2 |
45 | #include "qom/object.h" | 46 | +#define SBI_ERR_INVALID_PARAM -3 |
46 | @@ -XXX,XX +XXX,XX @@ bool isa_ext_is_enabled(RISCVCPU *cpu, uint32_t ext_offset); | 47 | +#define SBI_ERR_DENIED -4 |
47 | int cpu_cfg_ext_get_min_version(uint32_t ext_offset); | 48 | +#define SBI_ERR_INVALID_ADDRESS -5 |
48 | void riscv_cpu_disable_priv_spec_isa_exts(RISCVCPU *cpu); | 49 | +#define SBI_ERR_ALREADY_AVAILABLE -6 |
49 | 50 | +#define SBI_ERR_ALREADY_STARTED -7 | |
50 | +typedef struct RISCVCPUMultiExtConfig { | 51 | +#define SBI_ERR_ALREADY_STOPPED -8 |
51 | + const char *name; | 52 | +#define SBI_ERR_NO_SHMEM -9 |
52 | + uint32_t offset; | 53 | + |
53 | + bool enabled; | 54 | /* SBI Extension IDs */ |
54 | +} RISCVCPUMultiExtConfig; | 55 | #define SBI_EXT_0_1_SET_TIMER 0x0 |
55 | + | 56 | #define SBI_EXT_0_1_CONSOLE_PUTCHAR 0x1 |
56 | +extern const RISCVCPUMultiExtConfig riscv_cpu_extensions[]; | 57 | @@ -XXX,XX +XXX,XX @@ |
57 | +extern const RISCVCPUMultiExtConfig riscv_cpu_vendor_exts[]; | 58 | #define SBI_EXT_IPI 0x735049 |
58 | +extern const RISCVCPUMultiExtConfig riscv_cpu_experimental_exts[]; | 59 | #define SBI_EXT_RFENCE 0x52464E43 |
59 | +extern Property riscv_cpu_options[]; | 60 | #define SBI_EXT_HSM 0x48534D |
60 | + | 61 | +#define SBI_EXT_DBCN 0x4442434E |
61 | +void riscv_cpu_add_misa_properties(Object *cpu_obj); | 62 | |
62 | + | 63 | /* SBI function IDs for BASE extension */ |
63 | /* CSR function table */ | 64 | #define SBI_EXT_BASE_GET_SPEC_VERSION 0x0 |
64 | extern riscv_csr_operations csr_ops[CSR_TABLE_SIZE]; | 65 | @@ -XXX,XX +XXX,XX @@ |
65 | 66 | #define SBI_EXT_HSM_HART_STOP 0x1 | |
66 | diff --git a/target/riscv/kvm_riscv.h b/target/riscv/kvm_riscv.h | 67 | #define SBI_EXT_HSM_HART_GET_STATUS 0x2 |
68 | |||
69 | +/* SBI function IDs for DBCN extension */ | ||
70 | +#define SBI_EXT_DBCN_CONSOLE_WRITE 0x0 | ||
71 | +#define SBI_EXT_DBCN_CONSOLE_READ 0x1 | ||
72 | +#define SBI_EXT_DBCN_CONSOLE_WRITE_BYTE 0x2 | ||
73 | + | ||
74 | #define SBI_HSM_HART_STATUS_STARTED 0x0 | ||
75 | #define SBI_HSM_HART_STATUS_STOPPED 0x1 | ||
76 | #define SBI_HSM_HART_STATUS_START_PENDING 0x2 | ||
77 | diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c | ||
67 | index XXXXXXX..XXXXXXX 100644 | 78 | index XXXXXXX..XXXXXXX 100644 |
68 | --- a/target/riscv/kvm_riscv.h | 79 | --- a/target/riscv/kvm/kvm-cpu.c |
69 | +++ b/target/riscv/kvm_riscv.h | 80 | +++ b/target/riscv/kvm/kvm-cpu.c |
70 | @@ -XXX,XX +XXX,XX @@ | 81 | @@ -XXX,XX +XXX,XX @@ static KVMCPUConfig kvm_v_vlenb = { |
71 | #ifndef QEMU_KVM_RISCV_H | 82 | KVM_REG_RISCV_VECTOR_CSR_REG(vlenb) |
72 | #define QEMU_KVM_RISCV_H | ||
73 | |||
74 | -/* Temporarily implemented in cpu.c */ | ||
75 | void kvm_riscv_cpu_add_kvm_properties(Object *obj); | ||
76 | - | ||
77 | -void kvm_riscv_init_user_properties(Object *cpu_obj); | ||
78 | void kvm_riscv_reset_vcpu(RISCVCPU *cpu); | ||
79 | void kvm_riscv_set_irq(RISCVCPU *cpu, int irq, int level); | ||
80 | void kvm_riscv_aia_create(MachineState *machine, uint64_t group_shift, | ||
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) | ||
91 | { | ||
92 | int i; | ||
93 | |||
94 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_add_misa_properties(Object *cpu_obj) | ||
95 | } | ||
96 | } | ||
97 | |||
98 | -typedef struct RISCVCPUMultiExtConfig { | ||
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 | }; | 83 | }; |
116 | 84 | ||
117 | -static const RISCVCPUMultiExtConfig riscv_cpu_vendor_exts[] = { | 85 | +static KVMCPUConfig kvm_sbi_dbcn = { |
118 | +const RISCVCPUMultiExtConfig riscv_cpu_vendor_exts[] = { | 86 | + .name = "sbi_dbcn", |
119 | MULTI_EXT_CFG_BOOL("xtheadba", ext_xtheadba, false), | 87 | + .kvm_reg_id = KVM_REG_RISCV | KVM_REG_SIZE_U64 | |
120 | MULTI_EXT_CFG_BOOL("xtheadbb", ext_xtheadbb, false), | 88 | + KVM_REG_RISCV_SBI_EXT | KVM_RISCV_SBI_EXT_DBCN |
121 | MULTI_EXT_CFG_BOOL("xtheadbs", ext_xtheadbs, false), | 89 | +}; |
122 | @@ -XXX,XX +XXX,XX @@ static const RISCVCPUMultiExtConfig riscv_cpu_vendor_exts[] = { | 90 | + |
123 | }; | 91 | static void kvm_riscv_update_cpu_cfg_isa_ext(RISCVCPU *cpu, CPUState *cs) |
124 | 92 | { | |
125 | /* These are experimental so mark with 'x-' */ | 93 | CPURISCVState *env = &cpu->env; |
126 | -static const RISCVCPUMultiExtConfig riscv_cpu_experimental_exts[] = { | 94 | @@ -XXX,XX +XXX,XX @@ static int uint64_cmp(const void *a, const void *b) |
127 | +const RISCVCPUMultiExtConfig riscv_cpu_experimental_exts[] = { | 95 | return 0; |
128 | /* ePMP 0.9.3 */ | 96 | } |
129 | MULTI_EXT_CFG_BOOL("x-epmp", epmp, false), | 97 | |
130 | MULTI_EXT_CFG_BOOL("x-smaia", ext_smaia, false), | 98 | +static void kvm_riscv_check_sbi_dbcn_support(RISCVCPU *cpu, |
131 | @@ -XXX,XX +XXX,XX @@ static const RISCVCPUMultiExtConfig riscv_cpu_experimental_exts[] = { | 99 | + KVMScratchCPU *kvmcpu, |
132 | DEFINE_PROP_END_OF_LIST(), | 100 | + struct kvm_reg_list *reglist) |
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) | ||
227 | +{ | 101 | +{ |
228 | + const char *propname = opaque; | 102 | + struct kvm_reg_list *reg_search; |
229 | + bool value; | 103 | + |
230 | + | 104 | + reg_search = bsearch(&kvm_sbi_dbcn.kvm_reg_id, reglist->reg, reglist->n, |
231 | + if (!visit_type_bool(v, name, &value, errp)) { | 105 | + sizeof(uint64_t), uint64_cmp); |
232 | + return; | 106 | + |
233 | + } | 107 | + if (reg_search) { |
234 | + | 108 | + kvm_sbi_dbcn.supported = true; |
235 | + if (value) { | ||
236 | + error_setg(errp, "extension %s is not available with KVM", | ||
237 | + propname); | ||
238 | + } | 109 | + } |
239 | +} | 110 | +} |
240 | + | 111 | + |
241 | +static void riscv_cpu_add_kvm_unavail_prop(Object *obj, const char *prop_name) | 112 | static void kvm_riscv_read_vlenb(RISCVCPU *cpu, KVMScratchCPU *kvmcpu, |
113 | struct kvm_reg_list *reglist) | ||
114 | { | ||
115 | @@ -XXX,XX +XXX,XX @@ static void kvm_riscv_init_multiext_cfg(RISCVCPU *cpu, KVMScratchCPU *kvmcpu) | ||
116 | if (riscv_has_ext(&cpu->env, RVV)) { | ||
117 | kvm_riscv_read_vlenb(cpu, kvmcpu, reglist); | ||
118 | } | ||
119 | + | ||
120 | + kvm_riscv_check_sbi_dbcn_support(cpu, kvmcpu, reglist); | ||
121 | } | ||
122 | |||
123 | static void riscv_init_kvm_registers(Object *cpu_obj) | ||
124 | @@ -XXX,XX +XXX,XX @@ static int kvm_vcpu_set_machine_ids(RISCVCPU *cpu, CPUState *cs) | ||
125 | return ret; | ||
126 | } | ||
127 | |||
128 | +static int kvm_vcpu_enable_sbi_dbcn(RISCVCPU *cpu, CPUState *cs) | ||
242 | +{ | 129 | +{ |
243 | + /* Check if KVM created the property already */ | 130 | + target_ulong reg = 1; |
244 | + if (object_property_find(obj, prop_name)) { | 131 | + |
245 | + return; | 132 | + if (!kvm_sbi_dbcn.supported) { |
133 | + return 0; | ||
246 | + } | 134 | + } |
247 | + | 135 | + |
248 | + /* | 136 | + return kvm_set_one_reg(cs, kvm_sbi_dbcn.kvm_reg_id, ®); |
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); | ||
256 | +} | 137 | +} |
257 | + | 138 | + |
258 | +static void riscv_cpu_add_kvm_unavail_prop_array(Object *obj, | 139 | int kvm_arch_init_vcpu(CPUState *cs) |
259 | + const RISCVCPUMultiExtConfig *array) | 140 | { |
141 | int ret = 0; | ||
142 | @@ -XXX,XX +XXX,XX @@ int kvm_arch_init_vcpu(CPUState *cs) | ||
143 | kvm_riscv_update_cpu_misa_ext(cpu, cs); | ||
144 | kvm_riscv_update_cpu_cfg_isa_ext(cpu, cs); | ||
145 | |||
146 | + ret = kvm_vcpu_enable_sbi_dbcn(cpu, cs); | ||
147 | + | ||
148 | return ret; | ||
149 | } | ||
150 | |||
151 | @@ -XXX,XX +XXX,XX @@ bool kvm_arch_stop_on_emulation_error(CPUState *cs) | ||
152 | return true; | ||
153 | } | ||
154 | |||
155 | +static void kvm_riscv_handle_sbi_dbcn(CPUState *cs, struct kvm_run *run) | ||
260 | +{ | 156 | +{ |
261 | + const RISCVCPUMultiExtConfig *prop; | 157 | + g_autofree uint8_t *buf = NULL; |
262 | + | 158 | + RISCVCPU *cpu = RISCV_CPU(cs); |
263 | + g_assert(array); | 159 | + target_ulong num_bytes; |
264 | + | 160 | + uint64_t addr; |
265 | + for (prop = array; prop && prop->name; prop++) { | 161 | + unsigned char ch; |
266 | + riscv_cpu_add_kvm_unavail_prop(obj, prop->name); | 162 | + int ret; |
163 | + | ||
164 | + switch (run->riscv_sbi.function_id) { | ||
165 | + case SBI_EXT_DBCN_CONSOLE_READ: | ||
166 | + case SBI_EXT_DBCN_CONSOLE_WRITE: | ||
167 | + num_bytes = run->riscv_sbi.args[0]; | ||
168 | + | ||
169 | + if (num_bytes == 0) { | ||
170 | + run->riscv_sbi.ret[0] = SBI_SUCCESS; | ||
171 | + run->riscv_sbi.ret[1] = 0; | ||
172 | + break; | ||
173 | + } | ||
174 | + | ||
175 | + addr = run->riscv_sbi.args[1]; | ||
176 | + | ||
177 | + /* | ||
178 | + * Handle the case where a 32 bit CPU is running in a | ||
179 | + * 64 bit addressing env. | ||
180 | + */ | ||
181 | + if (riscv_cpu_mxl(&cpu->env) == MXL_RV32) { | ||
182 | + addr |= (uint64_t)run->riscv_sbi.args[2] << 32; | ||
183 | + } | ||
184 | + | ||
185 | + buf = g_malloc0(num_bytes); | ||
186 | + | ||
187 | + if (run->riscv_sbi.function_id == SBI_EXT_DBCN_CONSOLE_READ) { | ||
188 | + ret = qemu_chr_fe_read_all(serial_hd(0)->be, buf, num_bytes); | ||
189 | + if (ret < 0) { | ||
190 | + error_report("SBI_EXT_DBCN_CONSOLE_READ: error when " | ||
191 | + "reading chardev"); | ||
192 | + exit(1); | ||
193 | + } | ||
194 | + | ||
195 | + cpu_physical_memory_write(addr, buf, ret); | ||
196 | + } else { | ||
197 | + cpu_physical_memory_read(addr, buf, num_bytes); | ||
198 | + | ||
199 | + ret = qemu_chr_fe_write_all(serial_hd(0)->be, buf, num_bytes); | ||
200 | + if (ret < 0) { | ||
201 | + error_report("SBI_EXT_DBCN_CONSOLE_WRITE: error when " | ||
202 | + "writing chardev"); | ||
203 | + exit(1); | ||
204 | + } | ||
205 | + } | ||
206 | + | ||
207 | + run->riscv_sbi.ret[0] = SBI_SUCCESS; | ||
208 | + run->riscv_sbi.ret[1] = ret; | ||
209 | + break; | ||
210 | + case SBI_EXT_DBCN_CONSOLE_WRITE_BYTE: | ||
211 | + ch = run->riscv_sbi.args[0]; | ||
212 | + ret = qemu_chr_fe_write(serial_hd(0)->be, &ch, sizeof(ch)); | ||
213 | + | ||
214 | + if (ret < 0) { | ||
215 | + error_report("SBI_EXT_DBCN_CONSOLE_WRITE_BYTE: error when " | ||
216 | + "writing chardev"); | ||
217 | + exit(1); | ||
218 | + } | ||
219 | + | ||
220 | + run->riscv_sbi.ret[0] = SBI_SUCCESS; | ||
221 | + run->riscv_sbi.ret[1] = 0; | ||
222 | + break; | ||
223 | + default: | ||
224 | + run->riscv_sbi.ret[0] = SBI_ERR_NOT_SUPPORTED; | ||
267 | + } | 225 | + } |
268 | +} | 226 | +} |
269 | + | 227 | + |
270 | static void kvm_riscv_add_cpu_user_properties(Object *cpu_obj) | 228 | static int kvm_riscv_handle_sbi(CPUState *cs, struct kvm_run *run) |
271 | { | 229 | { |
272 | int i; | 230 | int ret = 0; |
273 | @@ -XXX,XX +XXX,XX @@ static void kvm_riscv_init_multiext_cfg(RISCVCPU *cpu, KVMScratchCPU *kvmcpu) | 231 | @@ -XXX,XX +XXX,XX @@ static int kvm_riscv_handle_sbi(CPUState *cs, struct kvm_run *run) |
274 | } | 232 | } |
275 | } | 233 | ret = 0; |
276 | 234 | break; | |
277 | -void kvm_riscv_init_user_properties(Object *cpu_obj) | 235 | + case SBI_EXT_DBCN: |
278 | +static void riscv_init_user_properties(Object *cpu_obj) | 236 | + kvm_riscv_handle_sbi_dbcn(cs, run); |
279 | { | 237 | + break; |
280 | RISCVCPU *cpu = RISCV_CPU(cpu_obj); | 238 | default: |
281 | KVMScratchCPU kvmcpu; | 239 | qemu_log_mask(LOG_UNIMP, |
282 | @@ -XXX,XX +XXX,XX @@ void kvm_riscv_aia_create(MachineState *machine, uint64_t group_shift, | 240 | "%s: un-handled SBI EXIT, specific reasons is %lu\n", |
283 | kvm_msi_via_irqfd_allowed = kvm_irqfds_enabled(); | ||
284 | } | ||
285 | |||
286 | +void kvm_riscv_cpu_add_kvm_properties(Object *obj) | ||
287 | +{ | ||
288 | + DeviceState *dev = DEVICE(obj); | ||
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 | + } | ||
304 | +} | ||
305 | + | ||
306 | static void riscv_host_cpu_init(Object *obj) | ||
307 | { | ||
308 | CPURISCVState *env = &RISCV_CPU(obj)->env; | ||
309 | -- | 241 | -- |
310 | 2.41.0 | 242 | 2.45.1 | diff view generated by jsdifflib |
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 1 | From: Cheng Yang <yangcheng.work@foxmail.com> |
---|---|---|---|
2 | 2 | ||
3 | The array isn't marked as 'const' because we're initializing their | 3 | Use qemu_fdt_setprop_u64() instead of qemu_fdt_setprop_cell() |
4 | elements in riscv_cpu_add_misa_properties(), 'name' and 'description' | 4 | to set the address of initrd in FDT to support 64-bit address. |
5 | fields. | ||
6 | 5 | ||
7 | In a closer look we can see that we're not using these 2 fields after | 6 | Signed-off-by: Cheng Yang <yangcheng.work@foxmail.com> |
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> | ||
17 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 7 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
18 | Message-ID: <20230925175709.35696-17-dbarboza@ventanamicro.com> | 8 | Message-ID: <tencent_A4482251DD0890F312758FA6B33F60815609@qq.com> |
19 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 9 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
20 | --- | 10 | --- |
21 | target/riscv/cpu.c | 21 ++++++++------------- | 11 | hw/riscv/boot.c | 4 ++-- |
22 | 1 file changed, 8 insertions(+), 13 deletions(-) | 12 | 1 file changed, 2 insertions(+), 2 deletions(-) |
23 | 13 | ||
24 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | 14 | diff --git a/hw/riscv/boot.c b/hw/riscv/boot.c |
25 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
26 | --- a/target/riscv/cpu.c | 16 | --- a/hw/riscv/boot.c |
27 | +++ b/target/riscv/cpu.c | 17 | +++ b/hw/riscv/boot.c |
28 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_init(Object *obj) | 18 | @@ -XXX,XX +XXX,XX @@ static void riscv_load_initrd(MachineState *machine, uint64_t kernel_entry) |
29 | } | 19 | /* Some RISC-V machines (e.g. opentitan) don't have a fdt. */ |
30 | 20 | if (fdt) { | |
31 | typedef struct RISCVCPUMisaExtConfig { | 21 | end = start + size; |
32 | - const char *name; | 22 | - qemu_fdt_setprop_cell(fdt, "/chosen", "linux,initrd-start", start); |
33 | - const char *description; | 23 | - qemu_fdt_setprop_cell(fdt, "/chosen", "linux,initrd-end", end); |
34 | target_ulong misa_bit; | 24 | + qemu_fdt_setprop_u64(fdt, "/chosen", "linux,initrd-start", start); |
35 | bool enabled; | 25 | + qemu_fdt_setprop_u64(fdt, "/chosen", "linux,initrd-end", end); |
36 | } RISCVCPUMisaExtConfig; | ||
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 | } | 26 | } |
77 | } | 27 | } |
78 | 28 | ||
79 | -- | 29 | -- |
80 | 2.41.0 | 30 | 2.45.1 | diff view generated by jsdifflib |
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 1 | From: Clément Léger <cleger@rivosinc.com> |
---|---|---|---|
2 | 2 | ||
3 | Our error message is returning the value of 'ret', which will be always | 3 | The current semihost exception number (16) is a reserved number (range |
4 | -1 in case of error, and will not be that useful: | 4 | [16-17]). The upcoming double trap specification uses that number for |
5 | the double trap exception. Since the privileged spec (Table 22) defines | ||
6 | ranges for custom uses change the semihosting exception number to 63 | ||
7 | which belongs to the range [48-63] in order to avoid any future | ||
8 | collisions with reserved exception. | ||
5 | 9 | ||
6 | qemu-system-riscv64: Unable to read ISA_EXT KVM register ssaia, error -1 | 10 | Signed-off-by: Clément Léger <cleger@rivosinc.com> |
7 | 11 | ||
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> | 12 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
20 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> | 13 | Message-ID: <20240422135840.1959967-1-cleger@rivosinc.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> | 14 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
24 | --- | 15 | --- |
25 | target/riscv/kvm/kvm-cpu.c | 4 ++-- | 16 | target/riscv/cpu_bits.h | 2 +- |
26 | 1 file changed, 2 insertions(+), 2 deletions(-) | 17 | 1 file changed, 1 insertion(+), 1 deletion(-) |
27 | 18 | ||
28 | diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c | 19 | diff --git a/target/riscv/cpu_bits.h b/target/riscv/cpu_bits.h |
29 | index XXXXXXX..XXXXXXX 100644 | 20 | index XXXXXXX..XXXXXXX 100644 |
30 | --- a/target/riscv/kvm/kvm-cpu.c | 21 | --- a/target/riscv/cpu_bits.h |
31 | +++ b/target/riscv/kvm/kvm-cpu.c | 22 | +++ b/target/riscv/cpu_bits.h |
32 | @@ -XXX,XX +XXX,XX @@ static void kvm_riscv_init_multiext_cfg(RISCVCPU *cpu, KVMScratchCPU *kvmcpu) | 23 | @@ -XXX,XX +XXX,XX @@ typedef enum RISCVException { |
33 | val = false; | 24 | RISCV_EXCP_INST_PAGE_FAULT = 0xc, /* since: priv-1.10.0 */ |
34 | } else { | 25 | RISCV_EXCP_LOAD_PAGE_FAULT = 0xd, /* since: priv-1.10.0 */ |
35 | error_report("Unable to read ISA_EXT KVM register %s, " | 26 | RISCV_EXCP_STORE_PAGE_FAULT = 0xf, /* since: priv-1.10.0 */ |
36 | - "error %d", multi_ext_cfg->name, ret); | 27 | - RISCV_EXCP_SEMIHOST = 0x10, |
37 | - kvm_riscv_destroy_scratch_vcpu(kvmcpu); | 28 | RISCV_EXCP_INST_GUEST_PAGE_FAULT = 0x14, |
38 | + "error code: %s", multi_ext_cfg->name, | 29 | RISCV_EXCP_LOAD_GUEST_ACCESS_FAULT = 0x15, |
39 | + strerrorname_np(errno)); | 30 | RISCV_EXCP_VIRT_INSTRUCTION_FAULT = 0x16, |
40 | exit(EXIT_FAILURE); | 31 | RISCV_EXCP_STORE_GUEST_AMO_ACCESS_FAULT = 0x17, |
41 | } | 32 | + RISCV_EXCP_SEMIHOST = 0x3f, |
42 | } else { | 33 | } RISCVException; |
34 | |||
35 | #define RISCV_EXCP_INT_FLAG 0x80000000 | ||
43 | -- | 36 | -- |
44 | 2.41.0 | 37 | 2.45.1 |
45 | 38 | ||
46 | 39 | diff view generated by jsdifflib |
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
---|---|---|---|
2 | 2 | ||
3 | riscv_cpu_add_misa_properties() is being used to fill the missing KVM | 3 | Running a KVM guest using a 6.9-rc3 kernel, in a 6.8 host that has zkr |
4 | MISA properties but it is a TCG helper that was adapted to do so. We'll | 4 | enabled, will fail with a kernel oops SIGILL right at the start. The |
5 | move it to tcg-cpu.c in the next patches, meaning that KVM needs to fill | 5 | reason is that we can't expose zkr without implementing the SEED CSR. |
6 | the remaining MISA properties on its own. | 6 | Disabling zkr in the guest would be a workaround, but if the KVM doesn't |
7 | allow it we'll error out and never boot. | ||
7 | 8 | ||
8 | Do not use riscv_cpu_add_misa_properties(). Let's create a new array | 9 | In hindsight this is too strict. If we keep proceeding, despite not |
9 | with all available MISA bits we support that can be read by KVM. The | 10 | disabling the extension in the KVM vcpu, we'll not add the extension in |
10 | array is zero terminate to allow us to iterate through it without | 11 | the riscv,isa. The guest kernel will be unaware of the extension, i.e. |
11 | knowing its size. | 12 | it doesn't matter if the KVM vcpu has it enabled underneath or not. So |
13 | it's ok to keep booting in this case. | ||
12 | 14 | ||
13 | Then, inside kvm_riscv_add_cpu_user_properties(), we'll create all KVM | 15 | Change our current logic to not error out if we fail to disable an |
14 | MISA properties as usual and then use this array to add any missing MISA | 16 | extension in kvm_set_one_reg(), but show a warning and keep booting. It |
15 | properties with the riscv_cpu_add_kvm_unavail_prop() helper. | 17 | is important to throw a warning because we must make the user aware that |
18 | the extension is still available in the vcpu, meaning that an | ||
19 | ill-behaved guest can ignore the riscv,isa settings and use the | ||
20 | extension. | ||
16 | 21 | ||
17 | Note that we're creating misa_bits[], and not using the existing | 22 | The case we're handling happens with an EINVAL error code. If we fail to |
18 | 'riscv_single_letter_exts[]', because the latter is tuned for riscv,isa | 23 | disable the extension in KVM for any other reason, error out. |
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 | 24 | ||
23 | While we're at it, move both satp and the multi-letter extension | 25 | We'll also keep erroring out when we fail to enable an extension in KVM, |
24 | properties to kvm_riscv_add_cpu_user_properties() as well. | 26 | since adding the extension in riscv,isa at this point will cause a guest |
27 | malfunction because the extension isn't enabled in the vcpu. | ||
25 | 28 | ||
29 | Suggested-by: Andrew Jones <ajones@ventanamicro.com> | ||
26 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 30 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
27 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> | 31 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> |
28 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 32 | Cc: qemu-stable <qemu-stable@nongnu.org> |
29 | Message-ID: <20230925175709.35696-14-dbarboza@ventanamicro.com> | 33 | Message-ID: <20240422171425.333037-2-dbarboza@ventanamicro.com> |
30 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 34 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
31 | --- | 35 | --- |
32 | target/riscv/cpu.h | 3 ++- | 36 | target/riscv/kvm/kvm-cpu.c | 12 ++++++++---- |
33 | target/riscv/cpu.c | 2 ++ | 37 | 1 file changed, 8 insertions(+), 4 deletions(-) |
34 | target/riscv/kvm/kvm-cpu.c | 22 ++++++++++++++-------- | ||
35 | 3 files changed, 18 insertions(+), 9 deletions(-) | ||
36 | 38 | ||
37 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h | ||
38 | index XXXXXXX..XXXXXXX 100644 | ||
39 | --- a/target/riscv/cpu.h | ||
40 | +++ b/target/riscv/cpu.h | ||
41 | @@ -XXX,XX +XXX,XX @@ | ||
42 | #define RV(x) ((target_ulong)1 << (x - 'A')) | ||
43 | |||
44 | /* | ||
45 | - * Consider updating misa_ext_info_arr[] and misa_ext_cfgs[] | ||
46 | + * Update misa_bits[], misa_ext_info_arr[] and misa_ext_cfgs[] | ||
47 | * when adding new MISA bits here. | ||
48 | */ | ||
49 | #define RVI RV('I') | ||
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); | ||
57 | |||
58 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | ||
59 | index XXXXXXX..XXXXXXX 100644 | ||
60 | --- a/target/riscv/cpu.c | ||
61 | +++ b/target/riscv/cpu.c | ||
62 | @@ -XXX,XX +XXX,XX @@ | ||
63 | |||
64 | /* RISC-V CPU definitions */ | ||
65 | static const char riscv_single_letter_exts[] = "IEMAFDQCPVH"; | ||
66 | +const uint32_t misa_bits[] = {RVI, RVE, RVM, RVA, RVF, RVD, RVV, | ||
67 | + RVC, RVS, RVU, RVH, RVJ, RVG, 0}; | ||
68 | |||
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 | 39 | diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c |
72 | index XXXXXXX..XXXXXXX 100644 | 40 | index XXXXXXX..XXXXXXX 100644 |
73 | --- a/target/riscv/kvm/kvm-cpu.c | 41 | --- a/target/riscv/kvm/kvm-cpu.c |
74 | +++ b/target/riscv/kvm/kvm-cpu.c | 42 | +++ b/target/riscv/kvm/kvm-cpu.c |
75 | @@ -XXX,XX +XXX,XX @@ static void kvm_riscv_add_cpu_user_properties(Object *cpu_obj) | 43 | @@ -XXX,XX +XXX,XX @@ static void kvm_riscv_update_cpu_cfg_isa_ext(RISCVCPU *cpu, CPUState *cs) |
76 | { | 44 | reg = kvm_cpu_cfg_get(cpu, multi_ext_cfg); |
77 | int i; | 45 | ret = kvm_set_one_reg(cs, id, ®); |
78 | 46 | if (ret != 0) { | |
79 | + riscv_add_satp_mode_properties(cpu_obj); | 47 | - error_report("Unable to %s extension %s in KVM, error %d", |
80 | + | 48 | - reg ? "enable" : "disable", |
81 | for (i = 0; i < ARRAY_SIZE(kvm_misa_ext_cfgs); i++) { | 49 | - multi_ext_cfg->name, ret); |
82 | KVMCPUConfig *misa_cfg = &kvm_misa_ext_cfgs[i]; | 50 | - exit(EXIT_FAILURE); |
83 | int bit = misa_cfg->offset; | 51 | + if (!reg && ret == -EINVAL) { |
84 | @@ -XXX,XX +XXX,XX @@ static void kvm_riscv_add_cpu_user_properties(Object *cpu_obj) | 52 | + warn_report("KVM cannot disable extension %s", |
85 | misa_cfg->description); | 53 | + multi_ext_cfg->name); |
86 | } | 54 | + } else { |
87 | 55 | + error_report("Unable to enable extension %s in KVM, error %d", | |
88 | + for (i = 0; misa_bits[i] != 0; i++) { | 56 | + multi_ext_cfg->name, ret); |
89 | + const char *ext_name = riscv_get_misa_ext_name(misa_bits[i]); | 57 | + exit(EXIT_FAILURE); |
90 | + riscv_cpu_add_kvm_unavail_prop(cpu_obj, ext_name); | 58 | + } |
91 | + } | 59 | } |
92 | + | ||
93 | for (i = 0; i < ARRAY_SIZE(kvm_multi_ext_cfgs); i++) { | ||
94 | KVMCPUConfig *multi_cfg = &kvm_multi_ext_cfgs[i]; | ||
95 | |||
96 | @@ -XXX,XX +XXX,XX @@ static void kvm_riscv_add_cpu_user_properties(Object *cpu_obj) | ||
97 | object_property_add(cpu_obj, "cboz_blocksize", "uint16", | ||
98 | NULL, kvm_cpu_set_cbomz_blksize, | ||
99 | NULL, &kvm_cboz_blocksize); | ||
100 | + | ||
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); | ||
104 | } | ||
105 | |||
106 | static int kvm_riscv_get_regs_core(CPUState *cs) | ||
107 | @@ -XXX,XX +XXX,XX @@ static void kvm_riscv_init_multiext_cfg(RISCVCPU *cpu, KVMScratchCPU *kvmcpu) | ||
108 | } | 60 | } |
109 | } | 61 | } |
110 | |||
111 | -static void riscv_init_user_properties(Object *cpu_obj) | ||
112 | +static void riscv_init_kvm_registers(Object *cpu_obj) | ||
113 | { | ||
114 | RISCVCPU *cpu = RISCV_CPU(cpu_obj); | ||
115 | KVMScratchCPU kvmcpu; | ||
116 | @@ -XXX,XX +XXX,XX @@ static void riscv_init_user_properties(Object *cpu_obj) | ||
117 | return; | ||
118 | } | ||
119 | |||
120 | - kvm_riscv_add_cpu_user_properties(cpu_obj); | ||
121 | kvm_riscv_init_machine_ids(cpu, &kvmcpu); | ||
122 | kvm_riscv_init_misa_ext_mask(cpu, &kvmcpu); | ||
123 | kvm_riscv_init_multiext_cfg(cpu, &kvmcpu); | ||
124 | @@ -XXX,XX +XXX,XX @@ static void kvm_cpu_instance_init(CPUState *cs) | ||
125 | Object *obj = OBJECT(RISCV_CPU(cs)); | ||
126 | DeviceState *dev = DEVICE(obj); | ||
127 | |||
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 */ | ||
140 | -- | 62 | -- |
141 | 2.41.0 | 63 | 2.45.1 | diff view generated by jsdifflib |
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
---|---|---|---|
2 | 2 | ||
3 | At this moment we do not expose extension properties for vendor CPUs | 3 | We're not setting (s/m)tval when triggering breakpoints of type 2 |
4 | because that would allow users to change them via command line. The | 4 | (mcontrol) and 6 (mcontrol6). According to the debug spec section |
5 | drawback is that if we were to add an API that shows all CPU properties, | 5 | 5.7.12, "Match Control Type 6": |
6 | e.g. qmp-query-cpu-model-expansion, we won't be able to show extensions | ||
7 | state of vendor CPUs. | ||
8 | 6 | ||
9 | We have the required machinery to create extension properties for vendor | 7 | "The Privileged Spec says that breakpoint exceptions that occur on |
10 | CPUs while not allowing users to enable extensions. Disabling existing | 8 | instruction fetches, loads, or stores update the tval CSR with either |
11 | extensions is allowed since it can be useful for debugging. | 9 | zero or the faulting virtual address. The faulting virtual address for |
10 | an mcontrol6 trigger with action = 0 is the address being accessed and | ||
11 | which caused that trigger to fire." | ||
12 | 12 | ||
13 | Change the set() callback cpu_set_multi_ext_cfg() to allow enabling | 13 | A similar text is also found in the Debug spec section 5.7.11 w.r.t. |
14 | extensions only for generic CPUs. In cpu_add_multi_ext_prop() let's not | 14 | mcontrol. |
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 | 15 | ||
20 | For the veyron-v1 CPU, we're now able to disable existing extensions | 16 | Note that what we're doing ATM is not violating the spec, but it's |
21 | like smstateen: | 17 | simple enough to set mtval/stval and it makes life easier for any |
18 | software that relies on this info. | ||
22 | 19 | ||
23 | $ ./build/qemu-system-riscv64 --nographic -M virt \ | 20 | Given that we always use action = 0, save the faulting address for the |
24 | -cpu veyron-v1,smstateen=false | 21 | mcontrol and mcontrol6 trigger breakpoints into env->badaddr, which is |
25 | 22 | used as as scratch area for traps with address information. 'tval' is | |
26 | But setting extensions that the CPU didn't set during cpu_init(), like | 23 | then set during riscv_cpu_do_interrupt(). |
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 | 24 | ||
34 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 25 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
35 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 26 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
36 | Message-ID: <20230926183109.165878-3-dbarboza@ventanamicro.com> | 27 | Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com> |
28 | Message-ID: <20240416230437.1869024-2-dbarboza@ventanamicro.com> | ||
37 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 29 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
38 | --- | 30 | --- |
39 | target/riscv/tcg/tcg-cpu.c | 64 +++++++++++++++++++++++++++++--------- | 31 | target/riscv/cpu_helper.c | 1 + |
40 | 1 file changed, 50 insertions(+), 14 deletions(-) | 32 | target/riscv/debug.c | 3 +++ |
33 | 2 files changed, 4 insertions(+) | ||
41 | 34 | ||
42 | diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c | 35 | diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c |
43 | index XXXXXXX..XXXXXXX 100644 | 36 | index XXXXXXX..XXXXXXX 100644 |
44 | --- a/target/riscv/tcg/tcg-cpu.c | 37 | --- a/target/riscv/cpu_helper.c |
45 | +++ b/target/riscv/tcg/tcg-cpu.c | 38 | +++ b/target/riscv/cpu_helper.c |
46 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp) | 39 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_do_interrupt(CPUState *cs) |
47 | riscv_cpu_disable_priv_spec_isa_exts(cpu); | 40 | tval = env->bins; |
48 | } | 41 | break; |
49 | 42 | case RISCV_EXCP_BREAKPOINT: | |
50 | +static bool riscv_cpu_is_generic(Object *cpu_obj) | 43 | + tval = env->badaddr; |
51 | +{ | 44 | if (cs->watchpoint_hit) { |
52 | + return object_dynamic_cast(cpu_obj, TYPE_RISCV_DYNAMIC_CPU) != NULL; | 45 | tval = cs->watchpoint_hit->hitaddr; |
53 | +} | 46 | cs->watchpoint_hit = NULL; |
54 | + | 47 | diff --git a/target/riscv/debug.c b/target/riscv/debug.c |
55 | /* | 48 | index XXXXXXX..XXXXXXX 100644 |
56 | * We'll get here via the following path: | 49 | --- a/target/riscv/debug.c |
57 | * | 50 | +++ b/target/riscv/debug.c |
58 | @@ -XXX,XX +XXX,XX @@ static void cpu_set_misa_ext_cfg(Object *obj, Visitor *v, const char *name, | 51 | @@ -XXX,XX +XXX,XX @@ bool riscv_cpu_debug_check_breakpoint(CPUState *cs) |
59 | target_ulong misa_bit = misa_ext_cfg->misa_bit; | 52 | if ((ctrl & TYPE2_EXEC) && (bp->pc == pc)) { |
60 | RISCVCPU *cpu = RISCV_CPU(obj); | 53 | /* check U/S/M bit against current privilege level */ |
61 | CPURISCVState *env = &cpu->env; | 54 | if ((ctrl >> 3) & BIT(env->priv)) { |
62 | - bool value; | 55 | + env->badaddr = pc; |
63 | + bool generic_cpu = riscv_cpu_is_generic(obj); | 56 | return true; |
64 | + bool prev_val, value; | 57 | } |
65 | 58 | } | |
66 | if (!visit_type_bool(v, name, &value, errp)) { | 59 | @@ -XXX,XX +XXX,XX @@ bool riscv_cpu_debug_check_breakpoint(CPUState *cs) |
67 | return; | 60 | if (env->virt_enabled) { |
68 | } | 61 | /* check VU/VS bit against current privilege level */ |
69 | 62 | if ((ctrl >> 23) & BIT(env->priv)) { | |
70 | + prev_val = env->misa_ext & misa_bit; | 63 | + env->badaddr = pc; |
71 | + | 64 | return true; |
72 | + if (value == prev_val) { | 65 | } |
73 | + return; | 66 | } else { |
74 | + } | 67 | /* check U/S/M bit against current privilege level */ |
75 | + | 68 | if ((ctrl >> 3) & BIT(env->priv)) { |
76 | if (value) { | 69 | + env->badaddr = pc; |
77 | + if (!generic_cpu) { | 70 | return true; |
78 | + g_autofree char *cpuname = riscv_cpu_get_name(cpu); | 71 | } |
79 | + error_setg(errp, "'%s' CPU does not allow enabling extensions", | 72 | } |
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 | -- | 73 | -- |
184 | 2.41.0 | 74 | 2.45.1 | diff view generated by jsdifflib |
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
---|---|---|---|
2 | 2 | ||
3 | We'll introduce generic errors that will output a CPU type name via its | 3 | Privileged spec section 4.1.9 mentions: |
4 | RISCVCPU pointer. Create a helper for that. | ||
5 | 4 | ||
6 | Use the helper in tcg_cpu_realizefn() instead of hardcoding the 'host' | 5 | "When a trap is taken into S-mode, stval is written with |
7 | CPU name. | 6 | exception-specific information to assist software in handling the trap. |
7 | (...) | ||
8 | |||
9 | If stval is written with a nonzero value when a breakpoint, | ||
10 | address-misaligned, access-fault, or page-fault exception occurs on an | ||
11 | instruction fetch, load, or store, then stval will contain the faulting | ||
12 | virtual address." | ||
13 | |||
14 | A similar text is found for mtval in section 3.1.16. | ||
15 | |||
16 | Setting mtval/stval in this scenario is optional, but some softwares read | ||
17 | these regs when handling ebreaks. | ||
18 | |||
19 | Write 'badaddr' in all ebreak breakpoints to write the appropriate | ||
20 | 'tval' during riscv_do_cpu_interrrupt(). | ||
8 | 21 | ||
9 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 22 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
10 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 23 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
11 | Message-ID: <20230926183109.165878-2-dbarboza@ventanamicro.com> | 24 | Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com> |
25 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
26 | Message-ID: <20240416230437.1869024-3-dbarboza@ventanamicro.com> | ||
12 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 27 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
13 | --- | 28 | --- |
14 | target/riscv/cpu.h | 1 + | 29 | target/riscv/insn_trans/trans_privileged.c.inc | 2 ++ |
15 | target/riscv/cpu.c | 11 +++++++++++ | 30 | 1 file changed, 2 insertions(+) |
16 | target/riscv/tcg/tcg-cpu.c | 4 +++- | ||
17 | 3 files changed, 15 insertions(+), 1 deletion(-) | ||
18 | 31 | ||
19 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h | 32 | diff --git a/target/riscv/insn_trans/trans_privileged.c.inc b/target/riscv/insn_trans/trans_privileged.c.inc |
20 | index XXXXXXX..XXXXXXX 100644 | 33 | index XXXXXXX..XXXXXXX 100644 |
21 | --- a/target/riscv/cpu.h | 34 | --- a/target/riscv/insn_trans/trans_privileged.c.inc |
22 | +++ b/target/riscv/cpu.h | 35 | +++ b/target/riscv/insn_trans/trans_privileged.c.inc |
23 | @@ -XXX,XX +XXX,XX @@ typedef struct isa_ext_data { | 36 | @@ -XXX,XX +XXX,XX @@ static bool trans_ebreak(DisasContext *ctx, arg_ebreak *a) |
24 | int ext_enable_offset; | 37 | if (pre == 0x01f01013 && ebreak == 0x00100073 && post == 0x40705013) { |
25 | } RISCVIsaExtData; | 38 | generate_exception(ctx, RISCV_EXCP_SEMIHOST); |
26 | extern const RISCVIsaExtData isa_edata_arr[]; | 39 | } else { |
27 | +char *riscv_cpu_get_name(RISCVCPU *cpu); | 40 | + tcg_gen_st_tl(tcg_constant_tl(ebreak_addr), tcg_env, |
28 | 41 | + offsetof(CPURISCVState, badaddr)); | |
29 | void riscv_add_satp_mode_properties(Object *obj); | 42 | generate_exception(ctx, RISCV_EXCP_BREAKPOINT); |
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 | } | 43 | } |
67 | 44 | return true; | |
68 | -- | 45 | -- |
69 | 2.41.0 | 46 | 2.45.1 | diff view generated by jsdifflib |
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 1 | From: Jason Chien <jason.chien@sifive.com> |
---|---|---|---|
2 | 2 | ||
3 | Let's change the other instances in realize() where we're enabling an | 3 | Add support for Zve32x extension and replace some checks for Zve32f with |
4 | extension based on a certain criteria (e.g. it's a dependency of another | 4 | Zve32x, since Zve32f depends on Zve32x. |
5 | extension). | ||
6 | 5 | ||
7 | We're leaving icsr and ifencei being enabled during RVG for later - | 6 | Signed-off-by: Jason Chien <jason.chien@sifive.com> |
8 | we'll want to error out in that case. Every other extension enablement | 7 | Reviewed-by: Frank Chang <frank.chang@sifive.com> |
9 | during realize is now done via cpu_cfg_ext_auto_update(). | 8 | Reviewed-by: Max Chou <max.chou@sifive.com> |
10 | 9 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | |
11 | The end goal is that only cpu init() functions will handle extension | 10 | Message-ID: <20240328022343.6871-2-jason.chien@sifive.com> |
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> | 11 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
19 | --- | 12 | --- |
20 | target/riscv/cpu.c | 50 +++++++++++++++++++++++----------------------- | 13 | target/riscv/cpu_cfg.h | 1 + |
21 | 1 file changed, 25 insertions(+), 25 deletions(-) | 14 | target/riscv/cpu.c | 2 ++ |
15 | target/riscv/cpu_helper.c | 2 +- | ||
16 | target/riscv/csr.c | 2 +- | ||
17 | target/riscv/tcg/tcg-cpu.c | 16 ++++++++-------- | ||
18 | target/riscv/insn_trans/trans_rvv.c.inc | 4 ++-- | ||
19 | 6 files changed, 15 insertions(+), 12 deletions(-) | ||
22 | 20 | ||
21 | diff --git a/target/riscv/cpu_cfg.h b/target/riscv/cpu_cfg.h | ||
22 | index XXXXXXX..XXXXXXX 100644 | ||
23 | --- a/target/riscv/cpu_cfg.h | ||
24 | +++ b/target/riscv/cpu_cfg.h | ||
25 | @@ -XXX,XX +XXX,XX @@ struct RISCVCPUConfig { | ||
26 | bool ext_zhinx; | ||
27 | bool ext_zhinxmin; | ||
28 | bool ext_zve32f; | ||
29 | + bool ext_zve32x; | ||
30 | bool ext_zve64f; | ||
31 | bool ext_zve64d; | ||
32 | bool ext_zvbb; | ||
23 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | 33 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c |
24 | index XXXXXXX..XXXXXXX 100644 | 34 | index XXXXXXX..XXXXXXX 100644 |
25 | --- a/target/riscv/cpu.c | 35 | --- a/target/riscv/cpu.c |
26 | +++ b/target/riscv/cpu.c | 36 | +++ b/target/riscv/cpu.c |
37 | @@ -XXX,XX +XXX,XX @@ const RISCVIsaExtData isa_edata_arr[] = { | ||
38 | ISA_EXT_DATA_ENTRY(zvbb, PRIV_VERSION_1_12_0, ext_zvbb), | ||
39 | ISA_EXT_DATA_ENTRY(zvbc, PRIV_VERSION_1_12_0, ext_zvbc), | ||
40 | ISA_EXT_DATA_ENTRY(zve32f, PRIV_VERSION_1_10_0, ext_zve32f), | ||
41 | + ISA_EXT_DATA_ENTRY(zve32x, PRIV_VERSION_1_10_0, ext_zve32x), | ||
42 | ISA_EXT_DATA_ENTRY(zve64f, PRIV_VERSION_1_10_0, ext_zve64f), | ||
43 | ISA_EXT_DATA_ENTRY(zve64d, PRIV_VERSION_1_10_0, ext_zve64d), | ||
44 | ISA_EXT_DATA_ENTRY(zvfbfmin, PRIV_VERSION_1_12_0, ext_zvfbfmin), | ||
45 | @@ -XXX,XX +XXX,XX @@ const RISCVCPUMultiExtConfig riscv_cpu_extensions[] = { | ||
46 | MULTI_EXT_CFG_BOOL("zfh", ext_zfh, false), | ||
47 | MULTI_EXT_CFG_BOOL("zfhmin", ext_zfhmin, false), | ||
48 | MULTI_EXT_CFG_BOOL("zve32f", ext_zve32f, false), | ||
49 | + MULTI_EXT_CFG_BOOL("zve32x", ext_zve32x, false), | ||
50 | MULTI_EXT_CFG_BOOL("zve64f", ext_zve64f, false), | ||
51 | MULTI_EXT_CFG_BOOL("zve64d", ext_zve64d, false), | ||
52 | MULTI_EXT_CFG_BOOL("zvfbfmin", ext_zvfbfmin, false), | ||
53 | diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c | ||
54 | index XXXXXXX..XXXXXXX 100644 | ||
55 | --- a/target/riscv/cpu_helper.c | ||
56 | +++ b/target/riscv/cpu_helper.c | ||
57 | @@ -XXX,XX +XXX,XX @@ void cpu_get_tb_cpu_state(CPURISCVState *env, vaddr *pc, | ||
58 | *pc = env->xl == MXL_RV32 ? env->pc & UINT32_MAX : env->pc; | ||
59 | *cs_base = 0; | ||
60 | |||
61 | - if (cpu->cfg.ext_zve32f) { | ||
62 | + if (cpu->cfg.ext_zve32x) { | ||
63 | /* | ||
64 | * If env->vl equals to VLMAX, we can use generic vector operation | ||
65 | * expanders (GVEC) to accerlate the vector operations. | ||
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 @@ static RISCVException fs(CPURISCVState *env, int csrno) | ||
71 | |||
72 | static RISCVException vs(CPURISCVState *env, int csrno) | ||
73 | { | ||
74 | - if (riscv_cpu_cfg(env)->ext_zve32f) { | ||
75 | + if (riscv_cpu_cfg(env)->ext_zve32x) { | ||
76 | #if !defined(CONFIG_USER_ONLY) | ||
77 | if (!env->debugger && !riscv_cpu_vector_enabled(env)) { | ||
78 | return RISCV_EXCP_ILLEGAL_INST; | ||
79 | diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c | ||
80 | index XXXXXXX..XXXXXXX 100644 | ||
81 | --- a/target/riscv/tcg/tcg-cpu.c | ||
82 | +++ b/target/riscv/tcg/tcg-cpu.c | ||
27 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp) | 83 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp) |
84 | return; | ||
28 | } | 85 | } |
29 | 86 | ||
30 | if (cpu->cfg.ext_zfh) { | 87 | - if (cpu->cfg.ext_zve32f && !riscv_has_ext(env, RVF)) { |
31 | - cpu->cfg.ext_zfhmin = true; | 88 | - error_setg(errp, "Zve32f/Zve64f extensions require F extension"); |
32 | + cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zfhmin), true); | 89 | - return; |
90 | + /* The Zve32f extension depends on the Zve32x extension */ | ||
91 | + if (cpu->cfg.ext_zve32f) { | ||
92 | + if (!riscv_has_ext(env, RVF)) { | ||
93 | + error_setg(errp, "Zve32f/Zve64f extensions require F extension"); | ||
94 | + return; | ||
95 | + } | ||
96 | + cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zve32x), true); | ||
33 | } | 97 | } |
34 | 98 | ||
35 | if (cpu->cfg.ext_zfhmin && !riscv_has_ext(env, RVF)) { | 99 | if (cpu->cfg.ext_zvfh) { |
36 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp) | 100 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp) |
37 | } | 101 | cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zvbc), true); |
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 | } | 102 | } |
43 | 103 | ||
44 | /* The Zve64d extension depends on the Zve64f extension */ | 104 | - /* |
45 | if (cpu->cfg.ext_zve64d) { | 105 | - * In principle Zve*x would also suffice here, were they supported |
46 | - cpu->cfg.ext_zve64f = true; | 106 | - * in qemu |
47 | + cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zve64f), true); | 107 | - */ |
108 | if ((cpu->cfg.ext_zvbb || cpu->cfg.ext_zvkb || cpu->cfg.ext_zvkg || | ||
109 | cpu->cfg.ext_zvkned || cpu->cfg.ext_zvknha || cpu->cfg.ext_zvksed || | ||
110 | - cpu->cfg.ext_zvksh) && !cpu->cfg.ext_zve32f) { | ||
111 | + cpu->cfg.ext_zvksh) && !cpu->cfg.ext_zve32x) { | ||
112 | error_setg(errp, | ||
113 | "Vector crypto extensions require V or Zve* extensions"); | ||
114 | return; | ||
115 | diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc | ||
116 | index XXXXXXX..XXXXXXX 100644 | ||
117 | --- a/target/riscv/insn_trans/trans_rvv.c.inc | ||
118 | +++ b/target/riscv/insn_trans/trans_rvv.c.inc | ||
119 | @@ -XXX,XX +XXX,XX @@ static bool do_vsetvl(DisasContext *s, int rd, int rs1, TCGv s2) | ||
120 | { | ||
121 | TCGv s1, dst; | ||
122 | |||
123 | - if (!require_rvv(s) || !s->cfg_ptr->ext_zve32f) { | ||
124 | + if (!require_rvv(s) || !s->cfg_ptr->ext_zve32x) { | ||
125 | return false; | ||
48 | } | 126 | } |
49 | 127 | ||
50 | /* The Zve64f extension depends on the Zve32f extension */ | 128 | @@ -XXX,XX +XXX,XX @@ static bool do_vsetivli(DisasContext *s, int rd, TCGv s1, TCGv s2) |
51 | if (cpu->cfg.ext_zve64f) { | 129 | { |
52 | - cpu->cfg.ext_zve32f = true; | 130 | TCGv dst; |
53 | + cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zve32f), true); | 131 | |
132 | - if (!require_rvv(s) || !s->cfg_ptr->ext_zve32f) { | ||
133 | + if (!require_rvv(s) || !s->cfg_ptr->ext_zve32x) { | ||
134 | return false; | ||
54 | } | 135 | } |
55 | 136 | ||
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 | -- | 137 | -- |
135 | 2.41.0 | 138 | 2.45.1 | diff view generated by jsdifflib |
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 1 | From: Jason Chien <jason.chien@sifive.com> |
---|---|---|---|
2 | 2 | ||
3 | At this moment there are eleven CPU extension properties that starts | 3 | Add support for Zve64x extension. Enabling Zve64f enables Zve64x and |
4 | with capital 'Z': Zifencei, Zicsr, Zihintntl, Zihintpause, Zawrs, Zfa, | 4 | enabling Zve64x enables Zve32x according to their dependency. |
5 | Zfh, Zfhmin, Zve32f, Zve64f and Zve64d. All other extensions are named | ||
6 | with lower-case letters. | ||
7 | 5 | ||
8 | We want all properties to be named with lower-case letters since it's | 6 | Resolves: https://gitlab.com/qemu-project/qemu/-/issues/2107 |
9 | consistent with the riscv-isa string that we create in the FDT. Having | 7 | Signed-off-by: Jason Chien <jason.chien@sifive.com> |
10 | these 11 properties to be exceptions can be confusing. | 8 | Reviewed-by: Frank Chang <frank.chang@sifive.com> |
11 | 9 | Reviewed-by: Max Chou <max.chou@sifive.com> | |
12 | Deprecate all of them. Create their lower-case counterpart to be used as | 10 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
13 | maintained CPU properties. When trying to use any deprecated property a | 11 | Message-ID: <20240328022343.6871-3-jason.chien@sifive.com> |
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> | ||
24 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
25 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> | ||
26 | Message-ID: <20231009112817.8896-2-dbarboza@ventanamicro.com> | ||
27 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 12 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
28 | --- | 13 | --- |
29 | docs/about/deprecated.rst | 23 ++++++++++++++++++++++ | 14 | target/riscv/cpu_cfg.h | 1 + |
30 | target/riscv/cpu.h | 1 + | 15 | target/riscv/cpu.c | 2 ++ |
31 | target/riscv/cpu.c | 39 +++++++++++++++++++++++++++----------- | 16 | target/riscv/tcg/tcg-cpu.c | 17 +++++++++++------ |
32 | target/riscv/tcg/tcg-cpu.c | 31 +++++++++++++++++++++++++++++- | 17 | 3 files changed, 14 insertions(+), 6 deletions(-) |
33 | 4 files changed, 82 insertions(+), 12 deletions(-) | ||
34 | 18 | ||
35 | diff --git a/docs/about/deprecated.rst b/docs/about/deprecated.rst | 19 | diff --git a/target/riscv/cpu_cfg.h b/target/riscv/cpu_cfg.h |
36 | index XXXXXXX..XXXXXXX 100644 | 20 | index XXXXXXX..XXXXXXX 100644 |
37 | --- a/docs/about/deprecated.rst | 21 | --- a/target/riscv/cpu_cfg.h |
38 | +++ b/docs/about/deprecated.rst | 22 | +++ b/target/riscv/cpu_cfg.h |
39 | @@ -XXX,XX +XXX,XX @@ of generic CPUs: rv32 and rv64 as default CPUs and 'max' as a feature complete | 23 | @@ -XXX,XX +XXX,XX @@ struct RISCVCPUConfig { |
40 | CPU for both 32 and 64 bit builds. Users are then discouraged to use the 'any' | 24 | bool ext_zve32x; |
41 | CPU type starting in 8.2. | 25 | bool ext_zve64f; |
42 | 26 | bool ext_zve64d; | |
43 | +RISC-V CPU properties which start with capital 'Z' (since 8.2) | 27 | + bool ext_zve64x; |
44 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | 28 | bool ext_zvbb; |
45 | + | 29 | bool ext_zvbc; |
46 | +All RISC-V CPU properties which start with capital 'Z' are being deprecated | 30 | bool ext_zvkb; |
47 | +starting in 8.2. The reason is that they were wrongly added with capital 'Z' | ||
48 | +in the past. CPU properties were later added with lower-case names, which | ||
49 | +is the format we want to use from now on. | ||
50 | + | ||
51 | +Users which try to use these deprecated properties will receive a warning | ||
52 | +recommending to switch to their stable counterparts: | ||
53 | + | ||
54 | +- "Zifencei" should be replaced with "zifencei" | ||
55 | +- "Zicsr" should be replaced with "zicsr" | ||
56 | +- "Zihintntl" should be replaced with "zihintntl" | ||
57 | +- "Zihintpause" should be replaced with "zihintpause" | ||
58 | +- "Zawrs" should be replaced with "zawrs" | ||
59 | +- "Zfa" should be replaced with "zfa" | ||
60 | +- "Zfh" should be replaced with "zfh" | ||
61 | +- "Zfhmin" should be replaced with "zfhmin" | ||
62 | +- "Zve32f" should be replaced with "zve32f" | ||
63 | +- "Zve64f" should be replaced with "zve64f" | ||
64 | +- "Zve64d" should be replaced with "zve64d" | ||
65 | + | ||
66 | Block device options | ||
67 | '''''''''''''''''''' | ||
68 | |||
69 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h | ||
70 | index XXXXXXX..XXXXXXX 100644 | ||
71 | --- a/target/riscv/cpu.h | ||
72 | +++ b/target/riscv/cpu.h | ||
73 | @@ -XXX,XX +XXX,XX @@ typedef struct RISCVCPUMultiExtConfig { | ||
74 | extern const RISCVCPUMultiExtConfig riscv_cpu_extensions[]; | ||
75 | extern const RISCVCPUMultiExtConfig riscv_cpu_vendor_exts[]; | ||
76 | extern const RISCVCPUMultiExtConfig riscv_cpu_experimental_exts[]; | ||
77 | +extern const RISCVCPUMultiExtConfig riscv_cpu_deprecated_exts[]; | ||
78 | extern Property riscv_cpu_options[]; | ||
79 | |||
80 | typedef struct isa_ext_data { | ||
81 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | 31 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c |
82 | index XXXXXXX..XXXXXXX 100644 | 32 | index XXXXXXX..XXXXXXX 100644 |
83 | --- a/target/riscv/cpu.c | 33 | --- a/target/riscv/cpu.c |
84 | +++ b/target/riscv/cpu.c | 34 | +++ b/target/riscv/cpu.c |
85 | @@ -XXX,XX +XXX,XX @@ const char *riscv_get_misa_ext_description(uint32_t bit) | 35 | @@ -XXX,XX +XXX,XX @@ const RISCVIsaExtData isa_edata_arr[] = { |
86 | const RISCVCPUMultiExtConfig riscv_cpu_extensions[] = { | 36 | ISA_EXT_DATA_ENTRY(zve32x, PRIV_VERSION_1_10_0, ext_zve32x), |
87 | /* Defaults for standard extensions */ | 37 | ISA_EXT_DATA_ENTRY(zve64f, PRIV_VERSION_1_10_0, ext_zve64f), |
88 | MULTI_EXT_CFG_BOOL("sscofpmf", ext_sscofpmf, false), | 38 | ISA_EXT_DATA_ENTRY(zve64d, PRIV_VERSION_1_10_0, ext_zve64d), |
89 | - MULTI_EXT_CFG_BOOL("Zifencei", ext_ifencei, true), | 39 | + ISA_EXT_DATA_ENTRY(zve64x, PRIV_VERSION_1_10_0, ext_zve64x), |
90 | - MULTI_EXT_CFG_BOOL("Zicsr", ext_icsr, true), | 40 | ISA_EXT_DATA_ENTRY(zvfbfmin, PRIV_VERSION_1_12_0, ext_zvfbfmin), |
91 | - MULTI_EXT_CFG_BOOL("Zihintntl", ext_zihintntl, true), | 41 | ISA_EXT_DATA_ENTRY(zvfbfwma, PRIV_VERSION_1_12_0, ext_zvfbfwma), |
92 | - MULTI_EXT_CFG_BOOL("Zihintpause", ext_zihintpause, true), | 42 | ISA_EXT_DATA_ENTRY(zvfh, PRIV_VERSION_1_12_0, ext_zvfh), |
93 | - MULTI_EXT_CFG_BOOL("Zawrs", ext_zawrs, true), | 43 | @@ -XXX,XX +XXX,XX @@ const RISCVCPUMultiExtConfig riscv_cpu_extensions[] = { |
94 | - MULTI_EXT_CFG_BOOL("Zfa", ext_zfa, true), | 44 | MULTI_EXT_CFG_BOOL("zve32x", ext_zve32x, false), |
95 | - MULTI_EXT_CFG_BOOL("Zfh", ext_zfh, false), | 45 | MULTI_EXT_CFG_BOOL("zve64f", ext_zve64f, false), |
96 | - MULTI_EXT_CFG_BOOL("Zfhmin", ext_zfhmin, false), | 46 | MULTI_EXT_CFG_BOOL("zve64d", ext_zve64d, false), |
97 | - MULTI_EXT_CFG_BOOL("Zve32f", ext_zve32f, false), | 47 | + MULTI_EXT_CFG_BOOL("zve64x", ext_zve64x, false), |
98 | - MULTI_EXT_CFG_BOOL("Zve64f", ext_zve64f, false), | 48 | MULTI_EXT_CFG_BOOL("zvfbfmin", ext_zvfbfmin, false), |
99 | - MULTI_EXT_CFG_BOOL("Zve64d", ext_zve64d, false), | 49 | MULTI_EXT_CFG_BOOL("zvfbfwma", ext_zvfbfwma, false), |
100 | + MULTI_EXT_CFG_BOOL("zifencei", ext_ifencei, true), | 50 | MULTI_EXT_CFG_BOOL("zvfh", ext_zvfh, false), |
101 | + MULTI_EXT_CFG_BOOL("zicsr", ext_icsr, true), | ||
102 | + MULTI_EXT_CFG_BOOL("zihintntl", ext_zihintntl, true), | ||
103 | + MULTI_EXT_CFG_BOOL("zihintpause", ext_zihintpause, true), | ||
104 | + MULTI_EXT_CFG_BOOL("zawrs", ext_zawrs, true), | ||
105 | + MULTI_EXT_CFG_BOOL("zfa", ext_zfa, true), | ||
106 | + MULTI_EXT_CFG_BOOL("zfh", ext_zfh, false), | ||
107 | + MULTI_EXT_CFG_BOOL("zfhmin", ext_zfhmin, false), | ||
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(), | ||
116 | }; | ||
117 | |||
118 | +/* Deprecated entries marked for future removal */ | ||
119 | +const RISCVCPUMultiExtConfig riscv_cpu_deprecated_exts[] = { | ||
120 | + MULTI_EXT_CFG_BOOL("Zifencei", ext_ifencei, true), | ||
121 | + MULTI_EXT_CFG_BOOL("Zicsr", ext_icsr, true), | ||
122 | + MULTI_EXT_CFG_BOOL("Zihintntl", ext_zihintntl, true), | ||
123 | + MULTI_EXT_CFG_BOOL("Zihintpause", ext_zihintpause, true), | ||
124 | + MULTI_EXT_CFG_BOOL("Zawrs", ext_zawrs, true), | ||
125 | + MULTI_EXT_CFG_BOOL("Zfa", ext_zfa, true), | ||
126 | + MULTI_EXT_CFG_BOOL("Zfh", ext_zfh, false), | ||
127 | + MULTI_EXT_CFG_BOOL("Zfhmin", ext_zfhmin, false), | ||
128 | + MULTI_EXT_CFG_BOOL("Zve32f", ext_zve32f, false), | ||
129 | + MULTI_EXT_CFG_BOOL("Zve64f", ext_zve64f, false), | ||
130 | + MULTI_EXT_CFG_BOOL("Zve64d", ext_zve64d, false), | ||
131 | + | ||
132 | + DEFINE_PROP_END_OF_LIST(), | ||
133 | +}; | ||
134 | + | ||
135 | Property riscv_cpu_options[] = { | ||
136 | DEFINE_PROP_UINT8("pmu-num", RISCVCPU, cfg.pmu_num, 16), | ||
137 | |||
138 | diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c | 51 | diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c |
139 | index XXXXXXX..XXXXXXX 100644 | 52 | index XXXXXXX..XXXXXXX 100644 |
140 | --- a/target/riscv/tcg/tcg-cpu.c | 53 | --- a/target/riscv/tcg/tcg-cpu.c |
141 | +++ b/target/riscv/tcg/tcg-cpu.c | 54 | +++ b/target/riscv/tcg/tcg-cpu.c |
142 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_add_misa_properties(Object *cpu_obj) | 55 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp) |
56 | |||
57 | /* The Zve64d extension depends on the Zve64f extension */ | ||
58 | if (cpu->cfg.ext_zve64d) { | ||
59 | + if (!riscv_has_ext(env, RVD)) { | ||
60 | + error_setg(errp, "Zve64d/V extensions require D extension"); | ||
61 | + return; | ||
62 | + } | ||
63 | cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zve64f), true); | ||
143 | } | 64 | } |
144 | } | 65 | |
145 | 66 | - /* The Zve64f extension depends on the Zve32f extension */ | |
146 | +static bool cpu_ext_is_deprecated(const char *ext_name) | 67 | + /* The Zve64f extension depends on the Zve64x and Zve32f extensions */ |
147 | +{ | 68 | if (cpu->cfg.ext_zve64f) { |
148 | + return isupper(ext_name[0]); | 69 | + cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zve64x), true); |
149 | +} | 70 | cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zve32f), true); |
150 | + | 71 | } |
151 | +/* | 72 | |
152 | + * String will be allocated in the heap. Caller is responsible | 73 | - if (cpu->cfg.ext_zve64d && !riscv_has_ext(env, RVD)) { |
153 | + * for freeing it. | 74 | - error_setg(errp, "Zve64d/V extensions require D extension"); |
154 | + */ | 75 | - return; |
155 | +static char *cpu_ext_to_lower(const char *ext_name) | 76 | + /* The Zve64x extension depends on the Zve32x extension */ |
156 | +{ | 77 | + if (cpu->cfg.ext_zve64x) { |
157 | + char *ret = g_malloc0(strlen(ext_name) + 1); | 78 | + cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zve32x), true); |
158 | + | 79 | } |
159 | + strcpy(ret, ext_name); | 80 | |
160 | + ret[0] = tolower(ret[0]); | 81 | /* The Zve32f extension depends on the Zve32x extension */ |
161 | + | 82 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp) |
162 | + return ret; | ||
163 | +} | ||
164 | + | ||
165 | static void cpu_set_multi_ext_cfg(Object *obj, Visitor *v, const char *name, | ||
166 | void *opaque, Error **errp) | ||
167 | { | ||
168 | @@ -XXX,XX +XXX,XX @@ static void cpu_set_multi_ext_cfg(Object *obj, Visitor *v, const char *name, | ||
169 | return; | 83 | return; |
170 | } | 84 | } |
171 | 85 | ||
172 | + if (cpu_ext_is_deprecated(multi_ext_cfg->name)) { | 86 | - if ((cpu->cfg.ext_zvbc || cpu->cfg.ext_zvknhb) && !cpu->cfg.ext_zve64f) { |
173 | + g_autofree char *lower = cpu_ext_to_lower(multi_ext_cfg->name); | 87 | + if ((cpu->cfg.ext_zvbc || cpu->cfg.ext_zvknhb) && !cpu->cfg.ext_zve64x) { |
174 | + | 88 | error_setg( |
175 | + warn_report("CPU property '%s' is deprecated. Please use '%s' instead", | 89 | errp, |
176 | + multi_ext_cfg->name, lower); | 90 | - "Zvbc and Zvknhb extensions require V or Zve64{f,d} extensions"); |
177 | + } | 91 | + "Zvbc and Zvknhb extensions require V or Zve64x extensions"); |
178 | + | ||
179 | g_hash_table_insert(multi_ext_user_opts, | ||
180 | GUINT_TO_POINTER(multi_ext_cfg->offset), | ||
181 | (gpointer)value); | ||
182 | @@ -XXX,XX +XXX,XX @@ static void cpu_add_multi_ext_prop(Object *cpu_obj, | ||
183 | const RISCVCPUMultiExtConfig *multi_cfg) | ||
184 | { | ||
185 | bool generic_cpu = riscv_cpu_is_generic(cpu_obj); | ||
186 | + bool deprecated_ext = cpu_ext_is_deprecated(multi_cfg->name); | ||
187 | |||
188 | object_property_add(cpu_obj, multi_cfg->name, "bool", | ||
189 | cpu_get_multi_ext_cfg, | ||
190 | cpu_set_multi_ext_cfg, | ||
191 | NULL, (void *)multi_cfg); | ||
192 | |||
193 | - if (!generic_cpu) { | ||
194 | + if (!generic_cpu || deprecated_ext) { | ||
195 | return; | 92 | return; |
196 | } | 93 | } |
197 | 94 | ||
198 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_add_user_properties(Object *obj) | ||
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 | } | ||
207 | -- | 95 | -- |
208 | 2.41.0 | 96 | 2.45.1 | diff view generated by jsdifflib |
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 1 | From: Jason Chien <jason.chien@sifive.com> |
---|---|---|---|
2 | 2 | ||
3 | Vendor CPUs that set RVG are displaying user warnings about other | 3 | In current implementation, the gdbstub allows reading vector registers |
4 | extensions that RVG must enable, one warning per CPU. E.g.: | 4 | only if V extension is supported. However, all vector extensions and |
5 | vector crypto extensions have the vector registers and they all depend | ||
6 | on Zve32x. The gdbstub should check for Zve32x instead. | ||
5 | 7 | ||
6 | $ ./build/qemu-system-riscv64 -smp 8 -M virt -cpu veyron-v1 -nographic | 8 | Signed-off-by: Jason Chien <jason.chien@sifive.com> |
7 | qemu-system-riscv64: warning: Setting G will also set IMAFD_Zicsr_Zifencei | 9 | Reviewed-by: Frank Chang <frank.chang@sifive.com> |
8 | qemu-system-riscv64: warning: Setting G will also set IMAFD_Zicsr_Zifencei | 10 | Reviewed-by: Max Chou <max.chou@sifive.com> |
9 | qemu-system-riscv64: warning: Setting G will also set IMAFD_Zicsr_Zifencei | 11 | Message-ID: <20240328022343.6871-4-jason.chien@sifive.com> |
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> | 12 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
46 | --- | 13 | --- |
47 | target/riscv/tcg/tcg-cpu.c | 1 - | 14 | target/riscv/gdbstub.c | 2 +- |
48 | 1 file changed, 1 deletion(-) | 15 | 1 file changed, 1 insertion(+), 1 deletion(-) |
49 | 16 | ||
50 | diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c | 17 | diff --git a/target/riscv/gdbstub.c b/target/riscv/gdbstub.c |
51 | index XXXXXXX..XXXXXXX 100644 | 18 | index XXXXXXX..XXXXXXX 100644 |
52 | --- a/target/riscv/tcg/tcg-cpu.c | 19 | --- a/target/riscv/gdbstub.c |
53 | +++ b/target/riscv/tcg/tcg-cpu.c | 20 | +++ b/target/riscv/gdbstub.c |
54 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp) | 21 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_register_gdb_regs_for_features(CPUState *cs) |
55 | return; | 22 | gdb_find_static_feature("riscv-32bit-fpu.xml"), |
56 | } | 23 | 0); |
57 | 24 | } | |
58 | - warn_report("Setting G will also set IMAFD_Zicsr_Zifencei"); | 25 | - if (env->misa_ext & RVV) { |
59 | cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_icsr), true); | 26 | + if (cpu->cfg.ext_zve32x) { |
60 | cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_ifencei), true); | 27 | gdb_register_coprocessor(cs, riscv_gdb_get_vector, |
61 | 28 | riscv_gdb_set_vector, | |
29 | ricsv_gen_dynamic_vector_feature(cs, cs->gdb_num_regs), | ||
62 | -- | 30 | -- |
63 | 2.41.0 | 31 | 2.45.1 | diff view generated by jsdifflib |
1 | From: Clément Chigot <chigot@adacore.com> | 1 | From: Huang Tao <eric.huang@linux.alibaba.com> |
---|---|---|---|
2 | 2 | ||
3 | This replaces the exit calls by shutdown requests, ensuring a proper | 3 | In RVV and vcrypto instructions, the masked and tail elements are set to 1s |
4 | cleanup of Qemu. Features like net/vhost-vdpa.c are expecting | 4 | using vext_set_elems_1s function if the vma/vta bit is set. It is the element |
5 | qemu_cleanup to be called to remove their last residuals. | 5 | agnostic policy. |
6 | 6 | ||
7 | Signed-off-by: Clément Chigot <chigot@adacore.com> | 7 | However, this function can't deal the big endian situation. This patch fixes |
8 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 8 | the problem by adding handling of such case. |
9 | Message-ID: <20231003071427.188697-6-chigot@adacore.com> | 9 | |
10 | Signed-off-by: Huang Tao <eric.huang@linux.alibaba.com> | ||
11 | Suggested-by: Richard Henderson <richard.henderson@linaro.org> | ||
12 | Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com> | ||
13 | Cc: qemu-stable <qemu-stable@nongnu.org> | ||
14 | Message-ID: <20240325021654.6594-1-eric.huang@linux.alibaba.com> | ||
10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 15 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
11 | --- | 16 | --- |
12 | include/gdbstub/syscalls.h | 9 +++++++++ | 17 | target/riscv/vector_internals.c | 22 ++++++++++++++++++++++ |
13 | gdbstub/gdbstub.c | 5 +++-- | 18 | 1 file changed, 22 insertions(+) |
14 | gdbstub/system.c | 6 ++++++ | ||
15 | gdbstub/user.c | 6 ++++++ | ||
16 | 4 files changed, 24 insertions(+), 2 deletions(-) | ||
17 | 19 | ||
18 | diff --git a/include/gdbstub/syscalls.h b/include/gdbstub/syscalls.h | 20 | diff --git a/target/riscv/vector_internals.c b/target/riscv/vector_internals.c |
19 | index XXXXXXX..XXXXXXX 100644 | 21 | index XXXXXXX..XXXXXXX 100644 |
20 | --- a/include/gdbstub/syscalls.h | 22 | --- a/target/riscv/vector_internals.c |
21 | +++ b/include/gdbstub/syscalls.h | 23 | +++ b/target/riscv/vector_internals.c |
22 | @@ -XXX,XX +XXX,XX @@ int use_gdb_syscalls(void); | 24 | @@ -XXX,XX +XXX,XX @@ void vext_set_elems_1s(void *base, uint32_t is_agnostic, uint32_t cnt, |
23 | */ | 25 | if (tot - cnt == 0) { |
24 | void gdb_exit(int code); | 26 | return ; |
25 | |||
26 | +/** | ||
27 | + * gdb_qemu_exit: ask qemu to exit | ||
28 | + * @code: exit code reported | ||
29 | + * | ||
30 | + * This requests qemu to exit. This function is allowed to return as | ||
31 | + * the exit request might be processed asynchronously by qemu backend. | ||
32 | + */ | ||
33 | +void gdb_qemu_exit(int code); | ||
34 | + | ||
35 | #endif /* _SYSCALLS_H_ */ | ||
36 | diff --git a/gdbstub/gdbstub.c b/gdbstub/gdbstub.c | ||
37 | index XXXXXXX..XXXXXXX 100644 | ||
38 | --- a/gdbstub/gdbstub.c | ||
39 | +++ b/gdbstub/gdbstub.c | ||
40 | @@ -XXX,XX +XXX,XX @@ static void handle_v_kill(GArray *params, void *user_ctx) | ||
41 | gdb_put_packet("OK"); | ||
42 | error_report("QEMU: Terminated via GDBstub"); | ||
43 | gdb_exit(0); | ||
44 | - exit(0); | ||
45 | + gdb_qemu_exit(0); | ||
46 | } | ||
47 | |||
48 | static const GdbCmdParseEntry gdb_v_commands_table[] = { | ||
49 | @@ -XXX,XX +XXX,XX @@ static int gdb_handle_packet(const char *line_buf) | ||
50 | /* Kill the target */ | ||
51 | error_report("QEMU: Terminated via GDBstub"); | ||
52 | gdb_exit(0); | ||
53 | - exit(0); | ||
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) | ||
68 | +{ | ||
69 | + qemu_system_shutdown_request_with_code(SHUTDOWN_CAUSE_GUEST_SHUTDOWN, | ||
70 | + code); | ||
71 | +} | ||
72 | + | ||
73 | /* | ||
74 | * Memory access | ||
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 | } | 27 | } |
84 | + | 28 | + |
85 | +} | 29 | + if (HOST_BIG_ENDIAN) { |
86 | + | 30 | + /* |
87 | +void gdb_qemu_exit(int code) | 31 | + * Deal the situation when the elements are insdie |
88 | +{ | 32 | + * only one uint64 block including setting the |
89 | + exit(code); | 33 | + * masked-off element. |
34 | + */ | ||
35 | + if (((tot - 1) ^ cnt) < 8) { | ||
36 | + memset(base + H1(tot - 1), -1, tot - cnt); | ||
37 | + return; | ||
38 | + } | ||
39 | + /* | ||
40 | + * Otherwise, at least cross two uint64_t blocks. | ||
41 | + * Set first unaligned block. | ||
42 | + */ | ||
43 | + if (cnt % 8 != 0) { | ||
44 | + uint32_t j = ROUND_UP(cnt, 8); | ||
45 | + memset(base + H1(j - 1), -1, j - cnt); | ||
46 | + cnt = j; | ||
47 | + } | ||
48 | + /* Set other 64bit aligend blocks */ | ||
49 | + } | ||
50 | memset(base + cnt, -1, tot - cnt); | ||
90 | } | 51 | } |
91 | 52 | ||
92 | int gdb_handlesig(CPUState *cpu, int sig) | ||
93 | -- | 53 | -- |
94 | 2.41.0 | 54 | 2.45.1 |
95 | |||
96 | diff view generated by jsdifflib |
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 1 | From: Yangyu Chen <cyy@cyyself.name> |
---|---|---|---|
2 | 2 | ||
3 | This CPU only exists if we're compiling with KVM so move it to the kvm | 3 | This code has a typo that writes zvkb to zvkg, causing users can't |
4 | specific file. | 4 | enable zvkb through the config. This patch gets this fixed. |
5 | 5 | ||
6 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 6 | Signed-off-by: Yangyu Chen <cyy@cyyself.name> |
7 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | 7 | Fixes: ea61ef7097d0 ("target/riscv: Move vector crypto extensions to riscv_cpu_extensions") |
8 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> | ||
9 | Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com> | 8 | Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com> |
10 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 9 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
11 | Message-ID: <20230925175709.35696-7-dbarboza@ventanamicro.com> | 10 | Reviewed-by: Max Chou <max.chou@sifive.com> |
11 | Reviewed-by: Weiwei Li <liwei1518@gmail.com> | ||
12 | Message-ID: <tencent_7E34EEF0F90B9A68BF38BEE09EC6D4877C0A@qq.com> | ||
13 | Cc: qemu-stable <qemu-stable@nongnu.org> | ||
12 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 14 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
13 | --- | 15 | --- |
14 | target/riscv/cpu.c | 15 --------------- | 16 | target/riscv/cpu.c | 2 +- |
15 | target/riscv/kvm.c | 21 +++++++++++++++++++++ | 17 | 1 file changed, 1 insertion(+), 1 deletion(-) |
16 | 2 files changed, 21 insertions(+), 15 deletions(-) | ||
17 | 18 | ||
18 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | 19 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c |
19 | index XXXXXXX..XXXXXXX 100644 | 20 | index XXXXXXX..XXXXXXX 100644 |
20 | --- a/target/riscv/cpu.c | 21 | --- a/target/riscv/cpu.c |
21 | +++ b/target/riscv/cpu.c | 22 | +++ b/target/riscv/cpu.c |
22 | @@ -XXX,XX +XXX,XX @@ static void rv32_imafcu_nommu_cpu_init(Object *obj) | 23 | @@ -XXX,XX +XXX,XX @@ const RISCVCPUMultiExtConfig riscv_cpu_extensions[] = { |
23 | } | 24 | /* Vector cryptography extensions */ |
24 | #endif | 25 | MULTI_EXT_CFG_BOOL("zvbb", ext_zvbb, false), |
25 | 26 | MULTI_EXT_CFG_BOOL("zvbc", ext_zvbc, false), | |
26 | -#if defined(CONFIG_KVM) | 27 | - MULTI_EXT_CFG_BOOL("zvkb", ext_zvkg, false), |
27 | -static void riscv_host_cpu_init(Object *obj) | 28 | + MULTI_EXT_CFG_BOOL("zvkb", ext_zvkb, false), |
28 | -{ | 29 | MULTI_EXT_CFG_BOOL("zvkg", ext_zvkg, false), |
29 | - CPURISCVState *env = &RISCV_CPU(obj)->env; | 30 | MULTI_EXT_CFG_BOOL("zvkned", ext_zvkned, false), |
30 | -#if defined(TARGET_RISCV32) | 31 | MULTI_EXT_CFG_BOOL("zvknha", ext_zvknha, false), |
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) | ||
61 | +{ | ||
62 | + CPURISCVState *env = &RISCV_CPU(obj)->env; | ||
63 | + | ||
64 | +#if defined(TARGET_RISCV32) | ||
65 | + env->misa_mxl_max = env->misa_mxl = MXL_RV32; | ||
66 | +#elif defined(TARGET_RISCV64) | ||
67 | + env->misa_mxl_max = env->misa_mxl = MXL_RV64; | ||
68 | +#endif | ||
69 | +} | ||
70 | + | ||
71 | +static const TypeInfo riscv_kvm_cpu_type_infos[] = { | ||
72 | + { | ||
73 | + .name = TYPE_RISCV_CPU_HOST, | ||
74 | + .parent = TYPE_RISCV_CPU, | ||
75 | + .instance_init = riscv_host_cpu_init, | ||
76 | + } | ||
77 | +}; | ||
78 | + | ||
79 | +DEFINE_TYPES(riscv_kvm_cpu_type_infos) | ||
80 | -- | 32 | -- |
81 | 2.41.0 | 33 | 2.45.1 |
82 | 34 | ||
83 | 35 | diff view generated by jsdifflib |
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 1 | From: Huang Tao <eric.huang@linux.alibaba.com> |
---|---|---|---|
2 | 2 | ||
3 | All code related to MISA TCG properties is also moved. | 3 | In this patch, we modify the decoder to be a freely composable data |
4 | structure instead of a hardcoded one. It can be dynamically builded up | ||
5 | according to the extensions. | ||
6 | This approach has several benefits: | ||
7 | 1. Provides support for heterogeneous cpu architectures. As we add decoder in | ||
8 | RISCVCPU, each cpu can have their own decoder, and the decoders can be | ||
9 | different due to cpu's features. | ||
10 | 2. Improve the decoding efficiency. We run the guard_func to see if the decoder | ||
11 | can be added to the dynamic_decoder when building up the decoder. Therefore, | ||
12 | there is no need to run the guard_func when decoding each instruction. It can | ||
13 | improve the decoding efficiency | ||
14 | 3. For vendor or dynamic cpus, it allows them to customize their own decoder | ||
15 | functions to improve decoding efficiency, especially when vendor-defined | ||
16 | instruction sets increase. Because of dynamic building up, it can skip the other | ||
17 | decoder guard functions when decoding. | ||
18 | 4. Pre patch for allowing adding a vendor decoder before decode_insn32() with minimal | ||
19 | overhead for users that don't need this particular vendor decoder. | ||
4 | 20 | ||
5 | At this point, all TCG properties handling is done in tcg-cpu.c, all KVM | 21 | Signed-off-by: Huang Tao <eric.huang@linux.alibaba.com> |
6 | properties handling is done in kvm-cpu.c. | 22 | Suggested-by: Christoph Muellner <christoph.muellner@vrull.eu> |
7 | 23 | Co-authored-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com> | |
8 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 24 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> |
9 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> | ||
10 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 25 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
11 | Message-ID: <20230925175709.35696-18-dbarboza@ventanamicro.com> | 26 | Message-ID: <20240506023607.29544-1-eric.huang@linux.alibaba.com> |
12 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 27 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
13 | --- | 28 | --- |
14 | target/riscv/cpu.h | 1 - | 29 | target/riscv/cpu.h | 1 + |
15 | target/riscv/cpu.c | 90 -------------------------------------- | 30 | target/riscv/tcg/tcg-cpu.h | 15 +++++++++++++++ |
16 | target/riscv/tcg/tcg-cpu.c | 90 ++++++++++++++++++++++++++++++++++++++ | 31 | target/riscv/cpu.c | 1 + |
17 | 3 files changed, 90 insertions(+), 91 deletions(-) | 32 | target/riscv/tcg/tcg-cpu.c | 15 +++++++++++++++ |
33 | target/riscv/translate.c | 31 +++++++++++++++---------------- | ||
34 | 5 files changed, 47 insertions(+), 16 deletions(-) | ||
18 | 35 | ||
19 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h | 36 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h |
20 | index XXXXXXX..XXXXXXX 100644 | 37 | index XXXXXXX..XXXXXXX 100644 |
21 | --- a/target/riscv/cpu.h | 38 | --- a/target/riscv/cpu.h |
22 | +++ b/target/riscv/cpu.h | 39 | +++ b/target/riscv/cpu.h |
23 | @@ -XXX,XX +XXX,XX @@ extern const RISCVCPUMultiExtConfig riscv_cpu_vendor_exts[]; | 40 | @@ -XXX,XX +XXX,XX @@ struct ArchCPU { |
24 | extern const RISCVCPUMultiExtConfig riscv_cpu_experimental_exts[]; | 41 | uint32_t pmu_avail_ctrs; |
25 | extern Property riscv_cpu_options[]; | 42 | /* Mapping of events to counters */ |
26 | 43 | GHashTable *pmu_event_ctr_map; | |
27 | -void riscv_cpu_add_misa_properties(Object *cpu_obj); | 44 | + const GPtrArray *decoders; |
28 | void riscv_add_satp_mode_properties(Object *obj); | 45 | }; |
29 | 46 | ||
30 | /* CSR function table */ | 47 | /** |
48 | diff --git a/target/riscv/tcg/tcg-cpu.h b/target/riscv/tcg/tcg-cpu.h | ||
49 | index XXXXXXX..XXXXXXX 100644 | ||
50 | --- a/target/riscv/tcg/tcg-cpu.h | ||
51 | +++ b/target/riscv/tcg/tcg-cpu.h | ||
52 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp); | ||
53 | void riscv_tcg_cpu_finalize_features(RISCVCPU *cpu, Error **errp); | ||
54 | bool riscv_cpu_tcg_compatible(RISCVCPU *cpu); | ||
55 | |||
56 | +struct DisasContext; | ||
57 | +struct RISCVCPUConfig; | ||
58 | +typedef struct RISCVDecoder { | ||
59 | + bool (*guard_func)(const struct RISCVCPUConfig *); | ||
60 | + bool (*riscv_cpu_decode_fn)(struct DisasContext *, uint32_t); | ||
61 | +} RISCVDecoder; | ||
62 | + | ||
63 | +typedef bool (*riscv_cpu_decode_fn)(struct DisasContext *, uint32_t); | ||
64 | + | ||
65 | +extern const size_t decoder_table_size; | ||
66 | + | ||
67 | +extern const RISCVDecoder decoder_table[]; | ||
68 | + | ||
69 | +void riscv_tcg_cpu_finalize_dynamic_decoder(RISCVCPU *cpu); | ||
70 | + | ||
71 | #endif | ||
31 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | 72 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c |
32 | index XXXXXXX..XXXXXXX 100644 | 73 | index XXXXXXX..XXXXXXX 100644 |
33 | --- a/target/riscv/cpu.c | 74 | --- a/target/riscv/cpu.c |
34 | +++ b/target/riscv/cpu.c | 75 | +++ b/target/riscv/cpu.c |
35 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_init(Object *obj) | 76 | @@ -XXX,XX +XXX,XX @@ void riscv_cpu_finalize_features(RISCVCPU *cpu, Error **errp) |
36 | #endif /* CONFIG_USER_ONLY */ | 77 | error_propagate(errp, local_err); |
37 | } | 78 | return; |
38 | 79 | } | |
39 | -typedef struct RISCVCPUMisaExtConfig { | 80 | + riscv_tcg_cpu_finalize_dynamic_decoder(cpu); |
40 | - target_ulong misa_bit; | 81 | } else if (kvm_enabled()) { |
41 | - bool enabled; | 82 | riscv_kvm_cpu_finalize_features(cpu, &local_err); |
42 | -} RISCVCPUMisaExtConfig; | 83 | if (local_err != NULL) { |
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 | 84 | diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c |
140 | index XXXXXXX..XXXXXXX 100644 | 85 | index XXXXXXX..XXXXXXX 100644 |
141 | --- a/target/riscv/tcg/tcg-cpu.c | 86 | --- a/target/riscv/tcg/tcg-cpu.c |
142 | +++ b/target/riscv/tcg/tcg-cpu.c | 87 | +++ b/target/riscv/tcg/tcg-cpu.c |
143 | @@ -XXX,XX +XXX,XX @@ static bool tcg_cpu_realize(CPUState *cs, Error **errp) | 88 | @@ -XXX,XX +XXX,XX @@ void riscv_tcg_cpu_finalize_features(RISCVCPU *cpu, Error **errp) |
144 | return true; | 89 | } |
145 | } | 90 | } |
146 | 91 | ||
147 | +typedef struct RISCVCPUMisaExtConfig { | 92 | +void riscv_tcg_cpu_finalize_dynamic_decoder(RISCVCPU *cpu) |
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) | ||
154 | +{ | 93 | +{ |
155 | + const RISCVCPUMisaExtConfig *misa_ext_cfg = opaque; | 94 | + GPtrArray *dynamic_decoders; |
156 | + target_ulong misa_bit = misa_ext_cfg->misa_bit; | 95 | + dynamic_decoders = g_ptr_array_sized_new(decoder_table_size); |
157 | + RISCVCPU *cpu = RISCV_CPU(obj); | 96 | + for (size_t i = 0; i < decoder_table_size; ++i) { |
158 | + CPURISCVState *env = &cpu->env; | 97 | + if (decoder_table[i].guard_func && |
159 | + bool value; | 98 | + decoder_table[i].guard_func(&cpu->cfg)) { |
160 | + | 99 | + g_ptr_array_add(dynamic_decoders, |
161 | + if (!visit_type_bool(v, name, &value, errp)) { | 100 | + (gpointer)decoder_table[i].riscv_cpu_decode_fn); |
162 | + return; | 101 | + } |
163 | + } | 102 | + } |
164 | + | 103 | + |
165 | + if (value) { | 104 | + cpu->decoders = dynamic_decoders; |
166 | + env->misa_ext |= misa_bit; | ||
167 | + env->misa_ext_mask |= misa_bit; | ||
168 | + } else { | ||
169 | + env->misa_ext &= ~misa_bit; | ||
170 | + env->misa_ext_mask &= ~misa_bit; | ||
171 | + } | ||
172 | +} | 105 | +} |
173 | + | 106 | + |
174 | +static void cpu_get_misa_ext_cfg(Object *obj, Visitor *v, const char *name, | 107 | bool riscv_cpu_tcg_compatible(RISCVCPU *cpu) |
175 | + void *opaque, Error **errp) | 108 | { |
176 | +{ | 109 | return object_dynamic_cast(OBJECT(cpu), TYPE_RISCV_CPU_HOST) == NULL; |
177 | + const RISCVCPUMisaExtConfig *misa_ext_cfg = opaque; | 110 | diff --git a/target/riscv/translate.c b/target/riscv/translate.c |
178 | + target_ulong misa_bit = misa_ext_cfg->misa_bit; | 111 | index XXXXXXX..XXXXXXX 100644 |
179 | + RISCVCPU *cpu = RISCV_CPU(obj); | 112 | --- a/target/riscv/translate.c |
180 | + CPURISCVState *env = &cpu->env; | 113 | +++ b/target/riscv/translate.c |
181 | + bool value; | 114 | @@ -XXX,XX +XXX,XX @@ |
115 | #include "exec/helper-info.c.inc" | ||
116 | #undef HELPER_H | ||
117 | |||
118 | +#include "tcg/tcg-cpu.h" | ||
182 | + | 119 | + |
183 | + value = env->misa_ext & misa_bit; | 120 | /* global register indices */ |
184 | + | 121 | static TCGv cpu_gpr[32], cpu_gprh[32], cpu_pc, cpu_vl, cpu_vstart; |
185 | + visit_type_bool(v, name, &value, errp); | 122 | static TCGv_i64 cpu_fpr[32]; /* assume F and D extensions */ |
186 | +} | 123 | @@ -XXX,XX +XXX,XX @@ typedef struct DisasContext { |
187 | + | 124 | /* FRM is known to contain a valid value. */ |
188 | +#define MISA_CFG(_bit, _enabled) \ | 125 | bool frm_valid; |
189 | + {.misa_bit = _bit, .enabled = _enabled} | 126 | bool insn_start_updated; |
190 | + | 127 | + const GPtrArray *decoders; |
191 | +static const RISCVCPUMisaExtConfig misa_ext_cfgs[] = { | 128 | } DisasContext; |
192 | + MISA_CFG(RVA, true), | 129 | |
193 | + MISA_CFG(RVC, true), | 130 | static inline bool has_ext(DisasContext *ctx, uint32_t ext) |
194 | + MISA_CFG(RVD, true), | 131 | @@ -XXX,XX +XXX,XX @@ static inline int insn_len(uint16_t first_word) |
195 | + MISA_CFG(RVF, true), | 132 | return (first_word & 3) == 3 ? 4 : 2; |
196 | + MISA_CFG(RVI, true), | 133 | } |
197 | + MISA_CFG(RVE, false), | 134 | |
198 | + MISA_CFG(RVM, true), | 135 | +const RISCVDecoder decoder_table[] = { |
199 | + MISA_CFG(RVS, true), | 136 | + { always_true_p, decode_insn32 }, |
200 | + MISA_CFG(RVU, true), | 137 | + { has_xthead_p, decode_xthead}, |
201 | + MISA_CFG(RVH, true), | 138 | + { has_XVentanaCondOps_p, decode_XVentanaCodeOps}, |
202 | + MISA_CFG(RVJ, false), | ||
203 | + MISA_CFG(RVV, false), | ||
204 | + MISA_CFG(RVG, false), | ||
205 | +}; | 139 | +}; |
206 | + | 140 | + |
207 | +/* | 141 | +const size_t decoder_table_size = ARRAY_SIZE(decoder_table); |
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) | ||
214 | +{ | ||
215 | + int i; | ||
216 | + | 142 | + |
217 | + for (i = 0; i < ARRAY_SIZE(misa_ext_cfgs); i++) { | 143 | static void decode_opc(CPURISCVState *env, DisasContext *ctx, uint16_t opcode) |
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 | + } | ||
235 | +} | ||
236 | + | ||
237 | static void cpu_set_multi_ext_cfg(Object *obj, Visitor *v, const char *name, | ||
238 | void *opaque, Error **errp) | ||
239 | { | 144 | { |
145 | - /* | ||
146 | - * A table with predicate (i.e., guard) functions and decoder functions | ||
147 | - * that are tested in-order until a decoder matches onto the opcode. | ||
148 | - */ | ||
149 | - static const struct { | ||
150 | - bool (*guard_func)(const RISCVCPUConfig *); | ||
151 | - bool (*decode_func)(DisasContext *, uint32_t); | ||
152 | - } decoders[] = { | ||
153 | - { always_true_p, decode_insn32 }, | ||
154 | - { has_xthead_p, decode_xthead }, | ||
155 | - { has_XVentanaCondOps_p, decode_XVentanaCodeOps }, | ||
156 | - }; | ||
157 | - | ||
158 | ctx->virt_inst_excp = false; | ||
159 | ctx->cur_insn_len = insn_len(opcode); | ||
160 | /* Check for compressed insn */ | ||
161 | @@ -XXX,XX +XXX,XX @@ static void decode_opc(CPURISCVState *env, DisasContext *ctx, uint16_t opcode) | ||
162 | ctx->base.pc_next + 2)); | ||
163 | ctx->opcode = opcode32; | ||
164 | |||
165 | - for (size_t i = 0; i < ARRAY_SIZE(decoders); ++i) { | ||
166 | - if (decoders[i].guard_func(ctx->cfg_ptr) && | ||
167 | - decoders[i].decode_func(ctx, opcode32)) { | ||
168 | + for (guint i = 0; i < ctx->decoders->len; ++i) { | ||
169 | + riscv_cpu_decode_fn func = g_ptr_array_index(ctx->decoders, i); | ||
170 | + if (func(ctx, opcode32)) { | ||
171 | return; | ||
172 | } | ||
173 | } | ||
174 | @@ -XXX,XX +XXX,XX @@ static void riscv_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) | ||
175 | ctx->itrigger = FIELD_EX32(tb_flags, TB_FLAGS, ITRIGGER); | ||
176 | ctx->zero = tcg_constant_tl(0); | ||
177 | ctx->virt_inst_excp = false; | ||
178 | + ctx->decoders = cpu->decoders; | ||
179 | } | ||
180 | |||
181 | static void riscv_tr_tb_start(DisasContextBase *db, CPUState *cpu) | ||
240 | -- | 182 | -- |
241 | 2.41.0 | 183 | 2.45.1 | diff view generated by jsdifflib |
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 1 | From: Christoph Müllner <christoph.muellner@vrull.eu> |
---|---|---|---|
2 | 2 | ||
3 | target/riscv/cpu.c needs to handle all possible accelerators (TCG and | 3 | The th.sxstatus CSR can be used to identify available custom extension |
4 | KVM at this moment) during both init() and realize() time. This forces | 4 | on T-Head CPUs. The CSR is documented here: |
5 | us to resort to a lot of "if tcg" and "if kvm" throughout the code, | 5 | https://github.com/T-head-Semi/thead-extension-spec/blob/master/xtheadsxstatus.adoc |
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. | ||
10 | 6 | ||
11 | We'll start by adding a new subdir called 'tcg' and a new file called | 7 | An important property of this patch is, that the th.sxstatus MAEE field |
12 | 'tcg-cpu.c'. This file will be used to introduce a new accelerator class | 8 | is not set (indicating that XTheadMae is not available). |
13 | for TCG acceleration in RISC-V, allowing us to center all TCG exclusive | 9 | XTheadMae is a memory attribute extension (similar to Svpbmt) which is |
14 | code in its file instead of using 'cpu.c' for everything. This design is | 10 | implemented in many T-Head CPUs (C906, C910, etc.) and utilizes bits |
15 | inpired by the work Claudio Fontana did in x86 a few years ago in commit | 11 | in PTEs that are marked as reserved. QEMU maintainers prefer to not |
16 | f5cc5a5c1 ("i386: split cpu accelerators from cpu.c, using | 12 | implement XTheadMae, so we need give kernels a mechanism to identify |
17 | AccelCPUClass"). | 13 | if XTheadMae is available in a system or not. And this patch introduces |
14 | this mechanism in QEMU in a way that's compatible with real HW | ||
15 | (i.e., probing the th.sxstatus.MAEE bit). | ||
18 | 16 | ||
19 | To avoid moving too much code at once we'll start by adding the new file | 17 | Further context can be found on the list: |
20 | and TCG AccelCPUClass declaration. The 'class_init' from the accel class | 18 | https://lists.gnu.org/archive/html/qemu-devel/2024-02/msg00775.html |
21 | will init 'tcg_ops', relieving the common riscv_cpu_class_init() from | ||
22 | doing it. | ||
23 | 19 | ||
24 | 'riscv_tcg_ops' is being exported from 'cpu.c' for now to avoid having | 20 | Reviewed-by: LIU Zhiwei <zhiwe_liu@linux.alibaba.com> |
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> | ||
31 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 21 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
32 | Message-ID: <20230925175709.35696-2-dbarboza@ventanamicro.com> | 22 | Signed-off-by: Christoph Müllner <christoph.muellner@vrull.eu> |
23 | Message-ID: <20240429073656.2486732-1-christoph.muellner@vrull.eu> | ||
33 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 24 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
34 | --- | 25 | --- |
35 | target/riscv/cpu.h | 4 +++ | 26 | MAINTAINERS | 1 + |
36 | target/riscv/cpu.c | 5 +--- | 27 | target/riscv/cpu.h | 3 ++ |
37 | target/riscv/tcg/tcg-cpu.c | 58 ++++++++++++++++++++++++++++++++++++ | 28 | target/riscv/cpu.c | 1 + |
38 | target/riscv/meson.build | 2 ++ | 29 | target/riscv/th_csr.c | 79 ++++++++++++++++++++++++++++++++++++++++ |
39 | target/riscv/tcg/meson.build | 2 ++ | 30 | target/riscv/meson.build | 1 + |
40 | 5 files changed, 67 insertions(+), 4 deletions(-) | 31 | 5 files changed, 85 insertions(+) |
41 | create mode 100644 target/riscv/tcg/tcg-cpu.c | 32 | create mode 100644 target/riscv/th_csr.c |
42 | create mode 100644 target/riscv/tcg/meson.build | ||
43 | 33 | ||
34 | diff --git a/MAINTAINERS b/MAINTAINERS | ||
35 | index XXXXXXX..XXXXXXX 100644 | ||
36 | --- a/MAINTAINERS | ||
37 | +++ b/MAINTAINERS | ||
38 | @@ -XXX,XX +XXX,XX @@ L: qemu-riscv@nongnu.org | ||
39 | S: Supported | ||
40 | F: target/riscv/insn_trans/trans_xthead.c.inc | ||
41 | F: target/riscv/xthead*.decode | ||
42 | +F: target/riscv/th_* | ||
43 | F: disas/riscv-xthead* | ||
44 | |||
45 | RISC-V XVentanaCondOps extension | ||
44 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h | 46 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h |
45 | index XXXXXXX..XXXXXXX 100644 | 47 | index XXXXXXX..XXXXXXX 100644 |
46 | --- a/target/riscv/cpu.h | 48 | --- a/target/riscv/cpu.h |
47 | +++ b/target/riscv/cpu.h | 49 | +++ b/target/riscv/cpu.h |
48 | @@ -XXX,XX +XXX,XX @@ enum riscv_pmu_event_idx { | 50 | @@ -XXX,XX +XXX,XX @@ target_ulong riscv_new_csr_seed(target_ulong new_value, |
49 | RISCV_PMU_EVENT_CACHE_ITLB_PREFETCH_MISS = 0x10021, | 51 | uint8_t satp_mode_max_from_map(uint32_t map); |
50 | }; | 52 | const char *satp_mode_str(uint8_t satp_mode, bool is_32_bit); |
51 | 53 | ||
52 | +/* Export tcg_ops until we move everything to tcg/tcg-cpu.c */ | 54 | +/* Implemented in th_csr.c */ |
53 | +#include "hw/core/tcg-cpu-ops.h" | 55 | +void th_register_custom_csrs(RISCVCPU *cpu); |
54 | +extern const struct TCGCPUOps riscv_tcg_ops; | ||
55 | + | 56 | + |
56 | /* CSR function table */ | 57 | #endif /* RISCV_CPU_H */ |
57 | extern riscv_csr_operations csr_ops[CSR_TABLE_SIZE]; | ||
58 | |||
59 | 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 |
60 | index XXXXXXX..XXXXXXX 100644 | 59 | index XXXXXXX..XXXXXXX 100644 |
61 | --- a/target/riscv/cpu.c | 60 | --- a/target/riscv/cpu.c |
62 | +++ b/target/riscv/cpu.c | 61 | +++ b/target/riscv/cpu.c |
63 | @@ -XXX,XX +XXX,XX @@ static const struct SysemuCPUOps riscv_sysemu_ops = { | 62 | @@ -XXX,XX +XXX,XX @@ static void rv64_thead_c906_cpu_init(Object *obj) |
64 | }; | 63 | cpu->cfg.mvendorid = THEAD_VENDOR_ID; |
64 | #ifndef CONFIG_USER_ONLY | ||
65 | set_satp_mode_max_supported(cpu, VM_1_10_SV39); | ||
66 | + th_register_custom_csrs(cpu); | ||
65 | #endif | 67 | #endif |
66 | 68 | ||
67 | -#include "hw/core/tcg-cpu-ops.h" | 69 | /* inherited from parent obj via riscv_cpu_init() */ |
68 | - | 70 | diff --git a/target/riscv/th_csr.c b/target/riscv/th_csr.c |
69 | -static const struct TCGCPUOps riscv_tcg_ops = { | ||
70 | +const struct TCGCPUOps riscv_tcg_ops = { | ||
71 | .initialize = riscv_translate_init, | ||
72 | .synchronize_from_tb = riscv_cpu_synchronize_from_tb, | ||
73 | .restore_state_to_opc = riscv_restore_state_to_opc, | ||
74 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_class_init(ObjectClass *c, void *data) | ||
75 | #endif | ||
76 | cc->gdb_arch_name = riscv_gdb_arch_name; | ||
77 | cc->gdb_get_dynamic_xml = riscv_gdb_get_dynamic_xml; | ||
78 | - cc->tcg_ops = &riscv_tcg_ops; | ||
79 | |||
80 | object_class_property_add(c, "mvendorid", "uint32", cpu_get_mvendorid, | ||
81 | cpu_set_mvendorid, NULL, NULL); | ||
82 | diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c | ||
83 | new file mode 100644 | 71 | new file mode 100644 |
84 | index XXXXXXX..XXXXXXX | 72 | index XXXXXXX..XXXXXXX |
85 | --- /dev/null | 73 | --- /dev/null |
86 | +++ b/target/riscv/tcg/tcg-cpu.c | 74 | +++ b/target/riscv/th_csr.c |
87 | @@ -XXX,XX +XXX,XX @@ | 75 | @@ -XXX,XX +XXX,XX @@ |
88 | +/* | 76 | +/* |
89 | + * riscv TCG cpu class initialization | 77 | + * T-Head-specific CSRs. |
90 | + * | 78 | + * |
91 | + * Copyright (c) 2016-2017 Sagar Karandikar, sagark@eecs.berkeley.edu | 79 | + * Copyright (c) 2024 VRULL GmbH |
92 | + * Copyright (c) 2017-2018 SiFive, Inc. | ||
93 | + * | 80 | + * |
94 | + * This program is free software; you can redistribute it and/or modify it | 81 | + * This program is free software; you can redistribute it and/or modify it |
95 | + * under the terms and conditions of the GNU General Public License, | 82 | + * under the terms and conditions of the GNU General Public License, |
96 | + * version 2 or later, as published by the Free Software Foundation. | 83 | + * version 2 or later, as published by the Free Software Foundation. |
97 | + * | 84 | + * |
... | ... | ||
104 | + * this program. If not, see <http://www.gnu.org/licenses/>. | 91 | + * this program. If not, see <http://www.gnu.org/licenses/>. |
105 | + */ | 92 | + */ |
106 | + | 93 | + |
107 | +#include "qemu/osdep.h" | 94 | +#include "qemu/osdep.h" |
108 | +#include "cpu.h" | 95 | +#include "cpu.h" |
109 | +#include "qemu/accel.h" | 96 | +#include "cpu_vendorid.h" |
110 | +#include "hw/core/accel-cpu.h" | ||
111 | + | 97 | + |
112 | +static void tcg_cpu_init_ops(AccelCPUClass *accel_cpu, CPUClass *cc) | 98 | +#define CSR_TH_SXSTATUS 0x5c0 |
99 | + | ||
100 | +/* TH_SXSTATUS bits */ | ||
101 | +#define TH_SXSTATUS_UCME BIT(16) | ||
102 | +#define TH_SXSTATUS_MAEE BIT(21) | ||
103 | +#define TH_SXSTATUS_THEADISAEE BIT(22) | ||
104 | + | ||
105 | +typedef struct { | ||
106 | + int csrno; | ||
107 | + int (*insertion_test)(RISCVCPU *cpu); | ||
108 | + riscv_csr_operations csr_ops; | ||
109 | +} riscv_csr; | ||
110 | + | ||
111 | +static RISCVException smode(CPURISCVState *env, int csrno) | ||
113 | +{ | 112 | +{ |
114 | + /* | 113 | + if (riscv_has_ext(env, RVS)) { |
115 | + * All cpus use the same set of operations. | 114 | + return RISCV_EXCP_NONE; |
116 | + * riscv_tcg_ops is being imported from cpu.c for now. | 115 | + } |
117 | + */ | 116 | + |
118 | + cc->tcg_ops = &riscv_tcg_ops; | 117 | + return RISCV_EXCP_ILLEGAL_INST; |
119 | +} | 118 | +} |
120 | + | 119 | + |
121 | +static void tcg_cpu_class_init(CPUClass *cc) | 120 | +static int test_thead_mvendorid(RISCVCPU *cpu) |
122 | +{ | 121 | +{ |
123 | + cc->init_accel_cpu = tcg_cpu_init_ops; | 122 | + if (cpu->cfg.mvendorid != THEAD_VENDOR_ID) { |
123 | + return -1; | ||
124 | + } | ||
125 | + | ||
126 | + return 0; | ||
124 | +} | 127 | +} |
125 | + | 128 | + |
126 | +static void tcg_cpu_accel_class_init(ObjectClass *oc, void *data) | 129 | +static RISCVException read_th_sxstatus(CPURISCVState *env, int csrno, |
130 | + target_ulong *val) | ||
127 | +{ | 131 | +{ |
128 | + AccelCPUClass *acc = ACCEL_CPU_CLASS(oc); | 132 | + /* We don't set MAEE here, because QEMU does not implement MAEE. */ |
129 | + | 133 | + *val = TH_SXSTATUS_UCME | TH_SXSTATUS_THEADISAEE; |
130 | + acc->cpu_class_init = tcg_cpu_class_init; | 134 | + return RISCV_EXCP_NONE; |
131 | +} | 135 | +} |
132 | + | 136 | + |
133 | +static const TypeInfo tcg_cpu_accel_type_info = { | 137 | +static riscv_csr th_csr_list[] = { |
134 | + .name = ACCEL_CPU_NAME("tcg"), | 138 | + { |
135 | + | 139 | + .csrno = CSR_TH_SXSTATUS, |
136 | + .parent = TYPE_ACCEL_CPU, | 140 | + .insertion_test = test_thead_mvendorid, |
137 | + .class_init = tcg_cpu_accel_class_init, | 141 | + .csr_ops = { "th.sxstatus", smode, read_th_sxstatus } |
138 | + .abstract = true, | 142 | + } |
139 | +}; | 143 | +}; |
140 | + | 144 | + |
141 | +static void tcg_cpu_accel_register_types(void) | 145 | +void th_register_custom_csrs(RISCVCPU *cpu) |
142 | +{ | 146 | +{ |
143 | + type_register_static(&tcg_cpu_accel_type_info); | 147 | + for (size_t i = 0; i < ARRAY_SIZE(th_csr_list); i++) { |
148 | + int csrno = th_csr_list[i].csrno; | ||
149 | + riscv_csr_operations *csr_ops = &th_csr_list[i].csr_ops; | ||
150 | + if (!th_csr_list[i].insertion_test(cpu)) { | ||
151 | + riscv_set_csr_ops(csrno, csr_ops); | ||
152 | + } | ||
153 | + } | ||
144 | +} | 154 | +} |
145 | +type_init(tcg_cpu_accel_register_types); | ||
146 | diff --git a/target/riscv/meson.build b/target/riscv/meson.build | 155 | diff --git a/target/riscv/meson.build b/target/riscv/meson.build |
147 | index XXXXXXX..XXXXXXX 100644 | 156 | index XXXXXXX..XXXXXXX 100644 |
148 | --- a/target/riscv/meson.build | 157 | --- a/target/riscv/meson.build |
149 | +++ b/target/riscv/meson.build | 158 | +++ b/target/riscv/meson.build |
150 | @@ -XXX,XX +XXX,XX @@ riscv_system_ss.add(files( | 159 | @@ -XXX,XX +XXX,XX @@ riscv_system_ss.add(files( |
160 | 'monitor.c', | ||
161 | 'machine.c', | ||
162 | 'pmu.c', | ||
163 | + 'th_csr.c', | ||
164 | 'time_helper.c', | ||
151 | 'riscv-qmp-cmds.c', | 165 | 'riscv-qmp-cmds.c', |
152 | )) | 166 | )) |
153 | |||
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')) | ||
166 | -- | 167 | -- |
167 | 2.41.0 | 168 | 2.45.1 |
169 | |||
170 | diff view generated by jsdifflib |
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 1 | From: Max Chou <max.chou@sifive.com> |
---|---|---|---|
2 | 2 | ||
3 | Priv spec validation is TCG specific. Move it to the TCG accel class. | 3 | According v spec 18.4, only the vfwcvt.f.f.v and vfncvt.f.f.w |
4 | instructions will be affected by Zvfhmin extension. | ||
5 | And the vfwcvt.f.f.v and vfncvt.f.f.w instructions only support the | ||
6 | conversions of | ||
4 | 7 | ||
5 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 8 | * From 1*SEW(16/32) to 2*SEW(32/64) |
6 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> | 9 | * From 2*SEW(32/64) to 1*SEW(16/32) |
7 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 10 | |
8 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | 11 | Signed-off-by: Max Chou <max.chou@sifive.com> |
9 | Message-ID: <20230925175709.35696-20-dbarboza@ventanamicro.com> | 12 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
13 | Cc: qemu-stable <qemu-stable@nongnu.org> | ||
14 | Message-ID: <20240322092600.1198921-2-max.chou@sifive.com> | ||
10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 15 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
11 | --- | 16 | --- |
12 | target/riscv/cpu.h | 2 -- | 17 | target/riscv/insn_trans/trans_rvv.c.inc | 20 ++++++++++++++++++-- |
13 | target/riscv/cpu.c | 38 -------------------------------------- | 18 | 1 file changed, 18 insertions(+), 2 deletions(-) |
14 | target/riscv/tcg/tcg-cpu.c | 38 ++++++++++++++++++++++++++++++++++++++ | ||
15 | 3 files changed, 38 insertions(+), 40 deletions(-) | ||
16 | 19 | ||
17 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h | 20 | diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc |
18 | index XXXXXXX..XXXXXXX 100644 | 21 | index XXXXXXX..XXXXXXX 100644 |
19 | --- a/target/riscv/cpu.h | 22 | --- a/target/riscv/insn_trans/trans_rvv.c.inc |
20 | +++ b/target/riscv/cpu.h | 23 | +++ b/target/riscv/insn_trans/trans_rvv.c.inc |
21 | @@ -XXX,XX +XXX,XX @@ enum riscv_pmu_event_idx { | 24 | @@ -XXX,XX +XXX,XX @@ static bool require_rvf(DisasContext *s) |
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; | ||
37 | } | ||
38 | |||
39 | -int cpu_cfg_ext_get_min_version(uint32_t ext_offset) | ||
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 | } | 25 | } |
59 | } | 26 | } |
60 | 27 | ||
61 | -void riscv_cpu_disable_priv_spec_isa_exts(RISCVCPU *cpu) | 28 | +static bool require_rvfmin(DisasContext *s) |
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) | ||
96 | +{ | 29 | +{ |
97 | + const RISCVIsaExtData *edata; | 30 | + if (s->mstatus_fs == EXT_STATUS_DISABLED) { |
98 | + | 31 | + return false; |
99 | + for (edata = isa_edata_arr; edata && edata->name; edata++) { | ||
100 | + if (edata->ext_enable_offset != ext_offset) { | ||
101 | + continue; | ||
102 | + } | ||
103 | + | ||
104 | + return edata->min_version; | ||
105 | + } | 32 | + } |
106 | + | 33 | + |
107 | + g_assert_not_reached(); | 34 | + switch (s->sew) { |
108 | +} | 35 | + case MO_16: |
109 | + | 36 | + return s->cfg_ptr->ext_zvfhmin; |
110 | static void cpu_cfg_ext_auto_update(RISCVCPU *cpu, uint32_t ext_offset, | 37 | + case MO_32: |
111 | bool value) | 38 | + return s->cfg_ptr->ext_zve32f; |
112 | { | 39 | + default: |
113 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_validate_v(CPURISCVState *env, RISCVCPUConfig *cfg, | 40 | + return false; |
114 | } | ||
115 | } | ||
116 | |||
117 | +static void riscv_cpu_disable_priv_spec_isa_exts(RISCVCPU *cpu) | ||
118 | +{ | ||
119 | + CPURISCVState *env = &cpu->env; | ||
120 | + const RISCVIsaExtData *edata; | ||
121 | + | ||
122 | + /* Force disable extensions if priv spec version does not match */ | ||
123 | + for (edata = isa_edata_arr; edata && edata->name; edata++) { | ||
124 | + if (isa_ext_is_enabled(cpu, edata->ext_enable_offset) && | ||
125 | + (env->priv_ver < edata->min_version)) { | ||
126 | + isa_ext_update_enabled(cpu, edata->ext_enable_offset, false); | ||
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 | ||
136 | + } | ||
137 | + } | 41 | + } |
138 | +} | 42 | +} |
139 | + | 43 | + |
140 | /* | 44 | static bool require_scale_rvf(DisasContext *s) |
141 | * Check consistency between chosen extensions while setting | 45 | { |
142 | * cpu->cfg accordingly. | 46 | if (s->mstatus_fs == EXT_STATUS_DISABLED) { |
47 | @@ -XXX,XX +XXX,XX @@ static bool require_scale_rvfmin(DisasContext *s) | ||
48 | } | ||
49 | |||
50 | switch (s->sew) { | ||
51 | - case MO_8: | ||
52 | - return s->cfg_ptr->ext_zvfhmin; | ||
53 | case MO_16: | ||
54 | return s->cfg_ptr->ext_zve32f; | ||
55 | case MO_32: | ||
56 | @@ -XXX,XX +XXX,XX @@ static bool opxfv_widen_check(DisasContext *s, arg_rmr *a) | ||
57 | static bool opffv_widen_check(DisasContext *s, arg_rmr *a) | ||
58 | { | ||
59 | return opfv_widen_check(s, a) && | ||
60 | + require_rvfmin(s) && | ||
61 | require_scale_rvfmin(s) && | ||
62 | (s->sew != MO_8); | ||
63 | } | ||
64 | @@ -XXX,XX +XXX,XX @@ static bool opfxv_narrow_check(DisasContext *s, arg_rmr *a) | ||
65 | static bool opffv_narrow_check(DisasContext *s, arg_rmr *a) | ||
66 | { | ||
67 | return opfv_narrow_check(s, a) && | ||
68 | + require_rvfmin(s) && | ||
69 | require_scale_rvfmin(s) && | ||
70 | (s->sew != MO_8); | ||
71 | } | ||
143 | -- | 72 | -- |
144 | 2.41.0 | 73 | 2.45.1 |
145 | |||
146 | diff view generated by jsdifflib |
1 | From: Max Chou <max.chou@sifive.com> | 1 | From: Max Chou <max.chou@sifive.com> |
---|---|---|---|
2 | 2 | ||
3 | The operator (fwmacc16) of vfwmaccbf16.vf helper function should be | 3 | The require_scale_rvf function only checks the double width operator for |
4 | replaced by fwmaccbf16. | 4 | the vector floating point widen instructions, so most of the widen |
5 | checking functions need to add require_rvf for single width operator. | ||
5 | 6 | ||
6 | Fixes: adf772b0f7 ("target/riscv: Add support for Zvfbfwma extension") | 7 | The vfwcvt.f.x.v and vfwcvt.f.xu.v instructions convert single width |
8 | integer to double width float, so the opfxv_widen_check function doesn’t | ||
9 | need require_rvf for the single width operator(integer). | ||
10 | |||
7 | Signed-off-by: Max Chou <max.chou@sifive.com> | 11 | Signed-off-by: Max Chou <max.chou@sifive.com> |
8 | Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com> | 12 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
9 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | 13 | Cc: qemu-stable <qemu-stable@nongnu.org> |
10 | Message-ID: <20231005095734.567575-1-max.chou@sifive.com> | 14 | Message-ID: <20240322092600.1198921-3-max.chou@sifive.com> |
11 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 15 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
12 | --- | 16 | --- |
13 | target/riscv/vector_helper.c | 2 +- | 17 | target/riscv/insn_trans/trans_rvv.c.inc | 5 +++++ |
14 | 1 file changed, 1 insertion(+), 1 deletion(-) | 18 | 1 file changed, 5 insertions(+) |
15 | 19 | ||
16 | diff --git a/target/riscv/vector_helper.c b/target/riscv/vector_helper.c | 20 | diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc |
17 | index XXXXXXX..XXXXXXX 100644 | 21 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/target/riscv/vector_helper.c | 22 | --- a/target/riscv/insn_trans/trans_rvv.c.inc |
19 | +++ b/target/riscv/vector_helper.c | 23 | +++ b/target/riscv/insn_trans/trans_rvv.c.inc |
20 | @@ -XXX,XX +XXX,XX @@ static uint32_t fwmaccbf16(uint16_t a, uint16_t b, uint32_t d, float_status *s) | 24 | @@ -XXX,XX +XXX,XX @@ GEN_OPFVF_TRANS(vfrsub_vf, opfvf_check) |
21 | 25 | static bool opfvv_widen_check(DisasContext *s, arg_rmrr *a) | |
22 | RVVCALL(OPFVV3, vfwmaccbf16_vv, WOP_UUU_H, H4, H2, H2, fwmaccbf16) | 26 | { |
23 | GEN_VEXT_VV_ENV(vfwmaccbf16_vv, 4) | 27 | return require_rvv(s) && |
24 | -RVVCALL(OPFVF3, vfwmaccbf16_vf, WOP_UUU_H, H4, H2, fwmacc16) | 28 | + require_rvf(s) && |
25 | +RVVCALL(OPFVF3, vfwmaccbf16_vf, WOP_UUU_H, H4, H2, fwmaccbf16) | 29 | require_scale_rvf(s) && |
26 | GEN_VEXT_VF(vfwmaccbf16_vf, 4) | 30 | (s->sew != MO_8) && |
27 | 31 | vext_check_isa_ill(s) && | |
28 | static uint32_t fwnmacc16(uint16_t a, uint16_t b, uint32_t d, float_status *s) | 32 | @@ -XXX,XX +XXX,XX @@ GEN_OPFVV_WIDEN_TRANS(vfwsub_vv, opfvv_widen_check) |
33 | static bool opfvf_widen_check(DisasContext *s, arg_rmrr *a) | ||
34 | { | ||
35 | return require_rvv(s) && | ||
36 | + require_rvf(s) && | ||
37 | require_scale_rvf(s) && | ||
38 | (s->sew != MO_8) && | ||
39 | vext_check_isa_ill(s) && | ||
40 | @@ -XXX,XX +XXX,XX @@ GEN_OPFVF_WIDEN_TRANS(vfwsub_vf) | ||
41 | static bool opfwv_widen_check(DisasContext *s, arg_rmrr *a) | ||
42 | { | ||
43 | return require_rvv(s) && | ||
44 | + require_rvf(s) && | ||
45 | require_scale_rvf(s) && | ||
46 | (s->sew != MO_8) && | ||
47 | vext_check_isa_ill(s) && | ||
48 | @@ -XXX,XX +XXX,XX @@ GEN_OPFWV_WIDEN_TRANS(vfwsub_wv) | ||
49 | static bool opfwf_widen_check(DisasContext *s, arg_rmrr *a) | ||
50 | { | ||
51 | return require_rvv(s) && | ||
52 | + require_rvf(s) && | ||
53 | require_scale_rvf(s) && | ||
54 | (s->sew != MO_8) && | ||
55 | vext_check_isa_ill(s) && | ||
56 | @@ -XXX,XX +XXX,XX @@ GEN_OPFVV_TRANS(vfredmin_vs, freduction_check) | ||
57 | static bool freduction_widen_check(DisasContext *s, arg_rmrr *a) | ||
58 | { | ||
59 | return reduction_widen_check(s, a) && | ||
60 | + require_rvf(s) && | ||
61 | require_scale_rvf(s) && | ||
62 | (s->sew != MO_8); | ||
63 | } | ||
29 | -- | 64 | -- |
30 | 2.41.0 | 65 | 2.45.1 |
31 | 66 | ||
32 | 67 | diff view generated by jsdifflib |
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 1 | From: Max Chou <max.chou@sifive.com> |
---|---|---|---|
2 | 2 | ||
3 | Future patches will split the existing Property arrays even further, and | 3 | The opfv_narrow_check needs to check the single width float operator by |
4 | the existing code in riscv_cpu_add_user_properties() will start to scale | 4 | require_rvf. |
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 | 5 | ||
9 | Create a new kvm_riscv_cpu_add_kvm_properties() helper that will be | 6 | Signed-off-by: Max Chou <max.chou@sifive.com> |
10 | forked from riscv_cpu_add_user_properties() if we're running KVM. The | 7 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
11 | helper includes all properties that a KVM CPU will add. The rest of | 8 | Cc: qemu-stable <qemu-stable@nongnu.org> |
12 | riscv_cpu_add_user_properties() body will then be relieved from having | 9 | Message-ID: <20240322092600.1198921-4-max.chou@sifive.com> |
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> | 10 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
28 | --- | 11 | --- |
29 | target/riscv/kvm_riscv.h | 3 ++ | 12 | target/riscv/insn_trans/trans_rvv.c.inc | 1 + |
30 | target/riscv/cpu.c | 65 +++++++++++++++++++++++++--------------- | 13 | 1 file changed, 1 insertion(+) |
31 | 2 files changed, 44 insertions(+), 24 deletions(-) | ||
32 | 14 | ||
33 | diff --git a/target/riscv/kvm_riscv.h b/target/riscv/kvm_riscv.h | 15 | diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc |
34 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
35 | --- a/target/riscv/kvm_riscv.h | 17 | --- a/target/riscv/insn_trans/trans_rvv.c.inc |
36 | +++ b/target/riscv/kvm_riscv.h | 18 | +++ b/target/riscv/insn_trans/trans_rvv.c.inc |
37 | @@ -XXX,XX +XXX,XX @@ | 19 | @@ -XXX,XX +XXX,XX @@ static bool opffv_narrow_check(DisasContext *s, arg_rmr *a) |
38 | #ifndef QEMU_KVM_RISCV_H | 20 | static bool opffv_rod_narrow_check(DisasContext *s, arg_rmr *a) |
39 | #define QEMU_KVM_RISCV_H | 21 | { |
40 | 22 | return opfv_narrow_check(s, a) && | |
41 | +/* Temporarily implemented in cpu.c */ | 23 | + require_rvf(s) && |
42 | +void kvm_riscv_cpu_add_kvm_properties(Object *obj); | 24 | require_scale_rvf(s) && |
43 | + | 25 | (s->sew != MO_8); |
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 | } | 26 | } |
147 | -- | 27 | -- |
148 | 2.41.0 | 28 | 2.45.1 | diff view generated by jsdifflib |
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 1 | From: Max Chou <max.chou@sifive.com> |
---|---|---|---|
2 | 2 | ||
3 | If we want to make better decisions when auto-enabling extensions during | 3 | If the checking functions check both the single and double width |
4 | realize() we need a way to tell if an user set an extension manually. | 4 | operators at the same time, then the single width operator checking |
5 | The RISC-V KVM driver has its own solution via a KVMCPUConfig struct | 5 | functions (require_rvf[min]) will check whether the SEW is 8. |
6 | that has an 'user_set' flag that is set during the Property set() | ||
7 | callback. The set() callback also does init() time validations based on | ||
8 | the current KVM driver capabilities. | ||
9 | 6 | ||
10 | For TCG we would want a 'user_set' mechanic too, but we would look | 7 | Signed-off-by: Max Chou <max.chou@sifive.com> |
11 | ad-hoc via cpu_cfg_ext_auto_update() if a certain extension was user set | 8 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
12 | or not. If we copy what was made in the KVM side we would look for | 9 | Cc: qemu-stable <qemu-stable@nongnu.org> |
13 | 'user_set' for one into 60+ extension structs spreaded in 3 arrays | 10 | Message-ID: <20240322092600.1198921-5-max.chou@sifive.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> | ||
37 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
38 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> | ||
39 | Message-ID: <20230912132423.268494-18-dbarboza@ventanamicro.com> | ||
40 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 11 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
41 | --- | 12 | --- |
42 | target/riscv/cpu.c | 258 ++++++++++++++++++++++++++++----------------- | 13 | target/riscv/insn_trans/trans_rvv.c.inc | 16 ++++------------ |
43 | 1 file changed, 159 insertions(+), 99 deletions(-) | 14 | 1 file changed, 4 insertions(+), 12 deletions(-) |
44 | 15 | ||
45 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | 16 | diff --git a/target/riscv/insn_trans/trans_rvv.c.inc b/target/riscv/insn_trans/trans_rvv.c.inc |
46 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
47 | --- a/target/riscv/cpu.c | 18 | --- a/target/riscv/insn_trans/trans_rvv.c.inc |
48 | +++ b/target/riscv/cpu.c | 19 | +++ b/target/riscv/insn_trans/trans_rvv.c.inc |
49 | @@ -XXX,XX +XXX,XX @@ static const struct isa_ext_data isa_edata_arr[] = { | 20 | @@ -XXX,XX +XXX,XX @@ static bool opfvv_widen_check(DisasContext *s, arg_rmrr *a) |
50 | ISA_EXT_DATA_ENTRY(xventanacondops, PRIV_VERSION_1_12_0, ext_XVentanaCondOps), | 21 | return require_rvv(s) && |
51 | }; | 22 | require_rvf(s) && |
52 | 23 | require_scale_rvf(s) && | |
53 | +/* Hash that stores user set extensions */ | 24 | - (s->sew != MO_8) && |
54 | +static GHashTable *multi_ext_user_opts; | 25 | vext_check_isa_ill(s) && |
55 | + | 26 | vext_check_dss(s, a->rd, a->rs1, a->rs2, a->vm); |
56 | static bool isa_ext_is_enabled(RISCVCPU *cpu, uint32_t ext_offset) | 27 | } |
28 | @@ -XXX,XX +XXX,XX @@ static bool opfvf_widen_check(DisasContext *s, arg_rmrr *a) | ||
29 | return require_rvv(s) && | ||
30 | require_rvf(s) && | ||
31 | require_scale_rvf(s) && | ||
32 | - (s->sew != MO_8) && | ||
33 | vext_check_isa_ill(s) && | ||
34 | vext_check_ds(s, a->rd, a->rs2, a->vm); | ||
35 | } | ||
36 | @@ -XXX,XX +XXX,XX @@ static bool opfwv_widen_check(DisasContext *s, arg_rmrr *a) | ||
37 | return require_rvv(s) && | ||
38 | require_rvf(s) && | ||
39 | require_scale_rvf(s) && | ||
40 | - (s->sew != MO_8) && | ||
41 | vext_check_isa_ill(s) && | ||
42 | vext_check_dds(s, a->rd, a->rs1, a->rs2, a->vm); | ||
43 | } | ||
44 | @@ -XXX,XX +XXX,XX @@ static bool opfwf_widen_check(DisasContext *s, arg_rmrr *a) | ||
45 | return require_rvv(s) && | ||
46 | require_rvf(s) && | ||
47 | require_scale_rvf(s) && | ||
48 | - (s->sew != MO_8) && | ||
49 | vext_check_isa_ill(s) && | ||
50 | vext_check_dd(s, a->rd, a->rs2, a->vm); | ||
51 | } | ||
52 | @@ -XXX,XX +XXX,XX @@ static bool opffv_widen_check(DisasContext *s, arg_rmr *a) | ||
57 | { | 53 | { |
58 | bool *ext_enabled = (void *)&cpu->cfg + ext_offset; | 54 | return opfv_widen_check(s, a) && |
59 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_init(Object *obj) | 55 | require_rvfmin(s) && |
60 | qdev_init_gpio_in(DEVICE(obj), riscv_cpu_set_irq, | 56 | - require_scale_rvfmin(s) && |
61 | IRQ_LOCAL_MAX + IRQ_LOCAL_GUEST_MAX); | 57 | - (s->sew != MO_8); |
62 | #endif /* CONFIG_USER_ONLY */ | 58 | + require_scale_rvfmin(s); |
63 | + | ||
64 | + multi_ext_user_opts = g_hash_table_new(NULL, g_direct_equal); | ||
65 | } | 59 | } |
66 | 60 | ||
67 | typedef struct RISCVCPUMisaExtConfig { | 61 | #define GEN_OPFV_WIDEN_TRANS(NAME, CHECK, HELPER, FRM) \ |
68 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_add_misa_properties(Object *cpu_obj) | 62 | @@ -XXX,XX +XXX,XX @@ static bool opffv_narrow_check(DisasContext *s, arg_rmr *a) |
69 | } | 63 | { |
64 | return opfv_narrow_check(s, a) && | ||
65 | require_rvfmin(s) && | ||
66 | - require_scale_rvfmin(s) && | ||
67 | - (s->sew != MO_8); | ||
68 | + require_scale_rvfmin(s); | ||
70 | } | 69 | } |
71 | 70 | ||
72 | -static Property riscv_cpu_extensions[] = { | 71 | static bool opffv_rod_narrow_check(DisasContext *s, arg_rmr *a) |
73 | +typedef struct RISCVCPUMultiExtConfig { | ||
74 | + const char *name; | ||
75 | + uint32_t offset; | ||
76 | + bool enabled; | ||
77 | +} RISCVCPUMultiExtConfig; | ||
78 | + | ||
79 | +#define MULTI_EXT_CFG_BOOL(_name, _prop, _defval) \ | ||
80 | + {.name = _name, .offset = CPU_CFG_OFFSET(_prop), \ | ||
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 | { | 72 | { |
325 | g_assert(array); | 73 | return opfv_narrow_check(s, a) && |
326 | 74 | require_rvf(s) && | |
327 | - for (Property *prop = array; prop && prop->name; prop++) { | 75 | - require_scale_rvf(s) && |
328 | - qdev_property_add_static(dev, prop); | 76 | - (s->sew != MO_8); |
329 | + for (RISCVCPUMultiExtConfig *prop = array; prop && prop->name; prop++) { | 77 | + require_scale_rvf(s); |
330 | + cpu_add_multi_ext_prop(obj, prop); | ||
331 | } | ||
332 | } | 78 | } |
333 | 79 | ||
334 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_add_kvm_unavail_prop(Object *obj, const char *prop_name) | 80 | #define GEN_OPFV_NARROW_TRANS(NAME, CHECK, HELPER, FRM) \ |
81 | @@ -XXX,XX +XXX,XX @@ static bool freduction_widen_check(DisasContext *s, arg_rmrr *a) | ||
82 | { | ||
83 | return reduction_widen_check(s, a) && | ||
84 | require_rvf(s) && | ||
85 | - require_scale_rvf(s) && | ||
86 | - (s->sew != MO_8); | ||
87 | + require_scale_rvf(s); | ||
335 | } | 88 | } |
336 | 89 | ||
337 | static void riscv_cpu_add_kvm_unavail_prop_array(Object *obj, | 90 | GEN_OPFVV_WIDEN_TRANS(vfwredusum_vs, freduction_widen_check) |
338 | - Property *array) | ||
339 | + RISCVCPUMultiExtConfig *array) | ||
340 | { | ||
341 | g_assert(array); | ||
342 | |||
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); | ||
346 | } | ||
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); | ||
384 | -- | 91 | -- |
385 | 2.41.0 | 92 | 2.45.1 | diff view generated by jsdifflib |
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
---|---|---|---|
2 | 2 | ||
3 | This file is not needed for some time now. Both kvm_riscv_reset_vcpu() | 3 | raise_mmu_exception(), as is today, is prioritizing guest page faults by |
4 | and kvm_riscv_set_irq() have public declarations in kvm_riscv.h and are | 4 | checking first if virt_enabled && !first_stage, and then considering the |
5 | wrapped in 'if kvm_enabled()' blocks that the compiler will rip it out | 5 | regular inst/load/store faults. |
6 | in non-KVM builds. | ||
7 | 6 | ||
7 | There's no mention in the spec about guest page fault being a higher | ||
8 | priority that PMP faults. In fact, privileged spec section 3.7.1 says: | ||
9 | |||
10 | "Attempting to fetch an instruction from a PMP region that does not have | ||
11 | execute permissions raises an instruction access-fault exception. | ||
12 | Attempting to execute a load or load-reserved instruction which accesses | ||
13 | a physical address within a PMP region without read permissions raises a | ||
14 | load access-fault exception. Attempting to execute a store, | ||
15 | store-conditional, or AMO instruction which accesses a physical address | ||
16 | within a PMP region without write permissions raises a store | ||
17 | access-fault exception." | ||
18 | |||
19 | So, in fact, we're doing it wrong - PMP faults should always be thrown, | ||
20 | regardless of also being a first or second stage fault. | ||
21 | |||
22 | The way riscv_cpu_tlb_fill() and get_physical_address() work is | ||
23 | adequate: a TRANSLATE_PMP_FAIL error is immediately reported and | ||
24 | reflected in the 'pmp_violation' flag. What we need is to change | ||
25 | raise_mmu_exception() to prioritize it. | ||
26 | |||
27 | Reported-by: Joseph Chan <jchan@ventanamicro.com> | ||
28 | Fixes: 82d53adfbb ("target/riscv/cpu_helper.c: Invalid exception on MMU translation stage") | ||
8 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 29 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
9 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 30 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
10 | Message-ID: <20230925175709.35696-11-dbarboza@ventanamicro.com> | 31 | Message-ID: <20240413105929.7030-1-alexei.filippov@syntacore.com> |
32 | Cc: qemu-stable <qemu-stable@nongnu.org> | ||
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/kvm-stub.c | 30 ------------------------------ | 35 | target/riscv/cpu_helper.c | 22 ++++++++++++---------- |
14 | target/riscv/meson.build | 2 +- | 36 | 1 file changed, 12 insertions(+), 10 deletions(-) |
15 | 2 files changed, 1 insertion(+), 31 deletions(-) | ||
16 | delete mode 100644 target/riscv/kvm-stub.c | ||
17 | 37 | ||
18 | diff --git a/target/riscv/kvm-stub.c b/target/riscv/kvm-stub.c | 38 | diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.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 | 39 | index XXXXXXX..XXXXXXX 100644 |
56 | --- a/target/riscv/meson.build | 40 | --- a/target/riscv/cpu_helper.c |
57 | +++ b/target/riscv/meson.build | 41 | +++ b/target/riscv/cpu_helper.c |
58 | @@ -XXX,XX +XXX,XX @@ riscv_ss.add(files( | 42 | @@ -XXX,XX +XXX,XX @@ static void raise_mmu_exception(CPURISCVState *env, target_ulong address, |
59 | 'zce_helper.c', | 43 | |
60 | 'vcrypto_helper.c' | 44 | switch (access_type) { |
61 | )) | 45 | case MMU_INST_FETCH: |
62 | -riscv_ss.add(when: 'CONFIG_KVM', if_true: files('kvm.c'), if_false: files('kvm-stub.c')) | 46 | - if (env->virt_enabled && !first_stage) { |
63 | +riscv_ss.add(when: 'CONFIG_KVM', if_true: files('kvm.c')) | 47 | + if (pmp_violation) { |
64 | 48 | + cs->exception_index = RISCV_EXCP_INST_ACCESS_FAULT; | |
65 | riscv_system_ss = ss.source_set() | 49 | + } else if (env->virt_enabled && !first_stage) { |
66 | riscv_system_ss.add(files( | 50 | cs->exception_index = RISCV_EXCP_INST_GUEST_PAGE_FAULT; |
51 | } else { | ||
52 | - cs->exception_index = pmp_violation ? | ||
53 | - RISCV_EXCP_INST_ACCESS_FAULT : RISCV_EXCP_INST_PAGE_FAULT; | ||
54 | + cs->exception_index = RISCV_EXCP_INST_PAGE_FAULT; | ||
55 | } | ||
56 | break; | ||
57 | case MMU_DATA_LOAD: | ||
58 | - if (two_stage && !first_stage) { | ||
59 | + if (pmp_violation) { | ||
60 | + cs->exception_index = RISCV_EXCP_LOAD_ACCESS_FAULT; | ||
61 | + } else if (two_stage && !first_stage) { | ||
62 | cs->exception_index = RISCV_EXCP_LOAD_GUEST_ACCESS_FAULT; | ||
63 | } else { | ||
64 | - cs->exception_index = pmp_violation ? | ||
65 | - RISCV_EXCP_LOAD_ACCESS_FAULT : RISCV_EXCP_LOAD_PAGE_FAULT; | ||
66 | + cs->exception_index = RISCV_EXCP_LOAD_PAGE_FAULT; | ||
67 | } | ||
68 | break; | ||
69 | case MMU_DATA_STORE: | ||
70 | - if (two_stage && !first_stage) { | ||
71 | + if (pmp_violation) { | ||
72 | + cs->exception_index = RISCV_EXCP_STORE_AMO_ACCESS_FAULT; | ||
73 | + } else if (two_stage && !first_stage) { | ||
74 | cs->exception_index = RISCV_EXCP_STORE_GUEST_AMO_ACCESS_FAULT; | ||
75 | } else { | ||
76 | - cs->exception_index = pmp_violation ? | ||
77 | - RISCV_EXCP_STORE_AMO_ACCESS_FAULT : | ||
78 | - RISCV_EXCP_STORE_PAGE_FAULT; | ||
79 | + cs->exception_index = RISCV_EXCP_STORE_PAGE_FAULT; | ||
80 | } | ||
81 | break; | ||
82 | default: | ||
67 | -- | 83 | -- |
68 | 2.41.0 | 84 | 2.45.1 | diff view generated by jsdifflib |
1 | From: "Richard W.M. Jones" <rjones@redhat.com> | 1 | From: Alexei Filippov <alexei.filippov@syntacore.com> |
---|---|---|---|
2 | 2 | ||
3 | RISCV_CPU(cs) uses a checked cast. When QOM cast debugging is enabled | 3 | Previous patch fixed the PMP priority in raise_mmu_exception() but we're still |
4 | this adds about 5% total overhead when emulating RV64 on x86-64 host. | 4 | setting mtval2 incorrectly. In riscv_cpu_tlb_fill(), after pmp check in 2 stage |
5 | translation part, mtval2 will be set in case of successes 2 stage translation but | ||
6 | failed pmp check. | ||
5 | 7 | ||
6 | Using a RISC-V guest with 16 vCPUs, 16 GB of guest RAM, virtio-blk | 8 | In this case we gonna set mtval2 via env->guest_phys_fault_addr in context of |
7 | disk. The guest has a copy of the qemu source tree. The test | 9 | riscv_cpu_tlb_fill(), as this was a guest-page-fault, but it didn't and mtval2 |
8 | involves compiling the qemu source tree with 'make clean; time make -j16'. | 10 | should be zero, according to RISCV privileged spec sect. 9.4.4: When a guest |
11 | page-fault is taken into M-mode, mtval2 is written with either zero or guest | ||
12 | physical address that faulted, shifted by 2 bits. *For other traps, mtval2 | ||
13 | is set to zero...* | ||
9 | 14 | ||
10 | Before making this change the compile step took 449 & 447 seconds over | 15 | Signed-off-by: Alexei Filippov <alexei.filippov@syntacore.com> |
11 | two consecutive runs. | 16 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
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> | 17 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
21 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | 18 | Message-ID: <20240503103052.6819-1-alexei.filippov@syntacore.com> |
22 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 19 | Cc: qemu-stable <qemu-stable@nongnu.org> |
23 | Message-ID: <20231009124859.3373696-2-rjones@redhat.com> | ||
24 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 20 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
25 | --- | 21 | --- |
26 | target/riscv/cpu_helper.c | 3 +-- | 22 | target/riscv/cpu_helper.c | 12 ++++++------ |
27 | 1 file changed, 1 insertion(+), 2 deletions(-) | 23 | 1 file changed, 6 insertions(+), 6 deletions(-) |
28 | 24 | ||
29 | diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c | 25 | diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c |
30 | index XXXXXXX..XXXXXXX 100644 | 26 | index XXXXXXX..XXXXXXX 100644 |
31 | --- a/target/riscv/cpu_helper.c | 27 | --- a/target/riscv/cpu_helper.c |
32 | +++ b/target/riscv/cpu_helper.c | 28 | +++ b/target/riscv/cpu_helper.c |
33 | @@ -XXX,XX +XXX,XX @@ int riscv_cpu_mmu_index(CPURISCVState *env, bool ifetch) | 29 | @@ -XXX,XX +XXX,XX @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size, |
34 | void cpu_get_tb_cpu_state(CPURISCVState *env, vaddr *pc, | 30 | __func__, pa, ret, prot_pmp, tlb_size); |
35 | uint64_t *cs_base, uint32_t *pflags) | 31 | |
36 | { | 32 | prot &= prot_pmp; |
37 | - CPUState *cs = env_cpu(env); | 33 | - } |
38 | - RISCVCPU *cpu = RISCV_CPU(cs); | 34 | - |
39 | + RISCVCPU *cpu = env_archcpu(env); | 35 | - if (ret != TRANSLATE_SUCCESS) { |
40 | RISCVExtStatus fs, vs; | 36 | + } else { |
41 | uint32_t flags = 0; | 37 | /* |
42 | 38 | * Guest physical address translation failed, this is a HS | |
39 | * level exception | ||
40 | */ | ||
41 | first_stage_error = false; | ||
42 | - env->guest_phys_fault_addr = (im_address | | ||
43 | - (address & | ||
44 | - (TARGET_PAGE_SIZE - 1))) >> 2; | ||
45 | + if (ret != TRANSLATE_PMP_FAIL) { | ||
46 | + env->guest_phys_fault_addr = (im_address | | ||
47 | + (address & | ||
48 | + (TARGET_PAGE_SIZE - 1))) >> 2; | ||
49 | + } | ||
50 | } | ||
51 | } | ||
52 | } else { | ||
43 | -- | 53 | -- |
44 | 2.41.0 | 54 | 2.45.1 |
45 | |||
46 | diff view generated by jsdifflib |
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 1 | From: Rob Bradford <rbradford@rivosinc.com> |
---|---|---|---|
2 | 2 | ||
3 | We'll move riscv_init_max_cpu_extensions() to tcg-cpu.c in the next | 3 | This extension has now been ratified: |
4 | patch and set_misa() needs to be usable from there. | 4 | https://jira.riscv.org/browse/RVS-2006 so the "x-" prefix can be |
5 | removed. | ||
5 | 6 | ||
6 | Rename it to riscv_cpu_set_misa() and make it public. | 7 | Since this is now a ratified extension add it to the list of extensions |
8 | included in the "max" CPU variant. | ||
7 | 9 | ||
8 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 10 | Signed-off-by: Rob Bradford <rbradford@rivosinc.com> |
9 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | ||
10 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> | 11 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> |
11 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 12 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
12 | Message-ID: <20230925175709.35696-15-dbarboza@ventanamicro.com> | 13 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
14 | Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com> | ||
15 | Message-ID: <20240514110217.22516-1-rbradford@rivosinc.com> | ||
13 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 16 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
14 | --- | 17 | --- |
15 | target/riscv/cpu.h | 1 + | 18 | target/riscv/cpu.c | 2 +- |
16 | target/riscv/cpu.c | 34 ++++++++++++++++++---------------- | 19 | target/riscv/tcg/tcg-cpu.c | 2 +- |
17 | 2 files changed, 19 insertions(+), 16 deletions(-) | 20 | 2 files changed, 2 insertions(+), 2 deletions(-) |
18 | 21 | ||
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 | 22 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c |
32 | index XXXXXXX..XXXXXXX 100644 | 23 | index XXXXXXX..XXXXXXX 100644 |
33 | --- a/target/riscv/cpu.c | 24 | --- a/target/riscv/cpu.c |
34 | +++ b/target/riscv/cpu.c | 25 | +++ b/target/riscv/cpu.c |
35 | @@ -XXX,XX +XXX,XX @@ const char *riscv_cpu_get_trap_name(target_ulong cause, bool async) | 26 | @@ -XXX,XX +XXX,XX @@ static const MISAExtInfo misa_ext_info_arr[] = { |
36 | } | 27 | MISA_EXT_INFO(RVJ, "x-j", "Dynamic translated languages"), |
37 | } | 28 | MISA_EXT_INFO(RVV, "v", "Vector operations"), |
38 | 29 | MISA_EXT_INFO(RVG, "g", "General purpose (IMAFD_Zicsr_Zifencei)"), | |
39 | -static void set_misa(CPURISCVState *env, RISCVMXL mxl, uint32_t ext) | 30 | - MISA_EXT_INFO(RVB, "x-b", "Bit manipulation (Zba_Zbb_Zbs)") |
40 | +void riscv_cpu_set_misa(CPURISCVState *env, RISCVMXL mxl, uint32_t ext) | 31 | + MISA_EXT_INFO(RVB, "b", "Bit manipulation (Zba_Zbb_Zbs)") |
41 | { | 32 | }; |
42 | env->misa_mxl_max = env->misa_mxl = mxl; | 33 | |
43 | env->misa_ext_mask = env->misa_ext = ext; | 34 | static void riscv_cpu_validate_misa_mxl(RISCVCPUClass *mcc) |
44 | @@ -XXX,XX +XXX,XX @@ static void riscv_any_cpu_init(Object *obj) | 35 | diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c |
45 | RISCVCPU *cpu = RISCV_CPU(obj); | 36 | index XXXXXXX..XXXXXXX 100644 |
46 | CPURISCVState *env = &cpu->env; | 37 | --- a/target/riscv/tcg/tcg-cpu.c |
47 | #if defined(TARGET_RISCV32) | 38 | +++ b/target/riscv/tcg/tcg-cpu.c |
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) | 39 | @@ -XXX,XX +XXX,XX @@ static void riscv_init_max_cpu_extensions(Object *obj) |
167 | const RISCVCPUMultiExtConfig *prop; | 40 | const RISCVCPUMultiExtConfig *prop; |
168 | 41 | ||
169 | /* Enable RVG, RVJ and RVV that are disabled by default */ | 42 | /* Enable RVG, RVJ and RVV that are disabled by default */ |
170 | - set_misa(env, env->misa_mxl, env->misa_ext | RVG | RVJ | RVV); | 43 | - riscv_cpu_set_misa_ext(env, env->misa_ext | RVG | RVJ | RVV); |
171 | + riscv_cpu_set_misa(env, env->misa_mxl, env->misa_ext | RVG | RVJ | RVV); | 44 | + riscv_cpu_set_misa_ext(env, env->misa_ext | RVB | RVG | RVJ | RVV); |
172 | 45 | ||
173 | for (prop = riscv_cpu_extensions; prop && prop->name; prop++) { | 46 | for (prop = riscv_cpu_extensions; prop && prop->name; prop++) { |
174 | isa_ext_update_enabled(cpu, prop->offset, true); | 47 | isa_ext_update_enabled(cpu, prop->offset, true); |
175 | -- | 48 | -- |
176 | 2.41.0 | 49 | 2.45.1 |
177 | |||
178 | diff view generated by jsdifflib |
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 1 | From: Alistair Francis <alistair23@gmail.com> |
---|---|---|---|
2 | 2 | ||
3 | Move the remaining of riscv_tcg_ops now that we have a working realize() | 3 | When running the instruction |
4 | implementation. | ||
5 | 4 | ||
6 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 5 | ``` |
7 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | 6 | cbo.flush 0(x0) |
8 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> | 7 | ``` |
9 | Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com> | 8 | |
10 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 9 | QEMU would segfault. |
11 | Message-ID: <20230925175709.35696-5-dbarboza@ventanamicro.com> | 10 | |
11 | The issue was in cpu_gpr[a->rs1] as QEMU does not have cpu_gpr[0] | ||
12 | allocated. | ||
13 | |||
14 | In order to fix this let's use the existing get_address() | ||
15 | helper. This also has the benefit of performing pointer mask | ||
16 | calculations on the address specified in rs1. | ||
17 | |||
18 | The pointer masking specificiation specifically states: | ||
19 | |||
20 | """ | ||
21 | Cache Management Operations: All instructions in Zicbom, Zicbop and Zicboz | ||
22 | """ | ||
23 | |||
24 | So this is the correct behaviour and we previously have been incorrectly | ||
25 | not masking the address. | ||
26 | |||
27 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
28 | Reported-by: Fabian Thomas <fabian.thomas@cispa.de> | ||
29 | Fixes: e05da09b7cfd ("target/riscv: implement Zicbom extension") | ||
30 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
31 | Cc: qemu-stable <qemu-stable@nongnu.org> | ||
32 | Message-ID: <20240514023910.301766-1-alistair.francis@wdc.com> | ||
12 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 33 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
13 | --- | 34 | --- |
14 | target/riscv/cpu.h | 4 --- | 35 | target/riscv/insn_trans/trans_rvzicbo.c.inc | 16 ++++++++++++---- |
15 | target/riscv/cpu.c | 58 ------------------------------------ | 36 | 1 file changed, 12 insertions(+), 4 deletions(-) |
16 | target/riscv/tcg/tcg-cpu.c | 60 +++++++++++++++++++++++++++++++++++++- | ||
17 | 3 files changed, 59 insertions(+), 63 deletions(-) | ||
18 | 37 | ||
19 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h | 38 | diff --git a/target/riscv/insn_trans/trans_rvzicbo.c.inc b/target/riscv/insn_trans/trans_rvzicbo.c.inc |
20 | index XXXXXXX..XXXXXXX 100644 | 39 | index XXXXXXX..XXXXXXX 100644 |
21 | --- a/target/riscv/cpu.h | 40 | --- a/target/riscv/insn_trans/trans_rvzicbo.c.inc |
22 | +++ b/target/riscv/cpu.h | 41 | +++ b/target/riscv/insn_trans/trans_rvzicbo.c.inc |
23 | @@ -XXX,XX +XXX,XX @@ enum riscv_pmu_event_idx { | 42 | @@ -XXX,XX +XXX,XX @@ |
24 | RISCV_PMU_EVENT_CACHE_ITLB_PREFETCH_MISS = 0x10021, | 43 | static bool trans_cbo_clean(DisasContext *ctx, arg_cbo_clean *a) |
25 | }; | 44 | { |
26 | 45 | REQUIRE_ZICBOM(ctx); | |
27 | -/* Export tcg_ops until we move everything to tcg/tcg-cpu.c */ | 46 | - gen_helper_cbo_clean_flush(tcg_env, cpu_gpr[a->rs1]); |
28 | -#include "hw/core/tcg-cpu-ops.h" | 47 | + TCGv src = get_address(ctx, a->rs1, 0); |
29 | -extern const struct TCGCPUOps riscv_tcg_ops; | 48 | + |
30 | - | 49 | + gen_helper_cbo_clean_flush(tcg_env, src); |
31 | /* used by tcg/tcg-cpu.c*/ | 50 | return true; |
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 | ||
35 | index XXXXXXX..XXXXXXX 100644 | ||
36 | --- a/target/riscv/cpu.c | ||
37 | +++ b/target/riscv/cpu.c | ||
38 | @@ -XXX,XX +XXX,XX @@ static vaddr riscv_cpu_get_pc(CPUState *cs) | ||
39 | return env->pc; | ||
40 | } | 51 | } |
41 | 52 | ||
42 | -static void riscv_cpu_synchronize_from_tb(CPUState *cs, | 53 | static bool trans_cbo_flush(DisasContext *ctx, arg_cbo_flush *a) |
43 | - const TranslationBlock *tb) | ||
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 | { | 54 | { |
62 | #ifndef CONFIG_USER_ONLY | 55 | REQUIRE_ZICBOM(ctx); |
63 | @@ -XXX,XX +XXX,XX @@ static bool riscv_cpu_has_work(CPUState *cs) | 56 | - gen_helper_cbo_clean_flush(tcg_env, cpu_gpr[a->rs1]); |
64 | #endif | 57 | + TCGv src = get_address(ctx, a->rs1, 0); |
58 | + | ||
59 | + gen_helper_cbo_clean_flush(tcg_env, src); | ||
60 | return true; | ||
65 | } | 61 | } |
66 | 62 | ||
67 | -static void riscv_restore_state_to_opc(CPUState *cs, | 63 | static bool trans_cbo_inval(DisasContext *ctx, arg_cbo_inval *a) |
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 | { | 64 | { |
92 | #ifndef CONFIG_USER_ONLY | 65 | REQUIRE_ZICBOM(ctx); |
93 | @@ -XXX,XX +XXX,XX @@ static const struct SysemuCPUOps riscv_sysemu_ops = { | 66 | - gen_helper_cbo_inval(tcg_env, cpu_gpr[a->rs1]); |
94 | }; | 67 | + TCGv src = get_address(ctx, a->rs1, 0); |
95 | #endif | 68 | + |
96 | 69 | + gen_helper_cbo_inval(tcg_env, src); | |
97 | -const struct TCGCPUOps riscv_tcg_ops = { | 70 | return true; |
98 | - .initialize = riscv_translate_init, | 71 | } |
99 | - .synchronize_from_tb = riscv_cpu_synchronize_from_tb, | 72 | |
100 | - .restore_state_to_opc = riscv_restore_state_to_opc, | 73 | static bool trans_cbo_zero(DisasContext *ctx, arg_cbo_zero *a) |
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 | { | 74 | { |
116 | return object_dynamic_cast(cpu_obj, TYPE_RISCV_DYNAMIC_CPU) != NULL; | 75 | REQUIRE_ZICBOZ(ctx); |
117 | diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c | 76 | - gen_helper_cbo_zero(tcg_env, cpu_gpr[a->rs1]); |
118 | index XXXXXXX..XXXXXXX 100644 | 77 | + TCGv src = get_address(ctx, a->rs1, 0); |
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); | ||
135 | + | 78 | + |
136 | + tcg_debug_assert(!(cs->tcg_cflags & CF_PCREL)); | 79 | + gen_helper_cbo_zero(tcg_env, src); |
137 | + | 80 | return true; |
138 | + if (xl == MXL_RV32) { | ||
139 | + env->pc = (int32_t) tb->pc; | ||
140 | + } else { | ||
141 | + env->pc = tb->pc; | ||
142 | + } | ||
143 | + } | ||
144 | +} | ||
145 | + | ||
146 | +static void riscv_restore_state_to_opc(CPUState *cs, | ||
147 | + const TranslationBlock *tb, | ||
148 | + const uint64_t *data) | ||
149 | +{ | ||
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]; | ||
167 | +} | ||
168 | + | ||
169 | +static const struct TCGCPUOps riscv_tcg_ops = { | ||
170 | + .initialize = riscv_translate_init, | ||
171 | + .synchronize_from_tb = riscv_cpu_synchronize_from_tb, | ||
172 | + .restore_state_to_opc = riscv_restore_state_to_opc, | ||
173 | + | ||
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) | ||
189 | { | ||
190 | /* | ||
191 | * All cpus use the same set of operations. | ||
192 | - * riscv_tcg_ops is being imported from cpu.c for now. | ||
193 | */ | ||
194 | cc->tcg_ops = &riscv_tcg_ops; | ||
195 | } | 81 | } |
196 | -- | 82 | -- |
197 | 2.41.0 | 83 | 2.45.1 |
198 | |||
199 | diff view generated by jsdifflib |
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 1 | From: Yong-Xuan Wang <yongxuan.wang@sifive.com> |
---|---|---|---|
2 | 2 | ||
3 | KVM for RISC-V started supporting KVM_GET_REG_LIST in Linux 6.6. It | 3 | In AIA spec, each hart (or each hart within a group) has a unique hart |
4 | consists of a KVM ioctl() that retrieves a list of all available regs | 4 | number to locate the memory pages of interrupt files in the address |
5 | for get_one_reg/set_one_reg. Regs that aren't present in the list aren't | 5 | space. The number of bits required to represent any hart number is equal |
6 | supported in the host. | 6 | to ceil(log2(hmax + 1)), where hmax is the largest hart number among |
7 | groups. | ||
7 | 8 | ||
8 | This simplifies our lives when initing the KVM regs since we don't have | 9 | However, if the largest hart number among groups is a power of 2, QEMU |
9 | to always attempt a KVM_GET_ONE_REG for all regs QEMU knows. We'll only | 10 | will pass an inaccurate hart-index-bit setting to Linux. For example, when |
10 | attempt a get_one_reg() if we're sure the reg is supported, i.e. it was | 11 | the guest OS has 4 harts, only ceil(log2(3 + 1)) = 2 bits are sufficient |
11 | retrieved by KVM_GET_REG_LIST. Any error in get_one_reg() will then | 12 | to represent 4 harts, but we passes 3 to Linux. The code needs to be |
12 | always considered fatal, instead of having to handle special error codes | 13 | updated to ensure accurate hart-index-bit settings. |
13 | that might indicate a non-fatal failure. | ||
14 | 14 | ||
15 | Start by moving the current kvm_riscv_init_multiext_cfg() logic into a | 15 | Additionally, a Linux patch[1] is necessary to correctly recover the hart |
16 | new kvm_riscv_read_multiext_legacy() helper. We'll prioritize using | 16 | index when the guest OS has only 1 hart, where the hart-index-bit is 0. |
17 | KVM_GET_REG_LIST, so check if we have it available and, in case we | ||
18 | don't, use the legacy() logic. | ||
19 | 17 | ||
20 | Otherwise, retrieve the available reg list and use it to check if the | 18 | [1] https://lore.kernel.org/lkml/20240415064905.25184-1-yongxuan.wang@sifive.com/t/ |
21 | host supports our known KVM regs, doing the usual get_one_reg() for | ||
22 | the supported regs and setting cpu->cfg accordingly. | ||
23 | 19 | ||
24 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 20 | Signed-off-by: Yong-Xuan Wang <yongxuan.wang@sifive.com> |
25 | Acked-by: Alistair Francis <alistair.francis@wdc.com> | ||
26 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> | 21 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> |
27 | Message-ID: <20231003132148.797921-3-dbarboza@ventanamicro.com> | 22 | Cc: qemu-stable <qemu-stable@nongnu.org> |
23 | Message-ID: <20240515091129.28116-1-yongxuan.wang@sifive.com> | ||
28 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 24 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
29 | --- | 25 | --- |
30 | target/riscv/kvm/kvm-cpu.c | 96 +++++++++++++++++++++++++++++++++++++- | 26 | target/riscv/kvm/kvm-cpu.c | 9 ++++++++- |
31 | 1 file changed, 95 insertions(+), 1 deletion(-) | 27 | 1 file changed, 8 insertions(+), 1 deletion(-) |
32 | 28 | ||
33 | diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c | 29 | diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c |
34 | index XXXXXXX..XXXXXXX 100644 | 30 | index XXXXXXX..XXXXXXX 100644 |
35 | --- a/target/riscv/kvm/kvm-cpu.c | 31 | --- a/target/riscv/kvm/kvm-cpu.c |
36 | +++ b/target/riscv/kvm/kvm-cpu.c | 32 | +++ b/target/riscv/kvm/kvm-cpu.c |
37 | @@ -XXX,XX +XXX,XX @@ static void kvm_riscv_read_cbomz_blksize(RISCVCPU *cpu, KVMScratchCPU *kvmcpu, | 33 | @@ -XXX,XX +XXX,XX @@ void kvm_riscv_aia_create(MachineState *machine, uint64_t group_shift, |
34 | } | ||
38 | } | 35 | } |
39 | } | 36 | |
40 | 37 | - hart_bits = find_last_bit(&max_hart_per_socket, BITS_PER_LONG) + 1; | |
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) | ||
52 | +{ | ||
53 | + uint64_t val1 = *(const uint64_t *)a; | ||
54 | + uint64_t val2 = *(const uint64_t *)b; | ||
55 | + | 38 | + |
56 | + if (val1 < val2) { | 39 | + if (max_hart_per_socket > 1) { |
57 | + return -1; | 40 | + max_hart_per_socket--; |
41 | + hart_bits = find_last_bit(&max_hart_per_socket, BITS_PER_LONG) + 1; | ||
42 | + } else { | ||
43 | + hart_bits = 0; | ||
58 | + } | 44 | + } |
59 | + | 45 | + |
60 | + if (val1 > val2) { | 46 | ret = kvm_device_access(aia_fd, KVM_DEV_RISCV_AIA_GRP_CONFIG, |
61 | + return 1; | 47 | KVM_DEV_RISCV_AIA_CONFIG_HART_BITS, |
62 | + } | 48 | &hart_bits, true, NULL); |
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); | ||
78 | + | ||
79 | + /* | ||
80 | + * If KVM_GET_REG_LIST isn't supported we'll get errno 22 | ||
81 | + * (EINVAL). Use read_legacy() in this case. | ||
82 | + */ | ||
83 | + if (errno == EINVAL) { | ||
84 | + return kvm_riscv_read_multiext_legacy(cpu, kvmcpu); | ||
85 | + } else if (errno != E2BIG) { | ||
86 | + /* | ||
87 | + * E2BIG is an expected error message for the API since we | ||
88 | + * don't know the number of registers. The right amount will | ||
89 | + * be written in rl_struct.n. | ||
90 | + * | ||
91 | + * Error out if we get any other errno. | ||
92 | + */ | ||
93 | + error_report("Error when accessing get-reg-list, code: %s", | ||
94 | + strerrorname_np(errno)); | ||
95 | + exit(EXIT_FAILURE); | ||
96 | + } | ||
97 | + | ||
98 | + reglist = g_malloc(sizeof(struct kvm_reg_list) + | ||
99 | + rl_struct.n * sizeof(uint64_t)); | ||
100 | + reglist->n = rl_struct.n; | ||
101 | + ret = ioctl(kvmcpu->cpufd, KVM_GET_REG_LIST, reglist); | ||
102 | + if (ret) { | ||
103 | + error_report("Error when reading KVM_GET_REG_LIST, code %s ", | ||
104 | + strerrorname_np(errno)); | ||
105 | + exit(EXIT_FAILURE); | ||
106 | + } | ||
107 | + | ||
108 | + /* sort reglist to use bsearch() */ | ||
109 | + qsort(®list->reg, reglist->n, sizeof(uint64_t), uint64_cmp); | ||
110 | + | ||
111 | + for (i = 0; i < ARRAY_SIZE(kvm_multi_ext_cfgs); i++) { | ||
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 | + } | ||
120 | + | ||
121 | + reg.id = reg_id; | ||
122 | + reg.addr = (uint64_t)&val; | ||
123 | + ret = ioctl(kvmcpu->cpufd, KVM_GET_ONE_REG, ®); | ||
124 | + if (ret != 0) { | ||
125 | + error_report("Unable to read ISA_EXT KVM register %s, " | ||
126 | + "error code: %s", multi_ext_cfg->name, | ||
127 | + strerrorname_np(errno)); | ||
128 | + exit(EXIT_FAILURE); | ||
129 | + } | ||
130 | + | ||
131 | + multi_ext_cfg->supported = true; | ||
132 | + kvm_cpu_cfg_set(cpu, multi_ext_cfg, val); | ||
133 | + } | ||
134 | + | ||
135 | + if (cpu->cfg.ext_icbom) { | ||
136 | + kvm_riscv_read_cbomz_blksize(cpu, kvmcpu, &kvm_cbom_blocksize); | ||
137 | + } | ||
138 | + | ||
139 | + if (cpu->cfg.ext_icboz) { | ||
140 | + kvm_riscv_read_cbomz_blksize(cpu, kvmcpu, &kvm_cboz_blocksize); | ||
141 | + } | ||
142 | +} | ||
143 | + | ||
144 | static void riscv_init_kvm_registers(Object *cpu_obj) | ||
145 | { | ||
146 | RISCVCPU *cpu = RISCV_CPU(cpu_obj); | ||
147 | -- | 49 | -- |
148 | 2.41.0 | 50 | 2.45.1 | diff view generated by jsdifflib |
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
---|---|---|---|
2 | 2 | ||
3 | Add DEFINE_PROP_END_OF_LIST() and eliminate the ARRAY_SIZE() usage when | 3 | Commit 33a24910ae changed 'reg_width' to use 'vlenb', i.e. vector length |
4 | iterating in the riscv_cpu_options[] array, making it similar to what | 4 | in bytes, when in this context we want 'reg_width' as the length in |
5 | we already do when working with riscv_cpu_extensions[]. | 5 | bits. |
6 | 6 | ||
7 | We also have a more sophisticated motivation behind this change. In the | 7 | Fix 'reg_width' back to the value in bits like 7cb59921c05a |
8 | future we might need to export riscv_cpu_options[] to other files, and | 8 | ("target/riscv/gdbstub.c: use 'vlenb' instead of shifting 'vlen'") set |
9 | ARRAY_LIST() doesn't work properly in that case because the array size | 9 | beforehand. |
10 | isn't exposed to the header file. Here's a future sight of what we would | ||
11 | deal with: | ||
12 | 10 | ||
13 | ./target/riscv/kvm.c:1057:5: error: nested extern declaration of 'riscv_cpu_add_misa_properties' [-Werror=nested-externs] | 11 | While we're at it, rename 'reg_width' to 'bitsize' to provide a bit more |
14 | n file included from ../target/riscv/kvm.c:19: | 12 | clarity about what the variable represents. 'bitsize' is also used in |
15 | home/danielhb/work/qemu/include/qemu/osdep.h:473:31: error: invalid application of 'sizeof' to incomplete type 'const RISCVCPUMultiExtConfig[]' | 13 | riscv_gen_dynamic_csr_feature() with the same purpose, i.e. as an input to |
16 | 473 | #define ARRAY_SIZE(x) ((sizeof(x) / sizeof((x)[0])) + \ | 14 | gdb_feature_builder_append_reg(). |
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 | 15 | ||
30 | Homogenize the present and change the future by using | 16 | Cc: Akihiko Odaki <akihiko.odaki@daynix.com> |
31 | DEFINE_PROP_END_OF_LIST() in riscv_cpu_options[]. | 17 | Cc: Alex Bennée <alex.bennee@linaro.org> |
32 | 18 | Reported-by: Robin Dapp <rdapp.gcc@gmail.com> | |
19 | Fixes: 33a24910ae ("target/riscv: Use GDBFeature for dynamic XML") | ||
33 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 20 | Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> |
34 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> | 21 | Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com> |
22 | Acked-by: Alex Bennée <alex.bennee@linaro.org> | ||
23 | Reviewed-by: Akihiko Odaki <akihiko.odaki@daynix.com> | ||
35 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 24 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
36 | Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> | 25 | Cc: qemu-stable <qemu-stable@nongnu.org> |
37 | Message-ID: <20230912132423.268494-5-dbarboza@ventanamicro.com> | 26 | Message-ID: <20240517203054.880861-2-dbarboza@ventanamicro.com> |
38 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 27 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
39 | --- | 28 | --- |
40 | target/riscv/cpu.c | 12 +++++++----- | 29 | target/riscv/gdbstub.c | 6 +++--- |
41 | 1 file changed, 7 insertions(+), 5 deletions(-) | 30 | 1 file changed, 3 insertions(+), 3 deletions(-) |
42 | 31 | ||
43 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | 32 | diff --git a/target/riscv/gdbstub.c b/target/riscv/gdbstub.c |
44 | index XXXXXXX..XXXXXXX 100644 | 33 | index XXXXXXX..XXXXXXX 100644 |
45 | --- a/target/riscv/cpu.c | 34 | --- a/target/riscv/gdbstub.c |
46 | +++ b/target/riscv/cpu.c | 35 | +++ b/target/riscv/gdbstub.c |
47 | @@ -XXX,XX +XXX,XX @@ static Property riscv_cpu_options[] = { | 36 | @@ -XXX,XX +XXX,XX @@ static GDBFeature *riscv_gen_dynamic_csr_feature(CPUState *cs, int base_reg) |
48 | 37 | static GDBFeature *ricsv_gen_dynamic_vector_feature(CPUState *cs, int base_reg) | |
49 | DEFINE_PROP_UINT16("cbom_blocksize", RISCVCPU, cfg.cbom_blocksize, 64), | 38 | { |
50 | DEFINE_PROP_UINT16("cboz_blocksize", RISCVCPU, cfg.cboz_blocksize, 64), | 39 | RISCVCPU *cpu = RISCV_CPU(cs); |
51 | + | 40 | - int reg_width = cpu->cfg.vlenb; |
52 | + DEFINE_PROP_END_OF_LIST(), | 41 | + int bitsize = cpu->cfg.vlenb << 3; |
53 | }; | 42 | GDBFeatureBuilder builder; |
54 | 43 | int i; | |
55 | #ifdef CONFIG_KVM | 44 | |
56 | @@ -XXX,XX +XXX,XX @@ void kvm_riscv_cpu_add_kvm_properties(Object *obj) | 45 | @@ -XXX,XX +XXX,XX @@ static GDBFeature *ricsv_gen_dynamic_vector_feature(CPUState *cs, int base_reg) |
57 | riscv_cpu_add_kvm_unavail_prop(obj, prop->name); | 46 | |
47 | /* First define types and totals in a whole VL */ | ||
48 | for (i = 0; i < ARRAY_SIZE(vec_lanes); i++) { | ||
49 | - int count = reg_width / vec_lanes[i].size; | ||
50 | + int count = bitsize / vec_lanes[i].size; | ||
51 | gdb_feature_builder_append_tag( | ||
52 | &builder, "<vector id=\"%s\" type=\"%s\" count=\"%d\"/>", | ||
53 | vec_lanes[i].id, vec_lanes[i].gdb_type, count); | ||
54 | @@ -XXX,XX +XXX,XX @@ static GDBFeature *ricsv_gen_dynamic_vector_feature(CPUState *cs, int base_reg) | ||
55 | /* Define vector registers */ | ||
56 | for (i = 0; i < 32; i++) { | ||
57 | gdb_feature_builder_append_reg(&builder, g_strdup_printf("v%d", i), | ||
58 | - reg_width, i, "riscv_vector", "vector"); | ||
59 | + bitsize, i, "riscv_vector", "vector"); | ||
58 | } | 60 | } |
59 | 61 | ||
60 | - for (int i = 0; i < ARRAY_SIZE(riscv_cpu_options); i++) { | 62 | gdb_feature_builder_end(&builder); |
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 | -- | 63 | -- |
84 | 2.41.0 | 64 | 2.45.1 |
85 | 65 | ||
86 | 66 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
2 | 1 | ||
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 |
Deleted patch | |||
---|---|---|---|
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
2 | 1 | ||
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 |
Deleted patch | |||
---|---|---|---|
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
2 | 1 | ||
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 |
Deleted patch | |||
---|---|---|---|
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
2 | 1 | ||
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 |
Deleted patch | |||
---|---|---|---|
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
2 | 1 | ||
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 |
Deleted patch | |||
---|---|---|---|
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
2 | 1 | ||
3 | The 'max' CPU type is used by tooling to determine what's the most | ||
4 | capable CPU a current QEMU version implements. Other archs such as ARM | ||
5 | implements this type. Let's add it to RISC-V. | ||
6 | |||
7 | What we consider "most capable CPU" in this context are related to | ||
8 | ratified, non-vendor extensions. This means that we want the 'max' CPU | ||
9 | to enable all (possible) ratified extensions by default. The reasoning | ||
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> | ||
36 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
37 | --- | ||
38 | target/riscv/cpu-qom.h | 1 + | ||
39 | target/riscv/cpu.c | 56 ++++++++++++++++++++++++++++++++++++++++++ | ||
40 | 2 files changed, 57 insertions(+) | ||
41 | |||
42 | diff --git a/target/riscv/cpu-qom.h b/target/riscv/cpu-qom.h | ||
43 | index XXXXXXX..XXXXXXX 100644 | ||
44 | --- a/target/riscv/cpu-qom.h | ||
45 | +++ b/target/riscv/cpu-qom.h | ||
46 | @@ -XXX,XX +XXX,XX @@ | ||
47 | #define CPU_RESOLVING_TYPE TYPE_RISCV_CPU | ||
48 | |||
49 | #define TYPE_RISCV_CPU_ANY RISCV_CPU_TYPE_NAME("any") | ||
50 | +#define TYPE_RISCV_CPU_MAX RISCV_CPU_TYPE_NAME("max") | ||
51 | #define TYPE_RISCV_CPU_BASE32 RISCV_CPU_TYPE_NAME("rv32") | ||
52 | #define TYPE_RISCV_CPU_BASE64 RISCV_CPU_TYPE_NAME("rv64") | ||
53 | #define TYPE_RISCV_CPU_BASE128 RISCV_CPU_TYPE_NAME("x-rv128") | ||
54 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | ||
55 | index XXXXXXX..XXXXXXX 100644 | ||
56 | --- a/target/riscv/cpu.c | ||
57 | +++ b/target/riscv/cpu.c | ||
58 | @@ -XXX,XX +XXX,XX @@ static const char * const riscv_intr_names[] = { | ||
59 | }; | ||
60 | |||
61 | static void riscv_cpu_add_user_properties(Object *obj); | ||
62 | +static void riscv_init_max_cpu_extensions(Object *obj); | ||
63 | |||
64 | const char *riscv_cpu_get_trap_name(target_ulong cause, bool async) | ||
65 | { | ||
66 | @@ -XXX,XX +XXX,XX @@ static void riscv_any_cpu_init(Object *obj) | ||
67 | cpu->cfg.pmp = true; | ||
68 | } | ||
69 | |||
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; | ||
75 | + | ||
76 | +#ifdef TARGET_RISCV32 | ||
77 | + mlx = MXL_RV32; | ||
78 | +#endif | ||
79 | + set_misa(env, mlx, 0); | ||
80 | + riscv_cpu_add_user_properties(obj); | ||
81 | + riscv_init_max_cpu_extensions(obj); | ||
82 | + env->priv_ver = PRIV_VERSION_LATEST; | ||
83 | +#ifndef CONFIG_USER_ONLY | ||
84 | + set_satp_mode_max_supported(RISCV_CPU(obj), mlx == MXL_RV32 ? | ||
85 | + VM_1_10_SV32 : VM_1_10_SV57); | ||
86 | +#endif | ||
87 | +} | ||
88 | + | ||
89 | #if defined(TARGET_RISCV64) | ||
90 | static void rv64_base_cpu_init(Object *obj) | ||
91 | { | ||
92 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_add_user_properties(Object *obj) | ||
93 | riscv_cpu_add_qdev_prop_array(dev, riscv_cpu_experimental_exts); | ||
94 | } | ||
95 | |||
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) | ||
101 | +{ | ||
102 | + RISCVCPU *cpu = RISCV_CPU(obj); | ||
103 | + CPURISCVState *env = &cpu->env; | ||
104 | + Property *prop; | ||
105 | + | ||
106 | + /* Enable RVG, RVJ and RVV that are disabled by default */ | ||
107 | + set_misa(env, env->misa_mxl, env->misa_ext | RVG | RVJ | RVV); | ||
108 | + | ||
109 | + for (prop = riscv_cpu_extensions; prop && prop->name; prop++) { | ||
110 | + object_property_set_bool(obj, prop->name, true, NULL); | ||
111 | + } | ||
112 | + | ||
113 | + /* set vector version */ | ||
114 | + env->vext_ver = VEXT_VERSION_1_00_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 | + } | ||
129 | +} | ||
130 | + | ||
131 | static Property riscv_cpu_properties[] = { | ||
132 | DEFINE_PROP_BOOL("debug", RISCVCPU, cfg.debug, true), | ||
133 | |||
134 | @@ -XXX,XX +XXX,XX @@ static const TypeInfo riscv_cpu_type_infos[] = { | ||
135 | .abstract = true, | ||
136 | }, | ||
137 | DEFINE_DYNAMIC_CPU(TYPE_RISCV_CPU_ANY, riscv_any_cpu_init), | ||
138 | + DEFINE_DYNAMIC_CPU(TYPE_RISCV_CPU_MAX, riscv_max_cpu_init), | ||
139 | #if defined(CONFIG_KVM) | ||
140 | DEFINE_CPU(TYPE_RISCV_CPU_HOST, riscv_host_cpu_init), | ||
141 | #endif | ||
142 | -- | ||
143 | 2.41.0 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
2 | 1 | ||
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 |
Deleted patch | |||
---|---|---|---|
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
2 | 1 | ||
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 |
Deleted patch | |||
---|---|---|---|
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
2 | 1 | ||
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 |
Deleted patch | |||
---|---|---|---|
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
2 | 1 | ||
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 |
Deleted patch | |||
---|---|---|---|
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
2 | 1 | ||
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 |
Deleted patch | |||
---|---|---|---|
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
2 | 1 | ||
3 | Before adding support to detect if an extension was user set we need to | ||
4 | handle how we're enabling extensions in riscv_init_max_cpu_extensions(). | ||
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. | ||
8 | |||
9 | This means that, as is today, all extensions we're setting for the 'max' | ||
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> | ||
15 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
16 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> | ||
17 | Message-ID: <20230912132423.268494-19-dbarboza@ventanamicro.com> | ||
18 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
19 | --- | ||
20 | target/riscv/cpu.c | 18 +++++++++--------- | ||
21 | 1 file changed, 9 insertions(+), 9 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 @@ static void riscv_init_max_cpu_extensions(Object *obj) | ||
28 | set_misa(env, env->misa_mxl, env->misa_ext | RVG | RVJ | RVV); | ||
29 | |||
30 | for (prop = riscv_cpu_extensions; prop && prop->name; prop++) { | ||
31 | - object_property_set_bool(obj, prop->name, true, NULL); | ||
32 | + isa_ext_update_enabled(cpu, prop->offset, true); | ||
33 | } | ||
34 | |||
35 | /* set vector version */ | ||
36 | env->vext_ver = VEXT_VERSION_1_00_0; | ||
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); | ||
58 | } | ||
59 | } | ||
60 | |||
61 | -- | ||
62 | 2.41.0 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
2 | 1 | ||
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 |
Deleted patch | |||
---|---|---|---|
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
2 | 1 | ||
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. | ||
7 | |||
8 | After this patch, disabling ifencei or icsr while enabling RVG will | ||
9 | result in error: | ||
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> | ||
15 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
16 | Reviewed-by: Andrew Jones <ajones@ventanamicro.com> | ||
17 | Message-ID: <20230912132423.268494-21-dbarboza@ventanamicro.com> | ||
18 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
19 | --- | ||
20 | target/riscv/cpu.c | 18 ++++++++++++++++-- | ||
21 | 1 file changed, 16 insertions(+), 2 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 | riscv_has_ext(env, RVA) && riscv_has_ext(env, RVF) && | ||
29 | riscv_has_ext(env, RVD) && | ||
30 | cpu->cfg.ext_icsr && cpu->cfg.ext_ifencei)) { | ||
31 | + | ||
32 | + if (cpu_cfg_ext_is_user_set(CPU_CFG_OFFSET(ext_icsr)) && | ||
33 | + !cpu->cfg.ext_icsr) { | ||
34 | + error_setg(errp, "RVG requires Zicsr but user set Zicsr to false"); | ||
35 | + return; | ||
36 | + } | ||
37 | + | ||
38 | + if (cpu_cfg_ext_is_user_set(CPU_CFG_OFFSET(ext_ifencei)) && | ||
39 | + !cpu->cfg.ext_ifencei) { | ||
40 | + error_setg(errp, "RVG requires Zifencei but user set " | ||
41 | + "Zifencei to false"); | ||
42 | + return; | ||
43 | + } | ||
44 | + | ||
45 | warn_report("Setting G will also set IMAFD_Zicsr_Zifencei"); | ||
46 | - cpu->cfg.ext_icsr = true; | ||
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; | ||
53 | -- | ||
54 | 2.41.0 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: "liguang.zhang" <liguang.zhang@hexintek.com> | ||
2 | 1 | ||
3 | This patch fixes guest reboot errors when using KVM. | ||
4 | |||
5 | There are two issues when rebooting a guest using KVM | ||
6 | 1. When the guest initiates a reboot the host is unable to stop the vcpu | ||
7 | 2. When running a SMP guest the qemu monitor system_reset causes a vcpu crash | ||
8 | |||
9 | This can be fixed by clearing the CSR values at reset and syncing the | ||
10 | MPSTATE with the host. | ||
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 | ] | ||
19 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
20 | --- | ||
21 | target/riscv/kvm_riscv.h | 1 + | ||
22 | target/riscv/kvm.c | 44 ++++++++++++++++++++++++++++++++++++++++ | ||
23 | 2 files changed, 45 insertions(+) | ||
24 | |||
25 | diff --git a/target/riscv/kvm_riscv.h b/target/riscv/kvm_riscv.h | ||
26 | index XXXXXXX..XXXXXXX 100644 | ||
27 | --- a/target/riscv/kvm_riscv.h | ||
28 | +++ b/target/riscv/kvm_riscv.h | ||
29 | @@ -XXX,XX +XXX,XX @@ void kvm_riscv_aia_create(MachineState *machine, uint64_t group_shift, | ||
30 | uint64_t aplic_base, uint64_t imsic_base, | ||
31 | uint64_t guest_num); | ||
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; | ||
45 | + | ||
46 | static uint64_t kvm_riscv_reg_id(CPURISCVState *env, uint64_t type, | ||
47 | uint64_t idx) | ||
48 | { | ||
49 | @@ -XXX,XX +XXX,XX @@ int kvm_arch_get_registers(CPUState *cs) | ||
50 | return ret; | ||
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 | + }; | ||
59 | + | ||
60 | + int ret = kvm_vcpu_ioctl(CPU(cpu), KVM_SET_MP_STATE, &mp_state); | ||
61 | + if (ret) { | ||
62 | + fprintf(stderr, "%s: failed to sync MP_STATE %d/%s\n", | ||
63 | + __func__, ret, strerror(-ret)); | ||
64 | + return -1; | ||
65 | + } | ||
66 | + } | ||
67 | + | ||
68 | + return 0; | ||
69 | +} | ||
70 | + | ||
71 | int kvm_arch_put_registers(CPUState *cs, int level) | ||
72 | { | ||
73 | int ret = 0; | ||
74 | @@ -XXX,XX +XXX,XX @@ int kvm_arch_put_registers(CPUState *cs, int level) | ||
75 | return ret; | ||
76 | } | ||
77 | |||
78 | + if (KVM_PUT_RESET_STATE == level) { | ||
79 | + RISCVCPU *cpu = RISCV_CPU(cs); | ||
80 | + if (cs->cpu_index == 0) { | ||
81 | + ret = kvm_riscv_sync_mpstate_to_kvm(cpu, KVM_MP_STATE_RUNNABLE); | ||
82 | + } else { | ||
83 | + ret = kvm_riscv_sync_mpstate_to_kvm(cpu, KVM_MP_STATE_STOPPED); | ||
84 | + } | ||
85 | + if (ret) { | ||
86 | + return ret; | ||
87 | + } | ||
88 | + } | ||
89 | + | ||
90 | return ret; | ||
91 | } | ||
92 | |||
93 | @@ -XXX,XX +XXX,XX @@ int kvm_arch_get_default_type(MachineState *ms) | ||
94 | |||
95 | int kvm_arch_init(MachineState *ms, KVMState *s) | ||
96 | { | ||
97 | + cap_has_mp_state = kvm_check_extension(s, KVM_CAP_MP_STATE); | ||
98 | return 0; | ||
99 | } | ||
100 | |||
101 | @@ -XXX,XX +XXX,XX @@ int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run) | ||
102 | void kvm_riscv_reset_vcpu(RISCVCPU *cpu) | ||
103 | { | ||
104 | CPURISCVState *env = &cpu->env; | ||
105 | + int i; | ||
106 | |||
107 | if (!kvm_enabled()) { | ||
108 | return; | ||
109 | } | ||
110 | + for (i = 0; i < 32; i++) { | ||
111 | + env->gpr[i] = 0; | ||
112 | + } | ||
113 | env->pc = cpu->env.kernel_addr; | ||
114 | env->gpr[10] = kvm_arch_vcpu_id(CPU(cpu)); /* a0 */ | ||
115 | env->gpr[11] = cpu->env.fdt_addr; /* a1 */ | ||
116 | env->satp = 0; | ||
117 | + env->mie = 0; | ||
118 | + env->stvec = 0; | ||
119 | + env->sscratch = 0; | ||
120 | + env->sepc = 0; | ||
121 | + env->scause = 0; | ||
122 | + env->stval = 0; | ||
123 | + env->mip = 0; | ||
124 | } | ||
125 | |||
126 | void kvm_riscv_set_irq(RISCVCPU *cpu, int irq, int level) | ||
127 | -- | ||
128 | 2.41.0 | diff view generated by jsdifflib |
1 | From: Alvin Chang <vivahavey@gmail.com> | 1 | From: Alistair Francis <alistair23@gmail.com> |
---|---|---|---|
2 | 2 | ||
3 | Fix the inverted order of pmpaddr13 and pmpaddr14 in csr_name(). | 3 | Previously we only listed a single pmpcfg CSR and the first 16 pmpaddr |
4 | CSRs. This patch fixes this to list all 16 pmpcfg and all 64 pmpaddr | ||
5 | CSRs are part of the disassembly. | ||
4 | 6 | ||
5 | Signed-off-by: Alvin Chang <alvinga@andestech.com> | 7 | Reported-by: Eric DeVolder <eric_devolder@yahoo.com> |
6 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 8 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
7 | Message-ID: <20230907084500.328-1-alvinga@andestech.com> | 9 | Fixes: ea10325917 ("RISC-V Disassembler") |
10 | Reviewed-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
11 | Cc: qemu-stable <qemu-stable@nongnu.org> | ||
12 | Message-ID: <20240514051615.330979-1-alistair.francis@wdc.com> | ||
8 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 13 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
9 | --- | 14 | --- |
10 | disas/riscv.c | 4 ++-- | 15 | disas/riscv.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++- |
11 | 1 file changed, 2 insertions(+), 2 deletions(-) | 16 | 1 file changed, 64 insertions(+), 1 deletion(-) |
12 | 17 | ||
13 | diff --git a/disas/riscv.c b/disas/riscv.c | 18 | diff --git a/disas/riscv.c b/disas/riscv.c |
14 | index XXXXXXX..XXXXXXX 100644 | 19 | index XXXXXXX..XXXXXXX 100644 |
15 | --- a/disas/riscv.c | 20 | --- a/disas/riscv.c |
16 | +++ b/disas/riscv.c | 21 | +++ b/disas/riscv.c |
17 | @@ -XXX,XX +XXX,XX @@ static const char *csr_name(int csrno) | 22 | @@ -XXX,XX +XXX,XX @@ static const char *csr_name(int csrno) |
18 | case 0x03ba: return "pmpaddr10"; | 23 | case 0x0383: return "mibound"; |
19 | case 0x03bb: return "pmpaddr11"; | 24 | case 0x0384: return "mdbase"; |
20 | case 0x03bc: return "pmpaddr12"; | 25 | case 0x0385: return "mdbound"; |
21 | - case 0x03bd: return "pmpaddr14"; | 26 | - case 0x03a0: return "pmpcfg3"; |
22 | - case 0x03be: return "pmpaddr13"; | 27 | + case 0x03a0: return "pmpcfg0"; |
23 | + case 0x03bd: return "pmpaddr13"; | 28 | + case 0x03a1: return "pmpcfg1"; |
24 | + case 0x03be: return "pmpaddr14"; | 29 | + case 0x03a2: return "pmpcfg2"; |
30 | + case 0x03a3: return "pmpcfg3"; | ||
31 | + case 0x03a4: return "pmpcfg4"; | ||
32 | + case 0x03a5: return "pmpcfg5"; | ||
33 | + case 0x03a6: return "pmpcfg6"; | ||
34 | + case 0x03a7: return "pmpcfg7"; | ||
35 | + case 0x03a8: return "pmpcfg8"; | ||
36 | + case 0x03a9: return "pmpcfg9"; | ||
37 | + case 0x03aa: return "pmpcfg10"; | ||
38 | + case 0x03ab: return "pmpcfg11"; | ||
39 | + case 0x03ac: return "pmpcfg12"; | ||
40 | + case 0x03ad: return "pmpcfg13"; | ||
41 | + case 0x03ae: return "pmpcfg14"; | ||
42 | + case 0x03af: return "pmpcfg15"; | ||
43 | case 0x03b0: return "pmpaddr0"; | ||
44 | case 0x03b1: return "pmpaddr1"; | ||
45 | case 0x03b2: return "pmpaddr2"; | ||
46 | @@ -XXX,XX +XXX,XX @@ static const char *csr_name(int csrno) | ||
47 | case 0x03bd: return "pmpaddr13"; | ||
48 | case 0x03be: return "pmpaddr14"; | ||
25 | case 0x03bf: return "pmpaddr15"; | 49 | case 0x03bf: return "pmpaddr15"; |
50 | + case 0x03c0: return "pmpaddr16"; | ||
51 | + case 0x03c1: return "pmpaddr17"; | ||
52 | + case 0x03c2: return "pmpaddr18"; | ||
53 | + case 0x03c3: return "pmpaddr19"; | ||
54 | + case 0x03c4: return "pmpaddr20"; | ||
55 | + case 0x03c5: return "pmpaddr21"; | ||
56 | + case 0x03c6: return "pmpaddr22"; | ||
57 | + case 0x03c7: return "pmpaddr23"; | ||
58 | + case 0x03c8: return "pmpaddr24"; | ||
59 | + case 0x03c9: return "pmpaddr25"; | ||
60 | + case 0x03ca: return "pmpaddr26"; | ||
61 | + case 0x03cb: return "pmpaddr27"; | ||
62 | + case 0x03cc: return "pmpaddr28"; | ||
63 | + case 0x03cd: return "pmpaddr29"; | ||
64 | + case 0x03ce: return "pmpaddr30"; | ||
65 | + case 0x03cf: return "pmpaddr31"; | ||
66 | + case 0x03d0: return "pmpaddr32"; | ||
67 | + case 0x03d1: return "pmpaddr33"; | ||
68 | + case 0x03d2: return "pmpaddr34"; | ||
69 | + case 0x03d3: return "pmpaddr35"; | ||
70 | + case 0x03d4: return "pmpaddr36"; | ||
71 | + case 0x03d5: return "pmpaddr37"; | ||
72 | + case 0x03d6: return "pmpaddr38"; | ||
73 | + case 0x03d7: return "pmpaddr39"; | ||
74 | + case 0x03d8: return "pmpaddr40"; | ||
75 | + case 0x03d9: return "pmpaddr41"; | ||
76 | + case 0x03da: return "pmpaddr42"; | ||
77 | + case 0x03db: return "pmpaddr43"; | ||
78 | + case 0x03dc: return "pmpaddr44"; | ||
79 | + case 0x03dd: return "pmpaddr45"; | ||
80 | + case 0x03de: return "pmpaddr46"; | ||
81 | + case 0x03df: return "pmpaddr47"; | ||
82 | + case 0x03e0: return "pmpaddr48"; | ||
83 | + case 0x03e1: return "pmpaddr49"; | ||
84 | + case 0x03e2: return "pmpaddr50"; | ||
85 | + case 0x03e3: return "pmpaddr51"; | ||
86 | + case 0x03e4: return "pmpaddr52"; | ||
87 | + case 0x03e5: return "pmpaddr53"; | ||
88 | + case 0x03e6: return "pmpaddr54"; | ||
89 | + case 0x03e7: return "pmpaddr55"; | ||
90 | + case 0x03e8: return "pmpaddr56"; | ||
91 | + case 0x03e9: return "pmpaddr57"; | ||
92 | + case 0x03ea: return "pmpaddr58"; | ||
93 | + case 0x03eb: return "pmpaddr59"; | ||
94 | + case 0x03ec: return "pmpaddr60"; | ||
95 | + case 0x03ed: return "pmpaddr61"; | ||
96 | + case 0x03ee: return "pmpaddr62"; | ||
97 | + case 0x03ef: return "pmpaddr63"; | ||
26 | case 0x0780: return "mtohost"; | 98 | case 0x0780: return "mtohost"; |
27 | case 0x0781: return "mfromhost"; | 99 | case 0x0781: return "mfromhost"; |
100 | case 0x0782: return "mreset"; | ||
28 | -- | 101 | -- |
29 | 2.41.0 | 102 | 2.45.1 | diff view generated by jsdifflib |
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | 1 | From: Yu-Ming Chang <yumin686@andestech.com> |
---|---|---|---|
2 | 2 | ||
3 | This function is the core of the RISC-V validations for TCG CPUs, and it | 3 | Both CSRRS and CSRRC always read the addressed CSR and cause any read side |
4 | has a lot going on. | 4 | effects regardless of rs1 and rd fields. Note that if rs1 specifies a register |
5 | holding a zero value other than x0, the instruction will still attempt to write | ||
6 | the unmodified value back to the CSR and will cause any attendant side effects. | ||
5 | 7 | ||
6 | Functions in cpu.c were made public to allow them to be used by the KVM | 8 | So if CSRRS or CSRRC tries to write a read-only CSR with rs1 which specifies |
7 | accelerator class later on. 'cpu_cfg_ext_get_min_version()' is notably | 9 | a register holding a zero value, an illegal instruction exception should be |
8 | hard to move it to another file due to its dependency with isa_edata_arr[] | 10 | raised. |
9 | array, thus make it public and use it as is for now. | ||
10 | 11 | ||
11 | riscv_cpu_validate_set_extensions() is kept public because it's used by | 12 | Signed-off-by: Yu-Ming Chang <yumin686@andestech.com> |
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> | ||
17 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 13 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
18 | Message-ID: <20230925175709.35696-4-dbarboza@ventanamicro.com> | 14 | Message-ID: <20240403070823.80897-1-yumin686@andestech.com> |
19 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | 15 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> |
20 | --- | 16 | --- |
21 | target/riscv/cpu.h | 8 +- | 17 | target/riscv/cpu.h | 4 ++++ |
22 | target/riscv/tcg/tcg-cpu.h | 27 +++ | 18 | target/riscv/csr.c | 51 ++++++++++++++++++++++++++++++++++++---- |
23 | target/riscv/cpu.c | 361 +------------------------------------ | 19 | target/riscv/op_helper.c | 6 ++--- |
24 | target/riscv/csr.c | 1 + | 20 | 3 files changed, 53 insertions(+), 8 deletions(-) |
25 | target/riscv/tcg/tcg-cpu.c | 357 ++++++++++++++++++++++++++++++++++++ | ||
26 | 5 files changed, 397 insertions(+), 357 deletions(-) | ||
27 | create mode 100644 target/riscv/tcg/tcg-cpu.h | ||
28 | 21 | ||
29 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h | 22 | diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h |
30 | index XXXXXXX..XXXXXXX 100644 | 23 | index XXXXXXX..XXXXXXX 100644 |
31 | --- a/target/riscv/cpu.h | 24 | --- a/target/riscv/cpu.h |
32 | +++ b/target/riscv/cpu.h | 25 | +++ b/target/riscv/cpu.h |
33 | @@ -XXX,XX +XXX,XX @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size, | 26 | @@ -XXX,XX +XXX,XX @@ void cpu_get_tb_cpu_state(CPURISCVState *env, vaddr *pc, |
34 | bool probe, uintptr_t retaddr); | 27 | void riscv_cpu_update_mask(CPURISCVState *env); |
35 | char *riscv_isa_string(RISCVCPU *cpu); | 28 | bool riscv_cpu_is_32bit(RISCVCPU *cpu); |
36 | void riscv_cpu_list(void); | 29 | |
37 | -void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp); | 30 | +RISCVException riscv_csrr(CPURISCVState *env, int csrno, |
38 | 31 | + target_ulong *ret_value); | |
39 | #define cpu_list riscv_cpu_list | 32 | RISCVException riscv_csrrw(CPURISCVState *env, int csrno, |
40 | #define cpu_mmu_index riscv_cpu_mmu_index | 33 | target_ulong *ret_value, |
41 | @@ -XXX,XX +XXX,XX @@ enum riscv_pmu_event_idx { | 34 | target_ulong new_value, target_ulong write_mask); |
42 | #include "hw/core/tcg-cpu-ops.h" | 35 | @@ -XXX,XX +XXX,XX @@ typedef RISCVException (*riscv_csr_op_fn)(CPURISCVState *env, int csrno, |
43 | extern const struct TCGCPUOps riscv_tcg_ops; | 36 | target_ulong new_value, |
44 | 37 | target_ulong write_mask); | |
45 | +/* used by tcg/tcg-cpu.c*/ | 38 | |
46 | +void isa_ext_update_enabled(RISCVCPU *cpu, uint32_t ext_offset, bool en); | 39 | +RISCVException riscv_csrr_i128(CPURISCVState *env, int csrno, |
47 | +bool cpu_cfg_ext_is_user_set(uint32_t ext_offset); | 40 | + Int128 *ret_value); |
48 | +bool isa_ext_is_enabled(RISCVCPU *cpu, uint32_t ext_offset); | 41 | RISCVException riscv_csrrw_i128(CPURISCVState *env, int csrno, |
49 | +int cpu_cfg_ext_get_min_version(uint32_t ext_offset); | 42 | Int128 *ret_value, |
50 | +void riscv_cpu_disable_priv_spec_isa_exts(RISCVCPU *cpu); | 43 | Int128 new_value, Int128 write_mask); |
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 | ||
56 | new file mode 100644 | ||
57 | index XXXXXXX..XXXXXXX | ||
58 | --- /dev/null | ||
59 | +++ b/target/riscv/tcg/tcg-cpu.h | ||
60 | @@ -XXX,XX +XXX,XX @@ | ||
61 | +/* | ||
62 | + * riscv TCG cpu class initialization | ||
63 | + * | ||
64 | + * Copyright (c) 2023 Ventana Micro Systems Inc. | ||
65 | + * | ||
66 | + * This library is free software; you can redistribute it and/or | ||
67 | + * modify it under the terms of the GNU Lesser General Public | ||
68 | + * License as published by the Free Software Foundation; either | ||
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/>. | ||
78 | + */ | ||
79 | + | ||
80 | +#ifndef RISCV_TCG_CPU_H | ||
81 | +#define RISCV_TCG_CPU_H | ||
82 | + | ||
83 | +#include "cpu.h" | ||
84 | + | ||
85 | +void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp); | ||
86 | + | ||
87 | +#endif | ||
88 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | ||
89 | index XXXXXXX..XXXXXXX 100644 | ||
90 | --- a/target/riscv/cpu.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 | 44 | diff --git a/target/riscv/csr.c b/target/riscv/csr.c |
499 | index XXXXXXX..XXXXXXX 100644 | 45 | index XXXXXXX..XXXXXXX 100644 |
500 | --- a/target/riscv/csr.c | 46 | --- a/target/riscv/csr.c |
501 | +++ b/target/riscv/csr.c | 47 | +++ b/target/riscv/csr.c |
502 | @@ -XXX,XX +XXX,XX @@ | 48 | @@ -XXX,XX +XXX,XX @@ static RISCVException rmw_seed(CPURISCVState *env, int csrno, |
503 | #include "qemu/log.h" | 49 | |
504 | #include "qemu/timer.h" | 50 | static inline RISCVException riscv_csrrw_check(CPURISCVState *env, |
505 | #include "cpu.h" | 51 | int csrno, |
506 | +#include "tcg/tcg-cpu.h" | 52 | - bool write_mask) |
507 | #include "pmu.h" | 53 | + bool write) |
508 | #include "time_helper.h" | 54 | { |
509 | #include "exec/exec-all.h" | 55 | /* check privileges and return RISCV_EXCP_ILLEGAL_INST if check fails */ |
510 | diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c | 56 | bool read_only = get_field(csrno, 0xC00) == 3; |
511 | index XXXXXXX..XXXXXXX 100644 | 57 | @@ -XXX,XX +XXX,XX @@ static inline RISCVException riscv_csrrw_check(CPURISCVState *env, |
512 | --- a/target/riscv/tcg/tcg-cpu.c | 58 | } |
513 | +++ b/target/riscv/tcg/tcg-cpu.c | 59 | |
514 | @@ -XXX,XX +XXX,XX @@ | 60 | /* read / write check */ |
515 | 61 | - if (write_mask && read_only) { | |
516 | #include "qemu/osdep.h" | 62 | + if (write && read_only) { |
517 | #include "exec/exec-all.h" | 63 | return RISCV_EXCP_ILLEGAL_INST; |
518 | +#include "tcg-cpu.h" | 64 | } |
519 | #include "cpu.h" | 65 | |
520 | #include "pmu.h" | 66 | @@ -XXX,XX +XXX,XX @@ static RISCVException riscv_csrrw_do64(CPURISCVState *env, int csrno, |
521 | #include "time_helper.h" | 67 | return RISCV_EXCP_NONE; |
522 | #include "qapi/error.h" | 68 | } |
523 | #include "qemu/accel.h" | 69 | |
524 | +#include "qemu/error-report.h" | 70 | +RISCVException riscv_csrr(CPURISCVState *env, int csrno, |
525 | +#include "qemu/log.h" | 71 | + target_ulong *ret_value) |
526 | #include "hw/core/accel-cpu.h" | ||
527 | |||
528 | |||
529 | +static void cpu_cfg_ext_auto_update(RISCVCPU *cpu, uint32_t ext_offset, | ||
530 | + bool value) | ||
531 | +{ | 72 | +{ |
532 | + CPURISCVState *env = &cpu->env; | 73 | + RISCVException ret = riscv_csrrw_check(env, csrno, false); |
533 | + bool prev_val = isa_ext_is_enabled(cpu, ext_offset); | 74 | + if (ret != RISCV_EXCP_NONE) { |
534 | + int min_version; | 75 | + return ret; |
535 | + | ||
536 | + if (prev_val == value) { | ||
537 | + return; | ||
538 | + } | 76 | + } |
539 | + | 77 | + |
540 | + if (cpu_cfg_ext_is_user_set(ext_offset)) { | 78 | + return riscv_csrrw_do64(env, csrno, ret_value, 0, 0); |
541 | + return; | 79 | +} |
80 | + | ||
81 | RISCVException riscv_csrrw(CPURISCVState *env, int csrno, | ||
82 | target_ulong *ret_value, | ||
83 | target_ulong new_value, target_ulong write_mask) | ||
84 | { | ||
85 | - RISCVException ret = riscv_csrrw_check(env, csrno, write_mask); | ||
86 | + RISCVException ret = riscv_csrrw_check(env, csrno, true); | ||
87 | if (ret != RISCV_EXCP_NONE) { | ||
88 | return ret; | ||
89 | } | ||
90 | @@ -XXX,XX +XXX,XX @@ static RISCVException riscv_csrrw_do128(CPURISCVState *env, int csrno, | ||
91 | return RISCV_EXCP_NONE; | ||
92 | } | ||
93 | |||
94 | +RISCVException riscv_csrr_i128(CPURISCVState *env, int csrno, | ||
95 | + Int128 *ret_value) | ||
96 | +{ | ||
97 | + RISCVException ret; | ||
98 | + | ||
99 | + ret = riscv_csrrw_check(env, csrno, false); | ||
100 | + if (ret != RISCV_EXCP_NONE) { | ||
101 | + return ret; | ||
542 | + } | 102 | + } |
543 | + | 103 | + |
544 | + if (value && env->priv_ver != PRIV_VERSION_LATEST) { | 104 | + if (csr_ops[csrno].read128) { |
545 | + /* Do not enable it if priv_ver is older than min_version */ | 105 | + return riscv_csrrw_do128(env, csrno, ret_value, |
546 | + min_version = cpu_cfg_ext_get_min_version(ext_offset); | 106 | + int128_zero(), int128_zero()); |
547 | + if (env->priv_ver < min_version) { | ||
548 | + return; | ||
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) | ||
556 | { | ||
557 | if (riscv_has_ext(env, RVH) && env->priv_ver < PRIV_VERSION_1_12_0) { | ||
558 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_validate_priv_spec(RISCVCPU *cpu, Error **errp) | ||
559 | } | ||
560 | } | ||
561 | |||
562 | +static void riscv_cpu_validate_v(CPURISCVState *env, RISCVCPUConfig *cfg, | ||
563 | + Error **errp) | ||
564 | +{ | ||
565 | + if (!is_power_of_2(cfg->vlen)) { | ||
566 | + error_setg(errp, "Vector extension VLEN must be power of 2"); | ||
567 | + return; | ||
568 | + } | ||
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 | + } | 107 | + } |
840 | + | 108 | + |
841 | + /* | 109 | + /* |
842 | + * In principle Zve*x would also suffice here, were they supported | 110 | + * Fall back to 64-bit version for now, if the 128-bit alternative isn't |
843 | + * in qemu | 111 | + * at all defined. |
112 | + * Note, some CSRs don't need to extend to MXLEN (64 upper bits non | ||
113 | + * significant), for those, this fallback is correctly handling the | ||
114 | + * accesses | ||
844 | + */ | 115 | + */ |
845 | + if ((cpu->cfg.ext_zvbb || cpu->cfg.ext_zvkg || cpu->cfg.ext_zvkned || | 116 | + target_ulong old_value; |
846 | + cpu->cfg.ext_zvknha || cpu->cfg.ext_zvksed || cpu->cfg.ext_zvksh) && | 117 | + ret = riscv_csrrw_do64(env, csrno, &old_value, |
847 | + !cpu->cfg.ext_zve32f) { | 118 | + (target_ulong)0, |
848 | + error_setg(errp, | 119 | + (target_ulong)0); |
849 | + "Vector crypto extensions require V or Zve* extensions"); | 120 | + if (ret == RISCV_EXCP_NONE && ret_value) { |
850 | + return; | 121 | + *ret_value = int128_make64(old_value); |
851 | + } | 122 | + } |
852 | + | 123 | + return ret; |
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 | +} | 124 | +} |
889 | + | 125 | + |
890 | /* | 126 | RISCVException riscv_csrrw_i128(CPURISCVState *env, int csrno, |
891 | * We'll get here via the following path: | 127 | Int128 *ret_value, |
892 | * | 128 | Int128 new_value, Int128 write_mask) |
129 | { | ||
130 | RISCVException ret; | ||
131 | |||
132 | - ret = riscv_csrrw_check(env, csrno, int128_nz(write_mask)); | ||
133 | + ret = riscv_csrrw_check(env, csrno, true); | ||
134 | if (ret != RISCV_EXCP_NONE) { | ||
135 | return ret; | ||
136 | } | ||
137 | diff --git a/target/riscv/op_helper.c b/target/riscv/op_helper.c | ||
138 | index XXXXXXX..XXXXXXX 100644 | ||
139 | --- a/target/riscv/op_helper.c | ||
140 | +++ b/target/riscv/op_helper.c | ||
141 | @@ -XXX,XX +XXX,XX @@ target_ulong helper_csrr(CPURISCVState *env, int csr) | ||
142 | } | ||
143 | |||
144 | target_ulong val = 0; | ||
145 | - RISCVException ret = riscv_csrrw(env, csr, &val, 0, 0); | ||
146 | + RISCVException ret = riscv_csrr(env, csr, &val); | ||
147 | |||
148 | if (ret != RISCV_EXCP_NONE) { | ||
149 | riscv_raise_exception(env, ret, GETPC()); | ||
150 | @@ -XXX,XX +XXX,XX @@ target_ulong helper_csrrw(CPURISCVState *env, int csr, | ||
151 | target_ulong helper_csrr_i128(CPURISCVState *env, int csr) | ||
152 | { | ||
153 | Int128 rv = int128_zero(); | ||
154 | - RISCVException ret = riscv_csrrw_i128(env, csr, &rv, | ||
155 | - int128_zero(), | ||
156 | - int128_zero()); | ||
157 | + RISCVException ret = riscv_csrr_i128(env, csr, &rv); | ||
158 | |||
159 | if (ret != RISCV_EXCP_NONE) { | ||
160 | riscv_raise_exception(env, ret, GETPC()); | ||
893 | -- | 161 | -- |
894 | 2.41.0 | 162 | 2.45.1 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
2 | 1 | ||
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: | ||
7 | |||
8 | riscv_cpu_init() -> cpu_init() of each CPU -> .instance_post_init() | ||
9 | |||
10 | In the near future riscv_cpu_post_init() will call the init() function | ||
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> | ||
16 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
17 | Message-ID: <20230925175709.35696-6-dbarboza@ventanamicro.com> | ||
18 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
19 | --- | ||
20 | target/riscv/cpu.c | 43 ++++++++++++++++++++++++++++++++----------- | ||
21 | 1 file changed, 32 insertions(+), 11 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 @@ static void riscv_max_cpu_init(Object *obj) | ||
28 | mlx = MXL_RV32; | ||
29 | #endif | ||
30 | set_misa(env, mlx, 0); | ||
31 | - riscv_cpu_add_user_properties(obj); | ||
32 | - riscv_init_max_cpu_extensions(obj); | ||
33 | env->priv_ver = PRIV_VERSION_LATEST; | ||
34 | #ifndef CONFIG_USER_ONLY | ||
35 | set_satp_mode_max_supported(RISCV_CPU(obj), mlx == MXL_RV32 ? | ||
36 | @@ -XXX,XX +XXX,XX @@ static void rv64_base_cpu_init(Object *obj) | ||
37 | CPURISCVState *env = &RISCV_CPU(obj)->env; | ||
38 | /* We set this in the realise function */ | ||
39 | set_misa(env, MXL_RV64, 0); | ||
40 | - riscv_cpu_add_user_properties(obj); | ||
41 | /* Set latest version of privileged specification */ | ||
42 | env->priv_ver = PRIV_VERSION_LATEST; | ||
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); | ||
65 | } | ||
66 | #endif /* CONFIG_KVM */ | ||
67 | |||
68 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_set_irq(void *opaque, int irq, int level) | ||
69 | } | ||
70 | #endif /* CONFIG_USER_ONLY */ | ||
71 | |||
72 | +static bool riscv_cpu_is_dynamic(Object *cpu_obj) | ||
73 | +{ | ||
74 | + return object_dynamic_cast(cpu_obj, TYPE_RISCV_DYNAMIC_CPU) != NULL; | ||
75 | +} | ||
76 | + | ||
77 | +static bool riscv_cpu_has_max_extensions(Object *cpu_obj) | ||
78 | +{ | ||
79 | + return object_dynamic_cast(cpu_obj, TYPE_RISCV_CPU_MAX) != NULL; | ||
80 | +} | ||
81 | + | ||
82 | +static bool riscv_cpu_has_user_properties(Object *cpu_obj) | ||
83 | +{ | ||
84 | + if (kvm_enabled() && | ||
85 | + object_dynamic_cast(cpu_obj, TYPE_RISCV_CPU_HOST) != NULL) { | ||
86 | + return true; | ||
87 | + } | ||
88 | + | ||
89 | + return riscv_cpu_is_dynamic(cpu_obj); | ||
90 | +} | ||
91 | + | ||
92 | +static void riscv_cpu_post_init(Object *obj) | ||
93 | +{ | ||
94 | + if (riscv_cpu_has_user_properties(obj)) { | ||
95 | + riscv_cpu_add_user_properties(obj); | ||
96 | + } | ||
97 | + | ||
98 | + if (riscv_cpu_has_max_extensions(obj)) { | ||
99 | + riscv_init_max_cpu_extensions(obj); | ||
100 | + } | ||
101 | +} | ||
102 | + | ||
103 | static void riscv_cpu_init(Object *obj) | ||
104 | { | ||
105 | #ifndef CONFIG_USER_ONLY | ||
106 | @@ -XXX,XX +XXX,XX @@ static const struct SysemuCPUOps riscv_sysemu_ops = { | ||
107 | }; | ||
108 | #endif | ||
109 | |||
110 | -static bool riscv_cpu_is_dynamic(Object *cpu_obj) | ||
111 | -{ | ||
112 | - return object_dynamic_cast(cpu_obj, TYPE_RISCV_DYNAMIC_CPU) != NULL; | ||
113 | -} | ||
114 | - | ||
115 | static void cpu_set_mvendorid(Object *obj, Visitor *v, const char *name, | ||
116 | void *opaque, Error **errp) | ||
117 | { | ||
118 | @@ -XXX,XX +XXX,XX @@ static const TypeInfo riscv_cpu_type_infos[] = { | ||
119 | .instance_size = sizeof(RISCVCPU), | ||
120 | .instance_align = __alignof(RISCVCPU), | ||
121 | .instance_init = riscv_cpu_init, | ||
122 | + .instance_post_init = riscv_cpu_post_init, | ||
123 | .abstract = true, | ||
124 | .class_size = sizeof(RISCVCPUClass), | ||
125 | .class_init = riscv_cpu_class_init, | ||
126 | -- | ||
127 | 2.41.0 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
2 | 1 | ||
3 | We'll need to export these arrays to the accelerator classes in the next | ||
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> | ||
14 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
15 | Message-ID: <20230925175709.35696-8-dbarboza@ventanamicro.com> | ||
16 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
17 | --- | ||
18 | target/riscv/cpu.c | 22 +++++++++++++--------- | ||
19 | 1 file changed, 13 insertions(+), 9 deletions(-) | ||
20 | |||
21 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | ||
22 | index XXXXXXX..XXXXXXX 100644 | ||
23 | --- a/target/riscv/cpu.c | ||
24 | +++ b/target/riscv/cpu.c | ||
25 | @@ -XXX,XX +XXX,XX @@ typedef struct RISCVCPUMultiExtConfig { | ||
26 | {.name = _name, .offset = CPU_CFG_OFFSET(_prop), \ | ||
27 | .enabled = _defval} | ||
28 | |||
29 | -static RISCVCPUMultiExtConfig riscv_cpu_extensions[] = { | ||
30 | +static const RISCVCPUMultiExtConfig riscv_cpu_extensions[] = { | ||
31 | /* Defaults for standard extensions */ | ||
32 | MULTI_EXT_CFG_BOOL("sscofpmf", ext_sscofpmf, false), | ||
33 | MULTI_EXT_CFG_BOOL("Zifencei", ext_ifencei, true), | ||
34 | @@ -XXX,XX +XXX,XX @@ static RISCVCPUMultiExtConfig riscv_cpu_extensions[] = { | ||
35 | DEFINE_PROP_END_OF_LIST(), | ||
36 | }; | ||
37 | |||
38 | -static RISCVCPUMultiExtConfig riscv_cpu_vendor_exts[] = { | ||
39 | +static const RISCVCPUMultiExtConfig riscv_cpu_vendor_exts[] = { | ||
40 | MULTI_EXT_CFG_BOOL("xtheadba", ext_xtheadba, false), | ||
41 | MULTI_EXT_CFG_BOOL("xtheadbb", ext_xtheadbb, false), | ||
42 | MULTI_EXT_CFG_BOOL("xtheadbs", ext_xtheadbs, false), | ||
43 | @@ -XXX,XX +XXX,XX @@ static RISCVCPUMultiExtConfig riscv_cpu_vendor_exts[] = { | ||
44 | }; | ||
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); | ||
102 | -- | ||
103 | 2.41.0 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
2 | 1 | ||
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 |
Deleted patch | |||
---|---|---|---|
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
2 | 1 | ||
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 |
Deleted patch | |||
---|---|---|---|
1 | From: Daniel Henrique Barboza <dbarboza@ventanamicro.com> | ||
2 | 1 | ||
3 | This array will be read by the TCG accel class, allowing it to handle | ||
4 | priv spec verifications on its own. The array will remain here in cpu.c | ||
5 | because it's also used by the riscv,isa string function. | ||
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> | ||
15 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
16 | --- | ||
17 | target/riscv/cpu.h | 7 +++++++ | ||
18 | target/riscv/cpu.c | 47 +++++++++++++++++++++------------------------- | ||
19 | 2 files changed, 28 insertions(+), 26 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 @@ extern const RISCVCPUMultiExtConfig riscv_cpu_vendor_exts[]; | ||
26 | extern const RISCVCPUMultiExtConfig riscv_cpu_experimental_exts[]; | ||
27 | extern Property riscv_cpu_options[]; | ||
28 | |||
29 | +typedef struct isa_ext_data { | ||
30 | + const char *name; | ||
31 | + int min_version; | ||
32 | + int ext_enable_offset; | ||
33 | +} RISCVIsaExtData; | ||
34 | +extern const RISCVIsaExtData isa_edata_arr[]; | ||
35 | + | ||
36 | void riscv_add_satp_mode_properties(Object *obj); | ||
37 | |||
38 | /* CSR function table */ | ||
39 | diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c | ||
40 | index XXXXXXX..XXXXXXX 100644 | ||
41 | --- a/target/riscv/cpu.c | ||
42 | +++ b/target/riscv/cpu.c | ||
43 | @@ -XXX,XX +XXX,XX @@ static const char riscv_single_letter_exts[] = "IEMAFDQCPVH"; | ||
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; | ||
99 | } | ||
100 | |||
101 | - return isa_edata_arr[i].min_version; | ||
102 | + return edata->min_version; | ||
103 | } | ||
104 | |||
105 | g_assert_not_reached(); | ||
106 | @@ -XXX,XX +XXX,XX @@ static void riscv_cpu_disas_set_info(CPUState *s, disassemble_info *info) | ||
107 | void riscv_cpu_disable_priv_spec_isa_exts(RISCVCPU *cpu) | ||
108 | { | ||
109 | CPURISCVState *env = &cpu->env; | ||
110 | - int i; | ||
111 | + const RISCVIsaExtData *edata; | ||
112 | |||
113 | /* Force disable extensions if priv spec version does not match */ | ||
114 | - for (i = 0; i < ARRAY_SIZE(isa_edata_arr); i++) { | ||
115 | - if (isa_ext_is_enabled(cpu, isa_edata_arr[i].ext_enable_offset) && | ||
116 | - (env->priv_ver < isa_edata_arr[i].min_version)) { | ||
117 | - isa_ext_update_enabled(cpu, isa_edata_arr[i].ext_enable_offset, | ||
118 | - false); | ||
119 | + for (edata = isa_edata_arr; edata && edata->name; edata++) { | ||
120 | + if (isa_ext_is_enabled(cpu, edata->ext_enable_offset) && | ||
121 | + (env->priv_ver < edata->min_version)) { | ||
122 | + isa_ext_update_enabled(cpu, edata->ext_enable_offset, false); | ||
123 | #ifndef CONFIG_USER_ONLY | ||
124 | warn_report("disabling %s extension for hart 0x" TARGET_FMT_lx | ||
125 | " because privilege spec version does not match", | ||
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 | } | ||
154 | -- | ||
155 | 2.41.0 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Clément Chigot <chigot@adacore.com> | ||
2 | 1 | ||
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 |
Deleted patch | |||
---|---|---|---|
1 | From: Clément Chigot <chigot@adacore.com> | ||
2 | 1 | ||
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 |
Deleted patch | |||
---|---|---|---|
1 | From: Clément Chigot <chigot@adacore.com> | ||
2 | 1 | ||
3 | This replaces the exit calls by shutdown requests, ensuring a proper | ||
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. | ||
8 | |||
9 | Signed-off-by: Clément Chigot <chigot@adacore.com> | ||
10 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
11 | Message-ID: <20231003071427.188697-4-chigot@adacore.com> | ||
12 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
13 | --- | ||
14 | hw/misc/sifive_test.c | 9 +++++++-- | ||
15 | 1 file changed, 7 insertions(+), 2 deletions(-) | ||
16 | |||
17 | diff --git a/hw/misc/sifive_test.c b/hw/misc/sifive_test.c | ||
18 | index XXXXXXX..XXXXXXX 100644 | ||
19 | --- a/hw/misc/sifive_test.c | ||
20 | +++ b/hw/misc/sifive_test.c | ||
21 | @@ -XXX,XX +XXX,XX @@ | ||
22 | #include "qemu/module.h" | ||
23 | #include "sysemu/runstate.h" | ||
24 | #include "hw/misc/sifive_test.h" | ||
25 | +#include "sysemu/sysemu.h" | ||
26 | |||
27 | static uint64_t sifive_test_read(void *opaque, hwaddr addr, unsigned int size) | ||
28 | { | ||
29 | @@ -XXX,XX +XXX,XX @@ static void sifive_test_write(void *opaque, hwaddr addr, | ||
30 | int code = (val64 >> 16) & 0xffff; | ||
31 | switch (status) { | ||
32 | case FINISHER_FAIL: | ||
33 | - exit(code); | ||
34 | + qemu_system_shutdown_request_with_code( | ||
35 | + SHUTDOWN_CAUSE_GUEST_PANIC, code); | ||
36 | + return; | ||
37 | case FINISHER_PASS: | ||
38 | - exit(0); | ||
39 | + qemu_system_shutdown_request_with_code( | ||
40 | + SHUTDOWN_CAUSE_GUEST_SHUTDOWN, code); | ||
41 | + return; | ||
42 | case FINISHER_RESET: | ||
43 | qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET); | ||
44 | return; | ||
45 | -- | ||
46 | 2.41.0 | ||
47 | |||
48 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Clément Chigot <chigot@adacore.com> | ||
2 | 1 | ||
3 | This replaces the exit calls by shutdown requests, ensuring a proper | ||
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. | ||
8 | |||
9 | Signed-off-by: Clément Chigot <chigot@adacore.com> | ||
10 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
11 | Message-ID: <20231003071427.188697-5-chigot@adacore.com> | ||
12 | Signed-off-by: Alistair Francis <alistair.francis@wdc.com> | ||
13 | --- | ||
14 | hw/char/riscv_htif.c | 5 ++++- | ||
15 | 1 file changed, 4 insertions(+), 1 deletion(-) | ||
16 | |||
17 | diff --git a/hw/char/riscv_htif.c b/hw/char/riscv_htif.c | ||
18 | index XXXXXXX..XXXXXXX 100644 | ||
19 | --- a/hw/char/riscv_htif.c | ||
20 | +++ b/hw/char/riscv_htif.c | ||
21 | @@ -XXX,XX +XXX,XX @@ | ||
22 | #include "exec/address-spaces.h" | ||
23 | #include "exec/tswap.h" | ||
24 | #include "sysemu/dma.h" | ||
25 | +#include "sysemu/runstate.h" | ||
26 | |||
27 | #define RISCV_DEBUG_HTIF 0 | ||
28 | #define HTIF_DEBUG(fmt, ...) \ | ||
29 | @@ -XXX,XX +XXX,XX @@ static void htif_handle_tohost_write(HTIFState *s, uint64_t val_written) | ||
30 | g_free(sig_data); | ||
31 | } | ||
32 | |||
33 | - exit(exit_code); | ||
34 | + qemu_system_shutdown_request_with_code( | ||
35 | + SHUTDOWN_CAUSE_GUEST_SHUTDOWN, exit_code); | ||
36 | + return; | ||
37 | } else { | ||
38 | uint64_t syscall[8]; | ||
39 | cpu_physical_memory_read(payload, syscall, sizeof(syscall)); | ||
40 | -- | ||
41 | 2.41.0 | ||
42 | |||
43 | diff view generated by jsdifflib |