Skip to contentSkip to conversation

system: Make qemu_arch_available() common code

PATCH In review Philippe Mathieu-Daudé 3 participants 12 messages Feb 13 – Feb 16 Arm/Amlogic Meson SoC support

lore
Share & tools
lore
#0 lore raw

v4 cover system: Make qemu_arch_available() common code

- Avoid qemu_arch_available() in hw/
- Document qemu_arch_available(),
- define QEMU_ARCH_* based on SYS_EMU_TARGET_*, allowing (via with TargetInfo API) to compile arch_init.c as common,
- restrict qemu_arch_available() scope to system/ sub-directory.

---
v4: New approach
v3: Return directly within switch
v2: Prefer switch over array (pbo)

Philippe Mathieu-Daudé (5):
qemu: Document qemu_arch_available() method qemu/target_info: Add target_s390x() helper hw/scsi/disk: Prefer target_s390x() over qemu_arch_available()
system: Make qemu_arch_available() common code
system: Reduce 'arch_init.h' scope

 meson.build                |  2 --
 include/qemu/target-info.h |  7 ++++++
 include/system/arch_init.h | 30 -----------------------
 system/arch_init.h         | 50 ++++++++++++++++++++++++++++++++++++++
 hw/scsi/scsi-disk.c        |  4 +--
 system/arch_init.c         |  6 +++--
 target-info.c              |  5 ++++
 system/meson.build         |  2 +-
 8 files changed, 69 insertions(+), 37 deletions(-)
 delete mode 100644 include/system/arch_init.h
 create mode 100644 system/arch_init.h
Signature · 1 line
2.52.0
#1 lore raw

PATCH v4 1/5 qemu: Document qemu_arch_available() method

qemu_arch_available() is used to check if a broadly available feature should be exposed to a particular set of target architectures.

Since its argument is a mask of bits, rename it as @arch_bitmask.

We have less than 32 target architectures so far, so restrict it to the uint32_t type.

---
 include/system/arch_init.h | 8 +++++++-
 system/arch_init.c         | 4 ++--
 2 files changed, 9 insertions(+), 3 deletions(-)
include/system/arch_init.h +7 -1
index f2f909d5406..92d50ba8d63 100644
@@ -25,6 +25,12 @@ enum {
     QEMU_ARCH_LOONGARCH = (1 << 23),
 };
 
-bool qemu_arch_available(unsigned qemu_arch_mask);
+/**
+ * qemu_arch_available:
+ * @arch_bitmask: bitmask of QEMU_ARCH_* constants
+ *
+ * Return whether the current target architecture is contained in @arch_bitmask
+ */
+bool qemu_arch_available(uint32_t arch_bitmask);
 
 #endif
system/arch_init.c +2 -2
index e85736884c9..d7ec6e69c79 100644
@@ -24,7 +24,7 @@
 #include "qemu/osdep.h"
 #include "system/arch_init.h"
 
-bool qemu_arch_available(unsigned qemu_arch_mask)
+bool qemu_arch_available(uint32_t arch_bitmask);
 {
-    return qemu_arch_mask & QEMU_ARCH;
+    return arch_bitmask & QEMU_ARCH;
 }
Signature · 1 line
2.52.0
Reviewed-by on v4 1/5
#2 lore raw

Re: [PATCH v4 1/5] qemu: Document qemu_arch_available() method

Quoted 6 lines · Philippe Mathieu-Daudé

qemu_arch_available() is used to check if a broadly available feature should be exposed to a particular set of target architectures.

Since its argument is a mask of bits, rename it as @arch_bitmask.

Quoted 9 lines

We have less than 32 target architectures so far, so restrict it to the uint32_t type.

---
  include/system/arch_init.h | 8 +++++++-
  system/arch_init.c         | 4 ++--
  2 files changed, 9 insertions(+), 3 deletions(-)
#3 lore raw

PATCH v4 2/5 qemu/target_info: Add target_s390x() helper

In reply to Philippe Mathieu-Daudé

Add a helper to distinct whether the binary is targetting S390x or not.

---
 include/qemu/target-info.h | 7 +++++++
 target-info.c              | 5 +++++
 2 files changed, 12 insertions(+)
include/qemu/target-info.h +7 -0
index e3287334304..23c997de541 100644
@@ -92,4 +92,11 @@ bool target_ppc(void);
  */
 bool target_ppc64(void);
 
+/**
+ * target_s390x:
+ *
+ * Returns whether the target architecture is S390x.
+ */
+bool target_s390x(void);
+
 #endif
target-info.c +5 -0
index a26532f660f..28c458fc7a7 100644
@@ -88,3 +88,8 @@ bool target_ppc64(void)
 {
     return target_arch() == SYS_EMU_TARGET_PPC64;
 }
+
+bool target_s390x(void)
+{
+    return target_arch() == SYS_EMU_TARGET_S390X;
+}
Signature · 1 line
2.52.0
#5 lore raw

PATCH v4 3/5 hw/scsi/disk: Prefer target_s390x() over qemu_arch_available()

In reply to Philippe Mathieu-Daudé

qemu_arch_available() is used to check if a broadly available feature should be exposed to a particular set of target architectures. Here we only want to check something that is specific to s390x: the target_s390x() helper is more adapted. Besides, it will allow to reduce qemu_arch_available() scope.

---
 hw/scsi/scsi-disk.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
hw/scsi/scsi-disk.c +2 -2
index 877ad21579f..68eb65fbf4a 100644
@@ -27,13 +27,13 @@
 #include "qemu/module.h"
 #include "qemu/hw-version.h"
 #include "qemu/memalign.h"
+#include "qemu/target-info.h"
 #include "hw/scsi/scsi.h"
 #include "migration/misc.h"
 #include "migration/qemu-file-types.h"
 #include "migration/vmstate.h"
 #include "hw/scsi/emulation.h"
 #include "scsi/constants.h"
-#include "system/arch_init.h"
 #include "system/block-backend.h"
 #include "system/blockdev.h"
 #include "hw/block/block.h"
@@ -3180,7 +3180,7 @@ static void scsi_property_add_specifics(DeviceClass *dc)
     ObjectClass *oc = OBJECT_CLASS(dc);
 
     /* The loadparm property is only supported on s390x */
-    if (qemu_arch_available(QEMU_ARCH_S390X)) {
+    if (target_s390x()) {
         object_class_property_add_str(oc, "loadparm",
                                       scsi_property_get_loadparm,
                                       scsi_property_set_loadparm);
Signature · 1 line
2.52.0
Reviewed-by on v4 3/5
#6 lore raw

Re: [PATCH v4 3/5] hw/scsi/disk: Prefer target_s390x() over qemu_arch_available()

Quoted 11 lines · Philippe Mathieu-Daudé

qemu_arch_available() is used to check if a broadly available feature should be exposed to a particular set of target architectures. Here we only want to check something that is specific to s390x: the target_s390x() helper is more adapted. Besides, it will allow to reduce qemu_arch_available() scope.

---
  hw/scsi/scsi-disk.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
#7 lore raw

PATCH v4 4/5 system: Make qemu_arch_available() common code

In reply to Philippe Mathieu-Daudé

Remove the need of per-target QEMU_ARCH. Define the QEMU_ARCH_* constants based on SYS_EMU_TARGET_* ones, themselves already exposed via target_arch(), allowing to check the current target is included in @arch_bitmask.

---
 meson.build                |  2 --
 include/system/arch_init.h | 54 ++++++++++++++++++++++++--------------
 system/arch_init.c         |  6 +++--
 system/meson.build         |  2 +-
 4 files changed, 39 insertions(+), 25 deletions(-)
meson.build +0 -2
index 4af32c3e1f2..fc79a1d9aed 100644
@@ -3375,8 +3375,6 @@ foreach target : target_dirs
       config_target_data.set(k, v)
     endif
   endforeach
-  config_target_data.set('QEMU_ARCH',
-                         'QEMU_ARCH_' + config_target['TARGET_BASE_ARCH'].to_upper())
   config_target_h += {target: configure_file(output: target + '-config-target.h',
                                                configuration: config_target_data)}
 
include/system/arch_init.h +34 -20

64 lines not on this page · raw message

system/arch_init.c +4 -2
index d7ec6e69c79..604d5909ed0 100644
@@ -23,8 +23,10 @@
  */
 #include "qemu/osdep.h"
 #include "system/arch_init.h"
+#include "qemu/bitops.h"
+#include "qemu/target-info-qapi.h"
 
-bool qemu_arch_available(uint32_t arch_bitmask);
+bool qemu_arch_available(uint32_t arch_bitmask)
 {
-    return arch_bitmask & QEMU_ARCH;
+    return extract32(arch_bitmask, target_arch(), 1);
 }
system/meson.build +1 -1
index 4b69ef0f5fb..d91703d3dcc 100644
@@ -1,5 +1,4 @@
 specific_ss.add(when: 'CONFIG_SYSTEM_ONLY', if_true: [files(
-  'arch_init.c',
   'globals-target.c',
 )])
 
@@ -8,6 +7,7 @@ system_ss.add(files(
 ), sdl, libpmem, libdaxctl)
 
 system_ss.add(files(
+  'arch_init.c',
   'balloon.c',
   'bootdevice.c',
   'cpus.c',
Signature · 1 line
2.52.0
Reviewed-by on v4 4/5
#8 lore raw
Quoted 5 lines · Philippe Mathieu-Daudé

Remove the need of per-target QEMU_ARCH. Define the QEMU_ARCH_* constants based on SYS_EMU_TARGET_* ones, themselves already exposed via target_arch(), allowing to check the current target is included in @arch_bitmask.

Quoted 8 lines
---
  meson.build                |  2 --
  include/system/arch_init.h | 54 ++++++++++++++++++++++++--------------
  system/arch_init.c         |  6 +++--
  system/meson.build         |  2 +-
  4 files changed, 39 insertions(+), 25 deletions(-)
#9 lore raw

PATCH v4 5/5 system: Reduce 'arch_init.h' scope

In reply to Philippe Mathieu-Daudé

Better to restrict qemu_arch_available() scope so it is only used by generic system/ code to parse command line options.

---
 {include/system => system}/arch_init.h | 0
 1 file changed, 0 insertions(+), 0 deletions(-)
 rename {include/system => system}/arch_init.h (100%)
system/arch_init.h renamed from include/system/arch_init.h +0 -0
similarity index 100%
rename from include/system/arch_init.h
rename to system/arch_init.h
Signature · 1 line
2.52.0
Reviewed-by on v4 5/5
#10 lore raw

Re: [PATCH v4 5/5] system: Reduce 'arch_init.h' scope

Quoted 9 lines · Philippe Mathieu-Daudé

Better to restrict qemu_arch_available() scope so it is only used by generic system/ code to parse command line options.

---
  {include/system => system}/arch_init.h | 0
  1 file changed, 0 insertions(+), 0 deletions(-)

rename {include/system => system}/arch_init.h (100%)

Reviewed-by on the v4 series
#11 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 27 lines · Philippe Mathieu-Daudé

- Avoid qemu_arch_available() in hw/
- Document qemu_arch_available(),
- define QEMU_ARCH_* based on SYS_EMU_TARGET_*, allowing (via with TargetInfo API) to compile arch_init.c as common,
- restrict qemu_arch_available() scope to system/ sub-directory.

---
v4: New approach
v3: Return directly within switch
v2: Prefer switch over array (pbo)

Philippe Mathieu-Daudé (5):
qemu: Document qemu_arch_available() method qemu/target_info: Add target_s390x() helper hw/scsi/disk: Prefer target_s390x() over qemu_arch_available()
system: Make qemu_arch_available() common code
system: Reduce 'arch_init.h' scope

  meson.build                |  2 --
  include/qemu/target-info.h |  7 ++++++
  include/system/arch_init.h | 30 -----------------------
  system/arch_init.h         | 50 ++++++++++++++++++++++++++++++++++++++
  hw/scsi/scsi-disk.c        |  4 +--
  system/arch_init.c         |  6 +++--
  target-info.c              |  5 ++++
  system/meson.build         |  2 +-
  8 files changed, 69 insertions(+), 37 deletions(-)
Quoted 2 lines

delete mode 100644 include/system/arch_init.h
create mode 100644 system/arch_init.h

Series

... and since arch_init.c only contains one single small function, I think you could even go one step further and merge that into another file in system/ ... but that could also be done in a later patch.

Thomas