Skip to content

Avoid defining custom machine-definition macros for each new machine type

Goal

In include/hw/boards.h, there is a large comment providing a template for a #define DEFINE_VIRT_MACHINE_IMPL( macro implementing machine type versioning, which we are to adapt for each machine type.

The adaptations are not terribly complex, but still, very much mixed into the body of the functions being generated. As such, they are error prone, and any changes to the implementation need to be repeated for each machine type.

Would it not be wiser to define a generic version of this macro which accepts all the adaptations as parameters?

Technical details

The big macro isn't expected to be used directly anyway, but rather via helper wrapper macros:

 *  #define DEFINE_VIRT_MACHINE_LATEST(major, minor) \
 *      DEFINE_VIRT_MACHINE_IMPL(true, major, minor)
 *
 *  // Normal 2 digit e.g. 'virt-9.0'
 *  #define DEFINE_VIRT_MACHINE(major, minor) \
 *      DEFINE_VIRT_MACHINE_IMPL(false, major, minor)

So the machine-specific adaptations could be #defined in a helper macro that expands into the generic macro.

Additional information

There are already some semi-generic implementations of this macro, such as DEFINE_PC_VER_MACHINE(), which is used for the 'q35', 'pc' and 'isapc' machine types.

There does appear to be some deviation from the template macro in some cases. We would have to enumerate what the nature of these deviations is, why only some machine types need them, and how they would fit into the proposed generic macro. Still, if we could have a generic macro that simplifies 80% of machine types' version definitions, then that seems like a win.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information