qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/19] hw: Set QDev properties using QDev API (part 1/3)
@ 2023-02-03 18:08 Philippe Mathieu-Daudé
  2023-02-03 18:08 ` [PATCH 01/19] NOTFORMERGE scripts/coccinelle: Add qom-qdev-prop.cocci Philippe Mathieu-Daudé
                   ` (20 more replies)
  0 siblings, 21 replies; 31+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-02-03 18:08 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-arm, Markus Armbruster, Eduardo Habkost, qemu-riscv,
	Philippe Mathieu-Daudé

QEMU provides the QOM API for core objects.
Devices are modelled on top of QOM as QDev objects.

There is no point in using the lower level QOM API with
QDev; it makes the code more complex and harder to review.

I first converted all the calls using errp=&error_abort or
&errp=NULL, then noticed the other uses weren't really
consistent.

A QDev property defined with the DEFINE_PROP_xxx() macros
is always available, thus can't fail. When using hot-plug
devices, we only need to check for optional properties
registered at runtime with the object_property_add_XXX()
API. Some are even always registered in device instance_init.

I have probably been overzealous, so I tagged the patches
not using errp=&error_abort|&error_fatal|NULL as RFC.

PPC and ARM conversions will follow as two different series.

Philippe Mathieu-Daudé (19):
  scripts/coccinelle: Add qom-qdev-prop.cocci
  hw/qdev: Introduce qdev_prop_set_link()
  hw/acpi: Set QDev properties using QDev API
  hw/audio: Set QDev properties using QDev API
  hw/core/numa: Set QDev properties using QDev API
  hw/core/gpio: Set QDev properties using QDev API
  hw/scsi: Set QDev properties using QDev API
  hw/usb: Set QDev properties using QDev API
  hw/virtio: Set QDev properties using QDev API
  hw/avr: Set QDev properties using QDev API
  hw/hppa: Set QDev properties using QDev API
  hw/i386: Set QDev properties using QDev API
  hw/m68k: Set QDev properties using QDev API
  hw/microblaze: Set QDev properties using QDev API
  hw/mips: Set QDev properties using QDev API
  hw/nios2: Set QDev properties using QDev API
  hw/riscv: Set QDev properties using QDev API
  hw/rx: Set QDev properties using QDev API
  hw/sparc: Set QDev properties using QDev API

 hw/acpi/cpu_hotplug.c                    |  7 ++--
 hw/acpi/ich9.c                           |  4 +--
 hw/acpi/piix4.c                          |  4 +--
 hw/avr/arduino.c                         |  4 +--
 hw/avr/atmega.c                          |  4 +--
 hw/core/gpio.c                           |  8 ++---
 hw/core/numa.c                           |  4 +--
 hw/core/qdev-properties.c                |  5 +++
 hw/display/virtio-gpu-pci.c              |  4 +--
 hw/display/virtio-vga.c                  |  4 +--
 hw/dma/sparc32_dma.c                     |  6 ++--
 hw/hppa/machine.c                        |  3 +-
 hw/i386/pc.c                             |  8 ++---
 hw/i386/pc_q35.c                         | 25 +++++++-------
 hw/i386/sgx.c                            |  3 +-
 hw/i386/x86.c                            | 12 +++----
 hw/m68k/next-cube.c                      |  2 +-
 hw/m68k/q800.c                           |  7 ++--
 hw/mem/pc-dimm.c                         |  5 ++-
 hw/microblaze/petalogix_ml605_mmu.c      | 40 ++++++++++------------
 hw/microblaze/petalogix_s3adsp1800_mmu.c |  2 +-
 hw/microblaze/xlnx-zynqmp-pmu.c          | 40 +++++++++-------------
 hw/mips/boston.c                         |  6 ++--
 hw/mips/cps.c                            | 42 ++++++++----------------
 hw/mips/jazz.c                           |  3 +-
 hw/mips/malta.c                          |  6 ++--
 hw/nios2/10m50_devboard.c                |  2 +-
 hw/riscv/microchip_pfsoc.c               |  8 ++---
 hw/riscv/opentitan.c                     |  9 ++---
 hw/riscv/shakti_c.c                      |  7 ++--
 hw/riscv/sifive_e.c                      |  8 ++---
 hw/riscv/sifive_u.c                      |  9 ++---
 hw/riscv/spike.c                         | 10 +++---
 hw/riscv/virt.c                          |  9 ++---
 hw/rx/rx-gdbsim.c                        | 11 +++----
 hw/scsi/scsi-bus.c                       |  6 +---
 hw/sparc/sun4m.c                         | 10 +++---
 hw/sparc64/sun4u.c                       |  3 +-
 hw/usb/hcd-xhci-pci.c                    |  2 +-
 hw/usb/hcd-xhci-sysbus.c                 |  2 +-
 hw/virtio/virtio-iommu-pci.c             |  3 +-
 hw/virtio/virtio-rng.c                   |  3 +-
 include/hw/audio/pcspk.h                 |  2 +-
 include/hw/qdev-properties.h             |  1 +
 target/i386/cpu.c                        |  6 ++--
 target/i386/host-cpu.c                   |  7 ++--
 46 files changed, 155 insertions(+), 221 deletions(-)
 create mode 100644 scripts/coccinelle/qom-qdev-prop.cocci

-- 
2.38.1



^ permalink raw reply	[flat|nested] 31+ messages in thread

* [PATCH 01/19] NOTFORMERGE scripts/coccinelle: Add qom-qdev-prop.cocci
  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 ` Philippe Mathieu-Daudé
  2023-02-03 18:08 ` [PATCH 02/19] hw/qdev: Introduce qdev_prop_set_link() Philippe Mathieu-Daudé
                   ` (19 subsequent siblings)
  20 siblings, 0 replies; 31+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-02-03 18:08 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-arm, Markus Armbruster, Eduardo Habkost, qemu-riscv,
	Philippe Mathieu-Daudé

Script I used to generate the following patches. This is
not an automatic conversion as object_property_set_[u]int()
does not specify the type size. Each integer property must
then be converted manually. Therefore this script doesn't
seem relevant to be committed in the repository.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 scripts/coccinelle/qom-qdev-prop.cocci | 259 +++++++++++++++++++++++++
 1 file changed, 259 insertions(+)
 create mode 100644 scripts/coccinelle/qom-qdev-prop.cocci

diff --git a/scripts/coccinelle/qom-qdev-prop.cocci b/scripts/coccinelle/qom-qdev-prop.cocci
new file mode 100644
index 0000000000..21e6ed2b33
--- /dev/null
+++ b/scripts/coccinelle/qom-qdev-prop.cocci
@@ -0,0 +1,259 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+// SPDX-FileCopyrightText: Linaro Limited 2023
+//
+// Convert QOM set_property() API to QDev set_prop() API equivalent
+//
+// Only bool / string / link properties are automatically converted.
+// Integer properties must be converted manually, since the QOM
+// object_property_set_[u]int() helpers don't specify the type size.
+
+
+//
+// bool
+//
+
+// bool OBJECT
+@@
+typedef DeviceState;
+identifier dev;
+expression prop, val;
+@@
+    DeviceState *dev;
+    ...
+-   object_property_set_bool(OBJECT(dev), prop, val, ... /* &error_abort */);
++   qdev_prop_set_bit(dev, prop, val);
+
+// bool dev
+@@
+expression dev;
+expression prop, val;
+@@
+-   object_property_set_bool(OBJECT(dev), prop, val, ... /* &error_abort */);
++   qdev_prop_set_bit(dev, prop, val);
+    ...
+(
+    sysbus_realize(SYS_BUS_DEVICE(dev), ...);
+|
+    qdev_realize(dev, ...);
+|
+    qdev_realize_and_unref(dev, ...);
+)
+
+// bool DEVICE(dev)
+@@
+expression dev;
+expression prop, val;
+@@
+-   object_property_set_bool(OBJECT(dev), prop, val, ... /* &error_abort */);
++   qdev_prop_set_bit(DEVICE(dev), prop, val);
+    ...
+(
+    sysbus_realize(SYS_BUS_DEVICE(dev), ...);
+|
+    qdev_realize(DEVICE(dev), ...);
+|
+    qdev_realize_and_unref(DEVICE(dev), ...);
+)
+
+// bool DEVICE(obj)
+@@
+expression obj;
+expression prop, val;
+@@
+-   object_property_set_bool(obj, prop, val, ... /* &error_abort */);
++   qdev_prop_set_bit(DEVICE(obj), prop, val);
+    ...
+(
+    sysbus_realize(SYS_BUS_DEVICE(obj), ...);
+|
+    qdev_realize(DEVICE(obj), ...);
+|
+    qdev_realize_and_unref(DEVICE(obj), ...);
+)
+
+
+//
+// str
+//
+
+// str OBJECT
+@@
+typedef DeviceState;
+identifier dev;
+expression prop, val;
+@@
+    DeviceState *dev;
+    ...
+-   object_property_set_str(OBJECT(dev), prop, val, ... /* &error_abort */);
++   qdev_prop_set_string(dev, prop, val);
+
+// str dev
+@@
+expression dev;
+expression prop, val;
+@@
+-   object_property_set_str(OBJECT(dev), prop, val, ... /* &error_abort */);
++   qdev_prop_set_string(dev, prop, val);
+    ...
+(
+    sysbus_realize(SYS_BUS_DEVICE(dev), ...);
+|
+    qdev_realize(dev, ...);
+|
+    qdev_realize_and_unref(dev, ...);
+)
+
+// str DEVICE(dev)
+@@
+expression dev;
+expression prop, val;
+@@
+-   object_property_set_str(OBJECT(dev), prop, val, ... /* &error_abort */);
++   qdev_prop_set_string(DEVICE(dev), prop, val);
+    ...
+(
+    sysbus_realize(SYS_BUS_DEVICE(dev), ...);
+|
+    qdev_realize(DEVICE(dev), ...);
+|
+    qdev_realize_and_unref(DEVICE(dev), ...);
+)
+
+// str DEVICE(obj)
+@@
+expression obj;
+expression prop, val;
+@@
+-   object_property_set_str(obj, prop, val, ... /* &error_abort */);
++   qdev_prop_set_string(DEVICE(obj), prop, val);
+    ...
+(
+    sysbus_realize(SYS_BUS_DEVICE(obj), ...);
+|
+    qdev_realize(DEVICE(obj), ...);
+|
+    qdev_realize_and_unref(DEVICE(obj), ...);
+)
+
+
+// int OBJECT
+@@
+typedef DeviceState;
+identifier dev;
+expression prop, val;
+@@
+    DeviceState *dev;
+    ...
+-   object_property_set_int(OBJECT(dev), prop, val, ... /* &error_abort */);
++   qdev_prop_set_XintXX(dev, prop, val);
+
+// int dev
+@@
+expression dev;
+expression prop, val;
+@@
+-   object_property_set_int(OBJECT(dev), prop, val, ... /* &error_abort */);
++   qdev_prop_set_XintXX(dev, prop, val);
+    ...
+(
+    sysbus_realize(SYS_BUS_DEVICE(dev), ...);
+|
+    qdev_realize(dev, ...);
+|
+    qdev_realize_and_unref(dev, ...);
+)
+
+// int DEVICE(dev)
+@@
+expression dev;
+expression prop, val;
+@@
+-   object_property_set_int(OBJECT(dev), prop, val, ... /* &error_abort */);
++   qdev_prop_set_XintXX(DEVICE(dev), prop, val);
+    ...
+(
+    sysbus_realize(SYS_BUS_DEVICE(dev), ...);
+|
+    qdev_realize(DEVICE(dev), ...);
+|
+    qdev_realize_and_unref(DEVICE(dev), ...);
+)
+
+// int DEVICE(obj)
+@@
+expression obj;
+expression prop, val;
+@@
+-   object_property_set_int(obj, prop, val, ... /* &error_abort */);
++   qdev_prop_set_XintXX(DEVICE(obj), prop, val);
+    ...
+(
+    sysbus_realize(SYS_BUS_DEVICE(obj), ...);
+|
+    qdev_realize(DEVICE(obj), ...);
+|
+    qdev_realize_and_unref(DEVICE(obj), ...);
+)
+
+//
+// link
+//
+
+// link OBJECT
+@@
+typedef DeviceState;
+identifier dev;
+expression prop, val;
+@@
+    DeviceState *dev;
+    ...
+-   object_property_set_link(OBJECT(dev), prop, val, ... /* &error_abort */);
++   qdev_prop_set_link(dev, prop, val);
+
+// link dev
+@@
+expression dev;
+expression prop, val;
+@@
+-   object_property_set_link(OBJECT(dev), prop, val, ... /* &error_abort */);
++   qdev_prop_set_link(dev, prop, val);
+    ...
+(
+    sysbus_realize(SYS_BUS_DEVICE(dev), ...);
+|
+    qdev_realize(dev, ...);
+|
+    qdev_realize_and_unref(dev, ...);
+)
+
+// link DEVICE(dev)
+@@
+expression dev;
+expression prop, val;
+@@
+-   object_property_set_link(OBJECT(dev), prop, val, ... /* &error_abort */);
++   qdev_prop_set_link(DEVICE(dev), prop, val);
+    ...
+(
+    sysbus_realize(SYS_BUS_DEVICE(dev), ...);
+|
+    qdev_realize(DEVICE(dev), ...);
+|
+    qdev_realize_and_unref(DEVICE(dev), ...);
+)
+
+// link DEVICE(obj)
+@@
+expression obj;
+expression prop, val;
+@@
+-   object_property_set_link(obj, prop, val, ... /* &error_abort */);
++   qdev_prop_set_link(DEVICE(obj), prop, val);
+    ...
+(
+    sysbus_realize(SYS_BUS_DEVICE(obj), ...);
+|
+    qdev_realize(DEVICE(obj), ...);
+|
+    qdev_realize_and_unref(DEVICE(obj), ...);
+)
-- 
2.38.1



^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH 02/19] hw/qdev: Introduce qdev_prop_set_link()
  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 ` 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é
                   ` (18 subsequent siblings)
  20 siblings, 1 reply; 31+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-02-03 18:08 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-arm, Markus Armbruster, Eduardo Habkost, qemu-riscv,
	Philippe Mathieu-Daudé,
	Paolo Bonzini, Daniel P. Berrangé

Introduce qdev_prop_set_link(), equivalent of
object_property_set_link() for QDev objects.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
 hw/core/qdev-properties.c    | 5 +++++
 include/hw/qdev-properties.h | 1 +
 2 files changed, 6 insertions(+)

diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c
index 9789a2f5de..46236b1542 100644
--- a/hw/core/qdev-properties.c
+++ b/hw/core/qdev-properties.c
@@ -694,6 +694,11 @@ void error_set_from_qdev_prop_error(Error **errp, int ret, Object *obj,
     }
 }
 
+void qdev_prop_set_link(DeviceState *dev, const char *name, Object *value)
+{
+    object_property_set_link(OBJECT(dev), name, value, &error_abort);
+}
+
 void qdev_prop_set_bit(DeviceState *dev, const char *name, bool value)
 {
     object_property_set_bool(OBJECT(dev), name, value, &error_abort);
diff --git a/include/hw/qdev-properties.h b/include/hw/qdev-properties.h
index 21f399e9a3..c16dbefb2f 100644
--- a/include/hw/qdev-properties.h
+++ b/include/hw/qdev-properties.h
@@ -191,6 +191,7 @@ bool qdev_prop_set_drive_err(DeviceState *dev, const char *name,
  * Set properties between creation and realization.
  * @value must be valid.  Each property may be set at most once.
  */
+void qdev_prop_set_link(DeviceState *dev, const char *name, Object *value);
 void qdev_prop_set_bit(DeviceState *dev, const char *name, bool value);
 void qdev_prop_set_uint8(DeviceState *dev, const char *name, uint8_t value);
 void qdev_prop_set_uint16(DeviceState *dev, const char *name, uint16_t value);
-- 
2.38.1



^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH 03/19] hw/acpi: Set QDev properties using QDev API
  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-03 18:08 ` Philippe Mathieu-Daudé
  2023-03-01 14:07   ` Igor Mammedov
  2023-02-03 18:08 ` [PATCH 04/19] hw/audio: " Philippe Mathieu-Daudé
                   ` (17 subsequent siblings)
  20 siblings, 1 reply; 31+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-02-03 18:08 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-arm, Markus Armbruster, Eduardo Habkost, qemu-riscv,
	Philippe Mathieu-Daudé,
	Michael S. Tsirkin, Igor Mammedov, Ani Sinha, Marcel Apfelbaum,
	Aurelien Jarno

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/acpi/cpu_hotplug.c | 7 +++----
 hw/acpi/ich9.c        | 4 ++--
 hw/acpi/piix4.c       | 4 ++--
 3 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/hw/acpi/cpu_hotplug.c b/hw/acpi/cpu_hotplug.c
index b8c9081738..5bc5f435f4 100644
--- a/hw/acpi/cpu_hotplug.c
+++ b/hw/acpi/cpu_hotplug.c
@@ -10,6 +10,7 @@
  * See the COPYING file in the top-level directory.
  */
 #include "qemu/osdep.h"
+#include "hw/qdev-properties.h"
 #include "hw/acpi/cpu_hotplug.h"
 #include "qapi/error.h"
 #include "hw/core/cpu.h"
@@ -41,8 +42,7 @@ static void cpu_status_write(void *opaque, hwaddr addr, uint64_t data,
      */
     if (addr == 0 && data == 0) {
         AcpiCpuHotplug *gpe = opaque;
-        object_property_set_bool(OBJECT(gpe->parent), "cpu-hotplug-legacy",
-                                 false, &error_abort);
+        qdev_prop_set_bit(gpe->parent, "cpu-hotplug-legacy", false);
     }
 }
 
@@ -66,8 +66,7 @@ static void acpi_set_cpu_present_bit(AcpiCpuHotplug *gpe, CPUState *cpu)
 
     cpu_id = k->get_arch_id(cpu);
     if ((cpu_id / 8) >= ACPI_GPE_PROC_LEN) {
-        object_property_set_bool(OBJECT(gpe->parent), "cpu-hotplug-legacy",
-                                 false, &error_abort);
+        qdev_prop_set_bit(gpe->parent, "cpu-hotplug-legacy", false);
         return;
     }
 
diff --git a/hw/acpi/ich9.c b/hw/acpi/ich9.c
index 6c9a737479..9759119b32 100644
--- a/hw/acpi/ich9.c
+++ b/hw/acpi/ich9.c
@@ -30,6 +30,7 @@
 #include "hw/pci/pci.h"
 #include "migration/vmstate.h"
 #include "qemu/timer.h"
+#include "hw/qdev-properties.h"
 #include "hw/core/cpu.h"
 #include "sysemu/reset.h"
 #include "sysemu/runstate.h"
@@ -197,8 +198,7 @@ static bool vmstate_test_use_cpuhp(void *opaque)
 static int vmstate_cpuhp_pre_load(void *opaque)
 {
     ICH9LPCPMRegs *s = opaque;
-    Object *obj = OBJECT(s->gpe.parent);
-    object_property_set_bool(obj, "cpu-hotplug-legacy", false, &error_abort);
+    qdev_prop_set_bit(s->gpe.parent, "cpu-hotplug-legacy", false);
     return 0;
 }
 
diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
index 3a61d89f92..9a86d506de 100644
--- a/hw/acpi/piix4.c
+++ b/hw/acpi/piix4.c
@@ -206,8 +206,8 @@ static bool vmstate_test_use_cpuhp(void *opaque)
 
 static int vmstate_cpuhp_pre_load(void *opaque)
 {
-    Object *obj = OBJECT(opaque);
-    object_property_set_bool(obj, "cpu-hotplug-legacy", false, &error_abort);
+    PIIX4PMState *s = opaque;
+    qdev_prop_set_bit(DEVICE(s), "cpu-hotplug-legacy", false);
     return 0;
 }
 
-- 
2.38.1



^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH 04/19] hw/audio: Set QDev properties using QDev API
  2023-02-03 18:08 [PATCH 00/19] hw: Set QDev properties using QDev API (part 1/3) Philippe Mathieu-Daudé
                   ` (2 preceding siblings ...)
  2023-02-03 18:08 ` [PATCH 03/19] hw/acpi: Set QDev properties using QDev API Philippe Mathieu-Daudé
@ 2023-02-03 18:08 ` Philippe Mathieu-Daudé
  2023-02-03 18:09 ` [RFC PATCH 05/19] hw/core/numa: " Philippe Mathieu-Daudé
                   ` (16 subsequent siblings)
  20 siblings, 0 replies; 31+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-02-03 18:08 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-arm, Markus Armbruster, Eduardo Habkost, qemu-riscv,
	Philippe Mathieu-Daudé,
	Gerd Hoffmann

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>
---
 include/hw/audio/pcspk.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/hw/audio/pcspk.h b/include/hw/audio/pcspk.h
index 9506179587..e18ca08fa0 100644
--- a/include/hw/audio/pcspk.h
+++ b/include/hw/audio/pcspk.h
@@ -33,7 +33,7 @@
 
 static inline void pcspk_init(ISADevice *isadev, ISABus *bus, ISADevice *pit)
 {
-    object_property_set_link(OBJECT(isadev), "pit", OBJECT(pit), NULL);
+    qdev_prop_set_link(DEVICE(isadev), "pit", OBJECT(pit));
     isa_realize_and_unref(isadev, bus, &error_fatal);
 }
 
-- 
2.38.1



^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [RFC PATCH 05/19] hw/core/numa: Set QDev properties using QDev API
  2023-02-03 18:08 [PATCH 00/19] hw: Set QDev properties using QDev API (part 1/3) Philippe Mathieu-Daudé
                   ` (3 preceding siblings ...)
  2023-02-03 18:08 ` [PATCH 04/19] hw/audio: " Philippe Mathieu-Daudé
@ 2023-02-03 18:09 ` Philippe Mathieu-Daudé
  2023-03-01 14:09   ` Igor Mammedov
  2023-02-03 18:09 ` [PATCH 06/19] hw/core/gpio: " Philippe Mathieu-Daudé
                   ` (15 subsequent siblings)
  20 siblings, 1 reply; 31+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-02-03 18:09 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-arm, Markus Armbruster, Eduardo Habkost, qemu-riscv,
	Philippe Mathieu-Daudé,
	Marcel Apfelbaum, Yanan Wang

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/core/numa.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/hw/core/numa.c b/hw/core/numa.c
index d8d36b16d8..9b6f9848e3 100644
--- a/hw/core/numa.c
+++ b/hw/core/numa.c
@@ -34,6 +34,7 @@
 #include "qapi/opts-visitor.h"
 #include "qapi/qapi-visit-machine.h"
 #include "sysemu/qtest.h"
+#include "hw/qdev-properties.h"
 #include "hw/core/cpu.h"
 #include "hw/mem/pc-dimm.h"
 #include "migration/vmstate.h"
@@ -740,8 +741,7 @@ void numa_cpu_pre_plug(const CPUArchId *slot, DeviceState *dev, Error **errp)
         /* due to bug in libvirt, it doesn't pass node-id from props on
          * device_add as expected, so we have to fix it up here */
         if (slot->props.has_node_id) {
-            object_property_set_int(OBJECT(dev), "node-id",
-                                    slot->props.node_id, errp);
+            qdev_prop_set_int32(dev, "node-id", slot->props.node_id);
         }
     } else if (node_id != slot->props.node_id) {
         error_setg(errp, "invalid node-id, must be %"PRId64,
-- 
2.38.1



^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH 06/19] hw/core/gpio: Set QDev properties using QDev API
  2023-02-03 18:08 [PATCH 00/19] hw: Set QDev properties using QDev API (part 1/3) Philippe Mathieu-Daudé
                   ` (4 preceding siblings ...)
  2023-02-03 18:09 ` [RFC PATCH 05/19] hw/core/numa: " Philippe Mathieu-Daudé
@ 2023-02-03 18:09 ` Philippe Mathieu-Daudé
  2023-02-03 18:09 ` [RFC PATCH 07/19] hw/scsi: " Philippe Mathieu-Daudé
                   ` (14 subsequent siblings)
  20 siblings, 0 replies; 31+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-02-03 18:09 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-arm, Markus Armbruster, Eduardo Habkost, qemu-riscv,
	Philippe Mathieu-Daudé

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/core/gpio.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/hw/core/gpio.c b/hw/core/gpio.c
index 80d07a6ec9..ba05dfa92e 100644
--- a/hw/core/gpio.c
+++ b/hw/core/gpio.c
@@ -19,6 +19,7 @@
 
 #include "qemu/osdep.h"
 #include "hw/qdev-core.h"
+#include "hw/qdev-properties.h"
 #include "hw/irq.h"
 #include "qapi/error.h"
 
@@ -120,13 +121,12 @@ void qdev_connect_gpio_out_named(DeviceState *dev, const char *name, int n,
     char *propname = g_strdup_printf("%s[%d]",
                                      name ? name : "unnamed-gpio-out", n);
     if (input_pin && !OBJECT(input_pin)->parent) {
-        /* We need a name for object_property_set_link to work */
+        /* We need a name for qdev_prop_set_link to work */
         object_property_add_child(container_get(qdev_get_machine(),
                                                 "/unattached"),
                                   "non-qdev-gpio[*]", OBJECT(input_pin));
     }
-    object_property_set_link(OBJECT(dev), propname,
-                             OBJECT(input_pin), &error_abort);
+    qdev_prop_set_link(dev, propname, OBJECT(input_pin));
     g_free(propname);
 }
 
@@ -152,7 +152,7 @@ static qemu_irq qdev_disconnect_gpio_out_named(DeviceState *dev,
     qemu_irq ret = (qemu_irq)object_property_get_link(OBJECT(dev), propname,
                                                       NULL);
     if (ret) {
-        object_property_set_link(OBJECT(dev), propname, NULL, NULL);
+        qdev_prop_set_link(dev, propname, NULL);
     }
     g_free(propname);
     return ret;
-- 
2.38.1



^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [RFC PATCH 07/19] hw/scsi: Set QDev properties using QDev API
  2023-02-03 18:08 [PATCH 00/19] hw: Set QDev properties using QDev API (part 1/3) Philippe Mathieu-Daudé
                   ` (5 preceding siblings ...)
  2023-02-03 18:09 ` [PATCH 06/19] hw/core/gpio: " Philippe Mathieu-Daudé
@ 2023-02-03 18:09 ` Philippe Mathieu-Daudé
  2023-03-01 14:13   ` Igor Mammedov
  2023-02-03 18:09 ` [PATCH 08/19] hw/usb: " Philippe Mathieu-Daudé
                   ` (13 subsequent siblings)
  20 siblings, 1 reply; 31+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-02-03 18:09 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-arm, Markus Armbruster, Eduardo Habkost, qemu-riscv,
	Philippe Mathieu-Daudé,
	Paolo Bonzini, Fam Zheng

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/scsi/scsi-bus.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/hw/scsi/scsi-bus.c b/hw/scsi/scsi-bus.c
index ceceafb2cd..a8003126c4 100644
--- a/hw/scsi/scsi-bus.c
+++ b/hw/scsi/scsi-bus.c
@@ -347,11 +347,7 @@ SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, BlockBackend *blk,
         object_unparent(OBJECT(dev));
         return NULL;
     }
-    if (!object_property_set_bool(OBJECT(dev), "share-rw", share_rw, errp)) {
-        object_unparent(OBJECT(dev));
-        return NULL;
-    }
-
+    qdev_prop_set_bit(dev, "share-rw", share_rw);
     qdev_prop_set_enum(dev, "rerror", rerror);
     qdev_prop_set_enum(dev, "werror", werror);
 
-- 
2.38.1



^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH 08/19] hw/usb: Set QDev properties using QDev API
  2023-02-03 18:08 [PATCH 00/19] hw: Set QDev properties using QDev API (part 1/3) Philippe Mathieu-Daudé
                   ` (6 preceding siblings ...)
  2023-02-03 18:09 ` [RFC PATCH 07/19] hw/scsi: " Philippe Mathieu-Daudé
@ 2023-02-03 18:09 ` Philippe Mathieu-Daudé
  2023-02-03 18:09 ` [PATCH 09/19] hw/virtio: " Philippe Mathieu-Daudé
                   ` (12 subsequent siblings)
  20 siblings, 0 replies; 31+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-02-03 18:09 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-arm, Markus Armbruster, Eduardo Habkost, qemu-riscv,
	Philippe Mathieu-Daudé,
	Gerd Hoffmann

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/usb/hcd-xhci-pci.c    | 2 +-
 hw/usb/hcd-xhci-sysbus.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/hw/usb/hcd-xhci-pci.c b/hw/usb/hcd-xhci-pci.c
index 643d4643e4..7511af4ce2 100644
--- a/hw/usb/hcd-xhci-pci.c
+++ b/hw/usb/hcd-xhci-pci.c
@@ -115,7 +115,7 @@ static void usb_xhci_pci_realize(struct PCIDevice *dev, Error **errp)
     dev->config[PCI_CACHE_LINE_SIZE] = 0x10;
     dev->config[0x60] = 0x30; /* release number */
 
-    object_property_set_link(OBJECT(&s->xhci), "host", OBJECT(s), NULL);
+    qdev_prop_set_link(DEVICE(&s->xhci), "host", OBJECT(s));
     s->xhci.intr_update = xhci_pci_intr_update;
     s->xhci.intr_raise = xhci_pci_intr_raise;
     if (!qdev_realize(DEVICE(&s->xhci), NULL, errp)) {
diff --git a/hw/usb/hcd-xhci-sysbus.c b/hw/usb/hcd-xhci-sysbus.c
index faf57b4797..d73c71015b 100644
--- a/hw/usb/hcd-xhci-sysbus.c
+++ b/hw/usb/hcd-xhci-sysbus.c
@@ -36,7 +36,7 @@ static void xhci_sysbus_realize(DeviceState *dev, Error **errp)
 {
     XHCISysbusState *s = XHCI_SYSBUS(dev);
 
-    object_property_set_link(OBJECT(&s->xhci), "host", OBJECT(s), NULL);
+    qdev_prop_set_link(DEVICE(&s->xhci), "host", OBJECT(s));
     if (!qdev_realize(DEVICE(&s->xhci), NULL, errp)) {
         return;
     }
-- 
2.38.1



^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH 09/19] hw/virtio: Set QDev properties using QDev API
  2023-02-03 18:08 [PATCH 00/19] hw: Set QDev properties using QDev API (part 1/3) Philippe Mathieu-Daudé
                   ` (7 preceding siblings ...)
  2023-02-03 18:09 ` [PATCH 08/19] hw/usb: " Philippe Mathieu-Daudé
@ 2023-02-03 18:09 ` Philippe Mathieu-Daudé
  2023-02-03 18:09 ` [PATCH 10/19] hw/avr: " Philippe Mathieu-Daudé
                   ` (11 subsequent siblings)
  20 siblings, 0 replies; 31+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-02-03 18:09 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-arm, Markus Armbruster, Eduardo Habkost, qemu-riscv,
	Philippe Mathieu-Daudé,
	Gerd Hoffmann, Michael S. Tsirkin, Eric Auger, Laurent Vivier,
	Amit Shah

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/display/virtio-gpu-pci.c  | 4 ++--
 hw/display/virtio-vga.c      | 4 ++--
 hw/virtio/virtio-iommu-pci.c | 3 +--
 hw/virtio/virtio-rng.c       | 3 +--
 4 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/hw/display/virtio-gpu-pci.c b/hw/display/virtio-gpu-pci.c
index 93f214ff58..a2de06962b 100644
--- a/hw/display/virtio-gpu-pci.c
+++ b/hw/display/virtio-gpu-pci.c
@@ -39,8 +39,8 @@ static void virtio_gpu_pci_base_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
     }
 
     for (i = 0; i < g->conf.max_outputs; i++) {
-        object_property_set_link(OBJECT(g->scanout[i].con), "device",
-                                 OBJECT(vpci_dev), &error_abort);
+        qdev_prop_set_link(DEVICE(g->scanout[i].con), "device",
+                           OBJECT(vpci_dev));
     }
 }
 
diff --git a/hw/display/virtio-vga.c b/hw/display/virtio-vga.c
index e6fb0aa876..1652d74657 100644
--- a/hw/display/virtio-vga.c
+++ b/hw/display/virtio-vga.c
@@ -160,8 +160,8 @@ static void virtio_vga_base_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
     graphic_console_set_hwops(vga->con, &virtio_vga_base_ops, vvga);
 
     for (i = 0; i < g->conf.max_outputs; i++) {
-        object_property_set_link(OBJECT(g->scanout[i].con), "device",
-                                 OBJECT(vpci_dev), &error_abort);
+        qdev_prop_set_link(DEVICE(g->scanout[i].con), "device",
+                           OBJECT(vpci_dev));
     }
 }
 
diff --git a/hw/virtio/virtio-iommu-pci.c b/hw/virtio/virtio-iommu-pci.c
index 7ef2f9dcdb..f7edcb39db 100644
--- a/hw/virtio/virtio-iommu-pci.c
+++ b/hw/virtio/virtio-iommu-pci.c
@@ -67,8 +67,7 @@ static void virtio_iommu_pci_realize(VirtIOPCIProxy *vpci_dev, Error **errp)
         return;
     }
 
-    object_property_set_link(OBJECT(dev), "primary-bus",
-                             OBJECT(pbus), &error_abort);
+    qdev_prop_set_link(DEVICE(dev), "primary-bus", OBJECT(pbus));
 
     virtio_pci_force_virtio_1(vpci_dev);
     qdev_realize(vdev, BUS(&vpci_dev->bus), errp);
diff --git a/hw/virtio/virtio-rng.c b/hw/virtio/virtio-rng.c
index 7e12fc03bf..6733e5b017 100644
--- a/hw/virtio/virtio-rng.c
+++ b/hw/virtio/virtio-rng.c
@@ -205,8 +205,7 @@ static void virtio_rng_device_realize(DeviceState *dev, Error **errp)
         /* The child property took a reference, we can safely drop ours now */
         object_unref(default_backend);
 
-        object_property_set_link(OBJECT(dev), "rng", default_backend,
-                                 &error_abort);
+        qdev_prop_set_link(dev, "rng", default_backend);
     }
 
     vrng->rng = vrng->conf.rng;
-- 
2.38.1



^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH 10/19] hw/avr: Set QDev properties using QDev API
  2023-02-03 18:08 [PATCH 00/19] hw: Set QDev properties using QDev API (part 1/3) Philippe Mathieu-Daudé
                   ` (8 preceding siblings ...)
  2023-02-03 18:09 ` [PATCH 09/19] hw/virtio: " Philippe Mathieu-Daudé
@ 2023-02-03 18:09 ` Philippe Mathieu-Daudé
  2023-02-03 18:09 ` [PATCH 11/19] hw/hppa: " Philippe Mathieu-Daudé
                   ` (10 subsequent siblings)
  20 siblings, 0 replies; 31+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-02-03 18:09 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-arm, Markus Armbruster, Eduardo Habkost, qemu-riscv,
	Philippe Mathieu-Daudé,
	Michael Rolnik

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/avr/arduino.c | 4 ++--
 hw/avr/atmega.c  | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/hw/avr/arduino.c b/hw/avr/arduino.c
index 48ef478346..428e6e1b2d 100644
--- a/hw/avr/arduino.c
+++ b/hw/avr/arduino.c
@@ -15,6 +15,7 @@
 #include "atmega.h"
 #include "boot.h"
 #include "qom/object.h"
+#include "hw/qdev-properties.h"
 
 struct ArduinoMachineState {
     /*< private >*/
@@ -44,8 +45,7 @@ static void arduino_machine_init(MachineState *machine)
     ArduinoMachineState *ams = ARDUINO_MACHINE(machine);
 
     object_initialize_child(OBJECT(machine), "mcu", &ams->mcu, amc->mcu_type);
-    object_property_set_uint(OBJECT(&ams->mcu), "xtal-frequency-hz",
-                             amc->xtal_hz, &error_abort);
+    qdev_prop_set_uint64(DEVICE(&ams->mcu), "xtal-frequency-hz", amc->xtal_hz);
     sysbus_realize(SYS_BUS_DEVICE(&ams->mcu), &error_abort);
 
     if (machine->firmware) {
diff --git a/hw/avr/atmega.c b/hw/avr/atmega.c
index a34803e642..e6ebc7473a 100644
--- a/hw/avr/atmega.c
+++ b/hw/avr/atmega.c
@@ -327,8 +327,8 @@ static void atmega_realize(DeviceState *dev, Error **errp)
         devname = g_strdup_printf("timer%zu", i);
         object_initialize_child(OBJECT(dev), devname, &s->timer[i],
                                 TYPE_AVR_TIMER16);
-        object_property_set_uint(OBJECT(&s->timer[i]), "cpu-frequency-hz",
-                                 s->xtal_freq_hz, &error_abort);
+        qdev_prop_set_uint64(DEVICE(&s->timer[i]), "cpu-frequency-hz",
+                             s->xtal_freq_hz);
         sbd = SYS_BUS_DEVICE(&s->timer[i]);
         sysbus_realize(sbd, &error_abort);
         sysbus_mmio_map(sbd, 0, OFFSET_DATA + mc->dev[idx].addr);
-- 
2.38.1



^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH 11/19] hw/hppa: Set QDev properties using QDev API
  2023-02-03 18:08 [PATCH 00/19] hw: Set QDev properties using QDev API (part 1/3) Philippe Mathieu-Daudé
                   ` (9 preceding siblings ...)
  2023-02-03 18:09 ` [PATCH 10/19] hw/avr: " Philippe Mathieu-Daudé
@ 2023-02-03 18:09 ` Philippe Mathieu-Daudé
  2023-02-03 18:09 ` [RFC PATCH 12/19] hw/i386: " Philippe Mathieu-Daudé
                   ` (9 subsequent siblings)
  20 siblings, 0 replies; 31+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-02-03 18:09 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-arm, Markus Armbruster, Eduardo Habkost, qemu-riscv,
	Philippe Mathieu-Daudé,
	Richard Henderson, Helge Deller

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/hppa/machine.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/hw/hppa/machine.c b/hw/hppa/machine.c
index de1cc7ab71..6bd6a8d722 100644
--- a/hw/hppa/machine.c
+++ b/hw/hppa/machine.c
@@ -166,8 +166,7 @@ static DinoState *dino_init(MemoryRegion *addr_space)
     DeviceState *dev;
 
     dev = qdev_new(TYPE_DINO_PCI_HOST_BRIDGE);
-    object_property_set_link(OBJECT(dev), "memory-as", OBJECT(addr_space),
-                             &error_fatal);
+    qdev_prop_set_link(dev, "memory-as", OBJECT(addr_space));
     sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
 
     return DINO_PCI_HOST_BRIDGE(dev);
-- 
2.38.1



^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [RFC PATCH 12/19] hw/i386: Set QDev properties using QDev API
  2023-02-03 18:08 [PATCH 00/19] hw: Set QDev properties using QDev API (part 1/3) Philippe Mathieu-Daudé
                   ` (10 preceding siblings ...)
  2023-02-03 18:09 ` [PATCH 11/19] hw/hppa: " Philippe Mathieu-Daudé
@ 2023-02-03 18:09 ` Philippe Mathieu-Daudé
  2023-02-04 13:23   ` Bernhard Beschow
  2023-03-01 14:00   ` Igor Mammedov
  2023-02-03 18:09 ` [PATCH 13/19] hw/m68k: " Philippe Mathieu-Daudé
                   ` (8 subsequent siblings)
  20 siblings, 2 replies; 31+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-02-03 18:09 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-arm, Markus Armbruster, Eduardo Habkost, qemu-riscv,
	Philippe Mathieu-Daudé,
	Paolo Bonzini, Richard Henderson, Michael S. Tsirkin,
	Marcel Apfelbaum, David Hildenbrand, Igor Mammedov,
	Xiao Guangrong

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



^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH 13/19] hw/m68k: Set QDev properties using QDev API
  2023-02-03 18:08 [PATCH 00/19] hw: Set QDev properties using QDev API (part 1/3) Philippe Mathieu-Daudé
                   ` (11 preceding siblings ...)
  2023-02-03 18:09 ` [RFC PATCH 12/19] hw/i386: " Philippe Mathieu-Daudé
@ 2023-02-03 18:09 ` Philippe Mathieu-Daudé
  2023-02-05  9:14   ` Thomas Huth
  2023-02-03 18:09 ` [PATCH 14/19] hw/microblaze: " Philippe Mathieu-Daudé
                   ` (7 subsequent siblings)
  20 siblings, 1 reply; 31+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-02-03 18:09 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-arm, Markus Armbruster, Eduardo Habkost, qemu-riscv,
	Philippe Mathieu-Daudé,
	Thomas Huth, Laurent Vivier

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/m68k/next-cube.c | 2 +-
 hw/m68k/q800.c      | 7 +++----
 2 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/hw/m68k/next-cube.c b/hw/m68k/next-cube.c
index e0d4a94f9d..460b84c6e6 100644
--- a/hw/m68k/next-cube.c
+++ b/hw/m68k/next-cube.c
@@ -966,7 +966,7 @@ static void next_cube_init(MachineState *machine)
 
     /* Peripheral Controller */
     pcdev = qdev_new(TYPE_NEXT_PC);
-    object_property_set_link(OBJECT(pcdev), "cpu", OBJECT(cpu), &error_abort);
+    qdev_prop_set_link(pcdev, "cpu", OBJECT(cpu));
     sysbus_realize_and_unref(SYS_BUS_DEVICE(pcdev), &error_fatal);
 
     /* 64MB RAM starting at 0x04000000  */
diff --git a/hw/m68k/q800.c b/hw/m68k/q800.c
index 9d52ca6613..1f363a666c 100644
--- a/hw/m68k/q800.c
+++ b/hw/m68k/q800.c
@@ -427,7 +427,7 @@ static void q800_init(MachineState *machine)
 
     /* IRQ Glue */
     glue = qdev_new(TYPE_GLUE);
-    object_property_set_link(OBJECT(glue), "cpu", OBJECT(cpu), &error_abort);
+    qdev_prop_set_link(glue, "cpu", OBJECT(cpu));
     sysbus_realize_and_unref(SYS_BUS_DEVICE(glue), &error_fatal);
 
     /* VIA 1 */
@@ -483,8 +483,7 @@ static void q800_init(MachineState *machine)
     qdev_set_nic_properties(dev, &nd_table[0]);
     qdev_prop_set_uint8(dev, "it_shift", 2);
     qdev_prop_set_bit(dev, "big_endian", true);
-    object_property_set_link(OBJECT(dev), "dma_mr",
-                             OBJECT(get_system_memory()), &error_abort);
+    qdev_prop_set_link(dev, "dma_mr", OBJECT(get_system_memory()));
     sysbus = SYS_BUS_DEVICE(dev);
     sysbus_realize_and_unref(sysbus, &error_fatal);
     sysbus_mmio_map(sysbus, 0, SONIC_BASE);
@@ -520,7 +519,7 @@ static void q800_init(MachineState *machine)
 
     /* Logically OR both its IRQs together */
     escc_orgate = DEVICE(object_new(TYPE_OR_IRQ));
-    object_property_set_int(OBJECT(escc_orgate), "num-lines", 2, &error_fatal);
+    qdev_prop_set_uint16(escc_orgate, "num-lines", 2);
     qdev_realize_and_unref(escc_orgate, NULL, &error_fatal);
     sysbus_connect_irq(sysbus, 0, qdev_get_gpio_in(escc_orgate, 0));
     sysbus_connect_irq(sysbus, 1, qdev_get_gpio_in(escc_orgate, 1));
-- 
2.38.1



^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH 14/19] hw/microblaze: Set QDev properties using QDev API
  2023-02-03 18:08 [PATCH 00/19] hw: Set QDev properties using QDev API (part 1/3) Philippe Mathieu-Daudé
                   ` (12 preceding siblings ...)
  2023-02-03 18:09 ` [PATCH 13/19] hw/m68k: " Philippe Mathieu-Daudé
@ 2023-02-03 18:09 ` Philippe Mathieu-Daudé
  2023-02-03 18:09 ` [RFC PATCH 15/19] hw/mips: " Philippe Mathieu-Daudé
                   ` (6 subsequent siblings)
  20 siblings, 0 replies; 31+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-02-03 18:09 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-arm, Markus Armbruster, Eduardo Habkost, qemu-riscv,
	Philippe Mathieu-Daudé,
	Edgar E. Iglesias, Alistair Francis, Peter Maydell

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/microblaze/petalogix_ml605_mmu.c      | 40 +++++++++++-------------
 hw/microblaze/petalogix_s3adsp1800_mmu.c |  2 +-
 hw/microblaze/xlnx-zynqmp-pmu.c          | 40 ++++++++++--------------
 3 files changed, 35 insertions(+), 47 deletions(-)

diff --git a/hw/microblaze/petalogix_ml605_mmu.c b/hw/microblaze/petalogix_ml605_mmu.c
index a24fadddca..c8cc7d2375 100644
--- a/hw/microblaze/petalogix_ml605_mmu.c
+++ b/hw/microblaze/petalogix_ml605_mmu.c
@@ -71,9 +71,9 @@ petalogix_ml605_init(MachineState *machine)
 {
     ram_addr_t ram_size = machine->ram_size;
     MemoryRegion *address_space_mem = get_system_memory();
-    DeviceState *dev, *dma, *eth0;
+    DeviceState *cpu, *dev, *dma, *eth0;
     Object *ds, *cs;
-    MicroBlazeCPU *cpu;
+    MicroBlazeCPU *mbcpu;
     SysBusDevice *busdev;
     DriveInfo *dinfo;
     int i;
@@ -82,16 +82,16 @@ petalogix_ml605_init(MachineState *machine)
     qemu_irq irq[32];
 
     /* init CPUs */
-    cpu = MICROBLAZE_CPU(object_new(TYPE_MICROBLAZE_CPU));
-    object_property_set_str(OBJECT(cpu), "version", "8.10.a", &error_abort);
+    cpu = DEVICE(object_new(TYPE_MICROBLAZE_CPU));
+    mbcpu = MICROBLAZE_CPU(cpu);
+    qdev_prop_set_string(cpu, "version", "8.10.a");
     /* Use FPU but don't use floating point conversion and square
      * root instructions
      */
-    object_property_set_int(OBJECT(cpu), "use-fpu", 1, &error_abort);
-    object_property_set_bool(OBJECT(cpu), "dcache-writeback", true,
-                             &error_abort);
-    object_property_set_bool(OBJECT(cpu), "endianness", true, &error_abort);
-    qdev_realize(DEVICE(cpu), NULL, &error_abort);
+    qdev_prop_set_uint8(cpu, "use-fpu", 1);
+    qdev_prop_set_bit(cpu, "dcache-writeback", true);
+    qdev_prop_set_bit(cpu, "endianness", true);
+    qdev_realize(cpu, NULL, &error_abort);
 
     /* Attach emulated BRAM through the LMB.  */
     memory_region_init_ram(phys_lmb_bram, NULL, "petalogix_ml605.lmb_bram",
@@ -115,7 +115,7 @@ petalogix_ml605_init(MachineState *machine)
     sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
     sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, INTC_BASEADDR);
     sysbus_connect_irq(SYS_BUS_DEVICE(dev), 0,
-                       qdev_get_gpio_in(DEVICE(cpu), MB_CPU_IRQ));
+                       qdev_get_gpio_in(cpu, MB_CPU_IRQ));
     for (i = 0; i < 32; i++) {
         irq[i] = qdev_get_gpio_in(dev, i);
     }
@@ -148,10 +148,8 @@ petalogix_ml605_init(MachineState *machine)
     qdev_set_nic_properties(eth0, &nd_table[0]);
     qdev_prop_set_uint32(eth0, "rxmem", 0x1000);
     qdev_prop_set_uint32(eth0, "txmem", 0x1000);
-    object_property_set_link(OBJECT(eth0), "axistream-connected", ds,
-                             &error_abort);
-    object_property_set_link(OBJECT(eth0), "axistream-control-connected", cs,
-                             &error_abort);
+    qdev_prop_set_link(eth0, "axistream-connected", ds);
+    qdev_prop_set_link(eth0, "axistream-control-connected", cs);
     sysbus_realize_and_unref(SYS_BUS_DEVICE(eth0), &error_fatal);
     sysbus_mmio_map(SYS_BUS_DEVICE(eth0), 0, AXIENET_BASEADDR);
     sysbus_connect_irq(SYS_BUS_DEVICE(eth0), 0, irq[AXIENET_IRQ]);
@@ -161,10 +159,8 @@ petalogix_ml605_init(MachineState *machine)
     cs = object_property_get_link(OBJECT(eth0),
                                   "axistream-control-connected-target", NULL);
     qdev_prop_set_uint32(dma, "freqhz", 100 * 1000000);
-    object_property_set_link(OBJECT(dma), "axistream-connected", ds,
-                             &error_abort);
-    object_property_set_link(OBJECT(dma), "axistream-control-connected", cs,
-                             &error_abort);
+    qdev_prop_set_link(dma, "axistream-connected", ds);
+    qdev_prop_set_link(dma, "axistream-control-connected", cs);
     sysbus_realize_and_unref(SYS_BUS_DEVICE(dma), &error_fatal);
     sysbus_mmio_map(SYS_BUS_DEVICE(dma), 0, AXIDMA_BASEADDR);
     sysbus_connect_irq(SYS_BUS_DEVICE(dma), 0, irq[AXIDMA_IRQ0]);
@@ -200,11 +196,11 @@ petalogix_ml605_init(MachineState *machine)
     }
 
     /* setup PVR to match kernel settings */
-    cpu->cfg.pvr_regs[4] = 0xc56b8000;
-    cpu->cfg.pvr_regs[5] = 0xc56be000;
-    cpu->cfg.pvr_regs[10] = 0x0e000000; /* virtex 6 */
+    mbcpu->cfg.pvr_regs[4] = 0xc56b8000;
+    mbcpu->cfg.pvr_regs[5] = 0xc56be000;
+    mbcpu->cfg.pvr_regs[10] = 0x0e000000; /* virtex 6 */
 
-    microblaze_load_kernel(cpu, MEMORY_BASEADDR, ram_size,
+    microblaze_load_kernel(mbcpu, MEMORY_BASEADDR, ram_size,
                            machine->initrd_filename,
                            BINARY_DEVICE_TREE_FILE,
                            NULL);
diff --git a/hw/microblaze/petalogix_s3adsp1800_mmu.c b/hw/microblaze/petalogix_s3adsp1800_mmu.c
index 9d959d1ad8..9df1dd72f3 100644
--- a/hw/microblaze/petalogix_s3adsp1800_mmu.c
+++ b/hw/microblaze/petalogix_s3adsp1800_mmu.c
@@ -70,7 +70,7 @@ petalogix_s3adsp1800_init(MachineState *machine)
     MemoryRegion *sysmem = get_system_memory();
 
     cpu = MICROBLAZE_CPU(object_new(TYPE_MICROBLAZE_CPU));
-    object_property_set_str(OBJECT(cpu), "version", "7.10.d", &error_abort);
+    qdev_prop_set_string(DEVICE(cpu), "version", "7.10.d");
     qdev_realize(DEVICE(cpu), NULL, &error_abort);
 
     /* Attach emulated BRAM through the LMB.  */
diff --git a/hw/microblaze/xlnx-zynqmp-pmu.c b/hw/microblaze/xlnx-zynqmp-pmu.c
index 5a2016672a..e6f221d3eb 100644
--- a/hw/microblaze/xlnx-zynqmp-pmu.c
+++ b/hw/microblaze/xlnx-zynqmp-pmu.c
@@ -18,6 +18,7 @@
 #include "qemu/osdep.h"
 #include "qapi/error.h"
 #include "exec/address-spaces.h"
+#include "hw/qdev-properties.h"
 #include "hw/boards.h"
 #include "cpu.h"
 #include "boot.h"
@@ -76,35 +77,26 @@ static void xlnx_zynqmp_pmu_soc_init(Object *obj)
 static void xlnx_zynqmp_pmu_soc_realize(DeviceState *dev, Error **errp)
 {
     XlnxZynqMPPMUSoCState *s = XLNX_ZYNQMP_PMU_SOC(dev);
+    DeviceState *cpu = DEVICE(&s->cpu);
 
-    object_property_set_uint(OBJECT(&s->cpu), "base-vectors",
-                             XLNX_ZYNQMP_PMU_ROM_ADDR, &error_abort);
-    object_property_set_bool(OBJECT(&s->cpu), "use-stack-protection", true,
-                             &error_abort);
-    object_property_set_uint(OBJECT(&s->cpu), "use-fpu", 0, &error_abort);
-    object_property_set_uint(OBJECT(&s->cpu), "use-hw-mul", 0, &error_abort);
-    object_property_set_bool(OBJECT(&s->cpu), "use-barrel", true,
-                             &error_abort);
-    object_property_set_bool(OBJECT(&s->cpu), "use-msr-instr", true,
-                             &error_abort);
-    object_property_set_bool(OBJECT(&s->cpu), "use-pcmp-instr", true,
-                             &error_abort);
-    object_property_set_bool(OBJECT(&s->cpu), "use-mmu", false, &error_abort);
-    object_property_set_bool(OBJECT(&s->cpu), "endianness", true,
-                             &error_abort);
-    object_property_set_str(OBJECT(&s->cpu), "version", "8.40.b",
-                            &error_abort);
-    object_property_set_uint(OBJECT(&s->cpu), "pvr", 0, &error_abort);
+    qdev_prop_set_uint32(cpu, "base-vectors", XLNX_ZYNQMP_PMU_ROM_ADDR);
+    qdev_prop_set_bit(cpu, "use-stack-protection", true);
+    qdev_prop_set_uint8(cpu, "use-fpu", 0);
+    qdev_prop_set_uint8(cpu, "use-hw-mul", 0);
+    qdev_prop_set_bit(cpu, "use-barrel", true);
+    qdev_prop_set_bit(cpu, "use-msr-instr", true);
+    qdev_prop_set_bit(cpu, "use-pcmp-instr", true);
+    qdev_prop_set_bit(cpu, "use-mmu", false);
+    qdev_prop_set_bit(cpu, "endianness", true);
+    qdev_prop_set_string(cpu, "version", "8.40.b");
+    qdev_prop_set_uint8(cpu, "pvr", 0);
     if (!qdev_realize(DEVICE(&s->cpu), NULL, errp)) {
         return;
     }
 
-    object_property_set_uint(OBJECT(&s->intc), "intc-intr-size", 0x10,
-                             &error_abort);
-    object_property_set_uint(OBJECT(&s->intc), "intc-level-edge", 0x0,
-                             &error_abort);
-    object_property_set_uint(OBJECT(&s->intc), "intc-positive", 0xffff,
-                             &error_abort);
+    qdev_prop_set_uint32(DEVICE(&s->intc), "intc-intr-size", 0x10);
+    qdev_prop_set_uint32(DEVICE(&s->intc), "intc-level-edge", 0x0);
+    qdev_prop_set_uint32(DEVICE(&s->intc), "intc-positive", 0xffff);
     if (!sysbus_realize(SYS_BUS_DEVICE(&s->intc), errp)) {
         return;
     }
-- 
2.38.1



^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [RFC PATCH 15/19] hw/mips: Set QDev properties using QDev API
  2023-02-03 18:08 [PATCH 00/19] hw: Set QDev properties using QDev API (part 1/3) Philippe Mathieu-Daudé
                   ` (13 preceding siblings ...)
  2023-02-03 18:09 ` [PATCH 14/19] hw/microblaze: " Philippe Mathieu-Daudé
@ 2023-02-03 18:09 ` Philippe Mathieu-Daudé
  2023-02-03 18:09 ` [PATCH 16/19] hw/nios2: " Philippe Mathieu-Daudé
                   ` (5 subsequent siblings)
  20 siblings, 0 replies; 31+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-02-03 18:09 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-arm, Markus Armbruster, Eduardo Habkost, qemu-riscv,
	Philippe Mathieu-Daudé,
	Paul Burton, Aleksandar Rikalo, Hervé Poussineau,
	Aurelien Jarno, Jiaxun Yang

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/mips/boston.c |  6 ++----
 hw/mips/cps.c    | 42 ++++++++++++++----------------------------
 hw/mips/jazz.c   |  3 +--
 hw/mips/malta.c  |  6 ++----
 4 files changed, 19 insertions(+), 38 deletions(-)

diff --git a/hw/mips/boston.c b/hw/mips/boston.c
index 21ad844519..f3c2179f66 100644
--- a/hw/mips/boston.c
+++ b/hw/mips/boston.c
@@ -700,10 +700,8 @@ static void boston_mach_init(MachineState *machine)
     }
 
     object_initialize_child(OBJECT(machine), "cps", &s->cps, TYPE_MIPS_CPS);
-    object_property_set_str(OBJECT(&s->cps), "cpu-type", machine->cpu_type,
-                            &error_fatal);
-    object_property_set_uint(OBJECT(&s->cps), "num-vp", machine->smp.cpus,
-                            &error_fatal);
+    qdev_prop_set_string(DEVICE(&s->cps), "cpu-type", machine->cpu_type);
+    qdev_prop_set_uint32(DEVICE(&s->cps), "num-vp", machine->smp.cpus);
     qdev_connect_clock_in(DEVICE(&s->cps), "clk-in",
                           qdev_get_clock_out(dev, "cpu-refclk"));
     sysbus_realize(SYS_BUS_DEVICE(&s->cps), &error_fatal);
diff --git a/hw/mips/cps.c b/hw/mips/cps.c
index 2b5269ebf1..3109644c5e 100644
--- a/hw/mips/cps.c
+++ b/hw/mips/cps.c
@@ -79,10 +79,8 @@ static void mips_cps_realize(DeviceState *dev, Error **errp)
         CPUMIPSState *env = &cpu->env;
 
         /* All VPs are halted on reset. Leave powering up to CPC. */
-        if (!object_property_set_bool(OBJECT(cpu), "start-powered-off", true,
-                                      errp)) {
-            return;
-        }
+        qdev_prop_set_bit(DEVICE(cpu), "start-powered-off", true);
+
         /* All cores use the same clock tree */
         qdev_connect_clock_in(DEVICE(cpu), "clk-in", s->clock);
 
@@ -106,12 +104,9 @@ static void mips_cps_realize(DeviceState *dev, Error **errp)
     /* Inter-Thread Communication Unit */
     if (itu_present) {
         object_initialize_child(OBJECT(dev), "itu", &s->itu, TYPE_MIPS_ITU);
-        object_property_set_link(OBJECT(&s->itu), "cpu[0]",
-                                 OBJECT(first_cpu), &error_abort);
-        object_property_set_uint(OBJECT(&s->itu), "num-fifo", 16,
-                                &error_abort);
-        object_property_set_uint(OBJECT(&s->itu), "num-semaphores", 16,
-                                &error_abort);
+        qdev_prop_set_link(DEVICE(&s->itu), "cpu[0]", OBJECT(first_cpu));
+        qdev_prop_set_uint32(DEVICE(&s->itu), "num-fifo", 16);
+        qdev_prop_set_uint32(DEVICE(&s->itu), "num-semaphores", 16);
         if (!sysbus_realize(SYS_BUS_DEVICE(&s->itu), errp)) {
             return;
         }
@@ -122,10 +117,8 @@ static void mips_cps_realize(DeviceState *dev, Error **errp)
 
     /* Cluster Power Controller */
     object_initialize_child(OBJECT(dev), "cpc", &s->cpc, TYPE_MIPS_CPC);
-    object_property_set_uint(OBJECT(&s->cpc), "num-vp", s->num_vp,
-                            &error_abort);
-    object_property_set_int(OBJECT(&s->cpc), "vp-start-running", 1,
-                            &error_abort);
+    qdev_prop_set_uint32(DEVICE(&s->cpc), "num-vp", s->num_vp);
+    qdev_prop_set_uint64(DEVICE(&s->cpc), "vp-start-running", 0x1);
     if (!sysbus_realize(SYS_BUS_DEVICE(&s->cpc), errp)) {
         return;
     }
@@ -135,10 +128,8 @@ static void mips_cps_realize(DeviceState *dev, Error **errp)
 
     /* Global Interrupt Controller */
     object_initialize_child(OBJECT(dev), "gic", &s->gic, TYPE_MIPS_GIC);
-    object_property_set_uint(OBJECT(&s->gic), "num-vp", s->num_vp,
-                            &error_abort);
-    object_property_set_uint(OBJECT(&s->gic), "num-irq", 128,
-                            &error_abort);
+    qdev_prop_set_uint32(DEVICE(&s->gic), "num-vp", s->num_vp);
+    qdev_prop_set_uint32(DEVICE(&s->gic), "num-irq", 128);
     if (!sysbus_realize(SYS_BUS_DEVICE(&s->gic), errp)) {
         return;
     }
@@ -150,16 +141,11 @@ static void mips_cps_realize(DeviceState *dev, Error **errp)
     gcr_base = MIPS_CPU(first_cpu)->env.CP0_CMGCRBase << 4;
 
     object_initialize_child(OBJECT(dev), "gcr", &s->gcr, TYPE_MIPS_GCR);
-    object_property_set_uint(OBJECT(&s->gcr), "num-vp", s->num_vp,
-                            &error_abort);
-    object_property_set_int(OBJECT(&s->gcr), "gcr-rev", 0x800,
-                            &error_abort);
-    object_property_set_int(OBJECT(&s->gcr), "gcr-base", gcr_base,
-                            &error_abort);
-    object_property_set_link(OBJECT(&s->gcr), "gic", OBJECT(&s->gic.mr),
-                             &error_abort);
-    object_property_set_link(OBJECT(&s->gcr), "cpc", OBJECT(&s->cpc.mr),
-                             &error_abort);
+    qdev_prop_set_uint32(DEVICE(&s->gcr), "num-vp", s->num_vp);
+    qdev_prop_set_int32(DEVICE(&s->gcr), "gcr-rev", 0x800);
+    qdev_prop_set_uint64(DEVICE(&s->gcr), "gcr-base", gcr_base);
+    qdev_prop_set_link(DEVICE(&s->gcr), "gic", OBJECT(&s->gic.mr));
+    qdev_prop_set_link(DEVICE(&s->gcr), "cpc", OBJECT(&s->cpc.mr));
     if (!sysbus_realize(SYS_BUS_DEVICE(&s->gcr), errp)) {
         return;
     }
diff --git a/hw/mips/jazz.c b/hw/mips/jazz.c
index 6aefe9a61b..d18aeb439b 100644
--- a/hw/mips/jazz.c
+++ b/hw/mips/jazz.c
@@ -302,8 +302,7 @@ static void mips_jazz_init(MachineState *machine,
             qdev_set_nic_properties(dev, nd);
             qdev_prop_set_uint8(dev, "it_shift", 2);
             qdev_prop_set_bit(dev, "big_endian", big_endian > 0);
-            object_property_set_link(OBJECT(dev), "dma_mr",
-                                     OBJECT(rc4030_dma_mr), &error_abort);
+            qdev_prop_set_link(dev, "dma_mr", OBJECT(rc4030_dma_mr));
             sysbus = SYS_BUS_DEVICE(dev);
             sysbus_realize_and_unref(sysbus, &error_fatal);
             sysbus_mmio_map(sysbus, 0, 0x80001000);
diff --git a/hw/mips/malta.c b/hw/mips/malta.c
index af9021316d..3b88668bae 100644
--- a/hw/mips/malta.c
+++ b/hw/mips/malta.c
@@ -1064,10 +1064,8 @@ static void create_cps(MachineState *ms, MaltaState *s,
                        qemu_irq *cbus_irq, qemu_irq *i8259_irq)
 {
     object_initialize_child(OBJECT(s), "cps", &s->cps, TYPE_MIPS_CPS);
-    object_property_set_str(OBJECT(&s->cps), "cpu-type", ms->cpu_type,
-                            &error_fatal);
-    object_property_set_uint(OBJECT(&s->cps), "num-vp", ms->smp.cpus,
-                            &error_fatal);
+    qdev_prop_set_string(DEVICE(&s->cps), "cpu-type", ms->cpu_type);
+    qdev_prop_set_uint32(DEVICE(&s->cps), "num-vp", ms->smp.cpus);
     qdev_connect_clock_in(DEVICE(&s->cps), "clk-in", s->cpuclk);
     sysbus_realize(SYS_BUS_DEVICE(&s->cps), &error_fatal);
 
-- 
2.38.1



^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH 16/19] hw/nios2: Set QDev properties using QDev API
  2023-02-03 18:08 [PATCH 00/19] hw: Set QDev properties using QDev API (part 1/3) Philippe Mathieu-Daudé
                   ` (14 preceding siblings ...)
  2023-02-03 18:09 ` [RFC PATCH 15/19] hw/mips: " Philippe Mathieu-Daudé
@ 2023-02-03 18:09 ` Philippe Mathieu-Daudé
  2023-02-03 18:09 ` [RFC PATCH 17/19] hw/riscv: " Philippe Mathieu-Daudé
                   ` (4 subsequent siblings)
  20 siblings, 0 replies; 31+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-02-03 18:09 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-arm, Markus Armbruster, Eduardo Habkost, qemu-riscv,
	Philippe Mathieu-Daudé,
	Chris Wulff, Marek Vasut

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/nios2/10m50_devboard.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/hw/nios2/10m50_devboard.c b/hw/nios2/10m50_devboard.c
index 91383fb097..01f6d5c84c 100644
--- a/hw/nios2/10m50_devboard.c
+++ b/hw/nios2/10m50_devboard.c
@@ -102,7 +102,7 @@ static void nios2_10m50_ghrd_init(MachineState *machine)
         MemoryRegion *dev_mr;
         qemu_irq cpu_irq;
 
-        object_property_set_link(OBJECT(dev), "cpu", OBJECT(cpu), &error_fatal);
+        qdev_prop_set_link(dev, "cpu", OBJECT(cpu));
         sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
 
         cpu_irq = qdev_get_gpio_in_named(DEVICE(cpu), "EIC", 0);
-- 
2.38.1



^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [RFC PATCH 17/19] hw/riscv: Set QDev properties using QDev API
  2023-02-03 18:08 [PATCH 00/19] hw: Set QDev properties using QDev API (part 1/3) Philippe Mathieu-Daudé
                   ` (15 preceding siblings ...)
  2023-02-03 18:09 ` [PATCH 16/19] hw/nios2: " Philippe Mathieu-Daudé
@ 2023-02-03 18:09 ` Philippe Mathieu-Daudé
  2023-02-03 18:09 ` [PATCH 18/19] hw/rx: " Philippe Mathieu-Daudé
                   ` (3 subsequent siblings)
  20 siblings, 0 replies; 31+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-02-03 18:09 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-arm, Markus Armbruster, Eduardo Habkost, qemu-riscv,
	Philippe Mathieu-Daudé,
	Bin Meng, Palmer Dabbelt, Alistair Francis, Vijai Kumar K

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/riscv/microchip_pfsoc.c |  8 ++++----
 hw/riscv/opentitan.c       |  9 +++------
 hw/riscv/shakti_c.c        |  7 +++----
 hw/riscv/sifive_e.c        |  8 +++-----
 hw/riscv/sifive_u.c        |  9 +++------
 hw/riscv/spike.c           | 10 ++++------
 hw/riscv/virt.c            |  9 +++------
 7 files changed, 23 insertions(+), 37 deletions(-)

diff --git a/hw/riscv/microchip_pfsoc.c b/hw/riscv/microchip_pfsoc.c
index 82ae5e7023..ff6c4b0471 100644
--- a/hw/riscv/microchip_pfsoc.c
+++ b/hw/riscv/microchip_pfsoc.c
@@ -423,16 +423,16 @@ static void microchip_pfsoc_soc_realize(DeviceState *dev, Error **errp)
         qdev_set_nic_properties(DEVICE(&s->gem1), nd);
     }
 
-    object_property_set_int(OBJECT(&s->gem0), "revision", GEM_REVISION, errp);
-    object_property_set_int(OBJECT(&s->gem0), "phy-addr", 8, errp);
+    qdev_prop_set_uint32(DEVICE(&s->gem0), "revision", GEM_REVISION);
+    qdev_prop_set_uint8(DEVICE(&s->gem0), "phy-addr", 8);
     sysbus_realize(SYS_BUS_DEVICE(&s->gem0), errp);
     sysbus_mmio_map(SYS_BUS_DEVICE(&s->gem0), 0,
                     memmap[MICROCHIP_PFSOC_GEM0].base);
     sysbus_connect_irq(SYS_BUS_DEVICE(&s->gem0), 0,
         qdev_get_gpio_in(DEVICE(s->plic), MICROCHIP_PFSOC_GEM0_IRQ));
 
-    object_property_set_int(OBJECT(&s->gem1), "revision", GEM_REVISION, errp);
-    object_property_set_int(OBJECT(&s->gem1), "phy-addr", 9, errp);
+    qdev_prop_set_uint32(DEVICE(&s->gem1), "revision", GEM_REVISION);
+    qdev_prop_set_uint8(DEVICE(&s->gem1), "phy-addr", 9);
     sysbus_realize(SYS_BUS_DEVICE(&s->gem1), errp);
     sysbus_mmio_map(SYS_BUS_DEVICE(&s->gem1), 0,
                     memmap[MICROCHIP_PFSOC_GEM1].base);
diff --git a/hw/riscv/opentitan.c b/hw/riscv/opentitan.c
index 64d5d435b9..f69db8c31e 100644
--- a/hw/riscv/opentitan.c
+++ b/hw/riscv/opentitan.c
@@ -145,12 +145,9 @@ static void lowrisc_ibex_soc_realize(DeviceState *dev_soc, Error **errp)
     MemoryRegion *sys_mem = get_system_memory();
     int i;
 
-    object_property_set_str(OBJECT(&s->cpus), "cpu-type", ms->cpu_type,
-                            &error_abort);
-    object_property_set_int(OBJECT(&s->cpus), "num-harts", ms->smp.cpus,
-                            &error_abort);
-    object_property_set_int(OBJECT(&s->cpus), "resetvec", s->resetvec,
-                            &error_abort);
+    qdev_prop_set_string(DEVICE(&s->cpus), "cpu-type", ms->cpu_type);
+    qdev_prop_set_uint32(DEVICE(&s->cpus), "num-harts", ms->smp.cpus);
+    qdev_prop_set_uint64(DEVICE(&s->cpus), "resetvec", s->resetvec);
     sysbus_realize(SYS_BUS_DEVICE(&s->cpus), &error_fatal);
 
     /* Boot ROM */
diff --git a/hw/riscv/shakti_c.c b/hw/riscv/shakti_c.c
index e43cc9445c..32d3d7cbab 100644
--- a/hw/riscv/shakti_c.c
+++ b/hw/riscv/shakti_c.c
@@ -168,10 +168,9 @@ static void shakti_c_soc_instance_init(Object *obj)
      * So let it be in instance_init. When supported should use ms->cpu_type
      * instead of TYPE_RISCV_CPU_SHAKTI_C
      */
-    object_property_set_str(OBJECT(&sss->cpus), "cpu-type",
-                            TYPE_RISCV_CPU_SHAKTI_C, &error_abort);
-    object_property_set_int(OBJECT(&sss->cpus), "num-harts", 1,
-                            &error_abort);
+    qdev_prop_set_string(DEVICE(&sss->cpus), "cpu-type",
+                         TYPE_RISCV_CPU_SHAKTI_C);
+    qdev_prop_set_uint32(DEVICE(&sss->cpus), "num-harts", 1);
 }
 
 static const TypeInfo shakti_c_type_info = {
diff --git a/hw/riscv/sifive_e.c b/hw/riscv/sifive_e.c
index 3e3f4b0088..0f5dfc5f3d 100644
--- a/hw/riscv/sifive_e.c
+++ b/hw/riscv/sifive_e.c
@@ -178,9 +178,8 @@ static void sifive_e_soc_init(Object *obj)
     SiFiveESoCState *s = RISCV_E_SOC(obj);
 
     object_initialize_child(obj, "cpus", &s->cpus, TYPE_RISCV_HART_ARRAY);
-    object_property_set_int(OBJECT(&s->cpus), "num-harts", ms->smp.cpus,
-                            &error_abort);
-    object_property_set_int(OBJECT(&s->cpus), "resetvec", 0x1004, &error_abort);
+    qdev_prop_set_uint32(DEVICE(&s->cpus), "num-harts", ms->smp.cpus);
+    qdev_prop_set_uint64(DEVICE(&s->cpus), "resetvec", 0x1004);
     object_initialize_child(obj, "riscv.sifive.e.gpio0", &s->gpio,
                             TYPE_SIFIVE_GPIO);
 }
@@ -192,8 +191,7 @@ static void sifive_e_soc_realize(DeviceState *dev, Error **errp)
     SiFiveESoCState *s = RISCV_E_SOC(dev);
     MemoryRegion *sys_mem = get_system_memory();
 
-    object_property_set_str(OBJECT(&s->cpus), "cpu-type", ms->cpu_type,
-                            &error_abort);
+    qdev_prop_set_string(DEVICE(&s->cpus), "cpu-type", ms->cpu_type);
     sysbus_realize(SYS_BUS_DEVICE(&s->cpus), &error_fatal);
 
     /* Mask ROM */
diff --git a/hw/riscv/sifive_u.c b/hw/riscv/sifive_u.c
index 2fb6ee231f..97f504d011 100644
--- a/hw/riscv/sifive_u.c
+++ b/hw/riscv/sifive_u.c
@@ -540,10 +540,8 @@ static void sifive_u_machine_init(MachineState *machine)
 
     /* Initialize SoC */
     object_initialize_child(OBJECT(machine), "soc", &s->soc, TYPE_RISCV_U_SOC);
-    object_property_set_uint(OBJECT(&s->soc), "serial", s->serial,
-                             &error_abort);
-    object_property_set_str(OBJECT(&s->soc), "cpu-type", machine->cpu_type,
-                             &error_abort);
+    qdev_prop_set_uint32(DEVICE(&s->soc), "serial", s->serial);
+    qdev_prop_set_string(DEVICE(&s->soc), "cpu-type", machine->cpu_type);
     qdev_realize(DEVICE(&s->soc), NULL, &error_fatal);
 
     /* register RAM */
@@ -905,8 +903,7 @@ static void sifive_u_soc_realize(DeviceState *dev, Error **errp)
         qemu_check_nic_model(nd, TYPE_CADENCE_GEM);
         qdev_set_nic_properties(DEVICE(&s->gem), nd);
     }
-    object_property_set_int(OBJECT(&s->gem), "revision", GEM_REVISION,
-                            &error_abort);
+    qdev_prop_set_uint32(DEVICE(&s->gem), "revision", GEM_REVISION);
     if (!sysbus_realize(SYS_BUS_DEVICE(&s->gem), errp)) {
         return;
     }
diff --git a/hw/riscv/spike.c b/hw/riscv/spike.c
index badc11ec43..328278d820 100644
--- a/hw/riscv/spike.c
+++ b/hw/riscv/spike.c
@@ -25,6 +25,7 @@
 #include "qemu/osdep.h"
 #include "qemu/error-report.h"
 #include "qapi/error.h"
+#include "hw/qdev-properties.h"
 #include "hw/boards.h"
 #include "hw/loader.h"
 #include "hw/sysbus.h"
@@ -238,12 +239,9 @@ static void spike_board_init(MachineState *machine)
         object_initialize_child(OBJECT(machine), soc_name, &s->soc[i],
                                 TYPE_RISCV_HART_ARRAY);
         g_free(soc_name);
-        object_property_set_str(OBJECT(&s->soc[i]), "cpu-type",
-                                machine->cpu_type, &error_abort);
-        object_property_set_int(OBJECT(&s->soc[i]), "hartid-base",
-                                base_hartid, &error_abort);
-        object_property_set_int(OBJECT(&s->soc[i]), "num-harts",
-                                hart_count, &error_abort);
+        qdev_prop_set_string(DEVICE(&s->soc[i]), "cpu-type", machine->cpu_type);
+        qdev_prop_set_uint32(DEVICE(&s->soc[i]), "hartid-base", base_hartid);
+        qdev_prop_set_uint32(DEVICE(&s->soc[i]), "num-harts", hart_count);
         sysbus_realize(SYS_BUS_DEVICE(&s->soc[i]), &error_fatal);
 
         /* Core Local Interruptor (timer and IPI) for each socket */
diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c
index 4a11b4b010..0e091cb65f 100644
--- a/hw/riscv/virt.c
+++ b/hw/riscv/virt.c
@@ -1360,12 +1360,9 @@ static void virt_machine_init(MachineState *machine)
         object_initialize_child(OBJECT(machine), soc_name, &s->soc[i],
                                 TYPE_RISCV_HART_ARRAY);
         g_free(soc_name);
-        object_property_set_str(OBJECT(&s->soc[i]), "cpu-type",
-                                machine->cpu_type, &error_abort);
-        object_property_set_int(OBJECT(&s->soc[i]), "hartid-base",
-                                base_hartid, &error_abort);
-        object_property_set_int(OBJECT(&s->soc[i]), "num-harts",
-                                hart_count, &error_abort);
+        qdev_prop_set_string(DEVICE(&s->soc[i]), "cpu-type", machine->cpu_type);
+        qdev_prop_set_uint32(DEVICE(&s->soc[i]), "hartid-base", base_hartid);
+        qdev_prop_set_uint32(DEVICE(&s->soc[i]), "num-harts", hart_count);
         sysbus_realize(SYS_BUS_DEVICE(&s->soc[i]), &error_fatal);
 
         if (!kvm_enabled()) {
-- 
2.38.1



^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH 18/19] hw/rx: Set QDev properties using QDev API
  2023-02-03 18:08 [PATCH 00/19] hw: Set QDev properties using QDev API (part 1/3) Philippe Mathieu-Daudé
                   ` (16 preceding siblings ...)
  2023-02-03 18:09 ` [RFC PATCH 17/19] hw/riscv: " Philippe Mathieu-Daudé
@ 2023-02-03 18:09 ` Philippe Mathieu-Daudé
  2023-02-06 13:01   ` Yoshinori Sato
  2023-02-03 18:09 ` [PATCH 19/19] hw/sparc: " Philippe Mathieu-Daudé
                   ` (2 subsequent siblings)
  20 siblings, 1 reply; 31+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-02-03 18:09 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-arm, Markus Armbruster, Eduardo Habkost, qemu-riscv,
	Philippe Mathieu-Daudé,
	Yoshinori Sato

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/rx/rx-gdbsim.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/hw/rx/rx-gdbsim.c b/hw/rx/rx-gdbsim.c
index 47c17026c7..5d50f36877 100644
--- a/hw/rx/rx-gdbsim.c
+++ b/hw/rx/rx-gdbsim.c
@@ -21,6 +21,7 @@
 #include "qemu/error-report.h"
 #include "qemu/guest-random.h"
 #include "qapi/error.h"
+#include "hw/qdev-properties.h"
 #include "hw/loader.h"
 #include "hw/rx/rx62n.h"
 #include "sysemu/qtest.h"
@@ -99,12 +100,10 @@ static void rx_gdbsim_init(MachineState *machine)
 
     /* Initialize MCU */
     object_initialize_child(OBJECT(machine), "mcu", &s->mcu, rxc->mcu_name);
-    object_property_set_link(OBJECT(&s->mcu), "main-bus", OBJECT(sysmem),
-                             &error_abort);
-    object_property_set_uint(OBJECT(&s->mcu), "xtal-frequency-hz",
-                             rxc->xtal_freq_hz, &error_abort);
-    object_property_set_bool(OBJECT(&s->mcu), "load-kernel",
-                             kernel_filename != NULL, &error_abort);
+    qdev_prop_set_link(DEVICE(&s->mcu), "main-bus", OBJECT(sysmem));
+    qdev_prop_set_uint32(DEVICE(&s->mcu), "xtal-frequency-hz",
+                         rxc->xtal_freq_hz);
+    qdev_prop_set_bit(DEVICE(&s->mcu), "load-kernel", kernel_filename != NULL);
 
     if (!kernel_filename) {
         if (machine->firmware) {
-- 
2.38.1



^ permalink raw reply related	[flat|nested] 31+ messages in thread

* [PATCH 19/19] hw/sparc: Set QDev properties using QDev API
  2023-02-03 18:08 [PATCH 00/19] hw: Set QDev properties using QDev API (part 1/3) Philippe Mathieu-Daudé
                   ` (17 preceding siblings ...)
  2023-02-03 18:09 ` [PATCH 18/19] hw/rx: " Philippe Mathieu-Daudé
@ 2023-02-03 18:09 ` 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-03-01 13:42 ` Igor Mammedov
  20 siblings, 0 replies; 31+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-02-03 18:09 UTC (permalink / raw)
  To: qemu-devel
  Cc: qemu-arm, Markus Armbruster, Eduardo Habkost, qemu-riscv,
	Philippe Mathieu-Daudé,
	Mark Cave-Ayland, Artyom Tarasenko

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/dma/sparc32_dma.c |  6 +++---
 hw/sparc/sun4m.c     | 10 ++++------
 hw/sparc64/sun4u.c   |  3 +--
 3 files changed, 8 insertions(+), 11 deletions(-)

diff --git a/hw/dma/sparc32_dma.c b/hw/dma/sparc32_dma.c
index 0ef13c5e9a..49816755c2 100644
--- a/hw/dma/sparc32_dma.c
+++ b/hw/dma/sparc32_dma.c
@@ -347,7 +347,7 @@ static void sparc32_ledma_device_realize(DeviceState *dev, Error **errp)
     LEDMADeviceState *s = SPARC32_LEDMA_DEVICE(dev);
     SysBusPCNetState *lance = SYSBUS_PCNET(&s->lance);
 
-    object_property_set_link(OBJECT(lance), "dma", OBJECT(dev), &error_abort);
+    qdev_prop_set_link(DEVICE(lance), "dma", OBJECT(dev));
     sysbus_realize(SYS_BUS_DEVICE(lance), &error_fatal);
 }
 
@@ -380,7 +380,7 @@ static void sparc32_dma_realize(DeviceState *dev, Error **errp)
     }
 
     espdma = DEVICE(&s->espdma);
-    object_property_set_link(OBJECT(espdma), "iommu", iommu, &error_abort);
+    qdev_prop_set_link(espdma, "iommu", iommu);
     sysbus_realize(SYS_BUS_DEVICE(espdma), &error_fatal);
 
     esp = DEVICE(object_resolve_path_component(OBJECT(espdma), "esp"));
@@ -394,7 +394,7 @@ static void sparc32_dma_realize(DeviceState *dev, Error **errp)
                                 sysbus_mmio_get_region(sbd, 0));
 
     ledma = DEVICE(&s->ledma);
-    object_property_set_link(OBJECT(ledma), "iommu", iommu, &error_abort);
+    qdev_prop_set_link(ledma, "iommu", iommu);
     sysbus_realize(SYS_BUS_DEVICE(ledma), &error_fatal);
 
     lance = DEVICE(object_resolve_path_component(OBJECT(ledma), "lance"));
diff --git a/hw/sparc/sun4m.c b/hw/sparc/sun4m.c
index d9288326d6..f241a676b3 100644
--- a/hw/sparc/sun4m.c
+++ b/hw/sparc/sun4m.c
@@ -803,8 +803,7 @@ static void cpu_devinit(const char *cpu_type, unsigned int id,
     env = &cpu->env;
 
     qemu_register_reset(sun4m_cpu_reset, cpu);
-    object_property_set_bool(OBJECT(cpu), "start-powered-off", id != 0,
-                             &error_fatal);
+    qdev_prop_set_bit(DEVICE(cpu), "start-powered-off", id != 0);
     qdev_realize_and_unref(DEVICE(cpu), NULL, &error_fatal);
     cpu_sparc_set_id(env, id);
     *cpu_irqs = qemu_allocate_irqs(cpu_set_irq, cpu, MAX_PILS);
@@ -851,7 +850,7 @@ static void sun4m_hw_init(MachineState *machine)
 
     /* Create and map RAM frontend */
     dev = qdev_new("memory");
-    object_property_set_link(OBJECT(dev), "memdev", OBJECT(ram_memdev), &error_fatal);
+    qdev_prop_set_link(dev, "memdev", OBJECT(ram_memdev));
     sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
     sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, 0);
 
@@ -978,7 +977,7 @@ static void sun4m_hw_init(MachineState *machine)
 
     /* Logically OR both its IRQs together */
     ms_kb_orgate = DEVICE(object_new(TYPE_OR_IRQ));
-    object_property_set_int(OBJECT(ms_kb_orgate), "num-lines", 2, &error_fatal);
+    qdev_prop_set_uint16(ms_kb_orgate, "num-lines", 2);
     qdev_realize_and_unref(ms_kb_orgate, NULL, &error_fatal);
     sysbus_connect_irq(s, 0, qdev_get_gpio_in(ms_kb_orgate, 0));
     sysbus_connect_irq(s, 1, qdev_get_gpio_in(ms_kb_orgate, 1));
@@ -999,8 +998,7 @@ static void sun4m_hw_init(MachineState *machine)
 
     /* Logically OR both its IRQs together */
     serial_orgate = DEVICE(object_new(TYPE_OR_IRQ));
-    object_property_set_int(OBJECT(serial_orgate), "num-lines", 2,
-                            &error_fatal);
+    qdev_prop_set_uint16(serial_orgate, "num-lines", 2);
     qdev_realize_and_unref(serial_orgate, NULL, &error_fatal);
     sysbus_connect_irq(s, 0, qdev_get_gpio_in(serial_orgate, 0));
     sysbus_connect_irq(s, 1, qdev_get_gpio_in(serial_orgate, 1));
diff --git a/hw/sparc64/sun4u.c b/hw/sparc64/sun4u.c
index 387181ff77..823d527078 100644
--- a/hw/sparc64/sun4u.c
+++ b/hw/sparc64/sun4u.c
@@ -583,8 +583,7 @@ static void sun4uv_init(MemoryRegion *address_space_mem,
     sabre = SABRE(qdev_new(TYPE_SABRE));
     qdev_prop_set_uint64(DEVICE(sabre), "special-base", PBM_SPECIAL_BASE);
     qdev_prop_set_uint64(DEVICE(sabre), "mem-base", PBM_MEM_BASE);
-    object_property_set_link(OBJECT(sabre), "iommu", OBJECT(iommu),
-                             &error_abort);
+    qdev_prop_set_link(DEVICE(sabre), "iommu", OBJECT(iommu));
     sysbus_realize_and_unref(SYS_BUS_DEVICE(sabre), &error_fatal);
 
     /* sabre_config */
-- 
2.38.1



^ permalink raw reply related	[flat|nested] 31+ messages in thread

* Re: [PATCH 00/19] hw: Set QDev properties using QDev API (part 1/3)
  2023-02-03 18:08 [PATCH 00/19] hw: Set QDev properties using QDev API (part 1/3) Philippe Mathieu-Daudé
                   ` (18 preceding siblings ...)
  2023-02-03 18:09 ` [PATCH 19/19] hw/sparc: " Philippe Mathieu-Daudé
@ 2023-02-03 18:12 ` Philippe Mathieu-Daudé
  2023-02-03 18:52   ` BALATON Zoltan
  2023-03-01 13:42 ` Igor Mammedov
  20 siblings, 1 reply; 31+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-02-03 18:12 UTC (permalink / raw)
  To: qemu-devel; +Cc: qemu-arm, Markus Armbruster, Eduardo Habkost, qemu-riscv

On 3/2/23 19:08, Philippe Mathieu-Daudé wrote:
> QEMU provides the QOM API for core objects.
> Devices are modelled on top of QOM as QDev objects.
> 
> There is no point in using the lower level QOM API with
> QDev; it makes the code more complex and harder to review.
> 
> I first converted all the calls using errp=&error_abort or
> &errp=NULL, then noticed the other uses weren't really
> consistent.
> 
> A QDev property defined with the DEFINE_PROP_xxx() macros
> is always available, thus can't fail. When using hot-plug
> devices, we only need to check for optional properties
> registered at runtime with the object_property_add_XXX()
> API. Some are even always registered in device instance_init.
> 
> I have probably been overzealous, so I tagged the patches
> not using errp=&error_abort|&error_fatal|NULL as RFC.
> 
> PPC and ARM conversions will follow as two different series.

>   46 files changed, 155 insertions(+), 221 deletions(-)

Forgot to mention, this is based on
https://lore.kernel.org/qemu-devel/20230203163021.35754-1-philmd@linaro.org/
"hw/acpi/cpu_hotplug: Convert 'Object *device' -> 'DeviceState *parent'"

Based-on: <20230203163021.35754-1-philmd@linaro.org>



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH 00/19] hw: Set QDev properties using QDev API (part 1/3)
  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
  0 siblings, 0 replies; 31+ messages in thread
From: BALATON Zoltan @ 2023-02-03 18:52 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: qemu-devel, qemu-arm, Markus Armbruster, Eduardo Habkost, qemu-riscv

[-- Attachment #1: Type: text/plain, Size: 2454 bytes --]

On Fri, 3 Feb 2023, Philippe Mathieu-Daudé wrote:
> On 3/2/23 19:08, Philippe Mathieu-Daudé wrote:
>> QEMU provides the QOM API for core objects.
>> Devices are modelled on top of QOM as QDev objects.
>> 
>> There is no point in using the lower level QOM API with
>> QDev; it makes the code more complex and harder to review.
>> 
>> I first converted all the calls using errp=&error_abort or
>> &errp=NULL, then noticed the other uses weren't really
>> consistent.
>> 
>> A QDev property defined with the DEFINE_PROP_xxx() macros
>> is always available, thus can't fail. When using hot-plug
>> devices, we only need to check for optional properties
>> registered at runtime with the object_property_add_XXX()
>> API. Some are even always registered in device instance_init.
>> 
>> I have probably been overzealous, so I tagged the patches
>> not using errp=&error_abort|&error_fatal|NULL as RFC.
>> 
>> PPC and ARM conversions will follow as two different series.
>
>>   46 files changed, 155 insertions(+), 221 deletions(-)
>
> Forgot to mention, this is based on
> https://lore.kernel.org/qemu-devel/20230203163021.35754-1-philmd@linaro.org/
> "hw/acpi/cpu_hotplug: Convert 'Object *device' -> 'DeviceState *parent'"
>
> Based-on: <20230203163021.35754-1-philmd@linaro.org>

Doing these clean ups is nice but making tree wide one line changes in the 
middle of development window has a high chance of breaking series not yet 
merged which is less nice. I'm worried because it's hard enough to get a 
series reviewed and catch the attention of the maintainer so that it will 
also be merged. But when another series that causes my series to not apply 
lands first mine will get rejected needing a rebase and I have to start 
again which might mean it will miss the freeze and get forgotten or 
delayed until the next release. This is OK as long as the other 
conflicting series is adding functionality or fixing bugs but if it's just 
trivial clean up then maybe it would be better to merge these tree wide 
clean ups during the soft freeze or first after opening development to 
reduce the number of comflicts. It would also be less of a problem if 
merging a series would not take more than half of the development window 
but would land within a week or so but maintainers are often too busy to 
handle their job so we're limited to one ot two pulls per release. Please 
consider this when submitting these clean up series.

Regards,
BALATON Zoltan

^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [RFC PATCH 12/19] hw/i386: Set QDev properties using QDev API
  2023-02-03 18:09 ` [RFC PATCH 12/19] hw/i386: " Philippe Mathieu-Daudé
@ 2023-02-04 13:23   ` Bernhard Beschow
  2023-03-01 14:00   ` Igor Mammedov
  1 sibling, 0 replies; 31+ messages in thread
From: Bernhard Beschow @ 2023-02-04 13:23 UTC (permalink / raw)
  To: qemu-devel, Philippe Mathieu-Daudé
  Cc: qemu-arm, Markus Armbruster, Eduardo Habkost, qemu-riscv,
	Paolo Bonzini, Richard Henderson, Michael S. Tsirkin,
	Marcel Apfelbaum, David Hildenbrand, Igor Mammedov,
	Xiao Guangrong



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)


^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH 13/19] hw/m68k: Set QDev properties using QDev API
  2023-02-03 18:09 ` [PATCH 13/19] hw/m68k: " Philippe Mathieu-Daudé
@ 2023-02-05  9:14   ` Thomas Huth
  0 siblings, 0 replies; 31+ messages in thread
From: Thomas Huth @ 2023-02-05  9:14 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: qemu-devel, qemu-arm, Markus Armbruster, Eduardo Habkost,
	qemu-riscv, Laurent Vivier

Am Fri,  3 Feb 2023 19:09:08 +0100
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/m68k/next-cube.c | 2 +-
>  hw/m68k/q800.c      | 7 +++----
>  2 files changed, 4 insertions(+), 5 deletions(-)

Reviewed-by: Thomas Huth <huth@tuxfamily.org>


^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH 02/19] hw/qdev: Introduce qdev_prop_set_link()
  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
  0 siblings, 0 replies; 31+ messages in thread
From: Mark Cave-Ayland @ 2023-02-05 22:53 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé, qemu-devel
  Cc: qemu-arm, Markus Armbruster, Eduardo Habkost, qemu-riscv,
	Paolo Bonzini, Daniel P. Berrangé

On 03/02/2023 18:08, Philippe Mathieu-Daudé wrote:

> Introduce qdev_prop_set_link(), equivalent of
> object_property_set_link() for QDev objects.
> 
> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
> ---
>   hw/core/qdev-properties.c    | 5 +++++
>   include/hw/qdev-properties.h | 1 +
>   2 files changed, 6 insertions(+)
> 
> diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c
> index 9789a2f5de..46236b1542 100644
> --- a/hw/core/qdev-properties.c
> +++ b/hw/core/qdev-properties.c
> @@ -694,6 +694,11 @@ void error_set_from_qdev_prop_error(Error **errp, int ret, Object *obj,
>       }
>   }
>   
> +void qdev_prop_set_link(DeviceState *dev, const char *name, Object *value)
> +{
> +    object_property_set_link(OBJECT(dev), name, value, &error_abort);
> +}
> +
>   void qdev_prop_set_bit(DeviceState *dev, const char *name, bool value)
>   {
>       object_property_set_bool(OBJECT(dev), name, value, &error_abort);
> diff --git a/include/hw/qdev-properties.h b/include/hw/qdev-properties.h
> index 21f399e9a3..c16dbefb2f 100644
> --- a/include/hw/qdev-properties.h
> +++ b/include/hw/qdev-properties.h
> @@ -191,6 +191,7 @@ bool qdev_prop_set_drive_err(DeviceState *dev, const char *name,
>    * Set properties between creation and realization.
>    * @value must be valid.  Each property may be set at most once.
>    */
> +void qdev_prop_set_link(DeviceState *dev, const char *name, Object *value);
>   void qdev_prop_set_bit(DeviceState *dev, const char *name, bool value);
>   void qdev_prop_set_uint8(DeviceState *dev, const char *name, uint8_t value);
>   void qdev_prop_set_uint16(DeviceState *dev, const char *name, uint16_t value);

A general comment from me on this one: my feeling is that the main difference between 
QOM properties and qdev properties is that qdev properties are exposed to the user 
(for example they appear in the output of "-device foo,help") compared to QOM 
properties which tend to be used internally.

Following this thinking I'd always envisaged that an implementation of 
qdev_prop_set_link() would also be exposed to command line users so that you could 
set link properties from the command line similar to this:

   -device lance,id=lance0 -device ledma,dma=lance0

Of course this won't work in its current form (we don't have implicit ids for 
in-built devices as a starting point), but it does fit in with the recent discussions 
re: building machines completely from scratch. Certainly it feels to me as if this 
should be clarified before going ahead with a full-scale conversion for link 
properties as per this and your other related series.


ATB,

Mark.


^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH 18/19] hw/rx: Set QDev properties using QDev API
  2023-02-03 18:09 ` [PATCH 18/19] hw/rx: " Philippe Mathieu-Daudé
@ 2023-02-06 13:01   ` Yoshinori Sato
  0 siblings, 0 replies; 31+ messages in thread
From: Yoshinori Sato @ 2023-02-06 13:01 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: qemu-devel, qemu-arm, Markus Armbruster, Eduardo Habkost, qemu-riscv

On Sat, 04 Feb 2023 03:09:13 +0900,
Philippe Mathieu-Daudé 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/rx/rx-gdbsim.c | 11 +++++------
>  1 file changed, 5 insertions(+), 6 deletions(-)
> 
> diff --git a/hw/rx/rx-gdbsim.c b/hw/rx/rx-gdbsim.c
> index 47c17026c7..5d50f36877 100644
> --- a/hw/rx/rx-gdbsim.c
> +++ b/hw/rx/rx-gdbsim.c
> @@ -21,6 +21,7 @@
>  #include "qemu/error-report.h"
>  #include "qemu/guest-random.h"
>  #include "qapi/error.h"
> +#include "hw/qdev-properties.h"
>  #include "hw/loader.h"
>  #include "hw/rx/rx62n.h"
>  #include "sysemu/qtest.h"
> @@ -99,12 +100,10 @@ static void rx_gdbsim_init(MachineState *machine)
>  
>      /* Initialize MCU */
>      object_initialize_child(OBJECT(machine), "mcu", &s->mcu, rxc->mcu_name);
> -    object_property_set_link(OBJECT(&s->mcu), "main-bus", OBJECT(sysmem),
> -                             &error_abort);
> -    object_property_set_uint(OBJECT(&s->mcu), "xtal-frequency-hz",
> -                             rxc->xtal_freq_hz, &error_abort);
> -    object_property_set_bool(OBJECT(&s->mcu), "load-kernel",
> -                             kernel_filename != NULL, &error_abort);
> +    qdev_prop_set_link(DEVICE(&s->mcu), "main-bus", OBJECT(sysmem));
> +    qdev_prop_set_uint32(DEVICE(&s->mcu), "xtal-frequency-hz",
> +                         rxc->xtal_freq_hz);
> +    qdev_prop_set_bit(DEVICE(&s->mcu), "load-kernel", kernel_filename != NULL);
>  
>      if (!kernel_filename) {
>          if (machine->firmware) {
> -- 
> 2.38.1
> 

Reviewed-by: Yoshinori Sato <ysato@users.sourceforge.jp>

-- 
Yosinori Sato


^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH 00/19] hw: Set QDev properties using QDev API (part 1/3)
  2023-02-03 18:08 [PATCH 00/19] hw: Set QDev properties using QDev API (part 1/3) Philippe Mathieu-Daudé
                   ` (19 preceding siblings ...)
  2023-02-03 18:12 ` [PATCH 00/19] hw: Set QDev properties using QDev API (part 1/3) Philippe Mathieu-Daudé
@ 2023-03-01 13:42 ` Igor Mammedov
  20 siblings, 0 replies; 31+ messages in thread
From: Igor Mammedov @ 2023-03-01 13:42 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: qemu-devel, qemu-arm, Markus Armbruster, Eduardo Habkost, qemu-riscv

On Fri,  3 Feb 2023 19:08:55 +0100
Philippe Mathieu-Daudé <philmd@linaro.org> wrote:

> QEMU provides the QOM API for core objects.
> Devices are modelled on top of QOM as QDev objects.
> 
> There is no point in using the lower level QOM API with
> QDev; it makes the code more complex and harder to review.
> 
> I first converted all the calls using errp=&error_abort or
> &errp=NULL, then noticed the other uses weren't really
> consistent.
> 
> A QDev property defined with the DEFINE_PROP_xxx() macros
> is always available, thus can't fail. When using hot-plug
> devices, we only need to check for optional properties
> registered at runtime with the object_property_add_XXX()
> API. Some are even always registered in device instance_init.
> 
> I have probably been overzealous, so I tagged the patches
> not using errp=&error_abort|&error_fatal|NULL as RFC.

such patches are wrong (12/19 is definitely broken),
you can do above only if failure is not expected
otherwise you are killing QEMU process during runtime.

So if you do this, plse describe in commit message why
it isn't breaking anything for each case.

> 
> PPC and ARM conversions will follow as two different series.
> 
> Philippe Mathieu-Daudé (19):
>   scripts/coccinelle: Add qom-qdev-prop.cocci
>   hw/qdev: Introduce qdev_prop_set_link()
>   hw/acpi: Set QDev properties using QDev API
>   hw/audio: Set QDev properties using QDev API
>   hw/core/numa: Set QDev properties using QDev API
>   hw/core/gpio: Set QDev properties using QDev API
>   hw/scsi: Set QDev properties using QDev API
>   hw/usb: Set QDev properties using QDev API
>   hw/virtio: Set QDev properties using QDev API
>   hw/avr: Set QDev properties using QDev API
>   hw/hppa: Set QDev properties using QDev API
>   hw/i386: Set QDev properties using QDev API
>   hw/m68k: Set QDev properties using QDev API
>   hw/microblaze: Set QDev properties using QDev API
>   hw/mips: Set QDev properties using QDev API
>   hw/nios2: Set QDev properties using QDev API
>   hw/riscv: Set QDev properties using QDev API
>   hw/rx: Set QDev properties using QDev API
>   hw/sparc: Set QDev properties using QDev API
> 
>  hw/acpi/cpu_hotplug.c                    |  7 ++--
>  hw/acpi/ich9.c                           |  4 +--
>  hw/acpi/piix4.c                          |  4 +--
>  hw/avr/arduino.c                         |  4 +--
>  hw/avr/atmega.c                          |  4 +--
>  hw/core/gpio.c                           |  8 ++---
>  hw/core/numa.c                           |  4 +--
>  hw/core/qdev-properties.c                |  5 +++
>  hw/display/virtio-gpu-pci.c              |  4 +--
>  hw/display/virtio-vga.c                  |  4 +--
>  hw/dma/sparc32_dma.c                     |  6 ++--
>  hw/hppa/machine.c                        |  3 +-
>  hw/i386/pc.c                             |  8 ++---
>  hw/i386/pc_q35.c                         | 25 +++++++-------
>  hw/i386/sgx.c                            |  3 +-
>  hw/i386/x86.c                            | 12 +++----
>  hw/m68k/next-cube.c                      |  2 +-
>  hw/m68k/q800.c                           |  7 ++--
>  hw/mem/pc-dimm.c                         |  5 ++-
>  hw/microblaze/petalogix_ml605_mmu.c      | 40 ++++++++++------------
>  hw/microblaze/petalogix_s3adsp1800_mmu.c |  2 +-
>  hw/microblaze/xlnx-zynqmp-pmu.c          | 40 +++++++++-------------
>  hw/mips/boston.c                         |  6 ++--
>  hw/mips/cps.c                            | 42 ++++++++----------------
>  hw/mips/jazz.c                           |  3 +-
>  hw/mips/malta.c                          |  6 ++--
>  hw/nios2/10m50_devboard.c                |  2 +-
>  hw/riscv/microchip_pfsoc.c               |  8 ++---
>  hw/riscv/opentitan.c                     |  9 ++---
>  hw/riscv/shakti_c.c                      |  7 ++--
>  hw/riscv/sifive_e.c                      |  8 ++---
>  hw/riscv/sifive_u.c                      |  9 ++---
>  hw/riscv/spike.c                         | 10 +++---
>  hw/riscv/virt.c                          |  9 ++---
>  hw/rx/rx-gdbsim.c                        | 11 +++----
>  hw/scsi/scsi-bus.c                       |  6 +---
>  hw/sparc/sun4m.c                         | 10 +++---
>  hw/sparc64/sun4u.c                       |  3 +-
>  hw/usb/hcd-xhci-pci.c                    |  2 +-
>  hw/usb/hcd-xhci-sysbus.c                 |  2 +-
>  hw/virtio/virtio-iommu-pci.c             |  3 +-
>  hw/virtio/virtio-rng.c                   |  3 +-
>  include/hw/audio/pcspk.h                 |  2 +-
>  include/hw/qdev-properties.h             |  1 +
>  target/i386/cpu.c                        |  6 ++--
>  target/i386/host-cpu.c                   |  7 ++--
>  46 files changed, 155 insertions(+), 221 deletions(-)
>  create mode 100644 scripts/coccinelle/qom-qdev-prop.cocci
> 



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [RFC PATCH 12/19] hw/i386: Set QDev properties using QDev API
  2023-02-03 18:09 ` [RFC PATCH 12/19] hw/i386: " Philippe Mathieu-Daudé
  2023-02-04 13:23   ` Bernhard Beschow
@ 2023-03-01 14:00   ` Igor Mammedov
  1 sibling, 0 replies; 31+ messages in thread
From: Igor Mammedov @ 2023-03-01 14:00 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: qemu-devel, qemu-arm, Markus Armbruster, Eduardo Habkost,
	qemu-riscv, Paolo Bonzini, Richard Henderson, Michael S. Tsirkin,
	Marcel Apfelbaum, David Hildenbrand, Xiao Guangrong

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)



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [PATCH 03/19] hw/acpi: Set QDev properties using QDev API
  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
  0 siblings, 0 replies; 31+ messages in thread
From: Igor Mammedov @ 2023-03-01 14:07 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: qemu-devel, qemu-arm, Markus Armbruster, Eduardo Habkost,
	qemu-riscv, Michael S. Tsirkin, Ani Sinha, Marcel Apfelbaum,
	Aurelien Jarno

On Fri,  3 Feb 2023 19:08:58 +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/acpi/cpu_hotplug.c | 7 +++----
>  hw/acpi/ich9.c        | 4 ++--
>  hw/acpi/piix4.c       | 4 ++--
>  3 files changed, 7 insertions(+), 8 deletions(-)
> 
> diff --git a/hw/acpi/cpu_hotplug.c b/hw/acpi/cpu_hotplug.c
> index b8c9081738..5bc5f435f4 100644
> --- a/hw/acpi/cpu_hotplug.c
> +++ b/hw/acpi/cpu_hotplug.c
> @@ -10,6 +10,7 @@
>   * See the COPYING file in the top-level directory.
>   */
>  #include "qemu/osdep.h"
> +#include "hw/qdev-properties.h"
>  #include "hw/acpi/cpu_hotplug.h"
>  #include "qapi/error.h"
>  #include "hw/core/cpu.h"
> @@ -41,8 +42,7 @@ static void cpu_status_write(void *opaque, hwaddr addr, uint64_t data,
>       */
>      if (addr == 0 && data == 0) {
>          AcpiCpuHotplug *gpe = opaque;
> -        object_property_set_bool(OBJECT(gpe->parent), "cpu-hotplug-legacy",
> -                                 false, &error_abort);
> +        qdev_prop_set_bit(gpe->parent, "cpu-hotplug-legacy", false);
>      }
>  }
>  
> @@ -66,8 +66,7 @@ static void acpi_set_cpu_present_bit(AcpiCpuHotplug *gpe, CPUState *cpu)
>  
>      cpu_id = k->get_arch_id(cpu);
>      if ((cpu_id / 8) >= ACPI_GPE_PROC_LEN) {
> -        object_property_set_bool(OBJECT(gpe->parent), "cpu-hotplug-legacy",
> -                                 false, &error_abort);
> +        qdev_prop_set_bit(gpe->parent, "cpu-hotplug-legacy", false);
>          return;
>      }
>  
> diff --git a/hw/acpi/ich9.c b/hw/acpi/ich9.c
> index 6c9a737479..9759119b32 100644
> --- a/hw/acpi/ich9.c
> +++ b/hw/acpi/ich9.c
> @@ -30,6 +30,7 @@
>  #include "hw/pci/pci.h"
>  #include "migration/vmstate.h"
>  #include "qemu/timer.h"
> +#include "hw/qdev-properties.h"
>  #include "hw/core/cpu.h"
>  #include "sysemu/reset.h"
>  #include "sysemu/runstate.h"
> @@ -197,8 +198,7 @@ static bool vmstate_test_use_cpuhp(void *opaque)
>  static int vmstate_cpuhp_pre_load(void *opaque)
>  {
>      ICH9LPCPMRegs *s = opaque;
> -    Object *obj = OBJECT(s->gpe.parent);
> -    object_property_set_bool(obj, "cpu-hotplug-legacy", false, &error_abort);
> +    qdev_prop_set_bit(s->gpe.parent, "cpu-hotplug-legacy", false);
>      return 0;
>  }
>  
> diff --git a/hw/acpi/piix4.c b/hw/acpi/piix4.c
> index 3a61d89f92..9a86d506de 100644
> --- a/hw/acpi/piix4.c
> +++ b/hw/acpi/piix4.c
> @@ -206,8 +206,8 @@ static bool vmstate_test_use_cpuhp(void *opaque)
>  
>  static int vmstate_cpuhp_pre_load(void *opaque)
>  {
> -    Object *obj = OBJECT(opaque);
> -    object_property_set_bool(obj, "cpu-hotplug-legacy", false, &error_abort);
> +    PIIX4PMState *s = opaque;

In other series you were aiming for type safety converting Object to DeviceState
and here you do opposite of that

> +    qdev_prop_set_bit(DEVICE(s), "cpu-hotplug-legacy", false);
if you have to, just use DEVICE(opaque) here and drop above pointer casting.

>      return 0;
>  }
>  



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [RFC PATCH 05/19] hw/core/numa: Set QDev properties using QDev API
  2023-02-03 18:09 ` [RFC PATCH 05/19] hw/core/numa: " Philippe Mathieu-Daudé
@ 2023-03-01 14:09   ` Igor Mammedov
  0 siblings, 0 replies; 31+ messages in thread
From: Igor Mammedov @ 2023-03-01 14:09 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: qemu-devel, qemu-arm, Markus Armbruster, Eduardo Habkost,
	qemu-riscv, Marcel Apfelbaum, Yanan Wang

On Fri,  3 Feb 2023 19:09:00 +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/core/numa.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/hw/core/numa.c b/hw/core/numa.c
> index d8d36b16d8..9b6f9848e3 100644
> --- a/hw/core/numa.c
> +++ b/hw/core/numa.c
> @@ -34,6 +34,7 @@
>  #include "qapi/opts-visitor.h"
>  #include "qapi/qapi-visit-machine.h"
>  #include "sysemu/qtest.h"
> +#include "hw/qdev-properties.h"
>  #include "hw/core/cpu.h"
>  #include "hw/mem/pc-dimm.h"
>  #include "migration/vmstate.h"
> @@ -740,8 +741,7 @@ void numa_cpu_pre_plug(const CPUArchId *slot, DeviceState *dev, Error **errp)
>          /* due to bug in libvirt, it doesn't pass node-id from props on
>           * device_add as expected, so we have to fix it up here */
>          if (slot->props.has_node_id) {
> -            object_property_set_int(OBJECT(dev), "node-id",
> -                                    slot->props.node_id, errp);
> +            qdev_prop_set_int32(dev, "node-id", slot->props.node_id);

broken, see cover letter reply

>          }
>      } else if (node_id != slot->props.node_id) {
>          error_setg(errp, "invalid node-id, must be %"PRId64,



^ permalink raw reply	[flat|nested] 31+ messages in thread

* Re: [RFC PATCH 07/19] hw/scsi: Set QDev properties using QDev API
  2023-02-03 18:09 ` [RFC PATCH 07/19] hw/scsi: " Philippe Mathieu-Daudé
@ 2023-03-01 14:13   ` Igor Mammedov
  0 siblings, 0 replies; 31+ messages in thread
From: Igor Mammedov @ 2023-03-01 14:13 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: qemu-devel, qemu-arm, Markus Armbruster, Eduardo Habkost,
	qemu-riscv, Paolo Bonzini, Fam Zheng

On Fri,  3 Feb 2023 19:09:02 +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/scsi/scsi-bus.c | 6 +-----
>  1 file changed, 1 insertion(+), 5 deletions(-)
> 
> diff --git a/hw/scsi/scsi-bus.c b/hw/scsi/scsi-bus.c
> index ceceafb2cd..a8003126c4 100644
> --- a/hw/scsi/scsi-bus.c
> +++ b/hw/scsi/scsi-bus.c
> @@ -347,11 +347,7 @@ SCSIDevice *scsi_bus_legacy_add_drive(SCSIBus *bus, BlockBackend *blk,
>          object_unparent(OBJECT(dev));
>          return NULL;
>      }
> -    if (!object_property_set_bool(OBJECT(dev), "share-rw", share_rw, errp)) {
> -        object_unparent(OBJECT(dev));
> -        return NULL;
> -    }
> -
> +    qdev_prop_set_bit(dev, "share-rw", share_rw);

likely broken, see cover letter reply
(I'm stopping here, series should be rewritten to drop unjustified conversions or commit message describe why it's safe)


>      qdev_prop_set_enum(dev, "rerror", rerror);
>      qdev_prop_set_enum(dev, "werror", werror);
>  



^ permalink raw reply	[flat|nested] 31+ messages in thread

end of thread, other threads:[~2023-03-01 14:14 UTC | newest]

Thread overview: 31+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [RFC PATCH 12/19] hw/i386: " Philippe Mathieu-Daudé
2023-02-04 13:23   ` 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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).