Skip to contentSkip to conversation

hw/riscv: Inline TYPE_RISCV_CPU_BASE definition

PATCH In review Philippe Mathieu-Daudé 4 participants 13 messages May 26 RISC-V

lore
Share & tools
lore
#0 lore raw

cover hw/riscv: Inline TYPE_RISCV_CPU_BASE definition

Inline TYPE_RISCV_CPU_BASE in preparation of "single-binary:
Compile hw/riscv once":
https://lore.kernel.org/qemu-devel/[email protected]/

Anton Johansson (1):
target-info: Add target_riscv64()

Philippe Mathieu-Daudé (3):
hw/riscv/spike: Use 'max' CPU type by default hw/riscv/microblaze-v: Use RV32I / RV64I CPU type by default hw/riscv/virt: Inline TYPE_RISCV_CPU_BASE definition

 include/qemu/target-info.h      | 7 +++++++
 target/riscv/cpu.h              | 6 ------
 hw/riscv/microblaze-v-generic.c | 4 +++-
 hw/riscv/spike.c                | 2 +-
 hw/riscv/virt.c                 | 4 +++-
 target-info.c                   | 5 +++++
 6 files changed, 19 insertions(+), 9 deletions(-)
Signature · 1 line
2.53.0
#1 lore raw

PATCH 1/4 hw/riscv/spike: Use 'max' CPU type by default

The Spike RISC-V ISA Simulator aims for maximum coverage, so can start with the 'max' CPU type by default.

---
 hw/riscv/spike.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/riscv/spike.c +1 -1
index 87fe0f242f5..08eb7edb92f 100644
@@ -341,7 +341,7 @@ static void spike_machine_class_init(ObjectClass *oc, const void *data)
     mc->desc = "RISC-V Spike board";
     mc->init = spike_board_init;
     mc->max_cpus = SPIKE_CPUS_MAX;
-    mc->default_cpu_type = TYPE_RISCV_CPU_BASE;
+    mc->default_cpu_type = TYPE_RISCV_CPU_MAX;
     mc->possible_cpu_arch_ids = riscv_numa_possible_cpu_arch_ids;
     mc->cpu_index_to_instance_props = riscv_numa_cpu_index_to_props;
     mc->get_default_cpu_node_id = riscv_numa_get_default_cpu_node_id;
Signature · 1 line
2.53.0
Reviewed-by on v1 1/4
#2 lore raw

Re: [PATCH 1/4] hw/riscv/spike: Use 'max' CPU type by default

Quoted 5 lines · Philippe Mathieu-Daudé

The Spike RISC-V ISA Simulator aims for maximum coverage, so can start with the 'max' CPU type by default.

---

Quoted 16 lines
  hw/riscv/spike.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
hw/riscv/spike.c +1 -1
index 87fe0f242f5..08eb7edb92f 100644
@@ -341,7 +341,7 @@ static void spike_machine_class_init(ObjectClass *oc, const void *data)
      mc->desc = "RISC-V Spike board";
      mc->init = spike_board_init;
      mc->max_cpus = SPIKE_CPUS_MAX;
-    mc->default_cpu_type = TYPE_RISCV_CPU_BASE;
+    mc->default_cpu_type = TYPE_RISCV_CPU_MAX;
      mc->possible_cpu_arch_ids = riscv_numa_possible_cpu_arch_ids;
      mc->cpu_index_to_instance_props = riscv_numa_cpu_index_to_props;
      mc->get_default_cpu_node_id = riscv_numa_get_default_cpu_node_id;
Reviewed-by on v1 1/4
#3 lore raw

Re: [PATCH 1/4] hw/riscv/spike: Use 'max' CPU type by default

In reply to Philippe Mathieu-Daudé
Quoted 4 lines · Philippe Mathieu-Daudé

The Spike RISC-V ISA Simulator aims for maximum coverage, so can start with the 'max' CPU type by default.

Alistair

Quoted 19 lines

---
 hw/riscv/spike.c | 2 +-

 1 file changed, 1 insertion(+), 1 deletion(-)
hw/riscv/spike.c +1 -1
index 87fe0f242f5..08eb7edb92f 100644
@@ -341,7 +341,7 @@ static void spike_machine_class_init(ObjectClass
 *oc, const void *data)
      mc->desc = "RISC-V Spike board";
      mc->init = spike_board_init;
      mc->max_cpus = SPIKE_CPUS_MAX;
-    mc->default_cpu_type = TYPE_RISCV_CPU_BASE;
+    mc->default_cpu_type = TYPE_RISCV_CPU_MAX;
      mc->possible_cpu_arch_ids = riscv_numa_possible_cpu_arch_ids;
      mc->cpu_index_to_instance_props = riscv_numa_cpu_index_to_props;

     mc->get_default_cpu_node_id =
riscv_numa_get_default_cpu_node_id;

#4 lore raw

PATCH 2/4 target-info: Add target_riscv64()

In reply to Philippe Mathieu-Daudé

From: Anton Johansson <[email protected]>

Adds a helper function to tell if the binary is targeting riscv64 or not.

Message-ID: <[email protected]>

---
 include/qemu/target-info.h | 7 +++++++
 target-info.c              | 5 +++++
 2 files changed, 12 insertions(+)
include/qemu/target-info.h +7 -0
index 23c997de541..6c5b714288e 100644
@@ -99,4 +99,11 @@ bool target_ppc64(void);
  */
 bool target_s390x(void);
 
+/**
+ * target_riscv64:
+ *
+ * Returns whether the target architecture is riscv64
+ */
+bool target_riscv64(void);
+
 #endif
target-info.c +5 -0
index 28c458fc7a7..04c69c41f8a 100644
@@ -93,3 +93,8 @@ bool target_s390x(void)
 {
     return target_arch() == SYS_EMU_TARGET_S390X;
 }
+
+bool target_riscv64(void)
+{
+    return target_arch() == SYS_EMU_TARGET_RISCV64;
+}
Signature · 1 line
2.53.0
Reviewed-by on v1 2/4
#5 lore raw

Re: [PATCH 2/4] target-info: Add target_riscv64()

Quoted 11 lines · Philippe Mathieu-Daudé

From: Anton Johansson <[email protected]>

Adds a helper function to tell if the binary is targeting riscv64 or not.

Message-ID: <[email protected]>

Alistair

Quoted 34 lines

---
 include/qemu/target-info.h | 7 +++++++
 target-info.c              | 5 +++++

 2 files changed, 12 insertions(+)
include/qemu/target-info.h +0 -0
index 23c997de541..6c5b714288e 100644
@@ -99,4 +99,11 @@ bool target_ppc64(void);
   */
  bool target_s390x(void);

include/qemu/target-info.h +7 -0
+/**
+ * target_riscv64:
+ *
+ * Returns whether the target architecture is riscv64
+ */
+bool target_riscv64(void);
+

 #endif

target-info.c +5 -0
index 28c458fc7a7..04c69c41f8a 100644
@@ -93,3 +93,8 @@ bool target_s390x(void)
  {
      return target_arch() == SYS_EMU_TARGET_S390X;
  }
+
+bool target_riscv64(void)
+{
+    return target_arch() == SYS_EMU_TARGET_RISCV64;
+}
#6 lore raw

PATCH 3/4 hw/riscv/microblaze-v: Use RV32I / RV64I CPU type by default

In reply to Philippe Mathieu-Daudé

Per [*]:

AMD MicroBlaze™ V processor Key Capabilities:

- Configurable ISA support for RV32I and RV64I Base Integer Instruction Set

[*] https://www.amd.com/en/products/software/adaptive-socs-and-fpgas/microblaze-v.html

---
 hw/riscv/microblaze-v-generic.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
hw/riscv/microblaze-v-generic.c +3 -1
index b0494b1ac50..04a201dcd95 100644
@@ -14,6 +14,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "qemu/target-info.h"
 #include "qemu/units.h"
 #include "qapi/error.h"
 #include "target/riscv/cpu.h"
@@ -182,7 +183,8 @@ static void mb_v_generic_machine_init(MachineClass *mc)
     mc->init = mb_v_generic_init;
     mc->min_cpus = 1;
     mc->max_cpus = 1;
-    mc->default_cpu_type = TYPE_RISCV_CPU_BASE;
+    mc->default_cpu_type = target_riscv64() ? TYPE_RISCV_CPU_RV64I
+                                            : TYPE_RISCV_CPU_RV32I;
     mc->default_cpus = 1;
 }
 
Signature · 1 line
2.53.0
#7 lore raw

Re: [PATCH 3/4] hw/riscv/microblaze-v: Use RV32I / RV64I CPU type by default

Quoted 8 lines · Philippe Mathieu-Daudé

Per [*]:

AMD MicroBlaze™ V processor Key Capabilities:

- Configurable ISA support for RV32I and RV64I Base Integer Instruction Set

[*] https://www.amd.com/en/products/software/adaptive-socs-and-fpgas/microblaze-v.html

I am not sure if that's really the case ... the trick is on the "configurable" keyword. This basically means that they start with the base set and then add stuff on top of it.

In the link above, if you go down there to a "MicroBlaze V Processor Reference Guide", you'll get here:

https://docs.amd.com/r/en-US/ug1629-microblaze-v-user-guide/Introduction

And then if you click in "Features" in the left side, right below "Overview", you'll find a "Configurable Feature Overview" table. And there's a *lot* of stuff there.

Setting the board default to rv32i/rv64i will break the board. Pretty sure Linux won't boot with just rv64i, and I'd be surprised if OpenSBI would be able to play ball.

I see that you CCed the original contributor of the board (Sai Pavan Boddu) so we can see the author's opinion. From my perspective, if the idea is to not use TYPE_RISCV_CPU_BASE, maybe we can use rva23s64 for 64 bits (the feature table from the link seems close to the profile) and for 32 bit I would go with 'max' because we don't have 32 bit profiles implemented in QEMU.

A better solution would be to model a Microblaze V CPU for the board but setting the default to max32/rva23s64 seems sensible for now.

Thanks,
Daniel

Quoted 28 lines
---
  hw/riscv/microblaze-v-generic.c | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
hw/riscv/microblaze-v-generic.c +3 -1
index b0494b1ac50..04a201dcd95 100644
@@ -14,6 +14,7 @@
   */
 
  #include "qemu/osdep.h"
+#include "qemu/target-info.h"
  #include "qemu/units.h"
  #include "qapi/error.h"
  #include "target/riscv/cpu.h"
@@ -182,7 +183,8 @@ static void mb_v_generic_machine_init(MachineClass *mc)
      mc->init = mb_v_generic_init;
      mc->min_cpus = 1;
      mc->max_cpus = 1;
-    mc->default_cpu_type = TYPE_RISCV_CPU_BASE;
+    mc->default_cpu_type = target_riscv64() ? TYPE_RISCV_CPU_RV64I
+                                            : TYPE_RISCV_CPU_RV32I;
      mc->default_cpus = 1;
  }
 
#8 lore raw

Re: [PATCH 3/4] hw/riscv/microblaze-v: Use RV32I / RV64I CPU type by default

In reply to Philippe Mathieu-Daudé
Quoted 29 lines · Philippe Mathieu-Daudé

Per [*]:

  AMD MicroBlaze™ V processor Key Capabilities:

  - Configurable ISA support for RV32I and RV64I Base Integer Instruction Set

[*]
https://www.amd.com/en/products/software/adaptive-socs-and-fpgas/microblaze-v.html

---
 hw/riscv/microblaze-v-generic.c | 4 +++-

 1 file changed, 3 insertions(+), 1 deletion(-)
hw/riscv/microblaze-v- renamed from hw/riscv/microblaze-v-generic.c +0 -0

generic.c
index b0494b1ac50..04a201dcd95 100644

hw/riscv/microblaze-v-generic.c +0 -0
@@ -14,6 +14,7 @@
   */


 #include "qemu/osdep.h"
+#include "qemu/target-info.h"
 #include "qemu/units.h"
 #include "qapi/error.h"
 #include "target/riscv/cpu.h"

hw/riscv/microblaze-v-generic.c static void · line 188

Quoted 7 lines
hw/riscv/microblaze-v-generic.c +2 -1
@@ -182,7 +183,8 @@ static void
 mb_v_generic_machine_init(MachineClass *mc)
      mc->init = mb_v_generic_init;
      mc->min_cpus = 1;
      mc->max_cpus = 1;
-    mc->default_cpu_type = TYPE_RISCV_CPU_BASE;
+    mc->default_cpu_type = target_riscv64() ? TYPE_RISCV_CPU_RV64I
+                                            : TYPE_RISCV_CPU_RV32I;

This should probably be TYPE_RISCV_CPU_BASE32/TYPE_RISCV_CPU_BASE64 as then it's a no-op. We can talk about removing those CPUs separately then.

Alistair

Quoted 3 lines
hw/riscv/microblaze-v-generic.c +0 -0
      mc->default_cpus = 1;
  }

#9 lore raw

PATCH 4/4 hw/riscv/virt: Inline TYPE_RISCV_CPU_BASE definition

In reply to Philippe Mathieu-Daudé

TYPE_RISCV_CPU_BASE is only use by the 'virt' machine. Inline it, replacing a built time check by a runtime one.

---
 target/riscv/cpu.h | 6 ------
 hw/riscv/virt.c    | 4 +++-
 2 files changed, 3 insertions(+), 7 deletions(-)
target/riscv/cpu.h +0 -6
index 7d79c7a5a7e..0d2ecd9d6ba 100644
@@ -39,12 +39,6 @@ typedef struct CPUArchState CPURISCVState;
 
 #define CPU_RESOLVING_TYPE TYPE_RISCV_CPU
 
-#if defined(TARGET_RISCV32)
-# define TYPE_RISCV_CPU_BASE            TYPE_RISCV_CPU_BASE32
-#elif defined(TARGET_RISCV64)
-# define TYPE_RISCV_CPU_BASE            TYPE_RISCV_CPU_BASE64
-#endif
-
 /*
  * b0: Whether a instruction always raise a store AMO or not.
  */
hw/riscv/virt.c +3 -1
index 3d06c9c6104..8371b28c27a 100644
@@ -22,6 +22,7 @@
 #include "qemu/units.h"
 #include "qemu/error-report.h"
 #include "qemu/guest-random.h"
+#include "qemu/target-info.h"
 #include "qapi/error.h"
 #include "hw/core/boards.h"
 #include "hw/core/loader.h"
@@ -1932,7 +1933,8 @@ static void virt_machine_class_init(ObjectClass *oc, const void *data)
     mc->desc = "RISC-V VirtIO board";
     mc->init = virt_machine_init;
     mc->max_cpus = VIRT_CPUS_MAX;
-    mc->default_cpu_type = TYPE_RISCV_CPU_BASE;
+    mc->default_cpu_type = target_riscv64() ? TYPE_RISCV_CPU_BASE64
+                                            : TYPE_RISCV_CPU_BASE32;
     mc->block_default_type = IF_VIRTIO;
     mc->no_cdrom = 1;
     mc->pci_allow_0_address = true;
Signature · 1 line
2.53.0
Reviewed-by on v1 4/4
#10 lore raw

Re: [PATCH 4/4] hw/riscv/virt: Inline TYPE_RISCV_CPU_BASE definition

Quoted 39 lines · Philippe Mathieu-Daudé

TYPE_RISCV_CPU_BASE is only use by the 'virt' machine. Inline it, replacing a built time check by a runtime one.

---
  target/riscv/cpu.h | 6 ------
  hw/riscv/virt.c    | 4 +++-
  2 files changed, 3 insertions(+), 7 deletions(-)
target/riscv/cpu.h +0 -6
index 7d79c7a5a7e..0d2ecd9d6ba 100644
@@ -39,12 +39,6 @@ typedef struct CPUArchState CPURISCVState;
 
  #define CPU_RESOLVING_TYPE TYPE_RISCV_CPU
 
-#if defined(TARGET_RISCV32)
-# define TYPE_RISCV_CPU_BASE            TYPE_RISCV_CPU_BASE32
-#elif defined(TARGET_RISCV64)
-# define TYPE_RISCV_CPU_BASE            TYPE_RISCV_CPU_BASE64
-#endif
-
  /*
   * b0: Whether a instruction always raise a store AMO or not.
   */
hw/riscv/virt.c +1 -0
index 3d06c9c6104..8371b28c27a 100644
@@ -22,6 +22,7 @@
  #include "qemu/units.h"
  #include "qemu/error-report.h"
  #include "qemu/guest-random.h"
+#include "qemu/target-info.h"
  #include "qapi/error.h"
  #include "hw/core/boards.h"
  #include "hw/core/loader.h"

hw/riscv/virt.c static void virt_machine_class_init(ObjectClass *oc, const void *data) · line 1937

Quoted 6 lines
hw/riscv/virt.c +2 -1
@@ -1932,7 +1933,8 @@ static void virt_machine_class_init(ObjectClass *oc, const void *data)
      mc->desc = "RISC-V VirtIO board";
      mc->init = virt_machine_init;
      mc->max_cpus = VIRT_CPUS_MAX;
-    mc->default_cpu_type = TYPE_RISCV_CPU_BASE;
+    mc->default_cpu_type = target_riscv64() ? TYPE_RISCV_CPU_BASE64
+                                            : TYPE_RISCV_CPU_BASE32;

As I said in an earlier message today I would be soooooo down to make rv32/rv64 aliases of max32/max :D

Maaaaybe setting MAX as the default CPU for 'virt' could be a good way to put our feet in the water? Change it, see the amount of nagging coming our way, adjust if needed?

But that can wait. For now:

Quoted 3 lines
hw/riscv/virt.c +0 -0
      mc->block_default_type = IF_VIRTIO;
      mc->no_cdrom = 1;
      mc->pci_allow_0_address = true;
Reviewed-by on v1 4/4
#11 lore raw

Re: [PATCH 4/4] hw/riscv/virt: Inline TYPE_RISCV_CPU_BASE definition

In reply to Philippe Mathieu-Daudé
Quoted 4 lines · Philippe Mathieu-Daudé

TYPE_RISCV_CPU_BASE is only use by the 'virt' machine. Inline it, replacing a built time check by a runtime one.

Alistair

Quoted 45 lines

---
 target/riscv/cpu.h | 6 ------
 hw/riscv/virt.c    | 4 +++-

 2 files changed, 3 insertions(+), 7 deletions(-)
target/riscv/cpu.h +0 -0
index 7d79c7a5a7e..0d2ecd9d6ba 100644
@@ -39,12 +39,6 @@ typedef struct CPUArchState CPURISCVState;


 #define CPU_RESOLVING_TYPE TYPE_RISCV_CPU

target/riscv/cpu.h +0 -6
-#if defined(TARGET_RISCV32)
-# define TYPE_RISCV_CPU_BASE            TYPE_RISCV_CPU_BASE32
-#elif defined(TARGET_RISCV64)
-# define TYPE_RISCV_CPU_BASE            TYPE_RISCV_CPU_BASE64
-#endif
-

 /*
  * b0: Whether a instruction always raise a store AMO or not. */

hw/riscv/virt.c +3 -1
index 3d06c9c6104..8371b28c27a 100644
@@ -22,6 +22,7 @@
  #include "qemu/units.h"
  #include "qemu/error-report.h"
  #include "qemu/guest-random.h"
+#include "qemu/target-info.h"
  #include "qapi/error.h"
  #include "hw/core/boards.h"
  #include "hw/core/loader.h"
@@ -1932,7 +1933,8 @@ static void virt_machine_class_init(ObjectClass
 *oc, const void *data)
      mc->desc = "RISC-V VirtIO board";
      mc->init = virt_machine_init;
      mc->max_cpus = VIRT_CPUS_MAX;
-    mc->default_cpu_type = TYPE_RISCV_CPU_BASE;
+    mc->default_cpu_type = target_riscv64() ? TYPE_RISCV_CPU_BASE64
+                                            : TYPE_RISCV_CPU_BASE32;
      mc->block_default_type = IF_VIRTIO;
      mc->no_cdrom = 1;

     mc->pci_allow_0_address = true;

Reviewed-by Anton Johansson on the v1 series
#12 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 12 lines · Philippe Mathieu-Daudé

Inline TYPE_RISCV_CPU_BASE in preparation of "single-binary:
Compile hw/riscv once":
https://lore.kernel.org/qemu-devel/[email protected]/

Anton Johansson (1):
target-info: Add target_riscv64()

Philippe Mathieu-Daudé (3):
hw/riscv/spike: Use 'max' CPU type by default hw/riscv/microblaze-v: Use RV32I / RV64I CPU type by default hw/riscv/virt: Inline TYPE_RISCV_CPU_BASE definition

Quoted 11 lines
 include/qemu/target-info.h      | 7 +++++++
 target/riscv/cpu.h              | 6 ------
 hw/riscv/microblaze-v-generic.c | 4 +++-
 hw/riscv/spike.c                | 2 +-
 hw/riscv/virt.c                 | 4 +++-
 target-info.c                   | 5 +++++
 6 files changed, 19 insertions(+), 9 deletions(-)
Signature · 1 line
2.53.0

Series: