Add a more general DEFINE_MACHINE_EXTENDED macro and define simpler
versions with less parameters based on that. This is inspired by how
the OBJECT_DEFINE macros do this in a similar way to allow using the
shortened definition in more complex cases too.
Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
---
include/hw/boards.h | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/include/hw/boards.h b/include/hw/boards.h
index 665b620121..fd3d549ff5 100644
--- a/include/hw/boards.h
+++ b/include/hw/boards.h
@@ -762,7 +762,8 @@ struct MachineState {
} \
} while (0)
-#define DEFINE_MACHINE(namestr, machine_initfn) \
+#define DEFINE_MACHINE_EXTENDED(namestr, PARENT_NAME, InstanceName, \
+ machine_initfn, ABSTRACT, ...) \
static void machine_initfn##_class_init(ObjectClass *oc, const void *data) \
{ \
MachineClass *mc = MACHINE_CLASS(oc); \
@@ -770,8 +771,11 @@ struct MachineState {
} \
static const TypeInfo machine_initfn##_typeinfo = { \
.name = MACHINE_TYPE_NAME(namestr), \
- .parent = TYPE_MACHINE, \
+ .parent = TYPE_##PARENT_NAME, \
.class_init = machine_initfn##_class_init, \
+ .instance_size = sizeof(InstanceName), \
+ .abstract = ABSTRACT, \
+ .interfaces = (const InterfaceInfo[]) { __VA_ARGS__ } , \
}; \
static void machine_initfn##_register_types(void) \
{ \
@@ -779,6 +783,14 @@ struct MachineState {
} \
type_init(machine_initfn##_register_types)
+#define DEFINE_MACHINE(namestr, machine_initfn) \
+ DEFINE_MACHINE_EXTENDED(namestr, MACHINE, MachineState, machine_initfn, \
+ false, { })
+
+#define DEFINE_MACHINE_WITH_INTERFACES(namestr, machine_initfn, ...) \
+ DEFINE_MACHINE_EXTENDED(namestr, MACHINE, MachineState, machine_initfn, \
+ false, __VA_ARGS__)
+
extern GlobalProperty hw_compat_10_1[];
extern const size_t hw_compat_10_1_len;
--
2.41.3
On 18/10/25 17:11, BALATON Zoltan wrote:
> Add a more general DEFINE_MACHINE_EXTENDED macro and define simpler
> versions with less parameters based on that. This is inspired by how
> the OBJECT_DEFINE macros do this in a similar way to allow using the
> shortened definition in more complex cases too.
>
> Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
> ---
> include/hw/boards.h | 16 ++++++++++++++--
> 1 file changed, 14 insertions(+), 2 deletions(-)
>
> diff --git a/include/hw/boards.h b/include/hw/boards.h
> index 665b620121..fd3d549ff5 100644
> --- a/include/hw/boards.h
> +++ b/include/hw/boards.h
> @@ -762,7 +762,8 @@ struct MachineState {
> } \
> } while (0)
>
> -#define DEFINE_MACHINE(namestr, machine_initfn) \
> +#define DEFINE_MACHINE_EXTENDED(namestr, PARENT_NAME, InstanceName, \
> + machine_initfn, ABSTRACT, ...) \
> static void machine_initfn##_class_init(ObjectClass *oc, const void *data) \
> { \
> MachineClass *mc = MACHINE_CLASS(oc); \
> @@ -770,8 +771,11 @@ struct MachineState {
> } \
> static const TypeInfo machine_initfn##_typeinfo = { \
> .name = MACHINE_TYPE_NAME(namestr), \
> - .parent = TYPE_MACHINE, \
> + .parent = TYPE_##PARENT_NAME, \
> .class_init = machine_initfn##_class_init, \
> + .instance_size = sizeof(InstanceName), \
> + .abstract = ABSTRACT, \
> + .interfaces = (const InterfaceInfo[]) { __VA_ARGS__ } , \
IIUC Richard asked for array argument in order to save .rodata?
> }; \
> static void machine_initfn##_register_types(void) \
> { \
> @@ -779,6 +783,14 @@ struct MachineState {
> } \
> type_init(machine_initfn##_register_types)
>
> +#define DEFINE_MACHINE(namestr, machine_initfn) \
> + DEFINE_MACHINE_EXTENDED(namestr, MACHINE, MachineState, machine_initfn, \
> + false, { })
> +
> +#define DEFINE_MACHINE_WITH_INTERFACES(namestr, machine_initfn, ...) \
> + DEFINE_MACHINE_EXTENDED(namestr, MACHINE, MachineState, machine_initfn, \
> + false, __VA_ARGS__)
> +
> extern GlobalProperty hw_compat_10_1[];
> extern const size_t hw_compat_10_1_len;
>
+Pierrick
On 20/10/25 17:05, Philippe Mathieu-Daudé wrote:
> On 18/10/25 17:11, BALATON Zoltan wrote:
>> Add a more general DEFINE_MACHINE_EXTENDED macro and define simpler
>> versions with less parameters based on that. This is inspired by how
>> the OBJECT_DEFINE macros do this in a similar way to allow using the
>> shortened definition in more complex cases too.
>>
>> Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
>> ---
>> include/hw/boards.h | 16 ++++++++++++++--
>> 1 file changed, 14 insertions(+), 2 deletions(-)
>>
>> diff --git a/include/hw/boards.h b/include/hw/boards.h
>> index 665b620121..fd3d549ff5 100644
>> --- a/include/hw/boards.h
>> +++ b/include/hw/boards.h
>> @@ -762,7 +762,8 @@ struct MachineState {
>> } \
>> } while (0)
>> -#define DEFINE_MACHINE(namestr, machine_initfn) \
>> +#define DEFINE_MACHINE_EXTENDED(namestr, PARENT_NAME, InstanceName, \
>> + machine_initfn, ABSTRACT, ...) \
>> static void machine_initfn##_class_init(ObjectClass *oc, const
>> void *data) \
>> { \
>> MachineClass *mc = MACHINE_CLASS(oc); \
>> @@ -770,8 +771,11 @@ struct MachineState {
>> } \
>> static const TypeInfo machine_initfn##_typeinfo = { \
>> .name = MACHINE_TYPE_NAME(namestr), \
>> - .parent = TYPE_MACHINE, \
>> + .parent = TYPE_##PARENT_NAME, \
>> .class_init = machine_initfn##_class_init, \
>> + .instance_size = sizeof(InstanceName), \
>> + .abstract = ABSTRACT, \
IIUC we don't want to have abstract type with interfaces, but
only QOM leaves. So maybe better always use .abstract = false in
DEFINE_MACHINE_EXTENDED()?
>> + .interfaces = (const InterfaceInfo[]) { __VA_ARGS__ } , \
>
> IIUC Richard asked for array argument in order to save .rodata?
>
>> }; \
>> static void machine_initfn##_register_types(void) \
>> { \
>> @@ -779,6 +783,14 @@ struct MachineState {
>> } \
>> type_init(machine_initfn##_register_types)
>> +#define DEFINE_MACHINE(namestr, machine_initfn) \
>> + DEFINE_MACHINE_EXTENDED(namestr, MACHINE, MachineState,
>> machine_initfn, \
>> + false, { })
>> +
>> +#define DEFINE_MACHINE_WITH_INTERFACES(namestr, machine_initfn, ...) \
>> + DEFINE_MACHINE_EXTENDED(namestr, MACHINE, MachineState,
>> machine_initfn, \
>> + false, __VA_ARGS__)
>> +
>> extern GlobalProperty hw_compat_10_1[];
>> extern const size_t hw_compat_10_1_len;
On Mon, 20 Oct 2025, Philippe Mathieu-Daudé wrote:
> +Pierrick
>
> On 20/10/25 17:05, Philippe Mathieu-Daudé wrote:
>> On 18/10/25 17:11, BALATON Zoltan wrote:
>>> Add a more general DEFINE_MACHINE_EXTENDED macro and define simpler
>>> versions with less parameters based on that. This is inspired by how
>>> the OBJECT_DEFINE macros do this in a similar way to allow using the
>>> shortened definition in more complex cases too.
>>>
>>> Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
>>> ---
>>> include/hw/boards.h | 16 ++++++++++++++--
>>> 1 file changed, 14 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/include/hw/boards.h b/include/hw/boards.h
>>> index 665b620121..fd3d549ff5 100644
>>> --- a/include/hw/boards.h
>>> +++ b/include/hw/boards.h
>>> @@ -762,7 +762,8 @@ struct MachineState {
>>> } \
>>> } while (0)
>>> -#define DEFINE_MACHINE(namestr, machine_initfn) \
>>> +#define DEFINE_MACHINE_EXTENDED(namestr, PARENT_NAME, InstanceName, \
>>> + machine_initfn, ABSTRACT, ...) \
>>> static void machine_initfn##_class_init(ObjectClass *oc, const void
>>> *data) \
>>> { \
>>> MachineClass *mc = MACHINE_CLASS(oc); \
>>> @@ -770,8 +771,11 @@ struct MachineState {
>>> } \
>>> static const TypeInfo machine_initfn##_typeinfo = { \
>>> .name = MACHINE_TYPE_NAME(namestr), \
>>> - .parent = TYPE_MACHINE, \
>>> + .parent = TYPE_##PARENT_NAME, \
>>> .class_init = machine_initfn##_class_init, \
>>> + .instance_size = sizeof(InstanceName), \
>>> + .abstract = ABSTRACT, \
>
> IIUC we don't want to have abstract type with interfaces, but
> only QOM leaves. So maybe better always use .abstract = false in
> DEFINE_MACHINE_EXTENDED()?
Where did you get that from? What about these then:
static const TypeInfo pnv_psi_info
static const TypeInfo spapr_machine_info
static const TypeInfo e1000_base_info
static const TypeInfo ivshmem_common_info
static const TypeInfo macio_type_info
static const TypeInfo bus_info
static const TypeInfo device_type_info
static const TypeInfo hppa_machine_types
static const TypeInfo qxl_pci_type_info
static const TypeInfo pic_common_type
static const TypeInfo xive2_router_info
static const TypeInfo arm_gic_common_type
static const TypeInfo arm_gicv3_common_type
static const TypeInfo ioapic_common_type
static const TypeInfo loongarch_extioi_common_types
static const TypeInfo rp_info
static const TypeInfo virt_machine_info (hw/arm/virt.c)
static const TypeInfo mps2tz_info
static const TypeInfo armsse_info
static const TypeInfo m48txx_isa_type_info
static const TypeInfo m48txx_sysbus_type_info
static const TypeInfo pci_ide_type_info
static const TypeInfo ccw_machine_info
static const TypeInfo virtio_ccw_md_info
static const TypeInfo pc_machine_info
static const TypeInfo x86_machine_info
static const TypeInfo vfio_pci_device_info
static const TypeInfo ehci_pci_type_info
static const TypeInfo xhci_pci_info
static const TypeInfo uhci_pci_type_info
static const TypeInfo via_pm_info
static const TypeInfo via_isa_info
static const TypeInfo piix_pci_type_info
static const TypeInfo pcie_slot_type_info
static const TypeInfo pci_bridge_type_info
static const TypeInfo intel_hda_info
static const TypeInfo virtio_md_pci_info
>>> + .interfaces = (const InterfaceInfo[]) { __VA_ARGS__ } , \
>>
>> IIUC Richard asked for array argument in order to save .rodata?
Do you have an example for that? I'm not sure what do you mean.
Regards,
BALATON Zoltan
>>> }; \
>>> static void machine_initfn##_register_types(void) \
>>> { \
>>> @@ -779,6 +783,14 @@ struct MachineState {
>>> } \
>>> type_init(machine_initfn##_register_types)
>>> +#define DEFINE_MACHINE(namestr, machine_initfn) \
>>> + DEFINE_MACHINE_EXTENDED(namestr, MACHINE, MachineState,
>>> machine_initfn, \
>>> + false, { })
>>> +
>>> +#define DEFINE_MACHINE_WITH_INTERFACES(namestr, machine_initfn, ...) \
>>> + DEFINE_MACHINE_EXTENDED(namestr, MACHINE, MachineState,
>>> machine_initfn, \
>>> + false, __VA_ARGS__)
>>> +
>>> extern GlobalProperty hw_compat_10_1[];
>>> extern const size_t hw_compat_10_1_len;
>
>
+ Eduardo, Marcel (since changes in boards.h)
On 10/20/25 21:05, BALATON Zoltan wrote:
> On Mon, 20 Oct 2025, Philippe Mathieu-Daudé wrote:
>> +Pierrick
>>
>> On 20/10/25 17:05, Philippe Mathieu-Daudé wrote:
>>> On 18/10/25 17:11, BALATON Zoltan wrote:
>>>> Add a more general DEFINE_MACHINE_EXTENDED macro and define simpler
>>>> versions with less parameters based on that. This is inspired by how
>>>> the OBJECT_DEFINE macros do this in a similar way to allow using the
>>>> shortened definition in more complex cases too.
>>>>
>>>> Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
>>>> ---
>>>> include/hw/boards.h | 16 ++++++++++++++--
>>>> 1 file changed, 14 insertions(+), 2 deletions(-)
>>>>
>>>> diff --git a/include/hw/boards.h b/include/hw/boards.h
>>>> index 665b620121..fd3d549ff5 100644
>>>> --- a/include/hw/boards.h
>>>> +++ b/include/hw/boards.h
>>>> @@ -762,7 +762,8 @@ struct MachineState {
>>>> } \
>>>> } while (0)
>>>> -#define DEFINE_MACHINE(namestr, machine_initfn) \
>>>> +#define DEFINE_MACHINE_EXTENDED(namestr, PARENT_NAME, InstanceName, \
>>>> + machine_initfn, ABSTRACT, ...) \
>>>> static void machine_initfn##_class_init(ObjectClass *oc, const
>>>> void *data) \
>>>> { \
>>>> MachineClass *mc = MACHINE_CLASS(oc); \
>>>> @@ -770,8 +771,11 @@ struct MachineState {
>>>> } \
>>>> static const TypeInfo machine_initfn##_typeinfo = { \
>>>> .name = MACHINE_TYPE_NAME(namestr), \
>>>> - .parent = TYPE_MACHINE, \
>>>> + .parent = TYPE_##PARENT_NAME, \
>>>> .class_init = machine_initfn##_class_init, \
>>>> + .instance_size = sizeof(InstanceName), \
>>>> + .abstract = ABSTRACT, \
>>
>> IIUC we don't want to have abstract type with interfaces, but
>> only QOM leaves. So maybe better always use .abstract = false in
>> DEFINE_MACHINE_EXTENDED()?
>
> Where did you get that from? What about these then:
>
> static const TypeInfo pnv_psi_info
> static const TypeInfo spapr_machine_info
> static const TypeInfo e1000_base_info
> static const TypeInfo ivshmem_common_info
> static const TypeInfo macio_type_info
> static const TypeInfo bus_info
> static const TypeInfo device_type_info
> static const TypeInfo hppa_machine_types
> static const TypeInfo qxl_pci_type_info
> static const TypeInfo pic_common_type
> static const TypeInfo xive2_router_info
> static const TypeInfo arm_gic_common_type
> static const TypeInfo arm_gicv3_common_type
> static const TypeInfo ioapic_common_type
> static const TypeInfo loongarch_extioi_common_types
> static const TypeInfo rp_info
> static const TypeInfo virt_machine_info (hw/arm/virt.c)
> static const TypeInfo mps2tz_info
> static const TypeInfo armsse_info
> static const TypeInfo m48txx_isa_type_info
> static const TypeInfo m48txx_sysbus_type_info
> static const TypeInfo pci_ide_type_info
> static const TypeInfo ccw_machine_info
> static const TypeInfo virtio_ccw_md_info
> static const TypeInfo pc_machine_info
> static const TypeInfo x86_machine_info
> static const TypeInfo vfio_pci_device_info
> static const TypeInfo ehci_pci_type_info
> static const TypeInfo xhci_pci_info
> static const TypeInfo uhci_pci_type_info
> static const TypeInfo via_pm_info
> static const TypeInfo via_isa_info
> static const TypeInfo piix_pci_type_info
> static const TypeInfo pcie_slot_type_info
> static const TypeInfo pci_bridge_type_info
> static const TypeInfo intel_hda_info
> static const TypeInfo virtio_md_pci_info
>
>>>> + .interfaces = (const InterfaceInfo[]) { __VA_ARGS__ } , \
>>>
>>> IIUC Richard asked for array argument in order to save .rodata?
>
> Do you have an example for that? I'm not sure what do you mean.
>
> Regards,
> BALATON Zoltan
>
>>>> }; \
>>>> static void machine_initfn##_register_types(void) \
>>>> { \
>>>> @@ -779,6 +783,14 @@ struct MachineState {
>>>> } \
>>>> type_init(machine_initfn##_register_types)
>>>> +#define DEFINE_MACHINE(namestr, machine_initfn) \
>>>> + DEFINE_MACHINE_EXTENDED(namestr, MACHINE, MachineState,
>>>> machine_initfn, \
>>>> + false, { })
>>>> +
>>>> +#define DEFINE_MACHINE_WITH_INTERFACES(namestr, machine_initfn, ...) \
>>>> + DEFINE_MACHINE_EXTENDED(namestr, MACHINE, MachineState,
>>>> machine_initfn, \
>>>> + false, __VA_ARGS__)
>>>> +
>>>> extern GlobalProperty hw_compat_10_1[];
>>>> extern const size_t hw_compat_10_1_len;
>>
>>
On 20/10/25 17:11, Philippe Mathieu-Daudé wrote:
> +Pierrick
>
> On 20/10/25 17:05, Philippe Mathieu-Daudé wrote:
>> On 18/10/25 17:11, BALATON Zoltan wrote:
>>> Add a more general DEFINE_MACHINE_EXTENDED macro and define simpler
>>> versions with less parameters based on that. This is inspired by how
>>> the OBJECT_DEFINE macros do this in a similar way to allow using the
>>> shortened definition in more complex cases too.
>>>
>>> Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
>>> ---
>>> include/hw/boards.h | 16 ++++++++++++++--
>>> 1 file changed, 14 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/include/hw/boards.h b/include/hw/boards.h
>>> index 665b620121..fd3d549ff5 100644
>>> --- a/include/hw/boards.h
>>> +++ b/include/hw/boards.h
>>> @@ -762,7 +762,8 @@ struct MachineState {
>>> } \
>>> } while (0)
>>> -#define DEFINE_MACHINE(namestr, machine_initfn) \
>>> +#define DEFINE_MACHINE_EXTENDED(namestr, PARENT_NAME, InstanceName, \
>>> + machine_initfn, ABSTRACT, ...) \
>>> static void machine_initfn##_class_init(ObjectClass *oc, const
>>> void *data) \
>>> { \
>>> MachineClass *mc = MACHINE_CLASS(oc); \
>>> @@ -770,8 +771,11 @@ struct MachineState {
>>> } \
>>> static const TypeInfo machine_initfn##_typeinfo = { \
>>> .name = MACHINE_TYPE_NAME(namestr), \
>>> - .parent = TYPE_MACHINE, \
>>> + .parent = TYPE_##PARENT_NAME, \
>>> .class_init = machine_initfn##_class_init, \
>>> + .instance_size = sizeof(InstanceName), \
>>> + .abstract = ABSTRACT, \
>
> IIUC we don't want to have abstract type with interfaces, but
> only QOM leaves. So maybe better always use .abstract = false in
> DEFINE_MACHINE_EXTENDED()?
>
>>> + .interfaces = (const InterfaceInfo[]) { __VA_ARGS__ } , \
>>
>> IIUC Richard asked for array argument in order to save .rodata?
>>
>>> }; \
>>> static void machine_initfn##_register_types(void) \
>>> { \
>>> @@ -779,6 +783,14 @@ struct MachineState {
>>> } \
>>> type_init(machine_initfn##_register_types)
>>> +#define DEFINE_MACHINE(namestr, machine_initfn) \
>>> + DEFINE_MACHINE_EXTENDED(namestr, MACHINE, MachineState,
>>> machine_initfn, \
>>> + false, { })
>>> +
>>> +#define DEFINE_MACHINE_WITH_INTERFACES(namestr, machine_initfn, ...) \
>>> + DEFINE_MACHINE_EXTENDED(namestr, MACHINE, MachineState,
>>> machine_initfn, \
>>> + false, __VA_ARGS__)
Hmm how can be sure the __VA_ARGS__ argument is { NULL } terminated?
>>> +
>>> extern GlobalProperty hw_compat_10_1[];
>>> extern const size_t hw_compat_10_1_len;
>
On Mon, 20 Oct 2025, Philippe Mathieu-Daudé wrote:
> On 20/10/25 17:11, Philippe Mathieu-Daudé wrote:
>> +Pierrick
>>
>> On 20/10/25 17:05, Philippe Mathieu-Daudé wrote:
>>> On 18/10/25 17:11, BALATON Zoltan wrote:
>>>> Add a more general DEFINE_MACHINE_EXTENDED macro and define simpler
>>>> versions with less parameters based on that. This is inspired by how
>>>> the OBJECT_DEFINE macros do this in a similar way to allow using the
>>>> shortened definition in more complex cases too.
>>>>
>>>> Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
>>>> ---
>>>> include/hw/boards.h | 16 ++++++++++++++--
>>>> 1 file changed, 14 insertions(+), 2 deletions(-)
>>>>
>>>> diff --git a/include/hw/boards.h b/include/hw/boards.h
>>>> index 665b620121..fd3d549ff5 100644
>>>> --- a/include/hw/boards.h
>>>> +++ b/include/hw/boards.h
>>>> @@ -762,7 +762,8 @@ struct MachineState {
>>>> } \
>>>> } while (0)
>>>> -#define DEFINE_MACHINE(namestr, machine_initfn) \
>>>> +#define DEFINE_MACHINE_EXTENDED(namestr, PARENT_NAME, InstanceName, \
>>>> + machine_initfn, ABSTRACT, ...) \
>>>> static void machine_initfn##_class_init(ObjectClass *oc, const void
>>>> *data) \
>>>> { \
>>>> MachineClass *mc = MACHINE_CLASS(oc); \
>>>> @@ -770,8 +771,11 @@ struct MachineState {
>>>> } \
>>>> static const TypeInfo machine_initfn##_typeinfo = { \
>>>> .name = MACHINE_TYPE_NAME(namestr), \
>>>> - .parent = TYPE_MACHINE, \
>>>> + .parent = TYPE_##PARENT_NAME, \
>>>> .class_init = machine_initfn##_class_init, \
>>>> + .instance_size = sizeof(InstanceName), \
>>>> + .abstract = ABSTRACT, \
>>
>> IIUC we don't want to have abstract type with interfaces, but
>> only QOM leaves. So maybe better always use .abstract = false in
>> DEFINE_MACHINE_EXTENDED()?
>>
>>>> + .interfaces = (const InterfaceInfo[]) { __VA_ARGS__ } , \
>>>
>>> IIUC Richard asked for array argument in order to save .rodata?
>>>
>>>> }; \
>>>> static void machine_initfn##_register_types(void) \
>>>> { \
>>>> @@ -779,6 +783,14 @@ struct MachineState {
>>>> } \
>>>> type_init(machine_initfn##_register_types)
>>>> +#define DEFINE_MACHINE(namestr, machine_initfn) \
>>>> + DEFINE_MACHINE_EXTENDED(namestr, MACHINE, MachineState,
>>>> machine_initfn, \
>>>> + false, { })
>>>> +
>>>> +#define DEFINE_MACHINE_WITH_INTERFACES(namestr, machine_initfn, ...) \
>>>> + DEFINE_MACHINE_EXTENDED(namestr, MACHINE, MachineState,
>>>> machine_initfn, \
>>>> + false, __VA_ARGS__)
>
> Hmm how can be sure the __VA_ARGS__ argument is { NULL } terminated?
The same way as for OBJECT_DEFINE_TYPE_EXTENDED. This is modelled after
that as noted in the commit message.
Regards,
BALATON Zoltan
>>>> +
>>>> extern GlobalProperty hw_compat_10_1[];
>>>> extern const size_t hw_compat_10_1_len;
>>
>
>
© 2016 - 2025 Red Hat, Inc.