system: Make qemu_arch_available() common code
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
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
@@ -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
@@ -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
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_ttype.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- include/system/arch_init.h | 8 +++++++- system/arch_init.c | 4 ++-- 2 files changed, 9 insertions(+), 3 deletions(-)
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
@@ -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
@@ -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
Re: [PATCH v4 2/5] qemu/target_info: Add target_s390x() helper
Quoted 9 lines · Philippe Mathieu-Daudé
Add a helper to distinct whether the binary is targetting S390x or not.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- include/qemu/target-info.h | 7 +++++++ target-info.c | 5 +++++ 2 files changed, 12 insertions(+)
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
@@ -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
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: thetarget_s390x()helper is more adapted. Besides, it will allow to reduceqemu_arch_available()scope.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/scsi/scsi-disk.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
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
@@ -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
@@ -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
@@ -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
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 viatarget_arch(), allowing to check the current target is included in @arch_bitmask.
Quoted 8 lines
Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- 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(-)
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
Signature · 1 line
2.52.0
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.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- {include/system => system}/arch_init.h | 0 1 file changed, 0 insertions(+), 0 deletions(-)rename {
include/system=>system}/arch_init.h(100%)
Quoted 27 lines · Philippe Mathieu-Daudé
- Avoid
qemu_arch_available()in hw/
- Documentqemu_arch_available(),
- define QEMU_ARCH_* based on SYS_EMU_TARGET_*, allowing (via with TargetInfo API) to compilearch_init.cas common,
- restrictqemu_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: Documentqemu_arch_available()method qemu/target_info: Addtarget_s390x()helper hw/scsi/disk: Prefertarget_s390x()overqemu_arch_available()
system: Makeqemu_arch_available()common code
system: Reduce 'arch_init.h' scopemeson.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 100644system/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