diff mbox series

[RFC,12/19] hw/i386: Set QDev properties using QDev API

Message ID 20230203180914.49112-13-philmd@linaro.org
State New
Headers show
Series hw: Set QDev properties using QDev API (part 1/3) | expand

Commit Message

Philippe Mathieu-Daudé Feb. 3, 2023, 6:09 p.m. UTC
No need to use the low-level QOM API when an object
inherits from QDev. Directly use the QDev API to set
its properties.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/i386/pc.c           |  8 +++-----
 hw/i386/pc_q35.c       | 25 +++++++++++--------------
 hw/i386/sgx.c          |  3 +--
 hw/i386/x86.c          | 12 ++++--------
 hw/mem/pc-dimm.c       |  5 ++---
 target/i386/cpu.c      |  6 ++----
 target/i386/host-cpu.c |  7 +++----
 7 files changed, 26 insertions(+), 40 deletions(-)

Comments

Bernhard Beschow Feb. 4, 2023, 1:23 p.m. UTC | #1
Am 3. Februar 2023 18:09:07 UTC schrieb "Philippe Mathieu-Daudé" <philmd@linaro.org>:
>No need to use the low-level QOM API when an object
>inherits from QDev. Directly use the QDev API to set
>its properties.
>
>Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
>---
> hw/i386/pc.c           |  8 +++-----
> hw/i386/pc_q35.c       | 25 +++++++++++--------------
> hw/i386/sgx.c          |  3 +--
> hw/i386/x86.c          | 12 ++++--------
> hw/mem/pc-dimm.c       |  5 ++---
> target/i386/cpu.c      |  6 ++----
> target/i386/host-cpu.c |  7 +++----
> 7 files changed, 26 insertions(+), 40 deletions(-)
>
>diff --git a/hw/i386/pc.c b/hw/i386/pc.c
>index 6e592bd969..700fdefa12 100644
>--- a/hw/i386/pc.c
>+++ b/hw/i386/pc.c
>@@ -1236,8 +1236,7 @@ static void pc_superio_init(ISABus *isa_bus, bool create_fdctrl,
>         vmmouse = NULL;
>     }
>     if (vmmouse) {
>-        object_property_set_link(OBJECT(vmmouse), TYPE_I8042, OBJECT(i8042),
>-                                 &error_abort);
>+        qdev_prop_set_link(DEVICE(vmmouse), TYPE_I8042, OBJECT(i8042));
>         isa_realize_and_unref(vmmouse, isa_bus, &error_fatal);
>     }
>     port92 = isa_create_simple(isa_bus, TYPE_PORT92);
>@@ -1538,9 +1537,8 @@ static void pc_machine_device_pre_plug_cb(HotplugHandler *hotplug_dev,
>         char *resv_prop_str = g_strdup_printf("0xfee00000:0xfeefffff:%d",
>                                               VIRTIO_IOMMU_RESV_MEM_T_MSI);
> 
>-        object_property_set_uint(OBJECT(dev), "len-reserved-regions", 1, errp);
>-        object_property_set_str(OBJECT(dev), "reserved-regions[0]",
>-                                resv_prop_str, errp);
>+        qdev_prop_set_uint32(dev, "len-reserved-regions", 1);
>+        qdev_prop_set_string(dev, "reserved-regions[0]", resv_prop_str);
>         g_free(resv_prop_str);
>     }
> 
>diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
>index 66cd718b70..760efa62ca 100644
>--- a/hw/i386/pc_q35.c
>+++ b/hw/i386/pc_q35.c
>@@ -118,7 +118,7 @@ static void pc_q35_init(MachineState *machine)
>     PCMachineState *pcms = PC_MACHINE(machine);
>     PCMachineClass *pcmc = PC_MACHINE_GET_CLASS(pcms);
>     X86MachineState *x86ms = X86_MACHINE(machine);
>-    Q35PCIHost *q35_host;
>+    DeviceState *q35_host;
>     PCIHostState *phb;

While at it, you could incorporate this change: https://lore.kernel.org/qemu-devel/20230131115326.12454-5-shentey@gmail.com/ , i.e. resolve the now redundant q35_host variable and use phb instead as DeviceState.

I'll drop the patch from my series in favor of yours.

Best regards,
Bernhard

>     PCIBus *host_bus;
>     PCIDevice *lpc;
>@@ -206,7 +206,7 @@ static void pc_q35_init(MachineState *machine)
>     }
> 
>     /* create pci host bus */
>-    q35_host = Q35_HOST_DEVICE(qdev_new(TYPE_Q35_HOST_DEVICE));
>+    q35_host = qdev_new(TYPE_Q35_HOST_DEVICE);
> 
>     if (pcmc->pci_enabled) {
>         pci_hole64_size = object_property_get_uint(OBJECT(q35_host),
>@@ -219,18 +219,15 @@ static void pc_q35_init(MachineState *machine)
>                    pci_hole64_size);
> 
>     object_property_add_child(qdev_get_machine(), "q35", OBJECT(q35_host));
>-    object_property_set_link(OBJECT(q35_host), MCH_HOST_PROP_RAM_MEM,
>-                             OBJECT(ram_memory), NULL);
>-    object_property_set_link(OBJECT(q35_host), MCH_HOST_PROP_PCI_MEM,
>-                             OBJECT(pci_memory), NULL);
>-    object_property_set_link(OBJECT(q35_host), MCH_HOST_PROP_SYSTEM_MEM,
>-                             OBJECT(get_system_memory()), NULL);
>-    object_property_set_link(OBJECT(q35_host), MCH_HOST_PROP_IO_MEM,
>-                             OBJECT(system_io), NULL);
>-    object_property_set_int(OBJECT(q35_host), PCI_HOST_BELOW_4G_MEM_SIZE,
>-                            x86ms->below_4g_mem_size, NULL);
>-    object_property_set_int(OBJECT(q35_host), PCI_HOST_ABOVE_4G_MEM_SIZE,
>-                            x86ms->above_4g_mem_size, NULL);
>+    qdev_prop_set_link(q35_host, MCH_HOST_PROP_RAM_MEM, OBJECT(ram_memory));
>+    qdev_prop_set_link(q35_host, MCH_HOST_PROP_PCI_MEM, OBJECT(pci_memory));
>+    qdev_prop_set_link(q35_host, MCH_HOST_PROP_IO_MEM, OBJECT(system_io));
>+    qdev_prop_set_link(q35_host, MCH_HOST_PROP_SYSTEM_MEM,
>+                       OBJECT(get_system_memory()));
>+    qdev_prop_set_uint64(q35_host, PCI_HOST_BELOW_4G_MEM_SIZE,
>+                         x86ms->below_4g_mem_size);
>+    qdev_prop_set_uint64(q35_host, PCI_HOST_ABOVE_4G_MEM_SIZE,
>+                         x86ms->above_4g_mem_size);
>     /* pci */
>     sysbus_realize_and_unref(SYS_BUS_DEVICE(q35_host), &error_fatal);
>     phb = PCI_HOST_BRIDGE(q35_host);
>diff --git a/hw/i386/sgx.c b/hw/i386/sgx.c
>index 6a729bff94..196fa5afee 100644
>--- a/hw/i386/sgx.c
>+++ b/hw/i386/sgx.c
>@@ -304,8 +304,7 @@ void pc_machine_init_sgx_epc(PCMachineState *pcms)
>         object_property_parse(OBJECT(dev), SGX_EPC_MEMDEV_PROP,
>                               list->value->memdev, &error_fatal);
>         /* set the numa node property for sgx epc object */
>-        object_property_set_uint(OBJECT(dev), SGX_EPC_NUMA_NODE_PROP,
>-                                 list->value->node, &error_fatal);
>+        qdev_prop_set_uint32(dev, SGX_EPC_NUMA_NODE_PROP, list->value->node);
>         qdev_realize_and_unref(dev, NULL, &error_fatal);
>     }
> 
>diff --git a/hw/i386/x86.c b/hw/i386/x86.c
>index eaff4227bd..191a8c36ee 100644
>--- a/hw/i386/x86.c
>+++ b/hw/i386/x86.c
>@@ -43,6 +43,7 @@
> #include "sysemu/xen.h"
> #include "trace.h"
> 
>+#include "hw/qdev-properties.h"
> #include "hw/i386/x86.h"
> #include "target/i386/cpu.h"
> #include "hw/i386/topology.h"
>@@ -96,15 +97,10 @@ uint32_t x86_cpu_apic_id_from_index(X86MachineState *x86ms,
> 
> void x86_cpu_new(X86MachineState *x86ms, int64_t apic_id, Error **errp)
> {
>-    Object *cpu = object_new(MACHINE(x86ms)->cpu_type);
>+    DeviceState *cpu = DEVICE(object_new(MACHINE(x86ms)->cpu_type));
> 
>-    if (!object_property_set_uint(cpu, "apic-id", apic_id, errp)) {
>-        goto out;
>-    }
>-    qdev_realize(DEVICE(cpu), NULL, errp);
>-
>-out:
>-    object_unref(cpu);
>+    qdev_prop_set_uint32(cpu, "apic-id", apic_id);
>+    qdev_realize(cpu, NULL, errp);
> }
> 
> void x86_cpus_init(X86MachineState *x86ms, int default_cpu_version)
>diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c
>index 50ef83215c..d6e0c8b680 100644
>--- a/hw/mem/pc-dimm.c
>+++ b/hw/mem/pc-dimm.c
>@@ -66,8 +66,7 @@ void pc_dimm_pre_plug(PCDIMMDevice *dimm, MachineState *machine,
>         error_propagate(errp, local_err);
>         return;
>     }
>-    object_property_set_int(OBJECT(dimm), PC_DIMM_SLOT_PROP, slot,
>-                            &error_abort);
>+    qdev_prop_set_int32(DEVICE(dimm), PC_DIMM_SLOT_PROP, slot);
>     trace_mhp_pc_dimm_assigned_slot(slot);
> 
>     memory_device_pre_plug(MEMORY_DEVICE(dimm), machine, legacy_align,
>@@ -234,7 +233,7 @@ static uint64_t pc_dimm_md_get_addr(const MemoryDeviceState *md)
> static void pc_dimm_md_set_addr(MemoryDeviceState *md, uint64_t addr,
>                                 Error **errp)
> {
>-    object_property_set_uint(OBJECT(md), PC_DIMM_ADDR_PROP, addr, errp);
>+    qdev_prop_set_uint64(DEVICE(md), PC_DIMM_ADDR_PROP, addr);
> }
> 
> static MemoryRegion *pc_dimm_md_get_memory_region(MemoryDeviceState *md,
>diff --git a/target/i386/cpu.c b/target/i386/cpu.c
>index 4d2b8d0444..5532cd42c5 100644
>--- a/target/i386/cpu.c
>+++ b/target/i386/cpu.c
>@@ -5073,10 +5073,8 @@ static void x86_cpu_load_model(X86CPU *cpu, X86CPUModel *model)
>      */
> 
>     /* CPU models only set _minimum_ values for level/xlevel: */
>-    object_property_set_uint(OBJECT(cpu), "min-level", def->level,
>-                             &error_abort);
>-    object_property_set_uint(OBJECT(cpu), "min-xlevel", def->xlevel,
>-                             &error_abort);
>+    qdev_prop_set_uint32(DEVICE(cpu), "min-level", def->level);
>+    qdev_prop_set_uint32(DEVICE(cpu), "min-xlevel", def->xlevel);
> 
>     object_property_set_int(OBJECT(cpu), "family", def->family, &error_abort);
>     object_property_set_int(OBJECT(cpu), "model", def->model, &error_abort);
>diff --git a/target/i386/host-cpu.c b/target/i386/host-cpu.c
>index 10f8aba86e..0307eaa208 100644
>--- a/target/i386/host-cpu.c
>+++ b/target/i386/host-cpu.c
>@@ -158,7 +158,7 @@ void host_cpu_instance_init(X86CPU *cpu)
> 
>         host_cpuid(0, 0, NULL, &ebx, &ecx, &edx);
>         x86_cpu_vendor_words2str(vendor, ebx, edx, ecx);
>-        object_property_set_str(OBJECT(cpu), "vendor", vendor, &error_abort);
>+        qdev_prop_set_string(DEVICE(cpu), "vendor", vendor);
>     }
> }
> 
>@@ -174,13 +174,12 @@ void host_cpu_max_instance_init(X86CPU *cpu)
>     host_cpu_vendor_fms(vendor, &family, &model, &stepping);
>     host_cpu_fill_model_id(model_id);
> 
>-    object_property_set_str(OBJECT(cpu), "vendor", vendor, &error_abort);
>+    qdev_prop_set_string(DEVICE(cpu), "vendor", vendor);
>     object_property_set_int(OBJECT(cpu), "family", family, &error_abort);
>     object_property_set_int(OBJECT(cpu), "model", model, &error_abort);
>     object_property_set_int(OBJECT(cpu), "stepping", stepping,
>                             &error_abort);
>-    object_property_set_str(OBJECT(cpu), "model-id", model_id,
>-                            &error_abort);
>+    qdev_prop_set_string(DEVICE(cpu), "model-id", model_id);
> }
> 
> static void host_cpu_class_init(ObjectClass *oc, void *data)
Igor Mammedov March 1, 2023, 2 p.m. UTC | #2
On Fri,  3 Feb 2023 19:09:07 +0100
Philippe Mathieu-Daudé <philmd@linaro.org> wrote:

> No need to use the low-level QOM API when an object
> inherits from QDev. Directly use the QDev API to set
> its properties.
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>  hw/i386/pc.c           |  8 +++-----
>  hw/i386/pc_q35.c       | 25 +++++++++++--------------
>  hw/i386/sgx.c          |  3 +--
>  hw/i386/x86.c          | 12 ++++--------
>  hw/mem/pc-dimm.c       |  5 ++---
>  target/i386/cpu.c      |  6 ++----
>  target/i386/host-cpu.c |  7 +++----
>  7 files changed, 26 insertions(+), 40 deletions(-)
> 
> diff --git a/hw/i386/pc.c b/hw/i386/pc.c
> index 6e592bd969..700fdefa12 100644
> --- a/hw/i386/pc.c
> +++ b/hw/i386/pc.c
> @@ -1236,8 +1236,7 @@ static void pc_superio_init(ISABus *isa_bus, bool create_fdctrl,
>          vmmouse = NULL;
>      }
>      if (vmmouse) {
> -        object_property_set_link(OBJECT(vmmouse), TYPE_I8042, OBJECT(i8042),
> -                                 &error_abort);
> +        qdev_prop_set_link(DEVICE(vmmouse), TYPE_I8042, OBJECT(i8042));
>          isa_realize_and_unref(vmmouse, isa_bus, &error_fatal);
>      }
>      port92 = isa_create_simple(isa_bus, TYPE_PORT92);
> @@ -1538,9 +1537,8 @@ static void pc_machine_device_pre_plug_cb(HotplugHandler *hotplug_dev,
>          char *resv_prop_str = g_strdup_printf("0xfee00000:0xfeefffff:%d",
>                                                VIRTIO_IOMMU_RESV_MEM_T_MSI);
>  
> -        object_property_set_uint(OBJECT(dev), "len-reserved-regions", 1, errp);
> -        object_property_set_str(OBJECT(dev), "reserved-regions[0]",
> -                                resv_prop_str, errp);
> +        qdev_prop_set_uint32(dev, "len-reserved-regions", 1);
> +        qdev_prop_set_string(dev, "reserved-regions[0]", resv_prop_str);

this is wrong, you can do above only if failure is not expected (i.e. error_abort)


>          g_free(resv_prop_str);
>      }
>  
> diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
> index 66cd718b70..760efa62ca 100644
> --- a/hw/i386/pc_q35.c
> +++ b/hw/i386/pc_q35.c
> @@ -118,7 +118,7 @@ static void pc_q35_init(MachineState *machine)
>      PCMachineState *pcms = PC_MACHINE(machine);
>      PCMachineClass *pcmc = PC_MACHINE_GET_CLASS(pcms);
>      X86MachineState *x86ms = X86_MACHINE(machine);
> -    Q35PCIHost *q35_host;
> +    DeviceState *q35_host;
>      PCIHostState *phb;
>      PCIBus *host_bus;
>      PCIDevice *lpc;
> @@ -206,7 +206,7 @@ static void pc_q35_init(MachineState *machine)
>      }
>  
>      /* create pci host bus */
> -    q35_host = Q35_HOST_DEVICE(qdev_new(TYPE_Q35_HOST_DEVICE));
> +    q35_host = qdev_new(TYPE_Q35_HOST_DEVICE);
>  
>      if (pcmc->pci_enabled) {
>          pci_hole64_size = object_property_get_uint(OBJECT(q35_host),
> @@ -219,18 +219,15 @@ static void pc_q35_init(MachineState *machine)
>                     pci_hole64_size);
>  
>      object_property_add_child(qdev_get_machine(), "q35", OBJECT(q35_host));
> -    object_property_set_link(OBJECT(q35_host), MCH_HOST_PROP_RAM_MEM,
> -                             OBJECT(ram_memory), NULL);
> -    object_property_set_link(OBJECT(q35_host), MCH_HOST_PROP_PCI_MEM,
> -                             OBJECT(pci_memory), NULL);
> -    object_property_set_link(OBJECT(q35_host), MCH_HOST_PROP_SYSTEM_MEM,
> -                             OBJECT(get_system_memory()), NULL);
> -    object_property_set_link(OBJECT(q35_host), MCH_HOST_PROP_IO_MEM,
> -                             OBJECT(system_io), NULL);
> -    object_property_set_int(OBJECT(q35_host), PCI_HOST_BELOW_4G_MEM_SIZE,
> -                            x86ms->below_4g_mem_size, NULL);
> -    object_property_set_int(OBJECT(q35_host), PCI_HOST_ABOVE_4G_MEM_SIZE,
> -                            x86ms->above_4g_mem_size, NULL);
> +    qdev_prop_set_link(q35_host, MCH_HOST_PROP_RAM_MEM, OBJECT(ram_memory));
> +    qdev_prop_set_link(q35_host, MCH_HOST_PROP_PCI_MEM, OBJECT(pci_memory));
> +    qdev_prop_set_link(q35_host, MCH_HOST_PROP_IO_MEM, OBJECT(system_io));
> +    qdev_prop_set_link(q35_host, MCH_HOST_PROP_SYSTEM_MEM,
> +                       OBJECT(get_system_memory()));
> +    qdev_prop_set_uint64(q35_host, PCI_HOST_BELOW_4G_MEM_SIZE,
> +                         x86ms->below_4g_mem_size);
> +    qdev_prop_set_uint64(q35_host, PCI_HOST_ABOVE_4G_MEM_SIZE,
> +                         x86ms->above_4g_mem_size);
>      /* pci */
>      sysbus_realize_and_unref(SYS_BUS_DEVICE(q35_host), &error_fatal);
>      phb = PCI_HOST_BRIDGE(q35_host);
> diff --git a/hw/i386/sgx.c b/hw/i386/sgx.c
> index 6a729bff94..196fa5afee 100644
> --- a/hw/i386/sgx.c
> +++ b/hw/i386/sgx.c
> @@ -304,8 +304,7 @@ void pc_machine_init_sgx_epc(PCMachineState *pcms)
>          object_property_parse(OBJECT(dev), SGX_EPC_MEMDEV_PROP,
>                                list->value->memdev, &error_fatal);
>          /* set the numa node property for sgx epc object */
> -        object_property_set_uint(OBJECT(dev), SGX_EPC_NUMA_NODE_PROP,
> -                                 list->value->node, &error_fatal);
> +        qdev_prop_set_uint32(dev, SGX_EPC_NUMA_NODE_PROP, list->value->node);
>          qdev_realize_and_unref(dev, NULL, &error_fatal);
>      }
>  
> diff --git a/hw/i386/x86.c b/hw/i386/x86.c
> index eaff4227bd..191a8c36ee 100644
> --- a/hw/i386/x86.c
> +++ b/hw/i386/x86.c
> @@ -43,6 +43,7 @@
>  #include "sysemu/xen.h"
>  #include "trace.h"
>  
> +#include "hw/qdev-properties.h"
>  #include "hw/i386/x86.h"
>  #include "target/i386/cpu.h"
>  #include "hw/i386/topology.h"
> @@ -96,15 +97,10 @@ uint32_t x86_cpu_apic_id_from_index(X86MachineState *x86ms,
>  
>  void x86_cpu_new(X86MachineState *x86ms, int64_t apic_id, Error **errp)
>  {
> -    Object *cpu = object_new(MACHINE(x86ms)->cpu_type);
> +    DeviceState *cpu = DEVICE(object_new(MACHINE(x86ms)->cpu_type));
>  
> -    if (!object_property_set_uint(cpu, "apic-id", apic_id, errp)) {
> -        goto out;
> -    }
> -    qdev_realize(DEVICE(cpu), NULL, errp);
> -
> -out:
> -    object_unref(cpu);
you are loosing reference here

> +    qdev_prop_set_uint32(cpu, "apic-id", apic_id);

broken

> +    qdev_realize(cpu, NULL, errp);
>  }

I'd drop this whole hunk, as unnecessary
 
>  
>  void x86_cpus_init(X86MachineState *x86ms, int default_cpu_version)
> diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c
> index 50ef83215c..d6e0c8b680 100644
> --- a/hw/mem/pc-dimm.c
> +++ b/hw/mem/pc-dimm.c
> @@ -66,8 +66,7 @@ void pc_dimm_pre_plug(PCDIMMDevice *dimm, MachineState *machine,
>          error_propagate(errp, local_err);
>          return;
>      }
> -    object_property_set_int(OBJECT(dimm), PC_DIMM_SLOT_PROP, slot,
> -                            &error_abort);
> +    qdev_prop_set_int32(DEVICE(dimm), PC_DIMM_SLOT_PROP, slot);
>      trace_mhp_pc_dimm_assigned_slot(slot);
>  
>      memory_device_pre_plug(MEMORY_DEVICE(dimm), machine, legacy_align,
> @@ -234,7 +233,7 @@ static uint64_t pc_dimm_md_get_addr(const MemoryDeviceState *md)
>  static void pc_dimm_md_set_addr(MemoryDeviceState *md, uint64_t addr,
>                                  Error **errp)
>  {
> -    object_property_set_uint(OBJECT(md), PC_DIMM_ADDR_PROP, addr, errp);
> +    qdev_prop_set_uint64(DEVICE(md), PC_DIMM_ADDR_PROP, addr);
ditto

>  }
>  
>  static MemoryRegion *pc_dimm_md_get_memory_region(MemoryDeviceState *md,
> diff --git a/target/i386/cpu.c b/target/i386/cpu.c
> index 4d2b8d0444..5532cd42c5 100644
> --- a/target/i386/cpu.c
> +++ b/target/i386/cpu.c
> @@ -5073,10 +5073,8 @@ static void x86_cpu_load_model(X86CPU *cpu, X86CPUModel *model)
>       */
>  
>      /* CPU models only set _minimum_ values for level/xlevel: */
> -    object_property_set_uint(OBJECT(cpu), "min-level", def->level,
> -                             &error_abort);
> -    object_property_set_uint(OBJECT(cpu), "min-xlevel", def->xlevel,
> -                             &error_abort);
> +    qdev_prop_set_uint32(DEVICE(cpu), "min-level", def->level);
> +    qdev_prop_set_uint32(DEVICE(cpu), "min-xlevel", def->xlevel);
>  
>      object_property_set_int(OBJECT(cpu), "family", def->family, &error_abort);
>      object_property_set_int(OBJECT(cpu), "model", def->model, &error_abort);
> diff --git a/target/i386/host-cpu.c b/target/i386/host-cpu.c
> index 10f8aba86e..0307eaa208 100644
> --- a/target/i386/host-cpu.c
> +++ b/target/i386/host-cpu.c
> @@ -158,7 +158,7 @@ void host_cpu_instance_init(X86CPU *cpu)
>  
>          host_cpuid(0, 0, NULL, &ebx, &ecx, &edx);
>          x86_cpu_vendor_words2str(vendor, ebx, edx, ecx);
> -        object_property_set_str(OBJECT(cpu), "vendor", vendor, &error_abort);
> +        qdev_prop_set_string(DEVICE(cpu), "vendor", vendor);
>      }
>  }
>  
> @@ -174,13 +174,12 @@ void host_cpu_max_instance_init(X86CPU *cpu)
>      host_cpu_vendor_fms(vendor, &family, &model, &stepping);
>      host_cpu_fill_model_id(model_id);
>  
> -    object_property_set_str(OBJECT(cpu), "vendor", vendor, &error_abort);
> +    qdev_prop_set_string(DEVICE(cpu), "vendor", vendor);
^^^

>      object_property_set_int(OBJECT(cpu), "family", family, &error_abort);
>      object_property_set_int(OBJECT(cpu), "model", model, &error_abort);
>      object_property_set_int(OBJECT(cpu), "stepping", stepping,
>                              &error_abort);
if you do above then do it consistently, I dislike that end result is
a mix of old and new styles.

> -    object_property_set_str(OBJECT(cpu), "model-id", model_id,
> -                            &error_abort);
> +    qdev_prop_set_string(DEVICE(cpu), "model-id", model_id);
>  }
>  
>  static void host_cpu_class_init(ObjectClass *oc, void *data)
diff mbox series

Patch

diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 6e592bd969..700fdefa12 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1236,8 +1236,7 @@  static void pc_superio_init(ISABus *isa_bus, bool create_fdctrl,
         vmmouse = NULL;
     }
     if (vmmouse) {
-        object_property_set_link(OBJECT(vmmouse), TYPE_I8042, OBJECT(i8042),
-                                 &error_abort);
+        qdev_prop_set_link(DEVICE(vmmouse), TYPE_I8042, OBJECT(i8042));
         isa_realize_and_unref(vmmouse, isa_bus, &error_fatal);
     }
     port92 = isa_create_simple(isa_bus, TYPE_PORT92);
@@ -1538,9 +1537,8 @@  static void pc_machine_device_pre_plug_cb(HotplugHandler *hotplug_dev,
         char *resv_prop_str = g_strdup_printf("0xfee00000:0xfeefffff:%d",
                                               VIRTIO_IOMMU_RESV_MEM_T_MSI);
 
-        object_property_set_uint(OBJECT(dev), "len-reserved-regions", 1, errp);
-        object_property_set_str(OBJECT(dev), "reserved-regions[0]",
-                                resv_prop_str, errp);
+        qdev_prop_set_uint32(dev, "len-reserved-regions", 1);
+        qdev_prop_set_string(dev, "reserved-regions[0]", resv_prop_str);
         g_free(resv_prop_str);
     }
 
diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c
index 66cd718b70..760efa62ca 100644
--- a/hw/i386/pc_q35.c
+++ b/hw/i386/pc_q35.c
@@ -118,7 +118,7 @@  static void pc_q35_init(MachineState *machine)
     PCMachineState *pcms = PC_MACHINE(machine);
     PCMachineClass *pcmc = PC_MACHINE_GET_CLASS(pcms);
     X86MachineState *x86ms = X86_MACHINE(machine);
-    Q35PCIHost *q35_host;
+    DeviceState *q35_host;
     PCIHostState *phb;
     PCIBus *host_bus;
     PCIDevice *lpc;
@@ -206,7 +206,7 @@  static void pc_q35_init(MachineState *machine)
     }
 
     /* create pci host bus */
-    q35_host = Q35_HOST_DEVICE(qdev_new(TYPE_Q35_HOST_DEVICE));
+    q35_host = qdev_new(TYPE_Q35_HOST_DEVICE);
 
     if (pcmc->pci_enabled) {
         pci_hole64_size = object_property_get_uint(OBJECT(q35_host),
@@ -219,18 +219,15 @@  static void pc_q35_init(MachineState *machine)
                    pci_hole64_size);
 
     object_property_add_child(qdev_get_machine(), "q35", OBJECT(q35_host));
-    object_property_set_link(OBJECT(q35_host), MCH_HOST_PROP_RAM_MEM,
-                             OBJECT(ram_memory), NULL);
-    object_property_set_link(OBJECT(q35_host), MCH_HOST_PROP_PCI_MEM,
-                             OBJECT(pci_memory), NULL);
-    object_property_set_link(OBJECT(q35_host), MCH_HOST_PROP_SYSTEM_MEM,
-                             OBJECT(get_system_memory()), NULL);
-    object_property_set_link(OBJECT(q35_host), MCH_HOST_PROP_IO_MEM,
-                             OBJECT(system_io), NULL);
-    object_property_set_int(OBJECT(q35_host), PCI_HOST_BELOW_4G_MEM_SIZE,
-                            x86ms->below_4g_mem_size, NULL);
-    object_property_set_int(OBJECT(q35_host), PCI_HOST_ABOVE_4G_MEM_SIZE,
-                            x86ms->above_4g_mem_size, NULL);
+    qdev_prop_set_link(q35_host, MCH_HOST_PROP_RAM_MEM, OBJECT(ram_memory));
+    qdev_prop_set_link(q35_host, MCH_HOST_PROP_PCI_MEM, OBJECT(pci_memory));
+    qdev_prop_set_link(q35_host, MCH_HOST_PROP_IO_MEM, OBJECT(system_io));
+    qdev_prop_set_link(q35_host, MCH_HOST_PROP_SYSTEM_MEM,
+                       OBJECT(get_system_memory()));
+    qdev_prop_set_uint64(q35_host, PCI_HOST_BELOW_4G_MEM_SIZE,
+                         x86ms->below_4g_mem_size);
+    qdev_prop_set_uint64(q35_host, PCI_HOST_ABOVE_4G_MEM_SIZE,
+                         x86ms->above_4g_mem_size);
     /* pci */
     sysbus_realize_and_unref(SYS_BUS_DEVICE(q35_host), &error_fatal);
     phb = PCI_HOST_BRIDGE(q35_host);
diff --git a/hw/i386/sgx.c b/hw/i386/sgx.c
index 6a729bff94..196fa5afee 100644
--- a/hw/i386/sgx.c
+++ b/hw/i386/sgx.c
@@ -304,8 +304,7 @@  void pc_machine_init_sgx_epc(PCMachineState *pcms)
         object_property_parse(OBJECT(dev), SGX_EPC_MEMDEV_PROP,
                               list->value->memdev, &error_fatal);
         /* set the numa node property for sgx epc object */
-        object_property_set_uint(OBJECT(dev), SGX_EPC_NUMA_NODE_PROP,
-                                 list->value->node, &error_fatal);
+        qdev_prop_set_uint32(dev, SGX_EPC_NUMA_NODE_PROP, list->value->node);
         qdev_realize_and_unref(dev, NULL, &error_fatal);
     }
 
diff --git a/hw/i386/x86.c b/hw/i386/x86.c
index eaff4227bd..191a8c36ee 100644
--- a/hw/i386/x86.c
+++ b/hw/i386/x86.c
@@ -43,6 +43,7 @@ 
 #include "sysemu/xen.h"
 #include "trace.h"
 
+#include "hw/qdev-properties.h"
 #include "hw/i386/x86.h"
 #include "target/i386/cpu.h"
 #include "hw/i386/topology.h"
@@ -96,15 +97,10 @@  uint32_t x86_cpu_apic_id_from_index(X86MachineState *x86ms,
 
 void x86_cpu_new(X86MachineState *x86ms, int64_t apic_id, Error **errp)
 {
-    Object *cpu = object_new(MACHINE(x86ms)->cpu_type);
+    DeviceState *cpu = DEVICE(object_new(MACHINE(x86ms)->cpu_type));
 
-    if (!object_property_set_uint(cpu, "apic-id", apic_id, errp)) {
-        goto out;
-    }
-    qdev_realize(DEVICE(cpu), NULL, errp);
-
-out:
-    object_unref(cpu);
+    qdev_prop_set_uint32(cpu, "apic-id", apic_id);
+    qdev_realize(cpu, NULL, errp);
 }
 
 void x86_cpus_init(X86MachineState *x86ms, int default_cpu_version)
diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c
index 50ef83215c..d6e0c8b680 100644
--- a/hw/mem/pc-dimm.c
+++ b/hw/mem/pc-dimm.c
@@ -66,8 +66,7 @@  void pc_dimm_pre_plug(PCDIMMDevice *dimm, MachineState *machine,
         error_propagate(errp, local_err);
         return;
     }
-    object_property_set_int(OBJECT(dimm), PC_DIMM_SLOT_PROP, slot,
-                            &error_abort);
+    qdev_prop_set_int32(DEVICE(dimm), PC_DIMM_SLOT_PROP, slot);
     trace_mhp_pc_dimm_assigned_slot(slot);
 
     memory_device_pre_plug(MEMORY_DEVICE(dimm), machine, legacy_align,
@@ -234,7 +233,7 @@  static uint64_t pc_dimm_md_get_addr(const MemoryDeviceState *md)
 static void pc_dimm_md_set_addr(MemoryDeviceState *md, uint64_t addr,
                                 Error **errp)
 {
-    object_property_set_uint(OBJECT(md), PC_DIMM_ADDR_PROP, addr, errp);
+    qdev_prop_set_uint64(DEVICE(md), PC_DIMM_ADDR_PROP, addr);
 }
 
 static MemoryRegion *pc_dimm_md_get_memory_region(MemoryDeviceState *md,
diff --git a/target/i386/cpu.c b/target/i386/cpu.c
index 4d2b8d0444..5532cd42c5 100644
--- a/target/i386/cpu.c
+++ b/target/i386/cpu.c
@@ -5073,10 +5073,8 @@  static void x86_cpu_load_model(X86CPU *cpu, X86CPUModel *model)
      */
 
     /* CPU models only set _minimum_ values for level/xlevel: */
-    object_property_set_uint(OBJECT(cpu), "min-level", def->level,
-                             &error_abort);
-    object_property_set_uint(OBJECT(cpu), "min-xlevel", def->xlevel,
-                             &error_abort);
+    qdev_prop_set_uint32(DEVICE(cpu), "min-level", def->level);
+    qdev_prop_set_uint32(DEVICE(cpu), "min-xlevel", def->xlevel);
 
     object_property_set_int(OBJECT(cpu), "family", def->family, &error_abort);
     object_property_set_int(OBJECT(cpu), "model", def->model, &error_abort);
diff --git a/target/i386/host-cpu.c b/target/i386/host-cpu.c
index 10f8aba86e..0307eaa208 100644
--- a/target/i386/host-cpu.c
+++ b/target/i386/host-cpu.c
@@ -158,7 +158,7 @@  void host_cpu_instance_init(X86CPU *cpu)
 
         host_cpuid(0, 0, NULL, &ebx, &ecx, &edx);
         x86_cpu_vendor_words2str(vendor, ebx, edx, ecx);
-        object_property_set_str(OBJECT(cpu), "vendor", vendor, &error_abort);
+        qdev_prop_set_string(DEVICE(cpu), "vendor", vendor);
     }
 }
 
@@ -174,13 +174,12 @@  void host_cpu_max_instance_init(X86CPU *cpu)
     host_cpu_vendor_fms(vendor, &family, &model, &stepping);
     host_cpu_fill_model_id(model_id);
 
-    object_property_set_str(OBJECT(cpu), "vendor", vendor, &error_abort);
+    qdev_prop_set_string(DEVICE(cpu), "vendor", vendor);
     object_property_set_int(OBJECT(cpu), "family", family, &error_abort);
     object_property_set_int(OBJECT(cpu), "model", model, &error_abort);
     object_property_set_int(OBJECT(cpu), "stepping", stepping,
                             &error_abort);
-    object_property_set_str(OBJECT(cpu), "model-id", model_id,
-                            &error_abort);
+    qdev_prop_set_string(DEVICE(cpu), "model-id", model_id);
 }
 
 static void host_cpu_class_init(ObjectClass *oc, void *data)