> Move PCSouthBridgeOption from a hand-rolled C enum to a proper QAPI
> enum in qapi/machine.json.
> 
> This gives the x-south-bridge property a generated type_info with a
> valid masked_name, so it appears in query-qmp-schema introspection and
> the qapi-type field of qom-list-properties output.
> 
> The south_bridge/default_south_bridge fields change from const char *
> to PCSouthBridgeOption, with an explicit mapping table from enum value
> to QOM device type name.
> 
> Signed-off-by: Marc-AndrĂ© Lureau <[email protected]>
> Signed-off-by: Markus Armbruster <[email protected]>
> Message-ID: <[email protected]>
> ---
>  qapi/machine.json    | 14 ++++++++++
>  include/hw/i386/pc.h |  4 +--
>  hw/i386/pc_piix.c    | 61 +++++++++++++-------------------------------
>  3 files changed, 34 insertions(+), 45 deletions(-)
>
> diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
> index 63c4667ea372..5a94a34166d8 100644
> --- a/hw/i386/pc_piix.c
> +++ b/hw/i386/pc_piix.c
> @@ -47,6 +47,7 @@
>  #include "hw/acpi/acpi.h"
>  #include "hw/vfio/types.h"
>  #include "qapi/error.h"
> +#include "qapi/qapi-type-infos-machine.h"
>  #include "qemu/error-report.h"
>  #include "system/xen.h"
>  #ifdef CONFIG_XEN
> @@ -75,6 +76,11 @@ static GlobalProperty pc_piix_compat_defaults[] = {
>  static const size_t pc_piix_compat_defaults_len =
>      G_N_ELEMENTS(pc_piix_compat_defaults);
>  
> +static const char *pc_south_bridge_type[] = {
> +    [PC_SOUTH_BRIDGE_OPTION_PIIX3] = TYPE_PIIX3_DEVICE,
> +    [PC_SOUTH_BRIDGE_OPTION_PIIX4] = TYPE_PIIX4_PCI_DEVICE,
> +};

We could have
G_STATIC_ASSERT(G_N_ELEMENTS(pc_south_bridge_type), PC_SOUTH_BRIDGE_OPTION_LAST)
or something

> +
>  /*
>   * Return the global irq number corresponding to a given device irq
>   * pin. We could also use the bus number to have a more precise mapping.
> @@ -236,7 +242,8 @@ static void pc_init1(MachineState *machine, const char 
> *pci_type)
>  
>      gsi_state = pc_gsi_create(&x86ms->gsi, true);
>  
> -    pci_dev = pci_new_multifunction(-1, pcms->south_bridge);
> +    pci_dev = pci_new_multifunction(-1,
> +                                    
> pc_south_bridge_type[pcms->south_bridge]);
>      object_property_set_bool(OBJECT(pci_dev), "has-usb",
>                               machine_usb(machine), &error_abort);
>      object_property_set_bool(OBJECT(pci_dev), "has-acpi",
> @@ -317,51 +324,18 @@ static void pc_init1(MachineState *machine, const char 
> *pci_type)
>      }
>  }
>  
> -typedef enum PCSouthBridgeOption {
> -    PC_SOUTH_BRIDGE_OPTION_PIIX3,
> -    PC_SOUTH_BRIDGE_OPTION_PIIX4,
> -    PC_SOUTH_BRIDGE_OPTION_MAX,
> -} PCSouthBridgeOption;
> -
> -static const QEnumLookup PCSouthBridgeOption_lookup = {

The commit message should mention that enum values have been replaced:
PIIX3->ppix3, piix4-isa->piix4

Since it's a x- property, I suppose it is not a breaking change.

-- 
Marc-AndrĂ© Lureau <[email protected]>


Reply via email to