1
From: Alistair Francis <alistair.francis@wdc.com>
1
The following changes since commit a51e5124a655b3dad80b36b18547cb1eca2c5eb2:
2
2
3
The following changes since commit c5fbdd60cf1fb52f01bdfe342b6fa65d5343e1b1:
3
Merge tag 'pull-omnibus-111023-1' of https://gitlab.com/stsquad/qemu into staging (2023-10-11 09:43:10 -0400)
4
5
Merge tag 'qemu-sparc-20211121' of git://github.com/mcayland/qemu into staging (2021-11-21 14:12:25 +0100)
6
4
7
are available in the Git repository at:
5
are available in the Git repository at:
8
6
9
git@github.com:alistair23/qemu.git tags/pull-riscv-to-apply-20211122
7
https://github.com/alistair23/qemu.git tags/pull-riscv-to-apply-20231012-1
10
8
11
for you to fetch changes up to 526e7443027c71fe7b04c29df529e1f9f425f9e3:
9
for you to fetch changes up to 837570cef237b634eb4c245363470deebea7089d:
12
10
13
hw/misc/sifive_u_otp: Do not reset OTP content on hardware reset (2021-11-22 10:46:22 +1000)
11
target/riscv: Fix vfwmaccbf16.vf (2023-10-12 12:50:13 +1000)
14
12
15
----------------------------------------------------------------
13
----------------------------------------------------------------
16
Seventh RISC-V PR for QEMU 6.2
14
Second RISC-V PR for 8.2
17
15
18
- Deprecate IF_NONE for SiFive OTP
16
* Add support for the max CPU
19
- Don't reset SiFive OTP content
17
* Detect user choice in TCG
18
* Clear CSR values at reset and sync MPSTATE with host
19
* Fix the typo of inverted order of pmpaddr13 and pmpaddr14
20
* Split TCG/KVM accelerators from cpu.c
21
* Add extension properties for all cpus
22
* Replace GDB exit calls with proper shutdown
23
* Support KVM_GET_REG_LIST
24
* Remove RVG warning
25
* Use env_archcpu for better performance
26
* Deprecate capital 'Z' CPU properties
27
* Fix vfwmaccbf16.vf
20
28
21
----------------------------------------------------------------
29
----------------------------------------------------------------
22
Philippe Mathieu-Daudé (1):
30
Alvin Chang (1):
23
hw/misc/sifive_u_otp: Do not reset OTP content on hardware reset
31
disas/riscv: Fix the typo of inverted order of pmpaddr13 and pmpaddr14
24
32
25
Thomas Huth (1):
33
Clément Chigot (5):
26
hw/misc/sifive_u_otp: Use IF_PFLASH for the OTP device instead of IF_NONE
34
softmmu: add means to pass an exit code when requesting a shutdown
35
softmmu: pass the main loop status to gdb "Wxx" packet
36
hw/misc/sifive_test.c: replace exit calls with proper shutdown
37
hw/char: riscv_htif: replace exit calls with proper shutdown
38
gdbstub: replace exit calls with proper shutdown for softmmu
27
39
28
docs/about/deprecated.rst | 6 ++++++
40
Daniel Henrique Barboza (45):
29
hw/misc/sifive_u_otp.c | 22 +++++++++++++---------
41
target/riscv/cpu.c: split CPU options from riscv_cpu_extensions[]
30
2 files changed, 19 insertions(+), 9 deletions(-)
42
target/riscv/cpu.c: skip 'bool' check when filtering KVM props
43
target/riscv/cpu.c: split kvm prop handling to its own helper
44
target/riscv: add DEFINE_PROP_END_OF_LIST() to riscv_cpu_options[]
45
target/riscv/cpu.c: split non-ratified exts from riscv_cpu_extensions[]
46
target/riscv/cpu.c: split vendor exts from riscv_cpu_extensions[]
47
target/riscv/cpu.c: add riscv_cpu_add_qdev_prop_array()
48
target/riscv/cpu.c: add riscv_cpu_add_kvm_unavail_prop_array()
49
target/riscv/cpu.c: limit cfg->vext_spec log message
50
target/riscv: add 'max' CPU type
51
avocado, risc-v: add tuxboot tests for 'max' CPU
52
target/riscv: deprecate the 'any' CPU type
53
target/riscv/cpu.c: use offset in isa_ext_is_enabled/update_enabled
54
target/riscv: make CPUCFG() macro public
55
target/riscv/cpu.c: introduce cpu_cfg_ext_auto_update()
56
target/riscv/cpu.c: use cpu_cfg_ext_auto_update() during realize()
57
target/riscv/cpu.c: introduce RISCVCPUMultiExtConfig
58
target/riscv: use isa_ext_update_enabled() in init_max_cpu_extensions()
59
target/riscv/cpu.c: honor user choice in cpu_cfg_ext_auto_update()
60
target/riscv/cpu.c: consider user option with RVG
61
target/riscv: introduce TCG AccelCPUClass
62
target/riscv: move riscv_cpu_realize_tcg() to TCG::cpu_realizefn()
63
target/riscv: move riscv_cpu_validate_set_extensions() to tcg-cpu.c
64
target/riscv: move riscv_tcg_ops to tcg-cpu.c
65
target/riscv/cpu.c: add .instance_post_init()
66
target/riscv: move 'host' CPU declaration to kvm.c
67
target/riscv/cpu.c: mark extensions arrays as 'const'
68
target/riscv: move riscv_cpu_add_kvm_properties() to kvm.c
69
target/riscv: make riscv_add_satp_mode_properties() public
70
target/riscv: remove kvm-stub.c
71
target/riscv: introduce KVM AccelCPUClass
72
target/riscv: move KVM only files to kvm subdir
73
target/riscv/kvm: do not use riscv_cpu_add_misa_properties()
74
target/riscv/cpu.c: export set_misa()
75
target/riscv/tcg: introduce tcg_cpu_instance_init()
76
target/riscv/cpu.c: make misa_ext_cfgs[] 'const'
77
target/riscv/tcg: move riscv_cpu_add_misa_properties() to tcg-cpu.c
78
target/riscv/cpu.c: export isa_edata_arr[]
79
target/riscv/cpu: move priv spec functions to tcg-cpu.c
80
target/riscv: add riscv_cpu_get_name()
81
target/riscv/tcg-cpu.c: add extension properties for all cpus
82
target/riscv/kvm: improve 'init_multiext_cfg' error msg
83
target/riscv/kvm: support KVM_GET_REG_LIST
84
target/riscv/tcg: remove RVG warning
85
target/riscv: deprecate capital 'Z' CPU properties
31
86
87
Max Chou (1):
88
target/riscv: Fix vfwmaccbf16.vf
89
90
Richard W.M. Jones (1):
91
target/riscv: Use env_archcpu for better performance
92
93
liguang.zhang (1):
94
target/riscv: Clear CSR values at reset and sync MPSTATE with host
95
96
docs/about/deprecated.rst | 35 ++
97
include/gdbstub/syscalls.h | 9 +
98
include/sysemu/runstate.h | 2 +
99
include/sysemu/sysemu.h | 2 +-
100
target/riscv/cpu-qom.h | 1 +
101
target/riscv/cpu.h | 34 +-
102
target/riscv/{ => kvm}/kvm_riscv.h | 2 +-
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
diff view generated by jsdifflib
New patch
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
2
3
We'll add a new CPU type that will enable a considerable amount of
4
extensions. To make it easier for us we'll do a few cleanups in our
5
existing riscv_cpu_extensions[] array.
6
7
Start by splitting all CPU non-boolean options from it. Create a new
8
riscv_cpu_options[] array for them. Add all these properties in
9
riscv_cpu_add_user_properties() as it is already being done today.
10
11
'mmu' and 'pmp' aren't really extensions in the usual way we think about
12
RISC-V extensions. These are closer to CPU features/options, so move
13
both to riscv_cpu_options[] too. In the near future we'll need to match
14
all extensions with all entries in isa_edata_arr[], and so it happens
15
that both 'mmu' and 'pmp' do not have a riscv,isa string (thus, no priv
16
spec version restriction). This further emphasizes the point that these
17
are more a CPU option than an extension.
18
19
No functional changes made.
20
21
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
22
Reviewed-by: Weiwei Li <liweiwei@iscas.ac.cn>
23
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
24
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
25
Message-ID: <20230912132423.268494-2-dbarboza@ventanamicro.com>
26
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
27
---
28
target/riscv/cpu.c | 33 +++++++++++++++++++++++----------
29
1 file changed, 23 insertions(+), 10 deletions(-)
30
31
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
32
index XXXXXXX..XXXXXXX 100644
33
--- a/target/riscv/cpu.c
34
+++ b/target/riscv/cpu.c
35
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_add_misa_properties(Object *cpu_obj)
36
37
static Property riscv_cpu_extensions[] = {
38
/* Defaults for standard extensions */
39
- DEFINE_PROP_UINT8("pmu-num", RISCVCPU, cfg.pmu_num, 16),
40
DEFINE_PROP_BOOL("sscofpmf", RISCVCPU, cfg.ext_sscofpmf, false),
41
DEFINE_PROP_BOOL("Zifencei", RISCVCPU, cfg.ext_ifencei, true),
42
DEFINE_PROP_BOOL("Zicsr", RISCVCPU, cfg.ext_icsr, true),
43
@@ -XXX,XX +XXX,XX @@ static Property riscv_cpu_extensions[] = {
44
DEFINE_PROP_BOOL("Zve32f", RISCVCPU, cfg.ext_zve32f, false),
45
DEFINE_PROP_BOOL("Zve64f", RISCVCPU, cfg.ext_zve64f, false),
46
DEFINE_PROP_BOOL("Zve64d", RISCVCPU, cfg.ext_zve64d, false),
47
- DEFINE_PROP_BOOL("mmu", RISCVCPU, cfg.mmu, true),
48
- DEFINE_PROP_BOOL("pmp", RISCVCPU, cfg.pmp, true),
49
DEFINE_PROP_BOOL("sstc", RISCVCPU, cfg.ext_sstc, true),
50
51
- DEFINE_PROP_STRING("priv_spec", RISCVCPU, cfg.priv_spec),
52
- DEFINE_PROP_STRING("vext_spec", RISCVCPU, cfg.vext_spec),
53
- DEFINE_PROP_UINT16("vlen", RISCVCPU, cfg.vlen, 128),
54
- DEFINE_PROP_UINT16("elen", RISCVCPU, cfg.elen, 64),
55
-
56
DEFINE_PROP_BOOL("smstateen", RISCVCPU, cfg.ext_smstateen, false),
57
DEFINE_PROP_BOOL("svadu", RISCVCPU, cfg.ext_svadu, true),
58
DEFINE_PROP_BOOL("svinval", RISCVCPU, cfg.ext_svinval, false),
59
@@ -XXX,XX +XXX,XX @@ static Property riscv_cpu_extensions[] = {
60
DEFINE_PROP_BOOL("zhinxmin", RISCVCPU, cfg.ext_zhinxmin, false),
61
62
DEFINE_PROP_BOOL("zicbom", RISCVCPU, cfg.ext_icbom, true),
63
- DEFINE_PROP_UINT16("cbom_blocksize", RISCVCPU, cfg.cbom_blocksize, 64),
64
DEFINE_PROP_BOOL("zicboz", RISCVCPU, cfg.ext_icboz, true),
65
- DEFINE_PROP_UINT16("cboz_blocksize", RISCVCPU, cfg.cboz_blocksize, 64),
66
67
DEFINE_PROP_BOOL("zmmul", RISCVCPU, cfg.ext_zmmul, false),
68
69
@@ -XXX,XX +XXX,XX @@ static Property riscv_cpu_extensions[] = {
70
DEFINE_PROP_END_OF_LIST(),
71
};
72
73
+static Property riscv_cpu_options[] = {
74
+ DEFINE_PROP_UINT8("pmu-num", RISCVCPU, cfg.pmu_num, 16),
75
+
76
+ DEFINE_PROP_BOOL("mmu", RISCVCPU, cfg.mmu, true),
77
+ DEFINE_PROP_BOOL("pmp", RISCVCPU, cfg.pmp, true),
78
+
79
+ DEFINE_PROP_STRING("priv_spec", RISCVCPU, cfg.priv_spec),
80
+ DEFINE_PROP_STRING("vext_spec", RISCVCPU, cfg.vext_spec),
81
+
82
+ DEFINE_PROP_UINT16("vlen", RISCVCPU, cfg.vlen, 128),
83
+ DEFINE_PROP_UINT16("elen", RISCVCPU, cfg.elen, 64),
84
+
85
+ DEFINE_PROP_UINT16("cbom_blocksize", RISCVCPU, cfg.cbom_blocksize, 64),
86
+ DEFINE_PROP_UINT16("cboz_blocksize", RISCVCPU, cfg.cboz_blocksize, 64),
87
+};
88
89
#ifndef CONFIG_USER_ONLY
90
static void cpu_set_cfg_unavailable(Object *obj, Visitor *v,
91
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_add_user_properties(Object *obj)
92
#endif
93
qdev_property_add_static(dev, prop);
94
}
95
+
96
+ for (int i = 0; i < ARRAY_SIZE(riscv_cpu_options); i++) {
97
+ /* Check if KVM created the property already */
98
+ if (object_property_find(obj, riscv_cpu_options[i].name)) {
99
+ continue;
100
+ }
101
+ qdev_property_add_static(dev, &riscv_cpu_options[i]);
102
+ }
103
}
104
105
static Property riscv_cpu_properties[] = {
106
--
107
2.41.0
diff view generated by jsdifflib
New patch
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
2
3
After the introduction of riscv_cpu_options[] all properties in
4
riscv_cpu_extensions[] are booleans. This check is now obsolete.
5
6
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
7
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
8
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
9
Message-ID: <20230912132423.268494-3-dbarboza@ventanamicro.com>
10
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
11
---
12
target/riscv/cpu.c | 14 ++++----------
13
1 file changed, 4 insertions(+), 10 deletions(-)
14
15
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
16
index XXXXXXX..XXXXXXX 100644
17
--- a/target/riscv/cpu.c
18
+++ b/target/riscv/cpu.c
19
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_add_user_properties(Object *obj)
20
* Set the default to disabled for every extension
21
* unknown to KVM and error out if the user attempts
22
* to enable any of them.
23
- *
24
- * We're giving a pass for non-bool properties since they're
25
- * not related to the availability of extensions and can be
26
- * safely ignored as is.
27
*/
28
- if (prop->info == &qdev_prop_bool) {
29
- object_property_add(obj, prop->name, "bool",
30
- NULL, cpu_set_cfg_unavailable,
31
- NULL, (void *)prop->name);
32
- continue;
33
- }
34
+ object_property_add(obj, prop->name, "bool",
35
+ NULL, cpu_set_cfg_unavailable,
36
+ NULL, (void *)prop->name);
37
+ continue;
38
}
39
#endif
40
qdev_property_add_static(dev, prop);
41
--
42
2.41.0
diff view generated by jsdifflib
New patch
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
2
3
Future patches will split the existing Property arrays even further, and
4
the existing code in riscv_cpu_add_user_properties() will start to scale
5
bad with it because it's dealing with KVM constraints mixed in with TCG
6
constraints. We're going to pay a high price to share a couple of common
7
lines of code between the two.
8
9
Create a new kvm_riscv_cpu_add_kvm_properties() helper that will be
10
forked from riscv_cpu_add_user_properties() if we're running KVM. The
11
helper includes all properties that a KVM CPU will add. The rest of
12
riscv_cpu_add_user_properties() body will then be relieved from having
13
to deal with KVM constraints.
14
15
The helper was declared in kvm_stubs.h, while being implemented in
16
cpu.c, to allow '--enable-debug' builds to work. The compiler won't
17
remove the kvm_riscv_cpu_add_kvm_properties() reference when
18
'kvm_enabled()' is false if we end up with an unused function. Even
19
though being a KVM only helper we can't implement it in kvm.c due to its
20
many dependencies inside cpu.c, so make it public in kvm_riscv.h and
21
keep its implementation in cpu.c for now. We'll move it to kvm.c in the
22
near future.
23
24
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
25
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
26
Message-ID: <20230912132423.268494-4-dbarboza@ventanamicro.com>
27
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
28
---
29
target/riscv/kvm_riscv.h | 3 ++
30
target/riscv/cpu.c | 65 +++++++++++++++++++++++++---------------
31
2 files changed, 44 insertions(+), 24 deletions(-)
32
33
diff --git a/target/riscv/kvm_riscv.h b/target/riscv/kvm_riscv.h
34
index XXXXXXX..XXXXXXX 100644
35
--- a/target/riscv/kvm_riscv.h
36
+++ b/target/riscv/kvm_riscv.h
37
@@ -XXX,XX +XXX,XX @@
38
#ifndef QEMU_KVM_RISCV_H
39
#define QEMU_KVM_RISCV_H
40
41
+/* Temporarily implemented in cpu.c */
42
+void kvm_riscv_cpu_add_kvm_properties(Object *obj);
43
+
44
void kvm_riscv_init_user_properties(Object *cpu_obj);
45
void kvm_riscv_reset_vcpu(RISCVCPU *cpu);
46
void kvm_riscv_set_irq(RISCVCPU *cpu, int irq, int level);
47
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
48
index XXXXXXX..XXXXXXX 100644
49
--- a/target/riscv/cpu.c
50
+++ b/target/riscv/cpu.c
51
@@ -XXX,XX +XXX,XX @@ static Property riscv_cpu_options[] = {
52
DEFINE_PROP_UINT16("cboz_blocksize", RISCVCPU, cfg.cboz_blocksize, 64),
53
};
54
55
-#ifndef CONFIG_USER_ONLY
56
+#ifdef CONFIG_KVM
57
static void cpu_set_cfg_unavailable(Object *obj, Visitor *v,
58
const char *name,
59
void *opaque, Error **errp)
60
@@ -XXX,XX +XXX,XX @@ static void cpu_set_cfg_unavailable(Object *obj, Visitor *v,
61
propname);
62
}
63
}
64
+
65
+static void riscv_cpu_add_kvm_unavail_prop(Object *obj, const char *prop_name)
66
+{
67
+ /* Check if KVM created the property already */
68
+ if (object_property_find(obj, prop_name)) {
69
+ return;
70
+ }
71
+
72
+ /*
73
+ * Set the default to disabled for every extension
74
+ * unknown to KVM and error out if the user attempts
75
+ * to enable any of them.
76
+ */
77
+ object_property_add(obj, prop_name, "bool",
78
+ NULL, cpu_set_cfg_unavailable,
79
+ NULL, (void *)prop_name);
80
+}
81
+
82
+void kvm_riscv_cpu_add_kvm_properties(Object *obj)
83
+{
84
+ Property *prop;
85
+ DeviceState *dev = DEVICE(obj);
86
+
87
+ kvm_riscv_init_user_properties(obj);
88
+ riscv_cpu_add_misa_properties(obj);
89
+
90
+ for (prop = riscv_cpu_extensions; prop && prop->name; prop++) {
91
+ riscv_cpu_add_kvm_unavail_prop(obj, prop->name);
92
+ }
93
+
94
+ for (int i = 0; i < ARRAY_SIZE(riscv_cpu_options); i++) {
95
+ /* Check if KVM created the property already */
96
+ if (object_property_find(obj, riscv_cpu_options[i].name)) {
97
+ continue;
98
+ }
99
+ qdev_property_add_static(dev, &riscv_cpu_options[i]);
100
+ }
101
+}
102
#endif
103
104
/*
105
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_add_user_properties(Object *obj)
106
riscv_add_satp_mode_properties(obj);
107
108
if (kvm_enabled()) {
109
- kvm_riscv_init_user_properties(obj);
110
+ kvm_riscv_cpu_add_kvm_properties(obj);
111
+ return;
112
}
113
#endif
114
115
riscv_cpu_add_misa_properties(obj);
116
117
for (prop = riscv_cpu_extensions; prop && prop->name; prop++) {
118
-#ifndef CONFIG_USER_ONLY
119
- if (kvm_enabled()) {
120
- /* Check if KVM created the property already */
121
- if (object_property_find(obj, prop->name)) {
122
- continue;
123
- }
124
-
125
- /*
126
- * Set the default to disabled for every extension
127
- * unknown to KVM and error out if the user attempts
128
- * to enable any of them.
129
- */
130
- object_property_add(obj, prop->name, "bool",
131
- NULL, cpu_set_cfg_unavailable,
132
- NULL, (void *)prop->name);
133
- continue;
134
- }
135
-#endif
136
qdev_property_add_static(dev, prop);
137
}
138
139
for (int i = 0; i < ARRAY_SIZE(riscv_cpu_options); i++) {
140
- /* Check if KVM created the property already */
141
- if (object_property_find(obj, riscv_cpu_options[i].name)) {
142
- continue;
143
- }
144
qdev_property_add_static(dev, &riscv_cpu_options[i]);
145
}
146
}
147
--
148
2.41.0
diff view generated by jsdifflib
New patch
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
2
3
Add DEFINE_PROP_END_OF_LIST() and eliminate the ARRAY_SIZE() usage when
4
iterating in the riscv_cpu_options[] array, making it similar to what
5
we already do when working with riscv_cpu_extensions[].
6
7
We also have a more sophisticated motivation behind this change. In the
8
future we might need to export riscv_cpu_options[] to other files, and
9
ARRAY_LIST() doesn't work properly in that case because the array size
10
isn't exposed to the header file. Here's a future sight of what we would
11
deal with:
12
13
./target/riscv/kvm.c:1057:5: error: nested extern declaration of 'riscv_cpu_add_misa_properties' [-Werror=nested-externs]
14
n file included from ../target/riscv/kvm.c:19:
15
home/danielhb/work/qemu/include/qemu/osdep.h:473:31: error: invalid application of 'sizeof' to incomplete type 'const RISCVCPUMultiExtConfig[]'
16
473 | #define ARRAY_SIZE(x) ((sizeof(x) / sizeof((x)[0])) + \
17
| ^
18
./target/riscv/kvm.c:1047:29: note: in expansion of macro 'ARRAY_SIZE'
19
1047 | for (int i = 0; i < ARRAY_SIZE(_array); i++) { \
20
| ^~~~~~~~~~
21
./target/riscv/kvm.c:1059:5: note: in expansion of macro 'ADD_UNAVAIL_KVM_PROP_ARRAY'
22
1059 | ADD_UNAVAIL_KVM_PROP_ARRAY(obj, riscv_cpu_extensions);
23
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
24
home/danielhb/work/qemu/include/qemu/osdep.h:473:31: error: invalid application of 'sizeof' to incomplete type 'const RISCVCPUMultiExtConfig[]'
25
473 | #define ARRAY_SIZE(x) ((sizeof(x) / sizeof((x)[0])) + \
26
| ^
27
./target/riscv/kvm.c:1047:29: note: in expansion of macro 'ARRAY_SIZE'
28
1047 | for (int i = 0; i < ARRAY_SIZE(_array); i++) { \
29
30
Homogenize the present and change the future by using
31
DEFINE_PROP_END_OF_LIST() in riscv_cpu_options[].
32
33
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
34
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
35
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
36
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
37
Message-ID: <20230912132423.268494-5-dbarboza@ventanamicro.com>
38
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
39
---
40
target/riscv/cpu.c | 12 +++++++-----
41
1 file changed, 7 insertions(+), 5 deletions(-)
42
43
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
44
index XXXXXXX..XXXXXXX 100644
45
--- a/target/riscv/cpu.c
46
+++ b/target/riscv/cpu.c
47
@@ -XXX,XX +XXX,XX @@ static Property riscv_cpu_options[] = {
48
49
DEFINE_PROP_UINT16("cbom_blocksize", RISCVCPU, cfg.cbom_blocksize, 64),
50
DEFINE_PROP_UINT16("cboz_blocksize", RISCVCPU, cfg.cboz_blocksize, 64),
51
+
52
+ DEFINE_PROP_END_OF_LIST(),
53
};
54
55
#ifdef CONFIG_KVM
56
@@ -XXX,XX +XXX,XX @@ void kvm_riscv_cpu_add_kvm_properties(Object *obj)
57
riscv_cpu_add_kvm_unavail_prop(obj, prop->name);
58
}
59
60
- for (int i = 0; i < ARRAY_SIZE(riscv_cpu_options); i++) {
61
+ for (prop = riscv_cpu_options; prop && prop->name; prop++) {
62
/* Check if KVM created the property already */
63
- if (object_property_find(obj, riscv_cpu_options[i].name)) {
64
+ if (object_property_find(obj, prop->name)) {
65
continue;
66
}
67
- qdev_property_add_static(dev, &riscv_cpu_options[i]);
68
+ qdev_property_add_static(dev, prop);
69
}
70
}
71
#endif
72
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_add_user_properties(Object *obj)
73
qdev_property_add_static(dev, prop);
74
}
75
76
- for (int i = 0; i < ARRAY_SIZE(riscv_cpu_options); i++) {
77
- qdev_property_add_static(dev, &riscv_cpu_options[i]);
78
+ for (prop = riscv_cpu_options; prop && prop->name; prop++) {
79
+ qdev_property_add_static(dev, prop);
80
}
81
}
82
83
--
84
2.41.0
85
86
diff view generated by jsdifflib
New patch
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
2
3
Create a new riscv_cpu_experimental_exts[] to store the non-ratified
4
extensions properties. Once they are ratified we'll move them back to
5
riscv_cpu_extensions[].
6
7
riscv_cpu_add_user_properties() and riscv_cpu_add_kvm_properties() are
8
changed to keep adding non-ratified properties to users.
9
10
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
11
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
12
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
13
Message-ID: <20230912132423.268494-6-dbarboza@ventanamicro.com>
14
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
15
---
16
target/riscv/cpu.c | 13 ++++++++++++-
17
1 file changed, 12 insertions(+), 1 deletion(-)
18
19
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
20
index XXXXXXX..XXXXXXX 100644
21
--- a/target/riscv/cpu.c
22
+++ b/target/riscv/cpu.c
23
@@ -XXX,XX +XXX,XX @@ static Property riscv_cpu_extensions[] = {
24
DEFINE_PROP_BOOL("xtheadsync", RISCVCPU, cfg.ext_xtheadsync, false),
25
DEFINE_PROP_BOOL("xventanacondops", RISCVCPU, cfg.ext_XVentanaCondOps, false),
26
27
- /* These are experimental so mark with 'x-' */
28
+ DEFINE_PROP_END_OF_LIST(),
29
+};
30
31
+/* These are experimental so mark with 'x-' */
32
+static Property riscv_cpu_experimental_exts[] = {
33
/* ePMP 0.9.3 */
34
DEFINE_PROP_BOOL("x-epmp", RISCVCPU, cfg.epmp, false),
35
DEFINE_PROP_BOOL("x-smaia", RISCVCPU, cfg.ext_smaia, false),
36
@@ -XXX,XX +XXX,XX @@ void kvm_riscv_cpu_add_kvm_properties(Object *obj)
37
riscv_cpu_add_kvm_unavail_prop(obj, prop->name);
38
}
39
40
+ for (prop = riscv_cpu_experimental_exts; prop && prop->name; prop++) {
41
+ riscv_cpu_add_kvm_unavail_prop(obj, prop->name);
42
+ }
43
+
44
for (prop = riscv_cpu_options; prop && prop->name; prop++) {
45
/* Check if KVM created the property already */
46
if (object_property_find(obj, prop->name)) {
47
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_add_user_properties(Object *obj)
48
for (prop = riscv_cpu_options; prop && prop->name; prop++) {
49
qdev_property_add_static(dev, prop);
50
}
51
+
52
+ for (prop = riscv_cpu_experimental_exts; prop && prop->name; prop++) {
53
+ qdev_property_add_static(dev, prop);
54
+ }
55
}
56
57
static Property riscv_cpu_properties[] = {
58
--
59
2.41.0
diff view generated by jsdifflib
New patch
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
2
3
Our goal is to make riscv_cpu_extensions[] hold only ratified,
4
non-vendor extensions.
5
6
Create a new riscv_cpu_vendor_exts[] array for them, changing
7
riscv_cpu_add_user_properties() and riscv_cpu_add_kvm_properties()
8
accordingly.
9
10
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
11
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
12
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
13
Message-ID: <20230912132423.268494-7-dbarboza@ventanamicro.com>
14
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
15
---
16
target/riscv/cpu.c | 13 ++++++++++++-
17
1 file changed, 12 insertions(+), 1 deletion(-)
18
19
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
20
index XXXXXXX..XXXXXXX 100644
21
--- a/target/riscv/cpu.c
22
+++ b/target/riscv/cpu.c
23
@@ -XXX,XX +XXX,XX @@ static Property riscv_cpu_extensions[] = {
24
DEFINE_PROP_BOOL("zcmt", RISCVCPU, cfg.ext_zcmt, false),
25
DEFINE_PROP_BOOL("zicond", RISCVCPU, cfg.ext_zicond, false),
26
27
- /* Vendor-specific custom extensions */
28
+ DEFINE_PROP_END_OF_LIST(),
29
+};
30
+
31
+static Property riscv_cpu_vendor_exts[] = {
32
DEFINE_PROP_BOOL("xtheadba", RISCVCPU, cfg.ext_xtheadba, false),
33
DEFINE_PROP_BOOL("xtheadbb", RISCVCPU, cfg.ext_xtheadbb, false),
34
DEFINE_PROP_BOOL("xtheadbs", RISCVCPU, cfg.ext_xtheadbs, false),
35
@@ -XXX,XX +XXX,XX @@ void kvm_riscv_cpu_add_kvm_properties(Object *obj)
36
riscv_cpu_add_kvm_unavail_prop(obj, prop->name);
37
}
38
39
+ for (prop = riscv_cpu_vendor_exts; prop && prop->name; prop++) {
40
+ riscv_cpu_add_kvm_unavail_prop(obj, prop->name);
41
+ }
42
+
43
for (prop = riscv_cpu_experimental_exts; prop && prop->name; prop++) {
44
riscv_cpu_add_kvm_unavail_prop(obj, prop->name);
45
}
46
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_add_user_properties(Object *obj)
47
qdev_property_add_static(dev, prop);
48
}
49
50
+ for (prop = riscv_cpu_vendor_exts; prop && prop->name; prop++) {
51
+ qdev_property_add_static(dev, prop);
52
+ }
53
+
54
for (prop = riscv_cpu_experimental_exts; prop && prop->name; prop++) {
55
qdev_property_add_static(dev, prop);
56
}
57
--
58
2.41.0
diff view generated by jsdifflib
New patch
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
2
3
The code inside riscv_cpu_add_user_properties() became quite repetitive
4
after recent changes. Add a helper to hide the repetition away.
5
6
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
7
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
8
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
9
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
10
Message-ID: <20230912132423.268494-8-dbarboza@ventanamicro.com>
11
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
12
---
13
target/riscv/cpu.c | 29 +++++++++++++----------------
14
1 file changed, 13 insertions(+), 16 deletions(-)
15
16
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
17
index XXXXXXX..XXXXXXX 100644
18
--- a/target/riscv/cpu.c
19
+++ b/target/riscv/cpu.c
20
@@ -XXX,XX +XXX,XX @@ static Property riscv_cpu_options[] = {
21
DEFINE_PROP_END_OF_LIST(),
22
};
23
24
+static void riscv_cpu_add_qdev_prop_array(DeviceState *dev, Property *array)
25
+{
26
+ g_assert(array);
27
+
28
+ for (Property *prop = array; prop && prop->name; prop++) {
29
+ qdev_property_add_static(dev, prop);
30
+ }
31
+}
32
+
33
#ifdef CONFIG_KVM
34
static void cpu_set_cfg_unavailable(Object *obj, Visitor *v,
35
const char *name,
36
@@ -XXX,XX +XXX,XX @@ void kvm_riscv_cpu_add_kvm_properties(Object *obj)
37
*/
38
static void riscv_cpu_add_user_properties(Object *obj)
39
{
40
- Property *prop;
41
DeviceState *dev = DEVICE(obj);
42
43
#ifndef CONFIG_USER_ONLY
44
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_add_user_properties(Object *obj)
45
46
riscv_cpu_add_misa_properties(obj);
47
48
- for (prop = riscv_cpu_extensions; prop && prop->name; prop++) {
49
- qdev_property_add_static(dev, prop);
50
- }
51
-
52
- for (prop = riscv_cpu_options; prop && prop->name; prop++) {
53
- qdev_property_add_static(dev, prop);
54
- }
55
-
56
- for (prop = riscv_cpu_vendor_exts; prop && prop->name; prop++) {
57
- qdev_property_add_static(dev, prop);
58
- }
59
-
60
- for (prop = riscv_cpu_experimental_exts; prop && prop->name; prop++) {
61
- qdev_property_add_static(dev, prop);
62
- }
63
+ riscv_cpu_add_qdev_prop_array(dev, riscv_cpu_extensions);
64
+ riscv_cpu_add_qdev_prop_array(dev, riscv_cpu_options);
65
+ riscv_cpu_add_qdev_prop_array(dev, riscv_cpu_vendor_exts);
66
+ riscv_cpu_add_qdev_prop_array(dev, riscv_cpu_experimental_exts);
67
}
68
69
static Property riscv_cpu_properties[] = {
70
--
71
2.41.0
72
73
diff view generated by jsdifflib
New patch
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
2
3
Use a helper in riscv_cpu_add_kvm_properties() to eliminate some of its
4
code repetition.
5
6
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
7
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
8
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
9
Message-ID: <20230912132423.268494-9-dbarboza@ventanamicro.com>
10
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
11
---
12
target/riscv/cpu.c | 24 +++++++++++++-----------
13
1 file changed, 13 insertions(+), 11 deletions(-)
14
15
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
16
index XXXXXXX..XXXXXXX 100644
17
--- a/target/riscv/cpu.c
18
+++ b/target/riscv/cpu.c
19
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_add_kvm_unavail_prop(Object *obj, const char *prop_name)
20
NULL, (void *)prop_name);
21
}
22
23
+static void riscv_cpu_add_kvm_unavail_prop_array(Object *obj,
24
+ Property *array)
25
+{
26
+ g_assert(array);
27
+
28
+ for (Property *prop = array; prop && prop->name; prop++) {
29
+ riscv_cpu_add_kvm_unavail_prop(obj, prop->name);
30
+ }
31
+}
32
+
33
void kvm_riscv_cpu_add_kvm_properties(Object *obj)
34
{
35
Property *prop;
36
@@ -XXX,XX +XXX,XX @@ void kvm_riscv_cpu_add_kvm_properties(Object *obj)
37
kvm_riscv_init_user_properties(obj);
38
riscv_cpu_add_misa_properties(obj);
39
40
- for (prop = riscv_cpu_extensions; prop && prop->name; prop++) {
41
- riscv_cpu_add_kvm_unavail_prop(obj, prop->name);
42
- }
43
-
44
- for (prop = riscv_cpu_vendor_exts; prop && prop->name; prop++) {
45
- riscv_cpu_add_kvm_unavail_prop(obj, prop->name);
46
- }
47
-
48
- for (prop = riscv_cpu_experimental_exts; prop && prop->name; prop++) {
49
- riscv_cpu_add_kvm_unavail_prop(obj, prop->name);
50
- }
51
+ riscv_cpu_add_kvm_unavail_prop_array(obj, riscv_cpu_extensions);
52
+ riscv_cpu_add_kvm_unavail_prop_array(obj, riscv_cpu_vendor_exts);
53
+ riscv_cpu_add_kvm_unavail_prop_array(obj, riscv_cpu_experimental_exts);
54
55
for (prop = riscv_cpu_options; prop && prop->name; prop++) {
56
/* Check if KVM created the property already */
57
--
58
2.41.0
diff view generated by jsdifflib
New patch
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
2
3
Inside riscv_cpu_validate_v() we're always throwing a log message if the
4
user didn't set a vector version via 'vext_spec'.
5
6
We're going to include one case with the 'max' CPU where env->vext_ver
7
will be set in the cpu_init(). But that alone will not stop the "vector
8
version is not specified" message from appearing. The usefulness of this
9
log message is debatable for the generic CPUs, but for a 'max' CPU type,
10
where we are supposed to deliver a CPU model with all features possible,
11
it's strange to force users to set 'vext_spec' to get rid of this
12
message.
13
14
Change riscv_cpu_validate_v() to not throw this log message if
15
env->vext_ver is already set.
16
17
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
18
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
19
Reviewed-by: Weiwei Li <liweiwei@iscas.ac.cn>
20
Message-ID: <20230912132423.268494-10-dbarboza@ventanamicro.com>
21
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
22
---
23
target/riscv/cpu.c | 9 ++++-----
24
1 file changed, 4 insertions(+), 5 deletions(-)
25
26
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
27
index XXXXXXX..XXXXXXX 100644
28
--- a/target/riscv/cpu.c
29
+++ b/target/riscv/cpu.c
30
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_disas_set_info(CPUState *s, disassemble_info *info)
31
static void riscv_cpu_validate_v(CPURISCVState *env, RISCVCPUConfig *cfg,
32
Error **errp)
33
{
34
- int vext_version = VEXT_VERSION_1_00_0;
35
-
36
if (!is_power_of_2(cfg->vlen)) {
37
error_setg(errp, "Vector extension VLEN must be power of 2");
38
return;
39
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_validate_v(CPURISCVState *env, RISCVCPUConfig *cfg,
40
}
41
if (cfg->vext_spec) {
42
if (!g_strcmp0(cfg->vext_spec, "v1.0")) {
43
- vext_version = VEXT_VERSION_1_00_0;
44
+ env->vext_ver = VEXT_VERSION_1_00_0;
45
} else {
46
error_setg(errp, "Unsupported vector spec version '%s'",
47
cfg->vext_spec);
48
return;
49
}
50
- } else {
51
+ } else if (env->vext_ver == 0) {
52
qemu_log("vector version is not specified, "
53
"use the default value v1.0\n");
54
+
55
+ env->vext_ver = VEXT_VERSION_1_00_0;
56
}
57
- env->vext_ver = vext_version;
58
}
59
60
static void riscv_cpu_validate_priv_spec(RISCVCPU *cpu, Error **errp)
61
--
62
2.41.0
diff view generated by jsdifflib
New patch
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
2
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
New patch
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
2
3
Add smoke tests to ensure that we'll not break the 'max' CPU type when
4
adding new frozen/ratified RISC-V extensions.
5
6
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
7
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
8
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
9
Tested-by: Philippe Mathieu-Daudé <philmd@linaro.org>
10
Message-ID: <20230912132423.268494-12-dbarboza@ventanamicro.com>
11
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
12
---
13
tests/avocado/tuxrun_baselines.py | 32 +++++++++++++++++++++++++++++++
14
1 file changed, 32 insertions(+)
15
16
diff --git a/tests/avocado/tuxrun_baselines.py b/tests/avocado/tuxrun_baselines.py
17
index XXXXXXX..XXXXXXX 100644
18
--- a/tests/avocado/tuxrun_baselines.py
19
+++ b/tests/avocado/tuxrun_baselines.py
20
@@ -XXX,XX +XXX,XX @@ def test_riscv64(self):
21
22
self.common_tuxrun(csums=sums)
23
24
+ def test_riscv32_maxcpu(self):
25
+ """
26
+ :avocado: tags=arch:riscv32
27
+ :avocado: tags=machine:virt
28
+ :avocado: tags=cpu:max
29
+ :avocado: tags=tuxboot:riscv32
30
+ """
31
+ sums = { "Image" :
32
+ "89599407d7334de629a40e7ad6503c73670359eb5f5ae9d686353a3d6deccbd5",
33
+ "fw_jump.elf" :
34
+ "f2ef28a0b77826f79d085d3e4aa686f1159b315eff9099a37046b18936676985",
35
+ "rootfs.ext4.zst" :
36
+ "7168d296d0283238ea73cd5a775b3dd608e55e04c7b92b76ecce31bb13108cba" }
37
+
38
+ self.common_tuxrun(csums=sums)
39
+
40
+ def test_riscv64_maxcpu(self):
41
+ """
42
+ :avocado: tags=arch:riscv64
43
+ :avocado: tags=machine:virt
44
+ :avocado: tags=cpu:max
45
+ :avocado: tags=tuxboot:riscv64
46
+ """
47
+ sums = { "Image" :
48
+ "cd634badc65e52fb63465ec99e309c0de0369f0841b7d9486f9729e119bac25e",
49
+ "fw_jump.elf" :
50
+ "6e3373abcab4305fe151b564a4c71110d833c21f2c0a1753b7935459e36aedcf",
51
+ "rootfs.ext4.zst" :
52
+ "b18e3a3bdf27be03da0b285e84cb71bf09eca071c3a087b42884b6982ed679eb" }
53
+
54
+ self.common_tuxrun(csums=sums)
55
+
56
def test_s390(self):
57
"""
58
:avocado: tags=arch:s390x
59
--
60
2.41.0
61
62
diff view generated by jsdifflib
1
From: Thomas Huth <thuth@redhat.com>
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
2
2
3
Configuring a drive with "if=none" is meant for creation of a backend
3
The 'any' CPU type was introduced in commit dc5bd18fa5725 ("RISC-V CPU
4
only, it should not get automatically assigned to a device frontend.
4
Core Definition"), being around since the beginning. It's not an easy
5
Use "if=pflash" for the One-Time-Programmable device instead (like
5
CPU to use: it's undocumented and its name doesn't tell users much about
6
it is e.g. also done for the efuse device in hw/arm/xlnx-zcu102.c).
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.
7
8
8
Since the old way of configuring the device has already been published
9
The closest we have is a comment from Alistair [1] where he recalls from
9
with the previous QEMU versions, we cannot remove this immediately, but
10
memory that the 'any' CPU is supposed to behave like the newly added
10
have to deprecate it and support it for at least two more releases.
11
'max' CPU. He also suggested that the 'any' CPU should be removed.
11
12
12
Signed-off-by: Thomas Huth <thuth@redhat.com>
13
The default CPUs are rv32 and rv64, so removing the 'any' CPU will have
13
Acked-by: Philippe Mathieu-Daudé <philmd@redhat.com>
14
impact only on users that might have a script that uses '-cpu any'.
14
Reviewed-by: Markus Armbruster <armbru@redhat.com>
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>
15
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
26
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
16
Message-id: 20211119102549.217755-1-thuth@redhat.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>
17
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
31
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
18
---
32
---
19
docs/about/deprecated.rst | 6 ++++++
33
docs/about/deprecated.rst | 12 ++++++++++++
20
hw/misc/sifive_u_otp.c | 9 ++++++++-
34
target/riscv/cpu.c | 5 +++++
21
2 files changed, 14 insertions(+), 1 deletion(-)
35
2 files changed, 17 insertions(+)
22
36
23
diff --git a/docs/about/deprecated.rst b/docs/about/deprecated.rst
37
diff --git a/docs/about/deprecated.rst b/docs/about/deprecated.rst
24
index XXXXXXX..XXXXXXX 100644
38
index XXXXXXX..XXXXXXX 100644
25
--- a/docs/about/deprecated.rst
39
--- a/docs/about/deprecated.rst
26
+++ b/docs/about/deprecated.rst
40
+++ b/docs/about/deprecated.rst
27
@@ -XXX,XX +XXX,XX @@ as short-form boolean values, and passed to plugins as ``arg_name=on``.
41
@@ -XXX,XX +XXX,XX @@ QEMU's ``vhost`` feature, which would eliminate the high latency costs under
28
However, short-form booleans are deprecated and full explicit ``arg_name=on``
42
which the 9p ``proxy`` backend currently suffers. However as of to date nobody
29
form is preferred.
43
has indicated plans for such kind of reimplementation unfortunately.
30
44
31
+``-drive if=none`` for the sifive_u OTP device (since 6.2)
45
+RISC-V 'any' CPU type ``-cpu any`` (since 8.2)
32
+''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
46
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
33
+
47
+
34
+Using ``-drive if=none`` to configure the OTP device of the sifive_u
48
+The 'any' CPU type was introduced back in 2018 and has been around since the
35
+RISC-V machine is deprecated. Use ``-drive if=pflash`` instead.
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.
36
+
52
+
37
53
+After the introduction of the 'max' CPU type, RISC-V now has a good coverage
38
QEMU Machine Protocol (QMP) commands
54
+of generic CPUs: rv32 and rv64 as default CPUs and 'max' as a feature complete
39
------------------------------------
55
+CPU for both 32 and 64 bit builds. Users are then discouraged to use the 'any'
40
diff --git a/hw/misc/sifive_u_otp.c b/hw/misc/sifive_u_otp.c
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
41
index XXXXXXX..XXXXXXX 100644
61
index XXXXXXX..XXXXXXX 100644
42
--- a/hw/misc/sifive_u_otp.c
62
--- a/target/riscv/cpu.c
43
+++ b/hw/misc/sifive_u_otp.c
63
+++ b/target/riscv/cpu.c
44
@@ -XXX,XX +XXX,XX @@ static void sifive_u_otp_realize(DeviceState *dev, Error **errp)
64
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp)
45
TYPE_SIFIVE_U_OTP, SIFIVE_U_OTP_REG_SIZE);
65
RISCVCPUClass *mcc = RISCV_CPU_GET_CLASS(dev);
46
sysbus_init_mmio(SYS_BUS_DEVICE(dev), &s->mmio);
66
Error *local_err = NULL;
47
67
48
- dinfo = drive_get_next(IF_NONE);
68
+ if (object_dynamic_cast(OBJECT(dev), TYPE_RISCV_CPU_ANY) != NULL) {
49
+ dinfo = drive_get_next(IF_PFLASH);
69
+ warn_report("The 'any' CPU is deprecated and will be "
50
+ if (!dinfo) {
70
+ "removed in the future.");
51
+ dinfo = drive_get_next(IF_NONE);
52
+ if (dinfo) {
53
+ warn_report("using \"-drive if=none\" for the OTP is deprecated, "
54
+ "use \"-drive if=pflash\" instead.");
55
+ }
56
+ }
71
+ }
57
if (dinfo) {
72
+
58
int ret;
73
cpu_exec_realizefn(cs, &local_err);
59
uint64_t perm;
74
if (local_err != NULL) {
75
error_propagate(errp, local_err);
60
--
76
--
61
2.31.1
77
2.41.0
62
78
63
79
diff view generated by jsdifflib
New patch
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
2
3
We'll have future usage for a function where, given an offset of the
4
struct RISCVCPUConfig, the flag is updated to a certain val.
5
6
Change all existing callers to use edata->ext_enable_offset instead of
7
'edata'.
8
9
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
10
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
11
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
12
Message-ID: <20230912132423.268494-14-dbarboza@ventanamicro.com>
13
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
14
---
15
target/riscv/cpu.c | 18 +++++++++---------
16
1 file changed, 9 insertions(+), 9 deletions(-)
17
18
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
19
index XXXXXXX..XXXXXXX 100644
20
--- a/target/riscv/cpu.c
21
+++ b/target/riscv/cpu.c
22
@@ -XXX,XX +XXX,XX @@ static const struct isa_ext_data isa_edata_arr[] = {
23
ISA_EXT_DATA_ENTRY(xventanacondops, PRIV_VERSION_1_12_0, ext_XVentanaCondOps),
24
};
25
26
-static bool isa_ext_is_enabled(RISCVCPU *cpu,
27
- const struct isa_ext_data *edata)
28
+static bool isa_ext_is_enabled(RISCVCPU *cpu, uint32_t ext_offset)
29
{
30
- bool *ext_enabled = (void *)&cpu->cfg + edata->ext_enable_offset;
31
+ bool *ext_enabled = (void *)&cpu->cfg + ext_offset;
32
33
return *ext_enabled;
34
}
35
36
-static void isa_ext_update_enabled(RISCVCPU *cpu,
37
- const struct isa_ext_data *edata, bool en)
38
+static void isa_ext_update_enabled(RISCVCPU *cpu, uint32_t ext_offset,
39
+ bool en)
40
{
41
- bool *ext_enabled = (void *)&cpu->cfg + edata->ext_enable_offset;
42
+ bool *ext_enabled = (void *)&cpu->cfg + ext_offset;
43
44
*ext_enabled = en;
45
}
46
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_disable_priv_spec_isa_exts(RISCVCPU *cpu)
47
48
/* Force disable extensions if priv spec version does not match */
49
for (i = 0; i < ARRAY_SIZE(isa_edata_arr); i++) {
50
- if (isa_ext_is_enabled(cpu, &isa_edata_arr[i]) &&
51
+ if (isa_ext_is_enabled(cpu, isa_edata_arr[i].ext_enable_offset) &&
52
(env->priv_ver < isa_edata_arr[i].min_version)) {
53
- isa_ext_update_enabled(cpu, &isa_edata_arr[i], false);
54
+ isa_ext_update_enabled(cpu, isa_edata_arr[i].ext_enable_offset,
55
+ false);
56
#ifndef CONFIG_USER_ONLY
57
warn_report("disabling %s extension for hart 0x" TARGET_FMT_lx
58
" because privilege spec version does not match",
59
@@ -XXX,XX +XXX,XX @@ static void riscv_isa_string_ext(RISCVCPU *cpu, char **isa_str,
60
int i;
61
62
for (i = 0; i < ARRAY_SIZE(isa_edata_arr); i++) {
63
- if (isa_ext_is_enabled(cpu, &isa_edata_arr[i])) {
64
+ if (isa_ext_is_enabled(cpu, isa_edata_arr[i].ext_enable_offset)) {
65
new = g_strconcat(old, "_", isa_edata_arr[i].name, NULL);
66
g_free(old);
67
old = new;
68
--
69
2.41.0
diff view generated by jsdifflib
New patch
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
2
3
The RISC-V KVM driver uses a CPUCFG() macro that calculates the offset
4
of a certain field in the struct RISCVCPUConfig. We're going to use this
5
macro in target/riscv/cpu.c as well in the next patches. Make it public.
6
7
Rename it to CPU_CFG_OFFSET() for more clarity while we're at it.
8
9
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
10
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
11
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
12
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
13
Message-ID: <20230912132423.268494-15-dbarboza@ventanamicro.com>
14
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
15
---
16
target/riscv/cpu.h | 2 ++
17
target/riscv/cpu.c | 2 +-
18
target/riscv/kvm.c | 8 +++-----
19
3 files changed, 6 insertions(+), 6 deletions(-)
20
21
diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
22
index XXXXXXX..XXXXXXX 100644
23
--- a/target/riscv/cpu.h
24
+++ b/target/riscv/cpu.h
25
@@ -XXX,XX +XXX,XX @@
26
const char *riscv_get_misa_ext_name(uint32_t bit);
27
const char *riscv_get_misa_ext_description(uint32_t bit);
28
29
+#define CPU_CFG_OFFSET(_prop) offsetof(struct RISCVCPUConfig, _prop)
30
+
31
/* Privileged specification version */
32
enum {
33
PRIV_VERSION_1_10_0 = 0,
34
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
35
index XXXXXXX..XXXXXXX 100644
36
--- a/target/riscv/cpu.c
37
+++ b/target/riscv/cpu.c
38
@@ -XXX,XX +XXX,XX @@ struct isa_ext_data {
39
};
40
41
#define ISA_EXT_DATA_ENTRY(_name, _min_ver, _prop) \
42
- {#_name, _min_ver, offsetof(struct RISCVCPUConfig, _prop)}
43
+ {#_name, _min_ver, CPU_CFG_OFFSET(_prop)}
44
45
/*
46
* From vector_helper.c
47
diff --git a/target/riscv/kvm.c b/target/riscv/kvm.c
48
index XXXXXXX..XXXXXXX 100644
49
--- a/target/riscv/kvm.c
50
+++ b/target/riscv/kvm.c
51
@@ -XXX,XX +XXX,XX @@ static void kvm_riscv_update_cpu_misa_ext(RISCVCPU *cpu, CPUState *cs)
52
}
53
}
54
55
-#define CPUCFG(_prop) offsetof(struct RISCVCPUConfig, _prop)
56
-
57
#define KVM_EXT_CFG(_name, _prop, _reg_id) \
58
- {.name = _name, .offset = CPUCFG(_prop), \
59
+ {.name = _name, .offset = CPU_CFG_OFFSET(_prop), \
60
.kvm_reg_id = _reg_id}
61
62
static KVMCPUConfig kvm_multi_ext_cfgs[] = {
63
@@ -XXX,XX +XXX,XX @@ static void kvm_cpu_set_multi_ext_cfg(Object *obj, Visitor *v,
64
65
static KVMCPUConfig kvm_cbom_blocksize = {
66
.name = "cbom_blocksize",
67
- .offset = CPUCFG(cbom_blocksize),
68
+ .offset = CPU_CFG_OFFSET(cbom_blocksize),
69
.kvm_reg_id = KVM_REG_RISCV_CONFIG_REG(zicbom_block_size)
70
};
71
72
static KVMCPUConfig kvm_cboz_blocksize = {
73
.name = "cboz_blocksize",
74
- .offset = CPUCFG(cboz_blocksize),
75
+ .offset = CPU_CFG_OFFSET(cboz_blocksize),
76
.kvm_reg_id = KVM_REG_RISCV_CONFIG_REG(zicboz_block_size)
77
};
78
79
--
80
2.41.0
81
82
diff view generated by jsdifflib
New patch
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
2
3
During realize() time we're activating a lot of extensions based on some
4
criteria, e.g.:
5
6
if (cpu->cfg.ext_zk) {
7
cpu->cfg.ext_zkn = true;
8
cpu->cfg.ext_zkr = true;
9
cpu->cfg.ext_zkt = true;
10
}
11
12
This practice resulted in at least one case where we ended up enabling
13
something we shouldn't: RVC enabling zca/zcd/zcf when using a CPU that
14
has priv_spec older than 1.12.0.
15
16
We're also not considering user choice. There's no way of doing it now
17
but this is about to change in the next few patches.
18
19
cpu_cfg_ext_auto_update() will check for priv version mismatches before
20
enabling extensions. If we have a mismatch between the current priv
21
version and the extension we want to enable, do not enable it. In the
22
near future, this same function will also consider user choice when
23
deciding if we're going to enable/disable an extension or not.
24
25
For now let's use it to handle zca/zcd/zcf enablement if RVC is enabled.
26
27
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
28
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
29
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
30
Message-ID: <20230912132423.268494-16-dbarboza@ventanamicro.com>
31
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
32
---
33
target/riscv/cpu.c | 43 ++++++++++++++++++++++++++++++++++++++++---
34
1 file changed, 40 insertions(+), 3 deletions(-)
35
36
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
37
index XXXXXXX..XXXXXXX 100644
38
--- a/target/riscv/cpu.c
39
+++ b/target/riscv/cpu.c
40
@@ -XXX,XX +XXX,XX @@ static void isa_ext_update_enabled(RISCVCPU *cpu, uint32_t ext_offset,
41
*ext_enabled = en;
42
}
43
44
+static int cpu_cfg_ext_get_min_version(uint32_t ext_offset)
45
+{
46
+ int i;
47
+
48
+ for (i = 0; i < ARRAY_SIZE(isa_edata_arr); i++) {
49
+ if (isa_edata_arr[i].ext_enable_offset != ext_offset) {
50
+ continue;
51
+ }
52
+
53
+ return isa_edata_arr[i].min_version;
54
+ }
55
+
56
+ g_assert_not_reached();
57
+}
58
+
59
+static void cpu_cfg_ext_auto_update(RISCVCPU *cpu, uint32_t ext_offset,
60
+ bool value)
61
+{
62
+ CPURISCVState *env = &cpu->env;
63
+ bool prev_val = isa_ext_is_enabled(cpu, ext_offset);
64
+ int min_version;
65
+
66
+ if (prev_val == value) {
67
+ return;
68
+ }
69
+
70
+ if (value && env->priv_ver != PRIV_VERSION_LATEST) {
71
+ /* Do not enable it if priv_ver is older than min_version */
72
+ min_version = cpu_cfg_ext_get_min_version(ext_offset);
73
+ if (env->priv_ver < min_version) {
74
+ return;
75
+ }
76
+ }
77
+
78
+ isa_ext_update_enabled(cpu, ext_offset, value);
79
+}
80
+
81
const char * const riscv_int_regnames[] = {
82
"x0/zero", "x1/ra", "x2/sp", "x3/gp", "x4/tp", "x5/t0", "x6/t1",
83
"x7/t2", "x8/s0", "x9/s1", "x10/a0", "x11/a1", "x12/a2", "x13/a3",
84
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp)
85
86
/* zca, zcd and zcf has a PRIV 1.12.0 restriction */
87
if (riscv_has_ext(env, RVC) && env->priv_ver >= PRIV_VERSION_1_12_0) {
88
- cpu->cfg.ext_zca = true;
89
+ cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zca), true);
90
if (riscv_has_ext(env, RVF) && env->misa_mxl_max == MXL_RV32) {
91
- cpu->cfg.ext_zcf = true;
92
+ cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zcf), true);
93
}
94
if (riscv_has_ext(env, RVD)) {
95
- cpu->cfg.ext_zcd = true;
96
+ cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zcd), true);
97
}
98
}
99
100
--
101
2.41.0
diff view generated by jsdifflib
New patch
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
2
3
Let's change the other instances in realize() where we're enabling an
4
extension based on a certain criteria (e.g. it's a dependency of another
5
extension).
6
7
We're leaving icsr and ifencei being enabled during RVG for later -
8
we'll want to error out in that case. Every other extension enablement
9
during realize is now done via cpu_cfg_ext_auto_update().
10
11
The end goal is that only cpu init() functions will handle extension
12
flags directly via "cpu->cfg.ext_N = true|false".
13
14
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
15
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
16
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
17
Message-ID: <20230912132423.268494-17-dbarboza@ventanamicro.com>
18
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
19
---
20
target/riscv/cpu.c | 50 +++++++++++++++++++++++-----------------------
21
1 file changed, 25 insertions(+), 25 deletions(-)
22
23
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
24
index XXXXXXX..XXXXXXX 100644
25
--- a/target/riscv/cpu.c
26
+++ b/target/riscv/cpu.c
27
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp)
28
}
29
30
if (cpu->cfg.ext_zfh) {
31
- cpu->cfg.ext_zfhmin = true;
32
+ cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zfhmin), true);
33
}
34
35
if (cpu->cfg.ext_zfhmin && !riscv_has_ext(env, RVF)) {
36
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp)
37
}
38
39
/* The V vector extension depends on the Zve64d extension */
40
- cpu->cfg.ext_zve64d = true;
41
+ cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zve64d), true);
42
}
43
44
/* The Zve64d extension depends on the Zve64f extension */
45
if (cpu->cfg.ext_zve64d) {
46
- cpu->cfg.ext_zve64f = true;
47
+ cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zve64f), true);
48
}
49
50
/* The Zve64f extension depends on the Zve32f extension */
51
if (cpu->cfg.ext_zve64f) {
52
- cpu->cfg.ext_zve32f = true;
53
+ cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zve32f), true);
54
}
55
56
if (cpu->cfg.ext_zve64d && !riscv_has_ext(env, RVD)) {
57
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp)
58
}
59
60
if (cpu->cfg.ext_zvfh) {
61
- cpu->cfg.ext_zvfhmin = true;
62
+ cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zvfhmin), true);
63
}
64
65
if (cpu->cfg.ext_zvfhmin && !cpu->cfg.ext_zve32f) {
66
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp)
67
68
/* Set the ISA extensions, checks should have happened above */
69
if (cpu->cfg.ext_zhinx) {
70
- cpu->cfg.ext_zhinxmin = true;
71
+ cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zca), true);
72
}
73
74
if ((cpu->cfg.ext_zdinx || cpu->cfg.ext_zhinxmin) && !cpu->cfg.ext_zfinx) {
75
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp)
76
}
77
78
if (cpu->cfg.ext_zce) {
79
- cpu->cfg.ext_zca = true;
80
- cpu->cfg.ext_zcb = true;
81
- cpu->cfg.ext_zcmp = true;
82
- cpu->cfg.ext_zcmt = true;
83
+ cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zca), true);
84
+ cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zcb), true);
85
+ cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zcmp), true);
86
+ cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zcmt), true);
87
if (riscv_has_ext(env, RVF) && env->misa_mxl_max == MXL_RV32) {
88
- cpu->cfg.ext_zcf = true;
89
+ cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zcf), true);
90
}
91
}
92
93
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp)
94
}
95
96
if (cpu->cfg.ext_zk) {
97
- cpu->cfg.ext_zkn = true;
98
- cpu->cfg.ext_zkr = true;
99
- cpu->cfg.ext_zkt = true;
100
+ cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zkn), true);
101
+ cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zkr), true);
102
+ cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zkt), true);
103
}
104
105
if (cpu->cfg.ext_zkn) {
106
- cpu->cfg.ext_zbkb = true;
107
- cpu->cfg.ext_zbkc = true;
108
- cpu->cfg.ext_zbkx = true;
109
- cpu->cfg.ext_zkne = true;
110
- cpu->cfg.ext_zknd = true;
111
- cpu->cfg.ext_zknh = true;
112
+ cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zbkb), true);
113
+ cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zbkc), true);
114
+ cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zbkx), true);
115
+ cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zkne), true);
116
+ cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zknd), true);
117
+ cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zknh), true);
118
}
119
120
if (cpu->cfg.ext_zks) {
121
- cpu->cfg.ext_zbkb = true;
122
- cpu->cfg.ext_zbkc = true;
123
- cpu->cfg.ext_zbkx = true;
124
- cpu->cfg.ext_zksed = true;
125
- cpu->cfg.ext_zksh = true;
126
+ cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zbkb), true);
127
+ cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zbkc), true);
128
+ cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zbkx), true);
129
+ cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zksed), true);
130
+ cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zksh), true);
131
}
132
133
/*
134
--
135
2.41.0
diff view generated by jsdifflib
New patch
1
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
2
3
If we want to make better decisions when auto-enabling extensions during
4
realize() we need a way to tell if an user set an extension manually.
5
The RISC-V KVM driver has its own solution via a KVMCPUConfig struct
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
10
For TCG we would want a 'user_set' mechanic too, but we would look
11
ad-hoc via cpu_cfg_ext_auto_update() if a certain extension was user set
12
or not. If we copy what was made in the KVM side we would look for
13
'user_set' for one into 60+ extension structs spreaded in 3 arrays
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>
41
---
42
target/riscv/cpu.c | 258 ++++++++++++++++++++++++++++-----------------
43
1 file changed, 159 insertions(+), 99 deletions(-)
44
45
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
46
index XXXXXXX..XXXXXXX 100644
47
--- a/target/riscv/cpu.c
48
+++ b/target/riscv/cpu.c
49
@@ -XXX,XX +XXX,XX @@ static const struct isa_ext_data isa_edata_arr[] = {
50
ISA_EXT_DATA_ENTRY(xventanacondops, PRIV_VERSION_1_12_0, ext_XVentanaCondOps),
51
};
52
53
+/* Hash that stores user set extensions */
54
+static GHashTable *multi_ext_user_opts;
55
+
56
static bool isa_ext_is_enabled(RISCVCPU *cpu, uint32_t ext_offset)
57
{
58
bool *ext_enabled = (void *)&cpu->cfg + ext_offset;
59
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_init(Object *obj)
60
qdev_init_gpio_in(DEVICE(obj), riscv_cpu_set_irq,
61
IRQ_LOCAL_MAX + IRQ_LOCAL_GUEST_MAX);
62
#endif /* CONFIG_USER_ONLY */
63
+
64
+ multi_ext_user_opts = g_hash_table_new(NULL, g_direct_equal);
65
}
66
67
typedef struct RISCVCPUMisaExtConfig {
68
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_add_misa_properties(Object *cpu_obj)
69
}
70
}
71
72
-static Property riscv_cpu_extensions[] = {
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
{
325
g_assert(array);
326
327
- for (Property *prop = array; prop && prop->name; prop++) {
328
- qdev_property_add_static(dev, prop);
329
+ for (RISCVCPUMultiExtConfig *prop = array; prop && prop->name; prop++) {
330
+ cpu_add_multi_ext_prop(obj, prop);
331
}
332
}
333
334
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_add_kvm_unavail_prop(Object *obj, const char *prop_name)
335
}
336
337
static void riscv_cpu_add_kvm_unavail_prop_array(Object *obj,
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
--
385
2.41.0
diff view generated by jsdifflib
New patch
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
2
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
New patch
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
2
3
Add a new cpu_cfg_ext_is_user_set() helper to check if an extension was
4
set by the user in the command line. Use it inside
5
cpu_cfg_ext_auto_update() to verify if the user set a certain extension
6
and, if that's the case, do not change its value.
7
8
This will make us honor user choice instead of overwriting the values.
9
Users will then be informed whether they're using an incompatible set of
10
extensions instead of QEMU setting a magic value that works.
11
12
The reason why we're not implementing user choice for MISA extensions
13
right now is because, today, we do not silently change any MISA bit
14
during realize() time (we do warn when enabling bits if RVG is enabled).
15
We do that - a lot - with multi-letter extensions though, so we're
16
handling the most immediate concern first.
17
18
After this patch, we'll now error out if the user explicitly set 'zce' to true
19
and 'zca' to false:
20
21
$ ./build/qemu-system-riscv64 -M virt -cpu rv64,zce=true,zca=false -nographic
22
qemu-system-riscv64: Zcf/Zcd/Zcb/Zcmp/Zcmt extensions require Zca extension
23
24
This didn't happen before because we were enabling 'zca' if 'zce' was enabled
25
regardless if the user set 'zca' to false.
26
27
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
28
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
29
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
30
Message-ID: <20230912132423.268494-20-dbarboza@ventanamicro.com>
31
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
32
---
33
target/riscv/cpu.c | 16 ++++++++++++++++
34
1 file changed, 16 insertions(+)
35
36
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
37
index XXXXXXX..XXXXXXX 100644
38
--- a/target/riscv/cpu.c
39
+++ b/target/riscv/cpu.c
40
@@ -XXX,XX +XXX,XX @@ static int cpu_cfg_ext_get_min_version(uint32_t ext_offset)
41
g_assert_not_reached();
42
}
43
44
+static bool cpu_cfg_ext_is_user_set(uint32_t ext_offset)
45
+{
46
+ return g_hash_table_contains(multi_ext_user_opts,
47
+ GUINT_TO_POINTER(ext_offset));
48
+}
49
+
50
static void cpu_cfg_ext_auto_update(RISCVCPU *cpu, uint32_t ext_offset,
51
bool value)
52
{
53
@@ -XXX,XX +XXX,XX @@ static void cpu_cfg_ext_auto_update(RISCVCPU *cpu, uint32_t ext_offset,
54
return;
55
}
56
57
+ if (cpu_cfg_ext_is_user_set(ext_offset)) {
58
+ return;
59
+ }
60
+
61
if (value && env->priv_ver != PRIV_VERSION_LATEST) {
62
/* Do not enable it if priv_ver is older than min_version */
63
min_version = cpu_cfg_ext_get_min_version(ext_offset);
64
@@ -XXX,XX +XXX,XX @@ static RISCVCPUMisaExtConfig misa_ext_cfgs[] = {
65
MISA_CFG(RVG, false),
66
};
67
68
+/*
69
+ * We do not support user choice tracking for MISA
70
+ * extensions yet because, so far, we do not silently
71
+ * change MISA bits during realize() (RVG enables MISA
72
+ * bits but the user is warned about it).
73
+ */
74
static void riscv_cpu_add_misa_properties(Object *cpu_obj)
75
{
76
int i;
77
--
78
2.41.0
diff view generated by jsdifflib
New patch
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
2
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
New patch
1
From: "liguang.zhang" <liguang.zhang@hexintek.com>
1
2
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
New patch
1
From: Alvin Chang <vivahavey@gmail.com>
1
2
3
Fix the inverted order of pmpaddr13 and pmpaddr14 in csr_name().
4
5
Signed-off-by: Alvin Chang <alvinga@andestech.com>
6
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
7
Message-ID: <20230907084500.328-1-alvinga@andestech.com>
8
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
9
---
10
disas/riscv.c | 4 ++--
11
1 file changed, 2 insertions(+), 2 deletions(-)
12
13
diff --git a/disas/riscv.c b/disas/riscv.c
14
index XXXXXXX..XXXXXXX 100644
15
--- a/disas/riscv.c
16
+++ b/disas/riscv.c
17
@@ -XXX,XX +XXX,XX @@ static const char *csr_name(int csrno)
18
case 0x03ba: return "pmpaddr10";
19
case 0x03bb: return "pmpaddr11";
20
case 0x03bc: return "pmpaddr12";
21
- case 0x03bd: return "pmpaddr14";
22
- case 0x03be: return "pmpaddr13";
23
+ case 0x03bd: return "pmpaddr13";
24
+ case 0x03be: return "pmpaddr14";
25
case 0x03bf: return "pmpaddr15";
26
case 0x0780: return "mtohost";
27
case 0x0781: return "mfromhost";
28
--
29
2.41.0
diff view generated by jsdifflib
New patch
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
2
3
target/riscv/cpu.c needs to handle all possible accelerators (TCG and
4
KVM at this moment) during both init() and realize() time. This forces
5
us to resort to a lot of "if tcg" and "if kvm" throughout the code,
6
which isn't wrong, but can get cluttered over time. Splitting
7
acceleration specific code from cpu.c to its own file will help to
8
declutter the existing code and it will also make it easier to support
9
KVM/TCG only builds in the future.
10
11
We'll start by adding a new subdir called 'tcg' and a new file called
12
'tcg-cpu.c'. This file will be used to introduce a new accelerator class
13
for TCG acceleration in RISC-V, allowing us to center all TCG exclusive
14
code in its file instead of using 'cpu.c' for everything. This design is
15
inpired by the work Claudio Fontana did in x86 a few years ago in commit
16
f5cc5a5c1 ("i386: split cpu accelerators from cpu.c, using
17
AccelCPUClass").
18
19
To avoid moving too much code at once we'll start by adding the new file
20
and TCG AccelCPUClass declaration. The 'class_init' from the accel class
21
will init 'tcg_ops', relieving the common riscv_cpu_class_init() from
22
doing it.
23
24
'riscv_tcg_ops' is being exported from 'cpu.c' for now to avoid having
25
to deal with moving code and files around right now. We'll focus on
26
decoupling the realize() logic first.
27
28
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
29
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
30
Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
31
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
32
Message-ID: <20230925175709.35696-2-dbarboza@ventanamicro.com>
33
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
34
---
35
target/riscv/cpu.h | 4 +++
36
target/riscv/cpu.c | 5 +---
37
target/riscv/tcg/tcg-cpu.c | 58 ++++++++++++++++++++++++++++++++++++
38
target/riscv/meson.build | 2 ++
39
target/riscv/tcg/meson.build | 2 ++
40
5 files changed, 67 insertions(+), 4 deletions(-)
41
create mode 100644 target/riscv/tcg/tcg-cpu.c
42
create mode 100644 target/riscv/tcg/meson.build
43
44
diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
45
index XXXXXXX..XXXXXXX 100644
46
--- a/target/riscv/cpu.h
47
+++ b/target/riscv/cpu.h
48
@@ -XXX,XX +XXX,XX @@ enum riscv_pmu_event_idx {
49
RISCV_PMU_EVENT_CACHE_ITLB_PREFETCH_MISS = 0x10021,
50
};
51
52
+/* Export tcg_ops until we move everything to tcg/tcg-cpu.c */
53
+#include "hw/core/tcg-cpu-ops.h"
54
+extern const struct TCGCPUOps riscv_tcg_ops;
55
+
56
/* CSR function table */
57
extern riscv_csr_operations csr_ops[CSR_TABLE_SIZE];
58
59
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
60
index XXXXXXX..XXXXXXX 100644
61
--- a/target/riscv/cpu.c
62
+++ b/target/riscv/cpu.c
63
@@ -XXX,XX +XXX,XX @@ static const struct SysemuCPUOps riscv_sysemu_ops = {
64
};
65
#endif
66
67
-#include "hw/core/tcg-cpu-ops.h"
68
-
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
84
index XXXXXXX..XXXXXXX
85
--- /dev/null
86
+++ b/target/riscv/tcg/tcg-cpu.c
87
@@ -XXX,XX +XXX,XX @@
88
+/*
89
+ * riscv TCG cpu class initialization
90
+ *
91
+ * Copyright (c) 2016-2017 Sagar Karandikar, sagark@eecs.berkeley.edu
92
+ * Copyright (c) 2017-2018 SiFive, Inc.
93
+ *
94
+ * 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,
96
+ * version 2 or later, as published by the Free Software Foundation.
97
+ *
98
+ * This program is distributed in the hope it will be useful, but WITHOUT
99
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
100
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
101
+ * more details.
102
+ *
103
+ * You should have received a copy of the GNU General Public License along with
104
+ * this program. If not, see <http://www.gnu.org/licenses/>.
105
+ */
106
+
107
+#include "qemu/osdep.h"
108
+#include "cpu.h"
109
+#include "qemu/accel.h"
110
+#include "hw/core/accel-cpu.h"
111
+
112
+static void tcg_cpu_init_ops(AccelCPUClass *accel_cpu, CPUClass *cc)
113
+{
114
+ /*
115
+ * All cpus use the same set of operations.
116
+ * riscv_tcg_ops is being imported from cpu.c for now.
117
+ */
118
+ cc->tcg_ops = &riscv_tcg_ops;
119
+}
120
+
121
+static void tcg_cpu_class_init(CPUClass *cc)
122
+{
123
+ cc->init_accel_cpu = tcg_cpu_init_ops;
124
+}
125
+
126
+static void tcg_cpu_accel_class_init(ObjectClass *oc, void *data)
127
+{
128
+ AccelCPUClass *acc = ACCEL_CPU_CLASS(oc);
129
+
130
+ acc->cpu_class_init = tcg_cpu_class_init;
131
+}
132
+
133
+static const TypeInfo tcg_cpu_accel_type_info = {
134
+ .name = ACCEL_CPU_NAME("tcg"),
135
+
136
+ .parent = TYPE_ACCEL_CPU,
137
+ .class_init = tcg_cpu_accel_class_init,
138
+ .abstract = true,
139
+};
140
+
141
+static void tcg_cpu_accel_register_types(void)
142
+{
143
+ type_register_static(&tcg_cpu_accel_type_info);
144
+}
145
+type_init(tcg_cpu_accel_register_types);
146
diff --git a/target/riscv/meson.build b/target/riscv/meson.build
147
index XXXXXXX..XXXXXXX 100644
148
--- a/target/riscv/meson.build
149
+++ b/target/riscv/meson.build
150
@@ -XXX,XX +XXX,XX @@ riscv_system_ss.add(files(
151
'riscv-qmp-cmds.c',
152
))
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
2.41.0
diff view generated by jsdifflib
New patch
1
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
2
3
riscv_cpu_realize_tcg() was added to allow TCG cpus to have a different
4
realize() path during the common riscv_cpu_realize(), making it a good
5
choice to start moving TCG exclusive code to tcg-cpu.c.
6
7
Rename it to tcg_cpu_realizefn() and assign it as a implementation of
8
accel::cpu_realizefn(). tcg_cpu_realizefn() will then be called during
9
riscv_cpu_realize() via cpu_exec_realizefn(). We'll use a similar
10
approach with KVM in the near future.
11
12
riscv_cpu_validate_set_extensions() is too big and with too many
13
dependencies to be moved in this same patch. We'll do that next.
14
15
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
16
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
17
Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
18
Message-ID: <20230925175709.35696-3-dbarboza@ventanamicro.com>
19
[ Changes by AF:
20
- Renames to fix build failures after rebase
21
]
22
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
23
---
24
target/riscv/cpu.c | 128 -----------------------------------
25
target/riscv/tcg/tcg-cpu.c | 133 +++++++++++++++++++++++++++++++++++++
26
2 files changed, 133 insertions(+), 128 deletions(-)
27
28
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
29
index XXXXXXX..XXXXXXX 100644
30
--- a/target/riscv/cpu.c
31
+++ b/target/riscv/cpu.c
32
@@ -XXX,XX +XXX,XX @@
33
#include "qemu/log.h"
34
#include "cpu.h"
35
#include "cpu_vendorid.h"
36
-#include "pmu.h"
37
#include "internals.h"
38
-#include "time_helper.h"
39
#include "exec/exec-all.h"
40
#include "qapi/error.h"
41
#include "qapi/visitor.h"
42
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_validate_v(CPURISCVState *env, RISCVCPUConfig *cfg,
43
}
44
}
45
46
-static void riscv_cpu_validate_priv_spec(RISCVCPU *cpu, Error **errp)
47
-{
48
- CPURISCVState *env = &cpu->env;
49
- int priv_version = -1;
50
-
51
- if (cpu->cfg.priv_spec) {
52
- if (!g_strcmp0(cpu->cfg.priv_spec, "v1.12.0")) {
53
- priv_version = PRIV_VERSION_1_12_0;
54
- } else if (!g_strcmp0(cpu->cfg.priv_spec, "v1.11.0")) {
55
- priv_version = PRIV_VERSION_1_11_0;
56
- } else if (!g_strcmp0(cpu->cfg.priv_spec, "v1.10.0")) {
57
- priv_version = PRIV_VERSION_1_10_0;
58
- } else {
59
- error_setg(errp,
60
- "Unsupported privilege spec version '%s'",
61
- cpu->cfg.priv_spec);
62
- return;
63
- }
64
-
65
- env->priv_ver = priv_version;
66
- }
67
-}
68
-
69
static void riscv_cpu_disable_priv_spec_isa_exts(RISCVCPU *cpu)
70
{
71
CPURISCVState *env = &cpu->env;
72
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_disable_priv_spec_isa_exts(RISCVCPU *cpu)
73
}
74
}
75
76
-static void riscv_cpu_validate_misa_mxl(RISCVCPU *cpu, Error **errp)
77
-{
78
- RISCVCPUClass *mcc = RISCV_CPU_GET_CLASS(cpu);
79
- CPUClass *cc = CPU_CLASS(mcc);
80
- CPURISCVState *env = &cpu->env;
81
-
82
- /* Validate that MISA_MXL is set properly. */
83
- switch (env->misa_mxl_max) {
84
-#ifdef TARGET_RISCV64
85
- case MXL_RV64:
86
- case MXL_RV128:
87
- cc->gdb_core_xml_file = "riscv-64bit-cpu.xml";
88
- break;
89
-#endif
90
- case MXL_RV32:
91
- cc->gdb_core_xml_file = "riscv-32bit-cpu.xml";
92
- break;
93
- default:
94
- g_assert_not_reached();
95
- }
96
-
97
- if (env->misa_mxl_max != env->misa_mxl) {
98
- error_setg(errp, "misa_mxl_max must be equal to misa_mxl");
99
- return;
100
- }
101
-}
102
-
103
/*
104
* Check consistency between chosen extensions while setting
105
* cpu->cfg accordingly.
106
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_finalize_features(RISCVCPU *cpu, Error **errp)
107
#endif
108
}
109
110
-static void riscv_cpu_validate_misa_priv(CPURISCVState *env, Error **errp)
111
-{
112
- if (riscv_has_ext(env, RVH) && env->priv_ver < PRIV_VERSION_1_12_0) {
113
- error_setg(errp, "H extension requires priv spec 1.12.0");
114
- return;
115
- }
116
-}
117
-
118
-static void riscv_cpu_realize_tcg(DeviceState *dev, Error **errp)
119
-{
120
- RISCVCPU *cpu = RISCV_CPU(dev);
121
- CPURISCVState *env = &cpu->env;
122
- Error *local_err = NULL;
123
-
124
- if (object_dynamic_cast(OBJECT(dev), TYPE_RISCV_CPU_HOST)) {
125
- error_setg(errp, "'host' CPU is not compatible with TCG acceleration");
126
- return;
127
- }
128
-
129
- riscv_cpu_validate_misa_mxl(cpu, &local_err);
130
- if (local_err != NULL) {
131
- error_propagate(errp, local_err);
132
- return;
133
- }
134
-
135
- riscv_cpu_validate_priv_spec(cpu, &local_err);
136
- if (local_err != NULL) {
137
- error_propagate(errp, local_err);
138
- return;
139
- }
140
-
141
- riscv_cpu_validate_misa_priv(env, &local_err);
142
- if (local_err != NULL) {
143
- error_propagate(errp, local_err);
144
- return;
145
- }
146
-
147
- if (cpu->cfg.epmp && !cpu->cfg.pmp) {
148
- /*
149
- * Enhanced PMP should only be available
150
- * on harts with PMP support
151
- */
152
- error_setg(errp, "Invalid configuration: EPMP requires PMP support");
153
- return;
154
- }
155
-
156
- riscv_cpu_validate_set_extensions(cpu, &local_err);
157
- if (local_err != NULL) {
158
- error_propagate(errp, local_err);
159
- return;
160
- }
161
-
162
-#ifndef CONFIG_USER_ONLY
163
- CPU(dev)->tcg_cflags |= CF_PCREL;
164
-
165
- if (cpu->cfg.ext_sstc) {
166
- riscv_timer_init(cpu);
167
- }
168
-
169
- if (cpu->cfg.pmu_num) {
170
- if (!riscv_pmu_init(cpu, cpu->cfg.pmu_num) && cpu->cfg.ext_sscofpmf) {
171
- cpu->pmu_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL,
172
- riscv_pmu_timer_cb, cpu);
173
- }
174
- }
175
-#endif
176
-}
177
-
178
static void riscv_cpu_realize(DeviceState *dev, Error **errp)
179
{
180
CPUState *cs = CPU(dev);
181
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp)
182
return;
183
}
184
185
- if (tcg_enabled()) {
186
- riscv_cpu_realize_tcg(dev, &local_err);
187
- if (local_err != NULL) {
188
- error_propagate(errp, local_err);
189
- return;
190
- }
191
- }
192
-
193
riscv_cpu_finalize_features(cpu, &local_err);
194
if (local_err != NULL) {
195
error_propagate(errp, local_err);
196
diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c
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
+{
215
+ if (riscv_has_ext(env, RVH) && env->priv_ver < PRIV_VERSION_1_12_0) {
216
+ error_setg(errp, "H extension requires priv spec 1.12.0");
217
+ return;
218
+ }
219
+}
220
+
221
+static void riscv_cpu_validate_misa_mxl(RISCVCPU *cpu, Error **errp)
222
+{
223
+ RISCVCPUClass *mcc = RISCV_CPU_GET_CLASS(cpu);
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;
287
+ }
288
+
289
+ riscv_cpu_validate_misa_mxl(cpu, &local_err);
290
+ if (local_err != NULL) {
291
+ error_propagate(errp, local_err);
292
+ return false;
293
+ }
294
+
295
+ riscv_cpu_validate_priv_spec(cpu, &local_err);
296
+ if (local_err != NULL) {
297
+ error_propagate(errp, local_err);
298
+ return false;
299
+ }
300
+
301
+ riscv_cpu_validate_misa_priv(env, &local_err);
302
+ if (local_err != NULL) {
303
+ error_propagate(errp, local_err);
304
+ return false;
305
+ }
306
+
307
+ if (cpu->cfg.epmp && !cpu->cfg.pmp) {
308
+ /*
309
+ * Enhanced PMP should only be available
310
+ * on harts with PMP support
311
+ */
312
+ error_setg(errp, "Invalid configuration: EPMP requires PMP support");
313
+ return false;
314
+ }
315
+
316
+ riscv_cpu_validate_set_extensions(cpu, &local_err);
317
+ if (local_err != NULL) {
318
+ error_propagate(errp, local_err);
319
+ return false;
320
+ }
321
+
322
+#ifndef CONFIG_USER_ONLY
323
+ CPU(cs)->tcg_cflags |= CF_PCREL;
324
+
325
+ if (cpu->cfg.ext_sstc) {
326
+ riscv_timer_init(cpu);
327
+ }
328
+
329
+ if (cpu->cfg.pmu_num) {
330
+ if (!riscv_pmu_init(cpu, cpu->cfg.pmu_num) && cpu->cfg.ext_sscofpmf) {
331
+ cpu->pmu_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL,
332
+ riscv_pmu_timer_cb, cpu);
333
+ }
334
+ }
335
+#endif
336
+
337
+ return true;
338
+}
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
--
352
2.41.0
diff view generated by jsdifflib
New patch
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
2
3
This function is the core of the RISC-V validations for TCG CPUs, and it
4
has a lot going on.
5
6
Functions in cpu.c were made public to allow them to be used by the KVM
7
accelerator class later on. 'cpu_cfg_ext_get_min_version()' is notably
8
hard to move it to another file due to its dependency with isa_edata_arr[]
9
array, thus make it public and use it as is for now.
10
11
riscv_cpu_validate_set_extensions() is kept public because it's used by
12
csr.c in write_misa().
13
14
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
15
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
16
Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
17
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
18
Message-ID: <20230925175709.35696-4-dbarboza@ventanamicro.com>
19
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
20
---
21
target/riscv/cpu.h | 8 +-
22
target/riscv/tcg/tcg-cpu.h | 27 +++
23
target/riscv/cpu.c | 361 +------------------------------------
24
target/riscv/csr.c | 1 +
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
29
diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
30
index XXXXXXX..XXXXXXX 100644
31
--- a/target/riscv/cpu.h
32
+++ b/target/riscv/cpu.h
33
@@ -XXX,XX +XXX,XX @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size,
34
bool probe, uintptr_t retaddr);
35
char *riscv_isa_string(RISCVCPU *cpu);
36
void riscv_cpu_list(void);
37
-void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp);
38
39
#define cpu_list riscv_cpu_list
40
#define cpu_mmu_index riscv_cpu_mmu_index
41
@@ -XXX,XX +XXX,XX @@ enum riscv_pmu_event_idx {
42
#include "hw/core/tcg-cpu-ops.h"
43
extern const struct TCGCPUOps riscv_tcg_ops;
44
45
+/* used by tcg/tcg-cpu.c*/
46
+void isa_ext_update_enabled(RISCVCPU *cpu, uint32_t ext_offset, bool en);
47
+bool cpu_cfg_ext_is_user_set(uint32_t ext_offset);
48
+bool isa_ext_is_enabled(RISCVCPU *cpu, uint32_t ext_offset);
49
+int cpu_cfg_ext_get_min_version(uint32_t ext_offset);
50
+void riscv_cpu_disable_priv_spec_isa_exts(RISCVCPU *cpu);
51
+
52
/* CSR function table */
53
extern riscv_csr_operations csr_ops[CSR_TABLE_SIZE];
54
55
diff --git a/target/riscv/tcg/tcg-cpu.h b/target/riscv/tcg/tcg-cpu.h
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
499
index XXXXXXX..XXXXXXX 100644
500
--- a/target/riscv/csr.c
501
+++ b/target/riscv/csr.c
502
@@ -XXX,XX +XXX,XX @@
503
#include "qemu/log.h"
504
#include "qemu/timer.h"
505
#include "cpu.h"
506
+#include "tcg/tcg-cpu.h"
507
#include "pmu.h"
508
#include "time_helper.h"
509
#include "exec/exec-all.h"
510
diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c
511
index XXXXXXX..XXXXXXX 100644
512
--- a/target/riscv/tcg/tcg-cpu.c
513
+++ b/target/riscv/tcg/tcg-cpu.c
514
@@ -XXX,XX +XXX,XX @@
515
516
#include "qemu/osdep.h"
517
#include "exec/exec-all.h"
518
+#include "tcg-cpu.h"
519
#include "cpu.h"
520
#include "pmu.h"
521
#include "time_helper.h"
522
#include "qapi/error.h"
523
#include "qemu/accel.h"
524
+#include "qemu/error-report.h"
525
+#include "qemu/log.h"
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
+{
532
+ CPURISCVState *env = &cpu->env;
533
+ bool prev_val = isa_ext_is_enabled(cpu, ext_offset);
534
+ int min_version;
535
+
536
+ if (prev_val == value) {
537
+ return;
538
+ }
539
+
540
+ if (cpu_cfg_ext_is_user_set(ext_offset)) {
541
+ return;
542
+ }
543
+
544
+ if (value && env->priv_ver != PRIV_VERSION_LATEST) {
545
+ /* Do not enable it if priv_ver is older than min_version */
546
+ min_version = cpu_cfg_ext_get_min_version(ext_offset);
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
+ }
840
+
841
+ /*
842
+ * In principle Zve*x would also suffice here, were they supported
843
+ * in qemu
844
+ */
845
+ if ((cpu->cfg.ext_zvbb || cpu->cfg.ext_zvkg || cpu->cfg.ext_zvkned ||
846
+ cpu->cfg.ext_zvknha || cpu->cfg.ext_zvksed || cpu->cfg.ext_zvksh) &&
847
+ !cpu->cfg.ext_zve32f) {
848
+ error_setg(errp,
849
+ "Vector crypto extensions require V or Zve* extensions");
850
+ return;
851
+ }
852
+
853
+ if ((cpu->cfg.ext_zvbc || cpu->cfg.ext_zvknhb) && !cpu->cfg.ext_zve64f) {
854
+ error_setg(
855
+ errp,
856
+ "Zvbc and Zvknhb extensions require V or Zve64{f,d} extensions");
857
+ return;
858
+ }
859
+
860
+ if (cpu->cfg.ext_zk) {
861
+ cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zkn), true);
862
+ cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zkr), true);
863
+ cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zkt), true);
864
+ }
865
+
866
+ if (cpu->cfg.ext_zkn) {
867
+ cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zbkb), true);
868
+ cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zbkc), true);
869
+ cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zbkx), true);
870
+ cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zkne), true);
871
+ cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zknd), true);
872
+ cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zknh), true);
873
+ }
874
+
875
+ if (cpu->cfg.ext_zks) {
876
+ cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zbkb), true);
877
+ cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zbkc), true);
878
+ cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zbkx), true);
879
+ cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zksed), true);
880
+ cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_zksh), true);
881
+ }
882
+
883
+ /*
884
+ * Disable isa extensions based on priv spec after we
885
+ * validated and set everything we need.
886
+ */
887
+ riscv_cpu_disable_priv_spec_isa_exts(cpu);
888
+}
889
+
890
/*
891
* We'll get here via the following path:
892
*
893
--
894
2.41.0
diff view generated by jsdifflib
New patch
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
2
3
Move the remaining of riscv_tcg_ops now that we have a working realize()
4
implementation.
5
6
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
7
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
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-5-dbarboza@ventanamicro.com>
12
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
13
---
14
target/riscv/cpu.h | 4 ---
15
target/riscv/cpu.c | 58 ------------------------------------
16
target/riscv/tcg/tcg-cpu.c | 60 +++++++++++++++++++++++++++++++++++++-
17
3 files changed, 59 insertions(+), 63 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 @@ enum riscv_pmu_event_idx {
24
RISCV_PMU_EVENT_CACHE_ITLB_PREFETCH_MISS = 0x10021,
25
};
26
27
-/* Export tcg_ops until we move everything to tcg/tcg-cpu.c */
28
-#include "hw/core/tcg-cpu-ops.h"
29
-extern const struct TCGCPUOps riscv_tcg_ops;
30
-
31
/* used by tcg/tcg-cpu.c*/
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
}
41
42
-static void riscv_cpu_synchronize_from_tb(CPUState *cs,
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
{
62
#ifndef CONFIG_USER_ONLY
63
@@ -XXX,XX +XXX,XX @@ static bool riscv_cpu_has_work(CPUState *cs)
64
#endif
65
}
66
67
-static void riscv_restore_state_to_opc(CPUState *cs,
68
- const TranslationBlock *tb,
69
- const uint64_t *data)
70
-{
71
- RISCVCPU *cpu = RISCV_CPU(cs);
72
- CPURISCVState *env = &cpu->env;
73
- RISCVMXL xl = FIELD_EX32(tb->flags, TB_FLAGS, XL);
74
- target_ulong pc;
75
-
76
- if (tb_cflags(tb) & CF_PCREL) {
77
- pc = (env->pc & TARGET_PAGE_MASK) | data[0];
78
- } else {
79
- pc = data[0];
80
- }
81
-
82
- if (xl == MXL_RV32) {
83
- env->pc = (int32_t)pc;
84
- } else {
85
- env->pc = pc;
86
- }
87
- env->bins = data[1];
88
-}
89
-
90
static void riscv_cpu_reset_hold(Object *obj)
91
{
92
#ifndef CONFIG_USER_ONLY
93
@@ -XXX,XX +XXX,XX @@ static const struct SysemuCPUOps riscv_sysemu_ops = {
94
};
95
#endif
96
97
-const struct TCGCPUOps riscv_tcg_ops = {
98
- .initialize = riscv_translate_init,
99
- .synchronize_from_tb = riscv_cpu_synchronize_from_tb,
100
- .restore_state_to_opc = riscv_restore_state_to_opc,
101
-
102
-#ifndef CONFIG_USER_ONLY
103
- .tlb_fill = riscv_cpu_tlb_fill,
104
- .cpu_exec_interrupt = riscv_cpu_exec_interrupt,
105
- .do_interrupt = riscv_cpu_do_interrupt,
106
- .do_transaction_failed = riscv_cpu_do_transaction_failed,
107
- .do_unaligned_access = riscv_cpu_do_unaligned_access,
108
- .debug_excp_handler = riscv_cpu_debug_excp_handler,
109
- .debug_check_breakpoint = riscv_cpu_debug_check_breakpoint,
110
- .debug_check_watchpoint = riscv_cpu_debug_check_watchpoint,
111
-#endif /* !CONFIG_USER_ONLY */
112
-};
113
-
114
static bool riscv_cpu_is_dynamic(Object *cpu_obj)
115
{
116
return object_dynamic_cast(cpu_obj, TYPE_RISCV_DYNAMIC_CPU) != NULL;
117
diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c
118
index XXXXXXX..XXXXXXX 100644
119
--- a/target/riscv/tcg/tcg-cpu.c
120
+++ b/target/riscv/tcg/tcg-cpu.c
121
@@ -XXX,XX +XXX,XX @@
122
#include "qemu/error-report.h"
123
#include "qemu/log.h"
124
#include "hw/core/accel-cpu.h"
125
+#include "hw/core/tcg-cpu-ops.h"
126
+#include "tcg/tcg.h"
127
128
+static void riscv_cpu_synchronize_from_tb(CPUState *cs,
129
+ const TranslationBlock *tb)
130
+{
131
+ if (!(tb_cflags(tb) & CF_PCREL)) {
132
+ RISCVCPU *cpu = RISCV_CPU(cs);
133
+ CPURISCVState *env = &cpu->env;
134
+ RISCVMXL xl = FIELD_EX32(tb->flags, TB_FLAGS, XL);
135
+
136
+ tcg_debug_assert(!(cs->tcg_cflags & CF_PCREL));
137
+
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
}
196
--
197
2.41.0
198
199
diff view generated by jsdifflib
New patch
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
2
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
New patch
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
2
3
This CPU only exists if we're compiling with KVM so move it to the kvm
4
specific file.
5
6
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
7
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
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-7-dbarboza@ventanamicro.com>
12
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
13
---
14
target/riscv/cpu.c | 15 ---------------
15
target/riscv/kvm.c | 21 +++++++++++++++++++++
16
2 files changed, 21 insertions(+), 15 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 void rv32_imafcu_nommu_cpu_init(Object *obj)
23
}
24
#endif
25
26
-#if defined(CONFIG_KVM)
27
-static void riscv_host_cpu_init(Object *obj)
28
-{
29
- CPURISCVState *env = &RISCV_CPU(obj)->env;
30
-#if defined(TARGET_RISCV32)
31
- set_misa(env, MXL_RV32, 0);
32
-#elif defined(TARGET_RISCV64)
33
- set_misa(env, MXL_RV64, 0);
34
-#endif
35
-}
36
-#endif /* CONFIG_KVM */
37
-
38
static ObjectClass *riscv_cpu_class_by_name(const char *cpu_model)
39
{
40
ObjectClass *oc;
41
@@ -XXX,XX +XXX,XX @@ static const TypeInfo riscv_cpu_type_infos[] = {
42
},
43
DEFINE_DYNAMIC_CPU(TYPE_RISCV_CPU_ANY, riscv_any_cpu_init),
44
DEFINE_DYNAMIC_CPU(TYPE_RISCV_CPU_MAX, riscv_max_cpu_init),
45
-#if defined(CONFIG_KVM)
46
- DEFINE_CPU(TYPE_RISCV_CPU_HOST, riscv_host_cpu_init),
47
-#endif
48
#if defined(TARGET_RISCV32)
49
DEFINE_DYNAMIC_CPU(TYPE_RISCV_CPU_BASE32, rv32_base_cpu_init),
50
DEFINE_CPU(TYPE_RISCV_CPU_IBEX, rv32_ibex_cpu_init),
51
diff --git a/target/riscv/kvm.c b/target/riscv/kvm.c
52
index XXXXXXX..XXXXXXX 100644
53
--- a/target/riscv/kvm.c
54
+++ b/target/riscv/kvm.c
55
@@ -XXX,XX +XXX,XX @@ void kvm_riscv_aia_create(MachineState *machine, uint64_t group_shift,
56
57
kvm_msi_via_irqfd_allowed = kvm_irqfds_enabled();
58
}
59
+
60
+static void riscv_host_cpu_init(Object *obj)
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
--
81
2.41.0
82
83
diff view generated by jsdifflib
New patch
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
2
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
New patch
1
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
2
3
We'll introduce the KVM accelerator class with a 'cpu_instance_init'
4
implementation that is going to be invoked during the common
5
riscv_cpu_post_init() (via accel_cpu_instance_init()). This
6
instance_init will execute KVM exclusive code that TCG doesn't care
7
about, such as adding KVM specific properties, initing registers using a
8
KVM scratch CPU and so on.
9
10
The core of the forementioned cpu_instance_init impl is the current
11
riscv_cpu_add_kvm_properties() that is being used by the common code via
12
riscv_cpu_add_user_properties() in cpu.c. Move it to kvm.c, together
13
will all the relevant artifacts, exporting and renaming it to
14
kvm_riscv_cpu_add_kvm_properties() so cpu.c can keep using it for now.
15
16
To make this work we'll need to export riscv_cpu_extensions,
17
riscv_cpu_vendor_exts and riscv_cpu_experimental_exts from cpu.c as
18
well. The TCG accelerator will also need to access those in the near
19
future so this export will benefit us in the long run.
20
21
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
22
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
23
Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
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>
27
---
28
target/riscv/cpu.h | 14 +++++++
29
target/riscv/kvm_riscv.h | 3 --
30
target/riscv/cpu.c | 85 +++-------------------------------------
31
target/riscv/kvm.c | 68 +++++++++++++++++++++++++++++++-
32
4 files changed, 86 insertions(+), 84 deletions(-)
33
34
diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
35
index XXXXXXX..XXXXXXX 100644
36
--- a/target/riscv/cpu.h
37
+++ b/target/riscv/cpu.h
38
@@ -XXX,XX +XXX,XX @@
39
40
#include "hw/core/cpu.h"
41
#include "hw/registerfields.h"
42
+#include "hw/qdev-properties.h"
43
#include "exec/cpu-defs.h"
44
#include "qemu/cpu-float.h"
45
#include "qom/object.h"
46
@@ -XXX,XX +XXX,XX @@ bool isa_ext_is_enabled(RISCVCPU *cpu, uint32_t ext_offset);
47
int cpu_cfg_ext_get_min_version(uint32_t ext_offset);
48
void riscv_cpu_disable_priv_spec_isa_exts(RISCVCPU *cpu);
49
50
+typedef struct RISCVCPUMultiExtConfig {
51
+ const char *name;
52
+ uint32_t offset;
53
+ bool enabled;
54
+} RISCVCPUMultiExtConfig;
55
+
56
+extern const RISCVCPUMultiExtConfig riscv_cpu_extensions[];
57
+extern const RISCVCPUMultiExtConfig riscv_cpu_vendor_exts[];
58
+extern const RISCVCPUMultiExtConfig riscv_cpu_experimental_exts[];
59
+extern Property riscv_cpu_options[];
60
+
61
+void riscv_cpu_add_misa_properties(Object *cpu_obj);
62
+
63
/* CSR function table */
64
extern riscv_csr_operations csr_ops[CSR_TABLE_SIZE];
65
66
diff --git a/target/riscv/kvm_riscv.h b/target/riscv/kvm_riscv.h
67
index XXXXXXX..XXXXXXX 100644
68
--- a/target/riscv/kvm_riscv.h
69
+++ b/target/riscv/kvm_riscv.h
70
@@ -XXX,XX +XXX,XX @@
71
#ifndef QEMU_KVM_RISCV_H
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
};
116
117
-static const RISCVCPUMultiExtConfig riscv_cpu_vendor_exts[] = {
118
+const RISCVCPUMultiExtConfig riscv_cpu_vendor_exts[] = {
119
MULTI_EXT_CFG_BOOL("xtheadba", ext_xtheadba, false),
120
MULTI_EXT_CFG_BOOL("xtheadbb", ext_xtheadbb, false),
121
MULTI_EXT_CFG_BOOL("xtheadbs", ext_xtheadbs, false),
122
@@ -XXX,XX +XXX,XX @@ static const RISCVCPUMultiExtConfig riscv_cpu_vendor_exts[] = {
123
};
124
125
/* These are experimental so mark with 'x-' */
126
-static const RISCVCPUMultiExtConfig riscv_cpu_experimental_exts[] = {
127
+const RISCVCPUMultiExtConfig riscv_cpu_experimental_exts[] = {
128
/* ePMP 0.9.3 */
129
MULTI_EXT_CFG_BOOL("x-epmp", epmp, false),
130
MULTI_EXT_CFG_BOOL("x-smaia", ext_smaia, false),
131
@@ -XXX,XX +XXX,XX @@ static const RISCVCPUMultiExtConfig riscv_cpu_experimental_exts[] = {
132
DEFINE_PROP_END_OF_LIST(),
133
};
134
135
-static Property riscv_cpu_options[] = {
136
+Property riscv_cpu_options[] = {
137
DEFINE_PROP_UINT8("pmu-num", RISCVCPU, cfg.pmu_num, 16),
138
139
DEFINE_PROP_BOOL("mmu", RISCVCPU, cfg.mmu, true),
140
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_add_multiext_prop_array(Object *obj,
141
}
142
}
143
144
-#ifdef CONFIG_KVM
145
-static void cpu_set_cfg_unavailable(Object *obj, Visitor *v,
146
- const char *name,
147
- void *opaque, Error **errp)
148
-{
149
- const char *propname = opaque;
150
- bool value;
151
-
152
- if (!visit_type_bool(v, name, &value, errp)) {
153
- return;
154
- }
155
-
156
- if (value) {
157
- error_setg(errp, "extension %s is not available with KVM",
158
- propname);
159
- }
160
-}
161
-
162
-static void riscv_cpu_add_kvm_unavail_prop(Object *obj, const char *prop_name)
163
-{
164
- /* Check if KVM created the property already */
165
- if (object_property_find(obj, prop_name)) {
166
- return;
167
- }
168
-
169
- /*
170
- * Set the default to disabled for every extension
171
- * unknown to KVM and error out if the user attempts
172
- * to enable any of them.
173
- */
174
- object_property_add(obj, prop_name, "bool",
175
- NULL, cpu_set_cfg_unavailable,
176
- NULL, (void *)prop_name);
177
-}
178
-
179
-static void riscv_cpu_add_kvm_unavail_prop_array(Object *obj,
180
- const RISCVCPUMultiExtConfig *array)
181
-{
182
- const RISCVCPUMultiExtConfig *prop;
183
-
184
- g_assert(array);
185
-
186
- for (prop = array; prop && prop->name; prop++) {
187
- riscv_cpu_add_kvm_unavail_prop(obj, prop->name);
188
- }
189
-}
190
-
191
-void kvm_riscv_cpu_add_kvm_properties(Object *obj)
192
-{
193
- Property *prop;
194
- DeviceState *dev = DEVICE(obj);
195
-
196
- kvm_riscv_init_user_properties(obj);
197
- riscv_cpu_add_misa_properties(obj);
198
-
199
- riscv_cpu_add_kvm_unavail_prop_array(obj, riscv_cpu_extensions);
200
- riscv_cpu_add_kvm_unavail_prop_array(obj, riscv_cpu_vendor_exts);
201
- riscv_cpu_add_kvm_unavail_prop_array(obj, riscv_cpu_experimental_exts);
202
-
203
- for (prop = riscv_cpu_options; prop && prop->name; prop++) {
204
- /* Check if KVM created the property already */
205
- if (object_property_find(obj, prop->name)) {
206
- continue;
207
- }
208
- qdev_property_add_static(dev, prop);
209
- }
210
-}
211
-#endif
212
-
213
/*
214
* Add CPU properties with user-facing flags.
215
*
216
diff --git a/target/riscv/kvm.c b/target/riscv/kvm.c
217
index XXXXXXX..XXXXXXX 100644
218
--- a/target/riscv/kvm.c
219
+++ b/target/riscv/kvm.c
220
@@ -XXX,XX +XXX,XX @@ static void kvm_riscv_update_cpu_cfg_isa_ext(RISCVCPU *cpu, CPUState *cs)
221
}
222
}
223
224
+static void cpu_set_cfg_unavailable(Object *obj, Visitor *v,
225
+ const char *name,
226
+ void *opaque, Error **errp)
227
+{
228
+ const char *propname = opaque;
229
+ bool value;
230
+
231
+ if (!visit_type_bool(v, name, &value, errp)) {
232
+ return;
233
+ }
234
+
235
+ if (value) {
236
+ error_setg(errp, "extension %s is not available with KVM",
237
+ propname);
238
+ }
239
+}
240
+
241
+static void riscv_cpu_add_kvm_unavail_prop(Object *obj, const char *prop_name)
242
+{
243
+ /* Check if KVM created the property already */
244
+ if (object_property_find(obj, prop_name)) {
245
+ return;
246
+ }
247
+
248
+ /*
249
+ * Set the default to disabled for every extension
250
+ * unknown to KVM and error out if the user attempts
251
+ * to enable any of them.
252
+ */
253
+ object_property_add(obj, prop_name, "bool",
254
+ NULL, cpu_set_cfg_unavailable,
255
+ NULL, (void *)prop_name);
256
+}
257
+
258
+static void riscv_cpu_add_kvm_unavail_prop_array(Object *obj,
259
+ const RISCVCPUMultiExtConfig *array)
260
+{
261
+ const RISCVCPUMultiExtConfig *prop;
262
+
263
+ g_assert(array);
264
+
265
+ for (prop = array; prop && prop->name; prop++) {
266
+ riscv_cpu_add_kvm_unavail_prop(obj, prop->name);
267
+ }
268
+}
269
+
270
static void kvm_riscv_add_cpu_user_properties(Object *cpu_obj)
271
{
272
int i;
273
@@ -XXX,XX +XXX,XX @@ static void kvm_riscv_init_multiext_cfg(RISCVCPU *cpu, KVMScratchCPU *kvmcpu)
274
}
275
}
276
277
-void kvm_riscv_init_user_properties(Object *cpu_obj)
278
+static void riscv_init_user_properties(Object *cpu_obj)
279
{
280
RISCVCPU *cpu = RISCV_CPU(cpu_obj);
281
KVMScratchCPU kvmcpu;
282
@@ -XXX,XX +XXX,XX @@ void kvm_riscv_aia_create(MachineState *machine, uint64_t group_shift,
283
kvm_msi_via_irqfd_allowed = kvm_irqfds_enabled();
284
}
285
286
+void kvm_riscv_cpu_add_kvm_properties(Object *obj)
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
--
310
2.41.0
diff view generated by jsdifflib
New patch
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
2
3
This function is used for both accelerators. Make it public, and call it
4
from kvm_riscv_cpu_add_kvm_properties(). This will make it easier to
5
split KVM specific code for the KVM accelerator class in the next patch.
6
7
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
8
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
9
Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
10
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
11
Message-ID: <20230925175709.35696-10-dbarboza@ventanamicro.com>
12
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
13
---
14
target/riscv/cpu.h | 1 +
15
target/riscv/cpu.c | 5 ++---
16
target/riscv/kvm.c | 1 +
17
3 files changed, 4 insertions(+), 3 deletions(-)
18
19
diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
20
index XXXXXXX..XXXXXXX 100644
21
--- a/target/riscv/cpu.h
22
+++ b/target/riscv/cpu.h
23
@@ -XXX,XX +XXX,XX @@ extern const RISCVCPUMultiExtConfig riscv_cpu_experimental_exts[];
24
extern Property riscv_cpu_options[];
25
26
void riscv_cpu_add_misa_properties(Object *cpu_obj);
27
+void riscv_add_satp_mode_properties(Object *obj);
28
29
/* CSR function table */
30
extern riscv_csr_operations csr_ops[CSR_TABLE_SIZE];
31
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
32
index XXXXXXX..XXXXXXX 100644
33
--- a/target/riscv/cpu.c
34
+++ b/target/riscv/cpu.c
35
@@ -XXX,XX +XXX,XX @@ static void cpu_riscv_set_satp(Object *obj, Visitor *v, const char *name,
36
satp_map->init |= 1 << satp;
37
}
38
39
-static void riscv_add_satp_mode_properties(Object *obj)
40
+void riscv_add_satp_mode_properties(Object *obj)
41
{
42
RISCVCPU *cpu = RISCV_CPU(obj);
43
44
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_add_multiext_prop_array(Object *obj,
45
static void riscv_cpu_add_user_properties(Object *obj)
46
{
47
#ifndef CONFIG_USER_ONLY
48
- riscv_add_satp_mode_properties(obj);
49
-
50
if (kvm_enabled()) {
51
kvm_riscv_cpu_add_kvm_properties(obj);
52
return;
53
}
54
+ riscv_add_satp_mode_properties(obj);
55
#endif
56
57
riscv_cpu_add_misa_properties(obj);
58
diff --git a/target/riscv/kvm.c b/target/riscv/kvm.c
59
index XXXXXXX..XXXXXXX 100644
60
--- a/target/riscv/kvm.c
61
+++ b/target/riscv/kvm.c
62
@@ -XXX,XX +XXX,XX @@ void kvm_riscv_cpu_add_kvm_properties(Object *obj)
63
DeviceState *dev = DEVICE(obj);
64
65
riscv_init_user_properties(obj);
66
+ riscv_add_satp_mode_properties(obj);
67
riscv_cpu_add_misa_properties(obj);
68
69
riscv_cpu_add_kvm_unavail_prop_array(obj, riscv_cpu_extensions);
70
--
71
2.41.0
diff view generated by jsdifflib
New patch
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
2
3
This file is not needed for some time now. Both kvm_riscv_reset_vcpu()
4
and kvm_riscv_set_irq() have public declarations in kvm_riscv.h and are
5
wrapped in 'if kvm_enabled()' blocks that the compiler will rip it out
6
in non-KVM builds.
7
8
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
9
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
10
Message-ID: <20230925175709.35696-11-dbarboza@ventanamicro.com>
11
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
12
---
13
target/riscv/kvm-stub.c | 30 ------------------------------
14
target/riscv/meson.build | 2 +-
15
2 files changed, 1 insertion(+), 31 deletions(-)
16
delete mode 100644 target/riscv/kvm-stub.c
17
18
diff --git a/target/riscv/kvm-stub.c b/target/riscv/kvm-stub.c
19
deleted file mode 100644
20
index XXXXXXX..XXXXXXX
21
--- a/target/riscv/kvm-stub.c
22
+++ /dev/null
23
@@ -XXX,XX +XXX,XX @@
24
-/*
25
- * QEMU KVM RISC-V specific function stubs
26
- *
27
- * Copyright (c) 2020 Huawei Technologies Co., Ltd
28
- *
29
- * This program is free software; you can redistribute it and/or modify it
30
- * under the terms and conditions of the GNU General Public License,
31
- * version 2 or later, as published by the Free Software Foundation.
32
- *
33
- * This program is distributed in the hope it will be useful, but WITHOUT
34
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
35
- * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
36
- * more details.
37
- *
38
- * You should have received a copy of the GNU General Public License along with
39
- * this program. If not, see <http://www.gnu.org/licenses/>.
40
- */
41
-#include "qemu/osdep.h"
42
-#include "cpu.h"
43
-#include "kvm_riscv.h"
44
-
45
-void kvm_riscv_reset_vcpu(RISCVCPU *cpu)
46
-{
47
- abort();
48
-}
49
-
50
-void kvm_riscv_set_irq(RISCVCPU *cpu, int irq, int level)
51
-{
52
- abort();
53
-}
54
diff --git a/target/riscv/meson.build b/target/riscv/meson.build
55
index XXXXXXX..XXXXXXX 100644
56
--- a/target/riscv/meson.build
57
+++ b/target/riscv/meson.build
58
@@ -XXX,XX +XXX,XX @@ riscv_ss.add(files(
59
'zce_helper.c',
60
'vcrypto_helper.c'
61
))
62
-riscv_ss.add(when: 'CONFIG_KVM', if_true: files('kvm.c'), if_false: files('kvm-stub.c'))
63
+riscv_ss.add(when: 'CONFIG_KVM', if_true: files('kvm.c'))
64
65
riscv_system_ss = ss.source_set()
66
riscv_system_ss.add(files(
67
--
68
2.41.0
diff view generated by jsdifflib
New patch
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
2
3
Add a KVM accelerator class like we did with TCG. The difference is
4
that, at least for now, we won't be using a realize() implementation for
5
this accelerator.
6
7
We'll start by assiging kvm_riscv_cpu_add_kvm_properties(), renamed to
8
kvm_cpu_instance_init(), as a 'cpu_instance_init' implementation. Change
9
riscv_cpu_post_init() to invoke accel_cpu_instance_init(), which will go
10
through the 'cpu_instance_init' impl of the current acceleration (if
11
available) and execute it. The end result is that the KVM initial setup,
12
i.e. starting registers and adding its specific properties, will be done
13
via this hook.
14
15
Add a 'tcg_enabled()' condition in riscv_cpu_post_init() to avoid
16
calling riscv_cpu_add_user_properties() when running KVM. We'll remove
17
this condition when the TCG accel class get its own 'cpu_instance_init'
18
implementation.
19
20
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
21
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
22
Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
23
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
24
Message-ID: <20230925175709.35696-12-dbarboza@ventanamicro.com>
25
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
26
---
27
target/riscv/kvm_riscv.h | 1 -
28
target/riscv/cpu.c | 8 +++-----
29
target/riscv/kvm.c | 26 ++++++++++++++++++++++++--
30
3 files changed, 27 insertions(+), 8 deletions(-)
31
32
diff --git a/target/riscv/kvm_riscv.h b/target/riscv/kvm_riscv.h
33
index XXXXXXX..XXXXXXX 100644
34
--- a/target/riscv/kvm_riscv.h
35
+++ b/target/riscv/kvm_riscv.h
36
@@ -XXX,XX +XXX,XX @@
37
#ifndef QEMU_KVM_RISCV_H
38
#define QEMU_KVM_RISCV_H
39
40
-void kvm_riscv_cpu_add_kvm_properties(Object *obj);
41
void kvm_riscv_reset_vcpu(RISCVCPU *cpu);
42
void kvm_riscv_set_irq(RISCVCPU *cpu, int irq, int level);
43
void kvm_riscv_aia_create(MachineState *machine, uint64_t group_shift,
44
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
45
index XXXXXXX..XXXXXXX 100644
46
--- a/target/riscv/cpu.c
47
+++ b/target/riscv/cpu.c
48
@@ -XXX,XX +XXX,XX @@ static bool riscv_cpu_has_user_properties(Object *cpu_obj)
49
50
static void riscv_cpu_post_init(Object *obj)
51
{
52
- if (riscv_cpu_has_user_properties(obj)) {
53
+ accel_cpu_instance_init(CPU(obj));
54
+
55
+ if (tcg_enabled() && riscv_cpu_has_user_properties(obj)) {
56
riscv_cpu_add_user_properties(obj);
57
}
58
59
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_add_multiext_prop_array(Object *obj,
60
static void riscv_cpu_add_user_properties(Object *obj)
61
{
62
#ifndef CONFIG_USER_ONLY
63
- if (kvm_enabled()) {
64
- kvm_riscv_cpu_add_kvm_properties(obj);
65
- return;
66
- }
67
riscv_add_satp_mode_properties(obj);
68
#endif
69
70
diff --git a/target/riscv/kvm.c b/target/riscv/kvm.c
71
index XXXXXXX..XXXXXXX 100644
72
--- a/target/riscv/kvm.c
73
+++ b/target/riscv/kvm.c
74
@@ -XXX,XX +XXX,XX @@
75
#include "sysemu/kvm_int.h"
76
#include "cpu.h"
77
#include "trace.h"
78
+#include "hw/core/accel-cpu.h"
79
#include "hw/pci/pci.h"
80
#include "exec/memattrs.h"
81
#include "exec/address-spaces.h"
82
@@ -XXX,XX +XXX,XX @@ void kvm_riscv_aia_create(MachineState *machine, uint64_t group_shift,
83
kvm_msi_via_irqfd_allowed = kvm_irqfds_enabled();
84
}
85
86
-void kvm_riscv_cpu_add_kvm_properties(Object *obj)
87
+static void kvm_cpu_instance_init(CPUState *cs)
88
{
89
+ Object *obj = OBJECT(RISCV_CPU(cs));
90
DeviceState *dev = DEVICE(obj);
91
92
riscv_init_user_properties(obj);
93
@@ -XXX,XX +XXX,XX @@ void kvm_riscv_cpu_add_kvm_properties(Object *obj)
94
riscv_cpu_add_kvm_unavail_prop_array(obj, riscv_cpu_experimental_exts);
95
96
for (Property *prop = riscv_cpu_options; prop && prop->name; prop++) {
97
- /* Check if KVM created the property already */
98
+ /* Check if we have a specific KVM handler for the option */
99
if (object_property_find(obj, prop->name)) {
100
continue;
101
}
102
@@ -XXX,XX +XXX,XX @@ void kvm_riscv_cpu_add_kvm_properties(Object *obj)
103
}
104
}
105
106
+static void kvm_cpu_accel_class_init(ObjectClass *oc, void *data)
107
+{
108
+ AccelCPUClass *acc = ACCEL_CPU_CLASS(oc);
109
+
110
+ acc->cpu_instance_init = kvm_cpu_instance_init;
111
+}
112
+
113
+static const TypeInfo kvm_cpu_accel_type_info = {
114
+ .name = ACCEL_CPU_NAME("kvm"),
115
+
116
+ .parent = TYPE_ACCEL_CPU,
117
+ .class_init = kvm_cpu_accel_class_init,
118
+ .abstract = true,
119
+};
120
+static void kvm_cpu_accel_register_types(void)
121
+{
122
+ type_register_static(&kvm_cpu_accel_type_info);
123
+}
124
+type_init(kvm_cpu_accel_register_types);
125
+
126
static void riscv_host_cpu_init(Object *obj)
127
{
128
CPURISCVState *env = &RISCV_CPU(obj)->env;
129
--
130
2.41.0
diff view generated by jsdifflib
New patch
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
2
3
Move the files to a 'kvm' dir to promote more code separation between
4
accelerators and making our lives easier supporting build options such
5
as --disable-tcg.
6
7
Rename kvm.c to kvm-cpu.c to keep it in line with its TCG counterpart.
8
9
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
10
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
11
Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
12
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
13
Message-ID: <20230925175709.35696-13-dbarboza@ventanamicro.com>
14
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
15
---
16
target/riscv/{ => kvm}/kvm_riscv.h | 0
17
hw/intc/riscv_aplic.c | 2 +-
18
hw/riscv/virt.c | 2 +-
19
target/riscv/cpu.c | 2 +-
20
target/riscv/{kvm.c => kvm/kvm-cpu.c} | 0
21
target/riscv/kvm/meson.build | 1 +
22
target/riscv/meson.build | 2 +-
23
7 files changed, 5 insertions(+), 4 deletions(-)
24
rename target/riscv/{ => kvm}/kvm_riscv.h (100%)
25
rename target/riscv/{kvm.c => kvm/kvm-cpu.c} (100%)
26
create mode 100644 target/riscv/kvm/meson.build
27
28
diff --git a/target/riscv/kvm_riscv.h b/target/riscv/kvm/kvm_riscv.h
29
similarity index 100%
30
rename from target/riscv/kvm_riscv.h
31
rename to target/riscv/kvm/kvm_riscv.h
32
diff --git a/hw/intc/riscv_aplic.c b/hw/intc/riscv_aplic.c
33
index XXXXXXX..XXXXXXX 100644
34
--- a/hw/intc/riscv_aplic.c
35
+++ b/hw/intc/riscv_aplic.c
36
@@ -XXX,XX +XXX,XX @@
37
#include "target/riscv/cpu.h"
38
#include "sysemu/sysemu.h"
39
#include "sysemu/kvm.h"
40
-#include "kvm_riscv.h"
41
+#include "kvm/kvm_riscv.h"
42
#include "migration/vmstate.h"
43
44
#define APLIC_MAX_IDC (1UL << 14)
45
diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c
46
index XXXXXXX..XXXXXXX 100644
47
--- a/hw/riscv/virt.c
48
+++ b/hw/riscv/virt.c
49
@@ -XXX,XX +XXX,XX @@
50
#include "hw/riscv/virt.h"
51
#include "hw/riscv/boot.h"
52
#include "hw/riscv/numa.h"
53
-#include "kvm_riscv.h"
54
+#include "kvm/kvm_riscv.h"
55
#include "hw/intc/riscv_aclint.h"
56
#include "hw/intc/riscv_aplic.h"
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
--
103
2.41.0
diff view generated by jsdifflib
New patch
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
2
3
riscv_cpu_add_misa_properties() is being used to fill the missing KVM
4
MISA properties but it is a TCG helper that was adapted to do so. We'll
5
move it to tcg-cpu.c in the next patches, meaning that KVM needs to fill
6
the remaining MISA properties on its own.
7
8
Do not use riscv_cpu_add_misa_properties(). Let's create a new array
9
with all available MISA bits we support that can be read by KVM. The
10
array is zero terminate to allow us to iterate through it without
11
knowing its size.
12
13
Then, inside kvm_riscv_add_cpu_user_properties(), we'll create all KVM
14
MISA properties as usual and then use this array to add any missing MISA
15
properties with the riscv_cpu_add_kvm_unavail_prop() helper.
16
17
Note that we're creating misa_bits[], and not using the existing
18
'riscv_single_letter_exts[]', because the latter is tuned for riscv,isa
19
related functions and it doesn't have all MISA bits we support. Commit
20
0e2c377023 ("target/riscv: misa to ISA string conversion fix") has the
21
full context.
22
23
While we're at it, move both satp and the multi-letter extension
24
properties to kvm_riscv_add_cpu_user_properties() as well.
25
26
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
27
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
28
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
29
Message-ID: <20230925175709.35696-14-dbarboza@ventanamicro.com>
30
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
31
---
32
target/riscv/cpu.h | 3 ++-
33
target/riscv/cpu.c | 2 ++
34
target/riscv/kvm/kvm-cpu.c | 22 ++++++++++++++--------
35
3 files changed, 18 insertions(+), 9 deletions(-)
36
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
72
index XXXXXXX..XXXXXXX 100644
73
--- a/target/riscv/kvm/kvm-cpu.c
74
+++ b/target/riscv/kvm/kvm-cpu.c
75
@@ -XXX,XX +XXX,XX @@ static void kvm_riscv_add_cpu_user_properties(Object *cpu_obj)
76
{
77
int i;
78
79
+ riscv_add_satp_mode_properties(cpu_obj);
80
+
81
for (i = 0; i < ARRAY_SIZE(kvm_misa_ext_cfgs); i++) {
82
KVMCPUConfig *misa_cfg = &kvm_misa_ext_cfgs[i];
83
int bit = misa_cfg->offset;
84
@@ -XXX,XX +XXX,XX @@ static void kvm_riscv_add_cpu_user_properties(Object *cpu_obj)
85
misa_cfg->description);
86
}
87
88
+ for (i = 0; misa_bits[i] != 0; i++) {
89
+ const char *ext_name = riscv_get_misa_ext_name(misa_bits[i]);
90
+ riscv_cpu_add_kvm_unavail_prop(cpu_obj, ext_name);
91
+ }
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
}
109
}
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
--
141
2.41.0
diff view generated by jsdifflib
New patch
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
2
3
We'll move riscv_init_max_cpu_extensions() to tcg-cpu.c in the next
4
patch and set_misa() needs to be usable from there.
5
6
Rename it to riscv_cpu_set_misa() and make it public.
7
8
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
9
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
10
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
11
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
12
Message-ID: <20230925175709.35696-15-dbarboza@ventanamicro.com>
13
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
14
---
15
target/riscv/cpu.h | 1 +
16
target/riscv/cpu.c | 34 ++++++++++++++++++----------------
17
2 files changed, 19 insertions(+), 16 deletions(-)
18
19
diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
20
index XXXXXXX..XXXXXXX 100644
21
--- a/target/riscv/cpu.h
22
+++ b/target/riscv/cpu.h
23
@@ -XXX,XX +XXX,XX @@ void isa_ext_update_enabled(RISCVCPU *cpu, uint32_t ext_offset, bool en);
24
bool cpu_cfg_ext_is_user_set(uint32_t ext_offset);
25
bool isa_ext_is_enabled(RISCVCPU *cpu, uint32_t ext_offset);
26
int cpu_cfg_ext_get_min_version(uint32_t ext_offset);
27
+void riscv_cpu_set_misa(CPURISCVState *env, RISCVMXL mxl, uint32_t ext);
28
void riscv_cpu_disable_priv_spec_isa_exts(RISCVCPU *cpu);
29
30
typedef struct RISCVCPUMultiExtConfig {
31
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
32
index XXXXXXX..XXXXXXX 100644
33
--- a/target/riscv/cpu.c
34
+++ b/target/riscv/cpu.c
35
@@ -XXX,XX +XXX,XX @@ const char *riscv_cpu_get_trap_name(target_ulong cause, bool async)
36
}
37
}
38
39
-static void set_misa(CPURISCVState *env, RISCVMXL mxl, uint32_t ext)
40
+void riscv_cpu_set_misa(CPURISCVState *env, RISCVMXL mxl, uint32_t ext)
41
{
42
env->misa_mxl_max = env->misa_mxl = mxl;
43
env->misa_ext_mask = env->misa_ext = ext;
44
@@ -XXX,XX +XXX,XX @@ static void riscv_any_cpu_init(Object *obj)
45
RISCVCPU *cpu = RISCV_CPU(obj);
46
CPURISCVState *env = &cpu->env;
47
#if defined(TARGET_RISCV32)
48
- set_misa(env, MXL_RV32, RVI | RVM | RVA | RVF | RVD | RVC | RVU);
49
+ riscv_cpu_set_misa(env, MXL_RV32, RVI | RVM | RVA | RVF | RVD | RVC | RVU);
50
#elif defined(TARGET_RISCV64)
51
- set_misa(env, MXL_RV64, RVI | RVM | RVA | RVF | RVD | RVC | RVU);
52
+ riscv_cpu_set_misa(env, MXL_RV64, RVI | RVM | RVA | RVF | RVD | RVC | RVU);
53
#endif
54
55
#ifndef CONFIG_USER_ONLY
56
@@ -XXX,XX +XXX,XX @@ static void riscv_max_cpu_init(Object *obj)
57
#ifdef TARGET_RISCV32
58
mlx = MXL_RV32;
59
#endif
60
- set_misa(env, mlx, 0);
61
+ riscv_cpu_set_misa(env, mlx, 0);
62
env->priv_ver = PRIV_VERSION_LATEST;
63
#ifndef CONFIG_USER_ONLY
64
set_satp_mode_max_supported(RISCV_CPU(obj), mlx == MXL_RV32 ?
65
@@ -XXX,XX +XXX,XX @@ static void rv64_base_cpu_init(Object *obj)
66
{
67
CPURISCVState *env = &RISCV_CPU(obj)->env;
68
/* We set this in the realise function */
69
- set_misa(env, MXL_RV64, 0);
70
+ riscv_cpu_set_misa(env, MXL_RV64, 0);
71
/* Set latest version of privileged specification */
72
env->priv_ver = PRIV_VERSION_LATEST;
73
#ifndef CONFIG_USER_ONLY
74
@@ -XXX,XX +XXX,XX @@ static void rv64_sifive_u_cpu_init(Object *obj)
75
{
76
RISCVCPU *cpu = RISCV_CPU(obj);
77
CPURISCVState *env = &cpu->env;
78
- set_misa(env, MXL_RV64, RVI | RVM | RVA | RVF | RVD | RVC | RVS | RVU);
79
+ riscv_cpu_set_misa(env, MXL_RV64,
80
+ RVI | RVM | RVA | RVF | RVD | RVC | RVS | RVU);
81
env->priv_ver = PRIV_VERSION_1_10_0;
82
#ifndef CONFIG_USER_ONLY
83
set_satp_mode_max_supported(RISCV_CPU(obj), VM_1_10_SV39);
84
@@ -XXX,XX +XXX,XX @@ static void rv64_sifive_e_cpu_init(Object *obj)
85
CPURISCVState *env = &RISCV_CPU(obj)->env;
86
RISCVCPU *cpu = RISCV_CPU(obj);
87
88
- set_misa(env, MXL_RV64, RVI | RVM | RVA | RVC | RVU);
89
+ riscv_cpu_set_misa(env, MXL_RV64, RVI | RVM | RVA | RVC | RVU);
90
env->priv_ver = PRIV_VERSION_1_10_0;
91
#ifndef CONFIG_USER_ONLY
92
set_satp_mode_max_supported(cpu, VM_1_10_MBARE);
93
@@ -XXX,XX +XXX,XX @@ static void rv64_thead_c906_cpu_init(Object *obj)
94
CPURISCVState *env = &RISCV_CPU(obj)->env;
95
RISCVCPU *cpu = RISCV_CPU(obj);
96
97
- set_misa(env, MXL_RV64, RVG | RVC | RVS | RVU);
98
+ riscv_cpu_set_misa(env, MXL_RV64, RVG | RVC | RVS | RVU);
99
env->priv_ver = PRIV_VERSION_1_11_0;
100
101
cpu->cfg.ext_zfa = true;
102
@@ -XXX,XX +XXX,XX @@ static void rv64_veyron_v1_cpu_init(Object *obj)
103
CPURISCVState *env = &RISCV_CPU(obj)->env;
104
RISCVCPU *cpu = RISCV_CPU(obj);
105
106
- set_misa(env, MXL_RV64, RVG | RVC | RVS | RVU | RVH);
107
+ riscv_cpu_set_misa(env, MXL_RV64, RVG | RVC | RVS | RVU | RVH);
108
env->priv_ver = PRIV_VERSION_1_12_0;
109
110
/* Enable ISA extensions */
111
@@ -XXX,XX +XXX,XX @@ static void rv128_base_cpu_init(Object *obj)
112
}
113
CPURISCVState *env = &RISCV_CPU(obj)->env;
114
/* We set this in the realise function */
115
- set_misa(env, MXL_RV128, 0);
116
+ riscv_cpu_set_misa(env, MXL_RV128, 0);
117
/* Set latest version of privileged specification */
118
env->priv_ver = PRIV_VERSION_LATEST;
119
#ifndef CONFIG_USER_ONLY
120
@@ -XXX,XX +XXX,XX @@ static void rv32_base_cpu_init(Object *obj)
121
{
122
CPURISCVState *env = &RISCV_CPU(obj)->env;
123
/* We set this in the realise function */
124
- set_misa(env, MXL_RV32, 0);
125
+ riscv_cpu_set_misa(env, MXL_RV32, 0);
126
/* Set latest version of privileged specification */
127
env->priv_ver = PRIV_VERSION_LATEST;
128
#ifndef CONFIG_USER_ONLY
129
@@ -XXX,XX +XXX,XX @@ static void rv32_sifive_u_cpu_init(Object *obj)
130
{
131
RISCVCPU *cpu = RISCV_CPU(obj);
132
CPURISCVState *env = &cpu->env;
133
- set_misa(env, MXL_RV32, RVI | RVM | RVA | RVF | RVD | RVC | RVS | RVU);
134
+ riscv_cpu_set_misa(env, MXL_RV32,
135
+ RVI | RVM | RVA | RVF | RVD | RVC | RVS | RVU);
136
env->priv_ver = PRIV_VERSION_1_10_0;
137
#ifndef CONFIG_USER_ONLY
138
set_satp_mode_max_supported(RISCV_CPU(obj), VM_1_10_SV32);
139
@@ -XXX,XX +XXX,XX @@ static void rv32_sifive_e_cpu_init(Object *obj)
140
CPURISCVState *env = &RISCV_CPU(obj)->env;
141
RISCVCPU *cpu = RISCV_CPU(obj);
142
143
- set_misa(env, MXL_RV32, RVI | RVM | RVA | RVC | RVU);
144
+ riscv_cpu_set_misa(env, MXL_RV32, RVI | RVM | RVA | RVC | RVU);
145
env->priv_ver = PRIV_VERSION_1_10_0;
146
#ifndef CONFIG_USER_ONLY
147
set_satp_mode_max_supported(cpu, VM_1_10_MBARE);
148
@@ -XXX,XX +XXX,XX @@ static void rv32_ibex_cpu_init(Object *obj)
149
CPURISCVState *env = &RISCV_CPU(obj)->env;
150
RISCVCPU *cpu = RISCV_CPU(obj);
151
152
- set_misa(env, MXL_RV32, RVI | RVM | RVC | RVU);
153
+ riscv_cpu_set_misa(env, MXL_RV32, RVI | RVM | RVC | RVU);
154
env->priv_ver = PRIV_VERSION_1_11_0;
155
#ifndef CONFIG_USER_ONLY
156
set_satp_mode_max_supported(cpu, VM_1_10_MBARE);
157
@@ -XXX,XX +XXX,XX @@ static void rv32_imafcu_nommu_cpu_init(Object *obj)
158
CPURISCVState *env = &RISCV_CPU(obj)->env;
159
RISCVCPU *cpu = RISCV_CPU(obj);
160
161
- set_misa(env, MXL_RV32, RVI | RVM | RVA | RVF | RVC | RVU);
162
+ riscv_cpu_set_misa(env, MXL_RV32, RVI | RVM | RVA | RVF | RVC | RVU);
163
env->priv_ver = PRIV_VERSION_1_10_0;
164
#ifndef CONFIG_USER_ONLY
165
set_satp_mode_max_supported(cpu, VM_1_10_MBARE);
166
@@ -XXX,XX +XXX,XX @@ static void riscv_init_max_cpu_extensions(Object *obj)
167
const RISCVCPUMultiExtConfig *prop;
168
169
/* Enable RVG, RVJ and RVV that are disabled by default */
170
- set_misa(env, env->misa_mxl, env->misa_ext | RVG | RVJ | RVV);
171
+ riscv_cpu_set_misa(env, env->misa_mxl, env->misa_ext | RVG | RVJ | RVV);
172
173
for (prop = riscv_cpu_extensions; prop && prop->name; prop++) {
174
isa_ext_update_enabled(cpu, prop->offset, true);
175
--
176
2.41.0
177
178
diff view generated by jsdifflib
New patch
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
2
3
tcg_cpu_instance_init() will be the 'cpu_instance_init' impl for the TCG
4
accelerator. It'll be called from within riscv_cpu_post_init(), via
5
accel_cpu_instance_init(), similar to what happens with KVM. In fact, to
6
preserve behavior, the implementation will be similar to what
7
riscv_cpu_post_init() already does.
8
9
In this patch we'll move riscv_cpu_add_user_properties() and
10
riscv_init_max_cpu_extensions() and all their dependencies to tcg-cpu.c.
11
All multi-extension properties code was moved. The 'multi_ext_user_opts'
12
hash table was also moved to tcg-cpu.c since it's a TCG only structure,
13
meaning that we won't have to worry about initializing a TCG hash table
14
when running a KVM CPU anymore.
15
16
riscv_cpu_add_user_properties() will remain in cpu.c for now due to how
17
much code it requires to be moved at the same time. We'll do that in the
18
next patch.
19
20
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
21
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
22
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
23
Message-ID: <20230925175709.35696-16-dbarboza@ventanamicro.com>
24
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
25
---
26
target/riscv/cpu.h | 1 -
27
target/riscv/cpu.c | 150 -------------------------------------
28
target/riscv/tcg/tcg-cpu.c | 149 ++++++++++++++++++++++++++++++++++++
29
3 files changed, 149 insertions(+), 151 deletions(-)
30
31
diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
32
index XXXXXXX..XXXXXXX 100644
33
--- a/target/riscv/cpu.h
34
+++ b/target/riscv/cpu.h
35
@@ -XXX,XX +XXX,XX @@ enum riscv_pmu_event_idx {
36
37
/* used by tcg/tcg-cpu.c*/
38
void isa_ext_update_enabled(RISCVCPU *cpu, uint32_t ext_offset, bool en);
39
-bool cpu_cfg_ext_is_user_set(uint32_t ext_offset);
40
bool isa_ext_is_enabled(RISCVCPU *cpu, uint32_t ext_offset);
41
int cpu_cfg_ext_get_min_version(uint32_t ext_offset);
42
void riscv_cpu_set_misa(CPURISCVState *env, RISCVMXL mxl, uint32_t ext);
43
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
44
index XXXXXXX..XXXXXXX 100644
45
--- a/target/riscv/cpu.c
46
+++ b/target/riscv/cpu.c
47
@@ -XXX,XX +XXX,XX @@ static const struct isa_ext_data isa_edata_arr[] = {
48
ISA_EXT_DATA_ENTRY(xventanacondops, PRIV_VERSION_1_12_0, ext_XVentanaCondOps),
49
};
50
51
-/* Hash that stores user set extensions */
52
-static GHashTable *multi_ext_user_opts;
53
-
54
bool isa_ext_is_enabled(RISCVCPU *cpu, uint32_t ext_offset)
55
{
56
bool *ext_enabled = (void *)&cpu->cfg + ext_offset;
57
@@ -XXX,XX +XXX,XX @@ int cpu_cfg_ext_get_min_version(uint32_t ext_offset)
58
g_assert_not_reached();
59
}
60
61
-bool cpu_cfg_ext_is_user_set(uint32_t ext_offset)
62
-{
63
- return g_hash_table_contains(multi_ext_user_opts,
64
- GUINT_TO_POINTER(ext_offset));
65
-}
66
-
67
const char * const riscv_int_regnames[] = {
68
"x0/zero", "x1/ra", "x2/sp", "x3/gp", "x4/tp", "x5/t0", "x6/t1",
69
"x7/t2", "x8/s0", "x9/s1", "x10/a0", "x11/a1", "x12/a2", "x13/a3",
70
@@ -XXX,XX +XXX,XX @@ static const char * const riscv_intr_names[] = {
71
"reserved"
72
};
73
74
-static void riscv_cpu_add_user_properties(Object *obj);
75
-static void riscv_init_max_cpu_extensions(Object *obj);
76
-
77
const char *riscv_cpu_get_trap_name(target_ulong cause, bool async)
78
{
79
if (async) {
80
@@ -XXX,XX +XXX,XX @@ static bool riscv_cpu_is_dynamic(Object *cpu_obj)
81
return object_dynamic_cast(cpu_obj, TYPE_RISCV_DYNAMIC_CPU) != NULL;
82
}
83
84
-static bool riscv_cpu_has_max_extensions(Object *cpu_obj)
85
-{
86
- return object_dynamic_cast(cpu_obj, TYPE_RISCV_CPU_MAX) != NULL;
87
-}
88
-
89
-static bool riscv_cpu_has_user_properties(Object *cpu_obj)
90
-{
91
- if (kvm_enabled() &&
92
- object_dynamic_cast(cpu_obj, TYPE_RISCV_CPU_HOST) != NULL) {
93
- return true;
94
- }
95
-
96
- return riscv_cpu_is_dynamic(cpu_obj);
97
-}
98
-
99
static void riscv_cpu_post_init(Object *obj)
100
{
101
accel_cpu_instance_init(CPU(obj));
102
-
103
- if (tcg_enabled() && riscv_cpu_has_user_properties(obj)) {
104
- riscv_cpu_add_user_properties(obj);
105
- }
106
-
107
- if (riscv_cpu_has_max_extensions(obj)) {
108
- riscv_init_max_cpu_extensions(obj);
109
- }
110
}
111
112
static void riscv_cpu_init(Object *obj)
113
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_init(Object *obj)
114
qdev_init_gpio_in(DEVICE(obj), riscv_cpu_set_irq,
115
IRQ_LOCAL_MAX + IRQ_LOCAL_GUEST_MAX);
116
#endif /* CONFIG_USER_ONLY */
117
-
118
- multi_ext_user_opts = g_hash_table_new(NULL, g_direct_equal);
119
}
120
121
typedef struct RISCVCPUMisaExtConfig {
122
@@ -XXX,XX +XXX,XX @@ Property riscv_cpu_options[] = {
123
DEFINE_PROP_END_OF_LIST(),
124
};
125
126
-static void cpu_set_multi_ext_cfg(Object *obj, Visitor *v, const char *name,
127
- void *opaque, Error **errp)
128
-{
129
- const RISCVCPUMultiExtConfig *multi_ext_cfg = opaque;
130
- bool value;
131
-
132
- if (!visit_type_bool(v, name, &value, errp)) {
133
- return;
134
- }
135
-
136
- isa_ext_update_enabled(RISCV_CPU(obj), multi_ext_cfg->offset, value);
137
-
138
- g_hash_table_insert(multi_ext_user_opts,
139
- GUINT_TO_POINTER(multi_ext_cfg->offset),
140
- (gpointer)value);
141
-}
142
-
143
-static void cpu_get_multi_ext_cfg(Object *obj, Visitor *v, const char *name,
144
- void *opaque, Error **errp)
145
-{
146
- const RISCVCPUMultiExtConfig *multi_ext_cfg = opaque;
147
- bool value = isa_ext_is_enabled(RISCV_CPU(obj), multi_ext_cfg->offset);
148
-
149
- visit_type_bool(v, name, &value, errp);
150
-}
151
-
152
-static void cpu_add_multi_ext_prop(Object *cpu_obj,
153
- const RISCVCPUMultiExtConfig *multi_cfg)
154
-{
155
- object_property_add(cpu_obj, multi_cfg->name, "bool",
156
- cpu_get_multi_ext_cfg,
157
- cpu_set_multi_ext_cfg,
158
- NULL, (void *)multi_cfg);
159
-
160
- /*
161
- * Set def val directly instead of using
162
- * object_property_set_bool() to save the set()
163
- * callback hash for user inputs.
164
- */
165
- isa_ext_update_enabled(RISCV_CPU(cpu_obj), multi_cfg->offset,
166
- multi_cfg->enabled);
167
-}
168
-
169
-static void riscv_cpu_add_multiext_prop_array(Object *obj,
170
- const RISCVCPUMultiExtConfig *array)
171
-{
172
- const RISCVCPUMultiExtConfig *prop;
173
-
174
- g_assert(array);
175
-
176
- for (prop = array; prop && prop->name; prop++) {
177
- cpu_add_multi_ext_prop(obj, prop);
178
- }
179
-}
180
-
181
-/*
182
- * Add CPU properties with user-facing flags.
183
- *
184
- * This will overwrite existing env->misa_ext values with the
185
- * defaults set via riscv_cpu_add_misa_properties().
186
- */
187
-static void riscv_cpu_add_user_properties(Object *obj)
188
-{
189
-#ifndef CONFIG_USER_ONLY
190
- riscv_add_satp_mode_properties(obj);
191
-#endif
192
-
193
- riscv_cpu_add_misa_properties(obj);
194
-
195
- riscv_cpu_add_multiext_prop_array(obj, riscv_cpu_extensions);
196
- riscv_cpu_add_multiext_prop_array(obj, riscv_cpu_vendor_exts);
197
- riscv_cpu_add_multiext_prop_array(obj, riscv_cpu_experimental_exts);
198
-
199
- for (Property *prop = riscv_cpu_options; prop && prop->name; prop++) {
200
- qdev_property_add_static(DEVICE(obj), prop);
201
- }
202
-}
203
-
204
-/*
205
- * The 'max' type CPU will have all possible ratified
206
- * non-vendor extensions enabled.
207
- */
208
-static void riscv_init_max_cpu_extensions(Object *obj)
209
-{
210
- RISCVCPU *cpu = RISCV_CPU(obj);
211
- CPURISCVState *env = &cpu->env;
212
- const RISCVCPUMultiExtConfig *prop;
213
-
214
- /* Enable RVG, RVJ and RVV that are disabled by default */
215
- riscv_cpu_set_misa(env, env->misa_mxl, env->misa_ext | RVG | RVJ | RVV);
216
-
217
- for (prop = riscv_cpu_extensions; prop && prop->name; prop++) {
218
- isa_ext_update_enabled(cpu, prop->offset, true);
219
- }
220
-
221
- /* set vector version */
222
- env->vext_ver = VEXT_VERSION_1_00_0;
223
-
224
- /* Zfinx is not compatible with F. Disable it */
225
- isa_ext_update_enabled(cpu, CPU_CFG_OFFSET(ext_zfinx), false);
226
- isa_ext_update_enabled(cpu, CPU_CFG_OFFSET(ext_zdinx), false);
227
- isa_ext_update_enabled(cpu, CPU_CFG_OFFSET(ext_zhinx), false);
228
- isa_ext_update_enabled(cpu, CPU_CFG_OFFSET(ext_zhinxmin), false);
229
-
230
- isa_ext_update_enabled(cpu, CPU_CFG_OFFSET(ext_zce), false);
231
- isa_ext_update_enabled(cpu, CPU_CFG_OFFSET(ext_zcmp), false);
232
- isa_ext_update_enabled(cpu, CPU_CFG_OFFSET(ext_zcmt), false);
233
-
234
- if (env->misa_mxl != MXL_RV32) {
235
- isa_ext_update_enabled(cpu, CPU_CFG_OFFSET(ext_zcf), false);
236
- }
237
-}
238
-
239
static Property riscv_cpu_properties[] = {
240
DEFINE_PROP_BOOL("debug", RISCVCPU, cfg.debug, true),
241
242
diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c
243
index XXXXXXX..XXXXXXX 100644
244
--- a/target/riscv/tcg/tcg-cpu.c
245
+++ b/target/riscv/tcg/tcg-cpu.c
246
@@ -XXX,XX +XXX,XX @@
247
#include "pmu.h"
248
#include "time_helper.h"
249
#include "qapi/error.h"
250
+#include "qapi/visitor.h"
251
#include "qemu/accel.h"
252
#include "qemu/error-report.h"
253
#include "qemu/log.h"
254
@@ -XXX,XX +XXX,XX @@
255
#include "hw/core/tcg-cpu-ops.h"
256
#include "tcg/tcg.h"
257
258
+/* Hash that stores user set extensions */
259
+static GHashTable *multi_ext_user_opts;
260
+
261
+static bool cpu_cfg_ext_is_user_set(uint32_t ext_offset)
262
+{
263
+ return g_hash_table_contains(multi_ext_user_opts,
264
+ GUINT_TO_POINTER(ext_offset));
265
+}
266
+
267
static void riscv_cpu_synchronize_from_tb(CPUState *cs,
268
const TranslationBlock *tb)
269
{
270
@@ -XXX,XX +XXX,XX @@ static bool tcg_cpu_realize(CPUState *cs, Error **errp)
271
return true;
272
}
273
274
+static void cpu_set_multi_ext_cfg(Object *obj, Visitor *v, const char *name,
275
+ void *opaque, Error **errp)
276
+{
277
+ const RISCVCPUMultiExtConfig *multi_ext_cfg = opaque;
278
+ bool value;
279
+
280
+ if (!visit_type_bool(v, name, &value, errp)) {
281
+ return;
282
+ }
283
+
284
+ isa_ext_update_enabled(RISCV_CPU(obj), multi_ext_cfg->offset, value);
285
+
286
+ g_hash_table_insert(multi_ext_user_opts,
287
+ GUINT_TO_POINTER(multi_ext_cfg->offset),
288
+ (gpointer)value);
289
+}
290
+
291
+static void cpu_get_multi_ext_cfg(Object *obj, Visitor *v, const char *name,
292
+ void *opaque, Error **errp)
293
+{
294
+ const RISCVCPUMultiExtConfig *multi_ext_cfg = opaque;
295
+ bool value = isa_ext_is_enabled(RISCV_CPU(obj), multi_ext_cfg->offset);
296
+
297
+ visit_type_bool(v, name, &value, errp);
298
+}
299
+
300
+static void cpu_add_multi_ext_prop(Object *cpu_obj,
301
+ const RISCVCPUMultiExtConfig *multi_cfg)
302
+{
303
+ object_property_add(cpu_obj, multi_cfg->name, "bool",
304
+ cpu_get_multi_ext_cfg,
305
+ cpu_set_multi_ext_cfg,
306
+ NULL, (void *)multi_cfg);
307
+
308
+ /*
309
+ * Set def val directly instead of using
310
+ * object_property_set_bool() to save the set()
311
+ * callback hash for user inputs.
312
+ */
313
+ isa_ext_update_enabled(RISCV_CPU(cpu_obj), multi_cfg->offset,
314
+ multi_cfg->enabled);
315
+}
316
+
317
+static void riscv_cpu_add_multiext_prop_array(Object *obj,
318
+ const RISCVCPUMultiExtConfig *array)
319
+{
320
+ const RISCVCPUMultiExtConfig *prop;
321
+
322
+ g_assert(array);
323
+
324
+ for (prop = array; prop && prop->name; prop++) {
325
+ cpu_add_multi_ext_prop(obj, prop);
326
+ }
327
+}
328
+
329
+/*
330
+ * Add CPU properties with user-facing flags.
331
+ *
332
+ * This will overwrite existing env->misa_ext values with the
333
+ * defaults set via riscv_cpu_add_misa_properties().
334
+ */
335
+static void riscv_cpu_add_user_properties(Object *obj)
336
+{
337
+#ifndef CONFIG_USER_ONLY
338
+ riscv_add_satp_mode_properties(obj);
339
+#endif
340
+
341
+ riscv_cpu_add_misa_properties(obj);
342
+
343
+ riscv_cpu_add_multiext_prop_array(obj, riscv_cpu_extensions);
344
+ riscv_cpu_add_multiext_prop_array(obj, riscv_cpu_vendor_exts);
345
+ riscv_cpu_add_multiext_prop_array(obj, riscv_cpu_experimental_exts);
346
+
347
+ for (Property *prop = riscv_cpu_options; prop && prop->name; prop++) {
348
+ qdev_property_add_static(DEVICE(obj), prop);
349
+ }
350
+}
351
+
352
+/*
353
+ * The 'max' type CPU will have all possible ratified
354
+ * non-vendor extensions enabled.
355
+ */
356
+static void riscv_init_max_cpu_extensions(Object *obj)
357
+{
358
+ RISCVCPU *cpu = RISCV_CPU(obj);
359
+ CPURISCVState *env = &cpu->env;
360
+ const RISCVCPUMultiExtConfig *prop;
361
+
362
+ /* Enable RVG, RVJ and RVV that are disabled by default */
363
+ riscv_cpu_set_misa(env, env->misa_mxl, env->misa_ext | RVG | RVJ | RVV);
364
+
365
+ for (prop = riscv_cpu_extensions; prop && prop->name; prop++) {
366
+ isa_ext_update_enabled(cpu, prop->offset, true);
367
+ }
368
+
369
+ /* set vector version */
370
+ env->vext_ver = VEXT_VERSION_1_00_0;
371
+
372
+ /* Zfinx is not compatible with F. Disable it */
373
+ isa_ext_update_enabled(cpu, CPU_CFG_OFFSET(ext_zfinx), false);
374
+ isa_ext_update_enabled(cpu, CPU_CFG_OFFSET(ext_zdinx), false);
375
+ isa_ext_update_enabled(cpu, CPU_CFG_OFFSET(ext_zhinx), false);
376
+ isa_ext_update_enabled(cpu, CPU_CFG_OFFSET(ext_zhinxmin), false);
377
+
378
+ isa_ext_update_enabled(cpu, CPU_CFG_OFFSET(ext_zce), false);
379
+ isa_ext_update_enabled(cpu, CPU_CFG_OFFSET(ext_zcmp), false);
380
+ isa_ext_update_enabled(cpu, CPU_CFG_OFFSET(ext_zcmt), false);
381
+
382
+ if (env->misa_mxl != MXL_RV32) {
383
+ isa_ext_update_enabled(cpu, CPU_CFG_OFFSET(ext_zcf), false);
384
+ }
385
+}
386
+
387
+static bool riscv_cpu_has_max_extensions(Object *cpu_obj)
388
+{
389
+ return object_dynamic_cast(cpu_obj, TYPE_RISCV_CPU_MAX) != NULL;
390
+}
391
+
392
+static bool riscv_cpu_has_user_properties(Object *cpu_obj)
393
+{
394
+ return object_dynamic_cast(cpu_obj, TYPE_RISCV_DYNAMIC_CPU) != NULL;
395
+}
396
+
397
+static void tcg_cpu_instance_init(CPUState *cs)
398
+{
399
+ RISCVCPU *cpu = RISCV_CPU(cs);
400
+ Object *obj = OBJECT(cpu);
401
+
402
+ if (riscv_cpu_has_user_properties(obj)) {
403
+ multi_ext_user_opts = g_hash_table_new(NULL, g_direct_equal);
404
+ riscv_cpu_add_user_properties(obj);
405
+ }
406
+
407
+ if (riscv_cpu_has_max_extensions(obj)) {
408
+ riscv_init_max_cpu_extensions(obj);
409
+ }
410
+}
411
+
412
static void tcg_cpu_init_ops(AccelCPUClass *accel_cpu, CPUClass *cc)
413
{
414
/*
415
@@ -XXX,XX +XXX,XX @@ static void tcg_cpu_accel_class_init(ObjectClass *oc, void *data)
416
AccelCPUClass *acc = ACCEL_CPU_CLASS(oc);
417
418
acc->cpu_class_init = tcg_cpu_class_init;
419
+ acc->cpu_instance_init = tcg_cpu_instance_init;
420
acc->cpu_target_realize = tcg_cpu_realize;
421
}
422
423
--
424
2.41.0
diff view generated by jsdifflib
New patch
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
2
3
The array isn't marked as 'const' because we're initializing their
4
elements in riscv_cpu_add_misa_properties(), 'name' and 'description'
5
fields.
6
7
In a closer look we can see that we're not using these 2 fields after
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>
18
Message-ID: <20230925175709.35696-17-dbarboza@ventanamicro.com>
19
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
20
---
21
target/riscv/cpu.c | 21 ++++++++-------------
22
1 file changed, 8 insertions(+), 13 deletions(-)
23
24
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
25
index XXXXXXX..XXXXXXX 100644
26
--- a/target/riscv/cpu.c
27
+++ b/target/riscv/cpu.c
28
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_init(Object *obj)
29
}
30
31
typedef struct RISCVCPUMisaExtConfig {
32
- const char *name;
33
- const char *description;
34
target_ulong misa_bit;
35
bool enabled;
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
}
77
}
78
79
--
80
2.41.0
diff view generated by jsdifflib
New patch
1
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
2
3
All code related to MISA TCG properties is also moved.
4
5
At this point, all TCG properties handling is done in tcg-cpu.c, all KVM
6
properties handling is done in kvm-cpu.c.
7
8
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
9
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
10
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
11
Message-ID: <20230925175709.35696-18-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 | 90 --------------------------------------
16
target/riscv/tcg/tcg-cpu.c | 90 ++++++++++++++++++++++++++++++++++++++
17
3 files changed, 90 insertions(+), 91 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_vendor_exts[];
24
extern const RISCVCPUMultiExtConfig riscv_cpu_experimental_exts[];
25
extern Property riscv_cpu_options[];
26
27
-void riscv_cpu_add_misa_properties(Object *cpu_obj);
28
void riscv_add_satp_mode_properties(Object *obj);
29
30
/* CSR function table */
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_init(Object *obj)
36
#endif /* CONFIG_USER_ONLY */
37
}
38
39
-typedef struct RISCVCPUMisaExtConfig {
40
- target_ulong misa_bit;
41
- bool enabled;
42
-} RISCVCPUMisaExtConfig;
43
-
44
-static void cpu_set_misa_ext_cfg(Object *obj, Visitor *v, const char *name,
45
- void *opaque, Error **errp)
46
-{
47
- const RISCVCPUMisaExtConfig *misa_ext_cfg = opaque;
48
- target_ulong misa_bit = misa_ext_cfg->misa_bit;
49
- RISCVCPU *cpu = RISCV_CPU(obj);
50
- CPURISCVState *env = &cpu->env;
51
- bool value;
52
-
53
- if (!visit_type_bool(v, name, &value, errp)) {
54
- return;
55
- }
56
-
57
- if (value) {
58
- env->misa_ext |= misa_bit;
59
- env->misa_ext_mask |= misa_bit;
60
- } else {
61
- env->misa_ext &= ~misa_bit;
62
- env->misa_ext_mask &= ~misa_bit;
63
- }
64
-}
65
-
66
-static void cpu_get_misa_ext_cfg(Object *obj, Visitor *v, const char *name,
67
- void *opaque, Error **errp)
68
-{
69
- const RISCVCPUMisaExtConfig *misa_ext_cfg = opaque;
70
- target_ulong misa_bit = misa_ext_cfg->misa_bit;
71
- RISCVCPU *cpu = RISCV_CPU(obj);
72
- CPURISCVState *env = &cpu->env;
73
- bool value;
74
-
75
- value = env->misa_ext & misa_bit;
76
-
77
- visit_type_bool(v, name, &value, errp);
78
-}
79
-
80
typedef struct misa_ext_info {
81
const char *name;
82
const char *description;
83
@@ -XXX,XX +XXX,XX @@ const char *riscv_get_misa_ext_description(uint32_t bit)
84
return val;
85
}
86
87
-#define MISA_CFG(_bit, _enabled) \
88
- {.misa_bit = _bit, .enabled = _enabled}
89
-
90
-static const RISCVCPUMisaExtConfig misa_ext_cfgs[] = {
91
- MISA_CFG(RVA, true),
92
- MISA_CFG(RVC, true),
93
- MISA_CFG(RVD, true),
94
- MISA_CFG(RVF, true),
95
- MISA_CFG(RVI, true),
96
- MISA_CFG(RVE, false),
97
- MISA_CFG(RVM, true),
98
- MISA_CFG(RVS, true),
99
- MISA_CFG(RVU, true),
100
- MISA_CFG(RVH, true),
101
- MISA_CFG(RVJ, false),
102
- MISA_CFG(RVV, false),
103
- MISA_CFG(RVG, false),
104
-};
105
-
106
-/*
107
- * We do not support user choice tracking for MISA
108
- * extensions yet because, so far, we do not silently
109
- * change MISA bits during realize() (RVG enables MISA
110
- * bits but the user is warned about it).
111
- */
112
-void riscv_cpu_add_misa_properties(Object *cpu_obj)
113
-{
114
- int i;
115
-
116
- for (i = 0; i < ARRAY_SIZE(misa_ext_cfgs); i++) {
117
- const RISCVCPUMisaExtConfig *misa_cfg = &misa_ext_cfgs[i];
118
- int bit = misa_cfg->misa_bit;
119
- const char *name = riscv_get_misa_ext_name(bit);
120
- const char *desc = riscv_get_misa_ext_description(bit);
121
-
122
- /* Check if KVM already created the property */
123
- if (object_property_find(cpu_obj, name)) {
124
- continue;
125
- }
126
-
127
- object_property_add(cpu_obj, name, "bool",
128
- cpu_get_misa_ext_cfg,
129
- cpu_set_misa_ext_cfg,
130
- NULL, (void *)misa_cfg);
131
- object_property_set_description(cpu_obj, name, desc);
132
- object_property_set_bool(cpu_obj, name, misa_cfg->enabled, NULL);
133
- }
134
-}
135
-
136
#define MULTI_EXT_CFG_BOOL(_name, _prop, _defval) \
137
{.name = _name, .offset = CPU_CFG_OFFSET(_prop), \
138
.enabled = _defval}
139
diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c
140
index XXXXXXX..XXXXXXX 100644
141
--- a/target/riscv/tcg/tcg-cpu.c
142
+++ b/target/riscv/tcg/tcg-cpu.c
143
@@ -XXX,XX +XXX,XX @@ static bool tcg_cpu_realize(CPUState *cs, Error **errp)
144
return true;
145
}
146
147
+typedef struct RISCVCPUMisaExtConfig {
148
+ target_ulong misa_bit;
149
+ bool enabled;
150
+} RISCVCPUMisaExtConfig;
151
+
152
+static void cpu_set_misa_ext_cfg(Object *obj, Visitor *v, const char *name,
153
+ void *opaque, Error **errp)
154
+{
155
+ const RISCVCPUMisaExtConfig *misa_ext_cfg = opaque;
156
+ target_ulong misa_bit = misa_ext_cfg->misa_bit;
157
+ RISCVCPU *cpu = RISCV_CPU(obj);
158
+ CPURISCVState *env = &cpu->env;
159
+ bool value;
160
+
161
+ if (!visit_type_bool(v, name, &value, errp)) {
162
+ return;
163
+ }
164
+
165
+ if (value) {
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
+}
173
+
174
+static void cpu_get_misa_ext_cfg(Object *obj, Visitor *v, const char *name,
175
+ void *opaque, Error **errp)
176
+{
177
+ const RISCVCPUMisaExtConfig *misa_ext_cfg = opaque;
178
+ target_ulong misa_bit = misa_ext_cfg->misa_bit;
179
+ RISCVCPU *cpu = RISCV_CPU(obj);
180
+ CPURISCVState *env = &cpu->env;
181
+ bool value;
182
+
183
+ value = env->misa_ext & misa_bit;
184
+
185
+ visit_type_bool(v, name, &value, errp);
186
+}
187
+
188
+#define MISA_CFG(_bit, _enabled) \
189
+ {.misa_bit = _bit, .enabled = _enabled}
190
+
191
+static const RISCVCPUMisaExtConfig misa_ext_cfgs[] = {
192
+ MISA_CFG(RVA, true),
193
+ MISA_CFG(RVC, true),
194
+ MISA_CFG(RVD, true),
195
+ MISA_CFG(RVF, true),
196
+ MISA_CFG(RVI, true),
197
+ MISA_CFG(RVE, false),
198
+ MISA_CFG(RVM, true),
199
+ MISA_CFG(RVS, true),
200
+ MISA_CFG(RVU, true),
201
+ MISA_CFG(RVH, true),
202
+ MISA_CFG(RVJ, false),
203
+ MISA_CFG(RVV, false),
204
+ MISA_CFG(RVG, false),
205
+};
206
+
207
+/*
208
+ * We do not support user choice tracking for MISA
209
+ * extensions yet because, so far, we do not silently
210
+ * change MISA bits during realize() (RVG enables MISA
211
+ * bits but the user is warned about it).
212
+ */
213
+static void riscv_cpu_add_misa_properties(Object *cpu_obj)
214
+{
215
+ int i;
216
+
217
+ for (i = 0; i < ARRAY_SIZE(misa_ext_cfgs); i++) {
218
+ const RISCVCPUMisaExtConfig *misa_cfg = &misa_ext_cfgs[i];
219
+ int bit = misa_cfg->misa_bit;
220
+ const char *name = riscv_get_misa_ext_name(bit);
221
+ const char *desc = riscv_get_misa_ext_description(bit);
222
+
223
+ /* Check if KVM already created the property */
224
+ if (object_property_find(cpu_obj, name)) {
225
+ continue;
226
+ }
227
+
228
+ object_property_add(cpu_obj, name, "bool",
229
+ cpu_get_misa_ext_cfg,
230
+ cpu_set_misa_ext_cfg,
231
+ NULL, (void *)misa_cfg);
232
+ object_property_set_description(cpu_obj, name, desc);
233
+ object_property_set_bool(cpu_obj, name, misa_cfg->enabled, NULL);
234
+ }
235
+}
236
+
237
static void cpu_set_multi_ext_cfg(Object *obj, Visitor *v, const char *name,
238
void *opaque, Error **errp)
239
{
240
--
241
2.41.0
diff view generated by jsdifflib
New patch
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
2
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
1
From: Philippe Mathieu-Daudé <f4bug@amsat.org>
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
2
2
3
Once a "One Time Programmable" is programmed, it shouldn't be reset.
3
Priv spec validation is TCG specific. Move it to the TCG accel class.
4
4
5
Do not re-initialize the OTP content in the DeviceReset handler,
5
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
6
initialize it once in the DeviceRealize one.
6
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
7
8
Fixes: 9fb45c62ae8 ("riscv: sifive: Implement a model for SiFive FU540 OTP")
9
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
10
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
7
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
11
Message-Id: <20211119104757.331579-1-f4bug@amsat.org>
8
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
9
Message-ID: <20230925175709.35696-20-dbarboza@ventanamicro.com>
12
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
10
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
13
---
11
---
14
hw/misc/sifive_u_otp.c | 13 +++++--------
12
target/riscv/cpu.h | 2 --
15
1 file changed, 5 insertions(+), 8 deletions(-)
13
target/riscv/cpu.c | 38 --------------------------------------
14
target/riscv/tcg/tcg-cpu.c | 38 ++++++++++++++++++++++++++++++++++++++
15
3 files changed, 38 insertions(+), 40 deletions(-)
16
16
17
diff --git a/hw/misc/sifive_u_otp.c b/hw/misc/sifive_u_otp.c
17
diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
18
index XXXXXXX..XXXXXXX 100644
18
index XXXXXXX..XXXXXXX 100644
19
--- a/hw/misc/sifive_u_otp.c
19
--- a/target/riscv/cpu.h
20
+++ b/hw/misc/sifive_u_otp.c
20
+++ b/target/riscv/cpu.h
21
@@ -XXX,XX +XXX,XX @@ static void sifive_u_otp_realize(DeviceState *dev, Error **errp)
21
@@ -XXX,XX +XXX,XX @@ enum riscv_pmu_event_idx {
22
22
/* used by tcg/tcg-cpu.c*/
23
if (blk_pread(s->blk, 0, s->fuse, filesize) != filesize) {
23
void isa_ext_update_enabled(RISCVCPU *cpu, uint32_t ext_offset, bool en);
24
error_setg(errp, "failed to read the initial flash content");
24
bool isa_ext_is_enabled(RISCVCPU *cpu, uint32_t ext_offset);
25
+ return;
25
-int cpu_cfg_ext_get_min_version(uint32_t ext_offset);
26
}
26
void riscv_cpu_set_misa(CPURISCVState *env, RISCVMXL mxl, uint32_t ext);
27
}
27
-void riscv_cpu_disable_priv_spec_isa_exts(RISCVCPU *cpu);
28
}
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();
29
-}
52
-}
30
-
53
-
31
-static void sifive_u_otp_reset(DeviceState *dev)
54
const char * const riscv_int_regnames[] = {
55
"x0/zero", "x1/ra", "x2/sp", "x3/gp", "x4/tp", "x5/t0", "x6/t1",
56
"x7/t2", "x8/s0", "x9/s1", "x10/a0", "x11/a1", "x12/a2", "x13/a3",
57
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_disas_set_info(CPUState *s, disassemble_info *info)
58
}
59
}
60
61
-void riscv_cpu_disable_priv_spec_isa_exts(RISCVCPU *cpu)
32
-{
62
-{
33
- SiFiveUOTPState *s = SIFIVE_U_OTP(dev);
63
- CPURISCVState *env = &cpu->env;
34
64
- const RISCVIsaExtData *edata;
35
/* Initialize all fuses' initial value to 0xFFs */
65
-
36
memset(s->fuse, 0xff, sizeof(s->fuse));
66
- /* Force disable extensions if priv spec version does not match */
37
@@ -XXX,XX +XXX,XX @@ static void sifive_u_otp_reset(DeviceState *dev)
67
- for (edata = isa_edata_arr; edata && edata->name; edata++) {
38
serial_data = s->serial;
68
- if (isa_ext_is_enabled(cpu, edata->ext_enable_offset) &&
39
if (blk_pwrite(s->blk, index * SIFIVE_U_OTP_FUSE_WORD,
69
- (env->priv_ver < edata->min_version)) {
40
&serial_data, SIFIVE_U_OTP_FUSE_WORD, 0) < 0) {
70
- isa_ext_update_enabled(cpu, edata->ext_enable_offset, false);
41
- error_report("write error index<%d>", index);
71
-#ifndef CONFIG_USER_ONLY
42
+ error_setg(errp, "failed to write index<%d>", index);
72
- warn_report("disabling %s extension for hart 0x" TARGET_FMT_lx
43
+ return;
73
- " because privilege spec version does not match",
44
}
74
- edata->name, env->mhartid);
45
75
-#else
46
serial_data = ~(s->serial);
76
- warn_report("disabling %s extension because "
47
if (blk_pwrite(s->blk, (index + 1) * SIFIVE_U_OTP_FUSE_WORD,
77
- "privilege spec version does not match",
48
&serial_data, SIFIVE_U_OTP_FUSE_WORD, 0) < 0) {
78
- edata->name);
49
- error_report("write error index<%d>", index + 1);
79
-#endif
50
+ error_setg(errp, "failed to write index<%d>", index + 1);
80
- }
51
+ return;
81
- }
52
}
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
+{
97
+ const RISCVIsaExtData *edata;
98
+
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
+ }
106
+
107
+ g_assert_not_reached();
108
+}
109
+
110
static void cpu_cfg_ext_auto_update(RISCVCPU *cpu, uint32_t ext_offset,
111
bool value)
112
{
113
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_validate_v(CPURISCVState *env, RISCVCPUConfig *cfg,
53
}
114
}
54
55
@@ -XXX,XX +XXX,XX @@ static void sifive_u_otp_class_init(ObjectClass *klass, void *data)
56
57
device_class_set_props(dc, sifive_u_otp_properties);
58
dc->realize = sifive_u_otp_realize;
59
- dc->reset = sifive_u_otp_reset;
60
}
115
}
61
116
62
static const TypeInfo sifive_u_otp_info = {
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
+ }
138
+}
139
+
140
/*
141
* Check consistency between chosen extensions while setting
142
* cpu->cfg accordingly.
63
--
143
--
64
2.31.1
144
2.41.0
65
145
66
146
diff view generated by jsdifflib
New patch
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
2
3
We'll introduce generic errors that will output a CPU type name via its
4
RISCVCPU pointer. Create a helper for that.
5
6
Use the helper in tcg_cpu_realizefn() instead of hardcoding the 'host'
7
CPU name.
8
9
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
10
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
11
Message-ID: <20230926183109.165878-2-dbarboza@ventanamicro.com>
12
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
13
---
14
target/riscv/cpu.h | 1 +
15
target/riscv/cpu.c | 11 +++++++++++
16
target/riscv/tcg/tcg-cpu.c | 4 +++-
17
3 files changed, 15 insertions(+), 1 deletion(-)
18
19
diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
20
index XXXXXXX..XXXXXXX 100644
21
--- a/target/riscv/cpu.h
22
+++ b/target/riscv/cpu.h
23
@@ -XXX,XX +XXX,XX @@ typedef struct isa_ext_data {
24
int ext_enable_offset;
25
} RISCVIsaExtData;
26
extern const RISCVIsaExtData isa_edata_arr[];
27
+char *riscv_cpu_get_name(RISCVCPU *cpu);
28
29
void riscv_add_satp_mode_properties(Object *obj);
30
31
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
32
index XXXXXXX..XXXXXXX 100644
33
--- a/target/riscv/cpu.c
34
+++ b/target/riscv/cpu.c
35
@@ -XXX,XX +XXX,XX @@ static ObjectClass *riscv_cpu_class_by_name(const char *cpu_model)
36
return oc;
37
}
38
39
+char *riscv_cpu_get_name(RISCVCPU *cpu)
40
+{
41
+ RISCVCPUClass *rcc = RISCV_CPU_GET_CLASS(cpu);
42
+ const char *typename = object_class_get_name(OBJECT_CLASS(rcc));
43
+
44
+ g_assert(g_str_has_suffix(typename, RISCV_CPU_TYPE_SUFFIX));
45
+
46
+ return g_strndup(typename,
47
+ strlen(typename) - strlen(RISCV_CPU_TYPE_SUFFIX));
48
+}
49
+
50
static void riscv_cpu_dump_state(CPUState *cs, FILE *f, int flags)
51
{
52
RISCVCPU *cpu = RISCV_CPU(cs);
53
diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c
54
index XXXXXXX..XXXXXXX 100644
55
--- a/target/riscv/tcg/tcg-cpu.c
56
+++ b/target/riscv/tcg/tcg-cpu.c
57
@@ -XXX,XX +XXX,XX @@ static bool tcg_cpu_realize(CPUState *cs, Error **errp)
58
Error *local_err = NULL;
59
60
if (object_dynamic_cast(OBJECT(cpu), TYPE_RISCV_CPU_HOST)) {
61
- error_setg(errp, "'host' CPU is not compatible with TCG acceleration");
62
+ g_autofree char *name = riscv_cpu_get_name(cpu);
63
+ error_setg(errp, "'%s' CPU is not compatible with TCG acceleration",
64
+ name);
65
return false;
66
}
67
68
--
69
2.41.0
diff view generated by jsdifflib
New patch
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
2
3
At this moment we do not expose extension properties for vendor CPUs
4
because that would allow users to change them via command line. The
5
drawback is that if we were to add an API that shows all CPU properties,
6
e.g. qmp-query-cpu-model-expansion, we won't be able to show extensions
7
state of vendor CPUs.
8
9
We have the required machinery to create extension properties for vendor
10
CPUs while not allowing users to enable extensions. Disabling existing
11
extensions is allowed since it can be useful for debugging.
12
13
Change the set() callback cpu_set_multi_ext_cfg() to allow enabling
14
extensions only for generic CPUs. In cpu_add_multi_ext_prop() let's not
15
set the default values for the properties if we're not dealing with
16
generic CPUs, otherwise the values set in cpu_init() of vendor CPUs will
17
be overwritten. And finally, in tcg_cpu_instance_init(), add cpu user
18
properties for all CPUs.
19
20
For the veyron-v1 CPU, we're now able to disable existing extensions
21
like smstateen:
22
23
$ ./build/qemu-system-riscv64 --nographic -M virt \
24
-cpu veyron-v1,smstateen=false
25
26
But setting extensions that the CPU didn't set during cpu_init(), like
27
V, is not allowed:
28
29
$ ./build/qemu-system-riscv64 --nographic -M virt \
30
-cpu veyron-v1,v=true
31
qemu-system-riscv64: can't apply global veyron-v1-riscv-cpu.v=true:
32
'veyron-v1' CPU does not allow enabling extensions
33
34
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
35
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
36
Message-ID: <20230926183109.165878-3-dbarboza@ventanamicro.com>
37
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
38
---
39
target/riscv/tcg/tcg-cpu.c | 64 +++++++++++++++++++++++++++++---------
40
1 file changed, 50 insertions(+), 14 deletions(-)
41
42
diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c
43
index XXXXXXX..XXXXXXX 100644
44
--- a/target/riscv/tcg/tcg-cpu.c
45
+++ b/target/riscv/tcg/tcg-cpu.c
46
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp)
47
riscv_cpu_disable_priv_spec_isa_exts(cpu);
48
}
49
50
+static bool riscv_cpu_is_generic(Object *cpu_obj)
51
+{
52
+ return object_dynamic_cast(cpu_obj, TYPE_RISCV_DYNAMIC_CPU) != NULL;
53
+}
54
+
55
/*
56
* We'll get here via the following path:
57
*
58
@@ -XXX,XX +XXX,XX @@ static void cpu_set_misa_ext_cfg(Object *obj, Visitor *v, const char *name,
59
target_ulong misa_bit = misa_ext_cfg->misa_bit;
60
RISCVCPU *cpu = RISCV_CPU(obj);
61
CPURISCVState *env = &cpu->env;
62
- bool value;
63
+ bool generic_cpu = riscv_cpu_is_generic(obj);
64
+ bool prev_val, value;
65
66
if (!visit_type_bool(v, name, &value, errp)) {
67
return;
68
}
69
70
+ prev_val = env->misa_ext & misa_bit;
71
+
72
+ if (value == prev_val) {
73
+ return;
74
+ }
75
+
76
if (value) {
77
+ if (!generic_cpu) {
78
+ g_autofree char *cpuname = riscv_cpu_get_name(cpu);
79
+ error_setg(errp, "'%s' CPU does not allow enabling extensions",
80
+ cpuname);
81
+ return;
82
+ }
83
+
84
env->misa_ext |= misa_bit;
85
env->misa_ext_mask |= misa_bit;
86
} else {
87
@@ -XXX,XX +XXX,XX @@ static const RISCVCPUMisaExtConfig misa_ext_cfgs[] = {
88
*/
89
static void riscv_cpu_add_misa_properties(Object *cpu_obj)
90
{
91
+ bool use_def_vals = riscv_cpu_is_generic(cpu_obj);
92
int i;
93
94
for (i = 0; i < ARRAY_SIZE(misa_ext_cfgs); i++) {
95
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_add_misa_properties(Object *cpu_obj)
96
cpu_set_misa_ext_cfg,
97
NULL, (void *)misa_cfg);
98
object_property_set_description(cpu_obj, name, desc);
99
- object_property_set_bool(cpu_obj, name, misa_cfg->enabled, NULL);
100
+ if (use_def_vals) {
101
+ object_property_set_bool(cpu_obj, name, misa_cfg->enabled, NULL);
102
+ }
103
}
104
}
105
106
@@ -XXX,XX +XXX,XX @@ static void cpu_set_multi_ext_cfg(Object *obj, Visitor *v, const char *name,
107
void *opaque, Error **errp)
108
{
109
const RISCVCPUMultiExtConfig *multi_ext_cfg = opaque;
110
- bool value;
111
+ RISCVCPU *cpu = RISCV_CPU(obj);
112
+ bool generic_cpu = riscv_cpu_is_generic(obj);
113
+ bool prev_val, value;
114
115
if (!visit_type_bool(v, name, &value, errp)) {
116
return;
117
}
118
119
- isa_ext_update_enabled(RISCV_CPU(obj), multi_ext_cfg->offset, value);
120
-
121
g_hash_table_insert(multi_ext_user_opts,
122
GUINT_TO_POINTER(multi_ext_cfg->offset),
123
(gpointer)value);
124
+
125
+ prev_val = isa_ext_is_enabled(cpu, multi_ext_cfg->offset);
126
+
127
+ if (value == prev_val) {
128
+ return;
129
+ }
130
+
131
+ if (value && !generic_cpu) {
132
+ g_autofree char *cpuname = riscv_cpu_get_name(cpu);
133
+ error_setg(errp, "'%s' CPU does not allow enabling extensions",
134
+ cpuname);
135
+ return;
136
+ }
137
+
138
+ isa_ext_update_enabled(cpu, multi_ext_cfg->offset, value);
139
}
140
141
static void cpu_get_multi_ext_cfg(Object *obj, Visitor *v, const char *name,
142
@@ -XXX,XX +XXX,XX @@ static void cpu_get_multi_ext_cfg(Object *obj, Visitor *v, const char *name,
143
static void cpu_add_multi_ext_prop(Object *cpu_obj,
144
const RISCVCPUMultiExtConfig *multi_cfg)
145
{
146
+ bool generic_cpu = riscv_cpu_is_generic(cpu_obj);
147
+
148
object_property_add(cpu_obj, multi_cfg->name, "bool",
149
cpu_get_multi_ext_cfg,
150
cpu_set_multi_ext_cfg,
151
NULL, (void *)multi_cfg);
152
153
+ if (!generic_cpu) {
154
+ return;
155
+ }
156
+
157
/*
158
* Set def val directly instead of using
159
* object_property_set_bool() to save the set()
160
@@ -XXX,XX +XXX,XX @@ static bool riscv_cpu_has_max_extensions(Object *cpu_obj)
161
return object_dynamic_cast(cpu_obj, TYPE_RISCV_CPU_MAX) != NULL;
162
}
163
164
-static bool riscv_cpu_has_user_properties(Object *cpu_obj)
165
-{
166
- return object_dynamic_cast(cpu_obj, TYPE_RISCV_DYNAMIC_CPU) != NULL;
167
-}
168
-
169
static void tcg_cpu_instance_init(CPUState *cs)
170
{
171
RISCVCPU *cpu = RISCV_CPU(cs);
172
Object *obj = OBJECT(cpu);
173
174
- if (riscv_cpu_has_user_properties(obj)) {
175
- multi_ext_user_opts = g_hash_table_new(NULL, g_direct_equal);
176
- riscv_cpu_add_user_properties(obj);
177
- }
178
+ multi_ext_user_opts = g_hash_table_new(NULL, g_direct_equal);
179
+ riscv_cpu_add_user_properties(obj);
180
181
if (riscv_cpu_has_max_extensions(obj)) {
182
riscv_init_max_cpu_extensions(obj);
183
--
184
2.41.0
diff view generated by jsdifflib
New patch
1
From: Clément Chigot <chigot@adacore.com>
1
2
3
As of now, the exit code was either EXIT_FAILURE when a panic shutdown
4
was requested or EXIT_SUCCESS otherwise.
5
However, some hardware could want to pass more complex exit codes. Thus,
6
introduce a new shutdown request function allowing that.
7
8
Signed-off-by: Clément Chigot <chigot@adacore.com>
9
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
10
Message-ID: <20231003071427.188697-2-chigot@adacore.com>
11
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
12
---
13
include/sysemu/runstate.h | 2 ++
14
system/runstate.c | 12 +++++++++++-
15
2 files changed, 13 insertions(+), 1 deletion(-)
16
17
diff --git a/include/sysemu/runstate.h b/include/sysemu/runstate.h
18
index XXXXXXX..XXXXXXX 100644
19
--- a/include/sysemu/runstate.h
20
+++ b/include/sysemu/runstate.h
21
@@ -XXX,XX +XXX,XX @@ void qemu_system_wakeup_request(WakeupReason reason, Error **errp);
22
void qemu_system_wakeup_enable(WakeupReason reason, bool enabled);
23
void qemu_register_wakeup_notifier(Notifier *notifier);
24
void qemu_register_wakeup_support(void);
25
+void qemu_system_shutdown_request_with_code(ShutdownCause reason,
26
+ int exit_code);
27
void qemu_system_shutdown_request(ShutdownCause reason);
28
void qemu_system_powerdown_request(void);
29
void qemu_register_powerdown_notifier(Notifier *notifier);
30
diff --git a/system/runstate.c b/system/runstate.c
31
index XXXXXXX..XXXXXXX 100644
32
--- a/system/runstate.c
33
+++ b/system/runstate.c
34
@@ -XXX,XX +XXX,XX @@ void vm_state_notify(bool running, RunState state)
35
36
static ShutdownCause reset_requested;
37
static ShutdownCause shutdown_requested;
38
+static int shutdown_exit_code = EXIT_SUCCESS;
39
static int shutdown_signal;
40
static pid_t shutdown_pid;
41
static int powerdown_requested;
42
@@ -XXX,XX +XXX,XX @@ void qemu_system_killed(int signal, pid_t pid)
43
qemu_notify_event();
44
}
45
46
+void qemu_system_shutdown_request_with_code(ShutdownCause reason,
47
+ int exit_code)
48
+{
49
+ shutdown_exit_code = exit_code;
50
+ qemu_system_shutdown_request(reason);
51
+}
52
+
53
void qemu_system_shutdown_request(ShutdownCause reason)
54
{
55
trace_qemu_system_shutdown_request(reason);
56
@@ -XXX,XX +XXX,XX @@ static bool main_loop_should_exit(int *status)
57
if (shutdown_action == SHUTDOWN_ACTION_PAUSE) {
58
vm_stop(RUN_STATE_SHUTDOWN);
59
} else {
60
- if (request == SHUTDOWN_CAUSE_GUEST_PANIC &&
61
+ if (shutdown_exit_code != EXIT_SUCCESS) {
62
+ *status = shutdown_exit_code;
63
+ } else if (request == SHUTDOWN_CAUSE_GUEST_PANIC &&
64
panic_action == PANIC_ACTION_EXIT_FAILURE) {
65
*status = EXIT_FAILURE;
66
}
67
--
68
2.41.0
69
70
diff view generated by jsdifflib
New patch
1
From: Clément Chigot <chigot@adacore.com>
1
2
3
gdb_exit function aims to close gdb sessions and sends the exit code of
4
the current execution. It's being called by qemu_cleanup once the main
5
loop is over.
6
Until now, the exit code sent was always 0. Now that hardware can
7
shutdown this main loop with custom exit codes, these codes must be
8
transfered to gdb as well.
9
10
Signed-off-by: Clément Chigot <chigot@adacore.com>
11
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
12
Message-ID: <20231003071427.188697-3-chigot@adacore.com>
13
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
14
---
15
include/sysemu/sysemu.h | 2 +-
16
system/main.c | 2 +-
17
system/runstate.c | 4 ++--
18
3 files changed, 4 insertions(+), 4 deletions(-)
19
20
diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h
21
index XXXXXXX..XXXXXXX 100644
22
--- a/include/sysemu/sysemu.h
23
+++ b/include/sysemu/sysemu.h
24
@@ -XXX,XX +XXX,XX @@ bool defaults_enabled(void);
25
26
void qemu_init(int argc, char **argv);
27
int qemu_main_loop(void);
28
-void qemu_cleanup(void);
29
+void qemu_cleanup(int);
30
31
extern QemuOptsList qemu_legacy_drive_opts;
32
extern QemuOptsList qemu_common_drive_opts;
33
diff --git a/system/main.c b/system/main.c
34
index XXXXXXX..XXXXXXX 100644
35
--- a/system/main.c
36
+++ b/system/main.c
37
@@ -XXX,XX +XXX,XX @@ int qemu_default_main(void)
38
int status;
39
40
status = qemu_main_loop();
41
- qemu_cleanup();
42
+ qemu_cleanup(status);
43
44
return status;
45
}
46
diff --git a/system/runstate.c b/system/runstate.c
47
index XXXXXXX..XXXXXXX 100644
48
--- a/system/runstate.c
49
+++ b/system/runstate.c
50
@@ -XXX,XX +XXX,XX @@ void qemu_init_subsystems(void)
51
}
52
53
54
-void qemu_cleanup(void)
55
+void qemu_cleanup(int status)
56
{
57
- gdb_exit(0);
58
+ gdb_exit(status);
59
60
/*
61
* cleaning up the migration object cancels any existing migration
62
--
63
2.41.0
64
65
diff view generated by jsdifflib
New patch
1
From: Clément Chigot <chigot@adacore.com>
1
2
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
New patch
1
From: Clément Chigot <chigot@adacore.com>
1
2
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
New patch
1
From: Clément Chigot <chigot@adacore.com>
1
2
3
This replaces the exit calls by shutdown requests, ensuring a proper
4
cleanup of Qemu. Features like net/vhost-vdpa.c are expecting
5
qemu_cleanup to be called to remove their last residuals.
6
7
Signed-off-by: Clément Chigot <chigot@adacore.com>
8
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
9
Message-ID: <20231003071427.188697-6-chigot@adacore.com>
10
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
11
---
12
include/gdbstub/syscalls.h | 9 +++++++++
13
gdbstub/gdbstub.c | 5 +++--
14
gdbstub/system.c | 6 ++++++
15
gdbstub/user.c | 6 ++++++
16
4 files changed, 24 insertions(+), 2 deletions(-)
17
18
diff --git a/include/gdbstub/syscalls.h b/include/gdbstub/syscalls.h
19
index XXXXXXX..XXXXXXX 100644
20
--- a/include/gdbstub/syscalls.h
21
+++ b/include/gdbstub/syscalls.h
22
@@ -XXX,XX +XXX,XX @@ int use_gdb_syscalls(void);
23
*/
24
void gdb_exit(int code);
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
}
84
+
85
+}
86
+
87
+void gdb_qemu_exit(int code)
88
+{
89
+ exit(code);
90
}
91
92
int gdb_handlesig(CPUState *cpu, int sig)
93
--
94
2.41.0
95
96
diff view generated by jsdifflib
New patch
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
2
3
Our error message is returning the value of 'ret', which will be always
4
-1 in case of error, and will not be that useful:
5
6
qemu-system-riscv64: Unable to read ISA_EXT KVM register ssaia, error -1
7
8
Improve the error message by outputting 'errno' instead of 'ret'. Use
9
strerrorname_np() to output the error name instead of the error code.
10
This will give us what we need to know right away:
11
12
qemu-system-riscv64: Unable to read ISA_EXT KVM register ssaia, error code: ENOENT
13
14
Given that we're going to exit(1) in this condition instead of
15
attempting to recover, remove the 'kvm_riscv_destroy_scratch_vcpu()'
16
call.
17
18
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
19
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
20
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
21
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
22
Message-ID: <20231003132148.797921-2-dbarboza@ventanamicro.com>
23
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
24
---
25
target/riscv/kvm/kvm-cpu.c | 4 ++--
26
1 file changed, 2 insertions(+), 2 deletions(-)
27
28
diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c
29
index XXXXXXX..XXXXXXX 100644
30
--- a/target/riscv/kvm/kvm-cpu.c
31
+++ b/target/riscv/kvm/kvm-cpu.c
32
@@ -XXX,XX +XXX,XX @@ static void kvm_riscv_init_multiext_cfg(RISCVCPU *cpu, KVMScratchCPU *kvmcpu)
33
val = false;
34
} else {
35
error_report("Unable to read ISA_EXT KVM register %s, "
36
- "error %d", multi_ext_cfg->name, ret);
37
- kvm_riscv_destroy_scratch_vcpu(kvmcpu);
38
+ "error code: %s", multi_ext_cfg->name,
39
+ strerrorname_np(errno));
40
exit(EXIT_FAILURE);
41
}
42
} else {
43
--
44
2.41.0
45
46
diff view generated by jsdifflib
New patch
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
2
3
KVM for RISC-V started supporting KVM_GET_REG_LIST in Linux 6.6. It
4
consists of a KVM ioctl() that retrieves a list of all available regs
5
for get_one_reg/set_one_reg. Regs that aren't present in the list aren't
6
supported in the host.
7
8
This simplifies our lives when initing the KVM regs since we don't have
9
to always attempt a KVM_GET_ONE_REG for all regs QEMU knows. We'll only
10
attempt a get_one_reg() if we're sure the reg is supported, i.e. it was
11
retrieved by KVM_GET_REG_LIST. Any error in get_one_reg() will then
12
always considered fatal, instead of having to handle special error codes
13
that might indicate a non-fatal failure.
14
15
Start by moving the current kvm_riscv_init_multiext_cfg() logic into a
16
new kvm_riscv_read_multiext_legacy() helper. We'll prioritize using
17
KVM_GET_REG_LIST, so check if we have it available and, in case we
18
don't, use the legacy() logic.
19
20
Otherwise, retrieve the available reg list and use it to check if the
21
host supports our known KVM regs, doing the usual get_one_reg() for
22
the supported regs and setting cpu->cfg accordingly.
23
24
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
25
Acked-by: Alistair Francis <alistair.francis@wdc.com>
26
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
27
Message-ID: <20231003132148.797921-3-dbarboza@ventanamicro.com>
28
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
29
---
30
target/riscv/kvm/kvm-cpu.c | 96 +++++++++++++++++++++++++++++++++++++-
31
1 file changed, 95 insertions(+), 1 deletion(-)
32
33
diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c
34
index XXXXXXX..XXXXXXX 100644
35
--- a/target/riscv/kvm/kvm-cpu.c
36
+++ b/target/riscv/kvm/kvm-cpu.c
37
@@ -XXX,XX +XXX,XX @@ static void kvm_riscv_read_cbomz_blksize(RISCVCPU *cpu, KVMScratchCPU *kvmcpu,
38
}
39
}
40
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
+
56
+ if (val1 < val2) {
57
+ return -1;
58
+ }
59
+
60
+ if (val1 > val2) {
61
+ return 1;
62
+ }
63
+
64
+ return 0;
65
+}
66
+
67
+static void kvm_riscv_init_multiext_cfg(RISCVCPU *cpu, KVMScratchCPU *kvmcpu)
68
+{
69
+ KVMCPUConfig *multi_ext_cfg;
70
+ struct kvm_one_reg reg;
71
+ struct kvm_reg_list rl_struct;
72
+ struct kvm_reg_list *reglist;
73
+ uint64_t val, reg_id, *reg_search;
74
+ int i, ret;
75
+
76
+ rl_struct.n = 0;
77
+ ret = ioctl(kvmcpu->cpufd, KVM_GET_REG_LIST, &rl_struct);
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(&reglist->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(&reg_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, &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
--
148
2.41.0
diff view generated by jsdifflib
New patch
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
1
2
3
Vendor CPUs that set RVG are displaying user warnings about other
4
extensions that RVG must enable, one warning per CPU. E.g.:
5
6
$ ./build/qemu-system-riscv64 -smp 8 -M virt -cpu veyron-v1 -nographic
7
qemu-system-riscv64: warning: Setting G will also set IMAFD_Zicsr_Zifencei
8
qemu-system-riscv64: warning: Setting G will also set IMAFD_Zicsr_Zifencei
9
qemu-system-riscv64: warning: Setting G will also set IMAFD_Zicsr_Zifencei
10
qemu-system-riscv64: warning: Setting G will also set IMAFD_Zicsr_Zifencei
11
qemu-system-riscv64: warning: Setting G will also set IMAFD_Zicsr_Zifencei
12
qemu-system-riscv64: warning: Setting G will also set IMAFD_Zicsr_Zifencei
13
qemu-system-riscv64: warning: Setting G will also set IMAFD_Zicsr_Zifencei
14
qemu-system-riscv64: warning: Setting G will also set IMAFD_Zicsr_Zifencei
15
16
This happens because we decided a while ago that, for simplicity, vendor
17
CPUs could set RVG instead of setting each G extension individually in
18
their cpu_init(). Our warning isn't taking that into account, and we're
19
bugging users with a warning that we're causing ourselves.
20
21
In a closer look we conclude that this warning is not warranted in any
22
other circumstance since we're just following the ISA [1], which states
23
in chapter 24:
24
25
"One goal of the RISC-V project is that it be used as a stable software
26
development target. For this purpose, we define a combination of a base
27
ISA (RV32I or RV64I) plus selected standard extensions (IMAFD, Zicsr,
28
Zifencei) as a 'general-purpose' ISA, and we use the abbreviation G for
29
the IMAFDZicsr Zifencei combination of instruction-set extensions."
30
31
With this in mind, enabling IMAFD_Zicsr_Zifencei if the user explicitly
32
enables 'G' is an expected behavior and the warning is unneeded. Any
33
user caught by surprise should refer to the ISA.
34
35
Remove the warning when handling RVG.
36
37
[1] https://github.com/riscv/riscv-isa-manual/releases/download/Ratified-IMAFDQC/riscv-spec-20191213.pdf
38
39
Reported-by: Paul A. Clarke <pclarke@ventanamicro.com>
40
Suggested-by: Andrew Jones <ajones@ventanamicro.com>
41
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
42
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
43
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
44
Message-ID: <20231003122539.775932-1-dbarboza@ventanamicro.com>
45
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
46
---
47
target/riscv/tcg/tcg-cpu.c | 1 -
48
1 file changed, 1 deletion(-)
49
50
diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c
51
index XXXXXXX..XXXXXXX 100644
52
--- a/target/riscv/tcg/tcg-cpu.c
53
+++ b/target/riscv/tcg/tcg-cpu.c
54
@@ -XXX,XX +XXX,XX @@ void riscv_cpu_validate_set_extensions(RISCVCPU *cpu, Error **errp)
55
return;
56
}
57
58
- warn_report("Setting G will also set IMAFD_Zicsr_Zifencei");
59
cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_icsr), true);
60
cpu_cfg_ext_auto_update(cpu, CPU_CFG_OFFSET(ext_ifencei), true);
61
62
--
63
2.41.0
diff view generated by jsdifflib
New patch
1
From: "Richard W.M. Jones" <rjones@redhat.com>
1
2
3
RISCV_CPU(cs) uses a checked cast. When QOM cast debugging is enabled
4
this adds about 5% total overhead when emulating RV64 on x86-64 host.
5
6
Using a RISC-V guest with 16 vCPUs, 16 GB of guest RAM, virtio-blk
7
disk. The guest has a copy of the qemu source tree. The test
8
involves compiling the qemu source tree with 'make clean; time make -j16'.
9
10
Before making this change the compile step took 449 & 447 seconds over
11
two consecutive runs.
12
13
After making this change: 428 & 421 seconds.
14
15
The saving is over 5%.
16
17
Thanks: Paolo Bonzini
18
Thanks: Philippe Mathieu-Daudé
19
Signed-off-by: Richard W.M. Jones <rjones@redhat.com>
20
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
21
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
22
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
23
Message-ID: <20231009124859.3373696-2-rjones@redhat.com>
24
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
25
---
26
target/riscv/cpu_helper.c | 3 +--
27
1 file changed, 1 insertion(+), 2 deletions(-)
28
29
diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c
30
index XXXXXXX..XXXXXXX 100644
31
--- a/target/riscv/cpu_helper.c
32
+++ b/target/riscv/cpu_helper.c
33
@@ -XXX,XX +XXX,XX @@ int riscv_cpu_mmu_index(CPURISCVState *env, bool ifetch)
34
void cpu_get_tb_cpu_state(CPURISCVState *env, vaddr *pc,
35
uint64_t *cs_base, uint32_t *pflags)
36
{
37
- CPUState *cs = env_cpu(env);
38
- RISCVCPU *cpu = RISCV_CPU(cs);
39
+ RISCVCPU *cpu = env_archcpu(env);
40
RISCVExtStatus fs, vs;
41
uint32_t flags = 0;
42
43
--
44
2.41.0
45
46
diff view generated by jsdifflib
New patch
1
1
From: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
2
3
At this moment there are eleven CPU extension properties that starts
4
with capital 'Z': Zifencei, Zicsr, Zihintntl, Zihintpause, Zawrs, Zfa,
5
Zfh, Zfhmin, Zve32f, Zve64f and Zve64d. All other extensions are named
6
with lower-case letters.
7
8
We want all properties to be named with lower-case letters since it's
9
consistent with the riscv-isa string that we create in the FDT. Having
10
these 11 properties to be exceptions can be confusing.
11
12
Deprecate all of them. Create their lower-case counterpart to be used as
13
maintained CPU properties. When trying to use any deprecated property a
14
warning message will be displayed, recommending users to switch to the
15
lower-case variant:
16
17
./build/qemu-system-riscv64 -M virt -cpu rv64,Zifencei=true --nographic
18
qemu-system-riscv64: warning: CPU property 'Zifencei' is deprecated. Please use 'zifencei' instead
19
20
This will give users some time to change their scripts before we remove
21
the capital 'Z' properties entirely.
22
23
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
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>
28
---
29
docs/about/deprecated.rst | 23 ++++++++++++++++++++++
30
target/riscv/cpu.h | 1 +
31
target/riscv/cpu.c | 39 +++++++++++++++++++++++++++-----------
32
target/riscv/tcg/tcg-cpu.c | 31 +++++++++++++++++++++++++++++-
33
4 files changed, 82 insertions(+), 12 deletions(-)
34
35
diff --git a/docs/about/deprecated.rst b/docs/about/deprecated.rst
36
index XXXXXXX..XXXXXXX 100644
37
--- a/docs/about/deprecated.rst
38
+++ b/docs/about/deprecated.rst
39
@@ -XXX,XX +XXX,XX @@ of generic CPUs: rv32 and rv64 as default CPUs and 'max' as a feature complete
40
CPU for both 32 and 64 bit builds. Users are then discouraged to use the 'any'
41
CPU type starting in 8.2.
42
43
+RISC-V CPU properties which start with capital 'Z' (since 8.2)
44
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
45
+
46
+All RISC-V CPU properties which start with capital 'Z' are being deprecated
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
82
index XXXXXXX..XXXXXXX 100644
83
--- a/target/riscv/cpu.c
84
+++ b/target/riscv/cpu.c
85
@@ -XXX,XX +XXX,XX @@ const char *riscv_get_misa_ext_description(uint32_t bit)
86
const RISCVCPUMultiExtConfig riscv_cpu_extensions[] = {
87
/* Defaults for standard extensions */
88
MULTI_EXT_CFG_BOOL("sscofpmf", ext_sscofpmf, false),
89
- MULTI_EXT_CFG_BOOL("Zifencei", ext_ifencei, true),
90
- MULTI_EXT_CFG_BOOL("Zicsr", ext_icsr, true),
91
- MULTI_EXT_CFG_BOOL("Zihintntl", ext_zihintntl, true),
92
- MULTI_EXT_CFG_BOOL("Zihintpause", ext_zihintpause, true),
93
- MULTI_EXT_CFG_BOOL("Zawrs", ext_zawrs, true),
94
- MULTI_EXT_CFG_BOOL("Zfa", ext_zfa, true),
95
- MULTI_EXT_CFG_BOOL("Zfh", ext_zfh, false),
96
- MULTI_EXT_CFG_BOOL("Zfhmin", ext_zfhmin, false),
97
- MULTI_EXT_CFG_BOOL("Zve32f", ext_zve32f, false),
98
- MULTI_EXT_CFG_BOOL("Zve64f", ext_zve64f, false),
99
- MULTI_EXT_CFG_BOOL("Zve64d", ext_zve64d, false),
100
+ MULTI_EXT_CFG_BOOL("zifencei", ext_ifencei, true),
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
139
index XXXXXXX..XXXXXXX 100644
140
--- a/target/riscv/tcg/tcg-cpu.c
141
+++ b/target/riscv/tcg/tcg-cpu.c
142
@@ -XXX,XX +XXX,XX @@ static void riscv_cpu_add_misa_properties(Object *cpu_obj)
143
}
144
}
145
146
+static bool cpu_ext_is_deprecated(const char *ext_name)
147
+{
148
+ return isupper(ext_name[0]);
149
+}
150
+
151
+/*
152
+ * String will be allocated in the heap. Caller is responsible
153
+ * for freeing it.
154
+ */
155
+static char *cpu_ext_to_lower(const char *ext_name)
156
+{
157
+ char *ret = g_malloc0(strlen(ext_name) + 1);
158
+
159
+ strcpy(ret, ext_name);
160
+ ret[0] = tolower(ret[0]);
161
+
162
+ return ret;
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;
170
}
171
172
+ if (cpu_ext_is_deprecated(multi_ext_cfg->name)) {
173
+ g_autofree char *lower = cpu_ext_to_lower(multi_ext_cfg->name);
174
+
175
+ warn_report("CPU property '%s' is deprecated. Please use '%s' instead",
176
+ multi_ext_cfg->name, lower);
177
+ }
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;
196
}
197
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
--
208
2.41.0
diff view generated by jsdifflib
New patch
1
From: Max Chou <max.chou@sifive.com>
1
2
3
The operator (fwmacc16) of vfwmaccbf16.vf helper function should be
4
replaced by fwmaccbf16.
5
6
Fixes: adf772b0f7 ("target/riscv: Add support for Zvfbfwma extension")
7
Signed-off-by: Max Chou <max.chou@sifive.com>
8
Reviewed-by: LIU Zhiwei <zhiwei_liu@linux.alibaba.com>
9
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
10
Message-ID: <20231005095734.567575-1-max.chou@sifive.com>
11
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
12
---
13
target/riscv/vector_helper.c | 2 +-
14
1 file changed, 1 insertion(+), 1 deletion(-)
15
16
diff --git a/target/riscv/vector_helper.c b/target/riscv/vector_helper.c
17
index XXXXXXX..XXXXXXX 100644
18
--- a/target/riscv/vector_helper.c
19
+++ b/target/riscv/vector_helper.c
20
@@ -XXX,XX +XXX,XX @@ static uint32_t fwmaccbf16(uint16_t a, uint16_t b, uint32_t d, float_status *s)
21
22
RVVCALL(OPFVV3, vfwmaccbf16_vv, WOP_UUU_H, H4, H2, H2, fwmaccbf16)
23
GEN_VEXT_VV_ENV(vfwmaccbf16_vv, 4)
24
-RVVCALL(OPFVF3, vfwmaccbf16_vf, WOP_UUU_H, H4, H2, fwmacc16)
25
+RVVCALL(OPFVF3, vfwmaccbf16_vf, WOP_UUU_H, H4, H2, fwmaccbf16)
26
GEN_VEXT_VF(vfwmaccbf16_vf, 4)
27
28
static uint32_t fwnmacc16(uint16_t a, uint16_t b, uint32_t d, float_status *s)
29
--
30
2.41.0
31
32
diff view generated by jsdifflib