Re: [PATCH v2 03/14] hw/s390x: convert 'ccw' machine definitions to use new macros

2024-07-01 Thread Philippe Mathieu-Daudé

On 20/6/24 18:57, Daniel P. Berrangé wrote:

This changes the DEFINE_CCW_MACHINE macro to use the common
helpers for constructing versioned symbol names and strings,
bringing greater consistency across targets.

The added benefit is that it avoids the need to repeat the
version number twice in two different formats in the calls
to DEFINE_CCW_MACHINE.

A DEFINE_CCW_MACHINE_AS_LATEST helper is added so that it
is not required to pass 'false' for every single historical
machine type.

Reviewed-by: Thomas Huth 
Signed-off-by: Daniel P. Berrangé 
---
  hw/s390x/s390-virtio-ccw.c | 96 +-
  1 file changed, 53 insertions(+), 43 deletions(-)


Nice!

Reviewed-by: Philippe Mathieu-Daudé 




[PATCH v2 03/14] hw/s390x: convert 'ccw' machine definitions to use new macros

2024-06-20 Thread Daniel P . Berrangé
This changes the DEFINE_CCW_MACHINE macro to use the common
helpers for constructing versioned symbol names and strings,
bringing greater consistency across targets.

The added benefit is that it avoids the need to repeat the
version number twice in two different formats in the calls
to DEFINE_CCW_MACHINE.

A DEFINE_CCW_MACHINE_AS_LATEST helper is added so that it
is not required to pass 'false' for every single historical
machine type.

Reviewed-by: Thomas Huth 
Signed-off-by: Daniel P. Berrangé 
---
 hw/s390x/s390-virtio-ccw.c | 96 +-
 1 file changed, 53 insertions(+), 43 deletions(-)

diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c
index 3d0bc3e7f2..efed539bc6 100644
--- a/hw/s390x/s390-virtio-ccw.c
+++ b/hw/s390x/s390-virtio-ccw.c
@@ -15,6 +15,7 @@
 #include "qapi/error.h"
 #include "exec/ram_addr.h"
 #include "exec/confidential-guest-support.h"
+#include "hw/boards.h"
 #include "hw/s390x/s390-virtio-hcall.h"
 #include "hw/s390x/sclp.h"
 #include "hw/s390x/s390_flic.h"
@@ -816,35 +817,44 @@ static const TypeInfo ccw_machine_info = {
 },
 };
 
-#define DEFINE_CCW_MACHINE(suffix, verstr, latest)\
-static void ccw_machine_##suffix##_class_init(ObjectClass *oc,\
-  void *data) \
+#define DEFINE_CCW_MACHINE_IMPL(latest, ...)  \
+static void MACHINE_VER_SYM(class_init, ccw, __VA_ARGS__)(\
+ObjectClass *oc,  \
+void *data)   \
 { \
 MachineClass *mc = MACHINE_CLASS(oc); \
-ccw_machine_##suffix##_class_options(mc); \
-mc->desc = "Virtual s390x machine (version " verstr ")";  \
+MACHINE_VER_SYM(class_options, ccw, __VA_ARGS__)(mc); \
+mc->desc = "Virtual s390x machine (version " 
MACHINE_VER_STR(__VA_ARGS__) ")"; \
 if (latest) { \
 mc->alias = "s390-ccw-virtio";\
 mc->is_default = true;\
 } \
 } \
-static void ccw_machine_##suffix##_instance_init(Object *obj) \
+static void MACHINE_VER_SYM(instance_init, ccw, __VA_ARGS__)(Object *obj) \
 { \
 MachineState *machine = MACHINE(obj); \
-current_mc = S390_CCW_MACHINE_CLASS(MACHINE_GET_CLASS(machine));   
   \
-ccw_machine_##suffix##_instance_options(machine); \
+current_mc = S390_CCW_MACHINE_CLASS(MACHINE_GET_CLASS(machine));  \
+MACHINE_VER_SYM(instance_options, ccw, __VA_ARGS__)(machine); \
 } \
-static const TypeInfo ccw_machine_##suffix##_info = { \
-.name = MACHINE_TYPE_NAME("s390-ccw-virtio-" verstr), \
+static const TypeInfo MACHINE_VER_SYM(info, ccw, __VA_ARGS__) =   \
+{ \
+.name = MACHINE_VER_TYPE_NAME("s390-ccw-virtio", __VA_ARGS__),\
 .parent = TYPE_S390_CCW_MACHINE,  \
-.class_init = ccw_machine_##suffix##_class_init,  \
-.instance_init = ccw_machine_##suffix##_instance_init,\
+.class_init = MACHINE_VER_SYM(class_init, ccw, __VA_ARGS__),  \
+.instance_init = MACHINE_VER_SYM(instance_init, ccw, __VA_ARGS__),\
 };\
-static void ccw_machine_register_##suffix(void)   \
+static void MACHINE_VER_SYM(register, ccw, __VA_ARGS__)(void) \
 { \
-type_register_static(&ccw_machine_##suffix##_info);   \
+type_register_static(&MACHINE_VER_SYM(info, ccw, __VA_ARGS__));   \
 } \
-type_init(ccw_machine_register_##suffix)
+type_init(MACHINE_VER_SYM(register, ccw, __VA_ARGS__))
+
+#define DEFINE_CCW_MACHINE_AS_LATEST(major, minor) \
+DEFINE_CCW_MACHINE_IMPL(true, major, minor)
+
+#define DEFINE_CCW_MACHINE(major, minor) \
+DEFINE_CCW_MACHINE_IMPL(false, maj