All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: qemu-devel@nongnu.org
Cc: qemu-arm@nongnu.org, "Markus Armbruster" <armbru@redhat.com>,
	"Eduardo Habkost" <eduardo@habkost.net>,
	qemu-riscv@nongnu.org,
	"Philippe Mathieu-Daudé" <philmd@linaro.org>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Richard Henderson" <richard.henderson@linaro.org>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"Marcel Apfelbaum" <marcel.apfelbaum@gmail.com>,
	"David Hildenbrand" <david@redhat.com>,
	"Igor Mammedov" <imammedo@redhat.com>,
	"Xiao Guangrong" <xiaoguangrong.eric@gmail.com>
Subject: [RFC PATCH 12/19] hw/i386: Set QDev properties using QDev API
Date: Fri,  3 Feb 2023 19:09:07 +0100	[thread overview]
Message-ID: <20230203180914.49112-13-philmd@linaro.org> (raw)
In-Reply-To: <20230203180914.49112-1-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;
     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)
-- 
2.38.1



  parent reply	other threads:[~2023-02-03 18:13 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-03 18:08 [PATCH 00/19] hw: Set QDev properties using QDev API (part 1/3) Philippe Mathieu-Daudé
2023-02-03 18:08 ` [PATCH 01/19] NOTFORMERGE scripts/coccinelle: Add qom-qdev-prop.cocci Philippe Mathieu-Daudé
2023-02-03 18:08 ` [PATCH 02/19] hw/qdev: Introduce qdev_prop_set_link() Philippe Mathieu-Daudé
2023-02-05 22:53   ` Mark Cave-Ayland
2023-02-03 18:08 ` [PATCH 03/19] hw/acpi: Set QDev properties using QDev API Philippe Mathieu-Daudé
2023-03-01 14:07   ` Igor Mammedov
2023-02-03 18:08 ` [PATCH 04/19] hw/audio: " Philippe Mathieu-Daudé
2023-02-03 18:09 ` [RFC PATCH 05/19] hw/core/numa: " Philippe Mathieu-Daudé
2023-03-01 14:09   ` Igor Mammedov
2023-02-03 18:09 ` [PATCH 06/19] hw/core/gpio: " Philippe Mathieu-Daudé
2023-02-03 18:09 ` [RFC PATCH 07/19] hw/scsi: " Philippe Mathieu-Daudé
2023-03-01 14:13   ` Igor Mammedov
2023-02-03 18:09 ` [PATCH 08/19] hw/usb: " Philippe Mathieu-Daudé
2023-02-03 18:09 ` [PATCH 09/19] hw/virtio: " Philippe Mathieu-Daudé
2023-02-03 18:09 ` [PATCH 10/19] hw/avr: " Philippe Mathieu-Daudé
2023-02-03 18:09 ` [PATCH 11/19] hw/hppa: " Philippe Mathieu-Daudé
2023-02-03 18:09 ` Philippe Mathieu-Daudé [this message]
2023-02-04 13:23   ` [RFC PATCH 12/19] hw/i386: " Bernhard Beschow
2023-03-01 14:00   ` Igor Mammedov
2023-02-03 18:09 ` [PATCH 13/19] hw/m68k: " Philippe Mathieu-Daudé
2023-02-05  9:14   ` Thomas Huth
2023-02-03 18:09 ` [PATCH 14/19] hw/microblaze: " Philippe Mathieu-Daudé
2023-02-03 18:09 ` [RFC PATCH 15/19] hw/mips: " Philippe Mathieu-Daudé
2023-02-03 18:09 ` [PATCH 16/19] hw/nios2: " Philippe Mathieu-Daudé
2023-02-03 18:09 ` [RFC PATCH 17/19] hw/riscv: " Philippe Mathieu-Daudé
2023-02-03 18:09 ` [PATCH 18/19] hw/rx: " Philippe Mathieu-Daudé
2023-02-06 13:01   ` Yoshinori Sato
2023-02-03 18:09 ` [PATCH 19/19] hw/sparc: " Philippe Mathieu-Daudé
2023-02-03 18:12 ` [PATCH 00/19] hw: Set QDev properties using QDev API (part 1/3) Philippe Mathieu-Daudé
2023-02-03 18:52   ` BALATON Zoltan
2023-03-01 13:42 ` Igor Mammedov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230203180914.49112-13-philmd@linaro.org \
    --to=philmd@linaro.org \
    --cc=armbru@redhat.com \
    --cc=david@redhat.com \
    --cc=eduardo@habkost.net \
    --cc=imammedo@redhat.com \
    --cc=marcel.apfelbaum@gmail.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-riscv@nongnu.org \
    --cc=richard.henderson@linaro.org \
    --cc=xiaoguangrong.eric@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.