* [PATCH v4 00/17] target/riscv: deprecate riscv_cpu_options[]
@ 2024-01-05 23:05 Daniel Henrique Barboza
2024-01-05 23:05 ` [PATCH v4 01/17] target/riscv/cpu_cfg.h: remove unused fields Daniel Henrique Barboza
` (18 more replies)
0 siblings, 19 replies; 25+ messages in thread
From: Daniel Henrique Barboza @ 2024-01-05 23:05 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-riscv, alistair.francis, bmeng, liwei1518, zhiwei_liu,
palmer, ajones, Daniel Henrique Barboza
Hi,
This new version contains changes due to a rebase with current
riscv-to-apply.next, after "[PATCH v13 00/26] riscv: RVA22 profiles
support" was queued.
Most notable change is a new patch (12) that was added to handle
'cbop_blocksize' - zicbop was added by the profile work that just got
queued and was missing from v3.
A wrong 'cbom_blocksize' reference in patch 10 was also fixed.
Patches based on Alistair's riscv-to-apply.next.
Patches missing acks: 10, 12, 15, 16, 17
Changes from v3:
- patch 10:
- changed wrong cbom_blocksize ref to cboz_blocksize
- patch 12 (new):
- move cbop_blocksize to riscv_cpu_properties[]
- v3 link: https://lore.kernel.org/qemu-riscv/20240103174013.147279-1-dbarboza@ventanamicro.com/
Daniel Henrique Barboza (17):
target/riscv/cpu_cfg.h: remove unused fields
target/riscv: make riscv_cpu_is_vendor() public
target/riscv: move 'pmu-mask' and 'pmu-num' to riscv_cpu_properties[]
target/riscv: move 'mmu' to riscv_cpu_properties[]
target/riscv: move 'pmp' to riscv_cpu_properties[]
target/riscv: rework 'priv_spec'
target/riscv: rework 'vext_spec'
target/riscv: move 'vlen' to riscv_cpu_properties[]
target/riscv: move 'elen' to riscv_cpu_properties[]
target/riscv: create finalize_features() for KVM
target/riscv: move 'cbom_blocksize' to riscv_cpu_properties[]
target/riscv: move 'cbop_blocksize' to riscv_cpu_properties[]
target/riscv: move 'cboz_blocksize' to riscv_cpu_properties[]
target/riscv: remove riscv_cpu_options[]
target/riscv/cpu.c: move 'mvendorid' to riscv_cpu_properties[]
target/riscv/cpu.c: move 'mimpid' to riscv_cpu_properties[]
target/riscv/cpu.c: move 'marchid' to riscv_cpu_properties[]
target/riscv/cpu.c | 755 ++++++++++++++++++++++++++++-------
target/riscv/cpu.h | 8 +-
target/riscv/cpu_cfg.h | 4 -
target/riscv/kvm/kvm-cpu.c | 94 +++--
target/riscv/kvm/kvm_riscv.h | 1 +
target/riscv/tcg/tcg-cpu.c | 63 ---
6 files changed, 676 insertions(+), 249 deletions(-)
--
2.43.0
^ permalink raw reply [flat|nested] 25+ messages in thread
* [PATCH v4 01/17] target/riscv/cpu_cfg.h: remove unused fields
2024-01-05 23:05 [PATCH v4 00/17] target/riscv: deprecate riscv_cpu_options[] Daniel Henrique Barboza
@ 2024-01-05 23:05 ` Daniel Henrique Barboza
2024-01-05 23:05 ` [PATCH v4 02/17] target/riscv: make riscv_cpu_is_vendor() public Daniel Henrique Barboza
` (17 subsequent siblings)
18 siblings, 0 replies; 25+ messages in thread
From: Daniel Henrique Barboza @ 2024-01-05 23:05 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-riscv, alistair.francis, bmeng, liwei1518, zhiwei_liu,
palmer, ajones, Daniel Henrique Barboza
user_spec, bext_spec and bext_ver aren't being used.
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
---
target/riscv/cpu.h | 1 -
target/riscv/cpu_cfg.h | 2 --
2 files changed, 3 deletions(-)
diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
index 44fb0a9ca8..1c5ab8bd0e 100644
--- a/target/riscv/cpu.h
+++ b/target/riscv/cpu.h
@@ -180,7 +180,6 @@ struct CPUArchState {
target_ulong guest_phys_fault_addr;
target_ulong priv_ver;
- target_ulong bext_ver;
target_ulong vext_ver;
/* RISCVMXL, but uint32_t for vmstate migration */
diff --git a/target/riscv/cpu_cfg.h b/target/riscv/cpu_cfg.h
index 780ae6ef17..0612668144 100644
--- a/target/riscv/cpu_cfg.h
+++ b/target/riscv/cpu_cfg.h
@@ -140,8 +140,6 @@ struct RISCVCPUConfig {
uint32_t pmu_mask;
char *priv_spec;
- char *user_spec;
- char *bext_spec;
char *vext_spec;
uint16_t vlen;
uint16_t elen;
--
2.43.0
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v4 02/17] target/riscv: make riscv_cpu_is_vendor() public
2024-01-05 23:05 [PATCH v4 00/17] target/riscv: deprecate riscv_cpu_options[] Daniel Henrique Barboza
2024-01-05 23:05 ` [PATCH v4 01/17] target/riscv/cpu_cfg.h: remove unused fields Daniel Henrique Barboza
@ 2024-01-05 23:05 ` Daniel Henrique Barboza
2024-01-05 23:05 ` [PATCH v4 03/17] target/riscv: move 'pmu-mask' and 'pmu-num' to riscv_cpu_properties[] Daniel Henrique Barboza
` (16 subsequent siblings)
18 siblings, 0 replies; 25+ messages in thread
From: Daniel Henrique Barboza @ 2024-01-05 23:05 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-riscv, alistair.francis, bmeng, liwei1518, zhiwei_liu,
palmer, ajones, Daniel Henrique Barboza
We'll use this function in target/riscv/cpu.c to implement setters that
won't allow vendor CPU options to be changed.
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
---
target/riscv/cpu.c | 5 +++++
target/riscv/cpu.h | 1 +
target/riscv/tcg/tcg-cpu.c | 5 -----
3 files changed, 6 insertions(+), 5 deletions(-)
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
index cce8165d69..025c6cb23c 100644
--- a/target/riscv/cpu.c
+++ b/target/riscv/cpu.c
@@ -190,6 +190,11 @@ void isa_ext_update_enabled(RISCVCPU *cpu, uint32_t ext_offset, bool en)
*ext_enabled = en;
}
+bool riscv_cpu_is_vendor(Object *cpu_obj)
+{
+ return object_dynamic_cast(cpu_obj, TYPE_RISCV_VENDOR_CPU) != NULL;
+}
+
const char * const riscv_int_regnames[] = {
"x0/zero", "x1/ra", "x2/sp", "x3/gp", "x4/tp", "x5/t0", "x6/t1",
"x7/t2", "x8/s0", "x9/s1", "x10/a0", "x11/a1", "x12/a2", "x13/a3",
diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
index 1c5ab8bd0e..1ece80a604 100644
--- a/target/riscv/cpu.h
+++ b/target/riscv/cpu.h
@@ -773,6 +773,7 @@ enum riscv_pmu_event_idx {
void isa_ext_update_enabled(RISCVCPU *cpu, uint32_t ext_offset, bool en);
bool isa_ext_is_enabled(RISCVCPU *cpu, uint32_t ext_offset);
void riscv_cpu_set_misa(CPURISCVState *env, RISCVMXL mxl, uint32_t ext);
+bool riscv_cpu_is_vendor(Object *cpu_obj);
typedef struct RISCVCPUMultiExtConfig {
const char *name;
diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c
index 14133ff665..2c2ce51b19 100644
--- a/target/riscv/tcg/tcg-cpu.c
+++ b/target/riscv/tcg/tcg-cpu.c
@@ -917,11 +917,6 @@ static bool riscv_cpu_is_generic(Object *cpu_obj)
return object_dynamic_cast(cpu_obj, TYPE_RISCV_DYNAMIC_CPU) != NULL;
}
-static bool riscv_cpu_is_vendor(Object *cpu_obj)
-{
- return object_dynamic_cast(cpu_obj, TYPE_RISCV_VENDOR_CPU) != NULL;
-}
-
/*
* We'll get here via the following path:
*
--
2.43.0
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v4 03/17] target/riscv: move 'pmu-mask' and 'pmu-num' to riscv_cpu_properties[]
2024-01-05 23:05 [PATCH v4 00/17] target/riscv: deprecate riscv_cpu_options[] Daniel Henrique Barboza
2024-01-05 23:05 ` [PATCH v4 01/17] target/riscv/cpu_cfg.h: remove unused fields Daniel Henrique Barboza
2024-01-05 23:05 ` [PATCH v4 02/17] target/riscv: make riscv_cpu_is_vendor() public Daniel Henrique Barboza
@ 2024-01-05 23:05 ` Daniel Henrique Barboza
2024-01-05 23:05 ` [PATCH v4 04/17] target/riscv: move 'mmu' " Daniel Henrique Barboza
` (15 subsequent siblings)
18 siblings, 0 replies; 25+ messages in thread
From: Daniel Henrique Barboza @ 2024-01-05 23:05 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-riscv, alistair.francis, bmeng, liwei1518, zhiwei_liu,
palmer, ajones, Daniel Henrique Barboza
Every property in riscv_cpu_options[] will be migrated to
riscv_cpu_properties[]. This will make their default values init
earlier, allowing cpu_init() functions to overwrite them. We'll also
implement common getters and setters that both accelerators will use,
allowing them to share validations that TCG is doing.
At the same time, some options (namely 'vlen', 'elen' and the cache
blocksizes) need a way of tracking if the user set a value for them.
This is benign for TCG since the cost of always validating these values
are small, but for KVM we need syscalls to read the host values to make
the validations, thus knowing whether the user didn't touch the values
makes a difference.
We'll track user setting for these properties using a hash, like we do
in the TCG driver. All riscv cpu options will update this hash in case
the user sets it. The KVM driver will use this hash to minimize the
amount of syscalls done.
For now, both 'pmu-mask' and 'pmu-num' shouldn't be changed for vendor
CPUs. The existing setter for 'pmu-num' is changed to add this
restriction. New getters and setters are required for 'pmu-mask'
While we're at it, add a 'static' modifier to 'prop_pmu_num' since we're
not exporting it.
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
---
target/riscv/cpu.c | 91 ++++++++++++++++++++++++++++++++++++++++++----
1 file changed, 84 insertions(+), 7 deletions(-)
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
index 025c6cb23c..e5885e0dfb 100644
--- a/target/riscv/cpu.c
+++ b/target/riscv/cpu.c
@@ -58,6 +58,15 @@ bool riscv_cpu_is_32bit(RISCVCPU *cpu)
return riscv_cpu_mxl(&cpu->env) == MXL_RV32;
}
+/* Hash that stores general user set numeric options */
+static GHashTable *general_user_opts;
+
+static void cpu_option_add_user_setting(const char *optname, uint32_t value)
+{
+ g_hash_table_insert(general_user_opts, (gpointer)optname,
+ GUINT_TO_POINTER(value));
+}
+
#define ISA_EXT_DATA_ENTRY(_name, _min_ver, _prop) \
{#_name, _min_ver, CPU_CFG_OFFSET(_prop)}
@@ -1258,11 +1267,15 @@ static void riscv_cpu_post_init(Object *obj)
static void riscv_cpu_init(Object *obj)
{
+ RISCVCPU *cpu = RISCV_CPU(obj);
+
#ifndef CONFIG_USER_ONLY
qdev_init_gpio_in(DEVICE(obj), riscv_cpu_set_irq,
IRQ_LOCAL_MAX + IRQ_LOCAL_GUEST_MAX);
#endif /* CONFIG_USER_ONLY */
+ general_user_opts = g_hash_table_new(g_str_hash, g_str_equal);
+
/*
* The timer and performance counters extensions were supported
* in QEMU before they were added as discrete extensions in the
@@ -1272,6 +1285,9 @@ static void riscv_cpu_init(Object *obj)
*/
RISCV_CPU(obj)->cfg.ext_zicntr = true;
RISCV_CPU(obj)->cfg.ext_zihpm = true;
+
+ /* Default values for non-bool cpu properties */
+ cpu->cfg.pmu_mask = MAKE_64BIT_MASK(3, 16);
}
typedef struct misa_ext_info {
@@ -1480,26 +1496,46 @@ const RISCVCPUMultiExtConfig riscv_cpu_deprecated_exts[] = {
DEFINE_PROP_END_OF_LIST(),
};
+static void cpu_set_prop_err(RISCVCPU *cpu, const char *propname,
+ Error **errp)
+{
+ g_autofree char *cpuname = riscv_cpu_get_name(cpu);
+ error_setg(errp, "CPU '%s' does not allow changing the value of '%s'",
+ cpuname, propname);
+}
+
static void prop_pmu_num_set(Object *obj, Visitor *v, const char *name,
void *opaque, Error **errp)
{
RISCVCPU *cpu = RISCV_CPU(obj);
- uint8_t pmu_num;
+ uint8_t pmu_num, curr_pmu_num;
+ uint32_t pmu_mask;
visit_type_uint8(v, name, &pmu_num, errp);
+ curr_pmu_num = ctpop32(cpu->cfg.pmu_mask);
+
+ if (pmu_num != curr_pmu_num && riscv_cpu_is_vendor(obj)) {
+ cpu_set_prop_err(cpu, name, errp);
+ error_append_hint(errp, "Current '%s' val: %u\n",
+ name, curr_pmu_num);
+ return;
+ }
+
if (pmu_num > (RV_MAX_MHPMCOUNTERS - 3)) {
error_setg(errp, "Number of counters exceeds maximum available");
return;
}
if (pmu_num == 0) {
- cpu->cfg.pmu_mask = 0;
+ pmu_mask = 0;
} else {
- cpu->cfg.pmu_mask = MAKE_64BIT_MASK(3, pmu_num);
+ pmu_mask = MAKE_64BIT_MASK(3, pmu_num);
}
warn_report("\"pmu-num\" property is deprecated; use \"pmu-mask\"");
+ cpu->cfg.pmu_mask = pmu_mask;
+ cpu_option_add_user_setting("pmu-mask", pmu_mask);
}
static void prop_pmu_num_get(Object *obj, Visitor *v, const char *name,
@@ -1511,16 +1547,54 @@ static void prop_pmu_num_get(Object *obj, Visitor *v, const char *name,
visit_type_uint8(v, name, &pmu_num, errp);
}
-const PropertyInfo prop_pmu_num = {
+static const PropertyInfo prop_pmu_num = {
.name = "pmu-num",
.get = prop_pmu_num_get,
.set = prop_pmu_num_set,
};
-Property riscv_cpu_options[] = {
- DEFINE_PROP_UINT32("pmu-mask", RISCVCPU, cfg.pmu_mask, MAKE_64BIT_MASK(3, 16)),
- {.name = "pmu-num", .info = &prop_pmu_num}, /* Deprecated */
+static void prop_pmu_mask_set(Object *obj, Visitor *v, const char *name,
+ void *opaque, Error **errp)
+{
+ RISCVCPU *cpu = RISCV_CPU(obj);
+ uint32_t value;
+ uint8_t pmu_num;
+ visit_type_uint32(v, name, &value, errp);
+
+ if (value != cpu->cfg.pmu_mask && riscv_cpu_is_vendor(obj)) {
+ cpu_set_prop_err(cpu, name, errp);
+ error_append_hint(errp, "Current '%s' val: %x\n",
+ name, cpu->cfg.pmu_mask);
+ return;
+ }
+
+ pmu_num = ctpop32(value);
+
+ if (pmu_num > (RV_MAX_MHPMCOUNTERS - 3)) {
+ error_setg(errp, "Number of counters exceeds maximum available");
+ return;
+ }
+
+ cpu_option_add_user_setting(name, value);
+ cpu->cfg.pmu_mask = value;
+}
+
+static void prop_pmu_mask_get(Object *obj, Visitor *v, const char *name,
+ void *opaque, Error **errp)
+{
+ uint8_t pmu_mask = RISCV_CPU(obj)->cfg.pmu_mask;
+
+ visit_type_uint8(v, name, &pmu_mask, errp);
+}
+
+static const PropertyInfo prop_pmu_mask = {
+ .name = "pmu-mask",
+ .get = prop_pmu_mask_get,
+ .set = prop_pmu_mask_set,
+};
+
+Property riscv_cpu_options[] = {
DEFINE_PROP_BOOL("mmu", RISCVCPU, cfg.mmu, true),
DEFINE_PROP_BOOL("pmp", RISCVCPU, cfg.pmp, true),
@@ -1607,6 +1681,9 @@ RISCVCPUProfile *riscv_profiles[] = {
static Property riscv_cpu_properties[] = {
DEFINE_PROP_BOOL("debug", RISCVCPU, cfg.debug, true),
+ {.name = "pmu-mask", .info = &prop_pmu_mask},
+ {.name = "pmu-num", .info = &prop_pmu_num}, /* Deprecated */
+
#ifndef CONFIG_USER_ONLY
DEFINE_PROP_UINT64("resetvec", RISCVCPU, env.resetvec, DEFAULT_RSTVEC),
#endif
--
2.43.0
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v4 04/17] target/riscv: move 'mmu' to riscv_cpu_properties[]
2024-01-05 23:05 [PATCH v4 00/17] target/riscv: deprecate riscv_cpu_options[] Daniel Henrique Barboza
` (2 preceding siblings ...)
2024-01-05 23:05 ` [PATCH v4 03/17] target/riscv: move 'pmu-mask' and 'pmu-num' to riscv_cpu_properties[] Daniel Henrique Barboza
@ 2024-01-05 23:05 ` Daniel Henrique Barboza
2024-01-05 23:05 ` [PATCH v4 05/17] target/riscv: move 'pmp' " Daniel Henrique Barboza
` (14 subsequent siblings)
18 siblings, 0 replies; 25+ messages in thread
From: Daniel Henrique Barboza @ 2024-01-05 23:05 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-riscv, alistair.francis, bmeng, liwei1518, zhiwei_liu,
palmer, ajones, Daniel Henrique Barboza
Commit 7f0bdfb5bfc ("target/riscv/cpu.c: remove cfg setup from
riscv_cpu_init()") already did some of the work by making some
cpu_init() functions to explictly enable their own 'mmu' default.
The generic CPUs didn't get update by that commit, so they are still
relying on the defaults set by the 'mmu' option. But having 'mmu' and
'pmp' being default=true will force CPUs that doesn't implement these
options to set them to 'false' in their cpu_init(), which isn't ideal.
We'll move 'mmu' to riscv_cpu_properties[] without any defaults, i.e.
the default will be 'false'. Compensate it by manually setting 'mmu =
true' to the generic CPUs that requires it.
Implement a setter for it to forbid the 'mmu' setting to be changed for
vendor CPUs. This will allow the option to exist for all CPUs and, at
the same time, protect vendor CPUs from undesired changes:
$ ./build/qemu-system-riscv64 -M virt -cpu sifive-e51,mmu=true
qemu-system-riscv64: can't apply global sifive-e51-riscv-cpu.mmu=true:
CPU 'sifive-e51' does not allow changing the value of 'mmu'
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
---
target/riscv/cpu.c | 55 ++++++++++++++++++++++++++++++++++++++++++----
1 file changed, 51 insertions(+), 4 deletions(-)
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
index e5885e0dfb..891a3b630b 100644
--- a/target/riscv/cpu.c
+++ b/target/riscv/cpu.c
@@ -437,6 +437,8 @@ static void riscv_max_cpu_init(Object *obj)
CPURISCVState *env = &cpu->env;
RISCVMXL mlx = MXL_RV64;
+ cpu->cfg.mmu = true;
+
#ifdef TARGET_RISCV32
mlx = MXL_RV32;
#endif
@@ -451,7 +453,11 @@ static void riscv_max_cpu_init(Object *obj)
#if defined(TARGET_RISCV64)
static void rv64_base_cpu_init(Object *obj)
{
- CPURISCVState *env = &RISCV_CPU(obj)->env;
+ RISCVCPU *cpu = RISCV_CPU(obj);
+ CPURISCVState *env = &cpu->env;
+
+ cpu->cfg.mmu = true;
+
/* We set this in the realise function */
riscv_cpu_set_misa(env, MXL_RV64, 0);
/* Set latest version of privileged specification */
@@ -569,13 +575,18 @@ static void rv64_veyron_v1_cpu_init(Object *obj)
static void rv128_base_cpu_init(Object *obj)
{
+ RISCVCPU *cpu = RISCV_CPU(obj);
+ CPURISCVState *env = &cpu->env;
+
if (qemu_tcg_mttcg_enabled()) {
/* Missing 128-bit aligned atomics */
error_report("128-bit RISC-V currently does not work with Multi "
"Threaded TCG. Please use: -accel tcg,thread=single");
exit(EXIT_FAILURE);
}
- CPURISCVState *env = &RISCV_CPU(obj)->env;
+
+ cpu->cfg.mmu = true;
+
/* We set this in the realise function */
riscv_cpu_set_misa(env, MXL_RV128, 0);
/* Set latest version of privileged specification */
@@ -609,7 +620,11 @@ static void rv64i_bare_cpu_init(Object *obj)
#else
static void rv32_base_cpu_init(Object *obj)
{
- CPURISCVState *env = &RISCV_CPU(obj)->env;
+ RISCVCPU *cpu = RISCV_CPU(obj);
+ CPURISCVState *env = &cpu->env;
+
+ cpu->cfg.mmu = true;
+
/* We set this in the realise function */
riscv_cpu_set_misa(env, MXL_RV32, 0);
/* Set latest version of privileged specification */
@@ -1594,8 +1609,38 @@ static const PropertyInfo prop_pmu_mask = {
.set = prop_pmu_mask_set,
};
+static void prop_mmu_set(Object *obj, Visitor *v, const char *name,
+ void *opaque, Error **errp)
+{
+ RISCVCPU *cpu = RISCV_CPU(obj);
+ bool value;
+
+ visit_type_bool(v, name, &value, errp);
+
+ if (cpu->cfg.mmu != value && riscv_cpu_is_vendor(obj)) {
+ cpu_set_prop_err(cpu, "mmu", errp);
+ return;
+ }
+
+ cpu_option_add_user_setting(name, value);
+ cpu->cfg.mmu = value;
+}
+
+static void prop_mmu_get(Object *obj, Visitor *v, const char *name,
+ void *opaque, Error **errp)
+{
+ bool value = RISCV_CPU(obj)->cfg.mmu;
+
+ visit_type_bool(v, name, &value, errp);
+}
+
+static const PropertyInfo prop_mmu = {
+ .name = "mmu",
+ .get = prop_mmu_get,
+ .set = prop_mmu_set,
+};
+
Property riscv_cpu_options[] = {
- DEFINE_PROP_BOOL("mmu", RISCVCPU, cfg.mmu, true),
DEFINE_PROP_BOOL("pmp", RISCVCPU, cfg.pmp, true),
DEFINE_PROP_STRING("priv_spec", RISCVCPU, cfg.priv_spec),
@@ -1684,6 +1729,8 @@ static Property riscv_cpu_properties[] = {
{.name = "pmu-mask", .info = &prop_pmu_mask},
{.name = "pmu-num", .info = &prop_pmu_num}, /* Deprecated */
+ {.name = "mmu", .info = &prop_mmu},
+
#ifndef CONFIG_USER_ONLY
DEFINE_PROP_UINT64("resetvec", RISCVCPU, env.resetvec, DEFAULT_RSTVEC),
#endif
--
2.43.0
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v4 05/17] target/riscv: move 'pmp' to riscv_cpu_properties[]
2024-01-05 23:05 [PATCH v4 00/17] target/riscv: deprecate riscv_cpu_options[] Daniel Henrique Barboza
` (3 preceding siblings ...)
2024-01-05 23:05 ` [PATCH v4 04/17] target/riscv: move 'mmu' " Daniel Henrique Barboza
@ 2024-01-05 23:05 ` Daniel Henrique Barboza
2024-01-05 23:05 ` [PATCH v4 06/17] target/riscv: rework 'priv_spec' Daniel Henrique Barboza
` (13 subsequent siblings)
18 siblings, 0 replies; 25+ messages in thread
From: Daniel Henrique Barboza @ 2024-01-05 23:05 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-riscv, alistair.francis, bmeng, liwei1518, zhiwei_liu,
palmer, ajones, Daniel Henrique Barboza
Move 'pmp' to riscv_cpu_properties[], creating a new setter() for it
that forbids 'pmp' to be changed in vendor CPUs, like we did with the
'mmu' option.
We'll also have to manually set 'pmp = true' to generic CPUs that were
still relying on the previous default to set it.
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
---
target/riscv/cpu.c | 38 ++++++++++++++++++++++++++++++++++++--
1 file changed, 36 insertions(+), 2 deletions(-)
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
index 891a3b630b..df8e0b43f7 100644
--- a/target/riscv/cpu.c
+++ b/target/riscv/cpu.c
@@ -438,6 +438,7 @@ static void riscv_max_cpu_init(Object *obj)
RISCVMXL mlx = MXL_RV64;
cpu->cfg.mmu = true;
+ cpu->cfg.pmp = true;
#ifdef TARGET_RISCV32
mlx = MXL_RV32;
@@ -457,6 +458,7 @@ static void rv64_base_cpu_init(Object *obj)
CPURISCVState *env = &cpu->env;
cpu->cfg.mmu = true;
+ cpu->cfg.pmp = true;
/* We set this in the realise function */
riscv_cpu_set_misa(env, MXL_RV64, 0);
@@ -586,6 +588,7 @@ static void rv128_base_cpu_init(Object *obj)
}
cpu->cfg.mmu = true;
+ cpu->cfg.pmp = true;
/* We set this in the realise function */
riscv_cpu_set_misa(env, MXL_RV128, 0);
@@ -624,6 +627,7 @@ static void rv32_base_cpu_init(Object *obj)
CPURISCVState *env = &cpu->env;
cpu->cfg.mmu = true;
+ cpu->cfg.pmp = true;
/* We set this in the realise function */
riscv_cpu_set_misa(env, MXL_RV32, 0);
@@ -1640,9 +1644,38 @@ static const PropertyInfo prop_mmu = {
.set = prop_mmu_set,
};
-Property riscv_cpu_options[] = {
- DEFINE_PROP_BOOL("pmp", RISCVCPU, cfg.pmp, true),
+static void prop_pmp_set(Object *obj, Visitor *v, const char *name,
+ void *opaque, Error **errp)
+{
+ RISCVCPU *cpu = RISCV_CPU(obj);
+ bool value;
+
+ visit_type_bool(v, name, &value, errp);
+ if (cpu->cfg.pmp != value && riscv_cpu_is_vendor(obj)) {
+ cpu_set_prop_err(cpu, name, errp);
+ return;
+ }
+
+ cpu_option_add_user_setting(name, value);
+ cpu->cfg.pmp = value;
+}
+
+static void prop_pmp_get(Object *obj, Visitor *v, const char *name,
+ void *opaque, Error **errp)
+{
+ bool value = RISCV_CPU(obj)->cfg.pmp;
+
+ visit_type_bool(v, name, &value, errp);
+}
+
+static const PropertyInfo prop_pmp = {
+ .name = "pmp",
+ .get = prop_pmp_get,
+ .set = prop_pmp_set,
+};
+
+Property riscv_cpu_options[] = {
DEFINE_PROP_STRING("priv_spec", RISCVCPU, cfg.priv_spec),
DEFINE_PROP_STRING("vext_spec", RISCVCPU, cfg.vext_spec),
@@ -1730,6 +1763,7 @@ static Property riscv_cpu_properties[] = {
{.name = "pmu-num", .info = &prop_pmu_num}, /* Deprecated */
{.name = "mmu", .info = &prop_mmu},
+ {.name = "pmp", .info = &prop_pmp},
#ifndef CONFIG_USER_ONLY
DEFINE_PROP_UINT64("resetvec", RISCVCPU, env.resetvec, DEFAULT_RSTVEC),
--
2.43.0
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v4 06/17] target/riscv: rework 'priv_spec'
2024-01-05 23:05 [PATCH v4 00/17] target/riscv: deprecate riscv_cpu_options[] Daniel Henrique Barboza
` (4 preceding siblings ...)
2024-01-05 23:05 ` [PATCH v4 05/17] target/riscv: move 'pmp' " Daniel Henrique Barboza
@ 2024-01-05 23:05 ` Daniel Henrique Barboza
2024-01-05 23:05 ` [PATCH v4 07/17] target/riscv: rework 'vext_spec' Daniel Henrique Barboza
` (12 subsequent siblings)
18 siblings, 0 replies; 25+ messages in thread
From: Daniel Henrique Barboza @ 2024-01-05 23:05 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-riscv, alistair.francis, bmeng, liwei1518, zhiwei_liu,
palmer, ajones, Daniel Henrique Barboza
'priv_spec' and 'vext_spec' are two string options used as a fancy way
of setting integers in the CPU state (cpu->env.priv_ver and
cpu->env.vext_ver). It requires us to deal with string parsing and to
store them in cpu_cfg.
We must support these string options, but we don't need to store them.
We have a precedence for this kind of arrangement in target/ppc/compat.c,
ppc_compat_prop_get|set, getters and setters used for the
'max-cpu-compat' class property of the pseries ppc64 machine. We'll do
the same with both 'priv_spec' and 'vext_spec'.
For 'priv_spec', the validation from riscv_cpu_validate_priv_spec() will
be done by the prop_priv_spec_set() setter, while also preventing it to
be changed for vendor CPUs. Add two helpers that converts env->priv_ver
back and forth to its string representation. These helpers allow us to
get a string and set 'env->priv_ver' and return a string giving the
current env->priv_ver value. In other words, make the cpu->cfg.priv_spec
string obsolete.
Last but not the least, move the reworked 'priv_spec' option to
riscv_cpu_properties[].
After all said and done, we don't need to store the 'priv_spec' string in
the CPU state, and we're now protecting vendor CPUs from priv_ver
changes:
$ ./build/qemu-system-riscv64 -M virt -cpu sifive-e51,priv_spec="v1.12.0"
qemu-system-riscv64: can't apply global sifive-e51-riscv-cpu.priv_spec=v1.12.0:
CPU 'sifive-e51' does not allow changing the value of 'priv_spec'
Current 'priv_spec' val: v1.10.0
$
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
---
target/riscv/cpu.c | 73 +++++++++++++++++++++++++++++++++++++-
target/riscv/cpu.h | 3 ++
target/riscv/cpu_cfg.h | 1 -
target/riscv/tcg/tcg-cpu.c | 29 ---------------
4 files changed, 75 insertions(+), 31 deletions(-)
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
index df8e0b43f7..f3316c5082 100644
--- a/target/riscv/cpu.c
+++ b/target/riscv/cpu.c
@@ -1675,8 +1675,77 @@ static const PropertyInfo prop_pmp = {
.set = prop_pmp_set,
};
+static int priv_spec_from_str(const char *priv_spec_str)
+{
+ int priv_version = -1;
+
+ if (!g_strcmp0(priv_spec_str, PRIV_VER_1_12_0_STR)) {
+ priv_version = PRIV_VERSION_1_12_0;
+ } else if (!g_strcmp0(priv_spec_str, PRIV_VER_1_11_0_STR)) {
+ priv_version = PRIV_VERSION_1_11_0;
+ } else if (!g_strcmp0(priv_spec_str, PRIV_VER_1_10_0_STR)) {
+ priv_version = PRIV_VERSION_1_10_0;
+ }
+
+ return priv_version;
+}
+
+static const char *priv_spec_to_str(int priv_version)
+{
+ switch (priv_version) {
+ case PRIV_VERSION_1_10_0:
+ return PRIV_VER_1_10_0_STR;
+ case PRIV_VERSION_1_11_0:
+ return PRIV_VER_1_11_0_STR;
+ case PRIV_VERSION_1_12_0:
+ return PRIV_VER_1_12_0_STR;
+ default:
+ return NULL;
+ }
+}
+
+static void prop_priv_spec_set(Object *obj, Visitor *v, const char *name,
+ void *opaque, Error **errp)
+{
+ RISCVCPU *cpu = RISCV_CPU(obj);
+ g_autofree char *value = NULL;
+ int priv_version = -1;
+
+ visit_type_str(v, name, &value, errp);
+
+ priv_version = priv_spec_from_str(value);
+ if (priv_version < 0) {
+ error_setg(errp, "Unsupported privilege spec version '%s'", value);
+ return;
+ }
+
+ if (priv_version != cpu->env.priv_ver && riscv_cpu_is_vendor(obj)) {
+ cpu_set_prop_err(cpu, name, errp);
+ error_append_hint(errp, "Current '%s' val: %s\n", name,
+ object_property_get_str(obj, name, NULL));
+ return;
+ }
+
+ cpu_option_add_user_setting(name, priv_version);
+ cpu->env.priv_ver = priv_version;
+}
+
+static void prop_priv_spec_get(Object *obj, Visitor *v, const char *name,
+ void *opaque, Error **errp)
+{
+ RISCVCPU *cpu = RISCV_CPU(obj);
+ const char *value = priv_spec_to_str(cpu->env.priv_ver);
+
+ visit_type_str(v, name, (char **)&value, errp);
+}
+
+static const PropertyInfo prop_priv_spec = {
+ .name = "priv_spec",
+ .get = prop_priv_spec_get,
+ .set = prop_priv_spec_set,
+};
+
Property riscv_cpu_options[] = {
- DEFINE_PROP_STRING("priv_spec", RISCVCPU, cfg.priv_spec),
DEFINE_PROP_STRING("vext_spec", RISCVCPU, cfg.vext_spec),
DEFINE_PROP_UINT16("vlen", RISCVCPU, cfg.vlen, 128),
@@ -1765,6 +1834,8 @@ static Property riscv_cpu_properties[] = {
{.name = "mmu", .info = &prop_mmu},
{.name = "pmp", .info = &prop_pmp},
+ {.name = "priv_spec", .info = &prop_priv_spec},
+
#ifndef CONFIG_USER_ONLY
DEFINE_PROP_UINT64("resetvec", RISCVCPU, env.resetvec, DEFAULT_RSTVEC),
#endif
diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
index 1ece80a604..ee65ed555a 100644
--- a/target/riscv/cpu.h
+++ b/target/riscv/cpu.h
@@ -93,6 +93,9 @@ typedef struct riscv_cpu_profile {
extern RISCVCPUProfile *riscv_profiles[];
/* Privileged specification version */
+#define PRIV_VER_1_10_0_STR "v1.10.0"
+#define PRIV_VER_1_11_0_STR "v1.11.0"
+#define PRIV_VER_1_12_0_STR "v1.12.0"
enum {
PRIV_VERSION_1_10_0 = 0,
PRIV_VERSION_1_11_0,
diff --git a/target/riscv/cpu_cfg.h b/target/riscv/cpu_cfg.h
index 0612668144..68965743b6 100644
--- a/target/riscv/cpu_cfg.h
+++ b/target/riscv/cpu_cfg.h
@@ -139,7 +139,6 @@ struct RISCVCPUConfig {
bool ext_XVentanaCondOps;
uint32_t pmu_mask;
- char *priv_spec;
char *vext_spec;
uint16_t vlen;
uint16_t elen;
diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c
index 2c2ce51b19..a24c5e7e58 100644
--- a/target/riscv/tcg/tcg-cpu.c
+++ b/target/riscv/tcg/tcg-cpu.c
@@ -295,29 +295,6 @@ static void riscv_cpu_validate_misa_mxl(RISCVCPU *cpu, Error **errp)
}
}
-static void riscv_cpu_validate_priv_spec(RISCVCPU *cpu, Error **errp)
-{
- CPURISCVState *env = &cpu->env;
- int priv_version = -1;
-
- if (cpu->cfg.priv_spec) {
- if (!g_strcmp0(cpu->cfg.priv_spec, "v1.12.0")) {
- priv_version = PRIV_VERSION_1_12_0;
- } else if (!g_strcmp0(cpu->cfg.priv_spec, "v1.11.0")) {
- priv_version = PRIV_VERSION_1_11_0;
- } else if (!g_strcmp0(cpu->cfg.priv_spec, "v1.10.0")) {
- priv_version = PRIV_VERSION_1_10_0;
- } else {
- error_setg(errp,
- "Unsupported privilege spec version '%s'",
- cpu->cfg.priv_spec);
- return;
- }
-
- env->priv_ver = priv_version;
- }
-}
-
static void riscv_cpu_validate_v(CPURISCVState *env, RISCVCPUConfig *cfg,
Error **errp)
{
@@ -876,12 +853,6 @@ void riscv_tcg_cpu_finalize_features(RISCVCPU *cpu, Error **errp)
CPURISCVState *env = &cpu->env;
Error *local_err = NULL;
- riscv_cpu_validate_priv_spec(cpu, &local_err);
- if (local_err != NULL) {
- error_propagate(errp, local_err);
- return;
- }
-
riscv_cpu_validate_misa_priv(env, &local_err);
if (local_err != NULL) {
error_propagate(errp, local_err);
--
2.43.0
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v4 07/17] target/riscv: rework 'vext_spec'
2024-01-05 23:05 [PATCH v4 00/17] target/riscv: deprecate riscv_cpu_options[] Daniel Henrique Barboza
` (5 preceding siblings ...)
2024-01-05 23:05 ` [PATCH v4 06/17] target/riscv: rework 'priv_spec' Daniel Henrique Barboza
@ 2024-01-05 23:05 ` Daniel Henrique Barboza
2024-01-05 23:05 ` [PATCH v4 08/17] target/riscv: move 'vlen' to riscv_cpu_properties[] Daniel Henrique Barboza
` (11 subsequent siblings)
18 siblings, 0 replies; 25+ messages in thread
From: Daniel Henrique Barboza @ 2024-01-05 23:05 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-riscv, alistair.francis, bmeng, liwei1518, zhiwei_liu,
palmer, ajones, Daniel Henrique Barboza
The same rework did in 'priv_spec' is done for 'vext_spec'. This time is
simpler, since we only accept one value ("v1.0") and we'll always have
env->vext_ver set to VEXT_VERSION_1_00_0, thus we don't need helpers to
convert string to 'vext_ver' back and forth like we needed for
'priv_spec'.
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
---
target/riscv/cpu.c | 35 +++++++++++++++++++++++++++++++++--
target/riscv/cpu.h | 1 +
target/riscv/cpu_cfg.h | 1 -
target/riscv/tcg/tcg-cpu.c | 15 ---------------
4 files changed, 34 insertions(+), 18 deletions(-)
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
index f3316c5082..a4e5863de7 100644
--- a/target/riscv/cpu.c
+++ b/target/riscv/cpu.c
@@ -1307,6 +1307,7 @@ static void riscv_cpu_init(Object *obj)
/* Default values for non-bool cpu properties */
cpu->cfg.pmu_mask = MAKE_64BIT_MASK(3, 16);
+ cpu->env.vext_ver = VEXT_VERSION_1_00_0;
}
typedef struct misa_ext_info {
@@ -1745,9 +1746,38 @@ static const PropertyInfo prop_priv_spec = {
.set = prop_priv_spec_set,
};
-Property riscv_cpu_options[] = {
- DEFINE_PROP_STRING("vext_spec", RISCVCPU, cfg.vext_spec),
+static void prop_vext_spec_set(Object *obj, Visitor *v, const char *name,
+ void *opaque, Error **errp)
+{
+ RISCVCPU *cpu = RISCV_CPU(obj);
+ g_autofree char *value = NULL;
+ visit_type_str(v, name, &value, errp);
+
+ if (g_strcmp0(value, VEXT_VER_1_00_0_STR) != 0) {
+ error_setg(errp, "Unsupported vector spec version '%s'", value);
+ return;
+ }
+
+ cpu_option_add_user_setting(name, VEXT_VERSION_1_00_0);
+ cpu->env.vext_ver = VEXT_VERSION_1_00_0;
+}
+
+static void prop_vext_spec_get(Object *obj, Visitor *v, const char *name,
+ void *opaque, Error **errp)
+{
+ const char *value = VEXT_VER_1_00_0_STR;
+
+ visit_type_str(v, name, (char **)&value, errp);
+}
+
+static const PropertyInfo prop_vext_spec = {
+ .name = "vext_spec",
+ .get = prop_vext_spec_get,
+ .set = prop_vext_spec_set,
+};
+
+Property riscv_cpu_options[] = {
DEFINE_PROP_UINT16("vlen", RISCVCPU, cfg.vlen, 128),
DEFINE_PROP_UINT16("elen", RISCVCPU, cfg.elen, 64),
@@ -1835,6 +1865,7 @@ static Property riscv_cpu_properties[] = {
{.name = "pmp", .info = &prop_pmp},
{.name = "priv_spec", .info = &prop_priv_spec},
+ {.name = "vext_spec", .info = &prop_vext_spec},
#ifndef CONFIG_USER_ONLY
DEFINE_PROP_UINT64("resetvec", RISCVCPU, env.resetvec, DEFAULT_RSTVEC),
diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
index ee65ed555a..3cec85069f 100644
--- a/target/riscv/cpu.h
+++ b/target/riscv/cpu.h
@@ -105,6 +105,7 @@ enum {
};
#define VEXT_VERSION_1_00_0 0x00010000
+#define VEXT_VER_1_00_0_STR "v1.0"
enum {
TRANSLATE_SUCCESS,
diff --git a/target/riscv/cpu_cfg.h b/target/riscv/cpu_cfg.h
index 68965743b6..fea14c275f 100644
--- a/target/riscv/cpu_cfg.h
+++ b/target/riscv/cpu_cfg.h
@@ -139,7 +139,6 @@ struct RISCVCPUConfig {
bool ext_XVentanaCondOps;
uint32_t pmu_mask;
- char *vext_spec;
uint16_t vlen;
uint16_t elen;
uint16_t cbom_blocksize;
diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c
index a24c5e7e58..0fb054b20e 100644
--- a/target/riscv/tcg/tcg-cpu.c
+++ b/target/riscv/tcg/tcg-cpu.c
@@ -321,21 +321,6 @@ static void riscv_cpu_validate_v(CPURISCVState *env, RISCVCPUConfig *cfg,
"in the range [8, 64]");
return;
}
-
- if (cfg->vext_spec) {
- if (!g_strcmp0(cfg->vext_spec, "v1.0")) {
- env->vext_ver = VEXT_VERSION_1_00_0;
- } else {
- error_setg(errp, "Unsupported vector spec version '%s'",
- cfg->vext_spec);
- return;
- }
- } else if (env->vext_ver == 0) {
- qemu_log("vector version is not specified, "
- "use the default value v1.0\n");
-
- env->vext_ver = VEXT_VERSION_1_00_0;
- }
}
static void riscv_cpu_disable_priv_spec_isa_exts(RISCVCPU *cpu)
--
2.43.0
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v4 08/17] target/riscv: move 'vlen' to riscv_cpu_properties[]
2024-01-05 23:05 [PATCH v4 00/17] target/riscv: deprecate riscv_cpu_options[] Daniel Henrique Barboza
` (6 preceding siblings ...)
2024-01-05 23:05 ` [PATCH v4 07/17] target/riscv: rework 'vext_spec' Daniel Henrique Barboza
@ 2024-01-05 23:05 ` Daniel Henrique Barboza
2024-01-05 23:05 ` [PATCH v4 09/17] target/riscv: move 'elen' " Daniel Henrique Barboza
` (10 subsequent siblings)
18 siblings, 0 replies; 25+ messages in thread
From: Daniel Henrique Barboza @ 2024-01-05 23:05 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-riscv, alistair.francis, bmeng, liwei1518, zhiwei_liu,
palmer, ajones, Daniel Henrique Barboza
Turning 'vlen' into a class property will allow its default value to be
overwritten by cpu_init() later on, solving the issue we have now where
CPU specific settings are getting overwritten by the default.
Common validation bits are moved from riscv_cpu_validate_v() to
prop_vlen_set() to be shared with KVM.
And, as done with every option we migrated to riscv_cpu_properties[],
vendor CPUs can't have their 'vlen' value changed.
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
---
target/riscv/cpu.c | 45 +++++++++++++++++++++++++++++++++++++-
target/riscv/tcg/tcg-cpu.c | 5 -----
2 files changed, 44 insertions(+), 6 deletions(-)
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
index a4e5863de7..fd55064c3b 100644
--- a/target/riscv/cpu.c
+++ b/target/riscv/cpu.c
@@ -29,6 +29,7 @@
#include "qapi/visitor.h"
#include "qemu/error-report.h"
#include "hw/qdev-properties.h"
+#include "hw/core/qdev-prop-internal.h"
#include "migration/vmstate.h"
#include "fpu/softfloat-helpers.h"
#include "sysemu/kvm.h"
@@ -1307,6 +1308,7 @@ static void riscv_cpu_init(Object *obj)
/* Default values for non-bool cpu properties */
cpu->cfg.pmu_mask = MAKE_64BIT_MASK(3, 16);
+ cpu->cfg.vlen = 128;
cpu->env.vext_ver = VEXT_VERSION_1_00_0;
}
@@ -1777,8 +1779,47 @@ static const PropertyInfo prop_vext_spec = {
.set = prop_vext_spec_set,
};
+static void prop_vlen_set(Object *obj, Visitor *v, const char *name,
+ void *opaque, Error **errp)
+{
+ RISCVCPU *cpu = RISCV_CPU(obj);
+ uint16_t value;
+
+ if (!visit_type_uint16(v, name, &value, errp)) {
+ return;
+ }
+
+ if (!is_power_of_2(value)) {
+ error_setg(errp, "Vector extension VLEN must be power of 2");
+ return;
+ }
+
+ if (value != cpu->cfg.vlen && riscv_cpu_is_vendor(obj)) {
+ cpu_set_prop_err(cpu, name, errp);
+ error_append_hint(errp, "Current '%s' val: %u\n",
+ name, cpu->cfg.vlen);
+ return;
+ }
+
+ cpu_option_add_user_setting(name, value);
+ cpu->cfg.vlen = value;
+}
+
+static void prop_vlen_get(Object *obj, Visitor *v, const char *name,
+ void *opaque, Error **errp)
+{
+ uint16_t value = RISCV_CPU(obj)->cfg.vlen;
+
+ visit_type_uint16(v, name, &value, errp);
+}
+
+static const PropertyInfo prop_vlen = {
+ .name = "vlen",
+ .get = prop_vlen_get,
+ .set = prop_vlen_set,
+};
+
Property riscv_cpu_options[] = {
- DEFINE_PROP_UINT16("vlen", RISCVCPU, cfg.vlen, 128),
DEFINE_PROP_UINT16("elen", RISCVCPU, cfg.elen, 64),
DEFINE_PROP_UINT16("cbom_blocksize", RISCVCPU, cfg.cbom_blocksize, 64),
@@ -1867,6 +1908,8 @@ static Property riscv_cpu_properties[] = {
{.name = "priv_spec", .info = &prop_priv_spec},
{.name = "vext_spec", .info = &prop_vext_spec},
+ {.name = "vlen", .info = &prop_vlen},
+
#ifndef CONFIG_USER_ONLY
DEFINE_PROP_UINT64("resetvec", RISCVCPU, env.resetvec, DEFAULT_RSTVEC),
#endif
diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c
index 0fb054b20e..71a364453e 100644
--- a/target/riscv/tcg/tcg-cpu.c
+++ b/target/riscv/tcg/tcg-cpu.c
@@ -298,11 +298,6 @@ static void riscv_cpu_validate_misa_mxl(RISCVCPU *cpu, Error **errp)
static void riscv_cpu_validate_v(CPURISCVState *env, RISCVCPUConfig *cfg,
Error **errp)
{
- if (!is_power_of_2(cfg->vlen)) {
- error_setg(errp, "Vector extension VLEN must be power of 2");
- return;
- }
-
if (cfg->vlen > RV_VLEN_MAX || cfg->vlen < 128) {
error_setg(errp,
"Vector extension implementation only supports VLEN "
--
2.43.0
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v4 09/17] target/riscv: move 'elen' to riscv_cpu_properties[]
2024-01-05 23:05 [PATCH v4 00/17] target/riscv: deprecate riscv_cpu_options[] Daniel Henrique Barboza
` (7 preceding siblings ...)
2024-01-05 23:05 ` [PATCH v4 08/17] target/riscv: move 'vlen' to riscv_cpu_properties[] Daniel Henrique Barboza
@ 2024-01-05 23:05 ` Daniel Henrique Barboza
2024-01-05 23:05 ` [PATCH v4 10/17] target/riscv: create finalize_features() for KVM Daniel Henrique Barboza
` (9 subsequent siblings)
18 siblings, 0 replies; 25+ messages in thread
From: Daniel Henrique Barboza @ 2024-01-05 23:05 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-riscv, alistair.francis, bmeng, liwei1518, zhiwei_liu,
palmer, ajones, Daniel Henrique Barboza
Do the same thing we did with 'vlen' in the previous patch with 'elen'.
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
---
target/riscv/cpu.c | 44 ++++++++++++++++++++++++++++++++++++--
target/riscv/tcg/tcg-cpu.c | 5 -----
2 files changed, 42 insertions(+), 7 deletions(-)
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
index fd55064c3b..2bb4828324 100644
--- a/target/riscv/cpu.c
+++ b/target/riscv/cpu.c
@@ -1309,6 +1309,7 @@ static void riscv_cpu_init(Object *obj)
/* Default values for non-bool cpu properties */
cpu->cfg.pmu_mask = MAKE_64BIT_MASK(3, 16);
cpu->cfg.vlen = 128;
+ cpu->cfg.elen = 64;
cpu->env.vext_ver = VEXT_VERSION_1_00_0;
}
@@ -1819,9 +1820,47 @@ static const PropertyInfo prop_vlen = {
.set = prop_vlen_set,
};
-Property riscv_cpu_options[] = {
- DEFINE_PROP_UINT16("elen", RISCVCPU, cfg.elen, 64),
+static void prop_elen_set(Object *obj, Visitor *v, const char *name,
+ void *opaque, Error **errp)
+{
+ RISCVCPU *cpu = RISCV_CPU(obj);
+ uint16_t value;
+
+ if (!visit_type_uint16(v, name, &value, errp)) {
+ return;
+ }
+
+ if (!is_power_of_2(value)) {
+ error_setg(errp, "Vector extension ELEN must be power of 2");
+ return;
+ }
+
+ if (value != cpu->cfg.elen && riscv_cpu_is_vendor(obj)) {
+ cpu_set_prop_err(cpu, name, errp);
+ error_append_hint(errp, "Current '%s' val: %u\n",
+ name, cpu->cfg.elen);
+ return;
+ }
+
+ cpu_option_add_user_setting(name, value);
+ cpu->cfg.elen = value;
+}
+static void prop_elen_get(Object *obj, Visitor *v, const char *name,
+ void *opaque, Error **errp)
+{
+ uint16_t value = RISCV_CPU(obj)->cfg.elen;
+
+ visit_type_uint16(v, name, &value, errp);
+}
+
+static const PropertyInfo prop_elen = {
+ .name = "elen",
+ .get = prop_elen_get,
+ .set = prop_elen_set,
+};
+
+Property riscv_cpu_options[] = {
DEFINE_PROP_UINT16("cbom_blocksize", RISCVCPU, cfg.cbom_blocksize, 64),
DEFINE_PROP_UINT16("cbop_blocksize", RISCVCPU, cfg.cbop_blocksize, 64),
DEFINE_PROP_UINT16("cboz_blocksize", RISCVCPU, cfg.cboz_blocksize, 64),
@@ -1909,6 +1948,7 @@ static Property riscv_cpu_properties[] = {
{.name = "vext_spec", .info = &prop_vext_spec},
{.name = "vlen", .info = &prop_vlen},
+ {.name = "elen", .info = &prop_elen},
#ifndef CONFIG_USER_ONLY
DEFINE_PROP_UINT64("resetvec", RISCVCPU, env.resetvec, DEFAULT_RSTVEC),
diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c
index 71a364453e..c7c2a28f10 100644
--- a/target/riscv/tcg/tcg-cpu.c
+++ b/target/riscv/tcg/tcg-cpu.c
@@ -305,11 +305,6 @@ static void riscv_cpu_validate_v(CPURISCVState *env, RISCVCPUConfig *cfg,
return;
}
- if (!is_power_of_2(cfg->elen)) {
- error_setg(errp, "Vector extension ELEN must be power of 2");
- return;
- }
-
if (cfg->elen > 64 || cfg->elen < 8) {
error_setg(errp,
"Vector extension implementation only supports ELEN "
--
2.43.0
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v4 10/17] target/riscv: create finalize_features() for KVM
2024-01-05 23:05 [PATCH v4 00/17] target/riscv: deprecate riscv_cpu_options[] Daniel Henrique Barboza
` (8 preceding siblings ...)
2024-01-05 23:05 ` [PATCH v4 09/17] target/riscv: move 'elen' " Daniel Henrique Barboza
@ 2024-01-05 23:05 ` Daniel Henrique Barboza
2024-01-11 23:33 ` Alistair Francis
2024-01-05 23:05 ` [PATCH v4 11/17] target/riscv: move 'cbom_blocksize' to riscv_cpu_properties[] Daniel Henrique Barboza
` (8 subsequent siblings)
18 siblings, 1 reply; 25+ messages in thread
From: Daniel Henrique Barboza @ 2024-01-05 23:05 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-riscv, alistair.francis, bmeng, liwei1518, zhiwei_liu,
palmer, ajones, Daniel Henrique Barboza
To turn cbom_blocksize and cboz_blocksize into class properties we need
KVM specific changes.
KVM is creating its own version of these options with a customized
setter() that prevents users from picking an invalid value during init()
time. This comes at the cost of duplicating each option that KVM
supports. This will keep happening for each new shared option KVM
implements in the future.
We can avoid that by using the same property TCG uses and adding
specific KVM handling during finalize() time, like TCG already does with
riscv_tcg_cpu_finalize_features(). To do that, the common CPU property
offers a way of knowing if an option was user set or not, sparing us
from doing unneeded syscalls.
riscv_kvm_cpu_finalize_features() is then created using the same
KVMScratch CPU we already use during init() time, since finalize() time
is still too early to use the official KVM CPU for it. cbom_blocksize
and cboz_blocksize are then handled during finalize() in the same way
they're handled by their KVM specific setter.
With this change we can proceed with the blocksize changes in the common
code without breaking the KVM driver.
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
---
target/riscv/cpu.c | 16 +++++++---
target/riscv/cpu.h | 1 +
target/riscv/kvm/kvm-cpu.c | 59 ++++++++++++++++++++++++++++++++++++
target/riscv/kvm/kvm_riscv.h | 1 +
4 files changed, 72 insertions(+), 5 deletions(-)
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
index 2bb4828324..cd91966ea7 100644
--- a/target/riscv/cpu.c
+++ b/target/riscv/cpu.c
@@ -68,6 +68,11 @@ static void cpu_option_add_user_setting(const char *optname, uint32_t value)
GUINT_TO_POINTER(value));
}
+bool riscv_cpu_option_set(const char *optname)
+{
+ return g_hash_table_contains(general_user_opts, optname);
+}
+
#define ISA_EXT_DATA_ENTRY(_name, _min_ver, _prop) \
{#_name, _min_ver, CPU_CFG_OFFSET(_prop)}
@@ -1104,17 +1109,18 @@ void riscv_cpu_finalize_features(RISCVCPU *cpu, Error **errp)
}
#endif
- /*
- * KVM accel does not have a specialized finalize()
- * callback because its extensions are validated
- * in the get()/set() callbacks of each property.
- */
if (tcg_enabled()) {
riscv_tcg_cpu_finalize_features(cpu, &local_err);
if (local_err != NULL) {
error_propagate(errp, local_err);
return;
}
+ } else if (kvm_enabled()) {
+ riscv_kvm_cpu_finalize_features(cpu, &local_err);
+ if (local_err != NULL) {
+ error_propagate(errp, local_err);
+ return;
+ }
}
}
diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
index 3cec85069f..1c19fa84bb 100644
--- a/target/riscv/cpu.h
+++ b/target/riscv/cpu.h
@@ -510,6 +510,7 @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size,
bool probe, uintptr_t retaddr);
char *riscv_isa_string(RISCVCPU *cpu);
void riscv_cpu_list(void);
+bool riscv_cpu_option_set(const char *optname);
#define cpu_list riscv_cpu_list
#define cpu_mmu_index riscv_cpu_mmu_index
diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c
index 2c5217102c..2713f4b2ba 100644
--- a/target/riscv/kvm/kvm-cpu.c
+++ b/target/riscv/kvm/kvm-cpu.c
@@ -1493,6 +1493,65 @@ static void kvm_cpu_instance_init(CPUState *cs)
}
}
+void riscv_kvm_cpu_finalize_features(RISCVCPU *cpu, Error **errp)
+{
+ CPURISCVState *env = &cpu->env;
+ KVMScratchCPU kvmcpu;
+ struct kvm_one_reg reg;
+ uint64_t val;
+ int ret;
+
+ /* short-circuit without spinning the scratch CPU */
+ if (!cpu->cfg.ext_zicbom && !cpu->cfg.ext_zicboz) {
+ return;
+ }
+
+ if (!kvm_riscv_create_scratch_vcpu(&kvmcpu)) {
+ error_setg(errp, "Unable to create scratch KVM cpu");
+ return;
+ }
+
+ if (cpu->cfg.ext_zicbom &&
+ riscv_cpu_option_set(kvm_cbom_blocksize.name)) {
+
+ reg.id = kvm_riscv_reg_id_ulong(env, KVM_REG_RISCV_CONFIG,
+ kvm_cbom_blocksize.kvm_reg_id);
+ reg.addr = (uint64_t)&val;
+ ret = ioctl(kvmcpu.cpufd, KVM_GET_ONE_REG, ®);
+ if (ret != 0) {
+ error_setg(errp, "Unable to read cbom_blocksize, error %d", errno);
+ return;
+ }
+
+ if (cpu->cfg.cbom_blocksize != val) {
+ error_setg(errp, "Unable to set cbom_blocksize to a different "
+ "value than the host (%lu)", val);
+ return;
+ }
+ }
+
+ if (cpu->cfg.ext_zicboz &&
+ riscv_cpu_option_set(kvm_cboz_blocksize.name)) {
+
+ reg.id = kvm_riscv_reg_id_ulong(env, KVM_REG_RISCV_CONFIG,
+ kvm_cboz_blocksize.kvm_reg_id);
+ reg.addr = (uint64_t)&val;
+ ret = ioctl(kvmcpu.cpufd, KVM_GET_ONE_REG, ®);
+ if (ret != 0) {
+ error_setg(errp, "Unable to read cboz_blocksize, error %d", errno);
+ return;
+ }
+
+ if (cpu->cfg.cboz_blocksize != val) {
+ error_setg(errp, "Unable to set cboz_blocksize to a different "
+ "value than the host (%lu)", val);
+ return;
+ }
+ }
+
+ kvm_riscv_destroy_scratch_vcpu(&kvmcpu);
+}
+
static void kvm_cpu_accel_class_init(ObjectClass *oc, void *data)
{
AccelCPUClass *acc = ACCEL_CPU_CLASS(oc);
diff --git a/target/riscv/kvm/kvm_riscv.h b/target/riscv/kvm/kvm_riscv.h
index 8329cfab82..4bd98fddc7 100644
--- a/target/riscv/kvm/kvm_riscv.h
+++ b/target/riscv/kvm/kvm_riscv.h
@@ -27,5 +27,6 @@ void kvm_riscv_aia_create(MachineState *machine, uint64_t group_shift,
uint64_t guest_num);
void riscv_kvm_aplic_request(void *opaque, int irq, int level);
int kvm_riscv_sync_mpstate_to_kvm(RISCVCPU *cpu, int state);
+void riscv_kvm_cpu_finalize_features(RISCVCPU *cpu, Error **errp);
#endif
--
2.43.0
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v4 11/17] target/riscv: move 'cbom_blocksize' to riscv_cpu_properties[]
2024-01-05 23:05 [PATCH v4 00/17] target/riscv: deprecate riscv_cpu_options[] Daniel Henrique Barboza
` (9 preceding siblings ...)
2024-01-05 23:05 ` [PATCH v4 10/17] target/riscv: create finalize_features() for KVM Daniel Henrique Barboza
@ 2024-01-05 23:05 ` Daniel Henrique Barboza
2024-01-05 23:05 ` [PATCH v4 12/17] target/riscv: move 'cbop_blocksize' " Daniel Henrique Barboza
` (7 subsequent siblings)
18 siblings, 0 replies; 25+ messages in thread
From: Daniel Henrique Barboza @ 2024-01-05 23:05 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-riscv, alistair.francis, bmeng, liwei1518, zhiwei_liu,
palmer, ajones, Daniel Henrique Barboza
After adding a KVM finalize() implementation, turn cbom_blocksize into a
class property. Follow the same design we used with 'vlen' and 'elen'.
The duplicated 'cbom_blocksize' KVM property can be removed from
kvm_riscv_add_cpu_user_properties().
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
---
target/riscv/cpu.c | 39 +++++++++++++++++++++++++++++++++++++-
target/riscv/kvm/kvm-cpu.c | 4 ----
2 files changed, 38 insertions(+), 5 deletions(-)
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
index cd91966ea7..b77d26231c 100644
--- a/target/riscv/cpu.c
+++ b/target/riscv/cpu.c
@@ -1316,6 +1316,7 @@ static void riscv_cpu_init(Object *obj)
cpu->cfg.pmu_mask = MAKE_64BIT_MASK(3, 16);
cpu->cfg.vlen = 128;
cpu->cfg.elen = 64;
+ cpu->cfg.cbom_blocksize = 64;
cpu->env.vext_ver = VEXT_VERSION_1_00_0;
}
@@ -1866,8 +1867,42 @@ static const PropertyInfo prop_elen = {
.set = prop_elen_set,
};
+static void prop_cbom_blksize_set(Object *obj, Visitor *v, const char *name,
+ void *opaque, Error **errp)
+{
+ RISCVCPU *cpu = RISCV_CPU(obj);
+ uint16_t value;
+
+ if (!visit_type_uint16(v, name, &value, errp)) {
+ return;
+ }
+
+ if (value != cpu->cfg.cbom_blocksize && riscv_cpu_is_vendor(obj)) {
+ cpu_set_prop_err(cpu, name, errp);
+ error_append_hint(errp, "Current '%s' val: %u\n",
+ name, cpu->cfg.cbom_blocksize);
+ return;
+ }
+
+ cpu_option_add_user_setting(name, value);
+ cpu->cfg.cbom_blocksize = value;
+}
+
+static void prop_cbom_blksize_get(Object *obj, Visitor *v, const char *name,
+ void *opaque, Error **errp)
+{
+ uint16_t value = RISCV_CPU(obj)->cfg.cbom_blocksize;
+
+ visit_type_uint16(v, name, &value, errp);
+}
+
+static const PropertyInfo prop_cbom_blksize = {
+ .name = "cbom_blocksize",
+ .get = prop_cbom_blksize_get,
+ .set = prop_cbom_blksize_set,
+};
+
Property riscv_cpu_options[] = {
- DEFINE_PROP_UINT16("cbom_blocksize", RISCVCPU, cfg.cbom_blocksize, 64),
DEFINE_PROP_UINT16("cbop_blocksize", RISCVCPU, cfg.cbop_blocksize, 64),
DEFINE_PROP_UINT16("cboz_blocksize", RISCVCPU, cfg.cboz_blocksize, 64),
@@ -1956,6 +1991,8 @@ static Property riscv_cpu_properties[] = {
{.name = "vlen", .info = &prop_vlen},
{.name = "elen", .info = &prop_elen},
+ {.name = "cbom_blocksize", .info = &prop_cbom_blksize},
+
#ifndef CONFIG_USER_ONLY
DEFINE_PROP_UINT64("resetvec", RISCVCPU, env.resetvec, DEFAULT_RSTVEC),
#endif
diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c
index 2713f4b2ba..9a6a007931 100644
--- a/target/riscv/kvm/kvm-cpu.c
+++ b/target/riscv/kvm/kvm-cpu.c
@@ -484,10 +484,6 @@ static void kvm_riscv_add_cpu_user_properties(Object *cpu_obj)
NULL, multi_cfg);
}
- object_property_add(cpu_obj, "cbom_blocksize", "uint16",
- NULL, kvm_cpu_set_cbomz_blksize,
- NULL, &kvm_cbom_blocksize);
-
object_property_add(cpu_obj, "cboz_blocksize", "uint16",
NULL, kvm_cpu_set_cbomz_blksize,
NULL, &kvm_cboz_blocksize);
--
2.43.0
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v4 12/17] target/riscv: move 'cbop_blocksize' to riscv_cpu_properties[]
2024-01-05 23:05 [PATCH v4 00/17] target/riscv: deprecate riscv_cpu_options[] Daniel Henrique Barboza
` (10 preceding siblings ...)
2024-01-05 23:05 ` [PATCH v4 11/17] target/riscv: move 'cbom_blocksize' to riscv_cpu_properties[] Daniel Henrique Barboza
@ 2024-01-05 23:05 ` Daniel Henrique Barboza
2024-01-11 23:44 ` Alistair Francis
2024-01-05 23:05 ` [PATCH v4 13/17] target/riscv: move 'cboz_blocksize' " Daniel Henrique Barboza
` (6 subsequent siblings)
18 siblings, 1 reply; 25+ messages in thread
From: Daniel Henrique Barboza @ 2024-01-05 23:05 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-riscv, alistair.francis, bmeng, liwei1518, zhiwei_liu,
palmer, ajones, Daniel Henrique Barboza
Do the same we did with 'cbom_blocksize' in the previous patch.
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
---
target/riscv/cpu.c | 38 +++++++++++++++++++++++++++++++++++++-
1 file changed, 37 insertions(+), 1 deletion(-)
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
index b77d26231c..e3cbe9b1b6 100644
--- a/target/riscv/cpu.c
+++ b/target/riscv/cpu.c
@@ -1317,6 +1317,7 @@ static void riscv_cpu_init(Object *obj)
cpu->cfg.vlen = 128;
cpu->cfg.elen = 64;
cpu->cfg.cbom_blocksize = 64;
+ cpu->cfg.cbop_blocksize = 64;
cpu->env.vext_ver = VEXT_VERSION_1_00_0;
}
@@ -1902,8 +1903,42 @@ static const PropertyInfo prop_cbom_blksize = {
.set = prop_cbom_blksize_set,
};
+static void prop_cbop_blksize_set(Object *obj, Visitor *v, const char *name,
+ void *opaque, Error **errp)
+{
+ RISCVCPU *cpu = RISCV_CPU(obj);
+ uint16_t value;
+
+ if (!visit_type_uint16(v, name, &value, errp)) {
+ return;
+ }
+
+ if (value != cpu->cfg.cbop_blocksize && riscv_cpu_is_vendor(obj)) {
+ cpu_set_prop_err(cpu, name, errp);
+ error_append_hint(errp, "Current '%s' val: %u\n",
+ name, cpu->cfg.cbop_blocksize);
+ return;
+ }
+
+ cpu_option_add_user_setting(name, value);
+ cpu->cfg.cbop_blocksize = value;
+}
+
+static void prop_cbop_blksize_get(Object *obj, Visitor *v, const char *name,
+ void *opaque, Error **errp)
+{
+ uint16_t value = RISCV_CPU(obj)->cfg.cbop_blocksize;
+
+ visit_type_uint16(v, name, &value, errp);
+}
+
+static const PropertyInfo prop_cbop_blksize = {
+ .name = "cbop_blocksize",
+ .get = prop_cbop_blksize_get,
+ .set = prop_cbop_blksize_set,
+};
+
Property riscv_cpu_options[] = {
- DEFINE_PROP_UINT16("cbop_blocksize", RISCVCPU, cfg.cbop_blocksize, 64),
DEFINE_PROP_UINT16("cboz_blocksize", RISCVCPU, cfg.cboz_blocksize, 64),
DEFINE_PROP_END_OF_LIST(),
@@ -1992,6 +2027,7 @@ static Property riscv_cpu_properties[] = {
{.name = "elen", .info = &prop_elen},
{.name = "cbom_blocksize", .info = &prop_cbom_blksize},
+ {.name = "cbop_blocksize", .info = &prop_cbop_blksize},
#ifndef CONFIG_USER_ONLY
DEFINE_PROP_UINT64("resetvec", RISCVCPU, env.resetvec, DEFAULT_RSTVEC),
--
2.43.0
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v4 13/17] target/riscv: move 'cboz_blocksize' to riscv_cpu_properties[]
2024-01-05 23:05 [PATCH v4 00/17] target/riscv: deprecate riscv_cpu_options[] Daniel Henrique Barboza
` (11 preceding siblings ...)
2024-01-05 23:05 ` [PATCH v4 12/17] target/riscv: move 'cbop_blocksize' " Daniel Henrique Barboza
@ 2024-01-05 23:05 ` Daniel Henrique Barboza
2024-01-05 23:05 ` [PATCH v4 14/17] target/riscv: remove riscv_cpu_options[] Daniel Henrique Barboza
` (5 subsequent siblings)
18 siblings, 0 replies; 25+ messages in thread
From: Daniel Henrique Barboza @ 2024-01-05 23:05 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-riscv, alistair.francis, bmeng, liwei1518, zhiwei_liu,
palmer, ajones, Daniel Henrique Barboza
And remove the now unused kvm_cpu_set_cbomz_blksize() setter.
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
---
target/riscv/cpu.c | 38 +++++++++++++++++++++++++++++++++++++-
target/riscv/kvm/kvm-cpu.c | 28 ----------------------------
2 files changed, 37 insertions(+), 29 deletions(-)
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
index e3cbe9b1b6..f84c3fc4a2 100644
--- a/target/riscv/cpu.c
+++ b/target/riscv/cpu.c
@@ -1318,6 +1318,7 @@ static void riscv_cpu_init(Object *obj)
cpu->cfg.elen = 64;
cpu->cfg.cbom_blocksize = 64;
cpu->cfg.cbop_blocksize = 64;
+ cpu->cfg.cboz_blocksize = 64;
cpu->env.vext_ver = VEXT_VERSION_1_00_0;
}
@@ -1938,8 +1939,42 @@ static const PropertyInfo prop_cbop_blksize = {
.set = prop_cbop_blksize_set,
};
+static void prop_cboz_blksize_set(Object *obj, Visitor *v, const char *name,
+ void *opaque, Error **errp)
+{
+ RISCVCPU *cpu = RISCV_CPU(obj);
+ uint16_t value;
+
+ if (!visit_type_uint16(v, name, &value, errp)) {
+ return;
+ }
+
+ if (value != cpu->cfg.cboz_blocksize && riscv_cpu_is_vendor(obj)) {
+ cpu_set_prop_err(cpu, name, errp);
+ error_append_hint(errp, "Current '%s' val: %u\n",
+ name, cpu->cfg.cboz_blocksize);
+ return;
+ }
+
+ cpu_option_add_user_setting(name, value);
+ cpu->cfg.cboz_blocksize = value;
+}
+
+static void prop_cboz_blksize_get(Object *obj, Visitor *v, const char *name,
+ void *opaque, Error **errp)
+{
+ uint16_t value = RISCV_CPU(obj)->cfg.cboz_blocksize;
+
+ visit_type_uint16(v, name, &value, errp);
+}
+
+static const PropertyInfo prop_cboz_blksize = {
+ .name = "cboz_blocksize",
+ .get = prop_cboz_blksize_get,
+ .set = prop_cboz_blksize_set,
+};
+
Property riscv_cpu_options[] = {
- DEFINE_PROP_UINT16("cboz_blocksize", RISCVCPU, cfg.cboz_blocksize, 64),
DEFINE_PROP_END_OF_LIST(),
};
@@ -2028,6 +2063,7 @@ static Property riscv_cpu_properties[] = {
{.name = "cbom_blocksize", .info = &prop_cbom_blksize},
{.name = "cbop_blocksize", .info = &prop_cbop_blksize},
+ {.name = "cboz_blocksize", .info = &prop_cboz_blksize},
#ifndef CONFIG_USER_ONLY
DEFINE_PROP_UINT64("resetvec", RISCVCPU, env.resetvec, DEFAULT_RSTVEC),
diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c
index 9a6a007931..c9b4a6a7e8 100644
--- a/target/riscv/kvm/kvm-cpu.c
+++ b/target/riscv/kvm/kvm-cpu.c
@@ -343,30 +343,6 @@ static KVMCPUConfig kvm_cboz_blocksize = {
.kvm_reg_id = KVM_REG_RISCV_CONFIG_REG(zicboz_block_size)
};
-static void kvm_cpu_set_cbomz_blksize(Object *obj, Visitor *v,
- const char *name,
- void *opaque, Error **errp)
-{
- KVMCPUConfig *cbomz_cfg = opaque;
- RISCVCPU *cpu = RISCV_CPU(obj);
- uint16_t value, *host_val;
-
- if (!visit_type_uint16(v, name, &value, errp)) {
- return;
- }
-
- host_val = kvmconfig_get_cfg_addr(cpu, cbomz_cfg);
-
- if (value != *host_val) {
- error_report("Unable to set %s to a different value than "
- "the host (%u)",
- cbomz_cfg->name, *host_val);
- exit(EXIT_FAILURE);
- }
-
- cbomz_cfg->user_set = true;
-}
-
static void kvm_riscv_update_cpu_cfg_isa_ext(RISCVCPU *cpu, CPUState *cs)
{
CPURISCVState *env = &cpu->env;
@@ -484,10 +460,6 @@ static void kvm_riscv_add_cpu_user_properties(Object *cpu_obj)
NULL, multi_cfg);
}
- object_property_add(cpu_obj, "cboz_blocksize", "uint16",
- NULL, kvm_cpu_set_cbomz_blksize,
- NULL, &kvm_cboz_blocksize);
-
riscv_cpu_add_kvm_unavail_prop_array(cpu_obj, riscv_cpu_extensions);
riscv_cpu_add_kvm_unavail_prop_array(cpu_obj, riscv_cpu_vendor_exts);
riscv_cpu_add_kvm_unavail_prop_array(cpu_obj, riscv_cpu_experimental_exts);
--
2.43.0
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v4 14/17] target/riscv: remove riscv_cpu_options[]
2024-01-05 23:05 [PATCH v4 00/17] target/riscv: deprecate riscv_cpu_options[] Daniel Henrique Barboza
` (12 preceding siblings ...)
2024-01-05 23:05 ` [PATCH v4 13/17] target/riscv: move 'cboz_blocksize' " Daniel Henrique Barboza
@ 2024-01-05 23:05 ` Daniel Henrique Barboza
2024-01-05 23:05 ` [PATCH v4 15/17] target/riscv/cpu.c: move 'mvendorid' to riscv_cpu_properties[] Daniel Henrique Barboza
` (4 subsequent siblings)
18 siblings, 0 replies; 25+ messages in thread
From: Daniel Henrique Barboza @ 2024-01-05 23:05 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-riscv, alistair.francis, bmeng, liwei1518, zhiwei_liu,
palmer, ajones, Daniel Henrique Barboza
The array is empty and can be removed.
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
---
target/riscv/cpu.c | 5 -----
target/riscv/cpu.h | 1 -
target/riscv/kvm/kvm-cpu.c | 9 ---------
target/riscv/tcg/tcg-cpu.c | 4 ----
4 files changed, 19 deletions(-)
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
index f84c3fc4a2..9d4243891c 100644
--- a/target/riscv/cpu.c
+++ b/target/riscv/cpu.c
@@ -1974,11 +1974,6 @@ static const PropertyInfo prop_cboz_blksize = {
.set = prop_cboz_blksize_set,
};
-Property riscv_cpu_options[] = {
-
- DEFINE_PROP_END_OF_LIST(),
-};
-
/*
* RVA22U64 defines some 'named features' or 'synthetic extensions'
* that are cache related: Za64rs, Zic64b, Ziccif, Ziccrse, Ziccamoa
diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
index 1c19fa84bb..c0336b8c0d 100644
--- a/target/riscv/cpu.h
+++ b/target/riscv/cpu.h
@@ -791,7 +791,6 @@ extern const RISCVCPUMultiExtConfig riscv_cpu_vendor_exts[];
extern const RISCVCPUMultiExtConfig riscv_cpu_experimental_exts[];
extern const RISCVCPUMultiExtConfig riscv_cpu_named_features[];
extern const RISCVCPUMultiExtConfig riscv_cpu_deprecated_exts[];
-extern Property riscv_cpu_options[];
typedef struct isa_ext_data {
const char *name;
diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c
index c9b4a6a7e8..8c81049169 100644
--- a/target/riscv/kvm/kvm-cpu.c
+++ b/target/riscv/kvm/kvm-cpu.c
@@ -1446,19 +1446,10 @@ void kvm_riscv_aia_create(MachineState *machine, uint64_t group_shift,
static void kvm_cpu_instance_init(CPUState *cs)
{
Object *obj = OBJECT(RISCV_CPU(cs));
- DeviceState *dev = DEVICE(obj);
riscv_init_kvm_registers(obj);
kvm_riscv_add_cpu_user_properties(obj);
-
- for (Property *prop = riscv_cpu_options; prop && prop->name; prop++) {
- /* Check if we have a specific KVM handler for the option */
- if (object_property_find(obj, prop->name)) {
- continue;
- }
- qdev_property_add_static(dev, prop);
- }
}
void riscv_kvm_cpu_finalize_features(RISCVCPU *cpu, Error **errp)
diff --git a/target/riscv/tcg/tcg-cpu.c b/target/riscv/tcg/tcg-cpu.c
index c7c2a28f10..27591ad2f2 100644
--- a/target/riscv/tcg/tcg-cpu.c
+++ b/target/riscv/tcg/tcg-cpu.c
@@ -1267,10 +1267,6 @@ static void riscv_cpu_add_user_properties(Object *obj)
riscv_cpu_add_multiext_prop_array(obj, riscv_cpu_deprecated_exts);
riscv_cpu_add_profiles(obj);
-
- for (Property *prop = riscv_cpu_options; prop && prop->name; prop++) {
- qdev_property_add_static(DEVICE(obj), prop);
- }
}
/*
--
2.43.0
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v4 15/17] target/riscv/cpu.c: move 'mvendorid' to riscv_cpu_properties[]
2024-01-05 23:05 [PATCH v4 00/17] target/riscv: deprecate riscv_cpu_options[] Daniel Henrique Barboza
` (13 preceding siblings ...)
2024-01-05 23:05 ` [PATCH v4 14/17] target/riscv: remove riscv_cpu_options[] Daniel Henrique Barboza
@ 2024-01-05 23:05 ` Daniel Henrique Barboza
2024-01-12 1:24 ` Alistair Francis
2024-01-05 23:05 ` [PATCH v4 16/17] target/riscv/cpu.c: move 'mimpid' " Daniel Henrique Barboza
` (3 subsequent siblings)
18 siblings, 1 reply; 25+ messages in thread
From: Daniel Henrique Barboza @ 2024-01-05 23:05 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-riscv, alistair.francis, bmeng, liwei1518, zhiwei_liu,
palmer, ajones, Daniel Henrique Barboza
Keep all class properties in riscv_cpu_properties[].
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
---
target/riscv/cpu.c | 69 +++++++++++++++++++++++++---------------------
1 file changed, 37 insertions(+), 32 deletions(-)
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
index 9d4243891c..c725a4839d 100644
--- a/target/riscv/cpu.c
+++ b/target/riscv/cpu.c
@@ -1974,6 +1974,41 @@ static const PropertyInfo prop_cboz_blksize = {
.set = prop_cboz_blksize_set,
};
+static void prop_mvendorid_set(Object *obj, Visitor *v, const char *name,
+ void *opaque, Error **errp)
+{
+ bool dynamic_cpu = riscv_cpu_is_dynamic(obj);
+ RISCVCPU *cpu = RISCV_CPU(obj);
+ uint32_t prev_val = cpu->cfg.mvendorid;
+ uint32_t value;
+
+ if (!visit_type_uint32(v, name, &value, errp)) {
+ return;
+ }
+
+ if (!dynamic_cpu && prev_val != value) {
+ error_setg(errp, "Unable to change %s mvendorid (0x%x)",
+ object_get_typename(obj), prev_val);
+ return;
+ }
+
+ cpu->cfg.mvendorid = value;
+}
+
+static void prop_mvendorid_get(Object *obj, Visitor *v, const char *name,
+ void *opaque, Error **errp)
+{
+ uint32_t value = RISCV_CPU(obj)->cfg.mvendorid;
+
+ visit_type_uint32(v, name, &value, errp);
+}
+
+static const PropertyInfo prop_mvendorid = {
+ .name = "mvendorid",
+ .get = prop_mvendorid_get,
+ .set = prop_mvendorid_set,
+};
+
/*
* RVA22U64 defines some 'named features' or 'synthetic extensions'
* that are cache related: Za64rs, Zic64b, Ziccif, Ziccrse, Ziccamoa
@@ -2060,6 +2095,8 @@ static Property riscv_cpu_properties[] = {
{.name = "cbop_blocksize", .info = &prop_cbop_blksize},
{.name = "cboz_blocksize", .info = &prop_cboz_blksize},
+ {.name = "mvendorid", .info = &prop_mvendorid},
+
#ifndef CONFIG_USER_ONLY
DEFINE_PROP_UINT64("resetvec", RISCVCPU, env.resetvec, DEFAULT_RSTVEC),
#endif
@@ -2140,35 +2177,6 @@ static const struct SysemuCPUOps riscv_sysemu_ops = {
};
#endif
-static void cpu_set_mvendorid(Object *obj, Visitor *v, const char *name,
- void *opaque, Error **errp)
-{
- bool dynamic_cpu = riscv_cpu_is_dynamic(obj);
- RISCVCPU *cpu = RISCV_CPU(obj);
- uint32_t prev_val = cpu->cfg.mvendorid;
- uint32_t value;
-
- if (!visit_type_uint32(v, name, &value, errp)) {
- return;
- }
-
- if (!dynamic_cpu && prev_val != value) {
- error_setg(errp, "Unable to change %s mvendorid (0x%x)",
- object_get_typename(obj), prev_val);
- return;
- }
-
- cpu->cfg.mvendorid = value;
-}
-
-static void cpu_get_mvendorid(Object *obj, Visitor *v, const char *name,
- void *opaque, Error **errp)
-{
- uint32_t value = RISCV_CPU(obj)->cfg.mvendorid;
-
- visit_type_uint32(v, name, &value, errp);
-}
-
static void cpu_set_mimpid(Object *obj, Visitor *v, const char *name,
void *opaque, Error **errp)
{
@@ -2278,9 +2286,6 @@ static void riscv_cpu_class_init(ObjectClass *c, void *data)
cc->gdb_arch_name = riscv_gdb_arch_name;
cc->gdb_get_dynamic_xml = riscv_gdb_get_dynamic_xml;
- object_class_property_add(c, "mvendorid", "uint32", cpu_get_mvendorid,
- cpu_set_mvendorid, NULL, NULL);
-
object_class_property_add(c, "mimpid", "uint64", cpu_get_mimpid,
cpu_set_mimpid, NULL, NULL);
--
2.43.0
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v4 16/17] target/riscv/cpu.c: move 'mimpid' to riscv_cpu_properties[]
2024-01-05 23:05 [PATCH v4 00/17] target/riscv: deprecate riscv_cpu_options[] Daniel Henrique Barboza
` (14 preceding siblings ...)
2024-01-05 23:05 ` [PATCH v4 15/17] target/riscv/cpu.c: move 'mvendorid' to riscv_cpu_properties[] Daniel Henrique Barboza
@ 2024-01-05 23:05 ` Daniel Henrique Barboza
2024-01-12 1:29 ` Alistair Francis
2024-01-05 23:05 ` [PATCH v4 17/17] target/riscv/cpu.c: move 'marchid' " Daniel Henrique Barboza
` (2 subsequent siblings)
18 siblings, 1 reply; 25+ messages in thread
From: Daniel Henrique Barboza @ 2024-01-05 23:05 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-riscv, alistair.francis, bmeng, liwei1518, zhiwei_liu,
palmer, ajones, Daniel Henrique Barboza
Keep all class properties in riscv_cpu_properties[].
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
---
target/riscv/cpu.c | 68 ++++++++++++++++++++++++----------------------
1 file changed, 36 insertions(+), 32 deletions(-)
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
index c725a4839d..6149f5960e 100644
--- a/target/riscv/cpu.c
+++ b/target/riscv/cpu.c
@@ -2009,6 +2009,41 @@ static const PropertyInfo prop_mvendorid = {
.set = prop_mvendorid_set,
};
+static void prop_mimpid_set(Object *obj, Visitor *v, const char *name,
+ void *opaque, Error **errp)
+{
+ bool dynamic_cpu = riscv_cpu_is_dynamic(obj);
+ RISCVCPU *cpu = RISCV_CPU(obj);
+ uint64_t prev_val = cpu->cfg.mimpid;
+ uint64_t value;
+
+ if (!visit_type_uint64(v, name, &value, errp)) {
+ return;
+ }
+
+ if (!dynamic_cpu && prev_val != value) {
+ error_setg(errp, "Unable to change %s mimpid (0x%" PRIu64 ")",
+ object_get_typename(obj), prev_val);
+ return;
+ }
+
+ cpu->cfg.mimpid = value;
+}
+
+static void prop_mimpid_get(Object *obj, Visitor *v, const char *name,
+ void *opaque, Error **errp)
+{
+ uint64_t value = RISCV_CPU(obj)->cfg.mimpid;
+
+ visit_type_uint64(v, name, &value, errp);
+}
+
+static const PropertyInfo prop_mimpid = {
+ .name = "mimpid",
+ .get = prop_mimpid_get,
+ .set = prop_mimpid_set,
+};
+
/*
* RVA22U64 defines some 'named features' or 'synthetic extensions'
* that are cache related: Za64rs, Zic64b, Ziccif, Ziccrse, Ziccamoa
@@ -2096,6 +2131,7 @@ static Property riscv_cpu_properties[] = {
{.name = "cboz_blocksize", .info = &prop_cboz_blksize},
{.name = "mvendorid", .info = &prop_mvendorid},
+ {.name = "mimpid", .info = &prop_mimpid},
#ifndef CONFIG_USER_ONLY
DEFINE_PROP_UINT64("resetvec", RISCVCPU, env.resetvec, DEFAULT_RSTVEC),
@@ -2177,35 +2213,6 @@ static const struct SysemuCPUOps riscv_sysemu_ops = {
};
#endif
-static void cpu_set_mimpid(Object *obj, Visitor *v, const char *name,
- void *opaque, Error **errp)
-{
- bool dynamic_cpu = riscv_cpu_is_dynamic(obj);
- RISCVCPU *cpu = RISCV_CPU(obj);
- uint64_t prev_val = cpu->cfg.mimpid;
- uint64_t value;
-
- if (!visit_type_uint64(v, name, &value, errp)) {
- return;
- }
-
- if (!dynamic_cpu && prev_val != value) {
- error_setg(errp, "Unable to change %s mimpid (0x%" PRIu64 ")",
- object_get_typename(obj), prev_val);
- return;
- }
-
- cpu->cfg.mimpid = value;
-}
-
-static void cpu_get_mimpid(Object *obj, Visitor *v, const char *name,
- void *opaque, Error **errp)
-{
- uint64_t value = RISCV_CPU(obj)->cfg.mimpid;
-
- visit_type_uint64(v, name, &value, errp);
-}
-
static void cpu_set_marchid(Object *obj, Visitor *v, const char *name,
void *opaque, Error **errp)
{
@@ -2286,9 +2293,6 @@ static void riscv_cpu_class_init(ObjectClass *c, void *data)
cc->gdb_arch_name = riscv_gdb_arch_name;
cc->gdb_get_dynamic_xml = riscv_gdb_get_dynamic_xml;
- object_class_property_add(c, "mimpid", "uint64", cpu_get_mimpid,
- cpu_set_mimpid, NULL, NULL);
-
object_class_property_add(c, "marchid", "uint64", cpu_get_marchid,
cpu_set_marchid, NULL, NULL);
--
2.43.0
^ permalink raw reply related [flat|nested] 25+ messages in thread
* [PATCH v4 17/17] target/riscv/cpu.c: move 'marchid' to riscv_cpu_properties[]
2024-01-05 23:05 [PATCH v4 00/17] target/riscv: deprecate riscv_cpu_options[] Daniel Henrique Barboza
` (15 preceding siblings ...)
2024-01-05 23:05 ` [PATCH v4 16/17] target/riscv/cpu.c: move 'mimpid' " Daniel Henrique Barboza
@ 2024-01-05 23:05 ` Daniel Henrique Barboza
2024-01-12 1:37 ` Alistair Francis
2024-01-09 16:35 ` [PATCH v4 00/17] target/riscv: deprecate riscv_cpu_options[] Vladimir Isaev
2024-01-12 3:16 ` Alistair Francis
18 siblings, 1 reply; 25+ messages in thread
From: Daniel Henrique Barboza @ 2024-01-05 23:05 UTC (permalink / raw)
To: qemu-devel
Cc: qemu-riscv, alistair.francis, bmeng, liwei1518, zhiwei_liu,
palmer, ajones, Daniel Henrique Barboza
Keep all class properties in riscv_cpu_properties[].
Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
---
target/riscv/cpu.c | 110 +++++++++++++++++++++++----------------------
1 file changed, 57 insertions(+), 53 deletions(-)
diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
index 6149f5960e..3870c3a433 100644
--- a/target/riscv/cpu.c
+++ b/target/riscv/cpu.c
@@ -2044,6 +2044,62 @@ static const PropertyInfo prop_mimpid = {
.set = prop_mimpid_set,
};
+static void prop_marchid_set(Object *obj, Visitor *v, const char *name,
+ void *opaque, Error **errp)
+{
+ bool dynamic_cpu = riscv_cpu_is_dynamic(obj);
+ RISCVCPU *cpu = RISCV_CPU(obj);
+ uint64_t prev_val = cpu->cfg.marchid;
+ uint64_t value, invalid_val;
+ uint32_t mxlen = 0;
+
+ if (!visit_type_uint64(v, name, &value, errp)) {
+ return;
+ }
+
+ if (!dynamic_cpu && prev_val != value) {
+ error_setg(errp, "Unable to change %s marchid (0x%" PRIu64 ")",
+ object_get_typename(obj), prev_val);
+ return;
+ }
+
+ switch (riscv_cpu_mxl(&cpu->env)) {
+ case MXL_RV32:
+ mxlen = 32;
+ break;
+ case MXL_RV64:
+ case MXL_RV128:
+ mxlen = 64;
+ break;
+ default:
+ g_assert_not_reached();
+ }
+
+ invalid_val = 1LL << (mxlen - 1);
+
+ if (value == invalid_val) {
+ error_setg(errp, "Unable to set marchid with MSB (%u) bit set "
+ "and the remaining bits zero", mxlen);
+ return;
+ }
+
+ cpu->cfg.marchid = value;
+}
+
+static void prop_marchid_get(Object *obj, Visitor *v, const char *name,
+ void *opaque, Error **errp)
+{
+ uint64_t value = RISCV_CPU(obj)->cfg.marchid;
+
+ visit_type_uint64(v, name, &value, errp);
+}
+
+static const PropertyInfo prop_marchid = {
+ .name = "marchid",
+ .get = prop_marchid_get,
+ .set = prop_marchid_set,
+};
+
/*
* RVA22U64 defines some 'named features' or 'synthetic extensions'
* that are cache related: Za64rs, Zic64b, Ziccif, Ziccrse, Ziccamoa
@@ -2132,6 +2188,7 @@ static Property riscv_cpu_properties[] = {
{.name = "mvendorid", .info = &prop_mvendorid},
{.name = "mimpid", .info = &prop_mimpid},
+ {.name = "marchid", .info = &prop_marchid},
#ifndef CONFIG_USER_ONLY
DEFINE_PROP_UINT64("resetvec", RISCVCPU, env.resetvec, DEFAULT_RSTVEC),
@@ -2213,56 +2270,6 @@ static const struct SysemuCPUOps riscv_sysemu_ops = {
};
#endif
-static void cpu_set_marchid(Object *obj, Visitor *v, const char *name,
- void *opaque, Error **errp)
-{
- bool dynamic_cpu = riscv_cpu_is_dynamic(obj);
- RISCVCPU *cpu = RISCV_CPU(obj);
- uint64_t prev_val = cpu->cfg.marchid;
- uint64_t value, invalid_val;
- uint32_t mxlen = 0;
-
- if (!visit_type_uint64(v, name, &value, errp)) {
- return;
- }
-
- if (!dynamic_cpu && prev_val != value) {
- error_setg(errp, "Unable to change %s marchid (0x%" PRIu64 ")",
- object_get_typename(obj), prev_val);
- return;
- }
-
- switch (riscv_cpu_mxl(&cpu->env)) {
- case MXL_RV32:
- mxlen = 32;
- break;
- case MXL_RV64:
- case MXL_RV128:
- mxlen = 64;
- break;
- default:
- g_assert_not_reached();
- }
-
- invalid_val = 1LL << (mxlen - 1);
-
- if (value == invalid_val) {
- error_setg(errp, "Unable to set marchid with MSB (%u) bit set "
- "and the remaining bits zero", mxlen);
- return;
- }
-
- cpu->cfg.marchid = value;
-}
-
-static void cpu_get_marchid(Object *obj, Visitor *v, const char *name,
- void *opaque, Error **errp)
-{
- uint64_t value = RISCV_CPU(obj)->cfg.marchid;
-
- visit_type_uint64(v, name, &value, errp);
-}
-
static void riscv_cpu_class_init(ObjectClass *c, void *data)
{
RISCVCPUClass *mcc = RISCV_CPU_CLASS(c);
@@ -2293,9 +2300,6 @@ static void riscv_cpu_class_init(ObjectClass *c, void *data)
cc->gdb_arch_name = riscv_gdb_arch_name;
cc->gdb_get_dynamic_xml = riscv_gdb_get_dynamic_xml;
- object_class_property_add(c, "marchid", "uint64", cpu_get_marchid,
- cpu_set_marchid, NULL, NULL);
-
device_class_set_props(dc, riscv_cpu_properties);
}
--
2.43.0
^ permalink raw reply related [flat|nested] 25+ messages in thread
* Re: [PATCH v4 00/17] target/riscv: deprecate riscv_cpu_options[]
2024-01-05 23:05 [PATCH v4 00/17] target/riscv: deprecate riscv_cpu_options[] Daniel Henrique Barboza
` (16 preceding siblings ...)
2024-01-05 23:05 ` [PATCH v4 17/17] target/riscv/cpu.c: move 'marchid' " Daniel Henrique Barboza
@ 2024-01-09 16:35 ` Vladimir Isaev
2024-01-12 3:16 ` Alistair Francis
18 siblings, 0 replies; 25+ messages in thread
From: Vladimir Isaev @ 2024-01-09 16:35 UTC (permalink / raw)
To: Daniel Henrique Barboza, qemu-devel
Cc: qemu-riscv, alistair.francis, bmeng, liwei1518, zhiwei_liu,
palmer, ajones
Hi Daniel,
06.01.2024 02:05, Daniel Henrique Barboza wrote:
>
> Hi,
>
> This new version contains changes due to a rebase with current
> riscv-to-apply.next, after "[PATCH v13 00/26] riscv: RVA22 profiles
> support" was queued.
>
> Most notable change is a new patch (12) that was added to handle
> 'cbop_blocksize' - zicbop was added by the profile work that just got
> queued and was missing from v3.
>
> A wrong 'cbom_blocksize' reference in patch 10 was also fixed.
>
> Patches based on Alistair's riscv-to-apply.next.
>
> Patches missing acks: 10, 12, 15, 16, 17
>
> Changes from v3:
> - patch 10:
> - changed wrong cbom_blocksize ref to cboz_blocksize
> - patch 12 (new):
> - move cbop_blocksize to riscv_cpu_properties[]
> - v3 link: https://lore.kernel.org/qemu-riscv/20240103174013.147279-1-dbarboza@ventanamicro.com/
>
>
This series work fine in my tests as well, thank you! (sorry for the delay)
TCG part:
Tested-by: Vladimir Isaev <vladimir.isaev@syntacore.com>
> Daniel Henrique Barboza (17):
> target/riscv/cpu_cfg.h: remove unused fields
> target/riscv: make riscv_cpu_is_vendor() public
> target/riscv: move 'pmu-mask' and 'pmu-num' to riscv_cpu_properties[]
> target/riscv: move 'mmu' to riscv_cpu_properties[]
> target/riscv: move 'pmp' to riscv_cpu_properties[]
> target/riscv: rework 'priv_spec'
> target/riscv: rework 'vext_spec'
> target/riscv: move 'vlen' to riscv_cpu_properties[]
> target/riscv: move 'elen' to riscv_cpu_properties[]
> target/riscv: create finalize_features() for KVM
> target/riscv: move 'cbom_blocksize' to riscv_cpu_properties[]
> target/riscv: move 'cbop_blocksize' to riscv_cpu_properties[]
> target/riscv: move 'cboz_blocksize' to riscv_cpu_properties[]
> target/riscv: remove riscv_cpu_options[]
> target/riscv/cpu.c: move 'mvendorid' to riscv_cpu_properties[]
> target/riscv/cpu.c: move 'mimpid' to riscv_cpu_properties[]
> target/riscv/cpu.c: move 'marchid' to riscv_cpu_properties[]
>
> target/riscv/cpu.c | 755 ++++++++++++++++++++++++++++-------
> target/riscv/cpu.h | 8 +-
> target/riscv/cpu_cfg.h | 4 -
> target/riscv/kvm/kvm-cpu.c | 94 +++--
> target/riscv/kvm/kvm_riscv.h | 1 +
> target/riscv/tcg/tcg-cpu.c | 63 ---
> 6 files changed, 676 insertions(+), 249 deletions(-)
>
> --
> 2.43.0
>
>
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH v4 10/17] target/riscv: create finalize_features() for KVM
2024-01-05 23:05 ` [PATCH v4 10/17] target/riscv: create finalize_features() for KVM Daniel Henrique Barboza
@ 2024-01-11 23:33 ` Alistair Francis
0 siblings, 0 replies; 25+ messages in thread
From: Alistair Francis @ 2024-01-11 23:33 UTC (permalink / raw)
To: Daniel Henrique Barboza
Cc: qemu-devel, qemu-riscv, alistair.francis, bmeng, liwei1518,
zhiwei_liu, palmer, ajones
On Sat, Jan 6, 2024 at 10:09 AM Daniel Henrique Barboza
<dbarboza@ventanamicro.com> wrote:
>
> To turn cbom_blocksize and cboz_blocksize into class properties we need
> KVM specific changes.
>
> KVM is creating its own version of these options with a customized
> setter() that prevents users from picking an invalid value during init()
> time. This comes at the cost of duplicating each option that KVM
> supports. This will keep happening for each new shared option KVM
> implements in the future.
>
> We can avoid that by using the same property TCG uses and adding
> specific KVM handling during finalize() time, like TCG already does with
> riscv_tcg_cpu_finalize_features(). To do that, the common CPU property
> offers a way of knowing if an option was user set or not, sparing us
> from doing unneeded syscalls.
>
> riscv_kvm_cpu_finalize_features() is then created using the same
> KVMScratch CPU we already use during init() time, since finalize() time
> is still too early to use the official KVM CPU for it. cbom_blocksize
> and cboz_blocksize are then handled during finalize() in the same way
> they're handled by their KVM specific setter.
>
> With this change we can proceed with the blocksize changes in the common
> code without breaking the KVM driver.
>
> Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Alistair
> ---
> target/riscv/cpu.c | 16 +++++++---
> target/riscv/cpu.h | 1 +
> target/riscv/kvm/kvm-cpu.c | 59 ++++++++++++++++++++++++++++++++++++
> target/riscv/kvm/kvm_riscv.h | 1 +
> 4 files changed, 72 insertions(+), 5 deletions(-)
>
> diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
> index 2bb4828324..cd91966ea7 100644
> --- a/target/riscv/cpu.c
> +++ b/target/riscv/cpu.c
> @@ -68,6 +68,11 @@ static void cpu_option_add_user_setting(const char *optname, uint32_t value)
> GUINT_TO_POINTER(value));
> }
>
> +bool riscv_cpu_option_set(const char *optname)
> +{
> + return g_hash_table_contains(general_user_opts, optname);
> +}
> +
> #define ISA_EXT_DATA_ENTRY(_name, _min_ver, _prop) \
> {#_name, _min_ver, CPU_CFG_OFFSET(_prop)}
>
> @@ -1104,17 +1109,18 @@ void riscv_cpu_finalize_features(RISCVCPU *cpu, Error **errp)
> }
> #endif
>
> - /*
> - * KVM accel does not have a specialized finalize()
> - * callback because its extensions are validated
> - * in the get()/set() callbacks of each property.
> - */
> if (tcg_enabled()) {
> riscv_tcg_cpu_finalize_features(cpu, &local_err);
> if (local_err != NULL) {
> error_propagate(errp, local_err);
> return;
> }
> + } else if (kvm_enabled()) {
> + riscv_kvm_cpu_finalize_features(cpu, &local_err);
> + if (local_err != NULL) {
> + error_propagate(errp, local_err);
> + return;
> + }
> }
> }
>
> diff --git a/target/riscv/cpu.h b/target/riscv/cpu.h
> index 3cec85069f..1c19fa84bb 100644
> --- a/target/riscv/cpu.h
> +++ b/target/riscv/cpu.h
> @@ -510,6 +510,7 @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, int size,
> bool probe, uintptr_t retaddr);
> char *riscv_isa_string(RISCVCPU *cpu);
> void riscv_cpu_list(void);
> +bool riscv_cpu_option_set(const char *optname);
>
> #define cpu_list riscv_cpu_list
> #define cpu_mmu_index riscv_cpu_mmu_index
> diff --git a/target/riscv/kvm/kvm-cpu.c b/target/riscv/kvm/kvm-cpu.c
> index 2c5217102c..2713f4b2ba 100644
> --- a/target/riscv/kvm/kvm-cpu.c
> +++ b/target/riscv/kvm/kvm-cpu.c
> @@ -1493,6 +1493,65 @@ static void kvm_cpu_instance_init(CPUState *cs)
> }
> }
>
> +void riscv_kvm_cpu_finalize_features(RISCVCPU *cpu, Error **errp)
> +{
> + CPURISCVState *env = &cpu->env;
> + KVMScratchCPU kvmcpu;
> + struct kvm_one_reg reg;
> + uint64_t val;
> + int ret;
> +
> + /* short-circuit without spinning the scratch CPU */
> + if (!cpu->cfg.ext_zicbom && !cpu->cfg.ext_zicboz) {
> + return;
> + }
> +
> + if (!kvm_riscv_create_scratch_vcpu(&kvmcpu)) {
> + error_setg(errp, "Unable to create scratch KVM cpu");
> + return;
> + }
> +
> + if (cpu->cfg.ext_zicbom &&
> + riscv_cpu_option_set(kvm_cbom_blocksize.name)) {
> +
> + reg.id = kvm_riscv_reg_id_ulong(env, KVM_REG_RISCV_CONFIG,
> + kvm_cbom_blocksize.kvm_reg_id);
> + reg.addr = (uint64_t)&val;
> + ret = ioctl(kvmcpu.cpufd, KVM_GET_ONE_REG, ®);
> + if (ret != 0) {
> + error_setg(errp, "Unable to read cbom_blocksize, error %d", errno);
> + return;
> + }
> +
> + if (cpu->cfg.cbom_blocksize != val) {
> + error_setg(errp, "Unable to set cbom_blocksize to a different "
> + "value than the host (%lu)", val);
> + return;
> + }
> + }
> +
> + if (cpu->cfg.ext_zicboz &&
> + riscv_cpu_option_set(kvm_cboz_blocksize.name)) {
> +
> + reg.id = kvm_riscv_reg_id_ulong(env, KVM_REG_RISCV_CONFIG,
> + kvm_cboz_blocksize.kvm_reg_id);
> + reg.addr = (uint64_t)&val;
> + ret = ioctl(kvmcpu.cpufd, KVM_GET_ONE_REG, ®);
> + if (ret != 0) {
> + error_setg(errp, "Unable to read cboz_blocksize, error %d", errno);
> + return;
> + }
> +
> + if (cpu->cfg.cboz_blocksize != val) {
> + error_setg(errp, "Unable to set cboz_blocksize to a different "
> + "value than the host (%lu)", val);
> + return;
> + }
> + }
> +
> + kvm_riscv_destroy_scratch_vcpu(&kvmcpu);
> +}
> +
> static void kvm_cpu_accel_class_init(ObjectClass *oc, void *data)
> {
> AccelCPUClass *acc = ACCEL_CPU_CLASS(oc);
> diff --git a/target/riscv/kvm/kvm_riscv.h b/target/riscv/kvm/kvm_riscv.h
> index 8329cfab82..4bd98fddc7 100644
> --- a/target/riscv/kvm/kvm_riscv.h
> +++ b/target/riscv/kvm/kvm_riscv.h
> @@ -27,5 +27,6 @@ void kvm_riscv_aia_create(MachineState *machine, uint64_t group_shift,
> uint64_t guest_num);
> void riscv_kvm_aplic_request(void *opaque, int irq, int level);
> int kvm_riscv_sync_mpstate_to_kvm(RISCVCPU *cpu, int state);
> +void riscv_kvm_cpu_finalize_features(RISCVCPU *cpu, Error **errp);
>
> #endif
> --
> 2.43.0
>
>
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH v4 12/17] target/riscv: move 'cbop_blocksize' to riscv_cpu_properties[]
2024-01-05 23:05 ` [PATCH v4 12/17] target/riscv: move 'cbop_blocksize' " Daniel Henrique Barboza
@ 2024-01-11 23:44 ` Alistair Francis
0 siblings, 0 replies; 25+ messages in thread
From: Alistair Francis @ 2024-01-11 23:44 UTC (permalink / raw)
To: Daniel Henrique Barboza
Cc: qemu-devel, qemu-riscv, alistair.francis, bmeng, liwei1518,
zhiwei_liu, palmer, ajones
On Sat, Jan 6, 2024 at 9:09 AM Daniel Henrique Barboza
<dbarboza@ventanamicro.com> wrote:
>
> Do the same we did with 'cbom_blocksize' in the previous patch.
>
> Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Alistair
> ---
> target/riscv/cpu.c | 38 +++++++++++++++++++++++++++++++++++++-
> 1 file changed, 37 insertions(+), 1 deletion(-)
>
> diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
> index b77d26231c..e3cbe9b1b6 100644
> --- a/target/riscv/cpu.c
> +++ b/target/riscv/cpu.c
> @@ -1317,6 +1317,7 @@ static void riscv_cpu_init(Object *obj)
> cpu->cfg.vlen = 128;
> cpu->cfg.elen = 64;
> cpu->cfg.cbom_blocksize = 64;
> + cpu->cfg.cbop_blocksize = 64;
> cpu->env.vext_ver = VEXT_VERSION_1_00_0;
> }
>
> @@ -1902,8 +1903,42 @@ static const PropertyInfo prop_cbom_blksize = {
> .set = prop_cbom_blksize_set,
> };
>
> +static void prop_cbop_blksize_set(Object *obj, Visitor *v, const char *name,
> + void *opaque, Error **errp)
> +{
> + RISCVCPU *cpu = RISCV_CPU(obj);
> + uint16_t value;
> +
> + if (!visit_type_uint16(v, name, &value, errp)) {
> + return;
> + }
> +
> + if (value != cpu->cfg.cbop_blocksize && riscv_cpu_is_vendor(obj)) {
> + cpu_set_prop_err(cpu, name, errp);
> + error_append_hint(errp, "Current '%s' val: %u\n",
> + name, cpu->cfg.cbop_blocksize);
> + return;
> + }
> +
> + cpu_option_add_user_setting(name, value);
> + cpu->cfg.cbop_blocksize = value;
> +}
> +
> +static void prop_cbop_blksize_get(Object *obj, Visitor *v, const char *name,
> + void *opaque, Error **errp)
> +{
> + uint16_t value = RISCV_CPU(obj)->cfg.cbop_blocksize;
> +
> + visit_type_uint16(v, name, &value, errp);
> +}
> +
> +static const PropertyInfo prop_cbop_blksize = {
> + .name = "cbop_blocksize",
> + .get = prop_cbop_blksize_get,
> + .set = prop_cbop_blksize_set,
> +};
> +
> Property riscv_cpu_options[] = {
> - DEFINE_PROP_UINT16("cbop_blocksize", RISCVCPU, cfg.cbop_blocksize, 64),
> DEFINE_PROP_UINT16("cboz_blocksize", RISCVCPU, cfg.cboz_blocksize, 64),
>
> DEFINE_PROP_END_OF_LIST(),
> @@ -1992,6 +2027,7 @@ static Property riscv_cpu_properties[] = {
> {.name = "elen", .info = &prop_elen},
>
> {.name = "cbom_blocksize", .info = &prop_cbom_blksize},
> + {.name = "cbop_blocksize", .info = &prop_cbop_blksize},
>
> #ifndef CONFIG_USER_ONLY
> DEFINE_PROP_UINT64("resetvec", RISCVCPU, env.resetvec, DEFAULT_RSTVEC),
> --
> 2.43.0
>
>
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH v4 15/17] target/riscv/cpu.c: move 'mvendorid' to riscv_cpu_properties[]
2024-01-05 23:05 ` [PATCH v4 15/17] target/riscv/cpu.c: move 'mvendorid' to riscv_cpu_properties[] Daniel Henrique Barboza
@ 2024-01-12 1:24 ` Alistair Francis
0 siblings, 0 replies; 25+ messages in thread
From: Alistair Francis @ 2024-01-12 1:24 UTC (permalink / raw)
To: Daniel Henrique Barboza
Cc: qemu-devel, qemu-riscv, alistair.francis, bmeng, liwei1518,
zhiwei_liu, palmer, ajones
On Sat, Jan 6, 2024 at 9:09 AM Daniel Henrique Barboza
<dbarboza@ventanamicro.com> wrote:
>
> Keep all class properties in riscv_cpu_properties[].
>
> Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Alistair
> ---
> target/riscv/cpu.c | 69 +++++++++++++++++++++++++---------------------
> 1 file changed, 37 insertions(+), 32 deletions(-)
>
> diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
> index 9d4243891c..c725a4839d 100644
> --- a/target/riscv/cpu.c
> +++ b/target/riscv/cpu.c
> @@ -1974,6 +1974,41 @@ static const PropertyInfo prop_cboz_blksize = {
> .set = prop_cboz_blksize_set,
> };
>
> +static void prop_mvendorid_set(Object *obj, Visitor *v, const char *name,
> + void *opaque, Error **errp)
> +{
> + bool dynamic_cpu = riscv_cpu_is_dynamic(obj);
> + RISCVCPU *cpu = RISCV_CPU(obj);
> + uint32_t prev_val = cpu->cfg.mvendorid;
> + uint32_t value;
> +
> + if (!visit_type_uint32(v, name, &value, errp)) {
> + return;
> + }
> +
> + if (!dynamic_cpu && prev_val != value) {
> + error_setg(errp, "Unable to change %s mvendorid (0x%x)",
> + object_get_typename(obj), prev_val);
> + return;
> + }
> +
> + cpu->cfg.mvendorid = value;
> +}
> +
> +static void prop_mvendorid_get(Object *obj, Visitor *v, const char *name,
> + void *opaque, Error **errp)
> +{
> + uint32_t value = RISCV_CPU(obj)->cfg.mvendorid;
> +
> + visit_type_uint32(v, name, &value, errp);
> +}
> +
> +static const PropertyInfo prop_mvendorid = {
> + .name = "mvendorid",
> + .get = prop_mvendorid_get,
> + .set = prop_mvendorid_set,
> +};
> +
> /*
> * RVA22U64 defines some 'named features' or 'synthetic extensions'
> * that are cache related: Za64rs, Zic64b, Ziccif, Ziccrse, Ziccamoa
> @@ -2060,6 +2095,8 @@ static Property riscv_cpu_properties[] = {
> {.name = "cbop_blocksize", .info = &prop_cbop_blksize},
> {.name = "cboz_blocksize", .info = &prop_cboz_blksize},
>
> + {.name = "mvendorid", .info = &prop_mvendorid},
> +
> #ifndef CONFIG_USER_ONLY
> DEFINE_PROP_UINT64("resetvec", RISCVCPU, env.resetvec, DEFAULT_RSTVEC),
> #endif
> @@ -2140,35 +2177,6 @@ static const struct SysemuCPUOps riscv_sysemu_ops = {
> };
> #endif
>
> -static void cpu_set_mvendorid(Object *obj, Visitor *v, const char *name,
> - void *opaque, Error **errp)
> -{
> - bool dynamic_cpu = riscv_cpu_is_dynamic(obj);
> - RISCVCPU *cpu = RISCV_CPU(obj);
> - uint32_t prev_val = cpu->cfg.mvendorid;
> - uint32_t value;
> -
> - if (!visit_type_uint32(v, name, &value, errp)) {
> - return;
> - }
> -
> - if (!dynamic_cpu && prev_val != value) {
> - error_setg(errp, "Unable to change %s mvendorid (0x%x)",
> - object_get_typename(obj), prev_val);
> - return;
> - }
> -
> - cpu->cfg.mvendorid = value;
> -}
> -
> -static void cpu_get_mvendorid(Object *obj, Visitor *v, const char *name,
> - void *opaque, Error **errp)
> -{
> - uint32_t value = RISCV_CPU(obj)->cfg.mvendorid;
> -
> - visit_type_uint32(v, name, &value, errp);
> -}
> -
> static void cpu_set_mimpid(Object *obj, Visitor *v, const char *name,
> void *opaque, Error **errp)
> {
> @@ -2278,9 +2286,6 @@ static void riscv_cpu_class_init(ObjectClass *c, void *data)
> cc->gdb_arch_name = riscv_gdb_arch_name;
> cc->gdb_get_dynamic_xml = riscv_gdb_get_dynamic_xml;
>
> - object_class_property_add(c, "mvendorid", "uint32", cpu_get_mvendorid,
> - cpu_set_mvendorid, NULL, NULL);
> -
> object_class_property_add(c, "mimpid", "uint64", cpu_get_mimpid,
> cpu_set_mimpid, NULL, NULL);
>
> --
> 2.43.0
>
>
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH v4 16/17] target/riscv/cpu.c: move 'mimpid' to riscv_cpu_properties[]
2024-01-05 23:05 ` [PATCH v4 16/17] target/riscv/cpu.c: move 'mimpid' " Daniel Henrique Barboza
@ 2024-01-12 1:29 ` Alistair Francis
0 siblings, 0 replies; 25+ messages in thread
From: Alistair Francis @ 2024-01-12 1:29 UTC (permalink / raw)
To: Daniel Henrique Barboza
Cc: qemu-devel, qemu-riscv, alistair.francis, bmeng, liwei1518,
zhiwei_liu, palmer, ajones
On Sat, Jan 6, 2024 at 9:07 AM Daniel Henrique Barboza
<dbarboza@ventanamicro.com> wrote:
>
> Keep all class properties in riscv_cpu_properties[].
>
> Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Alistair
> ---
> target/riscv/cpu.c | 68 ++++++++++++++++++++++++----------------------
> 1 file changed, 36 insertions(+), 32 deletions(-)
>
> diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
> index c725a4839d..6149f5960e 100644
> --- a/target/riscv/cpu.c
> +++ b/target/riscv/cpu.c
> @@ -2009,6 +2009,41 @@ static const PropertyInfo prop_mvendorid = {
> .set = prop_mvendorid_set,
> };
>
> +static void prop_mimpid_set(Object *obj, Visitor *v, const char *name,
> + void *opaque, Error **errp)
> +{
> + bool dynamic_cpu = riscv_cpu_is_dynamic(obj);
> + RISCVCPU *cpu = RISCV_CPU(obj);
> + uint64_t prev_val = cpu->cfg.mimpid;
> + uint64_t value;
> +
> + if (!visit_type_uint64(v, name, &value, errp)) {
> + return;
> + }
> +
> + if (!dynamic_cpu && prev_val != value) {
> + error_setg(errp, "Unable to change %s mimpid (0x%" PRIu64 ")",
> + object_get_typename(obj), prev_val);
> + return;
> + }
> +
> + cpu->cfg.mimpid = value;
> +}
> +
> +static void prop_mimpid_get(Object *obj, Visitor *v, const char *name,
> + void *opaque, Error **errp)
> +{
> + uint64_t value = RISCV_CPU(obj)->cfg.mimpid;
> +
> + visit_type_uint64(v, name, &value, errp);
> +}
> +
> +static const PropertyInfo prop_mimpid = {
> + .name = "mimpid",
> + .get = prop_mimpid_get,
> + .set = prop_mimpid_set,
> +};
> +
> /*
> * RVA22U64 defines some 'named features' or 'synthetic extensions'
> * that are cache related: Za64rs, Zic64b, Ziccif, Ziccrse, Ziccamoa
> @@ -2096,6 +2131,7 @@ static Property riscv_cpu_properties[] = {
> {.name = "cboz_blocksize", .info = &prop_cboz_blksize},
>
> {.name = "mvendorid", .info = &prop_mvendorid},
> + {.name = "mimpid", .info = &prop_mimpid},
>
> #ifndef CONFIG_USER_ONLY
> DEFINE_PROP_UINT64("resetvec", RISCVCPU, env.resetvec, DEFAULT_RSTVEC),
> @@ -2177,35 +2213,6 @@ static const struct SysemuCPUOps riscv_sysemu_ops = {
> };
> #endif
>
> -static void cpu_set_mimpid(Object *obj, Visitor *v, const char *name,
> - void *opaque, Error **errp)
> -{
> - bool dynamic_cpu = riscv_cpu_is_dynamic(obj);
> - RISCVCPU *cpu = RISCV_CPU(obj);
> - uint64_t prev_val = cpu->cfg.mimpid;
> - uint64_t value;
> -
> - if (!visit_type_uint64(v, name, &value, errp)) {
> - return;
> - }
> -
> - if (!dynamic_cpu && prev_val != value) {
> - error_setg(errp, "Unable to change %s mimpid (0x%" PRIu64 ")",
> - object_get_typename(obj), prev_val);
> - return;
> - }
> -
> - cpu->cfg.mimpid = value;
> -}
> -
> -static void cpu_get_mimpid(Object *obj, Visitor *v, const char *name,
> - void *opaque, Error **errp)
> -{
> - uint64_t value = RISCV_CPU(obj)->cfg.mimpid;
> -
> - visit_type_uint64(v, name, &value, errp);
> -}
> -
> static void cpu_set_marchid(Object *obj, Visitor *v, const char *name,
> void *opaque, Error **errp)
> {
> @@ -2286,9 +2293,6 @@ static void riscv_cpu_class_init(ObjectClass *c, void *data)
> cc->gdb_arch_name = riscv_gdb_arch_name;
> cc->gdb_get_dynamic_xml = riscv_gdb_get_dynamic_xml;
>
> - object_class_property_add(c, "mimpid", "uint64", cpu_get_mimpid,
> - cpu_set_mimpid, NULL, NULL);
> -
> object_class_property_add(c, "marchid", "uint64", cpu_get_marchid,
> cpu_set_marchid, NULL, NULL);
>
> --
> 2.43.0
>
>
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH v4 17/17] target/riscv/cpu.c: move 'marchid' to riscv_cpu_properties[]
2024-01-05 23:05 ` [PATCH v4 17/17] target/riscv/cpu.c: move 'marchid' " Daniel Henrique Barboza
@ 2024-01-12 1:37 ` Alistair Francis
0 siblings, 0 replies; 25+ messages in thread
From: Alistair Francis @ 2024-01-12 1:37 UTC (permalink / raw)
To: Daniel Henrique Barboza
Cc: qemu-devel, qemu-riscv, alistair.francis, bmeng, liwei1518,
zhiwei_liu, palmer, ajones
On Sat, Jan 6, 2024 at 9:09 AM Daniel Henrique Barboza
<dbarboza@ventanamicro.com> wrote:
>
> Keep all class properties in riscv_cpu_properties[].
>
> Signed-off-by: Daniel Henrique Barboza <dbarboza@ventanamicro.com>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Alistair
> ---
> target/riscv/cpu.c | 110 +++++++++++++++++++++++----------------------
> 1 file changed, 57 insertions(+), 53 deletions(-)
>
> diff --git a/target/riscv/cpu.c b/target/riscv/cpu.c
> index 6149f5960e..3870c3a433 100644
> --- a/target/riscv/cpu.c
> +++ b/target/riscv/cpu.c
> @@ -2044,6 +2044,62 @@ static const PropertyInfo prop_mimpid = {
> .set = prop_mimpid_set,
> };
>
> +static void prop_marchid_set(Object *obj, Visitor *v, const char *name,
> + void *opaque, Error **errp)
> +{
> + bool dynamic_cpu = riscv_cpu_is_dynamic(obj);
> + RISCVCPU *cpu = RISCV_CPU(obj);
> + uint64_t prev_val = cpu->cfg.marchid;
> + uint64_t value, invalid_val;
> + uint32_t mxlen = 0;
> +
> + if (!visit_type_uint64(v, name, &value, errp)) {
> + return;
> + }
> +
> + if (!dynamic_cpu && prev_val != value) {
> + error_setg(errp, "Unable to change %s marchid (0x%" PRIu64 ")",
> + object_get_typename(obj), prev_val);
> + return;
> + }
> +
> + switch (riscv_cpu_mxl(&cpu->env)) {
> + case MXL_RV32:
> + mxlen = 32;
> + break;
> + case MXL_RV64:
> + case MXL_RV128:
> + mxlen = 64;
> + break;
> + default:
> + g_assert_not_reached();
> + }
> +
> + invalid_val = 1LL << (mxlen - 1);
> +
> + if (value == invalid_val) {
> + error_setg(errp, "Unable to set marchid with MSB (%u) bit set "
> + "and the remaining bits zero", mxlen);
> + return;
> + }
> +
> + cpu->cfg.marchid = value;
> +}
> +
> +static void prop_marchid_get(Object *obj, Visitor *v, const char *name,
> + void *opaque, Error **errp)
> +{
> + uint64_t value = RISCV_CPU(obj)->cfg.marchid;
> +
> + visit_type_uint64(v, name, &value, errp);
> +}
> +
> +static const PropertyInfo prop_marchid = {
> + .name = "marchid",
> + .get = prop_marchid_get,
> + .set = prop_marchid_set,
> +};
> +
> /*
> * RVA22U64 defines some 'named features' or 'synthetic extensions'
> * that are cache related: Za64rs, Zic64b, Ziccif, Ziccrse, Ziccamoa
> @@ -2132,6 +2188,7 @@ static Property riscv_cpu_properties[] = {
>
> {.name = "mvendorid", .info = &prop_mvendorid},
> {.name = "mimpid", .info = &prop_mimpid},
> + {.name = "marchid", .info = &prop_marchid},
>
> #ifndef CONFIG_USER_ONLY
> DEFINE_PROP_UINT64("resetvec", RISCVCPU, env.resetvec, DEFAULT_RSTVEC),
> @@ -2213,56 +2270,6 @@ static const struct SysemuCPUOps riscv_sysemu_ops = {
> };
> #endif
>
> -static void cpu_set_marchid(Object *obj, Visitor *v, const char *name,
> - void *opaque, Error **errp)
> -{
> - bool dynamic_cpu = riscv_cpu_is_dynamic(obj);
> - RISCVCPU *cpu = RISCV_CPU(obj);
> - uint64_t prev_val = cpu->cfg.marchid;
> - uint64_t value, invalid_val;
> - uint32_t mxlen = 0;
> -
> - if (!visit_type_uint64(v, name, &value, errp)) {
> - return;
> - }
> -
> - if (!dynamic_cpu && prev_val != value) {
> - error_setg(errp, "Unable to change %s marchid (0x%" PRIu64 ")",
> - object_get_typename(obj), prev_val);
> - return;
> - }
> -
> - switch (riscv_cpu_mxl(&cpu->env)) {
> - case MXL_RV32:
> - mxlen = 32;
> - break;
> - case MXL_RV64:
> - case MXL_RV128:
> - mxlen = 64;
> - break;
> - default:
> - g_assert_not_reached();
> - }
> -
> - invalid_val = 1LL << (mxlen - 1);
> -
> - if (value == invalid_val) {
> - error_setg(errp, "Unable to set marchid with MSB (%u) bit set "
> - "and the remaining bits zero", mxlen);
> - return;
> - }
> -
> - cpu->cfg.marchid = value;
> -}
> -
> -static void cpu_get_marchid(Object *obj, Visitor *v, const char *name,
> - void *opaque, Error **errp)
> -{
> - uint64_t value = RISCV_CPU(obj)->cfg.marchid;
> -
> - visit_type_uint64(v, name, &value, errp);
> -}
> -
> static void riscv_cpu_class_init(ObjectClass *c, void *data)
> {
> RISCVCPUClass *mcc = RISCV_CPU_CLASS(c);
> @@ -2293,9 +2300,6 @@ static void riscv_cpu_class_init(ObjectClass *c, void *data)
> cc->gdb_arch_name = riscv_gdb_arch_name;
> cc->gdb_get_dynamic_xml = riscv_gdb_get_dynamic_xml;
>
> - object_class_property_add(c, "marchid", "uint64", cpu_get_marchid,
> - cpu_set_marchid, NULL, NULL);
> -
> device_class_set_props(dc, riscv_cpu_properties);
> }
>
> --
> 2.43.0
>
>
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: [PATCH v4 00/17] target/riscv: deprecate riscv_cpu_options[]
2024-01-05 23:05 [PATCH v4 00/17] target/riscv: deprecate riscv_cpu_options[] Daniel Henrique Barboza
` (17 preceding siblings ...)
2024-01-09 16:35 ` [PATCH v4 00/17] target/riscv: deprecate riscv_cpu_options[] Vladimir Isaev
@ 2024-01-12 3:16 ` Alistair Francis
18 siblings, 0 replies; 25+ messages in thread
From: Alistair Francis @ 2024-01-12 3:16 UTC (permalink / raw)
To: Daniel Henrique Barboza
Cc: qemu-devel, qemu-riscv, alistair.francis, bmeng, liwei1518,
zhiwei_liu, palmer, ajones
On Sat, Jan 6, 2024 at 9:07 AM Daniel Henrique Barboza
<dbarboza@ventanamicro.com> wrote:
>
> Hi,
>
> This new version contains changes due to a rebase with current
> riscv-to-apply.next, after "[PATCH v13 00/26] riscv: RVA22 profiles
> support" was queued.
>
> Most notable change is a new patch (12) that was added to handle
> 'cbop_blocksize' - zicbop was added by the profile work that just got
> queued and was missing from v3.
>
> A wrong 'cbom_blocksize' reference in patch 10 was also fixed.
>
> Patches based on Alistair's riscv-to-apply.next.
>
> Patches missing acks: 10, 12, 15, 16, 17
>
> Changes from v3:
> - patch 10:
> - changed wrong cbom_blocksize ref to cboz_blocksize
> - patch 12 (new):
> - move cbop_blocksize to riscv_cpu_properties[]
> - v3 link: https://lore.kernel.org/qemu-riscv/20240103174013.147279-1-dbarboza@ventanamicro.com/
>
>
> Daniel Henrique Barboza (17):
> target/riscv/cpu_cfg.h: remove unused fields
> target/riscv: make riscv_cpu_is_vendor() public
> target/riscv: move 'pmu-mask' and 'pmu-num' to riscv_cpu_properties[]
> target/riscv: move 'mmu' to riscv_cpu_properties[]
> target/riscv: move 'pmp' to riscv_cpu_properties[]
> target/riscv: rework 'priv_spec'
> target/riscv: rework 'vext_spec'
> target/riscv: move 'vlen' to riscv_cpu_properties[]
> target/riscv: move 'elen' to riscv_cpu_properties[]
I've applied the first few patches to the RISC-V tree, the others
don't apply. Do you mind rebasing them and sending them again?
Alistair
> target/riscv: create finalize_features() for KVM
> target/riscv: move 'cbom_blocksize' to riscv_cpu_properties[]
> target/riscv: move 'cbop_blocksize' to riscv_cpu_properties[]
> target/riscv: move 'cboz_blocksize' to riscv_cpu_properties[]
> target/riscv: remove riscv_cpu_options[]
> target/riscv/cpu.c: move 'mvendorid' to riscv_cpu_properties[]
> target/riscv/cpu.c: move 'mimpid' to riscv_cpu_properties[]
> target/riscv/cpu.c: move 'marchid' to riscv_cpu_properties[]
>
> target/riscv/cpu.c | 755 ++++++++++++++++++++++++++++-------
> target/riscv/cpu.h | 8 +-
> target/riscv/cpu_cfg.h | 4 -
> target/riscv/kvm/kvm-cpu.c | 94 +++--
> target/riscv/kvm/kvm_riscv.h | 1 +
> target/riscv/tcg/tcg-cpu.c | 63 ---
> 6 files changed, 676 insertions(+), 249 deletions(-)
>
> --
> 2.43.0
>
>
^ permalink raw reply [flat|nested] 25+ messages in thread
end of thread, other threads:[~2024-01-12 3:18 UTC | newest]
Thread overview: 25+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-05 23:05 [PATCH v4 00/17] target/riscv: deprecate riscv_cpu_options[] Daniel Henrique Barboza
2024-01-05 23:05 ` [PATCH v4 01/17] target/riscv/cpu_cfg.h: remove unused fields Daniel Henrique Barboza
2024-01-05 23:05 ` [PATCH v4 02/17] target/riscv: make riscv_cpu_is_vendor() public Daniel Henrique Barboza
2024-01-05 23:05 ` [PATCH v4 03/17] target/riscv: move 'pmu-mask' and 'pmu-num' to riscv_cpu_properties[] Daniel Henrique Barboza
2024-01-05 23:05 ` [PATCH v4 04/17] target/riscv: move 'mmu' " Daniel Henrique Barboza
2024-01-05 23:05 ` [PATCH v4 05/17] target/riscv: move 'pmp' " Daniel Henrique Barboza
2024-01-05 23:05 ` [PATCH v4 06/17] target/riscv: rework 'priv_spec' Daniel Henrique Barboza
2024-01-05 23:05 ` [PATCH v4 07/17] target/riscv: rework 'vext_spec' Daniel Henrique Barboza
2024-01-05 23:05 ` [PATCH v4 08/17] target/riscv: move 'vlen' to riscv_cpu_properties[] Daniel Henrique Barboza
2024-01-05 23:05 ` [PATCH v4 09/17] target/riscv: move 'elen' " Daniel Henrique Barboza
2024-01-05 23:05 ` [PATCH v4 10/17] target/riscv: create finalize_features() for KVM Daniel Henrique Barboza
2024-01-11 23:33 ` Alistair Francis
2024-01-05 23:05 ` [PATCH v4 11/17] target/riscv: move 'cbom_blocksize' to riscv_cpu_properties[] Daniel Henrique Barboza
2024-01-05 23:05 ` [PATCH v4 12/17] target/riscv: move 'cbop_blocksize' " Daniel Henrique Barboza
2024-01-11 23:44 ` Alistair Francis
2024-01-05 23:05 ` [PATCH v4 13/17] target/riscv: move 'cboz_blocksize' " Daniel Henrique Barboza
2024-01-05 23:05 ` [PATCH v4 14/17] target/riscv: remove riscv_cpu_options[] Daniel Henrique Barboza
2024-01-05 23:05 ` [PATCH v4 15/17] target/riscv/cpu.c: move 'mvendorid' to riscv_cpu_properties[] Daniel Henrique Barboza
2024-01-12 1:24 ` Alistair Francis
2024-01-05 23:05 ` [PATCH v4 16/17] target/riscv/cpu.c: move 'mimpid' " Daniel Henrique Barboza
2024-01-12 1:29 ` Alistair Francis
2024-01-05 23:05 ` [PATCH v4 17/17] target/riscv/cpu.c: move 'marchid' " Daniel Henrique Barboza
2024-01-12 1:37 ` Alistair Francis
2024-01-09 16:35 ` [PATCH v4 00/17] target/riscv: deprecate riscv_cpu_options[] Vladimir Isaev
2024-01-12 3:16 ` Alistair Francis
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).