diff mbox series

[3/5] hw/loongarch: Add compat machine for 9.0

Message ID 20240220124126.1164081-4-maobibo@loongson.cn
State New
Headers show
Series Add migration test for loongarch64 | expand

Commit Message

Bibo Mao Feb. 20, 2024, 12:41 p.m. UTC
Since migration test case requires compat machine type support,
compat machine is added for qemu 9.0 here.

Signed-off-by: Bibo Mao <maobibo@loongson.cn>
---
 hw/loongarch/virt.c | 60 +++++++++++++++++++++++++++++++++++----------
 1 file changed, 47 insertions(+), 13 deletions(-)

Comments

gaosong March 4, 2024, 8:40 a.m. UTC | #1
在 2024/2/20 20:41, Bibo Mao 写道:
> Since migration test case requires compat machine type support,
> compat machine is added for qemu 9.0 here.
> 
> Signed-off-by: Bibo Mao <maobibo@loongson.cn>
> ---
>   hw/loongarch/virt.c | 60 +++++++++++++++++++++++++++++++++++----------
>   1 file changed, 47 insertions(+), 13 deletions(-)
> 
Reviewed-by: Song Gao <gaosong@loongson.cn>

Thanks.
Song Gao
> diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c
> index d0827aafab..a7d700497d 100644
> --- a/hw/loongarch/virt.c
> +++ b/hw/loongarch/virt.c
> @@ -46,6 +46,32 @@
>   #include "hw/block/flash.h"
>   #include "qemu/error-report.h"
>   
> +#define DEFINE_VIRT_MACHINE_LATEST(major, minor, latest) \
> +    static void virt_##major##_##minor##_class_init(ObjectClass *oc, \
> +                                                    void *data) \
> +    { \
> +        MachineClass *mc = MACHINE_CLASS(oc); \
> +        virt_machine_##major##_##minor##_options(mc); \
> +        mc->desc = "QEMU " # major "." # minor " ARM Virtual Machine"; \
> +        if (latest) { \
> +            mc->alias = "virt"; \
> +        } \
> +    } \
> +    static const TypeInfo machvirt_##major##_##minor##_info = { \
> +        .name = MACHINE_TYPE_NAME("virt-" # major "." # minor), \
> +        .parent = TYPE_VIRT_MACHINE, \
> +        .class_init = virt_##major##_##minor##_class_init, \
> +    }; \
> +    static void machvirt_machine_##major##_##minor##_init(void) \
> +    { \
> +        type_register_static(&machvirt_##major##_##minor##_info); \
> +    } \
> +    type_init(machvirt_machine_##major##_##minor##_init);
> +
> +#define DEFINE_VIRT_MACHINE_AS_LATEST(major, minor) \
> +    DEFINE_VIRT_MACHINE_LATEST(major, minor, true)
> +#define DEFINE_VIRT_MACHINE(major, minor) \
> +    DEFINE_VIRT_MACHINE_LATEST(major, minor, false)
>   
>   struct loaderparams {
>       uint64_t ram_size;
> @@ -1151,18 +1177,26 @@ static void virt_class_init(ObjectClass *oc, void *data)
>   #endif
>   }
>   
> -static const TypeInfo virt_machine_types[] = {
> -    {
> -        .name           = TYPE_VIRT_MACHINE,
> -        .parent         = TYPE_MACHINE,
> -        .instance_size  = sizeof(VirtMachineState),
> -        .class_init     = virt_class_init,
> -        .instance_init = virt_machine_initfn,
> -        .interfaces = (InterfaceInfo[]) {
> -         { TYPE_HOTPLUG_HANDLER },
> -         { }
> -        },
> -    }
> +static const TypeInfo virt_machine_info = {
> +    .name           = TYPE_VIRT_MACHINE,
> +    .parent         = TYPE_MACHINE,
> +    .abstract       = true,
> +    .instance_size  = sizeof(VirtMachineState),
> +    .class_init     = virt_class_init,
> +    .instance_init = virt_machine_initfn,
> +    .interfaces = (InterfaceInfo[]) {
> +    { TYPE_HOTPLUG_HANDLER },
> +    { }
> +    },
>   };
>   
> -DEFINE_TYPES(virt_machine_types)
> +static void machvirt_machine_init(void)
> +{
> +    type_register_static(&virt_machine_info);
> +}
> +type_init(machvirt_machine_init);
> +
> +static void virt_machine_9_0_options(MachineClass *mc)
> +{
> +}
> +DEFINE_VIRT_MACHINE_AS_LATEST(9, 0)
>
diff mbox series

Patch

diff --git a/hw/loongarch/virt.c b/hw/loongarch/virt.c
index d0827aafab..a7d700497d 100644
--- a/hw/loongarch/virt.c
+++ b/hw/loongarch/virt.c
@@ -46,6 +46,32 @@ 
 #include "hw/block/flash.h"
 #include "qemu/error-report.h"
 
+#define DEFINE_VIRT_MACHINE_LATEST(major, minor, latest) \
+    static void virt_##major##_##minor##_class_init(ObjectClass *oc, \
+                                                    void *data) \
+    { \
+        MachineClass *mc = MACHINE_CLASS(oc); \
+        virt_machine_##major##_##minor##_options(mc); \
+        mc->desc = "QEMU " # major "." # minor " ARM Virtual Machine"; \
+        if (latest) { \
+            mc->alias = "virt"; \
+        } \
+    } \
+    static const TypeInfo machvirt_##major##_##minor##_info = { \
+        .name = MACHINE_TYPE_NAME("virt-" # major "." # minor), \
+        .parent = TYPE_VIRT_MACHINE, \
+        .class_init = virt_##major##_##minor##_class_init, \
+    }; \
+    static void machvirt_machine_##major##_##minor##_init(void) \
+    { \
+        type_register_static(&machvirt_##major##_##minor##_info); \
+    } \
+    type_init(machvirt_machine_##major##_##minor##_init);
+
+#define DEFINE_VIRT_MACHINE_AS_LATEST(major, minor) \
+    DEFINE_VIRT_MACHINE_LATEST(major, minor, true)
+#define DEFINE_VIRT_MACHINE(major, minor) \
+    DEFINE_VIRT_MACHINE_LATEST(major, minor, false)
 
 struct loaderparams {
     uint64_t ram_size;
@@ -1151,18 +1177,26 @@  static void virt_class_init(ObjectClass *oc, void *data)
 #endif
 }
 
-static const TypeInfo virt_machine_types[] = {
-    {
-        .name           = TYPE_VIRT_MACHINE,
-        .parent         = TYPE_MACHINE,
-        .instance_size  = sizeof(VirtMachineState),
-        .class_init     = virt_class_init,
-        .instance_init = virt_machine_initfn,
-        .interfaces = (InterfaceInfo[]) {
-         { TYPE_HOTPLUG_HANDLER },
-         { }
-        },
-    }
+static const TypeInfo virt_machine_info = {
+    .name           = TYPE_VIRT_MACHINE,
+    .parent         = TYPE_MACHINE,
+    .abstract       = true,
+    .instance_size  = sizeof(VirtMachineState),
+    .class_init     = virt_class_init,
+    .instance_init = virt_machine_initfn,
+    .interfaces = (InterfaceInfo[]) {
+    { TYPE_HOTPLUG_HANDLER },
+    { }
+    },
 };
 
-DEFINE_TYPES(virt_machine_types)
+static void machvirt_machine_init(void)
+{
+    type_register_static(&virt_machine_info);
+}
+type_init(machvirt_machine_init);
+
+static void virt_machine_9_0_options(MachineClass *mc)
+{
+}
+DEFINE_VIRT_MACHINE_AS_LATEST(9, 0)