target/riscv: add 'max' CPU, deprecate
v3 cover target/riscv: add 'max' CPU, deprecate
Hi,
This version has changes suggested in v2. The most significant change is the deprecation of the 'any' CPU in patch 8.
The reasoning behind it is that Alistair mentioned that the 'any' CPU intended to work like the newly added 'max' CPU, so we're better of removing the 'any' CPU since it'll be out of place. We can't just remove the CPU out of the gate so we'll have to make it do with deprecation first.
Patches missing review: 5,6,7,8
Changes from v2:
- patches 1, 3, 4:
- remove "DEFINE_PROP_END_OF_LIST()" at the end of each prop array;
- use ARRAY_SIZE() in the for loop
- patch 5:
- remove the trailing '/' in the last line of the macro
- wrap the macro in "do {} while (0)"
- patch 8 (new):
- deprecate the 'any' CPU
- v2 link: https://lore.kernel.org/qemu-riscv/[email protected]/
Daniel Henrique Barboza (8):
target/riscv/cpu.c: split CPU options from riscv_cpu_extensions[] target/riscv/cpu.c: skip 'bool' check when filtering KVM props target/riscv/cpu.c: split vendor exts from riscv_cpu_extensions[] target/riscv/cpu.c: split non-ratified exts from
riscv_cpu_extensions[]
target/riscv/cpu.c: add a ADD_CPU_PROPERTIES_ARRAY() macro target/riscv: add 'max' CPU type
avocado, risc-v: add opensbi tests for 'max' CPU target/riscv: deprecate the 'any' CPU type
docs/about/deprecated.rst | 12 ++++ target/riscv/cpu-qom.h | 1 + target/riscv/cpu.c | 114 ++++++++++++++++++++++++++------- tests/avocado/riscv_opensbi.py | 16 +++++ 4 files changed, 121 insertions(+), 22 deletions(-)
Signature · 1 line
2.41.0
PATCH v3 1/8 target/riscv/cpu.c: split CPU options from riscv_cpu_extensions[]
We'll add a new CPU type that will enable a considerable amount of extensions. To make it easier for us we'll do a few cleanups in our existing riscv_cpu_extensions[] array.
Start by splitting all CPU non-boolean options from it. Create a new riscv_cpu_options[] array for them. Add all these properties in riscv_cpu_add_user_properties() as it is already being done today.
No functional changes made.
--- target/riscv/cpu.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-)
target/riscv/cpu.c +16 -8
@@ -1751,7 +1751,6 @@ static void riscv_cpu_add_misa_properties(Object *cpu_obj)static Property riscv_cpu_extensions[] = {/* Defaults for standard extensions */ -DEFINE_PROP_UINT8 ("pmu-num" ,RISCVCPU , cfg.pmu_num,16 ),DEFINE_PROP_BOOL ("sscofpmf" ,RISCVCPU , cfg.ext_sscofpmf, false),DEFINE_PROP_BOOL ("Zifencei" ,RISCVCPU , cfg.ext_ifencei, true),DEFINE_PROP_BOOL ("Zicsr" ,RISCVCPU , cfg.ext_icsr, true),
@@ -1767,11 +1766,6 @@ static Property riscv_cpu_extensions[] = {DEFINE_PROP_BOOL ("pmp" ,RISCVCPU , cfg.pmp, true),DEFINE_PROP_BOOL ("sstc" ,RISCVCPU , cfg.ext_sstc, true), -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 ), -DEFINE_PROP_UINT16 ("elen" ,RISCVCPU , cfg.elen,64 ), -DEFINE_PROP_BOOL ("smstateen" ,RISCVCPU , cfg.ext_smstateen, false),DEFINE_PROP_BOOL ("svadu" ,RISCVCPU , cfg.ext_svadu, true), DEFINE_PROP_BOOL("svinval", RISCVCPU, cfg.ext_svinval, false),
@@ -1802,9 +1796,7 @@ static Property riscv_cpu_extensions[] = {DEFINE_PROP_BOOL ("zhinxmin" ,RISCVCPU , cfg.ext_zhinxmin, false),DEFINE_PROP_BOOL ("zicbom" ,RISCVCPU , cfg.ext_icbom, true), -DEFINE_PROP_UINT16 ("cbom_blocksize" ,RISCVCPU , cfg.cbom_blocksize,64 ),DEFINE_PROP_BOOL ("zicboz" ,RISCVCPU , cfg.ext_icboz, true), -DEFINE_PROP_UINT16 ("cboz_blocksize" ,RISCVCPU , cfg.cboz_blocksize,64 ), DEFINE_PROP_BOOL("zmmul", RISCVCPU, cfg.ext_zmmul, false),
@@ -1848,6 +1840,18 @@ static Property riscv_cpu_extensions[] = { DEFINE_PROP_END_OF_LIST(), }; +static Property riscv_cpu_options[] = { +DEFINE_PROP_UINT8 ("pmu-num" ,RISCVCPU , cfg.pmu_num,16 ), + +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 ), +DEFINE_PROP_UINT16 ("elen" ,RISCVCPU , cfg.elen,64 ), + +DEFINE_PROP_UINT16 ("cbom_blocksize" ,RISCVCPU , cfg.cbom_blocksize,64 ), +DEFINE_PROP_UINT16 ("cboz_blocksize" ,RISCVCPU , cfg.cboz_blocksize,64 ), +};#ifndef CONFIG_USER_ONLY static void cpu_set_cfg_unavailable(Object *obj, Visitor *v,
@@ -1916,6 +1920,10 @@ static void riscv_cpu_add_user_properties(Object *obj)#endif qdev_property_add_static (dev, prop); } + +for (int i =0 ; i <ARRAY_SIZE (riscv_cpu_options); i++) { +qdev_property_add_static (dev, &riscv_cpu_options[i]); + } }static Property riscv_cpu_properties[] = {
Signature · 1 line
2.41.0
PATCH v3 2/8 target/riscv/cpu.c: skip 'bool' check when filtering KVM props
In reply to Daniel Henrique BarbozaAfter the introduction of riscv_cpu_options[] all properties in riscv_cpu_extensions[] are booleans. This check is now obsolete.
--- target/riscv/cpu.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-)
target/riscv/cpu.c +4 -10
@@ -1905,17 +1905,11 @@ static void riscv_cpu_add_user_properties(Object *obj)* Set the default to disabled for every extension * unknown to KVM and error out if the user attempts * to enable any of them. -* -* We're giving a pass for non-bool properties since they're -* not related to the availability of extensions and can be -* safely ignored as is. */ -if (prop->info == &qdev_prop_bool) { -object_property_add (obj, prop->name,"bool" , -NULL , cpu_set_cfg_unavailable, -NULL , (void *)prop->name); -continue ; - } +object_property_add (obj, prop->name,"bool" , +NULL , cpu_set_cfg_unavailable, +NULL , (void *)prop->name); + continue; }#endif qdev_property_add_static (dev, prop);
Signature · 1 line
2.41.0
PATCH v3 3/8 target/riscv/cpu.c: split vendor exts from riscv_cpu_extensions[]
In reply to Daniel Henrique BarbozaOur goal is to make riscv_cpu_extensions[] hold only ratified, non-vendor extensions.
Create a new riscv_cpu_vendor_exts[] array for them, changing riscv_cpu_add_user_properties() accordingly.
--- target/riscv/cpu.c | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-)
target/riscv/cpu.c +19 -14
@@ -1808,20 +1808,6 @@ static Property riscv_cpu_extensions[] = {DEFINE_PROP_BOOL ("zcmp" ,RISCVCPU , cfg.ext_zcmp, false),DEFINE_PROP_BOOL ("zcmt" ,RISCVCPU , cfg.ext_zcmt, false), -/* Vendor-specific custom extensions */ -DEFINE_PROP_BOOL ("xtheadba" ,RISCVCPU , cfg.ext_xtheadba, false), -DEFINE_PROP_BOOL ("xtheadbb" ,RISCVCPU , cfg.ext_xtheadbb, false), -DEFINE_PROP_BOOL ("xtheadbs" ,RISCVCPU , cfg.ext_xtheadbs, false), -DEFINE_PROP_BOOL ("xtheadcmo" ,RISCVCPU , cfg.ext_xtheadcmo, false), -DEFINE_PROP_BOOL ("xtheadcondmov" ,RISCVCPU , cfg.ext_xtheadcondmov, false), -DEFINE_PROP_BOOL ("xtheadfmemidx" ,RISCVCPU , cfg.ext_xtheadfmemidx, false), -DEFINE_PROP_BOOL ("xtheadfmv" ,RISCVCPU , cfg.ext_xtheadfmv, false), -DEFINE_PROP_BOOL ("xtheadmac" ,RISCVCPU , cfg.ext_xtheadmac, false), -DEFINE_PROP_BOOL ("xtheadmemidx" ,RISCVCPU , cfg.ext_xtheadmemidx, false), -DEFINE_PROP_BOOL ("xtheadmempair" ,RISCVCPU , cfg.ext_xtheadmempair, false), -DEFINE_PROP_BOOL ("xtheadsync" ,RISCVCPU , cfg.ext_xtheadsync, false), -DEFINE_PROP_BOOL ("xventanacondops" ,RISCVCPU , cfg.ext_XVentanaCondOps, false), -/* These are experimental so mark with 'x-' */ DEFINE_PROP_BOOL("x-zicond", RISCVCPU, cfg.ext_zicond, false),
@@ -1840,6 +1826,21 @@ static Property riscv_cpu_extensions[] = { DEFINE_PROP_END_OF_LIST(), }; +static Property riscv_cpu_vendor_exts[] = { +DEFINE_PROP_BOOL ("xtheadba" ,RISCVCPU , cfg.ext_xtheadba, false), +DEFINE_PROP_BOOL ("xtheadbb" ,RISCVCPU , cfg.ext_xtheadbb, false), +DEFINE_PROP_BOOL ("xtheadbs" ,RISCVCPU , cfg.ext_xtheadbs, false), +DEFINE_PROP_BOOL ("xtheadcmo" ,RISCVCPU , cfg.ext_xtheadcmo, false), +DEFINE_PROP_BOOL ("xtheadcondmov" ,RISCVCPU , cfg.ext_xtheadcondmov, false), +DEFINE_PROP_BOOL ("xtheadfmemidx" ,RISCVCPU , cfg.ext_xtheadfmemidx, false), +DEFINE_PROP_BOOL ("xtheadfmv" ,RISCVCPU , cfg.ext_xtheadfmv, false), +DEFINE_PROP_BOOL ("xtheadmac" ,RISCVCPU , cfg.ext_xtheadmac, false), +DEFINE_PROP_BOOL ("xtheadmemidx" ,RISCVCPU , cfg.ext_xtheadmemidx, false), +DEFINE_PROP_BOOL ("xtheadmempair" ,RISCVCPU , cfg.ext_xtheadmempair, false), +DEFINE_PROP_BOOL ("xtheadsync" ,RISCVCPU , cfg.ext_xtheadsync, false), +DEFINE_PROP_BOOL ("xventanacondops" ,RISCVCPU , cfg.ext_XVentanaCondOps, false), +}; +static Property riscv_cpu_options[] = {DEFINE_PROP_UINT8 ("pmu-num" ,RISCVCPU , cfg.pmu_num,16 ),
@@ -1918,6 +1919,10 @@ static void riscv_cpu_add_user_properties(Object *obj)for (int i =0 ; i <ARRAY_SIZE (riscv_cpu_options); i++) {qdev_property_add_static (dev, &riscv_cpu_options[i]); } + +for (int i =0 ; i <ARRAY_SIZE (riscv_cpu_vendor_exts); i++) { +qdev_property_add_static (dev, &riscv_cpu_vendor_exts[i]); + } }static Property riscv_cpu_properties[] = {
Signature · 1 line
2.41.0
PATCH v3 4/8 target/riscv/cpu.c: split non-ratified exts from riscv_cpu_extensions[]
In reply to Daniel Henrique BarbozaCreate a new riscv_cpu_experimental_exts[] to store the non-ratified extensions properties. Once they are ratified we'll move them back to riscv_cpu_extensions[].
Change riscv_cpu_add_user_properties to keep adding them to users.
--- target/riscv/cpu.c | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-)
target/riscv/cpu.c +21 -15
@@ -1808,21 +1808,6 @@ static Property riscv_cpu_extensions[] = {DEFINE_PROP_BOOL ("zcmp" ,RISCVCPU , cfg.ext_zcmp, false),DEFINE_PROP_BOOL ("zcmt" ,RISCVCPU , cfg.ext_zcmt, false), -/* These are experimental so mark with 'x-' */ -DEFINE_PROP_BOOL ("x-zicond" ,RISCVCPU , cfg.ext_zicond, false), - -/* ePMP 0.9.3 */ -DEFINE_PROP_BOOL ("x-epmp" ,RISCVCPU , cfg.epmp, false), -DEFINE_PROP_BOOL ("x-smaia" ,RISCVCPU , cfg.ext_smaia, false), -DEFINE_PROP_BOOL ("x-ssaia" ,RISCVCPU , cfg.ext_ssaia, false), - -DEFINE_PROP_BOOL ("x-zvfh" ,RISCVCPU , cfg.ext_zvfh, false), -DEFINE_PROP_BOOL ("x-zvfhmin" ,RISCVCPU , cfg.ext_zvfhmin, false), - -DEFINE_PROP_BOOL ("x-zfbfmin" ,RISCVCPU , cfg.ext_zfbfmin, false), -DEFINE_PROP_BOOL ("x-zvfbfmin" ,RISCVCPU , cfg.ext_zvfbfmin, false), -DEFINE_PROP_BOOL ("x-zvfbfwma" ,RISCVCPU , cfg.ext_zvfbfwma, false), - DEFINE_PROP_END_OF_LIST(), };
@@ -1841,6 +1826,23 @@ static Property riscv_cpu_vendor_exts[] = { DEFINE_PROP_BOOL("xventanacondops", RISCVCPU, cfg.ext_XVentanaCondOps, false), }; +/* These are experimental so mark with 'x-' */ +static Property riscv_cpu_experimental_exts[] = { +DEFINE_PROP_BOOL ("x-zicond" ,RISCVCPU , cfg.ext_zicond, false), + +/* ePMP 0.9.3 */ +DEFINE_PROP_BOOL ("x-epmp" ,RISCVCPU , cfg.epmp, false), +DEFINE_PROP_BOOL ("x-smaia" ,RISCVCPU , cfg.ext_smaia, false), +DEFINE_PROP_BOOL ("x-ssaia" ,RISCVCPU , cfg.ext_ssaia, false), + +DEFINE_PROP_BOOL ("x-zvfh" ,RISCVCPU , cfg.ext_zvfh, false), +DEFINE_PROP_BOOL ("x-zvfhmin" ,RISCVCPU , cfg.ext_zvfhmin, false), + +DEFINE_PROP_BOOL ("x-zfbfmin" ,RISCVCPU , cfg.ext_zfbfmin, false), +DEFINE_PROP_BOOL ("x-zvfbfmin" ,RISCVCPU , cfg.ext_zvfbfmin, false), +DEFINE_PROP_BOOL ("x-zvfbfwma" ,RISCVCPU , cfg.ext_zvfbfwma, false), +}; +static Property riscv_cpu_options[] = {DEFINE_PROP_UINT8 ("pmu-num" ,RISCVCPU , cfg.pmu_num,16 ),
@@ -1923,6 +1925,10 @@ static void riscv_cpu_add_user_properties(Object *obj)for (int i =0 ; i <ARRAY_SIZE (riscv_cpu_vendor_exts); i++) {qdev_property_add_static (dev, &riscv_cpu_vendor_exts[i]); } + +for (int i =0 ; i <ARRAY_SIZE (riscv_cpu_experimental_exts); i++) { +qdev_property_add_static (dev, &riscv_cpu_experimental_exts[i]); + } }static Property riscv_cpu_properties[] = {
Signature · 1 line
2.41.0
PATCH v3 5/8 target/riscv/cpu.c: add a ADD_CPU_PROPERTIES_ARRAY() macro
In reply to Daniel Henrique BarbozaThe code inside riscv_cpu_add_user_properties() became quite repetitive after recent changes. Add a macro to hide the repetition away.
--- target/riscv/cpu.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-)
target/riscv/cpu.c +10 -11
@@ -1875,6 +1875,13 @@ static void cpu_set_cfg_unavailable(Object *obj, Visitor *v, }#endif +#define ADD_CPU_PROPERTIES_ARRAY (_dev, _array) \ + do { \ + for (int i = 0; i < ARRAY_SIZE(_array); i++) { \ + qdev_property_add_static(_dev, &_array[i]); \ + } \ + } while (0) +/* * Add CPU properties with user-facing flags. *
@@ -1918,17 +1925,9 @@ static void riscv_cpu_add_user_properties(Object *obj)qdev_property_add_static (dev, prop); } -for (int i =0 ; i <ARRAY_SIZE (riscv_cpu_options); i++) { -qdev_property_add_static (dev, &riscv_cpu_options[i]); - } - -for (int i =0 ; i <ARRAY_SIZE (riscv_cpu_vendor_exts); i++) { -qdev_property_add_static (dev, &riscv_cpu_vendor_exts[i]); - } - -for (int i =0 ; i <ARRAY_SIZE (riscv_cpu_experimental_exts); i++) { -qdev_property_add_static (dev, &riscv_cpu_experimental_exts[i]); - } +ADD_CPU_PROPERTIES_ARRAY (dev, riscv_cpu_options); +ADD_CPU_PROPERTIES_ARRAY (dev, riscv_cpu_vendor_exts); +ADD_CPU_PROPERTIES_ARRAY (dev, riscv_cpu_experimental_exts); }static Property riscv_cpu_properties[] = {
Signature · 1 line
2.41.0
Re: [PATCH for-8.2 v3 5/8] target/riscv/cpu.c: add a ADD_CPU_PROPERTIES_ARRAY() macro
Quoted 5 lines · Daniel Henrique Barboza
The code inside
riscv_cpu_add_user_properties()became quite repetitive after recent changes. Add a macro to hide the repetition away.Signed-off-by Daniel Henrique Barboza <[email protected]>---
Weiwei Li
Quoted 42 lines
target/riscv/cpu.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-)target/riscv/cpu.c +10
-11@@ -1875,6 +1875,13 @@ static void cpu_set_cfg_unavailable(Object *obj, Visitor *v, }#endif +#define ADD_CPU_PROPERTIES_ARRAY (_dev, _array) \ + do { \ + for (int i = 0; i < ARRAY_SIZE(_array); i++) { \ + qdev_property_add_static(_dev, &_array[i]); \ + } \ + } while (0) +/* * Add CPU properties with user-facing flags. * @@ -1918,17 +1925,9 @@ static void riscv_cpu_add_user_properties(Object *obj)qdev_property_add_static (dev, prop); } -for (int i =0 ; i <ARRAY_SIZE (riscv_cpu_options); i++) { -qdev_property_add_static (dev, &riscv_cpu_options[i]); - } - -for (int i =0 ; i <ARRAY_SIZE (riscv_cpu_vendor_exts); i++) { -qdev_property_add_static (dev, &riscv_cpu_vendor_exts[i]); - } - -for (int i =0 ; i <ARRAY_SIZE (riscv_cpu_experimental_exts); i++) { -qdev_property_add_static (dev, &riscv_cpu_experimental_exts[i]); - } +ADD_CPU_PROPERTIES_ARRAY (dev, riscv_cpu_options); +ADD_CPU_PROPERTIES_ARRAY (dev, riscv_cpu_vendor_exts); +ADD_CPU_PROPERTIES_ARRAY (dev, riscv_cpu_experimental_exts); }static Property riscv_cpu_properties[] = {
PATCH v3 6/8 target/riscv: add 'max' CPU type
In reply to Daniel Henrique BarbozaThe 'max' CPU type is used by tooling to determine what's the most capable CPU a current QEMU version implements. Other archs such as ARM implements this type. Let's add it to RISC-V.
What we consider "most capable CPU" in this context are related to ratified, non-vendor extensions. This means that we want the 'max' CPU to enable all (possible) ratified extensions by default. The reasoning behind this design is (1) vendor extensions can conflict with each other and we won't play favorities deciding which one is default or not and
(2) non-ratified extensions are always prone to changes, not being stable enough to be enabled by default.
All this said, we're still not able to enable all ratified extensions due to conflicts between them. Zfinx and all its dependencies aren't enabled because of a conflict with RVF. zce, zcmp and zcmt are also disabled due to RVD conflicts. When running with 64 bits we're also disabling zcf.
MISA bits RVG, RVJ and RVV are also being set manually since they're default disabled.
This is the resulting 'riscv,isa' DT for this new CPU:
rv64imafdcvh_zicbom_zicboz_zicsr_zifencei_zihintpause_zawrs_zfa_ zfh_zfhmin_zca_zcb_zcd_zba_zbb_zbc_zbkb_zbkc_zbkx_zbs_zk_zkn_zknd_ zkne_zknh_zkr_zks_zksed_zksh_zkt_zve32f_zve64f_zve64d_ smstateen_sscofpmf_sstc_svadu_svinval_svnapot_svpbmt
--- target/riscv/cpu-qom.h | 1 + target/riscv/cpu.c | 53 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+)
target/riscv/cpu-qom.h +1 -0
@@ -30,6 +30,7 @@#define CPU_RESOLVING_TYPE TYPE_RISCV_CPU#define TYPE_RISCV_CPU_ANY RISCV_CPU_TYPE_NAME("any") +#define TYPE_RISCV_CPU_MAX RISCV_CPU_TYPE_NAME("max")#define TYPE_RISCV_CPU_BASE32 RISCV_CPU_TYPE_NAME("rv32")#define TYPE_RISCV_CPU_BASE64 RISCV_CPU_TYPE_NAME("rv64")#define TYPE_RISCV_CPU_BASE128 RISCV_CPU_TYPE_NAME("x-rv128")
target/riscv/cpu.c +53 -0
77 lines not on this page · raw message
Signature · 1 line
2.41.0
Re: [PATCH for-8.2 v3 6/8] target/riscv: add 'max' CPU type
Quoted 23 lines · Daniel Henrique Barboza
The 'max' CPU type is used by tooling to determine what's the most capable CPU a current QEMU version implements. Other archs such as ARM implements this type. Let's add it to RISC-V.
What we consider "most capable CPU" in this context are related to ratified, non-vendor extensions. This means that we want the 'max' CPU to enable all (possible) ratified extensions by default. The reasoning behind this design is (1) vendor extensions can conflict with each other and we won't play favorities deciding which one is default or not and
(2) non-ratified extensions are always prone to changes, not being stable enough to be enabled by default.All this said, we're still not able to enable all ratified extensions due to conflicts between them. Zfinx and all its dependencies aren't enabled because of a conflict with RVF. zce, zcmp and zcmt are also disabled due to RVD conflicts. When running with 64 bits we're also disabling zcf.
MISA bits RVG, RVJ and RVV are also being set manually since they're default disabled.
This is the resulting 'riscv,isa' DT for this new CPU:
Quoted 7 lines
rv64imafdcvh_zicbom_zicboz_zicsr_zifencei_zihintpause_zawrs_zfa_zfh_zfhmin_zca_zcb_zcd_zba_zbb_zbc_zbkb_zbkc_zbkx_zbs_zk_zkn_zknd_zkne_zknh_zkr_zks_zksed_zksh_zkt_zve32f_zve64f_zve64d_smstateen_sscofpmf_sstc_svadu_svinval_svnapot_svpbmtSigned-off-by Daniel Henrique Barboza <[email protected]>---
Weiwei Li
Quoted 101 lines
target/riscv/cpu-qom.h | 1 + target/riscv/cpu.c | 53 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+)target/riscv/cpu-qom.h +1
-0@@ -30,6 +30,7 @@#define CPU_RESOLVING_TYPE TYPE_RISCV_CPU#define TYPE_RISCV_CPU_ANY RISCV_CPU_TYPE_NAME("any") +#define TYPE_RISCV_CPU_MAX RISCV_CPU_TYPE_NAME("max")#define TYPE_RISCV_CPU_BASE32 RISCV_CPU_TYPE_NAME("rv32")#define TYPE_RISCV_CPU_BASE64 RISCV_CPU_TYPE_NAME("rv64")#define TYPE_RISCV_CPU_BASE128 RISCV_CPU_TYPE_NAME("x-rv128")target/riscv/cpu.c +53
-0@@ -248,6 +248,7 @@ static const char * const riscv_intr_names[] = { };static void riscv_cpu_add_user_properties (Object *obj); +static void riscv_init_max_cpu_extensions (Object *obj);const char *riscv_cpu_get_trap_name (target_ulong cause,bool async) {@@ -374,6 +375,25 @@ static void riscv_any_cpu_init(Object *obj) cpu->cfg.pmp = true; } +static void riscv_max_cpu_init (Object *obj) +{ +RISCVCPU *cpu =RISCV_CPU (obj); +CPURISCVState *env = &cpu->env; +RISCVMXL mlx =MXL_RV64 ; + +#ifdef TARGET_RISCV32 + mlx =MXL_RV32 ; +#endif +set_misa (env, mlx,0 ); +riscv_cpu_add_user_properties (obj); +riscv_init_max_cpu_extensions (obj); + env->priv_ver =PRIV_VERSION_LATEST ; +#ifndef CONFIG_USER_ONLY +set_satp_mode_max_supported (RISCV_CPU (obj), mlx ==MXL_RV32 ? +VM_1_10_SV32 :VM_1_10_SV57 ); +#endif +} +#if defined(TARGET_RISCV64 )static void rv64_base_cpu_init (Object *obj) {@@ -1930,6 +1950,38 @@ static void riscv_cpu_add_user_properties(Object *obj)ADD_CPU_PROPERTIES_ARRAY (dev, riscv_cpu_experimental_exts); } +/* +* The 'max' type CPU will have all possible ratified +* non-vendor extensions enabled. +*/ +static void riscv_init_max_cpu_extensions (Object *obj) +{ +RISCVCPU *cpu =RISCV_CPU (obj); +CPURISCVState *env = &cpu->env; +Property *prop; + +/* Enable RVG, RVJ and RVV that are disabled by default */ +set_misa (env, env->misa_mxl, env->misa_ext |RVG |RVJ |RVV ); + +for (prop = riscv_cpu_extensions; prop && prop->name; prop++) { +object_property_set_bool (obj, prop->name, true,NULL ); + } + +/* Zfinx is not compatible with F. Disable it */ +object_property_set_bool (obj,"zfinx" , false,NULL ); +object_property_set_bool (obj,"zdinx" , false,NULL ); +object_property_set_bool (obj,"zhinx" , false,NULL ); +object_property_set_bool (obj,"zhinxmin" , false,NULL ); + +object_property_set_bool (obj,"zce" , false,NULL ); +object_property_set_bool (obj,"zcmp" , false,NULL ); +object_property_set_bool (obj,"zcmt" , false,NULL ); + +if (env->misa_mxl !=MXL_RV32 ) { +object_property_set_bool (obj,"zcf" , false,NULL ); + } +} +static Property riscv_cpu_properties[] = {DEFINE_PROP_BOOL ("debug" ,RISCVCPU , cfg.debug, true),@@ -2268,6 +2320,7 @@ static const TypeInfo riscv_cpu_type_infos[] = { .abstract = true, }, DEFINE_DYNAMIC_CPU(TYPE_RISCV_CPU_ANY, riscv_any_cpu_init), + DEFINE_DYNAMIC_CPU(TYPE_RISCV_CPU_MAX, riscv_max_cpu_init),#if defined(CONFIG_KVM ) DEFINE_CPU(TYPE_RISCV_CPU_HOST, riscv_host_cpu_init),#endif
PATCH v3 7/8 avocado, risc-v: add opensbi tests for 'max' CPU
In reply to Daniel Henrique BarbozaAdd smoke tests to ensure that we'll not break the 'max' CPU type when adding new ratified extensions to be enabled.
--- tests/avocado/riscv_opensbi.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+)
tests/avocado/riscv_opensbi.py +16 -0
@@ -61,3 +61,19 @@ def test_riscv64_virt(self): :avocado: tags=machine:virt """ self.boot_opensbi() + + def test_riscv32_virt_maxcpu(self): + """ + :avocado: tags=arch:riscv32 + :avocado: tags=machine:virt + :avocado: tags=cpu:max + """ + self.boot_opensbi() + + def test_riscv64_virt_maxcpu(self): + """ + :avocado: tags=arch:riscv64 + :avocado: tags=machine:virt + :avocado: tags=cpu:max + """ + self.boot_opensbi()
Signature · 1 line
2.41.0
PATCH v3 8/8 target/riscv: deprecate the 'any' CPU type
In reply to Daniel Henrique BarbozaThe 'any' CPU type was introduced in commit dc5bd18fa5725 ("RISC-V CPU Core Definition"), being around since the beginning. It's not an easy CPU to use: it's undocumented and its name doesn't tell users much about what the CPU is supposed to bring. 'git log' doesn't help us either in knowing what was the original design of this CPU type.
The closest we have is a comment from Alistair [1] where he recalls from memory that the 'any' CPU is supposed to behave like the newly added 'max' CPU. He also suggested that the 'any' CPU should be removed.
The default CPUs are rv32 and rv64, so removing the 'any' CPU will have impact only on users that might have a script that uses '-cpu any'. And those users are better off using the default CPUs or the new 'max' CPU.
We would love to just remove the code and be done with it, but one does not simply remove a feature in QEMU. We'll put the CPU in quarantine first, letting users know that we have the intent of removing it in the future.
[1] https://lists.gnu.org/archive/html/qemu-devel/2023-07/msg02891.html
--- docs/about/deprecated.rst | 12 ++++++++++++ target/riscv/cpu.c | 5 +++++ 2 files changed, 17 insertions(+)
docs/about/deprecated.rst +12 -0
@@ -371,6 +371,18 @@ QEMU's ``vhost`` feature, which would eliminate the high latency costs under which the 9p ``proxy`` backend currently suffers. However as of to date nobody has indicated plans for such kind of reimplemention unfortunately. +RISC-V 'any' CPU type ``-cpu any`` (since 8.2) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +The 'any' CPU type was introduced back in 2018 and has been around since the +initial RISC-V QEMU port. Its usage has always been unclear: users don't know +what to expect from a CPU called 'any', and in fact the CPU does not do anything +special that aren't already done by the default CPUs rv32/rv64. + +After the introduction of the 'max' CPU type RISC-V now has a good coverage +of generic CPUs: rv32 and rv64 as default CPUs and 'max' as a feature complete +CPU for both 32 and 64 bit builds. Users are then discouraged to use the 'any' +CPU type starting in 8.2. Block device options ''''''''''''''''''''
target/riscv/cpu.c +5 -0
@@ -1470,6 +1470,11 @@ static void riscv_cpu_realize(DeviceState *dev, Error **errp)RISCVCPUClass *mcc =RISCV_CPU_GET_CLASS (dev);Error *local_err =NULL ; +if (object_dynamic_cast (OBJECT (dev),TYPE_RISCV_CPU_ANY ) !=NULL ) { +warn_report ("The 'any' CPU is deprecated and will be " +"removed in the future." ); + } +cpu_exec_realizefn (cs, &local_err);if (local_err !=NULL ) {error_propagate (errp, local_err);
Signature · 1 line
2.41.0
Alistair,
I'm doing some overly complicated stuff here w.r.t to KVM specific code that are biting me back in further cleanups I'm working on.
I'll do some changes in this series and re-send. Thanks,
Daniel
Quoted 41 lines · Daniel Henrique Barboza
Hi,
This version has changes suggested in v2. The most significant change is the deprecation of the 'any' CPU in patch 8.
The reasoning behind it is that Alistair mentioned that the 'any' CPU intended to work like the newly added 'max' CPU, so we're better of removing the 'any' CPU since it'll be out of place. We can't just remove the CPU out of the gate so we'll have to make it do with deprecation first.
Patches missing review: 5,6,7,8
Changes from v2:
- patches 1, 3, 4:
- remove "DEFINE_PROP_END_OF_LIST()" at the end of each prop array;
- useARRAY_SIZE()in the for loop
- patch 5:
- remove the trailing '/' in the last line of the macro
- wrap the macro in "do {} while (0)"
- patch 8 (new):
- deprecate the 'any' CPU
- v2 link: https://lore.kernel.org/qemu-riscv/[email protected]/Daniel Henrique Barboza (8):
target/riscv/cpu.c: split CPU options from riscv_cpu_extensions[]target/riscv/cpu.c: skip 'bool' check when filtering KVM propstarget/riscv/cpu.c: split vendor exts from riscv_cpu_extensions[]target/riscv/cpu.c: split non-ratified exts fromriscv_cpu_extensions[]
target/riscv/cpu.c: add aADD_CPU_PROPERTIES_ARRAY()macro target/riscv: add 'max' CPU type
avocado, risc-v: add opensbi tests for 'max' CPU target/riscv: deprecate the 'any' CPU typedocs/about/deprecated.rst | 12 ++++ target/riscv/cpu-qom.h | 1 + target/riscv/cpu.c | 114 ++++++++++++++++++++++++++------- tests/avocado/riscv_opensbi.py | 16 +++++ 4 files changed, 121 insertions(+), 22 deletions(-)