Skip to contentSkip to conversation

Support different CPU types for the sifive_e machine

PATCH Applied Corey Wharton 4 participants 11 messages Mar 13, 2020 – Apr 24, 2020

Subsystems (2)
lore
Share & tools
lore
#1 lore raw

PATCH v2 1/2 riscv: sifive_e: Support changing CPU type

In reply to Corey Wharton

Allows the CPU to be changed from the default via the -cpu command line option.

---
 hw/riscv/sifive_e.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
hw/riscv/sifive_e.c +2 -1
index a254cad489..b0a611adb9 100644
@@ -123,7 +123,7 @@ static void riscv_sifive_e_soc_init(Object *obj)
     object_initialize_child(obj, "cpus", &s->cpus,
                             sizeof(s->cpus), TYPE_RISCV_HART_ARRAY,
                             &error_abort, NULL);
-    object_property_set_str(OBJECT(&s->cpus), SIFIVE_E_CPU, "cpu-type",
+    object_property_set_str(OBJECT(&s->cpus), ms->cpu_type, "cpu-type",
                             &error_abort);
     object_property_set_int(OBJECT(&s->cpus), ms->smp.cpus, "num-harts",
                             &error_abort);
@@ -220,6 +220,7 @@ static void riscv_sifive_e_machine_init(MachineClass *mc)
     mc->desc = "RISC-V Board compatible with SiFive E SDK";
     mc->init = riscv_sifive_e_init;
     mc->max_cpus = 1;
+    mc->default_cpu_type = SIFIVE_E_CPU;
 }
 
 DEFINE_MACHINE("sifive_e", riscv_sifive_e_machine_init)
Signature · 1 line
2.21.1
#6 lore raw

PATCH v2 2/2 target/riscv: Add a sifive-e34 cpu type

In reply to Corey Wharton

The sifive-e34 cpu type is the same as the sifive-e31 with the single precision floating-point extension enabled.

---
v2: Added missing RVU flag

 target/riscv/cpu.c | 10 ++++++++++
 target/riscv/cpu.h |  1 +
 2 files changed, 11 insertions(+)
target/riscv/cpu.c +10 -0
index c0b7023100..1ae9d085b8 100644
@@ -164,6 +164,15 @@ static void rv32imacu_nommu_cpu_init(Object *obj)
     set_feature(env, RISCV_FEATURE_PMP);
 }
 
+static void rv32imafcu_nommu_cpu_init(Object *obj)
+{
+    CPURISCVState *env = &RISCV_CPU(obj)->env;
+    set_misa(env, RV32 | RVI | RVM | RVA | RVF | RVC | RVU);
+    set_priv_version(env, PRIV_VERSION_1_10_0);
+    set_resetvec(env, DEFAULT_RSTVEC);
+    set_feature(env, RISCV_FEATURE_PMP);
+}
+
 #elif defined(TARGET_RISCV64)
 
 static void riscv_base64_cpu_init(Object *obj)
@@ -609,6 +618,7 @@ static const TypeInfo riscv_cpu_type_infos[] = {
 #if defined(TARGET_RISCV32)
     DEFINE_CPU(TYPE_RISCV_CPU_BASE32,           riscv_base32_cpu_init),
     DEFINE_CPU(TYPE_RISCV_CPU_SIFIVE_E31,       rv32imacu_nommu_cpu_init),
+    DEFINE_CPU(TYPE_RISCV_CPU_SIFIVE_E34,       rv32imafcu_nommu_cpu_init),
     DEFINE_CPU(TYPE_RISCV_CPU_SIFIVE_U34,       rv32gcsu_priv1_10_0_cpu_init),
     /* Depreacted */
     DEFINE_CPU(TYPE_RISCV_CPU_RV32IMACU_NOMMU,  rv32imacu_nommu_cpu_init),
target/riscv/cpu.h +1 -0
index 3dcdf92227..ae5a1d9dce 100644
@@ -36,6 +36,7 @@
 #define TYPE_RISCV_CPU_BASE32           RISCV_CPU_TYPE_NAME("rv32")
 #define TYPE_RISCV_CPU_BASE64           RISCV_CPU_TYPE_NAME("rv64")
 #define TYPE_RISCV_CPU_SIFIVE_E31       RISCV_CPU_TYPE_NAME("sifive-e31")
+#define TYPE_RISCV_CPU_SIFIVE_E34       RISCV_CPU_TYPE_NAME("sifive-e34")
 #define TYPE_RISCV_CPU_SIFIVE_E51       RISCV_CPU_TYPE_NAME("sifive-e51")
 #define TYPE_RISCV_CPU_SIFIVE_U34       RISCV_CPU_TYPE_NAME("sifive-u34")
 #define TYPE_RISCV_CPU_SIFIVE_U54       RISCV_CPU_TYPE_NAME("sifive-u54")
Signature · 1 line
2.21.1
#0 lore raw

v2 cover Support different CPU types for the sifive_e machine

The purpose of this patch set is to allow the sifive_e machine to run with different CPU targets to enable different ISA entensions. To that end it also introduces a new sifive-e34 CPU type which provides the same ISA as sifive-e31, with the addition of the single precision floating-point extension (f). The default CPU for the sifive_e machine is unchanged.

v2: Added missing RVU flag

Corey Wharton (2):
riscv: sifive_e: Support changing CPU type
target/riscv: Add a sifive-e34 cpu type

 hw/riscv/sifive_e.c |  3 ++-
 target/riscv/cpu.c  | 10 ++++++++++
 target/riscv/cpu.h  |  1 +
 3 files changed, 13 insertions(+), 1 deletion(-)
Signature · 1 line
2.21.1
Reviewed-by on v2 1/2
#2 lore raw

Re: [PATCH v2 1/2] riscv: sifive_e: Support changing CPU type

In reply to Corey Wharton
Quoted 25 lines · Corey Wharton

Allows the CPU to be changed from the default via the -cpu command line option.

---
  hw/riscv/sifive_e.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
hw/riscv/sifive_e.c +1 -1
index a254cad489..b0a611adb9 100644
@@ -123,7 +123,7 @@ static void riscv_sifive_e_soc_init(Object *obj)
      object_initialize_child(obj, "cpus", &s->cpus,
                              sizeof(s->cpus), TYPE_RISCV_HART_ARRAY,
                              &error_abort, NULL);
-    object_property_set_str(OBJECT(&s->cpus), SIFIVE_E_CPU, "cpu-type",
+    object_property_set_str(OBJECT(&s->cpus), ms->cpu_type, "cpu-type",
                              &error_abort);
      object_property_set_int(OBJECT(&s->cpus), ms->smp.cpus, "num-harts",
                              &error_abort);

hw/riscv/sifive_e.c static void riscv_sifive_e_machine_init(MachineClass *mc) · line 226

Quoted 7 lines
hw/riscv/sifive_e.c +1 -0
@@ -220,6 +220,7 @@ static void riscv_sifive_e_machine_init(MachineClass *mc)
      mc->desc = "RISC-V Board compatible with SiFive E SDK";
      mc->init = riscv_sifive_e_init;
      mc->max_cpus = 1;
+    mc->default_cpu_type = SIFIVE_E_CPU;
  }
 
  DEFINE_MACHINE("sifive_e", riscv_sifive_e_machine_init)
Reviewed-by on v2 2/2
#7 lore raw

Re: [PATCH v2 2/2] target/riscv: Add a sifive-e34 cpu type

In reply to Corey Wharton
Quoted 5 lines · Corey Wharton

The sifive-e34 cpu type is the same as the sifive-e31 with the single precision floating-point extension enabled.

Alistair

Quoted 51 lines

---
v2: Added missing RVU flag

 target/riscv/cpu.c | 10 ++++++++++
 target/riscv/cpu.h |  1 +
 2 files changed, 11 insertions(+)
target/riscv/cpu.c +10 -0
index c0b7023100..1ae9d085b8 100644
@@ -164,6 +164,15 @@ static void rv32imacu_nommu_cpu_init(Object *obj)
     set_feature(env, RISCV_FEATURE_PMP);
 }
 
+static void rv32imafcu_nommu_cpu_init(Object *obj)
+{
+    CPURISCVState *env = &RISCV_CPU(obj)->env;
+    set_misa(env, RV32 | RVI | RVM | RVA | RVF | RVC | RVU);
+    set_priv_version(env, PRIV_VERSION_1_10_0);
+    set_resetvec(env, DEFAULT_RSTVEC);
+    set_feature(env, RISCV_FEATURE_PMP);
+}
+
 #elif defined(TARGET_RISCV64)
 
 static void riscv_base64_cpu_init(Object *obj)
@@ -609,6 +618,7 @@ static const TypeInfo riscv_cpu_type_infos[] = {
 #if defined(TARGET_RISCV32)
     DEFINE_CPU(TYPE_RISCV_CPU_BASE32,           riscv_base32_cpu_init),
     DEFINE_CPU(TYPE_RISCV_CPU_SIFIVE_E31,       rv32imacu_nommu_cpu_init),
+    DEFINE_CPU(TYPE_RISCV_CPU_SIFIVE_E34,       rv32imafcu_nommu_cpu_init),
     DEFINE_CPU(TYPE_RISCV_CPU_SIFIVE_U34,       rv32gcsu_priv1_10_0_cpu_init),
     /* Depreacted */
     DEFINE_CPU(TYPE_RISCV_CPU_RV32IMACU_NOMMU,  rv32imacu_nommu_cpu_init),
target/riscv/cpu.h +1 -1
index 3dcdf92227..ae5a1d9dce 100644
@@ -36,6 +36,7 @@
 #define TYPE_RISCV_CPU_BASE32           RISCV_CPU_TYPE_NAME("rv32")
 #define TYPE_RISCV_CPU_BASE64           RISCV_CPU_TYPE_NAME("rv64")
 #define TYPE_RISCV_CPU_SIFIVE_E31       RISCV_CPU_TYPE_NAME("sifive-e31")
+#define TYPE_RISCV_CPU_SIFIVE_E34       RISCV_CPU_TYPE_NAME("sifive-e34")
 #define TYPE_RISCV_CPU_SIFIVE_E51       RISCV_CPU_TYPE_NAME("sifive-e51")
 #define TYPE_RISCV_CPU_SIFIVE_U34       RISCV_CPU_TYPE_NAME("sifive-u34")
 #define TYPE_RISCV_CPU_SIFIVE_U54       RISCV_CPU_TYPE_NAME("sifive-u54")
--

2.21.1

Reviewed-by on v2 2/2
#8 lore raw

Re: [PATCH v2 2/2] target/riscv: Add a sifive-e34 cpu type

In reply to Corey Wharton
Quoted 4 lines · Corey Wharton

The sifive-e34 cpu type is the same as the sifive-e31 with the single precision floating-point extension enabled.

Quoted 8 lines

---
v2: Added missing RVU flag

 target/riscv/cpu.c | 10 ++++++++++
 target/riscv/cpu.h |  1 +
 2 files changed, 11 insertions(+)
#9 lore raw
In reply to Corey Wharton

ping

https://patchwork.kernel.org/patch/11437661/
https://patchwork.kernel.org/patch/11437665/

________________________________
From: Corey Wharton <[email protected]>
Sent: Friday, March 13, 2020 12:35 PM
To: [email protected] <[email protected]>; [email protected] <[email protected]>
Cc: Palmer Dabbelt <[email protected]>; Alistair Francis <[email protected]>; Sagar Karandikar <[email protected]>; Bastian Koppelmann <[email protected]>; Bin Meng <[email protected]>; Corey Wharton <[email protected]>
Subject: [PATCH v2 0/2] Support different CPU types for the sifive_e machine

The purpose of this patch set is to allow the sifive_e machine to run with different CPU targets to enable different ISA entensions. To that end it also introduces a new sifive-e34 CPU type which provides the same ISA as sifive-e31, with the addition of the single precision floating-point extension (f). The default CPU for the sifive_e machine is unchanged.

v2: Added missing RVU flag

Corey Wharton (2):
riscv: sifive_e: Support changing CPU type
target/riscv: Add a sifive-e34 cpu type

 hw/riscv/sifive_e.c |  3 ++-
 target/riscv/cpu.c  | 10 ++++++++++
 target/riscv/cpu.h  |  1 +
 3 files changed, 13 insertions(+), 1 deletion(-)

--
2.21.1

#10 lore raw
In reply to Corey Wharton
Quoted 9 lines · Corey Wharton

The purpose of this patch set is to allow the sifive_e machine to run with different CPU targets to enable different ISA entensions. To that end it also introduces a new sifive-e34 CPU type which provides the same ISA as sifive-e31, with the addition of the single precision floating-point extension (f). The default CPU for the sifive_e machine is unchanged.

v2: Added missing RVU flag

Applied to the RISC-V tree for 5.1

Alistair

Quoted 14 lines

Corey Wharton (2):
riscv: sifive_e: Support changing CPU type
target/riscv: Add a sifive-e34 cpu type

 hw/riscv/sifive_e.c |  3 ++-
 target/riscv/cpu.c  | 10 ++++++++++
 target/riscv/cpu.h  |  1 +
 3 files changed, 13 insertions(+), 1 deletion(-)

--
2.21.1

#3 lore raw

Re: [PATCH v2 1/2] riscv: sifive_e: Support changing CPU type

In reply to Corey Wharton
Quoted 7 lines · Corey Wharton

Allows the CPU to be changed from the default via the -cpu command line option.

Thanks for the patch.

Unfortunately this fails make check.

The problem is that the machine has the default_cpu_type set but then you set "cpu-type" from the SoC.

This diff fixes the make check failure for me:

hw/riscv/sifive_e.c +0 -2
index 1fd08f325c..b53109521e 100644
@@ -123,8 +123,6 @@ static void riscv_sifive_e_soc_init(Object *obj)
     object_initialize_child(obj, "cpus", &s->cpus,
                             sizeof(s->cpus), TYPE_RISCV_HART_ARRAY,
                             &error_abort, NULL);
-    object_property_set_str(OBJECT(&s->cpus), ms->cpu_type, "cpu-type",
-                            &error_abort);
     object_property_set_int(OBJECT(&s->cpus), ms->smp.cpus, "num-harts",
                             &error_abort);
     sysbus_init_child_obj(obj, "riscv.sifive.e.gpio0",
@@ -141,6 +139,8 @@ static void riscv_sifive_e_soc_realize(DeviceState

*dev, Error **errp)

     SiFiveESoCState *s = RISCV_E_SOC(dev);
     MemoryRegion *sys_mem = get_system_memory();

+ object_property_set_str(OBJECT(&s->cpus), ms->cpu_type, "cpu-type",

+                            &error_abort);
     object_property_set_bool(OBJECT(&s->cpus), true, "realized",
                             &error_abort);

I'm happy to just squash that into the patch. Let me know if you don't want me to do that and I'll drop these patches and let you re-send them.

Alistair

Quoted 29 lines
---
 hw/riscv/sifive_e.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
hw/riscv/sifive_e.c +2 -2
index a254cad489..b0a611adb9 100644
@@ -123,7 +123,7 @@ static void riscv_sifive_e_soc_init(Object *obj)
     object_initialize_child(obj, "cpus", &s->cpus,
                             sizeof(s->cpus), TYPE_RISCV_HART_ARRAY,
                             &error_abort, NULL);
-    object_property_set_str(OBJECT(&s->cpus), SIFIVE_E_CPU, "cpu-type",
+    object_property_set_str(OBJECT(&s->cpus), ms->cpu_type, "cpu-type",
                             &error_abort);
     object_property_set_int(OBJECT(&s->cpus), ms->smp.cpus, "num-harts",
                             &error_abort);
@@ -220,6 +220,7 @@ static void riscv_sifive_e_machine_init(MachineClass *mc)
     mc->desc = "RISC-V Board compatible with SiFive E SDK";
     mc->init = riscv_sifive_e_init;
     mc->max_cpus = 1;
+    mc->default_cpu_type = SIFIVE_E_CPU;
 }
 
 DEFINE_MACHINE("sifive_e", riscv_sifive_e_machine_init)
--

2.21.1

#4 lore raw

RE: [PATCH v2 1/2] riscv: sifive_e: Support changing CPU type

Quoted 55 lines

-----Original Message-----
From: Alistair Francis <[email protected]>
Sent: Friday, April 24, 2020 9:04 AM
To: Corey Wharton <[email protected]>
Cc: [email protected] Developers <[email protected]>; open list:RISC-V <[email protected]>; Sagar Karandikar <[email protected]>; Bastian Koppelmann <[email protected] paderborn.de>; Alistair Francis <[email protected]>; Palmer Dabbelt <[email protected]>; Bin Meng <[email protected]>
Subject: Re: [PATCH v2 1/2] riscv: sifive_e: Support changing CPU type

Quoted 7 lines · Corey Wharton

Allows the CPU to be changed from the default via the -cpu command line option.

Thanks for the patch.

Unfortunately this fails make check.

The problem is that the machine has the default_cpu_type set but then you set "cpu-type" from the SoC.

This diff fixes the make check failure for me:

hw/riscv/sifive_e.c index renamed from hw/riscv/sifive_e.c +0 -0

1fd08f325c..b53109521e 100644

hw/riscv/sifive_e.c +0 -2
@@ -123,8 +123,6 @@ static void riscv_sifive_e_soc_init(Object *obj)
     object_initialize_child(obj, "cpus", &s->cpus,
                             sizeof(s->cpus), TYPE_RISCV_HART_ARRAY,
                             &error_abort, NULL);
-    object_property_set_str(OBJECT(&s->cpus), ms->cpu_type, "cpu-type",
-                            &error_abort);
     object_property_set_int(OBJECT(&s->cpus), ms->smp.cpus, "num-harts",
                             &error_abort);
     sysbus_init_child_obj(obj, "riscv.sifive.e.gpio0", @@ -141,6 +139,8 @@

static void riscv_sifive_e_soc_realize(DeviceState *dev, Error **errp)

     SiFiveESoCState *s = RISCV_E_SOC(dev);
     MemoryRegion *sys_mem = get_system_memory();
hw/riscv/sifive_e.c +2 -0
+    object_property_set_str(OBJECT(&s->cpus), ms->cpu_type, "cpu-type",
+                            &error_abort);
     object_property_set_bool(OBJECT(&s->cpus), true, "realized",
                             &error_abort);
Quoted 5 lines

I'm happy to just squash that into the patch. Let me know if you don't want me to do that and I'll drop these patches and let you re-send them.

Alistair

Thanks for fixing this issue. I tested your patch and it seems to work as Intended and I'm fine with you squashing it into the patch.

Corey

Quoted 31 lines
Quoted 9 lines
---
 hw/riscv/sifive_e.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
hw/riscv/sifive_e.c index renamed from hw/riscv/sifive_e.c +0 -0

a254cad489..b0a611adb9 100644

hw/riscv/sifive_e.c static void riscv_sifive_e_soc_init(Object *obj) · line 129

Quoted 8 lines
hw/riscv/sifive_e.c +2 -1
@@ -123,7 +123,7 @@ static void riscv_sifive_e_soc_init(Object *obj)
     object_initialize_child(obj, "cpus", &s->cpus,
                             sizeof(s->cpus), TYPE_RISCV_HART_ARRAY,
                             &error_abort, NULL);
-    object_property_set_str(OBJECT(&s->cpus), SIFIVE_E_CPU, "cpu-type",
+    object_property_set_str(OBJECT(&s->cpus), ms->cpu_type,
+ "cpu-type",
                             &error_abort);
     object_property_set_int(OBJECT(&s->cpus), ms->smp.cpus, "num-

harts",

Quoted 13 lines
                             &error_abort); @@ -220,6 +220,7 @@ static
void riscv_sifive_e_machine_init(MachineClass *mc)
     mc->desc = "RISC-V Board compatible with SiFive E SDK";
     mc->init = riscv_sifive_e_init;
     mc->max_cpus = 1;

+ mc->default_cpu_type = SIFIVE_E_CPU;
}

DEFINE_MACHINE("sifive_e", riscv_sifive_e_machine_init)
--
2.21.1

#5 lore raw

Re: [PATCH v2 1/2] riscv: sifive_e: Support changing CPU type

Quoted 56 lines · Corey Wharton
Quoted 56 lines

-----Original Message-----
From: Alistair Francis <[email protected]>
Sent: Friday, April 24, 2020 9:04 AM
To: Corey Wharton <[email protected]>
Cc: [email protected] Developers <[email protected]>; open list:RISC-V <[email protected]>; Sagar Karandikar <[email protected]>; Bastian Koppelmann <[email protected] paderborn.de>; Alistair Francis <[email protected]>; Palmer Dabbelt <[email protected]>; Bin Meng <[email protected]>
Subject: Re: [PATCH v2 1/2] riscv: sifive_e: Support changing CPU type

Quoted 7 lines · Corey Wharton

Allows the CPU to be changed from the default via the -cpu command line option.

Thanks for the patch.

Unfortunately this fails make check.

The problem is that the machine has the default_cpu_type set but then you set "cpu-type" from the SoC.

This diff fixes the make check failure for me:

hw/riscv/sifive_e.c index renamed from hw/riscv/sifive_e.c +0 -0

1fd08f325c..b53109521e 100644

hw/riscv/sifive_e.c +0 -2
@@ -123,8 +123,6 @@ static void riscv_sifive_e_soc_init(Object *obj)
     object_initialize_child(obj, "cpus", &s->cpus,
                             sizeof(s->cpus), TYPE_RISCV_HART_ARRAY,
                             &error_abort, NULL);
-    object_property_set_str(OBJECT(&s->cpus), ms->cpu_type, "cpu-type",
-                            &error_abort);
     object_property_set_int(OBJECT(&s->cpus), ms->smp.cpus, "num-harts",
                             &error_abort);
     sysbus_init_child_obj(obj, "riscv.sifive.e.gpio0", @@ -141,6 +139,8 @@

static void riscv_sifive_e_soc_realize(DeviceState *dev, Error **errp)

     SiFiveESoCState *s = RISCV_E_SOC(dev);
     MemoryRegion *sys_mem = get_system_memory();
hw/riscv/sifive_e.c +2 -0
+    object_property_set_str(OBJECT(&s->cpus), ms->cpu_type, "cpu-type",
+                            &error_abort);
     object_property_set_bool(OBJECT(&s->cpus), true, "realized",
                             &error_abort);
Quoted 8 lines
Quoted 5 lines

I'm happy to just squash that into the patch. Let me know if you don't want me to do that and I'll drop these patches and let you re-send them.

Alistair

Thanks for fixing this issue. I tested your patch and it seems to work as Intended and I'm fine with you squashing it into the patch.

Great!

I'll send this patch as part of the PR after 5.0 then.

I also realised that my justification was wrong. It's not because of the machine/SoC split, but because of the order between init/realise.

Alistair

Quoted 34 lines

Corey

Quoted 31 lines
Quoted 9 lines
---
 hw/riscv/sifive_e.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
hw/riscv/sifive_e.c index renamed from hw/riscv/sifive_e.c +0 -0

a254cad489..b0a611adb9 100644

hw/riscv/sifive_e.c static void riscv_sifive_e_soc_init(Object *obj) · line 129

Quoted 8 lines
hw/riscv/sifive_e.c +2 -1
@@ -123,7 +123,7 @@ static void riscv_sifive_e_soc_init(Object *obj)
     object_initialize_child(obj, "cpus", &s->cpus,
                             sizeof(s->cpus), TYPE_RISCV_HART_ARRAY,
                             &error_abort, NULL);
-    object_property_set_str(OBJECT(&s->cpus), SIFIVE_E_CPU, "cpu-type",
+    object_property_set_str(OBJECT(&s->cpus), ms->cpu_type,
+ "cpu-type",
                             &error_abort);
     object_property_set_int(OBJECT(&s->cpus), ms->smp.cpus, "num-

harts",

Quoted 13 lines
                             &error_abort); @@ -220,6 +220,7 @@ static
void riscv_sifive_e_machine_init(MachineClass *mc)
     mc->desc = "RISC-V Board compatible with SiFive E SDK";
     mc->init = riscv_sifive_e_init;
     mc->max_cpus = 1;

+ mc->default_cpu_type = SIFIVE_E_CPU;
}

DEFINE_MACHINE("sifive_e", riscv_sifive_e_machine_init)
--
2.21.1